akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>

using   namespace std;
typedef long long int ll;
typedef unsigned long long int ull;
typedef long double ld;

#define  all(v)       (v).begin(),(v).end()
#define  rall(v)      (v).rbegin(),(v).rend()
#define  pb           push_back  
#define  eb           emplace_back
#define  mp           make_pair
#define  ff           first
#define  ss           second
#define  pf           push_front
#define  bs           binary_search
#define  lb           lower_bound
#define  ub           upper_bound
#define  umap         unordered_map
#define  uset         unordered_set
#define  dec(x)       fixed<<setprecision(x)
#define  lcm(a,b)    (a*b/__gcd(a,b))

typedef  priority_queue<ll>  pq;
typedef  priority_queue<ll,vector<ll>,greater<ll>> pqmn;
typedef  pair<ll,ll> pll;

const    ll inf=LLONG_MAX;
const    ll mod=1e9+7;
const    ld pi=acos(-1);

ll binpow(ll a, ll b) 
{ 
    ll ans = 1; 
    while (b) { 
        if (b & 1) 
            ans = ans * a % mod; 
        a= a * a % mod; 
             b >>=1;
    } 
    return ans%mod; 
} 
                    
void solution(){
    ll n;
    cin>>n;
    ll val=((binpow(10,n)%mod)-(binpow(9,n)%mod)-(binpow(9,n)%mod)+(binpow(8,n)%mod))%mod;
    cout<<(val+mod)%mod;

}

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    ll t;
    t=1;
    //cin>>t;
    while(t--){
        solution();
        cout<<"\n";
    }
    return 0;
}


Measured memory_bytes: 3604
#include <bits/stdc++.h>
using namespace std;
#define int long long 
#define all(a) a.begin(),a.end()
#define rep(i,n) for(long long i=0;i<n;i++)
#define P pair<long,long>
#define F first
#define S second
#define INF 100000000000000000
#define mod 1000000007
signed main(void){
    int n;cin>>n;
    vector<int>v(n),com(n);rep(i,n){cin>>v[i];com[i]=v[i];}
    sort(all(com));
    int count=0;
    rep(i,n)if(v[i]!=com[i])count++;
    int q,x,y;
    cin>>q;
    if(count==0)cout<<0<<endl;
    else{
        bool ans=false;
        rep(i,q){
            cin>>x>>y;x--;y--;
            int a=v[x],b=v[y],c=com[x],d=com[y];
            if(a==c)count++;
            if(b==d)count++;
            if(a!=c && b==c)count--;
            if(b!=d && a==d)count--;
            swap(v[x],v[y]);
            if(count==0){cout<<i+1<<endl;ans=true;break;}
        }
        if(!ans)cout<<-1<<endl;
    }
    
    
}


Measured memory_bytes: 7564
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <cmath>
#include <queue>
#include <set>
#include <map>
#include <iomanip>
#include <fstream>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
const int mod = 1000000007;

int main() {
    ios::sync_with_stdio(false);
    int n;
    cin >> n;
    cout << n * n;
}


Measured memory_bytes: 3616
#include <bits/stdc++.h>
#define WHOLE(v) (v).begin(), (v).end()
#define REV_WHOLE(v) (v).rbegin(), (v).rend()
using i64 = int64_t;
using namespace std;
template<size_t I,class H,class...T>struct TupleReaderWriter{static tuple<H,T...> r(istream&i){H v;i>>v;return tuple_cat(tuple<H>(v),TupleReaderWriter<sizeof...(T)-1,T...>::r(i));}static void w(ostream&o,tuple<H,T...>&t,string d){TupleReaderWriter<I-1,H,T...>::w(o,t,d);o<<d<<get<I>(t);}};
template<class H,class...T>struct TupleReaderWriter<0,H,T...>{static tuple<H,T...> r(istream&i){H v;i>>v;return tuple<H>(v);}static void w(ostream&o,tuple<H,T...>&t,string d){o<<get<0>(t);}};
template<class...T>istream&operator>>(istream&i,tuple<T...>&t){t=TupleReaderWriter<sizeof...(T),T...>::r(i);return i;}
template<class...T>ostream&operator<<(ostream&o,tuple<T...>&t){string delim=" ";TupleReaderWriter<sizeof...(T)-1,T...>::w(o,t,delim);return o;}
template<class T>istream&operator>>(istream&i,vector<T>&v){for(auto&x:v)i>>x;return i;}
template<class T>ostream&operator<<(ostream&o,vector<T>&v){string delim="";for(auto&x:v)o<<delim<<x,delim=" ";return o;}
template<class T>using rev_priority_queue=priority_queue<T,vector<T>,greater<T>>;
template<class T>using vector2d=vector<vector<T>>;
struct fixprec{int x;fixprec(int d):x(d){}};
ostream&operator<<(ostream&o,fixprec f){return o<<fixed<<setprecision(f.x);}
void R_YESNO(bool p) { cout << (p ? "YES" : "NO") << endl; }
void R_YesNo(bool p) { cout << (p ? "Yes" : "No") << endl; }
bool dp[2][10][10][10];
int main() {
    int N;
    string S;
    int a = 0;
    cin >> N;
    cin >> S;
    vector<int> v(N);
    for(int i = 0; i < N; i++) {
        v[i] = S[i] - '0';
    }
    for(int i = 0; i < 10; i++) {
        for(int j = 0; j < 10; j++) {
            for(int k = 0; k < 10; k++) {
                dp[0][i][j][k] = dp[1][i][j][k] = false;
            }
        }
    }
    dp[0][v[0]][v[1]][v[2]] = true;
    for (int p = 3; p < N; p++) {
        int x = v[p];
        for (int i = 0; i < 10; i++) {
            for (int j = 0; j < 10; j++) {
                for (int k = 0; k < 10; k++) {
                    dp[p & 1][i][j][k] |= dp[!(p & 1)][i][j][k];
                    dp[p & 1][i][j][x] |= dp[!(p & 1)][i][j][k];
                    dp[p & 1][i][k][x] |= dp[!(p & 1)][i][j][k];
                    dp[p & 1][j][k][x] |= dp[!(p & 1)][i][j][k];
                }
            }
        }
    }
    for (int i = 0; i < 10; i++) {
        for (int j = 0; j < 10; j++) {
            for (int k = 0; k < 10; k++) {
                if(dp[!(N & 1)][i][j][k]) {
                    a++;
                }
            }
        }
    }
    cout << a << endl;
    return 0;
}



Measured memory_bytes: 512
#include <iostream>
#include <algorithm>
#include <vector>
#include <iomanip>
#include <cmath>
#include<map>
#include <set>
#include <queue>
#include <cstring>
#include <cassert>
#include <limits>
using namespace std;
 
template<typename T> ostream& operator<<(ostream &os, const vector<T> &v) { os << "{"; for (typename vector<T>::const_iterator vi = v.begin(); vi != v.end(); ++vi) { if (vi != v.begin()) os << ", "; os << *vi; } os << "}"; return os; }
template<typename A, typename B> ostream& operator<<(ostream &os, const pair<A, B> &p) { os << '(' << p.first << ", " << p.second << ')'; return os; }
 
void dbg_out() { cerr << endl; }
template<typename Head, typename... Tail> void dbg_out(Head H, Tail... T) { cerr << ' ' << H; dbg_out(T...); }
 
#ifdef NEERAJ
#define dbg(...) cerr << "(" << #__VA_ARGS__ << "):", dbg_out(__VA_ARGS__)
#else
#define dbg(...)
#endif
 
#ifndef	ONLINE_JUDGE

#endif
 
 
#define rep(i, n)    for(ll i = 0; i < (n); ++i)
#define repA(i, a, n)  for(ll i = a; i <= (n); ++i)
#define repD(i, a, n)  for(ll i = a; i >= (n); --i)
#define trav(a, x) for(auto& a : x)
#define aint(x) x.begin(), x.end()
#define sz(x) (ll)(x).size()
#define fiint(a)  memset(a, 0, sizeof (a))
#define fst first
#define snd second
#define max(a,b) (a>b)?a:b
#define ll long long
#define mp make_pair
#define pb push_back
const long verybig = 10000000000000;
typedef long double ld;
 
typedef pair<ll, ll> pii;
typedef vector<ll> vi;
#define mod 1000000007
 
 
// g++ codec.cpp && ./a.out
 
void solve(){
	int n; cin >> n;
	double p[n];
	rep(i,n) cin >> p[i];
	double prod = (1-p[0]);
	double dp[n][n];
	dp[0][0] = p[0];
	for(int i = 1; i < n; ++i) {
		for(int j=0; j <= i; j++) {
			if(j == 0) {
				dp[i][j]=dp[i-1][j] * (1-p[i]) + prod * p[i];
			} else if(j < i){
				dp[i][j]=dp[i-1][j]*(1-p[i])+ dp[i-1][j-1]*(p[i]); 
			} else {
				dp[i][j] = dp[i-1][j-1] * p[i];
			}
		}
		// cout << prod << " ";
		prod *= (1-p[i]);
	}
	// cout << "\n";
	// for(int i = 0; i < n; ++i) {
		
	// 	for(int j = 0; j <= i; ++j) {
	// 		cout << dp[i][j] << " ";
	// 	}
	// 	cout << "\n";
	// }
	double sum = 0;
	int lim = n/2; 
	// if(n%2 == 0) lim++;
	for(int i = lim; i < n; i++) sum += dp[n-1][i];
	 cout << fixed << setprecision(10) << sum << endl;
}
 
int main() {
	cin.sync_with_stdio(0); cin.tie(0);
	cin.exceptions(cin.failbit); 
    // #ifndef	ONLINE_JUDGE
	// 	freopen("input.txt", "r", stdin);
	// #endif
 
    // ll t;
    // cin >> t;
    // rep(i,t)
	solve();
	return 0;
}

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

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

    int cnt = 0;
    while (n--) {
        string in;
        cin >> in;

        bool flag = false;
        range (i, 1, 100) {
            if (i > in.size()) break;
            rep (j, i) {
                string tmp = "";
                for (int k = j; k < in.size(); k += i) tmp += in[k];
                rep (k, (int)tmp.size() - (int)s.size() + 1) {
                    string cmp = "";
                    rep (l, s.size()) cmp += tmp[k + l];
                    if (cmp == s) flag |= true;
                }
            }
        }
        cnt += flag;
    }

    cout << cnt << endl;

    return 0;
}


Measured memory_bytes: 3200
#include<bits/stdc++.h>
using namespace std;
#define fastio ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define ll long long int
#define ull unsigned long long int
#define db double
#define ff first
#define ss second
#define mp make_pair
#define pb push_back
#define lb lower_bound
#define ub upper_bound 
#define pii pair<int , int>
#define pdd pair<double , double>
#define pll pair<long long int,long long int>
#define vpl vector<pll >
#define vll vector<ll >
#define mod 1000000007
#define inf 1e18
#define eps 0.000001
#define endl '\n'
int main()
{  
    fastio;
    //#ifndef ONLINE_JUDGE
        //freopen("input.txt", "rt", stdin);
        //freopen("output.txt", "wt", stdout);
    //#endif
    ll n;
    cin>>n;
    ll n1=n,s=0;
    while(n1!=0)
    {
        ll c=n1%10;
        s+=c;
        n1/=10;
    }
    if(n%s==0)
        cout<<"Yes";
    else
        cout<<"No";
}

Measured memory_bytes: 764
package main

import (
	"fmt"
)

func main() {
	var n int
	fmt.Scanf("%d", &n)

	set := make(map[int]bool, 1000000)
	set[n] = true

	for i := 2; ; i += 1 {
		var next int
		if n % 2 == 0 {
			next = n / 2
		} else {
			next = 3 * n + 1
		}

		if set[next] {
			fmt.Println(i)
			break
		}
		set[next] = true
		n = next
	}
}


Measured memory_bytes: 21760
#include <stdio.h>
#include <string.h>
#include <limits.h>
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <map>
#include <set>

typedef unsigned long long ULLONG;
typedef long long LLONG;
static const LLONG MOD_NUM = 1000000007;

template <class _T> static _T tp_abs(const _T& a) {
	//	usage:  tp_abs<type name>(a);
	return ((a < 0) ? (a * -1) : a);
}
template <class _T> static _T tp_min(_T a, _T b) {
	return a < b ? a : b;
}
template <class _T> static _T tp_max(_T a, _T b) {
	return a > b ? a : b;
}
template<class _T> static void get1int(_T& a) {
	const char* fmt = " %d";
	if (sizeof(_T) == sizeof(long long)) {
		fmt = " %lld";
	}

	if (scanf(fmt, &a) < 0) {
		printf("g1int Error\n");
	}
}
template<class _T> static void get2int(_T& a, _T& b) {
	const char* fmt = " %d %d";
	if (sizeof(_T) == sizeof(long long)) {
		fmt = " %lld %lld";
	}

	if (scanf(fmt, &a, &b) < 0) {
		printf("g2int Error\n");
	}
}
static void getstring(char* buff) {
	if (scanf(" %s", buff) < 0) {
		printf("getstr error!\n");
	}
}

static void AGC034B_ABC();

#if 1
int main()
{
	AGC034B_ABC();
	fflush(stdout);
	return 0;
}
#endif

static void AGC034B_ABC()
{
	auto str = new char[200001];
	memset(str, 0, sizeof(char) * 200001);

	getstring(str);
	
	int len = strlen(str);
	LLONG ans = 0;
	int acnt = 0;
	int bcnt = 0;
	int ccnt = 0;
	for (int i = 0; i < len; i++) {
		if (str[i] == 'A') {
			if ((bcnt > 0) || (ccnt > 0)) {
				acnt = 0;
			}
			acnt++;
			bcnt = ccnt = 0;
		}
		else if (str[i] == 'B') {
			bcnt++;
		}
		else if (str[i] == 'C') {
			ccnt++;
			if ((bcnt == 1) && (acnt > 0) && (ccnt == 1)) {
				ans += acnt;
				bcnt = ccnt = 0;
			}
			else {
				acnt = bcnt = 0;
			}
		}
	}

	printf("%lld\n", ans);
	delete[] str;
}


Measured memory_bytes: 384
import sys, bisect, math, itertools, string, queue, copy
import numpy as np
import scipy
from collections import Counter,defaultdict,deque
from itertools import permutations, combinations
from heapq import heappop, heappush
# input = sys.stdin.readline
sys.setrecursionlimit(10**8)
mod = 10**9+7
def inp(): return int(input())
def inpm(): return map(int,input().split())
def inpl(): return list(map(int, input().split()))
def inpls(): return list(input().split())
def inplm(n): return list(int(input()) for _ in range(n))
def inplL(n): return [list(input()) for _ in range(n)]
def inplT(n): return [tuple(input()) for _ in range(n)]
def inpll(n): return [list(map(int, input().split())) for _ in range(n)]
def inplls(n): return sorted([list(map(int, input().split())) for _ in range(n)])

n = inp()
ans = 0
for i in range(1,n+1,2):
    cnt = 0
    for div in range(1,i+1):
        if i % div == 0:
            cnt += 1
    if cnt == 8:
        ans +=1
print(ans)

Measured memory_bytes: 31180
H, N = map(int, input().split())
dp = [10 ** 18] * (H + 1)

dp[0] = 0

for i in range(N):
    a, b = map(int, input().split())
    for j in range(H):
        nj = min(j + a, H)  # nj: 次のjのindex, 配列外参照しないようにminをとる
        dp[nj] = min(dp[nj], dp[j] + b)

print(dp[H])



Measured memory_bytes: 43740
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<cmath>
#include<stack>
#include<queue>
#include<deque>
#include<map>
#include<set>
#include<bitset>
using namespace std;
typedef long long ll;
typedef vector<int> VI;
#define FOR(i,a,n) for(int (i)=(a);(i)<(n);(i)++)
#define eFOR(i,a,n) for(int (i)=(a);(i)<=(n);(i)++)
#define SORT(i) sort((i).begin(),(i).end())
#define rSORT(i,a) sort((i).begin(),(i).end(),(a))
constexpr auto INF = 1000000000;
constexpr auto LLINF = 1LL << 60;
constexpr auto mod = 1000000007;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; }return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; }return 0; }

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

    int n, m;
    ll p;
    cin >> n >> m >> p;
    int a, b;
    ll c;
    vector<tuple<int, int, ll>> edge;
    FOR(i, 0, m) {
        cin >> a >> b >> c;
        edge.push_back(make_tuple(--a, --b, c - p));
    }

    vector<ll> ans(n, -LLINF);
    ans[0] = 0;
    bool neg = false;
    eFOR(i, 1, n * 2) {
        for (auto next : edge) {
            tie(a, b, c) = next;
            if (chmax(ans[b], ans[a] + c)) {
                if (i >= n && b == n - 1)neg = true;
            }
        }
    }

    cout << (neg ? -1 : max(ans[n - 1], 0LL)) << "\n";
}


Measured memory_bytes: 512
#include <iostream>
#include <cstdio>
#include <vector>
#include <cmath>
#include <map>
#include <algorithm>
#include <string>
#include <utility>
#include <set>
#include <stack>
#include <deque>
#include <ctime>
#include <random>
#include <cassert>
#include <cmath>
#include <climits>
#include <queue>
#include <cstring>
#include <bitset>
#include <iomanip>
#include <chrono>

/*
#pragma GCC optimize("Ofast")
#pragma GCC optimize("unroll-loops")
#pragma GCC target("popcnt")
#pragma GCC target("avx2")
*/


#ifdef LOCAL
	#define dbg(x) cout << #x << " : " << x << endl;
#else 
	#define dbg(x)
#endif

#define fi(a,b) for (int i=a;i<b;i++)
#define fj(a,b) for (int j=a;j<b;j++)
#define fk(a,b) for (int k=a;k<b;k++)
#define fi1(a,b) for (int i=a-1;i>=b;i--)
#define fj1(a,b) for (int j=a-1;j>=b;j--)
#define fk1(a,b) for (int k=a-1;k>=b;k--)
#define fx(x,a) for (auto& x : a)
#define rep(i, a, b) for (int i = a; i < b; ++i)
#define rep1(i, a, b) for (int i = a - 1; i >= b; --i)
#define siz(x) (int)x.size()
#define lb lower_bound
#define ub upper_bound
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()

using namespace std;

template<typename T1, typename T2>inline void mine(T1 &x, T2 y) { if (x > y) x = y; }
template<typename T1, typename T2>inline void maxe(T1 &x, T2 y) { if (x < y) x = y; }

ostream& operator << (ostream &a, const vector<int> &b) {
    for (auto k : b) cout << k << ' ';
    return a;
}


typedef long long ll;
typedef unsigned long long ull;
typedef char ch;
typedef string str;
typedef pair<int, int> pii;
typedef map<int, int> mii;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<pii> vpii;
typedef vector<vpii> vvpii;
typedef vector<ch> vch;
typedef vector<vch> vvch;
typedef vector<str> vs;



const int MOD = 1000000007;
const int INF = 1000000050;
const long long BIG = (long long)2e18 + 50;
const int MX = 18;
const double EPS = 1e-9;


mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());


int cur[(1 << MX) + 1];
int32_t main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
   	
   	int n;
   	cin >> n;
   	set<pii> need;
   	fi(0, 1 << n) {
   		int x;
   		cin >> x;
   		auto it = need.lb({x, 0});
   		int was = 0;
   		if (it != need.end() && it->first == x)
   			was = it->second;
   		need.erase({x, was});
   		need.insert({x, was + 1});
   	}
   	auto it = --need.end();
   	int val = it->first;
   	int now = it->second - 1;
   	cur[0] = val;
   	need.erase(it);
   	if (now)
   		need.insert({val, now});
   	fi(0, n) {
   		fj(0, 1 << i) {
   			it = need.lb({cur[j], 0});
   			if (it == need.begin()) {
   				cout << "No\n";
   				return 0;
   			}
   			--it;
   			val = it->first;
   			now = it->second - 1;
   			cur[j + (1 << i)] = val;
   			need.erase(it);
		   	if (now)
		   		need.insert({val, now});
   		}
   	}
   	cout << "Yes\n";
}

Measured memory_bytes: 13568
#!/usr/bin/env python3
# Generated by https://github.com/kyuridenamida/atcoder-tools
from typing import *
import collections
import functools
import itertools
import math
import sys

INF = float('inf')


def solve(N: int, S: str):
    return "".join(chr((ord(c) - ord('A') + N) % 26 + ord('A')) for c in S)


def main():

    sys.setrecursionlimit(10 ** 6)

    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    S = next(tokens)  # type: str
    print(f'{solve(N, S)}')


if __name__ == '__main__':
    main()


Measured memory_bytes: 75304
#include <iostream>
using namespace std;
long n, a[100010], tmp;

int main() {
  cin.tie(0); ios_base::sync_with_stdio(false);
  cin >> n;
  for(int i = 0; i < n; ++i) cin >> a[i];

  // calc
  long amin = 0, amax = 2;
  for(int i = 0; i < n; ++i) {
    // min
    if(amin > a[n-1-i]) amin = (amin + a[n-1-i] - 1) / a[n-1-i] * a[n-1-i];
    else amin = a[n-1-i];
    
    // max
    amax = (amax / a[n-1-i] + 1) * a[n-1-i] - 1;
  }
  
  // min check
  tmp = amin;
  for(int i = 0; i < n; ++i) tmp = tmp / a[i] * a[i];
  if(tmp != 2) { cout << -1; return 0; }

  // max check
  tmp = amax;
  for(int i = 0; i < n; ++i) tmp = tmp / a[i] * a[i];
  if(tmp != 2) { cout << -1; return 0; }

  cout << amin << " " << amax;
  return 0;
}


Measured memory_bytes: 1024
def flip(x):
	if x:
		return False
	else:
		return True


n, m = [int(el) for el in input().split(' ')]

if n > 1 and m > 1:
	print((n-2)*(m-2))
elif n == 1 and m > 1:
	print(m-2)
elif n > 1 and m == 1:
	print(n-2)
else:
	print(1)

Measured memory_bytes: 3064
def main():
    path_list = [0] * 4

    for _ in range(3):
        a, b = map(int, input().split())
        path_list[a - 1] += 1
        path_list[b - 1] += 1

    odd, even = 0, 0
    for path in path_list:
        if path % 2 == 0:
            even += 1
        else:
            odd += 1

    if even == 4 or odd == 2:
        print("YES")
    else:
        print("NO")


if __name__ == "__main__":
    main()


Measured memory_bytes: 61984
#include<iostream>
#include<cstdio>
#include<cstring>
#include<queue>
#include<stack>
#include<cmath>
#include<algorithm>
#include<map>
typedef long long ll;
using namespace std;
#define INF 0x3f3f3f3f
/**
*超时有可能是输入的问题
*注意边界
*仔细读题
*没思路试试逆向思维
**加油，奥利给！！！ 
**/
map<int,int>p;
/*struct knd{
	int x,y,z;
}s[200000];*/ 
int a[200005];
int main()
{
	int m,n,i,j,t,k;
	ll s1=0;
	cin>>n;
	
	for(i=1;i<=n;i++)
	{
		cin>>a[i];
	 } 
	 sort(a+1,a+n+1,greater<int>());
	 t=n/2;
	 s1+=a[1];
	 for(i=2;i<=t;i++)
	 s1+=2*a[i];
	 if(n%2!=0) s1+=a[t+1];
	 cout<<s1;
 } 

Measured memory_bytes: 4016
#include <bits/stdc++.h>
#define _GLIBCXX_DEBUG
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
using namespace std;
using ll = long long;
const int INF = 1001001001;
const int MOD = 1000000007;
typedef long long ll;


int main(){
    int N;
    cin >> N;
    vector<int> L(N);
    rep(i, N) cin >> L[i];

    sort(L.begin(), L.end());
    int ans = 0;
    for(int b = 0; b < N; b++){
        for(int a = 0; a < b; a++) {
            int ab = L[a] + L[b];
            int r = lower_bound(L.begin(), L.end(), ab) - L.begin();
            int l = b + 1;
            ans += max(0, r - l);
        }
    }
    cout << ans << endl;
}


Measured memory_bytes: 256
using System;

    class Program
    {
        static void Main(string[] args)
        {
            int a, b, d, r;
            double f;
            string[] num = Console.ReadLine().Split(' ');
            a = int.Parse(num[0]);
            b = int.Parse(num[1]);

            d = a / b;
            r = a % b;
            f = (double)a / b;

            Console.Write(d + " " + r + " ");
            Console.WriteLine("{0:0.00000000}", f); 
        }
    }



Measured memory_bytes: 9356
#include<cstdio>
#include<cstring>
#include<iostream>
#include<algorithm>
using namespace std;
const int _=3e5+10;
int n,m,c[_];
inline void add(int x,int y){
    for(;x<=m;x+=x&(-x))c[x]+=y;
}
inline int sum(int x){
    int res=0;
    for(;x;x-=x&(-x))res+=c[x];
    return res;
}
struct node{
    int l,r,len;
}e[_];
inline bool cmp(node t1,node t2){
    return t1.len<t2.len;
}
signed main(){
    cin>>n>>m;
    for(int i=1;i<=n;i++){
        scanf("%d%d",&e[i].l,&e[i].r);
        e[i].len=e[i].r-e[i].l+1;
    }
    sort(e+1,e+1+n,cmp);
    int num=1;
    for(int d=1;d<=m;d++){
        while(e[num].len<d&&num<=n)
        { add(e[num].l,1); add(e[num].r+1,-1); num++; }
        int ans=n-num+1;
        for(int j=1;j*d<=m && d;j++)ans+=sum(j*d);
        
        printf("%d\n",ans);
    }
}

Measured memory_bytes: 4992
S = str(input())
N = int(len(S))

s1 = S[0:(N-1)//2]
s2 = S[((N+3)//2)-1:]
s1_r = ''.join(list(reversed(s1)))
s2_r = ''.join(list(reversed(s2)))

ans = 'No'

if s1==s2==s1_r==s2_r:
    ans = 'Yes'

print(ans)


Measured memory_bytes: 3060
#include <iostream>
#include <vector>
#include <algorithm>
#include <queue>
#include <set>
#include <string>
#include <cmath>
#include <map>
#include <iomanip>
#include <tuple>
#include <functional>
#include <bitset>
#define INF 1000000009
#define LINF 1000000000000000009
#define EPS 1e-10
#define double long double
#define all(a) a.begin(),a.end()
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
typedef pair<ll, P> PP;
template<class T> bool chmax(T &a, const T&b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> bool chmin(T &a, const T&b) { if (a > b) { a = b; return 1; } return 0; }
ll gcd(ll n, ll m) { return (m ? gcd(m, n%m) : n); }
ll lcm(ll n, ll m) { return n / gcd(n, m)*m; }

int main(){
	string s;
	int k;
	cin >> s >> k;
	set<string> st;
	int n = s.size();
	for (int i = 0; i < n; i++) {
		for (int j = 0; j < min(k, n - i); j++) {
			string t = "";
			for (int k = 0; k <= j; k++) {
				t += s[i + k];
			}
			st.insert(t);
		}
	}
	for (int i = 0; i < k - 1; i++) {
		st.erase(*st.begin());
	}
	cout << *st.begin() << endl;
}

Measured memory_bytes: 1664
#include <iostream>
using namespace std;
/*
������
���Ȃ���
inline long long R(long long n) {
	if (n == 0) {
		return 2;
	}
	else if (n == 1) {
		return 1;
	}
	else {
		return R(n - 1) + R(n - 2);
	}
}
*/

int main() {
	int n;
	long long a[87];

	cin >> n;

	a[0] = 2;
	a[1] = 1;

	for (int i = 2; i <= n; i++)
	{
		a[i] = a[i - 1] + a[i - 2];
	}

	cout << a[n] << endl;

	return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<set>
#include<algorithm>
#include<string>
#include<cstring>
#include<cstdio>
#include<cstdlib>
#include<iomanip>
#include<fstream>
using namespace std;
typedef long long ll;
#define fast_io ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);

int main()
{
    fast_io;
    #ifndef ONLINE_JUDGE
        freopen("input.txt", "r", stdin);
        freopen("output.txt", "w", stdout);
    #endif
    
    int t, a[4];
    cin >> t;
    memset(a, 0, sizeof(a));

    while (t--)
    {
        string s;
        cin >> s;

        if (s == "AC")
            a[0]++;
        else if (s == "WA")
            a[1]++;
        else if (s == "TLE")
            a[2]++;
        else
            a[3]++;
    }

    cout << "AC x " << a[0] << endl;
    cout << "WA x " << a[1] << endl;
    cout << "TLE x " << a[2] << endl;
    cout << "RE x " << a[3] << endl;
    
    return 0;
}

Measured memory_bytes: 3224
#include <iostream>

using namespace std;

int main(){

    // dist <= k  -> directly connected
    long long a,b,c,d,e,k;
    cin>>a>>b>>c>>d>>e>>k;

    long long max_sub = e-a;
    if (max_sub > k)
        cout<<":(";
    else
        cout<<"Yay!";

    return 0;
}


Measured memory_bytes: 256
// In the name of Allah the Lord of the Worlds.

#include<bits/stdc++.h>
using namespace std;

typedef long long ll;

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

    ll a, b;
    cin >> a >> b;
    bool space = false;
    for(int i=b-a+1;i<b+a;i++){
        if(space)cout << " ";
        space = true;
        cout << i;
    }
    cout << endl;

    return 0;
}


Measured memory_bytes: 256
#define _CRT_SECURE_NO_WARNINGS
#include <iostream>
#include <sstream>
#include <climits>
#include <cmath>
#include <string>
#include <vector>
#include <algorithm>
#include <queue>
#include <map>
#include <functional>
#include <set>
#include <numeric>
#include <stack>
#include <utility>
#include <time.h>
#include <iterator>
#include <bitset>
#include <random>
//#include "util.h"

using namespace std;
typedef unsigned uint;
typedef long long lint;
typedef unsigned long long ulint;



//呪文
template <typename _KTy, typename _Ty> ostream& operator << (ostream& ostr, const pair<_KTy, _Ty>& m) { cout << "{" << m.first << ", " << m.second << "}"; return ostr; }
template <typename _KTy, typename _Ty> ostream& operator << (ostream& ostr, const map<_KTy, _Ty>& m) { if (m.empty()) { cout << "{ }"; return ostr; } cout << "{" << *m.begin(); for (auto itr = ++m.begin(); itr != m.end(); itr++) { cout << ", " << *itr; } cout << "}"; return ostr; }
template <typename _Ty> ostream& operator << (ostream& ostr, const vector<_Ty>& v) { if (v.empty()) { cout << "{ }"; return ostr; }	cout << "{" << v.front(); for (auto itr = ++v.begin(); itr != v.end(); itr++) { cout << ", " << *itr; }	cout << "}"; return ostr; }
template <typename _Ty> ostream& operator << (ostream& ostr, const set<_Ty>& s) { if (s.empty()) { cout << "{ }"; return ostr; } cout << "{" << *(s.begin()); for (auto itr = ++s.begin(); itr != s.end(); itr++) { cout << ", " << *itr; }	cout << "}"; return ostr; }
//template <typename T> void print(T* v, int N) { if (N == 0) cout << "{ }"; cout << "{" << v[0]; for (int i = 1; i < N; i++) cout << ", " << v[i]; cout << "}"; }
#define PI 3.14159265358979323846
#define EPS 1e-8
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)
#define all(x) (x).begin(), (x).end()


int ProblemC()
{
	string S;
	cin >> S;

	int a[4];
	for (int i = 0; i < 4; i++) {
		a[i] = (int)(S[i] - '0');
	}

	char op[2] = { '+', '-' };
	for (int i = 0; i < 2; i++) {
		for (int j = 0; j < 2; j++) {
			for (int k = 0; k < 2; k++) {
				char op1 = op[i], op2 = op[j], op3 = op[k];
				int calc;
				calc = a[0];
				if (op1 == '+') calc += a[1];
				else calc -= a[1];
				if (op2 == '+') calc += a[2];
				else calc -= a[2];
				if (op3 == '+') calc += a[3];
				else calc -= a[3];

				if (calc == 7) {
					cout << a[0] << op1 << a[1] << op2 << a[2] << op3 << a[3] << "=7" << endl;
					return 0;
				}
			}
		}
	}

	return 0;
}

int main()
{
	//clock_t start, end;
	//start = clock();

	ProblemC();
	
	//end = clock();
	//printf("%d msec.\n", end - start);

	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, a, b) for (int i = a; i < b; i++)
#define all(v) v.begin(), v.end()
//'A' = 65, 'Z' = 90, 'a' = 97, 'z' = 122

int main() {
    int n;
    cin >> n;
    int f[n][10];
    rep(i, 0, n) {
        rep(j, 0, 10) {
            cin >> f[i][j];
        }
    }
    int p[n][11];
    rep(i, 0, n) {
        rep(j, 0, 11) {
            cin >> p[i][j];
        }
    }

    ll ans = -1e18;
    rep(i, 1, 1 << 10) {
        ll gain = 0;
        rep(j, 0, n) {
            int both = 0;
            rep(k, 0, 10) {
                if (i & (1 << k)) {
                    if (f[j][k]) both++;
                }
            }
            gain += p[j][both];
        }
        ans = max(ans, gain);
    }

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


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define rkc ios_base::sync_with_stdio(0);cin.tie(NULL);cout.tie(NULL);
typedef long long ll;
#define fl(i,a,b) for(ll i=a;i<b;i++)
#define rfl(i,a,b) for(ll i=a;i>b;i--)
#define pb push_back
#define mp make_pair
#define test ll t;cin>>t;while(t--)
#define lld long double
#define vpp vector<pair<ll,ll>>
#define ff first
#define ss second
const ll M = 1e9 + 7;
const double pi  =3.141592653589793238463;
int main()
{
    rkc;
    ll a,p;
    cin>>a>>p;
    cout<<(3*a+p)/2;
}

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

int main() {
    // #ifndef ONLINE_JUDGE
    // freopen("input.txt", "r", stdin);
    // freopen("output.txt", "w", stdout);
    // #endif

    string s;
    cin>>s;
    int ans = -1;
    for(int start = 0;start < s.size();start++) {
        for(int end = start;end < s.size();end++) {
            bool valid = true;
            for(char x: s.substr(start, end-start+1)) {
                if(x != 'A' && x != 'T' && x != 'G' && x != 'C') {
                    valid = false;
                    break;
                }
            }
            if(valid) ans = max(ans, end-start+1);
        }
    }
    cout<<max(0,ans);
}

Measured memory_bytes: 256
from heapq import *
def score(key):
    num = sum(key[:n])
    ans = [num]
    l = key[:n]
    heapify(l)

    for k in key[n:2 * n]:
        num -= heappushpop(l, k)
        num += k
        ans.append(num)
    return ans

n = int(input())
a = list(map(int, input().split()))
b = list(map(lambda x:-x,reversed(a)))

max_score = 0
le = score(a)
ri = reversed(score(b))
cou = map(lambda x,y:x+y, le, ri)
print (max(cou))

Measured memory_bytes: 38748
#include <bits/stdc++.h>
#define INF 1000000000
using namespace std;

int main() {


    int N;
    cin >> N;  
  vector<int> dp(N+2,0);
    vector<int>A(N);
    for (int i = 0; i < N; i++) { cin >> A.at(i); }
    
  for(int i=0;i<N-1;i++){
    int jump1;
    int jump2;
    if(A[1]<A[0])dp[1]=A[0]-A[1];
    else{dp[1]=A[1]-A[0];}
    if(A[i+2]<A[i+1])jump1=A[i+1]-A[i+2];
    else{jump1=A[i+2]-A[i+1];}
    if(A[i+2]<A[i])jump2=A[i]-A[i+2];
    else{jump2=A[i+2]-A[i];}
    dp[i+2]=min(dp[i+1]+jump1,dp[i]+jump2);}
    cout<<dp[N-1]<<endl;
}

Measured memory_bytes: 1024
A, B, C, X, Y = map(int, input().split())
ans = A * X + B * Y
for i in range(1, max(X, Y) + 1):
    ab_n = i * 2
    mix = C * ab_n + A * max(0, X - i) + B * max(0, Y - i)
    ans = min(ans, mix)
print(ans)


Measured memory_bytes: 3060
#include<bits/stdc++.h>
using namespace std;
int main(){
        int i,j,k,n;
        vector <int> v;
        cin>>n>>k;
        for(i=0;i<n;i++){
                cin>>j;
                v.push_back(j);
        }
        int *a=new int[n];
        a[0]=0;a[1]=abs(v[1]-v[0]);
        for(i=2;i<n;i++){
		a[i]=a[i-1]+abs(v[i-1]-v[i]);
		for(j=max(i-k,0);j<i-1;j++){
                a[i]=min(a[j]+abs(v[j]-v[i]),a[i]);
		}
	}


        cout<<a[n-1]<<endl;
}



Measured memory_bytes: 1144
//Classic
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define vll vector<ll>
#define vi vector<int>
#define pi pair<int,int>
#define vp vector<pi>
#define pb push_back
#define mp make_pair
#define F first
#define S second
#define For(i,a,b) for(ll i=a;i<b;i++)
#define endl "\n"
#define debug(x) cout<<"AA Baju Smit------> "<<#x<<" -> "<<x<<endl
#define all(x) x.begin(),x.end()
#define mint map<int,int>
#define mod 998244353
#define ciN cin
#define X INT_MAX
#define N INT_MIN
////////////////////////////////////////////////////////////////

//vi ok(1000001, 0);


void jabru() {

	int n; ciN >> n;
	vi v(n);
	ll ans = 0;
	for (int i = 1; i < n; i++) {

		for (int j = i; j < n; j += i) {
			v[j]++;
		}
		//ans += v[i];
	}
	for (int i = 1; i < n; i++) {
		ans += v[i];
	}
	cout << ans;
	cout << endl;
}

////////////////////////////////////////////////////////////////


int main() {
	ios::sync_with_stdio(0);
	cin.tie(0);
	int t;
	t = 1;
//	Sieve(1000001);
	//cin >> t;
	while (t--)
		jabru();


	return 0;
}





///////////////////////////////////////////////////////////////////////////////////////////
//Kai baju bhai???


Measured memory_bytes: 7160
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<int(n);++i)
const double PI = acos(-1);

typedef complex<double> Point;
typedef vector<Point> VP;

int main(void){
    int n;
    cin >> n;
    VP ps(n);
    rep(i,n){
        double x,y;
        cin >> x >> y;
        ps[i] = Point(x,y);
    }
    double M = 10000;
    double res = 0;
    rep(i,M){
        Point inf = polar(1e9, 2.0*PI*(i/M));
        VP used;
        Point p(0,0);
        rep(j,n){
            if (abs(ps[j]-inf) < 1e9) {
                p += ps[j];
            }
        }
        res = max(res, abs(p));
    }
    printf("%.20f\n", res);
    return 0;
}


Measured memory_bytes: 384
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
#define INF (int)(1e9)
#define MAXX 1.1529215e+18
#define inf 999999
#define EPS (1e-7)
#define rep(i,n) for(int i=0; i<(int)(n);i++)
#define FOR(i,k,n) for(int i=(k);i<(int)(n);i++)
#define ALL(a)  a.begin(),a.end()
#define RALL(a) a.begin(),a.end(),greater<int>()
#define PI acos(-1.0)
const ll MOD = 1e9+7;
const int MAX = 10000000;
template<typename T1, typename T2> inline bool chmin(T1 &a, T2 b) { if (a > b) { a = b; return 1; } return 0; }
template<typename T1, typename T2> inline bool chmax(T1 &a, T2 b) { if (a < b) { a = b; return 1; } return 0; }
template<typename T> T gcd(T a, T b) { if (b == 0) return a; return gcd(b, a % b); }
//next_permutation(ALL(p));
//typedef priority_queue<int> pque;//これは大きい順
//typedef priority_queue<int, vector<int>, greater<int>> pque;//これは小さい順
//factorizeは、素因数分解用の関数

int main(){
  int x,n;
  cin >> x >> n;
	vector<bool> p(105,false);
  rep(i,n){
    int a;
    cin >> a;
    p[a] = true;
  }

  int min=1000;
  int min_index = 0;
  rep(i,105){
    if(p[i] == false && min > abs(x-i)){
      min = abs(x-i);
      min_index = i;
    }
  }
  cout << min_index << endl;


  return 0;
}


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

using namespace std;

bool solve(string &s) {
	for (int i = 0; i < s.size() - 1; i++) {
		if (s[i] == s[i+1]) {
			cout << i+1 << ' ' << i+2;
			return true;
		}
	}
	for (int i = 0; i < s.size() - 2; i++) {
		if (s[i] == s[i+2]) {
			cout << i+1 << ' ' << i+3;
			return true;
		}
	}
	return false;
}

int main() {
	ios_base::sync_with_stdio(false);
	string s;
	cin >> s;
	if (!solve(s)) {
		cout << "-1 -1";
	}
	cout << '\n';
	return 0;
}

Measured memory_bytes: 512
# coding: utf-8
n, m, k = map(int,input().split())
flg=False
for i in range(n+1):
    for j in range(m+1):
        if i*m + (n-i)*j - i*j == k:
            flg=True
if flg:
    print("Yes")
else:
    print("No")

Measured memory_bytes: 64928
#include <array>
#include <iostream>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <string>

using namespace std::literals;

const auto tests = std::array<std::string, 7>{"SUN"s, "SAT"s, "FRI"s, "THU"s,
                                              "WED"s, "TUE"s, "MON"s};

int main() {
  auto N = 0;
  auto S = ""s;

  std::cin >> N >> S;

  for (auto &c : S)
    c = (c - 'A' + N) % 26 + 'A';

  std::cout << S;
  return 0;
}


Measured memory_bytes: 888
arg1 = input().strip()

if arg1 == "SUN":
    print("7")
elif arg1 == "MON":
    print("6")
elif arg1 == "TUE":
    print("5")
elif arg1 == "WED":
    print("4")
elif arg1 == "THU":
    print("3")
elif arg1 == "FRI":
    print("2")
elif arg1 == "SAT":
    print("1")


Measured memory_bytes: 2940
#include "bits/stdc++.h"

using namespace std;

void solve(void)
{
	int n, m, s, t;
	cin >> n >> m;
	vector<int> g[3*n];
	while(m--)
	{
		int u, v;
		cin >> u >> v;
		u--, v--;
		g[u].push_back(v+n);
		g[u+n].push_back(v+2*n);
		g[u+2*n].push_back(v);
	}
	cin >> s >> t;
	s--, t--;
	vector<int> ds(3*n, -1);
	queue<int> q;
	ds[s] = 0;
	q.push(s);

	while(!q.empty())
	{
		int v = q.front();
		q.pop();
		for (int nv : g[v])
		{
			if (ds[nv] != -1) continue;
			ds[nv] = ds[v] + 1;
			q.push(nv);
		}
	}
	int ans = ds[t] == -1 ? -1 : ds[t] / 3;
	cout << ans << endl;

}

int main()
{
	solve();
	//cout << "yui(*-v・)yui" << endl;
	return 0;
}


Measured memory_bytes: 17792
while 1:
        n = input()
        if n == 0: break
        for j in range(n):
                if j == 0: ns = raw_input()
                temp = ''
                count = 1
                for i in range(len(ns)-1):
                        if ns[i] == ns[i+1]:
                                count += 1
                        else:
                                temp += str(count)+ns[i]
                                count = 1
                temp += str(count)+ns[-1]
                ns = temp
        print ns

Measured memory_bytes: 5080
#include <iostream>
#include<bits/stdc++.h>
using namespace std;
 
int main() {
	string s;
	cin>>s;
	for(int i=0;i<s.size();i++)
	{
		if(s[i]=='1')s[i]='9';
		else if(s[i]=='9')s[i]='1';
	}
	cout<<s;
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
# define ll long long int
int main(){
	ll n,a,b,i,d,p,z;
	cin>>n>>a>>b;
	vector<ll> v(n);
	for(i=0;i<n;i++){
		cin>>v[i];
	}sort(v.begin(),v.end());
	i=upper_bound(v.begin(),v.end(),a)-v.begin();
	p=n-(upper_bound(v.begin(),v.end(),b)-v.begin());
	z=n-i-p;
	d=min(i,p);
	d=min(d,z);
	cout<<d;
}


Measured memory_bytes: 256
#include "bits/stdc++.h"
using namespace std;
#define sim template < class c
#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 << endl; }
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__) << "] "

void solve(){
    int d,t,s;
    cin>>d>>t>>s;
    if(s*t>=d){
        cout<<"Yes\n";
    }
    else{
        cout<<"No\n";
    }
}

int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int t=1;
    // cin>>t;
    while(t--){
        solve();
    }
    return 0;
}

Measured memory_bytes: 3644
using System;
using System.Collections;
using System.Linq;
class Program
{
    static void Main()
    {
        //以下入力を受け取る
        int x = int.Parse(Console.ReadLine()); //xは1以上1000以下の整数

        //以下1000以下のべき乗数を求める
        ArrayList n = new ArrayList();
        n.Add(1);
        for (int i = 2; i <= 1000; i++)
            for (int j = 2; j <= (int)Math.Log(1000, i); j++)
                n.Add((int)Math.Pow(i, j));
        int[] num = (int[])n.ToArray(typeof(int));

        //numの表示
        //for (int i = 0; i < num.Length; i++)
        //    Console.Write("{0} ", num[i]);
        //Console.WriteLine();

        //以下処理内容
        int ans = num.Select(s => (s <= x) ? s : 1).ToArray().Max();
        ans = (x == 1000) ? 1000 : ans;

        //以下解答の出力
        Console.WriteLine(ans);
    }
}

Measured memory_bytes: 13396
#pragma GCC optimize("Ofast")
    #pragma GCC optimize("unroll-loops")
    #pragma GCC target("sse2")
 
    #include <bits/stdc++.h>
    #include <vector> 
    #include <ext/pb_ds/assoc_container.hpp>
    #include <ext/pb_ds/tree_policy.hpp>
    using namespace std;
 
    #define int         long long
    #define ll          long long
    #define pb          push_back
    #define pii         pair<int,int>
    #define vi          vector<int>
    #define vii         vector<pii>
    #define mi          map<int,int>
    #define mii         map<pii,int>
    #define mp          make_pair
    #define all(a)      (a).begin(),(a).end()
    #define FF           first
    #define SS           second
    #define sz(x)       (int)x.size()
    #define endl        '\n'
    #define rep(i,a,b)  for(int i=a;i<b;i++)
     ll hell=1000000007;

      const int N=200005;
      vi seg,seg1;
      
    int n;
     void build(int n)
     {
        seg.resize(n<<1);seg1.resize(n<<1);
        fill(all(seg),n);
        fill(all(seg1),n);
     }

    void modify(int l,int r,int val)
    {
        for(l+=n,r+=n;l<r;l>>=1,r>>=1)
            {
                if(l&1)seg[l++]=val;
                if(r&1)seg[--r]=val;
            }
    }

    int query(int p)
    {
        int res=n;
        for(p+=n;p>0;p>>=1)res=min(res,seg[p]);
            return res;
    }


    void modify1(int l,int r,int val)
    {
        for(l+=n,r+=n;l<r;l>>=1,r>>=1)
            {
                if(l&1)seg1[l++]=val;
                if(r&1)seg1[--r]=val;
            }
    }

    int query1(int p)
    {
        int res=n;
        for(p+=n;p>0;p>>=1)res=min(res,seg1[p]);
            return res;
    }


   
  
    int solve(){  
       
      int q;
      cin>>n>>q;
      build(n);

      int ans=(n-2)*(n-2);
      //cout<<ans<<endl;

     
      rep(i,0,q)
      {
        int x,y;
        cin>>x>>y;
        if(x==1)
        {
           int x1=query(y);
          // cout<<x1<<" ";
           ans-=max(x1-2,0LL);
           if(y<=query1(1))
           modify1(1,x1,y);
        }
        else
        {
           int x1=query1(y);
             //cout<<x1<<" ";
           ans-=max(x1-2,0LL);
           if(y<=query(1))
           modify(1,x1,y);
        }
        //cout<<ans<<endl;
       // if(i==0)return 0;
      }
       
       cout<<ans<<endl;

     return 0;
        }


    signed main()
    {       


  
 
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0); 
 
    int t=1,k=1;                                                                                                                  
    //cin>>t;
   
    while(t--)
    {
     
     // cout<<"Case #"<<k++<<": ";
     solve();
     //cout<<endl;
    }
    return 0;
    } 

Measured memory_bytes: 9504
using System;

public class Test
{
	public static void Main( )
	{
		string str = Console.ReadLine();
		int q = int.Parse( Console.ReadLine() );
		for( var i=0; i<q; i++ ) {
			string[] cmds = Console.ReadLine().Split( ' ' );
			int s = int.Parse( cmds[1] );
			int e = int.Parse( cmds[2] );
			int len = e-s+1;
			if( "print" == cmds[0] ) {
				Console.WriteLine( str.Substring( s, len ) );
			} else if( "reverse" == cmds[0] ) {
				char[] arr = str.Substring( s, len ).ToCharArray();
				Array.Reverse( arr );
				string t = new string( arr );
				str = str.Substring( 0, s )+t+str.Substring( e+1 );
			} else if( "replace" == cmds[0] ) {
				str = str.Substring( 0, s )+cmds[3]+str.Substring( e+1 );
			}
		}
	}
}

Measured memory_bytes: 9028
#include <stdio.h>

int main()
{
	int ary[4][3][10] = {0};
	int n;
	int i;
	int z,y,x,w;

	scanf("%d", &n);
	for (i = 0; i < n; ++i) {
		scanf( "%d %d %d %d",&z, &y, &x, &w);
		ary[z-1][y-1][x-1] += w;
	}

	for (z = 0; z < 4; ++z) {
		for (y = 0; y < 3; ++y) {
			for (x = 0; x < 10; ++x) {
				putchar(' ');
				putchar('0' + ary[z][y][x]);
			}
			putchar('\n');
		}
		if (z != 3) puts("####################");
	}
	return 0;
}

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

using namespace std;

typedef long long ll;

const int INF = 1e9;
const ll LLINF = 1e18;
const ll MOD = (ll)1e9 + 7;

int main()
{
  int Q; scanf("%d", &Q);
  int N = 1e5;
  vector<bool> primes(N + 5, true);
  primes[0] = primes[1] = false;
  for (int i = 2; i * i <= N; ++i) {
    if (not primes[i]) { continue; }
    for (int j = i * i; j <= N; j += i) {
      primes[j] = false;
    }
  }

  vector<int> sims(N + 5, 0);
  for (int i = 3; i <= N; ++i) {
    if (primes[i] and primes[(i + 1) / 2]) {
      sims[i] = 1;
    }
  }
  for (int i = 3; i <= N; ++i) {
    sims[i] += sims[i - 1];
  }

  int l, r, ans;
  while (Q-- > 0) {
    scanf("%d %d", &l, &r);
    ans = sims[r] - sims[l - 1];
    printf("%d\n", ans);
  }
  return 0;
}


Measured memory_bytes: 1024
#include <iostream>
#include <string>
#include <algorithm>
using namespace std;
int dp[1002][1002];

int main(){
	int n;cin >> n;
	string x, y;
	while(n--){
		fill((int*)dp, (int*)(dp+1002), 0);
		cin >> x >> y;
		for(int i = 1;i <= x.size();i++){
			for(int j = 1;j <= y.size();j++){
				if(x[i-1] == y[j-1])dp[i][j] = dp[i-1][j-1] + 1;
				else dp[i][j] = max(dp[i-1][j], dp[i][j-1]);
			}
		}
		cout << dp[x.size()][y.size()] << endl;
	}
	return 0;
}

Measured memory_bytes: 7120
#include <bits/stdc++.h>
using namespace std;
// マクロ
#define rep(i,n) for (int i = 0; i < (int)(n); i++)
// 型エイリアス
using ll = long long;
using vi = vector<int>;
using vs = vector<string>;
using vvi = vector<vi>;
using vvs = vector<vs>;

int main() {
	int n;
  cin >> n;
  cout << "ABC" << n << endl;
}

Measured memory_bytes: 256
#include <iostream>

using namespace std;

int main()
{
    int n, a, b;
    cin >> n >> a >> b;

    int sum = 0;
    for (int i = 0; i <= n; i++) {
        int d_sum = 0;
        for (int j = i; j > 0; j/=10) d_sum += j % 10;
        if (a <= d_sum && d_sum <= b) sum += i;
    }

    cout << sum << endl;
}

Measured memory_bytes: 256
#include <bit>
#include <bitset>
#include <assert.h>
#include <stdio.h>
#include <string.h>
#include <algorithm>
#include <sstream>
#include <iostream>
#include <set>
#include <map>
#include <vector>
#include <math.h>
#include <stdlib.h>
#include <queue>
#include <stack>
#include <iomanip>

typedef long double ld;
typedef long long ll;

using namespace std;


/* TEMPLATE ENDS HERE */

int main() {
	cout << fixed << setprecision(12);	
	string s;
	int n;
	cin >> n;
	cin >> s;
	int i = 0, j = n - 1;
	while (s[i] == 'R') {
		i++;
	}
	while (s[j] == 'W') {
		j--;
	}
	int ret = 0;
	while (i < j) {
		if (s[i] == 'R' && s[j] == 'W') {
			i++;
			j--;
		} else if (s[i] == 'W' && s[j] == 'R') {
			ret++;
			i++;
			j--;
		} else if (s[i] == 'W') {
			j--;
		} else {
			i++;
		}
	}
	cout << ret << endl;
	return 0;
}


ll MOD = ((ll)1e9 + 7);

struct mod {
	ll x;

	mod(ll tx = 0) {
		x = tx;
		x %= MOD;
	}
	
	mod& operator=(const ll & tx) {
		x = tx % MOD;
		return *this;
	}
	
	mod& operator=(const mod & m2) {
		x = m2.x;
		return *this;
	}

	mod operator+(const mod& m2) const {
		return mod((x + m2.x) % MOD);
	}

	mod& operator+=(const mod& m2) {
		x += m2.x;
		x %= MOD;
		return *this;
	}

	mod operator-(const mod & m2) const {
		return mod((x - m2.x + MOD) % MOD);
	}

	mod& operator-=(const mod & m2) {
		x -= m2.x;
		x = (x + MOD) % MOD;
		return *this;
	}

	mod operator*(const mod & m2) const {
		return mod((x * m2.x) % MOD);
	}

	mod& operator*=(const mod & m2) {
		x *= m2.x;
		x %= MOD;
		return *this;
	}

	mod mypow(ll k) const {
		mod ret = 1;
		mod cur = x;
		while (k) {
			if (k & 1) {
				ret *= cur;
			}
			cur *= cur;
			k >>= 1;
		}
		return ret;
	}

	mod inv() const {
		return mypow(MOD - 2);
	}

	mod operator/(const mod & m2) const {
		return (*this) * m2.inv();
	}

	mod& operator/=(const mod & m2) {
		x *= m2.inv().x;
		x %= MOD;
		return *this;
	}

	bool operator<(const mod & m2) const {
		return x < m2.x;
	}
};

ostream &operator<<(ostream & os, const mod & m) {
	return os << m.x;
}



Measured memory_bytes: 3712