akhauriyash/Code-Regression huggingface dataset:
#include <cstdio>
#include <cstdlib>
#include <iostream>
#include <string>
#include <cmath>
#include <algorithm>
#include <vector>
#include <queue>
#include <stack>
#include <map>
#include <set>
 
 
using namespace std;
typedef long long ll;
 
#define mod 100000
#define INF 2000000000
#define LLINF 4000000000000000000
#define SIZE 50010
 
// [M???][N???][??????=OI,J=0,1][???20???JO???][???,???]
// 20*20*3*(2^20)
int dp[2][2][1<<19]={0};
 
void dp_init(int k){
     
    for(int i=0;i<2;i++){
        for(int j=0;j<(1<<19);j++){
            dp[k][i][j]=0;
        }
    }
}
 
int main(){
    int M,N,ans=0,ans2;
    int af_j,af_i;
    char in[20][21];
    int mm[20][20];
     
    scanf("%d%d",&M,&N);
     
    for(int i=0;i<M;i++){
        scanf("%s",in[i]);
    }
     
    for(int i=0;i<M;i++){
        for(int j=0;j<N;j++){
            if(in[i][j]=='?')
                mm[i][j] = -1;
            if(in[i][j]=='J')
                mm[i][j] = 0;
            if(in[i][j]=='O')
                mm[i][j] = 1;
            if(in[i][j]=='I')
                mm[i][j] = 2;
                 
        }
    }
    for(int i=0;i<3;i++){
        if(mm[0][0] >= 0) if(i!=mm[0][0]) continue;
         
        dp[0][(i==0)][0]+=1;
    }
     
    for(int m=0;m<M;m++){
        for(int n=0;n<N;n++){
            ans2=0;
            if(m+n==0) continue;
             
            dp_init((m*N+n)%2);
             
            for(int i=0;i<2;i++){
                for(int j=0;j<(1<<(N-1));j++){
                     
                    for(int k=0;k<3;k++){
                         
                        if(mm[m][n] >= 0)
                            if(k!=mm[m][n]) continue;
                         
                        af_j =(j%(1<<(N-2)))*2;
                         
                        af_i = (k==0);
                         
                        if(i==1 && k==1) af_j+=1; //JO
                         
                        if((j>>(N-2))==1 && k==2 && n<N-1){
                            ans2 += dp[(m*N+n+1)%2][i][j];
                        }else{
                            dp[(m*N+n)%2][af_i][af_j] += dp[(m*N+n+1)%2][i][j];
                        }
                         
                        dp[(m*N+n)%2][af_i][af_j]%=mod;
                        ans2%=mod;
                    }
                }
            }
             
            if(mm[m][n]>=0) ans2+=ans;
            else ans2+=ans*3;
             
            ans=ans2%mod;
        }
    }
     
    printf("%d\n",ans);
     
    return 0;
}


Measured memory_bytes: 11420
import numpy as np
N, K = map(int,input().split())
H = np.array(list(map(int,input().split())))

if K >= N:
    print(0)
elif K == 0:
    answer = np.sum(H)
    print(answer)
else:
    ind = np.argpartition(H, -K)[-K:]
    top_k = H[ind]
    answer = np.sum(H) - np.sum(top_k)
    print(answer)

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

int main()
{
    int n;
    cin>>n;
    int A[n];
    int B[n+1];
    for(int i=1; i<=n; i++){
        B[i]=0;
    }
    for(int i=1; i<n; i++){
        cin>>A[i];
        B[A[i]]++;
    }
    for(int i=1; i<=n; i++){
        cout<<B[i]<<endl;
    }
}


Measured memory_bytes: 5160
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Vol0_39
{
    class Program
    {
        static void Main(string[] args)
        {
            // ??\????????????????????????????????¢????????¢??°??????????????????
            string sInput = "";

            // ??\??????????????????
            do
            {
                sInput = Console.ReadLine();
                if (sInput != null && sInput != "")
                {
                    // ?§????????????????
                    Stack<int> A_Figure = null;

                    A_Figure = changeAtoR(sInput);

                    Console.WriteLine("{0}", CalcStack(A_Figure));
                }
            } while (sInput != null && sInput != "");
        }

        static Stack<int> changeAtoR(string R)
        {
            Stack<int> A_Figure = new Stack<int>();


            for (int i = 0; i < R.Length; i++)
            {
                int tmp = 0;

                if (R[i] == 'I')
                {
                    tmp = 1;
                }
                else if (R[i] == 'V')
                {
                    tmp = 5;
                }
                else if (R[i] == 'X')
                {
                    tmp = 10;
                }
                else if (R[i] == 'L')
                {
                    tmp = 50;
                }
                else if (R[i] == 'C')
                {
                    tmp = 100;
                }
                else if (R[i] == 'D')
                {
                    tmp = 500;
                }
                else if (R[i] == 'M')
                {
                    tmp = 1000;
                }

                A_Figure.Push(tmp);    
            }

            return A_Figure;
        }

        static int CalcStack( Stack<int> iStack)
        {
            int iTotal = 0;
            int iOldValue = 0;
            foreach ( int tmp in iStack)
            {
                if (iOldValue == 0)
                {
                    iTotal = tmp;
                }
                else if(iOldValue > tmp)
                {
                    iTotal -= tmp;
                }
                else
                {
                    iTotal += tmp;
                }

                iOldValue = tmp;
            }
            return iTotal;
        }

    }
}

Measured memory_bytes: 9752
#include<stdio.h>
#include<math.h>
#include<string.h>
#include<stdlib.h>
#define ll long long
int ctoi(const char c){
  if('0' <= c && c <= '9') return (c-'0');
  return -1;
}
int main()
{
    ll A;
    char B[5];
    scanf("%lld%s",&A,&B);
    printf("%lld",(A*(ctoi(B[0])*100+ctoi(B[2])*10+ctoi(B[3])))/100);
    return 0;
}

Measured memory_bytes: 1736
from collections import deque

H,W=map(int,input().split())
S=[[c=='#' for c in input()] for _ in range(H)]

def bfs(i,j):
    if S[i][j]:
        return 0
    que=deque()
    que.append((i,j))
    vis=[row[:] for row in S]
    vis[i][j]=1
    ans=-1
    while que:
        ans+=1
        for _ in range(len(que)):
            i,j=que.popleft()
            for ni,nj in nbs(i,j):
                if not vis[ni][nj]:
                    que.append((ni,nj))
                    vis[ni][nj]=1
    return ans

def nbs(i,j):
    for ni,nj in (i-1,j),(i,j+1),(i+1,j),(i,j-1):
        if 0<=ni<H and 0<=nj<W:
            yield ni,nj

ans=0
for i in range(H):
    for j in range(W):
        ans=max(ans,bfs(i,j))

print(ans)


Measured memory_bytes: 9384
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner scan = new Scanner(System.in);
		long a = scan.nextLong();
		long b = scan.nextLong();
		long c = scan.nextLong();
		long d = scan.nextLong();
		scan.close();



		long max1 =a*c;
		long max2 =a*d;

		long max3 =b*c;
		long max4 =b*d;

		long max = Math.max(Math.max(max1,max2),Math.max(max3, max4));

		System.out.println(max);
	}
}

Measured memory_bytes: 27072
#include <bits/stdc++.h>
using namespace std;
int a,b,sum;
bool flag=true;
int main() {
    cin>>a;
    b=a;
    while(a>0)
    {
        
        sum=sum+a%10;
        a=a/10;
    }
    if(b%sum==0)
    {
        printf("Yes");
        
    }
    else
    {
        printf("No");
    }
}
    
    
    
       

Measured memory_bytes: 256
#include<iostream>

using namespace std;

int a, b;

void input(){
    cin >> a >> b;
}

/*
ans = a / 0.080
ans = b / 0.10
*/

int tmp1, tmp2;

int solve(){
    int ans = -1;
    for(int i = 0; i < 100000; ++i){
        if(i >= a / 0.08 && i < (a + 1) / 0.08){
            //cout << i << endl;
            //cout << b / 0.1 << endl;
            if(i >= b / 0.1 && i < (b + 1) / 0.1){
                ans = i;
                break;
            }
        }
        
    }
    
    return ans;
}

int main(){
    input();
    cout << solve() << endl;
}

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

int cnt = 0;
vector<int> v;

void insertionSort(int* A, int n, int g){
    for(int i=g; i<n; i++){
        int v = A[i];
        int j = i - g;
        while((j>=0)&&(A[j] > v)){
            A[j+g] = A[j];
            j = j-g;
            cnt++;
        }
        A[j+g] = v;
    }
}

void ShellSort(int* A, int n){
    cnt = 0;
    for(int i=v.size()-1; i>=0; i--){
        insertionSort(A, n, v[i]);
    }
}

int main(){

    int n;
    scanf("%d", &n);

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

    for(int i=0; 3*i+1 <= n; i=3*i+1){
        v.push_back(3*i+1);
    }
    
    printf("%ld\n", v.size());
    for(int i=v.size()-1; i>=0; i--){
        if(i==0) printf("%d\n", v[i]);
        else printf("%d ", v[i]);
    }

    ShellSort(A, n);

    printf("%d\n", cnt);
    for(int i=0; i<n; i++){
        printf("%d\n", A[i]);
    }
    return 0;
}


Measured memory_bytes: 6632
//#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
#define rep(i, n) for(int i=0; i<n; ++i)
#define all(v) v.begin(), v.end()
#define rall(v) v.rbegin(), v.rend()
using namespace std;
using ll = int64_t;
using ld = long double;
using P = pair<int, int>;
using vs = vector<string>;
using vi = vector<int>;
using vvi = vector<vi>;
template<class T> using PQ = priority_queue<T>;
template<class T> using PQG = priority_queue<T, vector<T>, greater<T> >;
const int INF = 100010001;
const ll LINF = (ll)INF*INF*10;
template<typename T1, typename T2>
istream &operator>>(istream &is, pair<T1, T2> &p) { return is >> p.first >> p.second;}
template<typename T1, typename T2>
ostream &operator<<(ostream &os, const pair<T1, T2> &p) { return os << p.first << ' ' << p.second;}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    int m, k;
    cin >> m >> k;
    if(m == 1) {
        if(k) cout << -1 << endl;
        else {
            cout << "0 0 1 1" << endl;
        }
    }
    else {
        if(k >= (1<<m)) {
            cout << -1 << endl;
        } else {
            rep(i, 1<<m) {
                if(i != k) cout << i << ' ';
            }
            cout << k << ' ';
            for(int i = (1<<m)-1; i >= 0; --i) {
                if(i != k) cout << i << ' ';
            }
            cout << k << '\n';
        }
    }
}

Measured memory_bytes: 3612
def solve():
    a, b = [int(i) for i in input().split()]

    for i in range(10**6):
        if int(i * 0.08) == a and int(i * 0.10) == b:
            print(i)
            return
    print(-1)
    return


if __name__ == "__main__":
    solve()

Measured memory_bytes: 3060
#include <iostream>
#include <cstdio>
#include <cmath>
#include <string>
#include <algorithm>

using namespace std;
typedef long long ll;

int main(){
  int a, b;cin>>a>>b;
  if(a>8||b>8){
    cout<<":("<<endl;
  }else{
    cout<<"Yay!"<<endl;
  }
}

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

#ifdef LOCAL
    #define eprintf(...) fprintf(stderr, __VA_ARGS__)
#else
    #define eprintf(...)
#endif

#define fast_io ios_base::sync_with_stdio(false); cin.tie(nullptr)
#define rep(i, x, y) for(decltype(y) i = (x) - ((x) > (y)); i != (y) - ((x) > (y)); i += 1 - 2 * ((x) > (y)))
#define trav(i,a) for(auto& (i) : (a))
#define all(a) (a).begin(),(a).end()
#define sz(a) int((a).size())
#define clr(a,x) memset((a),(x),sizeof(a)) // array (0,-1)
#define dbg(x) cerr << "STDERR => " << __LINE__ << ": " << #x << " = " << (x) << "  :(\n";
#define eb emplace_back
#define mp make_pair
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
inline void cpuTime() { cerr << "cpu time : " << double(clock())/CLOCKS_PER_SEC << "\n"; return; }
using ll = long long;
using ull = unsigned long long;
using F = float;
using D = double;
using vi = vector<int>;
using pii = pair<int,int>;



void solve(){

    int n;
    cin >> n;

    cout << n*n*n << "\n";
    return;
}

/*
 read the question carefully ( what're the exact constraints? )
 look out for SPECIAL CASES (n=1?) and OVERFLOW (ll vs int?) ARRAY OUT OF BOUNDS
 Check datatypes
*/
int main(){

    fast_io;
    int t=1;
    // cin >> t;

    while(t--){
        solve();
    }

    cpuTime();
return 0;
}


Measured memory_bytes: 256
A = list(input())
for i in range(len(A)//2):
  if A[i] == A[len(A)-i-1]:
    continue
  else:
    print('No')
    exit()
for k in range(len(A)//2//2):
  if A[k] == A[(len(A)-1)//2-k-1]:
    continue
  else:
    print('No')
    exit()
for l in range(len(A)//2//2):
  if A[(len(A)+3)//2+l-1] == A[len(A)-l-1]:
    continue
  else:
    print('Notice')
    exit()
print('Yes')

Measured memory_bytes: 3064
#include<bits/stdc++.h>
#define F first
#define S second
#define endl '\n'
#define lcm( a, b ) ((a)/__gcd(a,b)*(b))
#define MP make_pair
#define pb push_back
#define all(x) (x).begin(),(x).end()

using namespace std;

typedef long long LL;
typedef pair<int, int> P;
typedef pair<int, P> i_P;
typedef pair< LL, LL > L_P;

const int INF = INT_MAX;
const int MIN = INT_MIN;
const LL LINF = LLONG_MAX;
const int MOD = 1000000000 + 7;
const int SIZE = 100005;

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

    double w, h, x, y;
    cin >> w >> h >> x >> y;

    printf( "%.9lf ", w * h / 2 );
    if( w / 2 == x && h / 2 == y ) printf( "1\n" );
    else printf( "0\n" );

    return 0;
}



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

int main()
{
  int n;
  scanf("%d", &n);
  vector<int> dp(3);
  vector<int> new_dp(3);
  for(int i = 0; i < n; i++)
  {
    vector<int> v(3);
    for(int j = 0; j < 3; j++)
    {
      scanf("%d", &v[j]);
    }
    for(int x = 0; x < 3; x++)
    {
      for(int y = 0; y < 3; y++)
      {
        if(x != y)
        {
          new_dp[y] = max(new_dp[y], dp[x] + v[y]);
        }
      }
    }
    dp = new_dp;
  }
  printf("%d", max({dp[0], dp[1], dp[2]}));
  
  return 0;
}


Measured memory_bytes: 256
/* Author: Dhruv Rastogi */
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define int long long
#define all(sdk) sdk.begin(),sdk.end()
#define mll map<int, int>
#define pb push_back
#define rep(i,a,b) for(int i=a;i<b;++i)
#define repd(i,a,b) for(int i=a;i>=b;--i)
#define mp make_pair
#define hell 1000000007
#define endl '\n'
#define vvll vector<vector<int> >
#define vll vector<int>
#define mint map<int,int> 
#define sz(x) (int)x.size()
#define sll set<int>
#define pll pair<int,int>
#define F first
#define S second
const long double PI = acos(-1.0);

void solve(){  
	string s,t;
	cin>>s>>t;
	int cnt=0;
	rep(i,0,3){
		if(s[i]==t[i]) ++cnt;
	}  
	cout<<cnt<<endl;
}

signed main(){
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    int t=1;
    // cin>>t;
    while(t--){
        solve();
    }
    return 0;
}

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


class Program
{
    public static List<string> list = new List<string>();

    static void Main(string[] args)
    {
        // 入力
        //var s = Console.ReadLine();
        //var n = int.Parse(Console.ReadLine());
        int[] nmq = Console.ReadLine().Split().Select(int.Parse).ToArray();
        var n = nmq[0];
        var m = nmq[1];
        var q = nmq[2];

        int[] a = new int[q];
        int[] b = new int[q];
        int[] c = new int[q];
        int[] d = new int[q];
        for (int i = 0; i < q; i++)
        {
            int[] tmp = Console.ReadLine().Split().Select(int.Parse).ToArray();
            a[i] = tmp[0];
            b[i] = tmp[1];
            c[i] = tmp[2];
            d[i] = tmp[3];
        }

        long ans = 0;
        F(string.Empty, n, m, 0);
        foreach (var elem in list)
        {
            var tmp = 0;
            for (int i = 0; i < q; i++)
            {
                if ((int.Parse(elem[b[i] - 1].ToString()) + 1) - (int.Parse(elem[a[i] - 1].ToString()) + 1 )== c[i])
                {
                    tmp += d[i];
                }
            }
            ans = Math.Max(ans, tmp);
        }

        Console.WriteLine(ans);
    }

    static void F(string text, int n, int m, int depth)
    {
        if (depth == n)
        {
            list.Add(text);
        }
        else
        {
            ++depth;
            if ((text.Length == 0 || int.Parse(text[text.Length - 1].ToString()) == 0) && m > 0) F(text + '0', n, m, depth);
            if ((text.Length == 0 || int.Parse(text[text.Length - 1].ToString()) <= 1) && m > 1) F(text + '1', n, m, depth);
            if ((text.Length == 0 || int.Parse(text[text.Length - 1].ToString()) <= 2) && m > 2) F(text + '2', n, m, depth);
            if ((text.Length == 0 || int.Parse(text[text.Length - 1].ToString()) <= 3) && m > 3) F(text + '3', n, m, depth);
            if ((text.Length == 0 || int.Parse(text[text.Length - 1].ToString()) <= 4) && m > 4) F(text + '4', n, m, depth);
            if ((text.Length == 0 || int.Parse(text[text.Length - 1].ToString()) <= 5) && m > 5) F(text + '5', n, m, depth);
            if ((text.Length == 0 || int.Parse(text[text.Length - 1].ToString()) <= 6) && m > 6) F(text + '6', n, m, depth);
            if ((text.Length == 0 || int.Parse(text[text.Length - 1].ToString()) <= 7) && m > 7) F(text + '7', n, m, depth);
            if ((text.Length == 0 || int.Parse(text[text.Length - 1].ToString()) <= 8) && m > 8) F(text + '8', n, m, depth);
            if ((text.Length == 0 || int.Parse(text[text.Length - 1].ToString()) <= 9) && m > 9) F(text + '9', n, m, depth);
        }
    }
}


Measured memory_bytes: 47980
#include<iostream>
using namespace std;
int main()
{
  int n, a, b, c;
  cin >> n;
  a = n / 100;
  b = (n / 10) % 10;
  c = n % 10;
  if(a == 7 || b == 7 || c == 7)
  cout << "Yes";
  else
    cout << "No";
  return 0;
}

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

using namespace std;

const int MOD = 1000000007;

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

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int N;
  cin >> N;
  vector<int64_t> A(N);
  for (int i = 0; i < N; i++) {
    cin >> A[i];
  }
  int64_t res = 0;
  for (int b = 0; b < 61; b++) {
    int cnt = 0;
    for (int i = 0; i < N; i++) {
      if ((A[i] >> b) & 1) cnt++;
    }
    res += 1LL * (N - cnt) * cnt % MOD * modpow(2, b, MOD);
    res %= MOD;
  }
  cout << res << '\n';
  return 0;
}


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

int main() {
 int a,b,c;
  cin >> a >> b >> c;
  
  if(a+b+c < 22) {
  cout << "win";
  }
  else {
  cout << "bust";
  }
}


Measured memory_bytes: 3620
import java.util.*;

public class Main {
    public static void main(String args[]) {
        Scanner sc = new Scanner(System.in);
        int H = sc.nextInt();
        int W = sc.nextInt();
        int h = sc.nextInt();
        int w = sc.nextInt();
        boolean[][] map = new boolean[H][W];
        for(int i = 0; i < h; i++) {
            for(int j = 0; j < W; j++) {
                map[i][j] = true;
            }
        }
        for(int i = 0; i < w; i++) {
            for(int j = 0; j < H; j++) {
                map[j][i] = true;
            }
        }
        int ans = 0;
        for(int i = 0; i < H; i++) {
            for(int j = 0; j < W; j++) {
                if(!map[i][j]) ans++;
            }
        }
        System.out.println(ans);
    } 
}

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

int main(){
    int N,cnt=0;
    string S;
    cin >> N >> S;
    for (int i = 0; i < N; i++){
        if (S[i] == 'A' && S[i+1] == 'B' && S[i+2] == 'C' )cnt++;
    }
    cout << cnt << endl;

return 0;
}


Measured memory_bytes: 256
def func(c):
    global cnt
    cnt += {'_':0, '/':1, '\\':-1}[c]
    return cnt

cnt = 0
g = [[0, False]] + [[func(c), False] for c in input()]

gmax = g[0][0]
for i in range(1, len(g)):
    if g[i - 1][0] < g[i][0] <= gmax :
        g[i][1] = True
    gmax = max(gmax, g[i][0])

puddles = []
volume = 0
saface_level = None

for i in range(len(g) - 1, -1, -1):
    if saface_level != None:
        volume += saface_level  - g[i][0]
        if saface_level == g[i][0]:
            puddles += [volume]
            saface_level = None
            volume = 0
    if saface_level == None and g[i][1]:
        saface_level = g[i][0] 

puddles = puddles[::-1]
print(sum(puddles))
print(len(puddles), *puddles)

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

int main() {
    string s,t;
    cin >> s >> t;
    int N = 3001;
    vector<vector<int>> dp(N,vector<int>(N));
    for(int is=1;is<=s.size();is++) {
        for(int it=1;it<=t.size();it++) {
            dp[is][it]=max(dp[is-1][it],dp[is][it-1]);
            if (s[is-1]==t[it-1]) {
                dp[is][it]=max(dp[is][it], dp[is-1][it-1]+1);
            }
        }
    }
    string ans;
    int ps=s.size(),pt=t.size();
    int l=dp[ps][pt];
    while (l>0) {
        while (dp[ps-1][pt]==dp[ps][pt]) ps--;
        while (dp[ps][pt-1]==dp[ps][pt]) pt--;
        ans+=s[ps-1];
        ps--;
        pt--;
        l--;
    }
    reverse(ans.begin(),ans.end());
    std::cout << ans << '\n';
    return 0;
}


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

int main () {
  int a,b,y;
  double x;
  
  cin >> a >> b;
  x = (a+b)/2.0;
  y = x;
  if ((x - y) >= 0.5) {
    y = y + 1;
  }
  cout << y << endl;
}

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

#ifdef ENABLE_DEBUG
#define DEBUG(a) cerr<<#a<<"="<<a<<endl
#define DEBUG_ARRAY(a,n) cerr<<#a<<"["<<n<<"]="<<a[n]<<endl
#else
#define DEBUG(a) 
#define DEBUG_ARRAY(a,n) 
#endif
#define FOR(i, a, b) for(int i = a;i < b;i++)
#define For(i, a) FOR(i, 0, a)
#define REV(i, a, b) for(int i = b-1;i >= a;i--)
#define Rev(i, a) REV(i, 0, a)
#define REP(a) For(i, a)

typedef long long int ll;
typedef unsigned long long ull;
typedef unsigned int uint;
typedef pair<ll, ll> P;
typedef pair<ll,P> PP;
typedef vector<ll> vll;

const ll INF=(1LL<<50);

vector<ll> m[2000];
bool used[2000];

void solve(long long N, long long K, std::vector<long long> A, std::vector<long long> B){
    ll ans=INF;
    for(ll i = 0; i < N-1; i++)
    {
        m[A[i]].push_back(B[i]);
        m[B[i]].push_back(A[i]);
    }
    if(K%2==0){
        for(ll i = 0; i < N; i++)
        {
            DEBUG(i);
            ll num_used=0;
            queue<P> q;
            fill(used,used+2000,false);
            q.push(P(i,0));
            used[i]=true;
            num_used++;
            while(!q.empty()){
                P cur=q.front();q.pop();
                for(auto v:m[cur.first]){
                    if(used[v]==false&&cur.second<K/2){
                        used[v]=true;
                        num_used++;
                        q.push(P(v,cur.second+1));
                        DEBUG(v);
                    }
                }
            }
            ans=min(ans,N-num_used);
            DEBUG(N-num_used);
        }
    }else{
        for(ll i = 0; i < N-1; i++)
        {
            DEBUG(i);
            ll num_used=0;
            fill(used,used+2000,false);
            queue<PP> q;
            q.push(PP(0,P(A[i],B[i])));
            num_used++;
            while(!q.empty()){
                auto cur=q.front();q.pop();
                for(auto e:m[cur.second.first])
                {
                    if(e!=cur.second.second&&cur.first<(K-1)/2){
                        num_used++;
                        DEBUG(e);
                        q.push(PP(cur.first+1,P(e,cur.second.first)));
                    }
                }
                if(cur.second.first==A[i]&&cur.second.second==B[i]){
                    for(auto e:m[cur.second.second])
                    {
                        if(e!=cur.second.first&&cur.first<(K-1)/2){
                            num_used++;
                            DEBUG(e);
                            q.push(PP(cur.first+1,P(e,cur.second.second)));
                        }
                    }
                }
            }
            DEBUG(N-1-num_used);
            ans=min(ans,N-1-num_used);
        }
    }
    cout<<ans<<endl;
}

int main(){
    long long N;
    scanf("%lld",&N);
    long long K;
    scanf("%lld",&K);
    std::vector<long long> A(N-1);
    std::vector<long long> B(N-1);
    for(int i = 0 ; i < N-1 ; i++){
        scanf("%lld",&A[i]);
        scanf("%lld",&B[i]);
        A[i]--;
        B[i]--;
    }
    solve(N, K, std::move(A), std::move(B));
    return 0;
}


Measured memory_bytes: 384
# include <bits/stdc++.h>
using namespace std;
typedef long long LL;
LL a[200010];
int main()
{
    int n;
    LL sum = 0, sum2=0, ans=0x3f3f3f3f3f3f3f3f;
    scanf("%d",&n);
    for(int i=0; i<n; ++i)
        scanf("%lld",&a[i]), sum+=a[i];
    for(int i=0; i<n-1; ++i)
    {
        sum2 += a[i];
        ans = min(ans ,llabs(2*sum2-sum));
    }
    printf("%lld\n",ans);
    return 0;
}


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

N,M=(int(x) for x in input().rstrip('\n').split())
Hs = [int(x) for x in input().rstrip('\n').split()]
nums = [1 for x in Hs]
for i in range(M):
  roads = [int(x) for x in input().rstrip('\n').split()]
  if Hs[roads[0]-1] < Hs[roads[1]-1]:
    nums[roads[0]-1] = 0
  elif Hs[roads[0]-1] > Hs[roads[1]-1]:
    nums[roads[1]-1] = 0
  else:
    nums[roads[0]-1] = 0
    nums[roads[1]-1] = 0
print(sum(nums))

Measured memory_bytes: 20144
#!/usr/bin/env python
# -*- coding: utf-8 -*-

import sys


def merge(A, left, mid, right):
    global count

    L = A[left:mid] + [1e9]
    R = A[mid:right] + [1e9]

    i, j = 0, 0

    for k in range(left, right):
        count += 1
        if L[i] <= R[j]:
            A[k] = L[i]
            i += 1
        else:
            A[k] = R[j]
            j += 1

    return None


def merge_sort(A, left, right):
    if left + 1 < right:
        mid = (left + right) // 2
        merge_sort(A, left, mid)
        merge_sort(A, mid, right)
        merge(A, left, mid, right)


if __name__ == '__main__':
    _input = sys.stdin.readlines()
    array_length = int(_input[0])
    array = list(map(int, _input[1].split()))
    assert array_length == len(array)
    count = 0
    merge_sort(A=array, left=0, right=array_length)
    print(*array)
    print(count)

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

vector<ll>v;
ll ans=0;
void dfs(int n,ll sum,ll tmp){
    if(n==0){
        ans += sum + tmp;
        return;
    }
    dfs(n-1,sum,tmp*10+v.at(n-1));
    dfs(n-1,sum+tmp,v.at(n-1));
}

int main(){
    ll s,sum=0,tmp=0;
    cin >> s;
    int i=0;
    while(s>0){
        v.push_back(s%10);
        s/=10;
        i++;
    }
    dfs(i-1,sum,v.at(i-1));
    cout << ans << endl;
}

Measured memory_bytes: 256
/*
    B - 1 Dimensional World's Tale
    https://atcoder.jp/contests/abc110/tasks/abc110_b
*/
#include <bits/stdc++.h>
using namespace std;

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

    int n, m, x, y;
    cin >> n >> m >> x >> y;
    vector<int> xi(n);
    vector<int> yi(m);

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

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

    sort(xi.begin(), xi.end());
    sort(yi.begin(), yi.end());

    // x_N < Z <= y_M
    int x_max = xi.back();
    int y_min = yi.front();

    x_max = max(x_max, x);
    y_min = min(y_min, y);

    if (x_max < y_min) {
        cout << "No War" << endl;
    } else {
        cout << "War" << endl;
    }

    return 0;
}

Measured memory_bytes: 256
package main

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

var scanner = bufio.NewScanner(os.Stdin)

func nextString() string {
	scanner.Scan()
	return scanner.Text()
}

func nextInt() int {
	n, err := strconv.Atoi(nextString())
	if err != nil {
		fmt.Printf("strconv.Atoi failed: %v\n", err)
	}
	return n
}

func getCombinationTable(n, k, p int) [][]int {
	table := make([][]int, n+1)
	table[0] = make([]int, k+1)
	table[0][0] = 1
	for i := 1; i <= n; i++ {
		table[i] = make([]int, k+1)
		table[i][0] = 1
		for j := 1; j <= k; j++ {
			table[i][j] = (table[i-1][j] + table[i-1][j-1]) % p
		}
	}
	return table
}

func main() {
	scanner.Split(bufio.ScanWords)

	prime := 1000000000 + 7

	nBalls := nextInt()
	nBoxes := nextInt()

	if nBalls < nBoxes {
		fmt.Println(0)
	} else {
		table := getCombinationTable(nBalls-1, nBalls-nBoxes, prime)
		fmt.Println(table[nBalls-1][nBalls-nBoxes])
	}
}



Measured memory_bytes: 9696
from functools import reduce

n = int(input())
p = [2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41,43, 47, 53, 59, 61, 67,
     71, 73, 79, 83, 89, 97, 101, 103, 107, 109, 113, 127, 131, 137, 139, 149,
     151, 157, 163, 167, 173, 179, 181, 191, 193, 197, 199, 211, 223, 227, 229,
     233, 239, 241, 251, 257, 263, 269, 271, 277, 281, 283, 293, 307, 311, 313,
     317, 331, 337, 347, 349, 353, 359, 367, 373, 379, 383, 389, 397, 401, 409,
     419, 421, 431, 433, 439, 443, 449, 457, 461, 463, 467, 479, 487, 491, 499,
     503, 509, 521, 523, 541, 547, 557, 563, 569, 571, 577, 587, 593, 599, 601,
     607, 613, 617, 619, 631, 641, 643, 647, 653, 659, 661, 673, 677, 683, 691,
     701, 709, 719, 727, 733, 739, 743, 751, 757, 761, 769, 773, 787, 797, 809,
     811, 821, 823, 827, 829, 839, 853, 857, 859, 863, 877, 881, 883, 887, 907,
     911, 919, 929, 937, 941, 947, 953, 967, 971, 977, 983, 991, 997]
pp = []
for x in p:
    k = x
    c = 0
    while n // k:
        c += n // k
        k *= x
    pp.append(c + 1)
print(reduce(lambda x, y: x * y, pp)%(10**9+7))


Measured memory_bytes: 3956
#include<stdio.h>
double f(double a,double b,double c){return a*a+b*b+c*c;}
int main(){
  int n,m,i,j,k;
  double max=0,s=0,d[30][3];
  scanf("%d %d",&n,&m);//printf("%d %d\n",n,m);
  for(i=0;i<n;i++){//printf("%d\n",i);
    for(j=0;j<3;j++)scanf("%lf",&d[i][j]);
  }//printf("a\n");
  for(i=0;i<(1<<n);i++){//printf("%d\n",i);
    k=s=0;
    for(j=i;j;j/=2)k+=j%2;
    if(k-m)continue;
    for(j=s=0;j<n;j++){
      if((i&(1<<j))==0)continue;
      for(k=0;k<j;k++){
	if((i&(1<<k))==0)continue;
	s+=f(d[j][0]-d[k][0],d[j][1]-d[k][1],d[j][2]-d[k][2]);
      }
    }
    if(s>max)max=s;
  }
  printf("%f\n",max);
  return 0;
}
    

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

using namespace std; 

int main()
{
	int x , y ;
	scanf("%d%d" , &x , &y) ;
	if ( y >= 2*x && y % 2 == 0 && 4 * x >= y ) puts("Yes") ;
	else puts("No") ;
	return 0 ;
}

Measured memory_bytes: 3652
let rec f a b = if b = 0 then a else f b (a mod b)
let n, m, s, t, l = Scanf.scanf "%d %d %s %s" @@ fun n m s t -> n, m, s, t, n / f n m * m
let d1, d2 = l / m, l / n
let _ = for i = 0 to min ((n - 1) / d1) ((m - 1) / d2) do if s.[i * d1] <> t.[i * d2] then (print_endline "-1"; exit 0) done; Printf.printf "%d\n" l

Measured memory_bytes: 2688
#include <stdio.h>

#define N_MAX 100000
#define Q_MAX 50000

int main(){
  int n,q,i,j;
  int S[N_MAX];
  int T[Q_MAX];
  int left,right,mid;
  int cont=0;

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

  //----------------
  for(i=0; i<q; i++){
    left=0;
    right=n;
    while(left<right){
      mid=(left+right)/2;
      if(S[mid]==T[i]){
	cont++;
	break;
      }else if(T[i]<S[mid]){
	right = mid;
      }else left = mid+1;
    }
  }

  printf("%d\n",cont);
  return 0;
}



Measured memory_bytes: 2320
n,m=map(int, input().split())
a=[list(map(int,input().split())) for i in range(n)]
count=0
for i in range(1,m+1):
  check=True
  for j in range(n):
    if i not in a[j][1:]:
      check=False
  if check:
    count+=1
print(count)

Measured memory_bytes: 9088
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(int)n;i++)
#define rep1(i,n) for(int i=1;i<=(int)n;i++)
#define sp(n) cout << fixed << setprecision(n)
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
typedef long long ll;
using namespace std;
int main(void){
    string s;cin>>s;
    string t="keyence";
    rep(i,8){
        string f1=s.substr(0,i),f2=s.substr(s.size()-7+i,7-i);
        string f=f1+f2;
        //cout<<f<<endl;
        if(f==t){
            cout<<"YES"<<endl;
            return 0;
        }
    }
    cout<<"NO"<<endl;
}


Measured memory_bytes: 3520
#include <iostream>
#include <string>
#include <algorithm>
#include <functional>
#include <vector>
#include <stack>
#include <queue>
#include <deque>
#include <set>
#include <map>
#include <cstdio>
#include <cmath>
#include <tuple>
#include <iomanip>
#include <numeric>
#include <unordered_map>
#include <sstream>
#include<limits.h>
#include<float.h>
#include<list>
#include <array>
#include <complex>
#include<stdio.h>
#include<string.h>
#include <bitset>

using namespace std;
#define int long long

#define I32_MAX 2147483647
#define I64_MAX 9223372036854775807LL
#define I64_MAX2 1223372036854775807LL
#define INF I64_MAX2
#define MOD 1000000007
#define MEM_SIZE 10000
#define DEBUG_OUT true
#define ALL(x) (x).begin(), (x).end()

template<typename T> void DEBUG(T e){if(DEBUG_OUT == false)return; std::cout << e <<" ";}
template<typename T> void DEBUG(const std::vector<T>& v){if(DEBUG_OUT == false)return;for(const auto& e : v){std::cout<< e << " "; } std::cout << std::endl;}
template<typename T> void DEBUG(const std::vector<std::vector<T> >& vv){if(DEBUG_OUT == false)return;for(const auto& v : vv){ DEBUG(v); } }
template<class T,class... Ts> void DEBUG(T d, Ts... e){if(DEBUG_OUT == false)return;DEBUG(d);DEBUG(e...);}
template <class T> void corner(bool flg, T hoge) {if (flg) {cout << hoge << endl; abort();}}
template< typename T1, typename T2 > inline bool chmax(T1 &a, T2 b) { return a < b && (a = b, true); }
template< typename T1, typename T2 > inline bool chmin(T1 &a, T2 b) { return a > b && (a = b, true); }
//SOLVE
//-----CODE------//
class DisjointSet{
  public:
  vector<int> rank,p;
  DisjointSet(){}
  DisjointSet(int size)
  {
    rank.resize(size,0);
    p.resize(size,0);
    for (int i = 0; i < size; i++)
    {
      makeSet(i);
    }
  }
void makeSet(int x)
{
  p[x] = x;
  rank[x] = 0;
}

bool same(int x, int y)
{
  return findSet(x) == findSet(y);
}

void unite(int x, int y)
{
  link(findSet(x),findSet(y));
}
void link(int x, int y)
{
  if(rank[x] > rank[y])
  {
    p[y] = p[x];
  }
  else
  {
    p[x] = p[y];
  }
  if(rank[x] == rank[y])
  {
    rank[y]++;
  }
}
  int findSet(int x)
  {
    if(x != p[x])
    {
      p[x] = findSet(p[x]);
    }
    return p[x];
  }
};

void solve (void)
{
  int N,M;cin>>N>>M;
  DisjointSet DS(N+M);
  for (int i = 0; i < N; i++)
  {
    int K;cin>>K;
    for (int k = 0; k < K; k++)
    {
      int L;cin>>L;
      L--;
      DS.unite(i,N+L);
    }
  }
  int check = 1;
  for (int i = 0; i < N-1; i++)
  {
    if(!DS.same(i,i+1))check = 0;
  }
  if(check)
  {
    cout<<"YES"<<endl;
  }
  else
  {
    cout<<"NO"<<endl;
  }
  
  
  
  
  return;
}
int32_t main(int32_t argc, const char *argv[])
{
  std::ios::sync_with_stdio(false);
  std::cin.tie(0);

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

  return 0;
}


Measured memory_bytes: 3456
#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() {
  int n, p;
  cin >> n >> p;
  vector<int> a(n);
  rep(i, n) cin >> a[i];

  int m1 = 0;
  rep(i, n) if (a[i] % 2 == 1) ++m1;
  ll ans;
  if (m1 > 0) ans = pow(2LL, n-1);
  else if (p == 0) ans = pow(2LL, n);
  else ans = 0;
  cout << ans << endl;

  return 0;
}

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

int main()
{
 int k;
 cin>>k;
  string S =  "ACL";
  string R;
  for(int i=1;i<=k;i++)
  {
    R = R + S;
  }
  cout<<R<<endl;
  return 0;
}

Measured memory_bytes: 3508
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<n;i++)
#define REP(i,n) for(int i=1;i<=n;i++)
#define int long long
#define ll long long
#define eps LDBL_EPSILON
#define mod (int)998244353
#define INF LLONG_MAX/10
#define P pair<int,int>
#define prique(T) priority_queue<T,vector<T>,greater<T>>
#define all(V) V.begin(),V.end()
template <class T, class U>
inline bool chmax(T& lhs, const U& rhs) {
	if (lhs < rhs) {
		lhs = rhs;
		return 1;
	}
	return 0;
}
template <class T, class U>
inline bool chmin(T& lhs, const U& rhs) {
	if (lhs > rhs) {
		lhs = rhs;
		return 1;
	}
	return 0;
}
using namespace std;
template<int m>
int modpow(int a, int b){
	if (!b)return 1;
	if (b & 1)return modpow<mod>(a, b - 1) * a % m;
	int memo = modpow<mod>(a, b / 2);
	return memo * memo % m;
}
template<int modulo>
class modInt {
	int value;
public:
	constexpr modInt() : value(0) { value = 0; }
	template<typename T>
	constexpr modInt(T value = 0) : value(value) {
		this->value = value % modulo;
	}
	inline constexpr operator int()const { return value; }
	inline constexpr modInt& operator+=(modInt x) {
		value += x.value;
		if (value >= modulo)value -= modulo;
		return *this;
	}
	inline constexpr modInt& operator++() {
		if (value == modulo - 1)value = 0;
		else value++;
		return *this;
	}
	inline constexpr modInt& operator-()const {
		return modInt(0) -= *this;
	}
	inline constexpr modInt& operator-=(modInt x) {
		value -= x.value;
		if (value < 0)value += modulo;
		return *this;
	}
	inline constexpr modInt& operator--() {
		if (value == 0)value = modulo - 1;
		else value--;
		return *this;
	}
	inline constexpr modInt& operator*=(modInt x) {
		value = value * x.value % modulo;
		return *this;
	}
	inline modInt& operator/=(modInt x) {
		return operator*=(x.inv());
	}
	inline modInt inv() {
		return modpow(*this, modulo - 2);
	}
	template<typename T> modInt operator+(T x) { return modInt(*this) += x; }
	template<typename T> modInt& operator+=(T x) { return operator+=(modInt(x)); }
	template<typename T> modInt operator-(T x) { return modInt(*this) -= x; }
	template<typename T> modInt& operator-=(T x) { return operator-=(modInt(x)); }
	template<typename T> modInt operator*(T x) { return modInt(*this) *= x; }
	template<typename T> modInt& operator*=(T x) { return operator*=(modInt(x)); }
	template<typename T> modInt operator/(T x) { return modInt(*this) /= x; }
	template<typename T> modInt& operator/=(T x) { return operator/=(modInt(x)); }
};
istream& operator>>(istream& ist, modInt<mod>& x) {
	int a;
	ist >> a;
	x = a;
	return ist;
}
modInt<mod> modpow(modInt<mod> a, int b) {
	if (!b)return modInt<mod>(1);
	if (b & 1)return modpow(a, b - 1) * a;
	modInt<mod> memo = modpow(a, b / 2);
	return memo * memo;
}
int n, r[2010];
string s;
modInt<mod> dp[4010][4010];
signed main() {
	cin >> s;
	n = s.size();
	rep(i, n) {
		r[i] = 2 - (s[i] - '0');
		if (i)r[i] += r[i - 1];
	}
	dp[0][0] = 1;
	rep(i, 2 * n) {
		rep(j, 2 * n + 1) {
			if (i + 1 - j <= 2 * min(n, i + 1) - r[min(n - 1, i)])dp[i + 1][j] += dp[i][j];
			if (j + 1 <= r[min(n - 1, i)])dp[i + 1][j + 1] += dp[i][j];
		}
	}
	cout << dp[2 * n][r[n - 1]] << endl;
	return 0;
}

Measured memory_bytes: 125568
#include<iostream>
#include<string.h>
#define rep(i,n) for(i = 0;i < n;i++)
using namespace std;

int main()
{
	char s1[5],s2[5];
	int i,j;
	while( cin >> s1 >> s2 )
	{
		bool flag[4] = {false};
		int hit = 0,blow = 0;
		if( strlen(s1) == 1 && strlen(s2) == 1 )
			break;
		rep(i,4){
			if( s1[i] == s2[i] ){
				hit++;
				flag[i] = true;
			}
		}
		rep(i,4){
			if( flag[i] )continue;
			rep(j,4){
				if( i == j )continue;
				if( s1[i] == s2[j] ){
					blow++;
					break;
				}
			}
		}
		cout << hit << " " << blow << endl;
	}
	return 0;
}

Measured memory_bytes: 1140
#include <time.h>

#include <stdlib.h>
#include <cstdint>
#include <cassert>
#include <algorithm>
#include <functional>
#include <iostream>
#include <limits>
#include <cstdint>
#include <cassert>
#include <algorithm>
#include <functional>
#include <iostream>
#include <limits>
#include <vector>
#include <map>
#include <set>
#include <iomanip>
#include <numeric>
#include <cmath>
#include <bitset>
#include <iterator>
#include <deque>
#include <string>
#include <queue>
#include <omp.h>
#include <fstream>   // ifstream, ofstream
typedef int64_t ll;
using namespace std;
const ll INF=1e10;
const double EPS=1e-8;
const ll mod = 1000000007;
int main(){
	ll n;
	cin>>n;
	vector<ll> a;
	for(ll i1=0;i1<n;i1++){
		ll temp;
		cin>>temp;
		a.push_back(temp);
	}
	multiset<ll> current_situation;
	current_situation.insert(a[0]);
	for(ll i1=1;i1<n;i1++){
		auto iter = current_situation.lower_bound(a[i1]);
		if(iter==current_situation.begin()){
			current_situation.insert(a[i1]);
		}else{
			--iter;
			current_situation.erase(iter);
			current_situation.insert(a[i1]);
		}
	}
	cout<<current_situation.size()<<endl;
}


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

#define ll long long
ll ep=1000000007;
ll n,m;
char cost[1005][1005];
ll dp[1005][1005];
int main(){
    cin>>n>>m;
    //memset(cost,0,sizeof(cost));
    for(ll i=0;i<n;i++){
        for(ll j=0;j<m;j++){
            cin>>cost[i][j];
        }
    }
    memset(dp,0,sizeof(dp));
    for(ll i=1;i<m;i++){
        if(cost[0][i]=='#'){
            break;
        }
        dp[0][i]=1;
    }
    for(ll j=1;j<n;j++){
        if(cost[j][0]=='#'){
            break;
        }
        dp[j][0]=1;
    }
    for(ll i=0;i<n;i++){
        for(ll j=0;j<m;j++){
            if(i!=0 && j!=0){
                if(cost[i][j]=='#'){continue;}
                dp[i][j]=(dp[i][j-1]+dp[i-1][j])%ep;
            }
        }
    }
    
    cout<<dp[n-1][m-1]<<endl;

    return 0;
}

Measured memory_bytes: 9088
#include <stdio.h>
#include <stdlib.h>

void prarr(long long int*A,int N){
  int i;
  for(i=0;i<N;i++){
    printf("%lld ",A[i]);
  }
}

long long int max(long long int A,long long int B,long long int C){
  if(B>A){A=B;}
  if(C>A){A=C;}
  return A;
}

void mkmax(long long int*A,long long int *Am,int N){
  int i;
  Am[0]=0;
  for(i=1;i<N+1;i++){
    if(A[i]>Am[i-1]){
      Am[i]=A[i];
    }else{
      Am[i]=Am[i-1];
    }
  }
}

int main(){
  int N,i;
  long long int C;
  scanf("%d%lld",&N,&C);

  long long int x[N+1];
  long long int y[N+1];
  long long int v[N+1];

  for(i=1;i<=N;i++){
    scanf("%lld%lld",&x[i],&v[i]);
  }
  for(i=1;i<=N;i++){
    y[i]=C-x[N+1-i];
  }
  
  long long int A[N+1];
  long long int B[N+1];
  long long int Am[N+1];
  long long int Bm[N+1];

  A[0]=0;
  B[0]=0;
  x[0]=0;
  y[0]=0;
  v[0]=0;
  for(i=1;i<=N;i++){
    A[i]=A[i-1]+v[i]-(x[i]-x[i-1]);
    B[i]=B[i-1]+v[N+1-i]-(y[i]-y[i-1]);
  }

  mkmax(A,Am,N);
  mkmax(B,Bm,N);
  
  long long int cal=0;
  for(i=0;i<N;i++){
    cal=max(cal,B[i]-y[i]+Am[N-i],A[i]-x[i]+Bm[N-i]);
  }
  printf("%lld",cal);
  return 0;
}
  
    
  
  


Measured memory_bytes: 5632
#include<stdio.h>

int main(void){
	int N, K, i, n = 1;
/*操作回数*/
	do{
		scanf("%d", &N);
	}while(N < 1 || N > 10);
/*操作Bで足す数*/
	do{
		scanf("%d", &K);
	}while(K < 1 || K > 10);
/*計算*/
	for (i = 0; i < N; i++){
		if (n < K)	n *= 2;
		else	n += K;
	}

	printf("%d\n", n);

	return 0;
}

Measured memory_bytes: 128
#include<bits/stdc++.h>
#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> d(n);
	rep(i, n)
		cin >> d[i];
	int ans = 0;
	for (int i = 0; i < n; i++) {
		for (int j = i + 1; j < n; j++) {
			ans += d[i] * d[j];
		}
	}
	cout << ans << endl;
}








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

using namespace std;

int main() {
    int N, count{};
    vector<int> a;
    bool done;
    cin >> N;
    
    for (int i {0}; i < N; i++) {
        int A{};
        cin >> A;
        a.push_back(A);
    }
    
    for (int j {1}; j < N; j++) {
        int pre_val = a.at(j-1);
        if (pre_val == a.at(j) && !done) {
            count++;
            done = true;
        } else {
            done = false;
        }
    }
    cout << count << endl;
    
    return 0;
}

Measured memory_bytes: 256
import sys

sys.setrecursionlimit(1000000)
input = lambda: sys.stdin.readline().rstrip()

N = int(input())

cnt = 0
for A in range(1, N + 1):
    last_digit = A % 10
    if last_digit == 0:
        continue
    first_digit = int(list(str(A))[0])
    for l in range(1, 7):
        if l == 1:
            if last_digit == first_digit:
                cnt += 1
        elif l < len(str(N)):
            cnt += 10 ** (l - 2)
        elif len(str(N)) == l:
            if last_digit < int(list(str(N))[0]):
                cnt += 10 ** (l - 2)
            elif last_digit == int(list(str(N))[0]):
                maybe, ok = 1, 0
                for j in range(1, l - 1):
                    ok = ok * 10 + maybe * int(list(str(N))[j])
                if first_digit <= N % 10:
                    ok += maybe
                cnt += ok
print(cnt)
                        
                        
                        

        
    

Measured memory_bytes: 43244
import java.io.*;

class Main{
        static boolean isPrime(int r){
                if(r<2)
                        return false;
                else if(r == 2)
                        return true;
                else if(r%2 ==0)
                        return false;
                for(int i=3; i*i<=r; i+=2)
                        if(r%i == 0)
                                return false;
                return true;
        }

        public static void main(String[] args) throws IOException{
                BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
                int N = Integer.parseInt(br.readLine());
                int i = 0;
                int count = 0;
                boolean isPrime = false;
                while(i<N){
                        int r = Integer.parseInt(br.readLine());
                        if(isPrime(r))
                                count++;
                        i++;
                }
                System.out.println(count);
        }
}

Measured memory_bytes: 29320
n = gets.to_i
s = gets.chomp
s_orig = s.dup

0.upto(n-1) do |i|
    if s[i] == "("
        if idx = s[i+1...n].index(")")
            s[i] = "_"
            s[idx+i+1] = "_"
        end
    end
end

n_unmatched_left = 0
n_unmatched_right = 0

0.upto(n-1) do |i|
    if s[i] == "("
        n_unmatched_left += 1
    elsif s[i] == ")"
        n_unmatched_right += 1
    end
end

s_out = "(" * n_unmatched_right + s_orig + ")" * n_unmatched_left
puts s_out


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

int n;
ll a[100009], b[100009];
ll ans;

int main(){
    scanf("%d", &n);
    for(int i = 1; i <= n + 1; i++){
        scanf("%lld", &a[i]);
    }
    for(int i = 1; i <= n; i++){
        scanf("%lld", &b[i]);
    }
    for(int i = 1; i <= n + 1; i++){
        if(b[i - 1] > 0 && a[i] > 0){
            int k = min(a[i], b[i - 1]);
            ans += k;
            a[i] -= k;
            b[i - 1] -= k;
        }
        if(b[i] > 0 && a[i] > 0){
            int k = min(a[i], b[i]);
            ans += k;
            a[i] -= k;
            b[i] -= k;
        }
    }
    printf("%lld\n", ans);
    return 0;
}

Measured memory_bytes: 1792
import java.io.IOException;
import java.io.BufferedReader;
import java.io.InputStreamReader;

public class Main {
    static int[] A = new int[100000];
    static void update(int i, int x){
        A[i] = x;
    }
    
    static void find(int s, int t){
        int min = Integer.MAX_VALUE;
        for (int i = s; i < t + 1; i++){
            if (A[i] < min){
                min = A[i];
            }
        }
        System.out.println(min);
    }
    public static void main(String[] args) throws IOException {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        String[] line = br.readLine().split(" ");
        int n = Integer.parseInt(line[0]);
        int q = Integer.parseInt(line[1]);
        for (int j = 0; j < 100000; j++){
            A[j] = Integer.MAX_VALUE;
        }
        for (int i = 0; i < q; i++){
            String[] ln = br.readLine().split(" ");
            int com = Integer.parseInt(ln[0]);
            int x = Integer.parseInt(ln[1]);
            int y = Integer.parseInt(ln[2]);
            if (com == 0){
                update(x,y);
            }else{
                find(x,y);
            }
        }
    }
}    

Measured memory_bytes: 64620