akhauriyash/Code-Regression huggingface dataset:
# 桁DP 最適化もうむり

MOD = 10 ** 9 + 7
s = gets.chomp.split("")
question = s.map { |c| c == "?" }
length = s.length
# dp[上から i 桁まで][13 で割ったあまり]の出現回数
# 桁の自由度(smaller)は本問では不要
dp = (length + 1).times.map { Array.new(13, 0) }
# 初期化
# dp[0 桁目まで][13 で割ったあまりが 0]の出現回数は 1
dp[0][0] = 1
# （右から見た）桁数 % 6
mod_memo = [4, 1, 10, 9, 12, 3]
all_nums = (0..9).to_a

# 桁数分ループする（i は遷移元の桁）
length.times do |i|
  # 13 で割ったあまりの増加分を求める
  addition = mod_memo[(length - i) % 6]
  # 桁の数字が "?" の場合は 10 回ループ、それ以外の場合はその数字のみ
  nums = question[i] ? all_nums : [s[i].to_i]
  dp_current = dp[i]
  # 最適化のため、事前に 1 行分だけ浅いコピーをする
  # dp_next と dp[i + 1] の object_id は同じ
  dp_next = dp[i + 1]
  # 13 で割ったあまりごとに確認する
  13.times do |mod|
    current_count = dp_current[mod] % MOD
    nums.each do |d|
      # 次の桁に遷移する
      dp_next[(mod + addition * d) % 13] += current_count
    end
  end
end

puts dp[length][5] %= MOD


Measured memory_bytes: 28028
#include <stdio.h>
#include <iostream>
#include <vector>
#include <algorithm>
#include <functional>
#include <cstdlib>
#include <list>
#include <numeric>
#include <map>
#include <cmath>
#include <string>
#define rep(i,n) for(int i=0;i<n;i++)
#define all(x) (x).begin(),(x).end()
#define sz(x) ((int)(x).size())
typedef long long ll;
using namespace std;
//================================================

int a = 0, b = 0, c, d, n, k = 0;
string s, t;



int main()
{
	cin >> s >> t;
	string ans;
	rep(i,sz(s))
	{
		ans += s[i];
		ans += t[i];
	}
	if(sz(s)-sz(t)==1)
	{
		ans = ans.substr(0, sz(ans) - 1);
	}
	cout << ans << endl;
	return 0;
}

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

int main() {
    long long L, R;
    cin >> L >> R;

    if (R - L >= 2019) {
        cout << 0 << endl;
        return 0;
    }

    long long res = 2019;
    for (long long i = L; i <= R; i++) {
        for (long long j = i + 1; j <= R; j++) {
            res = min(res, (i * j) % 2019);
        }
    }

    cout << res << endl;
    return 0;
}

Measured memory_bytes: 256
N, M = map(int, input().split())
A = list(map(int, input().split()))
weight = [0,2,5,5,4,5,6,3,7,6]
dp = [-1] * (N+1)
dp[0] =  0

for i in range(N+1):
    for a in A:
        if i + weight[a] < N+1:
            dp[i + weight[a]] = max(dp[i + weight[a]], dp[i]*10 + a)
print(dp[-1])


Measured memory_bytes: 20592
#include<cstdio>
#include<algorithm>
#include<iostream>
using namespace std;
 
char array[101][101];
int H,W;
int dx[]={1,0,-1,0};
int dy[]={0,1,0,-1};
 
int dfs(int Y, int X,char key){
  int nx,ny;
  array[Y][X]='.';
 
  for(int i=0;i<4;i++){
    nx=X+dx[i];
    ny=Y+dy[i];
    if(nx>=0 && nx<=W && ny>=0 && ny<=H && array[ny][nx]==key) dfs(ny,nx,key);
  }
 
}
 
 
int main(){
 
 
  while(1){
    cin>>H>>W;
    int cnt=0;
    if(H==0 && W==0) break;
    for(int i=0;i<H;i++)
      for(int j=0;j<W;j++)
    cin>>array[i][j];
    for(int i=0;i<H;i++)
      for(int j=0;j<W;j++)
    if(array[i][j]=='#' || array[i][j]=='*' || array[i][j]=='@'){
      dfs(i,j,array[i][j]);
      cnt++;
    }
    cout<<cnt<<endl;
  }
  return 0;
}

Measured memory_bytes: 1636
#include <iostream>
#include <algorithm>
#include <bitset>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <cstring>
#include <utility>
#include <vector>
#include <complex>
#include <valarray>
#include <fstream>
#include <cassert>
#include <cmath>
#include <functional>
#include <iomanip>
#include <numeric>
#include <climits>
#include <random>

#define _overload(a, b, c, d, ...) d
#define _rep1(X, A, Y) for (int (X) = (A);(X) <= (Y);++(X))
#define _rep2(X, Y) for (int (X) = 0;(X) < (Y);++(X))
#define rep(...) _overload(__VA_ARGS__, _rep1, _rep2)(__VA_ARGS__)
#define rrep(X,Y) for (int (X) = Y-1;(X) >= 0;--(X))
#define all(X) (X).begin(),(X).end()
#define len(X) ((int)(X).size())
#define mod(n, m) (((n)%(m)+(m))%m)
#define fi first
#define sc second
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> Pii;
typedef pair<ll,ll> Pll;
const int INFINT = 1 << 30;                          // 1.07x10^ 9
const ll INFLL = 1LL << 60;                          // 1.15x10^18
const double EPS = 1e-10;
const int MOD = 1000000007;
const int dx[4] = {1, 0, -1, 0}, dy[4] = {0, 1, 0, -1};

int K, N;

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

  cin >> N >> K;

  if (K != 1) cout << N - K << endl;
  else cout << 0 << endl;

  return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<queue>
#include<cstring>
#include<cmath>
#include<cstdlib>
using namespace std;
#define mem(a,b) memset(a,b,sizeof(a))
typedef long long LL;
typedef pair<int,int> PII;
#define X first
#define Y second
inline int read()
{
	int x=0,f=1;char c=getchar();
	while(!isdigit(c)){if(c=='-')f=-1;c=getchar();}
	while(isdigit(c)){x=x*10+c-'0';c=getchar();}
	return x*f;
}
char s[200010];
int len;
int main()
{
	scanf("%s",s);
	len=strlen(s);
	int cnt=0;
	for(int i=0;i<len;i++)cnt+=s[i]-'0';
	if(cnt%9==0)puts("Yes");
	else puts("No");
	return 0;
}
/*

*/

Measured memory_bytes: 3280
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n) FOR(i,0,n)

int n,h,w;
double ans = 0;

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

    cin >> n >> h >> w;
    cout << (n - h + 1) * (n - w + 1) << endl;
	

}

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

//temmplate------
#define FOR(i, m, n) for (int i = m; i < n; i++)
#define REP(i, n) for (int i = 0; i < n; i++)
#define REPR(i, n) for (int i = n; i >= 0; i--)
#define all(x) (x).begin(), (x).end()
#define INF 1e9
#define ZERO(a) memset(a, 0, sizeof(a))
typedef long long lint;
//------template

int main(){
    int H;
    int N;
    cin >> H >> N;
    int A[N];
    REP(i,N){
        cin >> A[i];
    }
    REP(i,N){
        H = H - A[i];
    }
    if (H <= 0){
        cout << "Yes\n";
    } else {
        cout << "No\n";
    }
}

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

const int maxn = 105;
const int mod = 1e9 + 7;

int n;
int dp[maxn][5][5][5][5]; // a - 0, c - 1, g - 2, t - 3

int rec (int pos, int l1, int l2, int l3, int l4) {
    if (dp[pos][l1][l2][l3][l4] != -1)
        return dp[pos][l1][l2][l3][l4];
    else if (l1 == 0 && l2 == 1 && l4 == 2)
        return 0;
    else if (l2 == 0 && l3 == 1 && l4 == 2)
        return 0;
    else if (l1 == 0 && l3 == 1 && l4 == 2)
        return 0;
    else if (l2 == 0 && l3 == 2 && l4 == 1)
        return 0;
    else if (l2 == 1 && l3 == 0 && l4 == 2)
        return 0;
    else if (pos == n)
        return 1;
    else {
        int res = 0;
        for (int i = 0; i < 4; ++i)
            (res += rec(pos + 1, l2, l3, l4, i)) %= mod;
        return dp[pos][l1][l2][l3][l4] = res;
    }
}

signed main () {
    cin >> n;
    memset(dp, -1, sizeof(dp));
    cout << rec(0, 4, 4, 4, 4) << '\n';
}


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

int main(){
	long long n;
	cin >> n;
	map<string,long long> m;
	string str;
	long long sum = 0;
	for(long long i = 0;i < n;i++){
		cin >> str;
		sort(str.begin(),str.end());
		m[str]++;
	}
	map<string,long long>::iterator it;
	for(it = m.begin();it!=m.end();it++){
		if(it->second > 1){
			for(long long i = 1;i < it->second;i++){
				sum += i;
			}
		}
	} 
	cout << sum << endl;
	return 0;
} 

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

int main(void){
	int max=0;
	int sum;
	int N,T,l,r;
	int now=0;
	int io[100001];
	cin>>N>>T;
	for(int i=0;i<=T;i++)io[i]=0;
	for(int i=0;i<N;i++){
		cin>>l>>r;
		io[l]++;
		io[r]--;
	}

	for(int i=0;i<=T;i++){
		now+=io[i];
		max=(max>=now)?(max):(now);
	}
	cout<<max<<endl;
	return 0;
}

Measured memory_bytes: 3504
s = input()
if s == 'RRS':
    print(2)
elif s == 'SRR':
    print(2)
elif s == 'RRR':
    print(3)
elif s == 'SRS':
    print(1)
elif s == 'RSS':
    print(1)
elif s == 'SSR':
    print(1)
elif s == 'RSR':
    print(1)
else:
    print(0)

Measured memory_bytes: 9120
# -*- coding: utf-8 -*-
import sys
sys.setrecursionlimit(10**9)
INF=10**18
MOD=10**9+7
input=lambda: sys.stdin.readline().rstrip()
YesNo=lambda b: bool([print('Yes')] if b else print('No'))
YESNO=lambda b: bool([print('YES')] if b else print('NO'))
int1=lambda x:int(x)-1

def main():
    N=int(input())
    A=[0]+list(map(lambda x: int(x)-1,input().split()))
    l=[0]*N
    for i in range(1,N):
        l[A[i]]+=1
    for i in range(N):
        print(l[i])

if __name__ == '__main__':
    main()


Measured memory_bytes: 93336
#pragma region
#include <bits/stdc++.h>

#define rep(i, n) for (int i = 0; i < int(n); i++)
#define rrep(i, n) for (int i = int(n) - 1; i >= 0; i--)
#define reps(i, n) for (int i = 1; i <= int(n); i++)
#define rreps(i, n) for (int i = int(n); i >= 1; i--)
#define repc(i, n) for (int i = 0; i <= int(n); i++)
#define rrepc(i, n) for (int i = int(n); i >= 0; i--)
#define repi(i, a, b) for (int i = int(a); i < int(b); i++)
#define repic(i, a, b) for (int i = int(a); i <= int(b); i++)
#define each(x, y) for (auto &x : y)
#define all(a) (a).begin(), (a).end()
#define bit32(x) (1 << (x))
#define bit64(x) (1ll << (x))

using namespace std;

using i32 = int;
using i64 = long long;
using f80 = long double;
using vi32 = vector<i32>;
using vi64 = vector<i64>;
using vf80 = vector<f80>;
using vstr = vector<string>;

inline void yes() { cout << "Yes" << '\n'; exit(0); }
inline void no() { cout << "No" << '\n'; exit(0); }
inline i64 gcd(i64 a, i64 b) { if (min(a, b) == 0) return max(a, b); if (a % b == 0) return b; return gcd(b, a % b); }
inline i64 lcm(i64 a, i64 b) { if (min(a, b) == 0) return max(a, b); return a / gcd(a, b) * b; }
template <typename T> class pqasc : public priority_queue<T, vector<T>, greater<T>> {};
template <typename T> class pqdesc : public priority_queue<T, vector<T>, less<T>> {};
template <typename T> inline void amax(T &x, T y) { if (x < y) x = y; }
template <typename T> inline void amin(T &x, T y) { if (x > y) x = y; }
template <typename T> inline T exp(T x, i64 n, T e = 1) { T r = e; while (n > 0) { if (n & 1) r *= x; x *= x; n >>= 1; } return r; }
template <typename T> istream& operator>>(istream &is, vector<T> &v) { each(x, v) is >> x; return is; }
template <typename T> ostream& operator<<(ostream &os, vector<T> &v) { rep(i, v.size()) { if (i) os << ' '; os << v[i]; } return os; }
void solve(); int main() { ios::sync_with_stdio(0); cin.tie(0); cout << fixed << setprecision(16); solve(); return 0; }
#pragma endregion

struct UnWeightedGraph {
  struct Edge {
    int to;
    Edge(int to) : to(to) {}
  };
  vector<vector<Edge>> edges;
  int n;
  UnWeightedGraph(int n) : n(n) {
    edges.assign(n, vector<Edge>());
  }
  void add_edge(int v, int u) {
    edges[v].emplace_back(u);
  }
  vector<Edge> &operator[](int x) {
    return edges[x];
  }
};

void solve() {
  int n, q;
  cin >> n >> q;
  UnWeightedGraph g(n);
  rep(i, n - 1) {
    int a, b;
    cin >> a >> b;
    a--, b--;
    g.add_edge(a, b);
    g.add_edge(b, a);
  }
  vi32 value(n);
  rep(i, q) {
    int p, x;
    cin >> p >> x;
    p--;
    value[p] += x;
  }
  auto dfs = [&](auto dfs, int u, int p) -> void {
    each(e, g[u]) if (e.to != p) {
      value[e.to] += value[u];
      dfs(dfs, e.to, u);
    }
  };
  dfs(dfs, 0, -1);
  cout << value << endl;
}


Measured memory_bytes: 21120
#include<bits/stdc++.h>
#include<math.h>
using namespace std;
int main()
{
	long long a,b,h,m;
	cin>>a>>b>>h>>m;
	 if (h == 12) h = 0;  
    if (m == 60) m = 0;  
    double hour_angle = 0.5 * (h * 60 + m);  
    double minute_angle = 6 * m; 
    double angle = abs(hour_angle - minute_angle);
    angle = min(360 - angle, angle);
    if(angle>180)
    angle=angle-180;
    double angl=double(angle*M_PI/180);
    cout<<fixed<<setprecision(9)<<sqrt(a*a+b*b-(2*a*b*cos(angl)));
}

Measured memory_bytes: 4228
#include <iostream>
#include <iomanip>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <algorithm>
#include <cstdio>
#include <utility>
#include <string>
#include <cmath>
#include <cstdlib>
#include <cstring>
#include <deque>

using namespace std;

typedef uint64_t u64;
typedef int64_t s64;
typedef uint32_t u32;
typedef int32_t s32;
typedef vector<s32> vs32;
typedef vector<u32> vu32;
typedef vector<s64> vs64;
typedef vector<u64> vu64;

const double PI=3.14159265358979323846;

#define MAX(x, y) ((x) < (y) ? (y) : (x))
#define MIN(x, y) ((x) > (y) ? (y) : (x))

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

#define CEIL(x, y) (((x) + (y) - 1) / (y))
#define MOD 1000000007ULL

#define IN(l, r, x) ((l) <= (x) && (x) < (r))

int n;
string s;

bool solve(int x)
{
    bool ret = false;
    map<string, int> m;
    for (int i = 0; i + x <= s.size(); ++i)
    {
        string t = s.substr(i, x);
        if (m[t] > 0 && m[t] + x <= i + 1)
        {
            ret = true;
        }
        else if (m[t] == 0)
        {
            m[t] = i + 1;
        }
    }
    return ret;
}

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

    cin >> n >> s;

    int l = 0;
    int r = n / 2 + 1;
    while (l + 1 < r)
    {
        int m = (l + r) / 2;
        if (solve(m))
        {
            l = m;
        }
        else
        {
            r = m;
        }
    }

    cout << l << "\n";
    return 0;
}



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


int main(){
    string str;
    cin >> str;
    int n=0,w=0,s=0,e=0;
    rep(i,str.size()){
        if(str[i]=='N') n++;
        else if(str[i]=='W') w++;
        else if(str[i]=='S') s++;
        else e++;
    }
    string ans;
    if( (n==0 && s>0) || (n>0 && s==0)){
        ans = "No";
    }
    else if( (w==0 && e>0) || (w>0 && e==0) ){
        ans = "No";
    }
    else ans = "Yes";
    cout << ans << endl;
    return 0;
}


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

int a,b,c,d,e,f;

int ans1,ans2;

double mx;

int main()
{
	cin>>a>>b>>c>>d>>e>>f;
	ans1=100*a;
	for(int i=0;i<=30;i++)
		for(int j=(i==0?1:0);j<=30;j++)
		{
			int q=i*a*100+j*b*100;
			if(q<=f)
			{
				for(int k=0;k<=300;k++)
					for(int l=0;l+k<=300;l++)
					{
						if(k*c+l*d+q<=f)
						{
							double now;
							now=(double)(k*c+l*d)/(double)(k*c+l*d+q);
							if(now>mx&&now*(e+100.0)<=e)
							{
								mx=now;
								ans2=k*c+l*d;
								ans1=k*c+l*d+q;
							}
						}
					} 
			}
		}
	cout<<ans1<<" "<<ans2;
 } 

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

struct Team{
    int id;
    int win;
    bool operator<(const Team& r) const {
        return win == r.win ? id < r.id : win > r.win;
    }
    Team(){}
    Team(int a, int b) : id(a), win(b) {}
};

int main(){
    int n,i,a,b,c,d;
    cin >> n;
    vector<Team> t(n);
    for(i=0;i<n;i++){
        t[i] = Team(i, 0);
    }
    for(i=0;i<n*(n-1)/2;i++){
        cin>>a>>b>>c>>d;
        a--;b--;
        if(c > d){
            t[a].win += 3;
        }else if(c < d){
            t[b].win += 3;
        }else{
            t[a].win += 1; t[b].win += 1;
        }
    }
    sort(t.begin(), t.end());
    int rw = t[0].win, cnt = 1, df = 0;
    vector<int> rank(n);
    for(i=0;i<n;i++){
        if(rw == t[i].win){
            rank[ t[i].id ] = cnt;
            df++;
        }else{
            rank[ t[i].id ] = cnt+df;
            cnt += df;
            rw = t[i].win;
            df = 1;
        }
    }
    for(i=0;i<n;i++){
        cout << rank[i] << endl;
    }
    return 0;
}

Measured memory_bytes: 1200
import itertools
S=input()
N=len(S)
flag=0
s="AKIHABARA"
s2=""
l2=[]
count=0
for i in range(9):
    l=list((itertools.combinations(s,i+1)))
    #print(l)
    for j in range(len(l)):
        s2="".join(l[j])
        l2.append(s2)
for i in range(len(l2)):
    if l2[i]==S:
        for j in range(len(l2[i])):
            if l2[i][j]=="A":
                count=count+1
        if (4-count)+len(l2[i])==9:
            flag=1
        break
if flag==1:
    print("YES")
else:
    print("NO")



Measured memory_bytes: 38256
#include<bits/stdc++.h>
using namespace std;
#define ll long long
int main(){
	ll x,n;
	cin>>x>>n;
	ll arr[n];
	bool vis[103]={0};
	for(int i=0;i<n;i++){
		cin>>arr[i];
		vis[arr[i]]=1;
	}
	ll a=x,ans1=102,ans2=102;
	while(a>=0){
		if(vis[a]==0){
			ans1=a;
			break;
		}
		a--;
	}
	a=x;
	while(a<=102){
		if(vis[a]==0){
			ans2=a;
			break;
		}
		a++;
	}
	if(x-ans1+1<=ans2-x+1){
		cout<<ans1;
	}
	else cout<<ans2;
	return 0;
}

Measured memory_bytes: 3672
#include <stdio.h>

int main(void){
  int n,i;
  float under;
  under=0.0;
  scanf("%d",&n );
  int  a[n];
  for(i=0;i<n;i++){
    scanf("%d",&a[i]);
  }

  for(i=0;i<n;i++){
    under += (1/(float)a[i]);
  }

  printf("%f\n",(1/under) );


  return 0;
}


Measured memory_bytes: 128
#include <iostream>
#include <stack>
using namespace std;
int main(){
	int N, i;
	int num[11];
	cin >> N;
	while( N-- > 0 ){
		for( i = 0; i < 10; i++ ){
			cin >> num[i];
		}
		stack<int> st1;
		stack<int> st2;
		for( i = 0; i < 10; i++ ){
			if( st1.empty() ){
				st1.push(num[i]);
				continue;
			}else if( st2.empty() ){
				if( st1.top() < num[i] ){
					st1.push(num[i]);
					continue;
				}else{
					st2.push(num[i]);
					continue;
				}
			}
			if( st1.top() > num[i] ){
				if( st2.top() > num[i] ){
					cout << "NO" << endl;
					break;
				}else{
					st2.push(num[i]);
				}
			}else{
				if( st2.top() < num[i] ){
					if( st1.top() > st2.top() ){
						st1.push(num[i]);
					}else{
						st2.push(num[i]);
					}
				}
			}
		}
		if( i == 10 ) cout << "YES" << endl;
	}
}

Measured memory_bytes: 1192
#include <bits/stdc++.h>
using namespace std;
#define REP(i,a) for(int i = 0; i < (a); i++)
typedef long long ll;
typedef pair<int, int> P;
const int INF = 1e9;
const int MOD = 1e9 + 7;

int SOD(int n){
	int sum = 0;
	while(n > 0){
		sum += n % 10;
		n /= 10;
	}
	return sum;
}

int main(){
	int n;
	cin >> n;
	if(SOD(n) == 1) cout << 10 << endl;
	else cout << SOD(n) << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define LOOP(n) for (int _i = 0; _i < (n); _i++)
#define REP(i, n) for (int i = 0; i < (n); ++i)
#define FOR(i, r, n) for (int i = (r); i < (n); ++i)
#define ALL(obj) begin(obj), end(obj)
using namespace std;
using ll = long long;
using ull = unsigned long long;

const int INF = 2100100100;
const int MOD = 1e9 + 7;

// 多次元 vector 生成
template <class T>
vector<T> make_vec(size_t a) {
    return vector<T>(a);
}
template <class T, class... Ts>
auto make_vec(size_t a, Ts... ts) {
    return vector<decltype(make_vec<T>(ts...))>(a, make_vec<T>(ts...));
}
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;
}

int main() {
    // cin.tie(0);
    // ios::sync_with_stdio(false);
    int A, B, C;
    cin >> A >> B >> C;
    if (A > B) swap(A, B);
    if (B > C) swap(B, C);

    int ans = 0;
    ans += (C - A) / 2;
    A += (C - A) / 2 * 2;
    ans += (C - B) / 2;
    B += (C - B) / 2 * 2;

    if ((C - A) + (C - B) == 0) {
        cout << ans << endl;
    } else if ((C - A) + (C - B) == 1) {
        cout << ans + 2 << endl;
    } else {
        cout << ans + 1 << endl;
    }

    return 0;
}


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

#define rep(i,z) for(int i = 0; i<(int)(z); i++)
#define rep1(i,z) for(int i = 1; i<=(int)(z); i++)
 
using namespace std;

typedef long long ll;
const ll MOD=1e9+7;
using pear = pair<int,int>; 



int main(){
  vector<int>c(3);
  int a,b; cin>>a;
  cin>>b;
  c[a-1]++; c[b-1]++;
  rep(i,3){
      if(c[i] == 0)cout<<i+1<<endl;
  }
  
}

Measured memory_bytes: 256
fn read_spc<T: std::str::FromStr>() -> Vec<T> {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).ok();
    s.trim().split_whitespace()
        .map(|e| e.parse().ok().unwrap()).collect()
}

fn main() {
    two_coins();
}

fn two_coins() {
    let abc: Vec<i64> = read_spc();
    let diff: i64 = abc[0] + abc[1] - abc[2];
    match diff {
        diff if diff < 0 => println!("No"),
        _                => println!("Yes")
    }
}

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

#define NL '\n'
#define C char
#define D double
#define F float
#define S string
#define sz(x) x.size()
#define INF LONG_LONG_MAX
#define PI (2.0*acos(0.0))
#define sfi(x) scanf("%d",&x)
#define sfi2(x,y) scanf("%d %d",&x,&y)
#define sfi3(x,y,z) scanf("%d %d %d",&x,&y,&z)
#define sfl(x) scanf("%lld",&x)
#define sfl2(x,y) scanf("%lld %lld",&x,&y)
#define sfl3(x,y,z) scanf("%lld %lld %lld",&x,&y,&z)
#define sfd(x) scanf("%lf",&x);
#define max3(a,b,c) max(a,max(b,c))
#define max4(a,b,c,d) max(max3(a,b,c),d)
#define min3(a,b,c) min(a,min(b,c))
#define min4(a,b,c,d) min(a,min3(b,c,d))
#define mem(ara,val) memset(ara,val,sizeof(ara))
#define READ freopen("input.txt","r",stdin)
#define WRITE freopen("output.txt","w",stdout)
#define IOS ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);

typedef long long LL;
typedef unsigned long long ULL;
typedef long double LD;

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

/*bool pal (S s)
{
    bool flag = true;
    for(int i=0; i<sz(s); i++)
    {
        if(s[i]!=s[sz(s)-i-1])
        {
            flag = false;
            break;
        }
    }
    if(flag) return true;
    else return false;
}*/

int main()
{
    int n;
    cin>>n;
    map <S , int> mp;
    map <S,int> :: iterator it;
    map <S,int> :: iterator iit;
    S x;
    vector <int> vec;
    for(int i=0; i<n; i++)
    {
        cin>>x;
        mp[x]++;
    }
    for(it=mp.begin(); it!=mp.end(); it++)
    {
        vec.push_back(it->second);
    }
    sort(vec.begin(), vec.end(), greater <int> ());
    //for(int i=0; i<sz(vec); i++) cout<<vec[i]<<" ";
    /*vector <int> idx;
    for(int i=1; i<sz(vec); i++)
    {
        if(vec[i]!=vec[i-1])
        {
            idx.push_back(vec[i-1]);
            break;
        }
        else
        {
            idx.push_back(vec[i]);
            idx.push_back(vec[i-1]);
        }
    }*/
    //int i=0;
    vector <S> ans;
    for(iit=mp.begin(); iit!=mp.end(); iit++)
    {
        if(iit->second==vec[0])
        {
            ans.push_back(iit->first);
        }
    }
    sort(ans.begin(),ans.end());

    for(int i=0; i<sz(ans); i++)
        cout<<ans[i]<<NL;
}


Measured memory_bytes: 27636
#ifndef bhartiya
    // #pragma GCC optimize("Ofast")
    // #pragma GCC optimize("unroll-loops")
    // #pragma GCC target ("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#endif

#include<bits/stdc++.h>
using namespace std;

typedef long long ll;
typedef pair<ll, ll> pll;
// not that imp
typedef pair<pll, ll> plll;
typedef vector<ll> vl;
typedef vector<pll> vll;

#define pb push_back
#define bitc  __builtin_popcountl
#define mp make_pair
#define ff first
#define ss second

#define swap(a,b) {a=a^b;b=a^b;a=a^b;}
#define fr(i,a,b) for (ll i = (a), _b = (b); i <= _b; i++)
#define rep(i,n) for (ll i = 0, _n = (n); i < _n; i++)
#define repr(i,n) for (ll i = n - 1; i >= 0; i--)
#define frr(i,a,b) for (ll i = (a), _b = (b); i >= _b; i--)

#ifdef bhartiya
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>
void __f(const char* name, Arg1&& arg1){
	cout << name << " : " << arg1 << endl;
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args){
	const char* comma = strchr(names + 1, ',');cout.write(names, comma - names) << " : " << arg1<<" | ";__f(comma+1, args...);
#define start_routine() int begtime = clock();
#define end_routine() int endtime = clock(); \
					  cout << "\n\nTime elapsed: " << (endtime - begtime)*1000/CLOCKS_PER_SEC << " ms\n\n";
}
#else
#define endl '\n'
#define trace(...)
#define start_routine()
#define end_routine()
#endif

#define inf 200000000000000ll
#define mod 1000000007ll
#define eps 1e-7

ll gcd(ll a, ll b){ return b==0 ? a : gcd(b, a%b); }
const ll maxn = 3004;
ll a[maxn];
ll dp[maxn][maxn];

int main()
{ 
    start_routine();
	ios_base::sync_with_stdio(false);
    cin.tie(NULL); cout.precision(10);
    cin.exceptions(cin.failbit);
    #ifdef bhartiya
        freopen("input.txt", "r", stdin);
        freopen("output.txt", "w", stdout);
    #endif
    int t = 1;
    // cin>>t;
    while(t--){
        ll n,k,x,m,y;
        cin>>n;
        rep(i,n){
            cin>>a[i];
            dp[1][i] = a[i];
        }
        for(ll i=2;i<=n;i++){
            for(ll j=0;j<=n-i;j++){
                x = a[j] - dp[i-1][j+1];
                y = a[j+i-1] - dp[i-1][j];
                dp[i][j] = max(x,y);
                // trace(x,y);
                // trace(dp[i-1][j], dp[i-1][j+1]);
                // trace(a[j], a[j+1]);
                // trace(i,j);
            }
        }
        cout<<dp[n][0]<<endl;
    }
    end_routine();
}


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

int main(){
  int count=0;
  int N;
  cin>>N;
  vector<int>H(N+1);
  H[N]=1000000001;
  vector<int>Hc(N);
  rep(i,N){
    cin>>H[i];
  }
  rep(i,N){
    int c=0;
    for(int j=i;j<N;j++){
      if(H[j]>=H[j+1]){
        c++;
      }
      else{
        Hc[i]=c;
        break;
      }
    }
    i+=c;
  }
  cout<<*max_element(Hc.begin(),Hc.end());
}


Measured memory_bytes: 1024
import java.util.*;

public class Main {

    /* チェックリスト
     * 結果はintの範囲を超えていませんか？(必要な時以外はlongを使いましょう)
     * TLEしそうな処理はありませんか？
     */
    public static void main(String args[]){
        Scanner s = new Scanner(System.in);
        int a = Integer.parseInt(s.nextLine());
        String[] sa = s.nextLine().split(" ");
        List<Float> list = new ArrayList<Float>();
        for(String in : sa){
            list.add(Float.valueOf(in));
        }
        float gyaku = 0;
        for(float i : list){
            gyaku += 1 / i;
        }
        System.out.println(1 / gyaku);
    }
}

Measured memory_bytes: 23636
#![allow(non_snake_case)]

use std::cmp::*;

fn read_line() -> String {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).unwrap();
    s.trim().to_string()
}

fn read_vec() -> Vec<i32> {
    read_line()
        .split_whitespace()
        .map(|e| e.parse().unwrap())
        .collect()
}

fn read_int_tuple() -> (i32, i32) {
    let v = read_vec();
    (v[0], v[1])
}

fn main() {
    let (N, M) = read_int_tuple();
    let N = N as usize;
    let m = 1e9 as i32 +7;
    let mut dp = vec![0; N+1];
    for i in 0..M {
        let a: usize = read_line().parse().unwrap();
        dp[a] = -1;
    }
    dp[0] = 1;
    dp[1] = if dp[1] == -1 {-1} else {1};
    for i in 2..N+1 {
        if dp[i] != -1 {
            dp[i] = max(0, dp[i-1]) + max(0, dp[i-2]);
            dp[i] %= m;
        }
    }
    println!("{}", dp[N]);
}


Measured memory_bytes: 4352
#ifdef Prateek
  #include "Prateek.h"
#else
  #include <bits/stdc++.h>
  using namespace std;
  #define debug(...) 42
#endif
#define F first
#define S second
#define pb push_back
#define f(i,x,n) for(int i=x;i<n;i++)
#define all(c) c.begin(),c.end()
#define int ll
using ll = long long;
const int MOD = 1e9+7, N = 1e7 + 10; 

int cnt[N];

int32_t main(){
   ios::sync_with_stdio(false);
   cin.tie(NULL);
   for(int i = 2; i < N; i++){
      for(int j = i; j < N; j += i){
         cnt[j]++;
      }
   }
   int ans = 0;
   int n;
   cin >> n;
   f(i,1,n+1){
      ans += i*(cnt[i]+1);
   }
   cout << ans << '\n';
   return 0;
} 

Measured memory_bytes: 81768
// In the name of Allah the Lord of the Worlds.

#include<bits/stdc++.h>

using namespace std;

typedef long long ll;

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

    ll n , m, k , ans = 0 , sum = 0;
    cin >> n >> m >> k;
    vector<ll>v;
    for(int i=0;i<n;i++){
        ll in;
        cin >> in;
        if(v.size()==0)v.push_back(in);
        else v.push_back(v[i-1]+in);
        if(v[i]<=k)ans = i+1;
    }
    for(int i=0;i<m;i++){
        ll in;
        cin >> in;
        sum+=in;
        if(sum<=k){
            ll rem = k-sum;
            int idx = --lower_bound(v.begin(), v.end(), rem+1) - v.begin();
            ans = max(ans, (ll)i+idx+2);
        }
    }
    cout << ans << endl;

    return 0;
}


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

using namespace std;

template <typename A, typename B>
string to_string(pair<A, B> p);

template <typename A, typename B, typename C>
string to_string(tuple<A, B, C> p);

template <typename A, typename B, typename C, typename D>
string to_string(tuple<A, B, C, D> p);

string to_string(const string& s) { return '"' + s + '"'; }

string to_string(const char* s) { return to_string((string)s); }

string to_string(bool b) { return (b ? "true" : "false"); }

string to_string(vector<bool> v) {
  bool first = true;
  string res = "{";
  for (int i = 0; i < static_cast<int>(v.size()); i++) {
    if (!first) {
      res += ", ";
    }
    first = false;
    res += to_string(v[i]);
  }
  res += "}";
  return res;
}

template <size_t N>
string to_string(bitset<N> v) {
  string res = "";
  for (size_t i = 0; i < N; i++) {
    res += static_cast<char>('0' + v[i]);
  }
  return res;
}

template <typename A>
string to_string(vector<A> v) {
  bool first = true;
  string res = "{";
  for (const auto& x : v) {
    if (!first) {
      res += ", ";
    }
    first = false;
    res += to_string(x);
  }
  res += "}";
  return res;
}

template <typename A, typename B>
string to_string(pair<A, B> p) {
  return "(" + to_string(p.first) + ", " + to_string(p.second) + ")";
}

template <typename A, typename B, typename C>
string to_string(tuple<A, B, C> p) {
  return "(" + to_string(get<0>(p)) + ", " + to_string(get<1>(p)) + ", " +
         to_string(get<2>(p)) + ")";
}

template <typename A, typename B, typename C, typename D>
string to_string(tuple<A, B, C, D> p) {
  return "(" + to_string(get<0>(p)) + ", " + to_string(get<1>(p)) + ", " +
         to_string(get<2>(p)) + ", " + to_string(get<3>(p)) + ")";
}

void debug_out() { cerr << endl; }

template <typename Head, typename... Tail>
void debug_out(Head H, Tail... T) {
  cerr << " " << to_string(H);
  debug_out(T...);
}

#ifdef LOCAL
#define debug(...) cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)
#else
#define debug(...) void(0)
#endif

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int n, m, k;
  cin >> n >> m >> k;
  vector<int> a(n + 1, 0);
  vector<long long> sum_a(n + 1, k + 1);
  sum_a[0] = 0;
  for (int i = 1; i <= n; i++) {
    cin >> a[i];
    if (sum_a[i - 1] + a[i] > k) continue;
    sum_a[i] = sum_a[i - 1] + a[i];
  }
  vector<int> b(m + 1, 0);
  vector<long long> sum_b(m + 1, k + 1);
  sum_b[0] = 0;
  for (int i = 1; i <= m; i++) {
    cin >> b[i];
    if (sum_b[i - 1] + b[i] > k) continue;
    sum_b[i] = sum_b[i - 1] + b[i];
  }
  debug(sum_a);
  debug(sum_b);
  int ans = 0;
  for (int i = 0; i <= n; i++) {
    if (sum_a[i] > k) break;
    int cnt_b = 0;
    for (int j = m; j >= 0; j--) {
      if (sum_a[i] + sum_b[j] <= k) {
        cnt_b = j;
        m = j;
        break;
      }
    }
    debug(i, cnt_b);
    ans = max(ans, i + cnt_b);
  }
  cout << ans << '\n';
  return 0;
}

Measured memory_bytes: 7944
gets # n
ns = gets.split.map(&:to_i)

counts = Hash.new(0)
# cumulative sums
ns.inject([0]) { |a, n| a << a.last + n }.each do |n|
  counts[n] += 1
end

# sum of nC2
p counts.each_value.reduce(0) { |a, n| a + n * (n - 1) / 2 }


Measured memory_bytes: 30596
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cmath>
#include<cstring>
#include<queue>
#include<vector>
#include<map>

#define For(i,a,b) for(int i=a;i<=b;i++)
#define ForD(i,a,b) for (int i=a;i>=b;i--)
#define LL long long
#define INF (2147483647)
#define sqr(x)	((x)*(x))

using namespace std;

inline int read(){
    int data=0,w=1; char ch=0;
    while (ch!='-'&&(ch<'0'||ch>'9')) ch=getchar();
    if (ch=='-') w=-1,ch=getchar();
    while  (ch>='0' && ch<='9') data=data*10+ch-'0',ch=getchar();
    return data*w;
}

inline void write(int x){
	if(x<0) putchar('-'),x=-x;
    if(x>9) write(x/10);
    putchar(x%10+'0');
} 


int a[1000000],f[1000000];
int main(){	
	int n=read(),x=read();
	if (x==1||x==2*n-1)	{
		puts("No");return 0;
	}
	if (n==2){
		puts("Yes");
		For(i,1,3)
			write(i),puts("");
		return 0;
	}
	memset(f,true,sizeof(f));
	if (x>2){
		f[1]=false,f[2]=false,f[x+1]=false,f[x]=false;
		a[n-1]=1,a[n]=x,a[n+1]=x+1,a[n+2]=2;
		int t=1;
		For(i,1,2*n-1){
			if (a[i]!=0)	continue;
			while(!f[t])
				t++;
			a[i]=t;t++;
		}
	}
	else{
		f[1]=false,f[2]=false,f[3]=false,f[4]=false;
		a[n-1]=3,a[n]=2,a[n+1]=1,a[n+2]=4;
		int t=1;
		For(i,1,2*n-1){
			if (a[i]!=0)	continue;
			while(!f[t])
				t++;
			a[i]=t;t++;
		}
	}
	puts("Yes");
	For(i,1,2*n-1)
		write(a[i]),puts("");
} 

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

using namespace std;


int main()
{
    long n, x;
    cin>> n >> x;
    long arr[n+1];
    
    for(int i =0; i < n; ++i)
    	cin>> arr[i];
    arr[n] = x;
    sort(arr, arr+n+1);
    long dif[n];
    for(int i =0; i < n; ++i){
    	dif[i] = arr[i+1]-arr[i];
    }
    
    long gcd = dif[0];
    
    for(int i = 1; i < n; ++i)
	{
	
    	gcd = __gcd(gcd, dif[i]);
    }
    cout << gcd << endl;
    return 0;
}

Measured memory_bytes: 1792
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#include<set> 
#include<math.h>
#define pai arccos(-1);
#define keta(n) cout << fixed << setprecision((n));
#define ll long long;
int main(){
  int k,s,a,b,c;
  cin>>k>>s;
  int ans =0;
  for(int x=0;x<=k;x++){
    for(int y=0;y<=k;y++){
     int z=s-x-y;
        if(0<=z&&z<=k)
          ans++;
      }
    }
  
	cout<<ans;
}


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

int main(void) {
	int n;

	while (1) {
		cin >> n;
		if (n == 0) break;

		int sumA = 0, sumB = 0;
		int pointA, pointB;
		for (int i = 0; i < n; i++){

			cin >> pointA >> pointB;
			if (pointA > pointB) {
				sumA += (pointA + pointB);
			} else if (pointB > pointA) {
				sumB += (pointA + pointB);
			} else {
				sumA += pointA;
				sumB += pointA;
			}
		}
		cout << sumA << " " << sumB << endl;
	}

	return 0;
}

Measured memory_bytes: 3076
### subroutines

def match?(c0, c1)
  (c0 == 'i' && c1 == 'i') ||
  (c0 == 'w' && c1 == 'w') ||
  (c0 == '(' && c1 == ')') ||
  (c0 == ')' && c1 == '(')
end

### main

str = gets.strip
n = str.length
k = (n - 1) / 2

count = 0

for i in (0..k)
  count += 1 if ! match?(str[i], str[n - 1 - i])
end

puts count

Measured memory_bytes: 6100
import sys

stdin = sys.stdin
sys.setrecursionlimit(10**6)
ns = lambda: stdin.readline().rstrip()
ni = lambda: int(stdin.readline().rstrip())
nm = lambda: map(int, stdin.readline().split())
nl = lambda: list(map(int, stdin.readline().split()))

n = ni()
a = nl()
lis = [(e, i) for i, e in enumerate(a)]
lis.sort()
dp = [[-1]*n for _ in range(n)]

def solve(l, r):
    if l > r:
        return 0
    if dp[l][r] >= 0:
        return dp[l][r]
    idx = r - l
    e, i = lis[idx]
    dp[l][r] = max(abs(i-l)*e + solve(l+1, r), abs(r-i)*e + solve(l, r-1))
    return dp[l][r]

print(solve(0, n-1))


Measured memory_bytes: 137600
/*----------------by syr----------------*/
/*
  -----  -----  -----
  |   |  |---|    _/
  |   |  | \_    /
  -----  |   \  -----

  |---\  \   /  |\  /|
  |   |   \_/   | \/ |
  |   |   / \   |    |
  |---/  /   \  |    |
*/
#include<algorithm>
#include<bitset>
#include<cctype>
#include<cstring>
#include<cstdlib>
#include<deque>
#include<fstream>
#include<functional>
#include<iomanip>
#include<iostream>
#include<iterator>
#include<limits>
#include<list>
#include<map>
#include<math.h>
#include<queue>
#include<set>
#include<stack>
#include<stdio.h>
#include<sstream>
#include<string>
#include<time.h>
#include<utility>
#include<vector>

#define PH push
#define MP make_pair
#define PB push_back
#define fst first
#define snd second
#define FOR(i,x,y) for(int i=(x);i<(y);++i)
#define REP(i,x,y) for(int i=(x);i<=(y);++i)
#define x0 x0123456789
#define y0 y0123456789
#define x1 x1234567890
#define y1 y1234567890
#define x2 x2345678901
#define y2 y2345678901

using namespace std;

typedef double db;
typedef long long ll;
typedef long double ldb;
typedef pair<int,int> pii;

const int INF=1e9+7;
const int maxn=1e5+5;

class FenwickTree{
	private:
		ll dat[maxn<<1+5];
	public:
		inline void clear(){memset(dat,0,sizeof(dat));}
		inline void update(int x,int k){
			for(x+=maxn;x<=maxn<<1;x+=x&(-x)) dat[x]+=k;
			return;
		}
		inline ll query(int x){
			ll ret=0;
			for(x+=maxn;x;x-=x&(-x)) ret+=dat[x];
			return ret;
		}
		inline void print(){
			REP(i,1,maxn<<1) if(dat[i]) printf("%d %lld\n",i,dat[i]);
			return;
		}
}fen;

int n;
int a[maxn],b[maxn],sum[maxn];

bool check(int x){
	fen.clear();
	ll ret=0;
	FOR(i,0,n) b[i]=(a[i]<x)?(-1):(1);
	FOR(i,0,n) sum[i]=(i)?(sum[i-1]+b[i]):(b[i]);
//	printf("%d\n",x);
//	FOR(i,0,n) printf("%d ",sum[i]);
//	puts("");
	for(int i=n-1;i>=0;--i){
		fen.update(sum[i],1);
		int r=fen.query(maxn);
		int l=fen.query(((i)?(sum[i-1]):(0))-1);
		ret+=r-l;
//		printf("%d %d %d %d %lld\n",maxn,sum[i-1]-1,r,l,ret);
//		fen.print();
//		printf("%lld ",ret);
	}
//	puts("");
//	printf("x=%d ret=%lld\n",x,ret);
	return (ret>=1ll*(n+1)*n/2/2);
}

int main(){
	scanf("%d",&n);
	FOR(i,0,n) scanf("%d",a+i);
	if(n==1){
		printf("%d\n",a[0]);
		return 0;
	}
	int l=-1,r=INF;
	while(l+1<r){
		int md=(l+r)>>1;
		if(check(md)) l=md;
		else r=md;
	}
	printf("%d\n",l);
	return 0;
}


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

const int M=305;
double dp[M][M][M];
//    i 3 j 2 k 1
// E[i][j][k]=E[i-1][j+1][k]*p1+E[i][j-1][k+1]*p2+E[i][j][k-1]*p3+E[i][j][k]*p4 + 1
// (1-p4) E[i][j][k] = E[i-1][j+1][k]*p1+E[i][j-1][k+1]*p2+E[i][j][k-1]*p3 + 1
// (1-(n-i-j-k)/n) = (i+j+k)/n
// pi/(1-p4) = i/(i+j+k)

int cnt[4];
int n; 
double getdp(int i,int j,int k)
{
	double &ans=dp[i][j][k];
	if(ans>-1.0) return ans;
	ans=(double)n;
	if(i) ans+=getdp(i-1,j+1,k)*i;
	if(j) ans+=getdp(i,j-1,k+1)*j;
	if(k) ans+=getdp(i,j,k-1)*k;
	ans/=(i+j+k);
	return ans;
}

int main()
{
	scanf("%d",&n);
	int ai;
	for(int i=1;i<=n;i++)
	{
		scanf("%d",&ai);
		cnt[ai]++;
	}
	for(int i=0;i<=n;i++)
		for(int j=0;j<=n;j++)
			for(int k=0;k<=n;k++)
				dp[i][j][k]=-100.0;
	dp[0][0][0]=0;
	printf("%.11f\n",getdp(cnt[3],cnt[2],cnt[1]));
	return 0;
}

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

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

#define fi first
#define se second
#define repl(i,a,b) for(ll i=(ll)(a);i<(ll)(b);i++)
#define rep(i,n) repl(i,0,n)
#define all(x) (x).begin(),(x).end()
#define dbg(x) cout<<#x"="<<x<<endl
#define mmax(x,y) (x>y?x:y)
#define mmin(x,y) (x<y?x:y)
#define maxch(x,y) x=mmax(x,y)
#define minch(x,y) x=mmin(x,y)
#define uni(x) x.erase(unique(all(x)),x.end())
#define exist(x,y) (find(all(x),y)!=x.end())
#define bcnt __builtin_popcountll

#define INF 1e16
#define mod 1000000007

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

  ll H,W,K;
  cin>>H>>W>>K;
  vector<string> B(H);
  rep(i,H)cin>>B[i];

  ll res=INF;
  rep(S,1<<H){
  	if(!((S>>(H-1))&1))continue;
  	ll sz=bcnt(S);
  	vector<ll> cnt(sz,0);
  	ll pen=0;
  	bool zdame=false;
  	rep(j,W){
  		ll idx=0;
  		ll crt=0;
  		rep(i,H){
  			if(B[i][j]=='1')crt++;
  			if((S>>i)&1){
  				if(crt>K){
  					zdame=true;
  					break;
  				}
  				cnt[idx]+=crt;
  				crt=0;
  				idx++;
  			}
  		}
  		if(zdame)break;
  		bool dame=false;
  		rep(i,sz){
  			if(cnt[i]>K){
  				dame=true;
  				break;
  			}
  		}
  		if(dame){
  			pen++;
  			j=j-1;
  			rep(i,sz)cnt[i]=0;
  		}
  	}
  	if(zdame)continue;
  	minch(res,pen+sz-1);
  }
  cout<<res<<endl;

  return 0;
}


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

int main(void){
  char S[10];
  int S1, S2, S3;
  scanf("%s", S);
  S1 = (S[0] - 48) * 1000 + (S[1] - 48) * 100 + (S[2] - 48) * 10 + (S[3] - 48);
  if(S[5] == '0')
    S2 = S[6] - 48;
  else
    S2 = (S[5] - 48) * 10 + (S[6] - 48);
  if(S[8] == '0')
    S3 = S[9] - 48;
  else
    S3 = (S[8] - 48) * 10 + (S[9] - 48);
  if(S2 < 4)
    cout << "Heisei" << "\n";
  else if(S2 == 4){
    if(S3 <= 30)
      cout << "Heisei" << "\n";
    else
      cout << "TBD" << "\n";
  }
  else if(S2 > 4)
    cout << "TBD" << "\n";
  return 0;
}


Measured memory_bytes: 3672
#include <stdio.h>

int main(void){
    char S[5];
    int N = 0;
    scanf("%s", S);
    for(int i = 0; i < 4; i++){
        switch(S[i]){
            case '+':
                N++; break;
            case '-':
                N--; break;
        }
    }
    printf("%d\n", N);
    return 0;
}

Measured memory_bytes: 128
#include<iostream>
#include<algorithm>
#include<vector>
#include<queue>
#include<map>
#include<unordered_map>

using namespace std;
typedef pair<long long int, long long int> PP;

long long int INF = 1e18;
long long int MOD = 1e9 + 7;

long long int dist(long long int x1, long long int y1, long long int x2, long long int y2){
  return abs(x2 - x1) + abs(y2 - y1);
}

int main(){
  long long int K;
  cin >> K;
  long long int X, Y;
  cin >> X >> Y;
  if(abs((X + Y) % 2) == 1 && K % 2 == 0){
    cout << -1 << endl;
    return 0;
  }
  vector<PP> v;
  long long int P = 0, Q = 0;
  while(P != X || Q != Y){
    if(abs(X - P) + abs(Y - Q) == K){
      v.push_back(PP(X, Y));
      break;
    }
    if((X + Y - P + Q) % 2 == 0){
      long long int y = (X + Y - P + Q) / 2;
      long long int x = (X + Y + P - Q) / 2 + K;
      if(dist(x, y, P, Q) == K && dist(x, y, X, Y) == K){
        P = x;
        Q = y;
        v.push_back(PP(x, y));
        continue;
      }
      y = (X + Y - P + Q) / 2;
      x = (X + Y + P - Q) / 2 - K;
      if(dist(x, y, P, Q) == K && dist(x, y, X, Y) == K){
        P = x;
        Q = y;
        v.push_back(PP(x, y));
        continue;
      }
      y = (X + Y - P + Q) / 2 - K;
      x = (X + Y + P - Q) / 2;
      if(dist(x, y, P, Q) == K && dist(x, y, X, Y) == K){
        P = x;
        Q = y;
        v.push_back(PP(x, y));
        continue;
      }
      y = (X + Y - P + Q) / 2 + K;
      x = (X + Y + P - Q) / 2;
      if(dist(x, y, P, Q) == K && dist(x, y, X, Y) == K){
        P = x;
        Q = y;
        v.push_back(PP(x, y));
        continue;
      }
      y = (-X + Y + P + Q) / 2;
      x = (X - Y + P + Q) / 2 + K;
      if(dist(x, y, P, Q) == K && dist(x, y, X, Y) == K){
        P = x;
        Q = y;
        v.push_back(PP(x, y));
        continue;
      }
      y = (-X + Y + P + Q) / 2;
      x = (X - Y + P + Q) / 2 - K;
      if(dist(x, y, P, Q) == K && dist(x, y, X, Y) == K){
        P = x;
        Q = y;
        v.push_back(PP(x, y));
        continue;
      }
      y = (-X + Y + P + Q) / 2 - K;
      x = (X - Y + P + Q) / 2;
      if(dist(x, y, P, Q) == K && dist(x, y, X, Y) == K){
        P = x;
        Q = y;
        v.push_back(PP(x, y));
        continue;
      }
      y = (-X + Y + P + Q) / 2 + K;
      x = (X - Y + P + Q) / 2;
      if(dist(x, y, P, Q) == K && dist(x, y, X, Y) == K){
        P = x;
        Q = y;
        v.push_back(PP(x, y));
        continue;
      }
    }
    if(abs(X - P) >= K){
      if(P < X){
        P += K;
      }else{
        P -= K;
      }
    }else{
      long long int rem = K - abs(X - P);
      P = X;
      if(Q < Y){
        Q += rem;
      }else{
        Q -= rem;
      }
    }
    v.push_back(PP(P, Q));
  }
  cout << v.size() << endl;
  for(PP p : v){
    cout << p.first << " " << p.second << endl;
  }
  return 0;
}


Measured memory_bytes: 5484
#include <stdio.h>

#define Max 10000
#define max 500

main(){
  int n[Max],q[max];
  int a,b,i,j,count=0;

  scanf("%d",&a);
  for(i=0;i<a;i++){
    scanf("%d",&n[i]);
  }
  scanf("%d",&b);
  for(j=0;j<b;j++){
    scanf("%d",&q[j]);
  }

  for(i=0;i<b;i++){
    for(j=0;j<a;j++){
      if(n[j] == q[i]){
	count++;
	break;
      }
    }
  }
  
  printf("%d\n",count);
  return 0;
}

Measured memory_bytes: 640
#include<iostream>
using namespace std;
int main(){
  int n,x[100],i,j,min=100000000,sum=0;
  cin >> n;
  for(i=0; i<n; i++){
    cin >> x[i];
  }
  for(i=1; i<100; i++){
    sum=0;
    for(j=0; j<n; j++){
      sum+=(x[j]-i)*(x[j]-i);
    }
    if(sum<min){
      min=sum;
    }
  }
  cout << min << endl;

}


Measured memory_bytes: 256
o[256],z[256];main(N,S,A,C,s,a,c,r,i){for(;scanf("%d",&N),N;printf("%d %d %d\n",S,A,C)){
	double H=9,h,n=N;
	for(i=0;i<N;i++)scanf("%d",z+i);
	for(s=0;s<16;s++)for(a=0;a<16;a++)for(c=0;c<16;c++){
		for(r=s,i=0;i<N;)o[(z[i++]+(r=(a*r+c)%256))%256]++;
		for(h=i=0;i<256;i++)if(o[i])h-=o[i]/n*log(o[i]/n),o[i]=0;
		if(h+.001<H)H=h,S=s,A=a,C=c;
	}
}exit(0);}

Measured memory_bytes: 640
#include <bits/stdc++.h>
 
using namespace std;
 
#define INF 1001000100010001000
#define MOD 1000000007
#define MAXMOD 4611664614458057389
#define EPS 1e-7
#define int long long
#define rep(i, N) for (int i = 0; i < N; i++)
#define Rep(i, N) for (int i = 1; i < N; i++)
#define For(i, a, b) for (int i = (a); i < (b); i++)
#define pb push_back
#define eb emplece_back
#define mp make_pair
#define i_i pair<int, int>
#define vi vector<int>
#define vvi vector<vi >
#define vb vector<bool>
#define vvb vector<vb >
#define vp vector< i_i >
#define all(a) (a).begin(), (a).end()
#define Int(x) int x; scanf("%lld", &x);
#define int2(x, y) int x, y; scanf("%lld %lld", &x, &y);
 
//int dxy[5] = {0, 1, 0, -1, 0};
// assign

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

int extgcd(int a, int b, int &x, int &y)
{
    int d = a;
    if (b != 0) {
        d = extgcd(b, a % b, y, x);
        y -= (a / b) * x;
    } else { x = 1; y = 0; }
    return d;
}

int repow(int x, int n, int mod)
{
    if (n == 0) return 1;
    int res = repow(x * x % mod, n / 2, mod);
    if (n & 1) res = res + x % mod;
    return res;
}

int mod_inverse(int a, int m)
{
    int x, y;
    extgcd(a, m, x, y);
    return ( m + x % m ) % m;
}

int ncmmod(int n, int m, int mod)
{
    int res = 1;
    rep(i, m) res = (res * ((n - i) % mod)) % mod;
    Rep(i, m+1) res = (res * mod_inverse(i, mod)) % mod;
    return res;
}

int ncm(int n, int r)
{
    if (r == 0) return 1;
    return (n-r+1) * ncm(n, r-1) / r;
}


signed main()
{
    Int(n);
    int2(a, b);
    
    vi data(n);
    rep(i, n) cin >> data[i];

    sort(all(data));
    reverse(all(data));

    if (data[0] != data[a-1] && a != 1) {
        double out = 0.0;
        rep(i, a) out += data[i];
        printf("%.10lf\n", out / a);

        int x = 0, y = 0;
        rep(i, n) {
            if (data[a-1] == data[i]) x++;
        }
        rep(i, a) {
            if (data[a-1] == data[i]) y++;
        }
        cout << ncm(x, y) << endl;
    } else {
        double out = 0.0;
        rep(i, a) out += data[i];
        printf("%.10lf\n", out / a);
        int cnt = 0;
        rep(i, n) {
            if (data[0] == data[i]) cnt++;
        }
        int ans = 0;
        for (int i = a-1; i < b; i++) {
            if (data[0] == data[i]) {
                ans += ncm(cnt, i+1);
//                cout << ";" << ans << endl;
            }
        }
        cout << ans << endl;
    }

    return 0;
}



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

template<class T> void vin(vector<T>& v, int n) {
    v.resize(n);
    for (int i = 0; i < n; ++i) {
        cin >> v[i];
    }
}

int sum[100010];

int main() {
    int N, K;
    cin >> N >> K;
    string s;
    cin >> s;

    bool flag = false;
    int len = 0, cur = 0;
    s += "1";
    rep(i, N+1) {
        if (s[i] == '0' and !flag) {
            flag = true;
        }
        else if (s[i] == '1' and flag) {
            flag = false;
            sum[cur++] = len;
            len = 0;
            flag = false;
        }
        len++;
    }

    int ans = 0, idx = 0, k = 0;
    len = 0; flag = false;
    rep(i, N) {
        if (s[i] == '1') {
            len++;
            flag = false;
        }
        else if (s[i] == '0' and !flag) {
            flag = true;
            k++;
            if (k > K) {
                len -= sum[idx++];
                k--;
                //cout << len << ", " << sum[idx-1] << endl;
            }
            len++;
        }
        else if (s[i] == '0' and flag) {
            len++;
        }

        ans = max(ans, len);
    }

    cout << ans << endl;
    // rep(i, N+1) cout << sum[i] << " ";
    // cout << endl;
}


Measured memory_bytes: 640