akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <iomanip>
#include <algorithm>
#include <utility>
#include <cmath>
#include <string>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <deque>
#include <numeric>

// https://umbccd.io/challenges


using namespace std;

using ll = long long;
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define mkp(a, b) make_pair(a, b)

using namespace std;


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


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

	vector<int> rc(l + 1);
	vector<int> gc(l + 1);
	vector<int> bc(l + 1);
	rc[l] = 0;
	gc[l] = 0;
	bc[l] = 0;

	for (int i = l - 1; i >= 0; i--) {
		rc[i] = rc[i + 1];
		gc[i] = gc[i + 1];
		bc[i] = bc[i + 1];

		if (s[i] == 'R') {
			rc[i]++;
		} else if (s[i] == 'G') {
			gc[i]++;
		} else {
			bc[i]++;
		}
	}
	ll total = 0;
	for (int i = 0; i < l; i++) {
		for (int j = i + 1; j < l; j++) {
			char c = ' ';
			if (s[i] == 'R') {
				if (s[j] == 'G') {
					c = 'B';
				}
				if (s[j] == 'B') {
					c = 'G';
				}
			} else if (s[i] == 'G') {
				if (s[j] == 'R') {
					c = 'B';
				}
				if (s[j] == 'B') {
					c = 'R';
				}
			} else if (s[i] == 'B') {
				if (s[j] == 'R') {
					c = 'G'; 
				} 
				if (s[j] == 'G') {
					c = 'R';
				}
			}
			if (c == ' ') {
				continue;
			}
			
			if (c == 'R') {
				total += rc[j + 1];
			} else if (c == 'G') {
				total += gc[j + 1];
			} else if (c == 'B') {
				total += bc[j + 1];
			}


			int next = j + (j - i);
			if (next >= l) {
				continue;
			} 
			if (c == s[next]) {
				total--;
			}
		}
	}


	cout << total << endl;

 	return 0;
}


Measured memory_bytes: 3156
//Name: Worst Sportswriter
//Level: 3
//Category: グラフ,Graph,トポロジカルソート
//Note:

/**
 * 条件1&#12316;3より、チーム間には全順序関係があることが分かる。
 * したがって、勝敗関係で有向グラフを作り、トポロジカルソートすると有効な順序がひとつ得られる。
 * これ以外の順序が存在するためには、元のグラフが1本の鎖になっていない（分枝をもつか、連結でない）必要がある。
 * また、この性質を満たすとき、順序の定義されない2ノードの順序は任意に決定できるため、複数の順序が存在する。
 *
 * オーダーは O(N + M)。
 */
#include <iostream>
#include <vector>
#include <algorithm>

using namespace std;

void topological_inner(const vector<vector<int>> &g, int v, vector<int> &res, vector<bool> &visited) {
    visited[v] = true;
    for(int to : g[v]) {
        if(!visited[to]) {
            topological_inner(g, to, res, visited);
        }
    }
    res.push_back(v);
}

vector<int> topological_sort(const vector<vector<int>> &g) {
    const int N = g.size();
    vector<int> res;
    vector<bool> visited(N, false);
    for(int i = 0; i < N; ++i) {
        if(!visited[i]) {
            topological_inner(g, i, res, visited);
        }
    }
    reverse(begin(res), end(res));
    return res;
}

bool check(const vector<int> &ord, const vector<vector<int>> &g) {
    const int N = ord.size();
    for(int i = 0; i < N-1; ++i) {
        const int next = ord[i+1];
        if(find(begin(g[ord[i]]), end(g[ord[i]]), next) == end(g[ord[i]])) return false;
    }
    return true;
}

bool solve() {
    int N;
    if(!(cin >> N)) return false;
    if(!N) return false;

    int M;
    cin >> M;
    vector<vector<int>> graph(N);
    for(int i = 0; i < M; ++i) {
        int a, b;
        cin >> a >> b;
        graph[a-1].push_back(b-1);
    }
    vector<int> ord = topological_sort(graph);
    const bool full_ordered = check(ord, graph);
    for(int o : ord) {
        cout << o+1 << endl;
    }
    cout << !full_ordered << endl;
    return true;
}

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

    while(solve()) ;
    return 0;
}

Measured memory_bytes: 2248
#include <iostream>
#include <string>
#include <vector>
#include <queue>
#include <map>
#include <algorithm>

typedef long long ll;
const ll MOD = 1e9 + 7;
const ll INF = ll(1e18)+1;

using namespace std;

const int NMAX = 2* 1e5;

int main(){
    ll n, k;
    vector<ll> a;
    cin >> n >> k;
    for(ll i = 0; i < n; i++){
        ll t;
        cin >> t;
        a.push_back(t);
    }
    sort(a.begin(), a.end());
    ll l = -INF, r = INF;

    while(l+1 < r){
        ll x = (l+r)/2;
        ll total = 0;
        for(ll i = 0; i < n; i++){
            if(a[i] < 0){
                ll l2 = -1, r2 = n;
                while(l2+1 < r2){
                    ll c = (l2+r2)/2;
                    if(a[i]*a[c] < x){
                        r2 = c;
                    } else {
                        l2 = c;
                    }
                }
                total += n-r2;
            } else {
                ll l2 = -1, r2 = n;
                while(l2+1 < r2){
                    ll c = (l2+r2)/2;
                    if(a[i]*a[c] < x){
                        l2 = c;
                    } else {
                        r2 = c;
                    }
                }
                total += r2;
            }
            if(a[i]*a[i] < x) total--;
        }
        total /= 2;
        if(total < k){
            l = x;
        } else {
            r = x;
        }
    }

    cout << l << endl;

    return 0;
}

Measured memory_bytes: 2420
#include <stdio.h>

int main()
{
 int i, n;
 char str[21], ans[21];
 scanf("%s", str);
 n=0;
 while(str[n]!='\0') n++;
 for(i=0; i<n; i++){
  ans[i] = str[n-i-1];
 }
 ans[i]= '\0';
 printf("%s\n", ans);
 return(0);
}

Measured memory_bytes: 524
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner scan=new Scanner (System.in);
		String s=scan.nextLine().replaceAll(" ", "");
		int a=Integer.parseInt(s);
		if(a%4==0) System.out.println("YES");
		else System.out.println("NO");
	}

}


Measured memory_bytes: 26956
import java.io.IOException;
import java.util.*;

public class Main{
	public static void main(String[] args){
      Scanner scanner = new Scanner(System.in);
      int sell = scanner.nextInt();
      int buy = scanner.nextInt();
      scanner.nextLine();
      ArrayList<Integer> list = new ArrayList<>();
      while(scanner.hasNextInt()){
      		list.add(scanner.nextInt());
      }
      Collections.sort(list);
      int result = 0;
      for(int i = 0; i < buy; i++){
      	result += list.get(i);
      }
      System.out.println(result);
    }
}

Measured memory_bytes: 38980
#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++)
#define SSTR( x ) static_cast< std::ostringstream & >( \
        ( std::ostringstream() << std::dec << x ) ).str()
#define ALL(s) (s).begin(), (s).end()
using namespace std;
typedef long long unsigned int llu;
typedef long long ll;

const string D_blue    = "\x1b[36m";
const string D_green   = "\x1b[32m";
const string D_red     = "\x1b[31m";
const string D_yellow  = "\x1b[33m";
const string Db_red    = "\x1b[41m";
const string Db_yellow = "\x1b[43m";
const string D_end     = "\x1b[39m";
const string Db_end    = "\x1b[49m";

int main (){
  int A,B;
  while (cin >> A >> B){
    int ans = 0;
    FOR(i,A,B+1){
      ostringstream ostr;
      ostr << i;
      string s = ostr.str();
      if(s[0] == s[4] && s[1] == s[3])ans ++;
    }
    cout << ans << endl;
  }
  return 0;
}


Measured memory_bytes: 256
#define _USE_MATH_DEFINES
#pragma region include
#include <iostream>
#include <iomanip>
#include <stdio.h>

#include <sstream>
#include <algorithm>
#include <iterator>
#include <cmath>
#include <complex>

#include <string>
#include <cstring>
#include <vector>
#include <bitset>

#include <queue>
#include <set>
#include <map>
#include <stack>
#include <list>

#include <ctime>
////
//#include <random>//
#pragma endregion //#include
/////////

#pragma region typedef
typedef long long LL;
typedef long double LD;
typedef unsigned long long ULL;
#pragma endregion //typedef
////定数
const int INF = (int)1e9;
const LL MOD = (LL)1e9+7;
const LL LINF = (LL)4e18+20;
const LD PI = acos(-1.0);
const double EPS = 1e-9;
/////////
using namespace::std;

void solve(){
	string str;
	int w;
	cin>>str>>w;
	int size = str.size();
	for(int i=0;i<size;++i){
		if(i%w ==0){
			cout << str[i];
		}
	}
	cout << endl;
}

#pragma region main
signed main(void){
	std::cin.tie(0);
	std::ios::sync_with_stdio(false);
	std::cout << std::fixed;//小数を10進数表示
	cout << setprecision(16);//小数点以下の桁数を指定//coutとcerrで別	

	solve();
}
#pragma endregion //main()


Measured memory_bytes: 256
//==========================Head files==========================
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<vector>
#include<queue>
#include<cmath>
#include<set>
#include<iostream>
#include<map>
#define LL long long
#define db double
#define mp make_pair
#define pr pair<int, int>
#define fir first
#define sec second
#define pb push_back
#define ms(i, j) memset(i, j, sizeof i)
using namespace std;
//==========================Templates==========================
inline int read() {
    int x = 0, f = 1; char c = getchar();
    while(c < '0' || c > '9'){if (c == '-') f = -1; c = getchar();}
    while(c >= '0' && c <= '9'){x = x * 10 + c - '0'; c = getchar();}
    return x * f;
}
inline LL readl() {
    LL x = 0, f = 1; char c = getchar();
    while(c < '0' || c > '9'){if (c == '-') f = -1; c = getchar();}
    while(c >= '0' && c <= '9'){x = x * 10 + c - '0'; c = getchar();}
    return x * f;
}
int power(int a, int b) {
	int ans = 1;
	while (b) {
		if(b & 1) ans = ans * a;
		b >>= 1; a = a * a;
	}
	return ans;
}
int power_mod(int a, int b, int mod) {
	a %= mod;
	int ans = 1;
	while (b) {
		if(b & 1) ans = (ans * a) % mod;
		b >>= 1, a = (a * a) % mod;
	}
	return ans;
}
LL powerl(LL a, LL b) {
	LL ans = 1ll;
	while (b) {
		if(b & 1ll) ans = ans * a;
		b >>= 1ll;a = a * a;
	}
	return ans;
}
LL power_modl(LL a, LL b, LL mod) {
	a %= mod;
	LL ans = 1ll;
	while (b) {
		if(b & 1ll) ans = (ans * a) % mod;
		b >>= 1ll, a = (a * a) % mod;
	}
	return ans;
}
LL gcdl(LL a, LL b) {return b == 0 ? a : gcdl(b, a % b);}
LL abssl(LL a) {return a > 0 ? a : -a;}
int gcd(int a, int b) {return b == 0 ? a : gcd(b, a % b);}
int abss(int a) {return a > 0 ? a : -a;}
//==========================Main body==========================
#define LD "%I64d"
#define D "%d"
#define pt printf
#define sn scanf
#define pty printf("YES\n")
#define ptn printf("NO\n")
//==========================Code here==========================
LL n;
struct gg {
	LL a, b;
} p[200000 + 5];
bool cmp(gg x, gg y) {
	if (x.b == y.b) return x.a < y.a;
	return x.b < y.b;
}
int main() {
	cin >> n;
	for (LL i = 1; i <= n; ++i) scanf("%lld%lld", &p[i].a, &p[i].b);
	sort(p + 1, p + 1 + n, cmp);
	LL now = 0;
	for (LL i = 1; i <= n; ++i) {
		if (now + p[i].a <= p[i].b) {
			now += p[i].a;
		} else return printf("No\n"), 0;
	}
	printf("Yes\n");
	return 0;
}

Measured memory_bytes: 3328
import java.util.*;
public class Main {
	public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        int X = sc.nextInt();
        int T = sc.nextInt();
        
        int times = N/X + ((N%X == 0) ? 0 : 1);
        System.out.println(times*T);
    }
}


Measured memory_bytes: 35716
#include <math.h>
#include <stdlib.h>
#include <string.h>
#include <algorithm>
#include <array>
#include <iomanip>
#include <iostream>
#include <limits>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>

using namespace std;

#define rep(i, n) for (int i = 0; i < (n); i++)
#define loop(i, a, n) for (int i = a; i < (n); i++)
#define all(in) in.begin(), in.end()
const int INF = 1e9;
const int MOD = 1e9 + 7;
int main() {
    int a, b, c;
    cin >> a >> b >> c;
    cout << a * b / 2 << endl;
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <cmath>
#include <utility>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define _GLIBCXX_DEBUG
#define all(x) x.begin(), x.end()
using namespace std;
typedef long long ll;
typedef pair<int, int> pair;
const int inf = 1000000000; //10^9

int main(){
    int n;
    cin >>n;
    vector<int> h(n);
    rep(i, n) cin >> h[i];
    reverse(all(h));
    int ans = 0;
    int val = 0;
    for (int i = 1; i < n; i++) {
        if (h[i-1] <= h[i]) val++;
        else val = 0;
        ans = max(ans, val);
    }
    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 3756
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int n,i;
    scanf("%d",&n);
    float ar[n];
    double sum=0,total;
    for(i=0;i<n;i++)
    {
       scanf("%f",&ar[i]);
    }
    for(i=0;i<n;i++)
    {
        sum=sum+(1/ar[i]);
    }
   total=1/sum;
 printf("%.14lf\n",total);


}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,a,b) for(int i=a;i<(b);++i)
#define erep(i,a,b) for(int i=a;i<=(int)(b);++i)
#define per(i,a,b) for(int i=(a);i>(b);--i)
#define eper(i,a,b) for(int i=(a);i>=b;--i)
#define fore(i, x, a) for(auto &&x:a) 
#define ITR(i,b,e) for(auto i=(b);i!=(e);++i)
#define pb push_back
#define mp make_pair
#define MOD 1000000007
#define ALL(x) begin(x),end(x)
#define F first
#define S second
const int inf=1001001001; const long long INF=1001001001001001001;
using namespace std;
using ll = long long;
using pii = pair<int,int>;
using vii = vector<int>;
using vll = vector<ll>;
using priority_queue_small = priority_queue<int, vector<int>, greater<int> >;
template<class T>using vv = vector<T>;
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a = b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a = b; return 1; } return 0; }
template<typename A, size_t N, typename T>
void Fill(A (&array)[N], const T &val){
    std::fill( (T*)array, (T*)(array+N), val );
}
template<class T> ostream& operator<<(ostream &os,const vector<T> &v) {
    ITR(i,begin(v),end(v))os<<*i<<(i==end(v)-1?"":" ");return os;}
template<class T> istream& operator>>(istream &is,vector<T> &v) {
    ITR(i,begin(v),end(v)) is>>*i;return is;}
template<class T,class U> istream& operator>>(istream &is, pair<T,U> &p) {
    is>>p.first>>p.second;return is;}
template<class T>T gcd(T a, T b){ return b ? gcd(b, a % b) : a; }
template<class T>T lcm(T a, T b){ return a / gcd(a, b) * b; }
int dy[]={0, 1, -1, 0}; int dx[]={1, 0, 0, -1};

int n, q, k;
ll d[100005];
vv<pii> g[100005];

void dfs(int p, int q, ll dist) {
  d[p] = dist;
  for (auto &x : g[p]) {
    if (x.first == q) continue;
    dfs(x.first, p, dist + x.second);
  }
}

int main() {
 cin.tie(0);
 ios::sync_with_stdio(false);
  cin >> n;
  rep(i, 0, n-1) {
    int a, b, c;
    cin >> a >> b >> c;
    a--, b--;
    g[a].pb({b, c}); g[b].pb({a, c});
  }
  cin >> q >> k;
  k--;
  dfs(k, -1, 0);
  while (q--) {
    int x, y;
    cin >> x >> y;
    x--, y--;
    cout << d[x] + d[y] << endl;
  }
  return 0;
}



Measured memory_bytes: 12800
#palace
n = int(input())
t, a = map(int, input().split())
h = list(map(int, input().split()))

b = t - h[0]*0.006
ans = 1

for i, name in enumerate(h, 1):
  temp = t - name*0.006
  if abs(a - temp) < abs(a - b):
    ans = i
    
    b = temp
print(ans)

Measured memory_bytes: 3064
# ------------------------------------------------------------
# THIS IS METADATA FOR ATCODER_TOOLS
# BE CAREFULL WHEN YOU CHANGE THE VALUE
# 
# METADATA::START
# test-1
# input: "1900\n"
# output: "100\n"
# test-2
# input: "3000\n"
# output: "0\n"
# MODE: TEST
# METADATA::FINISH
# 
# you can add your original test case 
# you can select MODE from NONE, DEBUG, RUN, TEST
# problem_url: https://atcoder.jp/contests/abc173/tasks/abc173_a
# submission_url: https://atcoder.jp/contests/abc173/submissions/me
# -------------------------------------------------------------

# snippets
n = gets.to_i
# arr = gets.split(' ').map(&:to_i)
puts 1000 - ((n - 1) % 1000 + 1)

Measured memory_bytes: 14176
n, m, q = gets.strip.split.map(&:to_i)
lr = m.times.map { gets.strip.split.map(&:to_i)}
pq = q.times.map { gets.strip.split.map(&:to_i)}

board = Array.new(n+1){ [0]*(n+1) }

lr.each do |l, r|
  board[l][r]+=1
end

#(0..n).each do |i|
#    p board[i]
#end


(1..n).each do |i|
  (1..n).each do |j|
      board[i][j]+=board[i-1][j]
  end
end

(1..n).each do |i|
  (1..n).each do |j|
      board[i][j]+=board[i][j-1]
  end
end

#p "---"
#(0..n).each do |i|
#    p board[i]
#end

results = []

pq.each do |from, to|
  current = board[to][to] - board[to][from-1] - board[from-1][to] + board[from-1][from-1]
  results << current
end

results.each do |r|
  p r
end


Measured memory_bytes: 48880
#include <iostream>
#include <string>
using namespace std;
 
int main(void) {
	
	int W,H,N;
	cin >> W >> H >> N ;
	int xL = 0, xU = W, yL = 0, yU = H;
	for(int i = 0;i < N;i++)
	{
		int x,y,a;
		cin >> x >> y >> a;

		switch(a)
		{
		case 1: 
			xL = max(x,xL);
			break;
		case 2:
			xU = min(x,xU);
			break;
		case 3:
			yL = max(y,yL);
			break;
		case 4:
			yU = min(y,yU);
			break;
		}	
	}

	cout << (max(xU - xL, 0) * max(yU - yL, 0)) << endl;
}

Measured memory_bytes: 256
//package com.company;

import java.io.*;
import java.util.*;

public class Main {
    public static class Task {

        public void solve(Scanner sc, PrintWriter pw) throws IOException {
            int n = sc.nextInt();
            int[] perm = new int[n];
            for (int i = 0; i < n; i++) {
                perm[sc.nextInt() - 1] = i;
            }
            for (int i = 0; i < n; i++) {
                pw.print(perm[i] + 1);
                pw.print(" ");
            }
            pw.println();
        }
    }

    static long TIME_START, TIME_END;

    public static void main(String[] args) throws IOException {
        Scanner sc = new Scanner(System.in);
//        Scanner sc = new Scanner(new FileInputStream("input"));
        PrintWriter pw = new PrintWriter(new BufferedOutputStream(System.out));
//        PrintWriter pw = new PrintWriter(new FileOutputStream("output"));

        Runtime runtime = Runtime.getRuntime();
        long usedMemoryBefore = runtime.totalMemory() - runtime.freeMemory();
        TIME_START = System.currentTimeMillis();
        Task t = new Task();
        t.solve(sc, pw);
        TIME_END = System.currentTimeMillis();
        long usedMemoryAfter = runtime.totalMemory() - runtime.freeMemory();
        pw.close();
        System.err.println("Memory increased: " + (usedMemoryAfter - usedMemoryBefore) / 1000000);
        System.err.println("Time used: " + (TIME_END - TIME_START) + ".");
    }

    static class Scanner {
        StringTokenizer st;
        BufferedReader br;

        public Scanner(InputStream s) {
            br = new BufferedReader(new InputStreamReader(s));
        }

        public Scanner(FileReader s) throws FileNotFoundException {
            br = new BufferedReader(s);
        }

        public String next() throws IOException {
            while (st == null || !st.hasMoreTokens())
                st = new StringTokenizer(br.readLine());
            return st.nextToken();
        }

        public int nextInt() throws IOException {
            return Integer.parseInt(next());
        }

        public long nextLong() throws IOException {
            return Long.parseLong(next());
        }

        public String nextLine() throws IOException {
            return br.readLine();
        }

        public double nextDouble() throws IOException {
            return Double.parseDouble(next());
        }

        public boolean ready() throws IOException {
            return br.ready();
        }
    }
}


Measured memory_bytes: 44612
input_map = [list(map(int,input().split())) for i in range(3)]


a1 = input_map[0][0]-input_map[0][1]
a2 = input_map[0][0]-input_map[0][2]
a3 = input_map[0][1]-input_map[0][2]
b1 = input_map[0][0]-input_map[1][0]
b2 = input_map[0][0]-input_map[2][0]
b3 = input_map[1][0]-input_map[2][0]

for i in range(1,3):
    if a1!=(input_map[i][0]-input_map[i][1]):print('No');exit()
    if a2!=(input_map[i][0]-input_map[i][2]):print('No');exit()
    if a3!=(input_map[i][1]-input_map[i][2]):print('No');exit()

for i in range(1,3):
    if b1!=(input_map[0][i]-input_map[1][i]):print('No');exit()
    if b2!=(input_map[0][i]-input_map[2][i]):print('No');exit()
    if b3!=(input_map[1][i]-input_map[2][i]):print('No');exit() 

print('Yes')  

Measured memory_bytes: 3064
#include <iostream>
#include <algorithm>
#include <vector>
#include <map>
#include <cmath>
using namespace std;
using ll = long double;
ll t[600010];
int n;
void built(){
	for(int i=0;i<=2*n;i++){
		t[i] = 1;
	}
	for(int i = n-1;i>0;i--){
		t[i] = t[i<<1]*t[i<<1|1];
	}
}

void update(int p,ll a){
	for(t[p+=n] = a;p>1;p >>= 1){
		t[p>>1] = t[p]*t[p^1];
	}
}

ll query(int l, int r){
	ll mn = 1000000000;
	for(l += n, r += n; l<r; l >>= 1,r >>= 1){
		if(l&1) mn *= t[l++];
		if(r&1) mn *= t[--r];
	}
	return mn;
}

map<int,int> mp;
vector<int> v;
int zatu(){
	int now = 0;
	for(auto x:mp){
		v.push_back(x.first);
		now++;
	}
	for(int i=0;i<now;i++){
		mp[v[i]] = i;
	}
	return now;
}
int ti[100010],l[100010],r[100010];
ll a[100010];
int main(){
	cout.precision(20);
	int i,m,q;
	cin >> m;
	for(i=0;i<m;i++){
		cin >> ti[i] >> a[i];
		mp[ti[i]]++;
	}
	cin >> q;
	for(i=0;i<q;i++){
		cin >> l[i] >> r[i];
		mp[l[i]]++; mp[r[i]]++;
	}
	n = zatu();
	ll te = 10;
	built();
	for(i=0;i<m;i++){
		update(mp[ti[i]],(te - a[i])/te);
	}
	for(i=0;i<q;i++){
		ll x = query(mp[l[i]],mp[r[i]] + 1);
		cout << x << endl;
	}
}


Measured memory_bytes: 30600
#include <algorithm>
#include <cmath>
#include <climits>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <fstream>
#include <iostream>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>
#include <cassert>
#include <functional>

using namespace std;

#define LOG(...) printf(__VA_ARGS__)
//#define LOG(...)
#define FOR(i,a,b) for(int i=(int)(a);i<(int)(b);++i)
#define REP(i,n) for(int i=0;i<(int)(n);++i)
#define ALL(a) (a).begin(),(a).end()
#define RALL(a) (a).rbegin(),(a).rend()
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort((c).begin(),(c).end())
#define RSORT(c) sort((c).rbegin(),(c).rend())
#define CLR(a) memset((a), 0 ,sizeof(a))

typedef long long ll;
typedef unsigned long long ull;
typedef vector<bool> vb;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<vb> vvb;
typedef vector<vi> vvi;
typedef vector<vll> vvll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;

const int dx[] = { -1, 0, 1, 0 }; const int dy[] = { 0, 1, 0, -1 };
struct pos{
	int x;
	int y;
};
struct rel{
	int to;
	int dis;
};
int main() {
	int n, hx, hy, dx, dy;
	while (cin >> n >> hx >> hy >> dx >> dy, n|hx|hy|dx|dy){
		vector<pos> p;
		REP(k, n){
			int x, y;
			cin >> x >> y;
			p.push_back({ x, y });
		}
		vector<vector<double>> r(n + 1, vector<double>(n + 1));
		vector<double> dr(n);
		REP(i, n + 1){
			if (i != n)
				dr[i] = hypot(dx - p[i].x,dy - p[i].y);

			for (int j = 0; j < n + 1; j++){
				if (i == j)continue;
				if (i != n  && j != n)r[i][j] = hypot(p[i].x - p[j].x,p[i].y - p[j].y);
				else if (i == n)r[i][j] = hypot(hx - p[j].x,hy - p[j].y);
				else if (j == n)r[i][j] = hypot(p[i].x - hx,p[i].y - hy);
			}
		}

		bool b[21] = { false };
		REP(i, n)b[i] = true;
		int b_n = n;
		bool flag = false;
		function<void(double dis, int from)> f = [&](double dis, int from){
			if (flag)return;
			for (int i = 0; i < n; i++){
				if (b[i] && (dis + r[from][i] + 1e-8) >= dr[i])return;
			}
			
			if (b_n != 0){
				for (int i = 0; i < n && !flag; i++){
					if (b[i]){
						b[i] = false;
						b_n--;
						f(dis + r[from][i], i);
						b[i] = true;
						b_n++;
					}
				}
			}
			else{
				flag = true;
				return;
			}

			return;
		};
		f(0.0, n); 
		cout << (flag ? "YES" : "NO") << endl;
	}
}

Measured memory_bytes: 1228
//g++ -std=c++14 test.cpp -o test.out
#include <string.h>
#include <stdlib.h>
#include <math.h>
#include <cassert>
#include <algorithm>
#include <functional>
#include <iostream>
#include <iomanip>
#include <vector>
#include <queue>
#include <map> 
#include <utility>
using namespace std;
 
void solve(double a,double b,double x,double* ans){
  double threshold = a*a*b/2.0;
  if(threshold<=x){
    double radius = (2.0*a*a*b - 2.0*x)/(a*a*a);
    (*ans) = atan(radius)*180.0/M_PI;
  }else{
    double radius = a*b*b/(2.0*x);
    (*ans) = atan(radius)*180.0/M_PI;
  }
}
 
int main(){
	double a,b,x;
	double ans = 0;
	cin>>a>>b>>x;
 
	solve(a,b,x,&ans);
 
	cout << fixed << setprecision(10) << ans << endl;
	return 0;
}

Measured memory_bytes: 384
#include <stdio.h>
 
#define N 101
 
int M[N][N] = {};
int d[N],f[N];
int t,n;
char c[N];
 
void visit(int v) {
    int i;
 
    c[v] = 'G';
    d[v] = ++t;
    for (i=1;i<=n;i++) {
        if (M[v][i] == 1 && c[i] == 'W') {
            visit(i);
        }
    }
    c[v] = 'B';
    f[v] = ++t;
}
 
void dfs() {
    int i;
    for (i=1;i<=n;i++) c[i] = 'W';
    t = 0;
    for (i=1;i<=n;i++) if (c[i] == 'W') visit(i);
}
 
int main() {
    int i,j;
    int u,k,v;
 
    scanf("%d", &n);
    for (i=1;i<=n;i++) {
        scanf("%d%d",&u,&k);
        for (j=1;j<=k;j++) {
            scanf("%d",&v);
            M[u][v] = 1;
        }
    }
 
    dfs();
 
    for (i=1;i<=n;i++) {
        printf("%d %d %d\n",i,d[i],f[i]);
    }
 
    return 0;
}

Measured memory_bytes: 636
#include <stdio.h>

int main(){
  int N;
  scanf("%d",&N);
  int A[N];
  int i,j,ANS;
  for(i=0;i<N;i++){
    scanf("%d",&A[i]);
  }

  ANS=0;
  for(i=0;i<N;i++){
    j=0;
    while(A[i]%2==0){
      j++;
      A[i]=A[i]/2;
    }
    ANS=ANS+j;
  }

  printf("%d", ANS);
  return 0;
}


Measured memory_bytes: 256
#pragma region head
#include <bits/stdc++.h>
using namespace std;
#define pb push_back
#define fi first
#define se second
#define mp make_pair
#define all(x) (x).begin(), (x).end()
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define repp(i, a, b) for (int i = a; i <= (b); ++i)
#define repr(i, a, b) for (int i = a; i >= (b); --i)
#define bit(n) (1LL << (n))
#define len(x) ((ll)(x).size())
#define debug(var) cout << "[" << #var << "]\n" << var << endl
#define int long long
typedef long long ll;
#define double long double
typedef double ld;
const int INF = 1001001001001001001ll;
const ll LINF = 1001001001001001001ll;
const int MOD = 1000000007;
const double EPS = 1e-9;
const double PI = acos(-1.0);

template <typename T>
ostream& operator<<(ostream& s, const vector<T>& v) {
  int len = v.size();
  for (int i = 0; i < len; ++i) {
    s << v[i];
    if (i < len - 1)
      s << ' ';
  }
  return s;
}

template <typename T>
ostream& operator<<(ostream& s, const vector<vector<T>>& vv) {
  int len = vv.size();
  for (int i = 0; i < len; ++i) {
    s << vv[i];
    if (i != len - 1)
      s << '\n';
  }
  return s;
}

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

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

__attribute__((constructor)) void initial() {
  cin.tie(nullptr);
  ios::sync_with_stdio(false);
  cout << fixed << setprecision(15);
}
#pragma endregion

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

P i_j(int p) {
  return P(p / N, p % N);
}

signed main() {
  cin >> N;

  int M = N * N;
  vector<int> p(M);
  rep(i, M) {
    cin >> p[i];
    p[i]--;
  }

  vector<vector<int>> cnt(N, vector<int>(N, INF));
  rep(i, N) {
    rep(j, N) {
      chmin(cnt[i][j], i);
      chmin(cnt[i][j], N - 1 - i);
      chmin(cnt[i][j], j);
      chmin(cnt[i][j], N - 1 - j);
    }
  }

  vector<vector<bool>> is_occupied(N, vector<bool>(N, true));


  int di[4] = {0, -1, 0, 1}, dj[4] = {1, 0, -1, 0};

  int ans = 0;
  rep(k, M) {
    P now = i_j(p[k]);
    int i = now.fi, j = now.se;
    ans += cnt[i][j];

    is_occupied[i][j] = false;

    queue<P> q;
    q.push(now);

    while (!q.empty()) {
      auto now = q.front();
      int i = now.fi, j = now.se;
      q.pop();

      rep(d, 4) {
        int ni = i + di[d], nj = j + dj[d];
        if (ni < 0 || ni >= N || nj < 0 || nj >= N)
          continue;
        if (chmin(cnt[ni][nj], cnt[i][j] + is_occupied[i][j]))
          q.push(P(ni, nj));
      }
    }
  }
  cout << ans << endl;
}

Measured memory_bytes: 7220
#include<iostream>
#include<algorithm>
#include<string>
#include<vector>
#include<cmath>
#include<map>
#include<iomanip>
#include<queue>
#include<stack>
#include<time.h>
#define rep(i,n)for(ll i=0;i<n;i++)
#define ll long long
using namespace std;
signed main() {
	long double t, x;
	cin >> t >> x;
	cout << t * t / (x*t) << endl;
	getchar(); getchar(); return 0;
}


Measured memory_bytes: 256
#include <iostream>

using namespace std;

int main()
{
    char a[2];
    cin>>a;
    if(a[0]=='9' || a[1]=='9')
        cout<<"Yes";//<<endl<<"The one's digit of "<<a<<" is 9.";
    else
        cout<<"No";//<<endl<<a<<" does not contain 9.";
    return 0;
}


Measured memory_bytes: 3556
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <set>
#include <unordered_map>
#include <unordered_set>
#include <numeric>
#include <cmath>
#include <tuple>
#include <bitset>
#include <utility>
 
#define push emplace_back
#define each(i, x) for (auto i=0; i < x; i++)
using ull = unsigned long long;
constexpr auto mod = 1000000007;
 
using namespace std;
template <typename T> inline void dump(const T& x) { cout << "[" << x << "]" << endl; }
template <typename T> inline void dump(const vector<T>& x) { for (const auto v : x) { cout << v << " "; } cout << endl; }
template <typename T> inline void sort_asc(vector<T>& x) { std::sort(x.begin(), x.end()); }
template <typename T> inline void sort_desc(vector<T>& x) { std::sort(x.begin(), x.end(), greater<T>()); }

ull f(ull n) {
  if (n % 2 == 0) {
    return n / 2;
  } else {
    return (3 * n) + 1;
  }
}

ull a(ull first, ull i) {
  if (i == 1) {
    return first;
  } else {
    return f(a(first, i-1));
  }
}
 
int main() {
  ull s;
  cin >> s;

  unordered_set<ull> sss;
  ull result = 0;
  each(i, 1000000) {
    auto n = i + 1;
    auto item = a(s, n);

    if (sss.count(item) == 1) {
      result = n;
      break;
    } else {
      sss.emplace(item);
    }
  }

  cout << result << endl;
 
  return 0;
}


Measured memory_bytes: 384
#include<cmath>
#include<cstdio>
#include<cstring>
#include<iostream>
#include<algorithm>
#define lop(c,l) for(int c=1;c<=(l);++c)
#define loop(c,l) for(int c=0;c<(l);++c)
using namespace std;

#define int long long
const int mod=1000000007;
int n,res,sc,las;
int cnt[256];
char str[200001];
inline int mul(const int& a,const int& b){
	return a*b%mod;
}
inline int add(const int& a,const int& b){
	return (a+b)%mod;
}
signed main(signed,char**,char**){
	scanf("%lld",&n);
	scanf(" %s",str);
	las=1;
	loop(i,n){
		if(cnt[str[i]]==0) ++sc;
		int ad=1;
		for(int j='a';j<='z';++j) if(str[i]!=j&&cnt[j]) ad=mul(ad,cnt[j]+1);
		res=add(res,ad);
		++cnt[str[i]];
	}
	printf("%lld",res);
	exit(0);
}

Measured memory_bytes: 384
#define _USE_MATH_DEFINES

#include <cmath>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <vector>
#include <algorithm>
#include <limits>
#include <cstring>
#include <string>
#include <queue>
#include <map>
#include <set>
#include <bitset>

using namespace std;

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

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

const int Maxn = 100010;
const int MOD = (int) 1e9 + 7;

int n;

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    cin >> n;
    map<int, int> mp;
    for (int i = 0; i < n; ++i) {
        int x;
        cin >> x;
        mp[x]++;
    }

    int ans = n, cnt = 0;
    for (auto &m : mp) {
        if (m.second >= 3) {
            if (m.second % 2) {
                ans -= (m.second - 1) / 2 * 2;
                m.second = 1;
            } else {
                ans -= (m.second - 2) / 2 * 2;
                m.second = 2;
            }
        }
        if (m.second == 2){
            cnt++;
        }
    }

    ans -= cnt / 2 * 2;
    if (cnt % 2) ans -= 2;
    cout << ans << endl;
}


Measured memory_bytes: 4992
#include<cstdio>
#include<cstdlib>
#include<cstring>

struct Node{
    int key;
    Node *next, *prev;
};

Node *nil;

Node* listSearch(int key){
    Node *cur = nil->next;
    while((cur != nil) && (cur->key != key)){
        cur = cur->next;
    }
    
    return cur;
}

void init(){
    nil = (Node *)malloc(sizeof(Node));
    nil->next = nil;
    nil->prev = nil;
}

void printList(){
    Node *cur = nil->next;
    int isf = 0;
    while(1){
        if(cur == nil) break;
        
        if(isf++ > 0){
            printf(" ");
        }
        
        printf("%d", cur->key);
        cur = cur->next;
    }
    
    printf("\n");
}

void deleteNode(Node *t){
    if(t == nil){
        return;
    }
    
    t->prev->next = t->next;
    t->next->prev = t->prev;
    free(t);
}

void deleteFirst(){
    deleteNode(nil->next);
}

void deleteLast(){
    deleteNode(nil->prev);
}

void deleteKey(int key){
    deleteNode(listSearch(key));
}

void insert(int key){
    Node *x = (Node *)malloc(sizeof(Node));
    x->key = key;
    x->next = nil->next;
    nil->next->prev = x;
    nil->next = x;
    x->prev = nil;
}

int main(){
    int key, n, i;
    int size = 0;
    char com[20];
    int np = 0;
    int nd = 0;
    
    scanf("%d", &n);
    
    init();
    
    for(int i = 0; i < n; i++){
        scanf("%s%d", com, &key);
        
        if(com[0] == 'i'){
            insert(key);
            np++;
            size++;
        }
        
        else if(com[0] == 'd'){
            if(strlen(com) > 6){
                if(com[6] == 'F'){
                    deleteFirst();
                }
                
                else if(com[6] == 'L'){
                    deleteLast();
                }
            }    
            else{
                deleteKey(key);
                nd++;
            }
                
            size--;
        }
    }
    
    printList();
    
    return 0;
}


Measured memory_bytes: 33812
using System;

class Test
{
    public static void Main()
    {
        string s = Console.ReadLine();
        string[] ss = s.Split(' ');
        
        int a = int.Parse(ss[0]);
        int b = int.Parse(ss[1]);
        int c = int.Parse(ss[2]);
        
        int count = 0;
        for(int i = a; i <= b; i++)
        {
            int y = c % i;
            
            if(y == 0)
            {
                count += 1;
            }
        }
        
        Console.WriteLine(count);
    }
}


Measured memory_bytes: 17928
#include <bits/stdc++.h>
using namespace std;
 
int64_t MOD = 1e9+7;
 
//---------- べき乗 ----------
int64_t power(int64_t a, int64_t n){
    if(n == 0) return 1;
    
    int64_t res = 1;
    while(n > 0){
        if(n % 2 == 1) res = res * a % MOD;
        a = a * a % MOD;
        n /= 2;
    }
 
    return res;
}
 
//---------- 逆元 ----------
int64_t inv(int64_t a){
    return power(a, MOD-2);
}
 
 
//--------- 組み合わせ ---------
int64_t comb(int64_t n, int64_t r){
  int64_t bunbo = 1, bunshi = 1;
 
  for(int i=0; i<r; i++){
    bunbo = bunbo * (r-i) % MOD;
    bunshi = bunshi * (n-i) % MOD;
  }
 
  return bunshi * inv(bunbo) % MOD;
}
 
 
int main(){ 
  int64_t N, A, B;
  cin >> N >> A >> B;
 
  int64_t ans = power(2, N) - comb(N, A) - comb(N, B) - 1;
  while(ans < 0) ans += MOD;
  
  cout << ans << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
int main()
{
	int a,b;
	char s[100];
	cin>>a>>b;
	cin>>s;
	if(s[a]!='-')
	{
		cout<<"No";
		return 0;
	}
	for (int i = 0; i < strlen(s); i++)
	{
		if(i==a)
			continue;
		if(s[i]-'0'<0||s[i]-'0'>9)
		{
			cout<<"No";
			return 0;
		}
	}
	cout<<"Yes";
	return 0;
}

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

int main(){
	int h, w; cin >> h >> w; std::vector<int> li(26, 0);
	for(int i = 0; i < h; i++){
		for(int j = 0; j < w; j++){
			char a; cin >> a;
			
			li[a - 'a']++;
		}
	}
	
	int A = (h / 2) * (w / 2);
	int B = h % 2 * (w / 2) + w % 2 * (h / 2);
	int C = (h % 2) * (w % 2);
	
	for(int i = 0; i < 26; i++){
		while(A and li[i] >= 4){
			li[i] -= 4;
			A--;
		}
	}
	
	for(int i = 0; i < 26; i++){
		while(B and li[i] >= 2){
			li[i] -= 2;
			B--;
		}
	}
	
	for(int i = 0; i < 26; i++){
		while(C and li[i] >= 1){
			li[i] -= 1;
			C--;
		}
	}
	
	if(A or B or C) cout << "No" << endl;
	else cout << "Yes" << endl;
	return 0;
}


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

int n, a, c[100009];
int main() {
  cin >> n;
  for (int i = 0; i < n; i++) {
    cin >> a;
    c[a]++;
  }
  int ret = 0;
  for (int i = 0; i <= 100000; i++) ret = max(ret, c[i] + c[i + 1] + c[i + 2]);
  cout << ret << endl;
}


Measured memory_bytes: 640
#include <bits/stdc++.h>
#define f(i,a,b) for(int i = a; i < b ; i++)
using namespace std;
typedef long long int ll;
typedef long double ld;
int h[100010], dp[100010];
int main(){
	int n;
	cin>>n;
	f(i,0,n) cin>>h[i];
	dp[1]=abs(h[1]-h[0]);
	f(i,2,n) dp[i]=min(dp[i-2]+abs(h[i]-h[i-2]),dp[i-1]+abs(h[i]-h[i-1]));
	cout<<dp[n-1];
}

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

#define rep(i,n) for(int i=0; i<n; i++)
#define all(x) (x).begin(),(x).end()
#define INF (1e9)

int main(){
  ll n,a[100010],b[100010],cnt=0;
  cin >> n;
  rep(i,n){
    cin >> a[i] >> b[i];
  }

  for(int i=n-1; i>=0; i--){
    if((cnt+a[i])%b[i]!=0)cnt += b[i]-(cnt+a[i])%b[i];
  }

  cout << cnt << endl;
}

Measured memory_bytes: 1792
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <map>
#include <cmath>
#include <queue>
#include <numeric>
#include <climits>
#include <iterator>
#include <iomanip>
#include <stack>
#include <set>
#include <cstdio>
#include <bitset>
#include <functional>
#include <tuple>
#include <list>
#include <deque>
using namespace std;
typedef pair<int, int> P;

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

typedef long long ll;
typedef vector<int> VI;

int main() {
    cin.tie(0);
   	ios::sync_with_stdio(false);
    priority_queue<ll> p;
    while(1){
        string c; cin >> c;
        if(c=="end") break;
        if(c=="insert") {
            ll n; cin >> n;
            p.push(n);
        }
        if(c=="extract"){
            cout << p.top() << endl;
            p.pop();
        }
    }
    
	return 0;
}


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

#define int long long
typedef pair<int,int>pint;
typedef vector<int>vint;
typedef vector<pint>vpint;
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define all(v) (v).begin(),(v).end()
#define rep(i,n) for(int i=0;i<(n);i++)
#define reps(i,f,n) for(int i=(f);i<(n);i++)
#define each(it,v) for(__typeof((v).begin()) it=(v).begin();it!=(v).end();it++)
template<class T,class U>inline void chmin(T &t,U f){if(t>f)t=f;}
template<class T,class U>inline void chmax(T &t,U f){if(t<f)t=f;}

int N,T[55];
bool dp[2][1050][1050];

signed main(){
    cin>>N;
    rep(i,N)cin>>T[i];

    dp[0][0][0]=true;
    int sum=0;
    rep(i,N){
        rep(j,1000)rep(k,1000){
            if(!dp[i&1][j][k])continue;
            int l=sum-j-k;
            dp[(i+1)&1][j+T[i]][k]=true;
            dp[(i+1)&1][j][k+T[i]]=true;
            dp[(i+1)&1][j][k]=true;
            dp[i&1][j][k]=false;
        }
        sum+=T[i];
    }


    int mi=1<<25;
    rep(i,1000)rep(j,1000)if(dp[N&1][i][j]){
        int k=sum-i-j;
        chmin(mi,max(max(i,j),k));
    }
    cout<<mi<<endl;

    return 0;
}

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

using namespace std;

const int N = 2e5 + 3;
const int M = 1e6 + 7;
const long long MOD = 1e9 + 7;
const long long INF = 1e18 + 9;
const int SM = 1e3 + 8;
const int LG = 20;
const double EPS = 3e-16;

int main(){
//	freopen("ex.in", "r", stdin);
//	freopen("ex.out", "w", stdout);
	ios_base::sync_with_stdio(false);
	cin.tie(0), cout.tie(0);
	int n; string s;
	cin >> n >> s;
	
	if(s.substr(0, n / 2) == s.substr(n / 2, n / 2) && n % 2 == 0){
		cout << "Yes";
	}
	else {
		cout << "No";
	}
	return 0;
}


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

#include <limits.h>

using namespace std;

typedef long long ll;

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;
}

const int INF = INT_MAX / 2;

int main(void) {
    int N;
    cin >> N;

    int acc = 0;
    vector<int> W(N);
    for (int i = 0; i < N; i++) {
        cin >> W[i];
        acc += W[i];
    }

    int x = 0, y = acc, m = INF;
    for (int i = 0; i < N; i++) {
        x += W[i];
        y -= W[i];
        chmin(m, abs(x - y));
    }

    cout << m << endl;

    return 0;
}


Measured memory_bytes: 256
#pragma GCC optimize("03")
#include <bits/stdc++.h>

using namespace std;

const int N = 3e2 + 1;
double n, dp[N][N][N];

double f(int i, int j, int k)
{
	if (i == 0 and j == 0 and k == 0) return 0;
	double& res = dp[i][j][k];
	if (res != -1) return res;
	double m = i + j + k;
	res = n / m;
	
	if (i > 0) res += i * f(i - 1, j, k) / m;
	if (j > 0) res += j * f(i + 1, j - 1, k) / m;
	if (k > 0) res += k * f(i, j + 1, k - 1) / m;
	
	return res;
}

int main()
{
	cin.tie(NULL);
	ios_base::sync_with_stdio(false);
	
	cin >> n;
	int cnt[3] = {};

	for (int i = 0; i < n; ++i)
	{
		int temp;
		cin >> temp;
		cnt[temp - 1]++;
	}
	
	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(10) << f(cnt[0], cnt[1], cnt[2]) << "\n";
}


Measured memory_bytes: 213376
#include <algorithm>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <string>

const int MaxN = 40000 + 5, MaxLen = 670;
const long long Dig = 1000000000000000000;

struct bign {
	int len;
	long long a[MaxLen];
};

inline std::istream& operator >> (std::istream& in, bign &x) {
	std::string str;
	std::cin >> str;
	x.len = (str.length() - 1) / 18 + 1;
	memset(x.a, 0, sizeof x.a);
	for (int i = 0; str[i] != '\0'; ++i) {
		long long d = (str.length() - i - 1) / 18;
		x.a[d] = x.a[d] * 10 + str[i] - '0';
	}
	return in;
}

inline std::ostream& operator << (std::ostream& out, bign x) {
	if (x.len == 0) {
		printf("%lld", 0);
		return out;
	}
	printf("%lld", x.a[x.len - 1]);
	for (int i = x.len - 2; i >= 0; --i)
		printf("%018lld", x.a[i]);
	return out;
}

inline void operator += (bign &x, const bign &y) {
	x.len = std::max(x.len, y.len);
	for (int i = 0; i < x.len; ++i) {
		x.a[i] += y.a[i];
		if (x.a[i] >= Dig) {
			x.a[i + 1]++;
			x.a[i] -= Dig;
		}
	}
	if (x.a[x.len] != 0) x.len++;
}

inline void operator -= (bign &x, const bign &y) {
	for (int i = 0; i < x.len; ++i) {
		x.a[i] -= y.a[i];
		if (x.a[i] < 0) {
			x.a[i] += Dig;
			x.a[i + 1]--;
		}
	}
	while (x.len > 0 && x.a[x.len - 1] == 0) x.len--;
}

inline bool operator == (const bign &x, const bign &y) {
	if (x.len != y.len) return false;
	for (int i = 0; i < x.len; ++i)
		if (x.a[i] != y.a[i]) return false;
	return true;
}

inline bool operator > (const bign &x, const bign &y) {
	if (x.len < y.len) return false;
	if (x.len > y.len) return true;
	for (int i = x.len - 1; i >= 0; --i) {
		if (x.a[i] > y.a[i]) return true;
		if (x.a[i] < y.a[i]) return false;
	}
	return false;
}

int N;
bign X;
bign _0, _1, _2, _3;
bign F[MaxN], G[MaxN];
bign ans, x;

void init() {
	scanf("%d", &N);
	std::cin >> X;

	_0.len = 0;
	_1.len = 1, _1.a[0] = 1;
	_2.len = 1, _2.a[0] = 2;
	_3.len = 1, _3.a[0] = 3;
}

void dfs(int n) {
	if (x == _0) {
		ans = _0;
		return;
	}
	if (n == 0) {
		ans = _1;
		return;
	}

	x -= _1;
	if (x > F[n - 1]) {
		x -= F[n - 1]; x -= _1;
		dfs(n - 1);
		ans += G[n - 1]; ans += _1;
	} else {
		dfs(n - 1);
	}
}

void solve() {
	F[0] = G[0] = _1;
	for (int i = 1; i <= N; ++i) {
		F[i] = F[i - 1];
		F[i] += F[i - 1]; F[i] += _3;
		G[i] = G[i - 1];
		G[i] += G[i - 1]; G[i] += _1;
	}

	x = X;
	dfs(N);
	std::cout << ans << std::endl;
}

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

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

int64_t euclid(int64_t a,int64_t b){
    
    int64_t warareru=b;
    int64_t waru=a;
    int64_t amari;
    while(true){
        amari = warareru%waru;
        if(amari==0)return waru;
        warareru = waru;
        waru = amari;
    }
}

int64_t reigai(int64_t moto,int64_t c,int64_t d,int64_t kobaisu){
    return (moto/c)+(moto/d)-(moto/kobaisu);
}

int main(void){
    int64_t a,b,c,d;
    cin>>a>>b>>c>>d;
    
    int64_t kobaisu = (c*d)/euclid(c,d);
    int64_t hoge = a-1;
    
    cout<<b-a+1-(reigai(b,c,d,kobaisu)-reigai(hoge,c,d,kobaisu))<<endl;
    
    
}


Measured memory_bytes: 256
//# define FLAG
///delet....................................
# include   <bits/stdc++.h>
using namespace std;
# define    pb                      push_back
# define    mp                      make_pair
# define    IOS                     ios::sync_with_stdio(false)
# define    mem(a,b)                memset(a,b,sizeof(a))
# define    FO(i,n,a)               for(int i=n; i>=a; --i)
# define    FOR(i,a,n)              for(int i=a; i<=n; ++i)
# define    MAX(a,b)                ((a)>(b)?(a):(b))
# define    MIN(a,b)                ((a)<(b)?(a):(b))
# define    lowbit(x)               ((x)&(-x))
# define    LINF                    0xfcfcfcfcfcfcfcf
# define    INF                     0x3f3f3f3f
# define    MOD                     1000000007
# define    eps                     0.00000001
# define    pi                      3.141592653
# define    ee                      2.718281828459
# define    hr                      ptc('\n')
# define    kb                      ptc(' ')
# define    bug                     puts("H");
# pragma    comment(linker,"/STACK:1024000000,1024000000")
typedef     pair<int,int>           PII;
typedef     vector<int>             VI;
typedef     long long               LL;
typedef     unsigned long long      ULL;
inline char gtc() {
    static char buf[1000000],*p1=buf-1,*p2=buf-1;
    return p1==p2&&(p2=(p1=buf-1)+fread(buf,1,1000000,stdin),p1==p2)?EOF:*++p1;
}
static char bufout[2000000],*chout=bufout-1;
inline void ptc(char ch) {
    *++chout=ch;
}
# define    Template                int
inline Template read() {
    char ch=gtc();
    while(!(ch>='0'&&ch<='9'||ch=='-'))ch=gtc();
    Template sum=0,flag=(ch=='-'?(ch=gtc()):0);
    while(ch>='0'&&ch<='9')sum=sum*10+ch-'0',ch=gtc();
    return flag?-sum:sum;
}
inline void out(Template x) {
    if(x<0)ptc('-'),x=-x;
    if(x>9)out(x/10);
    ptc(x%10+'0');
}
inline void write() {
    fwrite(bufout,1,chout-bufout+1,stdout);
}
///coding...................................

const int N=100005;


int main() {
    IOS;
#ifdef FLAG
    //freopen("in.txt","r",stdin);
    freopen("out.txt","w",stdout);
#endif
    int a,b,c;
    cin>>a>>b>>c;
    if(a==b)cout<<c<<endl;
    else if(a==c)cout<<b<<endl;
    else cout<<a<<endl;
    return 0;
}










///delete FLAG..............................




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

int main() {
  const double pi=3.141592653589;
  double a,b,x;
  cin >> a >> b >> x;
  double ans=0,k=0;
  if(x/a<a*b/2){
    k=(2*x)/(a*b);
    ans=atan(b/k)*180/pi; 
  }
  else if(x/a==a*b/2){
    ans=atan(b/a)*180/pi; 
  }
  else {
    k=((2*x)/(a*a))-b;
    ans=atan((b-k)/a)*180/pi;
  }
  cout << fixed << setprecision(10) << ans << endl;
}


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

#define rp(i, k, n) for (int i = k; i < n; i++)
typedef long long ll;
typedef double ld;



template<class T>inline bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>inline bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
const ll INF = 1ll << 60;
const ll MOD = 1e9 + 7ll;
const double PI=3.14159265358979323846;




int main() {
    string S;
    cin >> S;
    int Q;
    cin >> Q;
    bool r = false;
    rp(i, 0, Q) {
        int T;
        scanf("%d", &T);
        if(T == 1) r = !r;
        if(T == 2) {
            int f; string c;
            cin >> f >> c;
            if(f == 1) {
                if(r) {
                    S += c;
                }
                 else S.insert(0, c);
            }
            else {
                if(r) {
                    S.insert(0, c);
                }
                else S += c;
            }            
        }
    }
    if(r) reverse(S.begin(), S.end());
    cout << S << endl;
    return 0;

}

Measured memory_bytes: 3924