akhauriyash/Code-Regression huggingface dataset:
#include <cstdio>
#include <vector>
using namespace std;
int main() {
	vector<int> Card,A,B;
	int n,m,k;
	scanf("%d",&n);
	for(int i=1;i<=2*n;i++) Card.push_back(i);
	scanf("%d",&m);
	for(int i=0;i<m;i++) {
		scanf("%d",&k);
		A.clear(); B.clear();
		if(k==0) {
			for(int i=0;i<n;i++) A.push_back(Card[i]);
			for(int i=n;i<2*n;i++) B.push_back(Card[i]);
			Card.clear();
			for(int i=0;i<n;i++) Card.push_back(A[i]),Card.push_back(B[i]);
		}else {
			for(int i=0;i<k;i++) A.push_back(Card[i]);
			for(int i=k;i<2*n;i++) B.push_back(Card[i]);
			Card.clear();
			for(int i=0;i<2*n-k;i++) Card.push_back(B[i]);
			for(int i=0;i<k;i++) Card.push_back(A[i]);
		}
	}
	for(int i=0;i<2*n;i++) printf("%d\n",Card[i]);
}

Measured memory_bytes: 1056
#include <iostream>
#include <cstring>
#include <vector>
#include <set>
#include <map>
#include <algorithm>
#include <queue>
#include <cstdio>
#include <cmath>
#include <stack>
typedef long long ll;
#define INF 0x3f3f3f3f

using namespace std;
int board[1024][1024];
bool visited[1024][1024];
int W, H;
int ans = INF;
string result;
int step;
char temp[30];

int main(int argc, char *argv[]) {
	cin >> H >> W;
	for(int i = 1; i <= H; i++)
	{
		for(int j = 1; j <= W; j++)
		{
			cin >> board[i][j];
		}	
	}
	
	int i = 1, j = 1;
	int dx = 1;
	int g = 0;
	step = 0;
	result = "";
	
	while(i <= H)
	{
		if(g)
		{
			sprintf(temp, "%d %d\n", i, j);
			result += temp;
			g = 0;
			step++;
			board[i][j] += 1;
		}
		if(board[i][j] % 2 && !(i == H && j == W && i % 2) && !(i % 2 == 0 && i == H && j == 1))
		{
			g = 1;
			sprintf(temp, "%d %d ", i, j);
			result += temp;
		}

		if(i % 2 && j == W)
		{
			i++;
			dx = -1;
			j = W + 1;
		}

		if(i % 2 == 0 && j == 1)
		{
			i++;
			dx = 1;
			j = 0;
		}
		j += dx;

	}
	cout << step << endl;
	cout << result;
}

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

using namespace std;

typedef long long ll;
typedef pair<ll, ll> pll;

#define endl "\n"

const ll INF = 1e15;
const int MOD = 1e9 + 7;
const double EPS = 1e-9;
const double PI = acos(-1.0);

mt19937 rng((int) chrono::steady_clock::now().time_since_epoch().count());

int n;


int lcm(int x, int y) {
    return x / __gcd(x, y) * y;
}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(NULL), cout.tie(NULL);

    cin >> n;

    cout << lcm(n , 360) / n << endl;
}


Measured memory_bytes: 3608
#include <bits/stdc++.h>
#define REP(i, n) for(ll i = 0; i < (ll)(n); i++)
#define FOR(i, a, b) for(ll i = a; i < (ll)(b); i++)

#define ALL(x) (x).begin(), (x).end()
#define MAX(x) *max_element(ALL(x))
#define MIN(x) *min_element(ALL(x))

using namespace std;
using ll = unsigned long long;
using vel = vector<ll>;
using ves = vector<string>;
using veb = vector<bool>;

using qul = queue<ll>;

int main() {
    ll N,Q,sum = 0;
    cin >> N;
    vel A(N), count(1000000);
    REP(i, 1000000) count[i] = 0;
    REP(i, N){
        cin >> A[i];
        count[A[i]-1] = count[A[i]-1] + 1;
    }
    cin >> Q;
    vel B(Q), C(Q);
    REP(i, Q) {
        cin >> B[i] >> C[i];
    }
    REP(i, N) sum = sum + A[i];
    REP(i, Q){
        sum = sum + count[B[i]-1] * (C[i] - B[i]);
        count[C[i] - 1] = count[C[i] - 1] + count[B[i] - 1];
        count[B[i] - 1] = 0;
        cout << sum << endl;
    }
}


Measured memory_bytes: 13468
#include<iostream>
#include<math.h>
#include<vector>
using namespace std;



int main(){
    int n, d;
    cin >> n >> d;
    vector<int> v[10];
    int temp;
    for (int i = 0; i < n; i++)
    {
        for (int j = 0; j < d; j++)
        {
            cin >> temp;
            v[i].push_back(temp);
        }
    }
    int ans = 0;
    int dist;
    for (int i = 0; i < n; i++)
    {
        
        for (int j = i + 1; j < n; j++)
        {
            dist = 0;
            for (int k = 0; k < d; k++)
            {
                dist += (v[i][k] - v[j][k])*(v[i][k] - v[j][k]);
            }
            for (int l = 0; l*l <= dist; l++)
            {
                if(l*l==dist)
                {
                    ans++;
                }
            }
            
        }
        
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<algorithm>
#include<queue>
#include<cmath>
#include<string>
#include<set>
//int mod(int a,int b,int d);

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

int main() {
  int n;
  cin >> n;
  vector<int> l(n);
  rep(i,n) cin >> l[i];
  int c=0;

  rep(i,n-2){
    for(int j=i+1;j<n-1;++j){
      for(int k=j+1;k<n;++k){
        if(l[i]+l[j]>l[k] && l[j]+l[k]>l[i] && l[k]+l[i]>l[j] 
           && l[i]!=l[j] && l[j]!=l[k] && l[k]!=l[i] ) c++;
      }
    }
  }
  cout<<c<<endl;




}

Measured memory_bytes: 3628
// DP contest -- kahin se toh start karna padega be
// frog 1
#include <iostream>
#include <unordered_map>
#include <vector>
#define ll long long
using namespace std;

ll cost(vector<ll> &dp, vector<ll> &arr, ll x)
{
    ll n = arr.size();
    if (dp[x] != -1)
        return dp[x];
    if (x == n)
        return 0;
    if (x == n - 1)
        return abs(arr[x] - arr[x - 1]);
    dp[x + 1] = cost(dp, arr, x + 1);
    dp[x + 2] = cost(dp, arr, x + 2);
    dp[x] = min(abs(arr[x] - arr[x - 1]) + dp[x + 1], abs(arr[x + 1] - arr[x - 1]) + dp[x + 2]);
    return dp[x];
}

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    ll n;
    cin >> n;
    vector<ll> lookup(n, -1);
    vector<ll> height(n, -1);
    for (ll i = 0; i < n; i++)
    {
        cin >> height[i];
    }
    cout << cost(lookup, height, 1);
}

Measured memory_bytes: 6528
import sys


# \n
def input():
    return sys.stdin.readline().rstrip()

def main():

    N=int(input())
    S=list(input())
    K=int(input())

    d = S[K-1]

    for i in range(N):
        if S[i] !=d:
            S[i] ="*"

    print(*S,sep="")



if __name__ == "__main__":
    main()


Measured memory_bytes: 61812
from collections import Counter
n = int(input())
v = list(map(int, input().split()))

e = Counter(v[::2]).most_common() + [(0, 0)]
o = Counter(v[1::2]).most_common() + [(0, 0)]

if e[0][0] != o[0][0]:
    print(n - e[0][1] - o[0][1])
else:
    print(n - max(e[0][1]+o[1][1], e[1][1]+o[0][1]))

Measured memory_bytes: 20572
N = int(input())

S = {}
for i in range(N):
    a = input()
    if not a in S.keys():
        S[a] = 1
    else:
        S[a] += 1

maxv = max(S.values())
ans = []
for i, j in S.items():
    if j == maxv:
        ans.append(i)

ans = sorted(ans)
for i in ans:
    print(i)

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

namespace Practice
{
    class Program
    {

        static void Main(string[] args)
        {
            SolveA(args);
        }
        static void SolveA(string[] args)
        {
            string szLine = Console.ReadLine();
            string[] szArr = szLine.Split(' ');
            int a = int.Parse(szArr[0]);
            int b = int.Parse(szArr[1]);

            int dif = a - b;
            if (a >= 9 || b >= 9)
            {
                Console.WriteLine(":(");
            }
            else
            {
                Console.WriteLine("Yay!");
            }
        }

        static void SolveB(string[] args)
        {
            string szLine = Console.ReadLine();
            string[] szArr = szLine.Split(' ');
            int d = int.Parse(szArr[0]);
            int n = int.Parse(szArr[1]);

            int answer = 0;
            if( d == 0)
            {
                if (n == 100)
                {
                    answer = 101;
                    
                }
                else
                {
                    answer = n;
                }
            }else if( d == 1)
            {
                if (n == 100)
                {
                    answer = 100 * 101;
                }
                else
                {
                    answer = 100 * n;
                }
            }else // d == 2
            {
                if (n == 100)
                {
                    answer = 100 * 100 * 101;
                }
                else
                {
                    answer = 10000 * n;
                }
            }
            Console.WriteLine(answer);
        }

        static void SolveC(string[] args)
        {
            string szLine = Console.ReadLine();
            int n = int.Parse(szLine);
            szLine = Console.ReadLine();
            string[] szArr = szLine.Split(' ');
            long[] a = new long[szArr.Length];


            // 各数に対し、2^ki の倍数かを求め　ki を足し合わせるイメージ？
            int total = 0;
            for(int i=0;i<a.Length;++i)
            {
                long tmp = long.Parse(szArr[i]);
                a[i] = tmp;

                while ( tmp % 2 == 0)
                {
                    tmp /= 2;
                    total++;
                }
            }

            


            Console.WriteLine(total);
        }
    }

}


Measured memory_bytes: 11092
def digitSum(n):
    # 数値を文字列に変換
    s = str(n)
    # １文字ずつ数値化し配列にする。
    array = list(map(int, s))
    # 合計値を返す
    return sum(array)

N = int(input())

if digitSum(N) % 9 == 0 and N % 9 == 0:
    print('Yes')
else:
    print('No')

Measured memory_bytes: 11120
using System;
using System.Linq;

namespace HelloWorld
{
    class Program
    {
        static void Main()
        {
            Dice sai = new Dice();
            var die = Console.ReadLine().Split().Select(int.Parse).ToArray();
            var dir = Console.ReadLine().ToCharArray();
            Console.WriteLine(sai.Roll(dir, die));
        }
    }
    internal class Dice
    {
        internal int Roll(char[] dir, int[] pips)
        {
            foreach (var v in dir)
            {
                GoWays(v,pips);
            }
            return pips[0];
        }
        private void GoWays(char way, int[] pips)
        {
            if (way == 'N')
            {
                GoNorth(pips);
            }
            else if (way == 'W')
            {
                GoWest(pips);
            }
            else if (way == 'S')
            {
                GoSouth(pips);
            }
            else
            {
                GoEast(pips);
            }
        }
        private void GoNorth(int[] pips)
        {
            int tmp = pips[0];
            pips[0] = pips[1];
            pips[1] = pips[5];
            pips[5] = pips[4];
            pips[4] = tmp;

        }
        private void GoSouth(int[] pips)
        {
            int tmp = pips[0];
            pips[0] = pips[4];
            pips[4] = pips[5];
            pips[5] = pips[1];
            pips[1] = tmp;
        }
        private void GoWest(int[] pips)
        {
            int tmp = pips[0];
            pips[0] = pips[2];
            pips[2] = pips[5];
            pips[5] = pips[3];
            pips[3] = tmp;
        }
        private void GoEast(int[] pips)
        {
            int tmp = pips[3];
            pips[3] = pips[5];
            pips[5] = pips[2];
            pips[2] = pips[0];
            pips[0] = tmp;
        }
    }
}


Measured memory_bytes: 20404
#include <bits/stdc++.h>
#define INF 5000000000000000000
#define ll long long
#define pll pair<ll, ll>
using namespace std;
vector<ll> C(26);
vector<vector<ll>> S;

ll change_evaluation(vector<ll>& T,ll day) {
  day -= 1;
  vector<ll> last(26, -1);
  vector<ll> next(26, T.size());
  ll old = T.at(day) - 1;
  for (ll i = 0; i < day; ++i) {
    last.at(T.at(i) - 1) = i;
  }
  for (ll i = T.size() - 1; i > day; --i) {
    next.at(T.at(i) - 1) =  i;
  }
  ll max_t = 0, max_score = -INF;
  for (ll t = 0; t < 26; ++t) {
    ll score = S.at(day).at(t) - S.at(day).at(old);
    score += (next.at(t) - day) * (day - last.at(t)) * C.at(t);
    score -= (next.at(old) - day) * (day - last.at(old)) * C.at(old);
    if (score > max_score) {
      max_score = score;
      max_t = t;
    }
  }
  return max_t;
}

ll evaluation(ll t, ll day, vector<ll>& last) {
  ll score = 0;
  score += S.at(day).at(t);
  for (ll j = 0; j < 26; ++j) {
    if (j == t) {
      continue;
    }
    score -= (day + 1 - last.at(j)) * C.at(j);
  }
  return score;
}

ll whole_evaluation(vector<ll>& T) {
  ll D = T.size();
  vector<ll> last(26, 0);
  ll score = 0;
  for (ll i = 0; i < D; ++i) {
    ll contest = T.at(i) - 1;
    last.at(contest) = i + 1;
    score += S.at(i).at(contest);
    for (ll j = 0; j < 26; ++j) {
      score -= (i + 1 - last.at(j)) * C.at(j);
    }
  }
  return score;
}

int main() {
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  //-----------input-------------
  ll D;
  cin >> D;
  vector<ll> T(D);
  S = vector<vector<ll>>(D, vector<ll>(26));
  for (ll i = 0; i < 26; ++i) {
    cin >> C.at(i);
  }
  for (ll i = 0; i < D; ++i) {
    for (ll j = 0; j < 26; ++j) {
      cin >> S.at(i).at(j);
    }
  }
  //--------------------------------------
  vector<ll> last(26, 0);
  for (ll day = 0; day < D; ++day) {
    ll max_contest = 0;
    ll max_score = -INF;
    for (ll contest = 0; contest < 26; ++contest) {
      ll temp_score = evaluation(contest, day, last);
      if (temp_score > max_score) {
        max_score = temp_score;
        max_contest = contest + 1;
      }
    }
    last.at(max_contest - 1) = day;
    T.at(day) = max_contest;
  }

  random_device rnd;
  mt19937 mt(rnd());
  uniform_int_distribution<> rand(1, T.size());
  uniform_int_distribution<> rand_evn(1, 26);
  for (ll i = 0; i < 100000; ++i) {
    ll random = rand(mt);
    if (random < i) {
      ll event = rand_evn(mt);
      T.at(random - 1) = event;
    }
    else {
      ll max_t = change_evaluation(T, random);
      // cout << max_t << " rand" << "\n";
      T.at(random - 1) = max_t + 1;
    }
  }

  // ll score = whole_evaluation(T);
  // cout << score << "\n";

  for (ll i = 0; i < D; ++i) {
    cout << T.at(i) << "\n";
  }

  // vector<ll> ans = evaluation(C, S, T);
  // for (ll i = 0; i < ans.size(); ++i) {
  //   cout << ans.at(i) << "\n";
  // }
}


Measured memory_bytes: 3716
#include <stdio.h>
#include <string.h>
int main() 
{
    int n;
    char input[101];
    scanf("%d", &n);
    int ac = 0, wa = 0, tle = 0, re = 0;
    for(int i = 0 ; i < n; i++)
    {
    	scanf("%s", input);
    	if(strcmp(input, "AC") == 0)
    	{
    		ac++;
		} else if(strcmp(input, "TLE") == 0)
		{
			tle++;
		} else if(strcmp(input, "WA") == 0)
		{
			wa++;
		} else if(strcmp(input, "RE") == 0)
		{
			re++;
		}
	}
	printf("AC x %d\n", ac);
	printf("WA x %d\n", wa);
	printf("TLE x %d\n", tle);
	printf("RE x %d\n", re);
	
    return 0;
}

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

int main(){
  int N; cin >> N;
  string A,B,C; cin >> A >> B >> C;
  int res=0;
  for(int i=0; i<N; i++){
    if(A[i]==B[i]){
      if(B[i]==C[i]){
      }else{
        res++;
      }
    }else{
      if(B[i]==C[i]){
        res++;
      }else{
        if(A[i]==C[i]){
          res++;
        }else{
          res+=2;
        }
      }
    }
  }
  cout << res << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define all(x) (x).begin(),(x).end()
using ll=long long;

int main(){
    ll n,m,i,j,k;
    ll a,b,c,d;

    cin>>a>>b>>c>>d;
    (a-1)/d>=(c-1)/b ? cout<<"Yes" : cout<<"No";

    return 0;
}



Measured memory_bytes: 3636
import qualified Data.Text as T
import qualified Data.Text.IO as T
import qualified Data.Text.Read as T
import Data.List (group)

main :: IO ()
main = do
  s <- getLine :: IO String
  (k : _) <- map unsafeSignedDecimal . T.words <$> T.getLine :: IO [Int]
  let
    gs = map ((,) <$> head <*> length) . group $ s
    n | l == 1 = f (lh * k)
      | ch == cl = let ls = init . tail . map snd $ gs in f lh + g ls * k + f (lh + ll) * (pred k) + f ll
      | otherwise = (g . map snd $ gs) * k
      where
        l = length gs
        (ch, lh) = head gs
        (cl, ll) = last gs
  print n

f :: Int -> Int
f = (`div` 2)

g :: [Int] -> Int
g = sum . map f

unsafeSignedDecimal :: T.Text -> Int
unsafeSignedDecimal s = case T.signed T.decimal s of
  Right (n, _) -> n


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

#define     fast()              ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); 
#define     ll                  long long int
#define     test()              ll t; cin>>t; while(t--) 
#define     lp0(i,begin,end)    for(ll i=begin;i<end;i++)
#define     lp1(i,begin,end)    for(ll i=begin;i<=end;i++)
#define     rlp(i,begin,end)    for(ll i=end;i>=begin;i--)
#define     prec(n)             fixed<<setprecision(n)
#define     initial(a,i)        memset(a,i,sizeof(a))
#define     pb                  push_back
#define     PI                  3.1415926535897932384626433832795
#define     MOD                 1000000007
#define     F                   first
#define     S                   second
#define     all(a)              (a).begin(),(a).end()
#define     BPC(x)              __builtin_popcountll(x)
#define     gcd(a,b)            __gcd(a,b)

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

ll power(ll x,ll n)
{
    ll result = 1;
    while (n)
    {
        if (n & 1)
            result = result * x;
        n = n / 2;
        x = x * x;
    }
    return result;
}


// Solution Function
void solution(ll compte)
{
    // cout<<compte<<"\n";
    ll a,b;
    cin>>a>>b;

    
    if(a>=1 && a<=9 && b>=1 && b<=9)
        cout<<a*b;
    else
        cout<<-1<<"\n";    
    





}
// Driver Function
int main()
{
    ll compte = 1;
    //test()
    //{
        solution(compte);
        compte++;
    //}
    return 0;
}


Measured memory_bytes: 3564
#include <bits/stdc++.h>
using namespace std;
int main(){
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    #ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w",stdout);
    #endif
     double r;
     cin>>r;
     cout<<(3.14*r*2)<<endl;
}

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

int f[110][15];
int p[110][15];

int main(){
  int n;
  cin>>n;
  rep(i,n)rep(j,10) cin>>f[i][j];
  rep(i,n)rep(j,11) cin>>p[i][j];
  ll ans=LLONG_MIN;
  for(int i=1; i<(1<<10); i++){
    ll now=0;
    vector<int> c(n,0);
    rep(s,n){
      rep(j,10){
        if(i>>j&1 && f[s][j]==1) c[s]++;
      }
    }
    rep(j,n){
      now+=p[j][c[j]];
    }
    ans=max(ans,now);
  }
  cout<<ans<<endl;
}


Measured memory_bytes: 3632
#include<bits/stdc++.h>
using namespace std;
int main()
{
     // freopen("input1.txt","r",stdin);
     // freopen("output1.txt","w",stdout); 
    long double n,x,t;
    cin>>n>>x>>t;
    cout<<   (long long int) (ceil(n / x)*t );

}

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

int main(){
    int n, m;
    cin >> n;
    int x[n];
    for(int i = 0; i < n; i++) cin >> x[i];
    cin >> m;
    int a[m];
    for(int i = 0; i < m; i++) cin >> a[i];
    
    
    
    for(int i = 0; i < m; i++){
        if(a[i] == n && x[a[i]-1] < 2019) x[a[i]-1]++;
        else{
            if(x[a[i]-1]+1 != x[a[i]] && x[a[i]-1] < 2019) x[a[i]-1]++; 
        }
    }
    
    for(int i = 0; i < n; i++) cout << x[i] << endl;
    
    return 0;
}


Measured memory_bytes: 3092
#include<bits/stdc++.h>
using namespace std;
#define int long long int
#define pb push_back
#define mp make_pair
#define ip pair<int, int>
#define it pair<int, pair<int, int>>
#define F first
#define S second
#define fori(p, n) for(int i = p; i < n; i++)
#define forj(q, m) for(int j = q; j < m; j++)
#define fork(r, l) for(int k = r; k < l; k++)
#define revi(h) for(int i = h; i >= 0; i--)
#define all(v) v.begin(), v.end()
#define PI 3.14159265358
#define debug(x) cout<<"DEBUGGING --- "<<x<<endl;
#define fastio ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
#define input_from_file  freopen("input.txt", "r", stdin);
#define output_to_file freopen("output.txt", "w", stdout);

signed main(){
    fastio;
    // input_from_file; 
    // output_to_file;
    int n; cin >> n;
    vector<int>A(n);
    fori(0, n) cin >> A[i];
    vector<int>R(n);
    R[n - 1] = A[n - 1];
    revi(n - 2) R[i] = A[i] + R[i + 1];
    int sum = 0;
    fori(0, n - 1) sum += A[i] * R[i + 1];
    cout << sum << endl;
}


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

void fnInput(vector<string>& rvsStrX, vector<string>& rvsStrY)
{
  int nMaxSiz;
  cin >> nMaxSiz;
  rvsStrX.resize(nMaxSiz);
  rvsStrY.resize(nMaxSiz);

  for (int i = 0; i < nMaxSiz; ++i)
  {
    cin >> rvsStrX[i] >> rvsStrY[i];
    rvsStrX[i] = ' ' + rvsStrX[i];
    rvsStrY[i] = ' ' + rvsStrY[i];
  }
}

int fnLngCmnSubseq(const vector<string>& cnrvsStrX, const vector<string>& cnrvsStrY)
{
  vector<vector<int>> vvnLcsDP;
  for (int i = 0; i < cnrvsStrX.size(); ++i)
  {
    const int nMAXNX = cnrvsStrX[i].size();
    const int nMAXNY = cnrvsStrY[i].size();

    vvnLcsDP.clear();
    vvnLcsDP.resize(nMAXNX, vector<int>(nMAXNY, 0));

    for (int nx = 1; nx < nMAXNX; ++nx)
      for (int ny = 1; ny < nMAXNY; ++ny)
        if (cnrvsStrX[i][nx] == cnrvsStrY[i][ny])
          vvnLcsDP[nx][ny] = vvnLcsDP[nx - 1][ny - 1] + 1;
        else
          vvnLcsDP[nx][ny] = max(vvnLcsDP[nx - 1][ny], vvnLcsDP[nx][ny - 1]);

    cout << vvnLcsDP[nMAXNX - 1][nMAXNY - 1] << endl;
  }
}

int main()
{
  cin.tie(0);
  ios::sync_with_stdio(false);
  vector<string> vsStrX, vsStrY;

  fnInput(vsStrX, vsStrY);
  fnLngCmnSubseq(vsStrX, vsStrY);
  return 0;
}

Measured memory_bytes: 6972
#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++)
#define all(x) (x).begin(),(x).end()
#define V vector
typedef V<int> vi;
typedef V<vi> vvi;
typedef long long ll;
typedef pair<ll, ll> P;
constexpr auto INF = INT_MAX / 2;
constexpr auto LINF = 5000000000000000;
constexpr auto MOD = 1000000007;

int main() {
	
	ll n, a, b;
	cin >> n >> a >> b;
	ll mn = (n - 1) * a + b;
	ll mx = (n - 1) * b + a;

	cout << max(mx-mn+1,(ll)0) << endl;

}

Measured memory_bytes: 256
import itertools
import decimal
import math
from collections import Counter
import sys
input = sys.stdin.readline

N=int(input())
ListA=list(map(int,input().split()))
Q=int(input())

Counts = Counter(ListA)
Sum = sum(ListA)

for i in range(Q):
    B,C=map(int,input().split())
    Sum+=Counts[B]*(C-B)
    Counts[C]+=Counts[B]
    Counts[B]=0
    print(Sum)



Measured memory_bytes: 24344
import sys
import math
n,p=map(int,input().split())
if n==1:
  print(p)
  sys.exit()
soinsu=dict()
i=2
mx = math.ceil(p ** (1.0/n))+1
while i < mx:
  if p==1:
    break
  if p % i==0:
    p = p//i
    if i in soinsu:
      soinsu[i] += 1
    else:
      soinsu[i] = 1
  else:
    i += 1
#print(soinsu)
ans=1
for k,v in soinsu.items():
  if v//n > 0:
    ans *= k ** (v//n)
    #print(k,v,v//n, ans)
print(ans)

Measured memory_bytes: 63476
def c_snuke_festival(N, A, B, C):
    from bisect import bisect_left, bisect_right
    a, b, c = sorted(A), sorted(B), sorted(C)
    # bの各要素に対して、それより小さなaの要素数とそれより大きなcの要素数の積の総和が解
    return sum(bisect_left(a, _b) * (N - bisect_right(c, _b)) for _b in b)

N = int(input())
A = [int(i) for i in input().split()]
B = [int(i) for i in input().split()]
C = [int(i) for i in input().split()]
print(c_snuke_festival(N, A, B, C))

Measured memory_bytes: 23296
#include <iostream>
#include <vector>
#include <cmath>
#include <string>
#include <algorithm>
#include <iomanip>
#include <map>
#include <bitset>
#include <cstdio>
#include <set>
#include <stack>
#include <queue>
#include <cassert>
#include <numeric>
using namespace std;
typedef long long ll;
#define FOR(i,a,b) for (ll i=(a),__last_##i=(b);i<__last_##i;i++)
#define RFOR(i,a,b) for (ll i=(b)-1,__last_##i=(a);i>=__last_##i;i--)
#define REP(i,n) FOR(i,0,n)
#define RREP(i,n) RFOR(i,0,n)
#define __GET_MACRO3(_1, _2, _3, NAME, ...) NAME
#define rep(...) __GET_MACRO3(__VA_ARGS__, FOR, REP)(__VA_ARGS__)
#define rrep(...) __GET_MACRO3(__VA_ARGS__, RFOR, RREP)(__VA_ARGS__)
template<typename T> istream &operator>>(istream &is, vector<T> &v){ for (auto &x : v) is >> x; return is; }
template<typename T> ostream& operator<<(ostream& os, const vector<T>& v) {
    REP(i,v.size()){if(i)os<<" ";os<<v[i];}return os;}
template<typename T> ostream& operator<<(ostream& os, const vector<vector<T>>& v) {
    REP(i,v.size()){if(i)os<<endl;os<<v[i];}return os;}
#define vi vector<int>
#define vii vector<vector<int>>
#define mii map<int,int>
#define Sort(v) sort(v.begin(),v.end())
#define Reverse(v) reverse(v.begin(),v.end())
#define ALL(a)  (a).begin(),(a).end()
#define pb push_back
#define mp make_pair
//#define int ll

const int md = 1000000007;
const int INF = 1<<30;



int main(){
    int n; cin >> n;
    vector<vector<int>> e(n);
    vi c(n);
    vi d(n);


    rep(i,n-1){
        int a,b; cin >> a >> b;
        e[a-1].pb(b-1);
        e[b-1].pb(a-1);
        d[a-1]++; d[b-1]++;
    }
    cin >> c;

    int ans = 0;
    Sort(c);
    Reverse(c);

    rep(i,n-1) ans += c[i+1];
    Sort(d);
    Reverse(d);

    vector<pair<int,int>> ansv(n);
    queue<int> bfs;
    queue<int> a;
    vector<bool> visit(n,false);
    bfs.push(d[0]);
    while(!bfs.empty()){
        int tmp = bfs.front();
        a.push(tmp);
        bfs.pop();

        visit[tmp] = true;
        rep(i,e[tmp].size()){
            if(!visit[e[tmp][i]]) bfs.push(e[tmp][i]);
        }

    }

    rep(i,n){
        ansv[i] = make_pair(a.front(),c[i]);
        a.pop();
    }

    Sort(ansv);
    cout << ans << endl;
    rep(i,n){
        cout << ansv[i].second << " ";
    }
    cout << endl;

}


Measured memory_bytes: 1152
#include<bits/stdc++.h>
using namespace std;
 
typedef long long LL;
typedef unsigned long long ULL;
 
template<class T>
inline bool read(T &num)  
{
       char in;bool IsN=false;
       while(in=getchar(),in!='-'&&(in<'0'||in>'9'))if(in==EOF)return false;
       in=='-'?(IsN=true,num=0):num=in-'0';
       while(in=getchar(),in>='0'&&in<='9')num=num*10+in-'0';
       return IsN?num=-num:num,true;
}
 
 
#define lson l,mid,rt<<1
#define rson mid+1,r,rt<<1|1
#define __m  int mid=l+(r-l)/1
 
const int maxn   = 400;
const LL  inf_LL = 9e18   ;
const int inf    = 2e9 + 7;
const int mod    = 1e9 + 7;

LL rr[maxn],road[maxn][maxn];

int main() {
#ifdef LOCAL
    freopen("sample.in", "r", stdin);
#endif
    int n,m,r;
    read(n);read(m);read(r);
    for(int i=0;i<r;i++)
        scanf("%d",&rr[i]);
    for(int i=0;i<=n;i++)
        for(int j=0;j<=n;j++)
            road[i][j]=inf;
    for(int i=0;i<m;i++)
    {
        LL a,b,c;
        read(a);read(b);read(c);
        road[a][b]=min(road[a][b],c);
        road[b][a]=min(road[b][a],c);
    }
    for(int k=1;k<=n;k++)
    for(int i=1;i<=n;i++)
        for(int j=1;j<=n;j++)
                    road[i][j]=min(road[i][j],road[i][k]+road[k][j]);
    sort(rr,rr+r);
    LL ans=inf_LL;
    while(next_permutation(rr,rr+r))
    {
        LL temp=0;
        for(int i=1;i<r;i++)
            temp+=road[rr[i-1]][rr[i]];
        ans=min(ans,temp);
    }
    printf("%lld\n",ans);
    return 0;
}


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

int main() {
	string T="abcdefghijklmnopqrstuvwxyz";
	char c;
	int count=0;
	cin>>c;
	for(int i=0;i<26;i++){
		if(T.at(i)==c){
			count=i;
		}
	}
	cout<<T.at(count+1)<<endl;
	return 0;
}

Measured memory_bytes: 256
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<algorithm>
#include<functional>
#include<vector>
#include<queue>
#include<stack>
#include<set>
#include<map>
using namespace std;
#define MOD 1000000007
#define f(i,n) for(int i=0;i<int(n);i++)
#define N 510

int main() {
	char c[N];
	char a[N][N];
	char b[N][N];
	int n, m;
	f(i, N) {
		f(j, N) {
			a[i][j] = 0;
			b[i][j] = 0;
		}
		c[i] = 0;
	}
	scanf("%d %d", &n, &m);
	f(i, n) {
		a[i][0] = '#';
		a[i][m - 1] = '.';
		b[i][m - 1] = '#';
		b[i][0] = '.';
		if (i % 2 == 0) {
			for (int j = 1; j < (m - 1); j++) {
				a[i][j] = '#';
				b[i][j] = '.';
			}
		}
		else {
			for (int j = 1; j < (m - 1); j++) {
				b[i][j] = '#';
				a[i][j] = '.';
			}
		}
	}
	f(i, n) {
		scanf("%s", c);
		f(j, m) {
			if (c[j] == '#') {
				a[i][j] = '#';
				b[i][j] = '#';
			}
			c[j] = 0;
		}
	}
	f(i, n)printf("%s\n", a[i]);
	printf("\n");
	f(i, n)printf("%s\n", b[i]);
	return 0;
}

Measured memory_bytes: 1152
import java.util.Scanner;

class Main{
  public static void main(String[] args) {
    Scanner scanner = new Scanner(System.in);
    int N = Integer.parseInt(scanner.next());
    long K = Long.parseLong(scanner.next());
    scanner.close();

    long ans = K;

    for(int i=1; i<N; i++){
      ans *= K-1l;
    }

    System.out.println(ans);
  }
}


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

int main()
{
    int input[3];
    cin >> input[0] >> input[1] >> input[2];

    int cou5 = 0;
    int cou7 = 0;
    for (int i = 0; i < 3; i++)
    {
        if (input[i] == 5) {
            cou5++;
        }
        if (input[i] == 7) {
            cou7++;
        }
    }

    string result = (cou5 == 2 && cou7 == 1) ? "YES" : "NO";

    cout << result << endl;
    return 0;
}

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

typedef long long ll;
typedef long double ld;
typedef pair<int, int> ii;
typedef pair<int, ii> iii;
typedef pair<ii, int> ri3;
#define mp make_pair
#define pb push_back
#define fi first
#define sc second
#define SZ(x) (int)(x).size()
#define ALL(x) begin(x), end(x) 
#define REP(i, n) for (int i = 0; i < n; ++i) 
#define FOR(i, a, b) for (int i = a; i <= b; ++i)
#define RFOR(i, a, b) for (int i = a; i >= b; --i)

const int MX_N = 2005;

int N, K;
vector<int> al[MX_N];

int sub(int u, int p, int d, int k) {
    int ret = (d > k);
    for (auto v : al[u]) if (v != p) {
        ret += sub(v,u,d+1,k);
    }
    return ret;
}

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

    cin >> N >> K;
    vector<ii> el;
    FOR(i,1,N-1){
        int A, B; cin >> A >> B;
        al[A].push_back(B);
        al[B].push_back(A);
        el.emplace_back(A,B);
    }

    int ans = N+1;
    if (K&1) {
        for(auto& e : el) {
            ans = min(ans, sub(e.fi,e.sc,0,K/2)+sub(e.sc,e.fi,0,K/2));
        }
    } else {
        FOR(i,1,N){
            ans = min(ans, sub(i,-1,0,K/2));
        }
    }

    cout << ans;
}



Measured memory_bytes: 512
#include<iostream>
using namespace std;
int main() {
  int n;
  long long a[100050],b[100050],ans=0;
  cin >> n;
  for(int i=0;i<=n;i++) cin >> a[i];
  for(int i=0;i<n;i++) cin >> b[i];
  for(int i=n-1;i>=0;i--){
    if(b[i] >= a[i+1]){
      ans += a[i+1];
      b[i] -= a[i+1];
      a[i+1] = 0;
    }else{
      ans += b[i];
      b[i] = 0;
      a[i] -= b[i];
    }
    
    if(b[i] >= a[i]){
      ans += a[i];
      a[i] = 0;
    }else{
      ans += b[i];
      a[i] -= b[i];
    }
  }
  cout << ans;
  return 0;
}

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

using namespace std;

int main(){
    int n, y; cin >> n >> y;

    int res10000 = -1, res5000 = -1, res1000 = -1;
    for (int a = 0; a <= n; a++) {
        for(int b = 0; a + b <= n; b++){
            int c = n - a - b;
            int sum = 10000 * a + 5000 * b + 1000 * c;
            if(sum == y){
                res10000 = a;
                res5000 = b;
                res1000 = c;
            }
        } 
    }
    cout << res10000 << " " << res5000 << " " << res1000 << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define pb push_back
#define mp make_pair
typedef long long int ll;
using namespace std;

ll n;
vector<ll> a;
vector<ll> b, f;

int main(){
  cin >> n;
  a = vector<ll>(n);
  b = vector<ll>(n);
  f = vector<ll>(n);
  for(ll i=0;i<n;i++){
    cin >> a[i];
    if (i + a[i] < n) f[i + a[i]]++;
    if (i - a[i] >= 0) b[i - a[i]]++;   
  }
  ll ans = 0;
  for(ll i=0;i<n;i++){
    ans += f[i] * b[i];      
  }
  cout << ans << endl;
  return 0;
}
  

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

typedef long long ll;
#define all(x) (x).begin(),(x).end()
const int mod=1000000007;

int main(){
    
    ll N,A,B,C,D;cin>>N>>A>>B>>C>>D;
    ll M=abs(A-B),dif=(D-C);
    bool flag=false;
    for(ll i=0;i<=N-1;i++){
        ll a=C*i+(-C)*(N-1-i);
        if(a==M){
            flag=true;
        }
        else if(a>M){
            if(M+dif*(N-1-i)>=a){
                flag=true;
            }
        }else if(a<M){
            if(a+dif*i>=M) {
                flag=true;
            }
        }
    }
    if(flag) cout<<"YES"<<endl;
    else cout<<"NO"<<endl;
}


Measured memory_bytes: 256
sx, sy, tx, ty = map(int, input().split())
ans = ''
ans += 'U'*(ty-sy)
ans += 'R'*(tx-sx)
ans += 'D'*(ty-sy)
ans += 'L'*(tx-sx)
ans += 'L'
ans += 'U'*(ty-sy+1)
ans += 'R'*(tx-sx+1)
ans += 'D'
ans += 'R'
ans += 'D'*(ty-sy+1)
ans += 'L'*(tx-sx+1)
ans += 'U'
print(ans)

Measured memory_bytes: 3064
#include <cstdio>
#include <cstring>
using namespace std;

const int maxn = 15;
int an[maxn], bm[maxn];
int arr[maxn];
bool cnt;

void dfs(int n, int m, int k);

int main(){
    int t;
    scanf("%d", &t);
    while(t--){
        for(int i = 0; i < 10; ++i){
            scanf("%d", &arr[i]);
        }
        cnt = false;
        an[0] = arr[0];
        bm[0] = -1;
        dfs(0, 0, 1);

        if(cnt){
            puts("YES");
        }
        else{
            puts("NO");
        }
    }
    return 0;
}

void dfs(int n, int m, int k){
    if(k == 10){
        cnt = true;
        return ;
    }

    if(arr[k] < an[n] && arr[k] < bm[m]){
        return ;
    }

    if(arr[k] > an[n]){
        an[n+1] = arr[k];
        dfs(n+1, m, k+1);
    }
    if(arr[k] > bm[m]){
        bm[m+1] = arr[k];
        dfs(n, m+1, k+1);
    }
}

Measured memory_bytes: 1008
#include <iostream>

using namespace std;

int main(int argc, char** argv){
    int N, M;
    cin >> N >> M;

    int l = 1, r = N;
    for (int i=0; i<M; i++){
        int L, R;
        cin >> L >> R;
        if (L > l) l = L;
        if (R < r) r = R;
        if (l > r) break;
    }

    if (l > r) cout << "0\n";
    else cout << r - l + 1 << "\n";

    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, a, n) for(int i = a; i < n; i++)
#define int long long
using namespace std;
typedef pair<int, int> P;
const int mod = 1000000007;
const int INF = 1e18;

signed main(){
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    int a, p;
    cin >> a >> p;
    cout << (a * 3 + p) / 2 << endl;
}

Measured memory_bytes: 764
#include <stdio.h>

int main(void)

{

   int a,b,d,r; 

   double f;  

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

   d=a/b;  

   r=a%b;  

   f=(double)a/(double)b;  

   printf("%d %d %lf\n",d,r,f);  

   return 0;

}

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

#define A first
#define B second

typedef long long ll;
typedef pair<ll, ll> pii;
typedef list<pii> lii;


int main() {
  ll N, H, a, b, MAX_A = 0;
  ll sum = 0, ans = 1;
  lii katanas_a, katanas_b;
  cin >> N >> H;
  for (int i=0; i<N; i++) {
    cin >> a >> b;
    if (MAX_A < a) MAX_A = a;
    katanas_a.push_back(make_pair(a, b));
  }
  lii::iterator it = katanas_a.begin();
  while (it != katanas_a.end()) {
      if (it->B < MAX_A) {
          it = katanas_a.erase(it);
      } else ++it;
  }
  katanas_b = katanas_a;
  for (lii::iterator it = katanas_b.begin(); it!=katanas_b.end(); ++it) {
    it->A = it->B;
    sum += it->B;
  }
  katanas_a.sort(greater<pii>());
  katanas_b.sort(greater<pii>());
  if (H <= sum) {
    sum = 0;
    for (lii::iterator it = katanas_b.begin(); it!=katanas_b.end(); ++it) {
      sum += it->A;
      if (H <= sum) break;
      ans++;
    }
  } else {
    ans = katanas_b.size() + (H-sum) / MAX_A;
    if ((H-sum) % MAX_A != 0) ans++;
  }

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


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

#define rep(i, n) for (int i = 0; i < (n); i++)
#define MOD 1000000007
typedef long long ll;
typedef unsigned long long ull;

int main() {
  int n;
  cin >> n;
  vector<int> vec(n, 0);
  rep(i, n - 1) {
    int t;
    cin >> t;
    vec[t - 1]++;
  }

  for (auto x : vec) {
    cout << x << endl;
  }
}

Measured memory_bytes: 3996
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
#define rep(i,n) for(ll i = 0;i < n;++i)
    map<string,int> memo;
int main(){
    int n;
    cin >> n;
    rep(i,n){
        string s;
        cin >> s;
        memo[s] += 1;
    }
    int maxv = 0;
    for(auto x : memo){
        if(x.second > maxv) {
            maxv = x.second;
        }
    }
    for(auto it = memo.begin();it != memo.end();it++) {
        if(it->second == maxv) {
            cout << it->first << endl;
        }
    }
    return 0;
}

Measured memory_bytes: 25216
#include <iostream>

using namespace std;

int main(){

    int N;
    cin >> N;

    string S;
    cin >> S;

    int ret = 1;

    for(int i = 0; i < N-1; i++){
        if(S[i] != S[i+1])
            ret++;
    }

    cout << ret;

    return 0;
}

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


void solve(){
	int h1,m1,h2,m2,k;
	int time1 = 0,time2 = 0;
	cin >> h1 >> m1 >> h2 >> m2 >> k;
	time1 = (h1*60)+m1;
	time2 = (h2*60)+m2;
	cout<<(time2 - time1)-k<<"\n";
}
int main()
{
 	ios::sync_with_stdio(0);
 	cin.tie(0);
 	solve();
}

Measured memory_bytes: 3660
#include <iostream>
#include <algorithm>
#include <utility>
#include <string>
#include <vector>
#include <set>
#include <stack>
#include <queue>
#include <map>
#include <math.h>
#include <string.h>
#include <iomanip>
#include <numeric>
#include <cstdlib>
#include <cstdint>
#include <cmath>
#include <functional>

using namespace std;

using ll = long long;
using pll = pair<ll, ll>;
using vl = vector<ll>;
using vll = vector<vl>;
using vpll = vector<pll>;

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rrep(i, n) for (int i = ((int)(n)-1); i >= 0; i--)
#define Rep(i, n) for (long long i = 0; i< (long long)(n); i++)
#define RRep(i,n) for (long long i = ((long long)(n)-1); i>=0; i--)

struct Edge{
    int to;
    int weight;
    Edge(int t, int w) : to(t), weight(w){ }
};

using Graph = vector<vector<Edge>>;
using graph = vector<vector<int>>;

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;
}

template <class T>
T gcd(T a, T b){
    if( b==0 ) return a;
    return gcd(b, a%b);
}

template <class T>
T lcm(T a, T b){
    return (a*b)/gcd(a,b);
}

ll INF = 1e9+7;

vector<int> dx = {-1,0,1,0};
vector<int> dy = {0,-1,0,1};

int main(){
    string s;
    cin >> s;
    if(s[0]==s[1] && s[0]==s[2] && s[1]==s[2]){
        cout << "No" << endl;
    }
    else cout << "Yes" << endl;
}

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

int main()
{
	int n;

	cin >> n;

	while (n != 0) {
		int m = 0;
		bool f = 0;

		for (int i = 0; i < n; i++) {
			int k;
			cin >> k;

			if (k > 0) {
				m++;
				if (k > 1)
					f = 1;
			}
		}
		if (f)
			cout << m + 1 << endl;
		else
			cout << "NA" << endl;

		cin >> n;
	}

	return 0;
}



Measured memory_bytes: 3124
#![allow(unused_imports)]
use std::io::{ self, Write };
use std::str::FromStr;
use std::cmp::{ min, max };
use std::collections::{ BinaryHeap, VecDeque };

#[allow(unused_macros)]
macro_rules! trace {
    ($var:expr) => {
        let _ = writeln!(&mut std::io::stderr(), ">>> {} = {:?}", stringify!($var), $var);
    };
    ($($args:expr),*) => { trace!(($($args),*)) }
}

const M: usize = 1_000_000_007;

fn main() {
    let mut sc = Scanner::new();
    let n: usize = sc.cin();
    let mut a: Vec<i64> = vec![0; n]; for i in 0..n { a[i] = sc.cin(); }; a.sort();
    let mut b: Vec<i64> = vec![0; n]; for i in 0..n { b[i] = sc.cin(); }; b.sort();
    let mut c: Vec<i64> = vec![0; n]; for i in 0..n { c[i] = sc.cin(); }; c.sort();
    // trace!(a);
    // trace!(b);
    // trace!(c);

    let mut bb = vec![0; n];
    for i in 0..n {
        let x = b[i];
        let mut left = 0;
        let mut right = n;
        for _ in 0..1000 {
            let mid = (left + right) / 2;
            if c[mid] > x {
                right = mid;
            } else {
                left = mid;
            }
        }
        left = if left > 5 { left - 5 } else { 0 };
        right = if right + 5 < n { right + 5 } else { n };
        for j in left..right {
            if c[j] > x {
                bb[i] = n - j;
                break;
            }
        }
    }
    // trace!(bb);

    let mut bbac = vec![0; n];
    bbac[n-1] = bb[n-1];
    for i in 1..n {
        let j = n - i - 1;
        bbac[j] = bb[j] + bbac[j+1];
    }
    // trace!(bbac);

    let mut ans = 0;

    for i in 0..n {
        let x = a[i];
        let mut left = 0;
        let mut right = n;
        for _ in 0..1000 {
            let mid = (left + right) / 2;
            if b[mid] > x {
                right = mid;
            } else {
                left = mid;
            }
        }
        left = if left > 5 { left - 5 } else { 0 };
        right = if right + 5 < n { right + 5 } else { n };
        for j in left..right {
            if b[j] > x {
                ans += bbac[j];
                break;
            }
        }
    }

    println!("{}", ans);
}

#[allow(dead_code)]
struct Scanner { stdin: io::Stdin, buffer: VecDeque<String>, }
#[allow(dead_code)]
impl Scanner {
    fn new() -> Scanner { Scanner { stdin: io::stdin(), buffer: VecDeque::new() } }
    fn reserve(&mut self) {
        while self.buffer.len() == 0 {
            let mut line = String::new();
            let _ = self.stdin.read_line(&mut line);
            for w in line.split_whitespace() {
                self.buffer.push_back(String::from(w));
            }
        }
    }
    fn cin<T: FromStr>(&mut self) -> T {
        self.reserve();
        match self.buffer.pop_front().unwrap().parse::<T>() {
            Ok(a) => a,
            Err(_) => panic!("parse err")
        }
    }
}


Measured memory_bytes: 16124
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<map>
#include<cmath>
#include<string>
#include<vector>
#include<set>
#include<queue>
#include<stack>
#include<iostream>
#include<algorithm>
using namespace std;
#define debug(x) cout << #x << " = " << x << endl
#define lowbit(x) (x & (-x))

typedef long long LL;
typedef pair<int, int>PII;
const int maxn = 1e5 + 10;
const int inf = 1e9 + 10;
LL d, ans, G;
int vis[15];

struct point{
	LL x, c, i;
	LL pos;
}num[15];

bool cmp(point a, point b)
{
	if(a.pos == b.pos) return a.x < b.x;
	return a.pos > b.pos;
}
void Dfs(LL x)
{
	if(G <= 0)
	{
		if(x) ans = min(ans, x);
		return;
	}
	for(int i = 1; i <= d; i++)
	{
		if(!vis[num[i].i])
		{
			LL ind = G / (num[i].i * 100);
			if(G % num[i].i) ind++;
			vis[num[i].i] = 1;
			G -= num[i].pos;
			Dfs(x + min(ind, num[i].x));
			vis[num[i].i] = 0;
			G += num[i].pos;
		}
	}
}
int main()
{
	scanf("%lld%lld", &d, &G);
	for(int i = 1; i <= d; i++)
	{
		scanf("%lld%lld", &num[i].x, &num[i].c);
		num[i].pos = num[i].x * 100 * i + num[i].c;
		num[i].i = i;
	}
	ans = inf;
	memset(vis, 0, sizeof(vis));
	Dfs(0);
	printf("%lld\n", ans);
	return 0;
}

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

#define PI 3.14159265
#define ll long long
#define hell 1e9
   
    
 
int main(){
	int n;
	cin>>n;
	int a[n];
	for(int i=0;i<n-1;i++){
		cin>>a[i];
	}
	int ans=0;
	for(int i=1;i<n-1;i++){
		ans+=min(a[i],a[i-1]);
	}
	ans+=a[0];
	ans+=a[n-2];
	cout<<ans;
	return 0;
}

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

int main(){
  long long x,a,b;
cin>>x>>a>>b;
 if(a-b>=0){
   cout<<"delicious"<<endl;
 }
  else if(a-b>=-1*x){
    cout<<"safe"<<endl;
  }
  else{
    cout<<"dangerous"<<endl;
  }
}


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

const long long maxn = 1e5 + 10 , inf = 2e18;
long long e , n , t , x[maxn] , dp[maxn] , p[maxn];

int main()
{
    cin >> n >> e >> t;
    for(int i=1 ; i<=n ; i++) cin >> x[i];
    dp[0] = 0; p[0] = dp[0] - 2*x[1];
    for(int i=1 ; i<=n ; i++)
    {
        int y = lower_bound(x,x+n , x[i]-(t/2))-x;
        dp[i] = (y <= 1 ? t : min(p[y-2] + 2*x[i] , dp[y-1] + t));
        p[i] = min(p[i-1] , dp[i] - 2*(x[i+1]));
    }
    cout << dp[n] + e;
}

Measured memory_bytes: 2688
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <vector>
#include <functional>
#include <queue>
#include <string>
#include <cstring>
#include <numeric>
#include <cstdlib>
#include <cmath>
#include <map>
#include <unordered_map>
#include <set>
using namespace std;

typedef long long ll;

#define INF 10e17
#define rep(i,n) for(long long i=0; i<n; i++)
#define repr(i,n,m) for(long long i=m; i<n; i++)
#define END cout << endl
#define MOD 1000000007
#define pb push_back
#define sorti(x) sort(x.begin(), x.end())
#define sortd(x) sort(x.begin(), x.end(), std::greater<long long>())
#define debug(x) std::cerr << (x) << std::endl;
#define roll(x) for (auto&& itr : x) { debug(itr); }

template <class T> inline void chmax(T &ans, T t) { if (t > ans) ans = t;}
template <class T> inline void chmin(T &ans, T t) { if (t < ans) ans = t;}

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

    int a, b;
    cin >> a >> b;

    if (b == 1) {
        cout << 0 << endl;
        return 0;
    }

    int kosuu = a;
    if (kosuu >= b) {
        cout << 1 << endl;
        return 0;
    }
    
    for (int i = 2; i < 10000; ++i) {
        kosuu += a - 1;
        if (kosuu >= b) {
            cout << i << endl;
            return 0;
        }
    }
}


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

K = int(readline())

cur = 0
mods = set()
cnt = 0
while True:
  cnt += 1
  
  cur *= 10
  cur += 7
  cur %= K
  if cur == 0:
    print(cnt)
    break
  if cur in mods:
    print(-1)
    break
  mods.add(cur)

Measured memory_bytes: 77964
#include <bits/stdc++.h>
using namespace std;
const long long MOD = 1000000007;
const long long INF = 1LL << 60;

long power(long a, long b) {
    return b ? power(a*a%MOD, b/2) * (b%2?a:1)%MOD:1;
}

long perm(int N, int K) {
    long x = 1;
    for(int i = 1; i <= K; i++) x = x * (N-i+1) % MOD;
    return x % MOD;
}

long comb(int N,int K) {
    long x = 1, y = 1;
    for(int i = 1; i <= K; i++) {
        x = x * (N-i+1) % MOD;
        y = y * i % MOD;
    }
    return x * power(y, MOD-2) % MOD;
}

bool isprime(int n) {
    if(n < 2) return false;
    for(int i = 2; i*i <= n; ++i) {
        if (n % i ==  0) return false;
    }
    return true;
}

void dfs(const vector<vector<int> > &G, int v, vector<int> &seen) {
    seen[v] = true;

    for(int next_v : G[v]) {
        if(seen[next_v]) continue;
        dfs(G, next_v, seen);
    }
}

void yes() { cout << "Yes" << endl;}
void no() { cout << "No" << endl;}

int main() {
  vector<int> price;
  int n, k, tmp, ans = 0;
  cin >> n >> k;
  for(int i=0;i<n;i++) {
    cin >> tmp;
    price.push_back(tmp); 
  }
  sort(price.begin(),price.end());
  for(int i = 0; i<k;i++) {
    ans += price[i];
  }
  cout << ans << endl;
}

Measured memory_bytes: 3624
import java.util.Scanner;

public class Main {


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


		for( ;scan.hasNext();){

			int height = scan.nextInt();
			int width = scan.nextInt();

			//			int height = Integer.parseInt(args[k]);
			//			int width = Integer.parseInt(args[k+1]);

			if(!(height == 0 && width ==0)){

				for(int i = 0;i<height;i++){
					for(int j=0;j < width; j++){
						System.out.print("#");
					}
					System.out.println("");
				}
				System.out.println("");
			}else{
				break;
			}
		}
	}
}



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

signed main(){
  vector<int> A(5);
  rep(i,5){
    cin>>A[i];
    if(A[i]==0){
      cout<<i+1<<endl;
      return 0;
    }
  }
}

Measured memory_bytes: 3588