akhauriyash/Code-Regression huggingface dataset:
def cmb(n, r, mod):
    if r < 0 or r > n:
        return 0
    r = min(r, n-r)
    return g1[n] * g2[r] * g2[n-r] % mod

mod = 10**9 + 7 #出力の制限
N = 10**6
g1 = [1, 1] # 元テーブル
g2 = [1, 1] #逆元テーブル
inverse = [0, 1] #逆元テーブル計算用テーブル

for i in range(2, N + 1):
    g1.append((g1[-1] * i) % mod)
    inverse.append((-inverse[mod % i] * (mod//i)) % mod)
    g2.append((g2[-1] * inverse[-1]) % mod)

X, Y = map(int, input().split())

if (X + Y) % 3 != 0:
    print(0)
    exit()

A = (2 * Y - X) // 3
B = (2 * X - Y) // 3

print(cmb(A+B, A, mod))


Measured memory_bytes: 127432
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); i++)
#define rep1(i,n) for (int i = 1; i <= (n); i++)
#define repf(i,a,b) for (int i = (a); i < (b); i++)
#define repi(i,a,b) for (int i = (a); i <= (b); i++)
#define repr(i,a,b) for (int i = (a); i >= (b); i--)
#define all(x) (x).begin(),(x).end()
using namespace std;
using uint = unsigned int;
using ll = long long;
using ull = unsigned long long;
using vi = vector<int>;
using vvi = vector<vi>;
using pii = pair<int, int>;
using vc = vector<char>;
using vvc = vector<vc>;
using vs = vector<string>;
using tiii = tuple<int, int, int>;

int main() {
  int A, B, K;
  cin >> A >> B >> K;
  
  repr(i,min(A,B),1) {
    if (A%i==0 && B%i==0) {
      K--;
      if (K==0) {
        cout << i << endl;
        return 0;
      }
    }
  }
}

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

#define all(a) (a).begin(), (a).end()
#define rall(a) (a).rbegin(), (a).rend()
#define MIN(a) *min_element(all(a))
#define MAX(a) *max_element(all(a))
#define SUM(a) accumulate(all(a), 0LL)
#define REP(i, n) for(int (i)=0; (i)<(n); (i)++)
#define RREP(i, n) for(int (i)=(n)-1; (i)>=0; (i)--)
#define FOR(i, m, n) for(int (i)=(m); (i)<(n); i++)
#define FORR(i, m, n) for(int (i)=(n)-1; (i)>=(m); i--)
#define debug(x) cerr << #x << " = " << x << endl
//#define int long long

typedef long long ll;
//ll const MOD = 998244353;
ll const MOD = 1e9+7;
int const inf = 1e9;
ll const INF = 1e18;

inline void ios_(){cin.tie(0); ios::sync_with_stdio(false);}
template<typename T> int size(const T& a){return (int)a.size();}
template<typename T> T Div(T a, T b){return (a + b - 1) / b;}
template<typename T> bool chmin(T& a, const T& b){if(a > b){a = b; return true;} return false;}
template<typename T> bool chmax(T& a, const T& b){if(a < b){a = b; return true;} return false;}



signed main(){
    int n;
    cin >> n;
    vector<ll> enemy(n+1), hero(n);
    ll sum = 0;
    for(auto& i : enemy){
        cin >> i;
        sum += i;
    }
    for(auto& i : hero) cin >> i;

    REP(i, n+1){
        if(i > 0){
            if(hero[i-1] >= enemy[i]){
                hero[i-1] -= enemy[i];
                enemy[i] = 0;
            }else{
                enemy[i] -= hero[i-1];
                hero[i-1] = 0;
            }
        }
        if(i < n){
            if(hero[i] >= enemy[i]){
                hero[i] -= enemy[i];
                enemy[i] = 0;
            }else{
                enemy[i] -= hero[i];
                hero[i] = 0;
            }
        }
    }

    cout << sum - SUM(enemy) << endl;

    return 0;
}


Measured memory_bytes: 1792
import java.util.*;

public class Main {

    static int n;
    static int m;
    static int q;
    static int[] a;
    static int[] b;
    static int[] c;
    static int[] d;
    static int max = 0;
    static int[] f;

    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        Set<String> set = new HashSet<>();
        n = sc.nextInt();
        m = sc.nextInt();
        q = sc.nextInt();
        a = new int[q];
        b = new int[q];
        c = new int[q];
        d = new int[q];
        for(int i=0; i<q; i++) {
            a[i] = sc.nextInt()-1;
            b[i] = sc.nextInt()-1;
            c[i] = sc.nextInt();
            d[i] = sc.nextInt();
        }
        f = new int[n];
        dfs(0, 1);
        System.out.println(max);
    }

    static void dfs(int p, int last) {
        if(p == n) {
            int sum = 0;
            for(int i=0; i<q; i++) {
                if(f[b[i]]-f[a[i]] == c[i]) {
                    sum += d[i];
                }
            }
            max = Math.max(max, sum);
            return;
        }
        for(int i=last; i<=m; i++) {
            f[p] = i;
            dfs(p+1, i);
        }
    }
}

Measured memory_bytes: 37156
H,W = map(int,input().split())
C = [list(map(int,input().split())) for _ in range(10)]
A = [list(map(int,input().split())) for _ in range(H)]

dp = [float("INF")]*(10)
dp[1] = 0
cnt = 0
while cnt <= 10:
    cnt += 1
    for i in range(10):
        for j in range(10):
            dp[j] = min(dp[j],dp[i]+C[j][i])

cost = 0
for i in range(H):
    for j in range(W):
        if A[i][j] != -1:
            cost += dp[A[i][j]]
print(cost)

Measured memory_bytes: 74016
#include <iostream>
#include <stdio.h>
#include <cstring>
#include <math.h>
#include <algorithm>
#include <vector>
#include <string>
#include <stdlib.h>
#include <queue>
#include <stack>
#include <utility>
#include <fstream>
#include <random>
#include <map>
#include <unordered_map>
#include <cstdlib>
#define rep(i,n) for(int i=0;i<n;i++)
#define rrep(i,n) for(int i=n-1;i>=0;i--)
#define FOR(i,a,b) for(int i=a;i<b;i++)
#define ll long long
#define INF 1000000001
#define mod 1000000007
#define p pair<int,int>
int dx[4]={0,1,0,-1};
int dy[4]={1,0,-1,0};
using namespace std;
int POW(int x,int y){return int(pow(double(x),double(y)));}


int main(){
	int n;
	cin>>n;
	cout<<n/3<<endl;
	return 0;
}





Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < n; i++)
#define MOD 1000000007
#define MOD2 998244353
#define INF ((1<<30)-1)
#define LINF (1LL<<60)
#define EPS (1e-10)
typedef long long Int;
typedef pair<Int, Int> P;

int main() {
    int n;
    cin >> n;
    Int a[n];
    bool zero_contain = false;
    rep(i,n) {
        cin >> a[i];
        if (a[i] == 0) zero_contain = true;
    } 
    if (zero_contain) {
        cout << 0 << endl;
        return 0;
    }
    Int ans = 1;
    rep(i,n) {
        if (a[i] <= (Int)1e18 / ans) ans *= a[i];
        else {
            cout << -1 << endl;
            return 0;
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 4372
#include <stdio.h>

int main()
{
    int n, i, num[200005], min, max, benefit = 0;
    scanf("%d", &n);

    for (i = 0; i < n; i++)
    {
        scanf("%d", &num[i]);
    }
    min = num[0];
    max = -2000000000000005;
    for (i = 1; i < n; i++)
    {
        if (max < num[i] - min)
            max = num[i] - min;
        if (min > num[i])
            min = num[i];
    }

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

    return 0;
}



Measured memory_bytes: 2640
#include <bits/stdc++.h>
using namespace std;
#include <math.h>
#include <iomanip>
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

const int mod=1000000007;
const int INF=1001001001;

int main() {
  int N;
  cin>>N;
  vector<int>A(N);
  for(int i=0;i<N;i++){
    cin>>A[i];
  }
  sort(A.rbegin(),A.rend());
  int64_t ans=A[0];
  int cnt=N-2;
  for(int i=1;i<N;i++){
    for(int j=0;j<2;j++){
      if(cnt==0){cout<<ans<<endl;return 0;}
      ans+=A[i];
      cnt--;
    }
  }
  return 0;  
}

Measured memory_bytes: 4060
from collections import deque

K = int(input())

G = [None]*K
for i in range(K):
    G[i] = ((10*i % K, 0), ((i+1) % K, 1))
s = 1

dist = [10**9] * K
S = deque([s])
T = deque()
dist[s] = 0

d = 0
while S:
    while S:
        v = S.popleft()
        for w, c in G[v]:
            if d+c < dist[w]:
                dist[w] = d+c
                if c:
                    T.append(w)
                else:
                    S.append(w)
    S, T = T, S
    d += 1

print(dist[0]+1)

Measured memory_bytes: 30580
def main():
    N = int(input())
    march = [0] * 5
    for i in range(N):
        S = input()
        if S[0] == 'M':
            march[0] += 1
        elif S[0] == 'A':
            march[1] += 1
        elif S[0] == 'R':
            march[2] += 1
        elif S[0] == 'C':
            march[3] += 1
        elif S[0] == 'H':
            march[4] += 1
    march_sum = 0
    for i in range(0, 3):
        for j in range(i+1, 4):
            for k in range(j+1, 5):
                march_sum += march[i] * march[j] * march[k]
    print(march_sum)


if __name__ == '__main__':
    main()


Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
int main(){
    long long n, k, i, p[100000], pri=0;
    cin >> n >> k;
    for(i=0;i<n;i++){
        cin >> p[i];
    }
    sort(p, p+n);
    for(i=0;i<k;i++){
        pri+=p[i];
    }
    cout << pri <<endl;
    return 0;
}



Measured memory_bytes: 3572
#include "bits/stdc++.h"
using namespace std;
#define sim template < class c
#define ris return * this
#define dor > debug & operator <<
#define eni(x) sim > typename \
  enable_if<sizeof dud<c>(0) x 1, debug&>::type operator<<(c i) {
sim > struct rge { c b, e; };
sim > rge<c> range(c i, c j) { return rge<c>{i, j}; }
sim > auto dud(c* x) -> decltype(cerr << *x, 0);
sim > char dud(...);
struct debug {
#ifdef LOCAL
~debug() { cerr << endl; }
eni(!=) cerr << boolalpha << i; ris; }
eni(==) ris << range(begin(i), end(i)); }
sim, class b dor(pair < b, c > d) {
  ris << "(" << d.first << ", " << d.second << ")";
}
sim dor(rge<c> d) {
  *this << "[";
  for (auto it = d.b; it != d.e; ++it)
    *this << ", " + 2 * (it == d.b) << *it;
  ris << "]";
}
#else
sim dor(const c&) { ris; }
#endif
};
#define imie(...) " [" << #__VA_ARGS__ ": " << (__VA_ARGS__) << "] "

using ll = long long;
using ii = pair<int,int>;
using vi = vector<int>;
using vii = vector<ii>;

const int mod = 1e9+7;
const int oo = 1e8+7;


int main() {
    
    string a, b;
    getline(cin, a);
    getline(cin, b);

    vector<vector<pair<int,ii>>> dp(a.size()+1);
    for(int i = 0; i < (int)a.size()+1; ++i) {
        dp[i].assign((int)b.size()+1, make_pair(-oo, make_pair(0, 0)));
    }
    
    dp[0][0] = make_pair(0, make_pair(0, 0));
    
    for(int i = 0; i < (int)a.size(); ++i) {
        for(int j = 0; j < (int)b.size(); ++j) {
            if(a[i] == b[j] && dp[i+1][j+1].first < dp[i][j].first+1) {
                dp[i+1][j+1] = make_pair(dp[i][j].first+1, make_pair(i, j));
            }
            
            if(dp[i+1][j].first < dp[i][j].first) {
                dp[i+1][j] = make_pair(dp[i][j].first, make_pair(i, j));
            }
            
            if(dp[i][j+1].first < dp[i][j].first) {
                dp[i][j+1] = make_pair(dp[i][j].first, make_pair(i, j));
            }
        }
    }
    
    pair<int,ii> ans = make_pair(0, make_pair(0, 0));
    
    for(int i = 0; i < (int)a.size()+1; ++i) {
        for(int j = 0; j < (int)b.size()+1; ++j) {
            if(dp[i][j].first > ans.first) {
                ans.first = dp[i][j].first;
                ans.second = {i, j};
            }
        }
    }
    
    ii cur = ans.second;
    string s = "";
    
    while(cur.first > 0 && cur.second > 0) {
        int i = cur.first, j = cur.second;
        ii prev = dp[i][j].second;
        
        if(prev == make_pair(i-1, j-1)) {
            s += a[i-1];
        }
        cur = prev;
    }  
    
    reverse(s.begin(), s.end());
    cout << s << endl;
    
    return 0;
}




Measured memory_bytes: 105984
#include<stdio.h>
#include<math.h>
double a[100],b[100],c[100],r[100];
double g(double a,double b){return a*a+b*b;}
int cpcc(double X0,double Y0,double r0,double X1,double Y1,double r1,double s[2],double t[2]){
  double x1=X1-X0,y1=Y1-Y0,sx=y1,sy=-x1,a=x1*x1+y1*y1,b=r0*r0-r1*r1+a;
  double c=sqrt(a),d=b/(2*c),e=sqrt(r0*r0-b*b/(4.0*a));
  if(r0*r0-b*b/(4.0*a)<1e-9){
    s[0]=X0;
    s[1]=Y0;
    t[0]=X1;
    t[1]=Y1;
    return 1;
  }
  if(a>(r0+r1)*(r0+r1)+1e-9)return 0;
  //printf("!!%lf %lf %lf %lf\n",b*b/(4.0*a),r0*r0,sy,r0*r0-b*b/(4.0*a));
  s[0]=X0+(x1*d+sx*e)/c;
  s[1]=Y0+(y1*d+sy*e)/c;
  t[0]=X0+(x1*d-sx*e)/c;
  t[1]=Y0+(y1*d-sy*e)/c;
  return 1;
}
int n;
int f(){
  int i,j,k,m=0,c;
  double s[2],t[2],eps=1e-6;
  for(i=0;i<n;i++){
    for(j=i+1;j<n;j++){
      if(cpcc(a[i],b[i],r[i],a[j],b[j],r[j],s,t)){
	//printf("%lf %lf %lf %lf\n",s[0],s[1],t[0],t[1]);
	//printf("%lf\n",g(a[k]-s[0],b[k]-s[1])-(r[k]*r[k]+eps));
	for(k=c=0;k<n;k++){
	  if(hypot(a[k]-s[0],b[k]-s[1])-r[k]<eps)c++;
	}
	if(m<c)m=c;
	for(k=c=0;k<n;k++){
	  if(hypot(a[k]-s[0],b[k]-s[1])-r[k]<eps)c++;
	}
	if(m<c)m=c;
      }
    }
  }//printf("!!%d\n",m);
  return m;//printf("!!%d\n",m);
}
int main(){
  int i,j,k;
  scanf("%d %d",&n,&k);
  for(i=0;i<n;i++)scanf("%lf %lf %lf",&a[i],&b[i],&c[i]);
  if(n==1){
    printf("0\n");
    return 0;
  }
  double m,ok=1e9,ng=0;
  for(i=0;i<60;i++){//printf("%d\n",i);
    m=(ok+ng)/2;//printf("%lf\n",m);
    for(j=0;j<n;j++)r[j]=m/c[j];
    if(f()>=k)ok=m;
    else      ng=m;
  }
  printf("%.10lf\n",ok);
  return 0;
}
    
  


Measured memory_bytes: 128
#include <iostream>
#include <algorithm>
#include <iomanip>
#include <tuple>
#include <vector>

using namespace std;
typedef long long ll;

bool stless(tuple<int, int, int> a, tuple<int, int, int> b) {
    if (get<1>(a) != get<1>(b)) return get<1>(a) < get<1>(b);
    else return get<2>(a) < get<2>(b);
}

bool fless(tuple<int, int, int> a, tuple<int, int, int> b){
    return get<0>(a) < get<0>(b);
}

int main() {
    int N, M; cin >> N >> M;
    vector<tuple<int, int, int>> c(M);
    for (int i = 0; i < M; i++) {
        int p, y; cin >> p >> y;
        c[i] = make_tuple(i, p, y);
    }

    // 県 → 誕生年でソート 
    sort(c.begin(), c.end(), stless);
    // 誕生年を番号に書き換える
    get<2>(c[0]) = 1;
    for (int i = 1; i < M; i++) {
        if (get<1>(c[i]) == get<1>(c[i - 1])) get<2>(c[i]) = get<2>(c[i - 1]) + 1;
        else get<2>(c[i]) = 1;
    }

    // 市の番号でソート
    sort(c.begin(), c.end(), fless);
    for (int i = 0; i < M; i++) {
        cout << setfill('0') << right << setw(6) << get<1>(c[i])
             << setfill('0') << right << setw(6) << get<2>(c[i]) << endl;
    }

    return 0;
}

Measured memory_bytes: 2688
#include<cstdio>
#include<iostream>
#include<algorithm>
using namespace std;
typedef long long ll;
ll n,i,x,t,a,mi,mx,sum[200005],ans,c1,c2;
const ll inf=1e18;
ll query(ll a,ll b){return sum[b]-sum[a-1];}
ll aabs(ll a){return a<0?-a:a;}
void update()
{
	mi=min(query(1,c1),min(query(c1+1,t),min(query(t+1,c2),query(c2+1,n))));
	mx=max(query(1,c1),max(query(c1+1,t),max(query(t+1,c2),query(c2+1,n))));
	ans=min(ans,mx-mi);
}
int main()
{
	sum[0]=0;
	ans=inf;
	cin>>n;
	for(i=1;i<=n;i++)
	{
		cin>>x;
		sum[i]=sum[i-1]+x;
	}
	c1=1;t=2;
	for(c2=3;query(3,c2)<=query(c2+1,n);c2++);
	if(aabs(query(3,c2)-query(c2+1,n))>aabs(query(3,c2-1)-query(c2,n))||c2==n)c2--;
	update();
	for(t=3;t<n-1;t++)
	{
		for(;query(1,c1)<=query(c1+1,t);c1++);
		for(;query(t+1,c2)<=query(c2+1,n);c2++);
		if(aabs(query(1,c1)-query(c1+1,t))>aabs(query(1,c1-1)-query(c1,t))||c1==t)c1--;
		if(aabs(query(t+1,c2)-query(c2+1,n))>aabs(query(t+1,c2-1)-query(c2,n))||c2==n)c2--;
		update();	
	}
	cout<<ans;
	return 0;
}

Measured memory_bytes: 1792
s = input()
t = input()
c = 0
for i in range(len(s)-len(t)+1):
    cc = 0
    for j in range(len(t)):
        if t[j] == s[i+j]:
            cc += 1
    if cc >= c:
        c = cc
    cc = 0
print(len(t)-c)

Measured memory_bytes: 67396
#include<iostream>
#include<vector>
#include<algorithm>
using namespace std;
int N,K, dp[11][2001];
vector<int> t[11];
int main(){
  cin>>N>>K;
  for(int i=0;i<N;i++){
    int a,b;
    cin>>a>>b;
    t[b].push_back(a);
  }
  for(int i=1;i<=10;i++){
    sort(t[i].begin(),t[i].end());
    reverse(t[i].begin(),t[i].end());
    for(int j=1;j<=K;j++){
      int sum=0;
      for(int k=0;k<=(int)t[i].size();k++){
	if(j-k<0)break;
	if(k)sum+=t[i][k-1];
	dp[i][j]=max(dp[i][j],dp[i-1][j-k]+(k-1)*k+sum);
      }
    }
  }
  cout<<dp[10][K]<<endl;
  return 0;
}

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

int main(){
	int A,B,K;
	int count = 0;
	int ans;
	cin >> A >> B >> K;
	for(int i = A; count < K; i--){
		if(A%i == 0 && B%i == 0){
			count++;
			ans = i;
		}
	}
	cout << ans << endl;
	return 0;
}

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

int main() {
	int a,b,c;
	cin>>a>>b>>c;
	int x=c;
	int t=0;
	while(t<61){
		x=x-a;
		if(x<=0){
			cout<<(c+60*t)<<endl;
			return 0;
		}
		if(x<b){
			x=x+60-b;
			if(x==c){
				x=-1;
				cout<<x<<endl;
				return 0;
			}
			t++;
			continue;
		}else if (x==b){
			cout<<(c+60*t)<<endl;
			return 0;
		}else{
			x=x-b;
			if(x==c){
				x=-1;
				cout<<x<<endl;
				return 0;
			}
			continue;
		}
	}
	return 0;
}

Measured memory_bytes: 3124
#include<bits/stdc++.h>
#include<cmath>
#define pb push_back
#define ld long double
#define mp make_pair
#define vl vector<ll> 
#define vd vector<double>
#define vld vector<long double>
#define ll long long int
#define pl pair<ll, ll>
#define all(a) a.begin(), a.end()
#define forr(i, n) for(ll i=0; i<n; i++) 
#define forr1(i, n) for(ll i=1; i<=n; i++)
using namespace std;
const ld PI =3.1415926535897923846;
const ll MOD = 1e9+7;
void solve()
{
    ll n, k, c;
    cin>>n>>k>>c;
    string s;
    cin>>s;
    vl l, r;
    ll cur=0;
    forr(i, k)
    {
        while(s[cur]=='x')
        cur++;
        l.pb(cur);
        cur+=1+c;
    }
    cur=0;
    reverse(all(s));
    forr(i, k)
    {
        while(s[cur]=='x')
        cur++;
        r.pb(n-1-cur);
        cur+=1+c;
    }
    sort(all(r));
    forr(i, k)
    {
        if(l[i]==r[i])
        cout<<l[i]+1<<endl;
    }
}
int main()
{
    ll test=1;
    //cin>>test;
    while(test--)
        solve();
}


Measured memory_bytes: 8000
from collections import defaultdict
import sys

sys.setrecursionlimit(10**6)


N = int(input())
g = [set() for _ in range(N+1)]

for x, y in [map(int, input().split()) for _ in range(N-1)]:
    g[x].add(y)
    g[y].add(x)

M = 10**9 + 7


def dfs(u, p):
    w = 1
    b = 1
    for v in g[u]:
        if p == v:
            continue
        wn, bn = dfs(v, u)
        w *= wn + bn
        b *= wn
        w %= M
        b %= M
    return w, b
print(sum(dfs(1, -1))%M)


Measured memory_bytes: 123684
X, Y = map(int, input().split())

A = (2*Y - X)/3
B = (2*X - Y)/3
if (2*Y - X) % 3 != 0 or (2*X - Y) % 3 != 0 or A < 0 or B < 0:
    ans = 0
    print(ans)
else:
    A = int(A)
    B = int(B)
    p = 10**9 + 7
    def comb(n, r, p):
        num1, num2 = 1, 1
        for i in range(r):
            num1 *= n-i
            num2 *= i+1
            num1 %= p
            num2 %= p
        return int(num1 * pow(num2, p-2, p))
    ans = comb(A+B, A, p)
    print(ans % p)


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

int main() {
  int n;
  cin >> n;
  vector<long int> vecA(n);
  for (size_t i = 0; i < n; i++) {
    cin >> vecA.at(i);
  }
  sort(vecA.begin(),vecA.end());
  for (size_t i = 0; i < n - 1; i++) {
    if (vecA.at(i) == vecA.at(i + 1)) {
      cout << "NO" << endl;
      break;
    }
    if (i == n - 2) {
      cout << "YES" << endl;
    }
  }
  return 0;
}


Measured memory_bytes: 1792
#define DEB
#include<bits/stdc++.h>
#define REP(i,m) for(int i=0;i<(m);++i)
#define REPN(i,m,in) for(int i=(in);i<(m);++i)
#define ALL(t) (t).begin(),(t).end()
#define CLR(a) memset((a),0,sizeof(a))
#define pb push_back
#define mp make_pair
#define fr first
#define sc second

using namespace std;


#ifdef DEB
#define dump(x)  cerr << #x << " = " << (x) << endl
#define prl cerr<<"called:"<< __LINE__<<endl
#define dumpR(x) cerr<<"\x1b[31m"<<#x<<" = " <<(x)<<"\x1b[39m"<<endl
#define dumpY(x) cerr<<"\x1b[33m"<<#x<<" = " <<(x)<<"\x1b[39m"<<endl
#define dumpG(x) cerr<<"\x1b[32m"<<#x<<" = " <<(x)<<"\x1b[39m"<<endl
template<class T> void debug(T a,T b){ for(;a!=b;++a) cerr<<*a<<' ';cerr<<endl;}
#else
#define dump(x) ;
#define dumpR(x) ;
#define dumpY(x) ;
#define dumpG(x) ;
#define prl ;
template<class T> void debug(T a,T b){ ;}
#endif

template<class T> void chmin(T& a,const T& b) { if(a>b) a=b; }
template<class T> void chmax(T& a,const T& b) { if(a<b) a=b; }

typedef long long int lint;
typedef pair<int,int> pi;

namespace std{
  template<class S,class T>
  ostream &operator <<(ostream& out,const pair<S,T>& a){
    out<<'('<<a.fr<<','<<a.sc<<')';
    return out;
  }
}

const int INF=5e8;
int n;
char buf[505][505];
int main(){
  cin>>n;
  REP(i,n) scanf("%s",buf[i]);
  int blk=0;
  REP(i,n) REP(j,n) if(buf[i][j]=='#') ++blk;
  if(blk==0){
    puts("-1");
    return 0;
  }

  int fillC=0;
  REP(i,n){
    bool fail=false;
    REP(j,n) if(buf[j][i]=='.') fail=true;
    if(!fail) ++fillC;
  }

  int res=INF;
  REP(i,n){
    int blank=0;
    REP(j,n) if(buf[i][j]=='.') ++blank;
    int exist=0;
    REP(j,n) if(buf[j][i]=='#') exist=1;
    if(!exist){
      chmin(res,blank+1+n-fillC);
    }else{
      chmin(res,blank+n-fillC);
    }
  }
  cout<<res<<endl;
  return 0;
}





Measured memory_bytes: 512
//#pragma GCC optimize ("O3")
//#pragma GCC target ("sse4")

#include <iostream>

using namespace std;

#define sim template < class c
#define ris return * this
#define dor > debug & operator <<
#define eni(x) sim > typename \
  enable_if<sizeof dud<c>(0) x 1, debug&>::type operator<<(c i) {
sim > struct rge { c b, e; };
sim > rge<c> range(c i, c j) { return rge<c>{i, j}; }
sim > auto dud(c* x) -> decltype(cerr << *x, 0);
sim > char dud(...);
struct debug {
#ifdef LOCAL
~debug() { cerr << endl; }
eni(!=) cerr << boolalpha << i; ris; }
eni(==) ris << range(begin(i), end(i)); }
sim, class b dor(pair < b, c > d) {
  ris << "(" << d.first << ", " << d.second << ")";
}
sim dor(rge<c> d) {
  *this << "[";
  for (auto it = d.b; it != d.e; ++it)
    *this << ", " + 2 * (it == d.b) << *it;
  ris << "]";
}
#else
sim dor(const c&) { ris; }
#endif
};
#define imie(...) " [" << #__VA_ARGS__ ": " << (__VA_ARGS__) << "] "


// CHECK THE LIMITS
typedef long long ll;

const int MOD = 1000000007;
const ll INFLL = 1e18;
const int INF = 1e9;
const int NMAX = 1000001;

int gcd(int a, int b) {
  return b ? gcd(b, a%b) : a;
} 

int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
	int n;
	cin >> n;
	ll s= 0;
	for(int i = 1; i <= n; ++i)
	{
		for(int j = 1; j<= n; ++j)
		{
			for(int k = 1; k <= n; ++k)
			{
				s+=gcd(i,gcd(j,k));
			}
		}
	}
	cout << s;

    return 0;
}

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

int main() {
	int n; cin >> n;
	vector<int>a(n);
	ll ans = 0;
	map<int, int>am;
	for (int i = 0; i < n; i++) {
		int x;
		cin >> x;
		a.at(i) = x;
		ans += a.at(i);
		if (am.count(x))am.at(x)++;
		else am[x] = 1;
	}
	int q; cin >> q;
	for (int i = 0; i < q; i++) {
		int b, c;
		cin >> b >> c;
		if (!am.count(b)) {
			cout << ans << endl;
			continue;
		}
		ans += am.at(b) * (c - b);
		cout << ans << endl;
		if (am.count(c))am.at(c) += am.at(b);
		else am[c] = am.at(b);
		am.erase(b);
	}
}

Measured memory_bytes: 6548
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rrep(i, n) for (int i = 1; i < (int)(n+1); i++)
const long long INF = 1LL << 60;
int main(){
  ll N;
  cin>>N;
  vector<ll>p(10000000);
  ll f=0;
  ll cnt=0;
  rep(i,10000000){
    p[i]=0;
  }
    for(int i=1; i<1000000; i++){
        cnt+=i;
        p[i-1]++;
        if(N<=cnt){
            f=i;
          	break;
        }
    }
    cnt-=N;
  	if(cnt==0){
    }
  else{
  	p[cnt-1]=0;
  }
   
  rep(i,N){
      if(p[i]!=0){
          cout<<i+1<<endl;
      }
  }
}


Measured memory_bytes: 81392
def gcd(a, b):
    if (a == 0):
        return b
    elif (b == 0):
        return a
    elif (a == b):
        return a
    elif (a < b):
        return gcd(a, (b % a))
    else:
        return gcd(b, (a % b))


a, b, c, d = list(map(int, input().split()))
lcm = (c * d) // gcd(c, d)

b_c_cnt = b // c
b_d_cnt = b // d
b_lcm_cnt = b // lcm

b_cnt = b - (b_c_cnt + b_d_cnt) + b_lcm_cnt

a_c_cnt = a // c
a_d_cnt = a // d
a_lcm_cnt = a // lcm

a_cnt = a - (a_c_cnt + a_d_cnt) + a_lcm_cnt

if (a % c != 0 and a % d != 0):
    print(b_cnt - a_cnt + 1)
else:
    print(b_cnt - a_cnt)


Measured memory_bytes: 38384
#include <bits/stdc++.h>
using namespace std;
#define mod 1000000007
int main(void){
    // Your code here!
 int i,j,m,n;
 cin >> n >> m;
 string s[n];
 int a[n][m];
 for(i=0;i<n;i++)
 {
  for(j=0;j<m;j++)
  a[i][j]=0;
 }
 a[0][0]=1;
 for(i=0;i<n;i++)
 cin >> s[i];
 for(i=1;i<n;i++)
 {
  if(s[i][0]=='.')
  a[i][0]=a[i-1][0];
  else
  a[i][0]=0;
 }
 for(i=1;i<m;i++)
 {
  if(s[0][i]=='.')
  a[0][i]=a[0][i-1];
  else
  a[0][i]=0;
 }
 for(i=1;i<n;i++)
 {
  for(j=1;j<m;j++)
  {
   if(s[i][j]=='.')
   a[i][j]=((a[i-1][j]%mod)+(a[i][j-1]%mod))%mod;
   else
   a[i][j]=0;
  }
 }
 cout << a[n-1][m-1];
 return 0;
}

Measured memory_bytes: 5248
#include<bits/stdc++.h>
//typedef long long ll;
//#define ull       unsigned long long
#define int       long long
#define F           first
#define S           second
#define endl        "\n"//<<flush
#define eps         1e-6
#define lowbit(x)   (x&(-x))
#define PI          acos(-1.0)
#define inf         0x3f3f3f3f
#define MAXN        0x7fffffff
#define INF         0x3f3f3f3f3f3f3f3f
#define pa          pair<int,int>
#define ferma(a,b)  pow(a,b-2)
#define pb          push_back
#define all(x)      x.begin(),x.end()
#define memset(a,b) memset(a,b,sizeof(a));
#define IOS         ios::sync_with_stdio(false),cin.tie(0),cout.tie(0);
using namespace std;
void file()
{
#ifdef ONLINE_JUDGE
#else
    freopen("cin.txt","r",stdin);
    //  freopen("cout.txt","w",stdout);
#endif
}
signed main()
{
    IOS;
    //file();
    int n,a,b;
    cin>>n>>a>>b;
    int ans=n/(a+b)*a;
    cout<<ans+min(n%(a+b),a)<<endl;
    return 0;
}


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

Measured memory_bytes: 640
use std::io::prelude::*;

fn input<T>() -> T
where
    T: std::str::FromStr,
{
    let stdin = std::io::stdin();
    let token = stdin
        .lock()
        .bytes()
        .map(|c| c.unwrap() as char)
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect::<String>();
    token.parse().ok().unwrap()
}

fn main() {
    let n = input::<usize>();
    let k = input::<usize>();
    let h = {
        let mut temp = (0..n).map(|_| input()).collect::<Vec<i64>>();
        temp.sort();
        temp
    };

    let mut ans = std::i64::MAX;
    for i in 0..n - k + 1 {
        ans = std::cmp::min(ans, h[i + k - 1] - h[i]);
    }
    println!("{}", ans);
}


Measured memory_bytes: 4352
import std.stdio;
import std.string;
import std.format;
import std.conv;
import std.typecons;
import std.algorithm;
import std.functional;
import std.bigint;
import std.numeric;
import std.array;
import std.math;
import std.range;
import std.container;
import std.concurrency;
import std.traits;
import std.uni;
import std.regex;
import core.bitop : popcnt;
alias Generator = std.concurrency.Generator;

enum long INF = long.max/5;

void main() {
  enum string[] xs = ["SUN", "MON", "TUE", "WED", "THU", "FRI", "SAT"];
  string s;
  scanln(s);
  writeln(7 - xs.countUntil(s));
}

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


void times(alias fun)(long n) {
  // n.iota.each!(i => fun());
  foreach(i; 0..n) fun();
}
auto rep(alias fun, T = typeof(fun()))(long n) {
  // return n.iota.map!(i => fun()).array;
  T[] res = new T[n];
  foreach(ref e; res) e = fun();
  return res;
}

T ceil(T)(T x, T y) if (isIntegral!T || is(T == BigInt)) {
  // `(x+y-1)/y` will only work for positive numbers ...
  T t = x / y;
  if (y > 0 && t * y < x) t++;
  if (y < 0 && t * y > x) t++;
  return t;
}

T floor(T)(T x, T y) if (isIntegral!T || is(T == BigInt)) {
  T t = x / y;
  if (y > 0 && t * y > x) t--;
  if (y < 0 && t * y < x) t--;
  return t;
}

ref T ch(alias fun, T, S...)(ref T lhs, S rhs) {
  return lhs = fun(lhs, rhs);
}
unittest {
  long x = 1000;
  x.ch!min(2000);
  assert(x == 1000);
  x.ch!min(3, 2, 1);
  assert(x == 1);
  x.ch!max(100).ch!min(1000); // clamp
  assert(x == 100);
  x.ch!max(0).ch!min(10); // clamp
  assert(x == 10);
}

mixin template Constructor() {
  import std.traits : FieldNameTuple;
  this(Args...)(Args args) {
    // static foreach(i, v; args) {
    foreach(i, v; args) {
      mixin("this." ~ FieldNameTuple!(typeof(this))[i]) = v;
    }
  }
}

void scanln(Args...)(auto ref Args args) {
  enum sep = " ";
  enum n = Args.length;
  enum fmt = n.rep!(()=>"%s").join(sep);

  string line = readln.chomp;
  static if (__VERSION__ >= 2074) {
    line.formattedRead!fmt(args);
  } else {
    enum argsTemp = n.iota.map!(
      i => "&args[%d]".format(i)
    ).join(", ");
    mixin(
      "line.formattedRead(fmt, " ~ argsTemp ~ ");"
    );
  }
}

// fold was added in D 2.071.0
static if (__VERSION__ < 2071) {
  template fold(fun...) if (fun.length >= 1) {
    auto fold(R, S...)(R r, S seed) {
      static if (S.length < 2) {
        return reduce!fun(seed, r);
      } else {
        return reduce!fun(tuple(seed), r);
      }
    }
  }
}

// popcnt with ulongs was added in D 2.071.0
static if (__VERSION__ < 2071) {
  ulong popcnt(ulong x) {
    x = (x & 0x5555555555555555L) + (x>> 1 & 0x5555555555555555L);
    x = (x & 0x3333333333333333L) + (x>> 2 & 0x3333333333333333L);
    x = (x & 0x0f0f0f0f0f0f0f0fL) + (x>> 4 & 0x0f0f0f0f0f0f0f0fL);
    x = (x & 0x00ff00ff00ff00ffL) + (x>> 8 & 0x00ff00ff00ff00ffL);
    x = (x & 0x0000ffff0000ffffL) + (x>>16 & 0x0000ffff0000ffffL);
    x = (x & 0x00000000ffffffffL) + (x>>32 & 0x00000000ffffffffL);
    return x;
  }
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
vector<vector<string>>ans={
        {"-1"},                 //0
        {"-1"},                 //1
        {"-1"},                 //2
        {                       //3
         "..a",
                "..a",
                "bb."
        },
        {                       //4
         "abcc",
                "abdd",
                "eefg",
                "hhfg"
        },
        {                       //5
         "..abc",
                "..abc",
                "ddeff",
                "gge.h",
                "iijjh"
        },
        {                       //6
         "...abc",
                "...abc",
                "d.ee.f",
                "dgg..f",
                "hhi.jj",
                "kkill."
        },
        {
         "....abc",
                "....abc",
                "....def",
                "....def",
                "gghh..i",
                "jjkk..i",
                "llmmnn."
        }
};
int n;
void printA(vector<string>ans){
    for(auto x:ans){
        cout<<x<<endl;
    }
}
void manage(vector<string>ans,int prev){
    for(auto x:ans){
        cout<<string(prev,'.')
            <<x
            <<string(n-prev-x.length(),'.')
            <<endl;
    }
}
void rec(int n,int prev){
    if(n==0)return;
    if(n>9&&n!=13||n==6){
//        cout<<6<<" ";
        manage(ans[6],prev);
        rec(n-6,prev+6);

    }
    else if(n>8||n%5==0){
//        cout<<5<<" ";
        manage(ans[5],prev);
        rec(n-5,prev+5);
    }
    else{
//        cout<<"4"<<" ";
        manage(ans[4],prev);
        rec(n-4,prev+4);
    }
}
int main(){
    cin>>n;

    if(n<8)printA(ans[n]);
//    for(int i=9;i<30;i++){
//        rec(i,0);
//        cout<<endl;
//    }
    else rec(n,0);

}
//..abc
//..abc
//ddeff
//gge.h
//iijjh

//abcc
//abdd
//eefg
//hhfg

//..a
//..a
//bb.



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

class Solve{
private:
    int n_     = 0;
    int s_     = 0;
    int result = 0;
    void dfs(int num, int sum, int cnt);
public:
    Solve(int num, int sum);
    int getSolve();
};

Solve::Solve(int num, int sum){
    n_ = num;
    s_ = sum;
    
    Solve::dfs(0,0,0);
}

void Solve::dfs(int num, int sum, int cnt){
    if(sum == s_ && cnt == n_){
        result++;
        return;
    }
    if(num == 10 || cnt == n_){
        return;
    }
    
    Solve::dfs(num+1, sum+num, cnt+1);
    Solve::dfs(num+1, sum, cnt);
}

int Solve::getSolve(){
    return result;
}


int main(){
    int n, s = 0;
    while(cin >> n >> s){
        if(n == 0 && s == 0){
            break;
        }else{
            Solve solve(n, s);
            cout << solve.getSolve() << endl;
        }
    }
    return 0;
}

Measured memory_bytes: 3092
a,b,c = map(int,input().split())

if b-a+1 < c*2:
    #print('flag')
    for i in range(a,b+1):
        print(i)
else:
    for i in range(a,a+c):
        print(i)
    for i in range(b-c+1,b+1):
        print(i)

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

int main()
{
  deque<char> s;
  bool is_flipped = false;
  string original_s;
  int q;
  cin >> original_s >> q;
  for (char c : original_s) {
    s.push_back(c);
  }
  for (int i = 0; i < q; i++) {
    int t;
    cin >> t;
    if (t == 1) {
      is_flipped = !is_flipped;
    } else {
      int f;
      char c;
      cin >> f >> c;
      if (f == 1) {
        if (is_flipped) {
          s.push_back(c);
        } else {
          s.push_front(c);
        }
      } else {
        if (is_flipped) {
          s.push_front(c);
        } else {
          s.push_back(c);
        }
      }
    }
  }
  if (is_flipped) {
    for (auto it = s.rbegin(); it != s.rend(); it++) {
      cout << *it;
    }
  } else {
    for (auto it = s.begin(); it != s.end(); it++) {
      cout << *it;
    }
  }
  cout << '\n';
  return 0;
}


Measured memory_bytes: 896
import java.util.*;

public class Main{
	public static void main(String[]args){
		Scanner s = new Scanner(System.in);
		int X = s.nextInt();
		int T = (17+4+5+X) % 7;
		switch(T){
			case 1:
				System.out.println("sun");
				break;
			case 2:
				System.out.println("mon");
				break;
			case 3:
				System.out.println("tue");
				break;
			case 4:
				System.out.println("wed");
				break;
			case 5:
				System.out.println("thu");
				break;
			case 6:
				System.out.println("fri");
				break;
			case 0:
				System.out.println("sat");
				break;
		}
	}
}


Measured memory_bytes: 26236
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <cmath>
#include <queue>
#include <map>
#include <set>
#include <bitset>
#include <functional>
using namespace std;

typedef long long ll;


int main() {
	string s; cin >> s;
	s[3] = '8';
	cout << s << endl;
	return 0;
}


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

int main() {
    string S; cin >> S;
    int N = S.size();
    int ans = 1;
    char t = S[0];
    rep(i, 1, N) {
        if(t == S[i]) {
            t = 'A';
            i++;
            if(i != N) ans++;
        }
        else {
            t = S[i];
            ans++;
        }
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
typedef pair<int,int> P;
typedef long long ll;
typedef long double ld;
const int inf=1e9+7;
const ll longinf=1LL<<60;
#define REP(i,m,n) for(int i=(int)(m) ; i < (int) (n) ; ++i )
#define rep(i,n) REP(i,0,n)
#define F first
#define S second

const int mx=200010;
const ll mod=1e9+7;

int main(){
  ll n,k;
  cin >> n >> k;
  vector<int> a(n+1);
  rep(i,n){
    cin >> a[i+1];
  }
  int pos = 1;
  while(k){
    if(k&1) pos = a[pos];
    vector<int> na(n+1);
    REP(i,1,n+1){
      na[i] = a[a[i]];
    }
    swap(a,na);
    k >>= 1;
  }
  int ans = pos;
  cout << ans << endl;
  return 0;
}

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


int main()
{
  int n = 0;
  vector<long long> a(100010);

  cin >> n;

  for (int i = 0; i < n; i++)
  {
    /* code */
    cin >> a.at(i);
  }

  int zero = 0;
  for (int i = 0; i < n; i++)
  {
    if(a.at(i)==0)
      zero++;
  }
  if(zero > 0){
    cout << 0 << endl;
    return 0;
  }

  long long ans = 1;
  for (int i = 0; i < n;i++){
    if (a.at(i) <= 1000000000000000000 / ans)
    {
      ans *= a.at(i);
    }else
    {
      ans = -1;
      cout << ans << endl;
      return 0;
    }
  }

  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 3848
x = int(input())
arr = []
for i in range(x):
  arr.append(list(map(int,input().split())))
  
dp =[[0,0,0] for i in range(len(arr))]
dp[0][0],dp[0][1],dp[0][2] = arr[0][0],arr[0][1],arr[0][2]

for i in range(1,len(arr)):
  dp[i][0] += arr[i][0]+max(dp[i-1][1],dp[i-1][2])
  dp[i][1] += arr[i][1]+max(dp[i-1][0],dp[i-1][2])
  dp[i][2] += arr[i][2]+max(dp[i-1][0],dp[i-1][1])
print(max(dp[-1]))

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

using namespace std;

#define rep(i,n) for(int i=0;i<(n);++i)
#define out(S) cout<<(S)<<endl;
#define ShowAll(collection) for(auto i:collection){out(i);}
#define beginend(v) v.begin(),v.end()
#define Foreach(item,collection) for(auto item : collection)

using pii=pair<int,int>;
using vb=vector<bool>;
using ll=long long;
using ull=unsigned long long;
using vi=vector<int>;
using vvi=vector<vi>;
using vvc=vector<vector<char>>;
using ti3=tuple<int,int,int>;
using ulong=unsigned long;
template<typename T> void removeAt(vector<T>& v, int index) { v.erase(v.begin() + index); }
#define OCB(c) (c&1)|(c&2)<<2|(c&4)<<4|(c&8)<<6|(c&16)<<8|(c&32)<<10|(c&64)<<12|(c&128)<<14

int main(){
    string s,t;
    cin >> s>>t;
    sort(beginend(s));
    sort(beginend(t));
    reverse(beginend(t));

    out(s<t?"Yes":"No")
}


Measured memory_bytes: 256
S = list(str(input()))
A = S[0]
B = S[1]
C = S[2]
D = S[3]
a = int(A)
b = int(B)
c = int(C)
d = int(D)
if a+b+c+d == 7:
    print(A+"+"+B+"+"+C+"+"+D+"=7")
elif a-b+c+d == 7:
    print(A+"-"+B+"+"+C+"+"+D+"=7")
elif a+b-c+d == 7:
    print(A+"+"+B+"-"+C+"+"+D+"=7")
elif a+b+c-d == 7:
    print(A+"+"+B+"+"+C+"-"+D+"=7")
elif a-b-c+d == 7:
    print(A+"-"+B+"-"+C+"+"+D+"=7")
elif a-b+c-d == 7:
    print(A+"-"+B+"+"+C+"-"+D+"=7")
elif a+b-c-d == 7:
    print(A+"+"+B+"-"+C+"-"+D+"=7")
elif a-b-c-d == 7:
    print(A+"-"+B+"-"+C+"-"+D+"=7")


Measured memory_bytes: 3316
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>

using namespace std;

int main(){
    int max_num;
    vector < vector < int > > arr (26);
    cin >> max_num;
    for(int j=0;j<max_num;j++){
        string po;
        cin >> po;
        vector<int> l(0,26);
        for(int i=0;i<26;i++) arr[i].push_back(0);//要素を追加
        for(int i=0;i<po.length();i++){
            int cn = (int)po[i]-97;
            arr[cn][j]++;
        }
    }
    for(int i=0;i<26;i++){
        int min = *min_element(arr[i].begin(), arr[i].end());
        for(int j=0;j < min;j++){
            cout << (char)(i+97);
        }
    }
    cout <<"\n";
    return 0;
}

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

int main() {
    int a,b,c;
    cin >> a >> b >> c;
    int x = max(max(a,b),c);
    int y = min(min(a,b),c);
    cout << x-y << endl;
 }

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

#define SAFE_DELETE( x ) { if ( x ){ delete x; x = NULL; } }

struct tCell{
	tCell() : num( 0 ), times( 0 ), prev( NULL ), next( NULL ){}

	int num, times;
	tCell *prev, *next;
};

class MyArray{
public:
	MyArray() : mSize( 0 ), head( NULL ), tail( NULL ){
		head = new tCell;
		tail = new tCell;
		head->next = tail;
		tail->prev = head;
	}
	~MyArray(){
		init();
		SAFE_DELETE( tail );
		SAFE_DELETE( head );
	}

	void init(){
		for ( int i = mSize; i > 0; --i ){
			tCell* cell = tail->prev;
			cell->prev->next = cell->next;
			cell->next->prev = cell->prev;
			SAFE_DELETE( cell );
		}
		mSize = 0;
	}
	void store( int n, int t = 0 ){
		tCell* cell = head;
		int index = find( n );
		if ( index ){
			for ( int i = 0; i < index; ++i ){
				cell = cell->next;
			}
			++cell->times;
		}else{
			tCell* cell = new tCell;
			cell->num = n;
			if ( t ) cell->times = t;
			else ++cell->times;
			cell->prev = tail->prev;
			cell->next = tail;
			cell->prev->next = cell;
			cell->next->prev = cell;
			++mSize;
		}
	}
	int find( int ref ){
		tCell* cell = head;
		for ( int i = 0; i < mSize; ++i ){
			cell = cell->next;
			if ( cell->num == ref ){
				return i+1;
			}
		}
		return 0;
	}
	void comp( MyArray& a1, MyArray& a2 ){
		init();
		for ( int i = 0; i < a1.size(); ++i ){
			for ( int j = 0; j < a2.size(); ++j ){
				if ( a1[ i ].num == a2[ j ].num ){
					store( a1[ i ].num, a1[ i ].times+a2[ j ].times );
				}
			}
		}
		for ( int i = 0; i < mSize-1; ++i ){
			tCell* cell = head;
			for ( int j = 0; j < mSize-1-i; ++j ){
				cell = cell->next;
				if ( cell->num > cell->next->num ){
					tCell* prev = cell->prev;
					tCell* next = cell->next;
					tCell* nNext = cell->next->next;
					prev->next = next;
					cell->prev = next;
					cell->next = nNext;
					next->prev = prev;
					next->next = cell;
					nNext->prev = cell;
					cell = cell->prev;
				}
			}
		}
	}
	int size(){ return mSize; }

	tCell operator[]( int index ){
		tCell* cell = head->next;
		for ( int i = 0; i < index; ++i ){
			cell = cell->next;
		}
		return *cell;
	}

private:
	int mSize;
	tCell *head, *tail;
};

int main(){
	int num, day;
	char c;
	string s;
	MyArray list1, list2, result;

	while ( getline( cin, s ) && s.size() ){
		istringstream iss( s );
		iss >> num >> c >> day;
		list1.store( num );
	}

	while ( getline( cin, s ) && s.size() ){
		istringstream iss( s );
		iss >> num >> c >> day;
		list2.store( num );
	}

	result.comp( list1, list2 );

	for ( int i = 0; i < result.size(); ++i ){
		cout << result[ i ].num << " " << result[ i ].times << endl;
	}

	return 0;
}

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

namespace NotFounds
{
    public class Program
    {
        public static void Main(string[] args)
        {
            new Program().Solve();
        }

        public void Solve()
        {
            var cin = new MyInputStream();
            var a = cin.Read();
            var b = cin.Read();
            a = a.PadLeft(Max(a.Length, b.Length), '0');
            b = b.PadLeft(Max(a.Length, b.Length), '0');

            Console.Error.WriteLine(a);
            Console.Error.WriteLine(b);


            for (int i = 0; i < a.Length; ++i)
            {
                if (a[i] == b[i]) { }
                else if (a[i] > b[i])
                {
                    WriteLine("GREATER");
                    return;
                }
                else
                {
                    WriteLine("LESS");
                    return;
                }
            }
            WriteLine("EQUAL");
        }
    }

    public class MyInputStream
    {
        private char separator = ' ';
        private Queue<string> inputStream;
        public MyInputStream(char separator = ' ')
        {
            this.separator = separator;
            inputStream = new Queue<string>();
        }

        public string Read()
        {
            if (inputStream.Count != 0) return inputStream.Dequeue();
            string[] tmp = Console.ReadLine().Trim().Split(separator);
            for (int i = 0; i < tmp.Length; i++)
            {
                inputStream.Enqueue(tmp[i]);
            }
            return inputStream.Dequeue();
        }
        public string ReadLine() => Console.ReadLine();
        public int ReadInt() => int.Parse(Read());
        public long ReadLong() => long.Parse(Read());
        public double ReadDouble() => double.Parse(Read());
        public string r() => Read();
        public int ri() => ReadInt();
        public long rl() => ReadLong();
        public double rd() => ReadDouble();
    }
}

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

#define int             long long int
#define ld              long double
#define ff              first
#define ss              second
#define mp              make_pair
#define pb              push_back
#define endl            "\n"

#define si              set <int>
#define vi              vector <int>
#define pii             pair <int, int>
#define vpii            vector <pii>
#define mii             map <int, int>
#define que_max         priority_queue <int>
#define que_min         priority_queue <int, vi, greater<int>>

#define loop(i,s,e)     for(int i=s;i<e;i++)
#define rloop(i,e,s)    for(int i=e;i>=s;i--)
#define mset(a,f)       memset(a,f,sizeof(a))


#define M               1000000007
#define sz(x)           ((int) x.size())
#define all(p)          p.begin(), p.end()

#define bug(...)        __f (#__VA_ARGS__, __VA_ARGS__)
#define print(a)        for (auto x : a) cout << x << " "; cout << endl
#define Print(a,x,y)    for (int i=x; i<y; i++) cout<< a[i]<< " "; cout << endl

inline int power(int a, int b)
{
	int x = 1;
	while (b)
	{
		if (b & 1) x *= a;
		a *= a;
		b >>= 1;
	}
	return x;
}

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

const int N = 3e5 + 7;
vector <vi > adj;
bool vis[N];
int dp[1003][1003];


void solve()
{
	int n;
	cin >> n;
	double p[n + 1];
	double dp[n + 1][n + 1];

	for (int i = 1; i <= n; i++)
		cin >> p[i];


	memset(dp, 0, sizeof(dp));
	dp[0][0] = 1;

	loop(i, 1, n + 1)
	{
		double head = p[i], tail = 1 - p[i];

		dp[0][i] = tail * dp[0][i - 1];
		//bug(dp[0][i], i, dp[0][i - 1], tail, head, p[i]);

		loop(heads, 1, i + 1)
		{
			dp[heads][i] = head * dp[heads - 1][i - 1] + tail * dp[heads][i - 1];
			//bug(dp[heads][i]);
		}
	}

	double ans = 0;
	for (int i = n / 2 + 1; i <= n; i++)
		ans += dp[i][n];

	cout << setprecision(9) << ans;

	return;
}

int32_t main()
{
	ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);


	cout << setprecision(9) << fixed;

	int t = 1;
	//cin >> t;
	while (t--)
	{
		solve();
	}


	return 0;
}

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

int main() {
  string s;
  cin >> s;
  string k1 = "", k2 = "";
  int n = s.size();
  for (int i = 0; i < n; i++) {
    if (i % 2 == 0) {
      k1 += "1";
      k2 += "0";
    } else {
      k1 += "0";
      k2 += "1";
    }
  }

  string s3 = s[0] == '0' ? k2 : k1;
  int cnt   = 0;
  for (int i = 0; i < n; i++) {
    if (s[i] != s3[i]) cnt++;
  }
  cout << cnt << endl;
}

Measured memory_bytes: 768