akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
using namespace std;

typedef tree<int,null_type,less<int>,rb_tree_tag,
tree_order_statistics_node_update> indexed_set;

#define ll long long int
#define vr vector
#define pb push_back
#define pf push_front
#define mod 1000000007
#define all(v) v.begin(),v.end()
#define watch(x) cout << (#x) << " is " << (x) << "\n"
#define loop(i,n) for(i=0;i<n;i++)
#define inp !cin.eof()
#define sec itr->second
#define fir itr->first

ll powe(ll x,ll p)
{
   ll re=1;
  while(p)
  {
    if(p&1)
    re=(re*x)%mod;
    p/=2;
    x=(x*x)%mod;
  }
return re;
}

int main()
{
 ios_base::sync_with_stdio(false);
    cin.tie(NULL);

    ll n,i,ans=0,x;
    vr<ll> v;
    cin>>n;
    loop(i,n)
    {
        cin>>x;
        v.pb(x);
    }
    for(i=0;i<n-1;i++)
    {
        if(v[i]>v[i+1])
        {
            ans+=v[i]-v[i+1];
            v[i+1]=v[i];
        }
    }

    cout<<ans;




    return 0;
}



Measured memory_bytes: 5288
import numpy as np

n, m = input().split()
n = int(n)
m = int(m)

l = np.zeros(m, dtype=np.int)
r = np.zeros(m, dtype=np.int)

for i in range(m):
    li, ri = input().split()
    l[i] = li
    r[i] = ri

# 1枚だけで全てのゲートを通過できるのは max(l) から min(r) まで
x = max(r.min() - l.max() + 1, 0)

print(x)

Measured memory_bytes: 14032
/*
g++ -std=c++14 -o2 -Wall ABC.cpp -o .\out\ABC.out
.\out\ABC.out
*/

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

typedef long long ll;

int al[100005];
int ar[100005];

int main(){
//  freopen("./input/input.txt", "r", stdin);
  ios::sync_with_stdio(0);
  cin.tie(0);
  ll r, d, x;
  cin >> r >> d >> x;
  ll ans = x;
  for (int i = 1; i <= 10; ++i) {
    ans = r * ans - d;
    cout << ans << "\n";
  }
}


Measured memory_bytes: 256
#include <iostream>
#include<bits/stdc++.h>
#define ll long long 
using namespace std;
ll inf=(1LL<<60);
ll dp[(1<<16)];
ll sum[(1<<16)];
ll  calculate(vector<vector<int>>& score,int mask)
{
    ll ans=0;
    for(int i=0;i<17;i++)
    {
        for(int j=i+1;j<17;j++)
        {
            if(((mask &(1<<i))!=0) &&((mask & (1<<j))!=0))
            {
                ans+=score[i][j];
            }
        }
    }
    return ans;
}
void prepareSum(vector<vector<int>>& score ,int n)
{   
    for(int subset=1;subset<(1<<n);subset++)
   {
    dp[subset]=inf;
    }
    
    for(int subset=1;subset<(1<<n);subset++)
   {
    sum[subset]=calculate(score,subset);
   }
}
ll solve(vector<vector<int>>& score,int mask)
{  ll ans=0;
    if(mask==0)
    {
        return 0;
    }
    if(dp[mask]!=inf)
    {
        return dp[mask];
    }
    for(ll subset=mask;subset!=0;subset=(subset-1)&mask)
    {
        ans=max(ans,sum[subset]+solve(score,mask^subset));
    }
    return dp[mask]=ans;
}
int main() {
    int n;
    cin>>n;
    vector<vector<int>> score(n,vector<int>(n));
    for(int i=0;i<n;i++)
    {
        for(int j=0;j<n;j++)
        {
            cin>>score[i][j];
        }
    }
    prepareSum(score,n);
    cout<<solve(score,(1<<n)-1);
}


Measured memory_bytes: 4632
#include<bits/stdc++.h>
using namespace std;
vector<list<long long>>v(200010),v2(200010);
long long ind[200010],ar[200010],dist[200010],idx=0;
queue<long long>q;
int main()
{
	long long n,m,x,y,i;
	scanf("%lld%lld",&n,&m);
	for(i=1;i<=m;i++)
	{
		scanf("%lld%lld",&x,&y);
		v[x].push_back(y);
		v2[y].push_back(x);
		ind[y]++;
	}
	for(i=1;i<=n;i++)
	{
		if(ind[i] == 0)
			q.push(i);
	}
	while(!q.empty())
	{
		long long c=q.front();
		q.pop();
		ar[idx++]=c;
		for(auto it=v[c].begin();it!=v[c].end();it++)
		{
			ind[*it]--;
			if(ind[*it] == 0)
				q.push(*it);
		}
	}
	for(i=0;i<idx;i++)
		dist[ar[i]]=0;
	for(i=0;i<idx;i++)
	{
		long long node=ar[i];
		for(auto it=v2[node].begin();it!=v2[node].end();it++)
			dist[node]=max(dist[*it]+1,dist[node]);
	}
	printf("%lld\n",dist[ar[idx-1]]);
}


Measured memory_bytes: 16384
#include <bits/stdc++.h>
//#include <ext/pb_ds/tree_policy.hpp>
//#include <ext/pb_ds/assoc_container.hpp>
using namespace std;
//using namespace __gnu_pbds;
//template<typename key, typename val>
//using ordered_tree =
//  tree<key, val, less<>, rb_tree_tag, tree_order_statistics_node_update>;
typedef long long int64;
typedef complex<double> comp;
const double pi = 3.14159265358979323846;
const int inf = (int)1e+9 + 2;
const int64 inf64 = (int64)1e+18 + 2;
const double dinf = 1e+20;
const int mod = /*1'000'000'007;*/998244353;
const int base = 2187;
const double eps = 1e-8;
const int N = 100'000;
const int LOGN = 18;

int n, m, k;

void solve(int test)
{
  int d;
  cin >> n >> d;
  d = d + d + 1;
  cout << (n + d - 1) / d << '\n';
}

void precalc()
{
}

int main()
{
  ios::sync_with_stdio(0);
  cin.tie(0), cout.tie(0);
  precalc();
  int test = 1;
  //cin >> test;
  //auto start = chrono::high_resolution_clock::now();
  for (int i = 1; i <= test; ++i)
    solve(i);
  //cerr << chrono::duration_cast<chrono::milliseconds>(chrono::high_resolution_clock::now() - start).count() << '\n';
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int n,k;
long long w[109],s[109];
long long dp[109][100009];
long long bt(int i,int crnt){
	if(crnt>k) return-10000000000000;
	if(i==n) return 0;
	long long ans=0;
	if(dp[i][crnt]!=-1) return dp[i][crnt];
	ans=max(bt(i+1,crnt),bt(i+1,crnt+w[i])+s[i]);
	dp[i][crnt]=ans;
	return ans;
}
int main(){
	cin>>n>>k;
	memset(dp,-1,sizeof(dp));
	for(int i=0;i<n;i++){
		cin>>w[i]>>s[i];
	}
	cout<<bt(0,0)<<endl;
}



Measured memory_bytes: 85376
#include <bits/stdc++.h>
using namespace std;
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
typedef long long ll;
// Welcome to my source code!

int main() {
    int a, b;
    cin >> a >> b;
    int x1, x2, y1, y2, cnt = 0;
    for (int i = a; i <= b; i++) {
        x1 = i % 10;
        x2 = i / 10000 % 10;
        y1 = i / 10 % 10;
        y2 = i / 1000 % 10;
        if (x1 == x2 && y1 == y2) cnt++;
    }
    cout << cnt << endl;
}

Measured memory_bytes: 256
from itertools import permutations

n = int(input())
p = list(map(int, input().split()))
q = list(map(int, input().split()))

cnt_p = 1
for case in permutations(range(1, n+1)):
    if p == list(case):
        p_n = cnt_p
    cnt_p += 1

cnt_q = 1
for case in permutations(range(1, n+1)):
    if q == list(case):
        q_n = cnt_q
    cnt_q += 1
print(abs(p_n - q_n))


Measured memory_bytes: 41456
#include <iostream>
using namespace std;
int main () {
    int n;
    cin >> n;
    int res = n;
    for (int i = 0; i <= n; ++i) {
        int c = 0;
        int t = i;
        while (t > 0) {
            c += t % 6;
            t /= 6;
        }
        t = n - i;
        while (t > 0) {
            c += t % 9;
            t /= 9;
        }
        if (res > c) {
            res = c;
        }
    }
    printf ("%d\n" , res);
    return 0;
}


Measured memory_bytes: 256
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		// TODO Auto-generated method stub
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		color = new int[n];
		costFromRoot = new long[n];
		
		@SuppressWarnings("unchecked")
		ArrayList<Edge>[] edges = new ArrayList[n];
		
		for(int i = 0; i < n; i++) {
			edges[i] = new ArrayList<Edge>();
		}
		
		for(int i = 0; i < n - 1; i++) {
			int u = sc.nextInt() - 1;
			int v = sc.nextInt() - 1;
			int w = sc.nextInt();
			
			edges[u].add(new Edge(v, w));
			edges[v].add(new Edge(u, w));
		}
		
		ArrayList<Integer> queue = new ArrayList<Integer>();
		
		Arrays.fill(color, NONE);
		color[0] = BLACK;
		queue.add(0);
		
		while(!queue.isEmpty()) {
			int v = queue.remove(0);
			
			for(int i = 0; i < edges[v].size(); i++) {
				Edge e = edges[v].get(i);
//				System.out.println("from "+ v +" to "+e.to);
				
				if(color[e.to] == NONE) {
					costFromRoot[e.to] = e.cost + costFromRoot[v];

					if(costFromRoot[e.to] % 2 == 0) {
//						System.out.println("should be same color");
						color[e.to] = BLACK;
					}
//					else if(color[i] == BLACK){
////						System.out.println("shoud be white");
//						color[e.to] = WHITE;
//					}
					else {
//						System.out.println("should be black");
						color[e.to] = WHITE; 
					}
					
					queue.add(e.to);
				}
			}
		}
		
		for(int i = 0; i < n; i++) {
			System.out.println(color[i]);
		}
	}
	
	static int color[];
	static final int NONE = -1;
	static final int BLACK = 1;
	static final int WHITE = 0;
	static long costFromRoot[];

}

class Edge {
	int to;
	int cost;
	
	Edge(int to, int cost){
		this.to = to;
		this.cost = cost;
	}
}

Measured memory_bytes: 109960
#include <bits/stdc++.h>
#define ALL(v) v.begin(), v.end()
#define MOD 1000000007
#define MAX 510000
#define Rep(i, n) for(ll i = 0; i < (ll)(n); i++)
#define rep(i, n) for(ll i = 1; i <= (ll)(n); i++)

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

//cout << fixed << setprecision(10);//
//最小公倍数//
ll gcd(ll x, ll y) {
	if (x == 0) return y;
	return gcd(y%x, x);
}
ll lcm(ll x, ll y) { return x * y / gcd(x, y); }

//べき//
ll squ(ll n, ll p, ll m){
	if(p==0) return 1;
	if(p%2==0){
		ll t=squ(n, p/2, m);
		return t*t%m;
	}
	return n*squ(n,p-1,m);
	
}


//逆元mod(mを法とするaの逆元)//
long long modinv(long long a, long long m) {
	long long b = m, u = 1, v = 0;
	while (b) {
		long long t = a / b;
		a -= t * b; swap(a, b);
		u -= t * v; swap(u, v);
	}
	u %= m;
	if (u < 0) u += m;
	return u;
}

//Cmonp//
ll fac[MAX], finv[MAX], inv[MAX];

// テーブルを作る前処理
void COMinit() {
	fac[0] = fac[1] = 1;
	finv[0] = finv[1] = 1;
	inv[1] = 1;
	for (int i = 2; i < MAX; i++) {
		fac[i] = fac[i - 1] * i % MOD;
		inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
		finv[i] = finv[i - 1] * inv[i] % MOD;
	}
}

// 二項係数計算
ll COM(ll n, ll k) {
	if (n < k) return 0;
	if (n < 0 || k < 0) return 0;
	return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}

//nが大

ll com(ll n,ll m){
    if(n<m || n<=0 ||m<0){
		return 0;
	}
	if( m==0 || n==m){
		return 1;
	}
	
	ll k=1;
	for(ll i=1;i<=m;i++){
       k*=(n-i+1); 
	   k%=MOD;
	   k*=modinv(i,MOD);
	   k%=MOD;
	}

	return k;
}


////////////////////////////////////////////////////////////////////


int main() {
ll n;
string s;
cin>>n;
cin>>s;

ll large=n/2;
ll small=1;
ll ans=0;

for(int u=1;u<=17;u++){
	ll mid;
	if(u<=16) {mid=(large+small)/2;}
else {mid=ans+1;}
ll ac=0;
vector<pair<string,int>> vec{};
for(int k=0;k<=n-mid;k++){
	string r=s.substr(k,mid);
vec.push_back(make_pair(r,k));
}
sort(ALL(vec));
string nowstr=vec[0].first;
ll nowv=vec[0].second;
for(int i=0;i<n-mid;i++){
	
	if(vec[i].first==vec[i+1].first && abs(vec[i].second-vec[i+1].second)>=mid){
		ans=max(ans,mid);
		ac=1;
		break;
	}
	if(vec[i].first!=vec[i+1].first){ nowstr=vec[i+1].first; nowv=vec[i+1].second;}
if(vec[i].first==vec[i+1].first){
	if(abs(vec[i+1].second-nowv)>=mid){
		ans=max(ans,mid);
		ac=1;
		break;
	}
}
}


if(ac){small=mid;}
else {large=mid;}
if(mid==1 && ac==0){
	cout<<0<<endl;
	return 0;
}



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




}




Measured memory_bytes: 6576
/////////////////////////////////TEST CASES////////////////////////////////////
/*
*/
/////////////////////////////////////CODE//////////////////////////////////////		
#include <bits/stdc++.h>
using namespace std;
#define FOR(i, a, b) for (ll i = (a); i < (b); i++)
#define FORD(i, a, b) for (ll i = a ; i > b ; i--)
#define fastio ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0);
#define PI 3.14159265
typedef long long ll;
#define vl vector<ll> 
#define IN(inp) ll inp;cin>>inp;
#define pb push_back
#define all(a) a.begin(),a.end()
#define FR(i,a) for(auto i:a)
#define what(A) cout<<#A<<" is "<<A<<endl;
ll MAX = 100000000000;
ll MOD = 1000000007;
void solve()
{
	IN(d)IN(t)IN(s);
	if (s * t >= d)
		cout << "Yes" << endl;
	else
		cout << "No" << endl;
	

}
int main()
{
	fastio
		//freopen("input.txt", "rt", stdin);
		//freopen("output.txt", "wt", stdout);
		ll test = 1;
	//cin >> test;
	while (test--)
	{
		solve();
	}
}

Measured memory_bytes: 3684
#include <bits/stdc++.h>
#define ADD(a, b) a = (a + ll(b)) % mod
#define MUL(a, b) a = (a * ll(b)) % mod
#define MAX(a, b) a = max(a, b)
#define MIN(a, b) a = min(a, b)
#define rep(i, a, b) for(int i = int(a); i < int(b); i++)
#define rer(i, a, b) for(int i = int(a) - 1; i >= int(b); i--)
#define all(a) (a).begin(), (a).end()
#define sz(v) (int)(v).size()
#define pb push_back
#define sec second
#define fst first
#define debug(fmt, ...) Debug(__LINE__, ":", fmt, ##__VA_ARGS__)
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> pi;
typedef pair<ll, ll> pl;
typedef pair<int, pi> ppi;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<vl> mat;
typedef complex<double> comp;
void Debug() {cerr << '\n'; }
template<class FIRST, class... REST>void Debug(FIRST arg, REST... rest){
	cerr<<arg<<" ";Debug(rest...);}
template<class T>ostream& operator<<(ostream& out,const vector<T>& v) {
	out<<"[";if(!v.empty()){rep(i,0,sz(v)-1)out<<v[i]<<", ";out<<v.back();}out<<"]";return out;}
template<class S, class T>ostream& operator<<(ostream& out,const pair<S, T>& v){
	out<<"("<<v.first<<", "<<v.second<<")";return out;}
const int MAX_N = 500010;
const int MAX_V = 100010;
const double eps = 1e-6;
const ll mod = 1000000007;
const int inf = (1 << 30) - 1;
const ll linf = 1LL << 60;
const double PI = 3.14159265358979323846;
mt19937 rng; //use it by rng() % mod, shuffle(all(vec), rng)
///////////////////////////////////////////////////////////////////////////////////////////////////

int N;
ll C[MAX_N];
ll pow2[MAX_N];

void solve() {
	cin >> N;
	rep(i, 0, N) cin >> C[i];
	pow2[0] = 1;
	sort(C, C + N);
	reverse(C, C + N);
	rep(i, 0, N) pow2[i + 1] = pow2[i] * 2 % mod;
	if(N == 1) {
		cout << (C[0] * 2) % mod << "\n";
	}
	else {
		ll res = 0;
		rep(i, 0, N) {
			ADD(res, (pow2[N - 1] + i * pow2[N - 2] % mod) * C[i] % mod);
		}
		cout << res * pow2[N] % mod << "\n";
	}
}

uint32_t rd() {
	uint32_t res;
#ifdef __MINGW32__
	asm volatile("rdrand %0" :"=a"(res) ::"cc");
#else
	res = std::random_device()();
#endif
	return res;
}

int main() {
#ifndef LOCAL
	ios::sync_with_stdio(false);
    cin.tie(0);
#endif
    cout << fixed;
	cout.precision(20);
    cerr << fixed;
	cerr.precision(6);
	rng.seed(rd());
#ifdef LOCAL
	//freopen("in.txt", "wt", stdout); //for tester
	if(!freopen("in.txt", "rt", stdin)) return 1;
#endif	
	solve();
    cerr << "Time: " << 1.0 * clock() / CLOCKS_PER_SEC << " s.\n";
	return 0;
}



Measured memory_bytes: 5888
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define repr(i, n) for (int i = (n); i >= 0; --i)
#define FOR(i, m, n) for (int i = (m); i < (n); ++i)
#define FORR(i, m, n) for (int i = (m); i >= (n); --i)
#define equals(a, b) (fabs((a) - (b)) < EPS)
using namespace std;
typedef long long ll;
const ll mod = 1000000007;
const ll mod2 = 998244353;
const ll INF = 1e18;
const long double EPS = 1e-10;

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

bool check(ll a, ll b) {
  int ca = 0, cb = 0;
  while (a > 0 && a % 2 == 0) {
    ca++;
    a /= 2;
  }
  while (b > 0 && b % 2 == 0) {
    cb++;
    b /= 2;
  }
  return ca == cb;
}

int main() {
  ll n, m;
  cin >> n >> m;
  vector<ll> a(n);
  rep(i, n) cin >> a[i];

  rep(i, n) a[i] /= 2;
  ll d = a[0];

  FOR(i, 1, n) {
    if (d > m) {
      cout << 0 << endl;
      return 0;
    }
    if (!check(d, a[i])) {
      cout << 0 << endl;
      return 0;
    }
    d = d / gcd(d, a[i]) * a[i];
  }

  ll ans = (m / d + 1) / 2;
  cout << ans << endl;

  





  
  return 0;
}


Measured memory_bytes: 1024
i = list(map(int, input().split()))
M = []
life = i[1]
count = 0

for j in range(i[0]):
  m = int(input())
  M.append(m)
  life = life-M[j]
  
M.sort()

while life-M[0] >= 0:
  life = life-M[0]
  count = count+1
  
ans = i[0] + count
print(ans)

Measured memory_bytes: 3064
#include<bits/stdc++.h>
using namespace std;
int main()
{
  int a[10];
  for(int i=1;i<=5;i++)
    cin>>a[i];
  for(int i=1;i<=5;i++)
    if(a[i]==0){
      cout<<i<<endl;
      return 0;
    }
  return 0;
}

Measured memory_bytes: 3584
// ABC042A - 和風いろはちゃんイージー

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

int main() {
	int A, B, C;
	cin >> A >> B >> C;

	bool answer = false;

	if ((A == 5)&&(B == 5)&&(C == 7)) {
		answer = true;
	} else if ((A == 5)&&(B == 7)&&(C == 5)) {
		answer = true;
	} else if ((A == 7)&&(B == 5)&&(C == 5)) {
		answer = true;
	}

	if (answer) {
		cout << "YES" << endl;
	} else {
		cout << "NO" << endl;
	}

	return 0;
}


Measured memory_bytes: 256
#include "bits/stdc++.h"
#define rep(i,a,n) for(int i=a;i<n;i++)
using namespace std;
using ll=long long;
const int M=100010;


int main(){
	int n,fin_a=0,first_b=0,ans=0;
	int tmp=0;
	string s;
	cin>>n;
	rep(i,0,n){
		bool x=false,y=false;
		cin>>s;
		if(s[s.size()-1]=='A')fin_a++,x=1;
		if(s[0]=='B')first_b++,y=1;
		if(x==1&&y==1)tmp++;
		rep(j,1,s.size()){
			if(s[j-1]=='A'&&s[j]=='B')ans++;
		}
	}
	if(tmp==fin_a&&tmp==first_b&&tmp!=0)ans+=tmp-1;
	else ans+=min(fin_a,first_b);
	cout<<ans<<endl;

}

Measured memory_bytes: 256
use std::io::*;
use std::str::FromStr;

fn read<T: FromStr>() -> T {
    let stdin = stdin();
    let stdin = stdin.lock();
    let token: String = stdin
        .bytes()
        .map(|c| c.expect("failed to read char") as char)
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect();
    token.parse().ok().expect("failed to parse token")
}

fn main() {
    let a: i32 = read();
    let b: i32 = read();
    let c: i32 = read();

    let mut cnt = 0;
    if a == b {
        cnt += 1;
    }
    if a == c {
        cnt += 1;
    }
    if b == c {
        cnt += 1;
    }
    if cnt == 1 {
        println!("Yes");
    } else {
        println!("No");
    }
}


Measured memory_bytes: 4352
#include <algorithm>
#include <cassert>
#include <cstring>
#include <iostream>
#include <vector>

using namespace std;

#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define REP(i, n) FOR(i, 0, n)
#define TRACE(x) cout << #x << " = " << x << endl
#define _ << " _ " <<

typedef long long llint;

const int M = 4;
const int mod = 1e9 + 7;

inline int add(int a, int b) { return a + b >= mod ? a + b - mod : a + b; }

inline int sub(int a, int b) { return a >= b ? a - b : a - b + mod; }

inline int mul(int a, int b) { return llint(a) * b % mod; }

struct Matrix {
  int a[M][M];
  Matrix() { REP(i, M) REP(j, M) a[i][j] = 0; }

  int* operator[](int i) { return a[i]; }
  friend Matrix operator*(Matrix a, Matrix b) {
    Matrix r;
    REP(i, M) REP(j, M) REP(k, M) r[i][j] = add(r[i][j], mul(a[i][k], b[k][j]));
    return r;
  }
};

Matrix matrix_pow(Matrix a, llint b) {
  assert(b > 0);
  b--;
  Matrix r = a;
  while (b > 0) {
    if (b % 2) r = r * a;
    a = a * a, b /= 2;
  }
  return r;
}

Matrix getMat(int N) {
  assert(N > 4);

  Matrix B;
  B[0][0] = 3;
  B[1][0] = 2;
  B[2][0] = sub(0, 1);
  B[3][0] = 1;
  B[0][1] = 1;
  B[1][2] = 1;
  B[2][3] = 1;

  Matrix A;
  A[0][0] = 63;
  A[0][1] = 18;
  A[0][2] = 5;
  A[0][3] = 1;

  A = A * matrix_pow(B, N - 4);
  return A;
}

int f(int N) {
  if (N == 0) return 1;
  if (N == 1) return 1;
  if (N == 2) return 5;
  if (N == 3) return 18;
  if (N == 4) return 63;

  Matrix A = getMat(N);
  return A[0][0];
}

int main(void) {
  ios_base::sync_with_stdio(false);

  int N, M;
  cin >> N >> M;
  vector<int> A(M);
  REP(i, M) cin >> A[i];
  A.insert(A.begin(), 0);
  A.push_back(N);
  M += 2;

  Matrix B;
  B[0][0] = 3;
  B[1][0] = 2;
  B[2][0] = sub(0, 1);
  B[3][0] = 1;
  B[0][1] = 1;
  B[1][2] = 1;
  B[2][3] = 1;

  vector<int> g(M);
  g[0] = sub(0, 1);

  int k = 0;
  Matrix C;
  for (int i = 1; i < M; ++i) {
    C = C * matrix_pow(B, A[i] - A[i - 1]);
    while (k < i && A[k] + 5 <= A[i]) {
      Matrix t = getMat(A[i] - A[k]);
      REP(j, 4) { C[0][j] = add(C[0][j], mul(g[k], t[0][j])); }
      k++;
    }

    g[i] = sub(0, C[0][0]);
    for (int j = k; j < i; ++j) {
      g[i] = sub(g[i], mul(g[j], f(A[i] - A[j])));
    }
  }

  cout << g[M - 1] << "\n";

  return 0;
}


Measured memory_bytes: 1024
#include <bits/stdc++.h>
#define int long long
using namespace std;

class BIT{
public:
  typedef long long ll;
  ll n;
  vector<ll> bit;
  BIT():n(-1){};
  BIT(ll n_){
    n=1;
    while(n < n_+2) n *= 2;
    bit.resize(n+1, 0);
  }
  
  //[0, i]までの総和を得る
  ll sum(ll i){
    assert( i >= 0 && i <= n );
    i++;
    
    ll s=0;
    while(i>0){
      s = (s + bit[i]);
      i -= i & -i;
    }
    return s;
  }

  //i番目の要素にx加算(0 オリジン)
  void add(ll i,ll x){
    assert( i >= 0 && i <= n );
    i+=2;
    
    while(i <= n){
      bit[i] = (bit[i] + x);
      i += i & -i;
    }
  }
  
  ll sum(int l,int r){ //[l, r) 0オリジン
    assert(l <= r);
    assert( 0 <= l && l <= n);
    assert( 0 <= r && r <= n);
    return sum(r) - sum(l);
  }
};

int N, a[100005];

int check(int x){
  
  vector<int> Array;
  
  for(int i=0;i<N;i++){
    
    if( a[i] <= x ) Array.push_back( 1 );
    else Array.push_back( -1 );
    
  }
  
  for(int i=1;i<N;i++) Array[i] += Array[i-1];
  
  BIT bit( 200005 );
  
  int zero = 100002;
  
  for(int i=0;i<N;i++) bit.add( zero + Array[i], 1 );
  
  int res = bit.sum( zero + 1, 200005 );
  
  for(int i=0;i<N-1;i++){
    
    bit.add( zero + Array[i], -1 );
    
    res += bit.sum( zero + Array[i] + 1, 200005 );
    
  }
  
  int all = N * ( N + 1 ) / 2;
  
  return all / 2 + 1 <= res;
}

signed main(){
  
  cin>>N;
  
  for(int i=0;i<N;i++) cin>>a[i];
  
  int L = 0, R = 1e10;
  
  while( L + 1 < R ){
    
    int M = ( L + R ) / 2;
    
    if( check( M ) == 1 ) R = M;
    else L = M;
    
  }
  
  cout<<R<<endl;
  
  return 0;
}


Measured memory_bytes: 4960
//未完
#include <bits/stdc++.h>
#include <math.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep2(i, s, n) for (int i = (s); i < (int)(n); i++)
using ll = long long;
using vec = vector<int>;
using vec2 = vector<vector<int>>;

int main(){
    string s;
    cin >> s;
    vec a(s.size());
    rep(i, s.size()){
        char c = s.at(i);
        int f = c - '0';
        a[i] = f;
    }
    ll sum = 0, m;
        //10は回したいとおりの数、100はビットの数を入れる
    for(int i = 0;i < (1 << (s.size()-1));i++){
        m = a[0];
        for(int j = 0;j < (s.size()-1);j++){
            if(i & (1 << j)){
                sum += m;
                m = 0;
            }

         m = m*10 + a[j+1];

        }
        sum += m;
    }
  cout << sum << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define REP(i,n) for(int i=0;i<(n);i++)
#define N 200010
#define INF 1000000005
typedef long long ll;
#define ALL(v) (v).begin(),(v).end()
#define SZ(x) int(x.size())
#define IN(a) cin>>(a)
#define OUT(a) cout<<(a)<<endl
typedef pair<int,int> P;
const int MAX = 1000005;
const int MOD = 1000000007;

int main(){
    int n,k;
    cin>>n>>k;
    map<int,int>m;
    REP(i,k){
        int d;
        cin>>d;
        REP(j,d){
            int x;
            cin>>x;
            x--;
            m[x]++;
        }
    }
    int ans=0;
    REP(i,n){
        if(m[i]==0)ans++;
    }
    OUT(ans);
    return 0;
}

Measured memory_bytes: 3652
#include <stdio.h>
#include <string>
#include <cstring>
#include <stdlib.h>
#include <math.h>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <list>
#include <iterator>
#include <assert.h>
#pragma warning(disable:4996) 

typedef long long ll;
#define MIN(a, b) ((a)>(b)? (b): (a))
#define MAX(a, b) ((a)<(b)? (b): (a))
#define LINF 9223300000000000000
#define INF 2140000000
const long long MOD = 1000000007;
using namespace std;


int main(int argc, char* argv[])
{
    int n,k;
    scanf("%d%d", &n, &k);

    vector<int> a(n);
    int i,j;
    for(i=0; i<n; i++) {
        scanf("%d", &a[i]);
    }

    vector<int> dp(k+1);
    dp[0]=0;
    for(i=1; i<=k; i++) {
        for(j=0; j<n; j++) {
            if(i>=a[j] && dp[i-a[j]]==0) break;
        }
        if(j<n) {
            dp[i]=1;
        }
    }
    if(dp[k]) printf("First\n");
    else      printf("Second\n");

    return 0;
}


Measured memory_bytes: 640
function Main(input) {
  var inputary = input.split(" ");
  var a = parseInt(inputary[0], 10);
  var b = parseInt(inputary[1], 10);
  var c = parseInt(inputary[2], 10);

  if(a === b && b === c) {
    console.log("Yes");
  } else {
    console.log("No");
  }
}
Main(require("fs").readFileSync("/dev/stdin", "utf8"));

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

using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
ll a,b;
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    cin>>a>>b;
    cout<<max(a+b,max(a-b,a*b));
    return 0;
}


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

int main() {
  int r, S=0;
  for (int i=0; i<3; i++) {
    cin >> r;
    S+=r;
    S*=10;
  }
  S/=10;
  if (S%4==0) {
    cout << "YES" << endl;
  }
  else {
    cout << "NO" << endl;
  }
}


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

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

    int key_1 = x;
    while(binary_search(a.begin(),a.end(),key_1)){
        key_1++;
    }
    int key_2 = x;
    while(binary_search(a.begin(),a.end(),key_2)){
        key_2--;
    }

    int ans = 0;
    if(key_1 - x > x - key_2) {
        ans = key_2;
    }else if(key_1 - x < x - key_2) {
        ans = key_1;
    } else if (key_1 - x == x - key_2){
        ans = min(key_1, key_2);
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 3636
#include<bits/stdc++.h>
using namespace std;
int main(){
	int n,m;
	cin >> n >> m;
	int a[n][m],b[m],c[n];
	for(int i=0;i<n;i++){
		for(int j=0;j<m;j++) cin >> a[i][j];
		c[i]=0;
	}
	for(int i=0;i<m;i++) cin >> b[i];
	for(int i=0;i<n;i++){
		for(int j=0;j<m;j++) c[i]+=a[i][j]*b[j];
		cout << c[i] << endl;
	}
}


Measured memory_bytes: 3124
#include <bits/stdc++.h>
#define LL long long

using namespace std;

int main()
{
    int  a,b,c;
    cin>>a>>b>>c;
    if((a==c&&a!=b)||(b==c&&b!=a)||(a==b&&a!=c))
        cout<<"Yes"<<endl;
    else
        cout<<"No"<<endl;
}


Measured memory_bytes: 256
#8 abc085 c-otoshidama
n,y=map(int,input().split())
flag=False
ans=[-1,-1,-1]
for i in range(n+1):
    for j in range(n+1-i):
        otoshidama=10000*i+5000*j+1000*(n-i-j)
        if otoshidama==y:
            flag=True
            ans[0]=i
            ans[1]=j
            ans[2]=n-i-j
            break
print('{0} {1} {2}'.format(ans[0],ans[1],ans[2]))

            

Measured memory_bytes: 3064
#include <iostream>
#include <vector>
#include <algorithm>

using namespace std;

int main() {
	int h,w;
	string s;
	cin >> h >> w;
	int count = 0;

	for(int i = 0; i < h; i++){
		cin >> s;
		for(int j = 0; j < w; j++){
			if(s[j] == '#'){
				count++;
			}
		}
	}


	if(count == h+w-1){
		cout << "Possible" << endl;

	}else{
		cout << "Impossible" << endl;
	}

	return 0;
}

Measured memory_bytes: 256
void main()
{
    int[] tmp = readln.split.to!(int[]);
    int n = tmp[0], k = tmp[1];

    writeln(n - k + 1);
}

import std.stdio;
import std.string;
import std.array;
import std.conv;
import std.algorithm;
import std.range;
import std.math;
import std.numeric;
import std.container;
import std.typecons;
import std.ascii;
import std.uni;

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

#define fastIO ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
#define int long long int
#define fi first
#define se second
#define pub push_back
#define mkp make_pair
#define pi pair<int,int>
#define push push
#define all(v) v.begin(),v.end()
#define rep(i,l,r) for(int i = (int)(l) ; i < (int)(r) ; i++)
#define clr(a,x) memset(a,x,sizeof(a));
#define rr(v) for(auto &val:v)
#define print(v) for(const auto itr:v){ cout << itr << ' ';} cout << endl;
#define init(v,x) for(auto &itr:v){ itr = x; }
#define minpq(x) x,vector<x>,greater<x>
#define ln length()
#define sz size()
#define infinity 1e18;
#define elif else if

void addEdge(vector<pi> adj[],int u,int v,int wt) {
    adj[u].pub(mkp(v,wt));
    adj[v].pub(mkp(u,wt));
}


int32_t main(){
    fastIO
    char c;
    
    cin >> c;
    
    if(c >= 'A' && c <= 'Z')
        cout << "A\n";
        
    else if(c >= 'a' && c <= 'z')
        cout << "a\n";
        
    return 0;
}

Measured memory_bytes: 3612
//C
#include <cassert>
//#include <cctype>
#include <cerrno>
#include <cfloat>
#include <ciso646>
#include <climits>
#include <clocale>
#include <cmath>
#include <csetjmp>
#include <csignal>
#include <cstdarg>
#include <cstddef>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <ccomplex>
#include <cfenv>
#include <cinttypes>
#include <cstdalign>
#include <cstdbool>
#include <cstdint>
#include <ctgmath>
#include <cwchar>
#include <cwctype>
// C++
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>
#include <array>
#include <atomic>
#include <chrono>
#include <condition_variable>
#include <forward_list>
#include <future>
#include <initializer_list>
#include <mutex>
#include <random>
#include <ratio>
#include <regex>
#include <scoped_allocator>
#include <system_error>
#include <thread>
#include <tuple>
#include <typeindex>
#include <type_traits>
#include <unordered_map>
#include <unordered_set>

//ここまで標準include

using namespace std;

long aCb(long a, long b) {
	long out = 1;
	for (long i = 1; i <= b; i++) {
		out = out * (a + 1 - i) / i;
	}
	return out;
}

long long gcd(long long a, long long b) {
	long long r = -1;
	if (a < b) {
		swap(a, b);
	}
	while (r != 0) {
		r = a % b;
		if (r == 0) {
			return b;
		}
		else {
			a = b;
			b = r;
		}
	}
}

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

int main() {
	int X, A, B;
	cin >> X >> A >> B;
	if (B <= A) {
		cout << "delicious" << endl;
	}
	else if (B - A <= X) {
		cout << "safe" << endl;
	}
	else {
		cout << "dangerous" << endl;
	}
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
typedef long long ll;
using namespace std;
ll arr[3005];
ll dp[3005][3005];
ll rec(ll s,ll e)
{
	if(s==e)
	return arr[s];
	if(dp[s][e]!=-1)
	return dp[s][e];

	dp[s][e]=max(arr[s]-rec(s+1,e),arr[e]-rec(s,e-1));
	return dp[s][e];
}
ll solve(ll n)
{
	
	for(ll i=0;i<n;i++)
	cin>>arr[i];
	
	memset(dp,-1,sizeof(dp));
	
	return rec(0,n-1);//-arr[n-1];
}
int main()
{
	ll t=1,n;
	while(t--)
	{
	
		cin>>n;
		cout<<solve(n)<<endl;
	}


    return 0;
}

Measured memory_bytes: 71040
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

class Program
{
    public static int Main()
    {
        string S = Console.ReadLine();
        string output = "";
        int backspace = 0;

        for (int i = S.Length - 1; i >= 0; --i)
        {
            if (S[i] == 'B')
            {
                ++backspace;
            }
            else if(backspace>0)
            {
                --backspace;
            }
            else
            {
                output = S[i] + output;
            }
        }

        Console.WriteLine(output);
        return 0;
    }
}


Measured memory_bytes: 2648
const fs = require('fs')
const reader = (s: string) => s.split(' ').map(t => parseInt(t,10))
 
function Main(input: string) {

  const go75 = [5,5,7];
  const [...N] = reader(input)
  const sorting = N.sort()


  console.log(sorting.toString() === go75.toString() ? "YES" : "NO");

}
 
Main(fs.readFileSync('/dev/stdin', 'utf8'))

Measured memory_bytes: 7372
#include<bits/stdc++.h>
using namespace std;
char c[11];
int main()
{
	int i,n,k;
	char a;
	scanf("%d",&n);
	scanf("%s",c);
	scanf("%d",&k);
	a=c[k-1];
	for(i=0;i<n;i++)
	{
		if(c[i]==a)
			printf("%c",c[i]);
		else
			printf("*");
	}
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define ll long long
const double pi = 3.14159;
using namespace std;
int main()
{
	/*#ifndef ONLINE_JUDGE
	freopen("input.txt","r", stdin);
	freopen("output.txt","w", stdout);
	freopen("error.txt","w", stderr);
	#endif*/
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
	
	int n ;cin>>n;
	cout<<2*pi*n<<"\n";
	return 0;
}

Measured memory_bytes: 3800
#ABC117_C

N,M=map(int,input().split())

if N>=M:
    print(0)
    exit()
else:
    X=list(map(int,input().split()))
    X.sort()
    X_dist=[X[i+1]-X[i] for i in range(M-1)]
    X_dist.sort(reverse=True)
    ans=sum(X_dist[N-1:])
    print(ans)



Measured memory_bytes: 13960
#include <iostream>
using namespace std;
int main()
{
	int n, d, x, ans = 0;
  	cin >> n >> d >> x;
  	for (int i = 0; i < n; i++){
    	int a; cin >> a;
      	for (int j = 1; j <= d; j += a){
        	ans++;
        }
    }
  	cout << ans + x;
}

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

int main() {
	int n; cin >> n;
	vector<int> a(n);
	vector<int> b(n - 1);
	rep(i, n - 1) cin >> b[i];
	int ans = 0;
	rep(i, n) {
		if (i == 0) {
			a[0] = b[0];
		}
		else if (i == n - 1) {
			a[n - 1] = b[n - 2];
		}
		else {
			a[i] = min(b[i], b[i - 1]);
		}
	}
	rep(i, n) {
		ans += a[i];
	}
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define endl "\n"
#define ll long long 

int main()
{
    string s1,s2;
    int n;
    cin>>n;
    cin>>s1>>s2;
    int a = 0,b = 0;
    for(int i=0;i<2*n;i++)
    {
        if(i%2==0)
        {
            cout<<s1[a];
            a++;
        }
        else{
        cout<<s2[b];
        b++;
        }
    }
    cout<<endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ll long long int
#define ld long double
#define yorn(f) cout<<((f)?"Yes":"No")<<endl;
#define YORN(f) cout<<((f)?"YES":"NO")<<endl;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define repi(i, n) for (int i = 1; i < (int)(n); i++)
#define all(x) (x).begin(), (x).end()
#define put(x) cout << x << endl;
#define println(x) cout << x << endl;
using namespace std;


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

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

    ll res = T[0];
    rep(i, n) {
        ll div = gcd(res, T[i]);
        
        ll div2 = gcd(T[i], div);
        ll div1 = div / div2;

        res = (res / div1) * (T[i] / div2);
    }

    put(res);

    return 0;
}

Measured memory_bytes: 3628
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define INF 1e9
#define PI 3.14159265359
#define MOD 1000000007
#define ALL(v) v.begin(),v.end()
#define ALLR(v) v.rbegin(),v.rend()
typedef long long ll;
const int dx[4] = {1,0,-1,0};
const int dy[4] = {0,1,0,-1};
//isPrime
//modpow modinv
//getDigit
int main() {
  cout << fixed << setprecision(10);
  int r,g;
  cin >> r >> g;
  cout << 2*g-r << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
 
using namespace std;
using ll = long long;
 
const int N = 200005;
 
int n;
ll k;
 
ll div_floor(ll a, ll b) {
	return a / b - (((a ^ b) < 0) and a % b);
}
ll div_ceil(ll a, ll b) {
	return a / b + (((a ^ b) >= 0) and a % b);
}
int a[N];
 
ll f(ll lim) {
 
	ll ans = 0;
	
	for(int i = 0; i < n; i++) {
		if(a[i] == 0) {
			if(lim >= 0) ans += n - 1;
		}
		else if(a[i] > 0) {
			// a[i] * x <= lim
			// x <= lim / a[i]
			ll tmp = div_floor(lim, a[i]);
			int id = int(upper_bound(a, a + n, tmp) - a);
			if(i < id) ans += id - 1;
			else ans += id;
		}
		else { // a[i] < 0
			// a[i] * x <= lim
			// x >= lim / a[i];
			ll tmp = div_ceil(lim, a[i]);
			int id = int(lower_bound(a, a + n, tmp) - a);
			if(i >= id) ans += n - id - 1;
			else ans += n - id;
		}
	}
	assert(ans % 2 == 0);
	return ans / 2;
}
 
int main() {
	scanf("%d %lld", &n, &k);
 
	for(int i = 0; i < n; i++) scanf("%d", a + i);
 
	sort(a, a + n);
 
	ll lo = -1e18, hi = 1e18, ans = 0;
 
	while(lo <= hi) {
		ll mid = (lo + hi) / 2;
		if(f(mid) >= k) ans = mid, hi = mid - 1;
		else lo = mid + 1;
	}
	printf("%lld\n", ans);
	
}

Measured memory_bytes: 1024
/* ABC087B -Coins */

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

int func(int B, int C, int X){
  int b = X / 100, c = (X - 100 * b) / 50, cnt_2 = 0;
    while(b >= 0){
      if(b <= B && c <= C) cnt_2++;
      b--; c += 2;
    }
  return cnt_2;
}

int main(){
  int A, B, C, X, cnt = 0;
  cin >> A >> B >> C >> X;
  int a = X / 500;
  while(a >= 0){
    if(a <= A) cnt += func(B, C, X - 500 * a);
    a--;
  }
  cout << cnt << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
double all[10000][10000];
int main(){
    int a,kari,ko,b,c,d,x,y,jo;
    cin>>a;
    cin>>d;
    for(int i=0;i<d;i++){
        cin>>b>>c;
        if(b>a/2){b=a-b+1;}
        if(c>a/2){c=a-c+1;}
        jo=min(b,c)%3;
        if(jo==0){jo=3;}
        cout<<jo<<endl;;
    }


    // ???????????????????????????1000x1000????????????????¢??????§??????????????????
    //ko=a-1;

    //if(a%2==0){kari=a/2;}
    //if(a%2==1){kari=a/2+1;}

    /*for(int i=0;i<kari;i++){
        for(int j=i;j<a-i;j++){
            if(i%3==0){
                all[j][i]=1;
                all[i][j]=1;
                all[ko-i][j]=1;
                all[j][ko-i]=1;
            }
            if(i%3==1){
                all[i][j]=2;
                all[j][i]=2;
                all[ko-i][j]=2;
                all[j][ko-i]=2;
            }
            if(i%3==2){
                all[i][j]=3;
                all[j][i]=3;
                all[ko-i][j]=3;
                all[j][ko-i]=3;
            }
        }
    }*/
    /*for(int i=0;i<a;i++){



        for(int j=0;j<a;j++){
            cout<<all[i][j]<<" ";
        }cout<<endl;
    }*/

}

Measured memory_bytes: 3112
#include <iostream>
using namespace std;
#define MAX 101

int cnt;

void bubble_sort(int n,int array[]){
    int tmp;
    for(int i = 1 ; i < n ; i++){
        for(int j = n-1 ; j >= i ; j--){
            if(array[j] < array[j-1]){
                tmp = array[j];
                array[j] = array[j-1];
                array[j-1] = tmp;
                cnt++;
            }
        }
    }
}

int main(){
    int n,array[MAX];
    
    cin >> n;
    for(int i = 0 ; i < n ; i++){
        cin >> array[i];
    }
    cnt = 0;
    bubble_sort(n,array);
    
    for(int i = 0 ; i < n ; i++){
        if(!i) cout << array[i];
        else cout << ' ' << array[i];
    }
    cout << endl;
    cout << cnt << endl;
    
    return 0;
}

Measured memory_bytes: 1160
#include<bits/stdc++.h>
using namespace std;
#define REP(i, n) for(int i=0, i##_len=(n); i<i##_len; ++i)
typedef long long ll;
#define pb push_back
#define fi first
#define se second
#define ALL(x) (x).begin(),(x).end()
#define RALL(x) (x).rbegin(),(x).rend()
template <class T, class U> ostream &operator<<(ostream &os, const pair<T, U> &p){os<<"("<<p.first<<","<< p.second<<")";return os;}
template <class T> ostream &operator<<(ostream &os, const vector<T> &v){os<<"{";REP(i,(int)v.size()){if(i)os<<",";os<<v[i];}os<<"}";return os;}
template <typename T, size_t S> void printArray(const T (&array)[S]){for(auto val : array)std::cout << val << ", ";std::cout << "\n";}
void Yes() {cout << "Yes" << endl;}
void No() {cout << "No" << endl;}
void YES() {cout << "YES" << endl;}
void NO() {cout << "NO" << endl;}
const double PI=acos(-1);
const ll MOD = 1000000007;
using Graph = vector<vector<int>>;
//const int dx[4] = {1, 0, -1, 0};
//const int dy[4] = {0, 1, 0, -1};
//const int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1};
//const int dy[8] = {0, 1, 0, -1, 1, 1, -1, -1};

void solve(){
    ll n; cin >> n;
    map<ll, ll> mp;
    vector<ll> x, y;
    for(ll i=0; i<n; i++){
        ll ia; cin >> ia;
        x.pb((i+1) - ia);
        y.pb((i+1) + ia);
    }

    REP(i, n){
        mp[x[i]]++;
    }
    ll res = 0;
    REP(i, n){
        if(mp[y[i]] >= 1){
            res += mp[y[i]];
        }
        else continue;
    }
    
    cout << res << endl;
}

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

Measured memory_bytes: 28996
#include <bits/stdc++.h>
using namespace std;
int a, b;
int main() 
{
    cin>>a>>b;
    if(a>0&&b>0) 
        cout<<"Positive"<<endl;
	else 
	if(max(a,b)>=0&&min(a,b)<=0||a==0||b==0) 
        cout<<"Zero"<<endl;
	else 
	{
        if ((abs(min(a, b))-abs(max(a,b)))%2==0)
            cout<<"Negative"<<endl;
		else 
            cout<<"Positive"<<endl;
    }
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define fastio ios_base::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr);
#define ll long long
const int N = 2e5 + 1;
ll int freq[100001];
void findAns()
{
    //memset(freq, 0, sizeof(freq));

    for (int i = 0; i < 100001; i++) freq[i] = 0;

    int n;
    cin >> n;

    int x;
    ll int sum = 0;
    for (int i = 0; i < n; i++) {cin >> x; freq[x]++; sum += x;}

    int q;
    cin >> q;
    int a, b;
    while (q--)
    {
        cin >> a >> b;
        sum = sum - a * freq[a] + b * (freq[a]);
        // freq[a] = 0;
        freq[b] += freq[a];
        freq[a] = 0;
        cout << sum << "\n";
    }


}
int main()
{
// #ifndef ONLINE_JUDGE
//     freopen("in.txt", "r", stdin);
//     freopen("o1.txt", "w", stdout);
// #endif

    fastio;

    // ll int t;
    // cin >> t;

    // while (t--)
    findAns();
}

Measured memory_bytes: 4420
package main

import "bufio"
import "fmt"
import "os"
import "strconv"

func main() {
	var scanner = bufio.NewScanner(os.Stdin)
	scanner.Split(bufio.ScanWords)
	var nextInt = func() int {
		scanner.Scan()
		n, _ := strconv.Atoi(scanner.Text())
		return n
	}

	var n = nextInt()
	var q = nextInt()

	var g = make([][]int, n)
	for i := 0; i < n-1; i++ {
		var a = nextInt() - 1
		var b = nextInt() - 1
		g[a] = append(g[a], b)
		g[b] = append(g[b], a)
	}

	var f = make([]int, n)
	for i := 0; i < q; i++ {
		var p = nextInt() - 1
		var x = nextInt()
		f[p] += x
	}

	var dfs func(int, int)
	dfs = func(a int, parent int) {
		for _, b := range g[a] {
			if b == parent {
				continue
			}
			f[b] += f[a]
			dfs(b, a)
		}
	}
	dfs(0, -1)

	var writer = bufio.NewWriter(os.Stdout)
	defer writer.Flush()
	for i := 0; i < n; i++ {
		fmt.Fprintf(writer, "%d ", f[i])
	}
}


Measured memory_bytes: 75904
#include<bits/stdc++.h>
#define int long long
#define ll long long
#define fi first
#define se second
#define pb push_back
#define pii pair<int,int>
#define vi vector<int>
using namespace std;
const int N = 1e3+5,M = 1e6+5;
const int inf = 1e18;
int w[N],val[N];
ll good[100005];

main() {
    ios::sync_with_stdio(0);
    int n,W;
    cin >> n >> W;
    int lim = n*1000;
    for (int i = 1; i <= lim; i++)
        good[i] = W + 1;
    //good[0] = 1;
    for (int i = 1; i <= n; i++)
        cin >> w[i] >> val[i];
    for (int i = 1; i <= n; i++)
        for (int j = lim;j >= 0;j--)
            if (good[j] + w[i] <= W)
                good[ j + val[i] ] = min(good[j + val[i]],good[j] + w[i]);
    int ans = 0;
    for (int i = 1; i <= lim; i++)
        if (good[i] <= W)
        ans = max(ans,i);
        cout << ans;
}


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

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

#define mp make_pair
#define f first
#define s second
#define pb push_back
#define sz(x) ((int)(x).size())
#define all(x) (x).begin(),(x).end()
#define speed() ios_base::sync_with_stdio(0), cin.tie()
#define forit(it, s) for(__typeof(s.begin()) it = s.begin(); it != s.end(); ++it)

using namespace std;

typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
const int N = (int)2e5;


int main() { 
	#ifdef LOCAL
	freopen("a.in", "r", stdin);
	#endif
	int n;
	scanf("%d", &n);
	int cnt[2] = {0, 0};
	for (int i = 1, a; i <= n; i++) {
		scanf("%d", &a);
		cnt[a&1]++;
	}
	puts((cnt[1] & 1) ? "NO" : "YES");
	
	return 0;
}


Measured memory_bytes: 256
from sys import stdin

def main():
    N = int(stdin.readline().rstrip())
    a = [y for y in [6 ** x for x in range(10)] if y <= N]
    b = [y for y in [9 ** x for x in range(10)] if y <= N]
    c = sorted(list(set(a) | set(b)))
    spam = [None] * N
    count = 0
    tmp = [-1]
    while True:
        count += 1
        tmp2 = tmp[:]
        tmp = []
        for x in c:
            for y in tmp2:
                idx = y + x
                if idx >= N:
                    continue
                if not spam[idx]:
                    spam[idx] = count
                    tmp.append(idx)
        if spam[-1]:
            print(spam[-1])
            break


if __name__ == '__main__':
    main()


Measured memory_bytes: 5520
#include <bits/stdc++.h>
#define INF (1<<30)
#define MOD 1000000007
#define l_ength size
using ll = long long;
using namespace std;

int main(){
	int n, k; cin >> n >> k;
	vector<ll> v(n);
	ll ans = 0;
	for( auto &i : v ) cin >> i;
	for( int l = 0; l <= n; ++l ){
		for( int r = 0; r <= n; ++r ){
			if( ( l == 0 && r == 0 ) || l+r > n || l+r > k ) break;
			ll sum = 0;
			priority_queue< ll, vector<ll>, greater<ll> > pq;
			for( int i = 0; i < l; ++i ){
				sum += v[i];
				if( v[i] < 0 ) pq.push(v[i]);
			}
			for( int i = 0; i < r; ++i ){
				sum += v[n-1-i];
				if( v[n-i-1] < 0 ) pq.push(v[n-1-i]);
			}
			ans = max(ans, sum);
			for( int i = 0; ( i < k-l-r && !pq.empty() ); ++i ){
				sum += (-1)*pq.top();
				pq.pop();
			}
			ans = max(ans, sum);
		}
	}
	if( k > n ){
		ll sum = accumulate( v.begin(), v.end(), 0ll );
		priority_queue< ll, vector<ll>, greater<ll> > pq;
		for( int i = 0; i < n; ++i ){
			if( v[i] < 0 ) pq.push(v[i]);
		}
		for( int i = 0; ( i < k-n && !pq.empty() ); ++i ){
			sum += (-1)*pq.top();
			pq.pop();
		}
		ans = max(ans, sum);
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 256
def main():
    n=int(input())
    s=[[i for i in sorted(list(input().upper()))] for i in range(n)]
    used_min=[51]*26
    alpha2num = lambda c: ord(c) - ord('A')
    num2alpha = lambda c: chr(c + 65)
    for i in s:
        tmp = [0 for i in range(26)]
        for j in i:
            tmp[alpha2num(j)] += 1
        for k in range(26):
            if used_min[k] > tmp[k]:
                used_min[k] = tmp[k]
    for i in range(26):
        for j in range(used_min[i]):
            print(num2alpha(i).lower(),end='')

if __name__ == '__main__':
    main()

Measured memory_bytes: 3064
#include<iostream>
#include <stdio.h>
#include <string>
#include <string.h>
#include <algorithm>
#include <functional>
#include <vector>
#include <math.h>

using namespace std;

int gcd(int a, int b) {
	if (b == 0) return a;
	else return gcd(b, a%b);
}
int main()
{
	long long N, X;
	long long x[100010];
	cin >> N >> x[0];

	N = N + 1;

	for (long long i = 1; i < N; i++) {
		cin >> x[i];
	}

	sort(x, x + N);

	for (long long i = 1; i < N; i++) {
		x[i] = x[i] - x[0];
	}
	x[0] = 0;

	long long D = x[1] - x[0];
	long long temp = D;
	for (long long i = 1; i < N; i++) {
		long long a = x[i];
		long long b = D;
		D = gcd(a, b);
	}

	cout << D;

	return 0;
}


Measured memory_bytes: 1024