akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
using namespace std;

char sa[4004], sb[4004];
int dp[4001][4001], mm;

void search(){
    mm = 0;
    for(int z = 0; z < 4000; z++){
        if( sb[z] ) dp[0][z] = (sa[0] == sb[z]);
        if( sa[z] ) dp[z][0] = (sa[z] == sb[0]);
    }
    for(int x = 0; sa[x+1]; x++){
        for(int y = 0; sb[y+1]; y++){
            dp[x+1][y+1] = (sa[x+1] == sb[y+1]) ?
                           dp[x][y] + 1 : 0;
            if( dp[x+1][y+1] > mm ) mm = dp[x+1][y+1];
        }
    }
    cout << mm << endl;
}

int main(){
    while( cin >> sa >> sb ){
        search();
    }
    return 0;
}

Measured memory_bytes: 63672
#include<bits/stdc++.h>
#define rep(i,n) for (int i=0;i<(n);i++)
#define PI 3.14159265358979323846264338327950L
using namespace std;
using P = pair<int,int>;
using ll = long long;
using namespace std;
int main(void){
    int n;
    cin >> n;
    string s;
    cin >> s;
    int len = s.length();
    string a;
    rep(i, len){
        int x = s[i]-'A';
        x= (x+n) % 26;
        a = x+'A';
        cout << a;
    }
    return 0;
}

Measured memory_bytes: 3600
N = input()
b = N[0]
c = 0
for i in range(2**(len(N)-1)):
    a = "0"*20+str(bin(i))[2:]
    for j in range(1,len(N)):
        if a[-j] == "0":
            b += N[j]
        elif a[-j] == "1":
            c += int(b)
            b = N[j]
    c += int(b)
    b = N[0]
print(c)
    

Measured memory_bytes: 3060
R,C,K = map(int,input().split())
RCV = [list(map(int,input().split())) for _ in [0]*K]

V = [[0]*(C+1) for _ in [0]*(R+1)]

for r,c,v in RCV:
    V[r][c] = v

ans = [[[0]*(C+1) for _ in [0]*(R+1)] for _ in [0]*4]

for r in range(1,R+1):
    for c in range(C+1):
        ans[0][r][c] = max(ans[0][r-1][c],ans[1][r-1][c],ans[2][r-1][c],ans[3][r-1][c])
    i = 1
    for c in range(1,C+1):
        ans[i][r][c] = max(ans[i][r][c],ans[i][r][c-1],ans[i-1][r][c]+V[r][c])
    for i in range(2,4):
        for c in range(1,C+1):
            ans[i][r][c] = max(ans[i][r][c],ans[i][r][c-1],ans[i-1][r][c-1]+V[r][c])

out = max(ans[0][-1][-1],ans[1][-1][-1],ans[2][-1][-1],ans[3][-1][-1])
print(out)

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

using namespace std;
char s[100000];
char first_char,end_char;
int l;
int main ()
{
	scanf("%s",s);
	l=strlen(s)-2;
	first_char=s[0];
	end_char=s[l+1];
	printf("%c%d%c",first_char,l,end_char);
	return 0;
}

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

#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define rep3(i,m,n) for(int (i)=m;(i)<=(n);(i)++)
#define rep3rev(i,m,n) for(int (i)=m;(i)>=(n);(i)--)
#define all(a) (a.begin()),(a.end())
#define rall(a) (a.rbegin()),(a.rend())
#define fi first
#define se second
#define pb push_back
#define eb emplace_back

using ll = long long;
using vll = vector<ll>;
using vi = vector<int>;
using vvi = vector<vector<int>>;
using P = pair<int, int>;

void Main(){
    int n; cin >> n;    
    cout << 1-n << endl;
    return;
}

int main(){
    cin.tie(nullptr);
    ios_base::sync_with_stdio(false);
    cout << fixed << setprecision(15);
    Main();
    return 0;
}

Measured memory_bytes: 3632
#include<bits/stdc++.h>
using namespace std;
int main()
{
  int h,n;
  cin>>h>>n;
  int a[n];
  int sum=0;
  for(int i=0;i<n;i++)
  {
    cin>>a[i];
    sum+=a[i];
  }
  
  if(sum>=h)cout<<"Yes"<<endl;
  else
    cout<<"No"<<endl;
  
}


Measured memory_bytes: 640
a = [list(map(int, input().split())) for _ in range(3)]
n = int(input())
b = set([int(input()) for _ in range(n)])

yoko = [[(i,j) for j in range(3)] for i in range(3)]
tate = [[(i,j) for i in range(3)] for j in range(3)]
naname = [[(i,i) for i in range(3)], [(i,2 - i) for i in range(3)]]

atari = set()
for i in range(3):
    for j in range(3):
        if a[i][j] in b:
            atari.add((i, j))

if len(atari) < 3:
    print('No')
else:        
    for i in yoko:
        if i[0] in atari and i[1] in atari and i[2] in atari:
            print('Yes')
            exit()

    for i in tate:
        if i[0] in atari and i[1] in atari and i[2] in atari:
            print('Yes')
            exit()

    for i in naname:
        if i[0] in atari and i[1] in atari and i[2] in atari:
            print('Yes')
            exit()
    
    print('No')

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

int main()
{
	string s, s1, s2;
	string ss, ss1, ss2;
	cin >> s;
	int n = s.length();
	s1 = s.substr(0, (n-1)/2);
	s2 = s.substr((n+3)/2-1, (n-1)/2);
	ss = s; reverse(ss.begin(), ss.end());
	ss1 = s1; reverse(ss1.begin(), ss1.end());
	ss2 = s2; reverse(ss2.begin(), ss2.end());
	if (s == ss && s1 == ss1 && s2 == ss2)	puts("Yes");
	else	puts("No");
	return 0;
}

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

int l[100010], r[100010];
int t[100010];
int main() {
	int n,q; cin >> n >> q;
	string s; cin >> s;
	for (int i=0; i<q; ++i) {
		cin >> l[i] >> r[i];
	}
	t[0]=0;
	for (int i=0; i<n-1; ++i) {
		if ((s[i]=='A') && (s[i+1]=='C')) {
			t[i+1] = t[i] + 1;
		} else {
			t[i+1] = t[i];
		}
	}
	
	for (int i=0; i<q; ++i) {
		cout << t[r[i]-1] - t[l[i]-1] << endl;
	}	
	
	return 0;
}


Measured memory_bytes: 2176
#include <bits/stdc++.h>
using namespace std;
#define rep(i,ini,n) for(int i=ini;i<n;i++)
#define _rep(i,ini,n) for(int i=ini;i>=n;i--)
#define ToEnd(a) a.begin(),a.end()
uint64_t MOD=1000000007;

int main(){
    int N; cin>>N;
    vector<int> S(N);
    rep(n,0,N) cin>>S.at(n);

    priority_queue<int> notTen;
    for(auto s:S) if(s%10!=0) notTen.push(-s);

    int ans=accumulate(ToEnd(S),0);
    if(ans%10==0){
        if(notTen.size()) ans+=notTen.top();
        else ans=0;
    }

    cout<<ans<<endl;
}

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

int main() {
  int x;
  int N = 5;
  
  for(int i = 0; i < N; i++) {
    cin >> x;
     if (x == 0) {
       cout << i + 1 << endl;
       break;
     }
  }
}

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

#define rep(i, n) for(int i = 0; i<(n); i++)
#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)
using namespace std;
using ll = long long;

int main() {
    int N;
    cin >> N;
    vector<ll> A(N);
    rep(i, N) cin >> A[i];
    sort(A.rbegin(), A.rend());
    ll ans = A[0];
    int j = 1;
    rep(i, N - 2) {
        ans += A[j];
        i++;
        if (i < N - 2) ans += A[j];
        j++;
    }
    cout << ans << endl;
}


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

int count_marubatu(string S, int N)
{
	int sum=0, count;
	rep(i, N-1)
	{
		count = 0;
		while(S[i+count]!=S[i+count+1] && i+count+1<N) count++;
		i += count;
		if(count%2==1) count++;
		sum += count/2;
	}
	return sum;
}

int main(void)
{
    int N;
    cin >> N;
	string S;
	cin >> S;
	int ans = count_marubatu(S, N);
	cout << ans << endl;
}



Measured memory_bytes: 3336
import java.util.Scanner;
public class Main {
    static double num = 380000;
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        double ans = 0;
        for(int i = 0 ; i < n ; i++){
            double val = sc.nextDouble();
            char type = sc.next().charAt(0);
            if(type == 'J'){
                ans += val;
            } else {
                ans += val * num;
            }
        }
        System.out.println(ans);
    }
}

Measured memory_bytes: 23124
#include<bits/stdc++.h>
#define ll long long
using namespace std;
const int mod=998244353;
const int inf=0x3f3f3f3f;
int a[100005];
int main()
{
    ios::sync_with_stdio(false);
    string s; cin>>s;
    int len=s.size();
    if(s[0]==s[s.size()-1]) len--;
    if(len%2==0)
        cout<<"Second"<<endl;
    else
        cout<<"First"<<endl;
    return 0;
}


Measured memory_bytes: 512
// https://beta.atcoder.jp/contests/abc116

#define SUBMIT

#include <bits/stdc++.h>
using namespace std;

int main() {
    int a[3];
    cin >> a[0] >> a[1] >> a[2];
    sort(begin(a), end(a));
    auto ans = a[0] * a[1] / 2;
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
//Love and Freedom.
#include<cstdio>
#include<cmath>
#include<algorithm>
#include<cstring>
#define ll long long
#define inf 20021225
#define N 5010
#define mdn 1000000007
using namespace std;
int read()
{
	int s=0,t=1; char ch=getchar();
	while(ch<'0'||ch>'9'){if(ch=='-')	t=-1; ch=getchar();}
	while(ch>='0' && ch<='9')	s=s*10+ch-'0',ch=getchar();
	return s*t;
}
int n,a[N],fa[N],sz[N],wei,f[N][N]; bool tag[N];
int find(int x){return x==fa[x]?x:fa[x]=find(fa[x]);}
void merge(int x,int y)
{
	int fx=find(x),fy=find(y); if(fx==fy){tag[fx]=1; return;}
	fa[fx]=fy; sz[fy]+=sz[fx]; tag[fy]|=tag[fx];
}
void upd(int &x,int y){x+=x+y>=mdn?y-mdn:y;}
int ksm(int bs,int mi)
{
	int ans=1;
	while(mi)
	{
		if(mi&1)	ans=1ll*ans*bs%mdn;
		bs=1ll*bs*bs%mdn; mi>>=1; 
	}
	return ans;
}
int fac[N],inv[N];
int C(int n,int m){return 1ll*fac[n]*inv[m]%mdn*inv[n-m]%mdn;}
int main()
{
	n=read(); fac[0]=1;
	for(int i=1;i<=n;i++)	sz[i]=1,fa[i]=i,fac[i]=1ll*fac[i-1]*i%mdn; inv[n]=ksm(fac[n],mdn-2);
	for(int i=n;i;i--)	inv[i-1]=1ll*inv[i]*i%mdn; f[0][0]=1;
	for(int i=1;i<=n;i++){a[i]=read(); if(~a[i])	merge(a[i],i); else	wei++;}
	int coe=ksm(n-1,wei),cur=0,ans=0;
	for(int i=1;i<=n;i++)	if(find(i)==i)
	{
		if(tag[i])	upd(ans,coe);
		else
		{
			cur^=1; memcpy(f[cur],f[cur^1],sizeof(f[cur]));
			for(int j=0;j<=wei;j++)	if(f[cur^1][j])
				upd(f[cur][j+1],1ll*sz[i]*f[cur^1][j]%mdn);
		}
	}
	for(int i=1;i<=wei;i++)	upd(ans,1ll*ksm(n-1,wei-i)*f[cur][i]%mdn*fac[i-1]%mdn);
	if(wei)	upd(ans,mdn-1ll*wei*ksm(n-1,wei-1)%mdn);
	ans = (1ll*ksm(n-1,wei)*n%mdn-ans+mdn)%mdn;
	printf("%d\n",ans);
	return 0;
}


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

using namespace std;

// repetition
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define rep(i, n) for (int i = 0; i < (int)(n); i++)

// container util
#define all(x) (x).begin(), (x).end()

// typedef
typedef long long llint;
typedef unsigned long long ull;
typedef complex<long double> Complex;
typedef pair<int, int> P;
typedef tuple<int, int, int> TP;
typedef vector<int> vec;
typedef vector<vec> mat;

// constant
const int MOD = (int)1e9 + 7;
const int INF = (int)1e9;
const int dx[] = {0, 1, 0, -1};
const int dy[] = {1, 0, -1, 0};
const int ddx[] = {0, 1, 1, 1, 0, -1, -1, -1};
const int ddy[] = {1, 1, 0, -1, -1, -1, 0, 1};
const double pi = 3.14159265358979323846;

// conversion
inline int toInt(string s) {
  int v;
  istringstream sin(s);
  sin >> v;
  return v;
}
template <class T>
inline string toString(T x) {
  ostringstream sout;
  sout << x;
  return sout.str();
}

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

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

  int n;
  cin >> n;
  vector<llint> a(n);
  map<llint, llint> mp;
  for (int i = 0; i < n; i++) {
    cin >> a[i];
    mp[a[i]]++;
  }
  llint ans = 0;
  for (auto v : mp) {
    llint x = v.second;
    ans += x * (x - 1) / 2;
  }
  for (int i = 0; i < n; i++) {
    llint x = mp[a[i]];
    llint res = ans - x * (x - 1) / 2LL;
    x--;
    res += x * (x - 1) / 2;
    cout << res << endl;
  }

  return 0;
}

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

ans = 'APPROVED'
for i in range(N):
  if A[i] % 2 == 0 and A[i] % 3 != 0 and A[i] % 5 != 0:
    ans = 'DENIED'
    break
      
print(ans)

Measured memory_bytes: 9176
#include<bits/stdc++.h>
using namespace std;
int n,l,sum,ans=1e9,anspr;
int main(){
    int i,j;
    scanf("%d %d",&n,&l);
    for(i=1;i<=n;i++){
        if(abs(ans)>abs(l+i-1)) ans=l+i-1;
        sum+=l+i-1;
    }
    printf("%d",sum-ans);
    return 0;
}


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

using namespace std;

typedef long long ll; // ll  is 64bit same as double

int main() {
	
	// make input and output more efficient
	ios::sync_with_stdio(0);
	cin.tie(0);
	
	int a[5];
	
	int answer = -1;
	for(int i =0;i < 5;i++) {
		cin >> a[i];
		if(a[i] == 0) answer = i + 1;
	}
	
	cout << answer << "\n";	
	return 0;
}



Measured memory_bytes: 3612
#include <bits/stdc++.h>
using namespace std;
///////////////////////////////////////////
const long long int INF = 1LL<<60;
const long long int Mod = 1000000007;
using ll = long long int; using ci = const int;
using vi = vector<int>;  using Vi = vector<long long int>;
using P = pair<int, int>;  using PLL = pair<ll, ll>;
using matrix = vector<vector<ll>>;
#define pb(x) push_back(x)
#define mp(x,y) make_pair(x,y)
#define all(x) (x).begin(),(x).end()
#define rp(i,N) for(ll i = 0; i < (ll)N; i++)
#define repi(i,a,b) for(ll i = ll(a); i < ll(b); ++i)
template<class T>bool chmax(T &former, const T &b) { if (former<b) { former=b; return true; } return false; }
template<class T>bool chmin(T &former, const T &b) { if (b<former) { former=b; return true; } return false; }
template<class T>T sqar(T x){ return x*x; }//sqrt(x)は平方根;
#define Sort(v) std::sort(v.begin(), v.end(), std::greater<decltype(v[0])>()) //降順でVをソート
#define p_queue(v) priority_queue<v, vector<v>, greater<v> >
template<class T> inline void princ(T x){cout<<x<<" ";}; 
template<class T> inline void print(T x){cout<<x<<"\n";};
template<class T> inline void Yes(T condition){ if(condition) cout << "Yes" << endl; else cout << "No" << endl; }
template<class T> inline void YES(T condition){ if(condition) cout << "YES" << endl; else cout << "NO" << endl; }
///////////////////////////////////////////////////////////////////////////////////

void solve(){
    int n;
    cin >> n;
    Vi a(n);
    rp(i,n) cin >> a.at(i);
    sort(all(a));
    ll num=a[0];
    ll ctr=1;
    ll ans=0;
    rp(i,n-1){
        if(a.at(i)==a.at(i+1)){
            num=a.at(i);
            ctr++;
        }else{
            if(num<ctr) ans+=ctr-num;
            else if(ctr<num) ans+=ctr;
            ctr=1;
            num=a.at(i+1);
            
        }
    }
    if(num<ctr) ans+=ctr-num;
    else if(ctr<num) ans+=ctr;
    print(ans);
    return;
}
int main(){
    cin.tie(0);ios::sync_with_stdio(false);
    std::cout<<std::fixed<<std::setprecision(30);
    solve();
    return 0;
}

Measured memory_bytes: 3972
#!/usr/bin/env python3

N = int(input())
A = list(map(int,input().split()))
ans = 1
if 0 in A:
    print(0)
    exit()
else:
    for i in A:
        ans *= i
        if ans > 10**18:
            print(-1)
            exit()
print(ans)

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

using namespace std;

#define ll long long

const int N = 2*1e5;
const ll INF = 1e18;

int n;
long long K;
vector<int> q;

int sol(ll mi, int i){
    ll v = q[i];

    if(v == 0)
        if (mi >= 0) return n - 1; else return 0;

    if (v < 0 && v*q[n-1] > mi) return 0;
    if (v > 0 && v*q[0] > mi) return 0;


    int d = 0;
    int c = n-1;
    int g;
    int ans = 0, ww;
    while (d <= c){
        g = (d + c) / 2;
        if (q[g]*v <= mi) {
            ww = g;
            if (v < 0) c = g - 1; else d = g + 1;
        } else {
            if (v < 0) d = g + 1; else c = g - 1;
        }
    }

    //cout << "ww : " << ww << endl;

    if (v < 0){
        if (ww <= i) ans = -1;
        ans += n - ww;
    }
    else {
        if (i <= ww) ans = -1;
        ans += ww + 1;
    }

    return ans;
}
int main(){
    //freopen("in.txt", "r", stdin);
    cin >> n >> K;
    q.resize(n);
    for (int i = 0; i < n; i++) cin >> q[i];
    sort(q.begin(), q.end());
    ll lo = - INF;
    ll hi =   INF;
    ll mi;

    ll x = 0;
    while (lo + 1 < hi){
        mi = (lo + hi) / 2;

        ll x = 0;
        //cout << "mi: " << mi << endl;
        for (int i = 0; i < n; i++) {
            ll tmp = sol(mi, i);
            //cout << i << " : " << tmp << endl;
            x += tmp;
        }
        x = x / 2;
        //cout << "x: " << x << endl;
        if (x >= K) hi = mi; else lo = mi;
    }
    cout << hi << endl;
}


Measured memory_bytes: 1152
#pragma warning(disable:4996)
#pragma comment(linker, "/STACK:336777216")
#pragma GCC optimize("Ofast")

#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include <functional>

using namespace std;
using namespace __gnu_pbds;

typedef long long ll;
#define int long long int
typedef complex<long double> cd;
const long double pi=acos(-1);
typedef double db;
typedef long double ldb;
typedef pair <int, int> pii;
typedef pair <db, db> pdd;
typedef vector<int> vi;
typedef vector<vector<int> > matrix;

#define m1 make_pair
#define pb push_back
#define flush fflush(stdout)
#define IOS std::ios::sync_with_stdio(false); cin.tie(NULL);cout.tie(NULL);
#define reset(x,v) memset(x,v,sizeof(x))

#define fi first
#define se second
#define endl "\n"
#define debug(x) (cerr << #x << ": " << x << "\n")
#define setbits(x) __builtin_popcount(x)
#define setbitsll(x) __builtin_popcountll(x)
#define all(x) x.begin(),x.end()
#define pii pair<int,int>

inline ll gcd(ll a,ll b){if(a==0) return b;return gcd(b%a,a);}
inline ll power(ll a,ll n,ll m){if(n==0)return 1;ll p=power(a,n/2,m);p=(p%m*p%m)%m;if(n%2) return (p%m*a%m)%m;else return p;}
const double EPS = 1e-9;
const ll MOD =998244353;
const ll hell=1000000007;
const int INF = 1e17;
const ll LL_INF = 0x3f3f3f3f3f3f3f3f;
template<typename T>
using ordered_set=tree<T, null_type, less<T>, rb_tree_tag,tree_order_statistics_node_update>;

auto seed = chrono::high_resolution_clock::now().time_since_epoch().count();
std::mt19937 rng(seed);

double startTime;
double getCurrentTime() {
    return ((double)clock() - startTime) / CLOCKS_PER_SEC;
}


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

const int N=200005;


void solve()
{
    int n,m,x;
    cin>>n>>m>>x;
    int price[n],level[n][m];
    for(int i=0;i<n;i++)
    {
        cin>>price[i];
        for(int j=0;j<m;j++)
            cin>>level[i][j];
    }
    int mn=INF;
    for(int mask=1;mask<(1<<n);mask++)
    {
        int lv[m]={0};int sm=0;
        for(int j=0;j<n;j++)
        {
            if(mask&(1<<j))
            {
                for(int k=0;k<m;k++)
                    lv[k]+=level[j][k];
                sm+=price[j];
            }
        }
        int pos=1;
        for(int k=0;k<m;k++)
            if(lv[k]<x)
                pos=0;
        if(pos)
            mn=min(mn,sm);
    }
    if(mn==INF)
        mn=-1;
    cout<<mn<<endl;
    
    
    
}

int32_t main()
{
    IOS;
   
    int t;
    t=1;
    //cin>>t;
    while(t--)
    {
        solve();
    }
    return 0;
}


Measured memory_bytes: 3660
#include<stdio.h>
#include<iostream>
#include<algorithm>

using namespace std;

int main(){


int W,H,x,y,r;

cin>>W>>H>>x>>y>>r;

if(x==0||y==0||x==W||y==H){
  cout<<"No"<<endl;
  return 0;
}
else if(x+r>W || x-r<0){
  cout<<"No"<<endl;
  return 0;
}
else if(y+r>H || y-r<0){
  cout<<"No"<<endl;
  return 0;
}
else cout<<"Yes"<<endl;

return 0;

}

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

int main (){
    map <string, int> mp;
    ll n;
    cin >> n;
    while (n--){
        string s;
        cin >> s;
        sort (s.begin(), s.end());
        mp[s]++;
    }

    ll count = 0;
    for (auto i = mp.begin(); i != mp.end(); i++){
        ll k = i->second; 
        count += (k)*(k - 1) /2;
    }
    cout << count << endl;
    return 0;
}



Measured memory_bytes: 11136
#include <iostream>
#include <array>
#include <map>
#include <algorithm>
#include <cmath>
#include <vector>
#include <fstream>
#include <string>
#include <random>
#include <queue>
#include <iomanip>
 
using namespace std;
 
using ll = unsigned long long int;
using pii = pair<int, int>;
 
ll arr[100010] = {};
 
 
int main() {
 
	ll a, b, c, d, n;
	cin >> a >> b >> c >> d >> n;
 
	b = min(a * 2, b);
	c = min(b * 2, c);
	d = min(c * 2, d);
 
	ll e = n / 2,ans = 0;
 
	ans += e * d;
	if (n % 2) {
		ans += c;
	}
 
	cout << ans << endl;
 
}

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

using namespace std;

void solve() {
    int n,k;
    cin >> n >> k;
    vector<int> a(n);
    for (auto& x: a) {
        cin >> x;
    }
    sort(a.begin(), a.end(), greater<int>());
    bitset<5000> dp;
    dp[0] = 1;
    int cnt = 0;
    for (int x: a) {
        bool nec = false;
        for (int i = k-1; i >= 0; i--) {
            if (dp[i]) {
                if (x+i >= k) nec = true;
                else dp[x+i] = 1;
            }
        }
        if (nec) cnt = 0;
        else cnt++;
    }
    cout << cnt;
}

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    solve();
    cout << endl;
}


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

#define int long long
#define endl "\n"
#define REP(i,a,n) for(int i=a;i<n;++i)
#define REPR(i,a,n) for(int i=a;i>n;--i)
#define RUP(a,b) (((a)+(b)-1)/(b))
#define ALL(v) (v).begin(),(v).end()
#define pb push_back
#define mp make_pair
#define mt make_tuple
#define INF LLONG_MAX/2
#define PI acos(-1.0)
//#define MOD 1000000007

typedef long long ll;
typedef pair<int,int> Pii;
typedef tuple<int,int,int> Tiii;
typedef vector<int> Vi;
typedef vector<Vi> VVi;
typedef vector<Pii> VPii;
typedef vector<string> Vs;
typedef priority_queue<int> PQi;

template<class T> inline bool chmax(T& a,T b){if(a<b){a=b;return 1;}return 0;}
template<class T> inline bool chmin(T& a,T b){if(a>b){a=b;return 1;}return 0;}
void vout(Vi &v){for(int i=0;i<(v).size();i++) cout<<v[i]<<" ";cout<<endl;}
void vout(Vs &v){for(int i=0;i<(v).size();i++) cout<<v[i]<<" ";cout<<endl;}
void vvout(VVi &v){for(int i=0;i<(v).size();i++) vout(v[i]);}
int gcd(int a,int b){return b?gcd(b,a%b):a;}
int lcm(int a,int b){return a/gcd(a,b)*b;}
int mypow(int x, int n, int m){if(n==0)return 1;if(n%2==0)return mypow(x*x%m,n/2,m);else return x*mypow(x,n-1,m)%m;}
int digit(int k,int i){string s = to_string(k);return s[s.size()-i]-'0';}
void uniq(Vi &v){sort(v.begin(),v.end()); v.erase(unique(v.begin(),v.end()),v.end());} //vectorの同じ要素消す
int ctoi(char c){if(c>='0'&&c<='9'){return c-'0';}return 0;}
int leng(int n){string s=to_string(n); return s.size();} //intの桁数
int digitsum(int n){int ret=0; while(n>0){ret+=n%10;n/=10;}return ret;} //桁和
int lesscount(int x,Vi &a){return lower_bound(a.begin(),a.end(),x)-a.begin();} //vector aにおけるx未満の数の個数
int orlesscount(int x,Vi &a){return upper_bound(a.begin(),a.end(),x)-a.begin();} //vector aにおけるx以下の数の個数
int morecount(int x,Vi &a){return a.size()-orlesscount(x,a);} //vector aにおけるxより大きい数の個数
int ormorecount(int x,Vi &a){return a.size()-lesscount(x,a);} //vector aにおけるx以上の数の個数
int count(int x,Vi &a) {return upper_bound(ALL(a),x)-lower_bound(ALL(a),x);} //vector aにおけるxの個数
Vi accum(Vi &v){Vi ret((v).size()+1);REP(i,0,(v).size()) ret[i+1]=ret[i]+v[i];return ret;}
bool comp(Pii a,Pii b){
    if(a.second != b.second) return a.second<b.second;
    else return a.first<b.first;
}

signed main(){cin.tie(0);cout.tie(0);ios::sync_with_stdio(false);cout<<fixed<<setprecision(15);
    int n;
    cin>>n;
    Vs s(n);
    REP(i,0,n) cin>>s[i];
    set<string> se;
    REP(i,0,n){
        se.insert(s[i]);
    }
    cout<<se.size()<<endl;
    return 0;
}


Measured memory_bytes: 25116
#include<stdio.h>
#include<string.h>
 
int main() {
    int i;
    int n;
    char taro_str[100], hanako_str[100];
    int taro_score = 0, hanako_score = 0;
 
    scanf("%d", &n);
 
    for (i = 0;i < n;i++) {
        scanf("%s %s", taro_str, hanako_str);
 
        if (strcmp(taro_str, hanako_str) < 0) {
            hanako_score += 3;
        }
        else if (strcmp(taro_str, hanako_str) > 0) {
            taro_score += 3;
        }
        else {
            taro_score++;
            hanako_score++;
        }
    }
 
    printf("%d %d\n", taro_score, hanako_score);
 
    return 0;
}

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

#define ed cout << "\n";
#define speed                         \
    ios_base::sync_with_stdio(false); \
    cin.tie(NULL);                    \
    cout.tie(NULL);
#define ll long long
#define ffor(i, a, b) for (ll i = (ll)(a); i < (ll)(b); ++i)
#define rep(i, n) ffor(i, 0, n)
#define All(obj) (obj).begin(), (obj).end()
#define INF ((ll)1e9 + 7)
#define c(a) cout << a << "\n";
using namespace std;
const int N = 100005;

int main()
{
    speed;
    cout << fixed << setprecision(6);
    /*start*/
    string X, Y;
    cin >> X >> Y;
    string ans = "";
    if (X[0] == Y[0])
        ans = "=";
    else if (X[0] < Y[0])
        ans = "<";
    else if (X[0] > Y[0])
        ans = ">";
    c(ans);
    return 0;
}

Measured memory_bytes: 256
#include <stdio.h>

int main()
{
	int i, N, K, Q, A[100001];
	scanf("%d %d %d", &N, &K, &Q);
	for (i = 1; i <= Q; i++) scanf("%d", &(A[i]));
	
	int ans[100001] = {};
	for (i = 1; i <= Q; i++) ans[A[i]]++;
	for (i = 1; i <= N; i++) {
		if (ans[i] > Q - K) printf("Yes\n");
		else printf("No\n");
	}
	fflush(stdout);
	return 0;
}

Measured memory_bytes: 1280
#include <bits/stdc++.h>
 
using namespace std;
 
template <typename A, typename B>
string to_string(pair<A, B> p);
template <typename A, typename B, typename C>
string to_string(tuple<A, B, C> p);
template <typename A, typename B, typename C, typename D>
string to_string(tuple<A, B, C, D> p);
string to_string(const string& s) {
    return '"' + s + '"';
}
string to_string(const char* s) {
    return to_string((string) s);
}
string to_string(bool b) {
    return (b ? "true" : "false");
}
string to_string(vector<bool> v) {
    bool first = true;
    string res = "{";
    for (int i = 0; i < static_cast<int>(v.size()); i++) {
        if (!first) {
            res += ", ";
        }
        first = false;
        res += to_string(v[i]);
    }
    res += "}";
    return res;
}
template <size_t N>
string to_string(bitset<N> v) {
    string res = "";
    for (size_t i = 0; i < N; i++) {
        res += static_cast<char>('0' + v[i]);
    }
    return res;
}
template <typename A>
string to_string(A v) {
    bool first = true;
    string res = "{";
    for (const auto &x : v) {
        if (!first) {
            res += ", ";
        }
        first = false;
        res += to_string(x);
    }
    res += "}";
    return res;
}
template <typename A, typename B>
string to_string(pair<A, B> p) {
    return "(" + to_string(p.first) + ", " + to_string(p.second) + ")";
}
template <typename A, typename B, typename C>
string to_string(tuple<A, B, C> p) {
    return "(" + to_string(get<0>(p)) + ", " + to_string(get<1>(p)) + ", " + to_string(get<2>(p)) + ")";
}
template <typename A, typename B, typename C, typename D>
string to_string(tuple<A, B, C, D> p) {
    return "(" + to_string(get<0>(p)) + ", " + to_string(get<1>(p)) + ", " + to_string(get<2>(p)) + ", " + to_string(get<3>(p)) + ")";
}
void debug_out() { cerr << endl; }
template <typename Head, typename... Tail>
void debug_out(Head H, Tail... T) {
    cerr << " " << to_string(H);
    debug_out(T...);
}
#ifdef LOCAL
#define debug(...) cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)
#else
#define debug(...) 42
#endif
//Auther: Arin Roday
#define vec vector
#define i64 long long
#define endl '\n'
#define sz(x) (x).size()
#define times(n) for(int i = 0; i < (n); ++i)
#define bits(x) __builtin_popcount(x)
 
int test_case_number = 1;

void print_case(){
    #ifdef LOCAL
    cout << "Case #" << test_case_number++ << ": ";
    #endif
}

void solve(){
    int a;
    cin >> a;
    cout << (a + (a * a) + (a * a * a)) << endl;
}
 
int main(){
    int t = 1;
    while(t--){
        solve();
    }
}

Measured memory_bytes: 3612
import sys, math, itertools, collections, bisect
input = lambda: sys.stdin.buffer.readline().rstrip().decode('utf-8')
inf = float('inf') ;mod = 10**9+7
mans = inf ;ans = 0 ;count = 0 ;pro = 1

a , b = input().split()
a = int(a) * 100
b = int(b[0] + b[2:])
print(a*b//10000)

Measured memory_bytes: 65376
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		// TODO Auto-generated method stub
		Scanner sc = new Scanner(System.in);
		int W = sc.nextInt();
		int H = sc.nextInt();
		int x = sc.nextInt();
		int y = sc.nextInt();
		int r = sc.nextInt();
		int rs=x+r;
		int ls=x-r;
		int u=y+r;
		int d=y-r;
		if(W >= rs && ls >= 0 && H >= u && d >= 0){
				System.out.println("Yes");
		}else{
			System.out.println("No");
		}
	}
}

Measured memory_bytes: 26328
#include<stdio.h>
 
int main(void){
    //ax+by=c
    //dx+ey=f
    double a,b,c,d,e,f,x,y;
    while((scanf("%lf %lf %lf %lf %lf %lf",&a,&b,&c,&d,&e,&f))!=EOF){
    y = (c*d-a*f)/(b*d-a*e)+0.00001;
    x = (c-b*y)/a+0.000001;
    printf("%.3lf %.3lf\n",x,y);
    }
    return 0;
}

Measured memory_bytes: 656
#include <iostream>
#include <string>
#include <stdlib.h>
#include <cstdint>
using namespace std;

#define N 100

char s[N];

int main() {
	int n;
	int ans = 0;

	cin >> n;
	cin >> s;

	for( int i = 1; i < n; i++ ) {
		string x( &s[0], &s[i] );
		string y( &s[i], &s[N] );
		int cnt = 0;
		for( int i = 0; i < 26; i++ ) {
			char c = 'a' + i;
			if( x.find(c) != string::npos && y.find(c) != string::npos ) {
				cnt++;
			}
		}
		if( cnt > ans ) {
			ans = cnt;
		}
	}

	cout << ans << "\n";

	return 0;
}


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

void chmax(long long &a, long long b) {
    if (a < b) a = b;
}
void chmin(long long &a, long long b) {
    if (a > b) a = b;
}

int main() {
    int n; cin >> n;
    long long p_max, p_min, m_max, m_min;
    p_max = m_max = -1e18 - 100;
    p_min = m_min = 1e18 + 100;
    for (int i = 0; i < n; ++i) {
        long long x, y;
        cin >> x >> y;
        chmax(p_max, x + y);
        chmin(p_min, x + y);
        chmax(m_max, x - y);
        chmin(m_min, x - y);
    }
    long long ans = max(p_max - p_min, m_max - m_min);
    cout << ans << endl;
}

Measured memory_bytes: 3508
#include <bits/stdc++.h>
    #define rep(i,n) for (int i = 0; i < (n); ++i)
    using namespace std;
    typedef long long ll;
     
    int main() {
      int n;
      cin >> n;
      int ans = n*n*n;
      cout << ans << endl;
      return 0;
    }

Measured memory_bytes: 256
#!python3

LI = lambda: list(map(int, input().split()))

# input
N, M = LI()

MOD = 10 ** 9 + 7
MAX = (10 ** 5) * 5 + 5
fac, finv, inv = [None] * MAX, [None] * MAX, [None] * MAX


def comb_init():
    fac[0] = fac[1] = 1
    finv[0] = finv[1] = 1
    inv[1] = 1
    for i in range(2, MAX):
        fac[i] = fac[i - 1] * i % MOD
        inv[i] = -inv[MOD%i] * int(MOD / i) % MOD
        finv[i] = finv[i - 1] * inv[i] % MOD


def comb(n, k):
    if n < k or n < 0 or k < 0:
        return 0
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD


def perm(n, k):
    if n < k or n < 0 or k < 0:
        return 0
    return fac[n] * finv[n - k] % MOD


def main():
    comb_init()
    ans = 0
    v = perm(M, N)
    for i in range(N + 1):
        p = 1 if i % 2 == 0 else -1
        x = comb(N, i) * perm(M - i, N - i) % MOD
        ans = (ans + p * v * x) % MOD
    print(ans)
    

if __name__ == "__main__":
    main()


Measured memory_bytes: 115344
import java.util.*;

public class Main {

  public static void main (String[] args) {

    Scanner sc = new Scanner(System.in);

    String s_ = sc.next();
    String[] s = s_.split("");
    int K = sc.nextInt();
    sc.close();

    String result = "";
    SortedSet<String> tree = new TreeSet<>();
    int count = 0;

    for (int i = 0; i < s.length; i++) {
      result = "";
      count = 0;
      for (int j = i; j < s.length; j++) {
        result += s[j];
        tree.add(result);
        count++;
        if (K < count) {
          break;
        }
      }
    }

    String[] arr = tree.toArray(new String[tree.size()]);

    System.out.println(arr[K-1]);

  }

}

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

#define FOR(i,l,r) for(int i = int(l);i < int(r);i++)
template<typename T> bool chmax(T& a,const T& b){ return a < b ? (a = b,true) : false; }
template<typename T> bool chmin(T& a,const T& b){ return b < a ? (a = b,true) : false; }
typedef long long ll;

int N,M;
const int MAX_N = 100000;
vector< pair<int,int> > edge [MAX_N];
vector<int> A;
bool vis [MAX_N];

bool dfs(int curr)
{
	vis [curr] = true;
	bool res = true;
	for(const auto& it : edge [curr]){
		if(vis [it.first] == false){
			A [it.first] = A [curr] + it.second;
			res &= dfs(it.first);
		}
		else{
			res &= A [it.first] == A [curr] + it.second;
		}
	}
	return res;
}

int main()
{
	scanf("%d%d",&N,&M);
	A.assign(N,0);
	FOR(i,0,M){
		int l,r,d;
		scanf("%d%d%d",&l,&r,&d);
		l--;
		r--;
		edge [l].push_back(make_pair(r,d));
		edge [r].push_back(make_pair(l,-d));
	}

	bool ans = true;
	FOR(i,0,N) if(vis [i] == false){
		A [i] = 0;
		ans &= dfs(i);
	}
	puts(ans ? "Yes" : "No");

	return 0;
}


Measured memory_bytes: 12032
import sys
input = sys.stdin.readline

H, W, N = map(int, input().split())
A = [[] for _ in range(H+1)]
for _ in range(N):
    X, Y = map(int, input().split())
    A[X].append(Y)

ans = H
Ymax = 1
for n in range(1, H):
    cango = True
    for y in A[n+1]:
        if y <= Ymax:
            ans = n
            break
        elif y == Ymax+1:
            cango = False
    if ans != H:
        break
    if cango:
        Ymax += 1
print(ans)

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

int main(){
    int h, w = 0;
    while(1){
        cin >> h >> w;
        if(h==0 && w==0){
            break;
        }
        for(int i=1;i<=h;i++){
            if(i%2==1){
                for(int j=1;j<=w;j++){
                    if(j % 2 == 1){
                        cout<<"#";
                    }
                    if(j % 2 == 0){
                        cout<<".";
                    }
                }
            }
            if(i%2==0){
                for(int j=1;j<=w;j++){
                    if(j % 2 == 0){
                        cout<<"#";
                    }
                    if(j % 2 == 1){
                        cout<<".";
                    }
                }
            }
            
            cout<<endl;
        }
            
        
        cout<<endl;
    }
    
    return 0;
}


Measured memory_bytes: 3096
#ifdef DEBUG_IS_VALID
#define DEB 1 
#define _LIBCPP_DEBUG 0
#else
#define DEB 0
#define NDEBUG
#endif

#include <bits/stdc++.h>
using namespace std;

#define ALL(g) (g).begin(),(g).end()
#define REP(i, x, n) for(int i = x; i < n; i++)
#define rep(i,n) REP(i,0,n)
#define RREP(i, x, n) for(int i = x; i >= n; i--)
#define rrep(i, n) RREP(i,n,0)
#define pb push_back
#define fi first
#define se second
#pragma GCC optimize ("-O3")

using namespace std;

#define DUMPOUT cout
#define dump(...) if(DEB) DUMPOUT<<"  "<<#__VA_ARGS__<<" :["<<__LINE__<<":"<<__FUNCTION__<<"]"<<endl<<"    "; if(DEB) dump_func(__VA_ARGS__)
template<typename T1,typename T2>ostream& operator << (ostream& os, pair<T1,T2> p){cout << "(" << p.first << ", " << p.second << ")"; return os;}
template<typename T>ostream& operator << (ostream& os, vector<T>& vec) { os << "{"; for (int i = 0; i<vec.size(); i++) os << vec[i] << (i + 1 == vec.size() ? "" : ", "); os << "}"; return os; }
template<typename T>ostream& operator << (ostream& os, set<T>& st){cout << "{"; for(auto itr = st.begin(); itr != st.end(); itr++) cout << *itr << (next(itr)!=st.end() ? ", " : ""); cout << "}"; return os;}
template<typename T1,typename T2>ostream& operator << (ostream& os, map<T1,T2> mp){cout << "{"; for(auto itr = mp.begin(); itr != mp.end(); itr++) cout << "(" << (itr->first) << ", " << (itr->second) << ")" << (next(itr)!=mp.end() ? "," : ""); cout << "}"; return os; }

void dump_func(){DUMPOUT << endl;}
template <class Head, class... Tail>void dump_func(Head&& head, Tail&&... tail){ DUMPOUT << head; if (sizeof...(Tail) == 0) { DUMPOUT << " "; } else { DUMPOUT << ", "; } dump_func(std::move(tail)...);}
template<class T> inline bool chmax(T& a,T const& b){if(a>=b) return false; a=b; return true;}
template<class T> inline bool chmin(T& a,T const& b){if(a<=b) return false; a=b; return true;}

using ll = long long;
using P = pair<int,int>;
using Pl = pair<ll,ll>;
using vi = vector<int>;
using vvi = vector<vi>;
using vl = vector<ll>;
using vvl = vector<vl>;
using vp = vector<Pl>;
using vvp = vector<vp>;

const int INF = 1<<29;
const long long LINF=1LL<<59;


void solve(long long A, long long B){
  cout << max(max(A+B,A-B),A*B) << endl;
}

int main(){
  std::cout << std::fixed << std::setprecision(15);
  long long A;
  scanf("%lld",&A);
  long long B;
  scanf("%lld",&B);
  solve(A, B);
  return 0;
}


Measured memory_bytes: 256
/*input
10
8 5
10 8
6 5
1 5
4 8
2 10
3 6
9 2
1 7
*/

#include <bits/stdc++.h>

using namespace std;
using ll = long long;

/********************* MODULAR ARITHMETIC *******************************/

ll MOD = 1000000007;

void mod(ll &a){ if(a > MOD) a %= MOD; }
ll add(ll a, ll b) { a += b; mod(a); return a; }
ll mul(ll a, ll b) { mod(a); mod(b); a *= b; mod(a); return a; }
ll sub(ll a, ll b) { mod(a); mod(b); a -= b; a += MOD; mod(a); return a; }

ll powr(ll a, ll b) {
  ll x = 1LL;
  while(b) {
    if(b & 1) x = mul(x, a);
    a = mul(a, a), b >>= 1;
  }
  return x;
}

ll inv(ll a) { return powr(a, (MOD - 2)); }

/************************************************************************/

const int N = 1e5 + 10;
vector < int > v[N];
ll dp[N][3];

ll dfs(int s, int p, int color)
{
	if(dp[s][color] > -1) {
		return dp[s][color];
	}

	ll ans = 1;
	for(auto x: v[s]) {
		if(x == p) continue;
		if(color == 0) {
			ans = mul(ans, dfs(x, s, 1));
		} else {
			ll a = mul(ans, dfs(x, s, 0));
			ll b = mul(ans, dfs(x, s, 1));
			ans = add(a, b);
		}
	}
	return dp[s][color] = ans;
}

int main()
{
  int n;
  cin >> n;
  for(int i = 1; i < n; i ++) {
  	int x, y;
  	cin >> x >> y;
  	v[x].push_back(y);
  	v[y].push_back(x);
  }

 
	memset(dp, -1, sizeof(dp));
	ll a = dfs(1, 0, 0);
	ll b = dfs(1, 0, 1);
	cout << add(a, b);
  return 0;
}

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

typedef pair<int,int>P;

int n,m,k,a[111],b[111],ans;

void dfs(int d,int sum,vector<int> v){
  if(sum>k)return;
  if(d==n){
    vector<P>V;
    r(i,v.size())V.push_back(P(a[v[i]],b[v[i]]));
    sort(V.begin(),V.end(),greater<P>());
    int N=m,cnt=0;
    r(i,V.size()){
      if(N<=0)break;
      int cost=V[i].first;
      int lim=V[i].second;
      int x=min(N,lim);
      cnt+=x*cost;
      N-=lim;
    }
    ans=max(ans,cnt+max(N,0));
  }
  else{
    dfs(d+1,sum,v);
    v.push_back(d);
    dfs(d+1,sum+1,v);
  }
}

int main(){
  cin>>n>>m>>k;
  r(i,n)cin>>a[i];
  r(i,n)cin>>b[i];
  vector<int>v;
  dfs(0,0,v);
  cout<<ans<<endl;
}


Measured memory_bytes: 3160
#include <bits/stdc++.h>
using namespace std;
typedef unsigned long long int ull;
typedef long long int ll;
typedef long double ld;
#define mod 1000000007
#define pub(a) push_back(a)
#define mp(a,b) make_pair(a,b)
#define getl(s) getline(cin,s);

int main(){
  ios::sync_with_stdio(0);
  cin.tie(0);
  int x;
  cin>>x;
  cout<<(x>=30?"Yes":"No");
  return 0;
}


Measured memory_bytes: 3656
def main():
    N = int(input())
    a = list(map(int, input().split()))
    #print(a)
    
    cnt = 0
    for i in a:
        while i % 2 == 0:
            i //= 2
            cnt += 1
    print(cnt)
    
if __name__ == '__main__':
    main()

Measured memory_bytes: 4148
#include <bits/stdc++.h>
#pragma GCC optimize("Ofast")
#pragma GCC optimize("unroll-loops")
#pragma GCC target("tune=native")
using namespace std;
typedef long long ll;
typedef long double ld;

const ll INF = 1000000000000000000LL;
const int MAX_N = 3005;
const int K = 3;

int n, m, k;
ll v[MAX_N][MAX_N];
ll dp[MAX_N][MAX_N][K + 1];

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

	cin >> n >> m >> k;
	for (int i = 0; i < n; i++)
		for (int j = 0; j < m; j++)
			v[i][j] = -INF;
	for (int i = 0; i < k; i++)
	{
		int r, c;
		cin >> r >> c;
		r--; c--;
		cin >> v[r][c];
	}

	for (int i = 0; i < n; i++)
		for (int j = 0; j < m; j++)
			for (int kk = 0; kk <= K; kk++)
				dp[i][j][kk] = -INF;
	dp[0][0][0] = 0LL;
	dp[0][0][1] = v[0][0];

	for (int i = 0; i < n; i++)
		for (int j = 0; j < m; j++)
			for (int kk = 0; kk <= K; kk++)
			{
				if (i != n - 1)
				{
					dp[i + 1][j][0] = max(dp[i + 1][j][0], dp[i][j][kk]);
					dp[i + 1][j][1] = max(dp[i + 1][j][1], dp[i][j][kk] + v[i + 1][j]);
				}
				if (j != m - 1)
				{
					dp[i][j + 1][kk] = max(dp[i][j + 1][kk], dp[i][j][kk]);
					if (kk != K)
						dp[i][j + 1][kk + 1] = max(dp[i][j + 1][kk + 1], dp[i][j][kk] + v[i][j + 1]);
				}
			}

	ll result = 0LL;
	for (int kk = 0; kk <= K; kk++)
		result = max(result, dp[n - 1][m - 1][kk]);
	cout << result << '\n';

	return 0;
}

Measured memory_bytes: 355680
#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 repi(i, a, b) for (int i = (a); i < int(b); i++)
#define all(a) (a).begin(), (a).end()
#define bit(b) (1ull << (b))
#define uniq(v) (v).erase(unique(all(v)), (v).end())

using namespace std;
using i32 = int;
using i64 = long long;
using f64 = double;
using vi32 = vector<i32>;
using vi64 = vector<i64>;
using vf64 = vector<f64>;
using vstr = vector<string>;

template<typename T, typename S> void amax(T &x, S y) { if (x < y) x = y; }
template<typename T, typename S> void amin(T &x, S y) { if (y < x) x = y; }

int dp[100010][21];

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout << fixed << setprecision(16);
  int n;
  cin >> n;
  vi64 x(n);
  rep(i, n) cin >> x[i];
  int l, q;
  cin >> l >> q;
  rep(i, n) dp[i][0] = upper_bound(all(x), x[i] + l) - x.begin() - 1;
  rep(i, 20) rep(j, n) dp[j][i + 1] = dp[dp[j][i]][i];
  rep(_, q) {
    int a, b;
    cin >> a >> b;
    a--; b--;
    if (a > b) swap(a, b);
    int ans = 1;
    rrep(i, 20) if (dp[a][i] < b) {
      a = dp[a][i];
      ans += 1 << i;
    }
    cout << ans << endl;
  }
  return 0;
}


Measured memory_bytes: 9856
#include<iostream>
#include<algorithm>
#include<vector>
using namespace std;
#define REP(i,b,n) for(int i=b;i<n;i++)
#define rep(i,n)   REP(i,0,n)

typedef long long ll;
const ll mod =  1000000007;

ll solve(int n,int t,vector<int> &in){
  ll ret = 1;
  sort(in.begin(),in.end());
  //rep(i,in.size())cout << in[i] <<" " ;cout << endl;
  for(int i=in.size()-1;i>=0;i--){
    int tar = in[i] + t;
    int tmp = upper_bound(in.begin(),in.end(),tar)-in.begin()-1-i;
    //cout << in[i] <<" " << tar <<" " << tmp << endl;
    ret = ret * (tmp+1);
    ret %= mod;
  }
  return ret;
}

main(){
  int n,t;
  while(cin>>n>>t && n){
    vector<int> in(n);
    rep(i,n)cin>>in[i];
    cout << solve(n,t,in) << endl;
  }
  return 0;
}

Measured memory_bytes: 1248
n = gets.chomp.to_i
ishi = gets.chomp
l = 0
r = n-1
cnt = 0
while l < r
	if ishi[l] == "R"
		l += 1
		next 
	elsif ishi[r] == "W"
		r -= 1
		next 
	end

	ishi[l] = "R"
	ishi[r] = "W"
	cnt += 1
	l += 1
	r -= 1
end
puts cnt

Measured memory_bytes: 14656
#include <stdio.h>
#include <math.h>
#define LL long long
using namespace std;
LL N;
int main()
{
	scanf("%lld",&N);
	for(LL I=int(sqrt(N));I>=1;I--)
	{
		if(I*I<=N)
		{
			printf("%lld",I*I);
			return 0;
		}
	}
	return 0;
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
map<char,bool> arare;
int main(){

  int N;
  cin >> N;
  vector<int> cards(N);
  for(int i = 0;i < N;i++)cin >> cards[i];

  sort(cards.begin(),cards.end());
  reverse(cards.begin(),cards.end());

  int A = 0;
  int B = 0;

  for(int i = 0;i < N;i++){
    if(i % 2 == 0)A+=cards[i];
    else B+=cards[i];
  }

  cout << A-B << endl;

}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
const int base=1e9+7;
string s;long long n,kq,x,dem;
int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    //freopen("in.inp", "r", stdin);
    //freopen("ou.out", "w", stdout);
    cin>>n>>s;
    kq=1;
    x=0;dem=0;
    for (long long i=2*n-1;i>=0;i--)
    {
        if (i%2&&s[i]=='B') x++;
        else if (i%2==0&&s[i]=='W') x++;
        else {kq=(kq*x)%base; x--;dem++;}

    }
    if (dem!=n) cout<<0;
    else
    {
        for (int i=2;i<=n;i++) kq=(kq*i)%base;
        cout<<kq;
    }

    return 0;
}


Measured memory_bytes: 720
#include <iostream>
#include <sstream>
#include <iomanip>
#include <algorithm>
#include <functional>
#include <iterator>
#include <numeric>
#include <cstdint>
#include <cmath>
#include <bitset>
#include <string>
#include <list>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <map>

#define N_TIMES(i, n)     for ( uint64_t i = 0;     i <  n; ++i )
#define N_TIMES_REV(i, n) for (  int64_t i = n - 1; i >= 0; --i )

template<typename T> using maximum_heap = std::priority_queue<T, std::vector<T>, std::less<T>>;
template<typename T> using minimum_heap = std::priority_queue<T, std::vector<T>, std::greater<T>>;

template<typename T>
std::istream& operator>>(std::istream &is, std::vector<T> &v)
{
  for (typename std::vector<T>::size_type i = 0; i < v.size(); ++i) {
    is >> v[i];
  }  
  return is;
}

using namespace std;

const uint64_t M = 41;

int main()
{
  uint64_t N, K;
  cin >> N >> K;

  vector<uint64_t> A(N);
  cin >> A;

  auto simulate = [&](const vector<uint64_t> &a) {
    vector<int64_t> b(N + 1, 0);
    N_TIMES(n, N) {
      pair<int64_t, int64_t> range(
        static_cast<int64_t>(n) - a[n], 
        static_cast<int64_t>(n) + a[n]
      );
      range.first  = max(range.first,  static_cast<int64_t>(0));
      range.second = min(range.second, static_cast<int64_t>(N - 1));

      ++b[range.first];
      --b[range.second + 1];
    }

    uint64_t t = 0;
    vector<uint64_t> c(N, 0);
    N_TIMES(n, N) { t += b[n]; c[n] = t; }
    return c;
  };

  vector<uint64_t> B = A;
  N_TIMES(k, min(K, M)) {
    B = simulate(B);
  }

  N_TIMES(n, N) {
    cout << B[n];
    if (n + 1 < N) { cout << ' '; }
  }
  cout << endl;

  return 0;
}

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

int main(){
int N,K,P,A;
cin>>N;
for(int i=0;i<N;i++){
cin>>K>>P;
if(K<=P){
	A=K;
}
if(K%P==0&&K!=P){
A=P;

}
if(K%P!=0&&K!=P){
A=K%P;
}
cout<<A<<endl;
}

return 0;

}

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


int main()
{
    int n;
    int mochi[101];
    int num[101] = {0};
    int cnt = 0;
    cin >> n;
  

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

    for(int i = 0; i < n; i++){
        num[mochi[i]]++;
    }

    for(int i = 1; i <= 100; i++){
        if(num[i]){
            cnt++;
        }
    }
    cout << cnt << endl;
}

Measured memory_bytes: 256