akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <string>
#include <iomanip>
#include <algorithm>
#include <cmath>
#include <stdio.h>
using namespace std;
#define int long long
int MOD = 1000000007;
signed main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	string S;
	cin >> S;
	int N = S.size();
	if (S.back() == '1') {
		cout << -1 << endl;
		return 0;
	}
	S.pop_back();
	string T = S;
	reverse(T.begin(), T.end());
	if (S != T) {
		cout << -1 << endl;
		return 0;
	}
	if (S[0] == '0') {
		cout << -1 << endl;
		return 0;
	}
	int cur = 0;
	vector<pair<int, int> >vp;
	for (int i = 0; i < (N - 1) / 2; i++) {
		vp.emplace_back(cur, i + 1);
		if (S[i] == '1') {
			cur = i + 1;
		}
	}
	if (N % 2 == 1) {
		int sz = vp.size();
		for (int i = 0; i < sz; i++) {
			vp.emplace_back(vp[i].first + N, vp[i].second + N);
		}
		for (int i = 0; i < vp.size(); i++) {
			if (vp[i].first == cur + N) {
				vp[i].first = cur;
			}
			if (vp[i].second == cur + N) {
				vp[i].second = cur;
			}
		}
	}
	else {
		if (S[(N - 1) / 2] == '1') {
			int sz = vp.size();
			for (int i = 0; i < sz; i++) {
				vp.emplace_back(vp[i].first + N, vp[i].second + N);
			}
			vp.emplace_back(cur, cur + N);
		}
		else {
			int sz = vp.size();
			for (int i = 0; i < sz; i++) {
				vp.emplace_back(vp[i].first + N, vp[i].second + N);
			}
			for (int i = 0; i < vp.size(); i++) {
				if (vp[i].first == cur + N) {
					vp[i].first = cur;
				}
				if (vp[i].second == cur + N) {
					vp[i].second = cur;
				}
			}
			vp.emplace_back(cur, 10000000);
		}
	}
	set<int> st;
	for (int i = 0; i < vp.size(); i++) {
		st.insert(vp[i].first);
		st.insert(vp[i].second);
	}
	int k = 0;
	map<int, int> mp;
	for (auto s : st) {
		mp[s] = k;
		k++;
	}
	for (int i = 0; i < vp.size(); i++) {
		vp[i].first = mp[vp[i].first];
		vp[i].second = mp[vp[i].second];
	}
	for (int i = 0; i < vp.size(); i++) {
		cout << vp[i].first + 1 << " " << vp[i].second + 1 << endl;
	}
}

Measured memory_bytes: 14144
#include <stdlib.h>
#include <stdio.h>
#include <iostream>
using namespace std;
int main(){
	int a,b;
	cin>>a>>b;
	if(a+b==15){
		printf("+");
	}else if(a*b==15){
		printf("*");
	}else{
		printf("x");
	}
	return 0;
} 

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll,ll> P;
ll n;
ll a[105];
ll MAX,MIN;
int main(void){
    cin>>n;
    cin>>a[0];
    MAX=a[0];
    MIN=a[0];
    for(int i=1;i<n;i++){
        cin>>a[i];
        MAX=max(MAX,a[i]);
        MIN=min(MIN,a[i]);
    }
    cout<<MAX-MIN<<endl;

}



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

int main()
{
    int n;cin>>n;
    vector<int> a(n);
    double sum = 0;
    for(int i = 0; i<n; i++) {
        cin>>a[i];
        sum += a[i];
    }
    double ans = 110;
    int j;
    sum /= (double)n;

    for(int i = 0; i<n; i++) {
        if(ans > abs(sum - (double)a[i])){ ans = abs(sum - (double)a[i]);
        j = i;}
    }    
        cout << j << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int n;
long long s[200020], z = 1e18;
int main() {
	scanf("%d", &n);
	for (int i = 1; i <= n; i++) {
		scanf("%d", &s[i]);
		s[i] += s[i - 1];
	}
	for (int l = 0, r = 1, i = 1; i <= n; i++) {
		while (l < i && abs(s[i] - 2 * s[l]) > abs(s[i] - 2 * s[l + 1])) {
			l++;
		}
		while (r < n && abs(s[n] + s[i] - 2 * s[r]) > abs(s[n] + s[i] - 2 * s[r + 1])) {
			r++;
		}
		long long a[] = {s[l], s[i] - s[l], s[r] - s[i], s[n] - s[r]};
		sort(a, a + 4);
		z = min(z, a[3] - a[0]);
	}
	printf("%lld\n", z);
	return 0;
}

Measured memory_bytes: 1792
#include"bits/stdc++.h"
using namespace std;
#define FOR(i,k,n) for(int i = (int)(k); i < (int)(n); i++)
#define REP(i,n) FOR(i,0,n)
#define ALL(a) a.begin(), a.end()
#define MS(m,v) memset(m,v,sizeof(m))
#define D10 fixed<<setprecision(10)
typedef long long ll;
typedef long double ld;
typedef vector<int> vi;
typedef vector<string> vs;
typedef pair<int, int> pii;
const int MOD = 1000000007;
const int INF = MOD + 1;
const ld EPS = 1e-12;
template<class T> T &chmin(T &a, const T &b) { return a = min(a, b); }
template<class T> T &chmax(T &a, const T &b) { return a = max(a, b); }

/*--------------------template--------------------*/

int main()
{
	int n;
	cin >> n;
	vector<pii> v;
	vi s(111111);
	REP(i, n)
	{
		int a, b;
		cin >> a >> b;
		s[a-1]++; s[b]--;
		v.emplace_back(a, b);
	}
	FOR(i, 1, 111110) s[i] += s[i - 1];
	int ans = 0;
	REP(i, 111111)
	{
		if (s[i] >= i) chmax(ans, i);
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 4224
#include<bits/stdc++.h>
using namespace std;
int main(){
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	int a,b,ab,ilosca,iloscb;
	cin >> a >> b >> ab >>ilosca >> iloscb;
	long long wynik =0;





	if (a+b <= 2 * ab ){
		wynik += (a*ilosca);
		wynik += (b*iloscb);
	}
	else {
		if(ilosca>iloscb){
			
			wynik += 2*iloscb*ab;
			ilosca -=iloscb;
			wynik += min(ilosca*a,ilosca*ab*2);
		}
		else{
			wynik += 2*ilosca*ab;
			iloscb -=ilosca;
			wynik += min(iloscb*b,iloscb*ab*2);
		}
	}
	cout << wynik;
	return 0;
}

Measured memory_bytes: 256
import itertools

n = int(input())
s = [input() for _ in range(n)]

num = [0, 0, 0, 0, 0]
index = ['M', 'A', 'R', 'C', 'H']
for i in range(n):
    for j in range(5):
        if s[i][0] == index[j]:
            num[j] += 1
            pass

if num.count(0) >= 3:
    print(0)
    exit()

data = []
for i in range(5):
    if num[i] > 0:
        data.append(num[i])

if len(data) == 3:
    print(data[0] * data[1] * data[2])

elif len(data) == 4:
    print(data[0]*data[1]*data[2] + data[0]*data[1]*data[3] + data[0]*data[2]*data[3] + data[1]*data[2]*data[3])

else:
    print(data[0]*data[1]*data[2] + data[0]*data[1]*data[3] + data[0]*data[1]*data[4] + data[0]*data[2]*data[3] + data[0]*data[2]*data[4] + data[0]*data[3]*data[4] + data[1]*data[2]*data[3] + data[1]*data[2]*data[4] + data[1]*data[3]*data[4] + data[2]*data[3]*data[4])

Measured memory_bytes: 9796
n = int(input())
*a, = map(int, input().split())

a.insert(0, 0)
a.append(0)

s = 0
for i in range(len(a)-1):
    s += abs(a[i]-a[i+1])

for i in range(1, len(a)-1):
    print(s + abs(a[i-1]-a[i+1]) - (abs(a[i-1]-a[i]) + abs(a[i]-a[i+1])))


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

int main(int argc, char const *argv[])
{
	int n,m;
	while(cin>>n>>m,n+m)
	{
		int s[n],t[m],d=0;
		for (int i = 0; i < n; ++i) cin>>s[i],d+=s[i];
		for (int i = 0; i < m; ++i) cin>>t[i],d-=t[i];
		if(d%2)
		{
			cout<<-1<<endl;
			continue;
		}
		d/=2;
		sort(s,s+n),sort(t,t+m);
		int i;
		for (i = 0; i < n; ++i)
		{
			if(s[i]-d>=0)
			{
				for (int j = 0; j < m; ++j) if(s[i]-d==t[j])
				{
					cout<<s[i]<<" "<<t[j]<<endl;
					i=10000,j=m;
				}
			}
		}
		if(i==n)cout<<-1<<endl;
	}
	return 0;
}


Measured memory_bytes: 3008
#include <vector>
#include <list>
#include <map>
#include <set>
#include "queue"
#include <deque>
#include <stack>
#include <numeric>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <complex>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <ctime>
#include <cstring>
#include <climits>
#include <cassert>
#include <iostream>
#include "fstream"
#include  <unordered_set>
using namespace std;
#define PI acos(-1)
#define pii pair<long long ,long long >
#define ll  long long int
#define loop(i,n) for(int i=0;i<n;i++)
#define loop2(i,n) for(int i = 1;i<=n;i+=1)
#define pb push_back
#define mp make_pair
#define EPS 1e-8
void display(vector<int> v1){loop(i,v1.size()){cout<<v1[i]<<" ";}cout<<endl;}
int dx[8] = {0,1,0,-1,1,1,-1,-1};
int dy[8] = {1,0,-1,0,1,-1,1,-1};
using namespace  std;
const int MAXN = (int)1e3;
int arr[MAXN];
int n;
vector<pair<int , int> >v1,ans;
int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    cin>>n;
    for (int i = 1; i<=n; i+=1) {
        cin>>arr[i];
        v1.push_back({arr[i],i});
    }
    sort(v1.begin(), v1.end());
//
//    loop(i, v1.size())
//    {
//        cout<<v1[i].first<<" "<<v1[i].second<<endl;
//    }
    if (abs(v1[0].first)<abs(v1.back().first)) {
        for (int i = 1; i<=n; i+=1) {
            ans.push_back({v1.back().second,i});
        }
        for (int i = 1; i<=n-1; i+=1) {
            ans.push_back({i,i+1});
        }
    }
    else{
        for (int i =1; i<=n; i+=1) {
            ans.push_back({v1[0].second,i});
        }
        for (int i = n; i>=2; i-=1) {
            ans.push_back({i,i-1});
        }
    }
    
    cout<<ans.size()<<endl;
    loop(i, ans.size())
    {
        cout<<ans[i].first<<" "<<ans[i].second<<endl;
    }
    return 0 ;
}


Measured memory_bytes: 256
#include <stdio.h>
int main(void){
    int a, b, c;
    
    scanf("%d %d %d", &a,&b,&c);
    
    0 < a,b,c < 100;
    
    if (a < b && b < c) 
        printf("Yes\n");
    
    else
        printf("No\n");
        
    return(0);
}



Measured memory_bytes: 2080
import java.io.*;
import java.math.*;
import java.util.*;
 
public class Main {
	static final long MOD = 1000000007L;
	public static void main(String[] args) {
		FastScanner sc = new FastScanner();
		PrintWriter pw = new PrintWriter(System.out);
		
		int N = sc.ni();
		if (N>=30)
			pw.println("Yes");
		else
			pw.println("No");
		
		pw.close();
	}
	
    static class FastScanner { 
        BufferedReader br; 
        StringTokenizer st; 
  
        public FastScanner() { 
            br = new BufferedReader(new InputStreamReader(System.in)); 
        } 
  
        String next() { 
            while (st == null || !st.hasMoreElements()) { 
                try { 
                    st = new StringTokenizer(br.readLine());
                } catch (IOException  e) { 
                    e.printStackTrace(); 
                } 
            } 
            return st.nextToken(); 
        }
        
        int ni() { 
            return Integer.parseInt(next()); 
        }
  
        long nl() { 
            return Long.parseLong(next()); 
        } 
  
        double nd() { 
            return Double.parseDouble(next()); 
        } 
  
        String nextLine() {
            String str = ""; 
            try { 
                str = br.readLine(); 
            } catch (IOException e) {
                e.printStackTrace(); 
            } 
            return str;
        }
    }
}

Measured memory_bytes: 33024
#include <iostream>
#include <algorithm>
#include <vector>
#include <functional>
#include <queue>
using namespace std;



typedef long long ll;

#define rep(i,n) for(ll i = 0;i < n; i++)

int main(){
    ll N,K;
    cin >> N >> K;
    ll h[10001000];
    ll hr[10002000];
    ll ans[10001000];
    rep(i,N) cin >> h[i];
    sort(h,h+N);
    ll min = 1e9 + 1;
    for(ll i = 0;i < N-K+1;i++){
        ans[i] = h[i+K-1] - h[i];
        //cout << ans[i] << endl;
        if (ans[i] < min) min = ans[i];
    }
    cout << min << endl;
}

Measured memory_bytes: 2688
# include<iostream>
# include<vector>
# include<time.h>
# include<random>
using namespace std;
using vector1 = vector<int>;
using vector2 = vector<vector1>;
int last(int d, int j, vector1 t){ //d日目から数えてタイプjのコンテストが最後に開催された日を計算
  for(int i=d; i>=1; i--){
    if(t[i] == j) return i;
  }
  return 0;
}
int penalty(vector1 c, int d, vector1 t){ //ペナルティの合計を計算
  int m = 0;
  for(int i=1; i<=26; i++){
    m += c[i] * (d - last(d, i, t));
  }
  return m;
}
int calc_score(int d, int j, int c, vector1 t){ //開催されるコンテストが変更された場合のスコア差を算出
  int s = 1;
  if(d > 1) s = d - last(d-1, j, t);

  int r = s * c; //1日分のスコア差
  int sum = 0;  //スコア差の合計
  int i = d;
  do{
    sum += r;
    i++;
    if((int)t.size() < i) break;
  }while(t[i] != j);
  return sum;
}
void swap_(int d1, int d2, vector1& t){
  int tmp = t[d1]; t[d1] = t[d2]; t[d2] = tmp;
  return;
}
int main(){
  clock_t start = clock();
  int D; cin >> D; //日数d
  vector1 c(26+1, 0); for(int i=1; i<=26; i++) cin >> c[i]; //ペナルティc
  vector2 s(D+1, vector1(26+1)); //あるコンテストが開催された場合の満足度s
  for(int i=1; i<=D; i++){
    for(int j=1; j<=26; j++){
      cin >> s[i][j];
    }
  }
  vector1 t(D+1, 0); for(int i=1; i<=D; i++) t[i] = (i % 26) + 1;
/*  vector1 v(D+1, 0); //スコアv
  for(int i=1; i<=D; i++){
    v[i] = s[i][t[i]];
    v[i] -= penalty(c, i, t);
  }*/
  int score = 0;
  for(int i=1; i<=D; i++){
    score += s[i][t[i]];
    score -= penalty(c, i, t);
  }
  clock_t end = clock();
//  cout << score <<"\n";
  random_device random_a;
  auto num = random_a();
  mt19937 random_b;
  //num = 3180901575;
  random_b.seed(num);
//  cout <<"num: "<< num <<"\n";

  while((double)(end - start) / CLOCKS_PER_SEC < 1.9){
    int r = (int)random_b();
    if(r > 0){
      int p = ((int)random_b() * random_b() % 26) + 1;
      int d = ((int)random_b() * random_b() % D) + 1;
      int old = t[d];
      t[d] = p;
      int up = calc_score(d, p, c[p], t); //増えるスコア
      int down = calc_score(d, old, c[old], t); //減るスコア
      int l = up - down + s[d][p] - s[d][old];
      if(l > 0){
        score += l;
      }else{
        t[d] = old;
      }
    }else{
      int d1 = ((int)random_b() * random_b() % D) + 1;
      int d2 = ((int)random_b() * random_b() % D) + 1;
      int l_old_d1 = calc_score(d1, t[d1], c[t[d1]], t);
      int l_old_d2 = calc_score(d2, t[d2], c[t[d2]], t);
      //cout << t[d1] <<"  "<< t[d2] <<"\n";
      swap_(d1, d2, t);
      //cout << t[d1] <<"  "<<t[d2] <<"\n";
     // break;
      int l_d1 = calc_score(d1, t[d1], c[t[d1]], t);
      int l_d2 = calc_score(d2, t[d2], c[t[d2]], t);
      int l = l_d1 + l_d2 - l_old_d1 - l_old_d2 + s[d1][t[d1]] - s[d1][t[d2]] + s[d2][t[d2]] - s[d2][t[d1]];
      if(l >0){
        score += l;
      }else{
        swap_(d1, d2, t);
      }
    }
    end = clock();
  }
  for(int i=1; i<=D; i++){
    cout << t[i] <<"\n";
  }
  /*cout << score <<"\n";
  int score2=0;
  for(int i=1; i<=D; i++){
    score2 += s[i][t[i]];
    score2 -= penalty(c, i, t);
  }
  cout <<score2 <<"\n";*/
  return 0;
}


Measured memory_bytes: 3232
#include <iostream>

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

    if (b == 1) {
        return 1;
    }

    if (a <= b) {
        std::swap(a, b);
    }

    return gcd(b, a % b);
}


int main() {
    int k = 0;
    std::cin >> k;
    int s = 0;

    for (int a = 1; a <= k; ++a) {
        for (int b = 1; b <= k; ++b) {
            for (int c = 1; c <= k; ++c) {
                s += gcd(gcd(a, b), c);
            }
        }
    }

    std::cout << s << std::endl;
}


Measured memory_bytes: 3156
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.StringTokenizer;

public class Main {
    int n;
    int[] as;

    public static void main(String args[]) {
        new Main().run();
    }

    void run() {
        FastReader sc = new FastReader();
        n = sc.nextInt();
        as = new int[n];
        for (int i = 0; i < n; i++) {
            as[i] = sc.nextInt();
        }
        solve();
    }

    void solve() {
        int[] dp = new int[n + 1];
        for (int i = 0; i < n; i++) {
            dp[as[i] - 1] = i;
        }
        dp[n] = 0;
        int length = 1;
        int tempLength = 1;
        for (int i =1 ; i <= n; i++) {
            if (dp[i] > dp[i - 1]) {
                tempLength++;
            } else {
                length = Math.max(length, tempLength);
                tempLength = 1;
            }
        }
        System.out.println(n - length);
    }

    static int lower_bound(int[] arr, int key) {
        return lower_bound(arr, 0, arr.length - 1, key);
    }

    static int lower_bound(int[] arr, int beginIndex, int endIndex, int key) {
        int low = beginIndex;
        int high = endIndex;
        while (high - low >= 0) {
            int mid = (low + high) / 2;
            if (key <= arr[mid]) {
                high = mid - 1;
            } else {
                low = mid + 1;
            }
        }
        return low;
    }

    static class FastReader {
        BufferedReader br;
        StringTokenizer st;

        public FastReader() {
            br = new BufferedReader(new
                    InputStreamReader(System.in));
        }

        String next() {
            while (st == null || !st.hasMoreElements())
            {
                try
                {
                    st = new StringTokenizer(br.readLine());
                }
                catch (IOException e)
                {
                    e.printStackTrace();
                }
            }
            return st.nextToken();
        }

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

        long nextLong()
        {
            return Long.parseLong(next());
        }

        double nextDouble()
        {
            return Double.parseDouble(next());
        }

        String nextLine() {
            String str = "";
            try
            {
                str = br.readLine();
            }
            catch (IOException e)
            {
                e.printStackTrace();
            }
            return str;
        }
    }
}


Measured memory_bytes: 44888
#pragma comment(linker, "/STACK:1024000000,1024000000")
#include <iostream>
#include <cstdlib>
#include <cmath>
#include <string>
#include <cstring>
#include <cstdio>
#include <algorithm>
#include <queue>
#include <set>
#include <map>
#define re register
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
#define ms(arr) memset(arr, 0, sizeof(arr))
const int inf = 0x3f3f3f3f;
ll a,b,c,k;
int main() 
{
    cin>>a>>b>>c>>k;
    ll ans=999999999999999ll;
    if(k%2==0) ans=a-b;
    else ans=b-a;
    cout<<ans;
    return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<string>
using namespace std;
int main()
{
  string S;
  cin >> S;
  if(S == "SUN"){
    cout << 7<< endl;
  }
  if(S == "MON"){
    cout << 6<< endl;
  }
  if(S == "TUE"){
    cout << 5<< endl;
  }
  if(S == "WED"){
    cout << 4<< endl;
  }
  if(S == "THU"){
    cout << 3<< endl;
  }
  if(S == "FRI"){
    cout << 2<< endl;
  }
  if(S == "SAT"){
    cout << 1<< endl;
  }
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define rep(i,a,b) for(int i=int(a);i<int(b);++i)
using namespace std;
typedef long long ll;
int INF = (1LL << 30) - 1;
int MOD = 1e9+7;
int solve(int N){
    set<int> st[N];
    rep(i,0,N){
        int k;
        cin >> k;
        rep(j,0,k){
            int a;
            cin >> a;
            st[i].insert(a);
        }
    }
    int ans = -1;
    int M;
    cin >> M;
    vector<int> V(M);
    rep(i,0,M)cin >> V[i];
    rep(i,0,N){
        bool ok = 1;
        rep(j,0,M){
            if(st[i].count(V[j]))continue;
            ok = 0;
            break;
        }
        if(!ok)continue;
        if(ans != -1)return -1;
        ans = i + 1;
    }
    return ans;
}
main(){
    int N;
    cin >> N;
    while(N){
        cout << solve(N) << endl;
        cin >> N;
    }
}


Measured memory_bytes: 3520
#include <bits/stdc++.h>
// #include <atcoder/all>
#define ll long long int
#define ld long double
#define yorn(f) cout<<((f)?"Yes":"No")<<endl;
#define YORN(f) cout<<((f)?"YES":"NO")<<endl;
#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
#define repi(i, n) for (ll i = 1; i < (ll)(n); i++)
#define all(x) (x).begin(), (x).end()
#define put(x) cout << x << endl;
#define println(x) cout << x << endl;
using namespace std;
// using namespace atcoder;
void Main()
{
    ll a, b, c, d;
    cin >> a >> b >> c >> d;

    ll res = max(a * c, max(a * d, max(b * c, b * d)));
    put(res);
}
signed main(){ Main();return 0;}

Measured memory_bytes: 3636
import java.util.*;
import javax.lang.model.util.ElementScanner6;

public class Main {

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

        // 入力
        String s = sc.next();

        // 処理
        String out = "Yes";
        if(s.equals("AAA") || s.equals("BBB")){
            out = "No";
        }

        // 出力
        System.out.println(out);
    }

}

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

#define rep(i,a,n) for (int i = a;i < n;i++)
#define per(i,n,a) for (int i = n-1;i >= a;i--)
 
typedef long long ll;
using namespace std;
 
int main(){
  int n,a,b;
  cin >> n >> a >> b;
  int ans = 0;

  rep(i,1,n+1){
    int c = 0, t = i;

    rep(j,0,5){
      c += t%10;
      t /= 10;
    }
    if(a <= c && c <= b) ans += i;
  }
  
  printf("%d\n", ans);

  return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <sstream>
#include <vector>
#include <tuple>
#include <algorithm>
using namespace std;
#define REP(n) for(int i=0;i<n;i++)

int flowers[101] = { 0 };

bool pairCompare(const pair<int, long long> &firstElof, const pair<int, long long> &secondElof) {
	return firstElof.second > secondElof.second;
}

int type_cnt[100001] = { 0 };
int main() {
	long long N,K;
	//vector < pair<int,long long> > all_sushi;
	vector < long long > y0_sushi;
	vector < long long > y1_sushi;

	cin >> N >> K;
	vector <vector<long long>> type_vector(N+1);
	int type_cnt_ofs = 0;
	REP(N) {
		long long t, d;
		cin >> t >> d;
		type_vector[t].push_back(d);
	}

	REP(N+1) {
		if (type_vector[i].size() == 0) {
			continue;
		}
		sort(type_vector[i].begin(), type_vector[i].end());
		y1_sushi.push_back(type_vector[i].back());
		type_vector[i].pop_back();
		y0_sushi.insert(y0_sushi.end(), type_vector[i].begin(), type_vector[i].end());
	}



	sort(y1_sushi.rbegin(), y1_sushi.rend());
	sort(y0_sushi.rbegin(), y0_sushi.rend());

	/*
	REP(N + 1) {
		if (i > 0) {
			type_cnt[i] += type_cnt[i - 1];
			if (type_cnt[i] == 0) {
				type_cnt_ofs = i;
			}
		}
	}
	*/
	
	long long ans = 0;
	long long X = 0;
	long long Y = max(0,(int)(K-y0_sushi.size()));
	REP(Y) {
		X += y1_sushi[i];
	}
	REP(K - Y) {
		X += y0_sushi[i];
	}
	while (true) {
		long long tmp = X + Y*Y;
		if (tmp > ans) {
			ans = tmp;
		}
		if (Y >= K || Y >= y1_sushi.size()) break;
		X += y1_sushi[Y];
		X -= y0_sushi[K-Y-1];
		Y++;
	}
	
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 6904
#include <bits/stdc++.h>
#define ll long long
#define INF 1000000000
using namespace std;
int main(){
    int N;
    cin >> N;
    int W[N];
    for(int i=0;i<N;i++) cin >> W[i];

    int S1 = 0, S2 = 0;
    int ans = INF;
    for(int i=1;i<=N;i++){
        for(int j=0;j<N;j++){
            if(j<=i){
                S1 = S1 + W[j];
            }else{
                S2 = S2 + W[j];
            }
        }
        int sa = abs(S1-S2);
        ans = min(ans,sa);
        S1 = 0;
        S2 = 0;
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
//=================================
// Created on: 2018/07/04 10:14:55
//=================================
#include <bits/stdc++.h>
using namespace std;
int main()
{
    for (int N;;) {
        cin >> N;
        if (N == 0) { break; }
        vector<int> mem[31];
        for (int i = 0, m; i < N; i++) {
            cin >> m;
            for (int j = 0, d; j < m; j++) { cin >> d, mem[d].push_back(i); }
        }
        vector<set<int>> dp(N);
        for (int i = 0; i < N; i++) { dp[i].insert(i); }
        int ans = -1;
        for (int i = 1; i <= 30; i++) {
            set<int> merged;
            for (const int e : mem[i]) {
                for (const int E : dp[e]) { merged.insert(E); }
            }
            for (const int e : mem[i]) { dp[e] = merged; }
            if (merged.size() == N) {
                ans = i;
                break;
            }
        }
        cout << ans << endl;
    }
    return 0;
}



Measured memory_bytes: 3240
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <vector>
#include <set>
#include <cmath>
#include <map>
#define MAXSIZE 10007
using namespace std;

map<int, bool> mp;

int main() {
	int N;
	cin >> N;
	for (int i = 0; i < N; i++) {
		int t;
		cin >> t;
		mp[t] = !mp[t];
	}
	int ans = 0;
	for (auto it = mp.begin(); it != mp.end(); it++) {
		if (it->second == true) ans++;
	}
	cout << ans;
}

Measured memory_bytes: 4864
#include<iostream>
#include<stdio.h>
#include<vector>
#include<algorithm>
#include<set>
#include<string>
#include<map>
#include<string.h>
#include<complex>
#include<math.h>
#include<queue>
#include <functional>
#include<time.h>
#include <stack>
#include<iomanip>
using namespace std;
#define rep(i,a,n) for(int i=(a);i<(n);i++)
#define ll long long
#define llint long long int
#define reverse(v)  reverse(v.begin(), v.end());
#define Yes(ans) if(ans)cout<<"Yes"<<endl; else cout<<"No"<<endl;
#define YES(ans) if(ans)cout<<"YES"<<endl; else cout<<"NO"<<endl;
#define hei(a) vector<a>
#define whei(a) vector<vector<a>>
#define UF  UnionFind
#define rt (a); return (a); 
#define Pint pair<int,int>
#define keta(a)  fixed << setprecision(a)
constexpr auto INF = 1000000000;
constexpr auto mod = 1000000007;
//辞書順はnext_permutation( begin( v ), end( v ) );やで！
llint gcd(llint a, llint b) {
	if (b > a)swap(a, b);
	if (a % b == 0)return b;
	return gcd(b, a % b);
}
llint Tow(int n) {//2のn乗
	if (n == 0)return 1;
	llint x = Tow(n / 2);
	x %= mod;
	x *= x;
	x %= mod;
	if (n % 2 == 1)x *= 2;
	x %= mod;
	return x;
}
int main() {
	int n, x;
	cin >> n >> x;
	hei(int) a(n);
	rep(i, 0, n)cin >> a[i];
	sort(a.begin(), a.end());
	int ans = 0;
	rep(i, 0, n) {
		if (a[i] > x)break;
		x -= a[i];
		ans++;
	}
	if (ans == n && x > 0)ans--;
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 256
N, X, Y = map(int, input().split())
Graph = [[] for _ in range(N)]
for i in range(N):
    if i < N - 1:
        Graph[i].append(i + 1)
        Graph[i + 1].append(i)
    if X == i:
        Graph[X - 1].append(Y - 1)
        Graph[Y - 1].append(X - 1)
# print(Graph)
ans = [0] * (N - 1)
from collections import deque
for i in range(N):
    dist = [-1]*N
    que = deque([i])
    dist[i] = 0
    while que:
        v = que.popleft()
        d = dist[v]
        for w in Graph[v]:
            if dist[w] > -1:
                continue
            dist[w] = d + 1
            que.append(w)
    # print(dist)
    for d in dist:
        if d > 0:
            ans[d - 1] += 1
for a in ans:
    print(a // 2)

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

int main() {
  int N;
  cin>>N;
  
  vector<int> vec(N);
  for (int i = 0; i < N; i++) {
  cin >> vec.at(i);
}
  vector<int> veca(N);
  for (int i = 0; i < N; i++) {
  cin >> veca.at(i);
}
  int ame =0;
  int answer =0;
  
  for (int f = 0; f < N; f++) {
    for (int i = 0; i < N; i++) {
    if(i <= f){
      ame += vec.at(i);
    }
    if(i>=f){
      ame += veca.at(i);
    }
      if(i == N-1){
    if(ame > answer){
      answer = ame;
    }
    ame = 0;
    }
    }
  }
  
  cout << answer << endl;
}



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

string ss="NSEW";

bool vis[4];

int main(){
	string s;
	cin>>s;
	for(auto c:s)
		for(int j=0;j<4;j++)
			if(c==ss[j])
				vis[j]=true;
	if((vis[0]^vis[1])||(vis[2]^vis[3]))
		cout<<"No"<<endl;
	else
		cout<<"Yes"<<endl;
}


Measured memory_bytes: 256
def nyu():
    num1,num2,num3 = input().split()
    #num2 = list(map(int,input().split()))
    num1 = int(num1)
    num2 = int(num2)
    num3 = int(num3)
    return num1,num2,num3

def check(N,A,B):
    sum_cnt=0
    sum = 0
    for n in range(N+1):
        sum = 0
    #     tmp_n = n
    #     sum += int(tmp_n/10000)
    #     tmp_n = tmp_n % 10000
    #     sum += int(tmp_n/10000)
    #     tmp_n = tmp_n % 1000
    #     sum += int(tmp_n/100)
    #     tmp_n = tmp_n % 100
    #     sum += int(tmp_n/10)
    #     tmp_n = tmp_n % 10
    #     sum += tmp_n
        n_str = str(n)
        l_n_str = list(n_str)
    #   print(l_n_str)
        for ln in l_n_str:
            sum += int(ln)

        if A<=sum and sum<=B:
#           print("n=",n,"sum=", sum)
            sum_cnt +=n
    print(sum_cnt)

N,A,B=nyu()
check(N,A,B)



Measured memory_bytes: 3064
#include<iostream>
#include<iomanip>
#include<cmath>
#include<string>
#include<cstring>
#include<vector>
#include<list>
#include<algorithm>
#include<map>
#include<set>
#include<queue>
#include<stack>
using namespace std;
typedef long long ll;
#define fi first
#define se second
#define mp make_pair
#define rep(i, n) for(int i=0;i<n;++i)
#define rrep(i, n) for(int i=n;i>=0;--i)
const int inf=1e9+7;
const ll mod=1e9+7;
const ll big=1e18;
const double PI=2*asin(1);

bool DP[200005];

int main() {
  int N;
  cin>>N;
  vector<vector<int> > edge(N);
  int a, b;
  for(int i=0;i<N-1;++i) {
    cin>>a>>b;
    a--;
    b--;
    edge[a].push_back(b);
    edge[b].push_back(a);
  }
  queue<pair<int, int> > que;
  que.push(mp(0, 0));
  map<int, int> amap;
  for(int i=0;i<N;++i) amap[i] = -1;
  pair<int, int> state;
  while(!que.empty()) {
    state = que.front();que.pop();
    if(amap[state.fi]>-1) continue;
    amap[state.fi] = state.se;
    for(int i=0;i<edge[state.fi].size();++i) {
      if(amap[edge[state.fi][i]]>-1) continue;
      que.push(mp(edge[state.fi][i], state.se+1));
    }
  }
  int dist = 0;
  int node = 0;
  for(int i=0;i<N;++i) {
    if(dist<amap[i]) {
      dist = amap[i];
      node = i;
    }
  }
  que.push(mp(node, 0));
  for(int i=0;i<N;++i) amap[i] = -1;
  while(!que.empty()) {
    state = que.front();que.pop();
    if(amap[state.fi]>-1) continue;
    amap[state.fi] = state.se;
    for(int i=0;i<edge[state.fi].size();++i) {
      if(amap[edge[state.fi][i]]>-1) continue;
      que.push(mp(edge[state.fi][i], state.se+1));
    }
  }
  int distmax = 0;
  for(int i=0;i<N;++i) distmax = max(distmax, amap[i]);
  DP[0] = true;
  DP[1] = false;
  for(int i=2;i<=distmax;++i) {
    if(DP[i-2] && DP[i-1]) DP[i] = false;
    else DP[i] = true;
  }
  if(DP[distmax]) cout<<"First"<<endl;
  else cout<<"Second"<<endl;
}



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

int main() {
    int n;
    cin >> n;
    vector<int> a(n);
    for(int i = 0; i < n; i++){
        cin >> a.at(i);
    }
    sort(a.begin(), a.end());
    for(int i = 0; i < n; i++) {
        cout << a.at(i);
        if(i != n-1) cout << " ";
    }
    cout << endl;
}


Measured memory_bytes: 10688
#include <bits/stdc++.h>
#define itn int
#define REP(i, n) for (int i = 0; i < n; i++)
#define IREP(i, n) for (int i = n - 1; i >= 0; i--)
#define REPEACH(i, k) for (auto &i : k)
#define all(a) a.begin(), a.end()
#define MOD 1000000007
using namespace std;
typedef long long ll;

const ll INF = 1LL << 60;

signed main()
{
    int n;
    cin >> n;
    vector<vector<int>> v(3,vector<int>(n));
    REP(i,n){
        int a,b,c;
        cin >> a >> b >> c;
        if(i==0){
            v[0][0] = a;
            v[1][0] = b;
            v[2][0] = c;
        }
        else{
            v[0][i] = a + max(v[1][i-1], v[2][i-1]);
            v[1][i] = b + max(v[0][i-1], v[2][i-1]);
            v[2][i] = c + max(v[0][i-1], v[1][i-1]);
        }
    }
    cout << max({v[0][n - 1], v[1][n - 1], v[2][n - 1]}) << endl;
}


Measured memory_bytes: 1792
#include <iostream>
#include <algorithm>
#include <vector>
#define LL long long
#define pb push_back
#define mp make_pair
#define INF 0x3f3f3f3f
#define Inf 1000000000000000000LL
#define F first
#define S second
using namespace std;
// namespace UF{
	int par[100010],rnk[100010];
	void init(int n){
		for(int i=1;i<=n;i++)par[i]=i,rnk[i]=0;
	}
	int find(int x){
		if(x==par[x])return x;
		return par[x]=find(par[x]);
	}
	void unite(int x,int y){
		x=find(x),y=find(y);
		if(x==y)return;
		if(rnk[x]<rnk[y])par[x]=y;
		else{
			par[y]=x;
			if(rnk[x]==rnk[y])rnk[x]++;
		}
	}
	bool same(int x,int y){
		return find(x)==find(y);
	}
// };
// using UF::init;
// using UF::unite;
// using UF::same;
typedef pair<int,int>pii;
int n;
pii co[100010];
int u[100010];
int m;
vector<pair<int,pii> >E;
int kruskal(){
	sort(E.begin(),E.end());
	init(n);
	int res=0;
	for(auto cur:E){
		if(!same(cur.S.F,cur.S.S)){
			unite(cur.S.F,cur.S.S);
			res+=cur.F;
			// cout<<cur.u<<' '<<cur.v<<' '<<cur.c<<endl;
		}
	}
	return res;
}
int main(){
	cin>>n;
	for(int i=1;i<=n;i++){
		cin>>co[i].F>>co[i].S;
		u[i]=i;
	}
	sort(u+1,u+n+1,[](const int&x,const int&y){return co[x].F<co[y].F;});
	for(int i=1;i<n;i++)E.emplace_back(co[u[i+1]].F-co[u[i]].F,pii(u[i],u[i+1]));
	sort(u+1,u+n+1,[](const int&x,const int&y){return co[x].S<co[y].S;});
	for(int i=1;i<n;i++)E.emplace_back(co[u[i+1]].S-co[u[i]].S,pii(u[i],u[i+1]));
	cout<<kruskal()<<endl;
	return 0;
}


Measured memory_bytes: 6132
#include <iostream>
#include <string>
#include <vector>
using namespace std;

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

    vector<int> a(n);

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

    for (int i = k; i < n; i++) {
        cout << ((a[i - k] < a[i]) ? "Yes" : "No") << endl;
    }

    return 0;
}


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

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

using namespace std;

using graph=vector<vector<int>>;

void add_edge(graph& G,int u,int v){
	G[u].emplace_back(v);
	G[v].emplace_back(u);
}

vector<int> distance(const graph& G,int s){
	const int INF=INT_MAX;
	int n=G.size();
	vector<int> d(n,INF);
	d[s]=0;
	queue<int> Q; Q.emplace(s);
	while(!Q.empty()){
		int u=Q.front(); Q.pop();
		for(int v:G[u]) if(d[v]==INF) {
			d[v]=d[u]+1;
			Q.emplace(v);
		}
	}
	return d;
}

int main(){
	int n,m; scanf("%d%d",&n,&m);
	graph G(n);
	rep(i,m){
		int u,v; scanf("%d%d",&u,&v); u--; v--;
		add_edge(G,u,v);
	}

	auto d=distance(G,0);

	puts("Yes");
	for(int u=1;u<n;u++){
		for(int v:G[u]) if(d[v]+1==d[u]) {
			printf("%d\n",v+1);
			break;
		}
	}

	return 0;
}


Measured memory_bytes: 10116
#include<iostream>
#include<vector>
#include<algorithm>
#include<iomanip>
typedef long long ll;
using namespace std;
#define INF (1 << 30)
#define INFLL (1LL << 60)
#define rep(i, n) for(int i=0; i<(n); ++i)

namespace Sum
{
	int exec(int N, int K)
	{
		vector<int> sum(N + 1, 0);
		rep(i, N) {
			int s; cin >> s;
			sum[i + 1] = sum[i] + s;
		}
		int mx = 0 - INF;
		rep(i, N - K + 1) mx = max(mx, sum[i + K] - sum[i]);
		return mx;
	}
}

int main()
{
	vector<int> anss;
	for (;;) {
		int N, K; cin >> N >> K;
		if (N == 0 || K == 0) break;
		int rz = Sum::exec(N, K);
		anss.push_back(rz);
	}
	rep(i, anss.size()) {
		cout << anss[i] << endl;
	}
	return 0;
}



Measured memory_bytes: 3056
#include <iostream>
#include <string>
#include <vector>
#include <queue>
#include <deque>
#include <stack>
#include <set>
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <cstring>
#include <cmath>
#include <cstdlib>
#include <algorithm>
#include <random>
#include <iomanip>
#include <functional>
#include <cassert>

using namespace std;

typedef long long ll;

int main() {
  ios_base::sync_with_stdio(false); cin.tie(0);
#ifdef LOCAL
  freopen("input.txt", "r", stdin);
#endif
  int n, v;
  cin >> n >> v;
  vector <int> x(n);
  for (int i = 0; i < n; ++i) cin >> x[i];
  vector <int> l, r;
  vector <vector <int>> g;
  vector <int> id;
  vector <int> have;
  {
    int cur = v;
    while (true) {
      have.push_back(cur);
      if (cur == 0) break;
      cur /= 2;
    }
    reverse(have.begin(), have.end());
  }
  int uk = 0;
  for (int go : have) {
    vector <int> nid;
    int lst = 0;
    int j = 0;
    for (int i = 1; i <= n; ++i) {
      if (i == n || x[i] - x[i - 1] > go) {
        l.push_back(lst);
        r.push_back(i - 1);
        g.push_back(vector <int> ());
        nid.push_back(uk);
        while (j < (int)id.size() && r[id[j]] <= r[uk]) {
          g[uk].push_back(id[j++]);
        }
        uk++;
        lst = i;
      }
    }
    id = nid;
  }
  if ((int)id.size() > 18) {
    for (int i = 0; i < n; ++i) {
      cout << "Impossible\n";
    }
    return 0;
  }
  map <vector <int>, bool> vis;
  function <bool(vector <int>, int)> rec = [&] (vector <int> ids, int cnt) {
    if (!vis.count(ids)) {
      bool good = false;
      if (ids.empty()) {
        good = true;
      } else {
        if (cnt == 0) {
          good = false;
        } else {
          int nxt = 0;
          for (int i : ids) nxt += (int)g[i].size();
          for (int i : ids) {
            if (nxt - (int)g[i].size() <= cnt - 1) {
              vector <int> nids;
              for (int j : ids) {
                if (j != i) {
                  for (int k : g[j]) nids.push_back(k);
                }
              }
              if (rec(nids, cnt - 1)) {
                good = true;
                break;
              }
            }
          }
        }
      }
      vis[ids] = good;
    }
    return vis[ids];
  };
  for (int i : id) {
    vector <int> go;
    for (int j : id) {
      if (j != i) {
        for (int k : g[j]) {
          go.push_back(k);
        }
      } 
    }
    bool good = (go.size() <= (int)have.size() - 1 ? rec(go, (int)have.size() - 1) : false);
    for (int j = l[i]; j <= r[i]; ++j) {
      cout << (good ? "Possible" : "Impossible") << '\n';
    }
  }
}



Measured memory_bytes: 29484
n, k = map(int, input().split())
ans = 0
if k == 0:
    print(n*n)
else:
    for i in range(n-k):
        ans += n // (i + k + 1) * (i + 1)
        if n % (i + k + 1) >= k:
            ans += n % (i+k+1)-k+1
    print(ans)

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

using namespace std;

int main()
{
    int n;
    scanf("%d",&n);
    int a[n],b[n],c[n];
    for(int i=0;i<n;i++) scanf("%d",&a[i]);
    for(int i=0;i<n;i++) scanf("%d",&b[i]);
    for(int i=0;i<n-1;i++) scanf("%d",&c[i]);
    int res=0;
    for(int i=0;i<n;i++) res+=b[i];
    for(int i=0;i<n-1;i++) if(a[i]+1==a[i+1]) res+=c[a[i]-1];
    printf("%d\n",res);
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
  string S;
  cin >> S;
  for(int i = 0; i < S.size()-1; i++){
    for(int j = i+1;j<S.size(); j++){
      if(S.at(i) == S.at(j)){
        cout << "no" << endl;
        return 0;
      }
    }
  }
  cout << "yes" << endl;
}

Measured memory_bytes: 256
#include<stdio.h>
#include<stdlib.h>
typedef long long int ll;
int asc(const void *a,const void *b){return *(int*)a-*(int*)b;}
int main(){
    static int n,a[200000];
    int flg=0;

    scanf("%d",&n);
    for(int i=0;i<n;i++){
        scanf("%d",&a[i]);
    }

    
    qsort(a,n,sizeof(int),asc);

    for(int i=0;i<n;i++){
        if(a[i]!=0){
            flg=1;
            break;
        }
    }

    if(!flg){
        printf("Yes\n");
        return 0;
    }

    if(n%3!=0){
        printf("No\n");
        return 0;
    }

    
    if(a[0]!=a[n/3-1]||a[n/3]!=a[2*n/3-1]||a[2*n/3]!=a[n-1]){
        printf("No\n");
        return 0;
    }

    if((a[0]^a[2*n/3])==a[n/3]){
        printf("Yes\n");
        return 0;
    }
    printf("No\n");




    return 0;

}

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



signed main(){
    ios::sync_with_stdio(false);
	cin.tie(0);
 
    ll a,b;
    cin>>a>>b;
    if(a<b) swap(a,b);
    ll ans = a+b;
    if((ans)%2==0){
        ans/=2;
        cout<<ans<<endl;
    }
    else cout<<"IMPOSSIBLE"<<endl;
    
}

Measured memory_bytes: 256
import numpy as np
x, y = map(int, input().split())
A = []

for i in range(x):
    A.append(y)
    y += 1

B = np.abs(A)

we = min(B)
if we not in A:
    we = - + we
    A.remove(we)
else:
    A.remove(we)

cnt = 0
for i in A:
    cnt += i

print(cnt)

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

const int INF = 1e18;

int X, Y, Z, N;
int A[101010], B[101010], C[101010];
int a[101010], b[101010];
int dp1[101010], dp2[101010];

void calc1() {
  for (int i = 0; i < N; i++) dp1[i] = -INF;
  priority_queue<int> q;

  int sum = 0;
  for (int i = 0; i < N; i++) {
    q.push(-b[i]);
    sum += b[i];
    if (q.size() > Y) {
      int tmp = -q.top();
      sum -= tmp;
      q.pop();
    }

    if (q.size() == Y) dp1[i] = sum;
  }
}

void calc2() {
  for (int i = 0; i < N; i++) dp2[i] = -INF;
  priority_queue<int> q;

  int sum = 0;
  for (int i = N - 1; i >= 0; i--) {
    q.push(-a[i]);
    sum += a[i];
    if (q.size() > X) {
      int tmp = -q.top();
      sum -= tmp;
      q.pop();
    }

    if (q.size() == X) dp2[i] = sum;
  }
}

signed main() {
  cin >> X >> Y >> Z;
  N = X + Y + Z;

  for (int i = 0; i < N; i++) cin >> A[i] >> B[i] >> C[i];

  int ans = 0;
  for (int i = 0; i < N; i++) {
    ans += C[i];
    A[i] -= C[i];
    B[i] -= C[i];
  }

  vector<int> v;
  for (int i = 0; i < N; i++) v.push_back(i);

  sort(v.begin(), v.end(), [&](int x, int y) {
    return A[x] - B[x] < A[y] - B[y];
  });

  for (int i = 0; i < N; i++) {
    int idx = v[i];
    a[i] = A[idx];
    b[i] = B[idx];
  }

  calc1();
  calc2();

  int mx = -INF;
  for (int i = 0; i < N - 1; i++) {
    mx = max(mx, dp1[i] + dp2[i + 1]);
  }

  ans += mx;

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


Measured memory_bytes: 8052
x, n = [int(i) for i in input().split(' ')]

if n:
    p = [int(i) for i in input().split(' ')]
    if x in p:
        for i in range(1, 101):
            if not x - i in p:
                print(x - i)
                exit()
            elif not x + i in p:
                print(x + i)
                exit()
    else:
        print(x)
else:
    print(x)

Measured memory_bytes: 9196
#include <iostream>
#include <algorithm>
#include <vector>
#include <map>

template <class T>
std::map<T, int> compress(std::vector<T>& v) {
    std::sort(v.begin(), v.end());
    v.erase(std::unique(v.begin(), v.end()), v.end());

    std::map<T, int> rev;
    for (int i = 0; i < (int)v.size(); ++i) rev[v[i]] = i;
    return rev;
}

template <class T>
std::vector<T> vec(int len, T elem) { return std::vector<T>(len, elem); }

using lint = long long;

struct Point {
    lint x, y, z;
};

void solve() {
    int n, m;
    std::cin >> n >> m;

    std::vector<lint> xs, ys, zs;
    std::vector<Point> lps(n), rps(n);
    for (int i = 0; i < n; ++i) {
        auto& lp = lps[i];
        auto& rp = rps[i];
        std::cin >>
            lp.x >> lp.y >> lp.z >>
            rp.x >> rp.y >> rp.z;

        xs.push_back(lp.x);
        xs.push_back(rp.x);
        ys.push_back(lp.y);
        ys.push_back(rp.y);
        zs.push_back(lp.z);
        zs.push_back(rp.z);
    }

    auto revx = compress(xs);
    auto revy = compress(ys);
    auto revz = compress(zs);
    int xn = xs.size(), yn = ys.size(), zn = zs.size();

    auto grid = vec(xn, vec(yn, vec(zn, 0)));
    for (int i = 0; i < n; ++i) {
        auto l = lps[i], r = rps[i];

        l.x = revx[l.x], r.x = revx[r.x];
        l.y = revy[l.y], r.y = revy[r.y];
        l.z = revz[l.z], r.z = revz[r.z];

        ++grid[l.x][l.y][l.z];

        --grid[r.x][l.y][l.z];
        --grid[l.x][r.y][l.z];
        --grid[l.x][l.y][r.z];

        ++grid[l.x][r.y][r.z];
        ++grid[r.x][l.y][r.z];
        ++grid[r.x][r.y][l.z];

        --grid[r.x][r.y][r.z];
    }

    for (int i = 0; i < xn; ++i) {
        for (int j = 0; j < yn; ++j) {
            for (int k = 0; k + 1 < zn; ++k) {
                grid[i][j][k + 1] += grid[i][j][k];
            }
        }
    }
    for (int i = 0; i < xn; ++i) {
        for (int j = 0; j + 1 < yn; ++j) {
            for (int k = 0; k < zn; ++k) {
                grid[i][j + 1][k] += grid[i][j][k];
            }
        }
    }
    for (int i = 0; i + 1 < xn; ++i) {
        for (int j = 0; j < yn; ++j) {
            for (int k = 0; k < zn; ++k) {
                grid[i + 1][j][k] += grid[i][j][k];
            }
        }
    }

    lint ans = 0;
    for (int i = 0; i < xn; ++i) {
        for (int j = 0; j < yn; ++j) {
            for (int k = 0; k < zn; ++k) {
                if (grid[i][j][k] < m) continue;
                ans += (xs[i + 1] - xs[i]) * (ys[j + 1] - ys[j]) * (zs[k + 1] - zs[k]);
            }
        }
    }

    std::cout << ans << "\n";
}

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

    solve();

    return 0;
}



Measured memory_bytes: 7432
//                                               KEEP GRINDING
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp> 

using namespace std;
using namespace __gnu_pbds; 

typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update>   new_data_set;

#define fastio ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL); 

#define int long long
#define ld long double
#define MOD 1000000007
#define mod 998244353
#define precise(i) fixed << setprecision(10) << i
#define f(i,a,b) for(int i=a;i<b;++i)

#define endl '\n'
#define debug cout<<endl;cout<<"\n========================================\n"<<endl;
#define err1(a) cout<<#a<<" "<<a<<endl;
#define err2(a,b) cout<<#a<<" "<<a<<" "<<#b<<" "<<b<<endl;
#define err3(a,b,c) cout<<#a<<" "<<a<<" "<<#b<<" "<<b<<" "<<#c<<" "<<c<<endl;
#define err4(a,b,c,d) cout<<#a<<" "<<a<<" "<<#b<<" "<<b<<" "<<#c<<" "<<c<<" "<<#d<<" "<<d<<endl;

#define all(a) a.begin(),a.end()
#define show(a) for(auto xyz:a)cout<<xyz<<" ";cout<<endl;
#define mx(a) *max_element(a)
#define mn(a) *min_element(a) 
#define LB lower_bound  //THIS GIVES THE ITR TO THE ELEMENT IN RANGE [SI,EI) THAT IS >= OUR VALUE 
#define UB upper_bound  //THIS GIVES THE ITR TO THE ELEMENT IN RANGE [SI,EI) THAT IS > OUR VALUE 

#define fr first
#define sc second

#define MAXN 200050
#define INF 9223372036854775807
signed main(){
    fastio
	int n;
	cin>>n;
	vector<int> a(n),b(n);
	f(i,0,n)
	    cin>>a[i]>>b[i];
	sort(all(a));
	sort(all(b));
	int x,y;
	if(n%2){
		x=a[ n/2 ];
		y=b[ n/2 ];
	}else{
		x=a[ (n-1)/2 ]+ a[ (n-1)/2  + 1];
		y=b[ (n-1)/2 ]+ b[ (n-1)/2  + 1];
	}
	cout<<y-x+1;
	
}


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

using namespace std;
typedef long long int ll;
typedef pair<ll, ll > pi;  
typedef pair<pair<ll, ll >, ll > pii;  
vector<ll > vec;
vector<vector<ll > > vec2;
ll MOD = 1000000007;

int main(){

    string s; cin >> s;
    ll t_s = stoll(s);
    vector<ll > S(s.size(), 0);

    for(ll i = 0; i < s.size(); i++){
        S[i] = t_s % 10;
        t_s /= 10;
        //cout << S[i] << endl;
    }

    ll sum = 0;
    for(ll i = 0; i < (1<<s.length() - 1); i++){
        ll t_sum = S[0];
        ll cn = 1;
        bool f = true;
        for(ll j = 0; j < s.length() - 1; j++){
            if(i >> j & 1){
                sum += t_sum;
                t_sum = 0;
                cn = 0;
            }
            //cout << "kakuni:" << S[j + 1] * pow(10, cn) + t_sum << endl;
            //cout << S[j + 1] << " " << pow(10, cn) << endl;
            ll tt = ceil(S[j + 1]) * ceil(pow(10, cn));
            //cout << tt << endl;
            t_sum += tt;
            //cout << t_sum << endl;
            cn++;
           
        }
        //cout << bitset<3>(i) << endl;
        //cout << t_sum << endl;
        sum += t_sum;
    }

    cout << sum << endl;

}

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

using namespace std;

int main() {
	int n;

	cin >> n;

	vector <int> a(n);

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

	long long int ans = 0;

	for (int i = 1; i < n; i++) {
		if (a[i] >= a[i-1]) {
			continue;
		}

		ans += a[i-1] - a[i];
		a[i] = a[i-1];
	}

	cout << ans << "\n";

	return 0;
}

Measured memory_bytes: 4040