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

int a[50], b[50], c[50];
int dp[50][500][500];
const int INF = 1000000007;
int main(){
    int n, ma, mb;
    cin >> n >> ma >> mb;
    for(int i = 0; i < n; i++) cin >> a[i] >> b[i] >> c[i];
    for(int i = 0; i <= n; i++){
        for(int j = 0; j < 500; j++){
            for(int k = 0; k < 500; k++){
                dp[i][j][k] = INF;
            }
        }
    }
    dp[0][0][0] = 0;
    for(int i = 0; i < n; i++){
        for(int j = 0; j < 500; j++){
            for(int k = 0; k < 500; k++){
                if(dp[i][j][k] == INF) continue;
                dp[i+1][j][k] = min(dp[i+1][j][k], dp[i][j][k]);
                dp[i+1][j+a[i]][k+b[i]] = min(dp[i+1][j+a[i]][k+b[i]], dp[i][j][k] + c[i]);
            }
        }
    }
    int ans = INF;
    for(int i = 1; i < 500; i++){
        for(int j = 1; j < 500; j++){
            if(i * mb == j * ma) ans = min(ans, dp[n][i][j]);
        }
    }
    cout << (ans == INF ? -1 : ans) << endl;
    return 0;
}

Measured memory_bytes: 41216
import std.stdio;
import std.string;
import std.format;
import std.conv;
import std.typecons;
import std.algorithm;
import std.functional;
import std.bigint;
import std.numeric;
import std.array;
import std.math;
import std.range;
import std.container;
import std.concurrency;
import std.traits;
import std.uni;
import std.regex;
import core.bitop : popcnt;
alias Generator = std.concurrency.Generator;

enum long INF = long.max/5;

void main() {
  long N = 3;
  long K;
  scanln(K);

  long ans = 0;
  long[] zs = new long[K+1];
  foreach(x; 1..K+1) {
    long y = K.floor(x);
    ans += (x - zs[x]) * y^^N;
    foreach(i; 2..K.floor(x)+1) {
      zs[x*i] += x - zs[x];
    }
  }
  ans.writeln;
}

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


void times(alias fun)(long n) {
  // n.iota.each!(i => fun());
  foreach(i; 0..n) fun();
}
auto rep(alias fun, T = typeof(fun()))(long n) {
  // return n.iota.map!(i => fun()).array;
  T[] res = new T[n];
  foreach(ref e; res) e = fun();
  return res;
}

T ceil(T)(T x, T y) if (isIntegral!T || is(T == BigInt)) {
  // `(x+y-1)/y` will only work for positive numbers ...
  T t = x / y;
  if (y > 0 && t * y < x) t++;
  if (y < 0 && t * y > x) t++;
  return t;
}

T floor(T)(T x, T y) if (isIntegral!T || is(T == BigInt)) {
  T t = x / y;
  if (y > 0 && t * y > x) t--;
  if (y < 0 && t * y < x) t--;
  return t;
}

ref T ch(alias fun, T, S...)(ref T lhs, S rhs) {
  return lhs = fun(lhs, rhs);
}
unittest {
  long x = 1000;
  x.ch!min(2000);
  assert(x == 1000);
  x.ch!min(3, 2, 1);
  assert(x == 1);
  x.ch!max(100).ch!min(1000); // clamp
  assert(x == 100);
  x.ch!max(0).ch!min(10); // clamp
  assert(x == 10);
}

mixin template Constructor() {
  import std.traits : FieldNameTuple;
  this(Args...)(Args args) {
    // static foreach(i, v; args) {
    foreach(i, v; args) {
      mixin("this." ~ FieldNameTuple!(typeof(this))[i]) = v;
    }
  }
}

void scanln(Args...)(auto ref Args args) {
  enum sep = " ";
  enum n = Args.length;
  enum fmt = n.rep!(()=>"%s").join(sep);

  string line = readln.chomp;
  static if (__VERSION__ >= 2074) {
    line.formattedRead!fmt(args);
  } else {
    enum argsTemp = n.iota.map!(
      i => "&args[%d]".format(i)
    ).join(", ");
    mixin(
      "line.formattedRead(fmt, " ~ argsTemp ~ ");"
    );
  }
}

// fold was added in D 2.071.0
static if (__VERSION__ < 2071) {
  template fold(fun...) if (fun.length >= 1) {
    auto fold(R, S...)(R r, S seed) {
      static if (S.length < 2) {
        return reduce!fun(seed, r);
      } else {
        return reduce!fun(tuple(seed), r);
      }
    }
  }
}

// popcnt with ulongs was added in D 2.071.0
static if (__VERSION__ < 2071) {
  ulong popcnt(ulong x) {
    x = (x & 0x5555555555555555L) + (x>> 1 & 0x5555555555555555L);
    x = (x & 0x3333333333333333L) + (x>> 2 & 0x3333333333333333L);
    x = (x & 0x0f0f0f0f0f0f0f0fL) + (x>> 4 & 0x0f0f0f0f0f0f0f0fL);
    x = (x & 0x00ff00ff00ff00ffL) + (x>> 8 & 0x00ff00ff00ff00ffL);
    x = (x & 0x0000ffff0000ffffL) + (x>>16 & 0x0000ffff0000ffffL);
    x = (x & 0x00000000ffffffffL) + (x>>32 & 0x00000000ffffffffL);
    return x;
  }
}


Measured memory_bytes: 2856
import sys

def I(): return int(sys.stdin.readline())
def MI(): return map(int, sys.stdin.readline().split())
def LMI(): return list(map(int, sys.stdin.readline().split()))
MOD = 10 ** 9 + 7
INF = float('inf')


def digsum(num):
    ans = 0
    while num > 0:
        p, q = divmod(num, 10)
        num = p
        ans += q
    return ans

N = I()
ans = INF
for i in range(1, N // 2 + 1):
    ans = min(ans, digsum(i) + digsum(N - i))
print(ans)


Measured memory_bytes: 40940
N,Y = map(int,input().split())
for i in range(N+1):
  for k in range(N+1):
    if(N - (i + k) < 0):
      pass
    else:
      tmp = 10000 * i + 5000 * k + ((N - (i + k)) * 1000)
      if(tmp == Y):
        print(str(i),str(k),str(N-(i+k)))
        exit()
print("-1 -1 -1")

Measured memory_bytes: 3064
#include<iostream>
using namespace std;
int main()
{int a;
cin>>a;
if(a<105)cout<<"0";
else if(a<135)cout<<"1"<<endl;
else if(a<165)cout<<"2"<<endl;
else if(a<189)cout<<"3"<<endl;
else if(a<195)cout<<"4"<<endl;
else cout<<"5"<<endl;
return 0;}

Measured memory_bytes: 256
#include<cstdio>
#include<algorithm>
#include<string>
#include<iostream>


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

using namespace std;



char memo[1<<24];

int di[25][4];
int ma;
int n;

const int X=0;
const int Y=1;
const int R=2;
const int C=3;



void solve(int p,int score){
	if(memo[p]==1)return;
	
	if(ma<score)ma=score;
	
	int kouho[4][6];
	int kouhon[4];
	int i,j,k;
	bool f;
	
	//fill(kouhon,kouhon+4,0);
	kouhon[0]=kouhon[1]=kouhon[2]=kouhon[3]=0;
	
	rep(i,n){
		f=true;
		//for(j=0;j<i;j++){
		if(p&(1<<i))continue;
		
		rep(j,i){
			if(p&(1<<j))continue;
			
			if(i==j)continue;
			//printf("(i,j)=(%d,%d)  %d %d \n",i,j,(di[i][X]-di[j][X])*(di[i][X]-di[j][X])+(di[i][Y]-di[j][Y])*(di[i][Y]-di[j][Y]),(di[i][R]+di[j][R])*(di[i][R]+di[j][R]));
			
			if(
				(di[i][X]-di[j][X])*(di[i][X]-di[j][X])+(di[i][Y]-di[j][Y])*(di[i][Y]-di[j][Y])<(di[i][R]+di[j][R])*(di[i][R]+di[j][R])//2乗距離
			){
				//puts("false");
				f=false;
				break;
			}
		}
		if(f){
			kouho[di[i][C]][kouhon[di[i][C]]++]=i;
		}
	}
	
	//printf("kouhon[0]=%d\n",kouhon[0]);
	
	rep(i,4){
		if(kouhon[i]<2)continue;
		//int bp=p;
		rep(j,kouhon[i]){
			for(k=j+1;k<kouhon[i];k++){
				solve(p|(1<<kouho[i][j])|(1<<kouho[i][k]),score+2);
			}
		}
	}
	
	memo[p]=1;
}


int main(){
	
	
	int i;
	int x,y,r,c;
	
	
	while(true){
		
		scanf("%d",&n);
		if(n==0)return 0;
		
		rep(i,n){
			scanf("%d %d %d %d",&di[i][0],&di[i][1],&di[i][2],&di[i][3]);
			di[i][C]--;
		}
		
		fill(memo,memo+(1<<24),0);
		ma=0;
		
		solve(0,0);
		
		printf("%d\n",ma);
	
	}
}

Measured memory_bytes: 17572
#include <iostream>
#include <iomanip>
#include <utility>
#include <cmath>
#include <random>
#include <vector>
#include <map>
#include <set>
#include <deque>
#include <queue>
#include <stack>
#include <string>
#include <algorithm>
using namespace std;

#define rep(i,n) for(int i = 0; i<n; ++i)
#define REP(i,n) for(int i = 1; i<=n; ++i)
#define all(x) begin(x),end(x)
typedef long long ll;
typedef pair<int,int> ip;
typedef pair<ll,ll> lp;
const int inf = 1001001000;
const ll INF = 1LL<<60;
const int MOD = (int)1e9 + 7;

int H,W;
char m[105][105];
int ans[105][105];
int al[105][105];

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

int main(){
	cin>>H>>W;
	deque<ip> Q;
	REP(i,H){
		REP(j,W){
			scanf(" %c",&m[i][j]);
			ans[i][j] = inf;
			al[i][j] = 0;
		}
	}
	Q.push_front(make_pair(1, 1));
	ans[1][1] = 0;
	while(!Q.empty()){
		int y = Q.front().first, x = Q.front().second;
		Q.pop_front();
		rep(i,2){
			int ty = y+dy[i], tx = x+dx[i];
			if(ty>H || tx>W)continue;
			if(ans[ty][tx] == inf && m[ty][tx]==m[y][x]){
				ans[ty][tx] = ans[y][x];
				Q.push_front(make_pair(ty, tx));	
			}
			if(ans[ty][tx] == inf && m[ty][tx]!=m[y][x]){
				ans[ty][tx] = ans[y][x]+1;
				Q.push_back(make_pair(ty, tx));
			}
		}
	}
	int res = ans[H][W];
	if(m[1][1] == '#')res++;
	if(m[H][W] == '#')res++;
	cout<<res/2<<"\n";
	return 0;
}


Measured memory_bytes: 384
import java.util.Scanner;

public class Main {

  public static void main(String[] args) {
    Scanner scanner = new Scanner(System.in);

    int A = scanner.nextInt();
    int B = scanner.nextInt();
    int C = scanner.nextInt();
    int X = scanner.nextInt();

    int total = 0;
    for (int i = 0; i <= A; i++) {
      for (int j = 0; j <= B; j++) {
        for (int k = 0; k <= C; k++) {
            if ( i*500 + j*100 + k*50 == X) {
              total++;
            }
        }
      }
    }
    System.out.println(total);
  }
}

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

#define rep(i,s,n) for(ll i = (s); i < (n); i++)
#define rep0(i,n) rep(i,0,n)
#define rep1(i,n) rep(i,1,n+1)
#define repR(i,s,n) for(ll i = (n-1); i >= (s); i--)
#define repR0(i,n) repR(i,0,n)
#define repR1(i,n) repR(i,1,n+1)

#define BR "\n"
#define SP " "
#define SHOW(x) for(int i = 0; i < x.size(); i++) { cout << x[i] << SP; } cout << BR;
#define SHOW2(x) for(int j = 0; j < x.size(); j++) { SHOW(x[j]); } cout << BR;
#define fcout cout << fixed << setprecision(18)

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

  vector<ll> H(N);

  rep0(i, N) cin >> H[i];

  int ans = 0, temp = 0;
  repR(i, 1, N) {
    if (H[i-1] >= H[i]) {
      temp++;
    } else {
      temp = 0;
    }
    ans = max(ans, temp);
  }

  cout << ans;
  return 0;
}

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

int main(){
	
	int n; cin>>n;
	vector<int> d(n);
	for(auto &i:d) cin>>i;
	sort(d.begin(),d.end());
	int b = d.at(n/2);
	int a = d.at(n/2-1);
	cout << b-a << endl;
	
}

Measured memory_bytes: 640
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define double long double
#define rep(i,n) for(int i=0;i<n;i++)
#define mod 1000000007 //10^9+7
#define INF 1000000000000 //10^12
#define P pair<int,int>
int gcd(int a,int b){
    if(a%b==0)return b;
    return gcd(b,a%b);
}
int lcm(int a,int b){
    return a*b/gcd(a,b);
}
int lg(int a){
    int b=a;
    int cnt=0;
    while(b%2==0){
        b/=2;
        cnt++;
    }
    return cnt;
}
int n,m;
int a[200000];
int mul=1;
bool ans=true;
vector<int>vec;
signed main(){
    cin>>n>>m;
    rep(i,n){
        cin>>a[i];
        if(i>0&&lg(a[i])!=lg(a[i-1])){
            ans=false;
        }
        else{
            vec.push_back(a[i]/2);
        }
    }
    sort(vec.begin(),vec.end());
    if(ans==false)cout<<0<<endl;
    else{
        vec.erase(unique(vec.begin(),vec.end()),vec.end());
        int l=vec.size();
        rep(i,l){
            mul=lcm(vec[i],mul);
        }
        int val=((m/mul)+1)/2;
        if(mul>m)val=0;
        cout<<val<<endl;
    }
    return 0;
}


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

int main() {
    string W;
    cin>>W;
    transform (W.begin (), W.end (), W.begin (),::toupper);
    vector<string> S(1000);
    int cnt=0;
    for(int i=0;i<1000;i++){
        cin>>S.at(i);
        transform (S.at(i).begin(),S.at(i).end(),S.at(i).begin(),::toupper);
        if(S.at(i)==W) cnt++;
    }
    cout<<cnt<<endl;
    
}



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

const long long int MOD=1e9+7;

using namespace std;

int main(){
    long long int s, cnt;
    cin >> s;

    long long a1,b1,a2,b2;
    a1 = int(sqrt(s));
    b2 = a1;
    if(s > a1*b2){
        b2++;
    }
    if(s > a1*b2){
        a1++;
    }
    long long rest=b2*a1-s;
    if(rest==0){
        b1=0;
        a2=0;
    }
    else{
        b1=rest;
        a2=1;
    }
    cout << 0 << ' ' << 0 << ' ';
    cout << a1 << ' ' << b1 << ' ';
    cout << a2 << ' ' << b2 << endl;;

}

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

int main() {
	string s, t;
	cin >> s >> t;
	if (s.length() < t.length()) {
		cout << "UNRESTORABLE" << endl;
	} else {
		int h = -1;
		for (int i = s.length() - t.length(); i >= 0; i--) {
			int k = 0;
			for (int j = 0; j < t.length(); j++) {
				if (s[i + j] == '?' || s[i + j] == t[j]) {
					k++;
				}
			}
			if (k == t.length()) {
				h = i;
				break;
			}
		}
		if (h == -1) {
			cout << "UNRESTORABLE" << endl;
		} else {
			for (int i = 0; i < t.length(); i++) {
				s[h + i] = t[i];
			}
			for (int i = 0; i < s.length(); i++) {
				if (s[i] == '?') {
					s[i] = 'a';
				}
			}
			cout << s << endl;
		}
	}
	return 0;
}


Measured memory_bytes: 256
#include<stdio.h>
int main(){
  long long  n,m,l,i,j,k,a[101][101],b[101][101],c[101][101];

  for(i = 0;i < 101;i++){
    for(j = 0;j < 101;j++){
      a[i][j] = 0;
      b[i][j] = 0;
      c[i][j] = 0;
    }
  }

  scanf("%lld %lld %lld",&n,&m,&l);

  for(i = 0;i < n;i++){
    for(j = 0;j < m;j++){
      scanf("%lld",&a[i][j]);
    }
  }
 for(i = 0;i < m;i++){
    for(j = 0;j < l;j++){
      scanf("%lld",&b[i][j]);
    }
  }

 for(i = 0;i < n;i++){
   for(j = 0;j < l;j++){
     for(k = 0;k < m;k++){
       c[i][j] = c[i][j] + a[i][k] * b[k][j];
     }
   }
 }

 for(i = 0;i < n;i++){
   for(j = 0;;j++){
     printf("%lld",c[i][j]);
     if(j >= l-1)break;
     printf(" ");
   }
   printf("\n");
 }

  return 0;
}

Measured memory_bytes: 844
#include <bits/stdc++.h>
#include <math.h>
#define _GLIBCXX_DEBUG
#define _LIBCPP_DEBUG 0

using namespace std;
#define ll long long
#define rep(i,n) for (int i = 0; i < n; i++)
#define rrep(i,n) for (int i = n-1; i >= 0; i--)
#define MOD (1000000007)
#define vi vector<int>
#define vl vector<ll>
#define vvi vector<vi>
#define vvl vector<vl>
#define pii pair<int, int>
#define pb push_back

#define mp make_pair
#define all(a) (a).begin(),(a).end()

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

ll gcd(ll a, ll b) {
    if (b == 0) return a;
    else return gcd(b, a % b);
}

ll keta(ll n){
  string s = to_string(n);
  ll num = s.size();
  return num;
}

const ll INF = 1LL << 60;

const int dh[4] = {1,0,-1,0};
const int dw[4] = {0,1,0,-1};


int main(){
  int n,W; cin >> n >> W;
  vl weight(n),value(n);
  rep(i,n) cin >> weight[i] >> value[i];

  ll dp[n+1][W+1];
  memset(dp, 0LL, sizeof(dp));
  rep(i,n) rep(w,W+1) {
    dp[i+1][w] = dp[i][w];
    if(w >= weight[i]) chmax(dp[i+1][w], dp[i][w-weight[i]] + value[i]);
  }

  cout << dp[n][W] << endl;
}

Measured memory_bytes: 79104
N, K = [int(v) for v in input().split()]
X = [int(v) for v in input().split()]

res = 1e14
for l in range(N - K + 1):
    r = l + K - 1
    tmp = abs(X[r] - X[l])
    res = min(res, tmp + min(abs(X[r]), abs(X[l])))
print(res)

Measured memory_bytes: 14252
// -----------------------------------
// Author     : MatsuTaku
// Affiliation: Tokushima University
// Country    : Japan
// Date       : 04/08/2020
// -----------------------------------

#include <bits/stdc++.h>

using namespace std;
using ll = long long;

template <typename T, T MOD>
class modint {
 private:
  T val_;

 public:
  constexpr modint() : val_(0) {}
  constexpr modint(T v) : val_(v%MOD) {}
  constexpr modint& operator=(T v) { val_ = v%MOD; return *this; }

  constexpr T val() const { return val_; }
  constexpr modint operator+(modint x) const { return (val() + x.val())%MOD; }
  constexpr modint operator+=(modint x) { return *this = *this + x; }
  constexpr modint operator++() { return *this += 1; }
  constexpr modint operator++(int) { modint c = *this; ++(*this); return c; }
  constexpr modint operator-(modint x) const { return (val() + MOD - x.val())%MOD; }
  constexpr modint operator-=(modint x) { return *this = *this - x; }
  constexpr modint operator--() { return *this -= 1; }
  constexpr modint operator--(int) { modint c = *this; --(*this); return c; }
  constexpr modint operator*(modint x) const { return (val() * x.val())%MOD; }
  constexpr modint operator*=(modint x) { return *this = *this * x; }
  friend constexpr modint pow(modint x, T p) {
    modint t = 1;
    modint u = x;
    while (p) {
      if (p & 1)
        t *= u;
      u *= u;
      p >>= 1;
    }
    return t;
  }
  constexpr modint operator/(modint x) const { return *this * pow(modint{x}, MOD-2); }
  constexpr modint operator/=(modint x) { return *this = *this / x; }

  constexpr bool operator==(modint x) const { return val() == x.val(); }
  constexpr bool operator!=(modint x) const { return val() != x.val(); }
  constexpr bool operator<(modint x) const { return val() < x.val(); };
  constexpr bool operator<=(modint x) const { return val() <= x.val(); };
  constexpr bool operator>(modint x) const { return val() > x.val(); };
  constexpr bool operator>=(modint x) const { return val() >= x.val(); };

  friend std::ostream& operator<<(std::ostream& os, modint x) {
    return os << x.val();
  }
  friend std::istream& operator>>(std::istream& is, modint& x) {
    return is >> x.val_;
  }

};

template <typename T, T MOD, T MAX>
class combination {
 public:
  using mint = modint<T, MOD>;
 private:
  vector<mint> fact_;
  vector<mint> ifact_;

 public:
  constexpr combination() {
    fact_.resize(MAX+1);
    fact_[0] = 1;
    for (size_t i = 1; i <= MAX; ++i) {
      fact_[i] = fact_[i-1] * i;
    }
    ifact_.resize(MAX+1);
    ifact_[MAX] = mint(1)/fact_[MAX];
    for (int i = MAX-1; i >= 0; i--) {
      ifact_[i] = ifact_[i+1] * (i+1);
    }
  }

  mint operator()(T p, T q) const {
    return fact_[p] * ifact_[q] * ifact_[p-q];
  }

};

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

  constexpr ll MOD = 1e9+7;
  using combination = combination<ll, MOD, (ll)2e5>;
  int h,w,a,b; cin>>h>>w>>a>>b;
  combination::mint ans = 0;
  combination cmb;
  for (int y = b; y < w; y++) {
    ans += cmb(h-a-1+y, y) * cmb(w-y-1+a-1, a-1);
  }
  cout << ans << endl;

  return 0;
}


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

int main(){
  int n,m,q;scanf("%d %d %d\n",&n,&m,&q);
  int mp[n+1][n+1]={};
  int l,r;
  fol(i,m){
    scanf("%d %d\n",&l,&r);
    mp[l][r]++;
  }
  int ans = 0;
  for(int i=1;i<n+1;i++){
    for(int j=1;j<n+1;j++){
      mp[i][j]+=mp[i][j-1];
    }
  }
  fol(i,q){
    ans = 0;
    scanf("%d %d\n",&l,&r);
    for(int i=l;i<=r;i++){
      ans+=(mp[i][r]-mp[i][l-1]);
    }
    printf("%d\n",ans);
  }
  return 0;
}


Measured memory_bytes: 1920
#include <stdio.h>
int main()
{
  int cou,a,i;
  while(1){
    scanf("%d",&a);
    if(a==0)break;
    cou=0;
    for(i=2;i<=a/2+1;i++){
      if(i%2==0&&a%i==0)continue;
      if(i%2==0&&((a*1000000)/i)%1000000==500000&a/i>=i/2){
	cou++;
	//printf("%d\n",i);
      }
      if(i%2!=0&&a%i==0&&a/i>=i/2+1){
	cou++;
	//printf("%d\n",i);
      }
      if(i%2!=0&&a%i!=0)continue;
    }
    printf("%d\n",cou);
  }
  return 0;
}

Measured memory_bytes: 1028
#include "bits/stdc++.h"
#define MOD 1000000007
#define INF 11234567890
#define in std::cin
#define out std::cout
#define rep(i,N) for(int i=0;i<N;++i)
typedef long long int LL;

int N, M, A[5123], B[5123];
int low, high, mid;

bool check(int length)
{
	int seek;
	rep(i, M - length + 1)
	{
		auto j = M - length - i;
		if (M - (i + j) < 0) { continue; }
		seek = i;
		rep(k, N)
		{
			if (A[k] == B[seek]) { ++seek; }
			if (seek == M - j) { return true; }
		}
	}
	return false;
}

int main()
{
	in >> N >> M;
	rep(i, N) { in >> A[i]; }
	rep(i, M) { in >> B[i]; }
	
	if (N == 1)
	{
		rep(i, M)
		{
			if (B[i] == A[0])
			{
				low = 1;
				break;
			}
		}
	}
	else if (M == 1)
	{
		rep(i, N)
		{
			if (A[i] == B[0])
			{
				low = 1;
				break;
			}
		}
	}
	else
	{
		low = 0, high = std::min(N, M), mid;
		while (high - low > 1)
		{
			mid = (high + low) / 2;
			if (check(mid)) { low = mid; }
			else { high = mid; }
		}
	}

	out << low << std::endl;
	return 0;
}

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

import itertools
l=list(map(int ,input().split()))

comb=list(itertools.combinations(l,3))
comber=[]
a=[]
kosuu=0
for i in comb:
    a=list(i)
    a.sort()
    comber.append(a)
for i in range(len(comber)):
    if comber[i][2]<comber[i][1]+comber[i][0]:
        if comber[i][0]!=comber[i][1]!=comber[i][2]:
            kosuu+=1
print(kosuu)

Measured memory_bytes: 37096
#include <algorithm>
#include <iostream>
#include <vector>
#include <map>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <chrono>
#include <numeric>

using namespace std;

long long n;
char s[500001];
long long z[500001];
vector<vector<long long>> v;

long long solve(const vector<long long> &a) {
  size_t a_len = a.size();
  long long l, r1, r2, l_prev, r1_prev, r2_prev;
  l_prev = 0;
  r1_prev = 0;
  r2_prev = a[0];
  for (long long i=1;i<(a_len-1);i++) {
    if (a[i] > 1) {
      // l:left pattern O
      l = max(l_prev + a[i] - 1, max(r1_prev, r2_prev));
      // r1:left pattern X, segment length not decrease
      r1 = max(l_prev + a[i], max(r1_prev, r2_prev));
      // r2:left pattern X, segment length decrease
      r2 = max(l_prev, max(r1_prev, r2_prev - 1)) + a[i];
    } else {
      // l:left pattern O
      l = max(l_prev, r1_prev);
      // r1:left pattern X, segment length not decrease
      r1 = max(l_prev + a[i], r2_prev);
      // r2:left pattern X, segment length decrease
      r2 = max(l_prev, r1_prev) + a[i];
    }
    l_prev = l;
    r1_prev = r1;
    r2_prev = r2;
  }
  l = l_prev + a[a_len-1] ;
  r1 = r1_prev;
  r2 = r2_prev;
  return(max(l, max(r1, r2)));
}

int main(){
  cin >> n;
  cin >> s;
  long long l1 = 0;
  long long r1 = 0;
  long long c1 = 0;
  long long ioi = 0;
  long long tot = 0;
  vector<long long> tmpv;
  for (long long i=0;i<n;i++) {
    if (s[i] == '1') {
      c1++;
    } else {
      if (c1==0) {
	if (tmpv.size()>0)
	if (tmpv.size()>1) {
	  tot += solve(tmpv);
	}
	tmpv.clear();
      } else if (c1>0) {
	tmpv.push_back(c1);
      }
      c1 = 0;
    }
  }
  if (c1>0) 
    tmpv.push_back(c1);
  if (tmpv.size() > 1)
    tot += solve(tmpv);
  cout << tot << endl;
}


Measured memory_bytes: 2560
#include<bits/stdc++.h>
using namespace std;
#define pb push_back
#define mp make_pair
#define deb(a,b,c) cout<<#a<<" = "<<(a)<<", "<<#b<<" = "<<(b)<<", "<<#c<<" = "<<(c)<<endl;
 
typedef long long int ll;
typedef string str;
 
ll power(ll x, ll y, ll p) 
{ 
    ll res = 1;     
  
    x = x % p;   
    while (y) 
    { 
        if (y & 1) 
            res = (res*x) % p; 
        y = y>>1;  
        x = (x*x) % p; 
    } 
    return res; 
} 
 
ll nCrModP(ll n, ll r, ll p) 
{ 
    if (!r) 
      return 1; 
  
	ll fac[n+1]; 
   	fac[0] = 1; 
    for (ll i=1 ; i<=n; i++) 
        fac[i] = fac[i-1]*i%p; 
  
    return (fac[n]* power(fac[r], p-2,p) % p * power(fac[n-r], p-2,p) % p) % p; 
}
 
ll gcd(ll a, ll b){ 
    if (a == 0) 
        return b;  
    return gcd(b % a, a);
}
 
void fast(){
	ios::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
}

int main ()
{
	
	ll t,n,m,k,i,j,a,b;
	// cin >> t;
	// while(t--)
	// {
 //        cin >> n;
        str st,s;
 //    }
    cin >> s;
    n=s.size();
    if(s[n-1]=='s')
    	st =s + "es";
    else
    	st =s + "s";
    cout << st << "\n";
    return 0;
}

Measured memory_bytes: 3644
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <cmath>
#include <map>
#include <queue>
#include <iomanip>
#include <set>
#include <tuple>
#define mkp make_pair
#define mkt make_tuple
#define rep(i,n) for(int i = 0; i < (n); ++i)
using namespace std;
typedef long long ll;
const ll MOD=1e9+7;

const ll INF=1e16;
class SegmentTree{
public:

  int n;
  vector<ll> tree;

  SegmentTree(int size){
    n=1;
    while(n<size) n*=2;

    tree.resize(2*n-1,INF);
  }

  SegmentTree(vector<ll> v){
    int vSize=v.size();
    n=1;
    while(n<vSize) n*=2;

    tree.resize(2*n-1,INF);

    for(int i=0;i<vSize;i++) tree[i+n-1]=v[i];
    for(int i=n-2;i>=0;i--) tree[i]=min(tree[2*i+1],tree[2*i+2]);
  }

  void update(int index,ll value){
    index+=n-1;

    tree[index]=value;
    while(index>0){
      index=(index-1)/2;
      tree[index]=min(tree[2*index+1],tree[2*index+2]);
    }
  }

  ll getMin(int a,int b,int k,int l,int r){//[a,b),getMin(a,b,0,0,-1)
    if(r<0) r=n;

    if(r<=a||b<=l) return INF;
    else if(a<=l&&r<=b) return tree[k];
    else{
      ll lval=getMin(a,b,2*k+1,l,(l+r)/2);
      ll rval=getMin(a,b,2*k+2,(l+r)/2,r);
      return min(lval,rval);
    }
  }
};


int N,M;
vector<ll> L,R,C;

int main(){
  cin>>N>>M;
  L.resize(M);
  R.resize(M);
  C.resize(M);
  rep(i,M) cin>>L[i]>>R[i]>>C[i];
  rep(i,M){
    L[i]--;
    R[i]--;
  }

  vector<tuple<ll,ll,ll>> v;
  rep(i,M) v.push_back(mkt(R[i],L[i],C[i]));
  sort(v.begin(),v.end());

  vector<ll> p(N+1,INF);
  p[0]=0;
  SegmentTree seg(p);
  int now=0;
  for(int i=0;i<N;i++){
    ll res=INF;
    while(now<M&&get<0>(v[now])==i){
      auto f=v[now];
      ll b=get<0>(f);
      ll a=get<1>(f);
      ll c=get<2>(f);
      
      ll val=seg.getMin(a,b,0,0,-1);
      if(val==INF){
        now++;
        continue;
      }
      res=min(res,val+c);
      now++;
    }
    if(res!=INF) seg.update(i,res);
  }

  ll ans=seg.getMin(N-1,N,0,0,-1);
  if(ans==INF) cout<<-1<<endl;
  else cout<<ans<<endl;

  return 0;
}


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

int main() {
    int X,A,B,C;
    cin>>X>>A>>B;
    C = A - B;
    if (C > -1) {
        printf("delicious");
    }
    if(C < 0){
        C = C * -1;
        if(-1 < X-C){printf("safe");}
        else{printf("dangerous");}
    }
    
}

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



typedef unsigned long ul;
typedef unsigned long long ull;
typedef long long ll;
typedef vector<ll> vint;
typedef vector< vector<ll> > vvint;
typedef vector< vector< vector<ll> > > vvvint;
typedef vector<string> vstring;
typedef vector< vector<string> > vvstring;
typedef vector<char> vchar;
typedef vector< vector<char> > vvchar;
typedef vector<long double> vdouble;
typedef vector< vector<long double> > vvdouble;
typedef vector< vector< vector<long double> > > vvvdouble;
typedef pair<ll,ll> pint;
typedef vector<pint> vpint;
typedef vector<bool> vbool;

#define rep(i,n) for(ll i=0;i<n;i++)
#define repf(i,f,n) for(ll i=f;i<n;i++)
#define repr(i,n) for(ll i=n-1;i>=0;i--)
#define mp make_pair
#define mt make_tuple
#define pb push_back
#define pf push_front
#define fi first
#define se second
#define ALL(obj) (obj).begin(), (obj).end()
// #define LLONG_MAX 9223372036854775806
#define vmax(vec) *max_element(vec.begin(), vec.end())
#define vmin(vec) *min_element(vec.begin(), vec.end())
#define vsort(vec) sort(vec.begin(), vec.end())
#define vsortgr(vec) sort(vec.begin(), vec.end(), greater<ll>())
#define MOD 1000000007
// #define MOD 998244353
// #define MOD LLONG_MAX
const double PI=3.14159265358979323846;

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 dy[]={0, 0, 1, -1};
int dx[]={1, -1, 0, 0,};




void printv(vint &v){
  for(auto e:v) cout<<e<<" ";
  cout<<endl;
}


int main() {


  cout<<fixed<<setprecision(10);

  ll n,k; cin>>n>>k;
  vint p(n); rep(i,n) cin>>p[i];

  vdouble exp(n);

  rep(i,n){
    exp[i] = 0.5*(p[i]+1);
  }

  vdouble rui(n+1, 0);

  rep(i,n){
    rui[i+1] = rui[i] + exp[i];
  }

  long double ans = 0;

  rep(i,n){
    if(i+k > n) break;

    chmax(ans, rui[i+k] - rui[i]);
  }

  cout<<ans<<endl;

}

//


Measured memory_bytes: 8064
import operator
for e in iter(input,'0'):
    target = [[*map(int,input().split())]for _ in[0]*int(e)]
    s,t = min(target)
    target = {(x - s, y - t) for x, y in target}
    max_tx = max(target)[0]
    b = {tuple(map(int,input().split()))for _ in[0]*int(input())}
    max_sx = max(map(operator.itemgetter(0), b))
    lim_x = max_sx - max_tx
    for x,y in b:
        if x > lim_x:continue
        for u,v in target:
            if (x + u, y + v) not in b:break
        else:
            print(x - s, y - t)
            break


Measured memory_bytes: 6104
program test;
{$mode objfpc}{$H+}{$R+}{$S+}
Uses sysutils,math;
var
	N,i,cnt	:integer;
    d1,d2   :integer;
	ans	    :string;
begin
    readln(N);
	ans:='No';
    cnt:=0;
    for i:=1 to N do
    begin
        readln(d1,d2);
        if (d1=d2) then
        begin
            inc(cnt);
            if (cnt>=3) then
            begin
            	ans:='Yes';
                //break;
            end;
        end
        else cnt:=0;
    end;

    writeln(stdout,ans);
end.

Measured memory_bytes: 1388
#include <stdio.h>

int main(void)
{
	int apoint;
	int bpoint;
	int kaisu;
	int a, b;
	int i;
	
	while(1){
		scanf("%d", &kaisu);
		if(kaisu == 0)    break;
		apoint = 0;
		bpoint = 0;	
		for(i = 0; i < kaisu; i++){
			scanf("%d %d", &a, &b);
			if(a > b)        apoint += (a + b);
			else if(a < b)   bpoint += (a + b);
			else{
				apoint += a; bpoint += b;
			}
		}
	
		printf("%d %d\n", apoint, bpoint);
	}
	
	return 0;
}

Measured memory_bytes: 600
#include"bits/stdc++.h"
#define int long long
#define _overload3(_1,_2,_3,name,...) name
#define _rep(i,n) repi(i,0,n)
#define repi(i,a,b) for(int i=(a);i<(b);++i)
#define rep(...) _overload3(__VA_ARGS__,repi,_rep,)(__VA_ARGS__)
#define itr(i,x) for(auto i=(x).begin();i!=(x).end();++i)
#define All(x) (x).begin(),(x).end()
using namespace std;
typedef pair<int,int> P;
const int mod=1000000007;
int gcd(int x,int y){return y?gcd(y,x%y):x;}
int lcm(int x,int y){return x*y/gcd(x,y);}
signed main(){
	int n;
	cin>>n;
	vector<int> a(n);
	rep(i,n) cin>>a[i];
	sort(All(a));
	cout<<a.back()-a[0]<<endl;
}


Measured memory_bytes: 256
S = input()+"T"
X,Y = map(int,input().split())
dX0,dX,dY,dr,dc = 0,[],[],"x",0
for s in S:
    if s == "F":
        dc += 1
    elif s == "T":
        if dr == "x":
            dr = "y"
            dX.append(dc)
        else:
            dr = "x"
            dY.append(dc)
        dc = 0
dX0,dX = dX[0],dX[1:]

canX,canY = [dX0],[0]
for dx in dX:
    t = []
    for cx in canX:
        t.append(cx+dx)
        t.append(cx-dx)
    canX = list(set(t))

for dy in dY:
    t = []
    for cy in canY:
        t.append(cy+dy)
        t.append(cy-dy)
    canY = list(set(t))

print("Yes" if X in canX and Y in canY else "No")

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


int main(){
    int n, q;
    string s;
    cin >> n >> q >> s;
    vector<int> l(q),r(q);
    rep(i,q) cin >> l[i] >> r[i];
    vector<int> mem(n+1);

    rep(i,n){
        if(s[i]=='A' && s[i+1] == 'C') mem[i+1] = mem[i] + 1;
        else mem[i+1] = mem[i];
    }

    rep(i,q){
        cout << mem[r[i]-1] - mem[l[i]-1] << endl;
    }

}

Measured memory_bytes: 2176
N, M = map(int, input().split())
r = list([None]*N)
for i in range(M):
    s, c = map(int, input().split())
    if r[s-1] is not None and r[s-1] != c:
        print("-1")
        exit()
    r[s-1] = c

if N > 1 and r[0] == 0:
        print("-1")
        exit()

for i in range(len(r)):
    if r[i] is None:
        if N > 1 and i == 0:
            r[i] = 1
        else:
            r[i] = 0

print("".join(map(str, r)))

Measured memory_bytes: 3064
#!/usr/bin/ruby
# -*- coding: utf-8 -*-
=begin
ALDS1_4-C3
Search - Dictionary
Search III

Constraints
    A string consists of 'A', 'C', 'G', or 'T'
    1 ??? length of a string ??? 12
    n ??? 1000000
=end

class Main
  def initialize()
    #fh = open("/home/muz/Downloads/x.txt")
    #fh = open("/home/muz/Downloads/ALDS1_4_C_in2.txt")
    #fh = open("/home/muz/Downloads/ALDS1_4_C_in9.txt")
    fh = STDIN

    h = Hash.new
    n = fh.gets.chomp.to_i
    0.upto(n-1) {|i|
      begin
        f=fh.gets.split
      rescue => exe
        abort("not enough command?")
      else
        cmd,op = f
        if cmd == "insert" then
          h[op]=true
        elsif cmd == "find" then
          puts (h.has_key?(op) ? "yes" : "no")
        else
          abort("unknown command:#{cmd}")
        end
      end
    }
  end
end

if $0==__FILE__ then
  Main.new()
end

Measured memory_bytes: 48784
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define zero_pad(num) setfill('0') << std::right << setw(num)
using namespace std;
using ll = long long;
using ld = long double;
using P = pair<ll, ll>;

int main() {
    ll n, d, a;
    cin >> n >> d >> a;
    vector<P> x(n);
    rep(i, n)cin >> x[i].first >> x[i].second;
    sort(x.begin(), x.end());
    rep(i, n)x[i].second = (x[i].second+a-1) / a;
    priority_queue<P, vector<P>, greater<P>> que;
    int sum = x[0].second;
    que.push(make_pair(x[0].first+2*d, -sum));
    ll ans = sum;
    for(int i = 1; i < n; i++){
        if(!que.empty()){
            while(que.top().first < x[i].first){
                P p = que.top();
                que.pop();
                sum += p.second;
                if(que.empty())break;
            }
        }
        x[i].second -= sum;
        if(x[i].second > 0){
            ans += x[i].second;
            que.push(make_pair(x[i].first+2*d, -x[i].second));
            sum += x[i].second;
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 5492
S = list(input())
N = len(S)
counter = [0]*N

# Rについて、左から右に順に数えていく
start = 0
even, odd = 0, 0
for i, s in enumerate(S):
    if s == 'R':
        if (i-start) % 2 == 0:
            even += 1
        else:
            odd += 1
    else:
        if even > 0 or odd > 0:
            if (i-start) % 2 == 0:
                counter[i] += even
                counter[i-1] += odd
            else:
                counter[i] += odd
                counter[i-1] += even
            even, odd = 0, 0
        start = i

# Lについて、右から左に順に数えていく
start = 0
even, odd = 0, 0
for i, s in enumerate(S[::-1]):
    if s == 'L':
        if (i-start) % 2 == 0:
            even += 1
        else:
            odd += 1
    else:
        if even > 0 or odd > 0:
            if (i-start) % 2 == 0:
                counter[N-1-i] += even
                counter[N-i] += odd
            else:
                counter[N-1-i] += odd
                counter[N-i] += even
            even, odd = 0, 0
        start = i

print(' '.join(list(map(str, counter))))

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

using namespace std;

int main() {

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

    int train = 0;
    int taxi = 0;

    train = N * A;

    taxi = B;

    if (train <= taxi) {
        cout << train << endl;
    } else {
        cout << taxi <<endl;
    }

    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <string>
using namespace std;
 
int main() {
  string wather;
  cin >> wather;
 
  // 以下のコメント/* */を消して追記する
  if (wather == "Sunny") {
    cout << "Cloudy" << endl;
  }
  
   if (wather == "Cloudy") {
    cout << "Rainy" << endl;
  }
  
   if (wather == "Rainy") {
    cout << "Sunny" << endl;
  }
}

Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<map>
#include<cstring>
#include<string>
#include<algorithm>
#include<queue>
#include<vector>
#include<stack>
#include<cstdlib>
#include<cctype>
#include<cmath>
#define ll  long long
#define inf 99999999
using namespace std;


int main()
{
    int n,a,b;
    cin>>n>>a>>b;
    cout<<((a*n)<=b?a*n:b)<<endl;
    return 0;
}

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

#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>  // Including tree_order_statistics_node_update

using namespace __gnu_pbds;
using namespace std;

#define sz(a) int((a).size())
#define pb push_back
#define mp make_pair
#define all(c) (c).begin(), (c).end()
#define tr(c, i) for (__typeof((c).begin()) i = (c).begin(); i != (c).end(); i++)
#define present(c, x) ((c).find(x) != (c).end())
#define cpresent(c, x) (find(all(c), x) != (c).end())
#define minei(x) min_element(x.begin(), x.end()) - (x).begin()
#define maxei(x) max_element(x.begin(), x.end()) - (x).begin()
#define LSOne(S) (S & (-S))

#define uns(v) sort((v).begin(), (v).end()), v.erase(unique(v.begin(), v.end()), v.end())
#define acusum(x) accumulate(x.begin(), x.end(), 0)
#define acumul(x) accumulate(x.begin(), x.end(), 1, multiplies<int>());
#define bits(x) __builtin_popcount(x)
#define oo INT_MAX
#define inf 1000000000
#define MAXN 1000007
#define MOD 1000000007

const double pi = acos(-1.0);
const double eps = 1e-11;

typedef long long ll;
typedef pair<int, int> ii;
typedef vector<ii> vii;
typedef vector<int> vi;
typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> indexed_set;

int main() {
    std::ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    int n;
    cin >> n;
    vector<ll> v(n);
    map<ll, ll> cache;
    ll res = 0;
    for (int i = 0; i < n; i++) {
        cin >> v[i];
        res += cache[i - v[i]];
        cache[v[i] + i]++;
    }

    cout << res << endl;

    return 0;
}


Measured memory_bytes: 27480
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); ++i)
int main() {
  int a, b, s = 0;
  cin >> a >> b;
  for (int i = a; i <= b; i++) {
    if (i / 10000 == i % 10 && i / 1000 % 10 == i % 100 / 10) {
      s++;
    }
  }
  cout << s;
}


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

int main() {
  int D,N;
  cin >> D >> N;
  if (D==0) {
	if (N != 100) {
	  cout << N;
	}
	else {
	  cout << 101;
	}
  }
  else if (D==1) {
	if (N != 100) {
	  cout << N*100;
	}
	else {
		cout << 10100;
	}
  }
  else {
	if (N != 100) {
	  cout << N*10000;
	}
	else {
	  cout << 1010000;
		}
	  }
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,a,b) for(int i=int(a);i<int(b);++i)
#define SIZE 100005
#define INF 1000000005LL
#define MOD 1000000007

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

int N;
ll C;
ll x[SIZE];
ll v[SIZE];

ll e[SIZE];
ll y[SIZE];

int main()
{
	cin >> N >> C;
	rep(i,0,N)cin >> x[i] >> v[i];

	ll ans = 0;
	ll es = 0;
	for(int i=N-1;i>=0;i--){
		es += v[i];
		e[i] = max(e[i+1],es-(C-x[i]));
	}
	es = 0;
	rep(i,0,N) ans = max(ans,e[i]);
	rep(i,0,N) {
		es += v[i];
		ans = max(ans,es-x[i]*2+e[i+1]);
	}

	rep(i,0,N) y[i] = C - x[N-1-i];
	reverse(v,v+N);

	es = 0;
	for(int i=N-1;i>=0;i--){
		es += v[i];
		e[i] = max(e[i+1],es-(C-y[i]));
	}
	es = 0;
	rep(i,0,N) ans = max(ans,e[i]);
	rep(i,0,N) {
		es += v[i];
		ans = max(ans,es-y[i]*2+e[i+1]);
	}
	cout << ans << endl;

	return 0;
}


Measured memory_bytes: 3328
#include <iostream>
#include <algorithm>
#include <math.h>
using namespace std;

int main(){
    int N, K;
    cin >> N >> K;
    int l[N];
    for(int i = 0; i < N; i++){
        cin >> l[i];
    }

    sort(l, l+N, greater<int>());

    int ans = 0;
    for(int i = 0; i < K; i++){
        ans += l[i];
    }

    cout << ans << endl;
}

Measured memory_bytes: 256
//   _/                _/                 _/_/_/   _/
//_/_/_/_/   _/_/   _/_/_/_/   _/_/    _/       _/_/
// _/     _/    _/   _/     _/    _/  _/_/_/     _/
//_/     _/    _/   _/     _/    _/  _/    _/   _/
// _/_/   _/_/       _/_/   _/_/      _/_/     _/
#include<iostream>
#include<algorithm>
#include<cmath>
#include<iomanip>
#include<set>
#include<map>
#include<queue>
#include<vector>
using namespace std;
typedef long long ll;
const int MOD=1e9+7;
const double pi=3.14159265358979323846;
const int inf=1e9;
const ll INF=5e18;
typedef pair<int,int> P;
int main() {
  cin.tie(0),cout.tie(0);
  ios::sync_with_stdio(false);
  ll q,h,s,d,n;
  cin >> q >> h >> s >> d >> n;
  cout << n/2*(min({d,2*s,4*h,8*q}))+(n%2?min({s,2*h,4*q}):0) << endl;
}

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

void solve(long long N, std::string S, std::string T)
{
    for (int i = 0; i < N; i++)
    {
        cout << S[i] << T[i];
    }
    cout << endl;
}

// Generated by 1.1.6 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
int main()
{
    long long N;
    scanf("%lld", &N);
    std::string S;
    std::cin >> S;
    std::string T;
    std::cin >> T;
    solve(N, S, T);
    return 0;
}


Measured memory_bytes: 256
import java.util.HashMap;
import java.util.Map;
import java.util.Scanner;
 
public class Main {
 
	public Main() {
		// TODO 自動生成されたコンストラクター・スタブ
	}
 
	public static void main(String[] args){
		Map <Integer,Integer> mapL = new HashMap<Integer,Integer> ();
 
		Scanner sc = new Scanner(System.in);
			// 整数の入力
			int s,index,i,j,k,l;
			String result;
			s = sc.nextInt();
			sc.close();
			i=s%10;
			result="Good";
			for(index=0;index<3;index++) {
				s=(s-i)/10;
				if(i==s%10) {
					result="Bad";
					break;
				}
				i=s%10;
			}
			System.out.println(result);
			
 
			// 出力
 
	}
}

Measured memory_bytes: 24276
#include<stdio.h>
int main(){
  int n,m,a,i,j,h,p,q;
  while(scanf("%d %d %d",&n,&m,&a),n||m||a){
    int d[1001][1001]={0};
    for(i=0;i<m;i++){
      scanf("%d %d %d",&h,&p,&q);
      d[h][p]=q;
      d[h][q]=p;
    }
    for(i=1000;i;i--){
      for(j=1;j<=n;j++){
	if(d[i][a]){
	  a=d[i][a];
	  d[i][a]=0;
	
	  //printf("%d %d\n",i,j);
	}
      }
    }
    printf("%d\n",a);
  }
  return 0;
}

Measured memory_bytes: 4520
n = int(input())
s1 = input()
s2 = input()
ans = 1
i = 1
mod = 1000000007
if s1[0] == s2[0]:
    ans = 3
    i = 1
else:
    ans = 6
    i = 2
while i < n:
    if s1[i - 1] == s2[i - 1]:
        if s1[i] == s2[i]:
            ans = (ans * 2) % mod
            i += 1
            continue
        else:
            ans = (ans * 2) % mod
            i += 2
            continue
    else:
        if s1[i] == s2[i]:
            ans = (ans * 1) % mod
            i += 1
            continue
        else:
            ans = (ans * 3) % mod
            i += 2
            continue
print(ans)


Measured memory_bytes: 61216
import java.util.*;
import java.io.*;
import java.lang.*;

public class Main {
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int a = sc.nextInt();

        int b = n%500;
        if (b<=a)
            System.out.println("Yes");
        else
            System.out.println("No");
    }
}


Measured memory_bytes: 35672
s = input()
n1 = int(s[:2])
n2 = int(s[2:])

def f(n):
    if n>=1 and n<=12:
        return True
    else:
        return False

if f(n1) and f(n2):
    print("AMBIGUOUS")
elif f(n1) and (not f(n2)):
    print("MMYY")
elif f(n2) and (not f(n1)):
    print("YYMM")
else:
    print("NA")


Measured memory_bytes: 3060
#include <stdio.h>


int main(){
  int v,N,i,j;
  int A[1000];
  
  scanf("%d",&N);
  
  for(i=0;i<N;i++){
    scanf("%d",&A[i]);
  }

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

  for(i=1;i<=N-1;i++){
    v = A[i];
    j = i-1;
  
    while(j>=0 && A[j] > v){
      A[j+1] = A[j];
      j--;

    }
    A[j+1] = v;
    
    for(j=0;j<N-1;j++){
      printf("%d ",A[j]);
 
    }
    printf("%d",A[N-1]);
    printf("\n");
  }
  return 0;
}
  

 
    
    
    



Measured memory_bytes: 2056
a1s = gets.chomp.split(' ').map(&:to_i)
a2s = gets.chomp.split(' ').map(&:to_i)
a3s = gets.chomp.split(' ').map(&:to_i)
as = a1s + a2s + a3s
n = gets.chomp.to_i
bs = n.times.map { gets.chomp.to_i }

board = {}
as.each do |a|
    board[a] = false
end

bs.each do |b|
    next if board[b].nil?
    board[b] = true
end

result = as.map { |a| board[a] }

ans = 'No'
ans = 'Yes' if result[0] && result[1] && result[2]
ans = 'Yes' if result[0 + 3] && result[1 + 3] && result[2 + 3]
ans = 'Yes' if result[0 + 6] && result[1 + 6] && result[2 + 6]

ans = 'Yes' if result[0] && result[3] && result[6]
ans = 'Yes' if result[0 + 1] && result[3 + 1] && result[6 + 1]
ans = 'Yes' if result[0 + 2] && result[3 + 2] && result[6 + 2]

ans = 'Yes' if result[0] && result[4] && result[8]
ans = 'Yes' if result[2] && result[4] && result[6]

puts ans


Measured memory_bytes: 3836
#include <iostream>
#include <vector>
#include <sstream>
#include <cmath>
#include <algorithm>
#include <map>
#include <queue>

#define ull unsigned long long int
#define ll long long int
#define rep(var, from, to) for (ll var=(from); var<=(to); var++)
#define INF (1<<30)

using namespace std;

int n, m;
bool visited[100005];
int place[100005];

vector<pair<int ,int> > g[100005];

bool dfs(int v)
{
  for (int i=0; i<g[v].size(); i++)
  {
    int c = g[v][i].first;
    if (!visited[c])
    {
      visited[c] = true;
      place[c] = place[v]+g[v][i].second;
      bool t = dfs(c);
      if (!t) return false;
    } else
    {
      if (place[c] != place[v]+g[v][i].second)
      {
        return false;
      }
    }
  }
  return true;
}

bool bfs(int v)
{
  queue<int> qu;
  qu.push(v);
  while (qu.size() != 0)
  {
    v = qu.front();
    qu.pop();
    for (int i=0; i<g[v].size(); i++)
    {
      int c = g[v][i].first;
      if (!visited[c])
      {
        visited[c] = true;
        place[c] = place[v]+g[v][i].second;
        qu.push(c);
      } else
      {
        if (place[c] != place[v]+g[v][i].second)
        {
          return false;
        }
      }
    }
  }
  return true;
}

int main()
{
  std::ios_base::sync_with_stdio(false);
  cin >> n >> m;
  for (int i=0; i<m; i++)
  {
    int l, r, d;
    cin >> l >> r >> d;
    g[l].push_back(pair<int, int>{r, d});
    g[r].push_back(pair<int, int>{l, -d});
  }
  for (int i=1; i<=n; i++)
  {
    if (!visited[i])
    {
      place[i] = 0;
      visited[i] = true;
      bool t = bfs(i);
      if (!t)
      {
        cout << "No" << endl;
        return 0;
      }
    }
  }
  cout << "Yes" << endl;
}

Measured memory_bytes: 9472
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#include<iomanip>
using namespace std;

int main(){
    int a,b;
    cin>>a>>b;
    if(a<=8&&b<=8)cout<<"Yay!"<<endl;
    else cout<<":("<<endl;
    return 0;
}

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

long maxn=100000;
double f[100005][10];
double ans[100005];
double jie[10];
long n;
int main(){
	f[1][1]=1;
	jie[0]=1;
	for (int i=1;i<=10;i++) jie[i]=jie[i-1]/2;
	for (int i=1;i<=maxn;i++){
		ans[i]=ans[i-1]+1-f[i][0];
		//cout<<i<<": "<<ans[i]<<endl;
		for (int j=0;j<10;j++){
			f[i+1][j+1]+=f[i][j]*jie[j];
			f[i+1][0]+=f[i][j]*(1-jie[j]);
		}
	}
	while (cin>>n && n){
		printf("%.10f\n",ans[n]);
	}
}

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

int main()
{
    int w,a,b;
    cin >> w >> a >> b;
    if(a > b){
        swap(a,b);
    }
    if(b - (a + w) > 0){
        cout << b - (a + w);
    }else{
        cout << 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 A,B;
  
  cin>>A>>B;
  
  int ans=-1;
  
  for(int i=1;i<1001;i++){
    if((floor(i*0.08)==A)&&(floor(i*0.10)==B)){
        ans=i;
        break;
    }
  }


  cout<<ans<<endl;

}


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

#define M 100005
#define MOD 1000000007
#define PI 3.14159265358979323846
#define ep emplace_back
#define mk make_pair
#define all(v) (v).begin(),(v).end()
#define rall(v) (v).rbegin(),(v).rend()

typedef long long int lli;
typedef unsigned long long int ulli;
typedef pair<int,int> PII;
typedef pair<lli,lli> PLL;

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

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

    int n;
    cin>>n;
    
    if(n%1000==0)
        cout<<"0\n";
    else
    {
        int q = n/1000;
        int ans = (q+1)*1000-n;
        cout<<ans<<"\n";
    }
    
}


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

int main() {
  int a,b,c;
  bool chk = false;
  int cnt = 0;
  
  cin >> a >> b >> c;
  
  while(chk == false){
    if(a == b && b == c){
      chk = true;
      break;
    }
    
    if(a <= b && a <= c){
      if(a == b){
        a++;
        b++;
        cnt++;
      }else if(a == c){
        a++;
        c++;
        cnt++;
      }else{
        a+=2;
        cnt++;
      }
    }else if(b <= a && b <= c){
      if(b == a){
        b++;
        a++;
        cnt++;
      }else if(b == c){
        b++;
        c++;
        cnt++;
      }else{
        b+=2;
        cnt++;
      }
    }else{
      if(c == a){
        c++;
        a++;
        cnt++;
      }else if(c == b){
        c++;
        b++;
        cnt++;
      }else{
        c+=2;
        cnt++;
      }
    }
  }
  
  cout << cnt;
}


Measured memory_bytes: 256