akhauriyash/Code-Regression huggingface dataset:
#include <algorithm>
#include <array>
#include <bitset>
#include <cassert>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <map>
#include <memory>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <sstream>
#include <unordered_map>
#include <vector>


#define INF 4000000000000000000LL
#define MOD 1000000007
#define ALL(x) std::begin(x), std::end(x)


int main(int argc, char** argv)
{
  std::cin.tie(0);
  std::ios_base::sync_with_stdio(0);

  std::cout << std::fixed << std::setprecision(6);
  std::cerr << std::fixed << std::setprecision(6);

  long long R, G, B, N, c = 0;

  std::cin >> R >> G >> B >> N;

  for (int i = 0; i <= 3000; i ++)
    for (int j = 0; j <= 3000; j ++) {
      long long x = N - R * i - G * j;

      if (x >= 0 && x % B == 0)
        c ++;
    }

  std::cout << c << std::endl;

  return 0;
}


Measured memory_bytes: 888
#include <iostream>
#include <vector>
#include <string>
#include <math.h>
#include <algorithm>
#include <set>
#include <iomanip>
#include <stdio.h>
#include <sstream>
#include <bits/stdc++.h>
using namespace std;
int main(void){
  long double n;
  cin>>n;
  vector<long double> a(n);
  for(long long int i=0; i<n; i++){
    cin>>a.at(i);
  }
  
  sort(a.begin(),a.end());
  long double pre=a.at(n-1);
  long long int ans;
  long double mid=pre/2;
  a.erase(a.end()-1);
  auto itr=lower_bound(a.begin(),a.end(),mid);
  if(itr==a.end()){
    ans=a.at(n-2);
  }else if(itr==a.begin()){
    ans=*itr;
  }else{
    long long int a=*itr;
    long long int b=*(itr-1);
    if(abs(mid-a)<abs(mid-b)){
      ans=a;
    }else{
      ans=b;
    }
  }
  long long int hoge=floor(pre);
  cout<<hoge<<" "<<ans<<endl;
}

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

int main() {
    int N;
    cin >> N;
    vector<int>H(N);
    for(int i=0; i<N; ++i) {
        cin >> H[i];
    }
    int ans = 1;
    int highest = 0;
    for(int i=1; i<N; ++i) {
        if(H[i] >= H[highest]) {
        ans++;
        highest = i;
        }
    }
    cout << ans;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main(){
    int N,M; cin>>N>>M;
    vector<int> contest(N,0);
    int AC=0;
    int WA=0;
    for(int i=1;i<=M;i++){
        int p;cin>>p;
        string S;cin>>S;
        if(contest[p]!=-1){
            if(S=="AC"){
                AC++;
                WA=WA+contest[p];
                contest[p]=-1;
            }
            else{
                contest[p]++;
            }
        }
    }
    cout<<AC<<" "<<WA<<endl;
    return 0;
}

Measured memory_bytes: 768
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define REP(i,n) for(ll i=0, i##_len=(n); i<i##_len; ++i)
#define REPR(i,n) for(ll i = n;i >= 0;--i)
#define FOR(i,m,n) for(ll i = m, i##_len=(n);i <i##_len; ++i)
#define all(x) (x).begin(),(x).end()
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; }
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
const int INF = 1e9;
const ll LLINF = 1e16;
 
ll modinv(ll a, ll m) {
    ll b = m, u = 1, v = 0;
    while (b) {
        ll t = a / b;
        a -= t * b; swap(a, b);
        u -= t * v; swap(u, v);
    }
    u %= m;
    if (u < 0) u += m;
    return u;
}



int main(void)
{
    string s;
    cin >> s;

    string t = "";
    vector<string> component;
    component.push_back("dream");
    component.push_back("dreamer");
    component.push_back("erase");
    component.push_back("eraser");

    for (int i = s.size() - 1; i >= 0;){
        bool flag = false;
        REP(j,component.size()){

            if ( (int)(i - component[j].size() + 1) < 0)
            {
                continue;
            }

            if(s.substr(i-component[j].size() + 1,component[j].size()) == component[j]){
                flag = true;
                i -= component[j].size();
                t = component[j] + t;
                break;
            }
        }
        if(!flag){
            break;
        }
    }

    if (s == t)
    {
        cout << "YES" << endl;
    }
    else{
        cout << "NO" << endl;
    }


    return 0;
}

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

const int INF = 1 << 30;

int main() {
    int N; cin >> N;
    vector<vector<int>> G(N);
    for(int i = 0; i < N - 1; ++i) {
        int a, b; cin >> a >> b;
        a--, b--;
        G[a].emplace_back(b);
        G[b].emplace_back(a);
    }

    int K; cin >> K;
    vector<int> P(N, -1);
    int v, p;
    for(int i = 0; i < K; ++i) {
        cin >> v >> p; v--;
        P[v] = p;
    }

    vector<int> parity(N);

    auto pfs = [&](auto &&pfs, int cur, int pre, int p) -> bool {
        parity[cur] = p;
        if(P[cur] != -1 and P[cur] % 2 != parity[cur]) return false;
        bool res = true;
        for(auto &to : G[cur]) {
            if(to == pre) continue;
            res &= pfs(pfs, to, cur, 1 - p);
        }
        return res;
    };

    if(!pfs(pfs, v, v, P[v] % 2)) return cout << "No" << '\n', 0;

    vector<pair<int, int>> rng(N);

    auto dfs = [&](auto &&dfs, int cur, int pre) -> pair<int, int> {
        int l = -INF, r = INF;
        for(auto &to : G[cur]) {
            if(to == pre) continue;
            int tl, tr; tie(tl, tr) = dfs(dfs, to, cur);
            tl--, tr++;
            l = max(l, tl), r = min(r, tr);
        }
        if(P[cur] != -1) l = max(l, P[cur]), r = min(r, P[cur]);
        while(abs(l) % 2 != parity[cur]) l++;
        while(abs(r) % 2 != parity[cur]) r--;
        return rng[cur] = {l, r};
    };

    dfs(dfs, v, v);
    for(int i = 0; i < N; ++i) {
        if(rng[i].first > rng[i].second) return cout << "No" << '\n', 0;
    }

    auto efs = [&](auto &&efs, int cur, int pre, int n) -> void {
        P[cur] = n;
        for(auto &to : G[cur]) {
            if(to == pre) continue;
            int l, r; tie(l, r) = rng[to];
            if(l <= n - 1 and n - 1 <= r) efs(efs, to, cur, n - 1);
            else efs(efs, to, cur, n + 1);
        }
    };
    efs(efs, v, v, P[v]);

    cout << "Yes" << '\n';
    for(int i = 0; i < N; ++i) {
        cout << P[i] << '\n';
    }
    return 0;
}


Measured memory_bytes: 22272
a,b,c = map(int,input().split())
k = int(input())
i = 1
if c>b>a:
    print("Yes")
elif b<=a:
    if b*2**k<=a:
        print("No")
    else:
        while True:
            if b*2**i>a:
                break
            else:
                i+=1
        b = b*2**i
        i = k-i
        if c*2**i<=b:
            print("No")
        else:
            print("Yes")
elif c<=b:
    if c*2**k<=b:
        print("No")
    else:
        print("Yes")

Measured memory_bytes: 9136
package main

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

type edge struct {
	to    int
	value int
}

var edges [][]edge
var vertex []int
var visited []bool

func fillNumber(x int) bool {
	visited[x] = true
	for _, e := range edges[x] {
		if !visited[e.to] {
			vertex[e.to] = vertex[x] + e.value
			if !fillNumber(e.to) {
				fmt.Println("No")
				os.Exit(0)
			}
		} else if vertex[e.to] != vertex[x]+e.value {
			return false
		}
	}
	return true
}

func main() {
	in := IOInitialize()
	n, m := Int(in), Int(in)

	if m == 0 || m == 1 {
		fmt.Println("Yes")
		return
	}

	edges = make([][]edge, n)
	for i := range edges {
		edges[i] = make([]edge, 0, 32)
	}

	for i := 0; i < m; i++ {
		l, r, d := Int(in)-1, Int(in)-1, Int(in)
		edges[l] = append(edges[l], edge{to: r, value: d})
		edges[r] = append(edges[r], edge{to: l, value: -d})
	}

	vertex = make([]int, n)
	visited = make([]bool, n)

	for i := range visited {
		if !visited[i] {
			visited[i] = true
			if !fillNumber(i) {
				fmt.Println("No")
				return
			}
		}
	}
	fmt.Println("Yes")
}

//////////
//
//

func IOInitialize() *bufio.Scanner {
	t := bufio.NewScanner(os.Stdin)
	t.Split(bufio.ScanWords)
	return t
}

func Int(s *bufio.Scanner) int {
	if !s.Scan() {
		panic("\t\tThere is a FALSE not to want.")
	}

	value, err := strconv.Atoi(s.Text())
	if err != nil {
		panic("\t\tError:Failed to convert text to int,")
	}
	return value
}

func IntArray(s *bufio.Scanner, size int) []int {
	deepArray := make([]int, size)
	for i := range deepArray {
		deepArray[i] = Int(s)
	}
	return deepArray
}

func GraphSetByEdge(s *bufio.Scanner, v int) [][]int {
	g := make([][]int, v)
	for i := range g {
		g[i] = make([]int, 0)
	}
	for xxNonUsedInLoopI := 0; xxNonUsedInLoopI < v-1; xxNonUsedInLoopI++ {
		a, b := Int(s)-1, Int(s)-1
		g[a] = append(g[a], b)
		g[b] = append(g[b], a)
	}

	return g
}


Measured memory_bytes: 111232
S = raw_input().strip()
a, b = S[0:2], S[2:]

ia = int(a)
ib = int(b)

if ib == 0:
    if ia >= 1 and ia <=12: 
        print('MMYY')
        exit()

if ia == 0:
    if ib >= 1 and ib <= 12:
        print('YYMM')
        exit()

if ia > 12:
    if ib > 12:
        print('NA')
    elif ib > 0:
        print('YYMM')
    else:
        print('NA')
elif ia >= 1:
    if ib >=1 and ib <= 12:
        print('AMBIGUOUS')
    elif ib > 12:
        print('MMYY')
    else:
        print('NA')
else:
    if ib == 0:
        print('NA')
    elif ib <= 12:
        print('YYMM')
    else:
        print('NA')

Measured memory_bytes: 2692
def shuffle(l,k,n):
    if k:return l[k:] + l[:k]
    else:return [l[i+n*f]for i in range(n)for f in [0,1]]

n = int(input())
l = [i+1 for i in range(2*n)]
for _ in range(int(input())):
    l = shuffle(l,int(input()),n)
[print(e)for e in l]

Measured memory_bytes: 7680
import java.util.Scanner;

//AtCoder Grand Contest 148
//D	Brick Break
public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int N = Integer.parseInt(sc.next());
		int[] aArr = new int[N];
		boolean hasOne = false;
		for (int i = 0; i < N; i++) {
			aArr[i] = Integer.parseInt(sc.next());
			if (aArr[i] == 1) {
				hasOne = true;
			}
		}
		sc.close();

		int ans = 0;
		if (hasOne) {
			int target = 1;
			for (int i = 0; i < N; i++) {
				if (aArr[i] == target) {
					target++;
				} else {
					ans++;
				}
			}
			System.out.println(ans);
		} else {
			System.out.println(-1);
		}
	}
}


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

using namespace std;
int main()
{

     int a,b,c,k;
     cin>>a>>b>>c>>k;
     if(k<=a)
          cout<<k<<endl;
     else if(k<=a+b)
          cout<<a<<endl;
     else
          cout<<a-(k-a-b)<<endl;
     return 0;
}


Measured memory_bytes: 3608
#include <iostream>
#include <cstring>
#include <stdlib.h>
#include <vector>
#include <algorithm>
#include <cmath>
#include <stack>
#include <queue>
#include <math.h>
#include <string>
#include <map>
using namespace std;
typedef long long ll;
ll mod=1000000007;

int main()
{
    string S;
    cin >> S;
    vector< vector <ll> > dp(S.size(), vector<ll>(13, 0));
    
    if(S[0]=='?'){
        for(int i=0; i<10; i++) dp[0][i]=1;
    }else{
        dp[0][S[0]-(int)'0']=1;
    }

    for(int n=1; n<S.size(); n++){
        if(S[n]=='?'){
            for(int i=0; i<13; i++){
                for(int j=0; j<10; j++){
                    dp[n][i]+=dp[n-1][(j*13+i)/10]%mod;
                }
            }
        }else{
            for(int i=0; i<13; i++){
                dp[n][(i*10+(int)S[n]-(int)'0')%13]+=dp[n-1][i]%mod;
            }
        }
    }
    cout << dp[S.size()-1][5]%mod << endl;

    return 0;
}


Measured memory_bytes: 13696
#include <iostream>

using namespace std;

int main(){
    int N, K;
    cin >> N >> K;
    long x[50];
    long y[50];
    long ans = __LONG_MAX__;
    for(int i = 0; i < N; i++){
        cin >> x[i] >> y[i];
    }
    for(int i = 0; i < N; i++){
        for(int j = 0; j < i; j++){
            long x1, y1, x2, y2;
            x1 = min(x[i], x[j]);
            y1 = min(y[i], y[j]);
            x2 = max(x[i], x[j]);
            y2 = max(y[i], y[j]);
            int cnt = 0;
            for(int m = 0; m < N; m++){
                if(x[m] >= x1 && x[m] <= x2 && y[m] >= y1 && y[m] <= y2) cnt++;
            }
            if(cnt >= K) ans = min(ans, (x2-x1)*(y2-y1));
        }
    }
    
    for(int i = 0; i < N; i++){
        for(int j = 0; j < i; j++){
            for(int k = 0; k < j; k++){
                long x1, y1, x2, y2;
                x1 = min(min(x[i], x[j]), x[k]);
                y1 = min(min(y[i], y[j]), y[k]);
                x2 = max(max(x[i], x[j]), x[k]);
                y2 = max(max(y[i], y[j]), y[k]);
                int cnt = 0;
                for(int m = 0; m < N; m++){
                    if(x[m] >= x1 && x[m] <= x2 && y[m] >= y1 && y[m] <= y2) cnt++;
                }
                //cout << (x2-x1)*(y2-y1) << endl;
                if(cnt >= K) ans = min(ans, (x2-x1)*(y2-y1));
            }
        }
    }
    for(int i = 0; i < N; i++){
        for(int j = 0; j < i; j++){
            for(int k = 0; k < j; k++){
                for(int l = 0; l < k; l++){
                    long x1, y1, x2, y2;
                    x1 = min(min(x[i], x[j]), min(x[k], x[l]));
                    y1 = min(min(y[i], y[j]), min(y[k], y[l]));
                    x2 = max(max(x[i], x[j]), max(x[k], x[l]));
                    y2 = max(max(y[i], y[j]), max(y[k], y[l]));
                    int cnt = 0;
                    for(int m = 0; m < N; m++){
                        if(x[m] >= x1 && x[m] <= x2 && y[m] >= y1 && y[m] <= y2) cnt++;
                    }
                    //cout << (x2-x1)*(y2-y1) << endl;
                    if(cnt >= K) ans = min(ans, (x2-x1)*(y2-y1));
                }
            }
        }
    }
    cout << ans << endl;
}

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

using namespace std;

int main(){
  long long int a,b,k; cin >> a >> b >> k;
  if(a+b <= k) cout << "0 0" << endl;
  else if(a < k) cout << 0 << " " << b - (k-a) << endl;
  else cout << a-k << " " << b << endl;
  return 0;
}


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

n, k = [int(i) for i in input().split(' ')]

arr = [int(i) for i in input().split(' ')]

dp = [10**10]*n

k += 1
dp[0] = 0

for i in range(0, n):
    for j in range(1, k):
        if i+j < n:
            dp[i+j] = min(dp[i+j], dp[i] + abs(arr[i+j]-arr[i]))

print(dp[n-1])


Measured memory_bytes: 84464
import math
N = int(input())
e = [0] * (N+1)

def prime_factorize(n):
    a = []
    while n % 2 == 0:
        a.append(2)
        n //= 2
    f = 3
    while f * f <= n:
        if n % f == 0:
            a.append(f)
            n //= f
        else:
            f += 2
    if n != 1:
        a.append(n)
    return a

import collections

for i in range(2,N+1):
  c = collections.Counter(prime_factorize(i))
  for key,value in c.items():
    e[key] += value
#print(e)

def num(m):
  return len(list(filter(lambda x: x >= m-1,e)))

print(num(75) + num(25) * (num(3) - 1) + num(15) * (num(5) - 1)
     + num(5) * (num(5) - 1) * (num(3) - 2) // 2)

Measured memory_bytes: 3316
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<n;i++)
using namespace std;
const int INF=INT_MAX,MOD=1e9+7;

int main(){
    int n,k; cin>>n>>k;
    if(n%k==0) cout<<0<<endl;
    else cout<<1<<endl;
    return 0;
}


Measured memory_bytes: 764
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll zero = 0;
const ll INF = 10000000000000000; //10^16
const ll MOD = 1000000007; //10^9+7
const ll MOD2 = 998244353;


int main(void){
    ll N;
    cin >> N;
    
    vector<ll> cnt(N + 1, 0);
    cnt.at(0) = 3;
    ll tmp;
    ll ans = 1;
    for(ll i = 0; i < N; i++){
        cin >> tmp;
        ans = ans * (cnt.at(tmp) - cnt.at(tmp + 1)) % MOD;
        cnt.at(tmp + 1)++;
    }
    
    printf("%lld\n", ans);
}


Measured memory_bytes: 1024
#include<iostream>
#include<cstring>
#include<string>
#include<cstdio>
using namespace std;
int main(){
	string s;
	cin>>s;
	int g=0,p=0;
	int res=0;
	for(int i=0;i<s.size();i++){
		if(g==p){
			g++;
			if(s[i]=='p'){
				res--;
			}
		}
		else if(g>p){
			if(s[i]=='g'){
				p++;
				res++;
			}
			else{
				p++;
			}
		}
	}

	cout<<res<<endl;
	return 0;
}

Measured memory_bytes: 512
#include<bits/stdc++.h>
using namespace std;
typedef long long LL; 
map<int,LL>mmp;
int qq[100000+100];
int pp[100000+100];
int len=0;
int main()
{
	LL n,m;
	scanf("%lld %lld",&n,&m);
	LL sum=0;
	LL uu=0;
	mmp[0]=++len;
	qq[len]=0;
	pp[len]++;
	for(int i=0;i<n;i++)
	{
		LL num;
		scanf("%lld",&num);
		uu+=num;
		int p=uu%m;
		if(mmp[p]==0)
		{
			mmp[p]=++len;
			qq[len]=p;
			pp[len]++;
		}
		else
			pp[mmp[p]]++;
	}
	for(int i=1;i<=len;i++)
		sum+=(LL)(pp[i]-1)*(LL)pp[i]/2;
	printf("%lld\n",sum);
	return 0;
}

Measured memory_bytes: 4736
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ABC044A
{
    class Program
    {
        static void Main(string[] args)
        {
            int a, b, c, d,e,f;
            a=int. Parse(Console.ReadLine());
            b = int.Parse(Console.ReadLine());
            c = int.Parse(Console.ReadLine());
            d = int.Parse(Console.ReadLine());
            if (a > b)
            {
                e = b * c;
                f = (a - b) * d + e;
            }
           
            else
            {
                f = a * c;
            }
            Console.WriteLine(f);
            Console.
                ReadKey();
        }
    }
}


Measured memory_bytes: 13140
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		String S = sc.next();
		String T = sc.next();
		if(T.startsWith(S) && S.length() + 1 == T.length()){
			System.out.println("Yes");
		}else{
			System.out.println("No");			
		}
	}
}


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

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


Measured memory_bytes: 640
#include <iostream>
#include <algorithm>
#include <string>
#include <math.h>
#include <cstdint>
#include <vector>
#include <map>

using namespace std;
typedef long long ll;



ll ans,mx,mn=1e8,sum,cnt;
int main(){
	ll n,m;
	cin>>n>>m;
	ll a[m];
	for(ll i=0; i<m; i++){
		cin>>a[i];
	}
	sort(a,a+m);
	ll b[m-1],idx=0;
	for(ll i=0; i<m; i++){
		if(i<m) b[idx++] = abs(a[i]-a[i+1]);
	}
	sort(b,b+m-1);
	
	ans = m-n;
	if(ans <=0) cout<<0;
	else {
		for(ll i=0; i<ans; i++){
			sum +=b[i];
		}
		cout<<sum<<endl;
	}
}

Measured memory_bytes: 1792
// AUTHOR : Kishan Srivastav
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define mod 1000000007
#define in freopen("input.txt", "r", stdin)
#define out freopen("output.txt", "w", stdout)
#define ios ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);


int main() {
	ios
#ifndef ONLINE_JUDGE
	in;
	out;
#endif
	int n;
	cin>>n;
	string s;
	cin>>s;
	if(n % 2 != 0){
		cout<<"No"<<endl;
	}else{
		int l = 0;
		int r = n/2;
		bool flag = true;
		while(l != (n /2) &&  r != (n) ){
			if(s[l] != s[r]){
				flag = false;
				break;
			}else{
				l++;
				r++;
			}
		}
		if(flag == true){
			cout<<"Yes"<<endl;
		}else{
			cout<<"No"<<endl;
		}
	}

}

Measured memory_bytes: 3608
#include <iostream>
#include <vector>
#include <deque>
#include <algorithm>
#include <numeric>
#include <string>
#include <cstring>
#include <list>
#include <unordered_set>
#include <tuple>
#include <cmath>
#include <limits>
#include <type_traits>
#include <iomanip>
#include <map>
#include <unordered_map>
#include <queue>
#include <stack>
#include <set>
#include <bitset>
#include <regex>
#include <random>
#include<bits/stdc++.h>

using namespace std;

typedef long long ll;
#define rep(i,n)for(ll i=0;i<n;++i)
#define exout(x) printf("%.10f\n", x)
const double pi = acos(-1.0);
const ll MOD = 1000000007;
const ll INF = 1e10;
const ll MAX_N = 1010;

//最大公約数
ll gcd(ll x, ll y) {
	return y ? gcd(y, x % y) : x;
}

ll lcm(ll x, ll y) {
	if (x == 0 || y == 0)return 0;
	return (x / gcd(x, y) * y);
}

ll dp[101010][110];
ll dx[4] = { 0,0,-1,1 };
ll dy[4] = { -1,1,0,0 };

//long longしか使わない
//素数は1より大きい
int main() {
	ll k, t;
	cin >> k >> t;
	vector<ll>a(t);
	rep(i, t) {
		cin >> a[i];
	}
	sort(a.rbegin(), a.rend());
	ll ans = a[0] - 1;
	for (ll i = 1;i < t;++i) {
		ans = max(ll(0), ans - a[i]);
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 3600
#pragma GCC optimize(3)
#include<bits/stdc++.h>
#define MAXN 100005
#define INF 1000000000
#define MOD 1000000007
#define F first
#define S second
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
string str;
int n,k,a[MAXN];
vector<int> G[MAXN];
int cnt[MAXN],dp[MAXN],low[MAXN];
void dfs(int v,int p)
{
    dp[v]=low[v]=0;
    cnt[v]=(str[v]=='1'?1:0);
    P tmp=P(0,0);
    for(auto to:G[v])
    {
        if(to==p) continue;
        dfs(to,v);
        dp[v]+=dp[to]+cnt[to];
        cnt[v]+=cnt[to];
        tmp=max(tmp,P(dp[to]+cnt[to],low[to]+cnt[to]));
    }
    if(tmp.S>dp[v]-tmp.F) low[v]=tmp.S-(dp[v]-tmp.F);
    else low[v]=dp[v]&1;
}
int main()
{
    scanf("%d",&n);
    cin>>str;
    for(int i=0;i<n-1;i++)
    {
        int u,v;
        scanf("%d%d",&u,&v);
        u--; v--;
        G[u].push_back(v);G[v].push_back(u);
    }
    int ans=INF;
    for(int i=0;i<n;i++)
    {
        dfs(i,-1);
        if(low[i]==0) ans=min(ans,dp[i]);
    }
    if(ans==INF) puts("-1"); else printf("%d\n",ans/2);
    return 0;
}

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

/*
  // Time complexity
  O(v + e) (v: 頂点の数, e: 辺の数)

  // Initialization
  StronglyConnectedComponents scc = StronglyConnectedComponents(n); (n: 頂点の数)
  scc.add_edge(u, v, c); (u: start, v: to)
  scc.build();
*/

struct StronglyConnectedComponents {
    int n;
    vector< vector< int > > g;
    vector< vector< int > > rg;
    vector< bool > used;
    vector< int > order, comp;
    StronglyConnectedComponents(int n) : n(n), g(n), rg(n), used(n, false), comp(n, -1) { }
    void add_edge(int u, int v) {
        g[u].push_back(v);
        rg[v].push_back(u);
    }
    void build() {
        for (int i = 0; i < n; ++i) {
            if(!used[i]) dfs(i);
        }
        int cnt = 0;
        reverse(order.begin(), order.end());
        for(int i : order) {
            if(comp[i] == -1) rdfs(i, cnt++);
        }
    }
    int operator[](int k) {
        return comp[k];
    }
    void dfs(int idx) {
        used[idx] = true;
        for (int to : g[idx]) {
            if (!used[to]) dfs(to);
        }
        order.push_back(idx);
    }
    void rdfs(int idx, int cnt) {
        comp[idx] = cnt;
        for (int to : rg[idx]) {
            if(comp[to] == -1) rdfs(to, cnt);
        }
    }
};

/*
    verified http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=GRL_3_C&lang=jp
*/
int main() {
    int v, e; cin >> v >> e;
    StronglyConnectedComponents scc = StronglyConnectedComponents(v);
    for (int i = 0; i < e; ++i) {
        int s, t; cin >> s >> t;
        scc.add_edge(s, t);
    }
    scc.build();
    int q; cin >> q;
    vector< int > us(q), vs(q);
    for (int i = 0; i < q; ++i) {
        cin >> us[i] >> vs[i];
    }
    for (int i = 0; i < q; ++i) {
        cout << (scc[us[i]] == scc[vs[i]] ? 1 : 0) << endl;
    }
}



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

using namespace std;

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    int n;
    long long k;
    cin >> n >> k;
    vector<int> xs(n);
    for (int& x: xs) {
        cin >> x;
    }
    int m = *max_element(xs.begin(), xs.end());
    vector<pair<int, int>> move(n+1);
    move[n] = make_pair(0, 1);
    vector<int> first(m+1, -1);
    for (int i = n-1; i >= 0; --i) {
        first[xs[i]] = i;
    }
    vector<int> last_seen(m+1, -1);
    for (int i = n-1; i >= 0; --i) {
        if (last_seen[xs[i]] == -1) {
            if (first[xs[i]] == -1) {
                move[i] = make_pair(i+1, 1);
            } else {
                move[i] = make_pair(first[xs[i]]+1, 1);
            }
        } else {
            move[i] = make_pair(last_seen[xs[i]] + 1, 0);
        }
        last_seen[xs[i]] = i;
    }
    int pos = 0;
    int cycle_length = 0;
    while (pos < n) {
        cycle_length += move[pos].second;
        pos = move[pos].first;
    }
    ++cycle_length;
    k = (k-1) % cycle_length + 1;
    pos = 0;
    while (k > 1) {
        k -= move[pos].second;
        pos = move[pos].first;
    }
    while (pos < n) {
        if (move[pos].second) {
            cout << xs[pos] << " ";
            ++pos;
        } else {
            pos = move[pos].first;
        }
    }
    cout << endl;
    return 0;
}

Measured memory_bytes: 5376
N,M=map(int,input().split())
bridges = [1]*N
islandswar = [[] for _ in range(N+1)]
for i in range(M):
    a,b = map(int,input().split())
    islandswar[b].append(a)
count = 0
currightest = 0

def check(a,b):
    for i in range(a,b):
        if bridges[i] == 0:
            return False
    return True
    

for i in range(2,N+1):
    for j in range(0,len(islandswar[i])):
        if islandswar[i][j] >= currightest:
            if check(islandswar[i][j],i):
                bridges[i-1] = 0
                currightest = i
                count += 1

print(count)

Measured memory_bytes: 17460
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		long a = sc.nextLong();
		long b = sc.nextLong();
		long c = sc.nextLong();
		long k = sc.nextLong();
		sc.close();
		System.out.println(k % 2l == 0 ? a - b : b - a);
	}
}

Measured memory_bytes: 23764
import scala.io.StdIn._

object Main extends App {

  def display(a: Array[Int]) {
    a.zipWithIndex.foreach{ case (x, i) => {
      print(x)
      if (i+1 != a.length) print(" ")
    }}
    println()
  }

  def insertionSort(a: Array[Int], n: Int) {
    for (i <- (1 to n-1)) {
      var x = a(i)
      var j = i - 1
      while (j >= 0 && a(j) > x) {
        a(j+1) = a(j)
        j -= 1
      }
      a(j+1) = x
      display(a)
    }
    
  }

  val n = readLine.toInt
  val a = readLine.split(" ")
                  .map(s => s.toInt)
                  .toArray
  display(a)
  insertionSort(a, n)
}


Measured memory_bytes: 51440
n=int(input())
if n==1:
    print('Yes')
    print(2)
    print(1,1)
    print(1,1)
    exit()
if n==2:
    print('No')
    exit() 
a=[[1]]
i=1
for j in range(1,n):
    a.append(list(range(i,i+j)))
    if n==i+j-1:
        break
    elif i+j>n:
        print('No')
        exit()
    i+=j
print('Yes')
m=len(a)
for i in range(m-1):
    for j in range(i+1+(i<1),m):
        a[i].append(a[j][i])
print(m)
for b in a:
    print(len(b),*b)

Measured memory_bytes: 51932
#include <iostream>
#include <vector>
using namespace std;
typedef long long ll;

int main(){
    int N;
    ll A,B;
    cin >> N >> A >> B;
    ll inf = 1e18;
    vector<int> l(N+1,0),p(N+1,0);
    for(int i=1;i<=N;i++) cin >> p[i];
    vector<vector<ll>> dp(N+1,vector<ll>(N+1,inf));
    for(int i=1;i<=N;i++) for(int j=1;j<=N;j++){
        if(p[j]==i) break;
        if(p[j]>i) l[i]++;
    }
    for(int j=0;j<=N;j++) dp[0][j] = 0;
    for(int i=1;i<=N;i++) for(int j=0;j<=N;j++){
        if(j<=l[i]){
            dp[i][j] = min(dp[i][j],dp[i-1][j]+B);
            dp[i][l[i]] = min(dp[i][l[i]],dp[i-1][j]);
        }else dp[i][j-1] = min(dp[i][j-1],dp[i-1][j]+A);
    }
//    for(int i=0;i<=N;i++) for(int j=0;j<=N;j++) cerr << dp[i][j] << (j!=N? " ":"\n");
    cout << dp[N][0] << endl;
}

Measured memory_bytes: 195840
import java.util.*;
public class Main {

    public static void main(String[] args) {

        Scanner in = new Scanner(System.in);
        int n = in.nextInt();
        int k = in.nextInt();
        int cnt = 0;
        for (int i = 0; i < n; i++) {

            int x = in.nextInt();
            if (x >= k) {
                cnt++;
            }

        }

        System.out.println(cnt);

    }

}


Measured memory_bytes: 46632
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int ss, se;
        System.out.println(0);
        String ret = sc.next();
        if(ret.equals("Vacant")){
            return;
        }else if(ret.equals("Male")){
            ss = 0;
        }else{
            ss = 1;
        }
        System.out.println(n-1);
        ret = sc.next();
        if(ret.equals("Vacant")){
            return;
        }else if(ret.equals("Male")){
            se = 0;
        }else{
            se = 1;
        }
        
        solve(0, n/2, n-1, ss, se, sc);
    }

    public static boolean solve(int s, int m, int e, int ss, int se, Scanner sc){
        System.out.println(m);
        String ret = sc.next();
        if(ret.equals("Vacant")){
            return true;
        }else if(ret.equals("Male")){
            if(ss == 0){
                if((m-s) % 2 == 0){
                    return solve(m, m+(e-m)/2, e, 0, se, sc);
                }else{
                    return solve(s, s+(m-s)/2, m, ss, 0, sc);
                }
            }else{
                if((m-s) % 2 == 0){
                    return solve(s, s+(m-s)/2, m, ss, 0, sc);
                }else{
                    return solve(m, m+(e-m)/2, e, 0, se, sc);
                }
            }
        }else{
            if(ss == 0){
                if((m-s) % 2 == 0){
                    return solve(s, s+(m-s)/2, m, ss, 1, sc);
                }else{
                    return solve(m, m+(e-m)/2, e, 1, se, sc);
                }
            }else{
                if((m-s) % 2 == 0){
                    return solve(m, m+(e-m)/2, e, 1, se, sc);
                }else{
                    return solve(s, s+(m-s)/2, m, ss, 1, sc);
                }
            }
        }
    }
}

Measured memory_bytes: 24356
import os

def main():
    n = input()
    if(int(n[-1]) == 2): 
        print("hon")
    elif (int(n[-1]) == 4):
        print("hon")
    elif (int(n[-1]) == 5):
        print("hon")
    elif (int(n[-1]) == 7):
        print("hon")
    elif (int(n[-1]) == 9):
        print("hon")
    elif (int(n[-1]) == 0):
        print("pon")
    elif (int(n[-1]) == 1):
        print("pon")
    elif (int(n[-1]) == 6):
        print("pon")
    elif (int(n[-1]) == 8):
        print("pon")
    else:
        print("bon")

if __name__ == "__main__":
    main()

Measured memory_bytes: 9176
#include<stdio.h>
int main(void){
	int x[10000],a,i;
	i=1;
	while(1)
		{
		scanf("%d",&x[i]);
		if(x[i]==0){
			break;
		}
		a=i;
		i++;
	}
	i=0;
	i=1;
	while(i<=a){
	printf("Case %d: %d\n",i,x[i]);
	i++;
	}
	return 0;
}

Measured memory_bytes: 640
#define _USE_MATH_DEFINES
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cctype>
#include <clocale>
#include <cmath>
#include <cstdlib>
#include <ctime>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <tuple>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>

using namespace std;

#define IOS ios::sync_with_stdio(false); cin.tie(0);
#define FOR(i, s, n) for(int i = (s), i##_len=(n); i < i##_len; ++i)
#define FORS(i, s, n) for(int i = (s), i##_len=(n); i <= i##_len; ++i)
#define VFOR(i, s, n) for(int i = (s); i < (n); ++i)
#define VFORS(i, s, n) for(int i = (s); i <= (n); ++i)
#define REP(i, n) FOR(i, 0, n)
#define REPS(i, n) FORS(i, 0, n)
#define VREP(i, n) VFOR(i, 0, n)
#define VREPS(i, n) VFORS(i, 0, n)
#define RFOR(i, s, n) for(int i = (s), i##_len=(n); i >= i##_len; --i)
#define RFORS(i, s, n) for(int i = (s), i##_len=(n); i > i##_len; --i)
#define RREP(i, n) RFOR(i, n, 0)
#define RREPS(i, n) RFORS(i, n, 0)
#define ALL(v) (v).begin(), (v).end()
#define SORT(v) sort(ALL(v))
#define RSORT(v) sort(ALL(v), greater<decltype(v[0])>())
#define SZ(x) ((int)(x).size())
#define PB push_back
#define EB emplace_back
#define MP make_pair
#define MT make_tuple
#define BIT(n) (1LL<<(n))
#define UNIQUE(v) v.erase(unique(ALL(v)), v.end())

using ll = long long;
using ull = unsigned long long;
using Pi_i = pair<int, int>;
using VB = vector<bool>;
using VC = vector<char>;
using VD = vector<double>;
using VI = vector<int>;
using VLL = vector<ll>;
using VS = vector<string>;
using VSH = vector<short>;
using VULL = vector<ull>;

const int MOD = 1000000007;
const int INF = 1000000000;
const int NIL = -1;

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


int main(){
    int n, m; cin >> n;
    VI a(n);
    REP(i, n) cin >> a[i];
    cin >> m;
    VI b(m);
    REP(i, m) cin >> b[i];
    VI res;
    set_intersection(ALL(a), ALL(b), inserter(res, res.end()));
    REP(i, res.size()){
        cout << res[i] << "\n";
    }
    return 0;
}



Measured memory_bytes: 4836
#include <iostream>
#include <vector>
#include <string>
#include <numeric>
#include <algorithm>
#include <math.h>
using namespace std;

int main() {

	long long A;
	long long B;
	
	cin >> A;
	cin >> B;

	long long ansA = 0;
	long long ansB = 1;

	long long iA = 1;
	long long iB = 1;

	while (ansA != ansB) {
		ansA = A * iA;
		ansB = B * iB;

		if (ansA > ansB) {
			iB++;
		}
		else if (ansA < ansB) {
			iA++;
		}
		else {
			break;
		}
	}

	cout << ansA << endl;

	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
typedef long long ll;
using namespace std;
#define repr(i,a,b) for(int i=a;i<b;i++)
#define rep(i,n) for(int i=0;i<n;i++)
#define invrepr(i,a,b) for(int i=b-1;i>=a;i--)
#define invrep(i,n) invrepr(i,0,n)
#define repitr(itr,a) for(auto itr=a.begin();itr!=a.end();++itr)
const int MOD=1e9+7;

vector<pair<int,int>> vectorCnt(vector<int> a) {
    sort(a.begin(),a.end());
    int n=a.size();
    vector<pair<int,int>> b;
    int cnt=1;
    rep(i,n-1) {
            if (a[i+1]!=a[i]) {
                b.push_back(make_pair(cnt,a[i]));
                cnt=1;
            } else {
                ++cnt;
            }
    }
    b.push_back(make_pair(cnt,a[n-1]));
    return b;
}

int main() {
    ios_base::sync_with_stdio(false);    
    
    string s;
    cin >> s;
    int m=0;
    int ten_ele=1;
    int n=s.size();
    vector<int> a(n+1);
    rep(i,n) {
        a[i+1]=(a[i]+ten_ele*(s[n-1-i]-'0'))%2019;
        ten_ele=(10*ten_ele)%2019;
    } 
    vector<pair<int,int>> p=vectorCnt(a);
    sort(p.begin(),p.end(),greater<>());
    ll ans=0;
    rep(i,p.size()) {
        ll cnt=p[i].first;
        ans+=cnt*(cnt-1)/2;
    }
    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 5264
#include <iostream>
#include <string>
#include <cmath>
#include<algorithm>
#include<stack>
#include<queue>
#include<map>
#include<set>
#include<iomanip>
#define _USE_MATH_DEFINES
#include <math.h>
#include <functional>
using namespace std;

#define rep(i,x) for(int i=0;i<x;i++)
#define repn(i,x) for(int i=1;i<=x;i++)

typedef long long ll;
const ll INF = 1e17;
const ll MOD = 1000000007;
const ll MAX = 1000001;

ll max(ll a, ll b) {
	if (a > b) { return a; }
	return b;
}

ll min(ll a, ll b) {
	if (a > b) { return b; }
	return a;
}

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

ll lcm(ll a, ll b) {
	return a * b / gcd(a, b);
}



///////////////////////////


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

	ll A = 0;

	repn(i, N) {
		ll a;
		cin >> a;
		A += a;
	}

	if (A >= H) { cout << "Yes"; }
	else { cout << "No"; }

	
}


Measured memory_bytes: 256
L_MAX = 1000
N, A, B, C = map(int, input().split())
l = [None] * N
for i in range(N):
    l[i] = int(input())
D = [A, B, C]

mp_min = 3 * L_MAX
for bit in range(4 ** N):
    bamboos = [[], [], []]
    b = bit
    #print("b =", b)
    for i in range(N):
        if b % 4 < 3:
            bamboos[b % 4].append(l[i])
            #print("append l[{}] = {} to bamboos[{}]".format(i, l[i], b % 3))
        b //= 4 
    if any(map(lambda x: x == [], bamboos)):
        continue

    #for i in range(3):
    #    print("bamboos[{}] = {}".format(i, bamboos[i]))

    mp = 0
    for i in range(3):
        mp += abs(D[i] - sum(bamboos[i])) + 10 * (len(bamboos[i]) - 1)
    #print("mp =", mp)
    mp_min = min(mp_min, mp)
print(mp_min)

Measured memory_bytes: 3188
# -*- coding: utf-8 -*-
import sys
sys.setrecursionlimit(10**9)
INF=10**18
MOD=10**9+7
def input(): return sys.stdin.readline().rstrip()

def main():
    A,B,C,X,Y=map(int,input().split())
    ans=INF
    for i in range(max(X,Y)+1):
        tmp=C*2*i+A*max(X-i,0)+B*max(Y-i,0)
        ans=min(ans,tmp)
    print(ans)

if __name__ == '__main__':
    main()


Measured memory_bytes: 39152
#include <bits/stdc++.h>
 
using namespace std;
 
typedef long long ll;
typedef long double ld;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef pair<int, int> ii;
typedef vector<ii> vii;
 
#define fi first
#define se second
#define endl '\n'
#define MOD(n,k) ( (n % k) + k ) % k
#define isOn(S, j) (S & (1 << j) )
#define setBit(S, j) (S | (1 << j ) )
#define LSB(S) (S & (-S))

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

    int n, d4 = 0, d2 = 0, a;

    cin >> n;
    for (int i = 0; i < n; i++) {
        cin >> a;
        if (a % 4 == 0)
            d4++;
        else if (a % 2 == 0)
            d2++;
    }

    n -= d4 * 2;
    if (n <= 1) {
        cout << "Yes" << endl;
        return 0;
    }

    n -= d2;
    if (n <= 0)
        cout << "Yes" << endl;
    else
        cout << "No" << endl;

    return 0;
}  

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

int main(){
  int i,j,k,n,T,L,B,x,b[101],aa;
  double a[2][101],l[101];
  while(1){
    cin >> n >> T >> L >> B;
    if(n == 0 && !T && !L && !B) break;
    for(i=0;i<=n;i++){
      for(j=0;j<2;j++) l[i] = a[j][i] = b[i] = 0;
    }
    for(i=0;i<L;i++){
      cin >> x;
      b[x] = 1;
    }
    for(i=0;i<B;i++){
      cin >> x;
      b[x] = 2;
    }

    a[1][0] = 1;
    aa = 0;

    for(i=0;i<T;i++){
      for(j=0;j<=n;j++){
	a[0][j] = a[1][j];
	a[1][j] = l[j];
	l[j] = 0;
      }

      for(j=0;j<n;j++){
	for(k=j+1;k<=j+6;k++){
	  if(k <= n){
	    if(b[k] == 0) a[1][k] += a[0][j] / 6;
	    else if(b[k] == 1) l[k] += a[0][j] / 6;
	    else if(b[k] == 2) a[1][0] += a[0][j] / 6;
	  }
	  else if(k > n){
	    int kk = n - (k - n);
	    if(b[kk] == 0) a[1][kk] += a[0][j] / 6;
	    else if(b[kk] == 1) l[kk] += a[0][j] / 6;
	    else if(b[kk] == 2) a[1][0] += a[0][j] / 6;
	  }
	}
      }

      a[1][n] += a[0][n];
    }




    printf("%.6f\n",a[1][n]);

  }
  return 0;
}

Measured memory_bytes: 0
N,Q = map(int,input().split())

adj = [list() for _ in range(N)]
for _ in range(N-1):
    a,b = map(int,input().split())
    adj[a-1].append(b-1)
    adj[b-1].append(a-1)

memo = [0]*N
for _ in range(Q):
    p,x = map(int,input().split())
    memo[p-1] += x

stack = [(None,0)]
while stack:
    p,v = stack.pop()
    for u in adj[v]:
        if u != p:
            memo[u] += memo[v]
            stack.append((v,u))

print(*memo)

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

int ans, d[11], n, m, num[11], cnt, S, c;
string s;

bool check(){
  
  int sum=0;
  
  for(int i=0;i<cnt;i++){
    
    int di=d[i];
    
    if(i<c) di*=2;
    
    if(di>=10) di=di%10+di/10;

    sum+=di;
  }

  return (sum+S)%10==0;
}

void dfs(int x){
  
  if(x==cnt){
    
    if(check()) ans++;

    return;
  }
  
  for(int i=0;i<m;i++){
    d[x]=num[i];
    dfs(x+1);
  }
  
}

int main(){

  cin>>n;
  
  cin>>s;
  
  reverse(s.begin(), s.end());
  
  for(int i=0;i<n;i++)
    if(s[i]=='*'){
      cnt++;
      if(i%2) c++;
    }

  for(int i=0;i<n;i++){
    if(s[i]=='*') continue;
    int t=s[i]-'0';
    if(i%2) t*=2;
    if(t>=10) t=t%10+t/10;
    S+=t;
  }  
  
  cin>>m;
  
  for(int i=0;i<m;i++) cin>>num[i];
  
  dfs(0);

  cout<<ans<<endl;
  
  return 0;
}



Measured memory_bytes: 3304
def e_common_subsequence(N, M, S, T, MOD=10**9 + 7):
    # dp[i][j]: S[i], T[j] まで考慮したとき、この2つをペアにしたときの場合の数
    dp = [[0] * (M + 1) for _ in range(N + 1)]
    total = [[0] * (M + 1) for _ in range(N + 1)]

    ans = 1  # 空の列は常に等しい列である
    for i in range(N):
        for j in range(M):
            if S[i] == T[j]:
                dp[i + 1][j + 1] = (total[i][j] + 1) % MOD
                ans = (ans + dp[i + 1][j + 1]) % MOD
            total[i + 1][j + 1] = (total[i][j + 1] + total[i + 1][j]
                                   - total[i][j] + dp[i + 1][j + 1] + MOD) % MOD
    return ans

N, M = [int(i) for i in input().split()]
S = [int(i) for i in input().split()]
T = [int(i) for i in input().split()]
print(e_common_subsequence(N, M, S, T))

Measured memory_bytes: 104156
#include <bits/stdc++.h>
using namespace std;
#define rep0(i,n) for(ll (i) = 0; (i) < (n); ++(i))
#define rrep0(i,n) for(ll (i) = (n) - 1; (i) >= 0; --(i))
#define rep1(i,n) for(ll (i) = 1; (i) <= (n); ++(i))
#define rrep1(i,n) for(ll (i) = (n); (i) >= 1; --(i))
#define nfor(i,a,b) for(ll (i) = (a); (i) < (b); ++(i))
#define rfor(i,a,b) for(ll (i) = (a); (i) > (b); --(i))
#define ll long long
#define mod (1000000007)
#define YES cout << "YES" << endl;
#define Yes cout << "Yes" << endl;
#define yes cout << "yes" << endl;
#define NO cout << "NO" << endl;
#define No cout << "No" << endl;
#define no cout << "no" << endl;
#define all(x) (x).begin(),(x).end()

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

ll lcm(ll a,ll b){
    ll g = gcd(a,b);
    return a / g * b;
}

ll factorial(ll n){
    ll t = 1;
    rep1(i, n)t *= i;
    return t;
}

ll combinations(ll n, ll k) {
    ll r = 1;
    for (ll d = 1; d <= k; ++d) {
        r *= n--;
        r /= d;
    }
    return r;
}
int main()
{
    int n;
    ll ans,cnt1,cnt2;
    cin >> n;
    vector<vector<int> > f(n,vector<int>(10));
    vector<vector<ll> > p(n,vector<ll>(11));
    rep0(i, n){
        rep0(j, 10){
            cin >> f.at(i).at(j);
        }
    }
    
    rep0(i, n){
        rep0(j, 11){
            cin >> p.at(i).at(j);
        }
    }
    rep1(i, (1 << 10) - 1){
        cnt1 = 0;
        rep0(j, n){
            cnt2 = 0;
            rep0(k, 10){
                if((i >> k) & 1 && f.at(j).at(k))++cnt2;
            }
            cnt1 += p.at(j).at(cnt2);
        }
        if(i == 1)ans = cnt1;
        ans = max(ans, cnt1);
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 256
/*
    Author:zeke

    pass System Test!
    GET AC!!
*/
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cmath>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <utility>
#include <vector>
using ll = long long;
using ld = long double;
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(), (x).end()
#define rep3(var, min, max) for (ll(var) = (min); (var) < (max); ++(var))
#define repi3(var, min, max) for (ll(var) = (max)-1; (var) + 1 > (min); --(var))
#define Mp(a, b) make_pair((a), (b))
#define F first
#define S second
#define Icin(s) \
    ll(s);      \
    cin >> (s);
#define Scin(s) \
    ll(s);      \
    cin >> (s);
template <class T>
bool chmax(T& a, const T& b) {
    if (a < b) {
        a = b;
        return 1;
    }
    return 0;
}
template <class T>
bool chmin(T& a, const T& b) {
    if (b < a) {
        a = b;
        return 1;
    }
    return 0;
}
typedef pair<ll, ll> P;
typedef vector<ll> V;
typedef vector<V> VV;
typedef vector<P> VP;
ll mod = 1e9 + 7;
ll MOD = 1e9 + 7;
ll INF = 1e18;
// cout << "Case #" << index << " :IMPOSSIBLE";
int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(10);
    ll d;
    cin >> d;
    V C(26);
    rep(i, 26) cin >> C[i];
    VV S(d, V(26));
    rep(i, d) { rep(j, 26) cin >> S[i][j]; }
    V prev(26,-1);
    rep3(i,0,d){
        ll reg=-INF;
        ll res=0;
        rep(j,26){
            ll temp=0;
            temp+=S[i][j];
            rep(k,26){
                if(j==k){
                    continue;
                }
                temp-=C[k]*(i-prev[k]);
            }
            if(chmax(reg,temp)){
                res=j+1;
            }
        }
        prev[res-1]=i;
        cout<<res<<endl;
    }
}


Measured memory_bytes: 3744
import java.util.*;
public class Main{
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    int a = sc.nextInt();
    int b = sc.nextInt();
    int x = sc.nextInt();

    if(a>x){
      System.out.println("NO");
    }else{
      if(b>=x-a){
        System.out.println("YES");
      }else{
        System.out.println("NO");
      }
    }
  }
}


Measured memory_bytes: 22612
def main():
    import sys
    input = sys.stdin.readline
    x = int(input().rstrip('\n'))
    mp = 0
    for i in range(int(x ** 0.5) + 1):
        for j in range(int(x ** 0.5) + 1):
            p = pow(i, j)
            if p <= x:
                mp = max(p, mp)
    print(mp)


if __name__ == '__main__':
    main()


Measured memory_bytes: 38384
import java.util.*;


public class Main {
    public static void main(String[] args) 
    {
        Scanner sc=new Scanner(System.in);
        int sheep=sc.nextInt(); //羊の数
        int wolves=sc.nextInt(); //狼の数
        
            if(sheep>wolves)
            {
                System.out.println("safe"); //襲われない
            }
            else
            {
                System.out.println("unsafe"); //襲われる
            }
        
    }
}





Measured memory_bytes: 35712
using System;
using System.Collections;
using System.Collections.Generic;
using System.Text;
using System.IO;
using System.Linq;
using System.Diagnostics;
using System.Globalization;
using static System.Console;
using static System.Math;


namespace abc101_a
{
    class Program
    {
        static void Main(string[] args)
        {
            string str = Console.ReadLine();
            int count=0;
            for(int i=0; i<str.Length; i++){
                if(str[i]=='+')count++;
                if(str[i]=='-')count--;
            }
            WriteLine(count);
        }

        /// 値のスワップ
        static void Swap<T>(ref T lhs, ref T rhs)
        {
            T temp;
            temp = lhs;
            lhs = rhs;
            rhs = temp;
        }


    }
}

Measured memory_bytes: 11092
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  long x,y,ans;
  cin>>x;
  ans=0;
  y=100;
  while(true){
    ans++;
    y=y*1.01;
    if(y>=x){
      break;
    }
  }
  cout<<ans;
}

Measured memory_bytes: 3632
#include <bits/stdc++.h>
using namespace std;
typedef long long LL;
const LL mod=1000000007;
#define MAX 10000

int H,W,D,A;
int Q,L,R;
int px [90001] , py [90001];
int d [90001];
int main ()
{
    scanf ("%d%d%d",&H ,&W ,&D);
    for (int i=0;i<H;i++)
    {
        for (int j=0;j<W;j++)
        {
            scanf ("%d",&A);
            px[A]=i,py[A]=j;
        }
    }
    for (int i=D+1;i <=H*W;i++)
        d[i]=d[i-D]+ abs(px[i]-px[i-D ])+ abs(py[i]-py[i-D ]);
    scanf ("%d",&Q);
    while (Q--)
    {
        scanf ("%d%d",&L ,&R);
        printf ("%d\n",d[R]-d[L]);
    }
  	return 0;
}

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

int main(){
  int n;
  cin >> n;
  int A[n];
  double count=0;
  for (int i=0;i<n;i++){
    cin >> A[i];
    count +=1.0/double(A[i]);
  }
  cout << fixed << setprecision(6) << double(1.0)/count << endl;
}


Measured memory_bytes: 256
N = int(input())
list = input().split()
d = [int(n) for n in list]
sum = 0
sum_minus = 0
for i in range(N):
  sum_minus += d[i]*d[i]
  for k in range(N):
    sum += d[i]*d[k]
print(int((sum - sum_minus)/2)) 

Measured memory_bytes: 3060
#include "bits/stdc++.h"
using namespace std;
int main() {
	int N;
	cin >> N;
	map<int,int>mp;
	for (int n = 0;n<N;++n) {
		int num;
		cin >> num;
		mp[num] = n;
	}
	set<int>S; 
	S.insert(-1); 
	S.insert(N);
	long long ans = 0;
	for (int n = N; n > 0; --n) {
		int num = mp[n];
		S.insert(num);
		int l1, l2;
		{
			set<int>::iterator it = S.find(num);
			it--;
			l2 = *it;
			if (-1 != *it) {
				it--;
			}
			l1 = *it;
		}
		int r1, r2;
		{
			set<int>::iterator it = S.find(num);
			it = S.find(num);
			it++;
			r1 = *it;
			if (N != *it) {
				it++;
			}
			r2 = *it;
		}
		ans += (long long)n*(r2 - r1)*(num-l2);
		ans += (long long)n*(l2 - l1)*(r1-num);
	}
	cout << ans <<endl;
	return 0;
}

Measured memory_bytes: 12916