akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
long long n, p[200005], a[200005], maks, ans;
long long maksseg[1000006];
void update (int pos, int ll, int rr, int cur, long long val){
	if (ll==rr and ll==pos){
		maksseg[cur]=val;
		return;
	}
	if (ll>pos or rr<pos) return;
	int mid = (ll+rr)/2;
	update (pos, ll, mid, cur*2, val);
	update (pos, mid+1, rr, cur*2+1, val);
	maksseg[cur] = max(maksseg[cur*2], maksseg[cur*2+1]);
	return;
}
long long query(int l, int r, int ll, int rr, int cur){
	if (l<=ll and r>=rr) return maksseg[cur];
	if (r<ll or l>rr) return -1;
	long long ret = query(l, r, ll, (ll+rr)/2, cur*2);
	ret = max(ret, query(l, r, (ll+rr)/2+1, rr, cur*2+1));
	return ret;
}
int main (){
ios::sync_with_stdio(0);
cin.tie(0); cout.tie(0);
cin >> n;
for (int i=1; i<=n; i++)
	cin >> p[i];
for (int i=1; i<=n; i++)
	cin >> a[i];
for (int i=1; i<=n; i++){
	maks = query(1, p[i], 1, n, 1);
	update(p[i], 1, n, 1, maks+a[i]);
	ans = max(ans, maks+a[i]);
} cout << ans;
return 0;
}


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

int main() {
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	int n;
	cin >> n;
	vector<int> arr(n);
	for(int& x : arr) cin >> x;
	int mn = arr[n-1];
	for(int i = n-2; i >= 0; i--) {
		if(arr[i] > mn + 1) {
			cout << "No" << endl;
			return 0;
		}
		mn = min(mn, arr[i]);
	}
	
	cout << "Yes" << endl;
}


Measured memory_bytes: 768
#include<bits/stdc++.h>
using namespace std;
typedef int ll;
typedef long long int li;
const ll MAXN=2e5+51;
struct SegmentTree{
	ll l,r,sum;
};
SegmentTree tree[MAXN<<2];
ll cnt,l,r,mid,res;
ll x[MAXN],prefix[MAXN];
inline ll read()
{
    register ll num=0,neg=1;
    register char ch=getchar();
    while(!isdigit(ch)&&ch!='-')
    {
        ch=getchar();
    }
    if(ch=='-')
    {
        neg=-1;
        ch=getchar();
    }
    while(isdigit(ch))
    {
        num=(num<<3)+(num<<1)+(ch-'0');
        ch=getchar();
    }
    return num*neg;
}
inline void update(ll node)
{
	tree[node].sum=tree[node<<1].sum+tree[(node<<1)|1].sum;
}
inline void create(ll l,ll r,ll node)
{
	tree[node].l=l,tree[node].r=r;
	if(l==r)
	{
		tree[node].sum=0;
		return;
	}
	ll mid=(l+r)>>1;
	create(l,mid,node<<1);
	create(mid+1,r,(node<<1)|1);
	update(node);
}
inline void changePoint(ll pos,ll val,ll node)
{
	if(tree[node].l==tree[node].r)
	{
		tree[node].sum+=val;
		return;
	}
	ll mid=(tree[node].l+tree[node].r)>>1;
	if(pos<=mid)
	{
		changePoint(pos,val,node<<1);
	}
	else
	{
		changePoint(pos,val,(node<<1)|1);
	}
	update(node);
}
inline ll query(ll l,ll r,ll node)
{
	if(l<=tree[node].l&&r>=tree[node].r)
	{
		return tree[node].sum;
	}
	ll mid=(tree[node].l+tree[node].r)>>1,res=0;
	if(l<=mid)
	{
		res+=query(l,r,node<<1);
	}
	if(r>mid)
	{
		res+=query(l,r,(node<<1)|1);
	}
	return res;
}
inline ll check(ll mid)
{
	li ress=0;
	prefix[0]=0;
	for(register int i=1;i<=cnt;i++)
	{
		prefix[i]=prefix[i-1]+(x[i]<=mid?1:-1);
	}
	for(register int i=0;i<=cnt;i++)
	{
		prefix[i]+=cnt+1;
	}
	create(1,200001,1);
	for(register int i=0;i<=cnt;i++)
	{
		ress+=query(1,prefix[i]-1,1);
		changePoint(prefix[i],1,1);
	}
	return ress>=1ll*cnt*(cnt+1)/4+1;
}
int main()
{
	cnt=read(),l=1,r=1e9;
	for(register int i=1;i<=cnt;i++)
	{
		x[i]=read();
	}
	while(l<=r)
	{
		mid=(l+r)>>1;
		check(mid)?res=mid,r=mid-1:l=mid+1;
	}
	printf("%d\n",res);
}

Measured memory_bytes: 7680
#include<cstdio>
#include<cstdlib>
#include<cmath>
#include<iostream>
#include<string>
#include<stack>
#include<queue>
#include<vector>
#include<map>
#include<set>
#include<algorithm>
 
#define rep(n) for(int i=0;i<n;i++)
#define repp(j, n) for(int j=0;j<n;j++)
#define reppp(i, m, n) for(int i=m;i<=n;i++)
#define all(c) c.begin(), c.end()
#define rall(c) c.rbegin(), c.rend()
#define pb(x) push_back(x)
#define eb(x,y) emplace_back(x,y)
#define MOD 1000000007
#define MAX 1000000001
#define INF 1410065408
#define EPS 1e-9
 
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
struct edge{int from, to; ll cost;};
 
signed main(){
    
    int n,num=0;
    cin>>n;
    int a[n]; 
    
    rep(n){
        cin>>a[i];
    }
    
    sort(a,a+n);
    
    if(a[n-1]-a[0]>1){
        cout<<"No";
    }
    if(a[n-1]-a[0]==1){
        for(int i=0;a[0]==a[i];i++){
            num++;
        }
        if(a[0]+1-num>0&&a[0]*2+2<=n+num){
            cout<<"Yes";
        }
        else{
            cout<<"No";
        }
    }
    if(a[n-1]==a[0]){
        if(a[0]==n-1||n>=a[0]*2){
            cout<<"Yes";
        }
        else{
            cout<<"No";
        }
    }
}

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

long long int K, N, x, y, l, r, u, b, a;
vector<pair<long long, long long>> p;

int count(long long a, long long b, long long c, long long d){
    int ret = 0;
    for(auto i : p){
        ret += (i.first >= a) && (i.first <= c) && (i.second >= b) && (i.second <= d);
    }
    return ret;
}

int main(){
    scanf("%lld%lld", &N, &K);
    for(int i = 0; i < N; ++i){
        scanf("%lld%lld", &x, &y);
        p.emplace_back(x, y);
    }
    a = 9223372036854775707;
    for(int i = 0; i < N; ++i){
        for(int j = 0; j < N; ++j){
            for(int k = 0; k < N; ++k){
                for(int l = 0; l < N; ++l){
                    if(count(p[i].first, p[j].second, p[k].first, p[l].second) == K){
                        a = min(a, (p[k].first - p[i].first) * (p[l].second - p[j].second));
                    }
                }
            }
        }
    }
    cout << a << endl;
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <cstdlib>
#include <cmath>
#include <vector>
#include <unordered_map>
#include <map>
#include <set>
#include <algorithm>
#include <queue>
#include <stack>
#include <functional>
#include <bitset>
#include <assert.h>
#include <unordered_map>
#include <fstream>
using namespace std;
typedef long long ll;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<char> vc;
typedef vector<string> vs;
typedef vector<bool> vb;
typedef vector<double> vd;
typedef pair<ll,ll> P;
typedef pair<int,int> pii;
typedef vector<P> vpl;
typedef tuple<ll,ll,ll> tapu;
#define rep(i,n) for(int i=0; i<(n); i++)
#define REP(i,a,b) for(int i=(a); i<(b); i++)
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
const int inf = 1<<30;
const ll linf = 1LL<<62;
const int MAX = 510000;
ll dy[8] = {1,-1,0,0,1,-1,1,-1};
ll dx[8] = {0,0,1,-1,1,-1,-1,1};
const double pi = acos(-1);
const double eps = 1e-7;
template<typename T1,typename T2> inline bool chmin(T1 &a,T2 b){
	if(a>b){
		a = b; return true;
	}
	else return false;
}
template<typename T1,typename T2> inline bool chmax(T1 &a,T2 b){
	if(a<b){
		a = b; return true;
	}
	else return false;
}
template<typename T> inline void print(T &a){
    rep(i,a.size()) cout << a[i] << " ";
    cout << "\n";
}
template<typename T1,typename T2> inline void print2(T1 a, T2 b){cout << a << " " << b << "\n";}
template<typename T1,typename T2,typename T3> inline void print3(T1 a, T2 b, T3 c){
	cout << a << " " << b << " " << c << "\n";
}
const int mod = 1e9 + 7;
//const int mod = 998244353;


int main(){
    ll n; cin >> n;
    vl a(n); rep(i,n) cin >> a[i];
    ll b = 2;
    ll now = 1;
    sort(rall(a));
    ll ans = a[0];
    rep(i,n-2){
        if(!b){
            b = 2;
            now++;
        }
        ans += a[now];
        b--;
    }
    cout << ans << endl;
}

Measured memory_bytes: 4836
#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 true; } return false; }
//template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
 
/* attention
    long longのシフト演算には気をつけよう
    タイポした時のデバッグが死ぬほどきつくなるので変数名は最低3字くらい使った方がいいかも
    sizeは(int)とキャストしよう
    ごちゃごちゃ場合分けを考える前に全探索は考えましたか？
*/

int main(){
    int N, K; cin >> N >> K;
    vector<ll> v(N);
    for(int i=0; i<N; i++) cin >> v[i];

    ll ans = 0;
    for(int l=-1; l<N; l++){
        for(int r=N; r>l; r--){
            if(l+1+N-r > K) continue;
            priority_queue<ll> pq;
            ll sum = 0;
            
            if(l>=0) for(int i=0; i<=l; i++) {
                if(v[i] < 0) pq.push(-v[i]);
                sum += v[i];
            }
            if(r<N) for(int i=N-1; i>=r; i--){
                if(v[i] < 0) pq.push(-v[i]);
                sum += v[i];
            }

            int cnt = K-(l+1+N-r);
            while(cnt>0 && !pq.empty()){
                ll u=pq.top(); pq.pop();
                sum += u;
                cnt--;
            }

            ans = max(ans, sum);
        }
    }

    cout << ans << endl;
}

Measured memory_bytes: 256
from collections import deque

H,W=map(int,input().split())
n=int(input())
A=list(map(int,input().split()))
C=[]
for i in range(n):
    for _ in range(A[i]):
        C.append(i+1)


M=[deque([]) for _ in range(H)]

for i in range(H*W):
    if (i//W)%2==0:
        M[i//W].append(C[i])
    else:
        M[i//W].appendleft(C[i])

for i in range(H):
    print(*M[i])

Measured memory_bytes: 4340
#include <iostream>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <algorithm>
#include <string>
#include <cmath>
#include <cstdio>
#include <iomanip>
#include <fstream>
#include <cassert>
#include <cstring>
#include <numeric>
#include <ctime>
#include <complex>
#include <bitset>
#include <random>
#include <climits>

using namespace std;

typedef long long ll;
typedef long double ld;

#define int ll
#define double ld
#define loop(i, n) for(int i = 0; i < (int)n; ++i)
#define loop1(i, n) for(int i = 1; i <= (int)n; ++i)
#define F first
#define S second
#define pb push_back
#define pi pair <int, int>
#define all(x) begin(x), end(x)
#define ti tuple <int, int, int>
#define Point Vect
#define no {cout << 0; return;}
#define mkp make_pair
#define mkt make_tuple
#define cerr if(0) cerr

const int INF = 1000000000000000010;

bool left(int x, int calc, vector <int> & pls, vector <int> &mns, int nul) {
    int cnt = (x <= 0 ? 0 : nul * (nul - 1) / 2 + nul * (pls.size() + mns.size()));
    loop(i, pls.size()) {
        int l = i, r = pls.size();
        while (r - l > 1) {
            int m = l + r >> 1;
            if (pls[i] * pls[m] < x)
                l = m;
            else
                r = m;
        }
        cnt += l - i;
    }
    loop(i, mns.size()) {
        int l = i, r = mns.size();
        while (r - l > 1) {
            int m = l + r >> 1;
            if (mns[i] * mns[m] < x)
                l = m;
            else
                r = m;
        }
        cnt += l - i;
    }
    loop(i, mns.size()) {
        int l = -1, r = pls.size();
        while (r - l > 1) {
            int m = l + r >> 1;
            if (mns[i] * pls[m] >= x)
                l = m;
            else
                r = m;
        }
        cnt += pls.size() - r;
    }
    return cnt <= calc;
}

void solve() {
    int n, k, nul = 0;
    cin >> n >> k;
    --k;
    vector <int> mns, pls;
    loop(i, n) {
        int x; cin >> x;
        if (x < 0)
            mns.pb(x);
        else if (x == 0)
            ++nul;
        else
            pls.pb(x);
    }
    sort(all(mns), greater<int>());
    sort(all(pls));
    int l = -INF, r = INF;
    while (r - l > 1) {
        int m = l + r >> 1;
        if (left(m, k, pls, mns, nul))
            l = m;
        else
            r = m;
    }
    cout << l;
}

signed main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    //int t; cin >> t; loop(i, t)
    solve();
    return 0;
}

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

int main() {
  string S;
  cin >> S;
  if (S.at(2) == S.at(3) && S.at(4) == S.at(5)) {
    cout << "Yes" << endl;
  } else {
    cout << "No" << endl;
  }
}


Measured memory_bytes: 256
package main

import (
	"bufio"
	_ "container/heap"
	"fmt"
	"os"
	_ "sort"
	"strconv"
)

// I/O
type Scanner struct {
	sc *bufio.Scanner
}

func NewScanner() *Scanner {
	sc := bufio.NewScanner(os.Stdin)
	sc.Split(bufio.ScanWords)
	sc.Buffer(make([]byte, 1024), int(1e+9))
	return &Scanner{sc}
}

func (s *Scanner) nextStr() string {
	s.sc.Scan()
	return s.sc.Text()
}

func (s *Scanner) nextInt() int {
	i, e := strconv.Atoi(s.nextStr())
	if e != nil {
		panic(e)
	}
	return i
}

func (s *Scanner) nextFloat() float64 {
	f, e := strconv.ParseFloat(s.nextStr(), 64)
	if e != nil {
		panic(e)
	}
	return f
}

func (s *Scanner) nextRuneSlice() []rune {
	return []rune(s.nextStr())
}

func (s *Scanner) nextIntSlice(n int) []int {
	res := make([]int, n)
	for i := 0; i < n; i++ {
		res[i] = s.nextInt()
	}
	return res
}

func (s *Scanner) nextFloatSlice(n int) []float64 {
	res := make([]float64, n)
	for i := 0; i < n; i++ {
		res[i] = s.nextFloat()
	}
	return res
}

// Arithmetic
func max(nums ...int) int {
	m := nums[0]
	for _, i := range nums {
		if m < i {
			m = i
		}
	}
	return m
}

func min(nums ...int) int {
	m := nums[0]
	for _, i := range nums {
		if m > i {
			m = i
		}
	}
	return m
}

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

func pow(x, y int) int {
	res := 1
	for i := 0; i < y; i++ {
		res *= x
	}
	return res
}

func ceil(a, b int) int {
	if a%b == 0 {
		return a / b
	} else {
		return a/b + 1
	}
}

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

func lcm(a, b int) int {
	return a / gcd(a, b) * b
}

// Sort
type RuneSlice []rune

func (a RuneSlice) Len() int           { return len(a) }
func (a RuneSlice) Less(i, j int) bool { return a[i] < a[j] }
func (a RuneSlice) Swap(i, j int)      { a[i], a[j] = a[j], a[i] }

// Main
const MOD = int(1e+9) + 7
const INF = 1 << 60

func main() {
	sc := NewScanner()
	wtr := bufio.NewWriter(os.Stdout)
	defer wtr.Flush()
	S := sc.nextStr()
	goo := 0
	ans := 0
	for _, r := range S {
		if r == 'g' {
			if goo > 0 {
				goo--
				ans++
			} else {
				goo++
			}
		} else {
			if goo > 0 {
				goo--
			} else {
				goo++
				ans--
			}
		}
	}

	fmt.Fprintln(wtr, ans)
}


Measured memory_bytes: 1024
TIMEZONE_NUM = 10

N = int(input())
F = []
for _ in range(N):
    F.append(list(map(int, input().split())))
P = []
for _ in range(N):
    P.append(list(map(int, input().split())))

ans = -float('inf')
for i in range(1, 2 ** TIMEZONE_NUM):
    tmp_ans = 0
    for n in range(N):
        both_open_num = 0
        for flag_j, flag_f in zip(bin(i)[2:].zfill(TIMEZONE_NUM), F[n]):
            if int(flag_j) == flag_f == 1:
                both_open_num += 1
        tmp_ans += P[n][both_open_num]
    ans = max(ans, tmp_ans)

print(ans)


Measured memory_bytes: 3188
N=gets.to_i
if N > 100
  a = 10
elsif N > 1000
  a =100
elsif N > 10000
  a = 1000
else
a = 1
end
b = 0
l = []
while a < (N / 2) + 1 && b < N do
  b = N - a
  m = 0
  n = (a.to_s + b.to_s).split""
  n.each do |k|
    m += k.to_i
  end
  l << m
  a += 1
end
puts l.min


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

int main(){
#ifdef LOCAL
    freopen("./input.txt", "r", stdin);
#endif
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    
    string s;
    cin >> s;
    
    int ok = 1;
    string t = s;
    reverse(t.begin(), t.end());
    if (s != t) {
        ok = 0;
    }
    int n = s.length();
    string f = s.substr(0, (n-1)/2);
    string se = s.substr((n+1)/2, (n-1)/2);
    t = f;
    reverse(t.begin(), t.end());
    if(f!= t){
        ok = 0;
    }
    t = se;
    reverse(t.begin(), t.end());
    if(se !=t){
        ok = 0;
    }
    
    if(ok){
        cout << "Yes" << "\n";
    }else{
        cout << "No" << "\n";
    }
    
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define INF 329496729612
#define int long long
#define MOD (int)(1e9+7)
#define MAX 500
typedef  pair<int,int> P;

int r, c, ax, ay, by, bx, ans, temp;
int grid[MAX+10][MAX+10],countg[MAX+10][MAX+10], flags[MAX+10][MAX+10], dxy[4] = {1, -1, 0, 0};

void huga(){
  queue<P> Q;
  Q.push(P(ax,ay));

  for(int i = 0; i <= MAX; i++)
    for(int j = 0; j <= MAX; j++)
      grid[i][j] = INF;

  grid[ay][ax] = 0;
  countg[ay][ax]=1;

  while(!Q.empty()){
    P p = Q.front();Q.pop();
    int x = p.first, y=p.second,ny, nx;
    // int  rc[2][4] = {{x,x,0,r-1},{0,c-1,y,y}};
    int  rc[2][4] = {{x,x,0,c-1},{0,r-1,y,y}};
    for(int i = 0; i < 8; i++){
      if(i < 4) nx = x + dxy[i], ny = y + dxy[3-i];
      else  ny = rc[1][i-4], nx = rc[0][i-4];

      if(0 <= nx && nx < c && 0 <= ny && ny < r){
	if(grid[y][x]+1 < grid[ny][nx]){
	  grid[ny][nx] = grid[y][x]+1;
	  if(nx != bx|| ny != by)Q.push(P(nx,ny));
	}
      }
    }
  }

  Q.push(P(ax,ay));
  while(!Q.empty()){
    P p = Q.front();Q.pop();
    int x = p.first, y=p.second,ny, nx;
    // int  rc[2][4] = {{x,x,0,r-1},{0,c-1,y,y}};
    int  rc[2][4] = {{x,x,0,c-1},{0,r-1,y,y}};
    if(flags[y][x])continue;
    else flags[y][x]=1;
    for(int i = 0; i < 8; i++){
      if(i < 4) nx = x + dxy[i], ny = y + dxy[3-i];
      else  ny = rc[1][i-4], nx = rc[0][i-4];

      if(0 <= nx && nx < c && 0 <= ny && ny < r){
	if(grid[y][x]+1 == grid[ny][nx]){
	  countg[ny][nx] += countg[y][x];
	  if(nx != bx|| ny != by)Q.push(P(nx,ny));
	  countg[ny][nx] %= MOD;
	}
      }
    }
  }
}

signed main(){
  cin>>r>>c>>ay>>ax>>by>>bx;

  huga();

  cout<<grid[by][bx]<<" "<<countg[by][bx]%MOD<<endl;

  return 0;
}


Measured memory_bytes: 8948
#include<bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
int main(){
  double N ;
  cin >> N;
  
  int x;
  x = N;
  
  if (x % 2 == 0){
    cout << (x / 2) / N << endl;
  }
  else {
    cout << (x / 2 + 1) / N << endl;
  }
  
  
 
}

Measured memory_bytes: 256
#include<iostream>
#include<climits>
#include<math.h>
#include<vector>
#include<algorithm>
#include<cstdio>
#include <string>
#include <complex>
#include <functional>
using namespace std;
typedef pair<int,int> P;
double dat[100][100];
int dp[6][1010];//動的計画法
int prime[10000001];
char str[1010][1010];
vector<pair<int,int> > pc[100001];
int ABS(int a){return max(a,-a);}
int main(){
  int a,b;
  cin>>a>>b;
  cout<<(a-1)*(b-1)<<endl;
    return 0;
}

Measured memory_bytes: 4352
using System;
class Program
{
    static void Main(string[] args)
    {
        string[] nml = Console.ReadLine().Split(' ');
        int n = int.Parse(nml[0]);
        int m = int.Parse(nml[1]);
        int l = int.Parse(nml[2]);
        int[,] nm = new int[n, m];
        int[,] ml = new int[m, l];
        for (int i = 0; i < n; i++)
        {
            string[] data = Console.ReadLine().Split(' ');
            for (int j = 0; j < m; j++)
            {
                nm[i, j] = int.Parse(data[j]);
            }
        }
        for (int i = 0; i < m; i++)
        {
            string[] data = Console.ReadLine().Split(' ');
            for (int j = 0; j < l; j++)
            {
                ml[i, j] = int.Parse(data[j]);
            }
        }
        for (int i = 0; i < n; i++)
        {
            string line = "";
            for (int j = 0; j < l; j++)
            {
                long sum = 0;
                for (int k = 0; k < m; k++)
                {
                    sum += nm[i, k] * ml[k, j];
                }
                if (j != 0) line += " ";
                line += sum;
            }
            Console.WriteLine(line);
        }
    }
}

Measured memory_bytes: 17900
#include"bits/stdc++.h"
using namespace std;
typedef long long ll;
#define int ll
#define x first
#define y second
const int mod=1e9+7;
int modp(int a,int b)
{
	if(b==0)return 1;
	int u=modp(a,b/2);
	u=(u*u)%mod;
	if(b&1)return (a*u)%mod;
	return u;
}
pair<int,int> norm(int a,int b)
{
	int g=__gcd(a,b);
	a/=g;b/=g;
	if(a<0 or (a==0 and b<0))a=-a,b=-b;
	return {a,b};
}
pair<int,int> inv(pair<int,int> p)
{
	return norm(-p.y,p.x);
}
int32_t main()
{
	
	int n;
	cin>>n;
	int z=0;
  //	auto cc=inv(norm(1,2));cout<<cc.x<<" "<<cc.y<<"\n";
	map<pair<int,int>,int> m;
	for(int i=0;i<n;i++)
	{
		int a,b;cin>>a>>b;
		if(a==0 and b==0){z++;continue;}
		auto p=norm(a,b);
		m[p]++;m[inv(p)]+=0;
	}
  //for(int i=0;i<10;i++)cout<<modp(2,i+1)<<"\n";
	int res=1;
	for(auto i:m)
	{
		auto p=i.x;auto pi=inv(i.x);
		int c1=m[p],c2=m[pi];
		if(p>pi)continue;
		int ways=(modp(2,c1)+modp(2,c2)-1+mod)%mod;
		res=(res*ways)%mod;
	}
	int ans=(res-1)+z;ans%=mod;ans+=mod;ans%=mod;
	cout<<ans<<"\n";

}


Measured memory_bytes: 28548
N = int(input())
A = list(map(int,input().split()))
mod = 10**9+7
def power(a,b):
    if b == 0:
        return 1
    if b % 2 == 0:
        d = power(a,b//2)
        return d*d%mod
    elif b % 2 == 1:
        return a*power(a,b-1)%mod
import fractions
l = A[0]
g = A[0]
for i in range(1,N):
    x = A[i]
    g = fractions.gcd(l,x)
    l = l*x//g
l = l % mod
ans = 0
for i in range(N):
    ans += l*power(A[i],mod-2) % mod
ans = ans%mod
print(ans)

Measured memory_bytes: 5684
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
#define _USE_MATH_DEFINES
#include <math.h>
#define rep(i,n) for(int i = 0;i < n;i++)
#define NIL = -1;
#define all(x) x.begin(),x.end()
const ll INF = 1e9;
const ll mod = 1e9 + 7;

int digit(ll x) {
    if (x / 10 == 0) return 1;
    return digit(x / 10) + 1;
}

ll gcd(long long a,long long b) {
    if (a < b) swap(a,b);
    if (b == 0) return a;
    
    return gcd(b,a%b);
}

ll lcm(ll a,ll b){
    return ((a * b == 0)) ? 0 : (a / gcd(a,b) * b);
}

double DegreeToRadian(double degree){
    return degree * M_PI / 180.0;
}

int dx[4] = {0,1,0,-1};
int dy[4] = {1,0,-1,0};


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

int main(){
    double a, b, h, m;
    cin >> a >> b >> h >> m;

    double s = (60 * h + m) / 720 * 2 * M_PI;
    double l = m / 60 * 2 * M_PI;  
    double theta = s - l;

    cout << fixed << setprecision(10) << sqrt(a*a + b*b - 2*a*b*cos(theta)) << endl;
}

Measured memory_bytes: 4132
#include <bits/stdc++.h>
#define rep(i, n) for (ll i = 0; i < (ll)(n); ++i)
#define rep2(i, s, n) for (ll i = s; i < (ll)(n); i++)
#define repr(i, n) for (ll i = n; i >= 0; i--)
#define pb push_back
#define COUT(x) cout << (x) << endl
#define COUTF(x) cout << setprecision(15) << (x) << endl
#define ENDL cout << endl
#define DF(x) x.erase(x.begin())  // 先頭文字削除
#define ALL(x) x.begin(), x.end()
#define SORT(x) sort(ALL(x))
#define REVERSE(x) reverse(ALL(x))
#define init() \
  cin.tie(0);  \
  ios::sync_with_stdio(false)
#define debug(x) cerr << "[debug] " << #x << ": " << x << endl;
#define debugV(v)                       \
  cerr << "[debugV] " << #v << ":";     \
  rep(i, v.size()) cerr << " " << v[i]; \
  cerr << endl;
using namespace std;
using ll = long long;
using ld = long double;
using vll = vector<ll>;
using P = pair<ll, ll>;
constexpr ll INF = 0x3f3f3f3f3f3f3f3f;
constexpr double PI = 3.141592653589793238462643383279;
ll getDigit(ll x) {
  return x == 0 ? 1 : log10(x) + 1;
}

ll gcd(ll x, ll y) {
  return y ? gcd(y, x % y) : x;
}

ll lcm(ll a, ll b) {
  return a / gcd(a, b) * b;
}

vector<P> factorize(ll n) {
  vector<P> result;
  for (ll i = 2; i * i <= n; ++i) {
    if (n % i == 0) {
      result.pb({i, 0});
      while (n % i == 0) {
        n /= i;
        result.back().second++;
      }
    }
  }
  if (n != 1) {
    result.pb({n, 1});
  }
  return result;
}

vll divisor(ll n) {
  vll ret;
  for (ll i = 1; i * i <= n; i++) {
    if (n % i == 0) {
      ret.push_back(i);
      if (i * i != n) ret.push_back(n / i);
    }
  }
  SORT(ret);
  return (ret);
}

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;
}

signed main() {
  init();
  string S;
  cin >> S;

  ll mini = INF;
  rep(i, S.size()) {
    if (i + 2 >= (ll)S.size()) {
      continue;
    }
    string sub = S.substr(i, 3);
    ll a = stoi(sub);
    ll sa = abs(753 - a);
    if (mini > sa) {
      mini = sa;
    }
  }
  COUT(mini);
  return 0;
}

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

using namespace std;
using ll = long long;
using P = pair<int, int>;
using LP = pair<ll, ll>;

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

    int n;
    cin>>n;
    int k;
    cin>>k;
    int b = 0;
    rep(i, k) {
        int m;
        cin>>m;
        b += 1<<m;
    }

    rep(i, 1<<n) {
        if ((i&b) != b) continue;
        cout<<i<<":"<<(i != 0 ? ' ' : '\n');
        int temp = i;
        vector<int> res;
        rep(j, n) {
            if (temp & 1) res.push_back(j);
            temp = temp >> 1;
        }
        rep(j, res.size()) cout<<res[j]<<(j != res.size() - 1 ? ' ' : '\n');
    }
}


Measured memory_bytes: 3240
#include <stdio.h>

int main(void)
{
  int A,B;
  scanf("%d",&A);
  scanf("%d",&B);
  if(A%3 == 0 || B%3 == 0 || (A+B)%3 == 0)
    printf("Possible");
  else
    printf("Impossible");
  
  return 0;
}

Measured memory_bytes: 128
import time
startTimeProblem=time.time()

import fileinput, sys, itertools, functools
from math import *
from bisect import *
from heapq import *
from collections import *

def lcm(a, b):  
    return (a*b)/gcd(a, b)

class InputHelper:
    def __init__(self):
        self.myinput = fileinput.input()

    def isLocal(self):
        return not fileinput.isstdin()

    def int(self):
        return int(self.myinput.readline().rstrip())

    def ints(self):
        return [int(_) for _ in self.myinput.readline().rstrip().split()]

    def str(self):
        return self.myinput.readline().rstrip()

    def strs(self):
        return [_ for _ in self.myinput.readline().rstrip().split()]

class OutputHelper:
    def int(self, a):
        print(a)    

    def ints(self, a):  
        print(" ".join([str(_) for _ in a]))
    
    def intsNL(self, a):
        for _ in a:
            print(_)
    
    def str(self, s):
        print(s)

    def strs(self, s):
        print(" ".join([_ for _ in s]))

    def strsNL(self, s):
        for st in s:
            print(st)

class ListNode:
    def __init__(self, val):
        self.val = val
        self.next = None
        self.prev = None

In = InputHelper()
Out = OutputHelper()

######################################

N = In.str()

ans = 0

for num in N:
    ans += int(num)
    ans %= 9

if ans==0:
    Out.str("Yes")
else:
    Out.str("No")

######################################

if len(sys.argv)>2 and sys.argv[2]=="TIMEIT":
    fin = (time.time()-startTimeProblem)*1000
    print("{:.2f}".format(fin) + "ms")

Measured memory_bytes: 74584
import sys
from math import ceil
RI = lambda : [int(x) for x in sys.stdin.readline().split()]
ri = lambda : sys.stdin.readline().strip()

def input(): return sys.stdin.readline().strip()
def list2d(a, b, c): return [[c] * b for i in range(a)]
def list3d(a, b, c, d): return [[[d] * c for j in range(b)] for i in range(a)]
def list4d(a, b, c, d, e): return [[[[e] * d for j in range(c)] for j in range(b)] for i in range(a)]
def ceil(x, y=1): return int(-(-x // y))
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(N=None): return list(MAP()) if N is None else [INT() for i in range(N)]
def Yes(): print('Yes')
def No(): print('No')
def YES(): print('YES')
def NO(): print('NO')
INF = 10 ** 18
MOD = 10 ** 9 + 7
 
# for i in range(int(ri())):
n,k = RI()
if k >= n:
    print(min(n,abs(k-n)))
else:
    temp= n%k
    print(min(temp,abs(k-temp)))

Measured memory_bytes: 3064
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include <random>
#include <chrono>

using namespace std;
using namespace __gnu_pbds;

#define endl '\n'

typedef long long ll;
typedef pair<int, int> pii;
//typedef tree<int,null_type,less<int>,rb_tree_tag, tree_order_statistics_node_update> indexed_set;

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

const double oo = 1e11;
const int maxn = 1e5 + 5;

ll x[maxn], y[maxn];
ll vx[maxn], vy[maxn];
int n;


double f(double t){
	
	double mnX = oo, mxX = -oo, mnY = oo, mxY = -oo;
	
	for(int i = 0; i < n; i++){
		double nx = 1.0 * x[i] + 1.0 * t * vx[i];
		double ny = 1.0 * y[i] + 1.0 * t * vy[i];
		
		mnX = min(mnX, nx);
		mxX = max(mxX, nx);
		mnY = min(mnY, ny);
		mxY = max(mxY, ny);
	}
	
	return (mxX - mnX) * (mxY - mnY);
}

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

	//freopen("input.txt", "r", stdin);
	//freopen("output.txt", "w", stdout);
	
	cin >> n;
	
	for(int i = 0; i < n; i++){
		cin >> x[i] >> y[i];
		char c;
		cin >> c;
		
		if(c == 'U')
			vy[i] = +1;
		if(c == 'D')
			vy[i] = -1;
		if(c == 'R')
			vx[i] = +1;
		if(c == 'L')
			vx[i] = -1; 
	}
	
	double lo = 0.0, hi = oo;
	
	for(int i = 0; i < 150; i++){
		double third = (hi - lo) / 3.0;
		double p1 = lo + third;
		double p2 = hi - third;
		
		if(f(p1) < f(p2))
			hi = p2;
		else
			lo = p1;
	}
	
	cout << setprecision(10) << fixed;
	cout << f(lo) << endl;

	return 0;
}


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

int main() {
  int A , N;
  cin >> N >> A;
  int D = N%500;
  
  if (D <= A) {
    cout << "Yes" << endl;
  }
  
  if (D > A) {
    cout << "No" << endl;
  }
}

Measured memory_bytes: 256
#include<iostream>
#include<stdlib.h>
#include<vector>
#include<algorithm>
#include<stdio.h>
#include<string>
#include<map>
#include<math.h>
#include<iomanip>
#include<set>
#include<limits.h>
#include<cmath>
#include<queue>
#include<stack>
#define rep(i,n) for(ll i = 0; i < (ll)n; i++)
#define swap(a,b) a^=b;b^=a;a^=b;
#define chmax(a,b) {if(a < b) a = b;}
#define chmin(a,b) {if(a > b) a = b;}
using namespace std;
typedef long long ll;
ll gcd(ll, ll);
vector<bool> to_binary(int);
int sum(vector<int>);
int min(vector<int>);
int max(vector<int>);
ll nCr(ll n, ll r);

const ll INF = 1LL << 60;

typedef tuple<ll, ll> mtupl;

bool mycomp(mtupl x, mtupl y) {
	return get<1>(x) < get<1>(y);
}

vector<vector<ll>> memo;

ll get(int x, int y) {
	if (memo[x][y] != -1)
		return memo[x][y];

	if (x == 0) return 1;
	if (y < x) return 0;

	memo[x][y] = get(x, y - 1) + get(x - 1, y - 1);
	return memo[x][y];
}

ll mpow(ll a, ll b) {
	ll ans = 1;
	for (ll i = 0; i < b; i++) {
		ans *= a;
		ans %= 1000000007;
	}
	return ans;
}

ll nCr(ll n, ll r) {
	ll res = 1;
	for (int i = 0; i < r; i++) {
		res *= (n - i);
	}
	for (int i = 1; i <= r; i++) {
		res /= i;
	}
	return res;
}

int vsum(vector<int> v) {
	int res = 0;
	for (auto it = v.begin(); it != v.end(); it++)
		res += *it;
	return res;
}
int vmin(vector<int> v) {
	int min = INT32_MAX;
	for (auto it = v.begin(); it != v.end(); it++)
		min = std::min(min, *it);
	return min;
}
int vmax(vector<int> v) {
	int max = INT32_MIN;
	for (auto it = v.begin(); it != v.end(); it++)
		max = std::max(max, *it);
	return max;
}

ll gcd(ll A, ll B) {
	if (A == 0 || B == 0) return max(A, B);
	int r = A % B;
	while (r != 0) {
		A = B;
		B = r;
		r = A % B;
	}
	return B;
}

ll _gcd(ll A, ll B) {
	return (B == 0) ? A : gcd(A % B, B);
}

vector<bool> to_binary(int x) {
	vector<bool> res;
	while (x != 0) {
		res.push_back(x % 2);
		x /= 2;
	}
	return res;
}

template<int index>
bool comp(tuple<ll, ll, ll, ll> a, tuple<ll, ll, ll, ll> b) {
	return get<index>(a) < get<index>(b);
}

int vector_finder(std::vector<ll> vec, ll number) {
	auto itr = std::find(vec.begin(), vec.end(), number);
	size_t index = std::distance(vec.begin(), itr);
	if (index != vec.size()) { // 発見できたとき
		return index;
	}
	else { // 発見できなかったとき
		return 0;
	}
}


int len(int x) {
	return (int)log10(x) + 1;
}

int same_vec(vector<int> a, vector<int> b) {
	int res = 1, num = a.size();
	for (int i = 0; i < num; i++) {
		if (a[i] != b[i]) {
			res = 0;
			break;
		}
	}
	return res;
}


ll fibs[100] = { 0 };
ll fib(int n) {
	if (fibs[n] == 0) {
		return fibs[n] = fib(n - 1) + fib(n - 2);
	}
	return fibs[n];
}



int main(void) {
	cin.tie(0);
	ios::sync_with_stdio(false);
	//Program Start	

	int N,K;
	cin >> N >> K;

	int tmp,count = 0;
	rep(i, N) {
		cin >> tmp;
		if (K <= tmp) count++;
	}

	cout << count << endl;


ProgramEndPointLabel:;

	//Program End
#ifndef DEBUG
	system("pause");
#endif // !DEBUG


	return 0;
}




Measured memory_bytes: 504
#include <stdio.h>
int main( void )
{
	int N ;
	char s;
	scanf("%d\n", &N ) ;
	int R=0, B=0;
	for( int n = 0 ; n < N ; n++ ) {
		scanf("%c", &s ) ;
		s == 'R' ? R++ : B++ ;
	}
	printf("%s\n", (R>B) ? "Yes" : "No" ) ;
	return 0 ;
}

Measured memory_bytes: 128
#include <stdio.h>
int main(){
  int r[200000],max,min,j,i,n;
  scanf("%d",&n);
    for(i=0;i<n;i++){
      scanf("%d",&r[i]);
    }
   
    min=r[0];
    max=r[1]-r[0];
    for(j=1;j<n;j++){
      if(max<r[j]-min) max=r[j]-min;

      if(min>r[j]) min=r[j];
    }
    printf("%d\n",max);

  return 0;
}

Measured memory_bytes: 1376
N, K = map(int, input().split())
D = []
A = []
for k in range(K):
    d = int(input())
    a = list(map(int, input().split()))
    D.append(d)
    A.append(a)

check = [False]*(N+1)

for k in range(K):
    for sunuke in A[k]:
        if check[sunuke] == False:
            check[sunuke] = True
itazura = 0
for n in range(1, N+1):
    if check[n] == False:
        itazura += 1
print(itazura)

Measured memory_bytes: 9152
#include<iostream>
#include<string>

int main(void){
    int sx, sy, tx, ty;
    std::cin >> sx >> sy >> tx >> ty;

    int deltaX = tx - sx;
    int deltaY = ty - sy;

    //first visit for (tx, ty)
    std::cout << std::string(deltaY, 'U');
    std::cout << std::string(deltaX, 'R');
   
    //fist back to (sx, sy)
    std::cout << std::string(deltaY, 'D');
    std::cout << std::string(deltaX, 'L');

    //second visit for (tx, ty)
    std::cout << 'L' << std::string(deltaY + 1, 'U');
    std::cout << std::string(deltaX + 1, 'R') << 'D';

    //second back to (sx, sy)
    std::cout << 'R' << std::string(deltaY + 1, 'D');
    std::cout << std::string(deltaX + 1, 'L') << 'U' << std::endl;

    return 0;
}

Measured memory_bytes: 256
import sys

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

in_n = lambda: int(readline())
in_nn = lambda: map(int, readline().split())
in_na = lambda: map(int, read().split())
in_s = lambda: readline().rstrip().decode('utf-8')


def main():

    N, K = in_nn()
    p = list(in_nn())
    ans = sum(sorted(p)[:K])
    print(ans)


if __name__ == '__main__':
    main()


Measured memory_bytes: 9288
use std::cmp::max;

#[allow(unused_macros)]
macro_rules! scan {
    () => {
        {
            let mut line: String = String::new();
            std::io::stdin().read_line(&mut line).unwrap();
            line.trim().to_string()
        }
    };
    (;;) => {
        {
            let mut line: String = String::new();
            std::io::stdin().read_line(&mut line).unwrap();
            line.trim().split_whitespace().map(|s| s.to_string()).collect::<Vec<String>>()
        }
    };
    (;;$n:expr) => {
        {
            (0..$n).map(|_| scan!()).collect::<Vec<_>>()
        }
    };
    ($t:ty) => {
        {
            let mut line: String = String::new();
            std::io::stdin().read_line(&mut line).unwrap();
            line.trim().parse::<$t>().unwrap()
        }
    };
    ($($t:ty),*) => {
        {
            let mut line: String = String::new();
            std::io::stdin().read_line(&mut line).unwrap();
            let mut iter = line.split_whitespace();
            (
                $(iter.next().unwrap().parse::<$t>().unwrap(),)*
            )
        }
    };
    ($t:ty;;) => {
        {
            let mut line: String = String::new();
            std::io::stdin().read_line(&mut line).unwrap();
            line.split_whitespace()
                .map(|t| t.parse::<$t>().unwrap())
                .collect::<Vec<_>>()
        }
    };
    ($t:ty;;$n:expr) => {
        (0..$n).map(|_| scan!($t;;)).collect::<Vec<_>>()
    };
    ($t:ty; $n:expr) => {
        (0..$n).map(|_|
                    scan!($t)
        ).collect::<Vec<_>>()
    };
    ($($t:ty),*; $n:expr) => {
        (0..$n).map(|_|
                    scan!($($t),*)
        ).collect::<Vec<_>>()
    };
}
fn search<F>(len: usize, f: F) -> usize
where
    F: Fn(usize) -> bool,
{
    let mut left = 0;
    let mut right = len;
    while left < right {
        let mid = (left + right) / 2;
        if f(mid) {
            right = mid;
        } else {
            left = mid + 1;
        }
    }
    left
}

fn main() {
    let (a, b, q) = scan!(usize, usize, usize);
    let mut ts = scan!(i64;a);
    ts.insert(0, -1 << 60);
    ts.push(1 << 60);
    let mut ss = scan!(i64;b);
    ss.insert(0, -1 << 60);
    ss.push(1 << 60);

    for _ in 0..q {
        let x = scan!(i64);
        let rt = search(ts.len(), |i| x <= ts[i]);
        let rs = search(ss.len(), |i| x <= ss[i]);
        let lt = rt - 1;
        let ls = rs - 1;

        println!(
            "{}",
            vec![
                max((ts[rt] - x).abs(), (ss[rs] - x).abs()),
                2 * (ts[rt] - x).abs() + (ss[ls] - x).abs(),
                (ts[rt] - x).abs() + 2 * (ss[ls] - x).abs(),
                2 * (ts[lt] - x).abs() + (ss[rs] - x).abs(),
                (ts[lt] - x).abs() + 2 * (ss[rs] - x).abs(),
                max((ts[lt] - x).abs(), (ss[ls] - x).abs()),
            ]
            .iter()
            .min()
            .unwrap()
        )
    }
}


Measured memory_bytes: 9596
#include<stdio.h>
#define N 100
#define NIL -1

int fibonacci(int );
int A[N];

int main(){
  int n,i;
  for(i=0;i<N;i++) A[i]= NIL;

  scanf("%d",&n);
  printf("%d\n",fibonacci(n));

  return 0;
}

int fibonacci(int n){

  if(n == 0||n == 1) return A[n] = 1;
  if(A[n] != NIL) return A[n];
  return A[n] = fibonacci(n-2) + fibonacci(n-1); 
}



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

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

	vector<vector<int>> a(n, vector<int>(2));
	rep(i, n) {
		cin >> a.at(i).at(0);
		a.at(i).at(1) = i;
	}

	sort(a.begin(), a.end());

	rep(i, n) {
		if (i == a.at(n - 1).at(1)) {
			cout << a.at(n - 2).at(0) << endl;
		} else {
			cout << a.at(n - 1).at(0) << endl;
		}
	}
}


Measured memory_bytes: 14492
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  // Input
  int N;
  cin >> N;
  vector<string> S(N);
  for (int i; i<N; i++) cin >> S.at(i);

  int M;
  cin >> M;
  vector<string> T(M);
  for (int i; i<M; i++) cin >> T.at(i);
  
  // Point calculation
  vector<int> P_S(N); 
  
  for (int i = 0; i < N; i++) {
    for (int j = 0; j < N; j++){
      if (S.at(i) == S.at(j)) P_S.at(i)++;
    }
  }
 
  for (int i = 0; i < N; i++) {
    for (int j = 0; j < M; j++){
      if (S.at(i) == T.at(j)) P_S.at(i)--;
    }
  }  
  
  //Max calculation
  int p_max = 0;
  for (int i = 0;i < N; i++){
    if (p_max <= P_S.at(i)) p_max = P_S.at(i);
  }
  
  //Output
  cout << p_max << endl; 
}

Measured memory_bytes: 256
#include <algorithm>
#include <complex>
#include <cstdlib>
#include <ctime>
#include <time.h>
#include <iomanip>
#include <iostream>
#include <map>
#include <math.h>
#include <queue>
#include <random>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>

using namespace std;
#define SAY_YES cout << "YES" << endl;
#define SAY_Yes cout << "Yes" << endl;
#define SAY_NO cout << "NO" << endl;
#define SAY_No cout << "No" << endl;
#define IFYES(TRUE_OR_FALSE)   \
    if (TRUE_OR_FALSE)         \
    {                          \
        cout << "YES" << endl; \
    }                          \
    else                       \
    {                          \
        cout << "NO" << endl;  \
    }
#define IFYes(TRUE_OR_FALSE)   \
    if (TRUE_OR_FALSE)         \
    {                          \
        cout << "Yes" << endl; \
    }                          \
    else                       \
    {                          \
        cout << "No" << endl;  \
    }
#define IFyes(TRUE_OR_FALSE)   \
    if (TRUE_OR_FALSE)         \
    {                          \
        cout << "yes" << endl; \
    }                          \
    else                       \
    {                          \
        cout << "no" << endl;  \
    }
#define DEBUG_OUTPUT_ARRAY(XXX, ONE)                            \
    for (int i = 0; i < (ONE); i++)                             \
    {                                                           \
        cout << "DEBUG: i = " << i << " -> " << XXX[i] << endl; \
    }
#define DEBUG_OUTPUT_ARRAY2(XXX, ONE, TWO)                             \
    for (int i = 0; i < (ONE); i++)                                    \
    {                                                                  \
        cout << "<<< i = " << i << " >>>" << endl;                     \
        for (int j = 0; j < (TWO); j++)                                \
        {                                                              \
            cout << "DEBUG: j = " << j << " -> " << XXX[i][j] << endl; \
        }                                                              \
    }
#define DEBUG_OUTPUT_ARRAY2_BOX(XXX, ONE, TWO) \
    for (int i = 0; i < (ONE); i++)            \
    {                                          \
        cout << i << "  ";                     \
        for (int j = 0; j < (TWO); j++)        \
        {                                      \
            cout << XXX[i][j] << " ";          \
        }                                      \
        cout << endl;                          \
    }

typedef pair<long long int, long long int> pll;


const long long int mod = 998244353;
const long long int INF = 1e18;




long long int N,S,K,A[200050]={},dp[3005]={},sum[3005]={},res=0;
long long int findp[3005][3005];

int main()
{
    cout << fixed << setprecision(18);
    cin>>N>>K;
    for (int i = 0; i < N; i++)
    {
        cin>>A[i];
    }
    sort(A,A+N);
    for(long long int i = N-1; i >=N-K; i--){
        res+=A[i];
    }
    cout<<res<<endl;
    
}


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

#define watch(x) cerr << (#x) << ": " << (x) << endl

typedef long long LL;

const int N = 200009;
int n, a[N];
vector<int> graph[N];

int ans[N], d[N];

void dfs(int cur, int par = 0) {
    int j = lower_bound(d, d+n+1, a[cur]) - d;
    int saved = d[j];
    d[j] = a[cur];

    ans[cur] = lower_bound(d, d+n+1, INT_MAX) - d;
    for(int child : graph[cur]) {
        if(child == par) continue;
        dfs(child, cur);
    }
    
    d[j] = saved;
}

int main() {

    ios_base::sync_with_stdio(false);
    cin.tie(NULL);

    cin >> n;
    for(int i = 1; i <= n; ++i) {
        cin >> a[i];
    }
    for(int i = 0; i < n-1; ++i) {
        int u, v; cin >> u >> v;
        graph[u].push_back(v);
        graph[v].push_back(u);
    }

    for(int i = 0; i <= n; ++i) {
        d[i] = INT_MAX;
    }

    dfs(1);

    for(int i = 1; i <= n; ++i) {
        cout << ans[i] << '\n';
    }
    
    return 0;
}


Measured memory_bytes: 31172
#!/usr/bin/env python3
import sys
from itertools import product

def solve(N: int):
    def f(n):
        h = n
        while h // 10 > 0:
            h //= 10
        return h, n%10
    table = [[0] * 10 for _ in range(10)]
    for h, t in map(f, range(1, N+1)):
        table[h][t] += 1
    return sum(table[i][j] * table[j][i] for i, j in product(range(1, 10), repeat=2))

# Generated by 1.1.6 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    print(solve(N))

if __name__ == '__main__':
    main()


Measured memory_bytes: 3064
/*
    Mbak Rose Dong
*/
#include <bits/stdc++.h>
#define ll long long int
using namespace std;
int l[100100], r[100100];
ll c[100100];
ll dp[100100];
bool pend[100100];
vector<int> in[100100], out[100100];
int main()
{
    int n,i,j,k,x,y,ans,m,q,curr,temp;
    scanf("%d %d",&n,&m);
    for(i=1;i<=n;i++) dp[i] = 1e16;
    for(i=1;i<=m;i++)
    {
        scanf("%d %d %lld",&l[i], &r[i], &c[i]);
        in[l[i]].push_back(i);
        out[r[i]].push_back(i);
    }
    set<pair<ll,int> > s;
    for(i=1;i<=n;i++)
    {
        while(!s.empty() && pend[(*s.begin()).second] == 1) s.erase(s.begin());
        if(!s.empty())
        {
            curr = (*s.begin()).second;
            ll cost = (*s.begin()).first;
            dp[i] = min(dp[i], cost);
        }
        for(auto x : in[i])
        {
            ll aa = 0;
            if(l[x] != 1) aa = dp[l[x]];
            s.insert({c[x] + aa, x});
        }
        for(auto x : out[i])
        {
            pend[x] = 1;
        }
    }
    if(dp[n] == 1e16) dp[n] = -1;
    printf("%lld\n", dp[n]);
    return 0;
}


Measured memory_bytes: 16256
#include <algorithm>
#include <cfloat>
#include <climits>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <functional>
#include <iostream>
#include <map>
#include <memory>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>
 
using namespace std;
 
typedef long long ll;
 
#define sz size()
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define all(c) (c).begin(), (c).end()
#define rep(i,a,b) for(ll i=(a);i<(b);++i)
#define per(i,a,b) for(ll i=b-1LL;i>=(a);--i)
#define clr(a, b) memset((a), (b) ,sizeof(a))
#define ctos(c) string(1,c)
#define print(x) cout<<#x<<" = "<<x<<endl;
 
#define MOD 1000000007

int main(){
  ll n;
  cin>>n;
  vector<ll> v;
  rep(i,0,n){
    ll a;
    cin>>a;
    v.pb(a);
  }
  ll ans = -1;
  ll index = 1;
  rep(i,0,v.sz){
    if(v[i]==index){
      ans = index;
      index++;
    }
  }
  if(ans==-1){
    cout << -1 << endl;
  }
  else{
    cout << n-ans << endl;
  }
  return 0;
}

Measured memory_bytes: 2548
import sys
from collections import deque
n, m = map(int,sys.stdin.readline().rstrip().split()) # nは頂点の数、mは辺の数
g = [[] for _ in range(n)] # 隣接リスト

for _ in range(m):
    a, b = map(lambda x:int(x)-1,sys.stdin.readline().rstrip().split())
    g[a].append(b)
    g[b].append(a)
def bfs(u):
    a={}
    queue = deque([u])
    d = [None] * n # uからの距離の初期化
    d[u] = 0 # 自分との距離は0
    while queue:
        v = queue.popleft()
        for i in g[v]:
            if d[i] is None:
                d[i] = d[v] + 1
                a[i]=v+1
                queue.append(i)
                
    return d,a

# 0からの各頂点の距離
d,dct = bfs(0)
if None in d:
  print('No')
  sys.exit()
print('Yes')
for _, v in sorted(dct.items()):
    print(str(v))

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

int main(){
  int n, rank;
  bool einin[4][13] = {};
  char beta;
  
  cin >> n;
  for(int i = 0;i < n;i++){
    cin >> beta >> rank;
    if(beta == 'S')einin [0][rank-1] = true;
    if(beta == 'H')einin [1][rank-1] = true;
    if(beta == 'C')einin [2][rank-1] = true;
    if(beta == 'D')einin [3][rank-1] = true;
  }
  for(int h = 0;h < 4;h++){
    for(int w = 0;w < 13;w++){
      if(einin [h][w] == true)continue;
      if(h == 0)beta = 'S';
      if(h == 1)beta = 'H';
      if(h == 2)beta = 'C';
      if(h == 3)beta = 'D';
      cout << beta << " " << w+1 << endl;
    }
  }
}


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

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

    int h[n];
    int now[n];
    vector<int> check;
    for(int i = 0; i < n; i++){
        cin >> h[i];
        now[i] = 0;
        if(h[i] == now[i]){
            check.push_back(1);
        }else{
            check.push_back(0);
        }
    }

    long long ans = 0;
    int k = accumulate(check.begin(), check.end(), 0);
    while(1){
        if(k == n){
            break;
        }
        int r = 0;
        int flag = 0;
        for(int i = 0; i < n; i++){
            if(check[i] == 1){
                for(int j = r; j < i; j++){
                    now[j] += 1;
                    if(now[j] == h[j]){
                        check[j] = 1;
                    }
                    flag = 1;
                }
                if(flag == 1){
                    ans++;
                    flag = 0;
                }
                r = i + 1;
            }else if(i == n - 1){
                for(int j = r; j < n; j++){
                    now[j] += 1;
                    if(now[j] == h[j]){
                        check[j] = 1;
                    }
                    flag = 1;
                }

                if(flag == 1){
                    ans++;
                    flag = 0;
                }
            }
        }

        k = accumulate(check.begin(), check.end(), 0);

        
    }

    cout << ans << endl;
}

Measured memory_bytes: 256