akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
using ll = long long;

string S, T;

int main(){
  int N;
  cin >> N;
  vector<int> V(N);
  vector<int> C(N);
  vector<int> va(N);
  for(int i = 0; i<N; i++){
    cin >> V.at(i);
  }
  for(int i = 0; i<N; i++){
    cin >> C.at(i);
  }
  for(int i = 0; i<N; i++){
    va.at(i) = V.at(i) - C.at(i);
  }

  sort(va.rbegin(), va.rend());

  int ans = 0;

  for(int i = 0; i<N; i++){
    if(va.at(i) < 0){
      break;
    }
    ans += va.at(i);

  }

  cout << ans << endl;

}


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

int main() {
  int N,K,X,Y;
  cin >> N >> K >> X >> Y;
  
  if(N < K){
    cout << N * X << endl;
  }
  
  else{
    cout << (K * X) + (N - K) * Y << endl;
  }
}

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

using namespace std;
using uint = unsigned int;
using ll = long long;
using ull = unsigned long long;
constexpr ll TEN(int n) { return (n == 0) ? 1 : 10 * TEN(n - 1); }
template <class T> using V = vector<T>;
template <class T> using VV = V<V<T>>;

template <uint MD> struct ModInt {
    using M = ModInt;
    const static M G;
    uint v;
    ModInt(ll _v = 0) { set_v(_v % MD + MD); }
    M& set_v(uint _v) {
        v = (_v < MD) ? _v : _v - MD;
        return *this;
    }
    explicit operator bool() const { return v != 0; }
    M operator-() const { return M() - *this; }
    M operator+(const M& r) const { return M().set_v(v + r.v); }
    M operator-(const M& r) const { return M().set_v(v + MD - r.v); }
    M operator*(const M& r) const { return M().set_v(ull(v) * r.v % MD); }
    M operator/(const M& r) const { return *this * r.inv(); }
    M& operator+=(const M& r) { return *this = *this + r; }
    M& operator-=(const M& r) { return *this = *this - r; }
    M& operator*=(const M& r) { return *this = *this * r; }
    M& operator/=(const M& r) { return *this = *this / r; }
    M pow(ll n) const {
        M x = *this, r = 1;
        while (n) {
            if (n & 1) r *= x;
            x *= x;
            n >>= 1;
        }
        return r;
    }
    M inv() const { return pow(MD - 2); }
    friend ostream& operator<<(ostream& os, const M& r) { return os << r.v; }
};
using Mint = ModInt<TEN(9) + 7>;
// template<> const Mint Mint::G = Mint(3);

const int B = 4242424;
int n, k;
Mint dp[2333][2333];
bool used[2333][2333];
Mint fac[B], ifac[B];

void first() {
    fac[0] = 1;
    for (int i = 1; i < B; i++) fac[i] = Mint(i) * fac[i - 1];
    ifac[B - 1] = fac[B - 1].inv();
    for (int i = B - 2; i >= 0; i--) ifac[i] = Mint(i + 1) * ifac[i + 1];
}

Mint C(int n, int k) {
    if (n < 0 || k < 0 || n < k) return Mint(0);
    return fac[n] * ifac[k] * ifac[n - k];
}

Mint calc(int a, int b) {
    if (a > n || b > n || a < b) return Mint(0);
    if (used[a][b]) return dp[a][b];
    used[a][b] = true;
    return dp[a][b] = 
        calc(a + 1, b) + calc(a, b + 1) * C(n * k - a - b * (k - 1) - 1, k - 2);
}

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

    cin >> n >> k;
    if (k == 1) {
        cout << 1 << endl;
        return 0;
    }
    first();
    used[n][n] = true;
    dp[n][n] = 1;
    cout << calc(0, 0) * fac[n] << endl;
    return 0;
}

Measured memory_bytes: 60288
#include <iostream>
#include <iomanip>
#include <vector>
#include <utility>
#include <string>
#include <algorithm>
#include <numeric>
#include <cmath>
#include <string.h>
#include <deque>
#define REP(i,j,n) for(int i=j;i<n;i++)
#define SORT(x) sort(x.begin(),x.end())

using namespace std;

int main() {
	int n, count = 0;
	bool flag = true;
	cin >> n;
	vector<int> v(n);
	for (int i = 0; i < n; i++) cin >> v[i];
	while (flag) {
		flag = false;
		for (int i = n - 1; i > 0; i--) {

			if (v[i - 1] > v[i]) {
				int swap;
				swap = v[i - 1];
				v[i - 1] = v[i];
				v[i] = swap;
				count++;
				flag = true;
			}
		}
	}
	for (int i = 0; i < n; i++) {
		if (i != n - 1)cout << v[i] << " ";
		else cout << v[i] << endl;
	}
	cout << count << endl;
	return 0;
}

Measured memory_bytes: 3080
/* ex4_3
   moka223711 */

#include <stdio.h>

int snow(int h_west, int h_east); // 積雪量を求める関数のプロトタイプ宣言

int main(void){    
    // 高さがn(n+1)/2[m](n=1,2,…,999)の999本の塔が西から順に立っている
    // 雪に埋もれていない塔の高さから雪が何m積もっているか求める
    // 雪に埋もれていない西側の塔の高さをh_west、東側の塔の高さをh_eastとする
    
    int h_west, h_east;
    scanf("%d %d", &h_west, &h_east);
    
    // 積雪量を求める関数snow()から返り値を受け取って出力
    printf("%d\n", snow(h_west, h_east));
    
    return 0;
}

    // 積雪量を求める関数の定義
int snow(int h_west, int h_east){
    int dif, ans;
    
    // 東側の塔の高さから西側の塔の高さを引き、差difを求める
    dif = h_east - h_west;
    // ここでdifは東側の塔がdif番目の塔であることを表す
    
    // 差difから東側の塔の高さを求めて、雪に埋もれていない塔の高さを引くことで
    // 雪が何m積もっているかを求める
    ans = dif * (dif + 1) / 2 - h_east;
    
    // ansを返り値として返す
    return ans;
}


Measured memory_bytes: 128
#include <cstdio>
#include <cstdlib>
#include <iostream>
#include <queue>

using namespace std;

int main(void){
	char Sa[101], Sb[101], Sc[101];
	queue<char> Qa, Qb, Qc;

	scanf("%s %s %s", Sa, Sb, Sc);
	for (int i = 0; Sa[i] != '\0'; i++){
		Qa.push(Sa[i]);
	}
	for (int i = 0; Sb[i] != '\0'; i++){
		Qb.push(Sb[i]);
	}
	for (int i = 0; Sc[i] != '\0'; i++){
		Qc.push(Sc[i]);
	}

	char ch = Qa.front();
	Qa.pop();
	while (1){
		if (ch == 'a'){
			if (Qa.empty()) {
				printf("A\n"); 
				return 0;
			}
			ch = Qa.front();
			Qa.pop();
		}
		else if (ch == 'b'){
			if (Qb.empty()) {
				printf("B\n");
				return 0;
			}
			ch = Qb.front();
			Qb.pop();
		}
		else if (ch == 'c'){
			if (Qc.empty()) { 
				printf("C\n"); 
				return 0;
			}
			ch = Qc.front();
			Qc.pop();
		}
	}

	return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
#include<string.h>
#include <iostream>
#include <algorithm>
#define N 1e-5
#define ll long long
using namespace std;
int a[100005];
int main()
{
    long long n;
    scanf("%lld",&n);
    for(int i=1; i<=n; i++)
    {
        scanf("%d",&a[i]);
    }
    int ans=0;
    for(int i=1; i<=n; i++)
    {
        if(i==a[i])
        {
            swap(a[i],a[i+1]);
            ans++;
        }
    }
        printf("%d\n",ans);
        return 0;
}


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

int main()
{
    string ans;
    int a, b;
    cin >> a >> b;
    if(a==b){
        ans = "Draw";
    }else if(a==1){
        ans = "Alice";
    }else if(b==1){
        ans = "Bob";
    }else if(a>b){
        ans = "Alice";
    }else{
        ans = "Bob";
    }
    cout << ans << "\n";

    return 0;
}


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

using str = string;
using ss = stringstream;

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

    int d,n;
    cin>>d>>n;

    ss s;

    if(n==100)s<<101;
    else s<<n;
    
    for(int i=0;i<d;i++)s<<"00";

    cout<<s.str()<<"\n";

    return 0;
}


Measured memory_bytes: 3620
#include <bits/stdc++.h>
using namespace std;
#define MOD 1000000007
typedef long long ll;
typedef pair<int, int> P;

unsigned GetDigit(unsigned num){
    return log10(num)+1;
}

int main(){
    int n;
    cin >> n;
    int keta = GetDigit(n);
    int count[10][10];
    for(int i = 0; i < 10; i++){
        for(int j = 0; j < 10; j++){
            count[i][j] = 0;
        }
    }
    for(int i = 1; i <= n; i++){
        int keta = GetDigit(i);
        if(keta == 1){
            count[i][i]++;
        }
        else{
            int first = i % 10;
            int waru = (int)pow(10,keta-1);
            int last = i / waru;
            count[last][first]++;
        }
    }
    int ans = 0;
    for(int i = 0; i < 10; i++){
        for(int j = 0; j < 10; j++){
            ans += count[i][j] * count[j][i];
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
#include <iostream>
#define rep(i,n) for (int i = 0; i < (n); ++i)
using namespace std;
using ll = long long;
using P = pair<int,int>;
 
int main() {
  string s;
  cin >> s;
  rep(i,s.size()) {
    s[i] = 'x';
  }
  cout << s << endl;
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); i++)
using namespace std;
int main()
{
  int N;
  cin >> N;
  vector<int> A(N);
  rep(i, N)
  {
    cin >> A[i];
  }
  vector<int> ans(N);
  rep(i, N)
  {
    ans[A[i] - 1] = i + 1;
  }
  rep(i, N)
  {
    cout << ans[i] << endl;
  }
  return 0;
}

Measured memory_bytes: 1536
#include "bits/stdc++.h"
#define ALL(x) x.begin(), x.end()
#define LEN(x) (int)x.size()
#define iostreamBooster() do{ cin.tie(nullptr); ios_base::sync_with_stdio(false); }while(0)
using namespace std;
typedef int64_t i64;
typedef pair<int,int> pii;
template<class A, class B>inline bool chmax(A &a, const B &b){return b>a ? a=b,1 : 0;}
template<class A, class B>inline bool chmin(A &a, const B &b){return b<a ? a=b,1 : 0;}
constexpr int INF = 0x3f3f3f3f;

signed main()
{
  i64 a[100];
  int N;
  cin >> N;
  a[0] = 2;
  a[1] = 1;
  for (int i = 2; i <= N; ++i) {
    a[i] = a[i-1] + a[i-2];
  }

  cout << a[N] << endl;

  return 0;
}



Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <map>
#include <list>
#include <utility>
#include <tuple>
#include <cstdio>
#include <set>
#include <queue>
#include <stack>
#include <deque>
#include <unordered_map>
#include <unordered_set>
#include <bitset>
#include <cctype>
#include <cmath>
#define _GLIBCXX_DEBUG
using namespace std;
const long long INF = 1LL << 60;
typedef long long ll;
int main() {
    string S;
    cin >> S;
    int size = S.size();
    if(S[0]!='A'){
        cout << "WA" << endl;
    }
    else{
        int cnt=0;
        int num;
        bool frg = true;
        for(int i=2;i<size-1;i++){
            if(S[i]=='C'){
                cnt++;
                num= i;
            }
        }
        if(cnt!= 1){
                    cout << "WA" << endl;
                    frg = false;
                }
        if(frg){
            for(int i=1;i<size;i++){
                if(i!=num){
                    if(('a'> S[i])||(S[i] > 'z')){
                        cout<< "WA" << endl;
                        break;
                    }
                }
                if(i==size-1){
                    cout << "AC" << endl;
                }
            }
        }
        
    }
}

Measured memory_bytes: 3620
#include <stdio.h>
#include <stdlib.h>
#define M 10000000
#define I 100000000

typedef struct{
    int next;
    int now;
    int weight;
}node;

int n,d[M];
node A[M];

void bfs(int s){
    int i;
    int flag = 0;

    d[0]=0;
    while(flag!=1){
        flag=1;
        for(i=0;i<s;i++){
            if(A[i].weight+d[A[i].now]<d[A[i].next]){
                d[A[i].next]=A[i].weight+d[A[i].now];
                flag=0;
            }
        }
    }
}

int main(){
    int i,j;
    int s,t,c=0;

    scanf("%d",&n);
    for(i=0;i<n;i++){
        d[i]=I;
        scanf("%d%d",&s,&t);
        for(j=0;j<t;j++){
            A[c].now=s;
            scanf("%d%d",&A[c].next,&A[c].weight);
            c++;
        }
    }
    bfs(c);

    for(i=0;i<n;i++){
        printf("%d %d\n",i,d[i]);
    }
    return 0;
}



Measured memory_bytes: 7592
INF = int(2e5)
def solve():
    n = int(input())
    B = [INF] * 2 + list(map(int, input().split())) + [INF] * 2
    ans = 0
    for i in range(2, n + 2):
        ans += min(B[i - 1], B[i])
    print(ans)
solve()


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

int main()
{
	char x;
	cin>>x;
	switch (x)
	{
	case 'a':
	case 'e':
	case 'i':
	case 'o':
	case 'u':
		cout<<"vowel \n";
		break;
	default :
		cout<<"consonant \n";
	}
return 0;
}

Measured memory_bytes: 256
/** 
 * Dont raise your voice, improve your argument.
 * --Desmond Tutu
 */

#include <bits/stdc++.h>
using namespace std;
typedef unsigned int uint;
typedef long long ll;

#define fori(n) for(ll i=0; i<(n); i++)
#define forn(i, n) for(ll i=0; i<(n); i++)
#define forn3(i, x, n) for(ll i=(x); i<(n); i++)

int main() {
    int n, m;
    cin>>n>>m;
    vector<vector<int>> tree(n+1);
    fori(m) {
        int x, y;
        cin>>x>>y;
        tree[x].push_back(y);
    }

    vector<int> len(n+1);
    function<void(int)> dfs=[&](int v) {
        if(len[v]>0)
            return len[v];

        int ret=1;
        for(auto c : tree[v]) {
            dfs(c);
            ret=max(ret, 1+len[c]);
        }
        len[v]=ret;
    };

    int ans=0; /* number of vertex */
    for(int i=1; i<=n; i++)  {
        dfs(i);
        ans=max(ans, len[i]);
    }

    cout<<ans-1<<endl; /* number of edges */
    return 0;
}



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

int main()
{
    ios_base :: sync_with_stdio(false);
    cin.tie(NULL), cout.tie(NULL);
    ll n, i;
    cin >> n;
    vll a(n);
    for(i = 0; i < n; i++)
        cin >> a[i];
    sort(all(a));
    cout << a[n / 2] - a[n / 2 - 1] << endl;
    return 0;
}

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

using namespace std;

#define sim template <class c
#define ris return *this
#define dor > debug &operator<<
#define eni(x)                                                                        \
	sim > typename enable_if<sizeof dud<c>(0) x 1, debug &>::type operator<<(c i) \
	{
sim > struct rge
{
	c b, e;
};
sim > rge<c> range(c i, c j) { return rge<c>{i, j}; }
sim > auto dud(c *x) -> decltype(cerr << *x, 0);
sim > char dud(...);
struct debug
{
#ifdef LOCAL
	~debug()
	{
		cerr << endl;
	}
	eni(!=) cerr << boolalpha << i;
	ris;
} eni(==) ris << range(begin(i), end(i));
}
sim, class b dor(pair<b, c> d)
{
	ris << "(" << d.first << ", " << d.second << ")";
}
sim dor(rge<c> d)
{
	*this << "[";
	for (auto it = d.b; it != d.e; ++it)
		*this << ", " + 2 * (it == d.b) << *it;
	ris << "]";
}
#else
	sim dor(const c &)
	{
		ris;
	}
#endif
}
;
#define imie(...) " [" << #__VA_ARGS__ ": " << (__VA_ARGS__) << "] "

#define forn(i, n) for (int i = 0; i < int(n); i++)
#define rfor(n, i) for (ll i = (n - 1); i >= 0; --i)
#define all(V) V.begin(), V.end()
#define rall(V) V.rbegin(), V.rend()
#define len(V) (int)V.size()
#define ll long long
#define ld long double
#define ff first
#define ss second
#define pb push_back
#define mp make_pair
#define endl '\n'
#define M_PI 3.14159265358979323846
#define EPS 1e-7

void solve()
{
        string s; cin >> s;
        int n = s.length();
        ll cnt = 0, c = 0;
        string s1 = "";
        for (int i = 0; i < s.length(); ++i)
        {
                if (i % 2 == 0) s1 += "0";
                else s1 += "1";
        }
        string s2 = "";
        for (int i = 0; i < s.length(); ++i)
        {
                if (i % 2 == 0)
                        s2 += "1";
                else
                        s2 += "0";
        }
        for (int i = 0; i < n; ++i)
        {
                if (s[i] != s1[i]) cnt++;
        }
        for (int i = 0; i < n; ++i)
        {
                if (s[i] != s2[i])
                        c++;
        }

        cout << min(cnt, c);
}

int main()
{
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
	solve();
}


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

/* 
 * g++ -std=c++17 A.cpp -o A
 */
int main() {
  ios_base::sync_with_stdio(false);
  int N, W;
  int w, v;
  cin>>N>>W;
  vector<vector<int>> items(N+1);
  for (int i = 1; i <= N; i++) {
    cin>>w>>v;
    items[i].push_back(w);
    items[i].push_back(v);
  }
  long long dp[W+1][N+1];
  for (int w = 0; w < W+1; w++) {
    for (int i = 0; i < N+1; i++) {
      if (i == 0 || w == 0) {
        dp[w][i] = 0;
      } else if (w >= items[i][0]) {
        // can't overweight so we have this ^ condition
        // we choose the max of choosing the item at i
        // or not choosing the item at i
        dp[w][i] = max(items[i][1] + dp[w-items[i][0]][i-1], dp[w][i-1]);
      } else {
        dp[w][i] = dp[w][i-1];
      }
    }
  }
  cout << dp[W][N];
  cout << endl;
}


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

#define rep(i, a, b) for (int i = (a); i < (int)(b); i++)
#define rrep(i, a, b) for (int i = (a); i >= (int)(b); i--)
#define all(x) (x).begin(), (x).end()
using i32 = int32_t;
using i64 = int64_t;
using f32 = float;
using f64 = double;
using P = pair<int, int>;

template <class T>
bool chmin(T& a, T b) {
    if (a > b) {
        a = b;
        return true;
    } else {
        return false;
    }
}
template <class T>
bool chmax(T& a, T b) {
    if (a < b) {
        a = b;
        return true;
    } else {
        return false;
    }
}

template <class T>
void dump_vec(const vector<T>& v) {
    auto len = v.size();
    rep(i, 0, len) {
        cout << v[i] << (i == (int)len - 1 ? "\n" : " ");
    }
}

struct FastIO {
    FastIO() {
        cin.tie(0);
        ios::sync_with_stdio(false);
        cout << fixed << setprecision(20);
    }
} FASTIO;

//---------------------------------------------------------------------------------------------------

//---------------------------------------------------------------------------------------------------

signed main() {
    int N;
    cin >> N;

    int tot = 0;
    rep(i, 1, N + 1) rep(j, 1, N + 1) rep(k, 1, N + 1) {
        auto a = gcd(i, j);
        tot += gcd(a, k);
    }
    cout << tot << "\n";
}


Measured memory_bytes: 3656
#include <iostream>
using namespace std;
long long int factorial(long long int f){
    const unsigned int M = 1000000007; 
    long long int t=1;
    if(f>0){
      for(long long int  i=1;i<=f;i++){
        t=(t*i)%M;
      }
      return t;
    }
    else if(f==0){
        return 1;
    }
}
long long int power(long long int x,long long int y){
    const unsigned int M=1000000007;
    long long int res=1;
    while(y>0){
        if(y&1){
            res=(res*x)%M;
        }
        y=y>>1;
        x=(x*x)%M;
        
        
    }
    return res;
}
long long int modinv(int n){
    const unsigned int M=1000000007;
    return power(n,M-2);
}
long long int binomial(long long int n,long long int m){
    const unsigned int M = 1000000007; 
    long long int j=m+n;
    long long int b=(factorial(j)*(modinv(factorial(n)))%M*(modinv(factorial(m)))%M)%M;
    return b;
}

int main(){
	// your code goes here
	long long int x,y;
    const unsigned int M = 1000000007; 

	cin>>x>>y;
	if((x+y)%3!=0){
        cout<<0<<endl;
    }
    else {
        long long int m=((x*2)-y)/3;
        long long int  n=((y*2)-x)/3;
        if(n<0||m<0){
            cout<<0%M<<endl;
        }
        else if(n==0&&m==0){
            cout<<0<<endl;
        }
        else{
            cout<<binomial(n,m)<<endl;
        }
    }
	
	
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#include<iostream>
#include<vector>
#include <cmath>
#include <map>
#include <algorithm>
#include <string>
#define rep(i, n) for (int i = 0; i < n; ++i)
using ll = long long;
using namespace std;
#define P pair<int, int>
unsigned GetDigit(unsigned num){
    unsigned digit=0;
    while(num!=0){
        num /= 10;
        digit++;
    }
    return digit;
}

int main () {
    ll N ;
    cin >> N ;
    
    
    ll ans  = 1 ;
    for(ll i = 1 ; i * i <= N  ; i++){
          if(N % i == 0 && ans < i){
                ans = i ;
          }
    }

    ll a , b ;
    a = GetDigit(ans) ;
    b = GetDigit(N / ans) ;
    cout << max(a , b ) << endl;


    return 0 ;
}

 


Measured memory_bytes: 256
while True:
  a, op, b = map(str, input().split())
  a = int(a)
  b = int(b)
  if op == "+":
    print(a + b)
  elif op == "-":
    print(a - b)
  elif op == "*":
    print(a * b)
  elif op == "/":
    print(a // b)
  elif op == "?":
    break


Measured memory_bytes: 5596
N = int(input())
h = list(map(int,input().split()))
cost = [float('inf')]*N

cost[0] = 0
for i in range(N-1): 
  num = cost[i] + abs(h[i+1]-h[i])
  if cost[i+1] > num:
    cost[i+1] = num
  if i > 0:
    num2 = cost[i-1] + abs(h[i+1]-h[i-1])
    if cost[i+1] > num2:
      cost[i+1] =  num2
      
print(cost[N-1])

Measured memory_bytes: 13928
import java.util.*;
public class Main{
  public static void main(String[] args) {
		Scanner sc=new Scanner(System.in);
		StringBuilder str=new StringBuilder(sc.next());
		String s=str.toString();
		if(str.toString().equals("keyence")) {
			System.out.println("YES");
			return;
		}
		for(int i=0;i<str.length();i++) {
			for(int j=0;j<str.length()-i;j++) {
				if(str.delete(i,i+j+1).toString().equals("keyence")) {
					System.out.println("YES");
					return;
				}
				str=new StringBuilder(s);
			}
		}
		System.out.println("NO");

	}
}

Measured memory_bytes: 23636
#include<bits/stdc++.h>
using namespace std;
#define ALL(x) begin(x),end(x)
typedef long long ll;
int OO = 0x3f3f3f3f;

int n;
double arr[3003];
double mem[3003][3003];

double solve(int x, int t)
{
    double op1, op2;
    if(x == n)
        return 1;

    if(mem[x][t] != -1)
        return mem[x][t];

    op1 = solve(x+1, t)*arr[x];
    op2 = 0;
    if(t+1 <= (n/2))
        op2 = solve(x+1, t+1)*(1-arr[x]);

    return mem[x][t] = op1 + op2;
}

int main()
{
    cin >> n;
    for(int i = 0; i< 3003;i++)
    {
        for(int j = 0; j < 3003; j++)
        {
            mem[i][j] = -1;
        }
    }
    for(int i = 0; i< n; i++)
    {
        cin >> arr[i];
    }
    cout <<fixed << std::setprecision(10) <<solve(0, 0) << endl;
    return 0;
}


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

#define rep(i, n) for (int i = 0; i < int(n); i++)
#define rrep(i, n) for (int i = int(n) - 1; i >= 0; i--)
#define reps(i, n) for (int i = 1; i <= int(n); i++)
#define rreps(i, n) for (int i = int(n); i >= 1; i--)
#define repc(i, n) for (int i = 0; i <= int(n); i++)
#define rrepc(i, n) for (int i = int(n); i >= 0; i--)
#define repi(i, a, b) for (int i = int(a); i < int(b); i++)
#define repic(i, a, b) for (int i = int(a); i <= int(b); i++)
#define each(x, y) for (auto &x : y)
#define all(a) (a).begin(), (a).end()
#define bit32(x) (1 << (x))
#define bit64(x) (1ll << (x))
#define sz(v) ((int) v.size())

using namespace std;

using i64 = long long;
using f80 = long double;
using vi32 = vector<int>;
using vi64 = vector<i64>;
using vf80 = vector<f80>;
using vstr = vector<string>;

inline void yes() { cout << "Yes" << endl; exit(0); }
inline void no() { cout << "No" << endl; exit(0); }
inline i64 gcd(i64 a, i64 b) { if (min(a, b) == 0) return max(a, b); if (a % b == 0) return b; return gcd(b, a % b); }
inline i64 lcm(i64 a, i64 b) { if (min(a, b) == 0) return max(a, b); return a / gcd(a, b) * b; }
template <typename T> class pqasc : public priority_queue<T, vector<T>, greater<T>> {};
template <typename T> class pqdesc : public priority_queue<T, vector<T>, less<T>> {};
template <typename T> inline void amax(T &x, T y) { x = max(x, y); }
template <typename T> inline void amin(T &x, T y) { x = min(x, y); }
template <typename T> inline T exp(T x, i64 n, T e = 1) { T r = e; while (n > 0) { if (n & 1) r *= x; x *= x; n >>= 1; } return r; }
template <typename T> istream& operator>>(istream &is, vector<T> &v) { each(x, v) is >> x; return is; }
template <typename T> ostream& operator<<(ostream &os, vector<T> &v) { rep(i, v.size()) { if (i) os << ' '; os << v[i]; } return os; }
void solve(); int main() { ios::sync_with_stdio(0); cin.tie(0); cout << fixed << setprecision(16); solve(); return 0; }

void solve() {
  int n;
  cin >> n;
  string s;
  cin >> s;
  int ans = 0;
  reps(i, n - 1) {
    string l = s.substr(0, i);
    string r = s.substr(i);
    set<char> sl, sr;
    rep(i, sz(l)) sl.insert(l[i]);
    rep(i, sz(r)) sr.insert(r[i]);
    int sum = 0;
    each(s, sl) {
      if (sr.count(s)) sum += 1;
    }
    amax(ans, sum);
  }
  cout << ans << endl;
}

Measured memory_bytes: 256
#define _USE_MATH_DEFINES
#include <bits/stdc++.h>
using namespace std;
const int mod = 1e9 + 7, A = 0, C = 1, G = 2;
signed main() {
  ios::sync_with_stdio(false); cin.tie(0);
  int n;
  cin >> n;
  int dp[4][4][4] = {};
  dp[3][3][3] = 1;
  for (int it = 0; it < n; it++) {
    int nxt[4][4][4] = {};
    for (int cur = 0; cur < 4; cur++) {
      for (int i = 0; i < 4; i++) {
        for (int j = 0; j < 4; j++) {
          for (int k = 0; k < 4; k++) {
            if (cur == C && i == G && j == A) continue;
            if (cur == C && i == A && j == G) continue;
            if (cur == G && i == C && j == A) continue;
            if (cur == C && i == G && k == A) continue;
            if (cur == C && j == G && k == A) continue;
            nxt[cur][i][j] += dp[i][j][k];
            nxt[cur][i][j] %= mod;
          }
        }
      }
    }
    swap(dp, nxt);
  }
  int ans = 0;
  for (int i = 0; i < 4; i++) {
    for (int j = 0; j < 4; j++) {
      for (int k = 0; k < 4; k++) {
        ans = (ans + dp[i][j][k]) % mod;
      }
    }
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 256
n = int(input())
h = list(map(int, input().split()))
total = 0
max_total = 0

for i in range(n-1):
    if h[i] >= h[i+1]:
        total += 1
        max_total = max(max_total, total)
    else:
        total = 0

print(max_total)

Measured memory_bytes: 14224
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
typedef long long ll;
int main() {
  int n; cin>>n;
  n=n%10;
  if(n==3) cout << "bon";
  else if(n==0||n==1||n==6||n==8) cout << "pon";
  else cout << "hon";
}

Measured memory_bytes: 3636
import math
import itertools

N = int(input())
XY = [list(map(int, input().split())) for _ in range(N)]


def distance(a, b):
    return math.sqrt((a[0] - b[0]) ** 2 + (a[1] - b[1]) ** 2)


d = [[0 for _ in range(N)] for _ in range(N)]

for i in range(N):
    for j in range(N):
        d[i][j] = distance(XY[i], XY[j])

res = 0
for n in list(itertools.permutations(range(N))):
    for i in range(len(n) - 1):
        res += d[n[i]][n[i + 1]]

print(res / math.factorial(N))


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

int main() {
  int N, K;
  cin >> N >> K;
  double ans = 0;
  for(int i = 1; i <= N; i++) {
    double res = 1.0 / N;
    int atai = i;
    while(atai < K) {
      atai *= 2;
      res *= 0.5;
    }
    ans += res;
  }
  cout << fixed << setprecision(12);
 
  cout << ans << endl;
}

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

int countAB(string S){
  int c=0;
  for(int i=0; i<S.size()-1; i++){
    if('A'==S[i] && 'B'==S[i+1]){c++;}
  }
  return c;
}

int main(){
  int N; cin >> N;
  string s; int a,b,c,sum; a=b=c=sum=0;
  for(int i=0; i<N; i++){
    cin >> s; sum = sum + countAB(s);
    if('A'==s[s.size()-1] && 'B'==s[0]){c++;}
    else if('A'==s[s.size()-1]){a++;}
    else if('B'==s[0]){b++;}
  }
  
  if(c==0){cout << sum + min(a,b);}
  else{cout << sum + c-1 + min(a,1) + min(b,1) + min(a-min(a,1),b-min(b,1));}
  
  return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <set>
#include <algorithm>
#include <cctype>
#include <cmath>
#include <queue>
#include <map>
#include <numeric>
#include <unordered_map>
#include <iomanip>
#include <functional>
#include <bitset>
#include <complex>

#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define repi(i,a,b) for(int i=int(a);i<int(b);i++)
#define all(x) (x).begin(),(x).end()

template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }

typedef long long ll;

using namespace std;


int main()
{
  ios::sync_with_stdio(false);
  cin.tie(0);
  int a,b;cin>>a>>b;
  if(a<9&&b<9)cout<<"Yay!"<<endl;
  else cout<<":("<<endl;

  return 0;

}


Measured memory_bytes: 256
N, T = map(int, input().split())
t = list(map(int, input().split()))
def solve():
  count = T
  for i in range(1, len(t)):
    d=t[i] - t[i-1]
    if d<T:
      count-=(T-d)
    count+=T
  return count
  
print(solve())

Measured memory_bytes: 26708
import scala.io.StdIn._
import scala.math._

/**
 * ABC107B
 */
object Main extends App {

  val Seq(h, w) = readLine().split(" ").toSeq.map(_.toInt)
  val blob: Seq[String] = (0 until h).map(_ => readLine()).toIndexedSeq

  val calcNewRow = (b: String) => {
    (0 until w)
      .filter(colNum => blob.map(_(colNum).toString).contains("#"))
      .map(v => b(v))
      .mkString("")
  }

  val ans = blob.filter(v => v.contains("#"))
    .map(calcNewRow(_))

  ans.foreach(println)

}


Measured memory_bytes: 49900
#include<iostream>
#include <algorithm>
#include <string>
using namespace std;
#include <bits/stdc++.h>
#define rep(i,n) for (int i=0; i<(int)(n); i++)
typedef long long ll;
const int INF = numeric_limits<int>::max();
const int MOD = (1e9 + 7);

int main(){
  int N;
  cin >> N;
  double a, sum=0;
  double C[N];
  rep(i, N){
    cin >> a;
    C[i] = 1/a;
  }
  rep(i, N){
    sum += C[i];
  }
  cout << (double)1/sum << endl;
    
 
}

Measured memory_bytes: 256
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>
#define FOR(i,n,a) for(int i = a;i<n;i++)
#define rep(i,n) FOR(i,n,0)
#define UNFOR(i,n,a) for(int i = a;i>n;i--)
#define unrep(i,n) UNFOR(i,0.n)
typedef long long ll;
using namespace std;
string s;
int N,M,H,W;

int main() {
	int X;
	cin >> X;
	int ans = 1;
	FOR(i,40,2) {
		FOR(j,50,2) {
			int num = i;
			rep(k, j) {
				num = num*i;
				if (num > X) {
					break;
				}
				ans = max(ans, num);
			}
			if (num > X)break;
		}
	}
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 256
n = int(input())
st = input()
di = {}
for i in range(len(st)):
    if st[i] in di:
        di[st[i]] = di.get(st[i]) + 1
    else:
        di[st[i]] = 2
from functools import reduce
print((reduce(lambda x,y:x*y,di.values())-1)%1000000007)

Measured memory_bytes: 3700
import java.util.Scanner;
public class Main{
	public static void main(String[] args){
		Scanner scan = new Scanner(System.in);
		//文字列を入力
		String inputChar = scan.nextLine();
		for(int i = 0 ;i < inputChar.length() ;i++ ){
			//文字列のi番目の１文字を格納
			Character oneChar = inputChar.charAt(i);
			//isUpperCaseメソッドの引数がString型のためString型に変換
			String strOneChar = String.valueOf(oneChar);
			//大文字か判別
			//trueなら小文字で出力 falseなら大文字で出力
			if(Character.isUpperCase(oneChar)){
				System.out.print(strOneChar.toLowerCase());
			}else if(Character.isLowerCase(oneChar)){
				System.out.print(strOneChar.toUpperCase());
			}else{
				System.out.print(strOneChar);
			}
		}
		System.out.println("");
	scan.close();
	}
}



Measured memory_bytes: 27056
#include<bits/stdc++.h>
#include<iostream>
#include<cmath>
#include<vector>
#include<string>
#include<queue>
#include<set>
#include<map>
#include<algorithm>
#include<functional>

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> pii;
typedef pair<ll, ll> pll;
typedef pair<ull, ull> pullull;
typedef pair<ll, int> plli;
typedef pair<int, pii> pipii;
typedef vector<vector<int> > mati;
typedef vector<vector<double> > matd;

#define rep(i,x,y) for(int i=(x); i<(y); ++i)
const int INF = (1<<30);
const ll INFLL = 1LL<<62;
const long double EPS = 1e-12;

template <typename T>
void vec_print(vector<T> VEC){
  rep(i, 0, VEC.size()){
    cout << VEC[i] << " ";
  }
  cout << "\n";
};

template <typename T>
void mat_print(vector<vector<T> > MAT){
  rep(i, 0, MAT.size()){
    rep(j, 0, MAT[i].size()){
      cout << MAT[i][j] << " ";
    }
    cout << "\n";
  }
};

class HOGE{
  public:
    ll index;
    ll value;
    HOGE(ll index, ll value){
      this->index = index;
      this->value = value;
    };
    ~HOGE(void){
      return;
    };

    void print(void){
      cout << "index : " << index << ", value : " << value << "\n";
      return;
    };
    
    bool operator==(const HOGE &obj){
      return (this->value == obj.value);
    };
    bool operator<(const HOGE &obj){
      return (this->value < obj.value);
    };
    bool operator>(const HOGE &obj){
      return (this->value > obj.value);
    };
};

int main(){
  cin.tie(0); // cut the cin and cout (default, std::flush is performed after std::cin)
  ios::sync_with_stdio(false); // cut the iostream and stdio (DON'T endl; BUT "\n";)

  ll N, K;
  cin >> N >> K;
  ll pos=0;
  rep(i, 0, N){
    ll tmp;
    cin >> tmp;
  }

  ll ans;
  ans = (N-1)/(K-1);
  if((N-1)%(K-1)!=0) ans++;


  cout << ans << "\n";

  return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
int main()
{
  int i,j,alp[26]={0};
  char s,a='a';
  while(scanf("%c",&s)!=EOF){
    if(s>='A' && s<='Z')s+=32;
    for(i=0;i<26;i++){
      if(s==a)alp[i]++;
      a++;
    }
    a='a';
  }
  for(j=0;j<26;j++){
    printf("%c : %d\n",a,alp[j]);
    a++;
  }
  return 0;
}

Measured memory_bytes: 968
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <tuple>
#include <utility>
#include <set>
#include <numeric>
#include <queue>
#include <sstream>
#include <map>
#include <unordered_map>
#include <cmath>
using namespace std;
using LLI = long long int;

#define Rep(i, N) for (int i = 0; i < N; i++)

int main(int argc, char *argv[])
{
    int N, A, B;

    cin >> N;

    if (N == 1) {
        cout << "Hello World" << endl;
    } else {
        cin >> A >> B;
        cout << A + B << endl;
    }

    return 0;
}

Measured memory_bytes: 256
#include<map>
#include<cmath>
#include<stack>
#include<cstdio>
#include<queue>
#include<vector>
#include<cstring>
#include<iostream>
#include<algorithm>
using namespace std;
typedef long long ll;
char a,b,c;
int main(){
	scanf("%c%c%c",&a,&b,&c);
	if(a==c)puts("Yes");
	else puts("No");
	return 0;
}

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

int main(){
	int n,m;
	cin >> n >> m;
	vector<int> l(m);
	vector<int> r(m);
	rep(i,m) cin >> l[i] >> r[i];
	int mx = 0;
	int mn = 10000000;
	rep(i,m){
		mx = max(l[i],mx);
		mn = min(r[i],mn);
	}
	if(mn - mx < 0) cout << 0 << endl;
	else cout << mn - mx + 1 << endl;
}

Measured memory_bytes: 3968
#include <iostream>
#include <vector>
#include <string>
#include <utility>
#include <algorithm>
#include <climits>
#include <map>
#include <queue>
#include <cmath>

using namespace std;

using int64 = long long;


int main() {
    int64 n,m;
    cin >> n >> m;
    int64 ans = min(n, m/2);
    m -= ans*2;
    ans += m/4;
    cout << ans << endl;
}

Measured memory_bytes: 3160
//#include <bits/stdc++.h>
#include<iostream>
#include<iomanip>
#include<numeric>
#include<cstdio>
#include<cmath>
#include<string>
#include<algorithm>
#include<vector>
#include<map>
#include<stack>
#include<queue>
#include<ctype.h>
#include <fstream>
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define REP(i,n) FOR(i,0,n)
using namespace std;
typedef long long ll;//int64
typedef unsigned long long ull;
int gcd(int a,int b){return b?gcd(b,a%b):a;}
int lcm(int a,int b){return a*b/gcd(a,b);}
int dy[4]={0,1,0,-1};
//----------program from here----------

int main(){
  int a=0,b=0,c=0;

  cin >> a >> b >> c;
  cout << (a==b?(a==c?1:2):(b==c?2:a==c?2:3)) << endl;

  return 0;
}

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

constexpr int INF = 10000001;

int main() {
    std::ios::sync_with_stdio(false);
    std::cin.tie(0);
    int n, u, k, vv, cc;
    std::cin >> n;
    std::vector<std::vector<int>> v(n), c(n);
    std::vector<int> d(n), p(n);
    std::set<int> v_s, s;
    for (int i=0; i<n; i++) {
        std::cin >> u >> k;
        for (int j=0; j<k; j++) {
            std::cin >> vv >> cc;
            v[u].push_back(vv);
            c[u].push_back(cc);
        }
        d[i] = INF;
        v_s.insert(i);
    }
    d[0] = 0;
    //v_s.erase(0);

    while (not v_s.empty()) {
        int mind=INF+1;
        int minnode;
        auto iter = v_s.begin();
        for (int i=0; i<v_s.size(); i++,iter++) {
            if (d[*iter] < mind) {
                mind = d[*iter];
                minnode = *iter;
            }
        }
        v_s.erase(minnode);
        s.insert(minnode);
        for (int i=0; i<v[minnode].size(); i++) {
            if (v_s.find(v[minnode][i]) != v_s.end() and mind + c[minnode][i] < d[v[minnode][i]]) {
                d[v[minnode][i]] = mind + c[minnode][i];
                p[v[minnode][i]] = minnode;
            }
        }
    }

    for (int i=0; i<n; i++) {
        std::cout << i << " " << d[i] << "\n";
    }

    return 0;
}


Measured memory_bytes: 3216
#include <bits/stdc++.h>
using ll = long long;
using namespace std;
using Graph = vector<vector<ll>>;

int main(){
  string s; cin >> s;
  int ans = -1;
  for (int  left = 0; left < s.size(); left++)
  {
    for (int right = left; right < s.size(); right++)
    {
      char c = s.at(right);
      if (c == 'A' ||c == 'C' ||c == 'G' ||c == 'T')
      {
        if(right == s.size() - 1)
        {
          ans = max(ans, right - left + 1);
        }
        continue;
      }
      else 
      {
        ans = max(ans, right - left);
        left = right;
        break;
      }
      
    }
    
  }
  
  cout << ans << endl;

}

Measured memory_bytes: 256
#include<deque>
#include<list>
#include<map>
#include<queue>
#include<set>
#include<stack>
#include<vector>
#include<algorithm>
#include<string>
#include<iostream>
#include<sstream>
#include<cmath>
#include<cstdio>
#include<cstring>
using namespace std;
long long cm(int n,int m){  
  m=n-m<m?n-m:m;
  long long a=1;
  int b=n-m+1,c=1;
  for(;c<=m;){
    a=a*b/c;
    ++b;
    ++c;
  }
  return a;
}
int main(){
  int i,j,k;
  int n,m,l;
  scanf("%d%d%d",&n,&m,&l);
  int a[100],b[100],c[100];
  for(i=0;i<n;++i)
    scanf("%d%d%d",a+i,b+i,c+i);
  long long d[51];
  for(i=0;i<=(m+1)/2;++i)
    d[i]=d[m-i]=cm(m,i);
  double e[100][51],f[100][51],g[100][52];
  for(i=0;i<n;++i){
    g[i][m+1]=0;
    for(j=m;j>=0;--j){
      e[i][j]=(double)l/c[i]+b[i]*j;
      f[i][j]=pow((double)a[i]/100,j)*pow((double)(100-a[i])/100,m-j)*d[j];
      g[i][j]=g[i][j+1]+f[i][j];
    }
  }
  for(i=0;i<n;++i){
    double pr=0;
    for(j=0;j<=m;++j){
      double pi=f[i][j];
      for(k=0;k<n;++k){
	if(i!=k)
	  pi*=g[k][upper_bound(e[k],e[k]+m+1,e[i][j])-e[k]];
      }
      pr+=pi;
    }
    printf("%.8f\n",pr);
  }
  return 0;
}

Measured memory_bytes: 0
#define _CRT_SECURE_NO_WARNINGS

#include <stdio.h>
#include <string.h>
#include <algorithm>
#include <set>
#include <map>
#include <vector>
#include <math.h>
#include <cmath>
#include <queue>
#include <stack>
#include <list>
#include <functional>
#include <numeric>
#include <iostream>
#include <string>
#include <time.h>
#include <bitset>

using namespace std;
typedef long long ll;
#define rep(i, n) for (ll i = 0; i < (n); ++i)
#define all(x) (x).begin(),(x).end()
ll GCD(ll a, ll b) { return b ? GCD(b, a % b) : a; }

ll N, x[212345], y[212345], xx[212345], yy[212345];

int main() {

	cin >> N;

	rep(i, N) cin >> x[i] >> y[i];

	rep(i, N) {
		xx[i] = x[i] - y[i];
		yy[i] = x[i] + y[i];
	}

	ll minxx = xx[0], maxxx = xx[0], minyy = yy[0], maxyy = yy[0];

	rep(i, N) {
		minxx = min(minxx, xx[i]);
		maxxx = max(maxxx, xx[i]);
		minyy = min(minyy, yy[i]);
		maxyy = max(maxyy, yy[i]);
	}

	cout << max(maxxx - minxx, maxyy - minyy) << endl;

	return 0;
}


Measured memory_bytes: 9852
P = 998244353
N = int(input())
A = [int(a) for a in input().split()]
V = max(A) + 1
X = [0] * V
for a in A:
    X[a] += 1

fa = [1]
for i in range(1, V):
    fa.append(fa[-1]*i%P)
fainv = [pow(fa[-1], P-2, P)]
for i in range(1, V)[::-1]:
    fainv.append(fainv[-1]*i%P)
fainv = fainv[::-1]
W = [1] + [fainv[i] * fa[i-1] % P for i in range(1, V)]

for k in range(1, V):
    for i in range(k*2, V, k):
        W[i] = (W[i] - W[k]) % P

ans = 0
for k in range(1, V):
    s1 = 0
    s2 = 0
    for i in range(k, V, k):
        if X[i]:
            s1 += i * X[i]
            s2 += i * i * X[i]
    ans = (ans + (s1*s1-s2) * W[k]) % P
print(ans * fainv[2] % P)

Measured memory_bytes: 138360
N,W=map(int,input().split())
A=[list(map(int,input().split())) for i in range(N)]
dp=[[0 for i in range(W+1)] for j in range(N)]

for i in range(N):
    for j in range(W+1):
        if i==0:
            if j-A[i][1]>=0:
                dp[i][j]=A[i][0]
        else:
            if j-A[i][1]<0:
                dp[i][j]=dp[i-1][j]
            else:
                dp[i][j]=max(dp[i-1][j],dp[i-1][j-A[i][1]]+A[i][0])

print(dp[N-1][W])


Measured memory_bytes: 25520
###############################################
#                                             #
#   author: raghav_0901 (Raghav Dalmia)       #
#   updated on: 29-08-2020,  5:45:07 pm IST   #
#                                             #
###############################################

from math import *


def _in():
    arr = input().split(' ')
    return arr[0] if len(arr) == 1 else arr


def numCng(s, t):
    if(len(s) != len(t)):
        return 10**9
    cnt = 0
    for i in range(len(s)):
        if(s[i] != t[i]):
            cnt = cnt + 1
    # print(s, t, cnt)
    return cnt


if __name__ == "__main__":
    s = input()
    t = input()
    n, m = len(s), len(t)
    ans = m
    for i in range(n - m + 1):
        ans = min(ans, numCng(s[i:i + m], t))
    print(ans)


Measured memory_bytes: 9076
#include <bits/stdc++.h>
// statics
using namespace std;
using int64 = long long;
using PAIR = pair<int64, int64>;
constexpr int INF = 1 << 30;
constexpr int64 LINF = 1LL << 60;
constexpr int MOD = 1e9 + 7;
constexpr int MAX_N = 3e5 + 1;

// init/input
#define int int64
#define INIT ios::sync_with_stdio(false);cin.tie(0);
#define VAR(type, ...) type __VA_ARGS__;MACRO_VAR_Scan(__VA_ARGS__);
template<typename T> void MACRO_VAR_Scan(T &t) {cin>>t;}
template<typename First, typename...Rest> void MACRO_VAR_Scan(First &first, Rest&...rest) {cin>>first;MACRO_VAR_Scan(rest...);}
#define VEC(type, c, n) vector<type> c(n);for(auto &&i:c)cin>>i;

// out
#define OUT(dist) cout<<(dist);
#define FOUT(n, dist) cout<<fixed<<setprecision(n)<<(dist);
#define SP cout<<" ";
#define BR cout<<endl;
#define zero(n) cout<<setfill('0')<<right<<setw(n)
#define debug(x) cerr<<#x<<":"<< (x);BR;

// utility
#define ALL(a) (a).begin(), (a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define EACH(i, a) for(auto &&i:(a))
#define FOR(i, a, b) for(int i=(a);i<(b);++i)
#define RFOR(i, a, b) for(int i=(b)-1;i>=(a);--i)
#define REP(i, n) for(int i=0;i<(n);++i)
#define RREP(i, n) for(int i=(n)-1;i>=0;--i)
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
int gcd(int a,int b){return b?gcd(b,a%b):a;}

struct UnionFind {
  vector< int > par;
  UnionFind(int n = 1) {
    init(n);
  }

  void init(int n = 1) {
    par.resize(n);
    for(int i = 0; i < n; i++)
      par[i] = -1;
  }
  
  int root(int n) {
    if (par[n] < 0) return n;
    return par[n] = root(par[n]);
  }

  bool merge(int x, int y) {
    x = root(x); y = root(y);
    if (x == y) return false;
    if (par[x] > par[y]) swap(x, y);
    par[x] += par[y];
    par[y] = x;

    return true;
  }

  bool issame(int x, int y) {
    return root(x) == root(y);
  }

  int size(int x){
	  return -(par[root(x)]);
  }
};

signed main() {
  INIT;
  VAR(int,n,m);
  vector< pair<int,int> > d(m);
  REP(i,m){
    VAR(int,a,b);
    --a;--b;
    d[i] = make_pair(a,b);
  }

  reverse(ALL(d));
  
  UnionFind uf(n);
  vector<int> memo(m,0);

  REP(i,m){
    int a,b; tie(a,b)=d[i];
    /*
    debug(a);
    debug(b);
    debug(uf.size(a));
    debug(uf.size(b));
    */
    if(i>0) memo[i] += memo[i-1];
    
    if(!uf.issame(a,b)) memo[i] += uf.size(a) * uf.size(b);
    //debug(memo[i]);
    //debug("");
    uf.merge(a,b);
    //debug(uf.size(a));
  }

  RREP(i,m-1){
    //debug(memo[i]);
    OUT(memo[m-1]-memo[i])BR;
  }
  OUT(memo[m-1])BR;
  
  return 0;
}


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

using namespace std;
typedef long long ll;
typedef pair<ll, ll> p_ll;

template<class T>
void debug(T itr1, T itr2) { auto now = itr1; while(now<itr2) { cout << *now << " "; now++; } cout << endl; }
#define repr(i,from,to) for (int i=(int)from; i<(int)to; i++)
#define all(vec) vec.begin(), vec.end()
#define rep(i,N) repr(i,0,N)
#define per(i,N) for (int i=(int)N-1; i>=0; i--)

const ll MOD = pow(10,9)+7;
const ll LLINF = pow(2,61)-1;
const int INF = pow(2,30)-1;

vector<ll> fac;
void c_fac(int x=pow(10,6)+10) { fac.resize(x,true); rep(i,x) fac[i] = i ? (fac[i-1]*i)%MOD : 1; }
ll inv(ll a, ll m=MOD) { ll b = m, x = 1, y = 0; while (b!=0) { int d = a/b; a -= b*d; swap(a,b); x -= y*d; swap(x,y); } return (x+m)%m; }
ll nck(ll n, ll k) { return fac[n]*inv(fac[k]*fac[n-k]%MOD)%MOD; }
ll gcd(ll a, ll b) { if (a<b) swap(a,b); return b==0 ? a : gcd(b, a%b); }
ll lcm(ll a, ll b) { return a/gcd(a,b)*b; }


int main() {
  int N; cin >> N;
  string s[N]; int t[N]; rep(i,N) cin >> s[i] >> t[i];
  string X; cin >> X;
  int pos = 0; while(s[pos]!=X) pos++;
  int result = 0;
  repr(i,pos+1,N) result += t[i];
  cout << result << endl;
  return 0;
}

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

using namespace std;

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

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

const int dx[] = { -1, 0, 1, 0 }; const int dy[] = { 0, 1, 0, -1 };
int lfunc(int t, int f){
	int leye[] = { 0, 3, 5, 2, 4, 0, 4, 0, 1, 6, 0, 3, 2, 6, 0, 0, 1, 5 };
	if (t < 4)return leye[(t - 1) * 6 + (f - 1)];
	else return leye[(6 - t) * 6 + (6 - f)];
}
struct dief{
	int height;
	int eye;
};
int main() {

	int n;
	while (cin >> n, n){
		dief field[100][100] = { 0 };
		int ans[6] = { 0 };
		REP(i, n){
			int x = 50, y = 50;
			int t, f;
			cin >> t >> f;
			while (1){
			int l;
			l = lfunc(t, f);
				int move = 0;
				REP(j, 4){
					if (field[x + dx[j]][y + dy[j]].height < field[x][y].height)move += (1 << j);
				}
				if (move == 0){
					field[x][y].eye = t;
					field[x][y].height++;
					break;
				}
				int b = false;
				REP(j, 3){
					REP(k, 4){
						if (!(move&(1 << k)))continue;
						switch (k){
						case 0:
							if (f == 6 - j){
								x += dx[k];
								y += dy[k];
								int f2 = f;
								f = t;
								t = 7 - f2;
								b = true;
							}
							break;
						case 1:
							if (l == j + 1){
								x += dx[k];
								y += dy[k];
								f = f;
								t = l;
								b = true;
							}
							break;
						case 2:
							if (f == j + 1){
								x += dx[k];
								y += dy[k];
								int f2 = f;
								f = 7-t;
								t = f2;
								b = true;
							}
							break;
						case 3:
							if (l == 6 - j){
								x += dx[k];
								y += dy[k];
								f = f;
								t = 7-l;
								b = true;
							}
							break;
						}
					}
					if (b)break;
				}
				if (!b){
					field[x][y].eye = t;
					field[x][y].height++;
					break;
				}
			}
		}
		REP(i,100){
			REP(j, 100){
				if (field[i][j].eye != 0)ans[field[i][j].eye - 1]++;
			}
		}
		REP(i, 6){
			cout << ans[i];
			if (i != 5)cout << " ";
			else cout << endl;
		}
	}
}

Measured memory_bytes: 1244