akhauriyash/Code-Regression huggingface dataset:
using System;
namespace q1
{
    class q2
    {
        static void Main()
        {
            int N = int.Parse(Console.ReadLine());
            if (N%10==7||N-N%100==700||N%100-N%10==70)
            {
                Console.WriteLine("Yes");
            }
            else
            {
                Console.WriteLine("No");
            }
        }
    }
}

Measured memory_bytes: 27280
package main

import (
	"bufio"
	"bytes"
	"fmt"
	"io"
	"math/bits"
	"os"
	// "strconv"
	// "strings"
)

//  長い入力を読む
func ReadLongLines(times int) ([]string, error) {
	result := make([]string, times)
	reader := bufio.NewReader(os.Stdin)
	buffer := bytes.NewBuffer(make([]byte, 0))
	readBytes := int64(2)
	for i := 0; i < times; i++ {
		for {
			readBuf, isPrefix, err := reader.ReadLine()
			// fmt.Printf("Reader.Read: %d\n", len(readBuf))
			readBytes += int64(len(readBuf) + 1)
			if err != nil {
				if err == io.EOF {
					fmt.Println("EOF")
					break
				} else {
					return result, err
				}
			}
			_, err = buffer.Write(readBuf)
			if err != nil {
				return result, err
			}
			// end of line
			if !isPrefix {
				result[i] = buffer.String()
				buffer.Reset()
				// reader = bufio.NewReader(os.Stdin)
				break
			}
		}
	}
	// 先読みしてしまうようなので、戻しておく
	os.Stdin.Seek(-int64(reader.Buffered()), os.SEEK_CUR)
	return result, nil
}

// 出力 for 競プロ
type Console struct {
	writer *bufio.Writer
}

func NewConsole() Console {
	return Console{bufio.NewWriter(os.Stdout)}
}
func (this *Console) Printf(format string, a ...interface{}) {
	fmt.Fprintf(this.writer, format, a...)
}
func (this *Console) Println(s string) {
	fmt.Fprintln(this.writer, s)
}
func (this *Console) Close() {
	this.Flush()
}
func (this Console) Flush() {
	this.writer.Flush()
}

func PrintList(list []int) {
	con := NewConsole()
	defer con.Flush()
	for i := range list {
		if i == 0 {
			con.Printf("%d", list[i])
		} else {
			con.Printf(" %d", list[i])
		}
	}
	con.Println("")
}

func main() {
	con := NewConsole()
	defer con.Flush()

	var n int
	fmt.Scanf("%d", &n)
	max := uint32(1)
	for i := 0; i < n; i++ {
		max = max * 2
	}

	t := make([]uint32, 0, 18)
	fmt.Scanf("%d", &n)
	for i := 0; i < n; i++ {
		var x uint32
		fmt.Scanf("%d", &x)
		t = append(t, x)
	}
	T := uint32(0)
	for i := 0; i < len(t); i++ {
		T += 1 << t[i]
	}

	for i := uint32(0); i < max; i++ {
		// T が i の部分集合でない
		if (i & T) != T {
			continue
		}
		con.Printf("%d:", i)
		begin := bits.TrailingZeros32(i)
		end := bits.LeadingZeros32(i)
		for j := begin; j < 32-end; j++ {
			//fmt.Printf("%d & 1<<%d (%d)\n",i, j, (i & (1 << uint32(j))))
			if 0 < (i & (1 << uint32(j))) {
				con.Printf(" %d", j)
			}
		}
		con.Println("")
	}

}



Measured memory_bytes: 6152
function main()
  
  S = split(chomp(readline()),"")
  
  count01 = 0 # 01010101...
  count10 = 0 # 10101010...
  
  for i in 1:length(S)
    if i % 2 == 1
      if S[i] == "0"
        count10 += 1
      else
        count01 += 1
      end
    else
      if S[i] == "1"
        count10 += 1
      else
        count01 += 1
      end
    end
  end
  
  println(min(count01,count10))
  
end

main()

Measured memory_bytes: 122372
#include <bits/stdc++.h>                        
#define pb push_back                            
#define mp make_pair                            
#define all(x) (x).begin(), (x).end()
#define sz(x) (int)((x).size())
#define jonathan ios_base::sync_with_stdio(0)
#define livingston cin.tie(0)
using namespace std;                            
                                                
void yes() {cout << "YES" << endl;}                                               
void no() {cout << "NO" << endl;}                                                        
                                                
int dx[] = {1, 0, -1, 0, -1, -1, 1, 1};         
int dy[] = {0, 1, 0, -1, -1, 1, -1, 1}; 

const int INF = 1e9 + 9;
const long long LINF = 1e18 + 8;
const double EPS = 1e-9;
const long long MOD = 1e9 + 7; //998244353
const double PI = acos(-1);

long long dp[42][(1 << 16)][2];

void solve() {
    int n, x, y, z;
    cin >> n >> x >> y >> z;
    dp[0][0][0] = 1;
    int sum = x + y + z - 1;
    for (int i = 1; i <= n; i++) {
        for (int put = 1; put <= 10; put++) {
            for (int mask = 0; mask < (1 << sum); mask++) {
                bool okx = (z - put == 0) or ((z - put > 0) and (mask & (1 << (z - put - 1))));
                bool oky = (y + z - put == 0) or ((y + z - put > 0) and (mask & (1 << (y + z - put - 1))));
                bool okz = (x + y + z - put == 0) or ((x + y + z - put > 0) and (mask & (1 << (x + y + z- put - 1))));
                int mask2 = ((mask << put) | (1 << (put - 1))) & ((1 << sum) - 1);
                if (okx and oky and okz) {
                    dp[i][mask2][1] += ((dp[i - 1][mask][0] + dp[i - 1][mask][1]) % MOD);
                    dp[i][mask2][1] %= MOD;
                } else {
                    dp[i][mask2][0] += dp[i - 1][mask][0];
                    dp[i][mask2][0] %= MOD;
                    dp[i][mask2][1] += dp[i - 1][mask][1];
                    dp[i][mask2][1] %= MOD;
                }
            }
        }
    }
    long long res = 0;
    for (int mask = 0; mask < (1 << sum); mask++) {
        res += dp[n][mask][1];
        res %= MOD;
    }
    cout << res << endl;
} 

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

Measured memory_bytes: 44588
#include <stdio.h>
int main(){
    int a,b;
    char op;
    
    while(1){
        scanf("%d %c %d",&a,&op,&b);
        if (op=='?') break;
        else if(op=='+'){
            printf("%d\n",a+b);
        }
        else if(op=='-'){
            printf("%d\n",a-b);
        }
        else if (op=='*'){
            printf("%d\n",a*b);
        }
        else if (op=='/'){
            printf("%d\n",a/b);
        }
        else{
            printf("Invalid Input!!");
        }
    }
    return 0; 
}

Measured memory_bytes: 600
#include <iostream>
#include <string>

using namespace std;



int main(){
        string s;
        cin >> s;
        int N = s.length();
        long ans= 0;
        int date = N-1;
        for(int i = N-1; i >= 0; i--){
            if(s[i] == 'B'){
                ans += date - i;
              	date--;
            }
        }
        cout << ans;

}


Measured memory_bytes: 640
using System;
using System.Linq;
using System.Collections.Generic;
using static System.Console;
using System.Text;
using System.IO;
using static System.Math;
namespace AtCoder
{
    class Program
    {
        static public long[] Sarray() { return ReadLine().Split().Select(long.Parse).ToArray(); }
        static public List<long> Slist() { return ReadLine().Split().Select(long.Parse).ToList(); }

        static readonly long Mod = 1000000000 + 7;

        static void Main(string[] args)
        {
            //SetOut(new StreamWriter(OpenStandardOutput()) { AutoFlush = false });
            var S = ReadLine();
            var T = ReadLine();
            for (var i = 0; i < T.Length; ++i)
            {
                var match = true;
                for (var j = 0; j < T.Length; ++j)
                {
                    if (S[j] != T[(i + j)%T.Length])
                    {
                        match = false;
                        break;
                    }
                }
                if(match)
                {
                    WriteLine("Yes");
                    return;
                }
            }
            WriteLine("No");
            //Out.Flush();
        }
    }
}

Measured memory_bytes: 11092
#include<stdio.h>
#include<iostream>
using namespace std;


int main()
{	
	int a,b,c,d,i;

	i = 0;

	cin >> a >> b >> c;


	while (1)
	{
		if (a==b+1)
		{
			break;
		}

		d = c%a;

		if (d == 0)
		{
			i++;
		}

		a++;
	}


	cout << i << endl;


	return 0;
}

Measured memory_bytes: 1164
n, m = gets.chomp.split.map(&:to_i)
as = n.times.map {gets.chomp}
bs = m.times.map {gets.chomp}
(0..n - m).each do |i|
  (0..n - m).each do |j|
    ans_flag = true
    (0..m - 1).each do |x|
      (0..m - 1).each do |y|
        if as[i + x][j + y] != bs[x][y]
          ans_flag = false
          break
        end
      end
      break unless ans_flag
    end
    if ans_flag
      puts "Yes"
      exit 0
    end
  end
end

puts "No"


Measured memory_bytes: 1788
# C - Welcome to AtCoder
from collections import defaultdict


def main():
    N, M, *PS = open(0).read().split()
    is_correct = [0] * (int(N) + 1)
    wa_count = defaultdict(int)
    for p, s in zip(*[iter(PS)] * 2):
        p = int(p)
        if s == "AC":
            is_correct[p] = 1
        else:
            if not is_correct[p]:  # not yet AC and get WA -> +1 penalty
                wa_count[p] += 1
    penalties = sum(cnt for i, cnt in wa_count.items() if is_correct[i])
    print(sum(is_correct), penalties)


if __name__ == "__main__":
    main()


Measured memory_bytes: 24820
#include <cstdio>
#include <cstdlib>
#include <string>
#include <iostream>
using namespace std;

struct Node {
    int key;
    Node *parent, *left, *right;
};


Node *NIL, *root;

void insert(int k) { //insert k
    Node *y = NIL;
    Node *x = root;

    Node *z = (Node *) malloc(sizeof(Node));
    z->key = k;
    z->left = NIL;
    z->right = NIL;

    while ( x!= NIL ) {
        y = x;
        if ( z->key < x->key ) {
            x = x->left;
        } else {
            x = x-> right;
        }
    }

    z->parent = y;

    if(y == NIL) {
        root = z;
    }else if(z->key < y->key) {
        y->left = z;
    }else {
        y->right = z;
    }
}

void inOrder(Node *u) {
    if( u == NIL ) return;
    inOrder(u->left);
    printf(" %d",u->key);
    inOrder(u->right);
}

void preOrder(Node *u) {
    if( u == NIL ) return;
    printf(" %d", u->key);
    preOrder(u->left);
    preOrder(u->right);
}

int main(void) {
    int k,n,i;
    string com;
    scanf("%d", &n);
    for (i = 0 ; i < n ; i++ ) {
        cin >> com;
        if ( com == "insert") {
            scanf("%d", &k);

            insert(k);
        }else if (com == "print") {
            inOrder(root);
            printf("\n");
            preOrder(root);
            printf("\n");
        }
    }
    return 0;
}

Measured memory_bytes: 26708
#include <iostream>
#include <cmath>
#include <algorithm>
#include <vector>
#include <numeric>
#include <iomanip>
#include <utility>

using namespace std;

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(nullptr);
  int n;
  cin >> n;
  vector<pair<double, double>> rs(n);
  for (auto& r : rs) cin >> r.first >> r.second;
  vector<int> indices(n);
  iota(begin(indices), end(indices), 0);
  double total = 0;
  do {
    for (int i = 0; i < n - 1; i++) {
      total += hypot(rs[indices[i]].first - rs[indices[i + 1]].first,
          rs[indices[i]].second - rs[indices[i + 1]].second);
    }
  } while (next_permutation(begin(indices), end(indices)));
  for (int i = 1; i <= n; i++)
    total /= static_cast<double>(i);
  cout << setprecision(10) << total << endl;
}


Measured memory_bytes: 256
#include <algorithm>
#include <climits>
#include <cmath>
#include <iostream>
#include <numeric>
#include <queue>
#include <unordered_map>
#include <vector>

const int mod = 1e9 + 7;
const int kmax = 510000;

long long fact[kmax], fact_inv[kmax], inv[kmax];

void init_comb()
{
    fact[0] = fact[1] = 1;
    fact_inv[0] = fact_inv[1] = 1;
    inv[1] = 1;
    for (int i = 2; i < kmax; i++) {
        fact[i] = fact[i - 1] * i % mod;
        inv[i] = mod - inv[mod % i] * (mod / i) % mod;
        fact_inv[i] = fact_inv[i - 1] * inv[i] % mod;
    }
}

long long comb(int n, int r)
{
    if (n < r) {
        return 0;
    }

    if (n < 0 || r < 0) {
        return 0;
    }

    return fact[n] * (fact_inv[r] * fact_inv[n - r] % mod) % mod;
}

int main()
{
    int n, k;
    std::cin >> n >> k;

    std::vector<int> a(n);
    for (int i = 0; i < n; i++) {
        std::cin >> a[i];
    }

    long long ans = 0;
    for (int num_pop = 0; num_pop <= k; num_pop++) {
        for (int num_pop_from_right = 0; num_pop_from_right <= num_pop; num_pop_from_right++) {
            std::vector<int> copied_a = a;
            std::priority_queue<int, std::vector<int>, std::greater<int>> q;

            for (int i = 0; i < num_pop_from_right && copied_a.size(); i++) {
                q.push(copied_a.back());
                copied_a.pop_back();
            }

            std::reverse(copied_a.begin(), copied_a.end());

            for (int i = 0; i < num_pop - num_pop_from_right && copied_a.size(); i++) {
                q.push(copied_a.back());
                copied_a.pop_back();
            }

            for (int i = 0; i < k - num_pop && q.size() && q.top() < 0; i++) {
                q.pop();
            }

            long long sum = 0;
            while (q.size()) {
                sum += q.top();
                q.pop();
            }

            ans = std::max(ans, sum);
        }
    }

    std::cout << ans << std::endl;
}


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

  sort(a.begin(), a.end());
  int ai = a[n-1];
  rep(i, n) a[i] *= 2;
  int j1 = lower_bound(a.begin(), a.end(), ai) - a.begin();
  int aj1 = a[j1];
  int aj2 = a[j1-1];
  int aj;
  if (abs(aj1 - ai) < abs(aj2 - ai)) aj = aj1 / 2;
  else aj = aj2 / 2;
  printf("%d %d\n", ai, aj);
  return 0;
}

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

typedef long long int ll;
typedef long double ld;

//****************************************************                
#define lp(var,start,end) for (ll var = start; var <end ; ++var)
#define rlp(var,start,end) for(ll var = start; var>=end ; var--)
#define pb push_back
#define mp make_pair
#define pf push_front
#define ff first
#define ss second
#define vll vector<ll>
#define pll pair<ll,ll> 
#define vpll vector<pll>
#define all(X) X.begin(),X.end()
#define endl "\n" //comment it for interactive questions
#define trace1(a) cerr << #a << ": " << a << endl;
#define trace2(a,b) cerr << #a << ": " << a << " " << #b << ": " << b << endl;
#define trace3(a,b,c) cerr << #a << ": " << a << " " << #b << ": " << b << " " << #c << ": " << c << endl;
#define trace4(a,b,c,d) cerr << #a << ": " << a << " " << #b << ": " << b << " " << #c << ": " << c << #d << ": " << d << endl;
#define OC   
#define FAST_IO ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
        //*******************************************************
//Some Functions

const ll MOD = (ll)1e9+7; //change it for other mods

ll powmod(ll a,ll b)
{
   ll res = 1;
   while(b > 0) {
      if(b & 1) res = (res * a) % MOD;
      a = (a*a)%MOD;
      b = b >> 1; 
  }
  return res % MOD;
}

void solve(ll testnum)
{
    ll n,k;
    cin >> n >> k;
    vll a(n);
    for(ll i=0;i<n;i++) {
    	cin >> a[i];
    }
    sort(all(a));
    ll sum = 0;
    for(ll i=0;i<k;i++) {
    	sum += a[i];
    }
    cout << sum << "\n";
}

int main()
{
    FAST_IO;
    #ifdef STIO 
      freopen("input.txt" , "r", stdin);
      freopen("output.txt" , "w", stdout);
    #endif
    ll t = 1;
    // cin >> t;
    for (ll i = 1; i <= t; i++) {
        solve(i);
    }
}

Measured memory_bytes: 3624
n = int(input())
P = [int(s) for s in input().split(' ')]
count = 0
for p0, p1, p2 in zip(P, P[1:], P[2:]):
    if p0 < p1 < p2 or p2 < p1 < p0:
        count +=1
print(count)


Measured memory_bytes: 2940
#include<bits/stdc++.h>
#define ll long long int
#define ull unsigned long long int
#define boost ios_base::sync_with_stdio(false);	cin.tie(0);	cout.tie(0)
#define vi vector<int>
#define P push_back
#define F first
#define S second
#define debug(x) cout<<x<<" "
#define pi vector<pair<int,int> >
#define FOR(i,x,n) for(int i=x;i<n;i++)
using namespace std;
int main(){
    boost;
    int x,a;
    cin>>x>>a;
    if(x<a)cout<<"0";
    else cout<<"10";


    return 0;
}


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

int solve(vector<int> &memo, const vector<int> &h, int k, int i) {
    if (i == 0) return 0;
    if (i == 1) return abs(h[0] - h[1]);
    if (memo[i] != -1) return memo[i];

    memo[i] = INT_MAX;
    for (int j = 1; j <= k; ++j) {
        if (i - j < 0) break;
        memo[i] = min(memo[i], solve(memo, h, k, i - j) + abs(h[i - j] - h[i]));
    }

    return memo[i];
}

int main() {
    int n, k; cin >> n >> k;
    vector<int> h(n);
    for (auto &e : h) cin >> e;

    vector<int> memo(n, -1);
    cout << solve(memo, h, k, n - 1) << endl;
}



Measured memory_bytes: 11968
#include<iostream>
#include<string>
#include<cstdio>
#include<vector>
#include<cmath>
#include<algorithm>
#include<functional>
#include<iomanip>
#include<queue>
#include<ciso646>
#include<random>
#include<map>
#include<set>
#include<complex>
#include<bitset>
using namespace std;
typedef long long ll;
typedef unsigned int ui;
const ll MOD = (1e+9) + 7;
const ll INF = (ll)1000000007 * 1000000007;
typedef pair<int, int> P;
#define stop char nyaa;cin>>nyaa;
#define rep(i,n) for(int i=0;i<n;i++)
#define per(i,n) for(int i=n-1;i>=0;i--)
#define Rep(i,sta,n) for(int i=sta;i<n;i++)
#define rep1(i,n) for(int i=1;i<=n;i++)
#define per1(i,n) for(int i=n;i>=1;i--)
#define Rep1(i,sta,n) for(int i=sta;i<=n;i++)
typedef long double ld;
typedef complex<ld> Point;
const ld eps = 1e-11;
const ld pi = acos(-1.0);
typedef pair<ll, ll> LP;
typedef pair<ld, ld> LDP;
int trans(char t) {
	if (t == 'N')return 0;
	else if (t == 'W')return 1;
	else if (t == 'S')return 2;
	else return 3;
}
int main() {
	int c[2] = {};
	int used[4] = {};
	string s; cin >> s; int len = s.length();
	rep(i, len) {
		int n = trans(s[i]);
		if (!used[n]) {
			used[n] = 1; c[n % 2]++;
		}
	}
	if (c[0] != 1 && c[1] != 1)cout << "Yes" << endl;
	else cout << "No" << endl;
	return 0;
}

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

namespace BreakNumber
{
    class BreakNumber
    {
        static void Main(string[] args)
        {
            int intInputVal = int.Parse(Console.ReadLine()); // 標準入力

            int[] intItems = { 2, 4, 8, 16, 32, 64 }; // 比較値
            int intOutputVal = 1; // 出力結果
            for (int i = 0; i < intItems.Length; i++) {
                if (intItems[i] <= intInputVal)
                {
                    intOutputVal = intItems[i];
                }
            }
           
            // 出力
            Console.WriteLine(intOutputVal);
        }
    }
}


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

using namespace std;
typedef long long ll;
    
int main()
{
    ll X;
    cin >> X;

    int ure = 0;

    int coin500 = X / 500;
    int coin5 = X % 500 / 5;

    cout << coin500 * 1000 + coin5 * 5;

    return 0;
}


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

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

//infinity
#define INTINF 2000000000
#define LONGINF 2000000000

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

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

	REP(i, n) cin >> a[i];
	REP(i, n) cin >> b[i];
	REP(i, n) cin >> c[i];

	sort(a, a+n);
	sort(c, c+n);

	long long sum = 0;
	REP(i, n){
		long long aa = lower_bound(a, a+n, b[i]) - a;
		long long cc = n - (upper_bound(c, c+n, b[i]) - c);
		sum += aa * cc;
	}
	cout << sum << endl;
	return 0;
}


Measured memory_bytes: 2560
//

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
// const int INF = 2147483647;
// const ll INF = 9223372036854775807;
const ll MOD = 1e9 + 7;

// modint: mod 計算を int を扱うように扱える構造体
template<int MOD> struct ModInt {
	long long val;
	constexpr ModInt(long long v = 0) noexcept : val(v % MOD) {
		if (val < 0) val += MOD;
	}
	constexpr int getmod() { return MOD; }
	constexpr ModInt operator - () const noexcept {
		return val ? MOD - val : 0;
	}
	constexpr ModInt operator + (const ModInt& r) const noexcept { return ModInt(*this) += r; }
	constexpr ModInt operator - (const ModInt& r) const noexcept { return ModInt(*this) -= r; }
	constexpr ModInt operator * (const ModInt& r) const noexcept { return ModInt(*this) *= r; }
	constexpr ModInt operator / (const ModInt& r) const noexcept { return ModInt(*this) /= r; }
	constexpr ModInt& operator += (const ModInt& r) noexcept {
		val += r.val;
		if (val >= MOD) val -= MOD;
		return *this;
	}
	constexpr ModInt& operator -= (const ModInt& r) noexcept {
		val -= r.val;
		if (val < 0) val += MOD;
		return *this;
	}
	constexpr ModInt& operator *= (const ModInt& r) noexcept {
		val = val * r.val % MOD;
		return *this;
	}
	constexpr ModInt& operator /= (const ModInt& r) noexcept {
		long long a = r.val, b = MOD, u = 1, v = 0;
		while (b) {
			long long t = a / b;
			a -= t * b; swap(a, b);
			u -= t * v; swap(u, v);
		}
		val = val * u % MOD;
		if (val < 0) val += MOD;
		return *this;
	}
	constexpr bool operator == (const ModInt& r) const noexcept {
		return this->val == r.val;
	}
	constexpr bool operator != (const ModInt& r) const noexcept {
		return this->val != r.val;
	}
	friend constexpr ostream& operator << (ostream &os, const ModInt<MOD>& x) noexcept {
		return os << x.val;
	}
	friend constexpr ModInt<MOD> modpow(const ModInt<MOD> &a, long long n) noexcept {
		if (n == 0) return 1;
		auto t = modpow(a, n / 2);
		t = t * t;
		if (n & 1) t = t * a;
		return t;
	}
};

class Comb {
private:
	int MOD;
	long long* fac;
	long long* finv;
	long long* inv;
public:
	// 事前にテーブルを作成
	Comb(int MAX, int MOD) {
		this->MOD = MOD;

		fac = new long long[MAX + 1];
		finv = new long long[MAX + 1];
		inv = new long long[MAX + 1];

		fac[0] = fac[1] = 1;
		finv[0] = finv[1] = 1;
		inv[1] = 1;
		for (int i = 2; i <= MAX; i++) {
			fac[i] = fac[i - 1] * i % MOD;
			inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
			finv[i] = finv[i - 1] * inv[i] % MOD;
		}
	}

	~Comb() {
		delete[] fac, finv, inv;
	}

	// 二項係数計算
	long long calc(int n, int k){
		if (n < k) return 0;
		if (n < 0 || k < 0) return 0;
		return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
	}
};

using mint = ModInt<MOD>;

int main() {
	int S;
	cin >> S;

	Comb comb = Comb(2001, MOD);

	mint ans = 0;

	for (ll i=1; i*3 <=S; i++) {
		int s = S - i*3;
		ans = ans + (mint)comb.calc(i+s-1, s);
	}

	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 3608
#include <bits/stdc++.h>
using namespace std;
template <typename T> void read(T &x){
	x = 0; int f = 1; char ch = getchar();
	while (!isdigit(ch)) {if (ch == '-') f = -1; ch = getchar();}
	while (isdigit(ch)) {x = x * 10 + ch - '0'; ch = getchar();}
	x *= f;
}
inline void write(int x){if (x > 9) write(x/10); putchar(x%10+'0'); }

int main(){
	int n;
	read(n);
	int x;
	while (n--){
		read(x);
		if (x%2==0&&x%3!=0&&x%5!=0){
			puts("DENIED");
			return 0;
		}
	}
	puts("APPROVED");
    return 0;
}


Measured memory_bytes: 256
using System;
public class Hello{
    public static void Main(){
        // Your code here!
        var array = Console.ReadLine().Split(' ');
        var a = int.Parse(array[0]);
        var b = int.Parse(array[1]);
        var x = int.Parse(array[2]);
        if(a <= x && a+b >= x){
            Console.WriteLine("YES");
        }
        else{
            Console.WriteLine("NO");
        }
    }
}

Measured memory_bytes: 13140
/***************************************************************
	File name: A.cpp
	Author: ljfcnyali
	Create time: 2019年08月04日 星期日 19时56分49秒
***************************************************************/
#include<bits/stdc++.h>

using namespace std;

#define REP(i, a, b) for ( int i = (a), _end_ = (b); i <= _end_; ++ i ) 
#define mem(a) memset ( (a), 0, sizeof ( a ) ) 
#define str(a) strlen ( a ) 
typedef long long LL;

int main()
{
    int a, b, c; scanf("%d%d%d", &a, &b, &c); printf("%d\n", max(0, b + c - a));
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <sstream>
#include <cmath>
#include <algorithm>
#include <fstream>
#include <vector>
#include <memory>
#include <map>
#include <random>
#include <set>
#include <numeric>
#include <iomanip>
#include <bitset>

using namespace std;

const long long oo = 1e18;

class Graph {
    int n;
    vector<vector<pair<long long, int>>> g;
public:
    Graph(int n) : n(n), g(n) {

    }

    void addEdge(int from, int to, long long weight) {
        g[from].push_back({weight, to});
        g[to].push_back({weight, from});
    }

    vector<long long> Dijkstra(int start) {
        vector<long long> ans(n, +oo);
        ans[start] = 0;
        set<pair<long long, int>> pq;
        pq.insert({0, start});

        while (!pq.empty()) {
            auto edge = *pq.begin();
            pq.erase(pq.begin());

            for (auto e:g[edge.second]) {
                if (ans[e.second] > ans[edge.second] + e.first) {
                    pq.erase({ans[e.second], e.second}); // delete old
                    ans[e.second] = ans[edge.second] + e.first;// relax, take it easy
                    pq.insert({ans[e.second], e.second}); // add new
                }
            }
        }
        return ans;
    }
};
double f(long long n, long long m, long long d){
    long long stepm = 1;
    for(int i = 0; i < m; i++){
        stepm *= n;
    }


    long long ans = 0;
    for(int i = 0; i < stepm; i++){
        long long prev = -1e9+2;
        long long deg = 1, res = 0;
        for(int j = 0; j < m; j++){
            int num = (i/deg) % n;
            cout << num;
            deg *= n;
            if(abs(num - prev) == d){
                res++;
            }
            prev = num;
        }
        ans += res;
        cout << " " << res << endl;
    }
    cout << ans;
    return (ans * 1.0) / (1.0*stepm);
}

void run(istream &cin, ostream &cout) {
    long long n, m, d;
    cin >> n >> m >> d;
    double x = (min<double>(min<double>(2 * d, n), 2*(n-d)) + ((d == 0 )?1: 2) * max<double>(0, n - 2 * d)) / (1.0 * n * n);
    
    cout << setprecision(20) << x * (m-1);

}

int main() {
#ifdef  LOCAL
    ifstream cin("input.txt");
    ofstream cout("output.txt");
#else
    cin.tie(0);
    ios::sync_with_stdio(0);
#endif
    run(cin, cout);
    return 0;
}

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

#undef _P
#define _P(...) (void)printf(__VA_ARGS__)
#define FOR(x,to) for(x=0;x<(to);x++)
#define FORR(x,arr) for(auto& x:arr)
#define ITR(x,c) for(__typeof(c.begin()) x=c.begin();x!=c.end();x++)
#define ALL(a) (a.begin()),(a.end())
#define ZERO(a) memset(a,0,sizeof(a))
#define MINUS(a) memset(a,0xff,sizeof(a))
//-------------------------------------------------------

int N,M;

map<int,int> A;


void solve() {
	int i,j,k,l,r,x,y; string s;
	
	cin>>N;
	FOR(i,N) {
		cin>>x;
		A[x]++;
	}
	cin>>M;
	FOR(i,M) {
		cin>>x;
		if(A[x]==0) return _P("NO\n");
		A[x]--;
	}
	_P("YES\n");
	
}


int main(int argc,char** argv){
	string s;int i;
	if(argc==1) ios::sync_with_stdio(false), cin.tie(0);
	FOR(i,argc-1) s+=argv[i+1],s+='\n'; FOR(i,s.size()) ungetc(s[s.size()-1-i],stdin);
	cout.tie(0); solve(); return 0;
}


Measured memory_bytes: 9728
#include<bits/stdc++.h>
using namespace std;
int main(){
  int a,b,c,x,y;
  cin >> a >> b >> c >> x >> y;
  long ans = 0;
  int tmp;
  if(a+b>2*c){
    tmp = min(x,y);
    ans += tmp*2*c;
    x-=tmp;
    y-=tmp;
  }
  if(x>0){
    if(a>2*c) ans += 2*c*x;
    else ans += a*x;
  }
  if(y>0){
    if(b>2*c) ans += 2*c*y;
    else ans += b*y;
  }
  cout <<ans;


  
  
}

Measured memory_bytes: 256
#include <iostream>
using namespace std;
int main() {
  int x;
  int h = 0, m = 0, s = 0;
  cin >> x;
  while (x >= 60 * 60) {
    h += 1;
    x -= 60 * 60;
  }
  while (x >= 60) {
    m += 1;
    x -= 60;
  }
  cout << h << ":" << m << ":" << x << endl;
  return 0;
}

Measured memory_bytes: 1168
#include <iostream>
#include <cstdio>
#include <cmath>
#include <string>
#include <cstring>
#include <algorithm>
#include <iomanip>
#include <cstdlib>
#include <cctype>
#define ll long long
#define PI 3.14159265358979323846
using namespace std;
const int maxn = 1e6+7;

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


Measured memory_bytes: 256
#include "bits/stdc++.h"
#define rep(i,n) for(int i = 0; i < (n); ++i)
using namespace std;
typedef long long int ll;
typedef pair<int, int> P;
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(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	ll t1, t2, a1, a2, b1, b2;
	cin >> t1 >> t2 >> a1 >> a2 >> b1 >> b2;
	ll p = (a1 - b1) * t1;
	ll q = (a2 - b2) * t2;
	if(p > 0){
		p *= -1;
		q *= -1;
	}
	if(p+q < 0) cout << 0 << endl;
	else if(p+q == 0) cout << "infinity" << endl;
	else{
		ll s = (-p) / (p+q);
		ll t = (-p) % (p+q);
		if(t != 0) cout << (s*2 + 1LL) << endl;
		else cout << (s*2) << endl;
	}
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
template <typename T> void read(T &t) {
	t=0; char ch=getchar(); int f=1;
	while ('0'>ch||ch>'9') { if (ch=='-') f=-1; ch=getchar(); }
	do {(t*=10)+=ch-'0';ch=getchar();} while ('0'<=ch&&ch<='9'); t*=f;
}
typedef long long ll;
const int maxn=(2e5)+10;
int n,d[maxn],a[maxn],b[maxn];
ll ans,A,B,s[maxn];
int main() {
	read(n);
	for (int i=1;i<=n;i++) {
		read(a[i]); read(b[i]);
		A+=a[i]; B+=b[i];
		d[i*2-1]=a[i]; d[i*2]=b[i];
	}
	sort(d+1,d+(2*n+1));
	ans=min(A,B);
	for (int i=1;i<=2*n;i++) s[i]=s[i-1]+d[i];
	for (int i=1;i<=n;i++) {
		int pos=n,tmp=0;
		if (a[i]<=d[pos-1]) pos++; else tmp+=a[i];
		if (b[i]<=d[pos-1]) pos++; else tmp+=b[i];
		ans=min(ans,tmp+s[pos-2]);
	}
	printf("%lld\n",ans);
	return 0;
}

Measured memory_bytes: 3328
#define _USE_MATH_DEFINES
#define INF 10000000
#include <iostream>
#include <sstream>
#include <cstdio>
#include <cmath>
#include <algorithm>
#include <queue>
#include <stack>
#include <limits>
#include <map>
#include <string>
#include <cstring>
#include <set>
#include <deque>
#include <bitset>
#include <list>

using namespace std;

typedef long long ll;
typedef pair<int,string> P;

static const double eps = 1e-8;

const int tickets[5] = {0,6000,4000,3000,2000};

int main(){
  int t,n;
  while(~scanf("%d %d",&t,&n)){
    printf("%d\n",tickets[t]*n);
  }
}

Measured memory_bytes: 1188
//#include <bits/stdc++.h>
#include <iostream>
#include <fstream>
#include <vector>
#include <string>
#include <cmath>
#include <algorithm>
#include <map>
#include <iomanip>
#include <stdlib.h>
#include <stdio.h>
#include <queue>
#include <deque>
#include <set>
#include <stack>
#include <time.h>
 
using namespace std;
 
typedef long long ll;
typedef long double ld;
typedef pair<int, int> Pii;
typedef pair<int, ll> Pil;
typedef pair<ll, ll> Pll;
typedef pair<ll, int> Pli;

#define fi first
#define se second
#define mp make_pair
 
const ll MOD = 1e9 + 7;
const ll MOD2 = 998244353;
const ll MOD3 = 1812447359;
const ll INF = 1ll << 62;
const double PI = 2 * asin(1);

void yes() {printf("yes\n");}
void no() {printf("no\n");}
void Yes() {printf("Yes\n");}
void No() {printf("No\n");}
void YES() {printf("YES\n");}
void NO() {printf("NO\n");}


ll A; string S;

int main(){
  cin >> A >> S;
  ll B = 0;
  for (int i = 0; i < S.length(); i++){
    if (S[i] == '.') continue;
    B *= 10; B += S[i] - '0';
  }
  ll ans = A * B / 100;
  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 3632
N=int(input())
syougen=[]
for i in range(N):
  A=int(input())
  X=[list(map(int,input().split())) for i in range(A)]
  syougen.append(X)

def search(l):
  global seigo,syougen,flg
  for x,y in l:
    if seigo[x-1]==100:
      seigo[x-1]=y
      if y==1:
        search(syougen[x-1])
    elif seigo[x-1]!=y:
      flg=False

ans=0
for i in range(N):
  flg=True
  seigo=[100]*N
  seigo[i]=1
  _ans=0
  search(syougen[i])
  if flg:
    if sum(seigo)>100:
      i=0
      while sum(seigo)>100:
        if seigo[i]==100:
          _seigo=seigo[:]
          flg=True
          seigo[i]=1
          search(syougen[i])
          if flg:
            pass
          else:
            seigo=_seigo[:]
            seigo[i]=0
        i+=1
        i%=N
    _ans=sum(seigo)%100
    if _ans>ans:
      ans=_ans
      maxseigo=seigo        
print(ans)

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

int main(){
  int N;
  cin>>N;
  vector<int> V(N),C(N);
  for(int &i:V)
    cin>>i;
  for(int &i:C)
    cin>>i;
  int j=0;
  for(int i=0;i<N;i++)
    if(V[i]>C[i])
      j+=V[i]-C[i];
  cout<<j<<endl;
}

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

struct comp1 {
  bool operator()(const pair<int, int>& a, const pair<int, int>& b) {
    if(a.first != b.first)
      return a.first < b.first;
    return a.second > b.second;
  }
};

struct comp2 {
  bool operator()(const pair<int, int>& a, const pair<int, int>& b) {
    if(a.first != b.first)
      return a.first > b.first;
    return a.second > b.second;
  }
};

void solve() {
  cin>>n;
  vector<string>a(n);
  vector<pair<int, int>> adds, subs;
  
  int tlc = 0, trc = 0;
  for(int i = 0; i < n; i++) {
    cin>>a[i];
    int lc = 0, rc = 0;
    for(auto& c : a[i]) {
      if(c == '(')
        lc++;
      else {
        if(lc)  lc--;
        else  rc++;
      }
    }
    
    if(lc && !rc) tlc += lc;
    else if(!lc && rc)  trc += rc;
    else if(lc && rc) {
      if(lc >= rc)  adds.push_back({rc, lc});
      else  subs.push_back({rc, lc});
    }
  }
  
  sort(adds.begin(), adds.end(), comp1());
  sort(subs.begin(), subs.end(), comp2());
  bool pos = true;
  for(auto& i : adds) {
    if(i.first > tlc) {
      pos = false;
      break;
    }
    else {
      tlc -= i.first;
      tlc += i.second;
    }
  }
  
  for(auto& i : subs) {
    if(i.first > tlc) {
      pos = false;
      break;
    }
    else {
      tlc -= i.first;
      tlc += i.second;
    }
  }
  
  if(pos && tlc == trc) cout<<"Yes\n";
  else  cout<<"No\n";
}
signed main() {
  solve();
  return 0;
}

Measured memory_bytes: 34416
--https://www.lua.org/pil/11.4.html
local List = {}
function List.new ()
  return {first = 0, last = -1}
end

function List.pushleft (list, value)
  local first = list.first - 1
  list.first = first
  list[first] = value
end

function List.pushright (list, value)
  local last = list.last + 1
  list.last = last
  list[last] = value
end

function List.popleft (list)
  local first = list.first
  if first > list.last then return false end
  local value = list[first]
  list[first] = nil
  list.first = first + 1
  return value
end

function List.popright (list)
  local last = list.last
  if list.first > last then return false end
  local value = list[last]
  list[last] = nil
  list.last = last - 1
  return value
end

----------

local n,q=io.read("*n","*n")
local edge={}
local counter={}
for i=1,n do
    counter[i]=0
    edge[i]={}
end
for i=1,n-1 do
    local a,b=io.read("*n","*n")
    edge[a][b]=false
    edge[b][a]=false
end
for i=1,q do
    local p,x=io.read("*n","*n")
    counter[p]=counter[p]+x
end

local que=List.new()
List.pushright(que,1)

while true do
    local a=List.popleft(que)
    if a then
        for b,_ in pairs(edge[a]) do
            if not edge[a][b] then
                counter[b]=counter[b]+counter[a]
                edge[a][b]=true
                edge[b][a]=true
                List.pushright(que,b)
            end
        end
    else
        break
    end
end

print(table.concat(counter," "))

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

using namespace std;

const int MAXN = 101;
struct point {
	string s;
	int p, idx;
	point() {};
	point(string _s, int _p,int _idx) :s(_s), p(_p),idx(_idx) {};
};

bool cmp(point a, point b) {
	if (a.s == b.s) return a.p > b.p;
	return a.s < b.s;
}

int n;
vector<point> v;

int main() {

	cin >> n;

	for (int i = 0; i < n; i++) {
		string s;
		int p;
		cin >> s >> p;

		v.push_back(point(s, p, i + 1));
	}

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

	for (auto next : v) {
		cout << next.idx << "\n";
	}

	return 0;
}

Measured memory_bytes: 256
#include <algorithm>
#include <iostream>
#include <iomanip>
#include <iterator>
#include <list>
#include <map>
#include <queue>
#include <cstring> 
#include <set>
#include <string>
#include <valarray>
#include <vector>
using namespace std;
typedef long long int ll;
typedef long double ld;
#define all(v) v.begin(), v.end()
#define maxe(v) *max_element(v.begin(), v.end())
#define mine(v) *min_element(v.begin(), v.end())
#define pb push_back
#define pf push_front
#define rem 1000000007
#define cont continue

ll gcd(ll a, ll b)
{
    if (a == 0)
        return b;
    return gcd(b%a, a);
}
ll modulo(ll a, ll b)
{
    ll r = a % b;
    return r < 0 ? r + b : r;
}
ll longrem(string k,ll n)
{
    // k is taken into input as a string...
	int now=0;
    for(int i=0;i<k.size();i++)
    {
        now=(now*10)%n;
        now=(now+k[i]-'0')%n;
    }
    return now;    // O( log(k) )/log(10) )
}
ll ncr(ll n,ll k)  
{  
    ll res = 1;  
    if ( k > n - k )  
        k = n - k; 
    for (ll i = 0; i < k; ++i)  
    {  
        res *= (n - i);  
        res /= (i + 1);  
    }  
    return res;  
}

ll binaryToDecimal(ll n) 
{ 
    ll num = n; 
    ll dec_value = 0; 
  
    // Initializing base value to 1, i.e 2^0 
    ll base = 1; 
  
    ll temp = num; 
    while (temp) { 
        ll last_digit = temp % 10; 
        temp = temp / 10; 
  
        dec_value += last_digit * base; 
  
        base = base * 2; 
    } 
  
    return dec_value; 
} 

void decToBinary(int n) 
{ 
    
    int binaryNum[32]; 
  
    int i = 0; 
    while (n > 0) { 
  
         
        binaryNum[i] = n % 2; 
        n = n / 2; 
        i++; 
    } 
  
    // printing binary array in reverse order 
    for (int j = i - 1; j >= 0; j--) 
        cout << binaryNum[j]; 
} 
ll prime(ll n)
{
	ll flag=0;
	if(n==1 || n==2)
	{
		flag=0;
	}
	else 
	{
		if(n%2==0)
			flag=1;
		else
		{
			ll i=3;
			while(i<=sqrt(n) && flag==0)
			{
				if(n%i==0)
					flag=1;
				i=i+3;
			}
		}
	}
	return flag;
}
ll ispal(string str,string s)
{
	ll flag=0;
	reverse(str.begin(), str.end());
	if(str==s)
	{
		flag=1;
	}
	return flag;
}
ll ispalself(string str)
{
	ll flag=0;
	string s=str;
	reverse(str.begin(), str.end());
	if(str==s)
	{
		flag=1;
	}
	return flag;
}
/**************************************************************************************************************************************/
int main()
{
	
	ios::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
	
	
	
	/*ll t;
	cin>>t;
	while(t--)
	{*/
	ll i,n,a,b,cnt=0,sum,ans=0;
	
	cin>>n>>a>>b;
	
	sum=a+b;
	
	ans=(n/sum)*a;
	
	n=n%sum;
	
	ans+=min(n,a);
	
	cout<<ans<<"\n";
	
	
	
	
	
	
			
	//}
}

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

int water[31],sugar[3001];

int main() {

    int a,b,c,d,e,f;

    cin >> a >> b >> c >> d >> e >> f;

    for(int i=1; i<=3000; i++){
        if(i-c >=0 && i-d >= 0){
            sugar[i] = max(sugar[i-c] + c, sugar[i-d] + d);
        }
        else if(i-c >= 0){
            sugar[i] = max(sugar[i-c] + c, sugar[i-1]);
        }
        else if(i-d >= 0){
            sugar[i] = max(sugar[i-d] + d, sugar[i-1]);
        }
        else{
            sugar[i] = sugar[i-1];
        }
    }

    for(int i=1; i<31; i++){
        if(i-a >= 0 && i-b >= 0){
            water[i] = max(water[i-a] + a ,water[i-b] + b);
        }
        else if(i-a >= 0){
            water[i] = max(water[i-a] + a, water[i-1]);
        }
        else if(i-b>= 0){
            water[i] = max(water[i-b] + b, water[i-1]);
        }
        else{
            water[i] = water[i-1];
        }
    }

    pair<int,int> ans = make_pair(100*a,0);


    for(int i=1; i<31; i++){

        if(i*100 >= f){
            break;
        }

        int tmp_max_sugar = sugar[f-water[i]*100]; //入る砂糖の量で最大入る量

        if(tmp_max_sugar > water[i]*e){ //砂糖が解け切らない場合
            tmp_max_sugar = sugar[water[i]*e];
        }

        int use_water = water[i];
        int itr = i;
        while(itr>=0 && water[itr]*e >= tmp_max_sugar){
            use_water = water[itr];
            itr--;
        }



        if(use_water != 0 && static_cast<double>(ans.second)*100.0 /(static_cast<double>(ans.first) + static_cast<double>(ans.second)) <= 100.0*static_cast<double>(tmp_max_sugar) / (static_cast<double>(use_water)*100.0 +
                static_cast<double>(tmp_max_sugar))){
            ans.first = use_water*100;
            ans.second = tmp_max_sugar;
        }

    }

    cout << ans.first + ans.second << " " << ans.second << endl;


    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define int long long
using namespace std;
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; }

class ConvexFullTrick
{
 private:
    vector<pair<int,int>> lines;
    function<bool(int,int)> comp;
 public:
    ConvexFullTrick(function<bool(int,int)> comp=less<int>()):comp(comp){}
    void add(int a,int b){
        // 傾きは単調減少
        pair<int,int> line(a,b);
        while(lines.size()>=2){
            pair<int,int> l1=lines[lines.size()-2];
            pair<int,int> l2=lines[lines.size()-1];
            if(check(l1,l2,line)) break;
            lines.pop_back();
        }
        lines.push_back(line);
    }
    int get(int x){
        int ng=-1,ok=lines.size()-1;
        while(ok-ng>1){
            int mid=(ng+ok)/2;
            if(comp(f(mid,x),f(mid+1,x))) ok=mid;
            else ng=mid;
        }
        return f(ok,x);
    }
    bool check(pair<int,int> l1,pair<int,int> l2,pair<int,int> l3){
        // (l1とl2の交点)<(l2とl3の交点)=>true
        int x=(l2.first-l3.first)*(l2.second-l1.second);
        int y=(l1.first-l2.first)*(l3.second-l2.second);
        return x<y;
    }
    int f(int i,int x){
        return lines[i].first*x+lines[i].second;
    }
};

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

    int N,C; cin>>N>>C;
    vector<int> h(N);
    for(int i=0;i<N;i++) cin>>h[i];

    vector<int> dp(N);
    dp[0]=0;
    ConvexFullTrick cht;
    cht.add(-2*h[0],dp[0]+h[0]*h[0]);
    for(int i=1;i<N;i++){
        dp[i]=cht.get(h[i])+h[i]*h[i]+C;
        cht.add(-2*h[i],dp[i]+h[i]*h[i]);
    }
    cout<<dp[N-1]<<endl;
    return 0;
}

Measured memory_bytes: 9328
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ull = unsigned long long;
#define REP(i,n) for (ll i = 0; i < (n); ++i)


void solve(long long N, long long M, std::vector<long long> p, std::vector<std::string> S){
    vector<bool> ac(N, false);
    vector<ll> num_wa(N, 0);
    REP(i, M){
        p.at(i)--;
        if(S.at(i) == "AC"){
            ac.at(p.at(i)) = true;
        }else if(!ac.at(p.at(i))){
            num_wa.at(p.at(i))++;
        }
    }
    const ll num_ac = accumulate(ac.begin(), ac.end(), 0);
    ll total_num_wa = 0;
    REP(i, N){
        total_num_wa += ac.at(i) * num_wa.at(i);
    }
    cout << num_ac << " " << total_num_wa << endl;
}

// Generated by 1.1.6 https://github.com/kyuridenamida/atcoder-tools
int main(){
    long long N;
    scanf("%lld",&N);
    long long M;
    scanf("%lld",&M);
    std::vector<long long> p(M);
    std::vector<std::string> S(M);
    for(int i = 0 ; i < M ; i++){
        scanf("%lld",&p[i]);
        std::cin >> S[i];
    }
    solve(N, M, std::move(p), std::move(S));
    return 0;
}


Measured memory_bytes: 7296
#!/usr/bin/env python


def main():
    aaa = [111, 222, 333, 444, 555, 666, 777, 888, 999, 1111]
    n = int(input())

    for k in aaa:
        if n <= k:
            print(k)
            break


if __name__ == '__main__':
    main()


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

int main() 
{
    ll n, k;
    cin >> n >> k;
    ll ans = pow(n/k, 3);
    if (k%2==0)
        ans += pow((n+k/2)/k, 3);
    cout << ans;
    return 0;
}

Measured memory_bytes: 512
#pragma region
#include<bits/stdc++.h>
#define _GLIBCXX_DEBUG
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define repr(i, n) for (int i = n; i >= 0; i--)
#define repc(i, m, n) for (int i = m; i < n; i++)
#define reprc(i, m, n) for (int i = m; i > n; i--)
#define all(v) v.begin(), v.end()
#define INF 1e9
#define EPS 1e-10
using namespace std;
typedef long long ll;
#pragma endregion

int main()
{
  int N,K,R,S,P;
  string T;
  cin >> N >> K >> R >> S >> P >> T;
  char B[K+10];

  // long total = 0;
  // for(int i=0; i<N; ++i){
  //   if(B[i%K]!=T[i]){
  //     if(T[i]=='r')
  //       total += P;
  //     else if(T[i]=='s')
  //       total += R;
  //     else if(T[i]=='p')
  //       total += S;
  //     B[i%K] = T[i];
  //   }
  //   else{
  //     B[i%K] = ' ';
  //   }
    
  // }
  long ans = 0;
  for(int i=0; i<N; ++i){
    if(i>=K && T[i] == T[i-K]){
      T[i] = 'q';
    }
    else{
      if(T[i]=='r') ans += P;
      else if(T[i]=='s') ans += R;
      else ans += S;
    }
  }

  cout << ans << endl;

  return 0;
}

    
    /*
    int N,K,R,S,P;
    ll ans = 0;
    string T;
    cin >> N >> K;
    cin >> R >> S >> P;
    cin >> T;
    vector<int> score(N);

    rep(i, N){
        if(T.at(i) == 'r') score.at(i) = P;
        if(T.at(i) == 's') score.at(i) = R;
        if(T.at(i) == 'p') score.at(i) = S;

        if(i >= K && score.at(i) == score.at(i - K)){
            score.at(i) = 0;
        }
    }

    rep(i, N){
        ans += score.at(i);
    }

    cout << ans << endl;
    
}
*/

Measured memory_bytes: 512
#include<stdio.h>
              int main()
              {
                 int a,b,x,y,z;

                 scanf("%d%d",&a,&b);
                 x=a+(a-1);
                 y=b+(b-1);
                 z=a+a;
                 if(x>y)
                     printf("%d",x);

                 else if(a==b)
                     {
                       printf("%d",z);
                     }
                 else
                     printf("%d",y);





              }


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

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

  int s[M][N]={0};
  int k[M];
  int p[M];

  int count=0;

  for(int i=0; i<M; i++){
    cin >> k[i];
    for(int j=0; j<k[i]; j++){
      cin >> s[i][j];
    }
  }

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

  for(int bits=0; bits<(1<<N); bits++){
    int als=0;
    for(int i=0; i<M; i++){
      int sum=0;
      for(int j=0; j<k[i]; j++){
        int mask = (1 << (s[i][j]-1));
        if(bits & mask){
          sum++;
        }
      }
      if(sum%2==p[i]){
        als++;
      }
    }
    if(als == M){
      count++;
    }
  }

  cout << count << endl;

  return 0;
}

Measured memory_bytes: 256
#include<cstdio>
#include<iostream>
#include<cstdlib>
#include<cmath>
#include<vector>
#include<list>
#include<map>
#include<algorithm>

using namespace std;

// a^b % m
long long PowerMod(long long a, long long b, int m)
{
    long long res = 1;

    for (int i = 0; b > 0; i++) {
        if (b & 1) {
            res = (res * a) % m;
        }
        a = (a * a) % m;
        b >>= 1;
    }

    return res;
}

// a! % m
long long FactorialMod(long long a, int m)
{
    long long res = 1;
    for (int i = a; i > 0; i--) {
        res = (res * i) % m;
    }
    return res;
}

// nCr % m
long long CombinationMod(long long n, long long r, int m)
{
    if (r > n / 2) {
        r = n - r;
    }

    long long res = 1;
    for (int i = 0; i < r; i++) {
        res = (res * (n - i)) % m;
    }
    res *= PowerMod(FactorialMod(r, m), m - 2, m);
    res %= m;

    return res;
}

void PrimeFactorization(int x, vector<pair<int, int> >& y)
{
    int xrest = x;

    for (int i = 2; i < x; i++) {
        if (i > xrest) {
            break;
        }
        if (xrest % i == 0) {
            y.push_back(make_pair(i, 1));
            xrest /= i;
            while (xrest % i == 0) {
                y.back().second++;
                xrest /= i;
            }
        }
    }

}

int main()
{
    const int MOD = 1e9 + 7;

    int N, M;
    cin >> N >> M;

    vector<pair<int, int> > v;
    PrimeFactorization(M, v);

    long long ans = 1;
    for (int i = 0; i < v.size(); i++) {
        ans *= CombinationMod(v[i].second + N - 1, v[i].second, MOD);
        ans %= MOD;
    }

    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 256