akhauriyash/Code-Regression huggingface dataset:
let rec split_by f = function
  | [] -> ([],[])
  | hd :: tl -> if f hd then 
                  let (rl, wl) = split_by f tl in (hd :: rl, wl)
                else ([], hd :: tl)
       
let rec group_by f = function
  | [] -> []
  | hd :: tl -> let (rl, wl) = split_by (f hd) tl in (hd :: rl) :: group_by f wl


let solve bl al = 
  let trl lst = List.map (fun x -> (fst (List.hd x), List.length x)) @@ group_by (fun (x1, y1) (x2, y2) -> x1 = x2) @@ List.sort (fun (x1, y1) (x2, y2) -> compare x1 x2) lst in
  let rec iter xs ys = 
    match (xs, ys) with
    | ((xi, xn)::xt, (yi, yn)::yt) -> if xi = yi then (xi, xn + yn) :: iter xt yt
                                      else if xi > yi then iter xs yt else iter xt ys
    | _ -> [] in
  let bl' = trl bl in
  let al' = trl al in
  let rst = iter bl' al' in
  List.iter (fun (x, y) -> Printf.printf "%d %d\n" x y) rst

let rec read1 () =
  let s = read_line () in
  if s = "" then []
  else let (x, y) = Scanf.sscanf s "%d,%d" (fun x y -> (x, y)) in
       (x, y) :: read1 ()

let rec read2 () =
  try
    let s = read_line () in
    let (x, y) = Scanf.sscanf s "%d,%d" (fun x y -> (x, y)) in
    (x, y) :: read2 ()
  with
    End_of_file -> []
                  
let _ = 
  let bl = read1 () in
  let al = read2 () in
  solve bl al

Measured memory_bytes: 2344
#define _USE_MATH_DEFINES
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>

using namespace std;

#define MAX(x,y) (x>y?x:y)
#define MIN(x,y) (x<y?x:y)
#define ABS(x) (x>0?x:-(x))
#define INF 2147483647
#define LLINF 9223372036854775807
#define MOD 1000000007

typedef long long int lli;

void swap(int* a, int* b)
{
    int tmp;
    tmp = *a;
    *a = *b;
    *b = tmp;
}

void ll_swap(lli* a, lli* b)
{
    lli tmp;
    tmp = *a;
    *a = *b;
    *b = tmp;
}

int gcd(int a, int b)
{
    if (a < b)
        swap(&a, &b);

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

int lcm(int a, int b)
{
    return a * b / gcd(a, b);
}

long power(long x, int n) {
    long ans = 1;
    while (n > 0) {
        if ((n & 1) == 1) {
            ans = ans * x;
        }
        x = x * x;
        n >>= 1;
    }
    return ans;
}

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


lli comb(lli n, lli r)
{
    if (n == 0)
        return 0;

    if (r == 0 || r == n)
        return (1);
    else if (r == 1)
        return (n);
    return (comb(n - 1, r - 1) + comb(n - 1, r));
}

/*
#define MAX 100000
long long fac[MAX], finv[MAX], inv[MAX];
// テーブルを作る前処理
void COMinit() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (int i = 2; i < MAX; i++) {
        fac[i] = fac[i - 1] * i % MOD;
        inv[i] = MOD - inv[MOD % i] * (MOD / i) % MOD;
        finv[i] = finv[i - 1] * inv[i] % MOD;
    }
}
// 二項係数計算
long long COM(int n, int k) {
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}
*/


int binary_search(int* p, int n, int key,int num)
{
    int low, high, middle;

    low = 0;
    high = n - 1;

    while (low <= high)
    {
        middle = (low + high) / 2;
        if (gcd(num,p[middle])==1)
            return middle;
        else 
            high = middle - 1;
    }
}


int main()
{
    int N;
    int A[200000];
    int C[200000] = { 0 };

    scanf("%d", &N);

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

    for (int i = 0; i < N; i++)
        printf("%d\n", C[i]);
}



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

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

  int equalCount = 0;
  if(n % 2 == 1){
      cout << "No" << endl;
  }else{
      for(int i = 0; i < n/2; i++){
          if(s[i] == s[n/2 + i]){
              equalCount++;
              //cout << s[i] << s[n/2+ i] << endl;
          }
      }
      if(equalCount == n/2){
          cout << "Yes" << endl;
      }else{
          cout << "No" << endl;
      }
  }


  

      
  }

Measured memory_bytes: 256
#include<cstdio>
#include<iostream>
#include<cstring>
#include<algorithm>
#include<cmath>
int p[110];
int n,k,x,ans;
int main()
{
    ans = 0;
    scanf("%d",&n);
    scanf("%d",&k);
    for (int i = 1; i <= n; i++)
    {
        scanf("%d",&x);
        p[i] = x;
    }
    for (int i = 1; i <= n; i++)
    {
        ans = ans + fmin((k-p[i])*2,p[i] * 2);
    }
    printf("%d\n",ans);
    return 0;
}

Measured memory_bytes: 256
using System;

namespace Crane
{
    class Program
    {
        static void Main(string[] args)
        {
            int X, Y;

            string inD0 = Console.ReadLine();
            string[] cngD0 = inD0.Split(' ');

            X = int.Parse(cngD0[0]);
            Y = int.Parse(cngD0[1]);
            
            int j = 0;

            for(int i = X; X > 0; i--)
            {
                if ((i * 2 + j * 4) == Y)
                {
                    Console.WriteLine("Yes");
                    break;
                }
                else if(i==1){
                    if(X * 4 == Y)
                    {
                        Console.WriteLine("Yes");
                    }
                    else
                    {
                        Console.WriteLine("No");
                    }
                    break;
                }
                j++;

            }
        }
    }
}


Measured memory_bytes: 27468
#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;
    ll A, B;
    cin >> N >> A >> B;
    vector<ll> X(N);
    rep(i, N) cin >> X[i];

    vector<ll> D(N - 1);
    rep(i, N - 1) D[i] = min((X[i + 1] - X[i]) * A, B);
    ll ans = 0;
    rep(i, N - 1) ans += D[i];
    cout << ans << endl;
}

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

int main()
{
  int N;cin>>N;
  vector<string> S(N);
  vector<int> P(N);
  vector<int> num(N);
  for(int i=0;i<N;i++)
  {
    cin>>S[i];
    cin>>P[i];
  }
  for(int i=0;i<N;i++)
    num[i]=i+1;
  
  for(int i=0;i<N-1;i++)
  {
    for(int j=i+1;j<N;j++)
    {
       if(S[i].compare(S[j])>0)
       {
         swap(S[i],S[j]);
         swap(P[i],P[j]);
         swap(num[i],num[j]);
       }
      else if(S[i].compare(S[j])==0)
      {
        if(P[i]<P[j])
        {
          swap(S[i],S[j]);
          swap(P[i],P[j]);
          swap(num[i],num[j]);
        }
      }
    }
  }
  
  for(int i=0;i<N;i++)
  {
    cout<<num[i]<<endl; 
  }

}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <cmath>
using namespace std;
int main() {
    int N;
    cin >> N;
    int h[N];
    for(int i = 0;i < N;i++){
        cin >> h[i];
    }   
    int p = 0;
    bool flag = true;
    int b,c;
    while(flag == true){
        flag = false;
        for(int i = 0;i< N;i++){
            if(h[i] != 0){
                b = i;
                flag = true;
                break;
            }
        }
        bool flag2 = false;
        if(flag == true){
            for(int j = b;j<N;j++){
                if(h[j] == 0){
                    c = j;
                    flag2 = true;
                    break;
                }
            }
            if(flag2 == false){
                c = N;
            }
            for (int k = b;k<c;k++){
                h[k] = h[k] - 1;
            }
            p = p + 1;
        }
    }
    cout << p << endl;
}

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

using namespace std;
#define int64 long long

const int nMax = 10010;

int A[nMax];
int n, m;
int nTest;

void outerInit()
{
    if (ifstream("test.inp")) freopen("test.inp", "r", stdin);
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cout << setprecision(9) << fixed;
}

void enter()
{
    cin >> n;
    for (int i = 1; i <= n; ++i) cin >> A[i];
}

void init()
{
}

void solve()
{
    int cnt = 0;
    for (int i = 1; i <= n; ++i)
    for (int j = A[i]; j % 2 == 0; j /= 2) cnt++;
    cout << cnt;
}

int main()
{
    outerInit();

    nTest = 1;
    // cin >> nTest;
    for (int i = 1; i <= nTest; ++i)
    {
        if (i > 1) cout << "\n";
        enter();
        init();
        solve();
    }
}

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

int main() {
  int N, M;
  cin >> N >> M;
  vector<int> B(N);
  vector<int> wa(N);
  for (int i = 0; i < M; i++) {
    int P;
    string S;
    cin >> P >> S;
    P--;
    if (B.at(P)) continue;
    if (S == "AC") B.at(P) = 1;
    else wa.at(P)++;
  }
  cout << accumulate(B.begin(), B.end(), 0L) << "\n";
  int ans = 0;
  for (int i = 0; i < N; i++) {
    if (B.at(i)) ans += wa.at(i);
  }
  cout << ans << "\n";
}

Measured memory_bytes: 4016
#include<bits/stdc++.h>
#include<cmath>
#define pb push_back
#define ld long double
#define mp make_pair
#define vl vector<ll> 
#define vd vector<double>
#define vld vector<long double>
#define ll long long int
#define pl pair<ll, ll>
#define all(a) a.begin(), a.end()
#define forr(i, n) for(ll i=0; i<n; i++) 
#define forr1(i, n) for(ll i=1; i<=n; i++)
using namespace std;
const ld PI =3.1415926535897923846;
const ll MOD = 1e9+7;
const ll N=998244353;
ll power(ll x,ll n){ll res=1;while(n>0){if(n&1) res=res*x%N;x=x*x%N;n>>=1;}return res;}
ll modinverse(ll a){return power(a,  998244353-2);}
void solve()
{
   ll n;
   cin>>n;
   vl a(n);
   forr(i, n)
   {
       cin>>a[i];
   }
   sort(all(a));
   ll sum=0;
   sum+=a[a.size()-1];
   if(n%2==0)
   {
       //sum+=a[n/2-1];
       //cout<<sum<<endl;
       for(ll i=n/2; i<=n-2; i++)
       {
           sum+=2*a[i];
       }
   }
   else
   {
       sum+=a[n/2];
       for(ll i=n/2+1; i<n-1; i++)
       {
           sum+=a[i]*2;
       }
   }
   cout<<sum<<endl;
}
int main()
{
    ll test=1;
    //cin>>test;
    while(test--)
    {
        solve();
    }
}

Measured memory_bytes: 4836
#include <iostream>
#include <iomanip>
#include <cmath>

using namespace std;

int main() {
  int datasetnum;
  double x1,y1,x2,y2,x3,y3;

  cin >> datasetnum;

  for (int loopcount = 0; loopcount < datasetnum; loopcount++) {
    double px,py,r;

    cin >> x1 >> y1 >> x2 >> y2 >> x3 >> y3;

    double len_1 = sqrt(pow(x3-x2,2)+pow(y3-y2,2));
    double len_2 = sqrt(pow(x1-x3,2)+pow(y1-y3,2));
    double len_3 = sqrt(pow(x2-x1,2)+pow(y2-y1,2));

    double s = (len_1+len_2+len_3)/2;
    double area = sqrt(s*(s-len_1)*(s-len_2)*(s-len_3));

    double sin_1 = 2*area/(len_2*len_3);

    r = len_1/(2*sin_1);

    double a = x1 - x3;
    double b = y1 - y3;
    double c = pow(x1,2)-pow(x3,2)+pow(y1,2)-pow(y3,2);
    double d = x2 - x3;
    double e = y2 - y3;
    double f = pow(x2,2)-pow(x3,2)+pow(y2,2)-pow(y3,2);

    px = (c*e-b*f)/(2*(a*e-b*d));
    py = (c*d-a*f)/(2*(b*d-a*e));

    cout << fixed << setprecision(3) << px << " " << py << " " << r << endl;
  }

  return 0;
}

Measured memory_bytes: 1288
#include <iostream>

using namespace std;

int N;
int p[12];

int main(void) {

	cin >> N;

	for (int i = 1; i <= N; i++) {
		cin >> p[i];
	}

	int max_val = -1;

	int I;

	for (int i = 1; i <= N; i++) {
		if (max_val < p[i]) { max_val = p[i]; I = i; }
	}

	int ans = 0;

	for (int i = 1; i <= N; i++) {
		if (i == I) {
			ans += p[i] / 2;
		}
		else {
			ans += p[i];
		}
	}

	cout << ans << endl;
	//system("pause");
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define ll          long long
#define pb          push_back
#define mp          make_pair
#define pii         pair<int,int>
#define vi          vector<int>
#define all(a)      (a).begin(),(a).end()
#define sz(x)       (int)x.size()
#define hell        1000000007
#define lbnd        lower_bound
#define ubnd        upper_bound
#define bs          binary_search
#define ios         ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
using namespace std;

int main()
{
	int n,m,k,x;
	cin>>n>>m;
	vi v[11];
	int p[11];

	for(int i=1;i<=m;i++)
	{
		cin>>k;

		for(int j=1;j<=k;j++)
		{
			cin>>x;
			v[i].pb(x);
		}
	}

	for(int i=1;i<=m;i++)
	{
		cin>>p[i];
	}
	int cnt,sum,ans=0;

	for(int i=0;i<(1<<n);i++)
	{
		sum=0;
		for(int j=1;j<=m;j++)
		{
			cnt=0;
			for(int t=0;t<v[j].size();t++)
			{
				if(i&(1<<v[j][t]-1))
				cnt++;
			}
			if(cnt%2==p[j])
			sum++;
		}
		if(sum==m)
		{
			//cout<<i<<endl;
			ans++;
		}
	}
	cout<<ans;
}

Measured memory_bytes: 256
import java.util.*;
public class Main{
	
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int[] list1 = new int[180];
		int[] dp1 = new int[1000000];
		int[] dp2 = new int[1000000]; 
		for(int i = 0; i < 180; i++) {
			list1[i] = (i+1)*(i+2)*(i+3)/6;
		}

		Arrays.fill(dp1, 2 << 27);
		Arrays.fill(dp2, 2 << 27);

		dp1[0] = dp2[0] =  0;

		for(int i = 0; i < 180; i++) {
			int tmp = list1[i];
			if(list1[i] % 2 == 0)
			for(int j = tmp; j < 1000000; j++) {
				dp1[j] = Math.min(dp1[j-tmp]+1, dp1[j]);
			}
			else
			for(int j = tmp; j < 1000000; j++) {
				dp1[j] = Math.min(dp1[j-tmp]+1, dp1[j]);
				dp2[j] = Math.min(dp2[j-tmp]+1, dp2[j]);
			}
		}
		while(true) {
			int a = sc.nextInt();
			if(a == 0) break;
			System.out.println(dp1[a] + " " + dp2[a]);
		}
	}
	

	
}

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

#define pi 2*acos(0.00)
#define ll long long
#define fastio ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
#define nl '\n'
#define null '\0'

using namespace std;

int main()
{
    fastio;

    int n;
    cin>>n;
    int sbo[n]={0},x;
    for(int i=0;i<n-1;i++)
    {
        cin>>x;
        sbo[x-1]++;
    }
    for(int i=0;i<n;i++)
    cout<<sbo[i]<<nl;
}

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

using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef vector<int> vint;
typedef vector<double> vdbl;
typedef vector<ll> vll;
typedef vector<string> vstr;
typedef vector<vector<int> > vvint;
typedef vector<pair<int, int> > vpii;
typedef vector<pair<ll, ll> > vpll;
typedef priority_queue<int, vector<int>, greater<int> > spqint; //小さい順に取り出し
typedef priority_queue<ll, vector<ll>, greater<ll> > spqll;     //小さい順に取り出し
typedef priority_queue<int, vector<int>, less<int> > bpqint;    //大きい順に取り出し
typedef priority_queue<ll, vector<ll>, less<ll> > bpqll;        //大きい順に取り出し

#define REP(i, n) for (int(i) = 0; (i) < (int)(n); i++)
#define FOR(i, a, b) for (int(i) = a; (i) < (int)b; i++)
#define IREP(i, v) for (auto i = v.begin(); i != v.end(); i++)
#define MOD 1000000007
#define NIL -1
#define FI first
#define SE second
#define MP make_pair
#define PB push_back
#define PF push_front
#define TS to_string
#define BS binary_search
#define LB lower_bound
#define UB upper_bound
#define NP next_permutation
#define ALL(v) (v).begin(), (v).end()
#define SZ(x) (ll) x.size()
#define SP(x) setprecision((ll)x)

const int INF = 1e9;
const ll LINF = 1e18;
const double EPS = 1e-9;
const double PI = M_PI;
const int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1};
const int dy[8] = {0, 1, 0, -1, 1, 1, -1, -1};
ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; } //最大公約数
ll lcm(ll a, ll b) { return a / gcd(a, b) * b; }     //最小公倍数

void yes()
{
    cout << "Yay!" << endl;
}
void no()
{
    cout << ":(" << endl;
}
//-----------------------------------------

//-----------------------------------------
int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    int a, b ;
    cin >> a >> b ;
    if(a<=8 && b<=8){
        yes() ;
    }
    else{
        no() ;
    }
    

    return 0;
}


Measured memory_bytes: 384
#include<iostream>
#include<vector>
#include<algorithm>
#include<math.h>
#include<string>
#include<map>
#include<queue>

using namespace std;

int main(void) {
	int n;
	cin >> n;
	vector<pair<int,int>>a;
	for (int i = 0; i < n; i++) {
		int c, d;
		cin >> c >> d;
		a.emplace_back(d, c);
	}
	sort(a.begin(), a.end());
	long long count = 0;
	for (int i = 0; i < n; i++) {
		count += a[i].second;
		if (count > a[i].first) {
			cout << "No" << endl;
			return 0;
		}
	}
	if (count <=a[n-1].first) {
		cout << "Yes" << endl;
	}
	else {
		cout << "No" << endl;
	}
	return 0;
}

Measured memory_bytes: 2420
N = int(input())
A = [0] * N
B = list(map(int, input().split()))
A[0] = B[0]
A[N - 1] = B[N - 2]
if N == 2:
    print(sum(A))
    quit()
for i in range(N - 2):
    if B[i + 1] >= B[i]:
        A[i + 1] = B[i]
    else:
        A[i + 1] = B[i + 1]
print(sum(A))

Measured memory_bytes: 9180
#include<bits/stdc++.h>
#define all(s) s.begin(), s.end()
#define pb push_back
#define ii pair<int, int>
#define x first
#define y second
#define bit(x, y) ((x >> y) & 1)
#define bug(x) cerr<<#x<<" = "<<x<<'\n'

using namespace std;
using ll = long long;

const int mod = 1000000007;

int n, m, ans = 0;
int dp[3005][3005];
int cntmn[3005], cntmx[3005];
string s;

int main() {
    ios::sync_with_stdio(0);
    cin.tie(0); cout.tie(0);
    cin >> n >> m;
    cin >> s;
    s = " " + s;
//    bug(s);
    string t = s;
    for (int l, r, i = 1; i <= m; i++) {
        cin >> l >> r;
        sort(s.begin() + l, s.begin() + r + 1);
        sort(t.begin() + l, t.begin() + r + 1, greater<char>());
    }
    dp[0][0] = 1;
    for (int i = 1; i <= n; i++) {
        cntmn[i] = cntmn[i - 1] + (t[i] == '0');
        cntmx[i] = cntmx[i - 1] + (s[i] == '0');
        if (cntmn[i] == 0) dp[i][0] = dp[i - 1][0];
        for (int j = max(cntmn[i], 1); j <= cntmx[i]; j++) {
            dp[i][j] = (dp[i - 1][j - 1] + dp[i - 1][j]) % mod;
        }
    }

    for (int i = 0; i <= n; i++) {
        ans = (ans + dp[n][i]) % mod;
    }

    cout << ans << '\n';

    return 0;
}


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

int main()
{
    unsigned long  h ,w;
    cin>>h>>w;
    unsigned long ans;
    if(h%2==0)
    {
        ans=(h/2)*w;
    }
    else
    {
        if(w%2==0)
        {
            unsigned long a=(h/2)+1;
            unsigned long b=(h/2);
            ans=(a+b)*w/2;
        }
        else
        {
            unsigned long a=(h/2)+1;
            unsigned long b=(w/2)+1;
            ans=a*b+(h/2)*(w/2);
        }
    }
    if( h == 1 || w == 1)
    {
        ans=1;
    }
    cout<<ans<<"\n";
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using PII = pair<int, int>;
using VI = vector<int>;

const int N = 2e5 + 10;
ll a[N], sum[N], dp[N][2];
const ll INF = 1e18;

map<pair<int,int>, ll> memo;

ll get(int n, int k) {
  if (n == 0 && k == 0) return 0;
  if (n < 2 * k - 1 || n < 1) return -INF;
  if (k == 0) return 0;
  if (n == 2 * k - 1) return sum[n];
  if (memo.find(PII(n,k)) == memo.end()) {
    memo[PII(n,k)] = max(a[n] + get(n - 2, k - 1), get(n - 1, k));
  }
  return memo[PII(n,k)];
}

int main() {
#ifdef LOCAL_EXEC
//	freopen("sample.in", "r", stdin);
//	freopen("sample.out", "w", stdout);
#else
  ios_base::sync_with_stdio(false); cin.tie(NULL);
#endif

  int n; cin >> n;
  for (int i = 1; i <= n; i++) {
    cin >> a[i];
    sum[i] = a[i];
    if (i >= 2) sum[i] += sum[i - 2];
  }
  cout << get(n, n / 2) << endl;

  return 0;
}


Measured memory_bytes: 30168
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <cmath>
#include <map>
#include <queue>
#include <iomanip>
#define MOD 1000000007
typedef long long ll;
using namespace std;

double dp[330][330][330];
int n;

double expectation(int one,int two,int three){
  //cout<<one<<" "<<two<<" "<<three<<endl;
  if(dp[one][two][three]>=0) return dp[one][two][three];
  if(one==0&&two==0&&three==0) return 0.0;

  double res=1.0;
  if(one>0){
    res=res+expectation(one-1,two,three)*one/(double)n;
  }
  if(two>0){
    res=res+expectation(one+1,two-1,three)*two/(double)n;
  }
  if(three>0){
    res=res+expectation(one,two+1,three-1)*three/(double)n;
  }

  int zero=n-(one+two+three);

  if(zero<n) res=res*(double)n/(double)(n-zero);
  return dp[one][two][three]=res;
}

int main(){
  cin>>n;
  int a[n+1]={};
  int one=0,two=0,three=0;
  for(int i=0;i<n;i++){
    cin>>a[i];
    if(a[i]==1) one++;
    else if(a[i]==2) two++;
    else if(a[i]==3) three++;
  }

  for(int i=0;i<=n;i++){
    for(int j=0;j<=n;j++){
      for(int k=0;k<=n;k++){
        dp[i][j][k]=-1;
      }
    }
  }

  cout<<fixed<<setprecision(12)<<expectation(one,two,three)<<endl;

  return 0;
}


Measured memory_bytes: 258176
K = int(input())

g2 = [[0]*(K+1) for _ in range(K+1)]
def gcd(a, b):
    if g2[a][b] > 0:
        return g2[a][b]
    tmpa = a
    tmpb = b
    while b > 0:
        a,b = b, a%b
    g2[tmpa][tmpb] = a
    g2[tmpb][tmpa] = a
    return a

def gcd_3(a,b,c):
    g = gcd(a,b)
    g = gcd(g,c)
    return g

sm = 0
for a in range(1, K+1):
    for b in range(1, K+1):
        for c in range(1, K+1):
            sm += gcd_3(a,b,c)

print(sm)


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

int main(){
  int INF=1234567890;
  int N;
  cin>>N;
  vector<vector<int>> G(N);
  vector<pair<int,int>> vp;
  for(int i=0;i<N-1;i++){
    int a,b;
    cin>>a>>b;
    a--;
    b--;
    G[a].push_back(b);
    G[b].push_back(a);
    vp.push_back(make_pair(a,b));
  }
  map<pair<int,int>,int> I;
  int K=0;
  vector<int> edge_color(N);

  vector<int> d(N);
  queue<int> q;
  q.push(0);
  for(int i=0;i<N;i++) d[i] = INF;
  d[0]=0;

  while(!q.empty()){
    int u = q.front();
    q.pop();
    K=max(K,(int)G[u].size());
    int color=1;
    for(int v:G[u]){
      if(d[v]!=INF) continue;
      d[v]=d[u]+1;
      if(color==edge_color[u]) color++;
      edge_color[v]=color;
      I[make_pair(u,v)]=color;
      I[make_pair(v,u)]=color;
      color++;
      q.push(v);
    }
  }
  cout<<K<<endl;
  for(auto p:vp) cout<<I[p]<<endl;

}


Measured memory_bytes: 20084
import java.util.Scanner;

public class Main {

	/**
	 * @param args
	 */
	public static void main(String[] args) {
		// TODO 自動生成されたメソッド・スタブ


		Scanner scan = new Scanner(System.in);
		char[] mozi = scan.next().toCharArray();
		for(int i=mozi.length-1;i>=0;i--){
			System.out.print(mozi[i]);
		}
		System.out.println();
	}

}

Measured memory_bytes: 11000
#include <stdio.h>
#include <stdlib.h>
 
int main(void)
{
	int a,b;
	float average;
	scanf("%d %d", &a,&b);
	average = (a+b)/2.0;
	if((a+b) % 2 == 0)
		printf("%d", (int) average);
	else{
		average = average + 0.5;
		printf("%d", (int) average);
	}
	return 0;
}


Measured memory_bytes: 128
#include <bits/stdc++.h>
#define REP(i, n) for(int i = 0;i < n;i++)
#define ll long long
using namespace std;
//typedef vector<unsigned int>vec;
//typedef vector<ll>vec;
//typedef vector<vec> mat;
typedef pair<int, int> P;
typedef pair<ll,ll> LP;
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 ll MOD = 998244353;
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;};

void solve(){
    int N;
    cin >> N;
    N %= 10;
    if(N == 2 || N == 4 || N == 5 || N == 7 || N == 9) cout << "hon" << endl;
    else if(N == 0 || N == 1 || N == 6 || N == 8) cout << "pon" << endl;
    else cout << "bon" << endl;
}

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    solve();
    // int T; cin >> T; REP(t,T) solve();
}


Measured memory_bytes: 3688
#include<bits/stdc++.h>
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<iostream>
#include<stdlib.h>
#include<queue>
#include<map>
#include<vector>
#include<cmath>
#include<fstream>
#include <set>
//freopen(".in","r",stdin);
//freopen(".out","w",stdout);
//freopen("input.txt","r",stdin);
//freopen("output.txt","w",stdout);
const int  MAXN =2e5+10;
const int mod = 1e9 + 7;
const long long INF = 0x7f7f7f7f7f7f7f7f;
const int inf= 0x3f3f3f3f;
#define eps 1e-8
#define PI 3.1415926535898
#define lowbit(x) (x&(-x))
using namespace std ;
//getline(cin,s);
//set<ll>::iterator it;
//map<int,int>::iterator it;
typedef long long ll;
//ai/aj!=0(1=<j<=n) 
int need[1000005];
int a[MAXN];
int main()
{
	int n;
	int max1=0;
	scanf("%d",&n);
	for(int i=1;i<=n;i++) scanf("%d",&a[i]),max1=max(max1,a[i]);
	for(int i=1;i<=n;i++)
	{
		for(int j=a[i];j<=max1;j+=a[i])
		{
			need[j]++;
		}
	}
	int ans=0;
	for(int i=1;i<=n;i++)
	{
		if(need[a[i]]==1) ans++;
	}
	printf("%d\n",ans);
	return 0;
} 

Measured memory_bytes: 8304
import java.util.Scanner;

class Main{
	public static void main(String[] args) {
		Scanner sc=new Scanner(System.in);
		int kosu=sc.nextInt();
		long[] mati=new long[kosu];
		long aru=sc.nextLong();
		long tlp=sc.nextLong();
		for(int i=0; i<kosu; i++) {
			mati[i]=sc.nextLong();
		}
		long costs=0;

		for(int i=0; i<kosu-1; i++) {
			long a=mati[i+1]-mati[i];
			if(a*aru>tlp) {
				costs+=tlp;
			}
			else {
				costs+=a*aru;
			}
		}
		System.out.println(costs);
	}
}

Measured memory_bytes: 49472
import java.math.BigInteger
const val mod = 1000000007L

fun main() {
    val N = readLine()!!.toLong()
    var ans = remainder(10, N) - remainder(9, N) - remainder(9, N) + remainder(8, N)
    ans %= mod
    ans = (ans + mod) % mod
    println(ans)
}

fun remainder(x: Long, n: Long): Long {
    var rem = 1L
    for (i in 1..n) {
        rem = rem * x % mod
    }
    return rem
}

Measured memory_bytes: 34524
#include <iostream>
#include <string>
#include <sstream>
#include <algorithm>
#include <vector>
#include <utility>
#include <functional>
#include <stack>
#include <queue>
#include <map>
#include <set>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <deque>
#include <ctime>

using namespace std;

#define rep(i,n) REP(i,0,n)
#define REP(i,s,e) for(int i=(s); i<(int)(e); i++)
#define pb push_back
#define mp make_pair
#define all(r) (r).begin(),(r).end()
#define rall(r) (r).rbegin(),(r).rend()
#define fi first
#define se second
#define ARRAY_LENGTH(array) (sizeof(array) / sizeof(array[0]))


typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;

const int INF = 1e9;
const ll LINF = 1e18;
const ll MOD = 1e9 + 7;
double EPS = 1e-8;
const double PI = acos(-1);

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

int sigma(int n){
    if(n == 0) return 0;
    else return n + sigma(n-1);
}

int main(){

    int n;
    int sum = 0;
    cin >> n;

    cout << sigma(n) << endl;

}

Measured memory_bytes: 256
import java.util.Scanner;

class Main { 
    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        while (in.hasNext()) {
            int n = in.nextInt();
            int[] map = new int[n + 1];
            System.out.println(fib(n, map));
        }
    }
    static int fib(int n, int[] map) {
        if      (n == 0) return 1;
        else if (n == 1) return 1;
        else if (map[n] != 0) return map[n];
        else { map[n] = fib(n - 1, map) + fib(n - 2, map); 
            return map[n];
        }
    }
}

Measured memory_bytes: 17352
#include <algorithm>
#include <cassert>
#include <cctype>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <ctime>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <queue>
#include <random>
#include <set>
#include <sstream>
#include <string>
#include <utility>
#include <vector>

#define REP(i,s,n) for(int i=(int)(s);i<(int)(n);i++)
#define DEBUGP(val) cerr << #val << "=" << val << "\n"

using namespace std;
typedef long long int ll;
typedef vector<int> VI;
typedef vector<ll> VL;
typedef pair<int, int> PI;
const ll mod = 1e9 + 7;



int main(void) {
  ios::sync_with_stdio(false);
  cin.tie(0);
  ll n, k;
  cin >> n >> k;
  ll tot = 0;
  REP(b, k + 1, n + 1) {
    ll qmax = (n - k) / b;
    tot += (b - k) * qmax;
    ll r = (n - k) % b;
    tot += min(b - k, r + 1);
    if (k == 0) {
      tot--;
    }
    if (0) {
      DEBUGP(b);
      DEBUGP(qmax);
      DEBUGP(r);
      DEBUGP(tot);
    }
  }
  cout << tot << endl;
}


Measured memory_bytes: 256
#include <stdio.h>

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

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

int main(){
    int p,q,r,ans;
    cin >> p >> q >> r;
if(p<q){
    if(r<q){
        ans = p+r;
    }else{
        ans = p+q;
    }
}else if(p<r){
    ans = p+q;
}else {
    ans = q+r;
}
cout << ans << endl;
return 0;
}

Measured memory_bytes: 256
import sys
from collections import defaultdict
readline = sys.stdin.buffer.readline
def even(n): return 1 if n%2==0 else 0
n = int(readline())
lst1 = list(map(int,readline().split()))
dic1 = defaultdict(int)

for i in lst1:
    dic1[i] += 1



al = 0
for i in dic1.values():
    if i >= 2:
        al += i*(i-1)//2

for i in lst1:
    res = dic1[i]
    if res >= 2:
        print(al-res*(res-1)//2+(res-1)*(res-2)//2)
    else:
        print(al)

Measured memory_bytes: 71024
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define all(a) begin(a), end(a)

int main()
{
    ll n, x;
    cin >> n >> x;
    vector<ll> a(n);
    for (ll i = 0; i < n; ++i) cin >> a[i];
    sort(all(a));
    ll cnt = 0;
    for (ll i = 0; i < n; ++i)
    {
        if (x >= a[i])
        {
            ++cnt;
            x -= a[i];
        }
        else
        {
            x -= a[i];
        }
    }
    if (x > 0) --cnt;
    cout << cnt << endl;
    return 0;
}


Measured memory_bytes: 256
import std.stdio, std.array, std.string, std.conv, std.algorithm;
import std.typecons, std.range, std.random, std.math, std.container;
import std.numeric, std.bigint, core.bitop, core.stdc.stdio;
     
alias Tuple!(int, "x", int, "y") Point;
     
void main() {
    auto s = readln.split.map!(to!int);
    auto N = s[0];
    auto A = s[1]-1;
    auto B = s[2]-1;
    auto X = new int[](N);
    auto Y = new int[](N);
    int[][int] X_Y;
    int[][int] Y_X;
    foreach (i; 0..N) {
        s = readln.split.map!(to!int);
        X[i] = s[0] + s[1];
        Y[i] = s[0] - s[1];
        X_Y[X[i]] ~= Y[i];
        Y_X[Y[i]] ~= X[i];
    }

    RedBlackTree!(int)[int] rbtX_Y;
    RedBlackTree!(int)[int] rbtY_X;
    foreach (k; X_Y.keys) {
        X_Y[k].sort();
        rbtX_Y[k] = new RedBlackTree!(int)();
        rbtX_Y[k].insert(X_Y[k].dup);
    }
    foreach (k; Y_X.keys) {
        Y_X[k].sort();
        rbtY_X[k] = new RedBlackTree!(int)();
        rbtY_X[k].insert(Y_X[k].dup);
    }
     
    int manh = max(abs(X[A]-X[B]), abs(Y[A]-Y[B]));
    bool[int][int] used;
    DList!Point q;
    q.insert(Point(X[A], Y[A]));
    long ans = 0;
        
    while (!q.empty) {
        auto n = q.front;
        auto x = n.x;
        auto y = n.y;
        q.removeFront;
        if (x in used && y in used[x])
            continue;
        used[x][y] = true;
     
        foreach (d; [manh, -manh]) {
            auto nx = x + d;
            if (!(nx in X_Y)) continue;
            long lb = assumeSorted(X_Y[nx]).lowerBound(y-manh).length.to!long;
            long ub = assumeSorted(X_Y[nx]).lowerBound(y+manh+1).length.to!long;
            ans += (ub - lb);

            int[] ys;
            foreach (i; rbtX_Y[nx].upperBound(y-manh-1)) {
                if (i > y + manh) break;
                ys ~= i;
            }
            foreach (ny; ys) {
                if (ny > y + manh) break;
                q.insert(Point(nx, ny));
                rbtX_Y[nx].removeKey(ny);
            }
        }
     
        foreach (d; [manh, -manh]) {
            auto ny = y + d;
            if (!(ny in Y_X)) continue;
            long lb = assumeSorted(Y_X[ny]).lowerBound(x-manh+1).length.to!long;
            long ub = assumeSorted(Y_X[ny]).lowerBound(x+manh).length.to!long;
            ans += (ub - lb);
     
            int[] xs;
            foreach (i; rbtY_X[ny].upperBound(x-manh)) {
                if (i >= x + manh) break;
                xs ~= i;
            }
            foreach (nx; xs) {
                if (nx >= x + manh) break;
                q.insert(Point(nx, ny));
                rbtY_X[ny].removeKey(nx);
            }

        }        
    }
     
    writeln(ans/2);
}


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

int main()
{
    int n;
    cin >> n;
    set<int> d;
    for (int i = 0; i < n; i++) {
        int tmp;
        cin >> tmp;
        d.insert(tmp);
    }
    cout << d.size() << endl;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define rep(i,N) for(int i=0;i<(N);i++)
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
using namespace std;
const long long MOD = 1e9 + 7;
const long long INF = 1e12;
const int inf = 1e9;
const int mod = 1e9+7;
typedef long long ll;
typedef pair<ll,int> P;
typedef set<int> S;
int main(){
    cout << fixed << setprecision(10);
    ll a;
    double b;
    cin >> a >> b;
    ll c = round(100*b);
    cout << a*c/100 << endl; 
    return 0;
}

Measured memory_bytes: 3744
from functools import lru_cache as cache

@cache(maxsize=None)
def t(n):
    return 1 if n == 0 else t(n - 1) * 2 + 3

@cache(maxsize=None)
def p(n):
    return 1 if n == 0 else p(n - 1) * 2 + 1

f = lambda n, x: (0 if x <= 0 else 1) if n == 0 else f(n - 1, x - 1) if x <= 1 + t(n - 1) else p(n - 1) + 1 + f(n - 1, x - 2 - t(n - 1))

print(f(*map(int, input().split())))


Measured memory_bytes: 3684
#include<iostream>
using namespace std;
int main(){
	int n,y,a=0;
	cin>>n>>y;
	for(int i=0;i<y/10000+1;i++){
		for(int j=0;j<y/5000+1;j++){
			if(i*10000+j*5000+(n-i-j)*1000==y&&(n-i-j)>=0){
				cout<<i<<" "<<j<<" "<<n-i-j<<endl;
				a=1;
				break;
			}
		}
		if(a){
			break;
		}
	}
	if(a==0){
		cout<<"-1 -1 -1"<<endl;
	}
return 0;
}


Measured memory_bytes: 256
package main
import "fmt"
func main() {
  var m,k,u int64
  fmt.Scan(&m,&k)
  u = 1
  for i:=m;i>0;i-- { u *= 2 }
  u -= 1
  if k > u {
    fmt.Println(-1)
    return
  }
  if m == 0 {
    fmt.Println(0,0)
    return
  }
  if m == 1 {
    if k == 0 {
      fmt.Println(0,0,1,1)
    } else {
      fmt.Println(-1)
    }
    return
  }
  for i:=int64(0);i<u+1;i++ {
    if i == k { continue }
    fmt.Print(i)
    fmt.Print(" ")
  }
  fmt.Print(k)
  fmt.Print(" ")
  for i:=u;i>-1;i-- {
    if i == k { continue }
    fmt.Print(i)
    fmt.Print(" ")
  }
  fmt.Println(k)
}

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

int main() {
  	string S;
  	cin >> S;
  	bool flag = true;
  	if (S[2] != S[3]) flag = false;
  	if (S[4] != S[5]) flag = false;
  	if (flag == true) cout << "Yes" << endl;
  	if (flag == false) cout << "No" << endl;
}  

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <cmath>
#include <bitset> 
#include <cstring>

#define REP(i,k,n) for(int i=k;i<n;i++)
#define rep(i,n) for(int i=0;i<n;i++)

using namespace std;

vector<bitset<16> > v,c;
int memo[31][1<<16];
int n,m;

int dfs(bitset<16> t,int i)
{
	if(i == n) return 0;

	t |= v[i];
	if(memo[i][t.to_ulong()] != -1) return memo[i][t.to_ulong()];

	int ret = 0;
	rep(j,m)
	{
		bitset<16> bit = t & c[j];
		int temp = t.to_ulong() - bit.to_ulong();

		ret = max(ret,dfs(bitset<16>(temp),i+1) + (int)bit.count());
	}

	return memo[i][t.to_ulong()] = ret;
};

int main()
{
	while(cin >> n >> m)
	{
		if(n == 0 && m == 0) break;

		v.clear();
		c.clear();
		memset(memo,-1,sizeof(memo));
		int temp;

		rep(i,n)
		{
			double t = pow(2.0,15);
			int ret = 0;
			rep(j,16)
			{
				cin >> temp;
				ret += temp * t;
				t /= 2;
			}

			bitset<16> bit(ret);
			v.push_back(bit);
		}

		rep(i,m)
		{
			double t = pow(2.0,15);
			int ret = 0;
			rep(j,16) 
			{
				cin >> temp;
				ret += temp*t;
				t /= 2;
			}
			
			bitset<16> bit(ret);
			c.push_back(bit);
		}

		cout << dfs(bitset<16>(0),0) << endl;
	}

	return 0;
}

Measured memory_bytes: 9152
#include <iostream>
#include <algorithm>
#include <cstring>
using namespace std;

const int Max = 1005;
const int M = 10005;
int w[Max], s;
int b[Max];
int t[M];
int visit[Max];

int solve(int w[], int b[], int n)
{
    memset(visit, 0, sizeof(visit));
    for(int i=0; i<n; i++)
        t[b[i]] = i;
    int result = 0;
    for(int i=0; i<n; i++)
    {
        if(visit[i]) continue;
        int cur = i, sum = 0, num = 0, m = M;
        while(!visit[cur])
        {
            visit[cur] = 1;
            m = min(m, w[cur]);
            sum += w[cur];
            num++;
            cur = t[w[cur]];
        }
        if(num)
        {
            result += min(sum+(num-2)*m, sum+m+(num+1)*s);
        }
    }
    return result;
}
int main()
{
    int n;
    s = M;
    cin >> n;
    for(int i=0; i<n; i++)
    {
        cin >> w[i];
        b[i] = w[i];
        s = min(s, w[i]);
    }
    sort(b, b+n);
    cout << solve(w, b, n) << endl;
}



Measured memory_bytes: 3188
#include <iostream> 
#include<vector>
#include<algorithm>
#include<map>
#include<set>
#include<queue>
#include<deque>
#include<iomanip>
#include<sstream>
#include<cmath>
#include<bitset>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define req(i,n) for(int i = 1;i <=  n; i++)
#define rrep(i,n) for(int i = n -1;i >= 0;i--)
#define ALL(obj) begin(obj), end(obj)
#define RALL(obj) rbegin(obj),rend(obj)
typedef long long int ll;
typedef long double ld;
const ll INF = (1 << 30);
template<typename A, size_t N, typename T>
void Fill(A(&array)[N], const T & val) {
    fill((T*)array, (T*)(array + N), val);
}
struct UnionFind {
    vector<int> par; // par[i]:iの親の番号　(例) par[3] = 2 : 3の親が2

    UnionFind(int N) : par(N) { //最初は全てが根であるとして初期化
        for (int i = 0; i < N; i++) par[i] = i;
    }

    int root(int x) { // データxが属する木の根を再帰で得る：root(x) = {xの木の根}
        if (par[x] == x) return x;
        return par[x] = root(par[x]);
    }

    void unite(int x, int y) { // xとyの木を併合
        int rx = root(x); //xの根をrx
        int ry = root(y); //yの根をry
        if (rx == ry) return; //xとyの根が同じ(=同じ木にある)時はそのまま
        par[rx] = ry; //xとyの根が同じでない(=同じ木にない)時：xの根rxをyの根ryにつける
    }

    bool same(int x, int y) { // 2つのデータx, yが属する木が同じならtrueを返す
        int rx = root(x);
        int ry = root(y);
        return rx == ry;
    }
};
int main() {
    int n, m; cin >> n >> m; vector<int> a(m), b(m);
    rep(i, m) {
        cin >> a[i] >> b[i];
        a[i]--; b[i]--;
    }int ans = 0;
    rep(i, m) {
        UnionFind tree(n); bool boo = false;
        rep(j, m) {
            if (i == j)continue;
            tree.unite(a[j], b[j]);
        }
        rep(j, n) {
            rep(k, n) {
                if (!tree.same(k, j)) {
                    ans++; boo = true;
                    break;
                }
            }if (boo)break;
        }
    }cout << ans << endl;
}

Measured memory_bytes: 256
#include <cstdio>
#include <vector>

int main() {
  int N=100010;
  std::vector<int> sieve(N);
  sieve[0] = sieve[1] = 1;
  for (int i=2; i*i<N; ++i) {
    if (sieve[i]) continue;
    for (int j=i*i; j<N; j+=i)
      sieve[j] = i;
  }

  std::vector<int> is_like_2017(N), pre(N);

  for (int i=1; i<N; i+=2)
    if (sieve[i] == 0 && sieve[(i+1)/2] == 0)
      is_like_2017[i] = 1;

  for (int i=1; i<N; ++i)
    pre[i] = pre[i-1] + is_like_2017[i];

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

  for (int i=0; i<Q; ++i) {
    int l, r;
    scanf("%d %d", &l, &r);
    printf("%d\n", pre[r]-pre[l-1]);
  }
}


Measured memory_bytes: 1792
#include<iostream>
#include<algorithm>
#include<string>
#include<vector>
#include<math.h>
using namespace std;
int main(){
    int n;
    int d[101]={};
    cin>>n;
    for(int i = 0;i<n;i++){
        cin>>d[i];
    }
    sort(d,d+n);
    int ans=0;
    int b=-1;
    for(int i = 0;i<n;i++){
        if(d[i]!=b){
            ans++;
        }
      b=d[i];
    }
    cout<<ans<<endl;
    return 0;
}



Measured memory_bytes: 256
s = input()
k = int(input())
subs = []

for i in range(len(s)):
    for j in range(i + 1, i + 1 + k):
        subs.append(s[i:j])
        
list_subs = list(set(subs))
list_subs.sort()

print(list_subs[k - 1])

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

int main()
{
    string s;
    cin >> s;
    string ans = "yes";
    rep(i, s.size()) {
        repl(j, i + 1, s.size()) {
            if(s[i] == s[j]) {
                ans = "no";
            }
        }
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
N,K = input().split()
n = int(N)
k = int(K)
list = [input() for i in range(2,2*k+2)]

n_list=[]
for x in range(k):
  n_list=n_list+list[2*x+1].split()
  
n_list.sort()

s=1
for y in range(len(n_list)-1):
  if n_list[y]==n_list[y+1]:
    s=s
  else:
    s=s+1
print(n-s)    

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

//将键转换为数值
//查找地址
//存储 

//宏定义  使用宏时会完全展开，如 M + 10 = 1046527 + 10 ， NIL + 10 = (-1) + 10 
// #define N 1 + 2    n * 10 = 1 + 2 * 10 而不是 (1 + 2) * 10 
#define M 1046527
#define NIL (-1)
#define L 14
char H[M][L];

//将字符转换为数值
int getChar(char ch)
{
	if (ch == 'A') return 1;
	else if (ch == 'C') return 2;
	else if (ch == 'G') return 3;
	else if (ch == 'T') return 4;
	else return 0;
 } 
 
 //生成key
 long long getKey(char str[]) 
 {
 	long long v = 0;
 	int p = 1, i;
 	for (i = 0; str[i] !='\0'; ++i)
 	{
 		v += p * getChar(str[i]);
		p *= 5;
	}
	return v;
 }
 
 //开放地址法：当key相同时，h1函数产生的地址出现冲突，这时调用h2函数移动h2()个位置如果还冲突再
 //向后移动直到不冲突。移动时注意，n次移动后一定能遍历数组所有的地址，保证移动的位置与数组长度
 //互质是一个办法 如何保证互质， 数组长度为质数，则在之前的数都跟他互质 
 
 //***本题中实现的时set 
 
 
 //将地址限定在0 - M-1 
int h1(long long key) { return key % M;}
int h2(long long key) { return (key % M) + 1;} // 
bool find(char str[])
{
	long long key = getKey(str);
	int i;
	long long h;
	for (i = 0; i < M; ++i)
	{
		h = (h1(key) + i * h2(key)) % M;
		if (strcmp(H[h], str) == 0) return 1;//已经存在值
		else if (strlen(H[h]) == 0) return 0; //本题中的特例，相同的key必有相同的开始点，相同的增长速度，所以按此规律
		//向后找到第一个值为空的索引时再整个数组内必没有str因为str不再规律内，则一定不再其他规律 
	}
	h1(key);
}

bool insert(char str[])
{
	long long key = getKey(str);
	int i;
	long long h;
	for (i = 0; i < M; ++i) 
	{
		h = (h1(key) + i * h2(key)) % M;
		
		if (strcmp(H[h], str) == 0) return false;//已经有了 
		else if (strlen(H[h]) == 0) //没有则插入并返回true 
		{
			strcpy(H[h], str);
			return true;
		}
	}
	return 0;//没有空位也没有被插入过 
}

 int main()
 {
 	int i , n;
 	char s1[9], str[L];
 	for (i = 0; i < M; ++i) H[i][0] = '\0';
	scanf("%d", &n);
	for (i = 0; i < n; ++i)
	{
	
		
		scanf("%s %s", s1, str);
		if (s1[0] == 'i')
		insert(str);
		else
		{
			if (find(str))
			printf("yes\n");
			else
			printf("no\n");
		}
	}
 	return 0;
 }





Measured memory_bytes: 16988
import java.util.*
import java.math.*
import java.lang.Math.*


private val readString: ()->String = {readLine()!!}
private val readInt: ()->Int = { readLine()!!.toInt() }
private val readLong: ()->Long = { readLine()!!.toLong() }
private val readListInt: ()->List<Int> = { readLine()!!.split(' ').map(String::toInt) }
private val readListLong: ()->List<Long> = { readLine()!!.split(' ').map(String::toLong) }
private val errPrintln: (String)->Unit = { msg -> System.err.println(msg) }


data class Position(var x: Int, var y: Int)

fun solveA(G: Array<String>): Int {
    val H = G.size
    val W = G[0].length
    val INF = Int.MAX_VALUE / 2
    val step = Array(H) { Array<Int>(W){INF} }
    val starts = ArrayList<Position>()
    for (i in 0 until H) {
        for (j in 0 until W) {
            //step[i][j] = INF
            if (G[i][j] == '#') {
                starts.add(Position(i, j))
            }
        }
    }
    val dx = intArrayOf(0, 1, 0, -1)
    val dy = intArrayOf(1, 0, -1, 0)
    val que = ArrayDeque<Position>()
    for (i in starts.indices) {
        que.addLast(starts[i])
        step[starts[i].x][starts[i].y] = 0
    }
    var res = 0
    while (!que.isEmpty()) {
        val pos = que.removeFirst()
        val x = pos.x
        val y = pos.y
        for (i in dx.indices) {
            val nx = x + dx[i]
            val ny = y + dy[i]
            if (nx < 0 || H <= nx || ny < 0 || W <= ny) {
                continue
            }
            if (step[nx][ny] > step[x][y] + 1) {
                step[nx][ny] = step[x][y] + 1
                que.addLast(Position(nx, ny))
                res = max(res, step[nx][ny])
            }
        }
    }
    return res
}


fun main(args: Array<String>) {
    val (H, W) = readListInt()
    val A = Array<String>(H){""}
    for (i in 0 until H) {
        A[i] = readString()
    }

    val ans = solveA(A)

    println(ans)
}


Measured memory_bytes: 113980
#include <bits/stdc++.h>
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define rep(i,n) FOR(i,0,n)
#define repr(i,n) for(int i=(n)-1;0<=i;--i)
#define each(e,v) for(auto&& e:(v))
#define all(v) begin(v),end(v)
#define dump(x) cerr<<#x<<": "<<(x)<<endl
#define INF 100000000
using std::cin;
using std::cout;
using std::endl;
using std::ios;

int N, W;
int v[105] = {0}, w[105] = {0};
int dp[105][10005];

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

    cin >> N >> W;
    for(int i = 0; i < N; i++) cin >> v[i] >> w[i];

    for(int i = 0; i < N; i++) {
        for(int j = 0; j <= W; j++) {
            if(j < w[i]) {
                dp[i + 1][j] = dp[i][j];
            } else {
                dp[i + 1][j] = std::max(dp[i][j], dp[i][j - w[i]] + v[i]);
            }
        }
    }

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

}


Measured memory_bytes: 7128
from itertools import product as p

N = int(input())
*V, = map(int, input().split())
*C, = map(int, input().split())

ans = 0
for a in p(range(2), repeat=N):
    X, Y = 0, 0
    for i, j in enumerate(a):
        if j:
            X+=V[i]
            Y+=C[i]
    ans = max(ans, X-Y)
print(ans)

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

//keyence
int main(){
	int n; 
	scanf("%d",&n); 	
	long long sum = 0;
	int a[n] = {}; int b[n] = {}; int c[n]= {};
	for (int i=0; i<n; i++)
		scanf("%d",&a[i]);
	for (int i=0; i<n; i++){
		scanf("%d",&b[i]);
		c[i] = a[i] - b[i];
		sum += c[i];
	}
	if (sum < 0) cout << -1;
	else {
		sort(c,c+n);
		int count = 0; long long total = 0;
		for (; c[count]<0; count++)
			total += c[count];
		for (int i = n-1; total < 0; i-- ){
			total += c[i];
			count ++;
		}
		cout << count;
	}
	
}

Measured memory_bytes: 1408
#include <bits/stdc++.h>
    
using namespace std;
typedef long long ll;
    
int main()
{
    string a, b;
    cin >> a >> b;
    int result = stoi(a + b);

    for (int i = 1; i <= 10000; i++) {
        int tmp = i * i;
        if (tmp == result) {
            cout << "Yes";
            return 0;
        }
    }

    cout << "No";

    return 0;
}


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

#define rep(i, n) for (int i = 0; i < n; i++)

using namespace std;

int main()
{
    int n, a, b, c, x;
    while (cin >> n >> a >> b >> c >> x, n) {
        int d[100];
        rep(i, n) {
            cin >> d[i];
        }
        int j = 0, fl = 0;
        while (fl < 10001) {
            if (x == d[j]) {
                j++;
                if (j == n) {
                    break;
                }
            }
            x = (a * x + b) % c;
            fl++;
        }
        if (fl == 10001) { 
            puts("-1");
        } else {
            printf("%d\n", fl);
        }
    }
    return 0;
}

Measured memory_bytes: 3124
#include<iostream>
#include<cstdio>
#include<vector>
using namespace std;

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

int main() {
  for(;;) {
    string red, green, under;
    cin >> red; if( red == "-" ) break;
    cin >> green >> under;

    string left;
    int r = 0, g = 0;
    int u = 0;

    for(char center = green[g++]; left.size() + under.size() != red.size() + green.size();) {
      if( under[u] == center ) {
        u++;
        center = red[r++];
      } else {
        left += center;
        center = green[g++];
      }
    }
    cout << left << endl;
  }
  return 0;
}

Measured memory_bytes: 0