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

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

	int ans = 1;
	sort(d, d+n);
	for (int i = 1; i < n; i++) {
		if (d[i-1] < d[i]) {
			ans++;
		}
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 256
i=3;main(n,j){scanf("%d",&n);if(n==3)return!printf("2 3 25");for(;j=(n-i+1)/2*2,!(0<j&&j<5001&&i<15001);i+=3);for(i=n-j;i--;printf("%d ",2*i+2));for(;j--;printf("%d ",6*j+3));return 0;}

Measured memory_bytes: 256
#include<bits/stdc++.h>
typedef long long ll;
#define pii pair<int,int>
#define ff first
#define ss second
using namespace std;
void fast()
{
ios::sync_with_stdio(false);
cin.tie(NULL); cout.tie(NULL);
}
int prime_n[200005];
void prime(int n)
{
    for(int i=0;i<=n;i++) prime_n[i]=1;
    for (int i=2;i<=n;i++)
    {
      for (int j=i*i;j<=n;j+=i)
      {
         prime_n[j]=0;
      }
    }
}
int main()
{
    ll a[200005],n,ans,c;
    cin>>n;
    for(int i=0;i<n;i++)
    cin>>a[i];
    sort(a,a+n);
    ans=a[n-1];
    c=n-2;
    for(int i=1;i<n-1;i++)
    {
        ans+=a[c];
        if(i%2==0)
        --c;
    }
    cout<<ans<<endl;
}


Measured memory_bytes: 5208
#include <bits/stdc++.h>
using namespace std;
//#include <boost/multiprecision/cpp_int.hpp>
//using multiInt = boost::multiprecision::cpp_int;

using ll = long long int;
using ld = long double;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
template<typename Q_temp>
using smaller_queue = priority_queue <Q_temp, vector<Q_temp>, greater<Q_temp> >;

const int INF = (int) 1e9;
const ll LINF = (ll) 4e18;
const ll MOD = (ll) (1e9 + 7);
const double PI = acos(-1.0);

#define REP(i,m,n) for(ll i = m; i < (ll)(n); ++i)
#define rep(i,n) REP(i, 0, n)
#define MP make_pair
#define MT make_tuple
#define YES(n) cout << ((n) ? "YES" : "NO") << endl
#define Yes(n) cout << ((n) ? "Yes" : "No") << endl
#define Possible(n) cout << ((n) ? "Possible" : "Impossible") << endl
#define all(v) v.begin(), v.end()
#define NP(v) next_permutation(all(v))
#define dbg(x_) cerr << #x_ << ":" << x_ << endl;
#define dbg2(x_) for(auto a_ : x_) cerr << a_ << " "; cerr << endl;
#define dbg3(x_ , sx_) rep(i, sx_) cerr << x_[i] << " "; cerr << endl;
vector<int> Dx = {0, 0, -1, 1, -1, 1, -1, 1, 0};
vector<int> Dy = {1, -1, 0, 0, -1, -1, 1, 1, 0};

inline ll CEIL(ll a, ll b) {
    return (a + b - 1) / b;
}

void finish() {
    cout << -1 << endl;
    exit(0);
}

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

ll f(ll l, ll r, ll d) {
    l = CEIL(l, d) * d;
    r = (r / d) * d;
    return (r - l) / d + 1;
}

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll a, b, c, d;
    cin >> a >> b >> c >> d;
    ll g = __gcd(c, d);
    cout << (b - a + 1) - (f(a, b, c) + f(a, b, d) - f(a, b, c / g * d)) << endl;
    return 0;
}



Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int c[100][100],k,len=0;
long long dp[101][5];
string n;
int dfs(int idx,bool is0,bool limit,int used){
    if(idx>len)return 0;
	if(idx==len&&used==0)return 1;
	if(!limit&&dp[idx][used]!=-1)return dp[idx][used];
	int maxn=limit?(n[idx]-'0'):9,ans=0;
	for(int i=0;i<=maxn;i++){
		if(i!=0&&used==0)continue;
		if(is0&&i==0)ans+=dfs(idx+1,1,limit&&(i==maxn),used);
		else ans+=dfs(idx+1,0,limit&&(i==maxn),used-(i!=0));
	}
	if(!limit&&!is0)dp[idx][used]=ans;
	return ans;
}
int solve(){
	memset(dp,-1,sizeof(dp));
	return dfs(0,1,1,k);
}
int main(){
    c[0][0]=1;
    for(int i=1;i<100;i++){
        c[i][0]=1;
        for(int j=1;j<100;j++){
            c[i][j]=c[i-1][j]+c[i-1][j-1];
        }
    }
    cin>>n>>k;
    len=n.size();
    //cout<<len<<endl;
    cout<<solve()<<endl;
    return 0;
}

Measured memory_bytes: 384
import itertools


def warshall_floyd(G):
    import copy
    ret = copy.deepcopy(G)
    for k in range(N):
        for i in range(N):
            for j in range(N):
                ret[i][j] = min(ret[i][j], ret[i][k] + ret[k][j])
    return ret


N, M, R = map(int, input().split())
r = list(map(int, input().split()))
G = [[10 ** 10] * N for _ in range(N)]
for _ in range(M):
    A, B, C = map(int, input().split())
    G[A - 1][B - 1] = C
    G[B - 1][A - 1] = C
W, ans = warshall_floyd(G), 10 ** 10
for p in itertools.permutations(r, R):
    ans = min(ans, sum([W[p[i] - 1][p[i + 1] - 1] for i in range(R - 1)]))
print(ans)


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

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;

#define REP(i, n) for(int i=0; i<(n); ++i)
#define FOR(i, a, b) for(int i=(a); i<(b); ++i)
#define FORR(i, a, b) for(int i=(b)-1; i>=(a); --i)

#define DEBUG(x) cout<<#x<<": "<<x<<'\n'
#define DEBUG_VEC(v) cout<<#v<<":";REP(i, v.size())cout<<' '<<v[i];cout<<'\n'
#define ALL(a) (a).begin(), (a).end()

#define CHMIN(a, b) a=min((a), (b))
#define CHMAX(a, b) a=max((a), (b))

const ll MOD=1000000007ll;
// const ll MOD=998244353ll;
#define FIX(a) ((a)%MOD+MOD)%MOD

const double EPS=1e-11;
#define EQ0(x) (abs((x))<EPS)
#define EQ(a, b) (abs((a)-(b))<EPS)

ll dp[1333][1333];

int main(){
	ios::sync_with_stdio(false);
	cin.tie(0);
	int h, w;
	string a[1333];
	cin>>h>>w;
	REP(i, h){
		cin>>a[i];
	}
	dp[0][0]=1;
	REP(i, h){
		REP(j, w){
			if(j+1<w && a[i][j+1]!='#'){
				dp[i][j+1]=(dp[i][j+1]+dp[i][j])%MOD;
			}
			if(i+1<h && a[i+1][j]!='#'){
				dp[i+1][j]=(dp[i+1][j]+dp[i][j])%MOD;
			}
		}
	}
	cout<<dp[h-1][w-1]<<'\n';
	return 0;
}


Measured memory_bytes: 13568
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define all(x) (x).begin(),(x).end()
using namespace std;
using ll = long long;
using P = pair<int,int>;
template <class T> void chmin(T &a, const T &b) noexcept { if (b < a) a = b; }
template <class T> void chmax(T &a, const T &b) noexcept { if (a < b) a = b; }
void debug_out() { cout << endl; }
template <typename Head, typename... Tail>
void debug_out(Head H, Tail... T) { cout << H << " "; debug_out(T...); }
#ifdef _DEBUG
  #define debug(...) debug_out(__VA_ARGS__)
#else
  #define debug(...) 
#endif

int main() {
  std::cin.tie(nullptr);
  std::ios_base::sync_with_stdio(false);
  std::cout << std::fixed << std::setprecision(15);
  ll n,k;
  cin >> n >> k;
  ll ans = 0;
  if (k % 2 == 1) {
    ll res = n/k; //n以下のkの倍数の個数
    ans = res * res * res;
  }
  else {
    ll x = n/k; //n以下のkの倍数の個数
    ll y = (n + k/2)/k;
    ans = x*x*x + y*y*y; //n以下のkで割ってk/2あまる数の個数
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 256
n = int(input())
s = []
for i in range(n):
    s.append(input())

m = int(input())
t = []
for i in range(m):
    t.append(input())

dic = {}
for item in s:
    if item not in dic.keys():
        dic[item] = 0
    dic[item] += 1

for item in t:
    if item not in dic.keys():
        dic[item] = 0
    dic[item] -= 1

ans = max(dic.values())

if ans < 0:
    print(0)
else:
    print(ans)

Measured memory_bytes: 38512
B = [0]*20
A = [0]*20
def main():
    count = 0
    N, M, C = map(int, input().split())
    sum = C
    B =  list(map(int, input().split()))
    for i in range(N):
        A[i] = list(map(int, input().split()))
    for i in range(N):
        for j in range(M):
            sum += A[i][j]*B[j]
        if sum > 0:
            count += 1
        sum = C
    print(count)

main()


Measured memory_bytes: 3064
#include <bits/stdc++.h>
#define ll long long int
// #define fastio ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
using namespace std;

int main() 
{
    // fastio;

    // #ifndef ONLINE_JUDGE
    // freopen("input.txt","r",stdin);
    // freopen("output.txt","w",stdout);
    // #endif

    int n;
    cin>>n;
    vector<int> a(n);
    vector<int> b(n);
    vector<int> c(n);

    for(int i=0;i<n;i++)
    	cin>>a[i]>>b[i]>>c[i];

    vector<vector<int>> dp(3,vector<int>(n,INT_MIN));

    dp[0][0] = a[0];
    dp[1][0] = b[0];
    dp[2][0] = c[0];
    for(int i = 1; i < n; i++) {
        dp[0][i] = a[i] + max(dp[1][i-1], dp[2][i-1]);
        dp[1][i] = b[i] + max(dp[0][i-1], dp[2][i-1]);
        dp[2][i] = c[i] + max(dp[0][i-1], dp[1][i-1]);
    }
    cout << max(max(dp[0][n-1], dp[1][n-1]), dp[2][n-1]) <<endl;

    return 0;
}		

Measured memory_bytes: 2944
import sys

s=str(input())

for i in range(len(s)):
  if (i+1)%2==1:
    if s[i]=="R" or s[i]=="U" or s[i]=="D":
      continue
    else:
      print("No")
      sys.exit()

  else:
    if s[i]=="L" or s[i]=="U" or s[i]=="D":
      continue
    else:
      print("No")
      sys.exit()

print("Yes")

Measured memory_bytes: 38384
#include <bits/stdc++.h>
using namespace std;
typedef long long  ll;
#define FOR(i,a,n) for(ll i=(ll)a;i<(ll)n;i++)
#define RFOR(i,a,n) for(ll i=(ll)n-1;i >= (ll)a;i--)
#define rep(i,n) FOR(i,0,n)
#define rrep(i,n) RFOR(i,0,n)
#define ALL(v) v.begin(), v.end()
ll MOD = 1000000007;
ll INF = 200000000000000000;
double EPS = 1e-12;
double PI = 3.141592653589793238;
template<typename T>
void remove(std::vector<T>& vector, unsigned int index){
    vector.erase(vector.begin() + index);
}

ll dp[10010][2][110];

int main(){
  string K;
  ll D,N;
  cin >> K >> D;
  N = K.size();
  dp[0][0][0] = 1;
  rep(i,N){
    ll n = K[i] - '0';
    rep(j,2){
      rep(k,D){
        for(ll l = 0;(l < 10) && (j || (l <= n));l++){
          dp[i+1][j | (l < n)][(k+l) % D] += dp[i][j][k];
        }
        dp[i+1][0][k] %= MOD;
        dp[i+1][1][k] %= MOD;
      }
    }
  }
  ll ans = (dp[N][0][0] + dp[N][1][0]) % MOD - 1;
  if(ans < 0) ans += MOD;
  cout << ans << endl;
} 

Measured memory_bytes: 17408
from functools import reduce
#!/usr/bin/env python3

import math


def lcm_base(x, y):
    return (x * y) // math.gcd(x, y)


def lcm(*numbers):
    return reduce(lcm_base, numbers, 1)


def lcm_list(numbers):
    return reduce(lcm_base, numbers, 1)


def main():
    N = int(input())
    T = [int(input()) for i in range(N)]
    ans = lcm_list(T)
    print(ans)


if __name__ == "__main__":
    main()


Measured memory_bytes: 9464
import java.util.Scanner;

public class Main {

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

		Dice d = new Dice(scan.nextInt(), scan.nextInt(), scan.nextInt(), scan.nextInt(), scan.nextInt(),
				scan.nextInt());
		Dice d2 = new Dice(scan.nextInt(), scan.nextInt(), scan.nextInt(), scan.nextInt(), scan.nextInt(),
				scan.nextInt());
		if (d2.checkEqual(d))
			System.out.println("Yes");
		else
			System.out.println("No");

		scan.close();
		System.exit(0);
	}

}

class Dice {
	int Upp, Sou, Est, Wst, Nor, Bot;

	public Dice(int upp, int sou, int est, int wst, int nor, int bot) {
		Upp = upp;
		Sou = sou;
		Est = est;
		Wst = wst;
		Nor = nor;
		Bot = bot;
	}

	public boolean checkEqual(Dice d) {
		String pattern = "WWWSWWWSWWWSSWWWSSSWWWWWSWWW ";
		for (int i = 0; i < pattern.length(); i++) {
			if (equal(d))
				return true;
			operate(pattern.charAt(i));
		}
		return false;
	}

	public boolean equal(Dice d) {
		if (Upp == d.getUpp() && Sou == d.getSou() && Est == d.getEst() && Wst == d.getWst() && Nor == d.getNor()
				&& Bot == d.getBot())
			return true;
		else
			return false;
	}

	public void rotate(int upp, int sou) {
		if (sou == Wst || sou == Est)
			operate('E');
		for (int i = 0; i < 4; i++) {
			if (sou == Sou)
				break;
			operate('N');
		}
		for (int i = 0; i < 4; i++) {
			if (upp == Upp)
				break;
			operate('E');
		}
	}

	public int getEst() {
		return Est;
	}

	public int getWst() {
		return Wst;
	}

	public int getNor() {
		return Nor;
	}

	public int getBot() {
		return Bot;
	}

	public int getSou() {
		return Sou;
	}

	public void operate(char op) {
		int tmp;
		switch (op) {
		case 'S':
			tmp = Upp;
			Upp = Nor;
			Nor = Bot;
			Bot = Sou;
			Sou = tmp;
			break;
		case 'E':
			tmp = Upp;
			Upp = Wst;
			Wst = Bot;
			Bot = Est;
			Est = tmp;
			break;
		case 'W':
			tmp = Upp;
			Upp = Est;
			Est = Bot;
			Bot = Wst;
			Wst = tmp;
			break;
		case 'N':
			tmp = Upp;
			Upp = Sou;
			Sou = Bot;
			Bot = Nor;
			Nor = tmp;
			break;
		}
	}

	public int getUpp() {
		return Upp;
	}

}

Measured memory_bytes: 26480
S = input()
S = S[::-1]
T = ''
U = ['maerd', 'remaerd', 'esare', 'resare']
while True:
    S1 = S[:5]
    S2 = S[:6]
    S3 = S[:7]
    if S1 == U[0] or S1 == U[2]:
        S = S[5:]
    elif S2 == U[3]:
        S = S[6:]
    elif S3 == U[1]:
        S = S[7:]
    else:
        print('NO')
        exit()
    if S == '':
        print('YES')
        exit()


Measured memory_bytes: 3188
N,M = gets.chomp.split.map(&:to_i)
list = gets.split.map(&:to_i)
# list = M.times.map{ gets.chomp.split('').map(&:to_i) }.transpose
# puts list[1].class
ans = 0

for i in 0..M-1 do
  ans = ans + list[i]
end

if ans > N
  puts -1
else
  puts N - ans
end

Measured memory_bytes: 14484
#include<iostream>
#include<cstdio>
#include<cmath>
#include<algorithm>
using namespace std;

double dis(double x1,double y1,double x2,double y2){
  return sqrt( (x1-x2)*(x1-x2) + (y1-y2)*(y1-y2) );
}

int main(){
  int n;
  double x[100],y[100];
  double adjx,adjy;


  while(1){
    cin >> n;
    if(!n)break;

    for(int i=0;i<n;i++)scanf("%lf,%lf",&x[i],&y[i]);

    int m = 0;
    for(int i=0;i<n;i++){
      for(int j=0;j<n;j++){
	if(dis(x[i],y[i],x[j],y[j]) <= 2.0 + 1e-10){
	  if(i==j){
	    adjx = x[i];
	    adjy = y[i];
	  }else{
	    double mx = (x[i]+x[j])/2.0,my = (y[i]+y[j])/2.0;
	    double d = dis(x[i],y[i],mx,my);
	    double len = sqrt(1 - d*d);
	    double nx = -1.0 * (my-y[i]),ny = mx-x[i];
	    double dn = dis(0.0,0.0,nx,ny);
	    adjx = (nx * len)/dn + mx;
	    adjy = (ny * len)/dn + my;
	  }
	  int c = 0;
	  for(int k=0;k<n;k++){
	    if(dis(adjx,adjy,x[k],y[k]) <= 1.0 +  1e-10)c++;
	  }
	  m = max(m,c);
	}
      }
    }

    cout << m << endl;
  }
}
	

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

const int M = (int)1e9+7;
typedef long long LL;

void fastIO_test(void)
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);

    #ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
    #endif
}

 
int countDivisors(int n) 
{ 
    int cnt = 0; 
    for (int i = 1; i <= sqrt(n); i++) { 
        if (n % i == 0) { 
            // If divisors are equal, 
            // count only one 
            if (n / i == i) 
                cnt++; 
  
            else // Otherwise count both 
                cnt = cnt + 2; 
        } 
    } 
    return cnt; 
} 
 
void solve(void)
{
   int n;
   cin >> n;
   
   //sieve();
   LL total = 0;
   LL x=n-1; 
   for(int c=1; c<n; c++)
	{
		total += (x/c);
	}
	cout << total << "\n";	
}

int main()
{
    fastIO_test();

    LL t=1;
    //cin >> t;
    while (t--)
    {
        solve();
    }
    return 0;
}


Measured memory_bytes: 3616
import math
A = int(input())
B = int(input())
C = int(input())
X = int(input())

cnt = 0
for i in range(A + 1):
    for j in range(B + 1):
        for k in range(C + 1):
            if i * 500 + j * 100 + k * 50 == X:
                cnt += 1
print(cnt)


Measured memory_bytes: 3060
#include "iostream"
#include "algorithm"
#include "string"
using namespace std;

int main() {
	int n;
	cin >> n;
	int ans = 0;
	for (int i = 1; i <= n; i++) {
		int cnt = 1;
		int c = i;
		while (c / 10 >= 1) {
			c /= 10;
			cnt++;
		}
		if (cnt % 2 == 1)ans++;
	}
	cout << ans << endl;
}

Measured memory_bytes: 256
s = input()
n = len(s)
if s == s[::-1]:
    if s[:(n-1)//2] == s[(n+3)//2-3::-1] and s[(n+3)//2-1:] == s[:(n-1)//2:-1]:
        print("Yes")
    else:
        print("No")
else:
    print("No")


Measured memory_bytes: 3060
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define FAST ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define int ll
#define pii pair <int,int>
#define pipii pair <int,pair <int,int>>
#define mp make_pair
#define sz(var) (int)var.size()
const int maxinput=200005;
const int inf=1e15+7;
#define vi vector <int>
string x;
int opt_pos[maxinput];
int merger(int l1_org,int r1_org,int l2_org,int r2_org)
{
    int temp[r2_org-l1_org+1];
    int ret=0;
    int k=0;
    int l1=l1_org,l2=l2_org,r1=r1_org,r2=r2_org;
    while(l1<=r1 && l2<=r2)
    {
        if(opt_pos[l1]<opt_pos[l2])
        {
            temp[k]=opt_pos[l1];
            k++;l1++;
        }
        else
        {
            ret+=r1-l1+1;
            temp[k]=opt_pos[l2];
            l2++;k++;
        }
    }
    while(l1<=r1)
    {
        temp[k]=opt_pos[l1];
        l1++;
        k++;
    }
    while(l2<=r2)
    {
        temp[k]=opt_pos[l2];
        l2++;
        k++;
    }

    k=0;
    for(int i=l1_org;i<=r2_org;i++)
    {
        opt_pos[i]=temp[k];
        k++;
    }
    return(ret);
}
int inv(int l,int r)
{
    if(l==r)
        return(0);

    int mid=(l+r)/2;
    return(inv(l,mid)+inv(mid+1,r)+merger(l,mid,mid+1,r));
}

signed main() 
{
    FAST
    cin>>x;
    int n=x.length();
    map <char,vector <int>> mymap;
    for(int i=0;i<n;i++)
        mymap[x[i]].push_back(i);
    
    vector <pii> pal_pairs;
    int oddcounter=0;
    int summ=0;
    for(auto itr=mymap.begin();itr!=mymap.end();itr++)
    {
        vector <int> vec=(*itr).second;
        if(sz(vec)%2==1)
        {
            oddcounter++;
            if(oddcounter>=2)
            {
                cout<<-1<<endl;
                return(0);
            }
        }
        int k=sz(vec);
        for(int i=0;i<(k+1)/2;i++)
        {
            if(i==k-1-i)
            {
                pal_pairs.push_back(mp(vec[i],-1));
                continue;
            }
            pal_pairs.push_back(mp(vec[i],vec[k-1-i]));
        }
    }
    sort(pal_pairs.begin(),pal_pairs.end());
    int curr=0;
    for(int i=0;i<sz(pal_pairs);i++)
    {
        int idx1=pal_pairs[i].first;
        int idx2=pal_pairs[i].second;
        //cout<<idx1<<" "<<idx2<<endl;
        if(idx2==-1)
        {
            opt_pos[idx1]=n/2;
            continue;
        }
        opt_pos[idx1]=curr;
        opt_pos[idx2]=n-1-curr;
        curr++;
    }

    /*for(int i=0;i<n;i++)
        cout<<opt_pos[i]<<" ";
    cout<<endl;*/
    cout<<inv(0,n-1)<<endl;
}

Measured memory_bytes: 8780
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include <string.h>

int main() {
    char s[4];
    int ans=0;
    int i;
    scanf("%s", s);
    if (s[0]=='S'&&s[1]=='S'&&s[2]=='S') {
        printf("0\n");
    } else if (s[0]=='S'&&s[1]=='S'&&s[2]=='R') {
        printf("1\n");
    } else if (s[0]=='S'&&s[1]=='R'&&s[2]=='S') {
        printf("1\n");
    } else if (s[0]=='S'&&s[1]=='R'&&s[2]=='R') {
        printf("2\n");
    } else if (s[0]=='R'&&s[1]=='S'&&s[2]=='S') {
        printf("1\n");
    } else if (s[0]=='R'&&s[1]=='S'&&s[2]=='R') {
        printf("1\n");
    } else if (s[0]=='R'&&s[1]=='R'&&s[2]=='S') {
        printf("2\n");
    } else if (s[0]=='R'&&s[1]=='R'&&s[2]=='R') {
        printf("3\n");
    }
    return 0;
}

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

int main() {
  int N;
  cin >> N;
  vector<int> A(N);
  for (int i = 0; i < N; i++) cin >> A.at(i);
  vector<int> B(N);
  for (int i = 0; i < N; i++) cin >> B.at(i);
  vector<int> C(N - 1);
  for (int i = 0; i < N - 1; i++) cin >> C.at(i);

  int ans = 0;
  ans += accumulate(B.begin(), B.end(), 0L);
  for (int i = 1; i < N; i++) {
    if (A.at(i - 1) + 1 == A.at(i)) ans += C.at(A.at(i) - 2);
  }
  cout << ans << "\n";
}

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

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

using namespace __gnu_pbds;
using namespace std;

#define sint int32_t
#define int long long int
#define all(v) v.begin() , v.end()
#define vii vector<int>
#define pb push_back
#define pii pair<int,int>
#define F first
#define S second
#define fastio ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> ordered_set;

int arr[3001][3001];
int r , c , K;
int dp[3001][3001][4];


int solve(int i , int j , int cnt)
{
    if(i >= r) return 0;
    if(j >= c) return 0;

    if(i == r-1 && j == c-1)
    {
        if(cnt >= 1) return arr[i][j];
        return 0;
    }
    if(~dp[i][j][cnt]) return dp[i][j][cnt];

    int ans = 0;

    if(cnt >= 1 && arr[i][j])  ans = max({arr[i][j]+solve(i , j+1 , cnt-1) , solve(i , j+1 , cnt) , arr[i][j]+solve(i+1 , j , 3)});

    ans = max(ans , solve(i , j+1 , cnt));
    ans = max(ans , solve(i+1 , j , 3));

    return dp[i][j][cnt] = ans;

}


int32_t main()
{   fastio;


    cin>>r>>c>>K;
    memset(arr , 0 , sizeof(arr));
    while(K--)
    {
        int u , v , k;
        cin>>u>>v>>k;

        arr[u-1][v-1] = k;
    }

    memset(dp , -1 , sizeof(dp));

    cout<<solve(0 , 0 , 3)<<"\n";



}

Measured memory_bytes: 355968
import numpy as np
import sys
import bisect
sys.setrecursionlimit(10 ** 7)

# 二分探索

N = int(input())
A = list(map(int, input().split()))
B = list(map(int, input().split()))
C = list(map(int, input().split()))

'''
A = np.array(input().split(), dtype=np.int64)
B = np.array(input().split(), dtype=np.int64)
C = np.array(input().split(), dtype=np.int64)
'''

A.sort()
B.sort()
C.sort()

cntB = [0] * (N+1)

# Cを超えないBの累積和
for i in range(N):
    b = bisect.bisect_right(C, B[i])
    cntB[i+1] = cntB[i] + N - b


ans = 0
for i in range(N):
    a = bisect.bisect_right(B, A[i])
    c = cntB[N] - cntB[a]
    ans += c

print(ans)


Measured memory_bytes: 31508
#include<bits/stdc++.h>
using namespace std;
#define rep(i,a,n) for(int i=(a);i<=(n);++i)
#define per(i,a,n) for(int i=(a);i>=(n);--i)
#define pb push_back
using namespace std;
const int N=1e5+10;
typedef long long ll;
int n,m,k,u,v,x,y,par[N],sz[N],link[N];
vector<int>ban[N];
ll ans[N];
int find(int x){
	return par[x]==x?x:par[x]=find(par[x]);
}
void uni(int x,int y){
	x=find(x),y=find(y);
	if(x==y)return;
	if(x<y)par[y]=x,sz[x]+=sz[y];
	else par[x]=y,sz[y]+=sz[x];
}
int main()
{
	scanf("%d%d%d",&n,&m,&k);
	rep(i,1,n)par[i]=i,sz[i]=1;
	rep(i,1,m){
		scanf("%d%d",&u,&v);
		link[u]++;
		link[v]++;
		uni(u,v);
	}
	rep(i,1,k){
		scanf("%d%d",&u,&v);
		ban[u].pb(v);
		ban[v].pb(u);
	}
	rep(i,1,n){
		x=find(i);
		ans[i]=sz[x]-1-link[i];
		for(int z:ban[i])if(find(z)==x)ans[i]--;
	}
	rep(i,1,n){
		printf("%lld",ans[i]);
		if(i!=n)putchar(' ');
	}
	return 0;
}

Measured memory_bytes: 7936
import Control.Monad
import Control.Applicative hiding ((<|>))
import Text.Parsec
import Text.Parsec.Char

expression = maxmin 
  <$> oneOf "^_" <* char '('
  <*> expression <* char ',' <*> expression <* char ')'
  <|> number
number = makeNumber <$> (sourceColumn <$> getPosition) <*> many1 digit

maxmin c g h a b
  | a' >= b' = (i,z)
  | otherwise = (j,z)
  where 
    (i,x) = g a b
    (j,y) = h a' b'
    (a',b',z) = case c of
      '^' -> (max a x, b, max x y)
      '_' -> (a, min b x, min x y)

makeNumber i s@(c:_) a b
  | x == 0 || x*10+9 <= a || x >= b = (i, read s)
  | otherwise = (i+1, read s)
  where x = read [c]

main = do
  q <- readLn
  replicateM_ q $ do
    s <- getLine
    let (Right f) = parse expression "" s
        (i,x) = f 0 99
    putStrLn $ show x ++ " " ++ show i

Measured memory_bytes: 2428
#include <bits/stdc++.h>
#define DAU  ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define PLEC return 0;
using namespace std;
const int N(1005), mod(1e9 + 7);
int dp[N][N], n, m;
char x;
int main() {
    DAU
    cin >> n >> m;
    dp[0][1] = 1;
    for (int i = 1; i <= n; ++i)
        for (int j = 1; j <= m; ++j){
            cin >> x;
            if (x == '.') {
                if (dp[i-1][j] > 0)
                    dp[i][j] += dp[i-1][j];
                if (dp[i][j-1] > 0)
                    dp[i][j] += dp[i][j-1];
                dp[i][j] %= mod;
            }
        }
    cout << dp[n][m];
    PLEC
}


Measured memory_bytes: 4224
#include <iostream>
#include <vector>
#include <algorithm>

int main() {
  int n;
  std::cin >> n;
  std::vector<std::pair<int, int>> v;
  for (int i = 0; i < n; ++i) {
    int a;
    std::cin >> a;
    v.emplace_back(a, i);
  }

  std::sort(v.begin(), v.end());

  std::vector<std::pair<int, int>> t;
  for (int i = 0; i < n; ++i) {
    t.emplace_back(v[i].second, i);
  }
  std::sort(t.begin(), t.end());

  for (int i = 0; i < n; ++i) {
    if (t[i].second == n - 1) {
      std::cout << v[t[i].second - 1].first << std::endl;
    } else {
      std::cout << v[n - 1].first << std::endl;
    }
  }
}


Measured memory_bytes: 4976
#include <cstdio>
#include <algorithm>
#include <vector>
#define N 100005
using namespace std;
int n, d[N], t[N];
vector<int> g[N];

void f(int p) {
	int i, sz=g[p].size();
	for(i=0; i<sz; i++) f(g[p][i]);
	for(i=0; i<sz; i++) t[i] = d[g[p][i]];
	sort(t, t+sz);
	for(i=0; i<sz; i++) d[p] = max(d[p], t[i]) + 1;
}

int main() {
	scanf("%d", &n);
	for(int i=2, t; i<=n; i++) scanf("%d", &t), g[t].push_back(i);
	f(1);
	printf("%d\n", d[1]);
	return 0;
}

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

class D {
    static long mod = 1000000007;
    static void Main(string[] args) {
        var st = Console.ReadLine().Split().Select(long.Parse).ToArray();
        long n = st[0];
        long a = st[1];
        long b = st[2];


        long sum = myPow(2, n) % mod - 1;
        if (sum < 0) {
            sum += mod;
        }

        long xa = superCombinations(n, a);
        long xb = superCombinations(n, b);

        sum -= xa;
        sum -= xb;

        sum %= mod;
        if (sum < 0) {
            sum += mod;
        }

        Console.WriteLine(sum);
    }

    static long myPow(long x, long n) {
        if (n == 0)
            return 1;
        if (n % 2 == 0)
            return myPow(x * x % mod, n / 2);
        else
            return x * myPow(x, n - 1) % mod;
    }
    

    public static long superCombinations(long n, long k) {
        long count = n;

        for (long x = 1; x <= k - 1; x++) {
            count = count * (n - x) % mod * ModInv(x) % mod;
        }

        return (count * ModInv(k)) % mod;
    }

    static long FactorialMod(long a) {

        if (a <= 1) {
            return 1;
        } else {
            return a * FactorialMod(a - 1) % mod;
        }
    }

    public static long ModInv(long a) {
        if (a <= 1) {
            return 1;
        } else {
            long ret = (long)(0 - (ModInv(mod % a) * (mod / a)) % mod);
            if (ret < 0) {
                ret += (long)mod;
            }

            return (long)ret;
        }
    }

    static long FactorialModInv(long a) {
        if (a <= 1) {
            return 1;
        } else {
            return ModInv(a) * FactorialModInv(a - 1) % mod;
        }
    }
}

Measured memory_bytes: 13396
import java.util.*;
public class Main{
  public static void main (String args[]){
    Scanner sc = new Scanner(System.in);
    
    String s = sc.next();
    
    int l = s.length();
    
    for(int i = 0; i < l; i++){
      System.out.print("x");
    }
  }
}

Measured memory_bytes: 22736
#include<stdio.h>
#define MAX 2000001

int n,A[MAX];

void maxHeapify(i){
  int l,r,largest,temp;
  l=2*i;
  r=2*i+1;
  if(l<=n&&A[l]>A[i])largest = l;
  else largest = i;
  if(r<=n&&A[r]>A[largest])largest = r;
  if(largest!=i){
    temp=A[i];
    A[i]=A[largest];
    A[largest]=temp;
    maxHeapify(largest);
  }
}

int main(){
  int i;
  scanf("%d",&n);
  for(i=1;i<=n;i++){
    scanf("%d",&A[i]);
  }
  for(i=n/2;i>=1;i--){
    maxHeapify(i);
  }
  for(i=1;i<=n;i++){
    printf(" %d",A[i]);
  }
  printf("\n");
  return 0;
}

Measured memory_bytes: 2552
#include <bits/stdc++.h>
using namespace std;
#define LL long long 
#define LLU long long unsigned
#define rarr(arr, n) for(int aab = 0; aab < n; aab++){cin >> arr[aab];}
#define parr(arr, n) for(int aab = 0; aab < n; aab++){cout << arr[aab] << " ";}
#define pb push_back
#define f first
#define s second
#define all(x) x.begin(), x.end()
#define debug(x) cout << #x << " = " << x << "\n";

#define freopen freopen("in.txt", "r", stdin);freopen("out.txt", "w", stdout);ios_base::sync_with_stdio(0);cin.tie(0);

#define mod 1000000000000000000

int main(){
	long long int count = 0, n, c1 = 0, c2 = 0;
	cin >> n;
	if(n % 2 == 0){
		count++;
		c1 = 1, c2 = 0;
		n /= 2;
		while(n % 2 == 0){
			c2++;
			n /= 2;
			if(c2 > c1){
				c1 = c2;
				count++;
				c2 = 0;
			}
		}
	}

	for(int i = 3; i <= sqrt(n); i += 2){
		if(n % i == 0){
			count++;
			c1 = 1, c2 = 0;
			n /= i;
			while(n % i == 0){
				c2++;
				n /= i;
				if(c2 > c1){
					c1 = c2;
					count++;
					c2 = 0;
				}
			}
		}
	}

	if(n > 2){
		count++;
	}

	cout << count;
} 

Measured memory_bytes: 3680
#include<bits/stdc++.h>
#define EM 100000000
using namespace std;
using LL = long long;
using P = pair<LL, LL>;
LL LINF = 1e18;
int INF = 1e9;
using vint = vector<int>;
using vLL = vector<LL>;

int main(){
	int N, M;
	cin >> N >>M;
	vector<vector<int>>	k(M, vector<int>(20, 0));
	vint s(N, 0);
	vint p(M, 0);
	for(int i = 0;i < M;i++){
		cin >> k[i][0];
		for(int j = 1;j <= k[i][0];j++){
			int ss;
			cin >> ss;
			k[i][j] = ss-1;
		}
	}
	LL ans = 0;
	for(int i = 0;i < M;i++)	cin >> p[i];
	for(int i = 0;i < 1<<N;i++){
		for(int j = 0;j < N;j++)	s[j] = 0;
		for(int j = 0;j < N;j++){
			if(i&(1<<j))	s[j] = 1;
		}
		int cnt2 = 0;
		for(int j = 0;j < M;j++){
			int cnt = 0;
			for(int m = 1;m <= k[j][0];m++){
				if(s[k[j][m]] == 1)	cnt++;
			}
			if(cnt%2 == p[j])	cnt2++;
		}
		if(cnt2 == M)	ans++;
	}
	cout << ans << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define F first
#define S second
#define pb push_back
#define ll long long

using namespace std;
int main()
{
  ll a,b;
  cin>>a>>b;
  ll count1=0;
  ll count2=0;
  int i=1;
  while(1)
  {
    count1=floor(i*0.08);
    count2=floor(i*0.1);
    //cout<<count1<<" "<<count2<<endl;
    if(count1==a && count2==b){
       break;
    }
    else
    {
        if(count1>a && count2>b)
        {
        cout<<"-1"<<endl;
        exit(0);
            
        }
    }
     
   
      i++;
    
  }
  cout<<i<<endl;
}
   





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

int main() {
  string x, y;
  cin >> x >> y;
  if(x > y){
    cout << ">" << endl;
  }
  else if(x < y){
    cout << "<" << endl; 
  }
  else if(x == y){
    cout << "=" << endl;
  }
}


Measured memory_bytes: 256
import math
N, P = map(int, input().split())
a = math.floor(math.pow(P, 1/N))
if a == 1:
    ans = 1
else:
    a += 1
    for i in range(a, 0, -1):
        if P % pow(i, N) == 0:
            ans = i
            break
print(ans)


Measured memory_bytes: 9460
#include <bits/stdc++.h>
using namespace std;
  
int main(){
  int n,k, temp;
  cin>>n>>k;
  int arr[n];
  for(int i=0;i<n;i++){
    cin>>temp;
    arr[i]=temp;
  }
  int dp[n]={};
  dp[0]=0;
  dp[1]=abs(arr[1]-arr[0]);
  for(int i=2;i<=k;i++){
      if(i<n)
        dp[i]=abs(arr[i]-arr[0]);
  }
  for(int i=2;i<n;i++){
     int min = INT_MAX;int ans=INT_MAX;
     for(int j=1;j<=k;j++){
         
         if(i-j>=0)
            ans = dp[i-j]+abs(arr[i]-arr[i-j]);
         if(ans<min){
             min=ans;
         }
     }
    dp[i]=min;
  }
  cout<<dp[n-1]<<endl;
}


Measured memory_bytes: 1024
#include <iostream>
#include <cstdio>
using namespace std;
int main(){
char s[100000];
while(cin >> s){
     for(int i=0;s[i]!='\0';i++){
        if(i%2==0)
            printf("%c",s[i]);
     }
printf("\n");
}
return 0;
}

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

int main() 
{
    int r,c;
    cin>>r>>c;
    
    int a[r][c];
    int b[r+5][c+5];
    int d[c+5][r+5];
    int e[c+5][r+5];
    
    for(int i=0;i<r;i++){
        for(int j=0;j<c;j++){
            cin>>a[i][j];
        }
    }
    
    int sum=0;
    
      for(int i=0;i<r;i++){
        for(int j=0;j<c+1;j++){
            if(j!=c){
            b[i][j]=a[i][j];
            sum=sum+a[i][j];
        }
        
        else if(j==c){
            b[i][j]=sum;
            sum=0;
        }
      }
    }
    
       for(int i=0;i<c+1;i++){
        for(int j=0;j<r;j++){
            d[i][j]=b[j][i];
        }
    }
    
    for(int i=0;i<c+1;i++){
        for(int j=0;j<r+1;j++){
            if(j!=r){
            e[i][j]=d[i][j];
            sum=sum+d[i][j];
        }
        
        if(j==r){
            e[i][j]=sum;
            sum=0;
        }
      }
    }
         for(int i=0;i<r+1;i++){
        for(int j=0;j<c+1;j++){
            cout<<e[j][i]<<((j==c) ? "\n" : " ");
        }
        //cout<<"\n";
    }
    
return 0; 
} 




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

int main(){
    int n, l, i, s = 0, m = 0;
    cin >> n;
    for(i=0; i<n; i++){
        cin >> l;
        s += l;
        m = max(m, l);
    }
    if(2*m < s){
        cout << "Yes";
    }else{
        cout << "No";
    }
    return 0;
}

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

typedef pair<int, int> pii;

const int MN = 200010;

int N, Q;
vector<int> arr, psum;
vector<pii> query;

struct BIT {
    vector<int> tree, lazy;
    void init() {
        tree = vector<int>(4*MN, 1e9);
        lazy = vector<int>(4*MN, 1e9);
    }
    void prop(int l, int r, int n) {
        if(l != r && lazy[n] != 1e9) {
            tree[2*n] = min(tree[2*n], lazy[n]);
            lazy[2*n] = min(lazy[2*n], lazy[n]);
            tree[2*n + 1] = min(tree[2*n + 1], lazy[n]);
            lazy[2*n + 1] = min(lazy[2*n + 1], lazy[n]);
            lazy[n] = 1e9;
        }
    }
    void upd(int a, int b, int val, int l, int r, int n) {
        if(b < l || r < a) return;
        if(a <= l && r <= b) {
            tree[n] = min(tree[n], val);
            lazy[n] = min(lazy[n], val);
            return;
        }
        prop(l, r, n);
        int m = (l + r)>>1;
        upd(a, b, val, l, m, 2*n);
        upd(a, b, val, m + 1, r, 2*n + 1);
        tree[n] = min(tree[2*n], tree[2*n + 1]);
    }
    int quer(int a, int b, int l, int r, int n) {
        if(b < l || r < a) return 1e9;
        if(a <= l && r <= b) return tree[n];
        prop(l, r, n);
        int m = (l + r)>>1;
        int L = quer(a, b, l, m, 2*n);
        int R = quer(a, b, m + 1, r, 2*n + 1);
        return min(L, R);
    }
} bit, sub;

int cost(int l, int r) {
    if(r < 0) return 0;
    return psum[r] - (l == 0? 0 : psum[l - 1]);
}

vector<int> dp;

int main() {
    scanf("%d", &N);

    arr.resize(N);
    for(int i = 0; i < N; i++) {
        scanf("%d", &arr[i]);
    }
    psum.resize(N);
    for(int i = 0; i < N; i++) {
        psum[i] = arr[i];
        if(i) psum[i] += psum[i - 1];
    }

    scanf("%d", &Q);

    query.resize(Q);
    for(int i = 0; i < Q; i++) {
        int l, r; scanf("%d %d", &l, &r);
        l--; r--;

        query[i] = pii(l, r);
    }

    sort(query.begin(), query.end());

    int a = 0, b = 0, pos = N - 1;
    dp = vector<int>(Q + 1, 1e9);
    dp[Q] = 0;
    bit.init();
    sub.init();
    sub.upd(N, N, dp[Q], 0, MN - 1, 1);

    for(int i = Q - 1; i >= 0; i--) {
        while(pos >= 0 && pos >= query[i].first) {
            a += arr[pos] ^ 1;
            b += arr[pos];
            pos--;
        }
        dp[i] = min(dp[i], bit.quer(query[i].second, query[i].second, 0, MN - 1, 1) + a);
        dp[i] = min(dp[i], sub.quer(query[i].second + 1, MN - 1, 0, MN - 1, 1) + b + (query[i].second - query[i].first + 1) - 2 * cost(query[i].first, query[i].second));
        bit.upd(query[i].first, query[i].second, dp[i] - a, 0, MN - 1, 1);
        sub.upd(query[i].first, query[i].first, dp[i] - b, 0, MN - 1, 1);

        //cout << i << ' ' << dp[i] << endl;
    }

    int ans = cost(0, N - 1);
    for(int i = 0; i < Q; i++) {
        ans = min(ans, cost(0, query[i].first - 1) + dp[i]);
    }
    cout << ans;
}


Measured memory_bytes: 18688
N = gets.to_i
H = gets.split.map(&:to_i)
DP = Array.new(N, 10000)
DP[0] = 0
DP[1] = (H[1] - H[0]).abs

(N - 2).times {|i|
  DP[i + 2] = [
    DP[i] + (H[i + 2] - H[i]).abs,
    DP[i + 1] + (H[i + 2] - H[i + 1]).abs
  ].min
}

p DP[N - 1]


Measured memory_bytes: 11404
#include <bits/stdc++.h>
using namespace std;
int main()
{
    int n;
    cin >> n;
    long long sum = 0;
    for (int i = 1; i <= n; i++)
    {
        if (i % 3 != 0 and i % 5 != 0)
        {
            sum += i;
        }
    }
    cout << sum;
    return 0;
}

Measured memory_bytes: 3596
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>

using namespace std;

int main(){
	int k;
	cin >> k;
	int ans = 0;
	for(int i = 1; i <= k; i++){
		for(int j = 1; j <= k; j++){
			if(i % 2 == 0 && j % 2 != 0){
				ans++;
			}
		}
	}
	cout << ans << endl;
}

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

int main(){
  int a,b,d[110],e[110];
    cin>>a>>b;
   char c[110][110];
   for(int i =0;i<a ;i++){
      d[i] =0;
   }
  for(int j =0;j<b;j++){
     e[j] =0;
  }
    for(int i=0;i<a;i++){
        for(int j=0;j<b;j++){
            cin>>c[i][j];
            if(c[i][j]=='#'){
                d[i]=1; e[j]=1;
            }
        }
    }
    for(int i=0;i<a;i++){
        if(d[i] == 0) 
          continue;
        for(int j=0;j<b;j++){
            if(e[j] ==0 ) 
              continue;
          
            cout<<c[i][j];
        }
        cout<<endl;
    }
}


Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<algorithm>
#include<cctype>
#include<utility>
#include<string>
#include<cmath>
#include<cstring>
#include<queue>
#include<map>
#include<set>
#include<tuple>

#define REP(i, n) for(int i = 0;i < n;i++)
#define REPR(i, n) for(int i = n;i >= 0;i--)
#define FOR(i, m, n) for(int i = m;i < n;i++)
#define FORR(i, m, n) for(int i = m;i >= n;i--)
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
#define llong long long
#define pb(a) push_back(a)

using namespace std;

typedef long long int ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef tuple<int, int, int> tiii;


template<typename T>
vector<T> make_v(size_t a) { return vector<T>(a); }
template<typename T, typename... Ts>
auto make_v(size_t a, Ts... ts) {
	return vector<decltype(make_v<T>(ts...))>(a, make_v<T>(ts...));
}
template<typename T, typename V>
typename enable_if<is_class<T>::value == 0>::type
fill_v(T& t, const V& v) { t = v; }
template<typename T, typename V>
typename enable_if<is_class<T>::value != 0>::type
fill_v(T& t, const V& v) {
	for (auto& e : t) fill_v(e, v);
}


#define ARRAY_MAX 100005
int dx[4] = { 1,0,0,-1 };
int dy[4] = { 0,1,-1,0 };
const ll MOD = 1e9 + 7;
const int INF = 1e9 + 7;

#define DEBUG 1

ll dp[2055][2055];

int main() {

	
	ll n, m;
	cin >> n >> m;
	vector<int> s(n+10,0), t(m+10,0);
	for (int i = 0; i < n; i++)
	{
		cin >> s[i];
	}
	for (int i = 0; i < m; i++)
	{
		cin >> t[i];
	}

	dp[0][0] = 1;
	for (int i = 0; i <= n; i++) {
		for (int j = 0; j <= m; j++) {
			if (s[i] == t[j]) {
				dp[i + 1][j] += dp[i][j];
				dp[i][j + 1] += dp[i][j];

				dp[i + 1][j] %= MOD;
				dp[i][j + 1] %= MOD;
			}
			else
			{
				dp[i + 1][j] += dp[i][j];
				dp[i][j + 1] += dp[i][j];

				dp[i + 1][j] %= MOD;
				dp[i][j + 1] %= MOD;

				dp[i + 1][j + 1] -= dp[i][j];
				dp[i + 1][j + 1] += MOD;
				dp[i + 1][j + 1] %= MOD;
			}
		}
	}

	

	cout << dp[n][m]%MOD << endl;



	return 0;
}


Measured memory_bytes: 33024
#include <bits/stdc++.h>
#define MOD 1000000007
#define endl "\n"
typedef long long ll;
using namespace std;

const int N = 55;
string s[N];
bool ok[N][N];
int n, m;

int main() {
    ios_base::sync_with_stdio(false);
    cin >> n >> m;
    bool ans = true;
    for(int i = 0; i < n; i++) {
        cin >> s[i];
        for(int j = 0; j < m; j++) {
            if(s[i][j] == '#') {
                if(i && s[i - 1][j] == '#') {
                    ok[i][j] = true;
                    ok[i - 1][j] = true;
                }
                if(j && s[i][j - 1] == '#') {
                    ok[i][j] = true;
                    ok[i][j - 1] = true;
                }
            }
        }
    }
    for(int i = 0; i < n; i++) {
        for(int j = 0; j < m; j++) {
            if(s[i][j] == '#' && !ok[i][j]) {
                cout << "No" << endl;
                return 0;
            }
        }
    }
    cout << "Yes" << endl;
    return 0;
}

Measured memory_bytes: 256
import java.util.*;

public class Main {
    public static void main(String[] args) {
        Scanner sc;// = new Scanner(System.in);
        sc = new Scanner(System.in);
        int x = sc.nextInt();
        int y = sc.nextInt();
        int a[][] = new int[x][y];
        int b[] = new int[y];
        for(int i=0;i<x;i++){
            sc.nextLine();
            for(int j=0;j<y;j++){
                a[i][j] = sc.nextInt();
            }
        }
        for(int i=0;i<y;i++){
            sc.nextLine();
            b[i] = sc.nextInt();
        }

        for(int i=0;i<x;i++){
            int n = 0;
            for(int j=0;j<y;j++){
                n += a[i][j]*b[j];
            }
            System.out.println(n);
        }
    }
}


Measured memory_bytes: 46348
from decimal import Decimal
N, K = map(int, input().split())
t = 0
i = 1
while(i < K):
    t += 1
    i *= 2
under = 2**t

p = 0
for i in range(1, N+1):
    c = 0
    while(i < K):
        c += 1
        i *= 2
    p += 2**(t-c)
print(Decimal(p)/Decimal((2**t)*N))

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

using namespace std;

int main() {
	int A, B, C, D;
	int X, Y;
	cin >> A >> B >> C >> D;
	X = C % B;
	if (X > 0) {
		X = C / B + 1;
	}
	else {
		X = C / B;
	}
	Y = A % D;
	if (Y > 0) {
		Y = A / D + 1;
	}
	else {
		Y = A / D;
	}

	if (X <= Y) {
		cout << "Yes";
	}
	else {
		cout << "No";
	}


	return 0;
}

Measured memory_bytes: 3556
#include<iostream>

using namespace std;
main(){
  int n,s1,s2;
  int a,b;
  cin>>n;
  while(n!=0){
    s1=s2=0;
    for(int i=0;i<n;i++){
      cin>>a>>b;
      if(a>b)
	s1+=(a+b);
      else if(a<b)
	s2+=(a+b);
      else{
	s1+=a;
	s2+=a;
      }

    }
    cout<<s1<<" "<<s2<<endl;
    
    cin>>n;
  }
  return 0;
}

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

int main(){
  int n; cin>> n;
  vector<int>p(n);
  for(int i=0;i<n;i++) cin>> p[i];
  int k=0;
  for(int i=0; i<n;i++)
  if(p[i] !=i+ 1) k++;
  if(k<= 2) cout<< "YES"<< endl;
  else cout<<"NO"<< endl;
  return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <deque>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <cstring>
#include <iomanip>
#include <utility>
#include <math.h>

#define rep(i,n) for(int i=0;i<(n);i++)
#define reps(i,n) for(int i=1;i<=(n);i++)
#define lol long long
#define mp make_pair
#define fi first
#define se second
#define pu push_back
#define SYOU(x) setprecision(x+1)
#define abs(x,y) (max(x,y)-min(x,y))

const int INF = 0x3f3f3f3f;
const long long LINF = 0x3f3f3f3f3f3f3f3fLL;

using namespace std;

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    
    int n,a[105];
    cin>>n;
    rep(i,n){
	cin>>a[i];
    }
    for(int i=n-1;i>0;i--){
	cout<<a[i]<<" ";
    }
    cout<<a[0]<<'\n';

    return 0;
}



Measured memory_bytes: 3116
using System;
using System.Collections.Generic;
using System.Linq;

namespace ServalvsMonster
{
    class Program
    {
        static void Main(string[] args)
        {
            var input = Console.ReadLine().Split(' ');
            int monsterHealth = int.Parse(input[0]);
            int attackPower = int.Parse(input[1]);
            int attacksNumber = 0;

            if(monsterHealth % attackPower > 0)
            {
                attacksNumber = monsterHealth / attackPower + 1;
            }
            else
            {
                attacksNumber = monsterHealth / attackPower;
            }

            Console.WriteLine(attacksNumber);
        }
    }
}

Measured memory_bytes: 11092
#include<cstdio>
#include<algorithm>
#define LL long long
using namespace std;
const int p=1000000007;
int main()
{
	int n,m;
	LL ans=1;
	scanf("%d%d",&n,&m);
	if (n>m) swap(n,m);
	if (n==m)
	{
		for (int i=1;i<=n;i++) ans=ans*i%p;
		ans=ans*ans%p;
		ans=ans*2%p;
	}
	else if (n==m-1)
	{
		for (int i=1;i<=n;i++) ans=ans*i%p;
		ans=ans*ans%p;
		ans=ans*m%p;
	}
	else ans=0;
	printf("%lld\n",ans);
}


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


Measured memory_bytes: 5592
#include<bits/stdc++.h>
using namespace std;
int main(){
  int a,b,c;cin>>a>>b>>c;
  if(a==b&&b==c){
    cout<<1<<endl;
    return 0;
  }
  if(a==b||b==c||c==a){
    cout<<2<<endl;
    return 0;
  }
  cout<<3<<endl;
  return 0;
}

Measured memory_bytes: 256
import std.stdio, std.algorithm, std.conv, std.range, std.string;
 
void main(){
    string line;
    while(line = readln.chomp, line.length){
        auto d = line.to!int;
        int s;
        for(int x = 0; x < 600; x += d){
            s += x * x * d;
        }
        //auto d2 = reduce!((a, b) => a + b * b * d)(0, iota(d, 600, d));
        //if(d != d2) throw new Exception(text(d, " ", d2));
        s.writeln;
    }
}

Measured memory_bytes: 968
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#include<cmath>
#include<functional>
#include<map>
#include<cstdlib>
#include<complex>
#include<numeric>
#include<set>
#include<deque>
#include<queue>

using namespace std;
using Int = long long;
Int INF = 1LL << 60;
const Int MOD = 1000000000 + 7;

int main() {

	cin.tie(nullptr);
	ios::sync_with_stdio(false);

	Int N;
	cin >> N;

	vector<Int> w(N);
	for (Int i = 0; i < N; i++) {
		cin >> w[i];
	}

	vector<Int> s(N + 1);
	for (Int i = 0; i < N; i++) {
		s[i + 1] = s[i] + w[i];
	}

	Int ans = INF;
	Int temp;
	for (Int i = 0; i <= N; i++) {
		temp = abs((s[i] - s[0]) - (s[N]-s[i]));
		ans = min(ans, temp);
	}
	cout << ans << "\n";


}


Measured memory_bytes: 256
N = int(input())
easts = [0] * (N + 1)
wests = [0] * (N + 1)

for i, c in enumerate(input()):
    if c == 'E':
        easts[i + 1] += easts[i] + 1
        wests[i + 1] = wests[i]
    else:
        wests[i + 1] += wests[i] + 1
        easts[i + 1] = easts[i]

ans = 1 << 31
for i in range(N):
    ans = min(ans, easts[N] - easts[i + 1] + wests[i] - wests[0])
print(ans)


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

int n;
double memo[3005][3005];
bool vis[3005][3005];
double li[3005];

double dp(int idx, int he){
   if(idx > n){
      if(he > (n/2)) return 1.0;
      else return 0.0;
   }
   double &ret = memo[idx][he];
   if(vis[idx][he]) return ret;
   vis[idx][he] = 1;
   ret = dp(idx+1,he+1) * li[idx] + dp(idx+1,he) * (1.0 - li[idx]);
   return ret;
}

int main(){
   scanf("%d",&n);
   for(int i=1;i<=n;i++) scanf("%lf",&li[i]);
   double ans = dp(1,0);
   printf("%.11lf\n",ans);
	return 0;
}


Measured memory_bytes: 79744
#include<bits/stdc++.h>
using namespace std;
const int mod = 1e9 + 7;
const int N = 100000 + 10;
int power(int a, int b){
    int res = 1;
    while(b > 0){
        if(b & 1){
            res = 1LL * res * a % mod;    
        }
        a = 1LL * a * a % mod;
        b >>= 1;
    }
    return res;
}
int main() {
    string s;
    cin >> s;
    for(int i = 0; i < s.length(); i++){
        for(int j = i; j < s.length(); j++){
            string dum;
            for(int k = 0; k < s.length(); k++){
                if(k < i || k > j){
                    dum += s[k];
                }
            }
            if(dum == "keyence" || s == "keyence"){
                printf("YES\n");
                return 0;
            }
        }
    }
    printf("NO\n");
    return 0;
}

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


int main()
{
	vector<char> S;

	string hi;
	cin >> hi;

	for (int i = 0; i < (int)hi.size(); i++)
	{
		S.push_back(hi[i]);
	}

	if (S[0] != 'h')
	{
		cout << "No";
		return 0;
	}

	bool pash = true, pasi = false;

	for (int i = 1; i < S.size(); i++)
	{

		if (S[i] == 'i' && pash)
		{
			pasi = true;
			pash = false;
			continue;
		}
		else if (S[i] == 'h' && pasi)
		{
			pash = true;
			pasi = false;
			continue;
		}
		else
		{
			cout << "No";
			return 0;
		}
	}
	if (pash)
	{
		cout << "No";
		return 0;
	}
	cout << "Yes";

	return 0;
}

Measured memory_bytes: 256