akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
#define fi                first
#define se                 second
#define ll               long long
#define mod              1000000007
#define endl              "\n"
#define fast               ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define pb                push_back
#define all(v)             v.begin(),v.end()
#define inp(V,n)      for(int i=0;i<n;i++){cin >> V[i];}
#define oup(V,n)     {for(int i=0;i<n;i++){cout <<  V[i] << " "  ;} cout << endl;}
using namespace std;
ll factorial(ll n)
{
    return (n == 1 || n == 0) ? 1 : n * factorial(n - 1);
}
ll gcd(ll a, ll b)
{
    if (a == 0)
      return b;
    return gcd(b % a, a);
}
ll lcm(ll a, ll b)
{
   return (a*b)/gcd(a, b);
}
bool sortByVal(const pair<double,double> &a,
               const pair<double,double> &b)
{
    if(a.fi==b.fi)
    {
    return (a.se >b.se);
    }
    else
        return (a.fi<b.fi);
}
ll Powb(ll b,ll n)
{
    if(n==0) return 1LL;
    if(n==1) return b;
    ll temp = Powb(b,n/2);
    if(n%2==0){return (temp*temp)%mod;}
    else{return (b*((temp*temp)%mod))%mod;}
}
ll sumofdigit(ll n)
{
    ll c=0,d=0,sum=0,i;
    while(n>0)
    {
        c=n%10;
        sum+=c;
        n/=10;
    }
    return sum;
}
int main()
{
 fast;
     int t=1;
     //cin>>t;
     while(t--)
     {
        ll m,i=0,j=0,c=0,d=0,e=0,f=0,sum=0,g=0,h=0,n,maxi=0;
        cin>>n;
        d=1;
        sum=0;
        while(true)
        {
            sum+=1000;
            if(sum>=n)
                break;
        }
        cout<<sum-n;

     }
}



Measured memory_bytes: 3636
#include "bits/stdc++.h"
#define int long long
#define endl '\n'
using namespace std;
 
typedef long long ll;
#define db(x) cerr << #x << ": " << x << '\n';
#define read(a) int a; cin >> a;
#define readb(a, b) int a, b; cin >> a >> b;
#define readc(a, b, c) int a, b, c; cin >> a >> b >> c;
#define readarr(a, n) int a[(n) + 1] = {}; FOR(i, 1, (n)) {cin >> a[i];}
#define readmat(a, n, m) int a[n + 1][m + 1] = {}; FOR(i, 1, n) {FOR(j, 1, m) cin >> a[i][j];}

#define print(a) cout << a << endl;
#define printarr(a, n) FOR (i, 1, n) cout << a[i] << " "; cout << endl;
#define printv(v) for (int i: v) cout << i << " "; cout << endl;
#define printmat(a, n, m) FOR (i, 1, n) {FOR (j, 1, m) cout << a[i][j] << " "; cout << endl;} cout << endl;
#define all(v) v.begin(), v.end()
#define sz(v) (int)(v.size())
#define rz(v, n) v.resize((n) + 1);
#define pb push_back
#define fi first
#define se second
#define vi vector <int>
#define pi pair <int, int>
#define vpi vector <pi>
#define vvi vector <vi>
#define FOR(i, a, b) for (int i = (a); i <= (b); i++)
#define FORD(i, a, b) for (int i = (a); i >= (b); i--)
const ll inf = 1e18;
const ll mod = 1e9 + 7;
const ll N = 2e5 + 1;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
 
signed main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	
	string s;
	cin >> s;
	map <int, int> mp;
	mp[0] = 1;
	
	int cur = 0, p = 1, ans = 0;
	FORD (i, sz(s) - 1, 0)
	{
	    int d = s[i] - '0';
	    cur = (d*p + cur) % 2019;
	    p = p*10 % 2019;
	    ans += mp[cur];
	    mp[cur]++;
	}
	
	print(ans);
}














Measured memory_bytes: 3784
N=int(input())
V=list(map(int,input().split()))
C=list(map(int,input().split()))
netV = [V[i] - C[i] for i in range(N)]

netV=sorted(netV,reverse=True)

SUM=0
for i in range(N):
  if netV[i]>0:
    SUM += netV[i]
  else:
    break

print(SUM)

Measured memory_bytes: 9152
#include <iostream>
#include <algorithm>
#include <vector>
#include <queue>
#include <stack>
#include <string>
#include <iomanip>
#include <map>
#include <set>
#include <cmath>
#include <cstdio>
using namespace std;
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define FOR(i,m,n) for(int (i)=(m);(i)<(n);(i)++)
#define All(v) (v).begin(),(v).end()
typedef long long ll;

int main(){
    string S;
    cin >> S;
    rep(i,3){
        if(S[i]==S[i+1]){
            cout << "Bad" << endl;
            return 0;
        }
    }
        cout << "Good" << endl;
    return 0;
}

Measured memory_bytes: 256
#pragma GCC optimize ("O3")
#include <bits/stdc++.h>
using namespace std;
#define MuhammedAly ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define all(x) (x).begin(),(x).end()
#define allr(x) (x).rbegin(),(x).rend()
#define pb push_back
#define eb emplace_back
#define popc(x) __builtin_popcount(x)
#define LLMX 1e18
#define NotinRange(n,m) i<0||i>=(n)||j<0||j>=(m)
#define mem(x,y) memset((x),(y),sizeof (x))
#define sz(a) (int)(a).size()
#define inFile(s) freopen((s),"r",stdin)
#define	outFile(s) freopen((s),"w",stdout)
#define biEdge(v, a, b) (v)[(a)].pb((b)), (v)[(b)].pb((a))
#define pi (2 * acos(0))
#define X real()
#define Y imag()
#define cross(a, b) ((conj(a) * (b)).Y)
#define dot(a, b) ((conj(a) * (b)).X)
#define vec(a,b) ((b) - (a))
#define ll long long
typedef long double ld;
typedef complex<double>point;
typedef tuple<int, int, int> line;
typedef pair<point, point>segment;
typedef vector<point>polygon;
const int N = 2e5 + 5, M = 20 + 5, OO = 0x3f3f3f3f, mod = 1e9 + 7, base = 131, mod2 = 1000136437, mod3 = 998244353;
const double EPS = 1e-9;
int n;
ll arr[N], ans;
int main()
{
    MuhammedAly
    cin >> n;
    for(int i = 0 ; i < n ; i++)
        cin >> arr[i], arr[i] -= i + 1;
    sort(arr, arr + n);
    for(int i = 0 ; i < n ; i++)
        ans += abs(arr[i] - arr[n / 2]);
    cout << ans;
    return 0;
}

Measured memory_bytes: 1792
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		int[] a = new int[N];
		for(int i = 0;i < N;++i)
			a[i] = sc.nextInt();
		sc.close();
		
		int min = a[0], max = a[0];
		for(int i = 1;i < N;++i) {
			if(min > a[i])
				min = a[i];
			else if(max < a[i])
				max = a[i];
		}
		System.out.println((max - min));
	}
}


Measured memory_bytes: 23124
#include<iostream>
#include<algorithm>
using namespace std;
int main()
{
	int n,a,b,c,s[3]={0},i;
	cin>>n;
	cin>>a>>b;
	for(i=0;i<n;i++)
	{
		cin>>c;
		if(c<=a)
			s[0]++;
		else
		{
			if(c<=b)
			{
				s[1]++;
			}
			else
			{
				s[2]++;
			}
		}
	}
	sort(s,s+3);
	cout<<s[0]<<endl;
	return 0;
} 

Measured memory_bytes: 384
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <string>
#include <unordered_map>

template <class T> class UnionFind {

  private:
    struct subset  {
      T parent;
      T rank;
      T diff_weight;
      T sizes;
    };
    std::vector<subset> subsets;

  public:
    UnionFind (T N) {
      subsets.reserve(N);
      for(T i=0; i<N; i++){
        subsets.push_back( { i, 0, 0, 1 } );
      }
    }

    T Find (T x) {
      if (subsets[x].parent == x) return x;
      subsets[x].diff_weight += subsets[subsets[x].parent].diff_weight;
      return subsets[x].parent = Find(subsets[x].parent);
    }

    T weight(T x) {
      Find(x);
      return subsets[x].diff_weight;
    }

    bool Same (T x, T y) {
        return Find(x) == Find(y);
    }

    bool Union (T x, T y, T w) {
      w += weight(x); w -= weight(y);

      T xroot = Find(x);
      T yroot = Find(y);
      if ( xroot == yroot ) return false;

      if (subsets[xroot].rank < subsets[yroot].rank) {
        subsets[xroot].parent = yroot;
        w = -w;
        subsets[yroot].sizes += subsets[xroot].sizes;
      }
      else if (subsets[xroot].rank > subsets[yroot].rank) {
        subsets[yroot].parent = xroot;
        subsets[xroot].sizes += subsets[yroot].sizes;
      }
      else {
        subsets[yroot].parent = xroot;
        subsets[xroot].rank++;
        subsets[xroot].sizes += subsets[yroot].sizes;
      }
      subsets[yroot].diff_weight = w;
      return true;
    }

    T diff(T x, T y) {
      return weight(y) - weight(x);
    }

    T size (T x) {
      return subsets[Find(x)].sizes;
    }
};


int main (void) {
  int N, M;
  std::cin >> N >> M;

  std::vector<int> p(N);
  for(int i=0; i<N; i++) std::cin >> p[i];

  UnionFind<int> uf(N);
  for(int i=0; i<M; i++){
    int a, b; std::cin >> a >> b;
    uf.Union(a-1,b-1,0);
  }

  std::unordered_map<int, std::vector<int>> P;
  for(int i=0; i<N; i++){
    P[uf.Find(i)].push_back(i);
  }

  int ans = 0;
  for(auto itr = P.begin(); itr != P.end(); ++itr){
    for ( auto v = itr->second.begin(); v != itr->second.end(); ++v ) {
      if (std::binary_search(itr->second.begin(), itr->second.end(), p[*v]-1)) ans++;
    }
  }

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

Measured memory_bytes: 11044
//File Name: code_festival_2017_quala_b.cpp
  //Created Time: 2017年09月30日 星期六 21时22分45秒
                                   
#include <bits/stdc++.h>
using namespace std;
int main(){
	int n,m,k;
	cin >> n >> m >> k;
	bool flag(false);
	for(int i(0);i<=n;++i){
		for(int j(0);j<=m;++j){
			if(m * i + n * j - 2 * i * j == k){
				flag = true;
				break;
			}
		}
	}
	if(flag) puts("Yes");
	else puts("No");
	return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
using namespace std;
int main(void){
	int W,Q;
	while(cin>>W>>Q,!(W==0&&Q==0)){
		int cats_w[101],cats_loc[101];
		bool wall[101];
		for(int i=0;i<101;++i) wall[i]=false;
		for(int i=0;i<Q;++i){
			char c;
			cin>>c;
			if(c=='s'){
				bool f=false;
				int id,w,begin_loc=0,count=0;
				cin>>id>>w;
				cats_w[id]=w;
				for(int j=0;j<W;++j){
					if(wall[j]==false){
						++count;
						if(count==w){
							f=true;
							break;
						}
					}else{
						begin_loc=j+1;
						count=0;
					}
				}
				if(f){
					cout<<begin_loc<<endl;
					cats_loc[id]=begin_loc;
					for(int j=begin_loc;j<begin_loc+w;++j) wall[j]=true;
			}else {
					cout<<"impossible"<<endl;
			}
			}else if(c=='w'){
				int id;
				cin>>id;
				for(int j=cats_loc[id];j<cats_loc[id]+cats_w[id];++j) wall[j]=false;
			}
		}
		cout<<"END"<<endl;
	}
	return 0;
}

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

int ans1,ans2;
char t1,t2;
string x;

int main(){
	cin>>x;
	int pan = x.length();
	t1 = '0';
	t2 = '1';
	for(int i =0;i<pan;i++){
		if(x[i]!=t1)ans1++;
		if(x[i]!=t2) ans2++;
		if(t1=='0') t1='1';
		else t1='0';
		if(t2=='0') t2='1';
		else t2='0';
	}
	printf("%d\n",min(ans1,ans2));
	return 0;
}

Measured memory_bytes: 764
h,w,D = map(int,input().split())
a=[]

for _ in range(h):
    b=list(map(int,input().split()))
    a.append(b)

d={}
for i in range(h):
    c=a[i]
    for j in range(w):
        d[c[j]]=(i+1,j+1)


R_min=h*w
R_max=1
query=[]
q=int(input())
for _ in range(q):
    l,r=map(int,input().split())
    query.append([l,r])
    R_min = min(l,R_min)
    R_max = max(r,R_max)


cum=[0]*(h*w+1)
for k in range(R_min,R_max-D+1):
    prev = cum[k-1]
    cost = abs(d[k+D][0]-d[k][0]) + abs(d[k+D][1]-d[k][1])
    cum[k+D-1]=cost+prev



for j in range(q):
    l,r=query[j][0],query[j][1]
    score = cum[r-1]-cum[l-1]
    print(score)

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

int main(){
    int a,b,c,tmp;
    cin >>a>>b>>c;
    if(a>b && b>c){
        tmp = a;
        a = c;
        c = tmp;
    }
    if(a>b){
        tmp = b;
        b = a;
        a = tmp;
    }
    if(b>c){
        tmp = c;
        c = b;
        b = tmp;
    }
    cout << a <<" "<< b <<" "<< c <<endl;
    
}


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

#define _u(i,a,b) for(int i=a;i<=b;++i)
#define _d(i,a,b) for(int i=a;i>=b;--i)
#define endl "\n"
#define ii pair<int,int>
#define fi first
#define se second
#define ll long long
#define FIO() ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define FI(task) freopen(task".inp","r",stdin)
#define FO(task) freopen(task".out","w",stdout)

using namespace std;

const int N = 3e3+7;
const int M = 1e9+7;

int n, m;
int f[N][N];
ii trace[N][N];
string s, t;
vector<char> res;

void tv(int i, int j){
    if(s[i] == t[j]) res.push_back(s[i]);
    if(trace[i][j].fi == 0 || trace[i][j].se == 0) return;
    tv(trace[i][j].fi, trace[i][j].se);
}

#define task "test"

int main(){
    FIO();
    //FI(task);
    ///FO(task);

    cin >> s; s = " " + s; n = s.size() - 1;
    cin >> t; t = " " + t; m = t.size() - 1;
    _u(i,1,n) _u(j,1,m) if(s[i] == t[j]){
        f[i][j] = f[i-1][j-1] + 1;
        trace[i][j] = {i-1, j-1};
    }else{
        if(f[i-1][j] > f[i][j-1]){
            f[i][j] = f[i-1][j];
            trace[i][j] = {i-1, j};
        }else{
            f[i][j] = f[i][j-1];
            trace[i][j] = {i, j-1};
        }
    }
    tv(n, m);
    for(int i = (int)res.size()-1;i>=0;--i) cout << res[i];
    return 0;
}


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

int main() {
    int n;
    cin >> n;
    if(100 <= n && n <= 111){
        cout << 111 << endl;
    }else if(112 <= n && n <= 222){
        cout << 222 << endl;
    }else if(223 <= n && n <= 333){
        cout << 333 << endl;
    }else if(334 <= n && n <= 444){
        cout << 444 << endl;
    }else if(445 <= n && n <= 555){
        cout << 555 << endl;
    }else if(556 <= n && n <= 666){
        cout << 666 << endl;
    }else if(667 <= n && n <= 777){
        cout << 777 << endl;
    }else if(778 <= n && n <= 888){
        cout << 888 << endl;
    }else if(889 <= n && n <= 999){
        cout << 999 << endl;
    }
    return 0;
}

Measured memory_bytes: 256
N, M = gets.split.map(&:to_i)
queries = M.times.map { gets.split.map(&:to_i) }

if M == 0
  puts 'Yes'
  exit 0
end

graph = Array.new(N) { [] }
queries.each do |(l, r, d)|
  l -= 1
  r -= 1
  graph[l].push([r, d])
  graph[r].push([l, -d])
end

def bfs(graph, s, visited)
  w_list = Array.new(graph.size, nil)
  w_list[s] = 0
  queue = [s]
  while !queue.empty?
    u = queue.shift
    visited[u] = true
    graph[u].each do |(v, w)|
      next if visited[v]
      if w_list[v] && w_list[u] + w != w_list[v]
        return false
      elsif w_list[v].nil?
        w_list[v] = w_list[u] + w
        queue.push(v)
      end
    end
  end
  true
end

visited = {}
graph.each.with_index do |l, u|
  next if l.empty?
  next if visited[u]
  unless bfs(graph, u, visited)
    puts 'No'
    exit 0
  end
end
puts 'Yes'


Measured memory_bytes: 76908
#include<cstdio>
using namespace std;
int main(void){
	int a,b,c,x;
	int i,j,k;
	int sum,cnt;
	scanf("%d %d %d %d",&a,&b,&c,&x);
	cnt=0;
	for(i=0;i<=a;i++){
		for(j=0;j<=b;j++){
			for(k=0;k<=c;k++){
				sum=500*i+100*j+50*k;
				if(sum==x)	cnt++;
			}
		}
	}
	printf("%d\n",cnt);
	return 0;
}

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

int main() {
  int x,x500,x5;
  cin >> x;
  x500=x/500;
  x%=500;
  x5=x/5;
  cout << x500*1000 + x5*5 << endl;
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
///////////////////////////////////////////
const long long int INF = 1LL<<60;
const long long int Mod = 1000000007;
using ll = long long int; using ci = const int;
using vi = vector<int>;  using Vi = vector<long long int>;
using P = pair<int, int>;  using PLL = pair<ll, ll>;
using matrix = vector<vector<ll>>;
#define pb(x) push_back(x)
#define mp(x,y) make_pair(x,y)
#define all(x) (x).begin(),(x).end()
#define rp(i,N) for(ll i = 0; i < (ll)N; i++)
#define repi(i,a,b) for(ll i = ll(a); i < ll(b); ++i)
template<class T>bool chmax(T &former, const T &b) { if (former<b) { former=b; return true; } return false; }
template<class T>bool chmin(T &former, const T &b) { if (b<former) { former=b; return true; } return false; }
template<class T>T sqar(T x){ return x*x; }//sqrt(x)は平方根;
#define Sort(v) std::sort(v.begin(), v.end(), std::greater<decltype(v[0])>()) //降順でVをソート
#define p_queue(v) priority_queue<v, vector<v>, greater<v> >
template<class T> inline void princ(T x){cout<<x<<" ";}; 
template<class T> inline void print(T x){cout<<x<<"\n";};
template<class T> inline void Yes(T condition){ if(condition) cout << "Yes" << endl; else cout << "No" << endl; }
template<class T> inline void YES(T condition){ if(condition) cout << "YES" << endl; else cout << "NO" << endl; }
///////////////////////////////////////////////////////////////////////////////////

ll pow(ll x,ll y,ll mod){
    if(y==0) return 1;
    if(y&1) return x*pow(x,y-1,mod)%mod;
    ll p=pow(x,y/2,mod);
    return p*p%mod;
}

ll com(ll x,ll y,ll mod){
    ll res=1;
    rp(i,y) {
        res *= x-i;
        res %= mod;
    }
    rp(i,y){
        res *= pow(i+1,mod-2,mod);
        res %= mod;
    }
    return res;
}
int main(){
    int n,m;
    cin >> n >> m;
    vi p_count;
    for(int i=2; i*i<=m; i++){
        int ctr=0;
        while(m%i==0){
            m /= i;
            ctr++;
        }
        if(ctr) p_count.pb(ctr);
    }
    if(m!=1) p_count.pb(1);
    int ps=p_count.size();
    ll ans=1;
    for(auto p:p_count){
        ans *= com((ll)p+(ll)n-1ll,(ll)(n-1),Mod);
        ans %= Mod;
    }
    print(ans);
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
	string s;
	cin>>s;
	int ans=0,cnt=0;
	for(int i=0;i<s.size();i++){
		if(s[i]!='Z'&&cnt!=0){
			cnt++;
		}
		else if(s[i]=='A'){
			cnt++;
		}
		else if(s[i]=='Z'&&cnt!=0){
			cnt++;
			if(ans<cnt){
				ans=cnt;
			}
		}
	}
	cout<<ans<<endl;
}


Measured memory_bytes: 640
from collections import defaultdict
import bisect
n,m=map(int,input().split())
py=[[int(i) for i in input().split()] for _ in range(m)]

dic=defaultdict(list)
for  p,y in sorted(py):
    dic[p]+=[y]
for p,y in py:
    idx=bisect.bisect_right(dic[p],y)
    print('{:06g}{:06g}'.format(p,idx))

Measured memory_bytes: 41032
import java.util.*;

class Main{
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        int[] a = new int[2];
        for(int i = 0; i < 2; i++){
            a[i] = sc.nextInt();
        }
        sc.close();
        int[] b = new int[3];
        b[0] = a[0] + a[1];
        b[1] = a[0] - a[1];
        b[2] = a[0] * a[1];
        int MAX = MAX(b);
        System.out.println(MAX);
    }

    private static int MAX(int b[]){
        int MAX = b[0];
        if(b[0] < b[1]){
            MAX = b[1];
        }
        if(MAX < b[2]){
            MAX = b[2];
        }
        return MAX;
    }
}

Measured memory_bytes: 23764
#include<stdio.h>
#define MAX 45//4４番めまで行ける
int F[MAX];

int fibona(int n){
  int i=2;
  if(n==0||n==1) return F[n]=1; 
  else if(F[n]==-1)return F[n]=fibona(n-1)+fibona(n-2); //need calcule
  else return F[n];//already calculed
}

int main(){
  int n;
  int i;

  for(i=0;i<45;i++)F[i]=-1;

  scanf("%d",&n);
  printf("%d\n",fibona(n));
  return 0;
}



Measured memory_bytes: 2084
#include <bits/stdc++.h>
using namespace std;
int main(){
    int sx,sy,tx,ty;
    scanf("%d%d%d%d",&sx,&sy,&tx,&ty);
    int dx = tx-sx;
    int dy = ty-sy;
    string ans = "";
    ans += string(dy,'U') + string(dx,'R');
    ans += string(dy,'D') + string(dx,'L');
    ans += "L" + string(dy+1,'U') + string(dx+1,'R') + "D";
    ans += "R" + string(dy+1,'D') + string(dx+1,'L') + "U";
    cout << ans;



}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <deque>
#include <algorithm>
#include <numeric>
#include <string>
#include <cstring>
#include <list>
#include <unordered_set>
#include <tuple>
#include <cmath>
#include <limits>
#include <type_traits>
#include <iomanip>
#include <map>
#include <unordered_map>
#include <queue>
#include <stack>
#include <set>
#include <bitset>
#include <regex>
#include <random>
#include<bits/stdc++.h>

using namespace std;

typedef long long ll;
#define rep(i,n)for(ll i=0;i<n;++i)
#define exout(x) printf("%.10f\n", x)
#define chmax(x,y) x=max(x,y)
#define chmin(x,y) x=min(x,y)
const double pi = acos(-1.0);
const ll MOD = 1000000007;
const ll INF = 1e18;
const ll MAX_N = 201010;

//組み合わせの余りを求める
ll fac[MAX_N], finv[MAX_N], inv[MAX_N];
void COMinit() {
	fac[0] = fac[1] = 1;
	finv[0] = finv[1] = 1;
	inv[1] = 1;
	for (int i = 2; i < MAX_N; i++) {
		fac[i] = fac[i - 1] * i % MOD;
		inv[i] = MOD - inv[MOD % i] * (MOD / i) % MOD;
		finv[i] = finv[i - 1] * inv[i] % MOD;
	}
}

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

//最大公約数
ll gcd(ll x, ll y) {
	return y ? gcd(y, x % y) : x;
}

ll lcm(ll x, ll y) {
	if (x == 0 || y == 0)return 0;
	return (x / gcd(x, y) * y);
}

ll dx[4] = { 0,0,-1,1 };
ll dy[4] = { -1,1,0,0 };
ll dp[201010];

//long longしか使わない
//素数は1より大きい
//lower_boundは指定したkey以上の要素の一番左のイテレータをかえす
//upper_boundは指定したkeyより大きい要素の一番左のイテレータをかえす
int main() {
	ll n, k;
	cin >> n >> k;
	vector<pair<ll, ll>>p(k);
	ll waru = 998244353;
	rep(i, k) {
		ll r, l;
		cin >> l >> r;
		r++;
		p[i].first = l;
		p[i].second = r;
	}
	dp[0] = 1;
	dp[1] = -1;
	rep(i, n-1) {
		dp[i + 1] += dp[i];
		dp[i + 1] %= waru;
		rep(j, k) {
			if (i + p[j].first < n)dp[i + p[j].first] += dp[i];
			dp[i + p[j].first] %= waru;
			if (i + p[j].second < n)dp[i + p[j].second] -= dp[i];
			dp[i + p[j].second] += waru;
			dp[i + p[j].second] %= waru;
		}
	}
	cout << dp[n - 1] << endl;
	return 0;
}


Measured memory_bytes: 6736
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<n;i++)
#define ll int64_t
#define all(v) v.begin(), v.end()
#define bitrep(n) for(int bit=0;bit<(1<<n);bit++)

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

  cout << fixed << setprecision(18);

  cout << A/B << endl;
  
  return 0;
}

Measured memory_bytes: 256
import java.util.*;

public class Main{

public static void main(String[] args){
Scanner sc = new Scanner(System.in);
int[] mountains = new int[10];

for(int i=0; i<10; i++){
mountains[i] = sc.nextInt();
}

Arrays.sort(mountains);
System.out.println(mountains[9]);
System.out.println(mountains[8]);
System.out.println(mountains[7]);
}


}

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

using namespace std;

const int MaxN = 1e5 + 15;

int n, h;

pair<int, int> a[MaxN];
long long c[MaxN];

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

    cin >> n >> h;

    int mx = 0;

    for(int i = 1; i <= n; ++i)
    {
        cin >> a[i].second >> a[i].first;
        mx = max(mx, a[i].second);
    }
    sort(a + 1, a + n + 1);
    for(int i = n; i; --i)
        c[i] = c[i + 1] + a[i].first;

    long long ans = 1e9;

    for(int i = n + 1; i; --i)
    {
        if(c[i] >= h)
            ans = min(ans, n - i + 1ll);
        else
            ans = min(ans, n - i + 1 + (h - c[i]) / mx + ((h - c[i]) % mx ? 1 : 0));
    }

    cout << ans << '\n';
    return 0;
}


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

def solve():
    import itertools
    import copy

    K = int(input())
    grid = [[0 for i in range(8)] for j in range(8)]

    def put_queen(grid, r, c):
        for j in range(8):
            grid[r][j] = -1
        for i in range(8):
            grid[i][c] = -1
        # 左上
        i, j = r-1, c-1
        while i >= 0 and j >= 0:
            grid[i][j] = -1
            i, j = i-1, j-1
        # 左下
        i, j = r+1, c-1
        while i < 8 and j >= 0:
            grid[i][j] = -1
            i, j = i+1, j-1
        # 右上
        i, j = r-1, c+1
        while i >= 0 and j < 8:
            grid[i][j] = -1
            i, j = i-1, j+1
        # 右下
        i, j = r+1, c+1
        while i < 8 and j < 8 :
            grid[i][j] = -1
            i, j = i+1, j+1
        grid[r][c] = 1


    for i in range(K):
        r, c = list(map(int, input().split()))
        put_queen(grid, r, c)

    # 8!を全探索
    ps = itertools.permutations([i for i in range(8)], r=8)
    for p in ps:
        ans_grid = copy.deepcopy(grid)
        is_ok = True
        for i in range(8):
            if ans_grid[i][p[i]] == 1:
                continue
            if ans_grid[i][p[i]] == -1:
                is_ok = False
                break
            put_queen(ans_grid, i, p[i])
        if is_ok:
            break

    # ans_gridを出力して終了
    for i in range(8):
        s = ""
        for j in range(8):
            if ans_grid[i][j] == 1:
                s += "Q"
            else:
                s += "."
        print(s)


if __name__ == "__main__":
    solve()



Measured memory_bytes: 6340
#include <iostream>
#include <string>
#include <vector>
#include <cmath>
#include <algorithm>
#include <cstdlib>
#include <ctime>
#include <cstdio>
#include <functional>
#include <set>
#include <sstream>
#include <map>
#include <queue>
#include <stack>

using namespace std;


const int dx[]={0,0,-1,1};
const int dy[]={-1,1,0,0};

int main()
{
	int n,q;
	while(cin>>n>>q,n||q){
		vector<string> name(n);
		vector<long long> a(n),b(n);

		for(int i=0;i<n;i++) cin>>name[i]>>a[i]>>b[i];

		for(int i=0;i<q;i++){
			long long y;
			cin>>y;

			bool unknown=true;

			for(int i=0;i<n && unknown;i++){
				if(b[i]-a[i]+1<=y && y<=b[i]){
					unknown=false;
					cout<<name[i]<<" "<<y-b[i]+a[i]<<endl;
				}
			}

			if(unknown) cout<<"Unknown"<<endl;

		}

	}

	return 0;
}

Measured memory_bytes: 1292
#include<bits/stdc++.h>
#define r(i,n) for(int i=0;i<n;i++)
using namespace std;
typedef pair<int,int>P;
int dx[]={1,1,-1,-1};
int dy[]={-1,1,1,-1};
int Con(char c){
  if(c=='S')return 3;
  if(c=='E')return 0;
  if(c=='N')return 1;
  if(c=='W')return 2;
}
int x,y,X,Y,n,w,h,l,r,d,cnt,ans=1e7;
char c;
map<P,int>m;
void init(){
  r(i,w+1)m[P(0,i)]=cnt++;
  r(i,h+1)m[P(i,w)]=cnt++;
  r(i,w+1)m[P(h,w-i)]=cnt++;
  r(i,h+1)m[P(h-i,0)]=cnt++;
}
signed main(){
  vector<P>v;
  cin>>n>>w>>h;
  init();
  r(i,n){
    cin>>X>>Y>>c;
    d=Con(c);
    x=X;y=Y;
    while(0<x&&x<w&&0<y&&y<h){
      x+=dx[d];
      y+=dy[d];
    }
    l=m[P(y,x)];
    x=X;y=Y;
    while(0<x&&x<w&&0<y&&y<h){
      x+=dx[(d+1)%4];
      y+=dy[(d+1)%4];
    }
    r=m[P(y,x)];
    v.push_back(P(r,l));
  }
  sort(v.begin(),v.end());
  r(i,n){
    int now=v[i].first,count=1;
    for(int k=0,j=i;k<n;k++,j=(j+1)%n){
      r=v[j].first;
      l=v[j].second;
      if(l>r){
        if(!((l<=now&&now<=cnt)||(0<=now&&now<=r))){
          now=r;
          count++;
        }
      }
      else{
        if(!(l<=now&&now<=r)){
          now=r;
          count++;
        }
      }
    }
    ans=min(ans,count);
  }
  cout<<ans<<endl;
}


Measured memory_bytes: 28124
#include <bits/stdc++.h>
using namespace std;
using Int = long long;
#define PUTS(x) cout << (x) << endl;
#define rep(i, n) for (int i = 0, i##_len = (int)(n); i < i##_len; i++)
int main() {
    Int n, m, q;
    cin >> n >> m >> q;
    auto a = vector<vector<int>>(n, vector<int>(n, 0));
    rep(i, m) {
        Int l, r;
        cin >> l >> r;
        l--;
        r--;
        a[l][r]++;
    }
    auto s = vector<vector<int>>(n, vector<int>(n, 0));
    rep(i, n) {
        rep(j, n) {
            Int result = a[i][j];
            if (i > 0) result += s[i - 1][j];
            if (j > 0) result += s[i][j - 1];
            if (i > 0 && j > 0) result -= s[i - 1][j - 1];
            s[i][j] = result;
        }
    }
    rep(i, q) {
        Int p, q;
        cin >> p >> q;
        p--;
        q--;
        Int ans = s[n - 1][q];
        if (p > 0) ans -= s[p - 1][q];
        PUTS(ans);
    }
}


Measured memory_bytes: 2944
# 入力が10**5とかになったときに100ms程度早い
import sys
read = sys.stdin.readline


def read_ints():
    return list(map(int, read().split()))


def read_a_int():
    return int(read())


def read_matrix(H):
    '''
    H is number of rows
    '''
    return [list(map(int, read().split())) for _ in range(H)]


def read_map(H):
    '''
    H is number of rows
    文字列で与えられた盤面を読み取る用
    '''
    return [read()[:-1] for _ in range(H)]


def read_col(H, n_cols):
    '''
    H is number of rows
    n_cols is number of cols

    A列、B列が与えられるようなとき
    '''
    ret = [[] for _ in range(n_cols)]
    for _ in range(H):
        tmp = list(map(int, read().split()))
        for col in range(n_cols):
            ret[col].append(tmp[col])

    return ret


N = read_a_int()
A = read_ints()
now = 1
for a in A:
    if a == now:
        now += 1

if now == 1:
    print(-1)
else:
    print(N - now + 1)


Measured memory_bytes: 25568
#include <stdio.h>

#define DENOM 1000000007LL

int main(void) {
    int i, j, H, W;
    char map[1010][1010];
    long long dp[1010][1010];
    scanf("%d%d", &H, &W);
    for (i=1;i<=H;i++) scanf("%s", &map[i][1]);

    for (i=1;i<=H;i++) for (j=1;j<=W;j++) {
        if (map[i][j] == '#') dp[i][j] = 0;
        else if (i == 1 && j == 1) dp[i][j] = 1;
        else if (i == 1) dp[i][j] = dp[i][j-1];
        else if (j == 1) dp[i][j] = dp[i-1][j];
        else dp[i][j] = dp[i-1][j] + dp[i][j-1];
        dp[i][j] %= DENOM;
    }
    printf("%lld\n", dp[H][W] % DENOM);
    return 0;
}

Measured memory_bytes: 9088
#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < n; i++)
#define PI       3.1415926535897932384626433832795028841971
#define INF 1000000000
#define EPS      1e-10
#define MOD      1000003
#define HOGE 100000
#define HUGA 100000
using namespace std;
typedef long long ll;
typedef pair<double,double> P;
typedef pair<double,P> PQ;

int n, m, t;
bool x[10001];

int main(){
    cin >> n >> m >> t;
    int cnt = 0;
    rep(i,n){
        int z;
        cin >> z;
        for(int j = z-m; j < z+m; j++){
            if(j < 0 || j >= t) continue;
            x[j] = true;
        }
    }
    for(int j = 0; j < t; j++){
        if(x[j]) continue;
        cnt++;
    }
    cout << cnt << endl;
}

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

#define scd second
#define fst first
#define mkp make_pair
#define pb push_back
#define pf push_front

using namespace std;

typedef long long ll;
typedef pair<int,int> pii;
typedef vector<int> vint;
typedef vector<ll> vlong;
typedef vector<vint> vvint;
typedef vector<vlong> vvlong;
typedef vector<bool> vbool;

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

    int n, m;
    cin>>n>>m;
    vector<int> h(n);
    for(auto &x : h) cin>>x;
    vector<int> gr(n,0);
    while(m--){
        int ai, bi;
        cin>>ai>>bi;
        gr[ai-1]=max(gr[ai-1],h[bi-1]);
        gr[bi-1]=max(gr[bi-1],h[ai-1]);
    }

    int ans=0;
    for(int i=0; i<n; i++) {
        if(h[i]>gr[i]) ans++;
    }
    cout<<ans<<endl;
}

Measured memory_bytes: 3988
package main

import (
	"bufio"
	"container/heap"
	"fmt"
	"os"
	"strconv"
)

type Scanner struct {
	sc *bufio.Scanner
}

func NewScanner() *Scanner {
	sc := bufio.NewScanner(os.Stdin)
	sc.Split(bufio.ScanWords)
	sc.Buffer(make([]byte, 1024), int(1e+9))
	return &Scanner{sc}
}

func (s *Scanner) nextStr() string {
	s.sc.Scan()
	return s.sc.Text()
}

func (s *Scanner) nextInt() int {
	i, e := strconv.Atoi(s.nextStr())
	if e != nil {
		panic(e)
	}
	return i
}

func (s *Scanner) nextRuneSlice() []rune {
	return []rune(s.nextStr())
}

func (s *Scanner) nextIntSlice(n int) []int {
	res := make([]int, n)
	for i := 0; i < n; i++ {
		res[i] = s.nextInt()
	}
	return res
}

type IntHeap []int

func (h IntHeap) Len() int           { return len(h) }
func (h IntHeap) Less(i, j int) bool { return h[i] > h[j] }
func (h IntHeap) Swap(i, j int)      { h[i], h[j] = h[j], h[i] }

func (h *IntHeap) Push(x interface{}) {
	*h = append(*h, x.(int))
}

func (h *IntHeap) Pop() interface{} {
	old := *h
	n := len(old)
	x := old[n-1]
	*h = old[0 : n-1]
	return x
}

func main() {
	sc := NewScanner()
	N, M := sc.nextInt(), sc.nextInt()
	arr := make([][]int, M)
	for i := 0; i < N; i++ {
		a, b := sc.nextInt(), sc.nextInt()
		if a > M {
			continue
		}
		arr[M-a] = append(arr[M-a], b)
	}
	h := &IntHeap{}
	heap.Init(h)
	ans := 0
	for i := M - 1; i >= 0; i-- {
		for _, v := range arr[i] {
			heap.Push(h, v)
		}
		if h.Len() > 0 {
			ans += heap.Pop(h).(int)
		}
	}
	fmt.Println(ans)
}


Measured memory_bytes: 8832
import Control.Monad
import Control.Applicative
import Data.Functor
import Data.Function
import Data.Monoid
import Data.Maybe
import Data.List
import Data.Foldable (foldMap)
import Data.List.Split
import Data.Char
import Data.Ratio
import Data.Ord
import Data.Array.IO
import Data.IORef
 
readInt = read :: String -> Int
readDouble = read :: String -> Double
getInt = readLn :: IO Int
getInts = map readInt . words <$> getLine
sjoin :: (Show a) => [a] -> String
sjoin = unwords . map show
cond :: a -> a -> Bool -> a
cond t f c = if c then t else f
applyBin :: (b -> c -> d) -> (a -> b) -> (a -> c) -> a -> d
applyBin op f g x = op (f x) $ g x
applyUni :: (a -> b -> c) -> (a -> b) -> a -> c
applyUni op f x = op x $ f x
applyTuple :: (a -> b, a -> c) -> a -> (b, c)
applyTuple (f,g) a = (f a, g a)
-- end of templete

f :: (IOUArray (Int,Int) Char) -> (Int,Int) -> IO ()
f arr p@(y,x) = do
    c <- readArray arr p
    when (c=='1') $ do
        writeArray arr p '0'
        forM_ [1..3] $ \i -> do
            when (y-i>=1) $ f arr (y-i,x)
            when (y+i<=8) $ f arr (y+i,x)
            when (x-i>=1) $ f arr (y,x-i)
            when (x+i<=8) $ f arr (y,x+i)




main = do
    n <- getInt
    forM_ [1..n] $ \i -> do
        getLine
        field <- replicateM 8 getLine
        [sx, sy] <- replicateM 2 getInt
        arr <- newListArray ((1,1),(8,8)) $ concat field :: IO (IOUArray (Int,Int) Char)
        f arr (sy,sx)
        res <- sequence [sequence [readArray arr (y,x) | x <- [1..8]] | y <- [1..8]]
        putStrLn $ "Data " ++ show i ++ ":"
        mapM_ putStrLn res
        return ()

Measured memory_bytes: 4292
S = raw_input()
if "A" not in S:
    print -1
else:
    ans = "A"
    for s in S[S.index("A") + 1:]:
        if ans[-1] == "A" and s == "Z": ans += s
        if ans[-1] == "Z" and s == "A": ans += s
    if ans[-1] == "A": ans = ans[:-1]
    print ans if ans else -1

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

using namespace std;

typedef long long ll;
typedef unsigned long long ull;

#define Abs(x)((x) < 0 ? (x) * -1 : (x))

#define rep(x, y) for ((x) = 0; (x) < (y); (x)++)
#define repin(x, y) for ((x) = 0; (x) <= (y); (x)++)
#define nep(x, y) for ((x) = (y) - 1; 0 <= (x); (x)--)
#define nepi(x, y, z) for ((x) = (y) - 1; (z) <= (x); (x)--)
#define repi(x, y, z) for ((x) = (z); (x) < (y); (x)++)
#define repiin(x, y, z) for ((x) = (z); (x) <= (y); (x)++)
#define reps(x, y, z) for ((x) = 0; (x) < (y); (x) += (z))
#define repis(x, y, z, s) for ((x) = (z); (x) < (y); (x) += (s))
#define repiins(x, y, z, s) for ((x) = (z); (x) <= (y); (x) += (s))
#define repit(x) for (__typeof((x).begin()) it = (x).begin(); it != (x).end(); it++)
#define nepit(x) for (__typeof((x).rbegin()) it = (x).rbegin(); it != (x).rend(); it++)

#define All(x) (x).begin(),(x).end()

#define Mem0(x) memset(x, 0, sizeof(x))
#define Mem1(x) memset(x, -1, sizeof(x))

#define Unique(v) v.resize(unique(All(v)) - v.begin())

#define peq(p0, p1)(p0.first == p1.first && p0.second == p1.second)

#define End '\n'
#define Out(x) cout<<(x)<<End
#define OutP(p, sep, end) cout<<p.first<<sep<<p.second<<end

template<typename T> inline bool Max(T &x, const T &y) { return x < y ? x = y, 1 : 0; }
template<typename T> inline bool Min(T &x, const T &y) { return x > y ? x = y, 1 : 0; }
template<typename T> using V = vector<T>;
template<typename T> using VV = V<V<T> >;

#define Vsort(v) sort(All(v))
#define VsortR(v) sort(All(v), std::greater<__typeof(v[0])>())

#define pb push_back
#define mp make_pair
#define X first
#define Y second
#define lb std::lower_bound
#define ub std::upper_bound

#define lbi(v, x) lb(All(v), (x))-v.begin()
#define ubi(v, x) ub(All(v), (x))-v.begin()

static const ll MOD = 1e9 + 7;
static const double PI = 3.141592653589793;

#define LOCAL 0

int main()
{
#if LOCAL
    freopen("in.txt", "r", stdin);
    freopen("out.txt", "w", stdout);
    freopen("debug.txt", "w", stderr);
#endif

    cin.tie(0);
    ios::sync_with_stdio(false);
	//std::cout.precision(18);

    int n;

	cin >> n;

	int ans = 0;

	int i, j;

	rep(i, n) {
		rep(j, n) {
			if (n < i * 4 + j * 7) break;

			if (i * 4 + j * 7 == n) {
				Out("Yes");

				return 0;
			}
		}
	}

	Out("No");
	
	return 0;
}


Measured memory_bytes: 256
#[allow(unused_imports)]
use std::collections::HashSet;

#[allow(dead_code)]
fn read<T: std::str::FromStr>() -> T {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).ok();
    s.trim().parse().ok().unwrap()
}

#[allow(dead_code)]
fn read_vec<T: std::str::FromStr>() -> Vec<T> {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).ok();
    s.trim()
        .split_whitespace()
        .map(|e| e.parse().ok().unwrap())
        .collect()
}

fn main() {
    let hw = read_vec::<usize>();
    let h = hw[0];
    let w = hw[1];

    let mut masu : Vec<Vec<char>> = Vec::with_capacity(h);
    for _i in 0..h {
        let s : Vec<char> = read::<String>().chars().collect();
        masu.push(s);
    }

    let answer = solve(h, w, &masu);
    println!("{}", answer);
}

fn solve(h: usize, w: usize, masu: &[Vec<char>]) -> usize {

    let mut dp : Vec<Vec<(usize, usize)>> = vec![vec![(0, 0);w];h];
    let mut max = 0;
    for i in 0..h {
        for j in 0..w {

            if masu[i][j] == '#' {
                continue;
            }

            // yoko
            if j == 0 || masu[i][j-1] == '#' {
                let mut j1 = j + 1;
                while j1 < w && masu[i][j1] != '#' {
                    j1 += 1;
                }
                dp[i][j].0 = j1 - j - 1;
                
            } else {
                dp[i][j].0 = dp[i][j-1].0;
            }

            // tate
            if i == 0 || masu[i-1][j] == '#' {
                let mut i1 = i + 1;
                while i1 < h && masu[i1][j] != '#' {
                    i1 += 1;
                }
                dp[i][j].1 = i1 - i - 1;

            } else {
                dp[i][j].1 = dp[i-1][j].1;
            }

            let val = dp[i][j].0 + dp[i][j].1;
            if val > max {
                max = val;
            }
        }
    }
    return max + 1;
}


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

struct Card {
    char pic;
    int num;
};

void merge(vector<Card> &C1, int left, int mid, int right) {
    int n1, n2;
    n1 = mid - left;
    n2 = right - mid;
    vector<Card> L(n1 + 1);
    vector<Card> R(n2 + 1);
    for (int i = 0; i < n1; i++) {
        L.at(i) = C1.at(left + i);
    }
    L.at(n1).pic = 'Z';
    L.at(n1).num = 1000000001;
    for (int i = 0; i < n2; i++) {
        R.at(i) = C1.at(mid + i);
    }
    R.at(n2).pic = 'Z';
    R.at(n2).num = 1000000001;

    int i, j;
    i = 0;
    j = 0;
    for (int k = left; k < right; k++) {
        if (L.at(i).num <= R.at(j).num) {
            C1.at(k) = L.at(i);
            i++;
        } else {
            C1.at(k) = R.at(j);
            j++;
        }
    }
}

void mergeSort(vector<Card> &C1, int left, int right) {
    if (left + 1 < right) {
        int mid = (left + right) / 2;
        mergeSort(C1, left, mid);
        mergeSort(C1, mid, right);
        merge(C1, left, mid, right);
    }
}

bool isStable(vector<Card> &C1, vector<Card> &C2) {
    for (int i = 0; i < C1.size(); i++) {
        if (C1.at(i).pic != C2.at(i).pic) {
            return false;
        }
    }

    return true;
}

int partition(vector<Card> &C2, int p, int r) {
    Card t, x;
    x = C2.at(r);
    int i = p - 1;
    for (int j = p; j < r; j++) {
        if (C2.at(j).num <= x.num) {
            t = C2.at(++i);
            C2.at(i) = C2.at(j);
            C2.at(j) = t;
        }
    }
    t = C2.at(++i);
    C2.at(i) = C2.at(r);
    C2.at(r) = t;

    return i;
}

void quickSort(vector<Card> &C2, int p, int r) {
    if (p < r) {
        int q = partition(C2, p, r);
        quickSort(C2, p, q - 1);
        quickSort(C2, q + 1, r);
    }
}

int main() {
    int n;
    cin >> n;
    vector<Card> C1(n);
    vector<Card> C2(n);
    for (int i = 0; i < n; i++) {
        char c;
        int x;
        cin >> c;
        scanf("%d", &x);
        C1.at(i).pic = C2.at(i).pic = c;
        C1.at(i).num = C2.at(i).num = x;
    }

    mergeSort(C1, 0, n);
    quickSort(C2, 0, n - 1);

    if (isStable(C1, C2)) {
        cout << "Stable" << endl;
    } else {
        cout << "Not stable" << endl;
    }
    for (int i = 0; i < n; i++) {
        printf("%c %d\n", C2.at(i).pic, C2.at(i).num);
    }
}


Measured memory_bytes: 5216
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const long long INF = 1LL << 60;

int main() {
    int N;
    cin >> N;
    vector<int> A(N);

    for(int i=0; i<N; i++) {
        int x;
        cin >> x;
        A[x-1] = i + 1;
    }
    for(int i=0; i<N; i++) {
        cout << A[i] << " ";
    }

}

Measured memory_bytes: 3624
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i = 0; i < (int)n; i++)
using ll = long long;
const ll INF = 1e18;

int main(){
  ll n, k;
  cin >> n >> k;
  ll h[n+1];
  h[0] = 0;
  rep(i,n) cin >> h[i+1];
  vector<vector<ll>> dp(n+1,vector<ll>(n+1,INF));
  dp[0][0] = 0;
  for(int i = 1; i <= n; i++) {
    for(int j = 1; j <= n; j++) {
      rep(k,i) {  
        dp[i][j] = min(dp[i][j],dp[k][j-1]+max((ll)0,h[i]-h[k]));
      }
    }
  }
  ll ans = INF;
  rep(i,n+1) ans = min(ans,dp[i][n-k]);
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 1024
#include<bits/stdc++.h>
/* #define int long long */
#define rep(i, n) for(int i = 0; i < (int)n; i++)
#define repa(i, s, n) for(int i = s; i < (int)n; i++)
using namespace std;
using ll = long long;
typedef vector<int> vi;
typedef pair<int, int> P;
#define rrep(i,a,b) for(int i=a;i>=b;i--)
#define MOD 1000000007
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }

const int INF = 200000;
signed main(){
    int n;
    cin >> n;

    vi money;
    money.push_back(1);
    for(int tmp = 6; tmp <= n; tmp *= 6) money.push_back(tmp);
    for(int tmp = 9; tmp <= n; tmp *= 9) money.push_back(tmp);
    sort(money.begin(), money.end());

    vi dp(100100, INF);
    dp[0] = 0;

    rep(i, n+1){
        rep(j, money.size()){
            if(i+1 - money[j] < 0) continue;
            chmin(dp[i+1], dp[i+1 - money[j]] + 1);
        }
    }

    cout << dp[n] << endl;
}

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

int a[8];
int main() {
	while (1) {
		string m = "41412121";
		rep(i, 8) {
			if (!(cin >> a[i]))return 0;
		}
		string k;
		int M = INT_MAX;
		rep(i, 8) {
			rotate(m.begin(), m.begin() + 1, m.end());
			int s = 0;
			rep(j, 8)s += max(0, a[j] + '0' - m[j]);
			if (s < M) { M = s; k = m; }
			if (s == M&&m < k)k = m;
		}
		rep(i, 8)cout << k[i] << (i == 7 ? "\n" : " ");
	}
}

Measured memory_bytes: 3048
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    ll i,j,k,l,m,n,o,p,q,r,s,t,x,a[500][500],vis[500][500],tt=0;
    cin>>i>>j>>k;
    swap(i,j);
    swap(i,k);
    cout<<i<<" "<<j<<" "<<k<<endl;
    return 0;
}
    

Measured memory_bytes: 256
#include <vector>
#include <list>
#include <map>
#include <set>
#include <unordered_set>
#include <unordered_map>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <queue>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>
#include <fstream>
#include <cstdio>
#include <climits>
#include <complex>
#include <cstdint>
#include <tuple>

#define M_PI       3.14159265358979323846

using namespace std;

//conversion
//------------------------------------------
inline int toInt(string s) { int v; istringstream sin(s); sin >> v; return v; }
template<class T> inline string toString(T x) { ostringstream sout; sout << x; return sout.str(); }
inline int readInt() { int x; scanf("%d", &x); return x; }

//typedef
//------------------------------------------
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef pair<int, PII> TIII;
typedef long long LL;
typedef unsigned long long ULL;
typedef vector<LL> VLL;
typedef vector<VLL> VVLL;

//container util

//------------------------------------------
#define ALL(a)  (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define MP make_pair
#define SZ(a) int((a).size())
#define SQ(a) ((a)*(a))
#define EACH(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort((c).begin(),(c).end())

//repetition
//------------------------------------------
#define FOR(i,s,n) for(int i=s;i<(int)n;++i)
#define REP(i,n) FOR(i,0,n)
#define MOD 1000000007

#define rep(i, a, b) for(int i = a; i < (b); ++i)
#define trav(a, x) for(auto& a : x)
#define all(x) x.begin(), x.end()
#define sz(x) (int)(x).size()


struct Edge {
    int to, cost, nm;
    Edge(int to, int cost, int nm): to(to), cost(cost), nm(nm) {}
};

typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<vector<Edge>> AdjList;
AdjList graph;
#define chmin(x,y) x=min(x,y)
#define chmax(x,y) x=max(x,y)
const int INF = 100000000;

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

bool cmp(const pii& a, const pii& b){
    if(a.first == b.first){
        return a.second < b.second;
    }
    return a.first < b.first;
}

int arr[6];
int main() {


    int d; cin >> d;
    REP(i, d){
        cout << "Case " << i+1 << ":" << endl;
        int n; cin >> n;

        for(int j=0; j<10; ++j){
            n = n*n;
            int nn = 0;
            for(int k=3; k>=0; --k){
                nn = nn*10 + (int)(n/pow(10, k+2))%10;
            }

            n = nn;
            cout << n << endl;
        }
    }
    return 0;
}


Measured memory_bytes: 3220
pub fn read<T: std::str::FromStr>() -> T {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).ok();
    s.trim().parse().ok().unwrap()
}

pub fn read_vec<T: std::str::FromStr>() -> Vec<T> {
    read::<String>()
        .split_whitespace()
        .map(|e| e.parse().ok().unwrap())
        .collect()
}

pub fn read_vec2<T: std::str::FromStr>(n: usize) -> Vec<Vec<T>> {
    (0..n).map(|_| read_vec()).collect()
}

pub fn read_col<T: std::str::FromStr>(n: usize) -> Vec<T> {
    (0..n).map(|_| read()).collect()
}

fn main() {
    let nc: Vec<usize> = read_vec();
    let n = nc[0];
    let mut stc: Vec<Vec<u32>> = read_vec2(n);
    stc.sort_by(|a, b| {
        if a[2] == b[2] {
            a[0].partial_cmp(&b[0]).unwrap()
        } else {
            a[2].partial_cmp(&b[2]).unwrap()
        }
    });

    let mut s: Vec<u32> = vec![];
    let mut t: Vec<u32> = vec![];
    s.push(stc[0][0]);
    for i in 1..n {
        if stc[i][2] != stc[i - 1][2] || stc[i - 1][1] != stc[i][0] {
            t.push(stc[i - 1][1]);
            s.push(stc[i][0]);
        }
    }
    t.push(stc[n - 1][1]);
    s.sort();
    t.sort();

    let mut j = 0;
    let mut ans = 1;
    for i in 1..s.len() {
        while t[j] < s[i] {
            j += 1;
        }
        let tmp = i - j + 1;
        if tmp > ans {
            ans = tmp;
        }
    }

    println!("{}", ans);
}


Measured memory_bytes: 10620
// In The Name Of God
#include <bits/stdc++.h>
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>

#define sqr(A) ((A) * (A))
#define X first
#define Y second
#define MP make_pair
#define bsz  __builtin_popcount
#define all(A) A.begin(), A.end()
using namespace std;
using namespace __gnu_pbds;
template < typename T >
using ordered_set = tree < T , null_type , less < T > , rb_tree_tag , tree_order_statistics_node_update >;
typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;
const int MOD = 1e9 + 7;
const int MOD2 = 1e9 + 9;
const int PR = 727;
const int INF = INT_MAX;
const ll LINF = LLONG_MAX;

const int N = 1e5 + 20;
vector<int> G[N];
ll dp[N][2], n;

void dfs(int v, int p = -1) {
	if (!G[v].size())
		dp[v][0] = dp[v][1] = 1;
	ll res0 = 1, res1 = 1;
	for (int u : G[v])
		if (u - p) {
			dfs(u, v);
			res0 = (res0 * (dp[u][0] + dp[u][1])) % MOD;
			res1 = (res1 * dp[u][0]) % MOD;
		}
	dp[v][0] = res0;
	dp[v][1] = res1;
}

int main() {
	ios::sync_with_stdio(false), cin.tie(0), cout.tie(0);
	cin >> n;
	for (int i = 0, v, u; i < n - 1; i++) {
		cin >> v >> u;
		G[v].push_back(u);
		G[u].push_back(v);
	}
	dfs(1);
	cout << (dp[1][0] + dp[1][1]) % MOD << endl;
}



Measured memory_bytes: 14208