akhauriyash/Code-Regression huggingface dataset:
#pragma GCC optimize ("O3")
#pragma GCC target ("sse4")
 
#include <bits/stdc++.h>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/assoc_container.hpp>
 
using namespace std;
using namespace __gnu_pbds;
 
typedef long long ll;
typedef long double ld;
typedef complex<ld> cd;
 
typedef pair<int, int> pi;
typedef pair<ll,ll> pl;
typedef pair<ld,ld> pd;
 
typedef vector<int> vi;
typedef vector<ld> vd;
typedef vector<ll> vl;
typedef vector<pi> vpi;
typedef vector<pl> vpl;
typedef vector<cd> vcd;
 
template <class T> using Tree = tree<T, null_type, less<T>, rb_tree_tag,tree_order_statistics_node_update>;
 
#define FOR(i, a, b) for (int i=a; i<(b); i++)
#define F0R(i, a) for (int i=0; i<(a); i++)
#define FORd(i,a,b) for (int i = (b)-1; i >= a; i--)
#define F0Rd(i,a) for (int i = (a)-1; i >= 0; i--)
 
#define sz(x) (int)(x).size()
#define mp make_pair
#define pb push_back
#define f first
#define s second
#define lb lower_bound
#define ub upper_bound
#define all(x) x.begin(), x.end()
 
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
 
const int MOD = 1000000007;
const ll INF = 1e18;
const int MX = 100001; //check the limits, dummy
 
ll modExp(ll base, ll power) {
    if (power == 0) {
        return 1;
    } else {
        ll cur = modExp(base, power / 2); cur = cur * cur; cur = cur % MOD;
        if (power % 2 == 1) cur = cur * base;
        cur = cur % MOD;
        return cur;
    }
}

ll inv(ll base) {
    int g = MOD, r = base, x = 0, y = 1;
    while (r != 0) {
        int q = g / r;
        g %= r; swap(g, r);
        x -= q * y; swap(x, y);
    }
    return x < 0 ? x+MOD : x;
}

ll mul(ll A, ll B) {
	return (A*B)%MOD;
}

ll add(ll A, ll B) {
	return (A+B)%MOD;
}

ll dvd(ll A, ll B) {
    return mul(A, inv(B));
}

ll sub(ll A, ll B) {
    return (A-B+MOD)%MOD;
}
ll* facs = new ll[MX];
ll* facInvs = new ll[MX];

ll choose(ll a, ll b) {
	if (b > a) return 0;
	if (a < 0) return 0;
	if (b < 0) return 0;
    ll cur = facs[a];
    cur = mul(cur, facInvs[b]);
    cur = mul(cur, facInvs[a-b]);
    return cur;
}

void initFacs() {
	facs[0] = 1;
	facInvs[0] = 1;
	FOR(i, 1, MX) {
		facs[i] = (facs[i-1] * i) % MOD;
		facInvs[i] = inv(facs[i]);
	}
}
int main() {
	ios_base::sync_with_stdio(0); cin.tie(0);    
	
    initFacs();

    int N, K; cin >> N >> K;
    vl data(N); F0R(i, N) cin >> data[i];
    sort(all(data));
    ll ans = 0;
    F0R(i, N-K+1) {
        ll cnt = choose(N-i-1, K-1);
        ll val = data[i] + MOD; val %= MOD;
        val *= cnt; val %= MOD;
        ans += MOD - val; ans %= MOD;
    }

    FOR(i, K-1, N) {
        ll cnt = choose(i, K-1);
        ll val = data[i] + MOD; val %= MOD;
        val *= cnt; val %= MOD;
        ans += val; ans %= MOD;
    }

    cout << ans << endl;
    
	
	return 0;
}
 
// read the question correctly (ll vs int)
// template by bqi343



Measured memory_bytes: 2560
//参考：http://ehafib.hatenablog.com/entry/2015/12/23/164517
//インクルード(アルファベット順,bits/stdc++.hは使わない派閥)
#include<algorithm>//sort,二分探索,など
#include<bitset>//固定長bit集合
#include<cmath>//pow,logなど
#include<complex>//複素数
#include<deque>//両端アクセスのキュー
#include<functional>//sortのgreater
#include<iomanip>//setprecision(浮動小数点の出力の誤差)
#include<iostream>//入出力
#include<iterator>//集合演算(積集合,和集合,差集合など)
#include<map>//map(辞書)
#include<numeric>//iota(整数列の生成),gcdとlcm(c++17)
#include<queue>//キュー
#include<set>//集合
#include<stack>//スタック
#include<string>//文字列
#include<unordered_map>//イテレータあるけど順序保持しないmap
#include<unordered_set>//イテレータあるけど順序保持しないset
#include<utility>//pair
#include<vector>//可変長配列

using namespace std;
typedef long long ll;

//マクロ
//forループ関係
//引数は、(ループ内変数,動く範囲)か(ループ内変数,始めの数,終わりの数)、のどちらか
//Dがついてないものはループ変数は1ずつインクリメントされ、Dがついてるものはループ変数は1ずつデクリメントされる
#define REP(i,n) for(ll i=0;i<(ll)(n);i++)
#define REPD(i,n) for(ll i=n-1;i>=0;i--)
#define FOR(i,a,b) for(ll i=a;i<(ll)(b);i++)
#define FORD(i,a,b) for(ll i=a;i>=(ll)(b);i--)
//xにはvectorなどのコンテナ
#define ALL(x) (x).begin(),(x).end() //sortなどの引数を省略したい
#define SIZE(x) ((ll)(x).size()) //sizeをsize_tからllに直しておく
#define MAX(x) *max_element(ALL(x)) //最大値を求める
#define MIN(x) *min_element(ALL(x)) //最小値を求める
//定数
#define INF 1000000000000 //10^12:極めて大きい値,∞
#define MOD 1000000007 //10^9+7:合同式の法
#define MAXR 100000 //10^5:配列の最大のrange(素数列挙などで使用)
//略記
#define PB push_back //vectorヘの挿入
#define MP make_pair //pairのコンストラクタ
#define F first //pairの一つ目の要素
#define S second //pairの二つ目の要素


int main() {
    int K, N;
    cin >> K >> N;
    vector<int> A;
    FOR(i, 0, N){
        int tmp;
        cin >> tmp;
        A.push_back(tmp);
    }
    std::sort(A.begin(), A.end());

    int answer=std::numeric_limits<int>::max();

    for(int i=0; i<N-1; i++){
        int d =  A[(i+1)] - A[i];
        answer = min(answer, K-d);
    }

    answer = min(answer, K-(A[0]+K-A[N-1]));

    cout << answer << endl;
    return 0;
}


Measured memory_bytes: 4320
/**
 * neb, sw=8, ts=8
 */

#include <bits/stdc++.h>
#include <iostream>
#include <fstream>
#include <algorithm>
#include <string>
#include <vector>
#include <unordered_map>

typedef long long ll;
typedef unsigned long long ul;
typedef unsigned int ui;

using std::cout;	using std::cin;
using std::endl;

template<typename T>
inline T max(const T &x, const T &y) { if (x > y) return x; else return y; }

template<typename T>
inline T min(const T &x, const T &y) { if (x < y) return x; else return y; }

template<typename T>
inline void print_vec(const std::vector<T> &a) { for (auto i: a) { std::cout << i << " "; } std::cout << std::endl; }
template<typename T>
inline void print_vec(const std::vector<std::pair<T, T>> &a) { for (auto i: a) { std::cout << "{" << i.first << ", " << i.second << "}, "; } std::cout << std::endl; }


int main()
{
	int n;
	cin >> n;
	std::string s;
	int x;
	std::map<std::string, std::vector<std::pair<int, int>>> m;
	for (int i = 1; i <= n; ++i)
	{
		cin >> s;
		cin >> x;
		if (m[s].empty())
		{
			m[s] = std::vector<std::pair<int, int>>();
		}
		m[s].push_back({x, i});
	}

	for (auto &i: m)
	{
		std::sort(i.second.begin(), i.second.end(),
				[](const std::pair<int, int> &a, const std::pair<int, int> &b) {
					return a.first > b.first;
				}
				);
		for (auto &j: i.second)
			cout << j.second << endl;
	}
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (a>b) { a=b; return 1; } return 0; }

using Lint=long long;
using Graph=vector<vector<int>>;

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

    int N,M; cin>>N>>M;
    Graph G(N);
    for(int i=0;i<M;i++){
        int a,b; cin>>a>>b;
        G[a].push_back(b);
        G[b].push_back(a);
    }

    vector<int> color(N,-1);
    int c=0;
    function<void(int)> dfs=[&](int v)
    {
        color[v]=c;
        for(int u:G[v]) if(color[u]==-1){
            dfs(u);
        }
    };
    for(int i=0;i<N;i++) if(color[i]==-1) dfs(i),c++;

    int Q; cin>>Q;
    while(Q--){
        int s,t; cin>>s>>t;
        cout<<(color[s]==color[t]? "yes":"no")<<endl;
    }
    return 0;
}


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


int main() {
	int n, k;
	cin >> n >> k;
	double ans = 0;
	for (int i = 0; i < n; i++) {
		double hoge;
		hoge = 1.0 / n;
		for (int j = 0; k > (i + 1 <<j); j++) {
			hoge *= 0.5;
		}
		ans += hoge;
	}
	printf("%.12f", ans);
	cout << endl;
	return 0;
}


Measured memory_bytes: 256
package main

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

var sc, wr = bufio.NewScanner(os.Stdin), bufio.NewWriter(os.Stdout)

func scanString() string { sc.Scan(); return sc.Text() }
func scanInt() int { a,_ := strconv.Atoi(scanString()); return a }
func scanInt64() int64 { a,_ := strconv.ParseInt(scanString(),10,64); return a }
func scanFloat64() float64 { a,_ := strconv.ParseFloat(scanString(),64); return a }

func scanInts(n int) []int {
	res := make([]int, n); for i := 0; i < n; i++ { res[i] = scanInt() }; return res
}

func abs(a int) int { if a<0 { return -a }; return a }
func min(a,b int) int { if a<b { return a }; return b }
func max(a,b int) int { if a>b { return a }; return b }

//•*¨*•.¸¸♪Main•*¨*•.¸¸♪(　-ω-)ノ　(　・ω・)

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

	n := scanInt()
	k := scanInt()
	a := scanInts(n)

	sort.Ints(a)
	b := make(ints, n)
	copy(b,a)
	sort.Sort(b)

	l, r := -(1 << 62-1), 1 << 62-1
	for l + 1 < r {
		mid := (l + r)/2
		// fmt.Println(mid,l,r)
		c := 0
		for i := 0; i < n; i++ {
			tmp := a[i+1:]
			if a[i] < 0 {
				tmp = b[:n-i-1]
			}

			ll, rr := -1, len(tmp)
			for ll+1 < rr {
				midmid := (ll+rr)/2
				if a[i]*tmp[midmid] < mid {
					ll = midmid
				} else {
					rr = midmid
				}
			}
			
			c += rr
			// fmt.Println(a[i],rr,tmp)
		}

		if k > c {
			l = mid
		} else {
			r = mid
		}
		// fmt.Println(mid,c)
		// fmt.Println()
	}

	fmt.Println(l)
}

type ints []int

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


Measured memory_bytes: 8192
#include "bits/stdc++.h"
//#include "atcoder/all"
#define rep(i,n) for(int i = 0; i < (n); ++i)
using namespace std;
//using namespace atcoder;
typedef long long int ll;
typedef pair<int, int> P;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

int a[305][305];
ll memo[90005], num[90005];

int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	int h, w, d;
	cin >> h >> w >> d;
	rep(i,h)rep(j,w){
		cin >> a[i][j];
		num[a[i][j]] = i * w + j;
	}
	for(int i = 1; i <= h*w; ++i){
		if(i+d <= h*w){
			int y = num[i] / w;
			int x = num[i] % w;
			int ny = num[i+d] / w;
			int nx = num[i+d] % w;
			memo[i+d] = memo[i] + abs(y - ny) + abs(x - nx);
		}
	}
	int q;
	cin >> q;
	rep(qi,q){
		int l, r;
		cin >> l >> r;
		int ans = memo[r] - memo[l];
		cout << ans << endl;
	}
	return 0;
}


Measured memory_bytes: 5424
from sys import stdin, exit
from math import factorial
input = stdin.readline
lmi = lambda: list(map(int, input().split()))
mi = lambda: map(int, input().split())
si = lambda: input().strip('\n')
ssi = lambda: input().strip('\n').split()

n, m = mi()
foods = [0 for i in range(m+1)]
for i in range(n):
    arr = lmi()
    for j in arr[1:]:
        foods[j] += 1
cnt= 0
for i in range(1, m+1):
    if foods[i] == n:
        cnt += 1
print(cnt)

Measured memory_bytes: 3064
#define _USE_MATH_DEFINES
#include <iostream>
#include <fstream>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cstring>
#include <string>
#include <vector>
#include <utility>
#include <complex>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <deque>
#include <tuple>
#include <bitset>
#include <algorithm>
#include <random>
using namespace std;
typedef long double ld;
typedef long long ll;
typedef vector<int> vint;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<double, double> pdd;
typedef complex<ld> compd;
#define rep(i,n)	for(int i=0;i<n;i++)
#define srep(i,a,n)	for(int i=a;i<n;i++)
#define REP(i,n)	for(int i=0;i<=n;i++)
#define SREP(i,a,n)	for(int i=a;i<=n;i++)
#define rrep(i,n)	for(int i=n-1;i>=0;i--)
#define RREP(i,n)	for(int i=n;i>=0;i--)
#define all(a)	(a).begin(),(a).end()
#define mp(a,b)	make_pair(a,b)
#define mt	make_tuple
#define pb	push_back
#define fst	first
#define scn second
#define bicnt(x)	__buildin__popcount(x)
#define debug(x)	cout<<"debug: "<<x<<endl
#define DEBUG 0

const ll inf = (ll)1e9;
const ll mod = 998244353;
const ld eps = 1e-9;
const int dx[] = { 0,1,0,-1 };
const int dy[] = { 1,0,-1,0 };

int main() {
	string s;	cin >> s;
	srep(i, 1, s.size()) {
		if (s[i - 1] == 'A'&&s[i] == 'C') {
			cout << "Yes" << endl;
			return 0;
		}
	}
	cout << "No" << endl;
	return 0;
}

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

int main(){
	int n,d;
	cin >> n >> d;
	std::vector<vector<int>> x(n,vector<int>(d));
	rep(i,n) rep(j,d) cin >> x[i][j];

	int ans = 0;

	rep(i,n){
		FOR(j,i+1,n){
			int dist = 0;
			rep(k,d){
				dist += ((x[i][k]-x[j][k]) * (x[i][k] - x[j][k]));
			}
			rep(l,dist+1){
				if(l*l == dist){
					ans++;
					break;
				}
			}
		}
	}
	cout << ans << endl;
  return 0;
}


Measured memory_bytes: 256
import std.stdio, std.algorithm, std.conv, std.array, std.string, std.math, std.typecons, std.numeric, std.container, std.range;

void main()
{
    auto nm = readln.split.to!(int[]);
    auto N = nm[0];
    auto M = nm[1];
    auto G = new int[][N];
    auto RG = new int[][N];
    foreach (_; 0..M) {
        auto ab = readln.split.to!(int[]);
        auto A = ab[0]-1;
        auto B = ab[1]-1;
        G[A] ~= B;
        RG[B] ~= A;
    }

    foreach (n; 0..N) {
        auto memo = new bool[](N);
        int[] walk(int i, int p) {
            foreach (j; RG[i]) if (j != p && memo[j]) return [];
            int[] js;
            foreach (j; G[i]) if (memo[j]) js ~= j;
            if (js.length == 1) {
                return [js[0], i];
            } else if (js.length > 1) {
                return [];
            }
            foreach (j; G[i]) {
                memo[j] = true;
                auto r = walk(j, i);
                if (!r.empty) return r ~ i;
                memo[j] = false;
            }
            return [];
        }
        memo[n] = true;
        auto r = walk(n, -1);
        if (r.empty) continue;
        auto rr = [r[0]];
        foreach (p; r[1..$]) {
            if (p == rr[0]) break;
            rr ~= p;
        }
        if (!r.empty) {
            writeln(rr.length);
            foreach (p; rr) writeln(p + 1);
            return;
        }
    }
    writeln(-1);
}

Measured memory_bytes: 5680
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int N, x = 0;
  cin >> N;
  
  for (int i = 0; i < N; i++) {
    int l, r;
    cin >> l >> r;
    
    x = x + (r - l) + 1;
  }
  
  cout << x;
}

Measured memory_bytes: 256
#include <stdio.h>

int main() {
  int N = 0,X = 0,T = 0;
  int ans = 0;

  scanf("%d %d %d",&N,&X,&T);

  ans = T * ( (N / X) + ((N % X == 0)?0:1) );

  printf("%d\n",ans);


  return 0;
}

Measured memory_bytes: 1708
m = input().split()
N = int(m[0])
Y = int(m[1])
if Y > 10000*N:
  print(-1,-1,-1)
else:
  frag = 0
  for i in range(N+1):
    for j in range(N-i+1):
      if frag == 0 and 10000*i + 5000*j + 1000*(N-i-j) == Y:
        frag = 1
        print(i,j,N-i-j)
        break
  if frag == 0:
    print(-1,-1,-1)

Measured memory_bytes: 3064
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cctype>
#include <climits>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <deque>
#include <functional>
#include <fstream>
#include <iostream>
#include <iterator>
#include <limits>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>
#include <unordered_map>
#include <unordered_set>

using namespace std;

typedef vector<int> VI;
typedef vector<string> VS;
typedef pair<int,int> PI;
typedef vector<PI> VPI;
typedef unsigned long long ull;
typedef long long ll;

#define FOR(i, n) for(int i=0;i<(n);++i)
#define REP(i,s,n) for(int i=s;i<=n;++i)
#define SZ(x) ((int)(x).size())
#define LOOP(i,x) FOR(i,SZ(x))
#define IT(it,x) for(typeof((x).begin()) it = (x).begin();it!=(x).end();++it)
#define ALL(x) (x).begin(), (x).end()
#define ST first
#define ND second
#define MP make_pair
#define PB push_back
#define gc getchar

const int INF = 1e9 + 5;

#define MAXN 105

//int w[MAXN], v[MAXN];
//pair<int, long> dp[MAXN][2];

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

	int n, W;
	cin >> n >> W;

	vector<ll> dp(W + 1); // dp[i] is the maximum values of items with combined weight i

	for (int i = 0; i < n; i++) {
		int w, v;
		//cin >> w[i] >> v[i];
		cin >> w >> v;

		for (int weight_tillNow = W - w; weight_tillNow >= 0; weight_tillNow--) {
			dp[weight_tillNow + w] = max(dp[weight_tillNow + w], dp[weight_tillNow] + v);
		}
	}

	ll ans = 0;
	for (int i = 0; i <= W; i++) ans = max(ans, dp[i]);

	cout << ans << endl;

/*
	dp[0][0] = {0, 0};
	dp[0][1] = {w[0], v[0]};

	//cout << "not taking : " << dp[0][0].first << " " << dp[0][0].second << endl;
	//cout << "yes taking : " << dp[0][1].first << " " << dp[0][1].second << endl;

	for (int i = 1; i < n; i++) {
		dp[i][1] = {INF, -1};
		if (dp[i - 1][0].second >= dp[i - 1][1].second) {
			dp[i][0] = dp[i - 1][0];
			if (W >= (w[i] + dp[i - 1][0].first)) dp[i][1] = {w[i] + dp[i - 1][0].first, v[i] + dp[i - 1][0].second};
		} else {
			dp[i][0] = dp[i - 1][1];
			if (W >= (w[i] + dp[i - 1][1].first)) dp[i][1] = {w[i] + dp[i - 1][1].first, v[i] + dp[i - 1][1].second};
		}

		//cout << "not taking : " << dp[i][0].first << " " << dp[i][0].second << endl;
		//cout << "yes taking : " << dp[i][1].first << " " << dp[i][1].second << endl;
	}

	cout << max(dp[n - 1][0].second, dp[n - 1][1].second) << endl;
*/
	return 0;
}

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

ll n;
ll h[200200], a[200200], bit[200200];

ll maxi(ll i){
    ll res = 0;
    while(i>0){
        res = max(res,bit[i]);
        i -= i & -i;
    }
    return res;
}
void update(ll i, ll x){
    while(i<=n){
        bit[i] = max(bit[i],x);
        i += i & -i;
    }
}

int main(){
    cin >> n;
    rep(i,n) cin >> h[i];
    rep(i,n) cin >> a[i];

    rep(i,n) update(h[i], a[i] + maxi(h[i]));
    cout << maxi(n) << endl;
    return 0;
}

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

int main() {

    int n,x;
    cin >> x >> n ;
    unordered_set<int> v;
    for( int i = 0 ; i < n ; ++i) {
        int x;cin >> x ; v.insert(x) ;
    } 
    for ( int i = 0 ; ; ++i ) {
        if ( v.find(x-i)==v.end() ){
             cout << x-i << endl ;
             return 0 ;
        } 
        if ( v.find(x+i)==v.end() ){
             cout << x+i << endl ;
             return 0 ;
        } 
    } 

}

Measured memory_bytes: 3656
#include <bits/stdc++.h>
#define aaa cout<<233<<endl;
#define endl '\n'
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
// mt19937 rnd(TM(0));
const int inf = 0x3f3f3f3f;//1061109567 > 1e9
const ll linf = 0x3f3f3f3f3f3f3f3f;
const double eps = 1e-6;
const double pi = 3.14159265358979;
const int maxn = 2e5 + 5;
const int maxm = 5e5 + 233;
const int mod = 1e9 + 7;

ll n, k, a[maxn], f[maxn];
bool check(ll mid){
    ll kk = k;
    for(int i = 1; i <= n; ++i){
        if(a[i] * f[i] <= mid)continue;
        ll tmp = mid / f[i];
        // cout << tmp << " " << k << endl;
        if(kk >= a[i] - tmp){
            kk -= (a[i] - tmp);
        }
        else return false;
    }
    return true;
}
int main()
{
    // double pp = clock();
    // freopen("233.in", "r", stdin);
    // freopen("233.out", "w", stdout);
    ios_base::sync_with_stdio(0);
    cin.tie(0);cout.tie(0);
    
    cin >> n >> k;
    for(int i = 1; i <= n; ++i)cin >> a[i];
    for(int i = 1; i <= n; ++i)cin >> f[i];
    sort(a + 1, a + 1 + n, [](int i, int j){return i > j;});
    sort(f + 1, f + 1 + n);
    ll ans = a[1] * f[n];
    ll l = 0;
    ll r = ans;
    while(l <= r){
        ll mid = l + r >> 1;
        if(check(mid)){
            ans = mid;
            r = mid - 1;
        }
        else l = mid + 1;
    }
    cout << ans << endl;


    // cout << endl << (clock() - pp) / CLOCKS_PER_SEC << endl;
    return 0;
}

Measured memory_bytes: 3328
#include <bits/stdc++.h>
#define x first
#define y second
#define pb push_back
using namespace std;
typedef long long LL;
typedef pair<int, int> PII;
const double PI  = acos(-1.0);
const double eps = 1e-8;
const int inf = 0x3f3f3f3f;
const LL INF  = 0x3f3f3f3f3f3f3f3f;
const int N=1e6+10;
const int M=1e6+10;
const int mod=1e9+7;
inline LL gcd(LL a, LL b) { return b ? gcd(b, a % b) : a; }
inline LL lcm(LL a, LL b) { return a * b / gcd(a, b); }
inline LL read(){LL x=0,f=1;char c=getchar();while(c<'0'||c>'9') {if(c=='-')f=-1;c=getchar();}while(c>='0'&&c<='9') {x=x*10+c-'0';c=getchar();}return x*f;}
inline LL qpow(LL x,LL k=mod-2,LL m=mod){LL res=1;while(k){if(k&1) res=res*x%m;x=x*x%m;k>>=1;}return res;}
/*=================================================================================================================*/
LL fac[N]={1},p8[N]={1};

LL C(int n,int m){
    return fac[n]*qpow(fac[m])%mod*qpow(fac[n-m])%mod;
}

int main(){
    int n;cin>>n;
    if(n==1) return printf("0\n"),0;
    LL ans=1;
    for(int i=1;i<=n;i++) 
        ans=ans*10%mod,
        fac[i]=fac[i-1]*i%mod,
        p8[i]=p8[i-1]*8%mod;
    LL temp=0;
    for(int i=1;i<=n;i++){
        temp=(temp+C(n,i)*p8[n-i]%mod)%mod;
    }
    temp=temp*2%mod;
    ans=(ans-temp+mod)%mod;
    ans=(ans-p8[n]+mod)%mod;
    cout<<ans<<endl;
    return 0;
}


Measured memory_bytes: 19072
from collections import defaultdict

N, K = map(int, input().split())
TD = [tuple(map(int, input().split())) for _ in range(N)]
TD.sort(key=lambda A: A[1], reverse=True)

A = TD[:K][:: -1]
cnt = defaultdict(int)
V = set()
dSum = 0
for t, d in A:
    dSum += d
    cnt[t] += 1
    V.add(t)

i = 0
ans = dSum + len(V)**2
for t, d in TD[K:]:
    if not t in V:
        while i < K and cnt[A[i][0]] <= 1:
            i += 1
        if i == K:
            break

        dSum = dSum - A[i][1] + d
        V.add(t)
        cnt[A[i][0]] -= 1
        i += 1
        ans = max(ans, dSum + len(V)**2)

print(ans)


Measured memory_bytes: 25436
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.List;

public class Main {
	public static void main(String[] args) throws Exception {
		BufferedReader r = new BufferedReader(new InputStreamReader(System.in));
		int n = readInt(r);
		String[] numArrayStr = r.readLine().split(" ");

		List<Card> cardListBubble = makeCardList(numArrayStr);
		bubbleSort(cardListBubble);
		String[] cardArrayBubble = listToArray(cardListBubble);
		printBlank(cardArrayBubble);
		System.out.println("Stable");


		List<Card> cardListSlect = makeCardList(numArrayStr);
		selectSort(cardListSlect);
		String[] cardArraySlect = listToArray(cardListSlect);
		printBlank(cardArraySlect);

		if(compareAry(cardArrayBubble,cardArraySlect)){
			System.out.println("Stable");
		}else{
			System.out.println("Not stable");
		}
	}

	public static boolean compareAry(String[] cardArrayBubble,String[] cardArraySlect){
		for(int i = 0 ; i < cardArrayBubble.length; i++){
			if(!cardArrayBubble[i].equals(cardArraySlect[i])){
				return false;
			}
		}
		return true;
	}

	public static int readInt(BufferedReader r) throws Exception{
        return Integer.parseInt(r.readLine());
    }

	public static List<Card> makeCardList(String[] numArrayStr){
		List<Card> cardList = new ArrayList<>();
		for(int i = 0; i < numArrayStr.length; i++){
			Card card = new Card(numArrayStr[i].substring(0,1),
					Integer.parseInt(numArrayStr[i].substring(1)));
			cardList.add(card);
		}
		return cardList;
	}

	public static String[] listToArray(List<Card> cardList){
		String[] cardArray = new String[cardList.size()];
		for(int i = 0; i < cardList.size(); i++){
			cardArray[i] = cardList.get(i).c + String.valueOf(cardList.get(i).num);
		}
		return cardArray;
	}

	public static void printBlank(String[] numArrayStr){
		StringBuilder builder = new StringBuilder();
		for(int i = 0; i < numArrayStr.length; i++){
			builder.append(numArrayStr[i]);
			builder.append(" ");
		}

		System.out.println(builder.toString().trim());
	}


	public static void bubbleSort(List<Card> cardListBubble){
		boolean flag = true;
		while(flag){
			flag = false;
			for(int i = cardListBubble.size() - 1; i > 0 ; i-- ){
				if(cardListBubble.get(i).num < cardListBubble.get(i - 1).num){
					Card tempCard = cardListBubble.get(i);
					cardListBubble.set(i,cardListBubble.get(i - 1));
					cardListBubble.set(i - 1,tempCard);
					flag = true;
				}
			}
		}
	}

	public static void selectSort(List<Card> cardListSlect){
		for(int i = 0 ; i < cardListSlect.size(); i++){
			int miny = i;
			for(int y = i; y < cardListSlect.size() ; y++){
				if(cardListSlect.get(y).num < cardListSlect.get(miny).num){
					miny = y;
				}
			}
			if(miny != i){
				Card tempCard = cardListSlect.get(i);
				cardListSlect.set(i,cardListSlect.get(miny));
				cardListSlect.set(miny,tempCard);
			}
		}
	}


}

class Card{
	Card(String c,int num){
		this.c = c;
		this.num = num;
	}
	String c;
	int num;
}

Measured memory_bytes: 24428
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>
#include <climits>
#include <cstring>

#define rep(i, m, n) for(int i=int(m);i<int(n);i++)
#define all(c) begin(c),end(c)

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

//改造
typedef long long int ll;
using ll = long long int;
using ull = long long unsigned int;
using namespace std;
#define INF (1 << 30) - 1
#define INFl (ll)5e15
#define DEBUG 0 //デバッグする時1にしてね
#define dump(x)  cerr << #x << " = " << (x) << endl
#define MOD 1000000007


//ここから編集する
class Solve {
public:
    bool solve() {
        int N, M;
        cin >> N >> M;
        if (N == 0) return false;
        vector<ll> s(N), d(M);
        rep(i, 0, N) cin >> s[i];
        rep(i, 0, M) cin >> d[i];
        sort(all(d));

        vector<vector<ll>> dp(M + 1, vector<ll>(1 << N, INFl));
        vector<ll> sum_nukus(1 << N);

        for (int i = 0; i < 1 << N; ++i) {
            ll tmp = 0;
            dp[0][i] = 0;
            for (int j = 0; j < N; ++j) {
                if (i >> j & 1) tmp += s[j];
            }
            sum_nukus[i] = tmp;
        }


        for (int i = 0; i < M; ++i) {
            for (int bit = 0; bit < 1 << N; ++bit) {
                if (dp[i][bit] == INFl) continue;
                //なんにも使わない場合
                ll sum_nuku = sum_nukus[bit];
                ll tmp = dp[i][bit] + abs(sum_nuku - d[i]);
                chmin(dp[i + 1][bit], tmp);
            }
            for (int bit = 0; bit < 1 << N; ++bit) {
                for (int j = 0; j < N; ++j) {
                    int nbit = bit | (1 << j);
                    chmin(dp[i + 1][nbit], dp[i + 1][bit]);
                }
            }
        }

        ll ans = dp[M][(1 << N) - 1];
//        for (int bit = 0; bit < 1 << N; ++bit) {
//            chmin(ans, dp[M][bit]);
//        }
        cout << ans << endl;


        return true;
    }
};


int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(10);

    while (Solve().solve());
    return 0;

}



Measured memory_bytes: 29512
#include <stdio.h>
int main(void){
    int a,b,c,t;
    scanf("%d %d %d",&a,&b,&c);
    if(a>b){
     t=a;
     a=b;
     b=t;
    }if(b>c){
      t=b;
      b=c;
      c=t;
    }if(a>b){
      t=a;
      a=b;
      b=t;  
    }
    printf("%d %d %d\n",a,b,c);
    return 0;
}
 


Measured memory_bytes: 2116
def main():
    n = int(input()) 
    a = list() 
    a.append(list(map(int,input().split())))
    a.append(list(map(int,input().split())))
    a[1][0] += a[0][0] 
    for i in range(1,n):
        a[0][i] += a[0][i-1] 
        a[1][i] = max(a[1][i]+a[1][i-1] , a[1][i] + a[0][i] ) 
    print(a[1][n-1])

main()

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

int main(void)
{
    int n,k; cin>>n>>k;
    if(k==1) {cout<<0<<endl; return 0;}
    int cnt=n;
    for(int i=1;i<k;i++)
    {
        n--;
    }
    cout<<n-1<<endl;
     return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<algorithm>
#include<cmath>
#include<string>
using namespace std;
int main() {
	long long n, count = 0;
	cin >> n;
	vector<long long>l(n);
	for (long long i = 0; i < n; i++) {
		cin >> l[i];
	}
	sort(l.begin(), l.end());
	for (long long mid = n - 1; mid >= 0; mid--) {
		for (long long low = mid - 1; low >= 0; low--) {
			auto itr = lower_bound(l.begin(), l.end(), l[mid] + l[low]);
			long long ng = distance(itr, l.end());
			count += (n - 1 - mid) - ng;
		}
	}
	cout << count<< endl;

}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#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 REP(i, n) for(ll i = 0; i < (n); ++i)
#define REPR(i, n) for(ll i = n; i >= 0; i--)
#define FOREACH(x, a) for(auto &(x) : (a))
#define dump(x) cout << #x << " = " << (x) << endl;
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
using namespace std;
using ll = long long;
using P = pair<ll, ll>;

#define int long long

signed main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  int N;
  cin >> N;
  vector<int> a(3 * N);
  REP(i, 3 * N) cin >> a[i];
  sort(all(a));
  int ans = 0;
  REP(i, N) {
    int j = 3 * N - 2 - i * 2;
    ans += a[j];
  }
  cout << ans << endl;

  return 0;
}

Measured memory_bytes: 2560
#include<iostream>
#include<fstream>
#include<sstream>
#include<algorithm>
#include<cstdio>
#include<cassert>
#include<cmath>
#include<cstdlib>
#include<cstring>
#include<string>
#include<deque>
#include<queue>
#include<vector>
#include<list>
#include<map>
#include<set>
#include<bitset>
#include<stack> 
#include<iomanip>
#include<utility>
#include<functional>
using namespace std;
int n;
int par[100005];
int px[100005],py[100005];
pair<int,int> ex[100005],ey[100005];
long long ans;
int find(int x)
{
	if(par[x]==x)
		return x;
	else
		return par[x]=find(par[x]);
}
bool unite(int x,int y)
{
	x=find(x);
	y=find(y);
	if(x==y)
		return false;
	par[x]=y;
	return true;
}
int dist(int x,int y)
{
	return min(abs(px[x]-px[y]),abs(py[x]-py[y]));
}
int main()
{
	cin>>n;
	for(int i=0;i<n;i++)
	{
		cin>>px[i]>>py[i];
		par[i]=i;
		ex[i]=make_pair(px[i],i);
		ey[i]=make_pair(py[i],i);
	}
	sort(ex,ex+n);
	sort(ey,ey+n);
	set<pair<int,pair<int,int> > > s; 
	for(int i=0;i<n-1;i++)
	{
		s.insert(make_pair(dist(ex[i].second,ex[i+1].second),make_pair(ex[i].second,ex[i+1].second)));
		s.insert(make_pair(dist(ey[i].second,ey[i+1].second),make_pair(ey[i].second,ey[i+1].second)));
	}
	while(!s.empty())
	{
		pair<int,pair<int,int> > x=*s.begin();
		s.erase(x);
		int a=x.second.first;
		int b=x.second.second;
		ans+=(long long)unite(a,b)*(long long)dist(a,b);
	}
	cout<<ans;
	return 0;
}


Measured memory_bytes: 12416
def solve():
  N = int(input())
  
  activity = []
  for i in range(N):
    a, b, c = [int(j) for j in input().split()]
    activity.append((a, b, c))

  maximumHappiness = [[0 for i in range(3)] for j in range(N)]

  maximumHappiness[0][0] = activity[0][0]
  maximumHappiness[0][1] = activity[0][1]
  maximumHappiness[0][2] = activity[0][2]
  for i in range(1, N):
    maximumHappiness[i][0] = activity[i][0] + max(maximumHappiness[i - 1][1], maximumHappiness[i - 1][2])
    maximumHappiness[i][1] = activity[i][1] + max(maximumHappiness[i - 1][0], maximumHappiness[i - 1][2])
    maximumHappiness[i][2] = activity[i][2] + max(maximumHappiness[i - 1][0], maximumHappiness[i - 1][1])

  print(max(maximumHappiness[N - 1]))

solve()

Measured memory_bytes: 41792
MOD = 10 ** 9 + 7


def ok(last4):
    for i in range(4):
        t = list(last4)
        if i >= 1:
            t[i - 1], t[i] = t[i], t[i - 1]
        if 'AGC' in ''.join(t):
            return False
    return True


def dfs(cur, last3):
    if last3 in memo[cur]:
        return memo[cur][last3]
    if cur == N:
        return 1
    ret = 0
    for c in 'AGCT':
        if ok(last3 + c):
            ret = (ret + dfs(cur + 1, last3[1:] + c)) % MOD
    memo[cur][last3] = ret
    return ret


N = int(input())
memo = [{} for _ in range(N + 1)]

print(dfs(0, 'TTT'))
# print(memo)


Measured memory_bytes: 3848
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<unordered_map>
#include<cmath>
#include <bits/stdc++.h>

using namespace std;
using Graph = vector<vector<int>>;
typedef unsigned long long ll;
ll mod = (10e+8)+ 7;
	double ans = 0;
#define For(N,i) for(int i = 0; i < N; i++)


int main(){

	int N,K,R,S,P;
	string T;
	cin>>N>>K>>R>>S>>P;
	cin>>T;
	int f1 = 0;
	int f2 = 0;
	int f3 = 0;
	ll total = 0;
	for(int i = 0; i < N; i++){
		if(i < K){
			switch(T[i]){
				case 'r':total+=P;break;
				case 's':total+=R;break;
				case 'p':total+=S;break;
			}
		}
		else{
			switch(T[i]){
				case 'r':
				if(T[i-K] == 'r'){ 
					
						
						T[i] = 'a';
					
				}else{
					total+=P;
				}
				break;
				
				
				case 's':
				if(T[i-K] == 's'){ 
					
						
						T[i] = 'a';
					
				}else{
					total+=R;
				}
				break;
				
				
				case 'p':
				if(T[i-K] == 'p'){ 
					
						
						T[i] = 'a';
					
				}else{
					total+=S;
				}
				break;
			}
		}
	}



	cout<<total<<endl;

}

Measured memory_bytes: 512
#include <iostream>
#include <cmath>
#include <algorithm>
using namespace std;
#define EPS (1e-10)
#define equals(a, b) (fabs((a) - (b)) < EPS)

class Point {
    public:
    double x, y;

    Point(double x = 0, double y = 0): x(x), y(y) {}

    Point operator + (Point p) { return Point(x + p.x, y + p.y); }
    Point operator - (Point p) { return Point(x - p.x, y - p.y); }
    Point operator * (double a) { return Point(x * a, y * a); }
    Point operator / (double a) { return Point(x / a, y / a); }

    double norm() { return x * x + y * y; }
    double abs() { return sqrt(norm()); }

    bool operator < (const Point &p) const {
        return x != p.x ? x < p.x : y < p.y;
    }

    bool operator == (const Point &p) const {
        return fabs(x - p.x) < EPS && fabs(y - p.y) < EPS;
    }
};

struct Segment {
    Point p1, p2;
};

typedef Point Vector;
typedef Segment Line;

double dot(Vector a, Vector b) {
    return a.x * b.x + a.y * b.y;
}

double cross(Vector a, Vector b) {
    return a.x * b.y - a.y * b.x; 
}

bool isOrthogonal(Vector a, Vector b) {
    return equals(dot(a, b), 0.0);
}

bool isOrthogonal(Point a1, Point a2, Point b1, Point b2) {
    return isOrthogonal(a1 - a2, b1 - b2);
}

bool isOrthogonal(Segment s1, Segment s2) {
    return equals(dot(s1.p2 - s1.p1, s2.p2 - s2.p1), 0.0);
}

bool isParallel(Vector a, Vector b) {
    return equals(cross(a, b), 0.0);
}

bool isParallel(Point a1, Point a2, Point b1, Point b2) {
    return isParallel(a1 - a2, b1 - b2);
}

bool isParallel(Segment s1, Segment s2) {
    return equals(cross(s1.p2 - s1.p1, s2.p2 - s2.p1), 0.0);
}

int main()
{
    int q;
    double x1, x2, x3, x4, y1, y2, y3, y4;
    cin >> q;
    for (int i = 0; i != q; ++i)
    {
        cin >> x1 >> y1 >> x2 >> y2 >> x3 >> y3 >> x4 >> y4;
        Point p1 = Point(x1, y1);
        Point p2 = Point(x2, y2);
        Point p3 = Point(x3, y3);
        Point p4 = Point(x4, y4);
        if (isOrthogonal(p1, p2, p3, p4))
        {
            cout << 1 << endl;
        }
        else if (isParallel(p1, p2, p3, p4))
        {
            cout << 2 << endl;
        }
        else
        {
            cout << 0 << endl;
        }
    }
    return 0;
}


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



int main()
{
  int n, m, q;
  cin >> n >> m >> q;
  vector<vector<int>> train(n + 1, vector<int>(n + 1, 0));
  rep(i, m)
  {
    int l, r;
    cin >> l >> r;
    train[l][r]++;
  }
  vector<vector<int>> csum(n + 1, vector<int>(n + 1, 0));
  for (int i=1; i<=n; i++)
    for (int j=1; j<=n; j++)
      csum[i][j] = csum[i-1][j] + csum[i][j-1] - csum[i-1][j-1] + train[i][j];
  rep(i, q)
  {
    int l, r;
    cin >> l >> r;
    cout << csum[r][r] - csum[l-1][r] << endl;
  }
  return 0;
}

Measured memory_bytes: 2944
import java.util.Scanner;
 
class Main {
	int n;
	
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		Main m = new Main(sc);
		m.solve();
		sc.close();
	}
	Main(Scanner sc){
		n = sc.nextInt();
	}
	void solve(){
		boolean ans = false;
		flag:for(int i=0;i*4<=n;i++){
			for(int j=0;j*7<=n;j++){
				if(i*4+j*7==n){
					ans = true;
					break flag;
				}
			}
		}
		if(ans){
			System.out.println("Yes");
		} else {
			System.out.println("No");
		}
	}
}

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

#define ll long long
#define vvi vector<vector<int>>
#define vec vector
#define pq priority_queue
#define all(v) (v).begin(), (v).end()
#define uniqueV(x) sort(x.begin(), x.end()); x.erase(unique(x.begin(), x.end()), x.end());
#define rep(i, n) for (int (i) = (0); (i) < (n); ++(i))
#define repp(i, m, n) for (int (i) = (m); (i) < (n); ++(i))
#define debug(x) cerr << #x << ": " << x << endl;
#define debug2(x, y) cerr<<"("<<#x<<", "<<#y<<") = "<<"("<<x<<", "<<y<<")"<<endl;
#define debug3(x, y, z) cerr<<"("<<#x<<", "<<#y<<", "<<#z<<") = "<<"("<<x<<", "<<y<<", "<<z<<")"<<endl;
#define debugB(value, size) cerr<<#value<<": "<<bitset<size>(value) << endl;
#define line() cerr << "---------------" << endl;

const int dx[] = {1, -1, 0, 0};
const int dy[] = {0, 0, -1, 1};
const double PI = 3.14159265358979323846;

template<typename T>
void printA(vector<T> &printArray, char between = ' ') {
   int paSize = printArray.size();
   for (int i = 0; i < paSize; i++) { cerr << printArray[i] << between;}
   if (between != '\n') {cerr << endl;}
}

// ------------------------------------------------------------------------------------------

using pii = pair<int, int>;

int N;
pii p[555];
int M;

int main() {
   while (1) {
      cin >> N;
      if (N == 0) return 0;

      rep (i, N) {
         cin >> p[i].first >> p[i].second;
      }

      cin >> M;
      int x = 10, y = 10;
      rep (i, M) {
         char c; int d;
         cin >> c >> d;
         int dx = 0, dy = 0;
         if (c == 'N') dy = 1;
         if (c == 'S') dy = -1;
         if (c == 'W') dx = -1;
         if (c == 'E') dx = 1;
         while (d--) {
            x += dx, y += dy;
            rep (j, N) {
               if (p[j].first == x && p[j].second == y) p[j].first = -1, p[j].second = -1;
            }
         }
      }

      bool ok = true;
      rep (i, N) {
         if (p[i].first != -1 || p[i].second != -1) {
            ok = false;
         }
      }
      puts(ok ? "Yes" : "No");
   }

   return 0;
}


Measured memory_bytes: 2992
#include<bits/stdc++.h>
using namespace std;
typedef pair<int, int> PA;
typedef priority_queue<int> PQ;
typedef vector<int> VE;
#define int long long
#define INF 1000000009
#define mod 1000000007
#define pb push_back
#define MAXN 100005

int n, a[MAXN], ans, mi;

int gcd(int x, int y)
{
    if(x % y == 0){
        return y;
    }
    return gcd(y, x % y);
}

signed main()
{
    cin >> n;
    for(int i = 0; i < n; i++){
        cin >> a[i];
        a[i]--;
        ans += a[i];
    }
    cout << ans << endl;



    return 0;
}



Measured memory_bytes: 256
n,t = map(int,input().split())
ls = [list(map(int,input().split())) for i in range(n)]
ls1 = []
for i in range(n):
    if ls[i][1] <= t:
        ls1.append(ls[i][0])
if len(ls1) == 0:
    print("TLE")
else:
    print(min(ls1))

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

int main() {
  ll n;
  cin >> n;
  vector<string> s(n);
  for (int i = 0; i < n; i++)
    cin >> s[i];

  map<char, int> m;
  for (int i = 0; i < n; i++) {
    map<char, int> t;
    for (int j = 0; j < s[i].size(); j++) {
      if (i == 0 || m[s[i][j]] > 0) t[s[i][j]]++;
    }

    if (i == 0) {
      m = t;
      continue;
    }
    for (auto v : m) {
      if (t[v.first] == 0) {
        m.erase(v.first);
        continue;
      }
      if (v.second > t[v.first]) { m[v.first] = t[v.first]; }
    }
  }
  string ans = "";
  for (auto v : m) {
    for (int i = 0; i < v.second; i++)
      ans += v.first;
  }
  cout << ans << endl;
}

Measured memory_bytes: 256
from collections import deque
h,w = map(int,input().split())
maze = [['#'] * (w+2) for i in range(h+2)]
wall = 0
for i in range(1,h+1):
    s = input()
    for j in range(1,w+1):
        if s[j-1] == '#':
            wall += 1
        maze[i][j] = s[j-1]
queue = deque([[1,1]])
maze[1][1] = 0
while queue:
    x,y = queue.popleft()
    if [x,y] != [h,w]:
        for n,m in ([0,-1],[0,1],[-1,0],[1,0]):
            new_h,new_w = x+n,y+m
            if maze[new_h][new_w] == '.':
                maze[new_h][new_w] = maze[x][y] + 1
                queue.append([new_h,new_w])
            elif maze[new_h][new_w] != "#":
                maze[new_h][new_w] = min(maze[new_h][new_w],maze[x][y]+1)
            else:
                pass
if maze[h][w] == '.' or maze[h][w] == '#':
    print(-1)
else:
    print(h*w-(maze[h][w]+1)-wall)

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

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

ll MOD = 10e9 + 7;

int main() {
    int n;
    cin >> n;
    vector<int> p(n);
    REP(i, n) cin >> p[i];
    int counter = 0;
    for(int i=1; i<n-1; i++) {
        int min_v = min(min(p[i-1], p[i]), p[i+1]);
        int max_v = max(max(p[i-1], p[i]), p[i+1]);
        if (min_v != p[i] && max_v != p[i]) counter++;
    }
    cout << counter << endl;
    return 0;
}


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

int main(){
  string s;
  cin >> s;
  
  int sum = 0;
  for(int i = 0; i < s.size(); i++){
    sum += s[i] - '0';
  }
  if(stoi(s) % sum == 0){
    cout << "Yes" << endl;
  }
  else {
    cout << "No" << endl;
  }
}
  

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
using vi = vector<int>;
using mti = vector<vector<int>>;
using vl = vector<ll>;
using mtl = vector<vector<ll>>;
using pi = pair<int, int>;
using pl = pair<ll, ll>;
#define all(x) x.begin(),x.end()
#define rep(i,j,n) for (int i = j; i < (int)(n); i++)
#define _GLIBCXX_DEBUG
#define n_p(v) next_permutation(v.begin(),v.end())
#define to_ll(b) stoll(b)
#define MOD 1000000007
//name[i][j]-> vvl name(i,vl(j))
//map<int,int>mp

signed main(){
	int n; cin>>n;
	vl vec(n);
	map<ll,ll> mp;
	rep(i,0,n){
		ll a; cin>>a;
		vec[i]=a;
	}
	bool ok = true;
	for(ll i=n-2;i>=0;i--){
		if(vec[i]>vec[i+1]){
			if(vec[i]-vec[i+1]==1){
				vec[i]--;
			}
			else{
				ok=false;
			}
			//cout<<i;
		}
	}
	//rep(i,0,n) cout<<vec[i];
	//bool ok=true;
	if(ok) cout<<"Yes";
	else cout<<"No";
	
	return 0;
}

Measured memory_bytes: 1024
H,W,D=map(int,input().split());A=[list(map(int,input().split())) for _ in range(H)];Q=int(input());d=[0]*(H*W+1);g=[0]*(H*W+1)
for i in range(H):
  for j in range(W):d[A[i][j]]=[i,j]
for i in range(1,H*W-D+1):
  g[i+D]=abs(d[i+D][0]-d[i][0])+abs(d[i+D][1]-d[i][1])+g[i]
for q in range(Q):
  l,r=map(int,input().split());print(g[r]-g[l])

Measured memory_bytes: 63728
//#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
#define repd(i,a,b) for (int i=(a);i<(b);i++)
#define rep(i,n) repd(i,0,n)
typedef long long ll;
typedef long double lb;
#define int long long
#define double long double
#define endn "\n"
typedef pair<int,int> P;
template<class T> inline bool chmin(T& a, T b){if(a>b){a = b;return 1;}return 0;}
template<class T> inline bool chmax(T& a, T b){if(a<b){a = b;return 1;}return 0;}
const int MOD = 1000000007;
//const int MOD = 998244353;
template<class T> inline int add(T& a, T b, T M = MOD){a=(a+M)%M;b=(b+M)%M;a=(a+b)%M;return a;};
template<class T> inline int mul(T& a, T b, T M = MOD){if(a>=M)a%=M;if(b>=M)b%=M;a*=b;if(a>=M)a%=M;return a;};
const ll INF = 1e16;
const double EPS = 1e-10;
const double PI = 3.141592653589793;
const string abc="abcdefghijklmnopqrstuvwxyz";
const string ABC="ABCDEFGHIJKLMNOPQRSTUVWXYZ";
const pair<int,int> fd[] = {make_pair(1,0),make_pair(-1,0),make_pair(0,1),make_pair(0,-1)}; 

////////////////////////////////////////////////////////////////////
///////////////////////___modpow___////////////////////
ll modpow(ll a,  ll n, const ll &MOD = MOD){
  ll ret = n == 0 ? 1 : modpow(a, n/2, MOD);
  (ret *= ret) %= MOD;
  if(n%2)((ret *= a) %= MOD);
  return ret;
}
///////////////////////___modinv___////////////////////
ll modinv(ll d, const ll &MOD = MOD){
  return modpow(d, MOD-2, MOD);
}
////////////////////////////////////////////////////////////////////

int n;deque<P> ans;
signed main(){
  cin>>n;

  if(n % 2 == 1){
    repd(i,1,n){
      repd(j,i+1,n){
        if(i == j || i+j == n)continue;
        ans.push_back(P(i,j));
      }
    }
    repd(i,1,n){
      ans.push_back(P(i,n));
    }
  }else{
    repd(i,1,n+1){
      repd(j,i+1,n+1){
        if(i == j || i+j == n+1)continue;
        ans.push_back(P(i,j));
      }
    }
  }
  cout << ans.size() << endl;
  rep(i,ans.size()){
    cout << ans[i].first << " " << ans[i].second << endl;
  }
}


Measured memory_bytes: 384
using System;
using System.Linq;
using System.Collections.Generic;
using static System.Console;
using System.Text;
using System.IO;

namespace AOJ
{
    class Program
    {
        static public long[] Sarray() { return ReadLine().Split().Select(long.Parse).ToArray(); }
        static public List<long> Slist() { return ReadLine().Split().Select(long.Parse).ToList(); }
        static long cnt = 0;
        static void Main(string[] args)
        {
            var N = Sarray()[0];
            var Ai = Sarray();
            mergeSort(Ai, 0, (int)N);
            WriteLine(cnt);
        }
        static public void merge(long[] A, int left, int mid, int right)
        {
            var n1 = mid - left;
            var n2 = right - mid;
            var L = new long[n1 + 1];
            var R = new long[n2 + 1];
            for (var i = 0; i < n1; ++i)
            { L[i] = A[left + i]; }
            for (var i = 0; i < n2; ++i)
            { R[i] = A[mid + i]; }
            L[n1] = long.MaxValue;
            R[n2] = long.MaxValue;
            var im = 0;
            var jm = 0;
            for (var k = left; k < right; ++k)
            {
                if (L[im] <= R[jm])
                {
                    A[k] = L[im];
                    ++im;
                }
                else
                {
                    A[k] = R[jm];
                    cnt += mid + jm - k;
                    ++jm;
                }
            }
        }
        public static void mergeSort(long[] A, int left, int right)
        {
            if (left + 1 < right)
            {
                var mid = (left + right) / 2;
                mergeSort(A, left, mid);
                mergeSort(A, mid, right);
                merge(A, left, mid, right);
            }
        }
    }
}


Measured memory_bytes: 50804