akhauriyash/Code-Regression huggingface dataset:
import sys
input = sys.stdin.readline

class BaseXor:
    def __init__(self):
        self.size = 0
        self.base = []
    
    def base_calculate(self, x, b):
        return min(x, x ^ b)

    def make_base(self, x):
        for b in self.base:
            x = self.base_calculate(x, b)
        return x
    
    def change_base(self, x):
        for i in range(self.size):
            self.base[i] = self.base_calculate(self.base[i], x)

    def add_base(self, x):
        x = self.make_base(x)
        if x == 0:
            return False
        self.change_base(x)
        self.base.append(x)
        self.size += 1
        return True
    
    def judge_linearly_dependent(self, x):
        for b in self.base:
            x = self.base_calculate(x, b)
        res = True if x else False
        return res

def solve(n, a, s):
    base = BaseXor()
    judge = False
    for i in range(n-1, -1, -1):
        x = s[i]
        if x == "0":
            base.add_base(a[i])
        else:
            judge = base.judge_linearly_dependent(a[i])
            if judge:
                break
    
    res = 1 if judge else 0
    return res

def main():
    t = int(input())
    ans = [0]*t
    for i in range(t):
        n = int(input())
        a = list(map(int, input().split()))
        s = input()
        res = solve(n, a, s)
        ans[i] = res
    print(*ans, sep="\n")
    
if __name__ == "__main__":
    main()

Measured memory_bytes: 9224
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(n);++i)
#define ALL(A) A.begin(), A.end()

using namespace std;

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

const ll MOD = (ll)1e9 + 7LL;

int cnt[1000]; // 1000 is not prime.

void prime_factorize(int a){
	for (int p = 2; p * p <= a; ++p){
		if (a % p == 0){
			int c = 0;
			do{
				a /= p;
				++c;
			}while(a % p == 0);
			cnt[p] += c;
		} // end for
	} // end for

	if (a > 1) ++cnt[a];
}

int main()
{
	memset(cnt, 0, sizeof(cnt));
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	int N; cin >> N;

	for (int i = 1; i <= N; ++i){
		prime_factorize(i);
	} // end for

	ll res = 1LL;
	for (int i = 1; i <= N; ++i){
//		cerr << "i: " << setw(3) << i << " cnt: " << cnt[i] << endl;
		if (cnt[i] != 0){
			res = (res *((ll)cnt[i] + 1LL)) % MOD;
		} // end if
	} // end for

	cout << res << endl;

	return 0;
}

Measured memory_bytes: 256
d,n = map(int,input().split())
if d == 0 and n != 100:
    print(n)
elif d == 0 and n == 100:
    print(101)
elif d == 1 and n != 100:
    print(n*100)
elif d == 1 and n == 100:
    print(10100)
elif d == 2 and n != 100:
    print(n*10000)
else:
    print(1010000)

Measured memory_bytes: 3060
#include <iostream>
#include <cstdio>
#include <string>
#include <cmath>
#include <cctype>
#include <cstdlib>
#include <stack>
#include <queue>
#include <vector>
#include <algorithm>
#include <list>
#include <map>
#include <set>
using namespace std;
 
int main() {
	int n;
	cin >> n;
	long long ans=0;
	for (int i = 1; i <= n; i++) {
		if (i % 3 != 0 && i % 5 != 0) ans += i;
	}
	cout << ans << endl;
}


Measured memory_bytes: 3592
#include <stdio.h>
#include <math.h>

int main(void)
{
	const double pi = M_PI;
	
	int dis, turn;
	int theta = 90;
	double x = 0.0, y = 0.0;
	
	while (1){
		
		scanf("%d,%d", &dis, &turn);
		
		if (dis == 0 && turn == 0) break;
		
		x += cos(theta * 1.0 / 180 * pi) * dis * 1.0;
		y += sin(theta * 1.0 / 180 * pi) * dis * 1.0;
		
		theta =(theta - turn) % 360;
		
	}
	if (x < 0) x = floor(- 1 * x) * -1;
	else       x = floor(x);
	
	if (y < 0) y = floor(- 1 * y) * -1;
	else       y = floor(y);
	
	printf("%.0f\n%.0f\n", x , y);
	
	return (0);
}

Measured memory_bytes: 636
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define ull unsigned long long
#define INF 1e18
#define REPL(i,a,b) for(int i=a;i<a;++i)
#define REPLE(i,a,b) for(int i=a;i<=a;++i)
typedef vector<int> vi;
typedef vector<ll> vll;
typedef pair<int,int> pi;

#define M_PI 3.14159265358979323846

int a[100005];
const int oo = 1e9+10;
const int mod = 7901;

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

int dp[100005];
int n;
int memo[100005];

int dpF(int i){
	if(i == n-1)return 0;
	if(memo[i] != -1)return memo[i];
	
	int ans = abs(a[i] - a[i+1])+dpF(i+1);
	if(i+2 <= n-1){
		ans = min(ans, abs(a[i]-a[i+2])+dpF(i+2));
	}

	return memo[i] = ans;
}

void solve(){
	cin>>n;
	for(int i = 0 ; i < n ; ++i)cin>>a[i];
	
	memset(memo, -1 , sizeof memo);
	cout << dpF(0) << '\n';
	return;
	dp[0] = 0;
	dp[1] = abs(a[1] - a[0]);
	for(int i = 2 ; i < n ; ++i){
		dp[i] = min(abs(a[i]-a[i-1]) + dp[i-1] , abs(a[i]-a[i-2])+dp[i-2]);
	}
	cout << dp[n-1] << '\n';
}
int main(){   
    ios::sync_with_stdio(0);cin.tie(0);
	int t=1;
	while(t--){
		solve();
	}
}

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

const int N = (int)1e5;

int dat[N+5];

int main() {
    for (int i=0; i<N+3; i++) dat[i] = 0;

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

    int res = 0, penalty = 0;
    for (int i=1; i<=m; i++) {
        int a; scanf("%d", &a);
        char s[5]; scanf("%s", s);

        if (dat[a] >= 0) {
            if (s[0] == 'A') {
                res += 1;
                penalty += dat[a];
                dat[a] = -1;
            } else {
                dat[a] += 1;
            }
        }
    }

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


Measured memory_bytes: 640
from fractions import gcd
import math

def lcm(x, y):
    return (x * y) // gcd(x, y)
a,b,c,d = map(int,input().split())
all = b - a + 1
if c == 1 or d == 1:
    print(0)
    exit()

cd = lcm(c, d)

cs = b//c - math.ceil(a/c) + 1
ds = b//d - math.ceil(a/d) + 1
cds = b//cd - math.ceil(a/cd) + 1

print(all - cs - ds + cds)


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

int main() {
	int N;
	cin >> N;
	priority_queue<int> a;
	for (int i = 0; i < N; i++) {
		int j;
		cin >> j;
		a.push(j);
	}
	int A = 0, B = 0;
	while (true) {
		A += a.top();
		a.pop();
		if (a.empty())
			break;
		B += a.top();
		a.pop();
		if (a.empty())
			break;
	}
	cout << A - B << endl;
	return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <string>
#include <sstream>
#include <algorithm>
#include <cmath>
#include <vector>
#include <set>
#include <map>
#include <queue>
using namespace std;

int main() {
    int H,W;
    cin>>H>>W;
    vector<string> s(H);
    for (int i=0; i<H; i++) {
        cin>>s[i];
    }
    
    bool can=true;
    for (int i=0; i<H && can; i++) {
        for (int j=0; j<W; j++) {
            
            
            if (s[i][j]=='#') {
                bool neighbor=false;
                // 左
                if (i!=0) {
                    if (s[i-1][j]=='#') {
                        neighbor=true;
                    }
                }
                // 右
                if (i!=H-1) {
                    if (s[i+1][j]=='#') {
                        neighbor=true;
                    }
                }
                // 上
                if (j!=0) {
                    if (s[i][j-1]=='#') {
                        neighbor=true;
                    }
                }
                // 下
                if (j!=W-1) {
                    if (s[i][j+1]=='#') {
                        neighbor=true;
                    }
                }
                
                if (!neighbor) {
                    can=false;
                    break;
                }
            }
            
        }
    }
    
    if (can) {
        cout << "Yes" << endl;
    }
    else{
        cout << "No" << endl;
    }
}


Measured memory_bytes: 256
#include <stdio.h>
#include <iostream>
#include <map>

using namespace std;

typedef long long int ll;

ll max( ll p, ll q ) {
	if( p > q ) return p;
	return q;
}
ll solve(ll N);

int main(void) {

	ll N = 1;
	while(true) {
		cin >> N;
		if( N == 0 ) { break; }
		cout << solve(N) << endl;
	}

	return 0;
}

ll solve( ll N ) {

	ll ans = 0;
	map<int,ll> mp;	//mp[ID]=??\??£?????????
	map<int,ll> sum;
		mp[0] = -1;
		sum[0] = 0;

	for( int i = 0; i < N; i++ ) {

		int M, D, h, m, p;
		char e;

		scanf("%d/%d %d:%d %c %d", &M,&D,&h,&m,&e,&p);

		if( e == 'I' ) {
			mp[p] = m+60*h;
			if( mp.find(p) == mp.end() ) {
				//?????????ID
				sum[p] = 0;
			}
		} else {
			//??????
			//??°????????????????????§??´?????????
			if( p == 0 ) {
				//?\??\??????????
				for(auto it = mp.begin();it!=mp.end();++it){
					if( (*it).first == 0 || mp[(*it).first] < 0 ) { continue; }
					sum[(*it).first] += m+60*h - max( mp[p], mp[(*it).first] );
				}
			} else {
				//????????°???????????????
				if( mp[0] >= 0 ) {
					sum[p] += m+60*h - max( mp[p], mp[0] );
				}
			}
			mp[p] = -1;
		}

	}

	sum[0] = 0;
	for( auto it = sum.begin(); it != sum.end(); ++it ) {
		ans = max( (*it).second, ans );
	}

	return ans;

}

Measured memory_bytes: 3156
object Main extends App {
  val in = new java.util.Scanner(System.in)
  val N, K, S = in.nextInt
  val nS = if (S == 1000000000) S - 1 else S + 1
  println((Array.fill(K)(S) ++ Array.fill(N - K)(nS)).mkString(" "))
}

Measured memory_bytes: 40792
import math 
N,M=map(int,input().split())
def combination(n,r):
    if n<2:
        return 0
    else:
        return math.factorial(n) // (math.factorial(n - r) * math.factorial(r))

n=combination(N,2)
m=combination(M,2)
print(n+m)

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

namespace CSharpSample01
{


    class Program
    {
        static void Insert_Sort(int[] data_ary)
        {
            int change_index = 0;
            int change_val = 0;
            int shift_index = 0;
            int length = data_ary.Count();

            Console.WriteLine(string.Join(" ", data_ary));

            for (change_index = 1; change_index < length; change_index++)
            {
                change_val = data_ary[change_index];

                for (shift_index = change_index - 1; shift_index >= 0; shift_index--)
                {
                    if (data_ary[shift_index] > change_val)
                    {
                        data_ary[shift_index + 1] = data_ary[shift_index];
                    }
                    else if (data_ary[shift_index] <= change_val)
                    {
                        data_ary[shift_index + 1] = change_val;
                        break;
                    }

                    if (shift_index == 0)
                    {
                        data_ary[0] = change_val;
                    }

                }

                Console.WriteLine(string.Join(" ", data_ary));

            }


        }

        static void Main(string[] args)
        {
            int n = int.Parse(Console.ReadLine());
            int[] data_ary = Console.ReadLine().Split(' ').Select(x => int.Parse(x)).ToArray();

            Insert_Sort(data_ary);

            
        }
    }
}


Measured memory_bytes: 18316
#include<bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < (n); i++)
#define rrep(i,n) for(int i = 1; i <= (n); i++)
#define COUT(x) cout << (x) << endl
#define ALL(a) (a.begin()),(a.end())
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
typedef pair<ll, ll> LP;
const ll LINF = 1LL<<60;
const int INF = 1001001001;
const int MOD = 1000000007;

/* --------------------------------------------------- */
ll gcd(ll a, ll b) {
	if (b == 0) { return a; }
	if (a < b) { return gcd(b, a); }
	return gcd(b, a % b);
}

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

int main() {
    ll a, b, c, d;
    cin >> a >> b >> c >> d;
    // 範囲内の{Cの倍数+Dの倍数-LCM(C, D)の倍数}の余事象
    ll ca, cb, da, db, c_da, c_db;
    ca = (a - 1)/ c;
    cb = b / c;
    da = (a - 1) / d;
    db = b / d;
    c_da = (a - 1) / lcm(c, d);
    c_db = b / lcm(c, d);

    COUT((b - a + 1) - ((cb - ca) + (db - da) - (c_db - c_da)));

    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <map>
#include <unordered_map>
#include <set>
#include <unordered_set>
#include <cmath>
#include <algorithm>
#include <climits>
#include <iomanip>
#include <string.h>
#define endl "\n"
#define debug(x) cout << #x << " : " << x << endl;
#define debug2(x, y) cout << #x << " : " << x  << ", " << #y << " : " << y << endl;
#define FASTIO ios_base::sync_with_stdio(false),cin.tie(0);
typedef long long ll;
using namespace std;

int main()
{
	FASTIO
	
	ll n, W;
	cin >> n >> W;

	ll dp[n + 1][W + 1];
	memset(dp, 0, sizeof(dp));
	ll w[n + 1];
	ll v[n + 1];
	for(ll i = 1; i <= n; i ++)
		cin >> w[i] >> v[i];

	for(ll i = 1; i <= W; i ++)
	{
		for(ll j = 1; j <= n; j ++)
		{
			if(w[j] <= i)
				dp[j][i] = max(dp[j - 1][i - w[j]] + v[j], dp[j - 1][i]);
			else
				dp[j][i] = dp[j - 1][i];
		}
	}

	ll ans = dp[n][W];
	cout << ans << endl;
}

Measured memory_bytes: 82444
#include <stdio.h>
#include <ctype.h>
#include <string.h>
#include <malloc.h>
#include <stdlib.h>
 
typedef struct _node {
    int key;
    struct _node *next;
    struct _node *prev;
} NODE, *PNODE;
 
PNODE root;
 
void init(void) {
    root = (NODE *)malloc(sizeof(NODE));
    root->next = root;
    root->prev = root;
}
 
void insert(int key) {
    PNODE t = (NODE *)malloc(sizeof(NODE));
    t->key = key;
    t->next = root->next;
    t->prev = root;
    root->next->prev = t;
    root->next = t;
}
 
void deleteNode(PNODE node) {
    if (node == root) {
        return;
    }
    node->next->prev = node->prev;
    node->prev->next = node->next;
    free(node);
}
 
void _delete(int key) {
    PNODE cur = root->next;
    while (cur != root) {
        if (cur->key == key) {
            deleteNode(cur);
            return;
        }
        cur = cur->next;
    }
}
 
void deleteFirst(void) {
    deleteNode(root->next);
}
 
void deleteLast(void) {
    deleteNode(root->prev);
}
 
void printNodes(void) {
    PNODE cur = root->next;
    while (1) {
        printf("%d", cur->key);
        cur = cur->next;
        if (cur != root) {
            putchar(' ');
        }
        else {
            break;
        }
    }
    putchar('\n');
}
 
void release(void) {
    PNODE tmp, cur = root->next;
    while (cur != root) {
        tmp = cur;
        cur = cur->next;
        deleteNode(tmp);
    }
    free(root);
}
 
int main(void) {
    char cmd[100];
    int n, i, f;
    int key;
 
    init();
 
    scanf("%d", &n);
 
    f = 0;
    while (scanf("%s", cmd) > 0) {
        if (cmd[0] == 'i') {
            f = 1;
        }
        else if (cmd[0] == 'd') {
            switch (cmd[6]) {
            case '\0':
                f = 2;
                break;
            case 'F':
                deleteFirst();
                break;
            case 'L':
                deleteLast();
                break;
            }
        }
        else {
            key = atoi(cmd);
            if (f == 1) {
                insert(key);
            }
            else if (f == 2) {
                _delete(key);
            }
        }
    }
 
    printNodes();
 
    release();
 
    return 0;
}

Measured memory_bytes: 31848
S = input()
T = input()

if len(S) < len(T):
    print("UNRESTORABLE")
else:
    for i in reversed(range(len(S)-len(T)+1)):
        flg = True
        for j in range(len(T)):
            if S[i+j] != "?":
                if S[i+j] != T[j]:
                    flg = False
        if flg:
            list_s = list(S)
            for j in range(len(T)):
                list_s[i+j] = T[j]

            for j in range(len(list_s)):
                if list_s[j] == "?":
                    list_s[j] = "a"
            print(*list_s, sep="")
            exit()

    print("UNRESTORABLE")

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

#define rep(i,x,y) for(int i=(x);i<(y);++i)
#define debug(x) #x << "=" << (x)

#ifdef DEBUG
#define _GLIBCXX_DEBUG
#define print(x) std::cerr << debug(x) << " (L:" << __LINE__ << ")" << std::endl
#else
#define print(x)
#endif

const int inf=1e9;
const int64_t inf64=1e18;
const double eps=1e-9;

template <typename T> ostream &operator<<(ostream &os, const vector<T> &vec){
    os << "[";
    for (const auto &v : vec) {
    	os << v << ",";
    }
    os << "]";
    return os;
}

using i64=int64_t;

void solve(){
    int n,a,b;
    cin >> n >> a >> b;
    vector<i64> v(n);
    rep(i,0,n) cin >> v[i];
    pair<i64,i64> dp[50][51];
    dp[0][1]=make_pair(v[0],1);
    dp[0][0]=make_pair(0,1);
    rep(i,1,n){
        dp[i][0]=make_pair(0,1);
        rep(j,1,i+2){
            if(v[i]+dp[i-1][j-1].first>dp[i-1][j].first){
                dp[i][j]=make_pair(v[i]+dp[i-1][j-1].first,dp[i-1][j-1].second);
            }else if(v[i]+dp[i-1][j-1].first==dp[i-1][j].first){
                dp[i][j]=make_pair(dp[i-1][j].first,dp[i-1][j-1].second+dp[i-1][j].second);
            }else dp[i][j]=dp[i-1][j];
        }
    }

    long double ma=0;
    i64 num=0;
    rep(i,a,b+1){
        if(abs(ma-(long double)dp[n-1][i].first/i)<eps){
            num+=dp[n-1][i].second;
        }else if(ma<(long double)dp[n-1][i].first/i){
            ma=(long double)dp[n-1][i].first/i;
            num=dp[n-1][i].second;
        }
    }
    cout << ma << endl << num << endl;
}

int main(){
    std::cin.tie(0);
    std::ios::sync_with_stdio(false);
    cout.setf(ios::fixed);
    cout.precision(10);
    solve();
    return 0;
}


Measured memory_bytes: 256
/*
 *  Created on: 26 / 4 / 2020
 *  Author:     Eslam Waheed
 */
#include <bits/stdc++.h>
//#include <bits/BIGINT.h>
using namespace std;

#define _CRT_SECURE_NO_WARNINGS
#define __USE_MINGW_ANSI_STDIO
#define Eslam__Waheed ios_base::sync_with_stdio(false);cout.tie(NULL);cin.tie(NULL);

#define ll   long long
#define ull  unsigned ll
#define dd   double
#define ld   long dd
#define ss   string

#define pb      push_back
#define all(c)  c.begin(), c.end()
#define rall(c) c.rbegin(), c.rend()
#define stp(n)  cout << fixed << setprecision(n)
#define iq(v)   v.resize(unique(v.begin(),v.end())-v.begin())
#define sz(s)   (ll)(s.size())
#define endl    '\n'

#define loop(i,m,n)  for(ll i=m;i<n;i++)

ll gcd(ll a, ll b) { return !b ? abs(a) : gcd(b, a % b); }
ll lcm(ll a, ll b) { return abs(a / gcd(a, b)) * b; }

//const ll mod = 1e9 + 7;
//__int128
/*
 you can ^_^ (•‿•)

( إن الله وملائكته يصلون على النبي يا أيها الذين آمنوا صلوا عليه وسلموا تسليما )
*/
int main()
{
    //stp(20);
    Eslam__Waheed
        ll n; cin >> n;
    set<ss>st;
    while (n--)
    {
        ss s; cin >> s;
        st.emplace(s);
    }
    cout << st.size();
}

Measured memory_bytes: 19244
#include <iostream>
#include <cmath>
#include <iomanip>
#include <cstdio>
#include <cstdlib>
#include <cstring>

using namespace std;

typedef uint64_t u64;
typedef int64_t s64;
typedef uint32_t u32;
typedef int32_t s32;

#define MAX(x, y) ((x) < (y) ? (y) : (x))
#define MIN(x, y) ((x) > (y) ? (y) : (x))

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

#define CEIL(x, y) (((x) + (y) - 1)/ (y))

u64 N, T[5];

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

    cin >> N >> T[0] >> T[1] >> T[2] >> T[3] >> T[4];

    u64 min = T[0];
    for (int i = 1; i < 5; ++i)
    {
        min = MIN(min, T[i]);
    }

    cout << 5 + CEIL(N, min) - 1 << "\n";


    return 0;
}



Measured memory_bytes: 256
import java.util.Scanner;

public class Main{
    public static void main(String[] args){
	Scanner s = new Scanner(System.in);
	int a = s.nextInt();
	int b = s.nextInt();

	int d = a / b;
	int r = a % b;
	double f = (double)a / b;
	System.out.println(d+" "+r+" "+String.format("%.5f",f));
    }
}



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

#define ll long long
#define ull unsigned long long

int main(void) {
    ll D, N;
    ll base;
    cin >> D >> N;
    base = pow(100, D);
    if(N != 100) cout << N * base << endl;
    else cout << 101 * base << endl;
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
//#include <math.h>
#include <string>
//#include <time.h>
//#include <conio.h>
#include <algorithm>
using namespace std;

int main()
{
	int n;
	cin >> n;
	int *arr = new int[n];

	for (int i = 0; i < n; i++)
		scanf("%d", &arr[i]);
	sort(arr, arr + n);
	int a = 0, b = 0;
	for (int i = n - 1; i > 0;i--)
		if (arr[i] == arr[i - 1])
		{

			if (a == 0)
				a = arr[i];
			else b = arr[i];
			i--;
			if (a != 0 && b != 0)
				break;
		}
	long long ans = (long long)(a)*(long long)(b);
	cout << ans;
	return 0;
}

Measured memory_bytes: 640
#include<stdio.h>

int main() {
    
  int i,j,v,m,a,N,p;
  int A[1000];

  scanf("%d",&N);
 
  for(i=0;i<N;i++) {
    scanf("%d",&A[i]);
   
  }
for(p=0;p<N-1;p++) {
      printf("%d ",A[p]);     
    }
    printf("%d",A[p]);
    printf("\n");
  for(i=1;i<=N-1;i++) {
    v = A[i];
    j=i-1;
    while(j>=0 && A[j]>v) {
      
      A[j+1] = A[j];
      j--;
    }
    A[j+1]=v;
  

    for(p=0;p<N-1;p++) {
      printf("%d ",A[p]);     
    }
    printf("%d",A[p]);
    printf("\n");
}
  return 0;
}




Measured memory_bytes: 2124
#include<bits/stdc++.h>
using namespace std;
#define int long long int
#define mk make_pair
#define pb push_back
#define vi vector<int>
#define x first
#define y second
#define ms(a,b)  memset(a, b, sizeof(a))
#define rep(i,a,b)  for(int i=a;i<b;i++)
#define M 1000005
int dp[401][401];
signed main(){
    ios_base::sync_with_stdio(false); 
    cin.tie(NULL);
    cout.tie(NULL);
    int n;
    cin>>n;
    int a[n+1],pre[401]={0};
    for(int i=0;i<n;i++)cin>>a[i];
    for(int i=0;i<n;i++)for(int j=0;j<n;j++)dp[i][j]=((i==j) ? 0 : 1e18);

    pre[0]=a[0];
    for(int i=1;i<n;i++)pre[i]=pre[i-1]+a[i];

    for(int i=0;i<n-1;i++)
        dp[i][i+1]=a[i]+a[i+1];
    // dp[0][0]=0;
    for(int c=3;c<=n;c++){
        for(int i=0;i<n-c+1;i++){
            int j=i+c-1;
            for(int k=i;k<j;k++){
                dp[i][j] = min(dp[i][j],
                    dp[i][k]+dp[k+1][j] +
                        pre[j] - ((i>0) ? pre[i-1] : 0));
            }
        }
    }
    cout<<dp[0][n-1];
    return 0;
}

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

int main(){
    int n, a, b;
    cin >> n >> a >> b;
    while (1){
        if (a+1 != b) a++;
        else if (a-1 != 0) a--;
        else{
            cout << "Borys" << endl;
            exit(0);
        }
        if (b-1 != a) b--;
        else if (b+1 != n+1) b++;
        else{
            cout << "Alice" << endl;
            exit(0);
        }
    }
}


Measured memory_bytes: 256
n, m, c = map(int, input().split())
b = list(map(int, input().split()))  
a = [[int(i) for i in input().split()] for i in range(n)]
cnt = 0
list1 = []
list2 = []
for j in range(n):
    for k in range(m):
        integer = a[j][k] * b[k]
        list1.append(integer)
    list2.insert(0, list1)
    list1 = []
for l in range(n):
    if sum(list2[l]) + c > 0:
        cnt += 1 
print(cnt)

Measured memory_bytes: 3064
#include<bits/stdc++.h>
using namespace std;
int main(){
	int m,d;
	cin>>m>>d;
	int count =0;
	for(int i=22;i<=d;i++){
		if(i%10>=2&&i/10>=2){
		
		if((i%10)*(i/10)<=m){
	//	cout<<i<<endl;
		count++;
	}
}
	}
	cout<<count<<endl;
	return 0;
}

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

#if MYDEBUG
#include "lib/cp_debug.hpp"
#else
#define DBG(...) ;
#endif
#if __cplusplus <= 201402L
template <typename T>
T gcd(T a, T b) { return ((a % b == 0) ? b : gcd(b, a % b)); }
template <typename T>
T lcm(T a, T b) { return a / gcd(a, b) * b; }
#endif
using LL = long long;
constexpr LL LINF = 334ll << 53;
constexpr int INF = 15 << 26;
constexpr LL MOD = 1E9 + 7;

namespace Problem {
using namespace std;

class Solver {
 public:
  int n;
  Solver(LL n) : n(n){};

  void solve() {
  }
};
class Solver2 {
 public:
  int n, m;
  Solver2(LL n, LL m) : n(n), m(m){};

  void solve() {
    int ans = 0;
    ans += n * (n - 1) / 2;
    ans += m * (m - 1) / 2;
    cout << ans << endl;
  }
};
}  // namespace Problem

int main() {
  std::cin.tie(0);
  std::ios_base::sync_with_stdio(false);
  // std::cout << std::fixed << std::setprecision(12);
  long long n = 0, m;
  std::cin >> n >> m;

  Problem::Solver2 sol(n, m);
  sol.solve();
  return 0;
}


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

using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<string> vs;
typedef vector<char> vc;
typedef vector<vc> vvc;
typedef vector<bool> vb;
typedef pair<int, int> pii;
typedef pair<char, char> pcc;

#define ZP(a, len) setfill('0') << setw(len) << right << a
const int INF = 1e9;
const int MOD = 1e9 + 7;
const int dx[4] = {0, 1, 0, -1}, dy[4] = {1, 0, -1, 0};
const ll LINF = 1e11;

ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; }

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


void solve() {
    int a, b;
    cin >> a >> b;

    int ans = a * 3 + b;
    ans /= 2;
    cout << ans << "\n";
}


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

    solve();
    return 0;
}


Measured memory_bytes: 892
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(int)n;i++)
#define rep1(i,n) for(int i=1;i<=(int)n;i++)
#define sp(n) cout << fixed << setprecision(n)
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
typedef long long ll;
using namespace std;
int main(void){
    ll n;cin>>n;
    map<ll,ll> mp;
    rep(i,n){
        int a;cin>>a;
        mp[a]++;
        mp[a-1]++;
        mp[a+1]++;
    }
    ll res=0;
    for(auto& p:mp)chmax(res,p.second);
    cout<<res<<endl;
}

Measured memory_bytes: 9524
import sys
t=list(input())

if t[-1] == '?':
    t[-1] = 'D'

if len(t) == 1:
    pass
else:
    for i in range(len(t)):
        if i == 0 and t[i+1] == 'P' and t[0] == '?':
            t[i] = 'D'
            continue
        elif i == 0 and t[0] == '?':
            t[i] = 'P'
            continue
        try:
            if t[i-1] == 'P' and t[i] == '?':
                t[i] = 'D'
            elif t[i-1] == 'D' and t[i+1] == 'D' and t[i] == '?':
                t[i] = 'P'
            elif t[i-1] == 'D' and t[i+1] == 'P' and t[i] == '?':
                t[i] = 'D'
            elif t[i-1] == 'D' and t[i+1] == '?' and t[i] == '?':
                t[i] = 'P'
        except IndexError:
            pass

print(''.join(t))


Measured memory_bytes: 10992
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <queue>
#include <string>
#include <map>
#include <set>
#include <tuple>
#include <deque>
#include <numeric>
#include <bitset>
#include <iomanip>
#include <cassert>
#include <chrono>
#include <random>
#include <limits>
#include <iterator>
#include <functional>
#include <sstream>
using namespace std;

typedef long long ll;
typedef pair<int, int> P;
typedef pair<int, double> Pid;
typedef pair<double, int> Pdi;
typedef pair<ll, int> Pl;
typedef pair<int, pair<int, int>> PP;
const double PI = 3.1415926535897932;   // acos(-1)
const double EPS = 1e-15;
const ll mod = 1e+9 + 7;
const int INF = 1001001001;

#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)
#define chadd(x, y) x = (x + y) % mod

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

    int n;
    cin >> n;
    vector<int> a(n);
    for(int i = 0; i < n; ++i)  cin >> a[i];
    int sum = accumulate(a.begin(), a.end(), 0);
    if(sum % 10 != 0){
        cout << sum << endl;
        return 0;
    }
    sort(a.begin(), a.end());
    for(int i = 0; i < n; ++i){
        if(a[i] % 10 != 0){
            sum -= a[i];
            break;
        }
    }
    if(sum % 10 == 0)   sum = 0;
    cout << sum << endl;
}

Measured memory_bytes: 256
///
// File:  a.go
// Author: ymiyamoto
//
// Created on Fri Mar 30 07:33:26 2018
//
package main

import (
	"fmt"
)

var x, y int

func min(a, b int) int {
	if a < b {
		return a
	}
	return b
}

func main() {
	fmt.Scan(&x, &y)

	count := 1 << 30
	if x <= y {
		count = min(count, y-x)
	}
	if -x <= y {
		count = min(count, y+x+1)
	}
	if x <= -y {
		count = min(count, -y-x+1)
	}
	if -x <= -y {
		count = min(count, -y+x+2)
	}

	fmt.Println(count)
}


Measured memory_bytes: 512
#include<bits/stdc++.h>
#define Fst first
#define Snd second
#define RG register
#define mp make_pair
#define mem(a,b) memset(a,b,sizeof(a))
using namespace std;
typedef long long LL;
typedef long double LD;
typedef unsigned int UI;
typedef unsigned long long ULL;
template<typename T> inline void read(T& x) {
	char c = getchar();
	bool f = false;
	for (x = 0; !isdigit(c); c = getchar()) {
		if (c == '-') {
			f = true;
		}
	}
	for (; isdigit(c); c = getchar()) {
		x = x * 10 + c - '0';
	}
	if (f) {
		x = -x;
	}
}
template<typename T, typename... U> inline void read(T& x, U& ... y) {
	read(x), read(y...);
}
const int N=1e5+10;
int n,m,p,cnt;
int ID[N*5],head[N*5],X[N],Y[N];
bool vis[N*5];
map<int,int> S[410][2];
bitset<410> F[N*5],GG;
struct Edge {
  int to,last;
  Edge () {}
  Edge (int a,int b) :to(a),last(b) {}
}edge[N*10];
void ADD(int a,int b) {
  //printf("!%d %d\n",a,b);
  edge[++p]=Edge(b,head[a]); head[a]=p;
}
void DFS(int u) {
  if(vis[u]) return;
  vis[u]=true;
  if(ID[u]) F[u].set(ID[u]);
  for(int i=head[u];i;i=edge[i].last) {
    int v=edge[i].to;
    DFS(v);
    F[u]|=F[v];
  }
}
//#define rua
int main() {
//	ios::sync_with_stdio(false);
#ifdef rua
	freopen("GG.in","r",stdin);
#endif
  read(n,m);
  for(int i=1;i<=m;++i) {
    read(X[i],Y[i]);
    S[X[i]][0][i]=++cnt;
    S[X[i]][1][i]=++cnt;
    S[Y[i]][0][i]=++cnt;
    S[Y[i]][1][i]=++cnt;
  }
  for(int i=1;i<=n;++i) S[i][0][m+1]=++cnt,S[i][1][m+1]=++cnt;
  for(int i=1;i<=m;++i) {
    int x=X[i],y=Y[i];
    ADD(S[x][1][i],(*S[y][1].lower_bound(i+1)).Snd);
    ADD((*S[x][0].lower_bound(i+1)).Snd,(*S[y][1].lower_bound(i+1)).Snd);
    ADD((*S[x][0].lower_bound(i+1)).Snd,S[y][0][i]);
    //ADD(S[x][0][i],(*S[y][1].lower_bound(i+1)).Snd);
    ADD(S[y][1][i],(*S[x][1].lower_bound(i+1)).Snd);
    ADD((*S[y][0].lower_bound(i+1)).Snd,(*S[x][1].lower_bound(i+1)).Snd);
    ADD((*S[y][0].lower_bound(i+1)).Snd,S[x][0][i]);
    //ADD(S[y][0][i],(*S[x][1].lower_bound(i+1)).Snd);
  }
  for(int i=1;i<=n;++i) {
    ID[S[i][1][m+1]]=i;
    //printf("!#%d :%d %d\n",i,S[i][0][m+1],S[i][1][m+1]);
    map<int,int> ::iterator a,b;
    a=S[i][0].begin(); b=a; ++b;
    while(b!=S[i][0].end()) {
      ADD((*b).Snd,(*a).Snd);
      a=b; ++b;
    }
    a=S[i][1].begin(); b=a; ++b;
    while(b!=S[i][1].end()) {
      ADD((*a).Snd,(*b).Snd);
      a=b; ++b;
    }
  }
  for(int i=1;i<=cnt;++i) if(!vis[i]) DFS(i);
  for(int i=1;i<=n;++i) {
    int u=S[i][0][m+1];
    if(F[u].test(i)) GG.set(i);
  }
  //for(int i=1;i<=n;++i) printf("%d ",GG.test(i)); puts("");
  int res=0;
  for(int i=1;i<=n;++i) {
    int u=S[i][0][m+1];
    F[u]|=GG;
    if(F[u].test(i)) continue;
    res+=n-1-F[u].count();
    //printf("#%d %d\n",i,n-1-F[u].count());
  }
  printf("%d\n",res/2);
	return 0;
}


Measured memory_bytes: 53888
//int a = stoi(c); 文字列をintへ
//小文字から大文字
//transform(a.begin(), a.end(), a.begin(), ::toupper);
//数値計算 個数以外はdouble
//map<キー,値> p は辞書。p[キー] = 値
//map 全探索
//auto begin = p.begin(), end = p.end();
//for (auto it = begin; it != end; it++) {}
//mapのキー：it->first mapのバリュー：it->second
//大文字判定 isupper(文字) 小文字判定 islower(文字)
//do{}while(next_permutation(ALL(配列)))
//小文字に対応する文字コード：S[i] - 'a'
//文字コード→小文字：(char)(数字+'a')
//グラフの距離:隣接行列で扱う
//bool型　初期値はTrue
//島渡りの問題：中間ノードに着目
//背反な事象にちゃんとわける
//チェックリストはマップを使う
//数が大きい時の比較はstring型で行う
//全て0になったか調べたい->0になるたびにcntする
//例外処理は最初にする
//x = p^m + q^n...の約数の個数:(n+1)*(m+1)....
//N!のどの素因数で何回割れるか
//⇔1~Nまでの数がそれぞれどの素因数で何回割り切れるかの和
//パズルの問題->一般化して全探索
//数が大きい時のせぐふぉはコードテストで試してみる
//stack<ll> s;
//s.push(要素);s.top();s.pop();
//queue<ll> q;
//q.push(要素);q.front();q.pop();
//同じ作業繰り返す系の問題：収束先を見つける
//関係性は隣接行列で記録
//過半数：N/2.0で判定
//ある量からある量を引く系の問題：端から定義してやる
#include <bits/stdc++.h>
#define rep(i,N) for(int i = 0; i < N;i++)
#define ALL(a) (a).begin(),(a).end()
#define ll long long int
using namespace std;

//円周率
const double PI = 3.14159265358979323846;
//割るやつ
const ll MOD = (pow(10, 9) + 7);

// K進数でのNの桁数
ll dig(ll N, ll K) {
	ll dig = 0;
	while (N) {
		dig++;
		N /= K;
	}
	return dig;
}
// a,bの最大公約数
ll gcd(ll a, ll b) {
	if (b == 0) return a;
	return gcd(b, a%b);
}

//a,bの最小公倍数
ll lcm(ll a, ll b) {
	ll g = gcd(a, b);
	return a / g * b;
}

//階乗計算
ll f(ll n) {
	if (n == 0 || n == 1) return 1;
	else return (n * f(n - 1));
}

//Nのd桁目の数
ll dignum(ll N, ll d) {
	ll x = pow(10, d);
	N %= x;
	ll y = pow(10, d - 1);
	N /= y;
	return N;
}

//Nをdで何回割れるか
ll divcnt(ll N, ll d) {
	ll ans = 0;
	while (1) {
		if (N%d == 0) {
			ans++;
			N /= d;
		}
		else break;
	}

	return ans;
}

//素数判定
bool prime(ll num) {
	if (num < 2) return false;
	else if (num == 2) return true;
	else if (num % 2 == 0) return false;
	double sqrtNum = sqrt(num);
	for (int i = 3; i <= sqrtNum; i += 2) {
		if (num % i == 0) return false;
	}
	return true;
}

//フィボナッチ数列
vector<ll> memo(pow(10, 6) + 1);
ll fibo(ll n) {
	if (n == 1) return 1;
	else if (n == 2) return 1;
	else if (memo[n] != 0) return memo[n];
	else return memo[n] = fibo(n - 1) + f(n - 2);
}

int main() {
	ll N; cin >> N;
	vector<ll> A(N + 1);
	for (int i = 1; i <= N; i++)cin >> A[i];

	map<ll, ll> p;
	for (int i = 1; i <= N; i++) p[i - A[i]]++;

	ll ans = 0;
	for (int i = 1; i <= N; i++) {
		ans += p[i + A[i]];
	}

	cout << ans << endl;
}

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

int main() {
    int R, G, B, n;
    cin >> R >> G >> B >> n;

    int ans = 0;
    for (int r = 0; r <= n / R; r++) {
        for (int g = 0; g <= n / G; g++) {
            int b = (n - r * R - g * G) / B;
            if (b < 0 || b > n / B) continue;
            if (R * r + G * g + B * b == n) ans++;
        }
    }

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


Measured memory_bytes: 3600
import java.util.ArrayList;
import java.util.Scanner;

public class Main {
	public static void main(String[] args){
		Scanner s = new Scanner(System.in);
		ArrayList<Integer> a = new ArrayList<Integer>();

		while(true){
			int m = s.nextInt();
			if(m == 0){
				break;
			}

			int change = 1000 - m;

			a.add(count(change));
		}

		for(int i = 0; i < a.size(); i++){
			System.out.println(a.get(i));
		}

	}

	static int count(int change){
		int c = 0;
		while(change != 0){
			if(change >= 500){
				change -= 500;
				c++;
			}
			else if(change >= 100){
				change -= 100;
				c++;
			}
			else if(change >= 50){
				change -= 50;
				c++;
			}
			else if(change >= 10){
				change -= 10;
				c++;
			}
			else if(change >= 5){
				change -= 5;
				c++;
			}
			else if(change >= 1){
				change -= 1;
				c++;
			}
		}
		return c;
	}

}

Measured memory_bytes: 17168
import java.util.*;

public class Main {

    public static void main(String args[]) {

        Scanner sc = new Scanner(System.in);
        int n = Integer.parseInt(sc.next());
        HashMap<String, Integer> s = new HashMap<>();

        long result = 0;
        for (int i = 0; i < n; i++) {
            String[] arrS = sc.next().split("");
            Arrays.sort(arrS);
            StringBuilder sb = new StringBuilder();
            for (String c : arrS) {
                sb.append(c);
            }
            String key = sb.toString();
            if (s.containsKey(key)) {
                result += s.get(key);
                s.put(key, s.get(key) + 1);
            } else {
                s.put(key, 1);
            }
        }

        System.out.println(result);
    }
}

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

using namespace std;

const int MAX = 100;
const int WHITE = 0;
const int GRAY = 1;
const int BLACK = 2;

int N;
int M[MAX][MAX];
int C[MAX];

int d[MAX], f[MAX];
int tt;

void dfs_visit(int u) {
    C[u] = GRAY;
    d[u] = ++tt;
    for (int i = 0; i < N; i++) {
        if (M[u][i] == 1 && C[i] == WHITE) {
            dfs_visit(i);
        }
    }
    C[u] = BLACK;
    f[u] = ++tt;
    
}

void dfs() {
    for (int i = 0; i < N; i++) {
        if (C[i] == WHITE) {
            dfs_visit(i);
        }
    }
    
    for (int i = 0; i < N; i++) {
        printf("%d %d %d\n", i + 1, d[i], f[i]);
    }
}

int main() {
    int u, k;
    
    scanf("%d", &N);
    for (int i = 0; i < N; i++) {
        scanf("%d %d", &u, &k);
        u--;
        for (int j = 0; j < k; j++) {
            int v;
            scanf("%d", &v);
            v--;
            M[u][v] = 1;
        }
    }
    
    dfs();

    return 0;
}



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

#define MX 100005
int A[MX];
int dp[MX];

int F(int n){
    if (n == 1){
        return dp[n] = 0;
    }
    if (n == 2){
        return dp[n] = abs(A[2] - A[1]);
    }
    if (dp[n] != -1) return dp[n];

    return dp[n] = min(F(n - 1) + abs(A[n] - A[n-1]),
               F(n - 2) + abs(A[n] - A[n-2]));
}

int main()
{
    int n; cin >> n;
    for (int i = 1; i <= n; i++){
        cin >> A[i];
        dp[i] = -1;
    }

    dp[1] = 0;
    dp[2] = abs(A[1] - A[2]);

    for (int i = 3; i <= n; i++){
        dp[i] = min(dp[i-1] + abs(A[i] - A[i-1]),
                    dp[i-2] + abs(A[i] - A[i-2]));
    }
    cout << dp[n] << endl;
    return 0;
}


Measured memory_bytes: 1024
#include<bits/stdc++.h>
#define MOD 1000000007
using namespace std;
typedef long long ll;
int main () {
    ios_base::sync_with_stdio(false);
    ll N,K,ans;
    cin>>N>>K;
    ans = 0;
    for(ll i=K;i<=N+1;i++) {   
        ll L = i*(i-1)/2;
        ll R = N*i-L;
        ans+=R-L+1;
    }
    cout<<ans%MOD<<"\n";
    return 0;
}

Measured memory_bytes: 3632
# Candies
N = int(input())
A1 = list(map(int, input().split()))
A2 = list(map(int, input().split()))
ans = 0
for i in range(N):
    A1_sum = 0
    A2_sum = 0
    A1_sum = sum(A1[i] for i in range(i+1))
    A2_sum = sum(A2[i] for i in range(i,N))

    tmp = A1_sum+A2_sum
    if ans <= tmp:
        ans = tmp
    else:
        pass

print(ans)


Measured memory_bytes: 3064
#include <bits/stdc++.h>
#include <iostream>
#include <vector>
#include <string>
#include <numeric>
#include <iostream>
#include <cmath>
#include <algorithm>
#include <iomanip>
#include <queue>
#include <tuple>

#define rep(i,n) for(ll i=0;i<n;i++)
#define dup(x,y) (((x)+(y)-1)/(y)) // dup * y >= x なる最小のdup.
using namespace std;
typedef long long ll;
using Graph = vector<vector<ll>>;
ll gcd(ll a, ll b) { return b?gcd(b,a%b):a;}
ll lcm(ll a, ll b) { return a/gcd(a,b)*b;}
//	std::cout<<std::fixed<<std::setprecision(10);

int main() {
	int n, m;
	cin >> n >> m;
	if(n==m) cout << "Yes" << endl;
	else cout << "No" << endl;

	return 0;
}



Measured memory_bytes: 256
let () =
  let rec read () =
    let (n,m) = Scanf.scanf " %d %d\n" (fun x y -> (x,y)) in
    if n = 0 && m = 0 then ()
    else
      begin
        let q = Queue.create () in
        for i = 1 to n do
          Queue.push i q
        done;
        let rec loop q cnt =
          if Queue.length q = 1 then
            print_endline (string_of_int (Queue.pop q))
          else if cnt mod m = 0 then
            let _ = Queue.pop q in loop q 1
          else
            begin Queue.push (Queue.pop q) q;loop q (cnt+1) end
        in loop q 1 ;read ()
      end
  in read ()
;;

Measured memory_bytes: 10760
import sys

def countSumOf(vNum, n):
    if n < 0 or vNum * 9 < n: return 0
    if vNum == 1: return 1
    
    result = 0
    for x in range(10):
        result += countSumOf(vNum-1, n-x)
    return result

for line in sys.stdin:
    n = int(line)
    print countSumOf(4, n)

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

using namespace std;

inline double add(double a, double b){
    return abs(a+b)<(1e-10)*(abs(a)+abs(b)) ? 0.0 : a+b;
}

struct vec{
    double x,y;
    vec operator-(vec b){
        return (vec){add(x,-b.x),add(y,-b.y)};
    }
    vec operator+(vec b){
        return (vec){add(x,b.x),add(y,b.y)};
    }
    vec operator*(double d){
        return (vec){x*d,y*d};
    }
    double dot(vec v){
        return add(x*v.x,y*v.y);
    }
    double cross(vec v){
        return add(x*v.y,-y*v.x);
    }
    double norm(){
        return sqrt(x*x+y*y);
    }
};

int ccw(vec& a, vec& b, vec& c){
    vec ab = b-a, ac = c-a;
    double o = ab.cross(ac);
    if(o>0) return 1; //CCW
    if(o<0) return -1; //CW
    if(ab.dot(ac)<0){
        return 2; //C-A-B
    }else{
        if(ab.dot(ab)<ac.dot(ac)){
            return -2; //A-B-C
        }else{
            return 0; //A-C-B
        }
    }
}

int main(){
    int n;
    cin >> n;
    vec v;
    vector<vec> V,C1,C2;
    vector<vec>::iterator ite;
    while(n--){
        cin >> v.x >> v.y;
        V.push_back(v);
    }
    sort(V.begin(),V.end(),[](const vec& a, const vec& b){return a.y==b.y ? a.x < b.x : a.y< b.y;});
    C1.push_back(V[0]),C1.push_back(V[1]);
    for(auto i=V.begin()+2; i!=V.end();++i){
        C1.push_back(*i);        
        while(ite=C1.end()-1, C1.size()>2&&ccw(*(ite-2),*(ite-1),*ite)==-1){
            C1.erase(ite-1);
        }
    }
    C1.pop_back();

    sort(V.begin(),V.end(),[](const vec& a, const vec& b){return a.y==b.y ? a.x > b.x : a.y>b.y;});
    C2.push_back(V[0]),C2.push_back(V[1]);
    for(auto i=V.begin()+2; i!=V.end();++i){
        C2.push_back(*i);
        while(ite=C2.end()-1, C2.size()>2&&ccw(*(ite-2),*(ite-1),*ite)==-1){
            C2.erase(ite-1);
        }
    }
    C2.pop_back();

    cout << C1.size()+C2.size() << endl;
    for(auto& i : C1) cout << i.x << " " << i.y << endl;
    for(auto& i : C2) cout << i.x << " " << i.y << endl;
    return 0;
}

Measured memory_bytes: 6476
import Data.List

judge _ [] = []
judge t (j:js) =
  let r = head $ dropWhile (\(i,v) -> v > j) t
  in
    r:(judge t js)

hist [] = []
hist x@(xh:xs) =
  let l = length $ takeWhile (== xh) x
      r = dropWhile (== xh) x
  in
    (xh,l):(hist r)

ans n m i =
  let t = zip [1..] $ take n i
      j = drop n i
      r = judge t j
      h = hist $ sort $ map fst r
      a = fst $ maximumBy (\ (v0,n0) (v1,n1) -> compare n0 n1) h 
  in
    a

main = do
  l <- getLine
  c <- getContents
  let [n,m] = map read $ words l :: [Int]
      i = map read $ lines c :: [Int]
      o = ans n m i
  print o



Measured memory_bytes: 4960
n = input()
a = list(map(int,input().split()))

count = 0
odd = 1
b = -1
a.append(-1)
for i in a:
    
    if i == b and b != -1:
        odd += 1
    if i != b and b != -1:
        count += odd//2
        odd = 1
        #print(a)
    b = i
    if i == -1:
        count += odd//2
    #print(i,b,odd,count)
print(count)

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

typedef long long ll;
typedef pair<int,int> P;
int dx[] = {-1, 1, 0,  0};
int dy[] = { 0, 0, 1, -1};

 
int main(){
  ll n;
  cin >> n;
  priority_queue<ll, vector<ll>, greater<ll>> que;
  que.push(3LL);
  que.push(5LL);
  que.push(7LL);
  vector<ll> ans;
  while(true){
    ll tmp =  que.top();
    que.pop();
    if(tmp>n) break;
    ans.push_back(tmp);
    que.push(tmp*10+3LL);
    que.push(tmp*10+5LL);
    que.push(tmp*10+7LL);
  }
  int cnt = 0;
  for(int i=0; i<ans.size(); i++){
    string k = to_string(ans[i]);
    set<int> st;
    for(int j=0; j<k.length(); j++){
      st.insert(k[j]);
    }
    if(st.size()==3) cnt++;
  }
  cout << cnt << endl;
  return 0;
}


Measured memory_bytes: 1144
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define fsp(x) fixed << setprecision(x)
#define xout cerr
const ll inf = LLONG_MAX;
const long double pi = acosl(-1);
const char endk = '\n';
void Yes() {cout << "Yes" << endl;}
void No() {cout << "No" << endl;}
void YES() {cout << "YES" << endl;}
void NO() {cout << "NO" << endl;}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    //const ll mod = 1e9 + 7;
    //const ll mod = 998244353;

	ll n;
	cin >> n;
	ll ac = 0, wa = 0, tle = 0, re = 0;
	while (n--) {
		string s;
		cin >> s;
		if (s == "AC") ac++;
		if (s == "WA") wa++;
		if (s == "TLE") tle++;
		if (s == "RE") re++;
	}
	cout << "AC x " << ac << endl;
	cout << "WA x " << wa << endl;
	cout << "TLE x " << tle << endl;
	cout << "RE x " << re << endl;
}

Measured memory_bytes: 3656
/**
 * code generated by JHelper
 * More info: https://github.com/AlexeyDmitriev/JHelper
 * @author yassin
 */

#include <fstream>
#include <iostream>
#include <vector>
#include <string>
#include <utility>
#include <algorithm>
#include <map>
#include <set>
#include <cmath>
#include <cstdlib>
#include <tuple>
#include <queue>
#include <functional>
#include <stack>
#include <numeric>
#include <cassert>
#include <sstream>

using namespace std;

class apc001_d {
private:
    int dfs(int u, const vector<vector<int>> &g, vector<int> &vis,
            const vector<int> &a)
    {
        vis[u] = 1;
        int res = u;
        for (int v : g[u]) {
            if (!vis[v]) {
                int tmp = dfs(v, g, vis, a);
                if (a[tmp] < a[res]) {
                    res = tmp;
                }
            }
        }
        return res;
    }
public:
    void solve(istream& in, ostream& out) {
        int N, M;
        in >> N >> M;
        vector<int> a(N);
        for (int i = 0; i < N; ++i) {
            in >> a[i];
        }
        vector<vector<int>> g(N);
        for (int i = 0; i < M; ++i) {
            int x, y;
            in >> x >> y;
            g[x].push_back(y);
            g[y].push_back(x);
        }
        if (M == N - 1) {
            out << 0 << "\n";
            return;
        }
        int num_edges = N - 1 - M;
        int num_vert = 2 * num_edges;
        if (N < num_vert) {
            out << "Impossible\n";
            return;
        }
        long long cost = 0;
        vector<int> vis(N, 0);
        for (int u = 0; u < N; ++u) {
            if (!vis[u]) {
                int v = dfs(u, g, vis, a);
                cost += a[v];
                --num_vert;
                a[v] = 2'000'000'000;
            }
        }
        sort(a.begin(), a.end());
        for (int i = 0; i < num_vert; ++i) {
            cost += a[i];
        }
        out << cost << "\n";
    }
};


int main() {
	std::ios::sync_with_stdio(false); cin.tie(nullptr);
	apc001_d solver;
	std::istream& in(std::cin);
	std::ostream& out(std::cout);
	solver.solve(in, out);
	return 0;
}


Measured memory_bytes: 6528
n,m=map(int,input().split())
mod=10**9+7
dp=[1]*(n+1)
for _ in range(m):
    i=int(input())
    dp[i]=0
for i in range(n+1):
    if dp[i]==0 or i < 2: continue
    else: dp[i]=(dp[i-1]+dp[i-2])%mod
print(dp[-1])

Measured memory_bytes: 6900
#include <iostream>
#include <limits>
#include <queue>
#include <tuple>
#include <vector>
#define loop(i, a, n) for (int i = (a); i < (n); i++)
#define rep(i, n) loop(i, 0, n)
template<typename A, typename B> bool cmin(A &a, const B &b) { return a > b ? (a = b, true) : false; }
template<typename T> std::istream &operator>>(std::istream &is, std::vector<T> &v) {
  for (T &x : v) is >> x;
  return is;
}
using namespace std;

using Weight = int;
struct Edge {
  int src, dst;
  Weight weight;
  Edge(const int s = 0, const int d = 0, const Weight w = 0) : src(s), dst(d), weight(w) {}
};

using Edges = std::vector<Edge>;

class Graph {
  std::vector<Edges> g;

public:
  Graph(const int size = 0) : g(size) {}
  size_t size() const { return g.size(); }
  const Edges &operator[](const int i) const { return g[i]; }
  void addArc(const int src, const int dst, const Weight w) { g[src].emplace_back(src, dst, w); }
  void addEdge(const int node1, const int node2, const Weight w) {
    addArc(node1, node2, w);
    addArc(node2, node1, w);
  }
};

template<int inf = std::numeric_limits<Weight>::max() / 8> std::vector<Weight> dijkstra(const Graph &g, const int src) {
  using state = std::pair<Weight, int>;
  std::priority_queue<state, std::vector<state>, std::greater<state>> q;
  std::vector<Weight> dist(g.size(), inf);
  dist[src] = 0;
  q.emplace(0, src);
  while (q.size()) {
    Weight d;
    int v;
    std::tie(d, v) = q.top();
    q.pop();
    if (dist[v] < d) continue;
    for (auto &e : g[v]) {
      if (cmin(dist[e.dst], dist[v] + e.weight)) q.emplace(dist[e.dst], e.dst);
    }
  }
  return dist;
}

int main() {
  int n, m, s, t;
  cin >> n >> m >> s >> t;
  --s, --t;
  vector<int> d(n);
  cin >> d;
  Graph g(n);
  while (m--) {
    int a, b;
    cin >> a >> b;
    --a, --b;
    g.addArc(a, b, d[b]);
  }
  loop(i, 1, n) g.addArc(i, i - 1, 0);
  cout << dijkstra(g, s)[t] << endl;
}

Measured memory_bytes: 12056