akhauriyash/Code-Regression huggingface dataset:
#include<iostream>
#include<cstdlib>
#include<string>
using namespace std;

struct node
{
	int key;
	node* lc, * rc, * p;
};

node* root = 0;

void insert(int x)
{
	node* pre = root;        //设当前节点为根，以根为起点
	node* temp = pre;        //用来保存当前节点的临时指针

	node* in = (node*)malloc(sizeof(node));
	in->key = x;
	in->lc = 0;     
	in->rc = 0;     

	while (pre != 0)
	{
		temp = pre;
		if (in->key < pre->key)
			pre = pre->lc;
		else
			pre = pre->rc;
	}
	pre = temp;

	in->p = pre;
	if (pre == 0)
		root = in;
	else
	{
		if (in->key < pre->key)
			pre->lc = in;
		else
			pre->rc = in;
	}
}

void Inorder(node* r)
{
	if (r->lc != 0)
		Inorder(r->lc);

	cout << " " << r->key;

	if (r->rc != 0)
		Inorder(r->rc);
}

void Preorder(node* r)
{
	cout << " " << r->key;

	if (r->lc != 0)
		Preorder(r->lc);
	if (r->rc != 0)
		Preorder(r->rc);
}

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

	int n, x;
	string p;

	cin >> n;
	for (int i = 0; i < n; i++)
	{
		cin >> p;

		if (p == "insert")
		{
			cin >> x;
			insert(x);
		}
		else
		{
			Inorder(root);
			cout << endl;
			Preorder(root);
			cout << endl;
		}
	}

	return 0;
}


Measured memory_bytes: 26564
#include <bits/stdc++.h>
#include <cstdio>
#include <cstring>
#include <cstdlib>

#define FASTIO ios::sync_with_stdio(0); cin.tie(0);
#define show(x) cout << #x << " = " << x << "\n"
#define mem( a , b ) memset( a , b , sizeof a )
#define popcnt(x) __builtin_popcount(x)
#define all(x) x.begin() , x.end()
#define SZ(a) (int)a.size()
#define ll  long long
#define ld  long double
#define vii vector  <ll>
#define dqi deque   <ll>
#define sii set     <ll>
#define vpi vector  <pii>
#define mii map     <ll,ll>
#define pii pair    <ll,ll>
#define pi pair     <int,int>
#define vss vector  <string>
#define pb  push_back
#define F   first
#define S   second
#define L   length()
#define PI  3.141592654
#define OO (ll)1e18
#define mod(x,m) (x%m + m )%m
using namespace std;
void ONLINE__JUDGE();

pii swapii( pii pr ){ return { pr.S , pr.F }; }
int dx[] = {  0 ,  0 , -1 , +1 , -1 , +1 , -1 , +1 };
int dy[] = { -1 , +1 ,  0 ,  0 , -1 , +1 , +1 , -1 };

const ll MOD = 1e9 + 7;
const ll MAX = 2e7 + 9;

ll x,y,z;

int main()
{
    FASTIO //ONLINE__JUDGE();

    cin >> x >> y >> z;
    cout << min( z , x*y );
    return 0;
}


void ONLINE__JUDGE()
{
    #ifndef ONLINE_JUDGE
    freopen( "inp.c"         , "r" , stdin  );
    //freopen( "OutPut.txt"   , "w" , stdout );
    #endif // ONLINE_JUDGE
}



Measured memory_bytes: 256
#include<stdio.h>
#include<string.h>
#include<stdlib.h>
#include<math.h>

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

Measured memory_bytes: 128
#include<bits/stdc++.h>
using namespace std;
using ll=long long;
int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	string s;
	cin>>s;
	ll ans=0;
	vector<ll>rem(2019, 0);
	rem[0]=1;
	ll n=0,ex=1;
	for(ll i=(ll)s.size()-1;i>=0;i--){
		n=(n+(s[i]-'0')*ex)%2019;
		ans+=rem[n];
		rem[n]++;
		ex=ex*10%2019;
	}
	cout<<ans<<"\n";
}

Measured memory_bytes: 3804
n,l = map(int,input().split())
mn = 1000
sums = 0
for i in range(n):
    taste = l+i
    sums += taste
    
for i in range(n):
    taste = l+i
    if mn > abs(taste):
        ans = taste
        mn = abs(taste)
print(sums-ans)

Measured memory_bytes: 38356
#include <iostream>
using namespace std;
int main(){
  int a,b,s;
  char op;
  while (1) {
  cin >> a >> op >> b;
  if (op == '+') s = a + b;
  if (op == '-') s = a - b;
  if (op == '*') s = a * b;
  if (op == '/') s = a / b;
  if (op == '?') break;
  cout << s << endl;
  }
  return 0;
}

Measured memory_bytes: 3084
use std::vec::Vec;
use std::collections::HashMap;

fn read<T: std::str::FromStr>() -> T {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).ok();
    s.trim().parse().ok().unwrap()
}

fn read_vec<T: std::str::FromStr>() -> Vec<T> {
    read::<String>().split_whitespace().map(|e| e.parse().ok().unwrap()).collect()
}

fn read_touple<T: std::str::FromStr + Copy>() -> (T, T) {
  let v: Vec<T> = read_vec();
  assert_eq!(v.len(), 2);
  (v[0], v[1])
}

fn main() {
    let n: usize = read();
    let a: Vec<i64> = read_vec();
    let mut acc = HashMap::<i64, i64>::new();
    let mut ans = 0;
    for i in 0..n {
      let b =  (i as i64 + 1) + a[i];
      let c = (i as i64 + 1) - a[i];
      if let Some(x) = acc.get(&c) {
        ans += x;
      }
     if let Some(x) = acc.get_mut(&b) {
       *x += 1;
     } else {
       acc.insert(b, 1);
     }
    }
    //println!("{:?}", acc);
    println!("{}", ans);
}


Measured memory_bytes: 12304
#include <iostream>
#include <algorithm>
#include <functional>
#include <vector>
#include <string>
#include <array>
#include <cmath>
#include <queue>
#include <stack>
#include <numeric>

using namespace std;

int main() {
	string s,ABC,ARC;
	cin >> s;
	if (s == "ABC")cout << "ARC" << endl;
	else cout << "ABC" << endl;
}

Measured memory_bytes: 3620
#include<cstdio>
#include<cmath>
#include<algorithm>
#include<cstring>
#include<iostream>
#include<cstdlib>
#include<string>
using namespace std;
#define LL long long

const int MaxN = 1e5 + 55;
LL x[MaxN], v[MaxN];
LL a[MaxN], b[MaxN];

int main()
{
	LL n, c;
	cin >> n >> c;
	for(int i = 1; i <= n; i++) 
		cin >> x[i] >> v[i];

	for(LL i = 1; i <= n; i++) {
		a[i] = a[i - 1] + v[i] - (x[i] - x[i - 1]);
	}
		
	x[n + 1] = c;
	for(LL i = n; i >= 1; i--) {
		b[i] = b[i + 1] + v[i] - (x[i+1] - x[i]);
	}

	for(LL i = 2; i <= n; i++) {
		a[i] = max(a[i - 1], a[i]);
	}

	for(LL i = n - 1; i >= 1; i--) 
		b[i] = max(b[i], b[i+1]);
	LL ans = 0;
	for(LL i = 1; i <= n; i++) {
		ans = max(ans, - x[i] + a[i] + b[i+1]);
		ans = max(ans, b[i] - (c - x[i]) + a[i - 1]);
		ans = max(ans, a[i]);
		ans = max(ans, b[i]);
	}
	cout << ans << endl;
}

Measured memory_bytes: 3328
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
using Pair = pair<int, int>;
using Vec = vector<int>;
using Graph = vector<Vec>;
#define INF 1000000007
#define MOD 1000000007

Graph g;
vector<Pair> edge;
map <Pair, int> col;

void	dfs(int node, int color)
{
	int c = 1;
	for (auto it = g[node].begin(); it != g[node].end(); it++)
	{
		if (c == color)
			c++;
		Pair e;
		if (*it < node)
			e = make_pair(*it, node);
		else
			e = make_pair(node, *it);
		if(col.find(e) != col.end())
			continue ;
		col.insert(make_pair(e, c));
		dfs(*it, c);
		c++;
	}
}

int		main(void)
{
	int n;
	cin >> n;
	g = Graph(n);
	edge = vector<Pair>(n-1);
	for (auto it = edge.begin(); it != edge.end(); it++)
	{
		int a, b;
		cin >> a >> b;
		a--;
		b--;
		it->first = a;
		it->second = b;
		g[a].push_back(b);
		g[b].push_back(a);
	}
	int max = 0;
	for (int i = 0; i < n; i++)
	{
		int num_edge = g[i].size();
		if (num_edge > max)
			max = num_edge;
	}
	dfs(0, 0);
	cout << max << endl;
	for (auto it = edge.begin(); it != edge.end(); it++)
	{
		Pair e;
		if (it->first < it->second)
			e = make_pair(it->first, it->second);
		else
			e = make_pair(it->second, it->first);
		cout << col.at(e) << endl;
	}
}


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


int main() {
  int N;
  cin >> N;
  vector<int> even(N);

  //入力を見て何回偶数にできるかチェック

  for (int i=0; i<N; i++){
    int a;
    cin >> a;
    //bitset<100> tmp(a);
    int count = 0;
    
    for (int j=0; j<100; j++){
      if(a % 2 ==0){
        count++;
        a = a / 2; // 右へ1ビットシフト
      }else{
        break;
      }
    }
    even.at(i) = count; // 右シフトの数
  }

  //
  int ans = 100;
  for (int i=0; i<N-1; i++){
    ans = min(ans, even.at(i));
  }

  cout << ans << endl;

}


Measured memory_bytes: 256
N,M=map(int,input().split())
A=list(map(int,input().split()))
weight=[0,2,5,5,4,5,6,3,7,6]
li=[-100]*(N+1)
li[0]=0
for i in range(N+1):
  for a in A:
    if weight[a]+i<=N:
      li[weight[a]+i]=max(li[weight[a]+i],a+10*li[i])
print(li[N])

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

int main(){
  int n,k;
  cin >> n >> k;
  string s;
  cin >> s;
  if(s.at(k-1) == 'A') s.at(k-1)='a';
  else if(s.at(k-1) == 'B') s.at(k-1)='b';
  else s.at(k-1)='c';
  cout << s << endl;
}


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

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

template<class Type>
Type modpow(Type a, Type n, Type mod)
{
	Type res = 1;
	while (0 < n)
	{
		if (n & 1)
		{
			res = res * a % mod;
		}
		a = a * a % mod;
		n >>= 1;
	}
	return res;
}

template<class Type>
Type gcd(Type x, Type y)
{
	Type r;
	if (x < y)
	{
		swap(x, y);
	}

	while (0 < y)
	{
		r = x % y;
		x = y;
		y = r;
	}
	return x;
}

template<class Type>
bool isPrime(Type x)
{
	if (x == 2) return true;
	if (x < 2 || x % 2 == 0) return false;

	for (Type i = 3; i <= sqrt(x); i += 2)
	{
		if (x % i == 0) return false;
	}
	return true;
}

template<class Type>
vector<bool> eratos(Type n)
{
	vector<bool> isPrime(n + 1, true);
	isPrime[0] = isPrime[1] = false;
	for (Type i = 2; i <= n; i++)
	{
		if (isPrime[i])
		{
			Type j = i + i;
			while (j <= n)
			{
				isPrime[j] = false;
				j = j + i;
			}
		}
	}
	return isPrime;
}

bool binarySearchJudge(vector<int> a, int index, int key)
{
	if (key <= a[index]) return true;
	else return false;
}

int binarySearch(vector<int> a, int key)
{
	int ng = -1;
	int ok = a.size();
	while (1 < abs(ng - ok))
	{
		int mid = (ng + ok) / 2;
		if (binarySearchJudge(a, mid, key)) ok = mid;
		else ng = mid;
	}
	return a[ok] == key;
}

double dist(vector<int> x, vector<int> y, int i, int j)
{
	return sqrt(pow(x[i] - x[j], 2) + pow(y[i] - y[j], 2));
}

int main()
{
	int k, x;
	cin >> k >> x;
	if (x <= 500 * k) cout << "Yes" << endl;
	else cout << "No" << endl;
}

Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<vector>
#include<queue>
#include<set>
#include<map>
using namespace std;
#define ll long long
#define pb push_back
#define rep(i,n) for(int i=0; i<n; i++)
#define forp(i,a,b) for(int i=a;i<b;i++)
#define forn(i,a,b) for(int i=a;i>=b;i--)
#define All(x,v) for(auto x:v)
#define arrin(a,n) ll a[n]; rep(i,n) cin>>a[i]
#define vi vector<int>
#define nl "\n"
#define print(arr) All(x,arr) cout<<x<<" "; cout<<nl
#define sz(x) (int)x.size()
#define all(v) v.begin(),v.end()
#define vdsort(v) sort(v.begin(),v.end(),greater<int>())
#define F first
#define S second
#define mod 1000000007
const int MAXN=100001;
int spf[MAXN];
int gcd(int x, int y){ return y?gcd(y,x%y):x; }

void precal(){  
    spf[1] = 1; 
    for (int i=2; i<MAXN; i++)  spf[i] = i; 
    for (int i=4; i<MAXN; i+=2) spf[i] = 2; 
    for (int i=3; i*i<MAXN; i++) { 
        if (spf[i] == i) 
            for (int j=i*i; j<MAXN; j+=i) 
                if (spf[j]==j)  spf[j] = i; 
    } 
} 
vector<int> getFactorization(int x){
    vector<int> ret; 
    while (x != 1) { 
        ret.push_back(spf[x]); 
        x = x / spf[x]; 
    } 
    return ret; 
}

ll exp(ll n, ll m){
    ll a = 1;
    while (m){
        if (m & 1) a = (a * n % mod) % mod;
        m /= 2;
        n = (n*n) % mod;
    }
    return a;
}

int main()
{
    ios::sync_with_stdio(0);
    cin.tie(0); cout.tie(0);
    // freopen("input.txt","r",stdin); freopen("output.txt","w",stdout);
    int n,t=1;
    // cin>>t;
    while(t--){
        cin>>n;
        cout<<(n%1000==0? 0:1000-n%1000)<<nl;

    }
    return 0;
}

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

int main(){
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  int h, a;
  cin >> h >> a;
  (h % a == 0) ? cout << h / a : cout << h / a + 1;
  cout << "\n";
return 0;
}


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

inf = 1000000000
DP = [inf for _ in range(1000000)]
DP[0] = 0

for i in range(N):
    DP[i+1] = min(DP[i+1],DP[i]+1)
    j = 1
    while 6**j < 100000:
        DP[i+6**j] = min(DP[i+6**j],DP[i]+1)
        j += 1
    j = 1
    while 9**j < 100000:
        DP[i+9**j] = min(DP[i+9**j],DP[i]+1)
        j += 1
print(DP[N])

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

#define rep2(x,fr,to) for(int (x)=(fr);(x)<(to);(x)++)
#define rep(x,to) for(int (x)=0;(x)<(to);(x)++)
#define repr(x,fr,to) for(int (x)=(fr);(x)>=(to);(x)--)
#define all(c) (c).begin(),(c).end()
#define sz(v) (int)(v).size()

using namespace std;
typedef long long ll; typedef vector<int> VI; typedef pair<int,int> pii;
const int mod = (int)1e9 + 7;
void dbg(){ cerr << "\n"; }  template <typename T,typename ...T2> void dbg(const T& fst, const T2&...rst){ cerr << fst << ": "; dbg(rst...); }




int main()
{
	
	//cin.tie(0); ios_base::sync_with_stdio(false);
	string s;
	cin >> s;
	
	int ans = 1<<28;
	rep(i, sz(s)-2){
		int cr = stoi(s.substr(i,3));
		ans = min(ans, abs(753 - cr));
	}
	cout << ans <<"\n";
	return 0;
}


Measured memory_bytes: 256
## for use in beginner level questions where speed is key
## and also for single test case code
## mastercopy for x,y,z

import sys
import heapq, functools, collections
import random
from collections import Counter, defaultdict

# read line as a string
# strr = input()

# read line as an integer
# k = int(input())

# read one line and parse each word as a string
# lst = input().split()

# read one line and parse each word as an integer
a,b,c,d = list(map(int,input().split()))

if a <= 0 <= b:
    xx = [a,0,b] 
else:
    xx = [a,b]

if c <= 0 <= d:
    yy = [c,0,d]
else:
    yy = [c,d]

maxres = -10**18
for x in xx:
    for y in yy:
        maxres = max(maxres, x*y)

print(maxres)


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

int main(){
  int n, a[109];
  cin >> n;
  for(int i = 0; i < n; i++) cin >> a[i];
  sort(a, a + n, greater<int>());
  int Alice = 0, Bob = 0;
  for(int i = 0; i < n; i++){
    if(i % 2 == 0){
      Alice += a[i];
    } else{
      Bob += a[i];
    }
  }
  cout << Alice - Bob << endl;
  return 0;
}

Measured memory_bytes: 3612
import java.util.Scanner;

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

        int N = Integer.parseInt(scanner.next());
        int M = Integer.parseInt(scanner.next());
        int K = Integer.parseInt(scanner.next());

        if (K % N == 0 || K % M == 0) {
            System.out.println("Yes");
            return;
        }
        
        if (K < N || K < M) {
            System.out.println("No");
            return;
        }


        for (int n = 0; n <= N; n++) {
            for (int m = 0; m <= M; m++) {
                int sum = n * m + (N - n) * (M - m);
                if (sum == K) {
                    System.out.println("Yes");
                    return;
                }
            }
        }

        System.out.println("No");

    }
}


Measured memory_bytes: 21716
#include <bits/stdc++.h> 
using namespace std;
#define pb push_back
#define ll long long int
#define vi vector<int>
#define ii pair<int,int>
#define vli vector<ll>
#define graph vector<vector< int > >
#define vpi vector<pair<int ,int> >
#define vpli vector<pair<ll ,ll> >
#define mp make_pair
#define F first
#define S second
#define mod 163577857
#define INF (ll)1e10
#define wh(a) cout<<#a<<"  is  "<<a<<endl;
#define MIN(a,b) ((a) < (b) ? (a) : (b))
#define MAX(a,b) ((a) > (b) ? (a) : (b))
#define INI(a) memset(a,0,sizeof(a))
#define LIMIT 8008

void solve(){
    string s,t;
    cin>>s>>t;
    for(int i=0;i<(int)s.size();++i){
        if(s[i]==t[i]){
            continue;
        }
        cout<<"No";
        return;
    }
    cout<<"Yes";
    return;
}

int main(){
    ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
    #ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    #endif
    int t=1;
    // cin>>t;
    while(t--){
        solve();
    }
    return 0;
}

Measured memory_bytes: 3612
#include<bits/stdc++.h>
// Begin Header {{{
using namespace std;
using ll = long long;
using P = pair<ll, ll>;
using Graph = vector<vector<ll>>;
#define rep(i,n) for(ll i=0; i<n; i++)
#define loop(i, j, n) for(ll i=j; i<n; i++)
#define all(x) (x).begin(), (x).end()
constexpr int INF  = 0x3f3f3f3f;
const long long mod=1e9+7;
const long double PI = acos(-1);
// }}} End Header

int main() {
	ll n, sum=0;
	cin >> n;
	vector<ll> a(n);
	rep(i,n) cin >> a[i];
	sort(all(a), greater<int>());
	sum += a[0];
	ll cnt = n-2;
	loop(i, 1, n){
		if(cnt == 0) break; 
		sum+=a[i]; cnt--;
		if(cnt == 0) break;
		sum+=a[i]; cnt--;
	}
	cout << sum << endl;
	return 0;
}

Measured memory_bytes: 4780
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int k = sc.nextInt();
        boolean[] sunuke = new boolean[n];
        for (int i=0;i<k;i++){
            int d = sc.nextInt();
            for (int j=0;j<d;j++){
                sunuke[sc.nextInt()-1]=true;
            }
        }
        int ans = 0;
        for (int i=0;i<n;i++)if (!sunuke[i])ans++;
        System.out.println(ans);
    }
}


Measured memory_bytes: 46068
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define ios()                \
    ios::sync_with_stdio(0); \
    cin.tie(0);              \
    cout.tie(0)


signed main()
{
    ios();
    int N, L;
    cin >> N >> L;
    int sum = N * (L - 1) + N * (N+ 1) / 2;

    int min = 1e9;
    int min_num = 0;
    for (int i = 0; i < N; i++) {
        int tmp = L + i;
        if (abs(tmp) < min) min = abs(tmp),min_num = tmp;
    }

    cout << sum - min_num << endl;
}

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

using lint = long long int;
using pint = pair<int, int>;
using plint = pair<lint, lint>;
#define ALL(x) (x).begin(), (x).end()
#define SZ(x) ((lint)(x).size())
#define POW2(n) (1LL << (n))
#define FOR(i, begin, end) for (int i = (begin), i##_end_ = (end); i < i##_end_; i++)
#define IFOR(i, begin, end) for (int i = (end)-1, i##_begin_ = (begin); i >= i##_begin_; i--)
#define REP(i, n) FOR(i, 0, n)
#define IREP(i, n) IFOR(i, 0, n)

int main()
{
    int n,m;
    cin >> n>>m;
    vector<int> a(m),b(m);
    vector<vector<int>> e(n+1); //v(n, vector<lint>);
    REP(i, m) {
        cin >> a[i]>>b[i];
        int a1=a[i], b1=b[i];
        //cin >> a >> b;
        e[a1].push_back(b1);
        e[b1].push_back(a1);
    }
    int ans=0;
    //すべての辺を一回削除して見てみる
    REP(i,m){
        
    queue<int> q;
    q.push(1);
    vector<int> seen(n+1);
    seen[1] = 1;
    int count = 0;
    while(!q.empty()){
        int next=q.front();
        q.pop();
        count++;
        for (auto next_v : e[next])
        {
            if (seen[next_v] == 0 && !((next == a[i] && next_v == b[i])||(next == b[i] && next_v == a[i])))
            {
                q.push(next_v);
                seen[next_v] = 1;
            }
        }
    }

    //cout << count << "\n";
    if (count<n)
        ans++;
    }

    REP(i,n+1){
        for(auto next_v : e[i]){
            //cout << next_v;
        }
        //cout <<  "\n";
    }

   cout << ans <<"\n";

    return 0;
}

Measured memory_bytes: 256
'use strict';

class Node {
  constructor(key) {
    this.key = key;
    this.next = null;
    this.prev = null;
  }
}

class List {
  constructor() {
    this.nil = new Node();
    this.nil.next = this.nil;
    this.nil.prev = this.nil;
  }

  deleteFirst() {
    this.deleteNode(this.nil.next);
  }

  deleteKey(key) {
    this.deleteNode(this.listSearch(key));
  }

  deleteLast() {
    this.deleteNode(this.nil.prev);
  }

  deleteNode(node) {
    if (node === this.nil) {
      return;
    }
    node.prev.next = node.next;
    node.next.prev = node.prev;
  }

  insert(key) {
    const node = new Node(key);
    node.next = this.nil.next;
    this.nil.next.prev = node;
    this.nil.next = node;
    node.prev = this.nil;
  }

  listSearch(key) {
    // let node = this.nil;
    // while (node.next !== this.nil && node.key !== key) {
    let curr = this.nil.next;
    while (curr !== this.nil && curr.key !== key) {
      curr = curr.next;
    }
    return curr;
  }

  toArray() {
    let curr = this.nil.next;
    const arr = [];
    while (curr !== this.nil) {
      arr.push(curr.key);
      curr = curr.next;
    }
    return arr;
  }
}

const main = input => {
  input = input.split('\n');
  input.shift();
  const list = new List();
  input.forEach(v => {
    const tmp = v.split(' ');
    const command = tmp[0];
    const key = tmp[1];
    switch (command) {
      case 'insert':
        list.insert(key);
        break;
      case 'delete':
        list.deleteKey(key);
        break;
      case 'deleteFirst':
        list.deleteFirst();
        break;
      case 'deleteLast':
        list.deleteLast();
        break;
    }
  });

  console.log(list.toArray().join(' '));
};

main(require('fs').readFileSync('/dev/stdin', 'utf8'));

// function myInsert(x, arr) {
//   arr.unshift(x);
//   return arr;
// }
// function myDelete(x, arr) {
//   const i = arr.findIndex(v => v === x);
//   if (i > -1) {
//     arr.splice(i, 1);
//   }
//   return arr;
// }
// function myDeleteFirst(arr) {
//   arr.shift();
//   return arr;
// }
// function myDeleteLast(arr) {
//   arr.pop();
//   return arr;
// }



Measured memory_bytes: 271088
#include <bits/stdc++.h>
using namespace std;
#define fi first
#define se second
#define countof(array) (sizeof(array) / sizeof(array[0]))
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define rrep(i,n) for(int i = (n)-1; i >= 0; --i)
#define srep(i,n,s) for(int i = s; i < (n); ++i)
#define rsrep(i,n,s) for(int i = (n)-1; i >= s; --i)
#define all(a) (a).begin(),(a).end()
#define rall(a) (a).rbegin(),(a).rend()
#define aall(a) (a), (a)+countof(a)//for array sorting
#define raall(a) (a), (a)+countof(a), greater<>()
#define show(x) cout<<#x<<" = "<<x<<endl;
#define vfind(v, a) find(all(v), a) != v.end()
#define yn(f) { if (f) puts("YES"); else puts("NO"); }
#define yns(f) { if (f) puts("Yes"); else puts("No"); }
#define show_ary(...) { cout<<#__VA_ARGS__<<" = "; for (const auto& x : (__VA_ARGS__)) { cout<<x<<" "; } cout<<endl; }
#define show_pair(...) cout<<#__VA_ARGS__<<" = "<<endl; for (const auto& x : (__VA_ARGS__)) { cout<<"  "<<x.fi<<" : "<<x.se<<endl; }
#define out_ary(...) { for (const auto& x : (__VA_ARGS__)) { cout<<x<<" "; } cout<<endl; }
#define argmax(v) distance((v).begin(), max_element(all(v)))
#define argmin(v) distance((v).begin(), min_element(all(v)))
#define vmax(v) *max_element(all(v))
#define vmin(v) *min_element(all(v))
typedef long long int ll;
typedef pair<int, int> P;
typedef vector<P> vpair;
typedef vector<int> vint;
typedef vector<ll> vll;
typedef vector<double> vdouble;
typedef vector<string> vstr;
typedef vector<bool> vbool;
typedef vector<vint> vvint;
typedef vector<vll> vvll;
typedef vector<vstr> vvstr;
typedef vector<vbool> vvbool;
const ll LINF = 2000000000000000000ll;
const int INF = 1000000100;
const ll MOD = 1e9+7;


int N, A, B, C;
vint l;
int ans = INF;

void dfs(int idx, int a, int b, int c, int comb) {
    if (idx == N) {
        if (a && b && c) {
            int mp = abs(A-a) + abs(B-b) + abs(C-c) + comb*10;
            ans = min(ans, mp);
        } 
        return;
    }
    dfs(idx+1, a, b, c, comb);
    dfs(idx+1, a+l[idx], b, c, (a ? comb+1 : comb));
    dfs(idx+1, a, b+l[idx], c, (b ? comb+1 : comb));
    dfs(idx+1, a, b, c+l[idx], (c ? comb+1 : comb));
}

int main() {
    cin >> N >> A >> B >> C;
    l.resize(N);
    rep(i, N) cin >> l[i];
    
    dfs(0, 0, 0, 0, 0);

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

Measured memory_bytes: 256
#define _USE_MATH_DEFINES
#define INF 0x3f3f3f3f

#include <iostream>
#include <cstdio>
#include <sstream>
#include <cmath>
#include <cstdlib>
#include <algorithm>
#include <queue>
#include <stack>
#include <limits>
#include <map>
#include <string>
#include <cstring>
#include <set>
#include <deque>
#include <bitset>
#include <list>
#include <cctype>
#include <utility>
  
using namespace std;
  
typedef long long ll;
typedef pair <ll,ll> P;
typedef pair <int,P> PP;
  
static const double EPS = 1e-8;
  
static const int tx[] = {0,1,0,-1};
static const int ty[] = {-1,0,1,0};

ll fast_pow(ll x, ll n) {
  ll res = 1;
  while(n > 0) {
    if (n & 1) res = res * x;
    x = x * x;
    n >>= 1;
  }
  return res;
}

ll GCD(ll a ,ll b){
  return b > 0 ? GCD(b,a%b) : a;
}

P compute_dir(ll lhs_numerator,ll lhs_denominator,
              ll rhs_numerator,ll rhs_denominator){

  ll numerator = lhs_numerator * rhs_denominator + rhs_numerator * lhs_denominator;
  ll denominator = lhs_denominator * rhs_denominator;
  ll div = GCD(numerator,denominator);
  return P(numerator / div,denominator / div);

}

int main(){
  string str;
  while(cin >> str){
    if(str == "#") break;

    int west_count = 0;
    int north_count = 0;
    ll numerator = -1;
    ll denominator = -1;
    for(int i = str.size() -1; i >= 0; i--){
      if(str[i] == 'n'){
        if(numerator == -1){
          numerator = 0;
          denominator = 1;
        }
        else{
          P next = compute_dir(numerator,denominator,
                               -90,fast_pow(2,north_count + west_count));
          numerator = next.first;
          denominator = next.second;
        }
        north_count++;
      }
      else if(str[i] == 'w'){
        if(numerator == -1){
          numerator = 90;
          denominator = 1;
        }
        else{
          P next = compute_dir(numerator,denominator,
                               90,fast_pow(2,north_count + west_count));
          numerator = next.first;
          denominator = next.second;
        }
        west_count++;
      }
    }

    if(denominator <= 1){
      printf("%lld\n",numerator);
    }
    else{
      printf("%lld/%lld\n",numerator,denominator);
    }
  }
}

Measured memory_bytes: 1196
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <numeric>
using namespace std;

int main() {
    int n, l, r;
    int ans = 0;
    vector<int> w;
    vector<int> x;

    cin >> n;

    for (int i=0; i<n; i++) {
        int ww;
        cin >> ww;
        w.push_back(ww);
    }

    for (int i=0; i<n; i++) {
        l = accumulate (w.begin(), w.begin()+size_t(i), 0);
        r = accumulate (w.begin()+size_t(i), w.end(), 0);
        x.push_back(l-r>0 ? l-r : r-l);
        //cout << w[i] << l << r << endl;
    }

    ans = *min_element(x.begin(), x.end());
    cout << ans << endl;
}

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

using namespace std;

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

typedef long long ll;


int cnt[30][55][55];
int cnt2[30][55][55];
int val[30];

int getcnt(int a,int b,int c,int d,int e,int cnt[30][55][55]){
	int ret = cnt[e][c][d];
	if(c) ret-=cnt[e][a-1][d];
	if(d) ret-=cnt[e][c][b-1];
	if(c&&d) ret+=cnt[e][a-1][b-1];
	return ret;
}


int main(){
	int n;
	cin>>n;
	rep(o,n){
		int h,w;
		cin>>h>>w;
		vector<string> v(h);
		rep(i,h) cin>>v[i];
		bool update = true;
		bool ok=true;
		int ch[30];
		while(update){
			ok=true;
			update=false;
			rep(i,h) rep(j,w) if(v[i][j]!='.'&&v[i][j]!='-') ok=false;
			if(ok){
				break;
			}
			rep(i,30) rep(j,55) rep(k,55) cnt[i][j][k]=cnt2[i][j][k]=0;
			rep(i,30){
				ch[i]=0;
				rep(j,h){
					rep(k,w){
						if(v[j][k]==char('A'+i)||v[j][k]=='-'){
							cnt[i][j][k]=1;
							if(v[j][k]==char('A'+i)){
								ch[i]++;
								cnt2[i][j][k]=1;
							}
						}
						if(j) cnt[i][j][k]+=cnt[i][j-1][k];
						if(k) cnt[i][j][k]+=cnt[i][j][k-1];
						if(j&&k) cnt[i][j][k]-=cnt[i][j-1][k-1];

						if(j) cnt2[i][j][k]+=cnt2[i][j-1][k];
						if(k) cnt2[i][j][k]+=cnt2[i][j][k-1];
						if(j&&k) cnt2[i][j][k]-=cnt2[i][j-1][k-1];
					}
				}
			}
			// rep(i,h){
			// 	cout<<v[i]<<endl;
			// }
			// cout<<endl;
			rep(i,30){
				if(!ch[i]) continue;
				rep(y1,h){
					rep(x1,w){
						reep(y2,y1,h){
							reep(x2,x1,w){
								if(getcnt(y1,x1,y2,x2,i,cnt2)==ch[i]&&getcnt(y1,x1,y2,x2,i,cnt)==(y2-y1+1)*(x2-x1+1)){
									// cout<<"AAA"<<endl;
									// cout<<y1<<" "<<x1<<" "<<y2<<" "<<x2<<" "<<char(i+'A')<<" "<<getcnt(y1,x1,y2,x2,i)<<endl;
									update=true;
									reep(j,y1,y2+1){
										reep(k,x1,x2+1){
											v[j][k]='-';
										}
									}
									// goto end;
								}
							}
						}
					}
				}
		// end:
			// update=update;
			}
		}
		if(ok) cout<<"SAFE"<<endl;
		else cout<<"SUSPICIOUS"<<endl;
	}
}

Measured memory_bytes: 3776
import java.lang.*;
import java.io.*;
import java.util.*;

class Main{
	public static void main(String args[]) throws FileNotFoundException{
		Scanner sc=new Scanner(System.in);
		String buf;
		buf=sc.nextLine();
		String[] sbuf=buf.split("");
		
		int a=0;
		for(int i=0; i<sbuf.length; i++){
			if(sbuf[i].equals("+")){
				a+=1;
			}else{
				a-=1;
			}
		}
		
		System.out.println(a);

	}

	static void disp(long[] data){
		for(int i=0; i<data.length; i++){
				System.out.printf("%d ",data[i]);
		}
			System.out.println();
	}
}


Measured memory_bytes: 23636
use std::io::prelude::*;

fn input<T>() -> T
where
    T: std::str::FromStr,
{
    let stdin = std::io::stdin();
    let token: String = stdin
        .lock()
        .bytes()
        .map(|c| c.unwrap() as char)
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect();
    token.parse().ok().unwrap()
}

fn main() {
    let m: i64 = input();
    println!("{}", 48 - m);
}


Measured memory_bytes: 4352
s = gets.chomp.codepoints
k = gets.to_i
a = "a".ord
z = "z".ord
s.size.times{|i|
  break if k.zero?
  if s[i] != a
    t = (z - s[i]).succ
    if t <= k
      k -= t 
      s[i] = 97
    end
  end
}
k = k % 26
s[-1] = s[-1] + k

puts s.map(&:chr).join



Measured memory_bytes: 7676
#include<iostream>
#include<cstdio>
#include<stack>
#include<queue>
#include<algorithm>
#include<string>
#include<set>
#include<map>
#include<vector>
#include<math.h>
#include<tuple>
#include<string.h>
#include <numeric> 
#include<unordered_map>
using namespace std; 
#define sim template < class c
#define ris return * this
#define dor > debug & operator <<
#define eni(x) sim > typename \
  enable_if<sizeof dud<c>(0) x 1, debug&>::type operator<<(c i) {
sim > struct rge { c b, e; };
sim > rge<c> range(c i, c j) { return rge<c>{i, j}; }
sim > auto dud(c* x) -> decltype(cerr << *x, 0);
sim > char dud(...);
struct debug {
#ifdef LOCAL
~debug() { cerr << endl; }
eni(!=) cerr << boolalpha << i; ris; }
eni(==) ris << range(begin(i), end(i)); }
sim, class b dor(pair < b, c > d) {
  ris << "(" << d.first << ", " << d.second << ")";
}
sim dor(rge<c> d) {
  *this << "[";
  for (auto it = d.b; it != d.e; ++it)
    *this << ", " + 2 * (it == d.b) << *it;
  ris << "]";
}
#else
sim dor(const c&) { ris; }
#endif
};
#define pp(...) "\033[94m [" << #__VA_ARGS__ ": " << (__VA_ARGS__) << "]\033[0m"
#define pp1(...) "\033[1;47;35m" << #__VA_ARGS__ ": " << (__VA_ARGS__) << "]\033[0m"
#define dg(x) debug() << pp1(x)
#define dg1(x) debug() << pp(x)
#define dg2(x,y) debug() << pp(x) pp(y)
#define dg3(x,y,z) debug() << pp(x) pp(y) pp(z)
#define dg4(w,x,y,z) debug() << pp(w) pp(x) pp(y) pp(z)
#define int long long
#define all(x) x.begin() , x.end()
#define clr(x) memset(x , 0 , sizeof x);
#define sz(x) (int)x.size()
template<typename T> void db(T x ){ debug() <<">>> " <<  x; }
template<typename T> void db(T x , T y){ debug() <<">>> " <<  x <<" , "<< y; }
template<typename T> void db(T x , T y , T z){ debug() <<">>> "<< x <<" , "<< y <<" , "<< z; }
template<typename T> void db(T x , T y , T z , T a){ debug() <<">>> "<< x <<" , " << y <<" , "<< z <<" , "<< a; }
const int xx = 2e5;
const int Mod = 1e9 + 7;
const int inf = 1e18;
const int Maxn = 20010;

vector<int> fac, facInv, inv;
void facInit(int nmax)
{
    fac = facInv = inv = vector<int>(nmax + 1, 1);
    for (int i = 2; i <= nmax; i++)
    {
        fac[i] = fac[i-1] * i % Mod;
        inv[i] = Mod - inv[Mod%i] * (Mod/i) % Mod;
        facInv[i] = facInv[i-1] * inv[i] % Mod;
    }
}

int mul(int a , int b , int c) {
  return ( ((a * b ) % Mod) * c % Mod) % Mod;
}
int C(int n , int r) {
   return mul(fac[n] , facInv[r], facInv[n - r]);
}
int P(int n , int r) {
  return (fac[n] * facInv[n - r]) % Mod;
}
signed main(){
  ios::sync_with_stdio(false);cin.tie(0);

  int N, M;
  cin >> N >> M;
  facInit(M + 1);
  int ans = 0;
  int cur = 1;
  for(int i = 0; i <= N; i++) {
    ans += mul(cur , C(N , i) , P(M - i , N - i));
    ans = ans % Mod;
    cur = cur * -1;
    ans = (ans + Mod) % Mod;
  }
  dg1(ans);
  ans = (ans * P(M , N) ) % Mod;
  cout << ans << '\n';
}

Measured memory_bytes: 14308
#include <iostream>
#include <iomanip>
#include <string>
#include <vector>
#include <queue>
#include <algorithm>
#include <utility>
#include <cmath>
#include <map>
#include <set>
#include <stack>
#include <cstdio>
#include <cstdlib>
#include <cstring>

#define INF_LL 1e18
#define INF 1e9

#define REP(i, n) for(int i = 0;i < (n);i++)
#define FOR(i, a, b) for(int i = (a);i < (b);i++)
#define all(x) x.begin(),x.end()

using namespace std;

using ll = long long;
using PII = pair<int, int>;

template<typename T>
void chmax(T &a, T &b){
	a = max(a, b);
}

template<typename T>
void chmin(T &a, T &b){
	a = min(a, b);
}

class Union_find{
private:
	vector<int> par;
	vector<int> rank;
	int n;

public:
	Union_find(int a){
		n = a;
		for(int i = 0;i < n;i++){
			par.push_back(i);
			rank.push_back(0);
		}
	}

	int find(int x){
		if(par[x] == x){
			return x;
		}else{
			return par[x] = find(par[x]);
		}
	}

	void unite(int x, int y){
		x = find(x);
		y = find(y);
		if(x == y) return;

		if(rank[x] < rank[y]){
			par[x] = y;
		}else{
			par[y] = x;
			if(rank[x] == rank[y]) rank[x]++;
		}
	}

	bool same(int x, int y){
		return find(x) == find(y);
	}
};

const ll mod = 1e9+7;

int main(void){
	int N;
	int x[114514];
	stack<int> s;
	ll res = 1;
	cin >> N;
	REP(i, N){
		cin >> x[i];
	}
	REP(i, N){
		s.push(x[i]);
		if(x[i] < 2*s.size()-1){
			res = (res*s.size())%mod;
			s.pop();
		}
	}
	REP(i, s.size()){
		res = (res*(i+1))%mod;
	}
	cout << res << endl;
}


Measured memory_bytes: 1024
n, x = map(int, input().split())
a = list(map(int, input().split()))
a.sort()
if sum(a) == x:
    print(n)
    exit()
if sum(a) < x:
    print(n-1)
    exit()
i = n
while sum(a[:i]) > x:
    i -= 1
print(i)

Measured memory_bytes: 9188
#define _CRT_SECURE_NO_WARNINGS

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

typedef unsigned int uint;
typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;
typedef pair<int, int> ii;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<string> vs;
typedef vector<ii> vii;
typedef vector<vi> vvi;
typedef map<int, int> mii;
typedef pair<int, ii> edge;


#define sc(x)  scanf("%d",&x)
#define scl(x) scanf("%lld",&x)
#define all(v) v.begin(),v.end()
#define rall(v) v.rbegin(),v.rend()
#define mem(arr,val) memset(arr,val,sizeof arr)
#define sz(v) (int)v.size()
#define rsz(v) v.resize
#define clr(v) v.clear()
#define rev(v) reverse(all(v))
#define lop(i,end) for(int i=0; i<end; i++)
#define rlop(i,start) for(int i=start-1; i>=0; i--)
#define loop(i,start,end) for(int i=start; i<end; i++)
#define rloop(i,start,end) for(int i=start-1; i>=end; i--)
#define PB push_back
#define pb pop_back
#define mP make_pair
#define f first
#define s second

const ll OO = (ll)(4e18) + 9;
const int MOD = (int)(1e9) + 7;
const int oo = 2147483647;
const double EPS = 1e-8;
const double PI = acos(-1.0);

//enum dir { D, R, U, L , dr, ur, dl, ul };
int dx[] = { 1, 0, -1, 0, 1, -1, 1, -1 };
int dy[] = { 0, 1, 0, -1, 1, 1, -1, -1 };

string abc = "abcdefghijklmnopqrstuvwxyz";
string vowels = "aeiouy"; //and sometimes "aeiouy"

template<typename X, typename Y> bool ckmin(X& a, Y b) { return a > b ? a = b, true : false; }
template<typename X, typename Y> bool ckmax(X& a, Y b) { return a < b ? a = b, true : false; }
bool cklex(string &a, string b) {
	if (b == "") return false;
	if (a == "") return a = b, true;
	if (sz(a) < sz(b)) return false;
	if (sz(b) < sz(a)) return a = b, true;
	if (a < b) return false;
	return a = b, true;
}

int dcmp(ld d1, ld d2) { return fabs(d1 - d2) <= EPS ? 0 : d1 > d2 ? 1 : -1; } //Compare Double Numbers
ll gcd(ll x, ll y) { return !y ? x : gcd(y, x%y); }
ll lcm(ll a, ll b) { return a * (b / gcd(a, b)); }
int conv_2_1(int r, int c, int nCol) { return (nCol*r) + c + 1; } //convert index from 2D array to 1D array. (Zero-indexed)
ii conv_1_2(int n, int nCol) { return{ n / nCol, n % nCol }; } //convert index from 1D array to 2D array (row, col). (Zero-indexed)
template<typename T> void inter(T X) { cout << X << endl; fflush(stdout); }



int main()
{
	//freopen("in.txt", "r", stdin);
	//freopen("out.txt", "w", stdout);
	ios_base::sync_with_stdio(false); cin.tie(NULL);

	int t = 1;
	//cin >> t;
	while (t--) {
		int l, r, d;
		cin >> l >> r >> d;
		cout << r / d - l / d + (l%d ? 0 : 1)<< endl;
	}


	return 0;
}


Measured memory_bytes: 3640
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
int main(){
  ll n,a;
  cin >>n;
  ll x[5];
  for(ll i=0;i<5;i++) cin >>x[i];
  sort(x,x+5);
  ll p=x[0];
  cout <<((n+(p-1))/p)+4<<endl;
}


Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<string>
#include<set>
#include<vector>
#include<algorithm>
#define int long long
using namespace std;

int dp[51][2501]{};
signed main() {
	dp[0][0] = 1;
	int a, b; cin >> a >> b;
	for (int c = 0; c < a; c++) {
		int d; scanf("%lld", &d);
		for (int e = 49; e >= 0; e--) {
			for (int f = d; f <= 2500; f++) {
				dp[e + 1][f] += dp[e][f - d];
			}
		}
	}
	int sum = 0;
	for (int i = 1; i <= a; i++) {
		sum += dp[i][i * b];
	}
	cout << sum << endl;
}

Measured memory_bytes: 1280
#include<bits/stdc++.h>
using namespace std;
int n,W,v[107],w[107];
long long dp[107][100007];
int main(){
	ios::sync_with_stdio(0), cin.tie(NULL), cout.tie(NULL);
 	cin>>n>>W;
 	for(int i=1;i<=n;i++){
        cin>>w[i]>>v[i];
 	}
 	for(int i=1;i<=n;i++){
        for(int wt=1;wt<=W;wt++){
            if(w[i]<=wt){
                dp[i][wt]=max(v[i]+dp[i-1][wt-w[i]],dp[i-1][wt]);
            }else dp[i][wt]=dp[i-1][wt];
        }
 	}
 	cout<<dp[n][W];
}


Measured memory_bytes: 81628
#include<iostream>

using namespace std;

void swap(int *a,int *b){
  int tmp = *a;
  *a = *b;
  *b = tmp;
}

int main(void){
  int a,b,c;
  cin >> a >> b >> c;
  swap(&a,&b);
  swap(&a,&c);
  cout << a <<" "<< b << " " << c << endl;
  return 0;
}


Measured memory_bytes: 3636
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < n; ++i)
#define FOR(i, a, b) for (int i = a; i < b; ++i)
#define ALL(vec) vec.begin(), vec.end()
#define rALL(vec) vec.rbegin(), vec.rend()
using namespace std;
using ll = long long;

int main() {
    int N, M;
    cin >> N >> M;
    rep(i, M) {
        int A;
        cin >> A;
        N -= A;
    }
    cout << max(N, -1) << endl;
    return 0;
}

Measured memory_bytes: 3624
#include<algorithm>
#include<bitset>
#include<cmath>
#include<complex>
#include<deque>
#include<functional>
#include<iomanip>
#include<iostream>
#include<iterator>
#include<map>
#include<numeric>
#include<queue>
#include<set>
#include<stack>
#include<string>
#include<unordered_map>
#include<unordered_set>
#include<utility>
#include<vector>
using namespace std;
typedef long long ll;
#define REP(i,n) for(ll i=0;i<(ll)(n);i++)
#define REPD(i,n) for(ll i=n-1;i>=0;i--)
#define FOR(i,a,b) for(ll i=a;i<=(ll)(b);i++)
#define FORD(i,a,b) for(ll i=a;i>=(ll)(b);i--)
#define ALL(x) (x).begin(),(x).end()
#define SIZE(x) ((ll)(x).size())
#define MAX(x) *max_element(ALL(x))
#define MIN(x) *min_element(ALL(x))
#define D()
#define INF 1000000000000
#define MOD 10000007
#define MAXR 100000
#define PB push_back
#define MP make_pair
#define F first
#define S second
#define INITA(a,i,j,v) for(ll k=i;k<=j;k++){a[k]=v;}
int main() {
    string s; cin >> s;
    if (s.size() < 26) {
        set<char> st;
        string alps = "abcdefghijklmnopqrstuvwxyz";
        REP(i, alps.size()) {
            if (s.find(alps[i]) == string::npos) {
                cout << s << alps[i] << endl;
                return 0;
            }
        }
    } else if (s == "zyxwvutsrqponmlkjihgfedcba") {
        cout << -1 << endl;
    } else {
        string nxt = s;
        next_permutation(nxt.begin(), nxt.end());
        REP(i, 26) {
            if (s[i] == nxt[i]) {
                cout << s[i];
            } else {
                cout << nxt[i] << endl;
                return 0;
            }
        }
    }
    return 0;
}

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


long long int Exp(long long int exp_n,long long int exp_e, long long exp_mod);


int main(){
  string N;
  cin >> N;
  int n;
  for(int i=0;i<N.length();i++){
    n=n+N[i]-'0';
    if(n>9){
      n=n%9;
    }
  }
  
  if(n%9==0){
    cout << "Yes" << endl;
  }else{
    cout << "No" <<endl;
  }
  
  return 0;
}


long long int Exp(long long int exp_n,long long int exp_e, long long int exp_mod){
  long long int exp_o = 1;
  long long int exp_x=exp_n;
  long long int exp_tmp;
  
  while(0<exp_e){
    exp_tmp = exp_e/2;
    if(exp_e - exp_tmp*2 == 1){
      exp_o = exp_o*exp_x;
      if(exp_o>exp_mod){
        exp_o=exp_o%exp_mod;
      }
    }
    
    exp_x = exp_x*exp_x;
    if(exp_x>exp_mod){
      exp_x=exp_x%exp_mod;
    }
    exp_e = exp_tmp;
  }
  return exp_o;
}


Measured memory_bytes: 3752
def main():
  import math
  n,k=map(int,input().split())
  ans=pow(((2*n)//k)//2,3)+pow(math.ceil(((2*n)//k)/2),3) if k%2==0 else pow(n//k,3)
  print(ans)
if __name__=='__main__':
  main()

Measured memory_bytes: 2940
#include <bits/stdc++.h>
using namespace std;
#define MZ 1000000007
#define pq priority_queue
vector <int> vec[4];
int ans=0,gg;
void dfs(int now,int W,int v)
{
    if(now==4)
    {
        ans=max(ans,v);
        return;
    }
    dfs(now+1,W,v);
    for(int i=0;i<vec[now].size();i++)
    {
        W-=gg+now;
        if(W<0)
            return;
        v+=vec[now][i];
        dfs(now+1,W,v);
    }
}
int main()
{
    int w,v,n,W;
    scanf("%d%d",&n,&W);
    scanf("%d%d",&w,&v);
    gg=w;
    vec[0].push_back(v);
    for(int i=1;i<n;i++)
    {
        scanf("%d%d",&w,&v);
        vec[w-gg].push_back(v);
    }
    sort(vec[0].begin(),vec[0].end(),greater<int>());
    sort(vec[1].begin(),vec[1].end(),greater<int>());
    sort(vec[2].begin(),vec[2].end(),greater<int>());
    sort(vec[3].begin(),vec[3].end(),greater<int>());
    dfs(0,W,0);
    printf("%d\n",ans);
    return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<algorithm>
#include<set>
#include<string>
#include<string.h>
#include<complex>
#include<math.h>
using namespace std;
typedef long long int llint;
#define rep(i,n) for(int i=0;i<n;i++)

bool check(char a, char b) {
	return a > b;
}

int kuraiwa(int n) {
	int ans = 0;
	while (n > 0) {
		ans += n % 10;
		n /= 10;
	}
	return ans;
}

bool kaibun(int n) {
	int a[5];
	for (int i = 0; i < 5; i++) {
		a[i] = n % 10;
		n /= 10;
	}
	if (a[0] == a[4] && a[1] == a[3]) {
		return true;
	}
	else {
		return false;
	}
}

int main() {
	int n;
	cin >> n;
	vector<int>a(n);
	rep(i, n){
		cin >> a[i];
	}
	sort(a.begin(), a.end());
	cout << a[n - 1] - a[0] << endl;
	return 0;
}

Measured memory_bytes: 256
class Array
	def accum
		inject([0]){|a, x| a + [a[-1] + x]}
	end

	def accum!
		(1..size-1).each{|i|
			self[i] += self[i-1]
		}
		self.unshift(0)
	end

	def accum_2d
		ac = map{|r| r.accum}
		(1..size-1).each{|i|
			(1..ac[0].size-1).each{|j|
				ac[i][j] += ac[i-1][j]
			}
		}
		ac.unshift([0] * ac[0].size)
		ac
	end

	def accum_2d!
		each{|r| r.accum!}
		(1..size-1).each{|i|
			(1..self[0].size-1).each{|j|
				self[i][j] += self[i-1][j]
			}
		}
		unshift([0] * self[0].size)
	end
		
	def bsearch_first_index(l = 0, r = size - 1, &pred)
		return nil if l > r
		c = (l + r) / 2 
		if pred[self[c]]
			bsearch_first_index(l, c-1, &pred) || c
		else
			bsearch_first_index(c+1, r, &pred)
		end
	end

	def bsearch_first_item(l = 0, r = size - 1, &pred)
		i = bsearch_first_index(l, r, &pred)
		i ? self[i] : nil
	end

	def bsearch_last_index(l = 0, r = size - 1, &pred)
		return nil if l > r
		c = (l + r) / 2 
		if pred[self[c]]
			bsearch_last_index(c+1, r, &pred) || c
		else
			bsearch_last_index(l, c-1, &pred)
		end
	end

	def bsearch_last_item(l = 0, r = size - 1, &pred)
		i = bsearch_last_index(l, r, &pred)
		i ? self[i] : nil
	end
end

require 'prime'
primes = Prime.each(1299709).to_a

loop {
	n = gets.to_i
	break if n == 0
	p1 = primes.bsearch_last_item{|x| x <= n}
	if n == p1
		p 0
	else
		p2 = primes.bsearch_first_item{|x| x >= n}
		p p2 - p1
	end
}

Measured memory_bytes: 7496
import sys
import heapq
sys.setrecursionlimit(10**7)
n, m = [int(i) for i in sys.stdin.readline().split()]
INF = 10**9
graph = {j:[(j-1, 1e-10)] if j > 0 else [] for j in range(n)}
for i in range(m):
    l, r, c = [int(i) for i in sys.stdin.readline().split()]
    l -= 1
    r -= 1
    graph[l].append((r, c))
    graph[r].append((l, c))
que = [(0,0)]
already = set()
res = [-1 for i in range(n)]
while len(que) > 0:
    cost, cand = heapq.heappop(que)
    if cand in already:
        continue
    res[cand] = cost
    already.add(cand)
    for _next, _next_cost in graph[cand]:
        if _next in already:
            continue
        heapq.heappush(que, (cost + _next_cost, _next))
print(int(res[-1]))


Measured memory_bytes: 72708
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        // 標準入力を受け取る
        Scanner scanner = new Scanner(System.in);
        int N = scanner.nextInt();

        while (true){
            // Nの桁数
            int l = String.valueOf(N).length();
            // Nの一の位の数
            int x = N % 10;
            // 全ての桁の数が同じであるフラグ
            boolean correct_flg = true;
            // Nの十の位以降の数を取得し、xと比較する
            for (int i = 2; i <= l; i++) {
                // Nのある桁の数
                int y = (N % (int) Math.pow(10, i)) / (int) Math.pow(10, i-1);
                // xと等しくない => 全ての桁の数が等しい数ではない
                if (x != y) {
                    correct_flg = false;
                    break; // これ以降の桁の数を調べる必要がない
                }
            }
            // correct_flgがtrue => 全ての桁の数が等しい
            if (correct_flg) {
                break; // ループを抜ける
            }
            // correct_flgがfalse => Nに1を足して次のループへ
            else {
                N++;
            }
        }
        
        // 全ての桁の数が等しくなったNを標準出力
        System.out.println(N);

    }

}

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

using namespace std;

using ll = long long;

int main() {
  string s;
  cin >> s;
  array<int, 26> cs{0};
  ll n = s.length();
  for (int i = 0; i < n; ++i) {
    cs[s[i] - 'a']++;
  }
  ll ans = n * (n - 1) / 2 + 1;
  for (const auto &c : cs) {
    ans -= (ll)c * (c - 1) / 2;
  }
  cout << ans << endl;
}

Measured memory_bytes: 640