akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#define repp(i,l,r)for(long long i=(l);i<(r);i++)
#define rep(i,n) for (long long i = 0; i < (n); ++i)
#define per(i,n) for (long long i = (n); i >= 0; --i)
const int INF = 2147483647;//int max
const long long int MOD = 1000000007;
using namespace std;
using ll = long long;
using P = pair<int,int>;
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
int main() {
    ll n,m,k;
    cin >> n >> m >> k;
    vector<ll> a(n+1,0);
    repp(i,1,n+1){
        cin >> a[i];
        a[i] += a[i-1];
    }
    vector<ll> b(m+1,0);
    repp(i,1,m+1){
        cin >> b[i];
        b[i] += b[i-1];
    }
    ll b_pos = m;
    ll res = 0;
    rep(i,n+1){
        if(a[i] > k)break;
        while(b[b_pos] > k - a[i])b_pos--;
        res = max(res, i + b_pos);
    }
    cout << res << endl;
    return 0;
}


Measured memory_bytes: 6400
import sys

n = int(input())

x = [int(i) for i in input().split()]

cofg=sum(x)//n
cofg2=cofg+1

sum=0
sum2=0
for i in range(n):
    sum+=(x[i]-cofg)**2
    sum2+=(x[i]-cofg2)**2


ans = sum if sum < sum2 else sum2



print(ans)


Measured memory_bytes: 3060
#[allow(unused_imports)]
use std::cmp::*;
#[allow(unused_imports)]
use std::collections::*;
use std::io::{Write, BufWriter};
// https://qiita.com/tanakh/items/0ba42c7ca36cd29d0ac8
macro_rules! input {
    ($($r:tt)*) => {
        let stdin = std::io::stdin();
        let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));
        let mut next = move || -> String{
            bytes
                .by_ref()
                .map(|r|r.unwrap() as char)
                .skip_while(|c|c.is_whitespace())
                .take_while(|c|!c.is_whitespace())
                .collect()
        };
        input_inner!{next, $($r)*}
    };
}

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

macro_rules! read_value {
    ($next:expr, [graph1; $len:expr]) => {{
        let mut g = vec![vec![]; $len];
        let ab = read_value!($next, [(usize1, usize1)]);
        for (a, b) in ab {
            g[a].push(b);
            g[b].push(a);
        }
        g
    }};
    ($next:expr, ( $($t:tt),* )) => {
        ( $(read_value!($next, $t)),* )
    };
    ($next:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
    };
    ($next:expr, chars) => {
        read_value!($next, String).chars().collect::<Vec<char>>()
    };
    ($next:expr, usize1) => (read_value!($next, usize) - 1);
    ($next:expr, [ $t:tt ]) => {{
        let len = read_value!($next, usize);
        read_value!($next, [$t; len])
    }};
    ($next:expr, $t:ty) => ($next().parse::<$t>().expect("Parse error"));
}

#[allow(unused)]
macro_rules! debug {
    ($($format:tt)*) => (write!(std::io::stderr(), $($format)*).unwrap());
}
#[allow(unused)]
macro_rules! debugln {
    ($($format:tt)*) => (writeln!(std::io::stderr(), $($format)*).unwrap());
}

fn solve() {
    let out = std::io::stdout();
    let mut out = BufWriter::new(out.lock());
    macro_rules! puts {
        ($($format:tt)*) => (let _ = write!(out,$($format)*););
    }
    input! {
        n: usize, k: i64,
        a: [i64; n],
    }
    let mut pass = 1i64 << 30;
    let mut fail = 0;
    while pass - fail > 1 {
        let mid = (pass + fail) / 2;
        let mut sum = 0;
        for i in 0..n {
            sum += (a[i] + mid - 1) / mid;
        }
        if sum <= k + n as i64 {
            pass = mid;
        } else {
            fail = mid;
        }
    }
    puts!("{}\n", pass);
}

fn main() {
    // In order to avoid potential stack overflow, spawn a new thread.
    let stack_size = 104_857_600; // 100 MB
    let thd = std::thread::Builder::new().stack_size(stack_size);
    thd.spawn(|| solve()).unwrap().join().unwrap();
}


Measured memory_bytes: 2672
#include <iostream>
#include <assert.h>
#include <vector>
#include <unordered_map>
#include <queue>
#include <climits>
#include <cmath>
#include <algorithm>
#include <string>
using namespace std;

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

  string S, T;
  int32_t A, B;
  cin >> S >> T;
  cin >> A >> B;
  string U;
  cin >> U;
  if (S == U) {
    cout << A - 1 << " " << B << endl;
  } else {
    cout << A << " " << B - 1 << endl;
  }
  return 0;
}


Measured memory_bytes: 256
//File Name: apc001_a.cpp
  //Created Time: 2018年02月04日 星期日 16时37分40秒
                                   
#include <bits/stdc++.h>
using namespace std;

int main(){
    long x,y;
    cin >> x >> y;
    if(x % y == 0) cout << -1 << endl;
    else cout << x << endl;
    return 0;
}


Measured memory_bytes: 256
#include <vector>
#include <list>
#include <map>
#include <unordered_set>
#include <deque>
#include <stack>
#include <algorithm>
#include <functional>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <tuple>
#include <set>
#include <iostream>
#define INF (1<<30);
using namespace std;
#define ll long long

bool done[111111];

int Solve(int K) {
    set<pair<int,int>> Q;
    Q.insert({0,1});
    
    for(int i=0;i<=K;i++)
        done[i]=false;
    while(!Q.empty()) {
        auto it = Q.begin();
        int rem = it->second;
        int v = it->first;
        Q.erase(it);
        
        
        if(rem == 0) {
            return v+1;
        }
        if (done[rem]) continue;

        done[rem]=true;
        
        int nr = (rem+1)%K;
        
        if (!done[nr]) {
            Q.insert({v+1,nr});
        }
        
        nr = (rem*10)%K;
        
        if (!done[nr]) {
            Q.insert({v,nr});
        }
        
    }
    
    return -1;
}

int main() {
    int K;
    cin>>K;
    

    cout << Solve(K) << endl;

    
}


Measured memory_bytes: 2688
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <cmath>
#include <iomanip>
#include <queue>
#include <climits>

int main(){

    long N;
    std::cin >> N;
    N-=1;
    char T[1000];
    long count=0;
    while(1){
        T[count]='a'+(N%26);
        count++;
        N=N/26;
        if(N==0){
            break;
        }
        N-=1;
    }
    
    for(long i=count-1; i>=0; i--){
        std::cout << T[i];
    }
    std::cout << std::endl;
    return 0;
}

Measured memory_bytes: 3616
#include<bits/stdc++.h>
#define rep(i,n) for(int i=0;i<n;i++)
using namespace std;
int main()
{
    int a,b;
    cin>>a>>b;
    if(a/10||b/10)cout<<-1;
    else
        cout<<a*b;
    return 0;
}


Measured memory_bytes: 256
#include<stdio.h>
int main()
{
    int A,B;
    scanf("%d %d",&A,&B);
  if(A==1 && B==3)
    printf("2");
  if(A==2 && B==3)
    printf("1");
  if(A==2 && B==1)
    printf("3");
    if(A==3 && B==1)
        printf("2");
    if(A==3 && B==2)
        printf("1");
    if(A==1 && B==2)
        printf("3");
    return 0;
}


Measured memory_bytes: 128
#include <iostream>
#include <string>
#include <vector>
#include <list>
#include <set>
#include <algorithm>

using namespace std;

typedef long long ll;
typedef unsigned long long ull;

// to container
template <class C>
void input(C &c)
{
    for_each(c.begin(), c.end(), [](auto &i) { cin >> i; });
}

// to number, string
template <class T>
T input()
{
    T data;
    cin >> data;
    return data;
}

int main()
{
    string S = input<string>();

    string res = "Yes";
    for (int i = 0; i < S.size(); i++)
    {
        if ((i + 1) % 2 != 0)
        {
            if (S[i] == 'L')
            {
                res = "No";
                break;
            }
        }
        else
        {
            if (S[i] == 'R')
            {
                res = "No";
                break;
            }
        }
    }

    cout << res << endl;
    return 0;
}

Measured memory_bytes: 256
//
// Created by yamunaku on 2019/07/14.
//

#include <bits/stdc++.h>

using namespace std;

#define rep(i, n) for(int i = 0; i < (n); i++)
#define repl(i, l, r) for(int i = (l); i < (r); i++)
#define per(i, n) for(int i = ((n)-1); i >= 0; i--)
#define perl(i, l, r) for(int i = ((r)-1); i >= (l); i--)
#define all(x) (x).begin(),(x).end()
#define MOD9 998244353
#define MOD1 1000000007
#define IINF 1000000000
#define LINF 1000000000000000000
#define SP <<" "<<
#define CYES cout<<"Yes"<<endl
#define CNO cout<<"No"<<endl
#define CFS cin.tie(0);ios::sync_with_stdio(false)
#define CST(x) cout<<fixed<<setprecision(x)

typedef long long ll;
typedef long double ld;
typedef vector<int> vi;
typedef vector<vector<int>> mti;
typedef vector<ll> vl;
typedef vector<vector<ll>> mtl;

int main(){
    int h,w;
    cin >> h >> w;
    vector<string> f(h);
    rep(i,h) cin >> f[i];
    int mil=100000,mal=-100000,mir=100000,mar=-100000;
    rep(i,h){
        rep(j,w){
            if(f[i][j]=='B'){
                mil=min(mil,i+j);
                mal=max(mal,i+j);
                mir=min(mir,i-j);
                mar=max(mar,i-j);
            }
        }
    }
    int ans=0;
    rep(i,h){
        rep(j,w){
            if(f[i][j]=='B'){
                ans=max(ans,abs(i+j-mil));
                ans=max(ans,abs(i+j-mal));
                ans=max(ans,abs(i-j-mir));
                ans=max(ans,abs(i-j-mar));
            }
        }
    }
    cout << ans << endl;
    return 0;
}




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

int main(){
	char c;
	cin >> c;
	if (c == 'a' || c == 'i' || c == 'u' || c == 'e' || c == 'o') {
		cout << "vowel" << endl;
	} else {
		cout << "consonant" << endl;
	}
 }

Measured memory_bytes: 256
#include <stdio.h>

int main (void)
{
	int n, x;
	int l, m, i;
	

	while(1){
		int s = 0;
		scanf("%d %d", &n, &x);
		if(n==0 && x==0) break;
		
		for(l=1; l<=n; l++){
			for(m=l+1; m<=n; m++){
				for(i=m+1; i<=n; i++)
					if((l+m+i) == x)
					++s;

			
			}
		}
		printf("%d\n",s);
	}
	return 0;

}

Measured memory_bytes: 600
#include <iostream>
// #include <cassert>
#include <vector>
#include <algorithm>
#include <climits>

// #include <stack>
// #include <queue>
// #include <deque>
// #include <set>
// #include <map>
// #include <string>
// #include <unordered_set>
// #include <unordered_map>

// #include <tuple>
// #include <cmath>
// #include <numeric>

using namespace std;
typedef long long ll;
typedef pair<long,long> pll;
typedef pair<int,int> pii;
typedef pair<int,long> pil;
typedef pair<long,int> pli;
typedef vector<vector<long long>> vvll;
typedef vector<vector<long>> vvl;
typedef vector<vector<int>> vvi;
typedef vector<int> vi;
typedef vector<long> vl;
typedef vector<long long> vll;

#define emplace_back pb
const char el = '\n';

/*
Edge cases:


*/

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

    int n,x,y; cin>>n>>x>>y; cin.ignore();

    int shortcut=y-x;
    vector<int> ret(n,0);
    for (int i=1; i<=n; ++i) {
        for (int j = i+1; j<=n; ++j) {

            if (i<=x && j>=y) {
                ++ret[j-i-shortcut+1];
            } else {
                int bestdist = min(j-i,abs(i-x)+1+abs(y-j));
                ++ret[bestdist];
            }
        }

    }

    for (int i = 1; i<=n-1; ++i) {
        cout<<ret[i]<<el;
    }

}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <math.h>
#include <algorithm>
#include <stdint.h>
#include <queue>
#include <bitset>
#include <iomanip>
#include <set>
#include <map>

using namespace std;

#define PI (3.14159265358979323846)
#define INF (2147483647)
#define INF_LL (9223372036854775807)
#define DIV_NUM (1000000007)

// 配列初期化テンプレ
template<typename A, size_t N, typename T>
void Fill(A(&array)[N], const T& val) {
	std::fill((T*)array, (T*)(array + N), val);
}


int main() {

	string S;
	cin >> S;

	int N = S.size();
	for (int i = 0; i < N; i++) {
		if (S[i] != S[N - i - 1]) {
			cout << "No" << endl;
			return 0;
		}

	}

	int M = (N - 1) / 2;
	for (int i = 0; i < M; i++) {
		if (S[i] != S[M - i - 1]) {
			cout << "No" << endl;
			return 0;
		}
	}

	for (int i = (N + 3) / 2; i < N; i++) {
		if (S[i] != S[N - i - 1]) {
			cout << "No" << endl;
			return 0;
		}
	}

	cout << "Yes" << endl;

	return 0;
}



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


// type definitions
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector< vi > vvi;
typedef pair<int, int> pii;
typedef vector<pii> vpii;
typedef complex<int> ci;
typedef complex<double> cd;
typedef complex<long double> cld;

// macros
#define rep(i, a, b) for(int i=a; i<b; i++)
#define TIME clock() * 1.0 / CLOCKS_PER_SEC
#define all(c) c.begin(), c.end()
#define tr(c, it) for(auto it=(c).begin(); it!=c.end(); it++)
#define PB push_back
#define MP make_pair
#define bitcount __builtin_popcount
#define watch(x) cerr<< (#x) << " is " << (x) <<"\n";
#define sz(x) ((int)((x).size()))
#define UNIQUE(c) (c).resize(unique(all(c)) - (c).begin())
#define pii2ll(p) ((ll)(p).first<<32 | (p).second)


// template functions
template <typename T>
inline void printV(vector<T>& a) { rep(i, 0, sz(a)) { cout<<a[i]<<" "; } cout<<"\n"; }
template <typename T>
inline void printV(vector<T>& a, int n) { rep(i, 0, n) { cout<<a[i]<<" "; } cout<<"\n"; }
template <typename T>
inline void printVV(vector<vector<T>>& a)
{
	rep(i, 0, sz(a)) {
		printV(a[i]);
	}
	cout<<"\n";
}

template <typename T>
inline void clearVV(vector<vector<T>>& a)
{
	for(auto& x:a) {
		x.clear();
	}
	a.clear();
}
template <typename T>
inline void assignVV(vector<vector<T>> &a, T val)
{
	for(int i=0; i<sz(a); i++) {
		for(int j=0; j<sz(a[i]); j++) {
			a[i][j]=val;
		}
	}
}

// random number generation
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

// constants
const long double eps = LDBL_EPSILON;
const int inf = 5e8;
const int modn = 1e9+7;
const int MAX = 1e5;

inline int add(int a, int b)
{
	int ret=((ll)a+b)%modn;
	if(ret<0) {
		ret=(ret+modn)%modn;
	}
	return ret;
}

inline int mul(int a, int b)
{
	int ret=((ll)a*b)%modn;
	if(ret<0) {
		ret=(ret+modn)%modn;
	}
	return ret;
}

int n;
int dp[4][4][4][103];
int cnt=0;

bool checkagc(int i1, int i2, int i3)
{
	if(i1==0 and i2==2 and i3==1) return 1;
	return 0;
}

bool check(int i1, int i2, int i3)
{
	if(checkagc(i1, i2, i3) or checkagc(i1, i3, i2) or checkagc(i2, i1, i3)) return 1;
	return 0;
}



int solve(int prev1, int prev2, int prev3, int ind)
{
	if(ind==n) {
		if(check(prev1, prev2, prev3)) return 0;
		return 1;
	}
	
	int &memo=dp[prev1][prev2][prev3][ind];
	if(memo!=-1) return memo;
	
	if(check(prev1, prev2, prev3)) return 0;
	
	int ans=0;
	
	for(int i=0; i<4; i++) {
		if(checkagc(prev1, prev2, i) or checkagc(prev1, prev3, i)) continue;
		ans=add(ans, solve(prev2, prev3, i, ind+1));
	}
	return memo=ans;
}

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    // Your code here
    memset(dp, -1, sizeof(dp));
	cin>>n;
	int ans=0;
	for(int i=0; i<4; i++) {
		for(int j=0; j<4; j++) {
			for(int k=0; k<4; k++) {
				ans=add(ans, solve(i, j, k, 3));
			}
		}
	}
	cout<<ans<<"\n";
    return 0;
}



Measured memory_bytes: 256
#include "bits/stdc++.h"
using namespace std;
using ll=long long;
#define print(n) cout<<n<<endl
#define rep(i,a,n) for(ll i=a;i<n;i++)
#define ALL(s) s.begin(),s.end()
#define P pair<ll,ll>
#define vl vector<ll>
#define vi vector<int>
#define vvl vector<vector<ll>>
#define vvi vector<vector<int>>
const int M=200111;
const int inf=1000000007;
const int MOD=1000000007;
const double PI = 3.1415926535897932384626433;
const long long INF=1e18;
int dx[4]={-1,0,1,0},dy[4]={0,-1,0,1};
int ddx[8]={1,-1,0,0,1,-1,-1,1},ddy[8]={0,0,1,-1,1,-1,1,-1};


struct UnionFind {
	vector<int> par;
	UnionFind(int n) : par(n, -1) { }

	int root(int x) {
		if (par[x] < 0) return x;
		else return par[x] = root(par[x]);
	}

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

	bool merge(int x, int y) {
		x = root(x); y = root(y);
		if (x == y) return false;
		if (par[x] > par[y]) swap(x, y); // merge technique
		par[x] += par[y];
		par[y] = x;
		return true;
	}

	int size(int x) {
		return -par[root(x)];
	}
};

vvl comb(int n) {
	vvl v(n + 1,vl(n + 1, 0));
	for (int i = 0; i < v.size(); i++) {
		v[i][0] = 1;
		v[i][i] = 1;
	}
	for (int j = 1; j < v.size(); j++) {
		for (int k = 1; k < j; k++) {
			v[j][k] = (v[j - 1][k - 1] + v[j - 1][k]);
		}
	}
	return v;
}

void sosu(ll x,bool f[]){
	ll y=x;
	for(ll i=2;i<=sqrt(y);i++){
		if(x%i==0){
			x/=i;
			f[i]=true;
			i--;
		}
	}
}

ll __gcd(ll x,ll y){
	if(x<y)swap(x,y);
	while(1){
		ll tmp=x%y;
		x=y;
		y=tmp;
		if(y==0)break;
	}
	return x;
}

int keta(ll a){
	int ke=1;
	while(a/=10)ke++;
	return ke;
}

vector<long long> enum_divisors(long long N) {
	vector<long long> res;
	for (long long i = 1; i * i <= N; ++i) {
		if (N % i == 0) {
			res.push_back(i);
			// 重複しないならば i の相方である N/i も push
			if (N/i != i) res.push_back(N/i);
		}
	}
	// 小さい順に並び替える
	sort(res.begin(), res.end());
	return res;
}

ll zyou(ll x,ll n){
	ll y=1;
	rep(i,0,n){
		y*=x;
	}
	return y;
}

int main() {
	int a,b,c;
	cin>>a>>b>>c;
	if(b-a==c-b)print("YES");
	else print("NO");

}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
 
int main(){
    int x,a,b;
	cin >> x >> a >> b;
	if(abs(x-a)<abs(x-b)){
		cout << "A" << endl;
	}
	else{
		cout << "B" << endl;
	}
	return 0;
}

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

#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)

using ll = long long;
#define INF 1e9

int main(){
  int N;
  cin >> N;
  cout << (N%2? (double)(N/2+1)/N: (double)(N/2)/N) << endl;
  return 0;
}


Measured memory_bytes: 256
class Dice:

    def __init__(self, faces):
        self.faces = tuple(faces)

    def roll_north(self):
        self.faces = (self.faces[1], self.faces[5], self.faces[2],
                      self.faces[3], self.faces[0], self.faces[4])

    def roll_south(self):
        self.faces = (self.faces[4], self.faces[0], self.faces[2],
                      self.faces[3], self.faces[5], self.faces[1])

    def roll_west(self):
        self.faces = (self.faces[2], self.faces[1], self.faces[5],
                      self.faces[0], self.faces[4], self.faces[3])

    def roll_east(self):
        self.faces = (self.faces[3], self.faces[1], self.faces[0],
                      self.faces[5], self.faces[4], self.faces[2])

    def rotate(self):
        self.faces = (self.faces[0], self.faces[2], self.faces[4],
                      self.faces[1], self.faces[3], self.faces[5])

    def number(self, face_id):
        return self.faces[face_id - 1]

    def issame(self, other_dice):
        for i in range(4):
            if self.faces[0] == other_dice.faces[0]:
                for j in range(4):
                    if self.faces == other_dice.faces:
                        return True
                    self.rotate()
            self.roll_north()

        for i in range(4):
            if self.faces[0] == other_dice.faces[0]:
                for j in range(4):
                    if self.faces == other_dice.faces:
                        return True
                    self.rotate()
            self.roll_east()
        return False

dice_list = []
n = int(input())
for i in range(n):
    dice_list.append(Dice([int(a) for a in input().split()]))

res = "Yes"
for i in range(n):
    for j in range(i + 1, n):
        if dice_list[i].issame(dice_list[j]):
            res = "No"
            break
print(res)

Measured memory_bytes: 6800
#include <bits/stdc++.h>
#define F first
#define S second
#define pii pair<int, int>
#define pb push_back

using namespace std;

typedef long long ll;
typedef long double ld;

const int N = 1e5 + 10;

int n, q;

ll a[N], z[N];
pair<ll, int> seg[4 * N];
ll ps[N], ans[N];

void upd(int id, int p, ll vl, int s = 0, int e = q + 1){
	if(e - s < 2){
		seg[id].F = vl;
		seg[id].S = s;
		return ;
	}
	int mid = (s + e)/2;
	
	if(p < mid)
		upd(2*id, p, vl, s, mid);
	else upd(2*id + 1, p, vl, mid, e);

	if(seg[2*id].F >= seg[2*id + 1].F)
		seg[id] = seg[2*id];
	else seg[id] = seg[2*id + 1];	
	return ;
}

int get(int id, int p ,int s = 0, int e = q + 1){
	if(e - s < 2)
		return seg[id].F;

	int mid = (s + e)/2;
	if(p < mid)return get(2*id, p, s, mid);
	else return get(2*id + 1, p, mid, e);
}

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

	for(int i=q; i>=0; i--){
		if(i == q){
			upd(1, 0, a[q]);
			z[0] = 1;
			continue;
		}
		ll nz = 0;
		while(seg[1].F >= a[i]){
			ll vl = seg[1].F % a[i];
			nz += (seg[1].F / a[i]) * z[seg[1].S];
			upd(1, seg[1].S, vl);
		}
		upd(1, q - i, a[i]);
		z[q - i] = nz;
	}

	for(int i=0; i<=q; i++){
		ps[get(1, i)] += z[i];
	}

	ll sum = 0;
	for(int i=n; i>=1; i--){
		sum += ps[i];
		ans[i] = sum;
	}

	for(int i=1; i<=n; i++)
		cout << ans[i] << '\n';
}	

Measured memory_bytes: 11136
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
//factorial
int fact(int n)
{
  if(n != 0) return n * fact(n-1);
  else return 1;
}
//distance
double distance(int x1, int y1, int x2, int y2)
{
  double x = (x1-x2)*(x1-x2) + (y1-y2)*(y1-y2);
  return sqrt(x);
}

int main()
{
  int N; cin >> N;
  int X[10], Y[10];
  rep(i,N) cin >> X[i] >> Y[i];
  int n = fact(N);
  int pat = fact(N-1);
  double dist = 0;
  rep(i, N)
  {
    rep(j, N)
    {
      if(i != j) dist += distance(X[i], Y[i], X[j], Y[j]); 
    }
  }
  double ans = dist*pat/n;
  printf("%f", ans);
}

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

#define endl		'\n'
#define tc			int t;cin>>t;while(t--)
#define int			long long
#define fr(i,a,b)	for(int i=a;i<=b;i++)
#define rep(i,a,b)	for(int i=a;i<b;i++)
#define pb 			push_back
#define ppb			pop_back
#define mp			make_pair	
#define all(x)		x.begin(),x.end()
#define ff			first
#define ss			second
#define pii			pair<int,int>
#define vi			vector<int>
#define vvi			vector<vi>
#define pqi			priority_queue<int>
#define pqd			priority_queue<int,vi,greater<int>>
#define inf			LLONG_MAX
#define mod			1000000007

int gcd(int a,int b){ return b==0?a:gcd(b,a%b);}
int lcm(int a,int b){ return a*b/gcd(a,b);}



int32_t main(){

	ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0);

	int n;
	cin>>n;
	vector<double> p(n);
	for(double &i:p){
		cin>>i;
	}
	vector<vector<long double>> dp(n+1,vector<long double>((n+1)/2+1));
	fr(i,0,n){
		dp[i][0]=1;
	}
	fr(i,1,(n+1)/2){
		dp[0][i]=0;
	}
	fr(i,1,n){
		fr(j,1,(n+1)/2){
			dp[i][j]=p[i-1]*dp[i-1][j-1]+(1-p[i-1])*dp[i-1][j];
		}
	}

	cout<<fixed<<setprecision(10)<<dp[n][(n+1)/2]<<endl;


	return 0;	
}

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

using namespace std;

typedef long long  ll;
typedef vector<ll> VL;
typedef pair<ll,ll> PLL;
#define fr(i,x,y) for(ll i=x;i<y;i++)
#define inf 1000*1000*1000+5
const ll mod=998244353;


void solve()
{
	ll x;
	cin>>x;
	ll ans=1000*(x/500);
	x-=500*(x/500);
	ans+=(x/5)*5;
	cout<<ans<<endl;
	return;
}
int main()
{
	solve();
	return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
int main(void){
	int a,b,c,d;
	scanf("%d%d%d%d",&a,&b,&c,&d);
	if((a+b)==(c+d)){
		printf("Balanced");
	}else if((a+b)>(c+d)){
		printf("Left");
	}else{
		printf("Right");
	}
	return 0;
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
#define mod 1000000007
#define PI acos(-1.0)
typedef long long ll;
typedef unsigned long long ull;
#define gcd __gcd
const int INF=0x3f3f3f3f;
const ll LINF=1000000000000000000;
//priority_queue<int, vector<int>, greater<int> >p;
//#define N 200005
//ll d[4][2]={1,0,-1,0,0,1,0,-1};
char str[200];
int main()
{
//    ios_base::sync_with_stdio(0);
//    cin.tie(0);
    int n;
    cin >> n;
    cin >> str+1;
    int r = 0, b = 0;
    for (int i = 1; i <= n; i++)
    {
        if (str[i] == 'R')r++;
        else b++;
    }
    if (r > b)cout << "Yes" << endl;
    else cout << "No" << endl;
    return 0;
}


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

using namespace std;
typedef long long ll;
const int INF = 1e9;
const int MOD = 1e9 + 7;
const ll LINF = 1e18;

string f(string s) {
    string t;

    bool continue2 = false;

    for (int i = 0; i < s.size(); ++i) {
        if (continue2) {
            continue2 = false;
            continue;
        }

        if (s[i] == '(' && s[i+1] == ')') {
            continue2 = true;
            continue;
        }

        t += s[i];
    }

    if (s == t) {
        return t;
    }

    return f(t);
}

int main() {

    int n; cin >> n;
    string s; cin >> s;

    string t = f(s);

    int l = 0;
    int r = 0;

    for (int i = 0; i < t.size(); ++i) {
        if (t[i] == ')') {
            ++l;
        } else {
            ++r;
        }
    }

    string ans = "";

    for (int i = 0; i < l; ++i) {
        ans += '(';
    }

    ans += s;

    for (int i = 0; i < r; ++i) {
        ans += ')';
    }

    cout << ans << endl;
}

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

int C[102][102];

void meiro(int W,int H,int c){
  if(C[W][H]!=c){
    return;
  }

  C[W][H] = -1;

  meiro(W-1,H  ,c);
  meiro(W  ,H+1,c);
  meiro(W+1,H  ,c);
  meiro(W  ,H-1,c);
}

int main(){
  while(1){
    int w,h;
    cin >> w >> h;
    if(w==0 && h==0){
      break;
    }

    for(int i=0;i<102;i++){
      for(int j=0;j<102;j++){
        C[i][j] = 0;
      }
    }

    int xs,ys,xg,yg;
    cin >> xs >> ys >> xg >> yg;

    int n;
    cin >> n;

    int c,d,x,y;
    for(int i=0;i<n;i++){
      cin >> c >> d >> x >> y;

      if(d==0){
        for(int j=x;j<x+4;j++){
          for(int k=y;k<y+2;k++){
            C[j][k]=c;
          }
        }
      }else{
        for(int j=x;j<x+2;j++){
          for(int k=y;k<y+4;k++){
            C[j][k]=c;
          }
        }
      }
    }
    if(C[xs][ys] == 0){
      cout << "NG" << endl;
      continue;
    }
    
    meiro(xs,ys,C[xs][ys]);

    if(C[xg][yg] == -1){
      cout << "OK" << endl;
    }else{
      cout << "NG" << endl;
    }
  }

  return 0;
}



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

namespace My
{
template <typename ArrayT>
static void DumpArray(const ArrayT &arr)
{
#if defined(HOME)
	for (auto it = std::begin(arr); it != std::end(arr); ++it) {
		cerr << *it << " ";
	}
	cerr << endl;
#endif
}
template<typename T>
static void DumpGrid(const vector<vector<T>> &grid){
#if defined(HOME)
	REP (i, grid.size()) {
		REP (j, grid[i].size()) {
			cerr << grid[i][j] << " ";
		}
		cerr << endl;
	}
#endif
}
template <class ArrayT, typename T>
static void InitArray(ArrayT &arr, T initValue){
	for (auto &v : arr){
		v = initValue;
	}
}
template <typename T>
static bool ReplaceIfSmaller(T &target, T value)
{
	if (value < target) {
		target = value;
		return true;
	} else {
		return false;
	}
}
template <typename T>
static bool ReplaceIfBigger(T &target, T value)
{
	if (target < value) {
		target = value;
		return true;
	} else {
		return false;
	}
}

class Solver
{
  public:
	Solver() {}
	void Solve(istream &cin, ostream &cout)
	{
		int N;
		cin >> N;

		// matrixを作る
		vector<vector<int>> grid(15, vector<int>(15));
		REP(i, 15)REP(j, 15){
			grid[i][j] = -1;
		}

		REP(i, N){
			int A;
			cin >> A;

			REP(j, A){
				int X, Y;
				cin >> X >> Y;

				grid[i][X - 1] = Y;
			}
		}
		// DumpGrid(grid);

		// BIT全探索
		// 全探索に使用する全bit数
		// N = 15;

		int ans = 0;
		// bit mask の生成
		// 2^n     = 1 << n
		REP(mask, 1<<N){
			array<int, 15> arr {0};	// デフォルトで0初期化される
			// BITが立っているところだけを 1 にしていく
			REP(j,N){
				if (mask>>j&1){
					arr[j] = 1;
				}
			}

			bool failed = false;
			// arrをなめて、正直者の証言だけをチェックしていく
			REP(i, N){
				// iビット目が立っている？
				if (arr[i]) {
					// その人の証言を確認する
					REP(k, N){
						if (grid[i][k] == -1) continue;
						if (grid[i][k] != arr[k]) {
							failed = true;
							break;
						}
					}
					if (failed) break;
				}
			}
			cerr << mask << "======" << endl;
			DumpArray(arr);
			if (!failed) {
				cerr << "Succeeded" << endl;
				ReplaceIfBigger(ans, __builtin_popcount(mask));
			}
		}
		cout << ans << endl;
	}
};
} // namespace My

#if !defined(BOOST_TEST_MODULE)
#if !defined(GTEST_INCLUDE_GTEST_GTEST_H_)
int main()
{
	std::cin.tie(0);
	std::ios::sync_with_stdio(false);

	My::Solver solver;
	solver.Solve(std::cin, std::cout);

	return 0;
}
#endif
#endif


Measured memory_bytes: 256
import java.io.*;
import java.util.*;

public class Main {
    public static void main(String[]args) {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        try {
       String isWin = "";
    
       int [] a = new int [4];
     
       
       String  lines = br.readLine();    
    
       String[] strs = lines.trim().split("\\s+");
      
       for (int i = 0; i < strs.length; i++) {
       a[i] = Integer.parseInt(strs[i]);
       }
  
    int taka = (a[0]+a[3]-1)/a[3];
    int aoki = (a[2]+a[1]-1)/a[1];
    
    
    System.out.println(taka>=aoki?"Yes" : "No" ); 
     
    }catch (Exception e) {
    }
    
}}

Measured memory_bytes: 25440
n = int(input())
INF = float("inf")
edges = [[] for _ in range(n)]
visited = [False]*n
# edges = [[INF for _ in range(n)] for _ in range(n)]
edges = [[] for _ in range(n) for _ in range(n)]
d = [INF]*n
d[0] = 0

for _ in range(n):
    ls = list(map(int, input().split()))
    u = ls[0]
    degrees = ls[1]
    data = ls[2:]
  
    for i in range(degrees):
        v = data[i*2]
        cost = data[i*2+1]
        edges[u].append((v, cost))
        # edges[u][v] = cost

#通常版
# for _ in range(n):
#     dmin = float("inf")
#     for i in range(n):
#         if not visited[i] and d[i] < dmin:
#             dmin = d[i]
#             u = i
#     visited[u] = True
#     for v, c in enumerate(edges[u]):
#         d[v] = min(d[v], d[u] + c)

# for i in range(n):
#     print(i, d[i])
    
#heap版
import heapq

heap = [(0, 0)]
d[0] = 0


while heap:
    du, u = heapq.heappop(heap)
    for v, cost in edges[u]:
        if du + cost < d[v]:
            d[v] = du +  cost
            heapq.heappush(heap, (d[v], v))

for i in range(n):
    print(i, d[i])


Measured memory_bytes: 6884
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int a[] = {1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51};
        int k = sc.nextInt();
        System.out.println(a[k - 1]);
    }
}

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

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

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

using namespace std;

int peper[15][15];

void paint(int x, int y)
{
	if (x * y >= 0 && x >= 0)	peper[y][x]++;
}

int main()
{
	int x, y;
	int size;
	
	while (scanf("%d,%d,%d", &x, &y, &size) != EOF){
		peper[y][x]++;

		paint(x, y - 1);
		paint(x, y + 1);
		paint(x - 1, y);
		paint(x + 1, y);

		if (size > 1){
			paint(x + 1, y - 1);
			paint(x + 1, y + 1);
			paint(x - 1, y + 1);
			paint(x - 1, y - 1);
		}
		if (size > 2){
			paint(x, y - 2);
			paint(x, y + 2);
			paint(x - 2, y);
			paint(x + 2, y);
		}
	}
	int dark = 0;
	int blank = 0;
	
	for (int i = 0; i < 10; i++){
		for (int j = 0; j < 10; j++){
			if (peper[i][j] == 0)	blank++;
			dark = max(dark, peper[i][j]);
		}
	}
	printf("%d\n%d\n", blank, dark);
	return (0);
}

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

int main() {
    while (true) {
        int n;
        cin >> n;
        if (n == 0) {
            break;
        }
        bool field[101][101] = {};
        int w, h;
        cin >> w >> h;
        for (int i = 0; i < n; i++) {
            int x, y;
            cin >> x >> y;
            field[y][x] = true;
        }
        int s, t;
        cin >> s >> t;
        int max = 0;
        for (int y = 1; y <= h - t + 1; y++) {
            for (int x = 1; x <= w - s + 1; x++) {
                int count = 0;
                for (int i = 0; i < t; i++) {
                    for (int j = 0; j < s; j++) {
                        if (field[y + i][x + j]) {
                            count++;
                        }
                    }
                }
                if (max < count) {
                    max = count;
                }
            }
        }
        cout << max << endl;
    }
}

Measured memory_bytes: 0
#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)
typedef long long ll;
typedef pair<int,int> pint;
typedef pair<ll,int> pli;
const int inf=1e9+7;
const ll longinf=1LL<<60 ;
const ll mod=1e9+7 ;

int main(){
    int n,q;
    cin>>n>>q;
    string s;
    cin>>s;
    pair<char,char> p[q];
    rep(i,q)cin>>p[i].first>>p[i].second;
    int ok=-1,ng=n;
    while(ng-ok>1){
        int mid=(ok+ng)/2;
        int cur=mid;
        rep(i,q){
            if(0<=cur&&cur<n&&s[cur]==p[i].first){
                if(p[i].second=='R')++cur;
                else --cur;
            }
        }
        if(cur<n)ok=mid;
        else ng=mid;
    }
    int l=ok;
    ok=n;ng=-1;
    while(ok-ng>1){
        int mid=(ok+ng)/2;
        int cur=mid;
        rep(i,q){
            if(0<=cur&&cur<n&&s[cur]==p[i].first){
                if(p[i].second=='R')++cur;
                else --cur;
            }
        }
        if(cur>=0)ok=mid;
        else ng=mid;
    }
    int r=ok;
    cout<<max(l-r+1,0)<<endl;
    return 0;
}

Measured memory_bytes: 900
#define _CRT_SECURE_NO_WARNINGS
#include<stdio.h>
#include<vector>
#include<functional>
#include<algorithm>
#include<stdlib.h>
#include<string>
#include<string.h>
#define _USE_MATH_DEFINES
#include<math.h>
#include<deque>
#include<set>
#include<map>
#include<queue>
#include<list>
#include<iostream>
using namespace std;
typedef long long ll;
#define rep(i,a,b) for(auto i=a;i<b;i++)
#define all(_x) _x.begin(), _x.end()
#define r_sort(_x) sort(_x.begin(), _x.end(), std::greater<int>())
#define vec_cnt(_a, _n) (upper_bound(all(_a), _n) - lower_bound(all(_a), _n))
ll gcd(ll a, ll b) { return a % b == 0 ? b : gcd(b, a % b); }
ll lcm(ll a, ll b) { return (a / gcd(a, b)) * b; }
#define INF 1 << 30
const ll mod = 1000000007;
int main() {
	int N, A;
	scanf("%d", &N);
	vector<vector<int>> a(N), b(N);
	vector<int> f(N);
	rep(i, 0, N) {
		scanf("%d", &A);
		rep(i2, 0, A) {
			int x, y;
			scanf("%d%d", &x, &y);
			x--;
			if (y)a[i].push_back(x);
			else b[i].push_back(x);
		}
	}
	int ans = 0, c;
	rep(i, 0, 1 << N) {
		bool ok = true;
		c = 0;
		rep(i2, 0, N) {
			f[i2] = (i & (1 << i2)) && ++c;
		}
		rep(i2, 0, N) {
			if (!f[i2])continue;
			for (auto v : a[i2]) {
				if (f[v] == 0) {
					ok = false;
					break;
				}
			}
			if (!ok)break;
			for (auto v : b[i2]) {
				if (f[v]) {
					ok = false;
					break;
				}
			}
			if (!ok)break;
		}
		if (ok) {
			ans = max(ans, c);
		}
	}
	printf("%d\n", ans);
	return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <string>
#include <cstring>
#include <map>
#include <list>
#include <set>
#include <stack>
#include <deque>
#include <queue>
#include <cmath>
#include <algorithm>
#include <utility>
#include <functional>
#include <random>
#include <fstream>
#include <time.h>
#define int long long
#define debug(x) cerr << #x << " = " << x << endl
#define FOR(i,a,b) for(int i = (a); i < (b); i++)
#define rep(i,n) for(int i = 0; i < (n); i++)
#define repr(i,n) for(int i = (n); i > -1; i--)
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
const int MOD = 1000000007;
const ll LINF = 1e18;
const double EPS = 1e-9;


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

  int n;
  cin>>n;
  vector<int> a,b;
  if (n == 3) {
    cout << 2 << endl;
    cout << 1 << " " << 3 << endl;
    cout << 2 << " " << 3 << endl;
    return 0;
  }
  a.push_back(1);a.push_back(1);a.push_back(2);a.push_back(3);
  b.push_back(3);b.push_back(2);b.push_back(4);b.push_back(4);
  int now = 4;
  while(now < n) {
    if((n-now) == 1 && now % 2 == 0) {
      int adder = now + 1;
      FOR(i,1,adder) {
        a.push_back(i);
        b.push_back(adder);
      }
      now++;
    } else {
      int adder = now + 1;
      FOR(i,1,adder) {
        a.push_back(i);
        b.push_back(adder);
        a.push_back(i);
        b.push_back(0);
      }
      rep(i,a.size()) {
        a[i]++;b[i]++;
      }
      now += 2;
    }
  }

  cout << a.size() << endl;
  rep(i,a.size()) {
    cout << a[i] << " " << b[i] << endl;
  }
  

  return 0;
}


Measured memory_bytes: 512
#include <bits/stdc++.h>
typedef long long ll;
typedef long double ld;
using namespace std;

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

    int ans = 1e9;
    for (int i = 0; i + K - 1 < N; i++) {
        ans = min(ans, abs(x[i]) + abs(x[i + K - 1] - x[i]));
        ans = min(ans, abs(x[i + K - 1]) + abs(x[i + K - 1] - x[i]));
    }
    cout << ans << endl;
}


Measured memory_bytes: 640
package main

import (
	"bufio"
	"fmt"
	"io"
	"os"
	"strconv"
)

var (
	readString func() string
	stdout     *bufio.Writer
)

func init() {
	readString = newReadString(os.Stdin)
	stdout = bufio.NewWriter(os.Stdout)
}

func newReadString(ior io.Reader) func() string {
	r := bufio.NewScanner(ior)
	r.Buffer(make([]byte, 1024), int(1e+11))
	r.Split(bufio.ScanWords)

	return func() string {
		if !r.Scan() {
			panic("Scan failed")
		}
		return r.Text()
	}
}

func readInt() int {
	i, err := strconv.Atoi(readString())
	if err != nil {
		panic(err.Error())
	}
	return i
}

func readIntSlice(n int) []int {
	b := make([]int, n)
	for i := 0; i < n; i++ {
		b[i] = readInt()
	}
	return b
}

func readLengthAndSlice() []int {
	n := readInt()
	return readIntSlice(n)
}

func printf(f string, args ...interface{}) (int, error) {
	return fmt.Fprintf(stdout, f, args...)
}

func println(args ...interface{}) (int, error) {
	return fmt.Fprintln(stdout, args...)
}

func vi(n int, args ...int) []int {
	res := make([]int, n)
	if len(args) == 0 {
		return res
	}
	v := args[0]
	if v == 0 {
		return res
	}
	for i := 0; i < n; i++ {
		res[i] = v
	}
	return res
}

func vvi(n int, args ...int) [][]int {
	res := make([][]int, n)
	m := n
	if len(args) > 0 {
		m = args[0]
	}
	v := 0
	if len(args) > 1 {
		v = args[1]
	}
	for i := 0; i < n; i++ {
		res[i] = vi(m, v)
	}
	return res
}

func main() {
	defer stdout.Flush()

	// readString() string
	// readInt() int
	// readIntSlice(n int) []int
	// readLengthAndSlice() []int

	H := readInt()
	W := readInt()

	F := vvi(55, 55)

	for i := 1; i <= H; i++ {
		s := readString()
		j := 1
		for _, r := range s {
			if r == '#' {
				F[i][j] = 1
			}
			j++
		}
	}
	dx := []int{-1, 0, 1, 0}
	dy := []int{0, -1, 0, 1}

	for i := 1; i <= H; i++ {
		for j := 1; j <= W; j++ {
			if F[i][j] > 0 {
				flag := false
				for k := range dx {
					x := i + dx[k]
					y := j + dy[k]
					if F[x][y] > 0 {
						flag = true
					}
				}
				if !flag {
					println("No")
					return
				}
			}
		}
	}
	println("Yes")
}


Measured memory_bytes: 640
#include <bits/stdc++.h>
#include <vector>
#include <cmath>
#define REP(i, n) for (int i = 0; i < (int)(n); ++i)
#define REP2(i, m, n) for (int i = (m); i < (int)(n); ++i)
#define REPR(i, n) for (int i = (n)-1; i >= 0; --i)
#define REPR2(i, m, n) for (int i = (n)-1; i >= (m); --i)
#define REPx(x, a) for(auto x : a)
#define ALL(a) a.begin(), a.end()
#define SORT(a) sort(ALL(a))
#define SORTR(a) sort(ALL(a), greater<int>())
#define REVERSE(a) reverse(ALL(a))
#define bit_search(bit, n) REP(bit, 1<<(n))
#define bit_check(bit, i) (bit>>(i)) & 1
#define setpre(n) fixed << setprecision((n))
#define UNIQUE(a) do {SORT(a); (a).erase(unique(ALL(a)), (a).end());} while(0)
#define MAX(a) *max_element(ALL(a))
#define MIN(a) *min_element(ALL(a))
#define bisect_left(a, x) lower_bound(ALL(a), (x)) - a.begin()
#define bisect_right(a, x) upper_bound(ALL(a), (x)) - a.begin()
#define INPUT(a) REP(i, a.size()) cin >> a[i];
#define INPUTP(a) REP(i, a.size()) cin >> a[i].first >> a[i].second;
#define ENDL cout << endl;
using namespace std;
using LL = long long;
using LD = long double;
using PII = pair<int, int>;
using VPII = vector<PII>;
using PLL = pair<LL, LL>;
using VPLL = vector<PLL>;
using VI = vector<int>;
using VVI = vector<VI>;
using VLL = vector<LL>;
using VVLL = vector<VLL>;
using VC = vector<char>;
using VS = vector<string>;
using VB = vector<bool>;
const LL INF = 1e14;
const LL MOD = 1e9 + 7;

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()
{
  cin.tie(0);
  ios::sync_with_stdio(false);
  LL n, m;
  cin >> n >> m;
  VPLL key(m);
  REP(i, m)
  {
    LL a, b;
    cin >> a >> b;
    LL tmp = 0;
    REP(j, b)
    {
      LL c;
      cin >> c; c--;
      tmp |= 1<<c;
    }
    key[i] = {a, tmp};
  }
  VLL dp(1<<n, INF);
  dp[0] = 0;
  bit_search(s, n)
  {
    REPx(x, key)
    {
      LL cost = x.first;
      LL t = x.second | s;
      chmin(dp[t], cost+dp[s]);
    }
  }
  if (dp.back() == INF) cout << -1 << endl;
  else cout << dp.back() << endl;

  return 0;
}

Measured memory_bytes: 256
//#include "pch.h"
#include <iostream>
#include<string>
#include<algorithm>
#include<iomanip>

using namespace std;


int main() {

	string num;
	cin >> num;


	string ans = "Good";
	if (num[0] ==num[1]) ans = "Bad";
	if (num[1] == num[2]) ans = "Bad";
	if (num[2] == num[3]) ans = "Bad";

	cout << ans << endl;
}




Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <set>
#include <map>
#define MODD 1000000000000037ll
#define Inf 10000000
#define ll long long
using namespace std;

string S;

int main() {
    cin>>S;
    
    int L=S.size();
    int counts[26];
    for(int i=0;i<26;i++)
        counts[i]=0;
    for(int i=0;i<S.size();i++)
        counts[S[i]-'a']++;
    
    ll ans = ((ll)(L)*(ll)(L-1))/2;

    for(int i=0;i<26;i++) {
        ll x = ((ll)counts[i]*(ll)(counts[i]-1))/2;
        ans -= x;
    }
    
    cout << ans+1 << endl;
    /*
    int L=S.size();
    

    cout << ans << endl;
    
    map<string, vector<pair<int,int> > > uniq;
    for(int i=0;i<L;i++) {
        for(int j=i+1;j<L;j++) {
            // i to j
            int p1=i;
            int p2=j;
            string SS=S;
            while(p1<p2) {
                swap(SS[p1],SS[p2]);
                p1++;
                p2--;
            }
            cout << SS << endl;
            uniq[SS].push_back({i,j});
            
        }
    }
    
    for(auto x : uniq) {
        for(int j=0;j<x.second.size();j++)
            printf("%d %d,",x.second[j].first,x.second[j].second);
        printf("\n");
    }
    
    for(int i=0;i<L;i++) {
        // odd
        // i to L-1 and 0 to i
        int low=1;
        int high=min(L-i,i+1);
        while(low < high) {
            int mid = (low + high + 1)/2;
            if (GetHash(i+1-mid,i) == GetRevHash(i,i+mid-1)) {
                low=mid;
            } else {
                high=mid-1;
            }
        }
        // 2*1-1,2*2-1,...,2*low-1
        ans -= low;
        
        cout << low << " ";
        
        // even
        // i+1 to L-1 and 0 to i
        low=0;
        high=min(i+1,L-i-1);
        
        while(low<high) {
            int mid = (low + high + 1)/2;
            if (GetHash(i+1-mid,i) == GetRevHash(i+1,i+mid)) {
                low=mid;
            } else {
                high=mid-1;
            }
        }
        ans -= low;
        cout << low << endl;

    }
    
    cout << ans << endl;
     */
}

Measured memory_bytes: 640
#include "iostream"
#include "algorithm"
#include "vector"
#include "string"
#define cout(s) cout<<s<<endl 
using namespace std;

int main()
{
	int x, y;
	cin >> x >> y;
	bool ans = false;
	if ((x == 1 || x==3 || x == 5 || x == 7 || x == 8 || x == 10 || x == 12) && (y == 1 || y == 3 || y == 5 || y == 7 || y == 8 || y == 10 || y == 12))
		ans = true;
	if ((x == 4 || x == 6 || x == 9 || x == 11) && (y == 4 || y == 6 || y == 9 || y == 11))
		ans = true;
	
	cout((ans ? "Yes" : "No"));
	return 0;
}

Measured memory_bytes: 256
package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
)

func getScanner(fp *os.File) *bufio.Scanner {
	scanner := bufio.NewScanner(fp)
	scanner.Split(bufio.ScanWords)
	scanner.Buffer(make([]byte, 500001), 500000)
	return scanner
}

func getNextString(scanner *bufio.Scanner) string {
	scanner.Scan()
	return scanner.Text()
}

func getNextInt(scanner *bufio.Scanner) int {
	i, _ := strconv.Atoi(getNextString(scanner))
	return i
}

func getNextInt64(scanner *bufio.Scanner) int64 {
	i, _ := strconv.ParseInt(getNextString(scanner), 10, 64)
	return i
}

func main() {
	fp := os.Stdin
	if len(os.Args) > 1 {
		fp, _ = os.Open(os.Args[1])
	}

	scanner := getScanner(fp)
	writer := bufio.NewWriter(os.Stdout)

	n := getNextInt(scanner)
	aa := make([]int, n)
	ll := make([]int, n)
	rr := make([]int, n)

	for i := 0; i < n; i++ {
		aa[i] = getNextInt(scanner)
	}

	for i := 0; i < n; i++ {
		ll[i] = aa[i]
		rr[n-1-i] = aa[n-1-i]
		if i == 0 {
			continue
		}
		if ll[i] < ll[i-1] {
			ll[i] = ll[i-1]
		}
		if rr[n-1-i] < rr[n-i] {
			rr[n-1-i] = rr[n-i]
		}
	}

	for i := 0; i < n; i++ {
		if i == 0 {
			fmt.Fprintln(writer, rr[1])
			continue
		}
		if i == n-1 {
			fmt.Fprintln(writer, ll[n-2])
			continue
		}
		ans := ll[i-1]
		if ll[i-1] < rr[i+1] {
			ans = rr[i+1]
		}
		fmt.Fprintln(writer, ans)
	}

	writer.Flush()
}


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

int main() {
    long long n;
    cin >> n;
    vector<long long> a(n);
    long long total=0;
    for(int i=0;i<n;i++){
        cin >> a[i];
        total+=a[i];
    }
    long long com=0,com1=0,com2=0;
    for(int i=0;i<n-1;i++){
        com+=a[i];
        if(com<=(total/2)&&(com+a[i+1])>(total/2)){
            com1=com;
            com2=com+a[i+1];
            break;
        }
    }
    cout << min(abs(2*com1-total),abs(2*com2-total)) << endl;
}

Measured memory_bytes: 1792
L = [int(i) for i in input()]
l = len(L)


def mod_pow(a, p, mod):
    if p == 0:
        return 1
    elif p % 2 == 1:
        return a * mod_pow(a, p - 1, mod)
    else:
        return (mod_pow(a, p // 2, mod) % mod) ** 2 % mod


# L以下の整数は「上からi桁目まで同じで、それ以降違う」で考える。　あるL以下の整数=A+B
# L[i]=0のときAとBの桁は(0,0), L[i]=1のときAとBの桁は(0,1)(1,0)のどちらか
mod = 10 ** 9 + 7
answer = 0
prev = 1

for i, j in enumerate(L, 1):
    if j == 0:
        continue
    answer += prev * mod_pow(3, l - i, mod)
    answer %= mod
    prev *= 2
    prev %= mod

answer += prev
answer %= mod
print(answer)


Measured memory_bytes: 3956
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {

		Scanner scanner = new Scanner(System.in);
		while (true) {
			int n = scanner.nextInt();
			if (n == 0) {
				break;
			}
			int[][] map = new int[n][n];
			int i = 1;
			int x = n / 2;
			int y = n / 2 + 1;
			while (n * n >= i) {
				map[y][x] = i;
				y = (y + 1) % n;
				x = (x + 1) % n;
				if (map[y][x] != 0) {
					y = (y + 1) % n;
					x = (x + n - 1) % n;
				}
				i++;
			}
			for (int k = 0; k < n; k++) {
				for (int j = 0; j < n; j++) {
					System.out.print(String.format("%4d", map[k][j]));
				}
				System.out.println();
			}
		}

	}
}

Measured memory_bytes: 20120