akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;

#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/trie_policy.hpp>

using namespace __gnu_pbds;

#define int long long
#pragma GCC optimize ("O3")
#define ll long long
#define vec vector <int>
#define rep(i,a,b) for (ll i=a;i<b;i++)
#define repD(i,a,b) for (ll i=a;i>b;i--)
#define pb push_back
#define pii pair <int,int>
#define mp make_pair
#define ff first
#define ss second
#define all(a) a.begin(),a.end()
#define maa 1000000007
#define Eps 1e-9
#define PI 3.14159265359

typedef tree<pii,null_type,less <pii >,rb_tree_tag,tree_order_statistics_node_update>ind_set;
typedef gp_hash_table<int, int, hash<int> > ht1;   /// if clear is required
typedef cc_hash_table<int, int, hash<int> > ht2;

///*X.find_by_order("index")
///X.order_of_key("key")

///----------------------------------------------------------------------------------

int n,v[102],w[102];
int DP[102][100005];
int cap;
int fun(int i,int rem)
{
    if (rem<0)return -maa;
    if (rem==0)return 0;
    if (i>=n)return 0;
    if (DP[i][rem]!=-1)return DP[i][rem];

    int a=v[i]+fun(i+1,rem-w[i]);
    int b=fun(i+1,rem);
    return DP[i][rem]=max(a,b);


}
void solve()
{
    cin>>n>>cap;
    rep(i,0,n)cin>>w[i]>>v[i];
    rep(i,0,102)rep(j,0,100005)DP[i][j]=-1;
    cout<<fun(0,cap);
}
signed main()
{

    srand(time(NULL));

    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);

///freopen("input.txt","r",stdin);
///freopen("output.txt","w",stdout);

    int t=1;
///cin>>t;
    rep(a,0,t)
    {
        ///cout<<"Case "<<a+1<<": ";
        solve();
    }
}


Measured memory_bytes: 80000
N, *P = map(int, input().split())
L = [int(input()) for _ in range(N)]

mp = sum(P) - 30

minmp = 1e10
Pcnt = [0] * 3
Ks = [-1] * N

while True:

    i = N-1
    while i >= 0:
        pre = cur = Ks[i]
        cur += 1
        if cur >= 3:
            cur = -1
        Ks[i] = cur

        for d, x in ((-1, pre), (1, cur)):

            if x >= 0:
                Pcnt[x] += d
                mp -= abs(P[x])
                P[x] -= d * L[i]
                mp += abs(P[x]) + d * 10

        if cur >= 0:
            break
        i -= 1
    else:
        break

    if min(Pcnt) > 0:
        minmp = min(minmp, mp)

print(minmp)


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

using namespace std;

int n, k, gc, mx, x;

int gcd(int a, int b){
    while(b){
        a %= b;
        swap(a, b);
    }
    return a;
}

int main() {

    cin >> n >> k;

    for(int i = 1; i <= n; ++i){
        cin >> x;
        mx = max(mx, x);
        gc = gcd(gc, x);
    }

    if(k <= mx && k % gc == 0) cout << "POSSIBLE";
    else cout << "IMPOSSIBLE";

    return 0;

}


Measured memory_bytes: 256
n,k = map(int,input().split())
x = [int(i) for i in input().split()]
a = [abs(i) for i in x]
ans = float("inf")

for i in range(n-k+1):
    if x[i] * x[i+k-1] < 0:
        t = min(a[i],a[i+k-1])*2 + max(a[i],a[i+k-1])
    else:
        t = max(a[i],a[i+k-1])
    ans = min(t, ans)

print(ans)

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

int main()
{
    string s, t;
    cin >> s >> t;
    bool ans = true;
    for (int i = 0; i < s.length(); i++)
    {
        if (s.at(i) != t.at(i))
        {
            ans = false;
        }
    }
    if (ans)
    {
        cout << "Yes" << endl;
    }
    else
    {
        cout << "No" << endl;
    }

    return 0;
}

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

using ll = long long;
using ull = unsigned long long;

#define MOD 1000000007

int main(void) {
    string S;
    string prev;
    ll count = 0;
    cin >> S;
    for(ll i = 0;i < S.size();i++) {
        for(ll j = i + 1;j < S.size() + 1;j++) {
            string temp = string(S.begin() + i, S.begin() + j);
            if(prev != temp) {
                count++;
                i = j - 1;
                prev = temp;
                goto aaa;
            }
        }
        break;
        aaa:;
    }
    cout << count << endl;
    return 0;
}


Measured memory_bytes: 640
#include<iostream>
#include<vector>
#include<utility>
using namespace std;
ostream& operator<<(ostream &os, const pair<int,int> &p) {
  os << "(" << p.first << ", " << p.second << ")";
  return os;
}
int main(int argc, char *argv[])
{
  const int BIG = 1000000;
  const int CMAX = 50000;
  for(;;) {
    int n;
    cin >> n;
    if(n == 0) break;
    vector<int> ps;
    for(int i = 0; i < n; i++) {
      int p; cin >> p; ps.push_back(p);
    }
    // shop : at most 100
    // change : at most 49900... too much? to get 50, max = 25000
    // value : (# 500 yen so far, minimum payment) 
    vector<pair<int,int>> dp(CMAX+1, pair<int,int>(BIG, BIG));
    vector<pair<int,int>> dpnew(CMAX+1, pair<int,int>(BIG, BIG));
    dpnew[0] = make_pair(0, 0);
    int cmax = 0;
    for(int i = 0; i < n; i++) {
      // not buying
      for(int j = 0; j <= cmax; j++) {
        dp[j] = dpnew[j];
      }
      // buying
      for(int j = 0; j <= cmax; j++) {
        if(dp[j].first > 0) continue;
        const int p = ps[i] % 1000;
        if(p != 0 && p <= 500) { // got 500!
          const int jj = min(j + 500 - p, CMAX);
          cmax = min(max(cmax, jj), CMAX);
          pair<int,int> dd(dp[j].first - 1, dp[j].second + ps[i]);
          if(dd < dpnew[jj]) {
            dpnew[jj] = dd;
          }
        } else {
          // get 500 if possible!
          const int q = (p == 0 ? 1000 : p) - 500;
          if(j >= q) {
            const int jj = j - q;
            pair<int,int> dd(dp[j].first - 1, dp[j].second + ps[i]);
            if(dd < dpnew[jj]) {
              dpnew[jj] = dd;
            }
          } else { // get change
            const int jj = (j + 1000 - p) % 1000;
            cmax = min(max(cmax, jj), CMAX);
            if( jj <= CMAX) {
              pair<int,int> dd(dp[j].first, dp[j].second + ps[i]);
              if(dd < dpnew[jj]) {
                dpnew[jj] = dd;
              }
            }
          }
        }
      }
    }
    pair<int,int> dd(BIG, BIG);
    for(int j = 0; j <= cmax; j++) {
      if(dpnew[j] < dd) {
        dd = dpnew[j];
      }
    }
    cout << -dd.first << " " << dd.second << endl;
  }
  return 0;
}



Measured memory_bytes: 3676
#include<cstdio>
#include<iostream>
#include<cstring>
#include<algorithm>
using namespace std;
long long a[200005], ans;
int n, p1, p2;
int main()
{
	scanf("%d", &n);
	for(int i = 1; i <= n; ++i) scanf("%d", &a[i]), a[i] += a[i-1];
	ans = a[n];
	for(int i = 1; i <= n; ++i) {
		for(p2 = max(i, p2); p2 <= n; ++p2) {
			if(abs(2*a[p2] - a[i] - a[n]) < abs(2*a[p2+1] - a[i] - a[n])) break;
		}
		for(; p1 <= i; ++p1) {
			if(abs(2*a[p1] - a[i]) < abs(2*a[p1+1] - a[i])) break;
		}
		long long s1 = a[p1], s2 = a[i] - a[p1], s3 = a[p2] - a[i], s4 = a[n] - a[p2];
		ans = min(ans, max(max(s1, s2), max(s3, s4)) - min(min(s1, s2), min(s3, s4)) );
		//printf("%lld %lld %lld %lld, %lld\n", s1, s2, s3, s4, ans);
	}
	printf("%lld\n", ans);
	return 0;
}


Measured memory_bytes: 1792
N, K, Q = map(int, input().split())
A = [int(input()) for i in range(Q)]
d = [0 for i in range(N)]



for i in range(Q):
    d[A[i]-1]+=1

array = []
sum_d = sum(d)
for i in range(N):
    array.append(K-sum_d+d[i])

for i in range(N):
    if array[i] >0: print('Yes')
    else: print('No')


Measured memory_bytes: 12564
#include<bits/stdc++.h>
using namespace std;
int ans =0;
int n;

void func(int key,int i,int cnt,int *a){
    if(i==n){
        if(key<cnt)ans+=cnt-key;
        else if(key>cnt)ans += cnt;
        return;
    }
    int nek = a[i];
    if(nek!=key){
        //cout << "はい" << endl;
        if(key<cnt)ans+=cnt-key;
        else if(key>cnt)ans += cnt;
        func(nek,i+1,1,&a[0]);
    }else{
        //cout << "aaい" << endl;
        func(nek,i+1,cnt+1,&a[0]);
    }
    return;
}


int main(){
    cin >> n;
    vector<int> a(n);
    for(int i=0;i<n;i++){
        cin >> a[i];
    }
    sort(a.begin(),a.end());
    func(1,0,0,&a[0]);
    cout << ans << endl;
    return 0;  
}

Measured memory_bytes: 640
#include <stdio.h>

int main(void) {
  int n;
  scanf("%d", &n);
  int ans = 0;
  for(int i = 0;i < n;i++) {
    int a;
    scanf("%d", &a);
    if(i % 2 == 0 && a % 2 == 1) {
      ans++;
    }
  }
  printf("%d\n", ans);
  return 0;
}


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

int main (){
  string s;

  cin >> s;

  int A = (int)(s.at(0)-'0'),B = (int)(s.at(1)-'0'),C = (int)(s.at(2) - '0'),D = (int)(s.at(3)-'0');

  if(A+B+C+D==7) cout<<A<<'+'<<B<<'+'<<C<<'+'<<D<<"=7"<<endl;
  else if(A-B+C+D==7) cout<<A<<'-'<<B<<'+'<<C<<'+'<<D<<"=7"<<endl;
  else if(A+B-C+D==7) cout<<A<<'+'<<B<<'-'<<C<<'+'<<D<<"=7"<<endl;
  else if(A+B+C-D==7) cout<<A<<'+'<<B<<'+'<<C<<'-'<<D<<"=7"<<endl;
  else if(A-B-C-D==7) cout<<A<<'-'<<B<<'-'<<C<<'-'<<D<<"=7"<<endl;
  else if(A+B-C-D==7) cout<<A<<'+'<<B<<'-'<<C<<'-'<<D<<"=7"<<endl;
  else if(A-B+C-D==7) cout<<A<<'-'<<B<<'+'<<C<<'-'<<D<<"=7"<<endl;
  else if(A-B-C+D==7) cout<<A<<'-'<<B<<'-'<<C<<'+'<<D<<"=7"<<endl;

}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0;i<n;i++)
#define rep2(i,a,n) for(int i=a;i<n;i++)
#define been(ix) (ix).begin(),(ix).end()
using namespace std;
typedef long long ll; 
typedef vector<int> vi;
typedef vector<long long> vl;
const ll INFL = 1e18;
const int INF = 1001001001; 
typedef pair<int,int> P;
#define foreach(ix,i) for(auto& (ix) : (i))
typedef long double ld;
const int mod =1000000007;
const double PI = acos(-1);

int main(){
	int a[5];
    rep(i,5)cin>>a[i];
    rep(i,5){
        if(a[i]==0){
            cout<<i+1<<endl;
            return 0;
        }
    }
    //cout<<ans<<endl;
}

Measured memory_bytes: 3596
#include<bits/stdc++.h>
using namespace std;
int n,m;
double ans;
int main(){
	int x=1;
	cin>>n>>m;
	for(int i=1;i<=n;i++){
		int k=max(0.0,ceil(log2(1.0*m/i)));
		ans+=1.0/((1<<k)*n);
	}
	printf("%.10lf",ans);
}

Measured memory_bytes: 3900
#include <iostream>
#include <algorithm>
#include <vector>
#include <cstdio>
#include <cmath>

using namespace std;

#define REP(i,n) for(int i = 0; i < (int)(n); i++)
typedef long long ll;
typedef pair<int, int> pint;
typedef	pair<pint, int> Data;
void inline TorF(bool tf, const string &trueMessage, const string &falseMessage) {
  cout << (tf ? trueMessage : falseMessage) << endl;
}
void inline YESNO(bool tf) { TorF(tf, "YES", "NO"); }
void inline YesNo(bool tf) { TorF(tf, "Yes", "No"); }

struct Edge {
  int src, dst;
  ll cost;
};
typedef	vector<Edge> Edges;
typedef	vector<Edges> Graph;
Graph g;

vector<bool> used;
vector<ll> dist;

void dfs(const int cur, const ll d) {
  used[cur] = true;
  dist[cur] = d;
  REP(i,g[cur].size()) {
    int to = g[cur][i].dst;
    ll dd =  g[cur][i].cost;
    if(used[to] == false) {
      dfs(to, d+dd);
    }
  }
}

int main() {
  int N; cin>>N;
  g = Graph(N);
  used = vector<bool>(N);
  dist = vector<ll>(N);
  REP(i,N-1) {
    int a, b; ll  c; cin>>a>>b>>c;
    a--; b--;
    g[a].push_back((Edge){a,b,c});
    g[b].push_back((Edge){b,a,c});
  }
  //  sort(data.begin(), data.end());                                                        
  dfs(0, 0);
  REP(i,N) {
    //    cout << dist[i] << "," ;                                                           
    cout << dist[i] % 2LL << endl;
  }
  return 0;
}



Measured memory_bytes: 9984
#include "bits/stdc++.h"

#define REP(i,num) for(int i=0;i<(num);++i)
#define ALL(c) c.begin(),c.end()
#define PRINTALL(c) for(auto& x:c){cout<<x<<' ';}cout<<endl;

using namespace std;
using ll = long long;

template<typename T=int>
T in(){T x; cin >> x; return (x);}

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

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

	int N=in();
	vector<int> S(1,1);
	int six=6,nine=9;
	for(int i=0;;i++){
		if(six<=N){
			S.push_back(six);
			six *= 6;
		}
		else break;

		if(nine<=N){
			S.push_back(nine);
			nine *= 9;
		}
	}

	int dp[100100];
	for(auto& x:dp) x = 1e9;
	dp[0] = 0;

	for(int i=0;i<=N;i++){
		for(int j=0,ej=S.size();j<ej;j++){
			if(i<=N-S[j]) chmin(dp[i+S[j]],dp[i]+1);
		}
	}
	
	cout << dp[N] << endl;
	return 0;
}

Measured memory_bytes: 640
import math,itertools,fractions,heapq,collections,bisect,sys,queue,copy

sys.setrecursionlimit(10**7)
inf=10**20
mod=10**9+7
dd=[(-1,0),(0,1),(1,0),(0,-1)]
ddn=[(-1,0),(-1,1),(0,1),(1,1),(1,0),(1,-1),(0,-1),(-1,-1)]

def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def I(): return int(sys.stdin.readline())
def F(): return float(sys.stdin.readline())
def LS(): return sys.stdin.readline().split()
def S(): return input()

# GCD -- START --
def gcd(x,y):
  while y:
    x,y=y,x%y
  return x
# GCD --- END ---

def main():
  k=I()

  ans=0
  for i in range(1,k+1):
    for j in range(1,k+1):
      for l in range(1,k+1):
        ans+=gcd(gcd(i,j),l)

  return ans

# main()
print(main())


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

char S[ 100010 ];

int main()
{
int i;
int N;
int B;
int W;
char C;

	ios::sync_with_stdio( false );
	cin.tie( 0 );

	cin >> S;

	i = 0;
	B = 0;
	W = 0;
	while( C = S[ i ] )
	{
		if( i % 2 == 0 )
		{
			if( C == '0' )
				W++;
			else
				B++;
		}
		else
		{
			if( C == '1' )
				W++;
			else
				B++;
		}

		i++;
	}

	cout << min( B, W ) << endl;

	return 0;
}


Measured memory_bytes: 384
#include <bits/stdc++.h>
#define REP(i, a, n) for (ll i = ((ll) a); i < ((ll) n); i++)
using namespace std;
typedef long long ll;

int main(void) {
  ll N, M;
  cin >> N >> M;
  vector<ll> X(N), Y(N), Z(N);
  REP(i, 0, N) cin >> X[i] >> Y[i] >> Z[i];

  ll ans = -(1LL << 60);
  REP(s, -1, 2) if (s != 0) {
    REP(t, -1, 2) if (t != 0) {
      REP(u, -1, 2) if (u != 0) {
        vector<ll> v(N);
        REP(i, 0, N) v[i] = s * X[i] + t * Y[i] + u * Z[i];
        sort(v.begin(), v.end());
        ll w = 0;
        REP(i, 0, M) w += v[N - i - 1];
        ans = max(ans, w);
      }
    }
  }
  cout << ans << endl;
}

Measured memory_bytes: 256
<?php

	fscanf(STDIN, "%s", $S);
	
  	$weather = array('Sunny', 'Cloudy', 'Rainy');
	if ($S === 'Sunny') {
      echo ('Cloudy');
    } else if ($S === 'Cloudy') {
      echo ('Rainy');
    } else {
      echo ('Sunny');
    }
?>

Measured memory_bytes: 3700
#!/usr/bin/env python3
import sys, math, itertools, heapq, collections, bisect, string
input = lambda: sys.stdin.buffer.readline().rstrip().decode('utf-8')
sys.setrecursionlimit(10**7)
inf = float('inf')
mod = 10**9+7
ans = inf ;count = 0 ;pro = 1

n=int(input())
A=list(map(int,input().split()))
A.sort()
M=max(A)
m=0
# print(A)
for i in range(n-1):
    ai=A[i]
    # print(M,ai)
    if m<min(M-ai,ai):
        m=ai
        # print(m)
print(M,m)

Measured memory_bytes: 15168
#include<cstdio>
#include<algorithm>
int main(){
	int n;
	scanf("%d",&n);
	char s[n]={};
	scanf("%s",s);
	int a[n]={};
	for(int i=0;i<n;i++){
		if(s[i]=='E')a[i]=1;
	}
	int b[n]={};
	int c[n]={};
	b[0]=a[0];
	for(int i=1;i<n;i++){
		b[i]=a[i]+b[i-1];
	}
	c[n-1]=1-a[n-1];
	for(int i=n-2;i>=0;i--){
		c[i]+=(1-a[i])+c[i+1];
	}
	int ans=std::max(c[1],b[n-2]);
	for(int i=1;i<n-1;i++){
		ans=std::max(ans,b[i-1]+c[i+1]);
	}
	printf("%d\n",n-1-ans);
	return 0;
}

Measured memory_bytes: 4096
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(int)(n);i++)
using namespace std;
int main(){
    string s;
    cin>>s;
        if(s=="RRR") cout<<'3';
        if(s=="RRS"||s=="SRR") cout<<'2';
        if(s=="SSS") cout<<'0';
        if(s=="RSS"||s=="SRS"||s=="RSR"||s=="SSR") cout<<'1';
    
}

Measured memory_bytes: 3616
# ABC157c


def main():
    import sys
    input = sys.stdin.readline
    sys.setrecursionlimit(10**6)
    # 再帰関数を使わない限りPypyで出すこと

    n, m = map(int, input().split())
    con = [list(map(int, input().split())) for _ in range(m)]
    s = 10 ** (n - 1)
    if s == 1:
        s -= 1

    for i in range(s, 10 ** (n + 1)):
        falg = False
        num = list(str(i))
        for s, c in con:
            if num[s - 1] != str(c):
                falg = True
                break
        if falg:
            continue
        print(*num, sep='')
        exit(0)
    print(-1)


if __name__ == '__main__':
    main()


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

using namespace std;

using ll=long long;
using vi=vector<int>;
using vvi=vector<vi>;
using pii=pair<int,int>;
using vll=vector<ll>;
using vvll=vector<vll>;


int main(void)
{
	char s[100000+2];
	while(scanf("%100000[01]\n", s)==1)
	{
		int l=0;
		int m=0;

		for(l=0;s[l];l++)
		{
			if(s[l]=='0'+(l%2)) m++;
		}

		int ans=min(m, l-m);
		printf("%d\n", ans);
	}
	return 0;
}


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

using namespace std;

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

	long long int a,b;
	int k;

	cin >> a >> b >> k;

	for(int i=0;i<k;i++)
	{
		if(i%2==0)
		{
			if(a%2==1)
			{
				a-=1;
			}
			b += (a/2);
			a/=2;
		}
		else
		{
			if(b%2==1)
			{
				b-=1;
			}
			a += (b/2);
			b/=2;
		}
	}

	cout << a << ' ' << b << '\n';

	return 0;
}

Measured memory_bytes: 3640
#include <bits/stdc++.h>
#include <boost/multiprecision/cpp_int.hpp>

using boost::multiprecision::cpp_int;
using namespace std;

#if __has_include("print.hpp")
  #include "print.hpp"
#endif

#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define ALL(x) (x).begin(), (x).end()
#define RALL(x) (x).rbegin(), (x).rend()
#define MOD 1000000007

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


int main(){
  ios::sync_with_stdio(false);
  cin.tie(0);
  int k, x;
  cin >> k >> x;
  if(500 * k >= x)cout << "Yes" << endl;
  else cout << "No" << endl;
}


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

#define MAX_DIGIT 1000000+1
int dp[MAX_DIGIT+5][2];

int min(int a, int b){
	return (a < b) ? a : b;
}

int main(){
	char s[MAX_DIGIT+5];
	int len;
	int i, x;

	scanf("%s", s);
	len = strlen(s);

	dp[0][0] = 0;
	dp[0][1] = 1;
	for(i=0; i<len; i++){
		x = s[i] - '0';
		dp[i+1][0] = min(dp[i][0]+x, dp[i][1]+10-x);
		dp[i+1][1] = min(dp[i][0]+x+1, dp[i][1]+9-x);
	}

	printf("%d", dp[i][0]);

	return 0;
}


Measured memory_bytes: 8960
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using static System.Console;
using static System.Math;

namespace AtTest.ABC_131
{
    class D
    {
        static void Main(string[] args)
        {
            Method(args);
        }

        static void Method(string[] args)
        {
            int n = ReadInt();
            int[][] abs = new int[n][];
            for(int i = 0; i < n; i++)
            {
                abs[i] = ReadInts();
            }
            abs = abs.OrderBy(a => a[1] - a[0]).OrderBy(a=>a[1]).ToArray();

            int now = 0;
            for(int i = 0; i < n; i++)
            {
                if (now > abs[i][1] - abs[i][0])
                {
                    WriteLine("No");
                    return;
                }

                now += abs[i][0];
            }

            WriteLine("Yes");
        }

        private static string Read() { return ReadLine(); }
        private static char[] ReadChars() { return Array.ConvertAll(Read().Split(), a => a[0]); }
        private static int ReadInt() { return int.Parse(Read()); }
        private static long ReadLong() { return long.Parse(Read()); }
        private static double ReadDouble() { return double.Parse(Read()); }
        private static int[] ReadInts() { return Array.ConvertAll(Read().Split(), int.Parse); }
        private static long[] ReadLongs() { return Array.ConvertAll(Read().Split(), long.Parse); }
        private static double[] ReadDoubles() { return Array.ConvertAll(Read().Split(), double.Parse); }
    }
}


Measured memory_bytes: 37304
"use strict";
const input = require("fs").readFileSync("/dev/stdin", "utf8").split("\n");
let ws = new Set();
let prev = null;
console.log((() => {
	for (const w of input.slice(1,parseInt(input[0]) + 1)) {
		if (prev && prev != w[0]) {
			return "No";
		}
		if (ws.has(w)) {
			return "No";
		}
		ws.add(w);
		prev = w.substr(-1);
	}
	return "Yes";
})());


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

const int N = 500010;
const int mod = 998244353;

typedef long long LL;

inline int Pow(int x, int y) {
    int res = 1;
    for (; y; y >>= 1, x = (LL)x * x % mod) if (y & 1) res = (LL)res * x % mod;
    return res;
}

int frac[N], inv[N];

inline int C(int n, int r) {
    return (LL)frac[n] * inv[r] % mod * inv[n - r] % mod;
}

int main() {
    int n, m; scanf("%d%d", &n, &m);
    if (n > m) swap(n, m);
    frac[0] = inv[0] = 1;
    for (int i = 1; i <= m; i++) frac[i] = (LL)frac[i - 1] * i % mod, inv[i] = Pow(frac[i], mod - 2);
    int res = 0;
    for (int i = 0; i <= n; i++) {
        int w = (LL)C(n, i) * C(m, i) % mod * frac[i] % mod * Pow(m + 1, n - i) % mod * Pow(n + 1, m - i) % mod;
        if (i & 1) res = (res + mod - w) % mod;
        else res = (res + w) % mod;
    }
    printf("%d\n", res);
}

Measured memory_bytes: 4096
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.Scanner;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        Scanner in = new Scanner(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        CRemainderMinimization2019 solver = new CRemainderMinimization2019();
        solver.solve(1, in, out);
        out.close();
    }

    static class CRemainderMinimization2019 {
        public void solve(int testNumber, Scanner in, PrintWriter out) {
            long l = in.nextInt();
            long r = in.nextInt();
            long res = Long.MAX_VALUE;
            for (long i = l; i <= r && i <= l + 2019; i++) {
                for (long j = i + 1; j <= r && j <= i + 2020; j++) {
                    res = Math.min(res, (i * j) % 2019);
                }
            }
            out.println(res);
        }

    }
}



Measured memory_bytes: 21844
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <string>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <iomanip>
#include <utility>
#include <tuple>
#include <functional>
#include <bitset>
#include <cassert>
#include <time.h>
#define int long long
#define endl '\n'
#define INF 1000000000000000000
#define EPS 1e-10
#define all(a) a.begin(),a.end()
#define rep(i, n) for (int i = 0; i < (n); i++)
#define fi first
#define se second
#define pb push_back
#define double long double
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
typedef pair<ll, P> PP;
template<class T, class S> bool chmax(T &a, const S &b) { if (a < b) { a = b; return 1; } return 0; }
template<class T, class S> bool chmin(T &a, const S &b) { if (a > b) { a = b; return 1; } return 0; }
ll gcd(ll n, ll m) { return (m ? gcd(m, n%m) : n); }
ll lcm(ll n, ll m) { return n / gcd(n, m)*m; }

ll mod = 1000000007;
int dp[100010][2];
vector<vector<int>> tree(100010, vector<int>());

int solve(int n, int col, int p) {
	if (dp[n][col]) {
		return dp[n][col];
	}
	int res = 1;
	for (int i : tree[n]) {
		if (i == p) continue;
		if (col == 0) {
			res *= (solve(i, 0, n) + solve(i, 1, n)); res %= mod;
		}
		else {
			res *= solve(i, 0, n); res %= mod;
		}
	}
	return dp[n][col] = res;
}

signed main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	cout << fixed << setprecision(20);
	//modcalc();

	int n;
	cin >> n;
	rep(i, n - 1) {
		int a, b;
		cin >> a >> b;
		a--; b--;
		tree[a].pb(b);
		tree[b].pb(a);
	}
	cout << (solve(0, 0, -1) + solve(0, 1, -1)) % mod << endl;
}


Measured memory_bytes: 14208
package main

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

func getScanner(fp *os.File) *bufio.Scanner {
	scanner := bufio.NewScanner(fp)
	scanner.Split(bufio.ScanWords)
	scanner.Buffer(make([]byte, 500001), 500000)
	return scanner
}

func getNextString(scanner *bufio.Scanner) string {
	scanner.Scan()
	return scanner.Text()
}

func getNextInt(scanner *bufio.Scanner) int {
	i, _ := strconv.Atoi(getNextString(scanner))
	return i
}

func getNextInt64(scanner *bufio.Scanner) int64 {
	i, _ := strconv.ParseInt(getNextString(scanner), 10, 64)
	return i
}

func main() {
	fp := os.Stdin
	if len(os.Args) > 1 {
		fp, _ = os.Open(os.Args[1])
	}

	scanner := getScanner(fp)
	writer := bufio.NewWriter(os.Stdout)

	n := getNextInt(scanner)

	aa := make([]int, n)
	bb := make([]int, n)
	ma := make([]int, n)
	mb := make([]int, n)
	for i := 0; i < n; i++ {
		aa[i] = getNextInt(scanner)
	}
	for i := 0; i < n; i++ {
		bb[i] = getNextInt(scanner)
	}

	ans := 0

	for i := 0; i < 30; i++ {
		mapmod(i, n, aa, ma)
		mapmod(i, n, bb, mb)

		sort.Ints(mb)
		t := 1 << uint(i)

		c := 0
		for ii := 0; ii < n; ii++ {
			c += n - bsearch(ma[ii], n, t*3, mb) + bsearch(ma[ii], n, t*2, mb) - bsearch(ma[ii], n, t, mb)
		}
		c %= 2
		ans |= c << uint(i)
	}

	fmt.Fprintln(writer, ans)
	writer.Flush()
}

func mapmod(k, n int, aa, mm []int) {
	for i := 0; i < n; i++ {
		mm[i] = aa[i] % (2 << uint(k))
	}
}

func bsearch(a, n, t int, mb []int) int {
	l := 0
	r := n
	for l < r {
		m := (l + r) >> 1
		if a+mb[m] >= t {
			r = m
			continue
		}
		l = m + 1
	}
	return l
}


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

#define pb push_back
#define ff first
#define ss second

const long long MAXN = 1e5 + 21, inf = 1e18 + 21, LG = 20;

int n;
int a[MAXN];
int nxt, tmp;
int ans;

int main() {
    ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0);
    cin >> n;
    for (int i = 0; i < n; i++)
	cin >> a[i];
    
    for (int i = 0; i < n; i++) {
	nxt = tmp = 0;
	for (int j = i + 1; j < n; j++) {
	    if (a[j] >= a[j - 1])
		nxt++;
	    else
		break;
	}
	for (int j = i + 1; j < n; j++) {
	    if (a[j] <= a[j - 1])
		tmp++;
	    else
		break;
	}

	i += max(tmp, nxt);
	ans++;
    }

    cout << ans << '\n';
    return 0;
}


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

#define all(x) (x).begin(), (x).end()
#define pb push_back
#define mp make_pair
#define FILE "parade"

using namespace std;

typedef long long ll;
typedef unsigned long long ull;

const int INF = numeric_limits<int>::max();
const ll LLINF = numeric_limits<ll>::max();
const ull ULLINF = numeric_limits<ull>::max();
const double PI = acos(-1.0);

long long h, w;
vector<pair<int, int>> f;
set<pair<int, int>> used;
long long ans[10];
int a[100010], b[100010];

int main()
{
//    freopen(FILE".in", "r", stdin);
//    freopen(FILE".out", "w", stdout);
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    int n;
    scanf("%d%d%d", &h, &w, &n);
    for(int i = 0; i < n; i++)
    {
        scanf("%d%d", &a[i], &b[i]);
        f.pb(mp(a[i], b[i]));
    }
    sort(all(f));
    for(int i = 0; i < n; i++)
    {
        for(int j = max(1, a[i] - 2); j <= a[i]; j++)
        {
            for(int k = max(1, b[i] - 2); k <= b[i]; k++)
            {
                if(j + 2 <= h && k + 2 <= w)
                {
                    if(used.find(mp(j, k)) != used.end())
                        continue;
                    int cur = 0;
                    for(int l = 0; l < 3; l++)
                        for(int m = 0; m < 3; m++)
                            cur += binary_search(all(f), mp(l + j, m + k));
                    ans[cur]++;
                    used.insert(mp(j, k));
                }
            }
        }
    }
    long long tot = max(0LL, h - 2) * max(0LL, w - 2);
    long long sum = 0;
    for(int i = 1; i <= 9; i++)
        sum += ans[i];
    ans[0] = tot - sum;
    for(int i = 0; i <= 9; i++)
        printf("%lld\n", ans[i]);
    return 0;
}


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

int main()
{
    ll N;
    cin >> N;
    vector<bool> A(1000000010, false);
    for (int i = 0; i < N; ++i)
    {
        ll temp;
        cin >> temp;
        A[temp] = !A[temp];
    }
    ll ans = 0;
    for (auto t : A)
    {
        if (t)
        {
            ++ans;
        }
    }
    cout << ans << endl;
}

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

int main() {
	ll a;
	string x;
	cin >> a >> x;
	int c, d, e;
	c = x.at(0) - '0';
	d = x.at(2) - '0';
	e = x.at(3) - '0';
	ll ans = a * c;
	ll f = a * d * 10 + a * e;
	ans += f / 100;
	cout << ans << endl;
}


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

int main(){
  int n,d; cin >> n >> d;
  vector<vector<int>> x(n,vector<int>(d));
  for(int i=0;i<n;i++){
    for(int j=0;j<d;j++){
      cin >> x[i][j];
    }
  }
  double sum=0;
  int ans=0;
  double dis;
  for(int i=0;i<n-1;i++){
    for(int j=i+1;j<n;j++){
      rep(p,d){
        sum+=pow(x[i][p]-x[j][p],2);
      }
      dis=sqrt(sum);
      if(dis==(int)dis) ans++;
      sum=0;
    }
  }
  cout << ans << endl;
}

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

int main(void) {
	// input
	int n;
	std::cin >> n;
	std::vector<int> a1(n), a2(n);
	for(int i = 0; i < n; ++i) std::cin >> a1[i];
	for(int i = 0; i < n; ++i) std::cin >> a2[i];

	// sum
	std::vector<int> l(n), r(n);
	l[0] = a1[0];
	r[n-1] = a2[n-1];
	for(int i = 1; i < n; ++i) {
		l[i] = a1[i] + l[i-1];
		r[n-i-1] = a2[n-i-1] + r[n-i];
	}

	// ans
	int n_candy_max = 0;
	for(int i = 0; i < n; ++i) {
		int n_candy = l[i] + r[i];
		n_candy_max = (n_candy > n_candy_max ? n_candy : n_candy_max);
	}

	std::cout << n_candy_max << std::endl;

	return 0;
}


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

#define fast                     \
    ios::sync_with_stdio(false); \
    cin.tie(NULL);               \
    cout.tie(NULL)
#define int long long
#define endl '\n'

using namespace std;

const int N = 2e5 + 77;

int32_t main()
{
    fast;
    int a , b ;cin >> a >> b;
    int x, y ; cin >>x >> y ;
    string ans = "";
    string p1="" , p2="" , p3="",p4="";
    p1 += string(abs(x-a),'R');
    p1 += string(abs(b-y),'U');
    for(char i : p1){
        if(i=='R') p2 += 'L';
        else if(i=='U') p2 += 'D';
    }
    p3 += "DR";
    p3 += p1;
    p3 += "UL";

    p4 += "UL";
    p4 += p2;
    p4 += "DR";
    
    ans += p1 ;
    ans += p2;
    ans += p3;
    ans += p4;
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 3592
import java.util.Scanner;
import java.util.Map;
import java.util.HashMap;

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


    long s[] = new long[n + 1];
    Map<Long, Long> map = new HashMap<>();
    map.put(s[0], 1L);
    for (int i = 1; i <= n; i++) {
      s[i] = s[i - 1] + a[i - 1];
      if (map.get(s[i]) == null) {
        map.put(s[i], 1L);
      } else {
        map.put(s[i], map.get(s[i]) + 1);
      }
    }

    long cnt = 0;
    for (long key : map.keySet()) {
      long val = map.get(key);
      if (val > 1) {
        cnt += val * (val - 1) / 2;
      }
    }

    System.out.println(cnt);
  }
}


Measured memory_bytes: 93108
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define ull unsigned long long
#define ld long double
#define mod 1000000007LL
#define eps 1e-13
#define PI 3.141592653589793238L
#define INF 1000000011
#define INFLL 10000000011LL
#define vi vector<int>
#define vll vector<long long>
#define pii pair<int, int>
#define pll pair<long long, long long>
#define pil pair<int, long long>
#define pli pair<long long, int>
#define mp make_pair
#define F first
#define S second
#define pb push_back
#define fo(i,a,n) for(i = (a); i < (n); i++)
#define gtl(x) getline(cin, (x))
#define flsh fflush(stdout)
#define sws ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0)
#define gcd __gcd
#define all(a) (a).begin(), (a).end()
#define sz(a) (int)((a).size())
#define io_file freopen("D:/Coding Problems/Contest/input_file.in", "r", stdin); freopen("D:/Coding Problems/Contest/output_file.out", "w", stdout)

ll modx(ll Base, ll exponent)
{
	ll ans = 1;
	if(Base == 1)
		return Base;
	while(exponent)
	{
		if(exponent & 1)
			ans = (ans * Base)%mod;
		Base = (Base * Base)%mod;
		exponent = exponent >> 1;
	}
	return ans;
}

ll inmodx(ll num)
{
	return (modx(num, mod-2LL));
}

bool cmp(pair < vi, int > a, pair < vi, int > b)//true for a before b
{
	if(a.F.empty())
		return 1;
	if(b.F.empty())
		return 0;
	int i;
	fo(i,0,min(sz(a.F),sz(b.F)))
	{
		if(a.F[i] < b.F[i])
			return 1;
		else if(a.F[i] > b.F[i])
			return 0;
	}
	return (sz(a.F) <= sz(b.F));
}

const int N = (1e5) + 9;
const int M = (N<<2) + 9;
const int LOGN = ((int)log2(N)) + 3;
const int LOGM = ((int)log2(M)) + 3;
const int BUCK = 900;
const int SQRT = BUCK+9;

ll a[4];

void solve()
{
	int i, j;
	ll ans = INFLL;
	fo(i,0,3)
		cin >> a[i];
	fo(i,0,3)
		fo(j,i+1,3)
			ans = min(ans, a[i]+a[j]);
	cout << ans << '\n';
	return;
}

int main()
{
	sws;
	clock_t clk;
	clk = clock();
	// io_file;
	// srand (time(NULL));

	//Code here
	int t = 1, cs;
	cout << fixed << setprecision(15);
	// cin >> t;
	fo(cs,1,t+1)
	{
		// cout << "Case #" << cs << ": ";
		solve();
	}
	// Code ends here

	clk = clock() - clk;
	cerr << fixed << setprecision(6) << "Time: " << ((double)clk)/CLOCKS_PER_SEC << "\n";
	return 0;
}

Measured memory_bytes: 256
import fractions
from functools import reduce
def gcd_list(numbers):
    return reduce(fractions.gcd, numbers)

n,k = map(int, input().split())
a = list(map(int, input().split()))


b = gcd_list(a)

if k%b==0 and k<=max(a):
    print('POSSIBLE')
else:
    print('IMPOSSIBLE')


Measured memory_bytes: 88172
//#include <bits/stdc++.h>
#include <iostream>
#include <fstream>
#include <vector>
#include <string>
#include <cmath>
#include <algorithm>
#include <map>
#include <iomanip>
#include <stdlib.h>
#include <queue>
#include <deque>
#include <set>
#include <stack>
#include <time.h>

using namespace std;

typedef long long ll;
typedef long double ld;
typedef pair<int, int> Pii;
typedef pair<int, ll> Pil;
typedef pair<ll, ll> Pll;
typedef pair<ll, int> Pli;

const ll nmax = 1e9 + 7;
const ll Mod = 998244353;
const double PI = 2 * asin(1);

int N, K;
int A[100];
bool DP[100001], visited[100001];

bool Solve(int turn){
  if (turn == 0) return DP[0] = false;

  if (visited[turn] == true) return DP[turn];

  visited[turn] = true;
  bool now = false;
  for (int i = 0; i < N; i++){
    if (turn - A[i] < 0) continue;
    if (Solve(turn - A[i]) == false) now = true;
  }
  return DP[turn] = now;
}


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

  if (Solve(K) == true) cout << "First" << endl;
  else cout << "Second" << endl;

  return 0;
}


Measured memory_bytes: 6656
#include<iostream>
#include<string>

using namespace std;

int main() {
  string s;
  cin >> s;
  int groups = 1;
  char prev = 'E';
  for(int i = 0; i < s.length(); i++) {
    if(prev != 'E' && prev !=s[i]) {
      groups++;
    }
    prev = s[i];
  }
  groups--;
  cout << groups;

  return 0;
}


Measured memory_bytes: 512
package main

import (
	"bufio"
	_ "container/heap"
	"fmt"
	"os"
	"sort"
	"strconv"
)

// I/O
type Scanner struct {
	sc *bufio.Scanner
}

func NewScanner() *Scanner {
	sc := bufio.NewScanner(os.Stdin)
	sc.Split(bufio.ScanWords)
	sc.Buffer(make([]byte, 1024), int(1e+9))
	return &Scanner{sc}
}

func (s *Scanner) nextStr() string {
	s.sc.Scan()
	return s.sc.Text()
}

func (s *Scanner) nextInt() int {
	i, e := strconv.Atoi(s.nextStr())
	if e != nil {
		panic(e)
	}
	return i
}

func (s *Scanner) nextFloat() float64 {
	f, e := strconv.ParseFloat(s.nextStr(), 64)
	if e != nil {
		panic(e)
	}
	return f
}

func (s *Scanner) nextRuneSlice() []rune {
	return []rune(s.nextStr())
}

func (s *Scanner) nextIntSlice(n int) []int {
	res := make([]int, n)
	for i := 0; i < n; i++ {
		res[i] = s.nextInt()
	}
	return res
}

func (s *Scanner) nextFloatSlice(n int) []float64 {
	res := make([]float64, n)
	for i := 0; i < n; i++ {
		res[i] = s.nextFloat()
	}
	return res
}

// Arithmetic
func max(nums ...int) int {
	m := nums[0]
	for _, i := range nums {
		if m < i {
			m = i
		}
	}
	return m
}

func min(nums ...int) int {
	m := nums[0]
	for _, i := range nums {
		if m > i {
			m = i
		}
	}
	return m
}

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

func pow(x, y int) int {
	res := 1
	for i := 0; i < y; i++ {
		res *= x
	}
	return res
}

func ceil(a, b int) int {
	if a%b == 0 {
		return a / b
	} else {
		return a/b + 1
	}
}

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

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

// Sort
type RuneSlice []rune

func (a RuneSlice) Len() int           { return len(a) }
func (a RuneSlice) Less(i, j int) bool { return a[i] < a[j] }
func (a RuneSlice) Swap(i, j int)      { a[i], a[j] = a[j], a[i] }

type Num struct {
	bit, use, nuse, diff int
}

type ByDiff []Num

func (a ByDiff) Len() int           { return len(a) }
func (a ByDiff) Less(i, j int) bool { return a[i].diff > a[j].diff }
func (a ByDiff) Swap(i, j int)      { a[i], a[j] = a[j], a[i] }

// Main
const MOD = int(1e+9) + 7
const INF = 1 << 60

func main() {
	sc := NewScanner()
	wtr := bufio.NewWriter(os.Stdout)
	defer wtr.Flush()
	N, K := sc.nextInt(), sc.nextInt()
	A := sc.nextIntSlice(N)
	ans := 0
	var nums []Num
	for i := 40; i >= 0; i-- {
		bit := 1 << uint(i)
		count := 0
		for j := 0; j < N; j++ {
			if A[j]&bit > 0 {
				count++
			}
		}
		// ビットが立っている数の方が多い
		if ceil(N, 2) <= count {
			ans += bit * count
		} else {
			use := bit * (N - count)
			nuse := bit * count
			nums = append(nums, Num{bit, use, nuse, use - nuse})
		}
	}
	sort.Sort(ByDiff(nums))
	now := 0
	for _, num := range nums {
		if now+num.bit <= K {
			now += num.bit
			ans += num.use
		} else {
			ans += num.nuse
		}
	}

	fmt.Fprintln(wtr, ans)
}


Measured memory_bytes: 3072
// edpc_j
#include <bits/stdc++.h>
#ifdef LOCAL
#include "../cxx-prettyprint/prettyprint.hpp"
#endif
using namespace std;

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

#define REP(i, n) for (int (i) = 0 ; (i) < (int)(n) ; ++(i))
#define REPN(i, m, n) for (int (i) = m ; (i) < (int)(n) ; ++(i))
#define REP_REV(i, n) for (int (i) = (int)(n) - 1 ; (i) >= 0 ; --(i))
#define REPN_REV(i, m, n) for (int (i) = (int)(n) - 1 ; (i) >= m ; --(i))
#define ALL(x) x.begin(), x.end()

#define INF ((1 << 29)-1)
#define MOD (1000000007)

#define print2D(h, w, arr) REP(i, h) { REP(j, w) cout << arr[i][j] << " "; cout << endl; }
#define print_line(vec, n) {for(int i=0;i<(n-1);i++) cout << (vec)[i] << " "; cout << (vec)[(n)-1] << endl;}
template<class T> void print(const T& x){cout << x << endl;}
template<class T, class... A> void print(const T& first, const A&... rest) { cout << first << " "; print(rest...); }
struct PreMain {PreMain(){cin.tie(0);ios::sync_with_stdio(false);cout<<fixed<<setprecision(20);}} premain;


int N;
vector<int> A;
double memo[301][301][301];

double dfs(int a, int b, int c, int d){

    if (a < 0 || b < 0 || c < 0) return 0;
    if (d == N) return 0;

    if (memo[a][b][c] != -1) return memo[a][b][c];

    double e3 = dfs(a-1, b+1, c, d) * a / N;
    double e2 = dfs(a, b-1, c+1, d) * b / N;
    double e1 = dfs(a, b, c-1, d+1) * c / N;

    double e = (1 + (e1 + e2 + e3)) / (1 - double(d) / N);

    return memo[a][b][c] = e;
}


int main() {
#ifdef LOCAL
    ifstream in("../arg.txt"); cin.rdbuf(in.rdbuf());
#endif

    cin >> N;
    map<int, int> x;
    x[0]=x[1]=x[2]=x[3]=0;
    REP(i, N) {
        int a; cin >> a;
        x[a]++;
    }

    fill(memo[0][0], memo[0][0]+301*301*301, -1);
    double ans = dfs(x[3], x[2], x[1], x[0]);
    print(ans);

    return 0;
}


Measured memory_bytes: 213376
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < n; i++)
#define repr(i, n) for (int i = n - 1; i >= 0; i--)
#define ALL(x) x.begin(),x.end()
using ll = long long;
using pii = pair<int, int>;
using vi = vector<int>;

const ll INF = 1e18;
const int mod = 1e9+7;
const int MAX = 1e6;

bool is_prime(int x) { // 素数判定
    if (x < 2) return false;
    for (int i = 2; i * i <= x; i++) {
        if (x % i == 0) return false;
    }
    return true;
}

int seive[MAX+1]; // 整数の素因数で最小のもの

void erat() { // エラトステネスのふるい
    rep(i, MAX+1) seive[i] = i; // 初期化
    for (int i = 2; i <= MAX; i++) {
        if (seive[i] == i) { // seive[i]=iならばiは素数
            for (int j = i + i; j <= MAX; j += i) {
                seive[j] = i;
            }
        }
    }
}

void prime_fact(int x, set<int> &fact) { // 高速素因数分解
    while (x > 1 && x % seive[x] == 0) {
        fact.insert(seive[x]); // 素因数
        x /= seive[x];
    }
}


void prime_fact(int x, vector<int> &fact) { // 素因数分解
    for (int i = 2; i * i <= x; i++) {
        while (x % i == 0) {
            fact.push_back(i); // 素因数
            x /= i;
        }
    }
    if (x != 1) {
        fact.push_back(x);
    }
}

int main() {
    int n;
    cin >> n;
    map<int, int> p;
    for (int i = 2; i <= n; i++) {
        int x = i;
        for (int j = 2; j * j <= x; j++) {
            while (x % j == 0) {
                p[j]++; // jはxの素因数
                x /= j;
            }
        }
        if (x != 1) p[x]++; // xは1か素数
    }
    ll ans = 1;
    for (int i = 2; i <= n; i++) {
        ans *= p[i] + 1;
        ans %= mod;
    }
    cout << ans << "\n";
}

Measured memory_bytes: 3624
s = input()
temp = []
maximum = 0
count =0
for i in range(len(s)):
    if s[i] == 'A' or s[i] == 'C' or s[i] == 'G' or s[i] == 'T':
            count +=1
            maximum = max(maximum,count)
    else:
        count = 0

print(maximum)

Measured memory_bytes: 38384
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
#define MOD 998244353
#define MAX 100
#define INF 800000000

vector<vector<bool>> tree(26);

bool solve(int a,int b,int i,int left,int right,int s){
  if(right<=a||b<=left){
    return false;
  }
  if(a<=left&&right<=b){
    return tree.at(s).at(i);
  }
  return solve(a,b,2*i+1,left,(left+right)/2,s)||solve(a,b,2*i+2,(left+right)/2,right,s);
}

int solve2(int a,int b,int n){
  int ans=0;
  for(int i=0;i<26;i++){
    if(solve(a,b,0,0,n,i)){
      ans++;
    }
  }
  return ans;
}

int main(){
  int N,Q;
  string S;
  cin>>N>>S>>Q;
  int n=1;
  while(n<N){
    n*=2;
  }
  for(int i=0;i<26;i++){
    tree.at(i).resize(2*n-1,false);
  }

  for(int i=0;i<N;i++){
    tree.at(S.at(i)-'a').at(i+n-1)=true;
  }
  for(int i=0;i<26;i++){
    for(int j=n-2;j>=0;j--){
      tree.at(i).at(j)=tree.at(i).at(2*j+1)||tree.at(i).at(2*j+2);
    }
  }
  vector<int> a;
  for(int k=0;k<Q;k++){
    int q;cin>>q;
    if(q==1){
      int i,x,y,j;char c,d;
      cin>>i>>c;
      i--;
      d=S.at(i);
      S.at(i)=c;
      if(d==c){
        continue;
      }
      x=d-'a';y=c-'a';
      j=i+n-1;
      tree.at(x).at(j)=false;
      tree.at(y).at(j)=true;
      while(j>0){
        j=(j-1)/2;
        tree.at(x).at(j)=tree.at(x).at(2*j+1)||tree.at(x).at(2*j+2);
        tree.at(y).at(j)=tree.at(y).at(2*j+1)||tree.at(y).at(2*j+2);
      }
    }else{
      int l,r;
      cin>>l>>r;
      l--,r--;
      a.push_back(solve2(l,r+1,n));
    }
  }
  for(int i=0;i<a.size();i++){
    cout<<a.at(i)<<endl;;
  }
}


Measured memory_bytes: 6148
#include <stdio.h>


int N,M;
int visited[9];
int graph[9][9]; 
int cnt = 0;
int end = 0;

void init(){
  for(int i = 0;i <= 8;i++){
    visited[i] = 0;
  }
}

void dfs(int v){
  int num = 0;
  for(int i = 1;i <= N;i++){
    if(visited[i]) num++;
  }
  if(num == N){
    cnt++;
    return;
  }

  for(int i = 1;i <= N;i++){
    if(visited[i]) continue;
    if(graph[v][i] == 0) continue;
    visited[i] = 1;
    dfs(i);
    visited[i] = 0;
  }
}

int main(void){
  scanf("%d%d",&N,&M);

  int a,b;
  for(int i = 0;i <= N;i++){
    for(int j = 0;j <= N;j++){
      graph[i][j] = 0;
    }
  }
  for(int i = 0;i < M;i++){
    scanf("%d%d",&a,&b);
    graph[a][b] = graph[b][a] = 1;
  }

  init();
  visited[1] = 1;
  dfs(1);

  printf("%d\n",cnt);

  return 0;
}

Measured memory_bytes: 128
#include<bits/stdc++.h>
using namespace std;
int main(){
    string st;
    cin>>st;
    vector<int> d(26,0);
    for(int i=0;i<st.length();i++){
        d[st[i]-'a']++;
    }
    for(int i=0;i<d.size();i++){
        if(d[i]%2!=0){
            cout<<"No"<<endl;
            return 0;
        }
    }
    cout<<"Yes"<<endl;
    return 0;
}

Measured memory_bytes: 256
#include <cctype>
#include <cerrno>
#include <cfloat>
#include <ciso646>
#include <climits>
#include <clocale>
#include <cmath>
#include <csetjmp>
#include <csignal>
#include <cstdarg>
#include <cstddef>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>

#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>
#include <regex>
#define REP(i,n) for(int i = 0; i < n; i++)
#define FOR(i,j,n) for(int i = j; i < n; i++)
#define RFOR(i,j,n) for(int i = j-1; i >= n; i--)
#define PREC(n) fixed << setprecision(n)
#define print_array(v) REP(__k, v.size()) { cout << v[__k]; if(__k != v.size()-1) cout << " "; else cout << endl; }
#define YesorNo(a) printf(a?"Yes\n":"No\n")
#define _LIBCPP_DEBUG 0
using namespace std;
int64_t MOD = 1000000007;

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  string s;
  cin >> s;
  bool f = false;
  if(s == "abc") f = true;
  if(s == "bca") f = true;
  if(s == "cab") f = true;
  if(s == "acb") f = true;
  if(s == "bac") f = true;
  if(s == "cba") f = true;
  YesorNo(f);
  return 0;
}
//templete by private_yusuke

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
int main(){
	int n;
	cin>>n;
	string s;
	cin>>s;
	
	int ans=0;
	for(int i=1;i<n;i++){
		int cnt=0;
		
		for(char c='a';c<='z';c++){
			bool left=false,right=false;
			
			for(int j=0;j<i;j++)
				if(s[j]==c)
					left=true;
			
			for(int j=i;j<n;j++)
				if(s[j]==c)
					right=true;
			
			if(left&&right)
				cnt++;
		}
		
		if(ans<cnt)
			ans=cnt;
	}
	
	cout<<ans<<endl;
}

Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<string>
#include<cmath>
#include<map>
#include<stack>
#include<vector>
#include<queue>
#include<set>
#include<algorithm>
#define INF 0x3f3f3f3f
#define mod 1000000009
#define e  2.718281828459045
#define eps 1.0e18
#define PI acos(-1)
#define lowbit(x) (x&(-x))
#define memset(x,y) memset(x,y,sizeof(x))
#define lson i << 1,l,m
#define rson i << 1 | 1,m + 1,r
#define ll long long
using namespace std;
pair <float,float> pt[1001],t;
map <pair<float,float>,int> mp;
struct Piont{
	float x,y;
}p[1001];
int main(){
	ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
	//freopen("text1.in","r",stdin);
	//freopen("text1.out","w",stdout);
	string s;
	cin>>s;
	if(s[2]==s[3]&&s[4]==s[5]) cout<<"Yes";
	else cout<<"No";
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define rep(i,a,b) for(int i=a;i<b;i++)
#define rrep(i,a,b) for(int i=a;i>=b;i--)
#define fore(i,a) for(auto &i:a)
#define all(x) (x).begin(),(x).end()
//#pragma GCC optimize ("-O3")
using namespace std; void _main(); int main() { cin.tie(0); ios::sync_with_stdio(false); _main(); }
typedef long long ll; const int inf = INT_MAX / 2; const ll infl = 1LL << 60;
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; }
//---------------------------------------------------------------------------------------------------
/*---------------------------------------------------------------------------------------------------
　　　　　　　　　　　 ∧＿∧  
　　　　　 ∧＿∧ 　（´<_｀ ）　 Welcome to My Coding Space!
　　　　 （ ´_ゝ`）　/　 ⌒i     
　　　　／　　　＼　 　  |　|     
　　　 /　　 /￣￣￣￣/　　|  
　 ＿_(__ﾆつ/　    ＿/ .| .|＿＿＿＿  
　 　　　＼/＿＿＿＿/　（u　⊃  
---------------------------------------------------------------------------------------------------*/






double T, X;
//---------------------------------------------------------------------------------------------------
void _main() {
    cin >> T >> X;
    double ans = T / X;
    printf("%.10f\n", ans);
}

Measured memory_bytes: 256