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

#define N 500000
int key[N];
int rt[N];
int lt[N];
int parent[N];
int np = 0;
int root = -1;

int find_saiki(int x, int k){
	if(x==-1) return -1;
	if(k==key[x]) return x;

	if(k<key[x]){
		return find_saiki(lt[x], k);
	}else{
		return find_saiki(rt[x], k);
	}
	return -1;
}

int find(int k){
	return (find_saiki(root, k)>=0);
}

void del(int k){
//	cout << k << endl;
	int x = find_saiki(root, k);
	if(x>0){
		int y = parent[x];
		if(rt[x]==-1 || lt[x]==-1){
			// 0 child
			if(rt[x]==-1 && lt[x]==-1){
				if(rt[y]==x) rt[y] = -1;
				else lt[y] = -1;
			}
			// 1 child
			else if(rt[x]==-1){
				if(rt[y]==x) rt[y] = lt[x];
				else lt[y] = lt[x];
				parent[lt[x]] = y;
			}else if(lt[x]==-1){
				if(rt[y]==x) rt[y] = rt[x];
				else lt[y] = rt[x];
				parent[rt[x]] = y;
			}

			// del x
			rt[x] = lt[x] = parent[x] = -1;
		}
		// 2 child
		else{
			// find the node have next value to x
			int t = rt[x];
			while(lt[t]!=-1) t = lt[t];
			int kt = key[t];

			del(kt);

			key[x] = kt;
		}

	}
}

void insert(int k){
	int y = -1;
	int x = root;
	while(x!=-1){
		y = x;
		if(k < key[x]){
			x = lt[x];
		}else{
			x = rt[x];
		}
	}
	if(y==-1){
		root = np;
	}else{
		if(k<key[y]){
			lt[y] = np;
		}else{
			rt[y] = np;
		}
	}
	key[np] = k;
	parent[np] = y;
	np++;
}

void print_saiki1(int x){
	if(lt[x]!=-1) print_saiki1(lt[x]);
	if(x!=0) cout << " " << key[x];
	if(rt[x]!=-1) print_saiki1(rt[x]);
}

void print_saiki2(int x){
	if(x!=0) cout << " " << key[x];
	if(lt[x]!=-1) print_saiki2(lt[x]);
	if(rt[x]!=-1) print_saiki2(rt[x]);
}
void print(){
	print_saiki1(root);
	cout << endl;
	print_saiki2(root);
	cout << endl;
}


int main(){

	for(int i=0; i<N; i++){
		key[i] = -1;
		parent[i] = -1;
		lt[i] = -1;
		rt[i] = -1;
	}
	key[0] = -2000000001;
	np = 1;

	int n;
	cin >> n;
	for(int i=0; i<n; i++){
//		cout << i << endl;
		string s;
		cin >> s;
		if(s=="print"){
			print();
		}else if(s=="insert"){
			int k;
			cin >> k;
			insert(k);
		}else if(s=="find"){
			int k;
			cin >> k;
			if(find(k)){
				cout << "yes" << endl;
			}else{
				cout << "no" << endl;
			}
		}else if(s=="delete"){
			int k;
			cin >> k;
			del(k);
		}
	}


	return 0;
}

Measured memory_bytes: 9028
#include <iostream>
#include <map>
using namespace std;
int main(){
    string s,t; cin >> s >> t;
    map<char, char> mp, mp2;
    bool check = true;
    for(int i = 0; i < s.size(); i++){
        if(mp.count(s[i])){
            if(mp[s[i]] != t[i])check = false;
        }
        if(mp2.count(t[i])){
            if(mp2[t[i]] != s[i])check = false;
        }
        mp[s[i]] = t[i];
        mp2[t[i]] = s[i];
    }
    cout << ((check)? "Yes":"No") << endl;
}

Measured memory_bytes: 776
package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
	"strings"
)

func main() {
	var strInputs []string
	sc := bufio.NewScanner(os.Stdin)
	sc.Scan()
	strInputs = strings.Split(sc.Text(), " ")

	n, _ := strconv.Atoi(strInputs[0])
	min, _ := strconv.Atoi(strInputs[1])
	max, _ := strconv.Atoi(strInputs[2])
	count := 0

	for i := 1; i <= n; i++ {
		if (i <= 9) && (i >= min) && (i <= max) {
			count += i
		} else if i <= 99 {
			ans := (i / 10) + (i % 10)
			if (ans >= min) && (ans <= max) {
				count += i
			}
		} else if i <= 999 {
			ans := (i / 100) + (i / 10 % 10) + (i % 10)
			if (ans >= min) && (ans <= max) {
				count += i
			}
		} else if i <= 9999 {
			ans := (i / 1000) + (i / 100 % 10) + (i / 10 % 10) + (i % 10)
			if (ans >= min) && (ans <= max) {
				count += i
			}
		} else if i == 10000 {
			if (1 >= min) && (1 <= max) {
				count += 10000
			}
		}
	}
	fmt.Println(count)
}

Measured memory_bytes: 640
#include<iostream>

using namespace std;
 
int main(){
	long long n,cnt=0,ans;
	
	cin >> n;
	ans = n;

	for(long long i = n; i > 0; i--){
		
		if(i % 2 == 0){
			long long acc=0,j = i;
			
			while(j % 2 == 0){
				j /= 2;
				acc++;
			}

			if(acc > cnt){
				ans = i;
				cnt = acc;
			}		
		}
	}

	cout << ans << endl;
}


Measured memory_bytes: 3672
#include<vector>
#include<map>
#include<set>
#include<queue>
#include<algorithm>
#include<functional>
#include<numeric>
#include<utility>
#include<sstream>
#include<iostream>
#include<iomanip>
#include<cstdio>
#include<cmath>
#include<cstdlib>
#include<cctype>
#include<string>
#include<cstring>
#include<list>
using namespace std;
typedef vector<int>VI;
typedef vector<VI>VVI;
typedef vector<string>VS;
typedef pair<int,int>PII;
typedef long long LL;
typedef pair<LL,LL>PLL;
#define ALL(a) (a).begin(),(a).end()
#define RALL(a) (a).rbegin(),(a).rend()
#define PB push_back
#define EACH(i,c) for(typeof((c).begin())i=(c).begin();i!=(c).end();i++)
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n) FOR(i,0,n)
#define F first
#define S second

int N;
vector<PII>V;

int solve(){
    sort(V.begin(),V.end());
    int mi=1e9+7;
    REP(i,N){
        FOR(j,i+1,N){
            int x=abs(V[i].F-V[j].F);
            int y=abs(V[i].S-V[j].S);
            if(x*x>mi)break;
            mi=min(x*x+y*y,mi);
        }
    }
    return mi;
}
int main(){
    cin>>N;
    V.resize(N);
    REP(i,N)cin>>V[i].F>>V[i].S;
    cout<<solve()<<endl;

    return 0;
}

Measured memory_bytes: 4896
#include <cstdio>
#ifdef _MSC_VER
#include <conio.h>
#else
#define getch()
#endif

int main(){
	int Data[51]={};
	int N=0;
	int M=0;
	scanf(" %d %d",&N,&M);
	for(int i=0;i<M;i++){
		int ATemp=0;
		int BTemp=0;
		scanf(" %d %d",&ATemp,&BTemp);
		Data[ATemp-1]++;
		Data[BTemp-1]++;
	}
	for(int i=0;i<N;i++){
		printf("%d\n",Data[i]);
	}
	getch();
	return 0;
}

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

int main() {
    int a[3];

    cin >> a[0] >> a[1] >> a[2];

    sort(a, a + 3);

    if (a[0] == 5 && a[1] == 5 && a[2] == 7) {
        cout << "YES" << endl;
    } else {
        cout << "NO" << endl;
    }

    return 0;
}


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

int main(void) {
    int n, cnt, ans;
    string s;
    array<int, 26> w;
    ans = 0;
    cin >> n >> s;
    for(int i = 0; i < n; i++){
        w = {0};
        cnt = 0;
        for(int j = 0; j < i + 1; j++){
            for(int k = i + 1; k < n; k++){
                if(s[j] == s[k]) w[s[j]-'a'] = 1;
            }
        }
        for(int j = 0; j < 26; j++){
            if(w[j] == 1) cnt++;
        }
        ans = max(ans, cnt);
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 256
#include<iostream>
        #include<cmath>
         
    	using namespace std;
     
        int main(void){
          	int a,b,c,d;
        	cin >> a >>b >> c >> d;
          	
          if(abs(a-c) <= d){
           	cout << "Yes" << endl; 
          }
          else if(abs(a-b) <= d && abs(b-c) <= d){
             cout << "Yes" << endl;
          }
          else{
            cout << "No" << endl;
          }
          
        }

Measured memory_bytes: 256
#include <string>
#include <algorithm>
#include <vector> 
#include <math.h>
#include <iostream>
using namespace std;

int main()
{
	string a;
	cin >> a;
	
	string b = "A";
	if (a == "A") {
		b = "T";
	}
	else if (a == "G") {
		b = "C";
	}
	else if (a == "C") {
		b = "G";
	}

	cout << b << endl;
	return 0;

}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
const int maxn=5005;
const int mod=1000*1000*1000+7;
int n,ed,fir[maxn],sz[maxn];
int a[maxn],f[maxn][maxn],g[maxn];
struct Edge{
  int v,nxt;
}e[maxn*2];
inline void up(int&x,int y){
  if(x+=y,x>=mod)x-=mod;
}
void adde(int x,int y){
  e[++ed].v=y;e[ed].nxt=fir[x];fir[x]=ed;
}
void dfs(int x,int y){
  sz[x]=1;
  f[x][1]=1;
  for(int i=fir[x];i;i=e[i].nxt)if(e[i].v!=y){
    dfs(e[i].v,x);
    for(int j=1;j<=sz[x];j++){
      g[j]=f[x][j];
      f[x][j]=0;
    }
    for(int j=1;j<=sz[x];j++){
      for(int k=1;k<=sz[e[i].v];k++){
        up(f[x][j+k],1LL*g[j]*f[e[i].v][k]%mod);
        up(f[x][j],mod-1LL*g[j]*f[e[i].v][k]%mod*a[k]%mod);
      }
    }
    sz[x]+=sz[e[i].v];
  }
}
int main(){
  //freopen("aa.in","r",stdin);
  scanf("%d",&n);
  for(int i=1;i<n;i++){
    int x,y;scanf("%d%d",&x,&y);
    adde(x,y);adde(y,x);
  }
  a[0]=1;
  for(int i=2;i<=n;i+=2)a[i]=1LL*a[i-2]*(i-1)%mod;
  dfs(1,0);
  int ans=0;
  for(int i=1;i<=n;i++){
    up(ans,1LL*f[1][i]*a[i]%mod);
  }
  printf("%d\n",ans);
  return 0;
}

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

using namespace std;
using   ll=long long;

#define fast        	ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)

#define endl        	"\n"
#define pb          	push_back
#define mp          	make_pair
#define F           	first
#define S           	second
#define int             long long int
#define pll				pair<int , int>

#define ALL(v)      	v.begin(),v.end()
#define ALLR(v)     	v.rbegin(),v.rend()
#define pii         	3.14159265358979323
#define inf     		LLONG_MAX
#define ones(x)     	__builtin_popcount(x)
#define fill(a,b)   	memset(a,b,sizeof(a))
#define mod 			1000000007
#define hell            998244353 

ll mod_pow(ll a,ll b,ll m) 
{
    ll res = 1;
    while(b)	
    {
        if(b&1) 	
        {
        	res=(res*a) % m;
        }
        a=(a*a) % m;
        b>>=1;
    }
    return res;
}

ll mod_inverse(ll a) 
{
	return mod_pow(a , mod-2 , mod);
}

void solve() 
{
	int  l , r;
	
	cin >> l >> r;
	
	int lol = 2019;
	
	int ans = inf;
	
	for(int i = 1; i <= 2019; ++i) {
		int num = (l/2019)*2019;
		
		num += i;
		
		if(num < l) {
			num += 2019;
		}
		
		//cout << num << endl;
		
		if(num > r) {
			continue;
		}
		
		for(int j = 1; j <= 2019; ++j) {
			int tm;
			if(i == j) {
				tm = num + 2019;
			}
			else {
			tm = (l/2019)*2019;
			
			tm += j;
			
			if(tm < l) {
				tm += 2019;
			}
		
			}
			
			if(num >= l && num <= r && tm >= l && tm <= r) {
				ans = min(ans , (num*tm)%2019);
			}
		}
	}
	
	cout << ans;
}

signed main() {
    fast;
    
    int t = 1;
    
	//cin >> t;
    
    while(t--) {
        solve();
    }
 
    return 0;
}


Measured memory_bytes: 3616
import java.util.*;
    public class Main {
     
    	public static void main(String[] args) {
    			
    		Scanner scan=new Scanner(System.in);
    		
    		int n=Integer.parseInt(scan.next());
    		int m=Integer.parseInt(scan.next());
    		
    		System.out.print((n-1)*(m-1));

    		
    	
  
    				
 
     
    }
    }

Measured memory_bytes: 21844
#include<deque>
#include<queue>
#include<vector>
#include<algorithm>
#include<iostream>
#include<set>
#include<cmath>
#include<tuple>
#include<string>
#include<chrono>
#include<functional>
#include<iterator>
#include<random>
#include<unordered_set>
#include<array>
#include<map>
#include<iomanip>
using namespace std;
typedef long long int llint;
typedef long double lldo;
#define mp make_pair
#define mt make_tuple
#define pub push_back
#define puf push_front
#define pob pop_back
#define pof pop_front
#define fir first
#define sec second
#define res resize
#define ins insert
#define era erase
//cout<<setprecision(20)
const llint mod=1000000007;
const llint big=1e17+10;
const long double pai=3.141592653589793238462643383279502884197;
const long double eps=1e-9;
template <class T,class U>void mineq(T& a,U b){if(a>b){a=b;}}
template <class T,class U>void maxeq(T& a,U b){if(a<b){a=b;}}
llint gcd(llint a,llint b){if(a%b==0){return b;}else return gcd(b,a%b);}
llint lcm(llint a,llint b){return a/gcd(a,b)*b;}
template<class T> void SO(T& ve){sort(ve.begin(),ve.end());}
template<class T> void REV(T& ve){reverse(ve.begin(),ve.end());}
int LBI(vector<int>&ar,int in){return lower_bound(ar.begin(),ar.end(),in)-ar.begin();}
int UBI(vector<int>&ar,int in){return upper_bound(ar.begin(),ar.end(),in)-ar.begin();}
int main(void){
	string str;cin>>str;
	llint ans=0,i,n=str.size();
	llint dp[2][3]={0};
	dp[0][0]=1;
	//ato 0->から 1->0 2->00
	for(int h=0;h<n;h++){
		llint ddp[2][3]={0};
		llint na=0;
		if(str[h]=='0'||str[h]=='?'){
			na+=ans;
			ddp[0][1]+=dp[0][0];
			ddp[0][2]+=dp[0][1];
			ddp[0][1]+=dp[0][2];
			ddp[1][1]+=dp[1][0];
			ddp[1][2]+=dp[1][1];
			ddp[1][1]+=dp[1][2];
		}
		if(str[h]=='1'||str[h]=='?'){
			na+=ans;
			ddp[1][0]+=dp[0][0];
			ddp[0][0]+=dp[0][1];
			ddp[0][1]+=dp[0][2];
				   na+=dp[1][0];
			ddp[1][0]+=dp[1][1];
			ddp[1][1]+=dp[1][2];
		}
		ans=na%mod;
		for(i=0;i<6;i++){ddp[i/3][i%3]%=mod;}
		swap(dp,ddp);
	}
	ans+=dp[1][0];
	ans%=mod;
	cout<<ans<<endl;
	return 0;
}


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

#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define rep(i,n) FOR(i,0,n)
#define RFOR(i,a,b) for(int i=(a)-1;i>=(b);i--)
#define rrep(i,n) RFOR(i,n,0)

using namespace std;

typedef long long ll;
typedef unsigned long long ull;

const ll INF = 1e18;

ll f(ll b,ll n){
	if(n<b) return n;
	return f(b, n/b) + n%b; 
}

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

	ll n,s;
	cin >> n >> s;

	if(s == n){
		cout << (n+1) << endl;
		return 0;
	}

	for(ll b = 2; b*b <=n; b++){
		if(f(b,n) == s){
			cout << b << endl;
			return 0;
		}
	}

	ll ans = INF;

	for(ll p = 1; p*p <= n; p++){
		if((n - s) % p != 0) continue;
		ll b = (n - s) / p + 1;
		if(b < 2) continue;

		if(f(b,n) == s) ans = min(ans,b);
	}

	cout << (ans == INF ? -1 : ans) << endl;
}

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

Measured memory_bytes: 580
#include <iostream>
#include <list>
#include <algorithm>
#include <vector>
#include <memory>

int main()
{
    size_t N;
    std::cin >> N;
    for (size_t i = 0; i < N; i++) {
        size_t a;
        std::cin >> a;
        if (a % 2 == 1) {
            std::cout << "first" << std::endl;
            return 0;
        }
    }
    std::cout << "second" << std::endl;
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
using namespace std;
int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    int n; cin >> n;
    string s; cin >> s;
    int ans = 0;
    for (int i = 0; i < n-1; i++)
    {
        if(s[i] == s[i+1]) continue;
        ans++;
    }
    cout << ans+1 << endl;
    return 0;
}

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

int n;
int a[101][101];
int flg[101];
int t[101];
int sum = 0;

void visit(){
  int ima = 0;
  int mine = 100000000;
  
  
  for(int k=0;k<n-1;k++) {
    mine = 10000000;
    for(int i=0;i<n;i++) {
      if(flg[i] == 0 && mine > t[i]) {
	mine = t[i];
	ima = i;
      }
    }
    sum += mine;
    flg[ima] = 1;
    
    for(int i=0;i<n;i++) 
      if(a[ima][i] != -1) 
	if(t[i] > a[ima][i] ) t[i] = a[ima][i];
    
    
  }
}

int main() {

  cin >> n;

  for(int i=0;i<n;i++) 
    for(int j=0;j<n;j++) 
      cin >> a[i][j];
  
  for(int i=0;i<n;i++) {
    flg[i] = 0;
    t[i] = 100000000;
  }
  
  t[0] = 0;
  flg[0] = 1;
  for(int i=0;i<n;i++) 
    if(a[0][i] != -1) t[i] = a[0][i];

  visit();

  cout << sum << endl;
 
  return 0; 
  
}



Measured memory_bytes: 3104
#include <bits/stdc++.h>
using namespace std;
#define finish(x) return cout << x << endl, 0
#define ll long long

int n;

int calc(int x, int k){
    if(x % k == 0) return x / k;
    int d = x / k;
    if(x / k != (x - d - 1) / k) return calc(x - d - 1, k);
    int to = d * k;
    int g = (x - to) / (d + 1);
    x -= g * (d + 1);
    return calc(x, k);
}
int main(){
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cin >> n;
    int ans = 0;
    for(int i = 0 ; i < n ; i++){
        int x, y;
        cin >> x >> y;
        ans ^= calc(x, y);
    }
    if(ans) cout << "Takahashi\n";
    else cout << "Aoki\n";
}


Measured memory_bytes: 3636
#include <cstdio>
#include <cstring>
int n,s;
int dfs(int x,int y,int sum) {
	if(y==n) return (sum==s);
	if(x==10) return 0;
	return dfs(x+1,y,sum)+dfs(x+1,y+1,sum+x);
}
int main() {
	while(scanf("%d %d",&n,&s),n|s) {
		printf("%d\n",dfs(0,0,0));
	}
}

Measured memory_bytes: 1028
#include<stdio.h>
#include<stdlib.h>

void run(void){
  int n,m;
  scanf("%d%d",&n,&m);
  int *dp=(int *)calloc(m+1,sizeof(int));
  while(n--){
    int v,w;
    scanf("%d%d",&v,&w);
    for(int i=m;i-w>=0;i--) if(dp[i]<dp[i-w]+v) dp[i]=dp[i-w]+v;
  }
  printf("%d\n",dp[m]);
}

int main(void){
  run();
  return 0;
}


Measured memory_bytes: 2100
/* FALTU HI LIKH ... BUT KHALI NI BAITHNA */
#include<bits/stdc++.h>

#define fast ios_base::sync_with_stdio(false); cin.tie(nullptr); cin.tie(nullptr);
#define endl '\n'
#define int long long
#define ld long double
#define pb emplace_back
#define range(v) v.begin(),v.end()
#define mod (int)(1e9 + 7)
#define inf (int)(1e15)
#define pii pair<int,int>
#define ff first
#define ss second
#define N (int)(2e5 + 10)

using namespace std;



int32_t main() {
	fast
	int t_c = 1;
//	cin >> t_c;
	while (t_c--) {
//		cout << "#: ";
		int n, k;
		cin >> n >> k;
		unordered_map<int, int> h;
		for (int i = 0; i < k; i++) {
			int d;
			cin >> d;
			for (int i = 0; i < d; i++) {
				int s;
				cin >> s;
				h[s]++;
			}
		}

		int ans = 0;
		for (int i = 1; i <= n; i++) {
			if (!h.count(i)) ans++;
		}

		cout << ans << endl;


	}
}

Measured memory_bytes: 3628
import java.io.*;
import java.util.*;
class Main{
  public static void main(String[] args)throws IOException{
    BufferedReader mBufferedReader=new BufferedReader(new InputStreamReader(System.in));
    List<String>list=new ArrayList<String>();
    String[] marks={"S","H","C","D"};
    for(int i=0;i<4;i++){
      for(int j=0;j<13;j++){
        list.add(marks[i]+" "+(j+1));
      }
    }
    int n=Integer.parseInt(mBufferedReader.readLine());
    for(int i=0;i<n;i++){
      list.remove(mBufferedReader.readLine());
    }
    for(String s:list){
      System.out.println(s);
    }
  }
}   


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

#define rep(i, N) for (int i = 0; i < (N); i++)
#define all(a) (a).begin(), (a).end()
#define pb push_back

using ll = long long;
using i_i = tuple<int, int>;

int main() {
    int x, y;
    cin >> x >> y;
    int ans = 0;
    if (x == 1) ans += 300000;
    if (x == 2) ans += 200000;
    if (x == 3) ans += 100000;
    if (y == 1) ans += 300000;
    if (y == 2) ans += 200000;
    if (y == 3) ans += 100000;
    if (x == 1 && y == 1) ans += 400000;
    cout << ans << endl;
}


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

int n, q;
long long white;
long long r[200005], c[200005];
long long curr, curc;
long long ans;

int main() {
	scanf("%d%d", &n, &q);
	for (int i = 0; i <= n; i++) r[i] = -1, c[i] = -1;
	curr = n - 2, curc = n - 2;
	for (int i = 0; i < q; i++) {
		int o, x; scanf("%d%d", &o, &x);
		if (o == 1) {
			for (int j = x + 1; j <= n; j++) {
				if (r[j] != -1) break;
				r[j] = curr;
			}
			if (r[x] != -1) {
				white += r[x];
			}
			else {
				white += curr;
				curc = x - 2;
			}
		} else {
			for (int j = x + 1; j <= n; j++) {
				if (c[j] != -1) break;
				c[j] = curc;
			}
			if (c[x] != -1) {
				white += c[x];
			}
			else {
				white += curc;
				curr = x - 2;
			}
		}
	}
	ans = (long long) (n - 2) * (n - 2) - white;
	printf("%lld\n", ans);
	return 0;
}


Measured memory_bytes: 6880
#include <bits/stdc++.h>
//#include <ext/pb_ds/assoc_container.hpp>
//#include <ext/pb_ds/tree_policy.hpp>
 
using namespace std;
//using namespace __gnu_pbds;
using namespace std::chrono; 
 
//VARS
#define int               long long
#define ld                long double
#define mod1              1000000007
#define mod2              998244353
#define pi               3.14159265358979323846
//#define hs                100006
#define inf               1e18
#define ninf              -1*(1e18)
 
#define pb                push_back
#define mp                make_pair
#define all(x)            (x).begin(),(x).end()
#define fi                first
#define se                second
#define vc                vector
#define pii               pair<int,int>
#define msi               map<string,int>
#define mii               map<int,int>
#define psi               pair<string,int>
#define pis               pair<int,string>
#define endl              "\n"
 
//INPUT
#define rep(i,a,b)        for(int i=a;i<b;i++)
#define repe(i,a,b)       for(int i=a;i<=b;i++)
#define bac(i,a,b)        for(int i=a;i>b;i--)
#define bace(i,a,b)       for(int i=a;i>=b;i--)
 
//FAST
#define ios               ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
 
//FUNCTIONS
#define DECIMAL(n)        std::cout << std::fixed << std::setprecision(n)
#define SORT(v)           sort(all(v))
#define RSORT(v)          sort(all(v),greater<int>())
#define REVERSE(v)        reverse(ALL(v))
#define GCD(m,n)          __gcd(m,n)
#define LCM(m,n)          m*(n/GCD(m,n))
#define init(x,a)         memset(x,a,sizeof(x))
#define trav(a, x)        for(auto& a : x)
#define display(x)        trav(a,x) cout<<a<<" "; cout<<endl
#define pow(i,n)          (int)pow((int)i,n)
#define pow2(n)           ((int)1<<n)
 
void swp(int &a, int &b){
    auto temp=a;
    a=b;
    b=temp;
}

int ans(string s) 
{ 
  
    int n = s.length();  
    int p = 0; 
    for(int i=0;i<n/2;i++) 
    { 
        if(s[i]!= s[n-i-1])  
        {
            p+= 1; 
            if(s[i]<s[n-i-1])  
                s[n-i-1]= s[i] ; 
            else
                s[i]= s[n-i-1] ; 
        }
    } 
     return p;
} 

void solve(){
    string s;
    cin>>s;
    int t = ans(s);
    cout<<t;
    return;
}
 
signed main(){
    ios   
    int q=1;
    //cin>>q;
    while(q--){
        solve();
    }

    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define pb push_back
#define int long long
#define mp make_pair
#define inf 1000000007
#define ll long long
using namespace std;
ll deg[114514], tak[114514], par[114514];
vector<ll> to[114514];
signed main(){
	ll n,k;
	cin>>n>>k;
	vector<ll> a;
	for(int i=0;i<n;i++){
		ll x;
		cin>>x;
		a.pb(x-1);
		to[x-1].pb(i);
		to[i].pb(x-1);
		par[i] = x-1;
		deg[i]++;
		if(i>0 || x-1 == 0)deg[x-1]++;
	}
	ll ans = 0;
	if(a[0] != 0){
		ans++;
		a[0] = 0;
		par[0]=0;
	}
	if(k==1){
		for(int i=1;i<n;i++){
			if(a[i] != 0)ans++;
		}
		cout<<ans<<endl;
		return 0;
	}
	queue< int > que;
	for(int i=1;i<n;i++){
		if(deg[i]==1)que.push(i);
	}
	while(!que.empty()){
		ll ci = que.front();
		que.pop();
		if(tak[ci] == k-1 && par[ci] != 0){
			ans ++ ;
			tak[ci] = -1;
		}
		for(int i=0;i<to[ci].size();i++){
			ll di = to[ci][i];
			if( deg[di] > 1 ){
				tak[di] = max(tak[di], tak[ci] + 1 );
				deg[di]--;
				//cout<<di<<" "<<deg[di]<<endl;
				if(deg[di] == 1 && di != 0){
					que.push(di);
				}
			}
		}
	}
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 11384
#[allow(unused_imports)]
use {
   proconio::{fastout, input, marker::*},
   std::cmp::*,
   std::collections::*,
};

fn main() {
   input! {
      n: usize,
      a: usize,
      x: [usize; n]
   }
   let num = a * n;
   let mut dp = vec![vec![0usize; num + 1]; n + 1];
   dp[0][0] = 1;
   for i in 0..n {
      for j in (0..=i).rev() {
         for k in x[i]..=num {
            dp[j + 1][k] += dp[j][k - x[i]];
         }
      }
   }
   let mut ans = 0;
   for i in 1..=n {
      ans += dp[i][i * a];
   }
   println!("{}", ans);
}


Measured memory_bytes: 3028
import java.io.IOException;
import java.io.InputStream;
import java.util.*;

public class Main {
    public static void main(String[] args){
        FastScanner sc = new FastScanner();
        int h = sc.nextInt();
        int w = sc.nextInt();
        String[] lines = new String[h];
        for(int i=0; i<h; i++){
            lines[i] = sc.next();
        }
        for(String line : lines){
            System.out.println(line);
            System.out.println(line);
        }

    }

    static class FastScanner {
        private final InputStream in = System.in;
        private final byte[] buffer = new byte[1024];
        private int ptr = 0;
        private int buflen = 0;
        private boolean hasNextByte() {
            if (ptr < buflen) {
                return true;
            }else{
                ptr = 0;
                try {
                    buflen = in.read(buffer);
                } catch (IOException e) {
                    e.printStackTrace();
                }
                if (buflen <= 0) {
                    return false;
                }
            }
            return true;
        }
        private int readByte() { if (hasNextByte()) return buffer[ptr++]; else return -1;}
        private static boolean isPrintableChar(int c) { return 33 <= c && c <= 126;}
        public boolean hasNext() { while(hasNextByte() && !isPrintableChar(buffer[ptr])) ptr++; return hasNextByte();}
        public String next() {
            if (!hasNext()) throw new NoSuchElementException();
            StringBuilder sb = new StringBuilder();
            int b = readByte();
            while(isPrintableChar(b)) {
                sb.appendCodePoint(b);
                b = readByte();
            }
            return sb.toString();
        }
        public long nextLong() {
            if (!hasNext()) throw new NoSuchElementException();
            long n = 0;
            boolean minus = false;
            int b = readByte();
            if (b == '-') {
                minus = true;
                b = readByte();
            }
            if (b < '0' || '9' < b) {
                throw new NumberFormatException();
            }
            while(true){
                if ('0' <= b && b <= '9') {
                    n *= 10;
                    n += b - '0';
                }else if(b == -1 || !isPrintableChar(b)){
                    return minus ? -n : n;
                }else{
                    throw new NumberFormatException();
                }
                b = readByte();
            }
        }
        public int nextInt() {
            long nl = nextLong();
            if (nl < Integer.MIN_VALUE || nl > Integer.MAX_VALUE) throw new NumberFormatException();
            return (int) nl;
        }
        public double nextDouble() { return Double.parseDouble(next());}
    }
}

Measured memory_bytes: 21844
def solve():
    n = int(input())
    h = list(map(int, input().split()))

    for i in reversed(range(n - 1)):
        if h[i] > h[i + 1]:
            h[i] -= 1
            if h[i] > h[i + 1]:
                return False
    
    return True

if solve():
    print('Yes')
else:
    print('No')


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

int main()
{
	int64_t N;
	std::array<int64_t, 3> metal[3]{};
	scanf("%lld", &N);
	for (int i{}; i < 2; i++)
		for (int j{}; j < 3; j++)
			scanf("%lld", &metal[j][i]);
	for (int i{}; i < 3; i++)
	{
		if (metal[i][0] > metal[i][1])
		{
			metal[i][2] = 1;
			std::swap(metal[i][0], metal[i][1]);
		}
		metal[i][1] -= metal[i][0];
	}
	std::sort(metal, metal + 3, [](auto a, auto b) { return a[2] < b[2]; });

	int64_t max{};
	if (metal[0][2] == metal[2][2])
	{
		for (int64_t i{}; i * metal[0][0] <= N; i++)
			for (int64_t j{}; i * metal[0][0] + j * metal[1][0] <= N; j++)
			{
				int64_t k{(N - i * metal[0][0] - j * metal[1][0]) / metal[2][0]};
				max = std::max(max, N + i * metal[0][1] + j * metal[1][1] + k * metal[2][1]);
			}
	}
	else if (metal[1][2])
	{
		int64_t num{N + N / metal[0][0] * metal[0][1]};
		for (int64_t i{}; i * metal[1][0] <= num; i++)
		{
			int64_t j{(num - i * metal[1][0]) / metal[2][0]};
			max = std::max(max, num + i * metal[1][1] + j * metal[2][1]);
		}
	}
	else
	{
		for (int64_t i{}; i * metal[0][0] <= N; i++)
		{
			int64_t j{(N - i * metal[0][0]) / metal[1][0]};
			int64_t num{N + i * metal[0][1] + j * metal[1][1]};
			int64_t k{num / metal[2][0]};
			max = std::max(max, num + k * metal[2][1]);
		}
	}
	
	printf("%lld\n", max);
	return 0;
}

Measured memory_bytes: 256
#include <map>
#include <set>
#include <list>
#include <cmath>
#include <queue>
#include <stack>
#include <cstdio>
#include <string>
#include <vector>
#include <complex>
#include <cstdlib>
#include <cstring>
#include <numeric>
#include <sstream>
#include <iostream>
#include <algorithm>
#include <functional>

#define mp       make_pair
#define pb       push_back
#define all(x)   (x).begin(),(x).end()
#define rep(i,n) for(int i=0;i<(n);i++)
#define repi(i,a,b) for(int i = (a); i < (b); i++)

using namespace std;

typedef    long long          ll;
typedef    unsigned long long ull;
typedef    vector<bool>       vb;
typedef    vector<int>        vi;
typedef    vector<vb>         vvb;
typedef    vector<vi>         vvi;
typedef    pair<int,int>      pii;

const int INF=1<<29;
const double EPS=1e-9;

const int dx[]={1,0,-1,0},dy[]={0,-1,0,1};
int H,W,N;
int board[1010][1010];
int dp[1010][1010];//N-1回までの（i,j）の通った回数を数える
int main(){
	while(cin>>H>>W>>N,H||W||N){
		int posx,posy;
		memset(dp, 0, sizeof(dp));

		for(int i =1;i <=H;i++){
			for(int j =1;j <=W;j++){
				cin>>board[i][j];
			}
		}
		N--;
		dp[1][1]=N;
		for(int i =1;i <=H;i++){
			for(int j=1;j <=W;j++){
				if(dp[i][j]%2==0){
					dp[i][j+1]+=dp[i][j]/2;
					dp[i+1][j]+=dp[i][j]/2;
				}else{
					if(board[i][j]==0){
						dp[i+1][j]+=(dp[i][j]+1)/2;
						dp[i][j+1]+=(dp[i][j]-1)/2;
					}else{
						dp[i+1][j]+=(dp[i][j]-1)/2;
						dp[i][j+1]+=(dp[i][j]+1)/2;
					}
				}
			}
		}
		posx=posy=1;
		while(true){
			//cout <<posx<<" "<<posy<<endl;
			if(board[posy][posx]&&dp[posy][posx]%2)posy++;//最初が東で奇数→反転
			else if(board[posy][posx]&&!(dp[posy][posx]%2))posx++;//最初が東で偶数→そのまま
			else if(!board[posy][posx]&&dp[posy][posx]%2)posx++;//最初が南で奇数→反転
			else posy++;
			if(posx>=W+1||posy>=H+1)break;
		}
		cout <<posy<<" "<<posx<<endl;
	}
	return 0;
}

Measured memory_bytes: 9100
#![allow(unused_imports)]
#![allow(clippy::many_single_char_names)]
#![allow(clippy::suspicious_arithmetic_impl)]

// using Rust(1.42.0)
// My Library Repo is at "https://github.com/Loptall/prcn_lib"
// check available crates on AtCoder at "https://atcoder.jp/contests/language-test-202001"

/*
    AtCoder Language Update 2020204 お疲れ様でした! 有難いです
*/

// Dep crates are...
use std::cmp::{max, min, Ordering};
use std::collections::{BTreeMap, BTreeSet, HashMap, HashSet, VecDeque};
use std::mem::swap;
use std::ops::*;
use std::{i128, i16, i32, i64, i8, isize, u128, u16, u32, u64, u8, usize};

use itertools::*;
use itertools_num::*;
use lazy_static::lazy_static;
use maplit::{btreemap, btreeset, hashmap, hashset};
use num_bigint::{BigInt, BigUint};
use num_integer::{binomial, gcd, lcm, Integer};
use permutohedron::Heap;
use petgraph::unionfind::UnionFind;
use proconio::{fastout, input, is_stdin_empty, marker::*};
use rand::random;

// code...
fn main() {
    input! {
        n: usize, k: isize,
        a: [Usize1; n]
    }

    let mut visited = vec![-1; n];

    let mut cur = 0;
    let mut t = 0;

    loop {
        if visited[cur] == -1 {
            visited[cur] = t;
        } else {
            let base = t - visited[cur];
            for i in 0..(k - t) % base {
                cur = a[cur];
            }
            println!("{}", cur + 1);
            break;
        }
        cur = a[cur];
        t += 1;
        if t == k {
            println!("{}", cur + 1);
            break;
        }
    }
}


Measured memory_bytes: 6348
#include <stdio.h>

int main(){
    int N = 0;
    long long i = 0;
    long long a = 0;
    scanf("%d",&N);
    a = (long long)N;
    for(i = N; i != 1; i--){
        a = a * (i-1);
            }
    printf("%lld\n",a);
    return 0;
}

Measured memory_bytes: 592
// 6/11
// 3-2-1. 尺取法
// 類題
#include <bits/stdc++.h>
#define rep(i, n) for (ll i = 0; i < (n); ++i)
using namespace std;
using ll = long long;
using P = pair<int, int>;
const int INF = 1e9;

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

    ll right = 0;
    ll res = 0;
    // ll sum = 0, sxor = 0;
    ll sum = 0;

    for (ll left = 0; left < N; left++) {
        while (right < N && (sum ^ A[right]) == (sum + A[right])) {
            // sxor = sxor ^ A[right];
            sum += A[right];
            right++;

            // cout << "here>" << endl;
        }

        res += right - left;

        if (left == right) right++;
        else {
            // sxor = sxor ^ A[left];
            sum -= A[left];
        }
    }

    cout << res << endl;
}

Measured memory_bytes: 1792
package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
)

const (
	B = 100000007
)


func main() {
	N := readInt()
	S := readString()
	ms := 0
	for i := 1; i < N; i++ {
		ts := 0
		for j := 0; j < N - i; j++ {
			if S[j] == S[j + i] {
				ts++
				if ts > ms {
					ms = ts
				}
				if ts == i {
					break
				}
			} else {
				ts = 0
			}
		}
	}
	fmt.Println(ms)
}
  

const (
	ioBufferSize = 1 * 1024 * 1024 // 1 MB
)

var stdinScanner = func() *bufio.Scanner {
	result := bufio.NewScanner(os.Stdin)
	result.Buffer(make([]byte, ioBufferSize), ioBufferSize)
	result.Split(bufio.ScanWords)
	return result
}()

func readString() string {
	stdinScanner.Scan()
	return stdinScanner.Text()
}

func readInt() int {
	result, err := strconv.Atoi(readString())
	if err != nil {
		panic(err)
	}
	return result
}


Measured memory_bytes: 640
#include<cstdio>
#include<cstring>
#include<algorithm>
const int MAXN=200010;

inline long long max(long long x,long long y){
	return x>y?x:y;
}
struct node{
	int l,r;
	long long val,tag;
}tr[MAXN<<2];
void upd(int o){
	tr[o].val=max(tr[o<<1].val,tr[o<<1|1].val);
}
void pushdown(int o){
	if(tr[o].tag){
		tr[o<<1].tag+=tr[o].tag;
		tr[o<<1].val+=tr[o].tag;
		tr[o<<1|1].tag+=tr[o].tag;
		tr[o<<1|1].val+=tr[o].tag;
		tr[o].tag=0;
	}
}
void build(int o,int l,int r){
	// puts("233");
	tr[o].l=l;tr[o].r=r;
	if(l>=r)
		return;
	int mid=(l+r)>>1;
	build(o<<1,l,mid);
	build(o<<1|1,mid+1,r);
}
void update(int o,int lt,int rt,long long v){
	// printf("%d %d %d\n",o,lt,rt);
	int l=tr[o].l,r=tr[o].r;
	if(lt<=l&&r<=rt){
		tr[o].tag+=v;
		tr[o].val+=v;
		return;
	}
	pushdown(o);
	int mid=(l+r)>>1;
	if(lt<=mid)
		update(o<<1,lt,rt,v);
	if(mid+1<=rt)
		update(o<<1|1,lt,rt,v);
	upd(o);
}
long long query(int o,int lt,int rt){
	// puts("666");
	int l=tr[o].l,r=tr[o].r;
	if(l==lt&&r==rt)
		return tr[o].val;
	pushdown(o);
	int mid=(l+r)>>1;
	if(rt<=mid)//Though it's impossible that lt>=mid+1
		return query(o<<1,lt,rt);
	else if(lt>=mid+1)
		return query(o<<1|1,lt,rt);
	else
		return max(query(o<<1,lt,mid),query(o<<1|1,mid+1,rt));
}

struct event{
	int l,r;
	long long a;
	bool operator<(const event &rhs)const{
		return r<rhs.r;
	}
}p[MAXN];
int n,m;

int main(){
	scanf("%d%d",&n,&m);
	for(int i=1;i<=m;i++)
		scanf("%d%d%lld",&p[i].l,&p[i].r,&p[i].a);
	std::sort(p+1,p+m+1);
	build(1,1,n);
	int tot=1;
	for(int i=1;i<=n;i++){
		update(1,i,i,query(1,1,i));
		while(p[tot].r<=i&&tot<=m){
			update(1,p[tot].l,p[tot].r,p[tot].a);
			tot++;
		}
		// if(i==5)return 0;
	}
	printf("%lld\n",max(0,tr[1].val));
	return 0;
}

Measured memory_bytes: 16512
#include <iostream>
#include <vector>
#include <string>
#include <map>
#include <set>
#include <stack>
#include <queue>
#include <cmath>
#include <algorithm>
#include <utility>
#include <functional>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
const int MOD = 1000000007;
const double EPS = 1e-9;


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

  int a,b,c;
  cin>>a>>b>>c;
  int ans;
  if(a == b && b == c) {
    ans = 1;
  } else if(a != b && b != c && c != a) {
    ans = 3;
  } else {
    ans = 2;
  }
  cout << ans << endl;

  return 0;
}


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

#define MAX 500000

int partition(int A[],int p,int r){
    int x = A[r];
    int i = p - 1;
    for(int j=p;j<r;j++){
        if(A[j]<=x){
            i++;
            swap(A[i],A[j]);
        }
    }
    swap(A[i+1],A[r]);
    return i+1;
}

int main(){
    int A[MAX],n,i;
    scanf("%d",&n);
    for(i=0;i<n;i++) scanf("%d",&A[i]);
    int q = partition(A,0,n-1);

    for(i=0;i<n;i++){
        if(i) printf(" ");
        if(i==q) printf("[");
        printf("%d",A[i]);
        if(i==q) printf("]");
    }
    printf("\n");

    return 0;
}

Measured memory_bytes: 3500
n,a=map(int,input().split())
x=list(map(int,input().split()))
for i in range(n):
    x[i]-=a
# dp[i][j] = i番目までで(j-2500)を何個作れるか
dp=[[0]*5001 for i in range(n+1)]
dp[0][2500]=1
for i in range(n):
    for j in range(5000):
        for k in range(2):
            if 0<=j-k*x[i]<=5000:
                dp[i+1][j]+=dp[i][j-k*x[i]]
print(dp[n][2500]-1)


Measured memory_bytes: 5604
#include<stdio.h>
#include<string.h>
int main(){
    int n;
    scanf("%d",&n);
    int block[n];
    for(int i = 0;i < n;i++){
        scanf("%d",&block[i]);
    }
    int num_ptr = 1;
    int mbrc = 0;
    for(int i = 0;i < n;i++){
        if(block[i] != num_ptr){
            mbrc++;
        }else{
            num_ptr++;
        }
    }
    if(num_ptr == 1){
        printf("-1");
        return 0;
    }
    printf("%d",mbrc);
    return 0;
}

Measured memory_bytes: 896
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i = 0, i##_len = (n); i < i##_len; ++i)
#define rep2(i, x, n) for(int i = x, i##_len = (n); i < i##_len; ++i)
#define all(n) begin(n), end(n)
using ll = long long;
using P = pair<ll, ll>;
using vi = vector<int>;
using vl = vector<ll>;
using vs = vector<string>;
using vc = vector<char>;
using vb = vector<bool>;
using vd = vector<double>;
vi dir = {-1, 0, 1, 0, -1, -1, 1, 1, -1};

int main() {
  ll h1, m1, h2, m2, k;
  cin >> h1 >> m1 >> h2 >> m2 >> k;
  cout << h2 * 60 + m2 - h1 * 60 - m1 - k << endl;
}

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

def sumOfDegits(n):
    sum = 0
    while n > 0:
        sum += n % 10
        n = n // 10
    return sum

min_sum = float('inf')

for i in range (1, N):
    a = sumOfDegits(i)
    b = sumOfDegits(N-i)
    if min_sum > a + b:
        min_sum = a + b

print(min_sum)

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

int main() {
  
  int A=0, B=0;
  
  cin >> A >> B;
  
  int mul = 2*B;
  
  if(mul<A) {
    
    cout << A - mul << endl;
    
  } else {
    
    cout << "0" << endl;
    
  }
  
  return 0;
  
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define REP(i,n) for(int i = 0;i < (int)(n);i++)
#define RREP(i,n) for(int i = (int)n-1;i >= 0;i--)
#define FOR(i,s,n) for(int i = s;i < (int)n;i++)
#define RFOR(i,s,n) for(int i = (int)n-1;i >= s;i--)
#define ALL(a) a.begin(),a.end()
#define IN(a, x, b) (a<=x && x<b)
template<class T>inline bool CHMAX(T&a,T b){if(a<b){a = b;return true;}return false;}
template<class T>inline bool CHMIN(T&a,T b){if(a>b){a = b;return true;}return false;}
template<class T>istream&operator >>(istream&is,vector<T>&vec){for(T&x:vec)is>>x;return is;}
template<class T>inline void OUT(T t){cout<<t<<"\n";}
template<class T,class... Ts>inline void OUT(T t,Ts... ts){cout<<t<<" ";OUT(ts...);}
template<typename T=int>vector<T>mv(size_t a){return vector<T>(a);}
template<typename T=int,typename... Ts>auto mv(size_t a,Ts... ts){return vector<decltype(mv<T>(ts...))>(a,mv<T>(ts...));}
template<typename T,typename V>typename enable_if<is_class<T>::value==0>::type FILL(T&t,const V&v){t=v;}
template<typename T,typename V>typename enable_if<is_class<T>::value!=0>::type FILL(T&t,const V&v){for(auto &e:t)FILL(e,v);}
constexpr long long INF = 1e18;
 
signed main(){
	int N;
	cin>>N;
	auto a = mv<pair<int,int>>(N);
	REP(i,N){
		cin>>a[i].first;
		a[i].second=i;
	}
	sort(ALL(a));
	reverse(ALL(a));
	multiset<int>st;
	REP(i,2)st.insert(-1);
	REP(i,2)st.insert(N);
	int ans = 0;
	REP(i,N){
		st.insert(a[i].second);
		auto itr = st.find(a[i].second);
		auto l = *prev(itr),ll = *prev(prev(itr));
		int r = *next(itr),rr = *next(next(itr));
		ans += (N-i)*(*itr-l)*(rr-r);
		ans += (N-i)*(l-ll)*(r-*itr);
	}
	cout<<ans<<endl;
}


Measured memory_bytes: 6528
#include <bits/stdc++.h>
#define rep(i,n)for(int i=0;i<(n);i++)
using namespace std;
 
int main(){
    vector<int>v;
    int q;cin>>q;
    rep(i,q){
        int a;cin>>a;
        if(a==0){
            int x;cin>>x;
            v.push_back(x);
        }
        else if(a==1){
            int x;cin>>x;
            cout<<v[x]<<endl;
        }
        else v.pop_back();
    }   
}


Measured memory_bytes: 3856
Imports System.Collections.Generic
Public Class Program
  Shared Sub Main()
    Dim ab As Integer() = Array.ConvertAll(Of String, Integer)(Console.ReadLine().Split(" "), AddressOf Integer.Parse)
    Dim a As Integer = ab(0)  
    Dim b As Integer = ab(1)
    Console.WriteLine(Math.Max(a + b, Math.Max(a - b, a * b)).ToString())
  End Sub
End Class

Measured memory_bytes: 13140
import sys 
import collections
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
N,P = map(int,readline().split())
S = list(map(int,readline().rstrip().decode()))

def solve_2(S):
    cnt = sum(i for i,x in enumerate(S,1) if x % 2 == 0)
    return cnt
def solve_5(S):
    cnt = sum(i for i,x in enumerate(S,1) if x % 5 == 0)
    return cnt
def solve(S):
    if P == 2:
        return solve_2(S)
    if P == 5:
        return solve_5(S)
    mod_cnt = [0]*(len(S))
    power = 1
    S = S[::-1]
    mod_cnt[0] = S[0] % P
    for i in range(1,len(S)):
        power *= 10
        power %= P
        mod_cnt[i] = (mod_cnt[i-1] + S[i] * power) % P
    c = collections.Counter(mod_cnt)
    cnt = sum( n*(n-1)//2 for n in c.values()) + c[0]
    return cnt

print(solve(S))

Measured memory_bytes: 20536
#include <iostream>
#include <cstdio>
#include <cmath>
#include <algorithm>
#include <vector>
#include <queue>
#include <stack>
#include <set>
#include <deque>
#include <string>
#include <cstring>
#include <iomanip>
#include <fstream>
#include <map>
#include <unordered_map>
#include <bitset>

#define _crt_secure_no_warnings
#define FREEELO ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define pb push_back
#define mp make_pair
#define INF 0x3F3F3F3F3F3F3F3F
#define MAX 300001
#define MOD 1000000007
#define ALPHABET 128
#define loop(i, n) for (int i = 1; i <= (n); i++)
#define loop0(i, n) for (int i = 0; i < (n); i++)
#define sz(x) (int)x.size()
#define all(v) v.begin(), v.end()
#define F first
#define S second
using namespace std;
typedef long long ll;
typedef double lf;
typedef pair<ll, ll> llll;
typedef pair<int, int> ii;
typedef unordered_map<int, int> umii;
typedef unordered_map<ll, ll> umll;

int main() {
    int n; cin >> n;
    vector<ii> v(n);
    for (auto &i : v) cin >> i.F >> i.S;
    int ans = 0;
    map<int, int> diff, sum;
    for (auto [a, b] : v){
        diff[a - b]++;
        sum[a + b]++;
    }
    auto rem = [&] (int v, map<int, int> &mp){
        int t = --mp[v];
        if (!t) mp.erase(v);
    };
    auto read = [&] (int v, map<int, int> &mp){
        mp[v]++;
    };
    for (auto [a, b] : v){
        rem(a - b, diff);
        rem(a + b, sum);
        if (!sum.empty()){
            int cur = a + b;
            auto iter = sum.begin();
            ans = max(ans, cur - iter->F);
        }
        if (!diff.empty()){
            int cur = -a + b;
            auto iter = prev(diff.end());
            ans = max(ans, cur + iter->F);
        }
        read(a - b, diff);
        read(a + b, sum);
    }
    cout << ans << endl;
}

Measured memory_bytes: 23108
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define For(i,n,k) for(ll i=(n);i<(k);i++)
#define ALL(a)  (a).begin(),(a).end()
string n;
int m,ans=0;
void Main(){
    cin>>n;
    if(n=="SUN") cout<<7<<endl;
    if(n=="MON") cout<<6<<endl;
    if(n=="TUE") cout<<5<<endl;
    if(n=="WED") cout<<4<<endl;
    if(n=="THU") cout<<3<<endl;
    if(n=="FRI") cout<<2<<endl;
    if(n=="SAT") cout<<1<<endl;
}
int main(){
    Main();
    return 0;
}


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

typedef long long ll;
#define ar array
#define vi vector<int>
#define vvi vector<vector<int>>
#define vll vector<long long>
#define all(x) (x).begin(), (x).end()
#define en '\n'
#define FILL(x, v) memset(x, v, sizeof(x))
#define pb push_bacn
#define fast                     \
	ios::sync_with_stdio(false); \
	cin.tie(NULL);               \
	cout.tie(NULL);
#define F_OR(i, a, b, s) for (int i = (a); ((s) > 0 ? i < (b) : i > (b)); i += (s))
#define F_OR1(e) F_OR(i, 0, e, 1)
#define F_OR2(i, e) F_OR(i, 0, e, 1)
#define F_OR3(i, b, e) F_OR(i, b, e, 1)
#define F_OR4(i, b, e, s) F_OR(i, b, e, s)
#define GET5(a, b, c, d, e, ...) e
#define F_ORC(...) GET5(__VA_ARGS__, F_OR4, F_OR3, F_OR2, F_OR1)
#define FOR(...)       \
	F_ORC(__VA_ARGS__) \
	(__VA_ARGS__)

#define E_ACH2(x, a) for (auto &x : a)
#define E_ACH3(x, y, a) for (auto &[x, y] : a)
#define E_ACH4(x, y, z, a) for (auto &[x, y, z] : a)
#define E_ACHC(...) GET5(__VA_ARGS__, E_ACH4, E_ACH3, E_ACH2)
#define EACH(...)       \
	E_ACHC(__VA_ARGS__) \
	(__VA_ARGS__)

template <typename A, typename B>
inline void chmin(A &a, B b)
{
	if (a > b)
		a = b;
}
template <typename A, typename B>
inline void chmax(A &a, B b)
{
	if (a < b)
		a = b;
}

int main()
{
	fast;
	int h, n;
	cin >> h >> n;
	vi dp(h + 1, 1e8 + 1);
	dp[0] = 0;
	FOR(n)
	{
		int health, point;
		cin >> health >> point;
		for (int j = 1; j < h + 1; j++)
			dp[j] = min(dp[j], (j - health > 0 ? dp[j - health] : 0) + point);
	}
	cout << dp[h];
}

Measured memory_bytes: 3692
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <cstring>
#include <climits>
#include <vector>
#include <map>
#include <set>
#include <list>
#include <stack>
#include <queue>
#include <algorithm>
#include <iostream>
#include <string>

#define REP(i,n) for(auto i=0;i<n;++i)
#define REPR(i,n) for(auto i=n;i>=0;--i)
#define REPI(itr,v) for(auto itr=v.begin();itr!=v.end();++itr)
#define REPIR(itr,v) for(auto itr=v.rbegin();itr!=v.rend();++itr)
#define FOR(i,a,b) for(auto i=a;i<b;++i)
#define SORT(v,n) sort(v, v+n)
#define SORTV(v) sort(v.begin(), v.end())
#define ALL(v) v.begin(),v.end()
#define llong long long
#define ll long long
#define INF 999999999
#define MOD 1000000007
#define pb push_back
#define pf push_front
#define MP make_pair
#define SV(n,v) {int tmp;for(int i=0;i<n;++i){scanf("%d",&tmp);v.push_back(tmp);}}

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

using namespace std;

typedef pair<int,int> pii;

int main(){

  llong n, k;
  cin >> n >> k;

  vector<llong> v(n);
  REP(i,n){
    cin >> v[i];
  }

  llong ans = 0;
  for(int len = 1; len <= k && len <= n; ++len){
    //if(len <= k - len) continue;
    REP(i,len+1){

      int j = len - i;
      priority_queue<llong, vector<llong>, greater<llong> > que, que2;
      for(int ii = 0; ii < i; ++ii){
        que.push(v[ii]);
        que2.push(v[ii]);
      } 
      for(int ii = 0; ii < j; ++ii){
        que.push(v[n-ii-1]);
        que2.push(v[n-ii-1]);
      }
/*
      if((k - len) % 2 == 0){
        llong sum = 0;
        while(!que2.empty()){
          llong tp = que2.top();
          que2.pop();
          sum += tp;
        }
        ans = max(ans, sum);
      }else{
        llong sum = 0;
        if(!que2.empty()) que2.pop();
        while(!que2.empty()){
          llong tp = que2.top();
          que2.pop();
          sum += tp;
        }
        ans = max(ans, sum);
      }
*/
      int out = k - len;

      bool ff = false;
      llong tp2 = 0;
      REP(ii,out){
        if(que.empty()) break;

        llong tp = que.top();
        if((k-len) % 2 == 0){
          if(tp > 0) break;
        }else{
          if(tp > 0){
            ff = true;
            break;
          }
        }
        tp2 = tp;
        que.pop();
      }


      llong sum = 0;
      bool f = true;
      llong tp3 = 0;
      while(!que.empty()){
        llong tp = que.top();
        //cout << tp << endl;
        if(f){
          tp3 = tp;
          f = false;
        }
        que.pop();
        sum += tp;
        //cout << que.size() << endl;
      }
      if((k-len) % 2 == 0) ans = max(ans, sum);
      else{
        if(ff){
          ans = max(ans, sum - tp3);
          ans = max(ans, sum + tp2);
        }else{
          ans = max(ans, sum);
        }
      }
    }

  }

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



Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<cmath>
using namespace std;
int a[5],t,mi=1e9;
int main()
{
    cin.sync_with_stdio(false);
    cout.sync_with_stdio(false);
    for(int i=1;i<=3;i++)
        cin>>a[i];
    do
    {
        t=0;
        for(int i=2;i<4;i++)
            t+=abs(a[i-1]-a[i]);
        mi=min(mi,t);
    }while(next_permutation(a+1,a+4));
    cout<<mi;
}


Measured memory_bytes: 256