akhauriyash/Code-Regression huggingface dataset:
#include<stdio.h>

int main(void)
{
long int x,a,b;

scanf("%ld %ld %ld", &x, &a, &b);

if( a + x < b){
printf("dangerous\n");
}else if(a < b){
printf("safe\n");
}else{
printf("delicious\n");
}

return 0;
}

Measured memory_bytes: 128
#include <iostream>
#include <vector>
#include <string>
#include <queue>
#include <algorithm>

using namespace std;

class Node {
public:


	int cost;
	int index;

	Node(int _index = 0,int _cost = 0)
		:index(_index),cost(_cost)
	{}
};


int N;
vector<vector<bool>> S;

int main()
{
	int ans = 0;
	cin >> N;

	S = vector<vector<bool>>(N+1,vector<bool>(N+1,false));

	for (int i = 1; i <= N; i++) {
		string tmp;
		cin >> tmp;
		for (int j = 1; j <= N; j++) {


			if (tmp.at(j-1) == '1') {
				S.at(i).at(j) = true;
			}
		}
	}



	for (int s = 1; s <= N && ans != -1; s++) {
		vector<int> close = vector<int>(N + 1, 0);
		auto c = [](Node l, Node r) { return l.cost > r.cost; };
		priority_queue<Node, vector<Node>, decltype(c)> open(c);
		int max_cost = 0;

		open.push(Node(s,1));
		close.at(s) = 1;
		bool cont = true;
		while (!open.empty() && cont && ans != -1) {
			Node tgt = open.top();
			open.pop();

			int ti = tgt.index;
			int cost = tgt.cost + 1;
			

			for (int i = 1; cont && ans != -1 && i <= N; i++) {
				if (S.at(ti).at(i)) {
					if (close.at(i) == 0) {

						close.at(i) = cost;
						open.push(Node(i, close.at(i)));
						max_cost = max(cost, max_cost);
					}
					else {
						if (close.at(i) == cost - 1) {
							ans = -1;
							break;
						}
						if (close.at(i) < cost - 2) {
							cont = false;
							break;
						}
					}
				}
			}
		}

		if (ans != -1) {
			ans = max(ans, max_cost);
		}
	}
	cout << ans <<endl;

	return 0;
}


Measured memory_bytes: 256
// Author: 23forever
#include <bits/stdc++.h>
#define pii pair<int, int>
#define mp make_pair
#define fi first
#define se second
typedef long long LL;
const int MAXN = 200000;
using namespace std;

inline int read() {
  int x = 0, w = 1;
  char c = ' ';

  while (c < '0' || c > '9') {
    c = getchar();
    if (c == '-') w = -1;
  }
  while (c >= '0' && c <= '9') {
    x = (x << 1) + (x << 3) + (c ^ 48);
    c = getchar();
  }

  return x * w;
}

int n, h[MAXN + 5], dp[MAXN + 5];

void init() {
  n = read();
  for (int i = 1; i <= n; ++i) h[i] = read();
}

int main() {
#ifdef forever23
  freopen("test.in", "r", stdin);
  //freopen("test.out", "w", stdout);
#endif
  init();

  dp[0] = dp[1] = 0;
  dp[2] = fabs(h[2] - h[1]);
  for (int i = 3; i <= n; ++i) {
    LL w1 = fabs(h[i] - h[i - 1]), w2 = fabs(h[i] - h[i - 2]);
    dp[i] = min(dp[i - 1] + w1, dp[i - 2] + w2);
  }

  printf("%d\n", dp[n]);
  return 0;
}

Measured memory_bytes: 1024
import java.util.*;
 
public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		long N = Long.parseLong(sc.next());
		long M = Long.parseLong(sc.next());
		if (N * 2 > M) {
			System.out.printf("%d", M / 2);
		} else {
			long mod = M - (N * 2);
			System.out.printf("%d", N + (mod / 4));
		}
	}
}

Measured memory_bytes: 21844
#include<cstdio>
#include<functional>
#include<algorithm>
#include<cmath>
using namespace std;
int main(void)
{
	double x1,y1,x2,y2,s;
	scanf("%lf %lf %lf %lf",&x1,&y1,&x2,&y2);
	s=sqrt((x1-x2)*(x1-x2)+(y1-y2)*(y1-y2));
	printf("%.8lf\n",s);
	return 0;
}


Measured memory_bytes: 1084
a = list(input())
b = list(input())
for i in range(len(a)-1):
    for j in range(len(a)-i-1):
        if a[j] >= a[j+1]:
            a[j],a[j+1] = a[j+1],a[j]
for i in range(len(b)-1):
    for j in range(len(b)-i-1):
        if b[j] >= b[j+1]:
            b[j],b[j+1] = b[j+1],b[j]
a_string = ''.join(a)
b_string = ''.join(b[::-1])
if a_string < b_string:
    print('Yes')
else:
    print('No')

Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
char a;
long long powof10(long long x)
{
    long long res=1;
    for(long long i=1;i<=x;i++)
    {
        res=res*10;
    }
    return res;
}
int main()
{
    //ios_base::sync_with_stdio(0);
    //cin.tie(0);
    //cout.tie(0);
    long long pos=1;
    for(;pos<=10;++pos)
    {
        cout << "? "<< powof10(pos) << "\n";
        fflush(stdout);
        cin >> a;
        if(a=='N')
        {
            pos--;
            break;
        }
    }
    if(pos==11)
    {
        for(long long i=1;i<=10;i++)
        {
            cout << "? " << powof10(i)-1 << "\n";
            fflush(stdout);
            cin >> a;
            if(a=='Y')
            {
                cout << "! " << powof10(i-1);
                return 0;
            }
        }
    }
        long long l=powof10(pos),r=powof10(pos+1)-1;
        while(l!=r)
        {
            long long mid=(l+r)/2;
            cout << "? " << mid*10 << "\n";
            fflush(stdin);
            cin >> a;
            if(a=='N')
            {
                l=mid+1;
            }
            else
            {
                r=mid;
            }
        }
        cout << "! " << l;
        return 0;
}


Measured memory_bytes: 596
#include<iostream>
#include<algorithm>
#include<cstring>
#include<cstdlib>
#include<cstdio>
#include<vector>
#include<cmath>
#include<stack>
#include<queue>
#include<map>
#include<set>
#include<cctype>
#include<sstream>
using namespace std;

#define ll long long
#define PQ priority_queue
#define P pair<int,int>
#define CLA(array)   memset(array,0,sizeof array)
#define CLINF(array) memset(array,0x3f,sizeof array)
//ll qpow(ll a, ll b){ll res=1,base=a;while(b){if(b&1)res=res*base;base=base*base;b>>=1;}return res;}
//ll powmod(ll a, ll b,ll mod){ll res=1,base=a;while(b){if(b&1)res=res*base%mod;base=base*base%mod;b>>=1;}return res;}

int main()
{
    ll n,a,b;
    cin>>n>>a>>b;
    if(a>b)
    {
        cout<<0<<endl;
    }
    else if(a==b)
    {
        cout<<1<<endl;
    }
    else if(n==1&&a!=b)
    {
        cout<<0<<endl;
    }
    else
    {
        int ans=b-a;
        ll  minn=(n-1)*a+b;
        ll maxn=(n-1)*b+a;
        cout<<maxn-minn+1<<endl;
    }
    return 0;
}


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

int main(){
  
  int N,M;
  cin >> N >> M;
  
  vector<int> a(M);
  vector<int> b(M);
  vector<int> count(N);
  
  for(int i = 0; i < M; ++i){
  
    cin >> a.at(i) >> b.at(i);
  
  }
  
  for(int i = 0; i < N; ++i){
    
    for(int j = 0; j < M; ++j){
    
      if(a.at(j) == i+1){
      
        count.at(i) += 1;
      
      }
      
      if(b.at(j) == i+1){
      
        count.at(i) += 1;
      
      }
    
    }  
  
  }
  
  
  for(int i = 0; i < N; ++i){
  
    cout << count.at(i) << endl;
  
  }

  return 0;

}

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

#define INF 0x3f3f3f3f

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

int n;
ll ls[2000010];
ll sum;
ll mi = 10000000100;
ll sunu;

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

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

	for (int i = 0; i < n-1; i++) {
		sunu += ls[i];
		sum -= ls[i];
		mi = min(mi, abs(sunu - sum));
	}

	cout << mi << endl;

	return 0;
}


Measured memory_bytes: 1792
# coding: utf-8
# Your code here!
N,M=map(int,input().split())

A=list(map(int,input().split()))

A=list(map(lambda x:x%M,A))

dic={}
dic[0]=1

ans=0
temp=0

for i in range(len(A)):
    temp+=A[i]
    
    if temp%M in dic:
        ans+=dic[temp%M]
        dic[temp%M]+=1
    else:
        dic[temp%M]=1
    #print(ans)
#print(dic)
print(ans)

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

string a;

void f() {
	int i;
	bool v[150] = {};
	for (i = 0; a[i]; i++) {
		if (v[a[i]]) return;
		v[a[i]] = 1;
	}
	for (i = 0; a[i]; i++) cout << a[i];
	exit(0);
}

int main()
{
	int i, j;
	cin >> a;
	a += 'a' - 1;
	for (i = a.size() - 1; i >= 0; i--) {
		for (j = a[i] + 1; j <= 'z'; j++) {
			a[i] = j;
			f();
		}
		a[i] = '\0';
	}
    cout << "-1" << endl;
    return 0;
}

Measured memory_bytes: 256
//INCLUDE
//------------------------------------------
#include <bits/stdc++.h>
//DEFINE
//------------------------------------------
#define ll long long
#define ALLv(a)  (a).begin(),(a).end()
#define ALL(a,n)  (a),(a)+n
#define vi vector<long long>
#define vd vector<long double>
#define vs vector<string>
//CONST
//------------------------------------------
#define INF 1010000000000000017LL
#define MOD 1000000007LL
#define EPS 1e-12
#define PI 3.14159265358979323846
//REPEAT
//------------------------------------------
#define   FOR(i,m,n) for(ll (i)=(m);   (i)<(n);  (i)++)
#define   REP(i,n)   for(ll (i)=0;     (i)<(n);  (i)++)
#define  REPS(i,x)   for(ll (i)=1;     (i)<=(x); (i)++)
#define  RREP(i,x)   for(ll (i)=(x)-1; (i)>=0;   (i)--)
#define RREPS(i,x)   for(ll (i)=(x);   (i)> 0;   (i)--)
#define  WREP(i,in,j,jn) REP(i,in)REP(j,jn)
#define ifYN(x) cout<<(x?"APPROVED":"DENIED")<<"\n";
using namespace std;
//-------------------------------------------

int main(void){
  ll N;cin>>N;
  string S[N+1];REP(i,N)cin>>S[i];
  vector<pair<ll, string>> pl(N,make_pair(0,""));ll pli=0;
  sort(ALL(S,N));
  ll n0=0;ll MAX=0;string s=S[0];REP(i,N){
    if(i!=N-1&&s==S[i])continue;
    else{
      if(i==N-1){
        if(s==S[i]){
          i++;
          S[i]=S[i-1];
        }
        else{
          pl[pli+1].first=1;
          pl[pli+1].second=S[i];
        }
      }
      s=S[i];
      MAX=max(MAX,pl[pli].first=i-n0);
      pl[pli].second=S[n0];
      pli++;n0=i;
    }
  }
  REP(i,pli+1){
    if(pl[i].first==MAX)
    cout<</*pl[i].first<<":"<<*/pl[i].second<<"\n";
  }
  return 0;
}


Measured memory_bytes: 17408
#include <iostream>
#include <queue>
#include <vector>


class Graph {
  public:
    Graph(int n) : n(n) {
        adj_arr = std::vector<std::vector<int>>(n);
        depth = std::vector<int>(n, -1);
    }

    void breadth_search(int i, int d) {
        std::queue<int> queue;
        depth[i] = d;
        
        for (auto && v : adj_arr[i]) {
            if (depth[v - 1] == -1 || depth[v - 1] > d) {
                queue.push(v - 1);
            }
        }

        while (!queue.empty()) {
            int v = queue.front();
            queue.pop();
            breadth_search(v, d + 1);
        }
    }

    void print() {
        for (int i = 0; i < n; i++) {
            std::cout << i + 1 << " " << depth[i] << std::endl;
        }
    }

  public:
    std::vector<std::vector<int>> adj_arr;
    std::vector<int> depth;
    
  private:
    int n;
};


int main () {
    int n;
    std::cin >> n;

    Graph graph(n);

    for (int i = 0; i < n; i++) {
        int u, k;
        std::cin >> u >> k;
        std::vector<int> arr(k);
        
        for (int j = 0; j < k; j++) {
            std::cin >> arr[j];
        }
        graph.adj_arr[u - 1] = arr;
    }

    graph.breadth_search(0, 0);
    graph.print();
}



Measured memory_bytes: 3192
#include"bits/stdc++.h"
using namespace std;
#define REP(k,m,n) for(int (k)=(m);(k)<(n);(k)++)
#define rep(i,n) REP((i),0,(n))
using ll = long long;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
using tp3 = tuple<int, int, int>;
using Mat = vector<vector<ll>>;
constexpr int INF = 1 << 28;
constexpr ll INFL = 1ll << 60;
constexpr int dh[4] = { 0,1,0,-1 };
constexpr int dw[4] = { -1,0,1,0 };
bool isin(const int H, const int W, const int h, const int w) {
    return 0 <= h && h < H && 0 <= w && w < W;
}
template<typename T>
void output(const T& val) {
    cout << val << endl;
}
template<typename T>
void output(const vector<T>& vec, const bool newline = false) {
    for (const T& val : vec)cout << val << (newline ? '\n' : ' '); cout << endl;
}
template<typename T>
void output(const vector<vector<T>>& mat) {
    for (const auto& row : mat)output(row);
}
// ============ template finished ============

int main()
{
    ll N;
    cin >> N;
    map<pll, ll> mp;
    REP(i, 1, N + 1) {
        auto s = to_string(i);
        mp[{s.front() - '0', s.back() - '0'}]++;
    }
    ll res = 0;
    for (auto itr : mp) {
        auto p = itr.first;
        swap(p.first, p.second);
        res += itr.second*mp[p];
    }
    output(res);
    return 0;
}


Measured memory_bytes: 256
import sys
import numpy as np
import numba
from numba import njit
i8 = numba.int64

read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

@njit((i8[:], ), cache=True)
def main(XYP):
    X, Y, P = XYP[::3], XYP[1::3], XYP[2::3]
    N = len(X)
    dp_X = np.empty((1 << N, N), np.int64)  # 建設、人 -> Xコスト
    dp_X[0] = np.abs(X) * P
    for n in range(N):
        B = 1 << n
        dp_X[B:2 * B] = np.minimum(dp_X[:B], np.abs(X - X[n]) * P)

    dp_Y = np.empty((1 << N, N), np.int64)  # 建設、人 -> Xコスト
    dp_Y[0] = np.abs(Y) * P
    for n in range(N):
        B = 1 << n
        dp_Y[B:2 * B] = np.minimum(dp_Y[:B], np.abs(Y - Y[n]) * P)

    popcount = np.zeros(1 << N, np.int64)
    for n in range(N):
        popcount[1 << n:1 << n + 1] = popcount[:1 << n] + 1

    INF = 10**18
    ans = np.full(N + 1, INF, np.int64)
    for s in range(1 << N):
        size = popcount[s]
        t = s
        while True:
            u = s ^ t
            cost = (np.minimum(dp_X[t], dp_Y[u])).sum()
            ans[size] = min(ans[size], cost)
            if t == 0:
                break
            t = (t - 1) & s
    return ans

N = int(readline())
XYP = np.array(read().split(), np.int64)

ans = main(XYP)
print('\n'.join(map(str, ans.tolist())))

Measured memory_bytes: 117544
#include <bits/stdc++.h>
#define fi first
#define se second
#define pb push_back
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;

int p[5010];
ll c[5010], ans = -1e18;

int main() {
    ios_base::sync_with_stdio(0);
    int n, k; cin >> n >> k;
    for (int i=0;i<n;i++) {
        cin >> p[i];
        p[i]--;
    }
    for (int i=0;i<n;i++) cin >> c[i];

    for (int i=0;i<n;i++) {
        int q = i;
        ll now = 0, mx = -1e18;
        vector<ll> t;
        do {
            q = p[q];
            now += c[q];
            t.pb(now);
        } while (q!=i);
        ll mxv = max(0LL, t.back());
        for (int j=0;j<t.size();j++) {
            if (j+1>k) break;
            ans = max(ans, mxv*((k-j-1)/(int)t.size())+t[j]);
        }
    }

    cout << ans << endl;
}


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

using Int = long long int;
using UInt = unsigned long long int;


int main(void) {
    int x, y;
    cin >> x >> y;
    int g_num[13] = {0,1,3,1,2,1,2,1,1,2,1,2,1};
    if (g_num[x] == g_num[y]) {
        cout << "Yes" << endl;
    } else {
        cout << "No" << endl;
    }
    return 0;
}


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

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

    for(int i=0;i<3;i++){
        if(n[i]=='1'){
            n[i] = '9';
        }else if(n[i]=='9'){
            n[i] = '1';
        }

    }
    cout << n;

}

Measured memory_bytes: 256
import java.util.Scanner;

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

    int n = sc.nextInt();

    if(n==1){
      System.out.println("Hello World");
    }else if(n==2){
      int a = sc.nextInt();
      int b = sc.nextInt();

      int c = a + b;

      System.out.println(c);
    }
  }
}


Measured memory_bytes: 22100
import java.util.*;

public class Main{
	public static void main(String[]args){
		Scanner sc=new Scanner(System.in);
		int a=sc.nextInt();
		int b=sc.nextInt();
		String s=String.valueOf(a)+String.valueOf(b);
		int x=Integer.parseInt(s);
		boolean ans=false;
		for(int i=1;i<=x;i++){
			if(x==i*i){
				ans=true;
				break;
			}
		}
		if(ans==true){
			System.out.println("Yes");
		}else{
			System.out.println("No");
		}
	}
}


Measured memory_bytes: 21716
#include<iostream>
#include<string>
using namespace std;
int main() {
	string s; cin >> s;
	int ans = 0;
	for (int i = 0; i < s.size(); i++) {
		if (s[i] == 'g')ans++;
		else if (s[i] == 'p')ans--;
	}
	cout << ans / 2 << endl;
	return 0;
}

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

using namespace std;

using int64 = long long;

template<class T> inline bool UpdateMin(T& a, T b) {
  if (a > b) { a = b; return 1; } return 0;
}
template<class T> inline bool UpdateMax(T& a, T b) {
  if (a < b) { a = b; return 1; } return 0;
}

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

  string s;
  cin >> s;

  int min_value = INT_MAX;
  for (char c = 'a'; c <= 'z'; c++) {
    vector<int> ps;
    for (int i = 0; i < s.length(); i++) {
      if (s[i] == c) {
        ps.push_back(i);
      }
    }
    if (ps.empty()) continue;
    int max_value = 0;
    UpdateMax(max_value, ps.front());
    UpdateMax(max_value, static_cast<int>(s.length()) - 1 - ps.back());
    for (int i = 0; i + 1 < ps.size(); i++) {
      int gap = ps[i + 1] - ps[i] - 1;
      UpdateMax(max_value, gap);
    }
    UpdateMin(min_value, max_value);
  }
  cout << min_value << endl;
}

Measured memory_bytes: 256
let () =
  let n = Scanf.scanf "%d " (fun n -> n) in
  let a = Array.init n (fun _ -> Scanf.scanf "%d " (fun i -> i)) in
  let (e, o, f) =
    Array.fold_left (fun (e, o, f) a ->
      if a mod 4 = 0 then (e, o, f + 1)
      else if a mod 2 = 0 then (e + 1, o, f)
      else (e, o + 1, f))
      (0, 0, 0) a in
  print_endline (if e = 0 && o <= f + 1 || o <= f then "Yes" else "No")

Measured memory_bytes: 5120
#include <bits/stdc++.h>
using namespace std;
 
int main(){
    double a[100]={0.0},b[100]={0.0},c[100]={0.0},d1=0.0,d2=0.0,d3=0.0,d0=0.0;
    int e;
    cin>>e;
    for(int i=0;i<e;i++){
        cin>>a[i];
    }
    for(int i=0;i<e;i++){
        cin>>b[i];
    }
    for(int i=0;i<e;i++){
        c[i]=a[i]-b[i];
        if(c[i]<0)c[i]=c[i]*(-1);
    }
    for(int i=0;i<e;i++){
        d1+=c[i];
    }
    for(int i=0;i<e;i++){
        d2+=c[i]*c[i];
    }
    for(int i=0;i<e;i++){
        d3+=pow(c[i],3);
    }
    for(int i=0;i<e;i++){
        if(d0<c[i])d0=c[i];
    }
    d2=sqrt(d2);
    d3=pow(d3,1.0/3.0);
    cout <<setprecision(15)<<d1<<"\n"<<d2<<"\n"<<d3<<"\n"<<d0<<endl;
}

Measured memory_bytes: 3444
#include <bits/stdc++.h>
#define _GLIBCXX_DEBUG
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()

using namespace std;
using ll = long long;
using vpii = vector<pair<int, int>>;
using vpll = vector<pair<ll, ll>>;
// ceil() 切り上げ, floor() 切り捨て
// next_permutation(all(x))

int		main(void)
{
	int N;
	cin >> N;
	int all = pow(3, N);
	int sub = 1;
	for (int i = 0; i < N; i++)
	{
		int A;
		cin >> A;
		if (A%2 == 0)
			sub *= 2;
	}
	cout << all - sub << endl;
}



Measured memory_bytes: 384
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
#define rep(i,n) for(ll i=0;i<(ll)(n);i++)
#define all(a) (a).begin(),(a).end()
#define pb emplace_back

//0-index 抽象化半開区間セグツリー verified AOJ DSL_2_AB
template<typename T, typename E>
class segment_tree{
    typedef function<T(T,T)> F;
    typedef function<T(T,E)> G;
private:
    int num_of_elm_;
    vector<T> dat_;
    F f_;
    G g_;
    T ident_;
public:
    segment_tree(int n, F f, G g, T ident):f_(f), g_(g), ident_(ident){
        num_of_elm_ = 1;
        while(num_of_elm_<n)num_of_elm_*=2;
        dat_.resize(2*num_of_elm_,ident);
    }

    void update(int pos,T val){
        int p = num_of_elm_ + pos;
        dat_[p] = g_(dat_[p],val);
        while(p!=1){
            p/=2;
            dat_[p] = f_(dat_[p*2], dat_[p*2+1]);
        }
    }

    T query(int L, int R,int l=0,int r=0, int k=1){
        if(k==1)r = num_of_elm_;
        if(r<=L || R<=l)return ident_;
        else if(L<=l && r<=R){
            return dat_[k];
        }
        else{
            return f_(query(L,R,l,(l+r)/2,k*2), query(L,R,(l+r)/2,r,k*2+1));
        }
    }
};


int main(){
    int n,q;
    cin>>n>>q;
    auto  f = [](int a, int b){ return min(a,b); };
    auto  g = [](int a, int b){ return b; };
    segment_tree<int,int> st(n,f,g,(1LL<<31)-1);

    rep(i,q){
        int com,x,y;
        cin>>com>>x>>y;
        if(com==0){
            st.update(x,y);
        }else{
            cout<<st.query(x,y+1)<<endl;
        }

    }
}






Measured memory_bytes: 3864
#include<bits/stdc++.h>
#define watch(x) cout << (#x) << " is " << (x) << endl
typedef long long ll;
using namespace std;
int static fast = [](){
  ios::sync_with_stdio(false);
  cin.tie(0); cout.tie(0); return 0;
}();

int main() {
    int n, m, a, b;
    cin >> n >> m;
    vector<vector<int>> arr;
    for(int i = 0; i < m; i++) {
        cin >> a >> b;
        arr.push_back({a, b-1});
    }
    sort(arr.begin(), arr.end(), [](vector<int> &l, vector<int>& r)->bool
         {
            if (l[0] == r[0])
                return l[1] > r[1];
            return l[0] < r[0];
         }
    );
    int ans = 0;
    int limit = -1;
    for(int i = 0; i < m; i++) {
        // cout << arr[i][0] << " - " << arr[i][1] << endl;
        if (arr[i][0] > limit) {
            limit = arr[i][1];
            ans += 1;
        }
        limit = min(limit, arr[i][1]);
    }
    cout << ans << endl;
    return 0;
}



Measured memory_bytes: 6836
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<vector>
#define REP(i,n) for(int (i)=0;(i)<(int)(n);(i)++)
#define foreach(c,itr) for(__typeof((c).begin()) itr=(c).begin();itr!=(c).end();itr++)
using namespace std;

const int SIZE=107;
int a[SIZE],ans[3];
int x,n;

bool check(int x)
{
	REP(i,n)if(a[i]==x)return 0;
	return 1;
}

bool output(int a,int b)
{
	if(abs(a-x)==abs(b-x)) return a>b;
	return abs(a-x)>abs(b-x);
}

int main()
{
	//freopen("input.txt","r",stdin);
	//freopen("output.txt","w",stdout);
	cin>>x>>n;
	REP(i,n)cin>>a[i];
	sort(a,a+n);
	int t=x;
	while(!check(t))t++;
	ans[0]=t;
	t=x;
	while(!check(t))t--;
	ans[1]=t;
	cout<<ans[output(ans[0],ans[1])]<<endl;
	return 0;
}


Measured memory_bytes: 3624
def calc(h)
  a = [0, 0]
  h.each_cons(2) do |p, n|
    a = [[a[0], n - p].max, [a[1], p - n].max]
  end
  a
end
gets.to_i.times do
  gets
  h = gets.split.map(&:to_i)
  puts calc(h).join(' ')
end

Measured memory_bytes: 8716
#include <iostream>
#include <algorithm>
#include <vector>
#include <queue>
#include <string>
#include <cstring>
#include <utility>

#define rep(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define all(x) (x).begin(),(x).end()
#define MEMSET(v, h) memset((v), h, sizeof(v))
typedef long long ll;

using namespace std;

int main(void){
    int A, B, count=0;;
    cin >>A>>B;
    rep(i, 2){
        if(A>B){
            count+=A;
            A--;
        } else{
            count+= B;
            B--;
        }
    }
    cout << count << endl;
    return 0;
}


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

#define x first
#define y second
#define pii pair<int,int>
#define sz(x) (int)(x).size()
#define all(x) (x).begin(),(x).end()
using namespace std;
typedef long long LL;
const int maxn = 3e5+35;
int n,m,a,b,h[maxn];
vector<int> v[maxn];
int main(){
    scanf("%d %d",&n,&m);
    for(int i = 1;i <= n; ++i) scanf("%d",h+i);
    while(m--){
        scanf("%d %d",&a,&b);
        v[a].push_back(b);
        v[b].push_back(a);
    }
    int sum = n;
    for(int i = 1;i <= n; ++i){
        for(int j = 0;j < sz(v[i]); ++j){
            if(h[i] <= h[v[i][j]]){
                sum -= 1;
                break;
            }
        }
    }
    printf("%d\n",sum);
    return 0;
}

Measured memory_bytes: 14036
#include<iostream>
#include<set>

using namespace std;

set<string> s;    //创建string的set容器

int main()
{
    int n;
    string str;
    while(cin >> n) {
        while(n--) {
            cin >> str;
            s.insert(str);  //插入数据，set容器只能这么写
        }
        cout << s.size() << endl; //返回set中元素个数
        s.clear();                //清空
    }
    return 0;
}


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

using namespace std;

#pragma GCC optimize ("-O3")

#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define ll long long int
#define ld long double
#define vll vector<ll> 
#define vs vector<string>
#define vc vector<char>
#define vpll vector<pair<ll,ll> >
#define tc ll t=0;cin>>t;while(t--)
#define pb push_back
#define pop pop_back
#define all(x) (x).begin(),(x).end()
#define lb lower_bound
#define ub upper_bound
#define endl "\n"
#define maxe *max_element
#define mine *min_element
#define f first
#define s second
#define vli vll::iterator 
#define mp make_pair
#define unmap unordered_map
#define unmapll unordered_map<ll,ll>
#define max_val 99999999
#define min_val -99999999
#define mod 1000000007
const ld PI = 3.141592653589793;

bool isPowerOfTwo (int x) 
{ 
  return x && (!(x&(x-1))); 
} 

int main()
{
    IOS
    #ifdef LOCAL
            freopen("C:\\Users\\Just Coding Things\\Codeforces\\input.txt","r",stdin);
            freopen("C:\\Users\\Just Coding Things\\Codeforces\\output.txt","w",stdout);
        #endif
        ll n;
        cin>>n;
        ll r=n%10;
        if(r==2 || r==4 || r==5 || r==7 || r==9)
        cout<<"hon";
        else if(r==0 || r==1 || r==6 || r==8)
        cout<<"pon";
        else
        cout<<"bon";
		return 0;
}

Measured memory_bytes: 3608
N, M = map(int, input().split())
data = []
for i in range(N):
	temp = list(map(int, input().split()))
	data.extend(temp[1:])
ans = 0
#print(data)
for i in range(0, M+1):
	#print(N)
	#print(data.count(i+1))
	#print(i)
	if N == data.count(i):
		ans += 1
print(ans)


Measured memory_bytes: 3060
#include <bits/stdc++.h>
using namespace std;
int main(){
	double a, b, c, ang, s, l, h;
	const double Pi = 3.1415926;
	cin >> a >> b >> ang;
	ang = Pi*ang/180;  // 角度转化弧度 
	s = a*b*sin(ang)/2.0;  // a*sin(ang)是以b为底的高 
	c = sqrt(a*a+b*b-2*a*b*cos(ang));  // 余弦定理 
	l = a+b+c;
	h = 2*s/a;
	cout << fixed << setprecision(5) << s << endl;
	cout << fixed << setprecision(5) << l << endl;
	cout << fixed << setprecision(5) << h << endl;
	return 0;
}


Measured memory_bytes: 3468
#include<bits/stdc++.h>
#include<cctype>
using namespace std;
#define rep(i,n) for (int i=0;i<(n);i++)
#define all(v) (v).begin(),(v).end()
typedef long long int ll;
#define pi 3.1415926535897932384
#define E9 1000000000
#define eps 1e-4
#define pii pair<int,int>

int main(){
  int N; cin >> N;
  int a;
  map<int,int> s; 
  rep(i,N) {
    cin >> a;
    s[a]++;
  }
  ll retval = 0;
  for (auto p : s){
    if (p.second - p.first >= 0) retval += p.second - p.first;
    else retval += p.second;
  }
  cout << retval << endl;


  // cout << fixed << setprecision(10);
  
  return 0;
}



Measured memory_bytes: 8068
#include <bits/stdc++.h>
using namespace std;
#define ll long long
const double Pi=acos(-1);
int main() {
  double a,b,x;
  cin>>a>>b>>x;
  if(a*a*b<2*x){
    double left=2*b-2*(x/(a*a));
    double answer=atan(left/a);
    //cout<<left<<endl;
    cout << fixed << setprecision(9) << answer/Pi*180 << endl;
  }
  else{
    double left=x*2/(a*b);
    double answer=atan(b/left);
    cout << fixed << setprecision(9) << answer/Pi*180 << endl;
  }
}

Measured memory_bytes: 256
using System;
using System.Linq;
using System.Collections.Generic;

namespace aizu
{
    public class OnlineJudge
    {
        static void Main()
        {
            int input;
            while((input = int.Parse(Console.ReadLine())) != 0) {
                var point = Enumerable.Repeat(input + 1, 31).ToArray();
                var timeTable = (from p in Enumerable.Range(1, input) let data = Console.ReadLine().Split() select new { key = data[0], value = new HashSet<int>(data.Skip(2).Select(q => { int t = int.Parse(q); --point[t]; return t; })) }).ToDictionary(p => p.key, p => p.value);
                var min = timeTable.Min(m => m.Value.Sum(q => point[q]));
                Console.WriteLine("{0} {1}", min, timeTable.Where(p => p.Value.Sum(q => point[q]) == min).Select(p => p.Key).OrderBy(p => p).First());
            }
        }
    }
}

Measured memory_bytes: 7588
#include <iostream>
//#include <iomanip>
//#include <string>
//#include <vector>
//#include <algorithm>
//#include <utility>
//#include <set>
//#include <map>
//#include <queue>
//#include <bitset>
//#include <math.h>
using namespace std ;
//using ll = long long ;
//using ld = long double ;
//using vll = vector<ll> ;
//using vvll = vector<vll> ;
//using vc = vector<char> ;
//using vvc = vector<vc> ;
//using vb = vector<bool> ;
//using vvb = vector<vb> ;
//using pll = pair<ll,ll> ;

//ll mod = 1000000007 ;
//long double pie = acos(-1) ;

//string yorn(bool a){if(a) return"Yes" ; return "No" ;}
//string YorN(bool a){if(a) return"YES" ; return "NO" ;}
//ll gcd(long long a,long long b){if(b==0) return a ; return gcd(b,a%b) ;}
//ll lcm(long long a,long long b){return a/gcd(a,b)*b ;}
//ll sa(long long a,long long b){if(a>b) return a-b ; return b-a ;}
//void mysort(vector<long long> &a){sort(a.begin(),a.end()) ;}
//void myrev(vector<long long> &a){reverse(a.begin(),a.end()) ;}

int main(){
	long long a,b,c ;
	cin >> a >> b >> c ;
	if(a&b&c&1){
		if(a>b){
			long long t ; t = a ; a = b ; b = t ;
		}
		if(b>c){
			long long t ; t = b ; b = c ; c = t ;
		}
		cout << a*b << endl ;
	}else{
		cout << 0 << endl ;
	}
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
 
const int mod=1e9+7;
 
ll L,R;
 
ll f[64][2][2][2][2];
int l[100],r[100];
 
ll dfs(int x,int fl,int fr,int s,int ht)
{
    if(x<0)return 1;
    // x：第x位 （二进制转十进制下权值是1的为第0位）
    // fl： y之前是否有填过小于 R的某一位的数字   例如：R:11000 y:10??? fl即为1 表示后面数字可以往大了填 
    // fr： x之前是否有填过大于 L的某一位的数字   类似fl
    // s： 之前x是否有某一位 < y的某一位 如果有，后面的位数就没有相对大小限制了 (确保 x<=y)
    //ht：确保 x，y 最高位一样都为1  （满足推导的要求） 
    ll &ans=f[x][fl][fr][s][ht];
    if(ans)return ans;
    
    for(int i=0;i<2;i++)//y
    {
        for(int j=0;j<2;j++)//x
        {
            int tl=fl,tr=fr,ts=s,tt=ht;
            if(!tt&&i)if(i!=j)continue;
            if((j&i)!=j)continue;
            if(!tl&&j<l[x])continue;
            if(!tr&&i>r[x])continue;
            if(!ts&&j>i)continue;
            if(j>l[x])tl=1;if(i<r[x])tr=1;if(j<i)ts=1;if(j)tt=1;
            ans+=dfs(x-1,tl,tr,ts,tt);
        }
    }
    ans%=mod;
    return ans;
}
 
int main()
{
    ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
    cin>>L>>R;
    for(int i=63;i>=0;i--)
    {
        l[i]=(bool)((1ll<<i)&L);r[i]=(bool((1ll<<i)&R));
    }
    
    cout<<dfs(63,0,0,0,0);
    
    return 0;
}

Measured memory_bytes: 256
import java.math.BigDecimal;
import java.util.Arrays;
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int q = sc.nextInt();
		boolean[] flags = new boolean[64];
		Arrays.fill(flags, false);
		StringBuilder sb = new StringBuilder();
		for (int i = 0; i < q; i++) {
			switch (sc.nextInt()) {
				case 0:
					int index = sc.nextInt();
					if (flags[index]) {
						sb.append(1);
					} else {
						sb.append(0);
					}
					sb.append('\n');
					break;
				case 1:
					index = sc.nextInt();
					flags[index] = true;
					break;
				case 2:
					index = sc.nextInt();
					flags[index] = false;
					break;
				case 3:
					index = sc.nextInt();
					flags[index] = !flags[index];
					break;
				case 4:
					boolean flag = true;
					for (boolean tmp : flags) {
						if (!tmp) {
							flag = false;
							break;
						}
					}
					if (flag) {
						sb.append(1);
					} else {
						sb.append(0);
					}
					sb.append('\n');
					break;
				case 5:
					flag = false;
					for (boolean tmp : flags) {
						if (tmp) {
							flag = true;
							break;
						}
					}
					if (flag) {
						sb.append(1);
					} else {
						sb.append(0);
					}
					sb.append('\n');
					break;
				case 6:
					flag = true;
					for (boolean tmp : flags) {
						if (tmp) {
							flag = false;
							break;
						}
					}
					if (flag) {
						sb.append(1);
					} else {
						sb.append(0);
					}
					sb.append('\n');
					break;
				case 7:
					int count = 0;
					for (boolean tmp : flags) {
						if (tmp) {
							++count;
						}
					}
					sb.append(count);
					sb.append('\n');
					break;
				case 8:
					BigDecimal bd = BigDecimal.valueOf(0L);
					BigDecimal bd2 = BigDecimal.valueOf(1L);
					long tmp = 1L;
					for (int j = 0; j < 64; j++) {
						if (flags[j]) {
							bd = bd.add(bd2);
						}
						bd2 = bd2.multiply(BigDecimal.valueOf(2L));
					}
					sb.append(bd.toPlainString());
					sb.append('\n');
					break;
			}
		}
		System.out.print(sb.toString());
	}
}



Measured memory_bytes: 114488
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define ll long long
int main(){
    int n,m;
    cin >> n >> m;
    map<int,int>douro;
    
    rep(i,m){
        rep(j,2){
            int a;
            cin >> a;
            douro[a-1]++;
        }
    }
    
    rep(i,n){
        cout << douro[i] << endl;
    }
}

Measured memory_bytes: 256
n, k = map(int, input().split())
nums = list(map(int, input().split()))

NUM = int(10**9 + 7)

res = 0
for i in range(n - 1):
    count = 0
    for j in range(i + 1, n):
        if nums[i] > nums[j]:
            count += 1
    res += count
res *= k

count = 0
sorted_nums = sorted(nums)
mult = 1
for i in range(n - 1):
    if sorted_nums[i] < sorted_nums[i + 1]:
        count += (n - i - 1) * mult
        mult = 1
    else:
        mult += 1
res += count * (k - 1) * k // 2
print(res % NUM)


Measured memory_bytes: 41708
#include <iostream>
#include <string>
#include <vector>
#include <set>

int main()
{
  int N,M,X;
  std::cin>>N>>M>>X;
  
  std::vector<int> C;
  C.reserve(N*N);
  std::vector<std::vector<int>> t;
  t.reserve(N*N);
  for(size_t i=0;i!=N;i++)
  {
    int c;
    std::cin>>c;
    std::vector<int> A(M);
    for(auto &e:A)
      std::cin>>e;
    
    for(size_t j=0,jEnd=C.size();j!=jEnd;j++)
    {
      int cTemp=c+C[j];
      std::vector<int> temp(M);
      for(size_t k=0;k!=M;k++)
      {
        temp[k]=A[k]+t[j][k];
      }
      C.push_back(cTemp);
      t.push_back(move(temp));
    }
    C.push_back(c);
    t.push_back(move(A));
  }
  
  std::set<int> cSet;
  for(size_t i=0;i!=t.size();i++)
  {
    bool understood=true;
    for(auto &e:t[i])
    {
      if(e<X)
      {
        understood=false;
        break;
      }
    }
    if(understood)
    {
      cSet.insert(C[i]);
    }
  }
  
  int64_t result=cSet.empty()?-1:*cSet.begin();
  
  std::cout<<result<<std::endl;
  
  return 0;
}

Measured memory_bytes: 4116
import sys
input = sys.stdin.readline
# sys.setrecursionlimit(100000)


def main():
    n, k = [int(i) for i in input().strip().split()]
    p = [int(i) for i in input().strip().split()]
    c = [int(i) for i in input().strip().split()]
    ans = -10**9
    for i in range(n):
        scores = [0]
        seen = set([i])
        now = i
        loop = False
        for _ in range(k):
            now = p[now] - 1
            scores.append(c[now])
            if now in seen:
                loop = True
                break
            seen.add(now)
        for i in range(len(scores) - 1):
            scores[i + 1] += scores[i]
        tmp = max(scores[1:])
        ans = max(ans, tmp)
        if (not loop) or scores[-1] <= 0:
            continue
        tmp = scores[-1] * (k // (len(scores) - 1))
        rem = k % (len(scores) - 1)
        tmp += max(scores[:rem + 1])
        ans = max(ans, tmp)
        tmp = scores[-1] * (k // (len(scores) - 1) - 1)
        tmp += max(scores)
        ans = max(ans, tmp)
    print(ans)

if __name__ == "__main__":
    main()

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

using VS = vector<string>;    using LL = long long;
using VI = vector<int>;       using VVI = vector<VI>;
using PII = pair<int, int>;   using PLL = pair<LL, LL>;
using VL = vector<LL>;        using VVL = vector<VL>;

#define ALL(a)  begin((a)),end((a))
#define RALL(a) (a).rbegin(), (a).rend()
#define SZ(a) int((a).size())
#define SORT(c) sort(ALL((c)))
#define RSORT(c) sort(RALL((c)))
#define UNIQ(c) (c).erase(unique(ALL((c))), end((c)))
#define FOR(i, s, e) for (int(i) = (s); (i) < (e); (i)++)
#define FORR(i, s, e) for (int(i) = (s); (i) > (e); (i)--)
//#pragma GCC optimize ("-O3") 
#ifdef YANG33
#include "mydebug.hpp"
#else
#define DD(x) 
#endif
const int INF = 1e9;                          const LL LINF = 1e16;
const LL MOD = 1000000007;                    const double PI = acos(-1.0);
int DX[8] = { 0, 0, 1, -1, 1, 1, -1, -1 };    int DY[8] = { 1, -1, 0, 0, 1, -1, 1, -1 };

/* -----  __MAKE_TIME__  Problem: __PROBLEM__ / Link: __CONTEST_URL__  ----- */
/* ------問題------



-----問題ここまで----- */
/* -----解説等-----



----解説ここまで---- */



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

	LL X, t; cin >> X >> t;
	LL ans = max(0LL,X-t);
	cout<<ans<<endl;

	return 0;
}


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

def even(n):
    return n/2
def odd(n):
    return 3*n+1
a = [n]
i =0
while True:
    if n%2 ==0:
        n = even(n)
        a.append(n)
    else:
        n = odd(n)
        a.append(n)
    if a.count(n) == 2:
        break

print(len(a))

Measured memory_bytes: 3060
n = int(input())
a, b = map(int, input().split())
p = list(map(int, input().split()))

c1, c2, c3 = 0, 0, 0

for i in p:
    if i <= a:
        c1 += 1
    elif a < i <= b:
        c2 += 1
    elif b < i:
        c3 += 1

print(min(c1, c2, c3))

Measured memory_bytes: 3060
h,w = map(int, input().split())

a = []

for i in range(h):
    s = input()
    f = 1
    for j in range(w):
        if s[j]=='#':
            f = 0
            break
    if f==0:    
        a.append(s)

out = []
for i in range(w):
    f =1
    for j in range(len(a)):
        if a[j][i] == '#':
            f = 0
            break
    if f == 1:
        out.insert(0, i)
        
        
for i in out:
    for j in range(len(a)):
        a[j] = a[j][:i]+a[j][i+1:]
            
for i in range(len(a)):
    print(a[i])


Measured memory_bytes: 3064
N, A, B = [int(i) for i in input().split()]

some_sums = 0
for i in range(1, N+1):
    sums = 0
    for j in range(len(str(i))):
        sums += int(str(i)[j])
        
    if sums >= A and sums <= B:
        some_sums += i
        
print(some_sums)
        

Measured memory_bytes: 2940
#ifndef LOCAL
#pragma GCC optimize("O3")
#endif
#include "bits/stdc++.h"
using namespace std;
#define sim template < class c
#define int long long
#define ris return * this
#define dor > debug & operator <<
#define eni(x) sim > typename \
  enable_if<sizeof dud<c>(0) x 1, debug&>::type operator<<(c i) {
sim > struct rge { c b, e; };
sim > rge<c> range(c i, c j) { return rge<c>{i, j}; }
sim > auto dud(c* x) -> decltype(cerr << *x, 0);
sim > char dud(...);
struct debug {
#ifdef LOCAL
~debug() { cerr << '\n'; }
eni(!=) cerr << boolalpha << i; ris; }
eni(==) ris << range(begin(i), end(i)); }
sim, class b dor(pair < b, c > d) {
  ris << "(" << d.first << ", " << d.second << ")";
}
sim dor(rge<c> d) {
  *this << "[";
  for (auto it = d.b; it != d.e; ++it)
    *this << ", " + 2 * (it == d.b) << *it;
  ris << "]";
}
#else
sim dor(const c&) { ris; }
#endif
};
#define imie(...) " [" << #__VA_ARGS__ ": " << (__VA_ARGS__) << "] "
#define fastio ios_base::sync_with_stdio(false);cin.tie(0);
typedef long long ll;
const ll MOD = 1e9 + 7 ;
const ll N = 2e5 + 10 ;
const ll INF = 1e18 + 10 ;
const double pi = acos(-1) ;
signed main(){
    fastio
    int n , m ;
    cin >> n >> m ;
    int sum = 0 ;
    for(int i = 0; i < m; i++){
        int x ;
        cin >> x ;
        sum += x ;
    }
    if ( sum > n ) {
        cout << -1 << endl;
    }
    else cout << n - sum << endl;
    return 0; 
}

Measured memory_bytes: 3640
#include <bits/stdc++.h>
#include <assert.h>
using namespace std;
using i64 = long long;

int main()
{
  i64 n;
  string s;
  cin >> n >> s;
  i64 ans = 1;
  for (i64 i = 1; i < n; i++)
    if (s[i] != s[i - 1])
      ans++;
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 512
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
#define LLINF 9223372036854775807
#define MOD ll(1e9+7)
#define all(x) (x).begin(),(x).end()
#define dbg(x) cerr<<#x<<": "<<x<<endl

ll gcd(ll a, ll b){
    if(a==0 || b==0){
        return max(a, b);
    }
    if(a<b){swap(a,b);}
    if(b<1){return 0;}
    ll r;
    while((r = a%b) != 0){
        a = b;
        b = r;
    }
    return b;
}



int main(){
    ll n;
    cin >> n;
    vector<ll> a(n+1,0);
    for(int i = 0; i < n; i++){
        cin >> a[i];
    }
    sort(all(a));
    a.push_back(0);
    vector<ll> l(n+2, 0);
    vector<ll> r(n+2, 0);
    for(int i = 1; i <= n; i++){
        l[i] = gcd(l[i-1], a[i]);
        r[n+1-i] = gcd(r[n+2-i], a[n+1-i]);
    }
    ll ans = 1;
    for(int i = 0; i < n; i++){
        ans = max(ans, gcd(l[i],r[i+2]));
    }
    cout << ans << endl;
    return 0;
}


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

int main(){
	int n;
	cin >> n;
	string s;
	cin >> s;
	set<int> st;
	for(int i = 0;i <= 999;i++){
		int a1 = -1,a2 = -1,a3 = -1;
		for(int j = 0;j < s.size();j++){
			if(a1 == -1 && a2 == -1 && a3 == -1 && s[j]-'0'== i/100){
				a1 = s[j]-'0';
			}
			else if(a1 != -1 && a2 == -1 && a3 == -1 && s[j]-'0'== i/10 % 10){
				a2 = s[j]-'0';
			}
			else if(a1 != -1 && a2 != -1 && a3 == -1 && s[j]-'0'==i%10){
				a3 = s[j]-'0';
			}
			if(a1!=-1&&a2!=-1&&a3!=-1) break;
		}
		if(a1!=-1&&a2!=-1&&a3!=-1){
//			cout << a1 <<" " << a2 << " " << a3 << endl;
			int y = a1 * 100 + a2 * 10 + a3;
			st.insert(y);
//			printf("%03d\n",y);
		}
	}
	cout << st.size() << endl;
	return 0;
}

Measured memory_bytes: 384
#include<bits/stdc++.h>
#define pii pair<int,int>
#define x first
#define y second
#define mp make_pair
#define pb push_back
#define ll long long
#define sz size()
#define ft front
#define pu push
#define ty empty
#define rep(i,n) for(int i=0;i<n;i++)
using namespace std;
int n;
ll x,y;
int main(void)
{
	cin>>n;
	cin>>x>>y;
	for(int i=1;i<n;i++)
	{
		ll a,b;
		cin>>a>>b;
		ll c=(x+a-1)/a;
		ll d=(y+b-1)/b;
		x=max(c,d)*a;
		y=max(c,d)*b;
	}
	cout<<x+y<<endl;
}


Measured memory_bytes: 256
K, N = map(int, input().split())
mod = 998244353


def cmb(n, r, mod):
    if (r < 0 or r > n):
        return 0
    r = min(r, n-r)
    return g1[n] * g2[r] * g2[n-r] % mod


def H(n, k, mod):
    return cmb(n+k-1, k, mod)

Nmax = 10**5
g1 = [1, 1]
g2 = [1, 1]
inv = [0, 1]

for i in range(2, Nmax+1):
    g1.append((g1[-1] * i) % mod)
    inv.append((-inv[mod % i] * (mod//i)) % mod)
    g2.append((g2[-1] * inv[-1]) % mod)

ans = []
for i in range(2, K+2):
    res = 0
    if i % 2 == 1:
        for j in range(i//2+1):
            res += cmb(i//2, j, mod)*2**j*H(K-i//2*2+j, N-j, mod)
            res %= mod
    else:
        for j in range(i//2):
            res += cmb(i//2-1, j, mod)*2**j*H(K-i+1+j, N-j, mod)
            res += cmb(i//2-1, j, mod)*2**j*H(K-i+1+j, N-1-j, mod)
            res %= mod
    ans.append(res)

for elem in ans + ans[-2::-1]:
    print(elem)


Measured memory_bytes: 78436
import sys

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

l = 1
p = a[0] - 1

if a[0] == 2:
    print(l)
    sys.exit()

while l < int(2e5):
    l += 1
    if a[p] == 2:
        print(l)
        break
    else:
        p = a[p] - 1
else:
    print(-1)

Measured memory_bytes: 7084
import sys
while True:
    h, w = map(int, input().split())
    if h == 0 and w == 0:
        break
    for i in range(h):
        if i%2 == 1:
            for j in range(w):
                if j%2 ==1:
                    sys.stdout.write("#")
                else:
                    sys.stdout.write(".")
        else:
            for j in range(w):
                if j%2 ==1:
                    sys.stdout.write(".")
                else:
                    sys.stdout.write("#")
        print()
    print()


Measured memory_bytes: 6300
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vs = vector<string>;
using msi = map<string, int>;
using mii = map<int, int>;
using psi = pair<string, int>;
using pii = pair<int, int>;
using vlai = valarray<int>;
#define rep(i,n) for(int i=0;i<n;i++)
#define range(i,s,n) for(int i=s;i<n;i++)
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define fs first
#define sc second
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define INF 1E9
#define EPS 1E-9
#define MOD (1E9+7)
#define PI 3.1415926535897932384

std::ostream &operator<<(std::ostream &out, const vector<int> &tgt)
{
	string s;
	for (int i = 0; i<tgt.size(); i++) {
		s += (to_string(tgt[i]) + ((i != tgt.size() - 1) ? " " : ""));
	}
	out << s;
	return out;
}

int main() {
	string ans = "CODEFESTIVAL2016";
	string s;
	int n = 0;
	cin >> s;
	rep(i, s.size()) {
		if (s[i] != ans[i])n++;
	}
	cout <<n<< endl;
}

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

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


int main() {
  ll n;
  cin >> n;
  ll a[n], b[n];
  for (int i = 0; i < n; i++) cin >> a[i];
  for (int i = 0; i < n; i++) cin >> b[i];
  
  ll p = 0;
  ll m = 0;
  for (int i = 0; i < n; i++) {
    if (a[i] >= b[i]) {
      ll pp = a[i] - b[i];
      p += pp;
    }
    else {
      ll mm = b[i] - a[i];
      mm /= 2;
      m += mm;
    }
  }
  if (p > m) cout << "No" <<endl;
  else cout << "Yes" <<endl;
}


Measured memory_bytes: 384
//-------All power is within you,you can do Anything and Everything.---------//
 
    #include <bits/stdc++.h>
    using namespace std;
  
//*$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$ M $$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$*//

    #define pb push_back
    #define MP make_pair
    #define F first
    #define S second
    #define int long long
    #define fo(i,a,b) for(i=a;i<b;i++)
    #define rfo(i,b,a) for(i=b;i>=a;i--)
    #define deb(x) cout<<#x<<" "<<x<<endl;
    #define mem( a, val ) memset(a, val, sizeof( a ) )
    #define deci( x ) cout<<fixed<<setprecision( x );
    #define bitcount( x ) __builtin_popcountll( x )
 
    
    typedef vector<int> vi;
    typedef pair<int,int> pi; 
    
    const int MOD =  1000000007 ;
    const int MAX = 2e6 + 7;
    const int dx[8] = {-1, -1, -1, 0, 1, 1, 1, 0};
    const int dy[8] = {-1, 0, 1, 1, 1, 0, -1, -1};

//*$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$ V $$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$*//  
    
    int i,j,k,t,n,q,l,r,mid;
    
//*$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$ F $$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$*//
    
    int dp[MAX];
    int a[MAX];
    void solve()
    {
        cin>>n;
        fo(i,1,n+1)
        {
            cin>>a[i];
        }
        dp[1]=a[0];
        dp[2]=abs(a[1]-a[2]);
        fo(i,3,n+1)
    	{
    	    dp[i]=min(dp[i-1]+abs(a[i]-a[i-1]),dp[i-2]+abs(a[i]-a[i-2]));
    	}
    	cout<<dp[n]<<endl;
    }
    
//*$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$*//
//                          GAME STARTS FROM HERE                            //

    int32_t main() 
      {
      	
      	// int start,stop=clock();
        // cout<<"time:"<<(stop-start)/double(CLOCKS_PER_SEC)*1000<<endl;
      	ios_base::sync_with_stdio(0);
      	cin.tie(NULL);
      	
      	// cin>>t;while(t--)
      	solve();
      	
    	return 0;
      }

Measured memory_bytes: 5120