akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
using namespace std;
int n;
const int INF=123456789;
const int MAX=100;
int color[MAX];
const int BLACK=2;
const int WHITE=0;
const int GRAY=1;
int d[MAX],M[MAX][MAX];

void ds(){
  int minv,u;

  d[0]=0;color[0]=GRAY;
  while(1){
    minv=INF;u=-1;
    for(int i=0;i<n;i++){
      if(minv>d[i]&&color[i]!=BLACK){
        minv=d[i];
        u=i;
      }
    }

    if(u==-1) break;
    color[u]=BLACK;

    for(int i=0;i<n;i++){
      if(M[u][i]!=INF&&color[i]!=BLACK){
        if(d[i]>d[u]+M[u][i]){
          d[i]=d[u]+M[u][i];
          color[i]=GRAY;
        }
      }
    }
  }
}

int main(){
  int u,k,v,c;
  cin>>n;
  for(int i=0;i<n;i++){
    color[i]=WHITE; d[i]=INF;
    for(int j=0;j<n;j++){
      M[i][j]=INF;
    }
  }

  for(int i=0;i<n;i++){
    cin>>u>>k;
    for(int j=0;j<k;j++){
      cin>>v>>c;
      M[u][v]=c;
    }
  }

  ds();
  for(int i=0;i<n;i++){
  if(d[i]!=INF)  cout<<i<<" "<<d[i]<<endl;
  else cout<<i<<" "<<-1<<endl;
  }
  return 0;
}

Measured memory_bytes: 3084
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ConsoleApplication6
{
    class Program
    {
        static  List<List<Int64>>lst=new List<List<Int64>>();
        static void Main(string[] args)
        {
            //var length = c2i(RL());
            var rl = spr(RL()).Select(x=>c2i(x)).ToList();
            var H1 = rl[0];
            var M1 = rl[1];
            var H2 = rl[2];
            var M2 = rl[3];
            var K  = rl[4];

            var time = (H2 - H1) * 60 + (M2 - M1) - K;
            time = time < 0 ? 0 : time;
            Console.WriteLine(time);

        
        }
        
        static string RL() { return Console.ReadLine().Trim(); }
        static IEnumerable<string> spr(string s) { return s.Split(' '); }
        static Int64 c2i(string c) { return Int64.Parse(c); }
        //static double c2d(string c) { return double.Parse(c); }
        static string bool2ret(bool b) { return b ? "Yes" : "No"; }
    }
}


Measured memory_bytes: 28264
#include <iostream>
#include <fstream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <numeric>
#include <type_traits>

using namespace std;

int main(int argc, const char * argv[]) {
  int n, m;
  cin >> n >> m;
  vector<int> x(m);
  if(n >= m){
    cout << 0 << endl;
    return 0;
  }
  for(int i = 0; i < m; i++){
    cin >> x[i];
  }
  sort(x.begin(), x.end());
  vector<int> d(m-1);
  for(int i = 0; i < m-1; i++){
    d[i] = x[i+1] - x[i];
  }
  sort(d.begin(), d.end());
  int ans = 0;
  for(int i = 0; i < d.size() - n + 1; i++){
    ans += d[i];
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 1024
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		int[] nums = new int[N];

		for (int i = 0; i < N; i++) {
			nums[i] = sc.nextInt();
		}
		if (nums.length == 1) {
			System.out.println("Yes");
		}else {
			int lim = nums[0];
			for (int i = 1; i < N; i++) {
				if (nums[i] < lim) {
					System.out.println("No");
					break;
				}
				if (nums[i-1] - nums[i] < -1) {
					lim = nums[i]-1;

				}
				if (i == N-1) {
					System.out.println("Yes");
					break;
				}

			}
		}
	}
}




Measured memory_bytes: 59604
#include <iostream>
#include <algorithm>
#include <utility>
#include <vector>
#include <numeric>

template <class T, class U>
inline bool chmin(T &lhs, const U &rhs) {
  if (lhs > rhs) {
    lhs = rhs;
    return true;
  }
  return false;
}

template <class T, class U>
inline bool chmax(T &lhs, const U &rhs) {
  if (lhs < rhs) {
    lhs = rhs;
    return true;
  }
  return false;
}

int main() {
  int N, M, Q;
  std::cin >> N >> M >> Q;
  std::vector<int> A(Q), B(Q), C(Q), D(Q);
  for (int i = 0; i < Q; ++i) {
    std::cin >> A[i] >> B[i] >> C[i] >> D[i];
    --A[i]; --B[i];
  }
  std::vector<int> vec(N + M - 1);
  std::fill(vec.begin() + M - 1, vec.end(), 1);
  int ans = 0;
  do {
    std::vector<int> val(N);
    {
      std::array<int, 2> cnt{};
      for (auto x: vec) {
        if (x == 1) {
          val[cnt[1]] = cnt[0];
        }
        ++cnt[x];
      }
    }
    int sum = 0;
    for (int i = 0; i < Q; ++i) {
      if (val[B[i]] - val[A[i]] == C[i]) {
        sum += D[i];
      }
    }
    chmax(ans, sum);
  } while (std::next_permutation(vec.begin(), vec.end()));
  std::cout << ans << '\n';
  return 0;
}


Measured memory_bytes: 3632
L ,R = list(map(int, input().split()))

diff = R - L
min_mod = 2020
second_min_mod = 2021
for i in range(L, min(L+2019, L+(diff)+1)):
    for j in range(i+1, min(L+2019, L+(diff)+1)):
        if min_mod > (i*j) % 2019:
            min_mod = (i*j) % 2019
print(min_mod)


Measured memory_bytes: 3060
#include<stdio.h>
#define rep(i,N) for(int i=0;i<(int)N;i++)
#pragma GCC optimize("O3")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
static inline int IN(void)
{
  int x=0,f=0,c=getchar();while(c<48||c>57){f^=c==45,c=getchar();}
  while(c>47&&c<58){x=x*10+c-48,c=getchar();}return f?-x:x;
}
static inline int GCD(int a,int b){return !b?a:GCD(b,a%b);}
const int Primes[168]=
{2,3,5,7,11,13,17,19,23,29,31,37,41,43,47,53,59,61,67,71,73,79,83,89,
 97,101,103,107,109,113,127,131,137,139,149,151,157,163,167,173,179,181,191,193,197,199,211,223,
 227,229,233,239,241,251,257,263,269,271,277,281,283,293,307,311,313,317,331,337,347,349,353,359,
 367,373,379,383,389,397,401,409,419,421,431,433,439,443,449,457,461,463,467,479,487,491,499,503,
 509,521,523,541,547,557,563,569,571,577,587,593,599,601,607,613,617,619,631,641,643,647,653,659,
 661,673,677,683,691,701,709,719,727,733,739,743,751,757,761,769,773,787,797,809,811,821,823,827,
 829,839,853,857,859,863,877,881,883,887,907,911,919,929,937,941,947,953,967,971,977,983,991,997};
const char common[]="not coprime",disjoint[]="pairwise coprime",several[]="setwise coprime";
char esc[1000000];
static inline int Divide(int x)
{
  if(!x){return 0;}
  rep(i,168)
  {
    if(Primes[i]*Primes[i]>x)break;
    if(x%Primes[i])continue;
    if(esc[Primes[i]-1])return 0;
    esc[Primes[i]-1]=1;
    while(x%Primes[i]==0&&x)x/=Primes[i];
  }
  if(x>1){if(esc[x-1])return 0;esc[x-1]=1;}
  return 1;
}
int main(void)
{
  int N=IN(),A=0,f=0,g=0,last=0,penultimate=0;
  rep(i,N)
  {
    A=IN();g=GCD(g,A);if(i&&g!=1){f=1;}if(penultimate&&GCD(penultimate,A)>1){f=1;}
    penultimate=last;last=A;if(f)continue;else{if(!Divide(A))f=1;}
  }
  if(g>1)return puts(common),0;else{if(f)return puts(several),0;else return puts(disjoint),0;}
}

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

int main(){
  int n,cnt=0;
  string c = "YES";
  cin >> n;
  int a[n];
  for(int i=0;i<n;i++)
    cin >> a[i];
  for(int i=0;i<n;i++){
    if(a[i]!=i+1)
      cnt++;
  }
  if(cnt>2)
    c = "NO";
  cout << c << endl;
}

Measured memory_bytes: 256
import numpy as np

n = int(input())
A = np.array(list(map(int,input().split())))
minus = np.count_nonzero(A < 0)
A = np.abs(A)

if minus % 2 == 0:
  print(np.sum(A))
else:
  print(np.sum(A) - 2 * np.min(A))

Measured memory_bytes: 38164
def getN():
    return int(input())
def getNM():
    return map(int, input().split())
def getList():
    return list(map(int, input().split()))
def getArray(intn):
    return [int(input()) for i in range(intn)]
def input():
    return sys.stdin.readline().rstrip()
def rand_N(ran1, ran2):
    return random.randint(ran1, ran2)
def rand_List(ran1, ran2, rantime):
    return [random.randint(ran1, ran2) for i in range(rantime)]
def rand_ints_nodup(ran1, ran2, rantime):
  ns = []
  while len(ns) < rantime:
    n = random.randint(ran1, ran2)
    if not n in ns:
      ns.append(n)
  return sorted(ns)

def rand_query(ran1, ran2, rantime):
  r_query = []
  while len(r_query) < rantime:
    n_q = rand_ints_nodup(ran1, ran2, 2)
    if not n_q in r_query:
      r_query.append(n_q)
  return sorted(r_query)

from collections import defaultdict, deque, Counter
from sys import exit
from decimal import *
import heapq
import math
from fractions import gcd
import random
import string
import copy
from itertools import permutations
from operator import mul
from functools import reduce
from bisect import bisect_left, bisect_right

import sys
sys.setrecursionlimit(1000000000)
mod = 10 ** 9 + 7


#############
# Main Code #
#############

N, K = getNM()
A = getList()
lista = [[0, 0] for i in range(61)]
# bitの各桁が１か０かをlistaに収納
def splitbit(n):
    for i in range(61):
        if n & (1 << i):
            lista[i][0] += 1
        else:
            lista[i][1] += 1
for i in A:
    splitbit(i)

ans = 0
cnt = 0
for i in range(60, -1, -1):
    if lista[i][1] > lista[i][0] and cnt + 2 ** i <= K:
        cnt += 2 ** i
        ans += lista[i][1] * 2 ** i
    else:
        ans += lista[i][0] * 2 ** i
print(ans)

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

int main(){
    int N;
    long long ans;
    cin >> N;
    ans = 1;
    for (int i = 0; i < N; i++){
        ans = (ans * (i + 1)) % (1000000000 + 7);
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
S=input()

if "RRR"==S:
    print(3)
elif "RSR"==S:
    print(1)
elif "SRS"==S:
    print(1)
elif "RRS"==S or "SRR"==S:
    print(2)
elif "SSS"==S:
    print(0)
else:
    print(1)

Measured memory_bytes: 61576
#include<iostream>
#include<stdio.h>
#include<string.h>
#include<algorithm>
#include<vector>
#include<queue>
#include<map>
#include<set>
#include<iomanip>
#include<cmath>



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

using namespace std;
int n;
int a[300];

int main(){
  cin >> n;
  REP(i,n) cin >> a[i];
  sort(a,a+n);
  cout << a[n-1]-a[0] << endl;
  return 0;
}


Measured memory_bytes: 256
m,d = map(int,input().split())
count = 0

for i in range(1,m+1):
    for j in range(10,d+1):
        a = list(str(j))
        if  int(a[0]) >= 2 and int(a[1]) >= 2 and int(a[0]) * int(a[1]) == i:
            count += 1
print(count)

Measured memory_bytes: 9060
import java.util.HashMap;
import java.util.Map;
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = Integer.parseInt(sc.next());
        Map<Integer, Integer> map = new HashMap<>();
        for (int i = 0; i < n; i++) {
            int temp = Integer.parseInt(sc.next());
            if (map.containsKey(temp)) {
                System.out.println("NO");
                return;
            } else {
                map.put(temp, 1);
            }
        }
        System.out.println("YES");
    }
}


Measured memory_bytes: 68448
n = int(input())
a = list(map(int, input().split()))
l = sum(a)
h = l/2
b, c = 0, 0
ans = 0
for i in a:
    b = c
    c += i
    if c == h:
        print(0)
        break
    if h < c:
        ans = c-l+c if c-h<h-b else l-b-b
        print(ans)
        break

Measured memory_bytes: 26220
import heapq

n, m = map(int, input().split())
a = [int(i) * (-1) for i in input().split()]
heapq.heapify(a)
for _ in range(m):
    heapq.heappush(a, heapq.heappop(a) * (-1) // 2 * (-1))
print(-sum(a))


Measured memory_bytes: 14180
from collections import deque
def rad_reach(bfr,h,rest,E):
	cnt = 0
	Q = deque([(bfr,h,rest)])
	while Q:
		cnt += 1
		bfr,h,rest = Q.popleft()
		if rest > 0:
			for nxt in E[h]:
				if nxt == bfr:
					continue
				Q.append((h,nxt,rest-1))
	return cnt
def solve():
	N,K = map(int,raw_input().split())
	pairs = []
	E = [[] for i in xrange(N)]
	for i in xrange(N-1):
		p = map(lambda x:int(x)-1,raw_input().split())
		pairs.append(p)
		E[p[0]].append(p[1])
		E[p[1]].append(p[0])
	ans = N
	rad = K/2
	if K % 2 == 0:
		for c in xrange(N):
			ans = min(ans,N-rad_reach(-1,c,rad,E))
	else:
		for c1,c2 in pairs:
			ans = min(ans,N-rad_reach(c2,c1,rad,E)-rad_reach(c1,c2,rad,E))
	print ans
solve()

Measured memory_bytes: 3696
#include <bits/stdc++.h>
#define ll long long
#define MODV 1000000007
#define INF INT_MAX // 2147483647
#define INFLL LLONG_MAX // 9223372036854775807
#define rep(i, n) for(ll i=0, i##_len=(ll)(n); i<i##_len; i++)
#define repf(i, n) for(ll i=1, i##_len=(ll)(n+1); i<i##_len; i++)
#define per(i, n) for(ll i=((ll)(n))-1; i>=0; i--)
#define perf(i, n) for(ll i=((ll)(n)); i>0; i--)
#define all(v) v.begin(), v.end()
#define endl "\n"
#define vi vector<ll>
#define vvi vector<vector<ll>>
#define Yes() cout << "Yes" << endl
#define YES() cout << "YES" << endl
#define No() cout << "No" << endl
#define NO() cout << "NO" << endl
template<class T>bool chmax(T &a, const T &b){ if(a<b){ a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b){ if(b<a){ a=b; return 1; } return 0; }
using namespace std;

int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout << fixed << setprecision(10);
    ll a, b; cin >> a >> b;
    cout << max(a+(a-1), max(a+b, b+(b-1))) << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <vector>
#include <cmath>
#define rep(i, n) for(int i = 0; (i) < (n); (i)++)

using namespace std;

int main() {
    int n,m;
    cin >> n >> m;
    char a[n][m],b[n][m];
    rep(i,n) rep(j,m) cin >> a[i][j];
    rep(i,n) rep(j,m) cin >> b[i][j];

    int cnt = 0;
    rep(i,n) rep(j,m) if(a[i][j] != b[i][j]) cnt++;
    cout << cnt << endl;
}


Measured memory_bytes: 10888
import java.util.Scanner;


public class Main {
	
    public static void main(String[] args) {

        Scanner sc = new Scanner(System.in);
        
        long X = sc.nextLong();
        long max = 1;
        
        for(long i=2;i*i<=X;i++){
        	
        	long pow = i*i;
        	
        	for(;pow<=X;pow *= i)
        		if(max<pow)
        			max = pow;
        	
        }
        
        System.out.println(max);
		
	}


		

    
}

Measured memory_bytes: 21844
#include<iostream>
#include<cmath>
#include<algorithm>
#include<string>
#include<vector>
#include<stack>
#include<queue>
#include<set>
#include<map>
#include<iomanip>
#include<bitset>
using namespace std;
typedef long long ll;
typedef pair<ll,ll> P;
typedef pair<ll,P> P1;
typedef pair<P,P> P2;
#define pu push
#define pb push_back
#define mp make_pair
#define eps 1e-7
#define INF 1000000000
#define fi first
#define sc second
#define rep(i,x) for(ll i=0;i<x;i++)
#define repn(i,x) for(ll i=1;i<=x;i++)
#define SORT(x) sort(x.begin(),x.end())
#define ERASE(x) x.erase(unique(x.begin(),x.end()),x.end())
#define POSL(x,v) (lower_bound(x.begin(),x.end(),v)-x.begin())
#define POSU(x,v) (upper_bound(x.begin(),x.end(),v)-x.begin())

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

// 最長増加部分列の長さを求める
int LIS(const vector<long long> &a) {
    int N = (int)a.size();
    vector<long long> dp(N, INF);
    for (int i = 0; i < N; ++i) {
        // dp[k] >= a[i] となる最小のイテレータを見つける
        auto it = lower_bound(dp.begin(), dp.end(), a[i]);

        // そこを a[i] で書き換える
        *it = a[i];
    }

    // dp[k] < INF となる最大の k に対して k+1 が答え
    // それは dp[k] >= INF となる最小の k に一致する
    return lower_bound(dp.begin(), dp.end(), INF) - dp.begin();
}

int main() {
    int N; cin >> N;
    vector<long long> a(N);
    for (int i = 0; i < N; ++i) cin >> a[i];
    cout << LIS(a) << endl;
}



Measured memory_bytes: 4384
#include <iostream>
#include <vector>
#include <queue>
using namespace std;

static const int MAX = 100000;
static const int INFTY = (1<<20);
int n;
int d[MAX];

class Edge {
 public:
  int t, w;
  Edge(){}
  Edge(int t, int w): t(t), w(w) {}
};

vector<Edge> G[MAX];

void bfs(int s) {
  for (int i = 0; i < n; i++) {
    d[i] = INFTY;
  }
  queue<int> Q;
  Q.push(s);
  d[s] = 0;
  while (!Q.empty()) {
    int u = Q.front(); Q.pop();
    for (int i = 0; i < G[u].size(); i++) {
      Edge e = G[u][i];
      if (d[e.t] == INFTY) {
        d[e.t] = d[u] + e.w;
        Q.push(e.t);
      }
    }
  }
}

void solve() {
  bfs(0);
  int maxv = 0;
  int target;
  for (int i = 0; i < n; i++) {
    if (d[i] == INFTY) continue;
    if (maxv < d[i]) {
      maxv = d[i];
      target = i;
    }
  }
  bfs(target);
  maxv = 0;
  for (int i = 0; i < n; i++) {
    if (d[i] == INFTY) continue;
    maxv = max(maxv, d[i]);
  }
  cout << maxv << endl;
}

int main() {
  cin >> n;
  for (int i = 0; i < n-1; i++) {
    int s, t, w;
    cin >> s >> t >> w;
    G[s].push_back(Edge(t, w));
    G[t].push_back(Edge(s, w));
  }
  solve();
  return 0;
}



Measured memory_bytes: 9824
import sys
input = sys.stdin.buffer.readline

#sys.setrecursionlimit(10**9)
#from functools import lru_cache

def RD(): return sys.stdin.read()
def II(): return int(input())
def MI(): return map(int,input().split())
def MF(): return map(float,input().split())
def LI(): return list(map(int,input().split()))
def LF(): return list(map(float,input().split()))
def TI(): return tuple(map(int,input().split()))
# rstrip().decode()

def main():
	x=II()
	q,r=divmod(x,11)
	ans=0
	if r==0:
		ans-=1


	ans+=2*q+1+(r>6)

	print(ans)


if __name__ == "__main__":
	main()


Measured memory_bytes: 61948
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <cmath>
#define pi 3.14159265358979323846264338327950

int main() {
	int N, M; std::cin >> N >> M;

	//高さの入力
	std::vector<int> H(N);
	for (auto& r : H) std::cin >> r;

	//道の入力
	std::vector<int> A(M);
	std::vector<int> B(M);
	for (auto i{ 0 }; i < M; ++i)
		std::cin >> A[i] >> B[i];

	std::vector<bool> flag(N);
	std::fill(flag.begin(), flag.end(), true);
	int count{ 0 };
	for (auto i{ 0 }; i < M; ++i) {
		if (H[A[i]-1] == H[B[i]-1]) {
			flag[A[i]-1] = false;
			flag[B[i]-1] = false;
		}
		else if (H[A[i]-1] < H[B[i]-1])
			flag[A[i]-1] = false;
		else
			flag[B[i]-1] = false;
	}
	for (bool b : flag)
		if (b)
			++count;

	std::cout << count << std::endl;

	return 0;
}

Measured memory_bytes: 4560
#include <stdlib.h>
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
template<class T> inline bool chmin(T& a, T b) {
    if (a >= b) {
        a = b;
        return true;
    }
    return false;
}
template<class T> inline bool chmax(T& a, T b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;   
}

int main() {
    string s;
    cin>>s;
    if(s=="Cloudy"){
        cout<<"Rainy"<<endl;
    }
    if(s=="Rainy"){
        cout<<"Sunny"<<endl;
    }
    if(s=="Sunny"){
        cout<<"Cloudy"<<endl;
    }
        
}





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

std::string func(std::string str,int x){
  std::string ret;
	while( --x ){
		ret+=str;
	}
	return ret;
}
int main(){
	std::vector<int>::iterator Result;
	std::vector<int> mod;
 	int p,q;
  while(std::cin>>p>>q){
		mod.clear();
		bool End=false;
		while(1){
			if(p==0)break;
			std::cout<<(p*10)/q;
			mod.push_back(p);
			if(mod.size()>80)break;
			if( ( Result=std::find(mod.begin(), mod.end(), (p*10)%q ) ) !=mod.end() ){End=true;break;}
			p=(p*10)%q;
		}
		std::cout<<std::endl;
		if(End)std::cout<<func(" ",Result-mod.begin()+1)<<func("^",mod.size()-(Result-mod.begin())+1)<<std::endl;
	}
	return 0;
}

Measured memory_bytes: 1236
#include<bits/stdc++.h>
using namespace std;
int main(){
        long long n; cin>>n; string str="";
        while(n){
                int rem=n%26;
                if(!rem) str='z'+str;
                else str=(char)(97+rem-1)+str;
                n/=26;
                if(!rem) n--;
        }
        cout<<str<<endl;
}


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

using namespace std;

#define sz(v)           ((int)((v).size()))
#define clr(v, d)       memset(v, d, sizeof(v))
#define rep(i, v)       for(int i=0; i<sz(v); ++i)
#define lp(i, n)        for(int i=0; i<(int)(n); ++i)
#define lpi(i, j, n)    for(int i=(j); i<(int)(n); ++i)
#define lpd(i, j, n)    for(int i=(j); i>=(int)(n); --i)
#define INF             1000000000


typedef long long ll;
typedef pair<int, int> ii;
typedef vector<ii> vii;
typedef vector<int> vi;

const int N = 23;
const int MAX = (1 << 21);
const int MOD = 1e9+7;

int n;
int dp[MAX][N];

bool arr[N][N];

int solve(int pairs, int idx){
	if(idx == n && pairs != (1 << n)-1)
		return 0;
	if(idx == n){
	    return 1;
	}
	int & cur = dp[pairs][idx];
	if(~cur)
		return cur;
	cur = 0;
	lp(i, n)
	    if(arr[idx][i] && ((pairs & (1 << i)) == 0))
	        (cur += solve(pairs | (1 << i), idx+1)) %= MOD;
	return cur = cur % MOD;
}

int main()
{
	clr(dp, -1);
    cin >> n;
    lp(i, n)
        lp(j, n)
    	    cin >> arr[i][j];
    cout << solve(0, 0);
    return 0;
}


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

	int main() {
		int N; cin >> N;  // お餅の枚数
		vector<int> d(N); // お餅の直径
		rep(i,N){cin >> d.at(i);}
		int Ans = 0;      // 戻り値：異なる数値の数

		// お餅の直径を昇順に並べ替え
		sort(d.begin(),d.end());

		int pre = 0;  // 前のお餅の直径
		rep(i,N){
			if ( d.at(i) != pre ) {	// 直径が異なる場合、枚数加算
				Ans += 1;
				pre = d.at(i);
			}
		}

	    cout << Ans << endl;
	}

Measured memory_bytes: 256
//BISMILLAHIR RAHMANIR RAHIM
#include <bits/stdc++.h>
#define mem(a, b) (memset(a, b, sizeof(a)))
#define pb push_back
#define mk make_pair
#define ff first
#define ss second
#define PI acos(-1)
#define INF 2147483647
#define MOD 1000000007
#define MAX 100005
using namespace std;

typedef long long ll;
typedef vector<int> vi;
typedef pair<int, int> ii;
typedef pair<int, ii> pii;
typedef vector<ii> vii;
typedef priority_queue<int,vector<int>,greater<int> > PQ;

int Set(int mask, int pos){return mask = mask | (1<<pos);}
bool check(int mask, int pos){return (bool)(mask & (1<<pos));}

int main()
{
    ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
    int x, n;

    cin>>x>>n;

    int sum = 0;
    for(int i = 0; i < n; i++){
        int val;
        cin>>val;
        sum += val;
    }

    if(sum >= x){
        cout<<"Yes"<<endl;
    }
    else{
        cout<<"No"<<endl;
    }

    return 0;
}


Measured memory_bytes: 256
n,k = map(int,input().split())
arr = list(map(int,input().split()))

visited = set()
visited.add(0)
now = 0
root = [-1 for i in range(n+1)]
root[0] = 0
ind = 1
cnt = 0
first_seen = {}
first_seen[0] = 0

finished = False
while True:
    goto = arr[now]-1
    # print(goto)
    if goto not in visited:
        visited.add(goto)
        now = goto
        root[ind] = goto
        ind += 1
        cnt += 1
        first_seen[goto] = cnt
    else:
        root[ind] = goto
        cnt += 1
        now = goto
        break

    if cnt == k:
        finished = True
        break

if finished:
    print(now+1)
else:
    # print(now)
    # print(first_seen)
    pathl = cnt-first_seen[now]
    # print(cnt,first_seen[now])
    # print(pathl)
    left = k-cnt
    left = left%pathl
    fin = first_seen[now] + left
    # print(root)
    print(root[fin]+1)


Measured memory_bytes: 139776
#include <iostream>
#include <iomanip>
#include <sstream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <climits>
#include <cfloat>
#include <vector>
#include <string>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <algorithm>
#include <functional>
#include <utility>
#include <numeric>
#include <iterator>

using namespace std;

typedef long long LL;
typedef unsigned long long ULL;
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int,int> PII;
typedef istringstream ISS;
typedef ostringstream OSS;

#define REP( i, m, n ) for ( int i = (int)( m ); i < (int)( n ); ++i )
#define FOR( v, c ) for ( auto &v : c )

#define EACH( it, c ) for ( auto it = c.begin(); it != c.end(); ++it )
#define ALL( c ) (c).begin(), (c).end()
#define DRANGE( c, p ) (c).begin(), (c).begin() + p, (c).end()

#define PB( n ) push_back( n )
#define MP( a, b ) make_pair( ( a ), ( b ) )
#define EXIST( c, e ) ( (c).find( e ) != (c).end() )

#define fst first
#define snd second

#define DUMP( x ) cerr << #x << " = " << ( x ) << endl
#define DEBUG( x ) cerr << __FILE__ << ":" << __LINE__ << ": " << #x << " = " << ( x ) << endl

struct Edge
{
	int from, to;
	string label;
	
	Edge() {}
	Edge( int f, int t, string l ) : from( f ), to( t ), label( l )
	{
	}
};

string solve( int n, int m, int s, int g )
{
	vector< Edge > G( m );
	FOR( e, G )
	{
		cin >> e.from >> e.to >> e.label;
	}

	VS distance( n, "~" );
	distance[g] = "";

	REP( times, 0, n * 10 )
	{
		REP( i, 0, m )
		{
			Edge &e = G[i];
			if ( distance[ e.to ] == "~" )
			{
				continue;
			}
			distance[ e.from ] = min( distance[ e.from ], e.label + distance[ e.to ] );
		}
	}

	return n * 6 < distance[s].size() || distance[s] == "~" ? "NO": distance[s];
}

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

	while ( true )
	{
		int n, m, s, g;
		cin >> n >> m >> s >> g;

		if ( !( n | m | s | g ) )
		{
			break;
		}

		cout << solve( n, m, s, g ) << endl;
	}

	return 0;
}

Measured memory_bytes: 1968
#include <iostream>
using namespace std ;
int main(){
	int b[1000] , a[1000][100] , c , i = 1 , x , g , y , h = 1 , u = 0 ;
	cin >> x >> y ;
	for ( i = 1 ; i <= x ; i ++ ){
		for ( g = 1 ; g <= y ; g ++ ){
			cin >> a[i][g] ;
		}
	}
	for ( i = 1 ; i <= y ; i ++ ){
		cin >> b[i] ;
	}
	for ( i = 1 ; i <= x ; i ++ ){
		u = 0 ;
		for ( g = 1 ; g <= y ; g ++ ){
  			u += ( a[i][g] * b[g] ) ;
  		}
  		cout << u << endl ;
	}
	}

Measured memory_bytes: 1204
#include <bits/stdc++.h>
#define BASE 1000000007
using namespace std;

int main() {
    int n, k;
    cin >> n >> k;
    long dp[n + 1][k + 1];
    dp[0][0] = 1;
    fill(dp[0] + 1, dp[0] + k + 1, 0);
    for (int i = 1; i <= n; i++) {
        dp[i][0] = 1;
    }
    for (int i = 1; i <= n; i++) {
        for (int j = 1; j <= k; j++) {
            dp[i][j] = (dp[i - 1][j - 1] + dp[i - 1][j]) % BASE;
        }
    }
    for (int i = 1; i <= k; i++) {
        cout << (dp[n - k + 1][i] * dp[k - 1][i - 1]) % BASE << endl;
    }
    return 0;
}


Measured memory_bytes: 31488
#include <iostream>
#include <vector>
#include <algorithm>
#include <random>
#include <string>
#include <cmath>
#include <time.h>

using namespace std;
typedef long long ll;

ll N = 0;
ll M = 0;
ll x = 0;
ll y = 0;

//?????????????????

struct UnionFind{
    //ご本体
    vector<ll > tree;
    //高さ
    vector<ll > rank;
    //グループごとのサイズ
    vector<ll > size;
 
    //定義
    UnionFind(ll N) : tree(N), rank(N), size(N){
        for(int i = 0; i < N; i++){
            tree[i] = i;
            rank[i] = 0;
            size[i] = 1;
        }
    }

    //どの根っこに属しているのか？さかのぼり続ける
    int root(int x){
        if(tree[x] == x){
            return x;
        }
        //経路圧縮
        return tree[x] = root(tree[x]);
    }

    //木と木を(高さが低い方に)くっつける
    ll unite(int x, int y){
        int tx = root(x);
        int ty = root(y);
        //xとyの根が同じならくっつけない
        if(tx == ty){
            return 0;
        }
        
        ll s = size[tx] + size[ty];
        ll r = size[tx] * size[ty];
        size[tx] = s;
        size[ty] = s;

        //tree[tx] = ty;
        //高くない方にくっつけたい：効果がいまいちわからん
        //下：ランク付けのつもり 
        if(rank[tx] < rank[ty]){
            //小さい方を大きい方
            //txの根が大きい方の根に更新
            tree[tx] = ty; 
        }else{
            tree[ty] = tx;
            //つなげるときに同じ高さだったらつなげた後に高さを＋１する
            if(rank[tx] == rank[ty]){
                rank[tx]++;
            }
        }

        return r;

    }

    //同じ木に属しているか？根っこをさかのぼって調べてみる
    bool same(int x, int y){
        int tx = root(x);
        int ty = root(y);
        if(tx == ty){
            return true;
        }else{
            return false;
        }
    }
    //グループのサイズを返す
    int FindSize(int x){
        return size[root(x)];
    }

};

int main(){

    cin >> N >> M;

    UnionFind test(N);

    vector<ll > ans;
    ll t_ans = 0;
    //初期状態：どの組み合わせも橋がないのでとても不便
    //ans.push_back((N * (N - 1)) / 2);
    t_ans = (N * (N - 1)) / 2;
    //for(ll i = N; i >= 1; i--){
    //    t_ans += i - 1;
    //}

    vector<ll> X;
    vector<ll> Y;
    for(ll i = 0; i < M; i++){
        cin >> x >> y;
        X.push_back(x - 1);
        Y.push_back(y - 1);
    }

    //入力
    for(ll i = M - 1; i >= 0; i--){
        ans.push_back(t_ans);
        if(test.same(X[i], Y[i])){
            continue;
        }
        
        //cout << test.FindSize(X[i]) * test.FindSize(Y[i]) << endl;
        //t_ans -= test.FindSize(X[i]) * test.FindSize(Y[i]);
        ll r = test.unite(X[i], Y[i]);
        t_ans -= r;

    }

    for(ll i = M - 1 ; i >= 0 ; i--){
        cout << ans[i] << endl;
    }

}

Measured memory_bytes: 6124
n = int(input())
ab = [list(map(int, input().split())) for _ in range(n)]
ab.sort(key=lambda x:x[1])
comp = []
for lst in ab:
    comp.append(lst[1])
acc = [0]
for i, v in enumerate(ab):
    acc.append(acc[-1] + v[0])
for x, y in zip(acc[1:], comp):
    if x > y:
        print("No")
        break
else:
    print("Yes")

Measured memory_bytes: 145020
#include <bits/stdc++.h>
#include <algorithm>
using namespace std;
int main(){
	int A, B, Q; 
	cin >> A >> B >> Q; 
	long long int S[100010] = {}; 
	long long int T[100010] = {}; 
	for(int i = 1; i <= A; i++){
		cin >> S[i]; 
	}
	S[0] = -1e15, S[A+1] = 1e15;  
	for(int i = 1; i <= B; i++){
		cin >> T[i]; 
	}
	T[0] = -1e15, T[B+1] = 1e15; 
	for(int q = 0; q < Q; q++){
		long long int X; 
		cin >> X; 
		int s = lower_bound(S, S+A+1, X) - S; 
		int t = lower_bound(T, T+B+1, X) - T; 
		long long int u = X - min(S[s-1], T[t-1]);	
		long long int v = max(S[s], T[t]) - X; 
		long long int w = 2 * (X - S[s-1]) + (T[t] - X); 
		long long int x = (X - S[s-1]) + 2 * (T[t] - X); 
		long long int y = 2 * (X - T[t-1]) + (S[s] - X); 
		long long int z = (X - T[t-1]) + 2 * (S[s] - X); 
		cout << min({u,v,w,x,y,z}) << endl; 
	}
}

Measured memory_bytes: 2816
#include <bits/stdc++.h>
using namespace std;
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; }

const int MOD = 1e9+7;
int n, k;
vector<int> a(110, 0);

int dp[110][100100];

int main() {
    cin >> n >> k;
    for(int i = 0; i < n; ++i) cin >> a.at(i);

    dp[0][0] = 1;
    /*for(int i = 0; i < n; ++i) {
        for(int j = 0; j <= k; ++j) {
            for(int l = 0; l <= a.at(i); ++l) {
                if(j+l <= k) {
                    dp[i+1][j+l] = (dp[i+1][j+l]+dp[i][j]) % MOD;
                }
            }
        }
    }*/

    for(int i = 0; i < n; ++i) {
        vector<int> sum(100100, 0);
        for(int j = 0; j <= k; ++j) sum.at(j+1) = (sum.at(j)+dp[i][j])%MOD;
        for(int j = 0; j <= k; ++j) {
            dp[i+1][j] = (sum[j+1]-sum[max(0, j-a.at(i))]+MOD)%MOD;
        }
    }

    cout << dp[n][k] << endl;
}

Measured memory_bytes: 41208
#include "bits/stdc++.h"
#include<unordered_map>
#include<unordered_set>
#pragma warning(disable:4996)
using namespace std;
using ld = long double;
const ld eps = 1e-9;

//// < "d:\d_download\visual studio 2015\projects\programing_contest_c++\debug\a.txt" > "d:\d_download\visual studio 2015\projects\programing_contest_c++\debug\b.txt"


int main() {
	while (1) {
		int N, M; cin >> N >> M;
		if (!N)break;
		vector<pair<string, int>>lots;
		for (int i = 0; i < N; ++i) {
			string st; int money; cin >> st >> money;
			lots.push_back(make_pair(st, money));
		}
		int sum = 0;
		for (int i = 0; i < M; ++i) {
			string b; cin >> b;
			for (int j = 0; j < N; ++j) {
				bool ok = true;
				for (int k = 0; k < 8; ++k) {
					if (lots[j].first[k] == '*' || lots[j].first[k] == b[k]) {

					}
					else {
						ok = false;
					}
				}
				if (ok)sum += lots[j].second;
			}
		}
		cout << sum << endl;
	}
	
	return 0;
}

Measured memory_bytes: 3148
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
template<class T> bool chmax(T &a, const T &b){ if(a < b){ a = b; return 1; } else return 0; }

int main(){
  ll n;
  cin >> n;
  vector<ll> b(n + 1), ans(n + 1);
  unordered_map<ll, ll> m;
  for(ll i = 0; i < n; i++){
    ll a;
    cin >> a;
    b[++m[a]]++;
  }
  for(ll i = 1; i < n; i++) b[i + 1] += b[i];
  for(ll i = 1; i <= n; i++) chmax(ans[b[i] / i], i);
  for(ll i = n; i > 0; i--) chmax(ans[i - 1], ans[i]);
  for(ll i = 1; i <= n; i++) cout << ans[i] << endl;
}


Measured memory_bytes: 18888
#include<bits/stdc++.h>
#define maxn 100050
#define inf 0x3f3f3f3f
#define LL long long
#define pb push_back
#define pii pair<int,int>
#define fi first
#define se second
#define mm(a,b) memset(a,b,sizeof(a))
#define mp(a,b) make_pair(a,b)
const LL mod=1e9+7;
const LL INF=(LL)1e18;
using namespace std;
struct node{
	int x,y;
	int id;
	node(int x,int y,int id):x(x),y(y),id(id){}
};
struct edge{
	int u,v,w;
	edge(int u,int v,int w):u(u),v(v),w(w){}
	bool operator < (const edge& x) const{
		return w<x.w;
	}
};
int n;
int p[maxn];
vector<node>s;
vector<edge>e;
int cmp1(node a,node b){
	return a.x<b.x;
}
int cmp2(node a,node b){
	return a.y<b.y;
}
int find(int x){
	return x==p[x]?x:p[x]=find(p[x]);
}
int kruskal(){
	int ans=0;
	int len=e.size();
	int cnt=0;
	sort(e.begin(),e.end());
	for(int i=0;i<=n;i++) p[i]=i;
	for(int i=0;i<len;i++){
		int x=find(e[i].u),y=find(e[i].v);
		if(x!=y){
			ans+=e[i].w;
			p[x]=y;
			cnt++;
		}
		if(cnt==n-1) break;
	}
	return ans;
}
int main(){
//	freopen("input.txt","r",stdin);
//	freopen("ouput.txt","w",sdout);
	ios::sync_with_stdio(false);
	cin.tie(0),cout.tie(0);
	cin>>n;
	for(int i=1;i<=n;i++){
		int x,y;
		cin>>x>>y;
		s.pb(node(x,y,i));
	}
	sort(s.begin(),s.end(),cmp1);
	int len=s.size()-1;
	for(int i=0;i<len;i++){
		int ww=min(abs(s[i+1].x-s[i].x),abs(s[i+1].y-s[i].y));
		e.pb(edge(s[i].id,s[i+1].id,ww));
	}
	sort(s.begin(),s.end(),cmp2);
	for(int i=0;i<len;i++){
		int ww=min(abs(s[i+1].x-s[i].x),abs(s[i+1].y-s[i].y));
		e.pb(edge(s[i].id,s[i+1].id,ww));
	}
	cout<<kruskal()<<endl;
	return 0;
}


Measured memory_bytes: 6132
#include<iostream>
#include<algorithm>
#include<string.h>
#include<stdlib.h>
#include<math.h>


int main(){
  int X, A, B;
  std::cin >> X >> A >> B;
  if( A >= B ){
	std::cout << "delicious" << std::endl;
  }else if( B-A <= X ){
	std::cout << "safe" << std::endl;
  }else{
	std::cout << "dangerous" << std::endl;
  }
  return 0;
}

Measured memory_bytes: 256
M,D = map(int,input().split())

ans = 0

for m in range(M):

    m += 1

    for d in range(D):

        d += 1

        if d < 100 and d >= 10:

            d10 = d // 10
            d1  = d % 10

            if d10 >= 2 and d1 >= 2 and d10 * d1 == m:

                ans += 1

print (ans)


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

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

using namespace std;

int main() {
    vector<int> IDs;
    int N,M;
    cin >> N >> M;
    int smallID=0;
    int bigID=N;
    rep(i,M) {
        int L,R;
        cin >> L >> R;
        if(smallID<L) {
            if(bigID<L) {
                smallID = -1;
                bigID = -1;
                break;
            }
            smallID = L;

        }
        if(bigID>R) {
            if(smallID>R) {
                smallID = -1;
                bigID = -1;
                break;
            }
            bigID = R;
        }
    }
    if(smallID==-1 && bigID==-1) cout << 0 << endl;
    else cout << bigID-smallID + 1 << endl;
}


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

using namespace std;

int main() {
  string a, b;
  cin >> a >> b;

  string s = a + b;
  int num = stoi(s);

  for(int i = 2; i*i <= num; i++) {
    if(i*i == num) {
      cout << "Yes" << endl;
      return 0;
    }
  }
  cout << "No" << endl;

}



Measured memory_bytes: 256
#include <stdio.h>

int main(void){
  int m;
  unsigned long long int money;
  int year;
  int n;
  int fukuri;
  double nenri;
  unsigned long long int risi;
  unsigned int tesu;
  unsigned long long int tempmoney;
  unsigned long long int maxmoney;
  
  scanf("%d", &m);
  for(int i=0; i<m; i++){
    scanf("%lli", &money);
    scanf("%d", &year);
    scanf("%d", &n);
    maxmoney = money;
    for(int j=0; j<n; j++){
      tempmoney = money;
      risi = 0;
      scanf("%d%lf%d", &fukuri, &nenri, &tesu);
      if(fukuri){
	for(int y=0; y<year; y++){
	  tempmoney += (tempmoney*nenri-tesu);
	}
      }else{
	for(int y=0; y<year; y++){
	  risi += tempmoney*nenri;
	  tempmoney -= tesu;
	}
	tempmoney += risi;
      }
      if(tempmoney > maxmoney){
	maxmoney = tempmoney;
      }
    }
    printf("%lli\n", maxmoney);
  }
  return 0;
}

Measured memory_bytes: 1060
import sys
import math  # noqa
import bisect  # noqa
import queue  # noqa


def input():
    return sys.stdin.readline().rstrip()


def main():
    S = input()

    l = 0
    r = len(S) - 1

    cnt = 0
    while l < r:
        if S[l] == S[r]:
            l += 1
            r -= 1
        elif S[l] != 'x' and S[r] == 'x':
            r -= 1
            cnt += 1
        elif S[l] == 'x' and S[r] != 'x':
            l += 1
            cnt += 1
        else:
            return print(-1)

    print(cnt)


if __name__ == '__main__':
    main()


Measured memory_bytes: 40300
#include<bits/stdc++.h>
#include <math.h>
#include<iostream>
#include <string>
using namespace std;
typedef long long ll;
#define pb pushback
#define fr(i,n) for(int i=0;i<n;i++)
#define ifr(i,n) for(int i=n-1;i>=0;i--)


int main() {
    int x,y,z;
	cin >> x>> y;
    string ans;
    if(x<9&&y<9)ans="Yay!";
    else ans = ":(";
      cout << ans << endl;
}

Measured memory_bytes: 256
// ABC177D Friends

#include<stdio.h>
int par[200001];//親
int siz[200001];//サイズ

void ini(int n){ //初期化
  for(int i=1;i<=n;i++){
    par[i] = i;
    siz[i] = 1;
  }
}
int root(int x){ //根を返す
  if(par[x] == x) return x;
  else return par[x] = root(par[x]);
}

void uni(int x, int y){ //くっつける
  x = root(x);
  y = root(y);
  if(x != y){
    siz[x] += siz[y];
    par[y] = x;
  }
}

int size(int x){ //サイズを返す
  return siz[root(x)];
}

int max(int x, int y){
  if(x>=y) return x;
  else return y;
}

int main(void){
  int n,m,a,b,ma=0;
  scanf("%d %d",&n,&m);
  ini(n);
  for(int i=0;i<m;i++){
    scanf("%d %d",&a,&b);
    uni(a,b);
  }
  for(int i=1;i<=n;i++){
    ma = max(ma,size(i));
  }
  printf("%d",ma);
  return 0;
}

Measured memory_bytes: 3504
n, k = map(int, input().split())
h = list(map(int, input().split()))
dp = [10**9]*n
dp[0] = 0
for i in range(1,n):
    for j in range(1, k+1):
        if i-j >= 0:
            dp[i] = min(dp[i], dp[i-j] + abs(h[i]-h[i-j]))
print(dp[n-1])

Measured memory_bytes: 84764
// Palindromic Numbers

#include <iostream>

using namespace std;

int main(){
	int A, B;
	cin >> A >> B;

	int res = 0;

	for (int i = A; i <= B; ++i){
		// eg) 4桁目の場合
		// 12345 を 1000 で割ると
		// 12345/1000 = floor(12.345) -> mod 10 で2
		int d1, d2, d4, d5;
		d1 = (i / 10000) % 10; d2 = (i / 1000) % 10;
		d4 = (i / 10) % 10; d5 = i % 10;

		if (d1 == d5 && d2 == d4)
			res++;
	}
	cout << res << endl;

	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
constexpr int MOD = 1000000007;
template <typename T>
vector<T> Vec(int n, T v) { return vector<T>(n, v); }
template <class... Args>
auto Vec(int n, Args... args) { return vector<decltype(Vec(args...))>(n, Vec(args...)); }
int main()
{
    auto encode = [](const char c) { return c == 'A' ? 0 : c == 'T' ? 1 : c == 'G' ? 2 : c == 'C' ? 3 : -1; };
    int A, T, G, C, N;
    cin >> A >> T >> G >> C >> N;
    cin.ignore();
    map<string, int> mp;
    vector<vector<string>> rule(N);
    for (int i = 0; i < N; i++) {
        string s;
        getline(cin, s);
        s.push_back(' ');
        int pos = 0;
        string name;
        for (; pos < s.size() and s[pos] != ':'; pos++) { name.push_back(s[pos]); }
        mp[name] = i;
        pos += 2, name = "";
        for (; pos < s.size(); pos++) {
            if (s[pos] == ' ') {
                rule[i].push_back(name), name = "";
            } else if (s[pos] != '[' and s[pos] != ']') {
                name.push_back(s[pos]);
            }
        }
    }
    vector<int> len(N, 0);
    for (int i = N - 1; i >= 0; i--) {
        for (const string& s : rule[i]) {
            if (isupper(s[0])) {
                len[i]++;
            } else {
                len[i] += len[mp[s]];
            }
        }
        if (len[i] > A + T + G + C) { return cout << 0 << endl, 0; }
    }
    using Set = bitset<4>;
    if (len[0] != A + T + G + C) { return cout << 0 << endl, 0; }
    vector<vector<Set>> r(N);
    for (int i = N - 1; i >= 0; i--) {
        for (const string& s : rule[i]) {
            if (isupper(s[0])) {
                Set st;
                for (const char c : s) { st[encode(c)] = 1; }
                r[i].push_back(st);
            } else {
                for (const auto& st : r[mp[s]]) { r[i].push_back(st); }
            }
        }
    }
    const auto cand = r[0];
    r.clear(), r.shrink_to_fit();
    const int sz = cand.size();
    auto dp = Vec(A + 1, T + 1, G + 1, 0);
    dp[0][0][0] = 1;
    for (int i = 0; i < sz; i++) {
        auto tmp = Vec(A + 1, T + 1, G + 1, 0);
        for (int a = 0; a <= A; a++) {
            for (int t = 0; t <= T; t++) {
                for (int g = 0; g <= G; g++) {
                    if (dp[a][t][g] == 0) { continue; }
                    const int c = i - A - T - G;
                    if (cand[i][0] and a + 1 <= A) { (tmp[a + 1][t][g] += dp[a][t][g]) %= MOD; }
                    if (cand[i][1] and t + 1 <= T) { (tmp[a][t + 1][g] += dp[a][t][g]) %= MOD; }
                    if (cand[i][2] and g + 1 <= G) { (tmp[a][t][g + 1] += dp[a][t][g]) %= MOD; }
                    if (cand[i][3] and c + 1 <= C) { (tmp[a][t][g] += dp[a][t][g]) %= MOD; }
                }
            }
        }
        dp = tmp;
    }
    cout << dp[A][T][G] << endl;
    return 0;
}



Measured memory_bytes: 4080
#include <bits/stdc++.h>
using namespace std;
int a[3];
void solve()
{
    sort(a,a+3);
    cout<<a[2]*10+a[1]+a[0]<<endl;
}
int main()
{
    while(cin>>a[0]>>a[1]>>a[2])
        solve();
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for (ll i = 0; i < n; ++i)
#define sz(x) int(x.size())
#define ALL(c) (c).begin(), (c).end()
#define SUM(x) std::accumulate(ALL(x), 0LL)
#define MIN(v) *std::min_element(v.begin(), v.end())
#define MAX(v) *std::max_element(v.begin(), v.end())
#define EXIST(v, x) (std::find(v.begin(), v.end(), x) != v.end())
#define FORV(i, v) for (auto i = v.begin(); i != v.end(); i++)
using namespace std;

using ll = int64_t;

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; }
const int INF = 1'001'001'001;
const ll INFL = (1LL<<60);
const double eps = (1e-9);

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

  int a, b, k;
  cin >> a >> b >> k;

  vector<int> ans;
  for (int i = 1; i <= min(a, b); i++) {
    if (a % i == 0 && b % i == 0) {
      ans.push_back(i);
    }
  }

  reverse(ALL(ans));
  cout << ans[k-1] << endl;

  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <string>
#include <string.h>
#include <math.h>
#include <cmath>
#include <vector>
#include <list>
#include <set>
#include <map>
#include <algorithm>
#include <utility>
#include <deque>
#include <queue>
#include <functional>
//#include <boost/multiprecision/cpp_int.hpp>

#define rep(i, n) for(int i = 0; i < n; ++i)
#define REP(i, m, n) for(int i = m; i < n; ++i)
#define rrep(i,n) for(int i = n; i >= 0; --i)
#define RREP(i, m, n) for(int i = n; i >= m; --i)
#define llrep(i, n) for(ll i = 0; i < n; ++i)
#define llREP(i, m, n) for(ll i = m; i < n; ++i)
#define llrrep(i,n) for(ll i = n; i >= 0; --i)
#define llRREP(i, m, n) for(ll i = n; i >= m; --i)

using ll = long long;
using ull = unsigned long long;
using pii = std::pair<int, int>;
using pll = std::pair<long long, long long>;
using pil = std::pair<int, long long>;
using pli = std::pair<long long, int>;
using plpii = std::pair<long long, std::pair<int, int>>;
using pdd = std::pair<double, double>;

const long long INF = 1000000000000000001;
const long long _MOD = 1000000007;
const long long MOD = 998244353;
const int ALPHABET = 27;
const double pi = 3.14159265358979;

using namespace std;
//namespace mp = boost::multiprecision;

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

	int n;
	ll x;
	cin >> n >> x;
	ll* a = new ll[n];
	rep(i, n) cin >> a[i];
	sort(a, a + n);

	int ans = 0;
	rep(i, n) {
		if (x >= a[i]) {
			++ans;
			x -= a[i];
		}
		else {
			break;
		}
	}

	if (x != 0 && ans == n) {
		--ans;
	}

	cout << ans << "\n";

	return 0;
}


Measured memory_bytes: 3672
n = list(map(int,(input().strip().split(' '))))
a = n[0]
b = n[1]
t = 0
if a > b:
    t += a
    a -= 1
else:
    t += b
    b -= 1

if a > b:
    t += a
    a -= 1
else:
    t += b
    a -= 1

print(t)

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

using namespace std;

int main() {
	long long h, w;
	cin >> h >> w;

	if (h % 3 == 0 || w % 3 == 0) {
		cout << 0 << endl;
		return 0;
	}
	long long ans = min(h, w);
	if (h % 2 == 0)ans = min(ans, h / 2);
	else {
		ans = min(ans, max(w - w / 3, (h / 2 + 1)*(w - w / 3) - (w / 3)*h));
		ans = min(ans, max(w - w / 3-1, (w / 3+1)*h) - (h/2) *(w - w/3 -1));
	}
	if (w % 2 == 0)ans = min(ans, w / 2);
	else {
		ans = min(ans, max(h - h / 3, (w / 2 + 1)*(h - h / 3) - (h / 3)*w));
		ans = min(ans, max(h - h / 3-1, (h / 3+1)*w) - (w/2) *(h - h/3 -1));
	}
	cout << ans << endl;
	return 0;

}

Measured memory_bytes: 256
#include "bits/stdc++.h"
/*
#include <iostream>
#include <vector>
#include <map>
#include <utility>
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <stack>
#include <queue>
#include <set>
#include <unordered_map>
#include <unordered_set>
#include <numeric>
#include <complex>
#include <bitset>
#include <functional>
#include <stack>
#include <regex>
#include <tuple>
*/
#define int long long
#define REP(i,a,n) for(int i=a;i<n;++i)
#define rep(i,n) REP(i,0,n)
#define REV(i,a,n) for(int i=n;i>=a;--i)
#define all(e) e.begin(),e.end()
#define rall(e) e.rbegin(),e.rend()
#define pb push_back
#define mp make_pair
#define fs first
#define sc second
#define mod 1000000007
#define show(n) cerr<<#n<<" = "<<n<<endl
#define showp(n) cerr<<n.fs<<", "<<n.sc<<endl
#define shows(n) for(auto z:n){cerr<<z<<", ";}cerr<<endl
#define showsp(n) for(auto z:n){cerr<<z.fs<<" "<<z.sc<<", "}cerr<<endl

#define yes printf("Yes\n")
#define no printf("No\n")
#define case(i) printf("Case #%lld: ",i)

using namespace std;

using ull=unsigned long long;
using vi=vector<int>;
using pint=pair<int,int>;

const int INF=1LL<<55;

vector<bool> IsPrime;
vi pn;

int m,a,b;
int p,q;

void sieve(size_t max){
    if(max+1 > IsPrime.size()){
        IsPrime.resize(max+1,true);
    } 
    IsPrime[0] = false;
    IsPrime[1] = false;

    for(size_t i=2; i*i<=max; ++i)
        if(IsPrime[i])
            for(size_t j=2; i*j<=max; ++j)
                IsPrime[i*j] = false;
}

void solve(){
    double ab = (double)a/(double)b;
    double hi;
    int mult;
    int lgst=0;
    rep(i,pn.size()){
        rep(j,pn.size()){
            
            hi=(double)pn[i]/(double)pn[j];
            if(hi<ab||hi>1.0) continue;
            mult=pn[i]*pn[j];
            if(mult>m) break;
            if(lgst<=mult){
                p=pn[i];
                q=pn[j];
                lgst=mult;
            }
        }
    }

    printf("%lld %lld\n",p,q);
}

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

    sieve(10000);
    rep(i,10000){
        if(IsPrime[i]) pn.pb(i);
    }


    while(scanf("%lld %lld %lld",&m,&a,&b),m){
        solve();
    }
    
    return 0;
}


Measured memory_bytes: 3284
#import math
#import bisect
#import numpy as np
#import itertools
#import copy
import sys

ipti = sys.stdin.readline
MOD = 10 ** 9 + 7
INF = float('INF')
sys.setrecursionlimit(10 ** 5)

def main():
    n = int(input())
    a = list(map(int,ipti().split()))
    b = list(map(int,ipti().split()))
    c = list(map(int,ipti().split()))

    ans = sum(b)
    prev = a[0]

    for i in range(n):
        if a[i] - prev == 1:
            ans += c[prev-1]
        prev = a[i]

    print(ans)

if __name__ == '__main__':
    main()

Measured memory_bytes: 3064