akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <algorithm>
#include <string>
#include <utility>
#include <vector>
using namespace std;

int min2 (int a, int b){
  if(a > b) {return b;}
  else {return a;}
}

bool compare_by_b(pair<int, int> a, pair<int, int> b) {
  return a.second < b.second;
}

int main(int argc, char const *argv[]) {
  int N;
  cin >> N;
  int X[100100];
  int L[100100];
  for(int i = 0; i < N; i++){
    cin >> X[i];
    cin >> L[i];
  }
  vector<pair<int, int> > P;
  for(int i = 0; i < N; i++){
    P.push_back(make_pair(X[i]-L[i],X[i]+L[i]));
  }

  sort(P.begin(),P.end(),compare_by_b);


  int ans = 1;
  int now = P[0].second;
  for(int i = 1; i < N; i++){
    if(P[i].first >= now){
      now = P[i].second;
      ans++;
    }
  }


  cout << ans << endl;



}

Measured memory_bytes: 2168
#include <bits/stdc++.h>
#include <math.h>
using namespace std;
int main(){
    int N,M;
    cin>>N>>M;
    vector<int>a(N);
    vector<int>b(N);
    vector<int>c(M);
    vector<int>d(M);
    for(int i=0;i<N;i++){
        cin>>a.at(i)>>b.at(i);
    }
    for(int i=0;i<M;i++){
        cin>>c.at(i)>>d.at(i);
    }

    for(int i=0;i<N;i++){
        int dis=abs(a.at(i)-c.at(0))+abs(b.at(i)-d.at(0));int num=0;
        for(int j=0;j<M;j++){
        int kis=abs(a.at(i)-c.at(j))+abs(b.at(i)-d.at(j));
        if(dis>kis){
            dis=kis;num=j;}     
        }
        cout<<num+1<<endl;
    }
    return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
#include <ctype.h>
int main(void){
 
  char mozi;
  int co[26] = {0};
  int i;
  int ii = 0;
  int c = 0;
     
  while(scanf("%c", &mozi) != EOF){
    mozi = toupper(mozi);
    if((mozi > 64) || (mozi < 91)){
      co[mozi - 65] += 1;
    }
  }
  for(i = 0;i < 26; i++){
    printf("%c : %d\n", 'a' + i, co[i]);
  }
  return 0;
}

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

#pragma region template


// -type-
using ll = long long;
using pll = pair<ll, ll>;
using vl = vector<ll>;
using vvl = vector<vl>;
using vs = vector<string>;


// -const-
const ll MOD = 1000000007;

const string YES = "Yes";

const string NO = "No";

const ll MAX = (ll)0x3f0000003f000000;
const double EPS = 1e-9;
const int dx[] = {0, 1, 0, -1, 1, -1, 1, -1},
          dy[] = {1, 0, -1, 0, 1, -1, -1, 1};


// -define-
#define F first
#define S second

#define reps(i, k, n) for (int i = (k), i##_len = (n); i < i##_len; ++i)
#define rep(i, n) reps(i, 0, n)
#define all(o) begin(o), end(o)
#define sz(a) ((int)(a).size())
#define debug(x) cerr << x << " (L:" << __LINE__ << ")" << '\n';


// -functions-

inline bool in(string s, string c) {
    return (s.find(c) != string::npos);
}
inline bool in(string s, char c) {
    return (s.find(c) != string::npos);
}

template <class T>
void print(T& x) {
    cout << x << '\n';
}

struct setup_main {
    setup_main() {
        cin.tie(0);
        ios::sync_with_stdio(0);
        cout << fixed << setprecision(15);
    }
} setup_main_;

#pragma endregion

string ans = YES;

void solve(std::string S) {
    rep(i, S.size()) {
        if ((i + 1) % 2 == 0 and S[i] == 'R') ans = NO;
        if ((i + 1) % 2 == 1 and S[i] == 'L') ans = NO;
    }
    print(ans);
}
signed main() {
    std::string S;
    std::cin >> S;
    solve(S);

    return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<math.h>
using namespace std;


int main()
{
    int n;
    int m=0;
    int judge=0;
    cin>>n;
    vector<int> a(n+1);
    vector<int> b(n+1);
    for(int i=1;i<=n;i++)
    {
        cin>>a[i];
    }

    for(int i=n;i>0;i--)
    {
        judge=0;
        for(int j=2;j*i<=n;j++)
        {
            judge+=b[i*j];
            judge%=2;
        }
        b[i]=(a[i]+judge)%2;
        if(b[i]==1)
        {
            m++;
        }
    }
    cout<<m<<endl;
    if(m!=0)
    {
        for(int i=1;i<=n;i++)
        {
            if(b[i]==1)
            {
                cout<<i<<" ";
            }
        }
        cout<<endl;
    }
}

Measured memory_bytes: 2560
h,w=map(int,input().split())
s=[input() for i in range(h)]
for i in range(h):
    for j in range(w):
        if s[i][j]==".":
            cnt=0
            for x in range(-1,2):
                for y in range(-1,2):
                    if 0<=i+x<h and 0<=j+y<w and s[i+x][j+y]=="#":
                        cnt+=1
            print(cnt,end="")
        else:
            print("#",end="")
    print()

Measured memory_bytes: 3444
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp> // Common file
#include <ext/pb_ds/tree_policy.hpp> // Including tree_order_statistics_node_update
using namespace std;

#define ll long long
#define vi vector<int>
#define vll vector<ll>
#define frw(i, a, b) for(int i = a; i < b; i++)
#define fi first
#define se second
#define pb push_back
#define in insert
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define sz(a) int(a.size())
#define pii pair<int, int>
#define piii pair<int, pii>
#define pll pair<ll, ll>
#define plll pair<ll, pll>
#define vpii vector<pii>
#define P pair<ll, ll>
#define V vector<ll>
#define C vector<char>
#define vpiii vector<piii>
#define vpll vector<pll>
#define vplll vector<plll>
#define mod 1000000007
#define rep(i, s, n) for (ll i = (ll)(s); i < (ll)(n); i++)


int power(ll x, unsigned int y)  
{  
	ll p=mod;
    ll res = 1;      
  
    x = x % p; 
               
   
    if (x == 0) return 0; 
  
    while (y > 0)  
    {  
       
        if (y & 1)  
            res = (res*x) % p;  
  
       
        y = y>>1; 
        x = (x*x) % p;  
    }  
    return res;  
}  

int main()
{
	int n;
	cin>>n;
	ll a[n];
	for(int i=0;i<n;i++)
		cin>>a[i];
	sort(a,a+n);
	ll ans=0;
	for(int i=0;i<n;i++)
	{
		for(int j=i+1;j<n;j++)
		{
			ll t=a[i]+a[j];
			auto x=lower_bound(a,a+n,t);
			ll y=x-a;
			ans+=y-j-1;
		}
	}
	cout<<ans;

}


Measured memory_bytes: 256
import java.util.HashMap;
import java.util.Map;
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int[] a = new int[9];
        Map<Integer, Integer> map = new HashMap<>();
        for (int i = 0; i < 9; i++) {
            map.put(Integer.parseInt(sc.next()), i);
        }
        int n = Integer.parseInt(sc.next());
        for (int i = 0; i < n; i++) {
            int temp = Integer.parseInt(sc.next());
            if (map.containsKey(temp)) {
                a[map.get(temp)]++;
            }
        }
        for (int i = 0; i < 3; i++) {
            boolean ans = true;
            for (int j = i * 3; j < i * 3 + 3; j++) {
                if (a[j] == 0) {
                    ans = false;
                    break;
                }
            }
            if (ans) {
                System.out.println("Yes");
                return;
            }
        }
        for (int i = 0; i < 3; i++) {
            boolean ans = true;
            for (int j = i; j < i + 7; j += 3) {
                if (a[j] == 0) {
                    ans = false;
                    break;
                }
            }
            if (ans) {
                System.out.println("Yes");
                return;
            }
        }
        if (a[0] != 0 && a[4] != 0 && a[8] != 0) {
            System.out.println("Yes");
        } else if (a[2] != 0 && a[4] != 0 && a[6] != 0) {
            System.out.println("Yes");
        } else {
            System.out.println("No");
        }
    }
}

Measured memory_bytes: 21844
#define M(a,b) (a<b?a:b)
#define S(a,b) sqrt(a*a+b*b)
void main(a,b,c,n,r){for(;scanf("%d%d%d",&a,&b,&c),a|b|c;)for(scanf("%d",&n);n--;puts((2*r>M(M(S(a,b),S(b,c)),S(c,a)))?"OK":"NA"))scanf("%d",&r);}

Measured memory_bytes: 0
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		
	Scanner sc=new Scanner(System.in);
	
	
	//文字列sの入力
	String s =sc.next();
	
	//文字列pの入力
	String p =sc.next();
	
	
	//文字列sのループ化(2個接続すればOK？)
	String sr =new String(s+s);
	//System.out.println(sr);
	
	//文字列sに文字列pが含まれるかの判定(抽出)
	//抽出できたらYESできなかったらNOの振り分け
	
	if(sr.contains(p)) {
		System.out.println("Yes");
	}else {
		System.out.println("No");
	}
	
	
	
	
	
	
	
	//出力
	
	
	
	}
	

}



Measured memory_bytes: 26256
#include<bits/stdc++.h>
#define ll long long
#define dbg1(x) cerr<<#x<<"="<<(x)<<" "
#define dbg2(x) cerr<<#x<<"="<<(x)<<"\n"
#define dbg3(x) cerr<<#x<<"\n"
using namespace std;
#define reg register
inline int read()
{
	int x=0,f=1;char ch=getchar();
	while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}
	while(ch>='0'&&ch<='9'){x=(x<<3)+(x<<1)+ch-'0';ch=getchar();}
	return x*f;
}
const int MN=300005;
int a[MN],N;
void No(){puts("No");exit(0);}
void Yes(){puts("Yes");exit(0);}
void chk(int l,int r)
{
	reg int i,_1=0,_2=0;
	for(i=l+1;i<=r-1;i+=2)if(a[i]!=i)No();
	for(i=l;i<=r;i+=2)if(a[i]==i)No();
	for(i=l;i<=r;i+=2)
		if(_1<a[i]&&_2<a[i]) _2=a[i];
        else if(_1<a[i]) _1=a[i];
        else No();
}
main()
{
	N=read();reg int i;
	for(i=1;i<=N;++i) a[i]=read();
	int l=1,r;
	while(a[l]==l&&l<N)++l;
	while(1)
	{
		if(a[l]==l)Yes();
		if(l+2>N)No();r=l+2;
		int Mi=min(a[l],a[r]),Ma=max(a[l],a[r]);
		while((r!=Ma||l!=Mi)&&r<=N)r+=2,Mi=min(Mi,a[r]),Ma=max(Ma,a[r]);
		if(r>N)No();chk(l,r);
		l=r+1;while(a[l]==l&&l<N)++l;
		if(l>N)break;
	}
	Yes();
}

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

void main()
{
    auto md = readln.split.to!(int[]);
    auto M = md[0];
    auto D = md[1];

    int r;
    foreach (m; 0..M) {
        ++m;
        foreach (d; 21..D) {
            ++d;
            if (d%10 >= 2 && d/10 >= 2 && (d%10)*(d/10) == m) {
                ++r;
            }
        }
    }
    writeln(r);
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <queue>
#include <deque>
#include <algorithm>
#include <set>
#include <map>
#include <bitset>
#include <cmath>
#include <functional>
#include <iomanip>
#include <random>
#define vll vector<ll>
#define vvvl vector<vvl>
#define vvl vector<vector<ll>>
#define VV(a, b, c, d) vector<vector<d> >(a, vector<d>(b, c))
#define VVV(a, b, c, d) vector<vvl>(a, vvl(b, vll (c, d)));
#define re(c, b) for(ll c=0;c<b;c++)
#define all(obj) (obj).begin(), (obj).end()
typedef long long int ll;
typedef long double ld;
using namespace std;

int main(int argc, char const *argv[]) {
  ll D;std::cin >> D;

  vll c(26);
  re(i, 26) std::cin >> c[i];

  vvl s = VV(D, 26, 0, ll);
  re(i, D) re(j, 26) std::cin >> s[i][j];

  for(int i=0;i<D;i++){
    ll idx = 0, num = -1;
    for(int j=0;j<26;j++) {
      if(num<s[i][j]) {
        num = s[i][j];
        idx = j;
      }
    }
    std::cout << (i%26)+1 << '\n';
  }
  return 0;
}


Measured memory_bytes: 3284
import java.util.*;

public class Main {
    static int numMan;
    static int numGoSen;
    static int numSen;

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        int Y = sc.nextInt();

        float avgDenom = (float)Y/N;
        //System.out.println("Avg denom = " + avgDenom);
        if (avgDenom < 1000 || avgDenom > 10000 || Y%1000 != 0) {
            //System.out.println("Point 1");
            System.out.println("-1 -1 -1"); return;
        }
        if (avgDenom == 1000) {
            //System.out.println("Point 2");
            System.out.println("0 0 " + N); return;
        }
        if (avgDenom == 10000) {
            //System.out.println("Point 3");
            System.out.println(N + " 0 0"); return;
        }

        numMan = Y/10000;
        numGoSen = (Y-10000*numMan)/5000;
        numSen = (Y-10000*numMan-5000*numGoSen)/1000;
        //System.out.println("Initial nums=" + numMan + "," + numGoSen + "," + numSen);
        if (numBills() != N) {
            if (numBills() > N) {
                //System.out.println("Point 4");
                System.out.println("-1 -1 -1"); return;
            }
            int defBills = N-numBills();
            boolean ansFound = false;
            for (int x=0; x<=numMan; x++) {
                for (int y=0; y<=numGoSen+2*x; y++) {
                    //System.out.println("x,y=" + x + "," + y);
                    if (x+4*y == defBills) {
                        numMan -= x;
                        numGoSen += 2*x - y;
                        numSen += 5*y;
                        ansFound = true;
                        break;
                    } else if (x+4*y > defBills) {
                        break;
                    }
                }
                if (ansFound) { break; } 
            }
            if (!ansFound) {
                numMan = -1; numGoSen = -1; numSen = -1;
            }
        }
        System.out.println(numMan + " " + numGoSen + " " + numSen);
    }

    private static int numBills() {
        return numMan+numGoSen+numSen;
    }
}


Measured memory_bytes: 21844
(N, K), *ABs = readlines.map{|l| l.split.map(&:to_i)}
M = 10**9 + 7

@g = ABs.each_with_object(Array.new(N + 1){[]}){|(a, b), o| o[a] << b; o[b] << a}

s = [[1, 0, 0]]
d = []
res = 1
while !s.empty?
  v, d1, d2 = s.pop
  d[v] = true
  res = res * (K - d1 - d2) % M
  @g[v].each do |w|
    next if d[w]
    s << [w, 1, d1]
    d1 += 1
  end
end
puts res

Measured memory_bytes: 25468
#include<bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define rep2(i,a,b) for(int i=a;i<b;i++)
#define each(it,v) for(auto it : v)
#define mod 1000000007
#define all(v) (v).begin(),(v).end()
#define ll long long
#define vi vector<int>
#define vll vector<ll>
#define vpii vector<pair<int,int>>
#define vv vector<vector<int>>
using namespace std;

main()
{
    int n; cin>>n;
    int a[n];
    int mx1=0,mx2=0;
    rep(i,n)
    {
        cin>>a[i];
        if(mx1<=a[i])
        {
            mx2=mx1;
            mx1=a[i];
        }else if(mx2<=a[i])
        {
            mx2=a[i];
        }
    }
    rep(i,n)
    {
        if(a[i]==mx1)cout<<mx2<<endl;
        else cout<<mx1<<endl;
    }
}

Measured memory_bytes: 2432
import sys

read = sys.stdin.buffer.read
input = sys.stdin.buffer.readline
inputs = sys.stdin.buffer.readlines


#mod=10**9+7
# rstrip().decode('utf-8')
# map(int,input().split())
#import numpy as np

from scipy.optimize import fmin



def main():
	n = int(input())
	xy = [list(map(int, input().split())) for _ in [0] * n]
	def calc(k):
		i, j = k
		return max((x - i) ** 2 + (y - j) ** 2 for x,y in xy)

	x, y = fmin(calc, (500, 500),disp=0)
	print(calc((x, y)) ** 0.5)



if __name__ == "__main__":
	main()


Measured memory_bytes: 37140
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#define PI 				acos(-1)
#define mp				make_pair
#define pb				push_back
#define all(a)			(a).begin(), (a).end()
#define sz(a)			a.size()
#define srt(a)			sort(all(a))
#define mem(a, h)		memset(a, (h), sizeof(a))
#define f 				first
#define s 				second
#define MOD1			998244353
#define fore(i, b, e)	for(int i = b; i < e; i++)
#define forg(i, b, e, m)	for(int i = b; i < e; i+=m)
int in(){int r=0,c;for(c=getchar();c<=32;c=getchar());if(c=='-') return -in();for(;c>32;r=(r<<1)+(r<<3)+c-'0',c=getchar());return r;}

using namespace std;
using namespace __gnu_pbds;

typedef long long 		ll;
typedef unsigned long long 		ull;
typedef pair<int, int>  ii;
typedef vector<int>     vi;
typedef vector<ii>      vii;
typedef vector<ll>      vll;
typedef tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update> ordered_set;
//find_by_order kth largest  order_of_key <
const int tam = 100010;
const int MOD = 1e9+7;
const double EPS = 1e-9;
int main()
{
	ios::sync_with_stdio(0); cin.tie(0);
	//freopen("qwe.txt", "r", stdin);
	//freopen("asd.txt", "w", stdout);
	int n;
	cin>>n;
	int ar[n];
	fore(i, 0, n) cin>>ar[i];
	sort(ar, ar + n);
	int mi, mid;
	if(ar[n-1] & 1)
	{
		mi = (ar[n-1]) / 2;
		mid = mi + 1;
	}
	else
		mi = mid = (ar[n-1]) / 2;
	int re = ar[0], ace = 1000000010;
	fore(i, 0, n-1)
	{
		if(min(abs(ar[i] - mi), abs(ar[i] - mid)) < ace)
		{
			ace = min(abs(ar[i] - mi), abs(ar[i] - mid));
			re = ar[i];
		}	
	}
	cout<<ar[n-1]<<' '<<re<<'\n';
	return 0;
}

// read the question correctly (is y a vowel? what are the exact constraints?)
// look out for SPECIAL CASES (n=1?) and overflow (ll vs int?) ARRAY OUT OF BOUNDSS2

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

int main()
{
	int K, N;
	cin >> K >> N;
	vector<int> w;
	for (int i = 0; i < N; i++) {
		int tmp;
		cin >> tmp;
		w.push_back(tmp);
	}

	sort(w.begin(), w.end());
	vector<int> diff;
	for (int i = 0;i < N;i++) {
		int tmp;
		if (i == N - 1) {
			tmp = K - w[i] + w[0];
		}
		else {
			tmp = w[i + 1] - w[i];
		}
		diff.push_back(tmp);
	}
	sort(diff.begin(), diff.end(), greater<int>());

	int ans = K - diff[0];

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


Measured memory_bytes: 2676
def solve():
    N = int(input())
    L = list(map(int, input().split()))

    count = 0
    for i in range(N):
        for j in range(i+1, N):
            for k in range(j+1, N):
                if(L[i] != L[j] and L[j] != L[k] and L[k] != L[i]):
                    if(L[i]+L[j] > L[k] and L[j]+L[k] > L[i] and L[k]+L[i] > L[j]):
                        count += 1

    print(count)

if __name__ == "__main__":
    solve()

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

#define ll long long
#define vecll vector<long long>
#define vec2ll vector<vector<long long>>
#define vecbool vector<bool>
#define vecpairll vector<pair<long long,long long>>
#define forll(s,a,b) for(long long s = a;s < b;s++)
#define forllde(s,a) for(long long s = a;s > 0;s--)


int main()
{
  ll n, x2=0, x4=0;
  cin >> n;
  vecll a(n);
  forll(i, 0, n){
	cin >> a[i];
	if (a[i] % 4 == 0)
	  x4++;
	else if (a[i] % 2 == 0)
	  x2++;
  }
  if (x4 >= a.size() / 2){
	cout << "Yes" << endl;
	return 0;
  }
  if (a.size() - x4 * 2 <= x2)
	cout << "Yes" << endl;
  else
	cout << "No" << endl;
}



Measured memory_bytes: 1024
#include<bits/stdc++.h>
 
using namespace std;
 
int dp[51][1000][1000];
 
int main(){
  int n,t[50];
  cin>>n;
  for(int i=0;i<n;i++)cin>>t[i];
 
  for(int i=0;i<=n;i++)
    for(int j=0;j<900;j++)
      for(int k=0;k<900;k++)
    dp[i][j][k]=1e9;
 
  dp[0][0][0]=0;
  for(int i=0;i<n;i++)
    for(int j=0;j<1000;j++)
      for(int k=0;k<1000;k++){
    if(j+t[i]<1000)dp[i+1][j+t[i]][k]=min(dp[i+1][j+t[i]][k],dp[i][j][k]);
    if(k+t[i]<1000)dp[i+1][j][k+t[i]]=min(dp[i+1][j][k+t[i]],dp[i][j][k]);
    dp[i+1][j][k]=min(dp[i+1][j][k],dp[i][j][k]+t[i]);
      }
   
  int ans=1e9;
  for(int i=0;i<1000;i++)
    for(int j=0;j<1000;j++)
      if(dp[n][i][j]!=1e9)ans=min(ans,max(dp[n][i][j],max(i,j)));
   
  cout<<ans<<endl;
  return 0;
}

Measured memory_bytes: 201912
#include <iostream>
using namespace std;
int main(void){
    char a, b, c;
    char d, e, f;
    cin >> a >> b >> c;
    cin >> d >> e >> f;
    if(a == f && b == e && c == d){
        cout << "YES" << endl;
    }
    
    else{
        cout << "NO" << endl;
    }
}

Measured memory_bytes: 256
n = int(input())
a = [0]
a.extend(list(map(int, input().split())))
a.append(0)

total = 0

for i in range(n+1):
    total += abs(a[i] - a[i+1])

for i in range(n):
    print(total - abs(a[i+1] - a[i]) -
          abs(a[i+1] - a[i+2]) + abs(a[i] - a[i+2]))


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

#define ll long long
#define mtv(kit) cout<<#kit<<" - "<<kit<<"\n";
#define ff first
#define ss second
#define pb push_back
#define rep(i,a,b) for(i=a;i<b;i++)
#define pii pair<ll , ll>
#define all(x) x.begin(),x.end()
#define nl "\n"
#define ump unordered_map

void doit(){
	ll n, i , ans = LONG_MAX;
	cin >> n;
	vector< ll >v(n);
	for(i = 0; i < n; i++)cin>>v[i];
	ll c = 0, s = accumulate(all(v),0);
	rep(i,0,n){
		c += v[i];
		ans = min(ans, abs(c - (s - c)));
	}
	cout << ans << nl;
}

int main() {
#ifndef ONLINE_JUDGE
    freopen("input1.txt","r",stdin);
    freopen("output1.txt","w",stdout);
#endif
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    ll t = 1;
    // cin >> t;
    for(ll i = 1; i <= t; i++){
        doit();
    }
}


Measured memory_bytes: 3672
import collections
import itertools

N=int(input())
A=[]
B=[]


for i in range(N):
  A.append(input())

counter = collections.Counter(A)

mode_v = counter.most_common()[0][-1]

it = itertools.takewhile(
    lambda kv: kv[-1] == mode_v, counter.most_common()
)

for k,v in it:
  B.append(k)
B.sort()

for i in range(len(B)):
  print(B[i])


Measured memory_bytes: 45080
k = int(input())
valM = {}
count = 0
flag = 1
amari = 0
while True:
    count+=1
    amari = (amari*10+7)%k
    if (amari in valM):
        break
    if amari == 0:
        print(count)
        flag = 0
        break
    else:
        valM[amari] = 0
if flag:
    print("-1")

Measured memory_bytes: 92620
#define _CRT_SECURE_NO_WARNINGS
#include<bits/stdc++.h>
#include <unordered_map>
//#include"testlib.h"
#define endl "\n"
#define all(v) v.begin(),v.end()
#define allr(s) s.rbegin(),s.rend()
#define RT(s) return cout<<s,0
#define watch(x) cout << (#x)<<" = "<<x<<endl
#define sz(s)    (int)(s.size())
#define PI acos(-1)
#define EPS 1e-8
using namespace std;
typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;
typedef pair<int, int> ii;
typedef vector<int> vi;
typedef vector<ii> vii;
int dy[] = { 1, -1, 0, 0, -1, 1, 1, -1 };
int dx[] = { 0, 0, 1, -1, 1, -1, 1, -1 };
void file() {
#ifndef ONLINE_JUDGE
	freopen("in.txt", "r", stdin);
	//freopen("out.txt", "w", stdout);
#else
	//freopen("street.in", "r", stdin);
	//freopen("out.txt", "w", stdout);
#endif
}
void fast() {
	std::ios_base::sync_with_stdio(0);
	cin.tie(NULL);
}

int main() {
//	file();
	fast();
	ll n; cin >> n;
	ll ans = 1;
	for (ll i = 2; i * i <= n; i++) {
		if (n % i) continue;
		ll tmp = n;
		while (tmp % i == 0)
			tmp /= i;
		if (tmp % i == 1)
			ans++;
		if (n / i == i) continue;
		tmp = n;
		while (tmp % (n / i) == 0)
			tmp /= (n / i);
		if (tmp % (n / i) == 1)
			ans++;
	}
	ll num = n - 1;
	if (num > 1)
		ans++;
	for (ll i = 2; i * i <= num; i++) {
		if (num % i) continue;
		ans++;
		if (num / i != i) ans++;
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define LL long long
LL module = 1000000007;
int main(){
    int N;
    scanf("%d", &N);

    LL sum = 0, ans=0;
    LL val;
    while(N--){
        scanf("%lld", &val);
        LL tmp = val*sum;
        tmp %= module;
        ans += tmp;
        ans %= module;
        sum += val;
        sum %= module;
    }   
    
    printf("%lld\n", ans);
    return 0;
}


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

int main(){
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    
    int a, b, m;
    cin >> a >> b >> m;
    static int aa[100000], bb[100000];
    for(int i=0;i<a;++i) cin >> aa[i];
    for(int i=0;i<b;++i) cin >> bb[i];
    int64_t ans = aa[0] + bb[0];
    for(int i=0;i<m;++i){
        int64_t x, y, c;
        cin >> x >> y >> c;
        ans = min(ans, aa[x-1] + bb[y-1] - c);
    }
    sort(aa, aa+a);
    sort(bb, bb+b);
    ans = min(ans, (int64_t)(aa[0] + bb[0]));
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 1024
/*input
8
4 6 3 2 8 5 7 1
*/
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <fstream>
#include <functional>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <utility>
#include <vector>
using namespace std;
#define sp ' '
#define endl '\n'
#define fi first
#define se second
#define mp make_pair
#define int long long
#define N 200005
#define ii pair<int,int>
ostream& operator << (ostream &os, vector<int>&x) {
	for (int i = 0; i < x.size(); i++) os << x[i] << sp;
	return os;
}
ostream& operator << (ostream &os, pair<int, int> x) {
	cout << x.fi << sp << x.se << sp;
	return os;
}
ostream& operator << (ostream &os, vector<pair<int, int> >&x) {
	for (int i = 0; i < x.size(); i++) os << x[i] << endl;
	return os;
}

class ITmin {
private:
	ii f[4 * N];
public:
	ITmin() {
		memset(f, 127, sizeof(f));
	}
	void update(int k, int l, int r, int pos, int val) {
		if (r < pos || pos < l) return;
		if (pos == l && r == pos) {
			f[k].fi = val; f[k].se = l;
			return;
		}
		int mid = (l + r) / 2;
		update(k * 2, l, mid, pos, val); update(k * 2 + 1, mid + 1, r, pos, val);
		f[k] = min(f[k * 2], f[k * 2 + 1]);
	}
	ii get(int k, int l, int r, int L, int R) {
		if (r < L || R < l) return mp(1e9, 0);
		if (L <= l && r <= R) return f[k];
		int mid = (l + r) / 2;
		return min(get(k * 2, l, mid, L, R), get(k * 2 + 1, mid + 1, r, L, R));
	}
};

int n;
int a[N];
ii lab[N];
vector<vector<int> > e(N);
int peak = 0;
ITmin odd, even;

ii findsec(int l, int r) {
	if (l % 2 == 1) {
		ii rec = odd.get(1, 1, n, l, r);
		return rec;
	}
	else {
		ii rec = even.get(1, 1, n, l, r);
		return rec;
	}
}

void solve(int l, int r) {
	ii fin;
	if (l % 2 == 1)
		fin = odd.get(1, 1, n, l, r);
	else {
		fin = even.get(1, 1, n, l, r);
	}
	ii sen = findsec(fin.se + 1, r);
	lab[++peak] = mp(fin.fi, sen.fi);
	int node = peak;
	if (fin.se != l) {
		e[node].push_back(peak + 1);
		solve(l, fin.se - 1);
	}
	if (fin.se + 1 < sen.se) {
		e[node].push_back(peak + 1);
		solve(fin.se + 1, sen.se - 1);
	}
	if (sen.se != r) {
		e[node].push_back(peak + 1);
		solve(sen.se + 1, r);
	}
}

vector<int> ans;
priority_queue<pair<ii, int> , vector<pair<ii, int> >, greater<pair<ii, int> > > pq;
#define make(a,b,c) mp(mp(a,b),c)
void cal() {
	pq.push(make(lab[1].fi, lab[1].se, 1));
	while (!pq.empty()) {
		pair<ii, int> u = pq.top(); pq.pop();
		ans.push_back(u.fi.fi); ans.push_back(u.fi.se);
		for (int i = 0; i < e[u.se].size(); i++) {
			int v = e[u.se][i];
			pq.push(make(lab[v].fi, lab[v].se, v));
		}
	}
	cout << ans << endl;
}

signed main() {
	ios_base::sync_with_stdio(false); cin.tie(0);
	cin >> n;
	for (int i = 1; i <= n; i++) cin >> a[i];

	for (int i = 1; i <= n; i++) {
		if (i % 2 == 1)
			odd.update(1, 1, n, i, a[i]);
		else
			even.update(1, 1, n, i, a[i]);
	}
	solve(1, n);
	cal();
}

Measured memory_bytes: 62576
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class Main {

    static int count = 0;

    // right??£??¨??????????????????????´?????????????????´?
    public static void mergeSort(int[] num, int left, int right){
        if (left+1 < right){
            int mid = (left + right) / 2;
            mergeSort(num, left, mid);
            mergeSort(num, mid, right);
            merge(num, left, mid, right);
        }
    }

    private static void merge(int[] num, int left, int mid, int right) {
        int n1 = mid - left;
        int n2 = right - mid;

        int[] L = new int[n1+1];
        int[] R = new int[n2+1];
        for (int i=0; i<n1; i++){
            L[i] = num[left+i];
        }
        for (int i=0; i<n2; i++){
            R[i] = num[mid+i];
        }
        L[n1] = Integer.MAX_VALUE;
        R[n2] = Integer.MAX_VALUE;

        int i = 0;
        int j = 0;
        for (int k=left; k<right; k++){
            count++;
            if (L[i] <= R[j]){
                num[k] = L[i++];
            }else {
                num[k] = R[j++];
            }
        }
    }


    public static void main(String[] args) throws IOException {

        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        int n = Integer.parseInt(br.readLine());
        String[] strings = br.readLine().split("\\s+");
        int[] num = new int[n];
        for (int i=0; i<n; i++){
            num[i] = Integer.parseInt(strings[i]);
        }
        mergeSort(num, 0, n);

        for (int i=0; i<n; i++){
            if (i > 0){
                System.out.print(" " + num[i]);
            }
            else {
                System.out.print(num[i]);
            }

        }
        System.out.println();
        System.out.println(count);
    }
}

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

// #define int long long
#define rep(i, n) for (int i = (int)(0); i < (int)(n); ++i)
#define reps(i, n) for (int i = (int)(1); i <= (int)(n); ++i)
#define rrep(i, n) for (int i = ((int)(n)-1); i >= 0; i--)
#define rreps(i, n) for (int i = ((int)(n)); i > 0; i--)
#define irep(i, m, n) for (int i = (int)(m); i < (int)(n); ++i)
#define ireps(i, m, n) for (int i = (int)(m); i <= (int)(n); ++i)
#define SORT(v, n) sort(v, v + n);
#define REVERSE(v, n) reverse(v, v+n);
#define vsort(v) sort(v.begin(), v.end());
#define all(v) v.begin(), v.end()
#define mp(n, m) make_pair(n, m);
#define cout(d) cout<<d<<endl;
#define coutd(d) cout<<std::setprecision(10)<<d<<endl;
#define cinline(n) getline(cin,n);
#define replace_all(s, b, a) replace(s.begin(),s.end(), b, a);
#define PI (acos(-1))
#define FILL(v, n, x) fill(v, v + n, x);
#define sz(x) int(x.size())

using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vll = vector<ll>;
using vvll = vector<vll>;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
using vs = vector<string>;
using vpll = vector<pair<ll, ll>>;

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 ll INF = 1e15;
const int MOD = 1e9+7;
const ll LINF = 1e18;


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

ll ngcd(vector<ll> a) {
  ll res = a[0];
  for(ll i=1; i<a.size() && res!=1; i++) res = gcd(a[i], res);
  return res;
}
ll nlcm(vector<ll> a){
  ll res = a[0];
  for(ll i=1; i<a.size(); i++) res = lcm(a[i], res);
  return res;
}
bool is_prime(ll n) {
  if(n < 2) return false;
  for (ll i = 2; i * i <= n; i++) if (n % i == 0) return false;
  return true;
}
ll digsum(ll n) {
  ll res=0;
  while(n) res += n%10, n /= 10;
  return res;
}
ll digcnt(ll n){
  ll res=0;
  while(n) res++, n /= 10;
  return res;
}
vector<ll> divisor(ll n) {
  vector<ll> res;
  for (ll i = 1; i * i <= n; i++) {
    if (n % i == 0) {
      res.push_back(i);
      if (i != n / i) res.push_back(n / i);
    }
  }
  sort(res.begin(), res.end());
  return res;
}
map<ll, ll> prime_factor(ll n) {
  map<ll, ll> res;
  for (ll i = 2; i * i <= n; i++) {
    while (n % i == 0) ++res[i], n /= i;
  }
  if (n != 1) res[n] = 1;
  return res;
}

signed main()
{
  cin.tie( 0 ); ios::sync_with_stdio( false );
  ll n,a,b; cin>>n>>a>>b;
  ll ans=0;
  reps(i,n){
    ll tmp=digsum(i);
    if(a<=tmp&&tmp<=b) ans+=i;
  }
  cout<<ans<<endl;
}

Measured memory_bytes: 256
import qualified Data.ByteString.Char8 as B
import Data.Maybe (fromJust)

main :: IO ()
main = do
    [a, b, c] <- map (fst . fromJust . B.readInt) . B.words <$> B.getLine
    let l = take (b `div` gcd a b) [n * a `mod` b | n <- [1..]]
    putStrLn $ if any (\x -> x `mod` b == c) l then "YES" else "NO"


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

#define ALL(a)  (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define MP make_pair
#define SZ(a) int((a).size())
#define EACH(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORTASC(c) sort((c).begin(),(c).end())
#define SORTDESC(c,t) sort((c).begin(),(c).end(), std::greater<t>());
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)
#define VMAX(a) *max_element(ALL(a))
#define VMIN(a) *min_element(ALL(a))
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;

const double PI  = acos(-1.0);

template <class T, class S>
using umap = std::unordered_map<T, S>;
using ll = long long;
using namespace std;

int main() {
    ll n, m;

    cin >> n >> m;

    ll ans = 0;
    REP(i, n){
      ans += i;
    }

    REP(i, m){
      ans += i;
    }

  	cout << ans << endl;

    return 0;
}

Measured memory_bytes: 256
a = [list(map(int, input().split())) for i in range(2)]
k = a[0][1]

num_list = a[1]

positive_list = []
negative_list = []

ans_positive = []
ans_negative = []

ans_list = []

for _ in num_list:
    if _ > 0:
        positive_list.append(_)
    elif _ < 0:
        negative_list.insert(0, _)
    else:
        if num_list != [0]:
            k -= 1

for _ in list(range(len(positive_list))):
    if not 0 <= k - _ - 2 < len(negative_list):
        continue
    ans_positive.append(2 * positive_list[_] - negative_list[k - _ - 2])

for _ in list(range(len(negative_list))):
    if not 0 <= k - _ - 2 < len(positive_list):
        continue
    ans_negative.append(-2 * negative_list[_] + positive_list[k - _ - 2])

if ans_positive:
    ans_list.append(min(ans_positive))

if ans_negative:
    ans_list.append(min(ans_negative))

if k <= len(positive_list):
    ans_list.append(positive_list[k - 1])

if k <= len(negative_list):
    ans_list.append(-1 * negative_list[k - 1])

if ans_list == []:
    print(0)

else:
    print(min(ans_list))

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

int n,ans=1e6,cnt=0,b[200001];
string s;
int main() {
  cin >> n >> s;
  for(int i=0 ;i<n ;i++){
    if(s[i] == '#' ){
      cnt++;
    }
    b[i+1] = cnt;
  }
  for(int i=0 ;i<=n ;i++){
    ans = min(ans,n-i-b[n]+2*b[i]);
  }
  cout << ans << endl;
}

Measured memory_bytes: 1412
#include <cstdio>
#include <queue>
#include <algorithm>
#include <ctype.h>
#define DEBUG
const int bufSize = 1e6;
using namespace std;
inline char nc()
{
#ifdef DEBUG
    return getchar();
#endif
    static char buf[bufSize], *p1 = buf, *p2 = buf;
    return p1 == p2 && (p2 = (p1 = buf) + fread(buf, 1, bufSize, stdin), p1 == p2) ? EOF : *p1++;
}
template <typename T>
inline T read(T &r)
{
    static char c;
    r = 0;
    for (c = nc(); !isdigit(c);) c = nc();
    for (; isdigit(c); c = nc()) r = r * 10 + c - 48;
    return r;
}
const int maxn = 2e5 + 100;
int T, n, anum, bnum;
struct node
{
    int L, R, K;
    bool operator<(const node &b) {return K < b.K;}
} A[maxn], B[maxn];
priority_queue<int, vector<int>, greater<int> > q1, q2;
int main()
{
    read(T);
    while (T--)
    {
        anum = bnum = 0;
        long long ans = 0;
        read(n);
        for (int i = 1; i <= n; ++i)
        {
            int k, l, r;
            read(k), read(l), read(r);
            if (l > r) A[++anum].L = l, A[anum].R = r, A[anum].K = k;
            else B[++bnum].L = l, B[bnum].R = r, B[bnum].K = n - k;
            ans += std::min(l, r);
        }
        sort(A + 1, A + 1 + anum), sort(B + 1, B + 1 + bnum);
        for (int i = 1; i <= anum; ++i)
        {
            if (A[i].K == 0) continue;
            if (q1.size() < A[i].K) q1.push(A[i].L - A[i].R);
            else if (q1.size() == A[i].K && q1.top() < A[i].L - A[i].R) q1.pop(), q1.push(A[i].L - A[i].R);
        }
        for (int i = 1; i <= bnum; ++i)
        {
            if (B[i].K == 0) continue;
            if (q2.size() < B[i].K) q2.push(B[i].R - B[i].L);
            else if (q2.size() == B[i].K && q2.top() < B[i].R - B[i].L) q2.pop(), q2.push(B[i].R - B[i].L);
        }
        while (!q1.empty()) ans += q1.top(), q1.pop();
        while (!q2.empty()) ans += q2.top(), q2.pop();
        printf("%lld\n", ans);
    }
    return 0;
}


Measured memory_bytes: 6012
/**
**	author : Raghav
**	codechef:raghav_456
**	codeforces:raghavramola7
**/
#pragma GCC optimize("Ofast")
#pragma GCC target("avx,avx2,fma")
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
using namespace std;

#define ff              first
#define ss              second
#define int             long long
#define pb              push_back
#define mp              make_pair
#define pii             pair<int,int>
#define vi              vector<int>
#define mii             map<int,int>
#define pqb             priority_queue<int>
#define pqs             priority_queue<int,vi,greater<int> >
#define setbits(x)      __builtin_popcountll(x)
#define zrobits(x)      __builtin_ctzll(x)
#define mod             1000000007
#define inf             1e18
#define ps(x,y)         fixed<<setprecision(y)<<x
#define mk(arr,n,type)  type *arr=new type[n];
#define w(x)            int x; cin>>x; while(x--)
mt19937                 rng(chrono::steady_clock::now().time_since_epoch().count());

typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> pbds;


void Raghav()
{
	ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#ifndef ONLINE_JUDGE
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#endif
}
bool isPrime(int n)
{
	for (int i = 2; i <= sqrt(n) + 1; i++)
	{
		if (n % i == 0)
		{
			return false;
		}
	}
	return true;
}
int32_t main()
{
	Raghav();
	int n, x, ans = 0;
	cin >> n >> x;
	int a[n];
	for (int i = 0; i < n; i++)
	{
		cin >> a[i];
	}
	sort(a, a + n);
	for (int i = 1; i <= x; i++)
		ans += a[i - 1];
	cout << ans;
	return 0;
}

Measured memory_bytes: 3668
import sys
sys.setrecursionlimit(10 ** 5 + 10)


def input(): return sys.stdin.readline().strip()


def resolve():
    n, p = map(int, input().split())
    import math

    # cf. https://qiita.com/suecharo/items/14137fb74c26e2388f1f

    def make_prime_list_2(num):
        if num < 2:
            return []

        # 0のものは素数じゃないとする
        prime_list = [i for i in range(num + 1)]
        prime_list[1] = 0  # 1は素数ではない
        num_sqrt = math.sqrt(num)

        for prime in prime_list:
            if prime == 0:
                continue
            if prime > num_sqrt:
                break

            for non_prime in range(2 * prime, num, prime):
                prime_list[non_prime] = 0

        return [prime for prime in prime_list if prime != 0]

    def prime_factorization_2(num):
        """numの素因数分解
        素因数をkeyに乗数をvalueに格納した辞書型dict_counterを返す"""

        if num <= 1:
            # 例えば1を食ったときの対処の仕方は問題によって違うと思うのでそのつど考える。
            # cf. https://atcoder.jp/contests/abc110/submissions/12688244
            return False
        else:
            num_sqrt = math.floor(math.sqrt(num))
            prime_list = make_prime_list_2(num_sqrt)

            dict_counter = {}  # 何度もこの関数を呼び出して辞書を更新したい時はこれを引数にして
            # cf. https://atcoder.jp/contests/arc034/submissions/12251452

            for prime in prime_list:
                while num % prime == 0:
                    if prime in dict_counter:
                        dict_counter[prime] += 1
                    else:
                        dict_counter[prime] = 1
                    num //= prime
            if num != 1:
                if num in dict_counter:
                    dict_counter[num] += 1
                else:
                    dict_counter[num] = 1

            return dict_counter
    if p != 1:
        d = prime_factorization_2(p)
        ans = 1
        for k, v in d.items():
            if v >= n:
                ans *= k**(v//n)
        print(ans)
    else:
        print(1)


resolve()

Measured memory_bytes: 113904
#include <bits/stdc++.h>
using namespace std;
const int maxn = 1000;
char grid[maxn][maxn];
int dist[maxn][maxn];
int main(){
	int n, m, k; cin >> n >> m >> k;
	memset(grid, '#', sizeof(grid));
	for(int i = 1; i <= n; i++) for(int j = 1; j <= m; j++) cin >> grid[i][j];
	memset(dist, -1, sizeof(dist));
	queue<pair<int,int> > q;
	for(int i = 1; i <= n; i++) for(int j = 1; j <= m; j++) if(grid[i][j] == 'S'){
		dist[i][j] = 0;
		q.push({i, j});
	}
	while(!q.empty()){
		int x, y; tie(x, y) = q.front(); q.pop();
		for(int dx = -1; dx <= 1; dx++) for(int dy = -1; dy <= 1; dy++){
			if(abs(dx) + abs(dy) == 1){
				int nx = x + dx, ny = y + dy;
				if(grid[nx][ny] != '#' && dist[nx][ny] == -1){
					dist[nx][ny] = dist[x][y] + 1;
					q.push({nx, ny});
				}
			}
		}
	}
	int ans = 1<<30;
	for(int i = 1; i <= n; i++) for(int j = 1; j <= m; j++) if(dist[i][j] != -1 && dist[i][j] <= k){
		ans = min(ans, 1 + (min({i - 1, n - i, j - 1, m - j}) + k - 1) / k);
	}
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 5376
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll,ll> P;
int main(void){
	ll n,a,b;
	cin>>n>>a>>b;
	ll ans=0;
	ans=(n/(a+b))*a;
	ll p=n%(a+b);
	ans+=min(p,a);
	cout<<ans<<endl;
	
}


Measured memory_bytes: 256
num_list=list(map(str,input().split()))

stack=[]


for i in range(0,len(num_list)):
    if num_list[i]=="+":
        ans=0
        tmp1=int(stack.pop())
        tmp2=int(stack.pop())
        ans=tmp2+tmp1
        stack.append(ans) 
    elif num_list[i]=="*":
        ans=0
        tmp1=int(stack.pop())
        tmp2=int(stack.pop())
        ans=tmp2*tmp1
        stack.append(ans) 
    elif num_list[i]=="-":
        ans=0
        tmp1=int(stack.pop())
        tmp2=int(stack.pop())
        ans=tmp2-tmp1
        stack.append(ans) 
    elif num_list[i]=="/":
        ans=0
        tmp1=int(stack.pop())
        tmp2=int(stack.pop())
        ans=tmp2/tmp1
        stack.append(ans) 
    else:
        stack.append(num_list[i])
print(stack[0])


Measured memory_bytes: 5608
#include <bits/stdc++.h>
using namespace std;
using Int = long long;
vector<int> Pa, Pd, Na, Nd; // >=0/<0 ascending/decreasing
Int f(const vector<int> &A, const vector<int> &B, Int x, bool eq) {
    Int ans = 0;
    int t = B.size();
    for (int i = 0; i < A.size(); i++) {
        while (t > 0 && (Int)A[i] * B[t - 1] > x) t--;
        if (eq) {
            ans += max(0, t - i - 1);
        } else {
            ans += t;
        }
    }
    return ans;
}
Int lower_or_equal(Int x) {
    return f(Pa, Pa, x, 1) + f(Na, Pd, x, 0) + f(Nd, Nd, x, 1);
}
int main() {
    Int N, K; cin >> N >> K;
    for (int i = 0; i < N; i++) {
        int a; cin >> a;
        if (a >= 0) Pa.push_back(a);
        else Na.push_back(a);
    }
    sort(begin(Pa), end(Pa));
    sort(begin(Na), end(Na));
    Pd = Pa, Nd = Na;
    reverse(begin(Pd), end(Pd));
    reverse(begin(Nd), end(Nd));
    Int ng = -2e18, ok = 2e18;
    while (ok - ng > 1) {
        Int mid = (ng + ok) / 2;
        (lower_or_equal(mid) >= K ? ok : ng) = mid;
    }
    cout << ok << endl;
    return 0;
}


Measured memory_bytes: 2036
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<ll, ll> l_l;
typedef pair<int, int> i_i;
typedef vector<ll> vl;
typedef vector<int> vi;
typedef vector<char> vec;
typedef vector<bool> veb;
typedef vector<string> ves;
typedef vector<vector<ll>> vvl;
typedef vector<vector<int>> vvi;
typedef vector<vector<char>> vvec;
typedef vector<vector<bool>> vveb;
typedef vector<vector<string>> vves;
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define rep1(i,n) for(int i=1;i<(int)(n);i++)
#define rep2(i,n) for(int i=2;i<(int)(n);i++)
#define repk(i,k,n) for(int i=k;i<(int)(n);i++)
#define fs first
#define sc second
#define pb push_back
#define pp pop_back
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define maxel(a) *max_element(all(a))
#define minel(a) *min_element(all(a))
#define acc accumulate
#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))
typedef long long int64;
#define dame { puts("-1"); return 0;}
#define YES { cout << "YES" << endl; return 0; }
#define NO { cout << "NO" << endl; return 0; }
#define Yes { cout << "Yes" << endl; return 0; }
#define No { cout << "No" << endl; return 0; }
template<class T> bool chmax(T& a, const T& b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> bool chmin(T& a, const T& b) { if (a > b) { a = b; return 1; } return 0; }
int dx[] = { 0, 0, -1, 1 };
int dy[] = { 1, -1, 0, 0 };

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

	int K, N;
	cin >> K >> N;
	vi A(N);
	rep(i, N) {
		cin >> A.at(i);
	}
	int mi = 0;
	rep(i, N) {
		if (i != N - 1) {
			//cout << abs(A.at(i) - A.at(i + 1)) << endl;
			if (mi < A.at(i + 1) - A.at(i)) {
				mi = A.at(i + 1) - A.at(i);
			}
		}
		else {
			//cout << abs(K - A.at(i) + A.at(0)) << endl;
			if (mi < K - A.at(i) + A.at(0)) {
				mi = K - A.at(i) + A.at(0);
			}
		}
	}
	cout << K - mi;
	return 0;
}


Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
 
const int DIM = 1e5 + 5;
 
int arr[DIM];
 
int main( void ) {
    
    int n, a, b;
    cin >> n >> a >> b;
    
    long long ans = 0;
    for( int i = 1; i <= n; i ++ ) {
        cin >> arr[i];
        
        if( i >= 2 )
            ans += min( 1LL * b, 1LL * a * (arr[i] - arr[i - 1]) );
    }
    
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 640
#include<bits/stdc++.h> 
//#define <- プログラムの文字列を置換する
//typedef <- 新しい型に名前を付けるためのキーワード

using namespace std;

typedef long long ll;
typedef pair<int,int> pii;

const long long MOD = 1e9 + 7;
const long long INF = 1e15;
const int INF_INT = 1e9;

template<class TYPE>
struct edge{
    TYPE to,cost; 
    edge(TYPE t,TYPE c){
        to = t;
        cost = c;
    }
};

int main(){
    int N;
    cin >> N;
    int C[N];
    int S[N];
    int F[N];
    for(int i = 1; i < N; i++){
        cin >> C[i] >> S[i] >> F[i];
    }
    vector<int> ans;
    for(int i = 1; i < N; i++){
        int time = S[i] + C[i];
        for(int j = i+1; j < N; j++){
            time = max(time,S[j]);
            int n = (time-1)/F[j] + 1 - S[j] / F[j] + 1;
            time = S[j] + F[j]*(n - 1) + C[j];
        }
        ans.emplace_back(time);
    }
    ans.emplace_back(0);
    for(int num : ans) cout << num << endl;
    return 0;
}


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

using namespace std;

typedef long long ll;

#ifdef RED
  mt19937 rnd(228);
#else
  mt19937 rnd(chrono::high_resolution_clock::now().time_since_epoch().count());
#endif

const int N = (int)1e6 + 5;

int n;

int main() {
#ifdef RED
  freopen("a.in", "r", stdin);
#endif
  ios_base :: sync_with_stdio(0);
  cin.tie(0);
  cin >> n;
  vector <pair <int, int> > v(n);
  int i = 0;
  for (auto &x : v) {
    cin >> x.first;
    x.second = ++i;
  }
  sort(v.begin(), v.end());
  for (auto x : v) {
    cout << x.second << " ";
  }
  return 0;
}


Measured memory_bytes: 1664
#pragma GCC optimize(2)
#include<bits/stdc++.h>
#define ll long long
#define maxn 200005
#define inf 1e9
#define eps 1e-10
using namespace std;

inline ll read()
{
	ll x=0,w=1; char c=getchar();
	while(c<'0'||c>'9') {if(c=='-') w=-1; c=getchar();}
	while(c<='9'&&c>='0') {x=(x<<1)+(x<<3)+c-'0'; c=getchar();}
	return w==1?x:-x;
}

ll a[maxn],b[maxn],c[maxn],d[maxn],pre[maxn],n,tot;

inline void add(int x,int val){for(int i=x;i<=maxn-4;i+=i&-i) c[i]+=val;}
inline ll q(int x){ll res=0; for(int i=x;i;i-=i&-i) res+=c[i]; return res;}

inline bool jud(ll x)
{
	ll tmp=0,cnt=0;
	for(int i=1;i<=n;i++) if(a[i]<x) b[i]=-1; else b[i]=1;
	for(int i=0;i<=maxn-4;i++) c[i]=0; add(1e5,1);
	for(int i=1;i<=n;i++) pre[i]=pre[i-1]+b[i],tmp+=q(pre[i]+1e5),add(pre[i]+1e5,1);
	if(tmp+cnt>=tot/2) return true; return false;
}

int main()
{
	n=read(); tot=n*(n+1)/2;
	for(int i=1;i<=n;i++) a[i]=read(),d[i]=a[i]; sort(d+1,d+n+1);
	int l=1,r=n,ans=0;
	while(l<=r)
	{
		int mid=(l+r)>>1;
		if(jud(d[mid])) ans=d[mid],l=mid+1;
		else r=mid-1;
	}
	cout<<ans<<endl;
	return 0;
}

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

using namespace std;

template <class T>inline T updmax(T& a, T b) {return a = max(a, b);}
template <class T>inline T updmin(T& a, T b) {return a = min(a, b);}

class Solution {
public:
	void solve() {
		int n;
		cin >> n;
		vector<vector<int>> dp(1001, vector<int>(1002, 0));
		for(int i=0; i < n; i++){
			int x1, y1, x2, y2;
			cin >> x1 >> y1 >> x2 >> y2;
			dp[x1][y1]++;
			dp[x1][y2]--;
			dp[x2][y1]--;
			dp[x2][y2]++;
		}
		for(int i=0; i <= 1000; i++)for(int j=0; j < 1000; j++)dp[i][j+1] += dp[i][j];
		for(int i=0; i < 1000; i++)for(int j=0; j <= 1000; j++)dp[i+1][j] += dp[i][j];
		int ans = 0;
		for(int i=0; i <=1000; i++)for(int j=0; j <=1000; j++)updmax(ans, dp[i][j]);
		cout << ans << "\n";
		return;
	};
};

int main() {
	ios_base::sync_with_stdio(false);
	cin.tie(nullptr);
	Solution solution;
	solution.solve();
	return 0;
}


Measured memory_bytes: 6836
def main():
    A, B = map(int, input().split())
    X = prime_decomposition(gcd(A, B))
    print(len(set(X))+1)


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


def prime_decomposition(n):
    i = 2
    table = []
    while i * i <= n:
        while n % i == 0:
            n /= i
            table.append(i)
        i += 1
    if n > 1:
        table.append(n)
    return table


if __name__ == '__main__':
    main()


Measured memory_bytes: 3060