akhauriyash/Code-Regression huggingface dataset:
#include "bits/stdc++.h"

using namespace std;

int main(void) {
  int n; cin >> n;
  int innersum = 0;
  int headB = 0;
  int headA = 0;
  int both = 0;
  for (int i = 0; i < n; i++) {
    string s;
    cin >> s;

    if (s[0] == 'B' && s[s.length() - 1] == 'A') {
      both++;
    }
    if (s[s.length() - 1] == 'A') {
      headA++;
    }
    if (s[0] == 'B') {
      headB++;
    }

    for (int j = 0; j < s.length() - 1; j++) {
      if (s[j] == 'A' && s[j + 1] == 'B') {
        innersum++;
      }
    }
  }

  int res = innersum;

  res += min(headA, headB);
  if (headA == both && headB == both && 0 < headB) res--;
  //cout << headA << "," << headB << "," << both << endl; 
  cout << res << endl;
  return 0;
}


Measured memory_bytes: 384
def solve():
  N = int(input())
  S = input()
  red = [S.count('R')]*(N+2)
  white = [0]*(N+2)
  ans = float('inf')
  for i in range(N):
    red[i+2] = red[i+1]
    white[i+1] = white[i]
    if S[i]=='W':
      white[i+1] += 1
    if S[i]=='R':
      red[i+2] -= 1
  for i in range(N+2):
    if red[i]==white[i]:
      return red[i]
    if white[i]>red[i]:
      return red[i]
  return ans
print(solve())

Measured memory_bytes: 18180
#!/usr/bin/env python3

import sys
import math
from bisect import bisect_right as br
from bisect import bisect_left as bl
sys.setrecursionlimit(2147483647)
from heapq import heappush, heappop,heappushpop
from collections import defaultdict
from itertools import accumulate
from collections import Counter
from collections import deque
from operator import itemgetter
from itertools import permutations
mod = 10**9 + 7
inf = float('inf')
def I(): return int(sys.stdin.readline())
def LI(): return list(map(int,sys.stdin.readline().split()))

s = input()
t = input()
n = len(s)
m = len(t)
ans = 0
for i in range(n-m+1):
    cnt = 0
    for j in range(m):
        if s[i+j] == t[j]:
            cnt += 1
    ans = max(ans, cnt)
print(m - ans)

Measured memory_bytes: 68068
#include <algorithm>
#include <cstring>
#include <iostream>
#include <vector>
#include <cmath>
#include <math.h>
using namespace std;

typedef long long int ll; 
typedef pair<int,int> Pii;
typedef pair<ll,ll> Pll;


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

    sort(A.begin(),A.end());

    for (size_t i = 1; i < N; i++)
    {
        int pre = A[i-1];
        int next = A[i];
        if(pre == next){
            cout << "NO";
            goto END;
        }
    }
    cout << "YES";
    END:
    return 0;
}

Measured memory_bytes: 1024
#include<bits/stdc++.h>
#define rep(i,n) for(int i = 0;i < (n);++i)
#define reps(i,n) for(int i = 1;i <= (n);++i)
using namespace std;
int main(){
  int k,n;
  cin >> n >> k;
  if(k == 1) cout << 0 << '\n';
  else cout << n - k << '\n';
  return 0;
}

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

int N;

void add(int a, int w, vector<long long> &bit) 
{
    for (int x = a; x <= N; x += x & -x) bit[x] += w;
}
long long sum(int a, vector<long long> &bit) {
    long long ret = 0;
    for (int x = a; x > 0; x -= x & -x) ret += bit[x];
    return ret;
}

int main(void)
{
	cin >> N;
	int q;
	cin >> q;
	vector<long long> BIT(N + 1, 0);
	for (int i = 1; i <= N; i++)
	{
		int x;
		cin >> x;
		add(i, x, BIT);
	}
	for (int i = 0; i < q; i++)
	{
		int t, a, b;
		cin >> t >> a >> b;
		if (t == 0) add(a + 1, b, BIT);
		if (t == 1) cout << sum(b, BIT) - sum(a, BIT) << endl;
	}
}

Measured memory_bytes: 8232
/*
  AUTHOR:SOURABH
  CREATED:02:09:20
*/
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

#define ordered_set tree<ll , null_type, less< ll >, rb_tree_tag, tree_order_statistics_node_update>
#define ll long long int
#define ld long double
#define fi first
#define se second
#define pb push_back
#define pob pop_back
#define W while
#define fn(i,x) for(i=0;i<x;i++)
#define fs(i,s,x) for(i=s;i<x;i++)
#define fr(i,x) for(i=x;i>=0;i--)
#define fit(it,s) for(it=s.begin();it!=s.end();it++)
#define mp make_pair
#define pii pair<int,int>
#define pll pair<ll,ll>
#define vii vector<int>
#define vll vector<ll>
#define mii map<int,int>
#define mll map<ll,ll>
#define mod 1000000007
#define MAXN 10000001
#define M 32

using namespace std;
using namespace __gnu_pbds;

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

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

    ll t,n,i,curr,ans;
    t=1;
    //cin>>t;
    W(t--)
    {
        cin>>n;
        vll a(n);
        fn(i,n)
        cin>>a[i];
        ans=0;curr=0;
        fn(i,n-1)
        {
            if(a[i]>=a[i+1])
            {curr++;ans=max(ans,curr);}
            else
            curr=0;
        }
        cout<<ans;
    }
    return 0;
}



Measured memory_bytes: 3964
/*

 */

#include<bits/stdc++.h>

using namespace std;
const int maxN = 300;
const int INF = 1e8;
 
int n,m,st,fn;
int cap[maxN][maxN],f[maxN][maxN],d[maxN],ptr[maxN];
vector<int> g[maxN];

void input()
{
  cin>>n>>m;
  //cin>>st>>fn;
  st=1;
  fn=n;
  for(int i=1;i<=m;i++)
    {
      int k1,k2,val;
      
      cin>>k1>>k2>>val;
            k1++;k2++;
      g[k1].push_back(k2);
      g[k2].push_back(k1);

      cap[k1][k2]+=val;
      //cap[k2][k1]+=val;
    }
}
bool bfs() {
  //int qh=0, qt=0;
  queue<int> q;
  //q[qt++] = st;
  q.push(st);
  memset (d, -1, (n+10) * sizeof d[0]);
  d[st] = 0;
  while (q.size()>0) {
    int v = q.front();
    q.pop();
    //for (int to=1; to<=n; ++to)
    for(auto to:g[v])
      if (d[to] == -1 && f[v][to] < cap[v][to]) {
	q.push(to);
	d[to] = d[v] + 1;
      }
  }
  return d[fn] != -1;
}
 
int dfs (int v, int flow) {
  if (!flow)  return 0;
  if (v == fn)  return flow;
  for (int & to=ptr[v]; to<=n; ++to) {
    if (d[to] != d[v] + 1)  continue;
    int pushed = dfs (to, min (flow, cap[v][to] - f[v][to]));
    if (pushed) {
      f[v][to] += pushed;
      f[to][v] -= pushed;
      return pushed;
    }
  }
  return 0;
}
 
int dinic() {
  int flow = 0;
  for (;;) {
    if (!bfs())  break;
    memset (ptr, 0, (n+10) * sizeof ptr[0]);
    while (int pushed = dfs (st, INF))
      flow += pushed;
  }
  return flow;
}
int main()
{
  input();
  int MaxFlow=dinic();
  cout<<MaxFlow<<endl;
  return 0;
}

Measured memory_bytes: 3356
//#pragma GCC optimize ("-O3","unroll-loops")
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<queue>
#include<map>
#include<math.h>
#include<iomanip>
#include<set>
#include<numeric>
#include<cstring>
#include<cstdio>
#include<functional>
#include<bitset>
#include<limits.h>
#include<cassert>
#include<iterator>
#include<complex>
#include<stack>


#define REP(i, n) for(int i = 0;i < n;i++)
#define REPR(i, n) for(int i = n;i >= 0;i--)
#define FOR(i, m, n) for(int i = m;i < n;i++)
#define FORR(i, m, n) for(int i = m;i >= n;i--)
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
#define REVERSE(v,n) reverse(v,v+n);
#define VREVERSE(v) reverse(v.begin(), v.end());
#define ll long long
#define pb(a) push_back(a)
#define m0(x) memset(x,0,sizeof(x))
#define print(x) cout<<x<<'\n';
#define pe(x) cout<<x<<" ";
#define lb(v,n) lower_bound(v.begin(), v.end(), n);
#define ub(v,n) upper_bound(v.begin(), v.end(), n);
#define int long long
#define all(x) (x).begin(), (x).end()
//#define double long double

using namespace std;

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

const int MOD = 1e9 + 7;
const ll INF = 1e17;
const int INT_INF = 1e9;
const double pi = acos(-1);
const double EPS = 1e-10;
typedef pair<int, int>P;
const int MAX = 200020;

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


	int N; cin >> N;
	double ans;
	if (N % 2 == 0) {
		ans = (N/2 /(double)N);
	}
	else ans = (N/2+1) / (double)N;
	cout << setprecision(10) << ans << endl;
}


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

using namespace std;

int main() {
	int n;
	cin >> n;
	long long int lef, rig;
	cin >> lef >> rig;

	for (int i = 1; i < n; i++) {
		long long int t, a;
		cin >> t >> a;
		if (lef <= t && rig <= a) {
			lef = t;
			rig = a;
		}
		else {
			long long int add = max((lef % t == 0) ? lef / t : lef / t + 1,
				          (rig % a == 0) ? rig / a : rig / a + 1);
			lef = t * add;
			rig = a * add;
		}
	}

	cout << lef + rig << endl;


	return 0;
}

Measured memory_bytes: 256
import java.util.*;

public class Main {

	public static void main(String[] args) {
		Scanner in = new Scanner(System.in);
		
		long n = in.nextLong();
		long m = in.nextLong();
		
		long answer = 0;
		
		if (m >= n * 2) {
			answer = n + (m - n * 2) / 4;
		} else {
			answer = m / 2;
		}
		
		System.out.println(answer);
	}
}

Measured memory_bytes: 22868
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define pb push_back
#define sb __builtin_popcount
#define MOD (ll)1000000007

vector<ll> v;

bool sieves[200000];

void sof()
{
    memset(sieves, 0, sizeof(sieves));
    for (ll i = 2; i < 200000ll; i++)
    {
        if (sieves[i] == 0)
        {
            v.push_back(i);
            for (ll j = i * i; j < 200000ll; j += i)
            {
                sieves[j] = 1;
            }
        }
    }
}

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    sof();
    ll t;
    cin >> t;
    cout << *lower_bound(v.begin(), v.end(), t) << endl;
}

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

s = sorted(ab, key=lambda x:x[1])

time = 0
for i in range(n):
    time += s[i][0]
    if time > s[i][1]:
        print('No')
        exit()
print('Yes')

Measured memory_bytes: 55264
import std.functional,
       std.algorithm,
       std.bigint,
       std.string,
       std.traits,
       std.array,
       std.range,
       std.stdio,
       std.conv;

void main() {
  string s = readln.chomp;
  int c;

  foreach (i; 0..s.length-1) {
    if (s[i] != s[i + 1]) {
      c++;
    }
  }

  writeln(c);
}


Measured memory_bytes: 2556
#include <iostream>
#include <string>
#include <map>
#include <vector>
#include <bitset>
#include <iomanip>
#include <deque>
#include <tuple>
#include <algorithm>

using namespace std;

int main()
{
    int x, a, b;

    cin >> x >> a >> b;

    if (a >= b) {
        cout << "delicious" << endl;
    }
    else if (x+a >= b) {
        cout << "safe" << endl;
    }
    else {
        cout << "dangerous" << endl;
    }
}


Measured memory_bytes: 256
#include <stdio.h>

int main(void)
{
    int n, b, a[9];

    for (int i=0; i<9; i++) {
        scanf("%d", &a[i]);
    }

    scanf("%d", &n);

    for (int i=0; i<n; i++) {
        scanf("%d", &b);

        for (int j=0; j<9; j++) {
            if (a[j]==b) {
                a[j] = 0;
                break;
            }
        }
    }

    // check
    if (a[0]+a[1]+a[2]==0 ||
        a[3]+a[4]+a[5]==0 ||
        a[6]+a[7]+a[8]==0 ||
        a[0]+a[3]+a[6]==0 ||
        a[1]+a[4]+a[7]==0 ||
        a[2]+a[5]+a[8]==0 ||
        a[0]+a[4]+a[8]==0 ||
        a[2]+a[4]+a[6]==0)
        printf("Yes\n");
    else
        printf("No\n");

    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
 
using namespace std;
 
int main()
{
  	int H,kind_num,A;
  	int sum = 0;
    scanf("%d %d",&H,&kind_num);
	for(int i = 0;i < kind_num;i++){
	    scanf("%d",&A);
	    sum += A;
	}
  	if(sum >= H) printf("Yes\n");
  	else printf("No\n");
    return 0;
}

Measured memory_bytes: 256
#define _CRT_SECURE_NO_WARNINGS
#define _USE_MATH_DEFINES
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <cstdlib>
#include <algorithm>
#include <string>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <unordered_map>
#include <functional>
#include <utility>
#include <tuple>
#include <cctype>
#include <bitset>
#include <complex>
#include <cmath>
#include <array>
#include <numeric>
using namespace std;
#define INF 0x3f3f3f3f
#define INFLL 0x3f3f3f3f3f3f3f3fLL
//#define MOD 998244353
#define MOD 1000000007
#define mp make_pair
#define mt make_tuple
#define pb push_back
#define eb emplace_back
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef pair<int, int> pint;
typedef pair<ll,ll> pll;
typedef tuple<int,int,int> tint;
typedef vector<int> vint;
typedef vector<ll> vll;
typedef vector<ull> vull;
typedef vector<pint> vpint;
int dx[8]={0,0,-1,1,1,1,-1,-1};
int dy[8]={-1,1,0,0,1,-1,1,-1};
const int SIZE=50;
//↑templete
signed main(){
	int N;
	cin>>N;
	vll A;
	for(int i=0;i<N;i++){
		ll a;
		cin>>a;
		A.pb(a);
	}
	ll plu=0, And=0;
	for(int i=0;i<N;i++){
		(plu+=(A[i]%MOD)*(N-1))%=MOD;
	}
	for(int i=0;i<61;i++){
		//i bit目が立っている数字の数を数える
		ll cnt=0;
		for(ll a:A)
			if((a>>i)&1)
				cnt++;
		ll temp=cnt*(cnt-1)/2%MOD;
		temp%=MOD;
		temp*=(2LL<<i)%MOD;
		temp%=MOD;
		And+=temp;
		//cout<<i<<" "<<temp<<endl;
		And%=MOD;
		//(And+=(cnt)*(cnt-1)/2%MOD*((1LL<<i)%MOD)%MOD)%=MOD;
	}
	//(And*=2)%=MOD;
	//cout<<plu<<" "<<And<<endl;
	cout<<(plu+MOD-And)%MOD<<endl;
	return 0;
}

Measured memory_bytes: 6256
import sys
MAX_INT = int(10e10)
MIN_INT = -MAX_INT
mod = 1000000007
def IL(): return list(map(int,input().split()))
def SL(): return input().split()
def I(): return int(sys.stdin.readline())
def S(): return input()

def cnt(l):
  num = 1
  for i in l:
    if i != s:
      num *= (i+1)
  return num

N = I()
s = S()

dic = {"a":0,"b":0,"c":0,"d":0,"e":0,"f":0,"g":0,"h":0,"i":0,"j":0,"k":0,\
  "l":0,"m":0,"n":0,"o":0,"p":0,"q":0,"r":0,"s":0,"t":0,"u":0,"v":0,"w":0,\
    "x":0,"y":0,"z":0,}

ans = 0
for i in range(N):
  ans += cnt(list(dic.values()))//(dic[s[i]]+1)
  dic[s[i]] += 1

print(ans%mod)

Measured memory_bytes: 3188
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define FOR(i, s, e) for (int i = (int)(s); i <= (int)(e); i++)
#define printYesNo(is_ok) puts(is_ok ? "Yes" : "No");
#define SORT(v) sort(v.begin(), v.end());
#define RSORT(v) sort(v.rbegin(), v.rend());
#define REVERSE(v) reverse(v.begin(), v.end());

template <typename T>
void printlnVector(T v)
{
  rep(i, v.size())
  {
    cout << v[i] << endl;
  }
}

template <typename T>
void printVector(T v)
{
  rep(i, v.size())
  {
    cout << v[i] << " ";
  }
  cout << endl;
}

int main()
{
  string S;
  cin >> S;
  cout << S.substr(0, 4) + " " + S.substr(4, 8) << endl;
  return 0;
}

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


void solve(long long N, long long M, std::vector<long long> a, std::vector<long long> b){
for(int i=1;i<=N;i++){
    int ans=0;
    for(int j=0;j<M;j++){
        if((a.at(j)==i)||(b.at(j)==i))ans++;
    }
    cout<<ans<<endl;
}
}


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


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

int main(){
    int n;
    cin>>n;
    long long a[100005];
    long long b[100005];
    long long c[100005];
    for(int i=0;i<n;i++){
        cin>>a[i]>>b[i]>>c[i];
        }
    long long ans[100005][3];
   ans[0][0]=a[0];
   ans[0][1]=b[0];
   ans[0][2]=c[0];
 for(int i=1;i<n;i++){
     ans[i][0]=max(ans[i-1][1]+a[i],ans[i-1][2]+a[i]);
     ans[i][1]=max(ans[i-1][0]+b[i],ans[i-1][2]+b[i]);
     ans[i][2]=max(ans[i-1][1]+c[i],ans[i-1][0]+c[i]);
     
     }
 cout<<max(ans[n-1][0],max(ans[n-1][1],ans[n-1][2]))<<endl;

 
  }

Measured memory_bytes: 4992
#include <bits/stdc++.h>
using namespace std;
int n, mini = 1000;
int digit_sum(int a) {
	int val = 0;
	while(a) {
		val += a % 10;
		a /= 10;
	}
	return val;
}
int main() {
	cin >> n;
	for (int i = 1; i < n; i++)
		mini = min(mini, digit_sum(i) + digit_sum(n - i));
	cout << mini;
	return 0;
}

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

using namespace std;
using ll = long long;
using VI = vector<int>;
using VL = vector<ll>;
using VS = vector<string>;
using VB = vector<bool>;
using VVI = vector<VI>;
using VVL = vector<VL>;
using PII = std::pair<int, int>;
using PLL = std::pair<ll, ll>;
using TI3 = std::tuple<int, int, int>;
using TI4 = std::tuple<int, int, int, int>;
using TL3 = std::tuple<ll, ll, ll>;
using TL4 = std::tuple<ll, ll, ll, ll>;

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define repr(i, n) for (int i = (int)(n)-1; i >= 0; i--)
#define rep2(i, s, n) for (int i = (s); i < (int)(n); i++)
#define rep3(i, s, n, d) for (int i = (s); i < (int)(n); i += (d))
#define allpt(v) (v).begin(), (v).end()
#define allpt_c(v) (v).cbegin(), (v).cend()
#define allpt_r(v) (v).rbegin(), (v).rend()

const int mod1 = 1e9 + 7, mod2 = 998244353, mod3 = 1e9 + 9;
const int mod = mod1;
const ll inf = 1e18;

const string wsp = " ";
const string tb = "\t";
const string rt = "\n";

class Weited_Unionfind
{
    vector<int> p;
    vector<int> diff;
    VVI children;

public:
    int find(int x);
    void unite(int x, int y, int d, bool &ok);
    bool isunion(int x, int y);
    Weited_Unionfind(int n);
    void showdiff(int x, int y);
};

Weited_Unionfind::Weited_Unionfind(int n)
{
    children.resize(n);
    for (int i = 0; i < n; i++)
    {
        p.emplace_back(i);
        diff.emplace_back(0);
        children[i].emplace_back(i);
    }
}
int Weited_Unionfind::find(int x)
{
    while (p[x] != x)
    {
        p[x] = p[p[x]];
        x = p[x];
    }
    return x;
}

void Weited_Unionfind::unite(int x, int y, int d, bool &ok)
{
    int px, py, bigtree, smalltree, dx, dy;
    px = Weited_Unionfind::find(x);
    py = Weited_Unionfind::find(y);
    if (px == py)
    {
        if (diff[y] - diff[x] != d)
            ok = false;
        return;
    }
    dx = diff[x] - diff[px];
    dy = diff[y] - diff[py];
    bigtree = (children[px].size() >= children[py].size() ? px : py);
    smalltree = (bigtree == px ? py : px);
    p[smalltree] = bigtree;
    for (int z : children[smalltree])
    {
        children[bigtree].emplace_back(z);
        if (px == bigtree)
            diff[z] += d - dy + dx;
        else
            diff[z] -= d - dy + dx;
    }
    children[smalltree].clear();
}

bool Weited_Unionfind::isunion(int x, int y)
{
    return Weited_Unionfind::find(x) == Weited_Unionfind::find(y);
}

void Weited_Unionfind::showdiff(int x, int y)
{
    int px, py;
    px = Weited_Unionfind::find(x);
    py = Weited_Unionfind::find(y);
    if (px != py)
        cout << "?" << rt;
    else
        cout << diff[y] - diff[x] << rt;
}



int main()
{

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

#ifdef DEBUG
    cout << "DEBUG MODE" << endl;
    ifstream in("input.txt"); //for debug
    cin.rdbuf(in.rdbuf());    //for debug
#endif

    int n, q, a, b, d;
    bool ok{true};
    cin >> n >> q;
    Weited_Unionfind un(n + 1);

    rep(qi, q)
    {
        cin >> a >> b >> d;
        un.unite(a, b, d, ok);
        if (!ok)
            break;
    }

    cout << (ok ? "Yes" : "No") << rt;

    return 0;
}


Measured memory_bytes: 10608
#include <cstdio>
#include <cctype>
#include <algorithm>
using namespace std;
inline int read(int f = 1, int x = 0, char ch = ' ')
{
    while(!isdigit(ch = getchar())) if(ch == '-') f = -1;
    while(isdigit(ch)) x = x*10+ch-'0', ch = getchar();
    return f*x;
}
int n, f[2], g[2];
int main()
{
    n = read();
    for(int i = 1; i <= n; ++i) 
    {
        int x = read();
        if(!f[0]||f[0] == x) f[0] = x, ++f[1];
        else if(!g[0]||g[0] == x) g[0] = x, ++g[1];
    }
    if(f[0] > g[0]) swap(f[0], g[0]), swap(f[1], g[1]);
    if(!f[0]&&g[0] == n-1&&g[1] == n) puts("Yes");
    else if(f[1]+g[1] != n||(f[0]+1 != g[0]&&f[0])||f[1]+(g[0]-f[1])*2 > n||f[1]+1 > g[0]) puts("No");
    else puts("Yes");
    return 0;
}
/*
3
2 2 2
*/

Measured memory_bytes: 128
#include <iostream>
using namespace std;
int main()
{
  int A, B, C, D, E, F;
  cin >> A >> B >> C >> D >> E >> F;
  int ans1 = 0;
  int ans2 = 0;
  double ratio = -1.0;
  for (int i = 0; 100 * A * i <= F; i++)
  {
    for (int j = 0; 100 * (A * i + B * j) <= F; j++)
    {
      int water = 100 * (A * i + B * j);
      if (water == 0)
        continue;
      for (int k = 0; water + C * k <= F; k++)
      {
        for (int l = 0; water + C * k + D * l <= F; l++)
        {
          int sugar = C * k + D * l;
          double tmp = (100.0 * sugar) / (water + sugar);
          if (sugar <= E * (A * i + B * j) && ratio < tmp)
          {
            ans1 = water + sugar;
            ans2 = sugar;
            ratio = tmp;
          }
        }
      }
    }
  }
  cout << ans1 << " " << ans2 << endl;
  return 0;
}

Measured memory_bytes: 256
import sys

s = ''
for line in sys.stdin:
    s += line
s = s.lower()
count = {letter: s.count(letter) for letter in set(s)}
for c in range(97,97+26):
    if chr(c) in count:
        print("%c : %d" % (chr(c), count[chr(c)]))
    else:
        print("%c : 0" % chr(c))

Measured memory_bytes: 7464
#include<stdio.h>
int partition(int A[],int p,int r){
    int i,j,x,t;

    i=p-1;
    x=A[r];
    for(j=p;j<r;j++){
	if(A[j]<=x){
	    i++;
	    t=A[j];A[j]=A[i];A[i]=t;
	}
    }
    t=A[r];A[r]=A[i+1];A[i+1]=t;
    return i+1;
}

void quickSort(int A[],int p,int r){
    int q;
    if(p<r){
	q=partition(A,p,r);
	quickSort(A,p,q-1);
	quickSort(A,q+1,r);
    }
}

int search(int A[],int left,int right,int key){
    int mid;
    while(left+1<right){
	mid=(left+right)/2;
	if(A[mid]>key) right=mid;
	else left=mid;
    }
    return left;
}

int main(void){
    int n,m;
    int P[1001],Q[1000000];
    int i,j,num;
    int key,ans,r;

    while(1){
	scanf("%d%d",&n,&m);
	if(n==0&&m==0) break;

	P[0]=0;
	for(i=1;i<=n;i++) scanf("%d",&P[i]);

	num=0;
	for(i=0;i<=n;i++){
	    for(j=i;j<=n;j++){
		Q[num++]=P[i]+P[j];
	    }
	}

	quickSort(Q,0,num-1);

	ans=0;
	for(i=0;i<num;i++){
	    key=m-Q[i];
	    if(key<0) break;
	    r=search(Q,0,num,key);
	    if(Q[i]+Q[r]>ans) ans=Q[i]+Q[r];
	}
	printf("%d\n",ans);
    }

    return 0;
}

Measured memory_bytes: 2752
#include<bits/stdc++.h>
#define mems(a,x) memset(a,x,sizeof(a))
#define first fi
#define second se
using namespace std;
typedef long long ll;
const int mod=1e9+7,MS=105,N=66;
const double eps=1e-8;
ll inv(ll x){return x==1?x:(mod-mod/x)*inv(mod%x)%mod;}
ll inv(ll x,ll mod){return x==1?x:(mod-mod/x)*inv(mod%x,mod)%mod;}
ll qpow(ll a,ll n){ll ans=1;while(n){if(n&1) ans=ans*a%mod;a=a*a%mod;n>>=1;}return ans;}
ll mul(ll a,ll b){ll ans=0;while(b){if(b&1) ans=(ans+a)%mod;a=(a+a)%mod;b>>=1;};return ans;}
ll qpow(ll a,ll n,ll mod){ll ans=1;while(n){if(n&1) ans=ans*a%mod;a=a*a%mod;n>>=1;}return ans;}
ll mul(ll a,ll b,ll mod){ll ans=0;while(b){if(b&1) ans=(ans+a)%mod;a=(a+a)%mod;b>>=1;};return ans;}
struct vec
{
    double x,y;
    vec(double x=0,double y=0):x(x),y(y){}
    vec operator+(const vec&o)const{ return vec(x+o.x,y+o.y);}
    vec operator-(const vec&o)const{ return vec(x-o.x,y-o.y);}
    double operator*(const vec&o)const{ return x*o.x+y*o.y;}
    double operator^(const vec&o)const{ return x*o.y-y*o.x;}
    vec operator/(const double&o)const{ return vec(x/o,y/o);}
    vec operator*(const double&o)const{ return vec(x*o,y*o);}
    void sc(){scanf("%lf%lf",&x,&y);}
    double len(){return sqrt(x*x+y*y);}
};
struct Mat
{
    ll a[MS][MS];
    int n,m;
    Mat(int n=0,int m=0):n(n),m(m) { mems(a,0);}
    Mat operator*(const Mat&B)const
    {
        Mat C(n,B.m);
        for(int i=1;i<=n;i++)
            for(int j=1;j<=B.m;j++)
                for(int k=1;k<=m;k++)
                C.a[i][j]=(C.a[i][j]+a[i][k]*B.a[k][j])%mod;
        return C;
    }
};
int n,k;
vec a[N];
double c[N];
vec s1,s2;
vec polar(double a,double r){return vec(cos(r)*a,sin(r)*a);}
bool intersect(vec c1,vec c2,double r1,double r2)
{
    double d=(c1-c2).len();
    if(d-eps>r1+r2||d<=r1||d<=r2) return false;
    double a=acos((r1*r1+d*d-r2*r2)/(2*r1*d));
    double t=atan2(c2.y-c1.y,c2.x-c1.x);
    s1=c1+polar(r1,t-a);
    s2=c1+polar(r1,t+a);
    return true;
}
bool judge(double T)
{
    for(int i=1;i<=n;i++)
    {
        for(int j=i+1;j<=n;j++)
        {
            if(!intersect(a[i],a[j],T/c[i],T/c[j])) continue;
            int x=0,y=0;
            for(int k=1;k<=n;k++)
            {
                if(c[k]*(s1-a[k]).len()<=T+eps) x++;
                if(c[k]*(s2-a[k]).len()<=T+eps) y++;
            }
            if(x>=k||y>=k) return true;
        }
        int x=0;
        for(int j=1;j<=n;j++)
            if(c[j]*(a[i]-a[j]).len()<=T+eps) x++;
        if(x>=k) return true;
    }
    return false;
}
int main()
{
    scanf("%d%d",&n,&k);
    for(int i=1;i<=n;i++)
        a[i].sc(),scanf("%lf",&c[i]);
    double l=0,r=200000;
    for(int i=1;i<=50;i++)
    {
        double m=(l+r)/2;
        if(judge(m)) r=m;
        else l=m;
    }
    printf("%.10f\n",(l+r)/2);
}


Measured memory_bytes: 384
def main():
  n = int(input())
  a = list(map(int,input().split()))
  result = 1
  for i in range(n):
    result *= a[i]
    if result > 1000000000000000000:
      for j in range(i + 1, n):
        if a[j] == 0:
          return 0
      return -1
  return result

print(main())

Measured memory_bytes: 21716
#include <algorithm>//min/max/sort(rand-access it)/merge
#include <bitset>
#include <climits>//INT_MAX/INT_MIN/ULLONG_MAX
#include <cmath>//fmin/fmax/fabs/sin(h)/cos(h)/tan(h)/exp/log/pow/sqrt/cbrt/ceil/floor/round/trunc
#include <cstdlib>//abs/atof/atoi/atol/atoll/strtod/strtof/..., srand/rand, calloc/malloc, exit, qsort
#include <iomanip>//setfill/setw
#include <iostream>//cin/cout/wcin/wcout/left/right/internal/dec/hex/oct/fixed/scientific
#include <iterator>
#include <list>
#include <queue>
#include <string>//stoi/stol/stoul/stoll/stoull/stof/stod/stold/to_string/getline
#include <tuple>
#include <utility>//pair
#include <valarray>
#include <vector>

#define PRIME 1000000007

using namespace std;

typedef unsigned int ui;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> pii;
typedef pair<ll, int> plli;
typedef pair<ull, int> puli;
typedef pair<double, int> pdi;
typedef pair<ll, ll> pllll;
typedef pair<ull, ull> pulul;
typedef pair<double, double> pdd;
typedef tuple<int, int, int> ti3;
typedef tuple<int, int, int, int> ti4;

const bool debug = false;

int ipow(int base, int exp);
int left(int current, bool swap);
int right(int current, bool swap);
int griddist(int x, int y, int s, int t);
int griddist(pii one, pii two);
double sqeucldist(double x, double y, double s, double t);
double sqeucldist(pii one, pii two);

int main(void) {
	int n;
	cin >> n;
	vector<pii> data;
	for (int i = 0; i < n; ++i)
	{
		int a;
		cin >> a;
		data.emplace_back(a, i);
	}
	sort(data.begin(), data.end());
	if (debug)
	{
		for (int i = 0; i < n; ++i)
		{
			cout << data[i].first << "." << data[i].second << " ";
		}
		cout << endl;
	}
	ui swaps = 0U;
	for (int i = 0; i < n; ++i)
	{
		if (debug)
		{
			cout << abs(data[i].second - i) % 2 << " ";
		}
		swaps += abs(data[i].second - i) % 2;
	}
	cout << swaps/2 << endl;
	return 0;
}


Measured memory_bytes: 1400
using System;
using System.Collections.Generic;
using System.Dynamic;
using System.Linq;

namespace atcorder
{
    class Program
    {
        static void Main(string[] args)
        {
            string A = Console.ReadLine();
            string B = Console.ReadLine();
            if(A == "1" && B == "2")
            {
                Console.WriteLine("3");
            }
            else if (A == "3" && B == "2")
            {
                Console.WriteLine("1");
            }
            else if (A == "2" && B == "3")
            {
                Console.WriteLine("1");
            }
            else if (A == "2" && B == "1")
            {
                Console.WriteLine("3");
            }
            else
            {
                Console.WriteLine("2");
            }
        }
    }
}

//文字配列の取得
//string[] strArray = Console.ReadLine().Split(' ').ToArray();
//string S = strArray[0];
//string T = strArray[1];

//文字列の取得
//string s = Console.ReadLine();

//数字配列の取得
//int[] intArray = Console.ReadLine().Split(' ').Select(i => int.Parse(i)).ToArray();
//int H = intArray[0];
//int W = intArray[1];

//数字の取得
//int N = int.Parse(Console.ReadLine());

//リスト型(int)の取得
//List<int> A = new List<int>(Console.ReadLine().Split(' ').Select(i => int.Parse(i)).ToArray());

//出力
//Console.WriteLine(ans);
//Console.WriteLine("Yes");
//Console.WriteLine("No");
//Console.WriteLine(cnt);




Measured memory_bytes: 25744
import java.util.Scanner;

public class Main {
    public static void main(String... args){
        Scanner scan = new Scanner(System.in);
        while(true){
            if(!scan.hasNext())break;
            String s = scan.next();
            for(int i = 0;i < s.length();i++){
                alp.countAlp(s.charAt(i));
            }
        }
        for(alp a: alp.values()){
            System.out.println(a.name() + " : " + a.count);
        }

        scan.close();
    }

    enum alp{
        a,b,c,d,e,f,g,h,i,j,k,l,m,n,o,p,q,r,s,t,u,v,w,x,y,z;

        static void countAlp(char c){
            for(alp a: alp.values()){
                if(a.name().equals(String.valueOf(c).toLowerCase())){
                    a.count++;
                    break;
                }
            }
        }
        int count = 0;
    }

    

}


Measured memory_bytes: 28268
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0; i<n; i++)
#define cans cout << ans << endl
#define cyes cout << "Yes" << endl
#define cno cout << "No" << endl
typedef long long ll;


int main(){
    int n,q;
    cin >> n >> q;
    string s;
    cin >> s;
    vector<int> sum(n+1);
    vector<int> l(q),r(q);
    rep(i,q) cin >> l[i] >> r[i];
    sum[0] = 0;
    for(int i=1; i<s.size(); i++){
        if(s[i-1]=='A' && s[i]=='C') sum[i+1]=sum[i]+1; 
        else
        sum[i+1] = sum[i];
    }
    for(int i=0; i<q; i++){
        int ans = sum[r[i]]-sum[l[i]];
        cout << ans << endl;
    }
    return 0;
}

Measured memory_bytes: 4560
#include<stdio.h>
#include<math.h>
#define PI 3.14159265359
int main()
{
    int a,b,c;
    double rad;
    scanf("%d%d%d",&a,&b,&c);
    rad=c*PI/180;
    printf("%lf\n",0.5*a*b*sin(rad));
    printf("%lf\n",a+b+sqrt(a*a+b*b-(2*a*b*cos(rad))));
    printf("%lf\n",b*sin(rad));
    return 0;
}



Measured memory_bytes: 2052
#include <iostream>
#include <math.h>
using namespace std;
int main(void)
{
	int N, A[100], work,cou = 0;
	bool flag = 1;
	cin >> N;
	for (int i = 0; i < N; i++) {
		cin >> A[i];
	}
	while (flag) {
		flag = 0;
		for (int j = N - 1; j >= 1; j--) {
			if (A[j] < A[j - 1]) {
				work = A[j];
				A[j] = A[j - 1];
				A[j - 1] = work;
				flag = 1; cou++;
			}
		}
	}
	for (int i = 0; i < N; i++) {
		cout << A[i];
		if (i != N - 1)  cout << " ";
		else cout << endl;
	}
	cout << cou << endl;
}

Measured memory_bytes: 1160
#include <stdio.h>
 int main(void){
  int n;
  int i,j;
  scanf("%d",&n);
  if(n==1)
  printf("1");
  else if(2<=n&&n<4)
  printf("2");
  else if(4<=n&&n<8)
  printf("4");
  else if(8<=n&&n<16)
  printf("8");
  else if(16<=n&&n<32)
  printf("16");
  else if(32<=n&&n<64)
  printf("32");
  else
  printf("64");
  return 0;
 }

Measured memory_bytes: 128
import java.util.*;
public class Main{
    static Scanner kbd = new Scanner(System.in);
    public static void main(String[] args){
	while(kbd.hasNext()){
	    int q = kbd.nextInt();
	    if(q!=-1) solve(q);
	}
    }

    static void solve(int q){
	double ans = 1;
	int i = 1;
	while(Math.abs(ans*ans*ans - q)>=0.00001*q){
	    ans = calc(i, ans, q);
	    i++;
	}
	System.out.printf("%.6f\n",ans);
    }
    static double calc(int i, double x, int q){
	if(i==1) return q/2;
	return x-(x*x*x-q)/(3*x*x);
    }
}

Measured memory_bytes: 17192
#include <iostream>
#include <cstring>
#include <cstdio>
#include <algorithm>
#include <cmath>
#include <iomanip>

using namespace std;

const int N = 110,M = 1e5+100,mod = 1e9+7;
typedef long long LL;

int n,k;
LL dp[N][M];  //dp[i][j] 表示前i个小朋友一共分j颗糖的方案
int a[N];

int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    
    cin>>n>>k;
    for(int i = 1; i<=n; i++) cin>>a[i];
    
    dp[0][0] = 1;
    for(int i = 1; i<=n; i++){
        dp[i][0] = 1;
        for(int j = 0; j<k; j++){
            dp[i][j+1] = dp[i][j] + dp[i-1][j+1];
            if(j>=a[i]) dp[i][j+1] -= dp[i-1][j-a[i]];
            dp[i][j+1]  = (dp[i][j+1]+mod)%mod;
        }
    }
    cout<<dp[n][k];
    
    
    return 0;
}

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

using namespace std;

#define REP(i,n) for(int i=0; i<int(n); i++)
#define FOR(i,m,n) for(int i=int(m); i<int(n); i++)
#define ALL(obj) (obj).begin(),(obj).end()
#define VI vector<int>
#define VLL vector<long long>
#define VVI vector<vector<int>>
#define VVLL vector<vector<long long>>
#define VC vector<char>
#define VS vector<string>
#define VVS vector<vector<string>>
#define VVC vector<vector<char>>
typedef long long ll;
const int  INF = 1000000000;
const ll INFL = 1LL << 50;
const ll mod = 1000000007;




int main() {
	int n;
	cin >> n;
	VI a(n);
	int res = 0;
	REP(i, n) {
		int b;
		cin >> b;
		res += b;
		a[i] = b*n;
	}
	int ans,c = INF;
	REP(i, n) {
		if (abs(res - a[i]) < c) {
			ans = i;
			c = abs(res - a[i]);
		}
	}
	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++)
const long long MOD = 1e9+7, MAx = 1e18, larg = 1e5, INF = -1e9;
long long A,B,C,D,E,F,G,H,I,J,K,L,N,M,O,P,Q,R,S,T,U,V,W,x,y,z;
long long max_value = INF, max_index = -1;
long long min_value = MAx, min_index = -1;

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

int main() {
    cin >> H >> W;
    char maze[21][21];
    ll value[21][21];
    max_value = 0;
    rep(i, H){
        rep(j, W){
            cin >> maze[i][j];
        }
        maze[i][W] = '#';
    }
    rep(i, W+1) maze[H][i] = '#';
    int dx[4] = {0, 1, 0, -1}, dy[4] = {1, 0, -1, 0};
    rep(i, H){
        rep(j, W){
            if(maze[i][j] == '#') continue;
            else{
                rep(k, 21){
                    rep(l, 21){
                        value[k][l] = -1;
                    }
                }
                queue<Pa> que;
                value[i][j] = 0;
                que.push(make_pair(i, j));
                while(!que.empty()){
                    Pa curr = que.front(); que.pop();
                    rep(k, 4){
                        int y = curr.first+dy[k], x = curr.second+dx[k];
                        if(y < 0 || y >= H || x < 0 || x >= W) continue;
                        if(maze[y][x] == '#' || value[y][x] >= 0) continue;
                        que.push(make_pair(y, x));
                        value[y][x] = value[curr.first][curr.second] + 1;
                    }
                }
                rep(k, H + 1){
                    rep(l, W + 1){
                        max_value = max(value[k][l], max_value);
                    }
                }
            }
        }
    }
    cout << max_value;
}


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

int main(void)
{
    int A,B,H,M;
    cin >> A >> B >> H >> M;

    long double hour_deg;
    long double min_deg;
    long double deg;
    long double dis;

    hour_deg=30*H+0.5*M;
    min_deg=6*M;
    deg = hour_deg - min_deg;


    if(deg<0){
        deg = deg + 360.0;   
    }

    dis = sqrt(A*A + B*B - 2*A*B*cos(deg*2*M_PI/360.0));

    cout << fixed << setprecision(15) << dis << endl;

    return 0;

}

Measured memory_bytes: 4164
#ライブラリの点検
class Data():
    def __init__(self):
        self.power=1
        self.rev=1     
class Combi():
    def __init__(self,N,mod):
        self.lists=[Data() for _ in range(N+1)]
        self.mod=mod  
        for i in range(2,N+1):
            self.lists[i].power=((self.lists[i-1].power)*i)%self.mod
        self.lists[N].rev=pow(self.lists[N].power,self.mod-2,self.mod)
        for j in range(N,0,-1):
            self.lists[j-1].rev=((self.lists[j].rev)*j)%self.mod

    def combi(self,K,R):
        if K<R:
            return 0
        else:
            return ((self.lists[K].power)*(self.lists[K-R].rev)*(self.lists[R].rev))%self.mod

######################
h,w,a,b=map(int,input().split())
ans=0
mod=10**9+7
C=Combi(w+h+2,mod)
for i in range(h-a):
    ans+=C.combi(b+i-1,i)*C.combi(w+h-2-b-i,h-1-i)%mod
print(ans%mod)
######################

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

using namespace std;
#define int long long
#define N 666666
int arr[N];
deque<int> q;
signed main(){
	int n;
	cin>>n;
	int f=1;//原序 
	for(int i=1;i<=n;i++) scanf("%lld",&arr[i]);
	for(int i=1;i<=n;i++){
		if(f){
			q.push_back(arr[i]);
		}else{
			q.push_front(arr[i]);
		}
		f^=1;
	}
	if(f){
		for(int i=0;i<n;i++) cout<<q[i]<<" ";
	}else{
		for(int i=n-1;i>=0;i--) cout<<q[i]<<" ";
	}
	return 0;
}
/*
3
1 2 3
1 2 6
1 9 6
16 9 6
31 9 6
*/

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

using namespace std;

typedef vector<string> V;

class Solver {
    private:
        void search(string &line, bool has_used[], V &candidates, unsigned cur = 0) {
            char c = line[min(cur, (unsigned)line.length() - 1)];
            if (cur == line.length()) {
                candidates.push_back(line);
                return;
            }
            if (c == 'a') {
                search(line, has_used, candidates, cur + 1);
            }
            if (has_used[c - 'a']) {
                search(line, has_used, candidates, cur + 1);
            }
            if (!has_used[c + 1 - 'a']) {
                line[cur] = c + 1;
                has_used[c + 1 - 'a'] = true;
                search(line, has_used, candidates, cur + 1);
                line[cur] = c;
                has_used[c + 1 - 'a'] = false;
            }
        }
    public:
        V enumerate(string line) {
            V candidates;
            bool has_used[27];
            for (int i = 0; i < 26; ++i) {
                has_used[i] = false;
            }
            has_used[26] = true;
            search(line, has_used, candidates);
            return candidates;
        }
};

int main() {
    Solver s;
    string line;
    V candidates;
    while (true) {
        cin >> line;
        if (line == "#") {
            return 0;
        }
        candidates = s.enumerate(line);
        cout << candidates.size() << endl;
        if (candidates.size() < 10) {
            for (unsigned i = 0; i < candidates.size(); ++i) {
                cout << candidates[i] << endl;
            }
        } else {
            for (unsigned i = 0; i < 5; ++i) {
                cout << candidates[i] << endl;
            }
            for (unsigned i = 0; i < 5; ++i) {
                cout << candidates[candidates.size() - 5 + i] << endl;
            }
        }
    }
}

Measured memory_bytes: 2436
#include <bits/stdc++.h>
using namespace std;
#define FOR(i, s, e) for (int(i) = (s); (i) < (e); (i)++)
#define FORR(i, s, e) for (int(i) = (s); (i) > (e); (i)--)
int main() {
    cin.tie(0);
    ios_base::sync_with_stdio(false);
    string s;
    int K;
    int Num =0;
    vector <string> ss;
    cin >> s >> K;
    FOR(k,'a','z'+1) {
        FOR(i,0,s.size()){
            if(int(s[i]) == k){
                for(int(j) = 1;j+i<=s.size() && j < 6;j++){
                    ss.push_back(s.substr(i,j));
                }
            }
        }
        sort(ss.begin(), ss.end());
        if(ss.size() != 0) {
            Num++;
            if (Num == K) {
                cout << ss[0];
                return 0;
            }
        }
        FOR(i, 1, ss.size()) {
            if (ss[i - 1] != ss[i])
                Num++;
            if (Num == K) {
                cout << ss[i];
                return 0;
            }
        }
        ss.clear();
    }
    return 0;
}

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

int main() {
  int h, w;
  cin >> h >> w;
  vector<int> a(w);
  vector<int> b(h);
  vector<vector<char>> grid(h, vector<char>(w));

  for (int i=0; i<h; i++) {
    int bcnt=0;
    for (int j=0; j<w; j++) {
      cin >> grid[i][j];
      
      if (grid[i][j]=='.') {
        a[j]++;
        bcnt++;
      }
    }
    if (bcnt==w) b[i]++;
  }

  for (int i=0; i<h; i++) {
    if (b[i]) continue;
    for (int j=0; j<w; j++) {
      if (a[j]==h) continue;
      cout << grid[i][j];
    }
    cout << endl;
  }
}

Measured memory_bytes: 256
import sys
from itertools import accumulate


def input():
    return sys.stdin.readline().strip()


sys.setrecursionlimit(20000000)

MOD = 10 ** 9 + 7
INF = float("inf")


def main():
    N, K = map(int, input().split())
    A = list(map(int, input().split()))
    for _ in range(K):
        B = [0 for _ in range(N)]
        count = 0
        for i in range(N):
            if A[i] == N:
                count += 1
            l = max(0, i - A[i])
            r = min(N - 1, i + A[i])
            B[l] += 1
            if r + 1 < N:
                B[r + 1] -= 1
        B = list(accumulate(B))
        if count == N:
            break
        else:
            A = B
    print(*B, sep=" ")


if __name__ == "__main__":
    main()


Measured memory_bytes: 184328
#include<stdio.h>
int main(){
	char a,b;
	scanf("%c %c",&a,&b);
	if(a=='H'){
		if(b=='H'){
			printf("H");
		}
		else{
			printf("D");
		}
	}
	if(a=='D'){
		if(b=='H'){
			printf("D");
		}
		else{
			printf("H");
		}
	}
	return 0;
}

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

int main(){
    int N,H;
    cin >> N >> H;
    int a[N];
    int b[N];
    for(int i=0;i<N;i++){
        cin >> a[i] >> b[i];
    }
    sort(a,a+N,greater<int>());
    sort(b,b+N,greater<int>());
    int i=0;
    int cnt=0;
    while(b[i]>=a[0]&&i<N){
        H-=b[i];
        cnt++;
        if(H<=0){
            cout << cnt << endl;
            return 0;
        }
        i++;
    }
    cout << cnt+(H+(a[0]-1))/a[0] << endl;
}

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

int main() {
  int N;
  cin >> N;
  
  vector<int> card(N);
  for (int i = 0; i < N; i++) {
  	cin >> card.at(i);
  }
  
  sort(card.begin(), card.end());
  
  reverse(card.begin(), card.end());
  
  int Alice = 0, Bob = 0;
  
  for (int i = 0; i < N; i++) {
  	if (i % 2 == 0) {
    	Alice += card.at(i);
    }
    else {
    	Bob += card.at(i);
    }
  }
  
  cout << Alice - Bob;
  
}





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

using LL = long long;
const LL MOD = 1e9 + 7;

LL dp[101][100001] = {};
LL a[100001] = {};

int main() {
	int N, K;
	cin >> N >> K;
	for(int i=1;i<=N;i++) {
		cin >> a[i];
	}
	for(int i=0;i<=K;i++) {
		dp[0][i] = 0;
	}
	for(int i=0;i<=N;i++) {
		dp[i][0] = 1;
	}
	// cout << "HHHH";
	for(int i=1;i<=N;i++) {
		for(int j=0;j<=K;j++) {
			dp[i][j] = 0;
			// for(int k=0;k<=a[i]&&j-k>=0;k++) {
			// 	dp[i][j] = (dp[i][j] + dp[i-1][j-k])%MOD;
			// }
			if(j-a[i]-1 >= 0) {
				dp[i][j] = (dp[i-1][j] + dp[i][j-1] - dp[i-1][j-a[i]-1] + MOD) % MOD;
			} else {
				if(j-1>=0) dp[i][j] = (dp[i-1][j] + dp[i][j-1])% MOD;
				else {
					dp[i][j] = dp[i-1][j];
				}
			}
			
		}
	}

	// for(int i=0;i<=N;i++) {
	// 	for(int j=0;j<=K;j++) {
	// 		cout << dp[i][j] << " ";
	// 	}
	// 	cout << "\n";
	// }

	// cout << "HHHH";
	cout << dp[N][K];
}

Measured memory_bytes: 79104
#include <iostream>

int main(){
   int N, M;
   std::cin >> N >> M;
   int A[N];
   int sum = 0;
   for(int i=0; i<N; ++i){
      std::cin >> A[i];
      sum += A[i];
   }
   sum = sum/(4*M) + (sum%(4*M)==0 ? 0 : 1);
   int count = 0;
   for(int i=0; i<N; ++i){
      if(A[i]>=sum) ++count;
   }
   if(count>=M) std::cout << "Yes" << std::endl;
   else std::cout << "No" << std::endl;

   return 0;
}


Measured memory_bytes: 3592
import sys
from collections import deque

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

for i in range(n):
    if i % 2 != n % 2:
        b.appendleft(a[i])
    else:
        b.append(a[i])

for _ in b:
    sys.stdout.write(str(_) + " ")
sys.stdout.write("\n")


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

using namespace std;

int main(){
    int n;

    cin >> n;
    vector<int> a(n);
    vector<int> b(n);
    vector<int> c(n);
    for (int i = 0; i < n; i++){
        cin >> a[i];
    }
    for (int i = 0; i < n; i++){
        cin >> b[i];
    }
    for (int i = 0; i < n; i++){
        cin >> c[i];
    }

    sort(a.begin(), a.end());
    sort(c.begin(), c.end());
    long long sum = 0;
    long long j, k;
    for (int i = 0; i < n; i++){
        j = lower_bound(a.begin(), a.end(), b[i]) - a.begin();
        k = n-(upper_bound(c.begin(), c.end(), b[i]) - c.begin()) ;
        sum += j*k;
    }
    cout << sum << endl;
}


Measured memory_bytes: 1536
#include<bits/stdc++.h>
using namespace std;
#define mod 1000000007
typedef long long ll;
ll modinv(ll a, ll p) {
    if (p == 1) return 0;
    ll pp = p, y = 0, x = 1;
    while (a > 1) {
        ll q = a / p, t = p;
        p = a % p, a = t, t = y, y = x - q * y, x = t;
    }
    if (x < 0) x += pp;
    return x;
}
ll C(int n, int a) {
	ll ans = 1;
	for (ll i = n; i > n - a; i--)
		ans = ans * i % mod;
	for (ll i = 1; i <= a; i++)
		ans = ans * modinv(i, mod) % mod;
	return ans;
}
int main() {
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	int n, a, b;
	cin >> n >> a >> b;
	ll tmp = 2;
	int pow = n;
	ll ans = 1;
	while (pow) {
		if (pow & 1) ans = (ans * tmp) % mod;
		tmp = tmp * tmp % mod;
		pow >>= 1;
	}
	ans = (ans + mod - 1) % mod;
	ans = (ans + mod - C(n, a)) % mod;
	ans = (ans + mod - C(n, b)) % mod;
	cout << ans << "\n";
	return 0;
}

Measured memory_bytes: 256
typedef long long ll;
#include <bits/stdc++.h>
using namespace std;
ll gcd(ll a,ll b){
    if(a%b==0)return b;
    return gcd(b,a%b);
}

int main() {
    ll n;
    std::cin >> n;
    vector<ll> h(n);
    for (int i = 0; i < n; i++) {
        std::cin >> h[i];
    }
    ll now = 0;
    ll cnt = 0;
    for (int i = 0; i < n; i++) {
        if( h[i] >= now ){
            cnt++;
            now = h[i];
        }
    }
    std::cout << cnt << std::endl;
}


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

#define NMAX 1001
#define INF 2000000000

#define MOD 1000000007

using namespace std;

int n;
double re;
int aux;

int main()
{
    cin >> n;
    for(int i = 0; i < n; i++)
    {
        cin >> aux;
        re += 1. / aux;
    }
    cout << fixed << setprecision(5) << 1 / re << '\n';
    return 0;
}


Measured memory_bytes: 256
#pragma optimize("", off)
#pragma GCC optimize ("O3")
#pragma GCC optimize("Ofast,no-stack-protector,unroll-loops")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#pragma comment(linker, "/STACK:36777216")

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

int32_t main(){

   int n, p;
   string s;
   cin >> n >> p >> s;

   long long ans = 0;

   if(p == 2 or p == 5){

      vector<int> freq(p);
      for (int i = 0; i < n; ++i)
      {
         int curr = s[i] - '0';
         vector<int> tmp(p);
         for (int j = 0; j < p; ++j)
         {
            int neww = ((j * 10) % p + curr) % p; 
            tmp[neww] += freq[j];
         }
         freq = tmp;
         freq[curr%p]++;
         ans += freq[0];
      }
   }

   else{

      vector<int> a(n);
      int pw = 1;
      for (int i = n-1; i >= 0; --i)
      {
         a[i] = (s[i]-'0');
         a[i] *= pw;
         a[i] %= p;
         pw *= 10;
         pw %= p;
      }

      map<int, int> freq;
      freq[0] = 1;

      int sum = 0;
      for (int i = 0; i < n; ++i)
      {
         sum += a[i];
         sum %= p;
         if(freq.count(sum)){
            ans += freq[sum];
         }  
         freq[sum]++;
      }

   }
   cout<<ans;

   return 0;
}


Measured memory_bytes: 1668
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll INF = (ll)1e18;

int main(){
  ll N; cin >> N;
  vector<ll> cmnstr(26, INF);
  
  for(ll i = 0; i < N; i++){
    string S; cin >> S;
    vector<ll> tmpstr(26, 0LL);
    for(char e : S){
      tmpstr[e - 'a']++;
    }
    for(ll a = 0; a < 26; a++){
      cmnstr[a] = min(tmpstr[a], cmnstr[a]);
    }
  }
  
  for(ll a = 0; a < 26; a++){
    char c = a + 'a';
    ll cnt = cmnstr[a];
    for(ll i = 0; i < cnt; i++){
      cout << c;
    }
  }
  return 0;
}

Measured memory_bytes: 256