akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
struct edge {
	int to, cs[2];
};
const int maxn = 100100;
vector<edge> e[maxn];
long long dist[2][maxn];
long long ans[maxn];
int n;
void djk(int rot, int st){
	for(int i = 0; i < n; i++) dist[rot][i] = 1ll<<60;
	dist[rot][st] = 0;
	priority_queue<pair<long long, int> > pq;
	pq.push({0ll, st});
	while(!pq.empty()){
		long long cost; int at; tie(cost, at) = pq.top(); pq.pop();
		cost *= -1;
		if(dist[rot][at] != cost) continue;
		for(auto ed : e[at]){
			if(dist[rot][ed.to] > cost + ed.cs[rot]){
				dist[rot][ed.to] = cost + ed.cs[rot];
				pq.push({-dist[rot][ed.to], ed.to});
			}
		}
	}
}
int main(){
	int m, s, t; cin >> n >> m >> s >> t;
	for(int i = 0; i < m; i++){
		int u, v, a, b; cin >> u >> v >> a >> b;
		u--; v--;
		edge ee;
		ee.to = u;
		ee.cs[0] = a;
		ee.cs[1] = b;
		e[v].push_back(ee);
		ee.to = v;
		e[u].push_back(ee);
	}
	s--; t--;
	djk(0, s);
	djk(1, t);
	for(int i = 0; i <= n; i++) ans[i] = 0;
	for(int i = n - 1; i >= 0; i--){
		ans[i] = 1'000'000'000'000'000ll - dist[0][i] - dist[1][i];
		ans[i] = max(ans[i], ans[i + 1]);
	}
	for(int i = 0; i < n; i++){
		cout << ans[i] << endl;
	}
	return 0;
}



Measured memory_bytes: 10748
#include <iostream>

#include <vector>

#include <algorithm>

using std::cin;
using std::cout;
using std::endl;

using std::vector;

using std::sort;

static int
solve(int N, vector<int> &d)
{
  sort(d.begin(), d.end());
  int ret = 0;
  for (int n = 0; n < N; n++)
  {
    if (n == 0 || d[n] != d[n - 1])
    {
      ret++;
    }
  }
  return ret;
}

int
main()
{
  int N;
  cin >> N;
  vector<int> d(N);
  for (int n = 0; n < N; n++)
  {
    cin >> d[n];
  }
  cout << solve(N, d) << endl;
  return 0;
}


Measured memory_bytes: 256
//It doesn't matter how slow you go, Unless you don't stop.
#include<iostream>
#include<algorithm>
#include<bitset>
 
#include<cmath>
#include<cstring>
#include<climits>
 
#include<deque>
#include<queue>
#include<vector>
#include<set>
#include<map>
#include<unordered_set>
#include<unordered_map>
 
#include<fstream>
#include<chrono>
using namespace std;
 
typedef long long LL;
typedef pair<LL,LL> p64;
typedef vector<LL> v64;
typedef map<LL,LL> mp64;
 
#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define rep(i,s,e) for(long long i=s;i<=e;i++)
#define brep(i,s,e) for(long long i=s;i>=e;i--)
#define all(x) x.begin(),x.end()
#define mem(x,y) memset(x,y,sizeof(x))
#define DANGER std::ios::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL)
 set<LL> s;
 LL n;
LL cnt=0;
void solve(LL x)
{
    LL dummy = n;
    if(x==1)
    {
        return;
    }
    while(dummy%x==0)
    {
        dummy /= x;
    }
    if(dummy%x==1)
    {
        cnt++;
    }
}
void solve()
{
     cin>>n;
     for(LL i=1;i*i<=n;i++)
     {
         if(n%i==0)
         {
             solve(i);
             s.insert(i);
             if(i*i != n)
             {
                 solve(n/i);
                 s.insert(n/i);
             }
         }
     }
     --n;
     for(LL i=1;i*i<=n;i++)
     {
         if(n%i==0)
         {
             if(s.find(i)==s.end())
             {
                 cnt++;
             }
             if(i*i != n)
             {
                 if(s.find(n/i)==s.end())
                {
                     cnt++;
                }
             }
         }
     }

     cout<<cnt<<endl;
     
         
}
 
int main()
{
    DANGER;
    ofstream out("output.txt");
 
    auto start = chrono::high_resolution_clock::now();
    
    LL t = 1;
    // cin>>t;
    rep(test,1,t)
    {
        solve();
    }
    
    auto stop = chrono::high_resolution_clock::now();
    // auto duration = chrono::duration_cast<chrono::milliseconds>(stop - start); 
    // cout << "Time taken by function: " << duration.count() << " milliseconds" << endl;
}

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

#define MOD 1000000007

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

  int ans = 0;
  int _min = 999999;
  int _max = 0;
  rep(i, n) {
    int p;
    cin >> p;
    if (_min >= p) {
      ans++;
    }
    _min = min(_min, p);
  }

  cout << ans << endl;
}


Measured memory_bytes: 256
#include<iostream>
using namespace std;
#include<string>
#include<strstream>
#include<sstream>
#include<algorithm>
#include<math.h>
#include<iomanip>
#include<set>
bool issqr(int n)
{
	double d = sqrt(n);
	double x = floor(d);
	if (d - x == 0)
		return true;
	else
		return false;
}
int main()
{
	string s, t; cin >> s >> t;
	string h = s + t;
	int x = stoi(h);
	if (issqr(x))
		cout << "Yes";
	else
		cout << "No";
}

Measured memory_bytes: 3152
#include <bits/stdc++.h>
using namespace std;
int n; 
int W;

vector <pair <long long, long long> > v;

map <pair <long long, long long>, long long> m;

long long inf = 1000000000000000000;

long long solve(long long k, long long w){
	
	if (k < 0)
		return -inf;
	if (w < 0)
		return -inf;
	
	if (k == 0 || w == 0)
		return 0;
	
	
	if (m.count(make_pair(k, w)) != 0){
		return m[make_pair(k, w)];
	}
	long long res = max(solve(k-1, w), solve(k - 1, w - v[k - 1].first) + v[k - 1].second);
	
		
	return m[make_pair(k, w)] = res;
}


int main(){
	cin >> n;
	cin >> W;
	v = vector <pair <long long, long long> > (n);
	for (int i = 0; i < n; i++){
		cin >> v[i].first >> v[i].second;
	}
	
	
	cout << solve(n, W) << endl;
	
	return 0;
}

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

int main() {
  int a,b,c,d,e;
  cin>>a>>b>>c>>d>>e;
  if (a == 0){
    cout<< 1;
  }
  if (b == 0){
    cout<< 2;
  }
  if (c == 0){
    cout<< 3;
  }
  if (d == 0){
    cout<< 4;
  }
  if (e == 0){
    cout<< 5;
  }
	return 0;
}


Measured memory_bytes: 3624
/**
 * code generated by JHelper
 * More info: https://github.com/AlexeyDmitriev/JHelper
 * @author cherrypi59
 */

#pragma GCC optimize ("O2")
#pragma GCC optimize ("tree-vectorize")
#pragma GCC target ("sse4")

#include <bits/stdc++.h>
#define FOR(i, a, b) for(int i=(a);i<(b);++i)
#define FFOR(i, a, b) FOR(i, a, b+1)
#define REP(i, n) FOR(i, 0, n)
#define RREP(i, n) FOR(i, 1, n+1)
#define ALL(v) (v).begin(), (v).end()
#define RALL(v) (v).rbegin(), (v).rend()
#define LEN(x) (int)(x).size()
#define DUMP(x) cerr<<__LINE__<<' '<<#x<<"="<<(x)<<endl;
#define popcnt(x) __builtin_popcount(x)
#define popcntll(x) __builtin_popcountll(x)
#define pb push_back
#define eb emplace_back
#define mp make_pair

using namespace std;
using lint = long long;
using pii =  pair<int, int>;
using pll =  pair<lint, lint>;
template <typename T> using vc = vector<T>;
template <typename T> using vvc = vector<vector<T>>;
template <typename T> inline bool chmax(T &a, T b){if(a<b){a = b; return true;} return false;}
template <typename T> inline bool chmin(T &a, T b){if(a>b){a = b; return true;} return false;}

constexpr lint ten(int n) {return n==0 ? 1 : ten(n-1)*10;}

class EMajorityOfBalls {
public:
    void solve(std::istream& in, std::ostream& out){
        ios_base::sync_with_stdio(false);
        in.tie(nullptr), out.tie(nullptr);
        int N;
        in>>N;
        vc<int> vec;
        vc<char> ans(2*N+1), g = {'R', 'B'};
        auto query = [&](vc<int>& ids){
            out<<'?';
            for(auto& id : ids) out<<' '<<id;
            out<<endl;
            string res;
            in>>res;
            return res == "Red" ? 0 : 1;
        };
        FOR(i, 1, N+1) vec.pb(i);
        int f1 = query(vec);
        vec.clear();
        int left = 1, right = N + 1;
        while(1<right-left){
            int mid = (left+right) >> 1;
            FOR(i, mid, mid+N) vec.pb(i);
            int res = query(vec);
            if(res==f1) left = mid;
            else right = mid;
            vec.clear();
        }
        ans[left] = g[f1];
        ans[left+N] = g[f1^1];
        FOR(i, 1, left){
            vec.pb(i);
            FOR(j, left+1, left+N) vec.pb(j);
            int res = query(vec);
            if(res==f1) ans[i] = g[f1];
            else ans[i] = g[f1^1];
            vec.clear();
        }
        FOR(i, left+N+1, 2*N+1){
            vec.pb(i);
            FOR(j, left+1, left+N) vec.pb(j);
            int res = query(vec);
            if(res==f1) ans[i] = g[f1];
            else ans[i] = g[f1^1];
            vec.clear();
        }
        FOR(i, left+1, left+N){
            FOR(j, 1, left) vec.pb(j);
            FOR(j, left+N+1, 2*N+1) vec.pb(j);
            vec.pb(i);
            int res = query(vec);
            if(res==f1) ans[i] = g[f1];
            else ans[i] = g[f1^1];
            vec.clear();
        }
        out<<"! ";
        FOR(i, 1, 2*N+1) out<<ans[i];
        out<<endl;
    }
};


int main() {
	EMajorityOfBalls solver;
	std::istream& in(std::cin);
	std::ostream& out(std::cout);
	solver.solve(in, out);
	return 0;
}


Measured memory_bytes: 3844
num = 10**9+7

def modpow(a, n, p):
    if n==1:
        return a%p
    if n%2 == 1:
        return (a*modpow(a, n-1, p))%p
    else:
        temp = modpow(a, n//2, p)
        return (temp*temp)%p

def combi(x, y):
    numer = 1
    denom = 1
    for i in range(y):
        numer *= x-i
        denom *= i+1
        numer %= num
        denom %= num
    return (numer*modpow(denom, num-2, num))%num

def main():
    n, a, b = map(int, input().split())
    out1 = modpow(2, n, num)
    print((out1 - combi(n, a) - combi(n, b) - 1)%num)

if __name__=='__main__':
    # import time
    # start = time.time()
    main()
    # print(f"{time.time()-start}[s]")


Measured memory_bytes: 3064
X, Y, Z, K = map(int, input().split())
A = list(map(int, input().split()))
A.sort(reverse=True)
B = list(map(int, input().split()))
B.sort(reverse=True)
C = list(map(int, input().split()))
C.sort(reverse=True)

ABC = []
for xi in range(X):
    if xi+1 > K:
        break
    for yi in range(Y):
        if (xi+1)*(yi+1) > K:
            break
        for zi in range(Z):
            if (xi+1)*(yi+1)*(zi+1) > K:
                break
            ABC.append(A[xi]+B[yi]+C[zi])
ABC.sort(reverse=True)
for i in range(K):
    print(ABC[i])  

Measured memory_bytes: 8708
import sys
import math
import collections
import heapq
import queue
import itertools
import functools
import operator
import time

readline = sys.stdin.readline
 
IPS = lambda: readline().rstrip()
IP = lambda: int(readline().rstrip())
MP = lambda: map(int, readline().split())
LS = lambda: list(map(int, readline().split()))

def solve():
    for _ in range(1):
        n = IP()
        print(n + n**2 + n**3)
       
       
if __name__ == "__main__":
    solve()

Measured memory_bytes: 9656
s = input()
t = input()
ls = len(s)
lt = len(t)
min_count = 1000
for i in range(ls-lt+1):
  count = 0
  for j in range(lt):
    if s[i:i+lt][j] != t[j]:
      count += 1
  if min_count > count:
    min_count = count
print(min_count)


Measured memory_bytes: 8900
package main

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

var (
	xs, ys []float64
)

func solve() {
	n := getInt()
	kaijou := 1
	for i := 1; i <= n; i++ {
		kaijou *= i
	}
	xs, ys = make([]float64, n), make([]float64, n)
	for i := 0; i < n; i++ {
		xs[i] = getFloat()
		ys[i] = getFloat()
	}

	ans := 0.0
	for i := 0; i < n; i++ {
		bit := 1 << uint(i)
		ans += rec(n, i, bit, 0)
	}
	ans /= float64(kaijou)
	fmt.Fprintln(wr, ans)
}

func rec(n, prev, bit int, distSum float64) float64 {
	if bit == (1<<uint(n))-1 {
		return distSum
	}

	ret := 0.0
	for next := 0; next < n; next++ {
		if bit&(1<<uint(next)) > 0 {
			continue
		}

		nextBit := bit | (1 << uint(next))
		nextDistSum := distSum + distance(prev, next)
		ret += rec(n, next, nextBit, nextDistSum)
	}

	return ret
}

func distance(i, j int) float64 {
	a := math.Pow(math.Abs(xs[i]-xs[j]), 2)
	b := math.Pow(math.Abs(ys[i]-ys[j]), 2)
	return math.Sqrt(a + b)
}

// -----------------------------------------

const (
	inf = 1 << 60
	// mod = 1000000007
)

var (
	sc = bufio.NewScanner(os.Stdin)
	wr = bufio.NewWriter(os.Stdout)
)

func main() {
	maxBufSize := int(1e8)
	sc.Buffer(make([]byte, 4096), maxBufSize)
	sc.Split(bufio.ScanWords)
	solve()
	wr.Flush()
}

func getInt() (ret int) {
	sc.Scan()
	ret, err := strconv.Atoi(sc.Text())
	if err != nil {
		panic(err)
	}
	return
}

func getIntSlice(n int) (ret []int) {
	ret = make([]int, n)
	for i := range ret {
		ret[i] = getInt()
	}
	return
}

func getString() (ret string) {
	sc.Scan()
	ret = sc.Text()
	return
}

func getRunes() (ret []rune) {
	ret = []rune(getString())
	return
}

func getFloat() float64 {
	f, err := strconv.ParseFloat(getString(), 64)
	if err != nil {
		panic(err)
	}
	return f
}


Measured memory_bytes: 640
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#include<list>
#include<set>
#include<map>
#include<utility>
#include<cmath>

#define rep(i,x) for(int i=0;i<(int)(x);i++)
#define reps(i,x) for(int i=1;i<=(int)(x);i++)
#define rrep(i,x) for(int i=((int)(x)-1);i>=0;i--)
#define rreps(i,x) for(int i=((int)(x));i>0;i--)

#define all(x) (x).begin(),(x).end()
#define SZ(x) ((int)(x).size())
#define INF 2e10

template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
typedef long long ll;
int gcd(int a,int b){return b?gcd(b,a%b):a;}

using namespace std;

int main()
{
    ll n;
    vector<ll> v(5);
    cin >> n;
    rep(i, 5) cin >> v[i];
    ll m = *min_element(all(v));

    ll ans;
    if(n % m == 0) ans = n/m + 4;
    else ans = n/m + 5;

    cout << ans;


}


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

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

    int n,m,r1,r2;

    cin>>n>>m;

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

    int arr[n];
    for (int l = 0; l < n; ++l) {
        arr[l]=0;
    }

    for (int j = 0; j < m; ++j) {
        cin>>r1>>r2;
        r1=r1-1;
        r2=r2-1;
        if(arr[r1]<h[r2])
            arr[r1]=h[r2];
        if(arr[r2]<h[r1])
            arr[r2]=h[r1];

    }
    int count = 0;
    for (int k = 0; k < n; ++k) {
        if(arr[k]<h[k])
            count++;
    }
    cout<<count<<"\n";


    return 0;
}

Measured memory_bytes: 4400
#include <bits/stdc++.h>
//#define DEBUG

using namespace std;
struct node {
    int id, point;
} node[1<<18];
const int N=131072; // AC
//const int N=131071; // WA
int n, a[N];

void add(int id, int x)
{
    id=n-1+id;
    node[id].point+=x;

    while (id>0) {
        id=(id-1)/2;
        int c1=2*id+1, c2=2*id+2;
        if (node[c1].point>=node[c2].point)
            node[id]=node[c1];
        else
            node[id]=node[c2];
    }
}

void print()
{
#ifdef DEBUG
    int k=1;
    int x=0;
    while (true) {
        for(int i=0;i<k;++i) printf("(%d %d)", node[x+i].id, node[x+i].point);
        puts("");
        x+=k;
        k<<=1;
        if (x>=n) break;
    }
    puts("");
#endif
}

int main()
{
    int m, r, l;
    scanf("%d%d%d", &m, &r, &l);
    n=1;
    while (n<m) n<<=1;
    for(int i=0;i<m;++i) node[n-1+i].id=i;

    int pt=0;
    for(int i=0;i<r;++i) {
        int d, t, x;
        scanf("%d%d%d", &d, &t, &x);

        if (pt<t) {
            int id=node[0].id;
            a[id]+=t-pt;
        }
        add(d-1, x);
        print();
        pt=t;
    }
    print();
    a[node[0].id]+=l-pt;
#ifdef DEBUG
    for(int i=0;i<n;++i) printf("%d ", a[i]); puts("");
#endif
    printf("%d\n", 1+(max_element(a, a+n)-a));
}

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

using namespace std;

int main() {
	long long N, Z, W, buf;

	vector<long long> a;

	cin >> N >> Z >> W;

	for (int i = 0 ; i < N  ; i++)
	 {
       cin>>buf;
		a.push_back(buf);

	}
	long long answer;
	if (N > 1)
		{answer = max(abs(a[N - 2] - a[N - 1]), abs(a[N - 1] - W));}
	else
		{answer = abs(a[0] - W);}
	cout << answer << endl;
}


Measured memory_bytes: 256
def buble(lst):

    src_list = list(lst)
    flag=True
    while flag:
        flag = False
        for idx in range(len(lst)-1, 0, -1):
            if int(lst[idx][1]) < int(lst[idx-1][1]):
                tmp=lst[idx]
                lst[idx]=lst[idx-1]
                lst[idx-1]=tmp
                flag=True

    flag_stable = True
    for num in range(0, 9):
        tmp1 = []
        tmp2 = []
        for i in range(0, len(lst)):
            if int(lst[i][1]) == num:
                tmp1.append(lst[i])
            if int(src_list[i][1]) == num:
                tmp2.append(src_list[i])

        if tmp1 != tmp2:
           flag_stable = False
           break
    print " ".join(lst)

    if flag_stable:
        print "Stable"
    else:
        print "Not stable"

def selection(lst):

    src_list = list(lst)
    for i in range(len(lst)):
        m = i
        for j in range(i,len(lst)):
            if int(lst[m][1]) > int(lst[j][1]):
                m=j
        tmp=lst[i]
        lst[i]=lst[m]
        lst[m]=tmp

    flag_stable = True
    for num in range(0, 9):
        tmp1 = []
        tmp2 = []
        for i in range(0, len(lst)):
            if int(lst[i][1]) == num:
                tmp1.append(lst[i])
            if int(src_list[i][1]) == num:
                tmp2.append(src_list[i])

        if tmp1 != tmp2:
           flag_stable = False
           break

    print " ".join(lst)
    if flag_stable:
        print "Stable"
    else:
        print "Not stable"


n=raw_input()
lst1 = raw_input().split()
lst2 = list(lst1)

buble(lst1)
selection(lst2)

Measured memory_bytes: 6464
import heapq

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


heapq.heapify(V)

while len(V) > 1:
  e1 = heapq.heappop(V)
  e2 = heapq.heappop(V)
  heapq.heappush(V, (e1+e2)/2.)

print(V[0])

Measured memory_bytes: 3060
#!usr/bin/env python3
from collections import defaultdict, deque
from heapq import heappush, heappop
from itertools import permutations, accumulate
import sys
import math
import bisect
def LI(): return [int(x) for x in sys.stdin.readline().split()]
def I(): return int(sys.stdin.buffer.readline())
def LS():return [list(x) for x in sys.stdin.readline().split()]
def S():
    res = list(sys.stdin.readline())
    if res[-1] == "\n":
        return res[:-1]
    return res
def IR(n):
    return [I() for i in range(n)]
def LIR(n):
    return [LI() for i in range(n)]
def SR(n):
    return [S() for i in range(n)]
def LSR(n):
    return [LS() for i in range(n)]

sys.setrecursionlimit(1000000)
mod = 1000000007

def solve():
    def f(n):
        res = {1,n}
        i = 2
        while i**2 <= n:
            if n%i == 0:
                res.add(i)
                res.add(n//i)
            i += 1
        return res
    x = I()
    f = f(x)
    for a in range(10**7):
        a5 = a**5
        for l in f:
            b = a-l
            if a5 == x+b**5:
                print(a,b)
                return
    return

#Solve
if __name__ == "__main__":
    solve()


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

int S[100010], n;

bool bsch(int left, int right, int key){
    if(left == right) return false;
    int mid = (left + right) / 2;
    if(S[mid] == key) return true;
    if(S[mid] < key) return bsch(mid + 1, right, key);
    else return bsch(left, mid, key);
}
int main(){
    int q, x, ans = 0;
    cin >> n;
    for(int i = 0; i < n; i++) cin >> S[i];
    cin >> q;
    for(int i = 0; i < q; i++){
        cin >> x;
        if(bsch(0, n, x)) ans++;
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 3488
N = int(input())
W = list(map(int,input().split()))

Z = []

rX = []
rY = []
for i in range(N):
    rX.append(0)
    rY.append(0)
    Z.append(0)

rX[0] = W[0]
rY[0] = W[N-1]

for i in range(1,N):
    rX[i] = rX[i-1] + W[i]
    rY[i] = rY[i-1] + W[N-1-i]



rX.insert(0,0)
rY.reverse()
rY.append(0)
Z.append(0)

for i in range(N+1):
    Z[i] = abs(rX[i] - rY[i])

print(min(Z))

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

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

using namespace std;

const int inf = 1e9 + 7;

int main() {
	int n;
	cin >> n;
	int min = INT_MAX;
	int max = -INT_MAX;
	for(int i=0;i<n;i++){
		int tmp;
		cin >> tmp;
		if(max < tmp - min){
			max = tmp - min;
		}
		if(min > tmp){
			min = tmp;
		}
	}
	cout << max << endl;
	return 0;
}


Measured memory_bytes: 3104
#include<iostream>
#include<algorithm>
#include<vector>
#include<queue>
#include<stack>
#include<string>
#include<map>
#include<set>
#include<tuple>
#include<cmath>
#include<iomanip>


using namespace std;
typedef long long ll;
typedef vector<ll> v;
typedef vector<vector<ll>> vv;


#define MOD 1000000007
#define INF 1001001001
#define MIN -1001001001
#define rep(i,k,N) for(int i=k;i<N;i++)
#define MP make_pair
#define MT make_tuple //tie,make_tuple は別物
#define PB push_back
#define PF push_front
#define all(x) (x).begin(),(x).end()


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


int main(){
    ll N;
    cin>>N;
    v A(N);
    rep(i,0,N)cin>>A[i];
    ll ans = 0;
    rep(i,0,N){
        if(i%2 == 0 && A[i]%2 == 1)ans++;
    }
    cout<<ans;
    return 0;
}

Measured memory_bytes: 3592
#include <bits/stdc++.h>
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define F first
#define S second
#define all(x) (x).begin(),(x).end()
using namespace std;
typedef long long ll;
using vi = vector<int>;
using vvi = vector<vi>;
using pii = pair<int,int>;
 
int main(){
  int N,M;
  cin >> N >> M;
  vi k(M);
  vvi s(M);
  rep(i,M){
    cin >> k.at(i);
    for(int j = 0; j < k.at(i); j++){
      int x;
      cin >> x;
      s.at(i).push_back(x);
    }
  }

  vi p(M);
  rep(i,M){
    cin >> p.at(i);
  }

  int ans = 0;
  for(int i = 0; i < 1<<N;i++){
    bool ok = true;
    vi d(N);
    rep(j,N){
      if(i>>j&1){
        d.at(j) = 1;
      }
    }
    for(int j = 0; j < M; j++){
      int num =0;
      for(int l = 0; l < k.at(j); l++){
        if (d.at(s.at(j).at(l)-1) == 1){
          num++;
        }
      }
      if(num%2 != p.at(j)){
        ok = false;
      }
    }

    if(ok){
      ans++;
    }
  }
  cout << ans << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define vsort(v) sort(v.begin(), v.end())
#define rvsort(v) sort(v.begin(), v.end(), greater<ll>())
#define vfind(v, target) find(v.begin(), v.end(), target)
#define notFound(v, target) (vfind(v, target) == v.end())
#define ll long long
#define rep(i, s, g) for (ll i = (s); i < (g); i++)
#define MOD 1000000007
#define PI 3.14159265358979
using namespace std;

int main()
{
  ll A, B, H, M; cin >> A >> B >> H >> M;
  double degM, degH, theta, C, CC;
  degM = (double)M * 6; 
  degH = (double)H * 30 + (double)M * 0.5;
  theta = min(abs(degM - degH), 360 - abs(degM - degH));
  CC = A * A + B * B - 2 * A * B * cos(theta * PI / 180);
  C = sqrt(CC);
  cout << fixed << setprecision(15) << C << endl;
}

Measured memory_bytes: 4224
a,b,c,d = list(input())
a,b,c,d = int(a), int(b), int(c), int(d)
mark = {"+":1,"-":-1}
e = 0
for i, i_ in mark.items():
    for j, j_ in mark.items():
        for k, k_ in mark.items():
            if (e==0)&(a + i_ * b + c * j_ + d * k_ == 7):
                ans = str(a)+i+str(b)+j+str(c)+k+str(d)+"=7"
                print(ans)
                e = 1
                break

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

// #pragma GCC optimize("Ofast")
// #pragma GCC target("avx,avx2,fma")

#define fr(i, a, b) for(int i = (a); i <= (b); ++i)
#define rf(i, a, b) for(int i = (a); i >= (b); --i)
#define fe(x, y) for(auto& x : y)

#define fi first
#define se second
#define pb push_back

#define pw(x) (1LL << (x))
#define sz(x) (int)(x).size()
#define all(x) (x).begin(), (x).end()

using namespace std;

using ll = long long;
using ld = long double;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
using vi = vector<int>;
using vll = vector<ll>;

#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
template<typename T>
using oset = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
#define fbo find_by_order
#define ook order_of_key

mt19937_64 rng(chrono::system_clock::now().time_since_epoch().count());

template<typename T>
bool umn(T& a, T b) { return a > b ? a = b, 1 : 0; }
template<typename T>
bool umx(T& a, T b) { return a < b ? a = b, 1 : 0; }

const int N = 2e5 + 5;
const int mod = 1e9 + 7;
const int inf = 2e9;
const ll INF = 2e18;
const ld eps = 1e-9;

int main() {
#ifndef LOCAL
    // freopen("input.txt", "r", stdin);
    // freopen("output.txt", "w", stdout);
    ios::sync_with_stdio(0);
    cin.tie(0);
#endif
    ll a;
    cin >> a;
    ld x;
    cin >> x;
    ll b = round(x * 100.0);
    cout << (a * b) / 100 << "\n";
}

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

using namespace std;
const int MAXL = 1e6+10;
int dp0[MAXL], dp1[MAXL];

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

    dp1[0] = 2;
    for(int i=0;i<s.length();i++){
        int c = s[i] - '0';
        dp0[i+1] = min(dp0[i] + c, dp1[i] + c);
        dp1[i+1] = min(dp0[i] + 1 + 10 - c, dp1[i] -1 + 10-c);
    }

    cout <<min(dp0[s.length()], dp1[s.length()])<<endl;
}


Measured memory_bytes: 9220
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {

		String str="";
		int sum;

		Scanner sc= new Scanner( System.in );

		while ( true) {
			sum = 0;
			str = sc.nextLine();

			if ( str.equals("0") ) {
				break;
			}

			for ( int i = 0 ; i < str.length() ; i++ ) {
				sum += Character.getNumericValue( str.charAt(i) );
			}
			System.out.println( sum );
		}

		sc.close();
	}
}



Measured memory_bytes: 26404
import java.util.*

fun main(args: Array<String>) {
    val sc = Scanner(System.`in`)
    val n = sc.nextInt()
    val a = (0 until n).map { sc.next().toInt() }
    println(problem170d(n, a))
}

fun problem170d(n: Int, a: List<Int>): Int {
    val max = a.max()!!
    val isValid = BooleanArray(max + 1)
    a.forEach { isValid[it] = true }

    for (ai in a.distinct().sorted()) {
        if (!isValid[ai]) continue
        var num = 2
        while (num <= max / ai) {
            isValid[num * ai] = false
            num++
        }
    }
    a.groupBy { it }.filter { it.value.size >= 2 }.forEach { t, _ -> isValid[t] = false }
    return isValid.count { it }
}

Measured memory_bytes: 86908
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define ll long long
int main(){
  ll n;
  cin >> n;
  vector<string> s(n);
  rep(i,n){
    cin >> s.at(i);
  }
  string ans="Yes";
  rep(i,n-1){
    if(s.at(i).at(s.at(i).size()-1)!=s.at(i+1).at(0)){
      ans="No";
    }
  }
  sort(s.begin(),s.end());
  rep(i,n-1){
    if(s.at(i)==s.at(i+1)){
      ans="No";
    }
  }
  cout << ans;
}

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

const int MAX_N = 50;
const int MAX_AB = 500;
const int INF = 99999999;

int dp[MAX_N][MAX_AB][MAX_AB];

int main(void) {
    for (int k = 0; k < MAX_N; k++) {
        for (int i = 0; i < MAX_AB; i++) {
            for (int j = 0; j < MAX_AB; j++) {
                dp[k][i][j] = INF;
            }
        }
    }
    dp[0][0][0] = 0;

    int N, Ma, Mb; cin >> N >> Ma >> Mb;
    for (int i = 0; i < N; i++) {
        int a, b, c; cin >> a >> b >> c;
        for (int j = 0; j < MAX_AB; j++) {
            for (int k = 0; k < MAX_AB; k++) {
                if (dp[i][j][k] == INF) continue;
                dp[i+1][j][k] = min(dp[i+1][j][k], dp[i][j][k]);
                dp[i+1][j+a][k+b] = min(dp[i+1][j+a][k+b],dp[i][j][k]+c);
            }
        }

        // cout << "#" << endl;
        // for (int j = 0; j <= 10; j++) {
        //     for (int k = 0; k <= 10; k++) {
        //         cout << dp[i][j][k] << " ";
        //     }
        //     cout << endl;
        // }
    }

    int ans = INF;
    int pos_a = Ma;
    int pos_b = Mb;
    while (pos_a < MAX_AB && pos_b < MAX_AB) {
        ans = min(ans, dp[N][pos_a][pos_b]);
        pos_a += Ma;
        pos_b += Mb;
    }

    if (ans != INF) {
        cout << ans << endl;
    } else {
        cout << -1 << endl;
    }

    return 0;
}

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

#define rep(i, n) for(int i = 0; i < (int)n; i++)
#define ALL(a) begin(a),end(a)
#define COUNTOF(a) (sizeof(a)/sizeof(a[0]))
#define SP << " " <<
#define FMT(a) #a<<":"<<a 
#define FMT2(a,b) #a<<":"<<a<<", "<<#b<<":"<<b 
#define FMT3(a,b,c) #a<<":"<<a<<", "<<#b<<":"<<b<<", "<<#c<<":"<<c 
#define FMT4(a,b,c,d) #a<<":"<<a<<", "<<#b<<":"<<b<<", "<<#c<<":"<<c<<", "<<#d<<":"<<d 
typedef long long ll;
template<class T> istream& operator >> (istream& s, vector<T>& v) {
  for (T& x: v) s >> x;
  return s;
}
inline void Yes(bool f=true){cout<<(f?"Yes":"No")<<endl;}
inline void YES(bool f=true){cout<<(f?"YES":"NO")<<endl;}
#define ANS(a) cout<<a<<endl

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

    int N,M,C; cin >>N>>M>>C;
    vector<int> B(M); cin >> B;

    int ans = 0;
    vector<int> A(M);
    for (int i = 0; i < N; i++) {
        cin >> A;
        int v = C;
        for (int j = 0; j < M; j++) {
            v += A[j]*B[j];
        }
        if (v > 0) ans++;
    }
    ANS(ans);
}


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

using namespace std;

int main()
{
    string S, T;
    cin >> S >> T;

    vector<int> sCount;
    vector<int> tCount;

    int count[26] = {0};
    for(auto c : S) {
        count[c - 'a']++;
    }
    for(auto& x : count) {
        if(x >= 1) {
            sCount.push_back(x);
        }
        x = 0;
    }

    for(auto c : T) {
        count[c - 'a']++;
    }
    for(auto& x : count) {
        if(x >= 1) {
            tCount.push_back(x);
        }
    }

    if(sCount.size() != tCount.size()) {
        cout << "No" << endl;
        return 0;
    }

    sort(sCount.begin(), sCount.end());
    sort(tCount.begin(), tCount.end());

    for(size_t i = 0; i < sCount.size(); i++) {
        if(sCount[i] != tCount[i]) {
            cout << "No" << endl;
            return 0;
        }
    }

    cout << "Yes" << endl;
    return 0;
}


Measured memory_bytes: 776
#include <bits/stdc++.h>
using namespace std;
const int maxn = 200010;
char str[maxn];
int main(){
	scanf("%s",str);
  	int ans = 0;
  	for (int i=0;str[i];i++) ans += str[i] - '0';
  	if (ans % 9 == 0) printf("Yes\n");
   else printf("No\n");
  	return 0;
}

Measured memory_bytes: 3844
void main() {
    int[] tmp = readln.split.to!(int[]);
    int a = tmp[0], b = tmp[1], c = tmp[2];
    writeln(b - a == c - b ? "YES" : "NO");
}


import std.stdio;
import std.string;
import std.array;
import std.conv;
import std.algorithm;
import std.range;
import std.math;
import std.numeric;
import std.container;
import std.typecons;
import std.ascii;
import std.uni;

Measured memory_bytes: 256
#include<iostream>
#include<cstring>
#include<cstdio>
#include<vector>
#include<cmath>
#include<algorithm>
#include<functional>
#include<iomanip>
#include<queue>
#include<ciso646>
#include<map>
#include<set>
#include<complex>
#include<bitset>
#include<stack>
#include<utility>
using namespace std;
typedef long long ll;
typedef unsigned int ui;
const ll mod = 1000000007;
const ll INF = (ll)1000000007 * 1000000007;
typedef pair<int, int> P;
#define stop char nyaa;cin>>nyaa;
#define rep(i,n) for(int i=0;i<n;i++)
#define per(i,n) for(int i=n-1;i>=0;i--)
#define Rep(i,sta,n) for(int i=sta;i<n;i++)
#define rep1(i,n) for(int i=1;i<=n;i++)
#define per1(i,n) for(int i=n;i>=1;i--)
#define Rep1(i,sta,n) for(int i=sta;i<=n;i++)
typedef long double ld;
typedef complex<ld> Point;
const ld eps = 1e-2;
const ld pi = acos(-1.0);
typedef pair<ll, ll> LP;
int main() {
	stack<char>st;
	string s; cin >> s; int n = s.length();
	int ans = 0;
	rep(i, n) {
		char t = s[i];
		if (!st.empty() && st.top() != t) {
			ans++; st.pop();
		}
		else st.push(t);
	}
	cout << 2*ans << endl;
	//stop
	return 0;
}


Measured memory_bytes: 512
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0; i<(n); i++)
using ll = long long;
#define int long long
using P = pair<int,int>;
signed main(){
    int a,b;cin >> a >> b;
    rep(i,2000){
        if (!i)continue;
        if(i*8/100 == a && i*10/100 ==b){
            cout << i << endl;
            return 0;
        }
    }
    cout << -1 << endl;
    return 0;
}


Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

    private static final Scanner scanner = new Scanner(System.in);

    public static void main(String[] args) {
        int N = scanner.nextInt();

        boolean canReach = true;
        int prevT = 0;
        int prevX = 0;
        int prevY = 0;
        for (int i = 0; i < N; i++) {
            int t = scanner.nextInt();
            int hereX = scanner.nextInt();
            int hereY = scanner.nextInt();
            int distance = Math.abs(hereX - prevX) + Math.abs(hereY - prevY);

            if (distance > t || distance % 2 != Math.abs(t - prevT) % 2) {
                canReach = false;
                break;
            }

            prevT = t;
            prevX = hereX;
            prevY = hereY;
        }

        System.out.println(canReach ? "Yes" : "No");
    }

}

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

int main(){
    int cmin = 1e9;
    int ans = -1;
    int N, T; cin >> N >> T;
    for(int i = 0; i < N; i++){
        int c,t; cin >> c >> t;
        if(T >= t && cmin >= c){
            cmin = c;
            ans = c;
        }
    }
    if(ans == - 1) cout << "TLE" << endl;
    else cout << ans << endl;
    //cout <<  ((ans != -1 ) ? "TLE" : "ans") << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <cstring>
#include <cassert>
#include <sys/mman.h>
#include <unistd.h>
typedef long long lint;
const int N=1e5+5;
int n,len,q,pos[N];
int turn_0,turn_1,cnt_0,cnt_1,buk_0[N],buk_1[N];
bool stat[N];//0: clockwise, 1: counter

namespace IO{
	char *ibuf;
	struct _Init{
		_Init(){ibuf=(char*)mmap(0,lseek(0,0,SEEK_END),PROT_READ,MAP_PRIVATE,0,0);}
	}_init;
	inline int nxi(){
		int x=0;
		char c;
		while((c=*ibuf++)>'9'||c<'0');
		while(x=x*10-48+c,(c=*ibuf++)>='0'&&c<='9');
		return x;
	}
}
using IO::nxi;

int main(){
	n=nxi(),len=nxi(),q=nxi();
	for(int i=1; i<=n; ++i){
		pos[i]=nxi(),stat[i]=nxi()-1;
	}
	int cyc=q/len,rest=q-cyc*len;
	lint dlt=0;
	for(int i=1; i<=n; ++i){
		if(stat[i]==0){
			dlt+=cyc;
			int tgt=pos[i]+rest;
			if(tgt>=len) ++dlt,tgt-=len;
			else turn_0=cnt_0+1;
			buk_0[++cnt_0]=tgt;
		}
		else{
			dlt-=cyc;
			int tgt=pos[i]-rest;
			if(tgt<0){
				--dlt,tgt+=len;
				turn_1=cnt_1+1;
			}
			buk_1[++cnt_1]=tgt;
		}
	}
	for(int c=1,i=1,j=turn_0+1,k=1,l=turn_1+1; c<=n; ++c){
		int type=0,nval=1e9;
		if(i<=turn_0&&buk_0[i]<nval)
			nval=buk_0[i],type=1;
		if(j<=cnt_0&&buk_0[j]<nval)
			nval=buk_0[j],type=2;
		if(k<=turn_1&&buk_1[k]<nval)
			nval=buk_1[k],type=3;
		if(l<=cnt_1&&buk_1[l]<nval)
			nval=buk_1[l],type=4;
		assert(type);
		pos[c]=nval;
		switch(type){
			case 1: ++i; break;
			case 2: ++j; break;
			case 3: ++k; break;
			case 4: ++l; break;
		}
	}
	dlt%=n;
	if(dlt<0) dlt+=n;
	for(int i=dlt+1; i<=n; ++i){
		printf("%d\n",pos[i]);
	}
	for(int i=1; i<=dlt; ++i){
		printf("%d\n",pos[i]);
	}
	return 0;
}

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

int main(void) {
    int N;
    cin >> N;
    int D[110][2];
    for (int i = 0; i < N; i++) {
        cin >> D[i][0] >> D[i][1];
    }
    int zo = 0, zt = 0;
    for (int i = 0; i < N; i++) {
        if (D[i][0] == D[i][1]) {
            ++zt;
        } else {
            zo = max(zo, zt);
            zt = 0;
        }
    }
    zo = max(zo, zt);
    if (zo >= 3) {
        printf("Yes\n");
    } else {
        printf("No\n");
    }
    return 0;
}


Measured memory_bytes: 3632
#include<bits/stdc++.h>
using namespace std;
#define sf(a) scanf("%d",&a)
#define sf2(a,b) scanf("%d%d",&a,&b)
#define pf printf
#define PI 3.1416
int main( )
{
	int a,b;
	sf2(a,b);
	
	if(a==1 && b==2) pf("%d\n",3);
	else if(a==2 && b==1) pf("%d\n",3);
	else if(a==2 && b==3) pf("%d\n",1);
	else if(a==3 && b==2) pf("%d\n",1);
	else pf("%d\n",2);
}

Measured memory_bytes: 3724
#include <bits/stdc++.h>
using namespace std;
long long n;
int ans = 0;
void dfs(long long x, int a, int b, int c) {
	if(x > n) return;
	if(a && b && c) ans++;
	dfs(10 * x + 3, 1, b, c);
	dfs(10 * x + 5, a, 1, c);
	dfs(10 * x + 7, a, b, 1);
}
int main() {
	ios::sync_with_stdio(false);
	cin.tie(0); 
	
	cin >> n;
	dfs(0, 0, 0, 0);
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 256
from sys import stdin, stdout
from math import gcd
N=10**6+2
n = int(stdin.readline())
a = list(map(int, stdin.readline().split()))
mp=[0]*N;not_pairwise=1
for v in a:
    mp[v]+=1
for i in range(2,N):
    if sum(mp[i::i])>1:
        not_pairwise=0
        break
g = a[0]
for v in a:
    g = gcd(g, v)
if not_pairwise:
    print('pairwise coprime')
elif g == 1:
    print('setwise coprime')
else:
    print('not coprime')

Measured memory_bytes: 132948
/*---> 07 March 2020 <--- > 02:24:07 <---*/
// #pragma GCC optimize("Ofast")
// #pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
// #pragma GCC optimize("unroll-loops")
// #pragma comment(linker, "/stack:200000000")
#pragma GCC optimize("O3")
//#pragma GCC target ("sse4")
#include <bits/stdc++.h>
//#include <ext/pb_ds/tree_policy.hpp>
//#include <ext/pb_ds/assoc_container.hpp>
//using namespace __gnu_pbds;
using namespace std;
//template <class T> using Tree = tree<T, null_type, less<T>, rb_tree_tag,tree_order_statistics_node_update>;
#define int long long
#define F first
#define S second
#define mod 1000000007
#define inf (int)1e18+5
#define sz(x) (int)x.size()
#define PI 3.141592653589793238510
#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(),(x).rend()
#define __ ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define vi vector<int>
#define vpii vector<pair<int,int> > 
#define vvi vector<vector<int> >
#define PRINT_TIME cerr << "Time elapsed: " << 1.0 * clock() / CLOCKS_PER_SEC << " s." <<endl;
#define sim template < class c
#define ris return * this
#define dor > debug & operator <<
#define eni(x) sim > typename   enable_if<sizeof dud<c>(0) x 1, debug&>::type operator<<(c i) {
sim > struct rge { c b, e; };
sim > rge<c> range(c i, c j) { return rge<c>{i, j}; }
sim > auto dud(c* x) -> decltype(cerr << *x, 0);
sim > char dud(...);
struct debug {
#ifdef LOCAL
~debug() { cerr << endl; }
eni(!=) cerr << boolalpha << i; ris; }
eni(==) ris << range(begin(i), end(i)); }
sim, class b dor(pair < b, c > d) {
  ris << "(" << d.first << ", " << d.second << ")";
}
sim dor(rge<c> d) {
  *this << "[";
  for (auto it = d.b; it != d.e; ++it)
    *this << ", " + 2 * (it == d.b) << *it;
  ris << "]";
}
#else
sim dor(const c&) { ris; }
#endif
};
#define imie(...) " [" << #__VA_ARGS__ ": " << (__VA_ARGS__) << "] "
typedef long double ld;
typedef pair<int,int> pii;
///////////////////////////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////////////////////////
const int N=1e5+5;

int32_t main(){__
	int gg[3][3];
	for(int i=0;i<3;i++){
		for(int j=0;j<3;j++)
		cin>>gg[i][j];
	}
	vvi check(3,vi(3));
	int n,x;
	cin>>n;
	for(int i=0;i<n;i++){
		cin>>x;
		for(int j=0;j<3;j++){
			for(int k=0;k<3;k++){
				if(gg[j][k]==x)
					check[j][k]=true;
			}
		}
	}
	for(int i=0;i<3;i++){
		bool ok=true;
		for(int j=0;j<3;j++){
			if(!check[i][j]){
				ok=false;
			}
		}
		if(ok)
			return cout<<"Yes\n",0;
	}
	for(int i=0;i<3;i++){
		bool ok=true;
		for(int j=0;j<3;j++){
			if(!check[j][i]){
				ok=false;
			}
		}
		if(ok)
			return cout<<"Yes\n",0;
	}
	if(check[0][0] && check[1][1] && check[2][2])
		cout<<"Yes\n";
	else if(check[0][2] && check[1][1] && check[2][0])
		cout<<"Yes\n";
	else
		cout<<"No\n";
return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define ALL(x) (x).begin(),(x).end()
#define COUT(x) cout<<(x)<<"\n"
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define REP(i, n) for(int i=0;i<n;i++)
#define YES(x) cout<<(x?"YES":"NO")<<"\n"
#define Yes(x) cout<<(x?"Yes":"No")<<"\n"
#define dump(x) cout<<#x<<" = "<<(x)<<"\n"
#define endl "\n"
using G = vector<vector<int>>;
using M = map<int,int>;
using P = pair<int,int>;
using PQ = priority_queue<int>;
using PQG = priority_queue<int,vector<int>,greater<int>>;
using V = vector<int>;
using ll = long long;
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; }
const int INF = 1e9;
const int MOD = 1e9+7;
const ll LINF = 1e18;

int main() {
  IOS;
  int n,m; cin >> n >> m;
  vector<int> k(m), p(m);
  vector<vector<int>> s(m);
  REP(i,m) {
    cin >> k[i];
    REP(j,k[i]) {
      int _s;
      cin >> _s;
      s[i].push_back(_s-1);
    }
  }
  REP(i,m) cin >> p[i];

  int ans = 0;
  for (int bit = 0; bit < 1<<n; bit++) {
    vector<int> bits;
    REP(i,n) {
      if (bit >> i & 1) bits.push_back(i);
    }

    int ok = true;
    REP(i, m) {
      int sum = 0;
      REP(j,k[i]) {
        for (auto x: bits) {
          if(x == s[i][j]) { sum++; break; }
        }
      }
      if (sum % 2 != p[i]) { ok = false; break; }
    }
    if (ok) ans++;
  }

  COUT(ans);
  return 0;
}

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

#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define repr(i,n) for(int (i)=(n);(i)>0;(i)--)
#define rrep(i,n,m) for(int (i)=(n);(i)<(m);(i)++)
#define rrepr(i,n,m) for(int (i)=(n);(i)>(m);(i)--)
#define esort(s) sort((s).begin(),(s).end())

typedef long long ll;
typedef pair<int,int> ipair;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<vector<int>> vvi;

const int INF = 1000000000;
const ll LINF = 1000000000000000000;
const double PI = acos(-1.0);
const double EPS = 1e-10;

const ll MOD = 1000000007ll;
const int MAX=510000;

int A,B;

void solve(){
    cin>>A>>B;
    int ans;
    if(A==1){
        if(B==2) ans=3;
        else ans=2;
    } else if(A==2){
        if(B==1) ans=3;
        else ans=1;
    } else{
        if(B==1) ans=2;
        else ans=1;
    }
    cout<<ans<<endl;
    return;
}

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

    solve();
    return 0;
}

Measured memory_bytes: 256
#include <algorithm>
#include <iostream>
#include <set>
#include <string>

using namespace std;

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

	int K;
	cin >> K;

	// 先頭になり得る文字
	set<char> charList;

	auto sorteds = s;
	sort(sorteds.begin(), sorteds.end());
	charList.insert(sorteds.begin(),
		sorteds.begin() + min<int>(s.size(), 5));

	set<string> sset;
	for(int a = 0; a < s.size(); a++) {
		if(charList.find(s[a]) == charList.end()) {
			continue;
		}

		const auto cl = min<int>(s.size() - a, 5);
		for(int c = 1; c <= cl; c++) {
			sset.insert(s.substr(a, c));
		}
	}
	
	const auto result = *next(sset.begin(), K - 1);
	cout << result << endl;

	return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define MOD 1000000007
#define INF 1e9
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define all(x) (x).begin(),(x).end()

int d[10][10];

int main(){
    int h,w;
    cin>>h>>w;
    rep(i,10){
        rep(j,10){
            cin>>d[i][j];
        }
    }

    rep(k,10){
        rep(i,10){
            rep(j,10){
                d[i][j]=min(d[i][j],d[i][k]+d[k][j]);
            }
        }
    }

    ll ans=0;
    rep(i,h){
        rep(j,w){
            int a;
            cin>>a;
            if(a==-1) continue;
            //cout<<d[a][1]<<endl;
            ans+=d[a][1];
        }
    }

    cout<<ans<<endl;
}


Measured memory_bytes: 256
package main

import (
        "bytes"
        "fmt"
        "sort"
)

func main() {
        var n, l int
        fmt.Scan(&n, &l)
        ss := make([]string, n)
        for i := range ss {
                fmt.Scan(&ss[i])
        }
        sort.Sort(sort.StringSlice(ss))
        buf := bytes.NewBuffer([]byte{})
        for _, s := range ss {
                buf.WriteString(s)
        }
        fmt.Println(buf.String())
}

Measured memory_bytes: 768
#include <bits/stdc++.h>
using namespace std;
typedef long long LL;
LL read(){
	LL x=0,f=0;
	char ch=getchar();
	while (!isdigit(ch))
		f|=ch=='-',ch=getchar();
	while (isdigit(ch))
		x=(x<<1)+(x<<3)+(ch^48),ch=getchar();
	return f?-x:x;
}
const int N=200005;
int n,L;
int x[N];
LL tl[N],tr[N];
LL sv(){
	LL ans=0;
	for (int i=1;i<=n;i++)
		tl[i]=tl[i-1]+x[i];
	for (int i=n;i>=1;i--)
		tr[i]=tr[i+1]+L-x[i];
	for (int i=1;i<n;i++){
		int las=max(x[i+1]-x[i],x[i]+L-x[i+1]);
		if (i==n-1){
			ans=max(ans,(LL)x[i]+las);
			continue;
		}
		LL tmp=x[i]+las;
		int d=i-1-(n-i-1);
		if (d>=0){
			tmp+=tl[i-1]*2-tl[d]*2;
			tmp+=tr[i+2]*2;
		}
		else {
			d=-d;
			tmp+=tl[i-1]*2;
			tmp+=tr[i+2]*2-tr[n-d+2]*2;
		}
		ans=max(ans,tmp);
	}
	return ans;
}
int main(){
	L=read(),n=read();
	for (int i=1;i<=n;i++)
		x[i]=read();
	if (n==1){
		printf("%d\n",max(x[1],L-x[1]));
		return 0;
	}
	LL ans=sv();
	for (int i=1;i<=n;i++)
		x[i]=L-x[i];
	reverse(x+1,x+n+1);
	ans=max(ans,sv());
	cout << ans;
	return 0;
}

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

import math

BIG_NUM = 100000000000000000000000000000000000000000000000000000000000000000000000000000000


def main():
    n = int(input())
    for _ in range(n):
        a = int(input())
        b = int(input())
        if a >= BIG_NUM  or b >= BIG_NUM or a + b >= BIG_NUM:
            print("overflow")
        else:
            print(a+b)

if __name__ == "__main__":
    main()


Measured memory_bytes: 7772
#include <bits/stdc++.h>
using namespace std;
typedef long long LL;
void Input(); void Prepare(); void Setup(); void Solve(); void Clean();

#ifdef DEBUG6500
int N = 10;
int main(){ Prepare(); Solve(); return 0; }
#else
int N;
int main(){ Input(); Prepare(); Solve(); Clean(); return 0; }
#endif

void Solve()
{
	string ans = "No";
	if (N <= 81){
		for (int i = 1; i < 10; ++i)
			if ((N / i < 10) && (N % i == 0)){
				ans = "Yes";
			}
	}
	
	cout << ans << endl;
}

void Prepare()
{
}

#ifndef DEBUG6500
void Clean()
{
}

void Input()
{
	cin >> N;
}
#endif


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

using int32 = int_fast32_t;
using int64 = int_fast64_t;

const int32 INF = 1e9;
const int32 MOD = 1e9+7;
const int64 LLINF = 1e18;

#define YES(n) cout << ((n) ? "YES\n" : "NO\n"  )
#define Yes(n) cout << ((n) ? "Yes\n" : "No\n"  )
#define ANS(n) cout << (n) << "\n"
#define REP(i,n) for(int64 i=0;i<(n);++i)
#define FOR(i,a,b) for(int64 i=(a);i<(b);i++)
#define FORR(i,a,b) for(int64 i=(a);i>=(b);i--)
#define ALL(obj) (obj).begin(),(obj).end()
#define pii pair<int32,int32>
#define pll pair<int64,int64>
#define pb(a) push_back(a)
#define mp make_pair

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int64 h,w;
    cin >> w >> h;
    priority_queue<int64,vector<int64>,greater<int64>> p;
    priority_queue<int64,vector<int64>,greater<int64>> q;
    REP(i,w){
        int64 pi;
        cin >> pi;
        p.push(pi);
    }
    REP(i,h){
        int64 qi;
        cin >> qi;
        q.push(qi);
    }
    p.push(INF);
    q.push(INF);
    int64 ans = 0;
    while(h > 0 || w > 0){
        if(p.top() < q.top()){
            ans += p.top() * (h + 1);
            p.pop();
            w--;
        }else{
            ans += q.top() * (w + 1);
            q.pop();
            h--;
        }
        // cout << w << " " << h << endl;
    }
    // REP(i,h){
    //     ans += q.top();
    //     q.pop();
    // }
    // REP(j,w){
    //     ans += p.top();
    //     p.pop();
    // }
    ANS(ans);
    return 0;
}

Measured memory_bytes: 2548
#include<bits/stdc++.h>
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>
#define ll long long
#define M 1000000007
#define sz(a) (ll)a.size()
#define pll pair<ll,ll>
#define rep(i,a,b) for(ll i=(ll)a;i<(ll)b;i++)
#define sep(i,a,b) for(ll i=(ll)a;i>=(ll)b;i--)
#define mll map<ll,ll>
#define vl vector<ll>
#define pb push_back
#define lb lower_bound
#define ub upper_bound
#define all(a) a.begin(),a.end()
#define F first
#define S second
using namespace __gnu_pbds;
using namespace std;
template <typename T>
using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    ll n,k;
    cin>>k>>n;
    ll a[n];
    rep(i,0,n)
    	cin>>a[i];
    ll ans=M;
    rep(i,0,n)
    	ans=min(ans,k-(a[(i+1)%n]-a[i]+k)%k);
    cout<<ans;
}


Measured memory_bytes: 1792