akhauriyash/Code-Regression huggingface dataset:
n,k = gets.chomp.split.collect{ |item| item.to_i}
s = "R"
s += gets.chomp
s += "L"
 
ans = n
badn = 0
1.upto(n) do |i|
  if(s[i] == "R")
  	badn += 1 if ("L" == s[i+1])
  else
    badn += 1 if ("R" == s[i-1])
  end
end
ans -= [1,(badn - 2*k)].max
 
puts ans

Measured memory_bytes: 2172
import java.util.Scanner;

class Main{
	public static void main(String[] args) {

		Scanner sc=new Scanner(System.in);
		String S=sc.next();
		String T=sc.next();
		int[] start=new int[26];
		int[] goal=new int[26];		//変換テーブル
		for(int i=0; i<26; i++) {
			start[i]=-1;
			goal[i]=-1;
		}

		for(int i=0; i<S.length(); i++) {
			int a=S.charAt(i)-'a';
			int b=T.charAt(i)-'a';
			if(start[a]!=-1 || goal[b]!=-1) {
				if(start[a]!=b || goal[b]!=a) {		//変換テーブル通りならよい
					System.out.println("No");
					System.exit(0);
				}
			}
			else {
				start[a]=b;
				goal[b]=a;
			}
		}
		System.out.println("Yes");
	}
}

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

namespace Atcoder
{
    class Program
    {
        static void Main(string[] args)
        {
            //var input = Console.ReadLine().Split(' ').Select(x => int.Parse(x)).ToArray();
            var input = Console.ReadLine().ToCharArray();
            var year = new char[] { input[0], input[1], input[2], input[3] };
            var mon = new char[] { input[5], input[6] };
            var day = new char[] { input[8], input[9] };
            string y = string.Join("", year);
            string m = string.Join("", mon);
            string d = string.Join("", day);
            int y_int = int.Parse(y);
            int m_int = int.Parse(m);
            int d_int = int.Parse(d);

            if (y_int >= 2019)
            {
                if (m_int >= 5)
                {
                    Console.WriteLine("TBD");
                }
                else
                {
                    Console.WriteLine("Heisei");
                }
            }
            else
            {
                Console.WriteLine("Heisei");
            }
        }
    }
}

Measured memory_bytes: 11220
def getN():
    return int(input())
def getNM():
    return list(map(int, input().split()))
def getList():
    return list(map(int, input().split()))

n,m = getNM()
stores = []
for i in range(n):
    stores.append(getNM())

stores.sort()
ans = 0
for store in stores:
    if m <= store[1]:
        ans += store[0]* m
        break
    else:
        ans += store[0]*store[1]
        m -= store[1]


print(ans)

Measured memory_bytes: 27884
#include <cstdio>
#include <string.h>
using namespace std;

typedef struct {
	char c;
	int num;
} C_NUM;

char str[2000000];
C_NUM c_num[2000000];

int main()
{
	scanf("%s", str);
	int len = strlen(str);
	
	int j = 0;
	for (int i = 0; i < len; i++){
		if (j == 0 || str[i] != c_num[j - 1].c){
			c_num[j].c = str[i];
			c_num[j].num = 1;
			j++;
		}
		else if (str[i] == c_num[j - 1].c){
			c_num[j - 1].num++;
		}
	}
	
	int max_k = 0;
	for (int i = 0; i < j; i++){
//		printf("%c %d\n", c_num[i].c, c_num[i].num);
		if (c_num[i].c == 'O'){
			if (
			(c_num[i - 1].c == 'J' && c_num[i - 1].num >= c_num[i].num) &&
			(c_num[i + 1].c == 'I' && c_num[i + 1].num >= c_num[i].num) &&
			(max_k < c_num[i].num)
			){
				max_k = c_num[i].num;
			}
		}
	}
	
	printf("%d\n", max_k);
}

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

#define ALL(v) (v).begin(), (v).end()
#define rep(i, l, r) for (int i = (l); i < (r); ++i)
typedef long long ll;

void solve()
{
    int n;
    cin >> n;
    if (n & 1)
        cout << n / 2 + 1 << endl;
    else
        cout << n / 2 << endl;
}

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





Measured memory_bytes: 3568
#include <cstdio>
#include<iostream>
#include<map>
#include<algorithm>
#include<vector>
#include <cmath>
#include <iomanip>
#include <regex>
#include <queue>
#include <set>
using namespace std;
using ll = long long;
using Lf = long double;
using plong = pair<ll,ll>;
const int mod = 1000000007;
int main(){
    ll N,A,B;
    cin>>N>>A>>B;
    if((B-A)%2==0){
        cout<<(B-A)/2<<endl;
    }else{
        cout<<min(A-1,N-B)+1+(B-A-1)/2<<endl;
    }
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define rep(i, n) for (int i = 0; i < n; i++)
#include <math.h> /* M_PI */
int main()
{
    int s, w;
    cin >> s >> w;
    if (w >= s)
    {
        cout << "unsafe";
    }
    else
    {
        cout << "safe";
    }
}


Measured memory_bytes: 3636
// Author: πα

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

int main()
{
    int s, n, d;
    cin >> s >> n;
    while(n--)
        cin >> d, s -= d;
    cout << (s > 0 ? "No" : "Yes");
    return 0;
}


Measured memory_bytes: 256
import java.util.*;

public class Main {
	static char ch[][]=new char[9][9];
	static void check(int[][] bord){
		Set<Integer> s=new TreeSet<Integer>();
		//yoko
		for(int i=0;i<9;i++){
			s.clear();
			for(int j=0;j<9;j++){
				if(!s.add(bord[i][j])){
					//被りを見つけた時の処理
					for(int k=0;k<9;k++){
						if(bord[i][j]==bord[i][k]){
							ch[i][k]='*';
						}
					}
				}
			}
		}
		//tate
		for(int j=0;j<9;j++){
			s.clear();
			for(int i=0;i<9;i++){
				if(!s.add(bord[i][j])){
					//被りを見つけた時の処理
					for(int k=0;k<9;k++){
						if(bord[i][j]==bord[k][j]){
							ch[k][j]='*';
						}
					}
				}
			}
		}
		//3*3
		for(int i=0;i<9;i+=3){
			for(int j=0;j<9;j+=3){
				check2(bord,i,j);
			}
		}
	}
	static void check2(int[][] bord,int x,int y){
		Set<Integer> s=new TreeSet<Integer>();
		for(int i=y;i<y+3;i++){
			for(int j=x;j<x+3;j++){
				if(!s.add(bord[i][j])){
					for(int k=y;k<y+3;k++){
						for(int l=x;l<x+3;l++){
							if(bord[i][j]==bord[k][l]){
								ch[k][l]='*';
							}
						}
					}
				}
			}
		}
	}
	public static void main(String[] args) {
		Scanner sc=new Scanner(System.in);
		int n=sc.nextInt();
		int bord[][]=new int[9][9];
		while(n--!=0){
			for(int i=0;i<9;i++){
				for(int j=0;j<9;j++){
					bord[i][j]=sc.nextInt();
				}
			}
			for(int j=0;j<9;j++){
				Arrays.fill(ch[j],' ');
			}
			check(bord);
			for(int i=0;i<9;i++){
				for(int j=0;j<9;j++){
					System.out.print(ch[i][j]+""+bord[i][j]);
				}
				System.out.println();
			}
			if(n!=0) System.out.println();
		}
	}

}

Measured memory_bytes: 13000
#include <iostream>
#include <math.h>
 
using namespace std;
 
int main() {
    long long int x;
    cin>>x;
    long long int P = 100;
    int time=0;
    while(P<x){
        P += P/100;
        time++;
    }
    
    cout<<time<<endl;
}

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

int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    int N, K;
    cin >> N >> K;
    vector<int> A(N);
    for(int i=0; i<N; i++) cin >> A[i];

    int l = 0, r = 1e9;
    while(r - l > 1)
    {
        int cnt = 0;
        int mid = (l + r) / 2;
        for(int i=0; i<N; i++)
        {
            cnt += (A[i] - 1) / mid;
        }
        if(cnt <= K)
        {
            r = mid;
        }
        else
        {
            l = mid;
        }
    }

    cout << r << endl;

    return 0;
}


Measured memory_bytes: 3984
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
#define INF 100000000
#define rep(i,s,n) for (int i = (int)(s); i < (int)(n); i++)
#define mp make_pair
ll mod = 1000000007;
ll mod2 = 998244353;

int main(){
	ll n;cin>>n;
    int cnt = 0;
    ll x = n;
    ll num = 26;
    ll sum = 0;
    while (x>0){
        x-=num;
        if (x>0) sum+=num;
        num*=26;
        cnt+=1;
    }
    x = n-sum-1;
    string ans = "";
    rep(i,0,cnt){
        int a = x%26;
        char z = 'a'+a;
        ans = z + ans;
        x = (x-a)/26;
    }
    cout<<ans<<endl;
}

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

using namespace std;

using ll = long long;

int main() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    int n, m;
    cin >> n >> m;
    vector<int> a(n);
    int sum = 0;
    for (int i = 0; i < n; ++i) {
        cin >> a[i];
        sum += a[i];
    }

    int cnt = 0;
    for (int i = 0; i < n; ++i) {
        cnt += (a[i] * 4 * m >= sum);
    }
    cout << (cnt >= m ? "Yes" : "No") << "\n";
    return 0;
}

Measured memory_bytes: 256
K = gets.to_i
S = gets.chomp.chars.map{|x| x.ord-48 }
L = S.size / (K+1)
G = S.size % (K+1)

if G == 0
  puts 0.step(S.size-1, L).map{|i| $_[i,L].to_i}.max
  exit
end

p (10**(L+1)/9...10**(L+1)).bsearch{|x|
  k = 0
  n = 0
  S.each do |c|
    if x < c
      k = K+1
      break
    end
    n = n * 10 + c
    if n > x
      k += 1
      n = c
    end
  end
  k <= K
}


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

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

using namespace std;
using ll=long long;

const int INF = 100000000;

int main() {
    string s;
    cin >> s;
    if (s=="ABC"){
        cout << "ARC";
    } else{
        cout << "ABC";
    }
    return 0;
}


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

int main() {
	int N, T;
	cin >> N >> T;
	int res = 10000;
	for (int i = 0; i < N; ++i) {
		int c, t;
		cin >> c >> t;

		if (t <= T) {
			res = min(res, c);
		}
	}

	if (res < 10000) { cout << res << endl; }
	else { cout << "TLE" << endl; }

	return 0;
}


Measured memory_bytes: 256
import collections

k = int(input())
q = collections.deque(list(range(1, 10)))
i = 0

while i < k:
    i += 1

    org = q.popleft()
    x = org % 10

    if x != 0:
        q.append(10 * org + x - 1)

    q.append( 10 * org + x)

    if x != 9:
        q.append(10 * org + x + 1)
print(org)

Measured memory_bytes: 11956
#include<bits/stdc++.h>
#define fastio ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define lli long long int
#define ulli unsigned long long int
#define ff first
#define ss second
#define mp make_pair
#define pb push_back
#define pf pop_front()
#define lb lower_bound
#define ub upper_bound
#define bs binary_search
#define loopl(i,a,b) for(lli i=a;i<b;i++) 
#define loop(i,a,b) for(int i=a;i<b;i++)
#define mod 1000000007
#define inf 7+1e18
# define lld long double
#define eps 0.000001
#define endl '\n'
using namespace std ;
 
int main()
{
   lli r;
   cin>>r;
   if(r<1200) cout<<"ABC"<<endl;
   else if(r>=1200 && r<2800) cout<<"ARC"<<endl;
   else cout<<"AGC"<<endl;
}

Measured memory_bytes: 256
// Problem : B - Crane and Turtle
// Contest : AtCoder - AtCoder Beginner Contest 170
// URL : https://atcoder.jp/contests/abc170/tasks/abc170_b
// Memory Limit : 1024 MB
// Time Limit : 2000 ms
// Powered by CP Editor (https://github.com/cpeditor/cpeditor)

//mst,pq,mp,st,q
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define io ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define pb push_back
#define all(x) begin(x),end(x)

int mod = 1e9+7;
int inf = 4e18;
const int N = 5e5+5;
		
signed main()
{
    io
    int tt = 1;
    //cin>>tt;
    while(tt--)
    {
		int x,y;
		cin>>x>>y;
		for(int i=0;i<=x;++i)
		{
			if(2*i+4*(x-i)==y)
			{
				cout<<"Yes";
				return 0;
			}
		}
		cout<<"No";		
    }
    return 0;
}


Measured memory_bytes: 3608
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
using vb=vector<bool>;
using vvb=vector<vb>;
using vd=vector<double>;
using vvd=vector<vd>;
using vi=vector<int>;
using vvi=vector<vi>;
using vl=vector<ll>;
using vvl=vector<vl>;
using pll=pair<ll,ll>;
using tll=tuple<ll,ll>;
using tlll=tuple<ll,ll,ll>;
using vs=vector<string>;
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define rep(i,n) range(i,0,n)
#define rrep(i,n) for(ll i=(n)-1;i>=0;i--)
#define range(i,a,n) for(ll i=(a);i<(n);i++)
#define LINF ((ll)1ll<<60)
#define INF ((int)1<<30)
#define EPS (1e-9)
#define MOD (1000000007ll)
#define fcout(a) cout<<setprecision(a)<<fixed
#define fs first
#define sc second
#define PI (3.1415926535897932384)

int dx[]={1,0,-1,0,1,-1,-1,1},dy[]={0,1,0,-1,1,1,-1,-1};
template<class T>bool chmax(T&a,T b){if(a<b){a=b; return true;}return false;}
template<class T>bool chmin(T&a,T b){if(a>b){a=b; return true;}return false;}
template<class S>S sum(vector<S>&a){return accumulate(all(a),S());}
template<class S>S max(vector<S>&a){return *max_element(all(a));}
template<class S>S min(vector<S>&a){return *min_element(all(a));}
ll max(int a,ll b){return max((ll)a,b);} ll max(ll a,int b){return max(a,(ll)b);}
int sgn(const double&r){return (r>EPS)-(r<-EPS);} // a>0  : sgn(a)>0
int sgn(const double&a,const double&b){return sgn(a-b);} // b<=c : sgn(b,c)<=0

template<class T>void puta(T&&t){cout<<t<<"\n";}
template<class H,class...T>void puta(H&&h,T&&...t){cout<<h<<' ';puta(t...);}
template<class S,class T>void tf(bool b,S t,T f){if(b)puta(t);else puta(f);}
void YN(bool b){tf(b,"YES","NO");}
void Yn(bool b){tf(b,"Yes","No");}
void yn(bool b){tf(b,"yes","no");}
template<class S,class T>ostream&operator<<(ostream&os,pair<S,T>p){os<<"["<<p.first<<", "<<p.second<<"]";return os;};
template<class S>auto&operator<<(ostream&os,vector<S>t){bool a=1;for(auto s:t){os<<(a?"":" ")<<s;a=0;}return os;}
template<class S>auto&operator>>(istream&is,vector<S>&t){for(S&a:t)cin>>a;return is;}

/*他のライブラリを入れる場所*/


int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll n;
    cin>>n;
    ll ans=0;
    vl s(100);
    range(i,1,n+1){
        ll d=i%10;
        ll t=to_string(i)[0]-'0';
        if(d==0)continue;
        s[d*10+t]++;
        if(t==d)s[t]++;
    }
    range(i,1,n+1){
        ll d=i%10;
        ll t=to_string(i)[0]-'0';
        ans += s[t*10+d];
    }
    puta(ans);
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ll long long
#define rep(X,N) for(ll X = 0; X < (N); X++)
#define PI (acos(-1.0))
#define pback push_back
#define mpair make_pair
#define MODN 1000000007
#define ALL(V) (V).begin(),(V).end() 

using namespace std;

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

    vector<int> war_mostleft(100001);
    
    rep(i,m){
        int a,b;
        cin >> a >> b;

        if(war_mostleft[a] == 0 || b < war_mostleft[a]){
            war_mostleft[a] = b;
        }

    }

    int ans = 0;
    int broken_mostleft = n;

    for(int i = n - 1; i > 0; i--){
        if(war_mostleft[i] != 0){
            if(war_mostleft[i] <= broken_mostleft){
                ans++;
                broken_mostleft = i;
            }
        }
    }

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 640
def left(i):
  return 2 * i + 1

def right(i):
  return 2 * i + 2

def parent(i):
  return (i - 1) // 2

def swap(items, i, j):
  items[i], items[j] = items[j], items[i]
  
def bubble_up(items, i):
  p = parent(i)
  while i > 0 and items[i] > items[p]:
    swap(items, i, p)
    i = p
    p = parent(i)
    
def heappush(items, item):
  items.append(item)
  bubble_up(items, len(items) - 1)
  
def tricle_down(items, i):
  while True:
    j = -1
    r = right(i)
    if r < len(items) and items[r] > items[i]:
      l = left(i)
      if items[l] > items[r]:
        j = l
      else:
        j = r
    else:
      l = left(i)
      if l < len(items) and items[l] > items[i]:
        j = l
    if j >= 0:
      swap(items, i, j)
    i = j
    if i < 0:
      break
  
def heappop(items):    
  x = items[0]
  items[0] = items[-1]
  items.pop()
  tricle_down(items, 0)
  return x

N, M = map(int, input().split())

items = []
for x in input().split():
  heappush(items, int(x))

for _ in range(M):
  a = heappop(items)
  heappush(items, a // 2)
  
print(sum(items))  




Measured memory_bytes: 14308
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
typedef unsigned long ul;
typedef unsigned int ui;
typedef pair<int,int> P;
typedef pair<ll,ll> LP;
#define All(v) (v).begin(),(v).end()
#define Rep(i,n) for(int i = 0; i < (int)n; i++)
#define Reps(i,n) for(int i = 1; i <= (int)n; i++)
#define For(i,m,n) for(int i = m; i < n; i++)
#define Fors(i,m,n) for(int i = m; i <= n; i++)
#define Inf 2e9
#define F first
#define S second
#define pb push_back
#define mp make_pair
struct speed{speed(){cin.tie(); ios::sync_with_stdio(false); cout << fixed << setprecision(18);}}aaa;

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

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


int main (){
    int n;
    cin >> n;
    vector<int> a(n);
    int num;
    Rep(i,n){
        cin >> a[i];
        if(i == 0){
            num = a[i];
        }else{
            num = gcd(num,a[i]);
        }
    }
    cout << num << "\n";
}


Measured memory_bytes: 640
#include <iostream>
#include <algorithm>
#include <vector>
#include <queue>
#include <string>
 
using namespace std;

int main() {
    string s;
    cin >> s;
    if (s[0] == s[1] || s[1] == s[2] || s[2] == s[3])
        cout << "Bad" << endl;
    else
        cout << "Good" << '\n';
    return 0;
}


Measured memory_bytes: 256
import java.util.Arrays;
import java.util.Scanner;

public class Main {

  Scanner sc;

  Main() {
    sc = new Scanner(System.in);
  }

  public static void main(String[] args) {
    new Main().run();
  }

  void run() {
    int sum = 0;

    for(int i = 0; i < 10; ++i) {
      sum += ni();
    }

    System.out.println(sum);

  }

  int ni() {
    return Integer.parseInt(sc.next());
  }

  void debug(Object... os) {
    System.err.println(Arrays.deepToString(os));
  }
}

Measured memory_bytes: 26056
#include<bits/stdc++.h>
#include<algorithm>
#include<math.h>
#include<stdio.h>
#include<string.h>
#include<set>
using namespace std;
int main()
{
    int a,b,c;
    cin>>a>>b>>c;
    swap(a,b);
    swap(a,c);
    cout<<a<<" "<<b<<" "<<c;
    return 0;
}

Measured memory_bytes: 256
# http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=ALDS1_3_B&lang=jp

class Queue(object):
    def __init__(self):
        self.list = []

    def enqueue(self, x):
        self.list.append(x)
    
    def dequeue(self):
        return self.list.pop(0)
    
    def isEmpty(self):
        return len(self.list) == 0


def main():
    n, q = map(int, input().split(" "))
    que = Queue()

    jobs = [input().split(' ') for _ in range(n)]


    for job in jobs:
        que.enqueue([job[0], int(job[1])])

    total = 0
    while not que.isEmpty():
        # print(que.list)

        name, time = que.dequeue()

        nokori = time - q
        if nokori > 0:
            total += q
            que.enqueue([name, nokori])
        else:
            total += time
            print(name, total)




main()


Measured memory_bytes: 21280
#include <stdio.h>
#include <string.h>
int main(void){
    char s[101];
    scanf("%s",s);
    for(int i=0;i<strlen(s);i++){
        if((i%2==0 && s[i]=='L') || (i%2!=0 && s[i]=='R')){
            printf("No");
            return 0;
        }
    }
    printf("Yes");
    return 0;
}

Measured memory_bytes: 128
#include <cstdio>
#include <cstdint>
#include <cassert>
#include <cmath>
#include <vector>
#include <algorithm>
#include <string>
#include <utility>

namespace detail {
template <typename Tp, size_t N>
std::vector<Tp> make_vector(
    std::vector<size_t>& sizes,
    typename std::enable_if<(N == 1), Tp const&>::type x
) {
  return std::vector<Tp>(sizes[0], x);
}
template <typename Tp, size_t N>
auto make_vector(
    std::vector<size_t>& sizes,
    typename std::enable_if<(N > 1), Tp const&>::type x
) {
  size_t size = sizes[N-1];
  sizes.pop_back();
  return std::vector<decltype(make_vector<Tp, N-1>(sizes, x))>(
      size, make_vector<Tp, N-1>(sizes, x)
  );
}
}  // detail::

template <typename Tp, size_t N>
auto make_vector(size_t const(&sizes)[N], Tp const& x) {
  std::vector<size_t> s(N);
  for (size_t i = 0; i < N; ++i) s[i] = sizes[N-i-1];
  return detail::make_vector<Tp, N>(s, x);
}

std::vector<std::vector<int>> calc_dp(
    std::vector<std::pair<int, int>> const& ab, size_t t
) {
  size_t n = ab.size();
  int inf = 1e9;
  auto dp = make_vector<int>({n+1, t}, -inf);
  std::fill(dp[0].begin(), dp[0].end(), 0);
  for (size_t i = 0; i < n; ++i) {
    for (size_t j = 0; j < t; ++j) {
      dp[i+1][j] = dp[i][j];
      if (int(j) >= ab[i].first) {
        dp[i+1][j] = std::max(dp[i+1][j], dp[i][j-ab[i].first] + ab[i].second);
      }
    }
  }

  // for (size_t i = 0; i <= n; ++i)
  //   for (size_t j = 0; j < t; ++j)
  //     fprintf(stderr, "%d%c", dp[i][j], j+1<t? ' ': '\n');

  return dp;
}

int main() {
  size_t n, t;
  scanf("%zu %zu", &n, &t);

  std::vector<std::pair<int, int>> ab(n);
  for (auto& p: ab) scanf("%d %d", &p.first, &p.second);

  auto dp0 = calc_dp(ab, t);
  std::reverse(ab.begin(), ab.end());
  auto dp1 = calc_dp(ab, t);
  // std::reverse(dp1.begin(), dp1.end());
  std::reverse(ab.begin(), ab.end());

  intmax_t res = 0;
  for (size_t i = 0; i < n; ++i) {
    for (size_t j = 0; j < t; ++j) {
      intmax_t cur = ab[i].second;
      cur += dp0[i][j] + dp1[n-i-1][t-j-1];
      // fprintf(stderr, "(%zu, %zu): %jd = %d + %d[%zu] + %d[%zu]\n",
      //         i, j, cur, ab[i].second,
      //         dp0[i][j], i,
      //         dp1[n-i-1][t-j-1], n-i-1);
      res = std::max(res, cur);
    }
  }
  printf("%jd\n", res);
}


Measured memory_bytes: 70912
import java.util.Scanner;

public class Main {
    
    private static final String GOOD = "Good";
    private static final String BAD = "Bad";

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        String S = sc.nextLine();
        System.out.println(isGood(S)?GOOD:BAD);
    }

    private static boolean isGood(String target) {
        boolean result = true;
        char[] partitioned = target.toCharArray();
        
        for(int i=1;i<partitioned.length;i++) {
            if(partitioned[i-1]==partitioned[i]) {
                result = false;
            }
        }
        return result;
    }
}

Measured memory_bytes: 21844
import Data.List

sum' [] = 0
sum' (m:s:r) = m*60 + s + sum' r

ans' :: [[Int]] -> [Int]
ans' x =
  let x' = map (\ (a:s) -> (a,sum' s) ) x
      s  = sortBy (\ (a,b) (c,d) -> compare b d) x'
      l  = length s
  in
    [ fst $ (s!!0), fst $ (s!!1), fst (s!!(l-2)) ]

ans ([0]:_) = []
ans ([n]:x) =
  let i = take n x
      y = drop n x
  in
    (ans' i)++(ans y)

main = do
  c <- getContents
  let i = map (map read) $ map words $ lines c :: [[Int]]
      o = ans i
  mapM_ print o

Measured memory_bytes: 11232
#define NDEBUG
NDEBUG


#include <algorithm>
#include <array>
#include <bitset>
#include <cassert>
#include <cstring>
#include <cmath>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <set>
#include <sstream>
#include <string>
#include <tuple>
#include <unordered_map>
#include <unordered_set>
#include <vector>
#include <memory>
#include <queue>
#include <random>


using namespace std;

template<class T>
using vec = std::vector<T>;

template<class T>
using vec2d = std::vector<std::vector<T>>;


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


typedef int64_t i64;


// TC_REMOVE_BEGIN
/// caide keep
bool __hack = std::ios::sync_with_stdio(false);
/// caide keep
auto __hack1 = cin.tie(nullptr);
// TC_REMOVE_END


// Section with adoption of array and vector algorithms.


//#include <ext/pb_ds/tree_policy.hpp>
//#include <ext/pb_ds/assoc_container.hpp>
//
//template <class T> using StdTree = tree<T, null_type, less<T>, rb_tree_tag,tree_order_statistics_node_update>;


namespace template_util {
    

    constexpr int bytecount(uint64_t x) {
        return x ? 1 + bytecount(x >> 8) : 0;
    }

    template<int N>
    struct bytetype {
        
    };

    
    /// caide keep
    template<uint64_t N>
    struct minimal_uint : bytetype<bytecount(N)> {
    };
}


template<class T>
T next(istream& in) {
    T ret;
    in >> ret;
    return ret;
}

template<class T>
vector<T> next_vec(istream& in, size_t n) {
  vector<T> ret(n);
  for (size_t i = 0; i < n; ++i) {
    ret[i] = next<T>(in);
  }
  return ret;
}


#define dbg(...) ;


void solve(istream& in, ostream& out) {
  auto n = next<int>(in);
  auto x = next_vec<int>(in, n);
  auto L = next<int>(in);
  vec2d<int> to;
  vec<int> to1(n-1);
  int ptr = 0;
  i64 sum = 0;
  FOR(i, n-1) {
    while (ptr + 1 < n && sum + x[ptr + 1] - x[ptr] <= L) {
      sum += x[ptr + 1] - x[ptr];
      ++ptr;
    }
    to1[i] = ptr;
    sum -= (x[i+1] - x[i]);
  }
  to1.push_back(n-1);
  to.push_back(to1);
  for (int d = 2; d <= n; d *= 2) {
    to1 = vec<int>(n-1);
    FOR(i, n-1) {
      to1[i] = to.back()[to.back()[i]];
    }
    to1.push_back(n-1);
    to.push_back(to1);
  }
  dbg(to);
  auto nq = next<int>(in);
  while (nq--) {
    auto a = next<int>(in) - 1;
    auto b = next<int>(in) - 1;
    if (a > b) {
      swap(a, b);
    }
    i64 res = 0;
    for (int i = (int)to.size() - 1; i >= 0; --i) {
      if (to[i][a] >= b) {
        continue;
      }
      res += (1LL << i);
      a = to[i][a];
    }
    ++res;
    out << res << "\n";
  }
}

//#include <fstream>


int main() {
//  ifstream fin("bridges.in");
//  ofstream fout("bridges.out");
    solve(cin, cout);
//  solve(fin, fout);
    return 0;
}



Measured memory_bytes: 8688
A, B = map(int,input().split())

if A == 1 and B != 1:
    if B != 1 :
        print("Alice")

if B == 1 and A != 1:
    if A != 1 :
        print("Bob")

if A == 1 and B == 1 :
    print("Draw")

if A != 1 and B !=1 :
    if A > B :
        print("Alice")
    if A < B :
        print("Bob")
    if A == B :
        print("Draw")

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

using namespace std;

int main(){
    int N,sum=0,ans=0;
    cin >> N;
    vector<int> A(100001,0);
    for(int i=0;i<N;i++){
        int a;
        cin >> a;
        A[a]++;
    }

    for(int i=0;i<100001;i++){
        if(A[i]!=0){
            ans++;
            if(A[i]!=1){
                sum += (A[i]-1)%2;
            }
        }
    }

    cout << ans-(sum%2) << endl;
}

Measured memory_bytes: 640
#include <iostream>
#include <vector>
#include <algorithm>
#define MOD 1000000007LL
using namespace std;
typedef long long ll;

string s;

int arr[4][100000] = {};
int ans[100000] = {};
int mc,oc;

int main() {
	cin>>s;
	int n = s.size();
	mc = 0;
	oc = 0;
	for(int i = 0; i < n; i++) {
		if(s[i]=='R') {
			mc++;
		}else {
			arr[0][i] = oc;
			arr[1][i] = mc;
			mc=0;
			oc=0;
		}
		int tmp = mc;
		mc = oc;
		oc = tmp;
	}
	mc = 0;
	oc = 0;
	for(int i = n-1; i >= 0; i--) {
		if(s[i]=='L') {
			mc++;
		}else {
			arr[2][i] = oc;
			arr[3][i] = mc;
			mc=0;
			oc=0;
		}
		int tmp = mc;
		mc = oc;
		oc = tmp;
	}

	for(int i = n-1; i >= 0; i--) {
		if(arr[0][i]>0) {
			ans[i-1] += arr[0][i];
		}
		if(arr[1][i]>0) {
			ans[i] += arr[1][i];
		}
	}

	for(int i = 0; i < n; i++) {
		if(arr[2][i]>0) {
			ans[i+1] += arr[2][i];
		}
		if(arr[3][i]>0) {
			ans[i] += arr[3][i];
		}
	}

	cout << ans[0];
	for(int i = 1; i < n; i++) {
		cout << " " << ans[i];
	}
	cout << endl;
}


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

#define INF 1000010000
#define nl '\n'
#define pb push_back
#define ppb pop_back
#define mp make_pair
#define fi first
#define se second
#define pii pair<int,int>
#define pdd pair<double,double>
#define all(c) (c).begin(), (c).end()
#define SORT(c) sort(all(c))
#define sz(c) (c).size()
#define rep(i,n) for( int i = 0; i < n; ++i )
#define repi(i,n) for( int i = 1 ; i <= n; ++i )
#define repn(i,n) for( int i = n - 1 ; i >= 0 ; --i )
#define repf(j,i,n) for( int j = i ; j < n ; ++j )
#define die(s) {std::cout << s << nl;}
#define dier(s) {std::cout << s; return 0;}
#define dbg(var) {std::cout << #var << "  = " << var << nl;}
#define vi vector<int>
typedef long long ll;

using namespace std;


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

	int n , m;
	cin >> n >> m;
	
	vi v(m);
	rep(i , m)
	{
		int k;
		cin >> k;
		rep(j , k)
		{
			int x;
			cin >> x;
			--x;
			v[i] |= (1 << x);
		}
	}
	
	vi p(m);
	for(auto& el : p) cin >> el;
	
	int ans = 0;
	for(int i = 0; i < (1 << n); ++i)
	{
		bool ok = true;
		rep(j , m)
		{
			if(__builtin_popcount(v[j] & i) % 2 != p[j])
				ok = false;
		}
		if(ok)
			++ans;
	}

	die(ans);
	return 0;
}

Measured memory_bytes: 256
import java.io.PrintWriter

// 入力取得
private fun read() = readLine()!!
private fun readInt() = read().toInt()
private fun readLong() = read().toLong()
private fun nextDouble() = read().toDouble()

//入力取得(list)
private fun listOfString() = read().split(" ") //スペース区切り
private fun listOfInt() =listOfString().map { it.toInt() }
private fun listOfLong() =listOfString().map { it.toLong() }
private fun listOfDouble() =listOfString().map { it.toDouble() }

//二次元配列y生成
private fun arrayIntInit(n:Int) = Array(n, {Array(n, {it -> 0})}) //0で初期化した, n × nの二次元配列

//PrintWriter(出力用)
private val pw = PrintWriter(System.out)

fun main(args: Array<String>) {
    minorchange()
}

fun minorchange(){
    val s = read().toCharArray()
    val t = read().toCharArray()

    var count = 0
    if(!s.equals(t)){
        s.forEachIndexed(){
                i,c ->
            if(!c.equals(t[i])){
                count+=1
            }
        }
    }

    println(count)
    pw.flush()
}

private fun println(value : Any) {
    pw.println(value)
}

private fun print(value : Any) {
    pw.print(value)
}


Measured memory_bytes: 41480
#include<cstdio>
#include<iostream>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<algorithm>
#include<queue>
#include<vector>
using namespace std;
int main()
{
    char a[5][5];
    for(int i=0;i<3;i++){
        for(int j=0;j<3;j++){
            cin>>a[i][j];
        }
    }
    for(int i=0;i<3;i++)
        cout<<a[i][i];
    cout<<endl;
    return 0;
}


Measured memory_bytes: 256
#include <algorithm>
#include <array>
#include <vector>
#include <iostream>
#include <fstream>
#include <string>
#include <cmath>
#include <functional>
#include <queue>

using namespace std;

bool isLowercase(char c) {
	return ('a' <= c && c <= 'z');
}

bool Check(string S) {
	if (S[0] != 'A')return false;
	if (!isLowercase(S[1])) return false;
	if (!isLowercase(S[S.length() - 1]))return false;
	string Rest = S.substr(2, S.length() - 3);
	int N = Rest.length();
	bool C = false;
	for (int i = 0; i < N; i++) {
		if (Rest[i] == 'C') {
			if (C==false) {
				C = true;
				continue;
			} else {
				return false;
			}
		}
		if (!isLowercase(Rest[i])) {
			return false;
		}
	}
	return C;
}

int main() {
	string S;
	cin >> S;
	if (Check(S)) {
		cout << "AC" << endl;
	} else {
		cout << "WA" << endl;
	}
}

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

int main() {
    int N;
    cin >> N;
    int A[N];
    for (int i = 0; i < N; i++)
    {
        cin >> A[i];
    }

    string state = "INIT";
    int cnt = 1;
    for (int i = 0; i < N - 1; i++)
    {
        // cout << i << " " << state << endl;
        if (A[i] < A[i + 1])
        {
            if (state == "INIT") {
                state = "UP";
                continue;
            }
            else if (state == "UP")
            {
                continue;
            }
            else if (state == "DOWN") {
                state = "INIT";
                cnt++;
            }
        }
        else if (A[i] > A[i+1]) {
            if (state == "INIT") {
                state = "DOWN";
                continue;
            }
            else if (state == "UP")
            {
                state = "INIT";
                cnt++;
            }
            else if (state == "DOWN")
            {
                continue;
            }
                            }
        else
        {
            continue;
        }
        }
    cout << cnt << endl;
}

Measured memory_bytes: 640
var n,i,j,ans,x:longint;
var b:array[0..100200] of longint;
begin
  read(n);
  for i:=1 to n do begin read(x);if x>100000 then inc(ans)
  else inc(b[x]);end;
  for i:=1 to 100000 do
  begin
    if b[i]>0 then begin
      if b[i]>i then inc(ans,b[i]-i)
      else if b[i]<i then inc(ans,b[i]);end;
  end;
  writeln(ans);
end.

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <vector>
#include <array>
#include <string>
#include <queue>
#include <cmath>
#include <iterator>
#include <math.h>
#include <cstdio>
#include <map>
#include <bitset>

using namespace std;
using lli = long long int;
using ulli = unsigned long long int;

int main(void){
    int a,b;
    cin >> a >> b;
    if((a*b)%2 == 0){
        cout << "Even" << endl;
        return 0;
    }
    cout << "Odd" << endl;
    return 0;
}


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

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

int main() {
    int N; cin >> N;
    vector<long long> a(N);
    for (int i = 0; i < N; ++i) cin >> a[i];
    int num_minus = 0;
    long long mi = 1LL<<60;
    long long sum = 0;
    for (int i = 0; i < N; ++i) {
        if (a[i] < 0) ++num_minus;
        chmin(mi, abs(a[i]));
        sum += abs(a[i]);
    }
    if (num_minus % 2 == 0) cout << sum << endl;
    else cout << sum - mi*2 << endl;
}

Measured memory_bytes: 1024
#include <iostream>
#include <string>
#include <sstream>
using namespace std;
#define cMaxLimit 260

typedef struct { int key, parent, leftChild, rightChild; } Node;
stringstream ans1, ans2;

void print(Node node[], int maxNum)
{
    for (int i = 1; i <= maxNum; i++)
	{
        ans1 << "node " << i << ": ";
        ans1 << "key = " << node[i].key << ", ";
        if (node[i].parent != -1) ans1 << "parent key = " << node[i].parent << ", ";
        if (node[i].leftChild != -1) ans1 << "left key = " << node[i].leftChild << ", ";
        if (node[i].rightChild != -1) ans1 << "right key = " << node[i].rightChild << ", ";
        ans1 << endl;
    }
}

int main()
{
    int nodeMaxNum; cin >> nodeMaxNum;
    Node node[cMaxLimit + 1]; // ????????????????????????1-???????????????????????????
    for (int i = 1; i <= nodeMaxNum; i++)
	{
        int key; cin >> key;
        node[i].key = key;
        node[i].leftChild = -1;
        node[i].rightChild = -1;
        node[i].parent = -1;
    }
    for (int i = 1; i <= nodeMaxNum; i++)
	{
       ans2 << "node " << i << ": ";
       ans2 << "key = " << node[i].key << ", ";
       if (i / 2 >= 1) ans2 << "parent key = " << node[i / 2].key << ", ";
       if (i * 2 <= nodeMaxNum) ans2 << "left key = " << node[i * 2].key << ", ";
       if (i * 2 + 1 <= nodeMaxNum) ans2 << "right key = " << node[i * 2 + 1].key << ", ";
       ans2 << endl;
    }
    for (int i = 1; i <= nodeMaxNum; i++)
	{
        if (i / 2 >= 1) node[i].parent = node[i / 2].key;
        if (i * 2 <= nodeMaxNum) node[i].leftChild = node[i * 2].key;
        if (i * 2 + 1 <= nodeMaxNum) node[i].rightChild = node[i * 2 + 1].key;
    }
    print(node, nodeMaxNum);
	cout << ans2.str();
    return 0;
}

Measured memory_bytes: 3220
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.StringTokenizer;

public class Main {
	
	public static void main(String[] args) throws IOException {
		MyScanner sc = new MyScanner();
		PrintWriter out = new PrintWriter(System.out);
		int a = sc.nextInt();
		int b = sc.nextInt();
		int ans = a * b - a - b + 1;
		out.println(ans);
		
		out.flush();
	}
	
	static class MyScanner {
		private BufferedReader br;
		private StringTokenizer tokenizer;
		
		public MyScanner() {
			br = new BufferedReader(new InputStreamReader(System.in));
		}
		
		public String next() {
			while (tokenizer == null || !tokenizer.hasMoreTokens()) {
				try {
					tokenizer = new StringTokenizer(br.readLine());
				} catch (IOException e) {
					throw new RuntimeException(e);
				}
			}
			return tokenizer.nextToken();
		}
		
		public int nextInt() {
			return Integer.parseInt(next());
		}
		
		public long nextLong() {
			return Long.parseLong(next());
		}
	}
}


Measured memory_bytes: 21204
N,A,B,C,D=map(int,input().split())
a=N//A
b=N%A
if b==0:a=a
else:a=a+1
c=N//C
d=N%C
if d==0:c=c
else:c=c+1
E=a*B
F=c*D
if E>F:print(F)
else:print(E)



Measured memory_bytes: 5596
program main
Implicit None
	integer(8)::r,g,b,n,k,i,j,p,q
	
	read*,r,g,b,n
	k = 0
	
	do i = n/r,0,-1
		p = n - i*r
		if(p == 0)then
			k = k+1
			cycle
		endif
		do j = p/g,0,-1
			q = p - j*g
			if(mod(q,b) == 0) k = k+1
		enddo
	enddo
	
	print"(i0)",k
end program main

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

typedef long long ll;

int main()
{
    char i,j,k;
    ll n;
    cin >> n;
    string s;
    cin >> s;
    ll l;
    ll ans = 0;
    for(i = '0';i <= '9';++i){
        for(j = '0';j <= '9';++j){
            for(k = '0';k <= '9';++k){
                char tmp[3] = {i,j,k};
                int num = 0;
                for(l = 0;l < n;++l){
                    if(s.at(l) == tmp[num]){
                        ++num;
                    }
                    if(num == 3){
                        ++ans;
                        break;
                    }
                }
            }
        }
    }
    cout << ans << endl;
    return 0;
}

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

using namespace std;

int main() {
    int n;
    cin >> n;
    vector<int> a(n, 0);
    for (int i = 0; i < n; ++i) {
        cin >> a[i];
    }
    int count = 0;
    for (int i = 0; i < n - 1; ++i) {
        int temp = 1;
        int ta = a[i];
        for (int j = i + 1; j < n; ++j, ++i) {
            if(ta == a[j])
            {
                temp++;
            }else{
                break;
            }
        }
        count += temp / 2;
    }
    cout << count << endl;
    return 0;
}


Measured memory_bytes: 256
<?php
    $la = trim(fgets(STDIN));
//    $la = 125;
    $l1 = str_split($la);
//    print_r(($l1));
    $len = count($l1);
    $lenn = $len -1;
    $count = 0;
    $temp[0] = $l1[0];
    $ans = 0;
    for($i = 0; $i < pow(2,$len - 1); $i++){
        $bin = str_split(sprintf("%'0".$lenn."b",$i));
//        print_r($bin);
        for($j = 0; $j < $len -1; $j++){
            if($bin[$j] == 0){
                $temp[$count] = $temp[$count].$l1[$j+1];
            } else {
                $count++;
                $temp[$count] = $l1[$j+1];
            }
        }
            $ans += array_sum($temp);
//            print_r($temp);
            $temp = array($l1[0]);
            $count = 0;
    }    
    
    echo $ans;
?>  

Measured memory_bytes: 3452
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define repr(i, n) for (int i = (n); i >= 0; --i)
#define FOR(i, m, n) for (int i = (m); i < (n); ++i)
#define FORR(i, m, n) for (int i = (m); i >= (n); --i)
#define equals(a, b) (fabs((a) - (b)) < EPS)
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
//const ll mod = 1000000007;
//const ll mod = 998244353;
const int inf = 1e9 + 10;
const ll INF = 1e18;
const ld EPS = 1e-10;
const int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1};
const int dy[8] = {0, 1, 0, -1, 1, 1, -1, -1};
template<class T> bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T> bool chmin(T &a, const T &b) { if (a>b) { a=b; return 1; } return 0; }



int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout << fixed << setprecision(25);

  int n, x, t;
  cin >> n >> x >> t;

  cout << (n + x - 1) / x * t << '\n';

  
  return 0;
}

Measured memory_bytes: 3624
#include<stdio.h>
 
int gcd(int x,int y);
 
int main()
{
  int x,y;
 
  scanf("%d%d", &x, &y);
   
  printf("%d\n", gcd(x,y));
 
  return 0;
}
 
int gcd(int x, int y)
{
  int tmp;
 
  if(x < y) {
    tmp = x;
    x = y;
    y = tmp;
  }
  while(y > 0) {
    tmp = x % y;
    x = y;
    y = tmp;
  }
  return x;
}

Measured memory_bytes: 592
#include <bits/stdc++.h>
typedef long long ll;
using namespace std;
ll a7=1000000007;
ll inf=100000000000000000;

ll min(ll a,ll b){
    if(a<b)return a;
    else return b;
}
ll max(ll a,ll b){
    if(a>b)return a;
    else return b;
}

int main(){
    ll n,k;cin>>n>>k;
    ll v[n+1];
    for(ll i=1;i<n+1;i++){
        cin>>v[i];
    }
    ll dp1[n+1][k+1];
    ll dp2[n+1][k+1];
    vector<ll> d1;
    ll sum=0;
    for(ll i=0;i<=n;i++){
        for(ll j=0;j<=k;j++){
            dp1[i][j]=0;
            dp2[i][j]=0;
        }
    }
    for(ll i=1;i<=n;i++){
        sum+=v[i];
        d1.push_back(v[i]);
        sort(d1.begin(),d1.end());
        for(ll j=i;j<=min(2*i-1,k);j++){
            if(j==i){
                dp1[i][j]=sum;
            }else{
                dp1[i][j]=dp1[i][j-1]-d1[j-i-1];
            }
        }
    }
    vector<ll> d2;
    sum=0;
    for(ll i=1;i<=n;i++){
        sum+=v[n-i+1];
        d2.push_back(v[n-i+1]);
        sort(d2.begin(),d2.end());
        for(ll j=i;j<=min(2*i-1,k);j++){
            if(j==i){
                dp2[i][j]=sum;
            }else{
                dp2[i][j]=dp2[i][j-1]-d2[j-i-1];
            }
        }
    }
    ll a1;
    ll a2;
    for(ll i=1;i<=n;i++){
        a1=-inf;
        a2=-inf;
        for(ll j=1;j<=k;j++){
            dp1[i][j]=max(a1,dp1[i][j]);
            a1=dp1[i][j];
            dp2[i][j]=max(a2,dp2[i][j]);
            a2=dp2[i][j];
        }
    }
    for(ll j=1;j<=k;j++){
        a1=-inf;
        a2=-inf;
        for(ll i=1;i<=n;i++){
            dp1[i][j]=max(a1,dp1[i][j]);
            a1=dp1[i][j];
            dp2[i][j]=max(a2,dp2[i][j]);
            a2=dp2[i][j];
        }
    }
    ll ans=0;
    for(ll i=1;i<=n;i++){
        for(ll j=i;j<=min(2*i-1,k);j++){
            ans=max(ans,dp1[i][j]+dp2[n-i][k-j]);
        }
    }
    cout<<ans<<endl;
    return 0;
}



Measured memory_bytes: 384
import math
import itertools

def distance(p1, p2):
    return math.sqrt((p1[0]-p2[0])**2 + (p1[1]-p2[1])**2)

n = int(input())
points = {i: list(map(int,  input().split())) for i in range(n)}

total_distance = 0

for cource in itertools.permutations(range(n)):
    for i in range(1, n):
        total_distance += distance(points[cource[i-1]], points[cource[i]])

print(total_distance/math.factorial(n))

Measured memory_bytes: 3064
import bisect
import collections
N=int(input())
L=list(map(int,input().split()))
L.sort()
c = collections.Counter(L)
#print(L)
 
#b-a < c < a+b

#a<=b<=c
ans=0
L_a=L[:N-2]
for i,a in enumerate(L_a):
    L_b=L[i+1:N-1]
    for j,b in enumerate(L_b,start=i+1):
        x=bisect.bisect(L[j+1:],a+b)
        ans+=x
        if a+b==L[j+x]:
            #print(a,b,L[j+x])
            ans-=c[a+b]
        #print(i,a,j,b,x,N-j-1,L[j+1:])
print(ans)

Measured memory_bytes: 83008
def binary(node,parent,sibling,depth,root):
    if node!=-1:
        id,left,right=A[node]
        degree = len([i for i in (right, left) if i != -1])
        if parent==-1:root="root"
        elif degree!=0:root="internal node"
        else:root="leaf"
        B.append([node,parent,sibling,degree,depth,root])
        binary(left,node,right,depth+1,root)
        binary(right,node,left,depth+1,root)


def setHight(H,u):
    h1,h2=0,0
    if A[u][2]!=-1:
        h1=setHight(H,A[u][2])+1
    if A[u][1]!=-1:
        h2=setHight(H,A[u][1])+1
    H[u]=max(h1,h2)
    return H[u]


n=int(input())
A=[list(map(int,input().split())) for i in range(n)]
B,H=[],[0]*n
top=[i for i in range(n)]
for i in range(n):
    for j in (A[i][1],A[i][2]):
        if j!=-1:top.remove(j)
top=top[0]
A=sorted(A)
binary(top,-1,-1,0,"root")
setHight(H,top)
for j,i in enumerate(sorted(B)):
    print("node {}: parent = {}, sibling = {}, degree = {}, depth = {}, height = {}, {}"
          .format(i[0],i[1],i[2],i[3],i[4],H[j],i[5]))


Measured memory_bytes: 5616
n, *p = map(int, open(0).read().split())
swp = [p[i]for i in range(n) if p[i] == i+1]

if swp:
    cnt = 0
    flag = 0

    for i in range(len(swp)-1):
        if flag == 1:
            cnt += 1
            flag = 0
            continue
        if swp[i]+1 == swp[i+1]:
            flag = 1
        else:
            cnt += 1
    
    ans = cnt+1

else:
    ans = 0

print(ans)

Measured memory_bytes: 14068
#include<iostream>
#define rep(i,n) for(ll i = 1; i < (n); i++)
using ll = long long;
using namespace std;

int main()
{
    ll n;
    cin >> n;
    ll ans = 2 * n - 3;//1が関わる組の数
    rep(i,n/2){
        rep(j,n/2){
            if(((i+1) * (j+1)) < n) ans++;
            else break;
        }
    }
    cout << ans << endl;
    return 0;
}

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

using namespace std;

int main()
{
	char s[100001];

	while (scanf("%s", s) && s[0] != '0'){
		int ans = 0;
		int ct[2][11];
		memset(ct, 0, sizeof(ct));

		for (int i = 0; s[i]; i++){
			for (int j = 0; j <= 10; j++){
				ct[i % 2][(j * 10 + s[i] - '0') % 11] = ct[(i + 1) % 2][j];
			}
			if (s[i] != '0') ct[i % 2][s[i] - '0']++;
			ans += ct[i % 2][0];
		}
		printf("%d\n", ans);
	}

	return (0);
}

Measured memory_bytes: 1220
main :: IO ()
main = do
    [count, amount] <- map read . words <$> getLine
    let cases = execOtoshidama count amount
    if null cases
        then putStrLn "-1 -1 -1"
        else putStrLn $ unwords $ map show $ head cases
        
execOtoshidama :: Int -> Int -> [[Int]]
execOtoshidama num amount =
            [[x, y, z] | 
                  x <- [0 .. num], y <- [0 .. num - x], let z = num - x - y
                , x * 10000 + y * 5000 + z * 1000 == amount]

Measured memory_bytes: 636
#include <bits/stdc++.h>
#include <algorithm>
using namespace std;
int main(void){
    string s;
    cin>>s;
    
    string v=s,w=s.substr(0,(s.size()-1)/2),x=s.substr((s.size()+3)/2-1,(s.size()-3)/2+1),w2=w,x2=x;
    
    reverse(v.begin(),v.end());
    reverse(w2.begin(),w2.end());    
    reverse(x2.begin(),x2.end());
    
    if(s==v && w==w2 && x==x2) {
        cout<<"Yes\n";
    } else {
        cout<<"No\n";
    }

    return 0;
}

Measured memory_bytes: 3608
N = int(input())
a = list(map(int, input().split()))

alice = 0
bob = 0
flag = 0
for i in range(N):
    if flag == 0:
        alice += max(a)
        del a[a.index(max(a))]
        flag = 1
    else:
        bob += max(a)
        del a[a.index(max(a))]
        flag = 0

print(alice - bob)

Measured memory_bytes: 3064
#include <algorithm>
#include <array>
#include <cassert>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <map>
#include <memory>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <sstream>
#include <unordered_map>
#include <vector>


#define INF 4000000000000000000LL
#define MOD 1000000007
#define ALL(x) std::begin(x), std::end(x)


int main(int argc, char** argv)
{
  std::cin.tie(0);
  std::ios_base::sync_with_stdio(0);

  std::cout << std::fixed << std::setprecision(6);

  std::string s;

  std::cin >> s;

  for (int i = 0, size = s.size(); i < size; i ++) {
    if (i + 1 < size)
      if (s[i] == s[i + 1]) {
        std::cout << i + 1 << ' ' << i + 1 + 1 << std::endl;

        return 0;
      }

    if (i + 2 < size)
      if (s[i] == s[i + 2]) {
        std::cout << i + 1 << ' ' << i + 2 + 1 << std::endl;

        return 0;
      }
  }

  std::cout << -1 << ' ' << -1 << std::endl;

  return 0;
}


Measured memory_bytes: 512
N, M, V, P = gets.split.map(&:to_i)
A = gets.split.map(&:to_i).sort

def f(x)
  vote_cnt = M * V - M * (P - 1)

  return false if x < A[-P]

  (-P).downto(-N) do |i|
    a = A[i]

    # break if x <= a
    break if vote_cnt <= 0

    diff = x - a

    if diff >= M
      vote_cnt -= M
    else
      vote_cnt -= diff
    end
  end

  vote_cnt <= 0
end

ng = 0
ok = 10 ** 10

while (ng - ok).abs > 1
  mid = (ng + ok) / 2

  if f(mid)
    ok = mid
  else
    ng = mid
  end
end

puts A.count { |a| a + M >= ok }



Measured memory_bytes: 10104
use std::io::*;
use std::str::FromStr;

fn read<T: FromStr>() -> T {
    let stdin = stdin();
    let stdin = stdin.lock();
    let token: String = stdin
        .bytes()
        .map(|c| c.expect("failed to read char") as char) 
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect();
    token.parse().ok().expect("failed to parse token")
}

fn check(a: i32, b: i32, c: i32) -> bool {
    (a==5 && b==5 && c==7) || (a==5 && b==7 && c==5) || (a==7 && b==5 && c==5)
}

fn main() {
    let a: i32 = read();
    let b: i32 = read();
    let c: i32 = read();
    let res: &str = if check(a, b, c) { "YES" } else { "NO" };
    println!("{}", res);
}


Measured memory_bytes: 4352
N,M=map(int,input().split())
B=[]
for i in range(M):
  a,b=map(int,input().split())
  B.append([a,b])
B.sort(key=lambda x:x[1])
ans=1
c=[B[0][1]]
for item in B:
  if c[-1]<=item[0]:
    c.append(item[1])
    ans+=1
print(ans)

Measured memory_bytes: 21340