akhauriyash/Code-Regression huggingface dataset:
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
const int INF = (1<<30);
const ll INFLL = (1ll<<60);
const ll MOD = (ll)(1e9+7);

#define l_ength size

void mul_mod(ll& a, ll b){
	a *= b;
	a %= MOD;
}

void add_mod(ll& a, ll b){
	a = (a<MOD)?a:(a-MOD);
	b = (b<MOD)?b:(b-MOD);
	a += b;
	a = (a<MOD)?a:(a-MOD);
}

bool done[123][55][55];
ll memo[123][55][55],v[55];

ll solve(int t, int l, int r){
	if(done[t][l][r]){
		return memo[t][l][r];
	}
	done[t][l][r] = true;
	if(!t){
		return memo[t][l][r];
	}
	if(l>r){
		return memo[t][l][r];
	}
	memo[t][l][r] = max(memo[t][l][r],solve(t-1,l+1,r)+v[l]);
	memo[t][l][r] = max(memo[t][l][r],solve(t-1,l,r-1)+v[r]);
	if(t>1){
		memo[t][l][r] = max(memo[t][l][r],solve(t-2,l+1,r));
		memo[t][l][r] = max(memo[t][l][r],solve(t-2,l,r-1));
	}
	return memo[t][l][r];
}

int main(void){
	int n,k,i;
	cin >> n >> k;
	for(i=0; i<n; ++i){
		cin >> v[i];
	}
	cout << solve(k,0,n-1) << endl;
	return 0;
}


Measured memory_bytes: 2432
/**
 *   @FileName	a.cpp
 *   @Author	kanpurin
 *   @Created	2020.06.28 21:23:50
**/

#include "bits/stdc++.h" 
using namespace std; 
typedef long long ll;

int main() {
    int d;
    cin >> d;
    vector< int > c(26);
    vector< pair< int, int > > p(26);
    for (int i = 0; i < 26; i++) {
        cin >> c[i];
        p[i] = make_pair(c[i], i);
    }
    vector< vector< int > > s(d, vector< int >(26));
    vector< vector< pair< int, int > > > s2(d, vector< pair< int, int > >(26));
    for (int i = 0; i < d; i++) {
        for (int j = 0; j < 26; j++) {
            cin >> s[i][j];
            s2[i][j] = make_pair(s[i][j], j);
        }
        sort(s2[i].rbegin(), s2[i].rend());
    }
    sort(p.rbegin(), p.rend());
    vector< int > ans(d);
    for (int i = 0; i < min(d,26); i++) {
        ans[d - 1 - i] = p[i].second;
    }
    if (d > 26) {
        for (int i = 26; i < d; i++) {
            ans[d - 1 - i] = s2[d - 1 - i][0].second;
        }
    }
    for (int i = 0; i < d; i++) {
        cout << ans[i] + 1 << endl;
    }
    return 0;
}


Measured memory_bytes: 3740
MOD_SIZE = 1_000_000_007

N, M = gets.chomp.split(' ').map(&:to_i)
brokens = (M.times.map { gets.to_i }).uniq.sort
brokens.unshift(-1)
brokens.push(N+1)

$memo = {}
$memo[0] = 1
$memo[1] = 1
2.upto(N) do |i|
  $memo[i] = ($memo[i-2] + $memo[i-1]) % MOD_SIZE
end

def count_step_patterns(steps)
  return 1 if steps <= 1
  return $memo[steps] if $memo.key?(steps)
  $memo[steps] = count_step_patterns(steps-1) + count_step_patterns(steps-2)
end

cannot_reach = brokens.inject(nil) { |before, value|
  next value if before.nil?
  break nil if before + 1 == value
  value
}.nil?

if cannot_reach
  puts 0
else
  splitted = 0.upto(brokens.size-2).map { |i| brokens[i+1] - brokens[i] - 2 }
  puts splitted.inject(1) { |sum, steps| sum * $memo[steps] % MOD_SIZE }
end



Measured memory_bytes: 11268
#include <bits/stdc++.h>
#include <boost/multiprecision/cpp_int.hpp>
using namespace std;

//#define int long long
//using ll = boost::multiprecision::cpp_int;
using ll = long long;
//const int INF = 1e9;//INT_MAX=1<<31-1=2147483647
const ll INF = (ll)1e18;//1<<63-1=9223372036854775807
const int MOD = (int)1e9 + 7;
const double EPS = 1e-9;
const int dx[4]={1,0,-1,0};
const int dy[4]={0,1,0,-1};
#ifdef LOCAL_ENV
	#define debug(var) std::cout<<#var" = "<<var<<std::endl
#else
	#define debug(var)
#endif
#define p(var) std::cout<<var<<std::endl
#define PI (acos(-1))
#define rep(i, n)   for(ll i=0, i##_length=(n); i< i##_length; ++i)
#define repeq(i, n) for(ll i=1, i##_length=(n); i<=i##_length; ++i)
#define all(a) (a).begin(), (a).end()
#define pb push_back
inline bool isnatural(double a) { return a>=0 && ceil(a)==floor(a); }
template<typename T> inline T gcd(T a, T b) { return b ? gcd(b,a%b) : a; }
template<typename T> inline T lcm(T a, T b) { return a / gcd(a,  b) * b; }
template<typename T1, typename T2>inline bool chmax(T1 &a, T2 b) { return a < b && (a = b, true); }
template<typename T1, typename T2>inline bool chmin(T1 &a, T2 b) { return a > b && (a = b, true); }
template<typename T1, typename T2> ostream& operator<<(ostream& s, const pair<T1, T2>& p) {return s << "(" << p.first << ", " << p.second << ")";}
template<typename T> ostream& operator<<(ostream& s, const vector<T>& v) {
	for (int i = 0, len = v.size(); i < len; ++i){
		s << v[i]; if (i < len - 1) s << "\t";
	}
	return s;
}
template<typename T> ostream& operator<<(ostream& s, const vector< vector<T> >& vv) {
	for (int i = 0, len = vv.size(); i < len; ++i){
		s << vv[i] << endl;
	}
	return s;
}
template<typename T1, typename T2> ostream& operator<<(ostream& s, const map<T1, T2>& m) {
	s << "{" << endl;
	for (typeof(m.begin()) itr = m.begin(); itr != m.end(); ++itr){
		s << "\t" << (*itr).first << " : " << (*itr).second << endl;
	}
	s << "}" << endl;
	return s;
}

/*-----8<-----8<-----*/

class UnionFind {
public:
	vector<ll> v;
	UnionFind(size_t size) : v(size, -1) {}

	ll root(ll x) {
		return (v[x] < 0 ? x : v[x] = root(v[x]));
	}

	bool is_root(ll x) {
		return x == root(x);
	}

	bool is_same(ll x, ll y) {
		return root(x) == root(y);
	}

	bool unite(ll x, ll y) {
		x = root(x);
		y = root(y);
		if (x == y) return false;
		if (v[x] > v[y]) swap(x, y);
		v[x] += v[y];
		v[y] = x;
		return true;
	}

	ll size(ll x) {
		return -v[root(x)];
	}
};

int N, M;
vector<int> a,X,Y;

void input() {
	scanf("%d%d", &N, &M);
	a.assign(N,0);
	rep(i,N){
		ll t;
		cin>>t;
		a[i]=t-1;
	}
	X.assign(M,0);
	Y.assign(M,0);
	rep(i,M){
		cin >>X[i]>>Y[i];
		X[i]--;Y[i]--;
	}
}

void solve() {
	UnionFind tree=UnionFind(N);
	ll ans = 0;

	rep(i,M){
		tree.unite(X[i],Y[i]);
	}

	rep(i,N){
		if(tree.is_same(i,a[i]))ans++;
	}


	p(ans);
}

signed main() {
	input();
	solve();
	return 0;
}


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

using namespace std;

vector<int> G[200000];
bool used[200000];
int dist[200000];

void dfs(int v, int d){
    used[v] = true;
    dist[v] = d;
    for(int i = 0; i < G[v].size(); i++){
        if(!used[G[v][i]]){
            dfs(G[v][i], d+1);
        }
    }
}

int main(){
    int N;
    cin >> N;
    if(N == 1){
        cout << "First" << endl;
        return 0;
    }
    for(int i = 0; i < N-1; i++){
        int a, b;
        cin >> a >> b;
        a--;
        b--;
        G[a].push_back(b);
        G[b].push_back(a);
    }
    dfs(0, 0);
    int d_max = 0;
    int l;
    for(int i = 0; i < N; i++){
        if(d_max < dist[i]){
            l = i;
            d_max = dist[i];
        }
        dist[i] = 0;
        used[i] = false;
    }
    dfs(l, 0);
    int diam = 0;
    for(int i = 0; i < N; i++){
        if(diam < dist[i]){
            l = i;
            diam = dist[i];
        }
    }
    if(diam%3 == 1){
        cout << "Second" << endl;
    }else{
        cout << "First" << endl;
    }
}

Measured memory_bytes: 21504
N,M = map(int,input().split())
A = [input() for _ in range(N)]
B = [input() for _ in range(M)]
ans = False
for dx in range(N-M+1):
    for dy in range(N-M+1):
        flg = True
        for i in range(M):
            for j in range(M):
                if A[i+dx][j+dy] != B[i][j]:
                    flg = False
        if flg:
            ans = True
print("Yes" if ans else "No")
                

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

int main()
{
  int n, m, MAX = 0, SUM;
  int a, size;
  vector<int> v;

  while(cin >> n >> m, n) {

    int MAX = 0, SUM, a, size;
    vector<int> v;

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

    for (int i = 0; i < v.size(); i++) {
      for (int j = i+1; j < v.size(); j++) {
	SUM = v[i] + v[j];
	if (SUM <= m) {
	  MAX = max(MAX, SUM);
	  //cout << MAX << endl;
	}
      }
    }
    
    if (MAX==0) {
      cout << "NONE" << endl;
    }
    else {
      cout << MAX << endl;
    }
    
  }
  
  return 0;
}


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

int main() {
  
  int A, B;
  cin >> A >> B;
  
  if(A == 1 || B == 1){
    if(A != 1){
      cout << "Bob" << endl;
    }
    if(B != 1){
      cout << "Alice" << endl;
    }
    if(A == 1 && B == 1){
      cout << "Draw" << endl;
    }
  }
    
  else{
    if(A > B){
      cout << "Alice" << endl;
    }
  
    if(A < B){
      cout << "Bob" << endl;
    }
  
    if(A == B){
      cout << "Draw" << endl;
    }
  }
  
}

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

int main(){
    
    int n,m,l,r,ma=1,mi;
    cin >> n >> m ;
    mi=n;
    for (int i=0;i<m;i++){
        cin >> l >> r;
        ma=max(ma,l);
        mi=min(mi,r);
    }

    if(mi>=ma){
    cout << mi-ma+1 << endl;
    }else{
        cout << 0 << endl;
    }
    
}

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

using namespace std;

int main(){
    long double w,h,x,y;
    cin>>w>>h>>x>>y;
    cout<<w*h/2<<endl;
    if(w/2 == x && h/2 == y){
        cout<<1<<endl;
    }else{
        cout<<0<<endl;
    }

}

Measured memory_bytes: 256
import sys
readline = sys.stdin.readline
sys.setrecursionlimit(20000)

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

S = input()
Q = int(input())

prefix = []
suffix = []
flip = 0
for i in range(Q):
    T = input()
    if T == "1":
        prefix, suffix = suffix, prefix
        flip = 1 - flip
    else: # T == 2
        _, f, c = T.split()
        if f == "1":
            # 先頭に c 追加
            prefix.append(c)
        elif f == "2":
            # 末尾に c 追加
            suffix.append(c)

if flip == 1:
    S = S[::-1]
print("".join(prefix[::-1]), end="")
print(S, end="")
print("".join(suffix))


Measured memory_bytes: 6272
#include <bits/stdc++.h>//toINFandByd
#define forn(i, n) for (int i = 0; i < int(n); i++)
#define endl "\n"
using namespace std;
typedef long long ll;

void solve(){
    ll n;
    cin >> n;
    // n--;
    string ans = "";
    while(n>0){
        int d = n%26;
        if(d==0){
            d = 26;
            n--;
        }
        char c = (d-1)+'a';
        ans = c+ans;
        n/=26;
    }
    cout << ans << endl;
}   

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

Measured memory_bytes: 3656
#include <bits/stdc++.h>
using namespace std;
int main(void){
    // Your code here!
    long long int n,ans=0,s=0,t=1;
    cin>>n;
    
    long x[n+5][3];
    long ab[n+5];
    
    for(int j=0;j<n;j++){
        for(int k=0;k<2;k++){
            cin>>x[j][k];
        }
        ab[j]=x[j][0]+x[j][1];
        
    }
    
    pair<long,long> p[n+5];
    for(int i=0;i<n;i++){
        p[i] = make_pair(ab[i],i);
    }
    
    sort(p,p+n);
    for(int l=n-1;l>=0;l--){
        ans+=t*(x[p[l].second][s%2]);
        s++;
        t*=-1;
    }
    cout<<ans<<endl;
    return 0;
}


Measured memory_bytes: 4992
#include <iostream>
#include <sstream>
#include <vector>
#include <algorithm>
#include <numeric>
#include <cmath>
#include <utility>
#include <map>
#include <list>
#include <climits>
#include <set>
#include <deque>
#include <stack>
#include <unordered_map>
#include <unordered_set>
#include <iomanip>
#include <bitset>

// #define cerr if(false)cerr
#define watch(x) cerr << "> " << #x << ": " << x << "\n";

using namespace std;

template <typename T>
std::ostream &operator <<(std::ostream &out, vector<T> &v) {
	for (typename vector<T>::size_type i = 0; i < v.size(); ++i)
		out << v[i] << " ";
	out << "\n";
    return out;
}
template <typename T, typename N>
std::ostream &operator <<(std::ostream &out, vector<pair<T, N> > &v) {
	for (size_t i = 0; i < v.size(); ++i)
		out << "(" << v[i].first << ", " << v[i].second << ") ";
	out << "\n";
    return out;
}
template <typename T>
std::ostream &operator <<(std::ostream &out, vector<vector<T> > &v) {
	for (size_t i = 0; i < v.size(); ++i) {
		for (size_t j = 0; j < v[i].size(); ++j) {
			out << v[i][j] << " ";
		}
		out << "\n";
	}
   	return out;
}

int main() {

	std::ios::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);

	int n;
	cin >> n;

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

	for (int i = 0; i < n; ++i) {
		cout << (x ^ a[i]) << " ";
	}

	cout << "\n";

	return 0;

}

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

int main() {
  int n;
  cin >> n;
  vector<int> a(n+2, 0);
  vector<int> dist(n + 1);
  ll dist_sum = 0;
  for(int i = 1; i < n + 1; i++) cin >> a[i];
  for (int i = 0; i < n + 1; i++){
    dist[i] = abs(a[i + 1] - a[i]);
    dist_sum += dist[i];
  }
  for (int i = 1; i < n + 1; i++){
    ll tmp = dist_sum - dist[i - 1] - dist[i];
    tmp += abs(a[i + 1] - a[i - 1]);
    cout << tmp << endl;
  }
}

Measured memory_bytes: 2048
N, X, Y = map(int, input().split())

anss = [0] * N
for a in range(1, N+1):
    for b in range(a+1, N+1):
        d1 = b-a
        d2 = abs(X-a) + 1 + abs(Y-b)
        d = d1 if d1 <= d2 else d2
        anss[d] += 1

print('\n'.join(map(str, anss[1:])))


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

using namespace std;
using ll = long long;
const int mod = 1e9 + 7;

int main()
{
    ll n, k;
    cin >> n >> k;
    vector<ll> a(n);
    for (int i = 0; i < n; i++){
        cin >> a[i];
    }
    ll ans = 0;
    for (int i = 0; i < n; i++){
        ll cnt = 0;
        for (int j = i + 1; j < n; j++){
            if (a[j] < a[i]){
                cnt++;
            }
        }
        ans += (cnt) % mod * ((k * (k + 1) / 2) % mod);
        ans %= mod;
    }
    for (int i = 1; i < n; i++){
        ll cnt = 0;
        for (int j = 0; j < i; j++){
            if (a[j] < a[i]){
                cnt++;
            }
        }
        ans += (cnt) % mod * ((k * (k - 1) / 2) % mod);
        ans %= mod;
    }
    cout << ans;
    return 0;
}


Measured memory_bytes: 256
#include <vector>
#include <iostream>
#include <utility>
#include <algorithm>
#include <string>
#include <deque>
#include <tuple>
#include <queue>
#include <functional>
#include <cmath>
#include <iomanip>
#include <map>
//cin.sync_with_stdio(false);
//streambuf
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;

int main() {
	int h, w;
	while (cin >> h >> w, h) {
		vector<string> map(h);
		for (auto &a : map)cin >> a;
		int dx[] = { 0,0,1,1,1,-1,-1,-1 };
		int dy[] = { 1,-1,0,-1,1,0,1,-1 };
		vector<tuple<string, int, int, int>> buf;
		for (int i = 0; i < h; i++) {
			for (int j = 0; j < w; j++) {
				for (int d = 0; d < 8; d++) {
					buf.push_back(make_tuple((string)"" + map[i][j], j, i, d));
				}
			}
		}
		int l = 1;
		for (;; l++) {
			sort(buf.begin(), buf.end());
			vector<tuple<string, int, int, int>> buf2;
			for (int i = 1; i < buf.size(); i++) {
				if (get<0>(buf[i - 1]).size() < l)continue;
				if (get<0>(buf[i - 1]) == get<0>(buf[i]))buf2.push_back(buf[i - 1]);
				for (; i<buf.size()&&get<0>(buf[i - 1]) == get<0>(buf[i]); i++)buf2.push_back(buf[i]);
			}
			if (buf2.empty())break;
			buf = move(buf2);
			for (auto &a : buf) {
				string str;
				int x, y, d;
				tie(str, x, y, d) = a;
				int x1 = ((x + dx[d]*l) % w + w) % w;
				int y1 = ((y + dy[d]*l) % h + h) % h;
				if (x1 == x && y1 == y)continue;
				str += map[y1][x1];
				a = make_tuple(str, x, y, d);
			}
		}
		if (l < 3)cout << 0 << endl;
		else {
			string str = get<0>(buf[0]);
			cout << str.substr(0, l-1) << endl;
		}
	}
	return 0;
}

Measured memory_bytes: 3432
#include<iostream>
#include<cstdio>
#include<cstring>
#include<string>
#include<queue>
using namespace std;

const int CN = 210;

class fs{
  public: int to,nxt;
    void init(int t,int n) {to = t;nxt = n;}
}E[CN * CN];
int hd[CN],ecnt = 0;
void add(int x,int y) {E[++ecnt].init(y,hd[x]);hd[x] = ecnt;}

int n,ans = -1,ind[CN];

int dep[CN]; queue<int> Q;
int bfs(int s){
    memset(dep,0,sizeof(dep)); 
    Q.push(s); dep[s] = 1;
    while(!Q.empty()){
        int u = Q.front(); Q.pop();
        for(int k = hd[u];k;k=E[k].nxt){
            int v = E[k].to;
            if(dep[v] == dep[u]) return -1;
            if(!dep[v]) dep[v] = dep[u] + 1,Q.push(v);
        }
        
    }
    int mx = 0;
    for(int i=1;i<=n;i++) mx = max(mx, dep[i]);
    return mx;
}

int main()
{
    scanf("%d",&n);
    for(int i=1;i<=n;i++)
        for(int j=1;j<=n;j++){
            char c; cin>>c;
            if(c == '1') add(i,j),ind[j]++;
        }

    int mn = 0x3f3f3f3f;
    for(int i=1;i<=n;i++) mn = min(mn, ind[i]);
    for(int st=1;st<=n;st++) ans = max(ans, bfs(st));

    printf("%d",ans);

    return 0;
}

Measured memory_bytes: 512
#include<stdio.h>

int main(void)
{
    int i;
    int n[25]={0},tem[6]={24,24,24,24,24,24};
    int max1=24,max2=24;
    double s[25]={0};



    for(i=0;i<24;i++){
        scanf("%d%lf",&n[i],&s[i]);
        if(i%8==0){
        s[24]=1000;
        }
        if(s[max1]>s[i]){
            tem[(i/8)*2+1]=tem[(i/8)*2];
            tem[(i/8)*2]=max2;
            max2=max1;
            max1=i;
        } else if(s[max2]>s[i]){
            tem[(i/8)*2+1]=tem[(i/8)*2];
            tem[(i/8)*2]=max2;
            max2=i;
        } else if(s[tem[(i/8)*2]]>s[i]){
            tem[(i/8)*2+1]=tem[(i/8)*2];
            tem[(i/8)*2]=i;
        } else if(s[tem[(i/8)*2+1]]>s[i]){
            tem[(i/8)*2+1]=i;
        }

        if(i%8==7){
            printf("%d %.2lf\n%d %.2lf\n",n[max1],s[max1],n[max2],s[max2]);
            max1=24;
            max2=24;
        }
    }

    for(i=0;i<6;i++){
        if(s[max1]>s[tem[i]]){
            max2=max1;
            max1=tem[i];
        } else if(s[max2]>s[tem[i]]){
            max2=tem[i];
        }
       // printf("%d ",tem[i]);
    }//printf("%d %d\n",max1,max2);

    printf("%d %.2lf\n%d %.2lf\n",n[max1],s[max1],n[max2],s[max2]);

    return 0;
}

Measured memory_bytes: 652
#include <iostream>
#include <cstdio>
#include <vector>
#define N 100005
using namespace std;
typedef long long ll;
#define PII pair<ll, ll>
ll n, u, v, w, q, k, d[N], c[N];
vector<PII> a[N];

void f(ll p, ll q) {
	if(c[p]) return;
	c[p] = 1;
	d[p] = q;
	for(int i=0; i<a[p].size(); i++) {
		f(a[p][i].first, q+a[p][i].second);
	}
}

int main() {
	int i, j;
	scanf("%d", &n);
	for(i=0; i<n-1; i++) {
		scanf("%lld%lld%lld", &u, &v, &w);
		a[u].push_back(PII(v, w));
		a[v].push_back(PII(u, w));
	}
	scanf("%lld%lld", &q, &k);
	f(k, 0);
	while(q--) {
		scanf("%lld%lld", &u, &v);
		printf("%lld\n", d[u] + d[v]);
	}
	return 0;
}

Measured memory_bytes: 15104
import java.util.Scanner;

public class Main {
  private static final Scanner scanner = new Scanner(System.in);

  public static void main(String[] args) {
    int a = scanner.nextInt();
    int b = scanner.nextInt();
    int c = scanner.nextInt();
    int k = scanner.nextInt();
    solve(a, b, c, k);
  }

  static void solve(int a, int b, int c, int k) {
    int a1 = a;
    int b1 = b;
    int c1 = c;
    int res = 0;
    for (int i = 0; i < k; i++) {
      a1 *= 2;
    }
    res = Math.max(res, a1 + b1 + c1);
    a1 = a;
    b1 = b;
    c1 = c;
    for (int i = 0; i < k; i++) {
      b1 *= 2;
    }
    res = Math.max(res, a1 + b1 + c1);
    a1 = a;
    b1 = b;
    c1 = c;
    for (int i = 0; i < k; i++) {
      c1 *= 2;
    }
    res = Math.max(res, a1 + b1 + c1);
    System.out.println(res);
  }

}

Measured memory_bytes: 22996
// No.213741032120
#include <bits/stdc++.h>
#define N 2020
using namespace std;

int n, eps, Mod, f[N * 3][N * 4];

inline void inc(int &x, const long long &y) {
    return x = (x + y) % Mod, void();
}

int main() {
#ifdef isLOCAL
    freopen(".in", "r", stdin);
    freopen(".out", "w", stdout);
#endif

    cin >> n >> Mod;
    eps = n + 1;
    f[0][eps] = 1;

    for (int i = 0; i < n * 3; ++i)
        for (int j = -n, k; j <= 3 * n; ++j) if ((k = f[i][j + eps])) {
            inc(f[i + 1][j + 1 + eps], k);
            inc(f[i + 2][j - 1 + eps], 1ll * k * (i + 1));
            inc(f[i + 3][j + eps], 1ll * k * (i + 1) * (i + 2));
        }

    int ans = 0;
    for (int i = 0; i <= 3 * n; i += 3)
        ans = (ans + f[n * 3][i + eps]) % Mod;
    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 188928
def DFS(A = [0], i = 0, d = [0], f = [0], time = 1):
    for j in range(len(d)):
        if A[i][j] == 1 and d[j] == 0:
            time = time + 1
            d[j] = time
            time = DFS(A, j, d, f, time)
    time = time + 1
    f[i] = time
    return time

n = int(raw_input())
A = [0] * n
for i in range(n):
    A[i] = [0] * n

for i in range(n):
    value = map(int, raw_input().split())
    u = value[0] - 1
    k = value[1]
    nodes = value[2:]
    for j in range(k):
        v = nodes[j] - 1
        A[u][v] = 1

d = [0] * n
f = [0] * n

time = 0
for i in range(n):
    if d[i] == 0:
        time = time + 1
        d[i] = time
        time = DFS(A, i, d, f, time)

for i in range(n):
    print(str(i + 1) + " " + str(d[i]) + " " + str(f[i]))

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

using namespace std;
using P = pair<long, long>;

typedef long long int ll;

#define EPS (1e-7)
#define INF (1e18)
#define PI (acos(-1))

#define sortv(xs) sort(xs.begin(), xs.end())
#define sortvinv(xs) sort(xs.begin(), xs.end(), greater<long>())
#define lbv(xs, x) lower_bound(xs.begin(), xs.end(), x) - xs.begin()
#define ubv(xs, x) upper_bound(xs.begin(), xs.end(), x) - xs.begin()
#define bs(xs, x) binary_search(xs.begin(), xs.end(), x)
#define index_of(as, x) \
  distance(as.begin(), lower_bound(as.begin(), as.end(), x))
#define rad_to_deg(rad) (((rad)/2/M_PI)*360)
#define rng(i,a,b) for(int i=int(a);i<int(b);i++)
#define rep(i,b) rng(i,0,b)
#define gnr(i,a,b) for(int i=int(b)-1;i>=int(a);i--)
#define per(i,b) gnr(i,0,b)
#define concat(xs, ys) (xs).insert((xs).end(), (ys).begin(), (ys).end())

const int mod = 1000000007;

struct mint {
    ll x;
    mint(ll x=0):x(x%mod){}

    mint& operator+=(const mint a) {
        if((x += a.x) >= mod) x -= mod;
        return *this;
    }

    mint& operator-=(const mint a) {
        if (x < a.x) {
          x += mod;
        }
        x -= a.x;
        return *this;
    }

    mint& operator*=(const mint a) {
        x = (x * a.x) % mod;
        return *this;
    }

    mint& operator/=(const mint a) {
        *this *= a.inv();
        return *this;
    }

    mint operator+(const mint a) const {
        mint res(*this);
        return res += a;
    }

    mint operator-(const mint a) const {
        mint res(*this);
        return res -= a;
    }

    mint operator*(const mint a) const {
        mint res(*this);
        return res *= a;
    }

    mint operator/(const mint a) const {
        mint res(*this);
        return res /= a;
    }

    mint pow(ll n) const {
        mint a(*this);
        mint res = 1;
        while (n > 0) {
            if (n & 1) res *= a;
            a *= a;
            n >>= 1;
        }
        return res;
    }

    mint inv() const {
        return pow(mod - 2);
    }
};

long mypow(long n) {
  long res = 1;
  rep(i, n) res*=10;
  return res;
}

long mypow5(long n) {
  long res = 1;
  rep(i, n) res*=5;
  return res;
}

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

  long n;
  cin >> n;

  if (n % 2) {
    cout << 0 << endl;
  } else {
    long res = 0;
    long sm = 0;
    for (long i = 27; i >= 1; i--) {
      long cnt = n / mypow5(i) / 2 - sm;
      sm += cnt;
      res += i * cnt;
    }
    // long comb = 0;
    // for (long i = 18; i >= 1; i--) {
    //   long cnt = n / mypow(i);
    //   res += (comb * 9 + cnt) * i;
    //   comb = comb * 10 + cnt;
    //   n = n%mypow(i); 
    // }
    cout << res << endl;
  }  
}


Measured memory_bytes: 256
import sys
def input(): return sys.stdin.readline().strip()

def resolve():
    n=int(input())
    l=list(map(int,input().split()))
    from collections import Counter
    c=Counter(l)# ()にカウンターの対象のリストの変数名
    ans=[]
    for key,value in c.items():
        if value>=4:
            ans.append(key)
            ans.append(key)
        elif value>=2:
            ans.append(key)
    ans.sort(reverse=True)
    if ans:
        print(ans[0]*ans[1])
    else:
        print(0)
resolve()

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

using namespace std;

typedef long long ll;

const int INF = 1e9;
const ll LLINF = 1e18;
const ll MOD = (ll)1e9 + 7;

int main()
{
  ll N, M; scanf("%lld %lld", &N, &M);
  if (N > M) { swap(N, M); }
  ll ans = 0;
  if (N == 1) {
    ans = (M == 1) ? 1 : M - 2;
  }
  else if (N == 2) { ans = 0; }
  else {
    ans = (N - 2) * (M - 2);
  }
  printf("%lld\n", ans);
  return 0;
}


Measured memory_bytes: 256
/**
 * @copyright (c) 2020 Daisuke Hashimoto
 */

#include <bits/stdc++.h>
using namespace std;
using Pair = pair<int64_t, int64_t>;
constexpr int64_t kInf = INT64_MAX / 2L;

// std::cout << std::setprecision(20) << 1.1 << endl;

const int64_t kMod = 1000000007LL;
// const int64_t kMod = 998244353LL;
struct Mint {
  int64_t value;
  Mint(int64_t value = 0LL) : value((value % kMod + kMod) % kMod) {}
  Mint operator-() const {
    return Mint(-value);
  }
  Mint &operator+=(const Mint rhs) {
    if ((value += rhs.value) >= kMod) {
      value -= kMod;
    }
    return *this;
  }
  Mint &operator-=(const Mint rhs) {
    if ((value += kMod - rhs.value) >= kMod) {
      value -= kMod;
    }
    return *this;
  }
  Mint &operator*=(const Mint rhs) {
    (value *= rhs.value) %= kMod;
    return *this;
  }
  Mint operator+(const Mint rhs) const {
    return Mint(*this) += rhs;
  }
  Mint operator-(const Mint rhs) const {
    return Mint(*this) -= rhs;
  }
  Mint operator*(const Mint rhs) const {
    return Mint(*this) *= rhs;
  }
  Mint Pow(int64_t p) const {
    if (p == 0LL) {
      return 1LL;
    } else if (p < 0LL) {
      return Pow(-p).Pow(kMod - 2LL);
    }
    Mint temp = Pow(p >> 1LL);
    temp *= temp;
    if (p & 1LL) {
      temp *= (*this);
    }
    return temp;
  }
  Mint Inv() const {
    return Pow(kMod - 2LL);
  }
  Mint &operator/=(const Mint a) {
    return *this *= a.Inv();
  }
  Mint operator/(const Mint a) const {
    return Mint(*this) /= a;
  }
};
std::ostream &operator<<(std::ostream &os, const Mint &a) {
  os << a.value;
  return os;
}

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

  int64_t N, K;
  cin >> N >> K;
  // const int64_t L = static_cast<int64_t>(T.length());
  vector<int64_t> A(N);
  for (int64_t i = 0; i < N; ++i) {
    cin >> A[i];
  }
  vector<int64_t> bigger_left(N, 0);
  vector<int64_t> bigger(N, 0);
  for (int64_t i = 0; i < N; ++i) {
    for (int64_t j = 0; j < N; ++j) {
      if (A[j] > A[i]) {
        ++bigger[i];
        if (j < i) {
          ++bigger_left[i];
        }
      }
    }
  }

  Mint KK = K;
  Mint result = 0;
  for (int64_t i = 0; i < N; ++i) {
    const int64_t bl = bigger_left[i];
    const int64_t b = bigger[i];
    // cerr << bl << ", " << b << endl;
    result += KK * bl + (KK - 1) * KK * b / 2;
  }
  cout << result.value << endl;
  return 0;
}


Measured memory_bytes: 3676
#include <bits/stdc++.h>
#define RI register int
typedef long long LL;

#define FILEIO(name) freopen(name".in", "r", stdin), freopen(name".out", "w", stdout);

using namespace std;

char buf[1000000], *p1 = buf, *p2 = buf;
inline char gc() {
  if (p1 == p2) p2 = (p1 = buf) + fread(buf, 1, 1000000, stdin);
  return p1 == p2 ? EOF : *(p1++);
}
template <class T> inline void read(T &n) {
  n = 0; RI ch = gc(), f;
  while ((ch < '0' || ch > '9') && ch != '-') ch = gc();
  f = (ch == '-' ? ch = gc(), -1 : 1);
  while (ch >= '0' && ch <= '9') n = n * 10 + (ch ^ 48), ch = gc();
  n *= f;
}

int main() {
  
#ifdef LOCAL
  FILEIO("a");
#endif

  int n, m; cin >> n >> m;
  int flag = 1;
  for (RI i = 1, j = n; i <= j && i <= m; ++i, --j) {
    if (n % 2 == 0 && j - i <= n - (j - i) && flag) --j, flag = 0;
    printf("%d %d\n", i, j);
  }

  return 0;
}

// created by Daniel yuan


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

using namespace std;

typedef long long ll;

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

int N;
map<ll, ll> cnt;

int main() {
    cin >> N;
    ll s = 0;
    cnt[0] = 1;
    rep(i, N) {
        ll a; cin >> a;
        s += a;
        cnt[s] = cnt[s] + 1;
    }
    
    ll ans = 0;
    for(auto iter=cnt.begin(); iter!=cnt.end(); iter++) {
        ans += (ll)iter->second * (iter->second - 1) / 2;
    }
    cout << ans << endl;
}

Measured memory_bytes: 12800
#include <iostream>
#include <algorithm>
#include <fstream>
#include <vector>
#include <deque>
#include <assert.h>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <stdio.h>
#include <string.h>
#include <utility>
#include <math.h>
#include <bitset>
#include <iomanip>
#include <complex>
using namespace std;
//#define int long long
typedef pair<int,int> pii;
typedef vector<int> vi;
typedef long double ld;
typedef long long ll;
#define X first
#define Y second
#define all(o) o.begin(), o.end()
#define endl '\n'
#define IOS ios::sync_with_stdio(0), cin.tie(0)
const int maxn = 300 + 10;
int dp[maxn][maxn][maxn];
int32_t main(){
	IOS;
	string s;
	cin >> s;
	int n = s.size(), k1;
	cin >> k1;
	for(int k=0; k<=k1; k++){
		for(int sz=1; sz<=n; sz++){
			for(int i=0; i+sz<=n; i++){
				int j = i+sz;
				if(sz == 1){
					dp[k][i][j] = 1;
					continue;
				}
				if(s[i] == s[j-1]){
					dp[k][i][j] = dp[k][i+1][j-1]+2;
					continue;
				}
				int x = dp[k][i+1][j];
				x = max(x, dp[k][i][j-1]);
				if(k) 
					x = max(x, dp[k-1][i+1][j-1] + 2);
				dp[k][i][j] = x;
			}
		}
	}
	cout << dp[k1][0][n] << endl;
}


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

int main() {
  int N, K; cin >> N >> K;
  int d[K], dk[N];
  bool sunuke[N];
  for (int i=0; i<N; i++) {
    sunuke[i] = false;
  }

  for (int i=0; i<K; i++) {
    cin >> d[i];
    for (int j=0; j<d[i]; j++) {
      cin >> dk[j];
      sunuke[dk[j]-1] = true;
    }
  }

  int ans = 0;
  for (int i=0; i<N; i++) {
    if (sunuke[i] == false) ans++;
  }
  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 3620
#include <bits/stdc++.h>
#define REV(v) reverse(v.begin(), v.end());
#define REP(i, n) for (int i = 0; i < n; i++)
#define REPR(i, n) for (int i = n; i >= 0; i--)
#define FOR(i, start, stop) for (int i = start; i < stop; i++)
#define FORR(i, start, stop) for (int i = start; i > stop; i--)
#define SORT(v, n) sort(v, v + n);
#define SORTR(v, n) sort(v, v + n,greater<int>());
#define VSORT(v) sort(v.begin(), v.end());
#define VSORTR(v) sort(v.begin(), v.end(),greater<int>());
#define REMOVE(v,n) remove(vector<int> v,v+v.size(),int n)
#define ERASE(v,n) v.erase(v.begin()+n);
#define ll long long
#define ull unsigned long long
#define pb(a) push_back(a)
#define INF 999999999
#define V(v,i,j) vector(v.begin() + i, v.begin() + j)
#define INSERT(va,vb) va.insert(va.end(), vb.begin(), vb.end())
using namespace std;
typedef vector<int> vint;
typedef pair<int, int> P;
typedef pair<ll, ll> LP;
typedef pair<int, P> PP;
typedef pair<ll, LP> LPP;
int dy[] = {0, 0, 1, -1};
int dx[] = {1, -1, 0, 0};
const int MOD = 1000000007;
void chmin(int &a, int b) { if (a > b) a = b; }

//vector< vector<int> > v (size1, vector<int>(size2) );

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

    ll sx,sy,tx,ty;
    cin>>sx>>sy>>tx>>ty;
    ll x,y;
    x=tx-sx;
    y=ty-sy;

    //1周目
    FOR(i,0,y)cout<<'U';
    FOR(i,0,x)cout<<'R';
    FOR(i,0,y)cout<<'D';
    FOR(i,0,x)cout<<'L';
    //2周目
    cout<<'L'<<'U';
    FOR(i,0,y)cout<<'U';
    FOR(i,0,x)cout<<'R';
    cout<<'R'<<'D';
    cout<<'R'<<'D';
    FOR(i,0,y)cout<<'D';
    FOR(i,0,x)cout<<'L';
    cout<<'L'<<'U';

}

Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<iomanip>
#include<math.h>
#include<complex>
#include<queue>
#include<deque>
#include<stack>
#include<map>
#include<set>
#include<bitset>
#include<functional>
#include<assert.h>
#include<numeric>
using namespace std;
#define REP(i,m,n) for(int i=(int)(m) ; i < (int) (n) ; ++i )
#define rep(i,n) REP(i,0,n)
using ll = long long;
const int inf = 1e9 + 7;

int main() {
	int a;
	cin >> a;
	a = a%10;
	if (a == 3)cout << "bon" << endl;
	else if (a == 0)cout << "pon" << endl;

	else if (a == 1)cout << "pon" << endl;

	else if (a == 6)cout << "pon" << endl;

	else if (a == 8)cout << "pon" << endl;

	else cout << "hon" << endl;
	return 0;
}

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

#define M 1000005
#define ep emplace_back
#define mp make_pair

typedef long long int lli;
typedef pair<lli,lli> PII;

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

//    freopen("input.txt","rt",stdin);

    string s;
    cin>>s;

int n = (int)s.size();
if(n>=5)
{
	if(s[2]==s[3] && s[4]==s[5])
		cout<<"Yes\n";
	else
		cout<<"No\n";
}
else
cout<<"no\n";

}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define _GLIBCXX_DEBUG
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define rrep(i, n) for (int i = 1; i < (n+1); ++i)
using namespace std;
using ll = long long;
const ll INF = +10010010000;

const int mod = 1e9+7;

struct mint{
    ll x;
    mint(ll x=0):x((x%mod+mod)%mod){}
    mint& operator+=(const mint a){
        (x+=a.x)%=mod;
        return *this;
    }
    mint& operator-=(const mint a){
        (x-=mod-a.x)%=mod;
        return *this;
    }
    mint& operator*=(const mint a){
        (x *= a.x)%= mod;
        return *this;
    }
    mint operator+(const mint a)const{
        mint res(*this);
        return res+=a;
    }
    mint operator-(const mint a)const{
        mint res(*this);
        return res-=a;
    }
    mint operator*(const mint a)const{
        mint res(*this);
        return res*=a;
    }
    mint pow(ll t) const {
      if(!t)return 1;
      mint a = pow(t>>1);
      a*=a;
      if(t%1)a*=*this;
      return a;
    }

    // for prime mod
    mint inv() const {
      return pow(mod-2);
    }
    mint& operator/=(const mint a){
      return (*this) *= a.inv();
    }
    mint operator/(const mint a)const{
      mint res(*this);
      return res/=a;
    }
};

struct combination{
  vector<mint> fact, ifact;
  combination(int n):fact(n+1),ifact(n+1){
    fact[0] = 1;
    for(int i = 1; i<n;++i)fact[i] = fact[i-1] * i;
    ifact[n] = fact[n].inv();
    for(int i = n; i>=1;--i) ifact[i-1] = ifact[i] * i;
  }
  mint operator()(int n, int k){
    if(k<0 || k>n)return 0;
    return fact[n] * ifact[k] + ifact[n-k]; 
  }
};


int main(){
    ll n;
    // string a,b,c;
    string A, B,C;
    queue<char> a,b,c;
    cin >> A >> B >> C;
    rep(i,A.size()){
        a.push(A[i]);
    }
    rep(i,B.size()){
        b.push(B[i]);
    }
    rep(i,C.size()){
        c.push(C[i]);
    }
    
    char s = 'a';
    while(1){
        if(s=='a'){
            if(a.empty()){
                s = 'A';
                break;
            }
            s = a.front();a.pop();
        }else if(s=='b'){
            if(b.empty()){
                s = 'B';
                break;
            }
            s = b.front();b.pop();
        }else if(s=='c'){
            if(c.empty()){
                s = 'C';
                break;
            }
            s = c.front();c.pop();
        }
    }
    cout << s <<endl;
    return 0;
}

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

int main(void)
{
    int i,n;
    int l,s;
    int dis;
    double a,a2;
    scanf("%d",&n);
    for(i=0;i<n;i++){
        scanf("%d:%d",&l,&s);
        a=l*30+s*0.5;
        a2=s*6;
        dis=fabs(a-a2);
        if(dis>180){
            dis=360-dis;
        }
        if(dis<30 && dis>=0){
            puts("alert");
        }else if(dis>=90 && dis<=180){
            puts("safe");
        }else{
            puts("warning");
        }
        a=0;a2=0;
    }
    return 0;
}

Measured memory_bytes: 576
#include<iostream>
#include<cstring>
using namespace std;
int main() 
{ 
	string a;
	cin>>a;
	for(int i=0;i<2;i++)
	{
		if(a[i]==a[i+1]&&a[i]==a[i+2])
		{
			cout<<"Yes"<<endl;
			return 0;
		}
	}
	cout<<"No"<<endl;
	return 0; 
}

Measured memory_bytes: 256
function Main(input){
  input = input.split(" ");
  
  var a = parseInt(input[0]);
  var b = parseInt(input[1]);
  var mul = a * b;
  if(mul%2 == 0){
    console.log("Even");
  }else{
    console.log("Odd");
  }
}
 
Main(require("fs").readFileSync("/dev/stdin", "utf8"));

Measured memory_bytes: 7372
#include <bits/stdc++.h>
using namespace std;
#define INF 2147483647
#define INFF 9223372036854775807
#define ll long long
#define REP(i,n) for(long long i=0;i<n;i++)
#define REPP(i,m,n) for(long long i=m;i<n;i++)
#define ALL(N) (N.begin(),N.end())
#define de cout << "line : " << __LINE__ << " debug" << endl;
#define pb push_back
#define pq priority_queue
#define Dcout(N) cout << setprecision(20) << N << endl;
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() {
    cin.tie(0);    
	ios::sync_with_stdio(false);
    int N;
    cin >> N;
    ll sum = 0;
    REPP(i,1,N){
        sum += i;
    }
    cout << sum << endl;
}

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

int main(){
int N, M, L, Q; cin >> N >> M >> L;
int A[M], B[M], C[M];
for(int i=0; i<M; i++){ cin >> A[i] >> B[i] >> C[i]; }
cin >> Q; int s[Q], t[Q];
for(int i=0; i<Q; i++){ cin >> s[i] >> t[i]; }

unsigned long d[N][N], INF=1000000000000;
for(int i=0; i<N; i++){ for(int j=0; j<N; j++){ d[i][j]=(i==j)?0:INF; }}
for(int i=0; i<M; i++){ d[A[i]-1][B[i]-1]=d[B[i]-1][A[i]-1]=C[i]; } 
for(int k=0; k<N; k++){ for(int i=0; i<N; i++){ for(int j=0; j<N; j++){
  d[i][j]=min(d[i][j], d[i][k]+d[k][j]);
}}}

int ans[N][N];
for(int i=0; i<N; i++){
  ans[i][i]=0;
  for(int j=i+1; j<N; j++){ ans[i][j]=ans[j][i]=(d[i][j]<=L)?1:N; }
}
for(int k=0; k<N; k++){ for(int i=0; i<N; i++){ for(int j=0; j<N; j++){
  ans[i][j]=min(ans[i][j], ans[i][k]+ans[k][j]);
}}}
for(int i=0, l=0; i<Q; i++){
  l=(ans[s[i]-1][t[i]-1]<N)?ans[s[i]-1][t[i]-1]-1:-1;
  cout << l << "\n"; }
}

Measured memory_bytes: 2688
n,k,q=map(int,input().split())
diff=q-k
count=[0]*n
arr=[int(input()) for _ in range(q)]
ans=['No']*n
for i in range(q):
  count[arr[i]-1]+=1
for i in range(n):
  if count[i]>diff:
    ans[i]='Yes'
  print(ans[i])

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

int main() {
   int N,Y;
   cin >> N >> Y;

   for(int i = 0; i <= N; i++) {
      for(int j = 0; j <= N - i; j++) {
         if(10000 * i + 5000 * j + 1000 * (N - i - j) == Y) {
            cout << i << " " << j << " " << N - i - j;
            return 0;
         }
      }
   }

   cout << -1 << " " << -1 << " " << -1;
 return 0;

}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <algorithm>
#include <cmath>
#include <cstdlib>
#include <vector>
#include <array>
#include <queue>
#include <stack>
#include <set>
#include <utility>
using namespace std;

int main() {
  int n, m; cin >> n >> m;
  vector<int> c;
  for (int i = 0; i < m; i++) {
    int temp; cin >> temp;
    c.push_back(temp);
  }
  sort(c.begin(), c.end());
  int A[m][n+1];
  for (int i = 0; i < m; i++)
    A[i][0] = 0;
  for (int j = 0; j < n+1; j++)
    A[0][j] = j;
  for (int i = 1; i < m; i++) {
    for (int j = 1; j <= n; j++) {
      if (j < c[i])
        A[i][j] = A[i-1][j];
      else {
        A[i][j] = min(A[i][j-c[i]]+1, A[i-1][j]);
      }
    }
  }
  cout << A[m-1][n] << endl;
}



Measured memory_bytes: 7056
n = int(input())

strs = {}

for i in range(n):
    s = input().split()
    if(s[0] == 'insert'):
        if(s[1] not in strs):
            strs[s[1]] = ''
    else:
        if(s[1] in strs):
            print('yes')
        else:
            print('no')


Measured memory_bytes: 33112
#include <bits/stdc++.h>
using namespace std;
using lint = long long;
const lint mod = 1e9 + 7;
#define all(x) (x).begin(), (x).end()
#define bitcount(n) __builtin_popcountl((lint)(n))
#define fcout cout << fixed << setprecision(15)
#define highest(x) (63 - __builtin_clzl(x))
template<class T> inline void YES(T condition){ if(condition) cout << "YES" << endl; else cout << "NO" << endl; }
template<class T> inline void Yes(T condition){ if(condition) cout << "Yes" << endl; else cout << "No" << endl; }
template<class T = string, class U = char>int character_count(T text, U character){ int ans = 0; for(U i: text){ ans += (i == character); } return ans; }
lint power(lint base, lint exponent, lint module){ if(exponent % 2){ return power(base, exponent - 1, module) * base % module; }else if(exponent){ lint root_ans = power(base, exponent / 2, module); return root_ans * root_ans % module; }else{ return 1; }}
struct position{ int y, x; }; position mv[4] = {{0, -1}, {1, 0}, {0, 1}, {-1, 0}}; // double euclidean(position first, position second){ return sqrt((second.x - first.x) * (second.x - first.x) + (second.y - first.y) * (second.y - first.y)); }
template<class T, class U> string to_string(pair<T, U> x){ return to_string(x.first) + "," + to_string(x.second); } string to_string(string x){ return x; }
template<class itr> void array_output(itr start, itr goal){ string ans; for(auto i = start; i != goal; i++) ans += to_string(*i) + " "; if(!ans.empty()) ans.pop_back(); cout << ans << endl; }
template<class itr> void cins(itr first, itr last){ for(auto i = first; i != last; i++){ cin >> (*i); } }
template<class T> T gcd(T a, T b){ if(a && b){ return gcd(min(a, b), max(a, b) % min(a, b)); }else{ return a; }} template<class T> T lcm(T a, T b){ return a / gcd(a, b) * b; }
struct combination{ vector<lint> fact, inv; combination(int sz) : fact(sz + 1), inv(sz + 1){ fact[0] = 1; for(int i = 1; i <= sz; i++){ fact[i] = fact[i - 1] * i % mod; } inv[sz] = power(fact[sz], mod - 2, mod); for(int i = sz - 1; i >= 0; i--){ inv[i] = inv[i + 1] * (i + 1) % mod; } } lint C(int p, int q) const{ if(q < 0 || p < q) return 0; return (fact[p] * inv[q] % mod * inv[p - q] % mod); } };
template<class itr> bool next_sequence(itr first, itr last, int max_bound){ itr now = last; while(now != first){ now--; (*now)++; if((*now) == max_bound){ (*now) = 0; }else{ return true; } } return false; }
template<class itr, class itr2> bool next_sequence2(itr first, itr last, itr2 first2, itr2 last2){ itr now = last; itr2 now2 = last2; while(now != first){ now--, now2--; (*now)++; if((*now) == (*now2)){ (*now) = 0; }else{ return true; } } return false; }

int main(){
    string S;
    cin >> S;
    int ans = 1, len = 1, ptr = 1;
    while(ptr < S.size()){
        if(len == 2){
            ptr += 1;
            len = 1;
            ans++;
            continue;
        }
        if(S[ptr - 1] == S[ptr]){
            if(ptr + 1 == S.size()){
                break;
            }
            ptr += 2;
            len = 2;
            ans++;
        }else{
            ptr += 1;
            len = 1;
            ans++;
        }
    }
    cout << ans << endl;
}


Measured memory_bytes: 640
#include <bits/stdc++.h>
#define rep(i,n) for (int i=0; i<(n); ++i)
using namespace std;
using ll=long long;
int main(){
    string s;
    cin>>s;
    bool a=false;
    rep(i,s.size()-1){
        if(s[i]=='A'&&s[i+1]=='C')a=true;
    }
    if(a==true)cout<<"Yes"<<endl;
    else cout<<"No"<<endl;
}

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

using namespace std;

int count_palindromes(int n) {
    int result = 0;
    for (int i = 1; i <= n; ++i) {
        string s = to_string(i);
        int L = s.size();
        bool is_palindrome = true;
        int j = 0;
        int k = L - 1;
        while (j < k) {
            if (s[j] != s[k]) {
                is_palindrome = false;
                break;
            }
            ++j;
            --k;
        }
        if (is_palindrome) {
            ++result;
        }
    }
    return result;
}

int main() {

    cin.tie(0);
    ios::sync_with_stdio(false);

    int A, B;
    cin >> A >> B;

    int result = count_palindromes(B) - count_palindromes(A - 1);
    cout << result << endl;

    return 0;
}


Measured memory_bytes: 3748
#include<cstdlib>
#include<cstdio>
int main(){
  int a,b,c,d;scanf("%d%d%d%d", &a,&b,&c,&d);
  if(abs(a-c)<=d||abs(a-b)<=d&&abs(b-c)<=d) puts("Yes");
  else puts("No");
}

Measured memory_bytes: 128
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
#include <limits.h>

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

int iin() {
    int i;
    scanf("%d", &i);
    return i;
}

long long llin() {
    long long i;
    scanf("%lld", &i);
    return i;
}

double din() {
    double i;
    scanf("%lf", &i);
    return i;
}

char cin() {
    char c;
    scanf("%c", &c);
    return c;
}

void stin(char *s) {
    scanf("%s", s);
}

void iout(int i) {
    printf("%d\n", i);
}

void llout(long long i) {
    printf("%lld\n", i);
}

void dout(double i) {
    printf("%lf\n", i);
}

void cout(char c) {
    printf("%c\n", c);
}

void stout(char *s) {
    printf("%s\n", s);
}

int main() {
    int n = iin(), k = iin(), x = iin(), y = iin();
    iout(n > k ? (k * x + (n - k) * y) : (n * x));
    return 0;
}


Measured memory_bytes: 128
from statistics import median
N = int(input())
AList = list(map(int, input().split()))
 
L = []
m = 0
for j in range(1, N+1):
    L.append(AList[j-1] - j)
m = median(L)
 
p = 0
for j in range(1, N+1):
    p += abs(AList[j-1] - j - m)
 
print(int(p))

Measured memory_bytes: 27248
s = list(input())

ans = []
for i in range(len(s)):
    if s[i] == "0":
        ans.append("0")
    elif s[i] == "1":
        ans.append("1")
    else:
        if len(ans) > 0:
            del ans[len(ans) - 1]

ans = ''.join(ans)
print(ans)

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

int main() {
	int n;
	cin >> n;
	string march = "MARCH";
	vector<ll> cnt (5,0);
	rep(i,n) {
		string s;
		cin >> s;
		rep(j,5) if (s[0] == march[j]) cnt[j]++;
	}
	ll ans = 0;
	for (int i=0;i<5;i++)
		for (int j=i+1;j<5;j++)
			for (int k=j+1;k<5;k++)
				ans += cnt[i]*cnt[j]*cnt[k];
	cout << ans << endl;

	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n)for(long long i=0;i<(n);i++)
using namespace std;
using P=pair<long long,long long>;
typedef unsigned long long ull;
typedef long long ll;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
 
const ll MOD=1e9+7;
const ll INF=1e18;
const double pi=acos(-1);
int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};


int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);  
  
  int n,m;
  cin >> n >> m;
  int a[m],ans[n]={};
  rep(i,m) cin >> a[i];
  rep(i,m){
    int cnt=0;
    rep(j,n){
      int b;
      cin >> b;
      if(b==a[i]){
        ans[j]++;
      }
      else cnt++;
    }
    ans[a[i]-1]+=cnt;
  }
  rep(i,n){
    cout << ans[i] << endl;
  }
}



Measured memory_bytes: 3188
#include <bits/stdc++.h>
using namespace std;
int main(){
	ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    double n;
    cin >> n;
    double pi = 3.14159265359;
    cout << 2 * pi * n;
	return 0;
}

Measured memory_bytes: 3796
#include<bits/stdc++.h>
using namespace std;
unsigned long long gcd(unsigned long long a,unsigned long long b){
    while(b){
        a=a%b;
        unsigned long long x=b;
        b=a;
        a=x;
    }
    return a;
}
int main(){
    int n,i;
    cin>>n;
    unsigned long long t[n],x=1,y;
    for(i=0;i<n;i++){
        cin>>t[i];
        y=gcd(x,t[i]);
        x=(t[i]/y)*x;
    }
    cout<<x<<endl;
return 0;
}




Measured memory_bytes: 256
#include <iostream>

using namespace std;

int sumDigits (int num) {
    int sum = 0;
    while (num > 0) {
        sum += num % 10;
        num /= 10;
    }
    return sum;
}

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

    int sum, total = 0;
    for (int i = 1; i <= n; i++) {
        sum = sumDigits(i);
        if (sum >= a && sum <= b) total += i;
    }

    cout << total << endl;
}

Measured memory_bytes: 256