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

typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
#define fi first
#define se second
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
const int INF = (1<<30) - 1;
const ll LINF = (1LL<<60) - 1;

int main(){
    int n;
    cin >> n;
    vector<int> d(n);
    for (int i = 0; i < n; ++i) {
        cin >> d[i];
    }
    sort(all(d));
    cout << d[n/2] - d[n/2-1] << endl;
}

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

using namespace std;
using ll = long long ;
const int INF = 1001001001;
const ll mx = 1e18;

bool is_product_overflow(ll a, ll b) {

	ll prod = a * b;
	
	return (prod / b != a);
}

int main() {

    ll n ;
    cin >> n;
    ll ans = 1 ;
    ll a[n] ;
    for(ll i=0;i<n;i++){
        cin >> a[i] ;
        if(a[i]==0){
        cout << 0 << endl ;
        return 0 ;
        }
    }

    for(ll i=0;i<n;i++){
        if(a[i]<=mx/ans){
            ans*=a[i] ;
        }else{
            cout << -1 << endl ;
            return 0 ;
        }
    }

    cout << ans << endl ;

    return 0 ;
}


Measured memory_bytes: 4404
#include<iostream>
#include<vector>
#include<map>
#include<set>
#include<string>
#include<utility>
#include<algorithm>
#include<cstdio>
#include<iomanip>
#include<queue>
#include<stack>

#define ll int64_t
#define Rep(i, n) for (ll i = 0; i < n; i++)

using namespace std;

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

    int K, X;
    cin >> K >> X;
    for (int i = X-K+1; i <= X+K-1; i++) {
        if (i != X-K+1) cout << " ";
        cout << i;
    }
    cout << endl;
    return 0;
}

Measured memory_bytes: 256
import java.util.Scanner

object Main {

  def main(args: Array[String]): Unit = {
    val p = (x: Int) => math.pow(x, 2)
    val sc = new Scanner(System.in)

    var xyz = List(sc.nextInt, sc.nextInt, sc.nextInt).sorted

    while (xyz != List(0, 0, 0)) {
      val List(a, b, c) = xyz
      val enterable = math.sqrt(p(a) + p(b)) / 2

      for (i <- 0 until sc.nextInt) {
        val n = sc.nextInt
        println(if (n > enterable) "OK" else "NA")
      }

      xyz = List(sc.nextInt, sc.nextInt, sc.nextInt).sorted
    }

    sc.close()
  }
}

Measured memory_bytes: 44864
N, W = map(int, input().split())
w0, v0 = map(int, input().split())
W0 = [0, v0]
W1, W2, W3 = [0], [0], [0]
for i in range(N-1):
    w, v = map(int, input().split())
    if w == w0:
        W0.append(v)
    elif w == w0 + 1:
        W1.append(v)
    elif w == w0 + 2:
        W2.append(v)
    else:
        W3.append(v)
W0.sort()
W1.sort()
W2.sort()
W3.sort()
for i in range(1, len(W0)):
    W0[i] += W0[i-1]
for i in range(1, len(W1)):
    W1[i] += W1[i-1]
for i in range(1, len(W2)):
    W2[i] += W2[i-1]
for i in range(1, len(W3)):
    W3[i] += W3[i-1]

MaxValue = 0
for i in range(len(W0)):
    for j in range(len(W1)):
        for k in range(len(W2)):
            for l in range(len(W3)):
                if w0*i + (w0+1)*j + (w0+2)*k + (w0+3)*l <= W:
                    Total = (W0[-1]-W0[-1-i]) + (W1[-1]-W1[-1-j]) + (W2[-1]-W2[-1-k]) + (W3[-1]-W3[-1-l])
                    MaxValue = max(MaxValue, Total)
print(MaxValue)

Measured memory_bytes: 3064
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <climits>
#include <cfloat>
#include <map>
#include <utility>
#include <set>
#include <iostream>
#include <memory>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <sstream>
#include <complex>
#include <stack>
#include <queue>
#include <cstring>
#include <sstream>
#include <cassert>
#include <list>
#include <fstream>
using namespace std;
static const double EPS = 1e-5;
typedef long long ll;
typedef pair<int,int> PI;
typedef vector<int> vi;
#ifndef M_PI
#define M_PI 3.14159265358979323846
#endif
#define rep(i,n) for(int i=0;i<(int)n;++i)
#define FOR(i,c) for(__typeof((c).begin())i=(c).begin();i!=(c).end();++i)
#define ALL(c) (c).begin(), (c).end()
#define mp(a,b) make_pair(a,b)
#define pb(a) push_back(a)
#define F first
#define S second


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



main(){
  int n,m,p;
  while(cin>>n>>m>>p,n|m|p){
    int sum=0,mt,t;
    rep(i,n){
      cin>>t;
      sum+=t;
      if(i+1==m)mt=t;
    }

    if(mt){
      printf("%d\n",(100-p)*sum/mt);
    }else cout<<0<<endl;
  }
}

Measured memory_bytes: 0
import java.util.PriorityQueue;
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner in = new Scanner(System.in);
		int n = in.nextInt(), k = in.nextInt();
//		int minus = 0;
//		int ideal = 0;
		int[] dq = new int[n];
		for ( int i = 0; i < n; i++ ) {
			int inp = in.nextInt();
			dq[i] = inp;
//			if ( inp < 0 ) minus++;
//			else ideal += inp;
		}
		in.close();

		// 全要素から自由に取捨選択できる場合
//		if ( n + minus <= k ) {
//			System.out.println(ideal);
//			return;
//		}

		int total = 0;
		for ( int l = 0; l < n; l++ ) {
			for ( int r = 0; r <= n - l; r++ ) {
				int lr = l + r;
				if ( lr > k || lr > n ) break;

				PriorityQueue<Integer> pool = new PriorityQueue<>();
				for ( int i = 0; i < l; i++ ) {
					pool.add(dq[i]);
				}
				for ( int i = n - 1; n - r <= i; i-- ) {
					pool.add(dq[i]);
				}
				
				for ( int i = k - lr; 0 < i; i-- ) {
					if(!pool.isEmpty() && pool.peek() < 0) {
						pool.poll();
					}else {
						break;
					}
				}

				int temp = 0;
				for ( Integer i : pool ) {
					temp += i;
				}
				
//				System.out.println("l:" + l + " r:" + r + "   temp:" + temp );
				total = Math.max(total, temp);
			}
		}
		
		System.out.println(total);
	}
}


Measured memory_bytes: 24532
/*****Be Name Khoda*****/

#include<bits/stdc++.h>
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>

#define F first
#define S second
#define Size(x) ((int)x.size())
#define All(x) x.begin() , x.end()
#define int long long

using namespace std;
using namespace __gnu_pbds;
template <typename T>
using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;

const int N = 2e5 + 10;

int n , a[N] , sum;

int32_t main()
{
	ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
	cin >> n;
	for(int i = 0; i < n; i++)
		cin >> a[i] , sum += a[i];
	int mn = 1e18 , x = 0;
	for(int i = 0; i < n - 1; i++)
		x += a[i] , mn = min(mn , abs(sum - 2 * x));
	cout << mn;
}

Measured memory_bytes: 1792
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<n;i++)
#define FOR(i,start,end) for(int i=start;i<=end;i++)
const int INF = 1001001001;
typedef long long ll;
const ll MOD=1000000007;
using namespace std;
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; }
template<class T>auto MAX(const T& a) { return *max_element(a.begin(),a.end()); }
template<class T>auto MIN(const T& a) { return *min_element(a.begin(),a.end()); }
template<class T, class U>U SUM(const T& a, const U& v) { return accumulate(a.begin(),a.end(), v); }
template<class T, class U>U COUNT(const T& a, const U& v) { return count(a.begin(),a.end(), v); }
template<class T, class U>int LOWER(const T& a, const U& v) { return lower_bound(a.begin(),a.end(), v) - a.begin(); }
template<class T, class U>int UPPER(const T& a, const U& v) { return upper_bound(a.begin(),a.end(), v) - a.begin(); }
int GCD(int a, int b) { return b ? GCD(b, a%b) : a; }
int LCM(int a, int b) { int g = GCD(a, b); return a / g * b; }

int main(void){
    // Your code here!
    int n; cin >> n;
    if(n%10 == 2 ||n%10 == 4||n%10 == 5||n%10 == 7||n%10 == 9){
        cout << "hon";
    } else if (n%10 == 0||n%10 == 1||n%10 == 6||n%10 == 8){
        cout << "pon";
    } else {
        cout << "bon";
    }
}


Measured memory_bytes: 3632
/// kAAzuki Hoshino
/*
#pragma comment(linker, "/stack:200000000")
#pragma GCC optimize("O3")
#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#pragma GCC optimize("unroll-loops")
*/
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
using namespace std;
#define int long long
typedef tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update>ordered_set;
typedef long double ld;
typedef vector<int> vi;
typedef pair<int,int> pi;
typedef vector<pi> vpi;
#define inf 1000000000
#define mod 1000000007
#define rep(i,a,b) for (int i = a; i <= b; i++)
#define rep1(i, a, b) for(int i =a; i >=b; i--)
#define dmp(x) cerr<<"line "<<__LINE__<<" "<<#x<<":"<<x<<endl
#define fs first
#define sc second
#define pb push_back
#define all(c) (c).begin(),(c).end()
#define mt make_tuple
template<class S,class T> ostream& operator<<(ostream& o,const pair<S,T> &p){
	return o<<"("<<p.fs<<","<<p.sc<<")";
}
template<class T> ostream& operator<<(ostream& o,const vector<T> &vc){
	o<<"{";
	for(const T& v:vc) o<<v<<",";
	o<<"}";
	return o;
}

int a,p;

signed main(){
ios::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
//freopen("input.txt", "r", stdin);
//freopen("output.txt", "w", stdout);

        cin >> a >> p;
        cout << ( 3*a +p )/2 << endl;


return 0;
}
///....


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ad(x) (((x - 1) ^ 1) + 1)

typedef long long ll;
const int N = 200054, M = N * 2, mod = 1000000007;

int n, E = 0, chksum;
int inv[N];
int to[M], first[N], next[M], deg[N];
int p[N], Cycu, Cycv;
int cnt = 0, o[N], id[N];
bool used[N];

void init() {
	int i;
	for (inv[1] = 1, i = 2; i < N; ++i) inv[i] = ll(mod - mod / i) * inv[mod % i] % mod;
}

inline void addedge(int u, int v) {
	to[++E] = v, next[E] = first[u], first[u] = E, ++deg[u];
	to[++E] = u, next[E] = first[v], first[v] = E, ++deg[v];
}

inline void __builtin_deledge(int u, int v) {
	if (to[first[u]] == v) first[u] = next[first[u]];
	else for (int i = first[u]; i; i = next[i])
		if (to[next[i]] == v) {next[i] = next[next[i]]; return;}
}

inline void deledge(int u, int v) {__builtin_deledge(u, v), __builtin_deledge(v, u);}

void dfs(int x, int px = 0) {
	int i, y; used[x] = true, chksum += 2 - deg[x];
	o[++cnt] = x, id[x] = cnt;
	for (i = first[x]; i; i = next[i])
		if (!used[y = to[i]]) dfs(y, x);
		else if ((y = to[i]) != px) Cycu = x, Cycv = y;
}

void dfs2(int x) {
	int i, y;
	for (i = first[x]; i; i = next[i])
		if ((y = to[i]) != p[x]) p[y] = x, dfs2(y);
}

namespace Topo {
	int p[N], fc[N], nc[N], prod;

	inline void link(int x, int px) {
		p[x] = px, nc[x] = fc[px], fc[px] = x;
	}

	int dfs(int x) {
		int y, sz = 1;
		for (y = fc[x]; y; y = nc[y]) sz += dfs(y);
		return prod = (ll)prod * inv[sz] % mod, sz;
	}

	int main() {
		int i, _; prod = 1;
		for (_ = 1; _ <= cnt; ++_) i = o[_], p[i] = fc[i] = 0;
		for (_ = 1; _ <= cnt; ++_) if (i = o[_], ::p[::p[i]] > i) link(i, ::p[i]);
		for (_ = 1; _ <= cnt; ++_) if (!p[i = o[_]]) dfs(i);
		return prod;
	}
}

int main() {
	int i, u, v, ans = 1, cur; init();
	scanf("%d", &n);
	for (i = n *= 2; i > 1; --i) ans = (ll)ans * i % mod;
	for (i = 0; i < n; ++i) scanf("%d%d", &u, &v), addedge(u, v + n / 2);
	for (i = 1; i <= n; ++i) if (!used[i]) {
		if (cnt = 0, dfs(i), chksum) return putchar(48), putchar(10), 0;
		deledge(Cycu, Cycv);
		p[Cycu] = Cycv, dfs2(Cycu), cur = Topo::main();
		p[Cycv] = Cycu, dfs2(Cycv), cur += Topo::main();
		ans = (ll)ans * cur % mod;
	}
	printf("%d\n", ans);
	return 0;
}

Measured memory_bytes: 12544
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<(n);i++)
#define sz(x) int(x.size())
#define pb push_back
#define eb emplace_back
using ll=long long;
using P = pair<int,int>;
using LP=pair<ll,int>;
#define chmax(x,y) x = max(x,y)
#define chmin(x,y) x = min(x,y)
const ll MOD=1000000007,MOD2=998244353;



int main() {
    int D;
    cin>>D;
    if(D==25)cout<<"Christmas"<<endl;
    if(D==24)cout<<"Christmas Eve"<<endl;
    if(D==23)cout<<"Christmas Eve Eve"<<endl;
    if(D==22)cout<<"Christmas Eve Eve Eve"<<endl;
}

Measured memory_bytes: 3588
#include <iostream>
#include <vector>
#include <algorithm>
#include <utility>
#include <cmath>
#include <numeric>
#include <string>

#define debug(s) cout << s << endl
#define debug1(s, t) cout << s << " " << t << endl

using namespace std;
using i64 = long long;

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

    int ans;
    switch (a + b)
    {
    case 3:
        ans = 3;
        break;
    case 4:
        ans = 2;
        break;
    case 5:
        ans = 1;
        break;
    default:
        break;
    }
    cout << ans << endl;

    return 0;
}

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

int main(void){
    int a, b;
    string s;
    cin >> a >> b >> s;

    for (int i = 0; i < a; i++){
       if (!(((s[i] - '0') <= 9)&&(((s[i] - '0') >= 0)))){
            cout << "No" << endl;
            return 0;
        }
    }

    if (s[a] != '-'){
        cout << "No" << endl;
        return 0;
    }
    for (int i = a+1; i < a+b+1; i++){
        if (!(((s[i] - '0') <= 9) && (((s[i] - '0') >= 0)))){
            cout << "No" << endl;
            return 0;
        }
    }

    cout << "Yes" << endl;
    return 0;
    }

Measured memory_bytes: 256
<?php

$sc = new Scanner();

$n = $sc->next();

$p = [];
for ($i = 0; $i < $n; $i++) {
    $p[] = $sc->nextInt();
}
rsort($p);
$p[0] = $p[0] / 2;

echo array_sum($p) . PHP_EOL;

class Scanner {
    private $arr = [];
    private $count = 0;
    private $pointer = 0;
    public function next() {
        if($this->pointer >= $this->count) {
            $str = trim(fgets(STDIN));
            $this->arr = explode(' ', $str);
            $this->count = count($this->arr);
            $this->pointer = 0;
        }
        $result = $this->arr[$this->pointer];
        $this->pointer++;
        return $result;
    }
    public function hasNext() {
        return $this->pointer < $this->count;
    }
    public function nextInt() {
        return (int)$this->next();
    }
    public function nextDouble() {
        return (double)$this->next();
    }
}


Measured memory_bytes: 4728
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#pragma GCC optimize("Ofast")
#pragma GCC optimize("no-stack-protector")
#pragma GCC optimize("unroll-loops")
#pragma GCC target("sse,sse2,sse3,ssse3,popcnt,abm,mmx,tune=native")
#pragma GCC optimize("fast-math")
#include <string>
#include <ctime>
#include <stack>
#include <set>
#include <stdio.h>
#include <locale>
#define y1 y3278
#define y2 y4368
#define y y4368232
#define x x43682322
#define ff first
#define ss second
#define pb push_back
#define all(a) a.begin(),a.end()
#define tm tm3278
#define left left3278
#define right right3278
typedef long long ll;
typedef long double ld;
using namespace std;
using namespace __gnu_cxx;
using namespace __gnu_pbds;
typedef tree <int, null_type, less <int>, rb_tree_tag, tree_order_statistics_node_update> indexed_set;
template <class T> using Pair_indexed_set = tree <T, null_type, less <T>, rb_tree_tag, tree_order_statistics_node_update>;
const long long INF = 2000000000000000000;
const long long Maxll = 9223372036854775807;
const long long MOD = 1000000000000037;
const long long q0 = 31;
const int differ = 'a' - 'A';
template <class T>
istream& operator >> (istream &in, vector <T> &a)
{
    for (T &i: a) in >> i;
    return in;
}
template <class T>
ostream& operator << (ostream &out, vector <T> &a)
{
    for (T &i: a) out << i << ' ';
    out << '\n';
    return out;
}
template <class T>
ostream& operator << (ostream &out, set <T> &a)
{
    //out << a.size() << '\n';
    for (T i: a) out << i << ' ';
    return out;
}
/// Actual code starts here
string str;

ll n, ans;

void PYPY()
{
    cin >> n;
    for (int i = 1;i<=n;i++)
        for (int j = 1;j <=n;j++)
            for (int k = 1;k <=n;k++)
                ans += __gcd(i,__gcd(j,k));
    cout << ans;
}

int main()
{
     ios::sync_with_stdio(0);
     cin.tie(0);
     cout.tie(0);
    ll t = 1;
    // cin >> t;
     while (t--)
         PYPY();
}


Measured memory_bytes: 3648
using namespace std;
#define _CRT_SECURE_NO_WARNINGS
#pragma target("avx")
#pragma optimize("O3")
#pragma optimize("unroll-loops")
#include<iostream>
#include<algorithm>
#include<ctime>
#include<vector>
#include<string>
#include<cmath>
#include<map>
#include<iomanip>
#include<numeric>
#include<queue>
#include<deque>
#include<cfloat>
#include<functional>
#include<tuple>
#include<math.h>
#include<bitset>
#include<stack>
#include<set>
#include<random>
#include<stdlib.h>
#define rip(i,n) for(ll i=0;i<n;i++)
#define Rip(i,n) for(ll i=1;i<n;i++)
#define all(V) V.begin(),V.end()
#define ll long long
#define ld long double
#define MOD 998244353
#define mod MOD
#define sec setprecision
constexpr double eps = 1e-9;
constexpr double PI = 3.141592653589793238462643383279;
ll gcd(ll a, ll b) {
	if (a % b == 0)	return(b);
	else return(gcd(b, a % b));
}
ll lcm(ll a, ll b)
{
	return a * b / gcd(a, b);
}
const int MAX = 510000;
long long fac[MAX], finv[MAX], inv[MAX];
void cominit() {
	fac[0] = fac[1] = 1;
	finv[0] = finv[1] = 1;
	inv[1] = 1;
	for (ll i = 2; i < MAX; i++) {
		fac[i] = fac[i - 1] * i % MOD;
		inv[i] = MOD - inv[MOD % i] * (MOD / i) % MOD;
		finv[i] = finv[i - 1] * inv[i] % MOD;
	}
}
vector<ll> soinnsuubunnkai(ll n) {
	vector<ll>a;
	while (n % 2 == 0) {
		a.push_back(2);
		n /= 2;
	}
	ll f = 3;
	while (f * f <= n) {
		if (n % f == 0) {
			a.push_back(f);
			n /= f;
		}
		else f += 2;
	}
	if (n != 1)
		a.push_back(n);
	return(a);
}
// 二項係数計算
long long com(ll n, ll k) {
	if (n < k) return 0;
	if (n < 0 || k < 0) return 0;
	return fac[n] * (finv[k] * finv[n - k] % mod) % mod;
}
ll pow(ll a, ll b) {
	a = a % mod;
	if (b == 0)return(1);
	else if (b % 2 == 0)return(pow((a * a) % mod, b / 2));
	else return(a * (pow(a, b - 1)));
}
void solve() {
	int r;
	cin >> r;
	cout << r * r << endl;
}
int main() {
	solve();
}

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

using namespace std;

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


const ll LongINF=1e13+7;
const int INF=1e9+7;
const int dx[]={0,1,0,-1};
const int dy[]={1,0,-1,0};

template<class T> inline bool chmin(T& a, T b) {if (a > b) {a = b;return true;}return false;}
template<class T> inline bool chmax(T& a, T b) {if (a < b) {a = b;return true;}return false;}
template <class T, class Y>T GCD(T a, Y b){if(a<b){int c=a;a=b;b=c;}if (a % b == 0){return b;}return GCD(b, a % b);}
void clear(queue<pair<int, int>> &q){queue<pair<int, int>> empty;swap(q, empty);} //queueの中身の型は適時変更を忘れない

#define REP(i,a,b) for(int i=(a);i<(b);i++)
#define rep(i,n) REP(i,0,n)
#define pb push_back
#define rv reverse
#define ALL(a) (a).begin(),(a).end()


int main(){
    string S;
    int Co=0;
    int N;
    cin>>N>>S;
    rep(i,N-2){
        string A=S.substr(i,3);
        if(A=="ABC")Co++;
    }
    cout<<Co<<endl;

    return 0;
}

//a=97,z=122

Measured memory_bytes: 256
#pragma GCC optimize("O3")
#pragma GCC optimize ("unroll-loops")
#pragma GCC target ("avx")
#include <bits/stdc++.h>
constexpr int INF = 2147483647;
constexpr long long int INF_LL = 9223372036854775807;
constexpr int MOD = 1000000007;
constexpr double PI = 3.14159265358979323846;
using namespace std;
typedef long long int ll;
typedef unsigned long long int ull;

struct edge {
	ll to;
	ll cost;
};

//トポソ
void toposo_(vector<vector<edge>>& g, vector<int>& used, vector<int>& l, int pos) {
	if (!used[pos]) {
		used[pos] = 1;
		for (int i = 0; i < g[pos].size(); i++) {
			toposo_(g, used, l, g[pos][i].to);
		}
		l.push_back(pos);
	}
}
vector<int> toposo(vector<vector<edge>>& g) {
	vector<int> u(g.size(), 0), ret;
	for (int i = 0; i < g.size(); i++)toposo_(g, u, ret, i);
	reverse(ret.begin(), ret.end());
	return ret;
}

int main() {
	int N, M;
	cin >> N >> M;
	vector<vector<edge>> g(N);
	vector<vector<int>> pars(N);
	for (int i = 0; i < N + M - 1; i++) {
		int u, v;
		cin >> u >> v;
		u--; v--;
		g[u].push_back({ v,1 });
		pars[v].push_back(u);
	}

	vector<int> a = toposo(g);
	vector<int> used(N, 0), ans(N);
	for (int i = 0; i < N; i++) {
		if (i == 0) {
			ans[a[i]] = -1;
			used[a[i]] = i+1;
		}
		else {
			ll t1, t2 = -1;
			for (int j = 0; j < pars[a[i]].size(); j++) {
				if (used[pars[a[i]][j]] != 0) {
					if (t2 < used[pars[a[i]][j]]) {
						t1 = pars[a[i]][j];
						t2 = used[pars[a[i]][j]];
					}
				}
			}
			ans[a[i]] = t1;
			used[a[i]] = i + 1;
		}
		//cout << a[i] << endl;
	}
	for (int i = 0; i < N; i++) {
		cout << ans[i] + 1 << endl;
	}
}

Measured memory_bytes: 14068
n = int(input())
str_a = ''.join(['{:060b}'.format(a) for a in map(int, input().split())])
mod = 10**9 + 7

rest = 0
for d in range(60):
  ones = str_a[59-d::60].count('1')
  rest = (rest + 2**d * ones * (n - ones)) % mod
    
print(rest)

Measured memory_bytes: 65752
#include<bits/stdc++.h>
using namespace std;
#define int long long int
int32_t main()
{
    string s;
    cin >> s;
    int n = s.length();
    string b =s.substr(0, s.length()/2);
    string c = s.substr((n+3)/2 - 1, s.length()/2);

    string rb = b;
    reverse(rb.begin(), rb.end());
    string rc = c;
    reverse(rc.begin(), rc.end());

    string rs = s;
    reverse(rs.begin(), rs.end());

    if(rb == b && rc == c && rs == s)
    {
        cout << "Yes" << endl;
    }
    else
    {
        cout << "No" << endl;
    }
    return 0;
}


Measured memory_bytes: 256
#include <stdio.h>
#include <cmath>
#include <algorithm>
#include <cfloat>
#include <stack>
#include <queue>
#include <vector>
#include <string>
#include <iostream>
#include <set>
#include <map>
#include <time.h>
typedef long long int ll;
typedef unsigned long long int ull;
#define BIG_NUM 2000000000
#define MOD 1000000007
#define EPS 0.000000001
using namespace std;
 
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(a*x,a*y); }
    Point operator / (double a){ return Point(x/a,y/a); }
 
    double abs(){ return sqrt(norm()); }
    double norm(){ return x*x + y*y; }
 
    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;
    }
};
 
typedef Point Vector;
typedef vector<Point> Polygon;
 
int num_point,Q;
 
double norm(Vector a){
    return a.x*a.x+a.y*a.y;
}
 
double abs(Vector a){
    return sqrt(norm(a));
}
 
double cross(Vector a,Vector b){
    return a.x*b.y-a.y*b.x;
}
 
double dot(Vector a,Vector b){
    return a.x*b.x + a.y*b.y;
}
 
Point calc_minus(Point a,Point b){
    Point ret;
 
    ret.x = a.x-b.x;
    ret.y = a.y-b.y;
 
    return ret;
}
 
/*
 * IN 2
 * ON 1
 * OUT 0
 *
 */
int contains(Polygon g,Point p){
    int n = g.size();
    bool x = false;
    for(int i = 0; i < n; i++){
        Point a = g[i]-p,b = g[(i+1)%n]-p;
        if(abs(cross(a,b)) < EPS && dot(a,b) < EPS)return 1;
        if(a.y > b.y)swap(a,b);
        if(a.y < EPS && EPS < b.y && cross(a,b) > EPS) x = !x;
    }
    return (x ? 2:0);
}
 
int main(){
 
    scanf("%d",&num_point);
    Polygon g;
 
    double x,y;
    for(int loop = 0; loop < num_point; loop++){
        scanf("%lf %lf",&x,&y);
        g.push_back(Point(x,y));
    }
 
    scanf("%d",&Q);
 
    for(int loop = 0; loop < Q; loop++){
        scanf("%lf %lf",&x,&y);
        printf("%d\n",contains(g,Point(x,y)));
    }
 
    return 0;
}


Measured memory_bytes: 3252
#include <iostream>

#include <vector>

#include <algorithm>

#include <sstream>

#include <string>

#include <cmath>

#include <list>

using namespace std;



template <typename T> class SegTree

{

public:

	int n;

	T T_max;

	vector<T> dat;

	SegTree(int n_, T t_max)

	{

		int n = 1;

		T_max = t_max;

		while (n < n_)n *= 2;

		for (int i = 0; i < 2 * n - 1; i++)dat.push_back(t_max);

	}

	void update(int k, T a)

	{

		k += n - 1;

		dat[k] = a;

		while (k > 0)

		{

			k = (k - 1) / 2;

			dat[k] = min(dat[k * 2 + 1], dat[k * 2 + 2]);

		}

	}



	//[a,b)

	T query(int a, int b)

	{

		return _query(a, b, 0, 0, n);

	}



private:

	T _query(int a, int b, int k, int l, int r)

	{

		if (r <= a || b <= l)return T_max;

		if (a <= l && r <= b)return dat[k];

		else

		{

			T vl = _query(a, b, k * 2 + 1, l, (l + r) / 2);

			T vr = _query(a, b, k * 2 + 2, (l + r) / 2, r);

			return min(vr, vl);

		}

	}

};

int hoge1(double a)
{
	if (35.50 > a)return 7;
	if (37.50 > a)return 6;
	if (40.00 > a)return 5;
	if (43.00 > a)return 4;
	if (50.00 > a)return 3;
	if (55.00 > a)return 2;
	if (70.00 > a)return 1;
	return 0;
}

int hoge2(double a)
{
	if (71.00 > a)return 7;
	if (77.00 > a)return 6;
	if (83.00 > a)return 5;
	if (89.00 > a)return 4;
	if (105.00 > a)return 3;
	if (116.00 > a)return 2;
	if (148.00 > a)return 1;
	return 0;
}

int main()
{
	double a, b;
	string ans[8] = {"NA", "E", "D", "C", "B", "A", "AA", "AAA"};
	while (cin >> a >> b)
	{
		cout << ans[min(hoge1(a), hoge2(b))] << endl;
	}
}

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

int main(){
	int n;
	cin >> n;
	vector<int> a(n);
	rep(i, n) cin >> a.at(i);

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

	cout << a.back()-a.at(0) << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <stack>
#include <cstdlib>
#include <cctype>
using namespace std;

stack <double> st;

double solve(char s){
    double a,b;
    b = st.top();
    st.pop();
    a = st.top();
    st.pop();
    if(s == '+') return (a+b);
    else if(s == '-') return (a-b);
    else if(s == '*') return (a*b);
    else if(s == '/') return (a/b);
    return 1;
}

int main(){
    int cnt = 0 ;
    char s[80];
    while(1){
    exit:
        cin >> s;
        cnt++;
        if(cin.eof()) break;
        if(getchar() == '\n'){
            if(cnt == 1){
                cout << s << endl;
                cnt = 0;
                goto exit;
            }
            st.push(solve(s[0]));
            printf("%.6f\n",st.top());
            st.pop();
            cnt = 0;
        }
        else if(!isalnum(s[0]) && !isalnum(s[1])) st.push(solve(s[0]));
        else st.push(atof(s));
    }
    return 0;
}

Measured memory_bytes: 1260
def main():
    n = int(input())

    sn = str(n)

    if sn[1] == sn[2]:
        if sn[0] == sn[1] or sn[1] == sn[3]:
            print('Yes')
        else:
            print('No')
    else:
        print('No')

if __name__ == '__main__':
    main()

Measured memory_bytes: 38384
// Contest: AtCoder Beginner Contest 175 (https://atcoder.jp/contests/abc175)
// Problem: B: Making Triangle (https://atcoder.jp/contests/abc175/tasks/abc175_b)


// region boilerplate
#include <algorithm>
#include <array>
#include <bitset>
#include <cassert>
#include <cmath>
#include <chrono>
#include <cstdint>
#include <deque>
#include <exception>
#include <forward_list>
#include <functional>
#include <initializer_list>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <limits>
#include <list>
#include <map>
#include <memory>
#include <numeric>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <string>
#include <tuple>
#include <type_traits>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>

#if __cplusplus >= 201703L
#   include <optional>
#   include <string_view>
#   include <variant>
#endif

using namespace std;

#if __cplusplus >= 201703L
#   define all(a)      begin(a),end(a)
#   define sz(x)       ((int)size(x))
#else
#   define all(a)      (a).begin(),(a).end()
#   define sz(x)       ((int)(x).size())
#endif

#define rep(a, b)      for(int a = 0; a < (b); ++a)
#define reps(a, b, c)  for(int a = (b); a < (c); ++a)
#define trav(a, b)     for(auto& a : b)

using ll = long long;
using ld = long double;
using u64 = uint64_t;
using u32 = uint32_t;

using pi = pair<int, int>;
using pl = pair<ll, ll>;
using vi = vector<int>;
using vl = vector<ll>;
using vvi = vector<vi>;
using vpi = vector<pi>;

#if __cplusplus >= 201703L
#   define MAYBE_UNUSED [[maybe_unused]]
#else
#   define MAYBE_UNUSED
#endif

MAYBE_UNUSED static constexpr int INF = (int)1e9 + 5;
MAYBE_UNUSED static constexpr ll INFL = (ll)1e18 + 5;
MAYBE_UNUSED static mt19937 rng((u32)chrono::duration_cast<chrono::nanoseconds>(chrono::high_resolution_clock::now().time_since_epoch()).count());
//endregion

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

    int n; cin >> n;
    vi a(n);
    trav(ai, a) cin >> ai;
    sort(all(a));

    int c = 0;
    rep(i, n) reps(j, i+1, n) reps(k, j+1, n)
        c += a[i] != a[j] && a[j] != a[k] && a[i] + a[j] > a[k];
    cout << c << '\n';

    return 0;
}


Measured memory_bytes: 3648
from math import (log, ceil)
N, K = map(int,input().split())
total = 0.0
for i in range(1,N+1):
    if i < K:
        a = ceil(log(K/i,2))
        total += 2.0**(-a)
    else:
        total += 1.0
print(total/N)


Measured memory_bytes: 2940
void main()
{
    long n = rdElem;

    Point[] p = n.rdCol!Point;
    Point q = Point(0, 0, 0);
    foreach (x; p)
    {
        Point diff = x - q;
        if (diff.t < diff.len || (diff.t & 1) != (diff.len & 1))
        {
            "No".writeln;
            return;
        }
        q = x;
    }

    "Yes".writeln;
}

struct Point
{
    long t, x, y;

    Point opBinary(string op)(Point that)
    if ((op == "+" || op == "-" || op == "*"))
    {
        return Point(this.t-that.t, this.x-that.x, this.y-that.y);
    }

    long len()
    {
        return this.x.abs + this.y.abs;
    }
}

enum long mod = 10^^9 + 7;
enum long inf = 1L << 60;

T rdElem(T = long)()
if (!is(T == struct))
{
    return readln.chomp.to!T;
}

alias rdStr = rdElem!string;
alias rdDchar = rdElem!(dchar[]);

T rdElem(T)()
if (is(T == struct))
{
    T result;
    string[] input = rdRow!string;
    assert(T.tupleof.length == input.length);
    foreach (i, ref x; result.tupleof)
    {
        x = input[i].to!(typeof(x));
    }
    return result;
}

T[] rdRow(T = long)()
{
    return readln.split.to!(T[]);
}

T[] rdCol(T = long)(long col)
{
    return iota(col).map!(x => rdElem!T).array;
}

T[][] rdMat(T = long)(long col)
{
    return iota(col).map!(x => rdRow!T).array;
}

void rdVals(T...)(ref T data)
{
    string[] input = rdRow!string;
    assert(data.length == input.length);
    foreach (i, ref x; data)
    {
        x = input[i].to!(typeof(x));
    }
}

void wrMat(T = long)(T[][] mat)
{
    foreach (row; mat)
    {
        foreach (j, compo; row)
        {
            compo.write;
            if (j == row.length - 1) writeln;
            else " ".write;
        }
    }
}

import std.stdio;
import std.string;
import std.array;
import std.conv;
import std.algorithm;
import std.range;
import std.math;
import std.numeric;
import std.traits;
import std.container;
import std.functional;
import std.typecons;
import std.ascii;
import std.uni;

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

#define ll long long 
#define pb push_back
#define mem0(a) memset(a,0,sizeof(a))
#define mem1(a) memset(a,-1,sizeof(a))
#define memf(a) memset(a,false,sizeof(a))
#define all(v) v.begin(),v.end()
#define sz(a) (ll)a.size()
#define F first
#define S second
#define INF 2000000000000000000
#define endl "\n"
#define _time_ 1.0 * clock() / CLOCKS_PER_SEC
#define popcount(x) __builtin_popcountll(x)
#define pll pair<ll,ll> 
#define ld long double

const int M=1000000007;
const int MM=998244353;
const long double PI = acos(-1);

ll power(ll b,ll e,ll m)
{
    if(e==0) return 1;
    if(e&1) return b*power(b*b%m,e/2,m)%m;
    return power(b*b%m,e/2,m);
}
ll power( ll b, ll e)
{
    if(e==0) return 1;
    if(e&1) return b*power(b*b,e/2);
    return power(b*b,e/2);
}
template<typename T, typename U> static inline void amin(T &x, U y){ if(y<x) x=y; }
template<typename T, typename U> static inline void amax(T &x, U y){ if(x<y) x=y; }
template<typename T, typename U> ostream& operator<<(ostream &os, const pair<T, U> &p)
{ 
    return os<<'('<<p.F<< ","<<p.S<<')'; 
}

#define NCR 
const int NC=100005,MOD=M;
ll inv[NC],fac_inv[NC],fac[NC];
void initialize()
{
    ll i;
    inv[1]=1;
    for(i=2;i<=NC-2;i++)
        inv[i]=(MOD-MOD/i)*inv[MOD%i]%MOD; 
    fac[0]=fac[1]=1;
    for(i=2;i<=NC-2;i++)
        fac[i]=i*fac[i-1]%MOD;
    fac_inv[0]=fac_inv[1]=1;
    for(i=2;i<=NC-2;i++)
        fac_inv[i]=inv[i]*fac_inv[i-1]%MOD;
}
ll ncr(ll n,ll r)
{
    if(n<r) return 0;
    return (fac[n]*fac_inv[r]%MOD)*fac_inv[n-r]%MOD;
}


int _runtimeTerror_()
{
    ll s;
    cin>>s;
    ll ans = 0;
    for(int i=1;i<=s;++i)
    {
        if(3*i>s)
            break;
        ll u = s-3*i;
        ans = (ans + ncr(u+i-1,i-1))%M;
    }
    cout<<ans<<"\n";
    return 0;
}

int main()
{
    ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
    #ifdef runSieve
        sieve();
    #endif
    #ifdef NCR
        initialize();
    #endif
    int TESTS=1;
    //cin>>TESTS;
    while(TESTS--)
        _runtimeTerror_();
    return 0;
}

Measured memory_bytes: 6000
from collections import Counter

n = int(input())
res_c = Counter(input())
for i in range(n-1):
    cur_c = Counter(input())
    new_c = {}
    for key,val in res_c.items():
        # print(key,val)
        new_c[key] = min(val,cur_c[key])
        res_c = new_c
# print(res_c)
s = []
for key,val in res_c.items():
    s.append(key*val)
s.sort()
print("".join(s))


Measured memory_bytes: 3316
#include <stdio.h>
#define REP(i, n) for (int i = 0; i < n; ++i)

int main() {
    int N, K, ans;
    scanf("%d %d", &N, &K);
    ans = K; N--; K--;
    REP(i,N) ans *= K;
    printf("%d\n", ans);
}

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

int main(){
  int a,b;
  cin >> a >> b;
  if(a - b*2 > 0) cout << a - b*2 << endl;
  else cout << 0 << endl;
} 


Measured memory_bytes: 256
#if __has_include("../library/Basic/Debug.hpp")

#include "../library/Basic/Debug.hpp"

#else

/* ----- Header Files ----- */
// IO
#include <cstdio>
#include <iomanip>
#include <ios>
#include <iostream>

// algorithm
#include <algorithm>
#include <cmath>
#include <numeric>

// container
#include <vector>
#include <string>
#include <tuple>
#include <complex>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <deque>
#include <bitset>

// others
#include <random>
#include <limits>
#include <functional>
#include <ctime>
#include <cassert>
#include <cstdint>


/* ----- Type Alias ----- */
using Bool = bool;
using Int = long long int;
using Real = long double;
using Char = char;
using String = std::string;
template <class T, class U>
using Pair = std::pair<T, U>;
template <class... Ts>
using Tuple = std::tuple<Ts...>;

template <class T>
using Vector = std::vector<T>;
template <size_t N>
using Bits = std::bitset<N>;
template <class T>
using Queue = std::queue<T>;
template <class T>
using Stack = std::stack<T>;
template <class T>
using Deque = std::deque<T>;

template <class T>
using MaxHeap = std::priority_queue<T>;
template <class T>
using MinHeap = std::priority_queue<T, std::vector<T>, std::greater<T>>;
template <class T>
using Set = std::set<T>;
template <class T, class U>
using Map = std::map<T, U>;

template <class T, class... Us>
using Func = std::function<T(Us...)>;

template <class T>
T genv(T v) { return v; }

template <class T, class... Ts>
auto genv(size_t l, Ts... ts) {
    return Vector<decltype(genv<T>(ts...))>(l, genv<T>(ts...));
}

template <class Cost = Int>
struct Edge {
    Int src, dst;
    Cost cost;
    Edge(Int src = -1, Int dst = -1, Cost cost = 1)
        : src(src), dst(dst), cost(cost){};

    bool operator<(const Edge<Cost>& e) const { return this->cost < e.cost; }
    bool operator>(const Edge<Cost>& e) const { return this->cost > e.cost; }
};

template <class Cost = Int>
using Edges = Vector<Edge<Cost>>;
template <class Cost = Int>
using Graph = Vector<Vector<Edge<Cost>>>;

#endif

/* ----- Misc ----- */
void fastio() {
    std::ios::sync_with_stdio(false);
    std::cin.tie(nullptr);
}

struct Fout {
    Int precision;
    Fout(Int precision) : precision(precision) {}
};
std::ostream& operator<<(std::ostream& os, const Fout& fio) {
    os << std::fixed << std::setprecision(fio.precision);
    return os;
}


/* ----- Constants ----- */
// constexpr Int INF = std::numeric_limits<Int>::max() / 3;
// constexpr Int MOD = 1000000007;
// constexpr Real PI = acos(-1);
// constexpr Real EPS = 1e-10;
// std::mt19937 mt(int(std::time(nullptr)));

int main() {
    Int n, a, b;
    std::cin >> n >> a >> b;
    std::cout << std::min(a * n, b) << std::endl;
    return 0;
}


Measured memory_bytes: 256
n,k = map(int,input().split())
a = list(map(int,input().split()))

def gcd(a, b):
    while b:
        a, b = b, a % b
    return a

if n == 1:
    gcd1 = a[0]
else:
    gcd1 = gcd(a[0], a[1])

    for i in range(2,n):
        gcd1 = gcd(gcd1,a[i])

if k > max(a):
    print('IMPOSSIBLE')
else:
    if k % gcd1 == 0:
        print('POSSIBLE')
    else:
        print('IMPOSSIBLE')


Measured memory_bytes: 14252
#define _CRT_SECURE_NO_WARNINGS
#include <cstdio>
#include <map>
#include <vector>
using namespace std;
int main() {
	int n;
	scanf("%d", &n);
	vector<int> A(n);
	map <int, long long> mp;
	for (int i = 0; i < n; i++) {
		scanf("%d",&A[i]);
		mp[A[i]]++;
	}
	long long v=0;
	for (auto a : mp) {
		a.second = a.second * (a.second - 1) / 2;
		v += a.second;
	}
	for (int i = 0; i < n; i++) {
		printf("%lld\n", v-mp[A[i]]+1);
	}
}


Measured memory_bytes: 11536
import fractions
a,b,c,d = map(int,input().split())
l = (c*d)//fractions.gcd(c,d)
#print(fractions.gcd(c,d))
num =(((a-1)//c)+(((a-1)//d))-((a-1)//l))
num2 =((b//c)+(b//d))-(b//l)
print(b-a-(num2-num)+1)

Measured memory_bytes: 10644
#include<iostream>
#include<cctype>

using namespace std;

int main()
{
	string s;
	int f=0;
	cin>>s;
	if (s[0]=='A')
	{
		if (isupper(s[1]))
			f+=2;
		for (int i=2;i<s.size()-1;i++)
		{
			if (s[i]=='C')
			{
				f++;
			}
			else if (isupper(s[i]))
				f+=2;
		}
		if (s[s.size()-1]=='C' && f)
			f++;
		else if (isupper(s[s.size()-1]))
			f+=2;
	}
	if (f==1)
		cout<<"AC"<<endl;
	else
		cout<<"WA"<<endl;
	return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
#include <stdlib.h>
#define num 100000
#define true 1
#define false 0

void isPrime();
int isCheck(int i,int j,int m,int a,int b);
int isbigger(int num1,int num2);
int is1(int i,int j);
int N;
int *prime;

int main(){
  prime = (int *)malloc(num);
  isPrime();
  int m,a,b;
  int i,j,x,y;
  while(scanf("%d %d %d",&m,&a,&b ),(m&&a&&b)){
    int max=0;
    for(i=0;i<N;i++){
      for(j=0;j<N;j++){
        if(isCheck(i,j,m,a,b)) break;
        if(isbigger(max,prime[i]*prime[j])&&is1(i,j)) {
          max = prime[i]*prime[j];
          x = i;
          y = j;
        }
      }
    }
    printf("%d %d\n",prime[x],prime[y] );
  }

  free(prime);
  exit(0);
}

void isPrime(){
  int i,index=0;

  for (int j = 2;j < num;j++){
    for (i = 2;i < j;++i){
      if (j % i == 0){
        break;
      }
    }
    if (j == i){
      *(prime+index) = j;
      index++;
    }
  }
  N = index;
}

int isCheck(int i,int j,int m,int a,int b){
  double min = (double)a/b;
  double real = (double)prime[i]/prime[j];
  int pq = prime[i]*prime[j];
  if(min<=real&&pq<=m)  return false;
  return true;
}

int is1(int i,int j){
  double real = (double)prime[i]/prime[j];
  if (real<=1.0) return true;
  return false;
}

int isbigger(int num1,int num2){
  if (num1 >= num2){
    return false;
  }
  return true;
}



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

template<class T> long long largest_rectangle (vector<T> a) {
    a.emplace_back(0);
    int n = a.size(); T ret = 0;
    stack<pair<T, int>> sta;
    for (int i = 0; i < n; i++) {
        if (sta.empty()) sta.emplace(a[i], i);
        else if (sta.top().first < a[i]) sta.emplace(a[i], i);
        else if (sta.top().first > a[i]) {
            int idx = i;
            while (!sta.empty()) {
                if (sta.top().first < a[i]) break;
                T h; int t; tie(h, t) = sta.top(); sta.pop();
                T s = h * (i - t); idx = t;
                if (ret < s) ret = s;
            }
            sta.emplace(a[i], idx);
        }
    }
    return ret;
}

int main() {
    int n;
    cin >> n;
    vector<long long> a(n);
    for (auto &e : a) cin >> e;

    cout << largest_rectangle(a) << '\n';

    return 0;
}


Measured memory_bytes: 6072
N, K = map(int, input().split())
A = list(map(int, input().split()))

b = [0] * 40
for i in range(40):
    for k in A:
        b[i] += (k & (1 << i)) >> i

c = [0] * 40
for i in range(39):
    if b[i] > N - b[i]:
        c[i + 1] = c[i] + (b[i] << i)
    else:
        c[i + 1] = c[i] + (N - b[i] << i)

ans = 0
cnt = 0
for i in reversed(range(40)):
    if K & (1 << i):
        ans = max(ans, cnt + (b[i] << i) + c[i])
        cnt += N - b[i] << i
    else:
        cnt += b[i] << i
print(max(ans, cnt))


Measured memory_bytes: 69008
#include <bits/stdc++.h>
#define N 1000005
#define ll long long int 	
#define MP make_pair
#define pb push_back
#define ppb pop_back
#define sp " "
#define endl "\n"
#define fi first
#define se second
#define ii pair<int,int>
#define lli pair<ll,ll>
#define fast cin.tie(0);cout.tie(0);ios_base::sync_with_stdio(false)
#define fast2 freopen ("kmp.gir","r",stdin);freopen ("kmp.cik","w",stdout);
#define mod 1000000009
#define fs(x,y) for(int i=1;i<=y;i++) cin>>x[i]
#define fo(i,x,y) for(int i=x;i<=y;i++)
using namespace std;

ll n,m,ar[N],sum=INT_MAX,a,b,tut[N];

int main()
{
	fast;
	cin>>a>>b;
	if(b-a>=2019)
		return cout<<0,0;
	fo(i,a,b)
		tut[i%2019]=1;
	fo(i,0,2018)
		fo(j,i+1,2018)
			if(tut[i] && tut[j])
			{
				sum=min(sum,(ll)(i*j)%2019);

			}
	cout<<sum;
}



/*     cd onedrive\desktop\kod
cls


*/

Measured memory_bytes: 2304
/*
これを入れて実行
g++ code.cpp
./a.out
 */

#include <iostream>
#include <vector>
#include <string>
#include <queue>
#include <deque>
#include <algorithm>
#include <utility>
#include <set>
#include <map>
#include <cmath>
#include <math.h>
#include <tuple>
#include <iomanip>

using namespace std;
typedef long long ll;
typedef long double ld;

int dy4[4] = {-1, 0, +1, 0};
int dx4[4] = {0, +1, 0, -1};
int dy8[8] = {-1, -1, 0, 1, 1, 1, 0, -1};
int dx8[8] = {0, 1, 1, 1, 0, -1, -1, -1};

const long long INF = 1LL << 60;
const ll MOD = 1e9 + 7;

bool greaterSecond(const pair<int, int>& f, const pair<int, int>& s){
    return f.second > s.second;
}

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

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

ll nCr(ll n, ll r){
    if(r == 0 || r == n){
        return 1;
    } else if(r == 1){
        return n;
    }
    return (nCr(n - 1, r) + nCr(n - 1, r - 1));
}

ll nPr(ll n, ll r){
    r = n - r;
    ll ret = 1;
    for (ll i = n; i >= r + 1; i--) ret *= i;
    return ret;
}

//-----------------------ここから-----------

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

    vector<ll> a(n * 3);

    for(int i = 0; i < n * 3; i++) cin >> a[i];

    priority_queue<ll, vector<ll>, greater<ll>> f;
    ll ftotal = 0;
    for(int i = 0; i < n; i++){
        f.push(a[i]);
        ftotal += a[i];
    }

    vector<ll> fsum;

    fsum.push_back(ftotal);

    for(int i = n; i < n * 2; i++){
        f.push(a[i]);
        ftotal += a[i];
        ftotal -= f.top();
        f.pop();
        fsum.push_back(ftotal);
    }

    priority_queue<ll, vector<ll>, less<ll>> b;
    ll btotal = 0;
    for(int i = 2 * n; i < 3 * n; i++){
        b.push(a[i]);
        btotal += a[i];
    }

    vector<ll> bsum;

    bsum.push_back(btotal);
    for(int i = n * 2 - 1; i >= n; i--){
        b.push(a[i]);
        btotal += a[i];
        btotal -= b.top();
        b.pop();
        bsum.push_back(btotal);
    }

    reverse(bsum.begin(), bsum.end());

    ll ans = -INF;
    for(int i = 0; i < fsum.size(); i++){
        // cout << fsum[i] - bsum[i] << endl;
        ans = max(ans, fsum[i] - bsum[i]);
    }

    cout << ans << endl;


}


Measured memory_bytes: 6516
#include <bits/stdc++.h>
#define chmin(a, b) ((a) = min((a), (b)))
#define chmax(a, b) ((a) = max((a), (b)))
using namespace std;

using ll = long long;
using P = pair<int, int>;

const int MOD = 1e9 + 7;
const ll INF = 1e18;
const double pi = acos(-1);
const double eps = 1e-10;

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

ll modpow(ll a, ll b){
    if(b == 0) return 1;
    else if(b % 2 == 0){
        ll d = modpow(a, b/2) % MOD;
        return (d * d) % MOD;
    }
    else{
        return (a * modpow(a, b-1)) % MOD;
    }
}

const int MAX_N = 2010;

ll fact[MAX_N], finv[MAX_N];
ll comb(int n, int r){
    if(n < r || r < 0) return 0;
    return fact[n] * finv[n-r] % MOD * finv[r] % MOD;
}

void calc(int n){
    fact[0] = finv[0] = 1;
    for(int i=1; i<=n; i++){
        fact[i] = (fact[i-1] * i) % MOD;
        finv[i] = modpow(fact[i], MOD-2);
    }
}

int main(){
    ll n, k; cin>>n>>k;

    calc(2000);

    for(int i=1; i<=k; i++){
        ll ans = comb(n - k + 1, i) * comb(k - 1, i - 1);
        cout << ans % MOD << endl;
    }
}

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

int main()
{
    char s[105];
    scanf("%s", &s);
    int l = strlen(s), i, j, cnt = 0;
    for(i = 0, j = (l-1); i < (l/2); i++, j--) {
        if(s[i] != s[j]) {
            cnt = cnt + 1;
        }
    }
    printf("%d\n", cnt);
    return 0;
}


Measured memory_bytes: 128
#include <stdio.h>
#include <iostream>
#include <algorithm>
#include <string>
#include <iomanip>
#include <math.h>
#include <utility>
#include <vector>
#include <map>
#include <cstdlib>
#define div1 1000000007
const long long INF = 1LL << 60;
using namespace std;
// a>b -> a==b;
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
// a<b -> a==b;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }

int main(void)
{
    string s;

    cin >> s;

    if(s.size() == 2){
        cout << s << endl;
    }

    else{
        cout << s[2] << s[1] << s[0] << endl;
    }

    return 0;
}

Measured memory_bytes: 256
n,k,q = list(map(int,input().split()))
xs = [0]*n

for i in range(q):
  qi = int(input())
  xs[qi-1] += 1

#print(xs)  

for i in range(n):
  minus = q - xs[i]
  #print(k, xs[i], minus)
  if k - minus > 0:
    print("Yes")
  else:
    print("No")

Measured memory_bytes: 4680
#from statistics import median
#import collections
#aa = collections.Counter(a) # list to list
#from itertools import combinations # (string,3) 3回

mod = 10**9 + 7

def readInts():
  return list(map(int,input().split()))
def main():
    # S: azzel
    # T: apple
    S = input()
    T = input()
    ok = True
    dic_s = {}
    dic_t = {}
    for i in range(len(S)):
        s = S[i]
        t = T[i]
        if s in dic_s.keys():
            if dic_s[s] != t:
                ok = False
        if t in dic_t.keys():
            if dic_t[t] != s:
                ok = False
        dic_s[s] = t
        dic_t[t] = s
        #print(dic_s,dic_t,sep='\n')
    if ok:
        print('Yes')
    else:
        print('No')



if __name__ == '__main__':
  main()


Measured memory_bytes: 3632