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

/* #pragma */
//#pragma GCC optimize("Ofast")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")

/*alias*/
#define y0 y3487465
#define y1 y8687969
#define j0 j1347829
#define j1 j234892
#define next asdnext
#define prev asdprev
#define itn int

/*struct*/
struct aaa {
	aaa() {
		cin.tie(nullptr); ios::sync_with_stdio(false); cout << fixed << setprecision(20);
	};
}aaaaaaa;

/* const */
const int INF = 1001001001;
const long long LINF = 1001001001001001001ll;
const int MOD = 1e9 + 7; //10^9
const double EPS = 1e-9;
const int dx[] = { 1, 1, 0, -1, -1, -1, 0, 1 }, dy[] = { 0, 1, 1, 1, 0, -1, -1, -1 };
//Counterclockwise from the 6o'clock direction
//Take the x-axis downward and the y-axis right

//#define int long long

//g++ -std=c++14 -Wall --pedantic-errors -fsanitize=signed-integer-overflow -fno-sanitize-recover=all -o template template.cpp


int mae(string s){
	int cnt{};
	for(int m = 0, i_len = (int)s.size(); m < i_len; ++m){
		if(2*m+1 <= (int)s.size()){
			if(s[0] == '1'){
				if(s[2*m+1] != '0'){
					s[2*m+1] = '0';
					++cnt;
				}

				if(s[2*m] != '1'){
					s[2*m] = '1';
					++cnt;
				}
			}

			else if(s[0] == '0'){
				if(s[2*m+1] != '1'){
					s[2*m+1] = '1';
					++cnt;
				}

				if(s[2*m] != '0'){
					s[2*m] = '0';
					++cnt;
				}
			}
		}
	}
	if(s[(int)s.size()-1] == s[0] && (int)s.size()%2 != 0){
		--cnt;
	}
	return cnt;
}

int back(string s){

	reverse(s.begin(), s.end());
	int cnt{};
	for(int m = 0, i_len = (int)s.size(); m < i_len; ++m){
		if(2*m+1 <= (int)s.size()){
			if(s[0] == '1'){
				if(s[2*m+1] != '0'){
					s[2*m+1] = '0';
					++cnt;
				}

				if(s[2*m] != '1'){
					s[2*m] = '1';
					++cnt;
				}
			}

			else if(s[0] == '0'){
				if(s[2*m+1] != '1'){
					s[2*m+1] = '1';
					++cnt;
				}

				if(s[2*m] != '0'){
					s[2*m] = '0';
					++cnt;
				}
			}
		}
	}
	if(s[(int)s.size()-1] == s[0] && (int)s.size()%2 != 0){
		--cnt;
	}
	return cnt;	
}

signed main()
{
	string s{};cin >> s;
	int ans = min(mae(s), back(s));
	bool aaa = true;
	bool bbb = true;

	if(s[0] == '1'){
		for(const auto& i: s){
			if(i == '0'){
				aaa = false;
			}
		}
	}

	if(s[0] == '0'){
		for(const auto& i: s){
			if(i == '1'){
				bbb = false; 
			}
		}
	}

	if((int)s.size() == 1 && s[0] == '0')cout << 0 << endl;
	else if((int)s.size() == 1 && s[0] == '1')cout << 0 << endl;
	else if(aaa && bbb){
		cout << (int)s.size()/2 << endl;
	}
	else
		cout << ans << endl;

	return 0;
}

Measured memory_bytes: 592
#include <iostream>
#include <string>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <algorithm>
#include <utility>
#include <iomanip>
#include <tuple>
#include <numeric>
#include <cstdio>
#include <cmath>
using namespace std;
using ll = long long;
const int INF = 1e9;

int main() {
    int n, k; cin >> n >> k;
    vector<int> a(n+1, 0);
    for (int i = 1; i <= k; i++) {
        int d; cin >> d;
        for (int j = 0; j < d; j++) {
            int inp; cin >> inp;
            a[inp]++;
        }
    }
    int sum = 0;
    for (int i = 1; i <= n; i++) {
        if (a[i] != 0) {
            sum++;
        }
    }
    cout << n - sum << endl;
}

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

int main()
{
    long long a,b,c,d;
    long long num[4];
    long long c_num,o_num;

    cin>>a>>b>>c>>d;
    num[0] = a;
    num[1] = b;
    num[2] = c;
    num[3] = d;

    o_num=num[0]*num[2];
    for(int i=0;i<2;++i)
    {
        for(int j=2;j<4;++j)
        {
            c_num=num[i]*num[j];
            if(o_num<=c_num) o_num=c_num;
        }
    }
    cout<<o_num<<endl;
}

Measured memory_bytes: 3628
#include <iterator>
#include <list>
#include <algorithm>
#include <iostream>
#include <unordered_set>
#include <unordered_map>
#include <vector>
#include <sstream>
#include <iomanip>
#include <string>
#include <cmath>
#include <set>
#include <map>
#include <queue>
#include <stack>
using namespace std;

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

  vector<pair<string, pair<int, int>>> cities(N);
  for (int i = 1; i <= N; i++) {
    cin >> cities[i-1].first >> cities[i-1].second.first;
    cities[i-1].second.second = i;
  }

  sort(cities.begin(), cities.end(), [](pair<string, pair<int, int>>& lhs, pair<string, pair<int, int>>& rhs) {
                                       if (lhs.first != rhs.first) {
                                         return lhs.first < rhs.first;
                                       } else {
                                         return lhs.second.first > rhs.second.first;
                                       }
                                     });


  for (auto& kv : cities) {
    cout << kv.second.second << endl;
  }

  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define REP(i, n) for(int i = 0; i < n; i++)
#define REPR(i, n) for(int i = n; i >= 0; i--)
#define FOR(i, m, n) for(int i = m; i < n; i++)
#define INF 2e9
#define ALL(v) v.begin(), v.end()
using namespace std;
typedef long long ll;
int main()
{
    int n, m, c;
    int count = 0;
    cin >> n >> m >> c;
    int b[m];
    int a[n][m];
    REP(i, m) cin >> b[i];
    REP(i, n){
        REP(j, m) cin >> a[i][j];
    }
    REP(i, n){
        int tmp = 0;
        REP(j, m) tmp += a[i][j] * b[j];
        if (tmp + c > 0) count += 1;
    }
    cout << count << "\n";
}

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

struct Node{
  Node *right;
  Node *left;
  Node *parent;
  int key;
};

Node *root, *NIL;

Node *treeMinimum(Node *x){
  while(x->left != NIL) x=x->left;
  return x;
}

Node *treeMaximum(Node *x){
  while(x->right != NIL) x=x->right;
  return x;
}

Node *Search(Node *u, int k){
  while(u!=NIL && k!=u->key){
    if(k<u->key) u=u->left;
    else u=u->right;
  }
    return u;
}
Node *treeSuccessor(Node *x){
  if(x->right != NIL) return treeMinimum(x->right);
  Node *y=x->parent;
  while(y!=NIL && x==y->right){
    x=y;
    y=y->parent;
  }
  return y;
}

void Delete(Node *z){
  Node *y; // node to be deleted
  Node *x; // child of y
  if(z->left==NIL||z->right==NIL) y=z;
  else y=treeSuccessor(z);
  if(y->left!=NIL){
    x=y->left;
  }else{
    x=y->right;
  }
  if(x!=NIL)  x->parent=y->parent;
  if(y->parent==NIL) root=x;
  else{
    if(y==y->parent->left) y->parent->left=x;
    else y->parent->right=x;
  }
  if(y!=z) z->key=y->key;
  free(y);
}

void insert(int k){
  Node *y = NIL;
  Node *x = root;
  Node *z;

  z = (Node *)malloc(sizeof(Node));
  z->key = k;
  z->left = NIL;
  z->right = NIL;
  while(x!=NIL){
    y=x;
    if(z->key < x->key) x = x->left;
    else x = x->right;
  }
  z->parent=y;
  if(y==NIL) root=z;
  else{
    if(z->key < y->key) y->left=z;
    else y->right=z;
  }
}

void inorder(Node *u){
  if(u==NIL) return;
  inorder(u->left);
  cout<<" "<<u->key;
  inorder(u->right);
}
void preorder(Node *u){
  if(u==NIL) return;
  cout<<" "<<u->key;
  preorder(u->left);
  preorder(u->right);
}


int main(){
  int n,x;
  string s;
  cin>>n;
  for(int i=0;i<n;i++){
    cin>>s;
    if(s[0]=='f'){
      cin>>x;
      Node *t=Search(root,x);
      if(t!=NIL) cout<<"yes"<<endl;
      else cout<<"no"<<endl;
    }else if(s[0]=='i'){
      cin>>x;
      insert(x);
    }
    else if(s[0]=='p'){
      inorder(root);
      cout<<endl;
      preorder(root);
      cout<<endl;
    }
    else if(s[0]=='d'){
      cin>>x;
      delete(Search(root,x));
      
    }
  }
  
  return 0;
}



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

using ll = long long;

int main() {
    int d;
    cin >> d;
    cout << "Christmas";
    rep(i, 25 - d) cout << " Eve";
    cout << endl;
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h> 
using namespace std;
#define rep(i, N) for(int i=0; i<N; i++)
typedef long long ll;
#define dump(x) cerr<<#x<<"="<<x<<endl
using P = pair<int, int>;

int main() {
   string s, t;
   cin >> s >> t;

   int cnt = 0;
   rep(i, s.size()){
      if(s.at(i)!=t.at(i)){
         cnt++;
      }
   }

   cout << cnt << endl;
   return 0;
}


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

int main(){
    int n, x;
    cin >> n >> x;
    vector<int> vec(n);
    for(int i=0; i<n; i++){
        cin >> vec.at(i);
    }
    sort(vec.begin(), vec.end());

    int i = 0;
    while(x > 0){
        if(x == vec.at(i)){
            x -= vec.at(i);
            i++;
        }else if(x > vec.at(i) && i < n-1){
            x -= vec.at(i);
            i++;
        }else{
            break;
        }
        if(i >= n){
            break;
        }
    }
    cout << i << endl;
    return 0;
}

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

int main(){
  ll N;cin>>N;
  vector<ll> A(N+2,0);rep(i,N)cin>>A[i+1];
  ll ans=0;
  rep(i,N+1){
    ans += abs(A[i+1]-A[i]);
  }
  rep(i,N){
    if((A[i]<A[i+1]&&A[i+2]<A[i+1])||(A[i+1]<A[i]&&A[i+1]<A[i+2])){
      cout << ans - (abs(A[i+1]-A[i])+abs(A[i+2]-A[i+1])-abs(A[i+2]-A[i])) << endl;
    }
    else cout << ans << endl;
  }
}

Measured memory_bytes: 2048
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int a,b,c;
    cin>>a>>b>>c;
    if(a==b&&a==c&&b==c)
    {
        cout<<1<<endl;
        return 0;
    }
    if(a==b||b==c||a==c)
    {
        cout<<2<<endl;
        return 0;
    }
    cout<<3<<endl;
    return 0;
}

Measured memory_bytes: 256
import math
import fractions
from functools import reduce


n = int(input())
a = list(map(int,(input().split())))

def lcm_base(x, y):
    return ((x * y) // fractions.gcd(x, y))

def lcm(*numbers):
    return reduce(lcm_base, numbers, 1)

def lcm_list(numbers):
    return reduce(lcm_base, numbers, 1)

x = lcm(*a)

x = x - 1
result = 0
for i in a:
    result += x % i

print(result)


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

int main() {
  int n;
  cin >> n;
  
  if(n==111)
    cout<<999<<endl;
  if(n==119)
    cout<<991<<endl;
  if(n==191)
    cout<<919<<endl;
  if(n==199)
    cout<<911<<endl;
  if(n==911)
    cout<<199<<endl;
  if(n==919)
    cout<<191<<endl;
  if(n==991)
    cout<<119<<endl;
  if(n==999)
    cout<<111<<endl;
    
    
}

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

#define rep(i, a, b) for (int i = (a), i##end = (b); i <= i##end; ++i)
#define per(i, a, b) for (int i = (a), i##end = (b); i >= i##end; --i)

mt19937 Rnd(chrono::high_resolution_clock::now().time_since_epoch().count());

template <typename T>
inline void chkmax(T &x, T y) { if (x < y) x = y; }

template <typename T>
inline void chkmin(T &x, T y) { if (x > y) x = y; }

inline int read() {
  #define nc getchar()
  int x = 0;
  char c = nc;
  while (c < 48) c = nc;
  while (c > 47) x = x * 10 + (c ^ 48), c = nc;
  return x;
  #undef nc
}

typedef long long ll;
const int maxn = 1e6 + 10;
int n, A[maxn];

int main() {
  cin >> n;
  rep(i, 2, n) {
    int x = read();
    A[x]++;
  }
  rep(i, 1, n) cout << A[i] << endl;
  return 0;
}

Measured memory_bytes: 4380
s = input()

if s == 'MON':
  print(6)
elif s == 'TUE':
  print(5)
elif s == 'WED':
  print(4)
elif s == 'THU':
  print(3)
elif s == 'FRI':
  print(2)
elif s == 'SAT':
  print(1)
else:
  print(7)
    

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


int main()
{
	string s, p;
	cin >> s >> p;
	bool flag = false;
	for (int i = 0; i < s.length(); i++){
		for (int j = 0; j < p.length(); j++){
			if (s[(i + j)%s.length()] != p[j]){
				break;
			}
			else if (j == p.length() - 1){
					flag = true;
			}
		}
	}
	if (flag){
		cout << "Yes" << endl;
	}else{
		cout << "No" << endl;
	}

	return 0;
}

Measured memory_bytes: 1184
#include<bits/stdc++.h>
    using namespace std;
    #define ll long long 
    #define ld long double
    #define MOD 1000000007
    #define mod9 1000000009
    #define fast ios_base :: sync_with_stdio(0);cin.tie(NULL);cout.tie(NULL);
    #define mp make_pair
    #define pb push_back
    #define ct ll t;cin>>t;while(t--)
    #define bi begin()
    #define ei end()
    #define fi first 
    #define se second  
    #define foe(i,a,b) for(ll i=a;i<b;i++)
    #define rfoe(i,a,b) for(ll i=a;i>=0;i--)
    #define sz(s) s.size() 
    #define mem(a,s) memset(a,s,sizeof(a)) 
    #define all(v) v.bi,v.ei
    #define MAX             8000000000000000064LL
    #define MIN            -8000000000000000064LL   

    typedef pair<ll,ll> pii;
    
    ll add(ll a, ll b){return (a%MOD + b%MOD + ((MAX)/MOD)*MOD)%MOD;}
    ll sub(ll a, ll b){return (a%MOD - b%MOD + ((MAX)/MOD)*MOD)%MOD;}
    ll mul(ll a, ll b){return ((a%MOD)*(b%MOD) + ((MAX)/MOD)*MOD)%MOD;}
    ll lcm(ll a,ll b){return(a*b)/__gcd(a,b);}
    ll fact[1000007 ]={0};
    ll expo(ll x, ll y) {ll res=1;x=x%MOD;while(y>0){if(y&1)res=(1ll*res*x)%MOD;
    y=y>>1;x=(1ll*x*x)%MOD;} return res;}
    void facto() {fact[0]=1;fact[1]=1;for(ll i=2;i<1000007;i++)fact[i]=(fact[i-1]*i)%MOD;}
    ll ncr(ll n,ll r) {ll res=1; res=fact[n]; res=(res*(expo(fact[r],MOD-2)))%MOD; res=(res*(expo(fact[n-r],MOD-2)))%MOD; return res;}
    ll npr(ll n,ll r) {facto(); ll res=1; res=fact[n]; res=(res*(expo(fact[n-r],MOD-2)))%MOD; return res; }
    int const N=2e5+9;
    ll const INF = 2e18+5;
    ll dx[8]={0,0,1,-1,1,1,-1,-1};
    ll dy[8]={1,-1,0,0,-1,1,-1,1};
    long long binpow(long long a, long long b) {
    long long res = 1;
    while (b > 0) {
        if (b & 1)
            res = mul(res,a);
        a = mul(a,a);
        b >>= 1;
    }
    return res;
}
  
    void solve()
    {  
        string s;
        cin>>s;
        if(s.back()=='s')
        {
            cout<<s<<"es\n";
        }
        else
        {
            cout<<s<<"s\n";
        }
        
    }
    int main()
    {
        fast
        // facto();
        // Sieve();
    //    ct    
        { 
            solve();
        }
    }


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

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

  ll n,a,b;
  cin >> n >> a >> b;

  if(a == 0) {
    cout << 0 << endl;
    return 0;
  }

  ll ans = 0;
  ans += (n / (a+b)) * a;
  ll rem = n % (a+b);
  ans += min(rem, a);
  cout << ans << endl;
}


Measured memory_bytes: 256
import java.util.*;
/*
(r+1) × (c+1) の新しい表を出力して下さい。各行の隣り合う整数は１つの空白で区切って
下さい。各行の最後の列としてその行の合計値を、各列の最後の行としてその列の合計値を、
最後の行・列に表全体の合計値を挿入して下さい。 
*/
public class Main {
    public static void main(String[] args) throws Exception {
        // Your code here!
       Scanner sc = new Scanner(System.in);
       int r = sc.nextInt();//　n行ある
       int c = sc.nextInt();//　m行ある

        int [][] answer = new int[100+1][100+1];//元の表入れる箱
//        int [] row = new int [c];//answer行合計入れる箱
//        int [] column = new int [r];//answer列合計入れる箱

        int rowtotal=0;//行小計
        int columntotal=0;//列小計
        int totalall=0;//合計

        int i;
        int j;
        int k;
        int l;

        for( i = 0; i < r; i++){
          for( j = 0; j < c; j++){
              answer[i][j] = sc.nextInt();
  
              totalall += answer[i][j];
              rowtotal += answer[i][j];
              
              System.out.print(answer[i][j] + " ");
 //             }else{
 //                 System.out.print(answer[i][j]);
 //             }
              }
 //         }
               answer[i][c] = rowtotal;
               System.out.println(answer[i][c]);
               rowtotal = 0;

        }
        answer[r][c]=totalall;

        for(i=0;i<c;i++){
            for(j = 0;j<r;j++){
                columntotal+=answer[j][i];
                
            }
            answer[r][i]=columntotal;
            System.out.print(answer[r][i] + " ");
            
            columntotal=0;
        }
        System.out.println(answer[r][c]);
    }
}




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

using namespace std;
#define ll long long
#define ull unsigned long long
#define i128 __int128
#define mp make_pair
#define ld long double
typedef pair<int, int> pii;
typedef priority_queue<int, vector<int>, greater<int> > small_heap;
typedef priority_queue<int> big_heap;
const int N = 2e5 + 100;
int T;

int n, k, a[N];

bool work() {
    static int s[N];
    memset(s, 0, sizeof(s));
    for (int i = 1; i <= n; i++) {
        int l = max(1, i - a[i]), r = min(n, i + a[i]);
        s[l]++, s[r + 1]--;
    }
    bool res = false;
    for (int i = 1; i <= n; i++) {
        s[i] += s[i - 1];
        if (s[i] != a[i]) {
            res = true;
            a[i] = s[i];
        }
    }
    return res;
}

int main() {
    scanf("%d%d", &n, &k);
    for (int i = 1; i <= n; i++)
        scanf("%d", &a[i]);
    for (int i = 1; i <= k; i++)
        if (!work()) break;
    for (int i = 1; i <= n; i++)
        printf("%d ", a[i]);
    printf("\n");
    return 0;
}

Measured memory_bytes: 5368
while True:
    m,f,r = map(int,input().split())
    if m == -1 and f == -1 and r == -1: break
    result = "A" if m+f >= 80 else "B" if 80 > m+f >= 65 else "C" if 65 > m+f >= 50 or r >= 50 else "D" if 50 > m+f >= 30 else "F"
    if m == -1 or f == -1:
        result = "F"

    print(result)


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

using namespace std;

const int INF = 1000000010;

int main(){
  cin.tie(0);
  ios_base::sync_with_stdio(0);
  int N, K, Q;
  cin >> N >> K >> Q;
  vector<int> A(N);
  for(int i=0;i<N;i++) cin >> A[i];
  int ans = INF;
  for(int i=0;i<N;i++){
    int l = 0, r = 0;
    vector<int> vec;
    while(l < N){
      priority_queue<int, vector<int>, greater<int> > que;
      while(r < N && A[i] <= A[r]){
	       que.push(A[r]);
	       ++r;
      }
      while((int)que.size() >= K){
	       vec.push_back(que.top());
	       que.pop();
      }
      ++r;
      l = r;
    }
    if((int)vec.size() < Q) continue;
    sort(vec.begin(), vec.end());
    ans = min(ans, vec[Q-1] - vec[0]);
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 384
#coding; utf-8
import copy
N, k = map(int,input().split())
A = list(map(int,input().split()))
B = [0] * N
A = [0] + A
#B = copy.copy(A)
#k = 10
for j in range(k):
    #print(A)
    n_light = [0] * (N+1)
    for i in range(N):
        d = A[i+1]
        l = i+1-d
        r = i+1+d
        #print(l, r)
        n_light[max(l, 1)] += 1
        if r+1 <= N:# and l != r:
            n_light[r+1] -= 1
        #print(n_light)
    #print(n_light)
    for i in range(1,N):
        n_light[i+1] += n_light[i]
    n_str = [str(i) for i in n_light]
    if len(set(n_light[1:])) == 1 and j > 2:
        #print(n_light)
        break
    #n_str = [str(i) for i in n_light]
    A = n_light
    #print(n_light) 
print(' '.join(n_str[1:]))
    


Measured memory_bytes: 218840
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cctype>
#include <cmath>
#include <cstdint>
#include <cstdio>
#include <cstring>
#include <deque>
#include <fstream>
#include <functional>
#include <iostream>
#include <limits>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <vector>
using namespace std;
using ll = long long;
#define fst first
#define snd second

/* clang-format off */
template <class T, size_t D> struct _vec { using type = vector<typename _vec<T, D - 1>::type>; };
template <class T> struct _vec<T, 0> { using type = T; };
template <class T, size_t D> using vec = typename _vec<T, D>::type;
template <class T> vector<T> make_v(size_t size, const T& init) { return vector<T>(size, init); }
template <class... Ts> auto make_v(size_t size, Ts... rest) { return vector<decltype(make_v(rest...))>(size, make_v(rest...)); }
template <class T> inline void chmin(T &a, const T& b) { if (b < a) a = b; }
template <class T> inline void chmax(T &a, const T& b) { if (b > a) a = b; }
/* clang-format on */

struct item_t {
  int a, b;
};

int main() {
#ifdef DEBUG
  ifstream ifs("in.txt");
  cin.rdbuf(ifs.rdbuf());
#endif
  int N, T;
  while (cin >> N >> T) {
    vector<item_t> items(N);
    for (auto& item : items) cin >> item.a >> item.b;
    sort(items.begin(), items.end(), [&](auto& a, auto& b) {
      if (a.a != b.a) return a.a < b.a;
      return a.b < b.b;
    });
    vector<int> dp(T + 1, -1);
    dp[0] = 0;
    for (auto& item : items) {
      vector<int> ndp = dp;
      for (int t = 0; t < T; t++) {
        if (dp[t] < 0) continue;
        chmax(ndp[min(T, t + item.a)], dp[t] + item.b);
      }
      dp.swap(ndp);
    }
    cout << *max_element(dp.begin(), dp.end()) << endl;
  }
  return 0;
}


Measured memory_bytes: 256
#include <stdio.h>


int main(){

	int n;
	
	scanf("%d", &n);
	
	int numeros[n+1];
	int maior = 0, menor = 1000000000;
	
	
	for (int i = 0; i < n; i++){
		scanf("%d", &numeros[i]);
		if (maior < numeros[i])
			maior = numeros[i];
		if (menor > numeros[i])
			menor = numeros[i];
	}
	
	int subtracao = maior - menor;
	
	printf("%d\n", subtracao); 

	return 0;
}


Measured memory_bytes: 128
import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,random,time,copy,functools
from collections import deque

sys.setrecursionlimit(10**7)
inf = 10**20
mod = 10**9 + 7

DR = [1, -1, 0, 0]
DC = [0, 0, 1, -1]

def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LI_(): return [int(x)-1 for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def I(): return int(sys.stdin.readline())
def F(): return float(sys.stdin.readline())
def S(): return input()

def count_inside(p1, p2, points):
    cnt = 0
    min_x = min(p1[0], p2[0])
    min_y = min(p1[1], p2[1])
    max_x = max(p1[0], p2[0])
    max_y = max(p1[1], p2[1])
    for p in points:
        if min_x <= p[0] <= max_x and min_y <= p[1] <= max_y:
            cnt += 1
    return cnt

def main():
    N, K = LI()
    points = []
    X, Y = [], []
    for i, _ in enumerate(range(N)):
        x, y = LI()
        points.append((x, y))
        X.append((x, i))
        Y.append((y, i))
    X = sorted(X, key=lambda x: x[0])
    Y = sorted(Y, key=lambda x: x[0])
    mapOrder2x = {}
    mapOrder2y = {}

    zaatsu_X = [-1 for _ in range(N)]
    zaatsu_Y = [-1 for _ in range(N)]

    for order, (x, i) in enumerate(X):
        zaatsu_X[i] = order
        mapOrder2x[order] = x

    for order, (y, i) in enumerate(Y):
        zaatsu_Y[i] = order
        mapOrder2y[order] = y

    assert(-1 not in zaatsu_X)
    assert(-1 not in zaatsu_Y)

    G = [[0 for _ in range(N)] for __ in range(N)]
    cumsum = [[0 for _ in range(N+1)] for __ in range(N+1)]

    for x, y in zip(zaatsu_X, zaatsu_Y):
        G[x][y] = 1

    for x in range(N):
        for y in range(N):
            cumsum[x+1][y+1] = cumsum[x+1][y] + cumsum[x][y+1] - cumsum[x][y] + G[x][y]

    def query_cumsum2d(s, r1, r2, c1, c2):
        if c2 < c1:
            c1, c2 = c2, c1
        if r2 < r1:
            r1, r2 = r2, r1
        return s[r2][c2] - s[r2][c1] - s[r1][c2] +s[r1][c1]

    def calc_area(x1, x2, y1, y2, mapx, mapy):
        return abs(mapx[x1] - mapx[x2]) * abs(mapy[y1] - mapy[y2])

    area = inf
    for r1 in range(0, N):
        for r2 in range(r1, N+1):
            for c1 in range(0, N):
                for c2 in range(c1, N+1):
                    if K == query_cumsum2d(cumsum, r1, r2, c1, c2):
                        
                        _area = calc_area(r1, r2-1, c1, c2-1, mapOrder2x, mapOrder2y)
                        area = min(area, _area)
    print(area)
main()



Measured memory_bytes: 71916
#if !defined(__clang__) && defined(__GNUC__)
#include <bits/stdc++.h>
#else
#include <cstdlib>
#include <climits>
#include <iostream>
#include <cstdint>
#include <vector>
#include <string>
#include <complex>
#include <bitset>
#include <queue>
#include <deque>
#include <stack>
#include <utility>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <regex>
#endif //  !defined(__clang__) && defined(__GNUG__)
#include <boost/lexical_cast.hpp>
#include <boost/algorithm/string.hpp>
#include <boost/multi_array.hpp>
#include <boost/optional.hpp>

using namespace std;

std::vector<std::vector<int64_t>>
comb(int n) {
    std::vector<std::vector<int64_t>> v(n + 1, std::vector<int64_t>(n + 1, 0));
    for (size_t i = 0; i < v.size(); i++) {
        v[i][0] = 1;
        v[i][i] = 1;
    }
    for (size_t j = 1; j < v.size(); j++) {
        for (size_t k = 1; k < j; k++) {
            v[j][k] = (v[j - 1][k - 1] + v[j - 1][k]);
        }
    }
    return v;
}

/*
  uint64_t sum = 0;
  combination(inis, 3, [&sum](auto& v) {
  sum += std::accumulate(std::begin(v), std::end(v), 1ULL, [](auto acc, auto nn) {
  return acc*nn;
  });
  });
*/


int main()
{
    int N, A, B;
    std::cin >> N >> A >> B;

    std::vector<int64_t> V;
    for (int i = 0; i < N; ++i) {
        int64_t t;
        std::cin >> t;
        V.push_back(t);
    }

    // 降順
    std::sort(std::begin(V), std::end(V),
              [](const auto& a, const auto& b) {
                  return a > b;
              });

    auto ave = std::accumulate(V.begin(), V.begin()+A, 0LL) / (double)A;
    cout.precision(20);
    std::cout << ave << std::endl;

    const auto va = V[A-1];

    // vaの個数
    auto vaNum = std::count(V.begin(), V.end(), va);

    // 選んだA個のうち、最後の要素vaが含まれる個数
    auto vaSel = std::count(V.begin(), V.begin()+A, va);

    auto c = comb(51);
    int64_t count = 0;

    if (V[0] == V[A - 1]) {
        /*
          Aの部分が全部vaで埋まっている場合:

          vaを、AからBの範囲でとりうる組み合わせを数え上げる
         */

        for (int64_t i = A; i <= std::min(vaNum, (int64_t)B); ++i) {
            count += c[vaNum][i];
        }
    }
    else {
        /*
          全部vaではない場合、なにか別の値を加えると平均値が
          落ちてしまう。

          A個まで入れられなかったのこりのvaが、A個までに
          入る仕方を数え上げる

          -> vaの個数(vaNum)のうち、A個までの枠(vaSel)のうちvaの占める個数の組み合わせ
        */
        count = c[vaNum][vaSel];
    }

    std::cout << count  << std::endl;


    return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<iomanip>
#include<math.h>
#include<complex>
#include<queue>
#include<deque>
#include<stack>
#include<map>
#include<set>
#include<bitset>
#include<functional>
#include<assert.h>
#include<numeric>
using namespace std;
#define REP(i,m,n) for(int i=(int)m ; i < (int) n ; ++i )
#define rep(i,n) REP(i,0,n)
typedef long long ll;
typedef pair<int,int> pint;
typedef pair<ll,int> pli;
const int inf=1e9+7;
const ll longinf=1LL<<60 ;
const ll mod=1e9+7 ;

int main(){
	int a[]={3,1,2,1,0,1,0,1,1,0,1,0,1};
	int x,y;
	cin>>x>>y;
	if(a[x]==a[y])cout<<"Yes"<<endl;
	else cout<<"No"<<endl;
	return 0;
}

Measured memory_bytes: 256
#include<cstdio>
#include<string>
#include<cstring>
#include<utility>
#include<cmath>
#include<map>
#include<queue>
#include<set>
#include<algorithm>
#include<vector>
#include<iostream>
#define ll long long
#define pii pair<int,int>
#define mp make_pair
#define fi first
#define se second
#define inf 0x7fffffff
using namespace std;
const ll mod=1e9+7;
ll dp[110][4][4][4];
bool check(int x,int y,int z,int w)//agct
{
	if((y==0&&z==1&&w==2)||(y==0&&z==2&&w==1)||(y==1&&z==0&&w==2)||(x==0&&z==1&&w==2)||(x==0&&y==1&&w==2))
	{
		return 0;
	}
	return 1;
}
int main()
{
	int i,j,k,n,m,x,y,z;
	scanf("%d",&n);
	for(i=0;i<4;i++)
		for(j=0;j<4;j++)
			for(k=0;k<4;k++)
				if((i==0&&j==1&&k==2)||(i==0&&j==2&&k==1)||(i==1&&j==0&&k==2))
					dp[3][i][j][k]=0;
				else
					dp[3][i][j][k]=1;
	for(i=4;i<=n;i++)
		for(x=0;x<4;x++)
			for(y=0;y<4;y++)
				for(z=0;z<4;z++)
					for(j=0;j<4;j++)
						if(check(x,y,z,j))
						{
							dp[i][y][z][j]+=dp[i-1][x][y][z];
							dp[i][y][z][j]%=mod;
						}
	ll sum=0;
	for(i=0;i<4;i++)
		for(j=0;j<4;j++)
			for(k=0;k<4;k++)
			{
				sum+=dp[n][i][j][k];
				sum%=mod;
			}
	printf("%lld",sum);
	return 0;
}


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

using ll = long long;
using ld = long double;
using pii = pair<int, int>;
using pll = pair<ll, ll>;

#define REP(i, n) for (int i = 0, i##_len = (n); i < i##_len; ++i)
#define all(x) (x).begin(), (x).end()
#define m0(x) memset(x, 0, sizeof(x))

int dx4[4] = {1, 0, -1, 0}, dy4[4] = {0, 1, 0, -1};

int h, w;
vector<string> s;
int dp[110][110];

bool inside(int y, int x)
{
    return 0 <= y && y < h && 0 <= x && x < w;
}

int main()
{
    cin >> h >> w;
    for (int i = 0; i < h; i++)
    {
        string ss;
        cin >> ss;
        s.push_back(ss);
    }
    m0(dp);
    for (int i = 0; i < h; i++)
    {
        for (int j = 0; j < w; j++)
        {
            dp[i][j] = 1e9 + 7;
        }
    }
    if (s[0][0] == '.')
    {
        dp[0][0] = 0;
    }
    else
    {
        dp[0][0] = 1;
    }

    for (int ww = 0; ww < w; ww++)
    {
        for (int hh = 0; hh < h; hh++)
        {
            int befh = hh - 1;
            if (inside(befh, ww))
            {
                if (s[hh][ww] != s[befh][ww])
                {
                    dp[hh][ww] = min(dp[hh][ww], dp[befh][ww] + 1);
                }
                else
                {
                    dp[hh][ww] = min(dp[hh][ww], dp[befh][ww]);
                }
            }
            int befw = ww - 1;
            if (inside(hh, befw))
            {
                if (s[hh][ww] != s[hh][befw])
                {
                    dp[hh][ww] = min(dp[hh][ww], dp[hh][befw] + 1);
                }
                else
                {
                    dp[hh][ww] = min(dp[hh][ww], dp[hh][befw]);
                }
            }
        }
    }
    if(s[h - 1][w - 1]=='#') dp[h - 1][w - 1]++;
    cout << dp[h - 1][w - 1]/2 << endl;

    return 0;
}

Measured memory_bytes: 256
using System;

class Aizu
{
    public static void Main()
    {
        for(int i = 1; i <= 9;i++)
        {
            for(int j = 1; j <= 9;j++)
            {
                Console.WriteLine(i + "x" + j + "=" + i * j);
            }
        }
    }
}


Measured memory_bytes: 15744
#include <bits/stdc++.h>
#define REP(i, n) for(int i = 0; i < n; i++)
#define REPR(i, n) for(int i = n; i >= 0; i--)
#define FOR(i, m, n) for(int i = m; i < n; i++)
#define INF 2e9
#define ALL(v) (v).begin(), (v).end()
using namespace std;
typedef long long ll;

//const int dx[] = {1, 0, -1, 0, 1, -1, -1, 1};
//const int dy[] = {0, 1, 0, -1, 1, 1, -1, -1};

int main()
{
	int n, T;
	cin >> n >> T;
	int c, t;
	int min = INF;
	bool flag = true;

	REP(i, n){
		cin >> c >> t;
		if (t <= T and min > c){
			min = c;
			flag = false;
		}
	}

	if (flag){
		cout << "TLE" << endl;
		return 0;
	}

	cout << min << endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <tuple>

using namespace std;

class Emacs{
  int row, col;
  string buffer;
  vector<string> text;

  bool isFirstLine(){
    return row == 0;
  }

  bool isLastLine(){
    return row == text.size() - 1;
  }

  bool isFirstColumn(){
    return col == 0;
  }

  bool isLastColumn(){
    return col == text.at(row).size();
  }

  string::iterator firstColumn(){
    return text.at(row).begin();
  }

  string::iterator lastColumn(){
    return text.at(row).end();
  }

  void commandA(){
    col = 0;
  }

  void commandE(){
    col = text.at(row).size();
  }

  void commandP(){
    if(!isFirstLine()){
      row--;
    }
    col = 0;
  }

  void commandN(){
    if(!isLastLine()){
      row++;
    }
    col = 0;
  }

  void commandF(){
    if(isLastColumn()){
      commandN();
    }
    else{
      col++;
    }
  }

  void commandB(){
    if(isFirstColumn() && !isFirstLine()){
      row--;
      col = text.at(row).size();
    }
    else{
      col--;
    }
  }

  void commandD(){
    if(isLastColumn() && !isLastLine()){
      text.at(row) += text.at(row + 1);
      text.erase(text.begin() + row + 1);
    }
    else{
      text.at(row).erase(firstColumn() + col);
    }
  }

  void commandK(){
    if(isLastColumn() && !isLastLine()){
      commandD();
      buffer = "\n";
    }
    else{
      buffer = text.at(row).substr(col);
      text.at(row).erase(firstColumn() + col, lastColumn());
      col = text.at(row).size();
    }
  }

  void commandY(){
    if(buffer.empty()){
      return;
    }
    else if(buffer == "\n"){
      text.insert((text.begin() + row + 1), text.at(row).substr(col));
      text.at(row).erase(firstColumn() + col, lastColumn());
      commandN();
    }
    else{
      text.at(row).insert(col, buffer);
      col += buffer.size();
    }
  }

public:
  Emacs(vector<string> str){
    row = 0;
    col = 0;
    buffer = "";
    text = str;
  }

  void applyCommand(char c){
    switch(c){
      case 'a': commandA(); break;
      case 'e': commandE(); break;
      case 'p': commandP(); break;
      case 'n': commandN(); break;
      case 'f': commandF(); break;
      case 'b': commandB(); break;
      case 'd': commandD(); break;
      case 'k': commandK(); break;
      case 'y': commandY(); break;
    }
  }

  void output(){
    for(auto line : text){
      cout << line << endl;
    }
  }
};

int main(){
  vector<string> text;
  vector<char> commands;

  string str;
  while(getline(cin, str) && str != "END_OF_TEXT"){
    text.push_back(str);
  }

  char c;
  while(cin >> c && c != '-'){
    commands.push_back(c);
  }

  Emacs emacs(text);

  for(auto command : commands){
    emacs.applyCommand(command);
  }

  emacs.output();

  return 0;
}



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

int main(){
    int a, b, c;
    cin >> a >> b >> c;
    vector<int> v{ a, b, c };
    sort(v.begin(), v.end());
    cout << (v[0] == 5 && v[1] == 5 && v[2] == 7 ? "YES" : "NO") << "\n";
}

Measured memory_bytes: 256
import sys
import collections
sys.setrecursionlimit(10 ** 8)

def Z(): return int(input())
def ZZ(): return [int(_) for _ in input().split()]

def main():
    N, M = ZZ()
    a = collections.defaultdict(list)
    id = [''] * (M+1)
    for i in range(M):
        p, y = ZZ()
        a[p].append([y, i+1])
    for key in a.keys():
        a[key].sort()
        for j, al in enumerate(a[key], 1):
            y, i = al
            id[i] = '{:0=6}'.format(key) + '{:0=6}'.format(j)
    for i in range(1, M+1): print(id[i])

    return

if __name__ == '__main__':
    main()


Measured memory_bytes: 47952
import sys
import time
import random
import math
from collections import deque
import heapq
import itertools
from decimal import Decimal
import bisect
from operator import itemgetter
MAX_INT = int(10e18)
MIN_INT = -MAX_INT
mod = 1000000000+7
sys.setrecursionlimit(1000000)
def IL(): return list(map(int,input().split()))
def SL(): return input().split()
def I(): return int(sys.stdin.readline())
def S(): return input()

def tami(ans):
  res = 0
  LastDay = [0]*26
  for i in range(D):
    res += s[i][ans[i]]
    for j in range(26):
      if ans[i] == j:
        continue
      res -= (i+1 - LastDay[j]) * c[j]
    LastDay[ans[i]] = i+1
  return res

def nasu():
  res = []
  LastDay = [0]*26
  for d in range(1,D+1):
    tmp = ["", 0]
    for i in range(26):
      if tmp[1] < s[d-1][i] + (d - LastDay[i]) * c[i]:
        tmp = [i, s[d-1][i] + (d - LastDay[i]) * c[i]]
    res.append(tmp[0])
    LastDay[tmp[0]] = d
  return res

def nbo(ans, score, num):
  tmp_ans = ans[:]
  for _ in range(num):
    random_date = random.randint(0,D-1)
    random_val = random.randint(0,25)
    tmp_ans[random_date] = random_val
  scoscore = tami(tmp_ans)
  if scoscore > score:
    return (True, tmp_ans, scoscore)
  else:
    return (False, tmp_ans, scoscore)

start = time.time()
D = I()
c = IL()
s = [IL() for i in range(D)]

ans = nasu()
#print(ans)

score = tami(ans)
#print(score)

end = time.time()
num = 10
while (time.time() - start) < 1.8:
  judge, anans, scoscore = nbo(ans, score, num)
  if judge == True:
    ans, score = anans, scoscore
    #print(ans)
    #print(tami(ans))
for i in ans:
  print(i+1)

Measured memory_bytes: 90892
s = input()
n = [ i for i in s]
ans = 0

import itertools

for i in range(len(n)):
    for j in itertools.combinations(range(len(n)-1), i):
        temp = [i for i in s]
        for k in j[::-1]:
            temp.insert(k+1, "+")
        temp = "".join(temp)
        temp = temp.split("+")
        temp = map(int, temp)
        ans += sum(temp)

print(ans)

Measured memory_bytes: 41564
sol sb sa
    | l == 1        = if sbh == sah then 0 else 1
    | sbh == sah    = 0 + (sol sbt sat)
    | sbh /= sah    = 1 + (sol sbt sat)
    where
        l   = length sa
        sbh = head sb
        sah = head sa
        sbt = tail sb
        sat = tail sa

main=do
    s <- getLine
    let
        n = length s
        sb = take (div n 2) s
        sa = reverse $ drop ((div n 2) + n `mod` 2) s
    print $ if length s /= 1
        then sol sb sa
        else 0


Measured memory_bytes: 508
n = input()    
m = n.split()
p = [int(i) for i in m]
a = []
if p[2] >=10 **9-1:
    b = p[2]-1
else:
    b = p[2]+2
for i in range(p[0]):
    if i < p[1]:
        a.append(str(p[2]))
    else:
        a.append(str(b))
A = " ".join(a)
print(A)

Measured memory_bytes: 13464
#include <bits/stdc++.h>
using namespace std;
/*{{{*/  //template
#define rep(i,n) for(int i=0;i<n;i++)
constexpr int INF = numeric_limits<int>::max()/2;
constexpr long long LINF = numeric_limits<long long>::max()/3;
#define mp make_pair
#define pb push_back
#define eb emplace_back
#define fi first
#define se second
#define all(v) (v).begin(),(v).end()
#define sz(x) (int)(x).size()
#define debug(x) cerr<<#x<<":"<<x<<endl
#define debug2(x,y) cerr<<#x<<","<<#y":"<<x<<","<<y<<endl
//struct fin{ fin(){ cin.tie(0); ios::sync_with_stdio(false); } } fin_;
struct Double{ double d; explicit Double(double x) : d(x){} };
ostream& operator<<(ostream& os,const Double x){ os << fixed << setprecision(20) << x.d; return os; }
template<typename T> ostream& operator<<(ostream& os,const vector<T>& vec){ os << "["; for(const auto& v : vec){ os << v << ","; } os << "]"; return os; }
template<typename T,typename U> ostream& operator<<(ostream& os,const pair<T,U>& p){ os << "(" << p.first << ","<< p.second <<")"; return os; }
template<typename T> ostream& operator<<(ostream& os,const set<T>& st){ os<<"{"; for(T v:st) os<<v<<","; os <<"}"; return os; }
template<typename T,typename U> inline void chmax(T &x,U y){ if(y>x) x = y; }
template<typename T,typename U> inline void chmin(T &x,U y){ if(y<x) x = y; }
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> pii;
typedef vector<int> vi;
typedef vector<vi> vvi;
ll gcd(ll a,ll b){ if(b==0) return a; else return gcd(b,a%b); }
//constexpr double eps = 1e-14; 
constexpr double eps = 1e-10; 
constexpr ll mod = 1e9+7;
const int dx[]={1,0,-1,0} ,dy[] = {0,1,0,-1};
/*}}}*/

namespace Graph{
    int V;
    vector<vector<int>> G;
    vector<int> color;
    bool dfs(int v,int c){
        color[v]=c;
        for(int node:G[v]){
            if(color[node]==c) return false;
            if(color[node]==0 and !dfs(node,-c)) return false;
        }
        return true;
    }
    bool isBipartiteGraph(const vector<vector<int>>& g){
        G=g;
        V=G.size();
        color.assign(V,0);
        for(int i=0;i<V;i++)
            if(color[i]==0 and !dfs(i,1)) return false;
        return true;
    }
    vector<int> getColor(){
        return color;
    }
};

ll N,M;
vector<vector<int>> g;

int main(){
    cin >> N >> M;
    g.resize(N);
    rep(i,M){
        ll a,b;cin>>a>>b;a--;b--;
        g[a].pb(b);
        g[b].pb(a);
    }

    if(Graph::isBipartiteGraph(g)){
        ll w=0,b=0;
        for(int c : Graph::getColor()){
            assert(c!=0);
            if(c == -1) w++;
            else b++;
        }
        ll ans = w * b - M;
        cout << ans << endl;
    }else{
        ll ans = N * (N-1) / 2 - M;
        cout << ans << endl;
    }
}


Measured memory_bytes: 12288
#include <iostream>
#include <cmath>
#include <algorithm>
#include <vector>
#include <string>
#include <unordered_map>
#define rep(i,n) for( int i = 0; i < n; i++)
using namespace std;
using ll = long long;
#define SIZE_OF_ARRAY(array) (sizeof(array)/sizeof(array[0]))
ll u18 = 1000000000000000000;
int main()
{
    
  int n;
  cin >> n;
  int d[n][2];
  int tmp = 0;
  for ( int i = 0; i < n ; i++){
    cin >> d[i][0] >> d[i][1];
  }
  for ( int i = 0; i < n ; i++){
    if( d[i][0] == d[i][1] ){
      tmp ++;
      if( tmp >= 3 ) break;
    }
    else{
      tmp = 0;
    }
  }
  
  if( tmp >= 3 ){
    cout << "Yes" << endl;
  }
  else{
    cout << "No" << endl;
  }
	
   
  return 0;
}


Measured memory_bytes: 3632
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<cmath>
using namespace std;
char s1[101],s2[101];
int main(){
    gets(s1);
    gets(s2);
    int n=strlen(s1);
    int m=strlen(s2);
    sort(s1,s1+n);
    sort(s2,s2+m);
    for(int i=0;i<fmax(n,m);i++){
        if(s1[i]<s2[m-i-1]){
            printf("Yes\n");
            return 0;
        }
        if(s1[i]>s2[m-i-1])
            break;
    }
    printf("No\n");
    return 0;
} 

Measured memory_bytes: 128
#include<stdio.h>
#include<stdlib.h>
#include<algorithm>
using namespace std;
long long ha[100005],total[100005];
int inc(const void *a, const void *b)
{
    if(a<b)return -1;
    else return 1;
}
int main()
{
	long long m,n,l=0,r=200005,fenjie,sum,num,mid,kk,temp;
	//fenjie:二分答案的结果 sum:握手好感总和 num:握手次数 kk: 临界点 temp:区别于fenjie的临时值 
    scanf("%lld%lld",&n,&m);
    ha[0]=9999999;
    for(long long i=1;i<=n;i++)scanf("%lld",&ha[i]);
    sort(ha+1,ha+n+1);
    total[0]=0;
    for(long long i=1;i<=n;i++)total[i]=total[i-1]+ha[i];
    mid=(l+r)/2;
    while(l<=r)
	{
        sum=0;num=0;
        for(long long i=1;i<=n;i++)
		{
            kk=lower_bound(&ha[1],&ha[n+1],mid-ha[i])-&ha[0];
            num+=n-kk+1;
        }
		temp=mid;
        if(num>=m)
		{
            fenjie=mid;
            l=mid+1;
        }
        else
		{
			//fenjie=mid;
			r=mid-1;
		}
        mid=(l+r)/2;
    }
    for(long long i=1;i<=n;i++)
	{
        kk=lower_bound(&ha[1],&ha[n+1],temp-ha[i])-&ha[0];
        sum+=total[n]-total[kk-1];
        sum+=ha[i]*(n-kk+1);
    }
    if(m==num)printf("%lld\n",sum);
    else if(m>num)printf("%lld\n",sum+(m-num)*fenjie);
    else printf("%lld\n",sum-(num-m)*fenjie);
}

Measured memory_bytes: 1792
//#pragma GCC optimize(3)
#pragma comment(linker,"/stack:16777216")
#include<iostream>
#include<cstdio>
#include<string>
#include<vector>
#include<set>
#include<map>
#include<list>
#include<stack>
#include<queue>
#include<deque>
#include<functional>
#include<utility>
#include<algorithm>
#include<sstream>
#include<cstring>
#include<cmath>
#include<cctype>
#include<exception>
#include<climits>
#include<cfloat>
#include<iomanip>
#include<bitset>
#include<streambuf>
#include<cstdlib>
#include<ctime>
//#include"functions.h"
//#include"highprecision.h"
#define pb push_back
#define pf push_front
#define ppb pop_back
#define mp make_pair
#define np next_permutation
#define fi first
#define sc second
#define vi vector<int>
#define vll vector<long long>
#define vvi vector<vector<int> >
#define vpi vector<pair<int,int> >
#define pii pair<int,int>
#define pll pair<long long,long long>
#define pff pair<float,float>
#define pdd pair<double,double>
#define psi pair<string,int>
#define pis pair<int,string>
#define ppi pair<pii,int>
#define pdi pair<pii,pii>
#define LN 84757
#define INF 1e9
#define LLINF 1e18
#define MAXINT 0x7fffffff
#define MAXLL 0x7fffffffffffffff
#define EPS 1e-5
#define DEPS 1e-9
#define LDEPS 1e-13
#define MOD 1000000007
#define E 2.7182818284
#define PI 3.1415926535
#define rep(a,b) for(int a=0;a<b;a++)
#define forn(a,n) for(int a=1;a<=n;a++)
#define forr(a,n) for(int a=n;a>=1;a--)
#define repn(a,n,p) for(int a=0;a<n;a+=p)
#define repr(a,n) for(int a=n-1;a>=0;a--)
#define foreach(a,b) for(__typeof(b.begin())a=b.begin();a!=b.end();a++)
#define fillemp(a) memset(a,0,sizeof(a))
#define fillinf(a) memset(a,0x3f,sizeof(a))
#define frestream freopen("input.txt","r",stdin);freopen("output.txt","w",stdout);
#define stdf(a,b) freopen(a,"r",stdin);freopen(b,"w",stdout);
#define inputf(a) freopen(a,"r",stdin);
#define outputf(a) freopen(a,"w",stdout);
#define sz(a) a.size()
#define all(a) a.begin(),a.end()
#define MOD 1000000007
typedef long long ll;
typedef long double ld;
using namespace std;

int main(){
	int a,b;
	string s,t;
	cin>>a>>b;
	rep(i,b){
		s+=('0'+a);
	}
	rep(i,a){
		t+=('0'+b);
	}
	if(s>t)swap(s,t);
	cout<<s;
	return 0;
}

Measured memory_bytes: 256
# include <iostream>
# include <algorithm>
# include <vector>
# include <string>
# include <set>
# include <map>
# include <cmath>
# include <iomanip>
# include <functional>
# include <utility>
# include <stack>
# include <queue>
# include <list>
# include <tuple>
# include <unordered_map>
# include <numeric>
# include <complex>
# include <bitset>
# include <random>
# include <chrono>
# include <cstdlib>
# include <tuple>
# include <array>
using namespace std;
using LL = long long;
using ULL = unsigned long long;
using D = double;
constexpr int INF = 2147483647;
constexpr int HINF = INF / 2;
constexpr double DINF = 100000000000000000.0;
constexpr double HDINF = 50000000000000000.0;
constexpr long long LINF = 9223372036854775807;
constexpr long long HLINF = 4500000000000000000;
const double PI = acos(-1);
template <typename T_char>T_char TL(T_char cX) { return tolower(cX); };
template <typename T_char>T_char TU(T_char cX) { return toupper(cX); };
typedef pair<LL, LL> pii;
const int vy[] = { -1, -1, -1, 0, 1, 1, 1, 0 }, vx[] = { -1, 0, 1, 1, 1, 0, -1, -1 };
const int dx[4] = { 0,1,0,-1 }, dy[4] = { 1,0,-1,0 };
int popcnt(unsigned long long n) { int cnt = 0; for (int i = 0; i < 64; i++)if ((n >> i) & 1)cnt++; return cnt; }
int d_sum(LL n) { int ret = 0; while (n > 0) { ret += n % 10; n /= 10; }return ret; }
int d_num(LL n) { int ret = 0; while (n > 0) { ret++; n /= 10; }return ret; }
LL gcd(LL a, LL b) { if (b == 0)return a; return gcd(b, a%b); };
LL lcm(LL a, LL b) { LL g = gcd(a, b); return a / g*b; };
# define ALL(qpqpq)           (qpqpq).begin(),(qpqpq).end()
# define RALL(qpqpq)           (qpqpq).rbegin(),(qpqpq).rend()
# define UNIQUE(wpwpw)        sort(ALL((wpwpw)));(wpwpw).erase(unique(ALL((wpwpw))),(wpwpw).end())
# define LOWER(epepe)         transform(ALL((epepe)),(epepe).begin(),TL<char>)
# define UPPER(rprpr)         transform(ALL((rprpr)),(rprpr).begin(),TU<char>)
# define FOR(i,tptpt,ypypy)   for(LL i=(tptpt);i<(ypypy);i++)
# define RFOR(i,tptpt,ypypy)  for(LL i=(tptpt);i>=(ypypy);i--)
# define REP(i,upupu)         FOR(i,0,upupu)
# define INIT                 std::ios::sync_with_stdio(false);std::cin.tie(0)

int n;
int t[101010];
vector<int> v;
int main() {
	cin >> n;
	int maxt = 0;
	REP(i, n) {
		cin >> t[i];
		maxt = max(maxt, t[i]);
	}
	for (int i = 1; i <= maxt; i++) {
		if (maxt % i == 0)v.emplace_back(i);
	}
	int ans = 0;
	REP(i, n) {
		ans += *lower_bound(ALL(v), t[i]) - t[i];
	}
	cout << ans << endl;
}


Measured memory_bytes: 3508
// https://atcoder.jp/contests/abc166/tasks/abc166_d
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define REP(i, n) FOR(i, 0, n)
#define REPR(i, n) for (int i = n - 1; i >= 0; i--)
#define FOR(i, s, n) for (int i = (s), i##_len = (n); i < i##_len; ++i)
#define ALL(obj) (obj).begin(), (obj).end()
#define ALLR(obj) (obj).rbegin(), (obj).rend()
#define DIV(a, b) ((a - 1) / b + 1)

signed main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    int X;
    cin >> X;
    vector<pair<int, int>> v;
    REP(i, 1000) { v.emplace_back(i * i * i * i * i, i); }
    REP(i, 1000) REP(j, 1000) {
        if (v[i].first - v[j].first == X) {
            cout << v[i].second << " " << v[j].second << endl;
            return 0;
        }
        if (v[i].first + v[j].first == X) {
            cout << v[i].second << " -" << v[j].second << endl;
            return 0;
        }
    }

    return 0;
}


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

using namespace std;

using ll = long long;

const ll MOD = 1000000000 + 7;

int main(void){
    ll n, sum;
    ll cnt[60][2] = {};

    cin >> n;

    sum = 0;
    for(ll i=0; i<n ;i++){
        ll num;
        cin >> num;
        ll j=0;
        while(num>0ll){
            if(num%2ll)
                cnt[j][1]++;
            num /= 2ll;
            j++;
        }
    }

    for(ll i=0; i<60; i++){
        cnt[i][0] = n - cnt[i][1];
        ll xor_sum = (cnt[i][0] * cnt[i][1]) % MOD;
        xor_sum = (xor_sum * ((1ll << i) % MOD)) % MOD;
        sum = (sum + xor_sum) % MOD;
    }


    cout << sum << endl;

}

Measured memory_bytes: 256