akhauriyash/Code-Regression huggingface dataset:
#include<iostream>
#include<cstring>
#include<algorithm>
#include<cstdio>


using namespace std;
typedef long long ll;
const int maxn = 1e6+7;

int he,n;

ll a[maxn],b[maxn];

ll ans=0;

bool check(ll sum,ll k)
{
    he=1;
    for (int i=n; i>=1; i--)
    {
        if (a[he]*b[i]<=sum)
        {
            he++;
            continue;
        }
        if ((a[he]-sum/b[i])>k)
            return false;
        k-=a[he]-sum/b[i];
        he++;
    }
    return true;
}
int main()
{

    ll k;

    scanf("%d%lld",&n,&k);

    for (int i=1; i<=n; i++)
        scanf("%lld",&a[i]);

    for (int i=1; i<=n; i++)
        scanf("%lld",&b[i]);
    sort(a+1,a+1+n);
    sort(b+1,b+1+n);
    ll l=0,r;

    r=b[n]*a[n];
    ans=r;
    while (l<=r)
    {
        ll mid=(l+r)/2;
        if (check(mid,k))
            ans=mid,r=mid-1;
        else
            l=mid+1;
    }
    printf("%lld\n",ans);
    return 0;
}


Measured memory_bytes: 5888
#include <bits/stdc++.h>
using namespace std;
using int64 = long long;
#define int int64
#define rep(i, n) for(int i=0; i<n; i++)
#define FOR(i, a, b) for(int i=a; i<b; i++)
#define SORT(x) sort(x.begin(), x.end())
#define GSORT(x) sort(x.begin(), x.end(), greater<int>())
#define mk make_pair
#define fi first
#define se second
#define pb push_back
#define ALL(x) x.begin(), x.end()
#define V(T) vector<T>
typedef pair<int, int> P;
typedef pair<P, P> PP;
typedef vector<int> vi;
typedef vector<vi> vvi;
int max(int a, int b) {if(b>a) return b; else return a;}
int min(int a, int b) {if(b<a) return b; else return a;}

const char c[5] = {'M', 'A', 'R', 'C', 'H'};

signed main() {
    int N;
    cin >> N;
    V(string) S(N);
    vi alps(26, 0);
    rep(i, N) {
        cin >> S[i];
        alps[S[i][0]-'A']++;
    }

    int res = 0;
    FOR(i, 0, 3) FOR(j, i+1, 4) FOR(k, j+1, 5) {
        res += alps[c[i]-'A']*alps[c[j]-'A']*alps[c[k]-'A'];
    }
    
    cout << res << endl;
    return 0;
}

Measured memory_bytes: 6144
x = int(input())
m = 2 * x

sieve = [True for _ in range(m+1)]

p = 2
i = 2
while True:
    if p * p >= m:
        break
    while p * i <= m:
        sieve[p * i] = False
        i += 1
    p += 1
    while not sieve[p]:
        p += 1
    i = 2

for i in range(x, m):
    if sieve[i]:
        print(i)
        break


Measured memory_bytes: 52336
N, M, C = map(int, input().split())
B = list(map(int, input().split()))
source_code = [list(map(int, input().split())) for i in range(N)]

ans = 0
for i in range(N):
    count = 0
    for j in range(M):
        count += source_code[i][j] * B[j]

    if count + C > 0:
        ans += 1

print(ans)


Measured memory_bytes: 3060
#include<bits/stdc++.h>
using namespace std;
#define pb push_back
#define rep(i,n) for(ll i=0;i<n;i++)
#define rep1(i,n) for(ll i=1;i<=n;i++)
#define mp make_pair
#define F first
#define S second
#define pf pop_front
#define IOS ios_base::sync_with_stdio(0); cin.tie(0)
typedef long long ll;
const ll mod=1e9+7;
const ll maxn=2e5+100;
string a,b;
ll aa,bb;
int main()
{
    while(cin>>a)
    {
        rep(i,a.size())
        {
            cout<<"x";
        }
        cout<<"\n";
    }
}



Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<queue>
#include<functional>
#include<cmath>
#include<set>
#include<random>
#include<map>
using namespace std;
#define int long long
#define rep(i,n) for(int i=0;i<n;i++)
const long long mod = 1000000007;
const long long inf = 11451419198109130;
typedef pair<int, int> P;
typedef pair<P, P> PP;
struct edge {int to, cost;};
vector<edge>G1[114514], G2[114514];
int d1[114514], d2[114514];
bool u1[114514], u2[114514];

signed main() {
	int n, m, s, t; cin >> n >> m >> s >> t;
	rep(i, m) {
		int a, b, c, d; cin >> a >> b >> c >> d;
		a--; b--;
		G1[a].push_back({ b,c });
		G1[b].push_back({ a,c });
		G2[a].push_back({ b,d });
		G2[b].push_back({ a,d });
	}
	
	priority_queue<P, vector<P>, greater<P> >Q;
	fill(d1, d1 + 114514, inf);
	d1[s-1] = 0;
	Q.push(P(0, s-1));

	while (Q.size()) {
		P p = Q.top();
		Q.pop();
		int v = p.second;
		if (d1[v] < p.first)continue;
		rep(i, G1[v].size()) {
			edge e = G1[v][i];
			if (d1[e.to] > d1[v] + e.cost) {
				d1[e.to] = d1[v] + e.cost;
				Q.push(P(d1[e.to], e.to));
			}
		}
	}

	while (Q.size())Q.pop();

	fill(d2, d2 + 114514, inf);
	d2[t-1] = 0;
	Q.push(P(0, t-1));

	while (Q.size()) {
		P p = Q.top();
		Q.pop();
		int v = p.second;
		if (d2[v] < p.first)continue;
		rep(i, G2[v].size()) {
			edge e = G2[v][i];
			if (d2[e.to] > d2[v] + e.cost) {
				d2[e.to] = d2[v] + e.cost;
				Q.push(P(d2[e.to], e.to));
			}
		}
	}
	priority_queue<P,vector<P>,greater<P>>ans;
	rep(i, n) {
		int c = d1[i] + d2[i];
		ans.push(P(c, i+1));
	}

	rep(i, n) {
	F:;
		P p = ans.top();
		if (p.second <= i) {
			ans.pop();
			goto F;
		}
		cout << 1000000000000000 - p.first << endl;
		}
	}

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

using namespace std;
using ll = long long;
using ld = long double;
using pii = pair<int, int>;
using pll = pair<ll, ll>;

#define FOR(k,m,n) for(ll (k)=(m);(k)<(n);(k)++)
#define REP(i,n) FOR((i),0,(n))
#define WAITING(str) int str;std::cin>>str;
#define DEBUGING(str) cout<< #str << " " str<<endl

constexpr int INF = (1 << 30);
constexpr ll INFL = (1ll << 60);
constexpr ll MOD = 1000000007;// 10^9+7

int mhash(string s, string p) {
	stack<int> st;
	for (char c : s) {
		if (isalpha(c))st.push(p[c - 'a'] - '0');

		if (c == '+' || c == '*' || c == '^') {
			int r = st.top(); st.pop();
			int l = st.top(); st.pop();
			switch (c) {
			case '+':st.push(l | r); break;
			case '*':st.push(l&r); break;
			case '^':st.push(l^r); break;
			}
		}
	}
	assert(st.size() == 1);
	return st.top();
}

int main()
{
	ostringstream ss;
	while (true) {
		string s, p; cin >> s;
		if (s == ".")break;
		cin >> p;
		reverse(s.begin(), s.end());

		int cnt = 0;
		int tgt = mhash(s, p);
		REP(i, 10000) {
			ss.fill('0');
			ss << setw(4) << i;
			if (tgt == mhash(s, ss.str()))cnt++;
			ss.str("");
		}
		cout << tgt << " " << cnt << endl;
	}
	return 0;
}



Measured memory_bytes: 3120
def RevFlag(flag):
    if flag:
        return False
    else:
        return True

def main():
    from collections import deque
    S = input()
    d = deque()
    for s in S:
        d.append(s)
    N = int(input())
    rev = False

    for i in range(N):
        Q = [i for i in input().split()]
        if len(Q) == 1:
            rev = RevFlag(rev)
        else:
            F = int(Q[1])
            C = Q[2]
            if F == 1:
                if rev:
                    d.append(C)  # 末尾
                else:
                    d.appendleft(C)  # 先頭
            else:
                if rev:
                    d.appendleft(C)  # 先頭
                else:
                    d.append(C)  # 末尾
    if rev:
        d = ''.join(list(reversed(d)))
    else:
        d = ''.join(list(d))
    print(d)


if __name__ == '__main__':
    main()

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

int main(void){

    int N;
    std::cin >> N;

    std::vector<int64_t> L(N+1);

    if (N == 1)
    {
        L.at(N)=1;
    }
    
    else 
    {
        L.at(0) = 2;
        L.at(1) = 1;
        for (int i = 2; i <= N; i++)
        {
            L.at(i) = L.at(i - 1) + L.at(i - 2);
        }
        
    }
    std::cout << L.at(N) << "\n";
    return 0;
}

Measured memory_bytes: 3596
#include <iostream>
#include <string>
#include <set>
using namespace std;
int P[10], Q[10], n, fact[10];
int init_factorial(int n){
	fact[1] = 1;
	for(int i = 2; i <= n; i++)
		fact[i] = fact[i-1]*i;
}
int get_order(int perm[], int n){
	int order = 1;
	set<int> used;
	for(int i = 0; i < n; i++){
		int possible = perm[i]-1;
		for(int j = 1; j < perm[i]; j++)
			if(used.find(j) != used.end())
				possible--;
		if(possible)
			order += possible*fact[n-i-1];
		used.insert(perm[i]);
	}
	return order;
}
int main(){
	scanf("%d", &n);
	init_factorial(n);
	for(int i = 0; i < n; i++)
		scanf("%d", &P[i]);
	for(int i = 0; i < n; i++)
		scanf("%d", &Q[i]);
	int r1 = get_order(P, n), r2 = get_order(Q, n);
	printf("%d\n", r1 > r2 ? r1-r2 : r2-r1);
//	printf("%d\n", get_order(P, n));
	return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
	#include<string.h>
	int main(){
		
		int a,b,c,e,d,f;
		
		scanf("%d %d", &a,&b);
		
		c=a+b;
		d=a-b;
		f=b*a;
		if(c>=d&&c>=f){
			printf("%d\n", c);
		}
		else if(d>=c&&d>=f){
			printf("%d\n", d);
		}
		else printf("%d\n", f);
		return 0;
	}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <string>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <unordered_map>
#include <algorithm>
#include <functional>
#include <numeric>
#include <cstring>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cassert>
#include <climits>
#define bogo_sort   std::sort
#define bozo_sort   std::stable_sort
#define alles(obj)  obj.begin(), obj.end()
#define elif        else if
#define unless(flg) if(!(flg))
#define elless(flg) else if(!(flg))
#define echo        std::cout <<
#define read        std::cin >>
#define endl        std::endl
#define fin         << '\n'
#define bash        push_back
#define fish        push_front
#define makePair    std::make_pair
#define _           << ' ' <<
// type-define
#define Stack       std::stack
#define Queue       std::queue
#define Deque       std::deque
#define PQueue      std::priority_queue
#define Set         std::set
#define Vector      std::vector
#define Pair        std::pair
#define Map         std::map
#define HashMap     std::unordered_map
#define Greater     std::greater
using String  =     std::string;
using llong   =     long long;
using boolean =     bool;
using Pii     =     Pair<int, int>;
using Vi      =     Vector<int>;
using Vii     =     Vector<Pii>;
// utils
constexpr int   dx[] = {1, 0, -1, 0, 1, 1, -1, -1};
constexpr int   dy[] = {0, 1, 0, -1, 1, -1, 1, -1};
constexpr int   INF  = 0x3f3f3f3f;
constexpr llong LINF = 0x3f3f3f3f3f3f3f3fLL;

namespace {
    template<class A, class B> A power ( llong x, llong n, llong mod ) {
        llong ans = 1;
        while ( n > 0 ) {
            if ( n & 1 ) ans = ( ans * x ) % mod;
            x = ( x * x ) % mod;
            n >>= 1;
        }
        return ans;
    }
    template<class A, class B> A power ( A x, B n ) { return power( x, n, 1000000007 ); }
    template<class A> A gcd ( A x, A y ) { return x % y ? gcd( y, x % y ) : y; }
    template<class A, class B> A lcm   ( A x,  B y ) { return ( x / gcd(x, y) * y ); }
    template<class A> inline A abs ( A n ) { return ( n < 0 ) ? -n : n; }
    template<class A, class B> inline bool chmax ( A &a, const B &b ) { return b > a ? a = b, true : false; }
    template<class A, class B> inline bool chmin ( A &a, const B &b ) { return b < a ? a = b, true : false; }
    inline boolean isMovable ( int x, int y, int w, int h ) {
        return ( x >= 0 && y >= 0 && x < w && y < h );
    }
}

namespace Rlyeh {

    int a[110];

    signed call_of_Cthulhu( signed datum ) {

        int n, q;
        read n >> q;
        for ( int i = 0; i < n; i++ ) {
            read a[i];
        }
        bozo_sort(a, a+n);
        for ( int i = 0; i < n; i++ ) {
            if ( a[i] <= q ) {
                q -= a[i];
            }
            else {
                echo i fin;
                return 0;
            }
        }
        if ( q ) echo n-1 fin;
        else echo n fin;

        return 0;
    }
}

signed main(){std::cin.tie(0); std::ios::sync_with_stdio(false); int main_result = Rlyeh::call_of_Cthulhu(114514); return 0;}


Measured memory_bytes: 384
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

import numpy as np
def main():
    N = int(readline())
    tasks = np.array(read().split(), np.int64).reshape((-1, 2))
    tasks = tasks[np.argsort(tasks[..., 1]), ...]
    tasks[..., 0] = np.add.accumulate(tasks[..., 0], axis=0)
    if np.all(tasks[..., 1]-tasks[..., 0]>=0):
        print('Yes')
    else:
        print('No')
if __name__ == '__main__':
    main()


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


int main(){
    string S;
    cin>>S;
    int cnt=0;
    for(int i=0;i<S.size();i++){
        if(S.at(i)=='1'){
            cnt++;
        }
    }
    cout <<cnt<<endl;
}


Measured memory_bytes: 3620
as = []
5.times do
  as << gets.to_i
end

tmp = 0
count = 0
as.each do |a|
  c = (10 - a % 10)
  unless c == 10
    count += c
    tmp = [c, tmp].max
  end
end

count -= tmp
puts as.reduce(0) {|a,e| a+=e} + count


Measured memory_bytes: 1788
import java.util.*

fun main(args: Array<String>) {
    val scanner = Scanner(System.`in`)
    val n = scanner.nextInt()
    val m = scanner.nextInt()
//    val A = Array(n,{IntArray(m)})
    val A = mutableListOf<MutableList<Int>>()
    var t:IntArray

    val maxArray = IntArray(m)

    for (i in 0..n - 1) {
        A.add(mutableListOf<Int>())
        for (j in 0..m - 1) {
            A[i].add(scanner.nextInt())
        }
    }

    for (i in 0..m - 1) {
        t = IntArray(m)
        for (j in 0..n - 1) {
            t[A[j][0]-1]++
        }

        maxArray[i] = t.max() as Int

        for (j in 0..n - 1) {
            A[j].remove(t.indexOf(t.max() as Int) + 1)
        }
    }

    println(maxArray.min())
}

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

using namespace std;

using ll = long long;

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  int N;
  cin >> N;
  vector<int> d(N);
  for (int i = 0; i < N; ++i) cin >> d[i];
  int ans = 0;
  for (int i = 0; i < N; ++i) {
    for (int j = i + 1; j < N; ++j) {
      ans += d[i] * d[j];
    } 
  }
  cout << ans << endl;
}


Measured memory_bytes: 256
#define _CRT_SECURE_NO_WARNINGS
#include<iostream>
#include<sstream>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<climits>
#include<cmath>
#include<string>
#include<vector>
#include<set>
#include<map>
#include<queue>
#include<numeric>
#include<functional>
#include<algorithm>
#include<bitset>
#include<tuple>
#include<unordered_set>
#include<unordered_map>
#include<random>
#include<array>
#include<cassert>
using namespace std;
#define INF (1<<29)
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define all(v) v.begin(),v.end()
#define uniq(v) v.erase(unique(all(v)),v.end())



int n;
int a[200000];

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


	cin >> n;
	rep(i, n)cin >> a[i];


	int ma = -1, cnt = 0, sec = -1;
	rep(i,n) {
		if (ma < a[i]) {
			sec = ma;
			ma = a[i];
			cnt = 1;
		}
		else if (ma == a[i]) {
			cnt++;
		}
		else if (sec < a[i]) {
			sec = a[i];
		}
	}


	rep(i,n) {
		if (ma == a[i] && cnt == 1) {
			cout << sec << endl;
		}
		else {
			cout << ma << endl;
		}
	}



	return 0;
}

Measured memory_bytes: 2432
#include<stdio.h>
#include<iostream>
#include<math.h>
using namespace std;
int main(void){
  int a=0,b=0,c=0,ans=0;
  
  cin>>a>>b;
  for(int i=0;c+1<b;i++){
    ans++;
    c=c+a-1;
  }
  cout<<ans;
  return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <cmath>
#include <algorithm>
#include <climits>
#include <vector>
#include <string>
#include <set>
#include <iomanip>
#include <map>
#define rep(i,n) for (int i=0;i<(n);++i)
using namespace std;
using ll = long long;
const int INF = 10000000;

int main(){
    ll n; cin >> n;
    vector<ll> a(n);
    int flag = 1, ans = 0;
    rep(i, n){
        cin >> a[i];
        if(flag == a[i]){
            ++ans;
            ++flag;
        }
    }
    if(ans != 0) cout << n - ans << endl;
    else cout << -1 << endl;
    return 0;
}


Measured memory_bytes: 1920
#include <bits/stdc++.h>
using namespace std;
int main()
{
	int a,b,c;
	cin >> a >> b >> c;
	if(a<=c && b>=c){
		cout << "Yes" << endl;
	}
	else{
		cout << "No" << endl;
	}
	return 0;
}
//int 整数
//char 文字
//string 文字列


Measured memory_bytes: 256
n, m, c = map(int, input().split())
b = list(map(int, input().split()))
anslist = []
figure = 0
ans = 0
for i in range(n):
    sourse = list(map(int, input().split()))
    anslist.append(sourse)
    sourse = []
for j in range(n):
    for k in range(m):
        figure += anslist[j][k]*b[k]
    if figure+c > 0:
        ans += 1
    else:
        pass
    figure = 0
print(ans)


Measured memory_bytes: 3064
#include<bits/stdc++.h>
using namespace std;
string s[200005];
int main()
{
    ios::sync_with_stdio(false);
    int n;
    cin>>n;
    for(int i=0;i<n;i++)
    {
        cin>>s[i];
    }
    sort(s,s+n);
    string s1="";
    long long ans=0;
    for(int i=0;i<n;i++)
    {
        if(s1!=s[i])
        {
            ans++;
            s1=s[i];
        }
    }
    cout<<ans;
}


Measured memory_bytes: 9876
#include <cstdio>
#include <iostream>
#include <sstream>
#include <fstream>
#include <iomanip>
#include <algorithm>
#include <cmath>
#include <string>
#include <vector>
#include <list>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <bitset>
#include <numeric>
#include <climits>
#include <cfloat>
using namespace std;

const double PI = acos(-1.0);
const double EPS = 1.0e-10;

int main()
{
    for(;;){
        double r;
        cin >> r;
        if(r <= EPS)
            return 0;

        for(int d=1; ; ++d){
            int n = d * PI + 0.5;
            if(abs((double)n / d - PI) < r){
                cout << n << '/' << d << endl;
                break;
            }
        }
    }
}

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

using namespace std;
using ll = long long;

int main() {
	string s;
	cin >> s;

	int o = 0, e = 0;
	for (int i = 0; i < s.size(); ++i) {
		if (i % 2 == 0) {
			if (s[i] == '1') { ++e; }
			if (s[i] == '0') { ++o; }
		}
		if (i % 2 == 1) {
			if (s[i] == '1') { ++o; }
			if (s[i] == '0') { ++e; }
		}
	}

	cout << min(o, e) << endl;

	return 0;
}


Measured memory_bytes: 512
#include <iostream>
#include <stdio.h>

using namespace std;

int main(){
    double a,b,c,d,e,f,x,y;
    while (cin>>a>>b>>c>>d>>e>>f){
        x=(c*e-b*f)/(a*e-d*b);
        y=(f*a-c*d)/(e*a-b*d);
        if(x==0) x=0.0;
        if(y==0) y=0.0;
        printf("%.3f %.3f\n",x,y);
    }
}

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

using namespace std;

#define print(s) cout << (s) << endl;
#define sp(x) cout<<setprecision(x);
#define rep(i,n)  for (int i = 0; i < (n); i++)
#define all(a) a.begin(), (a).end()
#define gre(t) greater<t>()
 
int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    int x, y; cin>>x>>y;
    cout<<x + (y/2)<<endl;
}

Measured memory_bytes: 256
#https://atcoder.jp/contests/abc163/tasks/abc163_c
# -*- coding: utf-8 -*-
N = int(input())
A = input().split()
for i in range(len(A)):
  A[i] = int(A[i])
# A.insert(0,0)
buka = [0]*N
for i in range(len(A)):
  tmp = A[i]-1
  buka[tmp] += 1
for i in range(len(buka)):
  print(buka[i])

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

using namespace std;
#define  ll long long
#define ld long double
#define f first
#define s second

ll n,k,a[55];

ll solve(ll len)
{
    ll tmp=0 , rem , sum=0 , curSum=0;
    priority_queue<ll , vector<ll> , greater<ll> >q;

    for(int i=0; i<=len; i++)
    {
        while(q.size()) q.pop();
        sum=0;
        for(int j=1; j<=i; j++)
        {
            q.push(a[j]) , sum += a[j];
        }
        rem = len-i;
        for(int j=n; j>n-rem; j--)
        {
            q.push(a[j]) , sum += a[j];
        }
        rem = k-len;
        while(q.size() && q.top() <= 0 && rem)
        {
            rem--;
            sum -= q.top();
            q.pop();
        }
        tmp = max(tmp , sum);
    }
    return tmp;
}

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

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

    ll ans = 0;
    for(int i=1; i<=min(n,k); i++)
    {
        ans = max(ans , solve(i));
    }

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

Measured memory_bytes: 3600
#pragma GCC optimize("O3")
#include <bits/stdc++.h>
#define ll long long
#define rep(i,n) for(ll i=0;i<(n);i++)
#define pll pair<ll,ll>
#define pq priority_queue
#define pb push_back
#define eb emplace_back
#define fi first
#define se second
#define ios ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0);
#define lb(c,x) distance(c.begin(),lower_bound(all(c),x))
#define ub(c,x) distance(c.begin(),upper_bound(all(c),x))

using namespace std;

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 ll mod=1e9+7;

int main()
{
    ll n;
    cin >> n;
    char c;
    bool ok=true;
    set<string> sum;
    rep(i,n){
        string s;
        cin >> s;
        sum.insert(s);
        ll m=s.length();
        if(i==0){
            c=s[m-1];
            continue;
        }
        if(c!=s[0]){
            ok=false;
        }
        c=s[m-1];
    }
    if(ok && sum.size()==n) cout << "Yes" << endl;
    else cout << "No" << endl;
    return 0;
} 

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

int main() {
  string S;
  cin >> S;
  int N = S.length();
  vector<int> vec(N+1);
  for(int i = 0; i < N; i++){
    if(S[i]=='<') vec.at(i+1) = vec.at(i) + 1;
  }
  for(int i = N-1; i >= 0; i--){
    if(S[i]=='>') vec.at(i) = max(vec.at(i),vec.at(i+1)+1);
  }
  long long ans = 0;
  for(int i = 0; i <= N; i++){
    ans += vec.at(i);
  }
  cout << ans;
}

Measured memory_bytes: 2820
n, k = map(int, input().split())
info = [list(input().split()) for i in range(n)]

cnt_b = [[0]*k for i in range(k)]
cnt_w = [[0]*k for i in range(k)]

for i in range(n):
    x, y, c = info[i]
    x, y = int(x), int(y)
    move_cnt = (x//k) + (y//k)
    if move_cnt % 2 == 0:
        if c == "B":
            cnt_b[x % k][y % k] += 1
        if c == "W":
            cnt_w[x % k][y % k] += 1
    else:
        if c == "B":
            cnt_w[x % k][y % k] += 1
        if c == "W":
            cnt_b[x % k][y % k] += 1

ruiseki_b = [[0]*(k+1) for i in range(k+1)]
ruiseki_w = [[0]*(k+1) for i in range(k+1)]
for i in range(k):
    for j in range(k):
        ruiseki_b[i+1][j+1] = ruiseki_b[i+1][j] + cnt_b[i][j]
        ruiseki_w[i+1][j+1] = ruiseki_w[i+1][j] + cnt_w[i][j]
for j in range(k):
    for i in range(k):
        ruiseki_b[i+1][j+1] += ruiseki_b[i][j+1]
        ruiseki_w[i+1][j+1] += ruiseki_w[i][j+1]
ans = 0
for i in range(k+1):
    for j in range(k+1):
        ans_b = ruiseki_b[k][k] - ruiseki_b[i][k] - ruiseki_b[k][j] + 2*ruiseki_b[i][j]
        ans_w = ruiseki_w[i][k] + ruiseki_w[k][j] - 2*ruiseki_w[i][j]
        ans = max(ans_w + ans_b, ans)
        ans_w = ruiseki_w[k][k] - ruiseki_w[i][k] - ruiseki_w[k][j] + 2*ruiseki_w[i][j]
        ans_b = ruiseki_b[i][k] + ruiseki_b[k][j] - 2*ruiseki_b[i][j]
        ans = max(ans_w + ans_b, ans)
print(ans)

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

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

    int A, B;
    cin >> A >> B;

    int ans = max(ans, A+A-1);
    ans = max(ans, B+B-1);
    ans = max(ans, A+B);

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#pragma GCC optimize("O2")
using namespace std;
#define FASTIO ios_base::sync_with_stdio(false), cin.tie(0)
//#define MULTI_TEST
//#define GOOGLE
#ifdef LOCAL
#include "debugger.h"
#else
#define db(...)
#endif
#define ll long long
#define v32 vector<int>
#define v64 vector<ll>
#define s32 set<int>
#define s64 set<ll>
#define p32 pair<int, int>
#define p64 pair<ll, ll>
#define sz(v) (ll)(v).size()
#define fi first
#define se second
#define ln '\n'
const ll MOD = 1e9 + 7;
inline ll add(ll a, ll b, ll m) { return (((a % m + b % m) % m + m) % m); }
inline ll mul(ll a, ll b, ll m) { return (((a % m * b % m) % m + m) % m); }

const int N = 2005;
ll dp[N][N];

ll go(int i, int j, int n, vector<p64> &arr)
{
	if (i > j)
		return 0;
	if (dp[i][j] != -1)
		return dp[i][j];
	int idx = n - (j - i + 1) + 1;
	ll ans = arr[idx].fi * abs(arr[idx].se - i) + go(i + 1, j, n, arr);
	ans = max(ans, arr[idx].fi * abs(j - arr[idx].se) + go(i, j - 1, n, arr));
	return dp[i][j] = ans;
}

void solve()
{
	int n;
	cin >> n;
	vector<p64> arr(n + 1);
	for (int i = 1; i < n + 1; i++)
		cin >> arr[i].fi, arr[i].se = i;
	sort(arr.begin(), arr.end());
	reverse(arr.begin() + 1, arr.end());
	db(arr);
	memset(dp, -1, sizeof(dp));
	cout << go(1, n, n, arr) << ln;
	return;
}

int main()
{
	FASTIO;
	int t = 1;
#ifdef LOCAL
	clock_t start, stop;
	start = clock();
#endif
#ifdef MULTI_TEST
	cin >> t;
#endif
	for (int tc = 1; tc < t + 1; tc++)
	{
#ifdef GOOGLE
		cout << "Case #" << tc << ": ";
#endif
		solve();
	}
#ifdef LOCAL
	stop = clock();
	cerr << "Time :" << fixed << setprecision(5) << double(stop - start) / double(CLOCKS_PER_SEC) << "s" << ln;
#endif
	return 0;
}


Measured memory_bytes: 35212
use std::io::Read;

fn main() {
    let mut buf = String::new();
    std::io::stdin().read_to_string(&mut buf).unwrap();

    let answer = solve(&buf);

    println!("{}", answer);
}

fn solve(input: &str) -> String {
    let mut iterator = input.split_whitespace();

    let x: usize = iterator.next().unwrap().parse().unwrap();

    if x == 0 {
        "1".to_string()
    } else {
        "0".to_string()
    }
}


Measured memory_bytes: 2104
#include <iostream>
#include <algorithm>
#include <vector>
#include <queue>
#include <map>
#include <unordered_map>
#include <set>
using namespace std;

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

    unsigned long long N, A, B;
    cin >> N >> A >> B;
    vector<unsigned long long> X(N);
    for(int i=0; i<N; i++) cin >> X[i];

    unsigned long long ans = 0;
    for(int i=1; i<N; i++){
        unsigned long long walk = (X[i] - X[i-1]) * A;
        if(walk < B) ans += walk;
        else ans += B;
    }
    cout << ans << endl;


    return 0;
}


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

using namespace std;

int main()
{
    int a = 0;
    int b = 0;
    int k = 0;

    cin >> a >> b >> k;

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

    return 0;
}


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

int main(){
    double n,t,a;
    int ans;
    double mi=inf;
    cin >> n >> t >> a;
    rep(i,n){
        double h;
        cin >> h;
        double sub=abs(a-(t-h*0.006));
        if(mi>sub){
            mi=sub;
            ans=i+1;
        }
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 256
package main

import "fmt"

func main() {
	var str string
	fmt.Scan(&str)
	var strLen = len(str)
	var flag bool
	for i := 1; i < strLen; i++ {
		if str[i] == str[i-1] {
			flag = true
		}
	}
	if flag {
		fmt.Println("Bad")
	} else {
		fmt.Println("Good")
	}
}


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

int main(){
	vector<int> a(4);
  	cin>>a[0]>>a[1]>>a[2]>>a[3];
  	sort(a.begin(),a.end());
  	if(a[0]==1 && a[1]==4 && a[2]==7 && a[3]==9){
    	cout<<"YES"<<endl;
    }else{
    	cout<<"NO"<<endl;
    }
}    


Measured memory_bytes: 256
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.Arrays;
import java.util.HashSet;
import java.util.StringTokenizer;

public class Main {

  public static void main(String[] args) {
    InputReader in = new InputReader(System.in);
    PrintWriter out = new PrintWriter(System.out);

    int n = in.nextInt();

    HashSet<Integer> ns = new HashSet<>();

    int res = 1;

    while (!ns.contains(n)) {
      ns.add(n);
      if (n % 2 == 0)
        n /= 2;
      else
        n = 3 * n + 1;
      res++;
    }

    out.println(res);

    out.close();
  }

  static class InputReader {
    public BufferedReader reader;
    public StringTokenizer tokenizer;

    public InputReader(InputStream stream) {
      reader = new BufferedReader(new InputStreamReader(stream), 32768);
      tokenizer = null;
    }

    public String next() {
      while (tokenizer == null || !tokenizer.hasMoreTokens()) {
        try {
          tokenizer = new StringTokenizer(reader.readLine());
        } catch (IOException e) {
          throw new RuntimeException(e);
        }
      }
      return tokenizer.nextToken();
    }

    public int nextInt() {
      return Integer.parseInt(next());
    }

    public long nextLong() {
      return Long.parseLong(next());
    }

    public double nextDouble() {
      return Double.parseDouble(next());
    }
  }

  static void print(int[] arr) {
    Arrays.stream(arr).forEach(i -> System.out.print(i + " "));
    System.out.println();
  }

  static class Pair implements Comparable<Pair> {
    int x;
    int y;

    Pair(int x, int y) {
      this.x = x;
      this.y = y;
    }

    @Override
    public int compareTo(Pair o) {
      int compareX = Integer.compare(x, o.x);
      return (compareX == 0) ? Integer.compare(y, o.y) : compareX;
    }

    @Override
    public int hashCode() {
      int res = 7;
      res = 31 * res + x;
      res = 31 * res + y;
      return res;
    }

    @Override
    public boolean equals(Object o) {
      if (o instanceof Pair) {
        return hashCode() == o.hashCode();
      }
      return false;
    }

    @Override
    public String toString() {
      return "(" + x + ", " + y + ")";
    }

  }

}



Measured memory_bytes: 21332
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(ll i=0;i<n;i++)
#define rep1(i,n) for(int i=1;i<n+1;i++)
#define sort(A) sort(A.begin(),A.end())
#define reverse(A) reverse(A.begin(),A.end())
typedef long long ll;
typedef pair<int,int> P;

int main(){
  const int INF = pow(10,9)+7;
  int n;
  cin >>n;
  vector<ll> A(n);
  rep(i,n){
    cin >> A[i];
  }
  ll ans = 0;
  rep(i,60){
    ll x = 0;
    rep(j,n) if(A[j]>>i&1) x++;
    ll now = x*(n-x);
    rep(j,i) now = now*2%INF;
    ans += now;
    ans %= INF;
  }
  cout << ans << endl;
}

Measured memory_bytes: 2560
package main

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

var sc = bufio.NewReaderSize(os.Stdin, 1024*1024*1)

type kakko struct {
	str string
	min int
	max int
}

func main() {
	N := getStdinInt()
	F := make([]kakko, 0, N)
	L := make([]kakko, 0, N)
	for i := 0; i < N; i++ {
		s := getStdin()
		min, max := minMaxKakko(s)
		if min >= 0 {
			F = append(F, kakko{s, min, max})
		} else {
			L = append(L, kakko{s, min, max})
		}
	}
	sort.Slice(F, func(i, j int) bool { return F[i].max-F[i].min < F[j].max-F[j].min })
	sort.Slice(L, func(i, j int) bool { return L[i].max > L[j].max })

	K := make([]kakko, N)
	for i := 0; i < len(F); i++ {
		K[i] = F[i]
	}
	for i := 0; i < len(L); i++ {
		K[i+len(F)] = L[i]
	}

	first := -1
	last := -1
	for i := 0; i < len(K); i++ {
		if K[i].str[0] == '(' {
			first = i
			break
		}
	}
	for i := len(K) - 1; i >= 0; i-- {
		if i != first && K[i].str[len(K[i].str)-1] == ')' {
			last = i
			break
		}
	}

	if first == -1 || last == -1 {
		fmt.Printf("No\n")
		return
	}

	stack := 0
	stack = okKakko(K[first].str, stack)
	if stack < 0 {
		fmt.Printf("No\n")
		return
	}

	for i := 0; i < len(K); i++ {
		if first == i || last == i {
			continue
		}
		stack = okKakko(K[i].str, stack)
		if stack < 0 {
			fmt.Printf("No\n")
			return
		}
	}

	stack = okKakko(K[last].str, stack)
	if stack < 0 {
		fmt.Printf("No\n")
		return
	}

	if stack == 0 {
		fmt.Printf("Yes\n")
	} else {
		fmt.Printf("No\n")
	}
}

func minMaxKakko(s string) (int, int) {
	stack := 0
	min := math.MaxInt32
	max := math.MinInt32
	for i := 0; i < len(s); i++ {
		if s[i] == '(' {
			stack++
			if stack > max {
				max = stack
			}
		}
		if s[i] == ')' {
			stack--
			if stack < min {
				min = stack
			}
		}
	}
	return min, max
}

func okKakko(s string, stack int) int {
	for i := 0; i < len(s); i++ {
		if s[i] == '(' {
			stack++
		}
		if s[i] == ')' {
			stack--
		}
		if stack < 0 {
			return -1
		}
	}
	return stack
}

func getStdin() string {
	return readLine()
}
func getStdinArr() []string {
	str := getStdin()
	list := strings.Split(str, " ")
	return list
}
func getStdinInt() int {
	str := getStdin()
	rtn, _ := strconv.Atoi(str)
	return rtn
}
func getStdinIntArr() []int {
	str := getStdin()
	list := strings.Split(str, " ")
	rtn := make([]int, len(list))
	for idx, val := range list {
		rtn[idx], _ = strconv.Atoi(val)
	}
	return rtn
}

func getStdinIntArr64() []int64 {
	str := getStdin()
	list := strings.Split(str, " ")
	rtn := make([]int64, len(list))
	for idx, val := range list {
		rtn[idx], _ = strconv.ParseInt(val, 10, 64)
	}
	return rtn
}

func readLine() string {
	buf := make([]byte, 0, 0)
	for {
		l, p, e := sc.ReadLine()
		if e != nil {
			panic(e)
		}
		buf = append(buf, l...)
		if !p {
			break
		}
	}
	return string(buf)
}


Measured memory_bytes: 76668
N = int(input())
A = [int(input()) for _ in range(N)]
A.sort()

if N % 2 == 0:
    s = N//2
    d = -2 * sum(A[:s]) + A[s-1] - A[s] + 2 * sum(A[s:])
else:
    s = N//2
    d1 = -2 * sum(A[:s]) - A[s] - A[s+1] + 2 * sum(A[s:])
    s += 1
    d2 = -2 * sum(A[:s]) + A[s-2] + A[s-1] + 2 * sum(A[s:])
    d = max(d1, d2)

print(d)


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

const int N = 55;
int n, p;

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    cin >> n >> p;
    bool odd = false;
    for(int i = 1; i <= n; i++) {
        int c;
        cin >> c;
        if(c & 1) odd = true;
    }
    ll ans = 0;
    if(odd) {
        ans = 1LL << (n - 1);
    } else if(!p) {
        ans = 1LL << n;
    }
    cout << ans << endl;
    return 0;
}

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

using namespace std;

typedef long long ll;

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

	int n, m;
	cin >> n >> m;

	vector<int> a(n);
	int sm = 0;
	rep(i, n){
		cin >> a[i];
		sm += a[i];
	} 

	int cnt = 0;
	rep(i, n){
		if(a[i] * 4 * m >= sm) cnt++;
	}

	if(cnt >= m){
		puts("Yes");
	}else{
		puts("No");
	}

}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <stack>
#include <algorithm>
#include <numeric>
#include <math.h>
#include <stdio.h>
#include <ctype.h>
using namespace std;

#define N_MAX   (100000)
#define LL_MAX_NUM (1LL<<60)
#define INF 1e7

typedef long long ll;
typedef long long int lli;

void chmin(int &a, int b) { if (a > b) a = b; }

int N, A, B, C;
vector<int> L;

int rec(int i, int a, int b, int c) {
    if (i == N) {
        if (!a || !b || !c) return INF; 
        return abs(a - A) + abs(b - B) + abs(c - C);
    }
    int res = rec(i+1, a, b, c);
    
 
    chmin(res, rec(i+1, a + L[i], b, c) + (a ? 10 : 0));
    chmin(res, rec(i+1, a, b + L[i], c) + (b ? 10 : 0));
    chmin(res, rec(i+1, a, b, c + L[i]) + (c ? 10 : 0));
    
    return res;
}

int main() {

    cin >> N >> A >> B >> C;
    L.resize(N);
    for (int i = 0; i< N; ++i) cin >> L[i];
    
    cout << rec(0, 0, 0, 0) << endl;
}



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

int main() {
  int a, b, c, d;
  cin >> a >> b >> c >> d;
  bool flag = false;
  if(abs(a-c)<=d) flag = true;
  else if(abs(a-b)<=d && abs(b-c)<=d) flag = true;
  
  if(flag) cout << "Yes" << endl;
  else cout << "No" << endl;
}

Measured memory_bytes: 3624
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#include<list>
#include<set>
#include<map>
#include<utility>


#define rep(i,x) for(int i=0;i<(int)(x);i++)
#define reps(i,x) for(int i=1;i<=(int)(x);i++)
#define rrep(i,x) for(int i=((int)(x)-1);i>=0;i--)
#define rreps(i,x) for(int i=((int)(x));i>0;i--)

#define all(x) (x).begin(),(x).end()
#define SZ(x) ((int)(x).size())
#define INF 2e9

template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
typedef long long ll;
int gcd(int a,int b){return b?gcd(b,a%b):a;}

using namespace std;

int main()
{
    int n;
    cin >> n;
    vector<int> v(n), c(n);

    rep(i, n){
        cin >> v[i];
    }
    rep(i, n) cin >> c[i];

    ll ans = 0;
    rep(i, n){
        if(v[i] >= c[i]) ans += v[i] - c[i];
    }

    cout << ans;

}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
typedef long long ll;
#define rep(i, n) for(ll i = 0; i < n; i++)
#define rep2(i, s, n) for(ll i = s; i < n; i++)
using namespace std;

int main(){
  int n, k;
  cin >> n >> k;
  vector<ll> a(n);
  rep(i, n) cin >> a[i];
  
  ll min = 10000000000000;
  rep(i, 1<<(n-1)){
    int num = 0;
    vector<int> choice;
    rep(j, n-1){
      if (i>>j&1){
        num++;
        choice.push_back(j+1);
      }
    }
    if (num != k-1) continue;
    ll now = a[0];
    ll cash = 0;
    rep(j, num){
      rep2(x, 1, choice[j]){
        if (now < a[x])
          now = a[x];
      }
      if (now < a[choice[j]]){
        now = a[choice[j]];
      }
      else {
        now++;
        cash += now - a[choice[j]];
      }
    }
    if (cash < min)
      min = cash;
  }
  cout << min << endl;
  
  return 0;
}

Measured memory_bytes: 256
#include <cstdio>
#include <string>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <list>
#include <iterator>
#include <cassert>
#include <numeric>
#include <functional>
#include <cassert>
//#include <numeric>
#pragma warning(disable:4996) 
 
typedef long long ll;
#define MIN(a, b) ((a)>(b)? (b): (a))
#define MAX(a, b) ((a)<(b)? (b): (a))
#define LINF  9223300000000000000
#define LINF2 1223300000000000000
#define INF 2140000000
const long long MOD = 1000000007;
//const long long MOD = 998244353;

using namespace std;



void solve()
{
    int s, w;
    scanf("%d%d", &s, &w);
    if (s <= w) {
        printf("unsafe\n");
    }
    else {
        printf("safe\n");
    }

    return;
}

int main(int argc, char* argv[])
{
#if 1
    solve();
#else
    int T;
    scanf("%d", &T);
    int t;
    for(t=0; t<T; t++) {
        //printf("Case #%d: ", t+1);
        solve();
    }
#endif
    return 0;
}



Measured memory_bytes: 1664
/**
 * code generated by JHelper
 * More info: https://github.com/AlexeyDmitriev/JHelper
 * @author aajisaka
 */

#include<bits/stdc++.h>

using namespace std;

void debug_out() { cerr << endl; }
template <typename Head, typename... Tail>
void debug_out(Head H, Tail... T) {
  cerr << " " << to_string(H);
  debug_out(T...);
}
#ifdef LOCAL
#define debug(...) cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)
#else
#define debug(...) 42
#endif

#define SPEED ios_base::sync_with_stdio(false);cin.tie(nullptr)
#define rep(i,n) for(int i=0; i<(int)(n); i++)
#define all(v) v.begin(), v.end()
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }

using ll = long long;
using ull = unsigned long long;
using P = pair<ll, ll>;

constexpr long double PI = 3.14159265358979323846264338327950288L;
mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count());

class ELogs {
public:

    int getCnt(double d, vector<int>& a) {
      int ret = 0;
      for(auto e: a) {
        ret += floor(e/d);
      }
      return ret;
    }

    void solve(istream& cin, ostream& cout) {
      SPEED;
      int n, k; cin >> n >> k;
      vector<int> a(n);
      double ma = 0;
      rep(i, n) {
        cin >> a[i];
        chmax(ma, (double)a[i]);
      }

      double mi = 0.1;

      rep(i, 50) {
        double med = (mi+ma)/2;
        int cnt = getCnt(med, a);
        if (cnt > k) {
          mi = med;
        } else {
          ma = med;
        }
      }

      /*
      int ans2 = floor(mi);
      if (getCnt(ans2, a) <= k) {
        cout << ans2 << endl;
        return;
      }*/

      int ans = ceil(mi);
      cout << ans << endl;
    }
};

signed main() {
  ELogs solver;
  std::istream& in(std::cin);
  std::ostream& out(std::cout);
  solver.solve(in, out);
  return 0;
}

Measured memory_bytes: 3956
#include <iostream>
#include <numeric>
#include <vector>

template <class T>
std::vector<T> vec(int len, T elem) { return std::vector<T>(len, elem); }

template <int MOD>
struct ModInt {
    using lint = long long;
    int val;

    // constructor
    ModInt(lint v = 0) : val(v % MOD) {
        if (val < 0) val += MOD;
    };

    // unary operator
    ModInt operator+() const { return ModInt(val); }
    ModInt operator-() const { return ModInt(MOD - val); }
    ModInt inv() const { return this->pow(MOD - 2); }

    // arithmetic
    ModInt operator+(const ModInt& x) const { return ModInt(*this) += x; }
    ModInt operator-(const ModInt& x) const { return ModInt(*this) -= x; }
    ModInt operator*(const ModInt& x) const { return ModInt(*this) *= x; }
    ModInt operator/(const ModInt& x) const { return ModInt(*this) /= x; }
    ModInt pow(lint n) const {
        auto x = ModInt(1);
        auto b = *this;
        while (n > 0) {
            if (n & 1) x *= b;
            n >>= 1;
            b *= b;
        }
        return x;
    }

    // compound assignment
    ModInt& operator+=(const ModInt& x) {
        if ((val += x.val) >= MOD) val -= MOD;
        return *this;
    }
    ModInt& operator-=(const ModInt& x) {
        if ((val -= x.val) < 0) val += MOD;
        return *this;
    }
    ModInt& operator*=(const ModInt& x) {
        val = lint(val) * x.val % MOD;
        return *this;
    }
    ModInt& operator/=(const ModInt& x) { return *this *= x.inv(); }

    // compare
    bool operator==(const ModInt& b) const { return val == b.val; }
    bool operator!=(const ModInt& b) const { return val != b.val; }

    // I/O
    friend std::istream& operator>>(std::istream& is, ModInt& x) noexcept { return is >> x.val; }
    friend std::ostream& operator<<(std::ostream& os, const ModInt& x) noexcept { return os << x.val; }
};

constexpr int MOD = 1e9 + 7;
using mint = ModInt<MOD>;

void solve() {
    int n, k;
    std::cin >> n >> k;

    const int X = n * (n + 1) / 2;
    std::vector<mint> dp(X + 1, 0), pat(X + 1, 0);
    pat[0] = 1;

    auto ndp = dp, npat = pat;
    for (int i = n; i >= 1; --i) {
        std::fill(ndp.begin(), ndp.end(), 0);
        std::fill(npat.begin(), npat.end(), 0);

        for (int c = 0; c <= X; ++c) {
            for (int a = 0; a <= k; ++a) {
                int nc = (a > i ? 0 : (a + c) / i);
                if (c + nc > X) continue;

                ndp[c + nc] += dp[c] + pat[c] * (a - nc);
                npat[c + nc] += pat[c];
            }
        }

        std::swap(dp, ndp);
        std::swap(pat, npat);
    }

    std::cout << std::accumulate(dp.begin(), dp.end(), mint(0)) << std::endl;
}

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

    solve();

    return 0;
}


Measured memory_bytes: 384
from collections import deque

H, W = map(int, input().split())
m = [list(input()) for i in range(H)]
ans = 0

for h in range(H):
  for w in range(W):
    if m[h][w] == "#": continue
    q = deque([(h, w, 0)])
    used = set()
    while q:
      h, w, c = q.popleft()
      if (h, w) in used: continue
      ans = max(ans, c)
      if 0 <= h-1 and m[h-1][w] == "." and (h-1, w) not in used: q.append((h-1, w, c+1))
      if h+1 < H  and m[h+1][w] == "." and (h+1, w) not in used: q.append((h+1, w, c+1))
      if 0 <= w-1 and m[h][w-1] == "." and (h, w-1) not in used: q.append((h, w-1, c+1))
      if w+1 < W  and m[h][w+1] == "." and (h, w+1) not in used: q.append((h, w+1, c+1))
      used.add((h, w))
print(ans)

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

// 型定義
typedef long long ll;
typedef pair<ll, ll> P;

// forループ
#define REP(i,n) for(ll i=0; i<(ll)(n); ++i)

// 定数宣言
const int INF = 1e9;
const int MOD = 1e9+7;
const ll LINF = 1e18;

// グラフ表現
using Graph = vector<vector<int>>;

// グラフの辺表現
using Edge = map<pair<int,int>,int>;

// n次元配列の初期化。第２引数の型のサイズごとに初期化していく。
template<typename A, size_t N, typename T>
void Fill(A (&array)[N], const T &val){
    std::fill( (T*)array, (T*)(array+N), val );
}

// 最大公約数
ll gcd(ll a,ll b){
   if (a%b == 0) return(b);
   else return(gcd(b, a%b));
}

// 最小公倍数
ll lcm(ll a, ll b){
    return a*b/gcd(a, b);
}

int main()
{
    cout << fixed << setprecision(15);
    ll A, B, C;
    ll K;
    cin >> A >> B >> C;
    cin >> K;

    ll M = max({A, B, C});
    cout << ll(M*pow(2,K) - M + A + B + C) << endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main () {
	ios::sync_with_stdio(false);
	int a, b, c, d, e, f;
	cin >> a >> b >> c >> d >> e >> f;
	a *= 100; b *= 100;
	double dis = 0; int mt = 0, ms = 0;
	for (int i = 0; i * a <= f; i++)
		for (int j = 0; i * a + j * b <= f; j++) {
			int water = i * a + j * b;
			for (int k = 0; k * c * 100 <= e * water && water + k * c <= f; k++)
				for (int l = 0; (k * c + l * d) * 100 <= e * water && water + k * c + l * d <= f; l++) {
					int sugar = k * c + l * d;
					if (!water && !sugar) continue;
					if (1. * sugar / (sugar + water) > dis)
						dis = 1. * sugar / (sugar + water),
						mt = sugar + water, ms = sugar;
				}
		}
	if (!mt) mt = a;
	cout << mt << ' ' << ms << endl;
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#define rep(i,a) for(i = 0; i < a; i++)
using namespace std;


bool binarysearch(int *S, int key, int n) {
  int left = 0, right = n, mid = 0;
  while(left < right) {
    mid = (left + right) / 2;
    if(S[mid] == key) {
      return true;
    } else if(key < S[mid]) {
      right = mid;
    } else {
      left = mid + 1;
    }
  }
  return false;
}

int main(void) {

  int i,j,n,q,T,C;
  cin >> n;

  int S[n];
  rep(i,n) {
    cin >> S[i];
  }

  cin >> q;
  C = 0;
  rep(i,q) {
    cin >> T;
    if(binarysearch(S,T,n)) C++;
  }
  cout << C << endl;
  return 0;
}

Measured memory_bytes: 1548
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <iomanip>
#include <cmath>
#include <map>
#include <ctype.h>
using namespace std;

typedef long long ll;

int dx[4] = { 0, -1, 1, 0 };
int dy[4] = { -1, 0, 0, 1 };

int main() {
  string s;
  cin >> s;
  int res = 700;
  for (int i = 0; i != s.size(); ++i) {
    if (s[i] == 'o') res += 100;
  }
  cout << res << endl;
  return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define ld long double
#define mod 1000000007
#define mod2 1000000000
#define mod1 998244353
#define lol ios_base::sync_with_stdio(false);cin.tie(NULL);
#define all(x) (x).begin(), (x).end()
#define F(i, n) for (ll (i) = 0; (i) < (n); (i)++)
#define pb push_back
#define pf push_front
#define mp make_pair
#define f first
#define ss second


int main()
{
    ll n;cin >> n;
    ll fl = 0;
    ll md = 1e18; 
    ll arr[n];
    for(ll i=0;i<n;i++)
    {
        ll x;cin >> x;
        if(x==0) fl = 1;
        arr[i] = x;
    }
    if(fl)
    {
        cout << 0 << endl;
        return 0;
    }
    ll xx = 0;
    ll ans = 1;
    for(ll i=0;i<n;i++)
    {
        if (ans > md / arr[i])
        {
            xx = 1;
            break;
        }
        else
        {
            ans = ans *arr[i];
        }
    }
    if(xx)
    {
        cout << -1 << endl;
        return 0;
    }
    cout << ans << endl;
}
    

Measured memory_bytes: 4400
import numpy as np
# import math
import sys
input = sys.stdin.readline

def main():
    N = int(input())
    A = list(map(int,input().split()))

    A = np.array(A,np.int64)

    mod = 10**9 + 7

    res = 0

    for i in range(60):
        count = np.count_nonzero(A & 1)
        res += (N - count) * count * 2 ** i
        res %= mod
        A >>= 1

    print(res)

main()


Measured memory_bytes: 48784