akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#define bug1(x) cout<<#x<<" = "<<x<<endl
#define bug2(x,y) cout<<#x<<" = "<<x<<" "<<#y<<" = "<<y<<endl
#define bug3(x,y,z) cout<<#x<<" = "<<x<<" "<<#y<<" = "<<y<<" "<<#z<<" = "<<z<<endl
#define bug4(x,y,z,m) cout<<#x<<" = "<<x<<" "<<#y<<" = "<<y<<" "<<#z<<" = "<<z<<" "<<#m<<" = "<<m<<endl

using namespace std;

class Debugger {
public:
	template<typename T>
	void printVector(vector<T> const &vec, bool printSize=true){
		if(printSize){
			cout << vec.size() << endl;
		}
		for(auto &elem : vec){
			cout << elem << " ";
		}
		cout << endl;
	}

	template<typename T>
	void printMatrix(vector<vector<T>> const &matrix){
		cout << matrix.size()<< " ";
		if(!matrix.empty()){
			cout << matrix[0].size();
		}
		cout << endl; 
		for(auto &vec : matrix){
			printVector(vec, false);
		}
		cout << endl;
	}
};

const int maxN = 100005;

class TaskF {
private:
	Debugger debugger;

public:
	void solveOne(int it){
		int n , f[3];
		cin >> n >> f[0] >> f[1] >> f[2];
		vector<string> command(n);
		vector<pair<int,int>> values[3];
		for(int i = 0; i < n; i++){
			cin >> command[i];
			for(int j = 0; j < 2; j++){
				char ch = command[i][j];
				values[ch-'A'].push_back({i, command[i][!j] - 'A'});
			}
		}

		vector<char> ans;
		for(int i = 0; i < n;){
			int currCharacters[2] = {command[i][0] - 'A', command[i][1] - 'A'};
			int anotherCharacter = 1;
			if(currCharacters[0] == 1){
				anotherCharacter = 0;
			}else if(currCharacters[1] == 1){
				anotherCharacter = 2;
			}
			if(f[currCharacters[0]] + f[currCharacters[1]] == 0){
				cout << "No" << endl;
				return;
			}
			if(f[currCharacters[0]] == 0){
				ans.push_back(currCharacters[0]+'A');
				f[currCharacters[0]]++;
				f[currCharacters[1]]--;
				i++;
				continue;
			}
			if(f[currCharacters[1]] == 0){
				ans.push_back(currCharacters[1]+'A');
				f[currCharacters[1]]++;
				f[currCharacters[0]]--;
				i++;
				continue;
			}

			auto it = lower_bound(values[anotherCharacter].begin(), values[anotherCharacter].end(), make_pair(i,0));
			int newPosition = n;
			int firstCh = currCharacters[0];
			if(it != values[anotherCharacter].end()){
				newPosition = (*it).first;
				firstCh = (*it).second;
			}
			int secondCh = firstCh == currCharacters[0] ? currCharacters[1] : currCharacters[0]; 
			for(int j = i, c = 0; j < newPosition; j++, c++){
				if(c % 2 == 0){
					ans.push_back(firstCh + 'A');
					f[firstCh]++;
					f[secondCh]--;
				}else{
					ans.push_back(secondCh + 'A');
					f[secondCh]++;
					f[firstCh]--;
				}
			}
			i = newPosition;
		}
		cout << "Yes" << endl;
		for(char ch : ans){
			cout << ch << endl;
		}

	}

	void solve(){
		int tc = 1;
		for(int it = 1; it <= tc; it++){
			solveOne(it);
		}
	}
};


int main(){
	ios_base::sync_with_stdio(false);
	TaskF solver;
	solver.solve();
	return 0;
}


Measured memory_bytes: 8728
def makelist(n, m):
    return [[0 for _ in range(m)] for _ in range(n)]


R, G, B, N = map(int, input().split())
ans = 0
for i in range(3001):
    for j in range(3001):
        tmp = N - i*R - G*j
        if tmp >= 0 and tmp % B == 0:
            ans += 1
print(ans)


Measured memory_bytes: 41308
#include<cstdio>
using namespace std;
int a[100005];
int cnt[2][100005];
int main(){
	int n;
	scanf("%d",&n);
	for(int i=1;i<=n;i++){
		scanf("%d",&a[i]);
		cnt[0][a[i]]++;
		cnt[1][a[i]]++;
	}
	int ok=0,sum;
	int remain;
	sum=n-1;
	remain=n-1-a[1];
	cnt[0][a[1]]-=1;
	if(remain>=0&&cnt[0][a[1]]>=remain){
		sum-=remain;
		cnt[0][a[1]]-=remain;
		remain+=1;
		if(cnt[0][a[1]-1]+cnt[0][a[1]]==sum&&cnt[0][a[1]]<=remain&&cnt[0][a[1]]>0){
			ok=1;
			//printf("!\n");
		}
	}
	
	sum=n-1;
	remain=n-1-a[1];
	cnt[1][a[1]]-=1;
	if(remain>=0&&cnt[1][a[1]+1]>=remain){
		sum-=remain;
		cnt[1][a[1]+1]-=remain;
		if(cnt[1][a[1]+1]+cnt[1][a[1]]==sum&&cnt[1][a[1]+1]<=remain&&(cnt[1][a[1]+1]>0&&remain>0||cnt[1][a[1]+1]==0&&remain==0)){
			ok=1;
			//printf("?\n");
		}
	}
	
	if(ok)
		printf("Yes\n");
	else
		printf("No\n");
	
	
} 

Measured memory_bytes: 1280
import scala.io.{StdIn => in}
import scala.collection.{mutable => mu}

object Main extends App {
  val n = in.readInt

  val node = Array.ofDim[Int](n+1)
  val graph = Array.fill(n+1)(mu.ListBuffer.empty[Int])

  val edges = Iterator.continually(in.readLine)
    .take(n-1)
    .map(_.split(" ").map(_.toInt))
    .toArray

  val c = in.readLine.split(" ").map(_.toInt).sorted(Ordering[Int].reverse)

  edges.foreach { e =>
    e(1) +=: graph(e(0))
    e(0) +=: graph(e(1))
  }

  val visited = Array.ofDim[Boolean](n+1)
  val ite = c.iterator

  val stk = mu.Stack.empty[Int]
  def dfs(v:Int):Unit = {
    stk push v

    while(stk.nonEmpty) {
      val vc = stk.pop
      if(!visited(vc)) {
        visited(vc) = true
        node(vc) = ite.next
        graph(vc) foreach stk.push
      }
    }
  }
  dfs(1)

  val ans = (0 until n-1)./:(0)((acc, i) => {
    acc + ( node(edges(i)(0)) min node(edges(i)(1)) )
  })

  println(ans)
  println(node.tail.mkString(" "))
}

Measured memory_bytes: 40296
a, b, c = [ int(v) for v in input().split() ]
t = 0

if not all([a%2==0,b%2==0,c%2==0]):
    print(t)
elif all([a==b,b==c]):
    print(-1)


else:
    while True:
        a, b, c = map( int,[ b/2+c/2, c/2+a/2, a/2+b/2 ] )
        t += 1

        if not all([a%2==0,b%2==0,c%2==0]):
            print(t)
            break
        elif all([a==b,b==c]):
            print(-1)
            break
        

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

using namespace std;

#define pb push_back
#define mp make_pair
#define lli long long int
#define F first
#define S second
#define all(v) v.begin(),v.end()
#define mii map<lli,lli>
#define msi map<string,lli>
#define pii pair<lli,lli> 
#define vi vector<lli> 
#define vvi vector< vector<lli> >
#define sz(x) (lli)x.size()
#define ios ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define MAX1 998244353
#define MAX2 1000000007
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>
void __f(const char* name, Arg1&& arg1){
    std::cerr << name << " : " << arg1 << endl;
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args){
    const char* comma = strchr(names + 1, ',');std::cerr.write(names, comma - names) << " : " << arg1<<" | ";__f(comma+1, args...);
}
#define input(data,n,command) for(lli i=0;i<n;i++){lli tmp;cin>>tmp;data.pb(tmp);command}
#define sort_asc(a) sort(a.begin(),a.end());
//#define sort_desc(a) sort(a.begin(),a.end(),greater<lli>());
#define display(a) for(lli i = 0 ;i<a.size();i++){cout<<a[i]<<" ";} cout<<endl;
#define rep(i,a,b) for(lli i = a;i < b;i++)
#define endl "\n"

//Written By MUDIT BHARDWAJ...
/*--------------------------------------------------------------------*/
//vector<pair<lli,lli>>adj[300010];

lli solve()
{
    //start from here
    lli n,x,t;
    cin>>n>>x>>t;
    lli ans = (n/x);
    if(n%x)
    {
        ans++;
    }
    ans = ans*t;
    cout<<ans<<endl;
    return 0;
}

int main()
{
    ios
    //freopen("input.txt", "r", stdin);
    //freopen("output.txt", "w", stdout);
    lli T=1;
    //cin>>T;
    while(T--)
    {
        solve();
    }
    return 0;
}
/*-----------------------------------------------------------------------*/

Measured memory_bytes: 3604
#include <stdio.h>
#include <cmath>
#include <algorithm>
#include <stack>
#include <queue>
#include <vector>
#include <iostream>
#include <set>
typedef long long int ll;
typedef unsigned long long int ull;
#define BIG_NUM 2000000000
#define MOD 1000000007
#define PRIME1 99999883
#define PRIME2 99999893
#define EPS 0.00000001
#define NUM 48
using namespace std;

struct Info{
	Info(){
		leftWall = false;
		underWall = false;
	}
	bool leftWall,underWall;
};

struct Data{
	int row,col,count;
	bool check[30][30];
};

int W,H;
int div_row[4] = {-1,0,0,1},div_col[4] = {0,-1,1,0};

bool rangeCheck(int row,int col){
	if(row >= 0 && row <= H-1 && col >= 0 && col <= W-1)return true;
	else{
		return false;
	}
}

void func(){
	int tmp;

	Info table[H][W];
	int firstTime[H][W];

	for(int i = 0; i < H; i++){
		for(int k = 0; k < W; k++)firstTime[i][k] = BIG_NUM;
	}

	for(int i = 0; i < H-1; i++){
		for(int k = 0; k < W-1; k++){
			scanf("%d",&tmp);
			if(tmp == 1)table[i][k+1].leftWall = true;
		}
		for(int k = 0; k < W; k++){
			scanf("%d",&tmp);
			if(tmp == 1)table[i][k].underWall = true;
		}
	}
	for(int k = 0; k < W-1; k++){ //?¨?????????±?????????1?????????
		scanf("%d",&tmp);
		if(tmp == 1)table[H-1][k+1].leftWall = true;
	}

	Data first;
	first.row = 0;
	first.col = 0;
	for(int i = 0; i < H; i++){
		for(int k = 0; k < W; k++)first.check[i][k] = false;
	}

	first.check[0][0] = true;
	first.count = 0;

	queue<Data> Q;
	Q.push(first);

	int ans = -1,next_row,next_col;

	bool FLG;

	while(!Q.empty()){

		if(Q.front().row == H-1 && Q.front().col == W-1){
			ans = Q.front().count;
			break;
		}

		for(int i = 0; i < 4; i++){
			next_row = Q.front().row+div_row[i];
			next_col = Q.front().col+div_col[i];
			FLG = false;
			if(rangeCheck(next_row,next_col) == true && Q.front().check[next_row][next_col] == false && firstTime[next_row][next_col] > Q.front().count+1){

				switch(i){
				case 0: //???
					if(table[next_row][next_col].underWall == false)FLG = true;
					break;
				case 1: //???
					if(table[Q.front().row][Q.front().col].leftWall == false)FLG = true;
					break;
				case 2: //???
					if(table[next_row][next_col].leftWall == false)FLG = true;
					break;
				case 3: //???
					if(table[Q.front().row][Q.front().col].underWall == false)FLG = true;
					break;
				}
			}

			if(FLG){
				Data new_data;
				for(int a = 0; a < H; a++){
					for(int b = 0; b < W; b++)new_data.check[a][b] = Q.front().check[a][b];
				}
				new_data.check[next_row][next_col] = true;
				new_data.row = next_row;
				new_data.col = next_col;
				new_data.count = Q.front().count+1;
				firstTime[next_row][next_col] = new_data.count;
				Q.push(new_data);
			}
		}
		Q.pop();
	}

	printf("%d\n",ans+1);
}

int main(){

	while(true){
		scanf("%d %d",&W,&H);
		if(W == 0 && H == 0)break;

		func();
	}

    return 0;
}

Measured memory_bytes: 3144
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
#define FOR(i,a,b) for(ll i=a;i<b;i++)
#define rep(i,n) FOR(i,0,n)
#define ROF(i,a,b) for(ll i=a;i>=b;i--)
#define per(i,a) ROF(i,a,0)
#define pb push_back
using namespace std;
using ll=long long;
using ld=long double;
using ch=char;
typedef pair<ll,ll> P;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<P> vP;
typedef vector<ch> vc;
typedef vector<vc> vvc;
const ll MOD=1000000007;
const ll MOD2=998244353;
const ld PI=acos(-1);
const ll INF=1e18;
struct edge{ll to,cost;};
struct edge2{ll from,to,cost;};

template <typename T>
bool chmax(T &a, const T& b) {
  if (a < b) {
    a = b;
    return true;
  }
  return false;
}

template <typename T>
bool chmin(T &a, const T& b) {
  if (a > b) {
    a = b;
    return true;
  }
  return false;
}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    ll n,a,b;
    cin >> n >> a >> b;
    cout << min(a,b) << " " << max((ll)0,a+b-n) << endl;
}


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


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

int gcd3(int a , int b ,int c){
    int x = gcd(a,b);
    return gcd (x , c);
}

int C(int n){
    int ans = 0;
    for(int i = 1; i<=n; i++){
        for(int j = 1; j <=n; j++){
            for(int k = 1; k<=n; k++){
                    
                    int  temp = gcd3(i,j,k);
                    ans=ans + temp;
                    }
            }
        }
    

    return ans;
}

int main()
{
int n;
cin>>n;
int ans = C(n);
cout<<ans;

}

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

def solve(X, Y, Z, V, E, A):
    dp = [[0.0] * 6001 for _ in xrange(Y + max(V) + 1)]
    dp[0][0] = 1.0
    for i in xrange(Y):
        for j in xrange(5001):
            if dp[i][j] <= 0.0:
                continue
            for k in V:
                t = i + k
                if t > Y:
                    dp[Y][j] += dp[i][j]/X
                elif E[t] == 1:
                    dp[min(Y, t+A[t])][j] += dp[i][j]/X
                else:
                    dp[t][max(0, j+A[t])] += dp[i][j]/X

    s = 0
    for i in xrange(5001):
        s += i * dp[Y][i]
    print int(s)

if __name__ == "__main__":
    import sys

    while True:
        X, Y, Z = map(int, raw_input().split())
        if X | Y | Z == 0:
            sys.exit()
        V = map(int, raw_input().split())
        E = [0] * 100
        A = [0] * 100
        for _ in xrange(Z):
            n, e, a = map(int, raw_input().split())
            E[n] = e
            if e == 3:
                A[n] = -a
            else:
                A[n] = a
        solve(X, Y, Z, V, E, A)

Measured memory_bytes: 9424
#define _CRT_SECURE_NO_WARNINGS
#include"bits/stdc++.h"
#ifdef _DEBUG
#define DBG(n) n
#else
#define DBG(n)
#endif
#define INF          1e9
#define INFLL        1e18
#define EPS          1e-9
#define MOD          1000000007
#define REP(i,n)     for(ll i=0,i##_len=(n);i<i##_len;++i)
#define REP1(i,n)    for(ll i=1,i##_len=(n);i<=i##_len;++i)
#define REPR(i,n)    for(ll i=(n)-1;i>=0;--i)
#define REPR1(i,n)   for(ll i=(n);i>0;--i)
#define REPC(i,obj)  for(auto i:obj)
#define ALL(obj)     (obj).begin(),(obj).end()
#define SETP(n)      cout<<fixed<<setprecision(n)
#define VV(T,h,w)    move(vector<vector<T>>(h,move(vector<T>(w))))
#define VVI(T,h,w,i) move(vector<vector<T>>(h,move(vector<T>(w,i))))
using namespace std;
using ll = long long;
template<typename T = ll>inline T in() { T ret; cin >> ret; return ret; }

int main()
{
	string s; cin >> s;
	sort(ALL(s));
	cout << (unique(ALL(s)) == s.end() ? "yes" : "no") << endl;
}

Measured memory_bytes: 256
/* Coached by Dukkha */
#include <stdio.h>

int main() {
	int w, h, x, y;

	scanf("%d%d%d%d", &w, &h, &x, &y);
	printf("%f %d\n", w / 2.0 * h, x * 2 == w && y * 2 == h);
	return 0;
}


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


#define ll long long
#define pii pair<int,int >
#define pll pair<long long ,long long >
#define pbb pair<bool,bool>
#define plll pair<long long,pair<long long ,long long > > 
#define sefi second.first
#define sese second.second
#define fi first
#define se second
#define ld long double
#define pb push_back
#define mp make_pair
#define all(x) x.begin(),x.end()
#define rall(x) x.rbegin(),x.rend()
#define sz(x) x.size()
#define cont continue
//#define int long long 

const long long  md = 1e9 + 9;
const int Inf = 1e9;
const ll Inf64 = 1e18;
const ll MaxN = 1e5 + 10;
const ll MaxM = 11;
const ld eps = 1e-15;
const ll dx[4] = { 0,1,0,-1 };
const ll dy[4] = { 1,0,-1,0 };
const ll ddx[4] = { 1,1,-1,-1 };
const ll ddy[4] = { 1,-1,1,-1 };

using namespace std;

ll gcd(ll a, ll b) {
	while (a) {
		b %= a;
		swap(a, b);
	}
	return b;
}
ll gcdex(ll a, ll mod = md) {
	ll g = mod, r = a, x = 0, y = 1;
	while (r != 0) {
		ll q = g / r;
		g %= r;
		swap(g, r);
		x -= q * y;
		swap(x, y);
	}
	return x < 0 ? x + mod : x;
}

ll binpow(ll a, ll n) {
	ll res = 1;
	while (n) {
		if (n & 1) {
			res *= a;
			res %= md;
		}
		a *= a;
		a %= md;
		n >>= 1;
	}
	return res % md;
}
// /
/// ////
// ///////



signed main() {
	ios_base::sync_with_stdio(0);
	//ifstream cin("penalty.in");
	//ofstream cout("penalty.out");
	cin.tie(0);
	cout.tie(0);
	cerr.tie(0);
	// //
	//cout << fixed,cout.precision(10);
	// //

	
	ll N;
	cin >> N;
	vector<pll > Mt(N);
	map<pll, ll> Mp;
	for (int i = 0;i < N;i++) {
		cin >>Mt[i].fi>> Mt[i].se;
		Mp[Mt[i]] = i + 1;
	}
	sort(all(Mt));
	set<pll> St;
	ll Ans = 0;
	for (int i = 0;i < N;i++) {
		for (int j = 0;j < i;j++) {
			pll a = mp(Mt[i].first - Mt[j].first, Mt[i].second - Mt[j].second);
			ll t = 0;
			for (int k = 0;k < N;k++) {
				if (Mp[{Mt[k].first - a.first, Mt[k].second - a.second}] != 0)
					t++;
			}
			Ans = max(Ans, t);
		}
	}
	cout << N - Ans;

	/// ///////////////
	cerr << '\n' << "Time execute: " << clock() / (double)CLOCKS_PER_SEC << " sec" << '\n';

	return 0;

}
/*


*/

Measured memory_bytes: 2816
#include <iostream>
#include <vector>
#include <string>
#include <cstdlib>
#include <algorithm>

using namespace std;

int main(){
    int N,M;
    cin >> N >> M;
    vector<int> L(M);
    vector<int> R(M);
    for (int i = 0; i < M; i++)
    {
        cin >> L[i] >> R[i];
    }

    int Lmax = 1;
    int Rmin = N;

    for (int i = 0; i < M; i++)
    {
        Lmax = max(Lmax,L[i]);
        Rmin = min(Rmin,R[i]);
    }
    
    int ans = Rmin - Lmax + 1;

    if(ans<0) ans=0;

    cout << ans << endl;
    
    }


Measured memory_bytes: 1024
#include <bits/stdc++.h>
#define fi first
#define se second
#define m_p make_pair
#define p_b push_back
#define e_b emplace_back
#define all(x) (x).begin(),(x).end()
#define sz(x) ((int)(x).size())
using namespace std;
using ll = long long;
using ld = long double;
template<class T> bool chmax(T &a,T b){if(a<b){a=b;return true;}return false;}
template<class T> bool chmin(T &a,T b){if(a>b){a=b;return true;}return false;}

int main(){
  ios_base::sync_with_stdio(false);cin.tie(0);
  int N;
  cin >> N;
  vector<ll> A(N);
  bool flag=false;
  for(int i=0;i<N;i++){
    cin >> A.at(i);
    if(A.at(i)==0)  flag=true;
  }
  if(flag){
    cout << 0 << endl;
    return 0;
  }

  ll ans=1;
  for(int i=0;i<N;i++){
    if(ans>(ll)1e18/A.at(i)){
      cout << -1 << endl;
      return 0;
    }
    ans*=A.at(i);
  }
  if(ans>(ll)1e18)  ans=-1;
  cout << ans << endl;

  return 0;
}

Measured memory_bytes: 3996
a=input().split()
N=int(a[0])
K=int(a[1])
h_list = input().split()
h_list = [int(i) for i in h_list]
current_V = [0]
current_value = [0] * N

for i in range(1,N) :
    if i-K<0 :
        min_value=[]
        for  j in range(i) :
            min_value.append(current_value[j]+abs(h_list[j]-h_list[i]))
        current_value[i]=min(min_value)
    else :
        min_value = []
        for j in range(i-K,i):
            min_value.append(current_value[j] + abs(h_list[j] - h_list[i]))
        current_value[i] = min(min_value)



print(current_value[-1])


Measured memory_bytes: 52320
#include <bits/stdc++.h>
using namespace std;
#define ll long long
ll dp[100009];
ll n,x,result,ans;
vector<ll>v;
ll frog(ll pos,ll k)
{
   if (pos >= 0 && pos <n-1)
    {
        if (dp[pos]!= -1)
            return dp[pos];
      ll  int ret = INT_MAX;
        for(int i=1; i<=k ; i++)
        {
            if(pos+i==n)
                break;
            ans = frog(i + pos,k ) + abs(v[pos]-v[pos+i]);
           // cout<<ans<<endl;
                ret = min(ret,ans );
        }
        return dp[pos] = ret;
    }
    else if(pos==n-1)
        return 0;
    else
        return INT_MAX;
}

int main()
{
    ll k;
    cin>>n>>k;
    memset(dp,-1,sizeof(dp));
    for(ll i=0; i<n; i++)
    {
        cin>>x;
        v.push_back(x);
    }
    cout<<frog(0,k)<<endl;
}

Measured memory_bytes: 9716
#include <iostream>
#include <sstream>
#include <cstdio>
#include <cmath>
#include <cstring>
#include <cctype>
#include <string>
#include <vector>
#include <list>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <algorithm>
#include <functional>
#include <iomanip>
#include <limits>

using namespace std;
typedef long long int ll;
void sayYes() { cout << "Yes" << endl; };
void sayNo() { cout << "No" << endl; };
ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; }                   // 最大公約数
ll lcm(ll a, ll b) { return a * b / gcd(a, b); };                      // 最小公倍数
ll getDigit(ll num) { return log10(num) + 1; }                         // 桁数
ll digitSum(ll n) { return (n < 10) ? n : digitSum(n / 10) + n % 10; } // 各桁の和
#define rep(i, n) for (ll i = 0; i < n; i++)

void Main()
{
    // int n;
    // cin >> n;
    // vector<int> a(n);
    // rep(i, n)
    // {
    //     cin >> a[i];
    // }
    // int ans = 0;
    int n;
    cin >> n;
    cout << n * n * n << endl;
    return;
}

signed main(void)
{
    std::cin.tie(nullptr);
    std::ios_base::sync_with_stdio(false);
    std::cout << std::fixed << std::setprecision(15);
    Main();
    return 0;
}


Measured memory_bytes: 256
/* {{{ */
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
    ($($r:tt)*) => {
        let s = {
            use std::io::Read;
            let mut s = String::new();
            std::io::stdin().read_to_string(&mut s).unwrap();
            s
        };
        let mut iter = s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
}

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

macro_rules! read_value {
    ($iter:expr, ( $($t:tt),* )) => {
        ( $(read_value!($iter, $t)),* )
    };
    ($iter:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($iter, $t)).collect::<Vec<_>>()
    };
    ($iter:expr, chars) => {
        read_value!($iter, String).chars().collect::<Vec<char>>()
    };
    ($iter:expr, usize1) => {
        read_value!($iter, usize) - 1
    };
    ($iter:expr, $t:ty) => {
        $iter.next().unwrap().parse::<$t>().expect("Parse error")
    };
}
/* }}} */

fn main() {
    input! {
        n: usize
    }
    let mut v = vec![0;n+1];
    v[0] = 1;
    v[1] = 1;
    for i in 2..n+1 {
        v[i] = v[i-1] + v[i-2];
    }
    println!("{}", v[n]);
}
/* vim:set foldmethod=marker: */



Measured memory_bytes: 5032
#include <bits/stdc++.h>
#include <boost/multiprecision/cpp_dec_float.hpp>
#include <boost/multiprecision/cpp_int.hpp>
#pragma GCC target("avx")
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
using namespace std;
namespace mp = boost::multiprecision;
using i64 = int64_t;
using f80 = __float80;
using u64 = uint_fast64_t;
using Bint = mp::cpp_int;
using Real = mp::number<mp::cpp_dec_float<1024>>;
static const int dy[4] = {0,1,0,-1}, dx[4] = {1,0,-1,0};
constexpr i64 INF = 1'010'000'000'000'000'017LL;
constexpr u64 MOD = 1'000'000'007LL;
#define _overload3(_1,_2,_3,name,...) name
#define repi(i,start,end) for(i64 i=(start);i<(end);++i)
#define _rep(i,n) repi(i,0,n)
#define rep(...) _overload3(__VA_ARGS__,repi,_rep,)(__VA_ARGS__)
#define rrep(i,start,end) for(i64 i=(start);i>end;--i)
#define rng(a) a.begin(),a.end()
#define rrng(a) a.rbegin(),a.rend()
#define isin(x,l,r) ((l) <= (x) && (x) < (r))
#define show(x) cout<<#x<<" = "<<x<<endl;
#define PQ(T) priority_queue<T,v(T),greater<T> >
#define v(T) vector<T>
#define vv(T) v(v(T))
typedef pair<i64,i64> P;
typedef v(i64) vi;
typedef v(vi) vvi;
typedef v(P) vp;
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;}
template<typename T> ostream &operator<<(ostream &os, const vector< T > &v){
  rep(i,v.size()) os << v[i] << (i + 1 != v.size() ? " " : "");
  return os;
}
template<typename T> istream &operator>>(istream &is, vector< T > &v){
  for(T &in : v) is >> in;
  return is;
}

void Main()
{
  string N;
  cin >> N;
  char c = N.at(N.size()-1);
  if(c=='3') {
    cout << "bon\n";
  } else if(c=='0' or c=='1' or c=='6' or c=='8'){
    cout << "pon\n";
  } else {
    cout << "hon\n";
  }
}

int main()
{
  cin.tie(nullptr);
  ios_base::sync_with_stdio(false);
  cout << fixed << setprecision(15);
  Main();
}

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

int main() {
  char A,B,C;
  cin >> A >> B >> C ;
  bool res = false;
  if(A=='7' && B == '5' && C=='5') res = true;
  if(A=='5' && B == '7' && C=='5') res = true;
  if(A=='5' && B == '5' && C=='7') res = true;
  
  if(res){
    cout << "YES";
  }else{
    cout << "NO";
  }
  
  return 0;
}

Measured memory_bytes: 3528
#include <iostream>
#include <cstdlib>
#include <algorithm>
#include <vector>
#include <string>
#include <map>
#include <tuple>
#include <numeric>

using namespace std;

typedef long long ll;

int main(void){
    ll n;
    cin >> n;
    vector<ll> w(n);
    ll s1 = 0,s2 = 0;
    for(ll i = 0;i < n;i++){
        cin >> w[i];
        s1 += w[i];
    }
    ll diff = 1141541919810;
    ll ans = 0;
    for(ll i = 0;i < n;i++){
        s2 += w[i];
        s1 -= w[i];
        if(diff > abs(s1 - s2)){
            ans = abs(s1 - s2);
            diff = abs(s1 - s2);
        }
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 256
from collections import deque


def bellman_ford(start: int, graph: list) -> list:
    """bellman-ford法: 始点startから各頂点への最短距離を求める(負辺OK)
    計算量: O(|E||V|)
    """
    INF = float("inf")
    n = len(graph)
    dist = [INF] * n
    dist[start] = 0
    if n == 1:
        return False, [0]
    for _ in range(n):
        update = False
        for v, edge in enumerate(graph):
            for nxt_v, cost in edge:
                if (not reach[nxt_v]) or (not rev_reach[nxt_v]):
                    continue
                if dist[v] != INF and dist[nxt_v] > dist[v] + cost:
                    dist[nxt_v] = dist[v] + cost
                    update = True
        if not update:
            return dist[n - 1]
    return -INF


n, m, p = map(int, input().split())
info = [list(map(int, input().split())) for i in range(m)]

graph = [[] for i in range(n)]
rev_graph = [[] for i in range(n)]
for a, b, cost in info:
    a -= 1
    b -= 1
    graph[a].append((b, -(cost - p)))
    rev_graph[b].append(a)

reach = [False] * n
reach[0] = True
q = deque([0])
while q:
    v = q.popleft()
    for nxt_v, _ in graph[v]:
        if reach[nxt_v]:
            continue
        reach[nxt_v] = True
        q.append(nxt_v)
        
rev_reach = [False] * n
rev_reach[n - 1] = True
q = deque([n - 1])
while q:
    v = q.popleft()
    for nxt_v in rev_graph[v]:
        if rev_reach[nxt_v]:
            continue
        rev_reach[nxt_v] = True
        q.append(nxt_v)

dist = bellman_ford(0, graph)
if dist == -float("inf"):
    print(-1)
else:
    print(max(-dist, 0))


Measured memory_bytes: 53248
//45
#include<iostream>
#include<algorithm>
#include<vector>
#include<string>
#include<cctype>
#include<cstdlib>

using namespace std;

int main(){
  for(int m,n,k,nd;cin>>m>>n>>k>>nd,m|n|k|nd;){
    int c[6];
    for(int i=0;i<m;i++){
      cin>>c[i];
    }
    int d[108][108];
    fill(d[0],d[108],1<<29);
    while(nd--){
      string st[2];
      int ds;
      cin>>st[0]>>st[1]>>ds;
      int sti[2];
      for(int i=0;i<2;i++){
	sti[i]=(st[i]=="H")?0
	  :(st[i]=="D")?1
	  :atoi(st[i].c_str()+1)+((st[i][0]=='C')?1:1+m);
      }
      d[sti[0]][sti[1]]=d[sti[1]][sti[0]]=ds;
    }
    for(int i=0;i<108;i++){
      if(i<2||2+m<=i){
	for(int j=0;j<108;j++){
	  for(int k=0;k<108;k++){
	    d[j][k]=min(d[j][k],d[j][i]+d[i][k]);
	  }
	}
      }
    }
    int mc=1<<30;
    for(int i=0;i<1<<m;i++){
      vector<int> v;
      int cc=0;
      for(int j=0;j<m;j++){
	if(i>>j&1){
	  v.push_back(j+2);
	  cc-=c[j];
	}
      }
      do{
	int ccs=cc;
	vector<int> cv=v;
	cv.insert(cv.begin(),0);
	cv.push_back(1);
	for(int i=0;i<cv.size()-1;i++){
	  if(d[cv[i]][cv[i+1]]==1<<29){
	    ccs=1<<30;
	    break;
	  }
	  ccs+=d[cv[i]][cv[i+1]]*k;
	}
	mc=min(mc,ccs);
      }while(next_permutation(v.begin(),v.end()));
    }
    cout<<mc<<endl;
  }
  return 0;
}

Measured memory_bytes: 1280
N = int(input())
S = []
AC = 0
WA = 0
TLE = 0
RE = 0
for i in range(N):
    s = input()
    if s == "AC":
        AC = AC + 1
    elif s == "WA":
        WA = WA + 1
    elif s == "TLE":
        TLE = TLE + 1
    else :
        RE = RE + 1

print("AC x",AC)
print("WA x",WA)
print("TLE x",TLE)
print("RE x",RE)



Measured memory_bytes: 9136
#include <algorithm>
#include <iomanip>
#include <iostream>
#include <map>
#include <math.h>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdio.h>
#include <string.h>
#include <string>
typedef long long ll;
typedef unsigned long long ull;
using namespace std;

ll mult_mod(ll x, ll y, ll mod){
    return (x * y - (ll)(x / (long double)mod * y + 1e-3) * mod + mod) % mod;
}

ll pow_mod(ll a, ll b, ll p){
    ll res = 1;
    while (b){
        if (b & 1)
            res = mult_mod(res, a, p);
        a = mult_mod(a, a, p);
        b >>= 1;
    }
    return res % p;
}

ll gcd(ll a, ll b){
    return b ? gcd(b, a % b) : a;
}

int n;

int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    cin >> n;
    bool flag = false;
    for (int a = 1; a <= 9; a ++ ){
        for (int b = 1; b <= 9; b ++ ){
            if (a * b == n){
                flag = true;
                break;
            }
        }
        if (flag)
            break;
    }
    if (flag)
        cout << "Yes\n";
    else
        cout << "No\n";
    return 0;
}

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

#define REP(i, n) for(int (i)=0; (i)<(n); (i)++)
#define OUT(a) cout << (a) << "\n"
#define ll long long
#define uint unsigned int
#define ushort unsigned short
#define ulong unsigned long

ll MOD = 10e9 + 7;

int uf[100001];
int y_rank[100001];

int y_find(int x) {
    while (uf[x] != x) {
        uf[x] = uf[uf[x]];
        x = uf[x];
    }
    return x;
}

bool y_union(int x, int y) {
    int tmp_x = y_find(x);
    int tmp_y = y_find(y);
    if (tmp_x == tmp_y) {
        return false;
    }
    if (y_rank[tmp_x] < y_rank[tmp_y]) {
        swap(tmp_x, tmp_y);
    }
    y_rank[tmp_x] += y_rank[tmp_y];
    uf[tmp_y] = tmp_x;
    return true;
}

int main() {
    int n, m;
    cin >> n >> m;
    REP(i, n) {
        uf[i+1] = i+1;
        y_rank[i+1] = 0;
    }
    REP(i, m) {
        int x,y,trash;
        scanf("%d %d %d", &x, &y, &trash);
        y_union(x, y);
    }
    int counter = 0;
    for(int i=1; i<n+1; i++) {
        if (i == uf[i]) counter++;
    }
    printf("%d\n", counter);
    return 0;
}



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

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

    ll n;
    cin >> n;

    ll ans = pow(10, 12) + 1;
    for(ll i = 1; i <= ll(sqrt(n)); i++){
        if(n % i == 0){
            ans = min(ans, i + (n / i) - 2);
        }
    }
    cout << ans << endl;
}


Measured memory_bytes: 256
N_nin, K_poi, Q_mon = list(map(int, input().split()))
Pt = [K_poi] * N_nin

for i in range(Q_mon):
    cor = int(input())
    Pt[cor-1] += 1


for i in range(N_nin):
    if (Pt[i] > Q_mon):
        print('Yes')
    else :
        print('No')

Measured memory_bytes: 6596
sx, sy, tx, ty = map(int, input().split())

y = ty - sy
x = tx - sx

print('U' * y + 'R' * x + 'D' * y + 'L' * x + 'L' + 'U' * (y + 1) + 'R' * (x + 1) + 'D' + 'R' + 'D' * (y + 1) + 'L' * (x + 1) + 'U')

Measured memory_bytes: 3060
#include <bits/stdc++.h>
using namespace std;
struct Fast {Fast() {std::cin.tie(0); ios::sync_with_stdio(false);}} fast;
using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using pii = pair<int, int>;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(),(x).end()
#define pb push_back
#define mp make_pair
#define MOD 1000000007

int main() {
    string a, b; cin >> a >> b;
    a = a + b;
    int num = stoi(a);
    bool f = false;
    for (int i = 1; i * i <= num; i++) {
        if (i * i == num) {
            f = true;
        }
    }
    cout << (f ? "Yes" : "No") << endl;
}



Measured memory_bytes: 256
import math,sys
from sys import stdin, stdout
from collections import Counter, defaultdict, deque
input = stdin.readline
I = lambda:int(input())
li = lambda:list(map(int,input().split()))

def case():
    a=input().strip()
    b=input().strip()
    if(a==b[:len(b)-1]):
        print("Yes")
    else:
        print("No")

for _ in range(1):
    case()

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

int main(){
  int N,a,b,c,d;
  cin >> N;
  a = N/1000;
  b = N/100 - a*10;
  c = N/10 - a*100 - b*10;
  d = N - a*1000 -b*100 -c*10;
  if(a == b && a == c || b == c && b == d){
  cout << "Yes" << endl;
  }
  else{
  cout << "No" << endl;
  }
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define REP(i, n) for(int i = 0; i < (n); i++)
#define RREP(i, n) for(int i = (n); i >= 0; i--)
#define FOR(i, m, n) for(int i = (m); i < (n); i++)
#define ALL(obj) begin(obj), end(obj)
using namespace std;
using llong = long long;

const int INF = 100100100;
const int MOD = 1e9 + 7;

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

    int N;
    cin >> N;
    vector<int> vec(N);
    int tmp;

    REP(i, N) {
        cin >> tmp;
        vec[i] = tmp;
    }
    vec[0] -= 1;

    FOR(i, 1, N) {
        if(vec[i - 1] < vec[i]) {
            vec[i] -= 1;
        } else if(vec[i - 1] > vec[i]) {
            cout << "No";
            return 0;
        }
    }
    cout << "Yes";
    return 0;
}


Measured memory_bytes: 640
import java.util.*;
import java.util.function.*;
import java.lang.*;
import java.io.*;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        String S = sc.next();
        int N = S.length();
        int K = sc.nextInt();
        Set<String> substrings = new HashSet<>();
        for(int i=0; i<N; i++) for(int l=1; l<=Math.min(N-i, K); l++) {
            substrings.add(S.substring(i,i+l));
        }

        String[] a = substrings.toArray(new String[0]);
        Arrays.sort(a);
        System.out.println(a[K-1]);
    }
}


Measured memory_bytes: 39680
from collections import Counter

class UnionFind:
    def __init__(self, size):
        self.size = size
        self.parents = list(range(size))

    def union(self, x, y):
        r = self.find(x)
        self.parents[r] = self.find(y)

    def find(self, x):
        path = [x]
        v = x
        while self.parents[v]!=v:
            v = self.parents[v]
            path.append(v)
        for p in path:
            self.parents[p] = v
        return v

if __name__=='__main__':
    n, k, l = map(int, input().split())

    road = UnionFind(n)
    for p, q in (map(int, input().split()) for _ in range(k)):
        road.union(p-1, q-1)

    railway = UnionFind(n)
    for r, s in (map(int, input().split()) for _ in range(l)):
        railway.union(r-1, s-1)

    groups = [str(road.find(i))+"&"+str(railway.find(i)) for i in range(n)]
    ctr = Counter(groups)

    print(*(ctr[g] for g in groups))

Measured memory_bytes: 44632
#include <bits/stdc++.h>
using namespace std;
typedef int int__;
#define int long long
#define pb push_back
#define pi pair<int,int>
#define vpi vector<pi>
#define vi vector<int>
#define vvi vector<vi>
#define fi first
#define se second
#define forn(i, n)for(int i=0;i<int__(n);i++) 
#define sz(a)int__(a.size())
template <class A, class B> ostream& operator << (ostream& out, const pair<A, B> &a){return out << "(" << a.first << ", " << a.second << ")";}
template<class A>ostream& operator<<(ostream& out,const vector<A>&v){out<<"[";forn(i,sz(v)){if(i)out<<", ";out<<v[i];}return out<<"]";}
const int MAX = 1e9 + 100;
#define fast ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0)
int Mod(int x){const int mm=1e9 + 7;x%=mm;if(x<0)x+=mm;return x;}
int Pow(int x,int n){if(n==0)return 1;int t=Pow(x,n/2);t=Mod(t*t);if(n&1)t=Mod(t*x);return t;}
#define watch(x) cout << #x << " : " << x << endl;
int gcd(int a,int b){if(b==0)return a;return gcd(b,a%b);}
#define all(x) x.begin(), x.end()


int__ main() {
	fast;
	int n; cin >> n;

	int s = 0;
	for(int i=1;i<=n;i++){
		for(int j=1;j<=n;j++){
			for(int k=1;k<=n;k++) s += gcd(gcd(i,j),k);
		}
	}

	cout << s << endl;
}

Measured memory_bytes: 3656
#include <queue>
#include <iostream>
#include <map>
#include <algorithm>
#include <string>
#include <cmath>
#define rep(i, n) for(long long i = 0;(i) < (n);(i)++)
using namespace std;
using ll = long long;

ll N;
ll d[50];


int main()
{
	ll N;
	string str;
	cin >> N >> str;
	ll ans = 1;
	rep(i, str.length() - 1)
	{
		if (str[i] == str[i + 1]) continue;
		ans++;
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 512
#include <bits/stdc++.h>
using namespace std;
using ll = long long;

int main (){
    int N;
    cin >> N;
    vector<int> X(N), Y(N);
    for (int i = 0; i < N; i++)
    {
        int a;
        cin >> a;
        X[i] = a;
        Y[i] = a;
    }
    
    sort(Y.begin(), Y.end(), greater<int>());
    
    vector<int> B(N);
    for (int i = 0; i < N; i++)
    {
        if (X[i] < Y[N / 2 - 1])
        {
            B[i] = Y[N / 2 - 1];
        } else
        {
            B[i] = Y[N / 2];
        }
        
        
        cout << B[i] << endl;
        
    }
    
    
    return 0;
    
}

Measured memory_bytes: 4608
package main

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

func main() {
	scanner := bufio.NewScanner(os.Stdin)
	scanner.Scan()
	text := scanner.Text()
	data := strings.Split(text, " ")
	N, _ := strconv.Atoi(data[0])
	M, _ := strconv.Atoi(data[1])

	N_data := make([]string, N, N)
	M_data := make([]string, M, M)

	for i := 0; i < N; i++ {
		scanner.Scan()
		N_data[i] = scanner.Text()
	}

	for i := 0; i < M; i++ {
		scanner.Scan()
		M_data[i] = scanner.Text()
	}

	if N == 1 && M == 1 {
		if N_data[0] == M_data[0] {
			fmt.Println("Yes")
		} else {
			fmt.Println("No")
		}
	} else {

		flag := false
		for i := 0; !flag && i < N-M; i++ {
			for j := 0; !flag && j < N-M; j++ {
				lflag := true
				for k := 0; lflag && k < M; k++ {
					for l := 0; lflag && l < M; l++ {
						lflag = lflag && N_data[i+k][j+l] == M_data[k][l]
					}
				}
				if lflag {
					flag = true
				}
			}
		}

		if flag {
			fmt.Println("Yes")
		} else {
			fmt.Println("No")
		}

	}

	if err := scanner.Err(); err != nil {
		panic(err)
	}

}


Measured memory_bytes: 640
#include <vector>
#include <stack>
#include <queue>
#include <list>
#include <bitset>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <algorithm>
#include <numeric>
#include <iostream>
#include <iomanip>
#include <string>
#include <chrono>
#include <random>
#include <cmath>
#include <cassert>
#include <climits>
#include <cstring>
#include <cstdlib>
#include <functional>
#include <sstream>

using namespace std;


int main(int argc, char** argv) {
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout << fixed << setprecision(12);

    int n, K;
    cin >> n >> K;
    vector<int> bad(10, false);
    for (int i = 0; i < K; ++i) {
        int x;
        cin >> x;
        bad[x] = true;
    }
    
    auto ok = [&](int x) {
        while (x != 0) {
            if (bad[x % 10]) {
                return false;
            }
            x /= 10;
        }
        return true;
    };


    int res = -1;

    for (int i = n; ;++i) {
        if (ok(i)) {
            res = i;
            break;
        }
    }


    cout << res << '\n';


    return 0;
}

Measured memory_bytes: 3624
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <cmath>
#include <queue>
#include <map>
#include <unordered_map>
#include <set>
#include <functional>
#include <bitset>
#include <cassert>
#include <random>
using namespace std;
using ll = long long;


int main() {
	ll a, b; cin >> a >> b;
	int cnt = 1;
	for (ll i = 2; i <= 1000000; i++) {
		cnt += a%i == 0 && b%i == 0;
		while (a > 0 && a%i == 0) {
			a /= i;
		}
		while (b > 0 && b%i == 0) {
			b /= i;
		}
	}
	if (a > 1 && a == b) cnt++;
	cout << cnt << endl;
	return 0;
}


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

using namespace std;

#define C_MAX(a, b) ((a)>(b)?(a):(b))
#define SHOW_VECTOR(v) {std::cerr << #v << "\t:";for(const auto& xxx : v){std::cerr << xxx << " ";}std::cerr << "\n";}
#define SHOW_MAP(v) {std::cerr << #v << endl; for(const auto& xxx: v){std::cerr << xxx.first << " " << xxx.second << "\n";}}

int main() {

    int N, M;
    cin >> N >> M;

    vector<pair<int, int>> edges(M);
    for (int i = 0; i < M; i++) {
        int c, d;
        cin >> c >> d;
        edges[i] = make_pair(c, d);
    }
    sort(edges.begin(), edges.end());

    vector<pair<int, int>> newEdges;
    pair<int, int> edge(-1, -1);
    for (int i = 0; i < M; i++) {
        if (edge == make_pair(-1, -1)) {
            edge = edges[i];
            continue;
        }
        if (edge.second >= edges[i].first) {
            edge.second = max(edge.second, edges[i].second);
        } else {
            newEdges.push_back(edge);
            edge = edges[i];
        }
    }
    if (edge != make_pair(-1, -1)) newEdges.push_back(edge);

    int cost = 0;
    cost += N + 1;
    for (int i = 0; i < newEdges.size(); i++) {
        cost += (newEdges[i].second - newEdges[i].first) * 2;
    }

    cout << cost << endl;

    return 0;
}














































Measured memory_bytes: 3104
#include <iostream>
#include <vector>
#include <string>
#include <math.h>
#include <algorithm>
#include <set>
#include <iomanip>
#include <stdio.h>
#include <sstream>
#include <string>
using namespace std;
int main(void){
  int n;
  cin>>n;
  vector<long long int> a(n);
  vector<int> hoge(n+1);
  long long int ans=0;
  for(long long int i=0; i<n; i++){
    cin>>a.at(i);
    if(a.at(i)<=n){
      hoge.at(a.at(i))++;
    }else{
      ans++;
    }
  }

  for(long long int i=0; i<n+1; i++){
    if(i>hoge.at(i)){
      ans+=hoge.at(i);
    }else{
      ans+=hoge.at(i)-i;
    }
  }
  cout<<ans<<endl;
}

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

const ll mod = 1000000007;
const int INF = 1001001001;

ll dp[3002][3002][4];

ll max(ll a, ll b, ll c){
	return max(max(a, b), c);
}

int main() {
	cin.tie(0);
   	ios::sync_with_stdio(false);
	int R, C, K; cin >> R >> C >> K;
	vector<vector<ll>> mp(R, vector<ll> (C));
	for(int i = 0; i < K; i++){
		int r, c; cin >> r >> c;
		--r; --c;
		cin >> mp[r][c];

	}
    // i, jについた時の最大値
    for(int i = 0; i < R; i++){
        for(int j = 0; j < C; j++){
            for(int k = 0; k < 3; k++){
                dp[i][j+1][k+1] = max(dp[i][j][k] + mp[i][j], dp[i][j][k+1]);
                dp[i+1][j][0] = max(dp[i][j][k] + mp[i][j], dp[i+1][j][0]);
                dp[i+1][j][0] = max(dp[i][j][k+1], dp[i+1][j][0]);
            }
        }
    }
    /*for(int i = 0; i < R; i++){
        for(int j = 0; j < C; j++){
            for(int k = 0; k < 4; k++){
                cout << '(' << i << ',' << j << ',' << k << ',' << dp[i][j][k] << ')' << endl;
            }
        }
    }*/
	ll ans = 0;
	rep(k, 3) ans = max(ans, dp[R-1][C-1][k] + mp[R-1][C-1]);
    ans = max(ans, dp[R-1][C-1][3]);
    cout << ans << endl;
}


Measured memory_bytes: 355108
#include <iostream>
#include <vector>
#include <utility>
#include <algorithm>
using namespace std;

int a, b;

#define INF (1<<28)

int main() {
    while (cin >> a >> b) {
        if (a == 0 && b == 0) break;
        vector<int> v(4);
        int m = INF;
        for (int i = 1; i*i <= a; i++) {
            if (a % i == 0) {
                for (int j = 1; j*j <= b; j++) {
                    if (b % j == 0) {
                        v[0] = i;
                        v[1] = a/i;
                        v[2] = j;
                        v[3] = b/j;
                        sort(v.begin(), v.end());

                        int sum = 0;
                        for (int k = 0; k < 3; k++) {
                            sum += (v[k+1]-v[k]) * (v[k+1]-v[k]);
                        }
                        
                        m = min(m, sum);
                    }
                }
            }
        }
        cout << m << endl;
    }
    return 0;
}

Measured memory_bytes: 1212
#include <iostream>
#include <string>
#include <algorithm>
#include <set>
#include <map>
#include <unordered_map>
#include <cmath>

using namespace std;

typedef long long ll;

int main(int argc, char **argv)
{
    int N;
    string S;
    cin >> N >> S;

    if (N % 2 == 1) cout << "No" << endl;
    else {
        bool f = true;
        for (int i = 0; i < N / 2; ++i) {
            if (S[i] != S[i + N / 2]) {
                f = false;
            }
        }
        if (f) cout << "Yes" << endl;
        else cout << "No" << endl;
    }
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <cassert>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <complex>
#include <map>
#include<unordered_map>
#include <set>
#include <queue>
#include <stack>
#include <vector>
#include<bitset>
#include<deque>
#include<string>
#include<list>
#include<iterator>
#include<sstream>
#include <algorithm>
#include <numeric>
#include <math.h>

#define user spaesk
#define pi acos(-1)
#define int long long int
#define ld long double
#define ff first
#define ss second
#define lower(a) transform(a.begin(),a.end(),a.begin(),::tolower);

using namespace std;

typedef vector<vector<int> > matrix ;

const int N = 3e5 + 500;
const long long mod = 1e9 + 7;
const long long cmod = 998244353 ;
const long long inf = 1LL << 61;
const int M = 1e6 + 500;
const int ths = 1LL << 40;
const int NN = 5e3 + 6;

const int maxN = 500007;

///abc 156_e
///

int f[N];
int modexp(int a, int n) {

    int r = 1;
    while(n) {
        if(n & 1) {
            r = (r * a) % mod;
        }
        a = (a * a) % mod;
        n >>= 1;
    }
    return r;
}

int ncr(int n, int r) {

    if(n < r) {
        return 0;
    }
    int ans = (f[n] % mod * modexp(f[r], mod - 2) % mod * modexp(f[n - r], mod - 2) % mod) % mod;
    return ans ;
}

void solve()
{

    int n, k;
    cin>>n>>k;

    f[0] = 1;
    for(int i = 1; i <= n; i ++) {
        f[i] = f[i - 1] * i;
        f[i] %= mod;
    }

    k = min(k, n - 1);

    int ans = 0;
    for(int i = 0; i <= k; i ++) {
        int t = ncr(n, i);   /// selecting the number of 0's from n numbers
        t = (t % mod * ncr(n - 1, n - i - 1) % mod) % mod;   ///dividing the rest into n - i groups such that each group has at least 1
        ans = (ans + t) % mod;
    }

    cout<<ans;

    cout<<"\n";
    return ;
}

/*
*/

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

    int t = 1;
//    cin>>t;
    while(t --)
    {
        solve();
    }
    return 0;
}


Measured memory_bytes: 1792
#include <iostream>
#include <sstream>
#include <string>
#include <cctype>
using namespace std;

typedef string::const_iterator Iter;
typedef ostringstream SS;

string express(Iter &p);
string factor(Iter &p);
string term(Iter &p);
int number(Iter &p);

int N;

string express(Iter &p) {
	SS r;
	while(isalpha(*p) || isdigit(*p)) {
		string rs = term(p);
		r << rs;
		if(r.str().length() > N) break;
	}

	return r.str();
}


string term(Iter &p) {
	if(isdigit(*p)) {
		SS r;
		int num = number(p);
		if(*p == '(') {
			p++;
			string rs = express(p);
			p++;

			for(int i = 0; i < num; i++) {
				r << rs;
				if(r.str().size() > N) break;
			}
			return r.str();
		}
		else {
			char c = *p;
			p++;

			for(int i = 0; i < num; i++) {
				r << c;
				if(r.str().size() > N) break;
			}
			return r.str();
		}
	}
	else {
		return factor(p);
	}
}

string factor(Iter &p) {
	SS r;
	while(isalpha(*p)) {
		r << *p;
		p++;
		if(r.str().size() > N) break;
	}
	return r.str();
}

int number(Iter &p) {
	int r = 0;
	while(isdigit(*p)) {
		r *= 10;
		r += (*p) - '0';
		p++;
	}
	return r;
}

int main() {
	for(;;) {
		string line;
		int i;
		cin >> line >> i;
		N = i;
		if(line == "0" && i == 0) break;
		string source = line + "|";
		Iter begin = source.begin();
		string s = express(begin);
		if(i >= s.length())
			cout << 0 << endl;
		else
			cout << s[i] << endl;
	}
}

Measured memory_bytes: 5628