akhauriyash/Code-Regression huggingface dataset:
from copy import deepcopy
from sys import exit,setrecursionlimit
import math
from collections import defaultdict,Counter,deque
from fractions import Fraction as frac

setrecursionlimit(1000000)


def main():
	n = int(input())
	s = [input() for _ in range(n)]
	a = defaultdict(int)
	for i in s:
		t = ''
		for j in sorted(i):
			t += j
		a[t] += 1
	ans = 0
	for v in a.values():
		ans += v * (v-1) // 2
	print(ans)

def zip(a):
	mae = a[0]
	ziparray = [mae]
	for i in range(1,len(a)):
		if(mae != a[i]):
			ziparray.append(a[i])
			mae = a[i]
	return ziparray

def is_prime(n):
	if n < 2: return False

	for k in range(2, int(math.sqrt(n)) + 1):
		if n % k == 0:
			return False

	return True

def list_replace(n,f,t):
	return [t if i==f else i for i in n]

def base_10_to_n(X, n):
	X_dumy = X
	out = ''
	while X_dumy>0:
		out = str(X_dumy%n)+out
		X_dumy = int(X_dumy/n)
	if(out == ''): return '0'
	return out

def gcd(l):
	x = l.pop()
	y = l.pop()
	while(x%y!=0):
		z = x%y
		x = y
		y = z
	l.append(min(x,y))
	return gcd(l) if len(l) > 1 else l[0]

class Queue():
	def __init__(self):
		self.q = deque([])
	def push(self,i):
		self.q.append(i)
	def pop(self):
		return self.q.popleft()
	def size(self):
		return len(self.q)
	def debug(self):
		return self.q

class Stack():
	def __init__(self):
		self.q = []
	def push(self,i):
		self.q.append(i)
	def pop(self):
		return self.q.pop()
	def size(self):
		return len(self.q)
	def debug(self):
		return self.q

class graph():
	def __init__(self):
		self.graph = defaultdict(list)
	def addnode(self,l):
		f,t = l[0],l[1]
		self.graph[f].append(t)
		self.graph[t].append(f)
	def rmnode(self,l):
		f,t = l[0],l[1]
		self.graph[f].remove(t)
		self.graph[t].remove(f)
	def linked(self,f):
		return self.graph[f]

class dgraph():
	def __init__(self):
		self.graph = defaultdict(set)
	def addnode(self,l):
		f,t = l[0],l[1]
		self.graph[f].append(t)
	def rmnode(self,l):
		f,t = l[0],l[1]
		self.graph[f].remove(t)
	def linked(self,f):
		return self.graph[f]

main()


Measured memory_bytes: 99668
a0 = gets.chop.split.map(&:to_i).take(3)
a1 = gets.chop.split.map(&:to_i).take(3)
a2 = gets.chop.split.map(&:to_i).take(3)

if a0[0] - a0[1] == a1[0] - a1[1] && a2[0] - a2[1] == a0[0] - a0[1] &&
  a0[1] - a0[2] == a1[1] - a1[2] && a2[1] - a2[2] == a0[1] - a0[2] &&
  a0[2] - a0[0] == a1[2] - a1[0] && a2[2] - a2[0] == a0[2] - a0[0] &&
  a0[0] - a1[0] == a0[1] - a1[1] && a0[2] - a1[2] == a0[0] - a1[0] &&
  a1[0] - a2[0] == a1[1] - a2[1] && a1[2] - a2[2] == a1[0] - a2[0] &&
  a2[0] - a0[0] == a2[1] - a0[1] && a2[2] - a0[2] == a2[0] - a0[0]
  puts "Yes"
else
  puts "No"
end

Measured memory_bytes: 1788
//omajinai c++
#include <iostream>
#include<cmath>
#include<vector>
#include <algorithm>
#include <limits>
#include <numeric>
#include <type_traits>
#include <map>
#include <string>
#include <iomanip>
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(),(x).end()
#define itn int
using ll = long long;
constexpr auto mod = 1000000007;
using namespace std;
int main() {
string s;
  cin>>s;
  if(s.find("AB")==-1&&s.find("BA")==-1){
    cout<<"No";
  }
  else{
    cout<<"Yes";
  }
}


Measured memory_bytes: 256
#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;
const double PI = 3.14159265358979;
const vector<int> dx = {1, 0};
const vector<int> dy = {0, 1};

ll N;

ll g (ll X) {
  ll Y = N/X;
  return Y*(Y+1)*X/2;
}

int main() {
  cin >> N;
  ll res = 0;
  for (int j=1; j<=N; j++) res += g(j);
  cout << res << endl;
  return 0;
}

Measured memory_bytes: 3608
#include<iostream>
#include<vector>
#include<algorithm>
#include<cstdio>
#include<cstdlib>
#include<string>
#include<sstream>
#include<cmath>
#include<numeric>
#include<map>
#include<stack>
#include<queue>
#include<list>
#include<set>
#include<cstring>
using namespace std;
long long int mod = 1e9 + 7;
int main() {
  int n, a, b; cin >> n >> a >> b;

  cout << min(a, b) << " " << max(a+b-n, 0) << endl;

  return 0;
}



//EOF


Measured memory_bytes: 256
import copy

n, k = list(map(int, input().split()))
x_list = list(map(int, input().split()))

t_list = []

if 0 in x_list:
    zero_ind = x_list.index(0)

    for start_ind in range(max(0, zero_ind - k), min(zero_ind + 1, n - k + 1)):
        # print(start_ind)
        minv = x_list[start_ind]
        maxv = x_list[start_ind + k - 1]
        # print(minv, maxv)

        if minv < 0 < maxv:
            t = min(2 * abs(minv) + maxv, abs(minv) + 2 * maxv)

        else:
            t = max(abs(minv), abs(maxv))

        t_list.append(t)
        # print("t={}".format(t))

else:
    x_list2 = copy.copy(x_list)
    x_list2 = x_list2 + [0]
    x_list2 = sorted(x_list2)
    zero_ind = x_list2.index(0)

    for start_ind in range(max(0, zero_ind - k), min(zero_ind + 1, n - k + 1)):
        # print(start_ind)
        minv = x_list[start_ind]
        maxv = x_list[start_ind + k - 1]
        # print(minv, maxv)

        if minv < 0 < maxv:
            t = min(2*abs(minv) + maxv, abs(minv) + 2 * maxv)

        else:
            t = max(abs(minv), abs(maxv))

        t_list.append(t)


print(min(t_list))


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


int main(){
    string A,B;
    cin >> A >> B;
    if(A.size()>B.size()){
        cout << "GREATER" << endl;
        return 0;
    }
    if(A.size()<B.size()){
        cout << "LESS" << endl;
        return 0;
    }
    if(A==B){
        cout << "EQUAL" << endl;
        return 0;
    }
    REP(i,A.size()){
        if(A[i]>B[i]){
            cout << "GREATER" << endl;
            return 0;
        }
        if(A[i]<B[i]){
            cout << "LESS" << endl;
            return 0;
        }
    }
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <algorithm>
#include <set>
#include <map>
#include <numeric>
#include <climits>
#include <math.h>
#include <memory.h>
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define rrep(i, k, n) for(int i = (k); i < (int)(n); i++)
using namespace std;
using ll = long long;
int N, M;
int cnt = 0;
int ans = 0;
int i_index;
int tmp;
int main(){
    int H, W;
    cin >> H >> W;
    string s[H];
    rep(i, H) cin >> s[i];
    rep(i, W + 2) cout << '#';
    cout << endl;
    rep(i, H) cout << '#' << s[i] << '#' << endl;
    rep(i, W + 2) cout << '#';
    cout << endl;
    return 0;
}

Measured memory_bytes: 256
//><

#include<bits/stdc++.h>
using namespace std;
using ll = long long;
#define int long long
#define rep(i,x,y) for(ll i=x;i<y;i++)
#define irep(i,a) for(auto i = a.begin(); i != a.end(); ++i)
#define nvarep(n,a) ll n;cin>>n;vector<ll>a(n);rep(i,0,n)cin>>a[i]
#define vecrep(n,a,type) vector<type>a(n);rep(i,0,n)cin>>a[i]
#define gcd(a,b) __gcd(a,b)
#define lcm(a,b) (a/__gcd(a, b)*b)
#define range(a) (a).begin(),(a).end() 
#define pb push_back
#define mp make_pair
#define nnn "\n"
#define spa " "
#define cout15(a) printf("%.15f\n",a)
template<class T>inline bool chmin(T& a,T b,bool f){
if(f==1){if(a>b){a=b;return true;}return false;}
else if(f==0){if(a<b){a=b;return true;}return false;}return false;}
typedef pair<ll,string> p;
using g = vector<vector<ll>>;
const int inf = 2147483647;//2*10^9
const ll INF = 9223372036854775807;//9*10^18

signed main (){
    string s;cin>>s;
    ll ans = 0;
    if(s[0]=='>'){
        ll c = 0;
        for(int i=0;s[i]=='>';i++){
            c++;
            ans+=c;
        }
        s.erase(0,c);
    }
    if(s[s.size()-1]=='<'){
        ll c = 0;
        for(int i=s.size()-1;s[i]=='<';i--){
            c++;
            ans+=c;
        }
        s.erase(s.size()-c,c);
    }
    s.pb('<');
    while(s.size()!=1){
        bool flag = true;
        int dai=0,sho=0;
        for(int i=0;flag||s[i]!='<';i++){
            if(s[i]=='>'){
                flag=false;
                dai++;
            }else{
                sho++;
            }
        }
        s.erase(0,dai+sho);
        if(dai>sho)sho--;
        else dai--;
        rep(i,1,dai+1)ans+=i;
        rep(i,1,sho+1)ans+=i;
    }
    cout<<ans<<nnn;
    return 0;
}

Measured memory_bytes: 900
//abc153 a
#include <stdio.h>
int main(int argc, char const *argv[]) {
    int H,A;
    int x,y;
    scanf("%d %d",&H,&A );
    x = H/A;
    y = H%A;
    if(y!=0){
        x = x+1;
    }
    printf("%d\n",x );
    return 0;
}


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

int main(){
	ios::sync_with_stdio(0);
	cin.tie(0), cout.tie(0);
	
	int a,b, ans;
	cin>>a>>ans;
	
	ans = (ans<<1)-a;
	cout<<ans<<endl;
	
	return 0;
}

Measured memory_bytes: 256
#pragma GCC optimize("Ofast")
#define _USE_MATH_DEFINES
#include "bits/stdc++.h"

using namespace std;

using u8 = uint8_t;
using u16 = uint16_t;
using u32 = uint32_t;
using u64 = uint64_t;
using i8 = int8_t;
using i16 = int16_t;
using i32 = int32_t;
using i64 = int64_t;

constexpr char newl = '\n';
constexpr double eps = 1e-10;

#define FOR(i,a,b) for (int i = (a); i < (b); i++)
#define F0R(i,b) FOR(i,0,b)
#define RFO(i,a,b) for (int i = ((b)-1); i >=(a); i--)
#define RF0(i,b) RFO(i,0,b)
#define fi first
#define se second
#define debug(x) cout << #x << ": " << x << '\n';
#define rng(a) a.begin(),a.end()
#define rrng(a) a.rbegin(),a.rend()

template<typename T1, typename T2> inline void chmin(T1& a, T2 b) { if (a > b) a = b; }
template<typename T1, typename T2> inline void chmax(T1& a, T2 b) { if (a < b) a = b; }
template<class T> void Print(vector<T> v) {
  F0R(i, v.size()) {
    cout << v[i] << ' ';
  }
  cout << newl;
}

#if 1


// INSERT ABOVE HERE
signed main() {
  cin.tie(0);
  ios_base::sync_with_stdio(false);

  int N, L;
  cin >> N >> L;

  int l = L, r = L + N - 1;
  int sum = (l+r) * N / 2;
  if (l > 0) {
    sum -= l;
  }
  else if (r < 0) {
    sum -= r;
  }

  cout << sum;
}
#endif


Measured memory_bytes: 3648
import std.algorithm, std.container, std.conv, std.math, std.range, std.typecons, std.stdio, std.string;
import std.uni;

auto rdsp(){return readln.splitter;}
void pick(R,T)(ref R r,ref T t){t=r.front.to!T;r.popFront;}
void readV(T...)(ref T t){auto r=rdsp;foreach(ref v;t)pick(r,v);}

void main()
{
  string s1, s2, s3; readV(s1, s2, s3);
  writeln(s1[0].toUpper, s2[0].toUpper, s3[0].toUpper);
}


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

// varibable settings
#define int long long
const int INF=1e18;

// define basic macro {{{
#define _overload3(_1,_2,_3,name,...) name
#define _rep(i,n) repi(i,0,n)
#define repi(i,a,b) for(int i=(int)(a);i<(int)(b);++i)
#define rep(...) _overload3(__VA_ARGS__,repi,_rep,)(__VA_ARGS__)
#define _rrep(i,n) rrepi(i,0,n)
#define rrepi(i,a,b) for(int i=(int)((b)-1);i>=(int)(a);--i)
#define rrep(...) _overload3(__VA_ARGS__,rrepi,_rrep,)(__VA_ARGS__)
#define each(i,a) for (auto&& i : a)
#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(),(x).rend()
#define sz(x) ((int)(x).size())
#define pb(a) push_back(a)
#define mp(a, b) make_pair(a, b)
#define mt(a, b, c) make_tuple(a, b, c)
#define ub upper_bound
#define lb lower_bound
#define posl(A, x) (lower_bound(all(A), x)-A.begin())
#define posu(A, x) (upper_bound(all(A),x)-A.begin())
template<class T> inline void chmax(T &a, const T &b) { if((a) < (b)) (a) = (b); }
template<class T> inline void chmin(T &a, const T &b) { if((a) > (b)) (a) = (b); }

#define divceil(a,b) ((a)+(b)-1)/(b)
#define is_in(x, a, b) ((a)<=(x) && (x)<(b))
#define uni(x) sort(all(x));x.erase(unique(all(x)),x.end())
#define slice(l, r) substr(l, r-l)

typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef long double ld;
typedef pair<int,int> pii;
typedef tuple<int,int,int> iii;

template<typename T> using PQ = priority_queue<T, vector<T>, greater<T>>;
struct Fast { Fast(){ std::cin.tie(0); ios::sync_with_stdio(false); } } fast;

#if defined(PCM) || defined(LOCAL)
#else
    #define dump(...) 42
    #define dump_1d(...) 42
    #define dump_2d(...) 42
    #define cerrendl 42
#endif
//}}}

signed main() {
    double r;cin>>r;
    double ans = r * M_PI * 2;
    printf("%.12f", ans);
    return 0;
}


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

using namespace std;

#define fi first
#define se second
#define pb push_back

const int N = 302, M = 998244353;
int a[N];
int dp1[N][N*N], dp2[N][N*N];

int power(int x, int y) {
	if (y == 0) {
		return 1;
	}
	int temp = power(x, y >> 1);
	temp = ((long long)temp * temp) % M;
	if (y & 1) {
		temp = ((long long)temp * x) % M;
	}
	return temp;
}

int main() {
	int n, sum = 0;
	scanf("%d", &n);
	for (int i = 1; i <= n; i++) {
		scanf("%d", &a[i]);
		sum += a[i];
	}
	dp1[0][0] = 1;
	dp2[0][0] = 1;
	for (int i = 1; i <= n; i++) {
		for (int j = 0; j <= sum; j++) {
			dp1[i][j] = (dp1[i-1][j] * 2) % M;
			dp2[i][j] = dp2[i-1][j];
			if (j >= a[i]) {
				dp1[i][j] += dp1[i-1][j-a[i]];
				dp1[i][j] %= M;
				dp2[i][j] += dp2[i-1][j-a[i]];
				dp2[i][j] %= M;
			}
		}
	}
	int temp = 0;
	for (int i = (sum + 1)/2; i <= sum; i++) { // (sum + 2 - 1) / 2;
		temp += dp1[n][i];
		temp %= M;
	}
	if (sum % 2 == 0) {
		temp -= dp2[n][sum/2];
		temp += M;
		temp %= M;
	}
	temp = ((long long)temp * 3) % M;
	printf("%d", (power(3, n) - temp + M) % M);
	return 0;
}


Measured memory_bytes: 214912
#include <bits/stdc++.h>
#define rep(i, a, n) for(int i = a; i < n; i++)
#define REP(i, n) rep(i, 0, n)
#define repb(i, a, b) for(int i = a; i >= b; i--)
#define all(a) a.begin(), a.end()
#define int long long
#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)
using namespace std;
typedef pair<int, int> P;
const int mod = 1000000007;
const int INF = 1e12;

struct edge{
   int to, cost;
   edge(int to, int cost):to(to), cost(cost){}
};
vector<edge> G[100010];
int d[100010], d2[100010]; 
int n, m, s, t;
int tim, ans;
int dp[100010];
int dp2[100010];
int u[200010], v[200010], c[200010];

void dijkstra(int s){
    fill(d, d + 100010, INF);//V, INF
    d[s] = 0;
    priority_queue<P, vector<P>, greater<P> > q;
    q.push(P(d[s], s));
    dp[s] = 1;
    while(!q.empty()){
        P p = q.top(); q.pop();
        int from = p.second;
        int cost = p.first;
        if(d[from] < cost) continue;
        rep(i, 0, G[from].size()){
            edge e = G[from][i];
            int next = e.to;
            int newCost = e.cost + cost;
            if(d[next] > newCost){
                dp[next] = dp[from];
                d[next] = newCost;
                q.push(P(newCost, next));
            }else if(d[next] == newCost){
                (dp[next] += dp[from]) %= mod;
            }
        }
    }
}

void dijkstra2(int s){
    fill(d2, d2 + 100010, INF);//V, INF
    d2[s] = 0;
    priority_queue<P, vector<P>, greater<P> > q;
    q.push(P(d2[s], s));
    dp2[s] = 1;
    while(!q.empty()){
        P p = q.top(); q.pop();
        int from = p.second;
        int cost = p.first;
        if(d2[from] < cost) continue;
        rep(i, 0, G[from].size()){
            edge e = G[from][i];
            int next = e.to;
            int newCost = e.cost + cost;
            if(d2[next] > newCost){
                dp2[next] = dp2[from];
                d2[next] = newCost;
                q.push(P(newCost, next));
            }else if(d2[next] == newCost){
                (dp2[next] += dp2[from]) %= mod;
            }
        }
    }
}

signed main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    cin >> n >> m >> s >> t;
    s--; t--;
    rep(i, 0, m){
        cin >> u[i] >> v[i] >> c[i];
        u[i]--; v[i]--;
        G[u[i]].push_back(edge{v[i], c[i]});
        G[v[i]].push_back(edge{u[i], c[i]});
    }
    dijkstra(s);
    tim = d[t];    
    dijkstra2(t);
    ans = dp[t] * dp[t] % mod;
    rep(i, 0, n){
        if(d[i] * 2 == tim){
            // cout << " " << i << " " << d[i] << " " << dp[i] << " " << dp2[i] << endl;
            ans = (ans - dp[i] * dp[i] % mod * dp2[i] % mod * dp2[i] % mod + mod) % mod;
        }
    }
    rep(i, 0, m){
        if(d[u[i]] > d[v[i]]) swap(u[i], v[i]);
        if(d[u[i]] * 2 < tim && d[v[i]] * 2 > tim && d[u[i]] + c[i] == d[v[i]] && d[u[i]] + c[i] + d2[v[i]] == tim){
            // cout << u[i] << ' ' << v[i] << " " << d[u[i]] <<" " << d[v[i]] << endl;
            ans = (ans - dp[u[i]] * dp[u[i]] % mod * dp2[v[i]] % mod * dp2[v[i]] % mod + mod) % mod;
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 23508
#include<bits/stdc++.h>
#include <iostream>
#include <string>
#include <cmath>
using namespace std;
#define ll long long
#define rep(i, n) for (ll i = 0; i < (n); i++)
#define FOR(i,a,b) for(ll i=(a);i<(b);i++)
#define FORR(i,a,b)for(ll i=(a);i<=(b);i++)
#define repR(i,n) for(ll i=n;i>=0;i--)
#define all(v)(v).begin(),(v).end()
#define rall(v)(v).rbegin(),(v).rend()
#define F first
#define S second
#define pb push_back
#define pu push
#define COUT(x) cout<<(x)<<endl
#define PQ priority_queue<ll>
#define PQR priority_queue<ll,vector<ll>,greater<ll>>
#define YES(n) cout << ((n) ? "YES" : "NO"  ) << endl
#define Yes(n) cout << ((n) ? "Yes" : "No"  ) << endl
#define mp make_pair
#define maxs(x,y) (x = max(x,y))
#define mins(x,y) (x = min(x,y))
#define sz(x) (int)(x).size()
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
const ll MOD = 1000000007LL;
const ll INF = 1LL << 60;
using vll = vector<ll>;
using vb = vector<bool>;
using vvb = vector<vb>;
using vvll = vector<vll>;
using vstr = vector<string>;
using pll = pair<ll, ll>;
using vc = vector<char>;
using vvc = vector<vc>;
ll dx[4]={0,1,0,-1};
ll dy[4]={1,0,-1,0};
template<typename T>
struct UnionFind
{
	vector<T> par;
	vector<T> rank;
	UnionFind(T n):par(n),rank(n,0){
	   for(T i=0;i<n;i++){
	     par[i]=i;
	   }
	}
	T root(T x){
	  return par[x]==x?x:par[x]=root(par[x]);
	}

	bool unite(T x,T y){
	  if(x==y) return false;
	  x=root(x); y=root(y);
	  if(x==y) return false;
	  if(rank[x]<rank[y]) swap(x,y);
	  if(rank[x]==rank[y]) rank[x]++;
	  par[y]=x;
	  return true;
	}
	bool same(T x,T y){
	  return root(x)==root(y);
	}
};
int main(){
  ll n,m;
  cin>>n>>m;
  vll a(m),b(m);
  rep(i,m) cin>>a[i]>>b[i];
  ll cu=0;
  rep(i,m){
    UnionFind<ll> uf(n+1);
    rep(j,m){
      if(i==j) continue;
      uf.unite(a[j],b[j]);
    }
    set<ll> ans;
    for(int i=1;i<=n;i++){
      ans.insert(uf.root(i));
    }
    if(sz(ans)>1) cu++;
  }
  COUT(cu);
}
      


Measured memory_bytes: 256
//***********************
    //*** writer : Alan Hu **
    //***********************
    #include<iostream>
    #include<vector>
    #include<string>
    #include<set>
    #include<map>
    #include<algorithm>
    #include<queue>
    #include<list>
    #include<stack>
    #include<cstdio>
    #include<fstream>
    #include<numeric>
    #include<functional>
    #include<utility>
    #include<memory>
    #include<cstring>
    #include<cmath>
    using namespace std;
     
    #define CLEAN(a,b) memset(a,b,sizeof(a))
    #define mp make_pair
    #define pb push_back
    #define rept(i,a,b) for(int i=(int)(a);i<(int)(b);i++)
     
    typedef long long ll;
    typedef pair<int, int> pii;
     
    int main()
    {
    	int n,k;
    	cin>>n>>k;
    	rept(i,0,n) 
    	{
    		int x;
    		cin>>x;
    	}
    	cout<<(n+k-3)/(k-1)<<endl;
    	return 0;
    }

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

using namespace std;
using ll = long long;

const int N = 200005;

int n, q;
struct ds {
	int val[N];
	int lo, ptr;
};

ds ver, hor;

int main() {
	scanf("%d %d", &n, &q);

	ver.ptr = hor.ptr = n;
	ver.lo = hor.lo = n;

	ll ans = 1LL * (n - 2) * (n - 2);

	for(int i = 1; i <= q; i++) {
		int a, b;
		scanf("%d %d", &a, &b);
		if(a == 1) {
			ans -= (ver.val[b] ?: hor.lo) - 2;
			while(ver.ptr > b) {
				ver.val[ver.ptr--] = hor.lo;
			}
			ver.lo = min(ver.lo, b);
		}
		else {
			ans -= (hor.val[b] ?: ver.lo) - 2;
			while(hor.ptr > b) {
				hor.val[hor.ptr--] = ver.lo;
			}
			hor.lo = min(hor.lo, b);
		}
	}

	printf("%lld\n", ans);
}


Measured memory_bytes: 5244
//https://github.com/mostafa-saad/MyCompetitiveProgramming/blob/master/UVA/UVA_10740.txt
#include<queue>
#include<map>
#include <string>
#include<bits/stdc++.h>
#define pi 3.141592654
#define forr(i,a,b) for(int i=a;i<=b;i++)
#define F first
#define S second
#define input ios_base::sync_with_stdio(0);cin.tie(0);
//#define x real()
//#define y imag()
using namespace std;
typedef pair<double,double>pdd;
typedef long long  ll;
typedef pair<ll, ll>pii;
//typedef complex<double> point;
//template<typename T>T gcd(T x, T y) { if(y == 0)return x; else return gcd(y, x%y); }
//typedef bitset<30> mask;
//int x[8]={1,0,0,-1,-1,-1,1,1};
//int y[8]={0,1,-1,0,-1,1,-1,1};
//#define var(x) ((x)<<1)
//#define nvar(x) ((x)^1)
int m,k;
 main()
{

//cout<<Pow((ll)1000000,(ll)110);
//freopen("input.txt","r",stdin);
//freopen("output.txt","w",stdout);
//    char input[15];
//    scanf("%s", &input);  array of char
//  gets(c+1);  array of char
//printf("%s, ",name[k[i]].c_str());  printf of string
input;
cin>>m>>k;

int g=(1<<m)-1;

if(k>g)cout<<"-1";
else
{
    int e=0;
    forr(i,0,g)
    {
        if(i==k)continue;
        e^=i;
    }
    if(k==0)
    {
        forr(i,0,g)cout<<i<<" "<<i<<" ";
        return 0;
    }

    if(e!=k)
    {
        cout<<"-1";
        return 0;
    }
    forr(i,0,g)
    {
        if(i==k)continue;
        cout<<i<<" ";
    }
    cout<<k<<" ";
    for(int i=g;i>=0;i--)
    {
        if(i==k)continue;
        cout<<i<<" ";
    }
    cout<<k;
}
return 0;
}


Measured memory_bytes: 1792
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define FOR(i, s, e) for (int i = (int)(s); i <= (int)(e); i++)
#define printYesNo(is_ok) puts(is_ok ? "Yes" : "No");
#define SORT(v) sort(v.begin(), v.end());
#define RSORT(v) sort(v.rbegin(), v.rend());
#define REVERSE(v) reverse(v.begin(), v.end());

template <typename T>
void printlnVector(T v)
{
  rep(i, v.size())
  {
    cout << v[i] << endl;
  }
}

template <typename T>
void printVector(T v)
{
  rep(i, v.size())
  {
    cout << v[i] << " ";
  }
  cout << endl;
}

int main()
{
  string s;
  int K;
  cin >> s >> K;
  rep(i, s.size())
  {
    if (s[i] == 'a')
      continue;
    if ('z' - s[i] + 1 <= K)
    {
      K -= 'z' - s[i] + 1;
      s[i] = 'a';
    }
  }
  K %= 26;
  REVERSE(s);
  rep(i, s.size())
  {
    while (s[i] != 'z' && K != 0)
    {
      s[i]++;
      K--;
    }
  }
  REVERSE(s);
  cout << s << endl;
  return 0;
}


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


int main(){
    int c,a,b;
    cin >> c>>a>>b;
    cout <<a*c/2 << endl;
    return 0;
}


Measured memory_bytes: 256
n,m = map(int,input().split())
 
x = []
y = []
 
for _ in range(n):
    a,b = map(int,input().split())
    x.append((a,b))

for _ in range(m):
    c,d = map(int,input().split())
    y.append((c,d))

for i in range(n):
    ans = []
    for j in range(m):
        ans.append(abs(x[i][0]-y[j][0]) + abs(x[i][1]-y[j][1]))
    ind = ans.index(min(ans))
    print(ind + 1)

Measured memory_bytes: 3064
h,w=map(int,input().split())
m=[]
for _ in range(h): m.append(list(input()))
black=0
white=0
for i in range(h):
    for j in range(w):
        if m[i][j]=="#": black+=1
white=h*w-black
node=[[0,0,1]]
dx,dy=[-1,0,1,0],[0,1,0,-1]
while node:
    temp=node.pop(0)
    if temp[0]==h-1 and temp[1]==w-1:
        print(h*w-black-temp[2])
        exit()
    m[temp[0]][temp[1]]="#"
    for i in range(4):
        if 0<=temp[0]+dx[i]<h and 0<=temp[1]+dy[i]<w:
            if m[temp[0]+dx[i]][temp[1]+dy[i]]==".":
                node.append([temp[0]+dx[i],temp[1]+dy[i],temp[2]+1])
                m[temp[0]+dx[i]][temp[1]+dy[i]]="#"
print(-1)           

Measured memory_bytes: 9232
#include <iostream>
#include <sstream>
#include <algorithm>
#include <vector>
#include <string>

using namespace std;

int main(void) {
  int N;
  cin >> N;

  int a[N], b[N];

  for(int i=0; i<N; i++) {
    cin >> a[i];
  }
  for(int i=0; i<N; i++) {
    cin >> b[i];
  }

  vector<int> small;
  long long small_sum = 0;
  vector<int> remain;
  for(int i=0; i<N; i++) {
    if(a[i] < b[i]) {
      small.push_back(b[i] - a[i]);
      small_sum += b[i] - a[i];
    } else if (a[i] > b[i]) {
      remain.push_back(a[i] - b[i]);
    }
  }

  int ans = small.size();
  sort(remain.begin(), remain.end(), greater<int>());
  for (int i=0; i<remain.size(); i++) {
    if (small_sum <= 0) {
      break;
    }
    small_sum -= remain[i];
    ans++;
  }

  if (small_sum > 0) {
    ans = -1;
  }

  cout << ans << endl;

  return 0;

}


Measured memory_bytes: 1660
#include <cstdio>

using namespace std;

int main()
{
	int time;
	
	scanf("%d", &time);
	
	printf("%d:", time / 3600);
	time %= 3600;
	printf("%d:", time / 60);
	time %= 60;
	printf("%d\n", time);
	
	return (0);
}

Measured memory_bytes: 1020
#include <iostream>
#include <algorithm>
#include <cstring>
using namespace std;
int w,h;
char tbl[30][30];
int dx[] = {0,0,1,-1};
int dy[] = {1,-1,0,0};
bool visited[30][30];
int ans;

void dfs(int x,int y){
  visited[y][x] = 1;
  ++ans;
  for(int i=0;i<4;++i){
    int mx = x+dx[i];
    int my = y+dy[i];
    if(mx>=w || my>=h || mx<0 || my<0) continue;
    if(visited[my][mx] || tbl[my][mx]=='#') continue;
    dfs(mx,my);
  }
}

int main(){
  while(cin>>w>>h,w||h){
    memset(visited,0,sizeof(visited));
    ans = 0;
    for(int i=0;i<h;++i) cin >> tbl[i];
    int sx=-1,sy=-1;
    for(int i=0;i<h;++i)
      for(int j=0;j<w;++j)
	if(tbl[i][j]=='@')
	  sy=i,sx=j;

    dfs(sx,sy);
    cout << ans << endl;
}
  return 0;
}

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

int main() {
  int N;
  string S;
  cin >> N >> S;
  
  for (int i = 0; i < S.size(); i++) {
    char c = (S[i] - 'A' + N) % 26 + 'A'; 
    cout << c;
  }
  cout << endl;
  
  return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
#define Rep(i,a,n)for(int i=(int)(a);i<(int)(n);i++)
#define rep(i,n)Rep(i,0,n)
#define N 200010

int main() {
	int n, a[N], b[N] = { 0 }, c[N] = { 0 }; long long k;
	scanf("%d %lld", &n, &k);
	Rep(i, 1, n + 1)scanf("%d", &a[i]);
	int ch = 1, start, end;
	Rep(i, 1, N+10) {
		if (b[ch]!=0){ start = b[ch]; end = i; break; }
		b[ch] += i;
		ch = a[ch];
    }
	c[0]=ch;
	Rep(i,1,end-start+1) {
		c[i] = a[ch];
		ch = a[ch];
	}
	if (k<=start) {
		ch=1;int K = k;
		rep(i,K) {
			ch = a[ch];
		}
		printf("%d",ch);
	}
	else if(end-start==1)printf("%d", ch);
	else{
		k++;
		k = k-start;
		k = k%(end-start);
		printf("%d",c[k]);
	}
}

Measured memory_bytes: 4048
// tsukasa_diary's programing contest code template
#include <bits/stdc++.h>
using namespace std;
#define TSUKASA_DIARY_S_TEMPLATE
// define
#define for_(i,a,b) for(int i=(a);i<(b);++i)
#define for_rev(i,a,b) for(int i=(a);i>=(b);--i)
#define allof(a) (a).begin(),(a).end()
#define minit(a,b) memset(a,b,sizeof(a))
#define size_of(a) int((a).size())
#define cauto const auto
// typedef
typedef long long lint;
typedef double Double;
typedef pair< int, int > pii;
template< typename T > using Vec = vector< T >;
template< typename T > using Matrix = Vec< Vec< T > >;
template< typename T > using USet = unordered_set< T >;
template< typename T, class C > using MyUSet = unordered_set< T, C >;
template< typename T, typename F > using UMap = unordered_map< T, F >;
template< typename T, typename F, class C > using MyUMap = unordered_map< T, F, C >;
// hash
class PiiHash { public: size_t operator () (const pii& p) const { return (p.first << 16) | p.second; } };
// popcount
inline int POPCNT(int x) { return __builtin_popcount(x); }
inline int POPCNT(lint x) { return __builtin_popcount(x); }
// inf
const int iINF = 1L << 30;
const lint lINF = 1LL << 60;
// eps
const Double EPS = 1e-9;
const Double PI = acos(-1);
// inrange
template< typename T >
inline bool in_range(T v, T mi, T mx) { return mi <= v && v < mx; }
template< typename T >
inline bool in_range(T x, T y, T W, T H) { return in_range(x,0,W) && in_range(y,0,H); }
// neighbor clockwise
const int DX[4] = {0,1,0,-1}, DY[4] = {-1,0,1,0};
const int DX_[8] = {0,1,1,1,0,-1,-1,-1}, DY_[8] = {-1,-1,0,1,1,1,0,-1};
// variable update
template< typename T > inline void modAdd(T& a, T b, T mod) { a = (a + b) % mod; }
template< typename T > inline void minUpdate(T& a, T b) { a = min(a, b); }
template< typename T > inline void maxUpdate(T& a, T b) { a = max(a, b); }
// converter
template< typename F, typename T >
inline void convert(F& from, T& to) {
	stringstream ss;
	ss << from; ss >> to;
}

int N, K, D[11];

void solve() {
	set< int > able;
	for_(i,0,10) able.insert(i);
	for_(i,0,K) able.erase(D[i]);
	
	for_(val,N,100*N) {
		bool ok = true;
		int vv = val;
		
		while (vv > 0) {
			int dig = vv % 10;
			vv /= 10;
			ok &= able.count(dig);
		}
		
		if (ok) {
			cout << val << endl;
			break;
		}
	}
}

int main() {
	cin >> N >> K;
	for_(i,0,K) cin >> D[i];
	solve();
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
int main(){
  ll N,C,s,t,c,T=0; cin>>N>>C;
  vector<vector<bool>>Z(31, vector<bool>(100001,false));
  for(int i=0; i<N; i++){
    cin>>s>>t>>c;
    T=max(T,t);
    for(int j=s; j<=t; j++) Z[c][j]=true;
  }
  ll ans=0;
  for(int i=1; i<=T; i++){
    ll temp=0;
    for(int j=1; j<=30; j++){if(Z[j][i])temp++;}
    ans=max(ans,temp);
  }
  cout<<ans<<endl;
}

Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
using pint = pair<int, int>;
using pll = pair<ll, ll>;
using Edge = pair<int, ll>;
using Graph = vector<vector<int>>;
using WeightedGraph = vector<vector<Edge>>;
const ll INF = 1LL << 60;
const int INF32 = 1 << 29;
const ll MOD = 998244353;

int main() {
	ll N; cin >> N;
	vector<pll> vec(N);
	// Rを半開区間 + L昇順・R降順にソート
	for (int i = 0; i < N; ++i) {
		cin >> vec[i].first >> vec[i].second;
		++vec[i].second;
		vec[i].second *= -1;
	}
	sort(vec.begin(), vec.end());
	for (int i = 0; i < N; ++i) {
		vec[i].second *= -1;
	}

	// L最大はソートしたため右端の要素
	ll L = vec[N - 1].first;
	ll LR = vec[N - 1].second;
	// R最小を探す
	ll R = INF, tmp = -1, RL = 0;
	for (int i = 0; i < N; ++i) {
		if (R > vec[i].second) {
			tmp = i;
			R = vec[i].second;
			RL = vec[i].first;
		}
	}

    //TODO: ここ修正。
    // L最小とR最大が一致していなくとも、
    // 同一グループとしてシュミレーションするのが抜けてる？
	if (tmp == N - 1) {
		// 最大区間と最小区間の和
		ll LONGEST = 0;
		for (int i = 0; i < N; ++i) LONGEST = max(LONGEST, vec[i].second - vec[i].first);
		ll SHORTEST = LR - L;
		cout << LONGEST + SHORTEST << endl;
	}
	else {
		vec.erase(tmp + vec.begin());
		vec.pop_back();
		N = N - 2;
        // 同一グループにした場合
		ll LONGEST = 0;
		for (int i = 0; i < N; ++i) LONGEST = max(LONGEST, vec[i].second - vec[i].first);
		ll ans = max(R-L, 0LL) + LONGEST;

        // 別グループにした場合
		vector<ll> tR(N + 1, LR);
		for (int i = N - 1; i >= 0; --i) {
			tR[i] = min(tR[i + 1], vec[i].second);
		}
		vector<ll> tL(N + 1, RL);
		for (int i = 0; i < N; ++i) {
			tL[i+1] = max(tL[i], vec[i].first);
		}

		for (int i = 0; i < N + 1; ++i) {
			ll tmp = max(0LL, R - tL[i]) + max(0LL, tR[i] - L);
			ans = max(ans, tmp);
		}
		cout << ans << endl;
	}

	return 0;
}

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

using namespace std;
const int N = 4e3 + 5, MOD = 998244353;
int c[N][N], pw[N] = {1};

int mul() {return 1;}
template <typename Head, typename... Tail>
int mul(Head H, Tail... T) {return 1ll * mul(T...) * H % MOD;}
int sum() {return 0;}
template <typename Head, typename... Tail>
int sum(Head H, Tail... T) {return (mul(T...) + H) % MOD;}

int C(int n, int k) {
    if (k < 0 || n < 0 || n < k) return 0;
    return c[n][k];
}
int Solve(int n, int k, int m) {
    int r = k - m - m, res = 0;
    for (int i = 0; i <= m; i++) res = sum(res, mul(C(m, i), C(n + r - 1, n - i), pw[i]));
    return res;
}
int main() {
    c[0][0] = 1;
    for (int i = 1; i < N; i++)
        for (int j = 0; j <= i; j++) c[i][j] = sum(c[i - 1][j], c[i - 1][j - 1]);
    for (int i = 1; i < N; i++) pw[i] = mul(pw[i - 1], 2);
    int n, k; cin >> k >> n;
    for (int t = 2; t <= 2 * k; t++) {
        int m = 0;
        for (int i = 1; i <= k; i++) if (i <= t - i && t - i <= k) m++;
        if (t % 2 == 0) cout << sum(Solve(n, k - 1, m - 1), Solve(n - 1, k - 1, m - 1)) << "\n";
        else cout << Solve(n, k, m) << "\n";
    }

    return 0;
}


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

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define all(v) v.begin(), v.end()
#define SP << " " 
#define LLi long long int

using namespace std;

int imax=2147483647;
long long int llimax=9223372036854775807;
LLi mod=1000000007;

LLi modabs(LLi x){
	if(x>=0) return (x%mod);

	LLi tmp=abs(x);
	LLi di=(tmp+mod-1)/mod;
	return mod*di+x;
}
 
LLi modinv(LLi a) {
    LLi b = mod, u = 1, v = 0;
    while (b) {
        LLi t = a / b;
        a -= t * b; swap(a, b);
        u -= t * v; swap(u, v);
    }
    u %= mod;
    if (u < 0) u += mod;
    return u;
}

int main(){

	int n, k, zer=0, pp=0, mp=0, sig=1;
	vector<LLi> pv, mv;
	LLi tmp, ans=1;

	cin>> n >> k;

	rep(i, n){
		cin >> tmp;
		if(0<tmp) pv.push_back(tmp);
		if(0>tmp) mv.push_back(tmp);
		if(tmp==0) zer++;
	}
	
	sort(pv.begin(), pv.end(), greater<LLi>());
	sort(mv.begin(), mv.end());

	if(k%2==1 && n==(int)mv.size()){
		rep(i, k){
			ans*=modabs(mv[mv.size()-1-i]);
			ans=ans%mod;
		}
		cout<< ans <<endl;
		return 0;
	}

	rep(i, k){
		if((int)pv.size()==pp && (int)mv.size()==mp){
			cout<< 0 <<endl;
			return 0;
		}else if((int)pv.size()==pp){
			ans*=modabs(mv[mp]);
			ans=ans%mod;
			sig*=-1;
			mp++;
		}else if((int)mv.size()==mp){
			ans*=pv[pp];
			ans=ans%mod;
			pp++;
		}else{
			if(-mv[mp]<=pv[pp]){
				ans*=pv[pp];
				ans=ans%mod;
				pp++;
			}else{
				ans*=modabs(mv[mp]);
				ans=ans%mod;
				sig*=-1;
				mp++;
			}
		}
	}
	//cout<< "mp=" << mp <<endl;//
	//cout<< "pp=" << pp <<endl;//

	LLi p1=-1, p2=-1;
	if(sig!=1){
		if(pp!=(int)pv.size() && mp!=0) p1=pv[pp]*pv[pp-1];
		if(mp!=(int)mv.size() && pp!=0) p2=mv[mp]*mv[mp-1];
		//cout<< p1 <<endl;
		//cout<< p2 <<endl;

		if(p1>p2){
			ans*=pv[pp];
			ans=ans%mod;
			ans*=modinv(modabs(mv[mp-1]));
			ans=ans%mod;
		}
		if(p1<p2){
			ans*=modabs(mv[mp]);
			ans=ans%mod;
			ans*=modinv(pv[pp-1]);
			ans=ans%mod;
		}
		if(p1==-1 && p2==-1 && zer>0) ans=0;
	}

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

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

int main()
{
    int N, L;
    vector<int> apple;
    vector<int> abs_apple;
    cin >> N >> L;
    for (int i = 0; i < N; i++)
    {
        apple.push_back(L + i);
        abs_apple.push_back(abs(L + i));
    }
    int x=200, y = 300;
    for (int i = 0; i < N; i++)
    {
        if (abs_apple[i] < y)
        {
            y = abs_apple[i];
            x = i;
        }
    }

    apple.erase(apple.begin() + x);
    int total = 0;
    for (int i = 0; i < N - 1; i++)
    {
        total += apple[i];
    }
    cout << total << endl;
    return 0;
}

Measured memory_bytes: 256
function main() {
	input = input[0].split(' ');
	a = parseInt(input[0]);
	b = parseInt(input[1]);
	c = parseInt(input[2]);

	if(a < b && b < c) {
		console.log('Yes');
	} else {
		console.log('No');
	}

}

var input = "";

process.stdin.resume();
process.stdin.setEncoding("utf-8");
process.stdin.on("data", function(chunk) {
	input += chunk;
});

process.stdin.on("end", function() {
	input = input.split("\n");
	main();
})

Measured memory_bytes: 15672
N,X,Y = map(int,input().split())
X -= 1
Y -= 1
w = Y - X
dist = [[0] + [1]*(N-1-i) for i in range(N)]

for k in range(Y):
    for r in range(k+1, N):
        old = r - k
        new = abs(X - k) + 1 + abs(Y - r)
        if new < old:
            dist[k][old] -= 1
            dist[k][new] += 1

for i in range(1, N):
    cnt = 0
    for d in dist:
        if i < len(d):
            cnt += d[i]
    print(cnt)


Measured memory_bytes: 63964
#include <stdio.h>
#include <stdlib.h>


int main(){
  
  int max,min,n;
  scanf("%d",&n);
  int i,a[n];
  for(i = 0; i < n; i++){
    scanf("%d",&a[i]);
  }
  
  max = a[0];
  min = a[0];
  
  for(i = 1; i < n; i++){
    if(a[i] > max) max = a[i];
    if(a[i] < min) min = a[i];
  }
  
  int ans = max - min;
  
  printf("%d",ans);
    
      
  return 0;
  
}
  

Measured memory_bytes: 128
import java.util.*;

public class Main{

     public static void main(String []args){
        String S , A;
        Scanner sc = new Scanner(System.in);
        S = sc.nextLine();
        A = S.substring(0,4);
        if(A.equals("2018") == false){
           S = S.replace(A, "2018");
        } 
        System.out.println(S);
     }
}

Measured memory_bytes: 21972
#include<stdio.h>
#include<malloc.h>

bool decide(int *b){
	for(int i = 0; i < 8; i++)
		for(int j = i+1; j < 9; j++)
			for(int k = j + 1; k < 10; k++)
				if(b[i] > b[j] && b[j] > b[k])return false;
	return true;
}

int main(){
	int N;
	scanf("%d",&N);
	int (*a)[10];
	a = (int (*)[10])malloc(N*10*sizeof(int));
	for(int i = 0; i < N; i++)
		for(int j = 0; j < 10; j++)
			scanf("%d",&a[i][j]);

	for(int k = 0; k < N; k++){
		int *b = a[k];
		if(decide(b) == false)printf("NO\n");
		else printf("YES\n");
		}

	return 0;
}

Measured memory_bytes: 1008
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const double EPS = 1e-9;
typedef vector<int> vint;
typedef pair<int, int> pint;
#define rep(i, n) REP(i, 0, n)
#define ALL(v) v.begin() , v.end()
#define REP(i, x, n) for(int i = x; i < n; i++)

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

int main(){
    ll n, x; cin >> n >> x;
    int ans;
    rep(i, n){
        int a; cin >> a;
        a = abs(a - x);
        ans = i ? gcd(ans, a) : a;
    }
    cout << ans;
}

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

#define MAXN (100010)
#define ll long long

ll n;
ll a[MAXN], sum;

int main(){
	scanf("%lld", &n);
	for(int i = 1; i <= n; ++ i){
		scanf("%lld", a + i);
		sum += a[i];
	}
	ll tmp = n * (n + 1) / 2;
	if(sum % tmp) return printf("NO\n"), 0;
	ll k = sum / tmp;
	for(int i = 1; i <= n; ++ i){
		ll di = a[i % n + 1] - a[i];
		if(k < di || (k - di) % n) return printf("NO\n"), 0;
	}
	printf("YES\n");
	return 0;
}

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

using namespace std;
using ll = long long;

struct P { int x; int y; };

bool compx(const P &a, const P &b) {
    return (a.x == b.x) ? a.y < b.y : a.x < b.x;
}

bool compy(const P &a, const P &b) {
    return (a.y == b.y) ? a.x < b.x : a.y > b.y;
}

int main() {
    int n;
    cin >> n;
    vector<P> r, b;
    vector<bool> ur(n);
    fill(ur.begin(), ur.end(), true);
    for (int i = 0; i < n; i++) {
        P p;
        scanf("%d %d", &p.x, &p.y);
        r.push_back(p);
    }
    for (int i = 0; i < n; i++) {
        P p;
        scanf("%d %d", &p.x, &p.y);
        b.push_back(p);
    }
    sort(b.begin(), b.end(), compx);
    sort(r.begin(), r.end(), compy);
    int sum = 0;
    for (int i = 0; i < n; i++) {
        for (int j = 0; j < n; j++) {
            if (r[j].x < b[i].x && r[j].y < b[i].y && ur[j]) {
                sum++;
                ur[j] = false;
                break;
            }
        }
    }
    cout << sum << endl;
    return 0;
}


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

int main() {
  int N, M; cin>>N>>M;
  vector<int> cnt(M+1,0);
  for(int i = 0; i < N; i++) {
    int K; cin>>K;
    for(int j = 0; j < K; j++) {
      int A; cin>>A;
      cnt[A]++;
    }
  }
  int ans = 0;
  for(int i = 1; i <= M; i++) {
    if(cnt[i] == N) ans++;
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <algorithm>
using namespace std;
#include <vector>
#include <numeric>
#include <map>
#include <cmath>
#include <iomanip>
#include <queue>
using ll =long long;
using vi = vector<int>;
using vl = vector<ll>;
using vvi = vector<vi>;
using vs = vector<string>;

int main() {
    ll N, K, Q;
    cin >> N >> K >> Q;
    vl hito(N, K-Q);
    ll a;
    for(ll i=0; i<Q; i++){
        cin >> a;
        hito.at(a-1) += 1;
    }

    for(ll i=0; i<N; i++){
        if(hito.at(i) <= 0){
            cout << "No" << endl;
        }
        else{
            cout << "Yes" << endl;
        }
    }

}


Measured memory_bytes: 1408
from collections import deque

def dfs(n,m):
    d = deque([])
    if n == 1:
        for i in range(1,m+1):
            d.append([i])
        return d
    else:
        dd=dfs(n-1,m)
        for i in range(len(dd)):
            ll=dd.popleft()
            mx=max(ll)
            for j in range(mx,m+1):
                l=ll[:]
                l.append(j)
                d.append(l)
        return d



n,m,q = map(int,input().split())
x=[[0,0,0,0] for _ in range(q)]
cnt=[0 for _ in range(n)]
for i in range(q):
    x[i] = list(map(int,input().split()))

dq=dfs(n,m)
ans=0
ok=True
for i in range(len(dq)):
    aa=dq.popleft()
    scr=0
    for a,b,c,d in x:
        if aa[b-1]-aa[a-1]==c:
            scr+=d
    ans=max(ans,scr)

print(ans)

Measured memory_bytes: 29180
//include,namespace
 #include<bits/stdc++.h>
 #include<iostream> 
 #include <queue>
 #include <vector>
 #include <string>
 using namespace std;
//REPmacro
 #define all(x) (x).begin(),(x).end()             //ソート
 #define FOR(i,x,n)for(int i=(x);i<(n);i++)
 #define FOR_R(i,x,n) for(int i=(n-1);i>=(x);i--)
 #define REP(i, n) FOR(i, 0, n)
 #define REP_R(i, n) FOR_R(i, 0, n)
//long long(define)
 using ll = long long;
 typedef long long ll;
 typedef long long int64;
 typedef long long lint;
 typedef long long lli;
/////////
int main(){

    string A;
	cin >> A;
    bool is = true;
    FOR(i,1,A.size())if(A[i]!=A[i-1]){is = false;}
    if(is == false){
        cout << "Yes" << endl;
    }else{
        cout << "No" << endl;
    }

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

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

using namespace std;

int main() {
  int n;
  while (cin >> n, n) {
    string s;
    int ans = 0;
    bool f = true;
    vector<bool> l(2, false);
    for (int i = 0; i < n; i++) {
      cin >> s;
      if (f) {  // 床
        if (s == "lu") {
          l[0] = true;
        }
        if (s == "ru") {
          l[1] = true;
        }
        if (s == "ld") {
          l[0] = false;
        }
        if (s == "rd") {
          l[1] = false;
        }
      } else {  // 階段
        if (s == "ld") {
          l[0] = true;
        }
        if (s == "rd") {
          l[1] = true;
        }
        if (s == "lu") {
          l[0] = false;
        }
        if (s == "ru") {
          l[1] = false;
        }
      }
      if (l[0] && l[1]) {
        f = !f;
        ans++;
        l[0] = l[1] = false;
      }
    }
    cout << ans << endl;
  }

  return 0;
}


Measured memory_bytes: 3088
package main

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

func out(x ...interface{}) {
	fmt.Println(x...)
}

var sc = bufio.NewScanner(os.Stdin)

func getInt() int {
	sc.Scan()
	i, e := strconv.Atoi(sc.Text())
	if e != nil {
		panic(e)
	}
	return i
}

func getString() string {
	sc.Scan()
	return sc.Text()
}

// min, max, asub, absなど基本関数
func max(a, b int) int {
	if a > b {
		return a
	}
	return b
}

func min(a, b int) int {
	if a < b {
		return a
	}
	return b
}

func asub(a, b int) int {
	if a > b {
		return a - b
	}
	return b - a
}

func abs(a int) int {
	if a >= 0 {
		return a
	}
	return -a
}

func lowerBound(a []int, x int) int {
	idx := sort.Search(len(a), func(i int) bool {
		return a[i] >= x
	})
	return idx
}

func upperBound(a []int, x int) int {
	idx := sort.Search(len(a), func(i int) bool {
		return a[i] > x
	})
	return idx
}

const mod = 1000000007

func main() {
	sc.Split(bufio.ScanWords)
	sc.Buffer([]byte{}, 1000000)

	s := getString()
	digit := 1
	n := 0
	cnt := 0
	sum := 0
	m := make([][]int, 0)
	for i := len(s) - 1; i >= 0; i-- {
		if s[i] == '?' {
			b := make([]int, 10)
			for j := 0; j < 10; j++ {
				b[j] = (j * digit) % 13
				// out(j, digit, b[j])
			}
			sort.Ints(b)
			m = append(m, b)
			// out(b)
			cnt++
		} else {
			x := int(s[i] - '0')
			n = x * digit
			n %= 13
			sum += n
			sum %= 13
			// out(x, n)
		}
		digit *= 10
		digit %= 13
	}
	// out(sum)
	// for i := 0; i < cnt; i++ {
	// 	out(m[i])
	// }

	dp := make([][]int, cnt+1)
	for i := 0; i <= cnt; i++ {
		dp[i] = make([]int, 13)
	}

	dp[0][0] = 1
	for i := 0; i < cnt; i++ {
		for j := 0; j < 10; j++ {
			// out(i, j, m[i][j])
			for k := 0; k < 13; k++ {
				next := (m[i][j] + k) % 13
				dp[i+1][next] += dp[i][k]
				dp[i+1][next] %= mod
				// out("-->", (m[i][j]+k)%13)
			}
			// dp[i+1][xx] S+= dp[i-1][yy]
		}
	}

	pos := []int{5, 4, 3, 2, 1, 0, 12, 11, 10, 9, 8, 7, 6}
	out(dp[cnt][pos[sum]])
}


Measured memory_bytes: 25344
#include <iostream>
#include <array>
#include <algorithm>

int main() {
  int a,b,c;
  std::cin >> a >> b >> c;
  std::array<int,3> ar{a,b,c};
  std::sort(ar.begin(), ar.end(), [](int left, int right){ return left < right; });
  std::cout << ar[0] << " " << ar[1] << " " << ar[2] << std::endl;
}


Measured memory_bytes: 3156
#include<bits/stdc++.h>
using namespace std;
using i64 = int_fast64_t;
#define rep(i, N) for(i64 i = 0; i < N; i++)
#define Rep(i, k, N) for(i64 i = k; i < N; i++)
#define all(v) v.begin(), v.end()
#define eb emplace_back
#define Cout(s) cout << s << endl
string Yes(bool b) {if(b){return "Yes";} else {return "No";}}
string YES(bool b) {if(b){return "YES";} else {return "NO";}}

int main(){
    i64 N, K;
    cin >> N >> K;
    vector<i64> A(N+1);
    rep(i, N) cin >> A[i];

    for(i64 k = 0; k < min<i64>(K, 45); k++){
        vector<i64> B(N+1,0);
        for(i64 i = 0; i < N; i++){
            i64 b = max<i64>(i - A[i], 0); 
            i64 e = min<i64>(i + A[i], N-1);
            ++B[b], --B[e+1];
        }
        for(int i = 1; i < N; i++) B[i] += B[i-1];
        A = B;
    }

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


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

#define ll long long
#define mod 1000000007
#define inf 1000000000000000000
#define fr first
#define sc second
#define pb push_back
#define pf push_front
#define rep(i,a,n) for(ll i=a;i<n;i++)
#define per(i,a,n) for(ll i=n-1;i>=a;i--)
#define pll pair<ll,ll>
#define vll vector<ll>
#define umap unordered_map<ll,ll>
#define lpq priority_queue<ll,vector<ll>,greater<ll>>
ll globe=0;
ll powe(ll n,ll r){if(!r)return 1;else if(r%2==0)return powe(n*n,r/2);else return n*powe(n*n,(r-1)/2);}

ll solve(vector<vll> &dp,ll day,ll dec,vll &a,vll &b,vll &c){
	if(day==globe)
		return 0;
	if(dp[dec][day]!=-1)
		return dp[dec][day];
	if(dec==0)
		dp[dec][day]=max(b[day]+solve(dp,day+1,1,a,b,c),c[day]+solve(dp,day+1,2,a,b,c));
	else if(dec==1)
		dp[dec][day]=max(a[day]+solve(dp,day+1,0,a,b,c),c[day]+solve(dp,day+1,2,a,b,c));
	else
		dp[dec][day]=max(b[day]+solve(dp,day+1,1,a,b,c),a[day]+solve(dp,day+1,0,a,b,c));
	return dp[dec][day];
}

int main(){

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

	ll t=1;
	//cin>>t;
	while(t--){
		ll n;
		cin>>n;
		vll a(n);
		vll b(n);
		vll c(n);
		for(ll i=0;i<n;i++)
			cin>>a[i]>>b[i]>>c[i];
		ll ans=-inf;
		vll sdp(n,-1);
		vector<vll> dp(3,sdp);
		globe=n;
		ans=max(ans,a[0]+solve(dp,1,0,a,b,c));
		ans=max(ans,b[0]+solve(dp,1,1,a,b,c));
		ans=max(ans,c[0]+solve(dp,1,2,a,b,c));
		cout<<ans<<endl;
	}

	return 0;

}

Measured memory_bytes: 15104
#!/usr/bin/env python3
n,k=map(int,input().split())
h=[int(input()) for i in range(n)]
h.sort()
ans=10**10
for i in range(n):
    if i+k-1>=n:break
    ans=min(ans,h[i+k-1]-h[i])
print(ans)


Measured memory_bytes: 7384