akhauriyash/Code-Regression huggingface dataset:
/*Function Template*/
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef pair<ll,ll> pint;
const int MAX = 510000;
const int MOD = 1000000007;
#define rep(i, n) for(ll i = 0; i < (n); i++)
#define Rep(i, n) for(ll i = 1; i < (n); i++)
#define ALL(a)  (a).begin(),(a).end()
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
ll fac[MAX], finv[MAX], inv[MAX];


template<class T> inline bool chmin(T& a, T b) {
    if (a > b) {
        a = b;
        return true;
    }
    return false;
}
template<class T> inline bool chmax(T& a, T b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}
// テーブルを作る前処理
void COMinit() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (ll i = 2; i < MAX; i++){
        fac[i] = fac[i - 1] * i % MOD;
        inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
        finv[i] = finv[i - 1] * inv[i] % MOD;
    }

}
ll Len(ll n) {
  ll s=0;
  while(n!=0) s++, n/=10;
  return s;
}


ll Sint(ll n) {
  ll m=0,s=0,a=n;
  while(a!=0) s++, a/=10;
  for(ll i=s-1;i>=0;i--) m+=n/((ll)pow(10,i))-(n/((ll)pow(10,i+1)))*10;
  return m;
}


ll Svec(vector<ll> v){
  ll n=0;
  for(ll i=0;i<v.size();i++) n+=v[i];
  return n;
}


ll GCD(ll a,ll b) {
  return b ? GCD(b,a%b) : a;
}


ll LCM(ll a,ll b){
  return a/GCD(a,b)*b;
}


ll Factorial(ll n){
  ll m=1;
  while(n>=1) m*=n,n--;
  return m;
}

void runlength(string s,vector<pair<char,ll>> &p){
  ll x=1;
  if(s.size()==1){
    p.push_back(pair<char,ll>(s[0],1));
  }
  for(ll i=0;i<s.size()-1;i++){
    if(s[i]==s[i+1]){
      x++;
      if(i==s.size()-2){
        p.push_back(pair<char,ll>(s[i],x));
      }
    }else{
      p.push_back(pair<char,ll>(s[i],x));
      x=1;
      if(i==s.size()-2){
        p.push_back(pair<char,ll>(s[s.size()-1],x));
      }
    }
  }
}




ll COM(ll n,ll k){
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}

const int MAX_N=100010;
vector<bool> sieve_of_eratosthenes(){
  vector<bool> isPrime(MAX_N+1,true);
  for(int i=2;i<=MAX_N;i++){
    if(isPrime[i]){
      for(int j=2*i;j<=MAX_N;j+=i){
        isPrime[j]=false;
      }
    }
  }
  return isPrime;
}

vector<pint> prime_factorize(ll n){
  vector<pint> ans;
  for(ll p=2;p<=sqrt(n);p++){
    if(n%p!=0) continue;
    ll cnt=0;
    while(n%p==0){
      n/=p;
      cnt++;
    }
    ans.push_back(make_pair(p,cnt));
  }
  if(n!=1) ans.push_back(make_pair(n,1));
  return ans;
}

/*↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓*/
int main() {
  IOS;
  while(1){
    string g;cin>>g;
    if(g[0]=='#') return 0;
    ll y,m,d;cin>>y>>m>>d;
    if(y<=30){
      cout<<g<<' '<<y<<' '<<m<<' '<<d<<endl;
    }else if(y==31){
      if(m<=4) cout<<g<<' '<<y<<' '<<m<<' '<<d<<endl;
      else cout<<"? "<<y-30<<' '<<m<<' '<<d<<endl;
    }else{
      cout<<"? "<<y-30<<' '<<m<<' '<<d<<endl;
    }
    
    
    
    
    
  }
}


Measured memory_bytes: 3164
#include<stdio.h>
int fx(int angka,int a,int b){
	int v=10000,temp=0;
	for(int i=0; i<5; i++){
		temp=temp+(angka/v);
		angka=angka%v;
		v/=10;
	}
	
	if(temp>=a&&temp<=b){
		return 1;
	}
	
	
	return 0;
}

int main(){
	int angka,a,b;
	int total=0;
	scanf("%d %d %d", &angka,&a,&b);
	
	for(int i=1; i<=angka; i++){
		int temp=fx(i,a,b);	
		if(temp==1){
			total+=i;
		}		
	}
	
	printf("%d\n", total);
	return 0;
}

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

string s[100], t[100];

int main(){
  int n,i,m;
  cin >> n;
  for(i = 0; i < n; i++) cin >> s[i];
  cin >> m;
  for(i = 0; i < m; i++) cin >> t[i];

  int ans = 0;
  for(i = 0; i < n; i++){
    int score = 0;
    for(int j = 0; j < n; j++){
      if(s[i] == s[j])
        score++;
    }
    for(int j = 0; j < m; j++){
      if(s[i] == t[j])
        score--;
    }
    ans = max(ans,score);
  }

  cout << ans << endl;

  return 0;
}
        


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

int main() {
  ll h, w;
  cin >> h >> w;
  vector<string> g(h);
  REP(i, h){
  	cin >> g[i];
  }
  vector<bool> R(h, false);
  vector<bool> C(w, false);
  REP(i, h){
  	REP(j, w){
  		if (g[i][j] == '#'){
  			R[i] = true;
  			C[j] = true;
  		}
  	}
  }
  REP(i, h){
  	REP(j, w){
  		if (R[i] == true && C[j] == true){
  			cout << g[i][j];
  		}
  	}
  	if (R[i] == true){cout << "\n";}
  }
  
}


Measured memory_bytes: 764
from sys import setrecursionlimit
from operator import itemgetter
from math import ceil
def main():
    D,G = map(int,input().split())
    PC = [list(map(int,input().split())) for _ in range(D)]
    ans = float("inf")
    for i in range(2**D):
        done = [False]*D
        tmp = 0
        q = 0
        cnt = i
        point = 0
        while cnt > 0:
            if cnt%2 == 1:
                done[point] = True
                tmp += PC[point][0]*(100*(point + 1)) + PC[point][1]
                q += PC[point][0]
            point += 1
            cnt //= 2
        if tmp < G:
            for j in range(D):
                if not(done[D - j - 1]):
                    score = 100*(D - j)
                    num = min(ceil((G - tmp) / score),PC[D - j - 1][0])
                    tmp += num*score
                    q += num
                    if tmp < G:
                        q = float("inf")
                    break
                
        ans = min(q,ans)
    print(ans)
    return

if __name__ == "__main__":
    main()

Measured memory_bytes: 3064
#include <bits/stdc++.h>
#define PI 3.14159265359
using namespace std;
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;
}
const long long INF = 1LL << 60;
using pll = pair<long long, long long>;

int main() {
  // 標準入力が早くなる。Cスタイルの入出力とC++スタイルの入出力を混合させてはならない。
  cin.tie(nullptr);
  ios_base::sync_with_stdio(false);

  string S, T;

  cin >> S >> T;
  T.pop_back();
  if (S == T) {
    cout << "Yes" << endl;
  } else {
    cout << "No" << endl;
  }

  return 0;
}


Measured memory_bytes: 3636
def reverse(num):
    sum1 = 0
    while (num > 0):
        remainder = num % 10
        sum1 = remainder+sum1
        num = num // 10
    return sum1

n,a,b = list(map(int,input().split()))
c = 0
for i in range(1,n+1):
    if reverse(i)>=a and reverse(i)<=b:
        c+=i
print(c)

Measured memory_bytes: 9180
#include <iostream>
#include <algorithm>
#include <vector>
#define rep(i,n) for(ll i=0;i<n;++i)
#define rep1(i,n) for(ll i=1;i<=n;++i)
using namespace std;
typedef long long ll;
const int VMAX=100010;
ll n,m;
int a[100010],b[100010];
ll cntx,cnty;
bool f[100010],col[100010];
vector<int> edge[VMAX];
void add_edge(int from,int to){
  edge[from].push_back(to);
  edge[to].push_back(from);  
}
bool bipa_check(int x,bool c){
  f[x] = true;
  if(c) cntx++;
  else cnty++;
  col[x] = c;
  int vs = edge[x].size();
  rep(i,vs){
    int w = edge[x][i];
    if(f[w]){
      if(col[w] == c) return false;	      
    }
    else if(!bipa_check(w,!c)) return false;
  }
  return true;
}
int main()
{
  cin >> n >> m;
  rep(i,m) cin >> a[i] >> b[i];

  rep(i,m) add_edge(--a[i],--b[i]);

  cntx = cnty = 0;
  rep(i,n) f[i] = false;
  
  if(bipa_check(0,1)) cout << cntx*cnty - m << "\n";
  else cout << n*(n-1)/2 - m << "\n";
  
  
  return 0;
}


Measured memory_bytes: 7168
#include<iostream>
#include<vector>
#include<algorithm>
#include<cstdlib>
#include<cmath>
#include<math.h>
#include<map>
#include<string>
#include<numeric>
#include<set>
#include<deque>
using namespace std;

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

    vector<int> a(n);
    for(int i = 0; i < n; i++) cin >> a[i];

    deque<int> col;
    col.push_front(a[0]);

    for(int i = 1; i < n; i++){
        if(a[i] <= col[0]) col.push_front(a[i]);
        else{
            int j = 0;
            while(j < col.size()){
                if(a[i] <= col[j]) break;
                j++;
            }
            j--;
            col[j] = a[i];
        }
    }

    cout << col.size() << endl;

    return 0;
}

Measured memory_bytes: 1024
//This code was made by Chinese_zjc_
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cmath>
#include<string>
#define int long long
#define INF 0x3fffffffffffffff
using namespace std;
int n,a[51];
double ans;
signed main()
{
	scanf("%lld",&n);
	for(int i=1;i<=n;++i)
	{
		scanf("%lld",&a[i]);
	}
	sort(a+1,a+1+n);
	ans=a[1];
	for(int i=2;i<=n;++i)
	{
		ans=(ans+a[i])/2;
	}
	printf("%.14lf",ans);
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define int long long 
#define dd double
#define pb              push_back
#define mp              make_pair
#define pii             pair<int,int>
#define vi              vector<int>
#define mii             map<int,int>
#define pqb             priority_queue<int>
#define pqs             priority_queue<int,vi,greater<int> >
#define setbits(x)      __builtin_popcountll(x)
#define zrobits(x)      __builtin_ctzll(x)
#define mod 1000000007
#define tc(t) 			int t;cin >> t;while(t--)
#define for0(i , n)		for(int i=0;i<n;i++)
#define loop(i , a, b)	for(int i=a;i<=b;i++)
#define endl '\n'

int n;
vector<vector<vector<dd>>> dp(301,vector<vector<dd>>(301,vector<dd>(301,-1)));

dd sushi(int one,int two,int three){
	if(one<0||two<0||three<0)return 0;
	if(one==0 && two==0 && three==0) return 0;

	if(dp[one][two][three] > 0) return dp[one][two][three];

	int rem=one+two+three;
	dd expval=(n+one*sushi(one-1,two,three)+two*sushi(one+1,two-1,three)+three*sushi(one,two+1,three-1));
	return dp[one][two][three]=(expval/rem);
}

signed main() {

	ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    
#ifndef ONLINE_JUDGE
	freopen("input.txt" , "r" , stdin);
	freopen("output.txt" , "w" , stdout);
#endif

	cin >> n;
	int one=0,two=0,three = 0;

	for0(i,n){
		int x;
		cin >> x;
		if(x==1)one++;
		else if(x==2)two++;
		else three++;
	}

	cout <<setprecision(17)<<sushi(one,two,three);
	
	return 0;
}

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

int main() {
    string s, s2;
    ll k;
    cin >> s >> k;
    int n = s.size();
    s2 = s + s;

    set<char> st;
    rep(i, n) st.insert(s[i]);
    if (st.size() == 1) {
        cout << n * k / 2 << endl;
        return 0;
    }

    ll ans = 0, ans2 = 0, cnt = 1;
    rep(i, n) {
        if (s[i] == s[i + 1])
            cnt++;
        else
            ans += cnt / 2, cnt = 1;
    }

    cnt = 1;
    rep(i, n * 2) {
        if (s2[i] == s2[i + 1])
            cnt++;
        else
            ans2 += cnt / 2, cnt = 1;
    }

    ans = ans * k + (ans2 - ans * 2) * (k - 1);
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 3652
from math import sqrt,floor
from sys import stdin

def cntPrime(n):
    mx = sqrt(n)
    if n % 2 == 0:
      l = [0, 1] + [1, 0] * (int(n/2) - 1)
    else:
      l = [0, 1] + [1, 0] * (int(n/2) - 1) + [1]
    c = 3
    while c < mx:
        for k in range(c*2, n+1, c):
            l[k-1] = 0
        c = l[(c+1):].index(1) + c +2
        while c % 2 == 0:
            c = l[(c+1):].index(1) + c +2
    return l
t = cntPrime(1000000)
for n in stdin:
    n = int(n)
    print(sum(t[:n]))

Measured memory_bytes: 22952
// abc105_b
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#include<map>
#include<set>
#include<unordered_map>
#include<utility>
#include<cmath>
#include<random>
#include<cstring>
#include<queue>
#include<stack>
#include<bitset>
#include<cstdio>
#include<sstream>
#include<iomanip>
#include<assert.h>
#include<typeinfo>
#define loop(i,a,b) for(int i=a;i<b;i++)
#define rep(i,a) loop(i,0,a)
#define FOR(i,a) for(auto i:a)
#define pb push_back
#define all(in) in.begin(),in.end()
#define shosu(x) fixed<<setprecision(x)
#define show1d(v) rep(i,v.size())cout<<" "<<v[i];cout<<endl<<endl;
#define show2d(v) rep(i,v.size()){rep(j,v[i].size())cout<<" "<<v[i][j];cout<<endl;}cout<<endl;
using namespace std;
typedef long long ll;
typedef int Def;
typedef pair<Def,Def> pii;
typedef vector<Def> vi;
typedef vector<vi> vvi;
typedef vector<pii> vp;
typedef vector<vp> vvp;
typedef vector<string> vs;
typedef vector<double> vd;
typedef vector<vd> vvd;
typedef pair<Def,pii> pip;
typedef vector<pip>vip;
template<typename A,typename B>bool cmin(A &a,const B &b){return a>b?(a=b,true):false;}
template<typename A,typename B>bool cmax(A &a,const B &b){return a<b?(a=b,true):false;}
const double PI=acos(-1);
const double EPS=1e-9;
Def inf = sizeof(Def) == sizeof(long long) ? 2e18 : 1e9+10;
int dx[]={0,1,0,-1};
int dy[]={1,0,-1,0};
int main(int argc, char *argv[])
{
  int n;
  cin>>n;
  for(int i=0;i<=100;++i){
    for(int j=0;j<=100;++j){
      if(4*i+7*j==n) {
        cout<<"Yes"<<endl;
        return 0;;
      }
    }
  }

  cout<<"No"<<endl;
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for(ll i = 0, i##_len = (n); i < i##_len; i++)
#define reps(i, s, n) for(ll i = (s), i##_len = (n); i < i##_len; i++)
#define rrep(i, n) for(ll i = (n) - 1; i >= 0; i--)
#define rreps(i, e, n) for(ll i = (n) - 1; i >= (e); i--)
#define all(x) (x).begin(), (x).end()
#define sz(x) ((ll)(x).size())
#define len(x) ((ll)(x).length())

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    // ifstream in("input.txt");
    // cin.rdbuf(in.rdbuf());
    ll n;
    cin >> n;
    vector<ll> a(n);
    rep(i, n) cin >> a[i];
    ll m;
    cin >> m;
    vector<ll> b(m);
    rep(i, m) cin >> b[i];
    set<ll> s;
    s.insert(0);
    rep(i, n) {
        set<ll> add;
        for(auto x : s) add.insert(x + a[i]);
        for(auto x : add) s.insert(x);
    }
    s.erase(0);
    rep(i, m) {
        if (s.count(b[i]) == 0) {
            cout << "no" << endl;
        }
        else {
            cout << "yes" << endl;
        }
    }
    return 0;
}



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

using namespace std;

using ll = long long;

#define ALL(A) A.begin(),A.end()

vector<ll> workable_earliest(string S,ll C, ll K)
{
    ll ssize = S.size();
    
    vector<ll> answers;
    for(int i=0;i<ssize;i++)
    {
        if(S[i]=='o')
        {
            answers.push_back(i);
            break;
        }
    }
    
    for(int i=answers[0]+C+1;i<ssize && answers.size() < K;)
    {
        if(S[i]=='o')
        {
            answers.push_back(i);
            i+=C+1;
        }
        else
        {
            i++;
        }
    }

    for(auto& x : answers)
    {
        x++;
    }

    return answers;
}

vector<ll> workable_latest(string S, ll C, ll K)
{
    ll ssize = S.size();

    vector<ll> answers;

    for(int i=ssize-1;i>=0;i--)
    {
        if(S[i]=='o')
        {
            answers.push_back(i);
            break;
        }
    }

    for(int i=answers[0]-C-1;i>=0 && answers.size() < K;)
    {
        if(S[i]=='o')
        {
            answers.push_back(i);
            i-=(C+1);
        }
        else
        {
            i--;
        }
    }

    ll anssize = answers.size();

    vector<ll> copy(anssize);
    for(int i=0;i<anssize;i++)
    {
        copy[i] = answers[anssize-i-1] + 1;
    }

    return copy;
}

int main()
{
    ll N,K,C;
    cin >> N >> K >> C;

    string S;
    cin >> S;

    vector<ll> ans_earliest = workable_earliest(S,C,K);
    vector<ll> ans_latest = workable_latest(S,C,K);

/*    for(int i=0;i<K;i++)
    {
        ans_earliest[i]++;
        ans_latest[i]++;
    }*/

    vector<ll> answers;

    for(int i=0;i<K;i++)
    {
        if(ans_earliest[i]==ans_latest[i]) answers.push_back(ans_latest[i]);
    }

    for(auto x : answers)
    {
        cout << x << endl;
    }
    return 0;
}

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

int n, a[N];
ll dp[N][N][2];

ll f(int i, int j, int k) {
	if (i==j-1) return 0;
	if (dp[i][j][k]!=0) return dp[i][j][k];

	if (k==0) {
		dp[i][j][0] = max(
			f(i+1,j,1)+a[i+1],
			f(i,j-1,1)+a[j-1]
		);
	} else {
		dp[i][j][1] = min(
			f(i+1,j,0)-a[i+1],
			f(i,j-1,0)-a[j-1]
		);
	}
	return dp[i][j][k];
}

int main() {
	cin>>n;
	for (int i=1; i<=n; i++) cin>>a[i];
	cout<<f(0,n+1,0)<<endl;
	return 0;
}

Measured memory_bytes: 139904
#include<iostream>
#include<string>
#include<map>
using namespace std;

int main(void){
    int n,m;cin>>n>>m;
    int ans[n]={0};
    int a,b;
    for(int i=0;i<m;i++){
        cin>>a>>b;
        ans[a-1]+=1;
        ans[b-1]+=1;
    }
    for(int i=0;i<n;i++)cout<<ans[i]<<endl;
}

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

int main(){
  int N;
  cin >> N;
  string s = to_string(N);
  
  int count = 0;
  for (int i=1;i<s.size();i++){
    if (s.at(i-1) == s.at(i)){
      count += 1;
      if (2 <= count) break;
    }else{
      count = 0;
    }
  }
  
  if(2 <= count){
    cout << "Yes" << endl;
  }else{
    cout << "No" << endl;
  }

  
}

Measured memory_bytes: 256
n=input()
f=n[:2]
l=n[2:]
if (f=="00" and l=="00") or (int(f)>12 and int(l)>12) or (int(f)>12 and l=="00") or (int(l)>12 and f=="00") :
    print("NA")
elif int(f)>12 or f=="00":
    print("YYMM")
elif int(l)>12 or l=="00":
    print("MMYY")
else:
    print("AMBIGUOUS")

Measured memory_bytes: 3064
#include <iostream>
#include <string>
#include <sstream>
#include <iomanip> 
#include <math.h>
#include <stdio.h>
#include <string.h>
#include <queue>
#include <stack>
#include <vector>
#include <map>
#include <set>
#include <functional>
#include <algorithm>
#include <unordered_map>
#include <unordered_set>
#include <bitset>

using namespace std;


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

	int n, i, j, k, ans, x;
	cin >> n;
	vector<int> a(n + 1);
	for (i = 1; i <= n; i++) cin >> a[i];
	set<int> s;
	s.insert(1);
	x = 1;
	while (s.find(a[x]) == s.end()) {
		s.insert(a[x]);
		x = a[x];
		if (x == 2) break;
	}

	if (s.find(2) == s.end()) cout << "-1\n";
	else cout << s.size() - 1 << "\n";

	return 0;
}


Measured memory_bytes: 5376
#include<cstdio>
using namespace std;

int lb(int x){
    if (x==0) return -1;

    int cnt=0;
    while((x&1)==0){
        x/=2;
        cnt++;
    }

    return cnt;
}

int minim(int a,int b){
    if (a==-1) return b;
    if (b==-1) return a;
    return (a<b) ? a : b;
}

int main(){
    int a,b,c;

    scanf ("%d%d%d",&a,&b,&c);

    if (a>c){
        a^=c;
        c^=a;
        a^=c;
    }
    if (b>c){
        b^=c;
        c^=b;
        b^=c;
    }
    if (b>a){
        a^=b;
        b^=a;
        a^=b;
    }

    if ((a&1)==1 ||(b&1)==1 ||(c&1)==1) printf ("0");
    else printf ("%d",minim(minim(lb(b-a),lb(c-b)),lb(c-a)));

    return 0;
}


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

long long N, K, S, X[2009], Y[2009], Z[2009], col[2009], cnts; vector<int>x[2009], G[2009]; bool used[2009];

void init() {
	for (int i = 0; i < 2009; i++) {
		X[i] = 0; Y[i] = 0; Z[i] = 0; cnts = 0; col[i] = 0;
		x[i].clear(); G[i].clear(); used[i] = false;
	}
}

void dfs(int pos) {
	if (col[pos] >= 1) return;
	col[pos] = cnts; G[cnts].push_back(pos);
	for (int i = 0; i < x[pos].size(); i++) dfs(x[pos][i]);
}

long long reduction(long long a, long long b) {
	long long G1 = abs(X[a] - X[b]); G1 = S - G1;
	long long G2 = abs(Y[a] - Y[b]); G2 = S - G2;
	long long G3 = abs(Z[a] - Z[b]); G3 = S - G3;
	return G1*G2 + G2*G3 + G3*G1;
}

long long solve(vector<long long>A, bool ispath) {
	if (ispath == false) {
		long long minx = (1LL << 60);
		for (int i = 0; i < A.size(); i++) {
			int LL = i, RR = i + K - 1;

			long long V = 0;
			for (int j = LL; j <= RR; j++) V += S*S * 6;
			long long E = 0; if (A.size() == K) E = 1;
			for (int j = LL; j < RR + E; j++) V -= 2LL * reduction(A[j % A.size()], A[(j + 1) % A.size()]);
			minx = min(minx, V);
		}
		return minx;
	}
	if (ispath == true) {
		long long minx = (1LL << 60);
		for (int i = 0; i < A.size(); i++) {
			int LL = i, RR = i + K - 1; if (RR >= A.size()) continue;

			long long V = 0;
			for (int j = LL; j <= RR; j++) V += S*S * 6;
			for (int j = LL; j < RR; j++) V -= 2LL * reduction(A[j], A[j + 1]);
			minx = min(minx, V);
		}
		return minx;
	}
}

int main() {
	while (true) {
		cin >> N >> K >> S; init(); if (N + K + S == 0) break;
		for (int i = 1; i <= N; i++) cin >> X[i] >> Y[i] >> Z[i];
		for (int i = 1; i <= N; i++) {
			for (int j = 1; j <= N; j++) {
				if (abs(X[i] - X[j]) <= S && abs(Y[i] - Y[j]) <= S && abs(Z[i] - Z[j]) <= S && i != j) {
					x[i].push_back(j);
				}
			}
		}
		for (int i = 1; i <= N; i++) {
			if (col[i] == 0) { cnts++; dfs(i); }
		}
		long long minx = (1LL << 60);
		for (int i = 1; i <= cnts; i++) {
			vector<long long>A;
			int t = -1; bool ispath = true;
			for (int j = 0; j < G[i].size(); j++) {
				if (x[G[i][j]].size() <= 1) t = G[i][j];
			}
			if (t == -1) { t = G[i][0]; ispath = false; }

			while (true) {
				A.push_back(t); used[t] = true;
				int u = -1;
				for (int j = 0; j < x[t].size(); j++) {
					if (used[x[t][j]] == false) u = x[t][j];
				}
				if (u == -1) break;
				t = u;
			}
			minx = min(minx, solve(A, ispath));
		}
		if (minx == (1LL << 60)) minx = -1;
		cout << minx << endl;
	}
	return 0;
}


Measured memory_bytes: 3340
#include<iostream>
#include<algorithm>
using namespace std;
int main() {
	int N, K;
	int x[100];
	cin >> N >> K;
	for (int i = 0; i < N; ++i) {
		cin >> x[i];
	}
	int sum = 0;
	for (int i = 0; i < N; ++i) {
		int small[110];
		small[i] = min(x[i], abs(K - x[i]));
		sum += small[i];
	}
	cout << sum*2 << endl;
	return 0;
}

Measured memory_bytes: 256
let xs = stdin.ReadLine().ToCharArray()
let pivot = xs.Length / 2
let (s, s') = Array.splitAt pivot xs
let (rs, rs') = Array.splitAt (xs.Length%2) s'
Array.zip s (Array.rev rs')
|> Array.filter (fun (l, r) -> l <> r)
|> Array.length
|> printfn "%d"

Measured memory_bytes: 14044
#include <iostream>

using namespace std;
#define Inf 1e6 + 7;
const int N = 1e7 + 7;
int s[N];
int Find(int i)
{
    int r = i;
    while(s[r] != r)
    {
        r = s[r];
    }
    int x = i,j;
    while(x != r)
    {
        j = s[x];
        s[x] = r;
        x = j;
    }
    return r;
}
void Union(int i,int j)
{
    int x = Find(i);
    int y = Find(j);
    if(x != y)
    {
        s[y] = x;
    }
}
int main()
{
    int n,m;
    cin >> n >> m;
    int ans = 0;
    for(int i = 0 ; i < n ; i++)
    {
        s[i] = i;
    }
    for(int i = 0 ; i < m ; i++)
    {
        int u,v;
        cin >> u >> v;
        Union(u,v);
    }
    for(int i = 0 ; i < n ; i++)
    {
        if(s[i] == i)
        {
            ans++;
        }
    }
    cout << ans - 1 << endl;
    return 0;
}


Measured memory_bytes: 3984
def GCD(M, N) :
    while True :
        if N < M :
            N, M = M, N
        amari = N % M
        if amari == 0 :
            break
        else :
            N, M = M, amari
    return M

x, y = map(int, input().split()) 
gcd = GCD(x, y)
x = x / gcd
y = y / gcd
print(int(x-1 + y-1 + 1) * gcd + 1)


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

using namespace std;

typedef int64_t ll;
typedef vector<ll> vi;

const ll inf = 1e18;

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

    ll A, B, M;
    cin >> A >> B >> M;
    vi a(A, 0), b(B, 0), c(M, 0), x(M, 0), y(M, 0);
    ll minA = inf, minB = inf;
    for (ll i = 0; i < A; i++) {
        cin >> a[i]; minA = min(minA, a[i]);
    }
    for (ll i = 0; i < B; i++) {
        cin >> b[i]; minB = min(minB, b[i]);
    }
    for (ll i = 0; i < M; i++) cin >> x[i] >> y[i] >> c[i];
    ll res = minA + minB;
    for (ll i = 0; i < M; i++) {
        res = min(res, a[x[i]-1] + b[y[i]-1] - c[i]);
    }
    cout << res;
    return 0;
}


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


using namespace std;


#ifdef zxc

#include "debug.h"

#define debug(...) cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)
#else
#define debug(...) 42
#endif

using ll = int64_t;
using ld = long double;
const ld EPS = 1e-10;
const ll MOD = 1e9 + 7;
const ld PI = 3.141592653589793;
const int maxn = 200001;

void fast_io() {
    ios_base::sync_with_stdio(false);
    cin.tie(0);
}

signed main() {
#ifdef zxc
    mt19937 mt(228);
    freopen("../kolya_input.txt", "r", stdin);
//    freopen("../kolya_output.txt", "w", stdout);
#else
    //    mt19937 mt(std::chrono::high_resolution_clock::now().time_since_epoch().count());
    //            freopen("", "r", stdin);
    //        freopen("hack.out", "w", stdout);
#endif
    fast_io();
    cout.precision(1);
    cout << fixed;
    auto start = chrono::steady_clock::now();
    string s;
    cin>>s;
    set<char> x;
    for (char c:{'W', 'E', 'N', 'S'}) {
        auto pos_w = s.find(c);
        if (pos_w != string::npos) {
            x.insert(c);
        }
    }
    if (x.count('W') && !x.count('E') || !x.count('W') && x.count('E') ||
        !x.count('N') && x.count('S') || x.count('N') && !x.count('S')) {
        cout << "No";
    } else {
        cout << "Yes";
    }

    auto end = chrono::steady_clock::now();
    debug("time", chrono::duration_cast<chrono::milliseconds>(end - start).count() / 1000.0);

}



Measured memory_bytes: 256
#include "bits/stdc++.h"
using namespace std;
#ifndef LOCAL
#define endl '\n'
#endif

#define fr(i, a, b) for(int i = a; i <= b; i++)
#define rf(i, a, b) for(int i = a; i >= b; i--)
#define pf push_front
#define pb push_back
#define eb emplace_back
#define fi first
#define se second
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
#define sz(x) (int)x.size()
#define lb lower_bound
#define ub upper_bound

typedef long long ll;
typedef long double f80;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;

int pct(int x) { return __builtin_popcount(x); }
int pct(ll x) { return __builtin_popcountll(x); }
int bt(int x) { return 31 - __builtin_clz(x); } // floor(log2(x))
int bt(ll x) { return 63 - __builtin_clzll(x); } // floor(log2(x))
int cdiv(int a, int b) { return a / b + !(a < 0 || a % b == 0); }
ll cdiv(ll a, ll b) { return a / b + !(a < 0 || a % b == 0); }
int nxt_C(int x) { int c = x & -x, r = x + c; return (((r ^ x) >> 2) / c) | r; }
ll nxt_C(ll x) { ll c = x & -x, r = x + c; return (((r ^ x) >> 2) / c) | r; }

vector<int> get_bits(int mask) {
	vector<int> bb;
	while(mask) { int b = bt(mask); bb.pb(b); mask ^= (1 << b); }
	reverse(all(bb));
	return bb;
}

int get_mask(vector<int> v) {
	int mask = 0;
	for(int x : v) { mask ^= (1 << x); }
	return mask;
}

template<typename T>
void uniq(vector<T> &v) { sort(all(v)); v.resize(unique(all(v)) - v.begin()); }

mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count());

ll rand(ll l, ll r){
	uniform_int_distribution<ll> uid(l, r);
	return uid(rng);
}

void sc() {}

template <typename Head, typename... Tail>
void sc(Head &H, Tail &... T) { cin >> H; sc(T...); }

#ifdef LOCAL
#define debug(...) cerr << "[L:" << __LINE__ << "][" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)
#else
#define debug(...) 42
#endif

// #ifndef LOCAL
// string to_string(__int128 x) {
// 	string s = "";
// 	bool neg = 0;
// 	if(x < 0) { s += "-"; neg = 1; x = -x; }
// 	if(!x) s += '0';
// 	while(x) {
// 		int rem = x % 10;
// 		s += to_string(rem);
// 		x /= 10;
// 	}
// 	reverse(s.begin() + neg, s.end());
// 	return s;
// }
// #endif

const int mod = 1e9 + 7; // 998244353;

int pwr(int a,ll b) {
	int ans = 1;
	while(b) {
		if(b & 1) ans = (ans * 1LL * a) % mod;
		a = (a * 1LL * a) % mod;
		b >>= 1;
	}
	return ans;
}

/*
	Lookout for overflows!!
	Check array sizes!!
	Clear before test cases!!
	Use the correct modulo!!
	Check for corner cases!!
	Are you forgetting something?!
	Read problem statement carefully!!!
*/

const int N = 1e5 + 5;
ll a[N];

void solve() {
	int n;
    sc(n);
    ll l = 2, r = 2;
    fr(i, 1, n) {
        sc(a[i]);
    }
    rf(i, n, 1) {
        l = cdiv(l, a[i]) * a[i];
        r = (r / a[i]) * a[i];
        if(l > r) {
            cout << -1;
            return;
        }
        r += a[i] - 1;
    }
    cout << l << " " << r << endl;
}

int main() {
	ios :: sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
	int t = 1;
	// cin >> t;
	for(int tt = 1; tt <= t; tt++) {
		solve();
	}
	return 0;
}

Measured memory_bytes: 4432
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define repI(i, d, n) for (int i = (d); i < (n); ++i)
#define reps1(i, n) for (int i = 1; i < (n); ++i)
using namespace std;
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; }

using ll = long long;
using P = pair<int, int>;
using Pl = pair<ll, ll>;
using M = map<int, int>;
using Ml = map<ll, ll>;
ll const INF = 1ll<<61;
double pi = 3.141592653589793238;

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

  vector<ll> table(n+1);
  ll ans = 0;

  for(ll i=1; i<=n; ++i) {
    for(ll j=1; i*j<=n; ++j)
        // table[i*j] += i*j;
        ans += i*j;
  }

  // reps1(i, n+1) ans += (i * table[i]);

  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 81376
#include<bits/stdc++.h>
#define in inline
#define reg register
#define int unsigned long long
#define MAX 20030813
#define f(i,l,r) for(reg int i=l;i<=r;++i)
#define F(i,l,r) for(reg int i=l;i>=r;--i)
using namespace std;
namespace qwq{
	in void read(int &o)
	{
		o=0;
		int w=1;
		char c=getchar();
		while(c<'0'||c>'9')
		{
			if(c=='-')w*=-1;
			c=getchar();
		}
		while(c>='0'&&c<='9')
		{
			o=(o<<3)+(o<<1)+(c^48);
			c=getchar();
		}
		o*=w;
	}
	in void write(int x)
	{
	   	if(x<0)putchar('-'),x=-x;
    	if(x>9)write(x/10);
    	putchar(x%10+48);
	}
	in int max(int x,int y)
	{
		return x>y?x:y;
	}
	in int min(int x,int y)
	{
		return x<y?x:y;
	}
}
using namespace qwq;
int N,M,a,ans,Max;
char last,now;
int dp[3][555555],x[555555];
signed main()
{
	read(N);
	cin>>last;
    for(reg int i=1;i<N;++i)
    {
        cin>>now;
        x[i]=(now*813-last)%19260817;
        last=now;
    }
	for(reg int i=1;i<N;++i)
    {
        for(reg int j=i+2;j<N;++j)
        {
            if(x[j]==x[i])dp[i&1][j]=dp[!(i&1)][j-1]+1;
            else dp[i&1][j]=0;
            if(dp[i&1][j]>=j-i)dp[i&1][j]=j-i-1;
            ans=max(ans,dp[i&1][j]);
        }
    }
    if(!ans)putchar('0');
    else write(ans+1);
    return 0;
}




Measured memory_bytes: 4480
//#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
#define rep(i, n) for(int i=0; i<n; ++i)
#define all(v) v.begin(), v.end()
#define rall(v) v.rbegin(), v.rend()
using namespace std;
using ll = int64_t;
using ld = long double;
using P = pair<int, int>;
using vs = vector<string>;
using vi = vector<int>;
using vvi = vector<vi>;
template<class T> using PQ = priority_queue<T>;
template<class T> using PQG = priority_queue<T, vector<T>, greater<T> >;
const int INF = 100010001;
const ll LINF = (ll)INF*INF*10;

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    int n, W;
    cin >> n >> W;
    vi v(n), w(n), m(n);
    rep(i, n) {
        cin >> v[i] >> w[i] >> m[i];
    }

    vvi dp(n+1, vi(W+1));
    rep(i, n) {
        vector<multiset<int> > ms(w[i]);
        vi fi(W+1);
        rep(j, W+1) {
            ms[j%w[i]].insert(dp[i][j]-j/w[i]*v[i]);
            fi[j] = dp[i][j]-j/w[i]*v[i];
            if(j) dp[i+1][j] = max(dp[i+1][j-1], dp[i][j]);
            if(j >= (m[i]+1)*w[i]) {
                auto itr = ms[j%w[i]].find(fi[j-(m[i]+1)*w[i]]);
                ms[j%w[i]].erase(itr);
                int now = *(ms[j%w[i]].rbegin()) + j/w[i]*v[i];
                dp[i+1][j] = max(dp[i+1][j], min(now, dp[i+1][j-w[i]]+v[i]));
            } else if(j >= w[i]) {
                dp[i+1][j] = max(dp[i+1][j], dp[i+1][j-w[i]]+v[i]);
            }
        }
    }


    cout << dp[n][W] << endl;
}


Measured memory_bytes: 7352
#include <bits/stdc++.h>
#define rep(i,n) for (int i = (0); i < (n); ++i)
#define rrep(i,n) for(int i = 1; i <= (n); ++i)
#define drep(i,n) for(int i = (n)-1; i >= 0; --i)
#define srep(i,s,t) for (int i = s; i < t; ++i)
#define rng(x) (x).begin(),(x).end()
#define rrng(x) (x).rbegin(),(x).rend()
#define limit(x,l,r) max(l,min(x,r))
#define lims(x,l,r) (x = max(l,min(x,r)))
#define isin(x,l,r) ((l) <= (x) && (x) < (r))
#define show(x) cout << #x << " = " << (x) << endl
#define show2(x,y) cout << #x << " = " << (x) << ", " << #y << " = " << (y) << endl
#define show3(x,y,z) cout << #x << " = " << (x) << ", " << #y << " = " << (y) <<  ", " << #z << " = " << (z) << endl
#define showv(v) rep(i,v.size()) printf("%d%c", v[i], i==v.size()-1?'\n':' ')
#define showv2(v) rep(j,v.size()) showv(v[j])
#define showt(t,n) rep(i,n) printf("%d%c", t[i], i==n-1?'\n':' ')
#define showt2(t,r,c) rep(j,r) showt(t[j],c)
#define showvp(p) rep(i,p.size()) printf("%d %d\n", p[i].first, p[i].second);
#define printv(v) rep(i,v.size()) printf("%d\n", v[i])
#define printt(t,n) rep(i,n) printf("%d\n", t[i])
#define incl(v,x) find(rng(v),x)!=v.end()
#define fi first
#define se second
#define pb push_back
#define eb emplace_back
#define sz(x) (int)(x).size()
#define pcnt __builtin_popcountll
#define bn(x) ((1<<x)-1)
#define dup(x,y) (((x)+(y)-1)/(y))
#define newline puts("")
#define uni(x) x.erase(unique(rng(x)),x.end())
#define SP << " " <<
using namespace std;
using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vll = vector<ll>;
using pii = pair<int, int>;
using tiii = tuple<int, int, int>;
typedef vector<pii> vp;
typedef vector<tiii> vt;
const int mod = 1000000007;
const double EPS = 1e-9;
const int INF = (1<<30)-1;
const ll INFLL = (1LL<<62)-1;
#define dame { puts("No"); return 0;}
#define yn {puts("Yes");}else{puts("No");}
inline int in() { int x; scanf("%d",&x); return x;}
//cout << fixed << setprecision(10);
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; }

int main () {
  int n = in();

  auto f = [&](int x) {
    int res = 0;
    for (int i = 1; i*i <= x; ++i) {
      if (x%i == 0) {
        if (i*i == x) res++;
        else res += 2;
      }
    }
    return res;
  };

  int ans = 0;
  for (int i = 1; i <= n; i += 2) {
    if (f(i) == 8) ans++;
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
//#pragma comment(linker,"/STACK:1024000000,1024000000")
//251103FD
//4008802802
//4008160009
using namespace std;
#define PB pop_back
#define PF pop_front
#define np next_permutation
#define eb emplace_back
#define pb push_back
#define bf push_front
#define mp make_pair
#define s second
#define f first
#define foreach(it, a) for(__typeof((a).begin()) it=(a).begin(); it!=(a).end(); it++)
#define Foreach(it, a) for(__typeof((a).rbegin()) it=(a).rbegin(); it!=(a).rend(); it++)
#define forn(i, a) for(register int i=0; i<a; i++)
#define Forn(i, a) for(register int i=1; i<=a; i++)
#define memINF 127
#define all(x) x.begin(), x.end()
#define FAST ios::sync_with_stdio(false)
#define get(x) lower_bound(all(lisan), x)-lisan.begin()

typedef long long ll;
typedef pair<int,int> pi;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef unsigned int uint;

inline int in() 
{
    int x=0, c;
    while((uint)((c=getchar())-48)>=10) 
		if(c=='-') 
			return -in();
    do 
	{ x=(x<<3)+(x<<1)+(c^48); }
	while((uint)((c=getchar())^48)<10);
    return x;
}
inline int lcm(int a, int b){return a*b/__gcd(a, b);}

const int MAX=1e5+5;

int N, l, r, mid, BIT[MAX<<1], a[MAX], sum[MAX];
vi lisan;
ll k;

inline void Add(int *bit, int i, int x)
{
    while(i<=MAX*2-2)
    {
        bit[i]+=x;
        i+=i&-i;
    }
}

inline int Sum(int *bit, int i)
{
    int ret=0;
    while(i)
    {
        ret+=bit[i];
        i-=i&-i;
    }
    return ret;
}

inline bool check(int x)
{
    memset(BIT, 0, sizeof(BIT));
    sum[0]=N+1;
    ll ret=0;
    forn(i, N)
        sum[i+1]=sum[i]+(a[i]<=x?1:-1);
    forn(i, N+1)
    {
        ret+=Sum(BIT, sum[i]-1);
        Add(BIT, sum[i], 1);
    }
    return ret*2>k;
}

int main()
{
    N=in();
    k=1LL*N*(N+1)/2;
    forn(i, N)
        a[i]=in(), lisan.pb(a[i]);
    
    sort(all(lisan));
    lisan.resize(unique(all(lisan))-lisan.begin());
    
    if(lisan.size()==1)
    {
        printf("%d\n", lisan.back());
        return 0;
    }
    
    l=0, r=lisan.size()+1;
    while(l+1<r)
    {
        mid=l+r>>1;
        if(check(lisan[mid]))
            r=mid;
        else
            l=mid;
    }
    printf("%d\n", lisan[r]);
    return 0;
}

Measured memory_bytes: 2296
n, y = map(int, input().split())

for i in range(n+1):
    for j in range(n+1-i):
        if 10000*i+5000*j+1000*(n-i-j) == y:
            print(i, j, n-i-j, sep=' ')
            exit()

print(-1, -1, -1, sep=' ')


Measured memory_bytes: 40812
n, k, c = map(int, input().split())
s = input()

left = []
i = 0
while len(left) < k:
  if s[i] == 'o':
    left.append(i)
    i += c + 1
  else:
    i += 1

right = []
i = n - 1
while len(right) < k:
  if s[i] == 'o':
    right.append(i)
    i -= c + 1
  else:
    i -= 1

right = right[::-1]

for i in range(k):
  if left[i] == right[i]:
    print(left[i] + 1)

Measured memory_bytes: 26388
////////////////////////// Author
////////////////////////// Nasim Hossain Rabbi
////////////////////////// JU-CSE28
////////////////////////// CF - imnasim3.1415
////////////////////////// UVA - imnasim3.1415
////////////////////////// Mail - imnasim3.1415@gmail.com
#include<bits/stdc++.h>
using namespace std;
#define E end()
#define B begin()
#define sz size()
#define EM empty()
#define fi first
#define se second
#define cl clear()
#define sqr(a) (a*a)
#define mk make_pair
#define pb push_back
string en="\n";
string sp=" ";
string t="hello";
string Y="YES\n";
string N="NO\n";
#define rep(i,n) for(i=0;i<n;i++)
#define Rep(i,n) for(i=1;i<=n;i++)
#define per(i,n) for(i=n-1;i>=0;i--)
#define peR(i,n) for(i=n;i>0;i--)
#define mem(a,b) memset(a,b,sizeof(a))
#define all(cont) cont.begin(),cont.end()
#define fast ios_base::sync_with_stdio(false); cin.tie(NULL);cout.tie(NULL)
#define pi 3.1415926535897932384626433832795
#define vi vector<long long>
#define vs  vector<string>
#define MX LLONG_MAX
#define MN LLONG_MIN
#define MOD 1000000007
#define vp(vi,x) cin>>x; vi.pb(x);
#define bsearch(a,x) binary_search(all(a),x)
#define LB(a,x) (lower_bound(all(a),x)-a.B)
#define UB(a,x) (upper_bound(all(a),x)-a.B)
typedef long long LL;
typedef long double LD;
typedef unsigned long long ULL;
bool isprm(LL a){for(LL i=2;i*i<=a;i++){if(a%i==0)return false;}return true;}
bool palin(string a){for(int i=0;i<a.sz;i++){if(a.at(i)!=a.at(a.sz-i-1))return 0;} return 1;}
bool isVowel(char ch){ ch=toupper(ch); if(ch=='A'||ch=='U'||ch=='I'||ch=='O'||ch=='E') return true; return false;}
int toInt(string s){int sm;stringstream ss(s);ss>>sm;return sm;}
LL bpow(LL a,LL b){if(b==0)return 1;LL r=bpow(a,b/2);if(b%2)return r*r*a;else return r*r;}
LL binpow(LL a,LL b){LL r=1;while(b>0){if(b&1)r=r*a;a=a*a;b>>=1;}return r;}
LL binpow(LL a,LL b,LL m){a%=m;LL r=1;while(b>0){if(b&1) r=r*a%m;a=a*a%m; b>>=1;}return r;}
template<typename T>inline T gcd(T a,T b){if(a<0)return gcd(-a,b);if(b<0)return gcd(a,-b);return (b==0)?a:gcd(b,a%b);}
template<typename T>inline T lcm(T a,T b) {if(a<0)return lcm(-a,b);if(b<0)return lcm(a,-b);return a*(b/gcd(a,b));}
int main()
{
//    fast;
    LL i,j,k,n,m,l,s=0,x,y,tc=1,p,q,a,b,c=0;
    bool f=0,ff=0;
    string st;
    char ch;
    while(cin>>st)
    {
        f=0;
        map<char,int>mp;
        stringstream ss(st);
        while(ss>>ch)mp[ch]++;
        for(auto it=mp.B;it!=mp.E;it++)
        {
            x=it->se;
            if(x%2)
            {
                f=1;
                break;
            }
        }
        if(f)cout<<"No"<<en;
        else cout<<"Yes"<<en;
    }
}



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

using namespace std;
typedef long long ll;

#define MOD (long long)(1e9+7)
#define INF (1LL<<60)
#define rep(i,n) for(ll i = 0; i < (n); i++)
#define rep1(i,n) for(ll i = 1; i <= (n); i++)

template<class T> inline bool chmin(T& a, T b) {
  if (a > b) {
    a = b;
    return true;
  }
  return false;
}
template<class T> inline bool chmax(T& a, T b) {
  if (a < b) {
    a = b;
    return true;
  }
  return false;
}


// 最大公約数
ll gcd(ll a, ll b)
{
  if(b == 0) return a;
  return gcd(b, a % b);
}

// mod m におけるa の逆元
ll modinv(ll a, ll m) {
  ll b = m, u = 1, v = 0;
  while (b) {
    ll t = a / b;
    a -= t * b; swap(a, b);
    u -= t * v; swap(u, v);
  }
  u %= m;
  if (u < 0) u += m;
  return u;
}

// 素因数分解
vector<pair<ll, ll>> prim;
void pf(ll n)
{
  ll s = sqrt(n);
  ll r = 0;
  for(ll i = 2; i <= s; i++) {
    if((n % i) == 0) {
      r = 0;
      do {
	r++;
	n = n / i;
      } while((n % i) == 0);
      prim.push_back({i, r});
    }
  }
  if(n > s) {
    prim.push_back({n, 1});
  }
}

void solve()
{
  ll N; cin >> N;
  // ll x, y, z; cin >> x >> y >> z;
  // ll a, b, c; cin >> a >> b >> c;
  // string s; cin >> s;
  vector<ll> a(N); rep(i, N) cin >> a[i];
  ll Q;cin >> Q;

  vector<ll> b(Q);
  vector<ll> c(Q);
  rep(i, Q) cin >> b[i] >> c[i];

  ll ttl = 0;
  vector<ll> dcnt(100100, 0);
  rep(i, N) {
    ttl += a[i];
    dcnt[a[i]] ++;
  }
  ll ans = ttl;
  rep(i, Q) {
    ans += (c[i] - b[i]) * dcnt[b[i]];
    dcnt[c[i]] += dcnt[b[i]];
    dcnt[b[i]] = 0;
    cout << ans << "\n";
  }

 
  // ll ans = 0;
  // bool ok = false;

  // cout << ans << endl;
  // cout << (ok?"Yes":"No") << endl;
}


int main(void)
{
  // ll t; cin >> t; rep(i, t)
  solve();
}









Measured memory_bytes: 6416
#include"iostream"
#include"vector"
#include"string"
using namespace std;

int main()
{
	int n, m;
	vector<string> s(110), t(110);
	cin >> n;
	for (int i = 0; i < n; i++)cin >> s[i];
	cin >> m;
	for (int i = 0; i < m; i++)cin >> t[i];
	int ans, max = 0;

	for (int i = 0; i < n; i++)
	{
		for (int j = 0; j < n; j++)
		{
			if (s[i] == s[j])ans++;
		}
		for (int j = 0; j < m; j++)
		{
			if (s[i] == t[j])ans--;
		}
		if (max < ans)max = ans;
		ans = 0;
	}
	cout << max << endl;
}


Measured memory_bytes: 256
MOD = 10**9+7
ONE = '1'.freeze
def inv(x)
    res = 1 # 逆元をどんどんかけるやつ
    beki = x # 逆元を計算したい値のMOD化でのべき乗
    (MOD - 2).to_s(2).reverse.chars do |digest|
        res = (beki * res) % MOD if digest == ONE
        beki = (beki * beki) % MOD
    end
    res
end

N = gets.chomp.to_i
str = gets.split
a = Array.new(N)
for i in 0...N do
    a[i] = str[i].to_i
end
b = Array.new(N-1)
b[-1] = a[-1] - a[-2]
for i in 2..N-1 do
    b[-i] = b[-i+1] + a[-i] - a[-i-1]
end

c = 1
for i in 2...N do
    c *= i
    c %= MOD
end
answer = 0
for i in 0...N-1 do
    answer += (b[i]*c*inv(i+1)+MOD)%MOD
    answer %= MOD
end
puts answer

Measured memory_bytes: 11924
#include <vector>
#include <iostream>
#include <string>
#include <cstdlib>
#include <algorithm>
#include <cstdio>
#include <cstring>
#include <stack>
#include <math.h>
#define rep(i, n) for(int i = 0; i < (n); ++i)
using namespace std;
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;}
const long long INF = 1LL << 60;
// spring s; cin >> s;
// cout << res << endl;
// --------write my code!!!!!----------//

int main(){
    int N; cin >> N;
    // string B; cin >> B;
    // int n; cin >> n;
    // int C[n]; rep(i,n) cin >> C[i];
    
    int V[60];
    int C[60];
    rep(i,N) cin >> V[i];
    rep(i,N) cin >> C[i];
    
    int res=0;
    rep(i,N){
        if(V[i]-C[i]>0){
            res+=V[i]-C[i];
        }
    }

    cout << res <<endl;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
	ios_base::sync_with_stdio(0);
	long long a,b,n,x,form;
	cin>>a>>b>>n;
	if(n>=b){
		x=b-1;
	}
	else{
		x=n;
	}
	form=floor((double)a*x/b)-a*floor((double)x/b);
	cout<<form<<"\n";

}


Measured memory_bytes: 3652
s = input()
ah = int(s[0:2])
be = int(s[2:])

yymm = False
mmyy = False
na = False

if 1<=ah<=12:
    mmyy = True
if 1<=be<=12:
    yymm = True

if mmyy == True:
    if yymm == True:
        print('AMBIGUOUS')
    else:
        print('MMYY')
elif yymm == True:
    print('YYMM')
else:
    print('NA')

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


int main() {
  int N;
  cin >> N;
  std::vector<int> x(N), y(N), h(N);
  rep(i,N) cin >> x[i] >> y[i] >> h[i];

  int MAX = 101;
  rep(posY,MAX) rep(posX,MAX) {
    int needH = -1;
    rep(i,N) {
      if (h[i] > 0) {
        int tmp = h[i] + abs(posY-y[i]) + abs(posX - x[i]);
        if (needH == -1) {
          needH = tmp;
        } else {
          if (needH != tmp) {
            needH = -2;
            break;
          }
        }
      }
    }
    if (needH == -2) continue;
    rep(i,N) {
      if (h[i] == 0) {
        int dist = abs(posY-y[i]) + abs(posX - x[i]);
        if (needH > dist) {
          needH = -2;
          break;
        }
      }
    }
    if (needH == -2) continue;
    cout << posX << " " << posY << " " << needH << endl;
  }
}


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


void solve(long long N){
    if(N <= 999){
        cout << "ABC" << endl;
    }else{
        cout << "ABD" << endl;
    }
}

int main(){
    long long N;
    scanf("%lld",&N);
    solve(N);
    return 0;
}


Measured memory_bytes: 256
#include <stdio.h>


int main(void)
{
  int a,b,n,i;
  char op;

  for(i =1; ;i++)
    {

    
  scanf("%d %c %d",&a,&op,&b);

      if( op == '+' )
    {
      n = a + b;
      printf("%d\n",n);
    }
 else if( op == '-' )
   {
     n = a - b;
     printf("%d\n",n);
   }
 else if( op == '*' )
   {
     n = a * b;
     printf("%d\n",n);
   }
 else if( op == '/' )
   {
     n = a/ b;
     printf("%d\n",n);
   }
 else if( op == '?' )
   {
     break;
   }

    }


  return 0;

}



Measured memory_bytes: 2052
program classified
  implicit none
  integer :: n, i, j, k
  read(*,*) n
  do i = 1, n-1
    do j = i+1, n
      do k = 1, 9
        if (btest(i,k-1) .eqv. btest(j,k-1)) cycle
        write(*,'(i0)',advance='no') k
        if (j /= n) write(*,'(a)',advance='no') " "
        exit
      end do
    end do
    write(*,*)
  end do
end program classified

Measured memory_bytes: 512
#include <iostream>
#include <vector>
#include <map>
#include <unordered_map>
#include <queue>
#include <set>
#include <algorithm>
#include <string>
#include <math.h>
#include <limits.h>
#include <stack>
#include <complex>
#include <stdlib.h>
#include <stdio.h>
#include <functional>
#include <cfloat>
#include <math.h>
#include <numeric>
#include <string.h>
#include <sys/time.h>
#include <random>


#define fs first
#define sc second
#define endl "\n"

using namespace std;

typedef long long ll;
typedef unsigned int uint;
typedef pair<int, int> P;


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

    for(int i = 0; i < s.size(); i++){
        s[i] = (s[i] - 'A' + n) % 26 + 'A';
    }

    cout << s << endl;

    return 0;
}


Measured memory_bytes: 256
#include<stdio.h>
#include<algorithm>
using namespace std;
int b[200];
int dp1[1000001];
int dp2[1000001];
int main(){
    int a;
    for(int i=0;i<200;i++){
        b[i]=i*(i+1)*(i+2)/6;
    }
    for(int i=0;i<1000001;i++)dp1[i]=dp2[i]=99999999;
    dp1[0]=dp2[0]=0;
    for(int i=0;i<1000001;i++){
        for(int j=1;j<200;j++){
            if(i+b[j]<=1000000)dp1[i+b[j]]=min(dp1[i+b[j]],dp1[i]+1);
            if(b[j]%2&&i+b[j]<=1000000)dp2[i+b[j]]=min(dp2[i+b[j]],dp2[i]+1);
        }
    }
    while(scanf("%d",&a),a){
        printf("%d %d\n",dp1[a],dp2[a]);
    }
}


Measured memory_bytes: 10376