akhauriyash/Code-Regression huggingface dataset:
N,C=map(int,input().split())
D=[[int(i) for i in input().split()] for i in range(C)]
grid=[[int(i) for i in input().split()] for i in range(N)]
colors0=[0]*C
colors1=[0]*C
colors2=[0]*C
for i in range(1,N+1):
  for j in range(1,N+1):
    if (i+j)%3==0:
      colors0[grid[i-1][j-1]-1]+=1
    if (i+j)%3==1:
      colors1[grid[i-1][j-1]-1]+=1
    if (i+j)%3==2:
      colors2[grid[i-1][j-1]-1]+=1

d0=[10**20]*3
d1=[10**20]*3
d2=[10**20]*3
c0=[0]*3
c1=[0]*3
c2=[0]*3
s0=0
s1=0
s2=0
for c in range(C):
  for i in range(C):
    s0+=colors0[i]*D[i][c]
  for j in range(3):
    if s0<d0[j]:
      for k in range(2,j,-1):
        d0[k]=d0[k-1]
        c0[k]=c0[k-1]
      d0[j]=s0
      c0[j]=c
      break
  s0=0
  for i in range(C):
    s1+=colors1[i]*D[i][c]
  for j in range(3):
    if s1<d1[j]:
      for k in range(2,j,-1):
        d1[k]=d1[k-1]
        c1[k]=c1[k-1]
      d1[j]=s1
      c1[j]=c
      break
  s1=0
  for i in range(C):
    s2+=colors2[i]*D[i][c]
  for j in range(3):
    if s2<d2[j]:
      for k in range(2,j,-1):
        d2[k]=d2[k-1]
        c2[k]=c2[k-1]
      d2[j]=s2
      c2[j]=c
      break
  s2=0   
ans=10**20
for i in range(3):
  for j in range(3):
    for k in range(3):
      if c0[i]==c1[j] or c1[j]==c2[k] or c2[k]==c0[i]:
        pass
      else:
        if ans>d0[i]+d1[j]+d2[k]:
          ans=d0[i]+d1[j]+d2[k]
print(ans)

    

Measured memory_bytes: 43612
#include<bits/stdc++.h>
#define rep(i,n) for(int i = 0;i<n;i++)
using namespace std;
typedef pair<int,int> P;
typedef long long ll;
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;}

int main() {
    int x,n;
    cin >> x >> n;
    vector<int>d(102);
    rep(i,n) {
        int p;
        cin >> p;
        d[p] = 1;
    }
    P p = {99999,-1};
    for(int i = 0;i<=101;i++) {
        if(d[i] == 1) continue;
        int diff = abs(x-i);
        p = min(p,{diff,i});
    }
    cout << p.second << endl;
}

Measured memory_bytes: 3640
// Package main provides
//
// File:  c.go
// Author: ymiyamoto
//
// Created on Mon Jan  7 17:22:19 2019
//
package main

import "fmt"

func main() {
	var A, B, C, D, E, F int
	fmt.Scan(&A, &B, &C, &D, &E, &F)
	A *= 100
	B *= 100

	maxWater, maxSugar := 0, 0
	for a := 0; a*A <= F; a++ {
		for b := 0; a*A+b*B <= F; b++ {
			water := a*A + b*B
			for c := 0; water+c*C <= F; c++ {
				for d := 0; water+c*C+d*D <= F; d++ {
					suger := c*C + d*D
					total := water + suger
					if water > 0 && suger <= water*E/100 && total <= F {
						maxTotal := maxWater + maxSugar
						if total*maxSugar <= maxTotal*suger {
							maxWater = water
							maxSugar = suger
						}
					}
				}
			}
		}
	}

	fmt.Println(maxWater+maxSugar, maxSugar)
}


Measured memory_bytes: 512
if __name__ == "__main__":
    n = int(input())
    x =list((int(x) for x in input().split()))
    # print(x)
    
    tmp1 = 0
    tmp2 = x[0]
    for i in range(1,n):
        if tmp2 > x[i]:
            tmp3 = tmp2 - x[i]
            tmp1 += tmp3

            x[i] = x[i] + tmp3
            tmp2 = x[i]
        else:
            tmp1 += 0
            tmp2 = x[i]

    print(tmp1)


Measured memory_bytes: 32212
#include<vector>
#include<list>
#include<algorithm>
#include<iostream>
#include<string>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
using namespace std;
int main(){
  int i,j;
  int a[200],b[200],c,m,n;
  cin>>n>>m;
  for(i=0;i<n*2;i++)
    a[i]=i+1;
  for(i=0;i<m;i++){
    cin>>c;
    if(c){
      memcpy(b+n*2-c,a,c*sizeof(int));
      memcpy(b,a+c,(n*2-c)*sizeof(int));
    }else{
      for(j=0;j<n;j++){
	b[j*2]=a[j];
	b[j*2+1]=a[j+n];
      }
    }
    memcpy(a,b,sizeof(a));
  }
  for(i=0;i<n*2;i++)
    cout<<a[i]<<endl;
  return 0;
}

Measured memory_bytes: 0
import java.util.ArrayList;
import java.util.Collections;
import java.util.Scanner;

public class Main {
	public static void main(String[] args){
		Scanner scan = new Scanner(System.in);
		int a = scan.nextInt();
		int b = scan.nextInt();
		int c = scan.nextInt();
		scan.close();
		ArrayList<Integer> nums = new ArrayList<Integer>();
		nums.add(a);
		nums.add(b);
		nums.add(c);
		Collections.sort(nums);
		String answer = new String();
		answer += nums.get(0) + " " + nums.get(1) + " " + nums.get(2);
		System.out.println(answer);
	}

}

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

def solve():
    n = int(input())
    l4 = [4 * i for i in range(25)]
    l7 = [7 * i for i in range(15)]
    for a in l4:
        for b in l7:
            if a + b == n:
                print("Yes")
                return
    print("No")

if __name__=="__main__":
    solve()

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

using namespace std;

typedef long long ll;

int main(){
    ll H, Test, i;
    i = 0;

    cin >> H;

    while(H!=1){
        H = H /2;
        i++;
     //   if(H == 1) break;
     //  else continue;
    }

   //cout << "i " << i << " ";
    
    Test = 0;

    Test = pow(2, i+1) - 1;

    //cout << pow(2, 1) << " ";
    
    //Test += Test * 2 - 1;

    cout << Test;

    return 0;
}

Measured memory_bytes: 512
#include <algorithm>
#include <cmath>
#include <climits>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <fstream>
#include <iostream>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>
#include <cassert>
#include <functional>

using namespace std;

#define LOG(...) printf(__VA_ARGS__)
//#define LOG(...)
#define FOR(i,a,b) for(int i=(int)(a);i<(int)(b);++i)
#define REP(i,n) for(int i=0;i<(int)(n);++i)
#define ALL(a) (a).begin(),(a).end()
#define RALL(a) (a).rbegin(),(a).rend()
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort((c).begin(),(c).end())
#define RSORT(c) sort((c).rbegin(),(c).rend())
#define CLR(a) memset((a), 0 ,sizeof(a))

typedef long long ll;
typedef unsigned long long ull;
typedef vector<bool> vb;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<vb> vvb;
typedef vector<vi> vvi;
typedef vector<vll> vvll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;

const int dx[] = { -1, 0, 1, 0 }; const int dy[] = { 0, 1, 0, -1 };
bool primeb[32768];
int main() {
	vector<int> prime;
	FOR(i,2, 32768){
		if (!primeb[i]){
			prime.push_back(i);
			for (int j = i * 2; j < 32768; j+=i)primeb[j] = true;
		}
	}
	int n;
	while (cin >> n, n){
		int count = 0;
		for (int i = 0; i < prime.size(); i++){
			if (prime[i]>n / 2)break;
			if (find(ALL(prime), n - prime[i]) != prime.end())count++;
		}
		cout << count << endl;
	}
}

Measured memory_bytes: 1284
#pragma GCC optimize("O3")
#include <bits/stdc++.h>

using namespace std;

typedef int64_t  ll;
typedef uint64_t ull;

#define rep(i,n)   for (int i = 0; i < (n); i++)
#define rrep(i,n)  for (int i = (n)-1; i >= 0; i--)
#define rep1(i,n)  for (int i = 1; i <= (n); i++)
#define rrep1(i,n) for (int i = (n); i > 0; i--)

int main(void) {
    int a, b, ans;
    cin >> a >> b;
    ans = a-b*2;
    if (ans < 0) ans = 0;
    cout << ans << endl;
    return 0;
}


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

using namespace std;

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

	for (int i = 0; i < K; i++) {
		if (A >= B) {
			B = 2 * B;
		}
		else if (B >= C) {
			C = 2 * C;
		}
	}

	if (C > B && B > A) {
		cout << "Yes" << endl;
	}
	else {
		cout << "No" << endl;
	}
	

}






Measured memory_bytes: 3632
#include <iostream>
#include <algorithm>

#define MAX 3000

using namespace std;


int main() {
	int rgb[3], n, dp[MAX + 1];
	cin >> rgb[0] >> rgb[1] >> rgb[2] >> n;

	fill(dp, dp + MAX + 1, 0);
	dp[0] = 1;

	for (int i = 0; i < 3; i++) {
		for (int k = 1; k <= n; k++) {
			if (k - rgb[i] >= 0) {
				dp[k] += dp[k - rgb[i]];
			}
		}
	}

	cout << dp[n] << endl;

	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define MAX 100001
#define MOD 1000000007
#define ll long long
#define ld long double
#define fast ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define endl "\n"
int main() {
	fast;
	string s, t;
	cin >> s >> t;
	int m = s.size(), n = t.size();
	string temp = "";
	int ans = INT_MAX;
	for(int i=0;i<m;i++) {
		if(i >= n) {
			// cout << temp << endl;
			int ct = 0;
			for(int j=0;j<n;j++) {
				if(t[j] != temp[j]) ct++;
			}
			ans = min(ans, ct);
			temp.erase(temp.begin());
		}
		temp += s[i];
	}
	int ct = 0;
	for(int j=0;j<n;j++) {
		if(t[j] != temp[j]) ct++;
	}
	ans = min(ans, ct);
	cout << ans << endl;
}


Measured memory_bytes: 3664
N, M = gets.split.map &:to_i
XYZ = $<.map{|s|
  s.split.map &:to_i
}

signs = [1, -1]
p signs.product(signs, signs).map{|a,b,c|
  XYZ.map{|x,y,z|
    x*a + y*b + z*c
  }.max(M).inject(0, :+)
}.max


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

using namespace std;

#define M 1000000007
#define pb push_back
#define f first
#define s second
#define rep(i, st, ed) for(int i=st; i<ed; i++)
#define repn(i, st, ed) for(int i=st; i<=ed; i++)


typedef long long ll;
typedef unsigned long long int llt;

const int N = 1e5 + 10;

vector<int> g[N];
bool viss[N];
int vis[N];

void dfs(int curr, int par)
{
  for(auto x: g[curr])
    if(x != par)
      dfs(x, curr);
}

void dfs1(int curr, int par)
{
  viss[curr] = 1;
  for(auto x: g[curr])
    if(!viss[x])
      dfs1(x, curr);
}

void dfs2(int curr, int par, int num)
{
  vis[curr] = num;
  for(auto x: g[curr])
    if(vis[x] == 0)
      dfs2(x, curr, num);
}

ll fxor(ll n)
{
  if(n < 0) return 0;
  if(n % 4 == 3) return 0;
  else if(n % 4 == 0) return n;
  else if(n % 4 == 1) return n^(n-1);
  else if(n%4 == 2) return n^(n-1)^(n-2);
}

llt ppow(llt x, llt y)
{
  llt res = 1;
  while(y > 0){
    if(y&1)
      res = (res * x)%M;
    y = y >> 1;
    x = (x * x)%M;
  }
  return res;
}

llt factdp[N];
llt fact(llt x)
{
  if(x == 0) return 1;
  if(x == 1) return 1;
  if(factdp[x] != -1) return factdp[x];
  return factdp[x] = (x*fact(x-1))%M;
}

string ans ="";
void convert10tob(llt N, int b)
{
     if (N == 0)
        return;
     int x = N % b;
     N /= b;
     if (x < 0)
        N += 1;
     convert10tob(N, b);
     ans += to_string(x);
     return;
}

llt convertstrtob(string a, int b)
{
  llt aa = 0;
  llt mul = 1;
  for(int i=a.length()-1; i>=0; i--)
  {
    int curr = a[i] - '0';
    aa += (curr * mul);
    mul *= b;
  }
  return aa;
}

int arr[N];
int maxx[N];
int main()
{
  int n, t;
  cin>>n>>t;
  int diff = 0;
  unordered_set<int> ss;
  rep(i, 0, n)
    cin>>arr[i];
  for(int i=n-1;i>=0; i--)
  {
    maxx[i] = max(maxx[i+1], arr[i]);
    diff = max(diff, maxx[i] - arr[i]);
  }
  // rep(i, 0, n) cout<<maxx[i]<<" ";
  // cout<<endl;
  // cout<<diff<<endl;
  int count = 0;
  rep(i, 0, n)
  {
    if(maxx[i]-arr[i] == diff)
    {
      if(ss.find(maxx[i]) == ss.end() && ss.find(arr[i]) == ss.end())
      count++;
      ss.insert(maxx[i]);
      ss.insert(arr[i]);
    }
  }
  cout<<count<<endl;
  return 0;
}


Measured memory_bytes: 7460
n, k = map(int, input().split())
dlist = list(map(int, input().split()))

# antilist = list(set([0,1,2,3,4,5,6,7,8,9]) - (dlist))

res = []

digit = len(str(n))

while True:
    ok = True
    for i in range(0, len(str(n))):
        num = n // 10 ** (i) % 10
        if num in dlist:
            ok = False
    if ok:
        print(n)
        exit(0)
    n += 1


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

int main(){
	cout<<fixed<<setprecision(12);
	double x1, x2, y1, y2;
	cin>>x1>>y1>>x2>>y2;

	double X = pow(x1 - x2, 2);
	double Y = pow(y1 - y2, 2);
	double Z = sqrt(X + Y);
	
	cout<<Z<<endl;
	
	return 0;
}


Measured memory_bytes: 3264
import java.util.*;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		int[] h = new int[N];
		for (int i = 0; i < N; i++) {
			h[i] = sc.nextInt();
		}
		sc.close();

		int cnt = h[0];
		for (int i = 1; i < N; i++) {
			cnt += Math.max(h[i] - h[i - 1], 0);
		}

		System.out.println(cnt);
	}
}


Measured memory_bytes: 35952
def I(): return int(input())
def LI(): return list(map(int,input().split()))
def MI(): return map(int,input().split())
def LLI(n): return [list(map(int, input().split())) for _ in range(n)]

a,b,c,d = MI()
print(max(a*c,a*d,b*c,b*d))

Measured memory_bytes: 9188
#include <iostream>
#include <cmath>
#include <algorithm>
#include <vector>
using namespace std;
int main() {
    int N, K; cin >> N >> K;
    vector<int> A(N, 0);
    for (int i = 0; i < N; ++i) cin >> A[i];
    for (int i = K; i < N; i++) {
        if (A[i] > A[i - K]) cout << "Yes" << endl;
        else cout << "No" << endl;
    }
}


Measured memory_bytes: 4048
#include<stdio.h>

	int	main(void)
{
	int	a,b;
	scanf("%d%d",&a,&b);
	printf("%d\n",a-b);
	scanf("%d%d",&a,&b);
	printf("%d\n",a-b);
	scanf("%d%d",&a,&b);
	printf("%d\n",a-b);
	scanf("%d%d",&a,&b);
	printf("%d\n",a-b);
	scanf("%d%d",&a,&b);
	printf("%d\n",a-b);
	scanf("%d%d",&a,&b);
	printf("%d\n",a-b);
	scanf("%d%d",&a,&b);
	printf("%d\n",a-b);
	
return	0;
}

Measured memory_bytes: 600
/* {{{ Shinobu kawaii */
/*
  ______   __        _                  __                 
.' ____ \ [  |      (_)                [  |                
| (___ \_| | |--.   __   _ .--.   .--.  | |.--.   __   _   
 _.____`.  | .-. | [  | [ `.-. |/ .'`\ \| '/'`\ \[  | | |  
| \____) | | | | |  | |  | | | || \__. ||  \__/ | | \_/ |, 
 \______.'[___]|__][___][___||__]'.__.'[__;.__.'  '.__.'_/ 
                                                           
*/
/* }}} */

// #define int long long

/* cpp template {{{ */
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <climits>
#include <iostream>
#include <vector>
#include <string>
#include <sstream>
#include <algorithm>
#include <utility>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <deque>
#include <functional>
using namespace std;

/* short */
#define pb push_back
#define mp make_pair
#define print(x) cout << x << '\n'
#define Fi first
#define Se second

/* REPmacro */
#define REPS(i, a, n) for (int i = (a); i < (n); i++)
#define REP(i, n) for (int i = 0; i < (n); i++)
#define RREP(i, n) for (int i = 1; i <= (n); i++)
#define DEPS(i, a, n) for (int i = (a); i >= n; i--)
#define DEP(i, n) for (int i = (n); i >= 0; i--)

/* typedef */
typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef vector<vector<int> > vii;
typedef pair<int, int> pii;

/* const */
const int INF = 999999999;
const int dx[] = {0, 1, 0, -1}, dy[] = {1, 0, -1, 0};

/* func */
inline bool is_uruu(int y) {return (y % 4 == 0 && (y % 100 != 0 || y % 400 == 0));}
inline bool inside(int y, int x, int H, int W) {return (y >= 0 && x >= 0 && y < H && x < W);}

/* }}} */

string ftoBinary(double n)
{
  double b;
  b = n - (int)n;
  string s;
  bool ok = false;

  if (b == 0){
    ok = true;
    s = "0000";
  } else {
    REP(i, 4){
      b *= 2;
      s += (int)b + '0';
      if (b == 1.0){
        ok = true;
      }
      b -= (int)b;
      // print(s);
    }
  }

  if (ok){
    return (s);
  }
  return ("NA");
}

string itoBinary(double n)
{
  string s;
  int b = (int)n;
  bool ok = false;

  REP(i, 8){
    s += (b % 2) + '0';
    b /= 2;
    if (b == 0){
      ok = true;
    }
    // print(s);
  }
  if (ok){
    reverse(s.begin(), s.end());
    return (s);
  }
  return ("NA");
}

signed main()
{
  //cin.tie(0);
  //ios::sync_with_stdio(false);
  
  double n;
  while (scanf("%lf", &n), n >= 0){
    string a = itoBinary(n);
    string b = ftoBinary(n);
    if (a != "NA" && b != "NA"){
      printf("%s.%s\n", a.c_str(), b.c_str());
    } else {
      printf("NA\n");
    }
  }

  return (0);
}

Measured memory_bytes: 1276
#include <iostream>
#include <algorithm>
#include <iomanip>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <numeric>
#include <bitset>

static const int MOD = 1000000007;
using ll = int64_t;
using u32 = uint32_t;
using namespace std;

template<class T> constexpr T INF = ::numeric_limits<T>::max()/32*15+208;

template <class T, class U>
vector<T> make_v(U size, const T& init){ return vector<T>(static_cast<size_t>(size), init); }

template<class... Ts, class U>
auto make_v(U size, Ts... rest) { return vector<decltype(make_v(rest...))>(static_cast<size_t>(size), make_v(rest...)); }

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


int main() {
    int h, w, k;
    cin >> h >> w >> k;
    auto v = make_v(h, w, 0);
    pair<int, int> S;
    for (int i = 0; i < h; ++i) {
        string s;
        cin >> s;
        for (int j = 0; j < w; ++j) {
            v[i][j] = (s[j] == '#');
            if(s[j] == 'S') S = make_pair(i, j);
        }
    }
    int dx[] = {1, -1, 0, 0, 0}, dy[] = {0, 0, 1, -1, 0};
    if(k == 1){
        int ans = INF<int>;
        for (int i = 0; i < 5; ++i) {
            int y = S.first+dy[i], x = S.second+dx[i];
            if(v[y][x]) continue;
            chmin(ans, min({y, h-1-y, x, w-1-x}));
        }
        cout << ans+1 << "\n";
        return 0;
    }
    auto grid = make_v(h, w, make_pair(INF<int>, 0));
    grid[S.first][S.second] = make_pair(0, 0);
    queue<pair<int, int>> q;
    auto in = [&](int y, int x){ return 0 <= y && y < h && 0 <= x && x < w;};
    q.push(S);
    while(!q.empty()){
        int yy, xx; tie(yy, xx) = q.front(); q.pop();
        int a, b; tie(a, b) = grid[yy][xx];
        for (int i = 0; i < 4; ++i) {
            int y = yy+dy[i], x = xx+dx[i];
            if(!in(y, x)) continue;
            pair<int, int> to = make_pair(max(a+1, (b+v[y][x]+k-1)/k*k), b+v[y][x]);
            if(to < grid[y][x]){
                grid[y][x] = to;
                q.emplace(y, x);
            }
        }
    }
    int ans = INF<int>;
    for (int i = 0; i < h; ++i) {
        for (int j = 0; j < w; ++j) {
            if((i == 0 || i == h-1) || (j == 0 || j == w-1)){
                chmin(ans, grid[i][j].first);
            }
        }
    }
    cout << ans/k+1 << "\n";
    return 0;
}



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

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

    int len;
    len = s.size();

    bool aflag = false;
    int first, last;
    
    for (int i=0; i<len; ++i) {
        if ((!aflag) && (s[i] == 'A')) {
            aflag = true;
            first = i;
        } else if ((aflag) && (s[i] == 'Z')) {
            last = i+1;
        }
    }

    cout << s.substr(first, last - first).size() << endl;
    return 0;
}

Measured memory_bytes: 832
#include <algorithm>
#include <iostream>
#include <string>
#include <unordered_map>
#include <utility>

using namespace std;
typedef pair <int,int> P;

int main() {
  cin.tie(0); ios_base::sync_with_stdio(false);
  int N, M;
  unordered_map<string, int> m;
  cin >> N;
  for (int i=0; i<N; ++i) {
    string s; cin >> s;
    ++m[s];
  }
  cin >> M;
  for (int i=0; i<M; ++i) {
    string s; cin >> s;
    --m[s];
  }

  int ans = 0;
  for (const auto &x : m) {
    if (x.second > ans) ans = x.second;
  }
  cout << ans << "\n";
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using i64 = long long;
#define rep(i,s,e) for(i64 (i) = (s);(i) < (e);(i)++)
#define all(x) x.begin(),x.end()
#define let auto const

int main() {
  i64 N, M;
  cin >> N >> M;

  vector<i64> dp(1 << N, 1e17);
  dp[0] = 0;
  vector<i64> next(1 << N, 1e17);
  for(int i = 0;i < M;i++) {
    i64 a, b;
    cin >> a >> b;
    i64 s = 0;
    rep(j,0,b) {
      i64 c;
      cin >> c;
      c--;
      s |= (1 << c);
    }
    rep(t,0,(1 << N)) {
      next[t] = min(next[t], dp[t]);
      next[t | s] = min(next[t | s], dp[t] + a);
    }
    swap(dp, next);
  }
  if(dp[(1 << N) - 1] == 1e17) {
    cout << -1 << endl;
  }
  else {
    cout << dp[(1 << N) - 1] << endl;
  }
}


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

typedef long long llint;
typedef pair<int, int> pii;

#define mp make_pair
#define pb push_back
#define X first
#define Y second

//#define DEBUG
#ifdef DEBUG
#define TRACE(x) cout<<#x<<" = "<<x<<endl
#else
#define TRACE(x) ;
#endif // DEBUG

llint possibleSums[5050];
const int shift = 2505;


int main() {
    int n, avg;
    int arr[55];
    possibleSums[shift] = 1;
    cin >> n >> avg;
    for (int i = 0; i < n; i++) {
        cin >> arr[i];
        arr[i] -= avg;
    }
    llint ans = 0;
    for (int i = 0; i < n; i++) {
        ans += possibleSums[shift - arr[i]];
        if (arr[i] <= 0)
        for (int j = 0; j < 5050; j++) {
            if (j + arr[i] >= 0 && j + arr[i] < 5050) {
                possibleSums[j + arr[i]] += possibleSums[j];
            }
        }
        else
            for (int j = 5050; j >= 0; j--) {
            if (j + arr[i] >= 0 && j + arr[i] < 5050) {
                possibleSums[j + arr[i]] += possibleSums[j];
            }
        }
//        cout << i << " " << ans << endl;
//        for (int j = -3; j < 4; j++)
//            cout << j << " " << possibleSums[shift + j] << endl;
    }
    cout << ans << endl;
    return 0;
}



Measured memory_bytes: 256
from collections import defaultdict, Counter
from itertools import product, groupby, count, permutations, combinations
from math import pi, sqrt
from collections import deque
from bisect import bisect, bisect_left, bisect_right
from string import ascii_lowercase
from functools import lru_cache
import sys
sys.setrecursionlimit(10000)
INF = float("inf")
YES, Yes, yes, NO, No, no = "YES", "Yes", "yes", "NO", "No", "no"
dy4, dx4 = [0, 1, 0, -1], [1, 0, -1, 0]
dy8, dx8 = [0, -1, 0, 1, 1, -1, -1, 1], [1, 0, -1, 0, 1, 1, -1, -1]


def inside(y, x, H, W):
    return 0 <= y < H and 0 <= x < W


def ceil(a, b):
    return (a + b - 1) // b


# aとbの最大公約数
def gcd(a, b):
    if b == 0:
        return a
    return gcd(b, a % b)


# aとbの最小公倍数
def lcm(a, b):
    g = gcd(a, b)
    return a / g * b


def main():
    N = int(input())
    A, B = map(int, input().split())
    P = list(sorted(list(map(int, input().split()))))

    problem = [0] * 3
    for i in range(N):
        if P[i] <= A:
            problem[0] += 1
        elif A + 1 <= P[i] <= B:
            problem[1] += 1
        elif B + 1 <= P[i]:
            problem[2] += 1

    print(min(problem))



if __name__ == '__main__':
    main()


Measured memory_bytes: 4332
#122_C
n,q=map(int,input().split())
s=input()

cnt=[0 for _ in range(n)]
for i in range(0,n-1):
    cnt[i+1]=cnt[i]
    if s[i]=='A' and s[i+1]=='C':
        cnt[i+1]+=1
    
for _ in range(q):
    l,r=map(int,input().split())
    print(cnt[r-1]-cnt[l-1])

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

#define infi            5e9
#define infl            5e18
#define MX              100005
#define pi              2*acos(0.0)
#define ll              long long int
#define rr              read()
#define ff              first
#define ss              second
#define pb              push_back
#define pii             pair<int,int>
#define pll             pair<ll,ll>
#define ms(a,b)         memset(a, b, sizeof(a))
#define loop(i,n)       for(register int i=0;i<n;i++)
#define pool(i,n)       for(register int i=n-1;i>=0;i--)
#define loop1(i,n)      for(register int i=1;i<=n;i++)
#define pool1(i,n)      for(register int i=n;i>0;i--)

using namespace std;

inline ll read(){char c=getchar();ll num,sign=1;for(;c<'0'||c>'9';c=getchar())if(c=='-')sign=-1;for(num=0;c>='0'&&c<='9';){c-='0';num=num*10+c;c=getchar();}return num*sign;}
// inline ll pw(ll b, ll p){ll ans=1;while(p>0){if(p&1)ans*=b;p>>=1;b*=b;}return ans;}
// inline bool isPrime(ll n){if(n==1)return false;if(n==2)return true;if(!(n%2))return false;for(ll i=3;i<=sqrt(n);i+=2)if(!(n%i))return false;return true;}
// inline ll gcd(ll a, ll b){if(a==0)return b;return gcd(b%a,a);}

// //*************************************  Bitmask Opereations  **********************************//
// int Set(int N,int pos){return N=N | (1<<pos);}
// int reset(int N,int pos){return N= N & ~(1<<pos);}
// bool check(int N,int pos){return (bool)(N & (1<<pos));}
// //********************************************************************************************//

int main(){
    ios_base::sync_with_stdio(false);cin.tie(NULL);
    //#ifdef rid.dle//freopen("in.txt", "r", stdin);//#endif
    //freopen("in.txt", "r", stdin);

    ll n=rr,x=rr;
    ll a=0,b,ans=0,temp;
    loop(i,n){
        b=rr;
        temp=max(a+b-x,0LL);
        ans+=temp;
        a=b-temp;
    }
    printf("%lld\n", ans);

    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define F first
#define S second
#define fast ios_base::sync_with_stdio(0);cin.tie(NULL);cout.tie(NULL)
const ll mod = 1e9+7;
int n, d;
vector<int> a;
ll mult(ll a,ll b){return ((a%mod)*(b%mod))%mod;}
ll add(ll a,ll b){return ((a%mod)+(b%mod))%mod;}
ll sub(ll a,ll b){return ((a%mod)-(b%mod)+mod)%mod;}
ll dp[10009][2][101];
ll fun(int ci, int used, int sum){
    if(ci==n){
        if(sum==0)
            return 1;
        return 0;
    }
    if(dp[ci][used][sum]!=-1){
        return dp[ci][used][sum];
    }
    ll ans = 0;
    for(int i=0;i<=9;++i){
        if(used==1){
            ans = add(ans, fun(ci+1, 1, (sum+i)%d));
        }
        else{
            if(i < a[ci]){
                ans = add(ans, fun(ci+1, 1, (sum+i)%d));
            }
            if(i==a[ci]){
                ans = add(ans, fun(ci + 1, 0, (sum + i) % d));
            }
        }
    }
    return dp[ci][used][sum] = ans;
}
int solve(){
    string s;
    cin>>s;
    n = s.size();
    a.resize(n);
    
    memset(dp, -1, sizeof(dp));

    for(int i=0;i<n;++i){
        a[i] = s[i]-'0';
    }

    cin>>d;
    ll ans = sub(fun(0, 0, 0), 1);
    cout<<ans; 
    // current index, used, total sum till cur_indx-1
    return 0;
}
int main(){
    fast;
    int t=1;
    // cin>>t;
    while(t--){
        solve();
    }

    return 0;
}

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

#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define int long long int
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define all(a)      (a).begin(),(a).end()
#define rall(a)     (a).rbegin(),(a).rend()

typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<pii> vpii;
typedef vector<vector<int>> vvi;
typedef unordered_map<int,int> uoii;
typedef unordered_map<string,int> uosi;

const int MOD = 1e9+7;

const int INF = 1e10;

int pow(int a,int b){
    if(b==0) 
        return 1;
    int y=pow(a,b/2);
    if(b%2==0){
        return y*y;
    }else{
        return a*y;
    }
}


int32_t main()
{
    
    IOS
    int n;
    cin>>n;
    int le=log2(n);
    cout<<fixed<<setprecision(0)<<(pow(2,le+1)-1);

    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
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 (a>b) { a=b; return 1; } return 0; }

using Lint=long long;

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

    int N,K; cin>>N>>K;
    vector<int> a(N);
    for(int i=0;i<N;i++) cin>>a[i];
    vector<Lint> sum(N+1);
    for(int i=0;i<N;i++) sum[i+1]=(sum[i]+a[i])%K;

    map<int,Lint> cnt;
    cnt[0]++;
    Lint ans=0;
    for(int i=1;i<=N;i++){
        if(i-K>=0){
            int pre=(sum[i-K]-(i-K)%K+K)%K;
            cnt[pre]--;
        }
        int cur=(sum[i]-i%K+K)%K;
        ans+=cnt[cur];
        cnt[cur]++;
    }
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 15104
#include <iostream>
#include <vector>
#include <cassert>
using namespace std;


int M;

typedef vector<int> Vec;
typedef vector<Vec> Mat;
Mat operator*(const Mat& x, const Mat& y) {
    assert(x[0].size() == y.size());
    Mat r(x.size(), Vec(y[0].size()));
    for (size_t i = 0; i < r.size(); i++)
        for (size_t j = 0; j < r[0].size(); j++)
            for (size_t k = 0; k < y.size(); k++)
                r[i][j] = (r[i][j] + x[i][k] * y[k][j]) % M;
    return r;
}

vector<int> solve(int n, int a, int b, int c, int t, vector<int>& S) {
    // Make transition matrix
    Mat A(n, Vec(n));
    for (int i = 0; i < n; i++) {
        if (i - 1 >= 0) A[i][i-1] = a;
        A[i][i] = b;
        if (i + 1 < n) A[i][i+1] = c;
    }

    // Make initial state
    Mat x(n, Vec(1));
    for (int i = 0; i < n; i++) x[i][0] = S[i];

    // multiply t times
    while (t) {
        if (t & 1) x = A * x;
        A = A * A;
        t >>= 1;
    }
    
    // make answer
    vector<int> res(n);
    for (int i = 0; i < n; i++) res[i] = x[i][0];
    return res;
}

int main() {
    int N, A, B, C, T;
    while (true) {
        cin >> N >> M >> A >> B >> C >> T;
        if (N == 0 && M == 0 && A == 0 && B == 0 && C == 0 && T == 0)
            break;
        vector<int> S0(N);
        for (int i = 0; i < N; i++) cin >> S0[i];
        vector<int> res = solve(N, A, B, C, T, S0);
        for (size_t i = 0; i < res.size(); i++) {
            cout << res[i];
            cout << (i != res.size() - 1 ? " " : "\n");
        }
    }
}

Measured memory_bytes: 1248
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define sz(x) ((int)(x).size())
#define rep(i,l,r) for(int i=(l);i<(r);++i)
//-------head-------
const int N = 2e5 + 7;
int a[N];
void solve(int n, int x) {
	if (x == 1 || x == 2 * n - 1) {
		puts("No");
		return ;
	}
	memset(a, -1, sizeof(a));
	a[n] = x, a[n - 1] = 1, a[n + 1] = 2 * n - 1;
	int v = 1;
	rep(i, 1, 2 * n) {
		if (abs(i - n) <= 1)
			continue;
		while (v == x || v == 1 || v == 2 * n - 1)
			++v;
		a[i] = v++;
	}
	puts("Yes");
	rep(i, 1, 2 * n) {
		printf("%d\n", a[i]);
	}
}
int main() {
	int n, x;
	scanf("%d%d", &n, &x);
	solve(n, x);
	return 0;
}

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

int main() {
    int n, ans = 0;
    cin >> n;
    vector<int> a(n);
    vector<vector<pair<int, int>>> liar(n);
    rep(i, n) {
        cin >> a.at(i);
        rep(j, a.at(i)) {
            int x, y;
            cin >> x >> y;
            liar.at(i).push_back(make_pair(x - 1, y));
        }
    }
    rep(i, 2 << n) {
        int cnt = 0;
        bool flag = true;
        vector<int> temp(n);
        rep(j, n) {
            temp.at(j) = 1 & (i >> j);
            cnt += temp.at(j);
        }
        rep(j, n) {
            if(temp.at(j)) {
                rep(k, a.at(j)) {
                    pair<int, int> p = liar.at(j).at(k);
                    if(temp.at(p.first) != p.second) flag = false;
                }
            }
        }
        if(flag) ans = max(ans, cnt);
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
//#include <ext/pb_ds/tree_policy.hpp>
//#include <ext/pb_ds/assoc_container.hpp>
#define ll                  long long int
#define ull                 unsigned long long int
#define ld                  long double
#define fi                  first
#define se                  second
#define pb                  push_back
#define pbb                 pop_back
#define mp                  make_pair
#define popcount            __builtin_popcountll
#define pii     	        pair<int,int>
#define all(x)              x.begin(), x.end()
#define uniq(x)             x.erase(unique(x.begin(),x.end()),x.end())
#define mem(array, value)   memset(array, value, sizeof(array))
#define lcm(a,b)            (abs(a)/gcd(a,b))*abs(b)
#define random(a, b)        ((((rand() << 15) ^ rand()) % ((b) - (a) + 1)) + (a))
#define PI      	        2*acos(0.0)
#define INF     	        1e9
#define EPS     	        1e-8
#define line                cout << "\n==========\n"
#define fastRead 	        ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
using namespace std;
//using namespace __gnu_pbds;
//typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> orderedSet;

//int dx[] = {1, -1, 0, 0},                  dy[] = {0, 0, 1, -1};                  // 4 Direction
//int dx[] = {1, -1, 0, 0, 1, 1, -1, -1},    dy[] = {0, 0, 1, -1, 1, -1, 1, -1};    // 8 Direction
//int dx[] = {1, -1, 1, -1, 2, 2, -2, -2},   dy[] = {2, 2, -2, -2, 1, -1, 1, -1};   // Knight Direction

inline ll gcd(ll a, ll b){
    a = abs(a);
    b = abs(b);
    while (b){
        a = a % b;
        swap (a, b);
    }
    return a;
}
inline ll power(ll a, ll p){
    ll res = 1, x = a;
    while (p){
        if (p & 1){
            res = (res * x);
        }
        x = (x * x);
        p >>= 1;
    }
    return res;
}
inline ll bigmod(ll a, ll p, ll m){
    ll res = 1 % m, x = a % m;
    while (p){
        if (p & 1){
            res = (res * x) % m;
        }
        x = (x * x) % m;
        p >>= 1;
    }
    return res;
}

int main ()
{
    #ifdef Lollipop
    //freopen ("input.txt", "r", stdin);
    //freopen ("output.txt", "w", stdout);
    #endif
    int a, b;
    cin >> a >> b;
    int sqrtN = sqrt(b);
    for (int i = 1; i<=sqrtN; i++){
        if (b%i == 0){
            if (i == a || b/i == a){
                return cout << a+b << endl, 0;
            }
        }
    }
    cout << b-a << endl;
    return 0;
}


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

vector<int> v[100010];
int n,m,x,y,R,a[100010];

int revisar(int i){
    for (int j=0;j<v[i].size();j++)
        if (a[v[i][j]]>=a[i]) return 0;
    return 1;
}

int main(){
    cin.tie(0);
    ios_base::sync_with_stdio(0);
    cin>>n>>m;
    for (int i=1;i<=n;i++) cin>>a[i];
    while (m--){
        cin>>x>>y;
        v[x].push_back(y);
        v[y].push_back(x);
    }
    for (int i=1;i<=n;i++){
        R+=revisar(i);
    }
    cout<<R<<'\n';
}


Measured memory_bytes: 9176
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <set>
#include <cmath>
#include <stdio.h>
#include <list>
#include <numeric>
#include <stack>
#include <queue>
#include <tuple>
#include <bitset>
#include <map>
#include <math.h>
//　ceil(a/b)   (a + (b - 1))/ b
using namespace std;
#define rep(i,n) for(int i = 0; i < (n); i++)
typedef long long ll;
typedef pair<int,int> P;
const int inf=1000000007;
const int mod=1000000007;
const double PI=3.14159265358979323846;
int dx[] = {1,-1,0,0};
int dy[] = {0,0,1,-1};

int gcd(int a, int b){
  if (a%b==0){
    return(b);
  }
  else{
    return(gcd(b,a%b));
  }
}


// ll memo[2020][2020];
// int pascal_triangle(){
//   for(int i = 0; i < 2020; i++){
//     for(int j = 0; j < i+1; j++){
//       if(j == 0 || j == i) memo[i][j] = 1;
//       else{
// 	memo[i][j] = (memo[i-1][j-1]+memo[i-1][j]);
//       }
//     }
//   }
//   return 0;
// }


int factorial(int n){
  if(n == 0) return 1;
  return n*factorial(n-1);
}

int divisor(int a){
  int cnt = 0;
  for(int i=1; i <= a; i++) if(a%i == 0) cnt++;
  return cnt;
}

int comb(int n, int k){
  return factorial(n) / (factorial(n-k)*factorial(k));
}

int answer(bool f){
  if(f) cout << "Yes" << endl;
  else cout << "No" << endl;
  return 0;
}






int main(){
  int N;
  int X;
  cin >> N;
  cin >> X;
  
  int ans = N;
  int m = inf;
  rep(i,N){
    int a;
    cin >> a;
    X-=a;
    m = min(a,m);
  }
  ans += X/m;
  cout << ans << endl;
  
    
  
  
  return 0;
}









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

int main(){
  int l, r;
  cin >> l >> r;
  int ans = 5000;
  for(long long int i = l; i <= min(r, l+4038); i++){
    for(long long int j = i + 1;  j <= min(r, l+4038); j++){
      int temp = (i*j)%2019;
      ans = min(ans, temp);
    }
  }
  cout << ans << endl;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;
typedef long long ll;
typedef double db;
typedef vector <ll> vll;
typedef pair <ll, ll> pll;
#define pb push_back
#define mp make_pair
#define MAX 1000000
#define mod 1000000007
#define all(_) _.begin(), _.end()
#define F first
#define S second
#define ordered_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update>

int main()
{
    ios_base :: sync_with_stdio(false);
    cin.tie(NULL), cout.tie(NULL);
    ll n, i, ans = 0, u, v;
    cin >> n;
    for(i = 1; i <= n; i++)
        ans += i * (n - i + 1);
    for(i = 0; i < n - 1; i++)
    {
        cin >> u >> v;
        if(u > v)
            swap(u, v);
        ans -= u * (n - v + 1);
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 3644
n, m = gets.split.map(&:to_i)
arr = gets.split.map(&:to_i)
hash = {}

m.times do |i|
  a,b = gets.split.map(&:to_i)
  hash[a] = (hash[a] || []).push(b)
  hash[b] = (hash[b] || []).push(a)
end

cnt = n - hash.count
hash.each do |k,v|
  i = k - 1
  varr = v.map { |l| arr[l-1] }
  cnt += 1 if arr[i] > varr.max
  if arr[i] > v.max
  end
end
puts cnt

Measured memory_bytes: 33212
#include<cstdio>
#include<algorithm>
#include<iostream>
#include<cstring>
#include<string>
#include<algorithm>
using namespace std;
long  yaku,bai,a,b;
long long  fe;

int GCD(int x,int y){
  if(y==0){
    return x;
  }
  else{    
    return GCD(y,x%y);
  }
}
int main(){
  for(;cin>>a;){
    cin>>b;
    if(a>b){
      yaku=GCD(a,b);
    }
    else{
      yaku=GCD(b,a);
    }
    fe = a*b;
    cout<<yaku<<" "<<fe/yaku<<endl;
  }
}

Measured memory_bytes: 1160
import java.util.Scanner;

public class Main {
	public static void main(String[] args)
	{
		Scanner stdIn = new Scanner(System.in);
		int[] x = new int[50];
		int[] y = new int[50];
		
		while(true)
		{
			int n = stdIn.nextInt();
			int r = stdIn.nextInt();
			
			if(n==0 && r==0)
			{
				break;
			}
			
			if((n>=1 && n<=50) && (r>=1 && r<=50))
			{
			for(int i=0;i<n;i++)
			{
				x[i] = n-i;
			}
			
			for(int i=0;i<r;i++)
			{
				int s = stdIn.nextInt();
				int t = stdIn.nextInt();
				
				if(s<=n+1-t)
				{
					for(int j=0;j<t;j++)
					{
						y[j] = x[s+j-1];
					}	
				
					for(int j=0;j<s-1;j++)
					{
						y[t+j] = x[j];
					}	
				
					for(int j=0;j<s+t-1;j++)
					{
						x[j] = y[j];
					}
				}
				
			}
			
			System.out.println(x[0]);
		}
		}
	}

}

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

#define REP(i,n) for (int i=0;i<(n);++i)
#define RREP(i,n) for (int i=(n)-1;i>=0;--i)
#define all(a) (a).begin(),(a).end()

using namespace std;

using triple = tuple<int, int, int>;

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

    int N;
    cin >> N;
    vector<int> dp(N + 1, 0);
    vector<triple> v;
    REP(i, N) {
        int X, L;
        cin >> X >> L;
        v.emplace_back(X - L, X, L);
    }
    sort(all(v));

    RREP(i, N) {
        int left, X, L;
        tie(left, X, L) = v[i];
        int k = distance(v.begin(), lower_bound(v.begin() + i, v.end(), make_tuple(X + L, 0, 0)));
        dp[i] = max(dp[i + 1], 1 + dp[k]);
    }

    cout << dp[0] << endl;

    return 0;
}

Measured memory_bytes: 2296
#include <iostream>
#include <algorithm>
using namespace std;
static const int MAX=200000;

int main()
{
    int R[MAX],n;
    cin>>n;
    for(int i=0;i<n;i++)
        cin>>R[i];
    int maxv=-2000000000;
    int minv=R[0];

    for(int i=1;i<n;i++) 
    {
        maxv=max(maxv,R[i]-minv);  
        minv=min(minv,R[i]); 
    }
    cout<<maxv<<endl;
    return 0;
}


Measured memory_bytes: 3876
#include <bits/stdc++.h>
using namespace std;
using P=pair<int,int>;
using G=vector<vector<int>>;
using ll=long long;

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

  int dp[n];
  dp[0]=0;
  dp[1]=abs(h[1]-h[0]);

  for(int i=2;i<n;i++){
    dp[i]=min(dp[i-1]+abs(h[i]-h[i-1]),dp[i-2]+abs(h[i]-h[i-2]));
  }

  cout<<dp[n-1]<<endl;
}

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

#define mp       make_pair
#define pb       push_back
#define all(x)   (x).begin(),(x).end()
#define rep(i,n) for(int i=0;i<(n);i++)
#define REP(i,b,n) for(int i=b;i<n;i++)

using namespace std;

typedef    long long          ll;
typedef    unsigned long long ull;
typedef    vector<bool>       vb;
typedef    vector<int>        vi;
typedef    vector<vb>         vvb;
typedef    vector<vi>         vvi;
typedef    pair<int,int>      pii;

const int INF=1<<29;
const double EPS=1e-9;

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

int main(){
	int n;
	while(cin>>n){
		if(n==0)break;
		vector<pii> data;
		data.clear();
		for(int i =0;i <n;i++){
			int v,w;
			cin>>v>>w;
			data.push_back(pii(w,v));
		}
		sort(data.begin(),data.end());
		int sum =0;
		bool flag =true;
		for(int i =0;i <data.size();i++){
			sum +=(data[i].second);
			if(sum>data[i].first){
				cout<<"No"<<endl;
				flag =false;
				break;
			}
		}
		if(flag)cout<<"Yes"<<endl;
	}
	return 0;
}

Measured memory_bytes: 1192
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Practice
{
    class Program
    {
        static void Main(string[] args)
        {
            Solve();
        }
        private const long MOD = 1000000007;
        static void Solve()
        {
            var o = ReadAndParseLongArr();
            long n = o[0];
            long a = o[1];
            var x = ReadAndParseLongArr();
            long maxX = 50;
            long[,,] dp = new long[n + 1, n + 1, n * maxX + 1];

            dp[0, 0, 0] = 1;
            for (long i = 1; i <= n; ++i)
            {
                for (long j = 0; j <= i; ++j)
                {
                    for (long sum = 0; sum <= n * maxX; ++sum)
                    {
                        if (sum - x[i - 1] >= 0 && j >= 1)
                        {
                            dp[i, j, sum] = dp[i - 1, j, sum] + dp[i - 1, j - 1, sum - x[i - 1]];
                        }
                        else
                        {
                            dp[i, j, sum] = dp[i - 1, j, sum];
                        }
                    }
                }
            }
            long ans = 0;
            for (long j = 1; j <= n; ++j)
            {

                ans += dp[n, j, j * a];

            }
            Console.WriteLine(ans);
        }
        
        #region よく使う便利関数
        private static bool isPrime(long x)
        {
            if (x == 2) { return true; }
            if (x < 2 || x % 2 == 0) { return false; }
            long i = 3;
            while (i * i <= x)
            {
                if (x % i == 0) { return false; }
                i = i + 2;
            }
            return true;
        }
        private static long lcm(long x, long y)
        {
            return x / gcd(x, y) * y;
        }
        private static long gcd(long x, long y)
        {
            return y > 0 ? gcd(y, x % y) : x;
        }
        private static long pow(long x, long n)
        {
            if (n == 0) { return 1; }
            long res = pow(x * x % MOD, n / 2);
            if (n % 2 == 1)
            {
                res = res * x % MOD;
            }
            return res;
        }
        private static int ReadAndParseInt()
        {
            return int.Parse(Console.ReadLine());
        }
        private static int[] ReadAndParseIntArr()
        {
            return Array.ConvertAll(Console.ReadLine().Split(' '), int.Parse);
        }
        private static long ReadAndParseLong()
        {
            return long.Parse(Console.ReadLine());
        }
        private static long[] ReadAndParseLongArr()
        {
            return Array.ConvertAll(Console.ReadLine().Split(' '), long.Parse);
        }
        #endregion
    }
}

Measured memory_bytes: 60128
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
using ll = long long;
ll GetDigit(ll num){ return log10(num)+1; } //numの桁数を求める

int main()
{
    string a,b,c;
    cin >> a >> b >> c;
    int n = a.length() + b.length() + c.length();
    int na=0,nb=0,nc=0;
    char now = 'a';
    rep(i,n){
        if(now == 'a'){
            if(a[na] == 'a') now = 'a';
            else if(a[na] == 'b') now = 'b';
            else if(a[na] == 'c') now = 'c';
            na++;
            if(na == a.length()+1){
                cout << "A" << endl;
                return 0;
            }
        }else if(now == 'b'){
            if(b[nb] == 'a') now = 'a';
            else if(b[nb] == 'b') now = 'b';
            else if(b[nb] == 'c') now = 'c';
            nb++;
            if(nb == b.length()+1){
                cout << "B" << endl;
                return 0;
            }
        }else if(now == 'c'){
            if(c[nc] == 'a') now = 'a';
            else if(c[nc] == 'b') now = 'b';
            else if(c[nc] == 'c') now = 'c';
            nc++;
            if(nc == c.length()+1){
                cout << "C" << endl;
                return 0;
            }
        }
    }
    return 0;
}

Measured memory_bytes: 3632
#include <algorithm>
#include <cassert>
#include <cmath>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
using namespace std;
typedef long long ll;
// const int INF = (1 << 30) - 1;
// const ll LL_INF = (1LL << 62) - 1;
// const ll MOD = 1e9 + 7;

ll X, Y, A, B, C;
vector<ll> p, q, r;

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cin >> X >> Y >> A >> B >> C;
  p.resize(A);
  for (int i = 0; i < A; i++) {
    int tmp;
    cin >> tmp;
    p[i] = tmp;
  }
  q.resize(B);
  for (int i = 0; i < B; i++) {
    int tmp;
    cin >> tmp;
    q[i] = tmp;
  }
  r.resize(C);
  for (int i = 0; i < C; i++) {
    int tmp;
    cin >> tmp;
    r[i] = tmp;
  }
  sort(p.begin(), p.end(), greater<ll>());
  sort(q.begin(), q.end(), greater<ll>());

  priority_queue<ll, vector<ll>, greater<ll>> q_p;
  priority_queue<ll, vector<ll>, greater<ll>> q_q;
  for (int i = 0; i < X; i++) {
    q_p.push(p[i]);
  }
  for (int i = 0; i < Y; i++) {
    q_q.push(q[i]);
  }

  for (int i = 0; i < C; i++) {
    ll p_min = q_p.top();
    q_p.pop();
    ll q_min = q_q.top();
    q_q.pop();

    if (p_min < q_min && p_min < r[i]) {
      q_p.push(r[i]);
      q_q.push(q_min);
    } else if (q_min <= p_min && q_min < r[i]) {
      q_p.push(p_min);
      q_q.push(r[i]);
    } else {
      q_p.push(p_min);
      q_q.push(q_min);
    }
  }

  ll ans = 0;
  while (!q_p.empty()) {
    ll p_min = q_p.top();
    q_p.pop();
    ans += p_min;
  }
  while (!q_q.empty()) {
    ll q_min = q_q.top();
    q_q.pop();
    ans += q_min;
  }

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


Measured memory_bytes: 4852
#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; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }

#define FOR(i,a,b) for(ll i=(a);i<(b);++i)
#define ALL(v) (v).begin(), (v).end()
#define p(s) cout<<(s)<<endl
#define p2(s, t) cout << (s) << " " << (t) << endl
#define br() p("")
#define pn(s) cout << (#s) << " " << (s) << endl
#define p_yes() p("Yes")
#define p_no() p("No")

const ll mod = 1e9 + 7;
const ll inf = 1e18;

template < typename T >
void vprint(T &V){
	for(auto v : V){
    	cout << v << " ";
	}
	cout << endl;
}

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

    // input
    ll r, d, x;
    cin >> r >> d >> x;
    
    FOR(i, 0, 10){
        x = r*x-d;
        p(x);
    }
    
    return 0;
}

Measured memory_bytes: 256
N = int(input())
A = list(map(int, input().split()))

l = [0] *(10**6+1)

for i in range(N):
    num = A[i]
    if l[num] != 0:
        l[num] = 2
        continue
    for j in range(num, 10**6+1, num):
        l[j] += 1
ans = 0
for i in range(N):
    num = A[i]
    if l[num] == 1:
        ans += 1
print(ans)


Measured memory_bytes: 32156
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
constexpr ll INF = 1'010'000'000'000'000'017LL;
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define all(v) v.begin(), v.end()

int main() {
    ll n;
    cin >> n;
    vector<ll> fz;
    ll cnt = 0;

    for(size_t i = 1; i <= n; i++) {
        if(i % 3 != 0 && i % 5 != 0)
            cnt += i;
    }
    cout << cnt;
}


Measured memory_bytes: 3640