akhauriyash/Code-Regression huggingface dataset:
#include<iostream>
#include<iomanip>
#include<string>
#include<cstdlib>
#include<cmath>
#include<algorithm>
#include<vector>

using namespace std;

int minimum;
vector<string> check;

void calc(int num, string cards) {

	string card;

	if(num+1 < cards.length() && num%4 < 3 && cards[num] == cards[num+1]) {
		card = cards;
		card.erase(card.begin()+num+1);
		card.erase(card.begin()+num);
		if(find(check.begin(), check.end(), card) == check.end()) {
			check.push_back(card);
			calc(0, card);
		}
	}
	if(num+4 < cards.length() && cards[num] == cards[num+4]) {
		card = cards;
		card.erase(card.begin()+num+4);
		card.erase(card.begin()+num);
		if(find(check.begin(), check.end(), card) == check.end()) {
			check.push_back(card);
			calc(0, card);
		}
	}
	if(num+3 < cards.length() && num%4 > 0 && cards[num] == cards[num+3]) {
		card = cards;
		card.erase(card.begin()+num+3);
		card.erase(card.begin()+num);
		if(find(check.begin(), check.end(), card) == check.end()) {
			check.push_back(card);
			calc(0, card);
		}
	}
	if(num+5 < cards.length() && num%4 < 3 && cards[num] == cards[num+5]) {
		card = cards;
		card.erase(card.begin()+num+5);
		card.erase(card.begin()+num);
		if(find(check.begin(), check.end(), card) == check.end()) {
			check.push_back(card);
			calc(0, card);
		}
	}

	if(num+1 < cards.length()) calc(num+1, cards);
	else if(cards.length() < minimum) minimum = cards.length();
}

int main() {
	int N;
	cin >> N;
	string cards;
	char input;

	for(int i=0; i<N; i++) {
		check.clear();
		minimum=20;
		cards = "";

		for(int j=0; j<20; j++) {
			cin >> input;
			cards.push_back(input);
		}

		for(int j=0; j<20; j++) {
			calc(j, cards);
		}
		cout << minimum << endl;
	}

	return 0;
}

Measured memory_bytes: 1292
from itertools import accumulate
from bisect import bisect_right
N = int(input())
A = list(map(int, input().split()))

# 累積和を前計算
cumsum = list(accumulate(A))
cumsum.insert(0, 0)

#print(cumsum)
ans = float('inf')
# 真ん中を全探索
for i in range(2, N-1):
    #print(A[:i], A[i:])
    # 左の真ん中
    LC = cumsum[i] / 2

    LX = bisect_right(cumsum, LC)
    #print(LX)
    # 超えるべきか超えないべきか
    if abs(cumsum[LX-1] - LC) < abs(cumsum[LX] - LC):
        LX -= 1

    # 右の真ん中
    RC = (cumsum[N] + cumsum[i]) / 2
    RX = bisect_right(cumsum, RC)
    # 超えるべきか超えないべきか
    if abs(cumsum[RX-1] - RC) < abs(cumsum[RX] - RC):
        RX -= 1

    P, Q, R, S = cumsum[LX], cumsum[i]-cumsum[LX], cumsum[RX]-cumsum[i], cumsum[N]-cumsum[RX]
    ans = min(ans, max(P, Q, R, S) - min(P, Q, R, S))

print(ans)


Measured memory_bytes: 24180
import java.math.BigDecimal;
import java.util.Scanner;

public class Main {

    /**
     * お金
     */
    private static final String MONEY = "100000";

    /**
     * 利子
     */
    private static final String INTEREST_RATE = "0.05";

    /**
     * @param args n週間
     */
    public static void main(String[] args) {

        Scanner in = new Scanner(System.in);
        int weeks = in.nextInt();

        //借金を計算します。
        int debt = calcDebt(MONEY, INTEREST_RATE, weeks);

        System.out.println(debt);
        in.close();
    }

    /**
     * n週間後の借金を計算。<br>
     * @param money 借金
     * @param interestRate 利子
     * @param weeks n週間
     * @return n週間後の借金
     */
    private static int calcDebt(String money, String interestRate, int weeks) {

        BigDecimal debt = new BigDecimal(money);

        for (int i = 0; i < weeks; i++) {
            debt = debt.add(calcInterest(debt, INTEREST_RATE));
        }

        return debt.intValue();
    }

    /**
     * 利子から借金の上乗せ金額を計算。上乗せ金額が1000未満の場合は切り上げる。<br>
     * @param debt 借金
     * @param interestRate 利子
     * @return 上乗せ金額
     */
    static BigDecimal calcInterest(BigDecimal debt, String interestRate) {

        debt = debt.multiply(new BigDecimal(interestRate));

        return debt.setScale(-3, BigDecimal.ROUND_UP);
    }
}

Measured memory_bytes: 17240
li_a = list(input().split())
li_a += list(input().split())
li_a += list(input().split())
n = int(input())

for i in range(n):
    b = input()
    if b in li_a:
        idx = li_a.index(b)
        li_a[idx] = "o"
if any(
    [all(a == "o" for a in li_a[:3]),
    all(a == "o" for a in li_a[3:6]),
    all(a == "o" for a in li_a[6:]),
    all(a == "o" for a in li_a[::3]),
    all(a == "o" for a in li_a[1::3]),
    all(a == "o" for a in li_a[2::3]),
    all(a == "o" for a in li_a[::4]),
    all(a == "o" for a in li_a[2:8:2])]
    ):
    print("Yes")
else:
    print("No")


Measured memory_bytes: 3064
#include<bits/stdc++.h>
using namespace std;
#define int long long
//#define d long double
#define pii pair<int,int>
#define pb push_back
#define inf (int)1e18
#define init(x,a) memset(x,a,sizeof(x))
#define all(c) c.begin(),c.end()
int const mod=998244353;
int const mod1=1000000007;
int toint(const string &s) {stringstream ss; ss << s; int x; ss >> x; return x;}
string tostring ( int number ) {stringstream ss; ss << number; return ss.str();}
#define out(x) cout<<#x<<" = "<<" "<<x<<"\n";
#define trace1(x)                cerr<<#x<<": "<<x<<endl
#define trace2(x, y)             cerr<<#x<<": "<<x<<" | "<<#y<<": "<<y<<endl
#define trace3(x, y, z)          cerr<<#x<<":" <<x<<" | "<<#y<<": "<<y<<" | "<<#z<<": "<<z<<endl
 #define haha ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
// *** Using PBDS ***
// typedef tree<long long, null_type, less<long long>, rb_tree_tag, 
//              tree_order_statistics_node_update> 
//                 os; 
// *** Using PBDS ***
int modexp(int x, int n){
	if(n==0){
		return 1;
	}
	else if(n&1){
		return (modexp((x*x)%mod, n/2)%mod * x%mod)%mod;
	}
	else{
		return (modexp((x*x)%mod, n/2)%mod);
	}
}
 
int modinv(int n)
{
	return modexp(n,mod-2);
}
bool comp(pii a,pii b)
{
    if(a.first==b.first)
    return a.second<b.second;
    return a.first>b.first;
    
}

struct custom_hash {
    static uint64_t splitmix64(uint64_t x) {
        // http://xorshift.di.unimi.it/splitmix64.c
        x += 0x9e3779b97f4a7c15;
        x = (x ^ (x >> 30)) * 0xbf58476d1ce4e5b9;
        x = (x ^ (x >> 27)) * 0x94d049bb133111eb;
        return x ^ (x >> 31);
    }

    size_t operator()(uint64_t x) const {
        static const uint64_t FIXED_RANDOM = chrono::steady_clock::now().time_since_epoch().count();
        return splitmix64(x + FIXED_RANDOM);
    }
};
//unordered_map<long long, int, custom_hash> safe_map;



signed main()
{
	haha
	int a,b,c,d;
	cin>>a>>b>>c>>d;
	while(1)
	{
	    c-=b;
	    if(c<=0)
	    {
	        cout<<"Yes";
	        return 0;
	    }
	    a-=d;
	     if(a<=0)
	    {
	        cout<<"No";
	        return 0;
	    }
	    
	}
	
	
}


  
    

Measured memory_bytes: 3664
#include <bits/stdc++.h>
#define ll long long
using namespace std;
vector<vector<ll>>dp;
vector<ll>val,wei;
ll n;
ll solve(int i,int cap)
{
	if(i==n || cap<=0) return 0;
	if(dp[i][cap]!=-1) return dp[i][cap];
	if(cap < wei[i])
	{
		dp[i][cap]=solve(i+1,cap);
		return dp[i][cap];
	}
	ll include=solve(i+1,cap-wei[i])+val[i];
	ll exclude = solve(i+1,cap);
	dp[i][cap] = max(include,exclude);
	return dp[i][cap];
}
int main() {
	// your code goes here
	int w;
	cin>>n>>w;
	val.resize(n);
	wei.resize(n);
	for(int i=0;i<n;i++)
	cin>>wei[i]>>val[i];
	dp.resize(n+1,vector<ll>(w+1,-1));
	ll ans = solve(0,w);
	cout<<ans;
	return 0;
}

Measured memory_bytes: 83192
using System;

namespace atcoderA
{
    class MainClass
    {
        public static void Main(string[] args)
        {
            int[] input = Array.ConvertAll(Console.ReadLine().Split(' '), int.Parse);
            int A = input[0];
            int B = input[1];
            if (A + B < 24)
            {
                Console.WriteLine(A + B);
            }
            else
            {
                Console.WriteLine(A + B - 24);
            }
        }
    }
}

Measured memory_bytes: 11092
//semicolon less Java
class Main{
    public static void main(String[] args){
        for(String[] str : new String[][]{{"CODEFESTIVAL2016",
            new java.util.Scanner(System.in).next()}}){

            for(int[] var : new int[][]{{0, 0}}){
                while(var[0] < str[0].length()){
                    if(str[0].charAt(var[0]) != str[1].charAt(var[0])){
                        if(var[1]++ > 0){}
                    }
                    if(var[0]++ > 0){}
                }
                if(System.out.printf("%d\n", var[1]) == null){}
            }
        }
    }
}

Measured memory_bytes: 9804
import sys
readline = sys.stdin.buffer.readline
sys.setrecursionlimit(10 ** 8)
INF = float('inf')
MOD = 10 ** 9 + 7


def main():
    H, W = map(int, readline().split())
    alphabet = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ'
    for i in range(H):
        S = readline().decode('utf-8').strip().split()
        for j in range(W):
            if S[j]=='snuke':
                ans = alphabet[j] + str(i+1)
                print(ans)
                sys.exit()

if __name__ == '__main__':
    main()

Measured memory_bytes: 3064
#include <stdio.h>

#define INFTY 1000000001
#define MAX 200000

void merge(int *, int, int, int);
void mergeSort(int *, int, int);

long cnt=0;

int main(void)
{
	int i, n, A[MAX];
	
	scanf("%d",&n);
	for (i=0; i<n; i++) {
		scanf("%d",&A[i]);
	}
	
	mergeSort(A, 0, n);
	
	printf("%ld\n",cnt);
	
	return 0;
}

void merge(int *A, int left, int mid, int right)
{
	int i, j, n1, n2, k;
	int L[MAX/2 +2], R[MAX/2 +2];
	
	n1 = mid - left;
	n2 = right - mid;
	for (i=0; i<n1; i++) {
		L[i] = A[left + i];
	}
	for (i=0; i<n2; i++) {
		R[i] = A[mid + i];
	}
	L[n1] = INFTY;
	R[n2] = INFTY;
	
	i = 0;
	j = 0;
	for (k=left; k<right; k++) {
		if( L[i] <= R[j] ) {
			A[k] = L[i];
			i++;
		} else {
			A[k] = R[j];
			j++;
			cnt += n1 - i;
		}
	}
}

void mergeSort(int *A, int left, int right)
{
	int mid;
	if( left + 1 < right ) {
		mid = ( left + right ) / 2;
		mergeSort(A, left, mid);
		mergeSort(A, mid, right);
		merge(A, left, mid, right);
	}
}

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



int main(){
    int N,K;
    cin >> N >> K;
    int ans=1;
    for(int i=0;i<N;i++){
        if(ans*2<ans+K)ans=ans*2;
        else ans= ans+K;
    }
    cout <<ans << endl;
    return 0;
}




Measured memory_bytes: 256
#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pii =  pair<int, int>;
using pll =  pair<long long, long long>;
constexpr char ln =  '\n';
constexpr long long INF = 1000000009LL;
#define all(x) (x).begin(),(x).end()
#define rep(i,n) for(int i=0;i<(n);i++)
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; }

const int MOD = 2019;

int main() {
    string s; cin >> s;
    int n = s.size();
    reverse(all(s));
    int x = 1, tot = 0;
    vector<int> cnt(MOD, 0);
    ll ans = 0;
    rep(i, n+1){
        cnt[tot]++;
        tot += (s[i] - '0') * x;
        tot %= MOD;
        x *= 10;
        x %= MOD;
    }
    rep(i, cnt.size()){
        ans += cnt[i] * (cnt[i]-1) / 2;
    }
    cout << ans << ln;
}

Measured memory_bytes: 3756
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define ull unsigned long long
vector <int> adj[1000001];
bool visited[1000001];
int groupsize = 0;
int maxsize = 0;
void dfs(int s) {
	visited[s] = true;
	groupsize+=1;
    for(int i = 0;i < adj[s].size();++i){
        if(visited[adj[s][i]] == false)
            dfs(adj[s][i]);
    }
}
int main(){
	ios_base::sync_with_stdio(false);
    cin.tie(NULL);
	#ifndef ONLINE_JUDGE
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
	#endif
	int n,m;
	cin >> n >> m;
	for(int i = 0; i < m; ++i){
		int a,b;
		cin >> a >> b;
		// cout << a << ' ' << b << '\n';
		adj[a].push_back(b);
		adj[b].push_back(a);
	}
	for(int i = 1; i <= n; ++i){
		groupsize = 0;
		if(!visited[i]){
			dfs(i);
			if(groupsize > maxsize){
				maxsize = groupsize;
			}
		}
	}
	cout << maxsize;
}

Measured memory_bytes: 39736
#pragma GCC optimize("O3")
#include <bits/stdc++.h>

using namespace std;

#define F first
#define S second
#define PB emplace_back
#define ALL(x) (x).begin(),(x).end()
#define endl '\n'

using ll = long long;
using ld = long double;
using vi = vector<int>;
using vll = vector<ll>;
using pi = pair<int,int>;
using pll = pair<ll,ll>;

constexpr int IN = 1000005;
constexpr int INF = 1e9+5;
constexpr int INI = -1;


int main(){
    ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    string S;
    cin >> S;
    if(S[S.length()-1] == 's')
        S += "es";
    else
        S += "s";
    cout << S;
    return 0;
}


Measured memory_bytes: 3616
n=int(input())
x=[]*n;y=[]*n
for i in range(n):
  A=[]*n;B=[]*n
  for j in range(int(input())):
    a,b=map(int,input().split())
    A.append(a-1),B.append(b)
  x.append(A);y.append(B)
ans=0
for bit in range(2**n):
  T=[bit>>i&1for i in range(n)];cnt=0;f=1
  for i in range(n):
    if bit>>i&1:
      cnt+=1
      for p in range(len(x[i])):
        if T[x[i][p]]!=y[i][p]:
          f=0;break
  if f>0:ans=max(ans,cnt)
print(ans)

Measured memory_bytes: 3064
#include<stdio.h>
int main()
{
    int a,b,d,r;
    double f;
    scanf("%d%d",&a,&b);

    d=a/b;
    r=a%b;
    f=(double)a/(double)b;
    printf("%d %d %.5lf\n",d,r,f);
    return 0;
}



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

int main(int argc, char *argv[]){
  int n;
  while(std::cin >> n, n){
    vector<int> a(n);
    unordered_map<int, int> um;
    for (int i = 0; i < n; i++) {
      std::cin >> a[i];
    }
    for (int i = 0; i < a.size(); i++) {
      um[a[i]]++;
    }
    int ans = -1;
    for (auto i:um) {
      if(i.second > a.size()/2)ans = i.first;
    }
    if(ans == -1)std::cout << "NO COLOR" << std::endl;
    else std::cout << ans << std::endl;
  }
  return 0;
}

Measured memory_bytes: 9628
import sys
sys.setrecursionlimit(10**6)
n, a, b = map(int, input().split())
D = [[0]*2 for _ in range(101010)]
E = [[] for _ in range(n)]


def dfs(cur, pre, d, id):
    D[cur][id] = d
    for nv in E[cur]:
        if nv != pre:
            dfs(nv, cur, d+1, id)


a -= 1
b -= 1
for i in range(n-1):
    x, y = map(int, input().split())
    x -= 1
    y -= 1
    E[x].append(y)
    E[y].append(x)
dfs(a, a, 0, 0)
dfs(b, b, 0, 1)
max_d = 0
for i in range(n):
    if D[i][0] < D[i][1]:
        max_d = max(max_d, D[i][1]-1)
print(max_d)


Measured memory_bytes: 113604
#include <bits/stdc++.h> 
#define int long long
#define quickie ios_base::sync_with_stdio(false); cin.tie(NULL);
#define rep(i, a, b) for(int i=a; i<b; i++)
#define rep1(i, a, b) for(int i=a; i<=b; i++)
#define repp(i, a, b) for(int i=b-1; i>=a; i--)
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define SZ(x) ((int)(x).size())
#define db double
#define mi map<int, int>
#define mc map<char, int>
#define ms map<string, int>
#define vi vector<int>
#define qi queue<int>
#define MI(x) power(x, mod-2)
#define test int t; cin >> t;
#define mod 1000000007LL
//#define mod 998244353 
using namespace std;
int power(int x, int y) ;
int gcd(int a, int b) ;
#define pi 3.141592653589

signed main() {
    quickie 
    int n ;
    cin >> n ;
    db a[n] ;
    rep(i, 0, n) cin >> a[i] ;
    sort(a, a+n) ;
    db s = a[0] ;
    rep(i, 1, n) {
        s = (s+a[i])/2 ;
    }
    cout << fixed << setprecision(9) <<  s << "\n" ;
}

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

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

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
  int64_t N;
  cin >> N;
  vector<int64_t> vec(N);
  map<int64_t,int64_t> mp;
  for(int i=0; i<N; i++){
    cin >> vec[i];
    bitset<30> b(vec[i]);
    for(int j=0; j<30; j++){
      if(b.test(j)){
        mp[j]++;
        break;
      }
    }
  }
  
  int64_t sum = 0;
  for(int i=0; i<N; i++){
    sum ^= vec[i];
  }
  
  bool flag = true;
  int64_t ans = 0;
  
  bitset<30> B(sum);
  for(int i=29; i>=0; i--){
    if(B.test(i)){
      if(mp.count(i)){
        ans++;
        for(int j=0; j<=i; j++){
          B.flip(j);
        }
      }
      else{
        flag = false;
      }
    }
  }
  
  if(!flag){
    cout << -1 << endl;
  }
  else{
    cout << ans << endl;
  }
          
}

Measured memory_bytes: 4052
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		String W = sc.next();
		String T = "";
		int count = 0;
		while(true) {
			T = sc.next();
			if(T.equalsIgnoreCase(W)) {
				count++;
			} else if(T.equals("END_OF_TEXT")) {
				break;
			}
		}
		
		System.out.println(count);
		sc.close();
	}
	
}


Measured memory_bytes: 26360
#include "bits/stdc++.h"

#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(),(x).end()
#define bit(n) (1LL << (n))
#define sz(x) ((int)(x).size())
#define UNIQUE(v) v.erase( unique(v.begin(), v.end()), v.end() );
#define en '\n'
#define pb push_back
#define mp make_pair
#define P pair<int, int>

typedef long long ll;
using namespace std;

ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; }
ll lcm(ll a, ll b) { ll g = gcd(a, b); return a / g * b; }
const int dx[4] = { 1, 0, -1,  0 };
const int dy[4] = { 0, 1,  0, -1 };
const int INF = (int)1e9;
const ll  inf = (ll)1e18;
const int mod = 1000000007;

struct aaa {
	aaa() {
		cin.tie(0);
		ios::sync_with_stdio(0);
		cout << fixed << setprecision(20);
	};
}aaaaa;

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

	vector<int> x(m);
	rep(i, m) cin >> x[i];

	sort(x.begin(), x.end());

	vector<ll> p;

	for (int i = 0; i < m - 1; i++) {
		p.push_back(abs(x[i + 1] - x[i]));
	}

	sort(p.begin(), p.end());

	/*for (int i = 0; i < p.size(); i++) {
		cout << p[i] << " ";
	}
	cout << endl;*/

	ll sum = 0;
	for (int i = 0; i < (int)p.size() - (n - 1); i++) {
		sum += p[i];
	}

	cout << sum << endl;
}

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

#define vll vector<long long> 
#define pii pair<int,int> 
#define vpii vector<pair<int,int>> 
#define pll  pair<long long ,long long > 
#define  pb  push_back
#define fi  first 
#define sec second  
#define SORT(a) sort(a.begin(),a.end()) 
#define m_p make_pair
#define all(x)   (x.begin(),x.end()) 
#define sz(v)     ((int)(v.size()))
typedef vector<int> vi ;
const int nax=10123;
const int MOD=1e9 +7 ; 
int main(){	
	char k[nax]; 
	scanf("%s", &k); 
	int d; 
	cin>>d; 
	int n =strlen(k); 
	vector<vector<int>> dp(d,vector<int>(2));
	dp[0][0]=1; 
	for(int i=0;i<n;i++)
	{
		vector<vector<int>> new_dp(d,vector<int>(2)); 

		for(int sum=0;sum<d;sum++)
		{
			for(bool sm_already:{false,true})
			{	for(int digit=0;digit<=9;digit++)
				{
					if(digit>k[i]-'0' && !sm_already) break; 

					new_dp[(sum+digit)%d][sm_already || digit<k[i]-'0']=(new_dp[(sum+digit)%d][sm_already || digit<k[i]-'0']+dp[sum][sm_already] ) %MOD;
				}
	        }	
		}


		dp=new_dp  ;
	}

	int answer= (dp[0][false]+dp[0][true])%MOD; 
	answer--; 
	if(answer==-1 ) answer=MOD-1; 

	cout<<answer<<endl;
	return 0; 
}

Measured memory_bytes: 256
# coding: utf-8
import sys
input = sys.stdin.readline

def f(n, abc):
    dp = [0] * 3
    for a, b, c in abc:
        dp = [ max(dp[1] + a, dp[2] + a), \
               max(dp[0] + b, dp[2] + b), \
               max(dp[0] + c, dp[1] + c) ]
    return(max(dp))

n = int(input())    # 1 <= n <= 10^5
abc = [list(map(int, input().rstrip().split())) for _ in range(n)]

print(f(n, abc))


Measured memory_bytes: 30580
// 見せてやるぜ、奇跡ってやつをよぉ……
#include <iostream>
#include <array>
#include <algorithm>
#include <vector>
#include <set>
#include <unordered_set>
#include <cmath>
#include <complex>
#include <deque>
#include <iterator>
#include <numeric>
#include <map>
#include <unordered_map>
#include <queue>
#include <stack>
#include <string>
#include <tuple>
#include <utility>
#include <limits>
#include <iomanip>
#include <functional>
#include <cassert>
using namespace std;

using ll=long long;
template<class T> using V = vector<T>;
template<class T, class U> using P = pair<T, U>;
using vll = V<ll>;
using vvll = V<vll>;
#define rep(i, k, n) for (ll i=k; i<(ll)n; ++i)
#define REP(i, n) rep(i, 0, n)
#define ALL(v) v.begin(),v.end()
template<class T> inline bool chmax(T& a, T b) {if (a<b) {a=b; return true;} return false;}
template<class T> inline bool chmin(T& a, T b) {if (a>b) {a=b; return true;} return false;}
#define DEBUG_VLL(vec) REP(i, vec.size()) cerr<<vec[i]<<(i==vec.size()-1?'\n':' ');

const ll MOD = 1000000007;
const ll HIGHINF = (ll)1e18;

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll n; cin >> n;
    vll p(n); REP(i, n) cin >> p[i];
    vll pi(n+1, -1); REP(i, n) pi[p[i]] = i;
    multiset<ll> ms;
    ms.insert(-1); ms.insert(-1);
    ms.insert(n); ms.insert(n);

    ll ans = 0;
    for (ll i=n; i>=1; i--) {
        ll tpi = pi[i];
        auto lb = ms.upper_bound(tpi);
        ll glow = *lb;
        lb++;
        ll ggre = *lb;
        lb--; lb--;
        ll lgre = *lb;
        lb--;
        ll llow = *lb;
        
        ll t =  (ggre-glow) * (tpi-lgre) + (lgre-llow) * (glow-tpi);
        ans += t*i;
        ms.insert(tpi);
    }
    cout << ans << '\n';
    return 0;
}


Measured memory_bytes: 6528
#include <stdio.h>

int a[222222];

int main(void)
{
	int k, n, i, max = 0;
	
	scanf("%d %d", &k, &n);
	for (i = 1; i <= n; i++)
		scanf("%d", &a[i]);

	for (i = 1; i < n; i++)
		if (max < a[i + 1] - a[i])
			max = a[i + 1] - a[i];
	if (max < k - a[n] + a[1])
		max = k - a[n] + a[1];

	printf("%d", k - max);
	return 0;
}

Measured memory_bytes: 896
#include <cassert>
#include <cstdio>
#include <cmath>
#include <iostream>
#include <iomanip>
#include <sstream>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <numeric>
#include <algorithm>

using namespace std;
using lint = long long;
constexpr int MOD = 1000000007, INF = 1010101010;
constexpr lint LINF = 1LL << 60;

template <class T>
ostream &operator<<(ostream &os, const vector<T> &vec) {
	for (const auto &e : vec) os << e << (&e == &vec.back() ? "\n" : " ");
	return os;
}

#ifdef _DEBUG
template <class T>
void dump(const char* str, T &&h) { cerr << str << " = " << h << "\n"; };
template <class Head, class... Tail>
void dump(const char* str, Head &&h, Tail &&... t) {
	while (*str != ',') cerr << *str++; cerr << " = " << h << "\n";
	dump(str + (*(str + 1) == ' ' ? 2 : 1), t...);
}
#define DMP(...) dump(#__VA_ARGS__, __VA_ARGS__)
#else 
#define DMP(...) ((void)0)
#endif

int main() {

	cin.tie(nullptr);
	ios::sync_with_stdio(false);

	string S;
	cin >> S;

	lint ans = 0;
	int W_cnt = 0;
	for (int i = S.size() - 1; i >= 0; i--) {
		if (S[i] == 'W') W_cnt++;
		else ans += W_cnt;
	}

	cout << ans << "\n";

	return 0;
}

Measured memory_bytes: 720
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
constexpr int maxn = 200;
constexpr int inf = 1000000001;

int dis[maxn][maxn];
int n, m, r;
vector<int> r_vector;

void floyd() {
	for (int k = 0; k < n; ++k)
		for (int i = 0; i < n; ++i)
			for (int j = 0; j < n; ++j)
				dis[i][j] = min(dis[i][j], dis[i][k] + dis[k][j]);
}

int main() {
	cin >> n >> m >> r;
	for (int i = 0, a; i < r; ++i) {
		cin >> a;
		r_vector.emplace_back(a - 1);
	}
	for (size_t i = 0; i < maxn; i++)
	{
		for (size_t j = 0; j < maxn; j++)
		{
			dis[i][j] = inf;
		}
	}
	for (int i = 0, a, b, c; i < m; ++i) {
		cin >> a >> b >> c;
		a--; b--;
		dis[a][b] = dis[b][a] = min({ dis[b][a], dis[a][b], c });
	}
	floyd();
	std::sort(r_vector.begin(), r_vector.end());
	int ans = inf;
	do {
		int tmp = 0;
		for (int i = 0; i < r_vector.size() - 1; ++i)
			tmp += dis[r_vector[i]][r_vector[i + 1]];
		ans = min(ans, tmp);
	} while (next_permutation(r_vector.begin(), r_vector.end()));
	cout << ans << endl;
	return 0;
}

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

typedef long long ll;

ll memo[1000000]={0};
const ll MOD = 1000000000+7;

ll factorial(ll n){
    ll res = 1;
  	for(ll i = 2; i <= n; i++){
      res = (res * i) % MOD;
    }
  	return res;
}

ll power(ll a, ll n){
 	ll x = 1;
  	while(n > 0){
     	if (n & 1){
         	x = (a *x) % MOD; 
        }
      	a = (a * a) % MOD;
      	n >>= 1;
    }
  	return x;
}

ll comb(ll n, ll k){
 	ll a = factorial(n) % MOD;
  	ll b = factorial(n-k) % MOD;
  	ll c = factorial(k) % MOD;
  	return (((a * power(b, MOD-2)) % MOD) * power(c, MOD-2)) % MOD;
}

int main(void){

    ll X, Y;
    cin >> X >> Y;
    
    if((X+Y) % 3 != 0){
        cout << 0 << endl;
        return 0;
    }else{
        ll n = (2*Y - X) / 3;
        ll m = (2*X - Y) / 3;
        if (n < 0 || m < 0){
            cout << 0 << endl;
            return 0;
        }else{
            cout << comb(m+n, m) << endl;
        }
   
    
    }
  
  return 0;
}


Measured memory_bytes: 256
N = int(input())
A = list(map(int, input().split()))

# 無理な場合は-1

# 1からN-1が出てくるまでの個数を足していく？
idx = 0
cnt = 0
num = 1
brick = 0
flg = False
while True:
    if num == A[idx]:
        flg = True
        num += 1
        brick += cnt
        cnt = 0
    else:
        cnt += 1
    idx += 1
    if idx > N - 1:
        brick += cnt
        break

if flg == False:
    brick = -1

print(brick)

Measured memory_bytes: 24744
from collections import deque
n, m = map(int, input().split())
ab = []
for i in range(m):
    a, b = map(int, input().split())
    a-=1; b-=1
    ab.append((a, b))

edge = [[] for _ in range(n)]
for a, b in ab:
    edge[a].append(b)
    edge[b].append(a)

visited = [False]*n
visited[0] = True
dq = deque([0])
ans = [-1]*n

while dq:
    now = dq.popleft()
    for e in edge[now]:
        if visited[e]==False:
            visited[e] = True
            dq.append(e)
            ans[e]=now

f = True
for a in ans[1:]:
    if a == -1: f = False
if not f:
    print('No')
else:
    print('Yes')
    for a in ans[1:]:
        print(a+1)

Measured memory_bytes: 50024
#include <bits/stdc++.h>
#define fi first
#define se second
using namespace std;
using ll = long long;

int main() {
    ios::sync_with_stdio(0); cin.tie(0);
    int n;
    cin >> n;
    vector<int> a(n);
    for(int i = 0; i < n; ++i) {
        cin >> a[i];
    }
    sort(a.begin(), a.end());
    n = a.size() / 2;
    cout << a[n] - a[n - 1] << '\n';
}

Measured memory_bytes: 640
#pragma GCC optimize("Ofast")
#include<bits/stdc++.h>
using namespace std;
struct __INIT{__INIT(){cin.tie(0);ios::sync_with_stdio(false);cout<<fixed<<setprecision(15);}} __init;
#define max3(a,b,c) max(a,max(b,c))
#define min3(a,b,c) min(a,min(b,c))
#define MOD 1000000007
#define INF (1<<30)
#define LINF (1LL<<60)
#define endl "\n"
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define reprev(i,n) for(int (i)=(n-1);(i)>=0;(i)--)
#define Flag(x) (1<<(x))
#define Flagcount(x) __builtin_popcount(x)
#define pint pair<int,int>
#define pdouble pair<double,double>
typedef unsigned long long int ull;
typedef long long lint;
 
int main(void){
  int N,check=0;
  cin >> N;
  string S[N];
  rep(i,N) cin >> S[i];
  for(int i=0;i<N;i++) for(int j=i+1;j<N;j++) if(S[i]==S[j]) check=1;
  for(int i=1;i<N;i++) if(S[i][0]!=S[i-1][S[i-1].length()-1]) check=1;
  if(check==0) cout << "Yes" << endl;
  else cout << "No" << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define endl '\n'
#define INF (1 << 21)
const int MOD = 1000000009;
using namespace std;

int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  long long n, a, b;
  
  cin >> n >> a >> b;

  if(a > b || n == 1 && a < b){
    cout << 0 << endl;
  }else{
    cout << max((int)n - 2, 0)  * (b - a) + 1 << endl;
  }
  return 0;
}



Measured memory_bytes: 256
#include<iostream>
using namespace std;
    
int main() {
  long long sum = 0,n;
  cin >> n;
  
  for(int i = 0;i<= n; i++) {
    if(i%3 != 0 && i % 5 != 0) {
      sum += i;
    }
  }
  
  cout << sum << endl;
}

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

using namespace std;

int main( void )
{
	int n;
	while(cin >> n, n) {
		int map[][3] = { { -1, 5, -1 },
						 {  4, 6,  3 },
						 { -1, 2, -1 },
						 { -1, 1, -1 }
		};
		int sum = 1;
		while(n--) {
			string str;
			cin >> str;
			switch(str[0]) {
			case 'N':
				for(int i=1; i < 4; ++i) swap(map[0][1], map[i][1]);
				break;
			case 'E':
				for(int i=2; i > -1; --i) swap(map[3][1], map[1][i]);
				break;
			case 'W':
				for(int i=0; i <  3; ++i) swap(map[3][1], map[1][i]);
				break;
			case 'S':
				for(int i=2; i > -1; --i) swap(map[3][1], map[i][1]);
				break;
			case 'R':
				swap(map[1][2], map[2][1]);
				swap(map[1][2], map[1][0]);
				swap(map[1][2], map[0][1]);
				break;
			case 'L':
				swap(map[1][0], map[2][1]);
				swap(map[1][0], map[1][2]);
				swap(map[1][0], map[0][1]);
				break;
			}
			sum += map[3][1];
		}
		cout << sum << endl;
	}
	return 0;
}

Measured memory_bytes: 0
#include <bits/stdc++.h>
#include<iostream>
using namespace std;
 
int main() {
    int n;

    cin >> n;
    map<string,int>a;
    for(int i = 0;i < n;i++){
        string s;
        cin >> s;
        a[s] = 1;
    }
    if(a.size() == 3){
        cout << "Three";
    }else{
        cout << "Four";
    }
}
   


Measured memory_bytes: 3564
N = int(input())
t = list(map(int, input().split()))
v = list(map(int, input().split()))
u = [0]
for vi, ti in zip(v, t):
  u[-1] = min(u[-1], vi)
  u += [vi] * (ti * 2)

u[-1] = 0
U = u.copy()
T = len(u)
for i in range(1, T):
  u[i] = min(u[i], u[i-1]+0.5)

for i in range(T-2, -1, -1):
  u[i] = min(u[i], u[i+1]+0.5)

ans = 0
for i in range(1, T):
  ans += (u[i-1] + u[i]) * 0.25

print(ans)

Measured memory_bytes: 3760
#include<iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<string.h>
#include<math.h>
#include<utility>
#include<map>
using namespace std;
typedef long long int ll;
typedef long double ld;
typedef vector<ll> vi;
typedef vector<string> vs;
typedef pair<ll,ll> P;
typedef vector<P> vp;
#define REP(i,n) for(ll i=0;i<n;i++)
#define FOR(i,m,n) for(ll i=m;i<n;i++)
#define REPR(i,n) for(ll i=n-1;i>=0;i--)
#define FORR(i,n,m) for(ll i=n-1;i>=m;i--)
#define all(in) in.begin(),in.end()
#define ALL(in,K) in,in+K

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll x1,y1,x2,y2;
    cin >> x1 >> y1 >> x2 >> y2;
    cout << x2+(y1-y2) << " ";
    cout << y2+(x2-x1) << " ";
    cout << x1+(y1-y2) << " ";
    cout << y1+(x2-x1) << endl;
    return 0;
}

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



int main() {
	int N,M;
	cin >>N>>M;
	int k;
	vector<vector<int>>light(M,vector<int>(0));
	for(int i=0;i<M;i++){
		cin>>k;
		for(int j=0;j<k;j++){
			int s;
			cin>>s;
			light.at(i).push_back(s);
		}
	}
	vector <int>p(M);
	for(int i=0;i<M;i++){
		cin >>p.at(i);
	}
	
	int count =0;
	for(int bit =0;bit<(1<<N);++bit){
		bitset<10> swit(bit);
		bool pro=true;
		for(int i=0;i<M;i++){
			int licount=0;
			for(int j=0;j<light.at(i).size();j++){
				if(swit.test(light.at(i).at(j)-1)){
					licount++;
				}
			}
			
			if(licount%2==p.at(i)){
				pro=true;
			}
			
			else{
				pro=false;
				break;
			}
			
		}
		if(pro){
			count++;
		}
	}
	
	cout << count << endl;
	
	
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
                                                                                                
  
int main(){
                                                                     

    string s;

    int k, i, j, m;

    vector<string> a;


    cin >> s >> k;

    m = k;


    if( s.size() < k ) m = s.size();

   
    for( i = 0 ; i < s.size() ; i = i + 1 ){

         for( j = 1 ; j <= m ; j = j + 1 ){

              a.push_back( s.substr(i, j) );

              }

         }


    sort( a.begin(), a.end() );

    a.erase( unique(a.begin(), a.end()), a.end() );


    cout << a.at(k - 1) << endl;


    return 0;

    }

Measured memory_bytes: 1660
import java.util.Scanner;
public class Main {
	public static void main(String args[]){//double 处理果盘
		Scanner in = new Scanner(System.in);
		int n = in.nextInt(),num = 0;
		String alph = in.next();
		char[] al = alph.toCharArray();
		for (int i=0 ;i<n ;i++){
			if (i == 0) {
				++num;
			}else{
				if(al[i] != al[i-1]){
					++num;
				}
			}
		}
		System.out.println(num);
	}
}

Measured memory_bytes: 26524
#include <iostream>
#include <cstdio>
#include <string>
#include <algorithm>
#include <vector>
#include <climits>
#include <sstream>
#include <bitset>
#include <queue>

using namespace std;

int main(){
    long long int N, h, n, w;

    cin >> N;

    for(h = 1; h <= 3500; h++){
        for(n = 1; n <= 3500; n++){
            w = 4 * h * n - N * n - N * h;
            if(0 < w && N*h*n % w == 0){
                w = N*h*n / w;
                printf("%lld %lld %lld\n", h, n, w);
                return 0;
            }
            
        }
    }
    
    return 0;
    
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
#define sqr(x) ((x)*(x))
#define mp make_pair
#define uint unsigned
inline char gc(){
    static char buf[100000],*p1=buf,*p2=buf;
    return p1==p2&&(p2=(p1=buf)+fread(buf,1,100000,stdin),p1==p2)?EOF:*p1++;
}
#define gc getchar
inline ll read(){
	ll x = 0; char ch = gc(); bool positive = 1;
	for (; !isdigit(ch); ch = gc())	if (ch == '-')	positive = 0;
	for (; isdigit(ch); ch = gc())	x = x * 10 + ch - '0';
	return positive ? x : -x;
}
inline void write(ll a){
    if(a<0){
    	a=-a; putchar('-');
	}
    if(a>=10)write(a/10);
    putchar('0'+a%10);
}
inline void writeln(ll a){write(a); puts("");}
inline void wri(ll a){write(a); putchar(' ');}
inline ull rnd(){
	return ((ull)rand()<<30^rand())<<4|rand()%4;
}
const int N=1<<17|3;
struct PI{
	ll in,out;
};
inline PI mp(ll a,ll b){
	return (PI){a,b};
}
bool operator < (PI a,PI b){
	return a.in<b.in;
}
int n,ch[N][2];
ll dep[N],lim;
vector<PI> dp[N];
vector<PI> Merge(vector<PI> &a,vector<PI> &b){
	vector<PI> v,ans; v.clear(); ans.clear();
	v.resize(a.size()+b.size());
	merge(a.begin(),a.end(),b.begin(),b.end(),v.begin());
	for(auto i:v)if(ans.size()==0||i.out<ans[ans.size()-1].out)ans.push_back(i);
	return ans;
}
vector<PI> Merge(ll lim,vector<PI> &a,vector<PI> &b){
	vector<PI> v; v.clear();
	if(!a.size()||!b.size())return v;
	unsigned j=0;
	for(auto i:a){
		while(j+1<b.size()&&b[j+1].in+i.out<=lim)j++;
		//if(lim==23)cout<<i.in<<"dasfas  "<<b[j].out<<endl;
		if(b[j].in+i.out<=lim)v.push_back(mp(i.in,b[j].out));
	}
	return v;
}
void solve(int p){
	if(!ch[p][0]){
		dp[p].push_back(mp(dep[p],dep[p]));
		return;
	}
	solve(ch[p][0]); solve(ch[p][1]);
	vector<PI> tmp1=Merge(lim+dep[p]*2,dp[ch[p][0]],dp[ch[p][1]]);
	vector<PI> tmp2=Merge(lim+dep[p]*2,dp[ch[p][1]],dp[ch[p][0]]);
	dp[p]=Merge(tmp1,tmp2);
	//cout<<p<<" cqz "<<dp[p].size()<<endl;
	//for(auto i:dp[p])cout<<i.in<<" "<<i.out<<endl;
}
bool check(){
	solve(1); 
	if(dp[1].size())return 1;
	//for(auto i:dp[1])if(i.in+i.out<=lim)return 1;
	return 0;
}
int main(){
	n=read();
	for(int i=2;i<=n;i++){
		int fa=read(),v=read();
		dep[i]=dep[fa]+v;
		if(ch[fa][0])ch[fa][1]=i; else ch[fa][0]=i;
	}
	//lim=15; cout<<check()<<endl; return 0;
	ll l=0,r=((ll)1<<34)-10;
	while(l<r){
		lim=(l+r)>>1;
		if(check())r=lim; else l=lim+1;
	}
	cout<<l<<endl;
}

Measured memory_bytes: 93608
import java.util.*;

public class Main {
    public static void main(String[] args) throws Exception {
        Scanner sc=new Scanner(System.in);
        
        int k=sc.nextInt();
        int s=sc.nextInt();
        int z;
        int count=0;
        for(int x=0; x<=k; x++){
            for(int y=0; y<=k; y++){
                z=s-x-y;
                if(0<=z && z<=k){
                    count+=1;
                }
            }
        }
        System.out.println(count);
    }
}


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

#define REP(i, n) for (int (i) = 0 ; (i) < (int)(n) ; ++(i))
#define REPN(i, m, n) for (int (i) = m ; (i) < (int)(n) ; ++(i))
#define REP_REV(i, n) for (int (i) = (int)(n) - 1 ; (i) >= 0 ; --(i))
#define REPN_REV(i, m, n) for (int (i) = (int)(n) - 1 ; (i) >= m ; --(i))

#define INF 2e9
#define INF_LL 1LL<<60
#define ll long long
#define MAX_V
const double PI=3.14159265358979323846;

#define print2D(h, w, arr) REP(i, h) { REP(j, w) cout << arr[i][j] << " "; cout << endl; }
#define print_line(vec, n) {for(int i=0;i<(n-1);i++) cout << (vec)[i] << " "; cout << (vec)[(n)-1] << endl;}
template<class T> void print(const T& x){cout << x << endl;}
template<class T, class... A> void print(const T& first, const A&... rest) { cout << first << " "; print(rest...); }
struct PreMain {PreMain(){cin.tie(0);ios::sync_with_stdio(false);cout<<fixed<<setprecision(20);}} premain; 

ll gcd(ll a, ll b){
    ll tmp;
    if(a<b){
        tmp = a;
        a = b;
        b = tmp;
    }

    ll r = a%b;
    while(r!=0){
        a = b;
        b = r;
        r = a % b;
    }

    return b;
}

int main() {
    int n, m;
    cin >> n >> m;
    vector<int> bin[n];

    REP(i, m) {
        int a, b;
        cin >> a >> b;
        a--, b--;
        bin[a].push_back(b);
        bin[b].push_back(a);
    }

    queue<int> que;
    
    REP(i, bin[0].size()) {
        que.push(bin[0][i]);
    }

    int loop = que.size();
    REP(i, loop) {
        int top = que.front();
        que.pop();
        REP(j, bin[top].size()) {
            if(bin[top][j] == n-1) {
                cout << "POSSIBLE" << endl;
                return 0;
            }
        }
    }

    cout << "IMPOSSIBLE" << endl;

}
 

Measured memory_bytes: 12400
#include <bits/stdc++.h>
#define fi first
#define se second
#define pii pair<int,int>
#define mp make_pair
#define pb push_back
#define space putchar(' ')
#define enter putchar('\n')
#define eps 1e-10
#define MAXN 100005
//#define ivorysi
using namespace std;
typedef long long int64;
typedef unsigned int u32;
typedef double db;
template<class T>
void read(T &res) {
    res = 0;T f = 1;char c = getchar();
    while(c < '0' || c > '9') {
	if(c == '-') f = -1;
	c = getchar();
    }
    while(c >= '0' && c <= '9') {
	res = res * 10 +c - '0';
	c = getchar();
    }
    res *= f;
}
template<class T>
void out(T x) {
    if(x < 0) {x = -x;putchar('-');}
    if(x >= 10) {
	out(x / 10);
    }
    putchar('0' + x % 10);
}
string s;
void Solve() {
    cin >> s;
    bool f = 0;
    for(int i = s.length() - 1 ; i >= 0 ; --i) {
	if(s[i] == 'F') f = 1;
	if(s[i] == 'C' && f) {
	    puts("Yes");return;
	}
    }
    puts("No");
}

int main() {
#ifdef ivorysi
    freopen("f1.in","r",stdin);
#endif
    Solve();
    return 0;
}


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

int main(){
    int a;
    string s;
    cin>>a;
    cin>>s;
    if (a>=3200){
        cout << s << endl;
        return 0;
    }else{
        cout << "red" << endl;
        return 0;
    }
}

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


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

    long long k,a,b;
    cin >> k >> a >> b;

    //  increase biscuit
    //  A biscuits->1Y
    //  1Y -> B biscuits
    long long biscuit = 1LL;
    long long turn = 1LL;
    while(turn <= k){
        if( b >= a+2 and biscuit >= a and turn+1<=k){
            biscuit += b-a;
            turn++;
        } else {
            biscuit++;
        }
        turn++;
        //  cout << "biscuit " << biscuit << " yen " << yen << endl;
    }
    cout << biscuit << endl;


    return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;
import java.util.stream.IntStream;

public class Main{
	static final Scanner s=new Scanner(System.in);
	static IntStream REPS(int v){return IntStream.range(0,v);}
	static IntStream INS(int n){return REPS(n).map(i->getInt());}
	static int getInt(){return Integer.parseInt(s.next());}

	public static void main(String[]$){
		System.out.println(
				INS(10).sorted().skip(7).sum()
				+" "+
				INS(10).sorted().skip(7).sum()
				);
	}
}

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

using namespace std;

#define INF (1 << 30)
#define EPS 1e-10
#define MOD 1000000007

using ll = long long;

int main() {
    int n, x;
    while (cin >> n >> x && n > 0) {
        int ans = 0;
        for (int i = 1; i <= n; ++i) {
            for (int j = i + 1; j <= n; ++j) {
                int t = x - i - j;
                if (j < t && t <= n) {
                    ans++;
                }
            }
        }
        cout << ans << endl;
    }

    return 0;
}


Measured memory_bytes: 3096
#include <iostream>

using namespace std;
#define ll long long
ll value[109]{};
ll weights[109]{};
ll dp[109][1000009]{};
int main()
{
    int n,W;
    cin>>n>>W;

    for(int i = 1 ; i<= n ; i++)
    {
        cin>>weights[i]>>value[i];
    }


    for(int i = 0 ; i<= n ; i++)
    {
        for(int w = 0 ; w<=W ; w++)
        {
            if(i==0 || w == 0 )
                dp[i][w] = 0 ;
            else
            {
                if(weights[i]<=w)
                {
                    dp[i][w] = max(dp[i-1][w] , dp[i-1][w-weights[i]]+value[i]);
                }
                else
                    dp[i][w] = dp[i-1][w];
            }
        }
    }

    cout<<dp[n][W]<<endl;
    return 0;
}


Measured memory_bytes: 287744
def factorization(n):
    arr = []
    temp = n
    for i in range(2, int(-(-n**0.5//1))+1):
        if temp%i==0:
            cnt=0
            while temp%i==0:
                cnt+=1
                temp //= i
            arr.append([i, cnt])

    if temp!=1:
        arr.append([temp, 1])

    if arr==[]:
        arr.append([n, 1])

    return arr


def getnum(n):
    ret = 1
    _sum = 1
    while True:
        if _sum > n:
            return ret-1
        ret += 1
        _sum += ret

def main():
    n = int(input())
    aa = factorization(n)
    ret = 0
    for a in aa:
        if a[0] == 1:
            continue
        ret += getnum(a[1])
    print(ret)

if __name__=="__main__":
    main()


Measured memory_bytes: 63384
import numpy as np
from collections import defaultdict

#key = {1:2, 2:5, 3:5, 4:4, 5:5, 6:6, 7:3, 8:7, 9:6}

A, B, C = map(int, input().split())  #

if B//A > C:
    print(C)
else:
    print(B//A)

Measured memory_bytes: 21492
//https://algospot.com/judge/problem/read/CLOCKSYNC
#include <iostream>
#include <cstdio>
#include <functional>
#include <algorithm>
#include <climits>
#include <utility>
#include <string>
#include <stack>
#include <vector>
#include <queue>
#include <map>

#define LF '\n';
#define MOD 1000000007

typedef unsigned long long ull;
typedef long long ll;

using namespace std;

int main(void)
{
	ios::sync_with_stdio(false);
	int a, b, c;
	cin >> a >> b >> c;

	c = c - (a - b);
	cout << (c < 0 ? 0 : c);
	return 0;
}	

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int n, q;
int main() {
    while(cin >> n, n) {
        map<char, char> conversion;
        for(int i = 0; i < 128; i++) conversion[i] = i;
        string c, d;
        while(n--) cin >> c >> d, conversion[c[0]] = d[0];
        cin >> q;
        while(q--) cin >> c, cout << conversion[c[0]];
        cout << endl;
    }
}

Measured memory_bytes: 2988
=begin
－－－－－－－－－－－－－－ 
A = 100*A 水
B = 100*B 水
C,D = １回の投入可能砂糖量
E = 100(g)あたりに溶かすことのできる砂糖量
F = ビーカー許容量(水 + 砂糖 = 総質量)
sugar = F 質量内でできる砂糖の質量を格納(Ci + Dj を組み合わせてできる質量の列挙)
water = F 質量内でできる水の質量を格納(100Ai + 100Bjの組み合わせでできる質量の列挙)
sum = water[i]とsugar[j]の総質量
pos = water[i] に溶かせる砂糖量
con = sugar[j]*100 / (sugar[j] + water[i])  の砂糖濃度(%)
ans = 答え
－－－－－－－－－－－－－－
=end

A,B,C,D,E,F = gets.split.map(&:to_i);

water = [];
(0..30).each{|i|
  (0..30).each{|j|
    x = (100*A*i) + (100*B*j);
    water << x if x <= F;
  }
}
water.sort!.uniq!;

sugar = []
(0..100).each{|i|
  (0..100).each{|j|
    y = C * i + D * j;
    sugar << y if y <= F;
  }
}
sugar.sort!.uniq!;

sum_ans = 0;
sugar_ans = 0;
dif = -1;
con = 0.0;

water.each{|w|
  pos = w / 100 * E;
  sugar.each{|s|
    sum = w + s;
    next if pos < s || F < sum
    con = (s*100) / (s + w).to_f;
    if dif < con
      sum_ans = sum;
      sugar_ans = s;
      dif = con;
    end
  }
}

puts "#{sum_ans} #{sugar_ans}"

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

#define N 100

int pop(int *,int *);
void stack(int *,int *,int);

int main(){
  int num[N],top=0,calc[3],status;
  char in[10];
  int i;
  while(1){
    status=scanf("%s",in);
    if(status==EOF){
      break;
    }    
    if(in[0]=='+'){
      calc[1]=pop(num,&top);
      calc[2]=pop(num,&top);
      calc[0]=calc[2]+calc[1];
      stack(num,&top,calc[0]);
    }else if(in[0]=='-'){
      calc[1]=pop(num,&top);
      calc[2]=pop(num,&top);
      calc[0]=calc[2]-calc[1];
      stack(num,&top,calc[0]);
    }else if(in[0]=='*'){
      calc[1]=pop(num,&top);
      calc[2]=pop(num,&top);
      calc[0]=calc[2]*calc[1];
      stack(num,&top,calc[0]);
    }else if(in[0]=='/'){
      calc[1]=pop(num,&top);
      calc[2]=pop(num,&top);
      calc[0]=calc[2]/calc[1];
      stack(num,&top,calc[0]);
    }else{
      status=atoi(in);
      stack(num,&top,status);
    }
  }
  printf("%d\n",num[0]);
  return 0;
}

int pop(int *a,int *top){
  a[*top]=0;
  (*top)--;
  return a[*top];
}

void stack(int *a,int *top,int n){
  a[*top]=n;
  (*top)++;
}



Measured memory_bytes: 2108
/** Which of the favors of your Lord will you deny ? **/

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

#define LL long long
#define PII pair<int,int>
#define PLL pair<LL,LL>
#define MP make_pair
#define F first
#define S second

#define ALL(x) (x).begin(), (x).end()
#define DBG(x) cerr << __LINE__ << " says: " << #x << " = " << (x) << endl
#define READ        freopen("alu.txt", "r", stdin)
#define WRITE       freopen("vorta.txt", "w", stdout)

#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;

template<class TIn>using indexed_set = tree<TIn, null_type, less<TIn>,rb_tree_tag, tree_order_statistics_node_update>;

/**

PBDS
-------------------------------------------------
1) insert(value)
2) erase(value)
3) order_of_key(value) // 0 based indexing
4) *find_by_order(position) // 0 based indexing

**/

template<class T1, class T2>
ostream &operator <<(ostream &os, pair<T1,T2>&p);
template <class T>
ostream &operator <<(ostream &os, vector<T>&v);
template <class T>
ostream &operator <<(ostream &os, set<T>&v);

inline void optimizeIO()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
}

const int nmax = 2e5+7;
const LL LINF = 1e17;

template <class T>
string to_str(T x)
{
    stringstream ss;
    ss<<x;
    return ss.str();
}

//bool cmp(const PII &A,const PII &B)
//{
//
//}



int main()
{
    optimizeIO();

//    WRITE;

    int n,k;
    cin>>n>>k;

    vector<int>dp(k+1,-1);
    vector<int>v(n);
    int mn = INT_MAX;
    for(int i=0; i<n; i++)
        cin>>v[i] ,mn =min(mn,v[i]);

    for(int i=0;i<mn;i++)
        dp[i] = 0; /** lose **/

    for(int i=mn;i<=k;i++)
    {
        for(int x:v)
        {
            if(x>i)
                break;

            if(dp[i-x]==0) /** losing move available **/
                dp[i] = 1;
        }

        if(dp[i]==-1) /** If no win available for first **/
            dp[i] = 0;
    }

    if(dp[k]==1) cout<<"First"<<endl;
    else cout<<"Second"<<endl;

    return 0;
}

/**
1 4
3

2 4
2 3

2 5
2 3

2 7
2 3

**/

template<class T1, class T2>
ostream &operator <<(ostream &os, pair<T1,T2>&p)
{
    os<<"{"<<p.first<<", "<<p.second<<"} ";
    return os;
}
template <class T>
ostream &operator <<(ostream &os, vector<T>&v)
{
    os<<"[ ";
    for(int i=0; i<v.size(); i++)
    {
        os<<v[i]<<" " ;
    }
    os<<" ]";
    return os;
}

template <class T>
ostream &operator <<(ostream &os, set<T>&v)
{
    os<<"[ ";
    for(T i:v)
    {
        os<<i<<" ";
    }
    os<<" ]";
    return os;
}





Measured memory_bytes: 3700
#include<cstdio>
using namespace std;
int n, s[100000], t[50000];
int binarySearch(int s[], int t) {
	int left = 0, right = n;
	while (left < right) {
		int mid = (left + right) / 2;
		if (s[mid] == t) return 1;
		else if (t < s[mid]) right = mid;
		else left = mid + 1;
	}
	return 0;
}
int main() {
	int q;
	scanf("%d", &n);
	for (int i = 0; i < n; i++)
		scanf("%d", &s[i]);
	scanf("%d", &q);
	int cnt = 0;
	for (int i = 0; i < q; i++) {
		scanf("%d", &t[i]);
		cnt += binarySearch(s, t[i]);
	}
	printf("%d\n", cnt);
}


Measured memory_bytes: 3168