akhauriyash/Code-Regression huggingface dataset:
#include<stdio.h>
#include<string.h>
 
int main(){
    char s[1003]={'\0'};
    scanf("%s",s);
    int len=strlen(s);
 
    if(s[len-1]=='s'){
        s[len]='e';
        s[len+1]='s';
    }else{
        s[len]='s';
    }
    printf("%s",s);
    return 0;
}

Measured memory_bytes: 1732
n, t0 = list(map(int, input().split()))
t =  list(map(int, input().split()))

total = 0
for i in range(1,n):
    if t[i] - t[i-1] > t0:
        total += t0
    else:
        total += t[i] - t[i-1]
total += t0
print(total)

Measured memory_bytes: 25200
#include<bits/stdc++.h>
using namespace std;
#define MOD 1000000007
int mod(int a) 
{ 
    return (a%MOD + MOD) % MOD; 
} 
int main()
{
	ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
	int h,w;
	cin>>h>>w;
	vector<vector<char>>g(h,vector<char>(w));
	for(int i=0;i<h;i++)
	{
		for(int j=0;j<w;j++)
		{
			char x; cin>>x; g[i][j]=x;
		}
	}
	vector<vector<int>>dp(h,vector<int>(w,0));
	dp[0][0]=1;
	for(int i=0;i<h;i++)
	{
		for(int j=0;j<w;j++)
		{
			if(g[i][j]=='#')
			{
				continue;
			}
			if(i>0)
			{
				dp[i][j]+=mod(dp[i-1][j]);
			}
			if(j>0)
			{
				dp[i][j]+=mod(dp[i][j-1]);
			}
		}
	}
	cout<<mod(dp[h-1][w-1]);
return 0;
}

Measured memory_bytes: 5248
N = int(input())
L = [int(x) for x in input().split()]
L.sort()
cnt = 0

for i in range(len(L) - 2):
    for j in range(i+1, len(L)-1):
        for k in range(j+1, len(L)):
            a = L[i]
            b = L[j]
            c = L[k]
            p = a + b > c
            s = a != b
            t = b != c
            if p and s and t:
                cnt += 1
print(cnt)

Measured memory_bytes: 9100
A = int(input())
B = int(input())
C = int(input())
X = int(input())
counter = 0
for a in range(0, min(41, A+1)):
    for b in range(0, B+1):
        for c in range(0, C+1):
            if 500 * a + 100 * b + 50 * c == X:
                counter += 1
print(counter)

Measured memory_bytes: 3064
A = input()
opt = ['+','-']
for i in range(2):
  for j in range(2):
    for k in range(2):
      if eval(A[0]+opt[i]+A[1]+opt[j]+A[2]+opt[k]+A[3]) == 7:
        print(A[0]+opt[i]+A[1]+opt[j]+A[2]+opt[k]+A[3]+'=7')
        exit()

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

cnt = [[0,i] for i in range(n+1)]
cnt_a = [0] * (n+1)
cnt_b = [0] * (n+1)

for ai,bi in zip(a,b):
    cnt[ai][0] += 1
    cnt[bi][0] += 1
    cnt_a[ai] += 1
    cnt_b[bi] += 1

cnt.sort(reverse=True)
new_al = []
new_ar = []
new_bl = []
new_br = []
done = 0
for _,i in cnt:
    if(done >= n):
        new_ar += [i] * cnt_a[i]
        new_bl += [i] * cnt_b[i]
    elif(done + cnt_a[i] + cnt_b[i] <= n):
        new_al += [i] * cnt_a[i]
        new_br += [i] * cnt_b[i]
    else:
        if(cnt_a[i] > n-done):
            new_al += [i] * (n-done)
            new_ar += [i] * (cnt_a[i] - n + done)
            new_bl += [i] * cnt_b[i]
        else:
            new_al += [i] * cnt_a[i]
            new_br += [i] * (n - done - cnt_a[i])
            new_bl += [i] * (cnt_b[i] - (n - done - cnt_a[i]))
    done += cnt_a[i] + cnt_b[i]


new_a = new_al + new_ar[::-1]
new_b = new_bl + new_br[::-1]
new = [[ai,bi] for ai,bi in zip(new_a,new_b)]


new.sort()

ans =[]
for ni in new:
    x,y = ni
    if(x==y):
        print('No')
        exit()
    ans.append(y)

print('Yes')
print(' '.join(map(str,ans)))

Measured memory_bytes: 169476
using System;
using System.Collections.Generic;
using System.IO.Pipes;

namespace cswork
{
    class Program
    {
        class Scanner
        {
            string[] s;
            int i;

            char[] cs = new char[] { ' ' };

            public Scanner()
            {
                s = new string[0];
                i = 0;
            }

            public string next()
            {
                if (i < s.Length) return s[i++];
                string st = Console.ReadLine();
                while (st == "") st = Console.ReadLine();

                s = st.Split(cs, StringSplitOptions.RemoveEmptyEntries);
                i = 0;
                return next();
            }

            public int nextInt()
            {
                return int.Parse(next());
            }

            public long nextLong()
            {
                return long.Parse(next());
            }

            public double nextDouble()
            {
                return double.Parse(next());
            }
        }

        public Program() { }

        static void Main(string[] args)
        {
            new Program().Omame();
        }

        Scanner cin;
        const int MAXIN = 1024;
        bool[] used = new bool[MAXIN];
        int[] perm = new int[MAXIN];

        List<int[]> permList = new List<int[]>();

        public void Permutation(int pos, int n, int length)
        {
            if (pos == n)
            {
                permList.Add((int[])perm.Clone());
            }

            for (int i = 0; i < n; i++)
            {
                if (!used[i])
                {
                    perm[pos] = i;
                    used[i] = true;
                    Permutation(pos + 1, n, length);
                    used[i] = false;
                }
            }
        }

        void Omame()
        {
            cin = new Scanner();
            int x = cin.nextInt();
            int y = cin.nextInt();
            int z = cin.nextInt();

            Console.WriteLine(z + " " + x + " " + y);
        }

    }
}


Measured memory_bytes: 27792
#include <stdio.h>

int main() {
  int i, j = 0;
  char s[3], t[3];
  
  scanf("%s", s);
  scanf("%s", t);
  
  for( i = 0; i < 3; i++ ) {
      if (s[i] == t[i]) {
  		j++; 
	  }
  }
  
  printf("%d\n", j);
}


Measured memory_bytes: 128
#include <iostream>
#include <vector>
#include <array>
#include <list>
#include <string>
#include <stack>
#include <queue>
#include <deque>
#include <map>
#include <set>
#include <unordered_map>
#include <unordered_set>
#include <tuple>
#include <memory>
#include <cmath>
#include <algorithm>
#include <functional>
#include <iomanip>
#include <numeric>
#include <climits>
#include <cfloat>
#include <cassert>
#include <random>


int main() {
	long long int n, a, b; std::cin >> n >> a >> b;
	if ((b - a) % 2 == 0) {
		std::cout << (b - a) / 2 << std::endl;
	}
	else {
		auto min = std::min(a - 1, n - b);
		std::cout << min + (b - a + 1) / 2 << std::endl;
	}
}

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

int main() {
 int64_t a, b, c, d;
 cin >> a >> b >> c >> d;
 
 if (a * c >= 0 || b * d >= 0) cout << max(a * c, b * d) << endl;
 else cout << max(a * d, b * c) << endl;
}
  


Measured memory_bytes: 3672
#include <bits/stdc++.h>
#define ll long long int
#define fast ios_base::sync_with_stdio(false);cin.tie(NULL);
using namespace std;
template <class T1, class T2>void print(T1 a[], T2 n) { for (T2 i = 0; i < n; i++) { cout << a[i] << " ";} cout << endl;}
template <class T1, class T2>void print(vector<T1> a, T2 n) { for (T2 i = 0; i < n; i++) { cout << a[i] << " "; } cout << endl;}
ll modexpo(ll a, ll b, ll m) {if (b == 0) {return 1;} else if (a == 1) {return 1;} if (b % 2 == 0) {ll t = modexpo(a, b / 2, m); t = (t * t) % m; return t;} else {ll t = modexpo(a, b / 2, m); t = (t * t) % m; t = (t * a) % m; return t;}}


int dp[3001][3001];

// int fn(string s, string t, int idx1, int idx2) {
//     if (idx1 == 0) {
//         return 0;
//     }
//     if (idx2 == 0) {
//         return 0;
//     }

//     if (dp[idx1][idx2] != -1) {
//         return dp[idx1][idx2];
//     }

//     int ans = 0;
//     if (s[idx1 - 1] == t[idx2 - 1]) {
//         ans = fn(s, t, idx1 - 1, idx2 - 1) + 1;
//     }
//     else {
//         ans = max(fn(s, t, idx1 - 1, idx2), fn(s, t, idx1, idx2 - 1));
//     }

//     dp[idx1][idx2] = ans;
//     return ans;

// }


void dfs(string &ans, string s, string t, int idx1, int idx2) {

    if (idx1 == 0 || idx2 == 0) {
        return;
    }

    if (s[idx1 - 1] == t[idx2 - 1] ) {
        ans += (s[idx1 - 1]);
        dfs(ans, s, t, idx1 - 1, idx2 - 1);
    }
    else {
        int op1 = dp[idx1 - 1][idx2];
        int op2 = dp[idx1][idx2 - 1];
        if (op1 >= op2) {
            dfs(ans, s, t, idx1 - 1, idx2);
        }
        else {
            dfs(ans, s, t, idx1, idx2 - 1);
        }
    }
}



int main() {

    // taskkill /IM "cp.exe" /F
    fast



    memset(dp, -1, sizeof(dp));
    string s, t;
    cin >> s >> t;
    // fn(s, t, s.length(), t.length() );

    for (int i = 0; i <= s.length(); i++) {
        for (int j = 0; j <= t.length(); j++) {
            if (i == 0 || j == 0) {
                dp[i][j] = 0;
            }
            else if (s[i - 1] == t[j - 1]) {
                dp[i][j] = dp[i - 1][j - 1] + 1;
            }
            else {
                dp[i][j] = max(dp[i - 1][j], dp[i][j - 1]);
            }
        }
    }

    // cout << dp[s.length()][t.length()] << endl;



    string ans = "";
    // stack<char> ans;
    dfs(ans, s, t, s.length(), t.length());
    // // reverse(ans.begin(), ans.end());
    // // cout << ans << endl;
    // while (!ans.empty()) {
    //     cout << ans.top(); ans.pop();
    // }
    // cout << endl;

    // int i = s.length(), j = t.length();

    // while (i > 0 && j > 0) {
    //     if (s[i - 1] == t[j - 1]) {
    //         ans += s[i - 1];
    //         i--; j--;
    //     }
    //     else if (dp[i - 1][j] >= dp[i][j - 1]) {
    //         i--;
    //     }
    //     else {
    //         j--;
    //     }

    // }

    reverse(ans.begin(), ans.end());
    cout << ans << endl;

}

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

#define N 100005

int n, m;

vector<int> to[N];

vector<int> answer;

int dfn[N], low[N], tim;

void tarjan(int u, int f)
{
	dfn[u] = low[u] = ++tim;
	
	int cnt = 0;
	
	for (auto v : to[u])
		if (v != f)
		{
			if (!dfn[v])
			{
				tarjan(v, u);
				cnt += low[v] >= dfn[u];
				low[u] = min(low[u], low[v]);
			}
			else
				low[u] = min(low[u], dfn[v]);
		}
	
	if (cnt > (u ? 0 : 1))
		answer.push_back(u);
}

signed main(void) 
{
	cin >> n >> m;
	
	for (int u, v; m--; )
	{
		cin >> u >> v;
		
		to[u].push_back(v);
		to[v].push_back(u);
	}
	
	tarjan(0, -1);
	
	sort(begin(answer), end(answer));
	
	for (auto i : answer)
		cout << i << endl;
}

Measured memory_bytes: 6728
"""
根付き木の表現

 [INPUT]
13
0 3 1 4 10
1 2 2 3
2 0
3 0
4 3 5 6 7
5 0
6 0
7 2 8 9
8 0
9 0
10 2 11 12
11 0
12 0

[OUTPUT]
node 0: parent = -1, depth = 0, root, [1, 4, 10]
node 1: parent = 0, depth = 1, internal node, [2, 3]
node 2: parent = 1, depth = 2, leaf, []
node 3: parent = 1, depth = 2, leaf, []
node 4: parent = 0, depth = 1, internal node, [5, 6, 7]
node 5: parent = 4, depth = 2, leaf, []
node 6: parent = 4, depth = 2, leaf, []
node 7: parent = 4, depth = 2, internal node, [8, 9]
node 8: parent = 7, depth = 3, leaf, []
node 9: parent = 7, depth = 3, leaf, []
node 10: parent = 0, depth = 1, internal node, [11, 12]
node 11: parent = 10, depth = 2, leaf, []
node 12: parent = 10, depth = 2, leaf, []
"""

class Node():
    def __init__(self, id, children):
        self.id = id
        self.children = children
        self.parent = -1
        self.type = "internal node"
        self.right_sibling = None
        self.depth = None
        # self.left_child = children[0] if children != None else None

    def set_parent(self):
        if len(self.children) != 0:
            for child_id in self.children:
                node_list[child_id].parent = self.id
        else:
            self.type = "leaf"
        
    def set_depth(self):
        depth = 0
        node = self
        while node.parent != -1:
            node = node_list[node.parent]
            depth += 1

        if depth == 0:
            self.type = "root"
        self.depth = depth

    # def print_children(self):
    #     child = self.left_child
    #     while child != None:
    #         print(child.id)
    #         child = child.right_sibling




if __name__=="__main__":
    N = int(input())
    node_list = [None] * N
    for i in range(N):
        input_list = list(map(int, input().split()))
        id = input_list[0]
        children_num = input_list[1]
        children = input_list[2:] if children_num != 0 else []
        node_list[id] = Node(id, children)

    for n in node_list:
        n.set_parent()

    for n in node_list:
        n.set_depth()

    # from pprint import pprint
    # for n in node_list:
    #     pprint(vars(n))

    for n in node_list:
        print("node {}: parent = {}, depth = {}, {}, {}".format(n.id, n.parent, n.depth, n.type, n.children))
    




Measured memory_bytes: 42900
#include<cstdio>
#include<cstring>
#include<vector>
#include<queue>
#include<algorithm>
#include<cmath>
#include<climits>
#include<string>
#include<numeric>
#include<set>
#include<map>
#include<iostream>
using namespace std;
#define rep(i,n) for(int i = 0;i<((int)(n));i++)
#define reg(i,a,b) for(lli i = ((int)(a));i<=((int)(b));i++)
#define irep(i,n) for(int i = ((int)(n)-1);i>=0;i--)
#define ireg(i,a,b) for(int i = ((int)(b)-1);i>=((int)(a));i--)
typedef long long int lli;
typedef pair<int, int> mp;
#define fir first
#define sec second
#define IINF INT_MAX
#define LINF LLONG_MAX
#define eprintf(...) fprintf(stderr,__VA_ARGS__)
#define pque(type) priority_queue<type,vector<type>,greater<type> >
#define memst(a,b) memset(a,b,sizeof(a))
 
lli f(lli l, lli L, lli R, lli r){
	return (r-l+1)*(r-l)/2 - (r-R+1)*(r-R)/2 - (L-l+1)*(L-l)/2;
}
 
int main(void){
	lli n; cin >> n;
	vector<int> a(n), b(n+1);
	set<int> s;
	rep(i, n){
		cin >> a[i];
		b[a[i]] = i+1;
	}
	s.insert(0);
	s.insert(n+1);
	lli ans = 0;
	reg(i, 1, n){
		int t = b[i];
		s.insert(t);
		auto itr = s.find(t);
		int l = *(--itr); ++itr;
		int r = *(++itr) - 1;
		ans += f(l, t-1, t, r) * i;
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 11136
#include <bits/stdc++.h>
#define int long long
#define double long double
#define INF 1e18
using namespace std;
signed main() {
  int MAX = 100100;
  vector<int> v;
  v.push_back(1);
  for (int i = 6; i < MAX; i*=6) v.push_back(i);
  for (int i = 9; i < MAX; i*=9) v.push_back(i);
  vector<int> dp(MAX, INF);
  dp[0] = 0;
  for (int i = 0; i < MAX; i++) {
    for (int j = 0; j < v.size() && i+v[j]<MAX; j++) {
      dp[i+v[j]] = min(dp[i+v[j]], dp[i]+1);
    }
  }

  int N; cin >> N;
  cout << dp[N] << endl; 
}



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

int main(){
	string s;
	cin >> s;
	string now = s.substr(0,1);
	int ans = 1;
	int n = s.size();
	REP(i,n-1){
		if(i == n-1){
			if(s.substr(i,1) == now){
				now = s.substr(i,2);
				i++;
			}else{
				now = s.substr(i,1);
				ans++;
			}
		}else{
			if(s.substr(i,1) == now){
				now = s.substr(i,2);
				ans++;
				i++;
			}else{
				now = s.substr(i,1);
				ans++;
			}
		}
	}
	cout << ans << endl;
    return 0;
}



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

using namespace std;

#define vit vector<int>::iterator
#define pb push_back
#define ppb pop_back
#define mp make_pair
#define all(x) (x).begin(), (x).end()
#define forn(i, n) for(int i = 0; i < int(n); i++)
#define fr first
#define sc second
#define skip continue
#define PI 3.14159265

typedef unsigned long long ull;
typedef long long ll;
typedef unsigned int ui;
typedef long double ld;
typedef vector<int> vi;
typedef vector<long long> vll;
typedef vector<bool> vb;

const int INF = 1e9 + 5;
const int MAXN = 3e6 + 123;

/*void faster(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
}
bool cmp(const string& a, const string& b) {
	return (a + b) < (b + a);
}

vector<int> Reversed(const vector<int>& s){
   vector<int> d = s;
   reverse(all(d));
   return d;
}*/
//int a[27];
void solve(){
    double a, b, h;
    cin >> a >> b >> h;
    cout << 1.0/2*(a+b)*h;
}

int main(){
    //freopen("lepus.in","r",stdin);
   // freopen("lepus.out","w",stdout);
    //faster();
    int n=1;
    //cin>>n;
    while(n--){
        solve();
        //cout << endl;
    }
    //fclose(stdout);
}


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


bool is_prime(int a) {
	for (int i = 2; i * i <= a; i++) {
		if (a % i == 0)
			return false;
	}
	return true;
}

int main() {
	int n;
	cin >> n;
	int sum = 0;
	for (int i = 0; i < n; i++) {
		int m;
		cin >> m;
		if (is_prime(m))
			sum++;
	}
	cout << sum << endl;
	
}


Measured memory_bytes: 3080
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		double a = sc.nextDouble();
		double b = sc.nextDouble();
		double C = sc.nextDouble();
		
		double S = 0.5*a*b*Math.sin(Math.toRadians(C));
		double c = Math.sqrt(Math.pow(a, 2)+Math.pow(b, 2)-(2*a*b*Math.cos(Math.toRadians(C))));
		double L = a + b + c;
		double h = 2*S / a;
		
		System.out.println(S);
		System.out.println(L);
		System.out.println(h);

	}
}

Measured memory_bytes: 27856
#include <bits/stdc++.h>
 
using namespace std;
 
#define all(a) a.begin(), a.end()
#define pi acos(-1)
#define eps 1e-6
#define inf 1e14
 
typedef long long ll;
typedef vector<int> vi;
typedef pair<int, int> ii;
typedef vector<ii> vii;
typedef vector<vi> vvi;
 
const int dx[8] = {-1, -1, -1, 0, 0, 1, 1, 1};
const int dy[8] = {-1, 0, 1, -1, 1, 0, 1, -1};
const int maxn = 1e5; 
const int mod = 1e9 + 7;
const int maxa = 1e9 + 1;
 
int maxs(int &a, int b) { return a = max(a, b);}
int mins(int &a, int b) { return a = min(a, b);}
int mul(int a, int b) { return a * 1LL * b % mod;}
int add(int a, int b) { return a + b >= mod ? a + b - mod : a + b;}
int sub(int a, int b) { return a >= b ? a - b : a - b + mod;}

int n, k;
ll sum1[maxn + 1], sum2[maxn + 1];
vector<ll> A[maxn + 1], mx1, mx2;


int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    cin >> n >> k;
    for (int i = 0, t, d; i < n && cin >> t >> d; ++i)
        A[t - 1].push_back(d);
    
    for (int i = 0; i < n; ++i)
    {
        if (A[i].empty()) continue;
        
        sort(all(A[i]), greater<ll>());
        mx1.push_back(A[i][0]);
        for (int j = 1; j < A[i].size(); ++j)
            mx2.push_back(A[i][j]);

    }

    sort(all(mx1), greater<ll>());
    sort(all(mx2), greater<ll>());
    
    for (int i = 1; i <= mx1.size(); ++i)
        sum1[i] = sum1[i - 1] + mx1[i - 1];

    for (int i = 1; i <= mx2.size(); ++i)
        sum2[i] = sum2[i - 1] + mx2[i - 1];
    
    ll res = 0;
    for (int i = 1; i <= min(k, (int)mx1.size()); ++i)
        res = max(res, sum1[i] + sum2[k - i] + 1LL * i * i);

    cout << res;
}


Measured memory_bytes: 7412
/**
 * Title: B - String Palindrome
 * Url: https://atcoder.jp/contests/abc159/tasks/abc159_b
 */
#include<bits/stdc++.h>

using namespace std;

#define ll long long

bool is_kaibun(string s) {
    string rev_s = s;
    std::reverse(rev_s.begin(), rev_s.end());
    return s == rev_s;
}

bool is_palindrome(string s) {
    int len = s.length();
    for(int i=0; i<len; i++) {
        if(s[i]!=s[len-i-1]) return false;
    }
    return true;
}

int main() {

    string s; cin >> s;
    bool flag = true;
    if(!is_palindrome(s)) flag = false;
    if(!is_palindrome(s.substr(0, (s.length()-1)/2))) flag = false;
    if(!is_palindrome(s.substr((s.length()+3)/2-1))) flag = false;
    if(flag) {
        cout << "Yes" << endl;
    } else {
        cout << "No" << endl;
    }
    return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;

/**
 * Distance
 */
public class Main {

    public static void main(String[] args) {
        Scanner scan = new Scanner(System.in);

        double x1 = scan.nextDouble();
        double y1 = scan.nextDouble();
        double x2 = scan.nextDouble();
        double y2 = scan.nextDouble();

        double xx = Math.pow(x2 - x1, 2);
        double yy = Math.pow(y2 - y1, 2);
        double sum = Math.sqrt(yy + xx);
        System.out.println(String.format("%.6f", sum));
    }
}

Measured memory_bytes: 19024
#include<bits/stdc++.h>
using namespace std;
#define int long long 
#define ii pair <int, int>
#define app push_back
#define all(a) a.begin(), a.end()
#define bp __builtin_popcount
#define ll long long
#define mp make_pair
#define f first
#define s second
#define lb lower_bound
#define ub upper_bound
#define Time (double)clock()/CLOCKS_PER_SEC
const int N = 1e5 + 7, INF = 1e18 + 7;
int n, T, E, a[N], dp[N], pref[N];
signed main() {
    #ifdef HOME
    freopen("input.txt", "r", stdin);
    #else
    ios_base::sync_with_stdio(0); cin.tie(0);
    #endif
    cin >> n >> E >> T;
    for (int i = 1; i <= n; ++i) cin >> a[i];
    pref[0] = INF;
    for (int i = 1; i <= n; ++i) {
        //2 * a[i] - 2 * a[j] <= T
        //2 * a[j] >= 2 * a[i] - T
        //a[j] >= (2 * a[i] - T + 1) / 2
        int l = lb(a + 1, a + n + 1, (2 * a[i] - T + 1) >> 1) - a;
        dp[i] = min(dp[l - 1] + T, 2 * a[i] + pref[l - 1]);
        pref[i] = min(pref[i - 1], dp[i - 1] - 2 * a[i]);
    }   
    cout << dp[n] + E << '\n';
}

Measured memory_bytes: 2560
#include <iostream>
#include <vector>
#include <array>
#include <list>
#include <queue>
#include <set>
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <string>
#include <sstream>
#include <algorithm>
#include <random>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <cmath>
#include <cassert>
#include <climits>
#include <bitset>
#include <functional>
#include <iomanip>

#define FOR_LT(i, beg, end) for (int i = beg; i < end; i++)
#define FOR_LE(i, beg, end) for (int i = beg; i <= end; i++)
#define FOR_DW(i, beg, end) for (int i = beg; end <= i; i--)

using namespace std;

int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout << fixed << setprecision(20);

	int n; cin >> n;
	cout << n * n << endl;

	return 0;
}

Measured memory_bytes: 256
import sys
h,w=map(int,input().split())
if h==1 or w==1:
    print(1)
    sys.exit()
if h%2==0 and w%2==0:
    print(int(h*w/2))
elif h%2==1 and w%2==1:
    print(int(h*w/2)+1)
else:
    print(int(h*w/2))

Measured memory_bytes: 3060
/**
 *    author:  otera    
**/
#include<iostream>
#include<string> 
#include<cstdio>
#include<cstring>
#include<vector>
#include<cmath>
#include<algorithm> 
#include<functional>
#include<iomanip>
#include<queue>
#include<deque>
#include<ciso646>
#include<random>
#include<map>
#include<set>
#include<complex>
#include<bitset>
#include<stack>
#include<unordered_map>
#include<utility>
#include<cassert>
using namespace std;

#define int long long
typedef long long ll;
typedef unsigned long long ul;
typedef unsigned int ui;
typedef long double ld;
const int inf=1e9+7;
const ll INF=1LL<<60 ;
const ll mod=1e9+7 ;
#define rep(i,n) for(int i=0;i<n;i++)
#define per(i,n) for(int i=n-1;i>=0;i--)
#define Rep(i,sta,n) for(int i=sta;i<n;i++)
#define rep1(i,n) for(int i=1;i<=n;i++)
#define per1(i,n) for(int i=n;i>=1;i--)
#define Rep1(i,sta,n) for(int i=sta;i<=n;i++)
typedef complex<ld> Point;
const ld eps = 1e-8;
const ld pi = acos(-1.0);
typedef pair<int, int> P;
typedef pair<ld, ld> LDP;
typedef pair<ll, ll> LP;
#define fr first
#define sc second
#define all(c) c.begin(),c.end()
#define pb push_back
#define debug(x)  cerr << #x << " = " << (x) << endl;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

int n, q; 
vector<int> a;
vector<int> sum;
vector<int> oddsum, evensum;

bool check(int t, int x) {
    if(abs(a[n - t] - x) <= abs(a[n - (t + 1) / 2] - x)) return true;
    return false;
}

void solve() {
	cin >> n >> q;
    a.resize(n);
    sum.assign(n + 1, 0);
    evensum.assign(n + 1, 0);
    oddsum.assign(n + 1, 0);
    vector<int> x(q);
    rep(i, n) {
        cin >> a[i];
        sum[i + 1] = sum[i] + a[i];
        oddsum[i + 1] = oddsum[i], evensum[i + 1] = evensum[i];
        if(i & 1) oddsum[i + 1] += a[i];
        else evensum[i + 1] += a[i];
    }
    rep(i, q) {
        cin >> x[i];
    }
    rep(i, q) {
        int ok = 0, ng = n + 1;
        while(ng - ok > 1) {
            int mid = (ok + ng) / 2;
            if(check(mid, x[i])) ok = mid;
            else ng = mid;
        }
        //cerr << ok << endl;
        int ans = sum[n] - sum[n - (ok + 1) / 2];
        int pos = n - ok;
        if(n % 2 == 1) {
            ans += evensum[pos];
        } else {
            ans += oddsum[pos];
        }
        cout << ans << endl;
    }
}

signed main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	//cout << fixed << setprecision(10);
	//int t; cin >> t; rep(i, t)solve();
	solve();
    return 0;
}

Measured memory_bytes: 5632
def solve():
    n = int(input())
    s = [int(input()) for _ in range(n)]
    s = sorted(s)

    if sum(s)%10 != 0:
        print(sum(s))
        return
    else:
        for ss in s:
            if ss%10 != 0:
                print(sum(s)-ss)
                return
        print(0)

solve()


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

    int a[150]={0},b,c,l;
    cin>>b>>c;
    for(int i=1;i<=c;i++)
  {
      cin>>l;
      a[l]=1;
    }
    int ans1=-1,ans2=-1;
   for(int i=b;i>=0;i--)
   if(a[i]==0){
    ans1=i;
    break;
   }
   for(int i=b;i<=149;i++)
    if(a[i]==0)
   {
       ans2=i;
       break;
   }
   if(ans1!=-1)
   {
       if((b-ans1)<=ans2-b) cout<<ans1;
       else cout<<ans2;
   }
   else
    cout<<ans2;
    return 0;
    }

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

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

int main()
{
    using vi = vector<int>;
    using vvi = vector<vi>;
    using vvvi = vector<vvi>;
    using ll = long long;

    int N;
    cin >> N;
    vi L(N);
    rep(i, N) cin >> L[i];

    int ans = 0;

    // まずソートをする(ソートしても計算量に問題なく，二分探索に必要なため)
    sort(L.begin(), L.end());

    // a < b < c と順序関係を定めても一般性を失わないため，そのように順序関係を定めることで，探索が楽になる
    for(int i = 0; i < N; i++)
    {
        int a = L[i];
        for(int j = i + 1; j < N; j++)
        {
            int b = L[j];

            // 三角不等式より， b - a < c < a + b, ただし a < b
            int left = b - a;
            int right = a + b;

            auto left_iter = upper_bound(L.begin(), L.end(), left); // left < c となるLの要素のうち最小のイテレータ
            auto right_iter = lower_bound(L.begin(), L.end(), right); // right <= c となるLの要素のうち最小のイテレータ
            int left_idx = left_iter - L.begin(); // 配列のインデックスにする
            int right_idx = right_iter - L.begin(); // 配列のインデックスにする
            if(left_idx <= j) // 選ぶcの候補がb以下のものを含む場合
                left_idx = j + 1; // bより大きいもの限定にする
            int candidate_c = right_idx - left_idx; // 棒cの候補数(sortされているからこの間を選べば条件を満たすようになっている)
            if(candidate_c < 0 || candidate_c > N - 2)
                continue;
            else
                ans += candidate_c;
        }
    }

    cout << ans << endl;
}

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

#define ALL(obj) (obj).begin(),(obj).end()
#define SPEED cin.tie(0);ios::sync_with_stdio(false);

template<class T> using PQ = priority_queue<T>;
template<class T> using PQR = priority_queue<T,vector<T>,greater<T>>;

constexpr long long MOD = (long long)1e9 + 7;
constexpr long long MOD2 = 998244353;
constexpr long long HIGHINF = (long long)1e18;
constexpr long long LOWINF = (long long)1e15;
constexpr long double PI = 3.1415926535897932384626433L;

template <class T> vector<T> multivector(size_t N,T init){return vector<T>(N,init);}
template <class... T> auto multivector(size_t N,T... t){return vector<decltype(multivector(t...))>(N,multivector(t...));}
template <class T> void corner(bool flg, T hoge) {if (flg) {cout << hoge << endl; exit(0);}}
template <class T, class U>ostream &operator<<(ostream &o, const map<T, U>&obj) {o << "{"; for (auto &x : obj) o << " {" << x.first << " : " << x.second << "}" << ","; o << " }"; return o;}
template <class T>ostream &operator<<(ostream &o, const set<T>&obj) {o << "{"; for (auto itr = obj.begin(); itr != obj.end(); ++itr) o << (itr != obj.begin() ? ", " : "") << *itr; o << "}"; return o;}
template <class T>ostream &operator<<(ostream &o, const multiset<T>&obj) {o << "{"; for (auto itr = obj.begin(); itr != obj.end(); ++itr) o << (itr != obj.begin() ? ", " : "") << *itr; o << "}"; return o;}
template <class T>ostream &operator<<(ostream &o, const vector<T>&obj) {o << "{"; for (int i = 0; i < (int)obj.size(); ++i)o << (i > 0 ? ", " : "") << obj[i]; o << "}"; return o;}
template <class T, class U>ostream &operator<<(ostream &o, const pair<T, U>&obj) {o << "{" << obj.first << ", " << obj.second << "}"; return o;}
template <template <class tmp>  class T, class U> ostream &operator<<(ostream &o, const T<U> &obj) {o << "{"; for (auto itr = obj.begin(); itr != obj.end(); ++itr)o << (itr != obj.begin() ? ", " : "") << *itr; o << "}"; return o;}
void print(void) {cout << endl;}
template <class Head> void print(Head&& head) {cout << head;print();}
template <class Head, class... Tail> void print(Head&& head, Tail&&... tail) {cout << head << " ";print(forward<Tail>(tail)...);}
template <class T> void chmax(T& a, const T b){a=max(a,b);}
template <class T> void chmin(T& a, const T b){a=min(a,b);}
void YN(bool flg) {cout << (flg ? "YES" : "NO") << endl;}
void Yn(bool flg) {cout << (flg ? "Yes" : "No") << endl;}
void yn(bool flg) {cout << (flg ? "yes" : "no") << endl;}

int main() {
    string S; cin >> S;
    int N = S.size();
    string T = S.substr(0,N/2);
    string U = S.substr(N/2+1,N/2);
    for(int i = 0; i < N; ++i){
        if(i > N-1 - i) continue;
        corner(S[i]!=S[N-1-i],"No");
    }
    int M = N/2;
    for(int i = 0; i < M; ++i){
        if(i > M-1 - i) continue;
        corner(T[i]!=T[M-1-i],"No");
    }
    for(int i = 0; i < M; ++i){
        if(i > M-1 - i) continue;
        corner(U[i]!=U[M-1-i],"No");
    }
    cout << "Yes" << endl;


    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(ll i=0;i<n;i++)
#define repl(i,l,r) for(ll i=(l);i<(r);i++)
#define per(i,n) for(ll i=n-1;i>=0;i--)
#define perl(i,r,l) for(ll i=r-1;i>=l;i--)
#define fi first
#define se second
#define pb push_back
#define ins insert
#define pqueue(x) priority_queue<x,vector<x>,greater<x>>
#define all(x) (x).begin(),(x).end()
#define CST(x) cout<<fixed<<setprecision(x)
#define rev(x) reverse(x);
using ll=long long;
using vl=vector<ll>;
using vvl=vector<vector<ll>>;
using pl=pair<ll,ll>;
using vpl=vector<pl>;
using vvpl=vector<vpl>;
const ll MOD=1000000007;
const ll MOD9=998244353;
const int inf=1e9+10;
const ll INF=4e18;
const ll dy[9]={1,0,-1,0,1,1,-1,-1,0};
const ll dx[9]={0,-1,0,1,1,-1,1,-1,0};
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;
}
ll memo[410][410];
vl v(410);
ll dfs(ll l,ll r){
    if(l==r)return 0;
    if(memo[l][r])return memo[l][r];
    ll ret=INF;ll z=0;repl(i,l,r+1)z+=v[i];
    repl(i,l,r){
        chmin(ret,dfs(l,i)+dfs(i+1,r)+z);
    }
    memo[l][r]=ret;
    return ret;
}
int main(){
    ll n;cin >> n;
    rep(i,n){
        ll a;cin >> a;v[i]=a;
    }
    cout << dfs(0,n-1) << endl;
}

Measured memory_bytes: 4868
#include<iostream>
using namespace std;
int main(void){
  long long int n,m;cin>>n>>m;
  if(n==1 && m==1){cout<<"1";}
  else if(n==1){cout<<m-2;}
  else if(m==1){cout<<n-2;}
  else{cout<<(m-2)*(n-2);}
  return 0;
}

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

two_loops = As + [A+K for A in As]

max_dist = 0
max_dist_index = 0
for i in range(len(two_loops)-1):
    new_dist = two_loops[i+1]-two_loops[i]
    if new_dist > max_dist:
        max_dist = new_dist
        max_dist_index = i+1
print(two_loops[max_dist_index+N-1]-two_loops[max_dist_index])

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

typedef long long ll;
const ll MOD = 1e9+7;

int a;
string s;

int main()
{
    ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
    cin>>a>>s;
    if(a>=3200)cout<<s;
    else cout<<"red";



    return 0;
}


Measured memory_bytes: 256
e[6],n,r,i,a;
char s[6];
main(){
	for(;scanf("%d",&n),n;){
		int d[6]={1,2,3,5,4,6};
		a=1;
		for(;n--;){
			scanf("%s",s);
			r=*s%8-2;
			for(i=0;i<6;i++){
				//      R     S     L     E     N     W     
				e[i]=d["134526413652152346521463263154326415"[r*6+i]-'1'];
			}
			memcpy(d,e,sizeof(d));
			a+=*d;
		}
		printf("%d\n",a);
	}
	exit(0);
}

Measured memory_bytes: 0
import java.util.*;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int N = Integer.parseInt(sc.next());
        String S = sc.next();
        char before = S.charAt(0);
        int minus = 0;
        for (int i=1;i<N;i++) {
            if (S.charAt(i)==before) {
                minus++;
            }
            before = S.charAt(i);
        }
        System.out.println(N-minus);
    }
}

Measured memory_bytes: 24012
h,w,d = map(int,input().split())

dic = {}
for i in range(h):
  line = list(map(int,input().split()))
  for j in range(w):    
    dic[line[j]-1]=(i,j)              

A = [0]*(h*w)

for i in range(h*w-d):
    x,y = dic[i]
    nx,ny = dic[i+d]      
    A[i+d] = A[i] + abs(nx-x) + abs(ny-y)
  
q = int(input())  
for i in range(q):
  l,r = map(int,input().split())
  print(A[r-1] - A[l-1])  

Measured memory_bytes: 22608
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <queue>
#include <cmath>
#include <iostream>
#include <algorithm>
using namespace std;
int main (void)
{
	int x,y;
	cin>>x>>y;
	bool flag = false;
	if(x%y==0)
		flag = true;
	if(flag)
		cout<<"-1"<<endl;
	else
		cout<<x<<endl;
	return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<cmath>
#include<iomanip>
#include<set>
#include<map>
#include<queue>
#include<vector>
using namespace std;
typedef long long ll;
const int MOD=1e9+7;
const double pi=acos(-1);
int main() {
  cin.tie(0),cout.tie(0);
  ios::sync_with_stdio(false);
  ll n,q,a[100005]={},x[505]={};
  cin >> n >> q;
  for(int i=0; i<n; i++) {
    cin >> a[i];
  }
  for(int i=0; i<q; i++) {
    cin >> x[i];
  }
  for(int i=0; i<q; i++) {
    ll ans=0,r=0,cnt=0;
    for(int l=0; l<n; l++) {
      while(r<n&&cnt+a[r]<=x[i]) {
        cnt+=a[r];
        r++;
      }
      ans+=r-l;
      if(r==l) {
        r++;
      }
      else {
        cnt-=a[l];
      }
    }
    cout << ans << endl;
  }
}


Measured memory_bytes: 4000
import java.util.*;
import java.io.*;

public class Main {
	private static void solve(){
		//Implement solution here.
		int n = ni();
		int k = ni();
		Map<Integer,Queue<Integer>> map = new HashMap<>();
		Queue<Integer> nq = new PriorityQueue<>(Collections.reverseOrder());
		Queue<Integer> eq = new PriorityQueue<>(Collections.reverseOrder());
		for(int i = 0; i < n; i++) {
			int t = ni();
			int d = ni();
			if(!map.containsKey(t)) {
				map.put(t, new PriorityQueue<Integer>(Collections.reverseOrder()));
			} 
			map.get(t).add(d);
		}
		
		for(int key:map.keySet()) {
			nq.add(map.get(key).poll());
			while(!map.get(key).isEmpty()) {
				eq.add(map.get(key).poll());
			}
		}

		long dsum = 0;
		long var = 0;
		Queue<Integer> rq = new PriorityQueue<>();
		while(rq.size() < k && !nq.isEmpty()) {
			int dd = nq.poll();			
			rq.add(dd);
			dsum += dd;
			var++;
		}		
		long result = dsum + var * var;
		
		for(int i = 0; i < k; i++) {
			if(eq.isEmpty())break;
			int dd = eq.poll();
			dsum += dd;
			if(rq.size() >= k) {				
				dsum -= rq.poll();			
				var--;
			}
			rq.add(dd);
			result = Math.max(result, dsum + var * var);
		}
		
		System.out.println(result);
	}

	//Switch input source (stdin/file)
	private static BufferedReader br  = new BufferedReader(new InputStreamReader(System.in));
	public static void main(String[] args){
		String debugDataPath = System.getenv("DD_PATH");        
		if(debugDataPath != null){
			try{
				br = new BufferedReader(new InputStreamReader(new FileInputStream(new File(debugDataPath))));
			}catch(Exception e){
				throw new RuntimeException(e);
			}
		}
		solve();
	}

	//Input read utility
	private static StringTokenizer tokenizer = null;
	public static String next() {
		while (tokenizer == null || !tokenizer.hasMoreTokens()) {
			try {
				tokenizer = new StringTokenizer(br.readLine());
			} catch (Exception e) {
				throw new RuntimeException(e);
			}
		}
		return tokenizer.nextToken();
	}
	//Get next single int
	private static int ni() {
		return Integer.parseInt(next());
	}
	//Get next single long
	private static long nl() {
		return Long.parseLong(next());
	}
	//Get next single double
	private static double nd() {
		return Double.parseDouble(next());
	}
	//Get next int array from one line
	private static int[] na(int n) {
		int[] a = new int[n];
		for (int i = 0; i < n; i++)
			a[i] = ni();
		return a;
	}
	//Get next char array from one line
	private static char[] ns() {
		return next().toCharArray();
	}
	//Get next long array from one line
	private static long[] nal(int n) {
		long[] a = new long[n];
		for (int i = 0; i < n; i++)
			a[i] = nl();
		return a;
	}
}


Measured memory_bytes: 58716
#include <iostream>
#include <algorithm>
#include <vector>
using namespace std;
typedef pair<int,int>P;
#define X first
#define Y second
#define pb push_back
vector<P>V[10001];

void V_set(){
	for(int i=1;i<=10000;i++){
		for(int j=1;j*j<=i;j++){
			if(i%j==0){
				V[i].pb(P(j,i/j));
			}
		}
	}
}

int cal(P a,P b){
	int d[4]={a.X,a.Y,b.X,b.Y};
	sort(d,d+4);
	int t=0;
	for(int i=0;i<3;i++){
		t+=(d[i+1]-d[i])*(d[i+1]-d[i]);
	}
	return t;
}

int main(){
	
	V_set();
	
	int a,b;
	while(cin>>a>>b,a){
		int ans=999999999;
		for(int i=0;i<V[a].size();i++){
			for(int j=0;j<V[b].size();j++){
				ans=min(ans,cal(V[a][i],V[b][j]));
			}
		}
		cout<<ans<<endl;
	}
	
	
	return 0;
}


Measured memory_bytes: 2052
import math

nums = [int(e) for e in input().split()]
n = nums[0]
m = nums[1]

x = -1
y = -1

ms = []

if n%2 == 0:
    x = 1
    y = n
    count = True

    while x < y:
        if y-x <= n/2 and count:
            y -= 1
            count = False
        ms += [[x,y]]
        x += 1
        y -= 1


else:
    x = 1
    y = n
    while x < y:
        ms += [[x, y]]
        x += 1
        y -= 1


# print(ms)

for i in range(m):
    print(str(ms[i][0]) + " " + str(ms[i][1]))


Measured memory_bytes: 22396
#include <algorithm>
#include <iostream>
#include <math.h>
#include <stdio.h>
#include <string>
#include <sstream>
#include <vector>
#include <set>
#include <stack>
#include <map>
#include <cmath>
#include <queue>
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
using namespace std;
typedef unsigned long long ll;

int main()
{
	int n,q;
	cin>>n>>q;
	ll *numList = new ll[n];
	ll *cumSum = new ll[n];
	rep(i,n){
		numList[i] = 0;
		cumSum[i] = 0;
	}
	vector<int> *adjList = new vector<int> [n];
	rep(i,n-1){
		int a,b;
		cin>>a>>b;
		a--;
		b--;
		adjList[a].push_back(b);
		adjList[b].push_back(a);
	}

	stack<int> st;
	rep(i,q){
		int p;
		ll x;
		cin>>p>>x;
		p--;
		numList[p]+=x;
	}
	st.push(0);
	cumSum[0] = numList[0];
	vector<bool> visit(n);
	while(st.empty() != true){
		int currentNode = st.top();
		visit[currentNode] = true;
		st.pop();
		for(auto iter = adjList[currentNode].begin(); iter != adjList[currentNode].end(); iter++){
			if( visit[*iter] == true){
				continue;
			}
			cumSum[*iter] = cumSum[currentNode] + numList[*iter];
			st.push(*iter);
		}
	}
	rep(i,n)cout<<cumSum[i]<<" ";
	cout<<endl;
	return 0;
}



Measured memory_bytes: 17908
#include "bits/stdc++.h"
#include "ext/pb_ds/assoc_container.hpp"
#include "ext/pb_ds/tree_policy.hpp"
#include "ext/rope"
using namespace std;
using namespace chrono;
using namespace __gnu_pbds;
using namespace __gnu_cxx;
mt19937 rng(high_resolution_clock::now().time_since_epoch().count());
mt19937_64 rngll(high_resolution_clock::now().time_since_epoch().count());
#define lambdify(x) [&](auto &&...args){ return x(forward<decltype(args)>(args)...); }
template<typename T, typename U> T &ctmax(T &x, const U &y){ return x = max<T>(x, y); }
template<typename T, typename U> T &ctmin(T &x, const U &y){ return x = min<T>(x, y); }
template<typename T> using Tree = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;



int main(){
	cin.tie(0)->sync_with_stdio(0);
	int n;
	cin >> n;
	vector<array<int, 2>> a(n + 1);
	for(auto i = 1; i <= n; ++ i){
		for(auto j = 0; j < 2; ++ j){
			cin >> a[i][j];
		}
	}
	const int h = 9, mx = 1e5;
	vector<vector<long long>> dp(1 << h, vector<long long>(mx + 1));
	for(auto u = 1; u < min(1 << h, n + 1); ++ u){
		int p = u >> 1;
		dp[u] = dp[p];
		for(auto x = a[u][1]; x <= mx; ++ x){
			ctmax(dp[u][x], max(dp[u][x - 1], dp[p][x - a[u][1]] + a[u][0]));
		}
	}
	int qq;
	cin >> qq;
	while(qq --){
		int u, x;
		cin >> u >> x;
		if(__lg(u) < h){
			cout << dp[u][x] << "\n";
		}
		else{
			int d = __lg(u) - h + 1;
			long long res = dp[u >> d][x], sv = 0, sw = 0;
			for(auto mask = 1; mask < 1 << d; ++ mask){
				for(auto bit = 0; bit < d; ++ bit){
					if(mask & 1 << bit){
						sv += a[u >> bit][0];
						sw += a[u >> bit][1];
						break;
					}
					else{
						sv -= a[u >> bit][0];
						sw -= a[u >> bit][1];
					}
				}
				if(sw <= x) ctmax(res, dp[u >> d][x - sw] + sv);
			}
			cout << res << "\n";
		}
	}
	return 0;
}

/*

*/

////////////////////////////////////////////////////////////////////////////////////////
//                                                                                    //
//                                   Coded by Aeren                                   //
//                                                                                    //
////////////////////////////////////////////////////////////////////////////////////////

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

#define CPP_STR(x) CPP_STR_I(x)
#define CPP_CAT(x,y) CPP_CAT_I(x,y)
#define CPP_STR_I(args...) #args
#define CPP_CAT_I(x,y) x ## y

using i8  = int8_t;
using u8  = uint8_t;
using i16 = int16_t;
using u16 = uint16_t;
using i32 = int32_t;
using u32 = uint32_t;
using i64 = int64_t;
using u64 = uint64_t;

using f32 = float;
using f64 = double;

#define FOR(i, start, end) for(i64 i = (start), CPP_CAT(i,xxxx_end)=(end); i < CPP_CAT(i,xxxx_end); ++i)
#define REP(i, n) FOR(i, 0, n)
#define REPS(i, n) for(i64 i = 1; i <= n; ++i)
#define RREP(i, n) for(i64 i = n - 1; i >= 0 ; --i)
#define RREPS(i, n) for(i64 i = n; i >= 1; --i)

#define ALL(f,c,...) (([&](decltype((c)) cccc) { return (f)(std::begin(cccc), std::end(cccc), ## __VA_ARGS__); })(c))

#define UNIQUE(v) v.erase( unique(v.begin(), v.end()), v.end() );

#define pb push_back
#define mp make_pair

template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }

template<typename C>
i64 SIZE(const C& c) { return static_cast<i64>(c.size()); }

template<typename T, size_t N>
i64 SIZE(const T (&)[N]) { return static_cast<i64>(N); }


struct ProconInit {
    static constexpr int IOS_PREC = 15;
    static constexpr bool AUTOFLUSH = false;

    ProconInit() {
        cin.tie(nullptr);
        ios::sync_with_stdio(false);
        cout << fixed << setprecision(IOS_PREC);
        if(AUTOFLUSH)
            cout << unitbuf;
    }
} PROCON_INIT;


int main() {
    i64 L, R, d; cin >> L >> R >> d;

    i64 cr = R / d;
    i64 cl = (L - 1) / d;
    cout << (cr - cl) << endl;

    return 0;
}


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

namespace AtCoder
{
    class Program
    {
        static void Main(string[] args)
        {
            //[summary]A - ringring
            var prices = ReadLine();

            Console.WriteLine(prices.Sum() - prices.Max());
        }

        static List<int> ReadLine()
        {
            var line = Console.ReadLine();
            var array = line.Split(' ');

            return array.Select(x => int.Parse(x)).ToList();
        }
    }
}

Measured memory_bytes: 11348
N = int(input())
P = list(map(int, input().split()))
 
left_bigger  = [0] + [i for i in range(N+1)]
right_bigger = [i+1 for i in range(N+1)] + [N+1]
 
E = [(v, i+1) for i, v in enumerate(P)]
E.sort()

ans = 0
for v,i in E:
    l0=left_bigger[i]
    l1=left_bigger[l0]
    r0=right_bigger[i]
    r1=right_bigger[r0]
    
    ans += ((r1-r0)*(i-l0) + (r0-i)*(l0-l1))*v
    left_bigger[r0]=l0
    right_bigger[l0]=r0
print(ans)

Measured memory_bytes: 25596
#include <iostream>
#include <fstream>
#include <set>
#include <map>
#include <string>
#include <vector>
#include <bitset>
#include <algorithm>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <cassert>
#include <queue>

#define mp make_pair
#define pb push_back


typedef long long ll;
typedef long double ld;

using namespace std;
const int MX = 210;
const ll MOD = 1e9 + 7;

int n, m;
char s[MX][MX];
int en[MX][MX];

int cc0[MX];
int cc1[MX];
int main() {
	cin >> n >> m;
	for (int i = 0; i < n; ++i)
		cin >> s[i];
	ll ans = 1;
	int fl1 = 0;
	int fl2 = 0;
	for (int i = 0; i * 2 < n; ++i)
		for (int j = 0; j * 2 < m; ++j) {
			if (i * 2 == n - 1 && j * 2 == m - 1)
				continue;
			if (i * 2 == n - 1) {
				if (s[i][j] != s[i][m - 1 - j])
					fl1 = 1;
			}
			else if (j * 2 == m - 1) {
				if (s[i][j] != s[n - 1 - i][j])
					fl2 = 1;
			}
			else {
				vector<char> vv;
				vv.push_back(s[i][j]);
				vv.push_back(s[n - 1 - i][j]);
				vv.push_back(s[n - 1 - i][m - 1 - j]);
				vv.push_back(s[i][m - 1 - j]);
				sort(vv.begin(), vv.end());
				if (vv[0] == vv[3]) {
					en[i][j] = 1;
				}
				else if (vv[0] == vv[2] || vv[1] == vv[3]) {
					en[i][j] = 1;
					ans = (ans * 4) % MOD;
				}
				else if (vv[0] == vv[1] && vv[2] == vv[3]) {
					en[i][j] = 1;
					ans = (ans * 6) % MOD;
				}
				else if (vv[0] == vv[1] || vv[1] == vv[2] || vv[2] == vv[3]) {
					en[i][j] = 1;
					ans = (ans * 12) % MOD;
				}
				else {
					ans = (ans * 12) % MOD;
				}
			}
		}
	if (fl1)
		ans = (ans * 2) % MOD;
	if (fl2)
		ans = (ans * 2) % MOD;
	n = n / 2;
	m = m / 2;
	int fl = 1;
	while (fl) {
		fl = 0;
		for (int i = 0; i < n; ++i)
			cc0[i] = 0;
		for (int i = 0; i < m; ++i)
			cc1[i] = 0;
		for (int i = 0; i < n; ++i)
			for (int j = 0; j < m; ++j)
				if (!en[i][j])
					++cc0[i], ++cc1[j];
		for (int i = 0; i < n; ++i) {
			if (cc0[i] >= 2)
				continue;
			if (cc0[i] == 1)
				ans = (ans * 2) % MOD;
			fl = 1;
			for (int j = i + 1; j < n; ++j)
				for (int k = 0; k < m; ++k)
					en[j - 1][k] = en[j][k];
			--n;
			break;
		}
		if (fl)
			continue;
		for (int i = 0; i < m; ++i) {
			if (cc1[i] >= 2)
				continue;
			if (cc1[i] == 1)
				ans = (ans * 2) % MOD;
			fl = 1;
			for (int j = i + 1; j < m; ++j)
				for (int k = 0; k < n; ++k)
					en[k][j - 1] = en[k][j];
			--m;
			break;
		}
		if (fl)
			continue;
	}
	if (n > 0 && m > 0) {
		int cc = (n + m - 1);
		for (int j = 0; j < cc; ++j)
			ans = (ans * 2) % MOD;
	}
	cout << ans << "\n";
	return 0;
}




Measured memory_bytes: 384
#include <iostream>
#include <string>
#include <vector>
#include <cmath>
#include <deque>
#include <queue>//for queue and priority_queue
#include <fstream>
#include <iomanip>
#include <stack>
#include <algorithm>
#include <set>
#include <map>
#include <list>
#define endl "\n"
typedef long long ll;
using namespace std;
void Lancer() { ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); }
bool isPrime(ll n){
	if (n == 2 || n == 3 || n == 5)
		return true;
	else if (n % 2 == 0 || n % 3 == 0 || n % 5 == 0 || n == 1)
		return false;
	else {
		for (int i = 5; i <= sqrt(n); i += 2){
			if (n%i == 0)
				return false;
		}
		return true;
	}
}

char arr[57][57];
int main(){
	Lancer();
	ll n, a, b, t;
	cin >> n;
	a = 2, b = 1;
	while (n>0)
	{
		t = b;
		b += a;
		a = t;
		n--;
	}
	if (n == 0)cout << a;
	else cout << b;
	cout << endl;
	return 0;
}


Measured memory_bytes: 3700
#include<bits/stdc++.h>
#pragma GCC optimize("Ofast")
using namespace std;
#define bye return 0
#define Yes cout << "Yes" << "\n"
#define No  cout << "No" << "\n"
#define YES cout << "YES" << "\n"
#define NO cout << "NO" << "\n"
#define endl cout << "\n"
typedef long long ll;
int main(){
    ios::sync_with_stdio(false);
    cin.tie(NULL);
    int t, a, b, k, flag = 0;
    vector<int> xn;
    vector<int> yn;
    cin >> k;
    cin >> a >> b;

    for(int i=a; i<=b; ++i){
    	if(i%k==0){ 
    		flag=1;
    		break;
    	}
    }

    if(flag==1) cout << "OK" << "\n";
    else cout << "NG" << "\n";
    

    
   bye;

}



Measured memory_bytes: 3648