akhauriyash/Code-Regression huggingface dataset:
#include<stdio.h>
#define N 8
#define NOT_FREE 1
#define FREE 0

int putQueen(int);
int Board[N][N] = {};
int row[N] = {}, col[N] = {}, dpos[2*N-1] = {}, dneg[2*N-1] = {};

int main(){
  int k, r, c;
  int i;

  scanf("%d", &k);

  for(i = 0; i < k; i++){
    scanf("%d %d", &r, &c);
    Board[r][c] = row[r] = col[c] = dpos[r+c] = dneg[r-c+N-1] = NOT_FREE;
  }

  putQueen(0);
  
  return 0;
}

int putQueen(int i){
  int j, k, l;
  if(i == N){
    for(k = 0; k < N; k++){
      for(l = 0; l < N; l++){
	if(Board[k][l] == FREE)
	  printf(".");
	else
	  printf("Q");
      }
      printf("\n");
    }
    return;
  }
  if(row[i] == NOT_FREE)
    putQueen(i+1);
  else{
    for(j = 0; j < N; j++){
      if(col[j] == NOT_FREE || dpos[i+j] == NOT_FREE || dneg[i-j+N-1] == NOT_FREE)
	continue;
      col[j] = dpos[i+j] = dneg[i-j+N-1] = Board[i][j] = NOT_FREE;
      putQueen(i+1);
      col[j] = dpos[i+j] = dneg[i-j+N-1] = Board[i][j] = FREE;
    }
  }
}

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

#define REP(i, x, n) for (int i = x; i < (int)(n); i++)
#define rep(i, n) REP(i, 0, x);
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()

using namespace std;

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

int lcm(int a, int b) { return a * b / gcd(a, b); }

int main(void) {
  string a, b, c;
  cin >> a >> b >> c;
  char &ab = a.back();
  char &bf = b.front();
  char &bb = b.back();
  char &cf = c.front();
  if (ab == bf && bb == cf) {
    cout << "YES" << endl;
  } else {
    cout << "NO" << endl;
  }
  return 0;
}

Measured memory_bytes: 256
//ABC123B
#include <bits/stdc++.h>
#include <iostream>
#include <iomanip>
#include <numeric>
#include <math.h>
using namespace std;

int main(){
	string s;
	cin >> s;
	int n = s.size();
	vector <int> count(n);
	int j=0;
	for(int i=0;i<n;i++){
		if(s.at(i) == 'A' || s.at(i) == 'C' || s.at(i) == 'G' || s.at(i) == 'T'){
			count.at(j)++;
		}else{
			j++;
		}
	}
	int temp = count.size();
	sort(count.begin(),count.end());
	cout << count.at(temp-1);
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <cstring>
#include <vector>
#include <stack>

using namespace std;

typedef long long LL;
typedef pair<int,int> pii;
typedef vector<int> vi;

#define FOR(i,a,b) for (int i=a;i<b;i++)

char arr[53][53];
bool used[53][53];
int H, W;
bool inside(int r, int c){return 0<=r && 0<=c && r<H && c<W;};
int dr[] = {1,0,-1,0};
int dc[] = {0,1,0,-1};
int main(){
    scanf("%d %d",&H,&W);
    FOR(i,0,H) scanf("%s",arr[i]);
    memset(used,0,sizeof(used));
    bool flag = 1;
    FOR(i,0,H){
        FOR(j,0,W){
            if (!used[i][j] && arr[i][j]=='#'){
                int cnt = 0;
                used[i][j]=1;
                stack<pii> s;
                s.push(make_pair(i,j));
                while (!s.empty()){
                    pii u = s.top();
                    cnt++;
                    s.pop();
                    FOR(i,0,4){
                        int x = u.first+dr[i],y = u.second+dc[i];
                        if (inside(x,y) && !used[x][y] && arr[x][y]=='#'){
                            used[x][y]=1;
                            s.push(make_pair(x,y));
                        }
                    }
                }
                flag &= (cnt!=1);
                if (!flag) break;
            }
        }
    }
    puts(flag ? "Yes" : "No");
    return 0;
}

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

int main() {
    long long a,b,k;
    cin >> a >> b >> k ;
    if(a>=k){
        cout << a-k << endl;
        cout << b << endl;
    }
    else{
        cout << 0 << endl;
        if(a+b>=k){
            cout << b-(k-a) << endl;
        }
        else{
            cout << 0 << endl;
        }
    }
}

Measured memory_bytes: 256
#include <cstdio>
using namespace std;

const int MAXN = 1e5 + 1;

int n, k;
int a[MAXN];
int sol;

int main(){

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

    sol = (n-1)/(k-1);
    if ((n-1) % (k-1) > 0) sol++;

    printf("%d", sol);

}

Measured memory_bytes: 512
package main

import (
	"fmt"
)

const MOD = 1000000007

func ModAdd(a, b int64) int64 {
	return (a + b) % MOD
}

func ModMul(a, b int64) int64 {
	return a * b % MOD
}

func ModSub(a, b int64) int64 {
	r := (a%MOD - b%MOD) % MOD
	if r < 0 {
		r += MOD
	}
	return r
}

func ModDiv(a, b int64) int64 {
	return a % MOD * ModInv(b) % MOD
}

func ModPow(a, n int64) int64 {
	var r int64 = 1
	for n > 0 {
		if n&1 == 1 {
			r = r * a % MOD
		}
		a = a * a % MOD
		n >>= 1
	}
	return r
}

func ModInv(a int64) int64 {
	var b, u, v int64 = MOD, 1, 0
	for b > 0 {
		t := a / b
		a -= t * b
		a, b = b, a
		u -= t * v
		u, v = v, u
	}
	u %= MOD
	if u < 0 {
		u += MOD
	}
	return u
}

type Q struct {
	idx, value int
	a, b       int
	index      int
}

type QS []*Q

func (p QS) Len() int           { return len(p) }
func (p QS) Less(i, j int) bool { return p[i].value > p[j].value }
func (pq QS) Swap(i, j int) {
	pq[i], pq[j] = pq[j], pq[i]
	pq[i].index = i
	pq[j].index = j
}

func (pq *QS) Push(x interface{}) {
	n := len(*pq)
	item := x.(*Q)
	item.index = n
	*pq = append(*pq, item)
}

func (pq *QS) Pop() interface{} {
	old := *pq
	n := len(old)
	item := old[n-1]
	old[n-1] = nil  // avoid memory leak
	item.index = -1 // for safety
	*pq = old[0 : n-1]
	return item
}

func main() {
	var A, B int
	fmt.Scanf("%d %d\n", &A, &B)
	diff := A + B
	if diff%2 == 0 {
		fmt.Println(diff / 2)
	} else {
		fmt.Println("IMPOSSIBLE")

	}
}


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

int main(void){
  int n;
  cin >> n;

  if(n==0){
    cout << "2" << endl;
    return 0;
  }
  else if(n==1){
    cout << "1" << endl;
    return 0;
  }
  else{
    vector<long long int> l(n+1);
    l.at(0)=(long long int)2;
    l.at(1)=(long long int)1;
    for(int i=2;i<=n;i++){
      l.at(i)=l.at(i-1)+l.at(i-2);
    }
    cout << l.at(n) << endl;
  }
  
  return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
 
#define int long long 
#define ll long long 
#define pb push_back
#define mp make_pair
#define pii pair<ll,ll>
#define ff first
#define ss second
#define vi vector<ll>
#define mod 1000000007
#define MOD 1000000007
#define full(a) a.begin(),a.end()
#define inf INT_MAX
#define minf INT_MIN
#define dd double
#define fori(x,n) for(ll i=x;i<n;i++)
#define modd 998244353
#define umap unordered_map<ll,ll>
// dp + bitmasking 
ll dp[22][(1<<22)];
ll n;

ll fun(ll i,ll a[][21],ll women_subset){
  if(i==n){                       // when no man is left 
    if(women_subset==0)return 1;  // when no woman is also not left
    else return 0;
  }

  if(dp[i][women_subset]!=-1)return dp[i][women_subset];

  ll ans = 0;
  for(int j=0;j<n;j++){
    ll cond = ((women_subset&(1<<j))?1:0);    // finding the jth bit of women_subset to know about the woman taken or not
    if(cond and a[i][j]==1)
    ans = (ans + fun(i+1,a,women_subset ^ (1<<j)))%mod;   // through xor operation we are taking that woman and making its bit = 0 in women_subset
  }

  return dp[i][women_subset]=ans;
}






int32_t main() 
{ 
  
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
 
    #ifndef ONLINE_JUDGE
    freopen("input.txt","r",stdin);
    freopen("output.txt","w",stdout);
    #endif
  
 
   cin>>n;
   ll a[n][21];
   for(int i=0;i<n;i++)
    for(int j=0;j<n;j++)cin>>a[i][j];

      memset(dp,-1,sizeof dp);


  cout<<fun(0,a,(1<<n)-1);


    
    
 
return 0;
}    

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

int n, a[200003], b[200003];

int main(){
	cin >> n;
	for (int i=0;i<n;i++) cin >> a[i] >> b[i];
	sort(a,a+n);
	sort(b,b+n);
	if (n&1) cout << b[n/2]-a[n/2]+1 << "\n";
	else cout << b[n/2]+b[n/2-1]-a[n/2]-a[n/2-1]+1 << "\n";
}

// 1 2
// 2 4
// 5 5
// 7 9
// 9 10

Measured memory_bytes: 5124
#include<iostream>
#include<string>
#include<algorithm>

using namespace  std;
 int main(){
    int h,n;
    int a;
    int flag = 0;
    cin >> h >> n;
    for(int i=0;i<=n;i++){
        if(i!=n)cin >> a;
        if(h<=0){
            cout << "Yes" << endl;
            flag=1;
            break;
        }
        if(i==n) break;
        h -= a;
    }
    if(!flag) cout << "No" << endl;
    return 0;
}

Measured memory_bytes: 888
#pragma GCC optimize("Ofast",3,"inline")
#include <bits/stdc++.h>
using namespace std;
int n,m,q;
long long a[100050];
int data[100050];
int main(){
	ios_base::sync_with_stdio(false);
	cin>>n>>m>>q;
	for(int i=0;i<n;i++) a[i]=m;
	for(int i=0;i<q;i++)cin>>data[i],data[i]--,a[data[i]]++;
	for(int i=0;i<n;i++) if(a[i]-q<1)cout<<"No\n";else cout<<"Yes\n";
	return 0;
}


Measured memory_bytes: 1792
#include <iostream>
using namespace std;
#define rep(i,n) for(int i=0;i<n;i++)
int main(){
	int digit[5];
	int view[5];
	string s;
	int c = 0;
	while(cin >> s){
		if(c++)cout << endl;
		rep(i,5)digit[i]=0;
		rep(i,s.length()){
			digit[5-s.length()+i] = s[i]-'0';
		}
		rep(i,5)
			if(digit[i]<5)cout << "*";
			else cout << " ";
		cout << endl;
		rep(i,5)
			if(digit[i]>=5)cout << "*";
			else cout << " ";
		cout << "\n=====\n";
		rep(i,5){
			view[i] = digit[i]%5;
		}
		rep(i,5){
			rep(j,5){
				if(view[j]--)cout << "*";
				else cout << " ";
			}
			cout << endl;
		}
	}
}

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

int main()
{
	string _S, T;	cin >> _S >> T;
	vector<string> ans;
	string str = "";
	bool b = true;
	bool b2 = false;
	rep(i, _S.size() - T.size() + 1) {
		b = true;
		b2 = false;
		if (_S[i] == '?' || _S[i] == T[0]) {
			rep(j, T.size()) {
				if (_S[i + j] != '?'&&_S[i + j] != T[j]) {
					b = false;
					break;
				}
			}
			if (b) {
				if (i == 0) {
					str = T + _S.substr(T.size());
					b2 = true;
				}
				else if (i == _S.size() - T.size()) {
					str = _S.substr(0, i) + T;
					b2 = true;
				}
				else {
					str = _S.substr(0, i) + T + _S.substr(i + T.size());
					b2 = true;
				}
			}
		}
		if(b&&b2)	ans.push_back(str);
	}
	if (ans.empty()) {
		cout << "UNRESTORABLE" << endl;
		cin >> T;
		return 0;
	}
	rep(i, ans.size()) {
		rep(j, ans[i].size()) {
			if (ans[i][j] == '?') {
				ans[i][j] = 'a';
			}
		}
	}
	sort(ans.begin(), ans.end());
	cout << ans[0] << endl;
	cin >> _S;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define M 1000000007
#define U 998244353
#define N 1000005
#define int long long
#define sz(c) (int)c.size()
#define fr first
#define ll long long 
#define sc second
#define pb push_back
#define ppb pop_back
#define mp make_pair
#define all(a) (a).begin(),(a).end()
#define rep(i,a,n) for(int i=a ; i<n ; i++)
#define r0 return 0;
#define endl '\n'
#define INF (int)1e15
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>
void __f(const char* name, Arg1&& arg1){
	std::cerr << name << " : " << arg1 << endl;
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args){
	const char* comma = strchr(names + 1, ',');std::cerr.write(names, comma - names) << " : " << arg1<<" | ";__f(comma+1, args...);
}
bool pos[81][81][16100];
bool neg[81][81][16100];
signed main()
{
	ios_base::sync_with_stdio(0);
	int TESTS=1;
	// cin>>TESTS;
	while(TESTS--)
	{   
		int h,w;
		cin>>h>>w;
		int a[h][w],b[h][w],dp[h][w];
		rep(i,0,h){
			rep(j,0,w) cin>>a[i][j];
		}
		rep(i,0,h){
			rep(j,0,w) cin>>b[i][j];
		}
		int grid[h][w];
		rep(i,0,h){
			rep(j,0,w) grid[i][j] = abs(a[i][j]-b[i][j]);
		}
		rep(i,0,h){
			rep(j,0,w)
			rep(k,0,16100) {
				pos[h][w][k]=0;
				neg[h][w][k]=0;
			}
		}
		pos[0][0][abs(grid[0][0])]=1;
		neg[0][0][abs(grid[0][0])]=1;
		rep(i,0,h){
			rep(j,0,w){
				if(i){
					rep(k,0,16100){

						if(pos[i-1][j][k]){
							if(k+grid[i][j]<16100)
								pos[i][j][k+grid[i][j]] = 1;
							if(0<=k-grid[i][j] && k-grid[i][j]<16100)
								pos[i][j][k-grid[i][j]] = 1;
							else if(-16100<k-grid[i][j] && k-grid[i][j]<0)
								neg[i][j][-k+grid[i][j]] = 1;
						}
						if(neg[i-1][j][k]){
							if(k+grid[i][j]<=16000)
								neg[i][j][k+grid[i][j]] = 1;
							if(0<=-k+grid[i][j] && -k+grid[i][j]<16100)
								pos[i][j][-k+grid[i][j]] = 1;
							else if(-16100<-k+grid[i][j] && -k+grid[i][j]<0)
								neg[i][j][k-grid[i][j]] = 1;
						}
					}
				}
				if(j){
					rep(k,0,16100){
						if(pos[i][j-1][k]){
							if(k+grid[i][j]<16100)
								pos[i][j][k+grid[i][j]] = 1;
							if(0<=k-grid[i][j] && k-grid[i][j]<16100)
								pos[i][j][k-grid[i][j]] = 1;
							else if(-16100<k-grid[i][j] && k-grid[i][j]<0)
								neg[i][j][-k+grid[i][j]] = 1;
						}
						if(neg[i][j-1][k]){
							if(k+grid[i][j]<=16000)
								neg[i][j][k+grid[i][j]] = 1;
							if(0<=-k+grid[i][j] && -k+grid[i][j]<16100)
								pos[i][j][-k+grid[i][j]] = 1;
							else if(-16100<-k+grid[i][j] && -k+grid[i][j]<0)
								neg[i][j][k-grid[i][j]] = 1;
						}
					}
				}
			}
		}
		// trace(pos[0][1][8], pos[1][1][3],neg[1][2][2]);
		int ans = INT_MAX;
		rep(k,0,16100){
			if(pos[h-1][w-1][k]) ans = min(ans,k);
			if(neg[h-1][w-1][k]) ans = min(ans,k);
		}
		cout<<ans;
	}   
}     

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

#define what_is(x) cout << #x << " is " << x << endl;
#define PI acos(-1)
#define hell 1000000007
#define HELL 998244353
#define io ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0)
#define fix(n) cout << fixed << setprecision(n)
#define mset(a,n) memset(a,n,sizeof a)
#define rep(i,a,b) for (__typeof((b)) i=(a);i<(b);i++)
#define repp(i,a,b,p) for(__typeof((b)) i=(a);i<(b);i+=p)
#define ren(i,a,b) for(__typeof((a)) i=(a);i>=(b);i--)
#define renn(i,a,b,p) for(__typeof((a) i=(a);i>=(b);i-=p)
#define ADD(a,b,c) ((a)%c+(b)%c)%c
#define SUB(a,b,c) ((a)%c-(b)%c+c)%c
#define MUL(a,b,c) (((a)%c)*((b)%c))%c
#define lbd lower_bound
#define ubd upper_bound
#define ll long long
#define ld long double
#define pb push_back
#define fi first
#define se second
#define vll vector<ll>
#define pll pair<ll,ll>
#define vpll vector<pll>
#define all(v) (v).begin(), (v).end()
#define sz(x) (ll)x.size()
// #define out(n) cout<<n<<" "
#define outl(n) cout<<n<<endl
#define bug(n) {outl(n);return;}
#define pii pair<int,int>
#define lim 9223372036854775805
#define ninf -9223372036854775802
#define M 1000000007
#define eps 1e-9
#define MAX 10
#define N 500001
#define db(a) for(auto it:a) {cout<<it<<" ";}cout<<endl;
ll prime[MAX];
ll fact[MAX];

const long long INF64 = 1e18;
ll vpow(ll a,ll b,ll p){
    if(b==0)
        return 1;
    if(b==1)
            return a;
    ll temp=vpow(a,b/2,p);
    temp*=temp;
    temp%=p;
    if(b%2==0)
        return temp;
    temp=temp*a;
    temp%=p;
    return temp;
}

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


ll inverseMod(ll a,ll b,ll p){
    if(b==0)
        return 1;
    ll temp=vpow(b,p-2,p);
    ll ans=temp*a;
    ans%=p;
    return ans;
}
void sieve()
{
    prime[0] = prime[1] = 1;
    for (ll i = 2; i < MAX; i++) {
        if (prime[i] == 0) {
            for (int j = i * 2; j < MAX; j += i) {
                if (prime[j] == 0) {
                    prime[j] = i;
                }
            }
            prime[i] = i;
        }
    }
}
ll max(ll a, ll b)
{
    return a>b?a:b;
}

void factorial(){
    fact[0]=1;
    fact[1]=1;
    rep(i,2,MAX){
        fact[i]=(fact[i-1]*i);
        // fact[i]%=M;
    }
}
ll rand(ll a,ll b){
    return a+rand()%(b-a+1);
}

void solve(ll ttt){
    string s,t;
    cin>>s>>t;
    int n=s.size(),m=t.size(),i,count=0,ans=INT_MAX,j;
    for(i=0;i<=n-m;i++)
    {
        count=0;
        for(j=0;j<m;j++)
        {
            if(s[i+j]!=t[j])
                count++;
        }
        ans=min(ans,count);
    }
    cout<<ans<<endl;
    return;

}

int main(){
    io;
    // sieve();
    // factorial();
#ifndef ONLINE_JUDGE
    //
    //freopen("input1.txt","r",stdin);
    // freopen("output1.txt","w",stdout);
#endif
    ll t=1;
     //cin>>t;
    fix(12);
    rep(q,1,t+1){
         //cout<<"Case #"<<q<<": ";
         solve(q);
    }
    return 0;

}




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

// macro
#define rep(i,n) for(int i=0;i<n;i++)
#define ll long long
#define all(v) v.begin(), v.end()

// code starts
int main()
{
  string s;cin>>s;
  if(s[0]==s[1]&&s[1]==s[2])cout<<"No"<<endl;
  else cout<<"Yes"<<endl;
}


Measured memory_bytes: 764
#![allow(unused, non_snake_case, dead_code, non_upper_case_globals)]
use std::cmp::*;
use std::collections::*;
use std::mem::*;

fn main() {
    let (r, w, e) = (std::io::stdin(), std::io::stdout(), std::io::stderr());
    let mut io = IO::new(r.lock(), w.lock(), e.lock());
    assert_eq!(!0usize, std::usize::MAX); //🙊
    assert!(0 == 0); //😇

    let a = io.chars();
    let b = io.chars();
    if a.len() > b.len() {
        io.writeln("GREATER");
    } else if b.len() > a.len() {
        io.writeln("LESS");
    } else {
        for (&a, &b) in a.iter().zip(b.iter()) {
            if a > b {
                io.writeln("GREATER");
                return;
            }
            if b > a {
                io.writeln("LESS");
                return;
            }
        }
        io.writeln("EQUAL");
    }
}

static MX: usize = 1010101;
static MOD: i64 = 1000000007;
static INF: i64 = std::i64::MAX >> 1;
// IO
use std::io::*;
struct IO<R: Read, W: Write, E: Write> {
    Read: R,
    Write: BufWriter<W>,
    Error: BufWriter<E>,
}
impl<R: Read, W: Write, E: Write> IO<R, W, E> {
    fn new(r: R, w: W, e: E) -> IO<R, W, E> {
        IO {
            Read: r,
            Write: BufWriter::new(w),
            Error: BufWriter::new(e),
        }
    }
    fn read<T>(&mut self) -> T
    where
        T: std::str::FromStr,
    {
        let next: String = self
            .Read
            .by_ref()
            .bytes()
            .map(|c| c.unwrap() as char)
            .skip_while(|c| c.is_whitespace())
            .take_while(|c| !c.is_whitespace())
            .collect();
        next.parse().ok().unwrap()
    }
    fn chars(&mut self) -> Vec<char> {
        self.read::<String>().chars().collect()
    }
    fn chari(&mut self) -> Vec<i64> {
        self.chars()
            .iter()
            .map(|&c| (c as u8 - b'0') as i64)
            .collect::<Vec<i64>>()
    }
    fn readn<T: std::str::FromStr>(&mut self, n: usize) -> Vec<T> {
        (0..n).map(|_| self.read::<T>()).collect::<Vec<_>>()
    }
    fn readmat<T: std::str::FromStr>(&mut self, n: usize, m: usize) -> Vec<Vec<T>> {
        (0..n).map(|_| self.readn(m)).collect()
    }
    fn write<S: ToString>(&mut self, val: S) {
        self.Write.write(val.to_string().as_bytes());
    }
    fn writeln<S: ToString>(&mut self, val: S) {
        self.Write.write(val.to_string().as_bytes());
        self.Write.write(b"\n");
    }
    fn debug<S: std::fmt::Debug>(&mut self, val: S) {
        writeln!(self.Error, "(debug) {:?}", &val);
    }
    fn debug2<S: std::fmt::Debug, T: std::fmt::Debug>(&mut self, val1: S, val2: T) {
        writeln!(self.Error, "(debug2) {:?} -> {:?}", val1, val2);
    }
    fn debug3<S: std::fmt::Debug, T: std::fmt::Debug, U: std::fmt::Debug>(
        &mut self,
        val1: S,
        val2: T,
        val3: U,
    ) {
        writeln!(
            self.Error,
            "(debug3) {:?} -> {:?} -> {:?}",
            val1, val2, val3
        );
    }
}


Measured memory_bytes: 4352
#include<bits/stdc++.h>
using namespace std;
int main(){
	
	int n; cin >> n;
	string s;
	cin>>s;
	
	vector<int> v;
	
	for(int i=0;i<n;i++){
		if(s[i] == ')'){
			if(v.size() == 0 || v.back() == 0){
				v.push_back(0);
			}
			else{
				if(v.back())
				  v.pop_back();
			}
		}
		else{
			v.push_back(1);
		}
	}
	
//	cout << v.size();
    for(auto i : v){
    	if(i == 0)
	      s.insert(s.begin(),'(');
		else 
		  s.push_back(')');
	}
  	cout << s;	    	
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using lint = long long;
using pint = pair<int, int>;
using vi = vector<int>;
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define all(v) v.begin(), v.end()

template<typename T> T gcd(T a, T b) { return b ? gcd(b, a%b) : a; }
template<typename T> T lcm(T a, T b) { return a / gcd(a, b) * b; }
template<class T> void corner(bool flg, T hoge) { if (flg) { cout << hoge << endl; exit(0); } }

const int MOD = 1000000007;

int main() {
    lint H;
    cin >> H;

    lint t = H;
    lint c = 0;

    while (t > 0) {
        c++;
        t /= 2;
    }

    lint res = 0;

    rep(i, c) {
        res += pow(2, i);
    }

    cout << res << endl;
    return 0;
}


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

int c(int num, int den) {
	int ret = num/den + 1;
	if(num % den == 0) --ret;
	return ret;
}

int main() {
	int n, h, w;
	cin >> h >> w >> n;
	int ans = min(c(n, h), c(n, w));
	cout << ans;
	return 0;
}

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

bool multi_check(vector<string> v, int t){
  for(int i=0; i<t; i++){
    if(v[i]==v[t]) return false;
  }
  return true;
}

int main(){
  int N;
  cin >> N;
  vector<string> v(N);
  for(int i=0; i<N; i++){
    cin >> v[i];
    if(!multi_check(v,i)){
      cout << "No" <<endl;
      return 0;
    }
  }
  for(int i=1; i<N; i++){
    string s=v[i-1];
    string t=v[i];
    if(s[s.size()-1]!=t[0]){
      cout << "No" <<endl;
      return 0;
    }
  }
  cout << "Yes" <<endl;
}

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

int main() {
    string s;cin>>s;
    int ans = 0;
    if(s[0]==s[1] && s[0]==s[2])ans=1;
    if(s[1]==s[2] && s[1]==s[3])ans=1;
    
    if(ans==1)cout<<"Yes"<<endl;
    else cout<<"No"<<endl;

	return 0;
}

Measured memory_bytes: 3564
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, begin, end) for (int i = begin; i < (int)(end); i++)
#define all(v) v.begin(), v.end()
const int MOD = 1000000007;

int main()
{
    char b;
    cin >> b;
    if (b == 'A')
    {
        cout << 'T' << endl;
    }
    else if (b == 'T')
    {
        cout << 'A' << endl;
    }
    else if (b == 'G')
    {
        cout << 'C' << endl;
    }
    else
    {
        cout << 'G' << endl;
    }
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>

using namespace std;

long n, k;
long long talWwight;
int weight[100000];

bool justss(long long p) {
	long s = 0;
	long long tt = 0;
	for (long i = 0; i < k; ++i) {
		tt = 0;
		while ((tt + weight[s]) <= p) {
			
			tt += weight[s];
			s++;
			if (s >= n)
				return 1;
		}
	}
	return 0;
}


int main() {
	cin >> n >> k;
	for (int i = 0; i < n; ++i) {
		cin >> weight[i];
	}
	long long p = n * 10000;
	long long max = p;
	long long mid;
	long long min = 0;
	while (max > min +1) {
		mid = (max + min) / 2;
		bool ju = justss(mid);
		if (ju) {
			max = mid;
		}
		else if(!ju) {
			min = mid;
		}
	
	}
	cout <<max <<endl;
	cin >> p;
	return 0;
}


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

int main() {
  int a,b,c;
  cin >> a >>b >>c ;
  
  vector<int> vec = {a,b,c};
    sort(vec.begin(), vec.end());
  
 
     cout << (vec.at(2))*10+vec.at(0) +vec.at(1) << endl;
}
  




Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < n; ++i)
#define ALL(c) (c).begin(), (c).end()
#define SUM(x) std::accumulate(ALL(x), 0LL)
#define MIN(v) *std::min_element(v.begin(), v.end())
#define MAX(v) *std::max_element(v.begin(), v.end())
#define EXIST(v, x) (std::find(v.begin(), v.end(), x) != v.end())
using namespace std;

using ll = long long;

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> inline void dump(vector<T> v) { for (auto& x : v) cerr << x << " "; cerr << endl; }
template<class T> inline void dump(vector<pair<T, T>> v) { for (auto& p : v) cerr << p.first << " " << p.second << endl; }
template<class T> inline void dump(vector<vector<T>> vv) { for (auto& v : vv) {for (auto& x : v) cerr << x << " "; cerr << endl;} }

constexpr int INF = 1e9+5;
constexpr long long INFLL = 1LL<<60;
constexpr double eps = (1e-9);

using P = pair<int, int>;

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

  int n;
  cin >> n;
  vector<P> c;
  rep(i, n) {
    int x, y;
    cin >> x >> y;
    c.push_back({x, y});
  }

  double sum = 0.0;

  vector<int> order(n);
  rep(i, n) order[i] = i;
  int num = 0;

  do {
    num++;
    double x = 0.0;
    for (int i = 0; i < n - 1; i++) {
      x += sqrt(pow(c[order[i]].first - c[order[i+1]].first, 2) + pow(c[order[i]].second - c[order[i+1]].second, 2));
    }
    sum += x;
  } while (next_permutation(order.begin(), order.end()));

  printf("%.10lf\n", sum / num);

  return 0;
}


Measured memory_bytes: 3740
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <numeric>
#include <utility>
#include <cmath>
#include <iomanip>
#include <map>
#include <stack>

using namespace std;
typedef long long ll;
typedef pair<int, int> ii;

#define REP(i,n) for(int i=0;i<(int)(n);++i)
#define REP2(i,n,s) for(int i=(int)(s);i<(int)(n);++i)
#define RREP(i,n,s) for(int i=(int)(s);i>=(int)(n);--i)
#define FOR(i,c) for(__typeof((c).begin())i=(c).begin(),ie=(c).end();i!=ie;++i)
#define ALL(c) (c).begin(), (c).end()

int main() {
    int n,m;cin>>n>>m;
    vector<int> p(n);
    REP(i,n) {
        int q; cin>>q; q--;
        p[i] = q;
    }

    vector<vector<int>> e(n, vector<int>(0));
    REP(i,m) {
        int x,y;cin>>x>>y;
        x--;y--;
        e[x].push_back(y);
        e[y].push_back(x);
    }

    int rabels[n];
    fill(rabels, rabels+n, 0);
    int rabel = 0;
    bool b[n];
    fill(b, b+n, false);
    REP(i,n) {
        if(b[i]) continue;
        rabel++;

        stack<int> q;
        q.push(i);
        b[i] = true;
        rabels[i] = rabel;
        while(!q.empty()) {
            int x = q.top();
            q.pop();

            FOR(j, e[x]) {
                if(!b[*j]) {
                    q.push(*j);
                    b[*j] = true;
                    rabels[*j] = rabel;
                }
            }
        }
    }

    int cnt = 0;
    REP(i, n) {
        if(rabels[i] == rabels[p[i]]) cnt++;
    }

    cout << cnt << endl;
}


Measured memory_bytes: 6656
/*------------------------------------
........Bismillahir Rahmanir Rahim....
..........created by Abdul Aziz.......
------------------------------------*/
#include <iostream>
#include <algorithm>
#include <stdio.h>
#include <cmath>
#include <vector>
#include <set>
#include <map>
#include <cstring>
#include <unordered_map>
#include <queue>
#define   mod  998244353
#define   int  long long 
#define   ld   long double
#define   pb   push_back
#define   vi  vector<int> 
#define   dbg(x)  cerr << #x << " = " << x << '\n'
#define   sz(x)  (int)x.size()
#define   all(a) (a.begin(),a.end())
#define   ff   first
#define   ss   second
#define   pii  pair<int,int> 
#define   lcm(a,b) (a*b)/__gcd(a,b) 
using namespace std;

inline void solve(){
    int n,yen,a=-1,b=-1,c=-1; cin>>n>>yen; 
    if (n*10000>=yen and n*1000<=yen) { 
        for (int i=0;i<=n;i++){ 
            for (int j=0;j<=n-i;j++){ 
                int k = n-i-j; 
                if (i*10000+j*5000+k*1000==yen){
                    a=i,b=j,c=k;
                    break;
                }
            } 
        } 
    } 
    cout << a << " " << b << " " << c << endl ; 
}

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


Measured memory_bytes: 3436
import heapq
Q = int(input())

# 中央値の左側の値、右側の値を管理する
# heapqとする。rightは最小が興味あるが、leftは最大なので、-1をかけて扱う
left, right = [], []
# 両方のSUMも管理する必要がある。毎回SUMしてたら間に合わん
Lsum, Rsum = 0,0
Lcnt, Rcnt = 0,0
B = 0
for _ in range(Q):
  q = list(map(int, input().split()))
  if len(q) == 1:
    # 2
    # heapqってPeakできないの・・・？
    l = (-1) * heapq.heappop(left)
    heapq.heappush(left,(-1)*l)
    # (l-l1) + (l-l2) + ... + (l-l) + (r-l) + ... + (r1 - l)
    print(l, Rsum//2 - Lsum//2 + B)
    #print(left,right, Lsum, Rsum)
  else:
    # 1
    _,a,b = q
    B += b
    # まず双方にaを突っ込む
    heapq.heappush(left,(-1)*a)
    heapq.heappush(right,a)
    Lsum += a
    Lcnt += 1
    Rsum += a
    Rcnt += 1
    # leftの最大値と、rightの最小値の関係が崩れていたら、交換する
    l = (-1) * heapq.heappop(left)
    r = heapq.heappop(right)
    if l>=r:
      Lsum = Lsum - l + r
      Rsum = Rsum - r + l
      l,r = r,l
    heapq.heappush(left,(-1)*l)
    heapq.heappush(right,r)

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

int main()
{
	int a1,a2,a3,b1,b2,b3,x[4][4],i,j;
	for(i=1;i<=3;i++)
		for(j=1;j<=3;j++)
			cin>>x[i][j];
	a1=0;
	b1=x[1][1]-a1;
	b2=x[1][2]-a1;
	b3=x[1][3]-a1;
	a2=x[2][1]-b1;
	a3=x[3][1]-b1;
	if(a2+b2==x[2][2] && a2+b3==x[2][3] && a3+b2==x[3][2] && a3+b3==x[3][3])
	{
		cout<<"Yes";
		return 0;
	}
	cout<<"No";
	return 0;
}

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

using namespace std;

using ll = long long;

bool Dfs(int cur, int dst, int d, auto &adj, auto &visited) {
    if (cur == dst) return true;
    visited[cur] = true;
    if (d < 2) {
        for (auto u : adj[cur]) {
            if (!visited[u] && Dfs(u, dst, d + 1, adj, visited)) return true;
        }
    }
    return false;
}

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

    int n, m;
    cin >> n >> m;

    vector<vector<int>> adj(n);
    for (int i = 0, a, b; i < m; ++i) {
        cin >> a >> b;
        adj[a - 1].push_back(b - 1);
        adj[b - 1].push_back(a - 1);
    }

    vector<bool> visited(n, false);
    if (Dfs(0, n - 1, 0, adj, visited)) cout << "POSSIBLE\n";
    else cout << "IMPOSSIBLE\n";

    return 0;
}


Measured memory_bytes: 12016
#include <bits/stdc++.h> 
using namespace std;
typedef long long ll;
typedef pair<ll,ll> p;
const int inf=(1<<30);
#define rep(i,a,n)	for(int i=a;i<n;i++)
#define rrep(i,a,n) for(int i=(a-1);i>=n;i--)
	
	
int main(){
	ll a;
	double b;
	cin>>a>>b;
	ll ans,b2;
	b2=round(b*100);
	ans=(a*b2)/100;
	cout<<ans<<endl;
	
}

Measured memory_bytes: 3668
#include<iostream>
#include<vector>
#include<set>
using namespace std;
typedef long long ll;

const ll mod = 1e9 + 7;

ll modpow(ll a, ll b, ll p = 1e9+7){
    if(b == 0)  return 1;

    if(b % 2 == 0){
        ll d = modpow(a, b/2, p);
        return (d*d) % p;
    }else{
        return (a%p * modpow(a, b-1, p)) % p;
    }
}

int main(){
    int n;
    ll k;
    cin >> n >> k;
    k %= mod;
    if(k == 0)  k = mod;
    vector<ll> v(n);
    for(int i = 0; i < n; i++)  cin >> v[i];
    ll ans = 0;
    for(int i = 0; i < n; i++){
        ll cnt = 0;
        for(int j = i+1; j < n; j++){
            if(v[i] > v[j]) cnt++;
        }
        ll tmp = 0;
        for(int j = 0; j < n; j++){
            if(v[i] > v[j]) tmp++;
        }
        ll a = 2*cnt+(k-1)*tmp;
        a %= mod;
        a = a*modpow(2,mod-2)%mod*k%mod;
        ans += a;
        ans %= mod;
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
struct fast_ios { fast_ios(){ cin.tie(0); ios::sync_with_stdio(false); cout << fixed << setprecision(20); }; } fast_ios_;
#define FOR(i, begin, end) for(int i=(begin);i<(end);i++)
#define REP(i, n) FOR(i,0,n)
#define IFOR(i, begin, end) for(int i=(end)-1;i>=(begin);i--)
#define IREP(i, n) IFOR(i,0,n)
#define Sort(v) sort(v.begin(), v.end())
#define Reverse(v) reverse(v.begin(), v.end())
#define all(v) v.begin(),v.end()
#define SZ(v) ((int)v.size())
#define Lower_bound(v, x) distance(v.begin(), lower_bound(v.begin(), v.end(), x))
#define Upper_bound(v, x) distance(v.begin(), upper_bound(v.begin(), v.end(), x))
#define Max(a, b) a = max(a, b)
#define Min(a, b) a = min(a, b)
#define bit(n) (1LL<<(n))
#define bit_exist(x, n) ((x >> n) & 1)
#define debug(x) cout << #x << "=" << x << endl;
#define vdebug(v) cout << #v << "=" << endl; REP(i_debug, v.size()){ cout << v[i_debug] << ","; } cout << endl;
#define mdebug(m) cout << #m << "=" << endl; REP(i_debug, m.size()){ REP(j_debug, m[i_debug].size()){ cout << m[i_debug][j_debug] << ","; } cout << endl;}
#define pb push_back
#define f first
#define s second
#define int long long
#define INF 1000000000000000000
template<typename T> istream &operator>>(istream &is, vector<T> &v){ for (auto &x : v) is >> x; return is; }
template<typename T> ostream &operator<<(ostream &os, vector<T> &v){ for(int i = 0; i < v.size(); i++) { cout << v[i]; if(i != v.size() - 1) cout << endl; }; return os; }
template<typename T> void Out(T x) { cout << x << endl; }
template<typename T1, typename T2> void Ans(bool f, T1 y, T2 n) { if(f) Out(y); else Out(n); }

using vec = vector<int>;
using mat = vector<vec>;
using Pii = pair<int, int>;
using PiP = pair<int, Pii>;
using PPi = pair<Pii, int>;
using bools = vector<bool>;
using pairs = vector<Pii>;

//int dx[4] = {1,0,-1,0};
//int dy[4] = {0,1,0,-1};
//char d[4] = {'D','R','U','L'};

const int mod = 1000000007;
//const int mod = 998244353;
#define Add(x, y) x = (x + (y)) % mod
#define Mult(x, y) x = (x * (y)) % mod



signed main(){

    int n; cin >> n;
    vec p(n); cin >> p;
    int ans = 0;
    FOR(i, 1, n - 1){
        int m = min(p[i - 1], p[i + 1]);
        int M = max(p[i - 1], p[i + 1]);
        if(m < p[i] && p[i] < M) ans++;
    }
    Out(ans);

    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using lint = long long int;
template<class T = int> using V = vector<T>;
template<class T = int> using VV = V< V<T> >;
template<class T> void assign(V<T>& v, int n, const T& a = T()) { v.assign(n, a); }
template<class T, class... U> void assign(V<T>& v, int n, const U&... u) { v.resize(n); for (auto&& i : v) assign(i, u...); }

int main() {
  cin.tie(NULL); ios::sync_with_stdio(false);
  int n; cin >> n;
  V<> x(n), y(n); for (int i = 0; i < n; i++) cin >> x[i] >> y[i];
  for (int i = 0; i < n; i++) if (x[0] + y[0] + x[i] + y[i] & 1) return cout << -1 << '\n', 0;
  V<> d;
  V<string> w(n);
  if (~(x[0] + y[0]) & 1) {
    d.push_back(1);
    for (int i = 0; i < n; i++) {
      x[i]--;
      w[i].push_back('R');
    }
  }
  for (int l = 1 << 30; l; l >>= 1) {
    d.push_back(l);
    for (int i = 0; i < n; i++) {
      if (x[i] + y[i] > 0) {
        if (x[i] - y[i] > 0) {
          x[i] -= l;
          w[i].push_back('R');
        } else {
          y[i] -= l;
          w[i].push_back('U');
        }
      } else {
        if (x[i] - y[i] > 0) {
          y[i] += l;
          w[i].push_back('D');
        } else {
          x[i] += l;
          w[i].push_back('L');
        }
      }
    }
  }
  int m = d.size();
  cout << m << '\n';
  for (int i = 0; i < m; i++) cout << d[i] << (i != m - 1 ? ' ' : '\n');
  for (int i = 0; i < n; i++) cout << w[i] << '\n';
}

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

// definition {{{ 1

// scaning {{{ 2
#define Scd(x) scanf("%d", &x)
#define Scd2(x,y) scanf("%d%d", &x, &y)
#define Scd3(x,y,z) scanf("%d%d%d", &x, &y, &z)

#define Scll(x) scanf("%llu", &x)
#define Scll2(x,y) scanf("%llu%llu", &x, &y)
#define Scll3(x,y,z) scanf("%llu%llu%llu", &x, &y, &z)

#define Scc(c) scanf("%c", &c);
#define Scs(s) scanf("%s", s);
#define Scstr(s) scanf("%s", &s);
// }}} 2

// constants {{{ 2
#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))
// }}} 2

// systems {{{ 2
#define Rep(x,y) for(int x = 0; x < y; x++)
#define Repe(x,y,z) for(int x = z; x < y; x++)
// }}} 2

// output {{{ 2
#define YesNo(a) (a)?printf("Yes\n"):printf("No\n");
// }}} 2

// }}} 1

int main() {

    int N;
    int L;
    Scd2(N,L);
    int m = L;
    bool zero = false;

    int ansa = 0;
    Rep(i,N){
        ansa += L+i;
    }
    int sub = INF;
    int ans = 0;
    Rep(i,N){
        int tmp = 0;
        Rep(j,N){
            if( i == j ) continue;
            tmp += L+j;
        }
        if( abs(ansa - tmp) < sub ){
            ans = tmp;
            sub = abs(ansa - tmp);
        }
    }

    printf ("%d\n", ans );

    return 0;
}



Measured memory_bytes: 256
#define  _CRT_SECURE_NO_WARNINGS
#include <stdio.h>
#include <algorithm>
#include <utility>
#include <functional>
#include <cstring>
#include <queue>
#include <stack>
#include <math.h>
#include <iterator>
#include <vector>
#include <string>
#include <set>
#include <math.h>
#include <iostream>
#include <random>
#include<map>
#include <iomanip>
#include <time.h>
#include <stdlib.h>
#include <list>
#include <typeinfo>
#include <list>
#include <set>
#include <cassert>
#include<fstream>
#include <unordered_map>
#include <cstdlib>
#include <complex>
#include <cctype>
#include <bitset>
using namespace std;
typedef string::const_iterator State;
#define Ma_PI 3.141592653589793
#define eps 0.00000001
#define LONG_INF 1e18
#define GOLD 1.61803398874989484820458
#define MAX_MOD 1000000007
#define MOD 1000000007
#define seg_size 262144
#define REP(a,b) for(long long a = 0;a < b;++a)
int main() {
#define int long long
	iostream::sync_with_stdio(false);
	int n, k;
	cin >> n >> k;
	vector<long long> A;
	REP(i, n) {
		long long hoge;
		cin >> hoge;
		A.push_back(hoge);
	}
	sort(A.begin(), A.end());
	long long hoge = 0;
	REP(i, A.size()){
		hoge += A[i];
	}
	vector<long long> geko;
	for (int q = 1; q <= sqrt(hoge); ++q) {
		if (hoge % q == 0) {
			geko.push_back(hoge/q);
			geko.push_back(q);
		}
	}
	sort(geko.begin(), geko.end());
	reverse(geko.begin(), geko.end());
	for (int tmp = 0;;++tmp) {
		long long i = geko[tmp];
		vector<pair<int, int>> gogo;
		REP(q, n) {
			gogo.push_back(make_pair(A[q] - (A[q] / i) * i, (A[q] / i + 1LL) * i - A[q]));
		}
		sort(gogo.begin(), gogo.end());
		int now_k = k;
		for (int q = 0; q < gogo.size() - 1; ++q) {
			if (now_k > gogo[q].first) {
				now_k -= gogo[q].first;
				gogo[q].second += gogo[q].first;
				gogo[q].first = 0;
			}
			else {
				gogo[q].second += now_k;
				gogo[q].first -= now_k;
				now_k = 0;
			}
		}
		gogo[gogo.size() - 1].second += now_k;
		gogo[gogo.size() - 1].first -= now_k;
		REP(q, gogo.size()) {
			swap(gogo[q].first, gogo[q].second);
		}
		sort(gogo.begin(), gogo.end());
		int ok = 1;
		now_k = k;
		REP(q, gogo.size()) {
			gogo[q].first %= i;
			if (now_k >= gogo[q].first) {
				now_k -= gogo[q].first;
				gogo[q].second += gogo[q].first;
				gogo[q].first = 0;
			}
			else {
				ok = 0;
				break;
			}
		}
		if (now_k % i == 0 && ok == 1) {
			cout << i << endl;
			return 0;
		}
	}
}

Measured memory_bytes: 256
#include <stdio.h>
#include <iostream>
#include <vector>
#include <assert.h>
#include <set>
#include <map>
#include <cmath>
#include <queue>
#include <stack>
#include <string>
#include <sstream>
#include <memory.h>
#include <time.h>
#include <string.h>
#include <stdlib.h>
#include <algorithm>
using namespace std;
typedef long long ll;
const int N = 100000;
int n, e;
int v[N];
multiset<int> comp[N];
int p[N];
int find(int u) {
	if (p[u] == u)
		return u;
	return p[u] = find(p[u]);
}
int main()
{
	scanf("%d%d", &n, &e);
	for (int i = 0; i < n; ++i) {
		scanf("%d", v + i);
		p[i] = i;
	}
	for (int i = 0; i < e; ++i) {
		int a, b;
		scanf("%d%d", &a, &b);
		a = find(a);
		b = find(b);
		p[a] = b;
	}
	for (int i = 0; i < n; ++i) {
		find(i);
		comp[p[i]].insert(v[i]);
	}
	multiset<pair<int, int> > q;
	for (int i = 0; i<n; ++i)
		if (!comp[i].empty())
			q.insert(make_pair(-(int)comp[i].size(), i));
	int u = -1;
	if (!q.empty()) {
		u = q.begin()->second;
		q.erase(q.begin());
	}
	ll res = 0;
	while (u != -1 && !comp[u].empty() && q.size() >= 1) {
		int v = q.begin()->second;
		q.erase(q.begin());
		res += *comp[u].begin();
		res += *comp[v].begin();
		comp[u].erase(comp[u].begin());
		comp[v].erase(comp[v].begin());
		for (auto &x : comp[v])
			comp[u].insert(x);
		++e;
	}
	if (e != n - 1)
		puts("Impossible");
	else
		printf("%lld\n", res);
	return 0;
}

Measured memory_bytes: 15232
x,a,b = input().split()
x = int(x)
a = int(a)
b = int(b)

if x < a:
    distance_xa = a - x
else:
    distance_xa = x - a

if x < b:
     distance_xb = b - x
else:
     distance_xb = x - b

if distance_xa < distance_xb:
      print("A")
else:
      print("B")

Measured memory_bytes: 3060
#include<iostream>
#include<algorithm>
using namespace std;
#include<vector>
#include<functional>
template<typename T>
struct lazysegtree{
	function<T(T,T)>calcfn,lazycalcfn;
	function<T(T,T,unsigned int)>updatefn;
	int n;
	T defvalue,lazydefvalue;
	vector<T>dat,lazy;
	vector<bool>lazyflag;
	lazysegtree(int n_=0,T defvalue_=0,
		function<T(T,T)>calcfn_=[](T a,T b){return a+b;},
		function<T(T,T)>lazycalcfn_=[](T a,T b){return a+b;},
		function<T(T,T,unsigned int)>updatefn_=[](T a,T b,unsigned int width){return a+b*width;},
		T lazydefvalue_=0
	):defvalue(defvalue_),lazydefvalue(lazydefvalue_),
		calcfn(calcfn_),lazycalcfn(lazycalcfn_),updatefn(updatefn_)
	{
		n=1;
		while(n<n_)n<<=1;
		dat.assign(2*n-1,defvalue);
		lazy.assign(2*n-1,lazydefvalue);
		lazyflag.assign(2*n-1,false);
	}
	void copy(const vector<T>&v)
	{
		for(int i=0;i<v.size();i++)dat[i+n-1]=v[i];
		for(int i=n-2;i>=0;i--)dat[i]=calcfn(dat[2*i+1],dat[2*i+2]);
	}
	void eval(int i,int l,int r)
	{
		if(lazyflag[i])
		{
			dat[i]=updatefn(dat[i],lazy[i],r-l);
			if(r-l>1)
			{
				lazy[2*i+1]=lazycalcfn(lazy[2*i+1],lazy[i]);
				lazy[2*i+2]=lazycalcfn(lazy[2*i+2],lazy[i]);
				lazyflag[2*i+1]=lazyflag[2*i+2]=true;
			}
			lazy[i]=lazydefvalue;
			lazyflag[i]=false;
		}
	}
	void update(int a,int b,T x,int k=0,int l=0,int r=-1)//[a,b)
	{
		if(r<0)r=n;
		eval(k,l,r);
		if(b<=l||r<=a)return;
		else if(a<=l&&r<=b)
		{
			lazy[k]=lazycalcfn(lazy[k],x);
			lazyflag[k]=true;
			eval(k,l,r);
		}
		else
		{
			update(a,b,x,2*k+1,l,(l+r)/2);
			update(a,b,x,2*k+2,(l+r)/2,r);
			dat[k]=calcfn(dat[2*k+1],dat[2*k+2]);
		}
	}
	T query(int a,int b,int k=0,int l=0,int r=-1)//[a,b)
	{
		if(r<0)r=n;
		eval(k,l,r);
		if(b<=l||r<=a)return defvalue;
		else if(a<=l&&r<=b)return dat[k];
		else return calcfn(
			query(a,b,2*k+1,l,(l+r)/2),
			query(a,b,2*k+2,(l+r)/2,r)
		);
	}
};
int n,m;
vector<pair<int,int> >P[2<<17];
main()
{
	cin>>n>>m;
	for(int i=0;i<m;i++)
	{
		int l,r,a;cin>>l>>r>>a;
		P[r].push_back(make_pair(l,a));
	}
	lazysegtree<long>dp(n+1,0,
		[](long a,long b){return max(a,b);},
		[](long a,long b){return a+b;},
		[](long a,long b,unsigned int w){return a+b;}
	);
	for(int i=1;i<=n;i++)
	{
		dp.update(i,i+1,dp.query(0,i));
		for(int j=0;j<P[i].size();j++)
		{
			dp.update(P[i][j].first,i+1,P[i][j].second);
		}
	}
	cout<<dp.query(0,n+1)<<endl;
}

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

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

    if(S[0] == 'W' || S[2 * N - 1] == 'W') {
        cout << 0 << endl;
        return 0;
    }
    
    vector<bool> f(2 * N);
    f[0] = true;
    for(int i=1; i<2*N; ++i) {
        if(S[i - 1] != S[i]) f[i] = f[i - 1];
        else f[i] = !f[i - 1];
    }

    if(count(begin(f), end(f), true) != N) {
        cout << 0 << endl;
        return 0;
    }

    long long MOD = 1000000007;
    long long res = 1;
    for(int i=1; i<=N; ++i) res = (res * i) % MOD;
    
    int cnt = 0;
    for(int i=0; i<2*N; ++i) {
        if(f[i]) {
            ++cnt;
        } else {
            res = (res * cnt) % MOD;
            --cnt;
        }
    }
    cout << res << endl;
}

Measured memory_bytes: 640
import numpy as np
N,D = (int(x) for x in input().split())
X = np.zeros((N,D),dtype=int)
for I in range(0,N):
    X[I,:] = np.array([int(x) for x in input().split()],dtype=int)
    
Count = 0
for I in range(0,N-1):
    for II in range(I+1,N):
        if np.linalg.norm(X[I,:]-X[II,:]).is_integer():
            Count += 1
print(Count)

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

int main(){
	int n;
	long long temp,max,min;
	
	cin >> n;
	
	for(int i=0;i<n;i++){
		cin >> temp;
		if(i==0){
			max=temp;
			min=temp;
		}else{
			if(max<temp)max=temp;
			if(min>temp)min=temp;
		}
	}
	cout << max-min<<endl;
	
	return 0;
}

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

public class Main {
	static PrintWriter out;
	static StringBuilder sb;
	static int mod = (int) 1e9 + 7;
	static int inf = (int) 1e8;
	static int[] col;
	static int n, m, k;
	static ArrayList<Integer>[] ad;
	static int[][][] memo;
	static ArrayList<Integer> h;
	static char[][] grid;
	static int[] a;
	static boolean f;
	static int offest = 30;

	public static void main(String[] args) throws Exception {
		Scanner sc = new Scanner(System.in);
		out = new PrintWriter(System.out);
		int n = sc.nextInt();
		Long[] a = new Long[n];
		long ans = 1;
		f = false;
		for (int i = 0; i < n; i++) {
			a[i] = sc.nextLong();
			if (a[i] == 0) {
				f = true;
			}
		}
		if (f) {
			System.out.println(0);
			return;
		}
		Arrays.sort(a);
		for (int i = 0; i < n; i++) {
			ans = ans * a[i];
			if (ans <= 0 || ans > ((long) 1e18)) {
				System.out.println(-1);
				return;
			}
		}
		System.out.println(ans);
		out.flush();
	}

	static class Scanner {
		StringTokenizer st;
		BufferedReader br;

		public Scanner(InputStream system) {
			br = new BufferedReader(new InputStreamReader(system));
		}

		public Scanner(String file) throws Exception {
			br = new BufferedReader(new FileReader(file));
		}

		public String next() throws IOException {
			while (st == null || !st.hasMoreTokens())
				st = new StringTokenizer(br.readLine());
			return st.nextToken();
		}

		public String nextLine() throws IOException {
			return br.readLine();
		}

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

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

		public char nextChar() throws IOException {
			return next().charAt(0);
		}

		public Long nextLong() throws IOException {
			return Long.parseLong(next());
		}

		public int[] nextArrInt(int n) throws IOException {
			int[] a = new int[n];
			for (int i = 0; i < n; i++)
				a[i] = nextInt();
			return a;
		}

		public long[] nextArrLong(int n) throws IOException {
			long[] a = new long[n];
			for (int i = 0; i < n; i++)
				a[i] = nextLong();
			return a;
		}

		public boolean ready() throws IOException {
			return br.ready();
		}

		public void waitForInput() throws InterruptedException {
			Thread.sleep(3000);
		}
	}
}

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

int main(){
	int a, b, c, s;
	cin >> a >> b >> c;
	if(a > c){
		s = a;
		a = c;
		c = s;
	}
	if(b > c){
		s = b;
		b = c;
		c = s;
	}
	if(a > b){
		s = a;
		a = b;
		b = s;
	}
	cout << a << " " << b << " " << c << endl;
	return 0;
}


Measured memory_bytes: 3096
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cmath>
#include<map>
#include<cstring>
#include<climits>
#include<queue>
using namespace std;
#define MAXC 30
#define MAXN 500
int n,c,ans;
int D[MAXC+5][MAXC+5],C[MAXN+5][MAXN+5];
int cont[4][MAXC+5];
int main()
{
    ans=INT_MAX;
    scanf("%d%d",&n,&c);
    for(int i=1;i<=c;i++)
        for(int j=1;j<=c;j++)
        scanf("%d",&D[i][j]);
    for(int i=1;i<=n;i++)
        for(int j=1;j<=n;j++)
        scanf("%d",&C[i][j]);
    for(int i=1;i<=n;i++)
        for(int j=1;j<=n;j++)
        cont[(i+j)%3][C[i][j]]++;
    for(int i=1;i<=c;i++)
        for(int j=1;j<=c;j++)
        if(i!=j)
            for(int k=1;k<=c;k++)
            if(k!=i&&k!=j)
            {
                int res=0;
                for(int p=1;p<=c;p++)res+=cont[0][p]*D[p][i];
                for(int p=1;p<=c;p++)res+=cont[1][p]*D[p][j];
                for(int p=1;p<=c;p++)res+=cont[2][p]*D[p][k];
                ans=min(ans,res);
            }
    printf("%d",ans);
}

Measured memory_bytes: 1280