akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ull = unsigned long long;
using ld = long double;
using vi = vector<int>;
using vvi = vector<vi>;
using vvvi = vector<vvi>;
using vll = vector<ll>;
using vvll = vector<vll>;
using vvvll = vector<vvll>;
using vs = vector<string>;
using pll = pair<ll, ll>;
using vp = vector<pll>;
#define rep(i, n) for(ll i = 0; i < (n); i++)
#define repb(i, n) for(ll i = (n)-1; i >= 0; i--)
#define repr(i, a, b) for(ll i = (a); i < (b); i++)
#define reprb(i, a, b) for(ll i = (b)-1; i >= (a); i--)
#define ALL(a) (a).begin(), (a).end()
#define SZ(x) ((ll)(x).size())
const ll MOD = 1000000007;
const ll INF = 100000000000000000LL;
const ld EPS = 1e-12L;
const ld PI = 3.1415926535897932385L;
inline ll GCD(ll a, ll b){ return b?GCD(b, a % b):a; }
inline ll LCM(ll a, ll b){ return a/GCD(a, b)*b; }
inline ll powint(ull x, ll y){ ll r=1; while(y){ if(y&1) r*=x; x*=x; y>>=1; } return r; }
inline ll powmod(ll x, ll y, ll m = MOD){ ll r=1; while(y){ if(y&1) r*=x; x*=x; r%=m; x%=m; y>>=1; } return r; }
template<class S, class T>inline bool chmax(S &a, const T &b){ if(a<b) { a=b; return 1; } return 0; }
template<class S, class T>inline bool chmin(S &a, const T &b){ if(b<a) { a=b; return 1; } return 0; }
#ifdef OJ_LOCAL
#include "dump.hpp"
#else
#define dump(...) ((void)0)
#endif

int main(){
    cin.tie(0); ios::sync_with_stdio(false);
    cout << fixed << setprecision(15);
    ll k, s;
    cin >> k >> s;
    ll ans = 0;
    rep(x, k+1)rep(y, k+1){
        ll z = s-x-y;
        if(z >= 0 && z <= k){
            ans++;
        }
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#ifdef ENABLE_DEBUG
#define dump(a) cerr<<#a<<"="<<a<<endl
#define dumparr(a,n) cerr<<#a<<"["<<n<<"]="<<a[n]<<endl
#else
#define dump(a) 
#define dumparr(a,n) 
#endif
#define FOR(i, a, b) for(int i = a;i < b;i++)
#define For(i, a) FOR(i, 0, a)
#define REV(i, a, b) for(int i = b-1;i >= a;i--)
#define Rev(i, a) REV(i, 0, a)
#define REP(a) For(i, a)

typedef long long int ll;
typedef unsigned long long ull;
typedef unsigned int uint;
typedef pair<ll, ll> pll;
typedef pair<ll,pll> ppll;
typedef vector<ll> vll;

const ll INF=(1LL<<50);

template<class S,class T>
std::ostream& operator<<(std::ostream& os,pair<S,T> a){
  os << "(" << a.first << "," << a.second << ")";
  return os;
}
template<class T>
std::ostream& operator<<(std::ostream& os,vector<T> a){
  os << "[ ";
  REP(a.size()){
    os<< a[i] << " ";
  }
  os<< " ]";
  return os;
}

const string YES = "YES";
const string NO = "NO";

void solve(long long N, std::vector<long long> p){
  auto cpy=p;
  sort(cpy.begin(),cpy.end());
  ll cnt=0;
  REP(N){
    if(cpy[i]!=p[i]){
      ++cnt;
    }
  }
  if(cnt<=2){
    cout<<YES<<endl;
  }else{
    cout<<NO<<endl;
  }
}

int main(){
    long long N;
    scanf("%lld",&N);
    std::vector<long long> p(N);
    for(int i = 0 ; i < N ; i++){
        scanf("%lld",&p[i]);
    }
    solve(N, std::move(p));
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <functional>
#include<vector>
#include<math.h>
#include<bitset>
#include<string>
#include <deque>
#include<queue>
#include<map>
using namespace std;





int main() {
	long long int N;
	int sosuuu[55555];
	cin >> N;
	int sosuu[55559];
	for (int i = 0; i <=55555; i++) {
		sosuu[i] = 1;
	}
	sosuu[0] = 0;
	sosuu[1] = 0;
	int Y = 0;
	for (int i = 2; i <=55555; i++) {
		if (sosuu[i] == 1) {
			if (i >= 10) {
				sosuuu[Y] = i;
				Y++;
			}
			for (int j = 2 * i; j <= 55555; j+=i) {
				sosuu[j] = 0;
			}
		}
	}
	int Q = 0;
	int Z = 0;
	for (int i = 0; Q<N; i++) {
		if (sosuuu[i] % 5 == 1) {
			cout << sosuuu[i] << " ";
			Q++;
		}
	}


	return 0;
}

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

int main()
{
    int n,m,pi,xi,sum=0;
    cin>>n;
    int arr[n];
    for ( int i = 0 ; i < n ; i++){
        cin>>arr[i];
        sum+=arr[i];}
    cin>>m;
    for ( int i=0 ; i<m ; i++)
    {
      cin>>pi>>xi;
       cout<<sum+xi-arr[pi-1]<<endl;
    }
    return 0;
}

Measured memory_bytes: 256
#C
N, M = map(int, input().split())
a = [int(input()) for _ in range(M)]

dp = [1]*N
for i in range(M):
    dp[a[i]-1] = 0

for i in range(N):
    if dp[i] == 0:
        continue
    elif i == 0:
        dp[i] = 1
    elif i == 1:
        dp[i] = dp[i-1]+1
    else:
        dp[i] = dp[i-1] + dp[i-2]

ans = int(dp[N-1])%1000000007
print(ans)


Measured memory_bytes: 470264
#include <iostream>
#include <ios> 
#include <vector>
#include <string>
#include <algorithm>
#include <functional>
#include <queue>
#include <stack>
#include <set>
#include <cmath>
#include <bitset>
#include <map>
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define rep1(i,n) for(int i=1;i<=(int)(n);i++)

using namespace std;
typedef long long int lli;
//const int MAX=;
const string K("keyence");

int main(){
	string S;
	cin>>S;
	int l=S.size();
	bool ans=false;
	if(l==7){
		if(S==K)ans=true;
	}
	else{
		rep(i,7){
			string T=S;
			T.erase(T.begin()+i,T.begin()+i+l-7);
			if(T==K)ans=true;
		}
	}
	if(ans)cout<<"YES";
	else cout<<"NO";
}


Measured memory_bytes: 256
let reads f =  stdin.ReadLine().Split() |> Array.map f
let f a b =
    let rec loop a b n = match (1 + (a * n) - n) with
                         | c when c < b -> loop a b (n+1)
                         | _ -> n
    loop a b 0
    
reads int
|> (fun [|a;b|] -> f a b)
|> printfn "%d"

Measured memory_bytes: 14044
# -*- coding: utf-8 -*-
"""
A - Discount Fare
https://atcoder.jp/contests/abc113/tasks/abc113_a

"""
import sys


def solve(X, Y):
    return X + Y//2


def main(args):
    X, Y = map(int, input().split())
    ans = solve(X, Y)
    print(ans)


if __name__ == '__main__':
    main(sys.argv[1:])


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

using namespace std;

using ll = long long int;

#define FOR(i, b, e) for (int i = (b); i < (e); ++i)
#define RFOR(i, b, e) for (int i = ((e) - 1); (b) <= i; --i)
#define REP(i, N) for (int i = 0; i < (N); ++i)
#define RREP(i, N) for (int i = ((N) - 1); 0 <= i; --i)
#define scanInt(x) int x; scanf("%d", &(x)); getchar();
#define scanLLInt(x) ll x; scanf("%lld", &(x)); getchar();
#define scanVecInt(A, N) vector<int> A(N); REP(i, N){scanf("%d", &(A[i])); getchar();}
#define scanVecLLInt(A, N) vector<ll> A(N); REP(i, N){scanf("%lld", &(A[i])); getchar();}

int main()
{
    scanInt(N);
    if (N == 1){
        cout << "Hello World" << endl;
    }else{
        scanInt(A);
        scanInt(B);
        cout << (A + B) << endl;
    }
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n)for(int i=0;i<(n);i++)
#define ALL(a) (a).begin(), (a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define pb push_back
using ll = long long;
using P = pair<int, int>;
using Graph = vector<vector<int>>;

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

int n, m;
Graph G;

int dp[100100];
int rec(int v){
    if(dp[v] != -1) return dp[v];
    int res = 0;
    for (auto nv : G[v]){
        chmax(res, rec(nv) + 1);
    }
    return dp[v] = res;
}

int main(){
    cin >> n >> m;
    G.resize(n);
    rep(i,m){
        int x, y; cin >> x >> y;
        --x, --y;
        G[x].pb(y);
    }
    rep(i,n) dp[i] = -1;
    int ans = 0;
    rep(v,n) chmax(ans, rec(v));
    cout << ans << endl;
}

Measured memory_bytes: 8192
#include <bits/stdc++.h>
typedef long long int ll;
typedef long double ld;
using namespace std;
const long long int INF = 1e18;
const long long int mod = 1e9+7;

typedef pair<ll, ll> pairs;
typedef vector<pairs> p;

struct Edge{
    ll to, weight;
    Edge(ll t, ll w) : to(t), weight(w){}
};
using graph = vector<vector<ll>>;
using Graph = vector<vector<Edge>>;


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

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

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

// 回文
bool kai(string S){
    bool flag = true;
    for(ll i=0;i<S.size()/2;++i){
        if(S[i] != S[S.size()-i-1]){
            flag = false;
            break;
        }
    }
    return flag;
}
// ---------------------------------------------

int main(){
    ll d, g;
    cin>>d>>g;
    vector<ll> p(d), c(d);
    for(ll i=0;i<d;++i){
        cin>>p[i]>>c[i];
    }

    ll ans = INF;
    for(ll b=0;b<(1 << d);++b){
        ll flag = 0;
        ll num = 0;
        ll r = -1;
        for(ll i=0;i<d;++i){
            if(b >> i & 1){
                flag += 100 * (i+1) * p[i] + c[i];
                num += p[i];
            }else{
                r = i;
            }
        }
        if(flag < g){
            ll fl = 100 * (r+1);
            ll sum = (g - flag + fl -1) / fl;
            if(sum >= p[r]){
                continue;
            }
            num += sum;
        }
        ans = min(ans, num);
    }
    cout<<ans<<endl;

    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main() {
    int n;
    cin >> n;
    vector<int> v(n);
    for (int i = 0; i < n; i++) cin >> v[i];
    int m;
    cin >> m;
    vector<int> vv(m);
    for (int i = 0; i < m; i++) cin >> vv[i];
    cout << (v < vv) << endl;
}


Measured memory_bytes: 3088
import java.util.*;
import java.io.*;

class Main {

	void solve() {

		out.println(inint() + inint()/2);
		
	}
	
	public static Scanner in = new Scanner(System.in);
	public static PrintWriter out = new PrintWriter(System.out);
	
	public static void main(String[] args) {
		new Main().solve();
		out.flush();
	}
	
	public int inint() {
		return in.nextInt();
	}
	
	public String instr() {
		return in.next();
	}

}

Measured memory_bytes: 25172
n, k = map(int, input().split())
h = list(map(int, input().split()))

inf = 10**10
dp = [0] + [inf] * (n-1)

for i in range(1,n):
    j = 1
    while j <= k and j <= i:
        dp[i] = min(dp[i-j]+abs(h[i]-h[i-j]), dp[i])
        j += 1
    
print(dp[-1])

Measured memory_bytes: 85628
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef pair<int, int> pii;

int main()
{
	int n,a[105]={};
	vector<int>v;
	cin>>n;
	for(int i=0;i<n;i++)
	{
		cin>>a[i];
		if(i)a[i]+=a[i-1];
	}
	for(int i=0;i<n;i++)
	{
		v.push_back(max(a[n-1]-a[i],a[i])-min(a[n-1]-a[i],a[i]));
	}
	sort(v.begin(),v.end());
	cout<<v[0]<<endl;
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define F first
//#define S second
//#define T second.first
//#define C second.second
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<int,pair<int,int>> piii;

const int N= 1e5+5, L = 14, OO = 0x3f3f3f3f;
const ll M=10 ;
const double ESP = 1e-8;


int main(){
//    freopen("input.txt", "r", stdin);
//    freopen("output.txt", "w", stdout);
    ios_base::sync_with_stdio(0);
    cin.tie(NULL);
    int n;
    cin>>n;
    int cnt = 0;
    for(int i=1; i<=n; i++){
        string s = to_string(i);
        if(s.size()&1)
            cnt++;
    }
    cout<<cnt<<endl;
}
/*
*/


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

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

#define pb push_back
#define rep(i, n) for(int i = 0; i < (n); i++)
#define FOR(i, a, n) for(int i = a; i < (n); i++)
#define mod (ll)(1e9+7)
#define int ll

__attribute__((constructor))
void initial() {
  cin.tie(0);
  ios::sync_with_stdio(false);
}

signed main() {
	ll n, result = 0;
  map<int, int> num;
  cin >> n;
  rep(i, n) {
    int a;
    cin >> a;
    num[a - 1]++;
    num[a]++;
    num[a + 1]++;
  }
  for(auto i : num) {
    result = max(result, i.second);
  }
  cout << result << endl;
}

Measured memory_bytes: 6144
from collections import deque
from enum import Enum
import sys
import math

BIG_NUM = 2000000000
MOD = 1000000007
EPS = 0.000000001


LIST = deque()

num_command = int(input())

for loop in range(num_command):

    input_command = input()

    if input_command == 'deleteFirst':
        LIST.popleft()
    elif input_command == 'deleteLast':
        LIST.pop();
    else:
        com,num = input_command.split()

        if com == 'insert':
            LIST.appendleft(num)
        elif com == 'delete':
            try:
                LIST.remove(num)
            except:
                pass

print(' '.join(LIST))



Measured memory_bytes: 70164
n = int(input())
a = [int(i) for i in input().split()]
ans = 0
for i in range(1,n):
    if a[i] > a[i-1]:
        continue
    else:
        ans += abs(a[i]-a[i-1])
        a[i] = a[i-1]

print(ans)

Measured memory_bytes: 32320
#!/usr/bin/env python3
# n,m = map(int,sys.stdin.readline().split())
# a = tuple(map(int,sys.stdin.readline().split())) # single line with multi param
# a = tuple(sys.stdin.readline() for _ in range(n)) # multi line with single param
# a = tuple(tuple(map(int,sys.stdin.readline().rstrip().split())) for _ in range(N)) # multi line with multi param
# s = sys.stdin.readline().rstrip()
# n = int(sys.stdin.readline())
# INF = float("inf")
import sys,collections

h1,m1,h2,m2,k = map(int,sys.stdin.readline().split())

s = h1*60+m1
e = h2*60+m2
print(e-s-k)


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

#define min(A, B) ((B) > (A) ? (A) : (B))

/*
int min(int a, int b)
{
    return (b > a ? a : b);
}
*/

int main(void)
{
    int i, j, k;
    int n;
    int div[10001];
    static int dp[2][5001][2];
    
    scanf("%d", &n);
    
    for (i = 1; i <= n - 1; i++){
        scanf("%d", div + i);
    }
    memset(dp, 1, sizeof(dp));
    dp[0][0][0] = dp[0][0][1] = 0;
    
    for (i = 0; i <= n / 2; i++){
        for (j = 0; j <= n / 2; j++){
            if (i){
                dp[i & 1][j][0] = dp[(i - 1) & 1][j][0];
                dp[i & 1][j][1] = dp[(i - 1) & 1][j][0] + div[i + j];
            }
            if (j){
                dp[i & 1][j][0] = min(dp[i & 1][j][0], dp[i & 1][j - 1][1] + div[i + j]);
                dp[i & 1][j][1] = min(dp[i & 1][j][1], dp[i & 1][j - 1][1]);
            }
        }
    }
     
    printf("%d\n", min(dp[0][n / 2][0], dp[0][n / 2][1]));
     
    return (0);
}

Measured memory_bytes: 484
#include <bits/stdc++.h>
#include <vector>
#include <algorithm>
#include <deque>
#include <numeric>
#include <utility>
#define sign(a) ((a>0)-(a<0))
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define LL long long
#define INF (LL)(1LL<<60)
#define all(a) a.begin(), a.end()
#define gr greater<LL>()

using namespace std;

void solve(long long N, long long D, std::vector<std::vector<long long>> X){
    LL ans=0;
    rep(i, N-1){
        for(int j=i+1; j<N; j++){
            double tmp=0;
            rep(k, D){
                tmp += (X[i][k]-X[j][k])*(X[i][k]-X[j][k]);
            }
            double sq = sqrt(tmp);
            if(sq-floor(sq) == 0)ans++;
        }
    }
    cout << ans << endl;
}

int main(){
    long long N;
    scanf("%lld",&N);
    long long D;
    scanf("%lld",&D);
    std::vector<std::vector<long long>> X(N, std::vector<long long>(D));
    for(int i = 0 ; i < N ; i++){
        for(int j = 0 ; j < D ; j++){
            scanf("%lld",&X[i][j]);
        }
    }
    solve(N, D, std::move(X));
    return 0;
}


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

int main() {
	long long N, M;
	cin >> N >> M;
	if (N == 1 && M == 1) cout << 1 << endl;
	else if (N == 1) cout << max(0ll, M - 2) << endl;
	else if (M == 1) cout << max(0ll, N - 2) << endl;
	else cout << (N - 2) * (M - 2) << endl;
}

Measured memory_bytes: 256
def insertion_sort(A, N):
    yield A
    for i in range(1, N):
        v = A[i]
        j = i - 1
        while j >= 0 and A[j] > v:
            # 右にずらす
            A[j + 1] = A[j]
            j -= 1
        A[j + 1] = v
        yield A

N = int(input())
A = list(map(int, input().split()))
for li in insertion_sort(A, N):
    print(*li)


Measured memory_bytes: 5984
using System;
using System.Linq;

namespace CSharp
{
    class Program
    {
        static void Main()
        {
            var input = Console.ReadLine().Split(' ').Select(int.Parse).ToArray();
            var X = input[0];
            var A = input[1];

            Console.WriteLine(X < A ? 0 : 10);
        }
    }
}


Measured memory_bytes: 13396
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
int main() {
    cout.precision(15);
    ll N, K;
    cin >> N >> K;
    double p = 0, q = 1;
    for ( ll i = 1; i <= N; i++ ) {
        ll x = i;
        double q = 1;
        while ( x < K ) {
            x *= 2;
            q /= 2;
        }
        p += q;
    }
    p /= N;
    cout << p << '\n';
    return 0;
}

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


int main(){
    int n,m;
    
    cin >> n >> m;
    
    if(m<n-1){
        cout << "No" << endl;
        return 0;
    }
    
    vector<vector<int>> connect(n+1);
    
    int a,b;
    for(int i=0; i<m; i++){
        cin >> a >> b;
        connect[a].push_back(b);
        connect[b].push_back(a);
    }
    
    vector<int> ok(n+1,-1);
    
    queue<int> reach;
    
    reach.push(1);
    ok[1] = 0;
    while(!reach.empty()){
        for(int i=0; i<(int)connect.at(reach.front()).size(); i++){
            if(ok[connect.at(reach.front())[i]]==-1){//まだきてない
                ok[connect.at(reach.front())[i]] = reach.front();//親の番号
                reach.push(connect.at(reach.front())[i]);
            }
        }
        reach.pop();
    }
    
    bool comp = true;
    for(int i=2; i<=n; i++){
        if(ok[i]==-1)comp = false;
    }
    
    if(!comp)cout << "No" << endl;
    else{
        cout << "Yes" << endl;
        for(int i=2; i<=n; i++){
            cout << ok[i] << endl;
        }
    }
    
    return 0;
}



Measured memory_bytes: 10164
#!/usr/bin/env python
# -*- coding: utf-8 -*-


def main():
  text = input().strip()
  text = text.replace('BC', 'X')
  base = 0
  count = 0

  for i in range(len(text)):
    if text[i] == 'A':
      base += 1
    elif text[i] == 'X':
      count += base
    else:
      base = 0

  print(count)


if __name__ == '__main__':
  main()



Measured memory_bytes: 3500
<?php

	$s = trim(fgets(STDIN));
	if($s == "zyxwvutsrqponmlkjihgfedcba") echo -1;
	else{
	    $n = strlen($s);
	    for($i=0; $i<26; $i++) $f[$i] = false;
	    for($i=0; $i<$n; $i++){
	        $f[ord($s[$i]) - ord('a')] = true;
	    }
	    if($n < 26){
	        for($i=0; $i<$n; $i++) echo $s[$i];
	        $i = 0;
	        while($f[$i]) $i++;
	        echo chr(ord('a') + $i);
	    } else {
	        $ans = -1;
	        $l = $n-1;
	        while(true){
	            $x = ord($s[$l]) - ord('a');
	            $f[$x] = false;
	            $x++;
    	        while($x<26){
    	            if(!$f[$x]){
    	                $ans = $x;
    	                break;
    	            }
    	            $x++;
    	        }
    	        if($ans>0){
    	            for($i=0; $i<$l; $i++) echo $s[$i];
    	            echo chr(ord('a') + $ans);
    	            break;
    	        }
    	        $l--;
	        }
	    }
	}
	
?>

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

using namespace std;

#define INF 100000000
#define YJ 1145141919
#define INF_INT_MAX 2147483647
#define INF_LL 9223372036854775
#define INF_LL_MAX 9223372036854775807
#define EPS 1e-10
#define MOD 1000000007
#define MOD9 998244353
#define Pi acos(-1)
#define LL long long
#define ULL unsigned long long
#define LD long double

#define int long long

using II = pair<int, int>;

int gcd(int a, int b) { return b != 0 ? gcd(b, a % b) : a; }
int lcm(int a, int b) { return a * b / gcd(a, b); }
int extgcd(int a, int b, int &x, int &y) { int g = a; x = 1; y = 0; if (b != 0) g = extgcd(b, a % b, y, x), y -= (a / b) * x; return g; }

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n) FOR(i,0,n)
#define ALL(a)  begin((a)), end((a))
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define MP make_pair
#define SZ(a) int((a).size())

const int MAX_N = 305;
int N;
int A[4];
double dp[MAX_N][MAX_N][MAX_N];

double solve(int a, int b, int c)
{
  if(a == 0 && b == 0 && c == 0) {
    return 0;
  } else if(dp[a][b][c] != -1) {
    return dp[a][b][c];
  }

  double ret = 0;
  if(a > 0) {
    ret += solve(a-1, b, c) * a / N;
  }
  if(b > 0) {
    ret += solve(a+1, b-1, c) * b / N;
  }
  if(c > 0) {
    ret += solve(a, b+1, c-1) * c / N;
  }
  ret = (ret + 1) * N / (a + b + c);

  return dp[a][b][c] = ret;

}

signed main()
{
  cin >> N;
  REP(n,N) {
    int a; cin >> a;
    A[a]++;
  }

  REP(i,MAX_N) {
    REP(j,MAX_N) {
      REP(k,MAX_N) {
        dp[i][j][k] = -1;
      }
    }
  }

  printf("%.15f\n", solve(A[1], A[2], A[3]));

  return 0;
}

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

using namespace std;

int search(long long A[], int n, long long B[], int m, int K)
{
  int ans = 0, i;
  int k = K;
  for(i=0;i<n;i++)
  {
    if(K<A[i])
    {break;}

    K = K-A[i];
    int st = 0, end = m-1;
    while(st<end)
    {
      int mid = (st+end+1)/2;
      if (B[mid] <= K)
        st = mid;
      else
        end = mid-1;
    }
    //cout<< K-A[i]<<" "<<i<< " " <<st<<endl;
    if(B[st]<=K)
    ans = max(i+1+st+1, ans);
    else ans = max(ans, i+1);
    K=k;
  }
  return ans;
}

void solve()
{
  int n, m,K;
  cin >> n>> m>>K;

  long long A[200000], B[200000];
  int i;
  for(i=0;i<n;i++)
  {
    cin >> A[i];
    if(i!=0)A[i] = A[i]+A[i-1];
  }
  for(i=0;i<m;i++)
  {
    cin >> B[i];
    if(i!=0)B[i] = B[i]+B[i-1];
  }

  int ans;
  ans = search(A,n,B,m, K);
  ans = max(ans, search(B, m, A, n, K));
  cout << ans<< endl;
}

int main()
{
  int t;
  t=1;

  while(t--)
  {
    solve();
  }
}


Measured memory_bytes: 6788
#include<bits/stdc++.h>
using namespace std;
inline int read()
{
    int num = 0;
    char c;
    bool flag = false;
    while ((c = getchar()) == ' ' || c == '\n' || c == '\r');
        if (c == '-') flag = true;
    else
        num = c - '0';
    while (isdigit(c = getchar()))
    num = num * 10 + c - '0';
    return (flag ? -1 : 1) * num;
}
int main()
{
	int n,a,b,sum=0;
	n=read();
	for(int i=1;i<=n;i++)
	{
		a=read();
		b=read();
		sum+=b-a+1;
	}
	cout<<sum<<endl;
	return 0;
}



Measured memory_bytes: 256
#include <stdio.h>
#include <bits/stdc++.h>
#define endl '\n'
using namespace std;
using namespace rel_ops;

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> ii;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ii> vii;
typedef vector<vii> vvii;

map<ii, int> memo;

int n;
int W;
int wt[110];
int val[110];

int f(int i, int w) {
    if (i == n)
        return 0;
    ii cur(i, w);
    if (memo.count(cur))
        return memo[cur];
    int a = f(i + 1, w);
    int b = -1;
    if (wt[i] <= w)
        b = val[i] + f(i + 1, w -wt[i]);
    return memo[cur] = max(a, b);
}

int main() {
#ifdef LOCAL
    freopen("in", "r", stdin);
    //freopen("out", "w", stdout);
#endif
    ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
    cin >> n >> W;
    for (int i = 0; i < n; i++) {
        cin >> wt[i] >> val[i];
    }
    cout << f(0, W) << endl;
    return 0;
}

Measured memory_bytes: 6272
#include<iostream>
#include<string>
#include<vector>

int main(){
  int a,b,count;
  std::cin>>a>>b;
  std::string str[60];
  //std::vector <std::string> str(a+3,".");
  for(int i=1;i<=a;i++){
    std::cin>>str[i];
  }
  for(int i=0;i<=b+1;i++){
    str[0].insert(0,".");
    str[a+1].insert(0,".");
  }
  for(int i=1;i<=a;i++){
    str[i].insert(b,".");
    str[i].insert(0,".");
  }
 /* for(int i=0;i<=a+1;i++){
    for(int j=0;j<=b+1;j++){
      std::cout<<str[i][j];   
    }
    std::cout<<std::endl;
  }*/
  for(int i=1;i<=a;i++){
    for(int j=1;j<=b;j++){
      count=0; 
      //std::cout<<str[i][j]<<std::endl;
      if(str[i][j]=='#'){
        std::cout<<str[i][j];
        continue;
      }else {
        if(str[i-1][j-1]=='#'){
        count++;
      }
        if(str[i-1][j]=='#'){
        count++;
      }
        if(str[i-1][j+1]=='#'){
        count++;
      }
        if(str[i][j-1]=='#'){
        count++;
      }
        if(str[i][j+1]=='#'){
        count++;
      }
        if(str[i+1][j-1]=='#'){
        count++;
      }
        if(str[i+1][j]=='#'){
        count++;
      }
        if(str[i+1][j+1]=='#'){
        count++;
      }
      }
      std::cout<<count;
    }
    std::cout<<std::endl;
  } 
 /* for(int i=1;i<=a;i++){
    for(int j=1;j<=b;j++){
      std::cout<<str[i][j];   
    }
    std::cout<<std::endl;
  }*/
  return 0;
}


Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
    public static void main(String... args) {
        // 入力
        Scanner sc = new Scanner(System.in);
        double w = sc.nextDouble();
        double h = sc.nextDouble();
        double x = sc.nextDouble();
        double y = sc.nextDouble();

        if (x == w / 2.0 && y == h / 2.0) {
            System.out.println(w * h / 2.0 + " " + 1);
        } else if (x == w / 2.0) {
            System.out.println(w * h / 2.0 + " " + 0);
        } else if (y == h / 2.0) {
            System.out.println(w * h / 2.0 + " " + 0);
        } else if (x == w || y == h) {
            System.out.println(w * h / 2.0 + " " + 0);
        } else if (x == 0 || y == 0) {
            System.out.println(w * h / 2.0 + " " + 0);
        } else if (x/y == w/h || (w-x)/y == w/h) {
            System.out.println(w * h / 2.0 + " " + 0);
        } else {
            System.out.println(w * h / 2.0 + " " + 0);
//            double minx = 0;
//            double miny;
//            if (x < w - x) {
//                minx = x;
//            } else {
//                minx = w - x;
//            }
//            if (y < h - y) {
//                miny = y;
//            } else {
//                miny = h - y;
//            }
//
//            double q1 = minx * h;
//            double q2 = miny * w;
//
//            if (q1 < q2) System.out.println(q1 + " " + 0);
//            else if (q1 < q2) System.out.println(q2 + " " + 0);
//            else System.out.println(q1 + " " + 1);
        }
    }
}

Measured memory_bytes: 23124
from collections import deque
h,w=map(int,input().split())
grid=[input() for _ in range(h)]
vis=[[0]*w for _ in range(h)]
vis[0][0]=1
que=deque([(0,0)])
while que:
	p,q=que.popleft()
	for x,y in ((-1,0),(0,-1),(1,0),(0,1)):
		if 0<=p+x<w and 0<=q+y<h and vis[q+y][p+x]<1 and grid[q+y][p+x]==".":
			vis[q+y][p+x]=vis[q][p]+1
			que.append((p+x,q+y))
if not vis[h-1][w-1]:
	print(-1)
else:
	print(h*w-sum(c.count("#")for c in grid)-vis[h-1][w-1])

Measured memory_bytes: 3316
#include <cstdio>
#include <vector>
#include <algorithm>

int main() {
  int n;
  scanf("%d", &n);
  std::vector<int> h(n), dp(n);
  for (int i = 0; i < n; ++i) {
    scanf("%d", &h[i]);
    if (!i) dp[i] = 0;
    else dp[i] = 2e9;
    if (i >= 1) {
      dp[i] = std::min(dp[i], dp[i - 1] + std::abs(h[i] - h[i - 1]));
    }
    if (i >= 2) {
      dp[i] = std::min(dp[i], dp[i - 2] + std::abs(h[i] - h[i - 2]));
    }
  }
  printf("%d\n", dp.back());
  return 0;
}


Measured memory_bytes: 1024
#include <bits/stdc++.h>
using ll = long long;
using namespace std;
#define rep(i,n) for(int i=0, i##_len=(int)(n); i<i##_len; i++)
#define reps(i,n) for(int i=1 , i##_len=(int)(n);i<=i##_len;i++)
#define rrep(i,n) for(int i=((int)(n)-1);i>=0;i--)
#define rreps(i,n) for(int i=((int)(n));i>0;i--)
#define all(x) (x).begin(), (x).end()
#define F first
#define S second
#define mp make_pair
#define pb push_back
#define solve(a) ((a)?"Yes":"No")
typedef vector<long long> V;
typedef vector<V> VV;
typedef pair<long long , long long> P;
typedef vector<P> VP;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1;} return 0;}
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1;} return 0;}
const long long INFLL = 1LL<<62;
const int INF = 1<<30;
const double PI=acos(-1);
int main(){
    int g;
    cin >>g;
    vector<vector<int>>path(g);
    vector<int>dis(g,INF);
    queue<int>q;
    q.push(0);
    dis[0]=0;
    int u,k,v;
    int at=0;
    rep(i,g){
        
        cin>>u>>k;
        u--;
        rep(j,k){
            cin>>v;
            v--;
            path[u].push_back(v);
        }
    }
    while(!q.empty()){
        at=q.front();
        q.pop();
        for(auto itr=path[at].begin();itr!=path[at].end();itr++){
            if(chmin(dis[*itr],dis[at]+1)){
                q.push(*itr);
            }
        }
    }
    rep(i,g){
        cout<<i+1<<" "<<((dis[i]!=INF)?dis[i]:-1)<<endl;
    }
    //cout<<ans<<endl;
}


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

int main() 
{
    map<int, int> m;
    int N;
    cin >> N;
    
    for(int i = 0; i < N; i++) {
        int a;
        cin >> a;
        m[a]++;
        m[a - 1]++;
        m[a + 1]++;
    }
    
    int ans = 0;
    for ( auto x : m ) {
        ans = max(ans, x.second);
    }
    cout << ans << endl;
    
}

Measured memory_bytes: 7916
#include<iostream>
#include<cstring>
#include<cstdio>
#include<vector>
#include<stack>
#include<queue>
#include<list>
#include<algorithm>

using namespace std;

const int INF=0x3f3f3f3f;
const int O=1e-6;

const int Gx[4]= {0,1,0,-1},Gy[4]= {1,0,-1,0};

struct Blk
{
	int xl,xr,yl,yr;
} B[1010];

int MappingX[3010],Xlen;
int MappingY[3010],Ylen;
int W,H,T;
bool Grd[3010][3010];

void LSx()
{
	vector<int> Mtx;
	for(int i=0; i<T; ++i)
	{
		Mtx.push_back(B[i].xl);
		Mtx.push_back(B[i].xr);
		if(B[i].xl>0)
		{
			Mtx.push_back(B[i].xl-1);
		}
		if(B[i].xr<W-1)
		{
			Mtx.push_back(B[i].xr+1);
		}
	}
	sort(Mtx.begin(),Mtx.end());
	Mtx.erase(unique(Mtx.begin(),Mtx.end()),Mtx.end());
	Xlen=Mtx.size();
	for(int i=0; i<Xlen; ++i)
	{
		MappingX[i]=Mtx[i];
	}
	return;
}

void LSy()
{
	vector<int> Mtx;
	for(int i=0; i<T; ++i)
	{
		Mtx.push_back(B[i].yl);
		Mtx.push_back(B[i].yr);
		if(B[i].yl>0)
		{
			Mtx.push_back(B[i].yl-1);
		}
		if(B[i].yr<H-1)
		{
			Mtx.push_back(B[i].yr+1);
		}
	}
	sort(Mtx.begin(),Mtx.end());
	Mtx.erase(unique(Mtx.begin(),Mtx.end()),Mtx.end());
	Ylen=Mtx.size();
	for(int i=0; i<Ylen; ++i)
	{
		MappingY[i]=Mtx[i];
	}
	return;
}

int Turn(int* Line,int Len,int Tar)
{
	int l=0,r=Len;
	int m;
	while(l<r)
	{
		m=(l+r)/2;
		if(Line[m]<Tar)
		{
			l=m+1;
		}
		else
		{
			r=m;
		}
	}
	return r;
}

bool Check(int x,int y)
{
	return x>=0&&y>=0&&x<Xlen&&y<Ylen;
}

int ans=0;

int main()
{
	while(cin>>W>>H)
	{
		ans=0;
		if(W==H&&H==0)
		{
			return 0;
		}
		scanf("%d",&T);
		for(int i=0; i<T; i++)
		{
			scanf("%d%d%d%d",&B[i].xl,&B[i].yl,&B[i].xr,&B[i].yr);
			--B[i].xr;--B[i].yr;
		}
		LSx();
		LSy();
		memset(Grd,0,sizeof(Grd));
		for(int i=0; i<T; ++i)
		{
			B[i].xl=Turn(MappingX,Xlen,B[i].xl);
			B[i].xr=Turn(MappingX,Xlen,B[i].xr);
			B[i].yl=Turn(MappingY,Ylen,B[i].yl);
			B[i].yr=Turn(MappingY,Ylen,B[i].yr);
			for(int x=B[i].xl; x<=B[i].xr; ++x)
			{
				for(int y=B[i].yl; y<=B[i].yr; ++y)
				{
					Grd[x][y]=true;
				}
			}
		}
		//
		/*
		for(int x=0; x<Xlen; ++x)
		{
			for(int y=0; y<Ylen; ++y)
			{
				if(Grd[x][y])
				{
					cout<<"*";
				}
				else
				{
					cout<<"O";
				}
			}
			cout<<endl;
		}
		//*/
		stack<int> Xstk;
		stack<int> Ystk;
		int Nowx,Nowy;
		for(int x=0; x<Xlen; ++x)
		{
			for(int y=0; y<Ylen; ++y)
			{
				if(!Grd[x][y])
				{
					Xstk.push(x);
					Ystk.push(y);
					ans++;
					Grd[x][y]=true;
					while(!Xstk.empty())
					{

						Nowx=Xstk.top();
						Xstk.pop();
						Nowy=Ystk.top();
						Ystk.pop();
						Grd[Nowx][Nowy]=true;
						for(int i=0; i<4; ++i)
						{
							if(!Grd[Nowx+Gx[i]][Nowy+Gy[i]]&&Check(Nowx+Gx[i],Nowy+Gy[i]))
							{
								Grd[Nowx+Gx[i]][Nowy+Gy[i]]=true;
								Xstk.push(Nowx+Gx[i]);
								Ystk.push(Nowy+Gy[i]);
							}
						}
					}
					/*
					for(int gg=0; gg<Xlen; ++gg)
					{
						for(int ggr=0; ggr<Ylen; ++ggr)
						{
							if(Grd[gg][ggr])
							{
								cout<<"*";
							}
							else
							{
								cout<<"O";
							}
						}
						cout<<endl;
					}
					*/
				}
			}
		}
		printf("%d\n",ans);
	}
}


Measured memory_bytes: 13140
#include<iostream>
using namespace std;
int main()
{
    int a1 = 0, a4 = 0, n, a;
    cin >> n;
    for(int i = 0; i < n; i++){
        cin >> a;
        if(a % 4 == 0) a4 += 1;
        if(a % 2 == 1) a1 += 1;
    }
    if(a4 + a1 == n){
        cout << (a1 <= a4 + 1 ? "Yes" : "No") << endl;
    }
    else cout << (a1 <= a4 ? "Yes" : "No") << endl;
    return 0;
}

Measured memory_bytes: 256
#define _CRT_SECURE_NO_WARNINGS
#define _USE_MATH_DEFINES
#include "bits/stdc++.h"
//#include <intrin.h>

#define fore(i,a,b) for(int i = a; i < (b); i++)
#define fr(i,a,b) for(int i = a - 1; i >= b; i--)
#define fast ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0)
#define N 300005
#define inf 2000000000
#define EPS 1e-6
#define MOD (ll)1e15
#define __builtin_popcount(x) __popcnt(x)

using namespace std;

typedef long long ll;
typedef pair<int, int> pr;
typedef pair<int, pair<int, int>> tup;

inline void solve()
{
	int n, r;
	cin >> n >> r;
	cout << (n < 10 ? r + (100 * (10 - n)) : r);
}

int main()
{
	fast;
#if defined(_DEBUG)
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#endif
	int q = 1;
	//cin >> q;
	while (q--)
	{
		solve();
		cout << '\n';
	}
}

Measured memory_bytes: 256
import sys

n = int(input())
s = input()

r = []
g = []
b = []

for i in range(n):
  c = s[i]
  if c == 'R':
    r.append(i)
  elif c == 'G':
    g.append(i)
  else:
    b.append(i)
#print(r)
#print(g)
#print(b)

ans = len(r) * len(g) * len(b)

for i in range(n-2):
  for d in range(1, n):
    j = i + d
    k = i + 2 * d
    if k > (n-1):
      break
    if s[i] != s[j] and s[j] != s[k] and s[k] != s[i]:
      ans -= 1
      # print(i, j, k)
print(ans)

Measured memory_bytes: 68352
n = int(input())
a = []
max_count = 0
maxi = 0
max_id = 0
for i in range(n):
  a.append(int(input()))
  if a[i]>maxi:
    max_count = 1
    max_id = i
    maxi = a[i]

  elif a[i]==maxi:
    max_count += 1
    
if max_count <= 1:
  for i in range(max_id):
    print(maxi)
  print(sorted(a, reverse=True)[1])
  for i in range(max_id + 1, n):
    print(maxi)
    
else:
  for i in range(n):
    print(maxi)

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

#define int long long
#define rep(i,a,n) for(int i = a; i < n; i++)
#define pb push_back
#define eb emplace_back
#define dump(x) cout << #x << " = " << (x) << endl
#define chk() cout << "now" << endl;
#define ALL(x) (x).begin(),(x).end()
#define SORT(c) sort((c).begin(), (c).end())
#define SORTG(c) sort(ALL(c), greater<int>());
#define fi first
#define se second
int INF = 1e9 + 7;

typedef pair<int,int> P;
typedef vector<int> vi;

int L;

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

    cin>>L;
    int digit=0, sum=1;
    while(1) {
        sum*=2;
        if(sum>L) break;
        digit++;
    }
 
    int n=digit+1,m=2*digit,index=digit-1,rL=L;;
    L-=(1LL<<digit);
    int ans[n+1][n+1]={};
    // dump(digit); dump(n); dump(m); dump(index); dump(L);
    while(L>0) {
        if(L>=(1LL<<(index))) {
            
            ans[index+1][n]=rL-L;
            L-=(1LL<<(index));
            m++;
        }
        --index;
    }
    cout<<n<<' '<<m<<endl;
    for(int i = 1;i<n;i++) {
        cout<<i<<' '<<i+1<<' '<<0<<endl;
        cout<<i<<' '<<i+1<<' '<<(1LL<<i-1)<<endl;
    }
    rep(i,0,n+1) {
        rep(j,0,n+1) {
            if(ans[i][j]>0) {
                cout<<i<<' '<<j<<' '<<ans[i][j]<<endl;
            }
        }
    }
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <climits>
#include <cassert>

using namespace std;

string s;

int main() {
#ifdef __APPLE__
    freopen("input3.txt", "r", stdin);
#endif
cin >> s;

    long last_idx = s.length() - 1;
    long min_required_flips = LONG_MAX;

    for (long i = 0; i < last_idx; ++i) {
        if (s[i] != s[i+1]) {
            // 1100111
            // i = 1
            // last_idx = 6
            //
            // i = 3

            // 010
            // i = 1
            // last_idx = 2

            // 0001
            // i = 2
            // last_idx = 3
//            long required_flips = max(i+1, last_idx-i);
            min_required_flips = min(min_required_flips, max(i+1, last_idx-i));
        }
    }

    if (min_required_flips == LONG_MAX) {
        cout << last_idx + 1 << endl;
        return 0;
    }

    cout << min_required_flips << endl;

    return 0;
}

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

#define llint long long int

using namespace std;

int main(){
    int N;

    cin >> N;

    vector<int> A(N + 1);
    llint sum = 0;

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

        cin >> B;

        if(A[i] < B){
            B -= A[i];
            A[i] = 0;

            if(A[i + 1] < B){
                A[i + 1] = 0;
            }else{
                A[i + 1] -= B;
            }
        }else{
            A[i] -= B;
            B = 0;
        }
    }
    llint nokori = 0;

    for(int i = 0; i < N + 1; i ++){
        nokori += A[i];
    }
    cout << sum - nokori << endl;
}

Measured memory_bytes: 640
#include<bits/stdc++.h>
#define ll long long
#define sort(a) sort(a.begin(), a.end())
#define loop(n) for(ll i = 0; i<n; i++)
using namespace std;
 
int main(){
    int n, r;
    cin>>n>>r;
    if(n>=10){
        cout<<r<<"\n";
    }
    else cout<<r+100*(10-n)<<"\n";
    return 0;
}

Measured memory_bytes: 256
/*
csc -debug B.cs && mono --debug B.exe <<< "6
khabarovsk 20
moscow 10
kazan 50
kazan 35
moscow 60
khabarovsk 40"
*/

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading;
using System.Reflection;

public class HelloWorld {
    public static void SolveCodeForces() {
        var N = cin.NextInt();
        var R = Helpers.CreateArray(N, _ => Console.ReadLine().Split()).Select((a, i) => new { i = i+1, s = a[0], p = int.Parse(a[1]) })
            .OrderBy(a => a.s).ThenByDescending(a => a.p).ToArray();

        foreach (var a in R) {
            System.Console.WriteLine(a.i);
        }
    }

    static Scanner cin = new Scanner();
    static StringBuilder cout = new StringBuilder();

    static public void Main () {
        SolveCodeForces();
        // IncreaseStack(SolveCodeForces);
        // System.Console.Write(cout.ToString());
    }

    public static void IncreaseStack(ThreadStart action, int stackSize = 128000000)
    {
        var thread = new Thread(action, stackSize);
        thread.Start();
        thread.Join();
    }
}

public static class Helpers {
    public static T[] CreateArray<T>(int length, Func<int, T> itemCreate) {
        var result = new T[length];
        for (var i = 0; i < result.Length; i++)
            result[i] = itemCreate(i);
        return result;
    }
}

public class Scanner
{
    private string[] line = new string[0];
    private int index = 0;

    public string Next() {
        if (line.Length <= index) {
            line = Console.ReadLine().Split(' ');
            index = 0;
        }
        var res = line[index];
        index++;
        return res;
    }

    public int NextInt() {
        return int.Parse(Next());
    }

    public long NextLong() {
        return long.Parse(Next());
    }

    public ulong NextUlong() {
        return ulong.Parse(Next());
    }

    public string[] Array() {
        line = Console.ReadLine().Split(' ');
        index = line.Length;
        return line;
    }

    public int[] IntArray(int emptyPrefixLen = 0) {
        var array = Array();
        var result = new int[emptyPrefixLen + array.Length];
        for (int i = 0; i < array.Length; i++)
            result[emptyPrefixLen + i] = int.Parse(array[i]);
        return result;
    }

    public long[] LongArray() {
        var array = Array();
        var result = new long[array.Length];
        for (int i = 0; i < array.Length; i++)
            result[i] = long.Parse(array[i]);
        return result;
    }

    public ulong[] UlongArray() {
        var array = Array();
        var result = new ulong[array.Length];
        for (int i = 0; i < array.Length; i++)
            result[i] = ulong.Parse(array[i]);
        return result;
    }
}

Measured memory_bytes: 13792
n = int(input())
f = [list(map(int, input().split())) for _ in range(n)]
p = [list(map(int, input().split())) for _ in range(n)]

ans = -float('inf')
for k in range(1, 2**10):
    *bi, = map(int, bin(k).zfill(10).replace('b', '0')[::-1])
    ans = max(ans, sum([p[i][[bi[j] & f[i][j] for j in range(10)].count(1)]
              for i in range(n)]))
print(ans)


Measured memory_bytes: 3064
#include<bits/stdc++.h>
#include<vector>
using namespace std;
int main()
{
    int a[3];
    for(int i=0;i<3;i++) cin>>a[i];
    swap(a[0],a[1]);
    swap(a[0],a[2]);
    for(int i=0;i<3;i++){
        cout<<a[i]<<" ";
    }
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
using namespace std;
int main() {
    int n;
    cin >> n;
    int a, minA;
    long long sum = 0;
    cin >> a;
    minA = a;
    for (int i=1; i<n; i++) {
        cin >> a;
        if (a < minA) {
            sum += minA - a;
        } else {
            minA = a;
        }
    }
    cout << sum << endl;
}

Measured memory_bytes: 3592
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int A, B;
  cin >> A >> B;
  
  for(int i = 1; i < 1010; i++){
    int ans_A = i * 0.08;
    int ans_B = i * 0.1;
    if((ans_A == A) && (ans_B == B)){
      cout << i << endl;
      exit(0);
    }
  }
  cout << "-1" << endl;
}

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

using namespace std;

#define rep(i, n) for (int i = 0; i < (n); ++i)
#define all(obj) (obj).begin(), (obj).end()
#define bit(n) (1LL << (n))

typedef long long ll;

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 long long INF = 1LL << 60;

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  
  int n,m; cin>>n>>m;
  
  vector<bool> issafe;
  issafe.assign(n+1, true);
  
  rep(i,m) {
    int a; cin>>a;
    issafe[a] = false;
  }
  
  vector<int> dp(n+1, 0);
  
  dp[0] = 1;
  if(issafe[1]) dp[1] = 1;
  
  for (int i = 2; i < n+1; ++i) {
    if(issafe[i-1]) dp[i] += dp[i-1];
    if(issafe[i-2]) dp[i] += dp[i-2];
    
    dp[i] = dp[i]%1000000007;
  }
  
  cout<<dp[n];
  
  return 0;
}



Measured memory_bytes: 3728
#include<stdio.h>
int main(){
char S[100000];
scanf("%s",S);
int n=0;
int i,j;
int ans=0;
while(1){
	if(S[n]=='0'){
	}else if(S[n]=='1'){
	}else{
		break;
	}
	n=n+1;
}
if((n%2)==0){
	i=1;
	while(S[n/2-1]==S[n/2-1+i]){
		i=i+1;
		if((n/2-2+i)==n){
			break;
		}
	}
	j=1;
	while(S[n/2]==S[n/2-j]){
		j=j+1;
		if((n/2-j+1)==0){
			break;
		}
	}
	if(i>j){
		ans=n/2+j-1;
	}else{
		ans=n/2+i-1;
	}
}else{
	i=1;
	while(S[n/2]==S[n/2+i]){
		i=i+1;
		if((n/2-1+i)==n){
			break;
		}
	}
	j=1;
	while(S[n/2]==S[n/2-j]){
		j=j+1;
		if((n/2-j+1)==0){
			break;
		}
	}
	if(i>j){
		ans=n/2+j;
	}else{
		ans=n/2+i;
	}
}


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

Measured memory_bytes: 256
#include <stdlib.h>
#include <bits/stdc++.h>
#include <math.h>
using namespace std;
using ll=long long;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
inline constexpr ll gcd(ll a,ll b){if(!a||!b)return 0;while(b){ll c=b;b=a%b;a=c;}return a;}
inline constexpr ll lcm(ll a,ll b){if(!a||!b)return 0;return a*b/gcd(a,b);}

int main() {
   int a,b;
   cin>>a>>b;
   int p;
   double sum=0;
   for(int i=1;i<=a;i++){
      double per=1.0/a;
      int now=i;

      while(now<b){
         now*=2;
         per/=2;
      }
      sum+=per;
   }
   cout<<setprecision(15)<<sum<<endl;
}



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

int n, d[110];
bool a[110][110] = {};

void bfs(int u){
  
  queue<int> Q;
  
  Q.push(u);
  d[u] = 0;
  
  while(Q.size()){
    int p = Q.front();
    Q.pop();
    
    for(int i = 2;i <= n;i++){
      if(a[p][i] && d[i] == 0){
        Q.push(i);
        d[i] = d[p] + 1;
      }
    }
  }
}

int main(){
  
  int u, k, v;
  
  cin >> n;
  for(int i = 0;i < n;i++){
    cin >> u >> k;
    for(int j = 0;j < k;j++){
      cin >> v;
      a[u][v] = true;
    }
  }
  
  bfs(1);
  
  for(int i = 1;i <= n;i++){
    if(d[i] || i == 1) cout << i << " " << d[i] << endl;
    else cout << i << " " << -1 << endl;
  }
  
  return 0;
}
 



Measured memory_bytes: 3108
#include<bits/stdc++.h>
using namespace std;
priority_queue<int>pq[2];
char c[200005];
int main()
{
	scanf("%s",c);
	int k=strlen(c),ans=k;
	for(int i=k-1;i>-1;i--)
	{
		if(c[i]=='S')pq[0].push(i);
		else pq[1].push(i);
	}
	while(!pq[0].empty()&&!pq[1].empty())
	{
		if(pq[0].top()>pq[1].top())
		{
			pq[0].pop();
		}
		else
		{
			pq[0].pop(),pq[1].pop(),ans-=2;
		}
	}
	printf("%d",ans);
}

Measured memory_bytes: 1528
def nyu():
    num1= input()
#   num1 = int(num1)
    return num1

def convert(num1):
    lst_num = list(num1)
    #print(lst_num)
    #for x in list(lst_num):
    return lst_num

def check(lst_num):
    i =0
    sum = 0
    for x in list(lst_num):
   #     print("i=",i,"lst_num=",x)
   #     i+=1
        if(x == "1"):
            sum +=1
    print(sum)    

s = nyu()
lst = convert(s)
check(lst)

Measured memory_bytes: 2940
#[allow(dead_code)]
fn is_whitespace(c: &char) -> bool {
    c.is_whitespace()
}

#[allow(dead_code)]
fn is_eol(c: &char) -> bool {
    ['\r', '\n'].contains(c)
}

#[allow(unused_macros)]
macro_rules! input {
    ($var:ident, $($r:tt)*) => {
        input_inner!{$var, $($r)*}
    };

    ($($r:tt)*) => {
        let stdin = std::io::stdin();
        let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));
        #[allow(unused_mut, unused_variables, bare_trait_objects)]
        let mut next = move |f: &Fn(&char)->bool| -> String{
            bytes
                .by_ref()
                .map(|r|r.unwrap() as char)
                .skip_while(|c|f(&c))
                .take_while(|c|!f(&c))
                .collect()
        };
        input_inner!{next, $($r)*};
    };
}

#[allow(unused_macros)]
macro_rules! input_inner {
    ($next:expr) => {};
    ($next:expr, ) => {};

    ($next:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };

    ($next:expr, mut $var:ident : $t:tt $($r:tt)*) => {
        let mut $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };
}

#[allow(unused_macros)]
macro_rules! read_value {
    ($next:expr, ( $($t:tt),* )) => {
        ( $(read_value!($next, $t)),* )
    };

    ($next:expr, [ $t:tt ; eol ]) => {
        $next(&is_eol).split(' ').map(|x| x.parse::<$t>().unwrap()).collect::<Vec<_>>()
    };

    ($next:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
    };

    ($next:expr, chars) => {
        read_value!($next, String).chars().collect::<Vec<char>>()
    };

    ($next:expr, bytes) => {
        read_value!($next, String).into_bytes()
    };

    ($next:expr, usize1) => {
        read_value!($next, usize) - 1
    };

    ($next:expr, parser) => {
        $next
    };

    ($next:expr, $t:ty) => {
        $next(&is_whitespace).parse::<$t>().expect("Parse error")
    };
}

#[allow(unused_imports)]
use std::cmp::{max, min};
#[allow(unused_imports)]
use std::collections::{BinaryHeap, HashMap, HashSet};

#[allow(dead_code)]
struct Edge {
    from: usize,
    to: usize,
}

#[allow(dead_code)]
type Graph = Vec<Vec<usize>>;
#[allow(dead_code)]
const M: usize = 1_000_000_007;

fn main() {
    input! {
        h: usize,
        w: usize,
        n: usize,
    }

    if h > w {
        println!("{}", (n + h - 1) / h);
    } else {
        println!("{}", (n + w - 1) / w);
    }
}


Measured memory_bytes: 4352
import java.util.HashSet;
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        HashSet<Integer> set = new HashSet<>();
        for (int i = 0; i < n; i++) {
            set.add(sc.nextInt());
        }
        System.out.println(set.size());
    }
}

Measured memory_bytes: 35888