akhauriyash/Code-Regression huggingface dataset:
//file_name:ABC65_A.cpp
#include <bits/stdc++.h>
#define fi first
#define se second
#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(a) a.begin(),a.end()
#define maxs(x,y) (x = max(x,y))
#define mins(x,y) (x = min(x,y))
#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 pb push_back
#define sz(x) (int)(x).size()
#define pcnt __builtin_popcountll
#define uni(x) x.erase(unique(rng(x)),x.end())
#define snuke srand((unsigned)clock()+(unsigned)time(NULL));
#define show(x) cout<<#x<<" = "<<x<<endl;
#define PQ(T) priority_queue<T,v(T),greater<T> >
#define bn(x) ((1<<x)-1)
#define dup(x,y) (((x)+(y)-1)/(y))
#define newline puts("")
#define v(T) vector<T>
#define vv(T) v(v(T))
using namespace std;
typedef long long int ll;
typedef unsigned uint;
typedef unsigned long long ull;
typedef pair<int,int> P;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<P> vp;
inline int in() { int x; scanf("%d",&x); return x;}
template<typename T>inline istream& operator>>(istream&i,v(T)&v)
{rep(j,sz(v))i>>v[j];return i;}
template<typename T>string join(const v(T)&v)
{stringstream s;rep(i,sz(v))s<<' '<<v[i];return s.str().substr(1);}
template<typename T>inline ostream& operator<<(ostream&o,const v(T)&v)
{if(sz(v))o<<join(v);return o;}
template<typename T1,typename T2>inline istream& operator>>(istream&i,pair<T1,T2>&v)
{return i>>v.fi>>v.se;}
template<typename T1,typename T2>inline ostream& operator<<(ostream&o,const pair<T1,T2>&v)
{return o<<v.fi<<","<<v.se;}
template<typename T>inline ll suma(const v(T)& a) { ll res(0); for (auto&& x : a) res += x; return res;}
const double eps = 1e-10;
const ll LINF = 1001002003004005006ll;
const int INF = 1001001001;
#define dame { puts("-1"); return 0;}
#define yn {puts("Yes");}else{puts("No");}
const int MX = 200005;

    // int scan
    /*
    int x;
    scanf("%d",&x);
    int y;
    scanf("%d",&y);
    int z;
    scanf("%d",&z);

    // matrix scan
    /*
    ll a[n] = {};
    rep(i,n){
        scanf("%lld",&a[i]);
    }
    */

    // string scan
    /*
    string s;
    cin >> s;
    */


int main() {
    int x,a,b;
    scanf("%d%d%d",&x,&a,&b);

    if(b<=a){
        puts("delicious");
    }else if(a+x<b){
        puts("dangerous");
    }else{
        puts("safe");
    }

    return 0;
}



Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <string>
#include <cstring>
#include <algorithm>
#include <map>
#define REP(i, n) for(int i = 0; i < n; ++i)
#define RANGE(i, x, n) for(int i = x; i < n; ++i)
using namespace std;

int main()
{
    int N, C, K;
    cin >> N >> C >> K;
    vector<double> T(N, 0);
    vector<int> P(N, 0);
    REP(i, N) {
        cin >> T[i];
    }
    sort(T.begin(), T.end());
    int ans = 0, curp = 0;
    int bef = T[0] + K;
    REP(i, N) {
        if(T[i] <= bef) {
            ++curp;
            if(curp == C) {
                ++ans;
                curp = 0;
                if(i < N - 1) {
                    bef = T[i + 1] + K;
                }
            }
        }else {
            ++ans;
            curp = 0;
            bef = T[i] + K;
            --i;
        }
    }
    if(curp != 0) {
        ++ans;
    }
    cout << ans << endl;
}


Measured memory_bytes: 1408
#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<cmath>
#include<algorithm>
#include<cstring>
#include<ctime>
#include<deque>
#include<sstream>
#include<iomanip>
#include<sstream>
#include<vector>
#include<queue>
#include<stack>
#include<string>
#include<climits>
#include<map>
#include<set>
#include<list>
#include<cassert>
#include<deque>
#define REP(i,s,n) for(int i=s;i<n;i++)
#define rep(i,n) REP(i,0,n)
#define INF 1<<27
#define all(n) n.begin(),n.end()
#define insert(a,b,c,d) PP(P(a,b),P(c,d))
#define F first
#define S second
#define pb push_back
#define foreach(i,c) for(iter(c) i=(c).begin();i!=(c).end();++i)
using namespace std;
typedef pair<int,int> P;
typedef pair<P,P> PP;
typedef long long ll;
typedef unsigned long long ull;

double heroin(double a,double b,double c){
  double s = (a+b+c)*0.5;
  return sqrt(s*(s-a)*(s-b)*(s-c));
}

int main(){
  double a,l,x;
  while(cin >> a >> l >> x)
    {
      double area = heroin(a,l,l);
      area += 2*heroin(l,(l+x)*0.5,(l+x)*0.5);
      cout << setiosflags(ios::fixed) << setprecision(10) <<  area << endl;
    }
  return 0;
}

Measured memory_bytes: 1280
#include <bits/stdc++.h>
using namespace std;
int main()
{
	string s;	
	long int x,n;
	cin>>x;
	s=to_string(x);


	
	n=s.size();
	int i,d=0,y=s[0]-'0';
	y=y+((n-1)*9);
	y--;
	if(x<10)
	{
		cout<<x<<endl;
		return 0;
	}		
	for(i=0;i<n;i++)
	{
		
		if(s[i]=='9')
		{
			d++;
		}
	
		if(d==n-1 && s[0]!='9')
		{
			
			y++;
		}
		if(d==n)
		{
			cout<<n*9<<endl;
			return 0;
		}
	}
		cout<<y<<endl;
	
	
}

Measured memory_bytes: 3592
#define _GLIBCXX_DEBUG
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
//#define int long long
#include <bits/stdc++.h>
using namespace std;
int f(int n){
    int c = 0; 
    while (n%2 == 0){
        n /= 2;
        c++;
    }
    return c;
}
int main(){
    int n,a;
    cin >> n;
    vector<int> r(n);
    rep(i,n) {
        cin >> a;
        r[i] = f(a);
    }
    cout << *min_element(r.begin(),r.end()) << endl;
}

Measured memory_bytes: 384
#include<bits/stdc++.h> 
using namespace std;
int main(){
	int a,b,c,ans=3;
	cin >> a >> b >> c;
	if(a==b){
		ans--;
	}
	if(b==c){
		ans--;
	}
	if(c==a){
		ans--;
	}
	if(ans==0){
		ans++;
	}
	cout << ans << endl;
	return 0;
}

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

#define FOR(i,l,r) for(int i = (l);i < (r);i++)
#define PB push_back
#define MP make_pair
#define ALL(x) (x).begin(),(x).end()
typedef long long ll;

string S;
int cnt [256];

int main()
{
	cin >> S;
	FOR(i,0,S.size()){
		cnt [S [i]]++;
	}
	FOR(i,0,256){
		if(cnt [i] % 2){
			cout << "No" << endl;
			return 0;
		}
	}
	cout << "Yes" << endl;

	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using str = string;
using ll = long long;
#define REP(i,n) for(int i=0; i<int(n); i++)
#define RREP(i,n) for(int i=int(n)-1; i>=0; i--)
#define FOR(i,f,t) for(int i=int(f); i<=int(t); i++)
#define RFOR(i,f,t) for(int i=int(f); i>=int(t); i--)
#define ALL(vec) (vec).begin(),(vec).end()
#define ASORT(vec) sort(ALL(vec))
#define DSORT(vec) sort(ALL(vec), greater<int>());
#define MAX(x) *max_element(ALL(x))
#define MIN(x) *min_element(ALL(x))
#define YES(ans) if(ans) cout<<"YES"<<endl; else cout<<"NO"<<endl;
#define Yes(ans) if(ans) cout<<"Yes"<<endl; else cout<<"No"<<endl;
#define yes(ans) if(ans) cout<<"yes"<<endl; else cout<<"no"<<endl;
#define INF 1000000000000
#define NOD 1000000007
#define PI 3.141592653589793238462643

int main() {
    str t;
    cin >> t;
    REP(i, t.size()) if(t[i] == '?') t[i] = 'D';
    cout << t << endl;
}


Measured memory_bytes: 3756
#include <bits/stdc++.h>
#define be(v) (v).begin(),(v).end()
#define pb(q) push_back(q)
typedef long long ll;
using namespace std;
const ll mod=1000000007, INF=mod*mod*3LL;
#define doublecout(a) cout<<fixed<<setprecision(10)<<a<<endl;

int main() {
    cin.tie(0);
    cout.tie(0);
    ios::sync_with_stdio(false);
    ll n, ans = -INF, idx;
    cin >> n;
    vector<ll> a(n);
    for(int i=0;i<n;i++){
    	cin >> a[i];
    }
    vector<ll> dp(n, 0);
    vector<vector<ll> > v(n);
    for(ll i=0LL;i<n;i++){
    	ll id = -1, ma = -INF;
    	for(ll j=i;j>=0;j-=2){
    		if(ma < dp[j]) ma = dp[j], id = j;
    	}
    	dp[i] = ma + a[i];
    	if(ans < dp[i]){
    		ans = dp[i];
    		idx = i;
    	}
    	v[i] = v[id];
    	v[i].pb(i);
    }
    cout << ans << endl;
    reverse(be(v[idx]));
    vector<ll> c, b = v[idx];
    for(int i=n-1;i>b[0];i--){
    	c.pb(i);
    }
    idx = b[0] - 2;
    ll id = 1;
    n = b.size();
    while(id < n){
    	while(b[id] < idx) c.pb(idx),idx -= 2;
    	c.pb(idx + 1);
    	idx -= 2;
    	id++;
    }
    for(ll i=0LL;i<b[n-1];i++) c.pb(0);
    cout << c.size() << endl;
    for(auto& i: c){
    	cout << i+1 << endl;
    }
    return 0;
}


Measured memory_bytes: 3456
#include <bits/stdc++.h>
using namespace std;
#define fol(i,n) for(int i=0;i<n;i++)
#define pb push_back
#define pf push_front
typedef long long ll;
typedef pair<int,int> P;
typedef vector<P> vip;

int main(){
    int n;cin>>n;
    list<int>ans;
    int a;
    fol(i,n){
        cin >>a;
        i%2?ans.pf(a):ans.pb(a);
    }
    if (n%2) reverse(ans.begin(),ans.end());
    list<int>::iterator itr=ans.begin();
    fol(i,n-1) {
        cout << *itr<<" ";
        itr++;
    }
    cout << *itr<<endl;
    return 0;
}


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

int main() {
  vector<int> flight(3);
  for (int i = 0; i < 3; i++) {
    cin >> flight.at(i);
  }
  sort(flight.begin(), flight.end());
  cout << flight.at(0) + flight.at(1) << endl;
}

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

#define FOR(i,l,r) for(int i = (l);i < (r);i++)
#define ALL(x) (x).begin(),(x).end()
template<typename T> bool chmax(T& a,const T& b){return a < b ? (a = b,true) : false;}
template<typename T> bool chmin(T& a,const T& b){return b < a ? (a = b,true) : false;}
typedef long long ll;

int N;
const int MAX_N = 20000;

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

	cin >> N;
	vector<int> P(N);
	FOR(i,0,N){
		cin >> P [i];
	}

	vector<int> A(N + 1),B(N + 1);
	for(int i = 1;i <= N;i++){
		A [i] = MAX_N * i;
		B [i] = MAX_N * (N - i + 1);
	}

	FOR(i,1,N){
		if(P [i] > P [i - 1]){
			A [P [i]] += i;
		}
		else{
			B [P [i]] += i;
		}
	}

	for(int i = 1;i <= N;i++){
		cout << A [i] << (i == N ? "\n" : " ");
	}
	for(int i = 1;i <= N;i++){
		cout << B [i] << (i == N ? "\n" : " ");
	}

	return 0;
}


Measured memory_bytes: 896
#include <bits/stdc++.h>
#define rep(i,a,b) for(int i=a;i<(b);++i)
#define erep(i,a,b) for(int i=a;i<=(int)(b);++i)
#define per(i,a,b) for(int i=(b);i>(a);--i)
#define eper(i,a,b) for(int i=((int)(a));i>=b;--i)
#define pb push_back
#define mp make_pair
#define INF 2000000000
#define MOD 1000000007
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
int dy[]={0, 0, 1, -1};
int dx[]={1, -1, 0, 0};
int gcd(int a,int b){return b?gcd(b,a%b):a;}
int lcm(int a,int b){return a/gcd(a, b)*b;}

ll n, m, a[1005][3], t_ans = -(ll)(10e10);
int main() {
 ios::sync_with_stdio ( false );
 cin.tie ( 0 );
    cin >> n >> m;
    rep(i, 0, n) {
        rep(j, 0, 3) cin >> a[i][j];
    }
    rep(k, 0, 8) {
        vector<ll> v;
        ll ans = 0;
        rep(i, 0, n) {
            ll sum = 0LL;
            rep(j, 0, 3) {
                if ((k / (1 << j)) % 2 == 0) sum += a[i][j];
                else sum -= a[i][j];
            }
            v.pb(sum);
        }
        sort(v.begin(), v.end(), greater<ll>());
        rep(i, 0, m) ans += v[i];
        t_ans = max(t_ans, ans);
    }
    cout << t_ans << endl;
    return 0;
}


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

using namespace std;
typedef long long ll;
//typedef unsigned long long ll;

#define rep(i, n) for (int i = 0; i < (n); ++i)
//#define rep(i, n) for (ll i = 0; i < (n); ++i)
//#define sz(x) ll(x.size())
//typedef pair<ll, int> P;
typedef pair<ll, ll> P;
//const double INF = 1e10;
const ll INF = LONG_LONG_MAX / 10;
//const ll INF = 1e15;
const ll MINF = LONG_LONG_MIN;
//const int INF = INT_MAX / 10;
#define cmin(x, y) x = min(x, y)
#define cmax(x, y) x = max(x, y)
//typedef pair<int, int> P;
//typedef pair<double, double> P;

bool contain(set<P> &s, P a) { return s.find(a) != s.end(); }

//ifstream myfile("C:\\Users\\riku\\Downloads\\0_00.txt");
//ofstream outfile("log.txt");
//outfile << setw(6) << setfill('0') << prefecture << setw(6) << setfill('0') << rank << endl;
// std::cout << std::bitset<8>(9);


void print_line(vector<ll> &line) {
    if (line.size() == 0ll) {
        cout << endl;
        return;
    }
    for (ll i = 0; i < line.size(); i++) {
        cout << line[i];
        if (i == line.size() - 1) cout << endl;
        else cout << ' ';
    }
}


typedef priority_queue<long long, vector<long long>, greater<long long>> PQ_ASK;
const int mod = 1000000007;


int main() {

    int n, q;
    cin >> n >> q;

    vector<stack<ll>> ss(n);

    rep(i, q) {
        int query, t;
        cin >> query >> t;
        if (query == 0) {
            ll x;
            cin >> x;
            ss[t].push(x);
        } else if (query == 1) {
            if (ss[t].empty()) continue;
            cout << ss[t].top() << endl;
        } else if (query == 2) {
            if (ss[t].empty()) continue;
            ss[t].pop();
        }
    }

}


Measured memory_bytes: 5144
#include <iostream>

using namespace std;

struct Dice
{
    int lable1;
    int lable2;
    int lable3;
    int lable4;
    int lable5;
    int lable6;
};

struct Dice numA, numB;

void mN(Dice &num)
{
    int tmp = num.lable1;
    num.lable1 = num.lable2;
    num.lable2 = num.lable6;
    num.lable6 = num.lable5;
    num.lable5 = tmp;
    
    return ;
}

void mS(Dice &num)
{
    int tmp = num.lable1;
    num.lable1 = num.lable5;
    num.lable5 = num.lable6;
    num.lable6 = num.lable2;
    num.lable2 = tmp;
    
    return ;
}
    
void mE(Dice &num)
{
    int tmp = num.lable1;
    num.lable1 = num.lable4;
    num.lable4 = num.lable6;
    num.lable6 = num.lable3;
    num.lable3 = tmp;
    
    return ;
}

void mW(Dice &num)
{
    int tmp = num.lable1;
    num.lable1 = num.lable3;
    num.lable3 = num.lable6;
    num.lable6 = num.lable4;
    num.lable4 = tmp;
    
    return ;
}

void mSpin(Dice &num)
{
    int tmp = num.lable2;
    num.lable2 = num.lable4;
    num.lable4 = num.lable5;
    num.lable5 = num.lable3;
    num.lable3 = tmp;
    
    return ;
}

int main()
{
    bool bFlag = false;
    
    cin >> numA.lable1 >> numA.lable2 >> numA.lable3 >> numA.lable4 >> numA.lable5 >> numA.lable6;
    cin >> numB.lable1 >> numB.lable2 >> numB.lable3 >> numB.lable4 >> numB.lable5 >> numB.lable6;

    for (int i = 0; i < 4; i++)
    {
        for (int j = 0; j < 4; j++)
        {
            if ((numA.lable1 == numB.lable1) && (numA.lable2 == numB.lable2)
                && (numA.lable3 == numB.lable3) && (numA.lable4 == numB.lable4)
                && (numA.lable5 == numB.lable5) && (numA.lable6 == numB.lable6))
            {
                bFlag = true;
                break;
            }
            
            mSpin(numB);
        }
        
        if (true == bFlag)
        {
            break;
        }
        
        mN(numB);
    }
    
    mE(numB);
    
    for (int i = 0; i < 4; i++)
    {
        for (int j = 0; j < 4; j++)
        {
            if ((numA.lable1 == numB.lable1) && (numA.lable2 == numB.lable2)
                && (numA.lable3 == numB.lable3) && (numA.lable4 == numB.lable4)
                && (numA.lable5 == numB.lable5) && (numA.lable6 == numB.lable6))
            {
                bFlag = true;
                break;
            }
            
            mSpin(numB);
        }
        
        if (true == bFlag)
        {
            break;
        }
        
        mN(numB);
    }
    
    if (true == bFlag)
    {
        cout << "Yes" << endl;
    }
    else
    {
        cout << "No" << endl;
    }
    
    return 0;
}



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

using namespace std;

int main(){
    long long n;
    cin >> n;
    long long a[n];
    for(int i=0; i<n; i++){
        cin >> a[i];
    }
    if(a[n-1]!=2){
        cout << -1; return 0;
    }
    long long i=n-2, min=2, max=3;
    while(i>=0){
        if((min-1)/a[i]<max/a[i]){
            min=((min-1)/a[i]+1)*a[i];
            max=(max/a[i]+1)*a[i]-1;
        }
        else{
            cout << -1;return 0;
        }
        i--;
    }
    cout << min << " " << max;
    return 0;
}

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

using namespace std;
// #define int long long
mt19937 rnd(time(0));
typedef long long ll;
typedef long double ld;

// #define _GLIBCXX_DEBUG
#define f first
#define s second
#define pb push_back
#define pii pair<int, int> 
#define vi vector<int>
#define int ll

void solve(){
    int a, b;
    cin >> a >> b;
    cout << a / __gcd(a, b) * b << endl;
}

signed main(){
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    
    int t = 1;
    while(t--){
        solve();
    }
    
    return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<algorithm>
#define int long long
using namespace std;
int ok[213456];
signed main() {
	for (int y = 0; y < 10; y++) {
		for (int z = 0; z < 213456; z++) {
			ok[z] = 0;
		}
		int n, k, a, cnt = 0, sum = 0, ans = 0; cin >> n >> k;
		if (n == 0 && k == 0) { continue; }
		int mae = 0, ato = 0, husi = 0;
		for (int h = 0; h < k; h++) {
			cin >> a; ok[a] = 1;
			if (a == 0) { cnt++; }
		}
		if (cnt == 0) {
			for (int h = 1; h <= n; h++) {
				if (ok[h] == 1) { sum++; }
				else {
					ans = max(sum, ans); sum = 0;
				}
			}
		}
		else {
			for (int h = 1; h <= n; h++) {
				if (ok[h] == 1) {
					mae++; ato++;
				}
				else {
					if (husi % 2 == 0) { ans = max(ans, mae); mae = 0; ato++; }
					else { ans = max(ans, ato); mae++; ato = 0; }
					husi++;
				}
				ans = max(ans, max(mae, ato));
			}
		}
		cout << ans << endl;
	}
	return 0;
}


Measured memory_bytes: 4756
N, M = map(int, input().split())
G = [[] for i in range(N)]
for i in range(M):
    a, b = map(int, input().split())
    G[a-1].append(b-1)
    G[b-1].append(a-1)

dp = [{-1: -1} for i in range(N)]
mark = {}
Q = int(input())
col = [0]*(Q+1)
col[-1] = 0
C = []
for i in range(Q):
    v, d, c = map(int, input().split())
    col[i] = c
    C.append((v-1, d))

def dfs(v, d, idx):
    if d <= max(dp[v]):
        return
    dp[v][d] = idx
    if d:
        for w in G[v]:
            dfs(w, d-1, idx)

for i in range(Q-1, -1, -1):
    v, d = C[i]
    dfs(v, d, i)
print(*(col[max(e.values())] for e in dp), sep='\n')

Measured memory_bytes: 80956
# 因数を昇順に全列挙
from collections import Counter
import math
def com(n,r):
    return math.factorial(n) // (math.factorial(n-r) * math.factorial(r))
fac_list = []
def factoring(n):
    for i in range(2,n+1):
        if n % i == 0:
            fac_list.append(i)
            n = n // i
            break
    if n == 1:
        return fac_list
    else:
        return factoring(n)
# (素因数,指数)
n = int(input())
c = list(Counter(factoring(math.factorial(n))).values())
# 指数 (2,4,4),(2,24),(4,14),(74) の場合の数
l = [0]*5 # [2,4,14,24,74]
for e in c:
    if e >= 74:
        index = 4
    elif e >= 24:
        index = 3
    elif e >= 14:
        index = 2
    elif e >= 4:
        index = 1
    elif e >= 2:
        index = 0
    else:
        continue
    l[index] += 1
sum_l = sum(l)
num_74 = l[4]
if sum_l - l[0] - 1 > 0:
    num_4_14 = (l[2] + l[3] + l[4])*(sum_l - l[0] - 1)
else:
    num_4_14 = 0
if sum_l - 1 > 0:
    num_2_24 = (l[3] + l[4])*(sum_l - 1)
else:
    num_2_24 = 0
if sum_l - l[0] >= 2:
    num_2_4_4 = com(sum_l-l[0],2)*(sum_l - 2)
else:
    num_2_4_4 = 0
ans = num_74 + num_4_14 + num_2_24 + num_2_4_4
print(ans)

Measured memory_bytes: 3436
using System;

namespace ConsoleApp1
{
    class Program
    {
        static void Main(string[] args)
        {

            string[] input = Console.ReadLine().Split(' ');
            int N = Int32.Parse(input[0]);
            int L = Int32.Parse(input[1]);

            int first_aji = L;
            int aji = 0;
            int abs_min = 9999;
            for(int i = 1; i<=N; i++)
            {
                if (Math.Abs(abs_min) > Math.Abs(L + i - 1))
                {
                    abs_min = L + i - 1;
                }
                aji += L + i - 1;
            }

            aji = aji - abs_min;

            Console.WriteLine(aji);
        }
    }
}


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

using ll = long long;
using namespace std;

#define FOR(i,a,b) for(int i = (int)(a); i <= (int)(b); i++)
#define FORR(i,a,b) for(int i = (int)(a); i >= (int)(b); i--)
#define REP(i,n) FOR(i,0,(int)(n)-1)
#define REPR(i,n) FORR(i,(int)(n)-1,0)

#define LFOR(i,a,b) for(ll i = (ll)(a); i <= (ll)(b); i++)
#define LFORR(i,a,b) for(ll i = (int)(a); i >= (ll)(b); i--)
// #define LREP(i,n) LFOR(i,0,(ll)(n)-1)
// #define LREPR(i,n) LFORR(i,(ll)(n)-1,0)

#define SIZ(v) int(v.size())
const int INF = 1e8;
const ll LINF = 1e15;
const int MOD = 1e9+7;



int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  int n,k,ans=0;
  cin >> n >> k;
  REP(i,n){
    int a;
    cin >> a;
    if(a>=k) ans++;
  }
  cout << ans << endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <queue>
#include <map>
using namespace std;
int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};

void fill(int x, int y, int c, vector<vector<int> > &map){
  map[x][y] = c;
  for(int i=0; i<4; i++){
    int nx = x+dx[i];
    int ny = y+dy[i];
    if(nx<0 || ny<0 || nx>=(int)map.size() || ny>=(int)map[0].size()) continue;
    if(map[nx][ny] == 0){
      map[nx][ny] = c;
      fill(nx, ny, c, map);
    }
  }
}

int main(){
  while(1){
    int n;
    cin >> n;
    if(n==0) break;

    vector<int> l(n),t(n),r(n),b(n);
    priority_queue<int> x, y;
    for(int i=0; i<n; i++){
      cin >> l[i] >> t[i] >> r[i] >> b[i];
      x.push(-l[i]);
      x.push(-r[i]);
      y.push(-t[i]);
      y.push(-b[i]);
    }

    int numx=1, numy=1;
    map<int, int> xtoidx, ytoidx;
    int prev=-1;
    while(!x.empty()){
      if(-x.top() != prev){
        prev = -x.top();
        xtoidx[-x.top()] = numx;
        numx += 2;
      }
      x.pop();
    }
    prev = -1;
    while(!y.empty()){
      if(-y.top() != prev){
        prev = -y.top();
        ytoidx[-y.top()] = numy;
        numy += 2;
      }
      y.pop();
    }

    vector<vector<int> > plane(numx, vector<int>(numy, 0));
    for(int i=0; i<n; i++){
      for(int j=xtoidx[l[i]]; j<=xtoidx[r[i]]; j++){
        plane[j][ytoidx[t[i]]] = plane[j][ytoidx[b[i]]] = -1;
      }
      for(int j=ytoidx[b[i]]; j<=ytoidx[t[i]]; j++){
        plane[xtoidx[l[i]]][j] = plane[xtoidx[r[i]]][j] = -1;
      }
    }

    int count = 0;
    for(int i=0; i<numx; i++){
      for(int j=0; j<numy; j++){
        if(plane[i][j]==0){
          count++;
          fill(i, j, count, plane);
        }
      }
    }
    cout << count << endl;
  }
  return 0;
}

Measured memory_bytes: 5464
#include <bits/stdc++.h>
#define whlie while
#define pb push_back
#define eb emplace_back
#define fi first
#define se second
#define rep(i,N) for(int i = 0; i < (N); i++)
#define repr(i,N) for(int i = (N) - 1; i >= 0; i--)
#define rep1(i,N) for(int i = 1; i <= (N) ; i++)
#define repr1(i,N) for(int i = (N) ; i > 0 ; i--)
#define each(x,v) for(auto& x : v)
#define all(v) (v).begin(),(v).end()
#define sz(v) ((int)(v).size())
#define ini(...) int __VA_ARGS__; in(__VA_ARGS__)
#define inl(...) ll __VA_ARGS__; in(__VA_ARGS__)
#define ins(...) string __VA_ARGS__; in(__VA_ARGS__)
using namespace std; void solve();
using ll = long long; using vl = vector<ll>;
using vi = vector<int>; using vvi = vector< vector<int> >;
constexpr int inf = 1001001001;
constexpr ll infLL = (1LL << 61) - 1;
struct IoSetupNya {IoSetupNya() { cin.tie(nullptr); ios::sync_with_stdio(false); cout << fixed << setprecision(15); cerr << fixed << setprecision(10);} } iosetupnya;
template<typename T, typename U> inline bool amin(T &x, U y) { return (y < x) ? (x = y, true) : false; }
template<typename T, typename U> inline bool amax(T &x, U y) { return (x < y) ? (x = y, true) : false; }
template<typename T, typename U> ostream& operator <<(ostream& os, const pair<T, U> &p) { os << p.first << " " << p.second; return os; }
template<typename T, typename U> istream& operator >>(istream& is, pair<T, U> &p) { is >> p.first >> p.second; return is; }
template<typename T> ostream& operator <<(ostream& os, const vector<T> &v) { int s = (int)v.size(); rep(i,s) os << (i ? " " : "") << v[i]; return os; }
template<typename T> istream& operator >>(istream& is, vector<T> &v) { for(auto &x : v) is >> x; return is; }
void in(){} template <typename T,class... U> void in(T &t,U &...u){ cin >> t; in(u...);}
void out(){cout << "\n";} template <typename T,class... U> void out(const T &t,const U &...u){ cout << t; if(sizeof...(u)) cout << " "; out(u...);}
template<typename T>void die(T x){out(x); exit(0);}
#ifdef NyaanDebug
  #include "NyaanDebug.h"
  #define trc(...) do { cerr << #__VA_ARGS__ << " = "; dbg_out(__VA_ARGS__);} while(0)
  #define trca(v,N) do { cerr << #v << " = "; array_out(v , N);cout << endl;} while(0)
#else
  #define trc(...)
  #define trca(...)
  int main(){solve();}
#endif
using P = pair<vi,int>; using vp = vector<P>;
constexpr int MOD = /** 1000000007; //*/ 998244353;
////////////////

void solve(){
  ini(N);
  ins(S);
  vi a(N);
  rep(pat , 4){
    a[0] = pat & 1;
    a[1] = (pat >> 1) & 1;
    for(int i = 2 ; i < N ; i++){
      a[i] = a[i - 2];
      a[i] ^= ( (S[i - 1] == 'x') ^ a[i - 1] );
    }
    trc(a);
    int nya  = (S[0] == 'x' ) ^ a[0];
    int nyan = (S[N-1] == 'x')^ a[N - 1];
    if(a[N - 1] != (a[1] ^ nya ) ) continue;
    if(a[N - 2] != (a[0] ^ nyan) ) continue;

    rep(i , N){cout << (a[i]==0 ? "S" : "W"); };
    cout << endl; exit(0);

  }
  out(-1);
}

Measured memory_bytes: 976
import sys
import math

N, M = map(int ,sys.stdin.readline().strip().split())


class UnionFind():
    def __init__(self, n):
        self.n = n
        self.parents = [-1] * n

    def find(self, x):
        if self.parents[x] < 0:
            return x
        else:
            self.parents[x] = self.find(self.parents[x])
            return self.parents[x]

    def union(self, x, y):
        x = self.find(x)
        y = self.find(y)

        if x == y:
            return

        if self.parents[x] > self.parents[y]:
            x, y = y, x

        self.parents[x] += self.parents[y]
        self.parents[y] = x

    def size(self, x):
        return -self.parents[self.find(x)]

    def same(self, x, y):
        return self.find(x) == self.find(y)

    def members(self, x):
        root = self.find(x)
        return [i for i in range(self.n) if self.find(i) == root]

    def roots(self):
        return [i for i, x in enumerate(self.parents) if x < 0]

    def group_count(self):
        return len(self.roots())

    def all_group_members(self):
        return {r: self.members(r) for r in self.roots()}


uf = UnionFind(N)
for m in range(M):
    A, B = map(int, sys.stdin.readline().strip().split())
    A -= 1
    B -= 1
    uf.union(A, B)

ans = 0

for n in range(N):
    ans = max(ans, uf.size(n))

print(ans)


Measured memory_bytes: 73152
import collections

s = []
a = 0
x = input()
if len(x) % 2 != 0:
    print('No')
else:
    for i in x:
        s.append(i)
    c = collections.Counter(s)
    values, counts = zip(*c.most_common())
    for j in counts:
        if j % 2 == 0:
            a += 1
    if len(counts) == a:
        print('Yes')
    else:
        print('No')

Measured memory_bytes: 3316
#include <iostream>
#include <map>
#include <queue>
#include <cmath>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
using namespace std;
#pragma warning (disable: 4996)

bool prime(int x) {
	for (int i = 2; i * i <= x; i++) {
		if (x % i == 0) return false;
	}
	return true;
}

int main() {
	int X;
	cin >> X;
	for (int i = X; i <= 10000000; i++) {
		if (prime(i) == true) {
			cout << i << endl;
			return 0;
		}
	}
	return 0;
}

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

int main() {
  int x, n, a;//aは答え
  cin >> x >> n;
  if (n == 0) {//これが必要かは後ほど
    a = x;
  }
  
  set<int> p;
  for (int i = 0; i < n; i++) {
    int pi;
    cin >> pi;
    p.insert(pi);
  }
  set<int> q;//pが持ってない数字セット0～101
  for (int i = 0; i <= 101; i++) {
    if (!p.count(i)) {
      q.insert(i);
    }
  }
  
  if (q.count(x)) {
    a = x;
  }else {
    for (int i = 1; i <= 100; i++) {
      if (q.count(x - i)) {
        a = x - i;
        break;
      }else if (q.count(x + i)) {
        a = x + i;
        break;
      }
    }
  }
  cout << a << endl;
}

Measured memory_bytes: 3636
#include <iostream>
#include <sstream>
#include <iomanip>
#include <stdio.h>
#include <string>
#include <cstdlib>
#include <stdexcept>
#include <algorithm>
#include <set>
#include <map>
#include <stdlib.h>
using namespace std;
int main(){
    long int N,K,p,i;
    cin >> N >> K;
    p = K;
    K--;
    for(i = 1;i < N;i++){
        p *= K;
    }
    cout << p << endl;
}

Measured memory_bytes: 3548
#include<bits/stdc++.h>
#define inf 100000000000
#define int long long int
#define hell (int)(1e9+7)

using namespace std;

void solve(){
    string s;
    cin>>s;
    if(s[2]==s[3]&&s[4]==s[5])
        cout<<"Yes";
    else
        cout<<"No";
}

signed main()
{
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
	int t;
	//cin>>t;
	t=1;
	while(t--){
		solve();
	}
	return 0;
}


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

using namespace std;

typedef long long int ll;

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

  int n;
  cin >> n;
  cout << (1000 - (n % 1000)) % 1000 << '\n';
}


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

int main() {
  int n,x,temp;
  int f = 0;
  cin >> n;
  x = n;
  for(int i=8;i>=0;i--) {
    temp = pow(10,i);
    if(n/temp!=0) {
      f += x/temp;
      x -= temp * (x/temp);
    }
  }
  if(n%f==0) {
    cout << "Yes" << endl;
  }
  else {
    cout << "No" << endl;
  }
}

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

using namespace std;
typedef long long ll;

#define FAST ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define mp make_pair
#define pb push_back
#define lp(i,s,f) for(ll i = s; i < ll(f); i++)
#define inF freopen("input.in", "r", stdin);
#define outF freopen("output.in", "w", stdout);
#define endl '\n'
#define MOD 1000000007
#define mm(arr) memset(arr, 0, sizeof(arr))
#define int ll

int32_t main(){
    FAST
    int n, k; cin >> n >> k;
    int ans = 1;
    int highest[n + 1];
    mm(highest);
    int a = n;
    int sum = 0;
    for(int i = 1; i <= n + 1; i++){
        sum += a;
        sum %= MOD;
        highest[i] = sum;
        a--;
    }
    for(int i = k; i <= n; i++){
        int l = ((i * (i - 1))/2)%MOD;
        int a = highest[i] - l;
        a++;
        a %= MOD;
        if(a < 0)a += MOD;
        ans = (ans + a)%MOD;
    }
    cout << ans;
    return 0;
}


Measured memory_bytes: 5144
n, m = map(int, input().split())
ac, wa = [0]*(n+1), [0]*(n+1)
ans1, ans2 = 0, 0
for i in range(m):
    p, s = map(str, input().split())
    if ac[int(p)]==1: continue
    if s=='AC':
        ac[int(p)] = 1
        ans1 += 1
        ans2 += wa[int(p)]
    else:
        wa[int(p)] += 1
print(ans1, ans2)


Measured memory_bytes: 4596
//#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i, n) for (int i = 0; i < (n); i++)
#define all(v) v.begin(), v.end()
#define allr(v) v.rbegin(), v.rend()

int main() {
  int n, m, L = -1, R = 1e6;
  cin >> n >> m;
  rep(i, m) {
    int l, r;
    cin >> l >> r;
    L = max(L, l);
    R = min(R, r);
  }
  cout << max(R - L + 1, 0) << endl;
  return 0;
}

Measured memory_bytes: 384
import sys
import re
import math
import collections
import decimal
import bisect
import itertools

import copy

# import heapq
# from collections import deque
# import decimal

# sys.setrecursionlimit(100001)
INF = sys.maxsize
MOD = 10 ** 9 + 7

ni = lambda: int(sys.stdin.readline())
ns = lambda: map(int, sys.stdin.readline().split())
na = lambda: list(map(int, sys.stdin.readline().split()))


# ===CODE===


def main():
    n, a, b, c, d = ns()
    a -= 1
    b -= 1
    c -= 1
    d -= 1
    s = list(input())

    stone_twice_flg = True
    for i in range(a, max(c, d)):
        if s[i] == s[i + 1] == "#":
            stone_twice_flg = False
            break

    pass_flg = False
    if c > d:
        for i in range(b, d+1):
            if s[i - 1] == s[i] == s[i + 1] == ".":
                pass_flg = True
                break
    else:
        pass_flg = True

    if stone_twice_flg and pass_flg:
        print("Yes")
    else:
        print("No")


if __name__ == '__main__':
    main()


Measured memory_bytes: 7124
#include<iostream>
#include<fstream>
#include<cstdio>
#include<algorithm>
#include<cmath>
#include<vector>
#include<deque>
#include<set>
#include<map>
#include<bitset>
#include<ctime>
#include<queue>
using namespace std;
#define int long long
#define pii pair <int, int>
#define XX first
#define YY second

// constants:
const int mn = 200005;
const int mod = 1000000007;
const long long inf = 4444444444444444444;
const int sminf = 1111111111;
const bool is_multitest = 0;
const bool is_interactive = 0;

// i/o methods:
const bool input_from_file = 0;
const bool output_to_file = 0;
#define filename ""
#define in_extension "inp"
#define out_extension "out"

// data preprocessing: (e.g.: divisor generating, prime sieve)
void preprocess()
{
    
}

// global variables:
int n;
// main solution goes here:
void execute(int test_number)
{
    cin>>n;
    if (n%1000 != 0) cout << 1000 - n%1000;
    else cout<<0;
}
// REMEMBER TO CHOOSE TEST METHODS
// PLEASE REMOVE cout AND cerr DEBUG LINES BEFORE SUBMITTING PROBLEMS
// Solution by low_



















signed main()
{
#ifdef lowie
    if (!is_interactive)
    {
        freopen("test.inp", "r", stdin);
        freopen("test.out", "w", stdout);
    }
#else
    if (input_from_file) freopen(filename"."in_extension, "r", stdin);
    if (output_to_file) freopen(filename"."out_extension, "w", stdout);
#endif
    if (!is_interactive)
    {
        ios_base::sync_with_stdio(0);
        cin.tie(0);
        cout.tie(0);
    }

    preprocess();
    int ntest;
    if (is_multitest) cin >> ntest;
    else ntest = 1;

    for (int testno = 1; testno <= ntest; testno++)
    // use for instead of while to serve facebook hacker cup test format
    {
        execute(testno); // only start coding in this function, not in main
    }
}
// Template by low_
// Contact me via mail: ttuandung1803@gmail.com
// ...or codeforces: www.codeforces.com/profiles/low_
// ...or if you're interested in food: www.instagram.com/lowie.exe/

Measured memory_bytes: 3656
#include<iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<map>
#include<math.h>
#include<queue>
#include<deque>
#include<stack>
#include<cstdio>
#include<utility>
#include<set>
#include<list>
#include<cmath>
#include<stdio.h>
#include<string.h>
#include<iomanip>
#include<cstdio>
#include<cstdlib>
#include<cstring>
using namespace std;
#define FOR(i, a, b) for (ll i = (a); i <= (b); i++)
#define REP(i, n) FOR(i, 0, n - 1)
#define NREP(i, n) FOR(i, 1, n)
using ll = long long;
using pii = pair<int, int>;
using piii = pair<pii, pii>;
const ll dx[4] = { 0, -1, 1, 0 };
const ll dy[4] = { -1, 0, 0, 1 };
const int INF = 1e9 + 7;
int gcd(int x, int y) {
	if (x < y)swap(x, y);
	if (y == 0)return x;
	return gcd(y, x%y);
}
void mul(ll a, ll b) {
	a = a * b % INF;
}
///////////////////////////////////////

int N, M;
vector<vector<pii>>G;
vector<ll>d;
const ll lint = 1001001001001001001;
bool bellman_ford(int n, int s = 0) {
	d = vector<ll>(n, lint);
	d[s] = 0;
	for (int i = 0; i < n; ++i) {
		for (int v = 0; v < n; ++v) {
			for (int j = 0; j < G[v].size(); ++j) {
				pii e = G[v][j];
				if (d[e.first] > d[v] + e.second) {
					d[e.first] = d[v] + e.second;
					if (i == n - 1 && e.first == n - 1) {
						return true;
					}
				}
			}
		}
	}
	return false;
}
int main() {
	cin >> N >> M;
	G.resize(N);
	for (int i = 0; i < M; ++i) {
		int a, b, c;
		cin >> a >> b >> c;
		a--, b--;
		G[a].push_back(make_pair(b, -c));
	}
	if (bellman_ford(N)) {
		cout << "inf" << endl;
	}
	else {
		cout << -d[N - 1] << endl;
	}
	return 0;

}

Measured memory_bytes: 256
import java.util.Scanner;


public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		while (sc.hasNext()) {
			int a = sc.nextInt();
			int b = sc.nextInt();
			System.out.println((String.format("%d", a+b).length()));
		}
	}
}

Measured memory_bytes: 20548
H, W = [int(_) for _ in input().split()]
S = [input() for _ in range(H)]

for i in range(H):
    for j in range(W):
        edge0 = (i == 0)
        edge1 = (i == H - 1)
        edge2 = (j == 0)
        edge3 = (j == W - 1)
        x = j
        if S[i][j] == "#":
            if (S[i - 1][j] == "#" if not edge0 else False) or \
                    (S[i + 1][j] == "#" if not edge1 else "") or \
                    (S[i][j - 1] == "#" if not edge2 else "") or \
                    (S[i][j + 1] == "#" if not edge3 else ""):
                continue
            else:
                print("No")
                break
    else:
        continue
    break
else:
    print("Yes")


Measured memory_bytes: 3188
import java.io.IOException;
import java.io.InputStream;
import java.util.NoSuchElementException;

public class Main {

	static int[] rsq;
	static int n;

	public static void main(String[] args) {
		FastScanner sc = new FastScanner();

		n = sc.nextInt();
		int q = sc.nextInt();
		int[] com = new int[q];
		int[] x = new int[q];
		int[] y = new int[q];
		rsq = new int[n<<1];

		for (int i=0; i<q; i++) {
			com[i] = sc.nextInt();
			x[i] = sc.nextInt();
			y[i] = sc.nextInt();
		}

		for (int i=0; i<q; i++) {
			if (com[i] == 0) {
				add(x[i]-1, y[i]);
			} else {
				getSum(x[i]-1, y[i]-1);
			}
		}

	}

	static void add(int x, int y) {
		rsq[x+n] += y;
		for (int i=x+n; i>1; i>>=1) {
			rsq[i>>1] += y;
		}
	}

	static void getSum(int x, int y) {
		int sum = 0;
		for (int i=x+n, j=y+n; i<=j; i=(i+1)>>1, j=(j-1)>>1) {
			if ((i&1)==1) {
				sum += rsq[i];
			}
			if ((j&1)==0) {
				sum += rsq[j];
			}
		}
		System.out.println(sum);
	}
}

class FastScanner {
private final InputStream in = System.in;
private final byte[] buffer = new byte[1024];
private int ptr = 0;
private int buflen = 0;
private boolean hasNextByte() {
if (ptr < buflen) {
return true;
}else{
ptr = 0;
try {
buflen = in.read(buffer);
} catch (IOException e) {
e.printStackTrace();
}
if (buflen <= 0) {
return false;
}
}
return true;
}
private int readByte() { if (hasNextByte()) return buffer[ptr++]; else return -1;}
private boolean isPrintableChar(int c) { return 33 <= c && c <= 126;}
private void skipUnprintable() { while(hasNextByte() && !isPrintableChar(buffer[ptr])) ptr++;}
public boolean hasNext() { skipUnprintable(); return hasNextByte();}
public String next() {
if (!hasNext()) throw new NoSuchElementException();
StringBuilder sb = new StringBuilder();
int b = readByte();
while(isPrintableChar(b)) {
sb.appendCodePoint(b);
b = readByte();
}
return sb.toString();
}
public long nextLong() {
if (!hasNext()) throw new NoSuchElementException();
long n = 0;
boolean minus = false;
int b = readByte();
if (b == '-') {
minus = true;
b = readByte();
}
if (b < '0' || '9' < b) {
throw new NumberFormatException();
}
while(true){
if ('0' <= b && b <= '9') {
n *= 10;
n += b - '0';
}else if(b == -1 || !isPrintableChar(b)){
return minus ? -n : n;
}else{
throw new NumberFormatException();
}
b = readByte();
}
}
public int nextInt() {
if (!hasNext()) throw new NoSuchElementException();
int n = 0;
boolean minus = false;
int b = readByte();
if (b == '-') {
minus = true;
b = readByte();
}
if (b < '0' || '9' < b) {
throw new NumberFormatException();
}
while(true){
if ('0' <= b && b <= '9') {
n *= 10;
n += b - '0';
}else if(b == -1 || !isPrintableChar(b)){
return minus ? -n : n;
}else{
throw new NumberFormatException();
}
b = readByte();
}
}
}

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

int H,W;
char E[410][410];
int checked[410][410];
int dx[4]={1,-1,0,0};
int dy[4]={0,0,1,-1};
int blk,wht;
char c; 

void dfs(int x,int y){
  
  checked[x][y]=1;
  if(E[x][y]=='#'){
    blk++;
    }
  else{
    wht++;
  }

  for(int i=0;i<4;i++){
    int ny=y+dy[i];
    int nx=x+dx[i];
    if(nx< 0 || nx >=H || ny<0 || ny>=W || checked[nx][ny]==1) continue;
    if(E[x][y] == E[nx][ny]) continue;
    dfs(nx,ny);
  }
}
 

signed main(){
  cin>>H>>W;
  string s;
  for(int i=0;i<H;i++){
    for(int j=0;j<W;j++){
      checked[i][j]=0;
    }
  }
  
  //入力
  for(int i=0;i<H;i++){
    cin>>s;
    for(int j=0;j<W;j++){
      E[i][j]=s.at(j);
      //cout<<E[i][j];
    }
    //cout<<endl;
  }

  long long ans=0;
  for(int i=0;i<H;i++){
    for(int j=0;j<W;j++){
      if(checked[i][j]==0){
        blk=0;
        wht=0;
        dfs(i,j);
        ans+=blk*wht; 
      }
    }
  }

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

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

typedef long long ll;

 
int main(){
  int k; 
  cin >> k;
  string s, ans;
  cin >> s;
  if(s.size()<=k) cout << s << endl;
  else{
    cout << s.substr(0,k) << "..." << endl;
  }
  cout << ans << endl;
  return 0;
}


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

using namespace std;

/* * * *   * * *   	* * * */
typedef long long ll;
const int oo = 1e9;
const ll mod = 100000000;
typedef complex<ll> P;
#define X real()
#define Y imag()
/* * * *   * * *   	* * * */

int main(){
	ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
	string s; cin>>s;
	int m = (s[0]-48)*10 + (s[1]-48);
	int y = (s[2]-48)*10 + (s[3]-48);
	if (m > 0 && m <= 12 ){
		if (y > 0 && y <= 12 ) cout<<"AMBIGUOUS";
		else cout<<"MMYY";
	}else if (y > 0 && y <= 12 ) cout<<"YYMM";
	else cout<<"NA";
	return 0;
}


Measured memory_bytes: 384
n = int(input())
ai = [int(i) for i in input().split()]

s = [0]
tmp = 0

for i in range(n):
    tmp += ai[i]
    s.append(tmp)
    
#print(s)
s.sort()

tmp = s[0]
ans = 0
num = 1
#print(s)

for i in range(1,n+1):
    if s[i] == tmp:
        num += 1
    else:
        #print(num,ans)
        ans += num*(num-1)//2
        tmp = s[i]
        num = 1

ans += num*(num-1)//2

print(ans)

Measured memory_bytes: 99536
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (int)(n); i ++)
#define irep(i,n) for (int i = (int)(n) - 1;i >= 0;--i)
using namespace std;
using ll = long long;
using PL = pair<ll,ll>;
using P = pair<int,int>;
constexpr int INF = 1000000000;
constexpr long long HINF = 1000000000000000;
constexpr long long MOD = 1000000007;// = 998244353;
constexpr double EPS = 1e-4;
constexpr double PI = 3.14159265358979;

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

    int N; cin >> N;
    vector<ll> A(N),B(N);
    rep(i,N) cin >> A[i] >> B[i];

    ll ans = 0;
    irep(i,N) {
        A[i] += ans;
        if (A[i]%B[i] == 0) continue;
        ans += (A[i]/B[i] + 1)*B[i] - A[i];
    }
    cout << ans << '\n';
    return 0;
}

Measured memory_bytes: 4792
n=int(input())
p=[int(i) for i in input().split()]

a=0
b=0
for i in range(n):
    if p[i]==i+1:
        if a==0 or t==i:
           a+=1
        else:
           b+=(a+1)//2
           a=1
        t=i+1
b+=(a+1)//2

print(b)

Measured memory_bytes: 13880
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define loop(i,a,b) for(ll i=(a);i<ll(b);i++)
#define rep(i,b) loop(i,0,b)
#define show(x) cout << #x << " = " << x << endl


typedef int Capacity;
struct Edge {
    int src, dst;
    Capacity cap;
    Edge(int src_, int dst_, Capacity cap_) :
        src(src_), dst(dst_), cap(cap_) { }
};
typedef vector<Edge> Edges;
typedef vector<Edges> Graph;

struct Dinic {
    int n, s, t;
    vector<int> level, vis, iter;
    vector<vector<Capacity>> cap, flow;
    vector<vector<int>> g;
    Capacity inf;
    Dinic(int n)
        : n(n), cap(n, vector<Capacity>(n)), flow(n, vector<Capacity>(n)),
          g(n, vector<int>()), inf(numeric_limits<Capacity>::max()/8){}
    Dinic(const Graph &graph){
        *this = Dinic(graph.size());
        rep(i,n) for(auto &e : graph[i]) addEdge(e.src, e.dst, e.cap);
    }
    void addEdge(int u, int v, Capacity c){
        cap[u][v] += c; cap[v][u] += c; flow[v][u] += c;
        g[u].push_back(v); g[v].push_back(u);
    }
    Capacity solve(int s, int t){
        this->t = t, this->s = s;
        Capacity res = 0, aug = 1;
        while(aug > 0){
            levelize();
            vis.assign(n, false); iter.assign(n, 0); aug = 0;
            Capacity tmp = 1;
            nextState = make_tuple(s, inf);
            while(tmp > 0) aug += (tmp = augment(get<0>(nextState), get<1>(nextState)));
            res += aug;
        }
        return res;
    }
    void levelize(){
        level.assign(n, inf); level[s] = 0;
        queue<int> q; q.emplace(s);
        while(q.size()){
            int v = q.front(); q.pop();
            for(const int &d : g[v]){
                if(level[d] <= level[v] + 1 || cap[v][d] - flow[v][d] == 0) continue;
                level[d] = level[v] + 1; q.emplace(d);
            }
        }
    }
    tuple<int,Capacity> nextState;
    Capacity augment(int v, const Capacity &lim){
        // show(v);
        vis[v] = true;
        if(v == t) return lim;
        for(int &i = iter[v]; i < (int)g[v].size(); i++){
            const int &d = g[v][i];
            if(vis[d] || flow[v][d] == cap[v][d] || level[v] + 1 != level[d]) continue;
            Capacity aug = augment(d, min(lim, cap[v][d] - flow[v][d]));
            // show(v);
            flow[v][d] += aug; flow[d][v] -= aug;
            if(aug > 0){
                // show(aug);
                if(flow[d][v] == 0){
                    get<0>(nextState) = v;
                    get<1>(nextState) = lim - aug;
                }
                return aug;
            }
        }
        return 0;
    }
};

int main(){
    int N,M;
    cin >> N >> M;
    Graph g(N);
    rep(i,M){
        int a,b,c;
        cin >> a >> b >> c;
        g[a].emplace_back(a,b,c);
    }
    Dinic dinic(g);
    cout << dinic.solve(0,N-1) << endl;
}

Measured memory_bytes: 1356
#include<bits/stdc++.h>
#define PB push_back
#define MP make_pair
#define F first
#define S second
#define MOD	1000000007
#define int	long long
#define pii pair<int,int> 
#define vi vector<int>
using namespace std;

int dp[105][100005];

int32_t main(){
	int n, w;
	cin >> n >> w;
	
	int wt[n], val[n];
	for(int i = 0; i < n; i++)
		cin >> wt[i] >> val[i];
	
	// bottom up
	for(int i = 1; i <= n; i++){
		for(int j = 1; j <= w; j++){
			dp[i][j] = dp[i-1][j];
			if(wt[i-1] <= j){
				dp[i][j] = max(dp[i][j],dp[i-1][j-wt[i-1]] + val[i-1]);
			}
		}
	}
	
	cout << dp[n][w] << endl;

	return 0;
}



Measured memory_bytes: 79360
#include <bits/stdc++.h>
#define rep(i, n) for(ll i=0;i<n;i++)
using namespace std;
template<class T>bool chmax(T &a, const T &b) { if (b>a) { 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 long long INF = 2LL << 60;
using ll = long long;
using P = pair<ll, ll>;

int main(int argc, char const *argv[]) {
    int ans=6;
    int a;
    cin >> a;
    ans-=a;
    cin >> a;
    ans-=a;
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 256
import math
from math import gcd,pi,sqrt
INF = float("inf")

import sys
sys.setrecursionlimit(10**6)
import itertools
from collections import Counter,deque
def i_input(): return int(input())
def i_map(): return map(int, input().split())
def i_list(): return list(i_map())
def i_row(N): return [i_input() for _ in range(N)]
def i_row_list(N): return [i_list() for _ in range(N)]
def s_input(): return input()
def s_map(): return input().split()
def s_list(): return list(s_map())
def s_row(N): return [s_input for _ in range(N)]
def s_row_str(N): return [s_list() for _ in range(N)]
def s_row_list(N): return [list(s_input()) for _ in range(N)]

def main():
    x,y = i_map()

    ans = 0
    while True:
        ans += 1
        x *= 2
        if x > y:
            break
    print(ans)



if __name__=="__main__":
    main()


Measured memory_bytes: 9396