akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
using namespace std;
int main(){
  int n,k,x,sum=0;
  cin>>n>>k;
  for(int i=0;i<n;i++){
    cin>>x;
    if(k-x<x)
      sum+=2*(k-x);
    else
      sum+=2*x;
  }
  cout<<sum;
}

Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<cstring>
#include<algorithm>
#include<iomanip>
#include<vector>
#include<map>
using namespace std;

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

	if (s.length() > t.length())
	{
		cout << "GREATER";
	}
	else if (s.length() < t.length())
	{
		cout << "LESS";
	}
	else
	{
		if (s == t)
			cout << "EQUAL";
		else if (s > t)
			cout << "GREATER";
		else
			cout << "LESS";
	}
}

Measured memory_bytes: 256
using System;

class program
{
    public static int Main()
    {
        var In = Console.ReadLine();
        var a = int.Parse(In.Split(' ')[0]);
        var b = int.Parse(In.Split(' ')[1]);
        string sign = "==";

        if (a > b)
        {
            sign = ">";
        }
        else if (a < b)
        {
            sign = "<";
        }

        Console.WriteLine("a {0} b", sign);

        return 0;
    }
}

Measured memory_bytes: 5376
#pragma GCC optimize("O3")
#include <bits/stdc++.h>
#define ll long long
#define rep(i,n) for(ll i=0;i<(n);i++)
#define pll pair<ll,ll>
#define pq priority_queue
#define pb push_back
#define eb emplace_back
#define fi first
#define se second
#define ios ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0);
#define lb(c,x) distance(c.begin(),lower_bound(all(c),x))
#define ub(c,x) distance(c.begin(),upper_bound(all(c),x))

using namespace std;

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

const ll mod=1e9+7;


int main(){
    ll h,w;
    cin >> h >> w;
    vector<vector<char>> ans(h+2,vector<char>(w+2));
    rep(i,h+2){
        rep(j,w+2){
            if(i%(h+1)==0 || j%(w+1)==0){
                ans[i][j]='#';
            }
            else{
                cin >> ans[i][j];
            }
        }
    }
    rep(i,h+2){
        rep(j,w+2){
            cout << ans[i][j];
        }
        cout << endl;
    }
}

Measured memory_bytes: 3548
#include <iostream>
#define int long long
#define rep(i, n) for(i = 0; i < n; i++)
using namespace std;

int h, w, d, a, q, l, r;
int py[90000], px[90000];
int dist[90000];

signed main() {
	int i, j;
	
	cin >> h >> w >> d;
	rep(i, h) {
		rep(j, w) {
			cin >> a; a--;
			py[a] = i; px[a] = j;
		}
	}
	
	rep(i, h * w) {
		if (i >= d) {
			dist[i] = dist[i - d] + abs(py[i] - py[i - d]) + abs(px[i] - px[i - d]);
		}
	}
	
	cin >> q;
	rep(i, q) {
		cin >> l >> r;
		l--; r--;
		cout << dist[r] - dist[l] << endl;
	}
	return 0;
}

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

using E = System.Linq.Enumerable;

public class Program
{
    public static void Main()
    {
        var n = int.Parse(Console.ReadLine());
        var ps = Console.ReadLine().Split().Select(x => int.Parse(x)).ToArray();

        var k = 0;
        for (int i = 1; i + 1 < ps.Length; i++)
        {
            var qs = new [] { ps[i - 1], ps[i], ps[i + 1] };
            if (qs.Max() == ps[i] || qs.Min() == ps[i])
            {
                continue;
            }

            k++;
        }
        Console.WriteLine(k);
    }
}


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

// types
typedef long long ll;
typedef long double ld;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef pair<ld,ld> pdd;
typedef vector<ll> vll;

// macros
#define ALL(a) a.begin(),a.end()
#define SZ(a) ((int)a.size())
#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 FOR(i,a,b) for(int i=(a);i<(b);i++)
#define PB push_back
#define EB emplace_back
#define MP(a,b) make_pair(a,b)
#define SORT_UNIQUE(c) (sort(c.begin(),c.end()), c.resize(distance(c.begin(),unique(c.begin(),c.end()))))
#define GET_POS(c,x) (lower_bound(c.begin(),c.end(),x)-c.begin())
#define Decimal fixed<<setprecision(20)
#define INF 1000000000
#define LLINF 1000000000000000000LL

// constants
const int inf = 1e9;
const ll linf = 1LL << 50;
const double eps = 1e-10;
const int MOD = 1e9 + 7;
const int dx[4] = {-1, 0, 1, 0};
const int dy[4] = {0, -1, 0, 1};

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

  ll a, b, c;
  cin >> a >> b >> c;
  
  cout << max(0LL, c-(a-b)) << endl;
  
  
}


Measured memory_bytes: 256
import sys
import os
import math

ii = lambda: int(sys.stdin.buffer.readline().rstrip())
il = lambda: list(map(int, sys.stdin.buffer.readline().split()))
iln = lambda n: [int(sys.stdin.buffer.readline().rstrip()) for _ in range(n)]

iss = lambda: sys.stdin.buffer.readline().decode().rstrip()
isn = lambda n: [sys.stdin.buffer.readline().decode().rstrip() for _ in range(n)]


def main():
    if os.getenv("LOCAL"):
        sys.stdin = open("input.txt", "r")

    N, X, Y = il()
    ret = [0] * (N - 1)
    X -= 1
    Y -= 1
    for i in range(N - 1):
        for j in range(i + 1, N):
            k = min(abs(i - j), abs(X - i) + abs(Y - j) + 1, abs(Y - i) + abs(X - j) + 1)
            ret[k - 1] += 1

    print(*ret, sep="\n")


if __name__ == '__main__':
    main()


Measured memory_bytes: 3444
import java.util.Arrays;
import java.util.Scanner;
import java.util.stream.Collectors;

public class Main {
    public static void main(String[] args) {
        Scanner stdin = new Scanner(System.in);
        int h = stdin.nextInt();
        int w = stdin.nextInt();
        int n = stdin.nextInt();
        int[] a = new int[n];
        for (int i = 0; i < n; i++) {
            a[i] = stdin.nextInt();
        }
        
        int[] color = new int[h * w];
        int k = 0;
        for (int i = 0; i < n; i++) {
            for (int j = 0; j < a[i]; j++) {
                color[k + j] = i + 1;
            }
            k += a[i];
        }

        int[][] matrix = new int[h][w];
        int x = 0;
        int y = 0;
        int d = 1;
        for (int i = 0; i < h * w; i++) {
            matrix[x][y] = color[i];
            if (d == 1 && y == w - 1) {
                x += 1;
                d = -1;
            } else if (d == -1 && y == 0) {
                x += 1;
                d = 1;
            } else {
                y += d;
            }
        }
        
        for (int i = 0; i < h; i++) {
            String line = Arrays.stream(matrix[i]).mapToObj(Integer::toString).collect(Collectors.joining(" "));
            System.out.println(line);
        }
    }
}

Measured memory_bytes: 33836
package main

import (
	"fmt"
)

func main() {
	var (
		n, count int
	)
	fmt.Scan(&n)
	d := make([]int, n)
	m := make(map[int]bool)
	for i := range d {
		fmt.Scan(&d[i])
		if _, ok := m[d[i]]; !ok {
			m[d[i]] = true
			count++
		}
	}
	fmt.Println(count)
}


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

int main() {
    int n,ans=0;
    double v[10000];
    cin>>n;
    for(int i=0;i<n;i++){
        cin>>v[i];
    }
    sort(v,v+n);
    for(int i=0;i<n;i++){
        v[i+1]=(v[i]+v[i+1])/2;
    }
    cout<<fixed<<v[n-1]<<'\n';
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define ull unsigned long long
#define mst(a, b) memset((a), (b), sizeof(a))
#define mp(a, b) make_pair(a, b)
#define pi acos(-1)
#define pii pair<int, int>
#define pb push_back
const int INF = 0x3f3f3f3f;
const double eps = 1e-10;
const int maxn = 1e3 + 7;
const int maxm = 5e5 + 10;
const int mod = 1e9 + 7;
char s[maxn][maxn];
ll dp[maxn][maxn];
int main()
{
    ios::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    int n, m;
    cin >> n >> m;
    mst(dp, 0);
    for (int i = 1; i <= n; ++i)
    {
        for (int j = 1; j <= m; ++j)
        {
            cin >> s[i][j];
            if (s[i][j] == '.')
                dp[i][j] = 1;
        }
    }
    for (int i = 1; i <= n; ++i)
    {
        for (int j = 1; j <= m; ++j)
        {
            if (i == 1 && j == 1)
                continue;
            if (s[i][j] == '#')
                continue;
            dp[i][j] = (dp[i - 1][j] + dp[i][j - 1]) % mod;
        }
    }
    cout << dp[n][m] << endl;
    return 0;
}

Measured memory_bytes: 9216
#include <bits/stdc++.h>
#define DAU  ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define PLEC return 0;
using namespace std;
string s;
int main() {
    DAU
    cin >> s;
    for (size_t i = 0; i < s.size(); ++i)
        cout << 'x';
    PLEC
}


Measured memory_bytes: 256
import math
from functools import reduce
from collections import deque

def s(generator, splitter, mapper):
    return [ mapper(s) for s in generator().split(splitter) ]

# スペース区切りの入力を読み込んで数値リストにして返します。
def get_nums_l():
    return [ int(s) for s in input().split(" ")]

# 改行区切りの入力をn行読み込んで数値リストにして返します。
def get_nums_n(n):
    return [ int(input()) for _ in range(n)]

n = int(input())

print((n-2) * 180)

Measured memory_bytes: 38256
n=int(input())
p=list(map(int,input().split()))
count=0
for i in range(1,n-1):
    if (p[i-1]<p[i] and p[i]<p[i+1]) or (p[i-1]>p[i] and p[i]>p[i+1]):
        count+=1
    else:
        continue
print(count)

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

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

using namespace std;

int main(){
	
	int n;
	cin >> n;
	vector<int> a(n,0);
	vector<int> color(8,0);
	int super_red=0;
	for(int i=0;i<n;i++){
		cin >> a[i];
		if(1<=a[i] && a[i]<=399)color[0]++;
		if(400<=a[i] && a[i]<=799)color[1]++;
		if(800<=a[i] && a[i]<=1199)color[2]++;
		if(1200<=a[i] && a[i]<=1599)color[3]++;
		if(1600<=a[i] && a[i]<=1999)color[4]++;
		if(2000<=a[i] && a[i]<=2399)color[5]++;
		if(2400<=a[i] && a[i]<=2799)color[6]++;
		if(2800<=a[i] && a[i]<=3199)color[7]++;
		if(3200<=a[i])super_red++;
	}
	
	int cnt=0;
	for(int i=0;i<=7;i++){
		if(1<=color[i])cnt++;
	}
	
	long long min_cnt,max_cnt;
	min_cnt=max_cnt=0;
	if(cnt>0){
		min_cnt=cnt;
		max_cnt=cnt+super_red;
	}else if(cnt==0 && super_red>=1){
		min_cnt=1;
		max_cnt=super_red;
	}
	cout << min_cnt << " " << max_cnt << endl;
	
	return 0;
}

Measured memory_bytes: 256
#include <list>
#include <cstdio>

int main()
{
	int n, v;

	char c[12];

	std::list<int> l;

	scanf("%d", &n);

	for (int i = 0; i < n; i++)
	{
		scanf("%s", c);

		if (c[0] == 'i')
		{
			scanf("%d", &v);

			l.push_front(v);
		}
		else if (c[6] == 'F')
		{
			l.pop_front();
		}
		else if (c[6] == 'L')
		{
			l.pop_back();
		}
		else
		{
			scanf("%d", &v);

			std::list<int>::iterator it = l.begin();

			std::list<int>::iterator end_it = l.end();

			while (it != end_it)
			{
				if (*it == v)
				{
					l.erase(it); break;
				}

				it++;
			}
		}
	}

	std::list<int>::iterator it = l.begin();

	std::list<int>::iterator end_it = l.end();

	printf("%d", *it);

	while (++it != end_it)
	{
		printf(" %d", *it);
	}

	printf("\n");

	return 0;
}

Measured memory_bytes: 33988
n = int(input())
a = []
for i in range(n):
  a.append(int(input()))
a.sort()
jud = 1
q = a[0]
ans = 0
for i in range(1,n):
  if(q==a[i]):
    jud += 1
  else: 
    if(jud%2==1):
      ans += 1
    jud = 1
    q = a[i]
if (jud%2==1):
  ans += 1
if(n==1):
  ans = 1
print(ans)


Measured memory_bytes: 13112
#include <algorithm>
#include <cstdio>
#include <iostream>
#include <map>
#include <cmath>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>
#include <stdlib.h>
#include <stdio.h>
using namespace std;

#define ll         long long
#define PI         acos(-1.0)
#define FOR(I,A,B) for(int I = (A); I < (B); ++I)

int main(){
    //0->aさん,1->bさん,2->cさん
    vector<string> vs(3);
    cin>>vs[0]>>vs[1]>>vs[2];
    //FOR(i, 0, 3) vs[i] += 'X';
    int n[3];
    FOR(i, 0, 3) n[i] = 0;
    n[0] = 1;
    int mozi = vs[0][0] - 'a';
    while(1){
        n[mozi]++;
        if(vs[mozi].length()+1==n[mozi]){
            cout << char('A' + mozi) << endl;
            return 0;
        }
        mozi = vs[mozi][n[mozi]-1] - 'a';
    }
}

Measured memory_bytes: 256
#ifdef _WIN32
#include "stdc++.h"
#else
#include <bits/stdc++.h>
#endif

// 継承可能な型
template <class Type>
struct IN : Type
{
	IN()
	{
		std::cin >> *this;
	}
};

// 継承不可能な型
template <class Type>
struct IN_
{
	Type val;

	IN_()
	{
		std::cin >> val;
	}

	operator Type&()
	{
		return val;
	}

	IN_<Type>& operator=(const Type& _value)
	{
		val = _value;
		return *this;
	}
};

template <class Char, class Type>
std::basic_ostream<Char>& operator <<(std::basic_ostream<Char>& os, const IN_<Type>& value)
{
	return os << value.val;
}

template <class Char, class Type>
std::basic_istream<Char>& operator >>(std::basic_istream<Char>& is, IN_<Type>& value)
{
	return is >> value.val;
}

template <class Type>
void OUT(const Type& value)
{
	std::cout << value << std::endl;
}

template <class Type, class ... Args>
void OUT(const Type& value, const Args& ... args)
{
	std::cout << value << ' ';
	OUT(args...);
}

void Yes()
{
	OUT("Yes");
}
void No()
{
	OUT("No");
}

using ll = long long;
using inll = IN_<ll>;
using vll = std::vector<ll>;
using setll = std::set<ll>;
using msetll = std::multiset<ll>;
using instr = IN<std::string>;

// 階乗を計算 O(N) (N=10^7 で O(10^7))
int Factorial(ll n)
{
	for (ll i = n - 1; i > 1; i--)
		n *= i;
	return n;
}

// nCrを計算 O(N) (N=10^7 で O(10^7))
ll Combination(const ll n, const ll r)
{
	return Factorial(n) / (Factorial(r) * Factorial(n - r));
}

// 素数判定 O(sqrt(N)) (N=10^7 で O(10^3))
bool IsPrime(const ll num)
{
    if (num < 2) return false;
    if (num == 2) return true;
    if (num % 2 == 0) return false;

    double sqrtNum = sqrt(num);
    for (int i = 3; i <= sqrtNum; i += 2)
    {
        if (num % i == 0)
        {
            return false;
        }
    }

    return true;
}

// 各桁の和を計算 O(logN) (N=10^7 で O(7))
ll DigitSum(ll n)
{
	ll sum = 0;
	while(n != 0){
		sum += n % 10;
		n /= 10;
	}
	return sum;
}

#define FOR(i, m, n) for (ll (i) = (m); (i) < (n); ++(i))
#define REP(i, n) for (ll (i) = 0; (i) < (n); ++(i))
#define REPR(i, n) for (ll (i) = (n); (i) >= 0; --(i))
#define ITRREP(it, v) for (auto (it) = (v).begin(); (it) != (v).end(); ++(it))
#define ITRREPR(it, v) for (auto (it) = (v).rbegin(); (it) != (v).rend(); ++(it))
#define DIVUP(a, b) (((a) + (b) - 1) / (b))

void Main();

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

	Main();

#ifdef _DEBUG
	system("pause");
#endif

	return 0;
}

using namespace std;

//////////////////////////////

void Main()
{
	inll n, k;

	return OUT(
		((n - 1) / (k - 1)) +
		(((n - 1) % (k - 1) == 0) ? 0 : 1)
	);
}


Measured memory_bytes: 256
using System;
using System.Text;

namespace AOJ
{
    class Program
    {
        static void Main(string[] args)
        {
            var input = Console.ReadLine().Split();
            var n = int.Parse(input[0]);
            var list = new List<string>();

            for(var i = 0; i < n; i++){
                input = Console.ReadLine().Split();
                if(input[0] == "insert"){
                    list.insert(input[1]);
                }else if(input[0] == "delete"){
                    list.delete(input[1]);
                }else if(input[0] == "deleteFirst"){
                    list.deleteFirst();
                }else if(input[0] == "deleteLast"){
                    list.deleteLast();
                }
            }
            Console.WriteLine(list.ToString());
        }
    }


    class List<T>
    {
        private Cell<T> _head;
        private Cell<T> _tail;

        public List(){
            _head = new Cell<T>();
            _tail = new Cell<T>();
            _head._next = _tail;
            _tail._pred = _head;
        }

        public void insert(T data){
            var c = new Cell<T>(data, _head, _head._next);
            _head._next._pred = c;
            _head._next = c;
        }

        public void delete(T data){
            var c = search(data);
            if(c != _tail){
                del(c);
            }
        }

        public void deleteFirst(){
            var first = _head._next;
            del(first);
        }

        public void deleteLast(){
            var last = _tail._pred;
            del(last);
        }

        public override string ToString(){
            var current = _head._next;
            var result = "";
            if(current != _tail){
                var builder = new StringBuilder(current._data.ToString());
                current = current._next;
                while(current != _tail){
                    builder.Append($" {current._data}");
                    current = current._next;
                }

                result = builder.ToString();
            }

            return result;
        }

        private Cell<T> search(T data){
            var current = _head._next;
            while((current != _tail) && (!current._data.Equals(data))){
                current = current._next;
            }
            return current;
        }

        private void del(Cell<T> c){
            var pred = c._pred;
            var next = c._next;

            pred._next = next;
            next._pred = pred;
        }

        class Cell<Tdata>
        {
            public Cell<Tdata> _next;
            public Cell<Tdata> _pred;
            public Tdata _data;

            public Cell() { }
            public Cell(Tdata data, Cell<Tdata> pred, Cell<Tdata> next)
            {
                _data = data;
                _pred = pred;
                _next = next;
            }

        }
    }
}



Measured memory_bytes: 114848
A = []

for i in range(int(input())):
    a = [int(j) for j in input().split()]
    if a[0] == 0:
        x = a[1]
        A.append(x)
    elif a[0] == 1:
        p = a[1]
        print(A[p])
    else:
        A.pop()
    


Measured memory_bytes: 13360
#include <stdio.h>
#include <stdlib.h>

typedef struct {
	int id, solved, penalty;
} Team;

int compare(const void *a, const void *b) {
	int t;
	const Team ta = *(Team *)a, tb = *(Team *)b;

	t = tb.solved - ta.solved;
	if (t)
		return t;
	else {
		t = ta.penalty - tb.penalty;
		if (t)
			return t;
		else
			return ta.id - tb.id;
	}
}

int main(void) {
	int i;
	int t, p, r;

	while (scanf("%d %d %d", &t, &p, &r), t) {
		Team team[50] = {0};
		int wrong[50][10] = {0};

		for (i = 0; i < t; i++)
			team[i].id = i + 1;

		for (i = 0; i < r; i++) {
			int tid, pid, t;
			char mes[10];

			scanf("%d %d %d %s", &tid, &pid, &t, mes);
			tid--;
			pid--;

			if (mes[0] == 'C') {
				team[tid].solved++;
				team[tid].penalty += wrong[tid][pid] * 1200 + t;
			} else
				wrong[tid][pid]++;
		}

		qsort(team, t, sizeof(Team), &compare);

		for (i = 0; i < t; i++)
			printf("%d %d %d\n", team[i].id, team[i].solved, team[i].penalty);
	}

	return 0;
}

Measured memory_bytes: 616
#!/usr/bin/env python3
import sys
sys.setrecursionlimit(300000)


def solve(N: int, T: int, t: "List[int]"):
    ret = T * N
    tmp = 0
    for v in t:
        ret -= max(0, tmp - v)
        tmp = v + T
    print(ret)
    return


def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    T = int(next(tokens))  # type: int
    t = [ int(next(tokens)) for _ in range(N) ]  # type: "List[int]"
    solve(N, T, t)

if __name__ == '__main__':
    main()


Measured memory_bytes: 27200
#include <iostream>
#include <vector>
#include <utility>
using namespace std;

int solve(vector< vector<int> > &T, int v, int from){
  int ret = 0, k = 0;
  for(int i = 0; i < T[v].size(); ++i){
    if(T[v][i] != from){
      int t = solve(T,T[v][i],v);
      if(t == 0) ++k;
      ret += t;
    }
  }
  ret += max(0,k-1);
  return ret;
}

int main(){
  int N;
  cin >> N;
  if(N <= 2){
    cout << 1 << endl;
    return 0;
  }
  vector< vector<int> > T(N);
  int x, y;
  for(int i = 0; i < N-1; ++i){
    cin >> x >> y;
    T[x].push_back(y);
    T[y].push_back(x);
  }
  int m = 0, v = -1;
  for(int i = 0; i < N; ++i){
    if(T[i].size() > m){
      m = T[i].size();
      v = i;
    }
  }
  int ans = solve(T,v,v);

  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 13440
#include <cstdio>
#include <vector>
#include <algorithm>
#include <cstring>
#include <string>
#include <cctype>
#include <sstream>
#include <cmath>
#include <climits>
#include <set>
#include <iostream>
#include <map>
#include <functional>
#include <cstdlib>
#include <numeric>
#include <queue>
#include <complex>
#include <sstream>
#include <stack>

using namespace std;

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

typedef vector<int> vi;
typedef pair<int, int> pii;
typedef complex<double> Point;

int main()
{
	int n;
	while(scanf("%d", &n), n){
		vi dp(n, 0);
		int ans = 0;
		rep(i, n){
			char field[1024];
			scanf("%s", field);
			int rt = 0;
			rep(j, n){
				int next;
				if(field[j] == '*')
					next = 0;
				else
					next = min(rt, min(dp[j], j ? dp[j-1] : 0)) + 1;
				rt = dp[j];
				dp[j] = next;
				ans = max(ans, dp[j]);
			}
		}
		printf("%d\n", ans);
	}

	return 0;
}

Measured memory_bytes: 0
#include <bits/stdc++.h>
 
using namespace std;
 
#define ALL(x) x.begin(), x.end()
 
typedef long long int lld;
typedef pair<int, int> pii;
 
int main(){
	ios::sync_with_stdio(false);
	cin.tie(nullptr);
	cout.precision(15);
	cout << fixed;
 
	lld a, b;
	cin >> a >> b;

	if ((a + b) % 2)
		cout << "IMPOSSIBLE" << '\n';
	else
		cout << ((a + b) >> 1) << '\n';

	
	return 0;
}

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

int main(){
	// sengen
	int n,k,sum = 0;
	// nyuryoku
	cin >> n >> k;
	int p[n];
	for(int i=0;i<n;i++){
		cin >> p[i];
	}
	sort(p,p+n);
	// keisan
	for(int i=0;i<k;i++){
		sum += p[i];
	}
	// syutsuryoku
	cout << sum;
}

Measured memory_bytes: 3640
#include <iostream>
#include <iomanip>
#include<math.h>
#include<list>
#include <algorithm>
#include<set>
#include<vector>
#include<math.h>
#include<map>
#include<string>
#include <numeric>
#include <queue>
#include <sstream>
#include <bitset>
#include<stack>

using namespace std;
using ll = long long;
using vll = vector<long long>;
using sll = set<long long>;

template<typename T>
T gcd(T a, T b) { return b ? gcd(b, a % b) : a; }
template<typename T>
T lcm(T a, T b) { return a / gcd(a, b) * b; }

template<typename T>
map<T, T> getPrimeFactor(T n) {
	map<T, T> res;
	for (T i = 2; i * i <= n; ++i) {
		while (n % i == 0) {
			res[i] ++;
			n /= i;
		}
	}
	if (n != 1) res[n] = 1;
	return res;
}

template<typename T>
bool IsPrimeNumber(T num)
{
	if (num <= 2) return true;
	else if (num % 2 == 0) return false;

	double sqrtNum = sqrt(num);
	for (int i = 3; i <= sqrtNum; i += 2)
	{
		if (num % i == 0)
		{
			return false;
		}
	}

	return true;
}

long long modinv(long long a, long long m) {
	long long b = m, u = 1, v = 0;
	while (b) {
		long long t = a / b;
		a -= t * b; swap(a, b);
		u -= t * v; swap(u, v);
	}
	u %= m;
	if (u < 0) u += m;
	return u;
}


#define in(x) cin >> x
#define out(x) cout << x
#define outn(x) cout << x << '\n'
#define outs(x) cout << x << ' '
#define rep(i,s,e) for(ll i=s;i<e;i++)
#define repeq(i,s,e) for(ll i=s;i<=e;i++)


int main() {
	
	double ans = 0.0;
	ll n, k;
	std::cin >> n >> k;
	vector<double> p(n+1),q(n+1,0);
	repeq(i, 1, n) {
		std::cin >> p[i];
		if (p[i] != 1) {
			p[i] = p[i] / 2 + 0.5;
		}
		q[i] = q[i - 1] + p[i];
		if (i >= k) {
			ans = max(ans, q[i] - q[i - k]);
		}
	}
	std::cout << std::fixed << std::setprecision(15) << ans  << endl;

	return 0;
}

Measured memory_bytes: 3328
#include <iostream>
#include <iomanip>
#include <vector>
#include <algorithm>
#include <numeric>
#include <functional>
#include <cmath>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <sstream>
#include <string>
#define _repargs(_1,_2,_3,name,...) name
#define _rep(i,n) repi(i,0,n)
#define repi(i,a,b) for(int i=(int)(a);i<(int)(b);++i)
#define rep(...) _repargs(__VA_ARGS__,repi,_rep,)(__VA_ARGS__)
#define all(x) (x).begin(),(x).end()
#define mod 1000000007
#define inf 2000000007
#define mp make_pair
#define pb push_back
typedef long long ll;
using namespace std;
template <typename T>
inline void output(T a, int p = 0) {
    if(p) cout << fixed << setprecision(p)  << a << "\n";
    else cout << a << "\n";
}
// end of template

int main() {
    cin.tie(0);
    ios::sync_with_stdio(0);
    // source code
    string s;
    cin >> s;
    int ret = inf;
    rep(i, 26){
        int ma = 0, cur = 0;
        rep(j, s.size()){
            if(s[j] == 'a' + i){
                ma = max(ma, cur);
                cur = 0;
            }
            else{
                cur++;
            }
        }
        ma = max(ma,  cur);
        ret = min(ret, ma);
    }
    output(ret);
    
    return 0;
}

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

#define MAX 500

int stack[MAX];
int top = 0;

void push(int);
int pop(void);
int cul(char *);
int num(char *);

int main(){
  char a,s[MAX];
  int i;
  
  scanf("%[^\n]*s",s);
  
  printf("%d\n",cul(s));
  
  return 0;
} 
  
int cul(char *s){
  int a,b,i;
  
  while(*s){

    if(*s >= '0' && *s <= '9'){
      a = num(s);
      push(a);
      
      while(*s == '-' || *s == '+'){
        s++;
      }
      while(a != 0){
	a /= 10;
	s++;
      }
    
    }else{
      
     if(*s == '+'){
      b = pop();
      a = pop();
      push(a+b);
     }
     else if(*s == '-'){
      b = pop();
      a = pop();
      push(a-b);
     }
     else if(*s == '*'){
      b = pop();
      a = pop();
      push(a*b);
     }
     s++;
   }
  }
  return pop(); 
}

void push(int a){
  stack[top++] = a;
 }

int pop(){
  
  return stack[--top];
}

int num(char *s){
   int a = 0;
   
   if(*s == '+' || *s == '-'){
     s++;
   }

   while(*s >= '0' && *s <= '9'){
      a = (a * 10) + (*s - '0');
      s++;
   }
   return a;
}




Measured memory_bytes: 2104
#include<iostream>
#include<iomanip>
#include<functional>
#include<algorithm>
#include<string>
#include<vector>
#include<utility>
#include<tuple>
#include<map>
#include<set>
#include<queue>
#include<cmath>

using namespace std;
#define LL long long

int N,M,p[111111],ans=0;

struct UnionFind{
	int size;
	vector<int>ne;
	void init(int n){
		size=n;
		for(int i=0;i<=size;i++)ne.push_back(i);
		return;
	}
	
	int root(int x){
		if(ne[x]==x)return x;
		return ne[x]=root(ne[x]);
	}

	bool same(int x,int y){return root(x)==root(y);}

	void unite(int x,int y){
		if(same(x,y))return;
		int X=root(x),Y=root(y);
		ne[X]=Y;
		return;
	}

};
UnionFind u;

int main() {
	cin>>N>>M;
	u.init(N);
	for(int i=0;i<N;i++)cin>>p[i];
	for(int i=0;i<M;i++){
		int x,y;
		cin>>x>>y;
		u.unite(x,y);
	}
	for(int i=0;i<N;i++){
		if(u.root(p[i])==u.root(i+1))ans++;
	}
	cout<<ans<<endl;
	return 0;
}



Measured memory_bytes: 1144
#include<stdio.h>
#define MAX 2000000

int H,A[MAX+1];

void maxHeapify(int i){
  int l,r,largest,a;
  l=2*i;
  r=2*i+1;

  if( l<=H && A[l] > A[i] )largest = l;
  else largest = i;
  if( r<=H && A[r] > A[largest] )largest = r;

  if( largest != i ){
    a = A[i];
    A[i] = A[largest];
    A[largest] = a;
    maxHeapify(largest);
  }
}

int main(){
  int i;
  scanf("%d",&H);

  for(i=1;i<=H;i++)
    scanf("%d",&A[i]);

  for(i=H/2;i>=1;i--)
    maxHeapify(i);

  for(i=1;i<=H;i++)
    printf(" %d",A[i]);
  printf("\n");
  return 0;
}



Measured memory_bytes: 3648
#include "bits/stdc++.h"
#include "ext/pb_ds/assoc_container.hpp"
using namespace __gnu_pbds;
using namespace std;

#define pb                push_back
#define all(x)            (x).begin(),(x).end()
#define int               long long
#define INF               1e18
#define ff                first
#define ss                second
#define vi                vector<int>
#define pii               pair<int,int>
#define mii               map<int,int>
#define endl              "\n"
#define GCD(x,y)          (__gcd((x), (y)))
#define LCM(x,y)          (((x)/__gcd((x), (y)))*(y))
#define debug(x)          cout<<#x<<" is "<<(x)<<endl
#define mem(a,x)          memset(a,x,sizeof(a))
#define rep(i,a,b)        for(long long i=a;i<b;i++)
#define sp(ans,p)         fixed <<setprecision(p)<<ans;
#define IOS ios::sync_with_stdio(0);cin.tie(0); cout.tie(0);

typedef tree<pii, null_type, less<pii>, rb_tree_tag, tree_order_statistics_node_update> ordered_set;

// constexpr int N=;
// int ans=0;
int n;
int arr[105];
int ans = 0;
bool checkValidity(int a, int b, int c)
{
    // check condition
    if (a + b <= c || a + c <= b || b + c <= a)
        return false;
    else
        return true;
}
void recur(int ind, vector<int>  temp)
{
    if (temp.size() == 3)
    {
        set<int> check;
        for (auto itr : temp) check.insert(itr);
        // for (auto itr : temp) cout << itr << " ";
        if (check.size() == 3  and checkValidity(temp[0], temp[1], temp[2]))
        {
            // cout << temp[0] << " " << temp[1] << " " << temp[2] << endl;
            ans++;
        }
        return;
    }
    if (temp.size() > 3)
    {
        return;
    }
    rep(i, ind, n)
    {
        temp.pb(arr[i]);
        recur(i + 1, temp);
        temp.pop_back();
    }
}
void solve()
{
    ans = 0;
    cin >> n;
    rep(i, 0, n)
    {
        cin >> arr[i];
    }
    sort(arr, arr + n);
    vi temp;
    int k = 3;
    recur( 0, temp);
    cout << ans << endl;
    // cout << n;

    return;
}
signed main()
{
    IOS;
#ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
#endif
    // sieve();
    int t = 1;
    // cin >> t;
    while (t--)   solve();
    return 0;
}

Measured memory_bytes: 3632
#include <string>
#include <math.h>
#include <iostream>
 
using namespace std;
 
int main()
{
  int a, b;
  cin >> a >> b;
  int x = a + b;
  int y = a - b;
  int z = a * b;
  int max = x;
  if (max < y)
    max = y;
  if (max < z)
    max = z;
  cout << max;
}

Measured memory_bytes: 3612
read = input 
rn = lambda :list(map(int, read().split()))
n, m  = rn()
M = []
P = 1000000007
for i in range(m):
    M.append(int(read()))
M = set(M)
dp = [0 for i in range(n + 10)]
dp[0] = 1
for i in range(n+1):
    for nxt in range(i+1, i+3):
        if(nxt not in M):
            dp[nxt] += dp[i]
            dp[nxt] %= P
print(dp[n])

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

int n;
vector<double> prob;
double mem[3005][3005];

double dp(){
	mem[1][0]=1-prob[0];
	mem[1][1]=prob[0];
	for(int i=2;i<=n;i++)
	{
		for(int j=0;j<i;j++)
		{
			mem[i][j+1]=mem[i][j+1]+(mem[i-1][j]*prob[i-1]);
			mem[i][j]=mem[i][j]+(mem[i-1][j]*(1-prob[i-1]));
		}
	}
	double ans=0;
	for(int j=n;j>n/2;j--)
	{
		ans=ans+mem[n][j];
	}
	return ans;
}

int main(){
	cin>>n;
	memset(mem,0,sizeof(mem));
	for(int i=0;i<n;i++)
	{
		double x;
		cin>>x;
		prob.push_back(x);
	}
	cout<<fixed<<setprecision(10)<<dp()<<endl;
	return 0;
}

Measured memory_bytes: 74356
#include <iostream>
#include <set>
#include <vector>
using namespace std;

int main(){
    char S[101010];

    cin >> S;

    bool app[26];
    for (int i = 0; i < 26; i++){
        app[i] = false;
    }
    for (int i = 0; S[i] != '\0'; i++){
        app[S[i] - 'a'] = true;
    }
    for (int i = 0; i < 26; i++){
        if(!app[i]){
            printf("%c\n", (char)(i + 'a'));
            return 0;
        }
    }
    puts("None");
    return 0;
}

Measured memory_bytes: 384
#include <iostream>
#include <iomanip>
#include <vector>
#include <algorithm>
#include <numeric>
#include <functional>
#include <cmath>
#include <string>

using namespace std;

int dfs(int tar, long long n, int a, int b, int c) {

    int ret = 0;

    if (n>tar) return 0;

    if ( a && b && c && n <= tar ) ret += 1;

    ret += dfs(tar, n*10 + 3, a + 1, b, c);
    ret += dfs(tar, n*10 + 5, a, b + 1, c);
    ret += dfs(tar, n*10 + 7, a, b, c + 1);

    return ret;
}

int main(int argc, const char * argv[]) {
    
    int n;
    cin >> n;
    if (n<357) {
        cout << 0 << endl;
    }
    else {
        cout << dfs(n, 0, 0, 0, 0) << endl;
    }

    return 0;
}

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

#define vec(v) vector<int>(v)
#define be(v) (v).begin(), (v).end()
#define pb(q) push_back(q)
#define mapci(mp) map<char*,int>(mp)
#define mapcc(mp) map<char*,char*>(mp)
typedef long long ll;
using namespace std;

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n,a,b;
    cin>>n>>a>>b;
    n=b-a;
    if(n%2==0){
        cout <<"Alice"<<endl;
    }
    else{
        cout << "Borys"<<endl;
    }
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define fi first
#define se second
#define pb(x) push_back(x)
#define mp make_pair
#define sz(x) ((int)(x).size())
#define endl "\n"
#define fastio ios_base::sync_with_stdio(false); cin.tie(nullptr);
#define all(x) x.begin(),x.end()
#define y1 omg
#define INF 1000000010
#define FOR(x, n) for(int x=0; x<n; x++)
#define ini(x, n) memset(x, n, sizeof(x));
#define MOD (int)1e9 + 7
#define atoi(x) ((x)-'0')
using namespace std;
typedef long long ll;
typedef pair<int, int> ii;
typedef pair<int, ii> iii;
typedef vector<int> vi;
typedef vector<ii> vii;
typedef vector<vi> vvi;

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

ll a, b, c;

int main() {
	scanf("%lld %lld.%lld", &a, &b, &c);
	ll d = a * (b * 100 +  c) / 100;
	cout << d;
}

Measured memory_bytes: 3764
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define REP(i,m,n) for(int i=(int)(m); i<(int)(n); i++)
#define rep(i,n) REP(i,0,n)
#define RREP(i,m,n) for(int i=(int)(m); i>=(int)(n); i--)
#define rrep(i,n) RREP(i,n-1,0)
#define REPL(i,m,n) for(ll i=(ll)(m); i<(ll)(n); i++)
#define repl(i,n) REPL(i,0,n)
#define all(v) v.begin(), v.end()
const int inf = 1e9+7;
const ll longinf = 1LL<<60;
const ll mod = 1e9+7;
int main() {
  string S;
  cin >> S;
  vector<int> alph(26);
  vector<int> ans(26);
  for(char c: S) {
    int id = int(c-'a');
    rep(i, 26) {
      if(i == id) {
	ans[i] = max(alph[i], ans[i]);
	alph[i] = 0;
      } else {
	alph[i]++;
      }
    }
  }
  rep(i, 26) ans[i] = max(alph[i], ans[i]);
  cout << *min_element(all(ans)) << endl;
  return 0;
}


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

int r, n;
int ph[30], mh[30];

int main(){	
	while(scanf("%d%d",&r,&n),r||n){
		memset(ph,0,sizeof(ph));
		memset(mh,0,sizeof(mh));
		rep(i,n){
			int a, b, x;
			scanf("%d%d%d",&a,&b,&x);
			if(a < 0 && b > 0){
				for(int j = 0; j < b; j++) ph[j] = max(ph[j],x);
				for(int j = 0; j > a; j--) mh[-j] = max(mh[-j],x);
			} else if(a >= 0){
				for(int j = a; j < b; j++) ph[j] = max(ph[j],x);
			} else{
				for(int j = b; j > a; j--) mh[-j] = max(mh[-j],x);
			}
		}
		double s = 0.0, e = 100.0, mid;
		for(int i = 0; i < 100; i++){
			mid = (s+e)/2.0;
			if(mid > (double)min(ph[0],mh[0])){
				e = mid;
				continue;
			}
			bool ok = true;
			for(int j = -1*r+1; j <= r-1; j++){
				if(j <= 0){
					if((double)mh[-j] < mid-(double)r){
						ok = false;
						break;
					}
					if((double)j*(double)j+((double)mh[-j]+(double)r-mid)*((double)mh[-j]+(double)r-mid) < (double)r*(double)r){
						ok = false;
						break;
					}
				}
				if(j >= 0){
					if((double)ph[j] < mid-(double)r){
						ok  = false;
						break;
					}
					if((double)j*(double)j+((double)ph[j]+(double)r-mid)*((double)ph[j]+(double)r-mid) < (double)r*(double)r){
						ok = false;
						break;
					}
				}
			}
			if(ok) s = mid;
			else e = mid;
		}
		printf("%.9f\n",s);
	}
}

Measured memory_bytes: 1224
#include <bits/stdc++.h>
using namespace std;
#define mp       make_pair
#define pb       push_back
#define all(x)   (x).begin(),(x).end()
#define YES() printf("YES\n")
#define NO() printf("NO\n")
#define Yes() printf("Yes\n")
#define No() printf("No\n")
#define in(x,y,h,w) x >= 0 && x < h && y >= 0 && y < w

#define int long long
//typedef    long long          ll;
typedef    vector<bool>       vb;
typedef    vector<int>        vi;
typedef    vector<vb>         vvb;
typedef    vector<vi>         vvi;
typedef    pair<int,int>      P;

template <typename T> T &chmin(T &a, const T &b) { return a = min(a, b); }
template <typename T> T &chmax(T &a, const T &b) { return a = max(a, b); }
 
const int INF=1e+18;
const double EPS=1e-9;
const int MOD=1000000007;

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

class BIT{
	vector<int> bit;
public:
	BIT(int siz){
		bit.resize(siz + 1,0);
	}
	void add(int i,int x){
		while(i < bit.size()){
			bit[i] += x;
			i += i & -i;
		}
	}
	int sum(int i){
		int s = 0;
		while(i){
			s += bit[i];
			i -= i & -i;
		}
		return s;
	}
};

signed main(){
	int n,m,ans = 0;
	cin >> n >> m;
	BIT bit(n + 10);
	vector<P> vec;
	for(int i = 0;i < m;i++){
		int a,b;
		cin >> a >> b;
		vec.pb(P(b,a));
	}
	sort(all(vec));
	for(P p : vec){
		if(bit.sum(p.first - 1) - bit.sum(p.second - 1) == 0){
			ans++;
			bit.add(p.first - 1,1);
		}
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 3188
N,M=map(int,input().split())
k=[]
s=[]
for i in range(M):
    ks=list(map(int,input().split()))
    k.append(ks[0])
    s.append(list(map(lambda x:x-1,ks[1:])))
p=list(map(int,input().split()))

ans=0
for i in range(2**N):
    isOK=True

    for j in range(M):
        sum=0
        for x in s[j]:
            sum+=(i>>x)&1
        
        if sum%2!=p[j]:
            isOK=False
    
    if isOK:
        ans+=1

print(ans)

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

typedef long long ll;
typedef unsigned long long ull;
typedef unsigned __int128 HASH;
typedef pair<int,int> pii;
typedef pair<ll, ll> pll;
typedef pair<ull, ull> pullull;
typedef pair<ll,int> plli;
typedef pair<double, int> pdbi;
typedef pair<int,pii> pipii;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<vi> vvi;
typedef vector<vvi> vvvi;
typedef vector<pii> vpii;
typedef vector<vector<int>> mat;

#define rep(i,n) for (int i=0;i<(n);i++)
#define rep2(i,a,b) for (int i=(a);i<(b);i++)
#define rrep(i,n) for (int i=(n);i>0;i--)
#define rrep2(i,a,b) for (int i=(a);i>b;i--)
#define pb push_back
#define fi first
#define se second
#define all(a) (a).begin(),(a).end()
#define rall(a) (a).rbegin(),(a).rend()

const ll hmod1 = 999999937;
const ll hmod2 = 1000000000 + 9;
const ll INF = 1<<30;
const ll mod = 1000000000 + 7;
const int dx4[4] = {1, 0, -1, 0};
const int dy4[4] = {0, 1, 0, -1};
const int dx8[8] = {1, 1, 1, 0, 0, -1, -1, -1};
const int dy8[8] = {0, 1, -1, 1, -1, 0, 1, -1};
const double pi = 3.141592653589793;

//#define int long long
#define addm(X, Y) (X) = ((X) + ((Y) % mod) + mod) % mod

int a, b, c;

signed main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    cin >> a >> b >> c;
    rep(i, 100) {
        if (0 < (c + 60 * i) % (a + b) && (c + 60 * i) % (a + b) <= a) {
            cout << c + 60 * i << endl;
            return 0;
        }
    }
    cout << -1 << endl;
}

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

#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;

#define ll long long
#define db double
#define el "\n"
#define ld long double
#define rep(i,n) for(int i=0;i<n;i++)
#define rev(i,n) for(int i=n;i>=0;i--)
#define rep_a(i,a,n) for(int i=a;i<n;i++)
#define tr(ds, it) for(auto it=ds.begin(); it!=ds.end(); it++)
#define rtr(ds, it) for(auto it=ds.rbegin(); it!=ds.rend(); it--)
#define all(ds) ds.begin(), ds.end()
#define ff first
#define ss second
#define pb push_back
#define mp make_pair
typedef priority_queue <int> pq;
typedef vector< long long > vi;
typedef pair<long long, long long> ii;
#define o_set tree<ii, null_type,less<ii>, rb_tree_tag,tree_order_statistics_node_update>
#define graph vector<vi>
#define Mod 1000000007
#define fastio ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define T int t;cin>>t;rep(i,t)

void solve() {
	
	int n;
	cin >> n;
	ll k;
	cin >> k;
	int arr[n];
	int index = 1;
	rep(i, n) {
		cin >> arr[i];
	}
		
		
	unordered_map<int, int> s;
	s[1] = 1;
	int x = 2;
	ll count = 0;
	while(1) {
		index = arr[index - 1];
		if(s.find(index) != s.end()) {
			count = x - s[index];
			break;
		}
		s[index] = x++;	
	}
	if (k > s[index] - 1) {
		
		k -= (s[index] - 1);
		k %= count;
	
	while(k--){
		
		index = arr[index - 1];
	}
	
	cout << index;
		
	}
		
	else {
		index = 1;
		while(k--){
		
		index = arr[index - 1];
	}
	
	cout << index;
	}
	
	
	
}

int main()
{
    fastio;
//    T
    solve();
	//code
	return 0;
}


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

using namespace std;
using ll = long long;
using P = pair<int,int>;
#define all(c) (c).begin(),(c).end()
const int INF = 1e9;
const ll LINF = LLONG_MAX;
const ll MOD = 1e9+7;

template <class T>ostream &operator<<(ostream &o,const vector<T>&v)
{o<<"[";for(int i=0;i<(int)v.size();i++)o<<(i>0?", ":"")<<v[i];o<<"]";return o;}
template <class T, class U>ostream &operator<<(ostream &o, const pair<T, U>&p)
{o<<"{"<<p.first<<", "<<p.second<<"}";return o;}
template <class T, class U>ostream &operator<<(ostream &o, const map<T, U>&obj)
{o<<"{";for(auto itr=obj.begin();itr!=obj.end();++itr)o<<(itr!=obj.begin()?", ":"")<<*itr;o<<"}";return o;}
void dump() {}
template <class H, class... T>void dump(H&& head, T&&... tail)
{cout << head << (sizeof...(tail)==0 ? "\n" : " "); dump(forward<T>(tail)...);}


int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  
  int n,m,a,b,c;
  cin >> n >> m;
  vector<pair<int,vector<int>>> key(m);
  for(int i = 0; i < m; ++i){
    cin >> a >> b;
    key[i].first = a;
    for(int j = 0; j < b; ++j){
      cin >> c; c--;
      key[i].second.push_back(c);
    }
  }
  vector<int> dp(1<<n, INF);
  dp[0] = 0;

  for(int i = 0; i < m; ++i){
    int m = 0;
    for(auto c : key[i].second){
      m += 1 << c;
    }
    for(int j = 0; j < (1<<n); ++j){
      dp[j | m] = min(dp[j] + key[i].first, dp[j|m]);
      //dump(i,j,j|m,key[i],dp);
    }
    //dump(dp);
  }
//dump(dp);
//dump(key, 1<<1);
  int ans = dp[(1<<n)-1];
  cout << (ans >= 1e7 ? -1 : ans) << endl;
  return 0;
}


Measured memory_bytes: 384
#include<iostream>
#include<vector>
#include<algorithm>

using namespace std;

int main() {

	int k, n,a;

	vector<int>v;

	cin >> k >> n;

	for (int i = 0; i < n; i++) {
		cin >> a;
		v.push_back(a);
	}

	int sum = 0;
	//for (int i = 0; i < n; i++) { //start
	//	for(int i=0;i<n;)
	//	int j, now,k;
	//	if(now==0)


	//}
	vector<int>distance;
	for (int i = 0; i < n-1; i++) {
		int dist = v[i+1] - v[i];
		distance.push_back(dist);
	}
	int distn = v[0] + (k - v[n - 1]);
	distance.push_back(distn);

	int max = *max_element(distance.begin(), distance.end());

	cout << k - max << endl;

	return 0;

}

Measured memory_bytes: 2548
#include <bits/stdc++.h>
using namespace std;
int main(){
	string s1, s2;
	int t=0;
	cin >> s1 >> s2;
	for (int i=0; i<s1.size(); i++)
		if (s1[i]!=s2[i]) t++;
	cout << t << endl;
	return 0;
}

Measured memory_bytes: 3920
#include <iostream>
#include <vector>
#include <algorithm>
#include <math.h>
using namespace std;

typedef long long ll;

ll gcd(ll a, ll b) {
	if (!b)return a;
	return gcd(b, a % b);
}

int main() {
	ll a, b, i, g;
	int count = 1;
	cin >> a >> b;
	g = gcd(a, b);
	for (i = 2; i * i <= g; i++) {
		if (g % i == 0) {
			count++;
			while (g % i == 0) {
				g /= i;
			}
		}
	}
	if (g > 1)count++;
	cout << count << endl;
}

Measured memory_bytes: 256
#pragma GCC optimize("O3")
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <string>
#include <cstring>
#include <deque>
#include <list>
#include <queue>
#include <stack>
#include <vector>
#include <utility>
#include <algorithm>
#include <map>
#include <set>
#include <complex>
#include <cmath>
#include <limits>
#include <cfloat>
#include <climits>
#include <ctime>
#include <cassert>
#include <numeric>
#include <fstream>
#include <functional>
#include <bitset>
using namespace std;

using ll = long long;
using P = pair<int, int>;
using T = tuple<int, int, int>;

template <class T> inline T chmax(T &a, const T b) {return a = (a < b) ? b : a;}
template <class T> inline T chmin(T &a, const T b) {return a = (a > b) ? b : a;}

constexpr int MOD = 1e9 + 7;
constexpr int inf = 1e9;
constexpr long long INF = 1e18;
constexpr double pi = acos(-1);
constexpr double EPS = 1e-10;

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

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

    ll n, k; cin>>n>>k;
    vector<ll> a(n), f(n);
    for(int i=0; i<n; i++) cin>>a[i];
    for(int i=0; i<n; i++) cin>>f[i];
    sort(a.begin(), a.end());
    sort(f.begin(), f.end(), greater<ll>());

    ll ng = -1, ok = INF;
    while(ok - ng > 1){
        ll mid = (ok + ng) / 2;

        ll sum = 0;
        for(int i=0; i<n; i++){
            ll num = (mid / f[i]);
            sum += max(0LL, a[i] - num);
        }

        if(sum <= k) ok = mid;
        else ng = mid;
    }

    cout << ok << endl;

    return 0;
}

Measured memory_bytes: 3456
x, k, d = [int(i) for i in input().split()]
m = abs(x) // d
sgn = 1 if x >= 0 else -1
if k <= m:
    result = x - sgn * k * d
else:
    excess = k - m
    moves = m + (excess % 2)
    result = x - sgn * moves * d
print(abs(result))


Measured memory_bytes: 9172
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int maxn=105;
int a[maxn];
int main(){
	int n,k,x,q;
	cin>>n>>k;
	for(int i=0;i<k;++i)
		{
			cin>>x;
			for(int j=0;j<x;++j){
				cin>>q;
				a[q]++;
			}
		}
	int ans=0;
	for(int i=1;i<=n;++i)
		if(a[i]==0) ans++;
	cout<<ans<<endl;
	return 0;
} 

Measured memory_bytes: 3636
#include <iostream>
#include <vector>
using namespace std;
int main(){
	int n,i;
	cin >> n;
	vector<int> p(n);
	for(i=0; i<n; i++){
		cin >> p[i];
	}

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

	cout << ans << endl;
	return 0;
}

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

int main() {
    int A, B, C, K, sum = 0;
    cin >> A >> B >> C >> K;
    if (A >= K) {
        sum = K;
    } else if (A + B >= K) {
        sum = A;
    } else {
        sum = A - (K - A - B);
    }
    cout << sum << endl;
    return 0;
}

Measured memory_bytes: 3636
/*@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
Code author: Saurabh Singhal
Code copy karne vaale tera muh kaala
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@*/

#include<bits/stdc++.h>
#define mp(a,b) make_pair(a,b)
#define pb push_back
#define ppb pop_back

using namespace std;
typedef long long int ll;
typedef vector<int> vi_t;
typedef vector<ll> vll_t;
int t=1;
vll_t a,b;
int find(int a){
	int s=a,count=0;
	while(a%2==0){
		a/=2;
		count++;
	}
	return count;
}
int  main(){
	// #ifndef ONLINE_JUDGE
 //    // for getting input from input.txt
 //    freopen("input.txt", "r", stdin);
 //    // for writing output to output.txt
 //    freopen("output.txt", "w", stdout);
	// #endif
	int n,count=0;
	cin>>n;
	for(int i=0;i<n;i++){
		int a;
		cin>>a;
		count+=find(a);
	}
	cout<<count<<endl;
}

Measured memory_bytes: 256
import numpy as np
import bisect
def getNearestValue(list_, num):
    idx = np.abs(np.asarray(list_) - num).argmin()
    return list_[idx]

N=int(input())
A=[int(i) for i in input().split()]

A.sort()
a=A[-1]
print(a,getNearestValue(A,a/2))

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

using namespace std;

using llong = long long int;

#define rep(i, n) for (int i = 0; i < n; ++i)
#define stl_rep(itr, x) for (auto itr = x.begin(); itr != x.end(); ++itr)
#define all(x) x.begin(), x.end()
#define allr(x) x.rbegin(), x.rend()

const static int MOD = 1000000007;
const static int INF = 1<<30;
const static int dx[4] = {1, 0, -1, 0};
const static int dy[4] = {0, 1, 0, -1};

int main (int argc, char *argv[]) {
    cin.tie(0);
    ios::sync_with_stdio(false);

    int n;
    cin >> n;
    map<string, int> M;
    rep(i, n) {
        string s;
        cin >> s;
        ++M[s];
    }

    cout << "AC" << ' ' << 'x' << ' ' << M["AC"] << endl;
    cout << "WA" << ' ' << 'x' << ' ' << M["WA"] << endl;
    cout << "TLE" << ' ' << 'x' << ' ' << M["TLE"] << endl;
    cout << "RE" << ' ' << 'x' << ' ' << M["RE"] << endl;
    return 0;
}

Measured memory_bytes: 3656