akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <algorithm>
#include <utility>
#include <string>
#include <vector>
#include <set>
#include <stack>
#include <queue>
#include <map>
#include <math.h>
#include <string.h>
#include <iomanip>
#include <numeric>
#include <cstdlib>
#include <cstdint>
#include <cmath>
#include <functional>
#include <limits>

using namespace std;

using ll = long long;
using pll = pair<ll, ll>;
using vl = vector<ll>;
using vll = vector<vl>;
using vpll = vector<pll>;

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rrep(i, n) for (int i = ((int)(n)-1); i >= 0; i--)
#define Rep(i, n) for (long long i = 0; i< (long long)(n); i++)
#define RRep(i,n) for (long long i = ((long long)(n)-1); i>=0; i--)
#define all(v) (v).begin(),(v).end()

struct Edge{
    int to;
    int weight;
    Edge(int t, int w) : to(t), weight(w){ }
};

struct edge{
    int from;
    int to;
    int weight;
    edge(int f,int t,int w) : from(f), to(t), weight(w){ }
};

using Graph = vector<vector<Edge>>;
using graph = vector<vector<int>>;
using edges = vector<edge>;

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

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

template <class T>
T gcd(T a, T b){
    if( b==0 ) return a;
    return gcd(b, a%b);
}

template <class T>
T lcm(T a, T b){
    return (a*b)/gcd(a,b);
}

constexpr ll INF = 1e9+7;

vector<int> dx = {-1,0,1,0};
vector<int> dy = {0,-1,0,1};

bool compare(pair<int,int> a,pair<int,int> b){
    if(a.first != b.first) return a.first < b.first;
    else return a.second < b.second;
}

int main(){
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    int n,m;
    cin >> n >> m;
    vector<pair<int,int>> a(n);
    rep(i,n) cin >> a[i].first >> a[i].second;
    sort(all(a),compare);
    priority_queue<int> que;
    int flag = 0;
    int ans = 0;
    for(int i = 1; i<= m; i++){
        while(a[flag].first<=i && flag<n){
            que.push(a[flag].second);
            flag++;
        }
        if(que.empty()) continue;
        ans += que.top();
        que.pop();
    }
    cout << ans << endl;
}

Measured memory_bytes: 1660
#define _USE_MATH_DEFINES
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
using P	  = pair<ll, ll>;
using mat = vector<vector<ll>>;
typedef string::const_iterator State;
class ParseError {};

void IOS() { ios::sync_with_stdio(false), cin.tie(0); }

constexpr ll INF = 1e16;
constexpr ll INM = 114514;
constexpr ll MOD = 1e9 + 7;
constexpr ld EPS = 1e-12;

template <typename T>
void dump(T x) { cout << x << endl; }
void dumpf(ld x, int t) { cout << setprecision(t) << fixed << x << endl; }
template <typename A, size_t N, typename T>
void Fill(A (&array)[N], const T &val) {
	fill((T *)array, (T *)(array + N), val);
}
inline ll mod(ll a, ll b) {
	if (a > 0) return a % b;
	if (a % b == 0) return 0;
	ll x = -a / b + 1;
	a += x * b;
	return a % b;
}
ll powm(ll a, ll b, ll c) {
	if (b == 0)
		return 1;
	else if (b % 2 == 0) {
		ll d = powm(a, b / 2, c);
		return (d * d) % c;
	} else
		return (a * powm(a, b - 1, c)) % c;
}
ll gcd(ll a, ll b) {
	if (b == 0) return a;
	return gcd(b, a % b);
}
ll lcm(ll a, ll b) { return a / gcd(a, b) * b; }
ll dx[4] = {1, 0, -1, 0};
ll dy[4] = {0, 1, 0, -1};

int main() {
	IOS();
	int n, k;
	cin >> n >> k;
	ll ans = 0;
	for (int i = 0; i < n; i++) {
		int x;
		cin >> x;
		if (x >= k) ans++;
	}
	dump(ans);
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <cstring>
#include <map>
#include <iomanip>
#include <algorithm>
#include <cmath>
#include <set>
#include <vector>
#include <queue>
#include <list>
#include <numeric>
#include <stdio.h>
#include <string>
#include <cstdlib>
#include <math.h>
#include <stack>
#include <climits>
#include <bitset>

using namespace std;
typedef long long ll;

ll gcd(ll x, ll y) {
  ll tmp = 0;
  if (x < y){
    tmp=x;
    x=y;
    y=tmp;
  }
  while (y > 0) {
    ll r = x % y;
    x = y;
    y = r;
  }
  return x;
}

//for(int i = ; i < ; i++){}

int main(){
  int h,w;
  cin>>h>>w;
  int a[h][w];
  char c[h][w];
  for(int i = 0; i < h; i++){
    for(int j = 0; j < w; j++){
      a[i][j] = 0;
    }
  }
  for(int i = 0; i < h; i++){
    for(int j = 0; j < w; j++){
      cin>>c[i][j];
      if(c[i][j] == '#'){
        if(i>0){
          if(j>0)a[i-1][j-1]++;
          if(j<w-1)a[i-1][j+1]++;
          a[i-1][j]++;
        }
        if(i<h-1){
          if(j>0)a[i+1][j-1]++;
          if(j<w-1)a[i+1][j+1]++;
          a[i+1][j]++;
        }
        if(j>0)a[i][j-1]++;
        if(j<w-1)a[i][j+1]++;
      }
    }
  }
  for(int i = 0; i < h; i++){
    for(int j = 0; j < w; j++){
      if(c[i][j]=='#')cout<<'#';
      else cout<<a[i][j];
    }
    cout<<endl;
  }
  return 0;
}




Measured memory_bytes: 256
#include<cstdio>
#include<cstring>
#include<string>
#include<algorithm>
#include<iostream>
#include<cmath>
#include<cstdlib>
#include<ctime>
#include<map>
#include<queue>
#include<vector>
#include<stack>
#include<set>
#include<cctype>
#define pa pair<int,int>
#define INF 0x3f3f3f3f
#define inf 0x3f
#define fi first
#define se second
#define mp make_pair
#define ll long long
#define ull unsigned long long
#define pb push_back

using namespace std;

inline ll read()
{
	long long f=1,sum=0;
	char c=getchar();
	while (!isdigit(c)) {if (c=='-') f=-1;c=getchar();}
	while (isdigit(c)) {sum=sum*10+c-'0';c=getchar();}
	return sum*f;
}
const int MAXN=100010;
const int MAXM=200010;
struct edge{
	int next,to,val;
}e[MAXM*10];
int head[MAXN*10],cnt;
void addedge(int u,int v)
{
	e[++cnt].next=head[u];
	e[cnt].to=v;
	head[u]=cnt;
}
vector <pa> g[MAXN];
vector <int> col[MAXN*10];
int dis[MAXN*10],visit[MAXN*10],last[MAXN*10]; 
queue <int> q;
int main()
{
	int n,m;
	scanf("%d%d",&n,&m);
	for (int i=1;i<=m;i++)
	{
		int u,v,opt;
		scanf("%d%d%d",&u,&v,&opt);
		g[u].push_back(mp(opt,v));
		g[v].push_back(mp(opt,u));
		col[opt].push_back(u);
		col[opt].push_back(v);
	}
	for (int i=1;i<=n;i++)
	{
		sort(g[i].begin(),g[i].end());
		last[i]=0;
	}
	int tot=n+1;
	for (int color=1;color<MAXN*10;color++)
	{
//		if (color%10000==0) cout<<color<<endl;
		if (col[color].size()==0) continue;
		for (int i=0;i<col[color].size();i++)
		{
			int pt=col[color][i];
			if (visit[pt]==color) continue;
			q.push(pt),visit[pt]=color;
			vector <int> vec;
			vec.clear();
			while (!q.empty())
			{
				int x=q.front();
				vec.push_back(x);
				q.pop();
				while (last[x]<(int)g[x].size())
				{
					int ncol=g[x][last[x]].fi;
					if (ncol!=color) break;
					int v=g[x][last[x]++].se;
					if (visit[v]==color) continue;
					visit[v]=color;
					q.push(v);
				}
			}
			vector <int>::iterator it;
			for (it=vec.begin();it!=vec.end();it++)
				addedge(*it,tot),addedge(tot,*it);
			tot++;
		}
	}
	memset(visit,0,sizeof(visit));
	memset(dis,-1,sizeof(dis));
	q.push(1),dis[1]=0;
	while (!q.empty())
	{
		int x=q.front();
		q.pop();
		for (int i=head[x];i;i=e[i].next)
		{
			int v=e[i].to;
			if (visit[v]) continue;
			visit[v]=1;
			dis[v]=dis[x]+1;
			q.push(v);
		}
	}
	if (dis[n]==-1) cout<<-1;
	else cout<<dis[n]/2;
	return 0;
}
/*
3 3
1 2 1
2 3 1
3 1 2
*/

Measured memory_bytes: 59392
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> PA;
typedef priority_queue<int, vector<int>, greater<int> > GQint;
typedef priority_queue<int> PQint;
typedef priority_queue<PA, vector<PA>, greater<PA> > GQpair;
typedef priority_queue<PA> PQpair;
typedef	set<int> Sint;
typedef	set<PA> SPA;
typedef map<int, int> MAP;
#define REP(i, a, n) for(ll i = (ll) a;i < (ll) n;i++)
#define fi first
#define se second
#define pb push_back
#define INF 100000001
#define MOD 100000
#define MAXN 100001
#define MAXM 30001

int n, L, t[MAXN], d[2][MAXN];
int ans;


int main()
{
    cin >> n >> L;
    REP(i, 0, n){
        cin >> t[i];
        if(i > 0){
            if(t[i] < t[i - 1]){
                d[0][i] = L - t[i] + d[0][i - 1];
                d[1][i] = L - t[i];
            }
            else {
                d[1][i] = L - t[i] + d[1][i - 1];
                d[0][i] = L - t[i];
            }
        }
        else {
            d[0][i] = L - t[i];
            d[1][i] = L - t[i];
        }
        ans = max(ans, max(d[0][i], d[1][i]));
    }
    cout << ans << endl;



    return 0;
}
/*O(10 ^ 9)(2s)
    REP(i,a){
        REP(j,b){
4 4
1 2 100
2 3 250
2 4 200
3 4 100

        }
    }
*/




Measured memory_bytes: 4260
import java.util.Scanner;

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

        int N = sc.nextInt();
        int M = sc.nextInt();
        
        //int sum=(N+M)*(N+M-1)/2;
        int even,odd;
        
        if (N>=2) {
            even=N*(N-1)/2;
        } else {
            even=0;
        }
        
        if (M>=2) {
            odd=M*(M-1)/2;
        } else {
            odd=0;
        }   
        
        System.out.println(odd+even);
    }
}

Measured memory_bytes: 21716
#include <stdio.h>
#include <string.h>


int p[10010],n[10010];

int main(){
	char line[100];
	int a,b;
	int flag=1;
	int i;
	while(fgets(line,99,stdin)!=NULL){
		if(line[0]=='\n')flag=0;
		else{
			sscanf(line,"%d,%d",&a,&b);
			if(flag)p[a]++;
			else n[a]++;
		}
	}
	for(i=0; i<10010; i++){
		if(p[i]>0&&n[i]>0){
			printf("%d %d\n",i,p[i]+n[i]);
		}
	}
	return 0;
}

Measured memory_bytes: 612
A, B = map(int, input().split())

if A == 1 or B == 1:
    if A < B:
        print("Alice")
    elif A > B:
        print("Bob")
    else:
        print("Draw")
else:
    if A > B:
        print("Alice")
    elif A < B:
        print("Bob")
    else:
        print("Draw")


Measured memory_bytes: 2940
#include <iostream>

using namespace std;

int main()
{
    long long n,a,minv=2000000,maxv=-2000000,sum=0;
    cin>>n;
    for (int i=0; i<n; i++)
    {
        cin>>a;
        if (a<minv) minv=a;
        if (a>maxv) maxv=a;
        sum+=a;
    }
    cout<<minv<<" "<<maxv<<" "<<sum<<"\n";
    return 0;
}



Measured memory_bytes: 3112
#include <bits/stdc++.h>
using namespace std;
int main(){
int N,K,sum;
  int X;
  sum=0;
  cin>>N>>K;
  for(int i=0;i<N;i++){
    cin>>X;
    if(K-X>X){
    sum=sum+2*X;
    }
    else{
    sum=sum+2*K-2*X;
    }
  }
  cout<<sum;
  
}

Measured memory_bytes: 256
#pragma GCC optimize ("O3")
#include <bits/stdc++.h>
using namespace std;
#define endl "\n"
#define X first
#define Y second
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
const double pi = acos(-1.0);
int main(){
#ifdef _DEBUG
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
#endif
    ios::sync_with_stdio(false);
    cin.tie(NULL);
    string S;
    cin >> S;
    if(S[0] == S[1] and S[1] == S[2]) cout << "No";
    else cout << "Yes";
    return 0;   
}
    

Measured memory_bytes: 256
n, a = [int(i) for i in input().split()]
x = [int(i) for i in input().split()]

nx = n * max(max(x), a)
y = [xi - a for xi in x]
dp = [[0 for j in range(2 * nx + 1)] for i in range(n + 1)]
dp[0][nx] = 1

for i in range(n):
    for j in range(2 * nx + 1):
        if not 0 <= j - y[i] <= 2 * nx:
            dp[i + 1][j] = dp[i][j]
        elif j - y[i] <= 2 * nx:
            dp[i + 1][j] = dp[i][j] + dp[i][j - y[i]]

print(dp[n][nx] - 1)


Measured memory_bytes: 5732
import sys
sys.setrecursionlimit(100100)
n=int(input())
route=[[] for i in range(n)]
for i in range(n-1):
	u,v,w=map(int,input().split())
	route[u-1].append((v-1,w))
	route[v-1].append((u-1,w))
ans=[-1]*n
def dfs(p,d):
	ans[p]=d
	for i,j in route[p]:
		if ans[i]<0:dfs(i,(d+j)%2)
dfs(0,0)
for i in range(n):
	print(ans[i])

Measured memory_bytes: 79356
#include <bits/stdc++.h>
#define rep(i, n) for (int i=0; i<(int)(n); i++)
#define all(v) v.begin(), v.end()
using namespace std;
using ll = long long;
using Graph = vector<vector<int>>;
const ll MOD = 1000000007;
const ll INF = 10000000000000000;
vector<int> x4 = {0, 1, 0, -1}, x8 = {0, 1, 1, 1, 0, -1, -1, -1};
vector<int> y4 = {1, 0, -1, 0}, y8 = {1, 1, 0, -1, -1, -1, 0, 1};
template<class T> struct edge { int from, to; T cost;};
template<class T> inline bool chmin(T& a, T b){if (a>b){a = b; return true;}return false;}
template<class T> inline bool chmax(T& a, T b){if (a<b){a = b; return true;}return false;}
template<class T> inline T powerM(T a,T b){if (b==0) return 1;
T tmp = powerM(a,b/2); if (b%2==0) return tmp*tmp%MOD; else return tmp*tmp%MOD*a%MOD; }
template<class T> inline T power(T a,T b,T m){ if (b==0) return 1;
  T tmp = power(a,b/2,m); if (b%2==0) return tmp*tmp%m; else return tmp*tmp%m*a%m; }
template<class T> inline T gcd(T a, T b){if (b==0) return a; return gcd(b, a%b);}
template<class T> inline T lcm(T a, T b){return a / gcd(a,b) * b;}
// ax+by=gcd(a,b)を解く
template<class T> inline T extgcd(T a,T b,T &x,T &y){if (b==0){x=1; y=0; return a;} T d=extgcd(b,a%b,y,x); y -= a/b*x; return d;}


int main() {
  int n,x; cin >>n >>x;
  vector<int> a(n); rep(i, n) cin >>a.at(i);
  ll res = 0;
  if (a.at(0) > x){
    res += a.at(0) - x;
    a.at(0) = x;
  }
  rep(i, n-1){
    // a[i],a[i+1]について。a[i]単独でxを超えることはない
    if (a[i]+a[i+1]>x){
      int buf = a[i]+a[i+1]-x;
      res += buf;
      a[i+1] -= buf;
    }
  }
  cout <<res <<endl;
}

Measured memory_bytes: 768
N,L = map(int,input().split())
A = list(map(int,input().split()))

last = -1
for i,(a,b) in enumerate(zip(A,A[1:])):
    if a+b >= L:
        last = i
        break
if last < 0:
    print('Impossible')
    exit()
print('Possible')

ans = list(range(1,i+1)) + list(range(N-1,i,-1))
print(*ans, sep='\n')

Measured memory_bytes: 14052
#include <iostream>
#include <algorithm>
#include<vector>
#include <queue>
#include<string>
using namespace std;
const int INF = 1000000000;

int main()
{

	char a, b, c, d, e, f;
	int ans = 0;
	cin >> a >> b >> c >> d >> e >> f;
	if (a == d)ans++;
	if (b == e)ans++;
	if (c == f)ans++;
	cout << ans << endl;
}

Measured memory_bytes: 256
#include<stdio.h>
#include<string.h>

bool flag[110];

int main(){
	memset(flag,false,sizeof(flag));
	int N,K;
	scanf("%d%d",&N,&K);
	for(int i=1;i<=K;++i){
		int temp;
		scanf("%d",&temp);
		int a;
		for(int j=1;j<=temp;++j){
			scanf("%d",&a);
			flag[a]=true;
		}
	}
	int cnt=0;
	for(int i=1;i<=N;++i){
		if(!flag[i]) cnt++;
	}
	printf("%d ",cnt);
}

Measured memory_bytes: 1732
#include <bits/stdc++.h>
#define IO ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define DB(x) cerr << __LINE__ << ": " << #x << " = " << (x) << "\n"
using namespace std;
using ll = long long;

signed main() {
    IO;
    ll n, s = 0;
    cin >> n;
    map<ll, ll> m;
    for(ll i = 0; i < n; ++i) {
    	ll r1;
    	cin >> r1;
    	++m[r1];
    	s += r1;
    }
    ll q;
    cin >> q;
    // DB(s);
    for(int i = 1; i <= q; ++i) {
    	ll b, c;
    	cin >> b >> c;
    	s -= m[b] * b;
    	s += m[b] * c;
    	cout << s << "\n";
    	m[c] += m[b];
    	m[b] = 0;
    }
    return 0;
}

Measured memory_bytes: 9608
#input of int(split by space)
def get_i()
  return gets.chomp.split(" ").map(&:to_i)
end
#input of float(split by space)
def get_f()
  return gets.chomp.split(" ").map(&:to_f)
end
#input of string(split by space)
def get()
  return gets.chomp.split(" ")
end
#input of string(split per one character)
def get_nsp()
  return gets.chomp.split("")
end
#yes or no decision
def yn_judge(bool,y="Yes",n="No")
  return bool ? y : n 
end
#create of array
def array(size1,init=nil,size2=-1)
  if size2==-1
      return Array.new(size1){init}
  else
      return Array.new(size2){Array.new(size1){init}}
  end
end

def max(a,b)
    return a>b ? a : b
end

def min(a,b)
    return a>b ? b : a
end

INF=Float::INFINITY

N=gets.to_i
if N.even?
    puts N/2-1
else
    puts N/2
end

Measured memory_bytes: 14296
#include <bits/stdc++.h>
using namespace std;
using Graph = vector<vector<int>>;
#define ll long long
#define _GLIBCXX_DEBUG
const ll MOD = 1000000007;
const ll Mod = 998244353;
const int MAX = 510000;

int main() {
  ll a, b, x;
  cin >> a >> b >> x;
  ll k = a/x, l = b/x;
  if (a%x==0) cout << l-k+1 << endl;
  else cout << l-k << endl;
}

Measured memory_bytes: 256
import java.util.Scanner;


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

		while (sc.hasNext()) {
			a = sc.nextDouble();
			op =sc.next();
			b = sc.nextDouble();
			
			if (op.equals("+")) {
				System.out.println((int)(a+b));
			}
			else if (op.equals("-")) {
				System.out.println((int)(a-b));
			}
			else if (op.equals("*")) {
				System.out.println((int)(a*b));
			}
			else if (op.equals("/")) {
				System.out.println((int)(a/b));
			}
			else if (op.equals("?")) {
				break;
			}
		}
	}
}

Measured memory_bytes: 20260
#include <iostream>
#include <vector>
#include <array>
#include <algorithm>
#include <cstring>
#include <queue>
#include <iomanip>
#include <numeric>
#include <cmath>
#include <cstdlib>
#include <sstream>
#include <bitset>

using namespace std;

using ll = long long;
using Vec = vector<ll>;
using P = pair<ll, ll>;
using VecP = vector<P>;
#define rep(i, n) for(ll i=0;i<(n);i++)
#define SIZE_OF_ARRAY(array) (sizeof(array)/sizeof(array[0]))

//static const ll MOD = 1000000007;
//static const ll INF = 100000000;
//#define PI 3.14159265359


int main() {
    // input
    ll N;
    cin >> N;
    Vec a(N, 0), b(N, 0);
    ll sum_a = 0, sum_b = 0;
    for (int i = 0; i < N; ++i) {
        cin >> a[i];
        sum_a += a[i];
    }
    for (int i = 0; i < N; ++i) {
        cin >> b[i];
        sum_b += b[i];
    }

    // process
    ll count = 0;
    rep(i, N) {
        if (a[i] < b[i]) {
            count += ceil(((double) b[i] - (double) a[i]) / 2.0);
        }
    }

    if (count > sum_b - sum_a) {
        cout << "No" << endl;
    } else {
        cout << "Yes" << endl;
    }

    return 0;
}



Measured memory_bytes: 384
#include <bits/stdc++.h>
#define be(v) (v).begin(),(v).end()
#define pb(q) push_back(q)
typedef long long ll;
using namespace std;
const ll mod=1000000007;
#define doublecout(a) cout<<fixed<<setprecision(10)<<a<<endl;

int main() {
    cin.tie(0);
    cout.tie(0);
    ios::sync_with_stdio(false);
    int n,m;
    cin>>n>>m;
    cout << n*(n-1)/2+m*(m-1)/2 <<endl;
    return 0;
}


Measured memory_bytes: 256
from heapq import heappop, heappush
from collections import deque


def solve():
    N, M = map(int, input().split())
    loadmap = [[] for _ in range(N + 1)]
    for _ in range(M):
        A, B = map(int, input().split())
        loadmap[A].append(B)
        loadmap[B].append(A)

    dbrmap = [[float('inf'), -1, 0] for _ in range(N + 1)]  # 部屋の深度, しるべ, 予約状態

    # rooms = [[0, 1, 0]]  # [移動前の部屋, 移動後(現在)の部屋, 深度]
    rooms = deque()
    rooms.append([0, 1, 0])
    dbrmap[1][2] = 1
    while rooms:
        # br, r, d = heappop(rooms)
        br, r, d = rooms.popleft()
        if d <= dbrmap[r][0]:
            # update room data
            dbrmap[r][0] = d
            dbrmap[r][1] = br
            # add new room data
            for load in loadmap[r]:
                # heappush(rooms, [r, l, d + 1])
                if dbrmap[load][2] == 0:
                    rooms.append([r, load, d + 1])
                    dbrmap[load][2] = 1

    if min([db[1] for db in dbrmap[1:]]) <= -1:
        print('No')
    else:
        print('Yes')
        for db in dbrmap[2:]:
            print(db[1])


if __name__ == '__main__':
    solve()


Measured memory_bytes: 53896
H, W, A, B = map(int, input().split())

"""
    W=12
    A=5
H=7 111110000000
B=3 111110000000
    111110000000
    00000
    00000
    00000
    00000
"""

if A == 0:
    # 行は全て同じ文字列で構成される
    for i in range(B):
        print("1"*W)
    for i in range(H-B):
        print("0"*W)
else:
    for i in range(B):
        print(("1"*A)+("0"*(W-A)))
    for i in range(H-B):
        print(("0"*A)+("1"*(W-A)))




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

#define mp make_pair
#define mt make_tuple
#define fi first
#define se second
#define pb push_back
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
#define rep(i, k, n) for (int i = (int)(k); i < (int)(n); ++i)
#define rrep(i, k, n) for (int i = (int)(n) - 1; i >= (int)(k); --i)

typedef pair<int, int> ii;
typedef vector<int> vi;
typedef vector<ii> vii;
typedef vector<vi> vvi;
typedef vector<vii> vv_ii;
typedef pair<int,ii> i_ii;
typedef vector<i_ii> vi_ii;
typedef long long ll;
typedef unsigned long long ull;
typedef double db;

template <class T>
inline ostream& operator<<(ostream & o, vector<T> const& v) {
    for (int i = 0; i < (int)(v.size()) - 1; ++i)
        o << v[i] << ' ';
    if (!v.empty())
        o << v.back();
    return o;
}

template <class T, class Q>
inline ostream& operator<<(ostream & o, pair<T,Q> const& p) {
    o << "(" << p.fi << "," << p.se << ")";
    return o;
}

const int MAX_PRIME = 100100;
bitset<MAX_PRIME+1> bs;
vector<uint> primes;
uint x;

void sieve() {
    bs.set();
    bs[0] = bs[1] = 0;
    for (uint i = 2; i <= MAX_PRIME; ++i) {
        if(bs[i]) {
            for (uint j = i*i; j <= MAX_PRIME; j += i)
                bs[j] = 0;
            primes.push_back(i);
            if (i >= x)
                return;
        }
    }
}

int main(){

    ios::sync_with_stdio(false);
    cin.tie(nullptr); cout.tie(nullptr);

    cin >> x;
    sieve();
    auto it = lower_bound(all(primes), x);
    cout << *it << '\n';


    return 0;
}

Measured memory_bytes: 384
#include<bits/stdc++.h>
using namespace std;
const int MAXN=100000+10;
int n,T,a[MAXN],mxa,mxv,ans;
int main()
{
	scanf("%d%d",&n,&T);
	for(int i=1;i<=n;++i)scanf("%d",&a[i]);
	for(int i=n;i>=1;--i)
	{
		if(mxa-a[i]>mxv)mxv=mxa-a[i],ans=1;
		else if(mxa-a[i]==mxv)ans++;
		mxa=max(mxa,a[i]);
	}
	printf("%d\n",ans);
	return 0;
}

Measured memory_bytes: 4156
#![allow(non_snake_case, unused)]
use std::cmp::*;
use std::collections::*;
use std::f64::consts::*;

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

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

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

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

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

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

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

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

    ($next:expr, bytes) => {
        read_value!($next, String).into_bytes()
    };

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

    ($next:expr, $t:ty) => {
        $next().parse::<$t>().expect("Parse error")
    };
}
fn func(mut n: u64, x: u64) -> u64 {
    let mut res = 0;
    while (n > 0) {
        res += n % x;
        n /= x;
    }
    res
}

fn main() {
    input! {
        mut n: u64,
    }
    let mut ans = n.clone();

    for i in 0..n + 1 {
        let mut acc = func(i, 6) + func(n - i, 9);
        ans = min(ans, acc);
    }
    println!("{}", ans);
}


Measured memory_bytes: 4352
#include <bits/stdc++.h>
#define ll long long
using namespace std;
void fen(int num)
{
	num=num%10;
}
int main( )
{
	ll n;
	cin>>n;
	n=n%10;
	if(n==2||n==4||n==5||n==7||n==9)
	{
		cout<<"hon";
		return 0;
	 } 
	 else if(n==3)
	 {
	 	cout<<"bon";
	 }
	 else
	 {
	 	cout<<"pon";
	 }
	 return 0;
 } 

Measured memory_bytes: 3628
import sys
input = sys.stdin.readline
n,y = map(int,input().split())
for i in range(y//10000+2):
    for j in range(y//5000+2):
        if 9000*i + 4000*j == y - 1000*n and n-i-j >= 0:
            print(i,j,n-i-j)
            break
    else:
        continue
    break
else:print(-1,-1,-1)


Measured memory_bytes: 40684
#include<iostream>
#include<vector>
#include<map>
#include<set>
#include<string>
#include<algorithm>
#include<numeric>
#include<cmath>
#include<unordered_map>
#include<unordered_set>

using namespace std;
typedef long long int ll;
#define rep(i,n) for(int i=0;i<(int)n;i++)
#define all(a) (a).begin(),(a).end()
#define allg(a) (a).begin(),(a).end(),greater<>()
#define SUM(a) accumulate((a).begin(),(a).end(),0)

int main(void) {
	ll n; cin >> n;
	unordered_map<ll, ll> m;
	for (ll i = 1;i <= n; i++) {
		ll t;
		cin >> t;
		m.emplace(t, i);
	}
	for (ll i = 1; i <= n; i++) {
		cout << m[i];
		if (i != n)cout << " ";
	}
	cout << endl;
	return 0;
}


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

int main(){
    string a,b,c;
    cin >> a >> b >> c;
    int la =a.size();
    int lb =b.size();
    if(a[la-1]==b[0]&&b[lb-1]==c[0])cout << "YES" << endl;
    else cout << "NO" << endl;
    return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
#include<stdlib.h>
#include<math.h>
#define rep(i,n) for(i=0;i<n;i++)
#define PI 3.14159265358979323846264338327950L
int main(){
    long long int x,year=0;
    long long int dep=100;
    scanf("%lld",&x);
    while(dep<x){
        dep=dep+dep/100;
        year++;
    }
    printf("%d",year);
    return 0;
}

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

bool isprime(int p){
	if(p==1) return false;
	for(int i=2;i<p;i++)
		if(p%i==0) return false;
	return true;
}

int main(){
	int n; cin >> n;
	for(int i=13;i<=55555;i+=10){
		if(isprime(i)){
			if(i!=13) cout << " ";
			cout << i;
			n--;
		}
		if(n==0) break;
	}
	cout << endl;
	return 0;
}


Measured memory_bytes: 256
#include <vector>
#include <iostream>
#include <string>
#include <algorithm>
#include <functional>

#define rep(i, n) for (int i = 0; i < (n); i++)
using namespace std;
typedef long long ll;
const int INF = 1e9;

int main(){

    int n;
    int i;
    vector<int> v(21);
    vector<int> c(21);

    cin >> n;
    rep(i, n){
        cin >> v[i];
    }
    rep(i, n){
        cin >> c[i];
    }

    int ans = 0;

    rep(i,n){
        if(v[i]-c[i] >=0){
            ans += v[i]-c[i];
        }
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
#define INF 1000000001
#define V 100000
#define N 100

long long int min(long long int a, long long int b);

long long int w[N+1];
long long int dp[N+1][V+1];

int main(void)
{
	int ret;
	int i;
	int j;
	int n;
	int v[N+1];
	long long int w_max;
	scanf("%d %lld", &n, &w_max);
	w[0]=0;
	v[0]=0;
	for(i=1;i<n+1;i++){
		scanf("%lld %d",&w[i] ,&v[i]);
	}
	for(i=0;i<n+1;i++){
		for(j=0;j<V+1;j++){
			dp[i][j]=INF;
		}
	}
	dp[0][0]=0;
	for(i=0;i<n;i++){
		for(j=0;j<V+1;j++){
			if(v[i+1]<=j){
				dp[i+1][j]=min(dp[i][j-v[i+1]]+w[i+1],dp[i][j]);
			}else{
				dp[i+1][j]=dp[i][j];
			}
		}
	}
	for(j=V;j>=0;j--){
		if(dp[n][j]<=w_max){
			printf("%d\n\n",j);
			ret = 0;
			break;
		}else{
			ret = 1;
		}
	}
	return ret;
}

long long int min(long long int a, long long int b){
	return (a>b)?b:a;
}


Measured memory_bytes: 79104
#include <iostream>
#include <vector>
#include <map>
#include <set>
#include <string>
#include <utility>
#include <algorithm>
#include <cstdio>
#include <iomanip>
#include <queue>
#include <deque>
#include <stack>
#include <fstream>
#include <cmath>
#include <random>
#include <complex>
#include <functional>

#define ll int64_t
#define Rep(i, n) for (ll i = 0; i < n; i++)
using namespace std;
typedef vector<ll> vec;
typedef vector<vec> mat;

const ll inf = 1LL << 60;

template<class T> inline void chmin(T& a, T b) {
    if (a > b) {
        a = b;
    }
}
template<class T> inline void chmax(T& a, T b) {
    if (a < b) {
        a = b;
    }
}

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

    ll N, M;
    cin >> N >> M;

    vector<pair<ll, char>> con(M);
    Rep (i, M) {
        ll s;
        char c;
        cin >> s >> c;
        s--;
        con[i] = {s, c};
    }

    Rep (i, 1e4) {
        string a = to_string(i);
        if (a.size() != N) continue;
        bool check = true;
        for (auto e : con) {
            ll s = e.first;
            char c = e.second;
            check = check && (a[s] == c);
        }
        if (check) {
            cout << a << "\n";
            return 0;
        }
    }

    cout << "-1\n";
}

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

int main() {
  int h, w, d;
  cin >> h >> w >> d;
  vector<vector<int>> v(d);
  map<int, pair<int, int>> mp;
  for(int i=0;i<h;i++) {
    for(int j=0;j<w;j++) {
      int a;
      cin >> a;
      v[a%d].emplace_back(a);
      mp[a] = make_pair(i, j);
    }
  }

  for(int i=0;i<d;i++) {
    sort(v[i].begin(), v[i].end());
  }

  vector<vector<int>> cost = v;
  for(int i=0;i<d;i++) {
    cost[i][0] = 0;
    for(int j=1;j<v[i].size();j++) {
      cost[i][j] = cost[i][j-1] + abs(mp[v[i][j]].first - mp[v[i][j-1]].first) + abs(mp[v[i][j]].second - mp[v[i][j-1]].second);
    }
  }

  int q;
  cin >> q;
  for(int i=0;i<q;i++) {
    int l, r;
    cin >> l >> r;
    int remainder = l % d;
    if(remainder == 0) cout << cost[remainder][r/d-1] - cost[remainder][l/d-1] << endl;
    else cout << cost[remainder][r/d] - cost[remainder][l/d] << endl;
  }

  return 0;
}

Measured memory_bytes: 15872
#include <iostream>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <algorithm>
#include <stack>
#include <queue>
#include <vector>
#include <map>
#include <set>
#include <unordered_set>
#include <unordered_map>
#define ll long long
#define fi first
#define se second
#define pb push_back
#define me memset
const int N = 1e6 + 10;
const int mod = 1e9 + 7;
const int INF = 0x3f3f3f3f;
using namespace std;
typedef pair<int,int> PII;
typedef pair<ll,ll> PLL;
 
int n;
int cnt;
int v[N];

int main() {
    ios::sync_with_stdio(false);cin.tie(0);
  	cin>>n;
  	for(int i=1;i<=105;++i){
  		for(int j=1;j<=105;++j){
  			for(int k=1;k<=105;++k){
  				cnt=i*i+j*j+k*k+i*j+i*k+j*k;
  				if(cnt<10050) v[cnt]++;
  			}
  		}
  	}
  	for(int i=1;i<=n;++i){
  		cout<<v[i]<<endl;
  	}

    return 0;
}

Measured memory_bytes: 3608
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		String x = sc.nextLine();
		
		for(int i = 0; i < x.length(); i++){
			if(i%2 == 0){
				System.out.print(x.charAt(i));
			}
		}
	}
}


Measured memory_bytes: 36984
#include<cstdio>
#include<iostream>
#include<cstring>
#define RG register
using namespace std;
const int N=101;
int n,m,flg,a[N],b[N],cnt;
inline int read(){
	char ch=getchar(); int x=0, f=1;
	while(ch<'0' || ch>'9') {if(ch=='-') f=-1;ch=getchar();}
	while(ch>='0' && ch<='9') {x=x*10+ch-'0'; ch=getchar();}
	return x*f;}
inline void swp(int &a,int &b){int t=a;a=b;b=t;}
int main()
{
	//freopen("Arrays and Palindrome.in","r",stdin);
	n=read(); m=read();
	for(RG int i=1;i<=m;i++)
	{
		a[i]=read();
		if(a[i]%2) flg++;
	}
	if(m==1)
	{
		if(n==1) printf("1\n1\n1\n");
		else printf("%d\n2\n%d 1\n",n,n-1);
		return 0;
	}
	if(flg>2) printf("Impossible\n");
	else
	{
		for(RG int i=2;i<=m;i++) if(a[i]%2) a[1]%2 ? swp(a[m],a[i]) : swp(a[1],a[i]);
		b[++cnt]=a[1]+1;
		for(RG int i=2;i<m;i++) b[++cnt]=a[i];
		if(a[m]>1) b[++cnt]=a[m]-1;
		for(RG int i=1;i<=m;i++) printf("%d ",a[i]); printf("\n");
		printf("%d\n",cnt);
		for(RG int i=1;i<=cnt;i++) printf("%d ",b[i]); printf("\n");
	}
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int MAXN = 2e6 + 5;
const int INF = 0x3f3f3f3f;
const ll p = 1e9 + 7;
#define DEBUG(x) cout << x << '\n'

int F[MAXN], Finv[MAXN], inv[MAXN];
void init(){
    F[0] = Finv[0] = inv[1] = 1;
    for(int i = 2; i < MAXN; i++)
        inv[i] = (p - p / i) * 1ll * inv[p % i] % p;
    for(int i = 1; i < MAXN; i++){
        F[i] = F[i-1] * 1ll * i % p;
        Finv[i] = Finv[i-1] * 1ll * inv[i] % p;
    }
}
int C(int n, int m){
    return F[n] * 1ll * Finv[n-m] % p * Finv[m] % p;
}
ll f_pow(ll a, ll b){
    ll res = 1;
    for(; b; b >>= 1, a = a * a % p)
        if(b & 1) res = res * a % p;
    return res;
}
void run(){
    int n, k; string s; cin >> k >> s; init();
    n = s.size(); int ans = 0;
    for(int i = n; i <= n + k; i++){
        ans += C(i - 1, n - 1) * f_pow(26, n + k - i) % p * f_pow(25, i - n) % p;
        ans %= p;
    }
    cout << ans;
}
int main(){
#ifdef Irene
    freopen("in.txt", "r", stdin);
#endif // Irene
    ios::sync_with_stdio(false);

    run();
}


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

int main() {
    // insert code here...
    long double angle,answer;
    int a,b,c,d;
    static const double pi =3.141592653589793238462643383279;
    std::cin>>a>>b>>c>>d;
    angle=std::abs(d*5.5-c*30);
  	answer=sqrt(a*a+b*b-2*a*b*cos(pi*angle/180.0l));
    std::cout<<std::fixed<<std::setprecision(12)<<answer<<std::endl;
    return 0;
}


Measured memory_bytes: 4192
#include<bits/stdc++.h>
using namespace std;
int main(){
  int n;
  cin >> n;
  int i,j,count=0;
  for(i=1;i<=9;i++){
    for(j=1;j<=9;j++){
      if(i*j==n){
        count++;
      }
    }
  }
  if(count>0){
    cout << "Yes" << endl;
  }else{
    cout << "No" << endl;
  }
}
        

Measured memory_bytes: 256
x, y = map(int, input().split())
if x in [1, 3, 5, 7, 8, 10, 12]:
    if y in [1, 3, 5, 7, 8, 10, 12]:
        print('Yes')
    else:
        print('No')
elif x in [4, 6, 9, 11]:
    if y in [4, 6, 9, 11]:
        print('Yes')
    else:
        print('No')
else:
    if y == 2:
        print('Yes')
    else:
        print('No')

Measured memory_bytes: 3064
#include <algorithm>
#include <iostream>
#include <cstring>
#include <cstdio>
#include <string>
#include <vector>
#include <queue>
#include <stack>
#include <cmath>

int n, k;
std::string s;

int main()
{
    std::ios::sync_with_stdio(0), std::cin.tie(0), std::cout.tie(0);
    std::cin >> n >> k >> s;
    s = ' ' + s;
    if (s[k] == 'A')
        s[k] = 'a';
    else if (s[k] == 'B')
        s[k] = 'b';
    else
        s[k] = 'c';
    std::cout << s.substr(1, s.size() - 1) << std::endl;
    return 0;
}

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

d1 = {}
for _ in range(N):
    S = input()
    if S in d1:
        d1[S] += 1
    else:
        d1[S] = 1

d2 = {}
for key in d1:
    value = d1[key]
    if value in d2:
        d2[value].append(key)
    else:
        d2[value] = [key]

key = sorted(d2.keys(), reverse=True)[0]
for s in sorted(d2[key]):
    print(s)


Measured memory_bytes: 32988
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
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; }
const ll INF = 1LL << 60;

int main() {
    string s, t; cin >> s >> t;
    sort(s.begin(), s.end());
    sort(t.begin(), t.end(), greater<int>());
    if (s < t) {
        cout << "Yes" << endl;
    } else {
        cout << "No" << endl;
    }
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define endl '\n'
using namespace std;
using ll = long long;
using ld = long double;

int dfs(int node, vector<vector<int>>& edges, vector<int>& dp, vector<bool>& visited){
    if (visited[node]){return dp[node];}
    visited[node] = true;
    for (int connected_nodes: edges[node]){
        dp[node] = max(dp[node], dfs(connected_nodes, edges, dp, visited) + 1);
    }
    return dp[node];
}

void solve(){
    int n, m;
    cin >> n >> m;
    vector<vector<int>> edges(n + 1);
    vector<int> dp(n + 1, 0);
    vector<bool> visited(n + 1, false);
    for(int i = 1; i < m + 1; i++){
        int x, y;
        cin >> x >> y;
        edges[x].emplace_back(y);
    }

    int ans = 0;
    for(int i = 1; i < n + 1; i++){
        ans = max(ans, dfs(i, edges, dp, visited));
    }
    cout << ans << endl;
    return;
}

int main() {
    ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
    solve();
    return 0;
}


Measured memory_bytes: 11712
import sys
sys.setrecursionlimit(10**8)
def ii(): return int(sys.stdin.readline())
def mi(): return map(int, sys.stdin.readline().split())
def li(): return list(map(int, sys.stdin.readline().split()))
def li2(N): return [list(map(int, sys.stdin.readline().split())) for _ in range(N)]
def dp2(ini, i, j): return [[ini]*i for _ in range(j)]
#import bisect #bisect.bisect_left(B, a)
#from collections import defaultdict #d = defaultdict(int) d[key] += value
#from collections import Counter # a = Counter(A).most_common()
#from itertools import accumulate #list(accumulate(A))

S = input()
at = 'AT'
gc = 'GC'

if len(at.replace(S, '')) == 1:
    print(at.replace(S, ''))
else:
    print(gc.replace(S, ''))

Measured memory_bytes: 8988
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<climits>
#include<iostream>
#include<algorithm>
#include<stack>
#include<queue>
#include<vector>
#include<list>
#include<map>
#include<set>
using namespace std;
#define REP(i,n) for(int i=0;i<(n);i++)
#define max_n 53
#define max_p 53
int n,p,stone;
int score[max_n];
bool input(){
  cin>>n>>p;
  return (n!=0);
}

void solve(){ 
  REP(i,max_n)score[i]=0;
  stone=p;
  int person =0;
  while(true){
    if(stone>0){
      stone--;
      score[person]+=1;
      if(score[person]==p)break;
  }else{
    stone=score[person];
    score[person]=0;
  }
  person++;
  person%=n;
  }
  cout<<person<<endl;
}

int main(){
  while(input()){
    solve();
  }
  return 0;
}

Measured memory_bytes: 2948
// package app;

import java.util.Arrays;
import java.util.Scanner;
import java.util.stream.Stream;

public class Main {

    public static void main(final String[] args) throws Exception {
        final Scanner sc = new Scanner(System.in);

        // final String S = sc.next();
        // final int M = sc.nextInt();
        final double a = sc.nextDouble();
        final double b = sc.nextDouble();

        long result = Math.round( (a + b) / 2.0 );

        // System.out.println();
        System.out.println(result);

        // System.out.println(A <= X && A + B >= X ? "YES" : "NO");

    }
}

Measured memory_bytes: 22996
#include <bits/stdc++.h>
using namespace std;
#define pi acos(-1)
#define IOS ios_base::sync_with_stdio(0); cin.tie(); cout.tie();
#define ff first
#define ss second
#define pb push_back
#define debug(val) cerr << "The value of " << #val << " is = " << val << '\n';
typedef long double ld;
typedef long long ll;
typedef unsigned long long ull;
const ll mod = 1e9 + 7;
const ll inf = 0x3f3f3f3f;
const ll mininf = -922337203685477;
const ll nax = 0;
ld w, h, x, y;

int main(){
	IOS
	cin >> w >> h >> x >> y;
	cout << setprecision(9) << fixed << w*h/2 << '\n';
	cout << ((x+x==w)&&(y+y==h)) << '\n';
}


Measured memory_bytes: 3800
#include <iostream>
#include <stdio.h>
#include <string.h>
#include <algorithm>

using namespace std;

int a[3];
int ans=0;

int main()
{
	for(int i=0;i<3;i++) scanf("%d",&a[i]);
	sort(a,a+3);
	if(a[1]!=a[2]) ans=a[2]-a[1],a[0]+=ans,a[1]=a[2];
	if(a[0]!=a[1]) ans+=((a[1]-a[0]+1)>>1)+((a[1]-a[0])&1);
	printf("%d\n",ans);
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define F first
#define S second
#define pb push_back
#define mp make_pair
#define full(a) a.begin(),a.end()
#define rfull(a) a.rbegin(),a.rend()

using namespace std;
const double pi=acos(-1.0);
const double pii=2*pi;
const double eps=1e-6;
const long long MOD=1e9+7;

void solve(){
    int n,q;
    cin>>n>>q;
    long long ans=1ll*(n-2)*(n-2);
    int l=1,r=n,u=1,d=n;
    map<int,int> up,lr;
    vector<pair<int,int>> quer(q,{0,0});
    for(int i=0;i<q;i++) cin>>quer[i].first>>quer[i].second;
    for(int i=0,x,y;i<q;i++){
        x=quer[i].first;
        y=quer[i].second;
        if(x==1){
            auto itr=lr.lower_bound(y);
            if(itr==lr.begin()){
                int curr=d-u-1;
                r=y;
                lr.insert({y,curr});
                ans-=curr;
            }
            else ans-=(--itr)->second;
        }
        else{
            auto itr=up.lower_bound(y);
            if(itr==up.begin()){
                int curr=r-l-1;
                d=y;
                up.insert({y,curr});
                ans-=curr;
            }
            else ans-=(--itr)->second;
        }
        // cout<<u<<" "<<d<<" "<<l<<" "<<r<<"\n";
    }
    cout<<ans<<"\n";
}

int main(){
    std::ios::sync_with_stdio(false);
    std::cin.tie(NULL);
    std::cout.tie(NULL);

    solve();
    return 0;
}

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

using namespace std;

typedef long long LL;
typedef pair<int , int> P2;
typedef pair<pair<int , int> , int> P3;
typedef pair<pair<int , int> , pair<int , int> > P4;
#define PB(a) push_back(a)
#define MP(a , b) make_pair((a) , (b))
#define M3P(a , b , c) make_pair(make_pair((a) , (b)) , (c))
#define M4P(a , b , c , d) make_pair(make_pair((a) , (b)) , make_pair((c) , (d)))
#define repp(i,a,b) for(int i = (int)(a) ; i < (int)(b) ; ++i)
#define repm(i,a,b) for(int i = (int)(a) ; i > (int)(b) ; --i)

const LL mod = 1e9 + 7;
const int MC = 1e5 + 5;

LL a[MC],c[MC],qa[MC],qc[MC];

int main(){
	string S; cin >> S;
	int n = S.size();
	a[0] = 0; qa[0] = 1;
	repp(i,0,n){
		if(S[i] == 'A'){
			a[i+1] = (a[i] + qa[i]) % mod;
			qa[i+1] = qa[i];
		} else if(S[i] == '?'){
			a[i+1] = (a[i] * 3 + qa[i]) % mod;
			qa[i+1] = qa[i] * 3 % mod;
		} else {
			a[i+1] = a[i];
			qa[i+1] = qa[i];
		}
	}
	c[n] = 0; qc[n] = 1;
	repm(i,n,0){
		if(S[i-1] == 'C'){
			c[i-1] = (c[i] + qc[i]) % mod;
			qc[i-1] = qc[i];
		} else if(S[i-1] == '?'){
			c[i-1] = (c[i] * 3 + qc[i]) % mod;
			qc[i-1] = qc[i] * 3 % mod;
		} else {
			c[i-1] = c[i];
			qc[i-1] = qc[i];
		}
	}
	LL ans = 0;
	repp(i,1,n-1){
		if(S[i] == 'A' || S[i] == 'C') continue;
		ans = (ans + a[i] * c[i+1]) % mod;
	}
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 3584
#include<iostream>
#include<vector>
#include<algorithm>

using namespace std;

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

    for(int i = 0; i < n; i++)
    {
        cin >> A.at(i);
    }
    sort(A.begin(), A.end());
    cout << abs(A.at(n-1) - A.at(0)) << endl;
    return 0;
}

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

#define rep(i,n) for(i = 0;i < n;++i)
#define all(v) v.begin(), v.end()
using ll = long long;

int main()
{
    ll i,j;
    ll a,b,c,d;
    cin >> a >> b >> c >> d;
    cout << max({a*c, a*d, b*c, b*d}) << endl;

    return 0;
}

Measured memory_bytes: 3624
#include<bits/stdc++.h>
using namespace std;
signed main(){
  int h,w;
  while(cin>>h>>w,h,w){
    
    for(int i=0;i<h;i++){
      for(int j=0;j<w;j++){
	cout<<'#';
	if(j==w-1){
	  cout<<'\n';
	}
      }
    }
    cout<<'\n';
  }
  return(0);
}



Measured memory_bytes: 3028
use proconio::input;
#[allow(unused_imports)]
use proconio::marker::{Bytes, Chars};
#[allow(unused_imports)]
use std::cmp::{min, max};

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

	let mut c0 = 0;
	let mut c1 = 0;
	let mut c2 = 0;
	let mut c3 = 0;
	for i in 0..n {
		match a[i][0] {
			'A' => c0 += 1,
			'W' => c1 += 1,
			'T' => c2 += 1,
			'R' => c3 += 1,
			_ => (),
		}
	}
	println!("AC x {}", c0);
	println!("WA x {}", c1);
	println!("TLE x {}", c2);
	println!("RE x {}", c3);
}



Measured memory_bytes: 7828
import math
import queue

def readInt():
	return int(input())

def readInts():
	return list(map(int, input().split()))

def readChars():
	return input().split()



x = readInts()
n = x[0]
k = x[1]

def ts(l):
	return int((l*(l-1))/2)

def ts2(l):
	return int(l*(n+n-(l-1))/2)


#for i in range(k,n):
#	for j in range(0,n-i+1):
#iは個数

#a = range(0+1,n+n-1 +1) #2
#b = range(0+1+2,n+n-1+n-2 +1) #3

s = 0

for i in range(k,n+2):
	#x = range(ts(i),ts2(i)+1)
	#print(ts2(i)+1-ts(i))
	#print(x)
	s += ts2(i)+1-ts(i)

print(s%(1000000007))

Measured memory_bytes: 9708
#include <bits/stdc++.h>
#pragma optimize("O3")
#define array vector<vector<int>>
#define thread sort
#define FOR(i,a,b) for (int i = (a); i < (b); i++)
#define RFOR(i,a,b) for (int i = (a - 1); i >= (b); i--)
#define all(a) (a).begin(), (a).end()
#define endl "\n"
#define ll long long
#define pb push_back
#define PII pair<int, int>
#define PLL pair<long long, long long>
#define vi vector<int>
#define vb vector<bool>
#define vc vector<char>
#define vll vector<long long>
#define mii map<int, int>
#define mll map<long long, long long>
#define MOD 1000000007
#define MAX 1000000007
#define MOD2 1234567891
#define MOD3 998244353
using namespace std;

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



int main() {
    int n;
    cin >> n;
    vi a(n + 1), b(n);
    ll res = 0;
    FOR (i, 0, n + 1) {
        cin >> a[i];
    }

    FOR (i, 0, n) {
        cin >> b[i];
    }

    FOR (i, 0, n) {
        if (b[i] > a[i]) {
            res += a[i];
            int g = res;
            if (a[i + 1] < (b[i] - a[i])) {
                res += a[i + 1];
                a[i + 1] = 0;


            } else {
                res += b[i] - a[i];
                a[i + 1] -= (b[i] - a[i]);
            }

        } else {
            res += (b[i]);
        }
    }

    cout << res;
    return 0;
}

Measured memory_bytes: 1024
#include <assert.h>
#include <ctype.h>
#include <errno.h>
#include <float.h>
#include <fstream>
#include <iomanip>
#include <iostream>
#include <set>
#include <queue>
#include <limits>
#include <deque>
#include <locale>
#include <math.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <time.h>
#include <wchar.h>
#include <wctype.h>
#include <algorithm>
#include <bitset>
#include <map>
#include <iomanip>
#include <ios>
#include <iostream>
#include <vector>
#include <cwchar>
#include <cwctype>
#define mp make_pair
#define fs first
#define se second
#define memset(a,t) memset(a,t,sizeof(a))
#define all(v) v.begin(),v.end()
#define eprintf(...) fprintf(stderr, __VA_ARGS__),fflush(stderr)
#define MN 0LL
#define Mx 200000005
#define Mn -Mx
#define MX 20000000000000005
using namespace std;
int readint(){
	char c;
	while(c=getchar(),(c<'0'||c>'9')&&c!='-');
	bool flag=(c=='-');
	if(flag)c=getchar();
	int x=0;
	while(c>='0'&&c<='9'){
		x=x*10+c-48;
		c=getchar();
	}
	return flag?-x:x;
}
inline string tos(int x){
	string s;
	while(x) s=(char)(x%10+'0')+s,x/=10;
	return s;
}
map<int,int> cnave[200005];
int a[200005],b[200005];
inline int finda(int t){
	if(a[t]==t) return a[t];
	int x=finda(a[t]);
	a[t]=x;
	return x;
}
inline int findb(int t){
	if(b[t]==t) return b[t];
	int x=findb(b[t]);
	b[t]=x;
	return x;
}
int main(){
	ios_base::sync_with_stdio(false);
	int n,p,q,i,j,x,y;
	cin>>n>>p>>q;
	for(i=0;i<n;i++) a[i]=b[i]=i;
	for(i=0;i<p;i++){
		cin>>x>>y;
		x--,y--;
		a[finda(x)]=finda(y);
	}
	for(i=0;i<q;i++){
		cin>>x>>y;
		x--,y--;
		b[findb(x)]=findb(y);
	}
	for(i=0;i<n;i++){
		finda(i);findb(i);
		cnave[a[i]][b[i]]++;
	}
	for(i=0;i<n;i++) cout<<cnave[a[i]][b[i]]<<" ";
	cout<<endl;
	return 0;
}


Measured memory_bytes: 20096
// Sky's the limit :)
#include <bits/stdc++.h>
using namespace std;
#define int long long

signed main() {
    ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    
    int t = 1; 
    // cin >> t; 
    while (t--) {
        double a, b, h, m;
        cin >> a >> b >> h >> m;

        double pi = 2 * acos(0.0);
        double ang = pi * 2 * (h / 12 + m / (12 * 60) - m / 60);
        double ans = a * a + b * b - 2 * a * b * cosl(ang);
        ans = sqrt(ans);

        cout << fixed << setprecision(10) << ans << '\n';


    }
    
    cerr << "Time elapsed: " << 1.0 * clock() / CLOCKS_PER_SEC << " sec \n";
    return 0;
}



Measured memory_bytes: 4108
// Author: HarshKumar

#include <bits/stdc++.h>
using namespace std;
#define ll int64_t
const ll N = 1e6 + 6, M = 1e9 + 7;
int main()
{
    ios::sync_with_stdio(false), cin.tie(nullptr);
    ll n;
    cin >> n;
    set<string> f;
    string s;
    while (n--)
        cin >> s, f.insert(s);
    cout << f.size();
}

Measured memory_bytes: 19184