akhauriyash/Code-Regression huggingface dataset:
/*
Task:F - Must Be Rectangular!
Statement: Given N points (1<=x,y<=10^5)
You can do the following operation find acute triangle
add the point to form it rectangular if that point doesn't exist yet;
Find the maximum number of operation
*/
#include<bits/stdc++.h>
using namespace std;
const int maxn=2e5+100;
int n,u,v,vis[maxn],x,y;
vector<int> a[maxn];
void dfs(int nod,int dis){
    vis[nod]=true;
    if(dis&1) x++;
    else y++;
    for(auto i:a[nod]){
        if(!vis[i]){
            dfs(i,dis+1);
        }
    }
    return;
}

int main(){
    scanf("%d",&n);
    for(int i=1;i<=n;i++){
        scanf("%d%d",&u,&v);
        v+=(100000);
        a[u].push_back(v);
        a[v].push_back(u);
    }
    long long ans=0;
    for(int i=1;i<=200010;i++){
        if(!vis[i]){
            x=0,y=0;
            dfs(i,0);
            ans+=(1LL*x*y);
        }
    }
    printf("%lld\n",ans-n);
}
/*
6
1 1
1 2
1 3
2 2
2 3
2 4
*/


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

int main() {
  std::ios_base::sync_with_stdio(false);
      std::cin.tie(NULL);
int n;
std::cin >>n;
while (n>0) {
   n-=1000;
}
std::cout << abs(n) << '\n';
return 0;
}


Measured memory_bytes: 3640
#include <bits/stdc++.h>
#define ALL(A) (A).begin(), (A).end()
#define ll long long
#define rep(i, n) for (int i = 0; i < (n); i++)

using namespace std;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }

const ll mod = 1e9 + 7;
const ll INF = -1 * ((1LL << 63) + 1);
const int inf = -1 * ((1 << 31) + 1);

int main(void){
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(20);
    int a,b,c;
    cin >> a >> b >> c;
    if(a==b && a!=c){
        cout << "Yes" << endl;
    }else if(a==c && a!=b){
        cout << "Yes" << endl;
    }else if(b==c && a!=b){
        cout << "Yes" << endl;
    }else cout << "No" << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <cstring>
#include <stack>
#include <vector>
using namespace std;
const int maxx = 1010;
const int INF = 1 << 30;
int n, m[maxx][maxx];
int u, v ,k, c;
int flag[maxx];

void dijkstra() {
	int d[maxx];
	for (int i = 0; i < n; i++) {
		d[i] = INF;
		flag[i] = 0;
	}

	d[0] = 0;
	while (1) {
		int minv = INF;
		u = -1;
		// ???????????????????°???????
		for (int i = 0; i < n; i++) {
			if (minv > d[i] && flag[i] == 0) {
				u = i;
				minv = d[i];
			}
		}

		if (u == -1)
			break;

		// ?????°???????????\S
		flag[u] = 1;

		// ??´??°?????±u?????????V-S???v?????????????°??????¬
		for (int v = 0; v < n; v++) {
			if (flag[v] == 0 && m[u][v] != INF && d[v] > d[u] + m[u][v]) {
				d[v] = d[u] + m[u][v];
			}
		}
	}

	for (int i = 0; i < n; i++)
		printf("%d %d\n", i, d[i] == INF ? -1 : d[i]);
}
int main()
{
	scanf("%d", &n);
	
	for (int i = 0; i < n; i++) {
		for (int j = 0; j < n; j++) {
			m[i][j] = INF;
		}
	}
	for (int i = 0; i < n; i++) {
		scanf("%d %d", &u, &k);
		for (int j = 0; j < k; j++) {
			scanf("%d %d", &v, &c);
			m[u][v] = c;
		}
	}
	dijkstra();
	return 0;
}

Measured memory_bytes: 3548
#include<bits/stdc++.h>
#define rep(i,a,b) for(int i=a;i<b;i++)
#define rrep(i,a,b) for(int i=a;i>=b;i--)
#define fore(i,a) for(auto &i:a)
#define all(x) (x).begin(),(x).end()
//#pragma GCC optimize ("-O3")
using namespace std; void _main(); int main() { cin.tie(0); ios::sync_with_stdio(false); _main(); }
typedef long long ll; const int inf = INT_MAX / 2; const ll infl = 1LL << 60;
template<class T>bool chmax(T& a, const T& b) { if (a < b) { a = b; return 1; } return 0; }
template<class T>bool chmin(T& a, const T& b) { if (b < a) { a = b; return 1; } return 0; }
//---------------------------------------------------------------------------------------------------
/*---------------------------------------------------------------------------------------------------
　　　　　　　　　　　 ∧＿∧
　　　　　 ∧＿∧ 　（´<_｀ ）　 Welcome to My Coding Space!
　　　　 （ ´_ゝ`）　/　 ⌒i     @hamayanhamayan
　　　　／　　　＼　 　  |　|
　　　 /　　 /￣￣￣￣/　　|
　 ＿_(__ﾆつ/　    ＿/ .| .|＿＿＿＿
　 　　　＼/＿＿＿＿/　（u　⊃
---------------------------------------------------------------------------------------------------*/

int N;
//---------------------------------------------------------------------------------------------------
void _main() {
    cin >> N;
    int cnt = (N + 1) / 2;
    double ans = 1.0 * cnt / N;
    printf("%.10f\n", ans);
}








Measured memory_bytes: 256
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<cmath>
using namespace std;
#define pi 3.14159265358979323846
typedef long long ll;
#define double long double
struct complx
{
	double x,y;
	complx(double a=0,double b=0):x(a),y(b){}
};
complx operator+(const complx a,const complx b)
{
	return complx(a.x+b.x,a.y+b.y);
}
complx operator-(const complx a,const complx b)
{
	return complx(a.x-b.x,a.y-b.y);
}
complx operator*(const complx a,const complx b)
{
	return complx(a.x*b.x-a.y*b.y,a.x*b.y+a.y*b.x);
}
complx operator/(const complx a,const double b)
{
	return complx(a.x/b,a.y/b);
}
const int mod=200003;
int lim,len,rev[1000005];
void getlim(int dep)
{
	lim=1,len=0;
	while(lim<=dep) lim<<=1,len++;
	for(int i=1;i<lim;i++)
		rev[i]=(rev[i>>1]>>1)|((i&1)<<(len-1));
}
void fft(complx *a,int fl)
{
	for(int i=1;i<lim;i++)
		if(i<rev[i]) swap(a[i],a[rev[i]]);
	for(int k=1;k<lim;k<<=1)
	{
		complx wn(cos(pi/k),sin(pi/k));
	//	printf("k=%d,w=%f,%f\n",k,wn.x,wn.y);
		for(int i=0,r=k*2;i<lim;i+=r)
		{
			complx w(1,0);
			for(int j=0;j<k;j++,w=w*wn)
			{
				complx x=a[i+j],y=a[i+j+k]*w;
				a[i+j]=x+y;
				a[i+j+k]=x-y;
			}
		}
	}
	if(fl==-1)
	{
		reverse(a+1,a+lim);
		for(int i=0;i<lim;i++)
			a[i]=a[i]/(double)lim;
	}
}
int n,a[1000005],g[1000005],rg[1000005];
complx f[1000005];
ll ans,tans[1000005];
int main()
{
//	freopen("agc.in","r",stdin);
	int nw=1;
	for(int i=0;i<mod-1;i++)
	{
		g[nw]=i;
		rg[i]=nw;
		nw=2*nw%mod;
	}
//	for(int i=0;i<mod;i++)
	//	if(!g[i]) printf("i=%d,%d ",i,g[i]);
	scanf("%d",&n);
	for(int i=1;i<=n;i++)
	{
		scanf("%d",&a[i]);
		if(a[i]) f[g[a[i]]].x=f[g[a[i]]].x+1;
	}
	getlim(500000);
	//printf("lim=%d\n",lim);
	fft(f,1);
	for(int i=0;i<lim;i++)
		f[i]=f[i]*f[i];
	fft(f,-1);
	for(int i=0;i<=500000;i++)
	{
		tans[i%(mod-1)]+=f[i].x+0.5;
		//if(floor(f[i].x)!=floor(f[i].x+1e-2)) printf("i=%d,f=%.10Lf\n",i,f[i].x);
	}
	for(int i=0;i<mod-1;i++)
		ans+=1ll*tans[i]*rg[i];
	for(int i=1;i<=n;i++)
		ans-=1ll*a[i]*a[i]%mod;
	ans/=2;
	printf("%lld",ans);
	return 0;
}

Measured memory_bytes: 39640
#include <iostream>
#include <string>
#include <array>
#include <vector>
#include <cmath>
#include <algorithm>
#include <numeric>
#include <iterator>
#include <limits>
#include <set>
#include <map>

int main()
{
    std::string s;
    std::cin >> s;
    const auto n = s.size();

    std::string a2(s.rbegin(), s.rbegin() + (n - 1) / 2);
    if (!std::equal(a2.begin(), a2.end(), s.begin())) {
        std::cout << "No" << std::endl;
        return 0;
    }

    std::string b1(s.begin(), s.begin() + (n - 1) / 2);
    std::string b2(b1.rbegin(), b1.rbegin() + b1.size() / 2);
    if (!std::equal(b2.begin(), b2.end(), b1.begin())) {
        std::cout << "No" << std::endl;
        return 0;
    }

    std::string c1(s.begin() + (n + 3) / 2 - 1, s.end());
    std::string c2(c1.rbegin(), c1.rbegin() + c1.size() / 2);
    if (!std::equal(c2.begin(), c2.end(), c1.begin())) {
        std::cout << "No" << std::endl;
        return 0;
    }

    std::cout << "Yes" << std::endl;

    return 0;
}


Measured memory_bytes: 256
package main

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

var reader = bufio.NewReaderSize(os.Stdin, 1000000)
var writer = bufio.NewWriter(os.Stdout)
func NextLine() string {
  var line, buffer []byte
  var isPrefix bool = true
  var err error
  for isPrefix {
    line, isPrefix, err = reader.ReadLine()
    if err != nil { panic(err) }
    buffer = append(buffer, line...)
  }
  return string(buffer)
}
func NextIntVec() []int {
  L := strings.Split(NextLine(), " ")
  N := make([]int, len(L))
  for i := range N {
    N[i], _ = strconv.Atoi(L[i])
  }
  return N
}
func Write(s interface{}) {
  fmt.Fprintln(writer, s)
}
func Output() {
  _ = writer.Flush()
}

func main() {
  A := NextIntVec()
  O := A[1]
  JIL := 0
  if (A[0] % 2) + (A[3] % 2) + (A[4] % 2) > 1 {
    if A[0] > 0 && A[3] > 0 && A[4] > 0 { JIL = 1 }
  }
  I2 := (A[0] - JIL) / 2
  J2 := (A[3] - JIL) / 2
  L2 := (A[4] - JIL) / 2
  ans := O + 3 * JIL + 2 * I2 + 2 * J2 + 2 * L2
  Write(ans)
  Output()
}

Measured memory_bytes: 640
// #include C {
#include<cstring>
#include<cassert>
#include<cstdio>
#include<cctype>
#include<cmath>
// }

// #include C++ {
#include<functional>
#include<algorithm>
#include<iostream>
#include<vector>
#include<string>
#include<bitset>
#include<queue>
#include<deque>
#include<stack>
#include<list>
#include<map>
#include<set>
// }

using namespace std;
// #typedef {
typedef long long int64;
typedef pair <int, int> PII;
typedef pair <int64, int64> PLL;
// }

// #parameter{
#ifdef DEBUG_MODE

#define TYPE decltype
#define RF(filename) {freopen((filename), "r", stdin);}
#define WF(filename) {freopen((filename), "w", stdout);}
#define DF(filename) {freopen((filename), "w", stderr);}
#define eprintf printf

#else

#define TYPE __typeof
#define RF(filename) {;}
#define WF(filename) {;}
#define DF(filename) {;}
#define eprintf(...)
#define fprintf(...)

#endif

// #define {
#define SZ(a) ((int)(a).size())
#define X first
#define Y second
#define MP make_pair
#define L(x) ((x)<<1)
#define R(x) ((x)<<1 | 1)
#define max3(x, y, z) (max(max((x), (y)), (z)))
#define min3(x, y, z) (min(min((x), (y)), (z)))
#define BIT(x, i) (((x) >> (i)) & 1)
#define ALL(it) (it).begin(), (it).end()
#define FILL(__space, __val) memset(__space, __val, sizeof(__space))
#define MOVE(__spaceTo, __spaceFrom) memmove(__spaceTo, __spaceFrom, sizeof(__spaceTo))
#define UNIQUE(__vector) sort(ALL(__vector)), __vector.resize(unique(ALL(__vector)) - __vector.begin())
#define FOR(it, c) for( TYPE((c).begin()) it = (c).begin(); it != (c).end(); it++)
/////////////////////////////////////////////////////////////
const double PI = acos(-1.0);
const double EPS = 1e-6;

#define MAX_N 505
#define MAX_M 100005
#define MOD (int)(1e9+7)
#define INF ((1 << 30) - 1)
#define BINF ((1LL << 62) - 1LL)
#define NONE -1
#define NIL 0
// }

/////////////////////////////////////////////////////////////
bitset <MAX_N> visit;
vector <PII> edge;
int N, M;
void DFS(int u, int father, int forbid_index) {
	for (int j = 0; j < M; j++) {
		if (j == forbid_index)
			continue;
		if (edge[j].X == u && !visit[edge[j].Y]) {
			visit[edge[j].Y] = true;
			DFS(edge[j].Y, u, forbid_index);
		}
		if (edge[j].Y == u && !visit[edge[j].X]) {
			visit[edge[j].X] = true;
			DFS(edge[j].X, u, forbid_index);
		}
	}
}
/////////////////////////////////////////////////////////////
int main() {
	RF("input.txt");
//  WF("output.txt");
	DF("err.txt");

	scanf("%d %d", &N, &M);
	for (int j = 0; j < M; j++) {
		int a, b;
		scanf("%d %d", &a, &b);
		edge.emplace_back(a, b);
	}
	int bridge_count = 0;
	for (int j = 0; j < M; j++) {
		visit.reset();
		visit[1] = true;
		DFS(1, 1, j);
		if (visit.count() < N)
			bridge_count++;
	}
	printf("%d\n", bridge_count);
}

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

int n, m, x, c[15], a[15][15], sum[15], ans = 0x7fffffff;
bool flag;

bool check(int x) {
    for (int i = 1; i <= m; ++i) {
        if (sum[i] < x) {
            return false;
        }
    }
    return true;
}

void dfs(int stp, int cost) {
    if (cost >= ans) {
        return;
    }
    if (stp > n) {
        if (check(x)) {
            flag = true;
            ans = min(ans, cost);
        }
        return;
    }
    dfs(stp + 1, cost);
    for (int i = 1; i <= m; ++i) {
        sum[i] += a[stp][i];
    }
    dfs(stp + 1, cost + c[stp]);
    for (int i = 1; i <= m; ++i) {
        sum[i] -= a[stp][i];
    }
}

int main() {
    scanf("%d%d%d", &n, &m, &x);
    for (int i = 1; i <= n; ++i) {
        scanf("%d", c + i);
        for (int j = 1; j <= m; ++j) {
            scanf("%d", &a[i][j]);
        }
    }
    dfs(1, 0);
    if (flag) {
        printf("%d\n", ans);
    } else {
        printf("-1\n");
    }
    return 0;
}

Measured memory_bytes: 3828
#include<bits/stdc++.h>
using namespace std;
#define ll long long int
#define FOR(i,a,b) for(int i=a;i<b;i++)
#define FORit(it,a) for(auto it=a.begin();it!=a.end();it++)
#define ROF(i,a,b) for(int i=a;i>=b;i--)
#define vec vector
#define pb push_back
#define pop pop_back
#define all(x) x.begin(),x.end()
#define testcases ll t;cin>>t;while(t--)
#define mem(a,k) memset(a,k,sizeof(a))
#define F first
#define S second
#define MP(x,y) make_pair(x,y)
#define rt return
#define br break
#define ct continue
#define elif else if
#define ii pair<ll,ll>
#define arrin(a,n,index) for(int i=index;i<n;i++)cin>>a[i]
#define vecin(a,n,index) for(int i=index;i<n;i++)cin>>a[i]
#define arrout(a,n,index) for(int i=index;i<n;i++)cout<<a[i]<<" ";cout<<endl;
#define vecout(a,n,index) for(int i=index;i<n;i++)cout<<a[i]<<" ";cout<<endl;
ll mod = 1000000007;
int main()
{
#ifndef ONLINE_JUDGE
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#endif
	ios_base::sync_with_stdio(false);	cin.tie(NULL);	cout.tie(NULL);
	// START FROM HERE :)
	ll n;
	cin >> n;
	ll a[n];
	arrin(a, n, 0);
	ll sum[n];
	mem(sum, 0); sum[0] = a[0];
	FOR(i, 1, n) {
		sum[i] = sum[i - 1] + a[i];
	}
	ll ans = 0;
	FOR(i, 0, n) {
		ans += (a[i] % mod * ((sum[n - 1] % mod - sum[i] % mod + mod) % mod)) % mod;
	}
	cout << ans % mod << endl;

}

Measured memory_bytes: 6776
N=int(input())
A=list(map(int,input().split()))
B=[]
C=[]
for i in range(N):
  if i%2==0:
    B.append(A[i])
  else:
    C.append(A[i])
D=B[::-1]
E=C[::-1]
if N%2==0:
  print(*(E+B))
else:
  print(*(D+C))

Measured memory_bytes: 26356
import java.util.*;
public class Main {
 public static void main(String[] args){
	Scanner sc = new Scanner(System.in);
	int n=sc.nextInt();
	int[] r=new int[n];
	
	for(int i=1;i<=n;i++)r[sc.nextInt()-1]=i;
	for(int rr:r)System.out.print(rr+" ");
 }
}

Measured memory_bytes: 61708
#include <algorithm>
#include <complex>
#include <iostream>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>

using std::cin;
using std::cout;
using std::endl;
using std::cerr;

using std::string;
using std::to_string;
using std::vector;
using std::set;
using std::queue;
using std::stack;
using std::priority_queue;

using std::min;
using std::max;
using std::sort;
using std::abs;

typedef long long int ll;
const int MOD = 1e9 + 7;

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

    ll x, y;
    cin >> x >> y;
    for (ll i = 0; i < n - 1; i++) {
        ll t, a;
        cin >> t >> a;

        ll r = max((x + t - 1) / t, (y + a - 1) / a);
        x = t * r;
        y = a * r;
    }

    cout << (x + y) << endl;

    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define pie 3.141592653589793238462643383279
#define mod 1000000007
#define INF LLONG_MAX/5
#define all(v) v.begin(),v.end()
#define P pair<int,int>
#define S second
#define F first
#define f(i,n) for(int i=0;i<n;i++)
int mypow(int a,int b,int c){
	if(b==0)return 1;
	if(b%2)return mypow(a,b-1,c)*a%c;
	int z=mypow(a,b/2,c);
	return z*z%c;
}
signed main(){
	string s;
	int ans=0;
	cin>>s;
	f(i,(int)(s.size())/2){
		if(s[i]!=s[s.size()-1-i])ans++;
	}
	cout<<ans<<endl;
}


Measured memory_bytes: 256
#include <stdio.h>
int main(void)
{
	int L,M,N;
	int a,i,ii=13;
	
	while(scanf("%d",&L)&&L!=0){
		for(i=0;i<12;i++){
			scanf("%d%d",&M,&N);
			a=M-N;
			L-=a;
			if(L<=0&&ii>=i) ii=i;
		}
		if(L<=0){
			printf("%d\n",ii+1);
		} else {
			printf("NA\n");
		}
		ii=13;
	}
	return 0 ;
}

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

int main(){
  ll A, B, C, X, Y;
  cin >> A >> B >> C >> X >> Y;
  ll a,b,c;
  ll min = 10e16;
  for(c = 0; c <= 100000; c++){
    a = X - c;
    b = Y - c;
    if(a < 0) a = 0;
    if(b < 0) b = 0;
    if(a*A + b*B + 2*c*C < min) min = a*A + b*B + 2*c*C;
  }
  cout << min << endl;
}


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


def factors(n):
    i = 2
    factors = []
    while i * i <= n:
        if n % i:
            i += 1
        else:
            n //= i
            factors.append(i)
    if n > 1:
        factors.append(n)
    return factors


p = list(set(factors(N)))
ans = 0
e = 0
i = 0
for i in range(len(p)):
    e = 1
    while 1 < N:
        z = p[i] ** e
        if N % z == 0:
            N //= z
            ans += 1
        else:
            break
        e += 1
print(ans)


Measured memory_bytes: 9144
def main():
    N = int(input())
    V = list(map(int, input().split()))
    C = list(map(int, input().split()))
    K = [V[i] - C[i] for i in range(N)]
    ans = 0
    for k in K:
        if k > 0:
            ans += k
    print(ans)


if __name__ == "__main__":
    main()


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

#include <iostream>
#include <string>
#include <utility>
#include <vector>
#include <map>
#include <unordered_map>
#include <queue>
#include <algorithm>

#include <bits/stdc++.h>
#include <cmath>
#include <limits>

using namespace std;

#define MAX 200002
long long MOD = 1000000007;
long long MODPOW2[MAX] = {0};

void initModPow2(){
	MODPOW2[0] = 1;
	for(int i=1; i<MAX; i++){
		MODPOW2[i] = (MODPOW2[i-1]*2)%MOD;
	}
}

long long GCD(long long x, long long y){
        long long r=0;
        if(x < y) swap(x, y);
        r = x % y;
        while(r != 0){
                x = y;
                y = r;
                r = x % y;
        }
        return y;
}

// U(u個)とV(v個)が直交しているとき、どの2つも内積が0にならない選び方の数
// 余事象で考えて、2**(u+v)から内積が0になりうる選び方の数を引く
long long countUV(long long u, long long v){
	long long a=0, b=0, c=0, ret=0;
	a = MODPOW2[u+v] % MOD;
	b = (MODPOW2[u] - 1) % MOD;
	b = (b*(MODPOW2[v] - 1)) % MOD;
	ret = (a - b) % MOD;
	if(ret < 0) ret += MOD;
	return ret;
}

typedef std::pair<long long, long long> Tilt;
map<Tilt, long long> m1;

int main(int argc, char* argv[]){
	int N, M;
	long long zero = 0;

	cin >> N;

	initModPow2();
	long long ans=1; 
	for(int i=1; i<=N; i++){
		long long a, b;
		cin >> a >> b;

		if(a == 0 && b == 0){
			zero++;
			continue; //(0, 0)は除外するが、数えておく
		}
		if(a !=0 && b != 0){
			long long g = GCD(a, b);
			a = a / g;
			b = b / g;
			if(a < 0){
				a = 0 - a;
				b = 0 - b;
			}
		}
		if(a == 0){ b = 1; }
		if(b == 0){ a = 1; }
		Tilt t(a, b);
		if(m1.count(t)==0){
			m1[t] = 1;
		}
		else{
			long long v = m1[t];
			m1[t] = v+1;
		}
	}
	for(auto itr = m1.begin(); itr != m1.end(); itr++){
		long long x, y, u, v;
		Tilt t = itr->first;
		u = itr->second;
		if(u == -1) continue;
		x = t.first;
		y = t.second;
        if(y > 0){
			x = 0 - x;
			y = 0 - y;
		}
		Tilt w(0 - y, x); //法線ベクトル
		auto tmpitr2 = m1.find(w);
		if( tmpitr2 != m1.end()){
			v = m1[w];
			if(v == -1){ continue; }
			m1[w] = -1;
		}
		else{
			v = 0;
		}
		long long uvcnt = countUV(u, v);
		ans = (ans * uvcnt) % MOD;
		m1[t] = -1;
	}
	ans = ans + (zero % MOD) -1 ; //(0, 0)は他のどの要素とも直交するので足す。まったく選ばないを引く。
	ans = ans % MOD;
	if(ans < 0) ans += MOD;
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 17624
#include <iostream>
#include <sstream>
#include <vector>
using namespace std;

int main()
{
  vector<string> v;
  string str, s;

  getline(cin, str);
  stringstream ss{str};

  while( getline(ss, s, ' ') ) {
    v.push_back(s);
  }

  for(string tmp : v) {
    cout << tmp[0];
  }
  cout << endl;
  return(0);
}

Measured memory_bytes: 3620
n = int(input())
w = [input() for i in range(n)]
w_set = set()
w_set.add(w[0])

ans = 'Yes'
for i in range(1, n):
    if w[i-1][-1] != w[i][0] or w[i] in w_set:
        ans = 'No'
        break
    w_set.add(w[i])

print(ans)

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

const int Max=505;
int n,m,ans,num[Max][Max],a[1000000][5];

int main()
{
	scanf("%d%d",&n,&m);
	for(int i=1;i<=n;i++)
	  for(int j=1;j<=m;j++)
	    scanf("%d",&num[i][j]);
	for(int i=1;i<=n;i++)
	  for(int j=1;j<m;j++)
	    if(num[i][j]%2) num[i][j+1]++,ans++,a[ans][1]=i,a[ans][2]=j,a[ans][3]=i,a[ans][4]=j+1;
	for(int i=1;i<n;i++)
	  if(num[i][m]%2)
	    num[i+1][m]++,ans++,a[ans][1]=i,a[ans][2]=m,a[ans][3]=i+1,a[ans][4]=m;
	cout<<ans<<"\n";
	for(int i=1;i<=ans;i++) cout<<a[i][1]<<" "<<a[i][2]<<" "<<a[i][3]<<" "<<a[i][4]<<"\n";
	return 0;
}


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

#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define PN printf("\n")
#define MODV 1000000007

typedef long long ll;
typedef double dbl;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef pair<int, int> pi;
void addmod(int &a, ll b){a=(a+b); if(a>=MODV)a-=MODV;}
void mulmod(int &a, ll b){a=(a*b)%MODV;}
template<class T>bool domin(T &a, const T &b){return a>b?a=b,1:0;}
template<class T>bool domax(T &a, const T &b){return a<b?a=b,1:0;}
int gi(){int a;scanf("%d",&a);return a;}
ll gll(){ll a;scanf("%lld",&a);return a;}

#define MAXN 100005

int power(int a, int b) {
  int res = 1;
  while (b > 0) {
    if (b & 1) { mulmod(res, a); }
    b >>= 1;
    mulmod(a, a);
  }
  return res;
}

int inv(int a) { return power(a, MODV - 2); }

vi fact, invfact;
void calcfact(){
  static bool done=false;
  if(done)return;
  done=true;
  fact.resize(MAXN);
  invfact.resize(MAXN);
  fact[0]=invfact[0]=1;
  for(int i=1;i<MAXN;i++){
    fact[i]=fact[i-1];
    invfact[i]=invfact[i-1];
    mulmod(fact[i],i);
    mulmod(invfact[i],inv(i));
  }
}

int main() {
  ll n=gi(), m=gi();
  calcfact();
  if(n>m)swap(n,m);
  if(m>n+1)return cout<<0<<endl,0;
  int a;
  if(m==n+1){
    a=fact[m];
    mulmod(a,fact[n]);
  }else{
    a=fact[m];
    mulmod(a,a);
    mulmod(a,2);
  }
  cout<<a<<endl;

  return 0;
}

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

int main(){
    int n;
    cin >> n;
    vector<pair<int,int>> a(n);
    for(int i=0; i<n; i++){
        cin >> a[i].second >> a[i].first;
    }
    sort(a.begin(),a.end());
    ll sum=0;
    bool flag=true;
    for(int i=0; i<n; i++){
        sum+=a[i].second;
        if(sum>a[i].first){
            flag=false;
            break;
        }
    }
    if(flag)cout << "Yes";
    else cout << "No";
    cout << endl;
}

Measured memory_bytes: 1792
#include <iostream>
#include <string>
#include <map>
#include <queue>

using namespace std;

int main()
{
    string s;
    while (cin >> s, s[0] != '0') {
		map<string, bool> m;

		queue<string> q, r;

		q.push(s);

		int cnt = 0;

		while (q.size()) {
			while (q.size()) {
				string t = q.front(); q.pop();
				if (m[t]) continue;
				m[t] = true;
				bool f = true;
				for (int i = 0; i < t.size() - 1; ++i) {
					if ((t[i] == 'r' && t[i + 1] == 'b') || (t[i] == 'b' && t[i + 1] == 'r')) {
						char c = t[i], d = t[i + 1];
						t[i] = t[i + 1] = 'g';
						r.push(t);
						t[i] = c, t[i + 1] = d;
						f = false;
					} else if ((t[i] == 'b' && t[i + 1] == 'g') || (t[i] == 'g' && t[i + 1] == 'b')) {
						char c = t[i], d = t[i + 1];
						t[i] = t[i + 1] = 'r';
						r.push(t);
						t[i] = c, t[i + 1] = d;
						f = false;
					} else if ((t[i] == 'r' && t[i + 1] == 'g') || (t[i] == 'g' && t[i + 1] == 'r')) {
						char c = t[i], d = t[i + 1];
						t[i] = t[i + 1] = 'b';
						r.push(t);
						t[i] = c, t[i + 1] = d;
						f = false;
					}
				}
				if (f) {
                    cout << cnt << endl;
					goto nxt;
				}
			}
			while (r.size()) {
				string t = r.front(); r.pop();
				q.push(t);
			}
			cnt++;
		}

        cout << "NA" << endl;
nxt:;
	}
}

Measured memory_bytes: 3316
#include <iostream>
#include <algorithm>
#include <cmath>
#include <deque>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <vector>

using namespace std;

#define ALL(x) (x).begin(), (x).end()
#define FOR(i,a,b) for (int i=(int)(a);i<(int)(b);++i)
#define FORE(i,a,b) for (int i=(int)(a);i<=(int)(b);++i)
#define REP(i,n) FOR(i,0,n)
#define REPE(i,n) FOR(i,0,n)

typedef long long ll;
typedef pair<ll, ll> P;

int main() {
  string S; cin >> S;
  int N = S.size();
  const ll MOD = 1000000007;

  vector<ll> ans(13);
  fill(ALL(ans), 0);

  if (S[0] == '?') {
    REP(i,10) ans[i] = 1;
  } else {
    ans[S[0]-'0'] = 1;
  }

  FOR(i,1,N) {
    vector<ll> prev_ans(13);
    fill(ALL(prev_ans), 0);
    swap(prev_ans, ans);

    if (S[i] == '?') {
      REP(j,10) {
        REP(k,13) {
          int next_idx = (k*10+j) % 13;
          ans[next_idx] += prev_ans[k] % MOD;
          ans[next_idx] %= MOD;
        }
      }
    } else {
      REP(j,13) {
        int next_idx = (j*10+(S[i]-'0')) % 13;
        ans[next_idx] += prev_ans[j] % MOD;
        ans[next_idx] %= MOD;
      }
    }
  }
  cout << ans[5];

  return 0;
}

Measured memory_bytes: 512
from sys import stdin
import math
import re
import queue

input = stdin.readline

MOD = 1000000007
INF = 122337203685477580

def solve():
    vec = [0]*4
    for x in range(3):
        A,B = map(int, input().split())
        A -= 1
        B -=1
        vec[A] += 1
        vec[B] += 1
    
    if(vec[0] == 1 and vec[1] == 2 and vec[2] == 2 and vec[3] == 1):
        print("YES")
    else:
        print("NO")



if __name__ == '__main__':
    solve()


Measured memory_bytes: 3948
#include<bits/stdc++.h>
using namespace std;
pair<long long, long long> gainClosestFactor(long long n)
{
	long long i;
	long long integral_part = (long long)sqrt(n);
	if(n % integral_part == 0)
		return make_pair(integral_part, n / integral_part);
	else
	{
		int flag;
		int low = pow(integral_part, 2);
		int high = pow(integral_part + 1, 2);
		if((n - low) >= (high - n))
			flag = integral_part + 1;
		else
			flag = integral_part;
		for(i = flag - 1; i > 0; i--)
		{
			if(n % i == 0)
				break;
		}
		return make_pair(i, n / i);
	}
}
int main()
{
	long long a;cin>>a;
	pair<long long, long long> gn;
    gn = gainClosestFactor(a);
		cout << gn.first+gn.second-2<< endl;

	return 0;
}


Measured memory_bytes: 256
def solve(n):
    alphabet = "abcdefghijklmnopqrstuvwxyz"
    s_list = []
    m = n
    while m > 0:
        m = m - 1
        s_list.append(alphabet[m % 26])
        m = m // 26
    return "".join(reversed(s_list))


def main():
    n = int(input())
    res = solve(n)
    print(res)


def test():
    assert solve(2) == "b"
    assert solve(27) == "aa"
    assert solve(123456789) == "jjddja"


if __name__ == "__main__":
    test()
    main()


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

#define SZ(a) (int)a.size()
#define PB push_back
//#define cerr if(false)cerr
#define print(x) cerr<<"\n" << (#x) << " is " << (x) << endl;

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

typedef vector<int> vi;
typedef vector<ll> vll;

const int MAXN = 1000007;
const int INF = 1000303;
const int MOD = 1e9+7;

int main(){
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	int n, r;
	cin >> n >> r;
	if(n < 10){
		cout << r + (10-n)*100 << endl;
	}
	else cout << r << endl;
}


Measured memory_bytes: 256
n = int(input())
count = 0
room = [int(0) for i in range(4) for j in range(3) for k in range(10)]
while count < n:
    x = list(map(lambda k: int(k), input().split(" ")))
    room[(x[0]-1)*30+(x[1]-1)*10+(x[2]-1)] += x[3]
    count += 1
for i in range(4):
    if i != 0:
        print("####################")
    for j in range(3):
        for k in range(10):
            print(" %d" % room[30*i+10*j+k], end="")
        print("")

Measured memory_bytes: 6724
import sys

N = int(input())
info = []
for i in range(N):
    xi, yi, hi = map(int, input().split())
    info.append((xi, yi, hi))   

answer = (-1, -1, -1)
for cx in range(101):
    for cy in range(101):
        candidate = -1
        counter = 0
        for i in info:
            if i[2] != 0:
                H = i[2] + abs(i[0] - cx) + abs(i[1] - cy)
                counter += 1
                if candidate == -1:
                    candidate = H
                elif candidate != H:
                    candidate = -1
                    break
        if counter == 1:
            for i in info:
                if i[2] == 1:
                    answer = (i[0], i[1], i[2])
            break        
        elif candidate > 0:
            answer = (cx, cy, candidate)
            break
    if answer[2] > 0:
        break


print(answer[0], answer[1], answer[2])


Measured memory_bytes: 3064
N=input()
l=len(N)
N=int(N)
if l<3:
    print(0)
else:
    
    cands=[None]*(l+1)
    cands[0]={}
    cands[1]={}
    cands[2]={}
    cands[3]= {"357","375","537","573","735","753"}
    
    for i in range(3,l):
        cands[i+1] = set(s+c for c in cands[i] for s in ["3","5","7"]) | set(c+s for c in cands[i] for s in ["3","5","7"] )
        cands[i+1].add("3"+"5"*(i-1)+"7")
        cands[i+1].add("3"+"7"*(i-1)+"5")
        cands[i+1].add("5"+"3"*(i-1)+"7")
        cands[i+1].add("5"+"7"*(i-1)+"3")
        cands[i+1].add("7"+"3"*(i-1)+"5")
        cands[i+1].add("7"+"5"*(i-1)+"3")
    
    ans=sum( [len(cands[i]) for i in range(l)] )
    ans+=sum( int(c)<=N for c in cands[l])
    print(ans)

Measured memory_bytes: 75144
#include <stdio.h>

int main(void)
{
  int S;
  int h, m, s;
  scanf("%d", &S);
  h = S / 3600;
  m = (S % 3600) / 60;
  s = S % 60;
  //m = (S - h * 3600) / 60;
  //s = S - h * 3600 - m * 60;
  printf("%d:%d:%d\n", h, m, s);

  return 0;
}

Measured memory_bytes: 592
#include <bits/stdc++.h>
    using namespace std;
     
    int main()
    {
        int N;
        int sum = 0;
        bitset < 4000005 > bt;
        bt |= 1;
        cin >> N;
        for(int i = 0; i < N; i++) {
            int A;
            cin >> A;
            sum += A;
            bt |= (bt << A);
        }
        for(int i = (sum + 1) / 2; i < 2000005; i++) {
            if(bt[i]) {
                cout << i << endl;
                break;
            }
        }
        return (0);
    }

Measured memory_bytes: 1664
n = int(input())

for i in range(1, n + 1):
    if i % 3 == 0:
        print("", i, end = "")
        continue
    x = i
    while x != 0:
        if x % 10 == 3:
            print("", i , end = "")
            break
        x //= 10
print()


Measured memory_bytes: 6164
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.StringTokenizer;

public class Main {
 //Fast Reader
     private static class FastReader {
         BufferedReader br;
         StringTokenizer st;

         public FastReader() {
             br = new BufferedReader(new InputStreamReader(System.in));
         }

         public String next() {
             while (st == null || !st.hasMoreElements()) {
                 try {
                     st = new StringTokenizer(br.readLine());
                 } catch (IOException e) {
                     e.printStackTrace();
                 }
             }
             return st.nextToken();
         }

         public void resetST() {
             st = null;
         }

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

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

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

         public float nextFloat() {
             return Float.parseFloat(next());
         }

         public String nextLine() {
             String str = "";
             try {
                 str = br.readLine();
             } catch (IOException e) {
                 e.printStackTrace();
             }
             st = null;
             return str;
         }

         public int[] nextIntArray(int size) {
             int[] arr = new int[size];
             for (int i = 0; i < size; i++) {
                 arr[i] = nextInt();
             }
             return arr;
         }

         public long[] nextLongArray(int size) {
             long[] arr = new long[size];
             for (int i = 0; i < size; i++) {
                 arr[i] = nextLong();
             }
             return arr;
         }

         public double[] nextDoubleArray(int size) {
             double[] arr = new double[size];
             for (int i = 0; i < size; i++) {
                 arr[i] = nextDouble();
             }
             return arr;
         }
     }
    public static void main(String[] args) {
         FastReader sc =new FastReader();
         PrintWriter pr = new PrintWriter(System.out);
         int t =sc.nextInt();
         if(t<30)
             pr.println("No");
         else
             pr.println("Yes");
         pr.close();
	// write your code here
    }
}


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

int main() {
	int n,a,b,c,d;cin>>n>>a>>b>>c>>d;
	int Min=INT_MAX;
	for(int w=1;w<=n;w++){
		int ax=(a-1)/w,ay=(a-1)%w;
		int bx=(b-1)/w,by=(b-1)%w;
		int cx=(c-1)/w,cy=(c-1)%w;
		int dx=(d-1)/w,dy=(d-1)%w;
		Min=min(Min,abs(ax-bx)+abs(ay-by)+abs(cx-dx)+abs(cy-dy));
	}
	cout<<Min<<endl;
}

Measured memory_bytes: 3092
#include<iostream>
#include<algorithm>
using namespace std;
signed main()
{
  int a,b;
  cin>>a>>b;
  if(a<b){
    cout<<"a < b\n";
  }
  if(a>b){
    cout<<"a > b\n";
  }
  if(a==b){
    cout<<"a == b\n";
  }
  return(0);
}



Measured memory_bytes: 3084
#include<bits/stdc++.h>
//#include<atcoder/all>
using namespace std;
//using namespace atcoder;
#define rep(i,n) for(int i=0;i<n;i++)
#define rep1(i,n) for(int i=1;i<=n;i++)
#define per(i,n) for(int i=n-1;i>=0;i--)
#define per1(i,n) for(int i=n;i>0;i--)
#define all(v) v.begin(), v.end()
typedef long long ll;
typedef pair<ll,ll> P;
typedef vector<ll> vec;
typedef vector<vec> mat;
int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    ll n,x,m;
    cin>>n>>x>>m;
    ll ans=0,a=x,l,c,r;
    vec num(m,0);
    if(n<m+1){
        rep(i,n) ans+=a,a=a*a%m;
        cout<<ans;
        return 0;
    }
    rep(i,m+1){
        if(num[a]==0) num[a]++;
        else{
            r=i,c=a;
            break;
        }
        ans+=a,a=a*a%m;
    }
    ll sum=0;
    a=x;
    rep(i,m+1){
        if(a==c){
            l=i;
            break;
        }
        sum+=a,a=a*a%m;
    }
    ll s=r-l,p=ans-sum;
    ll nn=n-l;
    sum+=nn/s*p;
    nn%=s;
    a=c;
    rep(i,nn) sum+=a,a=a*a%m;
    cout<<sum;
}

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

int main(){
    int n;
    cin >> n;
    vector<int> a(n);
    for (int i = 0; i < n; i++) {
        cin >> a[i];
    }
    for (int i = 0; i < n; i++) {
        if (i == n-1) {
            cout << a[i] << endl;
        }
        else cout << a[i] << " ";
    }
    for (int i = 1; i < n; i++) {
        int v = a[i];
        int j = i - 1;
        while (j >= 0 && a[j] > v) {
            a[j+1] = a[j];
            j--;
        }
        a[j+1] = v;
        for (int k = 0; k < n; k++) {
            if (k == n-1) {
                cout << a[k] << endl;
            }
            else cout << a[k] << " ";
        }
    }
}



Measured memory_bytes: 3116
import Data.List
import Data.Tuple
import qualified Data.ByteString.Char8 as BS
main = do
  [n,m] <- map read . words <$> getLine :: IO [Int]
  xs <- map (\[a,b] -> (a,b)) . map (map (read . BS.unpack) . BS.words) . BS.lines <$> BS.getContents :: IO [(Int,Int)]
  print $ step n (xs ++ map swap xs) 1 []

step :: Int -> [(Int,Int)] -> Int -> [Int] -> Int
step n path dest arrived =
  let 
    ns = map snd $ filter (\(a,_) -> a==dest) path
  in
    if sort (dest:arrived) == [1..n] 
       then 1
    else if dest `elem` arrived 
       then 0
    else
       sum $ [r | next<-ns, let r = step n path next (dest:arrived)]


Measured memory_bytes: 1020
#include <iostream>
#include <string>
#include <vector>
#include <utility>
#include <functional>
#include <numeric>
#include <list>
#include <set>
#include <map>
#include <algorithm>
#include <cmath>
#include <limits>
#include <iomanip>
#include <bitset>
#include <queue>

using namespace std;
typedef long long ll;

template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
#define rep(i, n) for(int i = 0;i < n;i++)
const long long INF = 1LL << 60;

int MOD = 1000000007;

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

     string s; cin >> s;
     int ans = 0;

     for(int i=1; i<s.size(); i++){
         if(s[i]!=s[i-1]) ans++;
     }
     cout << ans << endl;

    return 0;
}


Measured memory_bytes: 512
#include<stdio.h>

static const int N = 1000;

void trace(int A[], int n){
  int i;
  for ( i = 1; i <= n; i++ ){
    if ( i > 1 ) printf(" ");
    printf("%d", A[i]);
  }
  printf("\n");
}

int main(){
  int n, i, j,v;
  int A[N+1];
  scanf("%d", &n);

  for ( i = 1; i <= n; i++ ) scanf("%d", &A[i]);
  
  

  for(i=1;i<=n;i++){
    v = A[i];
    j = i-1;
    while( (0<=j) && (A[j]>v) ){
      A[j+1] = A[j];
      j--;
      A[j+1] = v;
    }trace(A, n);
  }
  
  return 0;
}


  
 
 




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

const int DIM = 200005;

char str1[DIM], str2[DIM];

inline int gcd(int x, int y) {
	return !y ? x : gcd(y, x % y); }

int main(void) {
	int n, m; cin >> n >> m;
	cin >> str1 >> str2;
	long long l = 1LL * n * m / gcd(n, m);
	for (int i = 0; i < n; ++i) {
		if (1LL * i * m % n == 0 and str1[i] != str2[1LL * i * m / n]) {
			cout << -1; return 0; } }
	cout << l;
	return 0; }


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

double PI = acos(-1);
int main(){
  cout << setprecision(10) << fixed;
  while(1){
    int n; 
    cin >> n;
    if(n == 0)break;
    vector<int> s(n);
    for(int i = 0; i < n; i++)cin >> s[i];
    int sum = 0;
    for(int i = 0; i < n; i++)sum += s[i];
    double ave = double(sum) / n;
    double var = 0;
    for(int i = 0; i < n; i++)var  += pow(s[i] - ave, 2);
    var /= n;
    cout << sqrt(var) << endl;
  }
}


Measured memory_bytes: 3300
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
using vl = vector<ll>;
template<class T> using vc = vector<T>;
template<class T> using vvc = vector<vector<T>>;

#define eb emplace_back
#define all(x) (x).begin(), (x).end()
#define rep(i, n) for (ll i = 0; i < (n); i++)
#define repr(i, n) for (ll i = (n)-1; i >= 0; i--)
#define repe(i, l, r) for (ll i = (l); i < (r); i++)
#define reper(i, l, r) for (ll i = (r)-1; i >= (l); i--)
#define repa(i,n) for (auto& i: n)

template<class T> inline bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T> inline bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
void init() {cin.tie(0);ios::sync_with_stdio(false);cout << fixed << setprecision(15);}

#ifdef DEBUG
template <class T, class N> void verr(const T& a, const N& n) { rep(i, n) cerr << a[i] << " "; cerr << "\n" << flush; }
ll dbgt = 1; void err() { cerr << "passed " << dbgt++ << "\n" << flush; }
template<class H, class... T> void err(H&& h,T&&... t){ cerr<< h << (sizeof...(t)?" ":"\n") << flush; if(sizeof...(t)>0) err(forward<T>(t)...); }
#endif

const ll INF = 4e18;
const ld EPS = 1e-11;
const ld PI = acos(-1.0L);
const ll MOD = 1e9 + 7;
// const ll MOD = 998244353;
//--------------------------------------------------------------------------------//
ll partition(vc<pair<ll,char>>& A, ll p, ll r){
    ll x = A[r].first;
    ll si = p - 1;
    repe(i, p, r){
        if(A[i].first<=x){
            si++;
            swap(A[i], A[si]);
        }
    }
    swap(A[si + 1], A[r]);
    return si + 1;
}

void quickSort(vc<pair<ll,char>>& A, ll p, ll r){
    if(p<r){
        ll q = partition(A, p, r);
        quickSort(A, p, q - 1);
        quickSort(A, q + 1, r);
    }
}

int main() {
    init();
    ll N;
    cin >> N;
    vc<pair<ll,char>> A(N), B;
    rep(i, N) cin >> A[i].second >> A[i].first;

    B = A;
    stable_sort(all(B), [](pair<ll, char> p1, pair<ll, char> p2) { return p1.first < p2.first; });

    quickSort(A, 0, N - 1);

    cout << (A == B ? "Stable" : "Not stable") << '\n';
    rep(i, N) cout << A[i].second << " " << A[i].first << '\n';
}


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

#define REP(i, n) for (ll (i) = 0 ; (i) < (ll)(n) ; ++(i))
#define REPN(i, m, n) for (ll (i) = m ; (i) < (ll)(n) ; ++(i))
#define REP_REV(i, n) for (ll (i) = (ll)(n) - 1 ; (i) >= 0 ; --(i))
#define REPN_REV(i, m, n) for (ll (i) = (ll)(n) - 1 ; (i) >= m ; --(i))

#define INF 2e9
#define INF_LL 1LL<<60
#define ll long long

#define MAX_V 105

typedef pair<int, int> P; 


int main(){
    string s;
    cin >> s;
    int top_per = 0, top_guu = 0;
    int possible_per = s.length() / 2;

    REP(i, s.length()) {
        if(s[i] == 'g') {
            top_guu++;
        } else {
            top_per++;
        }
    }

    cout << possible_per - top_per;

    return 0;
}


Measured memory_bytes: 512
#include <bits/stdc++.h>
#define INF 2147483647
#define INF_LL 9223372036854775807
using namespace std;
typedef long long int ll;
typedef unsigned long long int ull;

int main() {
	int r, g, b;
	cin >> r >> g >> b;
	if ((100 * r + 10 * g + b) % 4 == 0)cout << "YES" << endl;
	else cout << "NO" << endl;
	return 0;
}

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

int main()
{
    int W, H, N;
    int arr[1000][3];
    cin >> W >> H >> N;
    for (int i = 0; i < N; i++) {
        for (int j = 0; j < 3; j++) {
            cin >> arr[i][j];
        }
    }

    int map[H + 1][W + 1];
    memset(map, 0, sizeof(map));

    for (int i = 0; i < N; i++) {
        if (arr[i][2] == 1) {
            for (int k = 1; k <= H; k++) {
                for (int l = 1; l <= arr[i][0]; l++) {
                    map[k][l] = 1;
                }
            }
        } else if (arr[i][2] == 2) {
            for (int k = 1; k <= H; k++) {
                for (int l = arr[i][0] + 1; l <= W; l++) {
                    map[k][l] = 1;
                }
            }
        } else if (arr[i][2] == 3) {
            for (int k = 1; k <= arr[i][1]; k++) {
                for (int l = 1; l <= W; l++) {
                    map[k][l] = 1;
                }
            }
        } else if (arr[i][2] == 4) {
            for (int k = arr[i][1] + 1; k <= H; k++) {
                for (int l = 1; l <= W; l++) {
                    map[k][l] = 1;
                }
            }
        }
    }

    int counter = 0;
    for (int i = 1; i <= H; i++) {
        for (int j = 1; j <= W; j++) {
            if (map[i][j] == 0) {
                counter++;
            }
        }
    }

    cout << counter << endl;

    return 0;
}


Measured memory_bytes: 384
#include <bits/stdc++.h>
#define ALL(v) v.begin(), v.end()
#define RALL(a) (a).rbegin(), (a).rend()
#define SORT(c) sort((c).begin(),(c).end())
#define dbug(x) cout<<#x<<"="<<x<<endl
#define m0(x) memset(x,0,sizeof(x))
#define rep(i, n) for(int i = 0; i < n; i++)
#define repr(i, n) for(int i = n; i >= 0; i--)
#define reps(i, m, n) for(int i = m; i < n; i++)
#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))

using namespace std;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef pair<int, int> pii;
typedef vector<pii> VP;
typedef long long ll;
typedef pair<ll, ll> pl;

template<typename T>
istream& operator >> (istream& is, vector<T>& vec){
  for(T& x: vec) is >> x;
  return is;
}

int main(){

  int N,K,X,Y;
  cin >> N>> K>>X>>Y;
  int sum;

  if(N<K){
    sum=N*X;
  }
  else{
    sum=K*X+(N-K)*Y;
  }

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


Measured memory_bytes: 256
#include <bits/stdc++.h>
typedef long long ll;
using namespace std;
int main(){
    ios_base:: sync_with_stdio(false);
    cin.tie(NULL); cout.tie(NULL);
    ll n;cin>>n;
    ll a[n];for(ll i=0;i<n;i++)cin>>a[i];
    ll ans = 0;
    for(ll i=0;i<n;i++){
        ll j=i;
        while(j<n && a[j]==a[i])j++;
        ans+=(j-i)/2;
        i=j-1;
    }
    cout<<ans;
}




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

using namespace std;

const int MOD = 1000000007;

int main() {
    long long N;
    cin>>N;
    long long A[N];
    long long sum=0;
    for(int i=0;i<N;i++){
        cin>>A[i];
        sum+=A[i];
    }
    long long B[N];
    B[0]=A[0];
    for(int i=1;i<N;i++){
        B[i]=A[i]+B[i-1];

    }
    long long minn=9223372036854775806;
    for(int i=0;i<N-1;i++){
        if(minn>abs(sum-2*B[i])){
            minn=abs(sum-2*B[i]);
        }


    }
    cout<<minn<<endl;





}

Measured memory_bytes: 3328
import sys
sys.setrecursionlimit(2147483647)
INF=float("inf")
MOD=10**9+7
input=lambda :sys.stdin.readline().rstrip()
def bisection(l,r,f,discrete=True,left=True):
    eps=1 if discrete else 10**-12
    if((not left)^f(r)): return r if left else r+1
    elif(left^f(l)): return l-1 if left else l
    while(r-l>eps):
        h=(l+r)//2 if discrete else (l+r)/2
        if((not left)^f(h)): l=h
        else: r=h
    return h if not discrete else l if left else r

def resolve():
    from collections import Counter
    from bisect import bisect_left
    n=int(input())
    A=Counter(map(int,input().split()))
    A=list(A.values())
    A.sort()
    m=len(A)
    S=[0]*(m+1)# cumulative distribution
    for i in range(m):
        S[i+1]=S[i]+A[i]
    for k in range(1,n+1):
        def check(p):
            i=bisect_left(A,p)
            return S[i]+(m-i)*p>=k*p
        print(bisection(0,n//k+1,check))
resolve()

Measured memory_bytes: 120108
from itertools import permutations

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

for i, can in enumerate(permutations(range(1, n+1))):
    if p == can:
        x = i
    if q == can:
        y = i
print(abs(x - y))

Measured memory_bytes: 3060
#include<iostream>
    #include<stdio.h>
    //#include <bits/stdc++.h>
    #include<vector>
    #include<float.h>
    #include<iomanip>
    #include<algorithm>
    #include<string>
    #include<cstring>
    #include<math.h>
    #include<cmath>
    #include<sstream>
    #include<set>
    #include<map>
    #include<queue>
    #include<cassert>
    #include<cmath>
    #include<cstdint>
     
    #define INF 1e9
    #define rep(i,n)for(int i=0;(i)<(int)(n);i++)
    #define REP(i,a,b)for(int i=(int)(a);(i)<=(int)(b);i++)
    #define VEC(type, c, n) std::vector<type> c(n);for(auto& i:c)std::cin>>i;
    #define vec(type,n) vector<type>(n)
    #define vvec(m,n) vector<vector<int>> (int(m),vector<int>(n))
    #define ALL(a)  (a).begin(),(a).end()
    #define chmin(a, b) a = min(a, b)
    #define chmax(a, b) a = max(a, b)
     
    using namespace std;
    using ll = long long;
    using Graph = vector<vector<int>>;
    using P = pair<ll, ll>;
     
const int MOD = 1e9 + 7;



int main(){
   int n;
   cin >> n;
   vector<int> p(n);
   rep(i, n)cin >> p[i];
   ll res = 1000, now = p[0];
   rep(i, n){
      if(now < p[i]){
         res = (res / now) * p[i] + (res % now);
      }
      now = p[i];
   }
   cout << res << endl;
}


Measured memory_bytes: 3636