akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
using pii=pair<int,int>;
using ll=long long;

#define fi first
#define se second
#define pb push_back
#define rep(i,n) for(int i=0; i<(int)(n); i++)
#define MOD 1000000007

template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }

bool visited[100010][2];
ll dp[100010][2];
int deg[100010];
//white-false&0, black-true&1

ll rec(vector<vector<int> >& e, int cur, int color, int degree) {
	//cout << "cur:" << cur << " color:" << color << endl;
	deg[cur] = degree;
	if(visited[cur][color] == true) {
		//cout << "already visited:" << dp[cur][color] << endl;
		return dp[cur][color];
	}
	visited[cur][color] = true;

	if(color == 0) {
		ll temp = 1;
		for(auto k : e[cur]) {
			if(deg[k] < deg[cur]) {
				continue;
			}
			//cout << "k:" << k << endl;
			temp *= rec(e, k, 0, degree+1) + rec(e,k,1,degree+1);
			temp %= MOD;
			//cout << "dp[" << k << "][0]:" << dp[k][0] << " temp:" << temp << endl;
			//cout << "dp[" << k << "][1]:" << dp[k][1] << " temp:" << temp << endl;
		}
		if(temp == 1) {
			//cout << "mattan, ";
			return dp[cur][color] = 1;
		}
		//cout << "dp[" << cur << "][" << color << "] is " << temp << endl;
		return dp[cur][color] = temp;
	}
	else {
		ll temp = 1;
		for(auto k : e[cur]) {
			if(deg[k] < deg[cur]) {
				continue;
			}
			temp *= rec(e,k,0,degree+1);
			temp %= MOD;
			//cout << "dp[" << k << "][0]:" << dp[k][0] << " temp:" << temp << endl;
		}
		if(temp == 0) {
			//cout << "mattan, ";
			return dp[cur][color] = 1;
		}
		//cout << "dp[" << cur << "][" << color << "] is " << temp << endl;
		return dp[cur][color] = temp;
	}
}

int main() {
	int n;
	cin >> n;
	vector<vector<int> > e(n, vector<int>());
	
	rep(i,n-1) {
		int xt,yt;
		cin >> xt >> yt;
		xt--;
		yt--;
		e[xt].pb(yt);
		e[yt].pb(xt);
	}
	rep(i,n) {
		visited[i][0] = false;
		visited[i][1] = false;
	}
	memset(dp, 0, sizeof(dp));
	dp[0][0] = 1;
	dp[0][1] = 1;
	ll ans = 0;

	rep(i,n) deg[i] = 1e9;
	ans += rec(e, 0, 0, 0);
	ans %= MOD;
	ans += rec(e, 0, 1, 0);
	ans %= MOD;
	cout << ans << endl;

  return 0;
}

Measured memory_bytes: 14848
#include<bits/stdc++.h>
using namespace std;
const int N=1e5+5;
int n,now,vi[N],fa[N],vis[N],v[N<<1],deep[N],nex[N<<1],head[N];
void addedges(int x,int y){
	nex[++now]=head[x];
	head[x]=now,v[now]=y;
}
vector<int>b[N];
void dfs(int x){
	deep[x]=deep[fa[x]]+1;
	for(int i=head[x];i;i=nex[i])
		if(v[i]!=fa[x])	fa[v[i]]=x,dfs(v[i]);
	b[deep[x]].push_back(x);
}
int main(){
	scanf("%d",&n);
	for(int i=1;i<n;i++){
		int x,y;
		scanf("%d%d",&x,&y);
		addedges(x,y),addedges(y,x);
	}
	dfs(1);
	for(int i=n;i;i--){
		int si=b[i].size();
		for(int j=0;j<si;j++){
			int k=b[i][j];
			if(!vis[k]){
				if(vis[fa[k]]||k==1){
					puts("First");
					return 0;
				}
				vis[fa[k]]=1;
			}
		}
	}
	puts("Second");
	return 0;
}

Measured memory_bytes: 6400
#include <bits/stdc++.h>
#define rep(i,s,n) for (int i=s;i<n;++i)
#define drep(i,s,n) for (int i=n;i>=s;--i)
#define all(x) (x).begin(),(x).end()
#define rall(a) (a).rbegin(),(a).rend()
#define print(x) cout<<(x)<<endl
using namespace std;
typedef long long ll;
int gcd(int a,int b)
{if (a%b == 0) return(b);
 else          return(gcd(b,a%b));}
int lcm(int a,int b)
{return a*b/gcd(a,b);}
void printv(vector<auto> v) {cout<<'[';rep(i,0,v.size()){cout<<v[i]<<',';}cout<<']'<<endl;}
void printvv(vector<vector<auto>> vv)
{
  cout<<'['<<endl;
  rep(q,0,vv.size()){cout<<'[';rep(p,0,vv.at(q).size())cout<<vv.at(q).at(p)<<',';cout <<']'<<endl;}
  cout<<']'<<endl;
}
void solve(); int main(){cin.tie(0);ios::sync_with_stdio(0);solve();}
int step_x[] = {-1,0,0,1};
int step_y[] = {0,-1,1,0};
const long long INF = 1000000;
//------------------------------------------------------------
ll n;
void solve()
{
    cin >> n;
    vector<pair<ll,ll>> v(n);
    rep(i,0,n) {cin >> v[i].first; v[i].second=i;}

    vector<vector<ll>> dp(n+2, vector<ll>(n+2, -1));
    dp[0][0]=0;

    sort(rall(v));

    rep(i, 0, n)
    {
      rep(l,0,i+1)
      {
        if(dp[i][l]>=0)
        {
          dp[i+1][l+1] = max(dp[i+1][l+1], dp[i][l]+v[i].first*abs(v[i].second-l));
          dp[i+1][l]   = max(dp[i+1][l], dp[i][l]+v[i].first*abs((n-1)-(i-l)-v[i].second));
        }
      }
    }

    ll ans = -1;
    rep(i,0,n) ans = max(ans, dp[n][i]);

    print(ans);

    return;
}



Measured memory_bytes: 34612
#include <bits/stdc++.h>
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define repi(i,a,b) for(int i=int(a);i<int(b);++i)
#define REP(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)

using namespace std;
using ll = long long;

int main()
{
    ll sum = 0;
    string s;
    cin >> s;
    rep(i,s.length()){
        int a = 0;
        a = s[i]-'0';
        sum+=a;
        if(sum > 9) sum -= 9;
    }


    if(sum%9 == 0)
        cout << "Yes" << endl;
    else
        cout << "No" << endl;
    return 0;
}


Measured memory_bytes: 3724
#include<iostream>
#include<string>
#include<algorithm>
#include<cstdio>
#include<cstring>
#include<cstdlib>
#include<cmath>
#include<queue>
using namespace std;
typedef long long s64;

#define next nxt
const int ONE = 1000005;
const int INF = 2147483640;

int get()
{
        int res = 1, Q = 1; char c;
        while( (c = getchar()) < 48 || c > 57)
            if(c == '-') Q = -1;
        if(Q) res = c - 48;
        while( (c = getchar()) >= 48 && c <= 57)
            res = res * 10 + c - 48;
        return res * Q;
}

int n, k;
int A[ONE], p[ONE];
int next[ONE], first[ONE], go[ONE], Input[ONE], tot;
priority_queue <int, vector <int>, greater <int> > q;

int res = INF;
namespace Seg
{
        struct power {int val;} Node[ONE * 4];
        void Build(int i, int l, int r)
        {
            Node[i].val = INF;
            if(l == r) return;
            int mid = l + r >> 1;
            Build(i << 1, l, mid), Build(i << 1 | 1, mid + 1, r);
        }

        void Update(int i, int l, int r, int L, int x)
        {
            if(L <= l && r <= L)
            {
                Node[i].val = x;
                return;
            }
            int mid = l + r >> 1;
            if(L <= mid) Update(i << 1, l, mid, L, x);
            else Update(i << 1 | 1, mid + 1, r, L, x);
            Node[i].val = min(Node[i << 1].val, Node[i << 1 | 1].val);
        }

        void Query(int i, int l, int r, int L, int R)
        {
            if(L > R) return;
            if(L <= l && r <= R)
            {
                res = min(res, Node[i].val);
                return;
            }
            int mid = l + r >> 1;
            if(L <= mid) Query(i << 1, l, mid, L, R);
            if(mid + 1 <= R) Query(i << 1 | 1, mid + 1, r, L, R);
        }
}

void Add(int u, int v)
{
        Input[v]++, next[++tot] = first[u], first[u] = tot, go[tot] = v;
}

void Deal()
{
        int now = 0;
        for(int i = 1; i <= n; i++)
            if(!Input[i]) q.push(i);
        while(!q.empty())
        {
            int u = q.top(); q.pop();
            A[u] = ++now;
            for(int e = first[u]; e; e = next[e])
            {
                int v = go[e];
                if(--Input[v] == 0) q.push(v);
            }
        }
        for(int i = 1; i <= n; i++) printf("%d\n", A[i]);
}

int main()
{
        n = get(), k = get();
        for(int i = 1; i <= n; i++) p[get()] = i;

        Seg::Build(1, 1, n);
        for(int i = n; i >= 1; i--)
        {
            res = INF, Seg::Query(1, 1, n, p[i] + 1, min(p[i] + k - 1, n));
            if(res != INF) Add(p[i], p[res]);

            res = INF, Seg::Query(1, 1, n, max(1, p[i] - k + 1), p[i] - 1);
            if(res != INF) Add(p[i], p[res]);

            Seg::Update(1, 1, n, p[i], i);
        }

        Deal();
}

Measured memory_bytes: 35060
#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");
    if(a+b==c+d) printf("Balanced\n");
    if(a+b<c+d) printf("Right\n");
}

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

int main(){
  int n;
	cin >> n;
	int v[n];
	r(i,n) cin >>v[i];
  int q;
  cin >> q;
  while(q--){
    int b,e,t;
    cin >> b >> e >> t;
    swap_ranges(v+b,v+e,v+t);
  }
  r(i,n){
    if(i)cout <<" ";
    cout << v[i];
  }
  cout << endl;
}


Measured memory_bytes: 3092
#include <stdio.h>

int main()
{
    int H,W;
    for(;;) {
        scanf("%d %d", &H, &W);

        if((H == 0)&&(W == 0))
            break;

        int i,j;
        for(i=0; i<H; i++) {
            for(j=0; j<W; j++) {
                printf("#");
            }
            printf("\n");
        }
        printf("\n");
    }
    return(0);
}



Measured memory_bytes: 2056
import heapq

INF = float('inf')

class Edge():
    def __init__(self, a, b, cost):
        self.a = a
        self.b = b
        self.cost = cost
    def __str__(self):
        return 'Edge: {} -> {}, cost {}'.format(self.a, self.b, self.cost)

def dijkstra(n, G, s):
    dist = [INF] * n
    dist[s] = 0
    h = []
    heapq.heappush(h, (0, s))

    while h:
        # 使っていない頂点のうち、現時点で最も距離の近いものを選びvとする
        d, v = heapq.heappop(h)
        if dist[v] < d:
            continue
        # vから到達可能な頂点について、距離が短くなれば更新
        for e in G[v]:
            if dist[e.b] > dist[v] + e.cost:
                dist[e.b] = dist[v] + e.cost
                heapq.heappush(h, (dist[e.b], e.b))
    return dist

n, x, y = map(int, input().split())

g = [[] for i in range(n)]

for i in range(n-1):
    g[i].append(Edge(i, i+1, 1))
    g[i+1].append(Edge(i+1, i, 1))

g[x-1].append(Edge(x-1, y-1, 1))
g[y-1].append(Edge(y-1, x-1, 1))

ans = [0] * n

for i in range(n):
    for d in dijkstra(n, g, i):
        ans[d] += 1

for item in ans[1:]:
    print(item // 2)



Measured memory_bytes: 120924
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
#include <cmath>
#include <iomanip>
#include <queue>
#include <stack>
#include <deque>
#include <utility>
#include <functional>
#define rep(i,n) for(int i=0;i<n;++i)
#define FOR(i,j,k) for(int i=j;i>=k;--i)

using ll = long long;
using namespace std;

const ll INF = 1010101010;
const ll MOD = 1000000007;

int main() {
	static ll n, m, A[1010101], B[1010101];
	rep(i, 3) cin >> A[i];
	sort(A, A + 3);
	cout << (A[2] - A[1]) + (A[1] - A[0]) << endl;
	return 0;
}

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

long int gcd(long int a,long int b){
    if(b==0)
        return a;

    return gcd(b,a%b);
}

int main(){
    long int a,b,c,d,temp;
    long int count=0;
    long int i;

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

    count = b/c - a/c + 1;
    if(a%c != 0)
        count--;

    count += b/d - a/d + 1;
    if(a%d != 0)
        count--;

    if(c<d){
        temp = c;
        c = d;
        d = temp;
    }

    i = c*d/gcd(c,d);

    count -= (b/i - a/i + 1);
    if(a%i != 0)
        count++;


    count = b-a+1-count;

    printf("%ld\n",count);


    return 0;
}

Measured memory_bytes: 128
#include <iostream>
#include <vector>
#include <functional>

const int N = 100000 + 7;

int n, m;
std::vector<int> e[N];
int cnt;
int vis[N];

int main() {
//	freopen("code.in", "r", stdin);
//	freopen("code.out", "w", stdout);

	scanf("%d%d", &n, &m);
	for (int i = 1, u, v; i <= m; ++i)
		scanf("%d%d", &u, &v),
		e[u].push_back(v), e[v].push_back(u);
	for (int i = 1; i <= n; ++i)
		if (e[i].size() & 1) return printf("No"), 0;
	for (int i = 1; i <= n; ++i)
		if (e[i].size() >= 6 || (cnt += e[i].size() == 4) > 2) return printf("Yes"), 0;
	if (cnt < 2) return printf("No"), 0;
	int x = 0, y = 0;
	for (int i = 1; i <= n; ++i)
		if (e[i].size() == 4) (!x ? x : y) = i;
	std::function<int(int, int)> dfs = [&](int x, int y) -> int {
		if (x == y) return 1;
		vis[x] = 1;
		int z = 0;
		for (auto t : e[x]) if (!vis[t]) z += dfs(t, y);
		return z;
	};
	return printf(dfs(x, y) == 4 ? "No" : "Yes"), 0;
}


Measured memory_bytes: 7680
#include <bits/stdc++.h>
using namespace std;
#define eb emplace_back
#define mod (1000000007)
 
// vector<long long int> temp(40002);//long int vis[1000002] = {0};
  // vector<long int> g[1000002];
int main() {
 
  long long int t = 1;
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
 
 //cin >> t;
  while(t--){
 
    int n,m,x = 0,y = 0,start = 0,end = 0,index = 0,z;

      cin >> n;
       int arr[n][3];

      for(int i = 0;i<n;i++)
       for(int j = 0;j<3;j++)
        cin >> arr[i][j];     
    
      for(int i = 1;i<n;i++)
      {
        
         arr[i][0] += max(arr[i-1][1],arr[i-1][2]);
         arr[i][1] += max(arr[i-1][0],arr[i-1][2]);
         arr[i][2] += max(arr[i-1][0],arr[i-1][1]);
      }


      for(int i = 0;i<3;i++)
       {
         start = max(start,arr[n-1][i]);
       }

       cout << start;
      
  } 
}


Measured memory_bytes: 4796
#include <bits/stdc++.h>
typedef long long ll;
using namespace std;
#define all(x) (x).begin(), (x).end()
#define MOD 1000000007
int main() {
    ll n, k, r, s, p;
    cin >> n >> k >> r >> s >> p;
    string t;
    cin >> t;
    vector<string> div(k, "");
    for(int i = 0; i < n; i++) {
        div[i % k] += t.substr(i, 1);
    }
    ll ans = 0;
    for(auto str : div) {
        for(int i = 0; i < str.size(); i++) {
            int q = 0;
            while(i + q < str.size() && str[i + q] == str[i]) {
                q++;
            }
            if(str[i] == 'r') {
                ans += ((q + 1) / 2) * p;
            }
            if(str[i] == 's') {
                ans += ((q + 1) / 2) * r;
            }
            if(str[i] == 'p') {
                ans += ((q + 1) / 2) * s;
            }
            i += q - 1;
        }
    }
    cout << ans << endl;
}


Measured memory_bytes: 5120
N, M = map(int, input().split())
ks = [list(map(int, input().split())) for i in range(M)]
p = list(map(int, input().split()))

def check(ar):
    cnt = 0
    for j in range(M):
        count = 0
        for k in ks[j][1::]:
            if ar[k-1] == 1:
                count += 1
        if count%2 == p[j]:
            cnt += 1
    return (cnt == M)


def dfs(n, ar):
    if n == 0:
        if check(ar):
            return 1
        else:
            return 0
    else:
        return dfs(n-1, ar+[0]) + dfs(n-1, ar+[1])
arr = []
ans = dfs(N, arr)
print(ans)


Measured memory_bytes: 3188
// Mere bas ka nahi hai
// still i'm trying
// apna time aayega
//
//        .--------------.  
//        | Try First One|
//        '--------------'
//                |     .--------------.
//                |     |              |
//                V     V              |
//              .--------------.       |
//              |      AC.     |<---.  |  
//              '--------------'    |  |
//              (True)|  |(False)   |  |
//           .--------'  |          |  |
//           |           V          |  |
//           |  .--------------.    |  |
//           |  |   Try Again  |----'  |
//           |  '--------------'       |
//           |                         |
//           |  .--------------.       |
//           '->| Try Next One |-------'
//              '--------------'                          		  
//


#include<bits/stdc++.h>
using namespace std;
//#include <boost/multiprecision/cpp_int.hpp>
//using namespace boost::multiprecision;
//#include <ext/pb_ds/assoc_container.hpp>
//#include <ext/pb_ds/tree_policy.hpp>
//using namespace __gnu_pbds;
#define int long long int
#define ld long double
#define ull unsigned long long
#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define r0 return 0;
#define tc int t;cin>>t;while(t--)
#define for0(i, n) for (int i = 0; i < n; i++)
#define for1(i, n) for (int i = 1; i <= n; i++)
#define loop(i,a,b) for (int i = a; i < b; i++)
#define vi vector<int>
#define vii vector<long long int>
#define SORT(v) sort(v.begin(),v.end());
#define PI 3.1415926535897932384626433832795
#define mod 1000000007
#define md 998244353
#define inf 1000000000000000 //1e15
#define gcd __gcd
#define lcm(a,b) ((a)*(b))/gcd(a,b)
#define all(a) (a).begin(),(a).end()
#define rall(a) (a).rbegin(),(a).rend()
#define crap ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define endl "\n"
int min(int a,int b){
    return (a<b)?a:b;
}
int max(int a,int b){
    return (a>b)?a:b;
}
int fp(int a,int b){
    if(b==0) return 1;
    int x=fp(a,b/2);
    x=(x*x)%mod;
    if(b&1) x=(x*a)%mod;
    return x;
}
int factorial(int n)
{
    int fact=1;
    for(int i=2;i<=n;i++)
    fact=fact*i;
    
    return fact;
}
int ncr(int n,int r)
{
    return factorial(n)/(factorial(r)*factorial(n-r));
}
int binomialCoeff(int n,int k)
{
    int dp[k+1];
    memset(dp,0,sizeof(dp));
    dp[0]=1;
    for(int i=1;i<=n;i++)
    {
        for(int j=min(i,k);j>0;j--)
        dp[j]=(dp[j]+dp[j-1])%mod;
    }
    return dp[k]%mod;
    
}
void c_p_c()
{
    crap;
#ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
#endif
}
signed main()
{
    c_p_c();
    int n;
    cin>>n;
    if(n==0)
    cout<<1<<endl;
    else
    {
        
        cout<<0<<endl;
    }
       
}

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

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

Measured memory_bytes: 256
#include <stdio.h>

int main(void) {
	
	int N;
	int A[200000];
	int max1 = 0;
	int max2 = 0;
	int a = 0;
	scanf("%d", &N);
	for (int i = 0; i < N; i++) {
		scanf("%d", &A[i]);
		if (A[i] > max1) {
			max1 = A[i];
			a = i;
		}
	}
	A[a] = 0;
	for (int i = 0; i < N; i++) {
		if (A[i] > max2) {
			max2 = A[i];
		}
	}

	for (int i = 0; i < N; i++) {
		if (a == i) {
			printf("%d\n", max2);
		}
		else {
			printf("%d\n", max1);
		}


	}
	return 0;

}

Measured memory_bytes: 2304
#include<cstdio>
#include<cstring>
#include<cmath>
#include<algorithm>
using namespace std;
typedef long double ld;
const int N=200005;
int n,v1[N],v2[N],val[100][100];
long double a[N];
long long ans,num[N];
int calc2(long long x){
	int res=0;
	while(x%2==0){
		res++;
		x/=2;
	}
	return res;
}
int calc5(long long x){
	int res=0;
	while(x%5==0){
		res++;
		x/=5;
	}
	return res;
}
int main(){
	scanf("%d",&n);
	for(int i=1;i<=n;i++){
		scanf("%Lf",&a[i]);
		num[i]=a[i]*1e9+0.5;
		v1[i]=calc2(num[i])-9;
		v2[i]=calc5(num[i])-9;
	}
	for(int i=n;i>=1;i--){
		for(int j=-v1[i];j<=32;j++){
			for(int k=-v2[i];k<=15;k++){
				ans+=val[j+32][k+15];
			}
		}
		val[v1[i]+32][v2[i]+15]++;
	}
	printf("%lld\n",ans);
	return 0;
}

Measured memory_bytes: 7984
#include <bits/stdc++.h>
using ll = long long;
using namespace std;
const long long MOD  = 1e9 +7;

int main()
{
	#ifndef ONLINE_JUDGE
	freopen("in.txt","r",stdin);
	freopen("out.txt","w",stdout);
	#endif
	ll n,k;
	cin >>n>>k;
	vector<ll> v(n);
	for(int i = 0;i < n; i++) cin >> v[i];
	vector<ll> dp(k+1), end(k+1);
	ll ans = 0;
	dp[0]  = 1;
	for(int i = 0;i < n; i++) {
		 ans  = 0;
		 for(int j = 0;j <= k;j++) {
			 ans = (ans+dp[j])%MOD;
		 	 if(j + v[i]<k) end[j+v[i]] = dp[j];
		 	 dp[j] = ans;
		 	 ans = (((ans - end[j])%MOD)+MOD) %MOD;
		 	 end[j] = 0;
		 }
	}
	cout <<dp[k]<<'\n';
	return 0;
}


Measured memory_bytes: 4828
fun main(args: Array<String>) {
    val s = readLine()!!.toInt()
    
    fun fn(n: Int): Int = if (n % 2 == 0) n / 2 else 3 * n + 1

    val list = mutableListOf(s)
    for (m in 2..1000000) {
        val am = fn(list.last())
        if (list.contains(am)) {
            println(m)
            return
        }
        list.add(am)
    }
}

Measured memory_bytes: 31872
#include<bits/stdc++.h>
#define M 1000000007
using namespace std;
typedef long long ll;
const int MAX_N = 1<<18;
 
class BIT{
   
public:
   
  int n;
  ll bit0[MAX_N+1],bit1[MAX_N+1];
 
  BIT(){
    n=MAX_N;
    memset(bit0,0,sizeof(bit0));
    memset(bit1,0,sizeof(bit1));
  }
 
  BIT(int n){
    this->n=n;
    memset(bit0,0,sizeof(bit0));
    memset(bit1,0,sizeof(bit1));
  }
 
  ll sum(ll *b,int i){
    ll s=0;
    while(i>0){
      s=(s+b[i]);
      i-=i&-i;
    }
    return s;
  }
 
  void add(ll *b,int i,ll v){
    while(i<=n){
      b[i]=(b[i]+v);
      i+=i&-i;
    }
  }
   
  // [a,b] += x
  void add(int a,int b,ll x){
    add(bit0,a,-x*(a-1));
    add(bit1,a,x);
    add(bit0,b+1,x*b);
    add(bit1,b+1,-x);
  }
   
  // return sum([a,b])
  ll sum(int a,int b){
    ll res=0;
    res+=sum(bit0,b)+sum(bit1,b)*b;
    res-=sum(bit0,a-1)+sum(bit1,a-1)*(a-1);
    return res;
  }
 
  void init(){
    memset(bit0,0,sizeof(bit0));
    memset(bit1,0,sizeof(bit1));
  }
};
 
BIT seg;
 
int main(){
   
  int n;
  ll kai[100001];
  kai[0]=1;
  for(int i=1;i<=1e5;i++)
    kai[i]=kai[i-1]*i%M;
  while(cin>>n,n){
    seg.init();
    ll c[100001];
    for(int i=1;i<=n;i++)c[i]=i;
    int R;
    ll ans=0;
    cin>>R;
    for(int s,t,i=0;i<R;i++)
      cin>>s>>t,swap(c[s],c[t]);
    for(int i=1;i<n;i++){
      ans=(ans+(c[i]-seg.sum(1,c[i])-1)*kai[n-i])%M;
      seg.add(c[i],c[i],1);
    }
    cout<<ans<<endl;
  } 
  return 0;
}

Measured memory_bytes: 8708
#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>;

int main () {
  int i, j, k, min=INT_MAX, A, B, C, X, count=0;
  
  cin >> A >> B >> C >> X;
  
  for(i=0; i<A+1; i++){
    for(j=0; j<B+1; j++){
      for(k=0; k<C+1; k++){
        if(i*500+j*100+k*50==X) count+=1;
      }
    }
  }
  
  cout << count;
}




Measured memory_bytes: 3600
import heapq

q = int(input())
l = []
r = []
lsum = 0
rsum = 0
cnt = 0
b = 0
#heapq正負注意
for i in range(q):
    *que,= map(int, input().split( ))
    if que[0]==1:
        b += que[2]
        a = que[1]
        ax = None
        if cnt%2==0:
            rsum += a
            heapq.heappush(r,a)
            ax = heapq.heappop(r)
            rsum -= ax
            heapq.heappush(l,-ax)
            lsum += ax
        else:
            lsum += a
            heapq.heappush(l,-a)
            ax = -heapq.heappop(l)
            lsum -= ax
            heapq.heappush(r,ax)
            rsum += ax
        cnt += 1

    else:
        x = -heapq.heappop(l)
        print(x, b + rsum - lsum + (len(l)+1-len(r))*x)
        heapq.heappush(l,-x)
        

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

using namespace std;
using LL = long long;
using P = pair<int, int>;
using Tapris = tuple<int, int, int>;

#define REP(i, n) for(LL i = 0; i < n; ++i)
#define FOR(i, a, n) for(LL i = a; i < n; ++i)
#define pb(a) push_back(a)
#define all(x) (x).begin(),(x).end()

const int INF = (int)1e9;
const LL INFL = (LL)1e15;
const int MOD = 1e9 + 7;

int dy[]={0, 0, 1, -1, 0};
int dx[]={1, -1, 0, 0, 0};

//#define int long long

/*************** using variables ***************/
int n;
P m;
vector<int> a, b, c;
int dp[45][405][405];
/**********************************************/

signed main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    
    cin >> n;
    cin >> m.first >> m.second;

    a.resize(n);
    b.resize(n);
    c.resize(n);

    REP(i, n) cin >> a[i] >> b[i] >> c[i];
    REP(i, n+1){
        REP(j, 401){
            REP(k, 401){
                dp[i][j][k] = INF;
            }
        }
    }
    dp[0][0][0] = 0;
    REP(i, n){
        REP(j, 401){
            REP(k, 401){
                if(dp[i][j][k] == INF) continue;
                
                dp[i+1][j][k] = min(dp[i+1][j][k], dp[i][j][k]);
                dp[i+1][j+a[i]][k+b[i]] = min(dp[i+1][j+a[i]][k+b[i]], dp[i][j][k] + c[i]);
                
            }
        }
    }
    int ans = INF;
    FOR(j, 1, 401){
        FOR(k, 1, 401){
            if(j*m.second == k*m.first) ans = min(ans, dp[n][j][k]);
        }
    }

    if(ans != INF) cout << ans << endl;
    else cout << -1 << endl;

}


Measured memory_bytes: 26880
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <utility>
#include <tuple>
#include <cstdint>
#include <cstdio>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <deque>
#include <unordered_map>
#include <unordered_set>
#include <bitset>
#include <cctype>
#include <functional>
#include <ctime>
#include <cmath>
#include <limits>
#include <numeric>
#include <type_traits>
#include <iomanip>
#include <float.h>
#include <math.h>
using namespace std;
using ll = long long;


unsigned euclidean_gcd(unsigned a, unsigned b) {
    if (a < b) return euclidean_gcd(b, a);
    unsigned r;
    while ((r = a % b)) {
        a = b;
        b = r;
    }
    return b;
}

class UnionFind {
public:
    vector <ll> par;
    vector <ll> siz;
    UnionFind(ll sz_) : par(sz_), siz(sz_, 1LL) {
        for (ll i = 0; i < sz_; ++i) par[i] = i;
    }
    void init(ll sz_) {
        par.resize(sz_);
        siz.assign(sz_, 1LL);
        for (ll i = 0; i < sz_; ++i) par[i] = i;
    }
    ll root(ll x) {
        while (par[x] != x) {
            x = par[x] = par[par[x]];
        }
        return x;
    }
    bool merge(ll x, ll y) {
        x = root(x);
        y = root(y);
        if (x == y) return false;
        if (siz[x] < siz[y]) swap(x, y);
        siz[x] += siz[y];
        par[y] = x;
        return true;
    }

    bool issame(ll x, ll y) {
        return root(x) == root(y);
    }

    ll size(ll x) {
        return siz[root(x)];
    }
};

long long modpow(long long a, long long n, long long mod) {
    long long res = 1;
    while (n > 0) {
        if (n & 1) res = res * a % mod;
        a = a * a % mod;
        n >>= 1;
    }
    return res;
}

long long modinv(long long a, long long mod) {
    return modpow(a, mod - 2, mod);
}


int main() {
    ll a;
    string b;
    cin >> a >> b;
    a *= ((b.at(0) - '0') * 100 + (b.at(2) - '0') * 10 + (b.at(3) - '0'));
    cout << a / 100 << endl;
}

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

int main() {

    int D, T, S;
    cin >> D >> T >> S;

    if (D <= T * S) cout << "Yes" << endl;
    else cout << "No" << endl;

    return 0;
}


Measured memory_bytes: 3632
arr = gets.chomp.split('')

unless arr.uniq.length == 2
  print 'No'
  exit
end

tmp_a = []
arr.uniq.each do |s|
  tmp_a.push(arr.select { |i| i == s }.count)
end

if tmp_a.select { |i| i == 2 }.length == 2
  print 'Yes'
else
  print 'No'
end


Measured memory_bytes: 1788
#include<bits/stdc++.h>
using namespace std;
#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define rep(i, a, b) for(int i=(a); i<(b); i++)
#define per(i, a, b) for(int i=(b)-1; i>=(a); i--)
#define sz(a) (int)a.size()
#define de(a) cout << #a << " = " << a << endl
#define dd(a) cout << #a << " = " << a << " "
#define all(a) a.begin(), a.end()
#define pw(x) (1ll<<(x))
#define endl "\n"
typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;
ll sum = 0;
int deep[200000+10];
bool vis[200000+10];
int res[200000+10];
int a[200000+10];
ll len = 0;
int dfs(int i){
	vis[i] = true;
	sum ++ ;
	deep[i] = sum ;
	res[sum] = i;
	if(!vis[a[i]]) return dfs(a[i]);
	else return sum - deep[a[i]] + 1;
}
int main(){
	ios::sync_with_stdio(false);
	cin.tie(0);cout.tie(0);
	int n;
	ll k;
	cin >> n >> k;
	k ++ ;
	rep(i, 1, n + 1) cin >> a[i];
	len = dfs(1);
	if(k <= sum){
		cout << res[k] << endl;
	}
	else{
		int last = sum - len;
		k -= last;
		k %= len;
	//	cout << sum <<" " << len <<" " << k <<endl;
		if( k == 0 ) cout << res[sum] << endl;
		else cout << res[last + k ] << endl;
	}
	return 0;
}
/*
6 8
6 5 2 5 3 2
*/

Measured memory_bytes: 6072
using System;
using System.Linq;
using System.Collections.Generic;

class Cmondai
{
    static void Main()
    {
        var N = Int32.Parse(Console.ReadLine());
        var a = Console.ReadLine().Split(' ').Select(x => Int32.Parse(x)).OrderBy(x=>x).ToArray();
        var array = new int[100002];
        for (int i=0;i<N;++i)
        {
            array[a[i]]++;
            array[a[i] + 1]++;
            array[a[i] + 2]++;
        }
        var ans = array.Max();
        Console.WriteLine(ans);
    }
}

Measured memory_bytes: 22624
#include<bits/stdc++.h>
typedef long long int ll;
typedef unsigned long long int ull;
#define BIG_NUM 2000000000
#define MOD 1000000007
#define EPS 0.000000001
using namespace std;


int main(){

	int N;
	scanf("%d",&N);

	vector<int> V;
	int tmp;

	for(int loop = 0; loop < N; loop++){
		scanf("%d",&tmp);
		V.push_back(tmp);
	}

	int num_query;
	scanf("%d",&num_query);

	int command,left,right;

	for(int loop = 0; loop < num_query; loop++){

		scanf("%d %d %d",&command,&left,&right);

		if(command == 0){
			printf("%d\n",*min_element(V.begin()+left,V.begin()+right));
		}else{
			printf("%d\n",*max_element(V.begin()+left,V.begin()+right));
		}
	}

	return 0;
}



Measured memory_bytes: 3224
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.lang.StringBuffer;

/*Question
/1????????¢????????????????????????????????? n ???????????????????±±????????£?????????????????????
/1???????????£???????????§??????????????? h ???????????????????????¨???????????????????????????????????£????????????????±±??????????????????????????????
/?????????????±±?????\???????????????1?????????????????§?????????????????????
/abcdeefab
/?????????????????????????????????????????????????????????????????????????????????????????????????????????????????????
/????????°???????????? h ??? 4 ??§?????£?????????????????¨????????????4?????? abcd ????????????????????? eefab ???????°??????£?????????????????§??\???????????????????????????
/eefababcd
/???????????£???????????????????????°??????????????????
/?????????????±±??????????????????(?????????)??¨ h ??????????????????????????????????????????(?????????)???????????????????????°?????????????????????????????????
*/
/*Input
/????????????????????¨????????????
/?????£??????????????° m
/h1
/h2
/..
/hm
/????????????????????¨??????????????? "-" ?????¨?????\?????????????????¨????????????
*/

public class Main {
	public static void main(String[] args) throws Exception{
		BufferedReader sc = new BufferedReader(new InputStreamReader(System.in));
		//??\????????????
		String st;
		//????????¨
		StringBuffer sb = new StringBuffer();
		//??\???????????????"-"??§?????????????????????("-"????????????)
		while (!(st = sc.readLine()).equals("-")){
			//???????????£????????????????????\???
			int m = Integer.parseInt(sc.readLine());
			//?????£?????????
			for(int i = 0;i < m;i++){
				//??????????????????????????£????????????????????\???
				int h = Integer.parseInt(sc.readLine());
				//??????????°?????????£?????????????????????????????£????????????
				st += st.substring(0,h);
				//?¬????????????????h?????§?????????????????????
				st = st.substring(h);
			}
			//???????????????????????¨?????????????????¨(sb)?????£???
			sb.append(st+"\n");
		}
		System.out.print(sb);
	}
}

Measured memory_bytes: 24216
#include <iostream>
#include <vector>
#include <utility>
#include <map>
#include <algorithm>
#include <queue>
#include <cmath>
#include <string>

using namespace std;

int main() {
    string s;
    cin >> s;
    int n = s.size();
    int ans = 0;

    for (int i=0; i<n/2; i++) {
        if (s[i] != s[n-i-1]) ans++;
    }

    cout << ans << endl;
}

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

int main() {
  int N, x;
  cin >> N >> x;

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

  sort(a, a + N);

  int counter = 0;
  int sum = 0;
  for (int i = 0; i < N; i++) {
    sum += a[i];
    if (x > sum) counter++;
    else if (x == sum) {
      counter++;
      break;
    }
    else break;
  }
  
    if (x > sum) counter--;

  cout << counter << endl;
}

Measured memory_bytes: 256
N = int(input())
S = [input() for _ in range(N)]
ans = 0
ba = b = a = 0
for s in S:
    ans += s.count('AB')
    if s[0] + s[-1] == 'BA':
        ba += 1
    if s[0] == 'B':
        b += 1
    if s[-1] == 'A':
        a += 1
ans += min(a, b)
if a == b == ba and b:
    ans -= 1
print(ans)


Measured memory_bytes: 3700
#include<deque>
#include<queue>
#include<vector>
#include<algorithm>
#include<iostream>
#include<set>
#include<cmath>
#include<tuple>
#include<string>
#include<chrono>
#include<functional>
#include<iterator>
#include<random>
#include<unordered_set>
#include<array>
#include<map>
#include<iomanip>
#include<assert.h>
#include<bitset>
#include<stack>
#include<memory>
using namespace std;
using namespace std::chrono;
typedef long long int llint;
typedef double lldo;
#define mp make_pair
#define mt make_tuple
#define pub push_back
#define puf push_front
#define pob pop_back
#define pof pop_front
#define fir first
#define sec second
#define res resize
#define ins insert
#define era erase

/*
cout<<fixed<<setprecision(20);
cin.tie(0);
ios::sync_with_stdio(false);
*/
const llint mod=1000000007;
const llint big=2.19e18+1;
const long double pai=3.141592653589793238462643383279502884197;
const long double eps=1e-15;
template <class T,class U>bool mineq(T& a,U b){if(a>b){a=b;return true;}return false;}
template <class T,class U>bool maxeq(T& a,U b){if(a<b){a=b;return true;}return false;}
llint gcd(llint a,llint b){if(a%b==0){return b;}else return gcd(b,a%b);}
llint lcm(llint a,llint b){if(a==0){return b;}return a/gcd(a,b)*b;}
template<class T> void SO(T& ve){sort(ve.begin(),ve.end());}
template<class T> void REV(T& ve){reverse(ve.begin(),ve.end());}
template<class T>llint LBI(vector<T>&ar,T in){return lower_bound(ar.begin(),ar.end(),in)-ar.begin();}
template<class T>llint UBI(vector<T>&ar,T in){return upper_bound(ar.begin(),ar.end(),in)-ar.begin();}

int main(void) {
	int i,j,h,n,K;cin>>n>>K;
	llint dp[101][256]={0};
	dp[0][0]=1;
	for(i=0;i<n;i++){
		int x;cin>>x;
		for(j=i;j>=0;j--){
			for(h=0;h<256;h++){
				dp[j+1][h^x]+=dp[j][h];
				dp[j+1][h^x]%=mod;
			}
		}
	}
	llint ans=0,kai=1;
	for(i=0;i<=n;i++){
		ans+=dp[i][K]*kai;
		ans%=mod;
		kai*=(i+1);
		kai%=mod;
	}
	cout<<ans<<endl;
	
	return 0;
}

Measured memory_bytes: 384
n,m=map(int,input().split())
a=list(map(int,input().split()))
a=sorted(a,reverse=True)
A=[]
s=sum(a)
c=s/(4*m)
for i in range(m):
  if a[i]>=c:
    A.append(a[i])
print("Yes" if len(A)==m else "No")

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

int main() {
  string S, T;
  cin >> S >> T;
  int A, B;
  cin >> A >> B;
  string U;
  cin >> U;
  
  if (S == U) {
    A = A - 1;
  }
  else {
    B = B - 1; 
  }   
  cout << A << " " << B << endl;
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n)  for(long long i=0;i<(long long)(n);i++)
#define REP(i,k,n) for(long long i=k;i<(long long)(n);i++)
#define all(a) a.begin(),a.end()
#define pb push_back
#define eb emplace_back
#define lb(v,k) (lower_bound(all(v),k)-v.begin())
#define ub(v,k) (upper_bound(all(v),k)-v.begin())
#define fi first
#define se second
#define pi M_PI
typedef long long ll;
typedef pair<ll,ll> P;
typedef tuple<ll,ll,ll> PP;
typedef multiset<ll> S;
typedef priority_queue<ll> PQ;
typedef priority_queue<P,vector<P>,greater<P>> SPQ;
using vi=vector<ll>;
using vvi=vector<vi>;
using vvvi=vector<vvi>;
const ll inf=1001001001001001;
const int INF=1001001001;
const int mod=1000000007;
template<class T> bool chmin(T&a,T b){if(a>b){a=b;return true;}return false;}
template<class T> bool chmax(T&a,T b){if(a<b){a=b;return true;}return false;}
template<class T> void out(T a){cout<<a<<'\n';}
template<class T> void outp(T a){cout<<'('<<a.fi<<','<<a.se<<')'<<'\n';}
template<class T> void outvp(T v){rep(i,v.size())outp(v[i]);}
template<class T> void outv(T v){rep(i,v.size()){if(i)cout<<' ';cout<<v[i];}cout<<'\n';}
template<class T> void outvv(T v){rep(i,v.size()){rep(j,v[i].size()){if(j)cout<<' ';cout<<v[i][j];}cout<<'\n';}}
ll gcd(ll a,ll b){if(b==0)return a;return gcd(b,a%b);}
ll modpow(ll a,ll b){a%=mod;if(b==0)return 1;if(b&1)return a*modpow(a,b-1)%mod;ll k=modpow(a,b/2);return k*k%mod;}

int main() {
    ll n;cin>>n;
    ll a=0,b=0;
    rep(i,n){
        ll d,c;cin>>d>>c;
        a+=c;
        b+=d*c;
    }
    out(a-1+(b-1)/9);
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <boost/multiprecision/cpp_int.hpp>

using boost::multiprecision::cpp_int;
using namespace std;

#if __has_include("print.hpp")
  #include "print.hpp"
#endif

#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define ALL(x) (x).begin(), (x).end()
#define RALL(x) (x).rbegin(), (x).rend()
#define MOD 1000000007

typedef long long ll;
typedef pair<ll, ll> p;


int main(){
  ios::sync_with_stdio(false);
  cin.tie(0);
  int n;
  cin >> n;
  vector<int> v(n);
  rep(i, n) cin >> v[i];

  ll res = 0;
  int now = 1;
  for (int i = 0; i < n; i++) {
    if(now == v[i]){
      res++;
      now++;
    }
  }

  if(res == 0) cout << -1 << endl;
  else cout << n - res << endl;
}


Measured memory_bytes: 1152
#include <bits/stdc++.h>
using namespace std;
#define REP(i, n) for (int i = 0; i < int(n); i++)
#define FOR(i, a, b) for (int i = a; i < int(b); i++)
#define FOREACH(i, v) for (__typeof((v).begin()) i = (v).begin(); i != (v).end(); i++)
#define SIZE(v) ((int)(v).size())
#define pb push_back
#define mp make_pair
#define st first
#define nd second
#define ll long long
#define llint long long
#define pii pair<int, int>
#define UNVISITED -1

const int MAX = 5050;
int P[MAX];
ll C[MAX];
int N;
ll K; 
bool visited[MAX];

ll solve(vector<int>& cycle) {
	int len = (int)cycle.size();
	vector<ll> best; best.pb(-INFINITY);
	ll cur = 0;
	REP(i, len) {
		cur += C[cycle[i]];
		best.pb(max(best.back(), cur));
	}
	ll ans = -INFINITY;
	if(K <= len) {
		ans = max(ans, best[K]);
	}
	else {
		if(cur < 0) {
			ans = best[len];
		}
		else {
			if(K > 3*len) {
				ll K2 = 2*len + K%len;
				ll K1 = K - K2;
				ans = (K1/len) * cur;
				cur = ans;
				int j = 0;
				REP(i, K2) {
					cur += C[cycle[j]];
					j++;
					if(j >= len) j -= len;
					ans = max(ans, cur);
				}
			}
			else {
				ll cur = 0;
				int j = 0;
				REP(i, K) {
					cur += C[cycle[j]];
					j++;
					if(j >= len) j -= len;
					ans = max(ans, cur);
				}
			}
		}
	}
	return ans;
}

int main() {
	scanf("%d %lld", &N, &K);
	ll ans = -INFINITY;
	for(int i = 1; i <= N; i++) scanf("%d", P + i);
	for(int i = 1; i <= N; i++) scanf("%lld", C + i), ans = max(ans, C[i]);
	
	for(int i = 1; i <= N; i++) if(!visited[i]) {
		vector<int> cycle;
		int j = i;
		while(!visited[j]) {
			cycle.pb(j);
			visited[j] = true;
			j = P[j];
		}
		int len = (int)cycle.size();
		REP(i, len) {
			vector<int> c;
			REP(j, len) {
				c.pb(i + j < len ? cycle[i + j] : cycle[i + j - len]);
			}
			ans = max(ans, solve(c));
		}
	}
	printf("%lld\n", ans);
}

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

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

Measured memory_bytes: 3628
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
#define REP(i, n) FOR(i, 0, (n))
#define FOR(i, a, b) for(int i=(a); i<(b); i++)
#define LAR(a, b) ((a)=max((a),(b)))
#define SML(a, b) ((a)=min((a),(b)))
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<pair<int, int>> vpii;
typedef pair<int, int> pii;
#define PB push_back
#define EB emplace_back
#define MP make_pair
#define ALL(a) (a).begin(), (a).end()
#ifdef LOCAL_DEBUG
#define DEBUG(...) printf(__VA_ARGS__)
#else
#define DEBUG(...)
#endif

int main(){
	int a, b; scanf("%d%d", &a, &b);
	b--; a--; 
	printf("%d\n", (b+a-1)/a);
}


Measured memory_bytes: 256
#define  _CRT_SECURE_NO_WARNINGS
#include <stdio.h>
#include <algorithm>
#include <utility>
#include <functional>
#include <cstring>
#include <queue>
#include <stack>
#include <math.h>
#include <iterator>
#include <vector>
#include <string>
#include <set>
#include <math.h>
#include <iostream>
#include <random>
#include<map>
#include <iomanip>
#include <time.h>
#include <stdlib.h>
#include <list>
#include <typeinfo>
#include <list>
#include <set>
#include <cassert>
#include<fstream>
#include <unordered_map>
#include <cstdlib>
#include <complex>
using namespace std;
#define Ma_PI 3.141592653589793
#define eps 0.00000001
#define LONG_INF 3e18
#define GOLD 1.61803398874989484820458
#define MAX_MOD 1000000007
#define MOD 998244353
#define REP(i,n) for(long long i = 0;i < n;++i)    
#define seg_size 524288
double dot(complex<double> a, complex<double> b) {
	return a.real() * b.real() + a.imag() * b.imag();
}
double gyaku_dot(complex<double> a, complex<double> b) {
	return a.real() * b.imag() - a.imag() * b.real();
}
double leng(complex<double> a) {
	return sqrt(a.real() * a.real() + a.imag() * a.imag());
}
double angles(complex<double> a, complex<double> b) {
	double cosine = dot(a, b) / (leng(a) * leng(b));
	double sine = gyaku_dot(a, b) / (leng(a) * leng(b));
	double kaku = acos(cosine);
	if (sine <= 0) {
		kaku = 2 * Ma_PI - kaku;
	}
	return kaku;
}
vector<int> convex_hull(vector<complex<double>> a) {
	vector<int> ans;
	double now_minnest = a[0].real();
	int now_itr = 0;
	REP(i, a.size()) {
		if (now_minnest > a[i].real()) {
			now_minnest = a[i].real();
			now_itr = i;
		}
	}
	ans.push_back(now_itr);
	complex<double> ba(0, 1);
	while (true) {
		int now_go = 0;
		double now_min = 0;
		int starter = ans[ans.size() - 1];
		for (int i = 0; i < a.size(); ++i) {
			if (i != starter) {
				double goa = angles(ba, a[i] - a[starter]);
				if (goa > now_min) {
					now_min = goa;
					now_go = i;
				}
			}
		}
		if (now_go == ans[0]) break;
		ans.push_back(now_go);
		ba = complex<double>(a[now_go] - a[starter]);
	}
	return ans;
}
long long gcd(long long a, long long b) {
	if (b == 0) return a;
	return gcd(b, a % b);
}
int main() {
	string s;
	cin >> s;
	REP(i, s.length() - 1) {
		if (s[i] == s[i + 1]) {
			cout << "Bad" << endl;
			return 0;
		}
	}
	cout << "Good" << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
  int N;
  cin >> N;
  int A[N];
  for (int i=0;i<N;i++){
    cin >> A[i];
  }
  int count=1;
  int destroy=0;
  for(int i=0;i<N;i++){
    if(count==A[i]){
      count++;
    }else {
      destroy++;
    }
  }
  if (count==1){
    cout << "-1";
  }else {
    cout << destroy;
  }
}


Measured memory_bytes: 1024
#include <iostream>
using namespace std;
int main(void){
    long long N,A,B,i,a,b,c,P;
    cin>>N>>A>>B;
    a=0;b=0;c=0;
    for(i=0;i<N;i++){
        cin>>P;
        if(P<A+1){
            a++;
        }else if(P<B+1){
            b++;
        }else{
            c++;
        }
    }
    N=min(a,min(b,c));
    cout<<N<<endl;
}


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

int main(){
  vector<int> v(5);
  for(int i=0; i<5; i++) cin >>v[i];
  int ans=-1;
  do{
    int temp=0;
    for(int i=0; i<5; i++){
      temp=ceil((double)temp/10)*10;
      temp+=v[i];
    }
    if(ans==-1) ans=temp;
    else ans=min(ans,temp);
  }while(next_permutation(v.begin(), v.end()));
  cout << ans << endl;
}

Measured memory_bytes: 256
#include <algorithm>
#include <cmath>
#include <iostream>
#include <map>
#include <numeric>
#include <string>
#include <vector>

using namespace std;

struct Memo {
	long long fact = 0;
	long long fact_inv = 0;
	long long inv = 0;
};
class Combination {
private:
	int m_module = 1000000007;
	vector<struct Memo> memo;
public:
	int calculate(int, int);
	Combination(int, int);
};
int Combination::calculate(int n, int k) {
	return (memo[n].fact * (memo[k].fact_inv * memo[n - k].fact_inv) % m_module) % m_module;
}
Combination::Combination(int memo_max, int module = 1000000007) {
	m_module = module;
	memo.push_back({ 1,1,0 });
	memo.push_back({ 1,1,1 });
	for (int loop = 2; loop <= memo_max; loop++) {
		struct Memo temp;
		temp.fact = (memo[loop - 1].fact * loop) % m_module;
		temp.inv = m_module - (memo[m_module % loop].inv * int(m_module / loop)) % m_module;
		temp.fact_inv = (memo[loop - 1].fact_inv * temp.inv) % m_module;
		memo.push_back(temp);
	}
}

void A_Strings(void) {

	string S, T;
	cin >> S >> T;
	cout << T << S << flush;
	return;
}

void B_Greedy_Takahashi(void) {

	long long A, B, K;
	cin >> A >> B >> K;

	if (K < A) {
		A -= K;
	}
	else if (K < A + B) {
		B -= (K - A);
		A = 0;
	}
	else {
		A = 0;
		B = 0;
	}
	cout << A << " " << B << flush;
	return;
}

int main(void) {

	//A_Strings();
	B_Greedy_Takahashi();
	return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define REP(i, n) for (int i = 0; i < (n); ++i)
#define int long long
#define vec(a,n) vector<int> (a)((n))
#define Vec(a,n) vector<string> (a)((n))
#define P pair<int,int>
#define PQ(n) priority_queue<P,vector<P>,greater<P>> (n)
#define pq(n) priority_queue<int> (n)
using namespace std;

signed main(){
    string s,t;
    cin >> s >> t;
    int n=s.size();
    vec(a,26);
    vec(b,26);
    int ans=0;
    REP(i,n){
        int x = s[i] - 'a';
        int y = s[i] - t[i];
        int z = t[i] - 'a';
        if(a[x] != 0 && a[x] != y){
            ans = 1;
        }
        else if(b[z] != 0 && b[z] != y){
            ans=1;
        }
        else{
            a[x]=y;
            b[z] = y;
        }
    }
    (ans == 0)? cout << "Yes" << endl : cout << "No" << endl;
    return 0;
}


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

typedef long long int ll;
ll MOD = 1000000007;
ll INFL = 1ll << 60;
ll INF = 1 << 28;

template <typename T>
ostream& operator<<(ostream& os, vector<T>& vec) {
  cout << "{";
  for (int i = 0; i < vec.size(); i++)
    os << vec[i] << (i + 1 == vec.size() ? "" : " ");
  cout << "}";
  return os;
}

// ====================================================================

int main() {
  int n;
  cin >> n;
  vector<int> v(n);
  for (int i = 0; i < n; i++) { cin >> v[i]; }
  sort(v.begin(), v.end());

  // cout << v << endl;

  ll ans = 0;
  for (int i = 0; i < n - 1; i++) {
    for (int j = i + 1; j < n; j++) {
      // cout << v[i] << " " << v[j] << " ";
      auto res = upper_bound(v.begin(), v.end(), abs(v[i] - v[j]));
      ll hidari = distance(v.begin(), res);
      res = lower_bound(v.begin(), v.end(), v[i] + v[j]);
      ll migi = distance(v.begin(), res);
      // cout << hidari << " " << migi << endl;
      ans += migi - hidari - 1;
      if (hidari <= i) ans--;
    }
  }

  cout << ans / 3 << endl;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int k,s,ans;
int main() {
	ios::sync_with_stdio(false);
	cin >> k >> s;
	for(int i = 0; i <= k; i++)
		for(int j = 0; j <= k; j++)
			ans += s - i - j >= 0 && s - i - j <= k;
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 256
#define _USE_MATH_DEFINES
#include <bits/stdc++.h>
using namespace std;
signed main() { 
  ios::sync_with_stdio(false); cin.tie(0);
  //b
  int h, w;
  cin >> h >> w;
  if (h > 1 && w > 1) cout << (1LL * h * w + 1) / 2 << endl;
  else cout << 1 << endl;
  return 0;
}

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

using namespace std;
typedef long long ll;

#define rep(i, N) for (int i = 0; i < (int)N; i++)
const ll MOD = pow(10,9)+7;
const ll LLINF = pow(2,61)-1;
const int INF = pow(2,29)-1;


int main() {
  int N; cin >> N;
  vector<vector<int>> work;
  rep(i,N) {
    int A, B; cin >> A >> B;
    work.push_back({A,B});
  }
  sort(work.begin(), work.end(), [](const vector<int>& x, const vector<int>& y) {return x[1]<y[1];});
  int sum = 0;
  bool ok = true;
  rep(i,N) {
    sum += work[i][0];
    if (work[i][1]<sum) { ok = false; break; }
  }
  string result = (ok) ? "Yes" : "No";
  cout << result << endl;
  return 0;
}

Measured memory_bytes: 12588
N = int(input())
A = list(map(int,input().split()))

c = [0 for k in range(max(A)+2)]
ans = 1
MOD = 1000000007

c[0] = 3
for k in range(N):
    ans *= c[A[k]] - c[A[k]+1]
    c[A[k]+1] += 1
    ans %= MOD

print(ans)


Measured memory_bytes: 56684