akhauriyash/Code-Regression huggingface dataset:
/*
[abc137] F - Polynomial Construction
*/

#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef pair<int, int> pii;
typedef pair<ll, int> pli;
typedef pair<ll, ll> pll;

const int MAX_P = 2999;
int MOD;

class gf {
public:
    int n;
    static int extgcd(int a, int b, int& x, int& y) {
        int d = a;
        if (b != 0) {
            d = extgcd(b, a % b, y, x);
            y -= (a / b) * x;
        } else {
            x = 1;
            y = 0;
        }
        return d;
    }
    static int mod_inv(int a, int m) {
        int x, y;
        extgcd(a, m, x, y);
        return (m + x) % m;
    }
    gf() : n(0) {}
    gf(int n) : n(n % MOD) {}
    gf operator+(const gf x) const { return gf((n + x.n) % MOD); }
    gf operator-(const gf x) const { return gf((n - x.n + MOD) % MOD); }
    gf operator*(const gf x) const { return gf((1LL * n * x.n) % MOD); }
    gf operator/(const gf x) const { return *this * x.inv(); }
    gf& operator+=(const gf x) { return *this = (*this + x); }
    gf& operator-=(const gf x) { return *this = (*this - x); }
    gf& operator*=(const gf x) { return *this = (*this * x); }
    gf& operator/=(const gf x) { return *this = (*this / x); }
    gf inv() const { return gf(mod_inv(n, MOD)); }
    gf pow(ll e) const {
        gf a = *this;
        gf x = 1;
        for (; e > 0; e >>= 1) {
            if (e & 1) {
                x = x * a;
            }
            a = a * a;
        }
        return x;
    }
};

int p;
int a[MAX_P];
gf c[MAX_P];
gf b[MAX_P];

void solve() {
    c[0] = 1;
    for (int i = 1; i <= p - 1; i++) {
        for (int j = i; j > 0; j--) {
            c[j] += c[j - 1];
        }
    }

    for (int i = 0; i < p; i++) {
        if (a[i] == 0) {
            continue;
        }
        b[0] += 1;
        gf pi = 1;
        for (int j = p - 1; j >= 0; j--) {
            b[j] -= c[j] * pi;
            pi *= -i;
        }
    }

    for (int i = 0; i < p; i++) {
        cout << b[i].n << " ";
    }
    cout << endl;
}

int main() {
    cin >> p;
    MOD = p;
    for (int i = 0; i < p; i++) {
        cin >> a[i];
    }

    solve();

    return 0;
}


Measured memory_bytes: 384
#include <bits/stdc++.h>
#define REP(i, n) for (long long i = 0; i < (long long)n; i++)
//#define _GLIBCXX_DEBUG
using namespace std;
using ll = long long;
using Pi = pair<int, int>;
using Pl = pair<ll, ll>;
using Vl = vector<ll>;
using vi = vector<int>;
using Graph = vector<vi>;

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  // std::cout << std::fixed << std::setprecision(15); //"for float-base
  // problem"
  int a, b;
  cin >> a >> b;
  if (a > b) {
    REP(i, a) cout << b;
  } else
    REP(i, b) cout << a;

  return 0;
}

Measured memory_bytes: 256
import itertools
n, m, q = map(int, input().split())

ql = [list(map(int, input().split())) for i in range(q)]

ans=0

for c in itertools.combinations_with_replacement(range(1, m + 1), n):
    a=0
    for j in ql:
        if c[j[1]-1] - c[j[0]-1] == j[2]:
            a += j[3]
    if ans < a:
        ans = a
print(ans)

Measured memory_bytes: 9080
#include <iostream>
#include <vector>

using namespace std;

int main() {
  int N;
  cin >> N;
  vector<int> X(N);
  int sum = 0;
  for (int i = 0; i < N; i++) {
    cin >> X[i];
    sum += X[i];
  }
  int ans = 1e6;
  const int P = (sum + N - 1) / N;
  for (int d = -1; d < 2; ++d) {
    int p = P + d;
    int tmp = 0;
    for (auto e : X) {
      tmp += (e - p) * (e - p);
    }
    ans = min(ans, tmp);
  }
  cout << ans << endl;
  return 0;
}



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

int main(){
    long long N, A, B, C, D, u, l;
    cin >> N >> A >> B >> C >> D;
    for(int i=0;i<N;i++){
        u = B + D * i - C * (N - i - 1);
        l = B + C * i - D * (N - i - 1);
        if(u >= A && l <= A){
            N = -1;
            break;
        }
    }
    if(N > 0) cout << "NO" << endl;
    else cout << "YES" << endl;

}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define IOS ios::sync_with_stdio(false);cin.tie(0);
#define fi first
#define se second
#define reset(n,k) memset((n),k,sizeof(n))
#define all(n) n.begin(),n.end()
#define pb push_back
using namespace std;
using ll=long long;
using pii=pair<int,int>;
ll cnt[10005];

int n,p;
string s;

ll power(int x,int y){
	ll mul = x;
	ll ans = 1;
	while(y){
		if(y&1)ans = ans * mul % p;
		mul= mul* mul % p;
		y>>=1;
	}
	return ans;
}

ll calc(ll now,ll idx){
	ll mul = n-idx;
	return now * power(10,mul)  % p	;
}

int main(){
	IOS;
	cin>>n>>p;
	cin>>s;
	s = " " + s;
	
	if(p!=2 && p!=5){
		ll now = 0, ans = 0;
		cnt[0] ++;
		for(int i=1;i<=n;i++){
			now = (now * 10 + (s[i]-'0')) %p;
			ll tmp = calc(now,i);
			ans += cnt[tmp];
			cnt[tmp]++;
		}
		cout<<ans<<'\n';
	}
	else if(p==2){
		ll ans = 0;
		for(int i=1;i<=n;i++){
			if((s[i]-'0')%2 == 0) ans += i;
		}
		cout<<ans<<'\n';
	}
	else{
		ll ans = 0;
		for(int i=1;i<=n;i++){
			if((s[i]-'0')%5 == 0) ans += i;
		}
		cout<<ans<<'\n';
	}


}


Measured memory_bytes: 788
PI = 3.14159265358979323846264338327950

import math
a,b,h,m = map(int,input().split())
# ~units in radians per minute
mw = (PI)/(30)
# ~units in radians per hour
hw = (PI)/(6)

ang = 2*PI*(h/12 + (m/60)/12 - m/60)
c = math.sqrt(a**2 + b**2 - 2*a*b*math.cos(ang))
# ~print(math.degrees(mrd),math.degrees(hrd),math.degrees(ang))
print(c)


Measured memory_bytes: 62100
#include <cstdio>
#include <algorithm>
using namespace std;

int main()
{
    int N, K;
    int D[10];

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

    for (int i = N;; i++)
    {
        int tmp = i;
        bool flag = true;
        while (tmp > 0)
        {
            int num = tmp % 10;
            for (int j = 0; j < K; j++)
            {
                if (num == D[j])
                {
                    flag = false;
                    break;
                }
            }

            if (flag)
            {
                tmp /= 10;
            }
            else
            {
                break;
            }
        }
        if (flag)
        {
            printf("%d\n", i);
            return 0;
        }
    }

    return 0;
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
using ll =long long int;
constexpr ll mod = 1e12;
int main()
{
	int n; cin >> n;
	priority_queue<int>q;
	vector<int>a;
	while (n--) {
		int val; cin >> val;
		q.push(val);
		a.push_back(val);
	}
	for (int i = 0; i < a.size(); ++i) {
		if (q.top() == a[i]) {
			int l = q.top(); q.pop();
			cout << q.top() << endl; q.push(l);
		}
		else cout << q.top() << endl;
	}
	return 0;
}

Measured memory_bytes: 3436
// inputに入力データ全体が入る
function Main(input) {
  
   input = input.split(" ");
  var A= parseInt(input[0], 10);
  var B= parseInt(input[1], 10);
  
  if( A >= 13){console.log(B);}
        else if (A >= 6){console.log(B /2);}
           else{console.log("0");} 
           
 
}
 
  
  //*この行以降は編集しないでください（標準入出力から一度に読み込み、Mainを呼び出します）
Main(require("fs").readFileSync("/dev/stdin", "utf8"));
  

Measured memory_bytes: 21064
#include <bits/stdc++.h>
using namespace std;
bool prime[200000];

int main(){

  for(int i=2;i*i<200000;i++)
    for(int j=2;j<200000/i&&!prime[i];j++) prime[i*j]=1;

  vector <int> n;
  for(int i=2;i<200000;i++)if(!prime[i])n.push_back(i);
					      
  int p,q;
  cin>>p>>q;
  int a=__gcd(p,q);
  p/=a,q/=a;
  
  int ans=1;
  for(int i=0;i<n.size();i++)
    if(q%n[i]==0){
      ans*=n[i];
      while(q%n[i]==0)q/=n[i];
    }
  ans*=q;
  cout << ans<<endl;
  return 0;

}

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

int N;
string S;

void solve() {
    //cout.precision(10);
    cin >> N >> S;
    S.push_back('#');
    int ans = 0;
    for(int i = 0; i + 1 < S.size(); i++) {
        if(S[i] != S[i+1]) ans++;
    }
    cout << ans << endl;
    return;
}

int main() {
    solve();
    return 0;
}


Measured memory_bytes: 3732
#include<bits/stdc++.h>
#define ll long long int
using namespace std;
int main()
{
  vector<ll>a;
  vector<ll>b;
  ll n,x[1005];
  cin>>n;
  for(ll i=0;i<n;i++)
  {
    cin>>x[i];
    a.push_back(x[i]);
  }
  ll m,y[1005];
  cin>>m;
  for(ll i=0;i<m;i++)
  {
    cin>>y[i];
    b.push_back(y[i]);
  }
  cout<<lexicographical_compare(a.begin(),a.end(),b.begin(),b.end())<<endl;
}



Measured memory_bytes: 3208
#include <iostream>
#include <sstream>
#include <iomanip>
#include <algorithm>
#include <cmath>
#include <string>
#include <vector>
#include <list>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <bitset>
#include <numeric>
#include <climits>
#include <cfloat>
using namespace std;

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

    long long sum = 0;
    for(int i=0; i<n; ++i){
        long long tmp;
        cin >> tmp;
        sum += tmp;
    }
    cout << (sum / n) << endl;

    return 0;
}

Measured memory_bytes: 0
N, K = map(int, input().split())
R, S, P = map(int, input().split())
T = input().strip()


def pon(computer, mine):
    if computer == 'r' and mine == 2: return P
    if computer == 's' and mine == 0: return R
    if computer == 'p' and mine == 1: return S
    return 0


dp = [[0 for _ in range(3)] for _ in range(N+10)]

ans = 0
for st in range(K):
    for i in range(st, N, K):
        for j in range(3):
            for k in range(3):
                if j == k:
                    continue
                if i+1-K >= 0:
                    dp[i+1][k] = max(dp[i+1][k], dp[i+1-K][j] + pon(T[i], k))
                else:
                    dp[i+1][k] = max(dp[i+1][k], pon(T[i], k))
    ans += max(dp[i+1])

print(ans)


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

ll gcd(ll a, ll b) { return b?gcd(b,a%b):a;}
ll lcm(ll a, ll b) { return b/gcd(a,b)*b;}

int main() {
  ll a, b, c, x, y;
  cin >> a >> b >> c >> x >> y;
  ll ans = LONG_LONG_MAX;
  // 制約条件に目をつける
  // 全探索で終わるなら全探索する
  for (ll i = 0; i <= 100000; i++) {
    ans = min(2 * c * i + a * max(ll(0), x-i) + b * max(ll(0), y-i), ans);
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h> 
using namespace std;
int gcd(int a, int b) 
{ 
    if (a == 0) 
        return b; 
    return gcd(b % a, a); 
} 
  

int findGCD(int arr[], int n) 
{ 
    int result = arr[0]; 
    for (int i = 1; i < n; i++) 
        result = gcd(arr[i], result); 
  
    return result; 
} 
  

int main() 
{ 
    int n,x;
    cin>>n>>x;
    int array[n];
    int arr[n];
    for (int i=0;i<n;i++){
        cin>>array[i];
    }
    sort(array,array+n);
    arr[0]=abs(x-array[0]);
    for(int i=1;i<n;i++){
        arr[i]=array[i]-array[i-1];
    }
    
    
    int l = sizeof(arr) / sizeof(arr[0]); 
    cout << findGCD(arr, l) << endl; 
    return 0; 
} 

Measured memory_bytes: 1024
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#include<map>
#include<queue>
#include<stack>
#include<cmath>	

using namespace std;

int main() {
	string s;
	cin >> s;
	map<char, int> mp;

	for (int i = 0; i < 4; ++i) {
		mp[s[i]] += 1;
	}

	for (int i = 0; i < 4; ++i) {
		if (mp[s[i]] != 2) {
			cout << "No" << endl;
			return 0;
		}
	}
	cout << "Yes" << endl;

	return 0;
}

Measured memory_bytes: 256
#include<iostream>

using namespace std;

int N,M = 0;
int A[10001] = {0};

int main(){

	cin >> N >> M;

	int sum = 0;
	for(int i = 0;i < M;i++){
		cin >> A[i];
		sum += A[i];
	}


	int answer = N - sum;

	if(answer < 0)
		cout << -1<< endl ;
	else
		cout << answer << endl;


	return 0;
}





Measured memory_bytes: 3644
def check(list, p, k):
    i = 0
    for j in range(k):
        sum = 0
        while sum+list[i] <= p:
            sum += list[i]
            i += 1
            if i == len(list):
                return i


    return i

nk = list(map(int, input().split()))
n = nk[0]
k = nk[1]

list = []
for i in range(n):
    list.append(int(input()))

max_num = 100000 * 10000

#二分探索で最大積載量の最小値を求める
left = 0
right = max_num
while left+1 < right:
    mid = int((left + right) /2)
    if check(list, mid, k) >= len(list):
        right = mid
    else:
        left = mid

print(right)



Measured memory_bytes: 9552
import itertools

N = int(input())
L_list = [int(e) for e in input().split()]

ans = 0

for Li,Lj,Lk in itertools.combinations(L_list, 3):
    if Li != Lj != Lk != Li:
        comb_L = [Li,Lj,Lk]
        comb_L.sort(reverse=False)
        longest = comb_L.pop(-1)
        if longest < sum(comb_L):
            ans += 1
            
print(ans)

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



int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout << fixed << setprecision(18);
  
  string s;
  ll a, b, c, k,ans;
  cin >> a >> b >> c >> k;
  
  //vector<ll> a(n);  rep(i, 0, n) cin >> a[i]
  if(a >= k) ans = k;
  else if(a+b >= k) ans = a;
  else ans = a-(k-a-b);
  cout << ans << "\n";
  
  //cout << (  ?"Yes" :"No") << "\n";

}

Measured memory_bytes: 3652
n=int(input())#入力を受け取る

x=n%10

if x==7:
  print("Yes")  

else:
  y = n//10

  if y%10==7:
    print("Yes")
  
  else:
    z = y//10
    if z==7:
      print("Yes")
    else:
      print("No")


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

void sort(int N, int *array){
    for(int i=0;i<N-1;i++){
        for(int j=i+1;j<N;j++){
        if(array[i]<array[j]){
            int temp = array[i];
            array[i]=array[j];
            array[j]=temp;
        }
        }
    }
    
}


int main(int argc, const char * argv[]) {
    // insert code here...
    int N ;
    cin >> N;
    int a[N];
    for(int i=0;i<N;i++){
        cin >>a[i];
    }
    sort(N,a);
    
    int sumA =0;
    int sumB=0;
    
    for(int i=0;i<N;i++){
        if(i%2==0)sumA+=a[i];
        else sumB += a[i];
    }
    
    
    cout << sumA-sumB <<endl;
    
}


Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner scanner = new Scanner(System.in);
		String string = scanner.nextLine();
		char[] letters = string.toCharArray();
		
		String ans = "No";
		for (int i = 0; i < letters.length; i++) {
			if (letters[i]=='9') {
				ans="Yes";
			}
		}

		System.out.println(ans);
		scanner.close();
	}

}


Measured memory_bytes: 21716
#include<iostream>
#include<algorithm>

#define NMAX 50000
#define MMAX 20
#define INF 100000000

using namespace std;
 
int main(void){
  std::ios_base::sync_with_stdio();

  int n,m;
  int co[MMAX];
  int dp[NMAX+1];

  cin>>n>>m;

  for(int i=0;i<m;i++) cin>>co[i];
  for(int j=0;j<=n;j++) dp[j]=INF;
  dp[0]=0;

  for(int i=0;i<=n;i++){
	  if(dp[i]!=INF){
		  for(int j=0;j<m;j++){
			  if(i+co[j]<=n){
				  dp[i+co[j]]=min(dp[i]+1,dp[i+co[j]]);
			  }
		  }
	  }
  }

  cout<<dp[n]<<endl;
  return 0;
}

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

using namespace std;

typedef pair <int, int> pi;
typedef long long LL;   

const int P = 998244353;
const int INF = 0x3f3f3f3f;
const LL INFLL = 0x3f3f3f3f3f3f3f3fll;
const int N = 1e6 + 1e5;

int n, m, inv_n;
LL a[N], b[N], c[N], S, inv_S;

inline LL ksm(LL base, LL x) {
    LL res = 1;
    while(x) {
        if(x & 1) res *= base, res %= P;
        x >>= 1, base *= base, base %= P;
    }
    return res;
}

inline void fwt_xor(LL a[], int type) {
    for(int i = 1; i < n; i <<= 1)
        for(int j = 0; j < n; j += i << 1)
            for(int k = j; k < j + i; k++)
                a[k] = (a[k] + a[k + i]) % P,
                a[k + i] = (a[k] - a[k + i] * 2 + P * 2) % P;
    if(type == -1)
        for(int i = 0; i < n; i++) a[i] = (a[i] * inv_n) % P;
}

void init() {
    int len;
    cin >> len;
    n = 1 << len;
    inv_n = ksm(n, P - 2);
    for(int i = 0; i < n; i++) scanf("%lld", &a[i]), S = (S + a[i]) % P;
    inv_S = ksm(S, P - 2);
    for(int i = 0; i < n; i++) a[i] = (a[i] * inv_S) % P;
    fwt_xor(a, 1);
    for(int i = 0; i < n; i++) b[i] = c[i] = 1;
    b[0] = 0;
    fwt_xor(b, 1), fwt_xor(c, 1);
    
    /*
    for(int i = 0; i < n; i++) {
        LL tmp = ksm((1 - a[i] + P) % P, P - 2);
        b[i] = (b[i] * tmp) % P;
        c[i] = (c[i] * tmp) % P;
    }
    fwt_xor(b, -1), fwt_xor(c, -1);
    */
    
    for(int i = 0; i < n; i++) c[i] = (c[i] - b[i] + P) % P;
    LL x = (P - b[0]) * ksm(c[0], P - 2) % P;
    for(int i = 0; i < n; i++) c[i] = (b[i] + c[i] * x) % P;
    for(int i = 0; i < n; i++) {
        LL tmp = ksm((1 - a[i] + P) % P, P - 2);
        c[i] = (c[i] * tmp) % P;
    }
    for(int i = 0; i < n; i++) b[i] = c[i];
    c[0] = 1;
    fwt_xor(b, -1), fwt_xor(c, -1);

    
    for(int i = 0; i < n; i++) c[i] = (c[i] - b[i] + P) % P;
    x = (P - b[0]) * ksm(c[0], P - 2) % P;
    for(int i = 0; i < n; i++) c[i] = (b[i] + c[i] * x) % P;
    for(int i = 0; i < n; i++) printf("%lld\n", c[i]);
}

int main() {
    init();
    return 0;
}

Measured memory_bytes: 15104
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<(n);++i)
#define FOR(i,n,j) for(int i=(j);i<(n);++i)
#define ssort(n) sort((n).begin(),(n).end())
#define rsort(n) sort((n).begin(),(n).end(),greater<int>())
#define mp make_pair
using ll=long long;
using ld=long double;
typedef pair<int,int> P;
typedef pair<P,int> COST;
#define repl(i,n) for(ll i=0;i<(n);++i)
#define Yes cout << "Yes" << endl
#define No cout << "No" << endl
#define YES cout << "YES" << endl
#define NO cout << "NO" << endl

using Graf_char=vector<vector<char>>;
using Graf_int=vector<vector<int>>;
#define MAX 10000000

int main()
{
    int n;
    cin >> n;
    vector<string> s(n);
    map<string,ll> count;
    rep(i,n)cin >> s[i];
    stack<string> st;
    rep(i,n){
        ssort(s[i]);
        if(count[s[i]]==0){
            st.push(s[i]);
        }
        count[s[i]]++;
    }
    ll ans=0;
    while(!st.empty()){
        ll num=count[st.top()];
        if(num>1){
            ans+=num*(num-1);
        }
        st.pop();
    }
    cout << ans/2 << endl;
    
}

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

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

#define rep(i, n) for (ll i = 0, xxx_rep_end = (n); i < xxx_rep_end; ++i)
#define all(x) (x).begin(), (x).end()

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

constexpr ll INF = 0x3f3f3f3f3f3f3f3fLL;
constexpr ll mod = 1000000007;

int main() {
    ll K, A, B;
    cin >> K >> A >> B;
    ll x = (A + K - 1) / K * K;

    if (x <= B) {
        cout << "OK" << endl;
    } else {
        cout << "NG" << endl;
    }
}

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

struct QuickFind{
  vector<int> r,p;
  vector<vector<int> > v;
  QuickFind(){}
  QuickFind(int size){init(size);}
  void init(int size){
    r.resize(size,0);
    p.resize(size,0);
    v.resize(size);
    for(int i=0;i<size;i++){
      r[i]=1,p[i]=i;
      v[i].resize(1,i);
    }
  }
  bool same(int x,int y){
    return p[x]==p[y];
  }
  void unite(int x,int y){
    x=p[x];y=p[y];
    if(x==y) return;
    if(r[x]<r[y]) swap(x,y);
    r[x]+=r[y];
    for(int i=0;i<(int)v[y].size();i++){
      p[v[y][i]]=x;
      v[x].push_back(v[y][i]);
    }
    v[y].clear();
  }
};
signed main(){
  int n;
  cin>>n;
  vector<int> a(n);
  for(int i=0;i<n;i++) cin>>a[i];
  vector<int> b(a);
  sort(b.begin(),b.end());
  map<int,int> p,q;
  for(int i=0;i<n;i++){
    p[a[i]]=i;
    q[b[i]]=i;
  }
  QuickFind qf(n);
  for(int i=0;i<n;i++) 
    qf.unite(i,p[b[i]]);
  //for(int i=0;i<n;i++) cout<<i<<" "<<p[b[i]]<<endl;
  int ans=0;
  for(int i=0;i<n;i++){
    int k=qf.v[i].size();
    if(qf.p[i]!=i||k==1) continue;
    int m=a[qf.v[i][0]];
    int tmp=0;
    for(int j=0;j<k;j++){
      //cout<<" "<<a[qf.v[i][j]];
      tmp+=a[qf.v[i][j]];
      m=min(m,a[qf.v[i][j]]);
    }
    //cout<<endl;
    ans+=min(tmp+m*(k-2),tmp+m+b[0]*(k+1));
  }
  cout<<ans<<endl;
  return 0;
}

Measured memory_bytes: 3328
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
#define INT(...) int __VA_ARGS__;in(__VA_ARGS__)
#define LL(...) ll __VA_ARGS__;in(__VA_ARGS__)
#define ULL(...) ull __VA_ARGS__;in(__VA_ARGS__)
#define STR(...) string __VA_ARGS__;in(__VA_ARGS__)
#define CHR(...) char __VA_ARGS__;in(__VA_ARGS__)
#define DBL(...) double __VA_ARGS__;in(__VA_ARGS__)
#define vec(type,name,...) vector<type> name(__VA_ARGS__)
#define VEC(type,name,size) vector<type> name(size);in(name)
#define vv(type,name,h,...) vector<vector<type>>name(h,vector<type>(__VA_ARGS__))
#define VV(type,name,h,...) vector<vector<type>>name(h,vector<type>(__VA_ARGS__));in(name)
#define vvv(type,name,h,w,...) vector<vector<vector<type>>>name(h,vector<vector<type>>(w,vector<type>(__VA_ARGS__)))
inline int scan(){ return getchar(); }
inline void scan(int &a){ scanf("%d", &a); }
inline void scan(unsigned &a){ scanf("%u", &a); }
inline void scan(long &a){ scanf("%ld", &a); }
inline void scan(long long &a){ scanf("%lld", &a); }
inline void scan(unsigned long long &a){ scanf("%llu", &a); }
inline void scan(char &a){ cin >> a; }
inline void scan(float &a){ scanf("%f", &a); }
inline void scan(double &a){ scanf("%lf", &a); }
inline void scan(long double &a){ scanf("%Lf", &a); }
inline void scan(vector<bool> &vec){ for(unsigned i = 0; i < vec.size(); i++) { int a; scan(a); vec[i] = a; } }
inline void scan(string &a){ cin >> a; }
template<class T> inline void scan(vector<T> &vec);
template<class T, size_t size> inline void scan(array<T, size> &vec);
template<class T, class L> inline void scan(pair<T, L> &p);
template<class T, size_t size> inline void scan(T (&vec)[size]);
template<class T> inline void scan(vector<T> &vec){ for(auto &i : vec) scan(i); }
template<class T, size_t size> inline void scan(array<T, size> &vec){ for(auto &i : vec) scan(i); }
template<class T, class L> inline void scan(pair<T, L> &p){ scan(p.first); scan(p.second); }
template<class T, size_t size> inline void scan(T (&vec)[size]){ for(auto &i : vec) scan(i); }
template<class T> inline void scan(T &a){ cin>>a; }
inline void in(){}
template <class Head, class... Tail> inline void in(Head &head, Tail&... tail){ scan(head); in(tail...); }
inline constexpr ll gcd(ll a,ll b){if(!a||!b)return 0;while(b){ll c=b;b=a%b;a=c;}return a;}
inline constexpr ll lcm(ll a,ll b){if(!a||!b)return 0;return a*b/gcd(a,b);}
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
using Graph = vector<vector<int>>;
/* 4方向への隣接頂点への移動を表すベクトル */
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};

const long long INF = 1LL << 60;
int main(){
    INT(N);
    INT(K);
    vec(int,v,N);
    for(int i = 0; i < K; i++){
        INT(d);
        for(int j = 0; j < d; j++){
            int l = 0;
            cin >> l;
            v[l-1]++;
        }
    }
    int ans = 0;
    for(int i = 0; i < N; i++){
        if(v[i] == 0){
            ans++;
        }
    }
    
    cout << ans << endl;
}

Measured memory_bytes: 3704
#include <stdio.h>

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

	int ans = 0;
	if (a != b && b != c && c != a)
		ans = 3;
	else if (a == b && b == c && c == a)
		ans = 1;
	else
		ans = 2;

	printf("%d\n", ans);
	return 0;
}


Measured memory_bytes: 128
#include <iostream>
#include <vector>
#include <algorithm>
#include <queue>
#include <cstring>
#include <iomanip>
#include <unordered_map>
#include <string>
#include <unordered_set>
using namespace std;
typedef long long ll;
ll x;
int main() {
    ll curr = 100;
    int cnt = 0;
    cin >> x;
    while(curr < x) {
        curr += curr / 100;
        cnt ++;
    }
    cout << cnt << endl;
    return 0;
}

Measured memory_bytes: 3632
h, w = map(int, input().split())

sss = [input() for _ in range(h)]

def f(sss, i, j):
    if sss[i][j] == '.':
        return True
    for v in (-1, 1):
        if i+v < 0 or h <= i+v:
            continue
        if sss[i+v][j] == '#':
            return True
    for u in (-1, 1):
        if j+u < 0 or w <= j+u:
            continue
        if sss[i][j+u] == '#':
            return True
    return False

def solve(sss):
    for i in range(h):
        for j in range(w):
            if not f(sss, i, j):
                return False
    return True

print("Yes" if solve(sss) else "No")


Measured memory_bytes: 3064
#include <bits/stdc++.h>
#define REP(i, n) for(int i = 0;i < n;i++)
#define VSORT(v) sort(v.begin(), v.end())
#define VRSORT(v) sort(v.rbegin(), v.rend())
#define ll long long
using namespace std;
typedef pair<int, int> P;
typedef pair<ll, ll> LP;
typedef pair<int, P> PP;
typedef pair<ll, LP> LPP;
typedef vector<unsigned int>vec;
typedef vector<vec> mat;
typedef vector<vector<int>> Graph;

const int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1};
const int dy[8] = {0, 1, 0, -1, 1, 1, -1, -1};
const int INF = 1000000000;
const ll LINF = 1000000000000000000;//1e18
const ll  MOD = 1000000007;
const double PI = acos(-1.0);
const double EPS = 1e-10;

template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
template<class T> inline void add(T &a, T b){a = ((a+b) % MOD + MOD) % MOD;};


int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll N, K, Q;
    cin >> N >> K >> Q;
    vector<ll> A(Q);
    map<ll,ll> mp;
    REP(i,N) mp[i] = 0;
    REP(i,Q){
        cin >> A[i];
        --A[i];
        mp[A[i]]++;
    }
    for(auto x : mp){
        if(K - (Q - x.second) > 0) cout << "Yes" << endl;
        else cout << "No" << endl;
    }
}


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


using namespace std;

const int MAXN = 52;
const int MAXA = 50;

long long dp[MAXN][MAXN][(MAXA+1)*MAXN] = {0};
int x[MAXN] = {0};
int N,A;

void solve(){
	cin>>N>>A;
	for (int i=1;i<=N;i++){
		cin>>x[i];
	}
	for (int i=0;i<=N;i++)
		dp[i][0][0] = 1;
	for (int i=1;i<=N;i++){
		for (int k=1;k<=i;k++){
			for (int j=0;j<x[i];j++)
				dp[i][k][j] = dp[i-1][k][j];
			for (int j=x[i];j<=MAXA*i;j++){
				dp[i][k][j] = dp[i-1][k][j]+dp[i-1][k-1][j-x[i]];
			}
		}
	}
	long long rSum = 0;
	for (int k=1;k<=N;k++){
		rSum+=dp[N][k][A*k];
	}
	cout<<rSum<<endl;
//	cout<<dp[4][3][24]<<endl;
}


int main(){
//	freopen("in.txt","r",stdin);
	std::ios::sync_with_stdio(false);

//	int TestCase;
//	cin>>TestCase;
//	for (int i=0;i<TestCase;i++){
		solve();
//	}

	return 0;
}


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

#define INF_LL (int64)1e18
#define INF (int32)1e9
#define REP(i, n) for(int64 i = 0;i < (n);i++)
#define FOR(i, a, b) for(int64 i = (a);i < (b);i++)
#define all(x) x.begin(),x.end()
#define fs first
#define sc second

using int32 = int_fast32_t;
using uint32 = uint_fast32_t;
using int64 = int_fast64_t;
using uint64 = uint_fast64_t;
using PII = pair<int32, int32>;
using PLL = pair<int64, int64>;

const double eps = 1e-10;

template<typename A, typename B>inline void chmin(A &a, B b){if(a > b) a = b;}
template<typename A, typename B>inline void chmax(A &a, B b){if(a < b) a = b;}

int64 exp(string&, int32&);
int64 term(string&, int32&);
int64 fact(string&, int32&);
int64 number(string&, int32&);

int64 exp(string& s, int32& p){
	int64 ret = term(s, p);
	while(p < s.size()){
		if(s[p] == '+'){
			p++;
			ret += term(s, p);
		}else if(s[p] == '-'){
			p++;
			ret -= term(s, p);
		}else{
			break;
		}
	}
	return ret;
}

int64 term(string& s, int32& p){
	int64 ret = fact(s, p);
	while(p < s.size()){
		if(s[p] == '*'){
			p++;
			ret *= fact(s, p);
		}else if(s[p] == '/'){
			p++;
			ret /= fact(s, p);
		}else{
			break;
		}
	}
	return ret;
}

int64 fact(string& s, int32& p){
	int64 ret = 0;
	if(s[p] == '('){
		p++;
		ret = exp(s, p);
		p++;
	}else{
		ret = number(s, p);
	}
	return ret;
}

int64 number(string& s, int32& p){
	int64 ret = 0;
	while(isdigit(s[p])){
		ret = ret*10+s[p]-'0';
		p++;
	}
	return ret;
}
int main(void){
	int32 N;
	cin >> N;

	REP(i, N){
		string s;
		int32 p = 0;
		cin >> s;
		cout << exp(s, p) << endl;
	}
}


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

#define rep(i, n) for (int i = 0; i < int(n); i++)
#define rrep(i, n) for (int i = int(n) - 1; i >= 0; i--)
#define reps(i, n) for (int i = 1; i <= int(n); i++)
#define rreps(i, n) for (int i = int(n); i >= 1; i--)
#define repc(i, n) for (int i = 0; i <= int(n); i++)
#define rrepc(i, n) for (int i = int(n); i >= 0; i--)
#define repi(i, a, b) for (int i = int(a); i < int(b); i++)
#define repic(i, a, b) for (int i = int(a); i <= int(b); i++)
#define all(a) (a).begin(), (a).end()
#define bit32(x) (1 << (x))
#define bit64(x) (1ll << (x))
#define sz(v) ((int) v.size())

using namespace std;

using i64 = long long;
using f80 = long double;
using vi32 = vector<int>;
using vi64 = vector<i64>;
using vf80 = vector<f80>;
using vstr = vector<string>;

void yes() { cout << "Yes" << endl; exit(0); }
void no() { cout << "No" << endl; exit(0); }
template <typename T> class pqasc : public priority_queue<T, vector<T>, greater<T>> {};
template <typename T> class pqdesc : public priority_queue<T, vector<T>, less<T>> {};
template <typename T> void amax(T &x, T y) { x = max(x, y); }
template <typename T> void amin(T &x, T y) { x = min(x, y); }
template <typename T> T exp(T x, i64 n, T e = 1) { T r = e; while (n > 0) { if (n & 1) r *= x; x *= x; n >>= 1; } return r; }
template <typename T> istream& operator>>(istream &is, vector<T> &v) { for (auto &x : v) is >> x; return is; }
template <typename T> ostream& operator<<(ostream &os, vector<T> &v) { rep(i, v.size()) { if (i) os << ' '; os << v[i]; } return os; }
void solve(); int main() { ios::sync_with_stdio(0); cin.tie(0); cout << fixed << setprecision(16); solve(); return 0; }

// http://koturn.hatenablog.com/entry/2018/08/01/010000
template <typename T, typename U>
vector<U> make_vector(T&& n, U&& val) {
  return vector<U>(forward<T>(n), forward<U>(val));
}
template <typename T, typename... Args>
decltype(auto) make_vector(T&& n, Args&&... args) {
  return vector<decltype(make_vector(forward<Args>(args)...))>(forward<T>(n), make_vector(forward<Args>(args)...));
}

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

void solve() {
  string s;
  cin >> s;
  int n = sz(s);
  vi32 xorsum(n + 1);
  rep(i, n) {
    int bit = bit32(s[i] - 'a');
    xorsum[i + 1] = xorsum[i] ^ bit;
  }
  map<int, int> mins;
  mins[0] = 0;
  rep(i, n) {
    int x = xorsum[i + 1];
    int ans = INF;
    if (mins.count(x)) {
      amin(ans, mins[x] + 1);
    }
    rep(j, 26) {
      int px = x ^ bit32(j);
      if (mins.count(px)) {
        amin(ans, mins[px] + 1);
      }
    }
    if (mins.count(x)) {
      amin(mins[x], ans);
    } else {
      mins[x] = ans;
    }
    if (i == n - 1) {
      cout << ans << endl;
    }
  }
}


Measured memory_bytes: 13536
#include<iostream>
#include<string>
#include<cstdio>
#include<algorithm>
#include<cstdlib>
#include<cmath>
#include<vector>
#include<utility>
#include<queue>
#include<stack>
#include<set>
#include<map>
#include<unordered_set>
#include<unordered_map>
#include<bitset>
using namespace std;
#define INF 2000000007
#define LINF 100000000000000007
#define MOD 1000000007
#define int long long
#define rep(i,n) for(int i=0;i<n;i++)
#define repb(i, n) for (int i = n - 1; i >= 0; i--)
//#define MODE 1
#ifdef MODE
#define DEB(X) cout<< #X <<": "<<X<<" ";
#define ARDEB(i,X) cout<< #X <<"["<<i<<"]: "<<X[i]<<" ";
#define END cout<<endl;
#else
#define DEB(X) {}
#define ARDEB(i,X) {}
#define END {}
#endif
//typedef long long int ll;
typedef pair<int,int> P;
struct edge{int to,cost;};
int ceil2(int a,int b){if(a%b){return a/b+1;}else{return a/b;}}
int n,k,ans;
signed main(){
	int d;
	cin>>n>>k>>d;
	cout<<k/d-(n-1)/d<<endl;
	
}

Measured memory_bytes: 3600
#include <bits/stdc++.h>
using namespace std;
int main(int argc, char const *argv[])
{
    int n, ans = 0;
    cin >> n;
    vector<int> a(n);
    for (int i = 0; i < n; ++i)
    {
        cin >> a[i];
    }
    sort(a.begin(), a.end());
    for (int i = 0; i < n; ++i)
    {
        for (int j = i + 1; j < n; ++j)
        {
            for (int k = j + 1; k < n; ++k)
            {
                if (a[i] != a[j] && a[j] != a[k] && a[k] != a[i] && a[k] < a[i] + a[j])
                    ans ++;
            }
        }
    }
    cout << ans << '\n';
    return 0;
}

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

int main() {
  long long a, b, k;
  cin >> a >> b >> k;
  

  a = a-k;
  if(a<0){
      b=b+a;
      a=0;
  }
  if(b<0){
      b=0;
  }
  cout << a << ' ' << b << endl;
  
  
}

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

typedef long long ll;
typedef long double ld;
typedef int32_t i32;

#define int long long
#define mp make_pair
#define ff first
#define ss second
#define pb push_back
#define pf push_front

#define FOR(i,a,b) for(ll i=a;i<b;i++)
#define RFOR(i,a,b) for(ll i=a;i>=b;i--)
#define FILL(a,b,c) for(ll i=0;i<c;i++) a[i]=b;

#define sz(v) ((int)(v).size())
#define all(v) (v).begin(), (v).end()
#define allr(v) (v).rbegin(), (v).rend()

#define endl "\n"
#define setpri(x) setprecision(x)
#define vp(x) cout<<#x<<" : "<< (x)<<" | "
#define yes cout<<"YES"<<endl
#define no cout<<"NO"<<endl
#define forf(i,a,b) for(int i=a;i<b;i++)

#define INF 1e17+4
#define MINF 
#define MAX_INT 100000
#define MOD 1000000007
ll mod(ll n) { n %= MOD; if (n < 0) return n + MOD; else return n;}
// vector<int> adj[1000002];
// int vis[1000002],dep[1000002],siz[1000002];

// void dfs(ll cur,ll par)
// {
//     vis[cur]=1;siz[cur]=1;
//     for(auto x:adj[cur])
//     {
//         if(vis[x]!=1)
//         {
//             dep[x]=dep[cur]+1;
//             dfs(x,cur);
//             siz[cur]+=siz[x];
//         }    
//     }
// }

// bool sortfunc(const pair<int,int> &a, const pair<int,int> &b) 
// { 
//     return ;
// }


void solve()
{
    int ans=0,a,b,x;
    cin>>a>>b>>x;
    x=min(x,b-1);
    cout<<floor((ld)(a*x)/b);
    
    // cout<<ans;
}



signed main()
{
    FAST;
    
    // ll t;cin>>t;while(t--)
        solve();
 
    return 0;
}

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

#define rep(i, n) for(int i = 0; i<(n); i++)
#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)
using namespace std;
typedef long long ll;

int main() {
    int N;
    cin >> N;
    set<int> se; // 3200以下で登場する色の種類数
    int over_num = 0; // 3200以上の人数

    rep(i, N) {
        int a;
        cin >> a;
        if (a >= 3200) {
            over_num++;
        } else {
            se.insert(a / 400);
        }
    }

    int max = se.size() + over_num;
    int min = se.size();
    if (se.size() == 0) min = 1;

    cout << min << " " << max << endl;
}

Measured memory_bytes: 768
#include<bits/stdc++.h>
using namespace std;
int p[100001];
int main()
{
    int n, k, q;
    cin >> n >> k >> q;
    for(int i = 0; i < q; i++)
    {
        int pos; cin >> pos;
        p[pos]++;
    }
    for(int i = 1; i <= n; i++)
    {
        if(p[i]+k-q > 0) cout << "Yes" << endl;
        else cout << "No" << endl;
    }
}


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

using namespace std;

typedef long long ll;

int main()
{
    int n, W;

    while (cin >> n >> W) {
        int w[n + 5], v[n + 5];

        for (int i = 1; i <= n; i ++) cin >> w[i] >> v[i];

        ll dp[n + 5][W + 5];


        memset(dp, 0, sizeof dp);

        for (int i = 1; i <= n; i++) {
            for (int j = 0; j <= W; j++) {
                if (j - w[i] >= 0) {
                    dp[i][j] = max(dp[i][j], (ll) dp[i - 1][j - w[i]] + v[i]);
                }
                dp[i][j] = max(dp[i][j], (ll) dp[i - 1][j]);
            }
        }

        cout << dp[n][W] << endl;

    }
    return 0;
}


Measured memory_bytes: 82304
#include <stdio.h>

int main(void){
    int a,b,x;
    scanf("%d %d %d",&a,&b,&x);
    if(a > x){
        printf("NO\n");
    }
    else if(a==x){
        printf("YES\n");
    }
    else{
        if((a+b)>x){
            printf("YES\n");
        }else{
            printf("NO\n");
        }
    }
    return 0;
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
#pragma GCC optimize("unroll-loops,no-stack-protector")
#pragma GCC target("sse,sse2,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#define watch(x) cout << (#x) << " is " << (x) << endl

typedef long long ll;
typedef long double ld;
using namespace std;

const int MOD = 1e9 + 7;

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int a;
    string s;
    cin >> a >> s;
    if(a >= 3200)
    {
        cout << s;
    }
    else
    {
        cout << "red";
    }

    return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<map>
#include<queue>
using namespace std;

const int INF = 1<<29;
int main(){
    int n;
    while(cin >> n, n){
        map<string, int> enc;
        vector<vector<int>> path(200, vector<int>(200, INF));
        int cnt = 0;
        string x, a, b, c;
        for(int i = 0; i < n; i++){
            cin >> x >> a >> x >> c >> b;
            int val = stoi(c.substr(3));
            if(enc.count(a) == 0)   enc[a] = cnt++;
            if(enc.count(b) == 0)   enc[b] = cnt++;
            path[enc[a]][enc[b]] = val;
            path[enc[b]][enc[a]] = -val;
        }
        // run dijkstra from all vertexes
        bool valid = true;
        for(int i = 0; i < cnt && valid; i++){
            vector<int> dp(cnt, INF);
            dp[i] = 0;
            queue<int> q;
            q.push(i);
            while(valid && !q.empty()){
                int pos = q.front(); q.pop();
                for(int j = 0; j < cnt; j++){
                    if(path[pos][j] == INF)   continue;
                    if(dp[j] == INF){
                        dp[j] = dp[pos]+path[pos][j];
                        q.push(j);
                    }else if(dp[pos]+path[pos][j] != dp[j]){
                        valid = false;
                        break;
                    }
                }
            }
        }
        cout << (valid ? "Yes" : "No") << endl;
    }
    return 0;
}


Measured memory_bytes: 3336
#include<cstdio>
#include<algorithm>
#include<cstring>
#include<vector>
using namespace std;
int main()
{
	int q, w, e, r;
	int dap = 0;
	scanf("%d %d %d %d", &q, &w, &e, &r);
	for (int i = 0; i <= r; i++) {
		for (int y = 0; y <= r; y++) {
			int x = q * i + y * w;
			if (x > r)continue;
			if ((r - x) % e == 0)dap++;
		}
	}
	printf("%d\n", dap);
}

Measured memory_bytes: 128
use std::io::{self};

fn main() {
    let k: i32 = read_line().parse().unwrap();
    println!("{}", format!("{}", solve(k)));
}

fn solve(n: i32) -> i32 {
    let e = get_even_count(n);
    return e * (n - e);
}

fn get_even_count(n: i32) -> i32 {
    n / 2
}

fn read_line() -> String {
    let mut s = String::new();
    io::stdin().read_line(&mut s).unwrap();
    return s.trim_right().to_owned();
}

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

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


Measured memory_bytes: 256
type tree = Nil | Node of int * tree * tree

let create () = Nil

let insert x t =
  let rec doit = function
    | Nil -> Node (x, Nil, Nil)
    | Node (y, l, r) when x < y -> Node (y, doit l, r)
    | Node (y, l, r) -> Node (y, l, doit r) in
  doit t

let preorder f t =
  let rec doit = function
    | Nil -> ()
    | Node (x, l, r) -> f x; doit l; doit r in
  doit t

let inorder f t =
  let rec doit = function
    | Nil -> ()
    | Node (x, l, r) -> doit l; f x; doit r in
  doit t

let print t =
  let f e = print_string " "; print_int e in
  inorder f t;
  print_newline ();
  preorder f t;
  print_newline ()

let split_on_char sep s =
  let open String in
  let r = ref [] in
  let j = ref (length s) in
  for i = length s - 1 downto 0 do
    if get s i = sep then begin
      r := sub s (i + 1) (!j - i - 1) :: !r;
      j := i
    end
  done;
  sub s 0 !j :: !r

let () =
  let m = read_int () in
  let rec read i t =
    if i < m then
      match split_on_char ' ' (read_line ()) with
      | ["insert"; n] -> read (i + 1) (insert (int_of_string n) t)
      | _ -> print t; read (i + 1) t in
  read 0 (create ())

Measured memory_bytes: 31784
#include<bits/stdc++.h>
#define ll long long
#define mod 1000000007
using namespace std;

int candies(vector<int>& v,int n,int k){
    ll dp[n+2][k+2];

    for(int j=0;j<=k;j++){
        dp[1][j] = (j>v[1]) ? 0 : 1; 
    }

    for(int i=2;i<=n;i++){
        for(int j=0;j<=k;j++){
            if(j==0){
                dp[i][j] = dp[i-1][j];
            }
            else{
                dp[i][j] = (mod + dp[i][j-1] + dp[i-1][j] - ((j-1-v[i]>=0) ? dp[i-1][j-1-v[i]] : 0)) % mod;
            }
        }
    }
    return dp[n][k];
}

int main(){
    int n,k;
    cin>>n>>k;
    vector<int> v(n+1);
    for(int i=1;i<=n;i++){
        cin>>v[i];
    }
    cout<<candies(v,n,k);
    return 0;
}

Measured memory_bytes: 78592
#include<iostream>
#include<algorithm>
#include<cstdio>

using namespace std;

int v[1000000];

int getInt(){
  int ret = 0,c;
  c = getchar();
  while(!isdigit(c)) c = getchar();
  while(isdigit(c)){
    ret *= 10;
    ret += c - '0';
    c = getchar();
  }
  return ret;
}

int main(){
  while(int n = getInt()){
    int ans = -1;

    for(int i = 0; i < n; i++)
      v[i] = getInt();

    sort(v, v + n);

    int cnt = 0;
    int prev = -1;
    const int n2 = n / 2;

    for(int i = 0; i < n; i++){
      if(prev == v[i]){
	cnt++;
      }else{
	if(cnt > n2){
	  ans = prev;
	  break;
	}
	prev = v[i];
	cnt = 1;
      }
    }
    if(cnt > n2)
      ans = prev;

    if(ans == -1)
      puts("NO COLOR");
    else
      printf("%d\n", ans);
  }
  return 0;
}

Measured memory_bytes: 4744
#include<iostream>
#include<algorithm>
#include<map>
#include<vector>
#define int long long
using namespace std;
int32_t main()
{
 int n;
 cin >> n;
 int arr[n];
 int sum=0;
map<int,int> cnt;



 for(int i=0; i<n; i++)
 {
     cin >> arr[i];
     cnt[arr[i]]++;
     sum+=arr[i];

 }
 int k;
 cin >> k;
 while(k--)
 { int a,b;
 cin >> a >> b;
int x=cnt[a];
sum=sum+(x*(b-a));
cnt[a]=0;
cnt[b]+=x;
cout << sum << endl;
 }
 return 0;
 }


Measured memory_bytes: 9720
using System;

public class hello
{
    public static void Main()
    {
        var n = int.Parse(Console.ReadLine().Trim());
        var atotal = 0;
        var btotal = 0;
        for (int i = 0; i < n; i++)
        {
            string[] line = Console.ReadLine().Trim().Split(' ');
            var a = line[0];
            var b = line[1];
            if (a.CompareTo(b) > 0) atotal += 3;
            else if (a.CompareTo(b) ==0)
            {
                atotal += 1;
                btotal += 1;
            }
            else btotal += 3;
        }
        Console.WriteLine("{0} {1}", atotal, btotal);
    }
}

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

same = [a1 == a2 for a1, a2 in zip(a[:-1], a[1:])] + [False]
tmp = 0
ans = 0
for s in same:
  if s:
    tmp += 1    
  else:
    ans += (tmp + 1) // 2
    tmp = 0
print(ans)

Measured memory_bytes: 3188
#include <iostream>
#include <algorithm>
#include <vector>
#include <unordered_map>
#include <unordered_set>
#include <set>
#include <queue>
#include <cmath>
#include <cstdio>

using namespace std;

int main(){
    int n, k; cin >> n >> k;
    vector<int> mods(k, n/k);
    for(int i=0; i<n%k; ++i){
        ++mods[i+1];
    }
    long long ans=0;
    for(int i=0; i<k; ++i){
        if(i*2%k==0){
            long long m=mods[i];
            ans+=m*m*m;
        }
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 1024
//============================================================================
// Name        : (^o^).cpp
// Author      :
// Version     :
// Copyright   : Your copyright notice
// Description : Hello World in C++, Ansi-style
//============================================================================

#include<iostream>
#include<stdio.h>
using namespace std;

int main(){
    int a,b,t,m;
    t=0;
    m=0;
    while(1)
    {
    cin>>a>>b;
    if(a==0&&b==0){
    	return 0;
    }
    while (1){
    	cout<<"#";
    	t++;
    	if(t==b){
    		cout<<endl;
    		t=0;
    		m++;
    	}if(m==a){
    		m=0;
    		break;
    	}
    	}
    	cout<<endl;}
	return 0;
}



Measured memory_bytes: 3100
object Main{
  def main(args : Array[String]): Unit ={
    // do something
    val k : SubMain = new SubMain
    k.solve
  }
}

class SubMain{
  var n : Int = 0
  var as : Array[Int] = Array.empty
  def getN: Unit ={
    n = scala.io.StdIn.readLine().toInt
  }
  def getDatas: Unit ={
    as = scala.io.StdIn.readLine().split(' ').map(_.toInt)
  }
  def subsolve: Int ={
    val s : Int = as.sum
    val tmpAs = as.map(i => math.abs(i * n - s))
    tmpAs.zipWithIndex.min._2
  }
  def solve: Unit ={
    getN
    getDatas
    val res = subsolve
    println(res)
  }
}

Measured memory_bytes: 25552
pub fn cc_intersect((p1, r1): (Point, f64), (p2, r2): (Point, f64)) -> Vec<Point> {
    let dist = (p1 - p2).abs();
    if dist > r1 + r2 {
        return Vec::new();
    }

    let rc = (dist * dist + r1 * r1 - r2 * r2) / (2. * dist);
    let rs = (r1 * r1 - rc * rc).sqrt();
    let diff = (p2 - p1) / dist;
    vec![p1 + diff * Point(rc, rs), p1 + diff * Point(rc, -rs)]
}

#[derive(Copy, Clone)]
pub struct Point(f64, f64);

impl Point {
    fn abs(self) -> f64 {
        let x = self.0;
        let y = self.1;
        (x * x + y * y).sqrt()
    }
}

impl ::std::ops::Add<Point> for Point {
    type Output = Point;
    fn add(self, rhs: Point) -> Point {
        Point(self.0 + rhs.0, self.1 + rhs.1)
    }
}

impl ::std::ops::Sub<Point> for Point {
    type Output = Point;
    fn sub(self, rhs: Point) -> Point {
        Point(self.0 - rhs.0, self.1 - rhs.1)
    }
}

impl ::std::ops::Div<f64> for Point {
    type Output = Point;
    fn div(self, rhs: f64) -> Point {
        Point(self.0 / rhs, self.1 / rhs)
    }
}

impl ::std::ops::Mul<Point> for Point {
    type Output = Point;
    fn mul(self, rhs: Point) -> Point {
        let Point(x1, y1) = self;
        let Point(x2, y2) = rhs;
        Point(x1 * x2 - y1 * y2, x1 * y2 + y1 * x2)
    }
}

fn main() {
    let (r, w) = (std::io::stdin(), std::io::stdout());
    let mut sc = IO::new(r.lock(), w.lock());
    let c1x: f64 = sc.read();
    let c1y: f64 = sc.read();
    let c1r: f64 = sc.read();
    let c2x: f64 = sc.read();
    let c2y: f64 = sc.read();
    let c2r: f64 = sc.read();

    let mut points = cc_intersect((Point(c1x, c1y), c1r), (Point(c2x, c2y), c2r))
        .into_iter()
        .map(|Point(x, y)| (x, y))
        .collect::<Vec<_>>();
    if points[0] > points[1] {
        points.swap(0, 1);
    }
    println!(
        "{} {} {} {}",
        points[0].0, points[0].1, points[1].0, points[1].1
    );
}

pub struct IO<R, W: std::io::Write>(R, std::io::BufWriter<W>);

impl<R: std::io::Read, W: std::io::Write> IO<R, W> {
    pub fn new(r: R, w: W) -> IO<R, W> {
        IO(r, std::io::BufWriter::new(w))
    }
    pub fn write<S: std::ops::Deref<Target = str>>(&mut self, s: S) {
        use std::io::Write;
        self.1.write(s.as_bytes()).unwrap();
    }
    pub fn read<T: std::str::FromStr>(&mut self) -> T {
        use std::io::Read;
        let buf = self
            .0
            .by_ref()
            .bytes()
            .map(|b| b.unwrap())
            .skip_while(|&b| b == b' ' || b == b'\n' || b == b'\r' || b == b'\t')
            .take_while(|&b| b != b' ' && b != b'\n' && b != b'\r' && b != b'\t')
            .collect::<Vec<_>>();
        unsafe { std::str::from_utf8_unchecked(&buf) }
            .parse()
            .ok()
            .expect("Parse error.")
    }
    pub fn vec<T: std::str::FromStr>(&mut self, n: usize) -> Vec<T> {
        (0..n).map(|_| self.read()).collect()
    }
    pub fn chars(&mut self) -> Vec<char> {
        self.read::<String>().chars().collect()
    }
}



Measured memory_bytes: 5088