akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <vector>
using namespace std;
 
int main() {
	int N;
	std::vector<string> S;
	string S_i;
	int P_i, karibango;
	std::vector<int> P, index;
	string kari;

	cin >> N;
	for(int i = 0; i < N; i++){
		cin >> S_i >> P_i;
		S.push_back(S_i);
		P.push_back(P_i);
		index.push_back(i+1);
	}

	for(int i = 0; i < N-1; i++){
		for(int j = N-1; j > i; j--){
			if(S[j] < S[j-1]){
				kari = S[j];
				S[j] = S[j-1];
				S[j-1] = kari;
				karibango = P[j];
				P[j] = P[j-1];
				P[j-1] = karibango;

				karibango = index[j];
				index[j] = index[j-1];
				index[j-1] = karibango;
			}else if(S[j] == S[j-1]){
				if(P[j] > P[j-1]){
					kari = S[j];
					S[j] = S[j-1];
					S[j-1] = kari;
					karibango = P[j];
					P[j] = P[j-1];
					P[j-1] = karibango;

					karibango = index[j];
					index[j] = index[j-1];
					index[j-1] = karibango;
				}
			}
		}
	}


	for(int i = 0; i < N; i++){
		cout << index[i] << endl;
	}
}





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

int main(){
	char a[27];
	gets(a,stdin);
	int len= strlen(a);
	//printf("%d\n",len);
	int check=0;
	for(int i=0;i<len+1;++i){
		for(int j=i+1;j<len+1;++j){
			if(a[i]==a[j]) check++;
		}
	}
	if(check==0){
		puts("yes");
	}else{
		puts("no");
	}
	return 0;
}

Measured memory_bytes: 128
#include <iostream>
#include <cstdio>
#include <string>

#include <map>
#include <set>
#include <algorithm>
#include <vector>
using namespace std;

int main ()
{
    int a,s,d;
    cin >> a >> s>> d;
    
    cout << (a+s)*d/2 << endl;
    
}



Measured memory_bytes: 256
#define _CRT_SECURE_NO_WARNINGS
#include "bits/stdc++.h"
using namespace std;
#define rep(i, n) for(int i=0; i<(n); ++i)
#define FOR(i, m, n) for(int i=(m); i<(n); ++i)
#define sz(x) ((int)(x).size())
#define all(x) (x).begin(),(x).end()
#define mp make_pair
#define pb push_back
#define Cout(x) cout << (x) << endl
#define Cout2(x, y) cout << (x) << " " << (y) << endl
#define dump(x) cerr << #x << " = " << (x) << endl;
typedef long long LL;
typedef vector<int> VI;
typedef vector<LL> VL;
typedef vector<string> VS;
typedef vector<bool> VB;
typedef vector<vector<int>> VVI;
typedef pair<int, int> PII;
const int inf = 1e9;
const double pi = acos(-1.0);

int main() {
	LL n; cin >> n;
	VL a(n), b(n), ab(n);
	rep(i, n) { cin >> a[i] >> b[i]; ab[i] = a[i] + b[i]; }

	LL ans = -accumulate(all(b), 0LL);
	sort(all(ab), greater<LL>());
	for (int i = 0; i < n; i += 2)ans += ab[i];
	Cout(ans);
}

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

int n;
vector<int> ans;
vector<vector<pair<int,int>>> graph;

void bfs(int v,int c){
  ans[v]=c;
  queue<pair<int,int>> que;
  que.push(make_pair(v,c));
  while(!que.empty()){
    v=que.front().first;
    c=que.front().second;
    que.pop();
    ans[v]=c;
    for(auto e:graph[v]){
      if(ans[e.first]!=-1) continue;
      if(e.second%2==0) que.emplace(e.first,c);
      else que.emplace(e.first,1-c);
    }
  }
}

int main(){
  cin >> n;
  ans.assign(n+1,-1);
  graph.assign(n+1,vector<pair<int,int>>());

  for (int i = 0; i < n-1; i++)
  {
    int u,v,w;
    cin >> u >> v >> w;
    graph[u].push_back(make_pair(v,w));
    graph[v].push_back(make_pair(u,w));
  }
  bfs(1,0);

  for (int i = 1; i <= n; i++)
  {
    cout << ans[i] << endl;
  }
  
}

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

void solve() {
    int N; cin >> N;
    vector<long long> A(N);
    rep(i, N) cin >> A[i];
    long long sum = accumulate(A.begin(), A.end(), 0LL);
    long long ans = sum;
    long long cur = 0LL;
    rep(i, N - 1) {
        cur += A[i];
        ans = min(ans, abs(sum - cur - cur));
    }
    cout << ans << '\n';
}

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


Measured memory_bytes: 1792
#include<bits/stdc++.h>
using namespace std;
typedef pair<int,int>pr;
bool solve(){
    int N,K;
    scanf("%d%d",&N,&K);
    if(N==0&&K==0)return false;
    vector<int>c;
    bool flag=false;
    for(int i=0;i<K;i++){
        int a;
        scanf("%d",&a);
        if(a)c.push_back(a);
        else flag=true;
    }
    sort(c.begin(),c.end());
    c.push_back(1<<30);
    vector<pr>V;
    int ma=0,cur=1;
    for(int i=0;i<c.size()-1;i++){
        if(c[i]+1==c[i+1]){
            cur++;
        }
        else {
            ma=max(ma,cur);
            V.push_back(pr(c[i-cur+1],c[i]));
            cur=1;
        }
    }
    if(flag){
        for(int i=0;i<V.size()-1;i++){
            if(V[i].second+2==V[i+1].first){
                ma=max(ma,V[i+1].second-V[i].first+1);
            }
        }
    }

    printf("%d\n",ma);
    return true;
}
int main(){
    while(solve());
    return 0;
}

Measured memory_bytes: 1712
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
#define MAXN 1001024
int gcd(int a,int b){
	if(b==0)return a;
	else return gcd(b,a%b);
}
//素数列挙
ll prime[MAXN] ;//segment_sieve [a,b)
bool is_prime[MAXN];
int sieve(int n){
	int res = 0;
	fill(is_prime,is_prime+MAXN,true);
	is_prime[0] = is_prime[1] = false;
	for(int i = 2;i<=n;i++){
		if(!is_prime[i])continue;
		prime[res++] = i;
		for(int j = 2*i;j<=n;j+=i)is_prime[j] = false;
	}
	return res;	
}
bool is_prime_ab[MAXN];
ll segment_sieve(ll a,ll b){
	fill(is_prime,is_prime+MAXN,true);
	fill(is_prime_ab,is_prime_ab+MAXN,true);
	for(int i=2;i*i <= b-1 ;i++){
		if(!is_prime[i]) continue;
		for(ll j = 2*i;j*j<=b-1;j+=i)is_prime[j] = false;
		for(ll j = a-a%i;j<b;j += i){
			if(j< a) continue;
			if(is_prime_ab[j-a]) is_prime_ab[j-a] = false;
		}
	}
	ll res = 0;
	for(ll i = a;i< b ;i++ )if(is_prime_ab[i-a] ) prime[res++] = i;
	return res;
}

bool is_primef(ll n){
	if(n==1) return false;
	for(ll i=2;i*i<=n;i++)
		if(n%i==0)return false;
	return true;
}

vector<ll> divisors(ll n){
	vector<ll> res;
	for(ll i=1;i*i<=n;i++){
		if(n%i != 0) continue;
		res.push_back(i);
		if(n/i== i)continue;
		res.push_back(n/i);
	}
	return res;
}
map<ll,ll> prime_factors(ll n){
	map<ll,ll> res;
	if(n<=1){
		res[n] = 1;
		return res;
	}
	
	//for(int i=2,_n = n;i*i<=_n;i++){
	for(ll i=2;i*i<=n;i++){
		while(n%i==0){
			res[i]++;
			n /= i;
		}
	}
	if(n!=1)res[n] = 1;
	return res;
}

//1からnまででnと互いにそなものの数
ll euler_phi(ll n){
	ll cnt = n;
	map<ll,ll> res = prime_factors(n);
	for(auto it = res.begin(),end = res.end();it!=end;it++){
		cnt = cnt/it->first*(it->first-1);
	}
	return cnt;
}


int main(){
	ll n;
	cin>>n;
	cout<<euler_phi(n)<<endl;
	return 0;
}



Measured memory_bytes: 3108
#include<bits/stdc++.h>
#define ios ios_base::sync_with_stdio(0);cin.tie(0);
using namespace std ;

int main(){
	string s1,s2;
	cin>>s1>>s2;
	int cnt=0;
	for(int i=0; i<s1.size(); i++){
		if(s1[i]==s2[i])
			cnt++; 
	} 
	cout<<cnt<<'\n';
	return 0;
}



Measured memory_bytes: 256
import re


n, k = map(int, input().split())
s = input()
s_re = re.split(r'(0+)', s)
srl = len(s_re)
m = [0] * srl
if srl // 2 <= k:
    ans = n
else:
    for i, w in enumerate(s_re):
        m[i] = len(w)
    tmp = sum(m[:k * 2 + 1])
    ans = tmp
    for i in range(0, srl, 2):
        ie = i + k * 2 + 1
        if ie < srl:
            tmp = tmp - m[i] - m[i+1] + m[ie] + m[ie+1]
            ans = max(ans, tmp)
        else:
            break
print(ans)

Measured memory_bytes: 52444
a = int(input())
temp = [0]*(a+1)
for i in range(a,0,-1):
    b = i
    while b%2 ==0:
        temp[i] += 1
        b = b//2
if temp.index(max(temp))==0:
    print(1)
else:print(temp.index(max(temp)))

Measured memory_bytes: 3060
N=int(input())
count=0
if N//100000==1:
    count=90909
elif N//10000>0:
    count=N%10000+910+((N//10000)-1)*10000
elif N//1000>0:
    count=909
elif N//100>0:
    count=N%100+10+((N//100)-1)*100
elif N//10>0:
    count=9
else:
    count=N//1
print(count)

Measured memory_bytes: 9096
nm = gets().split(" ");
n = nm[0].to_i;
m = nm[1].to_i;
l_max = 1;
r_min = n;
for i in 1..m
	s = gets.split(" ");
	l = s[0].to_i;
	r = s[1].to_i;
	if l >  l_max
		l_max = l;
	end
	if r < r_min
		r_min = r;
	end
end
ans = r_min - l_max + 1;
if ans > 0
	puts(ans);
else
	puts(0);
end

Measured memory_bytes: 1788
def maxSubarrayXOR(lis, n, INT_BITS = 60):
    idx = 0
    for i in range(INT_BITS-1,-1,-1):
        Midx = -1
        bit_i = 1 << i
        for j in range(idx, n):
            if lis[j] & bit_i:
                Midx = j
                break
        else: continue
        lis[Midx], lis[idx] = lis[idx], lis[Midx]
        for j in range(n):
            if j != idx and lis[j] & bit_i:
                lis[j] ^= lis[idx]
        idx += 1
    res = 0
    for x in lis: res ^= x
    return res

n = int(input())
a = list(map(int, input().split()))
t = 0
for x in a: t ^= x
b = [x^(x&t) for x in a]
print(t + maxSubarrayXOR(b, n)*2)


Measured memory_bytes: 16116
#include <bits/stdc++.h>
#define mem(dp,a) memset(dp,a,sizeof(dp))
#define pb(x) push_back(x)
#define m_p(x,y) make_pair(x,y)
#define rep(i,a,b) for(ll i=a;i<b;i++)
#define repush_back(i,a,b) for(ll i=a;i>=b;i--)
#define f(n) for(ll i=0;i<n;i++)
#define r(n) for(ll j=0;j<n;j++)
#define F first
#define S second
#define pi 3.14159265359
#define hs ios_base::sync_with_stdio(false);cin.tie(NULL);
using namespace std;
typedef long long int ll;
ll HRX=1e18;
ll INF=1e9+7;

int main()
{
  hs;
  ll n;
  cin>>n;
  ll m[n+1];
  f(n+1)
  {
    cin>>m[i];
  }
  ll h[n];
  f(n)
  {
    cin>>h[i];
  }
  ll cnt=0;
  for(ll i=0;i<n;i++)
  {
    if(m[i]<=h[i])
    {
     cnt+=m[i];
     h[i]=h[i]-m[i];
     if(h[i]>0)
     {
        if(m[i+1]>h[i])
        {
          cnt+=h[i];
          m[i+1]=m[i+1]-h[i];
        }

        else
        {
         cnt+=m[i+1];
         m[i+1]=0;
        }
     }

    }
    else if(m[i]>h[i])
    {
     cnt+=h[i];
    }



  }
  cout<<cnt<<endl;
  return 0;
}


Measured memory_bytes: 1792
# -*- coding: utf-8 -*-
"""
https://abc058.contest.atcoder.jp/tasks/abc058_a

"""
import sys
from sys import stdin
input = stdin.readline


def solve(a, b, c):
    if b - a == c - b:
        return 'YES'
    else:
        return 'NO'


def main(args):
    a, b, c = map(int, input().split())
    ans = solve(a, b, c)
    print(ans)


if __name__ == '__main__':
    main(sys.argv[1:])


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

using namespace std;
using ll = long long;

//container util
#define SORT(c) sort((c).begin(),(c).end())

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

//print
#define pv(val) cerr << #val << '=' << (val) << endl

const int INF = 1e9;

int main(void){

	string s; cin >> s;
	if(s == "ABC") cout << "ARC" << endl;
	else cout << "ABC" << endl;


	return 0;

}


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

int main(){

    int a,b;

    cin >> a >>b;

    if(b%a==0){
        cout << a+b << endl;
    }else{
        cout << b-a << endl;
    }

    return 0;
}

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

int main(void)
{

  long int N, ans;
  long int max;
  long int large, small;
  int i;

  scanf("%ld",&N);
  max = sqrt(N);

  for(i=max;i>=1;i--){
    if(N%i==0){
      small = i;
      large = N/i;
      break;
    }
  }
  ans = small + large - 2;
  printf("%ld\n",ans);

  return 0;
}






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

int main(){
  string s; cin >> s;
  int count=0, ans=0;
  char looking='\0';
  for(int i=0; i<4; i++){
    if(looking!=s[i]){
      looking=s[i];
      count=1;
    }else count++;
    ans = max(ans, count);
  }

  string anss="No";
  if(ans>=3) anss="Yes";
  cout << anss << endl;
  return 0;
}


Measured memory_bytes: 256
using System;

namespace AtCoder1
{
    class Program
    {
        static void Main(string[] args)
        {
            int x = int.Parse(Console.ReadLine());
            if (x == 7)
            {
                Console.WriteLine("YES");
            }
            else if (x == 5)
            {
                Console.WriteLine("YES");
            }
            else if (x == 3)
            {
                Console.WriteLine("YES");
            }
            else 
            {
                Console.WriteLine("NO");
            }
        }
    }
}


Measured memory_bytes: 11092
import heapq
N, M = map(int, input().split())
A = list(map(lambda x: int(x)*-1, input().split()))
heapq.heapify(A)
for i in range(M):
    tmp = heapq.heappop(A)
    heapq.heappush(A, (tmp+1) // 2)
print(str(-sum(A)))

Measured memory_bytes: 14252
#include <stdio.h>
int main(){
    int a,b,c;
    int count=0;
    int i;
    scanf("%d %d %d",&a,&b,&c);
    for(i=a;i<=b;i++){
        if(c%i==0){
            count++;
        }
    }
    printf("%d\n",count);
}


Measured memory_bytes: 2084
#include <iostream>
#include <vector>
#include <string>

using namespace std;

using vi = vector<int>;

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

    int n, m;
    cin >> n >> m;
    vi s(m), c(m);
    for (int i = 0; i < m; i++) {
        cin >> s.at(i) >> c.at(i);
        s.at(i)--;
    }

    for (int i = 0; i < 1000; i++) {
        string t = to_string(i);

        bool f = true;
        if ((int)t.length() == n) {
            for (int j = 0; j < m; j++) {
                if (t.at(s.at(j)) != c.at(j) + '0') {
                    f = false;
                }
            }
        } else {
            f = false;
        }

        if (f) {
            cout << i << endl;
            return 0;
        }
    }

    cout << -1 << endl;

    return 0;
}


Measured memory_bytes: 3700
#define _USE_MATH_DEFINES

#include <cstdio>
#include <cstdlib>
#include <iostream>
#include <cmath>
#include <algorithm>
#include <vector>
#include <queue>
#include <map>
#include <list>

using namespace std;

long long int INF = 1e18;
long long int MOD = 1e9 + 7;

typedef pair<long long int, long long int> P;

#define MAX_V 200000

struct edge{
	int to;
	long long int cost;
};

vector<edge> G[MAX_V];
long long int d[MAX_V];

// 計算コストはO(ElogV)

void shortest_path(int s, int V){ // Vは頂点数
	
	priority_queue<P, vector<P>, greater<P> > que;
	
	for(int i = 0; i < V; i++){
		d[i] = INF;
	}
	d[s] = 0;
	
	que.push(P(0, s));
	
	while(!que.empty()){
		
		P p = que.top();
		que.pop();
		
		int v = p.second;
		
		if(d[v] < p.first){
			continue;
		}
		
		for(int i = 0; i < G[v].size(); i++){
			edge e = G[v][i];
			if(d[e.to] > e.cost + d[v]){
				d[e.to] = d[v] + e.cost;
				que.push(P(d[e.to], e.to));
			}
		} // 頂点への最小コストを更新
	}
}

int main(){
	
	while(true){
		int N;
		cin >> N;
		if(N == 0){
			break;
		}
		int H = N + 10;
		int a[1000] = {};
		for(int i = 0; i < 2 * H; i++){
			G[i].clear();
		}
		for(int i = 0; i < N; i++){
			cin >> a[i];
		}
		for(int i = 0; i < N; i++){
			edge e;
			if(a[i] == 2){
				e.to = i - 1;
				e.cost = 0;
				G[i].push_back(e);
			}else if(i == N - 1 || a[i] == 1 && a[i + 1] == 1){
				e.to = i + 1;
				e.cost = 0;
				G[i].push_back(e);
			}else{
				e.cost = 1;
				e.to = i + H;
				G[i].push_back(e);
				e.to = i + H + 1;
				G[i].push_back(e);
				e.to = i + H + 2;
				G[i].push_back(e);
			}
		}
		for(int i = 0; i < N; i++){
			cin >> a[i];
		}
		for(int i = 0; i < N; i++){
			edge e;
			if(a[i] == 2){
				e.to = i + H - 1;
				e.cost = 0;
				G[i + H].push_back(e);
			}else if(i == N - 1 || a[i] == 1 && a[i + 1] == 1){
				e.to = i + H + 1;
				e.cost = 0;
				G[i + H].push_back(e);
			}else{
				e.cost = 1;
				e.to = i;
				G[i + H].push_back(e);
				e.to = i + 1;
				G[i + H].push_back(e);
				e.to = i + 2;
				G[i + H].push_back(e);
			}
		}
		edge e2;
		e2.cost = 0;
		e2.to = H;
		G[0].push_back(e2);
		shortest_path(0, 2 * H);
		long long int ans = min(d[N], d[N + H]);
		if(ans == INF){
			cout << "NA" << endl;
		}else{
			cout << ans << endl;
		}
	}
	
	return 0;
}



Measured memory_bytes: 7844
#include<stdio.h>
#include<string.h>
#include<stdlib.h>
int main(){
	int a, b, n;
	char s[100005];
	scanf("%d %d %d", &n, &a, &b);
	scanf("%s", s);
	for (int i = 0; i < n; i++){
		if (s[i] == 'a')
		{
			if (a + b>0){
				printf("Yes\n");
				a--;
			}
			else printf("No\n");
		}
		else if (s[i] == 'b')
		{
			if (a + b>0){
				if (b > 0){
					printf("Yes\n");
					b--;
				}
				else printf("No\n");
			}
			else printf("No\n");
		}
		else printf("No\n");
	}
	return 0;
}

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

#undef _P
#define _P(...) (void)printf(__VA_ARGS__)
#define FOR(x,to) for(x=0;x<(to);x++)
#define FORR(x,arr) for(auto& x:arr)
#define ITR(x,c) for(__typeof(c.begin()) x=c.begin();x!=c.end();x++)
#define ALL(a) (a.begin()),(a.end())
#define ZERO(a) memset(a,0,sizeof(a))
#define MINUS(a) memset(a,0xff,sizeof(a))
//-------------------------------------------------------

int X,A,B;

void solve() {
	int i,j,k,l,r,x,y; string s;
	
	cin>>X>>A>>B;
	cout<<(X-A)%B<<endl;
}


int main(int argc,char** argv){
	string s;int i;
	if(argc==1) ios::sync_with_stdio(false), cin.tie(0);
	FOR(i,argc-1) s+=argv[i+1],s+='\n'; FOR(i,s.size()) ungetc(s[s.size()-1-i],stdin);
	cout.tie(0); solve(); return 0;
}


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

int main(){

    std::priority_queue <int>Q;
    int n;
    int a;

    scanf("%d\n", &n);

    for (int i = 0; i < n; i++){
        scanf("%d", &a);
        Q.push(a);
    }

    int ans = 0;
    while( 1 ){
        if(Q.empty()) break;
        ans += Q.top();
        Q.pop();
        if(Q.empty()) break;
        ans -= Q.top();
        Q.pop();
    }

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

    return 0;
}


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

#define ll long long
#define fw(p) for(int w=0;w<(p);w++)
#define fx(p) for(int x=0;x<(p);x++)
#define fy(p) for(int y=0;y<(p);y++)
#define fz(p) for(int z=0;z<(p);z++)
#define fyg(p,g) for(int y=(g);y<(p);y++)
#define fzg(p,g) for(int z=(g);z<(p);z++)
#define ce(d) cout<<d<<endl;
#define vecp(p) int aa;cin>>aa;(p).push_back(aa);
#define vecpl(p) long long aa;cin>>aa;(p).push_back(aa);
#define vecps(p) string aa;cin>>aa;(p).push_back(aa);
#define vecp2(p) cin>>aa;(p).push_back(aa);
#define vecpl2(p) long long a	b;cin>>ab;(p).push_back(ab);
#define vecps2(p) string ab;cin>>ab;(p).push_back(ab);
#define sorts(c) sort((c).begin(),(c).end());
#define reverses(c) reverse((c).begin(),(c).end());
#define vec(b) vector<int> (b);
#define vecl(b) vector<long long> (b);
#define vecs(b) vector<string> (b);
#define pb(b,a) (b).push_back((a));
#define doublece(a,b) cout<<(a)<<' '<<(b)<<endl;
#define pairs(s) vector<pair<int,int>> (s);
#define pairsp(s) int aa,bb;cin>>aa>>bb;(s).push_back(make_pair(aa,bb));
#define MOD 1000000007
#define cey ce("Yes")
#define cen ce("No")
#define ceY ce("YES")
#define ceN ce("NO")
ll dp[110][110][2];
int main()
{
	string N;
	int K;
	cin >> N >> K;
	dp[0][0][0] = 1;
	fx(N.size()) {
		fy(10) {
			if (y<N[x]-'0') {
				fz(4) {
					if (y==0) {
						dp[x + 1][z][1] += dp[x][z][1] + dp[x][z][0];
					}
					else {
						dp[x + 1][z + 1][1] += dp[x][z][1] + dp[x][z][0];
					}

				}
			}
			else if (y == N[x] - '0') {
				fz(4) {
					if (y == 0) {
						dp[x + 1][z][1] += dp[x][z][1];
						dp[x + 1][z][0] += dp[x][z][0];
					}
					else {
						dp[x + 1][z + 1][1] += dp[x][z][1];
						dp[x + 1][z + 1][0] += dp[x][z][0];
					}

				}
			}
			else if(x!=0){
				fz(4) {
					if (y == 0) {
						dp[x + 1][z][1] += dp[x][z][1];
					}
					else {
						dp[x + 1][z + 1][1] += dp[x][z][1];
					}
				}
			}
		}
	}

	ce(dp[N.size()][K][1]+ dp[N.size()][K][0])

    return 0;
}



Measured memory_bytes: 384
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
using vi=vector<int>;
using vvi=vector<vi>;
using pii=pair<int,int>;
#define rep(i,n) for(int i=0;i<n;i++)
#define range(i,a,n) for(int i=a;i<n;i++)
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define INF 1e9
#define EPS 1e-9
#define MOD (1e9+7)
void put(string d){}template<class H,class...T>void put(string d,H&h,T&...t){cout<<h;if(sizeof...(t))cout<<d;put(d,t...);}
template<class T>void puti(T&a,string d=" "){bool f=1;for(auto&_:a)cout<<(exchange(f,0)?"":d)<<_;cout<<endl;}
template<class T>void putii(T&a,string d=" "){for(auto&_:a)puti(_,d);}

int main(){
	ll n,a,b; cin>>n>>a>>b;
	vi h(n);
	for(auto&i:h)cin>>i;
	
	ll l=0,r=1000000001;
	while(r-l>1){
		int m=(l+r)/2, t=m;
		auto cp=h;
		rep(i,n){
			if(cp[i]>b*m){
				cp[i]-=b*m;
				t-=ceil(cp[i]/(double)(a-b));
			}
		}
		(t>=0?r:l)=m; 
	}
	cout<<r<<endl;
	return 0;
}


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

#define for_(i,a,b) for(int i=a;i<b;++i)
#define ALL(a) a.begin(),a.end()
#define INIT(a,b) memset(a,b,sizeof(a))
using lint = long long int;

int main() {
    char C;
    cin >> C;
    puts('A' <= C and C <= 'Z' ? "A" : "a");
}

Measured memory_bytes: 3616
#include <bits/stdc++.h>
#define int long long
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
using namespace std;
constexpr int MOD = 1000000007;
constexpr int INF = numeric_limits<int>::max() / 2;
typedef pair<int,int> P;
using Graph = vector<vector<int>>;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
const double PI = acos(-1.0);
// cout << fixed << setprecision(14);
 
signed main(){
	cin.tie(nullptr);
	ios::sync_with_stdio(false);

    int K;
    cin >> K;
    cout << 50 << endl;
    int W = K/50+49;
    int X = K % 50;
    rep(i,X){
        cout << W+50+1-X << " ";
    }
    rep(i,50-X){
        cout << W-X << " ";
    }
    cout << endl;
}

Measured memory_bytes: 256
fun main(args: Array<String>) {
    val sc = java.util.Scanner(System.`in`)
    val L = sc.nextLong()
    val R = sc.nextLong()


    var t = 99999999999L
    (L..Math.min(R - 1, L + 2020)).map { l1 ->
        (Math.max(L + 1, R - 2020)..R).map { r1 ->
            t = Math.min(t, (l1 * r1) % 2019)
        }
    }

    println(t)
}


Measured memory_bytes: 75732
#include <iostream>
#include <cstdint>
#include <cmath>
#include <string>
#include <vector>
#include <map>
#include <set>
#include <algorithm>
#include <iomanip>
#include <sstream>

int main(void)
{
    int64_t N, M;
    std::cin >> N >> M;

    std::vector<bool> cards(N, false);

    int64_t L = 1;
    int64_t R = N;
    for (int64_t i=0; i < M; ++i) {
        int64_t l, r;
        std::cin >> l >> r;
        if (L < l) L = l;
        if (r < R) R = r;
    }

    int64_t ans = 0;
    if (R < L) ans = 0;
    else ans = R-L+1;

    std::cout << ans << std::endl;

    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define FAST ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define MAXX 100005
#define ll signed long long int
using namespace std;
 
ll ans = 0, a[MAXX],b[MAXX] ,n,c,  t, m = 0, z= 0,x = 1,f=0, mx, mn;
signed main()
{
    FAST;
	ll y ;
	cin >> x >> y >> z;
	if(x+y+z >= 22){
		cout << "bust";
		return 0;
	}
	cout << "win";
}

Measured memory_bytes: 256
#include <cstdio>

int main()
{
    int n,m,l;
    scanf("%d %d %d", &n, &m, &l);

    int A[n][m], B[m][l];
    for(int i = 0; i < n; i++){
        for(int j = 0; j < m; j++){
            scanf("%d", &A[i][j]);
        }
    }
    for(int i = 0; i < m; i++){
        for(int j = 0; j < l; j++){
            scanf("%d", &B[i][j]);
        }
    }

    unsigned long int C[n][l];
    for(int i = 0; i < n; i++){
        for(int j = 0; j < l; j++) C[i][j] = 0;
    }

    for(int i = 0; i < n; i++){
        for(int j = 0; j < l; j++){
            for(int k = 0; k < m; k++) C[i][j] += A[i][k]*B[k][j];
        }
    }

    for(int i = 0; i < n; i++){
        for(int j = 0; j < l; j++){
            if(n == 1 && l == 1) printf("%ld\n", C[i][j]);
            else if(j == 0) printf("%ld", C[i][j]);
            else if(j != l-1) printf(" %ld", C[i][j]);
            else printf(" %ld\n", C[i][j]);
        }
    }
    return 0;
}

Measured memory_bytes: 1184
import java.util.*;

public class Main {
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    int n = sc.nextInt();
    int k = sc.nextInt();
    long[] h = new long[n];
    for(int i = 0; i < n; i++) {
      h[i] = sc.nextLong();
    }
    long[] dp = new long[n];
    for(int i = 1; i < n; i++) {
      dp[i] = Long.MAX_VALUE;
    }
    for(int i = 1; i < n; i++) {
      for(int j = 1; j <= k; j++) {
        if(i >= j) dp[i] = Math.min(dp[i], dp[i - j] + Math.abs(h[i] - h[i - j]));
      }
    }
    System.out.println(dp[n - 1]);
  }
}

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

void solve(){
    int x, a;
    cin >> x >> a;
    if(x < a) cout << 0 << endl;
    else cout << 10 << endl;

}

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

Measured memory_bytes: 256
package main

import (
	"fmt"
	"strings"
)

func main() {
	var h, w int
	fmt.Scan(&h, &w)
	cnt := 0

	for i := 0; i < h; i++ {
		var a string
		fmt.Scan(&a)
		cnt += strings.Count(a, "#")
	}

	if cnt == h+w-1 {
		fmt.Println("Possible")
	} else {
		fmt.Println("Impossible")
	}
}


Measured memory_bytes: 640
b=input().split(" ")
a0=input().split(" ")
a1=input().split(" ")
a2=input().split(" ")
a3=input().split(" ")
a4=input().split(" ")
a5=input().split(" ")
a6=input().split(" ")
a7=input().split(" ")
a8=input().split(" ")
a9=input().split(" ")
array=[a0,a1,a2,a3,a4,a5,a6,a7,a8,a9]
cost=0
for k in range(10):
	for i in range(10):
		for j in range(10):
			array[i][j]=min(int(array[i][j]),int(array[i][k])+int(array[k][j]))
for i in range(int(b[0])):
	lines=input().split()
	for j in range(int(b[1])):
		if int(lines[j])!=-1:
			cost+=int(array[int(lines[j])][1])
print(cost)

Measured memory_bytes: 3064
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#include<climits>
#include<queue>
#include<stack>
	

int main(){
	int n, k;
	int ans=0;
	int sum=0;
	int minSum=0;

	std::vector<int> aList;
	std::vector<int> deltaList;

	std::cin>>n>>k;

	aList.resize(n);
	deltaList.resize(n-1);
	for(int i=0; i<n; i++)
		std::cin>>aList[i];

	std::sort(aList.begin(), aList.end(), [](int x, int y){return x>y;});

	for(int i=0; i<n-1; i++)
		deltaList[i]= aList[i]- aList[i+1];

	for(int i=0; i<k-1; i++)
		sum+=deltaList[i];

	minSum=sum;

	for(int i=0; i<n-k; i++){
		sum-= deltaList[i];
		sum+= deltaList[i+k-1];

		if(sum<minSum)
			minSum=sum;
	}

	std::cout<<minSum<<std::endl;

	return 0;	
}


Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
#define endl                        '\n'
#define debug(x)                    cerr << #x << ": " <<  x << endl;
#define fast_io;                    ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
const ll MAXN=1e6 + 10;
const ll LOG=22;
const ll INF=8e18;
const ll MOD=1e9 + 7; // 998244353; // 1e9 + 9;
int main(){
fast_io;
int a,b;
char c;
cin>>a>>c>>b;
if(c=='+'){
      cout<<a+b;
      return 0;
}
cout<<a-b;
return 0;
}


Measured memory_bytes: 256
def examB():
    S = SI(); N =len(S)
    ans = N//2
    for i in range(N//2):
        if S[i]==S[N-1-i]:
            ans -=1
    print(ans)
    return

def examC():
    return

def examD():
    return

def examE():
    return

def examF():
    return

import sys,copy,bisect,itertools,heapq,math
from heapq import heappop,heappush,heapify
from collections import Counter,defaultdict,deque
def I(): return int(sys.stdin.readline())
def LI(): return list(map(int,sys.stdin.readline().split()))
def LSI(): return list(map(str,sys.stdin.readline().split()))
def LS(): return sys.stdin.readline().split()
def SI(): return sys.stdin.readline().strip()
mod = 10**9 + 7
inf = float('inf')

if __name__ == '__main__':
    examB()


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

int main() {
  int x;
  cin >> x;
  if (x >= 400 && x <= 599) cout << 8 << endl;
  if (x >= 600 && x <= 799) cout << 7 << endl;
  if (x >= 800 && x <= 999) cout << 6 << endl;
  if (x >= 1000 && x <= 1199) cout << 5 << endl;
  if (x >= 1200 && x <= 1399) cout << 4 << endl;
  if (x >= 1400 && x <= 1599) cout << 3 << endl;
  if (x >= 1600 && x <= 1799) cout << 2 << endl;
  if (x >= 1800 && x <= 1999) cout << 1 << endl;
}

Measured memory_bytes: 3628
#include <iostream>

using namespace std;

int main() {
    int N;
    cin >> N;
    int sum = 0;
    int l, r;

    for (int i = 0; i < N; i++) {
        cin >> l >> r;

        sum += (r - l) + 1;
    }

    cout << sum << endl;

    return 0;
}

Measured memory_bytes: 256
import java.io.*;
import java.util.*;
 
public class Main {
 
	void submit() {

        int H = nextInt();
        int A = nextInt();
        
        if(H%A==0){
    	    out.println(H/A);
        }else{
    	    out.println((H/A)+1);
        }
	}
 
	void preCalc() {
 
	}
 
	void stress() {
 
	}
 
	void test() {
 
	}
 
	Main() throws IOException {
		br = new BufferedReader(new InputStreamReader(System.in));
		out = new PrintWriter(System.out);
		preCalc();
		submit();
		//stress();
		//test();
		out.close();
	}
 
	static final Random rng = new Random();
 
	static int rand(int l, int r) {
		return l + rng.nextInt(r - l + 1);
	}
 
	public static void main(String[] args) throws IOException {
		new Main();
	}
 
	BufferedReader br;
	PrintWriter out;
	StringTokenizer st;
 
	String nextToken() {
		while (st == null || !st.hasMoreTokens()) {
			try {
				st = new StringTokenizer(br.readLine());
			} catch (IOException e) {
				throw new RuntimeException(e);
			}
		}
		return st.nextToken();
	}
 
	String nextString() {
		try {
			return br.readLine();
		} catch (IOException e) {
			throw new RuntimeException(e);
		}
	}
 
	int nextInt() {
		return Integer.parseInt(nextToken());
	}
 
	long nextLong() {
		return Long.parseLong(nextToken());
	}
 
	double nextDouble() {
		return Double.parseDouble(nextToken());
	}
}

Measured memory_bytes: 22996
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class Main{
	public static void main(String[] args) throws IOException {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		String str,strArray[];
		boolean cups[] = new boolean[3];
		char cupAl[] = {'A', 'B', 'C'};

		cups[0] = true;

		while(null!=(str=br.readLine())){
			strArray = str.split(",");
			int l=0,r=0;

			if(strArray[0].equals("A")){
				r=0;
			}else if(strArray[0].equals("B")){
				r=1;
			}else if(strArray[0].equals("C")){
				r=2;
			}

			if(strArray[1].equals("A")){
				l=0;
			}else if(strArray[1].equals("B")){
				l=1;
			}else if(strArray[1].equals("C")){
				l=2;
			}
			Chenge(r, l, cups);
		}

		for(int i=0; i<cups.length; i++){
			if(cups[i]){
				System.out.println(cupAl[i]);
				break;
			}
		}
	}

	static void Chenge(int r, int l, boolean cups[]){
		boolean temp=cups[r];
		cups[r]=cups[l];
		cups[l]=temp;
	}

}

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

using namespace std;
using ll = long long;

int main() {
    int a,b,c,k;
    cin>>a>>b>>c>>k;
    if(k<=a)cout<<k<<endl;
    else if(k-a<=b)cout<<a<<endl;
    else cout<<a-(k-a-b)<<endl;
    return 0;
}


Measured memory_bytes: 3636
#include <algorithm>
#include <cmath>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <vector>

typedef long long ll;

using namespace std;

int main() {
    ll x;
    cin >> x;
    ll n = 6 + 5;
    ll num = x / n;
    ll remain = x % n;
    int addition;
    ll ans = num * 2;
    if (remain > 6) {
        cout << ans + 2 << "\n";
        return 0;
    }
    if (remain > 0) {
        cout << ans + 1 << "\n";
        return 0;
    }
    cout << ans << "\n";
    return 0;
}

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

#define EPS (1e-10)
#define equals(a, b) (fabs((a) - (b)) < EPS)

class Point
{
    public:
    double x, y;

    Point(double x = 0, double y = 0): x(x), y(y) {}

    Point operator + (Point p) {return Point(x + p.x, y + p.y); }
    Point operator - (Point p) {return Point(x - p.x, y - p.y); }
    Point operator * (double a) {return Point(x * a, y * a);}
    Point operator / (double a) {return Point(x / a, y / a);}

    double abs() {return sqrt(norm());}
    double norm() {return x * x + y * y;}
    
    bool operator < (const Point &p) const {
        return x != p.x ? x < p.x : y < p.y;
    }

    bool operator == (const Point &p) const{
        return equals(x, p.x) && equals(y, p.y);
    }
};typedef Point Vector;

typedef vector<Point> Polygon;

struct Segment {
    Point p1, p2;
};

double dot(Vector a, Vector b){
    return a.x * b.x + a.y * b.y;
}

double cross(Vector a, Vector b){
    return a.x * b.y - a.y * b.x;
}

bool ccw(Point p0, Point p1, Point p2){
    Vector a = p1 - p0, b = p2 - p0;
    if (cross(a, b) > EPS) return true;
    if (cross(a, b) < -EPS) return false;
    if (dot(a, b) < -EPS) return false;
    if (a.norm() < b.norm()) return false;
    return false;
}

Polygon andrewScan(Polygon s){
    Polygon u, l;
    if (s.size() < 3) return s;
    sort(s.begin(), s.end());
    u.push_back(s[0]);
    u.push_back(s[1]);
    l.push_back(s[s.size()-1]);
    l.push_back(s[s.size()-2]);
    for (int i = 2; i < s.size(); i++){
        for (int n = u.size(); n >= 2 && ccw(u[n-2], u[n-1], s[i]); n--){
            u.pop_back();
        }
        u.push_back(s[i]);
    }
    
    for (int i = s.size()-3; i >= 0; i--){
        for (int n = l.size(); n >= 2 && ccw(l[n-2],l[n-1],s[i]); n--){
            l.pop_back();
        }
        l.push_back(s[i]);
    }
    reverse(l.begin(), l.end());
    for (int i = u.size()-2;i>=1;i--)l.push_back(u[i]);
    return l;
}
int main(){
    int n; cin >> n;
    Polygon G;
    for (int i = 0; i < n; i++)
    {
        int x, y; cin >> x >> y;
        G.push_back(Point(x, y));
    }
    Polygon H = andrewScan(G);
    cout << H.size() << endl;
    int start = 0;
    for (int i = 0; i < H.size(); i++)
    {
        if (H[i].y < H[start].y) start = i;
    }
    
    for (int i = 0; i < H.size(); i++)
    {
        cout << H[(start+i)%H.size()].x << " " << H[(start+i)%H.size()].y << endl;
    }
}


Measured memory_bytes: 9336
#include<bits/stdc++.h> 
using namespace std;
typedef long long ll;
template<typename T1,typename T2> bool chmin(T1 &a,T2 b){if(a<=b)return 0; a=b; return 1;}
template<typename T1,typename T2> bool chmax(T1 &a,T2 b){if(a>=b)return 0; a=b; return 1;}
int dx[4]={0,1,-1,0};
int dy[4]={1,0,0,-1};


signed main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout << fixed << setprecision(20);

    int h,w,n;
    cin>>h>>w>>n;
    int a,b;
    map<int,int> mh[h],mw[w];
    vector<int> vh[h],vw[w];
    int ch[h]={}, cw[w]={};
    for(int i=0;i<n;i++){
        cin>>a>>b;
        a--,b--;
        ch[a]++;
        cw[b]++;
        vh[a].push_back(b);
        vw[b].push_back(a);
        mh[a][b] = 1;
        mw[b][a] = 1;
    }
    int mmh=0,mmw=0;
    for(int i=0;i<h;i++)chmax(mmh,ch[i]);
    for(int i=0;i<w;i++)chmax(mmw,cw[i]);
    int ans = mmh + mmw - 1;
    bool pos = false;

    bool used[w]={};
    int t = 0;
    for(int j=0;j<w;j++){
        if(mmw == cw[j]){
            used[j] = 1;
            t++;
        }
    }

    for(int i=0;i<h;i++){
        if(mmh == ch[i]){
            int cnt = 0;
            for(auto j:vh[i]){
                if(used[j])cnt++;
            }
            if(cnt != t)pos = 1;
        }
    }



    ans += pos;
    cout << ans << endl;

}   

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

int main(){
	int a[6];
	for(int b=0;b<3;b++){
		for(int c=0;c<6;c++)scanf("%d",&a[c]);
		int d=(a[3]-a[0])*3600+(a[4]-a[1])*60+(a[5]-a[2]);
		printf("%d %d %d\n",d/3600,d%3600/60,d%3600%60);
	}
}

Measured memory_bytes: 3172
#include <bits/stdc++.h>
 
#define rep(i,n) for(ll i=0;i<n;++i)
#define all_map(pos,mp) for(ll pos=mp.begin();pos!=mp.end();pos -++)
#define ALL(a) (a).begin(),(a).end()

using namespace std;
using ll  = long long;
using pll = pair<ll, ll>;

const ll MOD  = 1e9 + 7;
const ll LINF = 1LL << 62;
const int INF = 1e9 + 7;

const ll MAX = 1e6+7;
ll fac[MAX], finv[MAX], inv[MAX];
//初期化
void COMinit() {
    fac[0]  = fac[1]  = 1;
    finv[0] = finv[1] = 1;
    inv[1]  = 1;

    for(int i = 2; i < MAX; ++i){
        fac[i]  = fac[i - 1] * i % MOD;
        inv[i]  = MOD - inv[MOD%i] * (MOD / i) % MOD;
        finv[i] = finv[i - 1] * inv[i] % MOD;
    }
}
//nCk
ll COM(int n, int k){
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;

    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}

//MODでべき乗が計算できる
ll modpow(ll a, ll n, ll mod) {
    ll res = 1;
    while (n > 0) {
        if (n & 1) res = res * a % mod;
        a = a * a % mod;
        n >>= 1;
    }
    return res;
}

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

    // except mat that not contain 1 and 9
    ll ans = modpow(10, n, MOD);

    ll exp1and9 = modpow(8, n, MOD);
    ll exp1or9 = modpow(9, n, MOD) - exp1and9; 

    ans -= exp1and9 + 2 * exp1or9;
    ans += 10*MOD;
    ans %= MOD;

    cout << ans << endl;
}

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

using namespace std;

typedef long long ll;

const int INF = 1e9;
const ll LLINF = 1e18;
const ll MOD = (ll)1e9 + 7;

int main()
{
  int W, H, N; scanf("%d %d %d", &W, &H, &N);
  int x, y, a;
  int left = 0, right = W, top = H, bottom = 0;
  for (int i = 0; i < N; ++i) {
    scanf("%d %d %d", &x, &y, &a);
    if (a == 1) {
      left = max(left, x);
    }
    else if (a == 2) {
      right = min(right, x);
    }
    else if (a == 3) {
      bottom = max(bottom, y);
    }
    else if (a == 4) {
      top = min(top, y);
    }
  }
  int ans = max(0, (right - left)) * max(0, (top - bottom));
  printf("%d\n", ans);
  return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define FAST ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
using namespace std;
//long long int countt[200003];
#include<ext/pb_ds/assoc_container.hpp> // include the associative containers or group of templates such as set, multimap, map etc.
#include<ext/pb_ds/tree_policy.hpp> // include the tree_order_statistics_node update
using namespace __gnu_pbds; //necessary for the GNU based Policy based data structures.
typedef tree<pair<int,int> ,null_type,less<pair<int,int>>,rb_tree_tag,tree_order_statistics_node_update> ordered_set;

#define int long long
#define endl "\n"


signed main()
{
    FAST;
    
    int i=0,j=0,k=0,n=0,m=0,count=0,temp=0;
    int temp1=0,temp2=0,temp3=0,x=0,l=0,y=0,sum=0;
    int left=0,up=0,down=0,start=0,end=0,r=0,q=0,total=0;
    int maxx=0,minn=0,curr=0,ans=0,places=0,zeroes=0,low=0,high=0;
    int prev=0,mid=0,z=0,d=0,val=0,pos=0,shift=0,h=0,right=0,var=0;
    
    int a,b,c;
    cin>>a>>b>>c>>k;
    
    ans=a+b;
    if(ans>=k)
    {
        cout<<min(k,a)<<endl;
    }
    
    else
    {
        cout<<a-(k-ans)<<endl;
    }
    
    
}

Measured memory_bytes: 3652
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
using p = pair<int, int>;
using P = pair<ll, ll>;
using V = vector<int>;
using VV = vector<vector<int>>;
using VVV = vector<vector<vector<int>>>;
using VL = vector<ll>;
using VVL = vector<vector<ll>>;
using VVVL = vector<vector<vector<ll>>>;
using Graph = VV;
#define rep(i,n) for(int i=0;i<(n);i++)
#define all(a) (a).begin(),(a).end()
#define output(x,y) cout << fixed << setprecision(y) << x << endl;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; }
ll lcm(ll a, ll b) { return a / gcd(a, b) * b; }
int Inf = (1 << 30);
ll inf = (1LL << 60);
const int MOD = 1e9 + 7;
int main() {
	int l;
	cin >> l;
	double L = (double)l / 3.0;
	output(pow(L, 3), 8);
	return 0;
}

Measured memory_bytes: 512
N, M, K = map(int, input().split())
mod = 998244353

fact = [1] * (N+1)
fact_inv = [1] * (N+1)
for i in range(1, N+1):
    fact[i] = i * fact[i-1] % mod
fact_inv[N] = pow(fact[N], mod-2, mod)
for i in range(1, N+1)[::-1]:
    fact_inv[i-1] = i * fact_inv[i] % mod
comb = lambda n, k: fact[n] * fact_inv[k] * fact_inv[n-k] % mod

ans = 0
for i in range(K+1):
    ans = (ans + comb(N-1, i) * M * pow(M-1, N-1-i, mod)) % mod
print(ans)

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

const int N=200005;
const long long MOD=1e9+7;
int n,m,k;
long long f[N],inv[N],dp[N];
struct node{int x,y;}a[N];
bool cmp(node a,node b){return a.x==b.x?a.y<b.y:a.x<b.x;}
long long zhs(long long a,long long b){return f[a]*inv[b]%MOD*inv[a-b]%MOD;}

long long ksm(long long a,long long b)
{
	long long res=1;
	while(b)
	{
		if(b%2) res=res*a%MOD;
		a=a*a%MOD,b/=2;
	}
	return res;
}

int main()
{
	scanf("%d%d%d",&n,&m,&k);
	int t=max(n,m)*2;
	f[0]=1;
	for(int i=1;i<=t;i++) f[i]=f[i-1]*i%MOD;
	inv[t]=ksm(f[t],MOD-2);
	for(int i=t;i>=1;i--) inv[i-1]=inv[i]*i%MOD;
	for(int i=1;i<=k;i++) scanf("%d%d",&a[i].x,&a[i].y);
	a[++k].x=n,a[k].y=m;
	sort(a+1,a+k+1,cmp);
	for(int i=1;i<=k;i++) dp[i]=zhs(a[i].x+a[i].y-2,a[i].x-1);
//	for(int i=1;i<=k;i++) cout<<i<<' '<<dp[i]<<endl;
	for(int i=1;i<=k;i++)
	{
		for(int j=i+1;j<=k;j++)
		{
			if(a[j].y>=a[i].y)
			{
//				cout<<i<<' '<<j<<' '<<zhs(a[j].x-a[i].x+a[j].y-a[i].y,a[j].x-a[i].x)*dp[i]%MOD<<endl;
				dp[j]=(dp[j]-zhs(a[j].x-a[i].x+a[j].y-a[i].y,a[j].x-a[i].x)*dp[i]%MOD+MOD)%MOD;
			}
		}
//		cout<<i<<' '<<dp[i]<<endl;
	}
	printf("%lld\n",dp[k]);
}

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

int main()
{	
	string s;

	while (cin >> s) {
		int nb, p, q;
		double w, h;

		p = s.find(",");
		q = s.find(",", p + 1);

		nb = stoi(s.substr(0, p));
		w = stod(s.substr(p + 1, q - p));
		h = stod(s.substr(q + 1, s.size() - q));

		if (w / (h * h) >= 25)
			cout << nb << endl;
	}

	return 0;
}



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

int main(){
  int a,b,c,cnt=0;
  cin>>a>>b>>c;
  if(a==b&&b==c){cout<<"1";return 0;} 
  if(a!=b) cnt++;
  if(a!=c) cnt++;
  if(b!=c) cnt++;
  cout<<cnt<<endl;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#include<stdio.h>
using namespace std;
typedef long long int ld;
typedef unsigned long long int lu;
typedef vector< int > vi;
typedef vector < ld > vd;
typedef set <ld> sd;
typedef vector< vi > vvi;
typedef vector< vd > vvd;
typedef pair< int,int > ii;
typedef pair< ld,ld > id;
#define sz(a) ld((a).size())
#define pb push_back
#define all(c) (c).begin(),(c).end()
#define tr(c,i) for(typeof((c).begin() i = (c).begin(); i != (c).end(); i++)
#define present(c,x) ((c).find(x) != (c).end())
#define cpresent(c,x) (find(all(c),x) != (c).end())

#define rep(i,a,b) for(i=a;i<b;i++)
#define REP(i,a,b) for(i=a;i<=b;i++)
#define reprev(i,a,b) for(i=a;i>=b;i--)


#define Vi vector
#define pr pair
#define isnum(a) (a>=48 && a<=57)
#define isS(a) (a>='a' && a<='z')
#define isU(a) (a>='A' && a<='Z')
#define toS(a) (isU(a)?a+32:a)
#define toU(a) (isS(a)?a-32:a)
#define toC(a) a&15

vector<char> prime (10000000+1, true);
void sieve(ld n)
{	
	//O(nloglogn) time
	prime[0] = prime[1] = false;
	for (ld i=2; i<=n; ++i)
		if (prime[i])
			if (i * 1ll * i <= n)
				for (ld j=i*i; j<=n; j+=i)
					prime[j] = false;
}


vd v1;

vd g[100004];
//vd g1[100004];
//vd ar;
//vvd final;
//ld mind = 1000000006;
//vd mind;
//ld c;
bool visit[100004];
ld dist[100004];
//for topological sort of a graph
void dfs(ld i,ld n)
{
	visit[i] = true;
	ld j,k;
	for(j=0;j<g[i].size();j++)
	{
		if(!visit[g[i][j]])
		{
			dfs(g[i][j],n);
		}
	}
	v1.pb(i);
}

void dfs1(ld i,ld n)
{
	visit[i] = true;
	ld j,k;
	for(auto x : g[i])
	{
		if(!visit[x])dfs1(x,n);
		dist[i]=max(dist[i],dist[x]+1);
	}
}
ld p = 1e9+7;

int main(){
	ld n,i,j;
	fixed;
	setprecision(15);
	cin >> n;
	long double p[n+1];
	p[0]=0.0;
	REP(i,1,n)
	{
		cin >> p[i];
	}
	long double dp[n+1][n+1];
	dp[1][1]=p[1];
	dp[1][0]=1-p[1];
	REP(i,2,n)
	{
		REP(j,0,n)
		{
			dp[i][j]=0.0;
			if(i>j)dp[i][j]+=(dp[i-1][j]*(1-p[i]));
			if(j>0)dp[i][j]+=(dp[i-1][j-1]*p[i]);
		}
	}
	long double prob=0.0;
	REP(i,n/2+1,n)prob+=dp[n][i];
	cout << setprecision(15) << prob << endl;
	return 0;
}

/*
//next step
//from transposed graph g1,get strongly connected components
void dfs1(ld i,ld n,ld len)
{
	visit[i] = true;
	ld j,k;
	final[len].pb(i);
	mind[len] = min(mind[len],ar[i]);
	rep(j,0,g1[i].size())
	{
		if(!visit[g1[i][j]])
		{
			dfs1(g1[i][j],n,len);
		}
	}
}
*/

Measured memory_bytes: 152960
N,M=map(int,input().split())
L=list(map(lambda x: (1,int(x)), input().split()))
for _ in range(M):
  L.append(tuple(map(int,input().split())))
L=sorted(L,key=lambda x: x[1],reverse=True)
ans,k=0,0
for n,a in L:
  if n+k>=N:
    ans+=a*(N-k)
    break
  else:
    ans+=a*n
    k+=n
print(ans)

Measured memory_bytes: 39032
#include <iostream>
#include <iomanip>
#include<math.h>
#include<list>
#include <algorithm>
#include<set>
#include<vector>
#include<math.h>
#include<map>
#include<string>
#include <numeric>
#include <queue>
#include <sstream>
#include <bitset>
#include<stack>

using namespace std;
using ll = long long;
using vll = vector<long long>;
using sll = set<long long>;


template<typename T>
T gcd(T a, T b) { return b ? gcd(b, a % b) : a; }
template<typename T>
T lcm(T a, T b) { return a / gcd(a, b) * b; }

template<typename T>
map<T, T> getPrimeFactor(T n) {
	map<T, T> res;
	for (T i = 2; i * i <= n; ++i) {
		while (n % i == 0) {
			res[i] ++;
			n /= i;
		}
	}
	if (n != 1) res[n] = 1;
	return res;
}

template<typename T>
bool IsPrimeNumber(T num)
{
	if (num <= 2) return true;
	else if (num % 2 == 0) return false;

	double sqrtNum = sqrt(num);
	for (int i = 3; i <= sqrtNum; i += 2)
	{
		if (num % i == 0)
		{
			return false;
		}
	}

	return true;
}

long long modinv(long long a, long long m) {
	long long b = m, u = 1, v = 0;
	while (b) {
		long long t = a / b;
		a -= t * b; swap(a, b);
		u -= t * v; swap(u, v);
	}
	u %= m;
	if (u < 0) u += m;
	return u;
}

// 繰り返し二乗法
ll pow2(ll n, ll p) {
	if (p == 0 || n == 1) {
		return 1;
	}
	else {
		ll ret = pow2(n * n, p / 2);
		if (p % 2 == 1) {
			ret *= n;
		}
		return ret;
	}
}

#define rep(i,s,e) for(ll i=s;i<e;i++)
#define repeq(i,s,e) for(ll i=s;i<=e;i++)


int main() {
	ll N;
	std::cin >> N;

	vll A(N);
	rep(i, 0, N) {
		std::cin >> A[i];
	}
	sort(A.begin(), A.end());

	queue<pair<ll, ll>> q;
	// できるだけ大きなマイナスを作っていく
	ll idx_min = 0;
	ll idx_max;
	for (idx_max = N - 1; idx_max > idx_min + 1 && A[idx_max - 1] >= 0; idx_max--) {
		q.push({ A[idx_min],A[idx_max] });
		A[idx_min] -= A[idx_max];
	}

	// 残った非負値にマイナスの数字を引いていく
	while (idx_min < idx_max) {
		q.push({ A[idx_max],A[idx_min] });
		A[idx_max] -= A[idx_min];
		idx_min++;
	}

	// 出力
	std::cout << A[idx_max] << endl;
	while (!q.empty()) {
		std::cout << q.front().first << " " << q.front().second << endl;
		q.pop();
	}

	return 0;
}


Measured memory_bytes: 5584