akhauriyash/Code-Regression huggingface dataset:
#include<iostream>
#include<map>
#include<set>
#include<string>
#include<algorithm>
#include<cmath>
#include<vector>

using namespace std;

typedef long long ll;
typedef unsigned long long ull;

const int inf = 999999999;
const double pi = acos(-1);

#define rep(i,m,n) for(int i = (m); i < (int)(n); i++)
#define mod(i) ((i)%(ll)(1e9 + 7))
#define divm(a,b) (mod(a * modpow((ll)b,(ll)(1e9+5))))
#define rsort(a,b,c) sort(a, b, greater<c>())

ll modpow(ll i,ll j){ ll tmp=1; while(j){ if(j%2)tmp=mod(tmp*i);i=mod(i*i);j/=2;}return tmp;}

///////////////////////////////////////////////////////////////////////////
int a[100005] = {};

int main(){
	int n;
	map<int,int> m;
	
	cin >> n;
    rep(i,0,n){
        cin >> a[i];
        m[a[i]] ++;
    }

    if(n%2 == 0){
        int t = -1;
        for(auto it:m){
            if(t != it.first - 2){
                cout << 0 << endl;
                return 0;
            }else if(it.first%2 == 0 || it.second != 2){
                cout << 0 << endl;
                return 0;
            }
            t += 2;
        }

        cout << modpow(2,(n)/2)<< endl;
    }else{
        int t = -2;
        for(auto it:m){
            if(t != it.first - 2){
                cout << 0 << endl;
                return 0;
            }else if(it.first == 0){
                if(it.second != 1){
                    cout << 0 << endl;
                    return 0;
                }
            }else if(it.first%2 == 1  || it.second != 2){
                cout << 0 << endl;
                return 0;
            }
            t += 2;
        }

        cout << modpow(2,(n-1)/2)<< endl;
    }
	return 0;
}

Measured memory_bytes: 3584
function main(lines) {
  const xs = splitN(lines[0]);

  const res = xs.indexOf(0) + 1;
  
  console.log(res);
}


main( require("fs").readFileSync("/dev/stdin", "utf8").trim().split("\n") );



function splitN(s) {
  return s.split(' ').map(Number);
}

Measured memory_bytes: 29636
n=int(input())
t,a=map(int,input().split())
h=list(map(int,input().split()))
kion=1000
ans=0
for i in range(n):
  if kion>abs(t-h[i]*0.006-a):
    kion=abs(t-h[i]*0.006-a)
    ans=i+1
print(ans)
  

Measured memory_bytes: 3060
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		
		int N = sc.nextInt();
		
		if (N%2 == 0) {
			System.out.println(N);
		} else {
			System.out.println(2*N);
		}
	}

}

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

typedef long long ll;
#define all(x) (x).begin(), (x).end()  // sortなどの引数を省略
#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
#define max3(x, y, z) max(x, max(y, z))
#define min3(x, y, z) min(x, min(y, z))

#ifdef _MSC_FULL_VER  //デバッグ出力
#define dout cout
#define debug() if (true)
#define check(x) std::cout << "★" << #x << "の値:" << (x) << endl
#define pass(x) std::cout << "☆" << x << endl
#else
#define dout \
  if (false) cout
#define debug() if (false)
#define check(x) \
  if (false) cout << "★" << #x << "の値:" << (x) << endl
#define pass(x) \
  if (false) cout << "☆" << x << endl
#endif

using namespace std;
int main() {
  int N;
  cin >> N;
  vector<int> list(N);
  int tmp;
  rep(i, N) {
    cin >> list[i];
    list[i]--;
  }
  int ans = 0;
  rep(i, N) {
    tmp = list[i];
    if (list[tmp] == i) {
      ans++;
    }
  }
  cout << ans / 2;
}
/*
//よく使うやつ
int N;
cin >> N;
vector<int> list(N);
rep(i,N) {
  cin >> list[i];
}
//配列(スタックとしても使える)
vector<int> list;
list.at(i)
vector<vector<int>> list(10, vector<int>(10));
//ソート クイックだからO(NlogN)
sort(all(list));
sort(all(list), greater<int>());

//配列の内容表示
dout << "====listの内容====\n";
for (int edp = 0; edp < N; edp++) dout << list[edp] << endl;
dout << "====ここまで====\n";


//配列の最小最大(Nは要素数)
*min_element(all(c))
*max_element(all(c))

//a[0]からa[N]を逆順にする(計算量はO(N))
reverse(all(a));
//listの末尾に要素を追加
list.push_back(10);
//listの末尾から要素を削除
list.pop_back();
//空ですか？
list.empty()



//キュー(待ち行列)
//定義
queue<int> a;
//追加
a.push(x);
//取る
a.pop();
//チェック
a.front()
//サイズ
a.size()
//空ですか
a.empty()



//優先度付きキュー※全部計算量がO(NlogN)あるので注意
// int 型の要素を持ち、最も小さい値を取り出す形の priority_queue を定義
priority_queue<int, vector<int>, greater<int>> Q1;
// double 型の要素を持ち、最も大きい値を取り出す形の priority_queueを定義
priority_queue<double, vector<double>, less<double>> Q2;
//追加
a.push(x);
//取る
a.pop();
//一番小さいの教えて下さい
a.top()
//サイズ
a.size()
//空ですか
a.empty()



//部分文字列
//添字3から5文字
s.substr(3,5)
//添字3から全部
s.substr(3)

//入れ替え
swap(a,b);



// int 型の番地に string 型の変数を記録する場合（2^31 要素の string型配列と同じような感じ）
map<int, string> mp;
for (auto itr =mp.begin(); itr != mp.end(); itr++) {
    //順番にマップを眺める。itr->firstでキー、itr->secondがバリュー
}

//ソート済みのaの中で初めてx以上になるインデックスを返す
lower_bound(all(a), x) - a

//next_permutation
do {
    //ここにパーテーションがくる
  } while (next_permutation(s.begin(), s.end()));

*/


Measured memory_bytes: 640
import sys
INF = 1 << 60
MOD = 10**9 + 7 # 998244353
sys.setrecursionlimit(2147483647)
input = lambda:sys.stdin.readline().rstrip()
def resolve():
    n, k = map(int, input().split())
    P = list(map(int, input().split()))
    P.sort()
    print(sum(P[:k]))
resolve()

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

int main()
{
	ll n,i,ans(0),a;
	cin>>n;
	for(i=1;i<=n;i++)
	{
		cin>>a;
		if(i%2==1 && a%2==1)
		{
			ans++;
		}
	}
	cout<<ans;
}


Measured memory_bytes: 3648
/* ex4-3
   Sagzar1993  */

#include <stdio.h>

int calcSnowDepth(int westHeight, int eastHeight); //プロトタイプ宣言

int main(void) {
    int westHeight, eastHeight; //２つの塔の埋もれていない部分の高さ
    int snowDepth; //求める雪の深さ

    scanf("%d %d", &westHeight, &eastHeight); //入力を受け取る

    snowDepth = calcSnowDepth(westHeight, eastHeight); //積雪の深さを計算

    printf("%d\n", snowDepth); //出力

    return 0;
}

int calcSnowDepth(int westHeight, int eastHeight){
    /*
    ２つの塔が西から数えてn, n+1(=eastTowerNum)番目とすると
    (n+1)(n+2)/2 - n(n+1)/2 = n+1
    またeastHeight - westHeight = (n+1)(n+2)/2 - n(n+1)/2
    */
    int eastTowerNum = eastHeight - westHeight;

    //１からeastTowerNumまでの和が東側の塔の高さ
    int eastTowerHeight = eastTowerNum * (eastTowerNum + 1) / 2;

    //塔の高さからその雪に埋もれていない部分の高さを引き、積雪の深さを求める
    int snowDepth = eastTowerHeight - eastHeight;

    return(snowDepth); //積雪の深さを返す
}

Measured memory_bytes: 128
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner input = new Scanner(System.in);
        Long N = input.nextLong();
        Long K = input.nextLong();
        long ans;

        if (N % K == 0) {
            ans = 0;
        } else {
            ans = ((N % K) <= (K / 2)) ? (N % K) : (K - (N % K));
        }
        System.out.println(ans);
    }
}


Measured memory_bytes: 21844
#if 0
date +%Y.%m.%d

题解先咕着。
#endif
#include <cstdio>
#include <queue>
#include <algorithm>
#define debug(...) fprintf(stderr, __VA_ARGS__)

typedef long long lolong;
inline int input() { int x; scanf("%d", &x); return x; }

const int maxn = 200005;
int a[maxn], b[maxn];

int n;
inline int &B(int x) {
	if(x < 1) return b[x + n];
	if(x > n) return b[x - n];
	return b[x];
}

int main() {
	n = input();
	for(int i = 1; i <= n; i ++)
		a[i] = input();
	std::queue<int> q;
	for(int i = 1; i <= n; i ++) {
		b[i] = input();
		if(b[i] > B(i - 1) and b[i] > B(i + 1))
			q.push(i);
	}
	lolong ans = 0;
	while(not q.empty()) {
		int p = q.front();
		q.pop();
		int sum = B(p - 1) + B(p + 1);
		int max = std::max(a[p], std::max(B(p - 1), B(p + 1)));
		int times = (b[p] - max + sum - 1) / sum;
		b[p] -= times * sum;
		ans += times;
		// debug("%d: %d\n", p, b[p]);
		if(b[p] < a[p]) {
			puts("-1");
			return 0;
		}
		if(B(p - 1) > B(p - 2) and B(p - 1) > b[p])
			q.push(p == 1 ? n : p - 1);
		if(B(p + 1) > B(p + 2) and B(p + 1) > b[p])
			q.push(p == n ? 1 : p + 1);
	}
	for(int i = 1; i <= n; i ++)
		if(b[i] != a[i]) {
			puts("-1");
			return 0;
		}
	printf("%lld\n", ans);
}


Measured memory_bytes: 3072
#include <functional>
#include <algorithm>
#include <iostream>
#include <vector>
#include <cstdio>
#include <stack>
#include <map>

using namespace std;

void solve();

int main() {
	solve();
}

// ============= actual code starts here =================

void solve() {
	int n, x, t;
	scanf("%d%d%d", &n, &x, &t);
	printf("%d\n", (n + x - 1) / x * t);
}

Measured memory_bytes: 3672
#include <stdio.h>

int maxnum(int, int ,int);

int main(){
    int a, b, c, k, ans, max, i;

    scanf("%d %d %d %d", &a, &b, &c, &k);

    max = maxnum(a, b, c);

    if(a==max)
        ans = b + c;
    else if(b==max)
        ans = a + c;
    else
        ans = a + b;

    for(i=0; i<k; i++){
        max *= 2;
    }

    ans += max;

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

    return 0;
}

int maxnum(int a, int b, int c){
    int max = a;

    if(max < b)
        max = b;
    if(max < c)
        max = c;
    
    return max;
}


Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
using lint = long long int;
using pint = pair<int, int>;
using plint = pair<lint, lint>;
struct fast_ios { fast_ios(){ cin.tie(0); ios::sync_with_stdio(false); cout << fixed << setprecision(20); }; } fast_ios_;

#define ALL(x) (x).begin(), (x).end()
#define FOR(i, begin, end) for(int i=(begin),i##_end_=(end);i<i##_end_;i++)
#define IFOR(i, begin, end) for(int i=(end)-1,i##_begin_=(begin);i>=i##_begin_;i--)
#define REP(i, n) FOR(i,0,n)
#define IREP(i, n) IFOR(i,0,n)


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

int main(){

    long long A;
    scanf("%lld",&A);
    long long P;
    scanf("%lld",&P);
    solve(A, P);
    return 0;
}



Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
using u32 = uint_fast32_t;
using i32 = int_fast32_t;
using u64 = uint_fast64_t;

struct Segtree {
	u32 n;
	vector<u32> data;
	u32 U = numeric_limits<u32>::min();
	Segtree(u32 N) : n(calc_n(N)), data(n*2, U) {}
	void set(u32 p, u32 v) {
		p += n;
		data[p] = v;
		while (p) {
			p /= 2;
			data[p] = max(data[p*2], data[p*2+1]);
		}
	}
	u32 get(u32 l, u32 r) {
		u32 res = U;
		for (l += n, r += n; l < r; l /= 2, r /= 2) {
			if (l & 1) res = max(res, data[l++]);
			if (r & 1) res = max(res, data[--r]);
		}
		return res;
	}
	u32 get(u32 p) {
		return data[p+n];
	}
private:
	u32 calc_n(u32 N) {
		u32 n = 1;
		while (n < N) n *= 2;
		return n;
	}
};

int main() {
	ios::sync_with_stdio(false);
	cin.tie(nullptr);
	u32 N;
	cin >> N;
	vector<i32> X(N), D(N);
	{
		vector<pair<i32, i32>> v;
		for (u32 i = 0; i < N; i++) {
			u32 a, b; cin >> a >> b;
			v.emplace_back(a, b);
		}
		sort(v.begin(), v.end());
		for (u32 i = 0; i < N; i++) {
			X[i] = v[i].first;
			D[i] = v[i].second;
		}
	}
	Segtree R(N);
	for (u32 l = N - 1; ~l; l--) {
		R.set(l, l);
		u32 r = lower_bound(X.begin() + l, X.end(), X[l] + D[l]) - X.begin();
		R.set(l, R.get(l, r));
	}
	vector<u64> dp(N+1);
	dp[N] = 1;
	for (u32 i = N - 1; ~i; i--) {
		dp[i] = dp[i+1] + dp[R.get(i)+1];
		dp[i] %= 998244353;
	}
	cout << dp[0] << endl;
}


Measured memory_bytes: 9456
#!python3.8
# -*- coding: utf-8 -*-
# abc168/abc168_b
import sys

s2nn = lambda s: [int(c) for c in s.split(' ')]
ss2nn = lambda ss: [int(s) for s in list(ss)]
ss2nnn = lambda ss: [s2nn(s) for s in list(ss)]
i2s = lambda: sys.stdin.readline().rstrip()
i2n = lambda: int(i2s())
i2nn = lambda: s2nn(i2s())
ii2ss = lambda n: [i2s() for _ in range(n)]
ii2nn = lambda n: ss2nn(ii2ss(n))
ii2nnn = lambda n: ss2nnn(ii2ss(n))

def main():
    K = i2n()
    S = i2s()
    if len(S) <= K:
        print(S)
    else:
        print(S[:K] + '...')
    return

main()


Measured memory_bytes: 9212
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (n); ++i)
using namespace std;
typedef pair<int, int> p;
typedef long long ll;
int main() {
  int m, k;
  cin >> m >> k;
  if (k >= pow(2, m)) {
    cout << -1 << endl;
    return 0;
  }
  if (m == 0) {
    if (k == 0) {
      cout << 0 << endl << 0 << endl;
      return 0;
    } else {
      cout << -1 << endl;
      return 0;
    }
  }
  if (m == 1) {
    if (k == 0) {
      cout << 0 << endl << 0 << endl << 1 << endl << 1 << endl;
      return 0;
    } else {
      cout << -1 << endl;
      return 0;
    }
  }
  vector<int> l(pow(2, m) - 1);
  vector<int> r(pow(2, m) - 1);
  vector<int> ans(pow(2, m + 1));
  int id = 0;
  rep(i, pow(2, m)) {
    if (i == k) continue;
    l[id] = i;
    id++;
  }
  id = 0;
  rep(i, pow(2, m)) {
    if (pow(2, m) - 1 - i == k) continue;
    r[id] = pow(2, m) - 1 - i;
    id++;
  }
  rep(i, pow(2, m) - 1) ans[i] = l[i];
  ans[pow(2, m) - 1] = k;
  rep(i, pow(2, m) - 1) ans[i + pow(2, m)] = r[i];
  ans[pow(2, m + 1) - 1] = k;
  rep(i, pow(2, m + 1)) cout << ans[i] << endl;
  return 0;
}

Measured memory_bytes: 5784
#[allow(dead_code)]
use std::collections::HashSet;

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()
}

#[allow(dead_code)]
fn read_vec<T: std::str::FromStr>() -> Vec<T> {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).ok();
    s.trim()
        .split_whitespace()
        .map(|e| e.parse().ok().unwrap())
        .collect()
}

fn main() {
   
    let nkq = read_vec::<i32>();
    let n = nkq[0] as usize;
    let k = nkq[1];
    let q = nkq[2];

    let mut win:Vec<usize> = vec![0; n];
    let mut p:Vec<i32> = vec![k -q; n];

    for i in 0..q {
        let winner = read::<usize>();
        win[winner - 1] += 1;
    }


    solve(n, &win, &mut p);
    //rintln!("XXX {:?}", p);
    for x in p {
        if x > 0 {
            println!("Yes");
        } else {
            println!("No");
        }
    }
}

fn solve(n: usize, win: &[usize], p: &mut [i32]) {
    for i in 0..n {
        p[i] += win[i] as i32;
    }
}


Measured memory_bytes: 4732
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll, ll> P;
typedef pair<ll, P> P3;
typedef pair<P ,P> PP;
constexpr ll MOD = ll(1e9) + 7;
constexpr int IINF = INT_MAX;
constexpr ll LLINF = LLONG_MAX;
constexpr int MAX_N = int(2e5) + 5;
constexpr double EPS = 1e-8;
constexpr int di[] = {0, 1, 0, -1}, dj[] = {1, 0, -1, 0};
#define REP(i, n) for (int i = 0; i < n; i++)
#define REPR(i, n) for (int i = n; i >= 0; i--)
#define SORT(v) sort((v).begin(), (v).end())
#define SORTR(v) sort((v).rbegin(), (v).rend())
#define ALL(v) (v).begin(), (v).end()

int main() {
    ll n, k;
    cin >> n >> k;
    vector<ll> a(n*2), nxt(n*2), len(n*2);
    vector<vector<int> > pos(MAX_N);
    for(int i=0;i<n;i++){
        cin >> a[i];
        a[i+n] = a[i];
        pos[a[i]].push_back(i);
        pos[a[i]].push_back(i+n);
    }
    for(int i=0;i<MAX_N;i++){
        sort(pos[i].begin(), pos[i].end());
    }
    for(int id=0;id!=n;){
        nxt[id] = *upper_bound(pos[a[id]].begin(), pos[a[id]].end(), id)+1;
        ll l = nxt[id] - id;
        while(nxt[id] > n) nxt[id] -= n;
        len[nxt[id]] = len[id]+l;
        id = nxt[id];
    }
    ll m = (k*n) % len[n];
    int bg = 0;
    while(m >= len[nxt[bg]]){
        bg = nxt[bg];
    }
    m -= len[bg];
    vector<int> s;
    vector<bool> used(MAX_N, false);
    for(int i=0,j=bg;i<m;i++,j=(j+1)%n){
        if(used[a[j]]){
            while(s.back()!=a[j]){
                used[s.back()] = false;
                s.pop_back();
            }
            used[a[j]] = false;
            s.pop_back();
        }
        else{
            used[a[j]] = true;
            s.push_back(a[j]);
        }
    }
    for(int i=0;i<s.size();i++){
        cout << s[i] << " \n"[i==int(s.size())-1];
    }
    return 0;
}


Measured memory_bytes: 22772
def min(a, b)
  if a < b
    return a
  else
    b
  end
end

A, B = gets.split.map(&:to_i)
div = min(A, B)
qa = A
qb = B
while 1 < div
  if (A % div == 0) && (B % div == 0)
    qa = A / div 
    qb = B / div
    puts div * qa * qb
    exit
  else
    div -= 1
  end
end
puts A * B



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

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

    int N;
    cin >> N;
    vector<vector<int>> dist(N, vector<int>(N));
    REP(i, N) {
        REP(j, N) {
            dist[i][j] = min(min(i, N - i - 1), min(j, N - j - 1));
        }
    }
    vector<vector<bool>> empty(N, vector<bool>(N));
    vector<int> di = {1, 0, -1, 0};
    vector<int> dj = {0, 1, 0, -1};
    int ans = 0;
    REP(t, N*N) {
        int P;
        cin >> P;
        P--;
        int y = P / N, x = P % N;
        ans += dist[y][x];
        empty[y][x] = true;
        queue<pair<int, int>> q;
        q.push({y, x});
        while (!q.empty()) {
            int i = q.front().first, j = q.front().second;
            q.pop();
            REP(k, 4) {
                int ni = i + di[k], nj = j + dj[k];
                if (0 <= ni && ni < N && 0 <= nj && nj < N) {
                    if (empty[i][j] && dist[ni][nj] > dist[i][j]) {
                        dist[ni][nj] = dist[i][j];
                        q.push({ni, nj});
                    } else if (!empty[i][j] && dist[ni][nj] > dist[i][j] + 1) {
                        dist[ni][nj] = dist[i][j] + 1;
                        q.push({ni, nj});
                    }
                }
            }
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 4652
#include <iostream>
#include <string>
#include <cstring>
#include <algorithm>
#include <functional>
#include <cmath>
#include <set>
#include <queue>
#include <deque>
#include <vector>
#include <climits>
#include <sstream>
#include <iomanip>
#include <map>
#include <stack>
using namespace std;
typedef unsigned long long ull;
typedef long long ll;

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

	vector<vector<vector<vector<ll>>>> dp(N + 1, vector<vector<vector<ll>>>(4, vector<vector<ll>>(4, vector<ll>(4))));
	dp[0][3][3][3] = 1;
	auto mod = (ll)1e9 + 7;

	for (auto i = 0; i < N; ++i)
	{
		for (auto j = 0; j < 4; ++j)
		{
			for (auto k = 0; k < 4; ++k)
			{
				for (auto l = 0; l < 4; ++l)
				{
					for (auto m = 0; m < 4; ++m)
					{
						if (m == 2)
						{
							if (l == 1 && k == 0)
							{
								continue;
							}
							if (l == 0 && k == 1)
							{
								continue;
							}
							if (k == 1 && j == 0)
							{
								continue;
							}
							if (l == 1 && j == 0)
							{
								continue;
							}
						}
						else if (m == 1 && l == 2 && k == 0)
						{
							continue;
						}
						dp[i + 1][m][l][k] += dp[i][l][k][j];
						dp[i + 1][m][l][k] %= mod;
					}
				}
			}
		}
	}

	auto ans = 0ll;
	for (auto j = 0; j < 4; ++j)
	{
		for (auto k = 0; k < 4; ++k)
		{
			for (auto l = 0; l < 4; ++l)
			{
				ans = (ans + dp[N][j][k][l]) % mod;
			}
		}
	}
	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 384
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define int ll
inline ll read(){
	ll res=0,f=1;
	char ch=getchar();
	while(ch<'0'||ch>'9'){if(ch=='-')f=-f;ch=getchar();}
	while(ch>='0'&&ch<='9'){res=(res<<3)+(res<<1)+ch-'0';ch=getchar();}
	return res*f;
}
void write(ll x){
	if(x<0) putchar('-'),x=-x;
	if(x>9) write(x/10);
	putchar(x%10|'0');
}
const int N=2e5+7;
int n;
int a[N];
int l,r,ans,sum,Xor;
int Sum[N],XOr[N];
signed main(){
	n=read();
	for(int i=1;i<=n;i++)a[i]=read();
//	Sum[i]=Sum[i-1]+a[i],XOr[i]=XOr[i-1]^a[i];
//	int res=0;
//	for(int i=1;i<=n;i++){
//		int ans2=0;
//		for(int j=i;j<=n;j++){
//			if(Sum[j]-Sum[i-1]==(XOr[j]^XOr[i-1])) ans2++;
//			if(Sum[j]-Sum[i-1]==(XOr[j]^XOr[i-1]) )cout<<i<<" "<<j<<" "<<endl;
//		}
//		res+=ans2;
////		cout<<ans2<<endl;
//	}
//	cout<<res<<endl;
	for(int i=1;i<=n;i++){
		l=i;
		if(r==l-1) sum=0,Xor=0;
		else sum-=a[i-1],Xor^=a[i-1];
		while(r<=n){
			r++;
			if(sum+a[r]!=(Xor^a[r])){
				r--;break;
			} 
			sum+=a[r],Xor=sum;
		}
		if(r>n) r--;
		ans+=(r-l+1);
	}
	cout<<ans<<endl;
}


Measured memory_bytes: 2944
#include <iostream>
#include <vector>
#include <string>

using namespace std;

int main() {
    string s;
    cin >> s;
    vector<int> x(s.size() + 1);
    for (int i = 0; i < s.size(); i++)x[i + 1] = x[i] + (s[i] == 'A' ? 1 : 2);
    string t;
    cin >> t;
    vector<int> y(t.size() + 1);
    for (int i = 0; i < t.size(); i++)y[i + 1] = y[i] + (t[i] == 'A' ? 1 : 2);

    int q;
    cin >> q;
    for (int i = 0; i < q; i++) {
        int a, b, c, d;
        cin >> a >> b >> c >> d;
        cout << (((x[b] - x[a - 1]) - (y[d] - y[c - 1])) % 3 == 0 ? "YES" : "NO") << endl;
    }
    return 0;
}

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

int main(){
  int N,W;
  cin >> N >> W;
  vector<int> w(N),v(N);
  for (int i = 0; i < N; i++)
  {
    cin >> w[i] >> v[i];
  }
  vector<vector<long long>> dp(N+1,vector<long long>(W+1,0));
  for (int i = 1; i <= N; i++)
  {
    for (int j = 0; j <= W; j++)
    {
      if(j>=w[i-1]){
        dp[i][j] = max(dp[i-1][j],dp[i-1][j-w[i-1]]+v[i-1]);
      }
      else dp[i][j] = dp[i-1][j];
    }
  }
  cout << dp[N][W] << endl;  
}

Measured memory_bytes: 80256
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <cstdio>
#include <cstring>
#include <cmath>
using namespace std;
using ll = long long;

struct Graph {
    struct Vertex { int n, d; };
    struct Edge { int i, n; };
    Graph(int n, int m) : v(n, { -1, -1 }), e(m), n(n), m(0) {}
    void add_edge(int i, int j) {
        e[m] = { j, v[i].n };
        v[i].n = m;
        m++;
    }
    int dfs(int i) {
        if (v[i].d >= 0) return v[i].d;
        if (v[i].d == -2) {
            cout << -1 << endl;
            exit(0);
        }
        v[i].d = -2;
        int d = 0;
        for (int j = v[i].n; j >= 0; j = e[j].n) {
            Edge &o = e[j];
            d = max(d, dfs(o.i) + 1);
        }
        return v[i].d = d;
    }
    vector<Vertex> v;
    vector<Edge> e;
    int n, m;
};

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

    int n;
    cin >> n;

    auto f = [&](int x, int y) {
        if (x < y) swap(x, y);
        return x * (x - 1) / 2 + y;
    };

    Graph g(n * (n - 1) / 2, n * (n - 2));
    for (int i = 0; i < n; i++) {
        int p;
        for (int j = 0; j < n - 1; j++) {
            int a;
            cin >> a;
            a--;

            if (j > 0) {
                g.add_edge(f(i, p), f(i, a));
            }
            p = a;
        }
    }

    int r = -1;
    for (int i = 0; i < g.n; i++) {
        r = max(r, g.dfs(i));
    }

    cout << r + 1 << endl;

    return 0;
}

Measured memory_bytes: 12032
// https://atcoder.jp/contests/abc162/tasks/abc162_b
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define REP(i, n) FOR(i, 0, n)
#define REPR(i, n) for (int i = n - 1; i >= 0; i--)
#define FOR(i, s, n) for (int i = (s), i##_len = (n); i < i##_len; ++i)
#define ALL(obj) (obj).begin(), (obj).end()
#define ALLR(obj) (obj).rbegin(), (obj).rend()
#define DIV(a, b) ((a - 1) / b + 1)

signed main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    int N;
    cin >> N;
    int sum = 0;
    FOR(i, 1, N + 1) {
        if (i % 3 != 0 && i % 5 != 0) {
            sum += i;
        }
    }
    cout << sum << endl;
    return 0;
}


Measured memory_bytes: 3652
#include <stdio.h>

int main(void)
{
	int i;
	int n, a;
	long long min, max, sum;
	
	scanf("%d", &n);
	
	scanf("%d", &a);
	max = sum = min = a;
	
	for (i = 1; i < n; i++){
		scanf("%d", &a);
		if (max < a){
			max = a;
		}
		if (min > a){
			min = a;
		}
		sum += a;
	}
	
	printf("%ld %ld %ld\n", min, max, sum);
	
	return (0);
}



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

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

    bool check1 = s[0] == s[1] && s[1] == s[2];
    bool check2 = s[1] == s[2] && s[2] == s[3];

    cout << ((check1 || check2) ? "Yes" : "No") << "\n";
}

Measured memory_bytes: 3576
#include<iostream>
#include<algorithm>
#include<cmath>
#include<cstdio>
#include<string>
#include<vector>
#include<list>
#include<set>
#include<cctype>
#define ld long double
#define ll long long int
#define ull unsigned long long int
using namespace std;
template<class T> inline bool chmax(T& a,T b){if(a<b){a=b;return 1;}return 0;}
template<class T> inline bool chmin(T& a,T b){if(a>b){a=b;return 1;}return 0;}
const long long INF=1LL<<60;
//set<int>::iterator it;

int main(void){
	ios::sync_with_stdio(false); cin.tie(0);
	
	int n,i;
	set<char> s;
	char a;
	cin>>n;
	for(i=0;i<n;i++){
		cin>>a;
		s.insert(a);
	}
	set<char>::iterator it;
	int ans=0;
	for(it=s.begin();it!=s.end();it++)ans++;
//	ans=int(s.end())-int(s.begin());
	if(ans==4)cout<<"Four"<<endl;
	else cout<<"Three"<<endl;
	
	
	
	return 0;
}

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


/// File input & output /////
#define fRead(x)        freopen("x.txt","r",stdin)
#define fWrite(x)       freopen ("x.txt","w",stdout)

#define mt              make_tuple
#define ld              long double
#define ll              long long
#define ull             unsigned long long
#define ff              first
#define ss              second
#define pb              push_back
#define INF             2e16
#define PI              acos(-1.0)
#define mp              make_pair
#define pii             pair<int,int>
#define pll             pair<LL,LL>


#define min3(a,b,c)     min(a,min(b,c))
#define max3(a,b,c)     max(a,max(b,c))
#define min4(a,b,c,d)   min(a,min(b,min(c,d)))
#define max4(a,b,c,d)   max(a,max(b,max(c,d)))
#define SQR(a)          ((a)*(a))
#define FOR(i,a,b)      for(int i=a;i<=b;i++)
#define ROF(i,a,b)      for(int i=a;i>=b;i--)
#define REP(i,b)        for(int i=0;i<b;i++)
#define MEM(a,x)        memset(a,x,sizeof(a))
#define ABS(x)          ((x)<0?-(x):(x))

#define SORT(v)         sort(v.begin(),v.end())
#define REV(v)          reverse(v.begin(),v.end())


#define FASTIO        ios_base::sync_with_stdio(0);cin.tie(nullptr);




///..................Sort by second element in a pair in decending order............. ///
bool SortbySecDesc(const pair<long long,long long > &a, const pair<long long,long long > &b)
{
    return a.second>b.second;
}

///.........................first element of pair in descending order..........................//////
bool sortinrev(const pair<int,int> &a,
               const pair<int,int> &b)
{
    return (a.first > b.first);
}



///.............................................................TEMPLATE................................................./////


//long long  Prime[3000000],nPrime;
//long long  mark[10000002];
//
//void seive(long long int n)
//{
//	long long int i,j,limit=sqrt(n*1.0)+2;
//	mark[1]=1;
//	for(i=4; i<=n ;i+=2)
//	mark[i]=1;
//	Prime[nPrime++]=2;
//	for(i=3; i<=n; i+=2)
//	{
//		if(!mark[i])
//		{
//			Prime[nPrime++]=i;
//			if(i<=limit)
//			{
//				for(j=i*i; j<=n ;j+=i*2)
//				{
//					mark[j]=1;
//				}
//			}
//		}
//	}
//}

int main()
{
    FASTIO;

    ll x, y;

    cin >> x >> y;

    for(int i=0; i<=100; i++)
    {
        for(int j=0; j<=100; j++)
        {
            if(i+j==x)
            {

                if(((2*i)+(4*j))==y)
                {
                    cout << "Yes" << endl;

                    return 0;
                }
            }
        }
    }

    cout << "No" << endl;





    return 0;
}


Measured memory_bytes: 3624
#include <iostream>
#include <string>

std::string Shuffle(const std::string& s, int h)
{
    // int l = s.length();
    // return s.substr(h, l - h) + s.substr(0, h);
    std::string result;
    for(int i = h; i < s.size(); i++){
        result.push_back(s[i]);
    }
    for(int i = 0; i < h; i++){
        result.push_back(s[i]);
    }
    return result;
}
std::string Shuffle(std::string s, std::istream& in)
{
    int m;
    in >> m;
    for(int i = 0; i < m; ++i){
        int h;
        in >> h;
        s = Shuffle(s, h);
    }
    return s;
}

int main()
{
    std::string s;
    std::cin >> s;
    for(; s != "-"; std::cin >> s){
        std::cout << Shuffle(s, std::cin) << std::endl;
    }
    return 0;
}

Measured memory_bytes: 3112
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<n;++i)
#define all(x) (x).begin(),(x).end()
using namespace std;
const int INF=1145141919,MOD=1e9+7;
const int64_t LINF=8931145141919364364,LMOD=998244353;
// const int dy[]={0,-1,0,1,1,-1,-1,1};
// const int dx[]={1,0,-1,0,1,1,-1,-1};

int main() {
	int h, w; cin >> h >> w;
	int a, b; cin >> a >> b;
	for(int y = 0; y < h; ++y) {
		if(y < b) {
			for(int x = 0; x < w; ++x) {
				if(x < a) cout << '0';
				else cout << '1';
			}
		} else {
			for(int x = 0; x < w; ++x) {
				if(x < a) cout << '1';
				else cout << '0';
			}
		}
		cout << endl;
	}
	return 0;
}

Measured memory_bytes: 1280
#include<stdio.h>
int main(){
	int n,m,c;
	int i,y,p=0,an=0;
	int B[200],A[100][100];
	scanf("%d %d %d",&n,&m,&c);
	for(i=0;i<m;i++){
		scanf("%d",&B[i]);
	}
	i=0;
	for(y=0;y<n;y++){
		for(i=0;i<m;i++){
			scanf("%d",&A[y][i]);
		}
	}
	y=0;i=0;
	while(y<n){
		for(i=0;i<m;i++){
			an=an+A[y][i]*B[i];
		}
		if(an+c>0){
			p=p+1;
		}
		an=0;
		y++;
	}
	printf("%d",p);
	
}


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

#define F first
#define S second
#define MP make_pair
#define pb push_back
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define LCM(a, b) (a) / __gcd((a), (b)) * (b)
#define CEIL(a, b) (a)/(b)+(((a)%(b))?1:0)
#define log_2(a) (log((a)) / log(2))
#define ln '\n'

using namespace std;
using LL = long long;
using ldouble = long double;
using P = pair<int, int>;
using LP = pair<LL, LL>;

static const int INF = INT_MAX;
static const LL LINF = LLONG_MAX;
static const int MIN = INT_MIN;
static const LL LMIN = LLONG_MIN;
static const int MOD = 1e9 + 7;
static const int SIZE = 200005;

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

vector<LL> Div(LL n) {
    vector<LL> ret;
    for(LL i = 1; i * i <= n; ++i) {
        if(n % i == 0) {
            ret.pb(i);
            if(i * i != n) ret.pb(n / i);
        }
    }
    sort(all(ret));
    return ret;
}

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

    int N;
    cin >> N;
    vector<int> v(N);
    for(int i = 0; i < N; ++i) cin >> v[i];

    int c = 0;
    for(int i = 0; i < N; ++i) {
        for(int j = i + 1; j < N; ++j) {
            for(int k = j + 1; k < N; ++k) {
                if(v[i] == v[j] || v[j] == v[k] || v[i] == v[k]) continue;
                if(v[i] + v[j] > v[k] && v[i] + v[k] > v[j] && v[j] + v[k] > v[i]) ++c;
            }
        }
    }
    cout << c << endl;
    return 0;
}



Measured memory_bytes: 3660
#include<iostream>
#include<vector>
#include<algorithm>
#include<string.h>
#include<complex>
#include<set>
using namespace std;
typedef long long int llint;
#define rep(i,n) for(int i=0;i<n;i++)
int main() {
	int n;
	cin >> n;
	int ans = 1;
	while (ans <= n / 2) {
		ans *= 2;
	}
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define int lint
typedef long long lint;
typedef pair<int,int> P;
const int    INF=(int)1e9;
const int    MOD=(int)1e9+7;
const double EPS=(double)1e-10;
struct Accelerate_Cin{
    Accelerate_Cin(){
        cin.tie(0); ios::sync_with_stdio(0);cout<<fixed<<setprecision(20);
    };
};

signed main(){
  string s;
  cin>>s;
  int ans=700;
  for(int t=0;t<3;t++){
    if(s[t]=='o')ans+=100;
  }

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


Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<algorithm>
#include<math.h>

using namespace std;

int main(){
  int x; cin >> x;
  if(x >= 2000){
    cout << '1' << endl;
  }
  else if(x < 100){
    cout << '0' << endl;
  }
  else{
    if((x/100)*5 < (x%100)) cout << '0' << endl;
    else cout << '1' << endl;
  }
}


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

int main() {
  char a[8];
  scanf("%s", a);

  char s1[8] = "SSS";
  char s2[8] = "SRR";
  char s3[8] = "RRS";
  char s4[8] = "RRR";

  if(strcmp(a, s1) == 0) printf("%d\n", 0);
  else if(strcmp(s2, a) == 0 || strcmp(s3, a) == 0) printf("%d\n", 2);
  else if(strcmp(s4, a) == 0) printf("%d\n", 3);
  else printf("%d\n", 1);

  return 0;
}

Measured memory_bytes: 1652
#include <bits/stdc++.h>
#include <iostream>
#include <algorithm>
#include <vector>
#include <cmath>
#include <string>
#include <functional>
#include <queue>
#include <map>
#define REP(i,n) for(int i=0;i<n;i++)
using namespace std;
typedef long long ll;
typedef pair<ll, ll> l_l;
typedef pair<int, int> i_i;
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;
}
const int INF = 100000000;

int main(){
  int n;
  cin >> n;
  vector<int> a(n);
  vector<ll> cnt(INF);
  ll ans; 
  for(int i = 1; i <= n; i++){
    cin >> a[i];
    ans += cnt[a[i]];
    cnt[a[i]]++;
  }
  for(int i = 1; i <=n; i++){
    ll t = ans-cnt[a[i]]+1;
    cout << t << endl;
  }
  return 0;
}

Measured memory_bytes: 784640
s = list(map(int, list(input())))
res = 7 - s[0]
if (s[1] + s[2] + s[3] == res):
  print(str(s[0]) + '+' + str(s[1]) + '+' + str(s[2]) + '+' + str(s[3]) + '=' + '7')
elif (s[1] + s[2] - s[3] == res):
  print(str(s[0]) + '+' + str(s[1]) + '+' + str(s[2]) + '-' + str(s[3]) + '=' + '7')
elif (s[1] - s[2] + s[3] == res):
  print(str(s[0]) + '+' + str(s[1]) + '-' + str(s[2]) + '+' + str(s[3]) + '=' + '7')
elif (s[1] - s[2] - s[3] == res):
  print(str(s[0]) + '+' + str(s[1]) + '-' + str(s[2]) + '-' + str(s[3]) + '=' + '7')
elif (-s[1] + s[2] + s[3] == res):
  print(str(-s[0]) + '-' + str(s[1]) + '+' + str(s[2]) + '+' + str(s[3]) + '=' + '7')
elif (-s[1] + s[2] - s[3] == res):
  print(str(s[0]) + '-' + str(s[1]) + '+' + str(s[2]) + '-' + str(s[3]) + '=' + '7')
elif (-s[1] - s[2] + s[3] == res):
  print(str(s[0]) + '-' + str(s[1]) + '-' + str(s[2]) + '+' + str(s[3]) + '=' + '7')
elif (-s[1] - s[2] - s[3] == res):
  print(str(s[0]) + '-' + str(s[1]) + '-' + str(s[2]) + '-' + str(s[3]) + '=' + '7')


Measured memory_bytes: 38428
Q, H, S, D = map(int, input().split())
N = int(input())

PS = [[Q * 8, 0.25], [H * 4, 0.5], [S * 2, 1], [D, 2]]

PS.sort(key=lambda x: x[0])


R = N
ans = 0
for i in range (4):
    if R == 0:
        break
    elif R >= PS[i][1]:
        ans += int(PS[i][0] * PS[i][1] // 2 * (R // PS[i][1]))
        R = R % PS[i][1]

print(ans)

Measured memory_bytes: 3188
(defun func(n x)
  (if (> n 0)
	(if (eq (1+ x) (read))
	  (func (1- n) (1+ x))
	  (func (1- n) x))
	x))

(let* ((n (read)) (s (func n 0)))
  (princ (if (eq s 0) -1 (- n s))))


Measured memory_bytes: 57704
#include <iostream>
#include <string>
#include <math.h>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
using namespace std;

typedef long long ll;
#define rep(i, n) for(int i = 0; i < n; i++)

int main(){
    string s;
    cin >> s;
    int len = (int)s.size();
    int mn = 10000;
    rep(j, len){
        char mx_char = s[j];
        int cnt = 0;
        string T = s;
        while(1){
            bool is = true;
            int size = (int)T.size();
            rep(i, size) if(T[i] != mx_char) is = false;
            if(is) break;
            cnt++;
            string t;
            rep(i, size-1){
                if(T[i] == mx_char || T[i+1] == mx_char){
                    t.push_back(mx_char);
                }else{
                    t.push_back(T[i+1]);
                }
            }
            T = t;
        }
        mn = min(mn, cnt);
    }
    cout << mn << endl;
    return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<queue>

#define MAX 1024
#define fr first
#define sc second
#define mp make_pair

using namespace std;

typedef pair<int,int> pi;

void MakeCountMap(int h, int w, int M[][MAX],int cnt[][MAX]){
  queue<pi> qp;
  bool vis[MAX][MAX]={{false,},};
  qp.push( mp(0,0) );
  while(!qp.empty()){
    pi now=qp.front();
    qp.pop();
    if(now.fr==h||now.sc==w)continue;
    int flr=cnt[now.fr][now.sc]/2;
    int cel=cnt[now.fr][now.sc]%2==0?flr:flr+1;
    cnt[now.fr+1][now.sc]+=M[now.fr][now.sc]==1?flr:cel;
    cnt[now.fr][now.sc+1]+=M[now.fr][now.sc]==1?cel:flr;
    if(!vis[now.fr+1][now.sc]){
      vis[now.fr+1][now.sc]=true;
      qp.push(mp(now.fr+1,now.sc));
    }
    if(!vis[now.fr][now.sc+1]){
      vis[now.fr][now.sc+1]=true;
      qp.push(mp(now.fr,now.sc+1));
    }
  }
}

int main()
{
  while(true){
    static int M[MAX][MAX];
    static int cnt[MAX][MAX];
    int h,w,n;
    cin >> h >> w >> n;
    
    if( h == 0 && w == 0 && n == 0 ) break;
    
    for(int i = 0; i < h; ++i){
      for(int j = 0; j < w; ++j){
	cin >> M[i][j];
	cnt[i][j] = 0;
      }
    }
    cnt[0][0] = n;

    MakeCountMap(h,w,M,cnt);

    /*
    for(int i = 0; i < h; ++i){
      for(int j = 0; j < w; ++j){
	cout << cnt[i][j] << ' ';
      }
      cout << endl;
    }
    cout << endl;
    */

    int nowi=0;
    int nowj=0;
    while(nowi<h&&nowj<w){
      if(cnt[nowi][nowj]%2==0){
	M[nowi][nowj]=M[nowi][nowj]==1?0:1;
      }
      if(M[nowi][nowj]){
	nowj++;
      }else{
	nowi++;
      }
    }
    cout<<1+nowi<<' '<<1+nowj<<endl;

  }
  return 0;
}

Measured memory_bytes: 9952
#include <iostream>
#include <cstdio>
#include <algorithm>
using namespace std;

int main() {
  string s;
  cin >> s;
  string t;
  cin >> t;
  sort(s.begin(),s.end());
  sort(t.rbegin(),t.rend());
  if (s<t) {
    printf("Yes\n");
  } else {
    printf("No\n");
  }
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main() {
    int n;
    cin>>n;
    string a;
    cin>>a;
    
    for (int i=0;i<a.length();i++)
    {
      
        a[i]=char (a[i]+n);
      	if (a[i]>char(90))
          a[i]=char(a[i]-26);
        cout<<a[i];
      	
    }
    
    
    
}

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

using namespace std;

struct prze
{
    int l, p;
};

int main()
{
    ios_base::sync_with_stdio(0);
    vector<prze> P;
    for (int i = 0; i < 8; ++i)
        P.push_back({i * 400, (i + 1) * 400 - 1});
    ++P[0].l;
    int mini, maxi;
    int inne = 0;
    vector<int> wyst(8, 0);
    int n;
    cin >> n;
    for (int i = 0; i < n; ++i)
    {
        int a;
        cin >> a;
        for (int j = 0; j < 8; ++j)
            if (a >= P[j].l && a <= P[j].p)
                ++wyst[j];
        if (a >= 3200)
            ++inne;
    }
    int rozne = 0;
    for (int i = 0; i < 8; ++i)
        if (wyst[i] != 0)
            ++rozne;
    if (rozne != 0)
        mini = rozne;
    else
        mini = 1;
    maxi = rozne + inne;
    cout << mini << " " << maxi;
    return 0;
}


Measured memory_bytes: 256
import sys

readline = sys.stdin.readline
MOD = 10 ** 9 + 7
INF = float('INF')
sys.setrecursionlimit(10 ** 5)


def main():
    import bisect

    n, k = map(int, readline().split())
    a = list(map(int, readline().split()))
    a.sort()

    neg = bisect.bisect_left(a, 0)
    zer = bisect.bisect_right(a, 0) - neg
    pos = n - (neg + zer)

    a_neg = a[:neg]
    a_pos = a[-pos:] if pos > 0 else []
    a_pos.sort(reverse=True)

    ans = 0
    flag = False
    
    if k == n:
        ans = 1
        for x in a:
            ans *= x
            ans %= MOD
        print(ans)
        sys.exit()

    if k % 2 == 0:
        a2 = []
        for i in range(0, pos - 1, 2):
            a2.append(a_pos[i] * a_pos[i + 1])
        for i in range(0, neg - 1, 2):
            a2.append(a_neg[i] * a_neg[i + 1])
        a2.sort(reverse=True)
        if len(a2) * 2 >= k:
            flag = True
            ans = 1
            for i in range(k // 2):
                ans *= a2[i]
                ans %= MOD
    else:
        a2 = []
        for i in range(1, pos - 1, 2):
            a2.append(a_pos[i] * a_pos[i + 1])
        for i in range(0, neg - 1, 2):
            a2.append(a_neg[i] * a_neg[i + 1])
        a2.sort(reverse=True)
        if pos > 0 and len(a2) * 2 + 1 >= k:
            flag = True
            ans = a_pos[0]
            for i in range(k // 2):
                ans *= a2[i]
                ans %= MOD

    if not flag:
        if zer > 0:
            ans = 0
        elif k % 2 == 0:
            b2 = []
            a_pos.sort()
            a_neg.sort(reverse=True)

            for i in range(1, neg - 1, 2):
                b2.append(a_neg[i] * a_neg[i + 1])
            for i in range(1, pos - 1, 2):
                b2.append(a_pos[i] * a_pos[i + 1])
            b2.sort()
            if len(b2) * 2 + 2 >= k:
                ans = a_pos[0] * a_neg[0]
                for i in range(k // 2):
                    ans *= b2[i]
                    ans %= MOD
        else:
            b2 = []
            a_pos.sort()
            a_neg.sort(reverse=True)
            for i in range(1, neg - 1, 2):
                b2.append(a_neg[i] * a_neg[i + 1])
            for i in range(0, pos - 1, 2):
                b2.append(a_pos[i] * a_pos[i + 1])
            b2.sort()
            if neg > 0 and len(b2) * 2 + 1 >= k:
                ans = a_neg[0]
                for i in range(k // 2):
                    ans *= b2[i]
                    ans %= MOD

    print(ans)

if __name__ == '__main__':
    main()


Measured memory_bytes: 96572
#include<iostream>
#include<vector>
#include<stdlib.h>
#include<time.h>
#include<math.h>
#include<string.h>
#include<algorithm>
#include<queue>
#include<map>
#include<iomanip>

using namespace std;

long long int euqlid( int a, int b ){
 long long int temp;
 if(a>b){
  temp=a;
  a=b;
  b=temp;
 }

 if(a<=0)return b;
 return euqlid(a,b%a);
}


int main(void){
 int n,m;
 vector<int> A;
 long long int ans=10000000000;

 cin>>n;
 for(int i=0; i<n; i++){
  cin>>m;
  A.push_back(m);
 }
 ans=A[0];
 for(int i=1; i<n; i++){
  ans=euqlid(ans,A[i]);
 }
 cout<<ans<<endl;
 return 0;
}


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

x = [0 for _ in range(n)]
y = [0 for _ in range(n)]
for i in range(n):
    x[i], y[i] = map(int, input().split())

min_x = min(x)
min_y = min(y)
for i in range(n):
    x[i] -= min_x
    y[i] -= min_y

sx = sorted(x)
sy = sorted(y)

if n == k:
    print(sx[n - 1] * sy[n - 1])
    exit()

d = [[0 for _ in range(n + 1)] for _ in range(n + 1)]
for i in range(n):
    d[sx.index(x[i]) + 1][sy.index(y[i]) + 1] = 1

for i in range(n + 1):
    for j in range(1, n + 1):
        d[i][j] += d[i][j - 1]

for i in range(n + 1):
    for j in range(1, n + 1):
        d[j][i] += d[j - 1][i]

#sx = [0] + sx
#sy = [0] + sy

a = 0
b = 1
ans = sx[n - 1] * sy[n - 1]
temp = 0
for p in range(n):
    for q in range(p + 1, n):
        for a in range(n):
            for b in range(a + 1, n):
                count = 0
                if d[b + 1][q + 1] - d[b + 1][p] - d[a][q + 1] + d[a][p] >= k:
                    ans = min(ans, (sx[b] - sx[a]) * (sy[q] - sy[p]))

print(ans)

Measured memory_bytes: 3188
#include <bits/stdc++.h>
using namespace std;
#define FAST_IO                       \
    ios_base::sync_with_stdio(false); \
    cin.tie(NULL);                    \
    cout.tie(NULL);
#define watch(x) cout << (#x) << " is: " << (x) << endl
#define vw(v)                        \
    cout << endl                     \
         << endl                     \
         << (#v) << " is: " << endl; \
    for (ll B : (v))                 \
    {                                \
        cout << B << " ";            \
    }                                \
    cout << endl
#define check(x) cout << "here " << (x) << "?" << endl
#define rep(i, a, b) for (long long i = (a); i < (b); i++)
#define per(i, a) for (long long i = (a - 1); i >= 0; i--)
#define all(x) (x).begin(), (x).end()
#define rv(x) (x).rbegin(), (x).rend()
#define pb push_back
typedef long long ll;
ll const MAX = 2147483647, REALMAX = 9223372036854775806;
// ll const N = ;

int main()
{
    FAST_IO
    ll n, sum = 0;
    string s;
    cin >> n >> s;
    rep(i, 2, n) if (s[i - 2] == 'A' && s[i - 1] == 'B' && s[i] == 'C')
        sum++;
    cout << sum;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using lint = long long int;
#define FOR(i, begin, end) for(int i=(begin),i##_end_=(end);i<i##_end_;i++)
#define IFOR(i, begin, end) for(int i=(end)-1,i##_begin_=(begin);i>=i##_begin_;i--)
#define REP(i, n) FOR(i,0,n)
#define IREP(i, n) IFOR(i,0,n)
constexpr int MOD = 1000000007;
constexpr int INF = 2147483647;
int main()
{
    lint k, q;
    cin >> k >> q;
    vector<lint> d(k);
    REP(i, k) cin >> d[i];

    REP(Q, q) {
        lint n, x, m;
        cin >> n >> x >> m;
        x = x%m;
        vector<lint> d2(k);
        REP(i, k) {
            d2[i] = d[i]%m;
        }
        lint a = (n-1)/k;
        lint b = (n-1)%k;
        lint ya = 0;
        lint yb = 0;
        lint zeroa = 0;
        lint zerob = 0;
        REP(i, k) {
            ya += d2[i];
            if(d2[i] == 0) zeroa++;
            if(i < b) {
                yb += d2[i];
                if(d2[i] == 0) zerob++;
            }
        }
        lint ans = n-1;
        ans -= (zeroa * a + zerob);
        lint y = ya * a + yb + x;
        //cout << y << endl;
        ans -= (y/m);
        cout << ans << endl;
    }
}

Measured memory_bytes: 384
#include <climits>
#include <iostream>
#include <vector>
#define rep(i, n) for (int i = 0; i < (n); i++)
using namespace std;
int H, W, K;
vector<string> S;

vector<pair<int, int>> decodePattern(int pattern, int length) {
  vector<pair<int, int>> dec;
  int prev = 0;
  int count = 0;
  while (pattern) {
    if (pattern % 2) {
      dec.emplace_back(prev, count);
      prev = count + 1;
    }
    pattern /= 2;
    count++;
  }
  if (count != length) dec.emplace_back(prev, length - 1);
  return dec;
}

inline int getWhiteCount(int x, int y1, int y2) {
  int ret = 0;
  for (int i = y1; i <= y2; ++i) ret += (S[i][x] == '1') ? 1 : 0;
  return ret;
}

int greedyCheck(int pattern) {
  vector<pair<int, int>> decY = decodePattern(pattern, S.size());
  int ynum = decY.size();
  int cut = ynum - 1;
  vector<int> white(ynum, 0);
  vector<int> cur_white(ynum, 0);
  for (int x = 0; x < W; ++x) {
    bool need_cut = false;
    for (int y = 0; y < ynum; ++y) {
      cur_white[y] = getWhiteCount(x, decY[y].first, decY[y].second);
      if (cur_white[y] > K)
        return INT_MAX;
      else if ((white[y] + cur_white[y]) > K)
        need_cut = true;
    }
    if (need_cut) {
      cut++;
      for (int y = 0; y < ynum; ++y) white[y] = cur_white[y];
    } else {
      for (int y = 0; y < ynum; ++y) white[y] += cur_white[y];
    }
  }
  return cut;
}

int main(void) {
  ios::sync_with_stdio(false);
  cin >> H >> W >> K;
  S.resize(H);
  rep(i, H) { cin >> S[i]; }
  int answer = INT_MAX;
  for (int pattern = 0; pattern < (1 << (H - 1)); ++pattern) {
    answer = min(answer, greedyCheck(pattern));
  }
  cout << answer << endl;
  return 0;
}


Measured memory_bytes: 384
#include <bits/stdc++.h>
using namespace std;
const unsigned int MOD = 1000000007;
#define ll long long
#define PI 3.1416
string day[]={"SUN","MON","TUE","WED","THU","FRI","SAT"};
int main() {
    //freopen("input.txt","r",stdin);
    //freopen("output.txt","w",stdout);
    int a;
    while(cin>>a){
        if(a%10==9 || a/10==9)cout<<"Yes"<<endl;
        else cout<<"No"<<endl;
    }
    return 0;
}


Measured memory_bytes: 256