akhauriyash/Code-Regression huggingface dataset:
#include "bits/stdc++.h"

#define MOD 1000000007
#define rep(i, n) for(ll i=0; i < (n); i++)
#define ALL(v) v.begin(),v.end()
#define DUMP(i, v)for(ll i=0;i<v.size();i++)cout<<v[i]<<" "

using namespace std;
typedef long long int ll;
typedef vector<ll> llvec;
typedef vector<double> dvec;
typedef pair<int, int> P;
struct Edge{ll from, to, cost;};

ll mod(ll a, ll mod){
  ll res = a%mod;
  if(res<0)res=res + mod;
  return res;
}

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

ll modinv(ll a, ll mod){
  return modpow(a, mod-2, mod);
}

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

bool is_prime(ll n){
  ll i = 2;
  if(n==1)return false;
  if(n==2)return true;
  bool res = true;
  while(i*i <n){
    if(n%i==0){
      res = false;
    }
    i = i+1;
  }

  //if(i==1)res = false;
  if(n%i==0)res=false;
  return res;
}

/**************************************
 ** A main function starts from here  **
 ***************************************/
int main(){
  ll N, M;
  cin >> N >> M;
  vector<vector<P> > v(N);
  vector<ll> cost(N, 1e18);
  rep(i,N-2){
    v[i+2].push_back(make_pair(i+1, 0));
  }
  rep(i, M){
    ll l, r, c;
    cin >> l >> r >> c;
    l--;r--;
    v[l].push_back(make_pair(r,c));
  }
  
  cost[0]=0;
  priority_queue<P, vector<P>, greater<P> > que;
  llvec chk(N, 0);
  que.push(make_pair(0, 0));
  while(!que.empty()){
    P p =que.top();
    que.pop();
    ll from = p.second;
    
    if(chk[from]!=0)continue;
    chk[from]=1;
    ll vnum = v[from].size();
    rep(i, vnum){
      ll to = v[from][i].first;
      ll c = v[from][i].second;
      if(cost[to]>cost[from]+c){
        cost[to]=cost[from]+c;
        que.push(make_pair(cost[to], to));
      }
    }
  }
  
  cout << (cost[N-1]==1e18?-1:cost[N-1]);
  
  return 0;
}


Measured memory_bytes: 8700
#include<iostream>
#include<vector>
#include<limits.h>
using namespace std;

struct Matrix{int r,c;};

int main(){
	int n;
	int i,k,l,f;
	cin >> n;
	vector<Matrix> M(n);
	
	for (i=0;i<n;i++){
		cin >> M[i].r;
		cin >> M[i].c;
	}
	
	int DPtable[n][n];
	for (i=0;i<n;i++){
		DPtable[i][i]=0;
	}
	
	for (k=1;k<n;k++){
		for (i=0;i<n-k;i++){
			int m=INT_MAX;
			for (l=0;l<=k-1;l++){
				f=M[i].r*M[i+l].c*M[i+k].c;
				if (DPtable[i][i+l]+DPtable[i+l+1][i+k]+f<m){
					m=DPtable[i][i+l]+DPtable[i+l+1][i+k]+f;
				}
			}
			DPtable[i][i+k]=m;
			
		}
	}
	
	cout << DPtable[0][n-1] <<endl;
	
	return 0;
}

Measured memory_bytes: 1236
<?php

const MOD =  1000000007;
const INV =  500000004;
fscanf(STDIN, "%d%d", $n, $k);
$array = explode(" ",trim(fgets(STDIN)));

$map = array_fill(0,$n,[0,0]);
foreach($array as $i => $value){

    if($i > 0){
        for($j=0; $j<$i; $j++) {
            if ($value > $array[$j]) {
                $map[$i][0]++;
            }
        }
    }
    for($j=$i+1; $j<$n;$j++){
        if($value > $array[$j]){
            $map[$i][1]++;
        }
    }
}
$ans = 0;
foreach($map as $value){
    $plus = (($k) * INV )% MOD;
    $plusb = (2 * $value[1] + ($k- 1) * ($value[0]+ $value[1])) % MOD;
    $ans = ($ans + (($plus * $plusb) % MOD)) %MOD;


}

echo $ans;

Measured memory_bytes: 4856
#include <iostream> // cin, cout, cerr
#include <algorithm> // minmax, sort, swap
#include <numeric> // iota
#include <cstdio> // printf, scanf
#include <string> // string, stoi, to_string
#include <vector> // vector
#include <queue> // queue, priority_queue
#include <deque> // deque
#include <map> // key-value pairs sorted by keys
#include <set> // set
#include <iomanip> // cout<<setprecision(n)
#include <functional> // function<void(int)>
#include <cmath>
#include <cassert>
#include <bitset>

#ifdef DEBUG
#include "debug.hpp"
#else
#define debug(...)
#endif

#define int long long // at least int64 > 9*10^18
#define EL '\n'
#define rep(i,n) for(int i = 0; i < (n); i++)
#define print(i) std::cout << (i) << '\n'
#define all(v) (v).begin(), (v).end()
/* libraries */

constexpr int MOD = 1e9+7;
struct mint
{
	int v;
	mint():v(0){}
	mint(int v):v((v+MOD)%MOD){}
	mint operator-()const{ return mint(0) - *this; }
	mint& operator+=(const mint& a){ if((v+=a.v)>=MOD) v-=MOD; return *this; }
	mint& operator-=(const mint& a){ if((v+=MOD-a.v)>=MOD) v-=MOD; return *this; }
	mint& operator*=(const mint& a){ (v*=a.v)%=MOD; return *this; }
	mint& operator/=(const mint& a){ (*this) *= a.inv(); return *this; }
	mint operator+(const mint& a)const{ return mint(*this) += a; }
	mint operator-(const mint& a)const{ return mint(*this) -= a; }
	mint operator*(const mint& a)const{ return mint(*this) *= a; }
	mint operator/(const mint& a)const{ return mint(*this) /= a; }
	bool operator<(const mint& a)const{ return v < a.v; }
	bool operator==(const mint& a)const{ return v == a.v; }
	mint pow(int k)const{ mint r(1),t(v); while(k){ if(k&1) r*=t; t*=t; k>>=1; } return r; }
	mint inv()const{ return pow(MOD-2); }
	static mint comb(int n, int k) {
		if(n-k<k) k=n-k;
		mint num(1), dom(1);
		for(int i=0;i<k;i++) { num*=n-i; dom*=i+1; }
		return num/dom;
	}
};
std::istream& operator>>(std::istream&i,mint&a){ int t; i>>t; a=mint(t); return i; }
std::ostream& operator<<(std::ostream&o,const mint&a){ o<<a.v; return o; }


signed main() {
	int n,a,b,c,d;
	std::cin >> n >> a >> b >> c >> d;
	std::vector<mint> fact(n+1,1);
	for(int i=2;i<=n;i++) fact[i]=fact[i-1]*mint(i);
	std::vector<std::vector<mint> > dp(n+1,std::vector<mint>(n+1,0));
	dp[0][0]=1;
	for(int i=1;i<=n;i++) {
		for(int j=0;j<=n;j++) {
			dp[i][j]+=dp[i-1][j];
			if(i<a || b<i) continue;
			for(int k=c;k<=d;k++) {
				if(j-i*k<0) break;
				dp[i][j]+=dp[i-1][j-i*k]*fact[j]/fact[j-i*k]/fact[i].pow(k)/fact[k];
			}
		}
	}
	print(dp[n][n]);
	return 0;
}


Measured memory_bytes: 10112
#include<bits/stdc++.h>
using namespace std;
main()
{
	int n,m;
	cin>>n>>m;
	int arr[n][m];
	for(int i=0;i<n;i++)
	{
		string s;
		cin>>s;
		for(int j=0;j<m;j++)
		{
			if(s[j] == '.')
			arr[i][j] = 1;
			else
			arr[i][j] = 2;
		}
	}
	vector<int> r;
	vector<int> c;
	for(int i=0;i<n;i++)
	{
		int c =0;
		for(int j=0;j<m;j++)
		{
			if(arr[i][j] == 2)
			{
				c++;
				break;
			}
		}
		if(c != 0)
		{
			r.push_back(i);
		}
	}
	for(int i=0;i<m;i++)
	{
		int c1 =0;
		for(int j=0;j<n;j++)
		{
			if(arr[j][i] == 2)
			{
				c1++;
				break;
			}
		}
		if(c1 != 0)
		{
			c.push_back(i);
		}
	}
	string arr1[r.size()];
	for(int i=0;i<r.size();i++)
	{
		string s2;
		for(int j=0;j<c.size();j++)
		{
			
			if(arr[r[i]][c[j]] == 1)
			{
				//cout<<".";
				s2 += '.';
			}
			else
			{
				//cout<<"#";
				s2 += '#';
			}
		}
		arr1[i] = s2;
		//cout<<endl;
	}
	for(int i=0;i<r.size();i++)
	{
		cout<<arr1[i]<<endl;
	}
}

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

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP0(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define REP1(i,n) for(int i=1, i##_len=(n); i<=i##_len; ++i)
#define RREP0(i,n) for(int i=n-1; i>=0; --i)
#define RREP1(i,n) for(int i=n; i>=1; --i)
#define SORT(c) sort((c).begin(),(c).end())
#define REVERSE(c) reverse((c).begin(),(c).end())
#define FILL(c, v) fill((c).begin(),(c).end(), v)
#define SZ(a) int((a).size())
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define CLR(a) memset((a), 0 ,sizeof(a))

inline int toInt(string s) {int v; istringstream sin(s);sin>>v;return v;}
template<class T> inline string toString(T x) {ostringstream sout;sout<<x;return sout.str();}

typedef long long LL;
typedef unsigned long long ULL;

const int INTINF = 1e9;
const LL LLINF = 1e18;
int gcd(int a,int b){return b?gcd(b,a%b):a;}

void solve()
{
    LL N; cin >> N;
    string result = "";
    if (N==0) { cout << "0" << endl; return; }
    while (N!=0)
    { // -2 で割り続けるループ. 言い換えると, 最初のk桁を除いたマイナス2進数で, 偶奇が最下位に対応する
        if (N%2 != 0)
        {
            result = "1" + result;
            N--;
        } 
        else result = "0" + result;
        N /= -2;
    }
    cout << result << endl;
}

int main(int argc, char const *argv[])
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    std::cout<<std::fixed<<std::setprecision(10);
    solve();
    return 0;
}

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

int main( void ) {
	int n;
	scanf( "%d", &n );
	int four = 0, two = 0, nicht = 0;
	for( int i = 0; i < n; i++ ) {
		int x;
		scanf( "%d", &x);
		if( x % 4 == 0 ) four++;
		else if( x % 2 == 0 ) two++;
		else nicht++;
	}
	if( two == 0 ) {
		if( four +1 >= nicht ) printf( "Yes\n" );
		else printf( "No\n");
	} else {
		if( four >= nicht ) printf( "Yes\n");
		else printf( "No\n");
	}
	
	
	return 0;
}


Measured memory_bytes: 128
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); i++)
#define rrep(i, n) for (int i = (n) - 1; i >= 0; i--)
#define reps(i, n) for (int i = 1; i <= (n); i++)
#define repi(i, a, b) for (int i = (a); i < (b); i++)
#define all(a) (a).begin(), (a).end()
#define bit(b) (1ull << (b))

using namespace std;
using i32 = int;
using u32 = unsigned int;
using i64 = long long;
using u64 = unsigned long long;
using f64 = double;
using f80 = long double;
using pii = pair<i32, i32>;
using vi32 = vector<i32>;
using vu32 = vector<u32>;
using vi64 = vector<i64>;
using vu64 = vector<u64>;
using vf64 = vector<f64>;
using vf80 = vector<f80>;
using vstr = vector<string>;
using vpii = vector<pii>;
using vvi32 = vector<vi32>;
using vvu32 = vector<vu32>;
using vvi64 = vector<vi64>;
using vvu64 = vector<vu64>;
using vvf64 = vector<vf64>;
using vvf80 = vector<vf80>;

template<typename T, typename S> bool amax(T &x, S y) { if (x < y) { x = y; return 1; } return 0; }
template<typename T, typename S> bool amin(T &x, S y) { if (y < x) { x = y; return 1; } return 0; }

template<int mod> class modint {
public:
  int x;
  modint(): x(0) {}
  modint(int a) { x = a % mod; if (x < 0) x += mod; }
  modint &operator+=(modint that) { x = (x + that.x) % mod; return *this; }
  modint &operator-=(modint that) { x = (x + mod - that.x) % mod; return *this; }
  modint &operator*=(modint that) { x = (long long) x * that.x % mod; return *this; }
  modint &operator/=(modint that) { return *this *= that.inverse(); }
  modint operator-() { return modint(-this->x); }
  friend ostream& operator<<(ostream &out, modint m) { return out << m.x; }
  modint inverse() {
    int a = x, b = mod, u = 1, v = 0;
    while (b) { int t = a / b; a -= t * b; u -= t * v; swap(a, b); swap(u, v); }
    return modint(u);
  }
#define op(o, p) modint operator o(modint that) { return modint(*this) p that; }
  op(+, +=) op(-, -=) op(*, *=) op(/, /=)
#undef op
#define op(o) bool operator o(modint that) const { return x o that.x; }
  op(==) op(!=) op(<) op(<=) op(>) op(>=)
#undef op
};

using mint = modint<1000000007>;

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout << fixed << setprecision(16);
  cerr << fixed << setprecision(16);
  string s;
  cin >> s;
  vector<vector<mint>> dp(s.size() + 1, vector<mint>(4));
  dp[s.size()][3] = 1;
  rrep(i, s.size()) rrep(j, 4) {
    if (j == 3) {
      dp[i][j] = dp[i + 1][j] * (s[i] == '?' ? 3 : 1);
    } else {
      dp[i][j] = dp[i + 1][j] * (s[i] == '?' ? 3 : 1) +
        dp[i + 1][j + 1] * ((s[i] == '?' || s[i] == "ABC"[j]) ? 1 : 0);
    }
  }
  cout << dp[0][0] << endl;
  return 0;
}

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

int main() {
  long n,a,b,c=0,ans=0;
  cin>>n;
  for(long i=1;i<=n;i++)
  {
    long x;
    cin>>x;

    if(x!=i)
    {
      c++;
    }
  }
  if(c>2)
  {
    cout<<"NO"<<endl;
  }
  else
  {
    cout<<"YES"<<endl;
  }
  //cout<<ans<<endl;
}

Measured memory_bytes: 256
#include<stdio.h>
#include<math.h>
int main()
{
    long long int r,n,i,s,f;
    scanf("%lld",&n);
    f=sqrt(n);
    for(i=f;i>=1;i--){
        if(n%i==0){
            r=n/i;
            s=r+i-2;
            break;
        }
    }
    printf("%lld",s);
    return 0;
}


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

using namespace std;

#define YES cout << "YES" << endl;
#define NO  cout << "NO"  << endl;
#define Yes cout << "Yes" << endl;
#define No  cout << "No"  << endl;
 
#define INF INT_MAX
#define MOD 1000000007
#define PI  acos(-1)

using ll  = long long;
using ull = unsigned long long;
using Pii = pair<int, int>;
using Pll = pair<ll, ll>;

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

int main(int argc, char *argv[])
{
    cin.tie(0);
    ios::sync_with_stdio(false);

    ll N;
    cin >> N;

    vector<ll> s(N);
    rep (i, N) {
        cin >> s[i];
    }

    rep (i, N) {
        if (s[i]%10 != 0) {
            break;
        } else {
            if (i == N-1) {
                cout << 0 << endl;
                return 0;
            }
        }
    } 

    ll ans = 0;
    rep (i, N) {
        ans += s[i];
    }

    ll mi = INF;
    if (ans%10 == 0) {
        rep (i, N) {
            if (s[i]%10 != 0) {
                mi = min(mi, s[i]);
            }
        }
        ans -= mi;
    }

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

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
#define int long long 
#define SIZE (100005)
 
struct Ranking {
  int val, num;
  bool operator < (const Ranking d) const {
    if(val < d.val) return (true);
    if(val > d.val) return (false);
    return (num > d.num);
  }
};
 
struct BIT
{
  int data[300005];
   
  BIT() {
    memset(data, 0, sizeof(data));
  }
   
  void add(int k, int x) {
    for(k++; k < 300005; k += k & -k) data[k] += x;
  }
   
  int query(int k) {
    int ans = 0;
    for(k++; k > 0; k -= k & -k) ans += data[k];
    return (ans);
  }
};
 
vector < Ranking > point;
vector < int > pos[SIZE];
int N, C;
 
main()
{
  int a[SIZE], b[SIZE], c[SIZE];
  int p[SIZE] = {};
  int it[SIZE] = {};
  BIT tree;
 
  cin >> N >> C;
   
  for(int i = 0; i < N; i++) point.push_back( (Ranking) { 0, i } );
  for(int i = 0; i < C; i++) {
    cin >> a[i] >> b[i];
    if(a[i] == 0) {
      cin >> c[i]; b[i]--;
      p[b[i]] += c[i];
      point.push_back( (Ranking) { p[b[i]], b[i] } );
    }
  }
   
  sort(point.begin(), point.end());
   
  for(int i = 0; i < point.size(); i++) pos[point[i].num].push_back(i);
  for(int i = 0; i < N; i++) tree.add(i, 1);
   
  for(int i = 0; i < C; i++) {
    if(a[i] == 0) {
      tree.add(pos[b[i]][ it[b[i]] ], -1);
      it[b[i]]++;
      tree.add(pos[b[i]][ it[b[i]] ], 1);
    } else {
      int l = -1, r = point.size() + 2;
      while(l + 1 < r) {
        int m = (l + r) / 2;
        if(N - tree.query(m) + 1 <= b[i]) r = m;
        else l = m;
      }
      cout << point[r].num + 1 << " " << point[r].val << endl;
    }
  }
 
  return (0);
}

Measured memory_bytes: 17676
#include <iostream>
#include <string>
#include <set>

using namespace std;

int main() {
	string s;
	cin >> s;
	set<char> st;
	for (int i = 0; i < s.size(); i++) {
		st.insert(s[i]);
	}
	if (s.size() == st.size()) {
		cout << "yes" << endl;
	}
	else {
		cout << "no" << endl;
	}
	return 0;
}

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

int judge_group(int a){
    int group;

    switch (a){
    case 1:
    case 3:
    case 5:
    case 7:
    case 8:
    case 10:
    case 12:
        group = 1;
        break;

    case 4:
    case 6:
    case 9:
    case 11:
        group = 2;
        break;

    case 2:
        group = 3;
        break;
    }

    return group;
}

int main(void){

    int x,y,x_group,y_group;

    scanf("%d %d",&x,&y);

    x_group = judge_group(x);
    y_group = judge_group(y);

    (x_group == y_group) ? printf("Yes\n") : printf("No\n");
    return 0;
}

Measured memory_bytes: 128
#![allow(dead_code)]
#![allow(unused_imports)]
#![allow(unused_variables)]

use proconio::{fastout, input};
use std::cmp::{max, min};

static INF: i32 = 1001001001;
static LINF: i64 = 1001001001001001001;

#[fastout]
fn main() {
  input! {
    n: usize,
    k: i32,
    h: [i32; n],
  }
  let mut dp = vec![INF; n];
  dp[0] = 0;
  for i in 0..n {
    for j in 1..(k + 1) {
      let ni = i + j as usize;
      if ni >= n {
        continue;
      }
      dp[ni] = min(dp[ni], dp[i] + (h[i] - h[ni]).abs());
    }
  }
  println!("{}", dp[n - 1]);
}


Measured memory_bytes: 3244
#include<cstdio>
#include<algorithm>
using namespace std;
typedef long long ll;
const int MAXN = 505;
const ll INF = 1000000000000000;
int n, x;
ll w[MAXN][MAXN], s[MAXN][MAXN], t[MAXN][MAXN], dp[MAXN][MAXN];
int main(){
	scanf("%d", &n);
	for(int i=1; i<=n; i++)
		for(int j=1; j<=n; j++) if(i!=j) scanf("%d", w[i]+j);
	for(int i=1; i<=n; i++)
		for(int j=1; j<=n; j++)
			s[i][j]=s[i-1][j]+s[i][j-1]-s[i-1][j-1]+w[i][j];
	for(int i=1; i<=n; i++)
		for(int j=1; j<=n; j++)
			t[i][j]=t[i-1][j]+t[i][j-1]-t[i-1][j-1]+(i<j?w[i][j]:0);
		for(int i=1; i<=n; i++){
		dp[i][1]=t[i][i]-t[0][i]-t[i][0]+t[0][0];
		for(int j=2; j<=i; j++){
			dp[i][j]=INF;
			for(int k=1; k<j; k++)
				dp[i][j]=min(dp[i][j], dp[j-1][k]+t[i][i]-t[i][j-1]-t[j-1][i]+t[j-1][j-1]+s[i][k-1]-s[j-1][k-1]);
		}
	}
	ll ans=INF;
	for(int i=1; i<=n; i++) ans=min(ans, dp[n][i]);
	printf("%lld\n", ans);
	return 0;
}

Measured memory_bytes: 8064
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define mp make_pair
#define pb push_back
#define rep(i,n) for(int i=0;i<n;i++)
#define rep1(i,n) for(int i=1;i<=(int)(n);i++)


int main(){
  ios::sync_with_stdio(false);
  cin.tie(0);
  int n;
  cin >> n;
  int sz = pow(2,n);
  vector<int> s(sz);
  rep(i,sz) cin >> s[i];
  sort(s.rbegin(), s.rend());

  if(sz==1) cout << "Yes" << endl;
  else{
    if(s[0]==s[1]) cout << "No" << endl;
    else{
      ll cap = n;
      ll ncap = n;
      priority_queue<ll> pq;

      pq.push(n);
      rep1(i,sz-1){
	vector<ll> tmp;
	ll same=1;
	ll cn;
	cn= pq.top();pq.pop();
	if(cn>0){
	  pq.push(cn-1);
	  tmp.pb(cn-1);
	  ncap += (cn-1)*2-cn;
	}
	while(i<sz-1 && s[i]==s[i+1]){
	  i++;
	  same++;	  
	  if(!pq.empty()){
	    cn = pq.top();pq.pop();
	  }
	  else continue;
	  if(cn>0){
	    pq.push(cn-1);
	    tmp.pb(cn-1);
	    ncap += (cn-1)*2 -cn;
	  }
	}

	//	cout << "cap same " << cap << " " << same << endl;
	//	cout << "ncap" << ncap <<endl;
	if(same>cap){
	  cout <<"No" << endl;
	  return 0;
	}
	cap=ncap;
	rep(j,tmp.size()) pq.push(tmp[j]);
	if(pq.empty()) break;
      }
      cout <<"Yes" << endl;
    }    
  }        
  return 0;
    

}


Measured memory_bytes: 4468
#include <stdio.h>

struct DICE {
	int num[7];
};

void throwdice(char ch, struct DICE *dice)
{
	int temp;
	switch (ch) {
	case 'N':
		temp = dice->num[6] ;
		dice->num[6] = dice->num[5] ;
		dice->num[5] = dice->num[1] ;
		dice->num[1] = dice->num[2] ;
		dice->num[2] = temp;
		break;
	case 'S':
		temp = dice->num[6] ;
		dice->num[6] = dice->num[2] ;
		dice->num[2] = dice->num[1] ;
		dice->num[1] = dice->num[5] ;
		dice->num[5] = temp;
		break;
	case 'E':
		temp = dice->num[6] ;
		dice->num[6] = dice->num[3] ;
		dice->num[3] = dice->num[1] ;
		dice->num[1] = dice->num[4] ;
		dice->num[4] = temp;
		break;
	case 'W':
		temp = dice->num[6] ;
		dice->num[6] = dice->num[4] ;
		dice->num[4] = dice->num[1] ;
		dice->num[1] = dice->num[3] ;
		dice->num[3] = temp;
		break;
	}
}

int main(void)
{
	struct DICE dice;
	int i, q, top, front, right;
	
	for(i=1; i<=6; i++) {
		scanf("%d",&dice.num[i]);
	}
	scanf("%d",&q);
	for (i=0; i<q; i++) {
		scanf("%d %d",&top,&front);
		while (dice.num[2] != front) {
			if (dice.num[3] == front || dice.num[4] == front) {
				throwdice('E', &dice);
			}
			throwdice('N', &dice);
		}
		while (dice.num[1] != top) {
			throwdice('E', &dice);
		}
		printf("%d\n", dice.num[3]);
	}
	return 0;
}

Measured memory_bytes: 596
#!/usr/bin/env python3
import collections

N, K, Q = list(map(int, input().split()))
a_list = []

for _ in range(Q):
    a = int(input().split()[0])
    a_list.append(a)

p_list = [K] * N
a_counter = collections.Counter(a_list)
result_list = []

count_dict = {i + 1: 0 for i in range(N)}
count_dict.update(dict(a_counter))

for winner in range(1, N + 1):
    # 負けた回数
    win_count = count_dict[winner]
    l_count = Q - win_count
    result = "Yes" if l_count < K else "No"
    result_list.append(result)

ans = "\n".join(result_list)
print(ans)


Measured memory_bytes: 23800
import scala.io.StdIn.readInt

object Main {

  def getMax(i:Int,minv:Int,maxv:Int,r:Int):Int = {
    val m = r-minv
    if(i==1) m.max(maxv)
    else getMax(i-1,r.min(minv),m.max(maxv),readInt)
  }

  def main(args:Array[String]) =
    println(getMax(readInt-1,readInt,Int.MinValue,readInt))

}

Measured memory_bytes: 62656
#include <bits/stdc++.h>
#define ld long double
#define endl "\n"
#define fastio ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define pb(x) push_back(x)
#define mp(a,b) make_pair(a,b)
#define ms(v,x) memset(v,x,sizeof(v))
#define all(v) v.begin(),v.end()
#define ff first
#define ss second
#define rep(i, a, b) for(int i = a; i < (b); ++i)
#define per(i, a, b) for(int i = b-1; i>=a ; i--)
#define trav(a, x) for(auto& a : x)
#define allin(a , x) for(auto a : x)
#define td(v) v.begin(),v.end()
#define sz(v) (int)v.size()
#define int long long
using namespace std;
typedef vector<int> vi;
#define y1 abacaba
#define left sefude
typedef long long ll;
typedef pair<int,int> pii;
inline ll mod(ll n, ll m ){ ll ret = n%m; if(ret < 0) ret += m; return ret; }
ll gcd(ll a, ll b){return (b == 0LL ? a : gcd(b, a%b));}
ll exp(ll a,ll b,ll m){
    if(b==0LL) return 1LL;
    if(b==1LL) return mod(a,m);
    ll k = mod(exp(a,b/2,m),m);
    if(b&1LL){
        return mod(a*mod(k*k,m),m);
    }
    else return mod(k*k,m);
}

const int N = 200100;
int a[N],b[N];

  
int32_t main(){
  fastio;
  int n;
  cin>>n;
  for(int i=1;i<=n;i++){
    cin >> a[i];
  }
  for(int i=2;i<=n;i++){
    b[1]^=a[i];
  }
  for(int i=2;i<=n;i++){
    b[i] = (a[i]^b[1]^a[1]);
  }
  for(int i=1;i<=n;i++){
    cout << b[i]<<" ";
  }
  cout << endl;
  // Math -> gcd it all
  // Did u check N=1? Did you switch N,M?
}

Measured memory_bytes: 6732
fun main(args: Array<String>) {
    val (n, m, x) = readLine()!!.split(" ").map { it.toInt() }
    val a = readLine()!!.split(" ").map { it.toInt() }

    var right = 0
    var left = 0
    for (stop in a) {
        if (stop < x) {
            left++
        } else {
            right++
        }
    }
    println(if (left < right) left else right)
}

Measured memory_bytes: 35992
N, *S = open(0).read().split()
d = {
    'AC': 0,
    'WA': 0,
    'TLE': 0,
    'RE': 0,
}
for s in S:
    if s in d:
        d[s] += 1
print('AC x', d['AC'])
print('WA x', d['WA'])
print('TLE x', d['TLE'])
print('RE x', d['RE'])

Measured memory_bytes: 17096
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
using Graph = vector<vector<int>>;
const int INF = 1e9 + 1;
const ll LLINF = 1e18;
const int MOD = 1e9 + 7;

int main() {
    int N, M;
    cin >> N >> M;
    map<int, int> mp;
    for(int i = 2; i <= sqrt(M); ++i) {
        while(M % i == 0) {
            mp[i]++;
            M /= i;
        }
    }
    if(M > 1)
        mp[M]++;

    vector<ll> fac(100050), finv(100050), inv(100050);
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for(int i = 2; i <= N + 50; ++i) {
        inv[i] = MOD - inv[MOD % i] * (MOD / i) % MOD;
        fac[i] = fac[i - 1] * i % MOD;
        finv[i] = finv[i - 1] * inv[i] % MOD;
    }

    ll ans = 1;
    for(auto i : mp) {
        int n = i.second + N - 1;
        ans *= fac[n] * (finv[n - i.second] * finv[i.second] % MOD) % MOD;
        ans %= MOD;
    }

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


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

const int64_t MOD = 1000000007;
typedef int64_t ll;
typedef uint64_t ull;

#define FOR(i, start, end) for(uint64_t i=start; i<end; i++)
#define REP(i, n) FOR(i, 0, n)

// 最大公約数gcd
// 最小公倍数lcm=m*n/gcd
uint64_t gcd(uint64_t m, uint64_t n) {
  uint64_t temp;
  while (m % n != 0){
    temp = n;
    n = m % n;
    m = temp;
  }
  return n;
}

uint64_t lcm(uint64_t m, uint64_t n) {
  return (m*n)/gcd(m,n);
}

// vector<vector<uint64_t> > v(n+1, vector<uint64_t>(n+1, 0))
// v[n][k]に組み合わせ数が入る。
void comb(vector<vector <uint64_t> > &v){
  for(uint64_t i = 0;i <v.size(); i++){
    v[i][0]=1;
    v[i][i]=1;
  }
  for(uint64_t k = 1;k <v.size();k++){
    for(uint64_t j = 1;j<k;j++){
      v[k][j]=(v[k-1][j-1]+v[k-1][j]);
    }
  }
}

// 掛け算オーバーフロー判定
bool is_product_overflow(uint64_t a, uint64_t b) {

	uint64_t prod = a * b;
	
	return (prod / b != a);
}

//素因数分解
void primeFactorization(uint64_t a, list<uint64_t> &factors){ //素因数分解を出力するプログラム
  long i,sq;
  if(a%2==0){ //偶数の場合
    factors.push_back(2);
    primeFactorization(a/2,factors); //2で割った値で再帰
    return;
  }
  sq = sqrt(a);
  for(i=3;i<=sq;i+=2){ //3以上√a以下の奇数の場合
	if(a%i==0){
	  factors.push_back(i);
      primeFactorization(a/i,factors); //割れた値で再帰
      return;
	}
  }
  //偶数でも3以上√a以下の奇数の場合でも割り切れない場合
  if(a!=1){ //aが1でないなら、a自身は素数
    factors.push_back(a);
  }
}

// フェルマーの小定理
// mod. m での a の逆元 a^{-1} を計算する
// (a/b)%m = a*movinv(b,m)%m  
int64_t modinv(int64_t a, int64_t m) {
    int64_t b = m, u = 1, v = 0;
    while (b) {
        int64_t t = a / b;
        a -= t * b; swap(a, b);
        u -= t * v; swap(u, v);
    }
    u %= m;
    if (u < 0) u += m;
    return u;
}

// 円周率
// M_PI

// #include <iomanip> // setprecisionを使用するのに必要
// cout << std::fixed << std::setprecision(15) << y << endl;

// 昇順
// priority_queue<int, vector<int>, greater<int> > queue;

ll pCount(int x){
  if(x==0) return 1;
  return pCount(x-1)*2 + 1;
}

ll allCount(int x){
  if(x==0) return 1;
  return allCount(x-1)*2 + 3;
}


signed main() {
  string s;
  cin >> s;
  ll k;
  cin >> k;
  
  int oneCount = 0;
  char nextChar = 0;
  for(auto c:s){
    if(c=='1'){
      oneCount++;
    }
    else{
      nextChar = c;
      break;
    }
  }
  
  if(k<=oneCount){
    cout << "1" << endl;
  }
  else{
    cout << nextChar << endl;
  }
  
  return 0;
}



Measured memory_bytes: 3712
#include <iostream>

using namespace std;

typedef long long ll;

#define rep(i,n) REP(i,0,n)
#define REP(i,a,n) for(int i = a ; i < (int)n ; i++)
#define INF 2000000000
#define int ll

ll n;
ll input[200001];
ll l[100002];
ll r[100002];

ll merge(int left, int right, int mid){
  rep(i, mid - left) l[i] = input[left + i];
  rep(i, right - mid) r[i] = input[mid + i];
  
  // 番兵
  l[mid -left] = r[right - mid] = INF;
  int l_idx, r_idx;
  ll cnt;
  l_idx = r_idx = 0;
  cnt = 0;
  REP(i, left, right){
    if(l[l_idx] <= r[r_idx]){
      input[i] = l[l_idx];
      l_idx++;
    }else{
      input[i] = r[r_idx];
      r_idx++;
      cnt += ((mid - left) - l_idx);
    }
  }
  return cnt;
}

ll mergeSort(int left, int right){
  if(right - left > 1){
    int mid = (right + left)/2;
    ll ret = mergeSort(left, mid);
    ret += mergeSort(mid, right);
    return (ret + merge(left, right, mid));
  }else{
    return 0;
  }
}

signed main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  
  cin >> n;
  rep(i, n){
    cin >> input[i];
  }

  cout << mergeSort(0, n) << endl;
}


Measured memory_bytes: 6252
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
int main()
{
    int a[4],b[3],i,m[3];
    char num[5];
    scanf("%s",num);
    for (i=0;i<4;i++)
    {
        a[i]=num[i]-'0';
    }
    for (i=0;i<8;i++)
    {
        m[0]=i%2;
        m[1]=i/2%2;
        m[2]=i/4%2;
        b[0]=pow(-1,m[0])*a[1];
        b[1]=pow(-1,m[1])*a[2];
        b[2]=pow(-1,m[2])*a[3];
        if (a[0]+b[0]+b[1]+b[2]==7) break;
    }
    printf("%d",a[0]);
    for (i=0;i<3;i++)
    {
        if (m[i]) printf("-");
        else printf("+");
        printf("%d",a[i+1]);
    }
    printf("=7");
    return 0;
}


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

int main(){
    int N;
    cin >> N;
    int A[N + 1] = {};
    int B[N] = {};
    for (int i = 0;i < N + 1;i++){
        cin >> A[i];
    }
    for (int i = 0;i < N;i++){
        cin >> B[i];
    }
    long long count = 0;
    for (int i = 0;i < N; i++){
        if (A[i] >= B[i]) count += B[i];
        else{
            count += A[i];
            B[i] -= A[i];
            if (A[i + 1] >= B[i]){
                count += B[i];
                A[i + 1] -= B[i];
            }
            else{
                count += A[i + 1];
                A[i + 1] = 0;
            }
        }
    }
    cout << count << endl;
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
#define pb          emplace_back
#define ll          long long
#define fi          first
#define se          second
#define mp          make_pair

using namespace std;

typedef pair<int, int> pii;
const int N = int(2e5) + 7;

vector<pii> v;
int xa, ya, xb, yb, r, c, n, x1, x2;
vector<int> s;

int32_t main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0), cout.tie(0);
    #define Task        "test"
    if(fopen(Task".inp", "r")) {
        freopen(Task".inp", "r", stdin);
        freopen(Task".out", "w", stdout);
    }
    cin >> r >> c >> n; ++r, ++c;
    for(int i = 0; i < n; ++i) {
        cin >> xa >> ya >> xb >> yb;
        if(xa == 0) x1 = ya;
        else if(ya == c - 1) x1 = c + xa;
        else if(xa == r - 1) x1 = c + r + c - ya - 1;
        else if(ya == 0) x1 = 2 * c + r + r - xa - 1;
        else continue;
        if(xb == 0) x2 = yb;
        else if(yb == c - 1) x2 = c + xb;
        else if(xb == r - 1) x2 = c + r + c - yb - 1;
        else if(yb == 0) x2 = 2 * c + r + r - xb - 1;
        else continue;
        v.pb(x1, i); v.pb(x2, i);
    }
    sort(v.begin(), v.end());
    for(pii p: v) {
        if(s.size() && p.se == s.back()) s.pop_back();
        else s.pb(p.se);
    }
    cout << (s.empty() ? "YES": "NO");
}


Measured memory_bytes: 2672
#include "iostream"
#include "climits"
#include "list"
#include "queue"
#include "stack"
#include "set"
#include "functional"
#include "algorithm"
#include "string"
#include "map"
#include "unordered_map"
#include "unordered_set"
#include "iomanip"
#include "cmath"
#include "random"
#include "bitset"
#include "cstdio"
#include "numeric"
#include "cassert"
#include "ctime"

using namespace std;

//constexpr long long int MOD = 1000000007;
//constexpr int MOD = 1000000007;
//constexpr int MOD = 998244353;
constexpr long long int MOD = 998244353;
constexpr double EPS = 1e-12;

//int N, M, K, T, H, W, L, R;
long long int N, M, K, T, H, W, L, R;

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

	cin >> N >> K >> M;
	if (N == 1) {
		cout << K << endl;
		return 0;
	}
	map<int, int>mp;
	mp[K] = 0;
	N--;
	vector<long long int>sum(1, 0);
	sum.push_back(K);
	int cnt = 1;
	while (1) {
		K = K * K%M;
		sum.push_back(sum.back() + K);
		if (mp.find(K) == mp.end()) {
			mp[K] = cnt;
		}
		else {
			if ((N - cnt) % (cnt - mp[K]) == 0) {
				sum.back() += (N - cnt) / (cnt - mp[K])*(sum.back() - sum[mp[K]+1]);
				break;
			}
			mp[K] = cnt;
		}
		if (cnt == N)break;
		cnt++;
	}
	cout << sum.back() << endl;
}

Measured memory_bytes: 6412
#include<bits/stdc++.h>
#define rep(i,n) for (int i=0; i<n; i++)
#define REP(i,x,n) for (int i=x; i<n; i++)
using namespace std;
using vi = vector<int>;
using vvi = vector<vi>;
using ll = long long;
const int mod =1'000'000'007;

int main(){
    int n, m;
    cin >> n >> m;
    vi h(n);
    rep(i,n) cin >> h.at(i);
    vvi list(n);
    rep(i,m){
        int a, b;
        cin >> a >> b;
        a--; b--;
        list.at(a).push_back(b);
        list.at(b).push_back(a);
    }
    int ans = 0;
    rep(i,n){
        bool flag = true;
        for (auto ele : list.at(i)){
            if (h.at(i) <= h.at(ele)) flag = false;
        }
        ans += flag? 1 : 0;
        // if (flag) cout << i << endl;
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 8732
#include<bits/stdc++.h>
#include <iostream>
#include <cstdio>
#define endl '\n'
using namespace std;
int main(int argc, char const *argv[])
{
	int n;
	cin>>n;
	int cnt,Max = 0,output = 1;
	for(int i = 1; i<=n; i++)
	{
		//if(i == 1)Max = 0;
		int num = i;
		cnt = 0;
		if(num%2==0){
			while(num%2==0)
			{
				num/=2;
				cnt++;
			}
		}
		//Max = max(Max,cnt);
		//cout<<i<<" "<<cnt<<endl;
		if(cnt > Max)Max = cnt,output = i;
		//cout<<Max<<" "<<output<<endl;
	}
	cout<<output;
	return 0;
}


Measured memory_bytes: 256
#include<cstdio>
#include<iostream>
#include<cmath>
#define LL long long
using namespace std;

int n;
int xx[20],yy[20],dis[20];
LL ans[20],p[20];
void f(int t,int x)
{
	int i;
	LL res=0;
	int dis2[20];
	for(i=1;i<=n;i++)
	{
		dis2[i]=dis[i];
		res+=dis2[i]*p[i];
	}
	ans[t]=min(ans[t],res);
	if(x>n) return;
	for(i=1;i<=n;i++)
		dis[i]=min(dis[i],abs(xx[i]-xx[x]));
	f(t+1,x+1);
	for(i=1;i<=n;i++)
		dis[i]=min(dis2[i],abs(yy[i]-yy[x]));
	f(t+1,x+1);
	for(i=1;i<=n;i++)
		dis[i]=dis2[i];
	f(t,x+1);
}
int main()
{
	int i;
	cin>>n;
	for(i=0;i<=n;i++)
		ans[i]=1ll<<60;
	for(i=1;i<=n;i++)
	{
		cin>>xx[i]>>yy[i]>>p[i];
		dis[i]=min(abs(xx[i]),abs(yy[i]));
	}
	f(0,1);
	for(i=0;i<=n;i++)
	{
		if(ans[i]<(1ll<<60)) cout<<ans[i]<<endl;
		else cout<<0<<endl;
	}
	return 0;
}

Measured memory_bytes: 3604
#include <iostream>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <algorithm>
#include <vector>
#include <map>
#include <queue>
using namespace std;
typedef long long LL;
const int N = 1e5 + 24;
struct node{
	int to;
	LL val;
	node(){};
	node(int _to, LL _val): to(_to),val(_val){}
};
int n,m;
vector<node>G[N];
int vis[N];
LL d[N];
void init(){
	for(int i = 0; i < N; i++)
		G[i].clear();
}
void spfa(int st){
	memset(vis,0,sizeof(vis));
	fill(d,d+N,1e16);
	queue<int>q;
	q.push(st);
	vis[st] = 1;
	d[st] = 0;
	while(!q.empty()){
		int st = q.front();
		vis[st] = 0;
		q.pop();
		for(int i = 0; i < G[st].size(); i++){
			int to = G[st][i].to;
			if(d[to] > d[st]+G[st][i].val){
				d[to] = d[st]+G[st][i].val;
				if(!vis[to]){
					q.push(to);
					vis[to] = 1;
				}
			}
		}
	}
}
int main(){
#ifdef CDZSC_OFFLINE
	freopen("in.txt","r",stdin);
#endif //CDZSC_OFFLINE
	while(scanf("%d",&n) != EOF){
		init();
		int st,to;
		LL k;
		for(int i = 1; i < n; i++){
			scanf("%d%d%lld",&st,&to,&k);
			G[st].push_back(node(to,k));
			G[to].push_back(node(st,k));
		}
		int x;
		scanf("%d%d",&m,&x);
		spfa(x);
		for(int i = 0; i < m; i++){
			scanf("%d%d",&st,&to);
			printf("%lld\n",d[st]+d[to]);
		}
	}
}

Measured memory_bytes: 10368
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<bitset>
#include<set>
#include<map>
#include<stack>
#include<queue>
#include<deque>
#include<list>
#include<iomanip>
#include<cmath>
#include<cstring>
#include<functional>
using namespace std;
using ll = long long;

double S( double a, double b, double theta ){
  double x;
  if( theta < atan2( b, a ) ){
    x = ( 2*b - a*tan(theta) )*a*a/2;
  }else{
    x = b*b*a/tan(theta)/2;
  }
  return x;
};

int main(){
  double a, b, x;
  cin >> a >> b >> x;
  double PI = acos(-1.0);
  double theta1 = 0.0, theta2 = PI/2, theta3;
 
  while( (theta2 - theta1) > 1e-8 ){
    theta3 = ( theta1 + theta2 ) / 2;
    if( S( a, b, theta3 ) < x ){
      theta2 = theta3;
    }else{
      theta1 = theta3;
    }
  }
  printf( "%.10lf", theta3*180.0/PI );
  return 0;
}



Measured memory_bytes: 512
#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<algorithm>
#include<vector>
#include<string>
#include<sstream>
#include<iomanip>
#include<utility>
#include<cmath>
#include<set>
#include<list>
#include<queue>
#include<stack>
#include<deque>
#include<map>
#include<set>
#include<cstring>
#include<iterator>
#include<bitset>
#include<assert.h>
using namespace std;
 
struct edge {int /*from,*/to,cost;};
typedef long long ll;
typedef pair<int,int> P;
typedef pair<int,pair<int,int> > PP;
typedef vector<int> VI;
typedef vector<long long int> VL;
typedef vector<edge> VE;
static const int MOD = 1000000007;
//static const int INF = 2147483647;
//static const long long INF = 9223372000000000000;
//static const long long INF = 9223372000000000000/2;
//static const int INF = 1000010000;
int dx4[4] = {0,1,0,-1}, dy4[4] = {-1,0,1,0};
//int dx5[5] = {-1,0,0,0,1}, dy5[5] = {0,-1,0,1,0};
//int dx8[8] = {-1,0,1,1,1,0,-1,-1}, dy8[8] = {1,1,1,0,-1,-1,-1,0};
//int dx9[9] = {-1,0,1,1,1,0,-1,-1,0}, dy9[9] = {1,1,1,0,-1,-1,-1,0,0};
#define PB push_back
#define MP make_pair
#define FI first
#define SE second
#define NP next_permutation
#define PQ priority_queue
#define UB upper_bound
#define LB lower_bound
#define ALL(x) (x).begin(),(x).end()
#define SZ(a) int((a).size())
#define LEN(a) int((a).length())
#define MAX(a,b,c) max((a),max((b),(c)))
#define MIN(a,b,c) min((a),min((b),(c)))
#define SORT(c) sort((c).begin(),(c).end())
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define REP(i,x) for(int i=0;i<(int)(x);i++)
#define REP1(i,x) for(int i=1;i<=(int)(x);i++)
#define RREP(i,x) for(int i=((int)(x)-1);i>=0;i--)
#define RREP1(i,x) for(int i=((int)(x));i>0;i--)
//#define int ll

signed main(){
    int a,b;
    char c;
    scanf("%d %c %d",&a,&c,&b);
    c=='+'?printf("%d\n",a+b):printf("%d\n",a-b);
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <array>
#include <unordered_set>
#include <set>
#include <cmath>
#include <string>
#include <queue>
#include <list>
#include <unordered_map>
#include <algorithm>
#include <functional>
#include <iomanip> // std::std::setprecision(X)
#include <limits>  //std::numeric_limits<int>::max(), min()


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

  long long N, M; std::cin >> N >> M;

  std::vector<std::vector<long long>> G(N);
  for(int i=0; i<N; i++) G[i].reserve(N);

  for(int i=0; i<M; i++) {
    long long u, v; std::cin >> u >> v;
    G[u-1].push_back(v-1);
  }

  long long S, T; std::cin >> S >> T;

  std::vector<std::vector<long long>> memo(N, std::vector<long long>(3, -1));
  std::queue<std::pair<long long, int>> q;
  q.push( { S-1, 0 } ); memo[S-1][0] = 0;
  while(!q.empty()){
    auto cur = q.front(); q.pop();
    for(auto& next : G[cur.first] ) {
      if ( memo[next][(cur.second+1)%3] != -1 ) continue;
      if ( next == T-1 && (cur.second+1)%3 == 0 ) {
        std::cout << (memo[cur.first][cur.second]+1)/3 << std::endl;
        return 0;
      }
      if(memo[next][(cur.second+1)%3] == -1 ) {
        memo[next][(cur.second+1)%3] = memo[cur.first][cur.second]+1; q.push( {next,(cur.second+1)%3} );
      }
    }
  }
  std::cout << -1 << std::endl;

  return 0;
}


Measured memory_bytes: 408576
a, b = map(int, input().split())
lst = []
s = 0

for i in range(1, 1001):
    s += i
    lst.append(s)

for i in range(999):
    x = lst[i] - a
    y = lst[i+1] - b

    if x == y and x > 0 and y > 0:
        print(x)


Measured memory_bytes: 38256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define P pair<int,int>
#define FOR(I,A,B) for(int I = (A); I < (B); ++I)
#define FORR(I,A,B) for(int I = ((B)-1); I >= (A); --I)
#define TO(x,t,f) ((x)?(t):(f))
#define SORT(x) (sort(x.begin(),x.end())) // 0 2 2 3 4 5 8 9
#define REV(x) (reverse(x.begin(),x.end())) //reverse
int gcd(int a,int b){if(a<b)swap(a,b);if(a%b==0)return b;return gcd(b,a%b);}
int lcm(int a,int b){int c=gcd(a,b);return ((a/c)*(b/c)*c);}//saisyo kobaisu
#define NEXTP(x) next_permutation(x.begin(),x.end())
const ll INF=1e18+7;
const ll MOD=1e9+7;
#define pri(a) cout << (a) << endl
char x[] = {'7','5','3'};
string xx[]={"7","5","3"};
string k;
int n;
int ans;

int main(){
	ios::sync_with_stdio(false);
	cin.tie(0);
	cin >> n;
	set<string> t,se;
	FOR(i,0,3)t.insert(xx[i]);
	FOR(i,0,3)se.insert(xx[i]);
	while(1){
		set<string> p;
		if(t.size()==0)break;
		for (auto y:t){
			if(y.size()<9){
				FOR(i,0,3)p.insert(y+x[i]);
				FOR(i,0,3)se.insert(y+x[i]);
			}
		}
		t = p;
	}
	for(string y:se){
		bool x3=false,x5=false,x7=false;
		for(char z:y){
			if(z=='7')x7=true;
			if(z=='5')x5=true;
			if(z=='3')x3=true;
		}
		if(x3&&x5&&x7)if(n>=stoi(y))ans++;
	}
	cout << ans << endl;
}

Measured memory_bytes: 6400
import java.util.Scanner;

public class Main {
    
	public static void main(String[] args){
	    
		Scanner scanner = new Scanner(System.in);
		
		int S = scanner.nextInt();
		int h = S/3600;
		int m = S%3600/60;
		int f = S%3600%60;
		
		System.out.println(h+":"+m+":"+f);
	}
    
}


Measured memory_bytes: 26212
from collections import Counter,defaultdict,deque
from heapq import heappop,heappush,heapify
import sys,bisect,math,itertools,fractions
from decimal import Decimal
sys.setrecursionlimit(10**8)
mod = 10**9+7
INF = float('inf')
def inp(): return int(sys.stdin.readline())
def inpl(): return list(map(int, sys.stdin.readline().split()))

n,K = inpl()
a = [inpl() for _ in range(n)]
res = INF
for i in range(1):
    a.sort(key=lambda x:x[i])
    for j in range(n-1):
        for k in range(j+1,n):
            l = a[j][i]
            r = a[k][i]
            b = [a[j],a[k]]
            cnt = 2
            for _ in range(n):
                if _ == j or _ == k:
                    continue
                if l < a[_][i] < r:
                    cnt += 1
                    b += [a[_]]
            if cnt < K: continue
            b.sort(key=lambda x:x[i^1])
            # print(j,k,b,i)
            for _ in range(cnt-K+1):
                u = max(x[i^1] for x in b[_:_+K])
                d = min(x[i^1] for x in b[_:_+K])
                res = min(res, (r-l)*(u-d))
                # print(res)
print(res)

Measured memory_bytes: 73176
#include <iostream>
#include <string>
#include <stdlib.h>
using namespace std;

int main() {
  int n, a, b, c, d;
  string s;
  cin >> n >> a >> b >> c >> d;
  cin >> s;
  
  int count = 0;
  for (int i=a-1;i<c;i++){
    if (s[i] == '#') count += 1;
    else count = 0;
    if (count >= 2){
      cout << "No" << endl;
      exit(0);
    }
  }
    
  count = 0;
  for (int i=b-1;i<d;i++){
    if (s[i] == '#') count += 1;
    else count = 0;
    if (count >= 2){
      cout << "No" << endl;
      exit(0);
    }
  }
  
  if (c<b){
    cout << "Yes" << endl;
    exit(0);
  }
  else if (c<d){
    cout << "Yes" << endl;
    exit(0);
  }
  else{
    count = 0;
    for (int i=b-2;i<d+1;i++){
      if (s[i] == '.') count += 1;
      else count = 0;
      if (count >= 3){
        cout << "Yes" << endl;
        exit(0);
      }
    }
  }
  cout << "No" << endl;
}

Measured memory_bytes: 640
import java.util.*;
public class Main{
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    String n = sc.next();
    for(int i = 0; i < n.length()/2; i++){
      if(n.charAt(i) != n.charAt(n.length()-i-1)){
        System.out.println("No");
        System.exit(0);
      }
    }
    System.out.println("Yes");
  }
}


Measured memory_bytes: 20948
package main

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

func main() {
	io := newIo()
	defer io.Flush()
	N, X := io.NextInt(), io.NextInt()
	result := 0
	prev := 0
	for i := 0; i < N; i++ {
		a := io.NextInt()
		if prev+a > X {
			result += a - (X - prev)
			a = X - prev
		}
		prev = a
	}
	fmt.Println(result)
}

type io struct {
	reader    *bufio.Reader
	writer    *bufio.Writer
	tokens    []string
	nextToken int
}

func newIo() *io {
	return &io{
		reader: bufio.NewReader(os.Stdin),
		writer: bufio.NewWriter(os.Stdout),
	}
}

func (io *io) Flush() {
	err := io.writer.Flush()
	if err != nil {
		panic(err)
	}
}

func (io *io) NextLine() string {
	var buffer []byte
	for {
		line, isPrefix, err := io.reader.ReadLine()
		if err != nil {
			panic(err)
		}
		buffer = append(buffer, line...)
		if !isPrefix {
			break
		}
	}
	return string(buffer)
}

func (io *io) Next() string {
	for io.nextToken >= len(io.tokens) {
		line := io.NextLine()
		io.tokens = strings.Fields(line)
		io.nextToken = 0
	}
	r := io.tokens[io.nextToken]
	io.nextToken++
	return r
}

func (io *io) NextInt() int {
	i, err := strconv.Atoi(io.Next())
	if err != nil {
		panic(err)
	}
	return i
}

func (io *io) NextFloat() float64 {
	i, err := strconv.ParseFloat(io.Next(), 64)
	if err != nil {
		panic(err)
	}
	return i
}

func (io *io) PrintLn(a ...interface{}) {
	fmt.Fprintln(io.writer, a...)
}

func (io *io) Printf(format string, a ...interface{}) {
	fmt.Fprintf(io.writer, format, a...)
}

func (io *io) PrintIntLn(a []int) {
	b := []interface{}{}
	for _, x := range a {
		b = append(b, x)
	}
	io.PrintLn(b...)
}

func (io *io) PrintStringLn(a []string) {
	b := []interface{}{}
	for _, x := range a {
		b = append(b, x)
	}
	io.PrintLn(b...)
}

func log(name string, value interface{}) {
	fmt.Fprintf(os.Stderr, "%s=%+v\n", name, value)
}


Measured memory_bytes: 6912
#define _CRT_SECURE_NO_WARNINGS

#include<stdio.h>
#include<string.h>
int main()
{
	int a, b, c;
	int i;
	scanf("%d %d", &a, &b);
	c = b - a;
	if (a > 0){
		printf("Positive");
	}
	else if (b>=0) {
		printf("Zero");
	}
	else if ((b - a) % 2) {
		printf("Positive");
	}
	else {
		printf("Negative");
	}
	return 0;
}


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

using namespace std;

#define debug(x,y) cout<<(#x)<<" " <<(#y)<<" is " << (x) <<" "<< (y) << endl
#define watch(x) cout<<(#x)<<" is " << (x) << endl
#define fast ios_base::sync_with_stdio(false)
#define fie(i,a,b) for(i=a;i<b;i++)
#define MOD 1000000007
#define mod 998244353
#define PB push_back
#define EB emplace_back
#define MP make_pair
#define FI first
#define SE second
#define ll long long
#define lld long long int
#define ALL(x) (x).begin(),(x).end()

typedef vector<lld> vi;
typedef vector<vector<lld>> vii;
typedef vector<string> vs;
typedef vector<bool> vb;
typedef vector<pair<lld, lld>> vpi;
typedef long long LL;

int main() {
    fast;
    cin.tie(0);
/*#ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w" , stdout);
#endif*/
    lld s, w;
    cin >> s >> w;
    if (w >= s) cout << "unsafe" << endl;
    else cout << "safe" << endl;

}


Measured memory_bytes: 3612
#include "bits/stdc++.h"
using namespace std;
 
////////////// Prewritten code follows. Look down for solution. ////////////////

#define int long long
#define endl '\n'
#define fs first
#define sc second
#define pb push_back
#define len(x) ((int)(x).size())     
#define all(x) (x).begin(), (x).end()
#define test int _; cin >> _; while(_--)
#define fastio ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);

typedef pair<int, int> pii;
typedef long long ll;
typedef long double ld;

const ll LINF = 0x3f3f3f3f3f3f3f3f;
const int INF = 0x3f3f3f3f;
const ll MOD = 1e9+7;

ll gcd(ll a, ll b){return (b == 0LL ? a : gcd(b, a%b));}
inline ll mod(ll a, ll b){return ((a%b)+b)%b;}
inline ll expo(ll b, ll p, ll m = MOD){
  ll ans = 1; 
  while(p > 0){
    if(p&1LL) ans = mod(ans*b, m); 
    b = mod(b*b, m); 
    p >>= 1LL;
  } 
  return ans;
}
 
////////////////////////// Solution starts below. //////////////////////////////

typedef vector<vector<int>> matriz;

int n, k;

matriz mult(matriz a, matriz b){
  matriz c(n, vector<int>(n, 0));
  for(int i = 0; i < n; i++){
    for(int j = 0; j < n; j++){
      for(int z = 0; z < n; z++){
        c[i][j] = (c[i][j] + (a[i][z]*b[z][j])%MOD)%MOD;
      }
    }
  }
  return c;
}

matriz Expo(matriz a, int p){
  if(p == 1) return a;
  matriz m = Expo(a, p/2);
  m = mult(m, m);
  if(p&1) m = mult(m, a);
  return m;
}

int32_t main(){
  fastio;
  cin >> n >> k;
  vector<int> in(n, 0);
  matriz m(n, vector<int>(n, 0));
  for(int i = 0; i < n; i++){
    for(int j = 0; j < n; j++){
      cin >> m[j][i];
    }
  }
  for(int i = 0; i < n; i++){
    for(int j = 0; j < n; j++){
      in[i] += m[i][j];
    }
  }
  if(k == 1){
    int ans = 0;
    for(int i = 0; i < n; i++){
      ans = (ans + in[i])%MOD;
    }
    cout << ans << endl;
  }else{
    vector<int> ans(n, 0);
    int resp = 0;
    m = Expo(m, k-1);
    for(int i = 0; i < n; i++){
      for(int j = 0; j < n; j++){
        ans[i] = (ans[i] + m[i][j]*in[j])%MOD;
      }
    }
    for(int i = 0; i < n; i++){
      resp += ans[i];
      resp %= MOD;
    }
    cout << resp << endl;
  }
  return 0;
}

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

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

	long long vehicle[5];
	for (int i = 0; i < 5; ++i) {
		cin >> vehicle[i];
	}

	long long minutes = 0;

	minutes += n / vehicle[0];
	if (n % vehicle[0] != 0) {
		++minutes;
	}

	long long prevMin = minutes;
	long long prev = vehicle[0];
	for (int i = 1; i < 5; ++i) {
		if (prev <= vehicle[i]) {
			++minutes;
		}
		else {
			long long t = n / vehicle[i];
			if (n % vehicle[i] != 0) {
				++t;
			}
			minutes += t - prevMin + 1;
			prevMin = t;
			prev = vehicle[i];
		}
	}

	cout << minutes << endl;

	return 0;
}

Measured memory_bytes: 256