akhauriyash/Code-Regression huggingface dataset:
#include<cstdio>
#include<cstring>
#include<string>
#include<iostream>
#include<cmath>
#include<algorithm>
#include<queue>
#include<map>
#include<ctime>
using namespace std;
int read()
{
	int x=0,f=1;char c=getchar();
	while(c==' '||c=='\n'||c=='-')
	{if(c=='-') f=-f;c=getchar();}
	while(c>='0'&&c<='9')
	{x=x*10+(c-'0');c=getchar();}
	return x*f;
}
#define ulint long long int
ulint a,b,n;
int main(void)
{
	//freopen("working.in","r",stdin);
	//freopen("working.out","w",stdout);
	cin>>n>>a>>b;
	if((b-a)%2==1)
		cout<<min((a+b-1)/2,(n+n-a-b+1)/2)<<endl;
	else cout<<(b-a)/2<<endl;
	return 0;
}
//	freopen("working.in","r",stdin);
//	freopen("working.out","w",stdout);

Measured memory_bytes: 888
class Node:
    def __init__(self, parent, left, right):
        self.parent, self.left, self.right = parent, left, right

N = int(input())
T = [Node(None, None, None) for _ in range(N)]
for t in T:
    i, left, right = map(int, input().split())
    if left != -1:
        T[i].left = left
        T[left].parent = i
    if right != -1:
        T[i].right = right
        T[right].parent = i

def get_sibling(i):
    if T[i].parent == None:
        return -1
    if i != T[T[i].parent].left and T[T[i].parent].left != None:
        return T[T[i].parent].left
    if i != T[T[i].parent].right and T[T[i].parent].right != None:
        return T[T[i].parent].right
    return -1

def get_depth(i):
    depth = 0
    while T[i].parent != None:
        depth += 1
        i = T[i].parent
    return depth

def get_height(i):
    h1, h2 = 0, 0
    if T[i].left != None:
        h1 = get_height(T[i].left) + 1
    if T[i].right != None:
        h2 = get_height(T[i].right) + 1
    return max(h1, h2)

for i, t in enumerate(T):
    print('node {}:'.format(i), end=' ')
    parent = t.parent if t.parent != None else -1
    print('parent = {},'.format(parent), end=' ')
    sibling = get_sibling(i)
    print('sibling = {},'.format(sibling), end=' ')
    degree = 0
    if t.left != None:
        degree += 1
    if t.right != None:
        degree += 1
    print('degree = {},'.format(degree), end=' ')
    depth = get_depth(i)
    print('depth = {},'.format(depth), end=' ')
    height = get_height(i)
    print('height = {},'.format(height), end=' ')
    if t.parent == None:
        node = 'root'
    elif t.left == None and t.right == None:
        node = 'leaf'
    else:
        node = 'internal node'
    print(node)


Measured memory_bytes: 5636
import java.util.Scanner;

public class Main {
    public static void main(String[] args) throws Exception {
		Scanner sc = new Scanner(System.in);
		// 入力値
		int n = sc.nextInt();
		int m = sc.nextInt();
		
		int ok = 0;
		int ng = 0;
		int[] ac = new int[n];
		int[] wa = new int[n];
		for(int i=0;i<m;i++){
			int idx = sc.nextInt();
			String s = sc.next();
			if("AC".equals(s)){
				if(ac[idx-1]==0){
					ok++;
					ng+=wa[idx-1];
				}
				ac[idx-1] = 1;
			}else if("WA".equals(s)){
				if(ac[idx-1]==0) wa[idx-1]++;
			}
		}
		sc.close();
		System.out.println(ok+" "+ng);
	}
}

Measured memory_bytes: 63712
// g++ -std=c++14

/*
     
    Today might be the chance to grasp the chance to let your talent bloom.
    May be tomorrow, the day after, or next year...
    May be even when you are 30. I'm not sure if physique has anything to do with it
    but if you think that it will never come, it probably never will.
     
    - Tooru Oikawa.
     
    */

#include <bits/stdc++.h>

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

#define endl "\n"
#define fi first
#define se second
#define pb(x) push_back(x)
#define mp(x, y) make_pair(x, y)
#define MEMS(a, b) memset(a, b, sizeof(a))
#define _                             \
    ios_base::sync_with_stdio(false); \
    cin.tie(NULL);                    \
    cout.tie(NULL);
#define __                            \
    freopen("input.txt", "r", stdin); \
    freopen("output.txt", "w", stdout);
#define all(c) c.begin(), c.end()
#define inf 1000000000000000001
#define pii pair<int, int>
#define tr(...)                                       \
    cout << __FUNCTION__ << ' ' << __LINE__ << " = "; \
    trace(#__VA_ARGS__, __VA_ARGS__)

template <typename S, typename T>
ostream &operator<<(ostream &out, pair<S, T> const &p)
{
    out << '(' << p.fi << ", " << p.se << ')';
    return out;
}

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

template <typename T>
void trace(const char *name, T &&arg1) { cout << name << " : " << arg1 << endl; }

template <typename T, typename... Args>
void trace(const char *names, T &&arg1, Args &&... args)
{
    const char *comma = strchr(names + 1, ',');
    cout.write(names, comma - names) << " : " << arg1 << " | ";
    trace(comma + 1, args...);
}

#define int ll

void solve()
{
    int k;
    cin >> k;
    int ans = 0;
    for(int i = 1 ; i <= k ; i++) {
        for(int j = 1 ; j <= k ; j++) {
            for(int l = 1 ; l <= k ; l++) {
                ans += __gcd(i, __gcd(j,l));
            }
        }
    } 

    cout << ans << endl;
}
int32_t main()
{
    _
        ll t;
    // cin >> t;
    t = 1;
    while (t--)
        solve();
}

Measured memory_bytes: 3648
N = int(input())
for h in range(1, 3501):
    for n in range(h, 3501):
        a = 4 * h * n - h * N - n * N
        if a == 0:
            break
        w = int((h * n * N) / a)
        if w > 0 and 4 / N == 1 / h + 1 / n + 1 / w:
            print(h, n, w)
            exit()

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

using namespace std;

int sum(int N) {

	int res = 0;
	while (N > 0) {
		res += N % 10;
		N /= 10;
	}
	return res;
}

int main () {

	int N;
	cin >> N;

	auto x = sum(N);
	cout << (N % x == 0 ? "Yes" : "No") << '\n';

	return 0;
}


Measured memory_bytes: 256
#include <stdlib.h>     /* srand, rand */
#include <time.h>       /* time */
#include <bits/stdc++.h>
#include <cmath>
#include <iomanip>
#include <iterator> 
using namespace std;

#define f first
#define s second

#define pb push_back
#define pp pop_back
#define mp make_pair

#define sz(x) (int)x.size()
#define sqr(x) ((x) * 1ll * (x))
#define all(x) x.begin(), x.end()
#define clr(a,v) memset(a, v, sizeof(a))

#define rep(i, l, r) for (int i = (l); i <= (r); i++)
#define per(i, l, r) for (int i = (l); i >= (r); i--)
#define reflex ios_base::sync_with_stdio(false)

#define nl '\n'
#define ioi exit(0);


#define PI 3.14159265

typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;

typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
const int N= (int)1e5 + 7;
const int inf = (int)1e9 + 7;
const int mod = (int)1e9 + 7;
//const int mod = 1000000007;
const ll linf = (ll)1e18 + 7;

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

vector<vector<int>> tab;
int main() { 
	ll x; cin>> x;
	for (ll i = -200; i <= 200; i++) {
		for (ll j = -200; j <= 200; j++) {
			if (i*i*i*i*i - j*j*j*j*j == x) {
				cout<< i <<" "<< j <<endl;
				return 0;
			} 
		}
	}
	return 0;
} 




Measured memory_bytes: 3604
N = int(input())

x = []
y = []
h = []
flag = True
index = 0

for i in range(N):
    _x, _y, _h = map(int, input().split())
    x.append(_x)
    y.append(_y)
    h.append(_h)

    if _h != 0 and flag:
        index = i

ans = []

for cx in range(101):
    for cy in range(101):
        H = h[index] + abs(x[index] - cx) + abs(y[index] - cy)
        for i in range(N):
            if h[i] == max(H-abs(x[i] - cx) - abs(y[i] - cy), 0):
                if i == N-1:
                    ans = [cx, cy, H]
            else:
                break

[print(i, end=' ') for i in ans]








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

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

int main() {
  ll n, k;
  cin >> n >> k;

  ll v[110000] = {};
  for (int i = 0; i < n; i++)
    cin >> v[i];

  ll dp[110000] = {};
  for (int i = 1; i < n; i++) dp[i] = INFL;

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

  cout << dp[n - 1] << endl;
}


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

int main(){
	char ch, ch2;
	
	while(1){
		scanf("%c", &ch);
		
		if(islower(ch)){
			ch2 = toupper(ch);
			cout << ch2;
		}else{
			ch2 = tolower(ch);
			cout << ch2;
		}
		
		if(ch == '\n'){
			break;
		}
	}
    return 0;
}

Measured memory_bytes: 3140
#include <iostream>
#include <vector>
#include <set>
#include <algorithm>
#include <math.h>
#include <string.h>
#include <map>
#include <numeric>
#include <random>
using namespace std;

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

int gcd_of_vector(vector<int> A, int begin, int end){
  int result = A[begin];
  for(int i=begin;i<end;i++){
    result = gcd(A[i],result);
  }
  return result;
}

int gcd_of_vector_with_skip(vector<int> A, int skip){
  int result = A[0];
  if(skip==0)result=A[1];
  for(int i=1;i<A.size();i++){
    if(i==skip)continue;
    result = gcd(A[i],result);
  }
  return result;
}

int main()
{
  int N,ans,gcd1,gcd2;
  cin>>N;
  vector<int> A(N);
  for(int i=0;i<N;i++){
    cin>>A[i];
  }

  if(N>=10){
    ans=1000000010;
    for(int i=0;i<2;i++){
      random_shuffle(A.begin(),A.end());
      gcd1 = gcd_of_vector(A,1,N/2);
      gcd2 = gcd_of_vector(A,N/2,N);
      ans = min(ans,max(gcd1,gcd2));
    }
  }else{
    ans=0;
    for(int i=0;i<N;i++){
      ans=max(ans,gcd_of_vector_with_skip(A,i));
    }
  }

  cout<<ans<<endl;
}


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

int main(){
  int N, E, C;
  cin >> N;
  vector<int> A(N);
  
  for (int i = 0; i < N; i++){
    cin >> A.at(i);
  }
  
  for (int i = 0; i < N; i++){
    if (A.at(i)%2 == 0){
      E++;
      if (A.at(i)%3 == 0 || A.at(i)%5 == 0){
        C++;
      }
      else {
        // 何もしない
      }
    }
    else {
      // 何もしない
    }
  }
  
  if (E == C){
    cout << "APPROVED";
  }
  else {
    cout << "DENIED";
  }

}


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

int main(){
    int n;
    cin>>n;
    double a[n];
    for(int i=0;i<n;i++)cin>>a[i];
    sort(a,a+n);
    for(int i=0;i<n-1;i++){
        a[i+1]=(a[i+1]+a[i])/2.0;
    }
    cout<<fixed<<setprecision(10)<<a[n-1]<<endl;
    return 0;
}

Measured memory_bytes: 3748
#include <iostream>
#include <algorithm>
#include <vector>
#include <array>
#include <string>

struct Trie {
    struct Node {
        int c;
        std::array<int, 26> nxt;
        std::array<int, 26> cnt;
        int sz;

        Node(int c) : c(c), sz(0) {
            nxt.fill(-1);
            cnt.fill(0);
        }
    };

    std::vector<Node> nodes;

    Trie() { nodes.emplace_back(-1); }

    void add(const std::string& s) {
        int pos = 0;
        for (char c : s) {
            int ci = c - 'a';

            int npos = nodes[pos].nxt[ci];
            if (npos == -1) {
                npos = nodes.size();
                nodes[pos].nxt[ci] = npos;
                nodes.emplace_back(ci);
            }
            pos = npos;
        }

        ++nodes[pos].sz;
    }

    int find(const std::string& s) const {
        int pos = 0;
        for (char c : s) {
            int ci = c - 'a';
            pos = nodes[pos].nxt[ci];
        }
        return pos;
    }

    void dfs() {
        for (int pos = (int)nodes.size() - 1; pos >= 0; --pos) {
            auto& node = nodes[pos];

            for (int c = 0; c < 26; ++c) {
                int npos = node.nxt[c];
                if (npos == -1) continue;

                const auto& cnode = nodes[npos];
                node.sz += cnode.sz;
                for (int d = 0; d < 26; ++d) {
                    node.cnt[d] += cnode.cnt[d];
                }
            }

            if (node.c != -1) node.cnt[node.c] = node.sz;
        }
    }
};

using lint = long long;

void solve() {
    int n;
    std::cin >> n;

    std::vector<std::string> ss(n);
    for (auto& s : ss) {
        std::cin >> s;
        std::reverse(s.begin(), s.end());
    }

    Trie trie;
    for (const auto& s : ss) trie.add(s);

    trie.dfs();

    lint ans = 0;

    for (auto s : ss) {
        int last = s.back() - 'a';
        s.pop_back();

        int pos = trie.find(s);

        for (int ci = 0; ci < 26; ++ci) {
            int npos = trie.nodes[pos].nxt[ci];

            if (npos == -1) continue;
            ans += trie.nodes[npos].cnt[last];
            if (ci == last) --ans;
        }
    }

    std::cout << ans << "\n";
}

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

    solve();

    return 0;
}


Measured memory_bytes: 227892
import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		
		Scanner sc = new Scanner(System.in);
		
		List<int[]> inputs = new ArrayList<>();
		
		while(true) {
			int a = sc.nextInt();
			int b = sc.nextInt();
			
			if(a == 0 && b == 0) break;
			
			int[] ab = new int[]{a,b};
			inputs.add(ab);
		}
		sc.close();
		
		int cases = 1;
		
		for(int[] ab : inputs) {
			if(ab[0] < ab[1]) {
				System.out.println(ab[0] + " " + ab[1]);
			} else {
				System.out.println(ab[1] + " " + ab[0]);
			}
		}
		
	}

}

Measured memory_bytes: 36028
#include<iostream>
#include<math.h>
#include<vector>
#include<string>
#include<stack>
#include<queue>
#include<map>
#include<algorithm>
#include<bitset>
#include <climits>
using namespace std;
#define _GLIBCXX_DEBUG
#define pq priority_queue
#define mp make_pair
#define pb push_back
#define ff first
#define ss second
#define vit vector<lint>::iterator
#define all(x) (x).begin(),(x).end()
#define rep(x) for(int i = 0;i < (x);i++)
#define repj(x) for(int j = 0;j < (x);j++)
#define REP(i,x) for(int (i) = 0;(i) < (x);(i)++)
#define rrep(x) for(int i = (x);i >= 0;i--)
#define mins(x,y) x = min(x,y)
#define maxs(x,y) x = max(x,y)
#define mod 1000000007
#define graph_set(n) struct edge{int to,int cost;} vector<edge> G((n))
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;
#define range(x,y) ((x) >= 0 && (x) < h && (y) >= 0 && (y) < w)
#define pyes cout << "Yes" << endl
#define pno cout << "No" << endl
typedef vector<long long> vi;
typedef vector<pair<long long, long long>> vp;
typedef vector<vector<long long>> vvi;
typedef pair<long long, long long> pi;
typedef long long lint;
typedef long long ll;
lint qp(int a, ll b) { int ans = 1; do { if (b & 1)ans = 1ll * ans*a; a = 1ll * a*a; } while (b >>= 1); return ans; }
lint qp(int a, ll b, int mo) { int ans = 1; do { if (b & 1)ans = 1ll * ans*a%mo; a = 1ll * a*a%mo; } while (b >>= 1); return ans; }
lint gcd(int a, int b) { return b ? gcd(b, a%b) : a; }
int dx[4] = { 1,0,-1,0 };
int dy[4] = { 0,1,0,-1 };
long long INF = 1e14;

//////////////////////////////////////////////////////////////////////

int main(void) {
	int n, l; cin >> n >> l;
	vector<string> a(n); rep(n)cin >> a[i];
	sort(all(a));
	rep(n) cout << a[i];
	cout << endl;
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
 
using namespace std;
 
template <class T> ostream& operator << (ostream &os, const vector<T> &v) { for (T i : v) os << i << ' '; return os; }
template <class T> ostream& operator << (ostream &os, const set<T> &v) { for (T i : v) os << i << ' '; return os; }
template <class T, class S> ostream& operator << (ostream &os, const pair<T, S> &v) { os << v.first << ' ' << v.second; return os; }
template <class T, class S> ostream& operator << (ostream &os, const map<T, S> &v) { for (auto i : v) os << '(' << i.first << "=>" << i.second << ')' << ' '; return os; }
template <class T, class S> ostream& operator << (ostream &os, const unordered_map<T, S> &v) { for (auto i : v) os << '(' << i.first << "=>" << i.second << ')' << ' '; return os; }
 
#ifndef ONLINE_JUDGE
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
    template <class Arg1> void __f(const char* name, Arg1&& arg1) { cerr << name << " : " << arg1 << endl; }
    template <class Arg1, class... Args>
    void __f(const char* names, Arg1&& arg1, Args&&... args) {
        const char* sep = strchr(names + 1, ',');
        cerr.write(names, sep - names) << " : " << arg1 << "  ";
        __f(sep + 1, args...);
    }
#else
#define trace(...) 0
#pragma GCC optimize ("O3")
#pragma GCC optimize ("unroll-loops")
#pragma GCC target("avx2,sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#define _CRT_SECURE_NO_WARNINGS
#endif
 
#define fast_cin() ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define MAX 1000000
#define ll long long
#define db double
#define str string
#define pb push_back
#define For(i,s,e) for (ll i=(s); i<(e); i++)
#define Forrev(i,s,e) for (ll i=(s); i>=(e); i--)
#define all(v) v.begin(),v.end()
 
#define vll vector<ll>
#define vs vector<string>
#define mapll map<ll,ll>
#define pll pair<ll,ll>
#define initialise(a, x) memset(a, x, sizeof(a))
#define maxheap priority_queue<ll>
#define minheap priority_queue<ll,vector<ll> ,greater<ll>>
 
#define ff first
#define ss second
#define endl "\n"
#define mp make_pair
const ll mod=1e9 + 7;
 
ll takemod(ll a) {
    return ((a%mod)+mod)%mod;
}
 
ll gcd(ll a, ll b) { 
    if (b == 0) 
        return a; 
    return gcd(b, a % b);        
}
 
ll fast_exp(ll base, ll expo) {
    ll res=1;
    while(expo>0) {
        if(expo&1) res=(res*base)%mod;
        base=(base*base)%mod;
        expo>>=1;}
    return res;
}
 
ll modinv(ll a) {
    return takemod(fast_exp(takemod(a), mod-2));
}
 
void solve() {
    
    int n; cin >> n;

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

    int dp[n];

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

    dp[n-1] = 0;
    dp[n-2] = abs(arr[n-2] - arr[n-1]);

    for (int i = n-3; i >= 0; i--) {
    	
    	int val1 = abs(arr[i] - arr[i+1]) + dp[i+1];
    	int val2 = abs(arr[i] - arr[i+2]) + dp[i+2];

    	dp[i] = min(val1, val2);
    }

    cout << dp[0] << endl;
}
 
signed main() 
{
    fast_cin();
    
    int t=1;
    //cin>>t;
    while(t--)
    {
        solve();
    }
    
    
    return 0;    
}

Measured memory_bytes: 4440
#include<bits/stdc++.h>
using namespace std;
#define IO ios_base::sync_with_stdio(false)
int main()
{
    IO;
    long long j, n, m, k=0, l, i;
    cin>>n>>m;
    n=n%m;
    cout<<min(n,m-n)<<endl;
    return 0;
}



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


int main(){
    int N;
    cin >> N;
    string S;
    cin >> S;
    if (N%2 == 1){
        cout << "No" << endl;
        return 0;
    }
    bool ans = true;
    for (int i=0; i < N/2; i++){
        if(S.at(i) != S.at(i + N/2))
            ans = false;
    }
    if (ans)
        cout << "Yes" << endl;
    else
        cout << "No" << endl;
}

Measured memory_bytes: 3588
#include <iostream>
#include <string>
#include <vector>
#include <set>
#include <algorithm>
#include <cctype>
#include <cmath>
#include <queue>
#include <map>
#include <numeric>
#include <unordered_map>
#include <iomanip>
#include <functional>
#include <bitset>
#include <complex>

#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define repi(i,a,b) for(int i=int(a);i<int(b);i++)
#define all(x) (x).begin(),(x).end()

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

typedef long long ll;

using namespace std;

ll dp[3002];
int main()
{
  ios::sync_with_stdio(false);
  cin.tie(0);
  int n;
  int mod=1e9+7;
  string s;
  cin>>n>>s;
  dp[1]=1;
  rep(i,n-1)
  {
    if(s[i]=='<')
    {
      int sum=0;
      repi(j,1,i+3)
      {
        sum+=dp[j];
        dp[j]=sum-dp[j];
        if(sum>mod)sum-=mod;
      }
    }
    else
    {
      for(int j=i+1;j>1;j--)
      {
        dp[j-1]+=dp[j];
        if(dp[j-1]>mod)dp[j-1]-=mod;
      }
    }
  }
  ll res=0;
  repi(i,1,n+1)res+=dp[i];
  cout<<res%mod<<endl;

  return 0;

}


Measured memory_bytes: 256
//Solution for aoj:0157 Russian Dolls
#include<iostream>
#include<algorithm>
using namespace std;
typedef pair<int, int>P;
const int INF = 1 << 30;

int main(){
	int n, m, a, b, ans;
	P doll[201];
	int dp[201];
	while (cin >> n && n){
		fill(dp, dp + 201, 0);
		ans = 0;
		for (int i = 0; i < n; i++){
			cin >> a >> b;
			doll[i] = P(a, b);
		}
		cin >> m;
		for (int i = n; i < n + m; i++){
			cin >> a >> b;
			doll[i] = P(a, b);
		}
		sort(doll, doll + n + m);
		for (int i = 0; i < n + m; i++){
			for (int j = 0; j < i; j++){
				if (doll[i].first > doll[j].first&&doll[i].second>doll[j].second){
					dp[i] = max(dp[i], dp[j] + 1);
				}
				ans = max(ans, dp[i]);
			}
		}
		cout << ans + 1 << endl;
	}
}

Measured memory_bytes: 1164
#include<bits/stdc++.h>
using namespace std;
#define rep(i,j,n) for(int i=(int)(j);i<(int)(n);i++)
#define REP(i,j,n) for(int i=(int)(j);i<=(int)(n);i++)
#define MOD 1000000007
#define int long long
#define ALL(a) (a).begin(),(a).end()
#define vi vector<int>
#define vii vector<vi>
#define pii pair<int,int>
#define priq priority_queue<int>
#define disup(A,key) distance(A.begin(),upper_bound(ALL(A),(int)(key)))
#define dislow(A,key) distance(A.begin(),lower_bound(ALL(A),(int)(key)))
signed main(){
  int X;
  cin>>X;
  int ans=(X+10)/11*2;
  if((X-1)%11<=5)
    ans--;
  cout<<ans;
  }


Measured memory_bytes: 256
#include<cmath> 
#include<cstdio>
#include<iostream>
using namespace std;
int n;
long long a[100005],ans=1,x=1e18,y=18;
int main()
{
	scanf("%d",&n);
	for(int i=0;i<n;++i)
	  {
	  	scanf("%lld",&a[i]);
	  	if(a[i]==0)
	  	  {
	  	  	printf("0");
	  	  	return 0;
		  }
	  }
	for(int i=0;i<n;++i)
	  {
	  	//ans=ans*a[i];
	  	if(log10(ans)+log10(a[i])>y)
	  	  {
	  	  	printf("-1");
	  	  	return 0;
		  }
		ans*=a[i];
		if(ans>x)
		  {
		  	printf("-1");
	  	  	return 0;
		  }
	  }
	cout<<ans;
}

Measured memory_bytes: 4776
K, A, B = map(int, input().split())

if (B - A) / 2 <= 1 or K < A + 1: # ビスケットを叩くのが良い
    ans = (K + 1)
else: # ビスケットを交換した方が良い
    n = (K - A - 1)
    if n % 2 == 0:
        ans = (B + (B-A)*int(n/2))
    else:
        ans = (B + (B-A)*int(n/2) + 1)

print(ans)


Measured memory_bytes: 3060
#include<iostream>
#include<algorithm>
#include<vector>
#include<string.h>
#include<cstdlib>
#include<map>
#include<fstream>
#include<string>
#include<sstream>
#include<iomanip>
#include<cmath>
#include<random>
#include<set>
#include<queue>

using namespace std;

long long dp[3][100100] = {};
const long long INF = 1LL << 60;
#define MOD 1000000007
#define Int int64_t
#define PI 3.14159265358979
#define dump(a) cout << a << endl;


//UnionFind群
class UnionFind {
protected:
    vector<int> par;
    vector<int> data;
    int cnt;
public:
    UnionFind() : par(1), data(1), cnt(1) {};

    UnionFind(int N);

    int root(int x);

    int marge(int x, int y);

    bool same(int x, int y);

    int add();

    int add(int x);

    inline int getSize(int x) { return data.at(root(x)); };
};

UnionFind::UnionFind(int N) : par(N), data(N), cnt(N) {
    for (int i = 0; i < N; i++) {
        par.at(i) = -1;
        data.at(i) = 1;
    }
}


int UnionFind::root(int x) {
    if (par.at(x) == -1) return x;
    return par.at(x) = root(par.at(x)); // 経路圧縮
}

int UnionFind::marge(int x, int y) {
    int rx = root(x);
    int ry = root(y);
    if (rx == ry) return rx;
    else { // ノード数の少ない方に接続
        if (data.at(rx) < data.at(ry)) swap(rx, ry);
        par.at(ry) = rx;
        data.at(rx) += data.at(ry);
        return rx;
    }
}

bool UnionFind::same(int x, int y) {
    return root(x) == root(y);
}

int UnionFind::add() {
    par.push_back(cnt);
    cnt++;
    return cnt - 1;
}

int UnionFind::add(int x) {
    par.push_back(cnt);
    cnt++;
    return marge(x, cnt);
}


struct UF{
    vector<int> par;

    UF(int N):par(N){
        for(int i=0;i<N;i++) par[i] = i;
    }

    int root(int x){
        if(par[x] == x) return x;
        else{
            return par[x] = root(par[x]);
        }
    }

    void unite(int x,int y){
        int rx=root(x);
        int ry=root(y);
        if(rx == ry) return;
        else{
            par[rx]=ry;
            return;
        }
    }

    bool same(int x,int y){
        int rx=root(x);
        int ry=root(y);
        return rx == ry;
    }
};



int main() {
    int n , m;
    cin >> n >> m;
    UF uf(n);
    vector<int> a(n);
    for (int i = 0 ; i < n;i++){
        cin >> a.at(i);
        a.at(i)--;
    }

    for (int i = 0 ; i < m;i++){
        int x, y;
        cin >> x >> y;
        uf.unite(x-1,y-1);
    }

    int cnt = 0;
    for (int i = 0 ;i < n ; i++){
        if (uf.same(i,a.at(i))) cnt++;
    }
    cout << cnt << endl;
}










Measured memory_bytes: 1152
n, k = map(int, input().split())
d = list(map(int, input().split()))

use = [i for i in range(10)]

for _d in d:
    use.remove(_d)


while True:
    ok = True
    s = str(n)
    for i in range(len(s)):
        if int(s[i]) not in use:
            ok = False
            break

    if ok:
        print(n)
        exit()
    else:
        n += 1



Measured memory_bytes: 40924
from collections import Counter
def prime_factorize(n):
    a = []
    while n % 2 == 0:
        a.append(2)
        n //= 2
    f = 3
    while f * f <= n:
        if n % f == 0:
            a.append(f)
            n //= f
        else:
            f += 2
    if n != 1:
        a.append(n)
    return a
def calc_n_value(i):
  return(int((
    ((i*8+1)**0.5-1)*0.5
  )//1))

n=int(input())
fcts = prime_factorize(n)
tmp = Counter(fcts).values()
out=0
for _ in tmp:
  out += calc_n_value(_)
print(out)

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

int main(){
  int n, k;
  cin >> n >>  k;
  int res = 0;
  vector<int>a(n);
  for(int i = 0; i<n; i++)
    cin >> a.at(i);
  
  sort(a.begin(), a.end());
  reverse(a.begin(), a.end());
  
  for(int i = 0; i<k; i++){
    res += a.at(i);
  }
  cout << res << endl;
}

Measured memory_bytes: 256
/*
*/

#pragma GCC optimize("O3")
#define _CRT_SECURE_NO_WARNINGS
#include <fstream>
#include <iostream>
#include <string>
#include <complex>
#include <math.h>
#include <set>
#include <vector>
#include <map>
#include <queue>
#include <stdio.h>
#include <stack>
#include <algorithm>
#include <list>
#include <ctime>

#include <memory.h>
#include <assert.h>

#define y0 sdkfaslhagaklsldk

#define y1 aasdfasdfasdf
#define yn askfhwqriuperikldjk
#define j1 assdgsdgasghsf
#define tm sdfjahlfasfh
#define lr asgasgash
#define norm asdfasdgasdgsd
#define have adsgagshdshfhds
#define ends asdgahhfdsfshdshfd
#define prev asdgSHJsfgsdfhdsh

#define eps 1e-8
#define M_PI 3.141592653589793
#define bsize 512

#define ldouble long double
using namespace std;

#define bs 1000000007

const int N = 1200031;

int main(){
//	freopen("apache.in","r",stdin);
//	freopen("apache.out","w",stdout);
	//freopen("input.txt", "r", stdin);
	//freopen("output.txt", "w", stdout);
	ios_base::sync_with_stdio(0);
//	cin.tie(0);

	int a,b;
	cin>>a>>b;
	long long dif=b-a;
	int h_r=dif*(dif+1)/2;
	cout<<h_r-b<<endl;

//	cin.get(); cin.get();
	return 0;
}


Measured memory_bytes: 256
package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
)

func main() {
	sc := NewScanner()

	k := sc.ReadInt()
	s := sc.ReadString()

	var sDisplay string
	if len(s) <= k {
		sDisplay = s
	} else {
		sDisplay = s[:k] + "..."
	}

	fmt.Println(sDisplay)
}

// util
// *   math/simple

func Abs(x int) int {
	if x >= 0 {
		return x
	}
	return -x
}

func Min(values ...int) int {
	if len(values) == 0 {
		panic("no values")
	}
	min := values[0]
	for _, v := range values {
		if v < min {
			min = v
		}
	}
	return min
}

func Max(values ...int) int {
	if len(values) == 0 {
		panic("no values")
	}
	max := values[0]
	for _, v := range values {
		if v > max {
			max = v
		}
	}
	return max
}

func Pow(base int, exponent uint) int {
	answer := 1
	for i := uint(0); i < exponent; i++ {
		answer *= base
	}
	return answer
}

// *   io

type Scanner struct {
	bufScanner *bufio.Scanner
}

func NewScanner() *Scanner {
	bufSc := bufio.NewScanner(os.Stdin)
	bufSc.Split(bufio.ScanWords)
	bufSc.Buffer(nil, 100000000)
	return &Scanner{bufSc}
}

func (sc *Scanner) ReadString() string {
	bufSc := sc.bufScanner
	bufSc.Scan()
	return bufSc.Text()
}

func (sc *Scanner) ReadInt() int {
	bufSc := sc.bufScanner
	bufSc.Scan()
	text := bufSc.Text()

	num, err := strconv.Atoi(text)
	if err != nil {
		panic(err)
	}
	return num
}


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

#define INF 20000000

int main()
{
  int N, M, X;
  cin >> N >> M >> X;
  vector<vector<long> > CA(N, vector<long>(M+1));
  for (int i = 0; i < N; i++)
  {
    for (int j = 0; j < M+1; j++) cin >> CA.at(i).at(j);
  }
  int count = 1;
  vector<int> digit(N);
  long ans = INF;
  for (int i = 0; i < N; i++) count *= 2;
  for (int i = 0; i < count; i++)
  {
    bool OK = true;
    int tmp = count/2;
    int index = 0;
    while (tmp > 0)
    {
      digit.at(index) = (i%(tmp*2))/tmp;
      index++;
      tmp /= 2;
    }
    for (int j = 1; j <= M; j++)
    {
      long tmp_sum = 0;
      for (int k = 0; k < N; k++)
      {
        if (digit.at(k)) tmp_sum += CA.at(k).at(j);
      }
      // cout << "i = " << i << ", tmp = " << tmp_sum << endl;
      if (tmp_sum < X)
      {
        OK = false;
        break;
      }
    }
    // cout << "OK = " << OK << endl;
    if (OK)
    {
      long tmp_ans = 0;
      for (int k = 0; k < N; k++)
      {
        if (digit.at(k)) tmp_ans += CA.at(k).at(0);
      }
      ans = min(ans, tmp_ans);
    }
  }
  if (ans == INF) cout << -1 << endl;
  else cout << ans << endl;
}


Measured memory_bytes: 3636
#include "bits/stdc++.h"
#include <atcoder/all>

using namespace std;
using namespace atcoder;

#define ll long long

using mint = modint998244353;
struct S {
	mint a; int size;
};
struct F {
	mint a, b;
};
S op(S l, S r) {
	return S{ l.a + r.a,l.size + r.size };
}
S e() {
	return S{ 0,0 };
}
S mapping(F l, S r) {
	return S{ l.a*r.a + r.size*l.b, r.size };
}
F composition(F l, F r) {
	return F{ l.a*r.a,l.a*r.b + l.b };
}
F id() {
	return F{ 1,0 };
}

signed main() {
	int N, Q; cin >> N >> Q;
	vector<S>a(N);
	for (int i = 0; i < N; i++) {
		int x; cin >> x;
		a[i] = { x,1 };
	}
	lazy_segtree<S, op, e, F, mapping, composition, id>seg(a);
	for (int i = 0; i < Q; i++) {
		int t; cin >> t;
		if (t == 0) {
			int l, r, b, c; cin >> l >> r >> b >> c;
			seg.apply(l, r, F{ b,c });
		}
		else {
			int l, r; cin >> l >> r;
			cout << seg.prod(l, r).a.val() << endl;
		}
	}
	return 0;
}


Measured memory_bytes: 19404
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int[] a = new int[n];
        long sum = 0;
        for(int i=0;i<n;i++){
            a[i] = sc.nextInt();
            sum += a[i];
        }
        int count[] = new int[100001];
        for(int i : a){
            count[i]++;
        }
        
        int q = sc.nextInt();
        int[] b = new int[q], c = new int[q];
        for(int i=0;i<q;i++){
            b[i] = sc.nextInt();
            c[i] = sc.nextInt();
        }
        for(int i=0;i<q;i++){
            sum += count[b[i]] * (c[i] - b[i]);
            System.out.println(sum);
            count[c[i]] += count[b[i]];
            count[b[i]] = 0;
        }
        
    }
}


Measured memory_bytes: 55012
function Main(input){
  n = String(input);
  l = 1000000000000000000;
  for(i=0;i<=(n.length-2);i++){
    if(Math.abs(753-Number(n.substr(i,3)))<=l)l=Math.abs(753-Number(n.substr(i,3)));
  }
console.log(Math.abs(l));
}
Main(require("fs").readFileSync("/dev/stdin", "utf8"));

Measured memory_bytes: 7372
#include<iostream>
#include<algorithm>
using namespace std;
int h, w, i, j, dp[1005][1005] = {}, mp[1005][1005] = {};
char c;
int main() {
	dp[1][1] = 1;
	cin >> h >> w;
	for (i = 1;i <= h;++i)
		for (j = 1;j <= w;++j) {
			cin >> c;
			if (c == '#')mp[i][j] = 1;
		}
	for (i = 1;i <= h;++i)
		for (j = 1;j <= w;++j) {
			if (mp[i - 1][j] == 0)dp[i][j] += dp[i - 1][j], dp[i][j] %= 1000000007;
			if (mp[i][j - 1] == 0)dp[i][j] += dp[i][j - 1], dp[i][j] %= 1000000007;
		}
	cout << dp[h][w];
}

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

typedef double du ;
typedef string st ;
typedef long long ll ;
typedef long double ld ;
typedef long long int lli ;

#define vi vector <lli>
#define loop(num) for (lli i = 0 ; i < num ; i ++ )
#define loop2(num) for (lli j = 0 ; j < num ; j ++ )
#define loopcin(num , ar ) for (lli i = 0 ; i < num ; i ++ ) {cin >> ar [i] ;}
#define loopcout(num , ar) for (lli i = 0 ; i < num ; i ++ ) {cout << ar [i] << ' '; }
#define looppu(num , ar) for (lli i = 0 ; i < num ;  i++) {lli x ; cin >> x ; ar . push_back (x) ;}
#define loopin(num , ar) for (lli i = 0 ; i < num ;  i++) {lli x ; cin >> x ; ar . insert (x) ;}

#define forr(num1 , num2) for (lli i = num1 ; i < num2 ; i ++ )
#define forrcin(num1 , num2 , ar ) for (lli i = num1 ; i < num2 ; i ++ ) {cin >> ar [i] ;}
#define forrcout(num1 , num2 , ar) for (lli i = num1 ; i < num2 ; i ++ ) {cout << ar [i] << ' '; }

#define D2forrcin(num1_1 , num1_2 , num2_1 , num2_2 , A ) for (lli i = num1_1 ; i < num1_2 ; i ++){ for (lli j = num2_1 ; j < num2_2 ; j++){cin >> A[i][j] ;}}
#define D2forrcout(num1_1 , num1_2 , num2_1 , num2_2 , A ) for (lli i = num1_1 ; i < num1_2 ; i ++){ for (lli j = num2_1 ; j < num2_2 ; j++){cout << A[i][j] << ' ' ;}cout << endl ;}

#define YES cout << "YES" << endl
#define Yes cout << "Yes" << endl
#define NO cout << "NO" << endl
#define No cout << "No" << endl

#define F first
#define S second
#define pb push_back
#define pf push_front
#define pob pop_back ()
#define pof pop_front ()

#define fastio ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);

signed main ()
{
    fastio
    ll s , t = 111 , res = 0 ;
    cin >> s ;

    while (t <= 999){
        if (s <= t){
            res = t ;
            break ;
        }
        else
            t += 111 ;
    }
    if (res)
        cout << t << endl ;
    else
        cout << "TlE" << endl ;
    return 0 ;
}

/*___________________________________________________________________functions___________________________________________________________________________*/



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

int main(){
  int a,b,c,d;
  int dis1,dis2,dis3;
  int cnt=0;

  cin >> a >> b >> c >> d;

  dis1 = a-c;
  dis2 = b-c;
  dis3 = a-b;
  
  if(dis1 >= 0)
    {
      if(dis1 <= d)
	{
	  cout << "Yes" << endl;
	  cnt++;
	}
      else
	{
	  cnt = 0;
	}
    }
  else
    {
      if(dis1*-1 <= d)
	{
	  cout << "Yes" << endl;
	  cnt++;
	}
      else
	{
	  cnt = 0;
	}
    }
  
  if(cnt == 0)
    {
  if(dis2 >= 0 && dis3 >= 0)
    {
      if(dis2 <= d && dis3 <= d)
	{
	  cout << "Yes" << endl;
	}
      else
	{
	  cout << "No" << endl;
	}
    }
  else
    {
      if(dis2*-1 <= d && dis3*-1 <= d)
	{
	  cout << "Yes" << endl;
	}
      else
	{
	  cout << "No" << endl;
	}
    }
    }
}


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

int main(){
  int N,L;
  cin >> N >> L;
  
  int appleAll = 0;
  rep(i,N){
    appleAll += L + i;
  }
  
  int min_sub = abs(appleAll);
  int min = abs(appleAll);
  rep(i,N){
    int tmp = 0;
    int tmp_sub = 0;
    rep(j,N){
      if(i == j)continue;
      tmp += L + j;
    }
    tmp_sub = abs(tmp - appleAll);
    if(min_sub > tmp_sub){
      min_sub = tmp_sub;
      min = tmp;
    }
  }
  
  cout << min << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define pb push_back
#define mp make_pair
#define eb emplace_back
#define fi first
#define se second
#define lb lower_bound
#define ub upper_bound
const int mod = 1e9+7;
const int mx = INT_MAX;
const long double pi = 4*atan((long double)1);
typedef vector<int> vi;
typedef pair<int,int> pii;
typedef vector<pii> vii;
void lcs( string X, string Y, int m, int n ) 
{ 
   int L[m+1][n+1]; 
   for (int i=0; i<=m; i++) 
   { 
     for (int j=0; j<=n; j++) 
     { 
       if (i == 0 || j == 0) 
         L[i][j] = 0; 
       else if (X[i-1] == Y[j-1]) 
         L[i][j] = L[i-1][j-1] + 1; 
       else
         L[i][j] = max(L[i-1][j], L[i][j-1]); 
     } 
   } 
   int index = L[m][n]; 
   char lcs[index+1]; 
   lcs[index] = '\0';
   int i = m, j = n; 
   while (i > 0 && j > 0) 
   {
      if (X[i-1] == Y[j-1]) 
      { 
          lcs[index-1] = X[i-1];
          i--; j--; index--;    
      } 
      else if (L[i-1][j] > L[i][j-1]) 
         i--; 
      else
         j--; 
   } 
   cout<<lcs;
} 

int main() 
{ 
	ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
  string X,Y;
  cin>>X>>Y;
  lcs(X, Y, X.length(),Y.length()); 
  return 0; 
} 

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

using namespace std;

typedef long long ll;

const int N = 85;

int dp[N][N][N * N + N + N];
int a[N][N], b[N][N];
int n, m;
int ans;

bool go(int x, int y, int diff) {
  if(x == n and y == m)  {
    ans = min(ans, abs(diff + (a[x][y] - b[x][y])));
    ans = min(ans, abs(diff - (a[x][y] - b[x][y])));
    return true;
  }
  if(x > n + 1 or y > m + 1) return false;
  if(dp[x][y][diff] != -1) return dp[x][y][diff];
  int ans = 0;
  ans |= go(x + 1, y, abs(diff + (a[x][y] - b[x][y])));
  ans |= go(x + 1, y, abs(diff - (a[x][y] - b[x][y])));
  ans |= go(x, y + 1, abs(diff + (a[x][y] - b[x][y])));
  ans |= go(x, y + 1, abs(diff - (a[x][y] - b[x][y])));
  return dp[x][y][diff] = ans;
}

int main() {
  memset(dp, -1, sizeof dp);
  cin >> n >> m;
  for(int i = 1; i <= n; i++) {
    for(int j = 1; j <= m; j++) {
      cin >> a[i][j];
    }
  }
  for(int i = 1; i <= n; i++) {
    for(int j = 1; j <= m; j++) {
      cin >> b[i][j];
    }
  }
  ans = 1e9;
  go(1, 1, 0);
  cout << ans << '\n';
}

Measured memory_bytes: 209024
//#include <boost/multiprecision/cpp_dec_float.hpp>
//#include <boost/multiprecision/cpp_int.hpp>
#include <stdio.h>
#include <iostream>
#include <vector>
#include <string>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <math.h>
#include <algorithm>
using namespace std;
//namespace mp = boost::multiprecision;
//using llll = mp::cpp_int;
// 仮数部が1024ビットの浮動小数点数型(TLEしたら小さくする)
//using Real = mp::number<mp::cpp_dec_float<1024>>;
using ll = long long;
const double EPS = 1e-10;
const ll MOD = 7+(1e+9);

int main(){
  ll n;
  cin>>n;
  vector<ll>v(n,0);
  for(ll i=0;i<n;i++){
    cin>>v[i];
  }
  sort(v.begin(),v.end());
  ll ans=v[n/2]-v[n/2-1];
  cout<<ans<<endl;
}


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

int main() {
  int N, a = 0;
  cin >> N;
  vector<int>L(N);
  for (int i = 0; i < N; i++) {
    cin >> L.at(i);
  }
  sort(L.begin(),L.end());
  for (int i = 0; i < N-1; i++) {
    a += L.at(i);
  }
  if (L.at(N-1)>=a) {
    cout << "No";
  }
  else {
    cout << "Yes";
  }
}

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

using namespace std;

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

    vector<int> a(N);

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

    std::sort(a.begin(), a.end(), greater<int>());

    int count = 1;

    for (int i = 0; i < N-1 ; i++){
        if (a[i] > a[i + 1]) {
            count = count + 1;
        }
    }
    cout << count << endl;

    return 0;
}

Measured memory_bytes: 256
// CODE © by 𝕌𝕥𝕜𝕒𝕣𝕤𝕙 𝔾𝕒𝕣𝕘
// Copying or sharing of this code without permission of the Author is strictly prohibited!!!
#include <bits/stdc++.h>
using namespace std;
#define Speed ios::sync_with_stdio(0); cin.tie(0);
#define pb push_back
#define endl "\n"
int power(int x, int n, int mod) {int res = 1; x %= mod; while (n) {if (n & 1)res = (res * x) % mod; x = (x * x) % mod; n >>= 1;} return res;}
signed main() {
#ifndef ONLINE_JUDGE
	freopen("input.txt", "r", stdin);
	// freopen("output.txt", "w", stdout);
#endif
	int a = 0, b = 0, c = 0, d = 0, i = 0, j = 0, k = 0, t = 0, n = 0, q = 0;
	cin >> n;
	int arr[n + 1], sus[4]={0};
	for (int i = 1; i <= n; i++) {
		cin >> arr[i];
		sus[arr[i]]++;
	}
	int ms1=0, ms2=0, ms3=0;
	ms1 = sus[1] + sus[2] + sus[3];
	ms2 = sus[2] + sus[3];
	ms3 = sus[3];
	double dp[ms3+1][ms2+1][ms1+1];
	for (int i = 0; i <= ms3; i++)
		for (int j = 0; j <= ms2; j++)
			for (int k = 0; k <= ms1; k++)
				dp[i][j][k]= 0.0;
	for (int i = 0; i <= ms3; i++)
		for (int j = 0; j <= ms2-i; j++)
			for (int k = 0;k <= ms1-i-j; k++) {
				if (i == 0 && j == 0 && k == 0)continue;
				dp[i][j][k] = (n * 1.0) / (i + j + k);
				if (k > 0)dp[i][j][k] += (dp[i][j][k - 1] * k * 1.0) / (i + j + k);
				if (j > 0)dp[i][j][k] += (dp[i][j - 1][k + 1] * j * 1.0) / (i + j + k);
				if (i > 0)dp[i][j][k] += (dp[i - 1][j + 1][k] * i * 1.0) / (i + j + k);
			}
	cout <<fixed<<setprecision(10)<< dp[sus[3]][sus[2]][sus[1]] ;

}

Measured memory_bytes: 216632
# include <bits/stdc++.h>
# define ll int64_t
# define rep(i,n) for(ll i=0;i<n;i++)
# define rrep(i,n) for(ll i=1;i<=n;i++)
# define ALL(x) (x).begin(), (x).end()
# define SZ(x) ((int)(x).size())
# define pb push_back
# define mod 1000000007

using namespace std;

bool compare_by_b(pair<string,ll> a,pair<string,ll> b){
    if(a.second != b.second) return a.second<b.second;
    else return a.first<b.first;
}

bool my_compare(pair<string,ll> a,pair<string,ll> b){
    
    if(a.first != b.first) return a.first<b.first;
    if(a.second != b.second) return a.second>b.second;
    else return true;
}

ll factorial(ll n){
    ll x=1;
    rrep(i,n) x*=i;
    return x;
}

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

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

void f(ll rest,string s){
    if(rest==0){
        cout<<s<<endl;
    }else{
        for(char c='a';c<='c';c++){
            f(rest -1,s+c);
        }
    }
}


int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    
    ll n,maxi=-1000000;
    cin>>n;
    vector<ll> a(n+1,0),b(n+1,0);

    rep(i,n) {
        ll up;
        cin>>up;
        a[i+1]=a[i]+up;
    }
    rep(i,n){
        ll down;
        cin>>down;
        b[i+1]=b[i]+down;
    }
    
    rrep(i,n){
        maxi=max(maxi,a[i]+b[n]-b[i-1]);
    }
    cout<<maxi<<endl;
    return 0;
}


Measured memory_bytes: 256
N,K = map(int,input().split())
S = input()
 
zeros = []
ones = [0]
# Sが0始まりの時は、それを挟むための1が必要なので、予め入れておく
# 1始まりの時は、これに+= 1するので問題なし
 
prev = '1'
for c in S:
    if c == '1':
        if prev == '0':
            ones.append(1)
        else:
            ones[-1] += 1
    else: #c == '0'
        if prev == '1':
            zeros.append(1)
        else:
            zeros[-1] += 1
    prev = c
ones.append(0)
# Sが0終わりの時は、それを挟むための1が必要なので、最後に付け加えておく
# 1終わりの時は不要だが、maxをとるので0を入れておいても影響はない

tmp = sum(zeros[0:K]) + sum(ones[0:K+1])
#　初期値として、最初の区間の和を計算しておけば、
# あとは先頭と最後尾を+-するだけで累積和を求められる
ans = tmp
for i in range(0,len(zeros)-K):
    tmp += zeros[i+K] - zeros[i] + ones[i+K+1] - ones[i]
    ans = max(tmp,ans)

print(ans)

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

int main() {
  ll K, N;
  cin >> K >> N;
  ll A[N];
  for (int i = 0; i < N; i++) cin >> A[i];

  vector<ll> left(N);
  vector<ll> right(N);

  for (int i = 0; i < N; i++) {
    if (i == 0) {
      left[i] = A[i] + (K - A[i+1]);
      right[i] = A[N] - A[i];
    }
    else if (i == N-1) {
      left[i] = A[i] - A[0];
      right[i] = (K - A[i]) + A[i-1];
    }
    else {
      left[i] = A[i] + (K - A[i+1]);
      right[i] = (K - A[i]) + A[i-1];
    }
  }

  sort(left.begin(), left.end());
  sort(right.begin(), right.end());

  cout << min(left[0], right[0]) << endl;
}

Measured memory_bytes: 4992
import java.util.Scanner;

public class Main {
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int[] a= new int[n];
		for(int i=0; i<n; i++){
			a[i] = sc.nextInt();
		}
		sc.close();
		
		int n2, n0, n4;
		n2 = 0;
		n0 = 0;
		for(int i=0; i<n; i++){
			if(a[i] % 4 != 0){
				if(a[i] % 2 == 0){
					n2++;
				}else{
					n0++;
				}
			}
		}
		n4 = n - n0 - n2;
		//System.out.println("" + n0 + ","+ n2 + ","+ n4 );
		if(n4*2 + n2 >= n/2*2){
			System.out.println("Yes");
		}else{
			System.out.println("No");
		}
	}
}

Measured memory_bytes: 49384
import sys
import math
def i():return int(sys.stdin.readline().replace("\n",""))
def i2():return map(int,sys.stdin.readline().replace("\n","").split())
def s():return str(sys.stdin.readline().replace("\n",""))
def l():return list(sys.stdin.readline().replace("\n",""))
def intl():return [int(k) for k in sys.stdin.readline().replace("\n","").split()]
def lx():return list(map(lambda x:int(x)*-1,sys.stdin.readline().replace("\n","").split()))
def t():return tuple(map(int,sys.stdin.readline().replace("\n","").split()))

if __name__ == "__main__":pass
l = input().split()
s,t = l[0],l[1]
a ,b = i2()
u = input()
if s == u:
    print(a-1,b)
else:
    print(a,b-1)

Measured memory_bytes: 3064
#include <stdio.h>
#include<math.h>
 
int main()
{
long long int N,l;
int a[100001]={0};
scanf("%lld",&N);
for(int i=1;i<=105;i++)
{
    for(int j=1;j<=105;j++)
    {
        for(int k=1;k<=105;k++)
        {
            l=i*i+j*j+k*k+i*j+i*k+j*k;
          a[l]++;
        }
    }
}
for(int i=0;i<N;i++)
{
printf("%d\n",a[i+1]);
}
}

Measured memory_bytes: 2108
import java.util.*;
class Main{
  static Scanner sc=new Scanner(System.in);
  public static void main(String args[]){
    int c[][] = new int[3][3];
    boolean F=false;
    for(int i=0;i<3;++i){
      for(int j=0;j<3;++j){
        c[i][j]=sc.nextInt();
      }
    }
    for(int a1=0;a1<=100&&!F;a1++){
      for(int a2=0;a2<=100&&!F;a2++){
        for(int a3=0;a3<=100&&!F;a3++){
          int b1=c[0][0]-a1,b2=c[0][1]-a1,b3=c[0][2]-a1;
          boolean L2,L3;
          L2=(c[1][0]==a2+b1&&c[1][1]==a2+b2&&c[1][2]==a2+b3);
          L3=(c[2][0]==a3+b1&&c[2][1]==a3+b2&&c[2][2]==a3+b3);
          F=L2&&L3;
        }
      }
    }
    System.out.println(F?"Yes":"No");
  }
}

Measured memory_bytes: 36768
#include<iostream>
#include<math.h>
#include<vector>
#include<algorithm>
#include<numeric>
#include<map>
using namespace std;

int main(){
    string s,t;
    int ans=0;
    cin>>s>>t;
    for(int i=0;i<3;++i)
        if(s[i]==t[i])++ans;
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long LL;
#define rep(i, n) for (int i = 0; i < n; i++)
#define repp(i, n, m) for (int i = (int)(n); i < (int)(m); i++)
#define rrep(i, n, m) for (int i = n; i >= m; i--)

template <class T>
bool contain(const std::string &s, const T &v)
{
    return s.find(v) != std::string::npos;
}

int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    LL N,a,cnt=0,cnt4=0,cnt2=0; cin>>N;
    rep(i,N){
        cin>>a;
        if(a%4==0){
            cnt4++;
        }else if(a%2==0){
            cnt2++;
        }else{
            cnt++;
        }
    }
    if((cnt4+1 == cnt && cnt2 == 0) || cnt4 >= cnt){
        cout<<"Yes"<<endl;
    }else{
        cout<<"No"<<endl;
    }
}


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


int main()
{
	int N;
	int K = 0;


	cin >> N;
	cin >> K;
	string S(N,'0');
	cin >> S;
	S[K - 1] = S[K - 1] + 32;

	cout << S << endl;

	
	
	
}


Measured memory_bytes: 256