akhauriyash/Code-Regression huggingface dataset:
S = input()
power = 0
answer = 0
temps = int(S)
while True:
    if temps < 10:
        break
    temps = temps/10
    power += 1

SS = list(S)

for i in range(1 << power):
    output = []
    for j in range(power):
        if (i>>j)&1 == 1:
            output.append(SS[j])
            output.append('+')
        else:
            output.append(SS[j])
    output.append(SS[power])
    temp_string = ''.join(output)
    answer += eval(temp_string)
    
print(answer)

Measured memory_bytes: 3064
#include <iostream>
#include <climits>
#include <bits/stdc++.h> 
using namespace std;
 
long long int topdown(long long int i, long long int w,long long  int n, long long int value[],long long int weight[], vector<vector<long long  int>> &dp){
    if(i == -1 || w <= 0) return 0;
    // cout << i << " " << w << " : " << dp[i][w] << endl;
    if(dp[i][w] != -1) return dp[i][w];
    if(weight[i] > w) return dp[i][w] = topdown(i-1, w,n, value, weight, dp);
    return dp[i][w] = max(topdown(i-1, w, n, value, weight, dp), value[i] + topdown(i-1, w - weight[i], n, value, weight, dp));
}
 
 
int main() {
    long long int n,w;
    cin >> n >> w;
    vector<vector<long long int>>  dp(n+1, vector<long long int> (w+1,-1));
    
 
    long long int value[n], weight[n];
    for(long long int i=0;i<n;i++){
        cin >> weight[i] >> value[i];
    }
    
    cout <<  topdown(n-1, w, n, value, weight, dp);
 
	return 0;
}

Measured memory_bytes: 83144
/*!enjoy karo yaar!*/

//CF,CC,AtC,SPOJ: hp1999
//HE: hemant269
//HR: hemant2132

// ref: https://img.atcoder.jp/abc139/editorial.pdf
// crux: mapping the "matches" to a graph

// really nice problem!

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

//#define     int             long long int
#define     fast()          ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define     all(x)          begin(x),end(x)
#define     rz(x)           resize(x)
#define     asn(x,y)        assign(x,y)
#define     mem(a,b)        memset(a,b,sizeof(a))
#define     sz(x)           ((int)(x.size()))
#define     eb              emplace_back
#define     pb              push_back
#define     pf              push_front
#define     pob             pop_back
#define     pof             pop_front
#define     ins             insert
#define     vi              vector<int>
#define     pii             pair<int,int>
#define     mii             map<int,int>
#define     F               first
#define     S               second
#define     remax(a,b)      a=max(a,b)
#define     remin(a,b)      a=min(a,b)
#define     bitcount(x)     __builtin_popcountll(x)
#define     iceil(n,x)      (((n)-1)/(x)+1)
#define     dbug(x)         cout<<#x<<": "<<(x)<<"\n"
#define     flush           fflush(stdout)
#define     show(x)         for(auto zz:x)cout<<zz<<" ";cout<<"\n";
#define     show2(x)        for(auto zz:x)cout<<zz.F<<" "<<zz.S<<"\n";

typedef unsigned long long ull;
typedef long long ll;
typedef long double ld;

const ld pi=acos(-1);
const ll inf=1e18,M=1e9+7;
const int N=1e3+5,NN=N*N;

vi v[NN],vis(NN),dist(NN),ind(NN);
int mat[N][N];

int n;

int getnode(int x,int y)
{
    if(x>y)
        swap(x,y);

    return ((x-1)*n+y);
}

void solve()
{
    cin>>n;

    for(int i=1;i<=n;++i)
    {
        for(int j=0;j<n-1;++j)
            cin>>mat[i][j];
    }

    for(int i=1;i<=n;++i)
    {
        for(int j=1;j<n-1;++j)
        {
            int a=getnode(i,mat[i][j-1]);
            int b=getnode(i,mat[i][j]);
            v[a].pb(b);                         // req. condition for ordering the matches...
            ++ind[b];
        }
    }

    queue<int> qu;

    for(int i=1;i<=n;++i)
    {
        for(int j=i;j<=n;++j)
        {
            int x=getnode(i,j);
            if(sz(v[x]) && !ind[x])
                qu.push(x),vis[x]=1;
        }
    }

    int ans=0;
    while(!qu.empty())
    {
        auto x=qu.front();
        qu.pop();

        ans=max(ans,dist[x]);

        for(auto c:v[x])
        {
            if(vis[c])                      // detecting a cycle
            {
                cout<<-1;
                return;
            }

            --ind[c];
            if(!ind[c])
            {
                qu.push(c);
                vis[c]=1;
                dist[c]=dist[x]+1;
            }
        }
    }

    for(int i=1;i<=n*n;++i)
    {
        if(sz(v[i]) && ind[i])
        {
            cout<<-1;
            return;
        }
    }

    cout<<ans+1;
}

int32_t main()
{
    fast();

    int t=1;
    //cin>>t;
    for(int z=1;z<=t;++z)
    {
        solve();
        //cout<<"\n";
    }

    return 0;
}



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

#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)

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

  if(a+b+c>=22) cout << "bust";
  else cout << "win";
}

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

using namespace std;
long double x[1010],y[1010],sum = 0,num = 1;
vector<int> v;
int main(){
	cout.precision(20);
	int i,n;
	cin >> n;
	for(i=0;i<n;i++){
		cin >> x[i] >> y[i];
		v.push_back(i);
		num *= (i + 1);
	}
	for(i=1;i<n;i++){
		sum += sqrt((x[i - 1] - x[i])*(x[i - 1] - x[i]) + (y[i - 1] - y[i])*(y[i - 1] - y[i]));
	}
	while(next_permutation(v.begin(),v.end())){
		for(i=1;i<n;i++){
			sum += sqrt((x[v[i - 1]] - x[v[i]])*(x[v[i - 1]] - x[v[i]]) + (y[v[i - 1]] - y[v[i]])*(y[v[i - 1]] - y[v[i]]));
		}
	}
	sum /= num;
	cout << sum << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <cstring>
#include <cstdlib>
#include <cmath>
using namespace std;
using ll = long long;

struct P {
    bool operator<(const P &p) const {
        return l < p.l;
    }
    int l, r;
};

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

    int n;
    cin >> n;

    vector<P> p(n);
    for (int i = 0; i < n; i++) {
        int l, r;
        cin >> l >> r;
        r++;

        p[i] = { l, r };
    }
    sort(p.begin(), p.end());

    if (n == 2) {
        int s = 0;
        for (int i = 0; i < n; i++) {
            int w = p[i].r - p[i].l;
            s += w;
        }
        cout << s << endl;
        exit(0);
    }

    int il = n - 1, l_max = p[il].l;
    int ir = -1, r_min = 1 << 30;
    for (int i = 0; i < n; i++) {
        if (p[i].r < r_min) {
            r_min = p[i].r;
            ir = i;
        }
    }

    int w_max = 0;
    for (int i = 0; i < n; i++) {
        if (i == il || i == ir) continue;
        int w = p[i].r - p[i].l;
        if (w > w_max) {
            w_max = w;
        }
    }

    int s0;
    {
        int w = max(p[ir].r - p[il].l, 0);
        s0 = w + w_max;//同じグループにした場合のスコア
    }

    if (il == ir) {
        cout << s0 << endl;
        exit(0);
    }

    int s1 = 0, r = p[il].r;
    for (int i = n - 1; i > ir; i--) {//il側に属するのが[i,n-1]とする
        r = min(r, p[i].r);
        int s = max(p[ir].r - p[i - 1].l, 0) + max(r - p[il].l, 0);
        s1 = max(s1, s);
    }

    cout << max(s0, s1) << endl;

    //左右に分けてしまいたくなる 片方を1問だけにするのも有効そう 同じ区間を2回に分けて使うこともある
    //バラバラだったら、一番長い1個を使うことになる
    //Lが最大のやつは、他のどれと組んでもLが悪化しない つまりそれを含むほうの左端はその最大のL
    //あくまでもそいつから見ればだが自分以上のRと組んでも悪化しない 引き受けることができる
    //3個以上残っててLが最大のとRが最小のやつが同じだったら除ける 何を加えても悪化しないので全部引き受ける
    //その2つ、同じグループだと最小の区間が出来上がる 何を加えても悪化しないので一番長い1個をもう片方にする N=2ならばらすだけ
    //違うグループとするとこれはO(N)でわかるんじゃ？ Rが最小のやつはLしか悪化しないから、全部取るところから始めて
    //そもそも片方を0問にするメリットはない

    return 0;
}

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

using namespace std;

const int N = 101;
const int W = 100001;
using ll = long long;
int v[N], w[N];
ll dp[N][W];
int n, c;

ll solve(int item, int cap) {
    if (cap < 0) {
        return -1e15;
    }
    if (item == 0) {
        return 0;
    }
    ll& ans = dp[item][cap];
    if (ans != -1) {
        return ans;
    }
    ans = 0;
    ans = max(solve(item - 1, cap), solve(item - 1, cap - w[item]) + v[item]);
    return ans;
}

int main() {
    cin >> n >> c;
    for (int i = 1; i <= n; i++) {
        cin >> w[i] >> v[i];
    }
    memset(dp, -1, sizeof dp);
    cout << solve(n, c);
    return 0;
}


Measured memory_bytes: 79104
#include <bits/stdc++.h>
using namespace std;
int main(void){
  int a,b,n,k,l,ans=0;
  cin >> a >> b;
  for (n=a;n<=b;n++){
    k=n;
    l=0;
    while (k){
      l=(l+k%10)*10;
      k/=10;
    }
    if (n==l/10) ans++;
  }
  cout << ans << endl;
  return 0;
}

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

#define ll long long
#define vl vector<ll>
#define vvl vector<vector<ll>> //vvl data(10, vector<ll>(10);
#define fo(i,a,b) for(ll i=a; i<b; i++)

int main(){
    ll X, N;
    cin >> X >> N;
    vl nums(N);
    fo(i, 0, N) cin >> nums[i];

    ll min_n = 101;
    ll ans = 101;
    ll i;
    bool pass = false;
    for(i=101; i>-2; i--){
        fo(j, 0, N){
            if(nums[j] == i){
                pass = true;
                continue;
            }
        }
        if(pass){
            pass = false;
            continue;
        }
        //cout << abs(i-X) << " " << min_n<< endl;
        if(abs(i-X) <= min_n){
            min_n = abs(i-X);
            ans = i;
        }
    }

    cout << ans << endl;

}

/*
　 ◇　　　　 ミ ◇
　◇◇　 /￣|　 ◇◇
◇◇＼　 L＿| ◇◇
　　彡Ｏ(・＿・)/
　 　　ヽ Ｐ`Ｏ
　　 ／彡#_|ミ＼
　　　 </LL凵>
　　　　∪ ∪
pass system test !!
*/

Measured memory_bytes: 3628
#include<stdio.h>

int main(void)

{

  int a,b;

  scanf("%d %d",&a,&b);

  if(a < b)

  {

    printf("a < b\n");

  }

  if(a > b)

  {

    printf("a > b\n");

  }

  if(a == b)

  {

    printf("a == b\n");

  }

  return 0;

}

Measured memory_bytes: 580
N = int(input())
A = [int(a) for a in input().split()]
B = [int(b) for b in input().split()]
C = [int(c) for c in input().split()]
ans = 0
for i in range(N):
    if A[i-1]+1 == A[i] and i != 0:
        ans = ans+B[A[i]-1]+C[A[i]-2]
    else:
        ans = ans+B[A[i]-1]
print(ans)


Measured memory_bytes: 3064
#include <cmath>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <string>
#include <vector>
using namespace std;
typedef long long int ll;
typedef vector<int> vi;
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define Sort(a) sort(a.begin(), a.end())
const int INF = 1 << 30;
const ll MOD = 1000000007;
int N;
vector<vector<pair<int, int>>> answers;

int isValid(int bit) {
  int max = 0;
  for (int i = 0; i < N; i++) {
    if ((bit & (1 << i)) == 0) continue;

    max++;
    for (auto answer : answers[i]) {
      if ((bit & (1 << (answer.first - 1))) != 0 && answer.second == 0)
        return false;
      if ((bit & (1 << (answer.first - 1))) == 0 && answer.second == 1)
        return false;
    }
  }
  return max;
}

int main(void) {
  cin >> N;
  answers.resize(N);
  for (int i = 0; i < N; i++) {
    int A;
    cin >> A;
    answers[i].resize(A);
    for (int j = 0; j < A; j++) {
      cin >> answers[i][j].first >> answers[i][j].second;
    }
  }

  int max = 0;
  for (int bit = 0; bit < (1 << N); bit++) {
    int val = isValid(bit);

    if (val > max) max = val;
  }
  cout << max << endl;
  return 0;
}

Measured memory_bytes: 256
fun main(args: Array<String>) {
    val N = readInputLine().toInt()
    
    if (N % 2 != 0) {
        println("No")
        return
    }
    
    val S = readInputLine()

    if (S.substring(0, N / 2).equals(S.substring(N / 2, N))) {
        println("Yes")
    } else {
        println("No")
    }
}

fun readInputLine(): String {
    return readLine()!!
}


Measured memory_bytes: 32036
#include <iostream>
#include <fstream>
#include <cstdio>
#include <cmath>
#include <vector>
#include <string>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <deque>
#include <bitset>
#include <algorithm>
#include <complex>
#include <array>
#include <iomanip>
using namespace std;

#define REP(i,n) for(int i=0; i<n; ++i)
#define FOR(i,a,b) for(int i=a; i<=b; ++i)
#define FORR(i,a,b) for (int i=a; i>=b; --i)
#define ALL(c) (c).begin(), (c).end()

typedef long long ll;
typedef vector<int> VI;
typedef vector<ll> VL;
typedef vector<long double> VD;
typedef vector<VI> VVI;
typedef vector<VL> VVL;
typedef vector<VD> VVD;
typedef pair<int,int> P;
typedef pair<ll,ll> PL;

template<typename T> void chmin(T &a, T b) { if (a > b) a = b; }
template<typename T> void chmax(T &a, T b) { if (a < b) a = b; }

int in() { int x; scanf("%d", &x); return x; }
ll lin() { ll x; scanf("%lld", &x); return x; }
#define INF 1LL<<60

int main() {
    int x, y;
    cin >> x >> y;
    if((4 * x - y) % 2 == 1) {
        cout << "No" << endl;
        return 0;
    }
    if((4 * x - y) < 0) {
        cout << "No" << endl;
        return 0;
    }
    int a = (4*x - y) / 2;

    int b = x - a;
    if(a<0 || b < 0) {
        cout << "No" << endl;
        return 0;
    }

    cout << "Yes" << endl;
    return 0;
}

Measured memory_bytes: 3620
#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>;

int main() {
  ll n,ans = 0;
  cin >> n;
  vector<pair<ll,int>> a;
  for(ll i = 2; i * i <= n; i++){
    int cnt = 0;
    while (n%i == 0){
      n/=i;
      cnt++;
    }
    a.emplace_back(i,cnt);
  }
  if (n != 1) a.emplace_back(n,1);
  for(auto au:a){
    int cnt = 1;
    while (au.second >= cnt){
      au.second -= cnt;
      cnt++;
      ans++;
    }
  }
  cout << ans <<endl;
}


Measured memory_bytes: 19784
#include<stdio.h>

int main(void){
	int A, B, C;
	
	scanf("%d%d%d",&A,&B,&C);
	if(A==5 && B==5 && C==7) printf("YES");
	else if(A==5 && B==7 && C==5) printf("YES");
	else if(A==7 && B==5 && C==5) printf("YES");
	else printf("NO");
	
	return 0;
}

Measured memory_bytes: 128
// ※※※ 解答不能 ※※※
// vjudge4氏.
// https://atcoder.jp/contests/tenka1-2017-beginner/submissions/1980283
#include <bits/stdc++.h>
using namespace std;
using LL = long long;
#define repex(i, a, b, c) for(int i = a; i < b; i += c)
#define repx(i, a, b) repex(i, a, b, 1)
#define rep(i, n) repx(i, 0, n)
#define repr(i, a, b) for(int i = a; i >= b; i--)
const int N = 100000 + 10;
int a[N], b[N];

int main (){
    int n, k;
    scanf("%d %d", &n, &k);
    k++;
    repx(i, 1, n + 1) scanf("%d %d", &a[i], &b[i]);
    LL ans = 0;
    rep(i, 31){
        if(~(k >> i) & 1) continue;
        int lim = (k ^ (1 << i)) | ((1 << i) - 1);
        LL cur = 0;
        repx(j, 1, n + 1) if((a[j] & lim) == a[j]) cur += b[j];
        ans = max(ans, cur);
    }
    printf("%lld\n", ans);
    return 0;
}

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

int main() {


    int a,b,s=0,c=0,i,j,k,em=1,g=1;


    cin>>a>>b;
    if(b==1) {
        cout<<0<<endl;
        return 0;
    }
   /* while(s<b) {
        if(g!=1)s--;
        s+=a;

        c++;


    }
    */
    if(a>=b)
    {
      cout<<1<<endl;
      return 0;
    }
    for(c=1;;c++)
    {
      if(c==1)s=a;
      else
      {
        s=(s-1)+a;

      }
      if(s>=b)break;
    }
    cout<<c<<endl;
    return 0;
}


Measured memory_bytes: 256
using System;

namespace ALDS1_2_C
{
    class Program
    {
        static int CardValue(string s)
        {
            return Int32.Parse(s.Substring(1, 1));
        }

        static void Main(string[] args)
        {
            int n = int.Parse(Console.ReadLine());
            string str = Console.ReadLine();
            string[] str1 = str.Split(' ');

            BubbleSort(str1);
            Console.WriteLine(string.Join(" ", str1));
            Console.WriteLine("Stable");

            string[] str2 = str.Split(' ');
            SelectionSort(str2);
            Console.WriteLine(string.Join(" ", str2));
            Console.WriteLine(string.Join(" ", str1) == string.Join(" ", str2) ? "Stable" : "Not stable");
            
        }

        static void BubbleSort(string[] cards) //バブルソート
        {
            int N = cards.Length;
            for (int i = 0; i < N - 1; i++)
            {
                for (int j = N - 1; j >= i + 1; j--)
                {
                    if (CardValue(cards[j]) < CardValue(cards[j - 1]))
                    {
                        string a = cards[j];
                        cards[j] = cards[j - 1];
                        cards[j - 1] = a;
                    }
                }
            }
        }

        static void SelectionSort(string[] cards)  //選択ソート
        {
            int N = cards.Length;
            for (int i = 0; i <= N - 1; i++)
            {
                int minj = i;
                for (int j = i; j <= N - 1; j++)
                {
                    if (CardValue(cards[j]) < CardValue(cards[minj]))
                        minj = j;
                }
                if (i != minj)
                {
                    string a = cards[i];
                    cards[i] = cards[minj];
                    cards[minj] = a;
                }
            }
        }
    }
}



Measured memory_bytes: 15968
import collections

N = int(input())
v = list(int(i) for i in input().split())


gu = v[0::2]
ki = v[1::2]


gc = collections.Counter(gu)
kc = collections.Counter(ki)

guc = gc.most_common()
kic = kc.most_common()

gv = gc.values()
kv = kc.values()

if guc[0][0] != kic[0][0]:
    gcount = sum(gv) - max(gv)
    kcount = sum(kv) - max(kv)
    print(gcount+kcount)
else:
    if len(guc) == 1 and len(kic) == 1 :
        print(str(guc[0][1]))
    else:
        if len(guc) == 1 and len(kic) != 1 :
            print(str(sum(gv)+sum(kv)-max(gv)-kic[1][1]))
        elif len(guc) != 1 and len(kic) == 1 :
            print(str(sum(gv)+sum(kv)-max(kv)-guc[1][1]))
        else:
            print(str(sum(gv)+sum(kv)-max((guc[1][1] + kic[0][1]), (guc[0][1] + kic[1][1]))))


Measured memory_bytes: 65644
N,K = map(int,input().split())


"""考え方
Kが奇数か否か、1か、で考える。

1.K=1
N**3

2.Kが偶数
「全てN以下のKの倍数」、「全てがx*K/2」のいずれか。

3.Kが奇数
全ての値が、「Kの倍数」でないといけない。
なので、N以下のKの倍数の個数をカウントし、3乗する。
"""

base = int(N//K)**3

if K%2 == 0:
  tmp = N + K // 2
  add_pattern = (tmp // K)**3
  print(base+add_pattern)
else:
  print(base)

Measured memory_bytes: 2940
### ----------------
### ここから
### ----------------

import sys
from io import StringIO
import unittest

def yn(b):
    print("Yes" if b==1 else "No")
    return

def resolve():
    readline=sys.stdin.readline

    n,k=map(int, readline().rstrip().split())

    mod = 10**9+7
    a=0
    z=0
    ans=0
    n+=1
    for i in range(1,n+1):
        a+=i
        z+=(n-i+1)
        cnt=z-a+1
        if i>=k:
            ans=(ans+cnt)%mod
    print(ans)

    return

if 'doTest' not in globals():
    resolve()
    sys.exit()

### ----------------
### ここまで 
### ----------------

Measured memory_bytes: 77512
#ifdef _MSC_VER
#include "stdc++.h"
#endif
#ifdef __GNUC__
#include<bits/stdc++.h>
#endif
using namespace std;

using ll = long long;

//constant
const double EPS = 1e-10;

#define REP(i, n) for (ll i = 0; i < n; i++)
#define FOR(i, s, e) for (ll i = s; i < e; i++)
#define ALL(x) (x).begin(),(x).end()
#define RALL(x) (x).rbegin(), (x).rend()

//debug
#define DUMP(x)  cerr << #x << " = " << (x) << endl;
#define DEBUG(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << endl;

// vector
//template<typename T> vector<vector<T>> vv(ll H, ll W, T v) { return vector<vector<T>> vec(H, vector<T>(W, v)); }

// view vector
template<typename T> void view(T e) { cout << e << endl; }
template<typename T> void view(const vector<T>& v) { for (const auto& e : v) { cout << e << " "; } cout << endl; }
template<typename T> void view(const vector<vector<T> >& vv) { for (const auto& v : vv) { view(v); } }

// DP
template<class T>bool chmax(T& a, const T& b) { if (a < b) { a = b; return 1; } return 0; }
template<class T>bool chmin(T& a, const T& b) { if (b < a) { a = b; return 1; } return 0; }




// ***************************************


int main(){

    int N, A, B;
    cin >> N >> A >> B;

    cout << min(N*A, B) << endl;

    return 0;
}


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

int main(){
  int N;
  cin>>N;
  int x[101],y[101],z[101];
  int xh,yh,zh,H;
  for(int i=0;i<N;i++){
    cin>>x[i]>>y[i]>>z[i];
    if(z[i]) xh=x[i],yh=y[i],zh=z[i];
  }
  bool s=false;
  for(int i=0;i<101;i++){
    for(int j=0;j<101;j++){
      H=abs(j-xh)+abs(i-yh)+zh;
      for(int k=0;k<N;k++){
        if(max(H-abs(j-x[k])-abs(i-y[k]),0)!=z[k])
          break;
        if(k==N-1)
          s=true;
      }
      if(s){
        cout<<j<<" ";
        break;
      }
    }
    if(s){
      cout<<i<<" ";
      break;
    }
  }
  cout<<H<<endl;
}


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

int
main ()
{
  int N, W;
  cin >> N >> W;
  int v[N];
  int w[N];
  for (int i = 0; i < N; i++)
    {
      cin >> v[i] >> w[i];
    }

  int DP[N + 1][W + 1];

  for (int j = 0; j <= W; j++)
    {
      DP[0][j] = 0;
    }

  for (int i = 1; i <= N; i++)
    {
      for (int j = 0; j <= W; j++)
	{
	  if (j < w[i - 1])
	    {
	      DP[i][j] = DP[i - 1][j];
	    }
	  else
	    {
	      if (DP[i - 1][j] > DP[i][j - w[i - 1]] + v[i - 1])
		{
		  DP[i][j] = DP[i - 1][j];
		}
	      else
		{
		  DP[i][j] = DP[i][j - w[i - 1]] + v[i - 1];
		}
	    }
	}
    }

  cout << DP[N][W] << endl;

  return 0;
}

Measured memory_bytes: 7012
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define MS(a) memset(a,0,sizeof(a))
#define MP make_pair
#define PB push_back
const int INF = 0x3f3f3f3f;
const ll INFLL = 0x3f3f3f3f3f3f3f3fLL;
inline ll read(){
    ll x=0,f=1;char ch=getchar();
    while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}
    while(ch>='0'&&ch<='9'){x=x*10+ch-'0';ch=getchar();}
    return x*f;
}
//////////////////////////////////////////////////////////////////////////
const int maxn = 1e5+10;

int n,m,mp[105][105],vis[105],ans;
vector<int> Q;

void dfs(int u){
	int tmp = 0;
	for(int i=0; i<(int)Q.size(); i++){
		int minn = INF;
		for(int j=0; j<(int)Q.size(); j++){
			if(i!=j) minn = min(minn,mp[Q[i]][Q[j]]);
		}
		if(minn == INF)
			minn = 0;
		tmp += minn;
	}
	ans = max(ans,tmp);

	for(int v=u+1; v<=n; v++){
		if(vis[v]) continue;
		int flag = 1;
		for(int j=0; j<(int)Q.size(); j++){//?????????v???????????????????????????????????????v?°±???????????¨??????????????????
			if(mp[v][Q[j]] == 0) {
				flag = 0;
				break;
			}
		}

		if(flag){
			vis[v] = 1;  // ???v
			Q.push_back(v);
			dfs(v);
			vis[v] = 0; // ??????v  ?????? ???v??????????????????????°?
			Q.pop_back();
		}
	}
}

int main(){
	n=read(), m=read();
	for(int i=0; i<m; i++){
		int u,v,w; scanf("%d%d%d",&u,&v,&w);
		mp[u][v]=mp[v][u]=w;
	}

	for(int i=1; i<=n; i++){
		vis[i] = 1;
		Q.push_back(i); // ?????????????????????????????????
		dfs(0);
		Q.pop_back();
		vis[i] = 0;
	}

	cout << ans << endl;

    return 0;
}

Measured memory_bytes: 3276
//#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
//#include <atcoder/all>
//using namespace atcoder;
using namespace std;
#define all(v) v.begin(), v.end()
using in = int64_t;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define REP(i,a,b) for(int i=(int)(a);i<(int)(b);i++)
#define Yes cout<<"Yes"<<endl
#define No cout<<"No"<<endl
#define yes cout<<"yes"<<endl
#define no cout<<"no"<<endl
#define YES cout<<"YES"<<endl
#define NO cout<<"NO"<<endl
const double PI=3.14159265358979323846;
const in MOD = 1000000007;
const in INF=1e18+7;
const int inf=1e9+7;
using P=pair<int,int>;
vector<int> dx={0,1,-1,0};
vector<int> dy={1,0,0,-1};


int main(){
ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
cout << fixed << setprecision(10);
    int n;
    cin>>n;
    vector<P> a(n);
    vector<int> pp(n),pm(n),mp(n),mm(n);
    int x,y;
    rep(i,n){
        cin>>x>>y;
        a[i]=P(x,y);
        pp[i]=x+y;
        pm[i]=x-y;
        mp[i]=-x+y;
        mm[i]=-x-y;
    }
    sort(all(pp));
    sort(all(pm));
    sort(all(mp));
    sort(all(mm));

    int ans1=pp[n-1]+mm[n-1];
    int ans2=pm[n-1]+mp[n-1];
    int ans=max(ans1,ans2);
    cout<<ans<<endl;
}/*
./problem.exe
*/

Measured memory_bytes: 7908
#include <bits/stdc++.h>
using namespace std;
 
int a,b,c;
int f[100];
 
int main() 
{
    cin>>a>>b>>c;
    int j=a%b;
    while (1)
    {
        if (j==c)
        {
            cout<<"YES"<<endl;
            return 0;
        }
        if (f[j])
        {
            cout<<"NO"<<endl;
            return 0;
        }else f[j]=1;
        j=(j+a)%b;
    }
}

Measured memory_bytes: 256
N = int(input())
l = len(str(N))

def make753(num, l, list753):
    if l == 0:
        if '3' in num and '5' in num and '7' in num and int(num) <= N:
            list753.append(int(num))
    else:
        make753(num + '3', l-1, list753)
        make753(num + '5', l-1, list753)
        make753(num + '7', l-1, list753)
    return list753

L = []
for l in range(3, l+1):
    L += make753('', l, [])
print(len(L))

Measured memory_bytes: 4328
// abc115_a
#include <iostream>
using namespace std;

int main(int argc, char *argv[])
{
  int d;
  cin >> d;
  cout << "Christmas";
  for (int i = 25 - d; i > 0; i--) {
    cout << " Eve";
  }
  cout << endl;
  return 0;
}


Measured memory_bytes: 256
A = list()
b = list()

n, m = map(int, input().split(" "))

for i in range(n):
    A.append(list())
    A[i] = [int(x) for x in input().split(" ")]

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

for i in range(n):
    c = 0
    for j in range(m):
        c += A[i][j] * b[j]
    print(c)

Measured memory_bytes: 8160
#include <iostream>
#include <string>
#include <vector>
#include <cmath>
#include <algorithm>
#include <cstdlib>
#include <ctime>
#include <cstdio>
#include <functional>
#include <set>
#include <sstream>
#include <map>
#include <queue>

using namespace std;
 
const double eps=1e-10;

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

int main()
{

	string s;
	while(getline(cin,s),s!="."){
		for(int i=s.size()-1;i>=0;i--){
			if(s[i]!='(' && s[i]!=')' && s[i]!='[' && s[i]!=']') s.erase(s.begin()+i);
		}

		int pos1,pos2;
		while( (pos1=s.find("()"))!=string::npos ||  (pos2=s.find("[]"))!=string::npos){

			if(pos1!=string::npos){
				s.replace(pos1,2,"");
				continue;
			}

			if(pos2!=string::npos){
				s.replace(pos2,2,"");
				continue;
			}


		}

		if(s=="") cout<<"yes"<<endl;
		else cout<<"no"<<endl;
	}

	return 0;
}

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

int main(){
 long long X; cin >> X;
  for(long long a=-1000; a<=1000; a++){
    for(long long b=-1000; b<=1000; b++){
      if(a*a*a*a*a-b*b*b*b*b==X){
        cout << a << " " << b << endl;
        return 0;
      }
    }
  }
}

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

int main() {
    int n; cin >> n;
    vector<int> a(4);
    for(int i=0; i<n; i++) {
        string s; cin >> s;
        if(s == "AC") a[0]++;
        if(s == "WA") a[1]++;
        if(s == "TLE") a[2]++;
        if(s == "RE") a[3]++;
    }
    cout << "AC x " << a[0] << endl;
    cout << "WA x " << a[1] << endl;
    cout << "TLE x " << a[2] << endl;
    cout << "RE x " << a[3] << endl;
}

Measured memory_bytes: 3620
#include<iostream>

using namespace std;

int GCD(int a, int b){
  int r;

  r = a%b;

  while(1){
    if(r == 0)break;
   a = b;
   b = r;
   r = a%b;
  }
  return b;
}


int main(){
 int a,b;
 int ans,temp;

 cin >> a >> b;

 if(a<b){
   temp = b;
   b = a;
   a = temp;
 }

 ans=GCD(a,b);

 cout << ans << endl;

}

Measured memory_bytes: 3100
# coding: utf-8
# Your code here!

num,k = map(int,input().split(" "))
r,s,p = map(int,input().split(" "))
machine = list(input())

score = 0
score_list = []
for i in range(num):
    if i <= k - 1:
        if machine[i] == "r":
            score += p
            score_list.append(p)
        elif machine[i] == "s":
            score += r
            score_list.append(r)
        else:
            score += s
            score_list.append(s)
    elif machine[i] != machine[i - k]:
        if machine[i] == "r":
            score += p
            score_list.append(p)
        elif machine[i] == "s":
            score += r
            score_list.append(r)
        else:
            score += s
            score_list.append(s)
    elif score_list[i - k] == 0:
        if machine[i] == "r":
            score += p
            score_list.append(p)
        elif machine[i] == "s":
            score += r
            score_list.append(r)
        else:
            score += s
            score_list.append(s)
    else:
        score_list.append(0)
    
    

print(score)
        
        
            

Measured memory_bytes: 4792
#include <iostream>
#include <stdio.h>
#include <string>
#include <cstdlib>
#include <cmath>
#include <cstring>
#include <math.h>
#include <vector>
#include <algorithm>
#include <queue>
#include <stack>
#include <climits>
#include <bitset>
#include <list>
#include <map>

using namespace std;

typedef unsigned long long ull;
typedef long long ll;

int main(){
    int k, t;
    cin >> k >> t;
    int a[t], sum=0;
    for(int i=0; i<t; i++){
        cin >> a[i];
        sum+=a[i];
    }
    sort(a, a+t);
    cout << max(2*a[t-1]-sum-1, 0) << endl;
    return 0;
}

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

const int N = 55;

int n, par[N], e[N][N], te[N][N], deg[N], tdeg[N];
vector <int> gb[N];

void dfs(int u) {
	for (int v : gb[u]) if (v != par[u]) {
		par[v] = u;
		dfs(v);
	}
}

void change(vector <int> &available, int u) {
	available.erase(find(available.begin(), available.end(), u));
	for (auto v : gb[u]) if (v != par[u]) {
		available.push_back(v);
	}
}

int calc(int root) {
	par[root] = 0;
	dfs(root);

	for (int i = 1; i <= n; ++i) {
		tdeg[i] = deg[i];
		for (int j = 1; j <= n; ++j) {
			te[i][j] = e[i][j];
		}
	}

	vector <int> available(1, root);
	change(available, root);

	int ret = 0;
	while(!available.empty()) {
		bool found = false;
		for (auto u : available) {
			if (te[u][par[u]]) {
				found = true;
				change(available, u);
				break;
			}
			if (tdeg[u] == 1) { // leaf
				found = true;
				// cut
				for (int i = 1; i <= n; ++i) if (te[i][u]) {
					te[i][u] = te[u][i] = false;
					--tdeg[i]; --tdeg[u];
				}
				// concatenate
				te[u][par[u]] = te[par[u]][u] = true;
				++tdeg[u]; ++tdeg[par[u]];
				++ret;

				change(available, u);
				break;
			}
		}
		if (!found) return 1e9;
	}

	return ret;
}

void solve() {
	cin >> n;
	for (int i = 1; i <= n; ++i) {
		deg[i] = 0;
		gb[i].clear();
		for (int j = 1; j <= n; ++j) {
			e[i][j] = 0;
		}
	}

	for (int i = 1; i < n; ++i) {
		int u, v; cin >> u >> v;
		e[u][v] = e[v][u] = true;
		++deg[u];
		++deg[v];
	}

	for (int i = 1; i < n; ++i) {
		int u, v; cin >> u >> v;
		gb[u].push_back(v);
		gb[v].push_back(u);
	}

	int res = 1e9;
	for (int i = 1; i <= n; ++i) {
		int cur = calc(i);
		res = min(res, cur);
	}

	for (int i = 1; i <= n; ++i) if (deg[i] == 1) {
		int adj_i = 0;
		for (int j = 1; j <= n; ++j) if (e[i][j]) {
			adj_i = j;
			e[i][j] = e[j][i] = false;
			--deg[i]; --deg[j];
		}
		for (int j = 1; j <= n; ++j) if (i != j) {
			e[i][j] = e[j][i] = true;
			++deg[i]; ++deg[j];
			res = min(res, calc(i) + 1);
			e[i][j] = e[j][i] = false;
			--deg[i]; --deg[j];
		}
		e[i][adj_i] = e[adj_i][i] = true;
		++deg[i]; ++deg[adj_i];
	}

	cout << (res == 1e9 ? -1 : res) << endl;
}

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

	int tt; cin >> tt;
	while(tt--) {
		solve();
	}
}

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



int main() {
	int A, B;
	cin >> A >> B;
	if (A >= 1 && A <= 9 && B >= 1 && B <= 9) {
		cout << A * B << endl;
	}
	else {
		cout << -1 << endl;
	}
}

Measured memory_bytes: 256
#include<iostream>
#include<stdio.h>
#include<string>
#include<vector>
#include<map>
#include<tuple>
#include<algorithm>
#include<cmath>
#include<limits>
#include<set>
#include<deque>
#include<queue>
using namespace std;
#define int long  long int
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
int gcd(int a, int b) { return b ? gcd(b, a % b) : a; }
int lcm(int a, int b) { return a / gcd(a, b) * b; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
typedef pair<int, int>P;
const int MOD = 1e9 + 7;
//const int MOD = 998244353;
const int INF = 1e18;
const long double PI = (acos(-1));


signed main() {
	int A, B, C, K;
	cin >> A >> B >> C >> K;
	int ans = 0;
	if (A >= K) {
		ans = K;
		cout << ans;
		return 0;
	}
	ans += A;
	K -= A;
	if (B >= K) {
		cout << ans;
		return 0;
	}
	K -= B;
	ans -= K;
	cout << ans;
}

Measured memory_bytes: 3680
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <cmath>
#include <map>
#include <numeric>
#include <set>
#include <iomanip>
#include <functional>
#define FOR(i, a, n) for (int i = (a); i < (n); i++)
#define REP(i, n) for(int i = 0; i < (n); i++)
using namespace std;


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

	int N, M;
	int st = 0, ed = 100000;
	int L, R;

	cin >> N >> M;

	REP(i, M)
	{
		cin >> L >> R;
		if (L >= st)st = L;
		if (R <= ed)ed = R;
	}

	if (st <= ed)
	{
		cout << ed - st + 1 << endl;
	}
	else
	{
		cout << 0 << endl;
	}

	return 0;
}

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

#define ll long long

using namespace std;
const int maxn=2e5+3;
int n;
ll f[maxn];
int fa[maxn];
int dee[maxn],da[maxn];
char s[maxn];
int calc(int x)
{
    int res=0;
    while(x)
    {
        int kk=__builtin_popcount(x);
        x=x%kk;
        res++;
    }
    return res;
}
void func(int x,int col)
{
    if(col<=0)
        return;
    f[0]=1;
    for(int i=1; i<maxn; i++)
        f[i]=f[i-1]*2%col;
    for(int i=1; i<=n; i++)
    {
        if(s[i]=='1')
            fa[i]=(fa[i-1]+f[i-1])%col;
        else
            fa[i]=fa[i-1];
    }
    for(int i=n; i>=1; i--)
    {
        if(s[i]=='1')
            dee[i]=(dee[i+1]+f[i-1])%col;
        else
            dee[i]=dee[i+1];
    }
    for(int i=1; i<=n; i++)
    {
         if(x==1 && s[i]=='1')
        {
            int ans=(fa[i-1]+dee[i+1])%col;
            da[i]=1+calc(ans);
        }
         if(s[i]=='0' && x==0)
        {
            int ans=(fa[i-1]+dee[i+1]+f[i-1])%col;
            da[i]=1+calc(ans);
        }
    }

}
int main()
{
    scanf("%d%s",&n,s+1);
    int len=strlen(s+1);
    reverse(s+1,s+1+n);
    int col=0;
    for(int i=1; i<=n; i++)
    {
        if(s[i]=='1')col++;
    }
    func(0,col+1);
    func(1,col-1);
    reverse(da+1,da+1+n);
    for(int i=1; i<=n; i++)
        printf("%d\n",da[i]);
}


Measured memory_bytes: 7856
#include<stdio.h>
#include<string.h>

int main(void){
	char S[100],A[100]="AAA",B[100]="BBB";
	scanf("%s",S);
	if(strcmp(S,A)==0 || strcmp(S,B)==0){
		printf("No\n");
	}else{
		printf("Yes\n");
	}
	return 0;
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(),(x).end()
#define m1(x) memset(x,-1,sizeof(x))
const int INF = 1e9 + 1;
const ll MOD = 1e9 + 7;
const double PI = 3.141592653589793;

string s;

int main(){
  cin >> s;
  bool flag;
  ll ans;
  ll dp[100000][2];
  dp[0][0] = 1; dp[0][1] = 2;
  for(int i = 1; i < s.size(); i++){
    int k = s.at(i) - '0';
    if(k){
      dp[i][0] = (dp[i-1][0] * 3 + dp[i-1][1] * 1 )% MOD;
      dp[i][1] = 2*dp[i-1][1] % MOD;
    }else{
      dp[i][0] = dp[i-1][0] * 3 % MOD;
      dp[i][1] = dp[i-1][1];
    }
  }
  cout << (dp[s.size()-1][0] + dp[s.size() - 1][1]) % MOD<<endl;
}
    

Measured memory_bytes: 2048
#include"bits/stdc++.h"

using namespace std; 

typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef vector<PII> VPII;
typedef long long LL;
typedef priority_queue<int> PQ_DESC;
typedef priority_queue<int, vector<int>, greater<int>> PQ_ASC;
typedef priority_queue<PII> PQ_DESC_PII;
typedef priority_queue<PII, vector<PII>, greater<PII>> PQ_ASC_PII;

#define ALL(c) (c).begin(),(c).end()
#define PB push_back
#define MP make_pair
#define SORT_ASC(c) sort(ALL(c))
#define SORT_DESC(c) sort(ALL(c), greater<typeof(*((c).begin()))>())
#define SIZE(a) int((a).size())

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

const double EPS = 1e-10;
const double PI  = acos(-1.0);
const int LARGE_INT = 1e9+100;
const int INF = 2e9+100;
const LL INF_LL = (LL)INF * 300 * 300;
const int MOD = 1e9+7;

//debug
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;

LL modpow(LL a, LL n) {
    LL res = 1;
    while (n > 0) {
        if (n & 1) res = res * a % MOD;
        a = a * a % MOD;
        n >>= 1;
    }
    return res;
}


void Main()
{

    int n,t;cin>>n>>t;
    VI a(n);
    REP(i, n) cin >> a[i];

    VI small(n);
    small[0] = a[0];

    int count = 0;
    int dist_max = 0;

    FOR(i,1,n){
        small[i] = min(small[i-1],a[i]);

        int dist = a[i]-small[i-1];
        if(dist > dist_max){
            dist_max = dist;
            count=1;
        }
        else if(dist == dist_max){
            count++;
        }
    }
    cout<<count<<endl;
    /*
    REP(i,n){
        cerr<<small[i]<<endl;
    }
    */

    /*
    VPII small(n);
    VPII large(n);

    small[0] = MP(a[0],1);
    large[n-1] = MP(a[n-1],1);

    FOR(i,1,n){
        small[i] = small[i-1];
        if(a[i] < small[i-1].first){
            small[i].first = a[i];
            small[i].second = 1;
        }
        else if(a[i] == small[i-1].first){
            small[i].second ++;
        }
    }
    ROF(i,0,n-1){
        large[i] = large[i+1];
        if(a[i] > large[i+1].first){
            large[i].first = a[i];
            large[i].second = 1;
        }
        else if(a[i] == large[i+1].first){
            large[i].second ++;
        }
    }

    REP(i,n){
        cerr<<small[i].first<<" "<<small[i].second<<endl;
    }
    cerr<<endl;
    REP(i,n){
        cerr<<large[i].first<<" "<<large[i].second<<endl;
    }
    */



    
	return;
}

int main()
{
	cin.tie(nullptr);
	ios_base::sync_with_stdio(false);
	cout << fixed << setprecision(15);
	Main();
    return 0;
}

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

int main() {
    int64_t H;
    cin >> H;

    int64_t ans = 0;
    int64_t add_num = 1;
    while (H > 0) {
        ans += add_num;
        H /= 2;
        add_num *= 2;
    }

    cout << ans << endl;
}

Measured memory_bytes: 256
object Main extends App {
  val sc = new java.util.Scanner(System.in)
  val x :: xs = List.fill(sc.nextInt())(sc.nextInt())
  val ((sum, count), _) = xs.foldLeft(0 -> 1 -> x) {
    case (((sum, count), l), r) =>
      (if (l == r) sum -> (count + 1) else (sum + count / 2) -> 1) -> r
  }
  println(sum + count / 2)
}


Measured memory_bytes: 55468
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<n;i++)
#define repA(a,i,n) for(int i=a;i<n;i++)
#define trav(a,x)for(auto &a: x)
#define fll(a) memset(a,-1,sizeof(a));
#define mp make_pair
#define pb push_back
#define all(x) x.begin(),x.end()
#define fst first
#define sec second
#define itr(it,x) for(auto it=x.begin();it!=x.end();it++)
typedef long long ll;
typedef long double ld;
typedef pair<int,int>pii;
typedef vector<int>vi;
typedef map<int,int>ma;
#define fastio ios_base::sync_with_stdio(false); cin.tie(NULL);
void fopen()
{
    freopen("input.txt","r",stdin);
    freopen("output.txt","w",stdout);   
}
int main()
{
    fastio;
   // fopen();
    ll n,m,v,p;
    cin>>n>>m>>v>>p;
    ll a[n];
    rep(i,n) cin>>a[i];
    sort(a,a+n,greater<int>());
    int i=p,j=n-1;
    while(j-i>=0)
    {
        int mid=i+(j-i)/2;
        ll w=a[mid]+m,s=(p-1)*m;
        repA(p-1,i,n)
        {
            s+=min(m,w-a[i]);
        }
        if(s>=m*v && w>=a[p-1]) i=mid+1;
        else j=mid-1;
    }
    cout<<i<<endl;


}

Measured memory_bytes: 1024
from collections import Counter,defaultdict,deque
from heapq import heappop,heappush,heapify
import sys,bisect,math,itertools,fractions,pprint
sys.setrecursionlimit(10**8)
mod = 10**9+7
INF = float('inf')
def inp(): return int(sys.stdin.readline())
def inpl(): return list(map(int, sys.stdin.readline().split()))

n = inp()
A = sorted(inpl())
B = sorted(inpl())
C = sorted(inpl())
cnt = [0] * n
res = 0
for i,b in enumerate(B):
    c = bisect.bisect_left(C,b+1)
    cnt[i] = n-c

acc = [0]
for x in cnt:
    acc += [acc[-1] + x]
su = sum(cnt) 
for i,a in enumerate(A):
    c = bisect.bisect_left(B,a+1)
    res += su - acc[c]
print(res)

Measured memory_bytes: 124300
{-# OPTIONS_GHC -O2 #-}
{-# LANGUAGE OverloadedStrings #-}
{-# LANGUAGE BangPatterns #-}
module Main where

import Data.Char (isSpace)
import qualified Data.Vector.Unboxed as U
import qualified Data.ByteString.Char8 as C

type Parser a = C.ByteString -> Maybe (a, C.ByteString)

parseInt :: Parser Int
parseInt = C.readInt . C.dropWhile isSpace

getIntVec :: Int -> IO (U.Vector Int)
getIntVec n = U.unfoldrN n parseInt <$> C.getLine

foldn (c, f) 0 = c
foldn (c, f) n = f (foldn (c, f) (n-1))

paran (c, f) 0 = c
paran (c, f) n = f n (paran (c, f) (n-1))

---------------------------------------------------------

frog1 vec = paran (step vec 0 undefined, step vec)

step vec 0 _ = (0, (vec U.! 0, undefined, undefined, undefined, undefined))
step vec 1 (c, (h, h1, c1, h2, c2)) = (c', (h', h, c, h1, c1))
  where
    h' = vec U.! 1
    c' = abs (h'-h)
step vec i (c, (h, h1, c1, h2, c2)) = (c', (h', h1', c1', h2', c2'))
  where
    h' = vec U.! i
    h1' = h
    c1' = c
    h2' = h1
    c2' = c1
    d1 = abs (h'-h1')
    d2 = abs (h'-h2')
    c' = min (c1'+d1) (c2'+d2)

main :: IO ()
main = do
  !n <- readLn :: IO Int
  !hs <- getIntVec n
  print $ fst $ frog1 hs (n-1)


Measured memory_bytes: 32124
#include<bits/stdc++.h>
#define ll long long 
using namespace std;
	
const ll siz = 1e5;	
const ll mod = 1e9 + 7;
const ll MAXX = 1e18;	

int main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	//freopen("INP.txt", "r", stdin);
	//freopen("OUT.txt", "w", stdout);
	ll n;
	cin >> n;
	string s;
	cin >> s;
	for (ll i = 0; i < s.size(); i++) {
		ll sub = s[i] - 'A';
		sub += n;
		ll need = 'Z' - 'A' + 1;
		sub %= need;
		s[i] = sub + 'A';
	}
	cout << s << '\n';
	return 0;
}


Measured memory_bytes: 256
n = int(input())
a = [int(x) for x in input().strip().split()]

c = [[None for i in range(n)] for j in range(n)]
s = [[0 for i in range(n)] for j in range(n)]

for i in range(n):
    c[i][i] = 0
    s[i][i] = a[i]

for i in range(n):
    for j in range(i+1,n):
        s[i][j] = s[i][j-1]+a[j]

def solve(i,j):
    if c[i][j] is not None:
        return c[i][j]
    mn = 10**100
    for k in range(i,j):
        mn = min(mn,solve(i,k)+solve(k+1,j)+s[i][k]+s[k+1][j])
    c[i][j] = mn
    return c[i][j]

# print(s)
print(solve(0,n-1))
# print(c)
    


Measured memory_bytes: 47068
/* 
* ID: juryc
* PROG: Count Order
* LANG: C++
*/
#include<bits/stdc++.h>
using namespace std;
int main(){
int n; cin>>n;
vector<int> p(n),q(n);
for(int& i :p) cin>>i;
for(int& i: q) cin>>i;
vector<int> r(p); 
sort(r.begin(),r.end());
auto eq=[&](vector<int> a,vector<int> b,int n){ int flag=1; for(int i=0;i<n;i++) flag&=(a[i]==b[i]); return flag; };
int cnta=0;
while(true){
if(eq(p,r,n)) break; 
next_permutation(r.begin(),r.end()); 
cnta++;
}
sort(r.begin(),r.end()); 
int cntb=0;
while(true){
if(eq(q,r,n)) break;
next_permutation(r.begin(),r.end()); 
cntb++;
}
cout<<abs(cntb-cnta)<<"\n";
return 0;
}

Measured memory_bytes: 3636
#include<bits/stdc++.h>
#define ll long long int
using namespace std;
const int mod=1e9+7;
                     // I'm in Love with Experience. �😎�
void solve()
{
    ll mn=0;
    string s,t;cin>>s>>t;
    ll ls = s.size();
    ll lt = t.size();
    for(ll i=0;i<min(lt,ls);++i)
    {
        if(s[i]!=t[i])mn++;
    }
    for(ll i=0;i<=abs(ls-lt);++i)
    {
        ll c=0;
        ll a=i;
        for(ll j=0;j<lt;++j)
        {
            if(s[i+j]!=t[j])c++;
        }
        mn=min(mn,c);
    }
    cout<<mn<<'\n';
}
int main(void)
{
    ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);solve();exit(0);
}/*Solved By:- Ritik Agarwal*/

Measured memory_bytes: 3660
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(n);++i)
#define all(a) (a).begin(),(a).end()
#define dunk(a) cout << (a) << endl
using namespace std;
typedef long long ll;

int main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	ll a, b, k;
	cin >> a >> b >> k;

	if (a >= k) {
		cout << a - k << ' ' << b << endl;
		return 0;
	}
	else {
		if (a + b >= k) {
			cout << 0 << ' ' << b - k + a << endl;
		}
		else {
			cout << 0 << ' ' << 0 << endl;
		}
	}

	return 0;
}

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

int main() {
  double n, sum = 0;
  cin >> n;
  vector<double> a(n);
  for (int i = 0; i < n; i ++) {
    cin >> a.at(i);
    sum += a.at(i);
  }

  double ave = sum / n;
  double ans = 0, tmp = 100;
  for (int i = 0; i < n; i ++) {
    if (abs(ave - a.at(i)) < tmp) {
      ans = i;
      tmp = abs(ave - a.at(i));
    }
  }
  cout << ans << endl;
}


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

int main() {
    string S; cin >> S;
    REP(i, 0, S.size()) {
        if (i + 1 < (int)S.size() && S[i] == S[i + 1]) {
            cout << i + 1 << " " << i + 2 << endl;
            return 0;
        }
        if (i + 2 < (int)S.size() && S[i] == S[i + 2]) {
            cout << i + 1 << " " << i + 3 << endl;
            return 0;
        }
    }
    cout << -1 << " " << -1 << endl;
    
    return 0;
}

Measured memory_bytes: 3736
#include<iostream>
#include<algorithm>
using namespace std;
int main(){
  int n,temp,sum=0;
  cin >> n;
  int a[n*2-1];
  for(int i=0;i<2*n;i++)cin >> a[i];
  sort(a,a+n*2);
  //for(int i=0;i<n*2-1;i++)cout << a[i]<<endl;
  for(int i=0;i<2*n;i+=2){
    sum+=a[i];
  }
  cout<< sum << endl;
}


Measured memory_bytes: 256
S = list(map(str,input()))
first = int(S[0]+S[1])
second = int(S[2]+S[3])
fj = False
sj = False
if first >= 1 and first <= 12:
  fj = True
if second >= 1 and second <= 12:
  sj = True
if fj and sj:
  print('AMBIGUOUS')
if fj and not sj:
  print('MMYY')
if not fj and sj:
  print('YYMM')
if not fj and not sj:
  print('NA')

Measured memory_bytes: 3064
/*Whose woods these are I think I know.
His house is in the village though;
He will not see me stopping here
To watch his woods fill up with snow.

My little horse must think it queer
To stop without a farmhouse near
Between the woods and frozen lake
The darkest evening of the year.

He gives his harness bells a shake
To ask if there is some mistake.
The only other sound’s the sweep
Of easy wind and downy flake.

The woods are lovely, dark and deep,
But I have promises to keep,
And miles to go before I sleep,
And miles to go before I sleep.*/

#include<bits/stdc++.h>
using namespace std;
#define lli long long int
#define pb push_back
#define fi first
#define se second
#define MOD 1000000007
const int maxn= 100010;
lli pre_r[4040];
lli pre_b[4040];
lli pre_g[4040];
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int n=0;lli r=0ll,b=0ll,g=0ll,res=0ll;string s;
    cin>>n;
    cin>>s;
    for(int i=0;i<n;++i)
    {
        pre_r[i+1]=pre_r[i];
        pre_b[i+1]=pre_b[i];
        pre_g[i+1]=pre_g[i];
        if(s[i]=='R')
            ++pre_r[i+1];
        else if(s[i]=='B')
            ++pre_b[i+1];
        else
            ++pre_g[i+1];
    }
    char ch;
    for(int i=0;i<n;++i)
        for(int j=i+1;j<n;++j)
        {
            if(s[i]==s[j])
                continue;
            if((s[i]=='R'&&s[j]=='B')||(s[i]=='B'&&s[j]=='R'))
            {
                ch='G';
                res+=pre_g[j]-pre_g[i+1];
            }
            else if((s[i]=='R'&&s[j]=='G')||(s[i]=='G'&&s[j]=='R'))
            {
                ch='B';
                res+=pre_b[j]-pre_b[i+1];
            }
            else
            {
                ch='R';
                res+=pre_r[j]-pre_r[i+1];
            }
            int mid=(i+j)/2;
            if(2*mid==(i+j)&&s[mid]==ch)
                --res;
        }
    cout<<res<<endl;
}


Measured memory_bytes: 3744