akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <bits/stdc++.h>
#include <vector>

int main(int argc, char const *argv[])
{
    int a, b;
    char op;

    std::vector<int> vector_a, vector_b;
    std::vector<char> vector_op;

    while (1)
    {

        std::cin >> a >> op >> b;
        if (op == '?')
        {
            break;
        }
        else
        {
            vector_a.emplace_back(a);
            vector_b.emplace_back(b);
            vector_op.emplace_back(op);
        }
    }

    for (int i = 0; i < vector_a.size(); i++)
    {
        if (vector_op[i] == '+')
        {
            std::cout << vector_a[i] + vector_b[i] << std::endl;
        }
        else if (vector_op[i] == '-')
        {
            std::cout << vector_a[i] - vector_b[i] << std::endl;
        }
        else if (vector_op[i] == '*')
        {
            std::cout << vector_a[i] * vector_b[i] << std::endl;
        }
        else if (vector_op[i] == '/')
        {
            std::cout << vector_a[i] / vector_b[i] << std::endl;
        }
    }

    return 0;
}



Measured memory_bytes: 3152
#include <iostream>
#include <map>

using namespace std;

main(){
  int in;
  while(cin >> in){
    map<int, bool> student;
    student[in]=true;
    for(int i=0;i<27;i++){
      cin >> in;
      student[in]=true;
    }
    for(int i=1;i<=30;i++){
      if(!student[i]) cout << i << endl;
    }
  }
  return 0;
}

Measured memory_bytes: 0
#include <bits/stdc++.h>
#define syosu(x) fixed<<setprecision(x)
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> P;
typedef pair<double,double> pdd;
typedef pair<ll,ll> pll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<double> vd;
typedef vector<vd> vvd;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<string> vs;
typedef vector<P> vp;
typedef vector<vp> vvp;
typedef vector<pll> vpll;
typedef pair<int,P> pip;
typedef vector<pip> vip;
const int inf=1<<30;
const ll INF=1ll<<60;
const double pi=acos(-1);
const double eps=1e-8;
const ll mod=1e9+7;
const int dx[4]={-1,0,1,0},dy[4]={0,-1,0,1};

int n,m,x,y,X,Y;
vs a;

int main(){
	cin>>n>>m>>x>>y;
	a=vs(n,string(m,'.'));
	X=x,Y=y;
	if(n%2==1){
		for(int i=0;i<m-1&&x;i+=2){
			a[n-1][i]='<';
			a[n-1][i+1]='>';
			x--;
		}
	}
	if(m%2==1){
		for(int i=0;i<n-1&&y;i+=2){
			a[i][m-1]='^';
			a[i+1][m-1]='v';
			y--;
		}
	}
	for(int i=0;i+1<n/2*2;i+=2) for(int j=0;j<m/2*2;j+=2){
		if(x){
			a[i][j]='<';a[i][j+1]='>';
			x--;
			if(x){
				a[i+1][j]='<';a[i+1][j+1]='>';
				x--;
			}
		}
		else if(y){
			a[i][j]='^';a[i+1][j]='v';
			y--;
			if(y){
				a[i][j+1]='^';a[i+1][j+1]='v';
				y--;
			}
		}
	}
	bool B=0;
	if(!x&&!y) B=1;
	if(!B&&n%2==1&&m%2==1&&n>=3&&m>=3&&X>=2&&Y>=2){
		a=vs(n,string(m,'.'));
		x=X-2,y=Y-2;
		a[0][0]='<';a[0][1]='>';a[0][2]='^';
		a[1][0]='^';a[1][2]='v';
		a[2][0]='v';a[2][1]='<';a[2][2]='>';
		for(int i=3;i<m-1&&x;i+=2){
			a[0][i]='<';
			a[0][i+1]='>';
			x--;
		}
		for(int i=3;i<n-1&&y;i+=2){
			a[i][0]='^';
			a[i+1][0]='v';
			y--;
		}
		for(int i=1;i<n-1;i+=2) for(int j=1;j<m-1;j+=2) if(i>1||j>1){
			if(x){
				a[i][j]='<';a[i][j+1]='>';
				x--;
				if(x){
					a[i+1][j]='<';a[i+1][j+1]='>';
					x--;
				}
			}
			else if(y){
				a[i][j]='^';a[i+1][j]='v';
				y--;
				if(y){
					a[i][j+1]='^';a[i+1][j+1]='v';
					y--;
				}
			}
		}
		if(x+y==0) B=1;
	}
	if(B){
		cout<<"YES"<<endl;
		for(int i=0;i<n;i++) cout<<a[i]<<endl;
	}
	else cout<<"NO"<<endl;
}

Measured memory_bytes: 2304
#include<iostream>
#include<vector>
#include<utility>
#include<map>
#include<deque>
#include<numeric>
#include<algorithm>
#include<unordered_map>

using namespace std;
using ll = long long int;
constexpr int INF = 1 << 29;
constexpr ll MOD = ll(1e9 + 7);

ll n;

int main(void) {
	cin >> n;
	n--;
	cout << n * (n + 1) / 2 << endl;
	return 0;
}

Measured memory_bytes: 256
/**
*    author:  Dooloper
*    created: 01.06.2020 22:44:40
**/

#include <iostream>
#include <vector>
#include <map>
#include <string>
#include <utility>
#include <algorithm>
#include <queue>
#include <deque>
#include <stack>
#include <cmath>
#include <functional>
#include <cassert>


using namespace std;
typedef unsigned long long ull;
#define ll long long

int main() {
    cin.tie(0);
    ll N;cin>>N;
    ll A;
    ull num = 1;
    ll ans =  1;
    bool isZero = false;
    bool isOver = false;
    ll line = pow(10,18);

    for(int i = 0; i < N; i++){
        cin>>A;
        if(A == 0){
            isZero = true;
            ans = 0;
        }
        if(!(isOver || isZero)){
            if(ans > line/A){
                isOver = true;
                ans = -1;
            }else{
                ans *= A;
            }
        }
    }

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

Measured memory_bytes: 3604
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <string>
#include <vector>
#include <map>
#include <set>
#include <cmath>
#include <cstdlib>
#include <stack>
#include <queue>
#include <numeric>
#include <ctime>
using namespace std;

int number(const string &s, int &k);
int expression(const string &s, int &k);
int term(const string &s, int &k);
int factor(const string &s, int &k);

// 式の評価.
int eval(const string &s){
    int k=0;
    int res = expression(s, k);
    /*if( k != s.size() ){
        // 構文規則が正しくない!!!!
    }*/
    return res;
}

bool is_digit(char c){
	return '0' <= c && c <= '9';
}

// <number> ::= <number> <digit> | <digit>
int number(const string &s, int &k){
    int res = 0;
    while( is_digit(s[k]) ){
        res = res * 10 + (s[k] - '0');
        ++k;
    }
    return res;
}

// <expression(式)> := <expression(式)> + <term(項)> | <term(項)> 
int expression(const string &s, int &k){
    int r1 = term(s, k);
     
    while( k < s.size() ){
        if( s[k] == '+' ){
            ++k;
            int r2 = term(s, k);
            r1 = r1 + r2;
        }else if( s[k] == '-' ){
            ++k;
            int r2 = term(s, k);
            r1 = r1 - r2;
        }else{
            break;
        }
    }
    return r1;
}

// <term(項)> := <term(項)> * <factor(因子)> | <factor(因子)>
int term(const string &s, int &k){
    int r1 = factor(s, k);
     
    while( k < s.size() ){
        if( s[k] == '*' ){
            ++k;
            int r2 = factor(s, k);
            r1 = r1 * r2;
        }else if( s[k] == '/' ){
            ++k;
            int r2 = factor(s, k);
            // 0 除算のエラー
            if( r2 == 0 ){
            	return -1;
            }
            r1 = r1 / r2;
        }else{
            break;
        }
    }
    return r1;
}

// <factor(因子)> := (<expression(式)>) | <Number>
int factor(const string &s, int &k){
    if( s[k] == '(' ){ // 括弧のはじまりのとき
        ++k; // '(' の 1つ先に進める.
        int r = expression(s, k);
        // ')' がないとき
        if( s[k] != ')' ) return -1;
         
        ++k; // ')' の 1つ先に進める.
        return r;
    }else if( is_digit(s[k]) ){ // 数字のとき
        return number(s, k);
    }else{ // 構文エラー
        return -1;
    }
}

int main(){
	int n;
	cin >> n;
	for(int i=0 ; i < n ; i++ ){
		string s;
		cin >> s;
		cout << eval(s) << endl;
	}
}

Measured memory_bytes: 1208
#include<bits/stdc++.h>
using namespace std;
int main(){
  string s;
  cin>>s;
  int l=s.length();
  vector<int> count(10);
  int j=0;
  for(int i=0;i<l;i++){
    if(s.at(i)=='A' || s.at(i)=='C' || s.at(i)=='G' || s.at(i)=='T'){
      count[j]++;
    }else{
      j++;
    }
  }
  sort(count.begin(),count.end());
  reverse(count.begin(),count.end());
  cout<<count[0]<<endl;
}

Measured memory_bytes: 3600
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <unistd.h>

#define lli long long int
#define ABS(X) (( (X)>=0 )?(X):(-1 * (X)))
typedef struct s_cell
{
	lli h;
	lli cost;
	lli number;
}	t_cell;


int	main(void)
{
	lli n;
	scanf("%lld", &n);

	t_cell cells[n];
	lli index = 0;

	while (index < n)
	{
		scanf("%lld", &(cells[index].h));
		cells[index].number = index;
		index++;
	}

	cells[0].cost = 0;
	cells[1].cost = ABS(cells[0].h - cells[1].h);
	index = 2;
	lli v = 0;
	lli w = 0;
	while (index < n)
	{
		v = ABS(cells[index-1].h - cells[index].h) + cells[index-1].cost;
		w = ABS(cells[index-2].h - cells[index].h) + cells[index-2].cost;
		cells[index].cost = (v<w)?(v):(w);
		index++;
	}

	printf("%lld",cells[n-1].cost);
	return(0);
}


Measured memory_bytes: 2560
#include <iostream>
using namespace std;
#define MAX 5000

int main(){
    int n,a[MAX];
    
    while(cin >> n,n){
        for(int i = 0 ; i < n ; i++) cin >> a[i];
        
        int max = a[0];
        for(int i = 0 ; i < n ; i++){
            int tmp = 0;
            for(int j = i ; j < n ; j++){
                tmp += a[j];
                if(max < tmp) max = tmp;
            }
        }
        cout << max << endl;
    }
    
    return 0;
}

Measured memory_bytes: 1172
#include<bits/stdc++.h>
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define ll long long
#define pii std::pair<int,int>
#define pli std::pair<ll,int>
#define pil std::pair<int,ll>
#define psi std::pair<string,int>
#define pll std::pair<ll,ll>
#define pci std::pair<char,int>
#define sll(x) scanf("%lld",&x)
#define prll(x) printf("%lld ",x)
#define pri(x) printf("%d ",x)
#define si(x) scanf("%d",&x)
#define pb push_back
#define vll std::vector<ll>
#define vpi std::vector<std::pair<int,int>>
#define vi std::vector<int>
#define vvi std::vector<std::vector<int>>
#define vvpil std::vector<std::vector<std::pair<int,ll>>>
#define vlpii std::vector<std::list<pii>>
#define vlpil std::vector<std::list<pil>>
#define li std::list<int>
#define lpil std::list<pil>
#define Endl printf("\n")
#define vli vector<list<int>>
#define vvll vector<vector<ll>>
#define mp make_pair
#define x first
#define y second
#define ull uint64_t
#define ma 100000000
#define imie(...) "[" << #__VA_ARGS__": " << (__VA_ARGS__) << "] "
const ll  INF=10000000000000;
const ll mod =  1e9 + 7;
using namespace std;
void add(ll& a , ll b){
	a += b;
	if(a >= mod) a -= mod;
}
ll mul(ll a , ll b){
	return (a * b) % mod;
}
ull Pow(ull a , ull b){
	if(b == 0) return 1 ;
	ull c = Pow(a , b / 2) ;
	if(b % 2) return (a * ((c * c) % mod)) % mod;
	return (c * c) % mod ;
}

int main(){
	IOS;
	cout.precision(30) ;
	int n ; cin >> n ;
	int m1 = -1 , m2 = -1 ;
	vll a(n) ; for(int i = 0 ; i < n ; i++){
		 cin >> a[i] ;
		 if(a[i] >= m1){m2 = m1 ; m1 = a[i] ;}
		 else if(a[i] > m2) m2 = a[i] ;
	 }
	 for(int i = 0 ; i < n ; i++){
		 if(a[i] == m1) cout << m2 <<"\n" ;
		 else cout << m1 <<"\n" ;
	 }
		
	return 0;
}


Measured memory_bytes: 3200
n, y = gets.split.map(&:to_i)

a = b = c = -1
valid = false

0.upto([y / 10_000, 2_000].min) do |i|
  break if valid

  0.upto(((y - 10_000 * i) / 5_000)) do |j|
    k = n - i - j
    valid = 10_000 * i + 5_000 * j + 1_000 * k == y

    if valid
      a, b, c = [i, j, k]
      break
    end
  end
end

puts [a, b, c].join(" ")


Measured memory_bytes: 1788
#include<stdio.h>
int main()
{
	int n,a,b,ar=0,br=0;
	while(1){
		scanf("%d",&n);
		if(n==0){
			break;
		}
		for(int i=0;i<n;i++){
			scanf("%d%d",&a,&b);
			if(a>b){
				ar+=(a+b);
			}else if(a==b){
				ar+=a;
				br+=b;
			}else{
				br+=(a+b);
			}
		}
		printf("%d %d\n",ar,br);
		ar=0;
		br=0;
	}
	return 0;
}

Measured memory_bytes: 2676
import collections
n,k = list(map(int, input().split()))
a = list(map(int, input().split()))
acnt = collections.Counter(a)
acnt = sorted(acnt.items(), key=lambda x: x[1])
ans = 0
al = len(acnt)
for i in acnt:
    if al<=k:
        break
    al -= 1
    ans += i[1]

print(ans)

Measured memory_bytes: 39344
#include <string>
#include<iostream>
#include<queue>
#include<vector>
#include<utility>
#define rep(i,n) for(int i=0;i<(n);i++)

using namespace std;
struct edge
{
  int  from,to,cost;
};

int main()
{
  int  N,K;
  cin >> N>>K;
  int d[K];
  int used[N];
  rep(i,N){
    used[i]=0;
  }
  rep(i,K){
    cin >> d[i];
    int A[d[i]];
    rep(j,d[i]){
        cin >> A[j];
        used[A[j]-1]++;
    }
  }
  int sum=0;
  rep(i,N){
    if(used[i]==0) sum++;
  }
  
  cout << sum << endl;
  return 0;

}



Measured memory_bytes: 3624
#include<iostream>
#include<string>
using namespace std;
int main(){
  string s;
  cin >> s;

  int s1, s2;
  s1 = 999;
  string answer = "Good"; 

  for(int i=0; i<4; i++){
    s2 = stoi(s.substr(i,1));
    if(s1==s2){
      answer = "Bad";
      break;
    }
    s1 = s2;
  }
  
  cout << answer << endl;
  return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
const long long mod=1000000007;
int main(){
  long long n,k;
  cin >> n >> k;
  vector<long long> a(n);
  for(int i=0;i<n;i++){
    cin >> a[i];
  }
  long long cnt=0;
  for(int i=0;i<n-1;i++){
    for(int j=i+1;j<n;j++){
      if(a[i]>a[j]){
        cnt++;
      }
    }
  }
  long long p=0;
  sort(a.begin(),a.end());
  for(int i=0;i<n-1;i++){
    for(int j=i+1;j<n;j++){
      if(a[i]<a[j]){
        p++;
      }
    }
  }
  cout << (k%mod*cnt%mod+((k-1)*k/2)%mod*p%mod)%mod << endl;
}

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


void DFS(list<long int> *l,long int i,long int dp[],bool vis[])
{
    vis[i]=true;
    for(auto j : l[i])
    {
        if(!vis[j]) 
            DFS(l,j,dp,vis);
        dp[i]=max(dp[i],1+dp[j]);
    }
}


int main()
{
    long int n,m;
    cin>>n>>m;
    list<long int> *l=new list<long int> [n+1];
    
    while(m--)
    {
        long int x,y;
        cin>>x>>y;
        l[x].push_back(y);
    }
    
    bool vis[n+1]={false};
    long int dp[n+1]={},i;
    for(i=1;i<=n;i++)
        if(!vis[i])
            DFS(l,i,dp,vis);
    
    long int ans=0;
    for(i=1;i<=n;i++)
        ans=max(ans,dp[i]);
    
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 9216
#include<iostream>
#include<algorithm>
#include<vector>
using namespace std;
int main(){
  int n;
  cin>>n;
  vector<int> v(2*n);
  for(int i=0;i<2*n;i++){
    cin>>v[i];
  }
  sort(v.begin(),v.end());
  int sum=0;
  for(int i=0;i<n;i++){
    sum+=v[i*2];
  }
  cout<<sum<<endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define REP(i,n) for (int i = 0; i < (n); i++)
#define RREP(i, s, n) for (int i = s; i < (n); i++)
#define ALL(a) a.begin(), a.end()
#define RALL(a) a.rbegin(), a.rend()
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
using namespace std;
using ll = long long;
typedef pair<int, int> pint;
typedef pair<ll, ll> pll;
const ll MOD = 1000000007;
const ll INF = MOD * MOD;
const int inf = (1<<29);

int main() {

    ll n, k;
    cin >> n >> k;
    
    ll ans = 0;
    for(ll i = k; i <=n+1 ; i++) {
        ll low = i * (i-1) / 2;
        ll high = (n*2 - i+1) * i / 2;
        ll add = high - low + 1;
        ans = (ans + add) % MOD;
    }

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

Measured memory_bytes: 3632
#include <bits/stdc++.h>
#define int long long
#define mod (int)(1e9+7)
#define inf (int)(3e18+7)
#define rep(i,n) for(int i=0;i<n;i++)
#define REP(i,n) for(int i=1;i<n;i++)
#define P pair<int,int>
#define PiP pair<int,pair<int,int>>
#define all(v) v.begin(),v.end()
#define mkp make_pair
#define mkt make_tuple
#define prique(T) priority_queue<T,vector<T>,greater<T>>
#define vecunique(vec) sort(vec.begin(), vec.end());decltype(vec)::iterator result = std::unique(vec.begin(), vec.end());vec.erase(result, vec.end())
using namespace std;

bool prime(int x) {
	for (int i = 2; i * i <= x; i++) {
		if (x % i == 0)return false;
	}
	return x > 1;
}
int gcd(int x, int y) {
	if (y == 0)return x;
	return gcd(y, x % y);
}
int lcm(int x, int y) {
	return x / gcd(x, y) * y;
}
int kai(int x) {
	if (x == 0)return 1;
	return kai(x - 1) * x % mod;
}
int mod_pow(int x, int y, int mod_) {
	int res = 1;
	while (y > 0) {
		if (y & 1) {
			res = res * x % mod_;
		}
		x = x * x % mod_;
		y >>= 1;
	}
	return res;
}
int comb(int x, int y) {
	if (y > x)return 0;
	return kai(x)* mod_pow(kai(x - y), mod - 2, mod) % mod * mod_pow(kai(y), mod - 2, mod) % mod;
}
/*--------Library Zone!--------*/

int n, m;
int p[19];
bool tr[19][19];
signed main() {
	cin >> n >> m;
	rep(i, m) {
		int a; cin >> a;
		rep(j, a) {
			int b; cin >> b; b--;
			tr[i][b] = true;
		}
	}
	rep(i, m)cin >> p[i];
	int ans = 0;
	rep(i, 1 << n) {
		int cnt[19];
		fill(cnt, cnt + m, 0);
		rep(j, n) {
			bool b = (i >> j) & 1;
			rep(k, m) {
				if (b && tr[k][j])cnt[k]++;
			}
		}
		rep(j, m) {
			if (cnt[j] % 2 != p[j])goto ng;
		}
		ans++;
	ng:;
	}
	cout << ans << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
const int mod = 7 + 1e9;
int h, w, dp[1000][1000];
bool grid[1000][1000];//its impossible to optain a length of 0 so no need for a memset
int f(int i = 0 , int j = 0 )//I was wrong
{
    if( i == h || j == w || grid[i][j] )
        return 0;
    if( i == h-1 && j == w-1)
        return 1;
    int &d = dp[i][j];
    if( d != -1 ) return d;
    return d = (f(i+1,j)%mod + f(i,j+1)%mod)%mod;
}
int main()
{
    memset(dp,-1,sizeof dp);
    cin >> h >> w;
    for(int i=0;i<h;++i)
    {
        string s; cin >> s;
        for(int j=0;j<w;++j)
        {
            grid[i][j] = s[j] == '.' ? 0 : 1 ;
        }
    }
    cout << f();
    return 0;
}

Measured memory_bytes: 5248
#include<stdio.h>
int main()
{
    int i,s,h,c,d,k,j,l,m;
int card[4][13]={0};
    char g,f;
    scanf("%d",&l);
    while(l--)
    {
getchar();
        scanf("%c",&g);
        scanf("%d",&m);
        if(g=='S')
        {
            card[0][m-1]=1;

        };
        if(g=='H')
        {

            card[1][m-1]=1;

        };
        if(g=='C')
        {


            card[2][m-1]=1;

        };
        if(g=='D')
        {

            card[3][m-1]=1;

        };

    }
for(i=0;i<4;i++)
{
    if(i==0)f='S';
    if(i==1)f='H';
    if(i==2)f='C';
    if(i==3)f='D';
    for( j=0;j<13;j++)
    {
        if(card[i][j]==0)
      {

          printf("%c %d\n",f,j+1);
      }
    }

}
return 0;
}



Measured memory_bytes: 2104
#include <bits/stdc++.h>
using namespace std;
using ll = int64_t;

int main() {
  ll h, w;
  cin >> h >> w;

  if (h == 1 || w == 1) {
    cout << 1 << endl;
    return 0;
  }

  ll ans = 0;
  if (w % 2 == 0) {
    ans = w / 2 * h;
    cout << ans << endl;
    return 0;
  }

  for (ll i = 0; i < h; i++) {
    if (i % 2 == 0) {
      ans += w / 2 + 1;
    } else {
      ans += w / 2;
    }
  }
  cout << ans << endl;
}


Measured memory_bytes: 3568
#include <iostream>
#include <string>
#define MAX 100000
using namespace std;

struct Card {
  char suit;
  int value;
};

Card L[MAX / 2 + 1];
Card R[MAX / 2 + 1];

void merge(Card *C, int left, int mid, int right) {
  int i,j,k;

  int n1 = mid - left;
  int n2 = right - mid;

  for (i = 0; i < n1; i++) {
    L[i] = C[left + i];
  }

  for (i = 0; i < n2; i++) {
    R[i] = C[mid + i];
  }
  L[n1].value = 1000000001;
  R[n2].value = 1000000001;

  i = 0;
  j = 0;
  for (k = left; k < right; k++) {
    if (L[i].value <= R[j].value) {
      C[k] = L[i];
      i++;
    } else {
      C[k] = R[j];
      j++;
    }
  }
}

void mergeSort(Card *C, int left, int right) {
  if (left + 1 < right) {
    int mid = (left + right) / 2;
    mergeSort(C, left, mid);
    mergeSort(C, mid, right);
    merge(C, left, mid, right);
  }
}

int partition(Card *C, int p, int r) {
  int x = C[r].value;
  int i = p - 1;
  Card tmp;
  for (int j = p; j < r; j++) {
    if (C[j].value <= x) {
      i++;
      tmp = C[i]; C[i] = C[j]; C[j] = tmp;
    }
  }
  i++;
  tmp = C[i]; C[i] = C[r]; C[r] = tmp;
  return i;
}

void quickSort(Card *C, int p, int r) {
  if (p < r) {
    int q = partition(C, p, r);
    quickSort(C, p, q - 1);
    quickSort(C, q + 1, r);
  }
}

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

  int n, q;
  cin >> n;

  Card A[MAX];
  Card B[MAX];
  for (int i = 0; i < n; i++) {
    cin >> A[i].suit >> A[i].value;
    B[i].suit = A[i].suit;
    B[i].value = A[i].value;
  }

  quickSort(A, 0, n - 1);
  mergeSort(B, 0, n);

  bool stable = true;
  for (int i = 0; i < n; i++) {
    if (A[i].suit != B[i].suit) {
      stable = false;
      break;
    }
  }

  if (stable) {
    cout << "Stable";
  } else {
    cout << "Not stable";
  }
  cout << endl;

  for (int i = 0; i < n; i++) {
    cout << A[i].suit << " " << A[i].value << endl;
  }

  return 0;
}

Measured memory_bytes: 5352
#include <bits/stdc++.h>
using namespace std;
typedef pair<int, int> P;
#define int long long
int N, Q;
vector<vector<int> > G;
vector<int> ans;

void dfs(int start, int ago){
    for(int i = 0; i < G[start].size(); i++){
        int next = G[start][i];
        if(next == ago) continue;
        ans[next] += ans[start];
        dfs(next, start);
    }
}

signed main(){
    cin >> N >> Q;
    G.resize(N);
    for(int i = 0; i < N - 1; i++){
        int a, b; cin >>a >> b;
        G[a - 1].push_back(b - 1), G[b - 1].push_back(a - 1);
    }
    ans.resize(N, 0);
    for(int i = 0; i < Q; i++){
        int p, x; cin >> p >> x;
        ans[p - 1] += x;
    }
    dfs(0, -1);
    for(int i = 0; i < N; i++){
        cout << ans[i] << '\n';
    }
}

Measured memory_bytes: 24320
#include <bits/stdc++.h>
#define debug(...)
#include <complex.h>
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;




int main() {
    ios::sync_with_stdio (false);
    cin.tie (0);
    int R, C;
    cin >> R >> C;
    vector<string>grid (R);
    for (string & s : grid)
        cin >> s;
    vector<vi> dist (R, vi (C, -1));
    vector<pair<int, int>> que;
    for (int i = 0; i < R; i++)
        for (int j = 0; j < C; j++)
            if (grid[i][j] == '#') {
                dist[i][j] = 0;
                que.emplace_back (i, j);
            }
    const int dx[4]= {1,0,-1,0}, dy[4]= {0,1,0,-1};

    for (int tt = 0; tt < (int) que.size(); tt++) {
        for (int i = 0; i < 4; i++) {
            int   xk = dx[i] + que[tt].first, yk = dy[i] + que[tt].second;
            if (0 <= xk && xk < R && 0 <= yk && yk < C && dist[xk][yk] ==-1) {
                dist[xk][yk] = dist[que[tt].first][que[tt].second] + 1;
                que.emplace_back (xk, yk);
            }
        }
    }


    cout << dist[que.back().first][que.back().second]  << '\n';

    return 0;
}














Measured memory_bytes: 15468
a = int(input()) 
b = int(input()) 
c = int(input()) 
x = int(input())
count = 0

for v_a in range(a+1):
    for v_b in range(b+1):
        for v_c in range(c+1):
            if v_a*500 + v_b*100 + v_c*50 == x:
                count += 1
print(count)

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

int main() {
  long X;cin>>X;
  int ansa=0,ansb=0;
  for(long a=-500;a<500;a++){
    for(long b=-500;b<500;b++){
      if(a*a*a*a*a-b*b*b*b*b==X){
        ansa=a;ansb=b;
      }
    }
  }
  cout<<ansa<<" "<<ansb<<endl;
}


Measured memory_bytes: 3624
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<algorithm>
#include<cmath>
using namespace std;
const int nMax=1e5+10;
int fir[nMax],cnt,n,k;
struct Edge
{
	int s,t,n;
}g[2*nMax];
void addedge(int s,int t)
{
	g[cnt].s=s;
	g[cnt].t=t;
	g[cnt].n=fir[s];
	fir[s]=cnt++;
}
int id[nMax],boo=1,dep[nMax],_l[nMax],_r[nMax],flag[nMax];
int dfs1(int now,int fa)
{
	for(int i=fir[now];i>=0;i=g[i].n)
	{
		if(g[i].t==fa)
			continue;
		dep[g[i].t]=dep[now]+1;
		int la=dfs1(g[i].t,now);
		if(boo==0)
			return 0;
		if(la==-1)
			continue;
		int ll=_l[la]-(dep[g[i].t]-dep[now]),lr=_r[la]+(dep[g[i].t]-dep[now]);
		if(_l[now]>_r[now])
		{
			_l[now]=ll;
			_r[now]=lr;
		} else
		{
			if(abs(_l[now])%2!=abs(ll)%2||_l[now]>lr||_r[now]<ll)
			{
				boo=0;
				return 0;
			}
			_l[now]=max(_l[now],ll);
			_r[now]=min(_r[now],lr);
		}
	}
	if(_l[now]<=_r[now])
		return now;
	else 
		return -1;
}
void dfs2(int now,int fa,int l,int r)
{
	if(flag[now]==0)
	{
		if(_l[now]>_r[now])
			id[now]=l;
		else
			if(l>=_l[now]&&l<=_r[now])
				id[now]=l;
			else
				id[now]=r;
	}
	for(int i=fir[now];i>=0;i=g[i].n)
	{
		if(g[i].t==fa)
			continue;
		dfs2(g[i].t,now,id[now]-1,id[now]+1);
	}
}
int main()
{
	memset(fir,-1,sizeof(fir));
	scanf("%d",&n);
	for(int i=1;i<n;i++)
	{
		int a,b;
		scanf("%d%d",&a,&b);
		addedge(a,b);
		addedge(b,a);
	}
	memset(_r,-1,sizeof(_r));
	scanf("%d",&k);
	for(int i=1;i<=k;i++)
	{
		int a,b;
		scanf("%d%d",&a,&b);
		flag[a]=1;
		id[a]=b;
		_l[a]=_r[a]=b;
	}
	dfs1(1,-1);
	if(boo==0)
	{
		printf("No\n");
		return 0;
	}
	printf("Yes\n");
	dfs2(1,-1,_l[1],_r[1]);
	for(int i=1;i<=n;i++)
		printf("%d\n",id[i]);
	return 0;
}

Measured memory_bytes: 10240
#include <bits/stdc++.h>
#define _GLIBCXX_DEBUG
#define rep(i,n) for(int i=0;i<n;i++)
#define inf 1e9+7
using namespace std;
typedef long long ll;
const double pi=acos(-1);

ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
ll lcm(ll a,ll b){return a/gcd(a,b)*b;}

int main(){
    int n;
    cin >> n;
    ll ans=1;
    ll mod=inf;
    for(int i=0;i<n;i++){
        ans*=10;
        ans%=mod;
    }
    ll mi=1;
    for(int i=0;i<n;i++){
        mi*=9;
        mi%=mod;
    }
    mi*=2;
    mi%=mod;
    ll pu=1;
    for(int i=0;i<n;i++){
        pu*=8;
        pu%=mod;
    }
    ans=ans+mod-mi+pu;
    ans%=mod;
    cout << ans << endl;
}

Measured memory_bytes: 3632
/*
ID: anonymo14
TASK: wormhole
LANG: C++                 
*/
#include<bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef vector<pair<int,int>> vpii;

#define F first
#define S second
#define PU push
#define PUF push_front
#define PUB push_back
#define PO pop
#define POF pop_front
#define POB pop_back

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

#define MOD 1000000007

void solve(int test_case) {//233
	double a,b;
	cin>>a>>b;
	cout<<ceil((a-1)/(b-1));
}

int main() {
	
	////// FILE BASED IO////
	//freopen("wormhole.in", "r", stdin);
	//freopen("wormhole.out", "w", stdout);
	///////////////
	
	ios::sync_with_stdio(0);
	cin.tie(0);
	int t=1;
	//cin>>t;
	REP(i,1,t) {
		solve(i);
	}
	return 0;
}	


Measured memory_bytes: 3804
#https://atcoder.jp/contests/panasonic2020/tasks/panasonic2020_a
# -*- coding: utf-8 -*-
N = [1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51]
K = int(input())
print(N[K-1])

Measured memory_bytes: 38384
#include <iostream>
#include <vector>
#include <algorithm>
#include <iterator>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <string>
#include <cmath>
using namespace std;
#define MOD 1000000007
#define INF 1<<30
#define LINF (ll)1<<62
#define rep(i,n) for(ll i=0; i<(n); i++)
#define REP(i,a,b) for(ll i=(a); i<(b); i++)
#define all(x) (x).begin(),(x).end()
using namespace std;
typedef long long ll;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef pair<ll, ll> P;
typedef vector<pair<ll, ll>> vpl;



int main(){
    string s; cin >> s;
    if(s[0] == s[s.size()-1]){
        if(s.size() % 2 == 0){
            cout << "First" << endl;
        }else{
            cout << "Second" << endl;
        }
    }else{
        if(s.size() % 2 == 0){
            cout << "Second" << endl;
        }else{
            cout << "First" << endl;
        }
    }
}

Measured memory_bytes: 512
N, M = map(int, input().split())

alist = []
blist = []

for i in range(M):
    a,b = map(int, input().split())
    alist.append(a)
    blist.append(b)

class UnionFind(object):
    """docstring for UnionFind."""

    def __init__(self, num_nodes):
        super(UnionFind, self).__init__()
        self.root = [i for i in range(num_nodes+1)]
        self.rank = [0]*(num_nodes+1)
        self.size = [1]*(num_nodes+1)

    def find(self, x):
        if x != self.root[x]:
            self.root[x] = self.find(self.root[x])
        return self.root[x]

    def union(self, x, y):
        xroot, yroot = self.find(x), self.find(y)
        if xroot == yroot:
            return
        elif self.rank[xroot] < self.rank[yroot]:
            self.root[xroot] = yroot
            self.size[yroot] += self.size[xroot]
        else:
            self.root[yroot] = xroot
            self.size[xroot] += self.size[yroot]
            if self.rank[xroot] == self.rank[yroot]:
                self.rank[xroot] += 1

anslist = []
ans = N*(N-1)/2

unionfind = UnionFind(N)
alist = alist[::-1]
blist = blist[::-1]

for i in range(M):
    anslist.append(ans)
    a = alist[i]
    b = blist[i]
    aroot, broot = unionfind.find(a), unionfind.find(b)
    # print(aroot, broot)
    if aroot == broot:
        continue
    p, q = unionfind.size[aroot], unionfind.size[broot]
    unionfind.union(aroot, broot)
    ans -= p*q

for i in range(M):
    print(int(anslist[M-i-1]))


Measured memory_bytes: 20780
#include <bits/stdc++.h>
#define REP(i, n) for (int (i) = 0; (i) < (int)(n); i++) 
#define FOR(i, a, b) for(int (i) = a; (i) < (int)b; i++)
#define RREP(i, n) for(int (i)=((int)(n)-1); (i)>=0; i--)
#define RFOR(i, a, b) for(int (i) =((int)(b)-1); (i)>=(int)a; i--)
#define ALL(v) (v).begin(),(v).end()
#define MOD 1000000007
#define NIL -1
#define FI first
#define SE second
#define MP make_pair
#define PB push_back
#define SZ(x)  (int)x.size()
#define SP(x)  setprecision((int)x)


using namespace std ;
typedef long long ll;
typedef vector<int> vint;
typedef vector<vint> vvint;
typedef vector<string> vstr;
typedef pair<int, int> pii;
const int INF = 1e9;
const ll LINF = 1e18;
const double EPS = 1e-9;
ll gcd(ll a, ll b) {return b ? gcd(b, a % b) : a;} //最大公約数
ll lcm(ll a, ll b) {return a / gcd(a, b) * b;} //最小公倍数

//-------------------------------------------------
// 
void yes(){
  cout <<"Yes"<<endl ;
}
void no(){
  cout <<"No"<<endl ;
}


//-------------------------------------------------
// メモ




//-------------------------------------------------


int main()
{
  cin.tie(0);
  ios::sync_with_stdio(false);
  
  int n, m ;
  cin >> n >> m ;
  bool fl = true ;
  
  if(m==0){
    if(n==1){
      cout << 0 <<endl ;
      return 0 ;
    }
    else if(n==2){
      cout << 10 <<endl ;
      return 0 ;
    }
    else{
      cout << 100 <<endl ;
      return 0 ;
    }
  }
  
  vector<int> vec(n,0) ;
  vec.at(0) = 1  ;
  vector<int> che(n,0) ;
  
  REP(i,m){
    int a, b ;
    cin >> a >> b ;
    che.at(a-1)++ ;
    
    if(che.at(a-1)==1){
      vec.at(a-1) = b ;
    }
    
    else{
      if(vec.at(a-1)!=b){
        fl = false ;
      }
    }
  }
  
  if(n>=2 && vec.at(0)==0){
    fl = false ;
  }
  
  if(fl){
    REP(i,n){
      cout << vec.at(i) ;
    }
    cout <<endl ;
  }
  
  else{
    cout << -1 <<endl ;
  }
      
    
    
 
  
  return 0 ;
}



Measured memory_bytes: 256
#include <iostream>
#define MOD 1000000007

using namespace std;

typedef long long ll;

int main() {
    ios::sync_with_stdio(false);
    ll n, k, ans = 0;
    cin >> n >> k;
    for (ll i = k; i <= n + 1; ++i) (ans += i * (n + 1 - i) + 1) %= MOD;
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 3608
import collections

n=int(input())

if n==1:
    a,b=(map(int, input().split()))
    print(1)
else:

    arr=[]
    for i in range(n):
        a,b=(map(int, input().split()))
        arr.append([a,b])
    arr=sorted(arr, key=lambda x: x[1], reverse=True)
    arr=sorted(arr, key=lambda x: x[0])
    
    tmparr=[]
    for num in range(len(arr)-1):
        #print(num)
        #tmparr=[]
        #for nn,i in enumerate(arr):
        for nn,i in enumerate(arr[num+1:]):
            #if nn==num:
            #    continue
            #g=gcd(arr[num][0]-i[0],arr[num][1]-i[1])
            tmparr.append(((arr[num][0]-i[0]),(arr[num][1]-i[1])))
            #print(tmparr)
        #print(tmparr)
    #print(set(tmparr))
    c = collections.Counter(tmparr)
    print(n-c.most_common()[0][1])

Measured memory_bytes: 3572
#include<bits/stdc++.h>
using namespace         std;
#define                 int long long
#define                 pb push_back
#define                 mp make_pair
#define st(arr,a)       memset(arr,a,sizeof arr)
#define                 nl cout<<endl
#define                 real signed
#define                 endl '\n'              
#define bitcount(x)     __builtin_popcountll(x)
const int MOD = 1000000007ll;
#define forn(i,a,b)     for(int i=a;i<=b;i++)
#define rfor(i,a,b)     for(int i=a;i>=b;i--)
#define all(x)          x.begin() , x.end()
#define pi pair<int,int>
#define X first
#define Y second
#define N 314159
#define  vi vector<int>
#define  v  vector

int n,arr[N];
vi blue;
int L[N],R[N];
signed main() 
{
    ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); 
    cin>>n;
    forn(i,1,n)cin>>arr[i];
    blue.pb(0);
    arr[0] = arr[n+1] = 0;
    forn(i,1,n)
    {
        while(arr[blue.back()]>arr[i])blue.pop_back();
        L[i] = blue.back();
        blue.pb(i);
    }
    blue.clear();
    blue.pb(n+1);
    rfor(i,n,1)
    {
        while(arr[blue.back()]>arr[i])blue.pop_back();
        R[i] = blue.back();
        blue.pb(i);
    }
    int ans = 0;
    forn(i,1,n)
    {
        ans+=(i-L[i])*(R[i]-i)*arr[i];
    }
    cout<<ans;
        
    



    return 0;

}

//       g++ -g c.cpp ; ./a.exe

Measured memory_bytes: 7924
#include <vector>
#include <iostream>
#include <cmath>
#include <map>
#include <unordered_map>
#include <algorithm>
#include <fstream>
#include <unistd.h>
#include <string>
#include <numeric>
#include <queue>
#include <deque>
#include <sstream>
#include <iomanip>
#include <set>
#include <stack>
#include <cassert>
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<vvl> vvvl;
typedef vector<vi> vvi;
typedef vector<vvi> vvvi;
typedef vector<bool> vb;
typedef vector<vector<bool>> vvb;
typedef vector<string> vs;
typedef vector<vector<string>> vvs;
typedef vector<char> vc;
typedef vector<vector<char>> vvc;
typedef vector<double> vd;
typedef vector<vd> vvd;
typedef pair<int, int> P;
typedef pair<ll, ll> PL;
typedef vector<P> vp;
typedef vector<PL> vpl;
typedef vector<vector<P>> vvp;
typedef vector<vector<PL>> vvpl;
const int INF = 1001001001;
const ll LINF = 1e10;
const double pi = 3.1415926535897932;
const string endstr = "\n";
#define FOR(i, a, b) for(ll i = (a); i < b; i++)
#define REP(i, n) for(ll i = 0; i < n; i++)
#define FORMAP(it, m) for(auto it = m.begin(); it != m.end(); it++)
#define ff first
#define ss second
#define pb push_back

template <typename T>
T gcd(T a, T b) {
    return (a == 0) ? b : gcd(b%a, a);
}
template <typename T>
T lcm(T a, T b) {
    return a / gcd(a, b) * b;
}

bool p_comp_fs(const PL p1, const PL p2){ return p1.first < p2.first;};
bool p_comp_fg(const PL p1, const PL p2){ return p1.first > p2.first;};
bool p_comp_ss(const PL p1, const PL p2){ return p1.second < p2.second;};
bool p_comp_sg(const PL p1, const PL p2){ return p1.second > p2.second;};
template <typename T>
vector<T> uniquen(vector<T> vec){
    vec.erase(unique(vec.begin(), vec.end()), vec.end());
    return vec;
}


int main(){
    ll N, M, R; cin >> N >> M >> R;
    vl rs(R, 0);
    REP(i, R) {
        ll r; cin >> r; rs[i] = r-1;
    };
    
    vvl d(N, vl(N, LINF));
    REP(i, N) d[i][i] = 0;
    REP(i,M){
        ll a, b, c; cin >> a >> b >> c;
        d[a-1][b-1] = c;
        d[b-1][a-1] = c;
    }
    
    REP(k, N) REP(i, N) REP(j, N){
        d[i][j] = min(d[i][j], d[i][k] + d[k][j]);
    }
    
    sort(rs.begin(), rs.end());
    ll ans = LINF;
    do{
        ll tmp = 0;
        REP(i, rs.size()-1){
            tmp += d[rs[i]][rs[i+1]];
        }
        ans = min(ans, tmp);
    }while(next_permutation(rs.begin(), rs.end()));
    
    cout << ans << endl;
    return 0;
    return 0;
}


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

int main(){
    int n,k;
    cin>>n>>k;
    set<int> s;
    for(int i=0;i<k;i++){
        int d;
        cin>>d;
        for(int i=0;i<d;i++){
            int tmp;
            cin>>tmp;
            s.insert(tmp);
        }
    }
    cout<<n-s.size()<<endl;
}

Measured memory_bytes: 3632
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <utility>
#include <map>

#include <stdio.h>

#define rep(i, n) for (int i = 0; i < (n); i++)
#define irep(i, k, n) for (int i = (k); i < (n); i++)
#define rrep(i, k, n) for (int i = (k); i >= (n); i++)
#define pb push_back
#define eb emplace_back
#define fi first
#define se second
#define vec vector

typedef long long ll;

template<class T> bool chmin(T& a, T b) {
  if (a > b) {
    a = b;
    return true;
  }
  return false;
}

template<class T> bool chmax(T& a, T b) {
  if (a < b) {
    a = b;
    return true;
  }
  return false;
}

template<class T> T gcd(T m, T n) {
  if (n == 0) return m;
  return gcd(n, m % n);
}

template<class T> T lcm(T m, T n) {
  return m * n / gcd(m, n);
}

const ll inf = 1LL << 60;
const int mod = 1e9 + 7;

using namespace std;

/* Input variables. */
int n;
vec<string> s;
vec<int> t;
string x;

/* Solve! */
void solve() {
  bool f = false;
  int res = 0;
  rep(i, n) {
    if (f) {
      res += t[i];
    }
    if (x == s[i]) {
      f = true;
    }
  }
  cout << res << endl;
}

int main() {
  /* Input handling. */
  cin >> n;
  s = vec<string>(n);
  t = vec<int>(n);
  rep(i, n) {
    cin >> s[i];
    cin >> t[i];
  }
  cin >> x;

  solve();
  return 0;
}

Measured memory_bytes: 888
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <bitset>
#include <map>
#include <tuple>
#include <unordered_map>
#include <list>
#include <numeric>
#include <utility>
#include <iterator>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cstring>
#include <climits>
#include <ctime>
#include <cassert>
#include <random>

#define INF 1000000000
#define LINF 9000000000000000000
#define mod  1000000007

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

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef vector<long long>vll;
typedef pair<int,int> pi;

int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};
int ddx[8]={-1,-1,0,1,1,1,0,-1};
int ddy[8]={0,1,1,1,0,-1,-1,-1};
bool debug=false;

/*---------------------------------------------------*/

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


Measured memory_bytes: 256
import sys

sys.setrecursionlimit(10 ** 6)
INF = float("inf")
MOD = 10 ** 9 + 7


def input():
    return sys.stdin.readline().strip()


def main():
    N, D = map(int, input().split())
    ans = 0
    for _ in range(N):
        x, y = map(int, input().split())
        if x*x + y*y <= D * D:
            ans += 1
    print(ans)

if __name__ == "__main__":
    main()


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

int main() {
	string S;
	int count0 = 0;
	int count1 = 0;
	cin >> S;

	for (int i = 0; i < S.size(); i++) {
		if (S[i] == '0') {
			count0++;
		} else {
			count1++;
		}
	}

	cout << min(count0,count1)*2 << endl;
}

Measured memory_bytes: 512
#include<iostream>
#include<algorithm>
#include<cstdio>
#include<cmath>
#include<cctype>
#include<math.h>
#include<string>
#include<string.h>
#include<stack>
#include<queue>
#include<vector>
#include<utility>
#include<set>
#include<map>
#include<stdlib.h>
#include<iomanip>

using namespace std;

#define ll long long
#define ld long double
#define EPS 0.0000000001
#define INF 1e9
#define LINF (ll)INF*INF
#define MOD 1000000007
#define rep(i,n) for(int i=0;i<(n);i++)
#define loop(i,a,n) for(int i=a;i<(n);i++)
#define all(in) in.begin(),in.end()
#define shosu(x) fixed<<setprecision(x)

#define int ll //!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!

typedef vector<int> vi;
typedef vector<string> vs;
typedef pair<int,int> pii;
typedef vector<pii> vp;

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


signed main(void) {
    int n;
    cin >> n;
    int a[25][25];
    rep(i,n)rep(j,n)cin >> a[i][j];
    vector<vi> dp(n+1, vi(1<<n));
    dp[0][0] = 1;
    rep(i,n)rep(bit,1<<n)if(dp[i][bit]){
        //cout << i << " " << bit << " " << dp[i][bit] << endl;
        rep(j,n)if(a[i][j]){
            if(bit & 1<<j)continue;
            int ne = bit | 1<<j;
            (dp[i+1][ne] += dp[i][bit]) %= MOD;
        }
    }
    int ans = 0;
    rep(i,1<<n)ans += dp[n][i], ans %= MOD;
    cout << ans << endl;
}


Measured memory_bytes: 377216
#include <cstdio>
#include <cstring>
#include <cmath>
#include <utility>
#include <iostream>
#include <functional>
#include <bitset>
#include <algorithm>
#include <vector>
#include <forward_list>
#include <set>
#include <map>
#include <queue>
#include <deque>
#include <stack>
#include <tuple>
#include <numeric>
#define rep(i, s, g) for ((i) = (s); (i) < (g); ++(i))
using namespace std;
using ll = long long;
using P = pair<ll, ll>;
const ll MOD = 1e9 + 7;
const ll INF = (1ll << 60);

int main(void)
{
    double a, b;
    double h, m;
    double at, bt, t;
    double ans;

    cin >> a >> b >> h >> m;

    at = M_PI * h / 6 + M_PI * m / 360;
    bt = M_PI * m / 30;

    t = min(abs(at - bt), 2 * M_PI - abs(at - bt));

    ans = a * a + b * b - 2 * a * b * cos(t);

    printf("%.10f\n", sqrt(ans));
}


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

int main() {
  int N;
  cin >> N;
  
  int sum_all = 0;
  vector<int> W(N);
  rep(i,N) {
    cin >> W.at(i);
    sum_all += W.at(i);
  }
  
  int ans = 10000;
  rep(T,N) {
    int S1 = 0, S2;
    repm(i,0,T+1) S1 += W.at(i);
    S2 = sum_all - S1;
    ans = min(ans, abs(S1 - S2));
  }
  
  cout << ans << endl;
}

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

#define int long long
#define rep(i, n) for (int i = 0; i < (int) (n); i++)
using namespace std;

vector<int> A;
vector<vector<int>> g;

bool dfs(int p, int x, int& r)
{
  vector<int> l;
  int t;
  r = A[x];
  int sum = 0;
  for (auto a : g[x]) {
    if (a == p) continue;
    if (!dfs(x, a, t)) return false;
    l.push_back(t);
    sum += t;
  }
  if (l.size() == 0) return true;
  sort(l.begin(), l.end());
  int mi = sum - min(sum / 2, (sum - l.back()));
  r = 2 * A[x] - sum;
  return mi <= A[x] && A[x] <= sum && r <= A[x];
}

signed main()
{
  int N;
  cin >> N;
  A.resize(N);
  rep(i, N) cin >> A[i];
  g.resize(N, vector<int>());
  rep(i, N-1) {
    int a, b;
    cin >> a >> b;
    a--;b--;
    g[a].push_back(b);
    g[b].push_back(a);
  }
  int res;
  if (dfs(-1, 0, res) && dfs(-1, N-1, res)) {
    cout << "YES" << endl;
  }
  else cout << "NO" << endl;
}


Measured memory_bytes: 17920
#include<stdio.h>
int main(void)
{
	long int x, a, b;

	scanf("%ld %ld %ld", &x, &a, &b);
	if (b<=a)
	{
		printf("delicious\n");
	}
	 else if (x + a >= b)
		{
			printf("safe\n");
		}
	else if (x + 1 + a <= b)
	{
		printf("dangerous\n");
	}

	
	return 0;
}

Measured memory_bytes: 128
N = gets.chomp.to_i
str_a = gets.chomp.split.map(&:to_i)
str_b = gets.chomp.split.map(&:to_i)
str = (1..N).map do |num|
  num
end
all = []
str.permutation(N) do |pattern|
  all << pattern
end
all.sort!
puts ((all.find_index(str_a) + 1) - (all.find_index(str_b) + 1)).abs


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

using namespace std;

#define ok1 printf("ok1\n");
#define ok2 printf("ok2\n");
#define M 1000000000000000000LL
#define rep(i,n) for(int i=0;i<n;i++)
#define REP(i,s,n) for(int i=(s);i<(n);i++)
#define repr(i,n) for(int i=n-1;i>=0;i--)
#define REPR(i,s,n) for(int i=(s);i>=(n);i--)
#define all(a) (a).begin(),(a).end()
#define rall(a) (a).rbegin(),(a).rend()
#define pb push_back
#define pf push_front
#define MIN(a,b) a=min((a),(b))
#define MAX(a,b) a=max((a),(b))
#define SIZE(v) (int)v.size()
#define Eunique(v) v.erace(unique(all(v)),v.end())
#define pvec(v)　rep(i,v.size()){cout << v[i] << " ";}
#define INF 0x3f3f3f3f
#define mset(m,v) memset(m,v,sezeof(m))
#define mod (ll)(1e9 +7);

const double pi = acos(-1.0);

typedef vector<int> vi;
typedef string ss;
typedef vector<string> vs;
typedef long long ll;
typedef vector<ll> vll;
typedef vector<vi> vvi;
typedef vector<vll> vvll;
typedef deque<ll> dll;
typedef pair<ll,ll> P;
ll dx[4] = {1,0,-1,0},dy[4] = {0,1,0,-1};

ll gcd(ll x,ll y)
{
    ll r;
    while((r = x % y) != 0)
    {
        x = y;
        y = r;
    }
    return y;
}

ll lcm(ll a,ll b){
    ll g = gcd(a,b);
    return a / g * b; // Be careful not to overflow
}

ll digsum(ll n){
    ll sum = 0;
    while(n > 0){
        sum += n % 10;
        n /= 10;
    }

    return sum;
}

int main()
{
    ll a, b,ans = 0,out = 1;
    cin >> a >> b;

    while(out < b){
        out += a - 1;
        ans++;
    }

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

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

#define gcu getchar_unlocked
#define pcu putchar_unlocked
#define _il inline
#define _in _il int in
#define _sc _il bool scan
template <typename T>
T in(int c){T n=0;bool m=false;if(c=='-')m=true,c=gcu();
	do{n=10*n+(c-'0'),c=gcu();}while(c>='0');return m?-n:n;} //&&c<='9'
_in() {return in<int>(gcu());}
template <typename T>
T scan(T &n){int c=gcu();return c==EOF?false:(n=in<T>(c),true);}
_sc(char &c){c=gcu();gcu();return c!=EOF;}
//_sc(string &s){int c;s="";
//	for(;;){c=gcu();if(c=='\n'||c==' ')return true;else if(c==EOF)return false;s+=c;}}
template <typename H,typename... T> _sc(H &h, T&&... t){return scan(h)&&scan(t...);}
#define _vo _il void out
#define _vl _il void outl
template <typename T>
_vo(T n){static char buf[20];char *p=buf;
	if(n<0)pcu('-'),n*=-1;if(!n)*p++='0';else while(n)*p++=n%10+'0',n/=10;
	while (p!=buf)pcu(*--p);}
_vo(const char *s){while(*s)pcu(*s++);}
_vo(char c){pcu(c);}
//_vo(string &s){for(char c:s)pcu(c);}
//_vo(string s){for(char c:s)pcu(c);}
template <typename H,typename... T> _vo(H&& h, T&&... t){out(h);out(move(t)...);}
template <typename T> _vo(vector<T> &v){for(T &x:v)out(&x == &v[0]?"":" "),out(x);out('\n');}
_vl(){out('\n');}
template <typename... T> _vl(T&&... t){out(move(t)...);outl();}

int main() {
	vector<int> v(in());
	for (int &x: v)
		x = in();
	if(prev_permutation(v.begin(), v.end()))
		out(v);
	next_permutation(v.begin(), v.end());
	out(v);
	if(next_permutation(v.begin(), v.end()))
		out(v);
}


Measured memory_bytes: 2636
import java.util.Scanner;

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

        if (a.length() < b.length()) {
            System.out.println("LESS");
        } else if (a.length() > b.length()) {
            System.out.println("GREATER");
        } else {
            for (int i = 0; i < a.length(); ++i) {
                if (a.charAt(i) < b.charAt(i)) {
                    System.out.println("LESS");
                    return;
                } else if (a.charAt(i) > b.charAt(i)) {
                    System.out.println("GREATER");
                    return;
                }
            }
            System.out.println("EQUAL");
        }
    }
}

Measured memory_bytes: 21844
package main

import (
	"fmt"
	"strconv"
)

func main() {
	// Code for B - Multiple of 9
	var N string
	fmt.Scanf("%s", &N)

	var ans int
	var temp int
	for i := 0; i < len(N); i++ {
		temp, _ = strconv.Atoi(string(N[i]))
		ans += temp
		ans = ans % 9
	}

	if ans%9 == 0 {
		fmt.Println("Yes")
	} else {
		fmt.Println("No")
	}
}


Measured memory_bytes: 3276
import java.util.*;
public class Main{
	public static void main(String[] args){
    
      Scanner sc = new Scanner(System.in);
      
      String a = sc.next();
      String n = sc.next();
      
      if (n.startsWith(a) && n.length() == a.length() + 1) {
      	System.out.println("Yes");
      } else {
      	System.out.println("No");      
      }
    }
}

Measured memory_bytes: 35644