akhauriyash/Code-Regression huggingface dataset:
fn main() {
    let mut input = String::new();
    let mut stack: Vec<char> = Vec::new();
    std::io::stdin().read_line(&mut input).ok();
    let s = input.trim();
    for c in s.chars() {
        if c != '1' && c != '0' {
            continue;
        }
        // let _stack = &mut stack;
        match stack.last() {
            None => stack.push(c),
            Some(&l) => {
                if l == c {
                    stack.push(c);
                } else {
                    stack.pop();
                }
            }
        }
    }

    println!("{}", s.len() - stack.len());
}


Measured memory_bytes: 4352
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i,n) for(int (i)=0;(i)<(int)(n);++(i))
#define all(x) (x).begin(),(x).end()
#define pb push_back
#define fi first
#define se second
#define dbg(x) cout<<#x" = "<<((x))<<endl
template<class T,class U> ostream& operator<<(ostream& o, const pair<T,U> &p){o<<"("<<p.fi<<","<<p.se<<")";return o;}
template<class T> ostream& operator<<(ostream& o, const vector<T> &v){o<<"[";for(T t:v){o<<t<<",";}o<<"]";return o;}

int main()
{
    ll x,y;
    cin >>x >>y;
    cout << x+y-__gcd(x,y)+1 << endl;
    return 0;
}

Measured memory_bytes: 3092
#include <bits/stdc++.h>
#define ADD(a, b) a = (a + ll(b)) % mod
#define MUL(a, b) a = (a * ll(b)) % mod
#define MAX(a, b) a = max(a, b)
#define MIN(a, b) a = min(a, b)
#define rep(i, a, b) for(int i = int(a); i < int(b); i++)
#define rer(i, a, b) for(int i = int(a) - 1; i >= int(b); i--)
#define all(a) (a).begin(), (a).end()
#define sz(v) (int)(v).size()
#define pb push_back
#define sec second
#define fst first
#define debug(fmt, ...) Debug(__LINE__, ":", fmt, ##__VA_ARGS__)
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> pi;
typedef pair<ll, ll> pl;
typedef pair<int, pi> ppi;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<vl> mat;
typedef complex<double> comp;
void Debug() {cerr << '\n'; }
template<class FIRST, class... REST>void Debug(FIRST arg, REST... rest){
	cerr<<arg<<" ";Debug(rest...);}
template<class T>ostream& operator<<(ostream& out,const vector<T>& v) {
	out<<"[";if(!v.empty()){rep(i,0,sz(v)-1)out<<v[i]<<", ";out<<v.back();}out<<"]";return out;}
template<class S, class T>ostream& operator<<(ostream& out,const pair<S, T>& v){
	out<<"("<<v.first<<", "<<v.second<<")";return out;}
const int MAX_N = 500010;
const int MAX_V = 100010;
const double eps = 1e-6;
const ll mod = 1000000007;
const int inf = (1 << 30) - 1;
const ll linf = 1LL << 60;
const double PI = 3.14159265358979323846;
mt19937 rng; //use it by rng() % mod, shuffle(all(vec), rng)
///////////////////////////////////////////////////////////////////////////////////////////////////

int N;
string S;
int T[MAX_N];

void solve() {
	cin >> S;
	S += 'd';
	N = sz(S);
	rep(i, 0, N) {
		if(S[i] == 'd') T[i] = 1;
	}
	rep(i, 0, N - 2) {
		if(S[i] == 'e' && S[i + 1] == 'r' && S[i + 2] == 'a') T[i] = 1;
	}
	// debug(vi(T, T + N));
	if(T[0] == 0) {
		cout << "NO\n"; return;
	}
	string tmp;
	tmp += S[0];
	rep(i, 1, N) {
		if(T[i] == 1) {
			if(tmp != "dream" && tmp != "dreamer" && tmp != "eraser" && tmp != "erase") {
				cout << "NO\n"; return;
			}
			else {
				tmp.clear(); tmp += S[i];
			}
		}
		else tmp += S[i];
	}
	cout << "YES\n";
}

uint32_t rd() {
	uint32_t res;
#ifdef __MINGW32__
	asm volatile("rdrand %0" :"=a"(res) ::"cc");
#else
	res = std::random_device()();
#endif
	return res;
}

int main() {
#ifndef LOCAL
	ios::sync_with_stdio(false);
    cin.tie(0);
#endif
    cout << fixed;
	cout.precision(20);
    cerr << fixed;
	cerr.precision(6);
	rng.seed(rd());
#ifdef LOCAL
	//freopen("in.txt", "wt", stdout); //for tester
	if(!freopen("in.txt", "rt", stdin)) return 1;
#endif	
	solve();
    cerr << "Time: " << 1.0 * clock() / CLOCKS_PER_SEC << " s.\n";
	return 0;
}



Measured memory_bytes: 848
#!/usr/bin/env python
# -*- coding: utf-8 -*-

import sys


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


def resolve():
    n = int(input())
    s = input()

    count_dic = {}

    for i in range(n):
        count_dic[str(i)+"R"] = s.count("R", i, n)
        count_dic[str(i)+"G"] = s.count("G", i, n)
        count_dic[str(i)+"B"] = s.count("B", i, n)

    all_count = n* (n-1) * (n-2)
    count = 0
    for i in range(n):
        for j in range(i+1, n):
            if s[i] == s[j]:
                continue

            if s[i] == "R" and s[j] == "G":
                target_str = "B"
            elif s[i] == "R" and s[j] == "B":
                target_str = "G"
            elif s[i] == "G" and s[j] == "R":
                target_str = "B"
            elif s[i] == "G" and s[j] == "B":
                target_str = "R"
            elif s[i] == "B" and s[j] == "R":
                target_str = "G"
            elif s[i] == "B" and s[j] == "G":
                target_str = "R"

            count += count_dic[str(j)+target_str]

            if 2*j-i < n:
                if target_str == s[2*j-i]:
                    count -= 1
            """
            for k in range(j+1, n):
                if j - i == k -j:
                    continue
                
                if s[i] == s[k] or s[j] == s[k]:
                    continue

                count += 1
            """

    print(count)


if __name__ == "__main__":
    resolve()



Measured memory_bytes: 71112
N = int(input())
H = list(map(int,input().split()))
c = 0
for i in reversed(range(1,N)):
    if H[i]-H[i-1] <=-2:
        c = 1
        break
    elif H[i]-H[i-1] == -1:
        H[i-1] -= 1
    else:
        continue
if c == 0:
    print('Yes')
else:
    print('No')

Measured memory_bytes: 14224
// template {{{
#include <bits/stdc++.h>

using namespace std;

#define all(c) (c).begin(), (c).end()
#define sz(c) (static_cast<int>(c.size()))
#define endl "\n"

using ld = long double;
using ll = long long;

inline ll addm(ll __a, ll __b, ll __m);
inline ll subm(ll __a, ll __b, ll __m);
inline ll mulm(ll __a, ll __b, ll __m);
ll powm(ll __a, ll __b, ll __m);
ll inv(ll __x, ll __m);
// }}}

const ll INFL = numeric_limits<ll>::max() / 2;
const ll INF = numeric_limits<int>::max() / 2;
const ll MOD = 1e9+7;

const int N = 100500;
int h[N], r[N];
void solve()
{
    int n, k; cin >> n >> k;
    fill(r+1, r+n, INF);
    for (int i = 0; i < n; i++) {
        cin >> h[i];
        for (int j = 1; i-j >= 0 && j <= k; j++)
            r[i] = min(r[i], r[i-j] + abs(h[i]-h[i-j]));
    }
    cout << r[n-1] << endl;
}

// main {{{
int main()
{
    cin.sync_with_stdio(0); cin.tie(NULL);
    solve();
    return 0;
}

inline ll addm(ll __a, ll __b, ll __m = MOD) {
    return ((__a+__b)%__m);
}
inline ll subm(ll __a, ll __b, ll __m = MOD) {
    return (((__a-__b)%__m+__m)%__m);
}
inline ll mulm(ll __a, ll __b, ll __m = MOD) {
    return ((__a*__b)%__m);
}
ll powm(ll __a, ll __b, ll __m = MOD) {
    ll ret = (!__b) ? 1 : powm(__a, __b/2, __m);
    return (!__b) ? 1 : mulm(mulm(ret, ret, __m), (__b%2) ? __a : 1, __m);
}
ll inv(ll __x, ll __m = MOD) {
    return powm(__x, __m-2, __m);
}
// }}}


Measured memory_bytes: 1024
#include<iostream>
#include<vector>
#include<algorithm>
#include<map>
#include<cstring>
#include<math.h>
#include<bitset>
#include<queue>
#include<set>
#include<iomanip>
#include<math.h>
#include<assert.h>
#include<string>
#include<cstdlib>
//#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
constexpr long long INF = 1LL << 40;
const double INFD = 1e100;
const ll mod = 1000000007;
const double PI = 3.1415926535897932384626433832795028841971;
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};
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;
}
// ----------------------------------------------------------------------------

int main(){
  int n;
  cin >> n;
  vector<int> a(n+1);
  for(int i=1; i<=n; i++){
    cin >> a[i];
  }
  ll res1=0,res2=0;
  ll sum1=0,sum2=0;
  for(int i=1; i<=n; i++){
    sum1 += a[i];
    sum2 += a[i];
    if(i%2){
      if(sum1 <= 0){
        res1 += abs(sum1)+1;
        sum1 = 1;
      }
      if(sum2 >= 0){
        res2 += abs(sum2)+1;
        sum2 = -1;
      }
    }else{
      if(sum1 >= 0){
        res1 += abs(sum1)+1;
        sum1 = -1;
      }
      if(sum2 <= 0){
        res2 += abs(sum2)+1;
        sum2 = 1;
      }
    }
  }
  cout << min(res1,res2) << endl;
  return 0;
}


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

int main() {
    int n;
    cin >> n;
    vector<int> p(n);
    rep(i,n){
        cin >> p.at(i);
    }
    sort(p.begin(),p.end());
    p.at(n-1) /= 2;
    int64_t ans = 0;
    rep(i,n){
        ans += p.at(i);
    }
    cout << ans << endl;
}

Measured memory_bytes: 3592
def main():
    H, W = map(int,input().split())
    h, w = map(int,input().split())

    point = W * H

    delete_h = h * W
    delete_w = w * H

    kaburi = h * w

    ans = point - (delete_h + delete_w - kaburi)
    print(ans)


if __name__ == '__main__':
    main()

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

long long max(long long a, long long b)
{
    return a > b ? a : b;
}

int main()
{
    long long a,b,k;
    cin >> a >> b >> k;

    if(k <= a)
    {
        cout << a - k << " " << b;
    }
    else if(k <= a + b)
    {
        cout << 0 << " " << b - (k - a);
    }
    else
    {
        cout << 0 << " " << 0;
    }
    cout << endl;
    

}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <algorithm>
#include <cmath>
#include <deque>
#include <queue>
#include <stack>
#include <vector>
#include <utility>
#include <iomanip>
#include <bitset>
#include <set>
#include <map>
#include <stdio.h>
#include <numeric>
#include <cstring>

#define rep(i,n) for (int i = 0; i < (n); i++)
#define rep1(i,n) for (int i = 1; i < (n); i++)
#define FOR(i,a,b) for (int i=(a); i < (b); i++)
#define MOD 1000000007 //10^9+7
using namespace std;
using ll = long long;
using PII = pair<int, int>;
const int INF = numeric_limits<int>::max();

// 負の数にも対応した % 演算
long long mod(long long val, long long m) {
    long long res = val % m;
    if (res < 0) res += m;
    return res;
}

//greatest common divisor
long long gcd(ll a, ll b) 
{
    if (a % b == 0) {
        return b;
    } else {
        return gcd(b, a % b);
    }
}

//least common multiple
long long lcm(ll a, ll b)
{
    return a / gcd(a, b) * b ;
}

ll factorial(ll n) {
    ll res = 1;
    for (ll i = 1; i <= n; i++) {
        res *= i;
    }
    return res;
}

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


Measured memory_bytes: 2560
#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 stl_rep(itr, x) for (auto itr = x.begin(); itr != x.end(); ++itr)
#define all(x) x.begin(), x.end()
#define allr(x) x.rbegin(), x.rend()

constexpr static int MOD = 1000000000 + 7;
constexpr static int inf = INT_MAX / 2;
constexpr static llong INF = LLONG_MAX / 2;
constexpr static int dx[] = {1, 0, -1, 0}, dy[] = {0, 1, 0, -1};

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

    int q;
    cin >> q;
    rep(i, q) {
        llong a, b;
        cin >> a >> b;
        if (a == b) {
            cout << 2 * (a - 1) << endl;
            continue;
        }
        llong lim = a * b - 1, left = -1, right = 1LL<<31;
        while (right - left > 1) {
            llong mid = (left + right) / 2;
            llong mul = (mid + 1) / 2 * (mid + 1 - (mid + 1) / 2);
            if (mul > lim) right = mid;
            else left = mid;
        }
        cout << left - 1 << endl;
    }

    return 0;
}

Measured memory_bytes: 256
// 標準入力から一行を読み取り、指定の型に変換する
fn read<T: std::str::FromStr>() -> T {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).ok();
    s.trim().parse().ok().unwrap()
}

// 標準入力から一行を読み取り、空白文字で分割し、各要素を指定の型に変換する関数
fn read_vec<T: std::str::FromStr>() -> Vec<T> {
    read::<String>().split_whitespace()
        .map(|e| e.parse().ok().unwrap()).collect()
}

use std::cmp::*;

fn main() {
    let nab: Vec<u64> = read_vec();
    let n = nab[0];
    let a = nab[1];
    let b = nab[2];

    // b - a が偶数
    if (b - a) % 2 == 0 {
        println!("{}", (b - a) / 2);
        return;
    }

    // b - a が奇数
    // Aの方が端に近い場合
    let mut even_cost: u64;
    if min(a - 1, n - b) == a - 1 {
        even_cost = a;
    } else { even_cost = n - b + 1; }
        
    println!("{}", even_cost + (b - a - 1) / 2);
}


Measured memory_bytes: 4352
#include<cstdio>
char s[100001];
int main() {
	int i;
	scanf("%s", s);
	if (s[0] == '\0' || s[1] == '\0') {
		printf("-1 -1");
		return 0;
	}
	else if (s[0] == s[1]) {
		printf("1 2");
		return 0;
	}
	else {
		for (i = 2; s[i] != '\0'; i++) {
			if (s[i] == s[i - 1]) {
				printf("%d %d", i, i + 1);
				return 0;
			}
			else if (s[i] == s[i - 2]) {
				printf("%d %d", i - 1, i + 1);
				return 0;
			}
		}
	}
	printf("-1 -1");
	return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<cstring>
using namespace std;
typedef long long ll;

ll seg[1<<20];
int V;

void init(int n){
  V = 1;
  while(n>V)V<<=1;
  memset(seg,0,sizeof(seg));
}

ll set(int p, ll v){
  int cur = V-1 + p;
  seg[cur] = v;
  while(cur){
    cur = (cur-1)/2;
    if(seg[cur] >= v)break;
    seg[cur] = v;
  }
  return v;
}

ll get(int a, int b, int k, int l, int r){
  if(r<=a || b<=l)return 0;
  if(a<=l && r<=b)return seg[k];
  ll vl = get(a,b,2*k+1,l,(l+r)/2);
  ll vr = get(a,b,2*k+2,(l+r)/2,r);
  return max(vl,vr);
}

ll n,a[100100];

int main(){
  cin >> n;
  for(int i=0;i<n;i++)cin >> a[i];

  init(n);
  ll res = 0;
  for(int i=0;i<n;i++){
    res = max(res,set(a[i]-1,get(0,a[i]-1,0,0,V) + a[i]));
  }

  cout << n*(n+1)/2 - res << endl;
}

Measured memory_bytes: 10136
#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <vector>
#include <string>
#include <queue>
#include <functional>
#include <set>
#include <map>
#define rep(i,n) for(int (i) = 0;(i) < (n);(i)++)

using namespace std;
typedef long long ll;

bool digit(ll x,int d){
    return ((x>>d)&(1ull))!=0;
}

ll xor_sum(ll x){
    bool fst = digit(x,0);
    ll ret = (ll)(fst^digit(x,1));
    for(ll n = 1;(x>>n)!=0;n++){
        if(digit(x,n)&(!fst)){
            ret += (1ull<<n);
        }
    }
    return ret;
}

int main(){
    ll A,B;
    cin>>A>>B;
    if(A!=0){
        cout<<(xor_sum(A-1)^xor_sum(B))<<endl;
    }else{
        cout<<xor_sum(B)<<endl;
    }
}


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

int main(){
  string s;cin >> s;
  int k;cin >> k;
  set<string> x;
  int l=(int)s.size();
  for(int i=1;i<=min({l,k});i++){
    for(int j=0;j<l-i+1;j++){
      x.insert(s.substr(j,i));
    }
  }
  int a=0;
  for(auto itr=x.begin();itr!=x.end();itr++){
    a++;
    if(a==k){cout << *itr << endl;break;}
  }
}


Measured memory_bytes: 1664
/*
 * main.c
 *
 *  Created on: 2019/07/21
 *      Author: family
 */

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>

typedef unsigned long long int uint64_t;
typedef long long int int64my_t;

typedef struct {
	int a;
	int b;
} CONNECT_t;

typedef struct {
	int p;
	int x;
} VERT_VAL_t;

//qsort(a, 3, sizeof(int), sort_inc);
int sort_inc(const void *a, const void *b)
{
	CONNECT_t *pa = (CONNECT_t *)a;
	CONNECT_t *pb = (CONNECT_t *)b;
	int da = pa->a;
	int db = pb->a;
	//printf("da=%d db=%d\n", da, db);
	if (da == db) {
		da = pa->b;
		db = pb->b;
		//printf(">da=%d db=%d\n", da, db);
	}
    return (da - db);
}

CONNECT_t cnct[200002];
VERT_VAL_t val[200002];
uint64_t ans[200002] = {0};

int main()
{
	int N = 0, Q = 0, i = 0;
	scanf("%d %d", &N, &Q);
	for(i = 1; i < N; i++) {
		int a, b;
		scanf("%d %d", &a, &b);
		cnct[i].a = a;
		cnct[i].b = b;
	}
	for(i = 1; i <= Q; i++) {
		int p, x;
		scanf("%d %d", &p, &x);
		val[i].p = p;
		val[i].x = x;
	}
	for (i = 1; i <= Q; i++) {
		ans[val[i].p] += (uint64_t)val[i].x;
	}
	qsort(&cnct[1], N-1, sizeof(CONNECT_t), sort_inc);
	for (i = 1; i < N; i++) {
		//printf("a=%d b=%d\n", cnct[i].a, cnct[i].b);
		ans[cnct[i].b] += ans[cnct[i].a];
	}
	for (i = 1; i <= N; i++) {
		printf("%lld ", ans[i]);
	}
	printf("\n");
    return 0;
}


Measured memory_bytes: 7008
#include "bits/stdc++.h"
 
typedef long long ll;
#define int ll
#define fi first
#define se second
#define SORT(a) sort(a.begin(),a.end())
#define rep(i,n) for(int i = 0;i < (n) ; i++) 
#define REP(i,n) for(int i = 0;i < (n) ; i++) 
#define MP(a,b) make_pair(a,b)
#define pb(a) push_back(a)
#define INF LLONG_MAX/2
#define all(x) (x).begin(),(x).end()
#define debug(x) cerr<<#x<<": "<<x<<endl
#define debug_vec(v) cerr<<#v<<":";rep(i,v.size())cerr<<" "<<v[i];cerr<<endl
using namespace std;
int MOD = 1000000007;

signed main(){
    int n,k,q;
    cin >> n >> k >> q;
    vector<int> a(n);
    rep(i,n)cin >> a[i];
    vector<int> b = a;
    SORT(b);
    int res = INF;
    rep(i,n){
        vector<int> c = a;
        int mini = b[i];
        vector<int> d[2001];
        int cnt = 0;
        rep(i,n){
            if(c[i] >= mini){
                d[cnt].pb(c[i]);
            }else{
                cnt++;
            }
        }
        vector<int> ans;
        rep(i,2001){
            int num =  (int)(d[i].size()) + 1 - k;
            if(num <= 0)continue;
            else{
                SORT(d[i]);
                rep(j,num){
                    ans.pb(d[i][j]);
                }
            }
        }
        if(ans.size() < q)continue;
        else{
            SORT(ans);
            res = min(res,ans[q-1]-ans[0]);
        }
    }
    cout << res << endl;


    return 0; 
}

// g++ -std=c++14 code1.cpp
// rm -r -f test;oj dl https://yahoo-procon2019-qual.contest.atcoder.jp/tasks/yahoo_procon2019_qual_d
// rm -r -f test;oj dl http://arc098.contest.atcoder.jp/tasks/arc098_c

Measured memory_bytes: 384
#include <bits/stdc++.h> 
using namespace std;
using ll = long long;
template<typename T> using v2 = vector<vector<T>>;
template<typename T> inline v2<T> fill(int r, int c, const T& t){ return v2<T>(r, vector<T>(c, t)); }
#define F first
#define S second

int numpwr(ll x, int div){
    int ans=0;
    while(x%div==0){
        ++ans;
        x/=div;
    }
    return ans;
}

void solve(){
    int n;
    cin>>n;
    vector<string> s(n);
    for(int i = 0; i < n; ++i) cin >> s[i];

    vector<int> p10(10);
    p10[0] = 1;
    for(int i = 1; i < 10; ++i) p10[i] = p10[i-1]*10;

    vector<ll> a = vector<ll>(n);
    for(int i = 0; i < n; ++i){
        int ind = s[i].find('.');
        int need=9;
        if(ind!=-1){
            need = 9-(s[i].length()-ind-1);
            s[i].erase(s[i].begin()+ind, s[i].begin()+ind+1);
        }
        a[i] = stoll(s[i])*p10[need];
    }

    map<pair<int,int>, int> cnt;
    for(int i = 0; i < n; ++i) ++cnt[{numpwr(a[i],2), numpwr(a[i],5)}];

    ll ans=0;
    for(auto p1 : cnt){
        for(auto p2 : cnt){
            if(p1.F.F+p2.F.F>=18 && p1.F.S+p2.F.S>=18){
                if(p1<p2){
                    ans+=(ll)p1.S*p2.S;
                }
                else if(p1==p2){
                    ans+=(ll)p1.S*(p1.S-1)/2;
                }
            }
        }
    }
    cout << ans << '\n';
}

int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    solve();
    return 0;
}

Measured memory_bytes: 11096
#include<bits/stdc++.h>
#define MAX 8
#define N 8
#define NOT_FREE -1
#define FREE 1
using namespace std;
int col[MAX],dpos[2*MAX-1],dneg[2*MAX-1],row[MAX];
int X[MAX][MAX];

void printBoard(){
    int i,j;
    for(i=0;i<N;i++) {
		for (j=0;j<N;j++) {
			if(X[i][j]!=FREE){
				if(row[i]!=j)return;
			}
		}
	}
    for(i =0;i<N;i++){
        for(j=0;j<N;j++){
            if(row[i]==j)cout<<'Q';
            else cout<<".";
        }
        cout<<endl;
    }
}

void putQueen(int i){
    int j;
    if(i==N){
        printBoard();
        return;
    }
    for(j=0;j<N;j++){
        if(col[j]==NOT_FREE||dpos[i+j]==NOT_FREE||dneg[i-j+N-1]==NOT_FREE)continue;
        row[i]=j;
        col[j]=dpos[i+j]=dneg[i-j+N-1]=NOT_FREE;
        putQueen(i+1);
        row[i]=col[j]=dpos[i+j]=dneg[i-j+N-1]=FREE;
    }
}

int main(){
    int a,b,n,i,j;
    for(i=0;i<N*2-1;i++){
        dpos[i]=FREE;
        dneg[i]=FREE;
    }
    for(i=0;i<MAX;i++){
        col[i]=FREE;
        row[i]=FREE;
    }
    for(i=0;i<MAX;i++){
        for(j=0;j<MAX;j++){
            X[i][j]=FREE;
        }
    }
    cin>>n;
    for(i=0;i<n;i++){
        cin>>a>>b;
        X[a][b]=NOT_FREE;
        // row[b]=a;
        // col[a]=b;
    }
    putQueen(0);
}




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

int main(){
  ll x;
  cin >> x;
  ll ans = 6;
  for(ll i = 1; i < x; i++) {
    ans = ans * 2 + 2;
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 3580
#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)

int main(){
    int n,k,s;
    cin>>n>>k>>s;
    rep(i,k)cout<<s<<" ";
    rep(i,n-k){
        cout<<1000000000-(s==1000000000)<<" ";
    }
    cout<<endl;
    return 0;
}


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

int main() {
	int a,b,x;
 	cin >> a >> b ;
  
  if ((a+b) % 2 == 0){
  	x = (a + b)/2;
    cout << x << endl;
  }
  if((a+b)%2 == 1){
    x = (a+b)/2+1;
    cout << x << endl;
  }
  
  
}


Measured memory_bytes: 256
parseInt(x) = parse(Int, x)
parseMap(x::Array{SubString{String},1}) = map(parseInt, x)

const INF=2<<32
function main()
    n::Int=parseInt(readline())
    h::Vector{Int}=vcat(parseMap(split(readline())),[INF])
    dp::Vector{Int}=fill(INF,100010)
    dp[1]=0
    for i in 1:n-1
        dp[i+1]=min(dp[i+1],dp[i]+abs(h[i]-h[i+1]))
        dp[i+2]=min(dp[i+2],dp[i]+abs(h[i]-h[i+2]))
    end
    println(dp[n])
end
main()

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

int main() {
    int N;
    cin >> N;
    string s;
    cin >> s;
    int R=count(s.begin(), s.end() , 'R');
    int B = N - R;
    if(R>B){
        cout << "Yes" << endl;
    }else{
        cout << "No" << endl;
    }
}

Measured memory_bytes: 256
#include<stdio.h>
main(){
  int a,b,c[100],d,i,j,l;
    scanf("%d",&a);
    for(i = 0; i < a ;i++){
scanf("%d",&c[i]); 
 printf("%d",c[i]);
 if(i != a-1) printf(" ");
} 
 printf("\n");
  for(i = 1; i < a; i++){
    d = c[i];
    j = i -1;
    while(j >= 0 && c[j] > d){
      c[j+1] = c[j];
      j--;
    }
      c[j+1] = d;    
    for(l = 0; l < a ; l++){
printf("%d",c[l]);   
 if(l != a - 1) printf(" ");     
}
    printf("\n");
  }
  return 0;
}

Measured memory_bytes: 604
#include<iostream>
#include<algorithm>
#include<queue>
using namespace std;
static const int MAX = 10000;
static const int INFTY = (1<<20);

int n;
vector<pair<int,int> > G[MAX];

void dij(){
  priority_queue<pair<int,int> > PQ;
  int color[MAX], d[MAX], i, j, u, v;
  for(i = 0; i < n; i++){
    d[i] = INFTY;
    color[i] = 0;
  }
  d[0] = 0;
  PQ.push(make_pair(0,0));
  color[0] = 1;

  while(!PQ.empty()){
    pair<int,int> f = PQ.top();
    PQ.pop();
    u = f.second;
    color[u] = 2;

    if(d[u] < f.first * (-1)) continue;
    for(j = 0; j < G[u].size(); j++){
      v = G[u][j].first;
      if(color[v] == 2) continue;
      if(d[v] > d[u] + G[u][j].second){
        d[v] =  d[u] + G[u][j].second;
        PQ.push(make_pair(d[v] * (-1), v));
        color[v] = 1;
      }
    }
  }

  for(i = 0; i < n; i++){
    cout << i << " " << (d[i] == INFTY ? -1 : d[i]) << endl;
  }
}
int main()
{
  int k, u, v, c, i, j;

  cin >> n;
  for(i = 0; i < n; i++){
    cin >> u >> k;
    for(j = 0; j < k; j++){
      cin >> v >> c;
      G[u].push_back(make_pair(v,c));
    }
  }

  dij();
  return 0;
}

Measured memory_bytes: 7988
N = int(input())
S = input()

import re


def nchars(s, n):
    assert n > 0
    reg = re.compile("(.)\\1{%d,}" % (n - 1))
    while True:
        m = reg.search(s)
        if not m:
            break
        yield m.group(0)
        s = s[m.end():]
        
ans = list(nchars(S,1))
ans = len(ans)
print(ans)

Measured memory_bytes: 12736
# B - Bingo
def is_winnable(player: int) -> bool:
    winnable_conditions = \
        {0b111000000, 0b000111000, 0b000000111, 0b100100100, 0b010010010, 0b001001001, 0b100010001, 0b001010100}
    return any(player & condition == condition for condition in winnable_conditions)


def main():
    *ANB, = map(int, open(0).read().split())
    A, B = ANB[:9], set(ANB[10:])
    player = 0b000000000
    for i, a in enumerate(A):
        if a in B:
            player |= 1 << i
    print("Yes" if is_winnable(player) else "No")


if __name__ == "__main__":
    main()


Measured memory_bytes: 3060
#include<iostream>
#include<algorithm>
#include <cstdio>
using namespace std;
int a[3];

int main(){
  scanf("%d %d %d",&a[0],&a[1],&a[2]);
  sort(a,a+3);
  printf("%d %d %d\n",a[0],a[1],a[2]);
  
  return 0;
}

Measured memory_bytes: 1204
#include <bits/stdc++.h>
using namespace std;
///////////////////////////////////////////
const long long int INF = 1LL<<60;
const long long int Mod = 1000000007;
using ll = long long int; using ci = const int;
using vi = vector<int>;  using Vi = vector<long long int>;
using P = pair<int, int>;  using PLL = pair<ll, ll>;
using matrix = vector<vector<ll>>;
#define pb(x) push_back(x)
#define mp(x,y) make_pair(x,y)
#define all(x) (x).begin(),(x).end()
#define rp(i,N) for(ll i = 0; i < (ll)N; i++)
#define repi(i,a,b) for(ll i = ll(a); i < ll(b); ++i)
template<class T>bool chmax(T &former, const T &b) { if (former<b) { former=b; return true; } return false; }
template<class T>bool chmin(T &former, const T &b) { if (b<former) { former=b; return true; } return false; }
template<class T>T sqar(T x){ return x*x; }//sqrt(x)は平方根;
#define Sort(v) std::sort(v.begin(), v.end(), std::greater<decltype(v[0])>()) //降順でVをソート
#define p_queue(v) priority_queue<v, vector<v>, greater<v> >
template<class T> inline void princ(T x){cout<<x<<" ";}; 
template<class T> inline void print(T x){cout<<x<<"\n";};
template<class T> inline void Yes(T condition){ if(condition) cout << "Yes" << endl; else cout << "No" << endl; }
template<class T> inline void YES(T condition){ if(condition) cout << "YES" << endl; else cout << "NO" << endl; }
///////////////////////////////////////////////////////////////////////////////////

int main(){
    int n,k;
    cin >> n >> k;
    int ctr=n;
    bool ok[n];
    rp(i,n) ok[i]=false;
    rp(i,k){
        int d;
        cin >> d;
        rp(j,d){
            int a;
            cin >> a;
            a--;
            if(!ok[a]){
                ok[a]=true;
                ctr--;
            }
        }
    }
    cout << ctr << endl;
    return 0;
}

Measured memory_bytes: 3584
#include<bits/stdc++.h>
#define rep(i, n) for (long long i = 0; i < (int)(n); i++)
#define all(a) a.begin(), a.end()
#define put(i) cout<<fixed<<i<<endl
using namespace std;
using ll = long long;

int main(){
    ll n; cin >> n;
    vector<ll> h(n); rep(i,n) cin >> h[i];

    vector<ll> dp(n,-1);
    dp[0] = 0;
    for(long long i = 1; i < n; i++){
        if(dp[i] == -1) dp[i] = dp[i-1] + abs(h[i]-h[i-1]);
        else dp[i] = min(dp[i], dp[i-1] + abs(h[i]-h[i-1]));
        if(i+1 < n and dp[i+1] == -1) dp[i+1] = dp[i-1] + abs(h[i+1]-h[i-1]);
        else if(i+1 < n) dp[i+1] = min(dp[i+1], dp[i-1] + abs(h[i+1]-h[i-1]));
    }

    //for(auto x:dp) cout << x << " "; cout << endl;
    put(dp[n-1]);
}

Measured memory_bytes: 4852
#include <bits/stdc++.h>
#define be(v) (v).begin(),(v).end()
#define pb(q) push_back(q)
typedef long long ll;
using namespace std;
const ll mod=1000000007;
#define doublecout(a) cout<<fixed<<setprecision(10)<<a<<endl;

int main() {
    cin.tie(0);
    cout.tie(0);
    ios::sync_with_stdio(false);
    ll n,u,v;
    cin>>n>>u>>v;
    u--;v--;
    ll a,b;
    vector<vector<ll> > g(n);
    ll du[n],dv[n];
    memset(du,-1,sizeof(du));
    memset(dv,-1,sizeof(dv));
    for(int i=0;i<n-1;i++){
    	cin>>a>>b;
    	a--;b--;
    	g[a].pb(b);
    	g[b].pb(a);
    }
    queue<ll> q;
    du[u]=0;
    q.push(u);
    while(!q.empty()){
    	int now=q.front();q.pop();
    	for(auto i:g[now]){
    		if(du[i]==-1){
    			du[i]=du[now]+1;
    			q.push(i);
    		}
    	}
    }
    dv[v]=0;
    q.push(v);
    while(!q.empty()){
    	int now=q.front();q.pop();
    	for(auto i:g[now]){
    		if(dv[i]==-1){
    			dv[i]=dv[now]+1;
    			q.push(i);
    		}
    	}
    }
    ll ans=0;
    for(int i=0;i<n;i++){
    	if(du[i]>=dv[i])continue;
    	ans=max(ans,dv[i]);
    }
    cout <<ans-1<<endl;
    return 0;
}


Measured memory_bytes: 8064
import math

A,B,H,M= list(map(int, input().split()))
 
theta = 2*math.pi*H/12+2*math.pi*M/12/60 #時針の角度
phi = 2*math.pi*M/60 #分針の角度
  
C = math.sqrt(A**2+B**2-2*A*B*math.cos(theta-phi))
print(C)

Measured memory_bytes: 9468
N, Q = map(int,input().split())
S = input()
t=[0]*(N+1)
for i in range(N):
  t[i + 1] = t[i] + (1 if S[i : i + 2] == 'AC' else 0)
for i in range(Q):
  l, r = map(int, input().split())
  print(t[r-1] - t[l-1])

Measured memory_bytes: 7748
#include<bits/stdc++.h>
using namespace std;
int n,a[100000];
int main(void)
{
	int sum,sum1=0;
	scanf("%d%d",&sum,&n);
	for(int i=0;i<n;i++)
	{
		scanf("%d",&a[i]);
		sum1+=a[i];
	}
	if(sum1>=sum)
	{
		printf("Yes");
	}
	else
	{
		printf("No");
	}
}

Measured memory_bytes: 640
using System;
using System.Collections.Generic;
using System.Linq;

class Program {
    static string ReadLine() { return Console.ReadLine(); }
    static int ReadInt() { return int.Parse(ReadLine()); }
    static int[] ReadInts() { return ReadLine().Split().Select(int.Parse).ToArray(); }
    static string[] ReadStrings() { return ReadLine().Split(); }

    static void Main() {
        string s;
        while ((s = ReadLine()) != null) {
            int n = s.Split().Select(int.Parse).ToArray().Sum();
            Console.WriteLine(n.ToString().Length);
        }
    }
}

Measured memory_bytes: 9520
#include <iostream>
#include <string>
#include <vector>
#include <map>
#include <cmath>
#include <algorithm>
#include <functional>
#include <stack>
#include <numeric>
typedef long long ll;
using namespace std;
const int MOD = (int)1e9 + 7;
const ll INF = (ll)1e18 + 7;
#define int long long

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

	int N, A, B;
	int min, max;
	cin >> N >> A >> B;

	if (A > B) {
		cout << 0 << endl;
		return 0;
	}
	if (N == 1) {
		if (A == B) {
			cout << 1 << endl;
		}
		else {
			cout << 0 << endl;
		}
		return 0;
	}

	min = A * (N - 1) + B;
	max = B * (N - 1) + A;
	int ans = max - min + 1;
	
	if (ans < 0)ans = 0;

	cout << ans << endl;

	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define REP(i, n) for(int i = 0; i < n; i++)
#define REPR(i, n) for(int i = n; i >= 0; i--)
#define FOR(i, m, n) for(int i = m; i < n; i++)
#define INF 2e9
#define ALL(v) v.begin(), v.end()
using namespace std;
typedef long long ll;

int main()
{
	string s;
	cin >> s;
	cout << (s[0] == s[2] ? "Yes" : "No") << endl;	
	
}


Measured memory_bytes: 256
mod = 10 ** 9 + 7

N = int(input())
T = [int(i) for i in input().split()]
A = [int(i) for i in input().split()]

HT = [False] * N
for i in range(1, N):
    if T[i - 1] < T[i]:
        HT[i] = True
HT[0] = True

HA = [False] * N
for i in range(N - 1):
    if A[i] > A[i + 1]:
        HA[i] = True
HA[-1] = True

ans = 1
for i in range(N):
    if HT[i] and HA[i]:
        ans *= 1 if T[i] == A[i] else 0
    elif HT[i]:
        ans *= 1 if T[i] <= A[i] else 0
    elif HA[i]:
        ans *= 1 if T[i] >= A[i] else 0
    else:
        ans = (ans * min(T[i], A[i])) % mod
print(ans)


Measured memory_bytes: 18924
@T = map {scalar reverse $_} ("dream","dreamer","erase","eraser");
$s = <>;
chomp($s);
$s = reverse($s);
$l = length($s);
for ($c=0;$c<$l;){
    $k = -1;
    for ($i=0;$i<4;$i++){
        if (substr($s,$c,length($T[$i])) eq $T[$i]){
            $k = length($T[$i]);
            last;
        }
    }
    if ($k<0){
        print "NO";
        exit;
    }
    $c += $k;
}
print "YES"

Measured memory_bytes: 4868
#include<cstdio>
#include<cstring>
int main(){
  int num[500];
  int i,n,max=0;
  memset(num,0,sizeof(num));
  while((scanf("%d",&n))!=EOF){
    num[n]++;
    if(num[n]>max)max=num[n];
  }
  for(i=0;i<101;i++)if(max == num[i])printf("%d\n",i); 
}

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

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

ab.sort(key = lambda x:x[1])

flag = True

now = 0


for job in ab:
  now += job[0]

  if now > job[1]:
    flag = False

if flag:
  print("Yes")
else:
  print("No")

Measured memory_bytes: 53600
MAIN : {
	my $s1 = <STDIN>;
	chomp $s1;
	my ($k, $a, $b) = split(" ", $s1);

	my $q = $b - $a;
	
	if ($q <= 1) {
		print STDOUT $k + 1, "\n";
		exit 0;
	}
	
	# 最初に1円にした残りの数
	my $w = $k - $a + 1;
	
	my $max = 0;

	# 残りの数を%2する
	if ($w % 2 eq 1) {
		$max = ($w - 1) / 2 * $q + 1 + $a;
	}
	else {
		$max = $w / 2 * $q + $a;
	}
	
	print STDOUT $max, "\n";
}




__END__


Measured memory_bytes: 384
m = [int(input()) for _ in range(5)]

t = []
for i in range(5):
    d = m[i] % 10
    o = m[i] // 10 * 10
    if d != 0:
        o += 10
    else:
        d = 10
    t.append([d, o, m[i]])

t.sort()
ans = t[0][2]
for i in range(1, 5):
    ans += t[i][1]

print(ans)

Measured memory_bytes: 3064
#include <bits/stdc++.h>
#include <math.h>
#define _GLIBCXX_DEBUG
#define _LIBCPP_DEBUG 0

using namespace std;
#define ll long long
#define rep(i,n) for (int i = 0; i < n; i++)
#define MOD (1000000007)
#define vi vector<int>
#define vvi vector<vi>
#define pii pair<int, int>
#define pb push_back
#define mp make_pair
#define all(a) (a).begin(),(a).end()

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

int gcd(int a, int b) {
    if (b == 0) return a;
    else return gcd(b, a % b);
}

const ll INF = 1LL << 60;

int main(){
  int sx,sy,tx,ty; cin >>sx>>sy>>tx>>ty;
  int X = tx-sx;
  int Y = ty-sy;

  cout << string(Y,'U') << string(X,'R');
  cout << string(Y,'D') << string(X,'L');
  cout << 'L' << string(Y+1,'U') << string(X+1,'R') << 'D';
  cout << 'R' << string(Y+1,'D') << string(X+1,'L') << 'U' << '\n';
}


Measured memory_bytes: 256
#!/usr/bin/python

import sys
 
n = int(sys.stdin.readline().strip())
adj = [set() for _ in range(n)]
colors = dict()
edges = []
for i in range(n-1):
    a, b = map(lambda x: int(x)-1, input().split())
    adj[a].add(b)
    adj[b].add(a)
    edges.append([a, b])
 
col = max(len(v) for v in adj)
 
s = -1
for i, a in enumerate(adj):
    if len(a) == col:
        s = i
        break
 
Q = [[s, -1, -1]]
while Q:
    cur, prev, prev_color = Q.pop()
    c = 0
    for nex in adj[cur]:
        if nex == prev:
            continue
        else:
            c += 1
        if c == prev_color:
            c += 1
        colors[min(cur, nex)*n + max(cur, nex)] = c
        Q.append([nex, cur, c])
print(col)
for a, b in edges:
    print(colors[a*n + b])

Measured memory_bytes: 105504
#include <iostream>
#include <string>
#include <vector>
#include <cmath>
#include <algorithm>
#include <iomanip>
using namespace std;
 
int main(){
    int N; cin>>N;
    vector<long> power(3*N);
    for(int i=0;i<3*N;i++)cin>>power.at(i);
    sort(power.begin(),power.end());
    reverse(power.begin(),power.end());
    long sum=0;
    for(int i=0;i<N;i++){
        sum += power.at(2*i+1);
    }
    cout<<sum<<endl;
}

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

int main() {

	int n,m;
	scanf("%d %d", &n, &m);

	// 0 nao foi
	// -1 ja tomou wa
	// 1 acertou
	map <int,int> mapa;

	int wa = 0;
	int ac = 0;

	for(int i = 0; i < m; i++) {
		int id;
		string res;
		cin >> id >> res;

		if(res == "WA") {
			if(mapa[id] != 1) mapa[id] -= 1;  
		} else {
			if(mapa[id] != 1) {
				wa += abs(mapa[id]);
				ac++;
				mapa[id] = 1;
			}
		}
	}

	printf("%d %d\n",ac, wa);

	return 0;
}

Measured memory_bytes: 4992
import numpy as np
N,K = list(map(int,input().split()))
A1 = list(map(int,input().split()))
A = list(map(lambda x:format(x,'050b'),A1))
K1 = format(K,"050b")
count = [0]*50
count = np.array(count)
ans = ["0"]*50
for a in A:
    count += np.array(list(map(int,list(str(a)))))
small_flag = 0
H = N/2
for a in range(50):
    if small_flag !=0:
        if count[a]>H:
            ans[a]="0"
        else:
            ans[a]="1"
    else:
        if count[a]<H and K1[a]=="1":
            ans[a]="1"
        elif count[a]>=H and K1[a]=="1":
            small_flag = "1"
ans = int("".join(ans),2)
ans1 = 0
for i in A1:
    ans1 += i^ans
print(ans1)

Measured memory_bytes: 29596
import bisect
n,m = list(map(int, input().split()))
a = list(map(int, input().split()))
a.sort()

data = [None] * m
for i in range(m):
    data[i] = list(map(int, input().split()))
data.sort(key = lambda x : x[1])
data.reverse()


ans = 0
count = 0
pre_index = 0
#print(data)
#print(a)
#data[][1] = value, data[][0] = card_num
for i in range(m):
    insert_index = bisect.bisect_left(a, data[i][1])
    count = min(data[i][0], insert_index - pre_index)
    for j in range(pre_index, pre_index + count):
        if j >= n:
            break
        a[j] = 0
    ans += count * data[i][1]
    pre_index = pre_index + count
print(ans + sum(a))


Measured memory_bytes: 77720
import sys

first = sys.stdin.readline().strip().split()
N = int(first[0])  # 数列の要素数
M = int(first[1])  # 数列の最大値
Q = int(first[2])

inp = list()

for _ in range(Q):
    inp.append(sys.stdin.readline().strip())


max_score = 0
As = list()


def loop(row, start, idx):

    global max_score

    if idx == N:
        # As.append(row)
        score = 0
        for item in inp:
            a, b, c, d = map(int, item.split())
            if row[b - 1] - row[a - 1] == c:
                score += d
        max_score = max(score, max_score)

    else:
        for i in range(start, M+1):
            loop(row + [i], i, idx+1)


loop([], 1, 0)

print(max_score)


Measured memory_bytes: 74052
#include <iostream>
#include <set>

using namespace std;

using ll = long long;

int main () {
	ll n, h;
	cin >> n >> h;

	multiset<int, greater<ll>> ss;
	int hh = 0;
	for (int i = 0; i < n; ++i) {
		int a, b;
		cin >> a >> b;
		ss.insert(b);
		hh = max(hh, a);
	}

	int ans = 0;
	while (h > 0) {
		if (!ss.empty() && *begin(ss) > hh) {
			h -= *begin(ss);
			ss.erase(begin(ss));
			++ans;
		} else {
			ans += h % hh == 0 ? h / hh : h / hh + 1;
			h = 0;
		}
	}
	cout << ans << endl;
}


Measured memory_bytes: 4992
#include <iostream>
#include<bits/stdc++.h>
#include<math.h>
using namespace std;
#define F first
#define S second
#define ll long long
const int MOD = 1e9 + 7;
const float epsilon = 0.0005f;
const float PI = 3.1415926535897932384626433f;
 
vector<pair<int,int>> dire{{0,1},{0,-1},{1,0},{-1,0}};
 
// std::cout << std::fixed;
// std::cout << std::setprecision(9);

void solve(){
    ll a, b, c, d;
    cin >> a >> b >> c >> d;
    ll ans = INT_MIN;
    ans = max({a * c, a * d, b * c, b * d});
    cout << ans << "\n";
}
    
int main(){
    ios::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    #ifndef ONLINE_JUDGE
        freopen("input.txt","r",stdin);
        freopen("output.txt","w",stdout);
    #endif
    // int t;cin>>t;
    // for(int i = 0;i<t;++i){
    //     solve();
    // }
    solve();
    return(0);
}

Measured memory_bytes: 3600
#pragma warning(disable : 4996)
#include <bits/stdc++.h>
#define all(x) (x).begin(), (x).end()
using namespace std;
typedef long long ll;
typedef pair<ll, ll> pll;
// https://atcoder.jp/contests/abc169/tasks/abc169_f
ll dp[3010][3010] ={0,};
int main(){
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
 
    ll mod = 998244353;
    ll inv = 499122177;
    ll n,s;
    cin >> n >> s;
    vector<ll> v(n);
    for(int i = 0;i<n;i++){
        cin >> v[i];
    }
    sort(all(v));
    dp[0][0] = 1;
    for(int i = 0;i<n;i++){
        dp[0][0] = (dp[0][0] * 2) % mod;
    }
    for(ll i = 0;i<n;i++){
        for(ll j = 0;j<=s;j++){
            dp[i+1][j] = (dp[i+1][j] + dp[i][j]) % mod;
            if (j + v[i] <= s) {
                dp[i+1][j+v[i]] = (dp[i+1][j+v[i]] + (dp[i][j] * inv)% mod) % mod;
            }
        }
    }
    cout << dp[n][s];


    return 0;
}

Measured memory_bytes: 74196
#include <bits/stdc++.h>
using namespace std;
int main(){
    int N,Y,i,j,k;
    cin >> N;
    Y = 0;
    int d[N];
    for(i=0;i<N;i++){
        cin >> d[i];
    }
    for(j=0;j<N;j++){
        for(k=j+1;k<N;k++){
            Y += d[j]*d[k];
        }
    }
    cout << Y << endl;
    return 0;
}

Measured memory_bytes: 256
#include <iostream>

using namespace std;

int main(int argc, char const *argv[]) {
	unsigned int a, b, c, d, sum = 0;
	cin >> a >> b >> c >> d;

	if(a < b) 
		sum += a;
	else
		sum += b;

	if(c < d)
		sum += c;
	else
		sum += d;

	cout << sum;

	return 0;
}

Measured memory_bytes: 256
import Data.List
import Data.Word
import Data.Bits
import Control.Monad

diffs :: [Word64] -> [Word64]
diffs xs = flip concatMap (tails xs) $
  \ys ->
    case ys of
      [] -> []
      y : ys' -> map (\z -> z - y) ys'


filterMask :: Int -> Word64 -> [Word64] -> Maybe [Word64]
filterMask k mask xs = guard (length ys >= k) >> Just ys where
  ys = filter (\x -> mask .&. x == mask) xs
  
solve :: Int -> [Word64] -> Word64
solve k xs = rec (shiftL 1 63) 0 ds where
  ds = diffs (scanl (+) 0 xs)
  rec 0 acc _ = acc
  rec mask acc xs = 
    case filterMask k mask xs of
      Nothing -> rec (shiftR mask 1) acc xs
      Just xs' -> rec (shiftR mask 1) (acc .|. mask) xs'
      


main = do
  [n, k] <- (map read . words) <$> getLine
  xs <- (map read . words) <$> getLine
  print $ solve k xs
  return ()


Measured memory_bytes: 45308
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define repe(i, n) for (int i = 0; i <= (n); ++i)
#define all(x) (x).begin(),(x).end()
using namespace std;
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
typedef long long ll;
const int INF = 1e9;
const ll mod = 1000000007;
int gcd(int a,int b){return b?gcd(b,a%b):a;}
int lcm(int a,int b){return a*b / gcd(a,b);}

int main() {
    string s;
    cin >> s;
    cout << s.substr(0, s.size()-8) << "\n";
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#include<cmath>
#pragma GCC optimize("Ofast")
using namespace std;
#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(),(x).rend()
typedef long long ll;
const ll MOD = 1e9+7;
#define rep(i,n) for(ll i=0, i##_len=(n); i<i##_len; ++i)
#define REP(i,num,n) for(ll i=num, i##_len=(n); i<i##_len; ++i)
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
template<class T> inline void add(T &a, T b){a = ((a+b) % MOD + MOD) % MOD;};
#define print(x) (cout << (x) << endl)
#define pb push_back
#define mp make_pair
#define sz(x) int(x.size())
#define fs first
#define sc second


const int INF = 1e9;
const ll LLINF = 1e16;

template<typename T>
vector<T> make_v(size_t a){return vector<T>(a);}
 
template<typename T,typename... Ts>
auto make_v(size_t a,Ts... ts){
  return vector<decltype(make_v<T>(ts...))>(a,make_v<T>(ts...));
}
 
template<typename T,typename U,typename... V>
typename enable_if<is_same<T, U>::value!=0>::type
fill_v(U &u,const V... v){u=U(v...);}
 
template<typename T,typename U,typename... V>
typename enable_if<is_same<T, U>::value==0>::type
fill_v(U &u,const V... v){
  for(auto &e:u) fill_v<T>(e,v...);
}
 
template<typename T>
T gcd(T a,T b){return b?gcd(b,a%b):a;}

template<typename T>
T ngcd(vector<T> a){
    T res;
    res = a[0];
    for(int i = 1; i < a.size() && res != 1; i++) {
        res = gcd(a[i], res);
    }
    return res;
}
 
template<typename T>
T lcm(T a, T b) {
    return a / gcd(a, b) * b;
}

template<typename T>
T nlcm(vector<T> numbers) {
    T res;
    res = numbers[0];
    for (int i = 1; i < numbers.size(); i++) {
        res = lcm(res, numbers[i]);
    }
    return res;
}

// 割り算の切り上げ処理
template<typename T>
T round_up(T a, T b) {
  return (a + b - 1) / b;
}

// 約数列挙
template<typename T>
vector<T> calc_divisor(T n) {
   vector<T> res;
   for (T i = 1LL; i*i <= n; ++i) {
       if (n % i == 0) {
           res.push_back(i);
           T j = n / i;
           if (j != i) res.push_back(j);
       }
   }
   sort(res.begin(), res.end());
   return res;
}

// 素数判定
template<typename T>
bool isPrime(T x){
    T i;
    if(x < 2)return 0;
    else if(x == 2) return 1;
    if(x%2 == 0) return 0;
    for(i = 3; i*i <= x; i += 2) if(x%i == 0) return 0;
    return 1;
}

// 桁和
template<typename T>
T digsum(T n) {
    T res = 0;
    while(n > 0) {
        res += n%10;
        n /= 10;
    }
    return res;
}

// 指定した文字cが文字列に何文字入ってるか
ll stringcount(string s, char c) {
    return count(s.cbegin(), s.cend(), c);
}


using pint = pair<int, int>;
using pll = pair<ll, ll>;

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




int main(void)
{
    cout.tie(0);
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(10);
    int a, b;
    cin >> a >> b;
    for(int i=1;i<=1e9;i++){
        if(abs(a - i) == abs(b - i)){
            print(i);
            return 0;
        }
    }
    print("IMPOSSIBLE");

}


Measured memory_bytes: 256
N, P = map(int, input().split())
a = list(map(int, input().split()))
odd = 0
for i in range(N):
    if a[i] % 2 != 0:
        odd += 1

if odd == 0:
    if P == 0:
        print(2 ** N)
    else:
        print(0)
else:
    print(2 ** (N - 1))

Measured memory_bytes: 38256
#include <stdio.h>
#include <string.h>
#include <ctype.h>
#include <math.h>
#include <stdlib.h>
#define INF 1000000000;

int main(void){
	int n,m;
	scanf("%d %d",&n,&m);
	int a[n],b[n],c[m],d[m];
	int i,j;
	for(i=0;i<n;i++){
		scanf("%d %d",&a[i],&b[i]);
	}
	for(i=0;i<m;i++){
		scanf("%d %d",&c[i],&d[i]);
	}
	int l;
	int p;
	for(i=0;i<n;i++){
		int min=INF;
		for(j=0;j<m;j++){
			l=abs(a[i]-c[j])+abs(b[i]-d[j]);
			if(min>l){
				min=l;
				p=j+1;
			}
		}
		printf("%d\n",p);
	}
	return 0;
}

Measured memory_bytes: 128
#include<bits/stdc++.h>
using namespace std;
typedef int64_t ll;
typedef long double ld;
const ll MOD=1000000007;
#define rep(i,n) for(ll i=0;i<(ll)(n);i++)
long long gcd(long long a,long long b){
    ll gcdmax=max(a,b);
    ll gcdmin=min(a,b);
    while(true){
        if(gcdmax%gcdmin==0)break;
        else gcdmax%=gcdmin;
        swap(gcdmin,gcdmax);
    }
    return gcdmin;
}
ll powerup(ll N,ll P,ll M){
    if(P==0)return 1;
    else if(P%2==0){
        ll t=powerup(N,P/2,M);
        return t*t%M;
    }
    else return N*powerup(N,P-1,M)%M;
}
int main()
{
  ll N;
  ll ans=0;
  cin>>N;
  ans=(N/500)*1000;
  N=N%500;
  ans+=(N/5)*5;
  cout<<ans<<endl;
}

Measured memory_bytes: 256
import itertools

N = int(input())

number = [7, 5, 3]

ans = 0
for i in range(10):
    for conv in itertools.product(number, repeat=i+1):
        
        tmp = 0
        for j in range(len(conv)):
            tmp += conv[j] * 10 ** (len(conv) - j - 1)
            
        
        if ((3 in conv) and (5 in conv) and (7 in conv)) and tmp <= N:
            ans += 1
            
        
print(ans)

Measured memory_bytes: 3064