akhauriyash/Code-Regression huggingface dataset:
#include<stdio.h>
typedef struct{
  int number;
  int son[2];//子
  int reach;
  int parent;
  int sibling;
  int degree;
  int height;
}node;

node B[10000];
int n;
int a;
int flag=0;

void preorder(int num){
  //  if(num!=a)printf(" ");
  printf(" %d",B[num].number);
  if(B[num].son[0]!=-1)preorder(B[num].son[0]);
  if(B[num].son[1]!=-1)preorder(B[num].son[1]);

}//OK

void inorder(int num){
  /* {
      printf(" %d",B[num].number);
      return;
      }*/
    if(B[num].son[0]!=-1)inorder(B[num].son[0]);
      printf(" %d",B[num].number);
  if(B[num].son[1]!=-1)inorder(B[num].son[1]);

  }

void postorder(int num){
  
  /* if(B[num].son[0]==-1){
    printf(" %d",B[num].number);
    return;
    }*/
if(B[num].son[0]!=-1)postorder(B[num].son[0]);
  /*  if(B[num].son[1]==-1){
    printf(" %d",B[num].number);
    return;
    }*/
  if(B[num].son[1]!=-1)postorder(B[num].son[1]);
  printf(" %d",B[num].number);
}//OK

int parent(int num){//parent input
  int i,j,r=-1;
  for(i=0;i<n;i++){
    for(j=0;j<2;j++){
      if(num==B[i].son[j]){
	r=i;
	return r;
      }
    }
  }
  return r;
}

int reach(int num){//reach input
  int i,r=0;
  for(i=0;i<n;i++){
    if(B[num].parent==-1)return r;
    else {
      num=B[num].parent;
      r++;
    }
  }
}

int sibling(int num){//sibling input
  int i,j,r=-1;
  for(i=0;i<n;i++){
    if(i!=num){
      if(B[num].parent==B[i].parent){
	r=i;
	return r;
      }
    }
  }
  return r;
}

int height(int num,int r,int parent){//height input
  //  printf("r = %d num = %d\n",r,num);
  if(parent==B[num].parent)r=0;
  if(B[num].son[0]==-1)return r;
  r++;
  r=height(B[num].son[0],r,parent);
  r=height(B[num].son[1],r,parent);
 
  return r;
}

int main(){
  int i,j,k;
  scanf("%d",&n);
  for(i=0;i<n;i++){
    B[i].parent=-1;
  }
  for(i=0;i<n;i++){
    scanf("%d",&a);
    B[a].number=a;
    for(j=0;j<2;j++){
      scanf("%d",&k);
      B[a].son[j]=k;
      B[k].parent=a;
      if(k==-1)B[a].degree=0;
      else B[a].degree=2;
    }
  }

  /*  for(i=0;i<n;i++){
    B[i].parent=parent(i);
  }
  */
  
  for(i=0;i<n;i++){
    B[i].reach=reach(i);
  }
  
  for(i=0;i<n;i++){
    B[i].sibling=sibling(i);
  }
  
  /*  for(i=0;i<n;i++){
    B[i].height=height(i,0,B[i].parent);
  }
  */
  for(i=0;i<n;i++){
    if(B[i].parent==-1){
      a=i;
      break;
    }
  }
  printf("Preorder\n");
   preorder(a);
  printf("\nInorder\n");
   inorder(a);
  printf("\nPostorder\n");
   postorder(a);
  printf("\n");


  return 0;
}

Measured memory_bytes: 0
#include<bits/stdc++.h>  
using namespace std;  
char a[100000000];
int main(){  
    cin>>a;
    int flag=0;
    for(int i=0;a[i]!='\0';i++){
        if(!flag&&a[i]=='C'){
            flag=1;
        }
        if(flag&&a[i]=='F'){
            cout<<"Yes"<<endl;
            return 0;
        }
    }
    cout<<"No"<<endl;
    return 0;
}  

Measured memory_bytes: 256
package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
)

func main() {
	sc := bufio.NewScanner(os.Stdin)
	sc.Split(bufio.ScanWords)
	n, err := nextInt(sc)
	if err != nil {
		panic(err)
	}
	for i := 0; i < n; i++ {
		strX := nextText(sc)
		strY := nextText(sc)
		fmt.Println(calcLcs(strX, strY))
	}
}

func calcLcs(strX, strY string) int {
	lenX, lenY := len(strX), len(strY)
	memo := make([][]int, lenX+1)
	for i := 0; i < lenX+1; i++ {
		memo[i] = make([]int, lenY+1)
	}

	lcs := 0
	for i := 1; i < lenX+1; i++ {
		for j := 1; j < lenY+1; j++ {
			if strX[i-1] == strY[j-1] {
				memo[i][j] = memo[i-1][j-1] + 1
			} else {
				if memo[i-1][j] > memo[i][j-1] {
					memo[i][j] = memo[i-1][j]
				} else {
					memo[i][j] = memo[i][j-1]
				}
			}
			if memo[i][j] > lcs {
				lcs = memo[i][j]
			}
		}
	}
	return lcs
}

func nextInt(sc *bufio.Scanner) (int, error) {
	sc.Scan()
	return strconv.Atoi(sc.Text())
}

func nextText(sc *bufio.Scanner) string {
	sc.Scan()
	return sc.Text()
}



Measured memory_bytes: 18920
#include <bits/stdc++.h>
#define FOR(i,b,e) for (common_type_t<decltype(b),decltype(e)> i = (b), i ## __end = (e); i < i ## __end; ++ i)
#define rep(i,n)   FOR (i, size_t{}, n)
#define ALL(x)     begin (x), end (x)
using namespace std;
using ll = int64_t;
constexpr ll inf = 2e18;
constexpr size_t invalid = ~0ull;

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

  size_t n;
  string s;
  cin >> n >> s;

  ll ans = 0;
  rep (i, n - 2)
  {
    if (s [i] == 'A' && s [i + 1] == 'B' && s [i + 2] == 'C') ++ ans;
  }
  cout << ans << endl;
}


Measured memory_bytes: 256
#include <stdio.h>
#include <cmath>
#include <algorithm>
#include <stack>
#include <queue>
#include <vector>
typedef long long int ll;
#define BIG_NUM 2000000000
using namespace std;

int main(){

	ll N,k,ans = 0;

	scanf("%lld %lld",&N,&k);

	for(int i = 0; i < N-1; i++){
		ans += ans/(k-1)+1;
	}

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

	return 0;
}

Measured memory_bytes: 2752
#include <bits/stdc++.h>
#define ll long long int
#define pb push_back
#define se second
#define fi first
#define rep(i, l, r) for (ll i = (ll)(l); i < (ll)(r); i++)
#define print(v) for (const auto itr : v){cout << itr << ' ';} cout << endl;
ll powermod(ll x, unsigned ll y, ll p){ll res = 1;x = x % p;while (y > 0){if (y & 1){res = (res*x) % p;}y = y>>1; x = (x*x) % p;}return res;}
#define mod 1000000007
#define inf 1e18
using namespace std;
const ll INF = 1e18L + 5;
const ll maxn = 2e5 + 5;
ll ceel(ll a, ll b)
{
   if (a % b == 0)
       return a / b;
   return a / b + 1;
}
ll lcm(ll a, ll b) { return (a * b) / __gcd(a, b); };


int main()
{

ll n,i,j,k,c,mx=-inf,mn=inf;
cin>>n>>k>>c;
string s;
cin>>s;
pair<ll,ll> arr[200005];
ll last=n-1,fir=0;
i=n-1;
while(i>=0 and s[i]=='x')
    i--;
last=i;
i=0;
while(i<n and s[i]=='x')
    i++;
fir=i;
if(last<0)
    exit(0);
ll k1=k,c1=0;
i=last;
while(k1!=0 and i>=0)
{
    while(i>=0 and (s[i]=='x' or c1>0))
    {
        i--;
        c1--;
    }
    // cout<<i<<endl;
    if(i<0)
        exit(0);
    
    arr[k1].se=i;
    c1=c;
    i--;
    k1--;
}
i=fir;
k1=1;
c1=0;
while(i<n and k1<=k)
{
    while(i<n and (s[i]=='x' or c1>0))
    {
        i++;
        c1--;
    }
    // cout<<i<<endl;
    if(i>=n)
        exit(0);
        
    arr[k1].fi=i;
    c1=c;
    i++;
    k1++;
}



for(i=1;i<=k;i++)
{
    if(arr[i].fi==arr[i].se)
    {
        cout<<arr[i].fi+1<<endl;
    }
    // cout<<arr[i].fi<<" "<<arr[i].se<<"\n";
}
return 0;
}


Measured memory_bytes: 4996
#include <bits/stdc++.h>
#define REP(i, s, n) for (int i = s; i < n; i++)
#define ALL(a) a.begin(), a.end()
#define MOD 1000000007
using namespace std;
typedef long long ll;

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

    int count[3] = {}; ll ans = 1;
    REP(i, 0, N) {
        int a; cin >> a;
        int cnt = 0;
        REP(j, 0, 3) if (count[j] == a) cnt++;
        REP(j, 0, 3) {
            if(count[j] == a) {
                count[j]++;
                break;
            }
        }
        ans = (ans * cnt) % MOD;
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
int main(void){
    int a,b,c,k;
    scanf("%d%d%d%d",&a,&b,&c,&k);
    if(k<=a){
        printf("%d",k);
        return 0;
    }
    if(k>a&&k<=a+b){
        printf("%d\n",a);
        return 0;
    }
    if(a+b<k&&k<=a+b+c){
        printf("%d\n",2*a+b-k);
        return 0;
    }
}

Measured memory_bytes: 1732
#include<cstdio>
#include<algorithm>
using namespace std;
const int MAXN=100005;
int n,X,v[MAXN];
int JCD;
int jcd(int x,int y){
	if(x==0)return y;
	return jcd(y%x,x);
}
int main(){
	scanf("%d%d",&n,&X);
	for(int i=1;i<=n;i++)
		scanf("%d",&v[i]);
	v[++n]=X;
	sort(v+1,v+n+1);
	JCD=v[2]-v[1];
	for(int i=3;i<=n;i++)
		JCD=jcd(JCD,v[i]-v[i-1]);
	printf("%d\n",JCD);
	return 0;
}

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

#define REP(i, m, n) for (int i = (m); i < (int)(n); i++)
#define REPS(i, m, n) for (int i = (m); i <= (int)(n); i++)
#define rep(i, n) REP(i, 0, n)
#define reps(i, n) for (int i = 0; i <= (int)(n); i++)
#define rrep(i, x) for (int i = ((int)(x)-1); i >= 0; i--)
#define rreps(i, x) for (int i = (int)(x); i >= 0; i--)
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define pb push_back
#define fi first
#define se second
typedef long long ll;
typedef pair<int, int> P;
const int inf = INT_MAX;
const ll INF = 1LL << 60;
const ll mod = 1e9 + 7;
const double EPS = 1e-10;
const double PI = acos(-1.0);
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; }
template<typename A, size_t N, typename T> void Fill(A (&array)[N], const T &val) { fill( (T*)array, (T*)(array+N), val ); }
template <class T1, class T2, class Pred = std::less<T2> >
struct sort_pair_second {
    bool operator()(const std::pair<T1,T2>&left, const std::pair<T1,T2>&right) {
        Pred p;
        return p(left.second, right.second);
    }
};

ll C[20];
ll A[20][101010];
int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);

    ll N, M, X;
    cin >> N >> M >> X;
    rep(i, N) {
      cin >> C[i];
      rep(j, M) cin >> A[i][j];
    }
    ll ans = inf;
    rep(i, 1 << N) {
      ll cost = 0;
      vector<ll> V(M, 0);
      rep(j, N) {
        if ((i >> j) & 1) {
          cost += C[j];
          rep(k, M) V[k] += A[j][k];
        }
      }
      bool flag = false;
      rep(j, M) if (V[j] < X) flag = true;
      if (flag) continue;
      ans = min(ans, cost);
    }
    if (ans == inf) ans = -1;
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 3740
#include<bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < n; i++)
#define PI 3.1415926535897932384626433832795028
#define INF (1<<29)
#define LINF (1LL<<60)
using namespace std;
using INT = long long;
using P = pair<int,int> ;

int main(){
    int n,len;
    string s;
    cin >> n >> s;
    len = s.size();
    for(int i = 0; i < len ; i++){
        s[i] = (s[i]-65+n)%26 + 65;
    }
    cout << s << endl;
	return 0;
}



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

int main()
{
    int N;
    cin >> N;
    if((N%10) == 3) {
        cout << "bon" << endl;
    } else if((N%10) == 0 || (N%10) == 1 || (N%10) == 6 || (N%10) == 8) {
        cout << "pon" << endl;
    } else {
        cout << "hon" << endl;
    }
    return 0;
}

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

int main(){
    ll a, b, c, d;
    cin >> a >> b >> c >> d;

    ll time[301];
    ll ans = 0;

    fill(time,time+301,0LL);

    for(ll i = a; i < b; i++){
        time[i]++;
    }
    for(ll i = c; i < d; i++){
        time[i]++;
    }

    for(long long i = 0; i < 301; i++){
        if(time[i] == 2) ans++;
    }

    put(ans);
}

Measured memory_bytes: 256
#include<iostream>
#include<string>
using namespace std;
int main() {
	string s;
	getline(cin, s);
	
	string::size_type pos1,pos2, begin;
	
	while(1){
		pos1 = s.find("apple", begin);
		pos2 = s.find("peach", begin);
		
		if( pos1 == string::npos && pos2 == string::npos ) 
			break;
		
		if( pos1 < pos2 ){
			s.replace( pos1, 5, "peach" );
			begin = pos1 + 5;
		}else{
			s.replace( pos2, 5, "apple" );
			begin = pos2 + 5;
		}
	
	}
	cout << s << endl;
}

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

int main() {
  int A, B, M;
  cin >> A >> B >> M;

  vector<int> a(A), b(B), a_o(A);
  int tmp = 0;
  int min = 100000000;
  for (int i = 0; i < A; i++) {
    cin >> a.at(i);
    a_o.at(i) = a.at(i);
  }
  sort(a.begin(), a.end());
  for (int i = 0; i < B; i++) {
    cin >> b.at(i) ;
    for (int j = 0; j < A; j++) {
      tmp = a.at(j) + b.at(i);
      if (tmp < min) min = tmp;
      else break;
    }
  }

  int x_a, x_b, x_m;
  for (int i = 0; i < M; i++) {
    cin >> x_a >> x_b >> x_m;
    tmp = a_o.at(x_a - 1) + b.at(x_b - 1) - x_m;
    if (tmp < min) min = tmp;
  }

  cout << min << endl;
}

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

int getSumOfDigits(int n){
    int sum=0;
    while(n>0){
        sum += n%10;
        n /= 10;
    }
    return sum;
}
int main(){
    int n;
    cin >> n;
    int fn = getSumOfDigits(n);
    if(n%fn==0)cout << "Yes" << endl;
    else cout << "No" << endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)

using namespace std;

typedef pair<int, int> p;
typedef long long ll;
const int inf = 1000000007;

int main() {
  int n;
  cin >> n;
  vector<int> d1(n), d2(n);
  rep(i, n) { cin >> d1[i] >> d2[i]; }
  bool ok = false;
  rep(i, n - 2) {
    if (d1[i] == d2[i] && d1[i + 1] == d2[i + 1] && d1[i + 2] == d2[i + 2]) {
      ok = true;
    }
  }
  if (ok) {
    cout << "Yes" << endl;
  } else {
    cout << "No" << endl;
  }
  return 0;
}

Measured memory_bytes: 3632
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <iostream>
#include <string>
#include <vector>
#include <map>
#include <set>
#include <stack>
#include <list>
#include <queue>
#include <deque>
#include <algorithm>
#include <numeric>
#include <utility>
#include <complex>
#include <functional>
#include <climits>

using namespace std;

bool endsWith(string s, string dr) {
    return s.size() >= dr.size() && 0 == s.compare(s.size()-dr.size(), dr.size(), dr);
}

string cutf(string s, string dr) {
    return s.substr(0, s.size()-dr.size());
}

int main() {
    string s;
    getline(cin, s);
    string dr = "dream", drer = "dreamer", er = "erase", erer = "eraser";
    while(s.size() > 0) {
        if(endsWith(s, dr)) {
            s = cutf(s, dr);
            continue;
        } else if(endsWith(s, drer)) {
            s = cutf(s, drer);
            continue;
        } else if(endsWith(s, er)) {
            s = cutf(s, er);
            continue;
        } else if(endsWith(s, erer)) {
            s = cutf(s, erer);
            continue;
        }
        break;
    }
    if(s.size() == 0) {
        cout << "YES" << endl;
    } else {
        cout << "NO" << endl;
    }

    
}


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

#define ll long long
#define INF_LL 1LL << 60
#define INF 99999999
#define MOD (ll)1000000007
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define REP(i, a, n) for(int i = a; i < (int)(n); i++)
#define all(x) (x).begin(),(x).end()

void put_double(double obj){printf("%.12f\n",obj);};

template < typename T > std::string to_string( const T& n )
{
    std::ostringstream stm ;
    stm << n ;
    return stm.str() ;
}

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 main()
{
    string s;
    cin >> s;

    rep(i,s.size())
    {
        if( (i+2)%2==0 ) cout << s[i];
    }
    cout << endl;
}


Measured memory_bytes: 512
#include<bits/stdc++.h>
using namespace std;
int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    int w, h, n;
    cin >> w >> h >> n;
    vector<int>x, y, a;
    for(int i = 0;i < n;i++) {
        int k, j, f;
        cin >> k >> j >> f;
        x.push_back(k);
        y.push_back(j);
        a.push_back(f);
    }
    int min_x = 0;
    int min_y = 0;
    int max_x = w;
    int max_y = h;
    for(int i = 0;i < n;i++) {
        switch (a[i])
        {
        case 1:
            min_x = max(min_x, x[i]);
            break;
        case 2:
            max_x = min(max_x, x[i]);
            break;
        case 3:
            min_y = max(min_y, y[i]);
            break;
        case 4:
            max_y = min(max_y, y[i]);
            break;
        }
    }
    if(max_x<min_x) {
        cout << 0 << endl;
        return 0;
    } else if(max_y<min_y) {
        cout << 0 << endl;
        return 0;
    }
    int rect = (max_x-min_x)*(max_y-min_y);
    if(rect < 0) {
        rect = 0;
    }
    cout << rect << endl;
}

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

const int MAX_H = 100, MAX_W = 100;
int H, W;
char field[MAX_H][MAX_W+1];
int dx[4] = {0,1,0,-1}, dy[4] = {1,0,-1,0};

void dfs(int x, int y, char a) {
    field[x][y] = '.';

    for (int i = 0; i < 4; i++) {
        int nx = x + dx[i], ny = y + dy[i];
        if (0 <= nx && nx < H && 0 <= ny && ny < W && field[nx][ny] == a) dfs(nx, ny, a);
    }
    return ;
}

void solve() {
    int res = 0;
    for (int i = 0; i < H; i++) {
        for (int j = 0; j < W; j++) {
            if (field[i][j] != '.') {
                dfs(i, j, field[i][j]);
                res++;
            }
        }
    }
    cout << res << endl;
}

int main () {
    while(cin >> H >> W, H&&W) {
        for (int i = 0; i < H; i++) {
            for (int j = 0; j < W; j++) {
                cin >> field[i][j];
            }
        }
        solve();
    }
    return 0;
}


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

int main(){
int H,W;

while(1){
cin>>H>>W;
if(H==0&&W==0)break;

for(int i=0;i<H;i++){
for(int x=0;x<W;x++){

if((i+x)%2==0){
cout<<'#';
}
else {cout<<'.';
}
}
cout<<endl;
}
cout<<endl;
}
return 0;
}


Measured memory_bytes: 3096
#include <bits/stdc++.h>
using namespace std;
const int MAX = 200000;

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

    int N;
    int A[MAX];
    int max1 = 0, max2 = 0;
    cin >> N;
    for (int i = 0; i < N; i++) {
        cin >> A[i];
        if (A[i] > max1) max1 = A[i];
        else if (A[i] > max2) max2 = A[i];
    }
    for (int i = 0; i < N; i++) {
        if (A[i] != max1) cout << max1 << endl;
        else
            cout << max2 << endl;
    }

    return 0;
}


Measured memory_bytes: 2432
def fib(n):
    a, b = 1, 1
    for _ in range(n):
        a, b = b, a + b
    return a


n, m = map(int, input().split())
a = [-1] + [int(input()) for i in range(m)] + [n + 1]
ans = 1

for i in range(len(a) - 1):
    if a[i] != 0 and a[i + 1] != n and a[i + 1] - a[i] == 1:
        print(0)
        exit()

    ans = ans * fib(a[i + 1] - a[i] - 2) % (10 ** 9 + 7)

print(ans)


Measured memory_bytes: 7848
# cook your dish here

def digSum(n):
    s = 0
    while n != 0:
        s += (n % 10)
        n //= 10
    return s

n = int(input())
ans = 1000000
l = 1
r = n - 1
while l <= r:
    ans = min(ans , digSum(l) + digSum(r))
    l += 1
    r -= 1

print(ans)

Measured memory_bytes: 3064
#include <bits/stdc++.h>
#ifdef BUG
    #include "debug.hpp"
#else
    #define DEBUG(var)
#endif

using namespace std;
template< class T1, class T2 > inline istream &
operator>>( istream & fin, pair< T1, T2 > & pr )
{ fin >> pr.first >> pr.second; return fin; }
template< class T0, class T1, class T2 > inline istream &
operator>>( istream & fin, tuple< T0, T1, T2 > & t )
{ fin >> get<0>(t) >> get<1>(t) >> get<2>(t); return fin; }
template< class T > inline istream &
operator>>( istream & fin, vector< T > & a ) {
for(auto & u: a) fin >> u; return fin; }
template<class T, size_t n> inline istream &
operator>>( istream & fin, array<T, n> & a ) {
for(auto & u: a) fin >> u; return fin; }
template<class FwdIter> inline auto
dump(FwdIter first, FwdIter last, const char * dlm = " ") -> void {
typedef typename iterator_traits<FwdIter>::value_type value_type;
copy(first, last, ostream_iterator<value_type>(cout, dlm)); }
template<typename T> vector<T> & operator--(vector<T> & a)
{ for(auto & i: a) --i; return a; }
/* @@@ ----------------------------------- */


int main(const int argc, char * argv [])
{
  ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);

  int64_t n;
  array<int64_t, 4> a;
  const array<int64_t, 4> b = {1, 2, 4, 8};
  cin >> a >> n;
  // for(auto & i: a) i *= 4;
  n *= 4;

  const int64_t inf = numeric_limits<int64_t>::max();
  const int64_t size = 1600;
  vector<int64_t> xs(size, inf);
  xs[0] = 0;
  for(int64_t k = 1; k < size; ++k)
    for(size_t i = 0; i < 4; ++i)
      if(b[i] < k + 1) xs[k] = min(xs[k], a[i] + xs[k - b[i]]);


  if (n < size)
    cout << xs[n];
  else
  {
    int64_t out = inf;
    for(size_t i = 0; i < 4; ++i)
    {
      const int64_t r = (n - (size / 4)) / b[i];
      const int64_t s = n - r * b[i];
      out = min(out, r * a[i] + xs[s]);
    }

    cout << out;
  }

  return EXIT_SUCCESS;
}


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

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++)
typedef long long ll;

int main() {
	string s;
	cin >> s;
	map<char, int> mp;
	rep(i, s.size()) {
		mp[s[i]]++;
	}
	for (char c = 'a'; c <= 'z'; ++c) {
		if (mp[c] == 0) {
			cout << c << endl;
			return 0;
		}
	}
	cout << "None" << endl;
	return 0;
}



Measured memory_bytes: 512
using System;

namespace ABC085C
{
    class Program
    {
        static void Main(string[] args)
        {
            var str = Console.ReadLine().Split(' ');
            int N = int.Parse(str[0]);
            int Y = int.Parse(str[1]);
            int i = 0; int j = 0; int k = 0;
            for(i = 0; i <= N; i++){ // 10k
                for(j = 0; j <= N-i; j++){ // 5k
                    k = N - i - j; // 1k
                    if(i*10000+j*5000+k*1000 > Y) continue;
                    if(i*10000+j*5000+k*1000 == Y){
                      Console.WriteLine("{0} {1} {2}",i, j, k);
                        return;
                      }                
                }
            }
            Console.WriteLine("-1 -1 -1");
        }
    }
}


Measured memory_bytes: 13140
package main

import (
   "fmt"
   "os"
   "bufio"
   "strconv"
   "sort"
)

const MaxBuf = 200100
var buf []byte
var sc = bufio.NewScanner(os.Stdin)

func init() {
   sc.Split(bufio.ScanWords)
   sc.Buffer(buf,MaxBuf)
}

func readString() string {
   sc.Scan()
   return sc.Text()
}

func readInt64() int64 {
   sc.Scan()
   r,_ := strconv.ParseInt(sc.Text(),10,64)
   return r
}

func readInt() int {
   sc.Scan()
   r,_ := strconv.Atoi(sc.Text())
   return r
}

func readFloat64() float64 {
	sc.Scan()
	r,_ := strconv.ParseFloat(sc.Text(),64)
	return r
}


type pi [][]int

func (st pi) Len() int { return len(st) }
func (st pi) Less(i,j int) bool { return st[i][0] < st[j][0]}
func (st pi) Swap(i,j int) {
	st[i][0] ,st[j][0] = st[j][0] ,st[i][0]
	st[i][1] ,st[j][1] = st[j][1] ,st[i][1]
}


func main() {
	n := readInt()
	a := make([][]int,n)
	for i := 0; i <n ; i++ {
		a[i] = make([]int,2)
		a[i][0] = readInt()
		a[i][1] = i+1
	}
	as := pi(a)
	sort.Sort(as)

	for i := 0; i < n ; i++ {
		fmt.Printf("%d ",as[i][1])
	} 
	
}

Measured memory_bytes: 6144
#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pii =  pair<int, int>;
using pll =  pair<long long, long long>;
constexpr char ln =  '\n';
constexpr long long MOD = 1000000007LL;
constexpr long long INF = 1000000009LL;
#define all(x) (x).begin(),(x).end()
#define rep(i,n) for(int i=0;i<(n);i++)
#define fo(i,j,n) for (int i=(j); i < (n); i++)
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() {    
    int n; ll k; cin >> n >> k;
    vector<ll> A(n), F(n);
    rep(i, n) cin >> A[i];
    rep(i, n) cin >> F[i];

    sort(all(A));
    sort(all(F), greater<ll>());

    ll ng = 0, ok = 1e12+1;
    while(ng < ok){
        ll mid = (ng + ok) / 2, sum = 0;
        rep(i, n){
            sum += max(0LL,(A[i] * F[i] - mid + F[i] - 1) / F[i]);
        }
        if(sum <= k) ok = mid;
        else ng = mid + 1;
    }
    cout << ok << ln;
} 


Measured memory_bytes: 3328
#include <stdio.h>
int main()
{   int n;
    int power[1001]={0};
    scanf("%d",&n);
    for(int i=2;i<=n;i++){
        int cpy=i;
        for(int j=2;j<=i;j++){
        while(cpy%j==0){
            cpy/=j;
            power[j]++;
        }
        }
    }
    long long ans=1;
    for(int i=0;i<=n;i++){
        //printf("power[%d] is %d\n",i,power[i]);
        ans*=(power[i]+1);
        ans%=1000000007;
    }
    printf("%lld",ans);

    return 0;
}


Measured memory_bytes: 128
#include<bits/stdc++.h>
using namespace std;
int a[310][310],b[310][310],x,y,n,tag[310][310],dis[310],ge[310],i;
struct cmp
{
	bool operator()(const pair<int,int>&a,const pair<int,int>&b)const
	{
		return ::a[a.first][a.second]>::a[b.first][b.second];
	}
};
priority_queue<pair<int,int>,vector<pair<int,int>>,cmp>q;
int main()
{
	scanf("%d",&n);
	for(int i=1; i<=n; i++)
		for(int j=1; j<=n; j++)
		{
			scanf("%d",&a[i][j]);
			b[i][j]=a[i][j];
		}
	for(int k=1; k<=n; k++)
		for(int i=1; i<=n; i++)
			for(int j=1; j<=n; j++)
				b[i][j]=min(b[i][j],b[i][k]+b[k][j]);
	for(int i=1; i<=n; i++)
		for(int j=1; j<=n; j++)
			if(a[i][j]!=b[i][j])
				return puts("-1"),0;
	for(i=1; i<=n; i++)
	{
		for(int j=1; j<=n; j++)
		{
			ge[j]=1;
			dis[j]=~0u>>1;
		}
		ge[i]=dis[i]=0;
		for(int j=1; j<=n; j++)
			if(i!=j)
				q.push(make_pair(i,j));
		while(!q.empty())
		{
			pair<int,int>x=q.top();
			tag[x.first][x.second]=1;
			ge[x.second]=0;
			q.pop();
			for(int j=1; j<=n; j++)
				if(j!=x.second&&a[i][x.second]+a[j][x.second]==a[i][j])
					q.push(make_pair(x.second,j));
			while(q.size()&&!ge[q.top().second])
				q.pop();
		}
	}
	long long ans=0;
	for(int i=1; i<=n; i++)
		for(int j=i+1; j<=n; j++)
			if(tag[i][j])
				ans=ans+a[i][j];
	cout<<ans<<endl;
}

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

int main() {
	int h, n;
	cin >> h >> n;
	vector<int> a(n);
	rep(i,n) {
		cin >> a[i];
	}
	int w = 0;
	rep(i,n) {
		w += a[i];
	}
	if (h <= w) {
		cout << "Yes" << endl;
	}
	else {
		cout << "No" << endl;
	}
	
	return 0;
}


Measured memory_bytes: 640
#include <bits/stdc++.h>
#define lli long long int

using namespace std;
    lli h,w;
lli mod = 1000000007;
lli calc(lli i,lli j,vector<vector<char> > &vec,vector<vector<lli> > &memo)
{
   // cout<<i<<"  "<<j<<endl;
    if(i >= h || j >= w)
        return 0;
    if(memo[i][j] != -1)
    {
        return memo[i][j];
    }
    memo[i][j] = 0;
    lli ans = 0;
    if(i < (h-1))
    {
        if(vec[i+1][j] != '#')
        {
            ans = calc(i+1,j,vec,memo);
            memo[i][j] = (memo[i][j]%mod + ans%mod)%mod;
        }
    }
    if(j < (w-1))
    {
        if(vec[i][j+1] != '#')
        {
            ans = calc(i,j+1,vec,memo);
            memo[i][j] = (memo[i][j]%mod + ans%mod)%mod;
        }
    }
    return memo[i][j];
}


int main()
{
    cin>>h>>w;
    vector<vector<char> > vec(h,vector<char>(w));
    vector<vector<lli> > memo(h,vector<lli>(w));
    for(lli i=0;i<h;i++)
    {
        for(lli j=0;j<w;j++)
        {
            cin>>vec[i][j];
            memo[i][j] = -1;
        }
    }
    memo[h-1][w-1] = 1;
    cout<<calc(0,0,vec,memo);
}


Measured memory_bytes: 9216
#include<bits/stdc++.h>
using namespace std;
#define pb push_back
#define int long long
#define endl "\n"
#define pii pair<int,int> 
#define ff first
#define ss second
#define mii map<int,int>
#define si set<int>
#define sti stack<int>
#define qi queue<int>
#define vi vector<int>
#define pq priority_queue<int>
#define IOS ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
const int M=1e9+7;
const double pi=3.14159265358979323846;
vector<vi> v;

void solve(){
	int n,m;
	cin>>n>>m;
	v.resize(n);
	for(int i=0;i<m;i++){
		int x,y;
		cin>>x>>y;
		x--,y--;
		v[x].pb(y);
		v[y].pb(x);
	}
	int ans[n]={0};
	bool b[n]={false};
	qi q;
	q.push(0); 
	cout<<"Yes"<<endl;
	while(q.size()>0){
		int x=q.front();
		q.pop();
		for(auto it:v[x]){
			if(!b[it]){
				b[it]=1;
				ans[it]=x+1;
				q.push(it);
			}
		}
	}
	for(int i=1;i<n;i++){
		cout<<ans[i]<<endl;
	}
}

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

Measured memory_bytes: 13160
<?php
$n = (int)trim(fgets(STDIN));

$a_map = [];
$as = [];
$max = 0;
for ($i=0; $i < $n; $i++) { 
	$a = (int)trim(fgets(STDIN));
	$as[] = $a;
	if (isset($a_map[$a])) {
		$a_map[$a] += 1;
	}else{
		$a_map[$a] = 1;
	}
	$max = max($max, $a);
}
$as_sorted = $as;
rsort($as_sorted);

$result = [];
foreach ($as as $v) {
	if ($v === $max) {
		if ($a_map[$v] > 1) {
			$result[] = $max;
		}else{
			$result[] = $as_sorted[1];
		}
	}else{
		$result[] = $max;
	}
}

echo implode(PHP_EOL, $result);

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

int dfs(vector<vector<int>>& graph,int k,vector<int>& vis, int& res)
{
	if(!vis[k])
    {
        int x=0;
        for(int i=0;i<graph[k].size();++i)
        {
        	x=max(x,dfs(graph,graph[k][i],vis,res));
        }	
        vis[k]=x+1;
        res=max(res,vis[k]);
        return vis[k];
    }
    return vis[k];
}

int main() {
	
	vector<int> vis(100005,0);
	int n,m,x,y;
	cin>>n>>m;
	vector<vector<int>>graph(n+1);
	for(int i=0;i<m;i++)
	{
		cin>>x>>y;
		graph[x].push_back(y);
	}
	int res = -1;
	for(int i=1;i<=n;i++)
	{
		if(vis[i]==0)
		dfs(graph,i,vis,res);
	}
	
	cout<<res-1;
	
	return 0;
}

Measured memory_bytes: 9472
#include<bits/stdc++.h>
#define ll long long
using namespace std;
const int N=1e5+5;
ll n,a,b,m,h[N];
bool check(ll mid)
{
	ll pnt=0;
	for(ll i=0;i<n;i++)
	{
		ll lc=h[i];
		lc-=mid*b;
		if(lc<=0)continue;
		pnt+=lc/m;
		if(lc%m!=0)pnt++;
	}
	return pnt<=mid;
}
int main()
{
	cin>>n>>a>>b;
	for(ll i=0;i<n;i++)cin>>h[i];
	m=a-b;
	ll l=0,r=1e9;
	while(l<=r)
	{
		ll mid=(l+r)>>1;
		if(check(mid))
			r=mid-1;
		else
			l=mid+1;
	}
	cout<<r+1<<endl;
	return 0;
}

Measured memory_bytes: 1024
def main():
    N = int(input())
    IDs = []
    for _ in range(N):
        IDs.append(input())
    locked = True
    M = int(input())
    for _ in range(M):
        t = input()
        if t in IDs:
            if locked:
                print('Opened by', t)
                locked = False
            else:
                print('Closed by', t)
                locked = True
        else:
            print('Unknown', t)

if __name__ == '__main__':
    main()

Measured memory_bytes: 6724
main = do
    s <- getLine
    let si = zip s [0..]
    putStrLn $ if 0 < (length $ filter (\ (x,i) -> (x == 'L' && i `mod` 2 == 0) || (x == 'R' && i `mod` 2 == 1)) si) then "No" else "Yes"


Measured memory_bytes: 380
import java.util.*

fun main(args: Array<String>) {
    val sc = Scanner(System.`in`)
    val n = sc.nextInt()
    val a = (0 until n).map { sc.next().toLong() }
    println(problem059c(n, a))
}

fun problem059c(n: Int, a: List<Long>): Long {
    val count1 = compute(n, a)
    val a = a.toMutableList()
    val a0 = a[0]
    var count = 0L
    if (a0 > 0) {
        val tmp = a0 + 1
        a[0] = a0 - tmp
        count += tmp
    } else {
        val tmp = a0 - 1
        a[0] = a0 - tmp
        count -= tmp
    }
    val count2 = compute(n, a) + count
    return Math.min(count1, count2)
}

fun compute(n: Int, a: List<Long>): Long {
    val a = a.toMutableList()
    var count = 0L
    var sum = 0L
    for (i in 0 until n) {
        if (sum + a[i] == 0L) {
            count++
            if (a[i] < 0) {
                a[i] = a[i] + 1
            } else {
                a[i] = a[i] - 1
            }
        }
        sum += a[i]
        if (i >= n - 1) {
            continue
        }
        val ai2 = a[i + 1]
        val sum2 = sum + ai2
        if (sum * sum2 < 0) {
            continue
        } else {
            if (sum > 0) {
                val tmp = sum + 1
                a[i + 1] = tmp * -1
                count += tmp + ai2
            } else {
                val tmp = Math.abs(sum - 1)
                a[i + 1] = tmp
                count += tmp - ai2
            }
        }
    }
    return count
}

Measured memory_bytes: 54860
#include <bits/stdc++.h>
using namespace std;
#define repd(i,a,b) for (int i=(a);i<(b);i++)
#define rep(i,n) repd(i,0,n)
#define all(x) (x).begin(),(x).end()
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
typedef long long ll;
const long long INF = 1LL << 60;
typedef pair<int, int> P;

bool wallcheck(int s, int e, string maze) {
    int cnt = 0;
    int len = (int)maze.size();
    repd(i, s, e) {
        if (maze[i] == '#') {
            cnt++;
        }
        else {
            cnt = 0;
        }
        if (cnt >= 2) break;
    }
    return ((cnt >= 2) ? false : true);
}

int main()
{
    int N, A, B, C, D;
    cin >> N >> A >> B >> C >> D;
    string S;
    vector<int> check(N, 0);

    cin >> S;
    A--; B--; C--; D--;
    bool flag = true;
    if (C < D) {
        if (!wallcheck(B, D, S)) flag = false;
        //S[D] = '#';
        if (!wallcheck(A, C, S)) flag = false;
    }
    else {
        if (!wallcheck(A, C, S)) flag = false;
        if (!wallcheck(B, D, S)) flag = false;
        int cnt = 0;
        rep(i, N) {
            if (S[i] == '.') cnt++;
            else cnt = 0;
            check[i] = cnt;
        }
        // rep(i, N) cout << check[i] << " ";
        // cout << endl;
        int index = 0;
        for (int i = D; i >= 0; i--) {
            if (S[i] == '#') {
                index = i;
                break;
            }
        }
        for (int i = N; i >= 0; i--) {
            if (check[i] == 0 || check[i + 1] == 0) continue;
            check[i] = check[i + 1];
        }
        // rep(i, N) cout << check[i] << " ";
        flag = false;
        repd(i, B + 1, index) {
            if (check[i] >= 3) {
                flag = true;
                break;
            }
        }
        /*
        repd(i, A, C) {
            if (check[i] >= 3) {
                cout << i << endl;
                break;
            }
        }
        cout << S[D - 1] << ":" << S[D] << endl;
        cout << D << ":" << check[D] << endl;
        */
        if (!flag && D != 0 && check[D] >= 3) {
            if (S[D - 1] != '#') {
                flag = true;
            }
        }
    }
    if (flag) cout << "Yes" << endl;
    else cout << "No" << endl;

    return 0;
}

Measured memory_bytes: 1540
import java.util.Scanner;

public class Main {

  public static void main(String[] args) {

    Scanner sc = new Scanner(System.in);
    int a = sc.nextInt();
    int b = sc.nextInt();
    int c = sc.nextInt();
    int k = sc.nextInt();
    while (a >= b) {
      b *= 2;
      k--;
    }
    while (b >= c) {
      c *= 2;
      k--;
    }

    if (k >= 0) {
      System.out.println("Yes");
    } else {
      System.out.println("No");
    }

  }
}

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

int main(){
	int monster, deathblow;
	long long hp[200200];
    cin >> monster >> deathblow;
	for(int i = 0; i < monster; ++i) cin >> hp[i];
	sort(hp, hp + monster, greater<>());
	for(int i = 0; i < deathblow; ++i) hp[i] = 0;
	cout << accumulate(hp, hp+monster, 0l) << endl;
}

Measured memory_bytes: 1792
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <vector>
#include <queue>
#include <set>
#include <map>
using namespace std;
#define int long long
#define rep(i, n) for (int i = 0; i < n; i++)
const int mo = 1e9 + 7;
int grid[3][3];
void solve()
{
    int c[3][3];
    rep(i,3)rep(j,3)cin>>c[i][j];
    int a[3],b[3];
    for(a[0]=0;a[0]<=100;a[0]++)
    {
        for(a[1]=0;a[1]<=100;a[1]++)
        {
            for(a[2]=0;a[2]<=100;a[2]++)
            {
                b[0]=c[0][0]-a[0];
                b[1]=c[0][1]-a[0];
                b[2]=c[0][2]-a[0];
                
                bool ok=1;
                rep(i,3)
                {
                    rep(j,3)
                    {
                        ok&=c[i][j]==a[i]+b[j];
                    }
                }
                if(ok)
                {
                    cout<<"Yes"<<endl;
                    return ;
                }
            }
        }
    }
    cout<<"No"<<endl;
}
main()
{
    cin.tie(0);
    ios::sync_with_stdio(0);
    solve();
    return 0;
}

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

struct dice{
    int nums[7];
};

void North(int *nums){
    nums[6]=nums[0];
    nums[0]=nums[1];
    nums[1]=nums[5];
    nums[5]=nums[4];
    nums[4]=nums[6];
}
void East(int *nums){
    nums[6]=nums[0];
    nums[0]=nums[3];
    nums[3]=nums[5];
    nums[5]=nums[2];
    nums[2]=nums[6];
}
void South(int *nums){
    nums[6]=nums[0];
    nums[0]=nums[4];
    nums[4]=nums[5];
    nums[5]=nums[1];
    nums[1]=nums[6];
}
void West(int *nums){
    nums[6]=nums[0];
    nums[0]=nums[2];
    nums[2]=nums[5];
    nums[5]=nums[3];
    nums[3]=nums[6];
}
int main(void){
    struct dice DICE[2];
    for(int i=0;i<2;i++){
        for(int j=0;j<6;j++){
            cin>>DICE[i].nums[j];
        }
    }
    for(int i=0;i<4;i++){
        if(DICE[0].nums[1]==DICE[1].nums[0])break;
        North(DICE[1].nums);
    }
    for(int i=0;i<4;i++){
        if(DICE[0].nums[1]==DICE[1].nums[0])break;
        West(DICE[1].nums);
    }
    South(DICE[1].nums);
    
    if(DICE[0].nums[4]!=DICE[1].nums[4]){
        cout<<"No"<<endl;
        return 0;
    }
    
    for(int i=0;i<4;i++){
        if(DICE[0].nums[0]==DICE[1].nums[0]&&DICE[0].nums[2]==DICE[1].nums[2]&&DICE[0].nums[3]==DICE[1].nums[3]&&DICE[0].nums[4]==DICE[1].nums[4]){
            cout<<"Yes"<<endl;
            return 0;
        }
        West(DICE[1].nums);
    }
        cout<<"No"<<endl;
    return 0;
}


Measured memory_bytes: 3120
#include <algorithm>
#include <cstdio>

// Definitions
#define MAXN 
#define elif else if
typedef long long int64;
#define File(s) freopen(#s ".in", "r", stdin), freopen(#s ".out", "w", stdout)

// Variables
int cnt, n;
bool ans;

// Functions
inline void ReadIn() {
  int a, b;
  scanf("%d", &n);
  for (int i = 1; i <= n; i++) {
    scanf("%d %d", &a, &b);
    if (a == b) {
      cnt++;
    } else {
      cnt = 0;
    }
    if (cnt == 3) {
      ans = true;
    }
  }
}
inline void PrintAns() {
  ans ? puts("Yes") : puts("No");
}

int main() {
#ifndef ONLINE_JUDGE
  File(data);
#endif
  ReadIn();
  PrintAns();
  return 0;
}
/*

*/

Measured memory_bytes: 1612
#include <stdio.h>
int X,Y,T[90][90];
int R(int x,int y,int d){
	if(0<=x&&x<X&&0<=y&&y<Y&&T[y][x]){
		T[y][x]=0;
		int t,r=R(x-1,y,d+1);
		t=R(x+1,y,d+1);if(r<t)r=t;
		t=R(x,y-1,d+1);if(r<t)r=t;
		t=R(x,y+1,d+1);if(r<t)r=t;
		T[y][x]=1;
		return r;
	}
	return d;
}
main(){
	int i,j,r,x;
	for(;scanf("%d%d",&X,&Y),X;printf("%d\n",r)){
		for(j=0;j<Y;j++)for(i=0;i<X;i++)scanf("%d",T[j]+i);
		for(r=j=0;j<Y;j++)for(i=0;i<X;i++)if(r<(x=R(i,j,0)))r=x;
	}
}

Measured memory_bytes: 628
#include <cstdio>
#include <cstdlib>
#include <iostream>
#include <fstream>
#include <sstream>
#include <set>
#include <map>
#include <vector>
#include <list>
#include <algorithm>
#include <cstring>
#include <cmath>
#include <string>
#include <stack>
#include <queue>
#include <bitset>     //UWAGA - w czasie kompilacji musi byc znany rozmiar wektora - nie mozna go zmienic
#include <cassert>
#include <iomanip>        //do setprecision
#include <ctime>
#include <complex>
using namespace std;

#define FOR(i,b,e) for(int i=(b);i<(e);++i)
#define FORQ(i,b,e) for(int i=(b);i<=(e);++i)
#define FORD(i,b,e) for(int i=(b)-1;i>=(e);--i)
#define REP(x, n) for(int x = 0; x < (n); ++x)

#define ST first
#define ND second
#define PB push_back
#define PF push_front
#define MP make_pair
#define LL long long
#define ULL unsigned LL
#define LD long double
#define pii pair<int,int>
#define pll pair<LL,LL>

const double pi = 3.14159265358979323846264;
const int mod=1000000007;


//mod演算ライブラリ
//mod=1000000007

LL add(LL a,LL b){
  return (a+b)%mod;
}

LL sub(LL a,LL b){
  return (a+mod-b)%mod;
}

LL mul(LL a,LL b){
  return ((a % mod) * (b % mod)) % mod;
}

LL power(LL x,LL y){//繰り返し二乗法 単品利用可
  if(y==0)return 1;
  else if(y==1)return x%mod;
  else if(y%2==0){
    LL tmp=power(x, y/2) % mod;
    return tmp*tmp%mod;
  }else {
    LL tmp=power(x, y/2) % mod;
    return ((tmp*tmp)%mod)*x%mod;
  }
}

LL dvs(LL a,LL b){
  return mul(a,power(b,mod-2));
}

const int SIZE_mod=200005;
int invfact[SIZE_mod];
int fact[SIZE_mod];

LL factset(int a){//aまでの階乗%mod表を作成
  fact[0]=1;
  FORQ(i,1,a){
    fact[i]=mul(fact[i-1],i);
  }
}

LL cmbset(int a){//1~aまでの階乗と階乗数の逆元のmod(mod)を用意 O(a)
  factset(a);
  invfact[a]=power(fact[a],mod-2);
  invfact[0]=1;
  FORD(i,a,1){
    invfact[i]=mul(invfact[i+1],i+1);
  }

}

LL cmb(int n,int r){//nCr%mod  (cmbset後に使用)
  if(n<r||r<0||n<0)return 0;
  return mul(fact[n],mul(invfact[r],invfact[n-r]));
}

LL prm(int n,int r){//nPr%mod
    return mul(cmb(n,r),fact[n]);
}

LL homo(int n,int r){//nHr%mod
  return cmb(n+r-1,r);
}


int main(){
	 //cin.tie(0);
	//ios::sync_with_stdio(false);
	//std::cout << std::fixed;
	//std::cout << std::setprecision(12);
	//std::cout << std::defaultfloat;
	int n,m;
	cin>>n>>m;
	vector<LL> s(n),t(m);
	FOR(i,0,n)cin>>s[i];
	FOR(i,0,m)cin>>t[i];
	vector<vector<LL>> dp=vector<vector<LL>>(n+1,vector<LL>(m+1,0));
	vector<vector<LL>> dp2=vector<vector<LL>>(n+1,vector<LL>(m+1,0));
	FOR(i,0,n){
		FOR(j,0,m){
			if(s[i]==t[j]){
				dp[i][j]=1;
				dp2[i][j]=1;
				if(i>0&&j>0){
					dp2[i][j]=dp[i][j]=add(dp[i][j],dp2[i-1][j-1]);
				}
			}
			if(j!=0){
				dp2[i][j]=add(dp2[i][j],dp2[i][j-1]);
			}
		}
		if(i!=0){
			FOR(j,0,m){
				dp2[i][j]=add(dp2[i][j],dp2[i-1][j]);
			}
		}
		//FOR(j,0,m)cerr<<dp2[i][j]<<" ";
		//cerr<<endl;
	}

	cout<<dp2[n-1][m-1]+1<<endl;

	return 0;
}


Measured memory_bytes: 62976
#define _USE_MATH_DEFINES
#include <cassert>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <string>
#include <sstream>
#include <vector>
#include <queue>
#include <stack>
#include <list>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <algorithm>
#include <complex>
#include <cmath>
#include <numeric>
#include <bitset>
#include <functional>

using namespace std;

#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>
void __f(const char* name, Arg1&& arg1){
  cerr << name << ": " << arg1 << endl;
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args){
  const char* comma = strchr(names + 1, ',');
  cerr.write(names, comma - names) << ": " << arg1 << " |";
  __f(comma + 1, args...);
}

typedef long long int64;
typedef pair<int, int> ii;
const int INF = 1 << 29;
const int MOD = 1e9 + 7;

int main() {
  string s;
  cin >> s;
  if (s[0] != 'A') {
    cout << "WA" << endl;
    return 0;
  }
  int cnt = 0;
  int n = s.size();
  for (int i = 2; i < n - 1; ++i) {
    if (s[i] == 'C') {
      ++cnt;
    }
  }
  if (cnt != 1) {
    cout << "WA" << endl;
    return 0;
  }
  cnt = 0;
  for (int i = 0; i < n; ++i) {
    if (s[i] >= 'a' && s[i] <= 'z') {
      ++cnt;
    }
  }
  if (cnt != n - 2) {
    cout << "WA" << endl;
  } else {
    cout << "AC" << endl;
  }
  return 0;
}


Measured memory_bytes: 256
import java.util.*;
import java.io.*;
import java.math.BigInteger;
 
public class Main{
	public static String toBinary(int x){
		String s = Integer.toBinaryString(x);
		for(int i = s.length(); i < 6; i++){
			s = "0" + s;
		}
		return s;
	}
    
	public static void main(String[] $){
		Scanner sc = new Scanner(System.in);
		int H = sc.nextInt();
		int W = sc.nextInt();
		int K = sc.nextInt();
		String[] c = new String[H];
		for(int i = 0; i < H; i++){
			c[i] = sc.next();
		}

		int sum = 0; 
		String iBi = "";
		String jBi = "";
		for(int i = 0; i < Math.pow(2, H); i++){
			iBi = toBinary(i);
			for(int j = 0; j < Math.pow(2, W); j++){
				jBi = toBinary(j);
				int exam = 0;
				for(int x = 0; x < H; x++){
					if(iBi.charAt(5-x) == '1') continue;
					for(int y = 0; y < W; y++){
						if(jBi.charAt(5-y) == '1') continue;
						if(c[x].charAt(y) == '#') exam++;
					}
				}
				if(exam == K) sum++;
			}
		}
		
		System.out.println(sum);
		
	}
} 

Measured memory_bytes: 39320
using System;
using System.Linq;
namespace ConsoleApp33 {
    class Program {
        static private int N;
        static private int[] h;
        
        static public int[] min;
        
        
        public static void Main(){
            GetData();
            CalculateMin();
            Console.WriteLine(min.Last());
        }
        
        public static void GetData(){
            N = int.Parse(Console.ReadLine());
            h = new int[N];
          	min = new int[N];
            var hs = Console.ReadLine().Split(' ');
            h = hs.Select(x => int.Parse(x)).ToArray();
        }
        
        public static void CalculateMin(){
            min[0] = 0;
            min[1] = Math.Abs(h[0] - h[1]);
          	min = min.Select((m, i) => min[i] = i >= 2 ? Math.Min(min[i - 1] + Math.Abs(h[i] - h[i - 1]), min[i - 2] + Math.Abs(h[i] - h[i - 2])) : min[i])
          	    .ToArray();
        }
    }
}

Measured memory_bytes: 19936
#include <iostream>
#include <cstdio>
#include <cstring>
#include <string>

using namespace std;

int main() {
	int n;
	string s;
	while (cin >> n, n) {
		cin >> s;
		int i, j, k;
		for (i = 0; i < n; ++i) {
			string tmp = "";
			for (j = 0; j < (int)s.size(); j = k) {
				int cnt = 0;
				for (k = j; s[j] == s[k]; ++k) cnt++;
				char sub[100];
				sprintf(sub, "%d", cnt);
				tmp += sub;
				tmp += s[j];
			}
			s = tmp;
		}
		cout << s << endl;
	}
}

Measured memory_bytes: 1372
a,b,m = gets.split.map(&:to_i)
as = gets.split.map(&:to_i)
bs = gets.split.map(&:to_i)
mmin = as.min + bs.min
m.times do
  ap, bp, sub = gets.split.map(&:to_i)
  res = as[ap-1] + bs[bp-1] - sub
  mmin = [mmin, res].min
end
puts mmin

Measured memory_bytes: 18588
#include <stdio.h>
#define INF 9999999999999.0
#define D 2
#define M 300000
struct Point
{
    double x[D];
} pt[M];
double dis[1 << D][M], minx[1 << D], maxx[1 << D];

void Get(int N)
{
    int tot = (1 << D);
    for (int s = 0; s < tot; s++)
    {
        int coe[D];
        for (int i = 0; i < D; i++)
            if (s & (1 << i))
                coe[i] = -1.0;
            else
                coe[i] = 1.0;

        for (int i = 0; i < N; i++)
        {
            dis[s][i] = 0.0;
            for (int j = 0; j < D; j++)
                dis[s][i] = dis[s][i] + coe[j] * pt[i].x[j];
        }
    }
}

void Solve(int N)
{
    int tot = (1 << D);
    double tmp, ans;
    for (int s = 0; s < tot; s++)
    {
        minx[s] = INF;
        maxx[s] = -INF;
        for (int i = 0; i < N; i++)
        {
            if (minx[s] > dis[s][i])
                minx[s] = dis[s][i];
            if (maxx[s] < dis[s][i])
                maxx[s] = dis[s][i];
        }
    }
    ans = 0.0;
    for (int s = 0; s < tot; s++)
    {
        tmp = maxx[s] - minx[s];
        if (tmp > ans)
            ans = tmp;
    }

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

int main()
{
    int n;
    scanf("%d", &n);
    for (int i = 0; i < n; i++)
        scanf("%lf %lf", &pt[i].x[0], &pt[i].x[1]);
    Get(n);
    Solve(n);

    return 0;
}

Measured memory_bytes: 11148
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <cmath>
#include <iomanip>
#include <stack>
#include <queue>
#include <numeric>
#include <map>
#include <unordered_map>
#include <set>
#define rep(i,n) for(int i=0;i<(n);i++)
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
#define pb push_back
#define mod 1000000007
using ll = long long;
using namespace std;

int main(){
  string S;
  cin >> S;
  int N = S.size();
  rep(i,N){
    if(i%2==0){
      if(S[i]=='L'){
        cout << "No" << endl;
        return 0;
      }
    }
    if(i%2==1){
      if(S[i]=='R'){
        cout << "No" << endl;
        return 0;
      }
    }
  }
  cout << "Yes" << endl;
  return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define M 1000000007
#define opt ios_base::sync_with_stdio(false); cin.tie(NULL);

void freak__()
{
    int n,i;
    cin >> n;
    int a[n],sum=0,sum1=0,sum2=0,cnt2=0,cnt1=0;
    for(i=0;i<n;i++)
    {
        cin >> a[i];
        sum+=a[i];
    }
    //cout << -4/5 << "\n";
    //sum1=-4; n=5;
    sum1=ceil((double)sum/(double)n);
    sum2=(sum/n);
    //cout << sum1 << "\n";
    for(i=0;i<n;i++) cnt1+=abs(a[i]-sum1)*abs(a[i]-sum1);
    for(i=0;i<n;i++) cnt2+=abs(a[i]-sum2)*abs(a[i]-sum2);
    cout << min(cnt1,cnt2) << "\n";
}

int main()
{
    opt;
    freak__();
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
using namespace std;
int main()
{
	long long n, i, a, b, t, r;
	cin >> n;
	i = 1;
	a = 1000000;
	b = -1000000;
	r = 0;
	0 < n <= 10000;
	while (i <= n)
	{
		cin >> t;
		-1000000 <= t <= 1000000;
		if (t < a) a = t;
		if (t > b) b = t;
		r += t;
		i++;
	}
	cout << a << " " << b << " " << r << endl;
}

Measured memory_bytes: 1160