akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;

const int MAXN = 15;
const int MAXS = 1 << 15;
const int INF = 1e9;

int N, M;
int A[MAXN][MAXN];
int C[MAXN][MAXS];
int inner[MAXS];

int dp[MAXS][MAXN];

int main() {
	scanf("%d %d", &N, &M);
	int tot = 0;
	for (int i = 0; i < M; i++) {
		int u, v, w; scanf("%d %d %d", &u, &v, &w); u--, v--;
		A[u][v] = A[v][u] = w;
		tot += w;
	}

	// set <-> single vertex
	for (int v = 0; v < N; v++) {
		for (int m = 0; m < (1 << N); m++) {
			for (int u = 0; u < N; u++) {
				if (m & (1 << u)) {
					C[v][m] += A[v][u];
				}
			}
		}
	}

	// vertices in a set
	for (int m = 0; m < (1 << N); m++) {
		for (int u = 0; u < N; u++) {
			if (!(m & (1 << u))) continue;
			for (int v = u+1; v < N; v++) {
				if (!(m & (1 << v))) continue;
				inner[m] += A[u][v];
			}
		}
	}

	// set initial value
	for (int m = 0; m < (1 << N); m++) {
		for (int cur = 0; cur < N; cur++) {
			dp[m][cur] = -INF;
		}
	}
	dp[1][0] = 0;

	// dp
	for (int m = 1; m < (1 << N); m++) {
		for (int v = 0; v < N; v++) {
			if (dp[m][v] == -INF) continue;
			int dpv = dp[m][v];

			// 1. add a brige from v to u
			for (int u = 0; u < N; u++) {
				if (!(m & (1 << u)) && A[v][u]) {
					dp[m|(1<<u)][u] = max(dp[m|(1<<u)][u], dpv + A[u][v]);
				}
			}
	
			// 2. add incident vertices
			int comp = (1 << N) - 1 - m;
			for (int s = comp; s > 0; s = (s - 1) & comp) {
				assert(!(m&s));
				dp[m|s][v] = max(dp[m|s][v], dpv + C[v][s] + inner[s]);
			}
		}
	}

	int ans = tot - dp[(1<<N)-1][N-1];
	printf("%d\n", ans);

	return 0;
}

Measured memory_bytes: 4224
#include <vector> 
#include <list> 
 #include <map>
 #include <set>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>
#include <queue>
using namespace std;

//conversion
//------------------------------------------
inline int toInt(string s) {int v; istringstream sin(s);sin>>v;return v;}
template<class T> inline string toString(T x) {ostringstream sout;sout<<x;return sout.str();}

//math
//-------------------------------------------
template<class T> inline T sqr(T x) {return x*x;}

//typedef
//------------------------------------------
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef long long LL;

//container util
//------------------------------------------
#define ALL(a)  (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define MP make_pair
#define SZ(a) int((a).size())
#define EACH(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort((c).begin(),(c).end())

//repetition
//------------------------------------------
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)

//constant
//--------------------------------------------
const double EPS = 1e-10;
const double PI  = acos(-1.0);

//clear memory
#define CLR(a) memset((a), 0 ,sizeof(a))

//debug
#define dump(x)  cerr << #x << '=' << (x) << endl;
#define debug(x) cerr << #x << '=' << (x) << '('<<'L' << __LINE__ << ')' << ' ' << __FILE__ << endl;

#define POSSIBLE cout<<"POSSIBLE"<<endl; return 0;
#define IMPOSSIBLE cout<<"IMPOSSIBLE"<<endl; return 0;

LL gcd(LL a,LL b){
    if(a<b){swap(a,b);}
    if(b==0) return a;
    return gcd(b,a%b);
}


int main(){

    LL N,K;
    cin>>N>>K;
    vector<LL> A(N);
    LL m=0;
    REP(i,N){ cin>>A[i];m=max(m,A[i]);}

    if(m<K){IMPOSSIBLE;}
    if(find(ALL(A),K)!=A.end()){POSSIBLE;}

    LL gcd_=gcd(A[0],A[1]);

    FOR(i,2,N){
        gcd_=gcd(gcd_,A[i]);
    }
    if(K%gcd_==0){POSSIBLE;}
    else{IMPOSSIBLE;}








  
}


Measured memory_bytes: 1024
lst = input()
lst = lst.split()


for i in range(len(lst)):
    lst[i]= int(lst[i])
N = lst[0]
L = lst[1]
q = L
l = 0
lste = [abs(L)]
tlst = []
for i in range(2,N+1):
    t = L+i-1
    q += t
    tlst.append(t)
    t = abs(t)
    lste.append(t)


slst = sorted(lste)
l = slst[0]
if tlst.count(-l) > 0:
    print(q+l)
else:
    print(q-l)

Measured memory_bytes: 9160
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		// TODO 自動生成されたメソッド・スタブ
		int count = 0;
		Scanner scan = new Scanner(System.in);
		int N = scan.nextInt();
		int D = scan.nextInt();
		int[][] point = new int[N][2];
		
		for(int i=0;i<N;i++) {
			for(int j=0;j<2;j++) {
				point[i][j] = scan.nextInt();
			}
		}
		
		for(int i=0;i<N;i++) {
			double a = Math.sqrt(Math.pow(point[i][0],2)+Math.pow(point[i][1],2));
			if(a<=D) {
				count++;
			}
		}
		
		System.out.println(count);

	}

}

Measured memory_bytes: 65160
package main

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

func main() {
	N, K := ReadInt(), ReadInt()
	A := make([]int, N)
	for i := 0; i < N; i++ {
		A[i] = ReadInt() - 1
	}
	next := make([][]int, 64)
	for i := 0; i < 64; i++ {
		next[i] = make([]int, N)
	}
	for i := 0; i < N; i++ {
		next[0][i] = A[i]
	}
	for k := 1; k < 64; k++ {
		for i := 0; i < N; i++ {
			next[k][i] = next[k-1][next[k-1][i]]
		}
	}
	v := 0
	for i := 0; i < 64; i++ {
		if K>>i&1 == 1 {
			v = next[i][v]
		}
	}
	fmt.Println(v + 1)
}

var reader = bufio.NewReader(os.Stdin)

func Scan(a ...interface{}) {
	if _, err := fmt.Fscan(reader, a...); err != nil {
		panic(err)
	}
}
func ReadInt() (i int) { Scan(&i); return }


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

const int INF = 1e9;

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

    int n;
    cin >> n;
    string s;
    cin >> s;
    vector<int> white(n), red(n);
    for (int i = 0; i < n; i++) {
        if (i) {
            red[i] = red[i - 1];
            white[i] = white[i - 1];
        }
        if (s[i] == 'R')
            red[i]++;
        else
            white[i]++;
    }
    int resp = n - white[n - 1];
    for (int i = 0; i < n; i++)
        resp = min(resp, max(i + 1 - red[i], n - (i + 1) - (white[n - 1] - white[i])));
    cout << resp << endl;

	return 0;
}

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

using namespace std;
#define rep(i, n) for (int i = 0; i < n; i++)
#define ll long long int
#define INF 1000000007
#define llINF 1000000000000000007
#define v(i) vector<i>
#define vv(i) vector<vector<i>>
// cin.eof() 入力個数の問題
// int num = atoi(string.c_str()); 文字列の整数変換

int main() {
    ll k,a,b;
    cin>>k>>a>>b;
    ll ans = 1;
    if(b - a <=2 || k + 1 <= a){
        ans += k;
    }else
    {
        ans += a - 1;
        k -= a - 1;

        ans += (b - a) * (k/2) + k%2;
    }
    
cout<<ans<<endl;

    return 0;
}


Measured memory_bytes: 3604
#include <vector>
#include <iostream>
#define rep(i, n) for (int i = 0; i < n; i++)
using namespace std;
void insertionSort(vector<int> &A, int N) {
    for (int i = 1; i < N; ++i) {
        rep(i, N) {
            if (i != N - 1) cout << A[i] << " ";
            else cout << A[i] << endl;
        }
        int v = A[i];
        int j = i - 1;
        while (j >= 0 && A[j] > v) {
            A[j + 1] = A[j];
            --j;
        }
        A[j + 1] = v;
    }
}
int main() {
    int N;
    cin >> N;
    vector<int> A(N);
    for (int i = 0; i < N; ++i) cin >> A[i];
    insertionSort(A, N);
    rep(i, N) {
        if (i != N - 1) cout << A[i] << " ";
        else cout << A[i] << endl;
    }
}


Measured memory_bytes: 3108
# -*- coding: utf-8 -*-
n, m, X, Y = map(int,input().split())
x = list(map(int, input().split()))
y = list(map(int, input().split()))

flag = False
#for z in range(-100, 101):
for z in range(X + 1, Y + 1):
    count_x = 0
    count_y = 0
    for i in x:
        if i < z:
            count_x += 1
    for i in y:
        if i >= z:
            count_y += 1
    #print(count_x, count_y)
    if count_x == n and count_y == m:
        flag = True
        #print(z)
if flag:
    print("No War")
else:
    print("War")

"""
count_x = 0
count_y = 0
ans = 0
for Z in range(-100, 101):
    #Z = 16
    if X <= Z <= Y:
        for i in range(n):
            if x[i] < Z:
                count_x += 1
        for j in range(m):
            if y[j] >= Z:
                count_y += 1
        if count_x == n and count_y == m:
            ans = 1

if ans == 1:
    print("No War")
else:
    print("War")
"""

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

int main(){
    int a, b, c, d, e, k;
    cin >> a >> b >> c >> d >> e >> k;
    if(b - a <= k && c - a <= k && d - a <= k && e - a <= k && c - b <= k && d - b <= k && e - b <= k && d - c <= k && e - c <= k && e - d <= k ){
        cout << "Yay!" << endl;
    }else{
        cout << ":(" << endl;
    }
    return 0;
}

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

int main(){
  int N;
  cin >> N;
  
  int last = N%10;
  if(N%1110 == last){
    cout << "Yes" << endl;
  }
  else if(N%1000 %111 == 0){
    cout << "Yes" << endl;
  }
  else{
    cout << "No" << endl;
  }
}

Measured memory_bytes: 256
import sys
f=lambda v,b: v.append(sum(b))
while True:
    c=input()
    if c==0: break
    x=range(c);z=range(c+1);q={}
    for i in x:
        q[i]=map(int,raw_input().split());t=q.values()[i];f(t,t)
    q[i+1]=[]
    for g in x:
        w=[]
        for j in x:
            w.append(q.values()[j][g]) 
        f(q[i+1],w)
    t=q[i+1];f(t,t)
    for i in q.values():
        for j in z: sys.stdout.write("%5d"%i[j])
        print 

Measured memory_bytes: 4268
#include <stdio.h>
int main(void){

  int N=0;
  int a;
  //  int even=0;
  int odd=0;
  scanf("%d",&N);

  int i;
  for(i=0;i<N;i++){
    scanf("%d",&a);
    if(a%2 != 0) odd++;
  }
  // printf("odd = %d\n",odd);
  
  if(odd%2 != 0){
    printf("NO\n");
  }else{
    printf("YES\n");
  }
}


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

int main() {
  int N;
  cin>>N;
  vector<vector<int>> p(N, vector<int>(3));
  for(int i=0;i<N;i++){
    cin>>p.at(i).at(0)>>p.at(i).at(1)>>p.at(i).at(2);
  }
  vector<vector<int>> z(N, vector<int>(3));
  z.at(0).at(0)=p.at(0).at(0);
  z.at(0).at(1)=p.at(0).at(1);
  z.at(0).at(2)=p.at(0).at(2);
  for(int i=1;i<N;i++){
    z.at(i).at(0)=max(z.at(i-1).at(1)+p.at(i).at(0),z.at(i-1).at(2)+p.at(i).at(0));
    z.at(i).at(1)=max(z.at(i-1).at(0)+p.at(i).at(1),z.at(i-1).at(2)+p.at(i).at(1));
    z.at(i).at(2)=max(z.at(i-1).at(0)+p.at(i).at(2),z.at(i-1).at(1)+p.at(i).at(2));
  }
  cout<<max(z.at(N-1).at(0),max(z.at(N-1).at(1),z.at(N-1).at(2)))<<endl;
}

Measured memory_bytes: 11136
use std::io::*;
use std::str::FromStr;

#[allow(dead_code)]
fn read<T: FromStr>() -> T {
    let stdin = stdin();
    let stdin = stdin.lock();
    let token: String = stdin
        .bytes()
        .map(|c| c.expect("failed to read char") as char)
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect();
    token.parse().ok().expect("failed to parse token")
}

fn main() {
    let mut s = read::<String>().chars().collect::<Vec<char>>();
    let t = read::<String>().chars().collect::<Vec<char>>();
    for _i in 0..s.len() {
        if s == t {
            println!("Yes");
            return;
        }
        let mut ns: Vec<char> = vec![];
        ns.push(*s.last().unwrap());
        ns.append(&mut s.clone());
        ns.pop();
        s = ns;
    }
    println!("No");
}


Measured memory_bytes: 4352
#include <stdio.h>

int main(void){
	int n,a,minv,maxv,i,b;
	scanf("%d",&n);
	scanf("%d",&b);
	minv=b;

	for(i=2;i<=n;i++){
		scanf("%d",&a);
		if(i==2)
			maxv = a-b;
		if(maxv < a-minv)
			maxv = a-minv;
		if(minv > a)
			minv =a;
	}
	printf("%d\n",maxv);
	return 0;
}

Measured memory_bytes: 596
#include<bits/stdc++.h>
using namespace std;
const int MAXN = 2e5 + 5;
typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;
template <typename T> void chkmax(T &x, T y) {x = max(x, y); }
template <typename T> void chkmin(T &x, T y) {x = min(x, y); } 
template <typename T> void read(T &x) {
	x = 0; int f = 1;
	char c = getchar();
	for (; !isdigit(c); c = getchar()) if (c == '-') f = -f;
	for (; isdigit(c); c = getchar()) x = x * 10 + c - '0';
	x *= f;
}
template <typename T> void write(T x) {
	if (x < 0) x = -x, putchar('-');
	if (x > 9) write(x / 10);
	putchar(x % 10 + '0');
}
template <typename T> void writeln(T x) {
	write(x);
	puts("");
}
int a[MAXN], b[MAXN];
priority_queue <pair <int, int>> Heap;
int main() {
	int n; read(n); ll ans = 0;
	for (int i = 1; i <= n; i++)
		read(b[i]);
	for (int i = 1; i <= n; i++)
		read(a[i]), Heap.push(make_pair(a[i], i));
	while (!Heap.empty()) {
		pair <int, int> tmp = Heap.top(); Heap.pop();
		if (b[tmp.second] == tmp.first) continue;
		if (b[tmp.second] > tmp.first) {
			writeln(-1);
			return 0;
		}
		int dis = tmp.first - b[tmp.second];
		int sum = a[tmp.second - 1] + a[tmp.second + 1];
		if (tmp.second == 1) sum += a[n];
		if (tmp.second == n) sum += a[1];
		if (sum > dis) {
			writeln(-1);
			return 0;
		}
		int add = dis / sum; ans += add;
		a[tmp.second] -= add * sum;
		tmp.first = a[tmp.second];
		Heap.push(tmp);
	}
	writeln(ans);
	return 0;
}

Measured memory_bytes: 3700
#include<bits/stdc++.h>
#define rep(i,n) for(int i=0;i<n;i++)
#define mp make_pair
#define pb push_back
#define x first
#define y second
#define forn(i,a,n) for(int i=a;i<n;i++)
#define foreach(i,c) for(__typeof(c.begin())i=(c.begin());i!=(c).end();i++)
#define pii pair<int,int>
#define vi vector<int>
#define ll long long
#define sz(s) s.size()
#define all(s) s.begin(),s.end()
#define zero(x) memset(x,0,sizeof(x))
#define vii vector<pair<int,int> >;
#define mpis map<int,string>
#define mpii map<int,int>
#define mpsi map<string,int>
#define re return
using namespace std;
int n,q;
vector<int> v[200001];
int p[200001],x[200001];
long long ans[200001];
void dfs(int d){
	for(int i=0;i<v[d].size();i++)
	ans[v[d][i]]+=ans[d];
	for(int i=0;i<v[d].size();i++)
	dfs(v[d][i]);
}
int main(){
	cin>>n>>q;
	for(int i=0;i<n-1;i++)
	{
		int a,b;
		cin>>a>>b;
		v[a].push_back(b);
	}
	for(int i=0;i<q;i++)
	cin>>p[i]>>x[i];
	for(int i=0;i<q;i++){
		ans[p[i]]+=x[i];
	}
	dfs(1);
	for(int i=1;i<=n;i++)
	cout<<ans[i]<<" ";
	re 0;
}

Measured memory_bytes: 22656
#include <bits/stdc++.h>
#define endl "\n"
using namespace std;

#define ll long long
const long long llINF = 1LL << 60;
const int iINF = 0x20000000;
template<class T> inline bool chmin(T& a, T b) { if (b < a) { 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; }

void execute();
int main() 
{
    cin.tie(nullptr);
    ios::sync_with_stdio(false);// cin と scanfの併用禁止
    cout << fixed << setprecision(15);
    execute();
    return 0;
}


void execute()
{
    ll N, X, T;
    cin >> N >> X >> T;

    cout << ((N+X-1) / X) * T << endl; 
}


Measured memory_bytes: 3608
#include<bits/stdc++.h>
using namespace std;
struct qwq{
	int a,b;
	inline bool operator<(const qwq &x)const{
	   return a<x.a;
	}
} x[100005];
priority_queue<int> q;
int main(){
	int n,m,i,j=1,s=0;
	scanf("%d%d",&n,&m);
	for(i=1;i<=n;++i)
	   scanf("%d%d",&x[i].a,&x[i].b);
	sort(x+1,x+n+1);
	for(i=1;i<=m;++i){
		for(;x[j].a==i&&j<=n;++j)
		   q.push(x[j].b);
		if(!q.empty()){
		   s += q.top();
		   q.pop();
		}
	}
	printf("%d",s);
	return 0;
}

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

using ll = long long;

const int INF = 1001001001;
const ll INF_LL = 1001001001001001001LL;

int main(void){
  int n,k; cin >> n >> k;
  string s; cin >> s;
  
  s[k-1] = tolower(s[k-1]);

  cout << s << endl;

  return 0;
}


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

using ll = int64_t;

#define rep(i, n) for (int i = 0; i < (n); ++i)
#define rrep(i, n) for (int i = 1; i <= (n); ++i)
#define drep(i, n) for (int i = (n)-1; i >= 0; --i)
#define ddrep(i, n) for (int i = n; i > 0; --i)
#define srep(i, s, t) for (int i = s; i < t; ++i)
#define ssrep(i, s, t) for (int i = s; i <= t; ++i)

#define rng(a) a.begin(), a.end()
#define pb push_back
#define eb emplace_back
#define fi first
#define se second

#define chmax(x, y) (x = max(x, y))
#define chmin(x, y) (x = min(x, y))

using pi = pair<int, int>;
using vi = vector<int>;
using vvi = vector<vi>;
using ld = long double;

template <class T, class U>
ostream &operator<<(ostream &os, const pair<T, U> &p) {
  os << "(" << p.first << "," << p.second << ")";
  return os;
}

template <class T> ostream &operator<<(ostream &os, const vector<T> &v) {
  os << "{";
  rep(i, (int)v.size()) {
    if (i)
      os << ",";
    os << v[i];
  }
  os << "}";
  return os;
}

template <typename T, size_t S> void printArray(const T (&array)[S]) {
  for (auto val : array)
    std::cout << val << ", ";
  std::cout << "\n";
}

const int mod = 1e9 + 7;
const int inf = 1e9 + 5;

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

  int n, d, a; std::cin >> n >> d >> a;
  vector<pi> points(n);
  rep(i, n) {
    std::cin >> points[i].fi >> points[i].se;
  }
  sort(rng(points));
  d *= 2;
  queue<pi> que;
  ll tot = 0, ans = 0;
  rep(i, n) {
    while (que.size() > 0 && que.front().fi < points[i].fi) {
      tot -= que.front().se;
      que.pop();
    }
    points[i].se -= tot;
    if (points[i].se > 0) {
      pi p;
      p.fi = points[i].fi + d;
      p.se = (points[i].se + a - 1) / a;
      ans += p.se, p.se *= a;
      tot += p.se;
      que.push(p);
    }
  }
  std::cout << ans << "\n";
}


Measured memory_bytes: 2688
#include<iostream>
#include<stdio.h>
#include<algorithm>
#include<vector>
#include<string.h>
#include<math.h>
#include<map>
#include<iomanip>

#define MOD 1e9+7;
#define INF 1e17+9;
#define PI acos(-1);

using namespace std;

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


Measured memory_bytes: 2560
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define repI(i, d, n) for (int i = (d); i < (n); ++i)
#define reps1(i, n) for (int i = 1; i < (n); ++i)
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; }

using ll = long long;
using P = pair<int, int>;
using Pl = pair<ll, ll>;
using M = map<int, int>;
ll const INF = 1ll<<61;
double pi = 3.141592653589793238;

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

  if (s == "ABC") cout << "ARC" << endl;
  else cout << "ABC" << endl;


  return 0;
}


Measured memory_bytes: 3628
#BFS
from collections import deque
def bfs(G):
    q=deque()
    q.append((k - 1, -1, 0))

    while q:
        #qの先頭を取り出す
        V, P, C = q.popleft()
        for new, cost in G[V]:
            if new == P:continue
            temp = C + cost
            q.append((new, V, temp))
            stand[new] = temp

n = int(input())
route_list = [[] for i in range(n)]  # 辺の移動の際のコスト
for i in range(n - 1):
    s, t, d = map(int, input().split())
    route_list[s - 1].append((t - 1, d))
    route_list[t - 1].append((s - 1, d))
# print(route_list)
q, k = map(int,input().split())


stand = [0] * n
bfs(route_list)
for i in range(q):
    x, y = map(int,input().split())
    temp = stand[x - 1] + stand[y - 1]
    print(temp)

Measured memory_bytes: 88864
n = int(input())
a = list(map(int, input().split()))

ans = 1
a.sort()

for i in a:
    if i == 0:
        ans = 0
        break
    elif ans > 10**18:
        ans = -1
        break
    else:
        ans = ans * i

if ans > 10**18:
    ans = -1
    
print(ans)

Measured memory_bytes: 21652
import java.util.Arrays;
import java.util.Scanner;

public class Main{
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);

		int n = sc.nextInt();
		int k = sc.nextInt();
		int[] p = new int[n];

		for (int i = 0; i < n; i++) {
			p[i] = sc.nextInt();
		}

		Arrays.sort(p);

		int ans = 0;
		for (int i = 0; i < k; i++) {
			ans += p[i];
		}
		System.out.println(ans);
	}

}


Measured memory_bytes: 38200
#include <iostream>
#include <algorithm>
#include <vector>
#include <queue>
#include <stack>
#include <string>
#include <iomanip>
#include <map>
#include <set>
#include <cmath>
#include <cstdio>
using namespace std;
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define FOR(i,m,n) for(int (i)=(m);(i)<(n);(i)++)
#define All(v) (v).begin(),(v).end()
typedef long long ll;

ll dp[110][100100];

int main(){
    int N,W;cin >> N >> W;
    vector<int> w(N),v(N);
    rep(i,N)cin >> w[i] >> v[i];

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

Measured memory_bytes: 79360
import itertools
import math
n=int(input())
l=[list(map(float,input().split())) for i in range(n)]

"""
for i in range(n):
    print(l[i])
"""

a=[]
ans=0
for i in range(n):
    a.append(i)
for x in itertools.permutations(a): 
    for i in range(n-1):
        #ans+=cal(a[i],a[i+1])
        add=(l[x[i]][0]-l[x[i+1]][0])**2+(l[x[i]][1]-l[x[i+1]][1])**2
        add=math.sqrt(add)
        ans+=add
        #print(ans)
    #print(x)
for i in range(1,n+1):
    ans/=i
print(ans)



Measured memory_bytes: 3064
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner scanner = new Scanner(System.in);
		int n = scanner.nextInt(),k = scanner.nextInt();
		char[] ng = new char[k];
		for(int i=0;i<k;i++){
			int x = scanner.nextInt();
			ng[i] = (char)('0'+ x);
		}
		int money = n;
		while(true){
			String s = String.valueOf(money);
			int count = 0;
			for(int i=0;i<s.length();i++){
				for(int j=0;j<k;j++){
					if(s.charAt(i) == ng[j]){
						break;
					}else if(j == (k-1)){
						count++;
					}
				}
			}
			if(count == s.length()){
				break;
			}else{
				money++;
			}
		}
		System.out.println(money);
	}

}


Measured memory_bytes: 24276
import java.util.Scanner;
public class Main{
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    int n = Integer.parseInt(sc.next());
    int r = Integer.parseInt(sc.next());
    if(n < 10){
      int def = 100*(10-n);
      System.out.println(r + def);
    }
    else{
      System.out.println(r);
    }
  }
}


Measured memory_bytes: 21716
#include <cstdio>
#include <cstring>
#include <iostream>
#include <algorithm>
#include <vector>
#include <map>
#include <queue>
using namespace std;
int N;
int X1[1111],X2[1111],Y1[1111],Y2[1111];
int dx[] = {0,0,1,-1};
int dy[] = {1,-1,0,0};

int compress(int z1[],int z2[],int w){
  vector<int> xs;
  for(int i = 0;i < N; i++){
    for(int d = -1; d <= 1; d++){
      int tx1 = z1[i] + d;
      int tx2 = z2[i] + d;
      if(0 <= tx1 && tx1 < w) xs.push_back(tx1);
      if(0 <= tx2 && tx2 < w) xs.push_back(tx2);
    }
  }

  sort(xs.begin(),xs.end());
  xs.erase( unique(xs.begin(),xs.end()) , xs.end());

  for(int i = 0; i < N; i++){
    z1[i] = find(xs.begin(),xs.end(),z1[i]) - xs.begin();
    z2[i] = find(xs.begin(),xs.end(),z2[i]) - xs.begin();
  }
  return xs.size();
}

bool f[3333][3333];

int main(void){
  int W,H;
  while(cin >> W >> H && W){
    cin >> N;
    for(int i = 0; i < N; i++){
      cin >> X1[i] >> Y1[i] >> X2[i] >> Y2[i];
    }
    W = compress(X1,X2,W);
    H = compress(Y1,Y2,H);

    memset(f,false,sizeof(f));
    for(int i = 0; i < N; i++){
      for(int x = X1[i]; x < X2[i]; x++){
	for(int y = Y1[i]; y < Y2[i]; y++){
	  f[x][y] = true;
	}
      }
    }

    int res = 0;
    for(int x = 0; x < W; x++){
      for(int y = 0; y < H; y++){
	if(f[x][y]) continue;
	res++;

	queue< pair<int,int> > que;
	que.push( make_pair(x,y) );
	while(!que.empty()){
	  int sx = que.front().first;
	  int sy = que.front().second;
	  que.pop();
	  for(int i = 0; i < 4; i++){
	    int nx = sx + dx[i];
	    int ny = sy + dy[i];
	    if(nx < 0 || ny < 0 || W <= nx || H <= ny) continue;
	    if(f[nx][ny])continue;
	    que.push( make_pair(nx,ny) );
	    f[nx][ny] = true;
	  }
	}
      }
    }
    cout << res << endl;
  }
}

Measured memory_bytes: 12104
#include <iostream>
#include<cstring>
#include<cstdio>
#include<algorithm>
#include<string>
using namespace std;
int main()
{
    int a,b,c,d,e,k,js=0;
    cin>>a>>b>>c>>d>>e>>k;
    if(b-a>k)js++;
    if(c-a>k)js++;
    if(d-a>k)js++;
    if(e-a>k)js++;
    if(c-b>k)js++;
    if(d-b>k)js++;
    if(e-b>k)js++;
    if(d-c>k)js++;
    if(e-c>k)js++;
    if(e-d>k)js++;
    if(js!=0)
        cout<<":("<<endl;
    else
        cout<<"Yay!"<<endl;
    return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include <stdio.h>
#include<algorithm>
#include<cstring>
#include <string>
#include<cmath>
#include<cstdlib>
#include<queue>
#include<map>
#include<vector>
#include<bits/stdc++.h>
#include <set>
#define ll   long long
#define IO ios::sync_with_stdio(false);cin.tie();cout.tie(0)
#define inf 0x3f3f3f
#define pi 3.1415926535898
using namespace std;
const int N=3e5+10;
const int mod=1e9+7;
int a[N],b[N];
ll maxs=-9999;
ll sum;
struct A
{
    int x,y;
};
map <pair<int,int >,int >mp;
int main()
{
    int h,w,m;
    int q[N],t[N];
    int cnt1,cnt2;
    cin>>h>>w>>m;
    int  sum1=0,sum2=0;
    for(int i=0; i<m; i++)
    {
        int x,y;
        cin>>x>>y;
        mp[make_pair(x,y)]++;
        a[x]++;
        b[y]++;
    }
    for(int i=1; i<=h; i++)
    {
        if(sum1<a[i])
        {
            cnt1=0;
            memset(q,0,sizeof(q));
            sum1=max(sum1,a[i]);
            q[cnt1++]=i;
            while(sum1==a[i+1])
            {
                q[cnt1++]=i;
                i++;
            }
        }
        if(sum1==a[i])
        {
            q[cnt1++]=i;
            while(sum1==a[i+1])
            {
                q[cnt1++]=i;
                i++;
            }
        }
    }
    for(int i=1; i<=w; i++)
    {
        if(sum2<b[i])
        {
            cnt2=0;
            memset(t,0,sizeof(t));
            sum2=max(sum2,b[i]);
            t[cnt2++]=i;
            while(sum2==b[i+1])
            {
                t[cnt2++]=i;
                i++;
            }
        }
        if(sum2==b[i])
        {
            t[cnt2++]=i;
            while(sum2==b[i+1])
            {
                t[cnt2++]=i;
                i++;
            }
        }
    }
    sum=sum1+sum2;
    int xx=0;
    for(int i=0; i<cnt1; i++)
    {
        for(int j=0; j<cnt2; j++)
        {
            int x1,y1;
            x1=q[i];
            y1=t[j];
            if(mp[make_pair(x1,y1)]==0)
            {
                xx=1;
                break;
            }

        }
        if(xx==1)
        {
            break;
        }
    }
    if(xx==0)
    {
        sum--;
    }
    cout<<sum<<endl;
    return 0;
}


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

public class Main
{
	public static void main(String [] Args)
	{
		Scanner in=new Scanner(System.in);
		int n=in.nextInt();
		String [] s=new String[n];
		int [] a=new int [n];
		int [] ans=new int [n];
		for(int i=0;i<n;i++)
		{
			s[i]=in.next();
			a[i]=in.nextInt();
			ans[i]=i;
		}
		for(int i=0;i<n;i++)
		{
			for(int j=i+1;j<n;j++)
			{
				if(compare(s[i],s[j])>0)
				{
					String temp2=s[i];
					s[i]=s[j];
					s[j]=temp2;
					int temp1=a[i];
					a[i]=a[j];
					a[j]=temp1;
					int temp=ans[i];
					ans[i]=ans[j];
					ans[j]=temp;
				}
				if(compare(s[i],s[j])==0&&a[j]>a[i])
				{
					String temp2=s[i];
					s[i]=s[j];
					s[j]=temp2;
					int temp1=a[i];
					a[i]=a[j];
					a[j]=temp1;
					int temp=ans[i];
					ans[i]=ans[j];
					ans[j]=temp;
				}
			}
		}
		for(int i=0;i<n;i++)
		{
			System.out.println(ans[i]+1);
		}
	}
	
	public static int compare(String a,String b)
	{
		int n=0;
		if(a.length()>b.length())
			n=b.length();
		else
			n=a.length();
		for(int i=0;i<n;i++)
		{
			if(a.charAt(i)!=b.charAt(i))
				return a.charAt(i)-b.charAt(i);
		}
		return a.length()-b.length();
	}
}
	

Measured memory_bytes: 23124
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(n) for (ll i = 0; i < n; ++i)
#define rep2(i, n) for (ll i = 0; i < n; ++i)
#define rep3(i, a, b) for (ll i = a; i < b; ++i)
#define rep4(i, a, b, c) for (ll i = a; i < b; i += c)
#define erep(n) for (ll i = 0; i <= n; ++i)
#define erep2(i, n) for (ll i = 0; i <= n; ++i)
#define erep3(i, a, b) for (ll i = a; i <= b; ++i)
#define erep4(i, a, b, c) for (ll i = a; i <= b; i += c)
#define rrep(i, a, b) for (ll i = a; i > b; --i)
#define rrep2(i, a, b, c) for (ll i = a; i > b; i -= c)
#define errep(i, a, b) for (ll i = a; i >= b; --i)
#define errep2(i, a, b, c) for (ll i = a; i >= b; i -= c)
#define print(a) cout << a << endl;
#define printVec(v) printf("{"); for (const auto& i : v) { std::cout << i << ", "; } printf("}\n");
inline int newline() { putchar('\n'); return 0; }

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

    int s[m], c[m];
    rep2(i, m) cin >> s[i] >> c[i];

    vector<int> v(n, -1);
    rep2(i, m) {
        int itemS = s[i];
        int itemC = c[i];

        itemS--;

        if (v[itemS] != -1 && v[itemS] != itemC) {
            print(-1);
            return 0;
        }

        if (n > 1 && itemS == 0 && itemC == 0) {
            print(-1);
            return 0;
        }

        v[itemS] = itemC;
    }

    const int threshold[3] = {0, 10, 100};

    int result = 0;
    rep2(i, n) result += pow(10, n - i - 1) * max(0, v[i]);

    if (result < threshold[n - 1]) result += threshold[n - 1];

    print(result);
    return 0;
}

Measured memory_bytes: 256
N, M = map(int, input().split())
X = list(map(int, input().split()))
X.sort()
X_interval = [X[i + 1] - X[i] for i in range(M - 1)]
X_interval.sort()

if N >= M:
    print(0)
elif N == 1:
    print(sum(X_interval))
else:
    print(sum(X_interval[:-(N - 1)]))


Measured memory_bytes: 13960
import sys
input = sys.stdin.readline
#-------------------------------------
n = int(input())
h = list(map(int,input().split()))

count_max = 0
count = 0
tmp = h[0]-1
for i in h:
    if i <= tmp:
        count += 1
        if count > count_max : count_max = count 
    else:
        count=0
    tmp = i

print(count_max)

Measured memory_bytes: 59632
infinity=2**35
def merge(A,left,mid,right):
  global cnt

  L=A[left:mid]
  R=A[mid:right]
  L.append(infinity)
  R.append(infinity)

  i=0
  j=0

  inver=0

  for k in range(left,right):
    if L[i]<=R[j]:
      A[k]=L[i]
      i+=1
      if inver>0:
        cnt+=inver
      
    else:
      A[k]=R[j]
      j+=1
      inver+=1



def mergeSort(A,left,right):
  if (left+1)<right:
    mid=(left+right)//2
    mergeSort(A,left,mid)
    mergeSort(A,mid,right)
    merge(A,left,mid,right)


n=int(input())
A=list(map(int,input().split()))
cnt=0

mergeSort(A,0,n)

print(cnt)



Measured memory_bytes: 27476
#define _CRT_SECURE_NO_WARNINGS
#include <iostream>
#include <algorithm>
#include <functional>
#include <string>
#include <vector>
#include <set>
#include <stdio.h>
using namespace std;

#define REP(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define REPL(i,f,n) for(int i=f, i##_len=(n); i<i##_len; ++i)
typedef long long ll;

int func(int x) {
	if (x % 2 != 0)return 0;
	return 1 + func(x / 2);
}
int main() {
	cin.tie(0);
	ios::sync_with_stdio(false);

	int N,a,ans = 0;
	cin >> N;
	REP(i, N) {
		cin >> a;
		ans += a - 1;
	}
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 1016
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int a,b,i,j,ara[10000];
    long long int s=0,m,n;
    cin>>a>>b;
    for(i=0;i<b;i++)
    {
        cin>>ara[i];
        s=s+ara[i];
    }
    if(s<=a)
    {
        m=a-s;
        cout<<m<<endl;
    }
    else
    {
        cout<<"-1"<<endl;
    }
    return 0;
}


Measured memory_bytes: 3624
#include <iostream>
#include <vector>
#include <algorithm>
#include <map>
#include <set>
#include <queue>
#include <climits>
#include <array>
#define rep(i, N) for(int (i) = 0; (i) < (N); (i)++)

using ll = long long;
using ull = unsigned long long;
constexpr ll mod = 1e9 + 7;
using namespace std;

int main() {

	int a; cin >> a;
	int ans = a / 2;
	if (a % 2 == 1)ans++;
	cout << (double)ans / (double)a;

	return 0;

}

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

int main() {
   int N, K, answer;
  answer = 0;
  cin >> N >> K;
  vector<int> p(N);
  for(int i = 0; i < N; i++){
    cin >> p[i];
  }
  
  sort(p.begin() , p.end() );
  
  for(int i = 0; i < K; i++){
    answer += p[i];
  }

  cout << answer << endl;
}


Measured memory_bytes: 3604
#include <iostream>
#include <string>
#include <sstream>
#include <iomanip> 
#include <math.h>
#include <stdio.h>
#include <string.h>
#include <queue>
#include <stack>
#include <vector>
#include <map>
#include <set>
#include <functional>
#include <algorithm>
#include <unordered_map>
#include <unordered_set>
#include <bitset>

using namespace std;



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

	long long n, i, j, k, ans;
	cin >> n >> k;
	vector<long long> a(n + 1), s(n + 1);
	s[0] = 0;
	for (i = 1; i <= n; i++) {
		cin >> a[i];
		a[i]--;
		s[i] = a[i] + s[i - 1];
	}

	ans = 0;
	map<long long, long long> ct;
	ct[0] = 1;
	for (i = 1; i <= n; i++) {
		if (i - k >= 0) ct[(s[i - k]) % k]--;
		ans += ct[s[i] % k];
		ct[s[i] % k]++;
	}

	cout << ans << "\n";

	return 0;
}



Measured memory_bytes: 15872
#include <iostream>
#include <cstring>
#include <algorithm>
#include <vector>
#include <string>
#include <math.h>
#include <iomanip>
#include <limits>
#include <list>
#include <queue>
#include <tuple>
#include <map>
#include <stack>
#include <set>
#include <bitset>
#include <functional>
#include <cassert>
using namespace std;
#define fast_io ios_base::sync_with_stdio (false) ; cin.tie(0) ; cout.tie(0) ;
#define ll long long int
#define rep(i,n) for(int i=0; i<(int)(n); i++)
#define reps(i,n) for(int i=1; i<=(int)(n); i++)
#define REP(i,n) for(int i=n-1; i>=0; i--)
#define REPS(i,n) for(int i=n; i>0; i--)
#define MOD (long long int)(1e9+7)
#define INF (int)(1e9)
#define LINF (long long int)(1e18)
#define chmax(a, b) a = (((a)<(b)) ? (b) : (a))
#define chmin(a, b) a = (((a)>(b)) ? (b) : (a))
#define all(v) v.begin(), v.end()
typedef pair<int, int> Pii;
typedef pair<ll, ll> Pll;

ll mpow(ll a, ll b){
  if(b==0) return 1;
  else if(b%2==0){ll memo = mpow(a,b/2); return memo*memo%MOD;}
  else return mpow(a,b-1) * a % MOD;
}
ll lpow(ll a, ll b){
  if(b==0) return 1;
  else if(b%2==0){ll memo = lpow(a,b/2); return memo*memo;}
  else return lpow(a,b-1) * a;
}
ll gcd(ll a, ll b){
  if(b==0) return a;
  else return gcd(b, a%b);
}
vector<ll> kaijo_memo;
ll kaijo(ll n){
  if(kaijo_memo.size() > n) return kaijo_memo[n];
  if(kaijo_memo.size() == 0) kaijo_memo.push_back(1);
  while(kaijo_memo.size() <= n) kaijo_memo.push_back(kaijo_memo[kaijo_memo.size()-1] * kaijo_memo.size() % MOD);
  return kaijo_memo[n];
}
vector<ll> gyaku_kaijo_memo;
ll gyaku_kaijo(ll n){
  if(gyaku_kaijo_memo.size() > n) return gyaku_kaijo_memo[n];
  if(gyaku_kaijo_memo.size() == 0) gyaku_kaijo_memo.push_back(1);
  while(gyaku_kaijo_memo.size() <= n) gyaku_kaijo_memo.push_back(gyaku_kaijo_memo[gyaku_kaijo_memo.size()-1] * mpow(gyaku_kaijo_memo.size(), MOD-2) % MOD);
  return gyaku_kaijo_memo[n];
}

ll nCr(ll n, ll r){
  if(n == r) return 1;//0個の丸と-1個の棒みたいな時に時に効く？不安.
  if(n < r || r < 0) return 0;
  ll ret = 1;
  if(n <= 1e7){
    ret *= kaijo(n); ret %= MOD;
    ret *= gyaku_kaijo(r); ret %= MOD;
    ret *= gyaku_kaijo(n-r); ret %= MOD;
  }else{
    rep(i,r){
      ret *= n-i; ret %= MOD;
      ret *= mpow(r-i, MOD-2); ret %= MOD;
    }
  }
  return ret;
}

/*std::mt19937 mt{ std::random_device{}() };

std::uniform_int_distribution<int> dist(1, 6);
dist(mt);

while(1){
	val;
	cout << val << endl;
	sol1 = solver1();
	sol2 = solver2();
	if(sol1==sol2){
	cout << "OK" << endl;
	}else{
	cout << "NG" << endl;
	cout << sol1 << endl;
	cout << sol2 << endl;
	break;
	}
}
*/

int main(void){
  fast_io
  cout<<fixed<<setprecision(15);
  int n, x, t;
  cin >> n >> x >> t;
  if(n%x == 0){
	  cout << n/x*t << endl;
  }else{
	  cout << int(n/x+1)*t << endl;
  }
  return 0;
}


Measured memory_bytes: 3640
import java.util.*;

public class Main {
	static final int r = 1000000007;
	static int n;
	static long fact[], finv[], inv[];

	public static long modinv(long a) {
		long b = r, u = 1, v = 0;
		while (b != 0) {
			long t = a / b;
			a -= t * b;
			long tmp = a;
			a = b;
			b = tmp;
			u -= t * v;
			tmp = u;
			u = v;
			v = tmp;
		}
		u %= r;
		if (u < 0)
			u += r;
		return u;
	}

	public static void cominit() {
		fact[0] = fact[1] = 1;
		finv[0] = finv[1] = 1;
		inv[1] = 1;
		for (int i = 2; i < n + 2; ++i) {
			fact[i] = fact[i - 1] * i % r;
			inv[i] = r - inv[r % i] * (r / i) % r;
			finv[i] = finv[i - 1] * inv[i] % r;
		}
	}

	public static long comb(int n, int k) {
		if (n < k)
			return 0;
		if (k < 0 || n < 0)
			return 0;
		if (k == 0)
			return 1;

		return fact[n] * (finv[k] * finv[n - k] % r) % r;
	}


	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		n = sc.nextInt();
		int k = sc.nextInt();
		fact = new long[n + 2];
		finv = new long[n + 2];
		inv = new long[n + 2];
		cominit();
 		sc.close();
		for(int i = 1; i <= k; ++i) {
			long ans = comb(n - k + 1, i);
			long t = comb(k - 1, i - 1);
			ans *= t;
			ans %= r;
			System.out.println(ans);
		}

	}
}


Measured memory_bytes: 22612
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
const int INF = (1<<30);
const ll INFLL = (1ll<<60);
const ll MOD = (ll)(1e9+7);

#define l_ength size

void mul_mod(ll& a, ll b){
	a *= b;
	a %= MOD;
}

void add_mod(ll& a, ll b){
	a = (a<MOD)?a:(a-MOD);
	b = (b<MOD)?b:(b-MOD);
	a += b;
	a = (a<MOD)?a:(a-MOD);
}

int main(void){
	int n,i,ans=0;
	string s,t;
	cin >> s;
	cin >> t;
	for(i=0; i<3; ++i){
		if(s[i]==t[i]){
			++ans;
		}
	}
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 256
#include <iostream>

using namespace std;

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

	int cnt = 0;
	while (N > 1) cnt++,N /= 2;

	int ans = 1;
	while (cnt > 0) ans *= 2,cnt--;
	
	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 256
/*A - Lucky 7*/

#include <bits/stdc++.h>
using namespace std;

int main(){

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

	bool can = false;
	string cad;


	cin >> cad;

	for (int i = 0; i < cad.size(); ++i)
	{
		if(cad[i] == '7'){
			can = true;
			break;
		}
	}

	if(can)
		cout << "Yes";
	else
		cout << "No";


	return 0;
}

Measured memory_bytes: 3636
N, M = map(int, input().split())
Ks = [list(map(int, input().split())) for _ in range(M)]
P = list(map(int, input().split()))

pat = [ format(i, '0'+ str(N) + 'b') for i in range(pow(2, N))]
count = 0

for p in pat:
#     print('--- '+p)
    breaked = False
    for i in range(M):
        cnt = 0
#         print('== ' + str(i))
        for s in Ks[i][1:]:
#             print(s, p[s-1])
            if p[s-1] == '1':
                cnt += 1
#         if cnt == 0 or cnt % 2 != P[i]:
        if cnt % 2 != P[i]:
            breaked = True
#             print('break', cnt, P[i])
            break
    if not breaked:
        count += 1

        
print(count)

Measured memory_bytes: 3064
N=int(input())
S=input()
slst=[s for s in S]
Q=int(input())

class Bit:
    def __init__(self, n):
        self.size = n
        self.tree = [0] * (n + 1)
 
    def sum(self, i):
        s = 0
        while i > 0:
            s += self.tree[i]
            i -= i & -i
        return s
 
    def add(self, i, x):
        while i <= self.size:
            self.tree[i] += x
            i += i & -i
 
bits=[Bit(N) for _ in range(26)]

for i in range(N):
    ch=ord(S[i])-ord('a')
    bits[ch].add(i+1,1)

for _ in range(Q):
    t,a,b=input().split()

    if t=='1':
        a=int(a)
        pos=a-1
        nextc=ord(b)-ord('a')
        beforec=ord(slst[pos])-ord('a')

        if nextc!=beforec:
            bits[beforec].add(a,-1)
            bits[nextc].add(a,1)
            slst[pos]=b
            
    else:
        l=int(a)
        r=int(b)

        cnt=[0]*26

        for i in range(26):
            cnt[i]+=bits[i].sum(r)
        
        if l-1>0:
            for i in range(26):
                cnt[i]-=bits[i].sum(l-1)
        
        ans=0

        for i in range(26):
            if cnt[i]>0:
                ans+=1
        
        print(ans)


Measured memory_bytes: 217972
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const double pi = acos(-1);
#define FOR(i,a,b) for (ll i=(a),__last_##i=(b);i<__last_##i;i++)
#define RFOR(i,a,b) for (ll i=(b)-1,__last_##i=(a);i>=__last_##i;i--)
#define REP(i,n) FOR(i,0,n)
#define RREP(i,n) RFOR(i,0,n)
#define __GET_MACRO3(_1, _2, _3, NAME, ...) NAME
#define rep(...) __GET_MACRO3(__VA_ARGS__, FOR, REP)(__VA_ARGS__)
#define rrep(...) __GET_MACRO3(__VA_ARGS__, RFOR, RREP)(__VA_ARGS__)
template<typename T> ostream& operator<<(ostream& os, const vector<T>& v) {
REP(i,v.size()){if(i)os<<" ";os<<v[i];}return os;}
template<typename T> ostream& operator<<(ostream& os, const vector<vector<T>>& v) {
REP(i,v.size()){if(i)os<<endl;os<<v[i];}return os;}
char del=' ';

int main() {
    // メインプログラムここから
    string a,b,c;
    cin >> a>>b>>c;
    cout << a[0] << b[0] << c[0]<< endl;
    // ここまで
}


Measured memory_bytes: 256
#include<stdio.h>
#include <stdlib.h>
#include<string.h>
#include<math.h>
#define loop(i, l, r) for(i=l; i<r; i++)/*Instead of function, (for).*/
#define rep(i,r) for(i=0; i<r; i++)
#define Max(a, b) ((a) > (b) ? (a) : (b))
#define Min(a, b) ((a) < (b) ? (a) : (b))
typedef long long int lli;
/*Return Combination ,(nCr)*/
int combi(int n, int r)
{
	if(r==0 || r==n) return 1;
	else return combi(n-1,r) + combi(n-1,r-1);
}
/*Return gcd(a, b)*/
int gcd(int a, int b){
	if(b == 0) return a;
	else return gcd(b, a % b);
}
int main(void)
{
	int n, i, satis=0;
	scanf("%d", &n);
	int a[n+1], b[n], c[n-1];

	rep(i,n) scanf("%d", &a[i]);
	rep(i,n) scanf("%d", &b[i]);
	rep(i,n-1) scanf("%d", &c[i]);

	int old = a[0];
	rep(i,n){
		satis += b[a[i] - 1];
		if(a[i] == old + 1){
			satis += c[old - 1];
		}
		old = a[i];
	}
	printf("%d", satis);
	return 0;
}

Measured memory_bytes: 128
#include <iostream>

using namespace std;

int main()
{
    int n,ans=0,p=0;
    cin>>n;
    int a[n];
    bool o=1,b=1,c=1,d=1,e=1,f=1,g=1,h=1;
    for(int i=0;i<n;i++){
        cin>>a[i];
        if(1<=a[i]&&a[i]<=399&&o) ans++,o=0;
        if(400<=a[i]&&a[i]<=799&&b) ans++,b=0;
        if(800<=a[i]&&a[i]<=1199&&c) ans++,c=0;
        if(1200<=a[i]&&a[i]<=1599&&d) ans++,d=0;
        if(1600<=a[i]&&a[i]<=1999&&e) ans++,e=0;
        if(2000<=a[i]&&a[i]<=2399&&f) ans++,f=0;
        if(2400<=a[i]&&a[i]<=2799&&g) ans++,g=0;
        if(2800<=a[i]&&a[i]<=3199&&h) ans++,h=0;
        if(a[i]>=3200) p++;



    }
    if(ans==0){
        ans=1;
        cout<<ans<<" "<<p<<endl;
    }else{
    cout<<ans<<" "<<ans+p<<endl;}

    return 0;
}


Measured memory_bytes: 256
macro_rules ! input { ( source = $ s : expr , $ ( $ r : tt ) * ) => { let mut iter = $ s . split_whitespace ( ) ; input_inner ! { iter , $ ( $ r ) * } } ; ( $ ( $ r : tt ) * ) => { let s = { use std :: io :: Read ; let mut s = String :: new ( ) ; std :: io :: stdin ( ) . read_to_string ( & mut s ) . unwrap ( ) ; s } ; let mut iter = s . split_whitespace ( ) ; input_inner ! { iter , $ ( $ r ) * } } ; }
macro_rules ! input_inner { ( $ iter : expr ) => { } ; ( $ iter : expr , ) => { } ; ( $ iter : expr , mut $ var : ident : $ t : tt $ ( $ r : tt ) * ) => { let mut $ var = read_value ! ( $ iter , $ t ) ; input_inner ! { $ iter $ ( $ r ) * } } ; ( $ iter : expr , mut $ var : ident $ ( $ r : tt ) * ) => { let mut $ var = $ iter . next ( ) . unwrap ( ) . parse ::< usize > ( ) . unwrap ( ) ; input_inner ! { $ iter $ ( $ r ) * } } ; ( $ iter : expr , $ var : ident : $ t : tt $ ( $ r : tt ) * ) => { let $ var = read_value ! ( $ iter , $ t ) ; input_inner ! { $ iter $ ( $ r ) * } } ; ( $ iter : expr , $ var : ident $ ( $ r : tt ) * ) => { let $ var = $ iter . next ( ) . unwrap ( ) . parse ::< usize > ( ) . unwrap ( ) ; input_inner ! { $ iter $ ( $ r ) * } } ; }
macro_rules ! read_value { ( $ iter : expr , ( $ ( $ t : tt ) ,* ) ) => { ( $ ( read_value ! ( $ iter , $ t ) ) ,* ) } ; ( $ iter : expr , [ $ t : tt ; $ len : expr ] ) => { ( 0 ..$ len ) . map ( | _ | read_value ! ( $ iter , $ t ) ) . collect ::< Vec < _ >> ( ) } ; ( $ iter : expr , chars ) => { read_value ! ( $ iter , String ) . chars ( ) . collect ::< Vec < char >> ( ) } ; ( $ iter : expr , usize1 ) => { read_value ! ( $ iter , usize ) - 1 } ; ( $ iter : expr , $ t : ty ) => { $ iter . next ( ) . unwrap ( ) . parse ::<$ t > ( ) . unwrap ( ) } ; }

fn main() {
    input! {
        n: usize,
        m: usize,
        es: [(usize1, usize1); m],
    }
    let mut g = Vec::with_capacity(n);
    for _ in 0..n {
        g.push(Vec::new());
    }
    for e in es {
        g[e.0].push(e.1);
        g[e.1].push(e.0);
    }
    for v in g {
        println!("{}", v.len());
    }
}


Measured memory_bytes: 4352
countBlue :: Integer -> Integer -> Integer -> Integer
countBlue n a b = let (d,m) = n `divMod` (a+b) in (a*d) + (minimum [a,m])
--   | n > a+b   = a + (countBlue (n-a-b) a b)
--   | n < a     = n
--   | otherwise = a

main = do
   [n,a,b] <- map read . words <$> getLine
   putStrLn $ show $ countBlue n a b

Measured memory_bytes: 508
import sys
input = sys.stdin.buffer.readline

INF = 10 ** 18

A, B, M = map(int, input().split())
a = [INF] + list(map(int, input().split()))
b = [INF] + list(map(int, input().split()))
xyc = [list(map(int, input().split())) for _ in range(M)]

answer = INF
for x, y, c in xyc:
    answer = min(answer, a[x] + b[y] - c)

a.sort()
b.sort()
answer = min(answer, a[0] + b[0])

print(answer)

Measured memory_bytes: 68832
#include "bits/stdc++.h"
using namespace std;
#define ll long long int
#define rep(i,n) for( int i = 0; i < n; i++ )
#define rrep(i,n) for( int i = n; i >= 0; i-- )
#define REP(i,s,t) for( int i = s; i <= t; i++ )
#define RREP(i,s,t) for( int i = s; i >= t; i-- )
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define INF 2000000000
#define mod 1000000007
#define INF2 1000000000000000000

vector<int> G[200010];

int N, K;

int height[200010];

void dfs(int parent, int a, int depth) {
	height[a] = depth;
	rep(i, G[a].size()) {
		if (G[a][i] != parent) {
			dfs(a, G[a][i], depth + 1);
		}
	}
}
int A[200010];
	int B[200010];
int main(void)
{
	cin.tie(0);
	ios::sync_with_stdio(false);

	cin >> N;

	rep(i, N - 1) {
		cin >> A[i] >> B[i];
        A[i]--; B[i]--;
		G[A[i]].push_back(B[i]);
		G[B[i]].push_back(A[i]);
	}
    int u = -1;
    int len = -1;
    dfs(-1, 1, 0);
    rep(i, N) {
        if (len < height[i]) {
            len = height[i];
            u = i;
        }
    }
    //cout << u << endl;
    rep(i, 200010) height[i] = 0;
    dfs(-1, u, 0);
	int D = 0;
    rep(i, N) D = max(D, height[i]);
    //cout << D << endl;
    if (D % 3 == 1) {
        cout << "Second" << endl;
    } else {
        cout << "First" << endl;
    }



	return 0;
}


Measured memory_bytes: 25984
N = int(input())
A = list(map(int, input().split()))
L = [[] for i in range(N)]
for i in range(N):
    L[i] = [A[i], i+1]
L.sort()
ans = [0 for i in range(N)]
for i in range(N):
    ans[i] = L[i][1]
print(*ans)



Measured memory_bytes: 23604
S = input()
P = ['dream', 'dreamer', 'erase', 'eraser']
s = S
for i in range(10**5):
    flg = True
    for p in P:
        if s[len(s)-len(p):] == p:
            s = s[:len(s)-len(p)]
            flg = False
            break
    if flg:
         print('NO')
         quit()
    if len(s) == 0:
        break
print('YES')


Measured memory_bytes: 3316
#include <iostream>
#include <vector>
#include <cmath>
#include <iomanip>
#include <algorithm>
using namespace std;
#define rep(i,n) for(int i=0; i<(n); i++)

int main() {
	int n,a=0,b=0;
	cin>>n;
	vector<int>p(n);
	rep(i,n)cin>>p[i];
	sort(p.begin(),p.end(),greater<int>());
	rep(i,n){
	    if(i%2==0)a+=p[i];
	    else b+=p[i];
	}
	cout<<a-b;
	return 0;
}

Measured memory_bytes: 256