akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#define ADD(a, b) a = (a + ll(b)) % mod
#define MUL(a, b) a = (a * ll(b)) % mod
#define MAX(a, b) a = max(a, b)
#define MIN(a, b) a = min(a, b)
#define rep(i, a, b) for(int i = int(a); i < int(b); i++)
#define rer(i, a, b) for(int i = int(a) - 1; i >= int(b); i--)
#define all(a) (a).begin(), (a).end()
#define sz(v) (int)(v).size()
#define pb push_back
#define sec second
#define fst first
#define debug(fmt, ...) Debug(__LINE__, ":", fmt, ##__VA_ARGS__)
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> pi;
typedef pair<ll, ll> pl;
typedef pair<int, pi> ppi;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<vl> mat;
typedef complex<double> comp;
void Debug() {cerr << '\n'; }
template<class FIRST, class... REST>void Debug(FIRST arg, REST... rest){
	cerr<<arg<<" ";Debug(rest...);}
template<class T>ostream& operator<<(ostream& out,const vector<T>& v) {
	out<<"[";if(!v.empty()){rep(i,0,sz(v)-1)out<<v[i]<<", ";out<<v.back();}out<<"]";return out;}
template<class S, class T>ostream& operator<<(ostream& out,const pair<S, T>& v){
	out<<"("<<v.first<<", "<<v.second<<")";return out;}
const int MAX_N = 500010;
const int MAX_V = 100010;
const double eps = 1e-6;
const ll mod = 1000000007;
const int inf = (1 << 30) - 1;
const ll linf = 1LL << 60;
const double PI = 3.14159265358979323846;
mt19937 rng; //use it by rng() % mod, shuffle(all(vec), rng)
///////////////////////////////////////////////////////////////////////////////////////////////////


void solve() {
	int R; cin >> R;
	cout << R * R << "\n";
}

uint32_t rd() {
	uint32_t res;
#ifdef __MINGW32__
	asm volatile("rdrand %0" :"=a"(res) ::"cc");
#else
	res = std::random_device()();
#endif
	return res;
}

int main() {
#ifndef LOCAL
	ios::sync_with_stdio(false);
    cin.tie(0);
#endif
    cout << fixed;
	cout.precision(20);
    cerr << fixed;
	cerr.precision(6);
	rng.seed(rd());
#ifdef LOCAL
	//freopen("in.txt", "wt", stdout); //for tester
	if(!freopen("in.txt", "rt", stdin)) return 1;
#endif	
	solve();
    cerr << "Time: " << 1.0 * clock() / CLOCKS_PER_SEC << " s.\n";
	return 0;
}



Measured memory_bytes: 256
n = int(input())
xy = [[] for i in range(n)]

for i in range(n):
    a = int(input())
    for j in range(a):
        x, y = map(int, input().split())
        xy[i].append([x, y])

ans = 0

for b in range(1 << n): # 1をn桁分、左にシフト(2進数)
    cnt = bin(b).count("1")
    ok = True
    for j in range(n):
        if ok == False:
            break
        if b&(1 << j) != 0:
        # 論理積(同じ桁のビットで共通の桁があればok)
        # j番目の人が正直者設定であれば、先に進む
            for x, y in xy[j]: # j人目の人の証言
                if y == 1 and b&(1 << x - 1) == 0:
                # 正直者と証言された人が正直者設定でない場合
                    ok = False
                if y == 0 and b&(1 << x - 1) != 0:
                # 不親切と証言された人が不親切設定でない場合
                    ok = False
    if ok == True:
        ans = max(cnt, ans)
print(ans)

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

int main()
{
	int n;
	cin >> n;
	int arr[n] = {0};
	for(int i = 1; i < n; i++)
	{	
		int temp;
		cin >> temp;
		arr[temp-1]++;
	}
	
	for(int i = 0; i < n; i++)
		cout << arr[i] << endl;
}


Measured memory_bytes: 4404
//
// Created by 李青坪 on 2018/11/2.
//

#include <cstdio>
#define MAXN 101
using namespace std;

int graph[MAXN][MAXN];
int nodeTime[MAXN][2];
int countTime = 0;
int n;

void dfs(int i){
    if (nodeTime[i][0] != 0){
        return;
    }
    countTime++;
    nodeTime[i][0] = countTime;
    for (int j = 1; j <= n; ++j) {
        if (graph[i][j] != 0 && nodeTime[j][0] == 0){
            dfs(j);
        }
    }
    countTime++;
    nodeTime[i][1] = countTime;
}

int main(){
    scanf("%d", &n);
    int u, k;
    for (int i = 0; i < n; ++i) {
        scanf("%d %d", &u, &k);
        int node;
        for (int j = 0; j < k; ++j) {
            scanf("%d", &node);
            graph[u][node] = 1;
        }
    }
    for (int m = 1; m <= n; ++m) {
        dfs(m);
    };
    for (int l = 1; l <= n; ++l) {
        printf("%d %d %d\n", l, nodeTime[l][0], nodeTime[l][1]);
    }
}
/*
6
1 2 2 3
2 2 3 4
3 1 5
4 1 6
5 1 6
6 0
 */


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

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

    int n,m,cnt,tmp=0;
    cin >> n;
    vector<string> b(n);
    for(int i=0;i<n;i++)
        cin >> b.at(i);
    cin >> m;
    vector<string> r(m);
    for(int i=0;i<m;i++)
        cin >> r.at(i);

    string data;
    for(int i=0;i<n;i++){
        cnt=1;
        data = b.at(i);
        for(int j=0;j<n;j++){
            if(j==i)
                continue;
            if(data==b.at(j))
                cnt++;
        }
        for(int j=0;j<m;j++){
            if(data==r.at(j))
                cnt--;
        }
        if(tmp<cnt)
            tmp=cnt;
    }
    cout << tmp << endl;
}


Measured memory_bytes: 256
package main

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

type Row []string

type Data []Row

func main() {
	nextReader = newScanner()
	N := nextInt()
	K := nextInt()
	f := make([]int, N)
	for k := 0; k < K; k++ {
		d := nextInt()
		for e := 0; e < d; e++ {
			m := nextInt()
			f[m-1] += 1
		}
	}
	ans := 0
	for _, n := range f {
		if n == 0 {
			ans += 1
		}
	}
	fmt.Printf("%d", ans)
}

var nextReader func() string

func newScanner() func() string {
	r := bufio.NewScanner(os.Stdin)
	r.Buffer(make([]byte, 1024), int(1e+11))
	r.Split(bufio.ScanWords)
	// r.Split(bufio.ScanLines)
	return func() string {
		r.Scan()
		return r.Text()
	}
}

func nextStrings() func() string {
	r := bufio.NewScanner(os.Stdin)
	r.Buffer(make([]byte, 1024), int(1e+11))
	r.Split(bufio.ScanWords)
	return func() string {
		r.Scan()
		return r.Text()
	}
}

func nextString() string {
	return nextReader()
}
func nextInt64() int64 {
	v, _ := strconv.ParseInt(nextReader(), 10, 64)
	return v
}
func nextInt() int {
	v, _ := strconv.Atoi(nextReader())
	return v
}
func nextInts(n int) []int {
	r := make([]int, n)
	for i := 0; i < n; i++ {
		r[i] = nextInt()
	}
	return r
}
func nextInt64s(n int) []int64 {
	r := make([]int64, n)
	for i := 0; i < n; i++ {
		r[i] = nextInt64()
	}
	return r
}
func nextFloat64() float64 {
	f, _ := strconv.ParseFloat(nextReader(), 64)
	return f
}

func maxInt(a, b int) int {
	if a > b {
		return a
	} else {
		return b
	}
}


Measured memory_bytes: 1756
#include <bits/stdc++.h>
using namespace std;
#define uint unsigned int
#define llong long long int
#define ullong unsigned long long int

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

    char c[1]; cin >> c[0];
    cout << ((c[0]=='a'||c[0]=='i'||c[0]=='u'||c[0]=='e'||c[0]=='o') ? "vowel" : "consonant") << endl;

    return 0;
}

Measured memory_bytes: 256
#include<cstdio>
#include<iostream>
#include<cmath>
#include<algorithm>
#include<cstring>
#include<cstdlib>
#include<queue>
#include<map>
#include<string>
#define ll long long
using namespace std;
int read()
{
	int x=0,f=1;
	char c=getchar();
	while(c<'0'||c>'9')
	{
		if(c=='-') f=-1;
		c=getchar();
	}
	while(c>='0'&&c<='9')
	{
		x=x*10+c-'0';
		c=getchar();
	}
	return x*f;
}
int a,b;
int main()
{
	a=read();b=read();
	if(b==100) ++b;
	if(a==0)
	{
		cout<<b;
	}
	else if(a==1)
	{
		cout<<b<<"00";
	}
	else 
	{
		cout<<b<<"0000";
	}
	return 0;
 } 

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

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

using std::cin;
using std::cout;
using std::endl;
using std::string;
using std::vector;

int H, W;

void move(int y, int x, int c, vector<vector<int>> &S, std::deque<std::pair<std::pair<int, int>, int>> &q, bool front)
{
  if (x >= 0 && x < W && y >= 0 && y < H)
  {
    if (S[y][x] == -1 || S[y][x] > c)
    {
      S[y][x] = c;
      if(front) {
	      q.push_front(std::make_pair(std::make_pair(y, x), c));
      } else {
	      q.push_back(std::make_pair(std::make_pair(y, x), c));
      }
    }
  }
}

int main()
{
  cin >> H >> W;
  int sy, sx;
  cin >> sy >> sx;
  int gy, gx;
  cin >> gy >> gx;

  vector<vector<int>> S(H);
  rep(i, H)
  {
    S[i].resize(W);
    rep(j, W)
    {
      char tmp;
      cin >> tmp;
      if (tmp == '#')
        S[i][j] = -2;
      else
        S[i][j] = -1;
    }
  }

  std::deque<std::pair<std::pair<int, int>, int>> q;

  q.push_front(std::make_pair(std::make_pair(sy - 1, sx - 1), 0));
  S[sy - 1][sx - 1] = 0;

  int tbl1_y[] = {0, 0, -1, 1};
  int tbl1_x[] = {-1, 1, 0, 0};

  int tbl2_y[] = {-2, -2, -2, -2, -2, -1, -1, -1, -1, 0, 0, 1, 1, 1, 1, 2, 2, 2, 2, 2};
  int tbl2_x[] = {-2, -1, 0, 1, 2, -2, -1, 1, 2, -2, 2, -2, -1, 1, 2, -2, -1, 0, 1, 2};

  while (!q.empty())
  {
    std::pair<std::pair<int, int>, int> e;
    if (!q.empty()) {     
      e = q.front();
      q.pop_front();
    }

    auto p = e.first;
    int y = p.first;
    int x = p.second;
    int c = e.second;

    rep(i, 4)
    {
      move(y + tbl1_y[i], x + tbl1_x[i], c, S, q, true);
    }

    rep(i, 20)
    {
      move(y + tbl2_y[i], x + tbl2_x[i], c + 1, S, q, false);
    }
  }

  cout << S[gy - 1][gx - 1] << endl;

  return 0;
}


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

using namespace std;

#define ll long long
#define rep(i,n) for(int i=1;i<=(n);i++)
#define rep0(i,n) for(int i=0;i<(n);i++)

const ll INF=1e9+7;

int main()
{
	/*freopen("input.txt","r",stdin);
	freopen("output.txt","w",stdout);*/
	int n,m;
	cin>>n>>m;
	if(n%(m*2+1)==0){
		cout<<n/(m*2+1);
	}
	else{
		cout<<n/(m*2+1)+1;
	}
	return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
	public static void main(String[] args) throws Exception {
		Scanner sc = new Scanner(System.in);
		int a = sc.nextInt();
		int b = sc.nextInt();
		if (a > b) {
			for (int i = 0; i < a; i++) {
				System.out.print(b);
			}
		} else {
			for (int i = 0; i < b; i++) {
				System.out.print(a);
			}
		}
	}
}

Measured memory_bytes: 19796
#include <stdio.h>

int main(){
	int i,tmp;
	int cup[3] = {1,0,0};
	char p,q;

	while(scanf("%c,%c",&p,&q) != EOF){
		tmp = cup[p-'A'];
		cup[p-'A'] = cup[q-'A'];
		cup[q-'A'] = tmp;
		scanf("%c",&p);
	}

	for(i = 0;i < 3;i++){
		if(cup[i]){
			printf("%c\n",i+'A');
			break;
		}
	}

	return 0;
}

Measured memory_bytes: 544
#include <stdio.h>

int main(){
   long a,b,c,d,ans,i,j,k;
    
   scanf("%ld %ld %ld %ld",&a,&b,&c,&d);
   i=a/c;if (a%c==0) i--;
   j=b/c;
   ans=j-i;
   i=a/d;if (a%d==0) i--;
   j=b/d;
   ans+=j-i;
   for (i=c,j=d;(k=i%j)>0;i=j,j=k) ;
   k=c*d/j;
   i=a/k;if (a%k==0) i--;
   j=b/k;
   ans-=j-i;
   printf("%ld\n",b-a-ans+1);
   return 0;
}


Measured memory_bytes: 128
#include<stdio.h>
#include<stdlib.h>
#include<stdint.h>
#include<inttypes.h>

typedef struct union_find {
  int32_t *parent;
  int32_t size;
} union_find;

void init_union_find (union_find * const u) {
  for (int32_t i = 0; i < u->size; ++i){
    u->parent[i] = -1;
  }
}

union_find* new_union_find (const int32_t size) {
  union_find * const u = (union_find *) calloc (1, sizeof (union_find));
  u->parent = (int32_t *) calloc (size, sizeof (int32_t));
  u->size = size;
  init_union_find (u);
  return u;
}

void free_union_find (union_find * const u) {
  free (u->parent);
  free (u);
}

int32_t root (union_find * const u, int32_t x) {
  int32_t index[32];
  int32_t top = 0;
  while (u->parent[x] >= 0) {
    index[top++] = x;
    x = u->parent[x];
  }
  while (top > 0) {
    u->parent[index[--top]] = x;
  }
  return x;
}

void unite (union_find * const u, int32_t x, int32_t y) {
  x = root (u, x);
  y = root (u, y);
  if (x == y) return;
  if (u->parent[x] > u->parent[y]) {
    const int32_t swap = x;
    x = y;
    y = swap;
  }
  u->parent[x] += u->parent[y];
  u->parent[y] = x;
}

typedef int32_t i32;
typedef int64_t i64;

#define ALLOC(size,type) ((type*)calloc((size),sizeof(type)))

void run (void) {
  i32 n;
  scanf ("%" SCNi32, &n);
  const i32 m = 100001;
  union_find *u = new_union_find (2 * m);
  i32 *cntX = ALLOC (2 * m, i32);
  i32 *cntY = ALLOC (2 * m, i32);
  for (i32 i = 1; i < m; ++i) {
    cntX[i] = cntY[i + m] = 1;
  }
  for (i32 i = 0; i < n; ++i) {
    i32 x, y;
    scanf ("%" SCNi32 "%" SCNi32, &x, &y);
    y += m;
    i32 a = root (u, x);
    i32 b = root (u, y);
    if (a == b) continue;
    unite (u, x, y);
    i32 c = root (u, x);
    cntX[c] += cntX[a ^ b ^ c];
    cntY[c] += cntY[a ^ b ^ c];
  }
  uint8_t *used = ALLOC (2 * m, uint8_t);
  i64 ans = -n;
  for (i32 i = 1; i < m; ++i) {
    i32 r = root (u, i);
    if (used[r]) continue;
    used[r] = 1;
    ans += (i64) cntX[r] * cntY[r];
  }
  printf ("%" PRIi64 "\n", ans);
}

int main (void) {
  run();
  return 0;
}


Measured memory_bytes: 2176
#include <bits/stdc++.h>
using namespace std;
typedef unsigned long long ull;
typedef long long ll;
#define fastio() ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
#define loop(i,a,b) for(ll i=a;i<b;i++)
#define loope(i,a,b) for(ll i=a;i<=b;i++)
#define test() ull t;cin>>t;while(t--)
#define pll pair<ll,ll>
#define puu pair<ull,ull>
#define f first
#define s second
#define pb push_back
#define mkp make_pair
#define ins insert
#define Vint vector<int>
#define Vll vector<ll>
#define Vull vector<ull>
#define nl cout<<endl
#define sp cout<<" "
#define MOD 1000000007
#define all(x) x.begin(),x.end()
int dx[] = {1,0,-1,0};
int dy[] = {0,1,0,-1};


int main() 
{
	// ios::sync_with_stdio(0);
	// cin.tie(0);
	// cout.tie(0);
	
	ll n;
	cin>>n;
	ll dp[n+1],v[n];
	memset(dp,0,sizeof(dp));
	loop(i,0,n)
		cin>>v[i];
	dp[2] = abs(v[1]-v[0]);
	loop(i,3,n+1){
		dp[i] = min(dp[i-2] + abs(v[i-1]-v[i-3]),dp[i-1] + abs(v[i-1]-v[i-2]));
	}

	cout<<dp[n];
}

Measured memory_bytes: 5164
import sys
N, X = map(int, input().split())

for i in range(N + 1):
    for k in range(0, N - i + 1):
        if i * 10000 + k * 5000 + (N - i - k) * 1000 == X:
            print(i, k, N - i - k)
            sys.exit()
print('-1 -1 -1')

Measured memory_bytes: 2940
#include<bits/stdc++.h>
using namespace std;
#define ll long long int
#define ld long double
#define pb emplace_back
#define mp make_pair
#define f(i,a,n) for(int i=a ; i<n ; i++)
#define F first
#define S second
#define vll vector<ll>
#define fast ios:: sync_with_stdio(false),cin.tie(0);
#define COUT cout<<fixed<<setprecision(12)
#define SET set<ll,greater<ll>>gquiz
#define ITERATOR set<ll,greater<ll>> :: iterator itr
#define V vector<ll>vector
#define sz size()
#define A vector<pair<ll,ll>>vect
ll N=100000,M=100000;
#define B vect.push_back(make_pair(N,M));
ll MOD=1000000007;
 
ll gcd(ll a,ll b) 
{ 
    if (a == 0) 
        return b; 
    return gcd(b % a, a); 
} 
ll ncr(ll n,ll r)
{
	if(n==1 || r==0)
	return 1;
	if(r>n/2)
	r=n-r;
	ll ans=1;
	for(ll i=1;i<=r;i++)
	{
		ans=((ans * n )/i);
		n--;
	}
	return ans;
}
int main()
{
	ll n,k;
	cin>>n>>k;
	ll cnt=0;
	while(n>0)
	{
		n=n/k;
		cnt++;
	}
	cout<<cnt;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define REP(i, n) for(int i = 0; i < n; i++)
#define COUT(x) cout<<(x)<<endl
#define dump(x)  cout << #x << " = " << (x) << endl;
using ll = long long;
using P = pair<int,int>;
using Graph = vector<vector<int>>;
using M = map<int,int>;
using PQ = priority_queue<int>;
using PQG = priority_queue<int, vector<int>, greater<int>>;
const int INF = 1e9;
const int MOD = 1e9+7;
const ll LINF = 1e18;

int main() {
  int a,b;
  string s;
  cin >> a >> b >> s;
  int i = 0;
  int ok = true;
  REP(i,s.size()) {
    char c = s[i];
    if (i == a) {
      if (c != '-') ok = false;
    } else {
      int cn= c-'0';
      if (cn < 0 || cn > 9) ok = false;
    }
  }
  COUT(ok ? "Yes" : "No");
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long int;
int main(){
	int n;
	cin >> n;
	int dp[n][3];
	for(int i=0;i<n;i++)
		for(int j=0;j<3;j++)
			cin >> dp[i][j];

	for(int i=1;i<n;i++){
		dp[i][0]+=max(dp[i-1][1],dp[i-1][2]);
		dp[i][1]+=max(dp[i-1][0],dp[i-1][2]);
		dp[i][2]+=max(dp[i-1][0],dp[i-1][1]);
	}
	cout << max({dp[n-1][0],dp[n-1][1],dp[n-1][2]});
return 0;
}



Measured memory_bytes: 4740
#include <bits/stdc++.h>
#define REP(i, n) for (int(i) = 0; (i) < (n); (i)++)
#define REPR(i, n) for (int(i) = (n); (i) >= 0; (i)--)
#define FOR(i, m, n) for (int(i) = (m); (i) < (n); i++)
#define INF 1e9
#define ALL(v) (v).begin(), (v).end()
using namespace std;
using ll = long long;
using pll = pair<ll, ll>;

int main()
{
  int P, Q, R, minimum;
  cin >> P >> Q >> R;

  minimum = min(P + Q, P + R);
  minimum = min(minimum, Q + R);

  cout << minimum << '\n';

  return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include "bits/stdc++.h"
using namespace std;
#define print(x) cout<<x<<endl;
#define rep(i,a,b) for(int i=a;i<b;i++)
#define REP(i,a) for(int i=0;i<a;i++)
#define debug int debug = 0;
#define RREP(i,a) for(int i=a-1;i>=0;i--)
#define rrep(i,a,b) for(int i=a-1;i>=b;i--)
#define printall(n,array) {for(int i=0;i<n;i++){cout<<array[i]<<" ";}cout<<endl;}
#define U() cout<<endl;
typedef long long ll;
typedef pair<int, int> PI;
typedef pair<int, PI> V;
typedef vector<int> VE;
const ll mod = 1000000007; //10^9+7

int white, black;
bool grid[100][100]; // true = white, false = black;
int K = 50;

bool check(int i, int j){
    bool color = !grid[i][j];
    int dx[8] = {0, 1, 1, 1, 0, -1, -1, -1};
    int dy[8] = {1, 1, 0, -1, -1, -1, 0, 1};
    REP(k, 8){
        if(i + dy[k] < 0 || i + dy[k] == 2 * K || j + dx[k] < 0 || j + dx[k] == 2 * K)continue;
        if(grid[i + dy[k]][j + dx[k]] == color){
            return false;
        }
    }
    return true;
}

int main(){
    cin >> white >> black;
    REP(i, 100){
        REP(j, 100){
            if(i < K){
                grid[i][j] = true;
            }else{
                grid[i][j] = false;
            }
        }
    }
    int wcount = 1, bcount = 1;
    REP(i, K - 1){
        if(bcount == black)break;
        REP(j, 100){
            if(check(i, j)){
                grid[i][j] = !grid[i][j];
                bcount++;
                if(bcount == black)break;
            }
        }
    }
    REP(i, K - 1){
        if(wcount == white)break;
        REP(j, 100){
            if(check(99 - i, j)){
                grid[99 - i][j] = !grid[99 - i][j];
                wcount++;
                if(wcount == white)break;
            }
        }
    }
    print(2 * K << " " << 2 * K);
    REP(i, 100){
        REP(j, 100){
            if(grid[i][j]){
                cout << ".";
            }else{
                cout << "#";
            }
        }
        cout << endl;
    }
    return 0;
}

Measured memory_bytes: 256
#include <bitset>
#include <cstdlib>
#include <functional>
#include <iostream>
#include <queue>
#include <vector>
using namespace std;

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

template<class T> inline void chmin(T &a, const T &b) { if(a > b) a = b; }

struct state {
	int v, t, d;
	state(int v_, int t_, int d_):v(v_), t(t_), d(d_) {}
	bool operator>(const state &s) const {
		return d > s.d;
	}
};

struct edge {
	int to, cost, time, company;
	edge(int to_, int cost_, int time_, int company_):to(to_), cost(cost_), time(time_), company(company_) {}
};

constexpr int MAX_K = 8;
constexpr int INF = (1 << 29);

int dijkstra(int s, int t, int h, const vector<vector<edge>> &G, const bitset<MAX_K> &b) {
	const int n = G.size();
	vector<vector<int>> dist(n, vector<int>(h + 1, INF));
	priority_queue<state, vector<state>, greater<state>> que;

	dist[s][0] = 0;
	que.push(state(s, 0, 0));

	while(!que.empty()) {
		const state s = que.top();
		que.pop();

		if(s.d > dist[s.v][s.t]) continue;
		if(s.v == t) return s.d;

		for(const auto &e : G[s.v]) {
			const int next_time = s.t + e.time;
			if(next_time > h) continue;

			const int next_dist = s.d + (b[e.company] ? 0 : e.cost);
			if(dist[e.to][next_time] > next_dist) {
				dist[e.to][next_time] = next_dist;
				que.emplace(e.to, next_time, next_dist);
			}
		}
	}

	return INF;
}

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

	for(int n, m, h, k; cin >> n >> m >> h >> k && n;) {
		vector<vector<edge>> G(n);

		rep(i, m) {
			int a, b, c, t, r;
			cin >> a >> b >> c >> t >> r;
			--a; --b; --r;
			G[a].emplace_back(b, c, t, r);
			G[b].emplace_back(a, c, t, r);
		}

		int s, t, p;
		cin >> s >> t >> p;
		--s; --t;

		vector<int> pass(p, 0);
		vector<int> value(p);

		rep(i, p) {
			int l;
			cin >> l >> value[i];

			rep(j, l) {
				int q;
				cin >> q;
				pass[i] |= (1 << (q - 1));
			}
		}

		vector<int> min_cost(1 << k, INF);
		min_cost[0] = 0;

		int ans = INF;
		rep(i, 1 << k) {
			if(min_cost[i] >= ans) continue;
			
			chmin(ans, dijkstra(s, t, h, G, bitset<MAX_K>(i)) + min_cost[i]);

			rep(j, p) {
				const int next = (i | pass[j]);
				chmin(min_cost[next], min_cost[i] + value[j]);
			}
		}

		cout << (ans == INF ? -1 : ans) << endl;
	}
	return EXIT_SUCCESS;
}

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

int nagasa[51];

int main() {

	int i, j;
	int n, k, tmp;
	int maxsum;

	scanf("%d%d", &n, &k);
	for (i = 0; i < n; i++) {
		scanf("%d", &nagasa[i]);
	}

	//長い順にソートする//
	for (i = 0; i < n; i++) {
		for (j = i + 1; j < n; j++) {
			if (nagasa[i] < nagasa[j]) {
				tmp = nagasa[i];
				nagasa[i] = nagasa[j];
				nagasa[j] = tmp;
			}
		}

	}

	maxsum = 0;
	for (i = 0; i < k; i++) {
		maxsum = maxsum + nagasa[i];
	}

	printf("%d", maxsum);

	return 0;
}

Measured memory_bytes: 128
#include <iostream>
#include <vector>
#include <string>
using namespace std;
//変数デバッグ
#define DEB(variable) cout << #variable << '=' << variable << endl

//for簡易表記(引数ミス防止)
#define FOR(LoopVariable,numberOFbegin,numberOFend) for (int LoopVariable = (numberOFbegin); (LoopVariable) < (numberOFend); (LoopVariable)++)
#define REP(LoopVariable,numberOFend) for(int LoopVariable = 0;(LoopVariable)<(numberOFend);LoopVariable++)

int main(){

    int n;
    cin >> n;

    if(n==1||n==2||n==3||n==5||n==6||n==9||n==10||n==13||n==17){
        cout << "No" << endl;
    }else{
        cout << "Yes" << endl;
    }

    return 0;
}

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

int main() {

  int N,Ali = 0,Bob = 0;
  cin >> N;

  vector<int> a(N);

  for (int i=0 ; i < N ; i++)
    cin >> a.at(i);
  
  sort(a.begin(),a.end());
  
  for (int i = 0 ; i < N ; i++){
    
    if (i % 2 == 0)
      Ali += a.at(N - 1 - i);
    else
      Bob += a.at(N - 1 - i);

  }
  
  
  cout << Ali - Bob << endl;
  
}

Measured memory_bytes: 256
/*** author: yuji9511 ***/
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using lpair = pair<ll, ll>;
const ll MOD = 1e9+7;
const ll INF = 1e18;
#define rep(i,m,n) for(ll i=(m);i<(n);i++)
#define rrep(i,m,n) for(ll i=(m);i>=(n);i--)
#define printa(x,n) for(ll i=0;i<n;i++){cout<<(x[i])<<" \n"[i==n-1];};
void print() {}
template <class H,class... T>
void print(H&& h, T&&... t){cout<<h<<" \n"[sizeof...(t)==0];print(forward<T>(t)...);}

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll N;
    cin >> N;
    ll A[2010];

    rep(i,0,N) cin >> A[i];
    bitset<2000*2000+1> cur(0), nxt(0);
    cur[0] = 1;
    rep(i,0,N){
        nxt = (cur | (cur<<A[i]));
        cur = nxt;
    }

    ll sum = 0;
    rep(i,0,N) sum += A[i];
    ll ans = (sum+1)/2;
    while(1){
        if(cur[ans] == true){
            print(ans);
            return 0;
        }
        ans++;
    }


}

Measured memory_bytes: 2688
n=int(input())
h=list(map(int,input().split()))

dp=[float('inf')]*n
dp[0]=0
dp[1]=abs(h[1]-h[0])
for i in range(2,n):
    dp[i]=min(dp[i],dp[i-2]+abs(h[i]-h[i-2]),dp[i-1]+abs(h[i]-h[i-1]))
print(dp[-1])

Measured memory_bytes: 13928
#include <iostream>
#include <iomanip>
#include <map>
#include <utility>
typedef long long ll;
using namespace std;
const ll INF = 1e9;
const ll MOD = 1e9 + 7;
#define repi(i, n, init) for (ll i = init; i < (n); i++)

ll gcd(ll a, ll b)
{
    ll x, y;
    x = max(a, b);
    y = min(a, b);
    if (x % y == 0)
    {
        return y;
    }
    else
    {
        gcd(y, x % y);
    }
}

int main()
{
    ll a, b;
    cin >> a >> b;
    ll g = gcd(a, b);
    map<ll, ll> pf;
    { //素因数分解
        for (ll i = 2; i * i <= g; i++)
        {
            while (g % i == 0)
            {
                pf[i]++;
                g /= i;
            }
        }
        if (g != 1)
            pf[g] = 1; //最後の素因数を回収
    }

    cout << pf.size() + 1 << endl;
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<ll,ll> P;
typedef pair<int,int> Pi;
#define rep(i, n) for (ll i = 0; i < n; i++)
#define FOR(i, a, b) for (ll i = a; i < b; i++)
#define fi first
#define se second
#define PI (acos(-1))

template<class T>
inline bool chmax(T &a, T b) {
    if(a < b) {
        a = b;
        return true;
    }
    return false;
}
template<class T>
inline bool chmin(T &a, T b) {
    if(a > b) {
        a = b;
        return true;
    }
    return false;
}
template<typename T> ostream& operator<<(ostream& s,const complex<T>& d) {return s<<"("<<d.real()<<", "<<d.imag()<< ")";}
template<typename T1, typename T2> ostream& operator<<(ostream& s,const pair<T1,T2>& d) {return s<<"("<<d.first<<", "<<d.second<<")";}
template<typename T> ostream& operator<<(ostream& s, const vector<T>& d){
	int len=d.size();
	rep(i,len){
		s<<d[i];if(i<len-1) s<<" ";
	}
	return s;
}
template<typename T> ostream& operator<<(ostream& s,const vector<vector<T>>& d){
	int len=d.size();
	rep(i,len){
		s<<d[i]<<endl;
	}
	return s;
}
template<typename T> ostream& operator<<(ostream& s,const set<T>& v){
	s<<"{ ";
	for(auto itr=v.begin();itr!=v.end();++itr) {
		if (itr!=v.begin()) {s<< ", ";}
		s<<(*itr);
	}
	s<<" }";
	return s;
}
template<typename T1, typename T2> ostream& operator<<(ostream& s,const map<T1,T2>& m){
	s<<"{"<<endl;
	for(auto itr=m.begin();itr!=m.end();++itr){
		s<<" "<<(*itr).first<<" : "<<(*itr).second<<endl;
	}
	s<<"}"<<endl;
	return s;
}

const ll mod=1e9+7;
const ll inf=1e15;
const int INF=1e9;

int n,u,v;
vector<vector<int>> g(100010);

int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	cin>>n>>u>>v;
	u--,v--;
	rep(i,n-1){
		int a,b;
		cin>>a>>b;
		a--,b--;
		g[a].push_back(b);
		g[b].push_back(a);
	}
	vector<int> dist1(n,INF),dist2(n,INF);
	dist1[u]=0;
	queue<int> que;
	que.push(u);
	while(!que.empty()){
		int x=que.front();
		que.pop();
		for(auto itr:g[x]){
			if(dist1[itr]==INF){
				dist1[itr]=dist1[x]+1;
				que.push(itr);
			}
		}
	}
	queue<int> que1;
	que1.push(v);
	dist2[v]=0;
	while(!que1.empty()){
		int x=que1.front();
		que1.pop();
		for(auto itr:g[x]){
			if(dist2[itr]==INF){
				dist2[itr]=dist2[x]+1;
				que1.push(itr);
			}
		}
	}
	int ans=-INF;
	rep(i,n){
		if(dist1[i]<dist2[i]){
			chmax(ans,dist2[i]-1);
		}
	}
	cout<<ans<<endl;
}

Measured memory_bytes: 6656
using System;

class ABC076B
{
	static public void Main(string[] args)
	{
		int N = int.Parse(Console.ReadLine());
		int K = int.Parse(Console.ReadLine());

		int val = 1;
		for(int i=0; i<N; i++)
		{
			if(val * 2 > val + K)
			{
				val = val + K;
			}
			else
			{
				val = val * 2;
			}
		}
		Console.WriteLine(val);
	}
}


Measured memory_bytes: 13140
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll mod=1e9+7;

template<typename T,T MOD,T B>
struct RollingHash{
  vector<T> hash,p;
  RollingHash(){}
  RollingHash(const string &s){
    ll n=s.size();
    hash.assign(n+1,0);
    p.assign(n+1,1);
    for(ll i=0;i<n;i++){
      hash[i+1]=(hash[i]*B+s[i])%MOD;
      p[i+1]=p[i]*B%MOD;
    }
  }
  //S[l, r)
  T find(ll l,ll r){
    T res=hash[r]+MOD-hash[l]*p[r-l]%MOD;
    return res>=MOD?res-MOD:res;
  }
};

int main() {
  string t,p;
  cin >> t >> p;
  RollingHash<ll,mod,1777771> rt(t);
  RollingHash<ll,mod,1777771> rp(p);
  for(ll i=0;i<(ll)t.size()-(ll)p.size()+1;i++) {
    if(rt.find(i,i+p.size())==rp.find(0,p.size())) {
      cout << i << endl;
    }
  }
}


Measured memory_bytes: 19820
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {

		// 入力
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();

		int[] list = new int[N];
		for (int i = 0; i < N; i++) {
			list[i] = sc.nextInt();
		}
		sc.close();

		int ans = 0;
		// 今見ている山
		for (int i = 0; i < N; i++) {

			boolean flag = true;

			for (int j = 0; j < i; j++) {
				if (list[j] > list[i]) {
					flag = false;
				}

			}
			if (flag)
				ans++;
		}
		System.out.println(ans);

	}
}


Measured memory_bytes: 22724
#include <stdio.h>
int main()
{
    int a,b,c;
    scanf("%d %d %d",&a,&b,&c);
    if (a < b){
        if (b < c){
            printf("%d %d %d\n",a,b,c);
        }else {
            if (a < c){
                printf("%d %d %d\n",a,c,b);
            }else {
                printf("%d %d %d\n",c,a,b);
            }
        }
    }else {
        if (b < c){
            if (a < c){
                printf("%d %d %d\n",b,a,c);
            }else {
                printf("%d %d %d\n",b,c,a);
            }
        }else {
            printf("%d %d %d\n",c,b,a);
        }
    }
    return 0;
}
    


Measured memory_bytes: 2140
#include <float.h>
#include <limits.h>
#include <math.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <time.h>

// 内部定数
#define D_ARRAY_MAX		100										// 最大配列数

// 内部変数
static FILE *szpFpI;											// 入力
static int si1Array[D_ARRAY_MAX];								// 配列
static int siACnt;												// 配列数
static int si1Del[D_ARRAY_MAX];									// 削除
static int siDCnt;												// 削除数

// 内部変数 - テスト用
#ifdef D_TEST
	static int siRes;
	static FILE *szpFpA;
	static int siTNo;
#endif

// １行出力
int
fOutLine(
	char *pcpLine				// <I> １行
)
{
	char lc1Buf[1024];

#ifdef D_TEST
	fgets(lc1Buf, sizeof(lc1Buf), szpFpA);
	if (strcmp(lc1Buf, pcpLine)) {
		siRes = -1;
	}
#else
	printf("%s", pcpLine);
#endif

	return 0;
}

// 実行メイン
int
fMain(
)
{
	int i;
	char lc1Buf[1024];

	// 配列数 - 取得
	fgets(lc1Buf, sizeof(lc1Buf), szpFpI);
	sscanf(lc1Buf, "%d", &siACnt);

	// 配列 - 取得
	for (i = 0; i < siACnt; i++) {
		fscanf(szpFpI, "%d", &si1Array[i]);
	}
	fgets(lc1Buf, sizeof(lc1Buf), szpFpI);

	// 削除
	while (siACnt > 0) {

		// 削除値を検索
		int liDNo = -1;
		for (i = siACnt - 1; i >= 0; i--) {
			if (si1Array[i] == i + 1) {
				liDNo = i;
				break;
			}
		}
		if (liDNo < 0) {
			return -1;
		}

		// 削除
		si1Del[siDCnt] = si1Array[i];
		siDCnt++;
		for (i = liDNo; i < siACnt - 1; i++) {
			si1Array[i] = si1Array[i + 1];
		}
		siACnt--;
	}

	return 0;
}

// １回実行
int
fOne(
)
{
	int i, liRet;
	char lc1Buf[1024];

	// データ - 初期化
	siDCnt = 0;													// 削除数

	// 入力 - セット
#ifdef D_TEST
	sprintf(lc1Buf, ".\\Test\\T%d.txt", siTNo);
	szpFpI = fopen(lc1Buf, "r");
	sprintf(lc1Buf, ".\\Test\\A%d.txt", siTNo);
	szpFpA = fopen(lc1Buf, "r");
	siRes = 0;
#else
	szpFpI = stdin;
#endif

	// 実行メイン
	liRet = fMain();

	// 出力
	if (liRet == 0) {
		for (i = siDCnt - 1; i >= 0; i--) {
			sprintf(lc1Buf, "%d\n", si1Del[i]);
			fOutLine(lc1Buf);
		}
	}
	else {
		sprintf(lc1Buf, "-1\n");
		fOutLine(lc1Buf);
	}

	// 残データ有無
#ifdef D_TEST
	lc1Buf[0] = '\0';
	fgets(lc1Buf, sizeof(lc1Buf), szpFpA);
	if (strcmp(lc1Buf, "")) {
		siRes = -1;
	}
#endif

	// テストファイルクローズ
#ifdef D_TEST
	fclose(szpFpI);
	fclose(szpFpA);
#endif

	// テスト結果
#ifdef D_TEST
	if (siRes == 0) {
		printf("OK %d\n", siTNo);
	}
	else {
		printf("NG %d\n", siTNo);
	}
#endif

	return 0;
}

// プログラム開始
int
main()
{

#ifdef D_TEST
	int i;
	for (i = D_TEST_SNO; i <= D_TEST_ENO; i++) {
		siTNo = i;
		fOne();
	}
#else
	fOne();
#endif

	return 0;
}


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

/*
Treeの問題？
というよりは累積和かな？
Aを反対から見ていって、そのときのA_iの親にA_iの値をプラスして足す
直属の部下の数だから累積でもないか…
*/

int main() {
    int N;
    cin >> N;
    vector<int> A, P;
    A = P = vector<int>(N + 1,  0);

    for (int i = 2; i <= N; i++)
    {
        // cin >> A[i];
        int a;
        cin >> a;
        P[a]++;
    }

    // for (int i = N; i >= 2; i--)
    // {
    //     P[A[i]] += P[i] + 1;
    // }

    for (int i = 1; i <= N; i++)
    {
        cout << P[i] << endl;
    }
}

Measured memory_bytes: 4756
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <cstring>
#include <queue>
#include <stack>

using namespace std;

typedef int itn;
typedef long long LL;
typedef unsigned long long ULL;
typedef vector<int> VI;
typedef vector<vector<int>> VVI;
typedef vector<LL> VL;
typedef vector<VL> VVL;
typedef map<int, int> M;
typedef pair<int, int> P;
typedef stack<int> S;
typedef queue<int> Q;
const LL MOD = 1000000007;

int main(void)
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    
    int n;
    cin >> n;
    if (n == 1) cout << "Hello World" << endl;
    else 
    {
        int a, b;
        cin >> a >> b;
        cout << a + b << endl;
    }

    return 0;
}


Measured memory_bytes: 256
//Decision's template
#include<cstdio>
#include<cstring>
#include<iostream>
#include<cstdlib>
#include<vector>
#include<queue>
#include<stack>
#include<algorithm>
#include<string>
#include<cmath>
#include<map>
#include<set>
using namespace std;

#define DP_maxn 16
#define maxn 1000000+10
#define INF 1000000007
#define mod 1000000007
#define mst(s,k) memset(s,k,sizeof(s))
#define eps 1e-12

typedef long long ll;

struct Edge{
    int from,to,dist;
    Edge(int u,int v,int d):from(u),to(v),dist(d){}
};

/*-------------------------------template End--------------------------------*/

char c;

int main(){
	cin>>c;
	if(c == 'A') cout<<'T'<<endl;
	else if(c == 'T') cout<<'A'<<endl;
	else if(c == 'C') cout<<'G'<<endl;
	else if(c == 'G') cout<<'C'<<endl;
	return 0;
}

Measured memory_bytes: 256
// inputに入力データ全体が入る
function Main(input) {
	input = input.split("\n");
       const N = parseInt(input[0]);
      if(N > 2){
console.log(180*(N-2));
}else{
console.log(0);
}
       
 }
//*この行以降は編集しないでください（標準入出力から一度に読み込み、Mainを呼び出します）
Main(require("fs").readFileSync("/dev/stdin", "utf8"));

Measured memory_bytes: 7624
#include<iostream>

#define MAX 10000

using namespace std;

int etog[MAX];

int main() {
	int i, j, n, q, com, x, y, tmpyg;

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

	for (i = 0; i < q; i++) {
		cin >> com >> x >> y;
		if (com == 0) {
			tmpyg = etog[y];
			for (j = 0; j < n; j++) {
				if (etog[j] == tmpyg)etog[j] = etog[x];
			}
		} else {
			if (etog[x] == etog[y])cout << 1 << endl;
			else cout << 0 << endl;
		}
	}
	return 0;
}

Measured memory_bytes: 3124
from collections import Counter

n, m = map(int, input().split())

L = []
cnt = 0

for _ in range(n):
    tmp = input().split()
    a = tmp[1:]
    L.extend(a)
    
c = Counter(L)
for k, v in c.items():
    if v==n:
        cnt += 1
print(cnt)

Measured memory_bytes: 3316
#include <bits/stdc++.h>
using namespace std;
const long long mod = pow(10, 9) + 7;
const long long INF = 1LL << 60;
template <class T> bool chmin(T& a, T b){if (a > b) {a = b; return true;} return false;}
template <class T> bool chmax(T& a, T b){if (a < b) {a = b; return true;} return false;}
int divCeil(int A, int B) {return (A + (B - 1)) / B;}
long long divCeil(long long A, int B) {return (A + (B - 1)) / B;}
long long divCeil(int A, long long B) {return (A + (B - 1)) / B;}
long long divCeil(long long A, long long B) {return (A + (B - 1)) / B;}

int main()
{
  int W, H, N;
  cin >> W >> H >> N;
  vector<int> x(N), y(N), a(N);
  for (int i = 0; i < N; i++) cin >> x.at(i) >> y.at(i) >> a.at(i);
  
  vector<vector<int>> xy(H, vector<int>(W, 0));
  for (int i = 0; i < N; i++)
  {
    if (a.at(i) == 1)
    {
      for (int j = 0; j < H; j++)
      {
        for (int k = 0; k < x.at(i); k++)
        {
          xy.at(j).at(k) = 1;
        } 
      }
    }
    else if (a.at(i) == 2)
    {
      for (int j = 0; j < H; j++)
      {
        for (int k = W - 1; k >= x.at(i); k--)
        {
          xy.at(j).at(k) = 1;
        } 
      }
    }
    else if (a.at(i) == 3)
    {
      for (int j = 0; j < y.at(i); j++)
      {
        for (int k = 0; k < W; k++)
        {
          xy.at(j).at(k) = 1;
        } 
      }
    }
    else if (a.at(i) == 4)
    {
      for (int j = H - 1; j >= y.at(i); j--)
      {
        for (int k = 0; k < W; k++)
        {
          xy.at(j).at(k) = 1;
        } 
      }
    }
  }
  
  int ans = 0;
  for (int i = 0; i < H; i++)
  {
    for (int j = 0; j < W; j++)
    {
      //cout << xy.at(i).at(j) << " ";
      if (xy.at(i).at(j) == 0) ans++;
    }
    //cout << endl;
  }
  
  cout << ans << endl;
}

Measured memory_bytes: 256
# 最初の文字列を基準に各文字と数をマップして、次からは使える文字を使えるだけ使うことにして減らしていく
n = gets.chomp.to_i
table = {}
gets.chomp.chars.each do |c|
  if table.has_key?(c)
    table[c]+=1
  else
    table[c]=1
  end
end
(n-1).times do
  # 基準になってるやつと共通するやつだけ考えればいい
  table_share = {}
  gets.chomp.chars.each do |c|
    if table.has_key?(c)
      if table_share.has_key?(c)
        table_share[c]+=1
      else
        table_share[c]=1
      end
    end
  end
  # 共通するやつの数を少ない方に合わせる
  table.keys.each do |k|
    if table_share.has_key?(k)
      # ここミスって1WA
      table[k] = [table[k], table_share[k]].min
    else
      table[k] = 0
    end
  end
end

# 残ったやつから辞書順で最小のやつを作る
ans = ""
table.keys.sort.each do |k|
  ans += k*table[k]
end
puts ans

Measured memory_bytes: 1788
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

int top, S[1000];

void push(int x)
{
    S[++top] = x;
}

int pop() {
    top--;
    return S[top + 1];
}


int main(int argc, char const *argv[])
{
    top = 0;
    int a, b;
    char s[100];
    while (scanf("%s", s) != EOF) {
        if (s[0] == '+') {
            b = pop();
            a = pop();
            push(a + b);
        } else if (s[0] == '-') {
            b = pop();
            a = pop();
            push(a - b);
        } else if (s[0] == '*') {
            b = pop();
            a = pop();
            push(a * b);
        } else {
            push(atoi(s));
        }
    }
    
    printf("%d\n", pop());

    return 0;
}



Measured memory_bytes: 2104
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int h, n; cin>>h>>n;
    int a[n];
    for(int i = 0; i < n; i++) cin>>a[i];
    sort(a, a + n);
    for(int i = n - 1; i >= 0; i--)
    {
        h -= a[i];
        if(h <= 0)
        {
            cout<<"Yes"<<'\n';
            return 0;
        }
    }
    cout<<"No"<<'\n';
    return 0;
}

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

#define fast_io ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);

using namespace std;

#define debug(x) cout<<(#x)<<"="<<(x)<<", ";
#define debug1(x) debug(x) cout<<'\n';
#define debug2(x1, x2) debug(x1) debug(x2) cout<<'\n';
#define debug3(x1, x2, x3) debug(x1) debug(x2) debug(x3) cout<<'\n';
#define debug4(x1, x2, x3, x4) debug(x1) debug(x2) debug(x3) debug(x4) cout<<'\n';
#define debug5(x1, x2, x3, x4, x5) debug(x1) debug(x2) debug(x3) debug(x4) debug(x5) cout<<'\n';

#define fcout cout<<fixed<<setprecision(15)
#define rep(i,j,k) for(int i=j; i<k; ++i)
#define rrep(i,j,k) for(int i=j; i>=k; --i)
#define all(x) (x).begin(), (x).end()
#define sortr(x) sort(x.begin(), x.end())
#define lb(x,val) lower_bound(x.begin(), x.end(), val)
#define ub(x,val) upper_bound(x.begin(), x.end(), val)
#define pb(x) emplace_back(x);

typedef long long int lli;
typedef pair<int,int> pii;
typedef pair<lli,lli> pll;
typedef vector<int> vi;
typedef vector<lli> vl;
typedef tuple<int, int, lli> tiil;

//const lli M=998244353ll;
const lli M=1000000007ll;

int main(){
	fast_io 
	string a,b; cin>>a>>b;
	int c,d; cin>>c>>d;
	string g;cin>>g;
	if(g==a) c--;
	else d--;
	cout<<c<<" "<<d;
	
	
	return 0;
}

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

int main(){
    std::ios_base::sync_with_stdio(0);  cin.tie(NULL);  cout.tie(NULL);
    long long  n ;
    cin >> n ;
    cout << n * (n + 1 ) / 2 ;
    return 0 ;
}

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

int main() {
    ll n,kkk;
    cin>>n>>kkk;
    V a(n);
    rep(i,n)cin>>a[i];
    ll logn=floor(log2(kkk));
    VV next(n,V(logn+1));
    rep(i,n)next[i][0]=a[i]-1;
    for(ll k=0;k<logn;k++){
        for(ll i=0;i<n;i++){
            next[i][k+1]=next[next[i][k]][k];
        }
    }
    ll p=0;
    for(ll k=logn;k>=0;k--){
        if((kkk>>k)&1){
            p=next[p][k];
        }
    }
    cout<<p+1<<endl;
}


Measured memory_bytes: 106624
#include<iostream>
#include <bits/stdc++.h>
#include <string>
#include <vector>
#include <algorithm>
using namespace std;

int main() {

    int x,a,b ;
    cin >> x >> a >> b ;
  
    x-= a ;
    x = x - (x/b)*b ;

    cout << x << endl ;

	return 0;
}



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

int main(){
        int a, b, c;
        scanf ("%04d/%02d/%02d", &a, &b, &c);

        if(a >= 2020){
                printf("TBD\n");
        }
        if(a <= 2018){
                printf("Heisei\n");
        }else if(a == 2019){
                if(b <= 04){
                        if(c <= 30){
                                printf("Heisei\n");
                        }else{
                                printf("TBD\n");
                        }
        }else if(b >= 05){
                printf("TBD\n");
                }
        }
        return 0;
}



                

Measured memory_bytes: 256
#include <stdio.h>
#include <math.h>
#include <string.h>
#include <iostream>
using namespace std;

int main(){
    int n, m, c;
    cin>>n>>m>>c;
    int b[m];
    int a[n][m];
    int ans=0;
    int betu = 0;
    for(int i=0; i<m; i++){
        cin>>b[i];
    }
    for(int i=0; i<n; i++){
        for(int j=0; j<m; j++){
            cin>>a[i][j];
        }
    }
    for(int i=0; i<n; i++){
        for(int j=0; j<m; j++){
            betu += b[j] * a[i][j];
        }
        betu += c;
        if(betu>0){
            ans++;
        }
        betu = 0;
    }
    cout<<ans<<endl;


    return 0;
}

Measured memory_bytes: 256
import qualified Data.Vector.Unboxed as U
main :: IO ()
main = do
    [k, n] <- map read . words <$> getLine :: IO [Int]
    getLine >>= print . solve k . U.fromList . map (read :: String -> Int). words

solve :: Int -> U.Vector Int -> Int
solve k xs = (k-) . U.foldl' max (k - U.last xs + U.head xs) $ U.zipWith (-) (U.tail xs) xs


Measured memory_bytes: 64400
#include <iostream>
#include<algorithm>
#include <stdio.h>
#include <string>
#include <string.h>
#include <map>
#include <math.h>
#include <vector>
#include <set>
#include <map>
#include <deque>
//#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N=1e3+7;
int gcd(int a,int b)
{
    return b?gcd(b,a%b):a;
}
map<int,int>mp;
int p[11],k[11],s[11][11];
int get_bit(int x,int i){return (x>>i)&1;}
int main()
{
    int n,m;
    cin>>n>>m;
    for(int i=0;i<m;i++) {
        scanf("%d",&k[i]);
        for (int j = 0; j <k[i];j++)
            scanf("%d",&s[i][j]);
    }
    for(int i=0;i<m;i++)cin>>p[i];
    int sum=0;
    for(int i=0;i<(1<<n);i++)
    {
        int f=0;
        for(int r=0;r<m;r++) {
            int ans=0;
            for(int l=0;l<k[r];l++)
                if (i&(1<<(s[r][l]-1)))
                    ans++;
            if(ans%2==p[r])
            {
                f++;
            }
        }
        if(f==m)
            sum++;
    }
    cout<<sum<<endl;
    return 0;
}


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

int main() {
    int N; cin >> N;
    vector<int> t(N), x(N), y(N);
    for (int i = 0; i < N; i++) {
        cin >> t[i] >> x[i] >> y[i];
    }
    for(int i = 0; i < N; i++) {
        if(!(t[i] % 2 == 0 && (x[i]+y[i]) % 2 == 0) ) {
            if(!(t[i] % 2 == 1 && (x[i]+y[i]) % 2 == 1) ) {
                puts("No");
                return 0;
            }
        }
        if(abs(x[i]) + abs(y[i]) > t[i]) {
            puts("No");
            return 0;
        }
    }
    puts("Yes");
}


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

#define REP(i,n) for(int i = 0;i < n;i++)
#define REPR(i,n) for(int i = n-1;i >= 0;i--)
#define FOR(i,m,n) for(int i = m;i < n;i++)
#define INF 2e9
#define ALL(v) v.begin(),v.end()
#define ll long long
#define GREATER greater<int>()

using namespace std;

string pop_back(string s){
    string t = s.substr(0,s.size()-1);
    return t;
}

int gcd(int max,int min){
    
    if(max<min){
        int tmp=max;
        max=min;
        min=tmp;
    }

    if(max%min==0)return min;
    else return gcd(min,max%min);

}

int main(void){

    int n;
    cin>>n;
    for(int i=1;i<=9;i++){
        if(i*111>=n){
            cout<<i*111<<endl;
            return 0;
        }
    }

    return 0;
}




Measured memory_bytes: 256
#include<bits/stdc++.h>
#define REP(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define REPS(i,n) for(int i=1, i##_len=(n); i<i##_len; ++i)
#define all(x) (x).begin(),(x).end()
using ll = long long;
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; }
#define INF 1e9
#define PI (acos(-1))
int main() {
    int n,ni=1;
    cin>>n;
    double sum=0;
    vector<ll> x(n),y(n),v(n);
    iota(all(v),0);
    REP(i,n){
        cin>>x[i]>>y[i];
    }
    
    do{
        REP(i,v.size()-1){
            sum+=sqrt((x[v[i]]-x[v[i+1]])*(x[v[i]]-x[v[i+1]])+(y[v[i]]-y[v[i+1]])*(y[v[i]]-y[v[i+1]]));
        }
    }while(next_permutation(all(v)));
    REP(i,n){
        ni*=(i+1);
    }
    sum/=ni;
    printf("%.10lf\n",sum);
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
const int N = 305;
char s[N][N];
int dp[N][N], pre[N][N];
int main() {
	int n, m;
	scanf("%d%d", &n, &m);
	for (int i = 1; i <= n; ++ i) scanf("%s", s[i] + 1);
	int ans = 0;
	for (int l = 1; l < m; ++ l) {
		memset(dp, 0x3f, sizeof(dp));
		memset(pre, 0, sizeof(pre));
		dp[0][0] = 0;
		for (int i = 1; i <= n; ++ i) {
			for (int j = 1; j <= n; ++ j) {
				if (s[i][l] == s[j][l + 1]) {
					pre[i][j] ++;
				}
			}
		}
		for (int i = 1; i <= n; ++ i) {
			for (int j = 1; j <= n; ++ j) {
				pre[i][j] += pre[i - 1][j - 1];
			}
		}
		for (int i = 0; i <= n; ++ i) {
			for (int j = 0; j <= n; ++ j) {
				if (i + j == 0) continue;
				if (i) dp[i][j] = min(dp[i][j], dp[i - 1][j] + pre[i][j]);
				if (j) dp[i][j] = min(dp[i][j], dp[i][j - 1] + pre[i][j]);
			}
		}
		ans += dp[n][n];
	}
	printf("%d\n", ans);
}



Measured memory_bytes: 1024