akhauriyash/Code-Regression huggingface dataset:
let () =
  let n = Scanf.scanf "%d " (fun a -> a) in
  let a_lst = Array.to_list @@ Array.init n (fun _ -> Scanf.scanf "%d " (fun a -> a)) in
  let a_lst_sorted = List.sort (fun x y -> compare y x) a_lst in

  let div lst =
    let rec aux even odd i = function
        [] -> (even, odd)
      | hd :: tl -> if i mod 2 = 0 then
          aux (hd::even) odd (i+1) tl
        else
          aux even (hd::odd) (i+1) tl
    in
    aux [] [] 0 lst
  in

  let a, b = div a_lst_sorted in
  let ans = (List.fold_left (+) 0 a) - (List.fold_left (+) 0 b) in

  Printf.printf "%d\n" ans


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

int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
   
	string s;
	cin>>s;
	long l = s.length();
	long ans =0;
	for(int i=0;i<l/2;i++)
		if(s[i] != s[l-i-1])
			ans++;
		cout<<ans;
}

Measured memory_bytes: 256
// at_abc144c.cpp : This file contains the 'main' function. Program execution begins and ends there.
//

#include <iostream>
#include<math.h>
using namespace std;
typedef long long ll;
int main()
{
    ll num;cin >> num;
    ll cur = sqrt(num);
    while (true) {
        
        if ((num+cur) % cur == 0) {
            cout << cur + num / cur - 2<<"\n";
            return 0;
        }
        else {
            cur--;
        }

    }
}

// Run program: Ctrl + F5 or Debug > Start Without Debugging menu
// Debug program: F5 or Debug > Start Debugging menu

// Tips for Getting Started: 
//   1. Use the Solution Explorer window to add/manage files
//   2. Use the Team Explorer window to connect to source control
//   3. Use the Output window to see build output and other messages
//   4. Use the Error List window to view errors
//   5. Go to Project > Add New Item to create new code files, or Project > Add Existing Item to add existing code files to the project
//   6. In the future, to open this project again, go to File > Open > Project and select the .sln file


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

typedef long long int ll;
#define INF 1999999999
#define MODA 1000000007
#define PI 3.1415926535897932384626433

int main()
{
    // freopen("input.txt", "r", stdin);
    // freopen("output.txt", "w", stdout);
    ios::sync_with_stdio(false);
    cin.tie(0);
    ll a, b;
    char ch;
    cin >> a >> ch >> b;
    if(ch == '+'){
        cout << a + b << endl;
    }
    else{
        cout << a - b << endl;
    }
    return 0;
}


Measured memory_bytes: 256
#include <stdio.h>
#include <queue>
using namespace std;

int main(){
    int n,q,query,x,t;;
    scanf("%d %d", &n,&q);
    priority_queue<int> A[n];
    for (int i = 0; i < q; i++)
    {        
        scanf("%d %d", &query,&t);
        switch (query){
            case 0:
                scanf("%d",&x);
                A[t].push(x);                       
                break;
            case 1:
                if (!A[t].empty()) printf("%d\n",A[t].top());
                break;
            case 2:
                if (!A[t].empty()) A[t].pop();
                break;
            default:
                break;
        }
    }    
    return 0;
}


Measured memory_bytes: 3744
#include<stdio.h>
#include<string.h>
#include<iostream>
#include<string>
#include<complex>
#include<algorithm>
#include<vector>
#include<math.h>
#include<set>
#include<map>
#include<queue>

int main()
{
	int n, a[100], s = 1, ans{};
	scanf("%d", &n);
	for (int i = 0; i < n; i++)
	{
		scanf("%d", a + i);
	}
	std::sort(a, a + n);
	for (int i = n - 1; i >= 0; i--)
	{
		ans += a[i] * s;
		s *= -1;
	}
	printf("%d\n", ans);
	return 0;
}

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

#define REP(i,n) for(ll i=0; i<(ll)(n); i++)
#define FOR(i,n,m) for (ll i=n; i<(ll)(m); i++)
#define pb push_back
#define INF 1000000007LL
#define all(a) (a).begin(),(a).end()
#define chmin(a,b) a=min(a,b)
#define chmax(a,b) a=max(a,b)

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

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


#include <cstdio>
#include <vector>
#include <algorithm>

using namespace std;

#define MAX_V 10000
vector<int> G[MAX_V];
vector<pair<int, int> > bridge;
vector<int> articulation;
int order[MAX_V], lowlink[MAX_V];
bool visited[MAX_V];
int V, E;

void dfs(int v, int pre, int &k)
{
    visited[v] = true;
    order[v] = k++;
    lowlink[v] = order[v];
    
    bool isArticulation = false;
    int cnt = 0;
    
    for (auto next_node: G[v]){
        if (!visited[next_node]){
            cnt++;
            dfs(next_node, v, k);
            lowlink[v] = min(lowlink[v], lowlink[next_node]);
            if (pre != -1 && order[v] <= lowlink[next_node]) isArticulation = true;
            if (order[v] < lowlink[next_node]) bridge.pb(make_pair(min(v, next_node), max(v, next_node)));
        }
        else if (next_node != pre){
            lowlink[v] = min(lowlink[v], order[next_node]);
        }
    }
    
    if (pre == -1 && cnt > 1) isArticulation = true;
    if (isArticulation) articulation.pb(v);
}

void detectBridges() {
    int k = 0;
    for (int i = 0; i < V; i++){
        if (!visited[i]) dfs(i, -1, k);
    }
}

int main(){
    ios::sync_with_stdio(false);
    cin >> V >> E;
    REP(i, E) {
        int x, y;
        cin >> x >> y;
        G[--x].push_back(--y);
        G[y].push_back(x);
    }
    
    detectBridges();
    
    cout << bridge.size() << endl;
    
    return 0;
}


Measured memory_bytes: 512
#include<bits/stdc++.h>
typedef long long ll;
using namespace std;
int main() {
	ll n,s=0,ans=0;
	ll MOD =1e9+7;
	scanf("%lld",&n);
	ll a[n];
	for(auto& k:a){
		scanf("%lld",&k);
		s+=k;
	}
	for(int i=0;i<n-1;i++){
		s-=a[i];
		ans+=((s)%MOD*(a[i])%MOD)%MOD;
		ans%=MOD;
	}
	ans%=MOD;
	printf("%lld",ans);
	return 0;
}


Measured memory_bytes: 5324
import math
def Sosu(N) :
    for i in range(2, int(math.sqrt(N))+1) :
        if N % i == 0 :
            return 'F'
    return 'T'
    

n = int(input())
ans = 0
for j in range(n) :
    a = int(input())
    if Sosu(a) == 'T' :
        ans += 1

print(ans)


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

#define MAX 200000
#define SENTINEL 2000000000
typedef long long llong;

int L[MAX / 2 + 2], R[MAX / 2 + 2];

llong merge(int A[], int n, int left, int mid, int right){
	
	int i,j,k;
	llong cnt = 0;
	int n1 = mid - left;
	int 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] = SENTINEL;
	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;   // =mid + j - k -1
		}
	}
	return cnt;
}

llong mergeSort(int A[], int n, int left, int right){
	
	int mid;
	llong 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;
}

int main(){
	int A[MAX], n, i;
	
	cin >> n;
	for(i=0; i<n; i++){
		cin >> A[i];
	}
	
	llong ans = mergeSort(A, n, 0, n);
	cout << ans << endl;
	
	return 0;
}




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

#define rep(i, n) for(int i=0; i < n; i++)
#define reps(i, n) for(int i=1; i <= n; i++)
#define INF 1e9
#define ALL(v) v.begin(), v.end()

using namespace std;
using ll=long long;

int dfs(int flg, ll cur, ll n){
  if (cur > n) return 0;
  int count = 0;
  if (flg == 0b111) count++;
  
  reps(i,3)count += dfs(flg|(int)pow(2,(i-1)), cur*10+(i*2+1), n);
  
  return count;
}

int main() {
  int N;
  cin >> N;
  int ans = 0;
  
  ans = dfs(0, 0, N);
  
  cout << ans << endl;
}


Measured memory_bytes: 256
import java.util.Scanner;
public class Main {
    public static void main(String args[]) {
        Scanner s = new Scanner(System.in);
        int n = Integer.parseInt(s.next());
        int r = Integer.parseInt(s.next());

        if(n>=10){
            System.out.println(r);

        }else{
            System.out.println(r+100*(10-n));

        }

    }
}

Measured memory_bytes: 21716
/**
 *	author: tanishq_code_c
**/
#include <bits/stdc++.h>
using namespace std;



void __print(int x) {cerr << x;}; void __print(long x) {cerr << x;}; void __print(long long x) {cerr << x;}; void __print(unsigned x) {cerr << x;}; void __print(unsigned long x) {cerr << x;}; void __print(unsigned long long x) {cerr << x;}; void __print(float x) {cerr << x;}; void __print(double x) {cerr << x;}; void __print(long double x) {cerr << x;}; void __print(char x) {cerr << '\'' << x << '\'';}; void __print(const char *x) {cerr << '\"' << x << '\"';}; void __print(const string &x) {cerr << '\"' << x << '\"';}; void __print(bool x) {cerr << (x ? "true" : "false");}
template<typename T, typename V>
void __print(const pair<T, V> &x) {cerr << '{'; __print(x.first); cerr << ','; __print(x.second); cerr << '}';}
template<typename T>
void __print(const T &x) {int f = 0; cerr << '{'; for (auto &i : x) cerr << (f++ ? "," : ""), __print(i); cerr << "}";}
void _print() {cerr << "]\n";}
template <typename T, typename... V>
void _print(T t, V... v) {__print(t); if (sizeof...(v)) cerr << ", "; _print(v...);}
#ifndef ONLINE_JUDGE
#define dbg(x...) cerr << "[" << #x << "] = ["; _print(x)
#else
#define dbg(x...)
#endif


#define int             							long long
#define setbits(x)     							    __builtin_popcountll(x)
#define zerobits(x)     							__builtin_ctzll(x)
#define mod             							1000000007
#define inf            							    1e18
#define endl            							'\n'
#define pb              							push_back
#define all(x)          							x.begin(),x.end()
#define ff              							first
#define ss              							second
#define rep(i,n)                                    for(int i = 0; i < n; i++)



void t_c_c()
{
	ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
	/*#ifndef ONLINE_JUDGE
		freopen("inp.txt", "r", stdin);
		freopen("out.txt", "w", stdout);
	#endif*/
	int x, k, d; cin >> x >> k >> d;
	int ans = 0;

	if (x < 0) x = abs(x);

	if (x % d == 0) {
		int moveforminus = x / d + 1;
		if (k < moveforminus) {
			cout << x - k*d << endl;
			return;
		}
		else {
			x = x - d * moveforminus;
			x = abs(x);
			if ((k - moveforminus) & 1) {
				cout << 0 << endl;
			}
			else {
				cout << d << endl;
			}
		}
	}
	else {
		int moveforminus = (x / d) + 1;
		if (k < moveforminus) {
			cout << x - k*d << endl;
			return;
		}
		else {
			x = x - d * moveforminus;
			x = x;
			if ((k - moveforminus) % 2 == 0) {
				cout << abs(x) << endl;
			}
			else {
				cout << x + d << endl;
			}
		}
	}
}

int32_t main()
{
	t_c_c();
	return 0;
}


Measured memory_bytes: 3588
import sys
input = sys.stdin.readline
n = int(input())
s = input().rstrip()
mod = 10**9+7

from collections import Counter
c = Counter(s)
ans = 0
for i in s:
  chk = 1
  for j,v in c.items():
    if j == i:
      continue
    chk *= v+1
  ans += chk
  ans %= mod
  c.update({i:-1})
  
print(ans%mod)

Measured memory_bytes: 3444
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define mp make_pair
#define pb push_back
#define pii pair<int,int>
const int maxn = 1e6 + 5;
const int mod = 1e9 + 7;
ll a[maxn] , n;
ll cost (ll x)
{
    ll ans = 0;
    for (int i = 1 ; i <= n ; i++) ans += (x - a[i]) * (x - a[i]);
    return ans;
}
int main()
{
    ios::sync_with_stdio(false);
    cin >> n;
    for (int i = 1 ; i <= n ; i++) cin >> a[i];
    ll ans = 1e18;
    for (int i = -200 ; i <= 200 ; i++)  ans = min (ans , cost(i));
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 3564
#include <bits/stdc++.h>
 
using namespace std;
const int MOD = 1e9+7;
const int INF = 0x3f3f3f3f;
const double PI = 4*atan(1);
typedef long long ll;
typedef pair<int,int> pii;
// int gcd(int a, int b) { 
//     if (a == 0) return b; 
//     return gcd(b % a, a); 
// }
// ll power(int base, int power) {
// 	ll prod = 1;
// 	ll b = base;
// 	while(power) {
// 		if (power & 1) {
// 			prod = f(prod*b);
// 		}
// 		b = f(b*b);
// 		power/=2;
// 	}
// 	return prod;
// }
int n,m,a[100],sum;
void solve() {
	cin >> n >> m;
	for (int i = 0; i < n; i++) {
		cin >> a[i];
		sum += a[i];
	}
	int cnt = 0;
	double x = 0.25/m*sum;
	for (int i = 0; i < n; i++) if (a[i] >= x) cnt++;
	if (cnt < m) {
		cout << "No\n";
	} else {
		cout << "Yes\n";
	}
}
int main() {

	// int t;
	// cin >> t;
	// for (int i = 1; i <= t; i++) { 
		// cout << "Case #" << i << ": ";
		solve();
	// }
}

Measured memory_bytes: 256
#include "iostream"
#include "algorithm"
#include "cstring"
#include "cstdio"
#include "vector"
using namespace std;
#define MAXN 2016
#define P 1000000007
int n;
vector<int> G[MAXN];
int A[MAXN] , F[MAXN] , d[MAXN] , s[MAXN] , siz[MAXN] , S;
void dfs( int u , int fa ) {
    if( A[u] ) s[u] = d[u] , siz[u] = 1; else siz[u] = s[u] = 0;
    int mxp = 0;
    for( int v : G[u] ) if( v != fa ) {
        d[v] = d[u] + 1 , dfs( v , u ) , s[u] += s[v] , siz[u] += siz[v];
        mxp = ( !mxp || s[v] > s[mxp] ) ? v : mxp;
    }
    int sum = s[u] - siz[u] * d[u] , mx = s[mxp] - siz[mxp] * d[u];
    if( sum >= 2 * mx ) F[u] = sum / 2;
    else
        F[u] = sum - mx + min( F[mxp] , ( 2 * mx - sum ) / 2 );
}
int main() {
    cin >> n;
    for( int i = 1 ; i <= n ; ++ i ) scanf("%1d",&A[i]);
    for( int i = 1 , u , v ; i < n ; ++ i ) {
        scanf("%d%d",&u,&v);
        G[u].push_back( v ) , G[v].push_back( u );
    }
    int res = 0x3f3f3f3f;
    for( int i = 1 ; i <= n ; ++ i ) {
        d[i] = 0, dfs( i , i );
        if( ( ~s[i] & 1 ) && F[i] == s[i] / 2 ) res = min( res , s[i] / 2 );
    }
    cout << ( res == 0x3f3f3f3f ? -1 : res ) << endl;
}

Measured memory_bytes: 512
#include<bits/stdc++.h>
using namespace std;
#define ll long long
int main(){
    ll n;
    cin>>n;

    ll a[n+1];

    for(ll i=0; i<n; i++){
        cin>>a[i];
    }
    ll sum=0;
    ll mx=a[0];
    for(ll i=0; i<n-1; i++){
        if(mx<=a[i+1]){
            mx=a[i+1];
        }
        else{
            mx=max(mx,a[i]);
            sum+=mx-a[i+1];
        }
    }
    cout<<sum<<endl;
}


Measured memory_bytes: 5152
#include<stdio.h>
int main(void){
  int a,b,c,d,N;
  scanf("%d", &N);
  if(N==1){
    printf("Hello World\n");
  }
  else{
    scanf("%d",&a);
    scanf("%d",&b);
    printf("%d\n", a+b);
  }
}

Measured memory_bytes: 128
#include <bits/stdc++.h> //C++の標準ライブラリを一行で一括でインクルードする
#include <math.h> //数学関数と数学定数を利用する
#define rep(i,n) for (int i = 0; i < (n); i++)
using namespace std;
typedef long long ll;
template<class T> void chmax(T &a,T b) { if (a<b) a=b;}
template<class T> void chmin(T &a,T b) { if (a>b) a=b;}

int main(){
  int n;
  cin >> n;
  vector<int> a(n),b(n);
  rep(i,n) cin >> a[i] >> b[i];
  ll r = 1;
  ll x = 1, y = 1;
  
  rep(i,n){    
    if(i==0) r = 1;
    else{
      r = max((a[i-1]*r + a[i] - 1)/a[i],(b[i-1]*r + b[i] - 1)/b[i]);
    }
    
    x = a[i] * r;
    y = b[i] * r;
  }
  
  cout << x + y << endl;
  
  return 0;
}

Measured memory_bytes: 256
// https://atcoder.jp/contests/agc019/tasks/agc019_b

fun main() {
    agc019b()
}

fun agc019b() {
    val a = readLine()!!
    val n = a.length.toLong()
    var count = (n - 1) * n / 2 + 1
    val appear = a.groupingBy { it }.eachCount()
    for (value in appear.values.map { it.toLong() }) {
        count -= (value * (value - 1) / 2)
    }
    println(count)
}

Measured memory_bytes: 42212
#!/usr/bin/env python3
import sys
sys.setrecursionlimit(10**8)
# input = sys.stdin.readline

n = int(input())
lr = []
for i in range(n):
    l, r = [int(item) for item in input().split()]
    lr.append((l, r))
lr.sort()
al = lr[0][0]; ar = lr[0][1]; anum = ar - al + 1
bl = lr[1][0]; br = lr[1][1]; bnum = br - bl + 1
# for line in lr:
#     print(line)

for i in range(2, n):
    nl = lr[i][0]; nr = lr[i][1]
    # add new to a
    adda_l = max(al, nl)
    adda_r = min(ar, nr)
    adda_num = max(adda_r - adda_l + 1, 0)
    adda_ret = adda_num + bnum
    # add new to b
    addb_l = max(bl, nl)
    addb_r = min(br, nr)
    addb_num = max(addb_r - addb_l + 1, 0)
    addb_ret = addb_num + anum
    # create new
    create_l = max(al, bl)
    create_r = min(ar, br)
    create_num = max(create_r - create_l + 1, 0)
    cnum = nr - nl + 1
    create_ret = create_num + cnum

    if adda_ret >= addb_ret and adda_ret >= create_ret:
        al = adda_l
        ar = adda_r
        anum = adda_num
    elif addb_ret >= adda_ret and addb_ret >= create_ret:
        bl = addb_l
        br = addb_r
        bnum = addb_num
    else:
        al = create_l
        ar = create_r
        anum = create_num
        bl = nl
        br = nr
        bnum = cnum

print(anum + bnum)

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

int n, m, solve[1010][1010];
string s1, s2;
int l1, l2, tmp;
    
int dp(int n, int m) {
    
    if (solve[n][m] >= 0) return solve[n][m];
    
    else if (n == 0 || m == 0) solve[n][m] = max(n, m);
    
    else {
        tmp = min(dp(n - 1, m), dp(n, m - 1)) + 1;
        if (s1[n - 1] == s2[m - 1]) solve[n][m] = min(tmp, dp(n - 1, m - 1));
        else solve[n][m] = min(tmp, dp(n - 1, m - 1) + 1);
    }
    
    return solve[n][m];
}

int main(void){

    cin >> s1;
    cin >> s2;
    l1 = s1.size();  l2 = s2.size();
    
    for (int i = 0; i <= 1000; i++) {
        for (int j = 0; j <= 1000; j++) solve[i][j] = -1;
    }
    
    cout << dp(l1, l2) << endl;
}



Measured memory_bytes: 7276
#include <bits/stdc++.h>
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define eps LDBL_EPSILON
#define moder 1000000007
#define int long long
#define ll long long
#define INF ((ll)1<<31)-1
#define P std::pair<int,int>
#define prique priority_queue<int,vector<int>,greater<int>>
using namespace std;
int n,a;
signed main(){
	bool b=false;
	cin>>n;
	rep(i,n){
		cin>>a;
		if(a%2)b=true;
	}
	if(b)puts("first");
	else puts("second");
    return 0;
}

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


int N,K;
int flag[200005];


//bool cmp1(int &a, int &b){  
//    return a>b;//最小值优先  
//}  

priority_queue<int> Pq;

void solution1(){
    int temp;
    for(int i=0; i<N; i++){
        scanf("%d", &temp);
        flag[temp]++;
    }
    for(int i=0; i<200004; i++){
        if(flag[i]>0){
            Pq.push(flag[i]);
        }
    }
    if(Pq.size() <= K){
        cout<<0<<endl;  
        return;
    }
    else{
        int Tl = Pq.size()-K;
        int count = 0;
        for(int i=0; i<K; i++){
        	Pq.pop();
		}
        for(int i=0; i<Tl; i++){
            count += Pq.top();
            Pq.pop();
        }
        cout<<count<<endl;
        return;
    }
}

int main(){
    cin >> N >> K;
    solution1();
}

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

int main(){
    int N, count, counts=0;
    cin >> N;
    for(int i=1;i<=N;i+=2){
        count=0;
        for(int j=1;j*j<i;j++){
            if(i%j==0) count += 2;
        }
        if(count==8) {
            counts++;
            //cout << i << " : " << counts << endl;
        }
    }
    cout << counts << endl;
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(void){
	int n,m;
	int a[200000],b[200000];
	int i;
	cin>>n;
	for(i=0;i<n;i++)	cin>>a[i];
	cin>>m;
	for(i=0;i<m;i++)	cin>>b[i];
	if(includes(a,a+n,b,b+m))	cout<<1<<endl;
	else						cout<<0<<endl;
	return 0;
}


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

using namespace std;

#define CIN ios_base::sync_with_stdio(0); cin.tie(NULL); cout.tie(NULL);
#define TEST_CASE(t) for(int zz=1 ; zz<=t ; zz++)
#define PRINT_CASE printf("Case %d: ",zz)
#define Debug(x)            cout<<#x " = "<<(x)<<endl

const int maxn = (int)3e5+5;
typedef long long ll;

int main()
{
    CIN
    //freopen("input.txt", "r", stdin);
    //freopen("output.txt", "w", stdout);

    //cout << "Fi Amanillah" << endl;

    int n;
    cin >> n;

    cout << n+ (n*n)+(n*n*n) << endl;

    return 0;
}




Measured memory_bytes: 3640
#include<iostream>
#include<algorithm>
#include<vector>
#include<string>
#include<utility>
#include<map>
#include<set>
#include <sstream>
#include<queue>
#include<stack>
#include<functional>
#include<math.h>
#include <iomanip>
using namespace std;


int main(void){
    long N;
    cin >> N;
    N = N;
    vector<char> cstr;
    for(int i =1; i < 100; i++){
        if(N <= pow(26,i)){

            N -= 1;
            for(int j = 0; j < i; j++){
                cstr.push_back((char)( 'a' + N % 26) );
                N = N / 26;
            }
            break;
        }else{
            N -= pow(26,i);
        }
    }    
    for(int i = 0; i < cstr.size(); i++){
        cout << cstr[cstr.size() - 1- i];
    }
    cout << endl;
}

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

int main() {
    Int a, b, c, k; cin >> a >> b >> c >> k;
    Int ans = 0;
    if (a >= k) {
        cout << k << endl;
        return 0;
    }

    ans = a;
    k -= a;
    k -= b;
    if (k > 0) {
        ans -= k;
    }
    cout << ans << endl;
}

Measured memory_bytes: 3632
#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < (int)(n); i++)
#define rrep(ri,n) for(int ri = (int)(n-1); ri >= 0; ri--)
#define rep2(i,x,n) for(int i = (int)(x); i < (int)(n); i++)
#define repit(itr,x) for(auto itr = x.begin(); itr != x.end(); itr++)
#define rrepit(ritr,x) for(auto ritr = x.rbegin(); ritr != x.rend(); ritr++)
#define ALL(x) x.begin(), x.end()
using ll = long long;
using namespace std;

int main(){
  int sx, sy, tx, ty;
  cin >> sx >> sy >> tx >> ty;

  int dx = tx - sx, dy = ty - sy;

  cout << string(dy, 'U');
  cout << string(dx, 'R');
  cout << string(dy, 'D');
  cout << string(dx+1, 'L');
  cout << string(dy+1, 'U');
  cout << string(dx+1, 'R');
  cout << string(1, 'D');
  cout << string(1, 'R');
  cout << string(dy+1, 'D');
  cout << string(dx+1, 'L');
  cout << string(1, 'U');
  cout << endl;
  return 0;
}

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

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

	while(n--){
		cin >> a >> b >>c;
		
		if(a*a + b*b == c*c or a*a+c*c == b*b or a*a == b*b + c*c){
			cout << "YES" << endl;
		}else{
			cout << "NO" << endl;
		}
	}

    return 0;
}


Measured memory_bytes: 2972
#include<stdio.h>

int partition(int *, int,int);

int main(){
  int i,n,A[100000],par;

  scanf("%d",&n);

  for(i=0;i<n;i++){
    scanf("%d",&A[i]);
      }

  par=partition(A,0,i-1);

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

  printf("%d\n",A[i]);

  return 0;
}
	 
int partition(int * A, int p,int r){
  int x,i,j,a;
  x=A[r];
  i=p-1;
  for(j=p;j<r;j++){
    if (A[j] <= x){
      i = i+1;
      a=A[i];
      A[i]=A[j];
      A[j]=a;
    }
  }

  a=A[i+1];
  A[i+1]=A[r];
  A[r]=a;
    
  return i+1;
}



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

int main(){
    int W,H,x,y,r;
    cin >> W >> H >> x >> y >> r;
    
    if (x - r >= 0 && x + r <= W && y - r >= 0 && y + r <= H) cout << "Yes" <<endl; 
    
    else cout << "No" << endl;
    
    return 0;
}


Measured memory_bytes: 3108
#include<cstdio>
#include<math.h>
#include<algorithm>
#include<vector>
#include<queue>
#include<string>
#include<set>
#include<cstring>
#include<map>
 
 
using namespace std;
#define int long long int
#define rep(i,n) for(int i=0;i<n;i++)
#define INF 1001001001
#define LLINF 1001001001001001001
#define mp make_pair
#define pb push_back
#define mod 1000000007

int X;
signed main(){
    scanf("%lld",&X);
    int ans=0;
    ans+=(int)(X/500)*1000;X%=500;
    ans+=(int)(X/5)*5;
    printf("%lld\n",ans);
    return 0;
}


Measured memory_bytes: 128
#include <iostream>
using namespace std;
int main(void){
    int daily, weekly, goal;
    int coins = 0;
    int N = 0;
    
    cin >> daily;
    cin >> weekly;
    cin >> goal;
    
    while(coins < goal){
        for(int i=0; i<7; i++){
            coins += daily;
            N++;
            
            if(coins>=goal){
                cout << N << "\n";
                return 0;
            }
        }
        
        coins += weekly;
        //N++;

        if(coins>=goal){
            cout << N << "\n";
            return 0;
        }        
    }
return 0;    
}



Measured memory_bytes: 3120
package main

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

func main() {
	r := bufio.NewReader(os.Stdin)
	var n int
	fmt.Fscan(r, &n)
	as := make([]int, n+1)
	for i := 1; i < n+1; i++ {
		fmt.Fscan(r, &as[i])
	}

	// 各箱のボール有無を管理
	bs := make([]int, n+1)
	for i := n; i >= 1; i-- {
		sum := 0
		for j := i + i; j <= n; j += i {
			// 自身より大きい倍数に入っている個数をチェック
			sum ^= bs[j]
		}
		bs[i] = sum ^ as[i]
	}

	var ans []int
	for i := 1; i < n+1; i++ {
		if bs[i] == 1 {
			ans = append(ans, i)
		}
	}

	w := bufio.NewWriter(os.Stdout)
	defer w.Flush()
	fmt.Fprintln(w, len(ans))
	for i := 0; i < len(ans); i++ {
		fmt.Fprintf(w, "%d ", ans[i])
	}
}


Measured memory_bytes: 9344
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int e, y;
  cin >> e >> y;
  if(e == 0) {
    if(1868 <= y && y <= 1911) {
      cout << 'M' << y - 1868 + 1 << endl;
    }
    else if(1912 <= y && y <= 1925) {
      cout << 'T' << y - 1912 + 1 << endl;
    }
    else if(1926 <= y && y <= 1988) {
      cout << 'S' << y - 1926 + 1 << endl;
    }
    else cout << 'H' << y - 1989 + 1 << endl;
  }
  else if(e == 1) cout << 1868 + y - 1 << endl;
  else if(e == 2) cout << 1912 + y - 1 << endl;
  else if(e == 3) cout << 1926 + y - 1 << endl;
  else cout << 1989 + y - 1 << endl;
}


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

struct BinaryIndexedTree {
  BinaryIndexedTree(size_t n) : n(n), v(n + 1, 0) {}

  size_t n;
  vector<int> v;

  int sum(int k) {
    int ret = 0;
    for (; k; k -= k & -k) ret += v[k];
    return ret;
  }

  void add(int k, int x) {
    for (; k <= n; k += k & -k) v[k] += x;
  }
};

int main() {
  cin.tie(0);
  ios::sync_with_stdio(0);
  int N, M;
  cin >> N >> M;

  M++;

  vector<pair<int, pair<int, int>>> v(N);
  for (int i = 0; i < N; ++i) {
    int l, r;
    cin >> l >> r;
    v[i].first = r - l + 1;
    v[i].second.first = l;
    v[i].second.second = r;
  }

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

  int idx = 0;
  BinaryIndexedTree bit(M + 1);
  for (int d = 1; d < M; ++d) {
    while (idx < N && v[idx].first < d) {
      pair<int, int> r = v[idx].second;
      bit.add(r.first, 1);
      bit.add(r.second + 1, -1);
      idx++;
    }

    int ans = N - idx;
    for (int i = d; i < M; i += d) {
      ans += bit.sum(i);
    }

    cout << ans << endl;
  }
}


Measured memory_bytes: 4864
#define _CRT_SECURE_NO_WARNINGS
#pragma _attribute_((optimize("-O2")))
#pragma comment(linker, "/STACK:102400000,102400000")

#include <iostream>
#include <queue>
#include <stack>
#include <cstdio>
#include <vector>
#include <map>
#include <list>
#include <set>
#include <cstdio>
#include <bitset>
#include <algorithm>
#include <cmath>
#include <cstring>
#include <cstdlib>
#include <string>
#include <sstream>
#include <time.h>
#include <iomanip>
#define Endl endl

//#define Local

using namespace std;

int main()
{
	ios::sync_with_stdio(false);
	cin.tie(0);
	//freopen("input1.txt", "r", stdin);
	//freopen("output1.txt", "w", stdout);

	long long N;
	cin >> N;
	long long h, n, w;
	for (h = 1; h <= 3500; h++)
		for (n = 1; n <= 3500; n++)
		{
			long long t = 4 * h*n - N*(h + n);
			if (t <= 0)
				continue;
			if ((N*h*n) % t == 0)
			{
				w = (N*h*n) / t;
				cout << h << " " << n << " " << w << endl;
				return 0;
			}

		}

#ifdef Local
	cout << "time: " << (long long)clock() * 1000 / CLOCKS_PER_SEC << " ms" << endl;
#endif
	return 0;
}

Measured memory_bytes: 256
import sys
input = sys.stdin.readline

n,m,k = map(int,input().split())
a = list(map(int,input().split()))
b = list(map(int,input().split()))

if a[0] > k:
    res = 0
    for i in range(m):
        if b[i] <= k:
            k -= b[i]
            res += 1
        else:
            break
    print(res)
else:
    cnt = 0
    a_idx = 0
    for i in range(n):
        if a[i] <= k:
            k -= a[i]
            cnt += 1
            a_idx = i
        else:
            break
    
    b_idx = -1
    for i in range(m):
        if b[i] <= k:
            k -= b[i]
            cnt += 1
            b_idx = i
        else:
            break
    
    res = cnt

    for i in range(a_idx,-1,-1):
        k += a[i]
        cnt -= 1
        fi = b_idx
        for j in range(b_idx+1,m):
            if b[j] <= k:
                k -= b[j]
                cnt += 1
                fi = j
            else:
                break
        b_idx = fi
        res = max(res,cnt)
    print(res)


Measured memory_bytes: 117964
#include "iostream"
#include "algorithm"
#include "string"
#include "vector"
#include "cmath"
#include "bitset"
#include "queue"
#include "functional"
#include "map"
#include "unordered_map"
#include "set"
#include "stack"

#define rep(n) for (int i = 0; i < n; ++i)
#define REP(n,i) for (int i = 0; i < n; ++i)
#define mod 1000000007
#define sp ' '
#define intmax 2147483647
#define llmax 9223372036854775807
#define nyan "(=^･ω･^=)"
#define mkp make_pair
#define P pair<ll, ll>
typedef long long ll;
using namespace std;

string s, t;
unordered_map<char, char>mp;
set<char>st;
int main() {
	cin >> s >> t;
	rep(s.size()) {
		if (mp.find(s[i]) == mp.end())
			mp[s[i]] = t[i];
		else {
			if (mp[s[i]] != t[i]) {
				cout << "No" << endl;
				return 0;
			}
		}
	}
	for (auto it = mp.begin(); it != mp.end(); ++it) {
		if (st.find(it->second) == st.end())
			st.insert(it->second);
		else {
			cout << "No" << endl;
			return 0;
		}
	}
	cout << "Yes" << endl;
	return 0;
}

Measured memory_bytes: 776
#include <bits/stdc++.h>
using namespace std;
#define Rep(i,N) for(int i = 0; i < N;i++)
typedef pair<int,int> Pi;
#define F first
#define S second
#define INF 1 << 28

inline void chmax(int &a,int b) {
  a = max(a,b);
}

inline void chmin(int &a,int b) {
  a = min(a,b);
}

int main()
{
  int N, K, A, B;
  cin >> N >> K;
  
  while(K--) {
    cin >> A >> B;
    if(A > N / 2)A = N - A + 1;
    if(B > N / 2)B = N - B + 1;
    int ans = min(A,B) % 3;
    if(!ans)ans = 3;
    cout << ans << endl;
  }

  return 0;
}

Measured memory_bytes: 3060
#include <iostream>
#include <cstdio>

using namespace std;

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

int main() {
	float x[4], y[4];
	bool flag;

	while (cin>>x[0]>>y[0]>>x[1]>>y[1]>>x[2]>>y[2]>>x[3]>>y[3] != NULL) {
		flag = false;
		REP(i,2) {
			if (x[i*2+1] == x[i*2] && y[((i+1)*2+1)%4] == y[((i+1)*2)%4])
				flag = true;
		}
		if (!flag && (y[1]-y[0])/(x[1]-x[0])*(y[3]-y[2])/(x[3]-x[2]) == -1)
			flag = true;

		if (flag)
			printf("YES\n");
		else
			printf("NO\n");
	}
	return 0;
}

Measured memory_bytes: 1184
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        long M = sc.nextInt();

        List<Long> H = new ArrayList<Long>();
        for (int i = 0; i < N; i++) {
            H.add(sc.nextLong());
        }

        List<Integer> jud = new ArrayList<Integer>(Collections.nCopies(N, 1));

        for (int i = 0; i < M; i++) {
            int a = sc.nextInt();
            int b = sc.nextInt();
            if (H.get(a - 1) <= H.get(b - 1)) {
                jud.set(a - 1, 0);
            }
            if (H.get(b - 1) <= H.get(a - 1)) {
                jud.set(b - 1, 0);
            }
        }
        sc.close();

        int count = 0;
        for (int i = 0; i < N; i++) {
            if (jud.get(i) == 1) {
                count++;
            }
        }

        System.out.println(count);
    }
}

Measured memory_bytes: 63780
import sys
n,w=list(map(int, sys.stdin.readline().split()))
arr=[list(map(int, sys.stdin.readline().split())) for i in range(n)]

dp=[[0]*(w+2) for i in range(n + 1)]

for i in range(1,w+1):
	if i >= arr[0][0]:
		dp[0][i]=arr[0][1]
		
for i in range(1,n):
	for j in range(1,w+1):
		if j >= arr[i][0]:
			dp[i][j]=max(dp[i-1][j],dp[i-1][j-arr[i][0]]+arr[i][1]);
		else:
			dp[i][j]=dp[i-1][j]


print(max(dp[n-1]))

Measured memory_bytes: 120428
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        int n = scanner.nextInt();
        int[] nums = new int[n];
        long[] sum = new long[n + 1];
        for (int i = 0; i < n; i++) {
            nums[i] = scanner.nextInt();
            sum[i + 1] = sum[i] + nums[i];
        }
        long ans = 0;
        int mod = 1000000007;
        for (int i = 0; i < n - 1; i++) {
            int cur = nums[i];
            ans += ((cur % mod) * ((sum[n] - sum[i + 1]) % mod)) % mod;
            ans %= mod;
        }
        System.out.println(ans);
    }
}

Measured memory_bytes: 61692
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.Collections;

public class Main {
	public static void main(String[] args) {
		try {
			BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
			int n = Integer.parseInt(br.readLine());
			String in2 = br.readLine();
			ArrayList<Integer> aList = new ArrayList<Integer>();
			int res = 0;

			for( String str:in2.split(" ") ){
				aList.add(Integer.parseInt(str));
			}

			Collections.sort(aList,Collections.reverseOrder());


			for(int i=0;i<aList.size();i++){
				int a = aList.get(i);
				i = i+1;
				int b = aList.get(i);
				res = res + ((a<b)?a:b);
			}

			System.out.println(res);

		}  catch (IOException e) {
			e.printStackTrace();
		}

	}

}


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

char m[128];

int main() {
	string s;
	cin >> s;
	int l = s.length();
	if (l % 2 == 1) {
		cout << "No" << endl;
		return 0;
	}

	m['b'] = 'd'; m['d'] = 'b'; m['p'] = 'q'; m['q'] = 'p';
	for (int i = 0; i < l / 2; i++) {
		if (m[s[i]] != s[l - 1 - i]) {
			cout << "No" << endl;
			return 0;
		}
	}
	cout << "Yes" << endl;
	return 0;
}


Measured memory_bytes: 512
import numpy as np

n = input()
l = [int(i) for i in input().split()]

cnt = 0
for i in range(1,len(l)-1):
    l_tmp = [l[i-1], l[i], l[i+1]]
    l_tmp.sort()
    arr_tmp = np.array(l_tmp)
    if len(arr_tmp[arr_tmp>l[i]])==1:
        cnt += 1
        
print(cnt)

Measured memory_bytes: 18380
#include <algorithm>
#include <iostream>
#include <vector>
#include <boost/operators.hpp>
using namespace std;

#define REP(i, n) for (int i = 0; i < (int)(n); ++i)
#define ALL(c) (c).begin(), (c).end()

// a を m で割った余り(>=0)を返す。
constexpr inline int mod(int a, int m) noexcept {
    int r = a % m;
    return r < 0 ? r + m : r;
}

int main() {
    int64_t N, X, M; cin >> N >> X >> M;

    // X + X^2 + X^4 + X^8 + ... (mod M)
    vector<int64_t> seen(M+1, -1);
    vector<int64_t> sum(M+10);

    int64_t a = X;
    int64_t S = 0;
    for (int64_t i = 1; i <= N; ++i) {
        S += a;
        if (i < (int)sum.size()) sum[i] = sum[i-1] + a;

        if (i < (int)sum.size() && seen[a] != -1) {
            int64_t period = i - seen[a];
            int64_t loop_sum = sum[i] - sum[seen[a]];
            int64_t n_loop = (N-i) / period;
            S += n_loop * loop_sum;
            i += n_loop * period;
        }
        seen[a] = i;

        a = (a * a) % M;
    }
    cout << S << endl;
}


Measured memory_bytes: 4744
//最初と最後しかボタンBを押さなくていいのでは？ -> 難しい条件分岐をせずとも、4パターン試せばよさそう。
#include <iostream>
#include <algorithm>
#define int long long
using namespace std;

int x, y;

int calc(int x, int y) {
	if (x > y) return 1e+18;
	return y - x;
}

signed main() {
	cin >> x >> y;
	int res1 = calc(x, y);
	int res2 = calc(x, -y) + 1;
	int res3 = calc(-x, y) + 1;
	int res4 = calc(-x, -y) + 2;
	cout << min({res1, res2, res3, res4}) << endl;
	return 0;
}

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

int main() {
    int n, p[20];
    cin >> n;
    REP(i, n)
        cin >> p[i];
    int answer = 0;
    for (int i = 1; i < n - 1; i++)
        if ((p[i - 1] < p[i] && p[i] < p[i + 1]) ||
            (p[i + 1] < p[i] && p[i] < p[i - 1]))
            answer++;
    cout << answer;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ll long long
#define V vector<long long>
#define VV vector<vector<long long>>
#define rep(i,n) for(ll (i)=0;(i)<(n);++(i))
using namespace std;

int main(){
    ll h,w;
    cin>>h>>w;
    if(h==1||w==1){
        cout<<1<<endl;
        return 0;
    }
    cout<<(h*w+2-1)/2<<endl;
}


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

using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<pii,pii> ppp;
typedef map<ppp,int>::iterator miter;
const int N = 100;
const int B1 = 131;
const int B2 = 127;
const int M1 = 998244353;
const int M2 = 1e9+7;
int _w;

int n;
char s[N];
map<ppp,int> c1, c2;

pii hsh( int *a, int n ) {
	ll h1 = 0, h2 = 0;
	for( int i = 0; i < n; ++i ) {
		h1 = (h1 * B1 + a[i]) % M1;
		h2 = (h2 * B2 + a[i]) % M2;
	}
	return pii( int(h1), int(h2) );
}

void prelude( char *begin, char *end, map<ppp,int> &cnt ) {
	static int tmp[N], tn, t1[N], n1, t2[N], n2;
	tn = 0;
	while( begin != end ) tmp[tn++] = *(begin++);
	for( int s = 0; s < (1<<n); ++s ) {
		n1 = n2 = 0;
		for( int i = 0; i < n; ++i )
			if( s & (1<<i) ) t1[n1++] = tmp[i];
			else t2[n2++] = tmp[i];
		++cnt[ ppp( hsh(t1, n1), hsh(t2, n2) ) ];
	}
}

int main() {
	cin >> n >> s;
	prelude(s, s+n, c1);
	reverse(s+n, s+n+n);
	prelude(s+n, s+n+n, c2);
	ll ans = 0;
	for( miter it = c1.begin(); it != c1.end(); ++it )
		ans += 1LL * it->second * c2[it->first];
	printf( "%lld\n", ans );
	return 0;
}


Measured memory_bytes: 49408
#include<bits/stdc++.h>
//ios::sync_with_stdio(false);cin.tie(0);
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> pii;
typedef pair<pii,int> ppii;
typedef pair<int,pii> pipi;
typedef pair<ll,ll> pll;
typedef pair<pll,ll> ppll;
typedef pair<ll,pll> plpl;
typedef tuple<ll,ll,ll> tl;
ll mod=1000000007;
ll mod2=998244353;
ll mod3=1000003;
ll mod4=998244853;
ll inf=1000000000000000000;
double pi=2*acos(0);
#define rep(i,m,n) for(ll i=m;i<n;i++)
#define rrep(i,n,m) for(ll i=n;i>=m;i--)
int dh[4]={1,-1,0,0};
int dw[4]={0,0,1,-1};
int ddh[8]={-1,-1,-1,0,0,1,1,1};
int ddw[8]={-1,0,1,-1,1,-1,0,1};
ll lmax(ll a,ll b){
    if(a<b)return b;
    else return a;
}
ll lmin(ll a,ll b){
    if(a<b)return a;
    else return b;
}
ll gcd(ll a,ll b){
    if(a<b)swap(a,b);
    if(b==0)return a;
    if(a%b==0)return b;
    return gcd(b,a%b);
}
ll Pow(ll n,ll k){
    ll ret=1;
    ll now=n;
    while(k>0){
        if(k&1)ret*=now;
        now*=now;
        k/=2;
    }
    return ret;
}
ll gya[1000010];
ll kai[1000010];
ll beki(ll n,ll k,ll md){
  ll ret=1;
  ll now=n;
  while(k>0){
    if(k%2==1){
      ret*=now;
      ret%=md;
    }
    now*=now;
    now%=md;
    k/=2;
  }
  return ret;
}
ll gyaku(ll n,ll md){
  return beki(n,md-2,md);
}
void nckinit(ll n,ll md){
  kai[0]=1;
  kai[1]=1;
  for(int i=2;i<=n;i++){
    kai[i]=kai[i-1]*i;
    kai[i]%=md;
  }
  gya[n]=gyaku(kai[n],md);
  for(int i=n-1;i>=1;i--){
    gya[i]=gya[i+1]*(i+1);
    gya[i]%=md;
  }
  gya[0]=1;
}
ll nck(ll n,ll k,ll md){
  if(k<0)return 0;
  if(k==0||n==k)return 1;
  ll ret=kai[n];
  ret*=gya[n-k];
  ret%=md;
  ret*=gya[k];
  ret%=md;
  return ret;
}
ll npk(ll n,ll k,ll md){
  if(k<0)return 0;
  if(k==0)return 1;
  ll ret=kai[n];
  ret*=gya[n-k];
  ret%=md;
  return ret;
}
int main(){
    ios::sync_with_stdio(false);cin.tie(0);
    ll n,c;cin>>n>>c;
    ll sum[401][401];
    rep(i,0,401){
        sum[i][0]=0;
        rep(j,1,401){
            sum[i][j]=(sum[i][j-1]+beki(j,i,mod))%mod;
        }
    }
    /*rep(i,0,c+1){
        rep(j,0,c+1)cout<<sum[i][j]<<" ";
        cout<<endl;
    }*/
    ll dp[n+1][c+1];
    memset(dp,0,sizeof dp);
    dp[0][0]=1;
    ll cc[n],d[n];
    rep(i,0,n)cin>>cc[i];
    rep(i,0,n)cin>>d[i];
    rep(i,1,n+1){
        ll a=cc[i-1];
        ll b=d[i-1];
        rep(j,0,c+1){
            rep(k,0,j+1){
                (dp[i][j]+=dp[i-1][k]*((sum[j-k][b]-sum[j-k][a-1]
                                        +mod)%mod))%=mod;
            }
        }
    }
    cout<<dp[n][c]<<endl;
   /* rep(i,0,n+1){
        rep(j,0,c+1)cout<<dp[i][j]<<" ";
        cout<<endl;
    }*/
}


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

using namespace std;
#define rep(i,n) for(int i=0;i<n;i++)
#define rep1(i,n) for(int i=1;i<=n;i++)
typedef long long ll;


int main(){
  string a,b,c;
  cin >> a >> b >> c;
  if(a[a.size()-1]==b[0] && b[b.size()-1]==c[0])cout << "YES" << endl;
  else cout << "NO" << endl;
}


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

namespace ConsoleApp
{
    class Program
    {
        static void Main(string[] args)
        {
            var N = int.Parse(Console.ReadLine());
            var h = Console.ReadLine().Split().Select(int.Parse).ToArray();

            var ans = new int[N];

            ans[1] = Math.Abs(h[0] - h[1]);
            for (int i = 2; i < N; i++)
            {
                ans[i] = Math.Min(ans[i - 1] + Math.Abs(h[i - 1] - h[i]), ans[i - 2] + Math.Abs(h[i - 2] - h[i]));
            }

            Console.WriteLine(ans[N - 1]);
        }
    }
}


Measured memory_bytes: 18016
#include <iostream>
#include <cstdio>
#include <vector>
#include <algorithm>
#include <utility>
#include <string>

using namespace std;

string s;

bool check1(int from, int to) {
	if (from == to) {
		return true;
	}

	int x = from;
	while (x < s.size()) {
		if (x + 2 == to || x + 1 == to) {
			return true;
		}

		if (s[x+2] == '.') {
			x += 2;
		} else if (s[x+1] == '.') {
			x++;
		} else {
			break;
		}
	}

	return false;
}

pair<int, int> pass(int x, int y, int x2, int y2) {
	while (x < y && x < s.size() && y < s.size()) {
		// printf("xy %d %d ", x, y);
		if (s[x + 2] == '.' && x + 2 != y) {
			x += 2;
		} else if (s[x + 1] == '.' && x + 1 != y) {
			x++;
		} else if (y == y2) {
			break;
		} else if (s[y + 1] == '.') {
			y++;
		} else if (s[y + 2] == '.') {
			y += 2;
		} else {
			// printf("\n");
			break;
		}
		// printf(" -> %d %d\n", x, y);
	}

	if (x > y) {
		return make_pair(x, y);
	} else {
		return make_pair(-1, -1);
	}
}

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

	a--;
	b--;
	c--;
	d--;

	s += "#####";

	if (c > d) {
		auto p = pass(a, b, c, d);
		if (p.first == -1) {
			cout << "No" << endl;
			return 0;
		} else {
			a = p.first;
			b = p.second;
		}
	}

	bool ok2 = check1(b, d);
	bool ok1 = check1(a, c);
	cout << (ok1 && ok2 ? "Yes" : "No") << endl;

	return 0;
}


Measured memory_bytes: 644
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
ll n,k;
ll v[107],w[107];
ll dp[100][100007];
ll f(ll i,ll s)
{
if(s>k)
return -LLONG_MAX;
if(i==n)
return 0;
if(dp[i][s]!=-1)
return dp[i][s];
return dp[i][s]=max(v[i]+f(i+1,s+w[i]),f(i+1,s));
}
int main()
{
cin>>n>>k;
ll i,j;
for(i=0;i<n;i++)
{
cin>>w[i]>>v[i];
for(j=0;j<=k;j++)
dp[i][j]=-1;
}
cout<<f(0,0);
return 0;
}

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


int main() {

    int h, w;
    cin >> h >> w;
    char board[100][100];
    for (int i = 0; i < h; ++i) {
        for (int j = 0; j < w; ++j) {
            char a; cin >> a;
            board[i][j] = a;
        }
    }
    for (int i = 0; i < w+2; ++i) cout << '#';
    cout << endl;
    for (int i = 0; i < h; ++i) {
        cout << '#';
        for (int j = 0; j < w; ++j) {
            cout << board[i][j];
        }
        cout << '#' << endl;
    }
    for (int i = 0; i < w+2; ++i) cout << '#';
    cout << endl;
    return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
int main(){
int a,b,k,i;
scanf("%d", &k);
scanf("%d%d", &a,&b);

for(i=a;i<=b;i++){
if(i%k==0){
printf("OK\n");
return 0;
}
}
printf("NG\n");
return 0;
}


Measured memory_bytes: 1664
#include<iostream>
#include<string.h>

using namespace std;

int main() {
    int n, a;
    cin >> n;
    while (n--) {
        cin >> a;
        if (!(a % 2))
            if (a % 3 && a % 5) {
                cout << "DENIED" << endl;
                return 0;
            }
    }
    cout << "APPROVED" << endl;
    return 0;
}


Measured memory_bytes: 256
def main():
    N, M = map(int, input().split())
    l = 1
    r = N - 1
    if N % 2 == 0:
        flag = True
        for i in range(M):
            if r - l <= N // 2 and flag:
                l += 1
                flag = False
            print(l,r)
            l += 1
            r -= 1
    else:
        for i in range(M):
            print(l,r)
            l += 1
            r -= 1

if __name__ == "__main__":
    main()

Measured memory_bytes: 69616
#include <bits/stdc++.h>
using namespace std;
#define REP(i,a) for(int i = 0; i < (a); i++)
#define ALL(a) (a).begin(),(a).end()
typedef long long ll;
typedef pair<int, int> P;
const int INF = 1e9;
const int MOD = 1e9 + 7;

int ans = INF;
int N,A,B,C;
int l[8];

void DFS(int depth, int a, int b, int c, int cnt){
    if(depth == N){
        if(a == 0 || b == 0 || c == 0) return;
        ans = min(ans, abs(A - a) + abs(B - b) + abs(C - c) + 10 * cnt);
        return;
    }
    if(a == 0) DFS(depth + 1, a + l[depth], b, c, cnt);
    else DFS(depth + 1, a + l[depth], b, c, cnt + 1);
    if(b == 0) DFS(depth + 1, a, b + l[depth], c, cnt);
    else DFS(depth + 1, a, b + l[depth], c, cnt + 1);
    if(c == 0) DFS(depth + 1, a, b, c + l[depth], cnt);
    else DFS(depth + 1, a, b, c + l[depth], cnt + 1);
    DFS(depth + 1, a, b, c, cnt);
}

signed main(){
    cin >> N >> A >> B >> C;
    REP(i,N){
        cin >> l[i];
    }
    DFS(0, 0, 0, 0, 0);
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for (int i = 0; i < int(n); i++)
#define rep1(i,n) for (int i = 1; i <= int(n); i++)
#define repR(i,n) for (int i = int(n)-1; i >= 0; i--)
#define rep1R(i,n) for (int i = int(n); i >= 1; i--)
#define all(x) (x).begin(), (x).end()
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define fst first
#define snd second
#define cauto const auto
#ifdef LOCAL
#define dump(...) cerr << "[" << __LINE__ << ":" << __FUNCTION__ << "] ", _dmp_(#__VA_ARGS__, __VA_ARGS__);
void _dmp_(const char*) { cerr << endl; }
template <class T, class... U>
void _dmp_(const char *s, T const& x, U const& ...y) { const char *o = "({[", *e = "]})"; for (int i = 0; *s != '\0'; cerr << *s++) { if (count(o,o+3,*s)) i++; if (count(e,e+3,*s)) i--; if (!i && *s == ',') break; } cerr << " = " << x; if (*s == ',') cerr << ", ", s++; _dmp_(s, y...); }
#else
#define dump(...)
#endif
using ll = long long;
#define int ll
template <class T> using pque_max = priority_queue<T>;
template <class T> using pque_min = priority_queue<T, greater<T> >;
#define CONAINER_OUTPUT os << "{"; for (auto const& x : v) os << " " << x; return os << " }";
template <class T> ostream& operator<<(ostream& os, vector<T> const& v) { CONAINER_OUTPUT }
template <class T> ostream& operator<<(ostream& os, deque<T> const& v) { CONAINER_OUTPUT }
template <class T> ostream& operator<<(ostream& os, set<T> const& v) { CONAINER_OUTPUT }
template <class T, class U> ostream& operator<<(ostream& os, map<T,U> const& v) { CONAINER_OUTPUT }
#undef CONAINER_OUTPUT
template <class T> istream& operator>>(istream& is, vector<T>& v) { for (auto& x : v) is >> x; return is; }
template <class T, class S> ostream& operator<<(ostream& os, pair<T,S> const& p) { return os << "(" << p.first << ", " << p.second << ")"; }
template <class T, class S> istream& operator>>(istream& is, pair<T,S> const& p) { return is >> p.first >> p.second; }
struct _Init_ { _Init_() { cin.tie(nullptr); ios::sync_with_stdio(false); cout << fixed << setprecision(20); } } _init_;

template <class T> void quit(T const& x) { cout << x << endl; exit(0); }
template <class T> bool chmin(T& x, T const& y) { if (x > y) { x = y; return true; } return false; }
template <class T> bool chmax(T& x, T const& y) { if (x < y) { x = y; return true; } return false; }
#define YesNo(c) ((c) ? "Yes" : "No")
////////////////////////////////

int32_t main() {
    int n; cin >> n;
    vector<int> b(n-1); cin >> b;

    int s = b[0];
    rep (i,n-2) s += min(b[i],b[i+1]);
    s += b[n-2];
    cout << s << endl;
}


Measured memory_bytes: 256