akhauriyash/Code-Regression huggingface dataset:
#if 1
#include <iostream>
#include <fstream>
#include <string>
#include <vector>
#include <map>
#include <set>
#include <unordered_map>
#include <unordered_set>
#include <queue>
#include <stack>
#include <array>
#include <deque>
#include <algorithm>
#include <utility>
#include <cstdint>
#include <functional>
#include <iomanip>
#include <numeric>
#include <assert.h>
#include <bitset>
#include <list>

auto& in = std::cin;
auto& out = std::cout;
#define all_range(C) std::begin(C), std::end(C)
const double PI = 3.141592653589793238462643383279502884197169399375105820974944;

int32_t N,M;
int32_t A[100000];
std::pair<int, int> oper[100000];


#include <vector>

class union_find
{
private:
	std::vector<int>parent;
	std::vector<int>rank;
public:
	union_find(int siz)
	{
		parent.resize(siz);
		rank.resize(siz);
		for (int i = 0; i < siz; ++i)
		{
			parent[i] = i;
			rank[i] = 0;
		}
	}
	void unite(int x, int y)
	{
		int xr = find(x);
		int yr = find(y);
		if (rank[xr] > rank[yr])
		{
			parent[yr] = xr;
		}
		else if (rank[xr] > rank[yr])
		{
			parent[xr] = yr;
		}
		else if (xr != yr)
		{
			parent[yr] = xr;
			++rank[xr];
		}
	}
	int find(int x)
	{
		if (parent[x] == x)
		{
			return x;
		}
		else
		{
			return parent[x] = find(parent[x]);
		}
	}
	bool check(int x, int y)
	{
		return find(x) == find(y);
	}
};

bool used[100000];
std::unordered_set<int> member[100000];
std::unordered_set<int> pos[100000];

int main()
{
	using std::endl;
	in.sync_with_stdio(false);
	out.sync_with_stdio(false);
	in.tie(nullptr);
	out.tie(nullptr);

	in >> N>>M;
	for (int32_t i = 0; i < N; i++)
	{
		in >> A[i]; --A[i];
	}
	union_find uniT(N);
	for (int32_t i = 0; i < M; i++)
	{
		in >> oper[i].first >> oper[i].second; --oper[i].first; --oper[i].second;
		uniT.unite(oper[i].first, oper[i].second);
	}

	for (int32_t i = 0; i < N; i++)
	{
		member[uniT.find(i)].insert(A[i]);
		pos[uniT.find(i)].insert(i);
		//member[uniT.find(oper[i].first)].insert(A[oper[i].first]);
		//pos[uniT.find(oper[i].first)].insert(oper[i].first);
		//member[uniT.find(oper[i].second)].insert(A[oper[i].second]);
		//pos[uniT.find(oper[i].second)].insert(oper[i].second);
	}

	int32_t res = 0;
	for (int32_t i = 0; i < N; i++)
	{
		for (auto& V : member[i]) {
			if (pos[i].count(V) > 0) {
				++res;
			}
		}
	}
	out << res << endl;

	return 0;
}
#endif


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

//#include <bits/stdc++.h>
using namespace std;
#define print(x) cout<<(x)<<endl
#define rep(i, n) for(int i = 0; i < (int)n; i++)
#define ll long long int
#define pb push_back

int main() {
  int N, K, d, o;
  cin >> N >> K;
  vector<int> a(N, 0);

  rep(i, K){
    cin >> d;
    rep(i, d){
      cin >> o;
      a[o-1]++;
    }
  }

  int ans = 0;
  rep(i, N){ 
    // print(a[i]);
    if(a[i] == 0) ans++;
  }
  print(ans);

}


Measured memory_bytes: 3628
#include <bits/stdc++.h>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <vector>
#include <string>
using namespace std;
typedef double  dbl;
typedef long long int lld;
#define foi(i,n) for(i = 0; i < n; i+=1)
#define fod(i,n) for(i=n-1; i >=0; i-=1)
#define MAX std::numeric_limits<lld>::max()
#define MIN std::numeric_limits<lld>::min()
#define FastIO  ios::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
int main (){
    FastIO
    lld n, k;
    cin >> n;
    cin >> k;
    lld c =0;
    while (n!=0){
    	n/=k;
    	c+=1;
    }
    cout << c << "\n";
    return 0;
}

Measured memory_bytes: 256
use std::io::stdin;
fn get_string() -> String {
    let mut s = String::new();
    stdin().read_line(&mut s).unwrap();
    s.trim().to_string()
}

macro_rules! input {
    ($single:ty) => ( get_string().parse::<$single>().unwrap() );
    ($plural:ty,) => ({
        let line = get_string();
        line.split_whitespace().map(|v| v.parse::<$plural>().unwrap()).collect::<Vec<$plural>>()
    });
    ($($plural:ty),+) => ({
        let line = get_string();
        let mut iter = line.split_whitespace();
        ($(iter.next().unwrap().parse::<$plural>().unwrap()),+)
    });
    ($single:ty; $times:expr) => ( (0..$times).map(|_| input!($single)).collect::<Vec<$single>>() );
    ($($plural:ty),+; $times:expr) => ( (0..$times).map(|_| input!($($plural),+)).collect::<Vec<($($plural),+)>>() );
}

#[allow(dead_code)]
fn get_value<T: std::str::FromStr>() -> T {
    get_string().parse().ok().unwrap()
}
#[allow(dead_code)]
fn get_values_for<T: std::str::FromStr>(times: u64) -> Vec<T> {
    (0..times).map(|_| get_value()).collect()
}
#[allow(dead_code)]
fn get_vector<T: std::str::FromStr>() -> Vec<T> {
    get_string()
        .split_whitespace()
        .map(|v| v.parse().ok().unwrap())
        .collect()
}
#[allow(dead_code)]
fn get_vectors_for<T: std::str::FromStr>(times: u64) -> Vec<Vec<T>> {
    (0..times).map(|_| get_vector()).collect()
}

fn main() {
    let n = input!(usize);
    let a = input!(i64,);
    let mut a: Vec<_> = a.iter().enumerate().map(|(i, v)| v - i as i64).collect();
    a.sort();
    println!("{}", calc(&a, a[n / 2]));
}

fn calc(a: &Vec<i64>, b: i64) -> i64 {
    a.iter().fold(0, |s, v| s + (v - b).abs())
}


Measured memory_bytes: 8444
#include<bits/stdc++.h>
#define REP(i,x,y) for(ll i=x; i<=y; i++)
#define BIT(t) ((long long 1) << t)
#define PER(i,y,x) for(ll i=y; i>=x; i--)
#define vll vector<ll>
#define vvll vector<vector<ll>>
#define SIZE(v) ll(v.size())
using namespace std;
typedef long long ll;
ll const MAX = 1e6 + 5;

struct unionfind {
       ll max_un;
       vector<ll> parent;
       vector<ll> components;
       unionfind(ll n) {
               max_un = n;
               parent = vector<ll>(n + 1);
               components = vector<ll>(n + 1);
               for (int i = 0; i <= n; i++) {
                       parent[i] = i;
                       components[i] = 1;
               }
               
       }
       ll find(ll x) {
               if (parent[x] == x) {
                       return x;
               }
               else {
                       parent[x] = find(parent[x]);
                       return parent[x];
               }
       }
       bool same(ll x, ll y) {
               return find(x) == find(y);
       }
       ll comp(ll x) {
               return components[find(x)];
       }
       void unite(ll x, ll y) {
               if (!same(x, y)) {
                       x = parent[x];
                       y = parent[y];
                       if (components[x] <= components[y]) {
                               parent[x] = y;
                               components[y] += components[x];
                       }
                       else {
                               parent[y] = x;
                               components[x] += components[y];
                       }
               }
       }
};

vector<pair<ll,ll>> v;

int main(){
    ll n, m;
    cin >> n >> m;
    bool flag = 0;
    ll q;
    cin >> q;
    unionfind un(n);
    REP(i,1,q){
        ll x,y,z;
        cin >> x >> y >> z;
        if(z == 0){
            un.unite(x, y);
        }else{
            flag = 1;
            v.push_back({x,y});
        }
    }
    REP(i,0,SIZE(v)-1){
        ll x = v[i].first; ll y = v[i].second;
        if(un.same(x, y)){
            cout << "No" << endl;
            return 0;
        }
    }
    if(n == m + 1){
        if(flag){
            cout << "No" << endl;
            return 0;
        }else{
            cout << "Yes" << endl;
            return 0;
        }
    }
    ll tmp = 0;
    REP(i,0,n-1){
        if(i == un.find(i)){
            tmp++;
        }
    }
    if(tmp <= 2){
        cout << "No" << endl;
        return 0;
    }
    m -= n - tmp;
    if(m <= tmp * (tmp-1) / 2){
        cout << "Yes" << endl;
    }else{
        cout << "No" << endl;
    }
}

Measured memory_bytes: 3956
def main():
    import sys
    input = sys.stdin.readline
    sys.setrecursionlimit(10**7)
    from collections import Counter, deque
    #from collections import defaultdict
    from itertools import combinations, permutations, accumulate, groupby, product
    from bisect import bisect_left,bisect_right
    from heapq import heapify, heappop, heappush
    from math import floor, ceil
    #from operator import itemgetter

    #inf = 10**17
    #mod = 10**9 + 7

    a,b = map(int, input().split())
    if a%b == 0:
        print(-1)
    else:
        print(a)

if __name__ == '__main__':
    main()

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

int main() {
  double a, b, x;
  cin >> a >> b >> x;

  double A, angle;
  if(b < 2 * x / (a * a)){
    A = 2 * b - 2 * x / (a * a);
    angle = atan2l(A, a) * 180 / M_PI;
  }
  else{
    A = 2 * x / (a * b);
    angle = atan2l(b, A) * 180 / M_PI;
  }
  printf("%.10f", angle);

  return 0;
}

Measured memory_bytes: 256
N,M,C=map(int,input().split())
B=list(map(int,input().split()))
num=0
A=[]
for i in range(N):
  A.append(list(map(int,input().split())))
D=[]
for j in range(N):
  sum=0
  D=A[j]
  for k in range(M):
    sum+=B[k]*D[k]
  if sum+C>0:
    num+=1
print(num)


Measured memory_bytes: 3064
n = gets.to_i

edge = Array.new(n+1) {[]}
(n-1).times do
    a, b = gets.split.map(&:to_i)
    edge[a] << b
    edge[b] << a
end

vis = Array.new(n+1)
vis[0] = vis[1] = 0
que = [1]
while now = que.shift
    edge[now].each do |e|
        next if vis[e]
        vis[e] = vis[now] + 1
        que << e
    end
end

vis[n] = 0
que = [n]
while now = que.shift
    edge[now].each do |e|
        next if vis[e] <= (vis[now] - 1).abs
        vis[e] = vis[now] - 1
        que << e
    end
end

x = vis.count {|e| e > 0} + 1
y = n - x
puts x > y ? "Fennec" : "Snuke"

Measured memory_bytes: 25308
#!/usr/bin/env python
# -*- coding: utf-8 -*-

"""
input:
aabaaa
aa

output:
0
3
4
"""

import sys


class NaiveStringSearch(object):
    __slots__ = ('target', 'pattern')

    def __init__(self, in_data):
        """"""
        self.target = in_data[0].strip()
        self.pattern = in_data[1].strip()

    def naive_matching(self):
        m, n = len(self.pattern), len(self.target)
        for i in range(n - m + 1):
            for j in range(m):
                if self.target[i + j] != self.pattern[j]:
                    break
                if j == m - 1:
                    print(i)
        return None


if __name__ == '__main__':
    _input = sys.stdin.readlines()
    case = NaiveStringSearch(in_data=_input)
    case.naive_matching()

Measured memory_bytes: 7536
# include <iostream>
# include <algorithm>
# include <vector>
# include <string>
# include <set>
# include <cmath>
# include <iomanip>
# include <functional>

using namespace std;

int main() {
	int a, b;
	cin >> a >> b;
	if (a + b >= 10) {
		cout << "error" << endl;
	}
	else {
		cout << a + b << endl;
	}
}


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

int main(void)
{
	int s,n,a,b;

	while(cin >> s, s){
		cin >> n;
		int now = 0;
		while(--n, n >= 0){
			cin >> a >> b;
			now += (b - a);
		}
		if(now >= s)
			cout << "OK";
		else
			cout << s-now;
		cout << endl;
	}

	return 0;
}

Measured memory_bytes: 1160
#include<stdio.h>
#define W 100
#define H 100
#define N 100

int main(void) {
	int w,h,n,l,m,i;
	int count = 0;
	scanf("%d %d %d", &w, &h, &n);
	int x[n],y[n],a[n],sq[h][w];
	for(i = 0; i < n; i++) {
		scanf("%d %d %d", &x[i], &y[i], &a[i]);
	}
	for(l = 0; l < h; l++) {
		for(m = 0; m < w; m++) {
			sq[l][m]=1;
		}
	}
	for(i = 0; i < n; i++) {
		switch(a[i]) {
			case 1 : 
				for(l = 0; l < h; l++) {
					for(m = 0; m < x[i]; m++) {
						sq[l][m]=0;
					}
				}
				break;
			case 2 : 
				for(l = 0; l < h; l++) {
					for(m = x[i]; m < w; m++) {
						sq[l][m]=0;
					}
				}
				break;
			case 3 : 
				for(l = 0; l < y[i]; l++) {
					for(m = 0; m < h; m++) {
						sq[l][m]=0;
					}
				}
				break;
			case 4 : 
				for(l = y[i]; l < h; l++) {
					for(m = 0; m < w; m++) {
						sq[l][m]=0;
					}
				}
				break;
		}
	}
	for(l = 0; l < h; l++) {
		for(m = 0; m < w; m++) {
			if(sq[l][m]==1) {
				count++;
			}
		}
	}
	printf("%d\n",count);
	return 0;
}


Measured memory_bytes: 256
import sys
input = sys.stdin.readline
ins = lambda: input().rstrip()
ini = lambda: int(input().rstrip())
inm = lambda: map(int, input().split())
inl = lambda: list(map(int, input().split()))

n = ini()
a = inl()
if len(set(a)) == n:
    print(n - 2)
elif len(set(a)) == 1:
    print(n//2)
else:
    f = {}
    s = {}
    for i in range(n):
        if i % 2 == 0:
            if a[i] not in f:
                f[a[i]] = 0
            f[a[i]] += 1
        else:
            if a[i] not in s:
                s[a[i]] = 0
            s[a[i]] += 1
    fsum = sum(f.values())
    ssum = sum(s.values())
    f = sorted(f.items(), key=lambda x: x[1], reverse=True)
    s = sorted(s.items(), key=lambda x: x[1], reverse=True)
    if f[0][0] == s[0][0]:
        tmp1 = fsum - f[0][1] + ssum - s[1][1]
        tmp2 = fsum - f[1][1] + ssum - s[0][1]
        print(min(tmp1, tmp2))
    else:
        print(fsum - f[0][1] + ssum - s[0][1])

Measured memory_bytes: 23112
#include <iostream>
//#include <iomanip>
#include <string>
#include <vector>
#include <algorithm>
//#include <utility>
//#include <set>
//#include <map>
//#include <queue>
//#include <deque>
//#include <bitset>
//#include <math.h>
using namespace std ;
using ll = long long ;
//using ld = long double ;
using vll = vector<ll> ;
//using vvll = vector<vll> ;
//using vc = vector<char> ;
//using vvc = vector<vc> ;
//using vb = vector<bool> ;
//using vvb = vector<vb> ;
//using pll = pair<ll,ll> ;

//ll mod = 1000000007 ;
//long double pie = acos(-1) ;

//void yorn(bool a){if(a) cout << "Yes" << endl ; else cout << "No" << endl ;}
//void YorN(bool a){if(a) cout << "YES" << endl ; else cout << "NO" << endl ;}
//ll gcd(long long a,long long b){if(b==0) return a ; return gcd(b,a%b) ;}
//ll lcm(long long a,long long b){return a/gcd(a,b)*b ;}
//ll sa(long long a,long long b){if(a>b) return a-b ; return b-a ;}
//void mysort(vector<long long> &a){sort(a.begin(),a.end()) ;}
//void myrev(vector<long long> &a){reverse(a.begin(),a.end()) ;}

int main(){
	ll n,m ;
	cin >> n >> m ;
	string s ;
	cin >> s ;
	reverse(s.begin(),s.end()) ;
	for(int i=0;i<m;i++) s += '1' ;
	vll ans ;
	ll pos = 0 ;
	while(pos!=n){
		bool ok = false ;
		for(int i=m;i>0;i--){
			if(s.at(pos+i)=='0'){
				ok = true ;
				pos += i ;
				ans.push_back(i) ;
				break ;
			}
		}
		if(!ok){
			cout << -1 << endl ;
			return 0 ;
		}
	}
	for(int i=ans.size()-1;i>=0;i--){
		cout << ans.at(i) ;
		if(i==0) cout << endl ;
		else cout << " " ;
	}
}


Measured memory_bytes: 1528
import re
import sys
import math
import itertools
import bisect
from copy import copy
from collections import deque,Counter
from decimal import Decimal
import functools
def v(): return input()
def k(): return int(input())
def S(): return input().split()
def I(): return map(int,input().split())
def X(): return list(input())
def L(): return list(input().split())
def l(): return list(map(int,input().split()))
def lcm(a,b): return a*b//math.gcd(a,b)
sys.setrecursionlimit(10 ** 9)
mod = 10**9+7
cnt = 0
ans = 0
inf = float("inf")
al = "abcdefghijklmnopqrstuvwxyz"

n,x,t = I()

if n % x == 0:
    print(t*(n//x))
else:
    print(t*(n//x+1))




Measured memory_bytes: 10472
import java.util.*;
public class Main{
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        String s = sc.next();
        long k = sc.nextLong();
        k = Math.min(k , (long) 100);
        sc.close();
        int n = -1;
        while(k > 0){
            n++;
            k--;
            if(s.charAt(n) != '1'){
                k = -2;
                System.out.println(s.charAt(n));
            }else{
            }
        }
        if(k != -2){
            System.out.println(1);
        }
    }
}

Measured memory_bytes: 35660
H, W, K = map(int, input().split())
S =[list(input()) for _ in range(H)]

# ans = [[0] * W for _ in range(H)]

num = 1
for i in range(W):
  swt = False
  for j in range(H):
    if S[j][i] == "#":
      S[j][i] = num
      num += 1
      swt = True
    if S[j][i] == ".":
      if swt == True:
        S[j][i] = S[j-1][i]
  swt = False
  for j in range(H - 1, -1, -1):
    if S[j][i] != ".":
      swt = True
    if S[j][i] == ".":
      if swt == True:
        S[j][i] = S[j+1][i]

for j in range(H):
  swt = False
  for i in range(W):
    if S[j][i] != ".":
      swt = True
    if S[j][i] == ".":
      if swt == True:
        S[j][i] = S[j][i-1]
  swt = False
  for i in range(W - 1, -1, -1):
    if S[j][i] != ".":
      swt = True
    if S[j][i] == ".":
      if swt == True:
        S[j][i] = S[j][i+1]

for i in S:
  print(*i)      

Measured memory_bytes: 7444
#include <iostream>
#include <cstdio>
#include <bits/stdc++.h>
#define FOR(i, m, n) for(int i = m;i < n;i++)
#define FORq(i, m, n) for(int i = m;i <= n;i++)
using namespace std;

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



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

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

  set<int> d;
  for (int i = 0; i < n; i++) {
    int a;
    cin >> a;
    d.insert(a);
  }

  cout << d.size() << endl;
}

Measured memory_bytes: 384
#include<cstdio>
#include<cstring>
#include<iostream>
using namespace std;
int main ()
{
    int al[3][102];
    int i,j,a;
    memset(al,0,sizeof(al));
    cin>>a;
    for(i=1;i<=2;i++)
    {
        for(j=1;j<=a;j++)
        {
            cin>>al[i][j];
        }
    }
    for(i=1;i<=2;i++)
    {
        for(j=1;j<=a;j++)
        {
            al[i][j]+=max(al[i-1][j],al[i][j-1]);
        }
    }
    cout<<al[2][a]<<endl;;
    return 0;
}

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

using namespace std;
using LL = long long;

constexpr int N = 1e5 + 5;

int n;
vector< string> vs;

void go(int k, string s, char mx) {
	if (k == n) {
		vs.push_back(s);
		return;
	}

	for (char x = 'a'; x <= mx + 1; x++) {
		s.push_back(x);
		go(k + 1, s, max(mx, x));
		s.pop_back();
	}
}

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

	cin >> n;
	go(1, "a", 'a');

	//sort(begin(vs), end(vs));
	for (auto s : vs) cout << s << "\n";
}

Measured memory_bytes: 9332
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;
#define li          long
#define ll          long long
#define ull         unsigned long long
#define ff          first
#define ss          second
#define pii         pair<int,int>
#define pli         pair<li,li>
#define pll         pair<ll,ll>
#define pb          push_back
#define fo(i,k,n)   for(int i = k;i<n; i++)
#define ro(i,k,n)   for(int i = k; i>=n; i--)
#define tc          int t;cin>>t;while(t--)
#define all(v)      v.begin(),v.end()
#define inf         INT_MAX
#define ninf        INT_MIN
#define W(x)        cout<<x<<endl
#define WW(x,y)     cout<<x<<' '<<y<<endl;
#define in(x)       cin>>x
#define vi          vector<int>
#define vll         vector<long long>
#define vpi         vector<pair<int>>
#define vpll        vector<pair<long long>>
#define vvi         vector<vector<int>>
#define vvll        vector<vector<long long>>
#define vvpi        vector<vector<pair<int,int>>>
#define vvpll       vector<vector<pair<long long>>>
#define int long long
const ll mod1 = 99844353;
const ll mod2 = 1e9+7;
template <class T>
using oset = tree<T,null_type,less<T>,rb_tree_tag,tree_order_statistics_node_update>;
void fastio()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
}
template<class T>
T power(T a,T b){
    T res = (T)1;
    while(b>0){
        if(b&1)res = res*a;
        b>>=1;
        a*=a;
    }
    return res;
}
int n,k;
bool check(vector<int> &a){
    for(int i = 0; i<n; i++)if(a[i]<n)return false;
    return true;
}
void solve(){
    cin>>n>>k;
    vector<int> a(n);
    for(int i = 0; i<n; i++)cin>>a[i];
    vector<int> temp;
    while(!check(a)&&k>0){
        temp.clear();
        temp.assign(n,0);
        for(int i = 0; i<n; i++){
            int l = max(0*1LL,i-a[i]);
            int r = min(n,i+a[i]);
            temp[l]+=1;
            if(r+1<n)temp[r+1]-=1;
        }
        for(int i = 1; i<n; i++){
            temp[i]+=temp[i-1];
        }
        a = temp;
        k-=1;
    }
    for(int x:a)cout<<x<<' ';
}
signed main(){
    fastio();
    int t = 1;
    //cin>>t;
    while(t--){
        solve();
    }
}


Measured memory_bytes: 6364
#include "iostream"
#include "climits"
#include "list"
#include "queue"
#include "stack"
#include "set"
#include "functional"
#include "algorithm"
#include "string"
#include "map"
#include "unordered_map"
#include "unordered_set"
#include "iomanip"
#include "cmath"
#include "random"
#include "bitset"
#include "cstdio"
#include "numeric"
#include "cassert"
#include "ctime"

using namespace std;

constexpr long long int MOD = 1000000007;
//constexpr int MOD = 1000000007;
//constexpr int MOD = 998244353;
//constexpr long long int MOD = 998244353;
constexpr long double EPS = 1e-12;

//int N, M, K, H, W, L, R;
long long int N, M, K, H, W, L, R;

class UnionFind {
	vector<int>parent;
	vector<int>rank;
public:
	UnionFind(int num) {
		num++;
		parent.resize(num);
		rank.resize(num);
		for (int i = 0; i < num; i++) {
			parent[i] = i;
			rank[i] = 0;
		}
	}
	int Find(int node) {
		if (parent[node] == node)return node;
		else return parent[node] = Find(parent[node]);
	}
	void Unite(int u, int v) {
		u = Find(u);
		v = Find(v);
		if (u == v)return;
		if (rank[u] < rank[v])parent[u] = v;
		else {
			parent[v] = u;
			if (rank[u] == rank[v])rank[u]++;
		}
	}
	bool Check_Same(int u, int v) {
		return Find(u) == Find(v);
	}
};

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

	cin >> N >> M;
	vector<pair<int, int>>v(N);
	for (auto &i : v)cin >> i.first >> i.second;
	sort(v.begin(), v.end());
	vector<pair<int, int>>box(M);
	for (auto &i : box)cin >> i.first >> i.second;
	vector<int>node(N + 1);
	sort(v.begin(), v.end());
	for (int i = 0; i < N; i++) {
		node[i] ^= v[i].second;
		node[i + 1] ^= v[i].second;
	}
	vector<int>ans;
	map<pair<int, int>, int>edgemp;
	for (int i = 0; i < M; i++) {
		auto a = lower_bound(v.begin(), v.end(), make_pair(box[i].first, 0)) - v.begin();
		auto b = lower_bound(v.begin(), v.end(), make_pair(box[i].second, 2)) - v.begin() - 1;
		if (a > b)continue;
		edgemp[{a, b + 1}] = i + 1;
	}
	vector<vector<int>>edge(N + 1);
	for (auto i : edgemp) {
		edge[i.first.first].push_back(i.first.second);
		edge[i.first.second].push_back(i.first.first);
	}
	vector<int>depth(N + 1, MOD);
	for (int i = 0; i <= N; i++) {
		if (depth[i] != MOD)continue;
		depth[i] = 0;
		queue<int>Q;
		Q.push(i);
		vector<int>rev;
		while (!Q.empty()) {
			int cn = Q.front();
			Q.pop();
			for (auto j : edge[cn]) {
				if (depth[j] > depth[cn] + 1) {
					depth[j] = depth[cn] + 1;
					Q.push(j);
					rev.push_back(j);
				}
			}
		}
		reverse(rev.begin(), rev.end());
		for (auto j : rev) {
			if (node[j]) {
				node[j] = 0;
				for (auto k : edge[j]) {
					if (depth[k] < depth[j]) {
						node[k] ^= 1;
						ans.push_back(edgemp[{min(j, k), max(j, k)}]);
						break;
					}
				}
			}
		}
	}
	if (accumulate(node.begin(), node.end(), 0)) {
		cout << -1 << endl;
		return 0;
	}
	sort(ans.begin(), ans.end());
	cout << ans.size() << endl;
	for (auto i : ans)cout << i << " ";
	cout << endl;
	return 0;
}


Measured memory_bytes: 23160
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <vector>

const int kN = 300 + 5;
const int MOD = 998244353;
int n, a[kN];
int c[kN * kN];
int d[kN * kN];

int power(int a, int b) {
  int ret = 1;
  for ( ; b; b >>= 1, a = a * 1LL * a % MOD) if (b & 1) ret = ret * 1LL * a % MOD;
  return ret;
}

int main() {
  scanf("%d", &n);
  for (int i = 0; i < n; ++ i) {
    scanf("%d", a + i);
  }
  int s = 0;
  c[0] = 1;
  d[0] = 1;
  for (int i = 0; i < n; ++ i) {
    for (int j = s; j >= 0; -- j) {
      (c[j + a[i]] += c[j]) %= MOD;
      (c[j] += c[j]) %= MOD;
      (d[j + a[i]] += d[j]) %= MOD;
    }
    s += a[i];
  }
  int result = power(3, n);
  for (int i = (s + 1) / 2; i <= s; ++ i) {
    result = (result - 3 * 1LL * c[i] % MOD + MOD) % MOD;
  }
  if (~s & 1) {
    result = (result + 3 * 1LL * d[s / 2] % MOD + MOD) % MOD;
  }
  printf("%d\n", result);
}


Measured memory_bytes: 896
#include <bits/stdc++.h>
#define NMAX 100005
using namespace std;
int n,k,d[NMAX],maxim,a[NMAX];
int main()
{
    cin>>n>>k;
    for(int i=1;i<=n;i++)
        cin>>a[i];
    for(int j=0;j<=k;j++)
    {
        if(d[j]==0)
        {
            for(int i=1;i<=n;i++)
            {
                if(j+a[i]<=k)
                    d[j+a[i]]=1;
            }
        }
    }
    if(d[k])
        cout<<"First";
    else
        cout<<"Second";
    return 0;
}


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

#define int long long
#define fi first
#define se second
#define rep(i,n) for(int i=0;i<(int)(n);++i)
#define rep1(i,n) for(int i=1;i<=(int)(n);++i)
#define rep11(i,n) for(int i=1;i<(int)(n);++i)
#define repo(i,o,n) for(int i=o;i<(int)(n);++i)
#define repm(i,n) for(int i=(int)(n)-1;i>=0;--i)
#define all(v) (v).begin(),(v).end()
#define rall(v) (v).rbegin(),(v).rend()
#define pb(n) push_back(n)
#define mp make_pair
#define MOD 1000000007
#define INF LONG_LONG_MAX
#define yn(f) cout << (f ? "Yes" : "No") << endl;

string s;
bool kr(int r, int l) {
    rep(i,(abs(r-l)+1)/2) {
        if (s[r+i] != s[l-i]) return false;
    }
    return true;
}

signed main() {
    cin >> s;
    int n = s.size();
    if (kr(0, n-1) && kr(0,(n-1)/2-1) && kr((n+3)/2-1, n-1)) yn(true)
    else yn(false)
}

Measured memory_bytes: 256
import sys
import numpy as np
from itertools import product

I = np.array(sys.stdin.read().split(), dtype=np.int64)
n, m = I[:2]
x, y, z = I[2:].reshape(n, 3).T 

def main():
    ans = 0
    for opx, opy, opz in product([1, -1], repeat=3):
        s = opx * x + opy * y + opz * z
        res = np.sort(s)[::-1][:m].sum()
        ans = max(ans, res)
    
    return ans

if __name__ == '__main__':
    ans = main()
    print(ans)

Measured memory_bytes: 12488
#include <bits/stdc++.h>
using namespace std;
#define pb push_back
#define fi first
#define se second
#define all(x) (x).begin(), (x).end()
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define repp(i, a, b) for (int i = a; i <= (b); ++i)
#define repr(i, a, b) for (int i = a; i >= (b); --i)
#define bit(n) (1LL << (n))
typedef long long ll;
const int INF = 1001001001;
const ll LINF = 1001001001001001001ll;
const int MOD = 1000000007;

template <class T>
inline bool chmin(T& a, T b) {
  if (a >= b) {
    a = b;
    return true;
  }
  return false;
}

template <class T>
inline bool chmax(T& a, T b) {
  if (a <= b) {
    a = b;
    return true;
  }
  return false;
}

int main() {
  int N;
  cin >> N;
  vector<vector<ll>> A(N, vector<ll>(N));
  rep(i, N) {
    rep(j, N) {
      cin >> A[i][j];
    }
  }

  vector<vector<bool>> need(N, vector<bool>(N, true));
  rep(i, N) {
    rep(j, N) {
      rep(k, N) {
        if (k == i || k == j)
          continue;

        if (A[i][j] > A[i][k] + A[k][j]) {
          cout << -1 << endl;
          return 0;
        }

        if (A[i][j] == A[i][k] + A[k][j])
          need[i][j] = false;
      }
    }
  }

  ll ans = 0;
  rep(i, N - 1) {
    repp(j, i + 1, N - 1) {
      if (need[i][j])
        ans += A[i][j];
    }
  }
  cout << ans << endl;
}

Measured memory_bytes: 1024
class UnionFindTree:
    __slots__ = ('__parents', )

    def __init__(self, n):
        self.__parents = [-1] * n

    def find(self, x):
        p = self.__parents
        if p[x] < 0:
            return x
        parent = self.find(p[x])
        p[x] = parent
        return parent

    def union(self, x, y):
        p = self.__parents
        x = self.find(x)
        y = self.find(y)
        if x == y:
            return False
        if p[x] > p[y]:
            x, y = y, x
        p[x] += p[y]
        p[y] = x
        return True

    def same(self, x, y):
        return self.find(x) == self.find(y)

    def size(self, x):
        return -self.__parents[self.find(x)]


def spline(func_=int, iter_=None):
    if iter_ is None:
        iter_ = input().split()
    return map(func_, iter_)


def main():
    n, m, k = spline()
    similar = UnionFindTree(n)
    candidates = [-1] * n
    for _ in range(m):
        a, b = spline()
        a -= 1
        b -= 1
        similar.union(a, b)
        candidates[a] -= 1
        candidates[b] -= 1
    for i in range(n):
        candidates[i] += similar.size(i)
    for _ in range(k):
        c, d = spline()
        c -= 1
        d -= 1
        if similar.same(c, d):
            candidates[c] -= 1
            candidates[d] -= 1
    print(*candidates, sep=' ')


if __name__ == "__main__":
    main()


Measured memory_bytes: 13436
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
int myabs(int n)
{
    return n < 0 ? n*-1 : n;
}
int main()
{
    int N,K;
    while(cin>>N>>K)
    {
        vector<int> vec(N+5),dp(N+5,1e9+1);
        for(int i=0;i<N;i++)
        {
            cin>>vec[i];
        }
        dp[0] = 0;
        for(int i = 0 ; i < N ; i++)
        {
            for(int j = 1 ; j <= K ; j++)
            {
                if(i + j >= N)break;
                int x = myabs(vec[i + j] - vec[i]) + dp[i] ;
                if(dp[i + j] > x)
                {
                    dp[i + j] = x;
                }
            }
        }
        cout<<dp[N-1]<<'\n';
    }
    return 0;
}


Measured memory_bytes: 1024
#include <iostream>
#include <limits.h>
using namespace std;

int main(void){
	int n;
	int r;
	int max = INT_MIN;
	int min =  100000000;

	cin >> n;

	cin >> r;
	min = r;
	for(int i=1; i<n; i++){
		cin >> r;
		if(r - min > max){
			max = r - min; 
		}
		if(min > r) min = r;
	}

	cout << max << endl;

	return 0;
}

Measured memory_bytes: 1164
#include<iostream>
#include<cstdio>
#include<string>
#include<algorithm>
#include<cstring>
using namespace std;
#define int(x) int x; scanf("%d",&x)
#define input(x) scanf("%d",&x)
#define rep(x,n) for(int x = 0; x < n; x++)
#define _br printf("\n")
#define INF 2000000000

typedef unsigned long long ull;

ull count_rev=0;
int A[200000];
int L[100002],R[100002];

void marge(int l, int m, int r){
    int nl = m-l;
    int nr = r-m;
    
    rep(i,nl) L[i] = A[l+i];
    rep(i,nr) R[i] = A[m+i];
    L[nl] = INF;
    R[nr] = INF;
    int countL = 0;
    int countR = 0;
    rep(i,nl+nr){
        if (L[countL] <= R[countR]) {
            A[l+countL+countR] = L[countL];
            countL++;
        }else{
            A[l+countL+countR] = R[countR];
            count_rev += nl - countL;
            countR++;
        }
    }
}

void divide(int l, int r){
    if (r-l > 1) {
        int m = (l+r)/2;
        divide(l,m);
        divide(m,r);
        marge(l,m,r);
    }
}

int main(){
    int n;
    cin >> n;
    rep(i,n) input(A[i]);
    
    divide(0,n);
    
    cout << count_rev << endl;
    
    return 0;
}

Measured memory_bytes: 2804
#include <bits/stdc++.h>
#define endl '\n'
#define int long long
#define lint long long
#define pii pair<int, int>
#define FOR(i, a, b) for(int i = (a); i < (b); ++i)
#define REP(i, n) FOR(i, 0, n)
#define ALL(v) (v).begin(), (v).end()
#define SZ(v) ((int)v.size())
#define ZERO(a) memset(a, 0, sizeof(a))
#define MINUS(a) memset(a, 0xff, sizeof(a))
#define MINF(a) memset(a, 0x3f, sizeof(a))
#define POW(n) (1LL << (n))
#define POPCNT(n) (__builtin_popcount(n))
#define IN(i,a,b) (a <= i && i <= b)
using namespace std;
template <typename T> inline bool CHMIN(T& a,T b) { if(a>b) { a=b; return 1; } return 0; }
template <typename T> inline bool CHMAX(T& a,T b) { if(a<b) { a=b; return 1; } return 0; }
template <typename T> inline void SORT(T& a) { sort(ALL(a)); }
template <typename T> inline void REV(T& a) { reverse(ALL(a)); }
template <typename T> inline void UNI(T& a) { sort(ALL(a)); a.erase(unique(ALL(a)),a.end()); }
template <typename T> inline T LB(vector<T>& v, T a) { return *lower_bound(ALL(v),a); }
template <typename T> inline int LBP(vector<T>& v, T a) { return lower_bound(ALL(v),a) - v.begin(); }
template <typename T> inline T UB(vector<T>& v, T a) { return *upper_bound(ALL(v),a); }
template <typename T> inline int UBP(vector<T>& v, T a) { return upper_bound(ALL(v),a) - v.begin(); }
template <typename T1, typename T2> ostream& operator<< (ostream& os, const pair<T1,T2>& p) { os << p.first << " " << p.second; return os; }
template <typename T1, typename T2> istream& operator>> (istream& is, pair<T1,T2>& p) { is >> p.first >> p.second; return is; }
template <typename T> ostream& operator<< (ostream& os, const vector<T>& v) { REP(i,v.size()) { if (i) os << " "; os << v[i]; } return os; }
template <typename T> istream& operator>> (istream& is, vector<T>& v) { for(T& in : v) is >> in; return is; }
template <typename T = int> vector<T> make_v(size_t a) { return vector<T>(a); }
template <typename T, typename... Ts> auto make_v(size_t a, Ts... ts) { return vector<decltype(make_v<T>(ts...))>(a,make_v<T>(ts...)); }
template <typename T, typename V> typename enable_if<is_class<T>::value == 0>::type fill_v(T &t, const V &v) { t = v; }
template <typename T, typename V> typename enable_if<is_class<T>::value != 0>::type fill_v(T &t, const V &v) { for(auto &e : t) fill_v(e, v); }
const lint MOD = 1000000007;
const lint INF = 0x3f3f3f3f3f3f3f3f;
const double PI = 3.14159265358979323846;
const double EPS = 1e-10;

int N;
string S;

void _main() {
    cin >> N >> S;
    if (N % 2 != 0) {
        cout << "No" << endl;
    } else {
        string T = S.substr(0, N / 2);
        cout << (S == T + T ? "Yes" : "No") << endl;
    }
}

signed main(signed argc, char **argv) {
    if (argc > 1) {
        if (strchr(argv[1], 'i')) freopen("input.txt", "r", stdin);
        if (strchr(argv[1], 'o')) freopen("output.txt", "w", stdout);
    }
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cout << fixed << setprecision(10);
    _main();
    return 0;
}

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

int main(){
  int f,t;
  int dis[7][7] = { { 0, 6,13,18,23,43,58},
		    { 6, 0, 7,12,17,37,52},
		    {13, 7, 0, 5,10,30,45},
		    {18,12, 5, 0, 5,25,40},
		    {23,17,10, 5, 0,20,35},
		    {58,52,45,40,35,15, 0} };
  int fee[7][7] = { {   0, 300, 500, 600, 700,1350,1650},
		    { 300,   0, 350, 450, 600,1150,1500},
		    { 500, 350,   0, 250, 400,1000,1350},
		    { 600, 450, 250,   0, 250, 850,1300},
		    { 700, 600, 400, 250,   0, 600,1150},
		    {1350,1150,1000, 850, 600,   0, 500},
		    {1650,1500,1350,1300,1150, 500,   0} };
  int h,m;
  bool flag;
  int ans;

  while(1){
    cin >> f;
    if(!f)break;
    f--;

    flag = false;
    cin >> h >> m;
    if(h==17 && m>=30)flag = true;
    else if(h == 18)flag = true;
    else if(h==19 && m<=30)flag = true;

    cin >> t;
    t--;
    cin >> h >> m;
    if(h==17 && m>=30)flag = true;
    else if(h == 18)flag = true;
    else if(h==19 && m<=30)flag = true;

    ans = fee[f][t];
    if(flag && dis[f][t]<=40){
      ans /= 2;
      if(ans != (ans/50)*50)ans = (ans/50 + 1)*50;
    }
    cout << ans << endl;
  }
}

Measured memory_bytes: 0
N = int(input())
arr = [0]*(N)
lim = int(N**0.5 + 1)
for i in range(1,lim):
    for j in range(1,lim):
        for k in range(1,lim):
            num = i**2 + j**2 + k**2 + i*j + j*k + k*i - 1
            if num <= N-1:
                arr[num] += 1

print(*arr, sep='\n')



Measured memory_bytes: 74728
using System;
using System.Collections.Generic;
using System.Linq;

class Program{

  static int Main() {

    long ans = 0;
    long[] nin = new long[5];

    long n = long.Parse(Console.ReadLine());

    for (int i = 0; i < 5;  i ++) {
      nin[i] = long.Parse(Console.ReadLine());
    }
    // ここまで入力

    if (nin.Min() >= n) {
      ans = 5;
    } else {
      ans = (n + nin.Min() - 1) / nin.Min() + 4;
    }

      Console.WriteLine("{0}", ans);

      return 0;
    }
}


Measured memory_bytes: 13268
n = [1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51]
K = int(input())
print(n[K-1])

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

#define rep(i,j,n) for(int i=(j);i<(n);i++)
#define erep(i,j,n) for(int i=(j);i<=(n);i++)
#define all(i) i.begin(),i.end()
#define rall(i) i.rbegin(),i.rend()
#define INF 1e9
const int mod = 1e9+7;

typedef vector<int> vi;
typedef vector<string> vs;
typedef vector<vi> vvi;
typedef pair<int, int> pi;
typedef long long i64;

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

  int n;
  while(cin >> n, n) {
    string s;
    cin >> s;
    vi ans(n, 0);
    int x = 0;
    rep(i, 0, 100) {
      if(s[i] == 'S') {
        x += ans[i % n];
        x++;
        ans[i % n] = 0;
      }
      else if(s[i] == 'L') {
        ans[i % n] += x;
        ans[i % n]++;
        x = 0;
      }
      else ans[i % n]++;
    }
    sort(all(ans));
    rep(i, 0, n) {
      cout << ans[i] << " ";
    }
    cout << x << endl;
  }
}



Measured memory_bytes: 3220
#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,sse3,sse4,popcnt,abm,mmx")
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#define pb push_back
#define F first
#define S second
#define ins insert
#define mp make_pair
#define fo(i, n1, n, x) for(int i = n1; i <= n; i += x)
#define foo(i, n, n1, x) for(int i = n; i >= n1; i -= x)
#define bit __builtin_popcount
#define md (l + ((r - l) / 2))
#define all(x) x.begin(),x.end()
#define eb emplace_back
#define ub upper_bound
#define lb lower_bound
#define ios ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define file(s) if (fopen(s".in", "r")) freopen(s".in", "r", stdin), freopen(s".out", "w", stdout)

using namespace std;
using namespace __gnu_pbds;

typedef long long ll;
typedef long double ld;

const int N = 2e5 + 11, mod = 1e9 + 7, mod2 = 998244353;
const int MAX = 3e5 + 11;
const int INF1 = 2e9 + 11;
const ll INF2 = 2e18 + 11;
const double INF3 = 1e8 + 11;
const int base = 500;
const int P = 31;
const int dx[] = {1, -1, 0, 0, 1, 1, -1, -1};
const int dy[] = {0, 0, 1, -1, 1, -1, 1, -1};
const double EPS = 1e-6;
const double PI = acos(-1.0);


template<typename T> using ordered_set = tree <T, null_type, less <T>, rb_tree_tag, tree_order_statistics_node_update>;
template<typename T1, typename T2> inline void chmin(T1 &a, T2 b) { if (a > b) a = b; }
template<typename T1, typename T2> inline void chmax(T1 &a, T2 b) { if (a < b) a = b; }


typedef pair <int, int> pii;
typedef pair <ll, ll> pll;

mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

int n;
double a[111],ans;
main() {
    file("walk");
    ios;
    cin>>n;
    fo(i,1,n,1) cin>>a[i],ans+=(1.0/a[i]);
    ans=(1.0/ans);
    cout<<fixed<<setprecision(9)<<ans;
    return 0;
}
/**

*/


Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<set>
#include<algorithm>
using namespace std;
int main(){
	int n;
	scanf("%d", &n);
	for(int tc=0;tc<n;++tc){
		string s;
		set<string> m;
		cin>>s;
		if(cin.eof())break;
		for(unsigned int i = 1; i < s.length(); ++i){
			string s_front = s.substr(0,i);
			string s_back = s.substr(i,s.length()-i);
			m.insert( s_front + s_back );
			m.insert( s_back + s_front );
			reverse( s_front.begin(), s_front.end() );
			m.insert( s_front + s_back );
			m.insert( s_back + s_front );
			reverse( s_front.begin(), s_front.end() );
			reverse( s_back.begin(), s_back.end() );
			m.insert( s_front + s_back );
			m.insert( s_back + s_front );
			reverse( s_front.begin(), s_front.end() );
			m.insert( s_front + s_back );
			m.insert( s_back + s_front );
		}
		printf("%d\n", m.size());
	}
	return 0;
}

Measured memory_bytes: 1032
#include <iostream>
using namespace std;
int main(void) {
	int n, j;
	char s[105], t[105];
	cin >> n;
	cin >> s >> t;
	for (j = 0; j < n; j++) {
		cout << s[j] << t[j];
	}
	cout << endl;
	return 0;
}

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

#ifdef LOCAL
#include "debug_print.hpp"
#else
void debug(...) {}
#endif

template<class T> inline bool chmax(T &a, T b)
{
    if(a < b)
    {
        a = b;
        return true;
    }
    return false;
}

void dfs(int num, vector<int> vec, vector<vector<int>>& vecs, int N, int M)
{
    vec.push_back(num);
    if((int)vec.size() == N)
    {
        vecs.push_back(vec);
        return;
    }
    for(int i=num; i<=M; i++)
    {
        dfs(i, vec, vecs, N, M);
    }
}

int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    int N, M, Q;
    cin >> N >> M >> Q;
    vector<int> A(Q), B(Q), C(Q), D(Q);
    for(int i=0; i<Q; i++) cin >> A[i] >> B[i] >> C[i] >> D[i];

    vector<vector<int>> vecs;
    for(int i=1; i<=M; i++) dfs(i, vector<int>(), vecs, N, M);

    debug(vecs);
    ll ans = 0;
    for(auto vec : vecs)
    {
        ll lans = 0;
        for(int i=0; i<Q; i++)
        {
            if(vec[B[i]-1] - vec[A[i]-1] == C[i]) lans += D[i];
        }
        chmax(ans, lans);
    }
    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 16160
#include <bits/stdc++.h>
#define int long long
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep2(i, s, n) for (int i = (s); i < (int)(n); i++)
using namespace std;
signed main(){
    int n; cin >> n;
    vector<int> a(n);
    rep(i,n) cin >> a[i];
    int cnt = 0;
    for (int i = 0; i < n-1; i++){
        for (int j = n-1; j > i; j--){
            if(a[j-1] > a[j]){
                swap(a[j],a[j-1]);
                cnt++;
            }
        }
    }
    rep(i,n){
        if (i == n-1) cout << a[i] << endl;
        else cout << a[i] << " ";
    }
    cout << cnt << endl;
    return 0;
}


Measured memory_bytes: 3104
#include<bits/stdc++.h>
using namespace std;
#define ll long long



int main(){
    ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
    int n;
    cin>>n;
    int c=0;
    int p=0;
    while(n--){
        int a, b;
        cin>>a>>b;
        if(a==b) c++;
        else c=0;
        if(c==3){cout<<"Yes"; return 0;}
    }
    cout<<"No";
}


Measured memory_bytes: 3648
S=input()
K=int(input())
h=1
b=0
l=[]
f=False
c1=0
c2=0
c3=0
c4=0
r=[]
v=[]
vf=False
vf1=False
vf2=False
for i in range(len(S)-1):
    if S[i]==S[i+1]:
        if i==0:
            c1=1
            c3=1
        if (i+1)==(len(S)-1):
            c2=1
            c4=1
        h+=1
        f=True
    else:
        f=False
    if not f:
        if h!=1:
            l.append(h)
            if c3==1:
                r.append(h)
                c3=0
            if c4==1:
                r.append(h)
                c4=0
        h=1
#print(l)
if f:
    l.append(h)
    #print(l)
    if c4==1:
        r.append(h)
        c4=0
#print(l)
if S[0]==S[-1]:
    #print(l)
    if c1==1 and c2==1:
        if len(l)==1:
            s=len(S)*K
            print(s//2)
            exit()
        else:
            v.append(l[0])
            v.append(l[-1])
            l[-1]+=l[0]
            del l[0]
            vf=True
    elif c1==1:
        #l[0]+=1
        v.append(l[0])
        #v.append(l[-1])
        l[0]+=1
        v.append(l[0])
        del l[0]
        vf1=True
    elif c2==1:
        #l[-1]+=1
        #v.append(l[0])
        v.append(l[-1])
        l[-1]+=1
        v.append(l[-1])
        del l[-1]
        vf2=True
    else:
        if len(S)==1:
            print(K//2)
            exit()
        print(K-1)
        exit()
h=0
if vf:
    h+=v[0]//2
    h+=v[-1]//2
    for i in range(len(l)):
        if i==(len(l)-1):
            h+=(l[i]//2)*(K-1)
        else:
            h+=(l[i]//2)*K
elif vf1:
    h+=(v[1]//2)*(K-1)
    h+=(v[0]//2)
    for i in range(len(l)):
        h+=(l[i]//2)*K
elif vf2:
    h+=(v[1]//2)*(K-1)
    h+=(v[0]//2)
    for i in range(len(l)):
        h+=(l[i]//2)*K
else:
    for i in range(len(l)):
        h+=(l[i]//2)*K

#print(l)
print(h)

Measured memory_bytes: 38384
h,w,k = map(int,input().split())
board = [list(input()) for _ in range(h)]
ans = 0
for paint_h in range(2**h):
    for paint_w in range(2**w):
        cnt = 0
        for i in range(h):
            for j in range(w):
                if(paint_h>>i)&1==0 and (paint_w>>j)&1==0:
                    if board[i][j]=='#':
                        cnt += 1
        if cnt == k:    
            ans += 1
print(ans)

Measured memory_bytes: 9100
#include <bits/stdc++.h>
using namespace std;
#define int long long
signed main() {
	int K;
	cin >> K;
	cout << 50 << endl;
	int x = K / 50;
	int y = K % 50;
	for (int i = 0; i < 50; i++) {
		if (i > 0) {
			cout << " ";
		}
		if (i < y) {
			cout << 50 + x + 50 - y;
		}
		else {
			cout << 49 + x - y;	
		}
	}
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
#define lli long long int
#define REP(i,s,n) for(lli i=s;i<n;i++)
#define NUM 2520
#define INF (1LL<<50)
#define DEBUG 0
#define mp(a,b) make_pair(a,b)
#define SORT(V) sort(V.begin(),V.end())
#define PI (3.141592653589794)
#define TO_STRING(VariableName) # VariableName
#define LOG(x) if(DEBUG)cout<<TO_STRING(x)<<"="<<x<<" "<<endl;
#define LOG2(x,y) if(DEBUG)cout<<TO_STRING(x)<<"="<<x<<" "<<TO_STRING(y)<<"="<<y<<endl;
#define LOG3(x,y,z) if(DEBUG)cout<<TO_STRING(x)<<"="<<x<<" "<<TO_STRING(y)<<"="<<y<<" "<<TO_STRING(z)<<"="<<z<<endl;
#define LOG4(w,x,y,z) if(DEBUG)cout<<TO_STRING(w)<<"="<<w<<" "<<TO_STRING(x)<<"="<<x<<" "<<TO_STRING(y)<<"="<<y<<" "<<TO_STRING(z)<<"="<<z<<endl;
 
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; }

lli d;
lli c[26];
lli s[370][26];
lli t[370];
lli lastDay[26];
std::chrono::system_clock::time_point start;

lli score(){

	lli ans = 0;
	REP(i,0,26)lastDay[i]=0;

	REP(i,1,d+1){
		ans += s[i-1][t[i-1]];

		lastDay[t[i-1]] = i;
		REP(j,0,26){
			ans -= c[j]*(i-lastDay[j]);
		}
		//cout<<ans<<endl;
	}
	return ans;
}

void dummyDayInput(){

	REP(i,0,d){
		cin>>t[i];
		//t[i]=1;
		t[i]--;
	}

}

void input(){
	cin>>d;
	REP(i,0,26)cin>>c[i];
	REP(i,0,d){
		REP(j,0,26){
			cin>>s[i][j];
		}
	}
}

void dummyDayChangeInput(){
	lli m;
	cin>>m;

	REP(i,0,m){
		lli d,q;
		cin>>d>>q;
		d--,q--;
		t[d] = q;
		cout<<score()<<endl;
	}
}

void init(){
	REP(i,0,365){
		lli maxD = -1;
		lli maxScore = 0;
		REP(j,0,26){
			if(maxScore<s[i][j]){
				maxScore = s[i][j];
				maxD = j;
			}
		}
		t[i] = maxD;
	}
}

void outputT(){
	REP(i,0,d){
		cout<<t[i]+1<<endl;
	}
}

int main(){

	ios::sync_with_stdio(false);
	std::cin.tie(nullptr);
	start = std::chrono::system_clock::now();
	mt19937 mt{std::random_device{}()};

	const lli T = 1950*1000;

	input();
	init();

	uniform_int_distribution<int> contestDist(0,25);
	uniform_int_distribution<int> dayDist(0,d-1);

	lli prevScore=score();

	lli cnt = 0;
	bool check = false;

	while(1){
        if(check || cnt%10000==0){
	        std::chrono::system_clock::time_point now = std::chrono::system_clock::now();
    	    double elapsed = std::chrono::duration_cast<std::chrono::microseconds>(now-start).count();
    	    if(elapsed > 1700*1000){
    	    	check = true;
    	    }
        	if(elapsed > T)break;
        }

        lli contestD = contestDist(mt);
        lli dayD     = dayDist(mt);

        LOG2(contestD,dayD);

        lli prevContest = t[dayD];
        t[dayD] = contestD;

        lli nowScore = score();
        if(prevScore>nowScore){
        	t[dayD] = prevContest;
        }
        else{
        	prevScore = nowScore;
        }
        cnt++;
	}

	outputT();
	//dummyDayInput();
	//score();
	//dummyDayChangeInput();
 
	return 0;
}

Measured memory_bytes: 3692
//shan61916
#include <bits/stdc++.h>
  using namespace std;
typedef   long long ll;
typedef   unsigned long long ull ;
typedef   double dll ;

#define   mp make_pair
#define   pb push_back
#define   ff first 
#define   ss second
#define   IOS ios::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define   endl "\n" 
#define   pll pair<ll, ll>
#define   all(x) x.begin(), x.end()
#define   vll vector<ll> 

const ll inf = (ll)(1e17 + 17);
const ll mod = (ll)(1e9 + 7);


int main(){
 IOS
#ifdef SHAN
    freopen("input.txt" , "r" , stdin);  
#endif
  ll h, n;
  cin >> h >> n;
  ll s = 0;
  for(ll i = 0; i < n; i++) {
  	ll tp;
  	cin >> tp;
  	s+=tp;
  }
  s >= h ? cout << "Yes" : 	cout << "No";
  return 0;
} //good night.

Measured memory_bytes: 384