akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
#define REP(i, n) for(int i=0; i<n; i++)
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; }
const ll MOD = 1e9+7;

typedef pair<ll, int> P;

//struct BIT{
//    int N;
//    vector<int> data;
//
//    BIT(int n){
//        N = n;
//        data.resize(N+1, 0);
//    }
//
//    void add(int a, int w){
//        for(int x = a; x <= N; x += x & -x)
//            data[x] += w;
//    }
//
//    int sum(int a){
//        int ret = 0;
//        for(int x = a; x > 0; x -= x & -x)
//            ret += data[x];
//        return ret;
//    }
//
//};

struct BIT{
    int N;
    vector<int> data;

    BIT(int n){
        N = n;
        data.resize(N, 0);
    }

    // 0-indexed
    void add(int a, int w){
        for(int x = a; x < N; x |= x + 1)
            data[x] += w;
    }

    int sum(int a){
        int ret = 0;
        for(int x = a-1; x >= 0; x = (x & (x+1)) - 1)
            ret += data[x];
        return ret;
    }
};

int main(){
    ll N, K;
    cin >> N >> K;
    vector<ll> A(N);
    REP(i,N){
        ll a;
        cin >> a;
        A[i] = a - K;
    }

    vector<ll> S(N);
    S[0] = A[0];
    priority_queue<P, vector<P>, greater<P> > que;

    que.push(P(0, 0));
    que.push(P(S[0], 1));
    for(int i = 1; i < N; i++){
        S[i] = S[i-1] + A[i];
        que.push(P(S[i], i+1));
    }


    vector<int> X(N+1);
    REP(i,N+1){
        auto p = que.top(); que.pop();
        X[p.second] = i;
    }

    BIT bit(N+1);
    ll ans = 0;
    for(int i = 0; i < N+1; i++){
        int x = X[i];
        //ans += bit.sum(x+1);
        //bit.add(x+1, 1);
        ans += bit.sum(x);
        bit.add(x, 1);
    }

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


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

#define rep(i, x, n) for (int i = x; i < n; i++)
typedef long long ll;

const int INF = 1e9 + 7;

using namespace std;

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

  int a, b;
  cin >> a >> b;

  cout << max(0, a - (b * 2)) << endl;


	return 0;
}


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

#define fast_io ios_base::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr);
#define cout_precision cout.setf(ios::fixed); cout.precision(32);
#define clr(a) memset(a,0,sizeof(a))
#define umap unordered_map
#define uset unordered_set
#define fr first
#define sc second
#define pb push_back
#define pf push_front
#define M int(1e9+7)
#define endl '\n'
#define largest(a,b,c) (a>b?(a>c? a:c):(b>c? b:c))
#define smallest(a,b,c) (a<b?(a<c? a:c):(b<c? b:c))

using ll = int64_t; using vll = vector<ll>; using vvll = vector<vll>;
using pll = pair<ll, ll>; using vpll = vector<pll>; using vvpll = vector<vpll>;



int main() {
	fast_io; cout_precision;
	string s,t;	cin >> s>> t;
	int n = s.size();
	int m = t.size();
	int res = INT_MAX;
	for(int i=0; i<=n-m; i++){
		string s1 = s.substr(i,m);
		int count = 0;
		for(int j=0; j<m; j++){
			if(s1[j] != t[j])	count++;
		}
		res = min(res , count);
	}
	cout << res <<endl;

	return 0;
}


Measured memory_bytes: 3644
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <iomanip>
#include <random>
#include <cstdio>
#include <cmath>
#include <map>
using namespace std;
typedef long long ll;
#define rep(i, n) for(int i = 0; i < (int) n; i++)

int main() {
    int a,b,k; cin>>a>>b>>k;
    for (int i = a; i <= min(b, a+k-1); i++) cout << i << endl;
    for (int i = max(b-k+1, a+k); i <= b; i++) cout << i << endl;
    return 0;
}

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

using namespace std;

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

    int s;

    cin >> s;
    cout << s / (60 * 60) << ":" << (s % (60 * 60)) / 60  << ":" << s % 60 << '\n';

    return 0;
}

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

bool IsPalindrome(string s){
    int l = s.length();
    bool answer = true;
if(l%2==0){
    for( int i=0;i<l/2;i++){
        if(s[i]!=s[l-i-1]){
            answer = false;
        }

    }


}

else{
    int k = (l-1)/2;
    for(int i=0;i<k;i++){
        if(s[i]!=s[l-i-1]){
            answer =false;
        }
    }





}

return answer;

}

int main()
{
  string s;
  cin>>s;
  int n = s.length();

  int p = (n-1)/2;
  p=p-1;
  int q= (n+3)/2;
  q=q-1;

  bool a1=false,a2=false,a3=false;
  if(IsPalindrome(s)) a1= true;

  string s2,s3;
  s2 = s.substr(0,p+1);
  s3  = s.substr(q,n);

  if(IsPalindrome(s2))a2 =true;
  if(IsPalindrome(s3))a3 = true;

  if(a1==true&&a2==true&&a3==true){
    cout<<"Yes";

  }
  else{
    cout<<"No";
  }


    return 0;
}


Measured memory_bytes: 256
n=[0]*5
x=10
flag=0
sum=0
for i in range(5):
  n[i]=int(input())
  if n[i]%10!=0 and n[i]%10<x:
    x=n[i]%10
    flag=i
for i in range(5):
  if i!=flag and n[i]%10!=0:
    sum+=(n[i]+(10-n[i]%10))
  else:
    sum+=n[i]
print(sum)

Measured memory_bytes: 3064
#include<bits/stdc++.h>
#include<algorithm>
#include<vector>
#include<queue>
using namespace std;
typedef long long ll;
ll dp[100][21];

int main(){
	int N;
	scanf("%d",&N);
	int d[100];
	for(int i=0;i<N;i++) scanf("%d",&d[i]);
	dp[1][d[0]]=1;
	for(int i=2;i<N;i++){
		for(int j=0;j<=20;j++){
			if(0<=j+d[i-1]&&j+d[i-1]<=20) dp[i][j]+=dp[i-1][j+d[i-1]];
			if(0<=j-d[i-1]&&j-d[i-1]<=20) dp[i][j]+=dp[i-1][j-d[i-1]];
		}
	}
	printf("%lld\n",dp[N-1][d[N-1]]);
}

Measured memory_bytes: 1204
import sys
def input(): return sys.stdin.readline().strip()
def mapint(): return map(int, input().split())
sys.setrecursionlimit(10**9)

N = int(input())
As = list(mapint())

cum = As.pop(0)
if cum!=0:
    cum2 = cum
    ans = 0
    for a in As:
        if cum*(cum+a)>=0:
            ans += abs(cum+a)+1
            cum = -1 if cum>0 else 1
        else:
            cum += a
        
    ans2 = abs(cum2)+1
    cum2 = 1 if cum2<0 else -1
    for a in As:
        if cum2*(cum2+a)>=0:
            ans2 += abs(cum2+a)+1
            cum2 = -1 if cum2>0 else 1
        else:
            cum2 += a
    print(min(ans, ans2))
else:
    cum = -1
    ans = 1
    for a in As:
        if cum*(cum+a)>=0:
            ans += abs(cum+a)+1
            cum = -1 if cum>0 else 1
        else:
            cum += a
        
    ans2 = 1
    cum2 = 1
    for a in As:
        if cum2*(cum2+a)>=0:
            ans2 += abs(cum2+a)+1
            cum2 = -1 if cum2>0 else 1
        else:
            cum2 += a
    print(min(ans, ans2))

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

int main(){
	int n, m;
	scanf("%d %d", &n, &m);
	
	char a[n][n+1], b[m][m+1];
	for(int i=0; i<n; i++) scanf("%s", a[i]);
	for(int i=0; i<m; i++) scanf("%s", b[i]);

	bool can = false;
	for(int i=0; i<n-m+1; i++){
		for(int j=0; j<n-m+1; j++){
			bool ok = true;
			for(int k=0; k<m; k++){
				for(int l=0; l<m; l++){
					if(a[i+k][j+l]!=b[k][l]) ok = false;
				}
			}
			if(ok) can = true;
		}
	}
	
	if(can) puts("Yes");
	else puts("No");
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef pair<int,int> pii;
#define ff first
#define ss second
#define pb push_back
#define all(x) x.begin(),x.end()
#define sz(x) (int)x.size()
#define rep(i,a,b) for(int i=a;i<=b;++i)
#define rrep(i,a,b) for(int i=a;i>=b;--i)
#define fastio() ios::sync_with_stdio(0);cin.tie(0);
#define nl "\n"
#define print(x) for(auto it:x) cout << it << " "; cout << "\n";
#define wi(x) cerr << #x << " is " << x << nl
const double eps = 1e-6;
const int mod = 1e9 + 7;

void solve(){
	int n,x,t; cin >> n >> x >> t;
	cout << ((n + x - 1)/x) * t;
}

int main(){
	fastio()
	
	int T=1;
	//int T; cin>>T;
	while(T--) solve();
	
	return 0;
}


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

using namespace std;

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

	string str;
	cin >> str;

	int n = str.size();
	vector<int> vals(n+1, 0);
	int up = 0;
	for(int i = 0; i < n; i++) {
		if(str[i] == '<') {
			up++;
		}
		else {
			up = 0;
		}

		vals[i+1] = up;
	}

	vals[n] = max(vals[n], 0);
	up = 0;
	for(int i = n-1; i >= 0; i--) {
		if(str[i] == '<') {
			up = 0;
		}
		else {
			up++;
		}

		vals[i] = max(vals[i], up);
	}

	long long sum = 0;
	for(int val : vals) {
		sum += val;
	}
	cout << sum << endl;

	return 0;
}


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

using namespace std;

int main() {
    int n, d, x;
    cin >> n >> d >> x;
    int res = x;
    for(int i=0; i<n; i++) {
        int a;
        cin >> a;
        res += (d + a - 1) / a; 
    }
    cout << res << endl;
}

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


int
main()
{
  std::cin.tie(nullptr);
  std::ios::sync_with_stdio(false);

  int n;
  std::cin >> n;
  std::cout << (n * 800 - (n / 15) * 200) << std::endl;

  return EXIT_SUCCESS;
}


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

int main(){
    int n;
    cin >> n;
    vector<int> a(n);
    rep(i,n) cin >> a.at(i);
    vector<int> b = a;
    sort(b.begin(),b.end(),greater<int>());
    int first_v = b.at(0);
    int second_v = b.at(1);
    rep(i,n){
        if(a.at(i) == first_v){
            cout << second_v << endl;
            continue;
        }
        cout << first_v << endl;
    }
}

Measured memory_bytes: 4792
#include <bits/stdc++.h>
using namespace std;
int main(){
	long long N; cin >> N; 
	long long M = N - 1; 
	vector<long long> divN, divM; 
	for(long long i = 1; i * i <= N; i++){
		if(N % i == 0){
			if(i != 1) divN.push_back(i);
		 	if(i * i != N) divN.push_back(N / i); 
		}
	}
	for(long long i = 1; i * i <= M; i++){
		if(M % i == 0){
			if(i != 1) divM.push_back(i);
		 	if(i * i != M) divM.push_back(M / i); 
		}
	}
	int ans = divM.size(); 
	for(int i = 0; i < divN.size(); i++){
		long long tmp = N; 
		while(tmp % divN.at(i) == 0) tmp /= divN.at(i); 
		if(tmp % divN.at(i) == 1) ans ++; 
	}
	cout << ans << endl; 
}

Measured memory_bytes: 384
#include<bits/stdc++.h>
using namespace std;
 
 
int main(){
    ios::sync_with_stdio(false);
	cin.tie(0);

    long long q;
    cin>>q;
    priority_queue<long long,vector<long long>> p; //大きい方が出る　←
    priority_queue<long long,vector<long long>,greater<long long>> pq; //小さい方　右 
    long long B=0;
    long long INF=1e18;
    long long x1=INF,x2=INF;
    long long cnt=0;
    long long a1=0,a2=0;
    for(long long i=0;i<q;i++){
        long long s;
        cin>>s;
        if(s==1){
            long long a,b;
            cin>>a>>b;
            B+=b;
            cnt++;
            if(cnt==1) x1=a;
            else if(cnt==2) {
                x2=a;
                if(x2<x1) swap(x1,x2);
            }
            else {
                if(cnt%2==0){
                    if(a<=x1){
                        p.push(a);
                        x2=x1;
                        x1=p.top();
                        a1+=a;
                        a1-=p.top();
                        p.pop();
                    }
                    else {
                        pq.push(a);
                        x2=pq.top();
                        a2+=a;
                        a2-=pq.top();
                        pq.pop();
                    }
                }
                else{
                    if(x1<=a && x2>=a){
                        p.push(x1);
                        a1+=x1;
                        x1=a;
                        pq.push(x2);
                        a2+=x2;
                    }
                    else if(x1>a) {
                        pq.push(x2);
                        a2+=x2;
                        p.push(a);
                        a1+=a;
                    }
                    else {
                        pq.push(a);
                        a2+=a;
                        p.push(x1);
                        a1+=x1;
                        x1=x2;
                    }
                }
            }

            
        }
        else {
            long long ans=0;
            ans+=a2-a1;
            ans+=B;
            if(cnt%2==0) ans+=x2-x1;
            //cerr<<cnt<<" "<<a1<<" "<<a2<<" "<<x1<<" "<<x2<<" "<<B<<endl;
            cout<<x1<<" "<<ans<<endl;
        }
    }

}

Measured memory_bytes: 3828
#include<bits/stdc++.h>
using namespace std;
#define int long long
signed main(){
  int a,b,q[1000][1000]={};
  string c[10000];
  cin>>a>>b;
  for(int i=0;i<a;i++) cin>>c[i];
  for(int i=1;i<=a;i++){
	for(int j=1;j<=b;j++){
      if(c[i-1][j-1]=='#'){
        q[i][j]=-1;
          if(q[i][j+1]!=-1) q[i][j+1]++;
          if(q[i][j-1]!=-1) q[i][j-1]++;
          if(q[i+1][j]!=-1) q[i+1][j]++;
          if(q[i-1][j]!=-1) q[i-1][j]++;
          if(q[i+1][j+1]!=-1) q[i+1][j+1]++;
          if(q[i+1][j-1]!=-1) q[i+1][j-1]++;
          if(q[i-1][j+1]!=-1) q[i-1][j+1]++;
          if(q[i-1][j-1]!=-1) q[i-1][j-1]++;
      }
    }
  }
  for(int i=1;i<=a;i++){
    for(int j=1;j<=b;j++){
      if(q[i][j]==-1) cout<<"#";
      else cout<<q[i][j];
    }
    cout<<"\n";
  }
}

Measured memory_bytes: 8192
#include <bits/stdc++.h>
using namespace std;
#define rep(i,s,n) for(int i = s;i<n;i++)
#define repe(i,s,n) for(int i = s;i<=n;i++)
#define pb push_back
#define fi first
#define se second
typedef long long ll;
typedef pair<int,int>pint;
typedef vector<int>vint;
typedef vector<pint>vpint;
static const ll maxLL = (ll)1 << 62;
const ll MOD=1000000007,INF=1e18;
int dy[]={-1,0,1,0};
int dx[]={0,1,0,-1};

#define int ll

string s;
int a=0,b=0,c=0;

signed main(){
   cin>>s;
   if(s.size()==1){
       cout<<"YES"<<endl;
       return 0;
   }
   rep(i,0,s.size()){
       if(s[i]=='a')a++;
       else if(s[i]=='b')b++;
       else c++;
   }
   b-=a;c-=a;
   if(abs(b)>=2||abs(c)>=2||abs(b-c)>=2)cout<<"NO"<<endl;
   else cout<<"YES"<<endl;
   
   
   
   return 0;
}

Measured memory_bytes: 512
s = gets.chomp

ss = s.count('S')
ws = s.count('W')
ns = s.count('N')
es = s.count('E')

if ss > 0 && ns > 0 && ws > 0 && es > 0
  puts 'Yes'
elsif ss == 0 && ns == 0 && ws > 0 && es > 0
  puts 'Yes'
elsif ss > 0 && ns > 0 && ws == 0 && es == 0
  puts 'Yes'
else
  puts 'No'
end

Measured memory_bytes: 1788
N = gets.chomp.to_i
R = N.times.map { gets.chomp.to_i }
minv = R[0]
maxv = -2000000000
(1..N-1).each do |i|
  maxv = [maxv, R[i] - minv].max
  minv = [minv, R[i]].min
end
puts maxv



Measured memory_bytes: 8896
l,r=gets.split.map(&:to_i)


a=((r-l)/2019)-1
a=0 if a<0
r=r-(a*2019)
res=(l...r).map { |e1|
  (e1+1..r).map { |e2|
    (e1*e2)%2019
  }.min
}.min

p res.to_i


Measured memory_bytes: 22780
#include "bits/stdc++.h"
#define _overload3(_1,_2,_3,name,...)name
#define _rep(i,n)repi(i,0,n)
#define repi(i,a,b)for(int i=int(a),i##_len=(b);i<i##_len;++i)
#define MSVC_UNKO(x)x
#define rep(...)MSVC_UNKO(_overload3(__VA_ARGS__,repi,_rep,_rep)(__VA_ARGS__))
#define all(c)c.begin(),c.end()
#define write(x)cout<<(x)<<'\n'
using namespace std; typedef long long ll; template<class T>using vv = vector<vector<T>>;
template<class T>auto vvec(int n, int m, T v) { return vv<T>(n, vector<T>(m, v)); }
template<class T, class U>bool chmax(T& a, U&& b) { return a < b ? a = b, 1 : 0; }
template<class T, class U>bool chmin(T& a, U&& b) { return b < a ? a = b, 1 : 0; }
constexpr int INF = 1 << 29, MOD = int(1e9) + 7; constexpr ll LINF = 1LL << 60;
struct aaa { aaa() { cin.tie(0); ios::sync_with_stdio(0); cout << fixed << setprecision(10); }; }aaaa;

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

    int ans = 0;
    rep(n, 1000) {
        int n0 = n / 100, n1 = n % 100 / 10, n2 = n % 10;
        int i = 0;
        for (; i < N; ++i) {
            if (S[i] == n0 + '0') {
                i++;
                break;
            }
        }
        for (; i < N; ++i) {
            if (S[i] == n1 + '0') {
                i++;
                break;
            }
        }
        for (; i < N; ++i) {
            if (S[i] == n2 + '0') {
                ans++;
                break;
            }
        }
    }

    write(ans);
}

Measured memory_bytes: 384
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <string>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <iomanip>
#include <utility>
#include <tuple>
#include <functional>
#include <bitset>
#include <cassert>
#include <complex>
#include <time.h>
#define ll long long
#define double long double
#define itn int
#define endl '\n'
#define co(ans) cout<<ans<<endl;
#define COYE cout<<"YES"<<endl;
#define COYe cout<<"Yes"<<endl;
#define COye cout<<"yes"<<endl;
#define CONO cout<<"NO"<<endl;
#define CONo cout<<"No"<<endl;
#define COno cout<<"no"<<endl;
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define FFOR(i,a,b) for(int i=(a);i<=(b);++i)
#define REP(i,n)  FOR(i,0,n)
#define RREP(i,n)  FFOR(i,1,n)
#define ALL(V) ((V).begin(),(V).end())
#define SORT(V) sort((V).begin(),(V).end())
#define REVERSE(V) reverse((V).begin(),(V).end())
#define INF ((1LL<<62)-(1LL<<31))
#define EPS 1e-10
#define PI 3.141592653589793238
#define MOD 1000000007
#define MAX 5100000
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;}
using namespace std;

int main(){
  ll N,ans=0;
  cin>>N;
  
  map<string,ll> L;
  
  REP(i,N){
    string S;
    cin>>S;
    L[S]=0;
  }
  
  cout<<L.size()<<endl;
  return 0;
}

Measured memory_bytes: 19260
#include <bits/stdc++.h>
#define INF 1e18
#define int long long
#define Rep(i, a, n) for (int i = (a); i < (n); i++)
#define rep(i, n) Rep(i, 0, n)
#define all(a) (a).begin(), (a).end()
using namespace std;
typedef pair<int, int> P;
typedef pair<int, P> PP;
const int mod = 1000000007;

signed main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);

    int n;
    string s;
    cin >> n >> s;
    vector<int> E(n), W(n);
    rep(i, s.size())
    {
        if (s[i] == 'E')
            E[i]++;
        else
            W[i]++;
    }
    rep(i, n - 1) W[i + 1] += W[i];
    for (int i = n - 1; i > 0; i--)
        E[i - 1] += E[i];
    int ans = INF;
    rep(i, n) ans = min(ans, W[i] + E[i] - 1);
    cout << ans << endl;
}

Measured memory_bytes: 5396
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define repi(i,a,b) for(int (i)=(a);(i)<(b);(i)++)
typedef long long ll;
using namespace std; 
using P = pair<int,int>;
const ll mod = 1e9+7;
const int INF = 1001001001;

const int MAX_W = 500;
const int MAX_H = 500;


int main(){
  string s;
  cin >> s;
  
  for(int temp=0;temp<(1<<3); temp++){
    ll t=s[0] -'0';
    ll sum = t;
    char m[3];
    for(int i=0;i<3;i++){
      t=s[i+1] - '0';
      if(temp&(1<<i)){
	  m[i] = '+';
	  sum+=t;
	}
      else{
	sum-=t;
	m[i] = '-';
      }
    }

    if(sum==7){
      for(int k=0;k<3;k++){
	cout << s[k] << m[k];
      }
      cout << s[3] << '=' << '7' << endl;
      return 0;
    }
    
  }
	  
      
}


Measured memory_bytes: 256
n,m,x=map(int,input().split())
from itertools import combinations
l=[]
for i in range(n):
    l.append(list(map(int,input().split())))
l1=[]
for i in range(n):
    l1.append(i)
l2=[]
for i in range(1,n+1):
    lx=[0]*i
    lyy=[0]*m
    for lx in combinations(l1,i):
        ly=lyy.copy()
        a=0
        for p in range(1,m+1):
            for k in lx:
                ly[p-1]+=l[k][p]
        for k in lx:
            a+=l[k][0]
        for j in ly:
            if j<x:
                a=0
                break
        if a!=0:
            l2.append(a)
if len(l2)!=0:
    print(min(l2))
else:
    print(-1)
                
                
                
        
    
            
        
    


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

#define rep(i, n) for (int i = 0; i < (n); i++)
#define contains(v, t) (find(v.begin(), v.end(), t) != v.end())
#define MOD 1000000007
typedef long long ll;
typedef unsigned long long ull;

int main() {
  int a,b;
  cin>>a>>b;
  if (a + b >= 10) {
    cout << "error";
  } else {
  cout << a + b;
  }
}


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

int main() {
	int64_t n, k;
	cin >> n >> k;
	int64_t a[n];
	for (auto &i : a) {
		cin >> i;
	}
	int64_t puni[n + 1]{}, imos[n + 1]{};
	for (int i = 0; i < n; i++) {
		puni[i + 1] = puni[i] + max(int64_t(0), a[i]);
		imos[i + 1] = imos[i] + a[i];
	}
	int64_t ans = imos[n];
	for (int i = 0; i <= n - k; i++) {
		//a[i...(i + k)]を塗る
		int64_t white = puni[n] - puni[i + k] + puni[i];
		ans = max(ans, white);
		int64_t black = white + imos[i + k] - imos[i];
		ans = max(ans, black);
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 2560
#include<iostream>
#include<algorithm>
using namespace std;
int f1(int a, int b) {
	if (a%b != 0)a += b - (a%b);
	return a / b;
}
int main() {
	int n; cin >> n;
	int c[600], s[600], f[600];
	for (int i = 1; i < n; i++) 
		cin >> c[i] >> s[i] >> f[i];
	for (int i = 1; i < n; i++) {
		int t = 0;
		for (int j = i; j < n; j++) {
			if (t <= s[j])t = s[j];
			else t = f1(t - s[j], f[j])*f[j] + s[j];
			t += c[j];
		}
		cout << t << endl;
	}
	cout << 0 << endl;
	return 0;
}

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

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

    vector<tuple<int, string, int>> v(n);
    for (int i = 0; i < n; i++) {
        string s;
        int p;
        cin >> s >> p;
        v.at(i) = make_tuple((i + 1), s, p);
    }

    sort(v.begin(), v.end(), [](const auto &a, const auto &b) {
        string x = get<1>(a), y = get<1>(b);
        if (x == y)
            return get<2>(a) > get<2>(b);
        else
            return x < y;
    });

    for (const auto &x : v)
        cout << get<0>(x) << endl;
}

Measured memory_bytes: 3568
K = int(input())
N = 50
# 最後の状態からさかのぼる
A = [49] * 50
# K を均等に割り振る（どれか一つを集中して選択しない）
for i in range(N):
    A[i] += K // 50
# 割り振った残りを、さらになるべく均等に割り振る
for i in range(K % N):
    A[i] += 51
    for j in range(N):
        A[j] -= 1

print(N)
print(*A)

Measured memory_bytes: 3060
using System.Text;
using static System.Math;
using System;

public class P
{
    public long d { get; set; }
    public long p { get; set; }
    public long t { get; set; }
    public long w { get; set; }
}

public class hello
{
    public static void Main()
    {
        string[] line = Console.ReadLine().Trim().Split(' ');
        var n = int.Parse(line[0]);
        var a = long.Parse(line[1]);
        var q = int.Parse(line[2]);
        var ps = new P[n];
        line = Console.ReadLine().Trim().Split(' ');
        var p = long.Parse(line[0]);
        var d = long.Parse(line[1]);
        ps[0] = new P { p = p, d = d };
        var td = d;
        var tp = p;
        var tt = 0L;
        var tw = 0L;
        for (int i = 1; i < n; i++)
        {
            line = Console.ReadLine().Trim().Split(' ');
             p = long.Parse(line[0]);
             d = long.Parse(line[1]);
            ps[i] = new P { p = p, d = d };
            if (td == 1 && d == 2)
            {
                tw = (tp + p) / 2;
                tt = tw - tp;
                ps[i].t = tt;
                ps[i].w = tw;
                ps[i - 1].t = tt;
                ps[i - 1].w = tw;
            }
             else  if (d == 2)
            {
                ps[i].t = tt;
                ps[i].w = tw;
            }
            td = d;
            tp = p;
        }
        writeP(ps, n);
        getAns(ps, n, a, q);
    }
    static void getAns (P[]ps, int n, long a , int q)
    {
        var sb = new StringBuilder();
        for (int i = 0; i < q; i++)
        {
            var b = int.Parse(Console.ReadLine().Trim()) - 1;
            long ans;
            var x = ps[b];
            if (x.t == 0 && x.d == 1) ans = x.p + a;
            else if (x.t == 0 && x.d == 2) ans = x.p - a;
            else if (x.t > 0 && x.d == 1) ans = Min(x.w, x.p + a);
            else ans = Max(x.w, x.p - a);
            sb.Append(string.Format("{0}\n", ans));
        }
        Console.Write(sb);
    }
    static void writeP (P[]ps , int n )
    {
        var tw = 0L;
        var tt = 0L;
        for (int i = n-1; i >= 0; i--)
        {
            if (ps[i].d == 1 && ps[i].t > 0) { tt = ps[i].t; tw = ps[i].w; }
            else if (ps[i].d == 1) { ps[i].t = tt;  ps[i].w = tw; }
        }
    }
}


Measured memory_bytes: 26720
n  = int(input())
a = list(map(int,input().split()))
b = list(map(int,input().split()))
c = list(map(int,input().split()))

ans = 0

for i in range(n):
      #print(i)
      ans += b[a[i]-1]
      #print("ans",ans)
  #print("aaa",a[i])
      if i != 0:
        hantei = a[i-1] + 1
        if a[i] == hantei:
          ans += c[a[i]-2]
    
print(ans)

Measured memory_bytes: 3064
#define ll long long
#define MOD 1000000007
#define mp make_pair
#define pb push_back
#define ff first
#define ss second
#include <bits/stdc++.h>
using namespace std;
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    ll n;
    cin >> n;
    ll sum = 0;
    ll a[22] = {0}, b[22] = {0}, c[22] = {0};
    for (int i = 1; i <= n; i++)
    {
        cin >> a[i];
    }
    for (int i = 1; i <= n; i++)
    {
        cin >> b[i];
        sum += b[i];
    }
    for (int i = 1; i < n; i++)
    {
        cin >> c[i];
    }
    for (int i = 2; i <= n; i++)
    {
        if (a[i - 1] == a[i] - 1)
            sum += c[a[i - 1]];
    }
    cout << sum;

    return 0;
}

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

int main() {
  int N, K;
  cin >> N >> K;
  vector<int> V(K);
  for (int i = 1; i <= N; i++) {
    V.at(i % K)++;
  }
  long ans = 0;
  for (int i = 0; i < K; i++) {
    int a = i;
    int b = (K - a) % K;
    int c = (K - a) % K;
    if ((b + c) % K == 0) {
      ans += (long) V.at(a) * V.at(b) *V.at(c);
    }
  }
  cout << ans << "\n";
}

Measured memory_bytes: 1024
#include <stdio.h>
int check(int ,int *,int );
int main(void){
  int n,q,S[10000],key,i,count;

  scanf("%d",&n);
  for(i=0;i<n;i++)
    scanf("%d",&S[i]);
  scanf("%d",&q);
  for(i=0,count=0;i<q;i++){
    scanf("%d",&key);
    if(check(key,S,n)==1)count++;
  }
  printf("%d\n",count);
  return 0;
}
int check(int key,int *S,int n){
  int i=0;
  while(S[i]!=key && i<n)i++;
  if(i==n)return 0;
  else return 1;
}


Measured memory_bytes: 2128
#include<bits/stdc++.h>
using namespace std;
#define ll long long
typedef pair<ll,ll> P;
typedef pair<ll,P> PP;
const ll MOD = 1e9+7;

int main(){
  ll n,x;
  cin>>n>>x;
  ll p[55],b[55];
  p[0]=b[0]=1;
  for(int i=1;i<55;i++){
    p[i]=p[i-1]*2+1;
    b[i]=b[i-1]*2+3;
  }
  ll ans=0;
  while(1){
    ll f=1;
    for(ll i=0;i<n;i++){
	 ll k=b[n-i]/2+1+i;
	 if(b[n-i]+i==x){
	   x=0;
	   ans+=p[n-i];
	   break;
	 }
	 if(k<=x){
	   ans+=p[n-i-1]+1;
	   x-=k;
	   n-=i+1;
	   f=0;
	   break;
	 }
    }
    if(f){
	 if(n<x)ans++;
	 break;
    }
  }
  cout<<ans<<endl;
  return 0;
}


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

int main(){
    long long N;
    cin >> N;
    vector<long long> vec;
    long long A;
    long long i;
    for(i=0; i<N; i++){
        cin >> A;
        vec.push_back(-A);
    }
    sort(vec.begin(),vec.end());
    long long ans=-vec[0];
    for(i=0; i<N-2; i++){
        ans += -vec[(i+2)/2];
    }
    cout << ans << endl;
    system("pause");
    return 0;
}

Measured memory_bytes: 5368
N = int(input())
shogens = [None] * N
for i in range(N):
    A = int(input())
    shogen = [None] * A
    for j in range(A):
        x, y = map(int, input().split())
        shogen[j] = (x, y)
    shogens[i] = shogen


def ok(i, shogens):
    for j in range(N):
        if (i >> j) & 1:
            for x, y in shogens[j]:
                if bin(i >> (x - 1))[-1] == str(y):
                    continue
                else:
                    return False
    return True


ans = 0
for i in range(2 ** N):
    if ok(i, shogens):
        ans = max(ans, bin(i).count('1'))
print(ans)

Measured memory_bytes: 46684
#include <bits/stdc++.h>
#define inf 233366666
using namespace std;
inline int read()
{int x=0;
char c=getchar();
while (c<'0'||c>'9') c=getchar();
while (c>='0'&&c<='9') x=x*10+c-'0',c=getchar();
return x;
}
int deg[100005],head[100005],nxt[200005],v[200005];
int dp[100005],n,tot=0,root=-1,tar;
inline void add(int a,int b)
{tot++;nxt[tot]=head[a];head[a]=tot;v[tot]=b;}
void dfs(int pos,int f)
{vector <int> vec;
int sz=0,l,r,i,ts;
for (i=head[pos];i;i=nxt[i])
{if (v[i]==f) continue;
dfs(v[i],pos);sz++;
vec.push_back(dp[v[i]]);
}
if (!(sz&1)) vec.push_back(0),sz++;
sort(vec.begin(),vec.end());
l=0;r=sz-1;
ts=sz>>1;
while (l<=r)
{int mid=(l+r)>>1,p1=0,p2=sz-1,tag=1;
for (i=1;i<=ts;i++)
{if (p1==mid) p1++;
if (p2==mid) p2--;
if (vec[p1]+vec[p2]>tar) {tag=0;break;}
p1++;p2--;
}
if (tag) {r=mid-1;}
else {l=mid+1;}
}
if (l==sz) {dp[pos]=inf;}
else {dp[pos]=vec[l]+1;}
}
inline bool chk(int mid)
{tar=mid;dfs(root,0);
return (dp[root]<=mid+1);
}
int main (){
	int i,a,b,cnt=0;
	n=read();
	for (i=1;i<n;i++)
	{a=read();b=read();
	add(a,b);add(b,a);
	deg[a]++;deg[b]++;
	}
	for (i=1;i<=n;i++)
	{if (deg[i]&1)
	{cnt++;root=i;}
	}
	cnt>>=1;
	int l=1,r=n;
	while (l<=r)
	{int mid=(l+r)>>1;
	if (chk(mid)) {r=mid-1;}
	else {l=mid+1;}
	}
	printf ("%d %d\n",cnt,l);
	return 0;
}
	
	

Measured memory_bytes: 15488
#include "bits/stdc++.h"
// Custom Header {{{
#define ALL(x) x.begin(), x.end()
#define rep(i, s, n)      for(int i(s); i < int(n); ++i)
#define endl '\n'
#ifndef YDK
#define eprintf(...)
#endif
using namespace std;
using i64 = long long;
using pii = pair<i64, i64>;
template<class A, class B>inline bool chmax(A &a, const B &b){return b>a ? a=b,1 : 0;}
template<class A, class B>inline bool chmin(A &a, const B &b){return b<a ? a=b,1 : 0;}
constexpr const int INF  = 0x3f3f3f3f;
constexpr const i64 LINF = 0x3f3f3f3f3f3f3f3fLL;
constexpr const int MOD  = int(1e9) + 7;
// }}}

// Library {{{
// }}}


signed main()
{
    string s; cin >> s;
    cout << s.length() / 2 - count(ALL(s), 'p') << endl;
    return 0;
}


Measured memory_bytes: 512
/*
 * If you're not willing to make sacrifices yourself, you'll never be
 * able to change anything. In order to overcome monsters, you must
 * be willing to abandon your own humanity.
 * ~ Arlert
 */

#include <bits/stdc++.h>

using namespace std;

typedef pair<int, int> II;
typedef vector<II> VII;
typedef vector<int> VI;
typedef vector<VI> VVI;

typedef long long int LL;

#define PB push_back
#define MP make_pair
#define F first
#define S second
#define SZ(a) (int)(a.size())
#define ALL(a) a.begin(), a.end()
#define SET(a, b) memset(a, b, sizeof(a))
#define si(n) scanf("%d", &n)
#define dout(n) printf("%d\n", n)
#define sll(n) scanf("%lld", &n)
#define lldout(n) printf("%lld\n", n)

#define TRACE

#ifdef TRACE
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>
void __f(const char *name, Arg1 &&arg1) {
  cerr << name << " : " << arg1 << std::endl;
}
template <typename Arg1, typename... Args>
void __f(const char *names, Arg1 &&arg1, Args &&... args) {
  const char *comma = strchr(names + 1, ',');
  cerr.write(names, comma - names) << " : " << arg1 << " | ";
  __f(comma + 1, args...);
}
#else
#define trace(...)
#endif

#define fast_io                     \
  ios_base::sync_with_stdio(false); \
  cin.tie(NULL)

#define endl1 '\n'
const int N = 201;
const int INF = 1e9;
int d[N][N];
int main() {
  fast_io;
  int n, m, r;
  cin >> n >> m >> r;
  for (int i = 0; i <= n; i++)
    for (int j = 0; j <= n; j++) d[i][j] = INF;
  VI R(r);
  for (int i = 0; i < r; i++) cin >> R[i];
  sort(ALL(R));
  for (int i = 0; i < m; i++) {
    int a, b, c;
    cin >> a >> b >> c;
    d[a][b] = d[b][a] = c;
  }
  for (int i = 1; i <= n; i++) d[i][i] = 0;
  for (int k = 1; k <= n; k++)
    for (int i = 1; i <= n; i++)
      for (int j = 1; j <= n; j++) d[i][j] = min(d[i][j], d[i][k] + d[k][j]);
  int ans = INF;
  do {
    int tans = 0;
    for (int i = 1; i < SZ(R); i++) tans += d[R[i]][R[i - 1]];
    ans = min(ans, tans);
  } while (next_permutation(ALL(R)));
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 384
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <ctime>
#include <cctype>

#include <algorithm>
#include <random>
#include <bitset>
#include <queue>
#include <functional>
#include <set>
#include <map>
#include <vector>
#include <iostream>
#include <limits>
#include <numeric>

#define LOG(FMT...) fprintf(stderr, FMT)

using namespace std;

typedef long long ll;
typedef unsigned long long ull;

int main() {
#ifdef LBT
  freopen("test.in", "r", stdin);
  int nol_cl = clock();
#endif

  int n, m, vsum = 0;
  scanf("%d%d", &n, &m);
  vector<ll> dp(1);
  while (n--) {
    int w, v;
    scanf("%d%d", &w, &v);
    vsum += v;
    dp.insert(dp.end(), v, m + 1);
    for (int i = vsum; i >= v; --i)
      dp[i] = min(dp[i], dp[i - v] + w);
  }
  for (int i = vsum; ; --i)
    if (dp[i] <= m) {
      printf("%d\n", i);
      break;
    }

#ifdef LBT
  LOG("Time: %dms\n", int ((clock()
          -nol_cl) / (double)CLOCKS_PER_SEC * 1000));
#endif
  return 0;
}


Measured memory_bytes: 1884
#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
int a[200010];
int main ()
{
	int n,k,i,t,t1=0;
	cin>>n>>k;
	memset(a,0,sizeof(a));
	for(i=0;i<n;i++)
	{
		cin>>t;
		a[t]++;
	}
	sort(a,a+n);
	for(i=1;i<=k;i++)
		t1+=a[n-i];
	cout<<n-t1<<endl;
	return 0;
}


Measured memory_bytes: 1024
#include <bits/stdc++.h>
#define REP(i,n) for(int i=0;i<n;i++)
#define REPP(i,n) for(int i=1;i<=n;i++)
const double PI = acos(-1);
const double EPS = 1e-15;
long long INF=(long long)1E17;
#define i_7 (long long)(1E9+7)
long mod(long a){
    long long c=a%i_7;
    if(c>=0)return c;
    return c+i_7;
}
using namespace std;

int n;//頂点数
int parent[100010];//iの親parent[i]を格納する配列
int my_rank[100010];//iを根とする部分木の高さみたいな量?
void init(int n){
    for(int i=0;i<n;i++){
        parent[i]=i;
        my_rank[i]=0;
    }
}
int root(int x){
    if(parent[x]==x)return x;
    else return root(parent[x]);
}
void unite(int x,int y){
    x=root(x);
    y=root(y);
    if(x==y)return ;
    if(my_rank[x]<my_rank[y])parent[x]=y;
    else{
        parent[y]=x;
        if(my_rank[x]==my_rank[y])my_rank[x]++;
    }
}
bool same(int x,int y){
    return root(x)==root(y);
}
struct edge {int u,v,cost;};
bool comp(const edge& e1,const edge& e2){
    return e1.cost<e2.cost;
}

vector <edge> edges;
//vector <pair<int,int>>p1,p2;
int kruskal(){
    sort(edges.begin(),edges.end(),comp);
    init(n);
    long long res=0;
    REP(i,edges.size()){
        edge e=edges[i];
        if(!same(e.u,e.v)){
            unite(e.u,e.v);
            res += (long long)e.cost;
        }
    }
    return res;
}

int main(){
  cin>>n;
  
  int x,y;
  vector<pair<int,int>> xs,ys;
  REP(i,n){
    cin>>x>>y;
    xs.push_back(make_pair(x,i));
    ys.push_back(make_pair(y,i));
  }
  
  sort(xs.begin(),xs.end());
  sort(ys.begin(),ys.end());
  
  REP(i,n-1){
    edge e;
    e.u = xs[i].second;
    e.v = xs[i+1].second;
    e.cost = xs[i+1].first - xs[i].first;
    edges.push_back(e);
  }
  REP(i,n-1){
    edge e;
    e.u = ys[i].second;
    e.v = ys[i+1].second;
    e.cost = ys[i+1].first - ys[i].first;
    edges.push_back(e);
  }
  
  long long ans;
  ans = kruskal();
  cout<<ans<<endl;
  return 0;
}


Measured memory_bytes: 6888
import math
 
n = int(input())
tmp = int(input())
tmpmin = tmp
t1 = int(input())
if t1 < tmp: tmpmin = t1
ans = t1 - tmp
 
 
for i in range(2,n):
    tmp = int(input())
  
    if tmp - tmpmin > ans: ans = tmp - tmpmin
    if tmp < tmpmin: tmpmin = tmp
     
print(int(ans))  


Measured memory_bytes: 5668
#include <bits/stdc++.h>
#include <iomanip> 
using namespace std; 
#define rep(i,a,b)		for(long int i=a;i<=b;i++)
#define MOD 1e9+7

long long int n,k,i;
int main() 
{ 
	ios::sync_with_stdio(false);
    cin.tie(NULL);  
    
    
	cin>>n>>k;
	i=1;
	while(n--)
	{
		i=min(i*2,i+k);
	}
	cout<<i;
}
	

Measured memory_bytes: 3656
process.stdin.setEncoding('utf-8');
process.stdin.on('data', (input) => {

  var arr = input.split('\n')

  for (var i = 0; i < arr.length && arr[i] != 0; i++) {
    var result = 'Case ' + (i + 1 )+ ': ' + arr[i];
    console.log(result);
  }
})


Measured memory_bytes: 22612
L, R = map(int, input().split())

if R - L + 1 >= 2019:
    print(0)
else:
    res = 2018
    for i in range(L, R):
        for j in range(i + 1, R + 1):
            res = min(res, (i * j) % 2019)
    print(res)

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

using namespace std;

typedef long long ll;

int main(void) {

	string a;
	
	cin >> a;

	int b = a.size()-1;

	if (a[b] == '3') {
		cout << "bon";
	}
	else if (a[b] == '0' || a[b] == '1' || a[b] == '6' || a[b] == '8' ) {
		cout << "pon";
	}
	else {
		cout << "hon";
	}

	return 0;
}

Measured memory_bytes: 3548
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int inf = 1e9 + 7;
using pii = pair<int, int>;
#define rep(i, n) for (int i = 0; i < n; ++i)
#define rrep(i, st, n) for (int i = st; i < n; ++i)
#define chmax(a, b) a = max(a, b)
#define chmin(a, b) a = min(a, b)
int dx[] = {0, 0, -1, 1};
int dy[] = {1, -1, 0, 0};
int main() {
    string s; cin >> s;
    while (s.size() < 15) {
        s += 'o';
    }
    int win = 0;
    rep(i, 15) {
        if (s[i] == 'o') win++;
    }
    if (win >= 8) puts("YES");
    else puts("NO");
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define pb push_back
#define int long long
#define pii pair<int,int>
#define f first
#define se second
using namespace std;
double pi=acos(-1.0);
int m=1000000007;
bool cmp2(int n,pii p)
 {return n<p.f;}
int abst(int a)
{return a<0?-a:a;}
struct HASH{
  size_t operator()(const pii &x)const{
    return (size_t) x.first * 37U + (size_t) x.second;}};
int Pow(int n,int x){int ans=1;
 while(x>0)
 {if(x&1)ans=(ans*n)%m;n=(n*n)%m;x=x>>1;}
 return ans;}

int max(int a,int b){return a>b?a:b;}
int min(int a,int b){return a<b?a:b;}
int32_t main(){
ios_base::sync_with_stdio(0);cin.tie(NULL);cout.tie(NULL);
int n;
cin>>n;
vector<vector<int>> v(n+1);
int a[n];
for(int i=0;i<n;i++)
{
cin>>a[i];
v[a[i]].pb(i);
}
int count=0;
int index=-1;
for(int i=1;i<=n;i++)
{
  if(v[i].size()==0)
  break;
  int x=upper_bound(v[i].begin(),v[i].end(),index)-v[i].begin();
  if(x==v[i].size())
  break;
  count++;
  index=v[i][x];
  //cout<<index<<" ";
}
if(count==0)
cout<<-1;
else
cout<<n-count;
}

Measured memory_bytes: 12800
var Main  = function(input){
    const [a, b, c, d] = input.trim().split(' ').map(x => BigInt(x));
    var array=[];

    array.push(a*c,a*d,b*c,b*d);
    array.sort((a,b)=>(a>b)? -1: (a<b)? 1: 0);
    // Bigintのソート

    console.log(array[0].toString(10));
};


Main(require("fs").readFileSync("/dev/stdin", "utf8"));


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

int main() {
    int n,m;
    cin >> n >> m;
    int p[m];
    string s[m];
    for(int i = 0; i < m; i++){
        cin >> p[i] >> s[i]; 
    }
    bool a[n] = {};
    int ac = 0;
    int wa = 0;
    int wacount[n] = {};
    for(int i = 0; i < m; i++){
        if(s[i] == "WA" && a[p[i]-1] == 0){
            wacount[p[i]-1] += 1;
        }else if(s[i] == "AC" && a[p[i]-1] == 0){
            a[p[i]-1] = 1;
            ac += 1;
        }
    } 
    for(int i = 0; i < n; i++){
        if(a[i] == 1){
            wa += wacount[i];
        }
    }

    cout << ac << " " << wa << endl;

    return 0;
}

Measured memory_bytes: 6528
#include <iostream>

using namespace std;
#define ll long long;
int N,M,A[100005];
int ref(int i)
  {if(A[i]==i)return i;
   return A[i]=ref(A[i]);
      
  }
int main()
{
cin>>N>>M;
int x,y,z,t1,t2;

for(int i=0;i<N+1;i++)
   {A[i]=i;
   }
int b=N;
while(M--)
  {cin>>x>>y>>z;
    t1=ref(x);  t2=ref(y);
    if(t1==t2) continue;
    A[t1]=t2;
    b--;
  }
  cout<<b;
   
}


Measured memory_bytes: 640
#include<bits/stdc++.h>
#define ll long long
#define re register
using namespace std;
const int maxn=1e5+10;
template<typename T> void read(T &x){
	T f=1;x=0;
	char c=getchar();
	while(c<'0' || c>'9'){if(c=='-') f=-1;c=getchar();}
	while(c>='0' && c<='9'){x=(x<<3)+(x<<1)+c-48;c=getchar();}
	x*=f;
}
int n;
int k;
int h[maxn];
int f[maxn];
int main(){
	read(n);
	read(k);
	h[0]=999999999;
	for(re int i=1;i<=n;i++){
		read(h[i]);
	}
	for(re int i=2;i<=n;i++){
		f[i]=999999999;
		for(re int j=i-1;j>=0 && j>=i-k;j--){
			f[i]=min(f[j]+abs(h[i]-h[j]),f[i]);
		}
	}
	cout<<f[n]<<endl;
	return 0;
}


Measured memory_bytes: 1024
#include<bits/stdc++.h>
#include<unordered_set>
#include<unordered_map>
#include <algorithm> 
#include <iostream>
#include <string>
#include <cmath>
using namespace std;
#define ll long long
#define rep(i, n) for (ll i = 0; i < (n); i++)
#define FOR(i,a,b) for(ll i=(a);i<(b);i++)
#define FORR(i,a,b)for(ll i=(a);i<=(b);i++)
#define repR(i,n) for(ll i=n;i>=0;i--)
#define all(v)(v).begin(),(v).end()
#define rall(v)(v).rbegin(),(v).rend()
#define F first
#define S second
#define pb push_back
#define pu push
#define COUT(x) cout<<(x)<<endl
#define PQ priority_queue<ll>
#define PQR priority_queue<ll,vector<ll>,greater<ll>>
#define YES(n) cout << ((n) ? "YES" : "NO"  ) << endl
#define Yes(n) cout << ((n) ? "Yes" : "No"  ) << endl
#define mp make_pair
#define maxs(x,y) (x = max(x,y))
#define mins(x,y) (x = min(x,y))
#define sz(x) (ll)(x).size()
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
const ll MOD = 1000000007LL;
const ll INF = 1LL << 60;
using vll = vector<ll>;
using vb = vector<bool>;
using vvb = vector<vb>;
using vvll = vector<vll>;
using vstr = vector<string>;
using pll = pair<ll, ll>;
using vc = vector<char>;
using vvc = vector<vc>;
template<class T> inline bool chmax(T& a, T b) { 
 if (a < b) { a = b; return true; } return false; 
}
template<class T> inline bool chmin(T& a, T b) {
 if (a > b) { a = b; return true; } return false; 
}
ll dx[4]={0,1,0,-1};
ll dy[4]={1,0,-1,0};
int main(){
  ll n,a,b,c;
  cin>>n>>a>>b>>c;
  vstr s(n);
  rep(i,n)cin>>s[i];
  vc ans(0);
  rep(i,n){
    if(s[i]=="AB"){
      if(a==0&&b==0){
        COUT("No");
        return 0;
      }
      if(a==0){
        ans.pb('A');
        ++a;--b;
      }else if(b==0){
        ans.pb('B');
        ++b;--a;
      }else{
        if(i==n-1){
          ans.pb('A');
          ++a;--b;
        }else{
          if(s[i+1]=="AC"){
            ans.pb('A');
            ++a;--b;
          }else{
            ans.pb('B');
            ++b;--a;
          }
        }
      }
    }
    else if(s[i]=="AC"){
      if(a==0&&c==0){
        COUT("No");
        return 0;
      }
      if(a==0){
        ans.pb('A');
        ++a;--c;
      } else if(c==0){
        ans.pb('C');
        ++c;--a;
      }else {
        if(i==n-1){
          ans.pb('A');
          ++a;--c;
        }else{
          if(s[i+1]=="AB"){
            ans.pb('A');
            ++a;--c;
          }else{
              ans.pb('C');
            ++c;--a;
          }
        }
      }
    }else{
      if(c==0&&b==0){
        COUT("No");
        return 0;
      }
      if(c==0){
        ans.pb('C');
        c++;
        b--;
      }else if(b==0){
        b++;
        c--;
        ans.pb('B');
      }else{
          if(i==n-1){
            c--;
            b++;
            ans.pb('B');
          }else{
          if(s[i+1]=="AB"){
            c--;
            b++;
            ans.pb('B');
          }
          else{
            b--;
            c++;
            ans.pb('C');
          }
        }
      }
    }
  }
  COUT("Yes");
  rep(i,n)COUT(ans[i]);
}


Measured memory_bytes: 6724
#include<bits/stdc++.h>
using namespace std;
string s;
int n,q;
int main()
{
	cin>>n>>s>>q;
	while(q--)
	{
		int k;
		cin>>k;
		long long ans=0,dm=0;
		int d=0,m=0;
		for(int i=0;i<n;i++)
		{
			if(s[i]=='C')
			{
				ans+=dm;
			}
			else if(s[i]=='D')
			{
				d++;
			}
			else if(s[i]=='M')
			{
				dm+=d;
				m++;
			}
			if(i>=k-1)
			{
				int p=i-k+1;
				if(s[p]=='D')
				{
					dm-=m;
					d--;
				}
				else if(s[p]=='M')
				{
					m--;
				}
			}
		}
		cout<<ans<<endl;
	}
	return 0;
}

Measured memory_bytes: 1412
#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 = 1 << 30;
const ll LLINF = 1LL << 62;

int mod = 1000000007;

int main(void){
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    vector<pair<int, int>> ev(100001);
    vector<pair<int, int>> od(100001);
    rep(i, 100001){
        ev[i] = make_pair(0, i);
        od[i] = make_pair(0, i);
    }
    int N; cin >> N;
    rep(i, N){
        int a; cin >> a;
        if(i&1) ev[a].first++;
        else od[a].first++;
    }
    sort(ev.rbegin(), ev.rend());
    sort(od.rbegin(), od.rend());
    int evcnt = N/2;
    int odcnt = N - evcnt;

    if(ev[0].second != od[0].second) cout << (evcnt - ev[0].first) + (odcnt - od[0].first) << endl;
    else{
        int ans1 = (evcnt - ev[1].first) + (odcnt - od[0].first);
        int ans2 = (evcnt - ev[0].first) + (odcnt - od[1].first);
        cout << min(ans1, ans2) << endl;
    }
    return 0;
}

Measured memory_bytes: 1792
# %%time
n = int(input())
a = list(map(int, input().split()))

# n = 10000
# a = np.random.randint(1, 1000, n)

import numpy as np
from collections import Counter

a = np.array(a)
ap = a + np.arange(n)
am = a - np.arange(n)
am = -am

c = Counter(am)

s = 0
for k in range(n):
    s += c[ap[k]]
    c[am[k]] -= 1

print(s)

Measured memory_bytes: 55044
// B - Collatz Problem
// https://atcoder.jp/contests/abc116/tasks/abc116_b
#include <bits/stdc++.h>
#define lli long long int
#define uli unsigned long long int
#define rep(i, m, n) for (lli i = m; i < (n); i++)
#define repe(i, m, n) for (lli i = m; i <= (n); i++)
#define ALL(x) (x).begin(), (x).end()
#define SIZE(x) ((lli)(x).size())
#define MAX(x) *max_element(ALL(x))
#define INF 1000000000000 //10^12
#define MOD 10000007      //10^9+7
#define SORT(n) sort(n.begin(), n.end())
#define SORTR(n) sort(n.begin(), n.end(), greater<int>())
#define REV(n) reverse(n.begin(), n.end())
#define Vec(K, L, N, S) vector<L> K(N, S)
#define rt sqrt
using namespace std;
using vi = vector<int>;
using vvi = vector<vi>;
using vvvi = vector<vvi>;
using vlli = vector<lli>;
using vs = vector<string>;
using ll = long long;
// vector入力
template <typename T>
istream &operator>>(istream &is, vector<T> &vec)
{
  for (T &x : vec)
    is >> x;
  return is;
}
// vector出力
template <typename T>
ostream &operator<<(ostream &os, vector<T> &vec)
{
  // os << '{';
  for (int i = 0; i < vec.size(); i++)
  {
    os << vec[i] << (i + 1 == vec.size() ? "" : "");
  }
  // os << '}';
  return os;
}

int main()
{
  ios::sync_with_stdio(false);
  cin.tie(0);
  lli a, b, s, c, h, k, n, w, ans = 0, count = 0;
  string t;
  cin >> n;
  vi d(1, n);
  set<int> g;
  g.insert(n);
  while (count < 1000)
  {
    if (n % 2 == 0)
    {
      n = n / 2;
      d.push_back(n);
      g.insert(n);
    }
    else
    {
      n = 3 * n + 1;
      d.push_back(n);
      g.insert(n);
    }
    count++;
  }
  rep(i, 0, d.size())
  {
    rep(j, g.size(), d.size())
    {
      if (d[i] == d[j])
      {
        ans++;
      }
      if (d[i] == d[j] && ans >= 1)
      {
        cout << j + 1 << endl;
        return 0;
      }
    }
  }
}

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

int main(){
	int A,B,C;
	cin >> A >> B;
  	C = A - 2*B;
  if(C <= 0){
    C = 0;
    cout << C <<endl;
  }else{
  	cout << C << endl;
  }
}

Measured memory_bytes: 256