akhauriyash/Code-Regression huggingface dataset:
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cmath>
#include<string>
#include<cstring>
#include<ctime>
#include<cstdlib>
#include<set>
#define ll long long
using namespace std;
set<ll> s;
string op;
ll f[12345678];
ll n,m,ans,x;
int main()
{
//	freopen("test.in","r",stdin);
//	freopen("test.out","w",stdout);
	cin>>n>>m;
	for(ll i=1;i<=m;++i)
	{
		cin>>x>>op;
		if(op=="AC") s.insert(x);
		else if(!s.count(x)) ++f[x];
	}
	for(ll i=1;i<=n;++i) if(s.count(i)) ans+=f[i];
	cout<<s.size()<<" "<<ans;
	return 0;
}


Measured memory_bytes: 4992
#include <bits/stdc++.h>
using namespace std;
#define x first
#define y second
#define dbg(x) cout << #x << '=' << x << '\n';
#define ll long long
#define pi pair<int,int>
#define pl pair<ll,ll>
#define pd pair<double,double>
#define ld long double
#define pld pair<ld,ld>
#define lg length()
#define sz size()
#define pb push_back
#define MAXN 100005
#define INF 1000000005
#define LINF 1000000000000000005
#define x1 xdddddddddddddddddd
#define y1 ydddddddddddddddddd

int n,a[100005],q,l,r;

bool p(int n){
    if(n==1) return 0;
    int s=sqrt(n);
    for(int i=2;i<=s;i++){
        if(n%i==0) return 0;
    }
    return 1;
}

int32_t main(){
    ios_base :: sync_with_stdio(0); cin.tie(); cout.tie();
    for(int i=1;i<=100000;i++){
        a[i]=a[i-1];
        if(i%2==0) continue;
        if(p(i) && p((i+1)/2)) a[i]++;
    }
    cin >> q;
    for(int i=1;i<=q;i++){
        cin >> l >> r;
        cout << a[r]-a[l-1] << '\n';
    }
}


Measured memory_bytes: 1024
package main

import (
	"fmt"
)

func main() {
	var n int
	fmt.Scan(&n)
	g := make([][]int, n)
	for i := 0; i < n; i++ {
		g[i] = make([]int, n)
	}

	for i := 0; i < n; i++ {
		var u,k int
		fmt.Scan(&u)
		fmt.Scan(&k)
		for j := 0; j < k; j++ {
			var v int
			fmt.Scan(&v)
			g[u-1][v-1] = 1
		}
	}

	for i := 0; i < n; i++ {
		fmt.Print(g[i][0])
		for j := 1; j < n; j++ {
			fmt.Printf(" %d", g[i][j])
		}
		fmt.Println()
	}
}



Measured memory_bytes: 1252
#include <iostream>
#include <string>
#include <cstring>
#include <algorithm>
#include <functional>
#include <cmath>
#include <set>
#include <queue>
#include <deque>
#include <vector>
#include <climits>
#include <sstream>
#include <iomanip>
#include <map>
#include <stack>
using namespace std;
typedef unsigned long long ull;
typedef long long ll;

void func(ll x, vector<ll>& list)
{
	for (auto i = 40; i >= 0; --i)
	{
		auto bit = 1ll << i;
		if (bit > x)
		{
			continue;
		}

		auto bit2 = 1ll << (i + 1);
		list[i] = x / bit2 * bit;
		list[i] += max(x % bit2 - bit + 1, 0ll);
	}
};


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

	vector<ll> list(41);
	vector<ll> list2(41);
	func(B, list);
	func(A - 1, list2);

	auto ans = 0ll;
	for (auto i = 0; i <= 40; ++i)
	{
		if ((list[i] - list2[i]) % 2 > 0)
		{
			ans |= 1ll << i;
		}
	}

	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 256
#include<cstdio>
#include<algorithm>
#include<cstring>
using namespace std;
int gi(){
	int x=0,w=1;char ch=getchar();
	while((ch<'0'||ch>'9')&&ch!='-')ch=getchar();
	if(ch=='-')w=0,ch=getchar();
	while(ch>='0'&&ch<='9')x=(x<<3)+(x<<1)+ch-'0',ch=getchar();
	return w?x:-x;
}
const int N=2e5+5;
const int mod=1e9+7;
int n,f[N],lst[N];
int main(){
	n=gi();f[0]=1;
	for(int i=1;i<=n;++i){
		int a=gi();
		f[i]=f[i-1];
		if(lst[a]&&lst[a]<i-1)f[i]=(f[i]+f[lst[a]])%mod;
		lst[a]=i;
	}
	printf("%d\n",f[n]);return 0;
}


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

int main(){
    long long n,blue,red;
    cin >> n >> blue >> red;
    /**/
    long long rest = n%(blue + red);
    long long count = (n - rest)/(blue + red);
    long long ans = blue*count + min(rest,blue);
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll,ll> P;
#define rep(i,n) for(int i=0;i<(int)n;i++)
const ll INF=(1LL<<61)-1;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

ll dp[3030][3030][5];

int main(){
    ll R,C,K; cin >> R >> C >> K;
    vector<vector<ll> > vv(R+1,vector<ll>(C+1));
    rep(i,K){
        int r,c,v; cin >> r >> c >> v;
        
        vv[r][c] = v;
    }

    memset(dp,0,sizeof(dp));
    for(int r=1;r<=R;r++){
        for(int c=1;c<=C;c++){
            // 前の行からの遷移
            rep(i,4)rep(j,4)chmax(dp[r][c][i],dp[r-1][c][j]);
            // 前の列からの遷移
            rep(i,4) chmax(dp[r][c][i],dp[r][c-1][i]);
            // 現在位置のアイテムを取った時
            for(int i=3;i>=1;i--) chmax(dp[r][c][i], dp[r][c][i-1]+vv[r][c]); 
            for(int i=1;i<=3;i++) chmax(dp[r][c][i],dp[r][c-1][i-1]+vv[r][c]);
            
        }
    }

    cout << dp[R][C][3] << endl;   
}

Measured memory_bytes: 432212
S = input()
T = input()
c2pos=dict()
s_c2pos = dict()

for ix, c in enumerate(S):
    if s_c2pos.get(c) == None:
        s_c2pos[c] = [ix]
    else:
        s_c2pos[c].append(ix)

for ix, c in enumerate(T):
    if c2pos.get(c) == None:
        c2pos[c] = [ix]
    else:
        c2pos[c].append(ix)

res = "Yes"

for k, v in c2pos.items():
    if len(v) < 1:
        continue

    if len(set([S[_v] for _v in v])) != 1:
        res = "No"

    if s_c2pos[S[v[0]]] != v:
        res = "No"
    
print(res)


Measured memory_bytes: 22196
from bisect import bisect_right

N = int(input())
X = [int(input()) for _ in range(N)]

INF = 10 ** 9 + 7
dp = [INF] * (N + 1)
for i in range(N):
    dp[bisect_right(dp, -X[i])] = -X[i]

print(sum(v < INF for v in dp))


Measured memory_bytes: 81620
#include <iostream>
#include <cmath>
#include<math.h>
#include<string.h>
#include<stdio.h>
using namespace std;

int main()
{

  int n,c1=0,c2=0;
  cin>>n;
  int ar[n];

  for(int i=0;i<n;i++)
  {
      cin>>ar[i];
  }

  for(int i =0;i<n-1;i++)
  {

          if(ar[i]>=ar[i+1])
            c1++;


            if(c1>c2)
                c2=c1;

          if(ar[i]<ar[i+1])
             {


                     c1=0;


             }




  }

  cout<<c2<<"\n";
    return 0;
}


Measured memory_bytes: 640
import java.util.Scanner;


public class Main {
	static int N;
	static long[] T;

	public static void main(String[] args) {

		Scanner sc = new Scanner(System.in);
		 N = sc.nextInt();
		 T = new long[N];
		 for(int i = 0 ; i < N ; i++){
			 T[i]= sc.nextInt();
		 }
		 sc.close();


		 int count = 0 ;
		 int counti = 0 ;


		 for (long m : T){
			 //System.out.println("calc : " + m);
			 count += counti;
			 //System.out.println("count :"+count);

			 for(int i = 1; i < 35 ; i++){
				 long p = (long)Math.pow(2, i);

				 if(m%p==0){
					 counti = i;
					// System.out.println("counti : "+counti);
				 }
				 else if(m%2 !=0){
					 counti = 0 ;
					 break;
				 }


				 else {
					 break;
				 }
			 }
		}
		 count += counti;
		 System.out.println(count);
	}
}

Measured memory_bytes: 35152
#ifdef _MSC_VER
#define _CRT_SECURE_NO_WARNINGS
#  include <intrin.h>
#  define __builtin_popcount __popcnt
#endif

#define _USE_MATH_DEFINES

#include <stdio.h>
#include <iostream>
#include <vector>
#include <unordered_map>
#include <stack>
#include <list>
#include <math.h>
#include <map>
#include <iomanip>
#include <functional>
#include <string>
#include <algorithm>
#include <queue>
#include <set>

using namespace std;

template<class T> ostream& operator<<(ostream& os, const vector<T>& v) {
	for (auto i = begin(v); i != end(v); i++) os << *i << (i == end(v) - 1 ? "" : " "); return os;
}
template<class T> istream& operator>>(istream& is, vector<T>& v) {
	for (auto i = begin(v); i != end(v); i++) is >> *i; return is;
}


int main() {

#if defined(_DEBUG) 
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#endif

	ios_base::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);

	int n;
	cin >> n;

	vector<int> vec(3 * n);
	for (int i = 0; i < 3 * n; i++)
	{
		cin >> vec[i];
	}

	vector<long long> left_sum(3 * n), right_sum(3 * n);
	multiset<int> tmp;
	long long curr = 0;
	for (int i = 0; i < n; i++)
	{
		curr += vec[i];
		tmp.insert(vec[i]);
	}
	left_sum[n - 1] = curr;

	for (int i = n; i < 2 * n; i++)
	{
		curr += vec[i];
		tmp.insert(vec[i]);
		int x = *tmp.begin();
		curr -= x;
		tmp.erase(tmp.find(x));
		left_sum[i] = curr;
	}

	curr = 0; tmp.clear();
	for (int i = 2 * n; i < 3 * n; i++)
	{
		curr += vec[i];
		tmp.insert(vec[i]);
	}
	right_sum[2 * n] = curr;
	for (int i = 2 * n - 1; i >= n; i--)
	{
		curr += vec[i];
		tmp.insert(vec[i]);
		int x = *tmp.rbegin();
		curr -= x;
		tmp.erase(tmp.find(x));
		right_sum[i] = curr;
	}

	long long best = -1e18;
	for (int i = n - 1; i < 2 * n; i++)
	{
		best = max(best, left_sum[i] - right_sum[i + 1]);
	}

	cout << best;

	return 0;
}


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

// エイリアス
using  ll = long signed long;
using ull = long unsigned long;
using  ld = long double;
using   P = pair<int, int>;
using llP = pair<ll, ll>;
using DoP = pair<double, double>;

// 汎用マクロ
#define ALL(a) (a).begin(), (a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define rep(i, n) for (int i = 0; i < n; ++i)
#define FOREACH(i,q) for (auto &i : q)
#define UNIQUE(v) do { sort((v).begin(), (v).end()); (v).erase(unique((v).begin(), (v).end()), (v).end()); } while (false)
#define SZ(x) ((int)(x).size())
template <class T>inline bool chmin(T &a, const T b) {if (a > b) { a = b; return true;} return false;}
template <class T>inline bool chmax(T &a, const T b) {if (a < b) { a = b; return true;} return false;}
template <class T>inline void line_out(const vector<T> vec) {int n = SZ(vec); rep(i, n) { cout << vec[i]; if(i < n-1) cout << " ";}cout << endl;}
const int di[] = {0, 1, 0, -1, 1, 1, -1, -1};
const int dj[] = {1, 0, -1, 0, 1, -1, 1, -1};
const int INF = 1 << 28;
const ll INF64 = 1ll << 62;
const int mod = 1000000007;
//const int mod = 998244353;
struct mint
{
  ll x; // typedef long long ll;
  mint(ll x = 0) : x((x % mod + mod) % mod) {}
  mint operator-() const { return mint(-x); }
  mint &operator+=(const mint a)
  {
    if ((x += a.x) >= mod)
      x -= mod;
    return *this;
  }
  mint &operator-=(const mint a)
  {
    if ((x += mod - a.x) >= mod)
      x -= mod;
    return *this;
  }
  mint &operator*=(const mint a)
  {
    (x *= a.x) %= mod;
    return *this;
  }
  mint operator+(const mint a) const
  {
    mint res(*this);
    return res += a;
  }
  mint operator-(const mint a) const
  {
    mint res(*this);
    return res -= a;
  }
  mint &operator++()
  {
    if ((x += 1) >= mod)
      x -= mod;
    return *this;
  }
  mint &operator--()
  {
    if ((x += mod - 1) >= mod)
      x -= mod;
    return *this;
  }
  mint operator*(const mint a) const
  {
    mint res(*this);
    return res *= a;
  }
  mint pow(ll t) const
  {
    if (!t)
      return 1;
    mint a = pow(t >> 1);
    a *= a;
    if (t & 1)
      a *= *this;
    return a;
  }

  // for prime mod
  mint inv() const
  {
    return pow(mod - 2);
  }
  mint &operator/=(const mint a)
  {
    return (*this) *= a.inv();
  }
  mint operator/(const mint a) const
  {
    mint res(*this);
    return res /= a;
  }
};

int main()
{
  int n; cin >> n;
  vector<int> a(n+1);
  rep(i, n) cin >> a[i+1];
  vector<int> box(n+1, 0);
  for(int i = n; i > 0; --i) {
    int sum = 0;
    for(int j = 2; j*i <= n; ++j) sum += box[j*i];
    if(a[i] != sum%2) box[i] = 1;
  }
  vector<int> ans;
  for(int i = 1; i <= n; ++i) if(box[i] == 1) ans.push_back(i);

  cout << ans.size() << endl;
  for(auto x : ans) cout << x << endl;
}

Measured memory_bytes: 5340
#include <bits/stdc++.h>
using namespace std;
void solve()
{
    string s;
    cin >> s;
    bool f = true;
    for (int i = 0; i < s.size(); i += 2)
    {
        if (s[i] == 'h' && s[i + 1] == 'i')
        {
        }
        else
        {
            f = false;
        }
    }
    if (f)
        cout << "Yes";
    else
    {
        cout << "No";
    }
}
int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);

    solve();
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, a, n) for (int i = a; i < n; i++)
#define repr(i, a, n) for (int i = n - 1; i >= a; i--)
using namespace std;
using ll = long long;
using P = pair<int, int>;
template <typename T> void chmin(T &a, T b) { a = min(a, b); }
template <typename T> void chmax(T &a, T b) { a = max(a, b); }

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

  int n;
  cin >> n;
  vector<int> v(n);
  rep(i, 0, n) cin >> v[i];

  int all = v[0];
  rep(i, 1, n) all ^= v[i];

  rep(i, 0, n) cout << (all ^ v[i]) << endl;
}


Measured memory_bytes: 3952
#include <iostream>
#include <math.h>
#include <algorithm>
#include <vector>
#include <numeric>
#include <string>
using namespace std;
const double PI = acos(-1.0);
const string alp = "abcdefghijklmnopqrstuvwxyz";
const string ALP = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort((c).begin(),(c).end())
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n) FOR(i,0,n)
#define REP1(i,n) FOR(i,1,n+1)
#define SUM(c) accumulate((c).begin(),(c).end(),0)
#define UNIQ(c) (c).erase(unique((c).begin(), (c).end()), (c).end());
#define Yn(b) puts(b?"Yes":"No")
#define YN(b) puts(b?"YES":"NO")

bool isprime(int p) {
  if (p==1) return false;
  FOR(i,2,p) {
    if (p%i==0) return false;
  }
  return true;
}

int main(){
  int k;
  long n,c;
  cin >> n >> k;
  c=0;
  if(k==0){
    cout << n*n;
    return 0;
  }
  FOR(i,k,n+1){
    c+=(n/i)*(i-k);
    if((n%i)-k+1>0){
      c+=(n%i)-k+1;
    }
  }
  cout << c;
  return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <array>
#include <algorithm>
#include <math.h>
using namespace std;

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

    int N;
    cin >> N;
    vector<int> costs = vector<int>(N);
    vector<int> dp = vector<int>(N+1);
    for(auto &i: costs)cin >> i;

    dp[0] = 0;
    dp[1] = 0;
    dp[2] = dp[1] + abs(costs[1] - costs[0]);
    if(N > 2){
        for (int i = 3; i < N + 1; i++)
        {
            dp[i] = min(dp[i - 1] + abs(costs[i - 1] - costs[i - 2]), dp[i - 2] + abs(costs[i - 3] - costs[i - 1]));
        }
    }
    std::cout << dp[N] << endl;
    return 0;
}

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

int main() {
  int a,b,c,d;
  cin >> a >> b >> c;
  if(b > c){
    d = b;
    b = c;
    c = d;
  }
  if(a > c){
    d = a;
    a = c;
    c = d;
  }
  if(a > b){
    d = a;
    a = b;
    b = d;
  }




  cout << a << " " << b << " " << c << endl;


}



Measured memory_bytes: 3068
import sys
from functools import lru_cache

sys.setrecursionlimit(10 ** 6)

T = int(input())
for _ in range(T):
    N, A, B, C, D = map(int, input().split())

    @lru_cache(maxsize=None)
    def rec(n):
        if n == 0:
            return 0

        min_ = n * D
        min_ = min(min_, (n % 2) * D + A + rec(n // 2))
        if n // 2 + 1 != n:
            min_ = min(min_, (2 - n % 2) * D + A + rec(n // 2 + 1))

        min_ = min(min_, (n % 3) * D + B + rec(n // 3))
        if n // 3 + 1 != n:
            min_ = min(min_, (3 - n % 3) * D + B + rec(n // 3 + 1))

        min_ = min(min_, (n % 5) * D  + C + (rec(n // 5)))
        if n // 5 + 1 != n:
            min_ = min(min_, (5 - n % 5) * D + C + rec(n // 5 + 1))

        return min_

    print(rec(N))


Measured memory_bytes: 111524
#include<iostream>
#include<cstdio>
#include<cmath>
#include<cstring>
#include<string>
#include<stack>
#include<queue>
#include<vector>
#include<algorithm>
#include<iomanip>
#include<utility>
typedef long long int ll;
using namespace std;
#define FOR(i,a,b) for (int i=(a);i<(b);i++)
#define REP(i,n) for (int i=0;i<signed(n);i++)
#define EREP(i,n) for (int i=1;i<=(n);i++)
#define ALL(a) (a).begin(),(a).end()
//#define EVEL 1
 
#ifdef EVEL
#define DEB(X) cout << #X << ":" <<X<<" " ;
#define TF(f) f ? cout<<"true  " : cout<<"false ";
#define END cout<<"\n";
#else
#define DEB(X) {}
#define TF(f) {}
#define END {}
#endif
const int MOD = 1000000007;
const ll INF = 200000000000;
struct edge {int to,cost;};
typedef std::pair<int,int> P;
 
    ll N;
    ll A[100010],B[100010],K[100010],ans=1;
    ll W=-1,T=-1,cnt;
    bool f=false;
 
int main(){
    ios_base::sync_with_stdio(false);
    cin>>N;
    REP(i,N){cin>>A[i];}
    std::sort(A,A+N);
    int k=0;
    REP(i,N){
        //DEB(A[i])DEB(A[i+1])DEB(B[k])DEB(K[k])
        if(A[i]!=A[i+1]){B[k]++;K[k]=A[i];k++;
        DEB(A[i])DEB(A[i+1])DEB(B[k-1])DEB(K[k-1])END}
        else if(N-1!=i)B[k]++;
 
    }
    DEB(k)END
    REP(i,k){
        DEB(k-i-1)DEB(B[k-i-1])DEB(K[k-i-1])DEB(W)DEB(T)END
        if(B[k-i-1]>=4&&W==-1){W=T=K[k-i-1];break;}
        if(B[k-i-1]>=2){
            if(W==-1)W=K[k-i-1];
            else {T=K[k-i-1];break;}
        }
    }
    if(W!=-1&&T!=-1)cout<<T*W;
    else cout<<0;
    return 0;
}

Measured memory_bytes: 2560
#include <bits/stdc++.h>
template<class T> inline bool chmin(T&a, T b){if(a > b){a = b; return true;}else{return false;}}
template<class T> inline bool chmax(T&a, T b){if(a < b){a = b; return true;}else{return false;}}
#define ll long long
#define double long double
#define rep(i,n) for(int i=0;i<(n);i++)
#define REP(i,n) for(int i=1;i<=(n);i++)
#define mod (ll)(1e9+7)
#define inf (ll)(3e18+7)
#define pi (double) acos(-1.0)
#define P pair<int,int>
#define PiP pair<int,pair<int,int>>
#define all(x) x.begin(),x.end()
#define rall(x) x.rbegin(),x.rend()
using namespace std;

vector<int> Z_Algorithm(string s){
    int n = s.size(), l = -1, r = -1;
    vector<int> a(n, 0);
    a[0] = n;
    for(int i = 1; i < n; i++){
        int &same = a[i];
        if(l != -1){
            same = min(r-i, a[i-l]);
            same = max(0, same);
        }
        while(same < n && s[i+same] == s[same])same++;
        if(r < i+same){
            r = i+same;
            l = i;
        }
    }
    return a;
}

int main() {
    int n;
    string s;
    cin >> n >> s;
    int ans = 0;
    while(s.size() > 0){
        vector<int> z = Z_Algorithm(s);
        for(int i = 0; i < s.size(); i++){
            if(z[i] < i+1)chmax(ans, z[i]);
        }
        s.erase(s.begin());
    }
    cout << ans << endl;
}

Measured memory_bytes: 3660
import sys
import math
from collections import defaultdict

sys.setrecursionlimit(10**7)
def input():
    return sys.stdin.readline()[:-1]

mod = 10**9 + 7

def I(): return int(input())
def II(): return map(int, input().split())
def III(): return list(map(int, input().split()))
def Line(N,num):
    if N<=0:
        return [[]]*num
    elif num==1:
        return [I() for _ in range(N)]
    else:
        read_all = [tuple(II()) for _ in range(N)]
        return map(list, zip(*read_all))

#################

import heapq
class Reverse:
    def __init__(self, val):
        self.val = val
        
    def __lt__(self, other):
        return self.val > other.val
        
    def __repr__(self):
        return repr(self.val)
    
class Heapq:
    def __init__(self, arr, desc = False):
        if desc:
            for i in range(len(arr)):
                arr[i] = Reverse(arr[i])
        self.desc = desc
        self.hq = arr
        heapq.heapify(self.hq)
 
    def pop(self):
        if self.desc: return heapq.heappop(self.hq).val
        else: return heapq.heappop(self.hq)
 
    def push(self, a):
        if self.desc: heapq.heappush(self.hq, Reverse(a))
        else: heapq.heappush(self.hq, a)
 
    def top(self):
        if self.desc: return self.hq[0].val
        else: return self.hq[0]

N = I()
S = III()

S.sort()
a = [Heapq([],True) for _ in range(N+1)]
count = [0]*(N+1)

s = S.pop()
a[N].push(s)
count[N] = 1

while S:
    flag = False
    temp = S.pop()
    for i in range(1,N+1)[::-1]:
        if count[i]:
            if temp<a[i].top():
                x = a[i].pop()
                count[i] -= 1
                a[i-1].push(x)
                a[i-1].push(temp)
                count[i-1] += 2
                flag = True
                break
    if not flag:
        print('No')
        exit()

print('Yes')

Measured memory_bytes: 123384
#include <cstdio>
#include <vector>
#include <iostream>
#include <iomanip>
#include <string>
#include <sstream>
#include <algorithm>
using namespace std;
typedef long long ll;
#define rep(i,n) for(int i=0;i<n;i++)

int n,m;
int p[100000],y[100000];
std::vector<int> yd[100001];

int main(){
    std::cin >> n >>m;
    rep(i,m)std::cin >> p[i] >>y[i],yd[p[i]].push_back(y[i]);
    rep(i,n)sort(yd[i+1].begin(),yd[i+1].end());
    rep(i,m)std::cout <<setw(6)<<setfill('0')<< p[i]
    <<setw(6)<<setfill('0')<< int(lower_bound(yd[p[i]].begin(),yd[p[i]].end(),y[i])-yd[p[i]].begin())+1<< std::endl;
}

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

int main()
{
  int r,g,b;

  cin >> r >> g >> b;

  int sum = 10 * g + b;

  if(sum%4 == 0){
    cout <<"YES\n";
  }else{
    cout <<"NO\n";
  }

  return 0;
}

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

int main()
{
  int p;
  cin>>p;
  bool flag=0;
  for(int i=1;i<=9;i++)
  {
    if(p%i==0&&p/i>=1&&p/i<=9)
    {
      flag=1;
      break;
    }
  }
  if(flag)
    cout<<"Yes";
  else
    cout<<"No";
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define dg(x) cerr << #x << " = " << x <<endl;
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define sz(x) (int)(x).size()
#define F first
#define S second
#define forn(i,n) for(int i=0;i<(int)n;i++)
#define fore(i,a,b) for(int i=(int)a;i<=(int)b;++i)
#define pb push_back
typedef long long ll;
typedef long double ld;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
int n,m;
bool G[10][10];
int main(){
#ifdef LOCAL
    //freopen("h.txt", "r", stdin);
    // freopen("main.out", "w", stdout);
#else
    ios::sync_with_stdio(0), cin.tie(0);
    #define endl '\n'
#endif
    cin>>n>>m;
    forn(i,m){
        int u,v;
        cin>>u>>v;
        G[u][v]=1;
        G[v][u]=1;
    }
    string path="";
    fore(i,2,n)path+='0'+i;
    ll cnt=0;
    do{
        bool ok=1;
        int last=1;
        forn(i,n-1){
            if(!G[path[i]-'0'][last]){
                ok=0;
                break;
            }
            last=path[i]-'0';

        }
        if(ok)cnt++;
    }while(next_permutation(all(path)));
    cout<<cnt<<endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using vi = vector<ll>;
using vs = vector<string>;
#define  rep(i,n) for(ll i = 0; i < (n); ++i)
#define  red(i,n) for(ll i = (n)-1; i >= 0; --i)
#define  all(a)   begin(a),end(a)
#define  pb(a)    push_back(a)
#define  yn(a)    cout << ( (a)?"Yes\n":"No\n" )
inline ll gcd(ll a,ll b) { return b?gcd(b,a%b):a; }
ll INF = 1e9+9, LINF = 1e18;

int main(){
    int n,i=0,P,Q;
    cin>>n;
    vi p(n),q(n),a(n);
    rep(i,n)cin>>p[i],a[i]=i+1;
    rep(i,n)cin>>q[i];
    do{
        if(a==p)P=i;
        if(a==q)Q=i;
        i++;
    }while(next_permutation(all(a)));
    cout<<abs(P-Q)<<endl;
}


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

class Mass{
public:
    int N;
    long H[100000];
};

int main(){


    Mass m;
    cin >> m.N;

    int i;
    int j = 0;
    int k = 0;
    for (i = 0; i < m.N; i++){
        cin >> m.H[i];
        if(i != 0 && m.H[i] <= m.H[i-1]){
            j++;
        }else{
            k = max(k, j);
            j = 0;
        }


    }
    cout << max(k, j);

    return 0;
}


Measured memory_bytes: 1024
#include <iostream>
#include <vector>
#include <algorithm>
#include <iomanip>
#include <cmath>
#include <map>
#include <cmath>
#include <bitset>
#include <string>
#include <queue>

using namespace std;

#define int long long

signed main() {
    int n;
    cin >> n;
    vector<string> v(n);
    for(int i = 0; i < n; i++) cin >> v[i];

    sort(v.begin(), v.end());
    v.erase(unique(v.begin(), v.end()), v.end());

    cout << v.size() << endl;
    return 0;
}

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

int main(){
  int N;
  cin >> N;
  long int ans=0;
  for(int i=1; i<N+1; i++){
    if(i%3!=0 && i%5!=0){
      ans += i;
    }
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 3636
n = int(input())
A = list(map(int, input().split()))
A = [a-1 for a in A]

P = [-1]*n
for i, a in enumerate(A):
    P[a] = i

R = [n]*n
q = []
import heapq
heapq.heapify(q)
for i in range(n):
    while q:
        if -q[0] > A[i]:
            v = -heapq.heappop(q)
            R[v] = i
        else:
            break
    heapq.heappush(q, -A[i])

L = [-1]*n
q = []
heapq.heapify(q)
for i in reversed(range(n)):
    while q:
        if -q[0] > A[i]:
            v = -heapq.heappop(q)
            L[v] = i
        else:
            break
    heapq.heappush(q, -A[i])
#print(P)
#print(R)
#print(L)
ans = 0
for i in range(n):
    ans += (P[i]-L[i])*(R[i]-P[i])*(i+1)
print(ans)


Measured memory_bytes: 107576
#include <iostream>
#include <vector>
#include <stack>
#include <queue>
#include <algorithm>
#include <cstdlib>
#include <cmath>
#include <numeric>

using namespace std;

#define rep(i, n) for(int i = 0; i < n; i++)
#define repi(i, start, end) for(int i = start; i < end; i++)
#define all(x) (x).begin(), (x).end()
#define debug(x) cout << (x) << endl;
typedef long long ll;
const int MAX = 999999999;

int main(){
    vector<int> nums(4);
    rep(i, 4) cin >> nums[i];

    if(count(all(nums), 1) == 1 && count(all(nums), 9) == 1 && count(all(nums), 7) == 1 && count(all(nums), 4) == 1) cout << "YES" << endl;
    else cout << "NO" << endl;
}

Measured memory_bytes: 256
#include<stdio.h>
#include<limits.h>
 
#define MAX 2000000000
 
typedef struct{
  int x;
  char c;
}card;
 
int Partition(int, int);
void Quicksort(int, int);
void merge(int, int, int,card[]);
void mergeSort(int, int, card[]);
 
card B[100000];
 
int main(){
  int i, p, n;
  char c;
  card C[100000];
 
  scanf("%d%c", &n, &c);
  
  for(i=0;i<n;i++){
 
    scanf("%c%d%c", &C[i].c, &C[i].x, &c);
 
    B[i] = C[i];
 
  }
  
  p = 0;
 
  mergeSort(0, n, C);
 
  Quicksort(0, n-1);
 
  for(i = 0; i < n; i++){
 
    if(C[i].c != B[i].c){
 
      printf("Not stable\n");
 
      break;
    }
 
    if(i == (n - 1))
      printf("Stable\n");
 
  }
  
  for(i=0;i<n;i++){
 
    printf("%c %d\n", B[i].c, B[i].x);
 
    }
  
  return 0;
 
}
 
  
int Partition(int p, int r){
 
  card tmp;
 
  int x, i, j;
 
  x = B[r].x;
 
  i = p - 1;
 
  for(j = p; j < r; j++){
 
    if (B[j].x <= x){
 
      i++;
 
      tmp = B[i];
 
      B[i] = B[j];
       
      B[j] = tmp;
       
    }
     
  }
  
  tmp = B[i + 1];
   
  B[i + 1] = B[r];
   
  B[r] = tmp;
 
  return (i + 1);
 
}
  
void Quicksort(int p, int r){
 
  int q;
 
  if(p < r){
 
     q = Partition(p, r);
 
     Quicksort(p, q-1);
 
     Quicksort(q+1, r);
 
  }
   
}
  
void merge(int left,int mid,int right,card A[]){
 
  int i, j, k;
 
  int n1 = mid - left;
 
  int n2 = right - mid;
 
  card L[100001],R[100001];
  
  for(i = 0;i<n1;i++){
 
    L[i] = A[left + i];
 
  }
  
  for(i = 0; i < n2; i++){
    R[i]=A[mid+i];
  }
    
  L[n1].x = MAX;
  R[n2].x = MAX;

  i = 0;
  j = 0;
 
  for(k = left; k < right; k++){
 
    if(L[i].x <= R[j].x)
      A[k]=L[i++];
    else
      A[k]=R[j++];
 
  }
    
}
 
void mergeSort(int left, int right, card A[]){
   
  if((left + 1) < right){
    int mid = (left + right) / 2;
    mergeSort(left, mid, A);
    mergeSort(mid, right, A);
    merge(left, mid, right, A);
  }
 
}

Measured memory_bytes: 2960
import math
a=int(input())
b=round(a/1.08)
c=math.floor(b*1.08)
d=math.floor((b-1)*1.08)
e=math.floor((b+1)*1.08)

if a==c:
  print(b)
else:
  if a==d:
    print(b-1)
  elif a==e:
    print(b+1)
  else:
  	print(':(')



Measured memory_bytes: 3060
#include <iostream>
#include <algorithm>
#include <string>
#include <math.h>
#include <stdio.h>
#include <set>
#include <vector>
using namespace std;


int main(){
    int n;
    cin>>n;
    int str[n];
    int i;
    int tmp=1;
    int ans=0;
    for(i=0; i<n; i++){
        cin>>str[i];
    }
    while(tmp){
        for(i=0; i<n; i++){
            if(str[i]%2==0){
                str[i] = str[i]/2;
            }
            else{
                tmp=0;
            }
        }
        if(tmp==1){
            ans++;
        }
    }
    cout<<ans<<endl;
    return 0;
}

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

#define REP(i,s,n) for(int i=s;i<n;i++)
#define rep(i,n) REP(i,0,n)
#define EPS (1e-8)
#define equals(a,b) (fabs((a)-(b))<EPS)

using namespace std;

typedef pair<int,int> ii;

bool LT(double a,double b) { return !equals(a,b) && a < b ; }

struct Edge {
  int to,cap;
  double cost;
  int rev;
};

const int MAX_V = 1000, IINF = INT_MAX;
int V;
vector<Edge> G[MAX_V];

double h[MAX_V],dist[MAX_V];//////// fpwjefoajfpojeawfopefa
int prevv[MAX_V], preve[MAX_V];


inline void add_edge(int from,int to,int cap,double cost){
  G[from].push_back((Edge){to,cap,cost,G[to].size()});
  G[to].push_back((Edge){from,0,-cost,G[from].size()-1});
}

double min_cost_flow(int s,int t,int f){
  double res = 0;
  fill(h,h+V,0);
  while(LT(0,f)){
    priority_queue<ii,vector<ii>,greater<ii> > Q;
    fill(dist,dist+V,INT_MAX);
    dist[s] = 0;
    Q.push(ii(0,s));
    while( !Q.empty() ){
      ii p = Q.top(); Q.pop();
      int v = p.second;
      if( LT(dist[v],p.first) ) continue;
      for(int i=0;i<G[v].size();i++)      {
	Edge &e = G[v][i];
	if( LT(0,e.cap) && LT(dist[v]+e.cost+h[v]-h[e.to],dist[e.to]) ) {
	  dist[e.to] = dist[v]+e.cost+h[v]-h[e.to];
	  prevv[e.to] = v;
	  preve[e.to] = i;
	  Q.push(ii(dist[e.to],e.to));
	}
      }
    }
    if( equals(dist[t],INT_MAX) ) return -1;
    rep(v,V) h[v] += dist[v];
    int d = f;
    for(int v=t;v!=s;v=prevv[v]) d = min(d,G[prevv[v]][preve[v]].cap);
    f -= d;
    res += d * h[t];
    for(int v=t;v!=s;v=prevv[v]) {
      Edge &e = G[prevv[v]][preve[v]];
      e.cap -= d;
      G[v][e.rev].cap += d;
    }
  }
  return res;
}

typedef vector<double> vd;
typedef vector<vd> mat;



vector<double> f(const mat& A,const vd& b){
  int n = A.size();
  mat B(n,vd(n+1));
  rep(i,n) rep(j,n) B[i][j] = A[i][j];
  rep(i,n) B[i][n] = b[i];

  rep(i,n){
    int pivot = i;
    REP(j,i,n) if( LT(abs(B[pivot][i]),abs(B[j][i])) ) pivot = j;
    swap(B[i],B[pivot]);
    if( abs(B[i][i]) < EPS ) return vd();
    REP(j,i+1,n+1) B[i][j] /= B[i][i];
    rep(j,n){
      if( i != j ){
	REP(k,i+1,n+1) B[j][k] -= B[j][i] * B[i][k];
      }
    }
  }  

  vd x(n);
  rep(i,n) x[i] = B[i][n];
  return x;
}

void init(int size=MAX_V){
  rep(i,size) G[i].clear();
}

int main(){
  int T;
  cin >> T;
  while( T-- ){
    int N,s,t,F;
    cin >> N >> s >> t >> F;
    mat A(N,vector<double>(N,0));
    vector<double> b(N,0);
    rep(i,N) {
      rep(j,N) {
	cin >> A[i][j];
      }
      cin >> b[i];
    }
    
    vector<double> ans = f(A,b);
    
    init();

    rep(i,N) {
      int M;
      cin >> M;
      vector<ii> vec(M);
      rep(j,M) cin >> vec[j].first;
      rep(j,M) cin >> vec[j].second;
      rep(j,M) {
	add_edge(i,vec[j].first,vec[j].second,abs(ans[i]-ans[vec[j].first]));
      }
    }

    V = N;
    double temp = min_cost_flow(s,t,F);
    if( equals(temp,-1) ) puts("impossible");
    else printf("%.10f\n",temp);

  }
  return 0;
}

Measured memory_bytes: 2076
#include <iostream>
#include <cstdio>
#include <map>
#include <cmath>
#define F first
#define S second

using namespace std;

typedef long long ll;

ll n;
ll a[55];
ll b[55];
map<pair<ll, ll>, ll> ma;
ll ans;

int main()
{
    scanf("%lld", &n);
    for(ll i = 0; i < n; i++)
    {
        scanf("%lld%lld", &a[i], &b[i]);
        for(ll j = 0; j < i; j++)
        {
            ma[make_pair(a[i] - a[j], b[i] - b[j])]++;
            ma[make_pair(a[j] - a[i], b[j] - b[i])]++;
        }
    }
    for(auto i:ma)
    {
        ans = max(ans, i.S);
    }
    printf("%lld\n", n - ans);
    return 0;
}


Measured memory_bytes: 384
//include
//------------------------------------------
#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>

using namespace std;

int main()
{
  int N, X=0;
  cin >> N;

  int d[N]={0};
  int check[110]={0};
  

  for(int i=0; i<N; ++i){
    cin >> d[i];
  }
  for(int i=0; i<N; ++i){
    check[d[i]]++;
  }
  for(int i=0; i<110; ++i){
    if(check[i]!=0) ++X;
  }
  cout << X << endl;
  return 0;
}


Measured memory_bytes: 256
s = input()

"""
ある文字が一つ飛ばし以内で存在すれば、その2文字を含めて3文字の答えを作れる
これ以上離れていてもアンバランスにするには、どこかで上記の条件を満たす必要があるため
十分条件でもある。
これをaからzまで試す
"""

for i in range(26):
    tgt = chr(ord('a')+i)
    idx = -10**7
    for j in range(len(s)):
        if s[j]==tgt:
            if j-idx<=2:
                print('{} {}'.format(idx+1, j+1))
                exit()
            else:
                idx = j
print('-1 -1')

            

Measured memory_bytes: 9036
N, x = map(int,input().split())
A = list(map(int,input().split()))
B = A
A = A + A
#print(B)
#print(A)
ans = 10**18
for i in range(N):
    for j in range(N):
        if B[j] > A[j+N-i]:
            B[j] = A[j+N-i]

    #print(sum(B))
    t = sum(B) + x*i
    #print(t)
    if ans > t:
        ans = t
print(ans)

Measured memory_bytes: 3316
// reference: https://qiita.com/tanakh/items/0ba42c7ca36cd29d0ac8
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
    ($($r:tt)*) => {
        let mut s = {
            use std::io::Read;
            let mut s = String::new();
            std::io::stdin().read_to_string(&mut s).unwrap();
            s
        };
        let mut iter = s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
}

macro_rules! input_inner {
    ($iter:expr) => {};
    ($iter:expr, ) => {};

    ($iter:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($iter, $t);
        input_inner!{$iter $($r)*}
    };
}

macro_rules! read_value {
    ($iter:expr, ( $($t:tt),* )) => {
        ( $(read_value!($iter, $t)),* )
    };

    ($iter:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($iter, $t)).collect::<Vec<_>>()
    };

    ($iter:expr, chars) => {
        read_value!($iter, String).chars().collect::<Vec<char>>()
    };

    ($iter:expr, usize1) => {
        read_value!($iter, usize) - 1
    };

    ($iter:expr, $t:ty) => {
        $iter.next().unwrap().parse::<$t>().expect("Parse error")
    };
}

fn main() {
    input! {
        n: usize,
        a: [i64; n]
    }

    let cnt = a.iter().filter(|&x| x.is_negative()).count();
    let a = a.into_iter().map(|x| x.abs()).collect::<Vec<_>>();
    let min = *a.iter().min().unwrap();
    let sum = a.into_iter().sum::<i64>();
    let ans = sum - if cnt % 2 == 0 { 0 } else { min * 2 };
    println!("{}", ans)
}


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

int leftMin = 1e9+7;
int diff, ans;

int main(){
	int N, a;
	scanf("%d %d", &N, &a);
	while(N--){
		scanf("%d", &a);
		if(a - leftMin == diff){
			++ans;
		}
		else if(a - leftMin > diff){
			diff = a - leftMin;
			ans = 1;
		}
		leftMin = min(leftMin, a);
	}
	printf("%d\n", ans);
}


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

int main() {
    int a, b, c;
    cin >> a >> b >> c;
    
    int mx = max(a, max(b, c));
    if(3 * mx % 2 == (a + b + c) % 2) cout << (3 * mx - a - b - c) / 2 << endl;
    else cout << (3 * (mx + 1) - a - b - c) / 2 << endl;
}


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

int main() {
  int n,m; cin >> n >> m;
  int s[m],c[m];
  REP(i,m) cin >> s[i] >> c[i];

  int a[n];
  for (int i = (n == 1 ? 0 : pow(10, n-1)); i < pow(10, n); i++) {
    int ok = 1;
    int tmp = i;
    REP(i, n) {
      a[i] = tmp % 10;
      tmp /= 10;
    }
    REP(j,m) {
      if (a[n - s[j]] != c[j] ) { ok = 0; break; }
    }
    if (ok) {
      cout << i << endl;
      return 0;
    }
  }
  cout << -1 << endl;
}

Measured memory_bytes: 256
#include <iostream> // cout, endl, cin
#include <string> // string, to_string, stoi
#include <vector> // vector
#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <utility> // pair, make_pair
#include <tuple> // tuple, make_tuple
#include <cstdint> // int64_t, int*_t
#include <cstdio> // printf
#include <map> // map
#include <queue> // queue, priority_queue
#include <set> // set
#include <stack> // stack
#include <deque> // deque
#include <unordered_map> // unordered_map
#include <unordered_set> // unordered_set
#include <bitset> // bitset
#include <cctype> // isupper, islower, isdigit, toupper, tolower

using namespace std;
using ll = long long;

#define rep(i,N) for(int i=0;i<(int)N;++i)

int main() {
	string S, T;
	cin >> S >> T;

	int A, B;
	cin >> A >> B;

	string U;
	cin >> U;

	if (U == S) { --A; }
	if (U == T) { --B; }

	cout << A << " " << B << endl;
}

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

#define     int long long
#define     pii pair<int,int>
#define     x first
#define     y second
#define     __FastIO ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0)
#define     MOD 1000000007
#define     INF 100000000
#define     nll cout << "\n"
#define     nl "\n"
#define     MAX 1000003
#define     print(v) cout << v << " "
#define     dbgv(v) cout << v << nl
#define     asdf(v) cout << v << nl
#define     pasdf(p) cout << p.x << " " << p.y << nl
#define     dbg cout << "dbg\n"
#define     vi vector<int>
#define     vl vector<ll>
#define     pb push_back
#define     con continue

int xx[] = {1, -1, 0, 0};
int yy[] = {0, 0, -1, 1};

int32_t main(){
    int l,r, d;
    while(cin >> l >> r >>d){
        int ans = r/d - (l-1)/d;
        asdf(ans);
    }
    return 0;
}


Measured memory_bytes: 3640
import java.io.*;
import java.util.*;
import java.lang.*;

class Main{
  public static void main(String[] args) throws IOException{
    Scanner scan=new Scanner(System.in);
    int n=Integer.parseInt(scan.next());
    int m=Integer.parseInt(scan.next());
    int l=Integer.parseInt(scan.next());
    long[][] arrayA=new long[n][m];
    for(int i=0;i<arrayA.length;i++){
      for(int j=0;j<arrayA[i].length;j++){
        arrayA[i][j]=Long.parseLong(scan.next());
      }
    }
    long[][] arrayB=new long[m][l];
    for(int i=0;i<arrayB.length;i++){
      for(int j=0;j<arrayB[i].length;j++){
        arrayB[i][j]=Long.parseLong(scan.next());
      }
    }

    long[][] arrayC=new long[n][l];
    for(int i=0;i<n;i++){
      for(int j=0;j<l;j++){
        for(int k=0;k<m;k++){
          arrayC[i][j]+=arrayA[i][k]*arrayB[k][j];
        }
      }
    }

    for(int i=0;i<arrayC.length;i++){
      for(int j=0;j<arrayC[i].length;j++){
        System.out.print(arrayC[i][j]);
        if(j<arrayC[i].length-1){
          System.out.print(" ");
        }
      }
      System.out.println();
    }
  }
}


Measured memory_bytes: 47932
#include <stdio.h>
#define N 45
int fibonacci(int);
int F[N];
int main(){
  int n,i;
  for(i=0;i<N;i++){
    F[i]=-1;
  }
  scanf("%d",&n);
  printf("%d\n", fibonacci(n));
  return 0;
}
  
int fibonacci(int n){
  int i;
  if(n == 0 || n == 1)
    return F[n] = 1 ;
  if( F[n]!= -1)
    return F[n];
  else
     return F[n] = fibonacci(n - 2) + fibonacci(n - 1);
	 }

Measured memory_bytes: 596
#[allow(unused_macros)]
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        let mut next = || { iter.next().unwrap() };
        input_inner!{next, $($r)*}
    };
    ($($r:tt)*) => {
        let stdin = std::io::stdin();
        let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));
        let mut next = move || -> String{
            bytes
                .by_ref()
                .map(|r|r.unwrap() as char)
                .skip_while(|c|c.is_whitespace())
                .take_while(|c|!c.is_whitespace())
                .collect()
        };
        input_inner!{next, $($r)*}
    };
}
#[allow(unused_macros)]
macro_rules! input_inner {
    ($next:expr) => {};
    ($next:expr, ) => {};

    ($next:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };
}
#[allow(unused_macros)]
macro_rules! read_value {
    ($next:expr, ( $($t:tt),* )) => {
        ( $(read_value!($next, $t)),* )
    };

    ($next:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
    };

    ($next:expr, chars) => {
        read_value!($next, String).chars().collect::<Vec<char>>()
    };

    ($next:expr, usize1) => {
        read_value!($next, usize) - 1
    };

    ($next:expr, $t:ty) => {
        $next().parse::<$t>().expect("Parse error")
    };
}


fn main() {
    input! {
        a: usize,
        b: usize,
    }
    if a + b >= 10 {
        println!("error")
    } else {
        println!("{}", a + b)
    }
} 


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



int main(){
  int N,M,tmp;
  cin>>N>>M;

  int maxd=max(N,M);
  int mind=min(N,M);

  if(maxd>mind+1){
    cout<<"0"<<endl;
  } else {
    long long result = 1;

    for(int i=maxd;i>0;i--){
      result *= i;
      result %= 1000000007;
    }

    for(int i=mind;i>0;i--){
      result *=i;
      result %=1000000007;
    }
    if(mind==maxd){
      result *=2;
      result %=1000000007;
    }

    cout<<result<<endl;

  }

  return 0;
}




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

if X <= 599:
    print(8)
elif X <= 799:
    print(7)
elif X <= 999:
    print(6)
elif X <= 1199:
    print(5)
elif X <= 1399:
    print(4)
elif X <= 1599:
    print(3)
elif X <= 1799:
    print(2)
else:
    print(1)

Measured memory_bytes: 9172
# -*- coding: utf-8 -*-

import sys
import copy

sys.setrecursionlimit(1000000)

# input = sys.stdin.readline

# ~~~~~~~~~~~~~~~~~~~~~_(＾～＾ ｣ ∠)_~~~~~~~~~~~~~~~~~~~~~

K, S = map(int, input().split())
ans = 0

for x in range(K + 1):
    for y in range(K + 1):
        z = S - (x + y)
        if z >= 0 and z <= K:
            ans += 1



print(ans)


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

using namespace std;
using ll = long long int;

int main(void) {
    constexpr ll MOD = 1e9 + 7;
    cout << fixed << setprecision(16);

    ll n, m;
    cin >> n >> m;
    vector<ll> s(n), t(m);
    for(auto &e: s) cin >> e;
    for(auto &e: t) cin >> e;

    vector<vector<ll>> dp(m+1, vector<ll>(n+1));

    for(ll i=0; i<=n; i++)
        dp[0][i] = 1;

    for(ll i=1; i<=m; i++) {
        dp[i][0] = 1;
        for(ll j=1; j<=n; j++) {
            dp[i][j] = (MOD + dp[i-1][j] + dp[i][j-1] - dp[i-1][j-1] + (t[i-1] == s[j-1] ? dp[i-1][j-1] : 0)) % MOD;
        }
    }
    cout << dp[m][n] << endl;
}


Measured memory_bytes: 31616
#include <stdlib.h>
#include <cmath>
#include <cstdio>
#include <cstdint>
#include <string>
#include <iostream>
#include <vector>
#include <utility>
#include <algorithm>
#include <map>
using namespace std;

int main(){
  long long N,K;
  cin >> N >> K;
  N=N%K;
  long long temp=N;
  while(1){
    temp=abs(N-K);
    if(temp<N){
      N=temp;
    }
    else{
      break;
    }
  }

  cout << N << endl;
  
  return 0;
}


Measured memory_bytes: 256
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
from collections import Counter


def main():
    N = int(input())
    V = list(map(int, input().split()))

    even = Counter(V[::2])
    odd = Counter(V[1::2])

    arr_even = even.most_common()
    arr_odd = odd.most_common()

    sum_even = sum(x[1] for x in arr_even)
    sum_odd = sum(x[1] for x in arr_odd)

    min_sum = sum_even - arr_even[0][1] + N // 2

    for i, x in arr_even:
        for j, y in arr_odd:
            if i != j:
                cnt = sum_even - x + sum_odd - y
                min_sum = min(min_sum, cnt)
                break
            else:
                continue

    print(min_sum)


if __name__ == "__main__":
    main()


Measured memory_bytes: 21176
#include<bits/stdc++.h>
#define rep(i,a) for(int i=(int)0;i<(int)a;++i)
#define rrep(i,a) for(int i=(int)a-1;i>=0;--i)
#define REP(i,a,b) for(int i=(int)a;i<(int)b;++i)
#define RREP(i,a,b) for(int i=(int)a-1;i>=b;--i)
#define pb push_back
#define eb emplace_back
#define all(x) x.begin(),x.end()
#define rall(x) x.rbegin(),x.rend()
using ll=long long;
constexpr ll mod = 1e9 + 7;
constexpr ll INF = 1LL << 60;
 
template<class T> inline bool chmin(T& a, T b) {
    if (a > b) {
        a = b;
        return true;
    }
    return false;
}
template<class T> inline bool chmax(T& a, T b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}


ll gcd(ll n, ll m) {
    ll tmp;
    while (m!=0) {
        tmp = n % m;
        n = m;
        m = tmp;
    }
    return n;
}
 
ll lcm(ll n, ll m) {
    return abs(n) / gcd(n, m)*abs(m);//gl=xy
}

using namespace std;

using P = pair<int, int>;

void solve()
{
	int n;
	cin >> n;
	vector<vector<int>> g(n);
	vector<P> cnt(n);
	rep(i,n){
		cnt[i].second = i;
	}
	vector<int> a(n), b(n);
	rep(i, n-1)
	{
		cin >> a[i] >> b[i];
		a[i]--;
		b[i]--;
		g[a[i]].pb(b[i]);
		g[b[i]].pb(a[i]);
		cnt[a[i]].first++;
		cnt[b[i]].first++;
	}
	sort(rall(cnt));
	vector<ll> c(n);
	rep(i,n){
		cin >> c[i];
	}
	sort(rall(c));
	ll sum = 0;
	REP(i, 1, n)
	{
		sum += c[i];
	}
	queue<int> q;
	q.emplace(cnt[0].second);
	vector<ll> v(n,-1);
	int pos = 0;
	while (!q.empty())
	{
		int x = q.front();
		q.pop();
		v[x] = c[pos++];
		for (auto y : g[x])
		{
			if(v[y]==-1){
				q.emplace(y);
			}
		}
	}
	cout << sum << "\n";
	rep(i,n){
		if(i){
			cout << " ";
		}
		cout << v[i];
	}
}

int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout<<fixed<<setprecision(15);
    solve();
    return 0;
}

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

using namespace std;
#define rep(i, n) for(int i = 0; i < (n) ; i++ )
#define SQR(x) (x)*(x)
typedef long long ll;

long fact(int N) {
    long ans = 1;
    rep(i, N) {
        ans *= (i + 1);
    }
    return ans;
}

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

    int x[9] = { 0 }, y[9] = { 0 };
    rep(i, N) {
        cin >> x[i] >> y[i];
    }

    auto pattern = [&](int i, int j) {
        int temp[8] = {0};
        int array[8] = { 1,2,3,4,5,6,7,8 };
        int answer = 1;

        rep(k, j) {
            temp[k] = (i - 1) / fact(N-1-k) + 1;
            i = i - (temp[k] - 1) * fact(N - 1 -k);
            answer = array[temp[k] - 1];

            rep(l, 8 - temp[k]) {
                array[temp[k]-1+l] = array[temp[k]+l];
            }
        }
        return answer;
    };

    long pat[40320][8] = {0};
    rep(i, fact(N)){
        rep(j, N) {
            pat[i][j] = pattern(i+1,  j+1);
        }
    }



    //double distance[120] = { 0 };
    long double temp = 0;
    long square = 0;
    rep(i, fact(N)){
        rep(j, N-1) {
            square = SQR(x[pat[i][j]-1] - x[pat[i][j + 1]-1]) + SQR(y[pat[i][j]-1] - y[pat[i][j + 1]-1]);
            temp += sqrt(square);
        }        
    }


    cout <<fixed << setprecision(8) << temp / fact(N) << endl;
}

Measured memory_bytes: 2816