akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
using namespace std;


// type definitions
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector< vi > vvi;
typedef pair<int, int> pii;
typedef vector<pii> vpii;
typedef complex<int> ci;
typedef complex<double> cd;
typedef complex<long double> cld;

// macros
#define rep(i, a, b) for(int i=a; i<b; i++)
#define TIME clock() * 1.0 / CLOCKS_PER_SEC
#define all(c) c.begin(), c.end()
#define tr(c, it) for(auto it=(c).begin(); it!=c.end(); it++)
#define pb push_back
#define mp make_pair
#define bitcount __builtin_popcount
#define ispresent(c, x) ((c).find(x) != (c).end())
#define watch(x) cout<< (#x) << " is " << (x) <<"\n";
#define sz(x) ((int)((x).size()))
#define UNIQUE(c) (c).resize(unique(all(c)) - (c).begin())
#define pii2ll(p) ((ll)(p).first<<32 | (p).second)

// template functions
template <typename T>
inline void printV(vector<T>& a) { rep(i, 0, sz(a)) { cout<<a[i]<<" "; } cout<<"\n"; }
template <typename T>
inline void print(T a) { cout<<a<<"\n"; }
template <typename T>
inline void print(T a, T b) { cout<<a<<" "<<b<<"\n"; }
template <typename T>
inline void print(T a, T b, T c) { cout<<a<<" "<<b<<" "<<c<<"\n"; }
template <typename T>
inline void print(T a, T b, T c, T d) { cout<<a<<" "<<b<<" "<<c<<" "<<d<<"\n"; }
template <typename T>
inline void printpii(pair<T, T> p) { cout<<p.first<<" "<<p.second<<"\n"; }
template <typename T>
inline void printVV(vector<vector<T>>& a)
{
	rep(i, 0, sz(a)) {
		printV(a[i]);
	}
	cout<<"\n";
}

template <typename T>
inline void clearVV(vector<vector<T>>& a)
{
	for(auto& x:a) {
		x.clear();
	}
	a.clear();
}
template <typename T>
inline void assignVV(vector<vector<T>> &a, T val)
{
	for(int i=0; i<sz(a); i++) {
		for(int j=0; j<sz(a[i]); j++) {
			a[i][j]=val;
		}
	}
}

template <typename T>
inline void readV(vector<T>& a) { rep(i, 0, sz(a)) cin>>a[i]; }
template <typename T>
inline void read(T& a) { cin>>a; }
template <typename T>
inline void read(T& a, T& b) { cin>>a>>b; }
template <typename T>
inline void read(T& a, T& b, T& c) { cin>>a>>b>>c; }
template <typename T>
inline void read(T& a, T& b, T& c, T& d) { cin>>a>>b>>c>>d; }
template <typename T>
inline void readpii(pair<T, T>& p) { cin>>p.first>>p.second; }
template <typename T>
inline void readVV(vector<vector<T>>& a)
{
	rep(i, 0, sz(a)) {
		readV(a[i]);
	}
}


// constants
const long double eps = 1e-9;
const int inf = 5e8;
const int modn = 1e9+7;
const int MAX = 1e5;


int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    // Your code here
	int n, W;
	cin>>n>>W;
	vector<ll> w(n+1);
	vector<ll> val(n+1);
	vector<vector<ll>> dp(W+1, vector<ll>(n+1));
	for(int i=1; i<=n; i++) {
		cin>>w[i]>>val[i];
	}
	
	for(int i=1; i<=W; i++) {
		for(int j=1; j<=n; j++) {
			if(i>=w[j]) {
				dp[i][j]=max(dp[i][j-1], dp[i-w[j]][j-1]+val[j]);
			}
			else {
				dp[i][j]=dp[i][j-1];
			}
		}
	}
	//~ printVV(dp);
	
	cout<<dp[W][n]<<"\n";
    return 0;
}



Measured memory_bytes: 82304
import java.util.Scanner;

public class Main{

	public static void main(String args[]){

		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int x = sc.nextInt();
		int[] gram = new int[n];
		int min = 1000;
		
		for(int i = 0; i < n; i ++) {
			gram[i] = sc.nextInt();
			x -= gram[i];
			if(min > gram[i]) {
				min = gram[i];
				
			}
		}
		
		int j = x / min;
		System.out.println(n + j);
		
	}
}


Measured memory_bytes: 21844
#include "iostream"
#include "climits"
#include "list"
#include "queue"
#include "set"
#include "functional"
#include "algorithm"
#include "math.h"
#include "utility"

using namespace std;

char letter[100001];
int far;

int main() {
	cin >> letter;
	for (int i = 0; letter[i] != NULL; i++) {
		far = i + 1;
	}
	if (far == 2) {
		if (letter[0] == letter[1]) {
			cout << "1 2\n";
			return 0;
		}
		cout << "-1 -1\n";
		return 0;
	}
	for (int i = 0; i < far - 2; i++) {
		if (letter[i] == letter[i + 1]) {
			cout << i+1 << " " << i + 2 << endl;
			return 0;
		}
	}
	for (int i = 0; i < far-3; i++) {
		if (letter[i] == letter[i + 2]) {
			cout << i+1 << " " << i + 3 << endl;
			return 0;
		}
	}
	cout << "-1 -1\n";
	return 0;
}

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

using namespace std;

const double PI = 3.141592653589;
#define fastio ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0)
#define pb push_back
#define mp make_pair
#define int long long
#define all(c) (c).begin(),(c).end()
#define M 1000000007
#define INF LLONG_MAX
#define pr(...) dbs(#__VA_ARGS__, __VA_ARGS__)
template <class T> void dbs(string str, T t) {cerr << str << " : " << t << "\n";}
template <class T, class... S> void dbs(string str, T t, S... s) {int idx = str.find(','); cerr << str.substr(0, idx) << " : " << t << ", "; dbs(str.substr(idx + 1), s...);}
template <class S, class T>ostream& operator <<(ostream& os, const pair<S, T>& p) {return os << "(" << p.first << ", " << p.second << ")";}
template <class T>ostream& operator <<(ostream& os, const vector<T>& p) {os << "[ "; for (auto& it : p) os << it << " "; return os << "]";}
template <class T>ostream& operator <<(ostream& os, const set<T>& p) {os << "[ "; for (auto& it : p) os << it << " "; return os << "]";}
template <class S, class T>ostream& operator <<(ostream& os, const map<S, T>& p) {os << "[ "; for (auto& it : p) os << it << " "; return os << "]";}
template <class T> void prc(T a, T b) {cerr << "["; for (T i = a; i != b; ++i) {if (i != a) cerr << ", "; cerr << *i;} cerr << "]\n";}
// Use pr(a,b,c,d,e) or cerr<<anything or prc(v.begin(),v.end()) or prc(v,v+n)
//  


int32_t main()
{
    fastio;
    //freopen("file.in", "r", stdin);
    //freopen("file.out", "w", stdout);
    string s;
    cin >> s;
    int n = s.length();
    for(int i=0;i<n;i++) cout << 'x';
    cout << "\n";
    return 0;
}



Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define mp make_pair
#define pb push_back
#define ff first
#define ss second
#define N 200005
ll mod=998244353;
#define fast ios_base::sync_with_stdio(false);cin.tie(NULL)
ll powermodm(ll x,ll n,ll M){ll result=1;while(n>0){if(n % 2 ==1)result=(result * x)%M;x=(x*x)%M;n=n/2;}return result;}
ll power(ll _a,ll _b){ll _r=1;while(_b){if(_b%2==1)_r=(_r*_a);_b/=2;_a=(_a*_a);}return _r;}
ll gcd(ll a,ll b){while(a&&b)a>b?a%=b:b%=a;return a+b;}
ll lcm(ll a,ll b){return (max(a,b)/gcd(a,b))*min(a,b);}
int main()
{
    fast;   
    ll a,b,c;
    cin>>a>>b>>c;
    ll y=__gcd(a,b);
    vector<ll> g;
    for(int i=1;i<=y;i++)
    {
        if(y%i==0)
        {
            g.pb(i);
        }
    }
    sort(g.begin(),g.end());
    reverse(g.begin(),g.end());
    cout<<g[c-1]<<endl;
    return 0;
}


Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        try (Scanner sc = new Scanner(System.in)) {
            int w = sc.nextInt();
            int n = sc.nextInt();
            int[] values = new int[w];
            for (int i = 0; i < values.length; i++) {
                values[i] = i;
            }
            for (int i = 0; i < n; i++) {
                String str = sc.next();
                String[] ab = str.split(",");
                int a = Integer.parseInt(ab[0]) - 1;
                int b = Integer.parseInt(ab[1]) - 1;
                for(int x=0;x<w;x++){
                    if(values[x]==a){
                        values[x] = b;
                        continue;
                    }else if(values[x]==b){
                        values[x] = a;
                        continue;
                    }
                }
            }
            for(int j = 0;j<w;j++){
                for(int k=0;k<w;k++){
                    if(values[k] == j){
                        System.out.println(k+1);
                    }
                }
            }
            sc.close();    
        }
    }
}



Measured memory_bytes: 26004
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <cmath>
#include <set>
#include <map>
#include <queue>
using namespace std;
#define rep(i,n) for(int i = 0;i<n;i++)
#define ll long long  
const long long MOD = 1000000007LL;
long long poww(int n){
    long long a = 1;
    rep(i,n){
        a = a*2;
    }
    return a;
}
int main(){
    int n;
    long long x;
    cin >> n >> x;
    long long dp[55][3];
    dp[0][0] = 1;//P
    dp[0][1] = 0;//B
    dp[0][2] = 1;//合計
    rep(i,52){
        dp[i+1][0] = 2*dp[i][0] + 1;
        dp[i+1][1] = 2*dp[i][1] + 2;
        dp[i+1][2] = dp[i+1][0] + dp[i+1][1];
    }
    long long ans = 0;
    int cnt = n;
    while(x!=0){
        if(x == 1){
            if(cnt == 0){
                ans++;
            }
            x = 0;
            break;
        }
        else if(x < 1+dp[cnt-1][2]){
            x = x-1;
            cnt--;
        }
        else if(x == 1+ dp[cnt-1][2]){
            x = 0;
            ans = ans + dp[cnt-1][0];
            break;
        }
        else if(x == 2+ dp[cnt-1][2]){
            x = 0;
            ans = ans + dp[cnt-1][0] + 1;
            break;
        }
        else if(x == 3 +2*dp[cnt-1][2]){
            x = 0;
            ans = ans + 2*dp[cnt-1][0] + 1;
            break;
        }
        else{
            ans = ans + dp[cnt-1][0] + 1;
            x = x - dp[cnt-1][2] - 2;
            cnt--;
        }   
    }
    cout << ans << endl;
}

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

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

ll inverse(ll x, const ll mod){
    return modpow(x, mod-2, mod);
}

vector<ll> lagrange_interpolation(vector<ll> xs, vector<ll> ys, const int m){
    const int n = xs.size();
    for(int i = 0; i < n; i++){
        xs[i] %= m;
        ys[i] %= m;
    }
    vector<ll> all_c(n+1);
    all_c[0] = 1;
    for(int i = 0; i < n; i++){
        vector<ll> nxt(n + 1);
        for(int j = 0; j < n; j++){
            nxt[j+1] = all_c[j];
        }
        for(int j = 0; j < n; j++){
            nxt[j] = (m + nxt[j] - xs[i] * all_c[j] % m) % m;
        }
        all_c = move(nxt);
    }

    vector<ll> c(n);
    for(int i = 0; i < n; i++){
        ll qi = 1;
        for(int j = 0; j < n; j++){
            if(i == j) continue;
            qi = qi * (m + xs[i] - xs[j]) % m;
        }
        qi = inverse(qi, m) * ys[i] % m;

        auto tmp_c = all_c;
        for(int j = n - 1; j >= 0; j--){
            c[j] = (c[j] + qi * tmp_c[j+1]) % m;
            tmp_c[j] = (tmp_c[j] + tmp_c[j+1] * xs[i]) % m;
        }
    }
    return c;
}
int main(){
    int p; cin >> p;
    vector<ll> xs(p), ys(p);
    for(int i = 0; i < p; i++){
        xs[i] = i;
        cin >> ys[i];
    }
    auto res = lagrange_interpolation(xs, ys, p);
    for(int i = 0; i < p; i++){
        cout << res[i] << " \n"[i+1 == p];
    }
    return 0;
}

Measured memory_bytes: 512
/*
	  Chase
	   Your
	  Legend

	英雄志逐传奇
*/

#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <cmath>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <math.h>
#include <stdio.h>

#define rep(i, n) for(int i = 0; i < (n); i++)
typedef long long ll;
using namespace std;

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

	vector<int>h(n);
	rep(i, n) {
		cin >> h[i];
	}


	int cnt, ans;
	cnt = 0;
	ans = 0;
	for (int i = n - 1; i > 0; i--) {
		if (h[i - 1] - h[i] >= 0) {
			cnt++;
		}
		else {
			ans = max(ans, cnt);
			cnt = 0;
		}
	}
	ans = max(ans, cnt);

	cout << ans << endl;
}

Measured memory_bytes: 640
import java.util.Scanner;

public class Main{
    public static void main(String[] args){
	Scanner sc = new Scanner(System.in);
	int N = sc.nextInt();
	int M = sc.nextInt();
	int[] A = new int[M];
	int sNum = 0;
	for(int i=0;i<M;i++){
	    A[i] = sc.nextInt();
	    sNum += A[i];
	}
	if(N - sNum >= 0) System.out.print(N - sNum);
	else System.out.print(-1);
	
    }			    
}


Measured memory_bytes: 46492
using System;
using System.Collections.Generic;
using System.Linq;
using static System.Math;

namespace ConsoleApp1
{
    class Program
    {
        static void Main(string[] args)
        {
            A();
        }

        static void A()
        {
            var ABCD = ReadSplitLong();
            var A = ABCD[0];
            var B = ABCD[1];
            var C = ABCD[2];
            var D = ABCD[3];

            var lcm = Lcm(C, D);
            var e = (B / C) + (B / D) - (B / lcm);

            var a = A - 1;
            var o = (a / C) + (a / D) - (a / lcm);
            Println(B - e - (a - o));
        }

        static IEnumerable<int> Range(int start, int stop)
        {
            if (start < 0 || stop < 0 || start > stop || (start <= 0 && stop <= 0))
                return new List<int>();

            return Enumerable.Range(start, stop - start);
        }

        static bool IsDigit(string str)
        {
            var i = 0;
            return int.TryParse(str, out i);
        }

        static int SumDigits(long num)
        {
            return num.ToString().Select(x => x.ToString()).Sum(int.Parse);
        }

        static int[] ToIntArray(string str)
        {
            return str.Select(x => x.ToString()).Select(int.Parse).ToArray();
        }

        static long Gcd(long a, long b) => b == 0 ? a : Gcd(b, a % b);
        static long Lcm(long a, long b) => a * b / Gcd(a, b);

        static bool IsPrime(int x)
        {
            if (x <= 1 || (x != 2 && x % 2 == 0)) return false;
            if (x == 2) return true;

            for (int i = 3; i < x; i += 2)
                if (x % i == 0) return false;

            return true;
        }

        static string Read() => Console.ReadLine();
        static int ReadInt() => int.Parse(Read());
        static long ReadLong() => long.Parse(Read());

        static List<string> ReadSplit() => Read().Split().ToList();
        static List<int> ReadSplitInt() => Read().Split().Select(int.Parse).ToList();
        static List<long> ReadSplitLong() => Read().Split().Select(long.Parse).ToList();

        static void Print(object value) => Console.Write(value.ToString());
        static void Println(object value) => Console.WriteLine(value.ToString());

        static string Join<T>(IEnumerable<T> list) => string.Join("", list);
    }

    public static class MyExtensions
    {
        public static string Slice(this string str, int start = 0, int stop = 0)
        {
            if (start > str.Length || stop > str.Length || start < 0 || stop < 0)
                return "";

            if (stop == 0) stop = str.Length;
            return str.Substring(start, stop - start);
        }
    }
}


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

int main(){
  char sent;
  int a = 0;
  vector<int> count(26, 0);
  while(cin>>sent){
    if(sent >= 'a' && sent <= 'z'){
      a = sent - 'a';
      
    count.at(a) ++;
    }
    else if(sent <= 'Z'&& sent >= 'A') {
      a = sent - 'A';
      
    count.at(a) ++;
    }
    
  }
  
  for(int i = 0; i < 26; i++){
    sent = 'a' + i; 
    cout << sent << " : " << count.at(i) << endl;
  }
}


Measured memory_bytes: 3088
#include<bits/stdc++.h>
using namespace std;
    static const double pi = 3.141592653589793;
 typedef pair<int64_t,int64_t> P;
#define rep(i, n) for (int i = 0; i < (n); i++)
 #define all(v) (v).begin(),(v).end()
 using ll = long long;
using Graph = vector<vector<int>>;

int main(){
string a;
ll n;
  cin>>n;
  cin>>a;
  
  vector<set<ll>>abc(26);
  rep(i,n){
  
    abc[a.at(i)-'a'].insert(i);
  
  }
  ll q;
  cin>>q;
  
 
  rep(i,q){
  ll d;
    cin>>d;
    if(d==1){
    ll k;
      cin>>k;
      k--;
      char w;
      cin>>w;
    abc[a[k]-'a'].erase(k);
      abc[w-'a'].insert(k);
      a[k]=w;
    }
  else{
  ll g,h;
    cin>>g>>h;
 
  g--;
    h--;
    ll sam=0;
 rep(i,26){
    auto it = abc[i].lower_bound(g);
                if (it != abc[i].end() && *it <= h) sam++;
 
 }
     cout<<sam<<endl;
  }
  
  }
  
  
  }
 





Measured memory_bytes: 24196
# coding: utf-8
# Your code here!
import sys
readline = sys.stdin.readline
read = sys.stdin.read


#n,m,*ab = [int(i) for i in read().split()]

k = int(input())
s = input()
if len(s) <= k:
    print(s)
else:
    print(s[:k]+"...")
    


Measured memory_bytes: 9160
#include <iostream>
#include <string>
using namespace std;
int main()
{
	int n;
	cin>>n;
  string s;
  cin>>s;
  if(s.size()<=n)
  {
  	cout<<s;
  }
  else{
  	for(int i=0;i<n;i++)
  	{
  		cout<<s[i];
	  }
	  cout<<"...";
  }
  return 0;
}

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

#define ASC(vec) vec.begin(), vec.end()		// 昇順ソート 例：sort(ASC(vec));
#define DESC(vec) vec.rbegin(), vec.rend()	// 降順ソート 例:sort(DESC(vec));
#define rep(i, n) for(i = 0; i < n; i++)
#define Rep(i, n) for(i = 1; i < n; i++)
#define Ans(s) cout << s << endl;

const int inf = (int)1e9 + 7;
const long long INF = 1LL << 60;

template<class T> inline bool chmin(T & a, T b) { if (a > b) { a = b; return true; } return false; }
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }

int GCD(int a, int b) { return b ? GCD(b, a % b) : a; }

typedef long long ll;

// 4,8方向に探索する際に用いる配列
//int dx[4] = { 0,  0, 1, -1 };
//int dy[4] = { 1, -1, 0,  0 };
//int dx[8] = { 1, 0, -1,  0, 1, -1, -1,  1 };
//int dy[8] = { 0, 1,  0, -1, 1,  1, -1, -1 };

constexpr auto MAX = 1010;

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

	long double pairs = 1.0 / n;
	long double ans = 0.0;

	for (int i = 1; i <= n; i++)
	{
		long double cnt = 0;

		while (i * pow(2.0, cnt) < k)
		{
			cnt++;
		}
		//cout << pairs * (1.0 / pow(2.0, cnt)) << endl;
		ans += pairs * (1.0 / pow(2.0, cnt));
	}
	cout << setprecision(15) << ans << endl;
}

Measured memory_bytes: 256
# -*- coding: utf-8 -*-
"""
Created on Tue May 12 00:13:44 2020

@author: shinba
"""
import sys

w,h,x,y = map(int,input().split())

if w%2 == 0 and h%2 == 0:
    if w//2 == x and h//2 == y:
        print((h*w)/2,1)
        sys.exit()
        
print(h*w/2,0)

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

int main() {

    int N;
    cin >> N;
    
    vector< tuple<string, int, int> > G(N);
    
    for(int i = 0; i < N; i++){
        string S;
        int P;
        cin >> S >> P;
        
        G.at(i) = make_tuple(S, -P, i+1);
    }
    
    sort(G.begin(), G.end());
 
    for(int i = 0; i < N; i++){
        cout << get<2>(G[i]) << endl;
    }   
    
    
    
}


Measured memory_bytes: 256
n = int(input())

testimony_dict = {}
for i in range(n):
    a = int(input())
    testimony_dict[i + 1] = []
    for j in range(a):
        xy = input().split(' ')
        testimony_dict[i + 1].append(xy)

max_valid_bin = ''
for i in range(2 ** n - 1, 0, -1):
    is_valid = True
    bin_i = format(i, '0{}b'.format(n))
    for j in range(1, len(bin_i) + 1):
        if bin_i[j - 1] == '1':
            for xy_list in testimony_dict[j]:
                if bin_i[int(xy_list[0]) - 1] != xy_list[1]:
                    is_valid = False
    if is_valid:
        max_valid_bin = bin_i
        break

print(len([i for i in max_valid_bin if i == '1']))


Measured memory_bytes: 3064
/************************************************
   Start coding only after you have clear idea. 
*************************************************/

#include <bits/stdc++.h>

#define x first
#define y second
#define pii pair<int,int>
#define sz(x) (int)(x).size()
#define all(x) (x).begin(),(x).end()
using namespace std;
typedef long long LL;
const int maxm = 2e3+23;
const int maxn = 2e5+35;
int n,f[maxn];
int main(){
    cin >> n;
    for(int x = 1;x <= 100; ++x){
        for(int y = 1;y <= 100; ++y){
            for(int z = 1;z <= 100; ++z){
                int sum = x*x+y*y+z*z+x*y+x*z+y*z;
                if(sum <= n) f[sum] += 1;
            }
        }
    }
    for(int i = 1;i <= n; ++i) cout << f[i] << '\n';
    return 0;
}

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

int w,h;
int c[100][100];
int dy[] = {-1,-1,0,1,1,1,0,-1}, dx[] = {0,1,1,1,0,-1,-1,-1};

void rec(int y,int x){
  if(y<0 || x<0 || y>=h || x>=w)return;
  if(c[y][x]==0)return;
  c[y][x] = 0;
 
  for(int i=0;i<8;i++){
    rec(y+dy[i],x+dx[i]);
  }
}
 
int main(){
  while(cin >> w >> h,w){
    for(int i=0;i<h;i++){
      for(int j=0;j<w;j++)cin >> c[i][j];
    }

    int cnt = 0;
    for(int i=0;i<h;i++){
      for(int j=0;j<w;j++){
	if(c[i][j]){
	  rec(i,j); cnt++;
	}
      }
    }

    cout << cnt << endl;
  }
}

Measured memory_bytes: 1256
#include <iostream>
#include <iterator>
#include <vector>
#include <algorithm>
#include <string>
#include <functional>
#include <bitset>
#include <cmath>

using namespace std;

int main()
{

    bitset<28> subset, T;
    
    int n, k, b;
    cin >> n >> k;

    while (k--)
    {
        cin >> b;
        T[b] = 1;
    }

    int upper = pow(2, n);
    for (int i = 0; i < upper; i++)
    {
        subset = i;
        if ((subset|T) == T)
        {
            cout << i << ":";            
            for (int j = 0; j < n; j++)
            {
                if (subset[j])
                {
                    cout << ' ' <<  j;
                }
            }
            cout << endl;            
        }

    }
}


Measured memory_bytes: 3284
#include <iostream>
#include <vector>
#include <string>
#include <sstream>
#include <ctime>
using namespace std;

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

int task(int N, int W, vector<int> &weight, vector<int> &value) {
	int V = 0;
	for (int x : value) {
		V += x;
	}
	vector<vector<int>> result(N + 1, vector<int> (V + 1, W + 1));
	result[0][0] = 0;
	for (int i = 1; i <= N; i++) {
		for (int v = 0; v <= V; v++) {
			if (value[i - 1] > v) {
				result[i][v] = result[i-1][v];
			} else {
				result[i][v] = min(result[i-1][v], result[i-1][v - value[i - 1]] + weight[i - 1]);
			}
		}
	}
	for (int v = V; v > 0; v--) {
		if (result[N][v] <= W) return v;
	}
	return 0;
}

void read_input(int &N, int &W, vector<int> &weight, vector<int> &value) {
	string seq;
	// read N, K
	getline(cin, seq);
	istringstream iss(seq);
	iss >> N;
	iss >> W;
	iss.clear();
	int buf;
	for (int i = 0; i < N; i++) {
		getline(cin, seq);
		iss.str(seq);
		iss >> buf;
		weight.push_back(buf);
		iss >> buf;
		value.push_back(buf);
		iss.clear();
	}
}

int main() {
	int N, W;
	vector<int> weight;
	vector<int> value;
	read_input(N, W, weight, value);
	//unsigned init_time = clock();
	cout << task(N, W, weight, value) << endl;
	//unsigned end_time = clock();
	//cout << double(end_time - init_time) / CLOCKS_PER_SEC << " seconds" << endl;
	return 0;
}

Measured memory_bytes: 40192
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define PI 3.141592653589793
#define rep(i, n) for (int i = 0; i < (n); i++)
#define REP(i, a, n) for (int i = a; i < (n); i++)
#define rrep(i, n, k) for (int i = (n); i >= (k); i--);
#define all(x) (x).begin(), (x).end()
#define vi vector<int>
template<class T> istream &operator>>(istream&is,vector<T>&v){for(auto &elemnt:v)is>>elemnt;return is;}
template<class T,class U> istream &operator>>(istream&is,pair<T,U>&p){is>>p.first>>p.second;return is;}
template<class T>vector<T> make_vector(size_t a){return vector<T>(a);}
template<class T, class... Ts>auto make_vector(size_t a, Ts... ts){return vector<decltype(make_vector<T>(ts...))>(a, make_vector<T>(ts...));}
const int MOD = 1e9 + 7;
const int INF = 2e18;

signed main() {
    int N;
    cin >> N;
    vector<vector<int>> tree(N + 1);
    vector<int> ans(N + 1, 0), count(N + 1, 0);
    vector<multiset<int>> save(N + 1);
    for (int i = 2; i <= N; i++) {
        int temp;
        cin >> temp;
        count[temp]++;
        ans[temp]++;
        tree[i].push_back(temp);
    }
    vector<int> check(N + 1, 0);
    queue<int> explore;
    for (int i = 1; i <= N; i++) if (count[i] == 0) explore.push(i);
    while (!explore.empty()) {
        int now = explore.front();
        explore.pop();
        if (check[now] != count[now]) {
            explore.push(now);
            continue;
        }
        int maxValue = 0, temp = 1;
        for (auto itr = save[now].rbegin(); itr != save[now].rend(); itr++) {
            maxValue = max(maxValue, temp++ + *itr);
        }
        ans[now] = maxValue;
        for (auto next : tree[now]) {
            save[next].insert(ans[now]);
            check[next]++;
            if (check[next] == count[next]) explore.push(next);
        }
    }
    cout << ans[1] << endl;
}

Measured memory_bytes: 17536
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.Set;
import java.util.HashMap;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.StringTokenizer;
import java.io.BufferedReader;
import java.util.Collections;
import java.io.InputStream;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        InputReader in = new InputReader(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        TaskC solver = new TaskC();
        solver.solve(1, in, out);
        out.close();
    }

    static class TaskC {
        public void solve(int testNumber, InputReader in, PrintWriter out) {
            int n = in.nextInt();
            HashMap<String, Integer> map = new HashMap<>();
            int maxRep = 1;
            for (int i = 0; i < n; i++) {
                String s = in.next();
                if (!map.containsKey(s)) {
                    map.put(s, 1);
                } else {
                    int oldValue = map.get(s);
                    map.replace(s, oldValue + 1);
                    maxRep = Math.max(maxRep, oldValue + 1);
                }
            }
            ArrayList<String> list = new ArrayList<>();
            Set<String> set = map.keySet();
            for (String s : set) {
                if (map.get(s) == maxRep)
                    list.add(s);
            }
            Collections.sort(list);
            for (String s : list) {
                out.println(s);
            }
        }

    }

    static class InputReader {
        public BufferedReader reader;
        public StringTokenizer tokenizer;

        public InputReader(InputStream stream) {
            reader = new BufferedReader(new InputStreamReader(stream), 32768);
            tokenizer = null;
        }

        public String next() {
            while (tokenizer == null || !tokenizer.hasMoreTokens()) {
                try {
                    tokenizer = new StringTokenizer(reader.readLine());
                } catch (IOException e) {
                    throw new RuntimeException(e);
                }
            }
            return tokenizer.nextToken();
        }

        public int nextInt() {
            return Integer.parseInt(next());
        }

    }
}



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

int main(){
  string s;
  cin >> s;
  
  int zero, one;
  zero = 0;
  one = 0;
  for(int i = 0; i < s.size(); i++){
    if(s[i] == '0'){
      zero++;
    }else{
      one ++;
    }
  }
  
  cout << s.size() - abs(zero - one) << endl;
}

Measured memory_bytes: 512
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
using ll = long long;
#define _DEBUG
     
int main() {
  int n;
  cin >> n;
  n %= 10;
  if (n == 2 || n == 4 || n == 5 || n == 7 || n == 9) cout << "hon" << endl;
  if (n == 0 || n == 1 || n == 6 || n == 8) cout << "pon" << endl;
  if (n == 3) cout << "bon" << endl;
}

Measured memory_bytes: 3632
const lines=readlines()
input()=shift!(lines)
int(x)=parse(Int,x)
function intLine()
    s=input()|>split
    int(s[1]),int(s[2])
end
function inE(e)
    x=intLine()
    push!(e[x[1]],x[2])
end
function bfs(e,f,s,t)
    q=Array{Pair{Int,Int}}([s=>1])
    while !isempty(q)
        v,m=shift!(q)
        u=m>2?1:m+1
        for w=e[v]
            if f[w,u]<0
                f[w,u]=f[v,m]+1
                push!(q,w=>u)
            end
        end
    end
end
function main()
    n,m=intLine()
    e=Array{Int,1}[[]for i=1:n]
    for i=1:m;inE(e);end
    s,t=intLine()
    f=ones(Int,(n,3))*-3
    f[s,1]=0
    bfs(e,f,s,t)
    show(f[t,1]÷3)
end
main()

Measured memory_bytes: 168024
#include<iostream>
#include<cstdio>
using namespace std;
int M[101][101];
int main(){
  int n,u,k,v;
  cin>>n;
  for(int i=0;i<n;i++){
    cin>>u>>k;
    u--;
    for(int j=0;j<k;j++){
      cin>>v;
      v--;
      M[u][v]=1;
    }
  }
  for(int i=0;i<n;i++){
    for(int j=0;j<n;j++){
      if(j) cout<<" ";
      cout<<M[i][j];
    }
    cout<<endl;
  }
  return 0;
}



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

using namespace std;

int main(){
  int N, M;
  int p[100010];
  string S[100010];
  bool ACflag[100010];
  int ansAC=0;
  int ansWA=0;
  int WA[100010];
  cin >> N >> M;
  for(int i=1; i<=M; i++){
    cin >> p[i];
    cin >> S[i];
  }
  for(int i=1; i<=N; i++){
    WA[i]=0;
    ACflag[i]=false;
  }
  for(int i=1; i<=M; i++){
    if(S[i]=="WA"&&ACflag[p[i]]==false) WA[p[i]]++;
    else if(S[i]=="AC"&&ACflag[p[i]]==false){
      ansAC++;
      ACflag[p[i]]=true;
    }
  }
  for(int i=1; i<=N; i++){
    if(ACflag[i]==true) ansWA+=WA[i];
  }
  cout << ansAC << " " << ansWA << endl;
  
  return 0;
}

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

#define lint long long
#define P pair<int, int>
#define LLP pair<long long, long long>
#define REP(i, x, n) for(int i = (x), i##_len = (int)(n) ; i < i##_len ; ++i)
#define rep(i, n) for(int i = 0, i##_len = (int)(n) ; i < i##_len ; ++i)
#define repr(i, n) for(int i = (int)(n) - 1 ; i >= 0 ; --i)
#define SORT(x) sort((x).begin(), (x).end())
#define SORT_INV(x) sort((x).rbegin(), (x).rend())

const int IINF = 1e9 + 100;
const long long LLINF = 2e18 + 129;
const long long MOD = 1e9 + 7;
const int dx4[] = {1, 0, -1, 0}, dy4[] = {0, 1, 0, -1};
const int dx8[] = {1, 1, 0, -1, -1, -1, 0, 1}, dy8[] = {0, -1, -1, -1, 0, 1, 1, 1};
const double EPS = 1e-8;

int v, e;
int cost[15][15];
int dp[15][1 << 15];

template<typename T>
bool chmin(T &a, T b){
    if(a > b){
        a = b;
        return true;
    }else{
        return false;
    }
}

int solve(int now, int S){
    if(dp[now][S] >= 0){
        return dp[now][S];
    }
    if(S == (1 << v) - 1){
        if(now == 0){
            return dp[now][S] = 0;
        }else{
            return dp[now][S] = IINF;
        }
    }

    int res = IINF;
    rep(i, v){
        if(S >> i & 1){
            continue;
        }
        chmin(res, solve(i, S | (1 << i)) + cost[now][i]);
    }

    return dp[now][S] = res;
}

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

    cin >> v >> e;

    rep(i, v){
        rep(j, v){
            cost[i][j] = IINF;
        }
        cost[i][i] = 0;
    }

    rep(i, e){
        int s, t, d;
        cin >> s >> t >> d;
        chmin(cost[s][t], d);
    }

    rep(i, v){
        rep(j, 1 << v){
            dp[i][j] = -1;
        }
    }

    int ans = solve(0, 0);

    if(ans < IINF){
        cout << ans << endl;
    }else{
        cout << -1 << endl;
    }

    return 0;
}


Measured memory_bytes: 5088
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define vi vector<int>
#define vll vector<long long>
#define pb push_back
void solve(){
    ll x;cin>>x;
    int i;
    for(i=1;;i++){
        if(i*(i+1)>=2*x)
        break;
    }
    cout<<i;
}
int  main(){
	//freopen("input.txt","r",stdin);
	//freopen("output.txt","w",stdout);
	ios::sync_with_stdio(0);
	cin.tie(0);
	int t;
    //cin>>t;
	t=1;
	while(t--){
		solve();
	}
	return 0;
}

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

#define REP(i,n) for(int i=0; i < (n); ++i)
#define REPR(i,n) for(int i=(n); i >= 0; --i)
#define FOR(i, m, n) for(int i = (m); i < (n); ++i)

#define INF 1e9

int main(){
  string S, T;
  cin >> S >> T;
  cout << T << S << endl;
  return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int atmax(vector<vector<int>> a,int n,int d)
{
  int count=0;
  for(int i=0;i<n;i++)
  {
    double a1=pow(a[i][0],2),a2=pow(a[i][1],2);
    double res=sqrt(a1+a2);
    if(res<=d)
      count++;
  }
  return count;
}
int main()
{
  int n,d,t;
  cin>>n>>d;
  vector<vector<int>> a;
  vector<int> v;
  for(int i=0;i<n;i++)
  {
    for(int i=0;i<2;i++)
    {
      cin>>t;
      v.push_back(t);
    }
    a.push_back(v);
    v.clear();
  }
  int res=atmax(a,n,d);
  cout<<res;
  return 0;
}

Measured memory_bytes: 25100
<?php
fscanf(STDIN,"%d %d %d",$a,$b,$c);
if($b-$a>0){
if($a<$c&&$c<$b){
echo("Yes");
}else{
echo("No");
}


}else{
if($b<$c&&$c<$a){
echo("Yes");
}else{
echo("No");

}
}

?>

Measured memory_bytes: 3700
#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < (int)(n); i++)
#define repr(i,n) for(int i = (int)(n-1); i >= 0; i--)
#define rep2(i,x,n) for(int i = (int)(x); i < (int)(n); i++)
#define repit(itr,x) for(auto itr = x.begin(); itr != x.end(); itr++)
#define repitr(ritr,x) for(auto ritr = x.rbegin(); ritr != x.rend(); ritr++)
#define ALL(n) begin(n), end(n)
using ll = long long;
using namespace std;

int main(){
	int a, b;
	cin >> a >> b;
	int t1, t2, t3;
	t1 = a + b;
	t2 = a - b;
	t3 = a * b;
	int ans = max(t1, t2);
	ans = max(ans, t3);
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 256
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<cmath>
#include<map> 
#include<iostream>
#include<time.h>
using namespace std;
typedef long long ll;
const double pi=acos(-1.0);
const ll mod=1e9+7;
const int inf=0x3f3f3f3f;
//ll begin_time=clock();
//ll end_time=clock();printf("time=%lldms\n",end_time-begin_time);
/****************************************************************************/ 

ll z[405];
int main()
{
	for(ll i=0;i<=400;i++)
	{
		if(i<=200)z[i]=-1LL*i*i*i*i*i;
		else 
		{
			ll ii=i-200;
			z[i]=1LL*ii*ii*ii*ii*ii;
		}
	}
	ll a,b,c,d;
	cin>>a;
	b=0;
	for(int i=0;i<=400;i++)
	{
		if(b)break;
		for(int j=0;j<=400;j++)
		{
			if(z[i]-z[j]==a)
			{
				b=1;
				c=i;d=j;
				if(c>200)c-=200;
				else c=-c;
				if(d>200)d-=200;
				else d=-d;
				printf("%d %d\n",c,d);
				break;
			}
		}
	}
	
}




Measured memory_bytes: 3764
#include <iostream>

using namespace std;
int main(){
    int box[100000];
    int red[100000];

    for(int i=0;i<100000;i++){
        box[i]=1;
        red[i]=0;
    }
    red[0]=1;

    int n,m;
    cin>>n>>m;
    int x,y;
    for(int i=0;i<m;i++){
        cin>>x>>y;
        x--;y--;

        if(box[x]==1 && red[x]>0){
            red[x]=0;
            red[y]=1;
        }else if(box[x]>1 && red[x]>0){
            red[y]=1;
        }
        box[x]--;
        box[y]++;
    }

    int sum=0;
    for(int i=0;i<100000;i++){
        if(red[i]>0)sum++;
    }
    cout<<sum<<endl;

    return 0;
}

Measured memory_bytes: 1024
a, b, c, x = [int(d[0]) for d in [input().split() for _ in range(4)]]
cnt = 0
for o in range(a+1):
    for p in range(b+1):
        for q in range(c+1):
            if o * 500 + p * 100 + q * 50 == x:
                cnt += 1
print(cnt)

Measured memory_bytes: 3060
#include<bits/stdc++.h>
using namespace std;
char a[5][5];
int main()
{
	for(int i=1;i<=3;i++)
	for(int j=1;j<=3;j++)
	cin>>a[i][j];
	cout<<a[1][1];
	cout<<a[2][2];
	cout<<a[3][3];
	return 0;
}

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

int n, W, w[102], v[102];
int dp[103][100005];

int main() {
	scanf("%d %d", &n, &W);
	int sum = 0;
	for(int i = 1;i <= n; i++) {
		scanf("%d %d", &w[i], &v[i]);
		sum += v[i];
	}
	for(int i = 0;i <= n; i++) {
		for(int j = 0;j <= sum; j++) {
			dp[i][j] = 1e9;
		}
	}
	
	dp[0][0] = 0;
	for(int i = 1;i <= n; i++) {
		for(int j = sum;j >= 0; j--) {
			if(j-v[i] < 0) dp[i][j] = dp[i-1][j];
			else dp[i][j] = min(dp[i-1][j], dp[i-1][j-v[i]]+w[i]);
		}
	}
	
	
	int ans = 0;
	for(int i = sum;i >= 0; i--) if(dp[n][i] <= W) {
		ans = i;
		break;
	} 
	
	printf("%d\n", ans);
}

Measured memory_bytes: 43176
#include <bits/stdc++.h>
using namespace std;
static const double PI = std::acos(-1.0);

int main() {
  double a, b, h, m;
  cin >> a >> b >> h >> m;
  auto u = polar(a, 2 * PI * ((h + m / 60) / 12));
  auto v = polar(b, 2 * PI * (m / 60));
  cout << fixed << setprecision(10);
  cout << abs(v - u) << endl;
}


Measured memory_bytes: 4088
#include<bits/stdc++.h>
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define rep2(i, m, n) for(int i = (int)(m); i < (int)(n); i++)
#define rep_inv(i, n, m) for(int i = (int)(n); i > (int)(m); i--)
using namespace std;
using ll = long long;
using vl = vector<ll>;
using vc = vector<char>;
using vvl = vector<vl>;
using vvc = vector<vc>;
using pll = pair<ll, ll>;
using vpll = vector<pll>;

int main(){
  ll n;
  cin >> n;
  vl a(n);
  rep(i, n) cin >> a[i];

  ll sum1 = 0, sum2 = 0;
  ll c1 = 0, c2 = 0;

  if(a[0] > 0){
    sum1 = a[0];
    c2 = a[0] + 1;
    sum2 = -1;
  } else if(a[0] < 0){
    sum2 = a[0];
    c1 = 1 - a[0];
    sum1 = 1;
  } else{
    sum1 = 1;
    sum2 = -1;
    c1 = c2 = 1;
  }

  rep2(i, 1, n){
    // cout << c1 << ' ' << sum1 << ' ' << c2 << ' ' << sum2 << endl;
    
    if(a[i] == 0){
      c1 += abs(sum1) + 1;
      c2 += abs(sum2) + 1;
      sum1 = sum1 > 0 ? -1 : 1;
      sum2 = sum2 > 0 ? -1 : 1;
      
      continue;
    }
    
    if((sum1 + a[i]) * (sum1 > 0 ? -1 : 1) <= 0){
      c1 += abs(((sum1 > 0 ? -1 : 1) - sum1) - a[i]);
      sum1 = sum1 > 0 ? -1 : 1;
    } else{
      sum1 += a[i];
    }
    
    if((sum2 + a[i]) * (sum2 > 0 ? -1 : 1) <= 0){
      c2 += abs(((sum2 > 0 ? -1 : 1) - sum2) - a[i]);
      sum2 = sum2 > 0 ? -1 : 1;
    } else{
      sum2 += a[i];
    }
    
  }
  
  // cout << c1 << ' ' << sum1 << ' ' << c2 << ' ' << sum2 << endl;

  cout << min(c1, c2) << endl;
  
  return 0;
}


Measured memory_bytes: 1024
s = list(input())
n = len(s)
temp = ['maerd', 'remaerd', 'esare', 'resare']
s.reverse()

i = 0
while i < n:
    flag = False
    for t in temp:
        if s[i:i+len(t)] == list(t):
            i += len(t)
            flag = True
            break

    if not flag:
        print("NO")
        exit()

print("YES")


Measured memory_bytes: 3956
fun main(args: Array<String>) 
{
    val (a,b) = readLine()!!.split(" ").map{x -> x.toInt()};
    if(a==b)println("Draw");
    else
    {
        if(a==1)println("Alice");
        else if(b==1)println("Bob");
        else
        {
            if(a>b)println("Alice");
            else println("Bob");
        }
    }
}


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

int main(){
  int n,k;
  int a[1000000];

  for(;;){
    cin >> n >> k;
    if(!n && !k)break;

    for(int i=0;i<n;i++)cin >> a[i];
    int sum = 0;
    for(int i=0;i<k;i++)sum += a[i];
    int m = sum;
    for(int i=k;i<n;i++){
      sum += a[i] - a[i-k];
      m = max(m,sum);
    }
    cout << m << endl;
  }
}

Measured memory_bytes: 0
#include <stdio.h>

typedef struct{
	int num;
	int sc;
}person;

int main(void){
	int n, i, max=0, ans=0;
	person p[20];

	scanf("%d", &n);
	for(i=0; i<n; i++)
		scanf(" %d %d", &p[i].num, &p[i].sc);
	
	for(i=0; i<n; i++){
		if( (max < p[i].sc) || (max == p[i].sc && p[i].num < p[ans].num) ) {
			max = p[i].sc;
			ans = i;
		}
	}
	
	printf("%d %d\n", p[ans].num, p[ans].sc);

	return 0;
}

Measured memory_bytes: 600
#include<cstdio>

int main()

{

	int a ,b,c ,d;

	while(scanf("%d%d%d%d",&a,&b,&c,&d)!=EOF)

	{

		a=a*b;

		c=c*d;

		if(a>c)

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

		else

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

	}

	return 0;

}


Measured memory_bytes: 128
#include<iostream>
#include<string.h>
#include<stdio.h>

using namespace std;

int main(){
    int top3Mountain[3];
    memset(top3Mountain, 0, sizeof(top3Mountain));
    
    for (int i=0; i<10; i++) {
        int newHeight = 0;
        scanf("%d", &newHeight);
        
        if (top3Mountain[0] < newHeight) {
            top3Mountain[2] = top3Mountain[1];
            top3Mountain[1] = top3Mountain[0];
            top3Mountain[0] = newHeight;
        } else if (top3Mountain[1] < newHeight) {
            top3Mountain[2] = top3Mountain[1];
            top3Mountain[1] = newHeight;
        } else if (top3Mountain[2] < newHeight) {
            top3Mountain[2] = newHeight;
        }
    }
    
    for (int i=0; i<3; i++) {
        printf("%d\n", top3Mountain[i]);
    }
    
    return 0;
}

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

#define rep(i, n) for(int i = 0; i<(n); i++)
#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)
using namespace std;
using ll = long long;

const ll INF = 1LL << 60;
const int MAX_N = 410;

ll memo[MAX_N][MAX_N];
bool visited[MAX_N][MAX_N];
vector<ll> sum;

ll rec(int L, int R) { // [L, R]の最小コスト
    if (L == R) return 0;
    if (visited[L][R]) return memo[L][R];
    visited[L][R] = true;

    ll res = INF;
    ll now = sum[R + 1] - sum[L]; // 今回の合成で増えるコスト
    for (int i = L; i < R; i++) { // [L, R]間の区切り位置を全部試す
        chmin(res, rec(L, i) + rec(i + 1, R) + now);
    }
    return memo[L][R] = res;
}

int main() {
    int N;
    cin >> N;
    vector<ll> a(N);
    rep(i, N) cin >> a[i];

    sum.resize(N + 1);
    rep(i, N) sum[i + 1] = sum[i] + a[i];

    cout << rec(0, N - 1) << endl;
}

Measured memory_bytes: 1664
#include <bits/stdc++.h>
#define rep(i,a,b) for(int i=a;i<b;i++)

using namespace std;

int main(){

	string nums[] = {".,!? ","abc","def","ghi","jkl",
					"mno","pqrs","tuv","wxyz"};

	int N;
	string ts;
	vector<string> v;
	vector<string> ans;

	cin>>N;
	for(int i=0; i<N; i++){
		cin>>ts;
		v.push_back(ts);
	}
	for(int i=0; i<N; i++){
		bool flag = true;
		int k=-1,cnt=0;
		ans.push_back("");
		for(int j=0; j<v[i].size(); j++){
			cnt = 0;
			while(1){
				if(flag){
					flag = false;
					k = (int)(v[i][j] - '0'-1);
					cnt=-1;
				}
				if(cnt == nums[k].size()) cnt = 0;
				if(v[i][j] == '0'){
					if(k!=-1) ans[i] += nums[k][cnt];
					flag = true;
					break;
				}

				cnt++;
				j++;
			}
		}
	}

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

	return 0;
}

Measured memory_bytes: 3132
//A.cpp
#include <iostream>
#include <string>
#include <algorithm>
#include <set>
#include <map>
#include <vector>
#include <queue>
#include <stack>
#include <math.h>
#define rep(i,n) for(int i = 0; i < (n); ++i)
using namespace std;
typedef long long ll;
ll gcd(ll a,ll b){return b!=0?gcd(b,a%b):a;}
ll lcm(ll a,ll b){return a*b/gcd(a,b);}
const ll mod=1e9+7;

int main(){
  string s,t;
  cin >> s >> t;
  int a,b;
  cin  >> a >> b;
  string u;
  cin >> u;
  if(u == s) printf("%d %d\n",a-1,b);
  else printf("%d %d\n", a,b-1);
  return 0;
}


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

using namespace std;


void solve() {
    int n, k;
    cin >> n >> k;
    string s; cin >> s;
    string t = s; reverse(t.begin(), t.end());
    string u = s + t;
    char mi = 'z';
    for (char x: s) {
        mi = min(mi, x);
    }
    int mx = 1;
    vector<int> len(2*n+1, 0);
    for (int i = 0; i < 2*n; i++) {
        len[i+1] = u[i] == mi ? len[i]+1 : 0;
        len[i+1] = min(len[i+1], n);
        mx = max(mx, len[i+1]);
    }
    if (k>15 || (1<<(k-1))*mx >= n) {
        for (int i = 0; i < n; i++) {
            cout << mi;
        }
        return;
    }
    int rep =(1<<(k-1)) * mx;
    int m = n - rep;
    string res = "{";
    for (int i = n+1; i <= 2*n; i++) {
        if (len[i] == mx) {
            string tmp = u.substr(i-m-mx, m);
            reverse(tmp.begin(), tmp.end());
            res = min(res, tmp);
        }
    }
    for (int i = 0; i < rep; i++) {
        cout << mi;
    }
    cout << res;
}

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    solve();
    cout << endl;
}


Measured memory_bytes: 384
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <cmath>
using namespace std;

int main()
{
    long n;
    long long acc = 0;
    cin >> n;
    for (long i =  1; i <= n; i++) {
        if (i % 3 == 0 || i % 5 == 0)
            continue;
        acc += i;
    }
    cout << acc << endl;
    return 0;
}

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

using namespace std;

int main() {
	string s; cin >> s;
	if (s == "Sunny") cout << "Cloudy" << endl;
	else if (s == "Cloudy") cout << "Rainy" << endl;
	else cout << "Sunny" << endl;

	return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
int main()
{
	int nc,N,K,total=1;
	scanf("%d",&N);
	scanf("%d",&K);
	while(N--)
	{
		if(total<K)
		{
			total = total*2;
		}
		else
		{
			total = total+K;
		}
	}
	printf("%d\n",total);
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
#define INF (1<<30)
#define MOD 1000000007
#define l_ength size
using ll = long long;
using namespace std;

int n;
vector<ll> h;
ll a, b;

bool ok( ll t ){
	vector<ll> cand;
	for( auto &i : h ){
		if( i-b*t > 0 ){
			cand.push_back(i-b*t);
		}
	}
	ll c = a-b;
	ll cnt = 0;
	for( auto &i : cand ){
		cnt += (i+(c-1))/c;
	}
	return cnt <= t;
}

int main(){
	cin >> n >> a >> b;
	for( int i = 0; i < n; ++i ){
		ll temp; cin >> temp;
		h.push_back(temp);
	}
	ll l = 0;
	ll r = 100000000000000/b;
	ll mid;
	while( r-l > 1 ){
		mid = (l+r)/2;
		if( ok(mid) ){
			r = mid;
		} else {
			l = mid;
		}
	}
	cout << r << endl;
	return 0;
}

Measured memory_bytes: 2896
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<n;++i)
#define rrep(i,n) for(int i=n-1;i>=0;--i)
#define REP(i,a,b) for(int i=a;i<b;i++)
#define yesno(flg) if(flg){cout<<'YES'<<endl;}else{cout<<'NO'<<endl;}
#define vi vector<int>
#define pb push_back
#define i197 1000000007
#define MAX_N 200002
using namespace std;

typedef long long ll;
typedef pair<int,int> Pii;
typedef pair<Pii,int> Piii;
typedef pair<int,ll> Pil;
typedef pair<ll,ll> Pll;
typedef pair<string,int> Psi;
typedef pair<Psi,int> Psii;

const int inf=1000000000;
struct edge{
	int myc,to,c,cost;
};
struct pos{
	int to,cost,color;
};
int dy[]={0, 0, 1, -1};
int dx[]={1, -1, 0, 0};

vi vec[200001];
int x[200001]={};
int dp[200001];

int main() {
	int n;
	string s;
	cin>>n>>s;
	char s1=s[0];
	int r=1;
	rep(i,n-1){
		if(s1!=s[i+1]){
			r++;
			s1=s[i+1];
		}
	}
	cout<<r<<endl;
	return 0;
}


Measured memory_bytes: 5120
/**
 *		author:  zvm
 *		created: 28.09.2020 17:53:16
**/

#include <bits/stdc++.h>

using namespace std ;

template <typename T>
class Segment_tree {
	public :
		Segment_tree( int _n ) {
			n = _n ;
			tree.resize(2*n,0) ;
		}

		T combine( T lchild, T rchild ) {
			return max(lchild, rchild);
		}

		void update( int idx, T val ) {
			for( tree[idx+=n] = val, idx /= 2 ; idx >= 1 ; idx /= 2 ) {
				tree[idx] = combine( tree[idx<<1], tree[idx<<1|1] );
			}
		}

		T query( int l, int r ) {
			T ans = 0 ;
			for( l += n, r += n ; l <= r ; l /= 2, r /= 2 ) {
				if( l&1 ) {
					ans = combine( ans, tree[l++] ) ;
				}
				if( !(r&1) ) {
					ans = combine( ans, tree[r--] ) ;
				}
			}
			return ans ;
		}

	private :
		int n ;
		vector<T> tree ;
};

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

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

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

	int sz = 1<<19 ;
	Segment_tree<int> dp(1<<19) ;

	// dp[i] stores max length of flat subseq ending with val i
	for( int i = 0 ; i < n ; ++i ) {
		dp.update( a[i], 1+dp.query( max(a[i]-k,0), min(a[i]+k,300000) ) );
	}

	cout << dp.query(0,sz-1) << endl ;
}


Measured memory_bytes: 8484
#include <bits/stdc++.h>
typedef long long ll;

using namespace std;

int main(){
    int N;
    cin >> N;
    int num[5]={0};
    num[0]=N/1000;
    num[1]=(N%1000)/100;
    num[2]=(N%100)/10;
    num[3]=(N%10);

    int bit[3]={0};
    for (int i=0;i<8;i++){
	int x=i;
	for (int j=0;j<3;j++){
	   bit[j]=x%2;
	   x/=2;
	}

	int cal=num[0];
	for (int j=0;j<3;j++){
	    if (bit[j] == 1){
		cal+=num[j+1];
	    } else {
		cal-=num[j+1];
	    }
	}

	if (cal == 7){
	    string s[5];
	    for (int j=0;j<3;j++){
		if (bit[j] == 1) s[j]='+';
		else s[j]='-';
	    }

	    cout << num[0] << s[0] << num[1] << s[1] << num[2] << s[2] << num[3] << "=7" << endl;
	
	    return 0;
	}
    }

    return 0;
}

Measured memory_bytes: 256