akhauriyash/Code-Regression huggingface dataset:
#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>

using namespace std;

//vector string deque break continue
#define forn(i, s, f) for (int i = (int)s; i < (int)f; i++)
#define ll long long
#define ull unsigned long long
#define ld long double
#define pii pair <int, int>
#define fs first
#define sc second
#define pf push_front
#define pb push_back
#define pop_f pop_front
#define pop_b pop_back
#define eb emplace_back
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define sz(x) (int)(x).size()

#define int long long

main() {
    ios_base::sync_with_stdio(0), cin.tie(0);
    int t1, t2, a1, a2, b1, b2;
    cin >> t1 >> t2 >> a1 >> a2 >> b1 >> b2;
    a1 *= t1, b1 *= t1, a2 *= t2, b2 *= t2;
    if (a1 + a2 == b1 + b2) {
        cout << "infinity";
        return 0;
    }
    //cout << t1 * a1 + t2 * a2 << " " << t1 * b1 + t2 * b2;
    if (a1 < b1) {
        swap(a1, b1);
        swap(a2, b2);
    }
    if (a1 + a2 > b1 + b2)
        cout << 0;
    else {
        if ((b1 - a1) % (a1 + a2 - b1 - b2))
            cout << 2 * ((b1 - a1) / (a1 + a2 - b1 - b2)) + 1;
        else
            cout << 2 * ((b1 - a1) / (a1 + a2 - b1 - b2));
    }
    return 0;
}

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

int main() {
  int N;
  cin >> N;
  vector<int> v(N);
  for (int i = 0; i < N; i++) {
    cin >> v.at(i);
  }
  
  int p = 1, cnt = 0;
  for (int i = 0; i < N; i++) {
    p = v.at(--p);
    cnt++;
    if (p == 2) break;
  }
  
  if (cnt < N) {
    cout << cnt << endl;
  }
  else {
    cout<< -1 << endl;
  }
}

Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
 
int main(int argc, char *argv[])
{
  int K, N;
  cin >> K >> N;
  
  vector<int> A(N);
  cin >> A[0];
  for (int i=1; i<N; i++)
    cin >> A[i];
  
  int max_len = 0;
  max_len = A[0] + K - A[N-1];
  for (int i=0; i<N-1; i++)
    if (max_len < A[i+1] - A[i])
      max_len = A[i+1] - A[i];
  
  cout << K - max_len << endl;
    
  
  return 0;
}

Measured memory_bytes: 1024
#include<bits/stdc++.h>
using ll  = long long;
#define int ll
#define rep(i,n) for(int i=0;i<n;i++)
#define loop(i,s,n) for(int i=s;i<n;i++)
#define erep(e,v) for(auto && e :v)
#define all(in) in.begin(), in.end()
#define MP make_pair
#define INF (sizeof(int) == 4 ? 1e9:1e18)
#define EPS 0.0000000001
using namespace std;
template<class T, class S> void cmin(T &a, const S &b) { if (a > b)a = b; }
template<class T, class S> void cmax(T &a, const S &b) { if (a < b)a = b; }
template<typename Head, typename Value> auto vectors(const Head &head, const Value &v) { return vector<Value>(head, v); }
template<typename Head, typename... Tail> auto vectors(Head x, Tail... tail) { auto inner = vectors(tail...); return vector<decltype(inner)>(x, inner); }
template<class T> void join(T a){for(auto itr :a){if(itr != *a.begin())cout << " "; cout << itr;} }
using ld  = long double;
using pii = pair<int,int>;
using piii = pair<int,pii>;
int W,H;
int dx[]={0,0,1,-1}, dy[]={1,-1,0,0};
bool valid(int x,int y){return (0<=x&&x<W)&&(0<=y&&y<H);}
signed main(){
    int ans = 0;
    int n; cin >> n;
    for(int i = n; i >= 1;i-- ){
        if (i %2){
            int temp = 0;
            for(int j = i; j >= 1;j--)
                if(i%j ==0)temp++;
        if (temp == 8)ans++;
        }
    }
    cout << ans << endl;
}




Measured memory_bytes: 256
/*
    Written by Nitrogens
    Desire for getting accepted!!
*/
#include <cstdio>
#include <ctime>
#include <cstring>
#include <cmath>
#include <cstdlib>
#include <iostream>
#include <algorithm>
#include <queue>
#include <map>
#include <bitset>
#include <stack>
#include <set>
#include <vector>
using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef double db;
typedef pair <int, int> pii;
typedef pair <ll, ll> pll;
typedef pair <ll, int> pli;
typedef pair <db, db> pdd;

const int maxn = 1e5+5;
const int Mod = 1000000007;
const int INF = 0x3f3f3f3f;
const ll LL_INF = 0x3f3f3f3f3f3f3f3f;
const double e = exp(1);
const db PI = acos(-1);
const db ERR = 1e-10;

#define Se second
#define Fi first
#define pb push_back
#define dbg(x) cout<<#x<<" = "<< (x)<< endl
#define dbg2(x1,x2) cout<<#x1<<" = "<<x1<<" "<<#x2<<" = "<<x2<<endl
#define dbg3(x1,x2,x3) cout<<#x1<<" = "<<x1<<" "<<#x2<<" = "<<x2<<" "<<#x3<<" = "<<x3<<endl

int main()
{
    //ios::sync_with_stdio(false);
    //freopen("a.txt","r",stdin);
    //freopen("b.txt","w",stdout);

    int a, b, c;
    scanf("%d%d%d", &a, &b, &c);

    int answer = min(c, b / a);
    printf("%d\n", answer);

    //cout << "time: " << (long long)clock() * 1000 / CLOCKS_PER_SEC << " ms" << endl;
    return 0;
}


Measured memory_bytes: 888
#include "bits/stdc++.h"
using namespace std;

typedef long long ll;
typedef vector<ll> vl;
typedef vector<vector<ll>> vvl;
typedef pair<ll, ll> P;
#define rep(i, n) for(ll i = 0; i < n; i++)
#define REP(i, a, b) for(ll i = a; i <= b; i++)
#define out(x) std::cout << x << '\n'
#define all(a) a.begin(), a.end()
#define pb push_back
#define sz(x) ((int)(x).size())
#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)
ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; }
ll lcm(ll a, ll b) { ll g = gcd(a, b); return a / g * b; }
const int dx[4] = { 1, 0, -1,  0 };
const int dy[4] = { 0, 1,  0, -1 };
const int INF = (int)1e9;
const ll  inf = (ll)1e18;
const int mod = 1000000007;
const int MAX_N = 100010;

ll func(ll x) {
	ll p = ((x + 1) / 2) % 2 == 0 ? 0 : 1;
	ll r = (x % 2 == 0) ? x + p : p;
	return r;
}

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

	ll a, b;
	cin >> a >> b;

	ll ans = func(a - 1) ^ func(b);

	out(ans);

	return 0;
}

Measured memory_bytes: 256
package main

import "fmt"

func sum(x int) int {
	s := 0
	for x > 0 {
		s += x % 10
		x /= 10
	}
	return s
}

func main() {
	var n int
	fmt.Scan(&n)
	s := sum(n)
	if n%s == 0 {
		fmt.Println("Yes")
	} else {
		fmt.Println("No")
	}
}


Measured memory_bytes: 512
#include<bits/stdc++.h>
using namespace std;
//typedef pair<int, int> P;
vector<pair<int, pair<int, int> > > v;

int main(){
while(1){//start

	int H, W;
	cin >> H >> W;
	if(H == 0 and W == 0) break;
	int D = H * H + W * W;

	for(int h = 1; h <= 150; h++){
		for(int w = 1; w <= 150; w++){
			int d = h * h + w * w;
			if(D < d and h < w ) v.push_back(make_pair(d, make_pair(h, w)));
			else if(D == d and h < w and H < h) v.push_back(make_pair(d, make_pair(h, w)));
		}
	}

	sort(v.begin(), v.end());

	cout << v[0].second.first << " " << v[0].second.second << endl;

	//init
	v.clear();
}//end

	return 0;
}



Measured memory_bytes: 3184
function Main(input) {
  input = input.split("\n");
  var S = input[0].split("").map(x => ~~x);
  dp = [...Array(S.length)].fill(0);

  dp[0]=0;

  for(var i=0; i < S.length; i++){
    if(S[i+1] == S[i]){
      dp[i+1]=dp[i]+1;
      if(S[i+1] == 0){
        S[i+1]=1;
      }else if(S[i+1] == 1){
        S[i+1]=0;
      }
    }else{
      dp[i+1]=dp[i];
    }
  }
console.log(dp[S.length-1]);

}

var input=Main(require("fs").readFileSync("/dev/stdin", "utf8"));
// var input=`000`
// Main(input);


Measured memory_bytes: 15924
#include<bits/stdc++.h>
using namespace std;
#define arep(i,x,n) for(int i=int(x);i<(int)(n);i++)
#define rep(i,n) for(long long i = 0;i < n;++i)
#define pi 3.141592653589793
#define eps 0.00000001
#define INF 1e9+7  
using ll = long long;
using P = pair<int, int>;
using lP = pair<ll, ll>;
using fP = pair<double, double>;
ll const mod = 998244353;
const ll MAX = 300000;
using vi = vector<int>;
using vc = vector<char>;
using vs = vector<string>;
using vvi = vector<vector<int>>;
using vvc = vector<vector<char>>;
using vvp = vector<vector<P>>;
int main() {
    int a, b;
    cin >> a >> b;
    int x = a / 0.08, y = b / 0.1;
    double e = 0.08, f = 0.1;

    if (x > y) {
        swap(x, y);
        swap(e, f);
        swap(a, b);
    }
    for (int i = x; i <= y+10; i++) {
        int t = i * e, s = i * f;
        if (t == (int)a && s == b) {
            cout << i << endl;
            return 0;
        }
    }
    cout << -1 << endl;
    return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<string>
#include<stack>
#include<queue>
#include<utility>
#include<algorithm>
using namespace std;
#define ll long long
#define vel vector<ll>
#define vvel vector<vel>
#define vvvel vector<vvel>
#define veb vector<bool>
#define pin pair<ll,ll>
#define mkp make_pair
#define mot pair<D,D>//time,dist
#define path pair<ll,int>//cost,to
#define int long long
using namespace std;
vvel ta_min(0);
vvel ta_max(0);
int leth = 1024 * 512;
int p = 1000000007;
vel par;
vel dis;
int n;
void mmax(ll &a, ll b) { a = max(a, b); }
void mmin(ll &a, ll b) { a = min(a, b); }
pin root(int ser) {
	if (par[ser] == -1) {return mkp(ser,0);}
	pin x=root(par[ser]);
	x.second += dis[ser];
	par[ser] = x.first;
	dis[ser] = x.second;
	return x;
}
void uni(int a, int b,int d) {
	pin p1 = root(a);
	pin p2 = root(b);
	int a1 = p1.first;
	int b1 = p2.first;
	if (a1 != b1) {
		par[b1] = a1;
		dis[b1] = d + dis[a] - dis[b];
	}
}
bool issame(int x, int y) {
	return root(x).first == root(y).first;
}
void ref(int &x) { x = x % p; x = (x + p) % p; }
int rui(int a, int n) {
	if (n == 0) { return 1; }
	int x = rui(a, n / 2);//return a^n%p
	x *= x; ref(x);
	if (n % 2 == 1) { x *= a; }
	ref(x);
	return x;
}
signed main() {
	int n, a, b; cin >> n >> a >> b;
	vel ans(0);
	if (a + b - 1 <=n and n<= a * b) {
		vel le(b,1);
		le[0] = a;
		int ex = n - a - b + 1;
		int ind = 1;
		while (ex > 0) {
			le[ind] = 1 + min(ex, a - 1);
			ex -= min(ex, a - 1);
			ind++;
		}
		int inf = n;
		for (int i = 0; i < b; i++) {
			inf -= le[i];
			for (int j = 0; j < le[i]; j++) {
				ans.push_back(inf + j + 1);
			}
		}
		for (int i = 0; i < n - 1; i++) { cout << ans[i] << " "; }
		cout << ans[n - 1] << endl;
	}
	else { cout << "-1" << endl; }
	return 0;
}

Measured memory_bytes: 7280
S = list(input())
List = set(["A", "T", "G", "C"])
cnt = 0
ResMax = 0

for i in S:
    if i in List:
        cnt += 1
    else:
        if cnt > ResMax:
            ResMax = cnt
        cnt = 0

if cnt > ResMax:
    ResMax = cnt
    
print(ResMax)

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

int main(void) {
	int W, H;
	int x, y, r;
	cin >> W >> H >> x >> y >> r;
	if (r <= x && x <= (W - r) && r <= y && y <= (H - r)) {
		cout << "Yes" << endl;
	} else {
		cout << "No" << endl;
	}
	return 0;
}




Measured memory_bytes: 3128
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <vector>
#include <cstring>
#include <queue>
#include <set>
#include <map>
#include <functional>
#include <string>
#define SIZE 105
using namespace std;
typedef long long int ll;
typedef pair <int,int> P;
int A[SIZE];
int B[SIZE];
int main()
{
int n;
scanf("%d",&n);
for(int i=0;i<n;i++) scanf("%d",&A[i]);
for(int i=0;i<n;i++) scanf("%d",&B[i]);

int ret=0;
for(int i=0;i<n;i++)
{
int sum=0;
for(int j=0;j<=i;j++) sum+=A[j];
for(int j=i;j<n;j++) sum+=B[j];
ret=max(ret,sum);
}
printf("%d\n",ret);
return 0;
}

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

int main() {
  int a,b;
  cin >> a >> b;
  int x = (a * b) % 2;
  if (x == 1) {
    cout << "Odd" << endl;
  }
  else {
    cout << "Even" << endl;
  }
   
}




Measured memory_bytes: 256
//
// Created by yuu on 2019-04-19.
//

#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <map>
#include <utility>
#include <math.h>
#include <stack>
#include <queue>

using namespace std;


int main(void){

    int N;
    int W;

    int vw[110][2];
    long long dp[110][100010]={};

    cin>>N>>W;

    for (int i = 0; i < N; ++i) {
        cin>>vw[i][1]>>vw[i][0];
    }

    for (int i = 0; i < N; ++i) {
        for (int weight = 0; weight <= W; ++weight) {

            if(weight - vw[i][1] >=0){
                dp[i+1][weight] = max(dp[i+1][weight], dp[i][weight - vw[i][1]] + vw[i][0]);
            }

            dp[i+1][weight] = max(dp[i+1][weight], dp[i][weight]);
        }
    }

    cout<<dp[N][W]<<endl;





    return 0;
}

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

class UnionFind {  
public:
  vector<long long> par;
  vector<long long> rank;

  UnionFind(long long N) : par(N + 1), rank(N + 1){
    for(int i = 0; i <= N; i++){  
      par[i] = i;
      rank[i] = 1;
    }
  }

  long long root(long long x){  
    if (par[x] == x) return x;
    return par[x] = root(par[x]);
  }

  long long size(long long x){  
    return rank[root(x)]; 
  }

  void unite(long long x, long long y){  
    long long rx = root(x); 
    long long ry = root(y);
    if (rx == ry) return;

    if(rank[rx] < rank[ry]){  
      par[rx] = ry; 
    } else{  
      par[ry] = rx;
      if(rank[rx] == rank[ry]) rank[rx]++; 
    }
  }

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

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout << setprecision(20) << fixed;
  int N, K, L;
  cin >> N >> K >> L;
  UnionFind car(N), train(N);
  for(int i = 0; i < K; i++){  
    int p, q;
    cin >> p >> q;
    car.unite(p, q);
  }
  for(int i = 0; i < L; i++){  
    int p, q;
    cin >> p >> q;
    train.unite(p, q);
  }
  vector<vector<long long>> G(N+1);
  vector<long long> ans(N+1);
  for(int i = 1; i <= N; i++){  
    G[train.root(i)].push_back(i); 
  }
  /*
  for(int i = 0; i <= N; i++){  
    cout << i << " " << train.par[i] <<endl; 
  }
  
  for(auto vec: G){  
    for(auto x : vec){  
      cout << x << " "; 
    } 
    cout <<endl;
  }
  //*/
  for(auto vec: G){  
    map<long long, long long> v;
    for(auto x: vec){  
      v[car.root(x)]++; 
    }
    for(auto x: vec){  
      ans[x] += v[car.root(x)]; 
    }
  }
  for(int i = 1; i <= N; i++) cout << ans[i] << " ";
}


Measured memory_bytes: 23372
#include <iostream>
#include <vector>

using namespace std;



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

int W, H;
int field[50][50];

void dfs(int field[50][50], int sx, int sy) {

    field[sy][sx] = 0;

    for (int i = 0; i < 8; i++) {
        int nx = sx + dx[i];
        int ny = sy + dy[i];

        if (0 <= nx && nx < W && 0 <= ny && ny < H && field[ny][nx] == 1) {
            dfs(field, nx, ny);
        }
    }
}

int main(void) {
    
    while (true) {
        cin >> W >> H;

        if (W == 0 && H == 0) break;
        
        for (int i = 0; i < H; i++) {
            for (int j = 0; j < W; j++) {
                cin >> field[i][j];
            }
        }

        int count = 0;

        for (int i = 0; i < H; i++) {
            for (int j = 0; j < W; j++) {
                if (field[i][j] == 1) {
                    dfs(field, j, i);
                    count++;
                }
            }
        }

        cout << count << endl;
    }

    return 0;
}



Measured memory_bytes: 3116
import sys
input = sys.stdin.readline
import itertools

N,B = map(int,input().split())
X = [int(x) for x in input().split()]

Xcum = tuple(itertools.accumulate(X))

coef = [2] * N
coef[0] = 5
coef[1] = 0

answer = min(sum(x*y for x,y in zip(Xcum[::-n], coef[:1+(N-1)//n])) + B*(N+n) for n in range(1,N+1))
print(answer)

Measured memory_bytes: 25268
import sys

read = sys.stdin.read
readline = sys.stdin.readline
readlines = sys.stdin.readlines
sys.setrecursionlimit(10 ** 9)
INF = 1 << 60


def main():
    N = int(readline())
    K = (1 + (8 * N + 1) ** 0.5) / 2
    if not K.is_integer():
        print('No')
        return
    K = int(K)

    ans = [[] for _ in range(K)]
    num = 1
    for k in range(K):
        for l in range(k + 1, K):
            ans[k].append(num)
            ans[l].append(num)
            num += 1
    print('Yes')
    print(K)
    for row in ans:
        print(K - 1, *row)


if __name__ == '__main__':
    main()


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

using namespace std;

const int MOD = 1000000007;

int64_t modpow(int64_t base, int64_t k, int64_t mod) {
  base %= mod;
  int64_t answer = 1;
  while (k > 0) {
    if (k & 1) answer = (answer * base) % mod;
    base = (base * base) % mod;
    k >>= 1;
  }
  return answer;
}

int main() {
  int64_t N;
  cin >> N;
  int64_t answer = modpow(10, N, MOD) + modpow(8, N, MOD) + (MOD - modpow(9, N, MOD)) * 2;
  answer %= MOD;
  cout << answer << endl;
  return 0;
}


Measured memory_bytes: 3636
#include <bits/stdc++.h>
#define rep(i, n) for (ll i = 0; i < (n); ++i)
#define rep1(i, n) for (ll i = 1; i <= (n); ++i)
#define rrep(i, n) for (ll i = (n - 1); i >= 0; --i)
#define ALL(obj) (obj).begin(), (obj).end()
#define pb push_back
#define to_s to_string
#define len(v) (int)v.size()
#define UNIQUE(v) v.erase(unique(v.begin(), v.end()), v.end())
#define print(x) cout << (x) << '\n'
#define debug(x) cout << #x << ": " << (x) << '\n'
using namespace std;
using ll = long long;
typedef pair<ll, ll> P;
ll MOD = 1e9 + 7;
ll devc(ll x, ll y) { return 1 + (x - 1) / y; }

vector<string> ans;

void func(string S, ll prev, ll N){
    if(len(S) == N){
        ans.pb(S);
        return;
    }

    rep(i,prev+1){
        char x = 'a' + i;

        ll tmp = 0;
        rep(j, len(S)) tmp = max(tmp, ll(S[j] - 'a'));

        if(i > tmp) func(S + x, prev + 1, N);
        else func(S+x, prev, N);
    }
}

int main()
{
    cin.tie(0);
    ios::sync_with_stdio(0);
    cout << fixed << setprecision(20);

    ll N;
    cin >> N;

    func("a", 1, N);
    sort(ALL(ans));
    for(auto s : ans) print(s);
    return 0;
}

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

int main(){
  int N;
  cin>>N;
  int l=72;
  for(int i=1;i<=(N+1)/2;i++){
    int j=0;
    for(int k=i;k>0;k/=10)
      j+=k%10;
    for(int k=N-i;k>0;k/=10)
      j+=k%10;
    l=min(l,j);
  }
  cout<<l<<endl;
}

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

#define MOD 1000000007

using ll = long long;


int main(void) {
    int n,m;
    cin >> n >> m;
    long ans;
    ans = (1900 * m + 100 * (n-m));
    for(int i=0;i<m;i++){
        ans *= 2;
    }
    
    cout << ans << endl;
    return 0;
}



Measured memory_bytes: 256
S = input()
n = len(S)
zero_first = 0
one_first = 0
for i in range(n):
  if i % 2 == 0:
    if S[i] == '0':
      one_first += 1
    else:
      zero_first += 1
  else:
    if S[i] == '1':
      one_first += 1
    else:
      zero_first += 1
print(min(one_first, zero_first))

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

using namespace std;

typedef long long ll;

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

	string S;
	cin >> S;

	vector<string> v;
	v.push_back("dream");
	v.push_back("dreamer");
	v.push_back("erase");
	v.push_back("eraser");

	int l = S.size();

	bool updated = true;
	while(l > 0 && updated){
		updated = false;
		rep(i, 4){
			string t = v[i];
			int x = t.size();
			if(!updated && l - x >= 0 && S.substr(l-x, x) == t){
				updated = true;
				l -= x;
			}
		}
	}

	if(l > 0){
		cout << "NO" << endl;
	}else{
		cout << "YES" << endl;
	}
}


Measured memory_bytes: 512
#include <bits/stdc++.h>
#define be(v) (v).begin(),(v).end()
#define pb(q) push_back(q)
typedef long long ll;
using namespace std;
const ll mod=1000000007, INF=(1LL<<60);
#define doublecout(a) cout<<fixed<<setprecision(10)<<a<<endl;

int main() {
    cin.tie(0);
    cout.tie(0);
    ios::sync_with_stdio(false);
    int s = 0;
    for(int i=0;i<5;i++){
    	int a;
    	cin >> a;
    	s += a;
    }
    cout << 15 - s << endl;
    return 0;
}


Measured memory_bytes: 3648
#include <algorithm>
#include <bitset>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <fstream>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>

using namespace std;

typedef long long ll;
typedef pair<int,int> PP;

/*
 freopen("input","r",stdin);
 freopen("output","w",stdout);
*/

ll MOD;

const int p = 2000;

ll F[6001][8001];

int main() {
    ios::sync_with_stdio(false);
    cin.tie(NULL);
    memset(F, 0, sizeof(F));
    F[0][p] = 1;
    int N;
    cin >> N >> MOD;
    for (int i = 0;i < 3 * N;i++) {
        for (int j = p - N;j <= p + 3 * N;j++) {
            // Place a 3
            if (i + 3 <= 3 * N) {
                ll num = ((i + 2) * (i + 1)) % MOD;
                F[i + 3][j] += (num * F[i][j]) % MOD;
                F[i + 3][j] %= MOD;
            }
            // Place a 1
            if (i + 1 <= 3 * N) {
                F[i + 1][j + 1] += F[i][j];
                F[i + 1][j + 1] %= MOD;
            }
            // Place a 2
            if (i + 2 <= 3 * N && j - 1 >= 0) {
                F[i + 2][j - 1] += ((i + 1) * F[i][j]) % MOD;
                F[i + 2][j - 1] %= MOD;
            }
        }
    }
    ll sol = 0;
    for (int j = p;j <= p + 3 * N;j += 3) {
        sol += F[3 * N][j];
        sol %= MOD;
    }
    cout << sol << endl;
    return 0;
}


Measured memory_bytes: 375552
#include<stdio.h>


#define SIZE 101

void print_a(char a[SIZE][SIZE], int h, int w){
  printf("------\n");
  for(int i=0; i<w; i++){
    printf("%s\n", a[i]);
  }
  printf("------\n");
}

int scan_y(char a[SIZE][SIZE], int h, int w){
  int flag_sharp=1;
  int flag_dot=1;
  for(int j=0; j<h; j++){
    flag_sharp = 1;
    flag_dot = 1;
    for(int i=0; i<w; i++) {
      if(a[j][i] == '#') flag_sharp = 0;
      if(a[j][i] != '.') flag_dot = 0;
    }
    if(flag_sharp && flag_dot) return j;
  }
  return -1;
}

int scan_x(char a[SIZE][SIZE], int h, int w){
  int flag_sharp=1;
  int flag_dot=1;
  for(int i=0; i<w; i++){
    flag_sharp = 1;
    flag_dot = 1;
    for(int j=0; j<h; j++){
      if(a[j][i] == '#') flag_sharp = 0;
      if(a[j][i] != '.') flag_dot = 0;
    }
    if(flag_sharp && flag_dot) return i;
  }
  return -1;
}

void del_tate(char a[SIZE][SIZE], int h, int w, int sx){
  char tmp[SIZE][SIZE] = {0};
  for(int i=0; i<w; i++){
    for(int j=0; j<h; j++){
      tmp[j][i] = a[j][i];
    }
  }

  for(int i=0; i<h; i++){
    for(int j=sx; j<w; j++){
      a[i][j] = tmp[i][j+1];
      if(j+1 == w) a[i][j+1] = '\0';
    }
  }

  //  print_a(a,h,w-1);
  
}

void del_yoko(char a[SIZE][SIZE], int h, int w, int sy){
  char tmp[SIZE][SIZE] = {0};
  for(int i=0; i<w; i++){
    for(int j=0; j<h; j++){
      tmp[j][i] = a[j][i];
    }
  }

  for(int i=sy; i<h; i++){
    for(int j=0; j<w; j++){
      a[i][j] = tmp[i+1][j];
      if(i+1==h) a[i][j] = 0;
    }
  }

  //   print_a(a,h-1,w);
  
}

int main(){
  int h,w;
  char a[101][101];
  scanf("%d", &h);
  scanf("%d", &w);

  for(int i=0; i<h; i++){
    scanf("%s", a[i]);
  }

  while(1){
    int sx = scan_x(a, h, w);
    int sy = scan_y(a, h, w);
    if(sx == -1 && sy == -1) break;
    
    if(sx!=-1){
      //      printf("sx=%d\n", sx);
      del_tate(a,h,w,sx);
      w--;
    }
    else if(sy!=-1){
      //      printf("sy=%d\n", sy);
      del_yoko(a,h,w,sy);
      h--;
    }
  }

  for(int i=0; i<h; i++){
    printf("%s\n", a[i]);
  }

  return 0;
}


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

// a^n mod を計算する
ll modpow(ll a, ll n, ll mod) {
    ll res = 1;
    while (n > 0) {
        if (n & 1) res = res * a % mod;
        a = a * a % mod;
        n >>= 1;
    }
    return res;
}
 
// a^{-1} mod を計算する
ll modinv(ll a, ll mod) {
    return modpow(a, mod - 2, mod);
}
 
const int MAX = 510000;
const ll MOD = 1000000007;
 
ll fac[MAX], finv[MAX], inv[MAX];
 
// テーブルを作る前処理
void COMinit() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (int i = 2; i < MAX; i++){
        fac[i] = fac[i - 1] * i % MOD;
        inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
        finv[i] = finv[i - 1] * inv[i] % MOD;
    }
}
 
// 二項係数計算
ll COM(int n, int k){
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}
int main() {
    int S;
    cin >> S;
    ll ans = 0;
    COMinit();
    for (int i = 1; i < S / 3 + 1; i++) {
        int k = S - 3 * i;
        ans += COM(k + i - 1, i - 1);
        ans %= MOD;
    }
    cout << ans << "\n";
    return 0;
}

Measured memory_bytes: 15556
#include<bits/stdc++.h>
#define int long long
#define rep(i,n) for(int i=0;i<n;i++)
#define srep(i,n,m) for(int i=n;i<m;i++)
#define elif else if
#define INF 1000000007
using namespace std;
int gcd(int a,int b){
    if(b==0) return a;
    return gcd(b,a%b);
}
int n,m,cnt=0,o,p,aa[220000],cntl=0,ab[220000];
pair<int,int> pp[220000];
string s,sa,ss[220000];
char c,cc[220000];
queue<int> que;
signed main(){
    cin>>n>>m>>o>>p;
    if(n>=p){
        cout<<p;
        return 0;
    }else{
        p-=n;
        cnt+=n;
    }
    if(m>=p){
        cout<<cnt;
        return 0;
    }else{
        p-=m;
    }
    cout<<cnt-p;
}

Measured memory_bytes: 10512
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < n; i++)
#define ll long long
#define endl '\n'
using namespace std;
#define N 4
#define N2 16
#define LIMIT 100

static const int dx[4] = {-1, 0, 1, 0};
static const int dy[4] = {0, -1, 0, 1};
static const char dir[4] = {'u', 'l', 'd', 'r'};
int MDT[N2][N2];

struct Puzzle {
    int f[N2], space, MD;
};

Puzzle state;
int limit;  // 深さの限界
int path[LIMIT];

int getAllMD(Puzzle pz) {
    int sum = 0;
    for (int i = 0; i < N2; i++) {
        if (pz.f[i] == N2) continue;
        sum += MDT[i][pz.f[i] - 1];
    }
    return sum;
}

bool isSolved() {
    for (int i = 0; i < N2; i++)
        if (state.f[i] != i + 1) return false;
    return true;
}

bool dfs(int depth, int prev) {
    if (state.MD == 0) return true;
    // 現在の深さにヒューリスティックを足して制限を超えたら枝を刈る
    if (depth + state.MD > limit) return false;

    int sx = state.space / N;
    int sy = state.space % N;
    Puzzle tmp;

    for (int r = 0; r < 4; r++) {
        int tx = sx + dx[r];
        int ty = sy + dy[r];
        if (tx < 0 || ty < 0 || tx >= N || ty >= N || ty >= N) continue;
        if (max(prev, r) - min(prev, r) == 2) continue;
        tmp = state;
        // マンハッタン距離の差分を計算しつつ，ピースをスワップ
        state.MD -= MDT[tx * N + ty][state.f[tx * N + ty] - 1];
        state.MD += MDT[sx * N + sy][state.f[tx * N + ty] - 1];
        swap(state.f[tx * N + ty], state.f[sx * N + sy]);
        state.space = tx * N + ty;
        if (dfs(depth + 1, r)) {
            path[depth] = r;
            return true;
        }
        state = tmp;
    }

    return false;
}

// 反復深化
string iterative_deepening(Puzzle in) {
    in.MD = getAllMD(in);  // 初期状態のマンハッタン距離

    for (limit = in.MD; limit <= LIMIT; limit++) {
        state = in;
        if (dfs(0, -100)) {
            string ans = "";
            for (int i = 0; i < limit; i++) ans += dir[path[i]];
            return ans;
        }
    }

    return "unsolvable";
}
int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);

    for (int i = 0; i < N2; i++)
        for (int j = 0; j < N2; j++)
            MDT[i][j] = abs(i / N - j / N) + abs(i % N - j % N);

    Puzzle in;

    for (int i = 0; i < N2; i++) {
        cin >> in.f[i];
        if (in.f[i] == 0) {
            in.f[i] = N2;
            in.space = i;
        }
    }
    string ans = iterative_deepening(in);
    cout << ans.size() << endl;

    return 0;
}


Measured memory_bytes: 3244
#include <cstdlib>
#include <cmath>
#include <climits>
#include <cfloat>
#include <map>
#include <utility>
#include <set>
#include <iostream>
#include <memory>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <sstream>
#include <deque>
#include <complex>
#include <stack>
#include <queue>
#include <cstdio>
#include <cctype>
#include <cstring>
#include <ctime>
#include <iterator>
#include <bitset>
#include <numeric>
#include <list>
#include <iomanip>
#include <cassert>

#if __cplusplus >= 201103L
#include <array>
#include <tuple>
#include <initializer_list>
#include <unordered_set>
#include <unordered_map>
#include <forward_list>

#define cauto const auto&
#define ALL(v) begin(v),end(v)
#else
#define ALL(v) (v).begin(),(v).end()
#endif

using namespace std;


namespace{
typedef long long LL;
typedef pair<int,int> pii;
typedef pair<LL,LL> pll;

typedef vector<int> vint;
typedef vector<vector<int> > vvint;
typedef vector<long long> vll, vLL;
typedef vector<vector<long long> > vvll, vvLL;

#define VV(T) vector<vector< T > >

template <class T>
void initvv(vector<vector<T> > &v, int a, int b, const T &t = T()){
	v.assign(a, vector<T>(b, t));
}
template <class T> inline T &chmin(T &x, const T &y){ return x = min(x, y); }
template <class T> inline T &chmax(T &x, const T &y){ return x = max(x, y); }
template <class F, class T>
void convert(const F &f, T &t){
	stringstream ss;
	ss << f;
	ss >> t;
}


#define REP(i,n) for(int i=0;i<int(n);++i)
#define RALL(v) (v).rbegin(),(v).rend()


#define MOD 1000000007LL
#define EPS 1e-8

vector<LL> fact(LL n){
	vector<LL> ret;
	for(LL i = 1; i * i <= n; ++i){
		if(n % i == 0){
			if(i > 1){ ret.push_back(i); }
			if(i * i != n){ ret.push_back(n / i); }
		}
	}
	return ret;
}

LL solve(){
	LL n;
	cin >> n;
	if(n == 2){ return 1; }
	
	vector<LL> f = fact(n), g = fact(n - 1);
	LL ans = g.size();
	for(LL x : f){
		LL t = n;
		while(t % x == 0){
			t /= x;
		}
		if(t % x == 1){ ++ans; }
	}
	return ans;
}

void mainmain(){
	cout << solve() << endl;
}



}
int main() try{
//	ios::sync_with_stdio(false); cin.tie(0);
	cout << fixed << setprecision(10);
	cerr << fixed << setprecision(4);
	mainmain();
}
catch(...){
	throw;
}


Measured memory_bytes: 384
#include <bits/stdtr1c++.h>

using namespace std;
// 我们称一个集合是独特的当对集合的每一个元素a_i, 有gcd(a_i, sum of aexpect a_i)!=1
// 并且gcd(a_i) = 1 元素的大小不超过30000
// N最大不超过20000
// 构造题
// 2 4 6 8 10 ... 20000*2
// 由题设可知，对于最大的N，我们要选择2/3的数
// 注意到为了选择那么多的数，我们应尽量选能被2,3整除的数
// 同时为了gcd all = 1, 不妨2,3交替选择， 比如6k+2, 6k+3, 6k+4, 6k+6
// N<6特殊处理
// 对于N>=6 唯一的问题是sum
// 注意有 gcd(ai, S) = gcd(ai,S-ai)(*) 从S中减去ai效果不变
const int maxn = 1e5 + 7;
vector<int> v;

int main() {
    int add[] = {0, 2, 3, 4, 0};
    int n;
    scanf("%d", &n);
    int tot = 0;
    if (n == 3) return !printf("2 5 63\n");// 70
    else if (n == 4) return !printf("2 5 20 63\n"); //90
    else if (n == 5) return !printf("2 5 20 30 63\n"); //120
    else {
        int cnt = 0, sum = 0;
        int a, b;
        for (int i = 2; i <= 30001; i++) {
            if (cnt < n && (i % 2 == 0 || i % 3 == 0)) {
                sum += i;
                cnt++;
                v.push_back(i);
            }
            if (i % 6 == 0) a = i;
            if (i % 6 == 4) b = i;
        }
        int X = sum % 6;
        if(X == 2) v[4] = a;
        else if(X==3) v[5] = a;
        else if(X==5) v[5] = b;

        for(int i=0;i<n;i++) printf("%d%c", v[i], i==n-1?'\n':' ');
    }
}

Measured memory_bytes: 512
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner scan = new Scanner(System.in);
		int n=scan.nextInt();
		int m=scan.nextInt();
		int[] a=new int[n+1];
		int[] b= new int[m];
		
		System.out.println((n*(n-1)/2)+(m*(m-1)/2));


	}

}


Measured memory_bytes: 27076
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <set>
#include <map>
using namespace std;

int main(void) {
    int A, B;
    cin >> A >> B;
    int ans = 0;
    if(A > B) {
	ans += A;
	A -= 1;
    } else {
	ans += B;
	B -= 1;
    }
    if(A > B) {
	ans += A;
	A -= 1;
    } else {
	ans += B;
	B -= 1;
    }
    cout << ans << endl;
  return 0;
}
    


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define ll long long int
#include <cmath>
using namespace std;
const unsigned int m = 1e3+5;
const double pi = 3.14159265358979323846;

int main()
{
	ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
   	int t;
   	//cin>>t;
   	t=1;
   	while(t--)
   	{
   	    double a,b;
   	    cin>>a>>b;
   	    int h,m;
   	    cin>>h>>m;
   	    long double mi,hr;
   	    mi=m*6.0;
   	    hr=h*30+m*0.5;
   	    long double C=(pi*abs(mi-hr))/180.0;
   	    long double c=sqrt(a*a+b*b-2*a*b*cos(C));
   	    cout<<setprecision(18)<<c<<endl;

	}
	return 0;
}


Measured memory_bytes: 4180
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        let mut next = || { iter.next().unwrap() };
        input_inner!{next, $($r)*}
    };
    ($($r:tt)*) => {
        let stdin = std::io::stdin();
        let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));
        let mut next = move || -> String{
            bytes
                .by_ref()
                .map(|r|r.unwrap() as char)
                .skip_while(|c|c.is_whitespace())
                .take_while(|c|!c.is_whitespace())
                .collect()
        };
        input_inner!{next, $($r)*}
    };
}

macro_rules! input_inner {
    ($next:expr) => {};
    ($next:expr, ) => {};

    ($next:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };
}

macro_rules! read_value {
    ($next:expr, ( $($t:tt),* )) => {
        ( $(read_value!($next, $t)),* )
    };

    ($next:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
    };

    ($next:expr, chars) => {
        read_value!($next, String).chars().collect::<Vec<char>>()
    };

    ($next:expr, usize1) => {
        read_value!($next, usize) - 1
    };

    ($next:expr, $t:ty) => {
        $next().parse::<$t>().expect("Parse error")
    };
}

fn main(){

    input!{
        n: usize,
        cs: chars,
    }
    
    let mut ans: Vec<usize> = Vec::new();
    let mut r_cnt_all = 0;
    let mut w_cnt_all = 0;
    let mut r_cnt = 0;
    let mut w_cnt = 0;

    for &i in &cs {
        if i=='R' {
            r_cnt_all += 1;
        } else {
            w_cnt_all += 1;
        }
    }

    r_cnt = r_cnt_all;
    if r_cnt==0 {
        println!("0");
        return;
    }
    for i in 0..n {
        if cs[i]=='R' {
            r_cnt -= 1;
        } else {
            w_cnt += 1;
        }
        ans.push(std::cmp::max(r_cnt, w_cnt));
        // println!("{}", std::cmp::max(r_cnt, w_cnt));
    }


    let mut min_ans = n;
    for i in ans {
        min_ans = std::cmp::min(min_ans, i);
    }
    println!("{}", min_ans);
}

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



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

    int na,nb;
    switch(a){
        case'A':
            na = 10;
        break;
        case'B':
            na = 11;
        break;
        case'C':
            na = 12;
        break;
        case'D':
            na = 13;
        break;
        case'E':
            na = 14;
        break;
        case'F':
            na = 15;
        break;
    }


    switch(b){
        case'A':
            nb = 10;
            break;
        case'B':
            nb = 11;
            break;
        case'C':
            nb = 12;
            break;
        case'D':
            nb = 13;
            break;
        case'E':
            nb = 14;
            break;
        case'F':
            nb = 15;
            break;
    }

    if(na>nb){
        cout<<'>';
    }else if(na==nb){
        cout<<'=';
    }else{
        cout<<'<';
    }
}






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

#pragma GCC optimize("O3,Ofast,no-stack-protector,unroll-loops,fast-math")

#define int long long
typedef pair <int, int> pii;

int32_t main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	int h, n;
	cin >> h >> n;
	int sum = 0;
	for (int i = 0; i < n; i++) {
		int tmp;
		cin >> tmp;
		sum += tmp;
	}
	if (sum >= h)
		cout << "Yes";
	else
		cout << "No";
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define int ll
typedef vector<int> vi;
#define endl '\n'
#define fo(i,a,b) for(int i=a;i<=b;i++)
#define rf(i,a,b) for(int i=a;i>=b;i--) 
#define fast_io ios_base::sync_with_stdio(0);
#define show(x) cout<<x<<endl;
#define pret(x) cout<<x<<endl; return 0;
#define disp(x) cout<<x<<" ";
#define let(x,y) cout<<x<<" "<<y<<endl;
ll MOD=1e9+7;
const int maxn=2e5+5;

int a[3001][3001], dp[3001][3001][4];
int n,m,k;

int32_t main(){
    fast_io;
    cin>>n>>m>>k;
    for (int i = 0; i < k; ++i)
    {
    	int r,c,v;
    	cin>>r>>c>>v;
    	a[r][c] = v;
    }
    fo(i, 1, n){
    	fo(j, 1, m){
    		int prev = 0;
    		for (int k = 0; k < 4; ++k)
    		{
    			prev = max(prev, dp[i-1][j][k]);
    		}
    		for (int k = 0; k < 4; ++k)
    		{
    			dp[i][j][k] = max(prev, dp[i][j-1][k]);
    		}
    		fo(k, 1, 3){
    			dp[i][j][k] = max(dp[i][j][k], dp[i][j-1][k-1] + a[i][j]);
    			dp[i][j][k] = max(dp[i][j][k], prev + a[i][j]);
    		}
    	}
    }
    int ans = 0;
    for (int i = 0; i < 4; ++i)
    {
    	ans = max(ans, dp[n][m][i]);
    }
    show(ans);
    return 0;
}

Measured memory_bytes: 355260
#include <iostream>
#include <vector>
#include "stdlib.h"
#include "math.h"
using namespace std;

int main(){
   int n,d[1000];
   cin >> n;
   for(int i=0;i<n;i++){
      cin >> d[i];
   }

   //0があるか
   int zero = 0;
   for(int j=0;j<n;j++){
      if (d[j] == 0) {
         zero = 1;
         break;
      }
   }
   if(zero == 0) {
      cout << "0" << endl;
      exit(0);
   }

   for(int i=0;;i++){ //exist i?
      int tmp = i;
      int left = 0;
      vector<int> vec;

      //桁に分ける
      int digit = (int)log10((double)tmp) + 1;
      for(int j=0;j<digit;j++){
         vec.insert(vec.begin(),tmp % 10);
         tmp /= 10;
      }
      int iflag = 0;
      int retflag = 0;
      for(int j=0;j<n - vec.size() + 1;j++){ //d[j]を先頭とする
         for(int k=0;k < vec.size();k++){
            if(d[j+k] != vec[k]) {
               retflag = 1;
               break;
            }
         }
         //この時点でretflagが0のままならiは存在
         if(retflag == 0)
         {
            iflag = 1;
            break;
         }else{
            retflag = 0;
            iflag = 0;
            continue;
         }
      }
      if(iflag == 0) {
         cout << i << endl;
         break;
      }
   }
}

Measured memory_bytes: 1264
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
struct st{int c; int s; int f;};

int main(void){
  int n, i, j, t;
  struct st *d;
  scanf("%d",&n);
  d = malloc(sizeof(struct st)*(n-1));
  for(i=0;i<n-1;i++) scanf("%d %d %d",&d[i].c,&d[i].s,&d[i].f);
  for(i=0;i<n-1;i++){
    t=d[i].s; t+=d[i].c; //printf("%d..",t);
    for(j=i+1;j<n-1;j++){
      if(t<d[j].s) t=d[j].s;
      else if(t%d[j].f!=0) t+=d[j].f-t%d[j].f;
      //printf("(%d)",t);
      t+=d[j].c;
      //printf("%d..",t);
    }
    printf("%d\n",t);
  }
  printf("0\n");
  return 0;
}


Measured memory_bytes: 128
#include<stdio.h>

int main(){
	int N, M, i;
	if(scanf("%d%d", &N, &M));
	for(i=N; i<=M/7; i++){
		if(M%i==0){
			printf("%d\n", M/i);
			return 0;
		}
	}
	if(M%6==0 && M/6>=N){
		printf("6\n");
		return 0;
	}
	if(M%5==0 && M/5>=N){
		printf("5\n");
		return 0;
	}
	if(M%4==0 && M/4>=N){
		printf("4\n");
		return 0;
	}
	if(M%3==0 && M/3>=N){
		printf("3\n");
		return 0;
	}
	if(M%2==0 && M/2>=N){
		printf("2\n");
		return 0;
	}
	printf("1\n");
	return 0;
}


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

string INF = "-";

int match[9] = {2,5,5,4,5,6,3,7,6};
string dp[10001+9]; //マッチi本で作れる最大数

string chmax(string s,string t){
  if(s == INF) return t;
  if(s.size() < t.size()) return t;
  if(s.size() == s.size() && s < t) return t;
  return s;
}

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

  int n,m; cin >> n >> m;
  vector<int> a(m);
  for(int i = 0; i < m; i++){
    cin >> a[i];
  }

  fill(dp,dp+10001+9,INF);
  dp[0] = "";
  for(int i = 0; i < n; i++){
    if(dp[i] == INF) continue;
    for(auto x : a){
      dp[i+match[x-1]] = chmax(dp[i+match[x-1]],dp[i]+to_string(x));
    }
  }
  cout << dp[n] << endl;

  return 0;
}


Measured memory_bytes: 33024
import java.util.*;
import java.io.*;

public class Main {

  void solve(InputReader in, PrintWriter out) {
    int H = in.nextInt();
    int n = in.nextInt();

    int sum = 0;
    for (int i = 0; i < n; ++i)
      sum += in.nextInt();

    out.println(sum >= H ? "Yes" : "No");
  }

  public static void main(String[] args) throws Exception {
    InputReader in = new InputReader(System.in);
    PrintWriter out = new PrintWriter(System.out);
    Main solver = new Main();
    solver.solve(in, out);
    out.close();
  }

  static class InputReader {
    BufferedReader in;
    StringTokenizer st;

    public InputReader(InputStream is) {
      in = new BufferedReader(new InputStreamReader(is));
    }

    public String next() {
      try {
        while (st == null || !st.hasMoreTokens()) {
          st = new StringTokenizer(in.readLine());
        }
        return st.nextToken();
      } catch (Exception e) {
        throw new RuntimeException(e);
      }
    }

    public int nextInt() {
      return Integer.parseInt(next());
    }

    public long nextLong() {
      return Long.parseLong(next());
    }
  }
}


Measured memory_bytes: 33244
//https://atcoder.jp/contests/abc153/tasks/abc153_c
#include <bits/stdc++.h>
#define in cin >> 
#define out cout <<
#define Vi vector<long int>
#define FOR(i,k,l) for(int i(k); i<l;i++)
#define M 100002

using namespace std;

int main(void) {
    int N, K;
    cin >> N >> K;
    
    vector <long> vec;
    long temp;
    for(int i = 0 ; i < N ; i++) {
        cin >> temp;
        vec.push_back(temp);
    }

    sort(vec.begin(), vec.end());

    unsigned long res = 0;
    for(int i = 0 ; i < N-K ; i++) {
        res += vec[i];
    }

    cout << res << " ";

}

Measured memory_bytes: 2420
A, B = map(int, input().split())
if not A == 1 and not B == 1:
    if A == B:
        print('Draw')
    elif A > B:
        print('Alice')
    elif A < B:
        print('Bob')
else:
    if A == 1 and B != 1:
        print('Alice')
    elif B == 1 and A != 1:
        print('Bob')
    else:
        print('Draw')

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

using ll = long long;

const int mod = 1000000007;
const int INF = 1000000000;
const double EPS = 1e-9;

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    int N;
    cin >> N;
    vector<vector<int>> c(9, vector<int>(9, 0));
    for (int n = 1; n <= N; ++n) {
        int d = to_string(n).size();
        int l = stoi(to_string(n).substr(0, 1));
        int r = stoi(to_string(n).substr(d - 1, 1));
        if (l == 0 || r == 0) continue;
        r--; l--;
        c[l][r]++;
    }
    int ans = 0;
    for (int i = 0; i < 9; ++i) {
        for (int j = 0; j < 9; ++j) {
            ans += c[i][j] * c[j][i];
        }
    }
    cout << ans << endl;
}


Measured memory_bytes: 256
#import pysnooper
#import numpy
#import os,re,sys,operator
#from collections import Counter,deque
#from operator import itemgetter,mul
from itertools import accumulate,combinations,groupby,combinations_with_replacement,permutations
from sys import stdin,setrecursionlimit
#from bisect import bisect_left,bisect_right
#from copy import deepcopy
#import heapq
#import math
#import string
#from time import time
#from functools import lru_cache,reduce
#from math import factorial
#import sys
#from fractions import gcd
setrecursionlimit(10**6)
input=stdin.readline

n=int(input().rstrip())
p=[int(i) for i in input().split()]
q=[int(i) for i in input().split()]
t=list(permutations(range(1,n+1),n))
#print(list(permutations(range(1,4),3)))
a,b=0,0
for i in range(len(t)):
    if list(t[i])==p:
        a=i+1
    if list(t[i])==q:
        b=i+1
print(abs(a-b))

Measured memory_bytes: 8052
#include <iostream>
#include <cstdlib>
#include <vector>
#include <algorithm>
#include <string>
#include <cmath>
#include <new>

using namespace std;

typedef long long ll;

#define rep(i, N) for (ll i = 0; i < (ll)(N); ++i)

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

int main(){
	ll m=0,l=0;
	string S;
	cin >> S;
	for(ll i=0;i<S.size();i++){
		if('A'==S[i]||'C'==S[i]||'G'==S[i]||'T'==S[i]){
			l++;
			m=max(m,l);
		}else{
			l=0;
		}
	}

	cout << m << endl;
	return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
#include <math.h>
#include <string.h>
#include <stdlib.h>
#include <iostream>
#include <algorithm>
#include <vector>
#include <map>
#include <utility>
#include <stack>
#include <queue>
#include <set>
#include <list>
#include <bitset>
#include <array>

using namespace std;

#define fi first	
#define se second
#define long long long
typedef pair<int,int> ii;

char col[200003];
int cnt[200003][2];
queue<int> q;
set<int> vec[200003];

void kill(int x)
{
	// cout << x << "\n"; fflush(stdout);
	q.push(x);
	while(q.size())
	{
		int curr = q.front(); q.pop();
		for(auto it : vec[curr])
		{
			// cout << "	" << it << "\n"; fflush(stdout);
			if(col[curr] == 'A') cnt[it][0]--;
			else cnt[it][1]--;
			
			if(it != curr)
				vec[it].erase(vec[it].find(curr));
			if((cnt[it][0] == 0 || cnt[it][1] == 0))
				q.push(it);
		}
		vec[curr].clear();
	}
}



int main()
{
	ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
	// freopen("input.in", "r", stdin); 

	int n, m;
	cin >> n >> m;
	for(int i = 1; i <= n; i++)
		cin >> col[i];

	for(int i = 1; i <= m; i++)
	{
		int u, v;
		cin >> u >> v;
		vec[u].insert(v);
		vec[v].insert(u);
	}
	for(int i = 1; i <= n; i++)
	{
		for(int v : vec[i])
		{
			if(col[v] == 'A') cnt[i][0]++;
			else cnt[i][1]++;
		}
	}
	for(int i = 1; i <= n; i++)
	{
		if(cnt[i][0] == 0 || cnt[i][1] == 0)
			kill(i);
	}
	for(int i = 1; i <= n; i++)
	{
		if(cnt[i][0] != 0 && cnt[i][1] != 0)
		{
			cout << "Yes\n";
			return 0;
		}
	}
	cout << "No\n";

}











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

#define rep(i, n) for (ll i = 0; i < (n); i++)
#define rep2(i, a, b) for (ll i = (a); i < (b); i++)
#define chmax(x, v) do { x = max(x, v); } while(0)
typedef uint64_t ull;
typedef int64_t ll;
typedef std::pair<ll, ll> PLL;

using namespace std;

signed main() {
  string s;
  cin >> s;
  ll n = s.size();
  ll ans = 0;
  rep(i,n/2) {
    ll j = n-1-i;
    if (s[i]!=s[j])
      ans++;
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<algorithm>
#include<cstdio>
#include<string>
#include<stdio.h>
#include<stdlib.h>
#include<float.h>
#include<tuple>
#include <string.h>
#include <iomanip>

using namespace std;
#define ll long long
#define rep(i,n) for(ll i=0;i<n;i++)
const ll mod=1e9+7;


int main(void){
    ll N,K;
    cin>>N>>K;
    if(2*K>(N-1)*(N-2)){
        cout<<-1<<endl;
        return 0;
    }
    ll M=N*(N-1)/2-K;
    cout<<M<<endl;
    
    for(ll i=1;i<N;i++){
        for(ll j=i+1;j<=N;j++){
            cout<<i<<" "<<j<<endl;
            M--;
            if(M<=0) return 0;
        }
    }
}

Measured memory_bytes: 256
#include <iostream>
#include <sstream>
#include <algorithm>
#include <string>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <stack>
#include <memory>
#include <complex>
#include <numeric>
#include <cstdio>
#include <iomanip>

#define REP(i,m,n) for(int i=int(m);i<int(n);i++)
#define RREP(i,m,n) for(int i=int(n)-1;i>=int(m);--i)
#define EACH(i,c) for (auto &(i): c)
#define all(c) begin(c),end(c)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort(begin(c),end(c))
#define pb emplace_back
#define MP make_pair
#define SZ(a) int((a).size())

#ifdef LOCAL
#define DEBUG(s) cout << (s) << endl
#define dump(x)  cerr << #x << " = " << (x) << endl
#define BR cout << endl;
#else
#define DEBUG(s) do{}while(0)
#define dump(x) do{}while(0)
#define BR 
#endif
using namespace std;

using UI = unsigned int;
using UL = unsigned long;
using LL = long long int;
using ULL = unsigned long long;
using VI = vector<int>;
using VVI = vector<VI>;
using VLL = vector<LL>;
using VS = vector<string>;
using PII = pair<int,int>;
using VP = vector<PII>;

//struct edge {int from, to, cost;};

constexpr double EPS = 1e-10;
//constexpr double PI  = acos(-1.0);
//constexpr int INF = INT_MAX;
constexpr int MOD = 1'000'000'007;
//inline void modAdd(LL &l, LL &r) {l = (l + r) % MOD;}

template<class T> inline T sqr(T x) {return x*x;}

void solve() {
    int n;
    cin >> n;
    VI ps;
    for (int i = 11; i < 55555+1; i+=10) {
        int v = i;
        for (int j = 2; j * j <= v; ++j) {
            if (v % j == 0) {
                v = 0;
                break;
            }
        }
        if (v == i) ps.push_back(v);
    }
    REP(i,0,n) {
        if (i) cout << " ";
        cout << ps[i];
    }
    cout << endl;
}

int main() {
    solve();
    
    return 0;
}

Measured memory_bytes: 256