akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <vector>
#include <algorithm>
 
using namespace std;
 
const int N = 50;
 
double max(double a, double b){
    return a > b ? a : b;
}
 
int main()
{
    int n;
    double cost[N][N] = {};
    cin >> n;
    vector<int> array(n);
    for(int i=0;i<n;i++){
        cin >> array[i];
    }
    sort(array.begin(), array.end());

    for(int i=0;i<n;i++){
        cost[0][i] = array[i];
    }
 
    for(int l=2;l<n+1;l++){
        for(int i=0;i<n-l+1;i++){
            for(int k=0;k<l-1;k++){
                cost[l-1][i] = max(cost[l-1][i], (cost[k][i] + cost[l-k-2][i+k+1]) / 2);
            }
        }
    }
 
    cout << cost[n-1][0] << endl;
}

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

typedef long long ll;
int n;
string s;

bool check(int x)
{
    map<string,int>v;
    for(int i=1; i<=n+1-x; i++)
    {
        string a=s.substr(i-1,x);
        if(v[a])
        {
            if(i-v[a]>=x)
                return true;

        }

            else
                v[a]=i;
    }
    return false;
}

int main()
{
    cin>>n;
    cin>>s;
    int l=0;
    int r=n/2;
    while(l<=r)
    {
        int mid=(l+r)/2;
        if(check(mid))
            l=mid+1;
        else
            r=mid-1;
    }
    cout<<r<<endl;
    return 0;
}
//#include<bits/stdc++.h>
//using namespace std;
//
//int n;
//string s;
//
//bool check(int x) {
//    map<string, int> v;
//    for(int i = 1; i <= n + 1 - x; i++) {
//        string a = s.substr(i - 1, x);
//        if(v[a]) {
//            if(i - v[a] >= x) return true;
//        }
//        else v[a] = i;
//    }
//    return false;
//}
//
//int main() {
//    cin >> n >> s;
//    int l = 0, r = n / 2;
//    while(l <= r) {
//        int m = (l + r) >> 1;
//        if(check(m)) l = m + 1;
//        else r = m - 1;
//    }
//    cout << r << endl;
//}


Measured memory_bytes: 6668
#include<bits/stdc++.h>
 using namespace std;
int main() {
  int n;
  cin>>n;
  int a[n];
  for(int i=0;i<n;++i) {
    cin>>a[i];
  }
  int maxm = a[0], c=1;
  for(int i=1;i<n;++i) {
    maxm = max(maxm, a[i]);
    if(maxm == a[i]) {
      c++;
    }
  }
  cout<<c;
  return 0;
}

Measured memory_bytes: 256
let () =
  Scanf.scanf "%d %d %d" @@ fun n m c ->
  let b = Array.init m (fun _ -> Scanf.scanf " %d" ((+) 0)) in
  let a = Array.init n (fun _ ->
    Array.init m (fun _ -> Scanf.scanf " %d" ((+) 0))) in
  Array.init n (fun i -> 
    let s = 
      Array.init m (fun j -> a.(i).(j) * b.(j))
      |> Array.fold_left (+) 0
    in
    if s + c > 0 then 1 else 0)
  |> Array.fold_left (+) 0
  |> Printf.printf "%d\n"


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


void solve(long long A, long long P){
  cout << (A*3 + P) / 2 << endl;
}

// Generated by 1.1.4 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
int main(){
    long long A;
    scanf("%lld",&A);
    long long P;
    scanf("%lld",&P);
    solve(A, P);
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
    #define all(v) v.begin(),v.end()
    using namespace std;
    int main(){
        long long n;
        cin>>n;
        vector<long long> h(n);
        for(auto&&i:h)
            cin>>i;
        for(int i=n-1;i>0;i--){
            if(h[i]==h[i-1]-1){
                h[i-1]--;
            }
			else if(h[i]<h[i-1]){
				cout<<"No"<<endl;
				return(0);
			}
        }
        for(int i=0;i<n-1;i++){
            if(h[i]>h[i+1]){
                cout<<"No"<<endl;
                return(0);
            }
        }
        cout<<"Yes"<<endl;
        return(0);
    }

Measured memory_bytes: 4044
#include <bits/stdc++.h>
typedef long long ll;
#define rep(i,a,n) for(ll i = a;i < n;i++)
#define rrep(i,a,n) for(ll i = n; i >= a;i--)
#define index_check(i,n) if(i > n-1 || i < 0) continue; 
#define LINF 1e18
#define INF 1e9
#define MOD (ll)(1e9+7)
using namespace std;

#define fs first
#define sc second

using P = pair<ll,ll>;
using Pll = pair<P,ll>;
using PQ = priority_queue<P,vector<P>,greater<P>>;

signed main(){
    ll a[3];
    rep(i,0,3){
        cin >> a[i];
    }

    sort(a,a+3);
    ll cnt = 0;
    if((a[2] - a[1]) % 2 && (a[2] - a[0]) % 2){
        cnt += (a[2] - a[1])/2;
        cnt += (a[2] - a[0])/2;
        cnt++;
    }
    else if((a[2] - a[1]) % 2 == 0 && (a[2] - a[0]) % 2 == 0){
        cnt += (a[2] - a[1]) / 2;
        cnt += (a[2] - a[0]) / 2;
    }
    else{
        cnt += (a[2] - a[1]) / 2;
        cnt += (a[2] - a[0]) / 2;
        cnt += 2;
    }

    cout << cnt << endl;
    return 0;
}


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

int main() {
  int K;
  vector<int> n(3);
  for(int i = 0; i < 3; i++) {
    cin >> n[i];
  }
  cin >> K;
  for (int i = 0; i < K; i++) {
    sort(n.begin(), n.end());
    reverse(n.begin(), n.end());
    n[0] *= 2;
  }
  int ans = 0;
  for (int i = 0; i < 3; i++) {
    ans += n[i];
  }
  cout << ans << endl;
};


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

int main() {
	string a, b;
	cin >> a >> b;
	for (int i = 0; i < b.length(); i++) {
		cout << a[i] << b[i];
	}
	if (a.length() > b.length()) {
		cout << a[a.length()-1] << endl;
	}
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define int long long
using namespace std;
#define deb(x) cout<<#x<<" = "<<x<<"\n";


signed main()
{
	//#ifndef ONLINE_JUDGE
	//freopen("input.txt", "r", stdin);
	//freopen("output.txt", "w", stdout);
	//#endif
	/************************************/
	
	
	int n; cin>>n;
	int a[n+1];
	vector<int> pos;
	for(int i=1; i<=n; i++)
	{
		cin>>a[i]; if(a[i] != i) pos.push_back(i);
	}
	
	if(pos.size() > 2 or pos.size() == 1) cout<<"NO\n";
	else cout<<"YES\n";
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
    using namespace std;
    #define Int int64_t
    #define dump(x) cout << (x) << endl
    #define fi first
    #define se second
    Int mod = 1e9+7;
    Int INF = 1e18;
    double EPS = 0.00000001;
    //Int mod = 1e6+3;

    int main() {
        double ax, ay, bx, by;
        cin >> ax >> ay >> bx >> by;
        complex<double> a(ax, ay), b(bx, by);
        int q;
        cin >> q;
        for (int i = 0; i < q; i++) {
            double px, py;
            cin >> px >> py;
            complex<double> p(px, py);
            complex<double> ab = (b - a), ap = (p - a);
            complex<double> e = ab / abs(ab);
            ap = ap / e;
            if (imag(ap) - EPS > 0) {
                dump("COUNTER_CLOCKWISE");
            }
            else if (imag(ap) + EPS < 0) {
                dump("CLOCKWISE");
            }
            else {
                if (real(ap) + EPS < 0) {
                    dump("ONLINE_BACK");
                }
                else if (real(ap) - EPS > abs(ab)) {
                    dump("ONLINE_FRONT");
                }
                else {
                    dump("ON_SEGMENT");
                }
            }
        }
        return 0;
    }


Measured memory_bytes: 3292
#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
int main(){
	int n,k;
	int s[60];
	int sum = 0;
	scanf("%d%d",&n,&k);
	for(int i = 1;i <= n;i++ )
		scanf("%d",&s[i]);
		sort(s+1,s+n+1);
		while(k--){
			sum += s[n-k];
			}
			printf("%d",sum);
	return 0;
	}

Measured memory_bytes: 128
using System;
using System.Collections.Generic;
using System.IO.Pipes;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace AtCoder.Abc
{
    class B_170_CraneAndTurtle
    {
        public static void Main(string[] args)
        {
            var sw = new System.IO.StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false };
            Console.SetOut(sw);

            // 整数配列の入力
            var nArray = Console.ReadLine().Split(' ').Select(i => long.Parse(i)).ToArray();

            long X = nArray[0];
            long Y = nArray[1];

            long tsuru = 0;
            long kame = X;

            bool flg = false;

            for (int i = 0; i <= X; i++, tsuru++, kame--)
            {
                if (tsuru * 2 + kame * 4 == Y)
                {
                    Console.WriteLine("Yes");
                    flg = true;
                    break;
                }
            }

            if (flg == false)
            {
                Console.WriteLine("No");
            }
            

            string result = "";

            Console.WriteLine(result);

            Console.Out.Flush();
        }
    }
}


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

using namespace std;

typedef long long ll;
typedef long double ld;
typedef pair<ll, ll> pll;
typedef vector<ld> vd;
typedef vector<ll> vll;
typedef vector<string> vstr;
typedef vector<vector<ll>> vvll;
typedef vector<pair<ll, ll>> vpll;
typedef priority_queue<ll, vector<ll>, greater<ll>> spqll;  // 小さい順に取り出し
typedef priority_queue<ll, vector<ll>, less<ll>> bpqll;     // 大きい順に取り出し

#define REP(i, n) for (ll i = 0; i < (ll)(n); i++)
#define FOR(i, a, b) for (ll i = (ll)a; i < (ll)b; i++)
#define IREP(i, v) for (auto i = (v).begin(); i != (v).end(); i++)
#define FI first
#define SE second
#define MP make_pair
#define MT make_tuple
#define PB push_back
#define TS to_string
#define NP next_permutation
#define ALL(v) (v).begin(), (v).end()
#define SZ(x) (ll) x.size()
#define SP(x) setprecision((ll)x)


ll INF = 1e9;
ll NIL = -1;
ll MOD = 1000000007;
ll LINF = 1e18;
ld EPS = 1e-9;
ld PI = M_PI;
vll dx = {1, 0, -1, 0, 1, -1, -1, 1};
vll dy = {0, 1, 0, -1, 1, 1, -1, -1};
ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a;} //最大公約数
ll lcm(ll a, ll b) { return a / gcd(a, b) * b;}     //最小公倍数

void yes(){ cout << "Yes" << endl;}
void no(){ cout << "No" << endl;}

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

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

    ll n;
    string s;
    cin >> n >> s;
    ll ans = 0;
    queue<ll> w;
    stack<ll> r;
    REP(i,n){
        if(s[i]=='W'){
            w.push(i);
        }
        else{
            r.push(i);
        }
    }
    while(!w.empty() && !r.empty()){
        ll wh = w.front();
        ll re = r.top();
        w.pop();
        r.pop();
        if(wh<re){
            ans++;
        }
        else{
            break;
        }
    }

    cout << ans <<endl;


    
    return 0;
}



Measured memory_bytes: 5288
#include <algorithm>
#include <cassert>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <iostream>
#include <vector>
#include <sstream>
#include <set>
using namespace std;
using ll = long long;

class range {private: struct I{int x;int operator*(){return x;}bool operator!=(I& lhs){return x<lhs.x;}void operator++(){++x;}};I i,n;
public:range(int n):i({0}),n({n}){}range(int i,int n):i({i}),n({n}){}I& begin(){return i;}I& end(){return n;}};

char s[100100];

int main() {
  while (scanf(" %s", s) != EOF) {
    int n = strlen(s);
    int res1 = -1, res2 = -1;
    for (int i : range(n)) {
      for (int j : range(i + 2, i + 5)) {
        if (j >= n + 1) continue;
        // [i, j)
        vector<int> v(26);
        for (int k : range(i, j)) v[s[k] - 'a']++;
        int good = 0;
        for (int k : range(26)) {
          if (v[k] > (j - i) / 2) good = 1;
        }
        if (good) {
          res1 = i + 1;
          res2 = j;
        }
      }
    }

    printf("%d %d\n", res1, res2);
  }
}


Measured memory_bytes: 384
#define NDEBUG

#include <unordered_map>
#include <functional>
#include <algorithm>
#include <iostream>
#include <cassert>
#include <cstring>
#include <iomanip>
#include <utility>
#include <string>
#include <vector>
#include <cmath>
#include <stack>
#include <queue>
#include <tuple>
#include <set>
#include <map>

// [0, max)
#define FOR0(var, max) for (sl (var) = 0; (var) < (max); ++(var))
// [min, max)
#define FORi(var, min, max) for (sl (var) = (min); (var) < (max); ++(var))
// [min, max)
#define FORi_INV(var, min, max) for (sl (var) = (max) - 1; (var) + 1 > (min); --(var))
#define FORITER(var, iter) for (auto (iter) = (var).begin(); (iter) != (var).end(); (iter)++)
#define FORITER_INV(var, iter) for (auto (iter) = (var).rbegin(); (iter) != (var).rend(); (iter)++)

// a < b < c
#define LTLT(a, b, c) (((a) < (b)) && ((b) < (c)))
// a <= b < c
#define LELT(a, b, c) (((a) <= (b)) && ((b) < (c)))
// a < b <= c
#define LTLE(a, b, c) (((a) < (b)) && ((b) <= (c)))
// a <= b <= c
#define LELE(a, b, c) (((a) <= (b)) && ((b) <= (c)))

#ifndef NDEBUG
#  define MASSERT(cond) m_assert(cond, __LINE__, #cond);
#else
#  define MASSERT(...)
#endif

using namespace std;

using uc = unsigned char;
using ui = unsigned int;
using ul = unsigned long long int;

using sc = signed char;
using si = signed int;
using sl = signed long long int;

using ld = long double;

void m_assert(const bool& cond, const sl& line, const char *condstr) {
  if (!cond) {
    cerr << "Assertion Failed: " << condstr << " at line " << line << endl;
    exit(1);
  }
}

static sl N;
static vector<sl> Ai;
static vector<vector<pair<sl, sl>>> Ti;

bool is_valid_choice(ui _choice) {
  vector<bool> choice(N);
  FOR0(i, N) {
    choice[i] = (_choice & (1 << i)) != 0;
  }
  FOR0(i, N) {
    if(choice[i]) {
      FORITER(Ti[i], it) {
        if (choice[it->first] != (it->second == 1)) {
          return false;
        }
      }
    }
  }
  return true;
}

void solve(void) {
  ui res = 0;
  FOR0(i, 1<<N) {
    if (!is_valid_choice(i)) {
      continue;
    }
    ui count = __builtin_popcount(i);
    if (res < count) {
      res = count;
    }
  }
  cout << res << endl;
}

int main(void) {
  cin >> N;
  Ai.resize(N);
  Ti.resize(N);
  FOR0(i, N) {
    cin >> Ai[i];
    Ti[i].resize(Ai[i]);
    FOR0(j, Ai[i]) {
      cin >> Ti[i][j].first >> Ti[i][j].second;
      Ti[i][j].first--; // 1-indexed -> 0-indexed
    }
  }
  solve();
  return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
main(){
int i,j,k,l,n,m;
while(cin>>m>>n){
 int x[m+1]={0};
 for(i=0;i<n;i++){
    cin>>k>>j;
    x[j]++;
    x[k]++; }
    j=0;
    for(i=1;i<=m;i++) cout<<x[i]<<endl;
} return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main()
{
  double b,c,h,m;
  cin>>b>>c>>h>>m;
  double a,ha,ma,ans;
  ha=0.5 * (h * 60 + m);
  ma=m*6;
  a=abs(ha-ma);
  a=min(a,360-a);
  double pi = 2 * asin(1.0); 
  a=(a*pi)/180;
  ans=(b*b)+(c*c)-(2*b*c*cos(a));
  cout<<fixed<<setprecision(20)<<sqrt(ans)<<endl;
}

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

using namespace std;
long long a[200005];
map<long long,long long>mp;
int main(){
	long long n;
	cin>>n;
	long long ans=0;
	vector<long long>v;
	for(int i=0;i<n;i++)cin>>a[i];
	for(int i=0;i<n;i++){
		mp[a[i]]++;
		v.push_back(a[i]);
	}
	sort(v.begin(),v.end());
	vector<long long>vv;
	vv.push_back(v[0]);
	for(int i=1;i<v.size();i++){
		if(v[i]!=v[i-1])vv.push_back(v[i]);
	}
	for(int i=0;i<vv.size();i++){
		ans+=mp[vv[i]]*(mp[vv[i]]-1)/2;
	}
	for(int i=0;i<n;i++){
		long long cnt=ans;
		cnt-=mp[a[i]]*(mp[a[i]]-1)/2;
		mp[a[i]]--;
		cnt+=mp[a[i]]*(mp[a[i]]-1)/2;
		cout<<cnt<<endl;
		mp[a[i]]++;
	}
	return 0;
}

Measured memory_bytes: 14576
list_num = list(map(int, input().split(' ')))

if int(str(list_num[0])*list_num[1]) > int(str(list_num[1])*list_num[0]):
    print(int(str(list_num[0]) * list_num[1]))
else:
    print(int(str(list_num[1]) * list_num[0]))

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

int main() {
    int r, c;
    cin >> r >> c;
    int arr[r+1][c+1] = {}, i, j;

    for(i=0; i<r; ++i) {
        for(j=0; j<c; ++j) {
            cin >> arr[i][j];
        }
    }

    for(i=0; i<r; ++i) {
        for(j=0; j<c; ++j) {
            arr[i][c] += arr[i][j];
        }
    }

    for(j=0; j<c+1; ++j) {
        for(i=0; i<r; ++i) {
            arr[r][j] += arr[i][j];
        }
    }

    for(i=0; i<r+1; ++i) {
        cout << arr[i][0];
        for(j=1; j<c+1; ++j) {
            cout << ' ' << arr[i][j];
        }
        cout << endl;
    }

    return 0;
}

Measured memory_bytes: 3136
import sys
from math import factorial
from collections import deque
input = sys.stdin.readline
sys.setrecursionlimit(10 ** 6)

class Combination:
    """
    O(n)の前計算を1回行うことで，O(1)でnCr mod mを求められる
    n_max = 10**6のとき前処理は約950ms (PyPyなら約340ms, 10**7で約1800ms)
    使用例：
    comb = Combination(1000000)
    print(comb(5, 3))  # 10
    """
    def __init__(self, n_max, mod=10**9+7):
        self.mod = mod
        self.modinv = self.make_modinv_list(n_max)
        self.fac, self.facinv = self.make_factorial_list(n_max)

    def __call__(self, n, r):
        if n < r:
            return 0
        return self.fac[n] * self.facinv[r] % self.mod * self.facinv[n-r] % self.mod

    def make_factorial_list(self, n):
        # 階乗のリストと階乗のmod逆元のリストを返す O(n)
        # self.make_modinv_list()が先に実行されている必要がある
        fac = [1]
        facinv = [1]
        for i in range(1, n+1):
            fac.append(fac[i-1] * i % self.mod)
            facinv.append(facinv[i-1] * self.modinv[i] % self.mod)
        return fac, facinv

    def make_modinv_list(self, n):
        # 0からnまでのmod逆元のリストを返す O(n)
        modinv = [0] * (n+1)
        modinv[1] = 1
        for i in range(2, n+1):
            modinv[i] = self.mod - self.mod//i * modinv[self.mod%i] % self.mod
        return modinv

comb = Combination(10 ** 5 + 5)
MOD = 10 ** 9 + 7

def permutations_count(n, r):
    return (comb(n,r) * factorial(r)) % MOD

def main():
    N, K = map(int, input().split())
    edge = [[] for _ in range(N)]
    for _ in range(N-1):
        a, b = map(int, input().split())
        a -= 1
        b -= 1
        edge[a].append(b)
        edge[b].append(a)

    ans = 1
    q = deque([])
    q.append((0,-1))
    while q:
        s, p = q.popleft()
        for v in edge[s]:
            if p == v:
                continue
            q.append((v,s))
        nk = K if p == -1 else K - 2
        c = len(edge[s]) + 1 if p == -1 else len(edge[s]) - 1
        ans *= permutations_count(nk,c)
        ans %= MOD

    

    print(ans)


    
if __name__ == "__main__":
    main()

Measured memory_bytes: 68300
from collections import defaultdict, deque, Counter
from heapq import heappush, heappop, heapify
import math
import bisect
import random
from itertools import permutations, accumulate, combinations, product
import sys
import string
from bisect import bisect_left, bisect_right
from math import factorial, ceil, floor
from operator import mul
from functools import reduce


sys.setrecursionlimit(2147483647)
INF = 10 ** 13
def LI(): return list(map(int, sys.stdin.buffer.readline().split()))
def I(): return int(sys.stdin.buffer.readline())
def LS(): return sys.stdin.buffer.readline().rstrip().decode('utf-8').split()
def S(): return sys.stdin.buffer.readline().rstrip().decode('utf-8')
def IR(n): return [I() for i in range(n)]
def LIR(n): return [LI() for i in range(n)]
def SR(n): return [S() for i in range(n)]
def LSR(n): return [LS() for i in range(n)]
def SRL(n): return [list(S()) for i in range(n)]
def MSRL(n): return [[int(j) for j in list(S())] for i in range(n)]
mod = 1000000007


def primes(n):
    is_prime = [True] * (n + 1)
    is_prime[0] = False
    is_prime[1] = False
    for i in range(2, int(n**0.5) + 1):
        if not is_prime[i]:
            continue
        for j in range(i * 2, n + 1, i):
            is_prime[j] = False
    return {i for i in range(n + 1) if is_prime[i]}



n = 10 ** 5
prime_set = primes(n)
q = I()
C = [0] * (n + 1)
for i in range(n + 1):
    if i % 2 and i in prime_set and (i + 1) // 2 in prime_set:
        C[i] = 1


acc = list(accumulate(C))
for i in range(q):
    l, r = LI()
    print(acc[r] - acc[l - 1])

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

int main() {
  int n,i;
  cin>>n;
  int h[n];
  for(i=0;i<n;i++)
    cin>>h[i];
  int dp[n]={};
  dp[1]=abs(h[1]-h[0]);
  for(i=0;i<n-2;i++)
    dp[i+2]=min( dp[i]+abs(h[i+2]-h[i]) , dp[i+1]+abs(h[i+2]-h[i+1]) );
  cout << dp[n-1]<<endl;

}

Measured memory_bytes: 1024
#include <iostream>
#include <sstream>
#include <algorithm>
#include <string>
#include <cmath>
using namespace std;


int main()
{
	int a;
	cin >> a;
	if(a % 1000 == 0)
	{
		cout << 0;
	}
	else
	{
		cout << (a/1000+1)*1000-a;
	}
}



Measured memory_bytes: 3628
//AtCoder ABC062 A - Grouping
#include <bits/stdc++.h>
using namespace std;
using ll=int64_t;

int main() {
    vector<int> g1 = {1,3,5,7,8,10,12};
    vector<int> g2 = {4,6,9,11};
	vector<int> g3 = {2};
    int x,y;
    cin>>x>>y;
    auto check = [&](const vector<int>& v){
        bool f0 = find(v.begin(), v.end(), x) != v.end();
        bool f1 = find(v.begin(), v.end(), y) != v.end();
        return (f0&&f1);
    };
    bool ans = check(g1)||check(g2)||check(g3);
    cout<<(ans?"Yes":"No")<<endl;
	return 0;
}

Measured memory_bytes: 256
N = gets.to_i
A = gets.chomp.split(" ").map(&:to_i)

L = 10 ** 18

ans = A.inject do |a,b|
  a == -1 ? b == 0 ? 0 : -1 : ((a *= b; a) > L ? -1 : a)
end

puts "#{ans}\n"


Measured memory_bytes: 23468
n = int(input())
s = [input() for i in range(n)]
s = "".join(s).replace("-","")
n = len(s)
mod = 10**9+7
dp = [[0 for i in range(n+1)] for j in range(n+1)]
dp[0][0] = 1
for i in range(n):
  si = s[i]
  if si == "D":
    for j in range(1,n+1):
      dp[i+1][j] = (dp[i+1][j]+dp[i][j]*j)%mod
      dp[i+1][j-1] = (dp[i+1][j-1]+dp[i][j]*j**2)%mod
  else:
    for j in range(n):
      dp[i+1][j+1] = (dp[i+1][j+1]+dp[i][j])%mod
      dp[i+1][j] = (dp[i+1][j]+dp[i][j]*j)%mod
print(dp[n][0])


Measured memory_bytes: 6160
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<iomanip>
#include<math.h>
#include<complex>
#include<queue>
#include<deque>
#include<stack>
#include<map>
#include<set>
#include<bitset>
#include<functional>
#include<assert.h>
#include<numeric>
using namespace std;
#define REP(i,m,n) for(int i=(int)(m) ; i < (int) (n) ; ++i )
#define rep(i,n) REP(i,0,n)
using ll = long long;
const int inf=1e9+7;
const ll longinf=1LL<<60 ;
const ll mod=1e9+7 ;


int h,w,sx,sy,gx,gy,ans;
int a[22][22];
void dfs(int x,int y,int cnt){
	if(cnt>10)return;
	int nx=x,ny=y;
	while(nx>=0&&a[nx][y]!=1){
		if(nx==gx&&y==gy)ans=min(ans,cnt);
		--nx;
	}
	++nx;
	if(nx>0&&nx!=x){
		a[nx-1][y]=0;
		dfs(nx,y,cnt+1);
		a[nx-1][y]=1;
	}
	nx=x;
	while(nx<=h-1&&a[nx][y]!=1){
		if(nx==gx&&y==gy)ans=min(ans,cnt);
		++nx;
	}
	--nx;
	if(nx<h-1&&nx!=x){
		a[nx+1][y]=0;
		dfs(nx,y,cnt+1);
		a[nx+1][y]=1;
	}
	while(ny>=0&&a[x][ny]!=1){
		if(x==gx&&ny==gy)ans=min(ans,cnt);
		--ny;
	}
	++ny;
	if(ny>0&&ny!=y){
		a[x][ny-1]=0;
		dfs(x,ny,cnt+1);
		a[x][ny-1]=1;
	}
	ny=y;
	while(ny<=w-1&&a[x][ny]!=1){
		if(x==gx&&ny==gy)ans=min(ans,cnt);
		++ny;
	}
	--ny;
	if(ny<w-1&&ny!=y){
		a[x][ny+1]=0;
		dfs(x,ny,cnt+1);
		a[x][ny+1]=1;
	}
}

void solve(){
	rep(i,h)rep(j,w){
		cin>>a[i][j];
		if(a[i][j]==2)sx=i,sy=j;
		if(a[i][j]==3)gx=i,gy=j;
	}
	ans=inf;
	dfs(sx,sy,1);
	cout<<(ans==inf?-1:ans)<<endl;
}
int main(){
	while(cin>>w>>h,h!=0)solve();
	return 0;
}


Measured memory_bytes: 3100
import java.util.*;
public class Main { 
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		int a = sc.nextInt();
		int b = sc.nextInt();
		int result = 0;
        if(a <= 9 && b <= 9){
            result = a * b;
        }else{
            result = -1;
        }
		System.out.println(result);
     }
}

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

using namespace std;

#define rep(i, a, b) for (int i = (a); i < (b); ++i)
#define sz(s) (int)s.size()

const int MOD = int(1e9) + 7;

int main() {
    int n;
    cin >> n;
    vector<int> a(n);
    for (auto &v : a) cin >> v;
    sort(a.begin(), a.end());
    int val = a[0];
    int f = abs(2 * a[0] - a.back());
    rep(i, 0, n - 1) {
        int cf = abs(2 * a[i] - a.back());
        if (cf < f) {f = cf; val = a[i];}
    }
    cout << a.back() << ' ' << val << '\n';
}

Measured memory_bytes: 640
n = int(input())

arr = list(map(int, input().split()))
arr.sort()
ans = 0
for i in range(n):
    for j in range(i+1,n):
        for k in range(j+1,n):
            if (arr[i]!=arr[j]) and (arr[i]!=arr[k]) and (arr[j]!=arr[k]):
                if (arr[i]+arr[j])>arr[k]:
                    ans+=1
                
print(ans)

Measured memory_bytes: 9088
#include <bits/stdc++.h>
using namespace std;
#include <ext/pb_ds/assoc_container.hpp> 
#include <ext/pb_ds/tree_policy.hpp> 
using namespace __gnu_pbds; 
#define ordered_set tree<int,null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update> 
#define ordered_set_pair tree<pair<int,int>,null_type,less<pair<int,int>>, rb_tree_tag,tree_order_statistics_node_update> 
#define ordered_set_mutiset tree<int,null_type,less_equal<int>, rb_tree_tag,tree_order_statistics_node_update>
typedef long long int ll;
typedef long double ld;
typedef unsigned long long int ull;
typedef pair<int,int> pi; 
#define PI 3.1415926535897932384
#define FOR(i,vv,n) for(int i=vv;i<n;i++)
#define FORR(i,n,vv) for(int i=n-1;i>=vv;i--)
#define ve vector 
#define maxind(v) (max_element(v.begin(),v.end())-v.begin())
#define minind(v) (min_element(v.begin(),v.end())-v.begin())
#define maxe(v) *max_element(v.begin(),v.end())
#define mine(v) *min_element(v.begin(),v.end())
#define pb push_back
#define pf push_front
#define ppb pop_back
#define ppf pop_front
#define eb emplace_back
#define FAST ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define mp make_pair
#define M 1000000007ll
#define INF 1000000000000000000ll
#define PRECISE cout.precision(18);
#define all(v) v.begin(),v.end()
#define BS(v,n) binary_search(all(v),n)
#define srt(v) sort(v.begin(),v.end())
#define rsrt(v) sort(all(v),greater <ll>())
#define uni(v) v.resize(unique(all(v))-v.begin())
#define F first
#define S second
#define GET(i,p) get<p>(i)


int main(){



    FAST
//	PRECISE

ll n,k;
cin>>n>>k;

ve <ll> v(n);
FOR(i,0,n)
cin>>v[i];
FOR(i,k,n){
	if(v[i]>v[i-k])cout<<"Yes";
	else cout<<"No";
	cout<<"\n";
}


return 0;
 }
 

Measured memory_bytes: 4784
from itertools import product
h, w, k = map(int, input().split())
CHOCO = [list(map(int, input())) for _ in range(h)]
# pythonだと重いケースが通ったり通らなかったり
# h, w, k = 10, 1000, 2
# CHOCO = [list(map(int, "11010"*200)) for _ in range(h)]
INF = 10**5

# print(h, w, k)
# for row in CHOCO:
#     print("".join(map(str, row)))

# 水平方向の切れ込み全探索
it = ["01"]*(h-1)
ans = INF
for x in product(*it):
    # print("".join(x))
    # 貪欲に垂直方向に切れ込みをいれる
    cnt = sum(map(int, x))

    # pieceごとに集約して、それぞれで貪欲に切る
    agg = [[0]*(w) for _ in range(cnt+1)]
    *ls, = map(int, x+('1',))
    for i in range(w):
        prev = c = 0
        for j, split in enumerate(ls):
            if split:
                agg[c][i] = prev+CHOCO[j][i]
                prev = 0
                c += 1
            else:
                prev += CHOCO[j][i]
    # print(agg)

    # 集約した配列を貪欲に切っていく
    # 切れない場合に注意
    tmp = [0]*(cnt+1)
    for xyz in zip(*agg):
        cannot_split = False
        can_continue = True
        for i, x in enumerate(xyz):
            if x > k:
                cannot_split = True
                break
            if x+tmp[i] > k:
                can_continue = False
                break

        if cannot_split:
            break

        if can_continue:
            for i, x in enumerate(xyz):
                tmp[i] += x
                continue
        else:
            for i, x in enumerate(xyz):
                tmp[i] = x
            cnt += 1

    if cannot_split:
        continue
    # print(ans, cnt, tmp)
    ans = min(ans, cnt)
print(ans)


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

int num(int x) {
	if (x == 4)return 5;
	else if (x > 4)return x + 2;
	else return x;
}

int main() {
	int n;
	while (cin >> n, n) {
		stack<int>st;
		while (n > 7) {
			int a = (n % 8);
			a = num(a);
			st.push(a);
			n /= 8;
		}
		int a = num(n);
		st.push(a);

		int b = st.size();
		for (int i = 0;i < b;i++) {
			cout << st.top();
			st.pop();
		}
		cout << endl;
	}
	return 0;
}

Measured memory_bytes: 2948
# -*- coding: utf-8 -*-
"""
Created on Sat Aug 10 23:27:57 2019

@author: doppe
"""

A = int(input())
S = []
for i in range (0, A):
    S.append(input())

ans = 0
groupList = []
groupDict = {}

ans = 0
for i in range(0, len(S)):
    a = list(S[i])
    a.sort()
    b = ''.join(a)
    if b in groupDict:
        groupDict[b] += 1
    else :
        groupDict[b] = 1

for v in groupDict.values():
    ans += (v * (v - 1)) / 2
        
print(int(ans))
    


Measured memory_bytes: 24980
from collections import deque
def bfs(sy,sx):
  q=deque([[sy,sx]])
  visited[sy][sx]=0
  while q:
    y,x=q.popleft()
    for dy,dx in ([1,0],[-1,0],[0,1],[0,-1]):
      ny,nx=y+dy,x+dx
      if ny<0 or ny>h-1 or nx<0 or nx>w-1 or path[ny][nx]=="#":continue
      if path[ny][nx]=="." and visited[ny][nx]==-1:
        visited[ny][nx]=visited[y][x]+1
        q.append([ny,nx])
  res=-1
  for i in range(h):
    for j in range(w):
      res=max(visited[i][j],res)
  return res

h,w=map(int,input().split())
path=[input() for i in range(h)]
visited=[[-1]*w for i in range(h)]
sy,sx=0,0
gy,gx=0,0
ans=0
for i in range(h):
  for j in range(w):
    if path[i][j]=="#":continue
    sy=i
    sx=j
    visited=[[-1]*w for _ in range(h)]
    t=bfs(sy,sx)
    ans=max(t,ans)
print(ans)



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

int main (){
    string s;
    int c=0;
    cin >> s;
    if(s.at(0)=='1') c++;
    if(s.at(1)=='1') c++;
    if(s.at(2)=='1') c++;
cout << c <<endl;
return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <cmath>
using namespace std;
typedef long long ll;
ll k, n, a[50];

int main() {
	cin >> k;
	ll alpha = k/50;
	ll beta = k%50;
	for(ll i = 0; i < 50; i++){a[i] = 49+alpha;}
	for(ll i = 0; i < beta; i++){
		for(ll j = 0; j < 50; j++){
			if(j == i){a[j] += 50;}
			else{a[j]--;}
		}
	}
	cout << 50 << endl;
	cout << a[0];
	for(ll i = 1; i < 50; i++){cout << " " << a[i];}
	return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
#include<math.h>
#include<string.h>
const double EPS = 0.1;
int N,X[50],Y[50],R[50],C[50],i,j;
char dp[1<<25];

int isOver(int a,int b)
{
	double x=sqrt((double)(X[a]-X[b])*(X[a]-X[b])+(Y[a]-Y[b])*(Y[a]-Y[b])),y=R[a]+R[b];
	if(y>x)return 1;
	return 0;
}

int ch(int n,int f)
{
	int i;
	for(i=0;i<n;i++)
		if(i!=n&&!((f>>i)&1)&&isOver(i,n))
			return 0;
	return 1;
}

int dfs(int d,int f)
{
	int i,r=0,t,n;
	if(dp[f]!=-1)return dp[f];
	if(d==N)
		return 0;
	for(n=0;n<N;n++)
	{
		if(!((f>>n)&1)&&ch(n,f))
		{
			for(i=0;i<N;i++)
				if(i!=n&&C[i]==C[n]&&!((f>>i)&1)&&ch(i,f))
				{
					f^=(1<<i);
					f^=(1<<n);
					t=dfs(d+1,f)+2;
					r=r<t?t:r;
					f^=(1<<i);
					f^=(1<<n);
				}
		}
	}
	return dp[f]=r;
}


int main()
{
	for(;scanf("%d",&N),N;)
	{
		memset(dp,-1,sizeof(dp));
		for(i=0;i<N;i++)
			scanf("%d%d%d%d",&X[i],&Y[i],&R[i],&C[i]);
		printf("%d\n",dfs(0,0));
	}
	return 0;
}

Measured memory_bytes: 33376
N, K = map(int, input().split())
A = list(map(int, input().split()))
A = sorted(A)
B = A[:][::-1]

fac = [1, 1]
finv = [1, 1]
inv = [0, 1]
Mod = 10**9+7
def COMinit():
  #N_C_kのN
  for i in range(2, 10**5+10):
    fac.append(fac[-1]*i%Mod)
    inv.append((-inv[Mod%i] * (Mod//i)) % Mod)
    finv.append(finv[-1] * inv[-1] % Mod)


def COM(n, k):
  if n < 0 or k < 0 or n < k:
    return 0
  return fac[n] * (finv[k] * finv[n-k] % Mod) % Mod

COMinit()

comb = {}
for i in range(K-1, N):
  comb[(i, K-1)] = COM(i, K-1)

ans = 0
for i in range(K-1, N):
  ans += A[i] * comb[(i, K-1)]
  ans %= Mod
for i in range(K-1, N):
  ans -= B[i] * comb[(i, K-1)]
  ans %= Mod
print(ans)



Measured memory_bytes: 78504
//https://qiita.com/tanakh/items/0ba42c7ca36cd29d0ac8 より
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
    ($($r:tt)*) => {
        let s = {
            use std::io::Read;
            let mut s = String::new();
            std::io::stdin().read_to_string(&mut s).unwrap();
            s
        };
        let mut iter = s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
}

macro_rules! input_inner {
    ($iter:expr) => {};
    ($iter:expr, ) => {};
    ($iter:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($iter, $t);
        input_inner!{$iter $($r)*}
    };
}

macro_rules! read_value {
    ($iter:expr, ( $($t:tt),* )) => {
        ( $(read_value!($iter, $t)),* )
    };
    ($iter:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($iter, $t)).collect::<Vec<_>>()
    };
    ($iter:expr, chars) => {
        read_value!($iter, String).chars().collect::<Vec<char>>()
    };
    ($iter:expr, usize1) => {
        read_value!($iter, usize) - 1
    };
    ($iter:expr, $t:ty) => {
        $iter.next().unwrap().parse::<$t>().expect("Parse error")
    };
}

// ここまで

fn run() {
    input! {
        n: usize,
        d: [[u32; 3]; n],
    }
    let mut dp = vec![0; 3];
    let max = std::cmp::max;
    for ref v in &d {
        let mut next = vec![0; 3];
        for i in 0..3 {
            for j in 0..3 {
                if i == j {
                    continue;
                }
                next[j] = max (next[j], dp[i] + v[j]);
            }
        }
        dp = next;
    }
    let ans = dp.iter().max().unwrap();
    println! ("{}", ans);
}

fn main() {
    run();
}


Measured memory_bytes: 10492
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0; i<(n); i++)
#define FOR(i,a,n) for(int i=(a); i<(n); i++)
#define all(v) v.begin(), v.end()
#define fi first
#define se second
using namespace std;
using ll = long long;
using P = pair<int ,int>;
const int INF = 1e9;
const int MOD = 1e9+7;

void print() { cout << endl; }
template <class Head, class... Tail> void print(Head&& head, Tail&&... tail) { cout << head << ((sizeof...(tail)!=0)?" ":""); print(forward<Tail>(tail)...); }
template <class T> void print(vector<T> &vec) { for (auto& a : vec) { cout << a << ((&a!=&vec.back())?" ":""); } cout << endl; }
template <class T> void print(vector<vector<T>> &df) { for (auto& vec : df) { print(vec); } }

struct edge{
    int u, v, cost;
};

struct UnionFind {
	vector<int> data;

	UnionFind(int sz) {
		data.assign(sz, -1);
	}

	void unite(int x, int y) {
		x = find(x), y = find(y);
		if (x == y) return;
		if (data[x] > data[y]) swap(x, y);
		data[x] += data[y];
		data[y] = x;
	}

	int find(int k) {
		if(data[k] < 0) return(k);
		return data[k] = find(data[k]);
	}

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

	int size(int k)	{
		return -data[find(k)];
	}
};

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

    int n; cin >> n;
    vector<pair<int, P>> a(n);
    rep(i, n) {
        int x,y; cin >> x >> y;
        a[i] = make_pair(i, P(x, y));
    }
    sort(all(a), [](auto a, auto b) {return a.se.fi<b.se.fi;});
    vector<edge> es;
    rep(i, n-1) {
        int fr = a[i].fi, to = a[i+1].fi;
        int cost = abs(a[i].se.fi-a[i+1].se.fi);
        es.push_back(edge{fr, to, cost});
    }
    sort(all(a), [](auto a, auto b) {return a.se.se<b.se.se;});
    rep(i, n-1) {
        int fr = a[i].fi, to = a[i+1].fi;
        int cost = abs(a[i].se.se-a[i+1].se.se);
        es.push_back(edge{fr, to, cost});
    }
    sort(all(es), [](edge a, edge b){return a.cost<b.cost;});

    UnionFind uf(n);
    ll ans = 0;
    for(const auto & e: es) {
        if (!uf.same(e.u, e.v)) {
            ans += e.cost;
            uf.unite(e.u, e.v);
        }
        if (uf.size(0)==n) break;
    }
    cout << ans << endl;
}

Measured memory_bytes: 6132
def main():
    from functools import lru_cache
    import bisect
    S = input()
    T = input()
    if set(S) & set(T) != set(T):
        print(-1)
    else:
        lt = len(T)
        ls = len(S)
        st = set(T)
        D = dict()
        for t in st:
            D[t] = list()
            for i, s in enumerate(S):
                if t == s:
                    D[t].append(i)
        pre = -1
        cnt = 0

        @lru_cache(maxsize=None)
        def judge(pre, t):
            X = D[t]
            index = bisect.bisect(X, pre)
            if len(X) == index:
                return (X[0], True)
            else:
                return (X[index], False)

        for t in T:
            J = judge(pre, t)
            pre = J[0]
            if J[1]:
                cnt += 1

        print(cnt * len(S) + pre + 1)


if __name__ == "__main__":
    main()


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

using ll = long long int;

const int MAX = (int)(5e2 + 5);

int h, w;
int a[MAX][MAX];

int ans_n;
vector<vector<int>> ans_vec;

int main(void) {
  // Here your code !
  scanf("%d %d", &h, &w);

  for (int i = 1; i <= h; ++i) for (int j = 1; j <= w; ++j) {
    scanf("%d", &(a[i][j]));
  }

  for (int i = 1; i <= h; ++i) for (int j = 1; j <= w - 1; ++j) {
    if (a[i][j] % 2 == 1) {
      a[i][j + 1] += 1;
      a[i][j] -= 1;

      ans_n += 1;
      vector<int> tmp;
      tmp.push_back(i);
      tmp.push_back(j);
      tmp.push_back(i);
      tmp.push_back(j + 1);
      ans_vec.push_back(tmp);
    }
  }

  for (int i = 1; i <= h - 1; ++i) {
    if (a[i][w] % 2 == 1) {
      a[i + 1][w] += 1;
      a[i][w] -= 1;

      ans_n += 1;
      vector<int> tmp;
      tmp.push_back(i);
      tmp.push_back(w);
      tmp.push_back(i + 1);
      tmp.push_back(w);
      ans_vec.push_back(tmp);
    }
  }

  /*
  for (int i = 1; i <= h; ++i) {
    for (int j = 1; j <= w; ++j) {
      printf("%d ", a[i][j]);
    }
    printf("\n");
  }
  */

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

  for (auto e: ans_vec) {
    printf("%d %d %d %d\n", e[0], e[1], e[2], e[3]);
  }

  return 0;
}


Measured memory_bytes: 9904
#include<iostream>
#include<sstream>
#include<string>
#include<vector>
#include<algorithm>
//#include<boost/multiprecision/cpp_int.hpp>
//#include<boost/multiprecision/cpp_dec_float.hpp>
//namespace mp = boost::multiprecision;
using namespace std;
int main()
{

	int a, b;
	cin >> a >> b;
	if (1 <= a && 9 >= a && 1 <= b && 9 >= b)
	{
		cout << a * b << endl;
		return 0;
	}
	cout << -1 << endl;

	return 0;
}

Measured memory_bytes: 256
#include <algorithm>
#include <iostream>
#include <cstdio>
#include <map>
#include <numeric>
#include <cmath>
#include <set>
#include <sstream>
#include <string>
#include <vector>
#include <queue>
#include <stack>
#include <complex>
#include <string.h>
#include <unordered_set>
#include <unordered_map>
#include <bitset>
#include <iomanip>
#include <sys/time.h>
#include <tuple>
#include <random>
using namespace std;

#define endl '\n'
#define ALL(v) (v).begin(), (v).end()
#define RALL(v) (v).rbegin(), (v).rend()
#define UNIQ(v) (v).erase(unique((v).begin(), (v).end()), (v).end())

typedef long long ll;
typedef long double ld;
typedef pair<ll, ll> P;
typedef complex<double> comp;
typedef vector< vector<ld> > matrix;
struct pairhash {
public:
    template<typename T, typename U>
    size_t operator()(const pair<T, U> &x) const {
	size_t seed = hash<T>()(x.first);
	return hash<U>()(x.second) + 0x9e3779b9 + (seed<<6) + (seed>>2);
    }
};
const int inf = 1e9 + 9;
const ll mod = 1e9 + 7;
const double eps = 1e-8;
const double pi = acos(-1);

int h, w, k;
string s[11];

int calc(int b) {
    vector<vector<int>> vec;
    int l = 0;
    int cnt = 0;
    for (int i = 0; i < h-1; i++) {
        if ((b>>i)&1) {
            vector<int> v;
            for (int j = l; j <= i; j++) {
                v.push_back(j);
            }
            vec.push_back(v);
            l = i+1;
            cnt++;
        }
    }
    vector<int> v;
    for (int j = l; j < h; j++) {
        v.push_back(j);
    }
    vec.push_back(v);

    const int sz = vec.size();
    int c[sz];
    memset(c, 0, sizeof(c));
    int p = 0;
    for (int i = 0; i < w; i++) {
        for (int j = 0; j < sz; j++) {
            for (int v : vec[j]) {
                if (s[v][i] == '1') {
                    c[j]++;
                }
            }
        }
        if (i == p) {
            for (int j = 0; j < sz; j++) {
                if (c[j] > k)
                    return inf;
            }
        }
        for (int j = 0; j < sz; j++) {
            if (c[j] > k) {
                cnt++;
                memset(c, 0, sizeof(c));
                p = i;
                i--;
                break;
            }
        }
    }
    return cnt;
}

int solve() {
    int res = inf;
    for (int b = 0; b < (1<<(h-1)); b++) {
        res = min(res, calc(b));
    }
    return res;
}

void input() {
    cin >> h >> w >> k;
    for (int i = 0; i < h; i++) cin >> s[i];
}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout << fixed << setprecision(15);

    input();
    cout << solve() << endl;
}


Measured memory_bytes: 3160
import sys

sys.setrecursionlimit(10 ** 6)
int1 = lambda x: int(x) - 1
printV = lambda x: print(*x, sep="\n")
printH = lambda x: print(" ".join(map(str,x)))
def IS(): return sys.stdin.readline()[:-1]
def II(): return int(sys.stdin.readline())
def MI(): return map(int, sys.stdin.readline().split())
def LI(): return list(map(int, sys.stdin.readline().split()))
def LI1(): return list(map(int1, sys.stdin.readline().split()))
def LII(rows_number): return [II() for _ in range(rows_number)]
def LLI(rows_number): return [LI() for _ in range(rows_number)]
def LLI1(rows_number): return [LI1() for _ in range(rows_number)]

def main():
	N = II()
	if(N%2!=0):
		print(N//2+1)
	else:
		print(N//2)

if __name__ == '__main__':
	main()

Measured memory_bytes: 3064
#include "bits/stdc++.h"
#include "math.h"
#include "string.h"
#include "algorithm"
 
using namespace std;
typedef int64_t ll;
typedef vector<int64_t> vll;
typedef vector<vll> vvll;
typedef vector<bool> vb;
typedef vector<vb> vvb;
typedef vector<int> vin;
typedef pair<ll,ll> P;
typedef vector<P> vp;
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)
#define SIZE(a) int((a).size())


int main(){
  ll n;
  vll c(5);
  cin>>n;
  REP(i,5){
    cin>>c[i];
  }
  sort(c.begin(),c.end());
  if(n>=c[0]){
    if(n%c[0]!=0){
      cout<<n/c[0]+5<<endl;
    }
    else{
      cout<<n/c[0]+4<<endl;
    }
  }
  else{
    cout<<5<<endl;
  }
}


Measured memory_bytes: 256
n,k,s = map(int, input().split())

ans = []
if s == 10**9:
    for i in range(k):
        ans.append(10**9)
    for i in range(n-k):
        ans.append(1)

else:
    for i in range(k):
        ans.append(s)
    for i in range(n-k):
        ans.append(s+1)

print(*ans)

Measured memory_bytes: 49264
class Node:
    __slots__ = ["val", "prev", "next"]

    def __init__(self, val=None, prev=None, next=None):
        self.val = val
        self.prev = prev
        self.next = next


class DoublyLinkedList():
    def __init__(self):
        self.end = Node(val="END", prev=None, next=None)
        self.cur = self.end

    def insert(self, x):
        new_node = Node(val=x, prev=self.cur.prev, next=self.cur)

        if self.cur.prev != None:
            self.cur.prev.next = new_node
        self.cur.prev = new_node
        self.cur = new_node

    def move(self, d):
        if d > 0:
            for i in range(d):
                if self.cur.next == None:
                    break
                self.cur = self.cur.next
        elif d < 0:
            for i in range(abs(d)):
                if self.cur.prev == None:
                    break
                self.cur = self.cur.prev
        else:
            raise
    
    def erase(self):
        if self.cur == self.end:
            return

        if self.cur.prev != None:
            self.cur.prev.next = self.cur.next

        self.cur.next.prev = self.cur.prev
        self.cur = self.cur.next

    def print_elements(self):
        node_list = []
        crnode = self.end
        while True:
            if crnode.prev == None:
                break
            node_list.append(crnode.prev.val)
            crnode = crnode.prev
        for i in range(len(node_list)-1, -1, -1):
            print(node_list[i])



def main():

    q = int(input())

    L = DoublyLinkedList()

    for _ in range(q):
    
        command, *list_num = input().split()
    
        if   command == "0":
            # insert(x)
            x = int(list_num[0])
            L.insert(x)
        elif command == "1":
            # move(d)
            d = int(list_num[0])
            L.move(d)
        elif command == "2":
            # erase()
            L.erase()
        else:
            raise


    L.print_elements()


if __name__ == "__main__":
    main()



Measured memory_bytes: 45740
#include <bits/stdc++.h>
using namespace std;
#define x first
#define y second
#define dbg(x) cout << #x << '=' << x << '\n';
#define ll long long
#define pi pair<int,int>
#define pl pair<long long,long long>
#define lg length()
#define pb push_back
ifstream in("file.in");
ofstream out("file.out");
#define MAXN 100005
#define INF 1000000005
#define LINF 1000000000000000005

long long n,a,b,c,d,x,t;

int32_t main(){
    ios_base :: sync_with_stdio(0);
    cin >> n >> a >> b >> c >> d;
    x=b-a;
    for(int i=0;i<=n;i++){
        if(x>=-d*i+c*(n-1-i) && x<=-c*i+d*(n-1-i)){
            cout << "YES";
            return 0;
        }
    }
    cout << "NO";
}


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

int compare_l(const void *p,const void *q){
	return*(int*)p-*(int*)q;
}

int main(){
	int h,x=0,z=0,n,i,max=0;
	
	scanf("%d %d",&n,&h);
	int a[n],b[n];
	
	for(i=0;i<=n-1;i++){
		scanf("%d %d",&a[i],&b[i]);
		if(max<a[i]) max=a[i];
	}
	qsort((void*)b,n,sizeof(b[0]),compare_l);
	for(i=n-1;b[i]>=max;i--){
		x+=b[i];
		z++;
		if(x>=h){
			printf("%d",z);
			return 0;
		}
	}
	
	while(1){
		if(x>=h){
			printf("%d",z);
			return 0;
		}
		h-=max;
		z++;
	}
}

Measured memory_bytes: 1276
#include <iostream>
#include <array>
#include <vector>
#include <algorithm>
#include <unordered_map>
#include <map>

using namespace std;
constexpr int kMaxN = 1e5 + 1000;
constexpr long long kMod = 1e9 + 7;
std::array<std::array<long long, 2>, kMaxN> d;
std::array<std::array<long long, 2>, kMaxN> pr;

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

    int n;
    cin >> n;
    long long a, b;
    cin >> a >> b;

    std::vector<long long> s(n);
    for (auto& el : s) {
        cin >> el;
    }

    for (int i = 0; i < n; i++) {
        for (int j = 0; j < 2; j++) {
            long long x = j == 0 ? a : b;
            pr[i][j] = 1;
            if (i > 0) {
                pr[i][j] += ((s[i] - s[i - 1] >= x) ? pr[i - 1][j] : 0LL);
            }
        }
    }

    d[0][0] = d[0][1] = 1;
    for (int i = 1; i < n; i++) {
        for (int j = 0; j < 2; j++) {
            d[i][j] = 0;
            long long x = j == 0 ? a : b;
            int id = std::lower_bound(s.begin(), s.begin() + i, s[i] - x + 1)
                - s.begin();
            id--;
            if (id == i - 1) {
                d[i][j] = d[i - 1][0] + d[i - 1][1];
                d[i][j] %= kMod;
                continue;
            }
            if (i - 1 - pr[i - 1][1 - j] <= id) {
                d[i][j] = d[id + 1][1 - j];
            }
        }
    }
    cout << (d[n - 1][0] + d[n - 1][1]) % kMod << endl;
}


Measured memory_bytes: 4224
#include <iostream>
using namespace std;
int main(){
  int n,m;
  int x[300000];
  int y[300000];
  cin >> n >> m >> x[0] >> y[0];
  for (int i=1;i<=n;i++){
    cin >> x[i];
  }
  for(int i=1;i<=m;i++){
    cin >> y[i];
  }
  sort(x,x+n+1);
  sort(y,y+m+1);
  if (x[n]<y[0]){
    cout<<"No War"<<endl;
  }else{
    cout<<"War"<<endl;
  }
}

Measured memory_bytes: 2304
//minamoto
#include<bits/stdc++.h>
#define R register
#define fp(i,a,b) for(R int i=(a),I=(b)+1;i<I;++i)
#define fd(i,a,b) for(R int i=(a),I=(b)-1;i>I;--i)
#define go(u) for(int i=head[u],v=e[i].v;i;i=e[i].nx,v=e[i].v)
template<class T>inline bool cmax(T&a,const T&b){return a<b?a=b,1:0;}
template<class T>inline bool cmin(T&a,const T&b){return a>b?a=b,1:0;}
using namespace std;
typedef long long ll;
const int N=1e5+5;
int a[N],id[N],sz[N],bl[N],to[N],nid[N],n,m;ll sum[N],k;
vector<int>st[N];
inline void swap(R int &x,R int &y){R int t=x;x=y,y=t;}
int main(){
//	freopen("testdata.in","r",stdin);
	scanf("%d",&n);
	fp(i,1,n)scanf("%d",&a[i]);
	fd(i,n,1)a[i]-=a[i-1],id[i]=i;
	scanf("%d%lld",&m,&k);
	for(R int i=1,x;i<=m;++i)scanf("%d",&x),swap(id[x],id[x+1]);
	fp(i,1,n)to[id[i]]=i;
	fp(i,1,n)if(!bl[i]){
		bl[i]=i,++sz[i];
		for(R int j=to[i];j!=i;j=to[j])bl[j]=i,++sz[i];
		st[i].resize(sz[i]),st[i][0]=i,nid[i]=0;
		for(R int j=to[i],c=1;j!=i;j=to[j],++c)st[i][c]=j,nid[j]=c;
	}
	fp(i,1,n)sum[st[bl[i]][(k+nid[i])%sz[bl[i]]]]=a[i];
	fp(i,1,n)sum[i]+=sum[i-1];
	fp(i,1,n)printf("%lld\n",sum[i]);
	return 0;
}

Measured memory_bytes: 9856