akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
using namespace std;
#define int long long int
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define all(v) v.begin(),v.end()
#define zeros(arr) memset(arr,0,sizeof(arr))
#define precise(num)  cout<<fixed; cout << std::setprecision(num)
int32_t main(){
    
    ios_base::sync_with_stdio(cin.tie(NULL));
    cout.tie(NULL);
    
    int tc = 1;
    // cin>>tc;
    while(tc -- ){
        
        
        string s;
        cin>>s;
        string flag="Yes\n";
        for(int i = 0; i <s.size() ; i++ )
        {
            if(s[i] != 'h' || s[i+1]!='i')
                flag="No";
                
            i++;    
            
        }
        cout<<flag<<endl;
    }
    
}

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

void rec(int d, ll val, vector<ll> &a) {
	a.push_back(val);
	if(d == 10) return;
	for(int i = -1; i <= 1; i++) {
		int add = val%10 + i;
		if(add >= 0 && add <= 9) rec(d+1, val*10+add, a);
	}
}

int main() {
	int k;
	cin >> k;
	vector<ll> a;
	rep(i, 9) rec(1, i+1, a);
	sort(all(a));
	cout << a[k-1] << endl;
	return 0;
}

Measured memory_bytes: 2420
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define i_7 (ll)(1E9+7)
#define i_5 (ll)(1E9+5)
ll mod(ll a){
    ll c=a%i_7;
    if(c>=0)return c;
    else return c+i_7;
}
typedef pair<int,int> i_i;
typedef pair<ll,ll> l_l;
ll inf=(ll)1E12;//10^12
#define rep(i,l,r) for(ll i=l;i<=r;i++)
#define pb push_back
ll max(ll a,ll b){if(a<b)return b;else return a;}
ll min(ll a,ll b){if(a>b)return b;else return a;}
const double EPS=1E-8;
////////////////////////////////////////



int main() {
    
    ll n;cin>>n;
    ll a[n][3];rep(i,0,n-1)rep(j,0,2)cin>>a[i][j];
    rep(i,0,n){
        if(i==n){
            cout<<-1;
            return 0;
        }else if(a[i][2]!=0)break;
    }
    
    if(a[0][2]==0){
        bool f=false;
        rep(i,1,n-1){
            if(a[i][2]!=0){
                rep(j,0,2){
                    swap(a[0][j],a[i][j]);
                }
                f=true;
                break;
            }
        }
        /*if(!f){
            bool x[105][105];memset(x,true,sizeof(x));
            rep(i,0,n-1){
                x[a[i][0]][a[i][1]]=false;
            }
            rep(ci,0,100)rep(cj,0,100){
                if(x[ci][cj]){
                    cout<<ci<<" "<<cj<<" "<<1<<endl;
                }
                return 0;
            }
        }*/
    }
    rep(ci,0,100){
        rep(cj,0,100){
            ll h=a[0][2]+abs(ci-a[0][0])+abs(cj-a[0][1]);
            bool flag=true;

            rep(i,1,n-1){
                if(a[i][2]==0){
                    if(a[i][2]+abs(ci-a[i][0])+abs(cj-a[i][1])<h){
                        flag=false;
                        break;
                    }
                }else if(h!=a[i][2]+abs(ci-a[i][0])+abs(cj-a[i][1])){
                    flag=false;
                    break;
                }
            }
            if(flag&&h>=1){
                cout<<ci<<" "<<cj<<" "<<h<<endl;
            }
        }
    }
    
    
    return 0;
}

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

int n,s[100010][27],a[100010];
char ss[100010];
long long ans;
const long long mod=1e9+7;
int main()
{
	scanf("%d",&n);
	scanf("%s",ss+1);
	for(int i=1;i<=n;++i)
	a[i]=ss[i]-'a'+1;
	for(int i=n;i>=1;--i)
	{
		for(int j=1;j<=26;++j)
		s[i][j]=s[i+1][j];
		s[i][a[i]]++;
	}
	for(int i=1;i<=n;++i)
	{
		int x=a[i];
		long long res=1;
		for(int j=1;j<=26;++j)
		{
			if(j==x)
			continue;
			res=res*(s[i][j]+1)%mod;
		}
		ans=(ans+res)%mod;
	}
	printf("%lld\n",ans);
	return 0;
}

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

int main(){
        string a,b,c;
        cin >> a >> b >> c;
        cout << a[0] << b[0] << c[0] << endl;
        return 0;
}


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

int main() {
    int n;cin>>n;
    int x[n],y[n],h[n];
    tuple<int,int,int> t;
    for (int i=0;i<n;i++) {
        cin>>x[i]>>y[i]>>h[i];
        if (h[i]!=0)
            t=make_tuple(x[i],y[i],h[i]);
    }
    for (int i=0;i<=100;i++)
        for (int j=0;j<=100;j++) {
            int a=abs(j-get<0>(t))+abs(i-get<1>(t))+get<2>(t);
            int f=1;
            for (int k=0;k<n;k++)
                f&=max(0,a-abs(j-x[k])-abs(i-y[k]))==h[k];
            if (f) {
                cout<<j<<' '<<i<<' '<<a<<endl;
                return 0;
            }
        }
    return 0;
}

Measured memory_bytes: 256
using System;
using System.Collections.Generic;

public class test {
    static public void Main () {
        var n = int.Parse (Console.ReadLine ());
        int pre;
        List<int> a = new List<int> ();
        for (pre = 0; pre < n; pre++) {
            a.Add (int.Parse (Console.ReadLine ()));
        }
        int maxv = a[a.Count - 1] - a[0];
        int minv = a[0];
        for (int i = 1; i < n; i++) {
            maxv = Math.Max (maxv, a[i] - minv);
            minv = Math.Min (minv, a[i]);
        }

        Console.Write ("{0}\n", maxv);
    }
}


Measured memory_bytes: 12080
#include <iostream>
#include <utility>
#include <algorithm>
#include <vector>
#include <string>
#include <queue>
#include <map>
using namespace std;
typedef long long ll;
const long long mod = 1e9 + 7;
int gcd (int a,int b) {
   if (a >= b) {
       if (b == 0) {
           return a;
       }
       else {
           return gcd(b,a % b);
       }
   }
   else {
       return gcd(b,a);
   }
}
ll pow(ll a,ll n,ll d) {
    if (n == 0) {
        return 1;
    }
    if (n % 2 == 1){
        return a * pow(a,n - 1,d) % d;
    }
    else {
        ll t = pow(a,n/2,d);
        return t * t % d;
    }
}
int main() {
    ll n,k;
    cin >> n >> k;
    ll ans[k + 1];
    for (ll i = k; i >= 1; i--) {
        ans[i] = pow(k / i, n , mod);
        int count = 2;
        while  (i * count < k + 1) {
            ans[i] -= ans[i * count];
            count++;
        }
    }
    ll ret = 0;
    for (int i = 1; i <= k; i++) {
        ret += ans[i] * i % mod;
    }
    cout << ret % mod ;
    return 0;
}

Measured memory_bytes: 4260
import java.util.Arrays;
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		// TODO 自動生成されたメソッド・スタブ
		int i;
		Scanner sc = new Scanner(System.in);
		 int n = sc.nextInt();
		 String s []=new String[n];
		 for(i = 0;i<n;i++) {
		 s[i]=sc.next();
				 };if(Arrays.asList(s).contains("Y")) {
			            System.out.println("Four");
			            }
				 else{System.out.println("Three");}
		 
		

	}

}


Measured memory_bytes: 21972
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int inf = 1e9;

int main(){
	int res = 0;
	int x = 0;
	for(int i = 0; i < 5; ++i){
		cin>>x;
		if(x == 0)res = i;
	}
	cout<<res+1<<endl;	
	return 0;
}


Measured memory_bytes: 3632
#include <bits/stdc++.h>
#define ll long long
#define f first
#define s second
using namespace std;
ifstream f ("test.in"); ofstream g ("test.out");
ll n,a[100005],b[100005],c[100005],dp[100005][5];
int main()
{   ios_base::sync_with_stdio(0);
    cin.tie(0);
    cin>>n;
    for(int i=1;i<=n;i++) cin>>a[i]>>b[i]>>c[i];
    dp[1][1]=a[1];
    dp[1][2]=b[1];
    dp[1][3]=c[1];
    for(int i=2;i<=n;i++)
    {   dp[i][1]=max(dp[i-1][2]+a[i],dp[i-1][3]+a[i]);
        dp[i][2]=max(dp[i-1][1]+b[i],dp[i-1][3]+b[i]);
        dp[i][3]=max(dp[i-1][1]+c[i],dp[i-1][2]+c[i]);
    }
    cout<<max(dp[n][1],max(dp[n][2],dp[n][3]));
    return 0;
}


Measured memory_bytes: 6528
#include <iostream>
#include <vector>
#include <string>
#include <utility>
#include <queue>
#include <algorithm>
#include <map>
#include <set>
#include <cmath>
using namespace std;

#define ll long long
#define pint pair<int,int>
#define pll pair<ll,ll>
#define pb push_back
#define mp make_pair
#define SPACE " "
#define fpf first.first
#define fps first.second
#define spf second.first
#define sps second.second

#define all(VECTOR) (VECTOR).begin(),(VECTOR).end()

ll gcd(ll a, ll b) {

	if (a < b) {

		ll tmp = a;
		a = b;
		b = tmp;

	}
	if (a%b == 0)return b;
	return gcd(b, a%b);

}
//最大公約数

ll lcm(ll a, ll b) {

	return a / gcd(a, b)*b;

}
//最小公倍数
int main(){

	ll a,b,c;
	cin >> a >> b >> c;
	int cnt=0;
	int num=min(a,b)+1;
	while(true){
		num--;
		if(a%num==0&&b%num==0)cnt++;
		if(cnt==c){
			cout<<num<<endl;
			break;
		}
	}
	return 0;
}

Measured memory_bytes: 256
//#pragma GCC optimize ("-O3","unroll-loops")
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<queue>
#include<map>
#include<math.h>
#include<iomanip>
#include<set>
#include<numeric>
#include<cstring>
#include<cstdio>
#include<functional>
#include<bitset>
#include<limits.h>
#include<cassert>
#include<iterator>
#include<complex>
#include<stack>
#include<unordered_map>
#include<unordered_set>
#include<time.h>
#include <random>

using namespace std;

#define REP(i, n) for(int i = 0;i < n;i++)
#define REPR(i, n) for(int i = n;i >= 0;i--)
#define FOR(i, m, n) for(int i = m;i < n;i++)
#define FORR(i, m, n) for(int i = m;i >= n;i--)
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
#define REVERSE(v,n) reverse(v,v+n);
#define VREVERSE(v) reverse(v.begin(), v.end());
#define ll long long
#define pb(a) push_back(a)
#define print(x) cout<<x<<'\n';
#define pe(x) cout<<x<<" ";
#define lb(v,n) lower_bound(v.begin(), v.end(), n);
#define ub(v,n) upper_bound(v.begin(), v.end(), n);
#define int long long
#define all(x) (x).begin(), (x).end()
#define print_space(v) REP(i,v.size())cout << v[i] << ((i == v.size() - 1) ? "\n" : " ");
//#define double long double

template<typename T1, typename T2> inline void chmin(T1 & a, T2 b) { if (a > b) a = b; }
template<typename T1, typename T2> inline void chmax(T1& a, T2 b) { if (a < b) a = b; }
typedef pair<int, int>P;
const int MOD = 1e9 + 7;
const int MAX = 200060;
const double pi = acos(-1);
const ll INF = 1e18;



void solve() {
	int N; cin >> N;
	vector<int>A(N);
	REP(i, N) {
		cin >> A[i];
	}
	//A.push_back(-INF);
	A.push_back(INF);
	VSORT(A);
	int ans = 0;
	FOR(i,0, N-1) {
		FOR(j, i + 1, N) {
			int a = A[i], b = A[j];
			int num = 0;
			int mx = a + b, mn = max(a - b, b - a);
			auto itr1 = lb(A, mx);
			int id = itr1 - A.begin();
			num = id - j - 1;
			if (num > 0)ans += num;
		}
	}
	print(ans);
}


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

	solve();
}

Measured memory_bytes: 256
import sys
import math
import itertools
import collections
import numpy as np

rl = sys.stdin.readline
n = int(rl())
li = []
for _ in range(n):
  lis = list(map(int, rl().split()))
  li.append(lis)
t = 0
for i in list(itertools.permutations(range(n))):
  for k in range(n-1):
    s = (li[i[k]][0] - li[i[k+1]][0])**2 + (li[i[k]][1] - li[i[k+1]][1])**2
    t += s**0.5
print(t/math.factorial(n))
  
  
  


Measured memory_bytes: 16960
import math

# input an integer N
N = int(input())

n = math.log(N,10) + 1
int_n = int(n)

sum = 0
for i in range(1, int_n, 2):
    sum += 9 * math.pow(10, i-1)

if int_n % 2 != 0:
    sum += N - math.pow(10,int_n-1)+1

print(int(sum))

Measured memory_bytes: 3316
#![allow(non_snake_case)]

use std::io::{stdin, Read};
use std::str::FromStr;
fn read_option<T: FromStr>() -> Option<T> {
    let stdin = stdin();
    let stdin = stdin.lock();
    let token: String = stdin
        .bytes()
        .map(|c| c.expect("failed to read char") as char)
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect();
    token.parse().ok()
}
fn read<T: FromStr>() -> T {
    let opt = read_option();
    opt.expect("failed to parse token")
}

fn main() {
    let N: usize = read();
    let mut vec: Vec<usize> = vec![];
    for _ in 0..N {
        vec.push(read());
    }
    vec.sort();
    let mut sum = 0;
    let mut min_index = 0;
    for (i, &v) in vec.iter().enumerate() {
        if sum * 2 < v {
            min_index = i;
        }
        sum += v;
    }
    println!("{}", N - min_index);
}


Measured memory_bytes: 4352
// C++ 14
#include <bits/stdc++.h>
using namespace std;
template <typename T>  ostream& operator<<(ostream& os, const vector<T>& v)  {  os << "[";  for (int i = 0; i < v.size(); ++i) {  os << v[i];  if (i != v.size() - 1)  os << ", ";  }  os << "]";  return os;  }
template <typename T> void print(T v, string s = "\n") { cout << v << s; }
template <typename T> void in(T &v) { cin >> v; }
#define ll long long
#define loop(__x, __start, __end) for(int __x = __start; __x < __end; __x++)

typedef pair<ll, ll> P;
int main() {
  ll n, k; in(n),in(k);
  vector<P> A(n);
  loop(i,0,n) in(A[i].first),in(A[i].second);
  sort(A.begin(), A.end());
  loop(i,0,n) {
    if (k <= A[i].second) {
      print(A[i].first);
      return 0;
    }
    
    k -= A[i].second;
  }
  assert(false);
  return 0;
}


Measured memory_bytes: 4848
#include<cstdio>
using namespace std;
int main(){
	
	char str[16] ={0};
	
	while(scanf("%s",str) != EOF){
		
		int num[16] = {0};
		
		for(int i = 0;i < 10; i++){
			
			num[i] = str[i] - 48;
			
		}
		
		int x = 9;
		int ans[16] = {0};
		
		for(int i = 0; i < x; i++){
			for(int j = 0; j < x; j++){
				ans[j] = (num[j]+num[j+1])%10;
				num[j] = ans[j];
			}
		}
		
		printf("%d\n",ans[0]);
		
	}
	
	return 0;
}

Measured memory_bytes: 968
#include <iostream>
#include <math.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <vector>
#include <algorithm>
#include <map>


int main(){
	int M1, M2, D1, D2;
	scanf("%d",&M1);
	scanf("%d",&D1);
	scanf("%d",&M2);
	scanf("%d",&D2);
	if (D1+1==D2){
		printf("0\n");
	} else {
		printf("1\n");
	}
	return 0;
}

Measured memory_bytes: 504
from collections import deque
import sys
input = sys.stdin.readline

S = deque(input().rstrip())
Q = int(input())
rev = False
for _ in range(Q):
    q = input().split()
    if q[0] == '1':
        rev = rev ^ True
    else:
        F, C = q[1:]
        if (F == '1') ^ rev:
            S.appendleft(C)
        else:
            S.append(C)
S = list(S)
if rev:
    S.reverse()
print(''.join(S))

Measured memory_bytes: 8436
def calc(n):
    return n * (n + 1) // 2


def solve():
    s = list(input())
    res = find_sum(s)
    print(res)


def find_sum(S):
    prev = S[0]
    series = 1
    l = []
    for i in range(1, len(S)):
        if prev == S[i]:
            series += 1
        else:
            l.append((prev, series))
            prev = S[i]
            series = 1
    l.append((prev, series))
    prev_max = l[0][1]
    prev = calc(prev_max)
    res = prev
    for s, n in l[1::]:
        if s == '<':
            prev = calc(n)
            prev_max = n
            res += prev
        else:
            if n >= prev_max:
                res -= prev_max
                prev = calc(n)
                res += prev
            else:
                prev = calc(n - 1)
                res += prev

    return res


if __name__ == "__main__":
    solve()

Measured memory_bytes: 27440
#include <iostream>
#include <string>
#include <vector>
#include <map>
#include <algorithm>
#include <deque>
using namespace std;
int main(){
    string s;
    cin >> s;
    string ans = "yes";
    for(int i=0;i<s.length();i++){
        for(int j=0;j<s.length();j++){
            if(i!=j&&s.substr(i,1)==s.substr(j,1)){
                ans = "no"; 
            }
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define N 1005
using namespace std;
char s[N];
int n,R[N][30];
int main() {
	scanf("%s",s+1); n = strlen(s+1);
	for (int _=n;_>=1;_--) {
		for (int i=1;i<=26;i++) R[_][i] = R[_+1][i];
		R[_][s[_]-'a'+1] = _;
	}
	
	int ans = 2147483647;
	for (int _=1;_<=26;_++) {
		int cur = -1;
		for (int i=1;i<=n;i++) {
			int t = n-i+1;
			if (R[i][_]) t = min(t, R[i][_] - i);
			cur = max(cur, t);
		}
		ans = min(ans, cur);
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#include<vector>
#include<string>
using namespace std;
 
int main() {
    int k;cin >> k;
    if(k==1||k==2||k==3||k==5||k==6||k==9||k==10||k==13||k==17){
        cout << "No" << endl;
    }else{
        cout <<"Yes" << endl;
    }
}

Measured memory_bytes: 256
#include "iostream"
#include "climits"
#include "list"
#include "queue"
#include "stack"
#include "set"
#include "functional"
#include "algorithm"
#include "string"
#include "map"
#include "iomanip"
#include "cmath"

using namespace std;

const long long int MOD = 1000000007;

long long int N, M, K, H, W, L, R;


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

	cin >> N >> M >> K;
	L = 0;
	R = 1000000;
	while (R - L > 1) {
		long long int mid = (L + R + 1) / 2;
		if (mid*M + K*(mid + 1) <= N) {
			L = mid;
		}
		else {
			R = mid;
		}
	}
	cout << L << endl;
	return 0;
}

Measured memory_bytes: 256
/*
    Author: Nguyen Tan Bao
    Status:
    Idea:

*/

#include <bits/stdc++.h>
#define FI first
#define SE second
#define EPS 1e-9
#define ALL(a) a.begin(),a.end()
#define SZ(a) int((a).size())
#define MS(s, n) memset(s, n, sizeof(s))
#define FOR(i,a,b) for (int i = (a); i <= (b); i++)
#define FORE(i,a,b) for (int i = (a); i >= (b); i--)
#define FORALL(it, a) for (__typeof((a).begin()) it = (a).begin(); it != (a).end(); it++)
#define WHATIS(x) cout << #x << " is " << x << endl;
#define ERROR(args...) { string _s = #args; replace(_s.begin(), _s.end(), ',', ' '); stringstream _ss(_s); istream_iterator<string> _it(_ss); err(_it, args); }
//__builtin_ffs(x) return 1 + index of least significant 1-bit of x
//__builtin_clz(x) return number of leading zeros of x
//__builtin_ctz(x) return number of trailing zeros of x

using namespace std;
using ll = long long;
using ld = double;
typedef pair<int, int> II;
typedef pair<II, int> III;
typedef complex<ld> cd;
typedef vector<cd> vcd;

void err(istream_iterator<string> it) {}
template<typename T, typename... Args>
void err(istream_iterator<string> it, T a, Args... args) {
    cout << *it << " = " << a << endl;
    err(++it, args...);
}

const ll MODBASE = 1000000007LL;
const int MAXN = 100010;
const int MAXM = 200010;
const int MAXK = 110;
const int MAXQ = 200010;

int n, k, q, a[MAXN];

int main() {
    ios::sync_with_stdio(0);
    cin.tie(nullptr);
    cin >> n >> k >> q;
    FOR(i,1,n) a[i] = k;
    FOR(i,1,q) {
        int u;
        cin >> u;
        a[u]++;
    }
    int cnt = 0;
    FOR(i,1,n)
        if (a[i] > q) cout << "Yes\n";
        else cout << "No\n";
    return 0;
}


Measured memory_bytes: 1024
<?php
$num = (int)fgets(STDIN);
$shiritori_words = [];
foreach(range(0,$num-1) as $n){
    $new_word = fgets(STDIN);
    if((!in_array($new_word,$shiritori_words) and substr($new_word,0,1) == substr($shiritori_words[count($shiritori_words)-1],-2,1)) or $n == 0){
        array_push($shiritori_words,$new_word);
    }else{
        echo "No";
        exit();
    }
}
echo "Yes";
?>

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

string divide[4] = {"dream", "dreamer", "erase", "eraser"};

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

    // 反転
    reverse(S.begin(), S.end());
    for(int i=0; i<4; i++)
       reverse(divide[i].begin(), divide[i].end());
    
    bool can = true;

    for(int i=0; i < S.size();){
        bool can2 = false;
        for(int j=0; j<4; j++){
            string d = divide[j];
            if(S.substr(i, d.size()) == d){
                can2 = true;
                i += d.size();
            }
        }
        if(!can2){
            can = false;
            break;
        }
    }
    if(can){
        cout << "YES" <<endl;
    }else{
        cout << "NO" << endl;
    }
}


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

int main(){
    int a, b, c, k;
    cin >> a >> b >> c >> k;
    int ans = 0;
    if(a >= k) ans += k;
    else ans += a;
    k -= a;

    if(k > 0){
        k -= b;
    }

    if(k > 0){
        ans -= min(c, k);
    }

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

Measured memory_bytes: 3636
#include <stdio.h>
#include <string.h>
#include <memory.h>

void sort(char* buff, int len) {
	int i,j;
	char t;
	for(i=0;i<len-1;i++) {
		for(j=i+1;j<len;j++) {
			if(buff[i] > buff[j]) {
				t = buff[i];
				buff[i] = buff[j];
				buff[j] = t;
			}
		}
	}
}

void reverse(char* buff, int len) {
	int i;
	char t;
	for(i=0;i<len/2;i++) {
		t = buff[i];
		buff[i] = buff[len-i-1];
		buff[len-i-1] = t;
	}
}

int main(void) {
	int i,n,len;
	char buff[20];
	char asc[20];
	char desc[20];
	
	scanf("%d\n", &n);
	for(i=0;i<n;i++) {
		scanf("%s\n", buff);
		len = strlen(buff);

		strcpy(asc, buff);
		sort(asc, len);

		strcpy(desc, asc);
		reverse(desc, len);
		
		printf("%d\n", atoi(desc)-atoi(asc));
	}
	
	return 0;
}

Measured memory_bytes: 612
cash = [1]
n = int(input())
ans = [float('inf')] * (n + 1)
for i in range(1, n):
    if 6 ** i > n:
        break
    cash.append(6 ** i)
for i in range(1, n):
    if 9 ** i > n:
        break
    cash.append(9 ** i)
cash.sort()
ans[0] = 0
for i in range(1, n + 1):
    for j in cash:
        if i - j < 0:
            break
        else:
            ans[i] = min(ans[i], ans[i - j] + 1)
print(ans[n])

Measured memory_bytes: 44368
#include<stdio.h>

int main(void){

int a, b, k, i;
int count = 0;
int ans = 0;

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

if(a >= b){
    for(i = b; i > 0; i--){
        if(a % i == 0 && b % i == 0){
            count += 1;
            if(count == k){
                ans = i;
            }
        }
    }
}

else{
    for(i = a; i > 0; i--){
        if(a % i == 0 && b % i == 0){
            count += 1;
            if(count == k){
                ans = i;
            }
        }
    }
}


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

return 0;
}


Measured memory_bytes: 128
n=int(input())

xy_list=[]
a_list=[]
for i in range(n):
    a=int(input())
    a_list.append(a)
    xy=[]
    for j in range(a):
        xy.append(input().split(" "))

    xy_list.append(xy)

maxn=0
b=[0]*n
for i in range(2**n):
    b=str(format(i,'b').zfill(n))
    out=0
    for j in range(n):
        if b[j]=="0":continue
        for k in range(a_list[j]):
            x=int(xy_list[j][k][0])
            y=str(xy_list[j][k][1])

            if b[x-1]!=y:
                out=1
                break
        
        if out==1:
            break
    
    if out == 0:
        maxn=max(maxn,b.count("1"))

print(maxn)

Measured memory_bytes: 3064
#include <iostream>
#include <iomanip>
#include <stdio.h>

using namespace std;

int main() {
	double a, b;
	cin >> a >> b;

	cout << int(a / b) << " ";
	cout << int(a) % int(b) << " ";
	printf("%.5lf\n", a / b);
	return 0;
}


Measured memory_bytes: 3220
#include <stdio.h>
#include <string.h>

typedef struct Words
{
    char	word[31];
    int		page[100];
} WORDS;

WORDS	wordArray[100];

void printMinWord(WORDS*);
void printMinPage(WORDS*);

int main()
{
    char	tempWord[31];
    int		tempPage;
    int		wordCnt;
    int		pageCnt;
    int		inputCnt = 0;
	
    while (scanf("%s %d", &tempWord, &tempPage) != EOF)
    {
        wordCnt = 0;
        /*sort page to each words*/
        while(1)
        {
            if(!strcmp(tempWord, wordArray[wordCnt].word))
            {
                for(pageCnt = 1; pageCnt < 100; pageCnt++)
                {
                    if(!(wordArray[wordCnt].page[pageCnt]))
                    {
                        break;
                    }
                }
                wordArray[wordCnt].page[pageCnt] = tempPage;
                break;
            }
            else if(!strcmp("", wordArray[wordCnt].word))
            {
                strcpy(wordArray[wordCnt].word, tempWord);
                wordArray[wordCnt].page[0] = tempPage;
                break;
            }
            wordCnt++;
        }
    }
	
    printMinWord(wordArray);

	return 0;
} 

void printMinWord(WORDS* word_array)
{
	int		word_cnt;
	char	min_word[31]	= "zzzzzzzzzzzzzzzzzzzzzzzzzzzzzz";
	int		min_word_index	= -1;
	
	/*find min word and its index*/
	for(word_cnt = 0; word_cnt < 100; word_cnt++)
	{
		if(!strcmp(word_array[word_cnt].word, ""))
		{
			continue;
		}
		if(strcmp(word_array[word_cnt].word, min_word) <= 0)
		{
			strcpy(min_word, word_array[word_cnt].word);
			min_word_index = word_cnt;
		}
	}
	
	/*no recursion if no word content*/
	if(min_word_index != -1)
	{
		printf("%s\n", word_array[min_word_index].word);
		printMinPage(&word_array[min_word_index]);
		strcpy(word_array[min_word_index].word, "");
		return printMinWord(word_array);
	}
}

void printMinPage(WORDS* word_array)
{
	int		page_cnt;
	int		min_page = 1001;
	int		min_page_index	= -1;
		
	/*find min page and its index*/
	
	
	for(page_cnt = 0; page_cnt < 100; page_cnt++)
	{
		if(word_array->page[page_cnt] == 0)
		{
			continue;
		}
		if(word_array->page[page_cnt] < min_page)
		{
			min_page = word_array->page[page_cnt];
			min_page_index = page_cnt;
		}
	}
	
	/*no recursion if no page content*/
	if(min_page_index == -1)
	{
		printf("\n");
		return word_array;
	}
	printf("%d", word_array->page[min_page_index]);
	word_array->page[min_page_index] = 0;
	
	for(page_cnt = 0; page_cnt < 100; page_cnt++)
	{
		if(word_array->page[page_cnt] == 0)
		{
			continue;
		}
		printf(" ");
		return printMinPage(word_array);
	}
	
	return printMinPage(word_array);
}

Measured memory_bytes: 644
x, y = map(int, input().split())

if (x+y)%3 != 0:
    print(0)
    exit(0)

n = (2*y-x)//3
m = (2*x-y)//3

if n<0 or m<0:
    print(0)
    exit(0)

mi = min(n,m)
num = n+m
mod = 10**9+7
a = 1
b = 1

for i in range(mi):
    a = a*(num-i)%mod
    b = b*(mi-i)%mod

print((a*pow(b,mod-2,mod))%mod)

Measured memory_bytes: 3064
import sys
from operator import itemgetter
from collections import deque, Counter
from itertools import permutations, combinations
from heapq import heapify, heappop, heappush
from bisect import bisect, bisect_left

def solve():
    input = sys.stdin.readline
    N = map(int, input().split())
    X = [int(x) for x in input().split()]
    minx, maxx = min(X), max(X)
    minPow = 1000000000000
    for i in range(minx, maxx+1):
        pow = 0
        for j, x in enumerate(X): pow += (x - i) ** 2
        minPow = min(minPow, pow)
    print(minPow)

    return 0

if __name__ == "__main__":
    solve()

Measured memory_bytes: 3348
#include <iostream>
#include <algorithm>
#include <cmath>
#include <limits>
#include <vector>
#include <cstdio>
#include <bits/stdc++.h>
#include <set>
#include <map>
#include <stdio.h>
#include <stack>
#include <queue>
#include <deque>
#include <numeric>
#include <bits/stdc++.h>
#include <utility>
#include <iomanip>

#define ALL(obj) (obj).begin(), (obj).end()
#define FOR(i,a,b) for(int i = (a); i < (b); i++)
#define RFOR(i,a,b) for(int i = (a); (b) <= i; i--)
#define REP(i,n) for(int i = 0; i < (n); i++)
#define RREP(i,n) for(int i = n; n <= i; i--)
#define ABS(a) ((a < 0) ? ((-1)*(a)) : (a))
#define elif else if
#define MOD 1000000007
#define INF (1<<29)

using namespace std;

#define ld long double
#define ll long long

map <int ,int> mpa,mpb;
typedef pair<ll, ll> P;
priority_queue<P, vector<P>, greater<P>> pque;

int main(){
  ios::sync_with_stdio(false);
  cin.tie(NULL);
  ll N,A,B,C,D;
  cin >> N >> A >> B >> C >> D;
  bool flag=false;
  ll cnt=B-A;
  for(int i=0;i<=N-1;i++){
    if(C*i-D*(N-1-i)<=cnt && cnt<=-C*(N-1-i)+D*i){
      flag=true;
      break;
    }
  }

  if(flag) cout << "YES" << endl;
  else cout << "NO" << endl;
  return 0;
}

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

int H, W, n;
int a[10000];
int c[100][100];

int main() {
	ios_base::sync_with_stdio(0);

	cin >> H >> W >> n;
	for(int i = 1; i <= n; i++) cin >> a[i];
	
	int i = 1;
	for(int y = 0; y < H; y++) {
		for(int _x = 0; _x < W; _x++) {
			int x = (y & 1 ? W - _x - 1 : _x);
			if(!a[i]) i++;
			c[y][x] = i;
			a[i]--;
		}
	}	
	
	for(int y = 0; y < H; y++) {
		for(int x = 0; x < W; x++) {
			cout << c[y][x] << " ";
		}
		cout << "\n";
	}
	
	return 0;
}

Measured memory_bytes: 384
import sys #追加
sys.setrecursionlimit(10**9) #追加

n = int(input())

abl = []
nodes = [[] for i in range(n)]
for _ in range(n-1):
    a,b = map(int,input().split())
    abl.append((a,b))
    nodes[a-1] += [b-1]
    nodes[b-1] += [a-1]

m_node = 0
for e in nodes:
    m_node = max(len(e), m_node)

use_node = [0 for i in range(n)]
dic = {}
def dfs(node, start_color):
    use_node[node] = 1
    for e in nodes[node]:
        if use_node[e] == 0:
            dic[(node,e)] = (start_color%m_node)+1
            dic[(e,node)] = (start_color%m_node)+1
            dfs(e, (start_color%m_node)+1)
            start_color += 1

dfs(0,0)
print(m_node)
for a,b in abl:
    print(dic[(a-1,b-1)])



Measured memory_bytes: 87676
#include<bits/stdc++.h>
using namespace std;
#define INFTY 1<<20
#define rep(i,n) for (int i = 0; i < (n); ++i)
typedef long long int ll;
using ipair = pair<int,int>;
bool operator< (const ipair a, const ipair b){return a.first < b.first;};
const int MOD=1000000007;
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};

int main(){ 
    int a,b;
    cin>>a>>b;
    int c,d,e;
    c=a+b;d=a-b;e=a*b;
    if(c>d && c>e){
        cout<<c<<endl;
    }else if(d>=c&&d>e){
        cout<<d<<endl;
    }else{
        cout<<e<<endl;
    }
    return 0;
}

Measured memory_bytes: 3644
using System;
using System.Globalization;
using System.Linq;

namespace AtCoder.Abcdef
{
    public class QuestionC
    {
        //https://atcoder.jp/contests/abc172/tasks/abc172_c
        public static void Main(string[] args)
        {
            var sw = new System.IO.StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false };
            Console.SetOut(sw);

            //Input int array
            int[] inputArray = Console.ReadLine().Split(' ').Select(i => int.Parse(i)).ToArray();
            (int n, int m, int k) = (inputArray[0], inputArray[1], inputArray[2]);
            long[] a = Console.ReadLine().Split(' ').Select(i => long.Parse(i)).ToArray();
            long[] b = Console.ReadLine().Split(' ').Select(i => long.Parse(i)).ToArray();

            var t = b.Sum();
            var j = m;
            var ans = 0;
            for (int i = 0; i < n+1; i++)
            {
                while (j > 0 && t > k) 
                {
                    --j;
                    t -= b[j];
                }

                if (t > k) break;
                ans = Math.Max(ans, j + i);
                if (i == n) break;
                t += a[i];
            }

            Console.WriteLine(ans);
            Console.Out.Flush();
        }
    }
}


Measured memory_bytes: 69728
/* Problem Description:
  A - Frog 1
*/

#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>

using namespace std;

#define REP(i,a,b) for (int i = (a); i < (b); i++)
#define RREP(i,a,b) for (int i = (a); i > (b); i--)
#define FOR(i,a,b) for (int i = (a); i <= (b); i++)
#define TRvi(it, c) for (vi::iterator it = (c).begin(); it != (c).end(); it++)
#define EPS 1e-10
#define PI acos(-1.0)
#define scan(x) scanf("%d",x)
#define ll long long
#define mp make_pair
#define pb push_back
#define sqr(x) ((x)*(x))
#define LSOne(x) x&(-x)
#define debug(x) cout << #x << " " << x << endl;

typedef vector<int> vi;
typedef pair<int, int> ii;
typedef vector<ii> vii;

const int inf = 1e9+10;

int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    #ifndef ONLINE_JUDGE
   //  freopen("in" , "r" , stdin);
   //  freopen("out" , "w" , stdout);
    #endif
    int n;
    cin >> n;
    int h[n];
    for (int i = 0; i < n; i++){
      cin >> h[i];
    }

    int dp[n];
    for (int i = 0; i < n; i++){
      dp[i] = inf;
    }
    dp[0] = 0;
    for (int i = 0; i < n; i++){
      for (int j = i+1; j <= i+2; j++){
        if (j < n)
          dp[j] = min(dp[j], dp[i]+abs(h[i]-h[j]));
      }
    }
    cout << dp[n-1] << endl;
    return 0;
 }


Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
#define pp pair<int,int>
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define rep2(i,m,n) for(int (i)=(m);(i)<(n);(i)++)
#define ll long long
#define ld long double
#define all(a) (a).begin(),(a).end()

int main() {
 string s;
  cin>>s;
  ll n=s.size();
  ll ans=0;
  ll temporaryblack=0;
 for(ll i=0;i<n;i++){
   if(s[i]=='B') temporaryblack++;
   if(s[i]=='W') ans+=temporaryblack;
}
  cout<<ans<<endl;
 return 0; 
}


Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
double a, b, c, d, e, f;
vector<double> water;
vector<double> salt;

int main() {
    cin >> a >> b >> c >> d >> e >> f;
    for(int i = 0; i <= f; ++i) {
        for(int j = 0; j <= f; ++j) {
            int insalt = c*i + d*j;
            if(insalt <= f) {
                salt.push_back(insalt);
            }
        }
    }    

    for(int i = 0; i <= f; ++i) {
        for(int j = 0; j <= f; ++j) {
            int inwater = 100 * (a*i + b*j);
            if(inwater <= f) {
                water.push_back(inwater);
            }
        }
    }

    sort(water.begin(), water.end());
    water.erase(unique(water.begin(), water.end()), water.end());
    sort(salt.begin(), salt.end());
    salt.erase(unique(salt.begin(), salt.end()), salt.end());

    int wlen = water.size();
    int slen = salt.size();

    double limit = (double)100 * e / ((double)100+e);
    double maxwater = 0.0;
    double maxsalt = 0.0;
    double maxc = 0.0;
    for(int i = 0; i < wlen; ++i) {
        for(int j = 0; j < slen; ++j) {
            if((water.at(i)+salt.at(j)) == 0) {

            }else if(water.at(i)+salt.at(j) <= f){
                double c = (double)100 * salt.at(j) / (water.at(i)+salt.at(j));
                if(c <= limit) {
                    if(maxc <= c) {
                        maxwater = water.at(i);
                        maxsalt = salt.at(j);
                        maxc = c;
                    }
                }
            }
        }
    }

    cout << maxwater+maxsalt << " " << maxsalt << endl;
}

Measured memory_bytes: 2420
n, a, b = map(int, input().split())

l = []
ans = 0

for i in range(1, n + 1):
    if len(str(i)) == 1 and a <= i <= b:
        l.append(i)
    elif len(str(i)) != 1:
        ans = sum(int(j) for j in str(i))
        if a <= ans <= b:
            l.append(i)
print(sum(l))

Measured memory_bytes: 3288
#include<stdio.h>

int mid(int, int);
int m;

int main()
{
  int i=0,l=0,r;
  int S[10000000],T,n,q,count=0;

  scanf("%d",&n);
  for(i=0; i<n; i++)
    {
      scanf("%d",&S[i]);
    }
  r=n;
  m=mid(l,r);
  
  scanf("%d",&q);
  for(i=0; i<q; i++)
    {
      scanf("%d",&T);
      
      while(l<r)
	{
	  if(S[m]==T)
	    {
	      count++;
	      
	      r=n;
	      l=0;
	      m=mid(l, r);
	     
	      
	      break;
	    }
	  else if(S[m]>T)
	    {
	  
	      r=m;
	      m=mid(l, r);
	      
	    }
	  else if(S[m]<T)
	    {
	      l=m+1;
	      m=mid(l, r);
	      
	    }
	  else if(l==m)
	    {
	      
	      r=n;
	      l=0;
	      m=mid(l, r);
	      break;
	    } 
	  
	} 
	

      r=n;
      l=0;
      m=mid(l,r);


	   
    }
  printf("%d\n",count);
  return 0;
}
  
int mid(int l, int r)
{

  m=(l+r)/2;
  return m;
}



Measured memory_bytes: 2088
n = int(input())
W = [input() for _ in range(n)]
ans = "Yes"
if len(W) != len(set(W)):
  print("No")
else:
  for i in range(n - 1):
    if W[i][-1] != W[i + 1][0]:
      ans = "No"
  print(ans)

Measured memory_bytes: 3060
#include<iostream>
#include<vector>
typedef unsigned long long ull;
using namespace std;

#define INF 0x7FFFFFFFFFFFFFFF

ull ABS(ull a,ull b)
{
  return a>b?a-b:b-a;
}

int main()
{
  ull i,j,N,K;
  cin >> N >> K;
  vector<ull> h(N),dp(N);
  for(i=0;i<N;++i)
  {
    cin >> h[i];
    dp[i]=INF;
  }
  dp[0]=0;
  for(i=0;i+1<N;++i)
  {
    for(j=1;j<=K&&i+j<N;++j)
    {
    	dp[i+j]=min(dp[i+j],dp[i]+ABS(h[i],h[i+j]));
    }
  }
  cout << dp[N-1];
  return 0;
}

Measured memory_bytes: 1792
#include <stdio.h>

int main(void) {
  int n;
  scanf("%d", &n);
  int count = 0;
  for(int i = 0;i < n;i++) {
    int a, b;
    scanf("%d%d", &a, &b);
    if(a == b) {
      count++;
    } else {
      count = 0;
    }
    if(count == 3) {
      break;
    }
  }
  printf(count == 3 ? "Yes" : "No");
  puts("");
  return 0;
}

Measured memory_bytes: 2152
class Q1052
  def doIt
    n = gets.to_i
    island = Struct.new("Island", :treasure, :bridge)
    while n > 0
      ary = Array.new
      for i in 0..n-1
        t = gets.split(" ").map{|x| x.to_i}
        is = island.new(t[0], t[1])
        ary.push is
      end
      ary.sort!{|a, b| a.bridge <=> b.bridge}
      sum = 0
      bOK = 1
      for i in 0..n-1
        sum += ary[i].treasure
        if ary[i].bridge < sum
          bOK = 0
          break
        end
      end
      if bOK == 1 then puts "Yes"
      else puts "No"
      end
      n = gets.to_i
    end
  end
end

Q1052.new.doIt

Measured memory_bytes: 5140
N, M = map(int,input().split())
A= [int(x) for x in input().split()]

threshold = sum(A) / (4*M)

gokaku = 0

for i in A:
  if i >= threshold:
    gokaku +=1

if gokaku >= M:
  print("Yes")
else:
  print("No")

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

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

using namespace std;

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

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

using ll = long long;
using ld = long double;

#define ALL(x) (x).begin(), (x).end()
template<class T>
using vc = vector<T>;
using vi = vc<int>;
using vvi = vc<vi>;

template<class T>
using va = valarray<T>;
using vad = va<ld>;

vi Read(ll n) {
    auto      v = vi(n);
    for (auto i = std::size_t(0); i < n; ++i) {
        cin >> v[i];
    }
    return v;
}

template<class T>
void Dump(const T& A) {
    REP(i, A.size() - 1) cout << A[i] << " ";
    cout << A[A.size() - 1] << "\n";
}

int main() {
    int x, y;
    cin >> x >> y;
    if (x < y) swap(x, y);

    while (y > 0){
        const auto r = x % y;
        x = y;
        y = r;
    }
    cout << x << endl;
    return 0;
}



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

#define int long long
using namespace std;
#define rep(i, n) for(int i=0;i<(n);++i)
typedef pair<int, int> pii;
const int INF = 1l << 60;
#define u_b upper_bound
#define l_b lower_bound

int N;
int A[100100];
int B[100100];

signed main() {
    cin >> N;
    rep(i, N + 1) {
        cin >> A[i];
    }
    rep(i, N) {
        cin >> B[i];
    }
    int ans = 0;
    for (int i = N - 1; i >= 0; --i) {
        ans += min(B[i], A[i + 1]);
        B[i] -= min(B[i], A[i + 1]);
        ans += min(B[i], A[i]);
        A[i] -= min(B[i], A[i]);
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 1792
// #pragma GCC target("avx2")  // CPU 処理並列化
// #pragma GCC optimize("O3")  // CPU 処理並列化
// #pragma GCC optimize("unroll-loops")  // 条件処理の呼び出しを減らす
#include<stdio.h>
#include<math.h>
#include<algorithm>
#include<queue>
#include<deque>
#include<stack>
#include<string>
#include<string.h>
#include<vector>
#include<set>
#include<map>
#include<bitset>
#include<stdlib.h>
#include<cassert>
#include<time.h>
#include<bitset>
#include<numeric>
using namespace std;
const long long mod=998244353;
const long long inf=mod*mod;
const long long d2=(mod+1)/2;
const double EPS=1e-10;
const double INF=1e+10;
const double PI=acos(-1.0);
const int C_SIZE = 3121000;
long long fact[C_SIZE];
long long finv[C_SIZE];
long long inv[C_SIZE];
long long Comb(int a,int b){
 	if(a<b||b<0)return 0;
 	return fact[a]*finv[b]%mod*finv[a-b]%mod;
}
void init_C(int n){
	fact[0]=finv[0]=inv[1]=1;
	for(int i=2;i<n;i++){
		inv[i]=(mod-(mod/i)*inv[mod%i]%mod)%mod;
	}
	for(int i=1;i<n;i++){
		fact[i]=fact[i-1]*i%mod;
		finv[i]=finv[i-1]*inv[i]%mod;
	}
}
long long pw(long long a,long long b){
	if(a<0LL)return 0;
	if(b<0LL)return 0;
	long long ret=1;
	while(b){
		if(b%2)ret=ret*a%mod;
		a=a*a%mod;
		b/=2;
	}
	return ret;
}
int ABS(int a){return max(a,-a);}
long long ABS(long long a){return max(a,-a);}
double ABS(double a){return max(a,-a);}
int sig(double r) { return (r < -EPS) ? -1 : (r > +EPS) ? +1 : 0; }
// ここから編集しろ
char in[310000];
int cur[3];
char col[5]="RGB";
int main(){
	int a;scanf("%d",&a);
	scanf("%s",in);
	long long ret=1;
	for(int i=0;i<a*3;i++){
		int t=0;
		for(int j=0;j<3;j++)if(in[i]==col[j])t=j;
		//printf("%d: %d %d %d\n",t,cur[0],cur[1],cur[2]);
		int r=0;
		for(int j=0;j<3;j++)if(cur[t]<cur[j])r++;
		if(r==0){
			;
		}else if(r==2){
			if(t==0)ret=(ret*(min(cur[1],cur[2])-cur[t]))%mod;
			if(t==1)ret=(ret*(min(cur[0],cur[2])-cur[t]))%mod;
			if(t==2)ret=(ret*(min(cur[1],cur[0])-cur[t]))%mod;
			
		}else{
			ret=(ret*(max(cur[0],max(cur[1],cur[2]))-cur[t]))%mod;
		}
		cur[t]++;
	}
	for(int i=1;i<=a;i++)ret=ret*i%mod;
	printf("%lld\n",ret);
}


Measured memory_bytes: 512
import bisect
import sys

A, B, Q = map(int,input().split())
s = tuple([-(10**18)] + list(map(int, (sys.stdin.readline() for _ in [0]*A))) + [10**18])
t = tuple([-(10**18)] + list(map(int, (sys.stdin.readline() for _ in [0]*B))) + [10**18])


def solve(s,t,x):
    ans = 10**18
    for i in range(2):
        a, b = (s, t) if i==0 else (t, s)
        posX1 = bisect.bisect_left(a,x)
        for j in range(2):
            ax = a[posX1 -j]
            posX2 = bisect.bisect_left(b,ax)
            for k in range(2):
                bx = b[posX2-k]
                ans = min(ans, abs(x-ax)+abs(bx-ax))
    return ans

for _ in range(Q):
    x = int(input())
    print(solve(s,t,x))

Measured memory_bytes: 14852
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vvvi = vector<vvi>;
using vll = vector<ll>;
using vvll = vector<vll>;
using vvvll = vector<vvll>;
using vs = vector<string>;
using pll = pair<ll, ll>;
using vp = vector<pll>;
#define rep(i, n) for (int i = 0; i < (n); i++)
#define repb(i, n) for (int i = (n-1); i >= 0; i--)
#define rea(i, a, b) for (int i = (a); i < (b); i++)
#define reab(i, a, b) for (int i = (a)-1; i >= (b); i--)
#define ALL(a) (a).begin(),(a).end()
#define SZ(x) ((int)(x).size())
#define PRINT(V) for (auto v:(V)) {cerr << v << " ";} cerr << endl
#define dump(x) cerr << #x << " : " << (x) << endl
#define dump2(x, y) cerr << "(" << #x << ", " << #y << ") = (" << x << ", " << y << ")" << endl
inline ll GCD(ll a, ll b){return b ? GCD(b, a % b) : a;}
const int MOD = 1000000007;
/* END OF TEMPLATE */

int main(){
    int n, m;
    cin >> n >> m;
    vi k(m);
    vi p(m);
    vvi s(m);
    rep(i, m){
        cin >> k[i];
        rep(j, k[i]){
            int stemp;
            cin >> stemp;
            s[i].emplace_back(stemp-1);
        }
    }
    rep(i, m){
        cin >> p[i];
    }
    int ans = 0;
    rep(i, 1<<n){
        bool valid = 1;
        rep(j, m){
            int swst = 0;
            rep(l, k[j]){
                swst += (i >> s[j][l])%2;
            }
            if(swst%2 != p[j]){
                valid = 0;
            }
        }
        if(valid) ans++;
    }
    cout << ans << endl;
}

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

int main() {
  int n;
  cin>>n;
  vector<int> h(n);
  for(int i=0;i<n;i++){
    cin>>h[i];
  }
  int cnt=0,a=0;
  for(int i=0;i<n;i++){
    if(a<=h[i]){
      cnt++;
      a=h[i];
    }
  }
  cout<<cnt<<endl;
}

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

int main(){
    int n;
    cin>>n;
    char p[n],q[n];
    for(int i=0;i<n;i++) cin>>p[i];
    for(int i=0;i<n;i++) cin>>q[i];
    int pi,qi;
    int pflg=0,qflg=0;
    int array[n];
    int index=1;
    for(int i=0;i<n;i++) array[i]=i+1;
    do{
        for(int i=0;i<n;i++){
            if(p[i]-'0'==array[i]) pflg+=1;
            else pflg=0;
            if(q[i]-'0'==array[i]) qflg+=1;
            else qflg=0;
        }
        if(pflg==n) {
            pi = index;
        }
        if(qflg==n){
            qi=index;
        }
        pflg=0;
        qflg=0;
        index++;
    }while(next_permutation(array,array+n));
    cout<<abs(qi-pi)<<endl;
}

Measured memory_bytes: 256
using System;
using System.Linq;
using System.Collections.Generic;
using static System.Console;

namespace A {
static class Extensions {
   public static int ToInt(this string str) {
      return int.Parse(str);
   }

   public static int[] readIntArr() {
      return ReadLine().Split(' ').Select(int.Parse).ToArray();
   }

   public static void Fill<T>(this List<T> a, T b) {
      for (var i = 0; i < a.Capacity; i++) {
         a.Add(b);
      }
   } 
}

class Program {
   public static void Main(string[] args) {
      var tmp = Extensions.readIntArr();
      var n = tmp[0];
      var k = tmp[1];
      var h = Extensions.readIntArr();

      var dp = new List<int>(n);
      dp.Fill(System.Int32.MaxValue); 
      dp[0] = 0;
      dp[1] = Math.Abs(h[0] - h[1]);

      for (var i = 2; i < n; i++) {
         for (var j = 1; j <= k; j++) {
            if (i - j < 0) break;
            dp[i] = Math.Min(dp[i], dp[i - j] + Math.Abs(h[i - j] - h[i]));
         }
      }

      WriteLine(dp[n - 1]);
   }
}

}


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

int main(){
    int a,b,c;
    cin >> a >> b >> c;
    if ( a+b+c>21) cout << "bust" << endl;
    else cout << "win" << endl;
    
    return 0;
}

Measured memory_bytes: 256