akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
using namespace std;
#define MOD 1000000007
#define INF 1000000010
#define EPS 1e-9
#define fst first
#define scd second

#define debug(x) cout<<x<<endl;
#define repi(i,x,n) for(int i=x;i<n;i++)
#define rep(i,n) repi(i,0,n)
#define lp(i,n) repi(i,0,n)
#define repn(i,n) for(int i=n;i>=0;i--)
#define int long long
#define endl "\n"


signed main(){
  cin.tie(0);	
  ios::sync_with_stdio(false);
  int n;
  cin>>n;
  string s;
  cin>>s;
  if(s.substr(s.size()/2)==s.substr(0,s.size()/2) ){
    cout<<"Yes"<<endl;
  }
  else cout<<"No"<<endl;

  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <cmath>
#include <limits>
#include <iomanip>
#include <vector>
#include <cstring>
#include <queue>
#define rep(i,n) for(int i=0;i<n;i++)
#define rep1(i,n) for(int i=1;i<=n;i++)
using namespace std;
using ll = long long;
using ld = long double;
using ull = unsigned long long;
using uld = unsigned long long;
using P = pair<int,int>;
ll MAX(ll a,ll b,ll c){return max(a,max(b,c));}
ll MIN(ll a,ll b,ll c){return min(a,min(b,c));}
const ll mod = 1e9+7;
const ll INF = 1e10;
const int dx[4] = {0,1,0,-1};
const int dy[4] = {1,0,-1,0};
template<class T> inline bool chmax(T &a,T& b){if(a < b){a = b; return true;} else return false;}
template<class T> inline bool chmin(T &a,T& b){if(a > b){a = b; return true;} else return false;}
int main(){
    int n;
    cin >> n;
    vector<ll> a(n);
    rep(i,n){
        cin >> a[i];
    }
    sort(a.begin(),a.end());
    reverse(a.begin(),a.end());
    ll ans = 0;
    rep(i,n-1){
        if(i == 0){
            ans += a[0];
            continue;
        }
        int k = i;
        k--;
        k /= 2;
        ans += a[k+1];
    }
    cout << ans << endl;
}

Measured memory_bytes: 4840
#include<iostream>
#include<cstdio>
#include<cstring>
#include<cmath>
#include<algorithm>
#include<queue>
#include<stack>
#include<vector>
#include<map>
using namespace std;
const int maxn = 6e2+10;
const int maxm = 36e4+10;

int read(){
	int x=0,f=1;
	char c=getchar();
	while(!isdigit(c)){if(c=='-')f=-1;c=getchar();}
	while(isdigit(c)){x=(x<<3)+(x<<1)+c-48;c=getchar();}
	return x*f;
}

int to[maxm],net[maxm],h[maxn],e=1;
inline void add(int x,int y){
	to[++e]=y;net[e]=h[x];h[x]=e;
}

int k,m,n;
int siz[maxn];
double ans=1e15;
double dp[maxn];
inline void work(int now){
	dp[n]=0;
	double sum,max_;
	for(register int x=n-1;x>=1;x--){
		sum=0;max_=0;
		for(register int i=h[x];i;i=net[i]){
			int y=to[i];
			sum+=dp[y];
			max_=max(max_,dp[y]);
		}
		if(now==x && siz[x]>=2){
			sum-=max_;
			dp[x]=sum/(siz[x]-1)+1;
		}
		else dp[x]=sum/siz[x]+1;
	}
	ans=min(ans,dp[1]);
}

int main(){
	n=read();m=read();
	for(register int i=1;i<=m;i++){
		int x=read(),y=read();
		siz[x]++;
		add(x,y);
	}
	for(register int i=0;i<n;i++)work(i);
	printf("%.8lf\n",ans);
	return 0;
}

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

const int N = 22;

int main() {
    int n;
    array<int, N> v, c;

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

    int ans = INT_MIN;
    for (int i = 0; i < (1 << n); i++) {
        int cur_v = 0, cur_c = 0;
        for (int j = 0; j < n; j++) {
            if (i & (1 << j)) {
                cur_v += v[j];
                cur_c += c[j];
            }
        }
        ans = max(ans, cur_v - cur_c);
    }

    cout << ans << endl;
}



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

int main(){
	int n;
	cin >> n;
	string s;
	cin >> s;
	int ans = 0;
	for(int i = 0; i < n - 2; i++){
		if(s[i] == 'A' && s[i + 1] == 'B' && s[i + 2] == 'C'){
			ans++;
		}
	}
	cout << ans << endl;
}

Measured memory_bytes: 256
//include,using,define等
#pragma region header
#include <algorithm>
#include <bitset>
#include <tuple>
#include <cstdint>
#include <cctype>
#include <assert.h>
#include <stdlib.h>
#include <stdio.h>
#include <cassert>
#include <cfloat>
#include <climits>
#include <cmath>
#include <complex>
#include <ctime>
#include <deque>
#include <fstream>
#include <functional>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <list>
#include <limits>
#include <map>
#include <memory>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>
#include <math.h>
#include <cstring>

// ===============================================================
//using系
#pragma region header
using namespace std;
using ll = long long;
using lint = long long;
using vl = vector<long long>;
using vvl = vector<vector<long long>>;
using vvi = vector<vector<int>>;
using vs = vector<string>;
using vc = vector<char>;
using vcc = vector<vector<char>>;
using vm = vector<short>;
using vmm = vector<vector<short>>;
using pii = pair<int, int>;
using psi = pair<string, int>;
using ld = long double;
using ull = unsigned long long;
using ui = unsigned int;
using qul = queue<ll>;
using pql = priority_queue<ll>;
const int dx[] = { 1,0,-1,0 };
const int dy[] = { 0,1,0,-1 };
constexpr ll mod = 1e9 + 7;
constexpr long double pi = 3.141592653589793238462643383279;
#pragma endregion
// ========================================================================
//define
#pragma region header
//#define int long long
#define rep(i, n) for(ll i = 0; i < n; i++)
#define REP(i, n) for(ll i = 1; i <= n; i++)
#define INF (ll)10000000000000000
#define mod (ll)1000000007
#define P pair<lint,lint>
template <class T>
bool chmax(T& a, const T& b) {
	if (a < b) {
		a = b;  // aをbで更新
		return true;
	}
	return false;
}
template <class T>
bool chmin(T& a, const T& b) {
	if (a > b) {
		a = b;  // aをbで更新
		return true;
	}
	return false;
}
#pragma endregion
#pragma endregion


int main(void) {
	lint k; cin >> k;
	queue<lint> s;
	s.push(1);
	s.push(2);
	s.push(3);
	s.push(4);
	s.push(5);
	s.push(6);
	s.push(7);
	s.push(8);
	s.push(9);
	lint ans;
	for (int i = 0; i < k; i++) {
		lint cnt = s.front();
		s.pop();
		if (cnt % 10 != 0) {
			s.push(10 * cnt + (cnt % 10) - 1);
		}
		s.push(10 * cnt + (cnt % 10));
		if (cnt % 10 != 9) {
			s.push(10 * cnt + (cnt % 10) + 1);
		}
		if (i == k - 1) ans = cnt;
	}
	printf("%lld\n", ans);
	
	return 0;
}

Measured memory_bytes: 5116
#include <iostream>
#include <vector>
#include <algorithm>
#include <utility>
#include <string>
#include <cmath>
#include <cstring>
#include <queue>
#include <map>
#include <climits>
#include <set>
#define REP(i, n) for (int i = 0; i < n; i++)
#define REPR(i, n) for (int i = n; i >= 0; i--)
#define FOR(i, m, n) for (int i = m; i < n; i++)
#define FORR(i, m, n) for (int i = m; i >= n; i--)
#define SORT(v, n) sort(v, v + n);
#define VSORT(v) sort(v.begin(), v.end());
#define llong long long
#define pb(a) push_back(a)
using namespace std;
typedef pair<int, int> pii;
typedef long long int ll;
typedef pair<ll, ll> pll;
int dx[4] = {1, 0, 0, -1};
int dy[4] = {0, 1, -1, 0};
#define MOD 1000000007
#define ARRAY_MAX 200005
const int INF = 1e9 + 7;
int main()
{
    int N;
    cin >> N;
    if (N <= 999)
        cout << "ABC" << endl;
    else 
       cout << "ABD"  <<endl;
    return 0;
}

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

ans = 0
mod = 0
mod_dic = {0: 1}
for a in A:
    mod = (mod + a) % M
    mod_dic[mod] = mod_dic.get(mod, 0) + 1

for v in mod_dic.values():
    ans += v * (v - 1) // 2

print(ans)

Measured memory_bytes: 14696
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int maxn = 1e5;

int a[maxn], dp[maxn];

int main()
{
#ifdef LOCAL
    freopen("data.txt", "r", stdin);
#endif
    int n, k;
    scanf("%d%d", &n, &k);
    for (int i = 0; i != n; ++i)
        scanf("%d", &a[i]);
    memset(dp, 0x3f, sizeof(dp));
    dp[0] = 0;
    for (int i = 1; i != n; ++i)
        for (int j = i - 1, j_ = max(0, i - k); j >= j_; --j)
            dp[i] = min(dp[i], dp[j] + abs(a[i] - a[j]));
    printf("%d\n", dp[n - 1]);
}

Measured memory_bytes: 1024
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <cstring>

#include <iostream>
#include <complex>
#include <string>
#include <algorithm>
#include <numeric>
#include <vector>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <unordered_map>
#include <unordered_set>

#include <functional>
#include <cassert>

typedef long long ll;
using namespace std;

#ifdef LOCAL
#define debug(x) cerr << __LINE__ << " : " << #x << " = " << (x) << endl;
#else
#define debug(x) ;
#endif

#define mod 1000000007 //1e9+7(prime number)
#define INF 1000000000 //1e9
#define LLINF 2000000000000000000LL //2e18
#define SIZE 200010


int main(){
  int n;
  int dp[SIZE][3] = {};

  scanf("%d", &n);

  for(int i=0;i<n;i++){
    int a, b, c;

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

    dp[i+1][0] = max({dp[i+1][0], dp[i][1] + a, dp[i][2] + a});
    dp[i+1][1] = max({dp[i+1][1], dp[i][0] + b, dp[i][2] + b});
    dp[i+1][2] = max({dp[i+1][2], dp[i][0] + c, dp[i][1] + c});
  }

  cout << max({dp[n][0], dp[n][1], dp[n][2]}) << endl;

  return 0;
}


Measured memory_bytes: 2560
#include <cstdio>
#include <iostream>
#include <vector>
#include <list>
#include <cmath>
#include <fstream>
#include <algorithm>
#include <string>
#include <queue>
#include <set>
#include <map>
#include <complex>
#include <iterator>
#include <cstdlib>
#include <cstring>
#include <sstream>
#include <stack>

using namespace std;

const double EPS=(1e-10);
typedef long long ll;
typedef pair<int,int> pii;
typedef complex<double> P;
bool EQ(double a,double b){
  return abs((a)-(b))<EPS;
}
void fast_stream(){
  std::ios_base::sync_with_stdio(0);
}

const int MAX_V = 300;
const double INF=1000000000;
int n,m;
P troops[101];
P bases[101];
double vs[101];
// troopÂÃbaseÂÃÂÃÂÃÂÂ®ÂÂÂÃ
double times[101][101];
// ÂOÂÂÂtÂÃÂÂÂXÂgÂ\ÂÂ»
vector<int> G[MAX_V];
// Â}ÂbÂ`ÂÂÂOÂÃÂyÂA
int match[MAX_V];
// dfsÂÃÂÂ·ÂÃÂÃÂÂ²ÂÃÂÂ½ÂÂ©ÂÃÂÂ¤ÂÂ©ÂÃÂtÂÂÂO
bool used[MAX_V];

// uÂÃvÂÃ°ÂÂÂÃÂÃÂÃ°ÂOÂÂÂtÂÃÂÃÂÃ
void add_edge(int u,int v){
  G[u].push_back(v);
  G[v].push_back(u);
}

// ÂÂÂÃÂpÂXÂÃ°dfsÂÃÂTÂÂ·
bool dfs(int v){
  used[v] = true;
  for(int i = 0; i < G[v].size(); i++){
    int u = G[v][i],w = match[u];
    if(w < 0 || !used[w] && dfs(w)){
      match[v] = u;
      match[u] = v;
      return true;
    }
  }
  return false;
}

// ÂÃ±ÂÂÂOÂÂÂtÂÃÂÃÂÃ¥Â}ÂbÂ`ÂÂÂOÂÃ°ÂÂÂÃÂÃ©
int bipartite_matching(int V){
  int res = 0;
  memset(match,-1,sizeof(match));
  for(int v = 0; v < V; v++){
    if(match[v] < 0){
      memset(used,0,sizeof(used));
      if(dfs(v))res++;
    }
  }
  return res;
}

// ÂÂÂÃtÂÃÂÃ°ÂÂÂÃ°ÂÂÂÂ½ÂÂ¹ÂÃ©ÂÂ©
bool check(double t){
  for(int i=0;i<MAX_V;i++)G[i].clear();
  for(int i=0;i<n;i++){
    for(int j=0;j<m;j++){
      // ÂÂÂÃÂÃÂÃÂÃÂÂÂÂ¤ÂÃÂÃ§ÂÃÂAÂÂÂÃ
      if(EQ(t,times[i][j])||t>times[i][j])
	add_edge(i,n+j);
    }
  }
  return bipartite_matching(n+m)==m;
}

int main(){

  while(cin>>n>>m&&(n|m)){
    for(int i=0;i<n;i++){
      int x,y;
      cin>>x>>y>>vs[i];
      troops[i]=P(x,y);
    }
    for(int i=0;i<m;i++){
      int x,y;
      cin>>x>>y;
      bases[i]=P(x,y);
    }
    for(int i=0;i<n;i++){
      for(int j=0;j<m;j++){
	double d=abs(troops[i]-bases[j]);
	times[i][j]=d/vs[i];
      }
    }
    double ub=INF;
    double lb=0;
    int cnt=100;
    while(cnt--){
      double mid=(ub+lb)/2;
      if(check(mid))ub=mid;
      else lb=mid;
    }
    printf("%.10f\n",ub);
  }

  return 0;
}

Measured memory_bytes: 1192
#include <iostream>

using namespace std;

int main()
{
    int h,w;
    cin >> h>> w;
    int a[h][w];
    for(int i=0;i<h;i++){
        for(int j=0;j<w;j++){
            cin >> a[i][j];
        }
    }
    int ans=10000000;
    for(int i=0;i<h;i++){
        for(int j=0;j<w;j++){
                int s=0;
            for(int k=0;k<h;k++){
                for(int l=0;l<w;l++){
                    int dt=k<i?i-k:k-i;
                    int dy=l<j?j-l:l-j;
                    s+=min(dt,dy)*a[k][l];
                }
            }
        ans=min(ans,s);
        }
    }

    cout << ans << endl;
    return 0;

}



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

int main() {
    int A[3][3];
    for(int i=0; i<3; i++) 
        for(int j=0; j<3; j++)
            cin >> A[i][j];
    int N, b;
    cin >> N;
    for(int i=0; i<N; i++) {
        cin >> b;
        for(int i=0; i<3; i++) 
                for(int j=0; j<3; j++)
                    if(A[i][j] == b)
                        A[i][j] = 0;
    }

    string ans = "No";
    for(int i=0; i<3; i++) {
        if(A[i][0]+A[i][1]+A[i][2] == 0) 
            ans = "Yes";
        if(A[0][i]+A[1][i]+A[2][i] == 0) 
            ans = "Yes";
    }
    if(A[0][0]+A[1][1]+A[2][2] == 0) 
        ans = "Yes";
    if(A[0][2]+A[1][1]+A[2][0] == 0) 
        ans = "Yes";
    cout << ans << endl;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
int main(){
    ll N,r,g,b;
    cin >> r >> g >> b;
    N = 100*r + 10*g + b;
    
    cout << ((N%4 == 0) ? "YES" : "NO") << "\n";
    return 0;
}


Measured memory_bytes: 256
#include <stdio.h>
#include <algorithm>
#include <math.h>
#include <string.h>
const int N = 1e5+10;
#define ll long long
long long n;
char ans[N];
int main() {
	scanf("%lld", &n); int cnt = 0;
	if (n <= 26) {printf("%c\n", n+'a'-1); return 0;}
	ll x = 26, nn = n; int p = 2;
	while (x*26+26 < nn) x = x*26+26, ++p;
	n -= x+1;
	while (n) {
		int x = n % 26;
		// printf("%lld %d\n", n, x);
		ans[++cnt] = (char)(x+'a');
		n /= 26;
	}
	while (cnt < p) ans[++cnt] = 'a';
	for (int i=cnt; i>0; i--) printf("%c", ans[i]); printf("\n");
}

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

int main() {
bool div2=true;
int N,cnt=0; cin>>N;
  vector<int> A(N);
  for(int i=0; i<N; i++){
    cin>>A.at(i);}
  
  while(div2){
  for(int i=0; i<N; i++){
    if(A.at(i)%2!=0){div2=false;goto end;}
    else {A.at(i)/=2;}
    if(i==N-1){cnt++;}
  }
  }
  end: cout<<cnt<<endl;
}

Measured memory_bytes: 256
N, K, Q = map(int, input().split())
N_list = [0] * N

for _ in range(Q):
  A = int(input())
  A -= 1
  N_list[A] += 1

for n in N_list:
  if n + K - Q > 0:
    print('Yes')
  else:
    print('No')


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

#ifdef LOCAL
#define DEBUG(...) debug(#__VA_ARGS__, __VA_ARGS__);
#else
#define DEBUG(...)
#endif

template<typename T, typename S> ostream& operator << (ostream &os, const pair<T, S> &p) {return os << "(" << p.first << ", " << p.second << ")";}
template<typename C, typename T = decay<decltype(*begin(declval<C>()))>, typename enable_if<!is_same<C, string>::value>::type* = nullptr>
ostream& operator << (ostream &os, const C &c) {bool f = true; os << "["; for (const auto &x : c) {if (!f) os << ", "; f = false; os << x;} return os << "]";}
template<typename T> void debug(string s, T x) {cerr << s << " = " << x << "\n";}
template<typename T, typename... Args> void debug(string s, T x, Args... args) {cerr << s.substr(0, s.find(',')) << " = " << x << " | "; debug(s.substr(s.find(',') + 2), args...);}

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    //freopen("input.txt", "r", stdin);
    //freopen("output.txt", "w", stdout);

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

    cout << (b - a < k && a % k != 0 && b % k != 0 && a % k <= b % k ? "NG" : "OK") << "\n";

    return 0;
}


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

int main(){
    int n,k;
    string s;
    cin >> n >> k >> s;
    s.at(k - 1) = tolower(s.at(k - 1));
    cout << s << endl;
}


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

int main() {
  int a, b, c, d;
  cin >> a >> b >> c >> d;
  int ans = 0;
  if(a > b)
    ans += b;
  else
    ans += a;
  if(c > d)
    ans += d;
  else
    ans += c;
  cout << ans << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <queue>
#include <algorithm>
#include <functional>
#include <numeric>
#include <set>
// #include <bits/stdc++.h>


using namespace std;
typedef long long li;

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

    li n;
    cin >> n;
    li nim = 0;

    for (int i = 0; i < n; ++i) {
        li a, k;
        cin >> a >> k;
        li grundy;
        while (true) {
            const li stride = a / k;
            if (stride == 0) {
                grundy = 0;
                break;
            }
            const li prevmax = stride * k - 1;
            if (a == prevmax + 1) {
                grundy = stride;
                break;
            }
            const li steps = (a - (prevmax + 1) + stride) / (stride + 1);
            a -= steps * (stride + 1);
        }

        nim ^= grundy;
    }

    cout << (nim ? "Takahashi" : "Aoki") << endl;
    return 0;
}


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

int main(){
    int A, B, C, K, i;
    int ans = 0;

    scanf("%d %d %d %d", &A, &B, &C, &K);

    if(K <= A)ans = K;
    else ans = A;
    if(A+B < K)ans -= (K - (A+B));

    printf("%d\n", ans);  

    return 0;
}

Measured memory_bytes: 1732
use std::collections::BinaryHeap;
use std::collections::HashMap;
use std::collections::HashSet;
use std::collections::VecDeque;

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)*}
    };
    ($next:expr, mut $var:ident : $t:tt $($r:tt)*) => {
        let mut $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")
    };
}

const MOD: i64 = 1_000_000_007;

fn main() {
    input! {
        s: chars,
        k: usize,
    }

    let mut dp = vec![vec![vec![0; 5]; 2]; s.len() + 1];
    dp[0][0][0] = 1;
    for i in 1..s.len() + 1 {
        let n = s[i - 1] as usize - '0' as usize;
        for j in 0..k + 1 {
            // smallが確定していないものは現在位置まで入力とすべて同じ
            if n == 0 {
                // 現在のけたが0
                // smallが確定していなかったもの
                dp[i][0][j] += dp[i - 1][0][j];

                // smallが確定していたもの
                dp[i][1][j] += dp[i - 1][1][j]; // 0の場合
                dp[i][1][j + 1] += 9 * dp[i - 1][1][j]; // 0以外
            } else {
                // 0以外
                // smallが確定していなかったもの
                dp[i][0][j + 1] += dp[i - 1][0][j]; // nと同じ値
                dp[i][1][j] += dp[i - 1][0][j]; // 0でsmall確定
                dp[i][1][j + 1] += (n - 1) * dp[i - 1][0][j]; // 0以外でnより小さくsmall確定

                // smallが確定していたもの
                dp[i][1][j] += dp[i - 1][1][j]; // 0の場合
                dp[i][1][j + 1] += 9 * dp[i - 1][1][j]; // 0以外
            }
        }
    }

    //println!("{:?}", dp);
    println!("{}", dp[s.len()][0][k] + dp[s.len()][1][k]);
}


Measured memory_bytes: 4352
import java.util.Scanner;

public class Main {
	static int[] l;
	static int min = 1000000000;
	static int N, A, B, C;
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		N = sc.nextInt();
		A = sc.nextInt();
		B = sc.nextInt();
		C = sc.nextInt();
		l = new int[N];
		for(int i = 0; i < N; i++) {
			l[i] = sc.nextInt();
		}
		sc.close();
		dfs(0, 0, 0, 0, 0);
		System.out.println(min);
	}
	static void dfs(int n, int a, int b, int c, int d) {
		if(n == N) {
			if(a == 0 || b == 0 || c == 0) {
				return;
			}
			int cost = Math.abs(A - a) + Math.abs(B - b) + Math.abs(C - c);
			cost += d - 30;
			min = Math.min(min, cost);
			return;
		}
		dfs(n + 1, a, b, c, d);
		dfs(n + 1, a + l[n], b, c, d + 10);
		dfs(n + 1, a, b + l[n], c, d + 10);
		dfs(n + 1, a, b, c + l[n], d + 10);
	}
}

Measured memory_bytes: 22868
using AtCoderBeginnerContest130.Questions;
using AtCoderBeginnerContest130.Extensions;
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;

namespace AtCoderBeginnerContest130.Questions
{
    public class QuestionA : AtCoderQuestionBase
    {
        public override IEnumerable<object> Solve(TextReader inputStream)
        {
            var xa = inputStream.ReadIntArray();
            var x = xa[0];
            var a = xa[1];
            yield return x < a ? 0 : 10;
        }
    }
}


namespace AtCoderBeginnerContest130
{
    class Program
    {
        static void Main(string[] args)
        {
            IAtCoderQuestion question = new QuestionA();    // 問題に合わせて書き換え
            var answers = question.Solve(Console.In);
            foreach (var answer in answers)
            {
                Console.WriteLine(answer);
            }
        }
    }
}

#region Base Classes

namespace AtCoderBeginnerContest130.Questions
{

    public interface IAtCoderQuestion
    {
        IEnumerable<object> Solve(string input);
        IEnumerable<object> Solve(TextReader inputStream);
    }

    public abstract class AtCoderQuestionBase : IAtCoderQuestion
    {
        public IEnumerable<object> Solve(string input)
        {
            var stream = new MemoryStream(Encoding.Unicode.GetBytes(input));
            var reader = new StreamReader(stream, Encoding.Unicode);

            return Solve(reader);
        }

        public abstract IEnumerable<object> Solve(TextReader inputStream);
    }

}

#endregion

#region Extensions

namespace AtCoderBeginnerContest130.Extensions
{
    internal static class TextReaderExtensions
    {
        internal static int ReadInt(this TextReader reader) => int.Parse(ReadString(reader));
        internal static long ReadLong(this TextReader reader) => long.Parse(ReadString(reader));
        internal static double ReadDouble(this TextReader reader) => double.Parse(ReadString(reader));
        internal static string ReadString(this TextReader reader) => reader.ReadLine();

        internal static int[] ReadIntArray(this TextReader reader, char separator = ' ') => ReadStringArray(reader, separator).Select(int.Parse).ToArray();
        internal static long[] ReadLongArray(this TextReader reader, char separator = ' ') => ReadStringArray(reader, separator).Select(long.Parse).ToArray();
        internal static double[] ReadDoubleArray(this TextReader reader, char separator = ' ') => ReadStringArray(reader, separator).Select(double.Parse).ToArray();
        internal static string[] ReadStringArray(this TextReader reader, char separator = ' ') => reader.ReadLine().Split(separator);
    }
}

#endregion

Measured memory_bytes: 13396
#include<bits/stdc++.h>
using namespace std;
int main()
{
  int n,m,i,j,r1,r2;
  vector<pair<int,int>> v;
  cin >> n >> m;
  for(i=1;i<=m;i++)
  {
      cin >> r1 >> r2;
      v.push_back(make_pair(r1,r2));
  }
  sort(v.begin(),v.end());
  i = 1;
  int k=1;
  int m1 = v[0].first;
  int m2 = v[0].second;
  while(i<m)
  {
      if(m1<=v[i].first && m2>=v[i].first)
      {
          m1=max(m1,v[i].first);
          m2=min(m2,v[i].second);
      }
     else
     {
         k=0;
         break;
     }
      
      i++;
  }
  if(k)
  cout << m2-m1+1 << endl;
  else
  cout << "0";
  return 0;
  }

Measured memory_bytes: 1400
import itertools
import collections
from math import gcd
def prime_factor_table(n):
    table = [0] * (n + 1)
    
    for i in range(2, n + 1):
        if table[i] == 0:
            for j in range(i + i, n + 1, i):
                table[j] = i
    
    return table

def prime_factor(n, prime_factor_table):
    prime_count = dict()
    
    while prime_factor_table[n] != 0:
        prime_count[prime_factor_table[n]] = 1
        n //= prime_factor_table[n]
    prime_count[n] = 1
    
    return prime_count

pp = prime_factor_table(10**6)
#print(prime_factor(21, pp))
N, = map(int, input().split())
X = list(map(int, input().split()))
d = dict()
f = 0
ff = 0
for x in X:
    y = prime_factor(x, pp)
    if x == 1:
        ff = 1
        continue
    for k in y:
        if k in d:
            f = 1
            d[k] += 1
        else:
            d[k] = 1
if f:
    m = 0
#    print(d)
    for k in d:
        m = max(m, d[k])
    if m != N or ff:
        print("setwise coprime")
    else:
        print("not coprime")
else:
    print("pairwise coprime")


Measured memory_bytes: 190512
#include <iostream>
#include <cstdlib>
using namespace std;
int main()
{
    int h, w;
    cin >> h >> w;
    int m[h][w];
    for (int i = 0; i < h; i++) {
        for (int j = 0; j < w; j++) {
            cin >> m[i][j];
        }
    }   
    int t = 0;
    int a[h * w][4];
    for (int i = 0; i < h - 1; i++) {
        for (int j = 0; j < w; j++) {
            if (m[i][j] % 2 != 0) {

                a[t][0] = i + 1;
                a[t][1] = j + 1;
                a[t][2] = i + 2;
                a[t][3] = j + 1;
                //1 no zure

                m[i + 1][j] += 1;
                t++;
            }
        }
    }   
    for (int i = 0; i < w - 1; i++) {
        if (m[h - 1][i] % 2 != 0) {

            a[t][0] = h;
            a[t][1] = i + 1;
            a[t][2] = h;
            a[t][3] = i + 2;

            m[h - 1][i + 1] += 1;
            t++;
        }
    }   
    cout << t << endl;
    for (int i = 0; i < t; i++) {
        cout
            << a[i][0] << " " 
            << a[i][1] << " " 
            << a[i][2] << " " 
            << a[i][3] << endl;
    }   
}


Measured memory_bytes: 6784
//インクルード(アルファベット順)
#include<algorithm>//sort,二分探索,など
#include<bitset>//固定長bit集合
#include<chrono>//実行時間計測
#include<cmath>//pow,logなど
#include<complex>//複素数
#include<deque>//両端アクセスのキュー
#include<functional>//sortのgreater
#include<iomanip>//setprecision(浮動小数点の出力の誤差)
#include<iostream>//入出力
#include<iterator>//集合演算(積集合,和集合,差集合など)
#include<map>//map(辞書)
#include<numeric>//iota(整数列の生成),gcdとlcm,accumulate
#include<queue>//キュー
#include<set>//集合
#include<stack>//スタック
#include<string>//文字列
#include<unordered_map>//順序保持しないmap
#include<unordered_set>//順序保持しないset
#include<utility>//pair
#include<vector>//可変長配列

using namespace std;
typedef long long ll;
//マクロ
//forループ
//引数は、(ループ内変数,動く範囲)か(ループ内変数,始めの数,終わりの数)、のどちらか
//Dがついてないものはループ変数は1ずつインクリメントされ、Dがついてるものはループ変数は1ずつデクリメントされる
#define REP(i,n) for(ll i=0;i<ll(n);i++)
#define REPD(i,n) for(ll i=n-1;i>=0;i--)
#define FOR(i,a,b) for(ll i=a;i<=ll(b);i++)
#define FORD(i,a,b) for(ll i=a;i>=ll(b);i--)
//xにはvectorなどのコンテナ
#define ALL(x) x.begin(),x.end()
#define SIZE(x) ll(x.size())
//定数
#define INF 1000000000000 //10^12:∞
#define MOD 1000000007 //10^9+7:合同式の法
#define MAXR 100000 //10^5:配列の最大のrange
//略記
#define PB push_back //挿入
#define MP make_pair //pairのコンストラクタ
#define F first //pairの一つ目の要素
#define S second //pairの二つ目の要素
#define PI 3.14159265358979323846264338327950L

#define YESNO(T) if(T){cout<<"YES"<<endl;}else{cout<<"NO"<<endl;}
#define yesno(T) if(T){cout<<"yes"<<endl;}else{cout<<"no"<<endl;}
#define YesNo(T) if(T){cout<<"Yes"<<endl;}else{cout<<"No"<<endl;}

#define int long long
#define Graph vector<vector<int> >
#define PII pair<int,int>
#define VI vector<int>
#define VVI vecotor<vector<int> >
#define VPII vector<pair<int,int> >

template<typename A, size_t N, typename T>

void Fill(A (&array)[N], const T &val) {
	std::fill( (T*)array, (T*)(array + N), val );
}


//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
//ここにグローバル変数宣言
int H, W, sh, sw, gh, gw;
int dh[4] = {1, 0, -1, 0};
int dw[4] = {0, 1, 0, -1};//BFS関連







//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
//ここに関数宣言
int ctoi(char c) {
	switch (c) {
	case '0': return 0;
	case '1': return 1;
	case '2': return 2;
	case '3': return 3;
	case '4': return 4;
	case '5': return 5;
	case '6': return 6;
	case '7': return 7;
	case '8': return 8;
	case '9': return 9;
	default: return 0;
	}
}










//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
signed main() {
	//入力の高速化用のコード
	ios::sync_with_stdio(false);
	cin.tie(nullptr);
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

string S;
cin>>S;
REP(i,S.size()){
	cout<<'x';
}


















return 0;

}







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

public class MainClass
{
	public const long Giri = 1000000007;

	
	public static void Main(string[] args)
	{
		string[] t = Input();
		int n = int.Parse(t[0]);
		long k = long.Parse(t[1]);
		int q = int.Parse(t[2]);
		int[] a = new int[n];
		for(int i = 0; i < q; i++)
		{
			a[int.Parse(Console.ReadLine())-1]++;
		}
		for(int i = 0; i < n; i++)
		{
			if(k - (q - a[i]) > 0)
			{
				Console.WriteLine("Yes");
			}
			else
			{
				Console.WriteLine("No");
			
			}
		}
		
	}
	
	public static long GCD(long a, long b)
	{
		if(b == 1)
			return a;
		long p = b / a;
		return GCD(a, b - a*p);
	}
	
	public static string[] Input()
	{
		return Console.ReadLine().Split(' ');
	}

	
	public static int Clamp(int val, int max, int min = 0)
	{
		return Math.Min(max, Math.Max(min, val));
	}

}



Measured memory_bytes: 17600
import java.util.Arrays;
import java.util.BitSet;
import java.util.Scanner;
import java.util.stream.IntStream;

public class Main{
	static Scanner s=new Scanner(System.in);
	public static void main(String[] __){
		while(true){
			int n=s.nextInt();
			if(n==0)return;
			
			int[][] in=new int[n][];
			for(int i=0;i<n;i++) {
				in[i]=IntStream.range(0,s.nextInt()).map(o->s.nextInt()).toArray();
			}
			BitSet list=new BitSet(n);
			IntStream.range(0,s.nextInt()).map(o->s.nextInt()).forEach(list::set);
			
			int r=-1;
			for(int i=0;i<n;i++) {
				BitSet clone=(BitSet)list.clone();
				Arrays.stream(in[i]).forEach(clone::clear);
				if(clone.isEmpty()) {
					if(r==-1)
						r=i+1;
					else
						r=0;
				}
			}
			System.out.println(r==0?-1:r);
		}
	}
}

Measured memory_bytes: 73136
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(n);i++)
#define all(v) v.begin(),v.end()
#define len(x) (ll)(x).length()
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
ll gcd(ll a,ll b){if(a%b==0){return b;}else{return(gcd(b,a%b));}}
ll lcm(ll a,ll b){return a*b/gcd(a,b);}
const int INF=1e9;
const ll INFS=1e18;
const int MOD=INF+7;
const int di[] = {-1,0,1,0};
const int dj[] = {0,-1,0,1};
const double PI=acos(-1);

int main() {
  int n,m;
  cin>>n>>m;
  vector<int> x(m);
  rep(i,m) cin>>x[i];
  sort(all(x));
  vector<int> dist(m-1);
  rep(i,m-1){
    dist[i]=x[i+1]-x[i];
  }
  sort(all(dist));
  int ans=0;
  if(m-n<=0){
    cout<<0<<endl;
    return 0;
  }
  rep(i,m-n){
    ans+=dist[i];
  }
  cout<<ans<<endl;
}

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

#define rep(i, n) REP(i, 0, n)
#define ALL(v) v.begin(), v.end()
#define MSG(a) cout << #a << " " << a << endl;
#define REP(i, x, n) for (int i = x; i < n; i++)
#define OP(m) cout << m << endl
typedef long long ll;
typedef unsigned long long ull;

int main()
{
    queue<string> q_n;
    queue<int> q_t;

    int n, q;
    cin >> n >> q;

    rep(i, n)
    {
        string name;
        int time;

        cin >> name >> time;

        q_n.push(name);
        q_t.push(time);
    }
    int sum_t = 0;

    while (q_t.empty() == 0)
    {
        int time = q_t.front();
        if (time <= q)
        {
            sum_t += time;
            cout << q_n.front() << " " << sum_t << endl;
        }
        else
        {
            sum_t += q;
            q_t.push(time - q);
            q_n.push(q_n.front());
        }
        q_n.pop(), q_t.pop();
    }

    return 0;
}


Measured memory_bytes: 5852
#include <queue>
#include <vector>
#include <iomanip>
#include <iostream>
#include <algorithm>
using namespace std;
int n; double x[1009], y[1009], r[1009]; vector<pair<int, double> > G[1009];
int main() {
	cin >> x[0] >> y[0] >> x[1] >> y[1];
	cin >> n;
	for (int i = 0; i < n; i++) cin >> x[i + 2] >> y[i + 2] >> r[i + 2];
	for (int i = 0; i < n + 2; i++) {
		for (int j = i + 1; j < n + 2; j++) {
			double dist = max(hypot(x[i] - x[j], y[i] - y[j]) - r[i] - r[j], 0.0);
			G[i].push_back(make_pair(j, dist));
			G[j].push_back(make_pair(i, dist));
		}
	}
	priority_queue<pair<double, int> > que; que.push(make_pair(0, 0));
	vector<double> d(n + 2, 1.0e+10); d[0] = 0;
	while (!que.empty()) {
		int u = que.top().second; que.pop();
		for (pair<int, double> e : G[u]) {
			if (d[e.first] > d[u] + e.second) {
				d[e.first] = d[u] + e.second;
				que.push(make_pair(-d[e.first], e.first));
			}
		}
	}
	cout << fixed << setprecision(15) << d[1] << endl;
	return 0;
}

Measured memory_bytes: 20756
#include <iostream>
#include<bits/stdc++.h>
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define ll long long
#define pii std::pair<int,int>
#define pli std::pair<ll,int>
#define pil std::pair<int,ll>
#define psi std::pair<string,int>
#define pll std::pair<ll,ll>
#define pci std::pair<char,int>
#define sll(x) scanf("%lld",&x)
#define prll(x) printf("%lld ",x)
#define pri(x) printf("%d ",x)
#define si(x) scanf("%d",&x)
#define pb push_back
#define vll std::vector<ll>
#define vpi std::vector<std::pair<int,int>>
#define vi std::vector<int>
#define vvi std::vector<std::vector<int>>
#define vvpil std::vector<std::vector<std::pair<int,ll>>>
#define vlpii std::vector<std::list<pii>>
#define vlpil std::vector<std::list<pil>>
#define li std::list<int>
#define lpil std::list<pil>
#define Endl printf("\n")
#define vli vector<list<int>>
#define vvll vector<vector<ll>>
#define mp make_pair
#define ma 100000000
#define mod 1000000007
const ll  INF=10000000000000;
using namespace std;

int main()
{
    IOS;
    int n;ll we;cin>>n>>we;
    ll w[n+1];
    ll v[n+1];
    ll sum=0;
    for(int i=1;i<=n;i++){
        cin>>w[i]>>v[i];
        sum+=v[i];
    }
    ll dp[n+1][sum+1];
    for(int i=0;i<n+1;i++){
        for(int j=0;j<=sum;j++) dp[i][j]=INF;
    }
    dp[0][0]=0;
    ll res=0;
    ll s1=0;
    for(int i=0;i<n;i++){
        s1+=v[i+1];
        for(ll j=0;j<=s1;j++){
            if(j-v[i+1]>=0){
                dp[i+1][j]=min(dp[i+1][j],dp[i][j-v[i+1]]+w[i+1]);
            }
            dp[i+1][j]=min(dp[i+1][j],dp[i][j]);
            if(dp[i+1][j]<=we) res=max(res,j);
        }


    }
    cout<<res;
    return 0;
}


Measured memory_bytes: 79232
#include <bits/stdc++.h>
using namespace std;
#define pb push_back
#define mp make_pair
#define ff first
#define ss second
typedef long long ll;

typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
int i,j,k;
int aa[int(1e5)];
int bb[int(1e5)];
int cc[int(1e5)];
int cache[int(1e6)][int(5)];
int n;

int dp(int x,int last){
    int a1,b1,c1;

    if(cache[x][last]!=0){
        return cache[x][last];
    }

    if(x==0){
        if(last==1){
            return max(bb[x],cc[x]);
        }
        else if(last ==2){
            
            return max(aa[x],cc[x]);
        }
        else if(last==3){
            
            return max(bb[x],aa[x]);
        }
        else{
            return max(max(aa[x],bb[x]),cc[x]);
        }
    }
    else if(last==4){ 
    a1 = aa[x] + dp(x-1,1);
    b1 = bb[x] + dp(x-1,2);
    c1 = cc[x] + dp(x-1,3);
    return max(max(a1,b1),c1);
    }
    else if(last==3){
        a1 = aa[x] + dp(x-1,1);
        b1 = bb[x] + dp(x-1,2);
        return cache[x][3] = max(a1,b1);    
    }
    else if(last==2){
        a1 = aa[x] + dp(x-1,1);
        c1 = cc[x] + dp(x-1,3);
        return cache[x][2] = max(a1,c1);
    }
    else if(last==1)
        c1 = cc[x] + dp(x-1,3);
        b1 = bb[x] + dp(x-1,2);
        return cache[x][1] = max(c1,b1);
}

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

    cin >> n;
    for(i=0;i<n;i++){
        cin >> aa[i] >> bb[i] >>cc[i];
    } 

    cout << dp(n-1,4) << endl;

}

Measured memory_bytes: 10752
#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < (int)(n); i++)
#define rrep(ri,n) for(int ri = (int)(n-1); ri >= 0; ri--)
#define rep2(i,x,n) for(int i = (int)(x); i < (int)(n); i++)
#define rrep2(ri,x,n) for(int ri = (int)(n-1); ri >= (int)(x); ri--)
#define repit(itr,x) for(auto itr = x.begin(); itr != x.end(); itr++)
#define rrepit(ritr,x) for(auto ritr = x.rbegin(); ritr != x.rend(); ritr++)
#define ALL(x) x.begin(), x.end()
using ll = long long;
using namespace std;

int main(){
  int n, m, x, y;
  cin >> n >> m >> x >> y;
  int mx = -1000, mn = 1000;
  rep(i, n){
    int in;
    cin >> in;
    mx = max(mx, in);
  }
  rep(i, m){
    int in;
    cin >> in;
    mn = min(mn, in);
  }
  bool f = false;
  if(mx >= mn) f = true;
  if(mn <= x || y < mn) f = true;
  if(f == false) cout << "No ";
  cout << "War" << endl;

  return 0;
}

Measured memory_bytes: 3632
#include <cassert>
#include <algorithm>
#include <iostream>
#include <iomanip>
#include <limits.h>
#include <map>
#include <queue>
#include <string.h>
#include <vector>

using namespace std;
typedef long long ll;

struct Node {
  int i;
  int v;

  Node(int i = -1, int v = -1) {
    this->i = i;
    this->v = v;
  }

  bool operator>(const Node &n) const {
    return v < n.v;
  }
};

int main() {
  int N;
  vector<int> A;
  vector<int> B;
  priority_queue <Node, vector<Node>, greater<Node> > pque;

  cin >> N;

  int a, b;
  for (int i = 0; i < N; ++i) {
    cin >> a;
    A.push_back(a);
  }

  for (int i = 0; i < N; ++i) {
    cin >> b;
    B.push_back(b);

    pque.push(Node(i, b));
  }

  ll ans = 0;

  while (!pque.empty()) {
    Node node = pque.top();
    pque.pop();

    if (node.v == A[node.i]) continue;

    int left = (node.i - 1 + N) % N;
    int right = (node.i + 1) % N;

    int d = B[left] + B[right];
    int r = (node.v - A[node.i]) / d;

    if (r == 0) {
      cout << -1 << endl;
      return 0;
    }

    ans += r;

    int nv = node.v - r * d;
    B[node.i] = nv;
    pque.push(Node(node.i, nv));
  }

  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 3956
#include<bits/stdc++.h>
#define M 500000
#define MAX 10000000000000010
#define mod 1000000007
#define ss second
#define ff first
#define ll long long int
#define pb push_back
#define ld double
#define fast ios_base::sync_with_stdio(false);cin.tie(NULL)
using namespace std;

ll fr[10][10];
int main()
{
	int n;
	cin>>n;
	ll ans = 0;
	for(int i=1;i<=n;i++)
	{
		if(i%10)
		{
			int temp = i;
			while(temp>=10)
				temp/=10;
			fr[temp][i%10]++;
		}
	}
	for(int i=1;i<=9;i++)
	{
		for(int j=1;j<=9;j++)
		{
			ans += fr[i][j]*fr[j][i];
		}
	}
	cout<<ans<<endl;
	return 0;
}

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

#define M 1001041
//#define M 2032409
#define NIL '\0'
#define L 14

char H[M][L]; /* Hash Table */

int getChar(char ch){
  if ( ch == 'A') return 1;
  else if ( ch == 'C') return 2;
  else if ( ch == 'G') return 3;
  else if ( ch == 'T') return 4;
}

/* convert a string into an integer value */
long long getKey(char str[]){
  long long sum = 0, p = 1, i;
  for ( i = 0; i < strlen(str); i++ ){
    sum += p*(getChar(str[i]));
    p *= 5;
  }
  return sum;
}

int h1(int key){return key%M;}
int h2(int key){return key%(M-1);}

int find(char str[]){
  long long key = getKey(str);
  long long i=0, j;

  while(1)
    {
      j=(h1(key)+i*h2(key))%M;
      if(strcmp(str, H[j])==0)return j;
      i++;
      if(H[j][0]==NIL || i==M)return NIL;
    }
}

int insert(char str[]){
  long long key = getKey(str);
  long long i=0, j;

  while(1)
    {
      j=(h1(key)+i*h2(key))%M;
      if(H[j][0]==NIL)
	{
	  strcpy(H[j], str);
	  return j;
	}
      else i++;

      if(i==M)break;
    }
  return -1;
}

int main(){
    int i, n, h;
    char str[L], com[9];
    for ( i = 0; i < M; i++ ) H[i][0] = '\0';
    
    scanf("%d", &n);
    
    for ( i = 0; i < n; i++ ){
	scanf("%s %s", com, str);
	
	if ( com[0] == 'i' ){
	    insert(str);
	} else {
	    if (find(str)){
		printf("yes\n");
	    } else {
		printf("no\n");
	    }
	}
    }

    return 0;
}

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

int main() {
  int N, K, X, Y;
  cin >> N >> K >> X >> Y;
  
  int total = 0;

  if (N - K > 0) {
    total += K * X;
    total += (N - K) * Y;
    cout << total << endl;
  }
  else {
    total += N * X;
    cout << total << endl;
  }
}

Measured memory_bytes: 3556
import java.util.Arrays;
import java.util.Scanner;
 
public class Main {
 
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
         
        int[] p = new int[3];
        int[] j = new int[2];
        p[0] = sc.nextInt();
        p[1] = sc.nextInt();
        p[2] = sc.nextInt();
        j[0] = sc.nextInt();
        j[1] = sc.nextInt();
        Arrays.sort(p);
        Arrays.sort(j);
        System.out.println(p[0]+j[0]-50);
    }
}

Measured memory_bytes: 17320
#pragma warning(disable:4996)

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#define _USE_MATH_DEFINES
#include <math.h>
#include <float.h>

#pragma region 定義
typedef long long  ll;
typedef unsigned long long  ull;


#define _itoa(A,N) sprintf(A, "%d", N);

int i_dsort(const void* a, const void* b);
int i_asort(const void* a, const void* b);

int  _gcd(int a, int b);
int  _swp(int* a, int* b);
int _cknum(char* a, int n);
int _atoi(char* s, int len);

int s_asort(const void* a, const void* b);
int s_dsort(const void* a, const void* b);

//昇順
int s_asort(const void* a, const void* b) {
	return(strcmp((char*)a, (char*)b));
}
int s_dsort(const void* a, const void* b) {
	return(strcmp((char*)b, (char*)a));
}

int i_dsort(const void* a, const void* b) {
	return(*(int*)b - *(int*)a);
}
int i_asort(const void* a, const void* b) {
	return(*(int*)a - *(int*)b);
}


int i_gcd(int a, int b);
int i_gcd(int a, int b) {
	if (!b)return a;
	return i_gcd(b, a % b);
}
int i_lcm(int a, int b);
int i_lcm(int a, int b) {
	return (a * b) / i_gcd(a, b);
}
int ll_gcd(ll a, ll b);
int ll_gcd(ll a, ll b) {
	if (!b)return a;
	return ll_gcd(b, a % b);
}
int ll_lcm(ll a, ll b);
int ll_lcm(ll a, ll b) {
	return (a * b) / ll_gcd(a, b);
}

// puts("Yes\n") puts("No\n")
// scanf("%d.%d") 浮動小数点入力を整数２つで得る


//#define pai  3.1415926535 
//#define  _USE_MATH_DEFINES でM_PIが使える

#define deg_rad(X)  (X*(M_PI/180))


int _swp(int* a, int* b)
{
	int tmp;
	tmp = *b; *b = *a; *a = tmp;
	return 0;
}
#define _abs(x) ((x)>0?(x):-(x))
#define _min(x,y) ((x)<(y)?(x):(y))
#define _max(x,y) ((x)<(y)?(y):(x))

int _cknum(char* a, int n) {
	int i;
	char t = '0';

	for (i = 0; i < n; i++) {
		if (a[i] < '0' || a[i]>'9') return 1;
	}
	return 0;
}


int _atoi(char* s, int len) {
	char tmp[20];
	memcpy(tmp, s, len);
	tmp[len] = 0x00;
	return (atoi(tmp));
}

//素因数分解　pf素数が入る　pc 素数の数
//ll _pfact(ll a);
//static ll pf[100000000];
//static ll pc;
//
//ll _pfact(ll a) {
//	long i, r;
//	if (a % 2 == 0) {
//		pf[pc] = 2; pc++;
//		return(_pfact(a / 2));
//	}
//	r = sqrt(a);
//	for (i = 3; i <= r; i += 2) {
//		if (a % i == 0) {
//			pf[pc] = i; pc++;
//			return(_pfact(a / i));
//		}
//	}
//	if (a != 1) {
//		pf[pc] = a; pc++;
//	}
//	return 0;
//
//}

//同じものの最初の文字をNULLにして降順
int _sort(const void* a, const void* b);
int _sort(const void* a, const void* b) {
	char rc;

	rc = strcmp((char*)b, (char*)a);
	if (rc == 0) {
		*(char*)a = 0x00;
		return(1);
	}
	return(rc);
}
// 立っている ビットの数
int bitcount(unsigned int uc);
int bitcount(unsigned int uc)
{
	int bit;

	for (bit = 0; 0 != uc; uc = (unsigned int)(uc >> 1))
		if (0 != (uc & 1))++bit;

	return bit;
}//bitco

#define _rnd(a,b)    ((a+b-1)/b) //　A/Bの余りを繰り上げる

#pragma endregion

// ABC081 A- Placing Marbles
int main(void) {
	int  a,b,c;
	
	scanf("%01d%01d%01d",&a,&b,&c);
	printf("%d\n",a+b+c);

	return 0;
}

Measured memory_bytes: 1684
#include <algorithm>
#include <iostream>
#include <vector>
#include <queue>
#include <set>
#include <string>
#include <map>
#include <cmath>
#include <cstring>

#define fi first
#define se second
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define rrep(i,n) for (int i = 1; i < (n); ++i)
#define drep(i,n) for (int i = (n)-1; i >= 0; --i)
#define srep(i,s,t) for (int i = s; i < t; ++i)
#define all(x) (x).begin(), (x).end()
#define maxs(x,y) (x = max(x,y))
#define mins(x,y) (x = min(x,y))
#define pb push_back
#define sz(x) (int)(x).size()
#define PQ(T) priority_queue<T, v(T), greater<T> >

using namespace std;
typedef long long ll;
typedef unsigned uint;
typedef unsigned long long ull;
typedef pair<int,int> P;

const ll LINF = 1001002003004005006ll;
const int INF = 1001001001;

const int mod = 1000000007;

int main() {
    int M;
    cin >> M;
    vector<ll> d(M);
    vector<ll> c(M);
    rep(i,M) cin >> d[i] >> c[i];
    
    ll n = 0;
    ll s = 0;
    rep(i,M) {
        n += c[i];
        s += (d[i] * c[i]);
    }

    ll ans = (n-1) + (s-1) / 9;
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 3328
target_list = list(input().split())
_stack = []

def calc_by_reverse_polish_notation(target_list):
    for target_value in target_list:
        if target_value in ["+", "-", "*"]:
            num_1 = int(_stack.pop())
            num_2 = int(_stack.pop())
            if target_value == "+":
                _stack.append(num_1 + num_2)
            elif target_value == "-":
                _stack.append(num_2 - num_1)
            elif target_value == "*":
                _stack.append(num_1 * num_2)
        else:
            _stack.append(target_value)

calc_by_reverse_polish_notation(target_list)
print(_stack[0])


Measured memory_bytes: 5596
def solve(s):
  t = 'keyence'
  if t in s[0:7] or t in s[-7:]:
    return 'YES'

  p = 0
  for i in range(len(s)):
    if t[p] == s[i]:
      p = p + 1
    else:
      if t[p:] in s[-7+p:]:
        return 'YES'
      else:
        return 'NO'
  return 'NO'

print(solve(input()))

Measured memory_bytes: 3060
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<n;i++)
#define rrep(i,n) for(int i=1;i<=n;i++)
#define drep(i,n) for(int i=n;i>=0;i--)
#define MAX 5002
#define B 100
#define dpb push_back
#define fi first
#define se second
typedef pair<int, int> P;
typedef long long ll;
const int inf = 1e9;
const ll INF = 1e18;

int main(){
	string str;
	cin >> str;
	printf("2018");
	for(int i = 4;i < str.size();i++){
		cout << str[i];
	}
	
	//printf("%d\n", ans);
	return 0;
}





Measured memory_bytes: 256