akhauriyash/Code-Regression huggingface dataset:
#include<cstdio>
#include<algorithm>
#include<vector>
using namespace std;
int n, C[101000], ck, cc;
long long S[101000], R[101000], SS;
vector<int>E[101000], Num[101000];
void DFS(int a, int pp, int num) {
	int i;
	C[a] = 1;
	for (i = 0; i < E[a].size(); i++) {
		if (E[a][i] == pp)continue;
		DFS(E[a][i], a, Num[a][i]);
		C[a] += C[E[a][i]];
	}
	if (pp) {
		if (C[a] * 2 == n)ck = num, cc = C[a];
		else {
			R[num] = (S[a] - S[pp]) / (n - C[a] * 2);
			SS -= C[a] * R[num];
		}
	}
}
int main() {
	int i, a, b;
	scanf("%d", &n);
	for (i = 1; i < n; i++) {
		scanf("%d%d", &a, &b);
		E[a].push_back(b);
		E[b].push_back(a);
		Num[a].push_back(i);
		Num[b].push_back(i);
	}
	for (i = 1; i <= n; i++)scanf("%lld", &S[i]);
	SS = S[1];
	DFS(1, 0, -1);
	if (ck)R[ck] = SS / cc;
	for (i = 1; i < n; i++)printf("%lld\n", R[i]);
}

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

int main(){
    int N;
    cin>>N;
    
    int a[N];
    for(int i=0;i<N;i++) cin>>a[i];
    
    int count=0;
    for(int i=0;i<N;i++){
        if(a[i+1]==a[i]){count++;i++;}
    }
    
    cout<<count<<endl;
}

Measured memory_bytes: 256
#include<iostream>
#include<stdio.h>
#include<cstring>
#include<cmath>
#include<vector>
#include<set>
#include<map>
#include<algorithm>
#include<unordered_map>
#include<bits/stdc++.h>
#define ll long long 
#define d double
using namespace std;
 
int main()
{
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  
  int n;
  cin>>n;
  int i;
  for(i=1;i<10;i++){
  	int j;
  	for(j=1;j<10;j++){
  		
  		int p=i*j;
  		if(p==n){
  			cout<<"Yes"<<endl;
  			return 0;
		  }
  		
  		
	  }
  	
  }
  
    cout<<"No"<<endl;
  
  
  return 0;
}

Measured memory_bytes: 3644
using System;
using System.Collections.Generic;
using System.Drawing;
using System.Linq;
using System.Runtime.CompilerServices;
using System.Text;
using System.Threading.Tasks;

namespace ConsoleApp1
{
    class Program
    {
        static void Main(string[] args)
        {
            long N = long.Parse(Console.ReadLine());
            long K = long.Parse(Console.ReadLine());
            long[] x = Console.ReadLine().Split(' ').Select(i => long.Parse(i)).ToArray();
            long total = 0;
            for(int j = 0; j < N; j++)
            {
                total += Math.Min(Math.Abs(x[j] -0), Math.Abs(x[j] - K))*2;
            }
            Console.WriteLine(total);
        }
    }
}
// 文字列の入力
//string s = Console.ReadLine();

// 整数の入力
//long n = long.Parse(Console.ReadLine());

// 文字列配列の入力
//string[] inputStrArray = Console.ReadLine().Split(' ');

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

//Console.WriteLine(ans);


Measured memory_bytes: 28180
from collections import defaultdict
import numpy as np

N = int(input())
A = np.fromstring(input(), np.int, sep=" ")

uniq_count = defaultdict(int)
for a in A:
    uniq_count[a] += 1
uniq = np.fromiter((uniq_count.keys()), np.int)
counts = np.fromiter(uniq_count.values(), np.int)

p = lambda n: n * (n - 1) // 2

n = p(counts)
m = p(counts - 1)

ans = n.sum() - n + m

mapping = dict(zip(uniq, ans))

for a in A:
    print(mapping[a])


Measured memory_bytes: 44920
#include <iostream>
#include <fstream>
#include <string>
#include <vector>
#include <algorithm>
#include <math.h>
#include <climits>
#include <assert.h>
#include <cstring>
#include <set>
using namespace std;

typedef long long ll;

int main()
{
    char c[200001];
    int n;
    int ans = 0;
    cin >> n;
    cin >> c;
    int left = 0;
    int right = n-1;
    while(left < right)
    {
        while(left < n-1 && c[left] == 'R')
        {
            left++;
        }
        while(right >= 0 && c[right] == 'W')
        {
            right--;
        }
        if(left >= right)break;
        c[left] = 'R';
        c[right] = 'W';
        ans++;
    }
    cout << ans;
    
}

Measured memory_bytes: 3760
from itertools import product

N = int(input())
S = input()

cnt = 0
for i, j, k in product(range(10), repeat=3):
    x = S.find(str(i))
    if x == -1:
        continue
    y = S.find(str(j), x + 1)
    if y == -1:
        continue
    z = S.find(str(k), y + 1)
    if z == -1:
        continue
    cnt += 1

print(cnt)


Measured memory_bytes: 3060
import java.util.*

fun main(args: Array<String>) {
    val sc = Scanner(System.`in`)
    val n = sc.nextInt()
    val x = sc.nextInt()
    var ans = 1
    var cur = 0
    repeat(n) {
        val l = sc.nextInt()
        cur += l
        if (cur <= x) {
            ans++
        }
    }
    println(ans)
}

Measured memory_bytes: 31140
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
int main(){
  int n,a;
  double t;
  cin >> n >> t >> a;
  vector<double> x(n);
  
  for (int i=0;i<n;i++){
    double h;
    cin >> h;
    x[i] = abs(t-h*6/1000-a);
  }
  
  int ans =0;
  
  for (int i=1;i<n;i++){
    if(x[ans]>x[i]) ans = i;
  }
  
  cout << ans+1 << endl;
  
    
    
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for (int (i) = 0; (i) <(n); (i)++) 
#define so(v) sort(v.begin(),v.end())
using ll = long long;
using vi=vector<int>;
using vii=vector<vi>;
const int MAX = 510000;
const int MOD = 1000000007;
ll gcd(ll a, ll b)
{
   if (a%b == 0)
   {
       return(b);
   }
   else
   {
       return(gcd(b, a%b));
   }
}
ll lcm(ll a, ll b)
{
   return a * b / gcd(a, b);
}
long long fac[MAX], finv[MAX], inv[MAX];
// テーブルを作る前処理
void COMinit() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (int i = 2; i < MAX; i++){
        fac[i] = fac[i - 1] * i % MOD;
        inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
        finv[i] = finv[i - 1] * inv[i] % MOD;
    }
}
// 二項係数計算
long long com(int n, int k){
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}
/*
* 素因数分解
* @param [in] n   自然数
* @param [in] out 素因数分解した数が入る
*/
template<typename T>
void PrimeFactors(T n, std::map<T,T> &out)
{
	while (n % 2 == 0)
	{
		++out[2];
		n = n / 2;
	}

	for (T i = 3; i <= sqrt(n); i = i + 2)
	{
		while (n%i == 0)
		{
			++out[i];
			n = n / i;
		}
	}

	if (n > 2)
		++out[n];
}
vector<int> to[20009];
vector<int> ans;
void dfs(int i,int j=-1){
    for(int v:to[i]){
        if(v==j)continue;
        ans[v]+=ans[i];
        dfs(v,i);
    }
}
int main(void){ 
    int n,q;cin>>n>>q;
    rep(i,n-1){
        int k,m;
        cin>>k>>m;
        to[k-1].push_back(m-1);
        to[m-1].push_back(k-1);
    }
    ans.resize(n);
    rep(i,q){
        int p,x;
        cin>>p>>x;
        p--;
        ans[p]+=x;
    }
    dfs(0);
    rep(i,n){
        cout<<ans[i]<<endl;
    }
}



Measured memory_bytes: 24960
#include <bits/stdc++.h>
#pragma GCC optimize("unroll-loops,no-stack-protector")
#pragma GCC target("sse,sse2,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#define watch(x) cout << (#x) << " is " << (x) << endl

typedef long long ll;
typedef long double ld;
using namespace std;

const int MOD = 1e9 + 7;

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    ld best = INT_MAX;
    int besti, n;
    ld t, a;
    cin >> n >> t >> a;
    vector<ld> h(n);
    for(int i = 0; i < n; i++)
    {
        cin >> h[i];
    }
    for(int i = 0; i < n; i++)
    {
        if(abs(t - h[i] * 3 / 500 - a) < best)
        {
            besti = i;
            best = abs(t - h[i] * 3 / 500 - a);
        }
    }
    cout << besti + 1;

    return 0;
}


Measured memory_bytes: 256
#include <cstdio>
#include <cstdint>
#include <vector>
#include <algorithm>
#include <queue>

template <class T>
using greater_queue=std::priority_queue<T, std::deque<T>, std::greater<T>>;

std::vector<intmax_t> greedy(const std::vector<intmax_t> &a) {
  greater_queue<intmax_t> q;
  size_t N=a.size()/3;

  intmax_t sum=0;
  for (size_t i=0; i<N; ++i) {
    q.emplace(a[i]);
    sum += a[i];
  }

  std::vector<intmax_t> res{sum};
  for (size_t i=N; i<N+N; ++i) {
    q.emplace(a[i]);
    sum += a[i];
    sum -= q.top();
    q.pop();
    res.push_back(sum);
  }

  return res;
}

int main() {
  size_t N;
  scanf("%zu", &N);

  std::vector<intmax_t> a(3*N), b(3*N);
  for (size_t i=0; i<3*N; ++i) {
    scanf("%jd", &a[i]);
    b[3*N-i-1] = -a[i];
  }

  std::vector<intmax_t> aa=greedy(a), bb=greedy(b);
  std::reverse(bb.begin(), bb.end());

  intmax_t res=-1e15;
  for (size_t i=0; i<aa.size(); ++i)
    res = std::max(res, aa[i]+bb[i]);

  printf("%jd\n", res);
}


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

typedef long long ll;
typedef vector<ll> vint;
typedef vector< vector<ll> > vvint;

#define rep(i,n) for(ll i=0;i<n;i++)
#define repf(i,f,n) for(ll i=f;i<n;i++)
#define repr(i,n) for(ll i=n-1;i>=0;i--)
#define mp make_pair
#define mt make_tuple
#define ALL(obj) (obj).begin(), (obj).end()
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }

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


int main() {
    cout<<fixed<<setprecision(10);

    ll n; cin>>n;
    vint a(n); rep(i,n) cin>>a[i];

    sort(ALL(a), greater<ll>());
    map<ll,ll> cnt;
    for(auto e:a) cnt[e]++;
    ll maxval = a.front();
    ll minval = a.back();


    // if(cnt[maxval] == 1){puts("Impossible"); return 0;}
    if((maxval+1)/2 != minval){puts("Impossible"); return 0;}


    if(maxval%2 == 0){
        if(cnt[minval] != 1){puts("Impossible"); return 0;}
        for(ll i = minval+1; i<=maxval; i++){
            if(cnt[i]<2){puts("Impossible"); return 0;}
        }
    }else{
        if(cnt[minval] != 2){puts("Impossible"); return 0;}
        for(ll i = minval+1; i<=maxval; i++){
            if(cnt[i]<2){puts("Impossible"); return 0;}
        }
    }

    puts("Possible");




    return 0;

}

Measured memory_bytes: 384
#include <iostream>
#include <unordered_map>

using namespace std;

int main() {
  unordered_map<char, char> m;
  m['A'] = 'T';
  m['T'] = 'A';
  m['C'] = 'G';
  m['G'] = 'C';
  
  char b;
  cin >> b;
  cout << m[b] << '\n';

  return 0;
}

Measured memory_bytes: 384
#include<bits/stdc++.h>
using namespace std;
typedef long long LL;
int main() {
  int n;
  cin >> n;
  int a[n];
  LL p1 = 0, p2 = 0;
  for(int i = 0; i < n; ++i) {
    cin >> a[i];
    if(i) p2 += a[i];
    else p1 += a[i];
  }
  
  LL ans = abs(p1 - p2);
  
  for(int i = 1; i < n - 1; ++i) {
    p1 += a[i];
    p2 -= a[i];
    if(abs(p1 - p2) < ans) ans = abs(p1 - p2);
  }
  
  cout << ans << endl;
  return 0;
}
  


Measured memory_bytes: 1024
#include<iostream>
#include<stdio.h>
#include<string>
#include<vector>
#include<map>
#include<tuple>
#include<algorithm>
#include<cmath>
#include<limits>
#include<set>
#include<queue>
using namespace std;
#define int long  long int
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
int gcd(int a, int b) { return b ? gcd(b, a % b) : a; }
int lcm(int a, int b) { return a / gcd(a, b) * b; }
typedef pair<int, int>P;
const int INF = 1e8;

signed main() {
	int N, M;
	cin >> N >> M;
	vector<bool>itikara(N, false), nmade(N, false);
	rep(i, M) {
		int a, b;
		cin >> a >> b;
		if (a == 1)itikara[b - 1] = true;
		else if (b == N)nmade[a - 1] = true;
	}
	rep(i, N) {
		if (itikara[i] && nmade[i]) {
			cout << "POSSIBLE";
			return 0;
		}
	}
	cout << "IMPOSSIBLE";
}

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

using namespace std;


#define M_DEBUG if(0)


template <typename T>
T gcd(T x, T y)
{
	return y == 0 ? x : __gcd(y, x % y);
}

vector<unsigned long long int> getFactors(unsigned long long int pN) {
	unsigned long long int n = pN;
	vector<unsigned long long int> ret;
	if (n % 2 == 0) {
		ret.push_back(2);
		while (n % 2 == 0) {
			n /= 2; // 素因数分解ならここで割れた回数をカウントして、素数とのpairをmapにinsertする
		}
	}
	for (unsigned long long int i = 3; i * i <= n; i += 2) {
		if (n % i != 0) continue;
		
		/* // 素数判定は不要。最小約数を順にチェックしているから、かならず素数
		bool isPrime = true;
		for (auto j : ret) {
			if (i * i < j) break;
			if (i % j == 0) {
				isPrime = false;
				break;
			}
		}
		if (isPrime) {
			ret.push_back(i);
			while (n % i == 0) {
				n /= i; // 素因数分解ならここで割れた回数をカウントして、素数とのpairをmapにinsertする
			}
		} 
		*/
		ret.push_back(i);
		while (n % i == 0) {
			n /= i; // 素因数分解ならここで割れた回数をカウントして、素数とのpairをmapにinsertする
		}
	}

	// あまり
	if (n > 1) ret.push_back(n);

	M_DEBUG {
		cout << "Factors < " << pN << ": " << endl;
		for (auto a : ret) {
			cout << a << ", ";
		}
		cout << endl;
	}
	return ret;
}


int main() {
	unsigned long long int a=0, b=0;
	cin >> a >> b;
	assert(a > 0 && a <= pow(10, 12));
	assert(b > 0 && b <= pow(10, 12));

	vector<unsigned long long int> factors = getFactors(gcd(a, b));
	// 1 は条件から固定
	M_DEBUG {
		cout << 1 ;
		for (int p: factors) { 
			cout << " " << p;
		}
		cout << endl;
	}

	cout << factors.size() + 1 << endl;

	return 0;
}

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

using namespace std;

using ll = long long;

template <class T>
using grid = vector<vector<T>>;

#define REP(i,n) for(ll i=0;i<(ll)(n);i++)
#define REPD(i,n) for(ll i=n-1;i>=0;i--)
#define FOR(i,a,b) for(ll i=a;i<=(ll)(b);i++)
#define FORD(i,a,b) for(ll i=a;i>=(ll)(b);i--)

#define input(...) __VA_ARGS__; in(__VA_ARGS__)

void print() {
  std::cout << std::endl;
}

template <class Head, class... Tail>
void print(Head&& head, Tail&&... tail) {
  std::cout << head << " ";
  print(std::forward<Tail>(tail)...);
}

void in() { }

template <class Head, class... Tail>
void in(Head&& head, Tail&&... tail) {
  cin >> head;
  in(std::forward<Tail>(tail)...);
}

int main() {
  int input(x, y);
  bool flg = true;
  REP(i, x + 1) {
    if (i * 2 + (x - i) * 4 == y) {
      print("Yes");
      flg = false;
      break;
    }
  }

  if(flg) print("No");
}


Measured memory_bytes: 3632
#include<bits/stdc++.h>
using namespace std;
int main(){
    int N;
    cin >> N;
    int temp;
    int ans = 0; 
    int v[N];
    for(int i=0;i<N;i++){
        cin >> v[i];
    }
    cout << endl;
    sort(v,v+N);
    for(int i=0;i<N-2;i++){
        for(int j=i+1;j<N-1;j++){
            for(int k=j+1;k<N;k++){
                //cout << v[i] << " " << v[j] << " " << v[k]<< endl;
                if(v[i]+v[j]>v[k]&&v[k]>v[j]&&v[j]>v[i]){
                    ans++;
                    //cout << "+" <<endl;
                }
            }
        }
    }
    cout << ans;
    return 0;
}


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

int main(){
	int N;
	string S;
	cin >> N >> S;
	vector<int> b(N+1,0);
	for(int i=0;i<N;i++){
		b[i+1]=b[i];
		if(S[i]=='#')b[i+1]++;
	}
	
	int ans=N;
	
	for(int i=0;i<=N;i++){
		int tmp=0;
		
		tmp+=b[i];
		tmp+=(N-i)-(b[N]-b[i]);
		
		ans=min(ans,tmp);
	}
	cout << ans << endl;
	return 0;
}

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

using namespace std;

struct UnionFind
{
  vector< int > data;

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

  bool unite(int x, int y)
  {
    x = find(x), y = find(y);
    if(x == y) return (false);
    swap(x, y);
    data[x] += data[y];
    data[y] = x;
    return (true);
  }

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

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

// A[i]*2 ≧ A[j]

int main()
{
  int N, A[100000];

  cin >> N;
  for(int i = 0; i < N; i++) {
    cin >> A[i];
  }

  sort(A, A + N);

  int last = 0;
  long long sum = 0;
  for(int i = 0; i < N; i++) {
    if(A[i] > sum * 2) {
      last = i;
    }
    sum += A[i];
  }

  cout << N - last << endl;


}

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

p = [1]*(100000+1)
p[0]=0
p[1]=0
        

for j in range(2,int(100000**0.5+1)):
    if p[j] == 0:
        continue
    for i in range(2,100000+1):
        if i!=j and i%j == 0:
            p[i] = 0
for i in range(100000-1, 1,-2):
    if p[int((i+1)/2)] == 0:
        p[i] = 0
p[2] = 0
for i in range(2,100000):
    p[i+1] += p[i]  

for i in range(n):
    l,r= map(int,input().split())
    print(p[r] - p[l -1])

Measured memory_bytes: 6772
#include<iostream>
using namespace std;
#include<algorithm>
#include<vector>
struct bimatch{
	int n;
	vector<vector<int> >G;
	vector<int>match;
	vector<bool>used;
	bimatch(int _n=0):n(_n),G(n),match(n),used(n){}
	void add_edge(int u,int v)
	{
		G[u].push_back(v);
		G[v].push_back(u);
	}
	bool dfs(int v)
	{
		used[v]=true;
		for(int u:G[v])

		{
			int w=match[u];
			if(w<0||!used[w]&&dfs(w))
			{
				match[v]=u;
				match[u]=v;
				return true;
			}
		}
		return false;
	}
	int count()
	{
		int ans=0;
		fill(match.begin(),match.end(),-1);
		for(int v=0;v<n;v++)
		{
			if(match[v]<0)
			{
				fill(used.begin(),used.end(),false);
				if(dfs(v))ans++;
			}
		}
		return ans;
	}
};
int n,m;
int g(int a,int b){return b?g(b,a%b):a;}
main()
{
	while(cin>>n>>m,n)
	{
		vector<int>a(n),b(m);
		for(int i=0;i<n;i++)cin>>a[i];
		for(int i=0;i<m;i++)cin>>b[i];
		bimatch P(n+m);
		for(int i=0;i<n;i++)
		{
			for(int j=0;j<m;j++)
			{
				if(g(a[i],b[j])>1)P.add_edge(i,n+j);
			}
		}
		cout<<P.count()<<endl;
	}
}



Measured memory_bytes: 4424
/**
 *  http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=ALDS1_1_D
 */
#include <iostream>

using namespace std;

int
main()
{
    ios_base::sync_with_stdio(false);

    int n;
    cin >> n; cin.ignore();

    int bot = 2000000000;
    int gain = -1000000000;
    for (int i = 0; i < n; i++) {
        int r;
        cin >> r; cin.ignore();
        if (r - bot > gain) gain = r - bot;
        if (bot > r) bot = r;
    }
    cout << gain << endl;

    return 0;
}

Measured memory_bytes: 3172
import sys
input = lambda: sys.stdin.readline().rstrip()
input_nums = lambda: list(map(int, input().split()))

def main():
    N, M = input_nums()
    A = input_nums()
    total = sum(A)
    h = total/(4*M)
    if len([a for a in A if a >= h]) >= M: print('Yes')
    else: print('No')


if __name__ == '__main__':
    main()


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

int main() {
	int n, p;
	while( cin >> n >> p, n || p ) {
		vector<int>data( n );
		int now = 0, P = p;
		while( 1 ) {

			for( size_t i = 0; i < n; i++ ) {
				data[i] += p / n;
			}

			p %= n;

			for( size_t i = 0; i < p; i++ ) {
				now++;
				now %= n;
				data[now]++;
			}

			now++; now %= n;
			while( !data[now] ) {
				now++; now %= n;
			}
			p = data[now];
			if( P == p ) {
				break;
			}
			data[now] = 0;
			//cout << p << P << endl;
			//cout << data[0] << data[1] << data[2] << endl;
		}
		now--;
		if( now < 0 ) {
			now = n - 1;
		}
		cout << now << endl;
	}
}

Measured memory_bytes: 3104
#include <iostream>
#include <sstream>
#include <fstream>
#include <string>
#include <vector>
#include <tuple>
#include <deque>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <algorithm>
#include <functional>
#include <utility>
#include <bitset>
#include <cmath>
#include <cstdlib>
#include <ctime>
#include <cstdio>
#include <numeric>
#include <string.h>
using namespace std;
const double PI = 3.14159265358979323846;
const double EPS = 1e-12;
const int INF = 1<<29;
const long long INFL = 1e18;
const int MOD = 1000000007;
const int MAX = 210000;
int n, m;

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

void solve() {
    cin >> n >> m;
    vector<vector<int>> s(m);
    vector<int> p(m);
    for (int i = 0; i < m; ++i) {
        int k; cin >> k;
        s[i].resize(k);
        for (int j = 0; j < k; ++j) {
            cin >> s[i][j];
            s[i][j]--;
        }
    }
    for (int i = 0; i < m; ++i) {
        cin >> p[i];
    }
    int ans = 0;
    for (int i = 0; i < (1 << n); ++i) {
        bool ok = true;
        for (int j = 0; j < m; ++j) {
            int cnt = 0;
            for (int id : s[j]) {
                if (i >> id & 1) {
                   cnt++;
                }
            }
            if ((cnt % 2 ) != p[j]) {
                ok = false;
            }
        }
        if (ok) {
            ans++;
        }
    }
    cout << ans << endl;
    return;
}
//逆元を求める関数
long long fac[MAX], finv[MAX], inv[MAX];
void COMinit() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (int i = 2; i < MAX; i++) {
      fac[i] = fac[i-1] * i % MOD;
      inv[i] = MOD - inv[MOD%i] * (MOD/i) % MOD;
      finv[i] = finv[i-1] * inv[i] % MOD;
    }
}
//組み合わせ
long long COM (int n, int k) {
    if(n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n-k] % MOD) % MOD;
}
int main(int args, char* argv[]) {
    solve();
}



Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main()
{
	int a[3];
	int k;
	cin>>a[0]>>a[1]>>a[2]>>k;
	sort(a,a+3);
	for(int i=0;i<k;i++)
	{
		a[2]*=2;
	}
	cout<<a[0]+a[1]+a[2]<<endl;
	return 0;
 } 

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define y second
#define x first
#define lsb(x) (x&-x)
#define pb push_back
#define y second
const int NMAX=2666; //LOL
const int MOD=1000000007; //LOL
const int SQRT=350;
using namespace std;
const int INF=1000000007;
typedef long long LL;
typedef long double LD;
typedef pair<int, int> PII;
typedef pair<LL, LL> PLL;
typedef vector<int> VI;
const int dx[]={-1, 0, 0, 1};
const int dy[]={0, 1, -1, 0};

int n,m,q,a;
VI G[100666];
int k;
int p[100666];
int rs=0;
int dfs(int v)
{
	if(G[v].empty())
		return 0;
	int ymax=-1;
	for(auto w: G[v])
	{
		int y=dfs(w);
		if(y>=k-1+(v==1))
			rs++;
		else
			ymax=max(ymax, y);
	}
	return ymax+1;
}

int main()
{
	//freopen("input.in", "rt", stdin);
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	cin>>n>>k;
	for(int i=1; i<=n; ++i)
		cin>>p[i];
	if(p[1]!=1)
		rs++, p[1]=1;
	for(int i=2; i<=n; ++i)
		G[p[i]].pb(i);
		
	dfs(1);
	
	cout<<rs;	
	return 0;
} 








Measured memory_bytes: 10880
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <iomanip>
#include <queue>
#include <stack>
#include <cstdlib>
#include <map>
#include <iomanip>
#include <set>
#include <functional>
#include <stdio.h>
#include <ctype.h>
#include <random>
#include <string.h>
#include <cmath>
#include <unordered_map>
#include <cstdio>
using namespace std;
#define all(vec) vec.begin(),vec.end()
typedef long long ll;

ll gcd(ll x, ll y) {
	if (y == 0)return x;
	return gcd(y, x%y);
}
ll lcm(ll x, ll y) {
	return x / gcd(x, y)*y;
}
ll kai(ll x, ll y, ll m) {
	ll res = 1;
	for (ll i = x - y + 1; i <= x; i++) {
		res *= i; res %= m;
	}
	return res;
}
ll mod_pow(ll x, ll y, ll m) {
	ll res = 1;
	while (y > 0) {
		if (y & 1) {
			res = res * x % m;
		}
		x = x * x % m;
		y >>= 1;
	}
	return res;
}

ll comb(ll x, ll y, ll m) {
	if (y > x)return 0;
	return kai(x, y, m) * mod_pow(kai(y, y, m), m - 2, m) % m;
}

int n, q, a[500010];
pair<pair<int, int>, int> p[500010];
int b[500010];
int ans[500010];

int BIT[500010];

void add(int k, int x) {
	while (k <= n) {
		BIT[k] += x;
		k += k & -k;
	}
}

int sum(int k) {
	int res = 0;
	while (0 < k) {
		res += BIT[k];
		k -= k & -k;
	}
	return res;
}

signed main() {
	std::random_device rnd;
	std::mt19937_64 mt(rnd());
	cin >> n >> q;
	for (int i = 1; i <= n; i++)cin >> a[i];
	for (int i = 0; i < q; i++)cin >> p[i].first.second >> p[i].first.first, p[i].second = i;
	sort(p, p + q);
	int k = 0;
	for (int i = 1; i <= n; i++) {
		if (b[a[i]])add(b[a[i]], -1);
		add(i, 1);
		b[a[i]] = i;
		while (p[k].first.first == i) {
			ans[p[k].second] = sum(i) - sum(p[k].first.second - 1);
			k++;
		}
	}
	for (int i = 0; i < q; i++)cout << ans[i] << endl;
}

Measured memory_bytes: 17460
#include <iostream>
#include <stdio.h>
#include <bits/stdc++.h>
#include <math.h>
#include <string>
#include <sstream>
#define ll long long
#define F first
#define S second
#define pb push_back
#define ld long double
#define pll pair<long long,long long>
#define pld pair<long double,long double>
#define ios     ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
using namespace std;
ll mod=1000000007;
ll gcd (ll a,ll b)
{
    if(b==0)
        return a;
    else
        return gcd(b,a%b);
}
ll fastexp(ll x ,ll n)
{
    ll result =1;
    while(n>0)
    {
        if(n%2==1)
            result*=x;
        x*=x;
        n=n/2;
    }
    return result;
}

ll modularExp(ll x,ll n,ll mod)
{
    ll result=1;
    while(n>0)
    {
        if(n%2==1)
            result=(result*x)%mod;
        x=((x%mod)*(x%mod))%mod;
        n=n/2;
    }
    return (result)%mod;
}
bool isPrime(ll n)
{
    for(ll i=2;i*i<=n;i++)
        if(n%i==0)
            return false;
    return true;
}
bool mycomp(pll &a,pll &b)
{
    if(a.F!=b.F)
        return a.F < b.F;
    else
        return a.S < b.S;
}

void solve()
{
     ll n;
     cin>>n;
     vector<ld> v(n+1);
     ll i,j;
     for(i=1;i<=n;i++)
          cin>>v[i];
     vector< vector<ld> > dp(n+1,vector<ld>(n+1));
     dp[0][0]=1;
     dp[1][1]=v[1];
     dp[1][0]=1-v[1];
     for(i=2;i<=n;i++)
     {
          dp[i][0]=dp[i-1][0] * (1-v[i]);
          for(j=1;j<=i;j++)
               dp[i][j]=(dp[i-1][j-1]*v[i]+dp[i-1][j]*(1-v[i]));
     }
     ld ans=0;
     for(i=n/2+1;i<=n;i++)
          ans+=dp[n][i];
     cout<<setprecision(12)<<ans<<"\n";
     // for(i=1;i<=n;i++)
     // {
     //      for(j=0;j<=n;j++)
     //           cout<<dp[i][j]<<" ";
     //      cout<<"\n";
     // }
}

int main()
{
    ios;
    ll t;
//    cin>>t;
  t=1;
    while(t--)
        solve();
}

Measured memory_bytes: 141056
#include<iostream>
#include<vector>
#include<map>
#include<cstdio>
#include<string>
#include<algorithm>
#include<cstdlib>
#include<cctype>
#include<string>
using namespace std;
typedef pair<int,int> P;
int solve(string);
int main(){
  int n,ans;
  string s1,s2,ANS;
  cin >> n;
  while(n--){
    cin >> s1 >> s2;
    ans = solve(s1) + solve(s2);
    char HM[10];
    sprintf(HM,"%4d",ans);
    string aa,tmp="mcxi";
    for(int i=0;i<4;i++){
      if(HM[i]>'1') aa += HM[i];
      if(HM[i]>'0') aa += tmp[i];
    }
	
    cout << aa << endl;
  }
}
int solve(string str){
  int cnt = 1,ans = 0;
  for(int i=0;i<str.size();i++){
    if(isdigit(str[i])){
      cnt = str[i]-'0';
      continue;
    }
    if(str[i] == 'm')ans += cnt * 1000;
    else if(str[i] == 'c') ans += cnt * 100;
    else if(str[i] == 'x') ans += cnt * 10;
    else if(str[i] == 'i')ans += cnt;
    cnt = 1;
  }
  return ans;
}

Measured memory_bytes: 1252
from collections import deque
n,m = map(int,input().split())
to = [[] for _ in range(n)]
v = []
for _ in range(m):
    a,b = map(int,input().split())
    a -= 1
    b -= 1
    to[a].append(b)
    to[b].append(a)
    v.append((a,b))
ans = m
seen = [False]*n
stk = deque()
for i in range(m):
    a,b = v[i]
    stk.clear()
    stk.append((a,-1))
    for j in range(n): seen[j] = False
    flag = True
    while stk and flag:
        cur,prev = stk.pop()
        seen[cur] = True
        for nxt in to[cur]:
            if nxt == b:
                if cur == a: continue
                ans -= 1
                flag = False
                break
            if nxt == prev: continue
            if seen[nxt]: continue
            stk.append((nxt,cur))
print(ans)

Measured memory_bytes: 3316
# coding: utf-8
# Your code here!
N=int(input())
X=list(map(int,input().split()))

X2=sorted(X)

for i in range(N):
    if X[i]<X2[N//2]:
        print(X2[N//2])
    else:
        print(X2[N//2-1])



Measured memory_bytes: 25224
#include<bits/stdc++.h>
using namespace std;
#define int 		  long long
#define	pb 			  push_back
#define all(a)		  (a).begin(),(a).end()
#define sz(x)		  (int)x.size()
#define endl	 	  "\n"
#define inf 		  1000000007
#define FOR(i, a, b)  for(int i=a; i<b; i++)
//int dp[1000001] = {0};

void solve(){
	int a, aa, b, k;	
	cin>>a>>b>>k;
	aa = max(0ll, a-k);
	k=max(0ll, k-a);
	b = max(0ll, b-k);
	cout<<aa<<" "<<b<<endl;
}

signed main(){
	ios::sync_with_stdio(false);
	cin.tie(0);
	int t=1;
	//cin>>t;
	FOR(i, 1, t+1){	
	//	cout<<"Case #"<<i<<":"<<endl;
		solve();
	}
	return 0;
 
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define F first
#define S second
#define pb push_back
#define ll long long
#define int long long
const ll INF = 1LL * 1000 * 1000 * 1000 * 1000 * 1000 * 1000;
const int inf = 1000 * 1000 * 1000 + 1000;


set<pair<int, pair<int, int> > > s;

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

    int a, b, c;
    cin >> a >> b >> c;

    int ans = 0;
    while(a % 2 == 0 && b % 2 == 0 && c % 2 == 0 && s.find({a,{b, c}}) == s.end()){
    	int na, nb, nc;
    	s.insert({a, {b, c}});
    	na = a;
    	nb = b;
    	nc = c;
    	a = nb / 2 + nc / 2;
    	b = na / 2 + nc / 2;
    	c = nb / 2 + na / 2;
    	ans++;
    }
    if(s.find({a, {b, c}}) != s.end())
        cout << -1 << '\n';
    else
    	cout << ans << '\n';

	return 0;
}


Measured memory_bytes: 256
# -*- coding: utf-8 -*-

import sys
import math


debug = False

def log(text):
    if debug:
        print(text)

def parse_input(lines_as_string = None):

    global debug
    lines = []
    if lines_as_string is None:
        debug = False
        # for line in sys.stdin:
        #     lines.append(line)
        lines.append(input())
    else:
        debug = True
        lines = [e for e in lines_as_string.split("\n")][1:-1]

    r = int(lines[0])

    return (r, )


def solve(r):

    return r*r

def main():
    # 出力
    result = solve(*parse_input())
    if isinstance(result, list):
        for r in result:
            print("%s" % r, sep='')
    else:
        print("%s" % result, sep='')

if __name__ == '__main__':

    main()
	

Measured memory_bytes: 3064
#include<cstdio>
#include<cstdlib>
#include<algorithm>
using namespace std;

int p[100],q[100],r[100],s[100];

int gcd(int x,int y){
  if(y==0) return x;
  return gcd(y,x%y);
}

int dfs(int v){
  if(v==-1){
    return 1;
  }else{
    long long int right = dfs(r[v]);
    long long int left = dfs(s[v]);
    int g = gcd(p[v],q[v]);
    p[v] /= g; q[v] /= g;
    left *= q[v]; right *= p[v];
    g = gcd(left,right);
    int moment = left*right/g;
    right = moment/p[v]; left = moment/q[v];
    return right + left;
  }
}

int solve(){
  int n,V;
  bool flag[100];
  scanf("%d",&n);
  if(n==0) return -1;
  fill(flag,flag+n,false);
  for(int i=0;i<n;i++){
    scanf("%d %d %d %d",p+i,q+i,r+i,s+i);
    r[i]--; s[i]--;
    if(r[i]>=0) flag[r[i]] = true;
    if(s[i]>=0) flag[s[i]] = true;
  }
  for(int i=0;i<n;i++) if(!flag[i]) V = i;
  int ans = dfs(V);
  printf("%d\n",ans);
  return ans;
}

int main(){
  while(true){
    if(solve()<0) break;
  }
  return 0;
}

Measured memory_bytes: 2728
#include <bits/stdc++.h>
#define _GLIBCXX_DEBUG
using namespace std;
#define REP(i,m,n) for(int i=(int)(m) ; i < (int) (n) ; ++i )
#define rep(i,n) REP(i,0,n)
#define square(x) pow(x 2.0)
#define all(x) (x).begin(),(x).end()
#define F first
#define S second
#define max_queue(x) priority_queue<x>
#define min_queue(x) priority_queue<x, vector<x>, greater<x>>
#define big_sort(v) sort(all(v), [](int a, int b) { return a > b; })//大きい順にソート
using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vs = vector<string>;
// aよりもbが大きいならばaをbで更新する
// (更新されたならばtrueを返す)
template <typename T>
bool chmax(T &a, const T& b) {
  if (a < b) {
    a = b;  // aをbで更新
    return true;
  }
  return false;
}
// aよりもbが小さいならばaをbで更新する
// (更新されたならばtrueを返す)
template <typename T>
bool chmin(T &a, const T& b) {
  if (a > b) {
    a = b;  // aをbで更新
    return true;
  }
  return false;
}
/*
#include <iostream> // cout, endl, cin
#include <string> // string, to_string, stoi
#include <vector> // vector
#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <utility> // pair, make_pair
#include <tuple> // tuple, make_tuple
#include <cstdint> // int64_t, int*_t
#include <cstdio> // printf
#include <map> // map
#include <queue> // queue, priority_queue
#include <set> // set
#include <stack> // stack
#include <deque> // deque
#include <unordered_map> // unordered_map
#include <unordered_set> // unordered_set
#include <bitset> // bitset
#include <cctype> // isupper, islower, isdigit, toupper, tolower
*/

int main() {
  ll n,a,ans=0;
  cin >> n;
  map<ll,ll> mp;
  rep(i,n){
    cin>>a;
    mp[i+a]++;
    if(mp.count(i-a)){ans+=mp[i-a];}
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 16040
#include <iostream>
#include <algorithm>
#include <vector>
#include <map>
using namespace std;

#define rep(i,n) for(int i=0;i<(n);++i)
#define all(f,c,...) (([&](decltype((c)) cccc) { return (f)(begin(cccc), end(cccc), ## __VA_ARGS__); })(c))

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

  map<int, int> count;
  rep(i, N) {
    int n = i+1;
    for (int j = 2; j * j <= n; ++j) {
      while (n % j == 0) {
        n /= j;
        ++count[j];
      }
    }
    if (n > 1)
      ++count[n];
  }
  vector<int> v;
  for (const auto& e : count) v.push_back(e.second);
  all(reverse, v);

  int two = v.end() - all(lower_bound, v, 3-1);
  int four = v.end() - all(lower_bound, v, 5-1);

  int ans = four * (four-1) * (two - 2) / 2;

  int fst = v.end() - all(lower_bound, v, 3-1);
  int snd = v.end() - all(lower_bound, v, 25-1);
  ans += (fst-1) * snd;

  fst = v.end() - all(lower_bound, v, 5-1);
  snd = v.end() - all(lower_bound, v, 15-1);
  ans += (fst-1) * snd;

  fst = v.end() - all(lower_bound, v, 75-1);
  ans += fst;

  cout << ans << endl;

  return 0;
}


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

int main() {
	ios_base::sync_with_stdio( false );

	int64_t N, M;
	cin >> N >> M;

	if( N == 1 ) {
		cout << (M > 1 ? M-2 : 1) << endl;
	}
	else if( M == 1 ) {
		cout << (N > 1 ? N-2 : 1) << endl;
	}
	else {
		cout << (N-2) * (M-2) << endl;
	}

	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define REP(i, a, b) for (int i = (int)(a); i < (int)(b); i++)
#define rep(i, n) REP(i, 0, n)
#define rrep(i, n) for (int i = (int)(n-1); i >= 0; i--)
#define sz(x) int(x.size())
#define bitsz(x) int(__builtin_popcount(x))
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define pb(x) push_back(x)
#define INF 1e9
#define LINF 1e18
#define mod 1000000007
template<class T> inline bool chmax(T &a, const T &b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T &a, const T &b) { if (a > b) { a = b; return 1; } return 0; }
template < typename T > inline string toString( const T &a ) { ostringstream oss; oss << a; return oss.str(); };
typedef long long ll;
typedef pair<int, int> P;
typedef pair<ll, ll> LP;
const int di[4] = {1,0,-1,0};
const int dj[4] = {0,1,0,-1};


int main() {
    int n,k; cin >> n >> k;
    vector<int> p(n);
    rep(i,n) cin >> p[i];
    sort(all(p));
    int ans = 0;
    rep(i,k) {
        ans += p[i];
    }
    cout << ans << endl;
}

Measured memory_bytes: 3552
/*************************************************************************
>>> Author: WindCry1
>>> Mail: lanceyu120@gmail.com
>>> Website: https://windcry1.com
>>> Date: 12/22/2019 11:08:25 PM
*************************************************************************/
#include <cstring>
#include <cmath>
#include <cstdio>
#include <cctype>
#include <cstdlib>
#include <ctime>
#include <vector>
#include <iostream>
#include <string>
#include <queue>
#include <set>
#include <map>
#include <algorithm>
#include <complex>
#include <stack>
#include <bitset>
#include <iomanip>
#include <list>
#include <sstream>
#include <fstream>
#if __cplusplus >= 201103L
#include <unordered_map>
#include <unordered_set>
#endif
#define ll long long
#define ull unsigned long long
#define DEBUG(x) cout<<#x<<" : "<<x<<endl;
#define lowbit(x) x&(-x)
#define ls u<<1
#define rs u<<1|1
using namespace std;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
const double clf = 1e-8;
const int INF = 0x3f3f3f3f;
const int mod = 1e9+7;
const int dir[4][2]={-1,0,1,0,0,-1,0,1};
ostream& operator <<(ostream &out, pii &p){
	return out<<p.first<<" "<<p.second;
}
istream& operator >>(istream &in, pii &p){
	return in>>p.first>>p.second;
}
int main(){
	ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
	//ifstream cin("C:\\Users\\LENOVO\\Desktop\\in.txt");
	//ofstream cout("C:\\Users\\LENOVO\\Desktop\\out.txt");
	int n;string a,b;cin>>n>>a>>b;
	for(int i=0;i<a.size();i++){
		cout<<a[i]<<b[i];
	}
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define pb push_back
#define pf push_front
#define ppb pop_back
#define ppf pop_front
#define f first
#define s second
#define mp make_pair
#define sz size()
int x, y;
int res;
int main() {
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
	cin >> x >> y;
	if(x == 1 && y == 1) cout << 1000000, exit(0);
	if(x == 1) res += 300000;
	if(x == 2) res += 200000;
	if(x == 3) res += 100000;
	if(y == 1) res += 300000;
	if(y == 2) res += 200000;
	if(y == 3) res += 100000;
	cout << res;
	return 0;
}

Measured memory_bytes: 256
'use strict'

const main = (input) => {
    const str = input.split('\n')[0].split(' ').map(v => v.split(''))
    if(str[0][str[0].length - 1] === str[1][0] && str[1][str[1].length - 1] === str[2][0]){
        console.log('YES')
    }else{
        console.log('NO')
    }
}

main(require('fs').readFileSync('/dev/stdin', 'utf-8'))

Measured memory_bytes: 9420
#define _CRT_SECURE_NO_WARNINGS

#include<iostream>
#include<string>
#include<vector>
#include<list>
#include<stack>
#include<queue>
#include<map>
#include<tuple>
#include<algorithm>
#include<numeric>
#include<math.h>
#include <functional>

#define REPS(i, a, b) for (int i = (a); i < (b); i++)
#define REP(i, n) for (int i = 0; i < (n); i++)

using namespace std;

using ll = long long;
using pii = pair<int, int>;
using vi = vector<int>;

const int mod = 1e9 + 7;
const long double pi = 3.141592653589793238462643383279502884197;
const long double eps = 1e-7;

int main() {
	int N;
	cin >> N;
	vector<int> a;
	int alice = 0, bob = 0;
	
	REP(i, N) {
		int ai;
		cin >> ai;
		a.push_back(ai);
	}
	std::sort(a.begin(), a.end(), std::greater<int>());//降順ソート

	REP(i, a.size()) {
		if (i % 2 == 0) {
			alice += a[i];
		}
		else {
			bob += a[i];
		}
	}

	cout << alice - bob;

	system("pause");
	return 0;
}

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

using namespace std;

const int MAX_N = 3005;

int n;

long double ans;

long double h[MAX_N];
long double dp[MAX_N][MAX_N];

int main() {
  cin >> n;
  for (int i = 1; i <= n; ++i) {
    cin >> h[i];
  }
  dp[0][0] = 1.0;
  for (int i = 1; i <= n; ++i) {
    for (int j = 0; j <= i; ++j) {
      if (j > 0) {
        dp[i][j] = (1.0 * dp[i - 1][j - 1] * h[i]) + dp[i - 1][j] * (1.0 - h[i]);
      } else {
        dp[i][j] = (1.0 * dp[i - 1][j]) * (1.0 - h[i]);
      }
    }
  }
  for (int i = n / 2 + 1; i <= n; ++i) {
    ans += dp[n][i];
  }
  cout << setprecision(10) << ans;
  return 0;
}


Measured memory_bytes: 139264
from collections import deque

n, q = map(int, input().split())
queue = deque([])
for i in range(n):
    name,time = input().split()
    time = int(time)
    queue.append([name, time])

t = 0
while len(queue) > 0:
    a = queue.popleft()
    time = a[1]
    name = a[0]

    if time > q:
        time -= q
        queue.append([name, time])
        t += q
    
    else:
        t += time
        print(a[0],t)


Measured memory_bytes: 13276
x, y, z, k = map(int, input().split())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
c = list(map(int, input().split())) 
a.sort(reverse=True)
b.sort(reverse=True)
c.sort(reverse=True)
p = []
for h in range(min(x,k)):
    for i in range(y):
        if h*i > k:
            break
        for j in range(z):
            if h*i*j > k:
                break
            p.append(a[h]+b[i]+c[j])

p.sort(reverse=True)
for i in range(k):
    print(p[i])

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

#define rep(i, n) for(int i = 0; i<(n); i++)
#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)
using namespace std;

const int MOD = 1000000007;

int main() {
    string S, T;
    cin >> S >> T;
    vector<int> start(26, -1);
    vector<int> goal(26, -1);
    rep(i, S.size()) {
        int a = S[i] - 'a';
        int b = T[i] - 'a';

        if (start[a] != -1 || goal[b] != -1) {
            if (start[a] != b || goal[b] != a) {
                cout << "No" << endl;
                return 0;
            }
        }
        start[a] = b;
        goal[b] = a;
    }

    cout << "Yes" << endl;
}

Measured memory_bytes: 776
s = str(input())
count=0
flg = False
max=0
for x in range(len(s)):
    if s[x] == 'A' or s[x] == 'T' or s[x] == 'C' or s[x] == 'G':
        count+=1
        if max <= count:
            max=count
    else:
        count=0
print(max)

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

#define REP(i, n) for (int i=0; i<n; i++)
#define print(x) cout << x << endl

typedef long long ll;

using namespace std;

void solve() {
    int N;
    cin >> N;
    string S;
    cin >> S;

    int ans = 1;
    char t = S[0];
    for (int i = 0; i < N; i++) {
        if (t != S[i]) {
            t = S[i];
            ans++;
        }
    }

    print(ans);
}

signed main() {
    solve();
}


Measured memory_bytes: 512
#include<iostream>
#include<algorithm>
#include<cstring>
using namespace std;
int main(){
    cin.tie(nullptr);
    ios_base::sync_with_stdio(false);

    int n;
    cin>>n;

    int p[n+1];
    int p2[n+1];
    for(int i=1;i<=n;i++){
        cin>>p[i];
        p2[i]=p[i];
    }

    int ans=0;
    int i;
    for(i=1;i<=n;i++){
        if(i==1){
            while(p[1]>0&&p[2]>0){
                ans+=2;
                p[1]-=1;
                p[2]-=1;
            }

            while(p[1]>0){
                ans++;
                p[1]-=1;
            }

            continue;
        }

        if(i==n){
            while(p[n]>0){
                ans++;
                p[n]-=1;
            }

            continue;
        }

        while(p[i]>0){
            ans+=2;
            p[i]-=1;
            p[i+1]-=1;
        }

    }

    int ans2=0;
    for(i=1;i<=n;i++){
        if(i==1){
            while(p2[1]>0){
                ans2++;
                p2[1]-=1;
            }
            
            continue;
        }

        if(i==n){
            while(p2[n]>0){
                ans2++;
                p2[n]-=1;
            }

            continue;
        }

        while(p2[i]>0){
            ans2+=2;
            p2[i]-=1;
            p2[i+1]-=1;
        }

    }

    cout<<min(ans,ans2)<<"\n";
    return 0;
}


Measured memory_bytes: 3260
#include <algorithm>
#include <iomanip>
#include <iostream>
#include <numeric>
#include <sstream>
#include <string>
#include <vector>
using namespace std;
int main(void){
    int x;
    cin >> x;
    if(x == 3 || x == 5 || x == 7){
        cout << "YES";
    } else{
        cout << "NO";
    }
    return 0;
}

Measured memory_bytes: 256
#include<cstdio>
#include<cstring>
using namespace std;
char s[100005],t[100005];
int main()
{
	scanf("%s%s",s+1,t+1);
	int len=strlen(s+1);
	for(int i=1;i<=len;i++)
	{
		if(s[i]!=t[i])
		{
			printf("No\n");
			return 0;
		}
	}
	if(strlen(t+1)!=len+1) printf("No\n");
	else printf("Yes\n");
}

Measured memory_bytes: 1660
import re
 
N = int(input())
S = input()
 
s = 0
a = 1
while s<len(S):
    pattern = re.compile(r"[^%s]+?" % S[s])
    matchObj = re.search(pattern, S[s+1:])
    if matchObj:
        s += matchObj.start()+len(matchObj.group())
        a+=1
    else:
        break
print(a)

Measured memory_bytes: 3572
// 有點不耐煩會破壞偉大的計劃

#include <bits/stdc++.h>

#define append push_back

using namespace std;
using ll = long long;

const int N = 1e5 + 3;
const int M = 1e6 + 7;
const long long MOD = 1e9 + 7;
const long long INF = 1e14 + 9;
const int SM = 1e3 + 5;
const int logN = 22, BL = 400;
const double EPS = 1e-9, PI = acos(-1);
const int dx[] = {1, 0, 0, -1, -1, 1, -1, 1};
const int dy[] = {0, 1, -1, 0, -1, 1, 1, -1};

void debug() {
	cerr << "\n";
}
template<typename Type1, typename... Type2>
void debug(Type1 a, Type2... b) {
    cerr << a << " ";
    debug(b...);
}

int main() {
//    freopen(".in", "r", stdin);
//    freopen(".out", "w", stdout);
    ios_base::sync_with_stdio(false);
    cin.tie(0), cout.tie(0);

    string s; cin >> s;

    long long n = s.size();

    set<char> c;

    for(auto i : s) {
        c.insert(i);
    }

    cout << (c.size() == n ? "yes" : "no");

    return 0;
}


Measured memory_bytes: 3604
#include <bits/stdc++.h>
using namespace std;
#define ll long long int
#define fast ios_base::sync_with_stdio(false); cin.tie(NULL) ; cout.tie(NULL);

ll dp[101][100001];
ll wt[100001];
ll val[100001];

int main()
{
    int n,w,i,j;
    cin>>n>>w; 
    
    for(i=1;i<=n;i++)
    {
       cin>>wt[i]>>val[i];
    }

    for(i=1;i<=n;i++)
    {
       for(j=1;j<=w;j++)
       {
       	  if(j>=wt[i])
       	  {
            dp[i][j]=max(dp[i-1][j],dp[i-1][j-wt[i]]+val[i]);
       	  }
       	  else
       	  	dp[i][j]=max(dp[i-1][j],dp[i][j-1]);
       }
    }   
    cout<<dp[n][w]<<"\n";
 	return 0;
}

Measured memory_bytes: 78720
import java.io.*;
import java.nio.CharBuffer;
import java.util.NoSuchElementException;

public class Main {

    public static void main(String[] args) {
        SimpleScanner scanner = new SimpleScanner(System.in);
        PrintWriter writer = new PrintWriter(System.out);

        int n = scanner.nextInt();
        int l = scanner.nextInt();
        int sum = 0;
        int x = Integer.MAX_VALUE;
        for (int i = l; i < l + n; ++i) {
            sum += i;
            if (Math.abs(i) < Math.abs(x)) {
                x = i;
            }
        }
        writer.println(sum - x);

        writer.close();
    }

    private static class SimpleScanner {

        private static final int BUFFER_SIZE = 10240;

        private Readable in;
        private CharBuffer buffer;
        private boolean eof;

        SimpleScanner(InputStream in) {
            this.in = new BufferedReader(new InputStreamReader(in));
            buffer = CharBuffer.allocate(BUFFER_SIZE);
            buffer.limit(0);
            eof = false;
        }


        private char read() {
            if (!buffer.hasRemaining()) {
                buffer.clear();
                int n;
                try {
                    n = in.read(buffer);
                } catch (IOException e) {
                    n = -1;
                }
                if (n <= 0) {
                    eof = true;
                    return '\0';
                }
                buffer.flip();
            }
            return buffer.get();
        }

        void checkEof() {
            if (eof)
                throw new NoSuchElementException();
        }

        char nextChar() {
            checkEof();
            char b = read();
            checkEof();
            return b;
        }

        String next() {
            char b;
            do {
                b = read();
                checkEof();
            } while (Character.isWhitespace(b));
            StringBuilder sb = new StringBuilder();
            do {
                sb.append(b);
                b = read();
            } while (!eof && !Character.isWhitespace(b));
            return sb.toString();
        }

        int nextInt() {
            return Integer.valueOf(next());
        }

        long nextLong() {
            return Long.valueOf(next());
        }

        double nextDouble() {
            return Double.parseDouble(next());
        }
    }
}

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

vector < int > arr;
int cache[100010];
int n, k;

int dpSol(int i)
{
    if(i == n - 1)
        return 0;
        
    int &res = cache[i];
    if(res != -1)
        return res;
        
    int ans = INT_MAX;
    
    for(int j = 1; j <= k; ++j)
        if(i + j < n)
            ans = min(ans, abs(arr[i] - arr[i + j]) + dpSol(i + j));
        else
            break;
        
    return res = ans;
}

int main()
{
    cin >> n >> k;
    
    arr = vector < int >(n);
    for(int i = 0; i < n; ++i)
        cin >> arr[i];
        
    memset(cache, -1, sizeof(cache));
    cout << dpSol(0);
}

Measured memory_bytes: 8832
#include <bits/stdc++.h>
using namespace std;
#define mp make_pair
#define pb push_back
#define re return
typedef vector<int> vi;
typedef long long ll;
typedef pair<int, int> pii; 
int n,a,b;
int h[100010];
int ans;
bool check(long long mid){
	long long sum=0;
    for(int i=0;i<n;i++){
		if(h[i]-mid*b>0)
   		sum+=(h[i]-mid*b+a-b-1)/(a-b);
  	}
 	return sum<=mid;
}
int main(){	
    //freopen("input.txt","r",stdin);
	//freopen("output.txt","w",stdout);
	cin>>n>>a>>b;
	for(int i=0;i<n;i++){
 		cin>>h[i];
	}
	int mid,l,r;
	l=0;
	r=1e9;
	while(l<=r){
 		mid=(l+r)/2;
 		if(check(mid)==1){
  			ans=mid;
  			r=mid-1;
 		}		
 		else
  		l=mid+1;
	}
	cout<<ans;
    return 0; 
}

Measured memory_bytes: 640