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

int N, M;
vector<int> A(100001);
vector<int> B(100001);

void solve(){
    vector<pair<int, int>> p(N + 1);
    for(int i = 1; i <= N; ++i){
        p[i] = make_pair(A[i], B[i]);
    }
    sort(p.begin() + 1, p.end());

    int ans = 0;
    priority_queue<int, vector<int>, less<int>> q;
    int k = 1;
    for(int i = 1; i <= M; ++i){
        int j = k;
        while(j <= N && p[j].first == i){
            q.push(p[j].second);
            j++;
        }
        k = j;
        if(!q.empty()){
            ans += q.top();
            q.pop();
        }
    }
    cout << ans;
}
int main(){
    cin >> N >> M;
    for(int i = 1; i <= N; ++i){
        cin >> A[i] >> B[i];
    }
    solve();
    return 0;
}

Measured memory_bytes: 2428
#include <cstdio>
#include <vector>
#include <map>
#include <algorithm>

using namespace std;

namespace SCC {
	const vector<vector<size_t>> *map, *revMap;
	vector<size_t> parent, topological;
	vector<bool> visit;
	size_t n, current;

	size_t find(size_t p) {
		size_t &q = parent[p];
		if (p == q) return p;
		return q = find(q);
	}

	inline void merge(size_t p, size_t q) {
		p = find(p);
		q = find(q);
		parent[q] = p;
	}

	inline void init(const size_t len) {
		parent.resize(len);
		for (size_t i = 0; i < len; i++) parent[i] = i;
	}

	void topologicalSort(size_t idx) {
		if (visit[idx]) return;
		visit[idx] = true;

		for (auto v : map->at(idx)) topologicalSort(v);

		topological.emplace_back(idx);
	}

	void getSCC(size_t idx) {
		if (visit[idx]) return;
		visit[idx] = true;

		for (auto v : revMap->at(idx)) getSCC(v);
		merge(current, idx);
	}

	vector<size_t>& SCC(const vector<vector<size_t>> &m, const vector<vector<size_t>> &revM) {
		map = &m;
		revMap = &revM;
		n = m.size();
		init(n);

		topological.clear();
		visit.resize(n);

		fill(visit.begin(), visit.end(), false);
		for (size_t i = 0; i < n; i++) topologicalSort(i);

		fill(visit.begin(), visit.end(), false);
		for (auto i = topological.rbegin(); i != topological.rend(); i++) {
			current = *i;
			getSCC(*i);
		}
		for (size_t i = 0; i < n; i++) find(i);

		return parent;
	}
}

int main() {
	vector<vector<size_t>> inM, outM;
	size_t n, m, a, b;
	scanf("%zd%zd", &n, &m);
	inM.resize(n);
	outM.resize(n);

	while (m--) {
		scanf("%zd%zd", &a, &b);
		inM[b].emplace_back(a);
		outM[a].emplace_back(b);
	}

	SCC::SCC(inM, outM);
	scanf("%zd", &m);
	while (m--) {
		scanf("%zd%zd", &a, &b);
		puts(SCC::parent[a] == SCC::parent[b] ? "1" : "0");
	}

	/*
	map<size_t, vector<size_t>> s;
	SCC::SCC(inM, outM);
	for (size_t i = 0; i < n; i++) {
		s[SCC::parent[i]].emplace_back(i);
	}
	printf("%zd\n", s.size());
	for (auto &v : s) {
		for (auto t : v.second) printf("%zd ", ++t);
		puts("-1");
	}
	*/
}

Measured memory_bytes: 3976
def B_OneClue():
    K, X = map(int, input().split())
    point_min = max(X - K +1,  -1000000)
    point_max = min(X + K - 1, 1000000)
    for x in range(point_max - point_min + 1):
        print(x + point_min, end=" ")
    
if __name__ == "__main__":
    B_OneClue()

Measured memory_bytes: 3060
import java.util.*;

class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		int[] A = new int[N];
		int[] B = new int[N];
		for (int i=0;i<N;i++) {
			A[i] = Integer.parseInt(sc.next());
			B[i] = A[i];
		}
		Arrays.sort(A);
		int swap = 0;
		for (int i=0;i<N;i++) {
			if (A[i] != B[i]) {
				swap++;
			}
		}
		if (swap<=2) {
			System.out.println("YES");
		} else {
			System.out.println("NO");
		}
	}
}

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


void solve(long long sx, long long sy, long long tx, long long ty){
    string res;
    tx = tx - sx;
    ty = ty - sy;
    for (int i = 0; i < tx; i++) {
	res.push_back('R');
    }
    for (int i = 0; i < ty; i++) {
	res.push_back('U');
    }
    for (int i = 0; i < tx; i++) {
	res.push_back('L');
    }
    for (int i = 0; i < ty; i++) {
	res.push_back('D');
    }

    res.push_back('L');
    for (int i = 0; i <= ty; i++) {
	res.push_back('U');
    }
    for (int i = 0; i <= tx; i++) {
	res.push_back('R');
    }
    res.push_back('D');

    res.push_back('R');
    for (int i = 0; i <= ty; i++) {
	res.push_back('D');
    }
    for (int i = 0; i <= tx; i++) {
	res.push_back('L');
    }
    res.push_back('U');

    cout << res << endl;
    
}

// Generated by 1.1.5 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
int main(){
    long long sx;
    scanf("%lld",&sx);
    long long sy;
    scanf("%lld",&sy);
    long long tx;
    scanf("%lld",&tx);
    long long ty;
    scanf("%lld",&ty);
    solve(sx, sy, tx, ty);
    return 0;
}


Measured memory_bytes: 256
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;


namespace abc167_c
{
    class Program
    {
        static void Main(string[] args)
        {
            var N = CIn.ReadInt();
            var M = CIn.ReadInt();
            var X = CIn.ReadInt();
            var C = new int[N];
            var A = new int[N,M];
            var ans = 1000000000000000;
            for(var i = 0; i < N; i++)
            {
                C[i] = CIn.ReadInt();
                for (var j = 0; j < M; j++)
                {
                    A[i, j] = CIn.ReadInt();                  
                }
            }
            for (int bit = 0; bit < Math.Pow(2, N); bit++)
            {
                var sum1 = 0;
                var sum2 = new int[M];
                for (int k = 0; k < N; k++)
                {
                    if (((bit >> k) & 1) == 1)
                    {
                        sum1 = sum1 + C[k];
                        for (int l = 0; l < M; l++)
                        {
                            sum2[l] = sum2[l] + A[k,l];                           
                        } 
                    }
                }
                if (sum2.All(e => e >= X))
                {
                    ans = Math.Min(ans, sum1);
                }
            }
            if(ans < 1000000000000000)
            {
                Console.WriteLine(ans);
            }
            else
            {
                Console.WriteLine(-1);
            }
        }
    }
    class CIn
    {
        private static readonly Queue<string> fieldBuffer = new Queue<string>();

        public static string Read()
        {
            if (fieldBuffer.Count == 0)
            {
                foreach (var field in Console.ReadLine().Split())
                {
                    fieldBuffer.Enqueue(field);
                }
            }

            return fieldBuffer.Dequeue();
        }

        public static int ReadInt() =>  int.Parse(Read());
        public static long ReadLong() => long.Parse(Read());
        public static double ReadDouble() => double.Parse(Read());

        public static string[] ReadStringArray(long n)
        {
            var array = new string[n];

            for (var i = 0; i < n; i++)
            {
                array[i] = Read();
            }

            return array;
        }

        public static int[] ReadIntArray(long n)
        {
            var array = new int[n];

            for (var i = 0; i < n; i++)
            {
                array[i] = ReadInt();
            }

            return array;
        }

        public static long[] ReadLongArray(long n)
        {
            var array = new long[n];

            for (var i = 0; i < n; i++)
            {
                array[i] = ReadLong();
            }

            return array;
        }
        public static double[] ReadDoubleArray(long n)
        {
            var array = new double[n];

            for (var i = 0; i < n; i++)
            {
                array[i] = ReadDouble();
            }

            return array;
        }
    }

}


Measured memory_bytes: 28788
import java.util.Scanner;
import java.util.stream.IntStream;

public class Main {

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

        int n = scanner.nextInt();
        int k = scanner.nextInt();
        int[] w = new int[n];
        for (int i = 0; i < n; i++) w[i] = scanner.nextInt();

        int sum = IntStream.of(w).sum();

        long left = 0;
        long right = IntStream.of(w).sum() + 1;
        long result = -1;
        while (left < right) {
            long mid = (left + right) / 2;
            if (check(w,  k,  mid)) {
                result = mid;
                right = mid;
            } else {
                left = mid + 1;
            }
        }

        System.out.println(result);
    }

    private static boolean check(int[] w, int k, long p) {
        int i = 0;
        for (int j = 0; j < k; j++) {
            int k_w = 0;
            while (k_w + w[i] <= p) {
                k_w += w[i];
                i++;
                if (i == w.length) return true;
            }
        }
        return false;
    }

}



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

int main() {
	int X, Y;
	cin >> X >> Y;
	cout << X + (Y >> 1);
	return 0;
}
/*
31536000のコメント解説欄
ここテンプレで用意してるから、A問題とかだとこの先空欄の危険あり
また、コンテスト後に https://31536000.hatenablog.com/ で解説していると思うので、良かったら読んでねー

やるだけ
*/

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main()
{
    long long a,b,k;
    cin>>a>>b>>k;
    if(k<=a)
    {
        cout<<a-k<<" "<<b<<endl;
    }
    else if(k<=a+b)
    {
        cout<<"0"<<" "<<b-(k-a)<<endl;
    }
    else cout<<"0 0"<<endl;
}

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

#define N 8
#define FREE -1
#define NOT_FREE 1

int row[N],col[N],dpos[2*N-1],dneg[2*N-1];

bool X[N][N];


void initialize()
{
  int i;

  for(i=0;i<N;i++)
    {
      row[i]=FREE,col[i]=FREE;
    }
  for(i=0;i<N;i++)
    {
      dpos[i]=FREE,dneg[i]=FREE;
    }
}

void printBoard()
{
  int i,j;

  for(i=0;i<N;i++)
    {
      for(j=0;j<N;j++)
	{
	  if(X[i][j])
	    {
	      if(row[i]!=j) return;
	    }
	}
    }
  for(i=0;i<N;i++)
    {
      for(j=0;j<N;j++)
	{
	  cout<<((row[i]==j)?"Q":".");
	}
      cout<<endl;
    }
}


void recursive(int i)
{
  int j;
  if(i==N)
    {
      printBoard();return;
    }

  for(j=0;j<N;j++)
    {
      if(NOT_FREE==col[j] || NOT_FREE == dpos[i+j] || NOT_FREE == dneg[i-j+N-1])
	{
	  continue;
	}
      row[i]=j;
      col[j]=dpos[i+j]=dneg[i-j+N-1]=NOT_FREE;

      recursive(i+1);

      row[i]=col[j]=dpos[i+j]=dneg[i-j+N-1]=FREE;
    }
}

int main()
{
  initialize();

  int i,j,k,r,c;

  for(i=0;i<N;i++)
    {
      for(j=0;j<N;j++)
	{
	  X[i][j]=false;
	}
    }

  cin>>k;
  for(i=0;i<k;i++)
    {
      cin>>r>>c;
      X[r][c]=true;
    }

  recursive(0);

  return 0;
}



Measured memory_bytes: 3128
#include <bits/stdc++.h>
#define SORT(x) sort(x.begin(),x.end(),greater<int>())
#define ALL(x) x.begin(),x.end()
#define rep(i, n) for(int i = 0; i < n; i++)
#define reps(i, m, n) for(int i = m; i < n; i++)
#define repr(i, m, n) for(int i = m; i >= n; i--)
#define INF 1000000000000000003 //1000000007
#define PI (acos(-1))
#define MOD 1000000007
using namespace std;
typedef long long ll;

int ct1,ct2;
struct edge{ll to;}; //edgeパラメータ
struct graph{
  ll N; //ノードの個数
  vector<vector<edge> > G; //G[辺の元]((.to辺の先,.costコスト),...)
  vector<ll> parent;
  vector<ll> depth; // d[ノード] ノードの深さ

  graph(ll n){ //グラフ生成時
    N = n;
    G.resize(N); //Edge情報
    parent.resize(N); //Node情報,親
    depth.resize(N); //Node情報,深さ
    rep(i,N){depth[i]= -1; parent[i]= -1;}
  }
  void add_edge(ll s, ll t){
    G[s].emplace_back((edge){t});
  }

  void dfs(ll v=0, ll p=0, ll d=0){
    parent[v] = p;
    depth[v] = d;
    for(auto E : G[v]){ // E つなぐエッジ
      if(E.to != p) dfs(E.to , v , d+1); //まだ行ってないなら
    }
  }
};


void Main(){

  int N;
  cin>>N;

  graph g(N);
  graph g2(N);

  rep(i,N-1){
    int a,b;
    cin>>a>>b;
    g.add_edge(a-1,b-1);
    g.add_edge(b-1,a-1);
    g2.add_edge(a-1,b-1);
    g2.add_edge(b-1,a-1);
  }

  g.dfs();
  g2.dfs(N-1,N-1);

  rep(i,N){
    if(g.depth[i]<=g2.depth[i])ct1++;
    else ct2++;
  }

  cout<< ( ct1>ct2 ? "Fennec" : "Snuke" )<<"\n";
}

//-----------------------------------
int main(){
  cin.tie(nullptr);
  ios_base::sync_with_stdio(false);
  cout << fixed << setprecision(15);
  Main();
}
//-----------------------------------


Measured memory_bytes: 17920
#include<cmath>
#include<cstdio>
#include<cstring>
#include<set>
#include<map>
#include<vector>
#include<assert.h>
#include<iostream>
#include<algorithm>
using namespace std;
#define pb push_back
#define mp make_pair
#define sz(x) ((int)(x).size())
#define rep(i,l,r) for(int i=(l);i<(r);++i)
#define setIO(x) freopen(x".in","r", stdin);freopen(x".out","w",stdout);
typedef long long ll;
typedef unsigned long long ul;
typedef pair<int, int> pii;
const ul BASE = 107;
const ll LINF = 9e18 + 7;
const int N = 2e5 + 7;
const int INF = 1e9 + 7;
const int MOD = 1e9 + 7;
const double PI = acos(-1.0);
const double EPS = 1e-8;
//-----------------head-----------------
ll a[3];
ll calc(ll x) {
	return abs(x / 2 - (x - x / 2));
}
ll solve() {
	rep(i, 0, 3)
		if (!(a[i] & 1))
			return 0;
	ll ans = LINF;
	rep(i, 0, 3)
	{
		ll tmp = 1;
		rep(j, 0, 3)
			if (j != i)
				tmp *= a[j];
		ans = min(ans, tmp);
	}
	return ans;
}
int main() {
	rep(i, 0, 3)
		scanf("%I64d", &a[i]);
	printf("%lld", solve());
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
 
#define int         long long
#define uint        unsigned int
#define ld          long double
#define showoff     ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define pb          push_back
#define pii         pair<int,int>
#define FOR(i,a,b)  for(int i=a;i<b;++i)
#define RFOR(i,a,b) for(int i=a;i>b;--i)
#define f           first
#define se          second
#define maxn        200005
#define all(v)      v.begin(),v.end()
#define sz(x)       (int)x.size()
#define mod         1000000007
#define pqueue      priority_queue<int>
#define pdqueue     priority_queue< int,vector<int> ,greater< int >>
 
using namespace std;
 
 
//mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
 
 
int power(int a,int n)
{
    a %= mod;
    if(n == 1)return a;
    if(n == 0)return 1;
    if(n%2)return (a*(power((a*a)%mod,n/2)%mod))%mod;
    return power((a*a)%mod,n/2)%mod;
}
const int inf = (int) 1e18;
 
int inverse(int x){
    return power(x,mod-2)%mod;//little fermat....
}

signed main()
{
    showoff;
    int n,k,ans = 0;
    cin >> n >> k;
    vector<int>v(n+5);
    FOR(i,1,n+1)cin >> v[i];
    FOR(i,1,n+1){
        int v1 = 0,v2 = 0;
        FOR(j,i+1,n+1)if(v[j] < v[i])++v1;
        FOR(j,1,n+1)if(v[j] < v[i])++v2;
        ans += ((v1*k)%mod+(v2*((k*(k-1)/2)%mod))%mod)%mod;
        ans %= mod;
    }
    cout << ans;
    return 0;
}
//*->for large size of matrix take int not long long if possible......
//*->always take maximum as inf for safer side ... 

Measured memory_bytes: 256
# -*- coding: utf-8 -*-

import math

a, b, c, d, e = int(input()), int(input()), int(input()), int(input()), int(input())

ans = math.ceil(a / 10)
ans += math.ceil(b / 10)
ans += math.ceil(c / 10)
ans += math.ceil(d / 10)
ans += math.ceil(e / 10)
ans *= 10
ans += min((a-1) % 10, (b-1) % 10, (c-1) % 10, (d-1) % 10, (e-1) % 10) - 10 + 1

print(ans)


Measured memory_bytes: 3064
#include<bits/stdc++.h>
using namespace std;
const int N=11;
int a[N][N];
int main()
{
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	int n,d,s,i,j,k,ans=0,dis;
	cin>>n>>d;
	for(i=0;i<n;i++)
	{
		for(j=0;j<d;j++)
			cin>>a[i][j];
		for(k=0;k<i;k++)
		{
			dis=0;
			for(j=0;j<d;j++)
				dis+=(a[i][j]-a[k][j])*(a[i][j]-a[k][j]);
			s=sqrt(dis);
			if(s*s==dis)ans++;
		}
	}
	cout<<ans<<'\n';
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ll long long
const int mod=1000000007;
int main(){
   int n , k;
   cin>>n>>k;
   int arr[n+1];
   for(int i = 0 ; i <= n; i++){
   		arr[i] = i;
   }
   ll sum = 0;
   int x = 0;
   int y = 0;
   for(int i = 0 ; i < k ; i++){
   	      sum += arr[i];
   }
   ll sum2 = 0;
   for(int i = n ; i > n-k ; i--){
   	       sum2 += arr[i];
   }
   x = k;
   y = n-k;
   ll ans = 0;
   ans = sum2 - sum+1;
   while( x <= n && y >= 0){
   	     sum += arr[x];
   	     sum2 += arr[y];
   	     ans = (ans%mod + (sum2 - sum+1 + mod)%mod + mod)%mod;
   	     x++;
   	     y--;
   }
   cout<<ans<<endl;
}

Measured memory_bytes: 4312
#include <iostream>
#include <string>
#include <vector>
#include <list>
#include <map>
#include <queue>
#include <stack>
#include <algorithm>
#include <fstream>
#include <sstream>
#include <iomanip>

using namespace std;

long long MOD = 1000000007;

int main(){
    int N, K;
    cin >> N >> K;
    vector<long long> H(N,0);
    for(auto &h:H){
        cin >> h;
    }
    sort(H.rbegin(), H.rend());

    long long ans=0;
    int cnt=0;
    for(int i=0; i<N; i++){
        if(cnt<K){
            cnt++;
            continue;
        }
        ans+=H[i];
    }
    cout << ans << endl;

}

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

const int DIM = 200005;
const int MOD = 1000000007;

int dp[DIM], psm[DIM], arr[DIM];

int main (void)
{
#ifdef HOME
	freopen("reversi.in", "r", stdin);
	freopen("reversi.out", "w", stdout);
#endif
	int N; cin >> N;
	dp[0] = 1;
	for (int i = 1; i <= N; ++i) {
		cin >> arr[i];
		dp[i] = dp[i - 1];
		if (arr[i] != arr[i - 1]) {
			dp[i] = (dp[i] + psm[arr[i]]) % MOD;
			psm[arr[i]] = dp[i];
		}
	}
	cout << dp[N] << endl;
	return 0;
}


Measured memory_bytes: 2560
S = input()
N = len(S)

str01 = "01" * (N // 2)
str10 = "10" * (N // 2)
if N % 2 == 1:
    str01 += "0"
    str10 += "1"

ans01 = 0
ans10 = 0
for i in range(N):
    if S[i] != str01[i]:
        ans01 += 1
    if S[i] != str10[i]:
        ans10 += 1

print(min(ans01, ans10))



Measured memory_bytes: 3316
import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,random,time,copy,functools

sys.setrecursionlimit(10**7)
inf = 10**3
eps = 1.0 / 10**10
mod = 10**9+7

def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LI_(): return [int(x)-1 for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def I(): return int(sys.stdin.readline())
def F(): return float(sys.stdin.readline())
def S(): return input()
def pf(s): return print(s, flush=True)


def main():
    rr = []

    while True:
        n,ni,na = LI()
        if n == 0:
            break
        a = sorted([I() for _ in range(n)], reverse=True)
        r = 0
        mi = -1
        for i in range(ni, na+1):
            tr = a[i-1] - a[i]
            if r <= tr:
                r = tr
                mi = i
        rr.append(mi)

    return '\n'.join(map(str, rr))


print(main())




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

int main(){
	int N; cin >> N;
	double sum = 0.0;

	for(int i = 0; i < N; ++i){
		double xi; cin >> xi;
		string ui; cin >> ui;
		if(ui == "JPY") sum += xi;
		else if(ui == "BTC"){
			sum += xi * 380000.0;
		}
	}

	cout << sum << endl;

	return 0;
}


Measured memory_bytes: 256
#include <iostream>

using namespace std;

int main() {
	int A, B,X;
	cin >> A >> B;
	if (A > B) {
		X = A;
		A--;
	}
	else {
		X = B;
		B--;
	}
	if (A > B) {
		X += A;
		A--;
	}
	else {
		X += B;
		B--;
	}
	cout << X << endl;
	return 0;
}

Measured memory_bytes: 256
#include <algorithm>
#include <iostream>
#include <cstring>
#include <cstdio>
#include <vector>
#include <stack>
#include <queue>
#include <cmath>
#include <set>
#include <map>
#define mp make_pair
#define pb push_back
#define pii pair<int,int>
#define link(x) for(edge *j=h[x];j;j=j->next)
#define inc(i,l,r) for(int i=l;i<=r;i++)
#define dec(i,r,l) for(int i=r;i>=l;i--)
const int MAXN=3e5+10;
const double eps=1e-8;
const int mod=1e9+9;
#define ll long long
using namespace std;
struct edge{int t,v;edge*next;}e[MAXN<<1],*h[MAXN],*o=e;
void add(int x,int y,int vul){o->t=y;o->v=vul;o->next=h[x];h[x]=o++;}
ll read(){
    ll x=0,f=1;char ch=getchar();
    while(!isdigit(ch)){if(ch=='-')f=-1;ch=getchar();}
    while(isdigit(ch))x=x*10+ch-'0',ch=getchar();
    return x*f;
}




ll a,b,n;
int main(){
    a=read();b=read();n=read();
    if(n<=b-1)printf("%lld\n",n*a/b);
    else printf("%lld\n",(b-1)*a/b);
    return 0;
}


Measured memory_bytes: 3764
#include <bits/stdc++.h>
#include <boost/multiprecision/cpp_int.hpp>
using int_t = boost::multiprecision::cpp_int;

int main()
{
    std::size_t N;
    std::cin >> N;

    bool over = false;
    boost::multiprecision::cpp_int A(1);
    for(std::size_t i=0; i<N; ++i)
    {
        std::int64_t a;
        std::cin >> a;

        if(a == 0)
        {
            std::cout << 0 << std::endl;
            return 0;
        }

        if(over)
        {
            continue;
        }

        if(boost::multiprecision::cpp_int(1'000'000'000'000'000'000) < A)
        {
            over = true;
        }
        A *= a;
    }
    if(over)
    {
        std::cout << "-1" << std::endl;
    }
    else if(boost::multiprecision::cpp_int(1'000'000'000'000'000'000) < A)
    {
        std::cout << "-1" << std::endl;
    }
    else
    {
        std::cout << A << std::endl;
    }
    return 0;
}


Measured memory_bytes: 3676
<?php
fscanf(STDIN, '%d', $n);
$p = array_map('intval', explode(' ', trim(fgets(STDIN))));
$min = 10 ** 9 + 7;
$ans = 0;
for ($i = 0; $i < $n; $i++) {
    $min = min($p[$i], $min);
    if ($p[$i] === $min) $ans++;
}
echo $ans . PHP_EOL;

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

int main() {
  int N;
  cin >> N;
  vector<string> A(N);
  for (int i = 0 ;i < N ; i++){
	cin >> A.at(i);
  }
  
  vector<string> ref(N);
  for (int i = 0 ;i < N ; i++){
	ref.at(i) = A.at(i);
  }
  
  int M;
  cin >> M;
  vector<string> B(M);
  for (int i = 0 ;i < M ; i++){
	cin >> B.at(i);
  }
    
  int c = 0;
  for (int i = 0 ;i < N ; i++){
    int counta = 0;
    for (int j = 0; j < N; j++){
      if ( A.at(i) == ref.at(j)){
        counta++;  
      }  //if
     } //for j
    
    for (int k = 0; k < M; k++){
      if (A.at(i) == B.at(k)){
        counta--;
      }//if
    }//for k

    c = max(c, counta);
    
  } //for i
  cout << c << endl;
}

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

int main() {
  int n;
  cin>>n;
  pair<int, int> a[n];
  for (int i=0; i<n; i++) {
    int x;
    cin>>x;
    a[i] = make_pair(x, i+1);
  }
  sort(a, a + n);
  for (int i=0; i<n; i++) {
    cout<<a[i].second;
    if (i != n - 1) {
      cout<<" ";
    }
  }
  cout<<endl;
}

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

int main() {
	int m,d;
	cin>> m >> d;
	int64_t cnt=0;
	for(int i=1;i<=m;i++){
		for(int j=22;j<=d;j++){
			if(j-j/10*10<=1) continue;
			else if(i==(j/10)*(j-j/10*10)) cnt++;
		}
	}
	cout << cnt << endl;
}


Measured memory_bytes: 384
import java.util.HashSet;
import java.util.Scanner;
import java.util.Set;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		long a = sc.nextLong();
		long b = sc.nextLong();
		long c = sc.nextLong();
		long d = sc.nextLong();
		long e = sc.nextLong();
		long f = sc.nextLong();
		long wa = -1;
		long su = -1;
		Set<Long> waterList = new HashSet<>();
		Set<Long> sugerList = new HashSet<>();
		for(int i = 0 ; 100 * i * a <= f ; i++) {
			for(int j = 0 ; 100 * i * a + 100 * b * j <= f ; j++) {
				waterList.add(100 * i * a + 100 * j * b);
			}
		}
		for(int i = 0 ; i * c <= f ; i++) {
			for(int j = 0 ; i * c + j * d <= f ; j++) {
				sugerList.add(i * c + j * d);
			}
		}
		for(long water : waterList) {
			for(long suger : sugerList) {
				if(water + suger <= f && e * water >= 100 * suger && suger * wa > su * water) {
					wa = water;
					su = suger;
				}
			}
		}
		System.out.println(wa + su + " " + su);
	}
}

Measured memory_bytes: 26568
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define FOR(i, s, n) for (int i = (s); i < (n); i++)
#define RFOR(i, s, n) for (int i = (n) - 1; i >= (s); i--)
#define REP(i, n) FOR(i, 0, n)
#define RREP(i, n) RFOR(i, 0, n)
#define ALL(a) a.begin(), a.end()
const long long MOD = 1e9+7, INF = 1e18;
template<class T>inline bool CHMAX(T&a,T b){if(a<b){a=b;return true;}return false;}
template<class T>inline bool CHMIN(T&a,T b){if(a>b){a=b;return true;}return false;}

int dx[] = {1,-1,0,0};
int dy[] = {0,0,1,-1};
#define IN(a, x, b) (a<=x && x<b)

signed main(){
	int H,W,K;
	cin>>H>>W>>K;
	string s[H];
	REP(i,H)cin>>s[i];
	int sx,sy;
	REP(i,H)REP(j,W)if(s[i][j]=='S'){sx = j,sy = i;}
	queue<pair<pair<int,int>,int>>que;
	vector<vector<int>>visit(H,vector<int>(W,0));
	que.push({{sy,sx},K});
	visit[sy][sx] = true;
	int mi = min({sy,sx,H-sy-1,W-sx-1});
	while(!que.empty()){
		int i = que.front().first.first;
		int j = que.front().first.second;
		int cost = que.front().second;
		que.pop();
		if(cost == 0)continue;
		REP(k,4){
			int ni = i + dx[k];
			int nj = j + dy[k];
			if(!IN(0,ni,H)||!IN(0,nj,W))continue;
			if(s[ni][nj]=='#')continue;
			if(visit[ni][nj])continue;
			visit[ni][nj] = true;
			que.push({{ni,nj},cost-1});
			CHMIN(mi,min({ni,nj,H-ni-1,W-nj-1}));
		}
	}
	cout<<1+(mi+K-1)/K<<endl;
}

Measured memory_bytes: 6144
#include <bits/stdc++.h>
#define be(v) (v).begin(),(v).end()
#define pb(q) push_back(q)
#define doublecout(a) cout<<fixed<<setprecision(10)<<a<<endl;
typedef long long ll;
using namespace std;
const ll mod=1000000007,mod9=1000000009;
template <class T>inline T lcm(T a,T b){return (a*b/__gcd(a,b));}

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll a,b,c,d;
    cin>>a>>b>>c>>d;
    ll ans=0;
    a--;
    ll e=lcm(c,d);
    ans+=b-((b/c)+(b/d)-(b/e));
    ans-=a-((a/c)+(a/d)-(a/e));
    cout << ans<<endl;
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define int long long
#define PB push_back
#define MP make_pair
#define FI first
#define SE second
using namespace std;
static const int INF = 1ll<<60;
typedef pair<int,int> pii;

string s;

signed main(){
    cin>>s;
    for(int i=0;i<s.size()-1;++i){
        for(int j=i+1;j<s.size();++j){
            if(s[i]=='C'&&s[j]=='F'){
                cout<<"Yes"<<endl;
                return 0;
            }
        }
    }
    cout<<"No"<<endl;
    return 0;
}


Measured memory_bytes: 256
import java.util.Scanner;


public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		String in = sc.nextLine();
		int a = Integer.parseInt(in);

		int ans = 0;
		int max = 0;
		int wk = 0;
		for (int i = 1; i <= a; i++) {
			wk = div2(i);
			if (wk >= max) {
				max = wk;
				ans = i;
			}
		}
		System.out.println(ans);
		sc.close();
	}

	private static int div2(int a) {
		int val = a;
		int mod = 0;
		int cnt = 0;
		while (true){
			mod = val % 2;
			val = val / 2;
			if (mod == 0 && val >= 2) {
				cnt++;
			} else if (mod == 0 && val < 2) {
				cnt++;
				break;
			} else {
				break;
			}
		}
		return cnt;
	}


}

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

#define all(x) (x).begin(), (x).end()
#define li long long
#define itn int

using namespace std;

inline int nxt(){
	int n;
	scanf("%d", &n);
	return n;
}

void panic() {
	puts("No");
	exit(0);
}

#define next lksjflkgkjsfg
#define prev jkhljsgf

int main(){

	int n = nxt(), m = nxt();
	vector<vector<int>> indices(m);
	int q = nxt();
	vector<int> a(q);
	for (itn i = 0; i < q; i++) {
		int x = nxt() - 1;
		a[i] = x;
		indices[x].push_back(i);
	}
	vector<int> lst(m);
	for (int i = 0; i < m; i++) {
		lst[i] = -i - 1;
	}

	for (itn i = 0; i < m; i++) {
		if (!indices[i].empty()) {
			lst[i] = indices[i].back();
		}
	}
	vector<itn> next(m, -1), prev(m, -1);
	for (int i = 0; i < m; i++) {
		if (i < m - 1) {
			next[i] = i + 1;
		}
		prev[i] = i - 1;
	}

	int cnt = 0;
	for (int i = 0; i < m - 1; i++) {
		if (lst[i] < lst[i + 1]) {
			cnt++;
		}
	}

	vector<char> used(m);
	int index = q - 1;
	vector<int> bound(n, q);
	while (index >= 0 && cnt) {

		int c = a[index];
		used[c] = 1;
		int nx = next[c];
		int pr = prev[c];
		if (nx > -1) {
			if (lst[c] < lst[nx]) {
				cnt--;
			}
			prev[nx] = pr;
		}
		if (pr > -1) {
			if (lst[pr] < lst[c]) {
				cnt--;
			}
			next[pr] = nx;
		}
		if (nx > -1 && pr > -1) {
			if (lst[pr] < lst[nx]) {
				cnt++;
			}
		}

		int i = n - 1;
		for (int j = (int)indices[c].size() - 1; j >= 0; j--) {
			if (i == -1) {
				break;
			}
			if (indices[c][j] < bound[i]) {
				bound[i--] = indices[c][j];
			}
		}
		if (i >= 0) {
			panic();
		}

		while (index >= 0 && used[a[index]]) {
			index--;
		}
	}

	puts("Yes");

	return 0;
}


Measured memory_bytes: 7808
N = int(input())
A = list(map(int, input().split()))
count = 0

A.sort()

for i in range(0, N - 1):
    if A[i] == A[i + 1]:
        count += 1
        break
    else:
        pass

if count == 0:
    print('YES')

else:
    print('NO')


Measured memory_bytes: 25172
import std.stdio;
import std.conv;
import std.string;
import std.typecons;
import std.algorithm;
import std.array;
import std.range;
import std.math;
import std.container;
import std.random;
       
void main() {
  auto r = readln.chomp.to!real;
  writefln("%.7f", r*r*PI);
  writefln("%.7f", 2*r*PI);
}

Measured memory_bytes: 1108
import Control.Applicative ((<$>), (<*>))
import Control.Monad
import Data.List
import Test.HUnit

main :: IO ()
-- main = runTestTT (TestList tests) >> return ()
main = do
  n <- getl toInt
  unless (n == 0) $ do
    solve <$> replicateM n (getl $ wrds toInt) >>= print
    main
    
solve :: [[Int]] -> Int
solve = fst . minimumBy cmpBMI . map bmi

bmi :: [Int] -> (Int, Double)
bmi [i, h, w] = (i, (10000 * fromIntegral w) / (fromIntegral h ^ 2))

cmpBMI :: (Int,Double) -> (Int,Double) -> Ordering
cmpBMI (i1, b1) (i2, b2)
  | bb1 == bb2 = compare i1 i2
  | otherwise = compare bb1 bb2
  where
    bb1 = abs (b1 - 22)
    bb2 = abs (b2 - 22)

toInt :: String -> Int
toInt s = read s

wrds :: (String -> a) -> String -> [a]
wrds f = map f . words

getl :: (String -> a) -> IO a
getl f = f <$> getLine

tests :: [Test]
tests = [
  "test1" ~: (1001,40.32) ~=? bmi [1001, 123, 61],
  "test2" ~: LT ~=? cmpBMI (100, 123.4) (1000, 123.5),
  "test3" ~: GT ~=? cmpBMI (300, 123.5) (200, 123.5),
  "test4" ~: (1001, 112.3) ~=?  minimumBy cmpBMI [(300, 123.5), (200, 123.5), (1001, 112.3)],
  "test5" ~: (200, 123.5) ~=?  minimumBy cmpBMI [(300, 123.5), (200, 123.5), (1001, 152.3)],
  "test6" ~: (2100, 22.2) ~=?  minimumBy cmpBMI [(300, 123.5), (200, 123.5), (1001, 152.3), (2000, 20.3), (2100, 22.2)]
  ]

Measured memory_bytes: 5684
s=input()
k=int(input())

ans=[]
a=ans.append
for i in range(len(s)):
	a(s[i])
for i in range(len(s)-1):
	a(s[i:i+2])
for i in range(len(s)-2):
	a(s[i:i+3])
for i in range(len(s)-3):
	a(s[i:i+4])
for i in range(len(s)-4):
	a(s[i:i+5])
ans=sorted(list(set(ans)))
print(ans[k-1])

Measured memory_bytes: 5068
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define fi first
#define se second
const int INF=0x3f3f3f3f;
#define N 200005

int p[N],m[N];

int find(int x){
	if(m[x]!=0)return x;
	else return p[x]=find(p[x]);
}

int main(){
	ios::sync_with_stdio(false);
	int n,q;
	while(cin>>n>>q){
		if(n==0&&q==0)break;
		memset(p,0,sizeof(p));
		memset(m,0,sizeof(m));
		p[1]=1;
		m[1]=-1;
		for (int i = 0; i < n-1; i++){
			cin>>p[i+2];
		}
		vector<pair<char,int>> st;
		while(q--){
			char t;
			int x;
			cin>>t>>x;
			st.push_back({t,x});
			if(t=='M'&&m[x]==0){
				m[x]=st.size();
			}
		}
		ll sum=0;
		for(int i=st.size()-1;i>=0;i--){
			if(st[i].fi=='M'){
				if(m[st[i].se]==i+1)m[st[i].se]=0;
			}
			else{
				sum+=find(st[i].se);
			}
		}
		cout<<sum<<endl;
	}
	return 0;
}

Measured memory_bytes: 6176
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
 
#define REP(i, n) for(int i = 0; i < (int)(n); i++)
int main(){
 string s;
 cin>>s;
 if (s=="AAA"||s=="BBB")
 {
     /* code */
     cout<<"No"<<endl;
 }
 else
 {
     cout<<"Yes"<<endl;
 }
 
 
}



Measured memory_bytes: 256
#include <iostream>
#include <vector>

using namespace std;

int main() {
    int n, m;
    cin >> n >> m;
    vector<vector<int>> s(m);
    vector<int> p(m);
    for (int i = 0; i < m; ++i) {
        int k, v;
        cin >> k;
        for (int j = 0; j < k; ++j) {
            cin >> v;
            s[i].push_back(v - 1);
        }
    }
    for (int i = 0; i < m; ++i) {
        cin >> p[i];
    }
    int answer = 0;
    bool b[n];
    for (int i = 0; i < (1 << n); ++i) {
        for (int j = 0; j < n; ++j) b[j] = (i & (1 << j)) != 0;
        bool ok = true;
        for (int j = 0; j < m; ++j) {
            int count = 0;
            for (int k : s[j]) {
                if (b[k]) ++count;
            }
            if (count % 2 != p[j]) {
                ok = false;
                break;
            }
        }
        if (ok) ++answer;
    }
    cout << answer << endl;
}


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

int m,t,p,r;
int zi,na,mo,ans;
int noa[52][12];
int acs[52];
int minu[52];
int check[52];
int o;
int num;

main(){
  while(cin >> m >> t >> p >> r, m||t||p||r){
    for(int i=1;i<=t;i++){
      for(int j=1;j<=p;j++){
        noa[i][j]=0;
      }
      acs[i]=0;
      minu[i]=0;
      check[i]=0;
    }

    for(int i=0;i<r;i++){
      cin >> zi >> na >> mo >> ans;
      if(ans==0){
        acs[na]++;
        minu[na]+=zi+noa[na][mo]*20;
      }
      else{
        noa[na][mo]++;
      }
    }

    for(int i=0;i<t;i++){
      num=-1;
      for(int j=t;j>0;j--){
        if(check[j]==0){
          if(num==-1){
            num=j;
          }
          else if(acs[num]<acs[j]){
            num=j;
          }
          else if(acs[num]==acs[j] && minu[num]>minu[j]){
            num=j;
          }
        }
      }
      if(i!=0){
        if(minu[num]==minu[o] && acs[num]==acs[o]){
          cout << "=";
        }
        else{
          cout << ",";
        }
      }
      cout << num;
      check[num]=1;
      o=num;
    }
    cout << endl;
  }
}

Measured memory_bytes: 1168
import sys
from collections import namedtuple


def next_str() -> str:
    result = ""
    while True:
        tmp = sys.stdin.read(1)
        if tmp.strip() != "":
            result += tmp
        elif tmp != '\r':
            break
    return result


def next_int() -> int:
    return int(next_str())


def main() -> None:
    sword = namedtuple('sw', ('wield', 'throw'))
    n, h = map(int, input().split())
    swords = [sword(next_int(), next_int()) for _ in range(n)]
    cnt = 0

    swords.sort(key=lambda x: x.throw, reverse=True)
    swords.sort(key=lambda x: x.wield)
    main_sword = swords.pop()
    swords.sort(key=lambda x: x.throw)

    while h > 0:
        cnt += 1
        if main_sword.throw >= h:
            h -= main_sword.throw
        elif len(swords) > 0 and main_sword.wield < swords[-1].throw:
            h -= swords.pop().throw
        else:
            h -= main_sword.throw
            cnt += 1 + (h - 1) // main_sword.wield
            break

    print(cnt)


if __name__ == "__main__":
    main()


Measured memory_bytes: 19272
#include <bits/stdc++.h>
    using namespace std;
    #define MOD 1000000007
    typedef long long ll;
     
    int main(){
        int n, i, j, k, a, b, count = 0;
        int res[10] = {};
        ll h, w, non_zero = 0;
        cin >> h >> w >> n;
        pair<int, int> mem, p[900000];
        for(i=0; i<n; i++){
            cin >> a >> b;
            //printf("%d %d\n", a, b);
            for(j=-1; j<=1; j++){
                for(k=-1; k<=1; k++){
                    if(1 <= a+j && a+j <= h && 1 <= b+k && b+k <= w){
                        p[count] = make_pair(a+j, b+k);
                        count++;
                    }
                }
            }
        }
        sort(p, p+count);
        j = 0;
        mem = p[0];
        for(i=0; i<count; i++){
            if(mem != p[i]){
                if(1 < mem.first && mem.first < h && 1 < mem.second && mem.second < w){
                    res[j]++;
                    non_zero++;
                }
                mem = p[i];
                j = 1;
            }else{
                j++;
            }
        }
        if(1 < mem.first && mem.first < h && 1 < mem.second && mem.second < w){
            res[j]++;
            non_zero++;
        }
        printf("%ld\n", (h-2)*(w-2)-non_zero);
        for(i=1; i<=9; i++){
            printf("%d\n", res[i]);
        }
    }

Measured memory_bytes: 7296
#include <algorithm>
#include <bitset>
#include <iomanip>
#include <ios>
#include <iostream>
#include <numeric>
#include <string>
#include <vector>

using namespace std;

int main()
{
    string N;
    cin >> N;
    string R = N;
    reverse(N.begin(), N.end());

    if (R == N) {
        cout << "Yes\n";
    } else {
        cout << "No\n";
    }
}

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

using namespace std;

#define all(x) x.begin(), x.end()
#define rep(i, n) for (int i = 0; i < n; ++i)
#define reps(i, m, n) for (int i = m; i <= n; ++i)

using i64 = long long;
using pii = pair<i64, i64>;

template<class A, class B>inline bool chmax(A &a, const B &b){return b > a ? a = b,1 : 0;}
template<class A, class B>inline bool chmin(A &a, const B &b){return b < a ? a = b,1 : 0;}

constexpr int INF = 0x3f3f3f3f;
constexpr i64 LINF = 0x3f3f3f3f3f3f3f3fLL;
constexpr int MOD = int(1e9) + 7;

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

  int n, d, x;
  cin >> n >> d >> x;

  int sum = 0;
  rep(i, n) {
    int a;
    cin >> a;
    int cnt = 0;
    for (int i = 1; i <= d; i += a) ++cnt;
    sum += cnt;
  }

  cout << sum + x << "\n";

  return 0;
}

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

#define pb push_back
#define ppp pop_back
#define pii pair<int,int>
#define fi first
#define se second

const int N = 22;
const int p = 1e9 + 7;

bool a[N][N];
int dp[1 << N];

void add(int &a, int b) {
    a += b;
    if (a >= p) a -= p;
    if (a < 0) a += p;
}

int main() {
    ios_base::sync_with_stdio(0); cin.tie(0);
#ifdef LOCAL
    freopen("input.txt", "r", stdin);
#endif
    int n;
    cin >> n;
    for (int i=0; i<n; i++) {
        for (int j=0; j<n; j++) {
            cin >> a[i][j];
        }
    }
	for (int i=0; i<(1<<n); i++) dp[i] = 0;
    dp[0] = 1;
    for (int mask=0; mask<(1 << n); mask++) {
        int j = __builtin_popcount(mask);
        for (int i=0; i<n; i++) {
            if (!(mask & (1 << i)) && a[j][i]) {
				add(dp[mask | (1 << i)], dp[mask]);
			}
		}
	}
	cout << dp[(1<<n) - 1] << "\n";
    return 0;
}


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

using namespace std;


const int INF = 10000000;

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

vector<vector<int>> d;

void solve() {
    int H, W; cin >> H >> W;
    vector<string> maze(H);
    for (int i = 0; i < H; i++) cin >> maze[i];

    queue<pair<int, int>> q;
    d.resize(H, vector<int>(W, INF));

    d[0][0] = 0;

    q.push(make_pair(0, 0));

    while(!q.empty()) {
        pair<int, int> p = q.front();
        q.pop();
        for (int i = 0; i < 4; i++) {
            for (int j = 0; j < 4; j++) {
                int nx = p.first + dx[i], ny = p.second + dy[i];
                if (0 <= nx && nx < H && 0 <= ny && ny < W) {
                    if (maze[nx][ny] == '.' && d[nx][ny] == INF) {
                        //cout << nx << " " << ny << endl;
                        d[nx][ny] = d[p.first][p.second] + 1;
                        q.push(make_pair(nx, ny));
                    }
                }
            }
        }
    }

    if (d[H - 1][W - 1] == INF) {
        cout << -1 << endl;
        return;
    }

    int count = 0;
    for (int i = 0; i < H; i++) {
        for (int j = 0; j < W; j++) {
            if (maze[i][j] == '#') count++;
            //cout << d[i][j] << " ";
        }
        //cout << endl;
    }

    int ans = H * W - (d[H - 1][W - 1] + 1) - count;
    cout << ans << endl;
}


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

Measured memory_bytes: 256
x1, y1, x2, y2 = map(int, input().split())

x3 = x2 - (y2-y1)
y3 = y2 + (x2-x1)
x4 = x1 - (y2-y1)
y4 = y1 + (x2-x1)

print(x3, y3, x4, y4)

Measured memory_bytes: 2940
#include <iostream>
#include <vector>
#include <set>
#include <queue>
#include <algorithm>
#include <string>
#include <cmath>
using namespace std;
const int INF = 1e9;
#define MAX 100
int main(void) {
	int w, h, n, x, y, a, minx = 0, miny = 0, maxx, maxy;
	cin >> w >> h >> n;
	maxx = w;
	maxy = h;
	for (int i = 0; i < n; ++i)
	{
		cin >> x >> y >> a;
		switch (a)
		{
		case 1:
			minx = max(minx, x);
			break;
		case 2:
			maxx = min(maxx, x);
			break;
		case 3:
			miny = max(miny, y);
			break;
		case 4:
			maxy = min(maxy, y);
			break;
		default:
			break;
		}
	}
	int d = (maxx - minx) > 0 ? maxx - minx : 0;
	int e = (maxy - miny) > 0 ? maxy - miny : 0;
	cout << d * e<< endl;
	return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<string.h>
#include<algorithm>
#include<stdio.h>
#include<cmath>
#include<vector>
#include<utility>

#define FOR(i, a, b) for(int i=(a);i<=(b);i++)
#define RFOR(i, a, b) for(int i=(a);i>=(b);i--)
#define MOD 1000000007
using namespace std;

int main(void) {
	
	int n, a, b;
	long long int k, count = 0;

	cin >> n >> k;
	vector<pair<int, int>>p(n+1);
	FOR(i, 1, n) {
		cin >> a >> b;
		p[i] = make_pair(a, b);
	}
	sort(p.begin(), p.end());
	FOR(i, 1, n) {
		count += p[i].second;
		if (count >= k) {
			cout << p[i].first << endl;
			break;
		}
	}
	return 0;
}

Measured memory_bytes: 1024
use std::io;
use std::io::{stdin, Read};
use std::process::exit;
use std::cmp::min;

fn main() {

    let mut scan = stdin();
    let mut line = String::new();

    let _ = scan.read_line(&mut line);
    let inputs: Vec<&str> = line.split_whitespace().collect();

    let w: i32 = inputs[0].parse().unwrap();
    let a: i32 = inputs[1].parse().unwrap();
    let b: i32 = inputs[2].parse().unwrap();

    // println!("w:{} a:{} b:{}", w,a,b);

    // (a+w)-b

    let mut v = 0;

    if a+w < b {
        v = (a+w)-b;
    } else if b+w < a{
        v = a-(b+w);
    } else {
        v = 0;
    }

    println!("{}",v.abs());
    
}



Measured memory_bytes: 2112
#include <iostream>
#include <cmath>
using namespace std;
int N;
int A[310];
int dp[310][310] = {};

int rec(int l,int r){
    if(dp[l][r]!=-1) return dp[l][r];
    if(l==r) return 0;
    if(l+1==r) return 2*(abs(A[l]-A[r])<=1);
    dp[l][r] = 0;
    int res1 = rec(l+1,r-1);
    if(abs(A[l]-A[r])<=1 && res1==r-l-1){
        dp[l][r] = r-l+1;
        return r-l+1;
    }
    dp[l][r] = res1;
    for(int k=0;k<r-l;k++){
        dp[l][r] = max(dp[l][r],rec(l,l+k)+rec(l+k+1,r));
    }
    return dp[l][r];
}

int main(){
    while(cin >> N && N>0){
        for(int i=1;i<=N;i++){
            cin >> A[i];
        }
        for(int i=1;i<=N;i++){
            for(int j=1;j<=N;j++){
                dp[i][j] = -1;
            }
        }
        cout << rec(1,N) << endl;
    }
}


Measured memory_bytes: 3320
import math
N=int(input())
S=list(input())
ans=0
Rc=S.count('R')
Wc=N-Rc
Wco=S[:Rc].count('W')
Rco=Rc-Wco
Wcu=Wc-Wco
Rcu=Rc-Rco

#print(Rco)
#print(Wco)
#print(Rcu)
#print(Wcu)


print(min(Rc,Wc,max(Wco,Rcu)))

Measured memory_bytes: 11736
//https://qiita.com/tanakh/items/0ba42c7ca36cd29d0ac8 より
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
    ($($r:tt)*) => {
        let s = {
            use std::io::Read;
            let mut s = String::new();
            std::io::stdin().read_to_string(&mut s).unwrap();
            s
        };
        let mut iter = s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
}

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

macro_rules! read_value {
    ($iter:expr, ( $($t:tt),* )) => {
        ( $(read_value!($iter, $t)),* )
    };
    ($iter:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($iter, $t)).collect::<Vec<_>>()
    };
    ($iter:expr, chars) => {
        read_value!($iter, String).chars().collect::<Vec<char>>()
    };
    ($iter:expr, usize1) => {
        read_value!($iter, usize) - 1
    };
    ($iter:expr, $t:ty) => {
        $iter.next().unwrap().parse::<$t>().expect("Parse error")
    };
}

// ここまで

use std::io::Write;

#[derive(Ord, PartialOrd, Eq, PartialEq)]
enum Event {
    Delete,
    Insert,
    Query,
}

fn run() {
    let out = std::io::stdout();
    let mut out = std::io::BufWriter::new(out.lock());
    input! {
        n: usize,
        m: usize,
        p: [(i32, i32, i32); n],
        q: [i32; m],
    }
    let mut e = Vec::with_capacity(2 * n + m);
    for (s, t, x) in p {
        e.push((s - x, Event::Insert, x));
        e.push((t - x, Event::Delete, x));
    }
    for d in q {
        e.push((d, Event::Query, 0));
    }
    e.sort();
    let mut set = std::collections::BTreeSet::new();
    for (_, q, x) in e {
        match q {
            Event::Delete => {set.remove(&x);},
            Event::Insert => {set.insert(x);},
            Event::Query => {
                if let Some(v) = set.iter().next() {
                    writeln!(out, "{}", v).unwrap();
                } else {
                    writeln!(out, "-1").unwrap();
                }
            },
        }
    }
}

fn main() {
    run();
}


Measured memory_bytes: 24568
package main

import (
	"fmt"
	"container/heap"
)

type Node struct {
	Id int
	Dis int
}

type PriorityQueue []*Node

func (pq PriorityQueue) Len() int { return len(pq) }

func (pq PriorityQueue) Less(i, j int) bool {
	return pq[i].Dis < pq[j].Dis
}

func (pq PriorityQueue) Swap(i, j int) {
	pq[i], pq[j] = pq[j], pq[i]
}

func (pq *PriorityQueue) Push(x interface{}) {
	*pq = append(*pq, x.(*Node))
}

func (pq *PriorityQueue) Pop() interface{} {
	n := len(*pq)
	pop := (*pq)[n-1]
	*pq = (*pq)[0:n-1]
	return pop
}

func main() {
	var n int
	fmt.Scan(&n)

	g := make([][]int, n)
	c := make([][]int, n)
	pq := make(PriorityQueue, 0, n)
	d := make([]int, n)
	for i := 0; i < n; i++ {
		var u,k int
		fmt.Scan(&u)
		fmt.Scan(&k)
		g[u] = make([]int, k)
		c[u] = make([]int, k)
		for j := 0; j < k; j++ {
			fmt.Scan(&g[u][j])
			fmt.Scan(&c[u][j])
		}

		if u == 0 {
			d[u] = 0
		} else {
			d[u] = 1 << 30
		}
		pq.Push(&Node{u, d[u]})
	}
	heap.Init(&pq)

	for pq.Len() > 0 {
		node := heap.Pop(&pq).(*Node)
		for i := 0; i < len(g[node.Id]); i++ {
			nextId := g[node.Id][i]
			nextDis := node.Dis + c[node.Id][i]
			if nextDis < d[nextId] {
				d[nextId] = nextDis
				heap.Push(&pq, &Node{nextId, nextDis})
			}
		}
	}

	for i := 0; i < n; i++ {
		fmt.Println(i, d[i])
	}
}



Measured memory_bytes: 1764