akhauriyash/Code-Regression huggingface dataset:
def main() :
    lst = input().split()
    stack = []
    for i in lst :
        if i == "+" :
            x = stack.pop()
            y = stack.pop()
            stack.append(x + y)

        elif i == "-" :
            x = stack.pop()
            y = stack.pop()
            stack.append(y - x)

        elif i == "*" :
            x = stack.pop()
            y = stack.pop()
            stack.append(x * y)

        else :
            stack.append(int(i))

    print(stack.pop())


if __name__ == "__main__" :
    main()

Measured memory_bytes: 5596
#include <bits/stdc++.h>
#define mp  make_pair
using namespace std;

typedef long long  LL;
typedef pair <int,int>  PII;
int n,x,y,z;
LL sum,s,ans;
PII k[100010];
multiset <int> a,b;

bool cmp(PII x,PII y){return x.first-x.second<y.first-y.second;}

void work()
{
	scanf("%d %d %d",&x,&y,&z),n=x+y+z;
	for (int i=1,x,y,z; i<=n; i++)
		scanf("%d %d %d",&x,&y,&z),s+=z,k[i]=mp(x-z,y-z);
	sort(k+1,k+n+1,cmp);
	for (int i=1; i<=y; i++)  b.insert(k[i].second),sum+=k[i].second;
	for (int i=y+1; i<=n; i++)  a.insert(-k[i].first);
	for (int i=1; i<=x; i++)  sum-=*a.begin(),a.erase(a.begin());
	ans=sum;
	for (int i=y+1; i<=y+z; i++)
		{
			if (-*a.begin()>=k[i].first)  a.erase(a.find(-k[i].first));
			else  sum-=k[i].first+(*a.begin()),a.erase(a.begin());
			sum+=k[i].second,b.insert(k[i].second);
			sum-=*b.begin(),b.erase(b.begin());
			ans=max(ans,sum);
		}
	printf("%lld",ans+s);
}

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


Measured memory_bytes: 5760
#include <stdio.h>
int main(void){
    long k,n,i,a[200000];
    scanf("%ld%ld",&k,&n);
    for(i=0;i<n;i++) scanf("%ld",&a[i]);
    long max = a[0]+k-a[n-1]; //max … 通らなかった経路
    for(i=0;i<n-1;i++){
        long tmp=a[i+1]-a[i];
        if(tmp>max) max=tmp;
    }
    printf("%ld",k-max);
    return 0;
}

Measured memory_bytes: 1664
#include <bits/stdc++.h>
#define INF (1<<30)
#define MOD 1000000007
#define l_ength size
using ll = long long;
using namespace std;

int main(){
	long double n, m, d ;
	cin >> n >> m >> d;
	cout << fixed << ( ( m - 1 ) * ( n - d ) * ( (d) ? 2 : 1 ) ) / ( n * n ) << endl;
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using PII = pair<int, int>;
using VI = vector<int>;

int main() {
#ifdef LOCAL_EXEC
//	freopen("sample.in", "r", stdin);
//	freopen("sample.out", "w", stdout);
#else
  ios_base::sync_with_stdio(false); cin.tie(NULL);
#endif

  int n; cin >> n;
  VI h(n), dp(n);
  for (int i = 0; i < n; i++) {
    cin >> h[i];
    if (i == 0) continue;
    dp[i] = 2e9;
    for (int j: {1, 2}) {
      if (i >= j) {
        dp[i] = min(dp[i], dp[i - j] + abs(h[i] - h[i - j]));
      }
    }
  }
  cout << dp[n - 1] << endl;

  return 0;
}


Measured memory_bytes: 1024
n = int(input())
s = input()
ans = 0

for i in range(1, n):
    x = s[:i]
    y = s[i:]
    cnt = 0
    for j in range(i):
        if(y.count(x[j])):
            y = y.replace(x[j], '')
            cnt += 1
    ans = max(ans, cnt)
print(ans)

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

using namespace std;

#define LOG(...) fprintf(stderr,__VA_ARGS__)
//#define LOG(...)
#define FOR(i,a,b) for(int i=(int)(a);i<(int)(b);++i)
#define REP(i,n) for(int i=0;i<(int)(n);++i)
#define ALL(a) (a).begin(),(a).end()
#define RALL(a) (a).rbegin(),(a).rend()
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort(ALL(c))
#define RSORT(c) sort(RALL(c))

typedef long long ll;
typedef unsigned long long ull;
typedef vector<bool> vb;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<vb> vvb;
typedef vector<vi> vvi;
typedef vector<vll> vvll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;

int main() {
    int m, n;
    cin >> m >> n;
    int ma = 0;
    REP(i, m) {
        int solves = 0;
        REP(j, n) {
            int a;
            cin >> a;
            if (a) solves++;
        }
        ma = max(ma, solves);
    }
    cout << ma << endl;
}

Measured memory_bytes: 3092
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int64_t N;
  cin >> N;
  vector<int> Y(N);
  vector<int> X(N);
  for (int i = 0; i < N; i++) {
    cin >> X.at(i);
    Y.at(i) = X.at(i);
  }
  sort(X.begin(), X.end());
  for (int i = 0; i < N; i++) {
    bool ok = false;
    if (Y.at(i) < X.at(N / 2)) {
      ok = true;
    }
    if (ok) {
      cout << X.at((N / 2)) << endl;
    }
    else {
      cout << X.at((N / 2) - 1) << endl;
    }
  }
}

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

struct Fast {Fast(){std::cin.tie(0);ios::sync_with_stdio(false);}} fast;

typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<vector<int> > vii;
typedef queue<int> qi;
typedef stack<int> si;
typedef deque<int> dqi;

#define reps(i, a, b) for (int i = a; i < b; ++i)
#define rep(i, n) reps(i, 0, n)
#define REPS(i, a, b) reps(i, a, b)
#define REP(i, n) rep(i, n)
#define deps(i, a, b) for (int i = a; i >= b; --i)
#define dep(i, n) deps(i, n, 0)
#define DEPS(i, a, b) deps(i, a, b)
#define DEP(i, n) dep(i, n)

#define pf push_front
#define pb push_back
#define mp make_pair
#define fst first
#define FST fst
#define sec second
#define SEC sec
#define sz(obj) ((int)(obj).size())
#define all(v) (v).begin(), (v).end()
#define ALL(v) all(v)

const int INF = 999999999;
const int MOD = 1e9 + 7;
const int dx[] = {0, 1, 0, -1}, dy[] = {1, 0, -1, 0};

inline bool inside(int y, int x, int H, int W) {return y >= 0 && x >= 0 && y < H && x < W;}
inline int in() {int x; std::cin >> x; return x;}
template <typename T>
void print(std::vector<T>& v, char c = ' ') {
  REP(i, v.size()) {
    if (i != 0) std::cout << c;
    std::cout << v[i];
  }
  std::cout << endl;
}
template <typename T> void print(T x) { std::cout << x << '\n'; }

signed main()
{
  int n = in();
  int a[3][n];
  int p[n];
  
  fill(p, p + n, 0);
  rep(i, n) rep(j, 3) a[j][i] = in();
  rep(i, 3) {
    rep(j, n) {
      bool flg = true;
      rep(k, n) if (j != k and a[i][j] == a[i][k]) flg = false;
      if (flg) p[j] += a[i][j];
    }
  }
  rep(i, n) print(p[i]);

  return (0);
}

Measured memory_bytes: 3152
#include<iostream>
#include<algorithm>
#include<math.h>
#include<queue>
#include<string>
#include<vector>
#include<tuple>
#include<stack>
#include<iomanip>
#include<map>
using namespace std;

int main() {
	char a;
	int b, c;
	cin >> b >> a >> c;
	if (a == '+') cout << b + c;
	else cout << b - c;
	return 0;
}

Measured memory_bytes: 256
from collections import deque
inf = -1

h,w = map(int,input().split())
s = []
for i in range(h):
    s.append(list(input()))
dx = [1,0,-1,0]
dy = [0,1,0,-1]

def bfs(sx,sy):
    d = [[inf] * w for _ in range(h)]
    que = deque()
    que.append([sx,sy])
    d[sx][sy] = 0
    while que:
        p = que.popleft()
        for i in range(4):
            nx = p[0] + dx[i]
            ny = p[1] + dy[i]
            if 0 <= nx < h and 0 <= ny < w and s[nx][ny] != '#' and d[nx][ny] == inf:
                que.append([nx,ny])
                d[nx][ny] = d[p[0]][p[1]] + 1
    cnt = 0
    for i in range(h):
        for j in range(w):
            cnt = max(cnt, d[i][j])
    return cnt

ans = 0
for i in range(h):
    for j in range(w):
        if s[i][j] != "#":
            ans = max(ans,bfs(i,j))
print(ans)

Measured memory_bytes: 44656
#include<iostream>
#include<vector>
#include<algorithm>
#include<set>
#include<queue>
#include<stack>
#include<map>
#include<math.h>
#include<string>
#include <cctype>
#include <cstdlib>
#include<bitset>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define reps(i, s, n) for (int i = s; i < (int)(n); i++)
#define out(x) cout << x << endl;
#define INF 1ll<<60;
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }

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

int main(){
    int l, r, d;
    cin >> l >> r >> d;

    int cnt=0, thr=l;

    while(thr<=r){
        if(thr%d==0)cnt++;
        thr++;
    }
    out(cnt);
}

Measured memory_bytes: 3632
#include "bits/stdc++.h"

using namespace std;

using ll = long long;
using ld = long double;

const double PI = 3.1415926535897932384626433832795;

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

int gcd(int x, int y) { return y ? gcd(y, x % y) : abs(x); }
ll gcd(ll x, ll y) { return y ? gcd(y, x % y) : abs(x); }
int lcm(int x, int y) { return x / gcd(x, y) * y; }
ll lcm(ll x, ll y) { return x / gcd(x, y) * y; }

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

	int a, p;
	cin >> a >> p;

	cout << (3 * a + p) / 2 << endl;
	return 0;
}


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

// 最小公倍数を求める
int euqlid (int a, int b){
  int temp;
  temp = a % b;
  if(temp == 0)return b;
  return euqlid(b,temp);
}

int main(){
  string w;
  cin >> w;
  if(w.length() % 2 != 0){
    cout << "No" << endl;
    return 0;
  }
  sort(w.begin(),w.end());
  rep(i,w.length()/2){
    if(w[i] != w[i+1]){
      cout << "No" << endl;
      return 0;
    }
    i++;
  }
  cout << "Yes" << endl;
}

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

int main() {
  int a, b, c;
  cin >> a >> b >> c;
  if (b - a == c - b) cout << "YES" << endl;
  else cout << "NO" << endl;
  return 0;
}

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

int main() {
  string sa, sb, sc;
  cin >> sa >> sb >> sc;

  int ai = 0, bi = 0, ci = 0;

  char prev = 'a';
  char next = sa[ai];
  char ans;
  while(true) {
    if (prev == 'a') {
      if (sa.length() == ai) {
        ans = 'A';
        break;
      }
      prev = sa[ai];
      ai++;
    } else if (prev == 'b') {
      if (sb.length() == bi) {
        ans = 'B';
        break;
      }
      prev = sb[bi];
      bi++;
    } else {
      if (sc.length() == ci) {
        ans = 'C';
        break;
      }
      prev = sc[ci];
      ci++;
    }
  }

  cout << ans << endl;
  
}


Measured memory_bytes: 256
import sys
input = sys.stdin.readline

def main():
    N = int(input())
    T, A = map(int, input().split())
    h = list(map(int, input().split()))
    ans = 0
    best = abs(T - h[ans] * 0.006 - A)
    for i in range(1, N):
        tmp = abs(T - h[i] * 0.006 - A)
        if tmp < best:
            best = tmp
            ans = i
    print(ans+1)

if __name__ == "__main__":
    main()

Measured memory_bytes: 3064
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <climits>
#include <cmath>
#include <ctime>
#include <cassert>
#include <iostream>
#include <fstream>
#include <sstream>
#include <iomanip>
#include <complex>
#include <string>
#include <vector>
#include <list>
#include <deque>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <bitset>
#include <iterator>
#include <functional>
#include <utility>
#include <algorithm>
#include <numeric>
#include <typeinfo>
 
using namespace std;
 
#define dump(n) cout<<"# "<<#n<<"="<<(n)<<endl
#define repi(i,a,b) for(int i=int(a);i<int(b);i++)
#define rep(i,n) repi(i,0,n)
#define iter(c) __typeof((c).begin())
#define foreach(i,c) for(iter(c) i=(c).begin();i!=(c).end();++i)
#define allof(c) (c).begin(),(c).end()
#define mp make_pair
 
typedef unsigned int uint;
typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<double> vd;
typedef vector<vd> vvd;
typedef vector<string> vs;
typedef pair<int,int> pii;
 
bool solve(vvi& field,int x,int y,int xg,int yg,int c)
{
    if(field[y][x]==0)
        return false;
    if(field[y][x]!=c)
        return false;
    if(x==xg && y==yg)
        return true;
    field[y][x]=-1;
    bool res=0;
    res|=solve(field,x-1,y,xg,yg,c);
    res|=solve(field,x+1,y,xg,yg,c);
    res|=solve(field,x,y-1,xg,yg,c);
    res|=solve(field,x,y+1,xg,yg,c);
    return res;
}
 
int main()
{
    for(int w,h;cin>>w>>h,w|h;){
        int xs,ys,xg,yg,n; cin>>xs>>ys>>xg>>yg>>n;
        vvi field(110,vi(110));
        rep(k,n){
            int c,d,x,y; cin>>c>>d>>x>>y;
            if(d)
                rep(i,4) rep(j,2)
                    field[y+i][x+j]=c;
            else
                rep(i,2) rep(j,4)
                    field[y+i][x+j]=c;
        }
        cout<<(solve(field,xs,ys,xg,yg,field[ys][xs])?"OK":"NG")<<endl;
    }
     
    return 0;
}


Measured memory_bytes: 3212
#include <bits/stdc++.h>
using namespace std;
int cnt[10004];
int main()
{
 int n;
 cin>>n;
 
 
     for(double j=1;j<=100;j++)
     {
         for(double k=1;k<=100;k++)
         {
             for(double l=1;l<=100;l++)
             {
                int sm=j*j+k*k+l*l+j*k+k*l+j*l;
                if(sm>n)
                continue;
                cnt[sm]++;
             }
         }
     }
 
 for(int i=1;i<=n;i++)
 cout<<cnt[i]<<endl;
   return 0;
}


Measured memory_bytes: 3552
#include<cstdio>
#include<bits/stdc++.h>
typedef long long int ll;
#define REP(i, n) for(int i = 0; i < (n); i++)
#define FOR_IN(i, a, b) for(int i = (a); i < (b); i++)
#define BETWEEN(x, a, b) ((x) >= (a) && (x) <= (b))
#define BIT(b, i) (((b) >> (i)) & 1)
#define LOG_F 1
#define LOG(...) if(LOG_F) fprintf(stderr, __VA_ARGS__)

using namespace std;

ll pow(int x, int n){
  return n == 0 ? 1 : x * pow(x, n - 1);
}


/*

 */
int a,b;

int main(){
  cin>>a>>b;
  if(a==1)
    a = 14;
  if(b==1)
    b = 14;

  if(a>b)
    cout << "Alice\n";
  else if(b>a)
    cout<<"Bob\n";
  else
    cout<<"Draw\n";

  return 0;
}


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

using namespace std;

int K,X,Y,N,ans;
int main()
{
	scanf("%d %d %d %d",&N,&K,&X,&Y);
	if(N>K) ans=K*X+(N-K)*Y;
	else ans=N*X;
	printf("%d",ans);
	return 0;
}

Measured memory_bytes: 256
N = int(input())
coords_list = tuple([(0, 0, 0)] + [tuple([int(elem) for elem in input().split(' ')]) for _ in range(N)])

for i in range(N):
    dt = coords_list[i + 1][0] - coords_list[i][0]
    diff = [abs(coords_list[i + 1][1] - coords_list[i][1]), 
            abs(coords_list[i + 1][2] - coords_list[i][2])]

    if sum(diff) > dt:
        print("No")
        exit(0)
    elif (diff[0] + diff[1]) % 2 == dt % 2:
        continue
    else: # diff == 0
        print("No")
        exit(0)
else:
    print("Yes")


Measured memory_bytes: 64728
#include "bits/stdc++.h"
#define in std::cin
#define out std::cout
#define rep(i,N) for(LL i=0;i<N;++i)
typedef long long int LL;

int main()
{
	LL N, M;
	in >> N >> M;
	std::vector<LL>p(M);
	std::vector<std::string>S(M);
	rep(i, M) in >> p[i] >> S[i];

	std::vector<bool>flag(N+1);
	std::vector<LL>w(N + 1);
	rep(i, M)
	{
		if (!flag[p[i]])
		{
			if (S[i] == "AC") flag[p[i]] = true;
			else ++w[p[i]];
		}
	}

	LL ans1 = 0, ans2 = 0;
	for (LL i = 1; i <= N; ++i)
	{
		if (flag[i])
		{
			++ans1;
			ans2 += w[i];
		}
	}

	out << ans1 << " " << ans2 << std::endl;
}


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

#define INF (1 << 30)
#define pb push_back
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define out(x) cout << x << endl;
#define all(x) (x).begin(),(x).end()
typedef long long ll;
using namespace std;

int main(){
    int N;
    cin >> N;
    ll h[N];
    bool ans = false;
    int tmp = 0;
    rep(i, N){
        cin >> h[i];
        if(tmp < h[i]){
            tmp = h[i] - 1;
        }else if(tmp == h[i]){
            tmp = h[i];
        }else if(tmp > h[i]){
            ans = false;
            out("No");
            return 0;
        }
    }
    out("Yes");
    return 0;
}

Measured memory_bytes: 1024
import javax.print.DocFlavor;
import java.awt.*;
import java.io.PrintWriter;
import java.lang.reflect.Array;
import java.math.BigInteger;
import java.util.*;
import java.util.List;

public class Main {

    static String br = System.getProperty("line.separator");
    static Scanner sc = new Scanner(System.in);
    static PrintWriter out = new PrintWriter(System.out);

    private static int Q;
    private static int N;
    private static int M;
    private static int[] a;
    private static int[] b;
    private static int[] c;
    private static int[] d;

    public static void main(String[] args) {
        String s = next();
        
        if(s.equals("ABC")){
            println("ARC");
        }else{
            println("ABC");
        }
    }

    static int nextInt() {
        return Integer.parseInt(next());
    }

    static Long nextLong() {
        return Long.parseLong(next());
    }

    static String next() {
        return sc.next();
    }

    static String nextLine(){
        return sc.nextLine();
    }

    static void println(Object o) {
        out.println(o);
        out.flush();
    }

    static void print(Object o) {
        PrintWriter out = new PrintWriter(System.out);
        out.print(o);
        out.flush();
    }
}


Measured memory_bytes: 35724
import sys
IS = lambda: sys.stdin.readline().rstrip()
II = lambda: int(IS())
MII = lambda: list(map(int, IS().split()))
def isPrime(n):
    if n == 1: return False
    for i in range(2,int(n**0.5)+1):
        if n % i == 0: return False
    return True

def main():
    n = II()
    pp = []
    p = 1
    cnt = 0
    while cnt < n:
        p += 10
        if isPrime(p): pp.append(p); cnt += 1
    print(*pp)

if __name__ == '__main__':
    main()


Measured memory_bytes: 3188
import numpy as np

h, w = [int(i) for i in input().split()]
grid = []
for i in range(h):
    grid.append(list(input()))
grid = (np.array(grid) == ".") * 1

L = np.zeros((h, w), dtype=int)
R = np.zeros((h, w), dtype=int)
U = np.zeros((h, w), dtype=int)
D = np.zeros((h, w), dtype=int)

for j in range(w):
    if j == 0:
        L[:, j] = grid[:, j]
    else:
        L[:, j] = (L[:, j - 1] + 1) * grid[:, j]


for j in range(w - 1, -1, -1):
    if j >= w - 1:
        R[:, j] = grid[:, j]
    else:
        R[:, j] = (R[:, j + 1] + 1) * grid[:, j]

for i in range(h):
    if i <= 0:
        U[i, :] = grid[i, :]
    else:
        U[i, :] = (U[i - 1, :] + 1) * grid[i, :]


for i in range(h - 1, -1, -1):
    if i >= h - 1:
        D[i, :] = grid[i, :]
    else:
        D[i, :] = (D[i + 1, :] + 1) * grid[i, :]

print(np.max(L + R + U + D - 3))


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


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

	if (a <= 5) {
		cout << 0;
	}
	else if (a <= 12) {
		cout << b / 2;
	}
	else {
		cout << b;
	}

	cout << endl;


	return 0;
}

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

int main() {
	int A, B;
	int sum, pull, mul, maxNum;

	cin >> A >> B;

	sum = A + B;
	pull = A - B;
	mul = A * B;

	maxNum = 0;

	maxNum = max(sum, pull);
	maxNum = max(maxNum, mul);

	cout << maxNum << endl;

	return 0;
}

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

int op(int a, int b, int i){
  int c = i==0 ? a+b : a-b;
  return(c);
}

int main(void){
  string s;
  cin >> s;
  int a,b,c,d;
  a = s[0]-48; b = s[1]-48; c = s[2]-48; d = s[3]-48; 
  
  char c_op[2] = {'+','-'};
  int flag = 0;  
  for(int i = 0; i < 2; i++){
    int r = op(a,b,i);
    for(int j = 0; j < 2; j++){
      int r2 = op(r,c,j);
      for(int k = 0; k < 2; k++){
        if(op(r2,d,k)==7 && flag == 0){
          cout << a << c_op[i] << b << c_op[j] << c << c_op[k] << d << "=7" << endl;            
          flag = 1;
        }
      }
    }
  }
}

Measured memory_bytes: 256
#define _GLIBCXX_DEBUG
#include<bits/stdc++.h>
using namespace std;
typedef long long int lli;
typedef unsigned long long int ulli;
#define vec(s) vector

#define vvec(s) vector<vector
>
typedef vector<lli> vi;
typedef vector<vi> vvi;
typedef pair<lli,lli> pii;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define YN(x) cout<<(bool x?"Yes":"No")<<endl;
#define out(s) cout<<s<<endl;
#define pb(s) push_back(s);
#define sp " ";
#define INF 10000000000
#define all(s) s.begin(),s.end()
void vout(vi v){
    for(int i=0;i<v.size();i++)
    cout<<v.at(i)<<endl;
}
int main(){
    lli n;
    cin >> n;
    vi a(n);
    queue<lli> next;
    rep(i, n) cin >> a[i];
    sort(all(a));
    reverse(all(a));
    lli ans = 0;
    rep(i,n){
        if(i==0){
            next.push(a[i]);
        }
        else{
            lli p = next.front();
            next.pop();
            ans += p;
            next.push(a[i]);
            next.push(a[i]);
        }
    }
    out(ans);
}

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

int main () {
  int a ,b ;
  cin >> a >> b ;
  int pre = 0 ;
  pre = max(a,b) ;
  if(a!=b)
  cout << pre + (pre -1 ) << endl ;
  else
    cout << pre * 2 << endl ;
}

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

int main(void)
{
	string s;

	cin >> s;

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

	if (s[0] == s[1] && s[2] == s[3] && s[0] != s[2])
		cout << "Yes";
	else
		cout << "No";

	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using uint = unsigned int;
using lint = long long int;
using ulint = unsigned long long int;
template<class T = int> using V = vector<T>;
template<class T = int> using VV = V< V<T> >;
template<class T, class U> void assign(V<T>& v, int n, const U& a) { v.assign(n, a); }
template<class T, class... Args> void assign(V<T>& v, int n, const Args&... args) { v.resize(n); for (auto&& e : v) assign(e, args...); }


int main() {
  cin.tie(nullptr); ios_base::sync_with_stdio(false);
  int n; cin >> n;
  V<> a(n); for (int i = 0; i < n; ++i) cin >> a[i];
  VV<> b(30);
  for (int i = 0; i < n; ++i) {
    b[__builtin_ctz(a[i])].push_back(a[i]);
  }
  int res = 0;
  for (int j = 0; j < 30; ++j) {
    sort(begin(b[j]), end(b[j]));
    int m = b[j].size();
    V<bool> used(m);
    map<int, int> mp;
    for (int i = m - 1; i >= 0; --i) {
      if (used[i]) continue;
      int s = 1 << __lg(b[j][i]) + 1;
      if (!binary_search(begin(b[j]), next(begin(b[j]), i), s - b[j][i])) continue;
      int ip = distance(begin(b[j]), lower_bound(begin(b[j]), end(b[j]), s - b[j][i]));
      if (mp.count(s - b[j][i])) ip = mp[s - b[j][i]];
      while (used[ip] and ip + 1 < m and b[j][ip + 1] == s - b[j][i]) ++ip;
      mp[s - b[j][i]] = ip;
      if (used[ip]) continue;
      if (i == ip) continue;
      ++res;
      used[i] = true;
      used[ip] = true;
    }
  }
  cout << res << '\n';
}

Measured memory_bytes: 3444
import sys
input = sys.stdin.readline

n,m = map(int,input().split())
lr = [ list(map(int,input().split())) for _ in range(m) ]
# print(lr)

l = []
r = []
for i in range(m):
    l.append(lr[i][0])
    r.append(lr[i][1])
# print(l)
# print(r)
l_max = max(l)
r_min = min(r)
if r_min>=l_max:
    ans = r_min - l_max + 1
else:
    ans = 0
print(int(ans))

Measured memory_bytes: 29072
#include<iostream>
#include<cstring>
#include<string>
#include<algorithm>
#include<cstdio>
using namespace std;

int main() {
	int i,j,n,m,flag=0;
	cin>>n>>m;
	if( n%m==0 )
		cout<<"0\n";
	else
		cout<<"1\n";
	return 0;
	}

Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<algorithm>
#include <string.h>
#include <stdio.h>
#include <math.h>
#include <set>
#include <queue>
#include <stack>
#include <map>

using namespace std;
typedef int status;
typedef long long ll;
typedef unsigned long long ull;
const ull base = 343;
const int INF = int(1e9);
const ll INF1 = ll(1e15);
const int MAX = 20002;

int N,flag;
ll sum,min1 = INF1;

struct S{
    ll a,b;
}M[100005];

int main()
{
    cin>>N;
    for(int i = 1;i <= N;i++){
        cin>>M[i].a>>M[i].b;
        sum += M[i].a;
        if(M[i].a > M[i].b){
            min1 = min1 > M[i].b?M[i].b:min1;
        }
        if(M[i].a!=M[i].b)flag = 1;
    }

    if(flag == 0){
        cout<<0<<endl;
        return 0;
    }

    cout<<sum - min1 <<endl;


    return 0;
}


Measured memory_bytes: 512
//#pragma GCC optimize("Ofast")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx")

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

#define ll long long
#define ld long double
#define F first
#define S second
#define pb push_back
#define sqr(x) (x) * (x)

using namespace std;
using namespace __gnu_pbds;

mt19937_64 gen(time(0));

typedef tree<
pair <int, int>,
null_type,
less<pair <int, int>>,
rb_tree_tag,
tree_order_statistics_node_update>
ordered_set;

//const int mod = 1e9 + 7;

//const int inf = 1e9;
//const int maxn = 1e6 + 66;

int a[1002];

signed main()
{
    cin.tie(0);
    cout.tie(0);
    ios_base::sync_with_stdio(false);
#ifdef LOCAL
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
#else

#endif
    int n, k;
    cin >> n >> k;
    for(int i = 0; i < n; ++i)
        cin >> a[i];
    sort(a, a + n);
    int ans = 0;
    for(int i = 0; i < k; ++i)
        ans += a[i];
    cout << ans;
    return 0;
}


Measured memory_bytes: 3660
def main():
  import sys
  input=sys.stdin.buffer.readline
  h,w=map(int,input().split())
  b,q=b'.'*w,range(w)
  for i in range(h):
    s=input()
    a=[]
    for x,y,z,c in zip(b,b'.'+s,s,q):
      c+=x==46>z
      i+=y==46>z
      if i>c:i=c
      a+=i,
    b,q=s,a
  print(i)
main()

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

using namespace std;
int main()
{
    int x1,y1,x2,y2;
    while (~scanf("%d%d%d%d",&x1,&y1,&x2,&y2)){
        int c1=x2-x1;
        int c2=y2-y1;
        for (int i=0;i<c2;++i)
            printf("U");
        for (int i=0;i<c1;++i)
            printf("R");
        for (int i=0;i<c2;++i)
            printf("D");
        for (int i=0;i<c1;++i)
            printf("L");
        printf("L");
        for (int i=0;i<=c2;++i)
            printf("U");
        for (int i=0;i<=c1;++i)
            printf("R");
        printf("D");
        printf("R");
        for (int i=0;i<=c2;++i)
            printf("D");
        for (int i=0;i<=c1;++i)
            printf("L");
        printf("U\n");
    }
    return 0;
}


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



int main()
{
  long long int a;
  cin >> a;
	
  for(int i=-120;i<=120;i++){
    for(int j=-120;j<=120;j++){
      
if(i*i*i*i*i - j*j*j*j*j == a){
  
  cout << i << " " << j << endl;
  return 0;
}
      
  
    }  
}
        
}      
        
 
  


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

#define rep(i,n) for(int i=0;i<n;i++)
#define REP(i,s,n) for(int i=(s);i<=(n);i++)
#define repr(i,n) for(int i=n-1;i>=0;i--)
#define REPR(i,s,n) for(int i=(s);i>=(n);i--)
#define all(a) (a).begin(),(a).end()
#define rall(a) (a).rbegin(),(a).rend()
#define Eunique(v) v.erase(unique(all(v)),v.end())
#define Eback(s) s.erase(s.end()-1,s.end())
#define rev(v) reverse(all(v))
#define minvec(v) *min_element(all(v))
#define maxvec(v) *max_element(all(v))
#define pb push_back
#define pf push_front
#define mod 1000000007
#define m_p make_pair
#define DOUBLE fixed << setprecision(15)
#define OK puts("OK")
#define OK1 puts("OK1")
#define OK2 puts("OK2")
#define SIZE(s) (int)s.size()
#define INF ((1LL<<62)-(1LL<<31))
#define zero(x,n) setw(x) << setfill('0') << n

typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<double> vd;
typedef long long ll;
typedef vector<ll> vll;
typedef vector<vll> vvll;
typedef pair<ll,ll> pll;
typedef pair<int,int> pii;
typedef vector<pair<int,int>> vpii;
typedef vector<pair<ll,ll>> vpll;
typedef vector<string> vs;
const double pi = acos(-1.0);

template<class A, class B>
ostream& operator<<(ostream& ost, const pair<A, B>&p) {
	ost << "{" << p.first << ", " << p.second << "} ";
	return ost;
}

template<class T>
ostream& operator<<(ostream& ost, const vector<T>&v) {
	ost << "{";
	for (int i = 0; i<(int)v.size(); i++) {
		if (i)ost << " ";
		ost << v[i];
	}
	ost << "} \n";
	return ost;
}

template<class A, class B>
ostream& operator<<(ostream& ost, const map<A, B>&v) {
	ost << "{";
	for (auto p:v) {
		ost << "{" << p.first << ", " << p.second << "} ";
	}
	ost << "} ";
	return ost;
}

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

ll gcd(ll x, ll y) {return __gcd(x,y);}
ll lcm(ll x, ll y) {return x/__gcd(x,y)*y;}

int main()
{
	ll x;
	vll v;
	while(1){
		cin >> x;
		if(x==0) break;
		v.pb(x);
	}
	rep(i,SIZE(v)) cout << "Case " << i+1 << ": " << v[i] << endl;
	return 0;
}


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

#define ALL(v) v.begin(), v.end()
#define V vector
#define P pair
typedef long long ll;
const int INT_INF = 1e9;
const ll INF = 1LL << 30;
const ll MOD = 1e9 + 7;

const ll limit = 100010;
using edge = struct { ll to; ll cost; };
V<edge> G[limit];
ll dis[limit];

void dfs(ll v, ll p, ll d){
    dis[v] = d;
    for(auto g : G[v]){
        if(g.to == p) continue;
        dfs(g.to, v, d + g.cost);
    }
}

int main() {
    ll n; cin >> n;
    for(int i = 0; i < n - 1; i++){
        ll a, b, c; cin >> a >> b >> c;
        a--, b--;
        G[a].push_back({b, c});;
        G[b].push_back({a, c});
    }

    ll q, k; cin >> q >> k;
    k--;

    dfs(k, -1, 0);

    for(int i = 0; i < q; i++){
        ll x, y; cin >> x >> y;
        x--, y--;
        cout << dis[x] + dis[y] << endl;
    }
}


Measured memory_bytes: 14336
#include <bits/stdc++.h>
using namespace std;
#define REP(i,n) for(int i=0; i<(n); i++)
#define REP2(i,x,n) for(int i=x; i<(n); i++)
int main()
{
    int H,W,N;
    cin >> H>>W>>N;


    int high = max(H,W);

    int ans = (N-1)/(high) + 1;
    cout << ans << endl;

   return 0;
}

Measured memory_bytes: 256
// vim:ts=4:sts=4:sw=4:et
// MOSCOW IPT JINOTEGA
// Table #14
#include <bits/stdc++.h>
using namespace std;
#define forn(i,n) for (int i = 0; i < int(n); ++i)
#define sz(x) ((int) (x).size())
#define all(x) (x).begin(), (x).end()
typedef long double ld;
typedef long long ll;
typedef long long i64;

const int M = 100100;

ll n, a[M];
ll l[M], r[M];

void read() {
    cin >> n;
    for (int i = 0; i < n; ++i)
        cin >> a[i];
    reverse(a, a + n);
}

void kill() {
    if (a[0] != 2) {
        cout << "-1\n";
        return;
    }

    l[0] = 2, r[0] = 3;
    for (int i = 1; i < n; ++i) {
        l[i] = (l[i - 1] + a[i] - 1) / a[i] * a[i];
        r[i] = r[i - 1] / a[i] * a[i] + (a[i] - 1);
        if (r[i] < l[i]) {
            cout << "-1\n";
            return;
        }
    }
    cout << l[n - 1] << " " << r[n - 1] << endl;
}

int main() {
#ifdef LOCAL
    assert(freopen("b.in", "r", stdin));
#endif
    ios_base::sync_with_stdio(false);

    read();
    kill();

    return 0;
}



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

#define mp make_pair
#define eb emplace_back
#define ff first
#define ss second

using namespace std;

typedef long long ll;
typedef unsigned long long ull;

const int MAXN = 100;
//#define int long long
const int INF = 1e9;

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

    int n;
    ll d;
    cin >> n >> d;
    d *= d;
    int ans = 0;

    ll x, y;
    for (int i = 0; i < n; i++){
    	cin >> x >> y;
    	ll dd = x * x + y * y;
    	if (dd <= d) ans++;
    }


    cout << ans << '\n';
    return 0;
}


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

int main(){
  int ans = 0;
  string s;
  cin >> s;
  if(s.at(0) == '1')
    ans++;
  if(s.at(1) == '1')
    ans++;
  if(s.at(2) == '1')
    ans++;
  
  cout << ans << endl;
}
   

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define mk make_pair
#define fs first
#define sc second
using namespace std;
typedef long long ll;
typedef long double ld;
bool can[4][4][10010];
int main(){
	vector<string> s(3);
	cin>>s[0]>>s[1]>>s[2];
	int n=s[0].size()+s[1].size()+s[2].size();
	sort(s.begin(), s.end());
	int ans=n;
	for(int i=0; i<3; ++i){
		for(int j=0; j<3; ++j){
			for(int k=0; k<n; ++k){
				can[i][j][k]=1;
			}
		}
	}
	for(int i=0; i<3; ++i){
		for(int j=0; j<3; ++j){
			if(i==j){
				continue;
			}
			for(int k=0; k<s[i].size(); ++k){
				can[i][j][k]=1;
				for(int l=0; l+k<s[i].size()&&l<s[j].size(); ++l){
					if(s[i][l+k] != s[j][l] && s[i][l+k]!='?' && s[j][l]!='?'){
						can[i][j][k]=0;
						break;
					}
				}
			}
		}
	}
	map<string ,int> mp;
	mp[s[0]]=0;
	mp[s[1]]=1;
	mp[s[2]]=2;
	do{
		int tmp1=mp[s[0]], tmp2=mp[s[1]], tmp3=mp[s[2]];
		for(int i=0; i<s[0].size(); ++i){
			if(!can[tmp1][tmp2][i])
				continue;
			ans=min(ans, n-min((int)s[1].size(), ((int)s[0].size()-i)));
			for(int j=0; j<s[1].size()||j+i<s[0].size(); ++j){
				if(j<s[1].size())
				if(!can[tmp2][tmp3][j])
					continue;
				if(j+i<s[0].size()){
					if(!can[tmp1][tmp3][j+i]){
						continue;
					}
				}
				ans=min(ans, max(max((int)s[0].size(), (int)s[1].size()+i), (int)s[2].size()+i+j));
				break;
			}
		}
	}while(next_permutation(s.begin(), s.end()));
	printf("%d\n",ans);
	return 0;
}




Measured memory_bytes: 384
//#include "bits/stdc++.h"

#define _USE_MATH_DEFINES
#include<cstdio>
#include <cstring>
#include <cmath>
#include <cstdlib>
#include <deque>
#include <algorithm>
#include <functional>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>
#include <iterator>
#include<iomanip>
#include<unordered_set>
#include<bitset>
#include<complex>

using namespace std;

#define rep(i,a,b) for(int i=(a), i##_len=(b);i<i##_len;i++)
#define rrep(i,a,b) for(int i=(b)-1;i>=(a);i--)
#define all(c) begin(c),end(c)

#define int ll
#define SZ(x) ((int)(x).size())
#define pb push_back
#define mp make_pair

//typedef unsigned long long ull;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<ll, int> pli;
typedef pair<double, double> pdd;
typedef vector< vector<int> > mat;

template<class T> bool chmax(T &a, const T &b) { if (a < b) { a = b; return true; } return false; }
template<class T> bool chmin(T &a, const T &b) { if (b < a) { a = b; return true; } return false; }

const int INF = sizeof(int) == sizeof(long long) ? 0x3f3f3f3f3f3f3f3fLL : 0x3f3f3f3f;
const int MOD =  (int)1e9 + 7;
const double EPS = 1e-9;

int N, X;
int A[100010];

signed main()
{
	cin.tie(0);
	ios::sync_with_stdio(false);
	
	cin >> N >> X;
	rep(i, 0, N)
	{
		cin >> A[i];
	}
	int ans = 0;
	if (A[0] > X)
	{
		ans += A[0] - X;
		A[0] = X;
	}
	rep(i, 1, N)
	{
		int res = max(0LL, A[i - 1] + A[i] - X);
		A[i] -= res;
		ans += res;
	}

	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 1024
#include<bits/stdc++.h>
#define rep(i,a,b) for(int i=a;i<b;i++)
#define rrep(i,a,b) for(int i=a;i>=b;i--)
#define fore(i,a) for(auto &i:a)
#define all(x) (x).begin(),(x).end()
//#pragma GCC optimize ("-O3")
using namespace std; void _main(); int main() { cin.tie(0); ios::sync_with_stdio(false); _main(); }
typedef long long ll; const int inf = INT_MAX / 2; const ll infl = 1LL << 60;
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 (b<a) { a = b; return 1; } return 0; }
//---------------------------------------------------------------------------------------------------
/*---------------------------------------------------------------------------------------------------
　　　　　　　　　　　 ∧＿∧  
　　　　　 ∧＿∧ 　（´<_｀ ）　 Welcome to My Coding Space!
　　　　 （ ´_ゝ`）　/　 ⌒i     
　　　　／　　　＼　 　 |　|     
　　　 /　　 /￣￣￣￣/　　|  
　 ＿_(__ﾆつ/　    ＿/ .| .|＿＿＿＿  
　 　　　＼/＿＿＿＿/　（u　⊃  
---------------------------------------------------------------------------------------------------*/












int N, D, A[301010];
//---------------------------------------------------------------------------------------------------
int zikken(int n, int d) {
    if (n == 1) return 0;

    set<int> gg;
    rep(i, 1, n) if (n - i <= d) gg.insert(zikken(i, d));

    int ng = 0;
    while (gg.count(ng)) ng++;
    return ng;
}
//---------------------------------------------------------------------------------------------------
void _main() {
    cin >> N >> D;
    rep(i, 0, N) cin >> A[i];

    //rep(i, 1, 20) rep(d, 1, 2) printf("g(%d,%d) = %d\n", i, d, zikken(i, d));

    int g = 0;
    rep(i, 0, N) g ^= (A[i] - 1) % (D + 1);

    if (g == 0) printf("Second\n");
    else printf("First\n");
}


Measured memory_bytes: 4056
m = 1000000007
s = int(input())
ways = [1]*10000
ways[0] = 0
ways[1] = 0
ways[2] = 0
ans = ways[3]

for i in range(6,s+1):
  ways[i] = ways[i]+ans
  ans += ways[i-2]
print(ways[s]%m)




Measured memory_bytes: 9256
#include <iostream>
#include <fstream>
#include <cstdio>
#include <cmath>
#include <vector>
#include <string>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <deque>
#include <bitset>
#include <algorithm>
#include <complex>
#include <array>
#include <functional>
#include <stack>
#include <iomanip>
#include <limits>
using namespace std;
#define REP(i,n) for(int i=0; i<n; ++i)
#define FOR(i,a,b) for(int i=a; i<=b; ++i)
typedef long long ll;
typedef vector<int> VI;
typedef vector<ll> VL;
typedef vector<double> VD;

#define INF 1e+9
#define MAX_V 300

struct edge {
    int to;
    int cost;
};
using P = pair<ll, ll>;
ll gcd(ll x, ll y)
{
  if(x<y)
  {
    swap(x,y);
  }
  while(y>0)
  {
    ll r=x%y;
    x=y;
    y=r;
  }
  return x;
}
int main(){
  ll x;cin>>x;
  if(400<=x&&x<600){
    cout<<8<<endl;
  }
  if(600<=x&&x<800){
    cout<<7<<endl;
  }
  if(800<=x&&x<1000){
    cout<<6<<endl;
  }
  if(1000<=x&&x<1200){
    cout<<5<<endl;
  }
  if(1200<=x&&x<1400){
    cout<<4<<endl;
  }
  if(1400<=x&&x<1600){
    cout<<3<<endl;
  }
  if(1600<=x&&x<1800){
    cout<<2<<endl;
  }
  if(1800<=x&&x<2000){
    cout<<1<<endl;
  }
}

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

typedef long long ll;

int main(void) {

    int N; cin >> N;
    vector<ll> A(N);
    for (int i = 0; i < N; i++) cin >> A[i];

    int odd_cnt = 0;
    for (int i = 0; i < N; i++) {
        if (A[i]%2) odd_cnt++;
    }

    if (N == 1 || odd_cnt%2 == 0) {
        cout << "YES" << endl;
    } else {
        cout << "NO" << endl;
    }

    return 0;
}

Measured memory_bytes: 1152
#include<iostream>
using namespace std;
int main(){
  int n,ans;
  cin >> n;ans = 0;
  if (n>=105) ans += 1;
  if (n>=135) ans += 1;
  if (n>=165) ans += 1;
  if (n>=189) ans += 1;
  if (n>=195) ans += 1;
  cout << ans << endl;
}
  


Measured memory_bytes: 256
#include<stdio.h>

typedef long long int int64;

#define ABS(a) ((a)>(0)?(a):-(a))

void run(void){
  int64 x,y;
  scanf("%lld%lld",&x,&y);
  puts(ABS(x-y)>1?"Alice":"Brown");
}

int main(void){
  run();
  return 0;
}

Measured memory_bytes: 128
//libraries
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/detail/standard_policies.hpp>

//namespace
using namespace std;
using namespace __gnu_pbds;

//typedef
//typedef tree<long long,null_type,less<long long>,rb_tree_tag,tree_order_statistics_node_update> ordered_set;
//typedef tree<long long,null_type,greater<long long>,rb_tree_tag,tree_order_statistics_node_update> ordered_set1;
typedef long long ll;
typedef long double ld;
typedef pair<int,int> pii;
typedef pair<long long,long long> pll;

//define
#define i(X) cin>>X;
#define o(X) cout<<X<<endl;
#define pb push_back
#define pf push_front
#define fi first
#define se second
#define line cout<<"\n";
#define pbp(a,b) push_back(make_pair(a,b));
#define vll(A) vector<long double> A;
#define ivect(A,n,p) vector<long long> A(n,p);
#define vst(A) sort(A.begin(),A.end());
#define rvst(A) sort(A.rbegin(),A.rend());
#define forin(i,a,b) for(long long i=a;i<=b;i++)
#define forde(i,a,b) for(long long i=a;i>=b;i--)
#define fio ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);

const long long inf=(long long)1e18;
const long long mod=(long long)(1e9+7);

ll power(ll x, ll y, ll p) 
{ 
    ll res = 1;      // Initialize result 
  
    x = x % p;  // Update x if it is more than or 
                // equal to p 
  
    while (y > 0) 
    { 
        // If y is odd, multiply x with result 
        if (y & 1) 
            res = (res*x) % p; 
  
        // y must be even now 
        y = y>>1; // y = y/2 
        x = (x*x) % p; 
    } 
    return res; 
} 
ll modInverse(ll a,ll p)
{
   return power(a,p-2,p);
}

int main()
{
    // #ifndef ONLINE_JUDGE
    //    freopen ("input.txt" , "r" , stdin);
	// 	// freopen ("OUTPUT.txt" , "w" , stdout);
	// #endif
    fio;
    ll testcase=1;
    //i(testcase);
    while(testcase--)
    {
        map<ll,ll> a,xx;
        //ll b[1000001]={0};
        ll mx=0;
        ll n;
        i(n);
        ll x[n];
        forin(i,0,n-1)
        {
            i(x[i]);
            a[x[i]]++;
            //b[x[i]]++;
            mx=max(mx,x[i]);
        }
        ll ans=0;
        sort(x,x+n);
        forin(i,0,n-1)
        {
            if(a[x[i]])
            {
                if(a[x[i]]>1)
                xx[x[i]]++;
                for(ll j=2*x[i];j<=mx;j+=x[i])
                {
                    if(a[j])
                    {
                        xx[j]++;
                    }
                }
            }
            a[x[i]]=0;
        }
        forin(i,0,n-1)
        {
            if(xx[x[i]]==0)
            {
                ans++;
            }
        }
        o(ans);
    }
    return 0;
}

Measured memory_bytes: 76868
#include<stdio.h>
int m[1000000];
int main(void){
    int n,i,j,cnt;
    while(scanf("%d",&n)!=EOF){
        cnt=0;
        for(i=0;i<=n;i++){
            m[i]=i;
        }
        m[1] = 0;
        for(i=2;i<=n;i++){
            for(j=2;i*j<=n;j++){
                m[i*j]=0;
            }
        }
        i=0;
        while(i <= n){
            if(m[i]!=0)
                cnt++;
            i++;
        }
        printf("%d\n",cnt);
    }
    return 0;
}

Measured memory_bytes: 4500
#include<stdio.h>
#include<stdlib.h>
#include<stdlib.h>
long long g(long long int n){
	if(n==0){
		return 2;
	}
	else{
		return g(n-1)*2+2; 
	}
}
int main(){
	long long n,k;
	scanf("%lld",&n);
	k=g(n);
	printf("%lld",k);
	return 0;
}

Measured memory_bytes: 128
def main():
    N, M = map(int, input().split())
    kukan_list = sorted([list(map(int, input().split())) for _ in range(M)], key=lambda x: x[1])
    ans = 0
    cut = 0
    
    for kukan in kukan_list:
        if cut >= kukan[0]:
            continue
        ans += 1
        cut = kukan[1] - 1
    
    print(ans)

if __name__ == "__main__":
    main()

Measured memory_bytes: 65304
#include <cstdio>
#include <iostream>
#include <vector>
#include <queue>
#include <utility>
#include <map>
#include <algorithm>

#define REP(i, a, b) for (int i=a; i <b; i++)

using namespace std;

typedef long long ll;
typedef vector< int > vi;



int main() {

    int n, k;
    scanf("%d %d", &n, &k);

    vi a(n);
    REP(i, 0, n) {
        scanf("%d", &a[i]);
    }

    int j = 0;
    int x;
    int y=0;

    sort(a.begin(), a.end());
    priority_queue < int, vector< int >, greater< int > > q;
    
    x = -1;
    int diffn = 0;
    while (j < n) {
        if (x == -1) {
            x = a[j];
            diffn++;
        }
        if (x == a[j]) {
            y++;
            j++;
        } else {
            q.push(y); 
            y = 0;
            x = -1;
        }
        if (j == n) {
            q.push(y);
        }
    }

    int ans = 0;
    while (diffn > k) {
        ans += q.top();
        q.pop();
        diffn--;
    }

    printf("%d\n", ans);
    return 0;
}

Measured memory_bytes: 2168
#include<iostream>
#include<cstdio>
using namespace std;
int n,m;
int main()
{
	scanf("%d%d",&n,&m);
	if(n%(2*m+1)) cout<<n/(2*m+1)+1<<endl;
	else cout<<n/(2*m+1)<<endl;
	return 0;
}

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

int main(){
    int N,M,L = 0;
    cin >> N >> M;
    vector <int> m(M);
    rep(i,m.size()){
        cin >> m.at(i);
        }
    rep(i,M){
        L += m.at(i);
    }
    if(N-L < 0) {
        cout << "-1" << endl;
    } else{
        cout << N - L << endl;
        }
    }

Measured memory_bytes: 3636
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair< ll, ll > Pi;
#define rep(i,n) for(int i=0;i<(n);i++)
#define rep2(i,n) for(int i=1;i<=(n);i++)
#define rep3(i,i0,n) for(int i=i0;i<(n);i++)
#define pb push_back
#define mod 1000000007
const ll INF = 1LL << 60;
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 (b<a) { a=b; return 1; } return 0; }
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;}
#define all(x) x.begin(), x.end()
#define mp make_pair
bool compare(Pi a, Pi b) {
    if(a.first != b.first){
        return a.first < b.first;
        
    }else{
        return a.second < b.second;
    }
}


bool In_map(ll y,ll x,ll h,ll w){
    if(y<0 || x<0 || y>=h || x>=w){
        return 0;
    }else{
        return 1;
    }
}
const vector<ll> dx{1,0,-1,0};
const vector<ll> dy{0,1,0,-1};
const int MAX = 510000;
const int MOD = 1000000007;

long long fac[MAX], finv[MAX], inv[MAX];

// テーブルを作る前処理
void COMinit() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (int i = 2; i < MAX; i++){
        fac[i] = fac[i - 1] * i % MOD;
        inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
        finv[i] = finv[i - 1] * inv[i] % MOD;
    }
}

// 二項係数計算
long long COM(int n, int k){
    
    if (n < 0 || k < 0) return 0;
    if (n < k) return 0;
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}

int main() {
    COMinit();
    ll N,K;
    cin >>N>>K;
    if(N==K){
        cout<<1<<endl;
        rep(i,K-1){
            cout<<0<<endl;
        }
        return 0;
    }
    rep2(i,K){
        ll ans = (2*((COM(K-1,i-1)*COM(N-K-1,i-1))%mod)+ (COM(K-1,i-1)*COM(N-K-1,i))%mod + (COM(K-1,i-1)*COM(N-K-1,i-2))%mod)%mod;
        cout<<ans<<endl;
    }
    



    return 0;
    

}

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

using namespace std;
typedef long long ll;
#define rep(i, n) for (ll i = 0; i < (ll)(n); ++i)
#define erep(i, n) for (ll i = 0; i <= (ll)(n); ++i)
#define FOR(i,a,b) for (ll i = (a); i < (ll)(b); ++i)
#define EFOR(i,a,b) for (ll i = (a); i <= (ll)(b); ++i)
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } }


int main() {
    int a,b; cin >> a >> b;
    
    cout << (a+b)%24 << endl;
    
    return 0;
}


Measured memory_bytes: 256
//----------BHAVIK DIWANI(PICT_COMP)---------------
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#define test ll t; cin>>t; while(t--)
#define fastio ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define mod 1000000007
#define ll long long
#define int long long
#define ull unsigned long long
#define MAX 1000005
#define pb push_back
#define mkp make_pair
#define vi vector<int>
#define pii pair<int,int>
#define endl '\n'
#define vs vector<string>
#define mii map<int,int>
#define msi map<string,int>
#define vpii vector< pair<int, int > >
#define vpsi vector< pair< string ,int > >
#define forci(p,q) for(int i=p;i<q;i++)

using namespace std;
int solve()
{	
	int a,b;
	cin>>a>>b;
	int x=a+b;
	int y=a-b;
	int z=a*b;
	x=max(x,y);
	x=max(z,x);
	cout<<x<<endl;
	return 0;
}
signed main()
{
	fastio;
//	test
		solve();
}



Measured memory_bytes: 3660
#include <bits/stdc++.h>
#define ll long long
#define Nmax 1005
#define MOD 1000000007
using namespace std;

ll n, m, dp[Nmax][Nmax];

void read()
{
    cin >> n >> m;
    char c;
    for (int i = 1; i <= n; ++i) {
        for (int j = 1; j <= m; ++j) {
            cin >> c;
            if (c == '#') {
                dp[i][j] = -1;
            }
        }
    }
}

void solve()
{
    int col = 1;
    while (!dp[1][col] && col <= m) {
        dp[1][col] = 1;
        ++col;
    }

    int row = 2;
    while (!dp[row][1] && row <= m) {
        dp[row][1] = 1;
        ++row;
    }

    for (int i = 2; i <= n; ++i) {
        for (int j = 2; j <= m; ++j)
        if (dp[i][j] != -1) {
            ll valLeft = (dp[i][j - 1] == -1) ? 0 : dp[i][j - 1];
            ll valUp = (dp[i - 1][j] == -1) ? 0 : dp[i - 1][j];
            dp[i][j] = (valLeft + valUp) % MOD;
        }
    }

    cout << dp[n][m];
}

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


Measured memory_bytes: 8064