akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#include <vector>
#include <iostream>
#include<algorithm>
#include<string>
#include <map>
#include <queue>
#include <stack>
#include<set>
#include<tuple>

#define DIV 1000000007
using namespace std;
using ll = long long;
using ldb = long double;

int main() {
	int N; cin >> N;
	vector<int> a(N), b(N);
	for (int i = 0; i < N; i++) {
		cin >> a[i];
	}

	for (int i = 0; i < N; i++) {
		cin >> b[i];
	}

	int M = pow(2, N);
	int ans = 1e6;
	for (int i = 0; i < M; i++) {
		vector<pair<int,int>> ev, od;
		for (int j = 0; j < N; j++) {
			if (i & (1 << j)) {
				if (j % 2 == 0) ev.push_back(make_pair(a[j], j));
				else ev.push_back(make_pair(b[j], j));
			}
			else {
				if (j % 2 == 1) od.push_back(make_pair(a[j], j));
				else od.push_back(make_pair(b[j], j));
			}
		}

		if (ev.size() != (N + 1) / 2) continue;
		sort(ev.begin(), ev.end());
		sort(od.begin(), od.end());
		int cnt = 0;
		bool fl = true;
		vector<pair<int, int>> t(N);
		for (int k = 0; k < N; k++) {
			if (k % 2 == 0) t[k] = ev[k / 2];
			else t[k] = od[k / 2];
			if (k > 0 && t[k - 1].first > t[k].first) {
				fl = false;
				break;
			}
		}

		for (int a = 0; a < N; a++) {
			for (int b = a + 1; b < N; b++) {
				if (t[a].second > t[b].second)cnt++;
			}
		}


		if (fl) ans = min(ans, cnt);
	}

	if (ans != 1e6) cout << ans << endl;
	else cout << -1 << endl;

}




Measured memory_bytes: 3984
def fact(n)
    $fact_table ||= Array.new(n+1)
    return $fact_table[n] if $fact_table[n]
    if n <= 1
        ans = 1
    else
        ans = n * fact(n - 1)
    end
    $fact_table[n] = ans
    return ans
end

def comb(n, k)
    return 0 if n < k
    return fact(n) / fact(k) / fact(n - k)
end


N, A, B = gets.split.map(&:to_i)
vs = gets.split.map(&:to_i).sort.reverse

average = vs[0...A].inject(:+) / A.to_f

if A < N && vs[A] == average
    fixed = vs.count{|v| v > average}
    rest = (A - fixed)..(B - fixed)
    cand = vs.count(average.to_i)
    sum = 0
    rest.each do |i|
        sum += comb(cand, i)
    end
elsif A < N && vs[A - 1] == vs[A]
    fixed = vs.count{|v| v > vs[A]}
    rest = A - fixed
    cand = vs.count(vs[A])
    sum = comb(cand, rest)
else
    sum = 1
end

puts average
puts sum

Measured memory_bytes: 1788
#include <bits/stdc++.h>
#define _overload3(_1, _2, _3, name, ...) name
#define _rep(i, n) repi(i, 0, n)
#define repi(i, a, b) for (ll i = (ll)(a); i < (ll)(b); ++i)
#define rep(...) _overload3(__VA_ARGS__, repi, _rep, )(__VA_ARGS__)
#define ll long long
#define lld long double
#define ALL(x) x.begin(), x.end()
#ifdef DEBUG
#define line() cerr << "[" << __LINE__ << "] ";
#define dump(i) cerr << #i ": " << i << " ";
#define dumpl(i) cerr << #i ": " << i << endl;
#else
#define line(i)
#define dump(i)
#define dumpl(i)
#endif
using namespace std;
int main(int argc, char const *argv[])
{
    int n;
    cin >> n;
    rep(i, 50000)
    {
        if (floor((double)i * 1.08) == n)
        {
            cout << i << endl;
            return 0;
        }
    }
    cout << ":(" << endl;
    return 0;
}


Measured memory_bytes: 256
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.util.HashMap;
import java.util.PriorityQueue;
import java.util.StringTokenizer;

public class Main {
  private static class FastScanner {
    private BufferedReader reader = null;
    private StringTokenizer tokenizer = null;

    public FastScanner(InputStream in) {
      reader = new BufferedReader(new InputStreamReader(in));
      tokenizer = null;
    }

    public String next() {
      if (tokenizer == null || !tokenizer.hasMoreTokens()) {
        try {
          tokenizer = new StringTokenizer(reader.readLine());
        } catch (IOException e) {
          throw new RuntimeException(e);
        }
      }
      return tokenizer.nextToken();
    }

    public String nextLine() {
      if (tokenizer == null || !tokenizer.hasMoreTokens()) {
        try {
          return reader.readLine();
        } catch (IOException e) {
          throw new RuntimeException(e);
        }
      }

      return tokenizer.nextToken("\n");
    }

    public long nextLong() {
      return Long.parseLong(next());
    }

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

    public double nextDouble() {
      return Double.parseDouble(next());
    }

    public int[] nextIntArray(int n) {
      int[] a = new int[n];
      for (int i = 0; i < n; i++)
        a[i] = nextInt();
      return a;
    }

    public long[] nextLongArray(int n) {
      long[] a = new long[n];
      for (int i = 0; i < n; i++)
        a[i] = nextLong();
      return a;
    }
  }

  public static void main(String[] args) {
    FastScanner sc = new FastScanner(System.in);
    int n = sc.nextInt();
    HashMap<String, Integer> count = new HashMap<>();
    for (int i = 0; i < n; i++) {
      count.merge(sc.next(), 1, Integer::sum);
    }
    PriorityQueue<String> pq = new PriorityQueue<>((String a, String b) -> {
      if (count.get(a) != count.get(b)) return count.get(b) - count.get(a);
      return a.compareTo(b);
    });
    pq.addAll(count.keySet());
    StringBuilder sb = new StringBuilder();
    int target = count.get(pq.peek());
    while (!pq.isEmpty() && target == count.get(pq.peek())) {
      if (sb.length() > 0) sb.append("\n");
      sb.append(pq.poll());
    }
    System.out.println(sb.toString());
  }
}

Measured memory_bytes: 64360
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
/* clang-format off */
#define INF (INT_MAX / 4)
#define REP(i, n) for (ll i = 0, i##_len = (n); i < i##_len; ++i)
#define ALL(a) (a).begin(), (a).end()
#define DEBUG(x) cout<<#x<<":"<<x<<"\n"
#define DEBUGS(v) cout << #v << ":";for(auto x:v){cout<<x<<" ";}cout<<"\n"
#define TIMER_S(start) chrono::system_clock::time_point start = chrono::system_clock::now();
#define TIMER_E(end) chrono::system_clock::time_point end = chrono::system_clock::now();
#define TIME(start, end) cout << static_cast<double>(chrono::duration_cast<chrono::microseconds>(end - start).count()) << "ms" << "\n";
/* clang-format on */

int main() {
  int n,a,b;
  cin >> n;
  vector<int> p(n), q(n),tmp(n);
  REP(i, n) { cin >> p.at(i); }
  REP(i, n) { cin >> q.at(i); }
  REP(i, n) { tmp.at(i) = i+1; }
  int cnt = 1;
  do {
    if (tmp == p) a = cnt;
    if (tmp == q) b = cnt;
    cnt++;
  } while (next_permutation(ALL(tmp)));
  cout << abs(a-b) << "\n";
  return 0;
  
}


Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<vector>
#include<string>
#include<unordered_map>

#define MOD 1000000007

using namespace std;

long long int expmod(long long int base, long long int exp, long long int mod) {
	if (exp == 0) return 1;
	long long int ret;
	ret = expmod(base, exp / 2, mod);
	ret *= ret;
	ret %= mod;
	if (exp % 2 == 1) ret *= base;
	ret %= mod;
	return ret;
}

int main(void) {
	int n;
	long long int w;
	unordered_map<int, int> m;
	cin >> n;
	for (int i = 0; i <= n; i++) {
		int a;
		cin >> a;
		unordered_map<int, int>::iterator itr;
		itr = m.find(a);
		if (itr != m.end()) w = i - (itr->second) + 1;
		else m[a] = i;
	}
	vector<long long int> Ca(n + 2), Cb(n + 2 - w);
	Ca[0] = 1;
	for (int i = 1; i <= n + 1; i++) {
		Ca[i] = n + 1 - i + 1;
		Ca[i] *= Ca[i - 1];
		Ca[i] %= MOD;
		Ca[i] *= expmod(i, 1000000005, MOD);
		Ca[i] %= MOD;
		//cout << Ca[i] << endl;
	}
	Cb[0] = 1;
	for (int i = 1; i <= n + 1 - w; i++) {
		Cb[i] = n + 1 - w - i + 1;
		Cb[i] *= Cb[i - 1];
		Cb[i] %= MOD;
		Cb[i] *= expmod(i, 1000000005, MOD);
		Cb[i] %= MOD;
		//cout << Cb[i] << endl;
	}

	for (int k = 1; k <= n + 1; k++) {
		if (k == 1) {
			cout << n << endl;
			continue;
		}
		if (k == n + 1) {
			cout << 1 << endl;
			continue;
		}
		if (k - 1 + w > n + 1) cout << Ca[k] << endl;
		else cout << (Ca[k] - Cb[k - 1] + MOD) % MOD << endl;
	}
	system("pause");
	return 0;
}

Measured memory_bytes: 7076
using System;
class Program
{
	static void Main(string[] args)
	{
		string[] input = Console.ReadLine().Split(' ');
		int a = int.Parse(input[0]);
		int b = int.Parse(input[1]);
		if ((a*b)%2 == 1 )
    {
     Console.WriteLine("Odd");
    }
		else
		{
			Console.WriteLine("Even");
		}
	}
}

Measured memory_bytes: 27504
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <functional>

int main()
{
    std::string S;
    std::cin >> S;
    int scount=0;
    int wcount=0;
    int ncount=0;
    int ecount=0;

    for(long i=0; i<S.length(); i++){
        if(S[i]=='N'){
            ncount++;
        }
        if(S[i]=='W'){
            wcount++;
        }
        if(S[i]=='S'){
            scount++;
        }
        if(S[i]=='E'){
            ecount++;
        }
    }
    if((ncount*scount==0 && ncount+scount!=0)  || ((wcount*ecount==0) && (wcount+ecount!=0))){
        std::cout << "No" << std::endl;
    }else{
        std::cout << "Yes" << std::endl;
    }
    return 0;
}

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

#if __has_include("print.hpp")
  #include "print.hpp"
#endif

#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()

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

int main(){
  int x;
  cin >> x;
  if(x == 7 || x == 5 || x ==3){
    cout << "YES" << endl;
  }else{
    cout << "NO" << endl;
  }
}


Measured memory_bytes: 256
//
// ALDS1_4 - A Linear Search
// You are given a sequence of n integers S and a sequence of different q integers T. 
// Write a program which outputs C,the number of integers in T which are also in the set S.
//
#include <iostream>
using namespace std;

void read(int** ppSArray, int& n, int** ppTArray, int& q);
int calc(int* pSArray, const int n, int* pTArray, const int q);
void write(const int count);

int main()
{
    int n = 0, q = 0, ret = 0;
    int* pTArray = NULL;
    int* pSArray = NULL;

    read(&pSArray, n, &pTArray, q);
    ret = calc(pSArray, n, pTArray, q);
    write(ret);

    delete[] pTArray;
    delete[] pSArray;
}

// Required which delete two pointers of heap area.
void read(int** ppSArray, int& n, int** ppTArray, int& q)
{
    if (((NULL == ppSArray) || (NULL != *ppSArray)) ||
        ((NULL == ppTArray) || (NULL != *ppTArray))) {
        return;
    }
    cin >> n;
    if (10000 < n)
        return;
    *ppSArray = new int[n];
    for (int i = 0; i < n; i++) {
        cin >> *(*ppSArray + i);
    }
    cin >> q;
    if (500 < q)
        return;
    *ppTArray = new int[q];
    for (int i = 0; i < q; i++) {
        cin >> *(*ppTArray + i);
    }
}

int calc(int* pSArray, const int n, int* pTArray, const int q)
{
    int count = 0;

    for (int i = 0; i < q; i++) {
        for (int j = 0; j < n; j++) {
            if (pTArray[i] == pSArray[j]) {
                count++;
                break;
            }
        }
    }

    return count;
}

void write(const int count)
{
    cout << count << endl;
}

Measured memory_bytes: 3116
#include <bits/stdc++.h>
using namespace std;
#define __ <<" "<<
#define ___ <<" "
#define bash push_back
#define ALL(x) x.begin(),x.end()
//#define int long long

struct IoSetup {
    IoSetup() {
        cin.tie(0);
        ios::sync_with_stdio(false);
        cout <<fixed<<setprecision(12);
        cerr <<fixed<<setprecision(12);
    }
}IoSetup;

typedef long long ll;
typedef pair < int , int >  pii;
static constexpr const signed int INF = 0x3f3f3f3f;
static constexpr const signed long long LINF = 0x3f3f3f3f3f3f3f3fLL;
static constexpr const signed int SMOD = 1000000007;
static constexpr const signed int NMOD = 998244353;
static constexpr const signed int dx[]={1,0,-1,0,1,1,-1,-1};
static constexpr const signed int dy[]={0,-1,0,1,-1,1,-1,1};

inline bool inside(int x,int y,int w,int h){return (x>=0 && y>=0 && x<w && y<h);}
template<class T>bool chmax(T &a, const T &b){return(a=max(a,b))==b;}
template<class T>bool chmin(T &a, const T &b){return(a=min(a,b))==b;}
inline int qp(int a,ll b,int mo){int ans=1;do{if(b&1)ans=1ll*ans*a%mo;a=1ll*a*a%mo;}while(b>>=1);return ans;}

int h, w;
string s[25];
int mem[30][30];

int bfs(int sy, int sx) {
    memset(mem,0x3f, sizeof(mem));

    mem[sy][sx] = 0;
    queue<pii> que;
    que.push(pii(sx, sy));
    int maxi = 0;
    while(!que.empty()) {
        int x = que.front().first;
        int y = que.front().second;
        que.pop();

        for(int i = 0; i < 4; i++) {
            int nx = x + dx[i];
            int ny = y + dy[i];
            if(inside(nx, ny, w, h) && s[ny][nx] != '#' && mem[ny][nx] == INF) {
                mem[ny][nx] = mem[y][x] + 1;
                chmax(maxi, mem[ny][nx]);
                que.push(pii(nx, ny));
            }
        }
    }
    return maxi;
}

signed main() {

    cin >> h >> w;

    for(int i = 0; i < h; i++) {
        cin >> s[i];
    }
    int maxi = 0;
    for(int i = 0; i < h; i++) {
        for(int j = 0; j < w; j++) {
            if(s[i][j]!='#')
                chmax(maxi, bfs(i, j));
        }
    }

    cout << maxi << endl;
    return 0;
}



Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
long long a,b,c,d,e,i,j,ii,jj,zx,xc,f[1000009],lef,rig,pas;
string s,h;
int main(){
    ios_base::sync_with_stdio(false),cin.tie(0),cout.tie(0);
    cin>>a>>b>>c>>d;
    if(a<=d){
        pas+=a;
        d-=a;
    }else{
        pas+=d;
        d=0;
    }
    if(b<=d){
        d-=b;
    }else{
        d=0;
    }
    if(c<=d){
        pas-=c;
        d-=c;
    }else{
        pas-=d;
        d=0;
    }
    cout<<pas;
    return 0;
}

Measured memory_bytes: 3660
import sys
stdin = sys.stdin
 
sys.setrecursionlimit(10**5) 
 
def li(): return map(int, stdin.readline().split())
def li_(): return map(lambda x: int(x)-1, stdin.readline().split())
def lf(): return map(float, stdin.readline().split())
def ls(): return stdin.readline().split()
def ns(): return stdin.readline().rstrip()
def lc(): return list(ns())
def ni(): return int(stdin.readline())
def nf(): return float(stdin.readline())

from collections import deque

n,m = li()

graph = [[] for _ in range(n)]
for _ in range(m):
    a,b = li_()
    graph[a].append(b)
    graph[b].append(a)
    
    path = deque([a,b])
    
path_set = set(path)

ed = b

satisfied = False
while not satisfied:
    
    satisfied = True
    
    for nex in graph[ed]:
        if nex in path_set:
            continue
        else:
            path_set.add(nex)
            path.append(nex)
            ed = nex
            satisfied = False
            break

    
ed = a

satisfied = False
while not satisfied:
    satisfied = True
    
    for nex in graph[ed]:
        if nex in path_set:
            continue
        else:
            path_set.add(nex)
            path.appendleft(nex)
            ed = nex
            satisfied = False
            break 
    
path = [pi+1 for pi in path]
    
print(len(path))
print(*path)

Measured memory_bytes: 33100
#ifndef _GLIBCXX_NO_ASSERT
#include <cassert>
#endif
#include <cctype>
#include <cerrno>
#include <cfloat>
#include <ciso646>
#include <climits>
#include <clocale>
#include <cmath>
#include <csetjmp>
#include <csignal>
#include <cstdarg>
#include <cstddef>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#ifdef __GXX_EXPERIMENTAL_CXX0X__
#include <ccomplex>
#include <cfenv>
#include <cinttypes>
#include <cstdbool>
#include <cstdint>
#include <ctgmath>
#include <cwchar>
#include <cwctype>
#endif

#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>
#ifdef __GXX_EXPERIMENTAL_CXX0X__
#include <array>
#include <atomic>
#include <chrono>
#include <condition_variable>
#include <forward_list>
#include <future>
#include <initializer_list>
#include <mutex>
#include <random>
#include <ratio>
#include <regex>
#include <system_error>
#include <thread>
#include <tuple>
#include <typeindex>
#include <type_traits>
#include <unordered_map>
#include <unordered_set>
#endif
 size_t strlen(const char *s);
#define rep(i,n) for(long long int i=0;i<n;i++)
#define sz(x) ((int)(x).size())

using namespace std;
struct ToUpper {
    char operator()(char c) { return toupper(c); }
};
struct ToLower {
    char operator()(char c) { return tolower(c); }
};
const int N=200010;
const int P=1000000007;
using ll = long long;

//絶対値
int ze(int a, int b){
	if(a>b){
		return a-b;
	}else{
		return b-a;
	}
}
//小さい方
long long int min(long long int a,long long int b){
	if(a>b){
		return b;
	}else{
		return a;
	}
}
//大きい方
long long int max(long long int a,long long int b){
	if(a>b){
		return a;
	}else{
		return b;
	}
}
// a^n mod 
long long modpow(long long a, long long n, long long mod) {
    long long res = 1;
    while (n > 0) {
        if (n & 1) res = res * a % mod;
        a = a * a % mod;
        n >>= 1;
    }
    return res;
}

// a^{-1} mod 
long long modinv(long long a, long long mod) {
    return modpow(a, mod - 2, mod);
}

//mod掛け算
long long mt(long long a, long long b, long long mod){
	return (a*b)%mod;
}

//メモ

/*
	memset(b, '\0', sizeof(b));
初期化*/

/*
	char s[N];
	strlen(s)
*/

/*
	if(  <  )puts("Yes");
	else puts("No");
*/

/*文字列比較
if(strcmp(name[i],s)==0)
*/

/*
	graph[a].push_back(b);//graph[a][i番目に入れた]==b
	graph[j].size()	//forで回すときとか

*/

/*添字1がa個、2がb個
  vector<vector<ll>> map(a,vector<ll>(b));
*/

int main(){
	ll a,v,b,w,t;
	cin>>a>>v>>b>>w>>t;





	if(ze(a,b)<=(v-w)*t      )puts("YES");


	else puts("NO");


}



Measured memory_bytes: 3604
N,K = map(int,input().split())
h = list(map(int,input().split()))
dp = []
for i in range(N):
	dp.append(float("inf"))

dp[0] = 0

for i in range(N):
	for k in range(K):
		if i+k+1 < N:
			dp[i+k+1] = min(dp[i+k+1], dp[i]+abs(h[i+k+1]- h[i]))

print(dp[N-1])


Measured memory_bytes: 57184
#include <bits/stdc++.h>
using namespace std;
#define f(i,j,k) for(int i=j;i<k;i++)
int main(){
    long long n,a[3][3],b[10];
    bool aa[3][3];
    f(i,0,3){
        f(j,0,3){
            cin>>a[i][j];
        }
    }
    cin>>n;
    f(i,0,n){
        cin>>b[i];
    }
    f(i,0,3){
        f(j,0,3){
            aa[i][j]=false;
            f(k,0,n){
                if(a[i][j]==b[k]){
                    aa[i][j]=true;
                }
            }
        }
    }
    string ans="No";
    f(i,0,3){
        if(aa[0][i]&&aa[1][i]&&aa[2][i]){
            ans="Yes";
            break;
        }
        else if(aa[i][0]&&aa[i][1]&&aa[i][2]){
            ans="Yes";
            break;
        }
    }
    if(aa[0][0]&&aa[1][1]&&aa[2][2]){
        ans="Yes";
    }
    if(aa[0][2]&&aa[1][1]&&aa[2][0]){
        ans="Yes";
    }
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 256
#include <cstdio>
#include <cctype>
#include <algorithm>
using namespace std;
inline int read(int f = 1, int x = 0, char ch = ' ')
{
    while(!isdigit(ch = getchar())) if(ch == '-') f = -1;
    while(isdigit(ch)) x = x*10+ch-'0', ch = getchar();
    return f*x;
}
const int N = 15, P = 1e9+7;
int n, m, f[1<<N|5], w[N*N], g[N], h[1<<N|5];
int main()
{
    n = read(), m = read(), f[0] = w[0] = 1;
    for(int i = 1; i <= m; ++i)
    {
        int x = read()-1, y = read()-1;
        g[x] |= 1<<y, w[i] = (w[i-1]<<1)%P;
    }
    for(int s = 1; s < 1<<n; ++s) h[s] = h[s^(s&-s)]+1;
    for(int s = 1; s < 1<<n; ++s)
        if((s&1) == (s>>1&1))
            for(int u = s; u; u = (u-1)&s)
                if((u&1) == (u>>1&1))
                {
                    int k = 1;
                    for(int i = 0; i < n; ++i)
                        if(s>>i&1)
                        {
                            if(u>>i&1) k = 1ll*k*w[h[g[i]&(s^u)]]%P;
                            else k = 1ll*k*(w[h[g[i]&u]]-1)%P;
                        }
                    f[s] = (f[s]+1ll*f[s^u]*k%P)%P;
                }
    printf("%d\n", (w[m]-f[(1<<n)-1]+P)%P);
    return 0;
}

Measured memory_bytes: 384
a = int(input())
b = int(input())
c = int(input())
d = int(input())
e = int(input())
k = int(input())

ok = True
for i in [a, b, c, d, e]:
    for j in [a, b, c, d, e]:
        if abs(j - i) > k:
            ok = False

if ok:
    print("Yay!")
else:
    print(":(")


Measured memory_bytes: 3060
#include <iostream>
#include <string>
#include<stack>

using namespace std;
string str;
int p;
 
int exp();
int factor();
int term();
 
int factor() {
  int num=0;
  while('0' <= str[p] && str[p] <= '9') {
    num*=10;
    num += str[p] - '0';
    p++;
  }
 
  if (str[p] == '('){
    p++;
    num = exp();
    p++;
  }

  return num;
}

int exp() {

  int sum=0,top=factor();
  

  while(str[p]!='=' && str[p]!=')') {
    if(str[p] == '+') {
      p++;
      sum+=top;
      top=factor();
    } else if(str[p] == '-'){
      p++;
      sum+=top;
      top=-factor();
    } else if(str[p] == '*'){
      p++;
      top*=factor();
    }else if(str[p] == '/'){
      p++;
      top/=factor();
    }
  }
  return sum+top;
}


/*
int exp() {

  
  stack<int> st;
  st.push(factor());

  while(str[p]!='=' && str[p]!=')') {
    if(str[p] == '+') {
      p++;
      st.push(factor());
    } else if(str[p] == '-'){
      p++;
      st.push(-factor());
    } else if(str[p] == '*'){
      p++;
      int k=st.top();
      st.pop();
      st.push(k*factor());
    }else if(str[p] == '/'){
      p++;
      int k=st.top();
      st.pop();
      st.push(k/factor()); 
    }
    
  }
 
  int sum=0;
  while(!st.empty()){
    sum+=st.top();
    st.pop();
  }
  return sum;
}
*/ 
int main() {
  int n;
 
  cin >> n;
   
  for(int i=0;i<n;i++) {
    p = 0;
  cin >> str;
  cout << exp() << endl;
  }
  return 0;
}

Measured memory_bytes: 1204
#include <bits/stdc++.h>
using namespace std;
int main(){
int N,M;
  cin>>N>>M;
  vector<int>moji(N);
  for(int i=0;i<N;i++){
  cin>>moji.at(i);
  }
  int sum=0;
   for(int i=0;i<N;i++){
 	sum+=moji.at(i);
  }
  int count;
 for(int i=0;i<N;i++){
   if(moji.at(i)*(4*M)>=sum){
   count++;
   }
  }
  if(count>=M){
  cout<<"Yes";
  }
  else{
  cout<<"No";
  }
}

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

int main() {
    int n, T;
    cin >> n >> T;
    vector<int> t(n);
    rep(i,n) cin >> t[i];

    ll ans = 0;
    for (int j=1; j<n; j++) {
        ans += min(T, t[j]-t[j-1]);
    }
    cout << ans + T << endl;
    return 0;
}

Measured memory_bytes: 1024
#include <iostream>
#include<map>
#include <algorithm>
#include <vector>
#include <string>
#include <utility>
#include <queue>
#define INF 1e9+7
#define rep(i,n) for(int i=0;i<n;i++)
#define NO cout<<"NO"<<endl;
#define YES cout << "YES"<<endl;
#define No cout << "No"<<endl;
#define Yes cout << "Yes"<<endl;
#define all(a) a.begin(),a.end()
using namespace std;
typedef long long int ll;
typedef unsigned long long int ull;

const int maxn = 100000;
const int mhw = 300;

//(int)'a'は97 (int)'A'は65 (int)'1'は49
//おまじない


int main() {

	int n;
	int num = 0;

	cin >> n;

	rep(i, n) {
		char c; cin >> c;
		if (c == 'R')num++;
	}

	if (n - num < num) {
		Yes;
	}
	else {
		No;
	}

	return 0;
}

Measured memory_bytes: 256
N,L=map(int,input().split())

Ta=[]
T=[]
for i in range(N):
    t=L+i
    T.append(t)
    Ta.append(abs(t))
#print(T)
#print(Ta)
trg=Ta.index(min(Ta))
#print(trg)
#print(T)
s=sum(T[:trg]+T[trg+1:])
print(s)


Measured memory_bytes: 3060
#[allow(unused_imports)]
use std::cmp::{min,max};
#[allow(unused_imports)]
use std::collections::BTreeMap;
#[allow(unused_imports)]
use std::ops::*;
#[allow(unused_imports)]
use std::collections::BinaryHeap;

fn main() {
    let n = read_i64() as usize;
    let xs = read_vec_i64();
    let mut dp = vec![(None,None); 1<<n];
    for (i,&x) in xs.iter().enumerate() {
        dp[i].0 = Some(i);
    }
    let f = |xyi : (Option<usize>, Option<usize>), zi: Option<usize>| {
        match zi {
            Some(zi) => {
                match xyi.0 {
                    Some(xi) => {
                        match xyi.1 {
                            Some(yi) => {
                                if xs[zi] > xs[xi] {
                                    (Some(zi), Some(xi))
                                }
                                else if xs[zi] > xs[yi] && xi != zi {
                                    (Some(xi), Some(zi))
                                }
                                else {
                                    xyi
                                }
                            }
                            None => {
                                if xi != zi {
                                    if xs[xi] > xs[zi] {
                                        (Some(xi), Some(zi))
                                    }
                                    else {
                                        (Some(zi), Some(xi))
                                    }
                                }
                                else {
                                    (Some(xi), None)
                                }
                            }
                        }
                    }
                    None => {
                        (Some(zi), None)
                    }
                }
            }
            None => {
                xyi
            }
        }
    };
    for i in 0..(1<<n) {
        for k in 0..n {
            if i & (1 << k) != 0 {
                continue;
            }
            dp[i|(1<<k)] = f(dp[i|(1<<k)], dp[i].0);
            dp[i|(1<<k)] = f(dp[i|(1<<k)], dp[i].1);
        }
    }
    let mut res = 0;
    for i in 1..(1<<n) {
        res = max(res, xs[dp[i].0.unwrap()] + xs[dp[i].1.unwrap()]);
        println!("{}", res);
    }
}

#[allow(dead_code)]
fn read_line() -> String {
    let mut ret = String::new();
    std::io::stdin().read_line(&mut ret).ok();
    ret.pop();
    return ret;
}

#[allow(dead_code)]
fn read_i64() -> i64 {
    let ss = read_line();
    return ss.parse::<i64>().unwrap();
}

#[allow(dead_code)]
fn read_vec_i64() -> Vec<i64> {
    let mut res = vec![];
    let ss = read_line();
    for ts in ss.split_whitespace() {
        let x = ts.parse::<i64>().unwrap();
        res.push(x);
    }
    return res;
}

use std::fmt::Display;
#[allow(dead_code)]
fn write_vec<T: Display>(xs: &Vec<T>) {
    if xs.len() == 0 {
        println!("");
        return;
    }
    print!("{}", xs[0]);
    for i in 1..xs.len() {
        print!(" {}", xs[i]);
    }
    println!("");
}


Measured memory_bytes: 16372
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <stack>
#include <queue>
#include <cmath>
#include <set>
#include <map>

#define N 0
#define INF 0x3f3f3f3f
#define LL long long
#define mz(x) ms(x,0)
#define ms(x,y) memset(x,y,sizeof(x))
#define mc(x,y) memcopy(x,y,sizeof(y))
#define MOD 1000000007

using namespace std ;

int main()
{
	int n ;
	scanf ("%d", &n) ;
	
	int mx ;
	LL ans = 0 ;
	for (int i=0; i<n; i++)
	{
		int a ;
		scanf ("%d", &a) ;
		
		if (i == 0)
			mx = a ;
		else if (a < mx)
			ans += (mx - a) ;
		else
			mx = a ;
	}
	
	cout << ans << endl ;

	return 0 ;
}

Measured memory_bytes: 3228
import bisect
N = int(input())
Data = list(map(int,input().split()))
Data.sort()
ans = 0
for i in range(N-2):
    for j in range(i+1,N-1):
        len3 = Data[i]+Data[j]
        # j番目よりも大きくて、サイズが　len3よりも小さい数
        k = bisect.bisect_left(Data,len3)
        # j番目よりも大きくて k-1番目までが求める数
        if k-1 > j:
            ans += (k-1-j)
print(ans)

Measured memory_bytes: 3188
n,m = map(int,input().split())
ans = ["-1"]*n

for _ in range(m):
    s,c = input().split()
    s = int(s)-1
    if ans[s] != "-1" and ans[s] != c: 
        print(-1)
        exit()
    ans[s] = c

if n != 1 and ans[0] == "0":
    print(-1)
    exit()



for i in range(n):
    if ans[i] == "-1":
        ans[i] = "0" if i != 0 or n == 1 else "1"

print("".join(ans))

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

int main(int argc, char const *argv[]) {
    long long x, k, d;
    cin >> x >> k >> d;
    x = abs(x);

    if (x/d >= k) {
        cout << x - k*d << endl;
        return 0;
    }

    if ((k - x/d)%2 == 0) cout << x%d << endl;
    else cout << abs(x%d - d) << endl;
    return 0;
}


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

#define LL long long
#define REP(i, n) for(int i = 0; i < (int)(n); i++)
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define ALL(x) (x).begin(),(x).end()
const int IINF = 1e9;
const LL LINF = 1e18;
const LL mod = 1e9+7;

int s(int x) {
    int res = 0;
    for(;x != 0;x /= 10) {
        res += x%10;
    }
    return res;
}

int main() {
    int N;
    cin >> N;
    if(N%s(N) == 0) {
        cout << "Yes" << endl;
    }else{
        cout << "No" << endl;
    }
    return 0;
}



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

#define REP(i, n) for(int i = 0; i < (int)(n); ++i)
#define FOR(i, m, n) for(int i = (int)(m); i < (int)(n); ++i)


int main()
{
    long long N;
    cin >> N;

    long long ans = 1e+18;
    for(long long i = 1; i*i <= N; ++i){
        if(N%i == 0) ans = min(ans, i+N/i-2);
    }

    /*
    vector<long long> divisor;
    for(long long i = 2; i*i <= N; ++i){
        while(N%i == 0){
            N /= i;
            divisor.push_back(i);
        }
    }
    if(N > 1) divisor.push_back(N);

    long long ans = 1e+12;
    int n = divisor.size();
    for(long long i = 0; i < (1<<n); ++i){
        long long a = 1, b = 1;
        for(long long j = 0; j < n; ++j){
            if(i & (1<<j)) a *= divisor[j];
            else b *= divisor[j];
        }
        ans = min(ans, a+b-2);
    }*/
    cout << ans << endl;
    
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <cstring> 
using namespace std;
#define fast std::ios::sync_with_stdio(false);cin.tie(NULL);
#define pb push_back
#define int long long int
#define F first
#define mem(a,b) memset(a,b,sizeof(a))
#define S second
#define MOD 1000000007
#define in_range(x, y, r, c) (x < r && y < c && x >= 0 && y >= 0)
#define MAXN 100008

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

    int n;
    cin>>n;
    int x = log(n)/(double)log(2);
    cout<<(int)pow(2, x+1)-1<<endl;
}

Measured memory_bytes: 640
/*#pragma GCC optimize("Ofast")
#pragma GCC target("avx,avx2,fma")
#pragma GCC optimization("unroll-loops")
*/

#include <bits/stdc++.h>
using namespace std;
#define pi acos(-1)
#define IOS ios_base::sync_with_stdio(0); cin.tie(); cout.tie();
#define fi first
#define se second
#define pf push_front
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define debug(x) cerr<<#x<<": "<<(x)<<'\n'
typedef long double ld;
typedef long long ll;
typedef unsigned long long ull;
const ll mod = 1e9+7;
const ll inf = 0x3f3f3f3f;
const ll nax = 0;
string s;
unordered_map<char, int>cnt;

int main(){
	IOS
	cin >> s;
	int n=s.length();
	for(int i=0;i<n;++i){
		cnt[s[i]]++;
	}
	if(abs(cnt['a']-cnt['b'])<=1 && abs(cnt['a']-cnt['c'])<=1 && abs(cnt['c']-cnt['b'])<=1) cout << "YES" << '\n';
	else cout << "NO" << '\n';
}


Measured memory_bytes: 3752
#include<iostream>
using namespace std;
int main(){
  int n, k, a, b;
  cin>>n>>k;
  a = n / k;
  b = n % k;
  long long ans = 1LL*a*a*a;
  if(k%2==0){
    if(k/2<=b) ans += 1LL*(a+1)*(a+1)*(a+1);
    else ans += 1LL*a*a*a;
  }
  cout<<ans<<endl;
}

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

using namespace std;

int main()
{
    long long n, m; cin >> n >> m;
    if (n > m) swap(n, m);
    long long ans = 0;

    if (n == 1) {
        if (m == 1) ans = 1;
        else ans = m - 2;
    } else {
        ans = (n - 2) * (m - 2);
    }

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 256
N = int(input())
h_list = list(map(int, input().split()))

count = 1
for h1 in range(1, N):
    result = True
    for h2 in range(h1):
        if h_list[h2] > h_list[h1]:
            result = False
    if result:
        count += 1
print(count)


Measured memory_bytes: 2940
#include <iostream>
#include <iomanip>
#include <string>
#include <string.h>
#include <math.h>
#include <cmath>
#include <vector>
#include <set>
#include <map>
#include <algorithm>
#include <utility>
#include <deque>
#include <queue>

#define rep(i, n) for(int i = 0; i < n; ++i)
#define REP(i, m, n) for(int i = m; i < n; ++i)
#define rrep(i,n) for(int i = n; i >= 0; --i)
#define RREP(i, m, n) for(int i = n; i >= m; --i)

using ll = long long;
using ull = unsigned long long;
using pii = std::pair<int, int>;
using pll = std::pair<long long, long long>;

using namespace std;

const long long MOD = 1000000007;

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

	ll n, a, b;
	cin >> n >> a >> b;

	ll t = n / (a + b);
	ll p = n % (a + b);

	cout << t * a + min(a, p) << "\n";

	return 0;
}


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

int main()
{
  int n,ans=0,m=0;
  cin>>n;
  vector<int> v(n);
  for(int &i:v) cin>>i;
  for(int i=0;i<n-1;i++)
  {
    if(v[i+1]>v[i])
      m=0;
     else
       {m++;}
    ans = max(m,ans);
  }
  cout<<ans;
  
  return 0;
}

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

typedef long long ll;
#define REP(i,n) for(int i=0,_n=(int)(n);i<_n;++i)
#define ALL(v) (v).begin(),(v).end()
#define CLR(t,v) memset(t,(v),sizeof(t))
template<class T1,class T2>ostream& operator<<(ostream& os,const pair<T1,T2>&a){return os<<"("<<a.first<<","<<a.second<< ")";}
template<class T>void pv(T a,T b){for(T i=a;i!=b;++i)cout<<(*i)<<" ";cout<<endl;}
template<class T>void chmin(T&a,const T&b){if(a>b)a=b;}
template<class T>void chmax(T&a,const T&b){if(a<b)a=b;}


int nextInt() { int x; scanf("%d", &x); return x;}
ll nextLong() { ll x; scanf("%lld", &x); return x;}

struct State {
  ll x, cost;
  bool operator < (const State& o) const {
    return cost > o.cost;
  }
};

int main2() {
  ll N_, A, B, C, D;
  cin >> N_ >> A >> B >> C >> D;

  const ll INF = 1LL << 61;

  const ll muls[] = {2, 3, 5};
  const ll coins[] = {A, B, C};

  map<ll, ll> memo;
  priority_queue<State> q;
  q.push((State){N_, 0});
  memo[N_] = 0;
  while (!q.empty()) {
    State state = q.top(); q.pop();
    const ll n = state.x;
    if (memo[n] != state.cost) continue;
    if (N_ >= 1000)
    if (n == 0) break;

    for (int i = 0; i < 3; i++) {
      ll mul = muls[i];
      ll coin = coins[i];
      if (n % mul) {
        ll nn = n - n % mul;
        // cout << n << " -> " << nn  << " " << endl;
        ll cost = (n % mul) * D;
        if (memo.count(nn) == 0 || memo[nn] > state.cost + cost) {
          if ((double)state.cost + (double)cost < (double)INF) {
            memo[nn] = state.cost + cost;
            q.push((State){nn, memo[nn]});
          }
        }
      }
      if (n % mul) {
        ll nn = n + (mul - n % mul);
        // cout << n << " -> " << nn  << " " << endl;
        ll cost = (mul - n % mul) * D;
        if (memo.count(nn) == 0 || memo[nn] > state.cost + cost) {
          if ((double)state.cost + (double)cost < (double)INF) {
            memo[nn] = state.cost + cost;
            q.push((State){nn, memo[nn]});
          }
        }
      }
      if (n % mul == 0) {
        ll nn = n / mul;
        ll cost = coin;
        if (memo.count(nn) == 0 || memo[nn] > state.cost + cost) {
          if ((double)state.cost + (double)cost < (double)INF) {
            memo[nn] = state.cost + cost;
            q.push((State){nn, memo[nn]});
          }
        }
      }
    }
    if (n < INF / D) {
      ll nn = 0;
      ll cost = n * D;
      if (memo.count(nn) == 0 || memo[nn] > state.cost + cost) {
        if ((double)state.cost + (double)cost < (double)INF) {
          memo[nn] = state.cost + cost;
          q.push((State){nn, memo[nn]});
        }
      }
    }
  }

  ll ans = memo[0];
  cout << ans << endl;
  return 0;
}

int main() {
  int T; cin >> T;
  while (T--)
    main2();
  return 0;
}

Measured memory_bytes: 8060
#include <iostream>
#include<stdio.h>
#include<string.h>
#include<deque> 
#include<algorithm>
using namespace std;
deque <char>q;
int  main()
{
	char a[105];
	int t;
	scanf("%d",&t);
	scanf("%s",a);
	int k=0;
	for(int i=0;i<strlen(a);i++)
	{
		if(a[i]=='(')
		{
			q.push_back(a[i]);
			k++;
		}
		else
		{
			if(k>0)
			{
				q.push_back(a[i]);
				k--;
			}
			else
			{
				q.push_back(')');
				q.push_front('(');
			}
		
		}
	}
	while(k--)
	q.push_back(')');
	while(!q.empty())
	{
		printf("%c",q.front());
		q.pop_front();
	}
	printf("\n");
	return 0;
 } 

Measured memory_bytes: 256
#include<bits/stdc++.h>
#include<unordered_set>
#include<unordered_map>
#include <algorithm> 
#include <iostream>
#include <string>
#include <cmath>
using namespace std;
#define ll long long
#define rep(i, n) for (ll i = 0; i < (n); i++)
#define FOR(i,a,b) for(ll i=(a);i<(b);i++)
#define FORR(i,a,b)for(ll i=(a);i<=(b);i++)
#define repR(i,n) for(ll i=n;i>=0;i--)
#define all(v)(v).begin(),(v).end()
#define rall(v)(v).rbegin(),(v).rend()
#define F first
#define S second
#define pb push_back
#define pu push
#define COUT(x) cout<<(x)<<endl
#define PQ priority_queue<ll>
#define PQR priority_queue<ll,vector<ll>,greater<ll>>
#define YES(n) cout << ((n) ? "YES" : "NO"  ) << endl
#define Yes(n) cout << ((n) ? "Yes" : "No"  ) << endl
#define mp make_pair
#define maxs(x,y) (x = max(x,y))
#define mins(x,y) (x = min(x,y))
#define sz(x) (ll)(x).size()
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
const ll MOD = 1000000007LL;
const ll INF = 1LL << 60;
using vll = vector<ll>;
using vb = vector<bool>;
using vvb = vector<vb>;
using vvll = vector<vll>;
using vstr = vector<string>;
using pll = pair<ll, ll>;
using vc = vector<char>;
using vvc = vector<vc>;
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 dx[4]={0,1,0,-1};
ll dy[4]={1,0,-1,0};
int main(){
  ll n,k,c;
  cin>>n>>k>>c;
  string s;
  cin>>s;
  vll l(0),r(0);
  for(int i=0;i<n&&sz(l)<k;){
    if(s[i]=='o'){
      
      l.pb(i);i+=c+1;
    }
    else i++;
  }
  for(int i=n-1;i>=0&&sz(r)<k;){
    if(s[i]=='o'){
      
      r.pb(i);
      i-=c+1;
    }
    else i--;
  }
  reverse(all(r));
  rep(i,k){
    if(r[i]==l[i]){
      COUT(r[i]+1);
    }
  }
}

Measured memory_bytes: 5108
n, c = gets.split.map(&:to_i)
sushis = []
n.times { sushis << gets.split.map(&:to_i) }
max_value = 0
current_value = 0
current_pos = 0
max_values = []
sushis.each do |dist, value|
  current_value -= (dist - current_pos)
  current_value += value
  max_value = current_value if max_value < current_value
  max_values << max_value
  current_pos = dist
end

reversed_sushis = sushis.reverse.map { |dist, value| [c - dist, value] }
max_value = 0
current_value = 0
current_pos = 0
reversed_max_values = []
reversed_sushis.each do |dist, value|
  current_value -= (dist - current_pos)
  current_value += value
  max_value = current_value if max_value < current_value
  reversed_max_values << max_value
  current_pos = dist
end

returned_max_values = []
max_values.each_with_index do |value, index|
  dist = sushis[index][0]
  returnable_index = n - index - 2
  value += reversed_max_values[returnable_index] - dist if returnable_index >= 0 && reversed_max_values[returnable_index] - dist > 0
  returned_max_values << value
end

returned_reversed_max_values = []
reversed_max_values.each_with_index do |value, index|
  dist = reversed_sushis[index][0]
  returnable_index = n - index - 2
  value += max_values[returnable_index] - dist if returnable_index >= 0 && max_values[returnable_index] - dist > 0
  returned_reversed_max_values << value
end

puts [returned_max_values.max, returned_reversed_max_values.max].max


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

int main() {
  // ここにプログラムを追記
  int intS;
  int intS1;
  int intS2;
  int intS3;

  cin >> intS;
  
  cout << (intS / 100) + (intS % 100) / 10 + (intS % 10) << endl;
  
}

Measured memory_bytes: 256
#include <cstring>
#include <cmath>
#include <algorithm>
#include <string>
#include <map>
#include <iostream>
#include <vector>
#include <queue>
#include <unordered_map>
#include <random>
#include <stack>
#include <set>
#include <unordered_set>

#define bug(x) cout<<"zdongdebug1: "<<x<<endl;
#define bug2(x, y) cout<<"zdongdebug2: "<<x<<" "<<y<<endl;
#define bug3(x, y, z) cout<<"zdongdebug3: "<<x<<" "<<y<<" "<<z<<endl;
using namespace std;
typedef long long ll;
const int maxn = 1000005;
const int mod = 1000000007;

int dir[4][2] = {{0,1},{0,-1},{1,0},{-1,0}};
int f0[maxn][4];
int f1[maxn][4];
int g[maxn][4];

int main() {
#ifdef suiyuan2009
  freopen("/Users/suiyuan2009/CLionProjects/icpc/input.txt", "r", stdin);
  //freopen("/Users/suiyuan2009/CLionProjects/icpc/output.txt", "w", stdout);
#endif
  int n,m,K;
  cin>>n>>m>>K;
  memset(f0,-1,sizeof(f0));
  int x1,y1, x2,y2;
  cin>>x1>>y1>>x2>>y2;
  x1--,y1--,x2--,y2--;
  vector<string> s = vector<string>(n);
  for(int i=0;i<n;i++)cin>>s[i];
  queue<int>qx,qy,qz;
  for(int i=0;i<4;i++){
    f0[x1 * m + y1][i] = 0;
    f1[x1*m + y1][i] = 0;
    g[x1 * m + y1][i] = 1;
    qx.push(x1);
    qy.push(y1);
    qz.push(i);
  }
  while(!qx.empty()){
    int x = qx.front();
    qx.pop();
    int y = qy.front();
    qy.pop();
    int z = qz.front();
    qz.pop();
    int tt = x * m + y;
    g[tt][z] = 0;
    for(int i=0;i<4;i++){
      int nx = x + dir[i][0];
      int ny = y + dir[i][1];
      if(nx<0||nx>=n||ny<0||ny>=m||s[nx][ny]=='@')continue;
      int v0,v1;
      if(i!=z){
        v0 = f0[tt][z]+1;
        v1 = 1;
      } else {
        v0 = f0[tt][z];
        if(v0==0)v0=1;
        v1 = f1[tt][z] + 1;
        if(v1==K+1){
          v0++;
          v1 = 1;
        }
      }
      int tt2 = nx*m+ny;
      int ov0 = f0[tt2][i];
      int ov1 = f1[tt2][i];
      if(ov0==-1||(ov0>v0)||(ov0==v0&&v1<ov1)){
        f0[tt2][i] = v0;
        f1[tt2][i] = v1;
        if(!g[tt2][i]){
          g[tt2][i]=1;
          qx.push(nx);
          qy.push(ny);
          qz.push(i);
        }
      }
    }
  }
  int ret = -1;
  for(int i=0;i<4;i++){
    if(f0[x2*m+y2][i]!=-1){
      if(ret==-1||ret>f0[x2*m+y2][i]){
        ret = f0[x2*m+y2][i];
      }
    }
  }
  cout<<ret<<endl;
  return 0;
}

Measured memory_bytes: 51516
#include <bits/stdc++.h>
#define DEBUG if(0)
#define lli long long int
#define ldouble long double
using namespace std;

lli n;
bool valid(lli num)
{
  lli aux = n;
  while (aux > 0 && aux % num == 0) aux /= num;
  return aux % num == 1;
}

int main()
{
  while (scanf("%lld", &n) != EOF)
  {
    set<lli> ans; ans.insert(n);
    for (int i = 2, end = sqrt(n); i <= end; i++)
    {
      if (n % i == 0 && valid(i))
      {
        ans.insert(i);
        if (n % (n / i) == 0 && valid(n / i))
          ans.insert(n / i);
      }
    }
    n--; ans.insert(n);
    for (int i = 2, end = sqrt(n); i <= end; i++)
    {
      if (n % i == 0)
      {
        ans.insert(i);
        if (n % (n / i) == 0)
          ans.insert(n / i);
      }
    }
    ans.erase(0), ans.erase(1);
    // for (int i = 2; i < n; i++)
    //   if (n % i == 1)
    //     ans.insert(i);
    printf("%d\n", (int)ans.size());
    DEBUG {
      for (int i: ans)
        printf("\t%d\n", i);
    }
  }
  return 0;
}

Measured memory_bytes: 256
import collections

letter = input().split(' ')
stack = collections.deque(letter.pop())


def calc_chk(num1, num2, op):
    if op in ['+', '-', '*'] and num1 not in ['+', '-', '*'] and num2 not in ['+', '-', '*']:
        return True
    else:
        return False

while letter:
    temp = letter.pop()
    stack.append(temp)

    is_calc = True
    while is_calc:
        # print(stack)
        if len(stack) >=3:
            if calc_chk(stack[-1], stack[-2], stack[-3]):
                num1 = stack.pop()
                num2 = stack.pop()
                op = stack.pop()
                val = str(eval(num1 + op + num2))
                stack.append(val)
    
            else:
                is_calc = False
        else:
            is_calc = False
print(*stack)


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

int main() {
	int h, w, n;
	cin >> h >> w >> n;
	vector<int> a(n);
	vector<vector<int>> grid(h, vector<int>(w));
	for (int i = 0; i < n; i++) {
		cin >> a[i];
	}
	int k = 0;
	for (int i = 0; i < h; i++) {
		for (int j = 0; j < w; j++) {
			if (a[k] == 0) k++;
			grid[i][j] = k+1;
			a[k]--;
		}
		if (i % 2 == 1) {
			reverse(grid[i].begin(), grid[i].end());
		}
	}
	for (int i = 0; i < h; i++) {
		for (int j = 0; j < w; j++) {
			cout << grid[i][j];
			if (j < w-1) cout << ' ';
		}
		cout << endl;
	}
	return 0;
}

Measured memory_bytes: 3196
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define rep(i,n) for(int i=0;i<n;i++)
#define rep1(i,n) for(int i=1;i<=n;i++)
#define rep2(i,n) for(int i=0;i<=n;i++)
#define repr(i,a,n) for(int i=a;i<n;i++)
#define all(a) a.begin(),a.end()
#define P pair<long long,long long>
#define double long double
#define vector2(a,b,c) vector<vector<string>> a(b,vector<string>(c))
#define INF 1e10
#define MOD 1e9+7
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; }
using Graph = vector<vector<int>>;
signed main(){
  int a,b;
  cin>>a>>b;
  string c[30][30];
  rep(i,a)rep(j,b)
    cin>>c[i][j];
  int d;
  int e;
  rep(i,a)rep(j,b){
  if(c[i][j]=="snuke"){
    d=i+1;
    e=j+1;
    }
  }
  char f=e+64;
  cout<<f<<d<<endl;
}

Measured memory_bytes: 256
from collections import Counter,defaultdict,deque
from heapq import heappop,heappush,heapify
import sys,bisect,math,itertools,pprint,fractions
sys.setrecursionlimit(10**8)
mod = 10**9+7
mod2 = 998244353
INF = float('inf')
def inp(): return int(sys.stdin.readline())
def inpl(): return list(map(int, sys.stdin.readline().split()))
def inpln(n): return list(int(sys.stdin.readline()) for i in range(n))

h,a = inpl()
print(math.ceil(h/a))

Measured memory_bytes: 5152
#include"bits/stdc++.h"
#define int long long
#define _overload3(_1,_2,_3,name,...) name
#define _rep(i,n) repi(i,0,n)
#define repi(i,a,b) for(int i=(a);i<(b);++i)
#define rep(...) _overload3(__VA_ARGS__,repi,_rep,)(__VA_ARGS__)
#define itr(i,x) for(auto i=(x).begin();i!=(x).end();++i)
#define All(x) (x).begin(),(x).end()
#define gridif(a,x,b) if((a)<=(x)&&(x)<(b))

using namespace std;
typedef pair<int,int> P;
const int mod=1000000007;

int digitsum(int n,int b){
	if(b<2) return -1;
	if(n<b) return n;
	return digitsum(n/b,b)+n%b;
}
int mpow(int a,int x);
int m_inv(int n);
vector<int> split(int n,int a);
string xal_number(int n,int x);
int gcd(int x,int y){return y?gcd(y,x%y):x;}
int lcm(int x,int y){return x*y/gcd(x,y);}
class Factorial{
private:
	vector<int> fac;
public:
	Factorial(int N){
		fac.push_back(1);
		rep(i,N) fac.push_back(fac[i]*(i+1)%mod);
	}
	int fact(int a){return fac[a];}
	int ifac(int a){return m_inv(fac[a]);}
	int cmb(int n,int r);
};
struct UnionFind {
    vector<int> par; // 親ノード
    UnionFind(int n = 1) { init(n);}
    void init(int n = 1) {
        par.resize(n);
        rep(i,n) par[i] = -1;
    }
    int root(int x) {
        if (par[x] <0) return x;
        else return par[x] = root(par[x]);      
    }
    int size(int x){ return -par[root(x)];}
    bool issame(int x, int y) {return root(x)==root(y);}
    bool connect(int x, int y);
};

signed main(){
	string s;
	cin>>s;
	int id0,id1;
	int n=s.length();
	rep(i,n) if(s[i]=='A'){
		id0=i;
		break;
	}
	rep(i,n) if(s[n-i-1]=='Z'){
		id1=n-i-1;
		break;
	}
	cout<<id1-id0+1<<endl;
}

Measured memory_bytes: 640
import sys
import heapq
stdin=sys.stdin

ns=lambda:input().rstrip()
ni=lambda:int(input().rstrip())
nm=lambda:map(int,input().split())
nl=lambda:list(map(int,input().split()))


N=int(input())
V=nl()
h=[]
for i in V:
  heapq.heappush(h,i) 

for i in range(N-1):
  minval=heapq.heappop(h)
  minval2=heapq.heappop(h)
  heapq.heappush(h,(minval+minval2)/2)
  
print(heapq.heappop(h))
  

Measured memory_bytes: 3188