akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
#define ll int64_t

int main() {
	ios_base::sync_with_stdio(0);cin.tie(0);
	int n,k;
	cin>>n>>k;
	vector<int> a(n);
	for(int& x:a) cin>>x;
	sort(a.begin(),a.end());
	int res=n,sum=0;
	for(int i=n-1;~i;--i)
		if(sum+a[i]<k) sum+=a[i];
		else res=min(res,i);
	cout<<res<<'\n';
}




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

int main(){
  int a,b,c,x,ans=0;
  cin>>a>>b>>c>>x;
  for(int i=0;i<=a;i++){
    for(int j=0;j<=b;j++){
      for(int k=0;k<=c;k++){
	if(i*500+j*100+k*50==x)ans++;
      }
    }
  }
  cout<<ans<<endl;
  return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define V vector
#define VI vector<int>
#define VVI vector<vector<int>>
#define REP(i,n) for(int i=0;i<(n);i++)
#define REPR(i,n) for(int i=n;i>=0;i--)
#define FOR(i,m,n) for(int i=m;i<n;i++)
#define MOD 1000000007
#define INF 1e9
#define F first
#define S second
#define All(x) (x).begin(),(x).end()
using namespace std;
typedef long long ll;

ll N,cnt=0;

void ch(ll s,ll v1,ll v2,ll v3){
    if(s>N)return;
    if(v1&&v2&&v3)cnt++;
    ch(s*10+3,1,v2,v3);
    ch(s*10+5,v1,1,v3);
    ch(s*10+7,v1,v2,1);
}

int main(void){
    cin>>N;
    ch(0,0,0,0);
    cout<<cnt<<endl;
}




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

#define rep(i,x,y) for(int i=(x);i<(y);++i)
#define debug(x) #x << "=" << (x)

#ifdef DEBUG
#define _GLIBCXX_DEBUG
#define show(x) std::cerr << debug(x) << " (L:" << __LINE__ << ")" << std::endl
#else
#define show(x)
#endif

typedef long long int ll;
typedef pair<int,int> pii;
template<typename T> using vec=std::vector<T>;

const int inf=1<<30;
const long long int infll=1LL<<62;
const double eps=1e-9;
const int dx[]={1,0,-1,0},dy[]={0,1,0,-1};

template <typename T> ostream &operator<<(ostream &os, const vector<T> &vec){
    os << "[";
    for (const auto &v : vec) {
    	os << v << ",";
    }
    os << "]";
    return os;
}

ll power(ll x,ll y,ll mod){
	ll result=1;
	while(y>0){
		if(y&1) result=result*x%mod;
		x=x*x%mod;
        y>>=1;
	}
	return result;
}


void solve(){
    const ll mod=1e9+7;
    ll n,c;
    cin >> n >> c;
    vector<ll> a(n),b(n);
    rep(i,0,n) cin >> a[i];
    rep(i,0,n) cin >> b[i];

    vector<vector<ll>> s(c+1,vector<ll>(401));
    rep(i,0,c+1) rep(j,1,401) s[i][j]=(s[i][j-1]+power(j,i,mod))%mod;
    vector<vector<ll>> dp(n,vector<ll>(c+1));
    rep(i,0,c+1) rep(x,a[0],b[0]+1) dp[0][i]=(dp[0][i]+power(x,i,mod))%mod;
    rep(i,1,n){
        rep(j,0,c+1){
            rep(k,0,j+1){
                dp[i][j]=(dp[i][j]+dp[i-1][j-k]*(s[k][b[i]]-s[k][a[i]-1]+mod)%mod)%mod;
                /*
                rep(x,a[i],b[i]+1){
                    dp[i][j]=(dp[i][j]+power(x,k,mod)*dp[i-1][j-k]%mod)%mod;
                }
                */
            }
        }
    }
    cout << dp[n-1][c] << endl;
}

int main(){
    std::cin.tie(0);
    std::ios::sync_with_stdio(false);
    cout.setf(ios::fixed);
    cout.precision(10);
    solve();
    return 0;
}


Measured memory_bytes: 2816
n = int(input())
a = list(map(int, input().split()))
var = [0]*8
clown = 0
for i in a:
  if i >= 3200:
    clown += 1
  else:
    var[i//400] = 1
if sum(var) > 0:
  print(sum(var), sum(var)+clown)
else:
  print(1, sum(var)+clown)

Measured memory_bytes: 3060
#include <iostream>
#include <cstdlib>
#include <string>
#include <vector>
#include <set>
#include <queue>
#include <array>

using namespace std;

int main()
{
    int n, w;
    cin >> n >> w;
    vector<long long> cost(n+1);
    vector<long long> value(n+1);
    long long dp[n+1][w+1];
    for (int i=1; i<=n; ++i){
        cin >> cost[i] >> value[i];
    }
    for (int i=0; i<=n; ++i){
        for (int j=0; j<=w; ++j){
            if(i == 0 || j == 0){
                dp[i][j] = 0;
            }
            else {
                if(j - cost[i] >= 0){
                    dp[i][j] = max(dp[i-1][j], dp[i-1][j-cost[i]] + value[i]);
                }
                else {
                    dp[i][j] = dp[i-1][j];
                }
            }
        }
    }
    cout << dp[n][w] << endl;
    return 0;
}


Measured memory_bytes: 79104
#include <iostream>

using namespace std;

int main()
{
    int n;
    cin >> n;
    string s;
    int ab=0,a=0,b=0,c=0;
    for(int o=0;o<n;o++)
    {
        cin >> s;
        if(s[0]=='B'&&s[s.size()-1]=='A') c++;
        else if(s[0]=='B') b++;
        else if(s[s.size()-1]=='A') a++;
        for(int i=0;i<(int)s.size()-1;i++) if(s[i]=='A'&&s[i+1]=='B') ab++;
    }
    if(min(a,b)>0) cout << ab+min(a,b)+c << endl;
    else if(max(a,b)>0) cout << ab+c << endl;
    else cout << ab+max(0,c-1) << endl;
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <queue>
#include <map>
#include <algorithm>
#include <vector>
#include <cmath>
#include <numeric>
#include <cstdlib>
#include <cstdio>
#include <ctime>
#include <random>

using namespace std;

int main()
{
    int N;
    vector<int> a[1000];
    cin >> N;

    int k, t;
    t = -1;
    for (int i = 1; i <= 2 * N; i++)
    {
        if(i * (i + 1) - 2 * N == 0)
        {
            t = i;
            break;
        }
    }

    if(t == -1)
    {
        cout << "No" << endl;
        return 0;
    }
    cout << "Yes" << endl;

    k = t + 1;
    cout << k << endl;

    int cnt = 1;

    for (int i = 1; i <= t;i++)
    {
        for (int j = 1; j <= i;j++)
        {
            a[i - 1].push_back(cnt++);
        }
    }

    for (int i = 1; i <= k - 1;i++)
    {
        cnt = 0;
        cout << t << ' ';
        for (int j = 1; j <= i;j++)
        {
            cout << a[i - 1][j - 1];
            cnt++;
            if(cnt != t)
            {
                cout << ' ';
            }
        }
        for (int j = 1; j <= t - i;j++)
        {
            cout << a[i - 1 + j][i - 1];
            cnt++;
            if (cnt != t)
            {
                cout << ' ';
            }
        }
        cout << endl;
    }

    cout << t << ' ';
    cnt = 0;
    for (int i = 0; i < t; i++)
    {
        cout << a[i][i];
        cnt++;
        if (cnt != t)
        {
            cout << ' ';
        }
    }
    cout << endl;

    return 0;
}

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

int comp(const void *a, const void *b){
  return *(int*)a - *(int*)b;
}

int main(){
  int N;
  scanf("%d", &N);
  int A[N];
  int i;

  for(i = 0; i < N; i++){
    scanf("%d", &A[i]);
  }

  qsort(A, N, sizeof(int), comp);
  int c, j;

  while(A[N-2] != 0){
    i = 0;
    while(A[i] == 0) i++;
    c = A[i];
    for(j = i + 1; j < N; j++){
      A[j] = A[j] % c;
    }
    qsort(A, N, sizeof(int), comp);
  }

  printf("%d\n", c);

  return 0;
}


Measured memory_bytes: 1012
# 初期入力
import sys
input = sys.stdin.readline  #文字列では使わない

N,M = map(int, input().split())
ans =1
ab =[0]*M
for i in range(M):
    a,b = map(int, input().split()) #争いのある部分
    ab[i] =(a,b)

#abをbでソート
ab.sort(key=lambda x: x[1],reverse=True)
max_a =ab[0][0]
for a,b in ab:
    if max_a < b:
        max_a =max(max_a,a)
        continue
    else:
        max_a =a
        ans +=1
print(ans)

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

#define int long long 
#define put(n) cout<<(n)<<"\n"
#define FOR(i,num,N) for(int(i)=(num);(i)<(N);(i)++)
#define RFOR(i,num,N) for(int (i)=(num);(i)>(N);(i)--)
#define all(v) (v).begin() , (v).end()
#define rall(v) (v).rbegin() , (v).rend()

signed main(){
    int N;
    cin>>N;
    vector<int> T(N),X(N),Y(N);

    FOR(i,0,N){
        cin>>T[i]>>X[i]>>Y[i];
    }

    int t = T[0];
    int x = X[0];
    int y = Y[0];
    string ans = "Yes";

    FOR(i,1,N){
        if(x+y > t){ans = "No";}
        else if(t % 2 != ((x+y) % 2)){ans = "No";}
        t = abs(T[i] - T[i-1]);
        x = abs(X[i] - X[i-1]);
        y = abs(Y[i] - Y[i-1]);
    }

    if(N == 1){
        if(x+y > t){ans = "No";}
        else if(t % 2 != ((x+y) % 2)){ans = "No";}
    }
    put(ans);
}




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

int main() {
  
  int r, D, x, y;
  cin >> r >> D >> x;
    
  for ( int i = 0; i < 10; i++) {
  y = r * x - D;
  x = y;
  cout << y << endl;
  }
   
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<n;i++)
#define int long long
#define INF 1e9
int h,w,d;
int a[334][334];
int b[114514];
map<int,pair<int,int>>mp;
signed main(){
	cin>>h>>w>>d;
	rep(i,h){
		rep(j,w){
			cin>>a[i][j];
			mp[a[i][j]]={i,j};
		}
	}
	for(int i=1;i<=h*w;i++){
		if(i-d<=0)b[i]=0;
		else b[i]=b[i-d]+abs(mp[i-d].first-mp[i].first)+abs(mp[i].second-mp[i-d].second);
	}
	int q;
	cin>>q;
	while(q--){
		int l,r;
		cin>>l>>r;
		int ans=0;
		if(l-d<=0)ans+=b[r];
		else ans+=b[r]-b[l];
		cout<<ans<<endl;
	}
	return 0;
}


Measured memory_bytes: 8192
#include<iostream>

using namespace std;

int main(void)
{
	int N;
	cin >> N;

	int ans = 0;

	while (N >= 500)
	{
		N -= 500;
		ans += 1000;
	}
	while (N >= 5)
	{
		N -= 5;
		ans += 5;
	}

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

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ll long long int
#define pi 3.141592653589793238
#define fast ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
int main(){
	fast;
	ll n;
	cin>>n;
	vector<ll> arr(n),fre(100001,0),max(100001,0);
	ll x;
	for(int i=0;i<n;i++)
		cin>>arr[i],fre[arr[i]]++;
	max[0]=fre[0]+fre[1];
	x=max[0];
	for(int i=1;i<100000;i++)
	{
		max[i]=fre[i]+fre[i-1]+fre[i+1];
		if(max[i]>x)
			x=max[i];
	}
	cout<<x;
	return 0;
}



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

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

  ll ans = N / (A+B) * A;
  if(N % (A+B) >= A) ans += A;
  else ans += N % (A+B);

  cout << ans << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int j,k,n,ans=INT_MAX,tmp;
    cin>>n;
    int x,y;
    int arr[n],i;
    for(i=0; i<n; i++)
        cin>>arr[i];
    sort(arr,arr+n);
    x=arr[0];
    y=arr[n-1];
    for(j=x;j<=y;j++)
    {
        int pnt=j;
        tmp=0;
        for(k=0;k<n;k++){
            tmp+=pow(arr[k]-pnt,2);
        }
        if(tmp<ans){
            ans=tmp;
        }
    }
    cout<<ans<<endl;


    return 0;
}



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

using namespace std;

int main()
{
	string s;
	int stack[103]={0};
	int pointer=0;
	bool flag=true;

	getline(cin,s);
	while (s!=".")
	{
		for (int i=0;i<s.length();++i)
		{
			if (s[i]=='(') stack[pointer++] = 1;
			if (s[i]=='[') stack[pointer++] = 2;
			if ((s[i]==')')&&(stack[--pointer]!=1)) {flag=false; break;}
			if ((s[i]==']')&&(stack[--pointer]!=2)) {flag=false; break;}
		}

		if (flag&&pointer==0) cout<<"yes"<<endl;
		else cout<<"no"<<endl;

		flag = true;
		pointer = 0;
		getline(cin,s);
	}
}

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

int main () {
  int N, M;
  cin >> N >> M;
  
  vector<int> road(N);
  for (int i = 0; i < M; i++) {
    int city1, city2;
    cin >> city1 >> city2;
    road.at(city1 - 1)++;
    road.at(city2 - 1)++;
  }
  
  for (int i = 0; i < N; i++)
    cout << road.at(i) << endl;
}

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

int main() {
  string s;
  cin >> s;
  s.replace(3, 1, "8");
  cout << s << endl;
  return 0;
}

Measured memory_bytes: 3560
#include<bits/stdc++.h>
#define long long long
using namespace std;
const int N=1e6,mod=1e9+7;
int big(int b,int p)
{
  int r=1;
  while(p)
  {
    if(p&1)r=(1LL*r*b)%mod;
    b=(1LL*b*b)%mod;p/=2;
  }
  return r;
}
long cl[N+2];
int main()
{
  ios_base::sync_with_stdio(0);cin.tie(0);
  int n,k;cin>>n>>k;

  for(int i=1;i<=k;i++)
    cl[i]=big((k/i),n);
  for(int i=k;i>=1;i--)
  {
    for(int j=i+i;j<=k;j+=i)
      cl[i]=(cl[i]-cl[j]+mod)%mod;
  }
  long ans=0;
  for(int i=1;i<=k;i++)
    ans=(ans+cl[i]*i)%mod;
  cout<<ans<<endl;

  return 0;
}


Measured memory_bytes: 4376
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
#include <ctype.h>
#include <limits.h>	
#define inf (INT_MAX-1)
#define INF 9223372036854775807
#define sq(n) ((n)*(n))
#define rep(i,n) for(i=0;i<n;i++)
#define rev(i,n) for(i=n-1;i>=0;i--)
const int mod=(int)1e09+7;

int in(void){
	int i;scanf("%d",&i);
	return i;
}
long long llin(void){
	long long i;scanf("%lld",&i);
	return i;
}
double din(void){
	double i;scanf("%lf",&i);
	return i;
}
void chin(char s[]){
	scanf("%s",s);
}
void print(int a){
	printf("%d\n",a);
}
void llprint(long long a){
	printf("%lld\n",a);
}
void dprint(double a){
	printf("%.10f\n",a);
}
void print2(int a,int b){
	printf("%d %d\n",a,b);
}
long long max(long long a,long long b){
	return a>b?a:b;
}
long long min(long long a,long long b){
	return a<b?a:b;
}
long long llabs(long long a){
	return a>0?a:-a;
}
double dmax(double a,double b){
	return a>b?a:b;
}
int cmp(const void *a,const void *b){
	return *(long long *)a-*(long long *)b;
}

int main(void){
	int w=in();
	print(w*32);
	return 0;
}

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

using namespace std;

#define ll long long
#define ld long double

signed main() {
	int w, h;
	cin >> w >> h;

	priority_queue<int, vector<int>, greater<int>> p, q;
	for (int i = 0; i < w; ++i) {
		int pi; cin >> pi;
		p.push(pi);
	}
	for (int i = 0; i < h; ++i) {
		int qi; cin >> qi;
		q.push(qi);
	}
	p.push(1000000000); q.push(1000000000); // 番兵

	++w; ++h;
	ll ans = 0;
	while (p.size() > 1 || q.size() > 1) {
		if (p.top() < q.top()) {
			ans += ((ll)p.top()) * h;
			--w;
			p.pop();
		}
		else {
			ans += ((ll)q.top()) * w;
			--h;
			q.pop();
		}
	}

	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 1400
import sys, heapq
def main():
    input = sys.stdin.readline
    que = []
    ans = []
    while True:
        a = input()
        if a[0] == "i":
            heapq.heappush(que, -int(a[7:]))
        elif a[2] == "t":
            ans.append(-heapq.heappop(que))
        else:
            break
    print("\n".join(map(str, ans)))

if __name__ == "__main__":
    main()


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

int main() {
    int n; cin >> n;
    vector<string> s(n);
    for (auto &si: s) cin >> si;
    set<string> se;
    char lst = s[0].front();
    for (auto &si: s) {
        if (se.count(si) || lst != si.front()) return !(cout << "No" << endl);
        se.emplace(si), lst = si.back();
    }
    cout << "Yes" << endl;
    return 0;
}


Measured memory_bytes: 256
from collections import defaultdict
MAX_A = 10**6

sieve = [[] for _ in range(MAX_A+1)]
# sieve[i] = True if i is prime
# sieve[i] = prime factors of i

for f in range(2, MAX_A + 1):
  if not sieve[f]:
    c = f
    while c <= MAX_A:
      sieve[c].append(f)
      c += f

N = int(input())
A = list(map(int, input().split()))

cnt = defaultdict(int)
for a in A:
  for s in sieve[a]:
    cnt[s] += 1

def is_pairwise_coprime():
  return all(v == 1 for v in cnt.values())

def is_setwise_coprime():
  return all(v < N for v in cnt.values())

if is_pairwise_coprime():
  print('pairwise coprime')
elif is_setwise_coprime():
  print('setwise coprime')
else:
  print('not coprime')


Measured memory_bytes: 318668
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.StringTokenizer;

public class Main {
    private static final BufferedReader READER = new BufferedReader(new InputStreamReader(System.in));

    private static int getInt() {
        return Integer.parseInt(line());
    }

    private static int[] getIntArr(int n) {
        int[] ans = new int[n];

        StringTokenizer stringTokenizer = new StringTokenizer(line(), " ");
        for (int i = 0; i < n && stringTokenizer.hasMoreTokens(); i++) {
            ans[i] = Integer.parseInt(stringTokenizer.nextToken());
        }

        return ans;
    }

    private static String line() {
        try {
            return READER.readLine();
        } catch (IOException e) {
            throw new RuntimeException(e);
        }
    }

    private static String solve() {
        return solveInternal(line(), line());
    }

    private static String solveInternal(String s, String t) {
        if (s.equals(t)) {
            return s;
        }
        if (s.isEmpty() || t.isEmpty()) {
            return "";
        }

        int[][] dp = new int[s.length()][t.length()];

        char firstS = s.charAt(0);
        char firstT = t.charAt(0);

        dp[0][0] = firstS == firstT ? 1 : 0;

        for (int i = 1; i < s.length(); i++) {
            dp[i][0] = s.charAt(i) == firstT ? 1 : dp[i - 1][0];
        }
        for (int i = 1; i < t.length(); i++) {
            dp[0][i] = t.charAt(i) == firstS ? 1 : dp[0][i - 1];
        }

        for (int i = 1; i < s.length(); i++) {
            for (int j = 1; j < t.length(); j++) {
                if (s.charAt(i) == t.charAt(j)) {
                    dp[i][j] = dp[i - 1][j - 1] + 1;
                } else {
                    dp[i][j] = max(dp[i - 1][j - 1], dp[i - 1][j], dp[i][j - 1]);
                }
            }
        }

        char[] ans = new char[dp[s.length() - 1][t.length() - 1]];

        int i = s.length() - 1;
        int j = t.length() - 1;
        int k = ans.length;
        while (k > 0) {

            if (i > 0 && j > 0 && dp[i - 1][j - 1] == k) {
                i--;
                j--;
            } else if (i > 0 && dp[i - 1][j] == k) {
                i--;
            } else if (j > 0 && dp[i][j - 1] == k) {
                j--;
            } else {
                if (s.charAt(i) != t.charAt(j)) {
                    throw new IllegalStateException();
                }
                k--;
                ans[k] = s.charAt(i);
            }
        }
        return new String(ans);
    }

    private static int max(int x, int y, int z) {
        return Math.max(Math.max(x, y), z);
    }

    public static void main(String... args) {
        System.out.println(solve());
//        String s = "aaaaaaaggggaaaaaaaaui";
//        String t = "baaaaahhhhhaaaaaaaaazpok";
//        System.out.println(
//                solveInternal(s, t)
//        );
    }
}


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

#define FOR(i, j, k) for(int i = j; i < k; i++)
#define REP(i, j) FOR(i, 0, j)
#define fst first
#define snd second
#define pb push_back
#define eb emplace_back
#define all(obj) (obj).begin(), (obj).end()
#define rall(obj) (obj).rbegin(), (obj).rend()
typedef long long int ll;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<vi> vvi;

int main() {

    int N, Q;
    cin >> N >> Q;

    vector<tuple<int, int, int>> T(N);
    REP(i, N) {
        int s, t, x;
        cin >> s >> t >> x;
        T[i] = tie(x, s, t);
    }
    sort(all(T));

    vi D(Q);
    REP(i, Q) cin >> D[i];

    set<pii> P;
    REP(i, Q) P.insert(make_pair(D[i], i));

    vector<int> ans(Q, -1);
    REP(i, N) {
        int s, t, x;
        tie(x, s, t) = T[i];

        pii l = make_pair(s - x, -1);
        auto it = P.lower_bound(l);

        while(it != P.end()) {
            if(it->first >= t - x)
                break;
            ans[it->second] = x;
            P.erase(it++);
        }
    }

    REP(i, Q) { cout << ans[i] << endl; }

    return 0;
}


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

using namespace std;
#define all(x) (x).begin(),(x).end()
#define rep(i, n) for (int i = 0; i < (n); i++)
#define chmin(x, y) (x) = min((x), (y))
#define chmax(x, y) (x) = max((x), (y))
#define endl "\n"
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;

template <typename T> ostream &operator<<(ostream &os, const vector<T> &vec) {os << "["; for (const auto &v : vec) {os << v << ","; } os << "]"; return os;}
template <typename T, typename U> ostream &operator<<(ostream &os, const pair<T, U> &p) {os << "(" << p.first << ", " << p.second << ")"; return os;}

void solve() {
    string s;
    cin >> s;
    string st;
    int cnt = 0;
    for (int i = 0; i < s.size(); i++) {
        while (st.size() && 
            (
                (st.back() == '0' && s[i] == '1')
                || (st.back() == '1' && s[i] == '0')
            )
            ) {
            st.pop_back();
            i++;
            cnt++;
        }
        st += s[i];
    }
    cout << cnt * 2 << endl;
}

int main() {
    #ifdef LOCAL_ENV
    cin.exceptions(ios::failbit);
    #endif
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout.setf(ios::fixed);
    cout.precision(16);
    
    solve();
}

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

int main()
{
    ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    string s; cin >> s;
    int n = s.size();
    cout<<s;
    if(s[n-1]=='s') cout << "es" << endl;
    else cout << "s" << endl;

    return 0;
}

Measured memory_bytes: 3628
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <cmath>

#define lpsbd(i, s, b, d) for(size_t i = (s); i < (b); i+=(d))
#define lpsb(i, s, b) for(size_t i = (s); i < (b); i++)
#define lpn(i, n) for(size_t i = 0; i < (n); i++)
#define fa(i, x) for(auto &i: x)
#define vcd(t, n, d) vector<t>(n, d)
#define vc(t, n) vector<t>(n)

using namespace std;
using ull = unsigned long long;

const ull MOD = 1000000007;

int main(void)
{
    int N;
    int count = 0;
    int p;
    cin >> N;
    for (int i = 1; i <= N; i++)
    {
        cin >> p;
        if (p != i) count++;
    }
    cout << ((count <= 2) ? "YES" : "NO") << endl;
    return 0;
}

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

int N, D, X;
int p[11][11];

int main() {
    cin >> N >> D >> X;
    for (int j = 0; j < D; ++j) {
        for (int k = 0; k < N; ++k) {
            cin >> p[j][k];
        }
    }

    int ret = X;

    int memo[101010];
    for (int j = 1; j < D; ++j) {
        for (int k = 0; k < N; ++k) {
            fill(memo, memo+101010, 0);
        }

        for (int k = 0; k < N; ++k) {
            for (int l = p[j-1][k]; l <= ret; ++l) {
                memo[l] = max(memo[l], memo[l - p[j-1][k]] + (p[j][k] - p[j-1][k]));
            }
        }

        ret += memo[ret];
    }
    cout << ret << endl;
    return 0;
}

Measured memory_bytes: 3468
const t={input:require('fs').readFileSync('/dev/stdin','utf8').split(/[\s]/),n:(arg:number=0):any=>{if(arg){const a=[];for(let i=0;i<arg;i++){a.push(t.n())}return a}else{const a=t.input[0];t.input.shift();return Number(a)}},s:(arg:number=0):any=>{if(arg){const a=[];for(let i=0;i<arg;i++){a.push(t.s())}return a}else{const a=t.input[0];t.input.shift();return String(a)}},c:(arg:number=0):any=>{if(arg){const a=[];for(let i=0;i<arg;i++){a.push(t.c())}return a}else{let a=t.input[0].split('');const b=a[0];a.shift();if(a.length>0){t.input[0]=a.join('')}else{t.input.shift()}return String(b)}},o:(...arg)=>{console.log(...arg)},abs:(a)=>{return Math.abs(a)},min:(...a)=>{return Math.min(...a)},max:(...a)=>{return Math.max(...a)},floor:(a)=>{return Math.floor(a)},asc:(ar:number[])=>{return ar.sort((a,b)=>{return a-b})},desc:(ar:number[])=>{return ar.sort((a,b)=>{return b-a})},sw:(a,arr:any[],op:'=='|'>='|'>'|'<='|'<'='==')=>{for(let i=0;i<arr.length;i+=2){if(eval(a+op+arr[i]))return arr[i+1];}return arr[arr.length-1]}};
const main=()=>{
  let n=t.n()
  let an=t.n(n)
  let max=an[0],c=1
  for(let i=1;i<n;i++){
    if(max<=an[i]){
      c++
      max=an[i]
    }
  }
  t.o(c)
}
main()

Measured memory_bytes: 7372
/*
h s, d't skp th si tll i's sved
 * ABC141 E
*/
#include<bits/stdc++.h>
#define ll long long
#define mod 1000000007
using namespace std;
int main()
{
int n;
cin>>n;
string s;
cin>>s;
string ans="No";
if(n%2==0)
{
if(s.substr(0,n/2)==s.substr(n/2,n/2))
{
ans="Yes";
}
}
cout<<ans;
}

Measured memory_bytes: 3572
import math
l=[]
def primeFactors(n): 
    while n % 2 == 0: 
        l.append(2)
        n = n / 2         
    for i in range(3,int(math.sqrt(n))+1,2): 
        while n % i== 0: 
            l.append(i)
            n = n / i 
             
    if n > 2: 
        l.append(n)

no=int(input())
d={}
primeFactors(no)
def count(n) : 
    return (-1 + math.sqrt(1 + 8 * n)) // 2; 

for i in range(len(l)):
	if l[i] in d:
		d[l[i]]+=1
	else:
		d[l[i]]=1
c=0
#print(d)
for u,v in d.items():
	c+=count(v)

print(int(c))

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

using namespace std;

void __start__() {
    ios::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
#ifdef MY
    freopen("/home/ainur/CLionProjects/wow/input.txt", "r", stdin);
    freopen("/home/ainur/CLionProjects/wow/output.txt", "w", stdout);
#else
#define endl '\n'
    //freopen("search.in", "r", stdin);
    //freopen("search.out", "w", stdout);
#endif
}

#define sz(x) (int)x.size()
#define yes cout<<"Yes\n"
#define  no cout << "No\n"
#define all(x) x.begin(),x.end()
#define rall(x) x.rbegin(),x.rend()
#define ft first
#define sd second
#define read(a) for(auto &qwqw:a)cin >> qwqw;
#define print(a) for(auto qwqw:a)cout<<qwqw<<' ';
#define print_plus(a) for(auto qwqw:a)cout<<qwqw+1<<' ';
//#define FOR(i, b, n) for(int i=b;i<n;i++) #define FOR(i, n) FOR(i, 0, n) #define FOR(n) FOR(i, 0, n)
mt19937_64 rnd(time(0));
#define int long long
using ll = long long;
using vi = vector<int>;
using ld = long double;
using vb = vector<bool>;
using pii = pair<int, int>;
using vd = vector<long double>;


int log2(int q) {
    int c = 0;
    while (q) {
        q >>= 1;
        c++;
    }
    return c;
}

void test_case() {
    int n, a, b, c, d;
    cin >> n;
    a=b=c=d=0;
    for (int i = 0; i < n; ++i) {
        string s;
        cin >> s;
        if(s=="AC")
            a++;
        if(s=="WA")
            b++;
        if(s=="TLE")
            c++;
        if(s=="RE")
            d++;
    }
    cout << "AC x " << a<<'\n';
    cout << "WA x " << b<<'\n';
    cout << "TLE x " << c<<'\n';
    cout << "RE x " << d<<'\n';

}

signed main() {
    __start__();
    int Q = 1;
    //cin >> Q;
    while (Q--) {
        test_case();
    }
}





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

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

    int cnt = 0;
    string ans = "AC";

    if(s[0] != 'A') ans = "WA";
    for(int i = 1; i < s.length(); i++){
        if(isupper(s[i])){
            if(i == 1|| i == s.length()-1|| s[i] != 'C')    ans = "WA";
            cnt++;//大文字の個数増やす
        }
    } 

    if(cnt != 1)    ans = "WA";
    cout << ans << endl;

}

Measured memory_bytes: 256
#include<stdio.h>
#include<stdlib.h>
#define ll long long 
ll max(ll a,ll b){return a>b?a:b;}
int main(){
    ll n, m, i;
    scanf("%lld%lld",&n,&m);
    ll a[n];
    for(ll i = 0; i < m; i++)
        scanf("%lld",&a[i]);
    ll sum = 0;
    for(ll i = 0; i < m; i++)
        sum += a[i];
    printf("%lld\n",max(-1, n- sum));
    return 0;
}

Measured memory_bytes: 1788
X=int(input())
A=0
while True:
    B=0
    while A**5-B**5>=X:
        if A**5-B**5==X:
            print(A,B)
            exit()
        B+=1
    while A**5-B**5<=X:
        if A**5-B**5==X:
            print(A,B)
            exit()
        B-=1
    A+=1

Measured memory_bytes: 9180
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

int main()
{
	int List[30];
	int i;
	for(i = 0;i < 30;i++)
	{
		List[i] = 0;
	}
	for(i = 0;i < 28;i++)
	{
		int tmp;
		scanf("%d",&tmp);
		List[tmp-1] = 1;
	}
	for(i = 0;i < 30;i++)
	{
		if(List[i] == 0)
		{
			printf("%d\n",i+1);
		}
	}
	return 0;
}

Measured memory_bytes: 0
#include <stdio.h>

int main() {
    int A, B, C, D;
    scanf("%d %d %d %d", &A, &B, &C, &D);

    if(A+B>C+D) {
        printf("Left\n");
    } else if (A+B<C+D) {
        printf("Right\n");
    } else {
        printf("Balanced\n");
    }

    return 0;
}

Measured memory_bytes: 128
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
vector<int> train[500];
 int main() {
	 int N, M, Q;
	 cin >> N >> M >> Q;
	 for (int i = 0; i < M; i++) {
		 int L, R;
		 cin >> L >> R;
		 L--; R--;
		 train[L].push_back(R);
	 }
	 for (int i = 0; i < N; i++) {
		 sort(train[i].begin(), train[i].end());
	 }
	 for (int i = 0; i < Q; i++) {
		 int p, q;
		 cin >> p >> q;
		 p--; q--;
		 int ans = 0;
		 for (int j = p; j <= q; j++) {
			 ans += upper_bound(train[j].begin(), train[j].end(), q) - train[j].begin();
		 }
		 cout << ans << endl;
	 }
}

Measured memory_bytes: 2176
#include <bits/stdc++.h>
#define MOD 1000000007
#define INF 1061109567
#define pb push_back
#define in(s) freopen(s,"r",stdin);
#define out(s) freopen(s,"w",stdout);
#define fi first
#define se second
#define bw(i,r,l) for (int i=r-1;i>=l;i--)
#define fw(i,l,r) for (int i=l;i<r;i++)
#define fa(i,x) for (auto i:x)
using namespace std;
const int N=1e5+5;
int n,k,val[N],l[N],r[N],ans[N];
vector<int> G[N];
queue<int> q,q2;
signed main() {
	//in("aome.inp");
	ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
	cin>>n;
	fw (i,1,n) {
		int u,v;
		cin>>u>>v;
		u--; v--;
		G[u].pb(v); G[v].pb(u);
	}
	cin>>k;
	memset(val,-1,sizeof(val));
	fw (i,0,n) l[i]=-INF,r[i]=INF;
	fw (i,0,k) {
		int a,b;
		cin>>a>>b;
		a--;
		val[a]=b;
		l[a]=b,r[a]=b;
		q.push(a); q2.push(a);
	}
	/*
	A lower bound and an upper bound is instilled on each node. BFS from the pre - written nodes to
	obtain these values.
	Then, it's easily seeable any values inside these bounds could do.
	*/
	while (!q.empty()) {
		int u=q.front(); q.pop();
		fa (v,G[u]) if (l[u]-1>l[v]) {
			l[v]=l[u]-1;
			q.push(v);
		}
	}
	while (!q2.empty()) {
		int u=q2.front(); q2.pop();
		fa (v,G[u]) if (r[u]+1<r[v]) {
			r[v]=r[u]+1;
			q2.push(v);
		}
	}
	fw (i,0,n) if (l[i]>r[i]) {cout<<"No"; return 0;}
	while (!q.empty()) q.pop();
	fw (i,0,n) ans[i]=-INF;
	fw (i,0,n) if (l[i]==r[i]) ans[i]=l[i],q.push(i);
	while (!q.empty()) {
		int u=q.front(); q.pop();
		fa (v,G[u]) {
			if (ans[v]==-INF) {
				if (ans[u]+1<=r[v]) {
					ans[v]=ans[u]+1;
					q.push(v);
				} else if (ans[u]-1>=l[v]) {
					ans[v]=ans[u]-1;
					q.push(v);
				}
			} else {
				if (ans[u]%2==ans[v]%2) {cout<<"No"; return 0;} 
			}
		}
	}
	cout<<"Yes\n";
	fw (i,0,n) cout<<ans[i]<<"\n";
	return 0;
}

Measured memory_bytes: 8832
#pragma GCC optimize("Ofast")
#pragma GCC optimize("unroll-loops")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;

int main()
{
	ios::sync_with_stdio(false);
	int n; cin >> n;
	ll result = 0;
	for (int i = 0; i < n; i++)
	{
		ll a; cin >> a;
		result += a - 1;
	}
	cout << result << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <sstream>
#include <vector>
#include <map>
#include <stack>
#include <queue>
#include <deque>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <climits>
#include <cstring>
using namespace std;

int main(){
    int n;
    cin >> n;
    int* S = new int[n];
    
    for(int i=0;i<n;i++){
        cin >> S[i];
    }
    
    int q;
    cin >> q;
    int* T = new int[n];
    for(int i=0; i<n; i++){
        cin >> T[i];
    }
    
    int ans = 0;
    
    for(int i=0; i<q; i++){
        for(int j=0; j<n; j++){
            if(T[i] == S[j]){
                ans++;
                break;
            }
        }
    }
    cout << ans << endl;
    
    delete[] S;
    delete[] T;
    return 0;
}


Measured memory_bytes: 3104
#include <iostream>
#include<string>
#include<cstdio>
#include<cmath>
#include<algorithm>
#include<vector>
using namespace std;
int main(){
    int t,n,s[10],f[10],i,sa[10]={0},h=0;
    while(cin>>t){
        if(t==0)break;
        cin>>n;
        for(i=0;i<n;i++){
            cin>>s[i]>>f[i];
            sa[i]=f[i]-s[i];
            h+=sa[i];
        }
        if(t<=h)cout<<"OK"<<endl;
        else cout<<t-h<<endl;
        h=0;
    }
          return 0;
}

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

#define froop1(a,n) for(int i = a;i < n;i++)
#define froop2(a,n) for(int i = a;i > n;i--)

#define ll long long

#define pq(name,type) priority_queue<type> name
#define vec(name,type,length,value) vector<type> name(length,value)
#define vec2(name,type,length,width,value) vector<vector<type>> name(length,vector<type>(width,value));

int main(){
	ll N,M,K;
  cin >> N >> M >> K;
  
  ll sum = 0,time = 0;
	while(sum < N){
	time += K;
      sum += M;
    }
  cout << time << endl;
return 0;
}

Measured memory_bytes: 3592
#include <algorithm>
#include <cstdlib>
#include<iostream>
#include<vector>
#include<map>
#include<cmath>
using namespace std;
int N,M,X,Y;


bool is_war(const vector<int>& x,const vector<int>& y){
    for(int Z=-100;Z<=100;++Z){
        bool is_ok=true;
        for(int i=0;i<x.size();++i){
            if(x[i]>=Z){
                is_ok=false;
            }
        }
        for(int i=0;i<y.size();++i){
            if(y[i]<Z){
                is_ok=false;
            }
        }
        if(is_ok) return false;
    }
    return true;
}


int main(int argc, char const *argv[])
{
    cin>>N>>M>>X>>Y;
    std::vector<int> x(N+1);
    std::vector<int> y(M+1);
    x[0]=X;
    y[0]=Y;
    for(int i=1;i<=N;i++){
        cin>>x[i];
    }
    for(int i=1;i<=M;i++){
        cin>>y[i];
    }
    if(is_war(x,y)){
        cout<<"War"<<endl;
    }else{
        cout<<"No War"<<endl;
    }

    return 0;
}


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

int main() {
    using namespace std;
    unsigned long N, K;
    cin >> N >> K;
    vector<unsigned long> p(N);
    for(auto& i : p)cin >> i;
    unsigned long mx{0}, now{0};
    for(unsigned long i{0}; i < K; ++i)mx = max(mx, now += p[i]);
    for(unsigned long i{K}; i < N; ++i)mx = max(mx, now += p[i] - p[i - K]);
    cout << (mx + K) / 2 << ((mx + K) & 1 ? ".5" : "") << endl;
    return 0;
}

Measured memory_bytes: 1792
//   _/                _/                 _/_/_/   _/
//_/_/_/_/   _/_/   _/_/_/_/   _/_/    _/       _/_/
// _/     _/    _/   _/     _/    _/  _/_/_/     _/
//_/     _/    _/   _/     _/    _/  _/    _/   _/
// _/_/   _/_/       _/_/   _/_/      _/_/     _/
#include<iostream>
#include<algorithm>
#include<cmath>
#include<iomanip>
#include<set>
#include<map>
#include<queue>
#include<vector>
using namespace std;
typedef long long ll;
const int MOD=1e9+7;
const double pi=3.14159265358979323846;
const int inf=1e9;
const ll INF=5e18;
typedef pair<int,int> P;
int main() {
  cin.tie(0),cout.tie(0);
  ios::sync_with_stdio(false);
  int a,b,k,f=1;
  cin >> a >> b >> k;
  while(k) {
    if(f) {
      f=0;
      if(a%2) {
        a--;
        a/=2;
        b+=a;
      }
      else {
        a/=2;
        b+=a;
      }
    }
    else {
      f=1;
      if(b%2) {
        b--;
        b/=2;
        a+=b;
      }
      else {
        b/=2;
        a+=b;
      }
    }
    k--;
  }
  cout << a << " " << b << endl;
}


Measured memory_bytes: 256
from math import ceil,floor,factorial,gcd,sqrt,log2,cos,sin,tan,acos,asin,atan,degrees,radians,pi,inf
from itertools import accumulate,groupby,permutations,combinations,product,combinations_with_replacement
from collections import deque,defaultdict,Counter
from bisect import bisect_left,bisect_right
from operator import itemgetter
from heapq import heapify,heappop,heappush
from queue import Queue,LifoQueue,PriorityQueue
from copy import deepcopy
from time import time
import string
import sys
sys.setrecursionlimit(10 ** 7)
def input() : return sys.stdin.readline().strip()
def INT()   : return int(input())
def MAP()   : return map(int,input().split())
def LIST()  : return list(MAP())

def bfs():
    d = [[inf]*w for i in range(h)]

    dy = [0, 1, 0, -1] 
    dx = [1, 0, -1, 0]
 
    que = deque([])
    que.append((sy, sx))
    d[sy][sx] = 0
 
    while que:
        p = que.popleft()
        if p[0] == gy and p[1] == gx:
            break
        for i in range(4):
            ny = p[0] + dy[i]
            nx = p[1] + dx[i]
 
            if 0 <= ny < h and 0 <= nx < w and s[ny][nx] != '#' and d[ny][nx] == inf:
                que.append((ny,nx))
                d[ny][nx] = d[p[0]][p[1]] + 1
 
    return d[gy][gx]

h, w = MAP()
s = [input() for i in range(h)]
sy = sx = 0
gy, gx = h-1, w-1

if bfs() == inf:
    ans = -1
else:
    count = 0
    for i in range(h):
        count += s[i].count('#')
    ans = h*w - bfs() - 1 - count

print(ans)

Measured memory_bytes: 10236
//#include <bits/stdc++.h>
//#include <stdio.h>
#include<iostream>
#include<cstdio>
#include<bitset>
#include<algorithm>
#include<vector>
#include<list>
#include<queue>
#include<stack>
//#include <bits/stdc++.h>
#include<string>
#include<string.h>
#include<cmath>
#include<utility>
#include<functional>
#include<map>
#include<set>
#include<cctype>
#include<fstream>
#include <numeric>
#include <iomanip>
#include <cstring> 
using namespace std;
using ll=long long;

#define FOR(i, a, b) for( int i=(a);i<=(b);i++)
#define RFOR(i, a, b) for( int i=(a);i>=(b);i--)
#define LFOR(i, a, b) for( long long int i=(a);i<=(b);i++)
#define LRFOR(i, a, b) for(long long int i=(a);i>=(b);i--)
#define MOD 1000000007


#include <iostream>
#include <cmath>
using namespace std;
 

 
bool isPrimeNum( ll x ){ // 素数である場合 true を返す
  if( x <= 1 ){ // 1以下である場合は素数でないことがすぐにわかる
    return false;
  }
  // sqrt( double型 ) は引数の平方根を double型で返すので、int型でキャスト
  int n = (int)sqrt( (double)x );
  for( int i = 2; i <= n; i++ ){
    if( x % i == 0 ){ // 割り切る整数がある場合、即判定終了
      return false;
    }
  }
  return true; // 割り切る整数がない場合、素数である
}

constexpr ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
constexpr ll lcm(int a,int b){return a*b/gcd(a,b);}
constexpr ll abs(ll a,ll b){
if(a>=b)return a-b;
if(a<b)return b-a;
}
int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};
 

 
int main() {
  double h,w;
  double ans;
  cin >> h >> w;
	ans=h/w;
	cout<<ans<<endl;
}

Measured memory_bytes: 256
h,w=map(int, input().split()) 
c=[list(map(int, input().split()))  for i in range(10)]
a=[list(map(int, input().split()))  for i in range(h)]

# ベルマンフォード法
#c=[[random.randint(1, 10) for i in range(n)] for i in range(n)]
for k in range(10):
    for i in range(10):
        for j in range(10):
            c[i][j]=min(c[i][j],c[i][k]+c[k][j])

ans=0 

for i in range(h):
    for j in range(w):
        if a[i][j]==-1 or a[i][j]==1:
            continue
        else:
            ans+=c[a[i][j]][1]
print(ans)
        
    




Measured memory_bytes: 3316
#include<iostream>
#include<stack>
#define _w_ true
using namespace std;

const int Ebit[8] = {0,1,2,3,5,7,8,9};
int main(){
  int n;
  stack<int> st;
  while(_w_){
    cin >> n;
    if(n == 0)break;
    while(_w_){
      if(n<8){
	st.push(Ebit[n]);
	break;
      }
      int amari = n%8;
      n = n/8;
      st.push(Ebit[amari]);
    }
    while(st.size()){
      cout << st.top();
      st.pop();
    }
    cout << endl;
  }
  return 0;
}

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

int main(){
    string s;
    ll k;
    cin >> s >> k;

    int f = 0;
    while(true){
        if(s[f] != '1'){ 
            cout << s[f] << endl;
            return 0;
        }
        else{
            if(f==k-1){
                cout << 1 << endl;
                return 0;
            }
            f++;
        }
        if(f == s.size()) {
            cout << 1 << endl; 
            return 0;
        }
    }
    return 0;
}

Measured memory_bytes: 3580
n=int(input())
a=list(map(int,input().split()))

import collections
counter=collections.Counter(a)

ans=0
for key in counter.keys():
  s=0
  s+=counter[key]
  if key+1 in counter:
    s+=counter[key+1]
  if key-1 in counter:
    s+=counter[key-1]
  ans=max(ans,s)
  
print(ans)

Measured memory_bytes: 14436
#include<iostream>
#include<algorithm>
using namespace std;
typedef long long ll;
int p=1e9+7;
int main()
{
  ll n,i,a=1,b=1,c=1,res;
  cin >> n;
  for(i=0;i<n;i++){
    a*=10;
    b*=9;
    c*=8;
    a%=p;
    b%=p;
    c%=p;
  }
  res=(a+c-2*b)%p;
  if(res<0)
    res+=p;
  cout << res << endl;
  return 0;
}

Measured memory_bytes: 3632
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
using namespace std;
using ll = long long;
using P = pair<int,int>;
const int mod = 1000000007;
const ll INF = 1001001001;
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; }

int main(){
  string s,t;
  cin >> s >> t;
  int n = int(s.size());
  int m = int(t.size());
  vector<vector<int>> dic(26);
  rep(i,n) dic[s[i]-'a'].push_back(i);
  rep(i,n) dic[s[i]-'a'].push_back(i+n);
  int p = 0;
  ll ans = 0;
  rep(i,m){
    int a = t[i] - 'a';
    if(dic[a].size()==0){
      puts("-1");
      return 0;
    }
    p = *lower_bound(dic[a].begin(),dic[a].end(),p) + 1;
    if(p>=n){
      ans += n;
      p -= n;
    }
  }
  ans += p;
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 4628
def min(a, b)
  a < b ? a : b
end

N, K = gets.split.map(&:to_i)
H = gets.split.map(&:to_i)

dp = Array.new(100105, Float::INFINITY)
dp[0] = 0
(N - 1).times do |i|
  1.upto(min(K, N - 1 - i)) do |j|
    num = dp[i] + (H[i + j] - H[i]).abs
    dp[i + j] = num if num < dp[i + j]
  end
end
puts dp[N - 1]

Measured memory_bytes: 8844
#include <iostream>
#include <string>
#include <vector>
#include <map>
#include <set>
#include <algorithm>
#include <cmath>
#include <climits>
#include <math.h>

#define X first
#define Y second
#define vsort(v) sort((v).begin(), (v).end())
#define vrev(v) reverse((v).begin(), (v).end())
#define P pair

// stoi(s): string to int
// stod(s): string to double

// INT_MAX
// INT_MIN
// LLONG_MAX
// LLONG_MIN
// DBL_MIN
// DBL_MAX
// LDBL_MIN
// LDBL_MAX

// A-Z: 65~90
// a-z: 97~122
// |a-z| = 26

using namespace std;
using ll = long long;

int main(int argc, const char *argv[]){
    int a, b;
    cin >> a >> b;
    if (b % a == 0) {
        cout << a + b << endl;
    }else{
        cout << b - a << endl;
    }
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <set>
#include <queue>
#include <stack>
#include <map>
#include <algorithm>
#include <math.h>
#include <cassert>
#define rep(i,n) for(int i = 0; i < n; ++i )
using namespace std;
using ll = long long;
using P = pair<int,int>;

int main() {
  ll n;
  cin >> n;
  --n;
  ll ans = (n+1)*n/2;
  cout << ans << endl;
}

Measured memory_bytes: 888
#pragma GCC optimize ("Ofast")
#include<bits/stdc++.h>
#define pb push_back
#define __V vector
#define all(x) x.begin(), x.end()
#define oit ostream_iterator
#define mod 1000000007ll
using namespace std;
void doin() {
	cin.tie();
	cout.tie();
	ios::sync_with_stdio(0);
#ifndef ONLINE_JUDGE
//	freopen("input.txt", "r", stdin);
//	freopen("output.txt", "w", stdout);
#endif
}
template<typename X, typename Y>
istream& operator>>(istream& in, pair<X, Y> &a) {
	in >> a.first >> a.second;
	return in;
}
template<typename T>
void getv(T& i) {
	cin >> i;
}
template<typename T, typename ... Ns>
void getv(vector<T>& v, int n, Ns ... ns) {
	v.resize(n);
	for (auto& i : v)
		getv(i, ns...);
}
template<typename T>
void getv1(T& i) {
	cin >> i;
}
template<typename T, typename ... Ns>
void getv1(vector<T>& v, int n, Ns ... ns) {
	v.resize(n + 1);
	for (int i = 1; i <= n; i++)
		getv(v[i], ns...);
}
#ifdef _WIN32
#define getchar_unlocked() _getchar_nolock()
#define _CRT_DISABLE_PERFCRIT_LOCKS
#endif
inline void getch(char &x) {
	while (x = getchar_unlocked(), x < 33) {
		;
	}
}
inline void getstr(string &str) {
	str.clear();
	char cur;
	while (cur = getchar_unlocked(), cur < 33) {
		;
	}
	while (cur > 32) {
		str += cur;
		cur = getchar_unlocked();
	}
}
template<typename T> inline bool sc(T &num) {
	bool neg = 0;
	int c;
	num = 0;
	while (c = getchar_unlocked(), c < 33) {
		if (c == EOF)
			return false;
	}
	if (c == '-') {
		neg = 1;
		c = getchar_unlocked();
	}
	for (; c > 47; c = getchar_unlocked())
		num = num * 10 + c - 48;
	if (neg)
		num *= -1;
	return true;
}
typedef unsigned long long ull;
typedef long long ll;
typedef float ld;
typedef ll _I;
typedef pair<_I, _I> pi;
typedef pair<ld, ld> pd;
typedef map<_I, _I> mii;
typedef __V <_I> vi;
typedef __V <char> vc;
typedef __V <ld> vd;
typedef __V <vd> vvd;
typedef __V <pi> vpi;
typedef __V <__V<_I>> vvi;
typedef __V <__V<char>> vvc;
typedef __V <__V<pi>> vvpi;
using AntonTsypko = void;
using arsijo = AntonTsypko;
using god = arsijo;
uniform_real_distribution<double> double_dist(0, 1);
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

int main() {
	doin();
	int n;
	cin >> n;
	vi a, r;
	getv(a, n);
	for(int i = 0; i < n; i++) {
		a[i]*=-1;
		auto it = upper_bound(all(r), a[i]);
		if(it == r.end()) r.pb(a[i]);
		else *it = a[i];
	}
	cout << r.size();
	return 0;
}


Measured memory_bytes: 2168
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
using namespace std;
using ll = long long;
using P = pair<int, int>;
using G = vector<vector<int>>;
    
int main(){
    string s, t;
    cin >> s >> t;
    int ans = 0;
    rep(i, s.size()){
        if(s[i]!=t[i]) ans++;
    }
    cout << ans << endl;
    return 0;
}

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

int main()
{
	int A, B, C, D;
	cin >> A >> B >> C >> D;

	if (A + B == C + D) {
		cout << "Balanced\n";
	}
	else if (A + B > C + D) {
		cout << "Left\n";
	}
	else if (A + B < C + D) {
		cout << "Right\n";
	}

	return 0;
}

Measured memory_bytes: 256
program main
    use iso_fortran_env
    implicit none

    character(1) :: txt
    character(27) :: cap
    integer(int32) :: i
    cap = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"

    i = 0
    read(*,*) txt
    i = index(cap, txt)

    if (i == 0) then
        print *, "a"
    else
        print *, "A"
    endif

end program main

Measured memory_bytes: 2860
import java.util.HashMap;
import java.util.Scanner;

public class Main {

	private static Scanner sc = new Scanner(System.in);

	public static void main(String[] args) {
		int n = sc.nextInt();
		HashMap<Integer, Integer> d = new HashMap<>();
		for (int i = 0; i < n; i++) {
			int dd = sc.nextInt();
			d.putIfAbsent(dd, 0);
			d.compute(dd, (k, v) -> v + 1);
		}
		int m = sc.nextInt();
		for (int i = 0; i < m; i++) {
			int tt = sc.nextInt();
			d.putIfAbsent(tt, 0);
			d.compute(tt, (k, v) -> v - 1);
			if (d.get(tt) < 0) {
				System.out.println("NO");
				return;
			}
		}
		System.out.println("YES");
	}
}

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

namespace ABC086_A
{
    class Program
    {
        static void Main(string[] args)
        {
            string[] array = Console.ReadLine().Split(' ');
            int a = int.Parse(array[0]);
            int b = int.Parse(array[1]);

            if ((a * b) % 2 == 1)
            {
                Console.WriteLine("Odd");
            }
            else
            {
                Console.WriteLine("Even");
            }
        }
    }
}


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

int main(){
  long N;cin>>N;
  vector<long>X(N),Y(N);
  vector<pair<long,long>>ai(N),bi(N);
  for(long i=0;i<N;i++){
    cin>>X[i]>>Y[i];
    ai[i]=pair<long,long>(X[i]+Y[i],i);
    bi[i]=pair<long,long>(X[i]-Y[i],i);
  }
  sort(ai.begin(),ai.end());
  sort(bi.begin(),bi.end());
  long ans=0;
  for(long i=0;i<N;i++){
    if((X[ai[0].second]-X[i])*(Y[ai[0].second]-Y[i])>=0){
      ans=max(ans,abs(X[i]+Y[i]-ai[0].first));
    }
    if((X[ai[N-1].second]-X[i])*(Y[ai[N-1].second]-Y[i])>=0){
      ans=max(ans,abs(X[i]+Y[i]-ai[N-1].first));
    }
    if((X[bi[0].second]-X[i])*(Y[bi[0].second]-Y[i])<=0){
      ans=max(ans,abs(X[i]-Y[i]-bi[0].first));
    }
    if((X[bi[N-1].second]-X[i])*(Y[bi[N-1].second]-Y[i])<=0){
      ans=max(ans,abs(X[i]-Y[i]-bi[N-1].first));
    } 
  }
  cout<<ans;
    
  
}



Measured memory_bytes: 12756
# -*- coding: utf-8 -*-

import heapq

def readInts():
  return [int(s) for s in input().split(" ")]

def main():
  N, M = readInts()
  tasks = [tuple(readInts()) for _ in range(N)]
  tasks.sort()

  h = []
  cur = 0
  ans = 0
  for m in range(1, M+1):
    while cur < len(tasks) and tasks[cur][0] <= m:
      heapq.heappush(h, -1 * tasks[cur][1])
      cur += 1
    if len(h) > 0:
      ans += -1 * heapq.heappop(h)
  print(ans)

if __name__ == "__main__":
  main()


Measured memory_bytes: 20776