akhauriyash/Code-Regression huggingface dataset:
import fractions
def main():
    n, X = map(int,input().split())
    x = list(map(int,input().split()))
    sub = []
    min_s = 0
    for i, xx in enumerate(x):
        sub.append(abs(xx-X))

    min_s = min(sub)
    ans = 1
    flg = True
    s = list(set(sub))
    if X == 1:
        print(sub[0])
        return
    ans = s[0]
    for i, ss in enumerate(s):
        if i == 0:
            continue
        ans = fractions.gcd(ans,ss)

    print(ans)



if __name__ =='__main__':
    main()


Measured memory_bytes: 19952
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define rep(i,n) for(int i=0;i<n;i++)
#define elif else if
string a;
signed main()
{
	cin>>a;
	if(a[0]=='Y'&&a[1]=='A'&&a[2]=='K'&&a[3]=='I'){
		cout<<"Yes";
	}else{
		cout<<"No";
	}
}

Measured memory_bytes: 256
def main():
	N, W = map(int, input().split())
	WV = [list(map(int, input().split())) for _ in range(N)]

	dp = [0] * (W + 1)
	#for n in range(N):
	#	w, v = WV[n]
	for w, v in WV:
		for sumw in range(W, w - 1, -1):
			#dp[sumw] = max([dp[sumw], dp[sumw - w] + v])
			t = dp[sumw - w] + v
			if dp[sumw] < t:
				dp[sumw] = t
		#for x in dp:
		#	print("{:4d}".format(x), end="")
		#print()
	return max(dp)

print(main())


Measured memory_bytes: 9716
#include <bits/stdc++.h>
#define rep(i,n) for (int i=0;i<(n);i++)
using namespace std;
using ll = long long;
using P = pair<int,int>;
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 ll INF = 1LL << 60;

int main() {

    ll N,M;
    cin >> N >> M;

    ll L[M],R[M];
    rep(i,M){
        cin >> L[i] >> R[i];
    }

    ll maxL = 0;
    ll minR = N;

    rep(i,M){
        if(maxL < L[i]){
            maxL = L[i];
        }
        if(minR > R[i]){
            minR = R[i];
        }
    }

    ll ans = minR - maxL + 1;
    if(ans >= 0){
        cout << ans << endl;
        return 0;
    }

    cout << 0 << endl;


}

Measured memory_bytes: 5076
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <utility>
#include <numeric>
#include <map>
#include <array>
using namespace std;
//変数デバッグ
#define DEB(variable) cout << #variable << '=' << variable << endl
 
//for簡易表記(引数ミス防止)
#define FOR(LoopVariable,numberOFbegin,numberOFend) for (int LoopVariable = (numberOFbegin); (LoopVariable) < (numberOFend); (LoopVariable)++)
#define REP(LoopVariable,numberOFend) for(int LoopVariable = 0;(LoopVariable)<(numberOFend);LoopVariable++)
 
 
int main(){
 
    int n;
    scanf("%d",&n);
    vector<int> mp(100100);
    int tmp;
    while(n--){
        scanf("%d", &tmp);
        mp[tmp]++;
        mp[tmp+2]++;
        mp[tmp+1]++;
    }
    int result=0;
    for(auto &x:mp){
        result=max(result,x);
    }
    cout << result << endl;
    return 0;
}

Measured memory_bytes: 640
/*
title:

url:
*/

#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <functional>
#include <queue>
#include <limits>
#include <string>
#include <utility>
#include <cstring>
#include <map>
#include <cmath>
#include <iterator>

using namespace std;

#define rep(i, n) for (int i = 0; i < (n); i++)
#define INF 1000000007

typedef pair<int, int> pint;
typedef long long ll;

#define int ll

//get vector of prime numbers which is lower than or equal n
vector<int> get_primes(int n)
{
    vector<bool> is_prime(n + 1, true);
    vector<int> res;
    is_prime[0] = is_prime[1] = false;
    for (int i = 2; i <= n; i++)
    {
        if (is_prime[i])
        {
            res.push_back(i);
            for (int j = 2 * i; j < is_prime.size(); j = j + i)
            {
                is_prime[j] = false;
            }
        }
    }
    return res;
}

vector<pair<int, int>> factorize(int n)
{
    vector<pair<int, int>> res;
    for (int i = 2; i * i <= n; i++)
    {
        int tmp = 0;
        while (n % i == 0)
        {
            tmp++;
            n /= i;
        }
        res.push_back(make_pair(i, tmp));
    }
    if (n != 1)
    {
        res.push_back(make_pair(n, 1));
    }
    return res;
}

int mpow(int x, int n)
{
    int res = 1;
    while (n != 0)
    {
        if (n & 1)
            res = res * x % INF;
        x = x * x % INF;
        n = n >> 1;
    }
    return res;
}

//mod frac
vector<int> mfrac;
void set_mfrac(int n)
{
    if (mfrac.size() == 0)
    {
        mfrac.push_back(1);
    }
    for (int i = mfrac.size(); i <= n; i++)
    {
        mfrac.push_back((i * mfrac[i - 1]) % INF);
    }
}

//get nCm mod INF
int mcomb(int n, int m)
{
    if (mfrac.size() <= n)
    {
        set_mfrac(n);
    }
    int res = mfrac[n];
    res = res * mpow(mfrac[m], INF - 2) % INF;
    res = res * mpow(mfrac[n - m], INF - 2) % INF;
    return res;
}

vector<int> get_gcd(int n){
    vector<int> res;
    for(int i=1;i*i<=n;i++){
        if(n%i==0){
            if(i*i==n)
            {res.push_back(i);}
            else
            {res.push_back(i);
            res.push_back(n/i);}
        }
    }
    return res;
}

signed main()
{
    int N;
    string S;
    cin >> N >> S;
    int ans = 1;
    char p = S[0];
    for(int i=0;i<N;i++){
        if(p!=S[i]){
            p = S[i];
            ans++;
        }
    }
    cout << ans <<endl;
}

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

int acc(int a, int b) {
	if(a < b) throw "Error";
	
	return a * (a + 1)  / 2 - b * (b + 1) / 2;
}

int main() {
	for(int n; cin >> n && n; ) {
		int answer = 0;
		
		for(int top = 1, tail = 0; top <= 1000; top++) {
			while(true) {
				if(top - tail > 1 && acc(top, tail) == n) {
					answer++;
				}
				
				if(acc(top, tail) > n) {
					tail++;
				} else {
					break;
				}
			}
		}
		
		cout << answer << endl;
	}
}

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

int main ()
{
  int H,N;
  cin >> H >> N;
  vector<int> A(N);
  for (int i = 0; i < N; i++) cin >> A.at(i);
  int sum = 0;
  for (int i = 0; i < N; i++) sum += A.at(i);
  if (sum >= H) cout << "Yes" << endl;
  else cout << "No" << endl;
  
  return 0;
}

Measured memory_bytes: 640
#include<iostream>
#include<vector>
#include<utility>
#include<algorithm>
#include<map>
typedef long long ll;
#define PB	push_back
#define FOR(n)			for(int i = 0; i < n; ++i)
#define RFOR(n)			for(int i = n; i >= 0; --i)
#define FORR(start,end) for(int i = start; i < end; ++i)
#define COUT(n)			cout << n << " " << flush
#define vi(v)			vector<int> v
#define vii(v)			vector<pair<int,int>> v
#define mii(m)			map<int, int> m
#define msi(m)			map<string, int, less<>> m
#define mmsi(m)			multimap<string, int, less<>> m
#define mkp(a,b)		make_pair(a,b)
#define ALL(obj)		obj.begin(), obj.end()
#define PI 3.141592
using namespace std;

int main() {
	int w, h, x, y;
	cin >> w >> h >> x >> y;

	cout << (double)w * (double)h / 2 << " " << flush;

	if (x + x == w && y + y == h)
		cout << 1 << endl;
	else
		cout << 0 << endl;

	return 0;
}

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

int main(void)
{
    int N;
    std::cin >> N;

    std::vector<int> L(N);
    for(int i = 0; i < N; i++)
    {
        std::cin >> L[i];
    }

    int L_max = *std::max_element(L.begin(), L.end());
    int L_max_index = std::distance(L.begin(), std::max_element(L.begin(), L.end()));

    int sum = 0;
    for(int i = 0; i < N; i++)
    {
        if(i == L_max_index)
        {
            continue;
        }

        sum += L[i];
    }

    if(L_max >= sum)
    {
        std::cout << "No" << std::endl;
    }

    else
    {
        std::cout << "Yes" << std::endl;
    }
    
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <numeric>
#include <cmath>
#include <unordered_map>
#include <iomanip>
#define REP(i, n) for(int i = 0; (i) < (n); (i)++)
#define MOD 1000000007
using namespace std;
 
int main(){
  int N;
  long long sum = 0;
  cin >> N;
  int B[N-1], A[N];
  REP(i,N-1){
    cin >> B[i];
  }
  A[0] = B[0];
  sum += A[0];
  for (int i = 1; i < N-1; i++){
    A[i] = min(B[i-1],B[i]);
    sum += A[i];
  }
  A[N-1] = B[N-2];
  sum += A[N-1];
  cout << sum << endl;
}


Measured memory_bytes: 256
#include <iostream>
using namespace std;
typedef long long ll;
ll n,a,b,ans,rans;
int main(void){
    cin>>n;
    for(int i=0;i<n;i++){
        cin>>a>>b;
        ans+=a*b;
        rans+=b;
    }
    rans+=(ans-1)/9-1;
    cout<<rans<<endl;
}


Measured memory_bytes: 256
S = input()

x = len(S)-1

s = 0
for i in range(1 << x):
    t = 0
    for j in range(x):
        if i & (1 << j):
            s += int(''.join(S[t:j+1]))
            t = j+1
    s += int(''.join(S[t:]))
print(s)

Measured memory_bytes: 2940
// include
// ------------------------------------------------
#include <bits/stdc++.h>
#include <vector>
#include <algorithm>
#include <math.h>

using namespace std;

// func
// ------------------------------------------------
int CalcSumOfDigit(int n);      // 各桁の和を計算する。
int getDigit(int n);            // 数字の桁数を取得する。
string upper(string str);       // 英字を大文字に変換する。
string lower(string str);       // 英字を小文字に変換する。

// define
// ------------------------------------------------
#define all(a)        (a).begin(),(a).end()
#define rall(a)       (a).rbegin(),(a).rend()
#define sz(a)         int((a).size())
#define rep(i,n)      for(int(i)=0;(i)<(n);(i)++)
#define repe(i,n)     for(int(i)=0;(i)<=(n);(i)++)
#define vsort(v)      sort((v).begin(),(v).end())
#define rvsort(v)     sort(rall((v)))
#define vi            vector<int>
#define GCD(a,b)      __gcd((a),(b))
#define LCM(a,b)      (a)/GCD((a),(b))*(b)
#define kiriage(a,b)  ((a)+(b)-1)/(b)

const int INF = 1e9;

typedef long long ll;
typedef unsigned long long ull;

// code
// ------------------------------------------------
int main() {

  string s;
  cin >> s;

  vector<ll> a(4);
  rep(i,4) a[i] = s[i] - 48;

  ll ans = 0;
  for(int bit = 0; bit < (1<<3) ; ++bit)
  {
    ll buf = a[0];

    for(int i = 1;i<4;i++)
    {
      if(bit & (1<<i-1))
        buf += a[i];
      else
        buf -= a[i];
    }
    if(buf == 7)
    {
      ans = bit;
      break;
    }
  }

  cout << a[0];
  for(int i = 1;i<4;i++)
  {
    if(ans & (1<<i-1))
      cout << "+";
    else
      cout << "-";
    cout << a[i];
  }
  
  cout << "=7" << endl;

  return 0;
}
// funcの実体
// ------------------------------------------------
int getDigit(int n)
{
  int i = 1;
  while(1)
  {
    n = n / 10;
    if(n == 1)
      break;
    i++;
  }
  return i;
}
int CalcSumOfDigit(int n)
{
  int s = 0;
  while(n)
  {
    s += n % 10;
    n = n / 10;
  }
  return s;
}

string upper(string str)
{
  for(auto itr = str.begin();itr != str.end() ; itr++)
  {
    if(97 <= *itr && *itr <= 122)
    {
      *itr = *itr - 32;
    }
  }
  return str;
}

string lower(string str)
{
  for(auto itr = str.begin();itr != str.end() ; itr++)
  {
    if(65 <= *itr && *itr <= 90)
    {
      *itr = *itr + 32;
    }
  }
  return str;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define maxn 55
#define mod 1000000007
typedef long long LL;
struct matrix {
    int sz;
    int m[maxn][maxn];
    matrix(){}
    matrix(int n) : sz(n) { memset(m,0,sizeof(m)); }
    void operator = (const matrix &A) {
        for(int i=0; i<sz; i++)
            for(int j=0; j<sz; j++)
                m[i][j] = A.m[i][j];
    }
    matrix operator*(const matrix& A) {
        matrix B(sz);
        for(int i=0; i<sz; i++)
            for(int j=0; j<sz; j++) {
                B.m[i][j] = 0;
                for(int k=0; k<sz; k++)
                    B.m[i][j] = ((LL)m[i][k] * A.m[k][j] % mod
                                 + B.m[i][j]) % mod;
            }
        return B;
    }
};
matrix pow(matrix A, LL k) {
    matrix ans(A.sz);
    for(int i=0; i<A.sz; i++)
        ans.m[i][i] = 1;
    while(k) {
        if(k&1) ans = ans * A;
        k >>= 1;
        A = A * A;
    }
    return ans;
}
int main() {
    int n;
    LL k;
    scanf("%d%lld", &n, &k);
    matrix A(n);
    for(int i=0; i<n; i++)
        for(int j=0; j<n; j++)
            scanf("%d", &A.m[i][j]);
    matrix ans = pow(A, k);
    int cnt = 0;
    for(int i=0; i<n; i++)
        for(int j=0; j<n; j++)
            cnt = (cnt + ans.m[i][j]) % mod;
    printf("%d\n", cnt);
    return 0;
}

Measured memory_bytes: 3868
#include<bits/stdc++.h>
using namespace std;
#define lli long long int
#define pb push_back
#define pob pop_back
#define rep(a,b) for(int i=a;i<b;i++)
#define repv(a,b) for(int i=a;i>=b;i--)
#define itr vector<lli> :: iterator
#define maximum(a,b,c)  max(a,max(b,c))
#define minimum(a,b,c) min(a,min(b,c))
#define tim clock_t
#define s string
//ANAGRAM SSOLUTION 	AUTHOR KUMAR MAPANIP//


inline void fast()
{
	std::ios_base::sync_with_stdio(false);
	cin.tie(NULL);
}

int main()
{
 fast();
  int a[]={111,222,333,444,555,666,777,888,999};
  vector<int> v(a,a+9);
  int n;
  cin>>n;
  vector<int> :: iterator it=lower_bound(v.begin(),v.end(),n);
  cout<<*it;
  return 0;
}


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

int A[100005];

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

    int N, x;
    cin >> N >> x;

    long long ans = 0;

    for(int i=1; i<=N; i++)
        cin >> A[i];

    for(int i=1; i<=N; i++)
    {
        int k = max(0, A[i] + A[i-1] - x);
        ans += k;
        A[i] -= k;
    }

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


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

using namespace std;

#define llong long long int
#define ldouble long double
#define rep(i, n) for (int i = 0; i < n; ++i)
#define all(x) x.begin(), x.end()
#define stl_rep(itr, x) for (auto itr = x.begin(); itr != x.end(); ++itr)

const static int MOD = 1000000000 + 7;
const static llong INF = 1LL << 60;
const static int dy[] = {0, 1, 0, -1};
const static int dx[] = {1, 0, -1, 0};

template<typename T> T my_gcd(T a, T b) {
    return (a ? my_gcd(b % a, a) : b);
}

template<typename T> T my_lcm(T a, T b){
	return a * b / my_gcd(a, b);	
}

struct UF {
    vector<int> par, sz;

    UF(int n) {
        par.resize(n);
        sz.resize(n);
        for (int i = 0; i < n; ++i) {
            par[i] = i;
            sz[i] = 1;
        }
    }

    int find_root(int x) {
        return par[x] == x ? x : par[x] = find_root(par[x]);
    }

    bool same(int x, int y) {
        return find_root(x) == find_root(y);
    }

    void unite(int x, int y) {
        x = find_root(x);
        y = find_root(y);
        if (x == y) return;
        
        if (sz[x] < sz[y]) swap(x, y);
        sz[x] += sz[y];
        par[y] = x;
    }
};

signed main (int argc, char *argv[]) {
    cin.tie(0);
    ios::sync_with_stdio(false);

    llong n, m;
    cin >> n >> m;
    vector<pair<int, int> > removed_edge(m);
    rep(i, m) {
        int a, b;
        cin >> a >> b;
        removed_edge[i] = make_pair(a - 1, b - 1);
    }
    reverse(removed_edge.begin(), removed_edge.end());

    UF uf(n);
    vector<llong> ans;
    llong inconvenience = n * (n - 1) / 2;
    ans.push_back(inconvenience);
    rep(i, m) {
        int e1 = removed_edge[i].first, e2 = removed_edge[i].second;
        if (uf.same(e1, e2)) {
            ans.push_back(inconvenience);
        } else {
            inconvenience = inconvenience - (llong)uf.sz[uf.find_root(e1)] * uf.sz[uf.find_root(e2)];
            ans.push_back(inconvenience);
        }

        uf.unite(e1, e2);
    }

    rep(i, m) {
        cout << ans[m - i - 1] << endl;
    }

    return 0;
}

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

#define _overload(_1,_2,_3,name,...) name
#define _rep(i,n) _range(i,0,n)
#define _range(i,a,b) for(int i=int(a);i<int(b);++i)
#define rep(...) _overload(__VA_ARGS__,_range,_rep,)(__VA_ARGS__)

#define _rrep(i,n) _rrange(i,n,0)
#define _rrange(i,a,b) for(int i=int(a)-1;i>=int(b);--i)
#define rrep(...) _overload(__VA_ARGS__,_rrange,_rrep,)(__VA_ARGS__)

#define _all(arg) begin(arg),end(arg)
#define uniq(arg) sort(_all(arg)),(arg).erase(unique(_all(arg)),end(arg))
#define getidx(ary,key) lower_bound(_all(ary),key)-begin(ary)
#define clr(a,b) memset((a),(b),sizeof(a))
#define bit(n) (1LL<<(n))
#define popcount(n) (__builtin_popcountll(n))

using namespace std;

template<class T>bool chmax(T &a, const T &b) { return (a < b) ? (a = b, 1) : 0;}
template<class T>bool chmin(T &a, const T &b) { return (b < a) ? (a = b, 1) : 0;}

using ll = long long;
using R = long double;
const R EPS = 1e-9L; // [-1000,1000]->EPS=1e-8 [-10000,10000]->EPS=1e-7
inline int sgn(const R& r) {return (r > EPS) - (r < -EPS);}
inline R sq(R x) {return sqrt(max(x, 0.0L));}

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

// Problem Specific Parameter:

int main(void) {
	ll n, m;
	cin >> n >> m;

	ll ans = 0LL;
	
	if (n >= 2 and m >= 2) {
		ans = 1LL * (n - 2) * (m - 2);
	} else if (n >= 2) {
		ans = n - 2;
	} else if (m >= 2) {
		ans = m - 2;
	} else {
		ans = 1LL;
	}

	cout << ans << endl;


	return 0;
}

Measured memory_bytes: 256
/**
 *  Square Route (Problem D, Practice Contest for Japan Domestic, 2007-06-24)
 *  by Kenji Inoue, 2007-06-28
 **/

#include <iostream>
#include <vector>

using namespace std;

int main() {
  int y[1501], x[1501];

  int N, M;
  while (cin >> N >> M, (N || M)) {
    y[0] = 0;
    for (int i=0; i<N; i++) {
      int t; cin >> t; y[i+1] = y[i] + t;
    }
    x[0] = 0;
    for (int i=0; i<M; i++) {
      int t; cin >> t; x[i+1] = x[i] + t;
    }

    vector<int> diag(3000000);
    for (int i=0; i<N+1; i++) {
      for (int j=0; j<M+1; j++) {
        diag[ 1500000 + y[i] - x[j] ]++;
      }
    }

    int count = 0;
    for (int i=0; i<=3000000; i++) {
      int v = diag[i];
      if (v == 0 || v == 1) { continue; }
      count += v * (v-1) / 2;
    }
    cout << count << endl;
  }

  return 0;
}

Measured memory_bytes: 12000
'''A - Pair
https://atcoder.jp/contests/abc108/tasks/abc108_a

>>> main(3)
2
>>> main(6)
9
>>> main(11)
30
>>> main(50)
625'''

from itertools import permutations


def main(k):
    count = 0

    for p in permutations(range(1, k + 1), 2):
        if p[0] % 2 == 0 and p[1] % 2 != 0:
            count += 1

    print(count)


if __name__ == "__main__":
    k = int(input())
    main(k)


Measured memory_bytes: 3188
import java.util.*;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int k = sc.nextInt();
        int[] h = new int[n];
        for(int i=0; i<n; i++) h[i] = sc.nextInt();
        sc.close();

        long[] dp = new long[n];
        Arrays.fill(dp, Long.MAX_VALUE);
        dp[0] = 0;
        dp[1] = Math.abs(h[1] - h[0]);
        for(int i=2; i<n; i++){
            for(int j=1; j<=Math.min(k, i); j++){
                long cdp = dp[i-j] + Math.abs(h[i-j] - h[i]);
                dp[i] = Math.min(cdp, dp[i]);
            }
        }

        System.out.println(dp[n-1]);
    }
}

Measured memory_bytes: 51136
from collections import defaultdict as dd
from functools import reduce
d=[2,3,5,7,11,13,17,19,23,29,31]
cd=len(d)

def f(n):
  i=0
  pr=dd(int)
  while i<cd and n//d[i]!=0:
    while i<cd and n%d[i]==0:
      pr[d[i]]+=1
      n=n//d[i]
    i+=1
  
  if pr.values():
    return reduce(lambda x,y:x*y,map(lambda x:x+1,pr.values()))
  else:
    return 0

n=int(input())
print(sum([1 for i in range(1,n+1,2) if f(i)==8]))

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

using ll = long long;
using Vi = vector<int>;
using Vl = vector<ll>;
using Pii = pair<int, int>;
using Pll = pair<ll, ll>;

constexpr int I_INF = numeric_limits<int>::max();
constexpr ll L_INF = numeric_limits<ll>::max();

//==================================

int main() {
#ifdef FASTIO
    cin.tie(0), cout.tie(0);
    ios::sync_with_stdio(false);
#endif
#ifdef FILEINPUT
    ifstream ifs("./in_out/input.txt");
    cin.rdbuf(ifs.rdbuf());
#endif

    ll N, M;
    cin >> N >> M;
    Vl A(N);
    for (int i = 0; i < N; i++) {
        cin >> A[i];
    }

    sort(A.begin(), A.end(), greater<ll>());

    ll left = 0, right = 2000000000000;
    while (right - left > 1) {
        ll mid = (left + right) >> 1;
        ll cnt = 0;
        for (int i = 0; i < N; i++) {
            ll left2 = -1, right2 = N;
            while (right2 - left2 > 1) {
                ll mid2 = (left2 + right2) >> 1;
                ll t = A[i] + A[mid2];
                if (t >= mid) {
                    left2 = mid2;
                }
                else {
                    right2 = mid2;
                }
            }
            cnt += left2 + 1;
        }

        if (cnt < M) {
            right = mid;
        }
        else {
            left = mid;
        }
    }


    Vl csum(N + 1);
    for (int i = 0; i < N; i++) {
        csum[i + 1] = csum[i] + A[i];
    }

    ll cnt = 0;
    ll ans = 0;
    for (int i = 0; i < N; i++) {
        ll left2 = -1, right2 = N;
        while (right2 - left2 > 1) {
            ll mid2 = (left2 + right2) >> 1;
            ll t = A[i] + A[mid2];
            if (t >= left) {
                left2 = mid2;
            }
            else {
                right2 = mid2;
            }
        }
        cnt += left2 + 1;
        ans += csum[left2 + 1] + A[i] * (left2 + 1);
    }
    ans += left * (M - cnt);

    cout << ans << endl;

    return 0;
}


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

#define REP(i, n) for(int i = 0; i < n; i++)
#define RREP(i,n) for(int i = (n)-1; i >= 0; i--)
#define FOR(i, l, r) for(int i = l; i < r; i++)
#define RFOR(i, l,r) for(int i= (l)-1; i>= (r) ; i--)

#define int64 int64_t
#define uint64 uint64_t
#define uint unsigned

vector<uint64> mul(const vector<vector<int> >& a,const vector<int>& b)
{
    vector<uint64> ret;
    REP(i, a.size())
        ret.push_back(inner_product(a[i].begin(), a[i].end(), b.begin(), 0));
    return ret;
}
int main()
{
    int n, m;
    cin >> n >> m;
    vector<int> b(m);
    vector< vector<int> > a(n, vector<int>(m));
    REP(i, n)
        REP(j, m)
            cin >> a[i][j];
    REP(i, m)
        cin >> b[i];

    auto ans = mul(a, b);
    REP(i, ans.size())
        cout << ans[i] << '\n';
}

Measured memory_bytes: 3160
#define _CRT_SECURE_NO_WARNINGS
#define _USE_MATH_DEFINES
#include "bits/stdc++.h"

#define fore(i,a,b) for(int i = a; i < (b); i++)
#define fr(i,a,b) for(int i = a - 1; i >= b; i--)
#define fast ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0)
#define N 200005
#define inf INT32_MAX
#define MOD 1000000007

using namespace std;

typedef long long ll;
typedef pair<int,int> pr;
typedef pair<pair<int,int>, int> tup;

inline void solve()
{
	int n;
	cin >> n;
	vector<vector<pr>> v(n);
	fore(i, 0, n)
	{
		int t;
		cin >> t;
		fore(j, 0, t)
		{
			int t1, t2;
			cin >> t1 >> t2;
			t1--;
			v[i].push_back({ t1,t2 });
		}
	}
	int otv = 0;

	fore(i, 0, (1 << n))
	{
		bool is = 1;
		fore(j, 0, n)
		{
			fore(k, 0, v[j].size())
			{
				if (((i >> j) & 1) && ((i >> v[j][k].first) & 1) != v[j][k].second)
				{
					is = 0;
				}
			}
		}
		if (is)
		{
			int o = 0;
			fore(j, 0, 30)
			{
				if ((i >> j) & 1)
					o++;
			}
			otv = max(o, otv);
		}
	}

	cout << otv;
}

int main()
{
	fast;
#if defined(_DEBUG)
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#endif
	solve();
}




Measured memory_bytes: 256
#include <bits/stdc++.h>
 
using namespace std;
 
#define rep(i, a, b) for (int i = (a), i##_end_ = (b); i < i##_end_; ++i)
#define debug(...) fprintf(stderr, __VA_ARGS__)
#define mp make_pair
#define x first
#define y second
#define pb push_back
typedef long long LL;
 
const int N = (int) 0, mod = (int) 0;
int findmx(int a, int b) {
	if (a + b == 0) return 0;
	int mx = 1;
	mx = max(mx, (a - 1) / (b + 1) + 1);
	mx = max(mx, (b - 1) / (a + 1) + 1);
	return mx;
}
int check(int a, int b, int lim) {
	int bm = lim;
	int mx = findmx(a, b);
	int needb = (bm - 1) / mx;
	int rema = a - bm, remb = b - needb;
	if (rema < 0 || remb < 0) return 0;
	int nxtmx = findmx(rema, remb);
	if (nxtmx <= mx) {
		return 1;	
	}
	return 0;
}
int main() {
	int q;
	cin >> q;
	while (q--) {
		int a, b, ql, qr;
		cin >> a >> b >> ql >> qr;
		--ql;
		int mx = findmx(a, b);
		int bl = 0, br = a + 1;
		while (bl < br - 1) {
			int bm = bl + br >> 1;
			if (check(a, b, bm)) {
				bl = bm;	
			} else {
				br = bm;
			}
		}
		int needb = (bl - 1) / mx;
		int use = bl + needb;
		for (int j = ql; j < min(qr, use); ++j) {
			if (j % (mx + 1) == mx) {
				cout << 'B';	
			} else {
				cout << 'A';
			}
		}
		vector<char> s;
		for (int j = qr - 1; j >= max(ql, use); --j) {
			if (((a + b) - j - 1) % (mx + 1) == mx) {
				s.pb('A');
			} else {
				s.pb('B');
			}
		}
		reverse(s.begin(), s.end());
		for (char c : s) cout << c;
		cout << '\n';
	}
}

Measured memory_bytes: 384
#include <bits/stdc++.h>
using namespace std;
struct node
{
    int k;
    int a[15];
    int p;
}s[15];
int main()
{
    int n,m;
    int i,j,k;
    int b[15],num,flag,ans,sum;
    while(scanf("%d%d",&n,&m)!=EOF)
    {
        ans=0;
        for(i=0;i<m;i++)
        {
            scanf("%d",&s[i].k);
            for(j=0;j<s[i].k;j++)
            {
                scanf("%d",&s[i].a[j]);
            }
        }
        for(i=0;i<m;i++)
            scanf("%d",&s[i].p);
        for(i=0;i<(1<<n);i++)
        {
            flag=0;
            for(j=0;j<m;j++)
			{
            	sum=0;
            	for(int r=0;r<s[j].k;r++)
				{
            		if((1<<(s[j].a[r]-1))&i)
            		sum++;
				}
				if(sum%2!=s[j].p)
				{
					flag=1;
					break;
				}
			}
            if(flag==0)
                ans++;
        }
        printf("%d\n",ans);
    }
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <algorithm>
#include <utility>
#include <iomanip>
#include <tuple>
#include <numeric>
#include <cstdio>
#include <cmath>
#include <cstdlib>
using namespace std;
using ll = long long;
const int INF = 1e9;

int main() {
    int n; cin >> n;
    n = n % 10;
    if (n == 2 || n == 4 || n == 5 || n == 7 || n == 9) {
        cout << "hon\n";
    } else if (n == 0 || n == 1 || n == 6 || n == 8) {
        cout << "pon\n";
    } else {
        cout << "bon\n";
    }
}

Measured memory_bytes: 3132
#include <bits/stdc++.h>
#define inf 1000000000000000
using namespace std;

long long n, sumn, ans = inf;
vector<long long> a, sum;

void solve(long long now);

int main() {
  long long i, x;
  cin >> n;
  sum.push_back(0);
  for(i = 0; i < n; ++i) {
    cin >> x;
    a.push_back(x);
    sum.push_back(sum[i] + a[i]);
  }
  for(i = 2; i < n; ++i) solve(i);
  cout << ans << endl;
  return 0;
}

void solve(long long now) {
  long long maxn = 0, minn = inf;
  auto lit = upper_bound(sum.begin() + 1, sum.begin() + now,
                         sum[now] / 2) -
             1;
  auto rit =
      upper_bound(sum.begin() + 1 + now, sum.end(),
                  sum[now] + (sum[n] - sum[now]) / 2) -
      1;
  auto lit2 = lit;
  ++lit2;
  auto rit2 = rit;
  ++rit2;
  if(lit != sum.begin() && rit != (sum.begin() + now - 1)) {
    maxn = 0;
    minn = inf;
    if(maxn < *lit) maxn = *lit;
    if(maxn < sum[now] - *lit) maxn = sum[now] - *lit;
    if(maxn < *rit - sum[now]) maxn = *rit - sum[now];
    if(maxn < sum[n] - *rit) maxn = sum[n] - *rit;
    if(minn > *lit) minn = *lit;
    if(minn > sum[now] - *lit) minn = sum[now] - *lit;
    if(minn > *rit - sum[now]) minn = *rit - sum[now];
    if(minn > sum[n] - *rit) minn = sum[n] - *rit;
    if(ans > maxn - minn) ans = maxn - minn;
  }
  if(lit2 != (sum.begin() + now) &&
     rit != (sum.begin() + now - 1)) {
    maxn = 0;
    minn = inf;
    if(maxn < *lit2) maxn = *lit2;
    if(maxn < sum[now] - *lit2) maxn = sum[now] - *lit2;
    if(maxn < *rit - sum[now]) maxn = *rit - sum[now];
    if(maxn < sum[n] - *rit) maxn = sum[n] - *rit;
    if(minn > *lit2) minn = *lit2;
    if(minn > sum[now] - *lit2) minn = sum[now] - *lit2;
    if(minn > *rit - sum[now]) minn = *rit - sum[now];
    if(minn > sum[n] - *rit) minn = sum[n] - *rit;
    if(ans > maxn - minn) ans = maxn - minn;
  }
  if(lit != sum.begin() && rit2 != (sum.end() + 1)) {
    maxn = 0;
    minn = inf;
    if(maxn < *lit) maxn = *lit;
    if(maxn < sum[now] - *lit) maxn = sum[now] - *lit;
    if(maxn < *rit2 - sum[now]) maxn = *rit2 - sum[now];
    if(maxn < sum[n] - *rit2) maxn = sum[n] - *rit2;
    if(minn > *lit) minn = *lit;
    if(minn > sum[now] - *lit) minn = sum[now] - *lit;
    if(minn > *rit2 - sum[now]) minn = *rit2 - sum[now];
    if(minn > sum[n] - *rit2) minn = sum[n] - *rit2;
    if(ans > maxn - minn) ans = maxn - minn;
  }
  if(lit2 != (sum.begin() + now) &&
     rit2 != (sum.end() + 1)) {
    maxn = 0;
    minn = inf;
    if(maxn < *lit2) maxn = *lit2;
    if(maxn < sum[now] - *lit2) maxn = sum[now] - *lit2;
    if(maxn < *rit2 - sum[now]) maxn = *rit2 - sum[now];
    if(maxn < sum[n] - *rit2) maxn = sum[n] - *rit2;
    if(minn > *lit2) minn = *lit2;
    if(minn > sum[now] - *lit2) minn = sum[now] - *lit2;
    if(minn > *rit2 - sum[now]) minn = *rit2 - sum[now];
    if(minn > sum[n] - *rit2) minn = sum[n] - *rit2;
    if(ans > maxn - minn) ans = maxn - minn;
  }
}

Measured memory_bytes: 3564
package main

import (
	"fmt"
)

func main() {
	var n int
	fmt.Scan(&n)
	
	first := n % 10
	
	ans := ""
	switch first {
		case 2,4,5,7,9:
			ans = "hon"
		case 0,1,6,8:
			ans = "pon"
		case 3:
			ans = "bon"
	}
	fmt.Println(ans)
}

Measured memory_bytes: 1748
K,X =map(int,input().split()) #k ko #X is black

#−1000000~1000000

i=max([-1000000,X-K+1])
j=min([1000000,X+K])

result=""

while i<j:
  result =result+" "+str(i)
  
  i=i+1

#print(result)
print(result[1:])

Measured memory_bytes: 3060
#include <stdio.h>
#include <stdlib.h>
#include <algorithm>
#include <bitset>
#include <cmath>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <string>
#include <vector>

using namespace std;

template <typename T>
static inline void ArrayInput(vector<T>& A) {
  for (auto itr = A.begin(); itr < A.end(); ++itr) cin >> *itr;
}

template <typename T>
static inline void ArrayPut(const vector<T>& A) {
  for (auto itr = A.begin(); itr < A.end(); ++itr) cout << *itr << " ";
  cout << endl;
}

bool Sec_compare(pair<uint64_t, uint64_t> a, pair<uint64_t, uint64_t> b) {
  if (a.second != b.second) {
    return a.second < b.second;
  } else {
    return a.first < b.first;
  }
}

int main() {
  uint64_t A1, A2, A3;
  cin >> A1 >> A2 >> A3;

  if ((A1 + A2 + A3) < 22) {
    cout << "win" << endl;
  } else {
    cout << "bust" << endl;
  }

  return 0;
}


Measured memory_bytes: 256
A,B,C = map(int, input().split())

ans = 0

while A%2 == B%2 == C%2 == 0:
  ans += 1
  A = A // 2
  B = B // 2
  C = C // 2
  #print(A,B,C)
  if A == B == C:
    ans = -1
    break
  elif A%2 == 1 or B%2 == 1 or C%2 == 1:
    a = A
    b = B
    A = B + C
    B = C + a
    C = a + b

print(ans)

Measured memory_bytes: 3064
from collections import defaultdict, deque
import sys, heapq, bisect, math, itertools, string, queue, copy, time
from fractions import gcd
import numpy as np
sys.setrecursionlimit(10**8)
INF = float('inf')
MOD = 10**9+7
EPS = 10**-7

s = input()
if s == 'AAA' or s == 'BBB':
    ans = 'No'
else:
    ans = 'Yes'

print(ans)

Measured memory_bytes: 27056
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, j, n) for (ll i = j; i < n; i++)
#define all(x) (x).begin(),(x).end()
#define INF (1000000000)
#define MOD (1000000007)
#define MAX (500000)
#define pii pair<int, int>

/////////////////////////////////////////////////////////

class XY{
public:
  ll x, y;
  XY() {x = y = 0;}
  XY(ll u, ll v) {x = u; y = v;}
};

class e{
public:
  ll a, b;
  e() {a = b = -1;}
  e(ll u, ll v) {a = u; b = v;}
};

template<typename T1, typename T2>
void chmin(T1 &a, T2 b) {if(a > b) a = b;}
template<typename T1, typename T2>
void chmax(T1 &a, T2 b) {if(a < b) a = b;}

template<typename T1, typename T2>
ll mypow(T1 a, T2 n){
  if(n == 0) return 1;
  if(n == 1) return a;
  if(n % 2) return a * mypow(a, n - 1);
  ll tmp = mypow(a, n / 2);
  return tmp * tmp;
}

template<typename T>
int BS(vector<T> &V, int left, int right, T key){
  int mid = (left + right) / 2;
  if(V[mid] <= key) left = mid;
  else right = mid;
  if(right - mid == 1) return left;
  else return BS(V, left, right, key);
}

ll comb(ll n, ll r){
	ll res = 1;
  rep(i, 0, r){
    res *= n - i;
    res /= i + 1;
  }
  return res;
}

template<typename T>
T euclid(T a, T b){
  if(b == 0) return a;
  else return euclid(b, a % b);
}

vector<ll> fact(MAX, 0), fact_inv(MAX, 0);

ll pow_mod(ll a, ll b){
	ll res = 1;
	while(b > 0){
		if(b & 1) res = res * a % MOD;
		a = a * a % MOD;
		b >>= 1;
	}
	return res;
}

void prepare_comb_mod(ll n){
	fact[0] = 1LL;
	for(ll i = 0; i < n; i++) fact[i+1] = fact[i] * (i + 1) % MOD;
	fact_inv[n] = pow_mod(fact[n], MOD - 2);
	for(ll i = n - 1; i >= 0; i--) fact_inv[i] = fact_inv[i + 1] * (i + 1) % MOD;
}

ll comb_mod(ll n, ll r){
	return (fact[n] * fact_inv[r]) % MOD * fact_inv[n - r] % MOD;
}

/////////////////////////////////////////////////////////

void Main() {
  int N, K; cin >> N >> K;
  vector<int> h(N);
  int res = 0;
  rep(i, 0, N) cin >> h[i];
  rep(i, 0, N){
    if(h[i] >= K) res++;
  }
  cout << res << endl;
}

/////////////////////////////////////////////////////////

int main(){
  cin.tie(nullptr);
  ios_base::sync_with_stdio(false);
  cout << std::fixed << std::setprecision(15);

  Main();
}


Measured memory_bytes: 8576
#include<bits/stdc++.h>
#define ALL(c) begin(c), end(c)
using namespace std;
using ll = long long;
using ld = long double;

const int N = 1e6+6;


int main(){
	//freopen("input.txt","r",stdin); //freopen("output.txt","w",stdout);
	ios::sync_with_stdio(0);cin.tie(0);//cout.precision(12);cout<<fixed;
	
	int n;
	
	cin>>n;
	
	int m = 0;
	
	vector<string> s(n);
	vector<int> c(n);
	vector<vector<int>> id(n);
	vector<pair<int,int>> gg;
	vector<int> begins, ends;
	for(int i=0;i<n;++i){
		cin>>s[i];
		cin>>c[i];
		
		for(int j=0;j<size(s[i]);++j){
			id[i].push_back(m++);
			gg.push_back({i,j});
		}
		
		ends.push_back(id[i].back());
		begins.push_back(id[i][0]);
	}
	
	ll inf = 1e18;
	vector<vector<ll>> dp(m, vector<ll>(m,-inf));
	
	map<pair<int,int>,ll> dist;
	set<pair<ll,pair<int,int>>> q;
	
	auto init = [&](int l, int r, int cost){
		pair p = {l,r};
		dist[p] = cost;
		q.insert({cost,p});
	};
	
	for(int i=0;i<n;++i){
		for(int k : id[i]) init(k,k,c[i]);
		
		for(int j=0;j+1<size(s[i]);++j) if(s[i][j] == s[i][j+1]){
			init(id[i][j],id[i][j+1],c[i]);
		}
		
		for(int j=0;j<n;++j) if(s[i].back()==s[j][0]){
			init(id[i].back(),id[j][0],c[i]+c[j]);
		}
	}
	
	ll ans = 1e18;
	while(!empty(q)){
		auto pp = *begin(q);
		q.erase(pp);
		ll dv = pp.first;
		
		auto [l,r] = pp.second;
		auto [li,lj] = gg[l];
		auto [ri,rj] = gg[r];
		
		//cout<<li<<' '<<lj<<' '<<ri<<' '<<rj<<endl;
		
		if(lj == 0 && rj+1 == size(s[ri])){
			ans = min(ans, dv);
			continue ;
		}
		
		vector<vector<pair<int,int>>> tl(26), tr(26);
		
		if(lj==0){
			for(int v : ends){
				auto [vi,vj] = gg[v];
				int x = s[vi][vj] - 'a';
				tl[x].push_back({v,c[vi]});
			}
		}else{
			int x = s[li][lj-1] - 'a';
			tl[x].push_back({id[li][lj-1],0});
		}
		
		if(rj+1==size(s[ri])){
			for(int v : begins){
				auto [vi,vj] = gg[v];
				int x = s[vi][vj] - 'a';
				tr[x].push_back({v,c[vi]});
			}
		}else{
			int x = s[ri][rj+1] - 'a';
			tr[x].push_back({id[ri][rj+1],0});
		}
		
		for(int x=0;x<26;++x){
			for(auto [vl,al] : tl[x])
			for(auto [vr,ar] : tr[x]){
				ll cur = dv + al + ar;
				//cerr<<"?"<<cur<<' '<<gg[vl].first<<' '<<gg[vl].second<<' '<<gg[vr].first<<' '<<gg[vr].second<<endl;
				pair to = {vl,vr};
				if(dist.count(to) == 0) dist[to] = inf;
				if(dist[to] > cur){
					q.erase({dist[to],to});
					dist[to] = cur;
					q.insert({dist[to],to});
				}
			}
		}
	}
	
	if(ans>=inf) ans = -1;
	cout<<ans<<endl;
	
	return 0;
}


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

#define pii pair<int,int>
#define int long long
#define endl '\n'
#define all(a) a.begin(), a.end()
#define keepU(a) sort(all(a));a.erase(unique(all(a)), a.end())
#define fast ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)

using namespace std;

// char mat[200][200];
string mat[200];
int cost[200][200], ans[200][200];
int n,m;

int oo = 1e15;


bool valid(int a, int b){
    if(a >= 1 and a <= n and b >= 1 and b <= m)return true;
    return false;
}

int32_t main()
{
    memset(ans, 0, sizeof ans);
    cin >> n >> m;
    for(int i = 1; i <= n;i++){
        for(int j = 1;j <= m;j++){
            char ch;
            cin >> ch;
            cost[i][j] = (ch=='#');
        }getchar();  
    }
    for(int i = 1; i <= n;i++){
        for(int j = 1; j <= m;j++){
            ans[i][j] = cost[i][j];
            if(i==1 and j==1)continue;
            if(i-1 < 1){
                if(cost[i][j-1] == 1 and cost[i][j] == cost[i][j-1])ans[i][j] = ans[i][j-1];
                else ans[i][j] += ans[i][j-1];
            }
            else if(j-1 < 1){
                if(cost[i-1][j] == 1 and cost[i][j] == cost[i-1][j])ans[i][j] = ans[i-1][j];
                else ans[i][j] += ans[i-1][j];
            }
            else{   
                int ans1 = ans[i][j];
                if(cost[i][j-1] == 1 and cost[i][j] == cost[i][j-1])ans1 = ans[i][j-1];
                else ans1 += ans[i][j-1];

                int ans2 = ans[i][j];
                if(cost[i-1][j] == 1 and cost[i][j] == cost[i-1][j])ans2 = ans[i-1][j];
                else ans2 += ans[i-1][j];

                ans[i][j] = min(ans1, ans2);
            }
        }
    }
    // for(int i = 1; i <= n;i++){
    //     for(int j = 1; j <= m;j++){
    //         cout << ans[i][j] << " ";
    //     }cout << endl;
    // }
    cout << ans[n][m] << endl;

    return 0;
}

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

using namespace std;
#define lli long long int

int main(){
    lli n, k, sum = 0;
    cin >> n >> k;
    if(n <= k){
        cout << 0 << endl;
        return 0;
    }
    vector<lli> v(n, 0);
    for(int i = 0; i < n; i++){
        cin >> v[i];
    }
    sort(v.begin(), v.end());
    for(int i = 0; i < n-k; i++){
        sum += v[i];
    }
    cout << sum << endl;
    return 0;
}

Measured memory_bytes: 1792
#include <stdio.h>
#include <iostream>
#include <algorithm>

using namespace std;
#define BUF (1000)

int n;
char s[3];
void input(void){
	cin >> s;
}

int main(void){
	input();
	if(s[0]==s[2]) cout << "Yes" << endl;
	else cout << "No" <<endl;
	return 0;
}


Measured memory_bytes: 256
import java.math.BigInteger;
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        BigInteger[] a = new BigInteger[n];
        BigInteger aa = new BigInteger("1000000000000000000");
        BigInteger sum = new BigInteger("1");
        boolean flg = false;
        for (int i = 0; i < n; i++) {
            a[i] = sc.nextBigInteger();
            if(a[i].equals(BigInteger.ZERO)) {
                flg = true;
            }
        }
        if(flg) {
            System.out.println(0);
            return;
        }
        for (int i = 0; i < n; i++) {
            sum = sum.multiply(a[i]);
            if(sum.compareTo(aa) > 0) {
                System.out.println(-1);
                return;
            }
        }
        System.out.println(sum);
    }
}

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

int main() {
  int H, W;
  cin >> H >> W;
  string s[9];
  for (int i=0; i<H; i++) {
    cin >> s[i];
  }

  int cnt=0;
  for (int i=0; i<H; i++) {
    for (int j=0; j<W; j++) {
      if (s[i][j] == '#') cnt++;
    }
  }

  string ans = (cnt == H+W-1) ? "Possible" : "Impossible";
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<cstring>
#include <cstdlib>  
#include <math.h>
#include <cmath>
#include<cctype>
#include<string>
#include<set>
#include<iomanip>
#include <map>
#include<algorithm>
#include <functional>
#include<vector>
#include<climits>
#include<stack>
#include<queue>
#include<bitset>
#include <deque>
#include <climits>
#include <typeinfo>
#include <utility> 
using namespace std;
using ll = long long;
template<typename T>using min_priority_queue = priority_queue<T, vector<T>, greater<T>>;
const ll MOD = 1e9 + 7;
const ll inf = 1LL << 60;
#define all(x) (x).begin(),(x).end()
#define rep(i,m,n) for(ll i = m;i < n;++i)
#define pb push_back
#define fore(i,a) for(auto &i:a)
#define rrep(i,m,n) for(ll i = m;i >= n;--i)
#define INF INT_MAX/2

ll dp1[303][90909];
ll dp2[303][90909];
int main() {
	ll tempmod = 998244353;
	int N;
	cin >> N;
	vector<int>a(N);
	int S = 0;
	rep(i, 0, N) {
		cin >> a[i];
		S += a[i];
	}

	dp1[0][0] = 1;
	for (int i = 0; i < N; i++) {
		for (int j = 0; j < 90909; j++) {
			if (j + a[i] < 90909) {
				dp1[i + 1][j + a[i]] += dp1[i][j];
				dp1[i + 1][j + a[i]] %= tempmod;
			}
			dp1[i + 1][j] += 2 * dp1[i][j];
			dp1[i + 1][j] %= tempmod;
		}
	}
	ll x = 0;
	rep(j, 0, 90909) {
		if (j * 2 >= S) {
			x += dp1[N][j];
			x %= tempmod;
		}
	}

	dp2[0][0] = 1;
	for (int i = 0; i < N; i++) {
		for (int j = 0; j < 90909; j++) {
			if (j + a[i] < 90909) {
				dp2[i + 1][j + a[i]] += dp2[i][j];
				dp2[i + 1][j + a[i]] %= tempmod;
			}
			dp2[i + 1][j] += dp2[i][j];
			dp2[i + 1][j] %= tempmod;
		}
	}
	ll y = (S % 2 == 0) ? dp2[N][S / 2] : 0;

	ll ans = 1;
	rep(i, 0, N) {
		ans *= 3;
		ans %= tempmod;
	}
	ans = (ans - 3 * x + 8 * tempmod) % tempmod;
	ans += 3 * y;
	cout << ans%tempmod << endl;


	return 0;
}


Measured memory_bytes: 429696
#include <bits/stdc++.h>
#define ll long long
#define double long double
#define rep(i,n) for(int i=0;i<(n);i++)
#define REP(i,n) for(int i=1;i<=(n);i++)
#define mod (ll)(1e9+7)
#define inf (ll)(3e18+7)
#define pi (double) acos(-1)
#define P pair<int,int>
#define PiP pair<int,pair<int,int>>
#define all(x) x.begin(),x.end()
#define rall(x) x.rbegin(),x.rend()
using namespace std;

int main() {
	ll n, m, x, ans = inf;
	cin >> n >> m >> x;
	vector<ll> c(n);
	vector<vector<ll>> a(n, vector<ll>(m));
	rep(i, n){
		cin >> c[i];
		rep(j, m){
			cin >> a[i][j];
		}
	}
	for(int bit = 0; bit < (1<<n); bit++){
		vector<ll> sum(n, 0);
		ll now = 0;
		rep(i, n){
			if(bit & (1<<i)){
				now += c[i];
				rep(j, m){
					sum[j] += a[i][j];
				}
			}
		}
		bool ok = true;
		rep(i, m)if(sum[i] < x)ok = false;
		if(ok)ans = min(ans, now); 
	}
	cout << (ans == inf ? -1 : ans) << endl;
}


Measured memory_bytes: 3636
#include <iostream>
#include <fstream>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <algorithm>
#include <vector>
#include <string>
#include <queue>
#include <deque>
#include <stack>
#include <set>
#include <map>
#include <bitset>
#include <sstream>
#include <iomanip>

using namespace std;

typedef long long ll;
typedef vector <int> vi;
typedef vector <vector <int>> vii;
typedef vector <long long> vll;
typedef vector <string> vs;
typedef vector <char> vc;
typedef set <int> si;
typedef set <string> ss;
typedef queue <int> qi;
typedef queue <long long> qll;
typedef queue <string> qs;
typedef queue <char> qc;
typedef struct board board;
typedef pair <int, int> pi;
typedef pair <long long, long long> pll;
typedef pair <int, pair<int, int>> pii;

#define eb emplace_back
#define ppb pop_back
#define clr(a) a.clear()
#define F first
#define S second
#define mkp make_pair

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

#define left(x) x * 2
#define right(x) x * 2 + 1

#define meme(a, b, c) fill(a + 1, a + 1 + b, c)

#define max(a, b) (a > b ? a : b)
#define min(a, b) (a > b ? b : a)
#define abs(a) (a > 0? a : -(a))

#define move(s) s += "#"

#define fr(i, a, b) for (ll i = a; i <= b; ++ i)
#define rf(i, a, b) for (ll i = a; i >= b; -- i)

#define eprintf(...) fprintf(stderr, __VA_ARGS__);

void to_pray() {
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    cerr << "Ready\n";
}

const int N = 4e6 + 10;
const int NN = 1e3 + 10;
const int NNN = 2e3 + 9;
const int MOD = 1e9 + 7;
const int INF = 1e9 + 7;
const ll LLINF = 1e12 + 7;
const ll P = 53;
const int EPS = 1e-9 - 8;
const int vN = 2e4 + 10;
const int sz = (1 << 22) - 1;
const double PI = acos(-1);

int main () {
    to_pray();

    int x, a;
    cin >> x >> a;
    
    cout << (x < a ? 0 : 10);
    
    cout << '\n';
    return 0;
}

Measured memory_bytes: 256
#include <stdio.h>

int a2102(char c[9][2]){
  int d,e,i,j,k;

  for(i=1;i<9;i++) if(c[0][1]!=c[i][1]) break;
  if(i==9 && c[1][0]==c[0][0]+1 && c[2][0]==c[0][0]+1 &&
     c[3][0]==c[0][0]+2 && c[4][0]==c[0][0]+2 && c[5][0]==c[0][0]+2 &&
     c[6][0]==c[0][0]+3 && c[7][0]==c[0][0]+3 && c[8][0]==c[0][0]+4) return 3;
    
  for(d=0,i=0;i<3;i++){
   if((c[i*3][1]==c[i*3+1][1] && c[i*3][1]==c[i*3+2][1]) &&
     ((c[i*3][0]==c[i*3+1][0] && c[i*3][0]==c[i*3+2][0]) ||
     (c[i*3][0]+1==c[i*3+1][0] && c[i*3][0]+2==c[i*3+2][0]))) d++;
  }
  if(d>=2) return d;
  for(i=0;i<2;i++){
    for(j=1;j<6;j++){
      if(c[i*3+j][1]!=c[i*3][1]) break;
    }
    if(j==6 && (
       (c[i*3+1][0]==c[i*3][0]+1 && c[i*3+2][0]==c[i*3][0]+1 &&
        c[i*3+3][0]==c[i*3][0]+2 && c[i*3+4][0]==c[i*3][0]+2 && c[i*3+5][0]==c[i*3][0]+3) ||
       (c[i*3+1][0]==c[i*3][0] && c[i*3+2][0]==c[i*3][0]+1 &&
        c[i*3+3][0]==c[i*3][0]+1 && c[i*3+4][0]==c[i*3][0]+2 && c[i*3+5][0]==c[i*3][0]+2))) return 3;
  }
  for(i=0;i<3;i++){
    if(c[i][1]==c[i+3][1] && c[i][1]==c[i+6][1] &&
       c[i][0]+1==c[i+3][0] && c[i][0]+2==c[i+6][0]) d++;
  }
  return d;
}

void swap(char *a,char *b){
  char c;
  c=*a;
  *a=*b;
  *b=c;
}

int main(){
  char c[9][2],c1,c2;
  int d,i,j,k,l,n;

  scanf("%d\n",&n);
  for(i=0;i<n;i++){
    for(j=0;j<2;j++){
      for(k=0;k<9;k++){
        c[k][j]=getchar();getchar();
      }
    }
    for(j=0;j<8;j++){
      for(k=j+1;k<9;k++){
        if(c[j][1]<c[k][1]){
          swap(&c[j][0],&c[k][0]);
          swap(&c[j][1],&c[k][1]);
        }
        if(c[j][1]==c[k][1] && c[j][0]>c[k][0]){
          swap(&c[j][0],&c[k][0]);
          swap(&c[j][1],&c[k][1]);
        }
      }
    }
    printf("%d\n",a2102(c)/3);
  }
  return 0;
}

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

int main() {
  int d,s,t;
  float tcal;
  
  cin >>d>>t>>s;
  
  tcal = (float)d/s;
  //cout<<tcal<<endl;
  if(tcal > t){
    cout<<"No\n";
    return 0;
  }
  
  else{
    cout<<"Yes\n";
    return 0;
  }
}

Measured memory_bytes: 3588
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define all(x) (x).begin(),(x).end()
using namespace std;
using ll = long long;
using P = pair<int,int>;
template <class T> void chmin(T &a, const T &b) noexcept { if (b < a) a = b; }
template <class T> void chmax(T &a, const T &b) noexcept { if (a < b) a = b; }
void debug_out() { cout << endl; }
template <typename Head, typename... Tail>
void debug_out(Head H, Tail... T) { cout << H << " "; debug_out(T...); }
#ifdef _DEBUG
  #define debug(...) debug_out(__VA_ARGS__)
#else
  #define debug(...) 
#endif

int main() {
  std::cin.tie(nullptr);
  std::ios_base::sync_with_stdio(false);
  std::cout << std::fixed << std::setprecision(15);
  int n;
  cin >> n;
  vector<ll> H(n);
  int ans = 0;
  rep(i,n) cin >> H[i];
  for (int h = 1; h <= 100; ++h) {
    int cnt = 0;
    rep(k,n) {
      if (H[k] >= h) {
        cnt++;
        int j = k;
        while(j < n) {
          if (H[j] >= h) j++;
          else break;
        }
        k = j;
      }
    }
    ans += cnt;
  }
  cout << ans << endl;
  return 0;
}

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

int main(void)
{
	double x1, y1, x2, y2;
	scanf("%lf", &x1);
	scanf("%lf", &y1);
	scanf("%lf", &x2);
	scanf("%lf", &y2);
	printf("%lf\n", sqrt(pow(x2 - x1, 2) + pow(y2 - y1, 2)));
	return 0;
}


Measured memory_bytes: 2112
#include<stdio.h>
int main()
{
  int a,b=1,c;
  while(1){
    scanf("%d%d\n",&a,&b);
    if(a==0 && b==0){break;}
    else if(a>b)printf("%d %d\n",b,a);
    else printf("%d %d\n",a,b);
    
  }
  return 0;
}


Measured memory_bytes: 1972