akhauriyash/Code-Regression huggingface dataset:
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cstring>
#include<vector>
#include<queue>
#include<stack>
#include<cmath>
using namespace std;
int main(){
	unsigned long long n,m;
	cin>>n>>m;
    if(n==1){
    	if(m!=1)cout<<m-2;
    	else cout<<1;
	}
	else if(m==1){
		if(n!=1)cout<<n-2;
		else cout<<1;
	}
	else {
	    cout<<m*n-2*n-2*m+4; 
	} 
	//freopen(".in","r",stdin);
	//freopen(".out","w",stdout);
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0; i<(n); i++)
#define reps(i,s,n) for(int i=(s); i<(n); i++)
#define all(v) v.begin(),v.end()
#define outve(v) for(auto i : v) cout << i << " ";cout << endl
#define outmat(v) for(auto i : v){for(auto j : i) cout << j << " ";cout << endl;}
#define in(n,v) for(int i=0; i<(n); i++){cin >> v[i];}
#define out(n) cout << (n) << endl
#define fi first
#define se second
#define pb push_back
#define mod 1000000007
#define infi 1900000000
#define infl 1100000000000000000
#define cyes cout << "Yes" << endl
#define cno cout << "No" << endl
#define csp << " " <<
#define outset(n) cout << fixed << setprecision(n);
using namespace std;
using ll = long long;
using ld = long double;
using vi = vector<int>;
using vvi = vector<vector<int>>;
using vl = vector<ll>;
using vvl = vector<vector<ll>>;
using pii = pair<int,int>;
using pll = pair<ll,ll>;
template<typename T> using ve = vector<T>;
template<typename T> using pq2 = priority_queue<T>;
template<typename T> using pq1 = priority_queue<T,vector<T>,greater<T>>;
template <typename T> bool chmax(T &a, T b) {if(a < b) {a = b;return 1;}return 0;}
template <typename T> bool chmin(T &a, T b) {if(a > b) {a = b;return 1;}return 0;}




int main()
{
    int N,M;
    cin >> N >> M;
    cout << N*(N-1)/2+M*(M-1)/2 << endl;

    
    
    
    
    

    return 0;
}


Measured memory_bytes: 256
#include <stdio.h>

int main(void)
{
	int N;
	scanf("%d",&N);
	int c,k,e,r;
	int ans = 0;
	c = 10;
	int c_w = 100;
	k = 1000;
	int k_w = 10000;
	e = 100000;
	int e_w = 1000000;
	r = 10000000;
	if(N < c)
	{
		ans = N;
	}
	else if(N >= c && N < c_w)
	{
		ans = 9;
	}
	else if(N >= c_w && N < k)
	{
		ans += 9;
		ans = ans + N - 99;
	}
	else if(N >= k && N < k_w)
	{
		ans += 9;
		ans += 900;
	}
	else if(N >= k_w && N < e)
	{
		ans += 9;
		ans += 900;
		ans = ans + N - 9999;
	}
	else if(N >= e)
	{
		ans += 9;
		ans += 900;
		ans += 90000;
	}
	
	printf("%d",ans);
	return 0;
}


Measured memory_bytes: 128
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const long long int INF = 1e9;

int main(){
  string s,t;
  
  cin >> s >> t;
 int x = s.size();
 s += s;
  int find[200010][26];
  
  for(int i=0;i<26;i++){
    
    find[2*x][i] = INF;
  }
  
  for(int i=2*x-1;i>=0;i--){
    
    for(int j=0;j<26;j++){
      
      find[i][j]=find[i+1][j];
    }
    
    find[i][s[i]-'a'] = i+1;
  }
  
  ll ans=0;
  
  for(int i=0;i<t.size();i++){
    
    if(find[(ans % x)][t[i]-'a'] == INF){
      
      cout << -1 << endl;
      
      return 0;
    }
    
    ans += find[(ans % x)][t[i]-'a']-(ans % x);
  }
  
  cout << ans << endl;
}


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

#define INF 0x3f3f3f3f

typedef long long ll;
typedef pair<int, int> P;

int n;
int f,t,o;

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

	cin >> n;
	for (int i = 0; i < n; i++) {
		int a;
		cin >> a;
		if (a % 4 == 0) f++;
		else if (a % 2 == 0) t++;
		else o++;
	}
	if (t == 0) {
		cout << (f >= o || f+1 == o ? "Yes" : "No") << endl;
	}
	else {
		cout << (f >= o ? "Yes" : "No") << endl;
	}
	return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
typedef long long ll;
typedef long double ld;
using namespace std;

#define REP(i, l, n) for(int i=(l), i##_len=(n); i<i##_len; ++i)
#define ALL(x) (x).begin(),(x).end()
#define pb push_back

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

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

int main(){
    ll a, b; cin >> a >> b;
    cout << lcm(a, b) << endl;
}

Measured memory_bytes: 256
use std::io::Read;

fn main() {
    let mut buff = String::new();
    std::io::stdin().read_to_string(&mut buff).unwrap();
    let mut iter = buff.split_whitespace();

    let s: String = iter.next().unwrap().parse().unwrap();

    let x: i32 = s.matches('+').count() as i32;
    let y: i32 = s.matches('-').count() as i32;

    println!("{}", x - y);

    ()
}


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

int main()
{
  ll H; cin >> H;
  ll W; cin >> W;
  ll A; cin >> A;
  ll B; cin >> B;

  vector<vector<int>> d(H, vector<int>(W, 0));
  for (int i=0; i<H; i++) {
    for (int j=0; j<W; j++) {
      int t = 0;
      if (j<A) t = 1;
      if (i<B) cout << t;
      else cout << (t+1)%2;
    }
    cout << endl;
  }

  return 0;
}


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

const int maxn=2e5+5;
int n,m=1,t,a[maxn],cnt[maxn],dat[4*maxn],sum[maxn];

void fM(int x,int y)
{
	x+=m-1;
	dat[x]+=y;
	while (x>0)
	{
		x=(x-1)/2;
		dat[x]=dat[2*x+1]+dat[2*x+2];
	}
}
int fQ(int l=0,int r=m,int x=0,int y=n,int k=0)
{
	if(r<=x||l>=y)return 0;
	else if(x<=l&&y<=r)return dat[k];
	else 
	{
		int lx=fQ(l,(l+r)>>1,x,y,2*k+1);
		int ly=fQ((l+r)>>1,r,x,y,2*k+2);
		return lx+ly;
	}
}
int main()
{
	scanf("%d%d",&n,&t);while (m<=n)m<<=1;
	rep(i,n)
	{
		int x;
		scanf("%d",&x);
		a[i]=x;
		sum[x]++;
		int p=x-sum[x];
		if(p>=0)
		{
			cnt[p]++;
			if(cnt[p]==1)fM(p,1);
		}
	}
	rep(i,t)
	{
		int x,y;
		scanf("%d%d",&x,&y);x--;
		int p=a[x]-sum[a[x]];
		if(p>=0)
		{
			cnt[p]--;
			if(cnt[p]==0)fM(p,-1);
		}
		
		sum[a[x]]--;
		a[x]=y;
		sum[a[x]]++;
		p=a[x]-sum[a[x]];
		if(p>=0)
		{
			cnt[p]++;
			if(cnt[p]==1)fM(p,1);
		}
		printf("%d\n",n-fQ());
	}
	
	return 0;
}

Measured memory_bytes: 6784
mod = 10**9 + 7

N,M = map(int,input().split())
A = set(int(input()) for _ in range(M))

dp = [0]*(N+1)
dp[0] = 1

for i in range(1,N+1):
    if i in A:
        dp[i] = 0
    else:
        if i == 1:
            dp[1] = dp[0]
        else:
            dp[i] = dp[i-1] + dp[i-2]
    dp[i] %= mod

ans = dp[N]
print(ans)

Measured memory_bytes: 11884
#include <bits/stdc++.h>
#define rep0(i, n) for (int i = 0; i < (n); ++i)
#define rep1(i, n) for (int i = 1; i <= (n); ++i)
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
typedef tuple<string, int, int> TU;
typedef tuple<int, int, int> TI;

int main()
{
    ll n;
    cin >> n;
    int input1[n];
    rep0(i,n){
        cin >> input1[i];
    }
    ll max=0,res=0;
    rep0(i,n){
        if(max<=input1[i]){
            res++;
            max=input1[i];
        }        
    }
    cout << res << endl;


}


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

int main(){
  
  string s,ans;
  cin >> s;
  for(int i=0;i<s.size();++i){
    if(s.at(i) == '0')ans += '0';
    if(s.at(i) == '1')ans += '1';
    if(s.at(i) == 'B'){
      if(ans.size() > 0){
        ans.pop_back();
      }
    }
  }
    cout << ans << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define REP(i, n) for (int i = 0; i < (int)(n); i++)
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
typedef long long ll;
typedef pair<int, int> P;
const int INF = 100100100;
const int MOD = (int)1e9 + 7;
const double EPS = 1e-9;
int main() {
  int K;
  int A, B;
  cin >> K >> A >> B;
  for (int i = A; i <= B; i++) {
    if (i % K == 0) {
      puts("OK");
      return 0;
    }
  }
  puts("NG");
}

Measured memory_bytes: 3624
#include <stdio.h>

int main(void){

	int a, b, i, d;

	while (1){
		scanf("%d %d", &a, &b);
		if (a == 0 && b == 0){
			break;
		}

		for (i = 0; i < a; i++){

			for (d = 0; d < b; d++)
			{
				printf("#");
			}
			printf("\n");


		}
		printf("\n");
	}


	return 0;
}


Measured memory_bytes: 2056
//    _____ _     _                _           _     _ _     _     
//    \_   \ |_  (_)___  __      _| |__   __ _| |_  (_) |_  (_)___ 
//     / /\/ __| | / __| \ \ /\ / / '_ \ / _` | __| | | __| | / __|
//  /\/ /_ | |_  | \__ \  \ V  V /| | | | (_| | |_  | | |_  | \__ \
//  \____/  \__| |_|___/   \_/\_/ |_| |_|\__,_|\__| |_|\__| |_|___/
//                                                                 
#include <bits/stdc++.h>
#define mp make_pair
#define pb push_back
#define f first
#define s second
#define all(x) x.begin(), x.end()
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;

ll div_floor(ll a, ll b) {
	// use when ret <= a/b, (a and b can be -ve)
	return a / b - (((a ^ b) < 0) and a % b);
}
ll div_ceil(ll a, ll b) { 
	// use when ret >= a/b, (a and b can be -ve)
	return a / b + (((a ^ b) >= 0) and a % b);
}
const int sz=1e6+9;
int n;
map<int,int> m;
int a;



int main(){
	cin>>n;
	while(n--){
		cin>>a;
		m[a]++;
		if(m[a]>1){
			cout<<"NO";
			return 0;
		}
	}
	cout<<"YES";
	return 0;
}

Measured memory_bytes: 9600
#include <stdio.h>
#include <iostream>
#include <algorithm>
#include <memory.h>
#include <vector>

using namespace std;
typedef long long LL;
const int maxn = 505;
const int A = 1000;

int n,m,a[maxn],stk[maxn],top;
int main()
{
	#ifdef Amberframe
		freopen("agc001d.in","r",stdin);
		freopen("agc001d.out","w",stdout);
	#endif
	scanf("%d %d",&n,&m);
	for (int i=1;i<=m;i++) {
		scanf("%d",&a[i]);
		if (a[i]&1) stk[++top]=i;
	}
	if (top>2) printf("Impossible");
	else {
		if (top>=1) swap(a[1],a[stk[1]]);
		if (top>=2) swap(a[m],a[stk[2]]);
		for (int i=1;i<=m;i++) printf("%d ",a[i]);
		if (m==1) {if (a[1]>1) a[m]--,a[++m]=1;}
		else a[1]++,a[m]--;a[m]==0?m--:0;
		printf("\n%d\n",m);
		for (int i=1;i<=m;i++) printf("%d ",a[i]);
	}
	return 0;
}

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

using namespace std;

int main() {

	char p[3], q[3];
	int a = 0;

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

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

	for (int i = 0; i < 3; i++) {
		if (p[i] == q[i]) {
			a++;
		}
	}

	cout << a;
	return 0;

}

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

ll solve() {
    ll ai, ao, at, aj, al, as, az;
    cin >> ai >> ao >> at >> aj >> al >> as >> az;
    ll ans = 0;
    ans += ao;
    if ( ai > 0 ) {
        ans += (ai-1)/2 * 2;
        ai -= (ai-1)/2 * 2;
    }
    if ( aj > 0 ) {
        ans += (aj-1)/2 * 2;
        aj -= (aj-1)/2 * 2;
    }
    if ( al > 0 ) {
        ans += (al-1)/2 * 2;
        al -= (al-1)/2 * 2;
    }
    int c2 = 0, c1 = 0;
    if ( ai > 1 ) c2++;
    if ( aj > 1 ) c2++;
    if ( al > 1 ) c2++;
    if ( ai > 0 ) c1++;
    if ( aj > 0 ) c1++;
    if ( al > 0 ) c1++;
    if ( c1 == 3 && c2 <= 1 ) {
        ans += 3;
    } else  {
        ans += ai/2 * 2;
        ans += aj/2 * 2;
        ans += al/2 * 2;
    }
    return ans;
}

int main() {
    auto ans = solve();
    cout << ans << "\n";
    return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<string>
using namespace std;
int main(){
  int n,i;double x,ans;string u;
  cin >> n;ans = 0;
  for (i=0;i<n;i++){
    cin >> x >> u;
    if (u=="JPY") ans += x;
    else ans += x*380000.0;
  }
  cout << ans << endl;
}
    
 

Measured memory_bytes: 384
//#include<bits/stdc++.h>
//#pragma comment(linker, "/STACK:102400000,102400000")
#include <stdio.h>
#include <iostream>
#include <iomanip>
#include <fstream>
#include <string.h>
#include <stdlib.h>
#include <time.h>
#include <limits.h>
#include <math.h>
#include <algorithm>
#include <deque>
#include <queue>
#include <stack>
#include <list>
#include <map>
#include <set>
#include <utility>
#include <sstream>
#include <complex>
#include <string>
#include <vector>
#include <bitset>
#include <functional>
using namespace std;
typedef long long LL;
typedef unsigned long long ULL;
typedef double db;
typedef long double ldb;
#define rep(i,a,b) for(i=a;i<b;i++)
#define repu(i,a,b) for(i=a;i<=b;i++)
#define repd(i,a,b) for(i=a;i>=b;i--)
#define repc(i,a,b,c) for(i=a;i<b;i+=c)
#define repcu(i,a,b,c) for(i=a;i<=b;i+=c)
#define repcd(i,a,b,c) for(i=a;i>=b;i-=c)
#define FIN freopen("input.in","r",stdin)
#define FOUT freopen("output.out","w",stdout)
#define CC(a) memset(a,0,sizeof(a))
#define MST(a,b) memset(a,b,sizeof(a))
#define PII pair<int,int>
#define PLL pair<long long,long long>
#define VI vector<int>
#define VL vector<long long>
#define VII vector<PII>
#define VLL vector<PLL>
#define all(x) x.begin(),x.end()
#define mp make_pair
#define pb push_back
#define pf push_front
 
template<typename T>inline void gn(T &x){
	x=0;T f=1;char ch=getchar();
	while(!isdigit(ch)){if(ch=='-')f=-1;ch=getchar();}
	while(isdigit(ch)){x=x*10+ch-'0';ch=getchar();}
	x*=f;
}
template<typename T>inline void gt(T x){
	if(!x)return;
	gt(x/10);putchar(x%10+'0');
}
 
const LL maxn=1e3+10;
LL MOD=1e9+7,inf=0x1f1f1f1f,mod=998244353;
db eps=1e-5;
LL t,n,m,q,ans,cnt[11],f[11];
string s[3];

int main()
{
//	ios_base::sync_with_stdio(false);cin.tie(0);
	LL i,j,k,l,ca=0,u,v;
	repu(i,0,2)cin>>s[i],cnt[i]=s[i].size();
	k=0;
	while(f[k]<cnt[k]){
		l=s[k][f[k]]-'a';
		f[k]++;
		k=l;
	}
	cout<<(char)(k+'A')<<endl;
	return 0;
}

Measured memory_bytes: 256
package main

import (
	"fmt"
	"math"
)

func main() {
	var (
		a, b, c float64
		k       int
	)
	fmt.Scan(&a, &b, &c, &k)
	max := math.Max(a, math.Max(b, c))
	sum := a + b + c - max
	for i := 0; i < k; i++ {
		max *= 2
	}
	sum += max
	fmt.Println(sum)
}


Measured memory_bytes: 512
#include <bits/stdc++.h>
using namespace std;
#define FOR(i, s, n) for(int i = s; i < (int)n; i++)
#define per(i, n) for(int i = n; i >= 0; i--)
#define ROF(i, s, n) for(int i = s; i >= (int)n; i--)
#define FORIT(i, A) for (auto i : A)
#define PRINT(x) cout << (x) << "\n"
#define ALL(a) (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define MP make_pair
#define EACH(i, n) for (__typeof((n).begin()) i = (n).begin(); i != (n).end(); ++i)
#define SZ(a) int((a).size())
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort((c).begin(),(c).end())
#define CLR(a) memset((a), 0 ,sizeof(a))
#define NCLR(a) memset((a), -1 ,sizeof(a))
#define dump(x) cout << #x << " = " << (x) << "\n";
#define debug(x) cout << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << "\n";
#define sq(n) (n) * (n)
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef long long LL;
typedef vector<LL> VLL;
typedef vector<VLL> VVLL;
typedef unsigned int uint;
typedef unsigned long long ull;
typedef priority_queue<int> maxpq;
typedef priority_queue< int, vector<int>, greater<int> > minpq;
typedef complex<double> P;
static const double EPS = 1e-10;
static const double PI = acos( -1.0 );
static const int mod = 1000000007;
static const int INF = 1 << 30;
static const LL LL_INF = 1152921504606846976;
static const int dx[] = { -1, 0, 1, 0, 1, -1, 1, -1 };
static const int dy[] = { 0, -1, 0, 1, 1, 1, -1, -1 };

int a, b, r = 90;
double x = 0, y = 0;

int main() {
	while ( ~scanf( "%d,%d", &a, &b ) ) {
		x += a * cos( r * PI / 180 );
		y += a * sin( r * PI / 180 );
		r -= b;
	}
	printf( "%d\n%d\n", ( int ) x, ( int ) y );
	return 0;
}

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

int main()
{
    string s;
    int k;
    cin >> s;
    cin >> k;
    int one_count = 0;
    if(s[0] == '1')
    {
        one_count++;
        for(int i = 1; i < s.length(); i++)
        {
            if(s[i-1] == '1' && s[i] == '1')
            {
                one_count++;
            }
            else
            {
                break;
            }
        }
    }
    if(one_count != 0 && one_count >= k)
    {
        cout << 1 << endl;
        return 0;
    }
    else
    {
        for(int i = 0; i < s.length(); i++)
        {
            if(s[i] != '1')
            {
                cout << s[i] << endl;
                return 0;
            }
        }
    }
}


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

string s;
char now;
int cnt = 0;

int main() {
  cin >> s;
  now = s[0];
  for(int i = 1; i < s.size(); ++i)
    if(now != s[i]) {
      ++cnt;
      now = s[i];
    }
  cout << cnt << endl;
  return 0;
}

Measured memory_bytes: 512
import java.util.*;
import java.io.InputStreamReader;
import java.io.BufferedReader;
import java.util.Arrays;
import java.util.List;
import java.util.ArrayList;
import java.util.ArrayDeque;
import java.util.Deque;
import java.util.Collections;
import java.awt.Point;


public class Main {
    public static void main(String[] args) throws Exception {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        String[] NW = br.readLine().split(" ");
        int N = Integer.parseInt(NW[0]);
        int W = Integer.parseInt(NW[1]);
        int[] w = new int[N+1];
        int[] v = new int[N+1];
        
        for (int i = 0; i < N; i++) {
            String[] s = br.readLine().split(" ");
            w[i+1] = Integer.parseInt(s[0]);
            v[i+1] = Integer.parseInt(s[1]);
        }
        
        long[][] dp = new long[N+1][W+1];
        
        for (int i = 0; i <= W; i++) {
            dp[0][i] = 0;
        }
        
        for (int i = 0; i <= N; i++) {
            dp[i][0] = 0;
        }
        
        for (int i = 1; i <= N; i++) {
            for (int j = 1; j <= W; j++) {
                if (j-w[i] >= 0) {
                    dp[i][j] = Math.max(dp[i-1][j-w[i]] + v[i], dp[i-1][j]);
                }
                else dp[i][j] = dp[i-1][j];
            }
        }
        
        
        System.out.println(dp[N][W]);
    }
}



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

using namespace std;

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

#define IOS ios_base::sync_with_stdio(0); cin.tie(0);
#define endl '\n'

int n;
int a[50];

int main()
{
	IOS;
	cin >> n;
	int c = 0;
	for (int i = 0; i < n; i++)
		cin >> a[i];
	for (int i = 0; i < n; i++) {
		int b;
		cin >> b;
		c += max(a[i]-b, 0);
	}
	cout << c << endl;
	return 0;
}



Measured memory_bytes: 256
#include<bits/stdc++.h>
#define ll long long
#define uint unsigned
#define ull unsigned ll
#define pii pair<int,int>
#define pll pair<ll,ll>
#define PB push_back
#define fi first
#define se second
#define For(i,j,k) for (int i=(int)(j);i<=(int)(k);i++)
#define Rep(i,j,k) for (int i=(int)(j);i>=(int)(k);i--)
#define CLR(a,v) memset(a,v,sizeof(a))
#define CPY(a,b) memcpy(a,b,sizeof(a))
using namespace std;
const int N=200;
int n,m,fl[N];
char s[N][N];
int f[2][N][N][N];
int g[2][N][N][N];
int main(){
	scanf("%d%d",&n,&m);
	For(i,1,n){
		scanf("%s",s[i]+1);
		For(j,1,n) s[i][j]=(s[i][j]=='.'?0:1); 
	}
	For(i,1,n){
		For(j,1,m) fl[j]=s[i][j];
		For(j,i,n){
			For(k,1,m) fl[k]=(fl[k]!=s[j][k]?2:fl[k]);
			int las=fl[m],ed=m;
			f[0][i][j][m+1]=m+1;
			Rep(k,m,1){
				if (las!=fl[k]) las=fl[k],ed=k;
				f[0][i][j][k]=(las==2?k:ed+1);
			}
		}
	}
	For(i,1,m){
		For(j,1,n) fl[j]=s[j][i];
		For(j,i,m){
			For(k,1,n) fl[k]=(fl[k]!=s[k][j]?2:fl[k]);
			int las=fl[n],ed=n;
			g[0][i][j][n+1]=n+1;
			Rep(k,n,1){
				if (las!=fl[k]) las=fl[k],ed=k;
				g[0][i][j][k]=(las==2?k:ed+1);
			}
		}
	}
	int pre=0,suf=1;
	for (int ans=0;ans<=100;){
		//printf("%d %d\n",f[pre][1][n][1],f[pre][1][n][2]);
		if (f[pre][1][n][1]==m+1){
			printf("%d\n",ans);
			return 0;
		}
		For(i,1,n) For(j,i,n) For(k,1,m+1)
			f[suf][i][j][k]=f[pre][i][j][f[pre][i][j][k]];
		For(i,1,m) For(j,i,m) For(k,1,n+1)
			g[suf][i][j][k]=g[pre][i][j][g[pre][i][j][k]];
		For(i,1,n) For(j,i,n){
			int ed=1;
			For(k,1,m){
				ed=max(ed,k);
				for (;ed!=m+1&&g[pre][k][ed][g[pre][k][ed][i]]>j;++ed);
				f[suf][i][j][k]=max(f[suf][i][j][k],ed);
			}
		}
		For(i,1,m) For(j,i,m){
			int ed=1;
			For(k,1,n){
				ed=max(ed,k);
				for (;ed!=n+1&&f[pre][k][ed][f[pre][k][ed][i]]>j;++ed);
				g[suf][i][j][k]=max(g[suf][i][j][k],ed);
			}
		}
		++ans;
		swap(pre,suf);
	}
}
/*
f[i][j][k][l]:上界为i，下界为j，左界为k，答案为l的最右右界
g[i][j][k][l]:左界为i，右界为j，上界为k，答案为l的最下下界 
竖着划分可以xjb转移 
横着划分二分右边界检验 
*/

Measured memory_bytes: 122880
#include <iostream>
#include <vector>
using namespace std;
int main() {
	int n, x;
	cin >> n >> x;
	vector<int> a(n+1);
	a[0] = 0;
	for (int i = 1; i < n+1; i++) {
		cin >> a[i];
	}
	int count = 0;
	int m = 0;
	for (int i = 0; i < n+1; i++) {
		m += a[i];
		if (m <= x) {
			count++;		
		}
	}
	cout << count << endl;
	return 0;
}













Measured memory_bytes: 256
import sys
sys.setrecursionlimit(10**6)
n = int(input())
graph = [[] for _ in range(n)]
for _ in range(n-1):
    a, b = map(int, input().split())
    graph[a-1].append(b-1)
    graph[b-1].append(a-1)
pre = [None]*n
def dfs(node, p_node=-1):
    for c_node in graph[node]:
        if c_node==p_node:
            continue
        pre[c_node] = node
        dfs(c_node, node)
dfs(0)
path = [n-1]
now = n-1
while now>0:
    now = pre[now]
    path.append(now)
snuke = path[len(path)//2-1]
fennec = path[len(path)//2]
def dfs2(node, p_node):
    cnt = 1
    for c_node in graph[node]:
        if c_node==p_node:
            continue
        cnt += dfs2(c_node, node)
    return cnt
print('FSennunkeec'[dfs2(fennec, snuke)<=dfs2(snuke, fennec)::2])

Measured memory_bytes: 134864
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int N;
  cin >>N;
  vector<int> L(N);
  
  for (int i=0;i<N;i++){
    cin >>L.at(i);
    //cout <<L.at(i);
    }
  sort(L.begin(), L.end());
  reverse(L.begin(), L.end());
  
  int max=L.at(0);
  int sum=0;
  
  for(int i=1;i<N;i++){
    sum+=L.at(i);}
  if(sum>max){
    cout<<"Yes"<<endl;
  }
  else{
    cout<<"No"<<endl;
  }
}
   


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
typedef pair<ll, pair<ll, ll> > P3;
const ll MOD = 1000000007;
const int IINF = INT_MAX;
const ll LLINF = LLONG_MAX;
const int MAX_N = int(3e3 + 5);
const double EPS = 1e-10;
const int di[] = {0, 1, 0, -1}, dj[] = {1, 0, -1, 0};
#define REP(i, n) for (int i = 0; i < n; i++)
#define REPR(i, n) for (int i = n; i >= 0; i--)
#define SORT(v) sort((v).begin(), (v).end())
#define ALL(v) (v).begin(), (v).end()

int dp[MAX_N][MAX_N];
string s, t;

int lcs() {
    for (int i = 0; i <= s.size(); i++) fill(dp[i], dp[i] + t.size() + 1, 0);
    for (int i = 0; i < s.size(); i++) {
        for (int j = 0; j < t.size(); j++) {
            if (s[i] == t[j]) {
                dp[i + 1][j + 1] = max(dp[i + 1][j + 1], dp[i][j] + 1);
            }
            dp[i + 1][j + 1] = max(dp[i + 1][j + 1], dp[i + 1][j]);
            dp[i + 1][j + 1] = max(dp[i + 1][j + 1], dp[i][j + 1]);
        }
    }
    return dp[s.size()][t.size()];
}

string get_lcs() {
    int i = s.size(), j = t.size();
    string res = "";
    while (i > 0 && j > 0) {
        if (dp[i][j - 1] == dp[i][j]) {
            j--;
        } else if (dp[i - 1][j] == dp[i][j]) {
            i--;
        } else {
            res += s[i - 1];
            i--;
            j--;
        }
    }
    reverse(res.begin(), res.end());
    return res;
}


int main() {
    cin >> s >> t;
    lcs();
    cout << get_lcs() << endl;
    return 0;
}


Measured memory_bytes: 35456
#include<stdio.h>
#include<string.h>
#define MAX 2000000
#define INFTY (1<<30)

int H,A[MAX +1];
void swap(int a,int b){
		int dmp;
		dmp = A[a];
		A[a] = A[b];
		A[b] = dmp;
	
}
void maxHeapify(int i){
	int l,r,largest;
	l = 2 * i;
	r = 2 * i + 1;
	int dmp = 0;
	if(l <= H && A[l] > A[i]){
		largest = l;
	}
	else {
		largest = i;
	}
	if(r <= H && A[r] > A[largest]){
		largest = r;
	}
	
	if(largest != i){
		
		swap(i,largest);
		maxHeapify(largest);
	}
}



int extract(){
	int maxv;
	if(H < 1){
		return  -INFTY;
	}
	maxv = A[1];
	A[1] = A[H--];
	maxHeapify(1);
	return maxv;
}

void increaseKey(int i,int key){
	
	if(key < A[i])return;
	A[i] = key;
	while(i > 1&&A[i / 2] < A[i]){
		swap(i,i/2);
		i = i/2;
	}
}

void insert(int key){
	H++;
	A[H] = -INFTY;
	increaseKey(H,key);
	
}
int main (){
	int Key;
	char com[10];
	while(1){
		scanf("%s",com);
		if(com[0] == 'e' && com[1] =='n')break;
		if(com[0] == 'i'){
			scanf("%d",&Key);
			insert(Key);
		}
		else{
			printf("%d\n",extract());
		}
		
	}
	return 0;
	
}


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

int main() {
  LL N;
  cin >> N;
  LL x = N / 3;
  cout << x << endl;
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define P pair<ll,ll>
#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 TO(x,t,f) ((x)?(t):(f))
#define SORT(x) (sort(x.begin(),x.end())) // 0 2 2 3 4 5 8 9
#define REV(x) (reverse(x.begin(),x.end())) //reverse
int gcd(int a,int b){if(a<b)swap(a,b);if(a%b==0)return b;return gcd(b,a%b);}
int lcm(int a,int b){int c=gcd(a,b);return ((a/c)*(b/c)*c);}//saisyo kobaisu
#define NEXTP(x) next_permutation(x.begin(),x.end())
const ll INF=1e18+7;
const ll MOD=1e9+7;
#define pri(a) cout << (a) << endl

struct Inversions{// tentosu
	// after init,u can get number of inversions num_inversion(A)
	vector<ll> L,R;
	void initsize(ll n){//input size of A
		L.resize(n/2+2);
		R.resize(n/2+2);
	}
	ll merge(vector<ll> &A,ll n,ll left,ll mid,ll right){
		ll i,j,k;
		ll cnt = 0;
		ll n1 = mid - left;
		ll n2 = right - mid;
		for(i=0;i<n1;i++)L[i]=A[left+i];
		for(i=0;i<n2;i++)R[i]=A[mid+i];
		L[n1]=R[n2]=INT_MAX;//
		i=j=0;
		for(k=left;k<right;k++){
			if(L[i]<=R[j]){
				A[k]=L[i++];
			}else{
				A[k]=R[j++];
				cnt += n1-i;
			}
		}
		return cnt;
	}
	ll mergeSort(vector<ll> &A,ll n,ll left,ll right){
		ll mid;
		ll v1,v2,v3;
		if(left+1<right){
			mid = (left+right)/2;
			v1 = mergeSort(A,n,left,mid);
			v2 = mergeSort(A,n,mid,right);
			v3 = merge(A,n,left,mid,right);
			return v1+v2+v3;
		}else return 0;
	}
	ll num_inversion(vector<ll> A){
		return mergeSort(A,A.size(),0,A.size());
	}
};


int main(){
	ios::sync_with_stdio(false);
	cin.tie(0);
	Inversions In;
	string s;
	vector<ll> a;
	cin >> s;
	FOR(i,0,s.size()){
		if(s[i]=='B')a.push_back(1);
		else a.push_back(0);
	}
	In.initsize(a.size());
	cout << In.num_inversion(a) << endl;
}


Measured memory_bytes: 5128
#include<bits/stdc++.h>
#define PB push_back
#define MP make_pair
using namespace std;
typedef long long int LL;
typedef vector<int> VI;
typedef pair<int, int> PII;

struct room
{
  int num;
  bool visited[2];
  
  bool operator<(const room r) const
  {
    return num < r.num;
  }
  bool operator>(const room r) const
  {
    return num > r.num;
  }
};

struct r_compare
{
  LL cost;
  int loc_x, loc_y;
  bool sw;

  bool operator<(const r_compare r) const
  {
    return cost < r.cost;
  }
  bool operator>(const r_compare r) const
  {
    return cost > r.cost;
  }
};

int m, n, k;
vector<room> ns[100010], ew[100010];
priority_queue<r_compare, vector<r_compare>, greater<r_compare> > Q;

LL dijk()
{
  if(ns[1].empty())
    return -1;

  r_compare qin = {(ns[1].begin())->num - 1, 1, (ns[1].begin())->num, false};
  Q.push(qin);

  while(!Q.empty()){
    r_compare c_now = Q.top();
    Q.pop();

    if(c_now.loc_x == m && c_now.loc_y == n)
      return c_now.cost;

    room sr = {(!c_now.sw ? c_now.loc_y : c_now.loc_x), {false, false}};
    vector<room>::iterator r_now = !c_now.sw ? lower_bound(ns[c_now.loc_x].begin(), ns[c_now.loc_x].end(), sr) : lower_bound(ew[c_now.loc_y].begin(), ew[c_now.loc_y].end(), sr);

    if(!r_now->visited[c_now.sw]){
      r_now->visited[c_now.sw] = true;
      
      if(!c_now.sw){
	if(r_now != ns[c_now.loc_x].begin()){
	  r_compare qin = {c_now.cost + r_now->num - (r_now - 1)->num, c_now.loc_x, (r_now - 1)->num, false};
	  Q.push(qin);
	}
	if(r_now != ns[c_now.loc_x].end() - 1){
	  r_compare qin = {c_now.cost + (r_now + 1)->num - r_now->num, c_now.loc_x, (r_now + 1)->num, false};
	  Q.push(qin);
	}
      }
      else{
	if(r_now != ew[c_now.loc_y].begin()){
	  r_compare qin = {c_now.cost + r_now->num - (r_now - 1)->num, (r_now - 1)->num, c_now.loc_y, true};
	  Q.push(qin);
	}
	if(r_now != ew[c_now.loc_y].end() - 1){
	  r_compare qin = {c_now.cost + (r_now + 1)->num - r_now->num, (r_now + 1)->num, c_now.loc_y, true};
	  Q.push(qin);
	}
      }

      r_compare qin = {c_now.cost + 1, c_now.loc_x, c_now.loc_y, !c_now.sw};
      Q.push(qin);
    }
  }
  return -1;
}

int main()
{
  scanf("%d%d%d", &m, &n, &k);
  
  bool last = false;
  for(int i = 0; i < k; i++){
    int x, y;
    if(x == m && y == n)
      last = true;
    scanf("%d%d", &x, &y);
    room xin = {y, {false, false}}, yin = {x, {false, false}};
    ns[x].PB(xin);
    ew[y].PB(yin);
  }
  
  if(!last){
    room xin = {n, {false, false}}, yin = {m, {false, false}};
    ns[m].PB(xin);
    ew[n].PB(yin);
  }
  
  for(int i = 1; i <= m; i++)
    sort(ns[i].begin(), ns[i].end());
  for(int i = 1; i <= n; i++)
    sort(ew[i].begin(), ew[i].end());

  printf("%lld\n", dijk());
  return 0;
}

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

const int INF = 1001001001;
const int di[] = {-1, 0, 1, 0};
const int dj[] = {0, -1, 0, 1};

int main() {
  int h, w; cin >> h >> w;
  vector<string> s(h);
  rep(i,h) cin >> s[i];
  int ans = 0;
  rep(si,h)rep(sj,w) {
    if (s[si][sj] == '#') continue;
    vector<vector<int>> dist(h, vector<int>(w, INF));
    queue<P> q;
    auto update = [&](int i, int j, int x) {
      if (dist[i][j] != INF) return;
      dist[i][j] = x;
      q.push(P(i,j));
    };
    update(si,sj,0);
    while (!q.empty()) {
      int i = q.front().first;
      int j = q.front().second; q.pop();
      rep(dir,4) {
        int ni = i+di[dir], nj = j+dj[dir];
        if (ni<0||ni>=h||nj<0||nj>=w) continue;
        if (s[ni][nj] == '#') continue;
        update(ni,nj,dist[i][j]+1);
      }
    }
    rep(i,h)rep(j,w) {
      if (dist[i][j] == INF) continue;
      ans = max(ans, dist[i][j]);
    }
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
char a[4],b[4];
int main()
{
	cin >> a[1] >> a[2] >> a[3] >> b[1] >> b[2] >> b[3];
	if (a[1] == b[3] && a[2] == b[2] && a[3] == b[1]) cout << "YES\n";
		else cout << "NO\n";
	return 0;
 } 

Measured memory_bytes: 256
_,m,*A=map(int,open(0).read().split());S=l=3*m;D=[0]*l
for a,b in zip(A,A[1:]):b+=m*(b<a);k=b-a;S+=k;D[a+2]+=1;D[b+1]-=k;D[b+2]+=k-1
for i in range(l*2):D[i%l]+=D[~-i%l]
print(S-l-max(D[a]+D[a+m]for a in A))

Measured memory_bytes: 17748
#include <bits/stdc++.h>
using namespace std;
#define ALL(a) (a).begin(),(a).end()
#define rALL(a) (a).rbegin(),(a).rend()
typedef pair<int, int> Pint;
typedef pair<int64_t, int64_t> Pll;
  
int main() {
    int N, M;
    cin >> N >> M;
    vector<Pint> A(N), C(M);
    for (int i = 0; i < N; i++) {
        cin >> A.at(i).first >> A.at(i).second;
    }
    for (int i = 0; i < M; i++) {
        cin >> C.at(i).first >> C.at(i).second;
    }

    for (int i = 0; i < N; i++) {
        int T = 1000000007;
        for (int j = 0; j < M; j++) {
            int a = T, b;
            T = min(T, abs(A.at(i).first - C.at(j).first) + abs(A.at(i).second - C.at(j).second));
            if (a != T) {
                b = j + 1;
            }
            if (j == M - 1) {
                cout << b << endl;
            }
        }

    }
}

Measured memory_bytes: 256
#include <iostream>
#include <numeric>
using namespace std;
int main(void){
    long long N, M;
    string S, T;
    
    /*入力*/
    cin >> N >> M;
    cin >> S;
    cin >> T;
    
    /*最小公倍数を求める*/
    long long n, m, x;
    long long LCM;
    
    n = N; m = M;
    x = n * m;
    
    if(n < m){
        int tmp = n;
        n = m;
        m = tmp;
    }
    
    long long r = n % m;
    while(r != 0){
        n = m;
        m = r;
        r = n % m;
    }
    
    LCM = x / m;
    
    /*いい文字列が存在するか*/
    
    long long s, t;
    
    s = LCM / N;
    t = LCM / M;
    
    for(long long i = 0; i < LCM; i += s * t){
        if(S[i / s] != T[i / t]){
            cout << "-1" << endl;
            exit(0);
        }
    }
    
    cout << LCM << endl;
    
    return 0;
}

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

using namespace std;

int main()
{

   int a,b,c,s,t;
   cin>>a>>b>>c;
   s=b-a;
   t=c-b;
   if(s==t){
    cout<<"YES"<<endl;
   }
   else{
    cout<<"NO"<<endl;
   }

    return 0;
}


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

using namespace std;
#define IOS cin.sync_with_stdio(0); cin.tie(0); cout.tie(0);

using ll = long long;
using ld = long double;


//Forward

int main(){
    IOS

    int n, k; cin>>n>>k;

    vector<int> h(n);
    for(int & x: h)cin>>x;

    vector<int> dp(n,INT_MAX);
    
    dp[n-1] = 0;
    dp[n-2] = abs(h[n-2]-h[n-1]);

    for(int i = n-3; i >= 0; --i){
        for(int j = i+1; j < n && j-i <= k; j++){
            dp[i] = min(dp[i], dp[j] + abs(h[i]-h[j]));
        }
    }

    cout<<dp[0];

}


Measured memory_bytes: 1024
///#pragma GCC optimize("Ofast")
///#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,avx2,fma")
///#pragma GCC optimize("unroll-loops")

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

///#include<ext/pb_ds/assoc_container.hpp>
///#include<ext/pb_ds/tree_policy.hpp>
///using namespace __gnu_pbds;
///template<typename T> using orderset = tree<T,null_type,less<T>,rb_tree_tag,tree_order_statistics_node_update>;
///(X).order_of_key(value) /// return lower_bound(value)
///(*X).find_by_order(index) /// return value (0 index)

mt19937 rng(chrono::steady_clock::now().time_since_epoch().count()); /// mt19937_64 (long long)

typedef unsigned long long ull;
typedef long long ll;
typedef long double ld;
typedef vector<int> vii;
typedef vector<ll> vll;
typedef vector<vll> vvll;
typedef vector<vii> vvii;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef vector<pii> vpii;
typedef vector<pll> vpll;
typedef vector<bool> vbb;

const int N = 1000001;
const int MOD = 1000000007;
const ll INF = LLONG_MAX;

#define fast() ios_base::sync_with_stdio(false),cin.tie(NULL)
#define next(x) next_permutation(all(x))
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define rev(a) reverse(all(a))
#define eb emplace_back
#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define yes cout<<"YES"<<nl
#define no cout<<"NO"<<nl
#define space ' '
#define nl '\n'
#define PI acos(-1)
#define Case(x) cout<<"Case "<<x<<": "
#define strtoint(a) atoi(a.c_str())
#define dbg(x) cerr<<#x<<" is "<<x<<'\n';
#define fix(x) cout<<fixed<<setprecision(x)
#define leastonepos(x) __builtin_ffs(x)
#define leadingoff(x) __builtin_clz(x)
#define trailingoff(x) __builtin_ctz(x)
#define numofone(x) __builtin_popcount(x)
#define time() cerr<<"Time elapsed : "<<clock()*1000.0/CLOCKS_PER_SEC<<"ms"<<'\n'

#define coutv(v) for(auto it:v)cout<<it<<space;cout<<nl;
#define cinv(v) for(auto &it:v)cin>>it;

///................Graph's Move.................
///const int dx[] = {+1,-1,+0,+0}; ///Rock's Move
///const int dy[] = {+0,+0,+1,-1}; ///Rock's Move
///const int dx[] = {+0,+0,+1,-1,-1,+1,-1,+1}; ///King's Move
///const int dy[] = {-1,+1,+0,+0,+1,+1,-1,-1}; ///king's Move
///const int dx[] = {-2,-2,-1,-1,+1,+1,+2,+2}; ///knight's Move
///const int dy[] = {-1,+1,-2,+2,-2,+2,-1,+1}; ///knight's Move
///*.....................-_-........................*///



int main()
{
    fast();
    int tc=1,cs=0;
    //cin>>tc;
    while(tc--)
    {
        int n,i;
        cin>>n;
        vii h(n),dp(n);
        cinv(h);
        for(i=1; i<n; i++)
        {
            dp[i]=(dp[i-1]+abs(h[i]-h[i-1]));
            if(i>1)
                dp[i]=min(dp[i],(dp[i-2]+abs(h[i]-h[i-2])));
        }
        cout<<dp[n-1]<<nl;
    }
}


Measured memory_bytes: 4004
#include<bits/stdc++.h>
using namespace std;
#define ll long long
ll dp[101][100001];ll n,W;
ll w[100001],v[100001];
ll ans(ll ind,ll c){
  if(c<0)return numeric_limits<ll>::min();
  if(ind>n-1)return 0;
  if(dp[ind][c]!=-1)return dp[ind][c];
  dp[ind][c] = max(ans(ind+1,c),ans(ind+1,c-w[ind])+v[ind]);
  return dp[ind][c];
}
int main(){
  memset(dp,-1,sizeof(dp));
  cin>>n>>W;for(ll i=0;i<n;i++)cin>>w[i]>>v[i];
  cout<<ans(0,W)<<endl;
  return 0;
}


Measured memory_bytes: 79104
#include<iostream>
#include<stdio.h>
using namespace std;
int main(){
 int t[4],n[4],a[4],i;
	for(i=0;i<4;i++){
		cin>>t[i]>>n[i];
	if(t[i]==1){
		a[i]=n[i]*6000;
	}
	else if(t[i]==2){
		a[i]=n[i]*4000;
	}
	else if(t[i]==3){
		a[i]=n[i]*3000;
	}
	else if(t[i]==4){
		a[i]=n[i]*2000;
	}
	}
for(i=0;i<4;i++){
		cout<<a[i]<<endl;	
	}
return 0;
}

Measured memory_bytes: 1160
#include<bits/stdc++.h>
using namespace std;
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define IFOR(i,a,b) for(int i=(b-1);i>=(a);--i)
#define RPT(i,a,b) for(int i=(a);i<((a)+(b));++i)
#define IRPT(i,a,b) for(int i=((a)+(b)-1);i>=(a);--i)

void solve(){
  int n;cin >> n;
  vector<int> a(n), b(n), c(n-1);
  FOR(i,0,n) {cin >> a[i]; a[i]--;}
  FOR(i,0,n) cin >> b[i];
  FOR(i,0,n-1) cin >> c[i];
  int ans = 0;
  FOR(i,0,n){
    ans += b[a[i]];
    if(i>0 && a[i-1]+1==a[i]) ans += c[a[i-1]];
  }
  cout << ans;
}

int main(){
  solve();
  return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#define loop(i,a,b) for(int i=a;i<b;i++)
#define rep(i,a) loop(i,0,a)


using namespace std;


int lcd(int a, int b){
	if (a < b) swap(a, b);
	int c;

	while (b != 0){
		c = a%b;
		a = b;
		b = c;
	}
	return a;
}



int main(){
	int a, b;
	while (cin >> a >> b){
		int c;
		c = lcd(a, b);
		cout << c << " " << a/c*b << endl;
	}
	
}

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

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

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

    ll i, N, P;
    cin>>N>>P;
    string S;
    cin>>S;

    ll cnt = 0;
    if (P == 2 || P == 5) {
        rep(i, N) {
            if ((S[i] - '0') % P == 0) {
                cnt += i + 1;
            }
        }
    }

    else {
        vector<ll> ppow(N + 10);
        ll acc = 1;
        rep(i, N + 10) {
            ppow[i] = acc;
            acc = (acc * 10) % P;
        }

        unordered_map<ll, ll> mp;
        ll r = 0;
        rep(i, N) {
            r = ((S[N - i - 1] - '0') * ppow[i] + r) % P;
            mp[r]++;
        }
        for (auto m : mp) {
            if (m.first == 0) cnt += m.second * (m.second + 1) / 2;
            else cnt += m.second * (m.second - 1) / 2;
        }
    }

    cout<<cnt<<endl;
}

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

int main(){
  ll n,cnt=0;
  cin >> n;
  vector<ll> a(n);
  for(ll i=0;i<n;i++){
    cin >> a.at(i);
  }
  
  for(ll i=1;i<n;i++){
    if(a.at(i-1) > a.at(i)){
      cnt += a.at(i-1)-a.at(i);
      a.at(i) = a.at(i-1);
    }
  }
  
  cout << cnt << endl;      
      
  return 0;
}


Measured memory_bytes: 4804
#include <iostream>
#include <algorithm>
#include <cassert>
#include <vector>
#include <string>
#include <queue>
#include <set>
#include <map>
#define rep(i, n)   for(int i = 0; i < (n); i++)
using namespace std;
typedef long long ll;

//AtCoderのライブラリのほぼパクリ
//https://github.com/atcoder-live/library/blob/master/mint.cpp
//これが元

const int mod = 1000000007;
struct mint{
    ll x;   //typedef long long ll
    mint(ll x = 0):x((x%mod+mod)%mod){}
    mint operator-() const {return mint(-x);}
    mint& operator+=(const mint a){
        if((x += a.x) >= mod)     x -= mod;
        return *this;
    }
    mint& operator-=(const mint a){
        if((x += a.x) >= mod)   x -= mod;
        return *this;
    }
    mint& operator*=(const mint a){ (x *= a.x) %= mod; return *this; }
    mint operator+(const mint a) const {return mint(*this) += a;}
    mint operator-(const mint a) const {return mint(*this) -= a;}
    mint operator*(const mint a) const {return mint(*this) *= a;}
    mint pow(ll t) const{
        if(!t)  return 1;
        mint a = pow(t >> 1);
        a *= a;
        if(t&1) a *= *this;
        return a;
    }

    // for prime mod
    mint inv() const {return pow(mod-2);}
    mint& operator/=(const mint a) {return *this *= a.inv();}
    mint operator/(const mint a) const {return mint(*this) /= a;}
};
istream& operator>>(istream& is, const mint& a) {return is >> a.x;}
ostream& operator<<(ostream& os, const mint& a) {return os << a.x;}

//AtCoderのパクリ
//https://github.com/atcoder-live/library/blob/master/comb.cpp
//これが元
//mintが必要

struct combinatoin{
    vector<mint> fact, ifact;
    combinatoin(int n):fact(n+1), ifact(n+1){
        assert(n < mod);
        fact[0] = 1;
        for(int i = 1; i <= n; ++i) fact[i] = fact[i-1]*i;
        ifact[n] = fact[n].inv();
        for(int i = n; i >= 1; --i) ifact[i-1] = ifact[i]*i;
    }
    mint operator()(int n, int k){
        if (k < 0 || k > n) return 0;
        return fact[n]*ifact[k]*ifact[n-k];
    }
};

int main(){
    int n,k;    cin >> n >> k;
    combinatoin C(n);
    for(int i = 1; i <= k; i++){
        cout << C(k-1, k-i)*C(n-k+1, i) << endl;
    }
}


Measured memory_bytes: 3624
#include <stdio.h>
int main()
{
	long long a, b, c;
	scanf("%lld %lld %lld",&a,&b,&c);
	long long ans = 1;
	if(a % 2 == 0||b%2==0||c%2==0) ans = 0;
	else 
	{
		if( a <= c && b <= c)
		{
			ans = a * b;
		}
		else
		{
			if(a <= b && c <= b)
			{
				ans =  a * c;
			}
			else
			{
				ans = c * b;
			}
		}
	}
	printf("%lld\n",ans);
	return 0;
}

Measured memory_bytes: 128
#include <iostream>
#include <string>
#include <algorithm>
#include <functional>
#include <vector>
#include <stack>
#include <queue>
#include <deque>
#include <set>
#include <map>
#include <cstdio>
#include <cmath>
#include <tuple>
#include <iomanip>
#include <numeric>
#include <unordered_map>
#include <sstream>   
#include<limits.h>
#include<float.h>
#include<list>
#include <array>
#include <complex>
using namespace std;
#define i64  long long
#define int  long long
 
#define I32_MAX 2147483647
#define I64_MAX 9223372036854775807LL
#define I64_MAX2 1223372036854775807LL
#define INF I64_MAX2
#define MOD 1000000007
#define MEM_SIZE 10000
#define DEBUG_OUT true
#define ALL(x) (x).begin(),(x).end()

// int DP[MEM_SIZE][MEM_SIZE] = {0};
// int GMEM[MEM_SIZE][MEM_SIZE] = {0};
template<typename T> void DEBUG(T e){if(DEBUG_OUT == false)return;std::cout << e << std::endl;}
template<typename T> void DEBUG(const std::vector<T>& v){if(DEBUG_OUT == false)return;for(const auto& e : v){ std::cout << e << " "; } std::cout << std::endl;}
template<typename T> void DEBUG(const std::vector<std::vector<T> >& vv){if(DEBUG_OUT == false)return;for(const auto& v : vv){ DEBUG(v); } }
template<class T> void DEBUG(string str, T e){if(DEBUG_OUT == false)return;std::cout <<str<<" ";DEBUG(e);};
template <class T> void corner(bool flg, T hoge) {if (flg) {cout << hoge << endl; exit(0);}}
template< typename T1, typename T2 > inline bool chmax(T1 &a, T2 b) { return a < b && (a = b, true); }
template< typename T1, typename T2 > inline bool chmin(T1 &a, T2 b) { return a > b && (a = b, true); }


//CODE
void solve(void)
{
  int N;
  cin>>N;
  vector<int> vec(N,0);
  for (int i = 0; i < N; i++)
  {
    int A;
    cin>>A;
    A -=(i+1);
    vec[i] = A;
  }
  if(N == 1)
  {
    cout<<0<<endl;
    return;
  }
  sort(ALL(vec));
  int MID;
  if(false)
  {
    MID = ((vec[(N)/2-1]+vec[(N)/2]))/2;
  }
  else
  {
    MID =vec[N/2];
  }
  // DEBUG(MID);

  int ANS = 0;
  
  for (int i = 0; i < N; i++)
  {
    ANS += abs(vec[i] - MID);
  }
  cout<<(int)ANS<<endl;
  
  
  
  

  
  
  return;
}


int32_t main(int32_t argc, const char *argv[])
{
  std::ios::sync_with_stdio(false);
  std::cin.tie(0);

  std::cout << std::fixed;
  std::cout << std::setprecision(9);
  solve();
  

 
  return 0;
}


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

#include <cstdlib>  // abs() for integer 絶対値求めやつ

#include <cmath>    // abs() for float, and fabs()

#include <algorithm>
#include <vector>
#define rep(i,n) for(int i = 0; i< (n);i++)

#define SORT(a) sort((a).begin(),(a).end());

#define che(a,string) cout<<string<<":"<<(a)<<endl;

#define ch(a,string) cout<<string<<":"<<(a)<<" ";

using namespace std;

typedef pair<int,int> P;

int main(){
  int n ; cin >> n; 
  if(n<105){
	  cout << 0<<endl;
	}
	else if(105<=n&&n<135){
		cout<<1<<endl;
	  }
	  else if(135<=n&&n<165){
		  cout<<2<<endl;
		}
		else if (165<=n&&n<189){
			cout<<3<<endl;
		  }
		  else if(189<=n&&n<195){
			  cout<<4<<endl;
			}
	  else if (195<=n){
		  cout<<5<<endl;
		  }
}



Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

	static Scanner sc = new Scanner(System.in);
	static int N;
	static int[][] R, C;

	public static void main(String[] args) {
		while (true) {
			N = sc.nextInt();
			if (N == 0) break;
			R = new int[N][N];
			C = new int[N][N];
			for (int i = 0; i < N; ++i) {
				for (int j = 0; j < N; ++j) {
					C[i][j] = sc.nextInt();
					R[i][j] = sc.nextInt();
				}
			}
			int[][] visited = new int[N][N];
			int ans = 0;
			for (int i = 0; i < N; ++i) {
				for (int j = 0; j < N; ++j) {
					if (visited[i][j] == 2) continue;
					int cr = i;
					int cc = j;
					boolean loop = false;
					while (true) {
						if (visited[cr][cc] == 2) break;
						if (visited[cr][cc] == 1) {
							loop = true;
							break;
						}
						visited[cr][cc] = 1;
						int nr = R[cr][cc];
						int nc = C[cr][cc];
						cr = nr;
						cc = nc;
					}
					if (loop) ++ans;
					cr = i;
					cc = j;
					while (visited[cr][cc] == 1) {
						visited[cr][cc] = 2;
						int nr = R[cr][cc];
						int nc = C[cr][cc];
						cr = nr;
						cc = nc;
					}
				}
			}
			System.out.println(ans);
		}
	}

}

Measured memory_bytes: 62080
import java.util.Scanner;
public class Main {
    public static void main(String args[]) {
        Scanner sc = new Scanner(System.in);
        int x = sc.nextInt();
        int glad = 0;
        if(x/500!=0){
            glad = x/500 * 1000;
            x = x%500;
        }
        if(x/5!=0){
            glad = glad + (x/5 * 5);
            x = x%500;
        }
        System.out.println(glad);
    }
}


Measured memory_bytes: 21844
#include<bits/stdc++.h>
using namespace std;
const int maxn = 2e5 + 5;

int n, a[maxn], b[maxn];
multiset<int> st;
int main() {
	cin >> n;
	for(int i = 0; i < n; i++) {
		cin >> a[i];
		b[i] = a[i];
	}
	sort(b, b + n);
	int y = n / 2;
	int x = y - 1;
	for(int i = 0; i < n; i++) {
		if(a[i] <= b[x])
			cout << b[y] << endl;
		else
			cout << b[x] << endl;
	}
	return 0;
}

Measured memory_bytes: 3712