akhauriyash/Code-Regression huggingface dataset:
#!/usr/bin/env python3
import sys


def solve(N: int, A: "List[int]"):
    from itertools import islice
    cap = [1]
    for a in A:
        cap.append(2*(cap[-1]-a))
    ans = 0
    p = 0
    for a, c in zip(A[N::-1], cap[N::-1]):
        c -= a
        if 2 * c < p:
            return -1
        p = min(c, p) + a
        ans += p
    return ans

# Generated by 1.1.7.1 https://github.com/kyuridenamida/atcoder-tools
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    A = [int(next(tokens)) for _ in range(N - 0 + 1)]  # type: "List[int]"
    print(solve(N, A))

def test():
    import doctest
    doctest.testmod()

if __name__ == '__main__':
    #test()
    main()


Measured memory_bytes: 684160
import sys


def main() -> None:
    n = int(input())
    a = [0] * n
    b = [0] * n
    ans = 0

    for i in range(n):
        a[i], b[i] = map(int, sys.stdin.readline().split())

    for i in range(n - 1, -1, -1):
        a[i] += ans
        if a[i] % b[i] != 0:
            ans += abs(a[i] % b[i] - b[i])

    print(ans)


if __name__ == '__main__':
    main()

Measured memory_bytes: 14836
#include<stdio.h>
#define INF 1000000
int graph[101][101],n,c,d;

void warshall_floyd(){
  int i,j;
  for(i=1;i<=n;i++)
    for(j=1;j<=n;j++)
      graph[i][j]=graph[j][i]=min(graph[i][j],graph[i][c]+graph[c][d]+graph[d][j]);
}

int min(int x,int y){
  return x<y?x:y;
}

int main(){
  int k,i,j,x,e,a,b;

  while(scanf("%d %d",&n,&k),n,k){

    for(i=1;i<=n;i++)
      for(j=1;j<=n;j++)
	graph[i][j]=i==j?0:INF;
    
    for(i=0;i<k;i++){
      if(scanf("%d",&x),x){
	scanf("%d %d %d",&c,&d,&e);

	if(graph[c][d]>e){
	graph[c][d]=e;
	graph[d][c]=e;
	warshall_floyd();
	}
      }else{
	scanf("%d %d",&a,&b);
	printf(graph[a][b]>=INF?"-1\n":"%d\n",graph[a][b]);
      }
    }
  }
  return 0;
}

Measured memory_bytes: 0
import sys
s = input()
k = int(input())
k = min(k,len(s))
i = 0
flag = 0
while i < k:
  if int(s[i]) != 1:
    print(s[i])
    flag = 1
    sys.exit()
  i += 1
if flag == 0:
  print(1)

Measured memory_bytes: 3060
A, B = map(int, input().split())

def xor(n):
  if n % 2 == 0:
    if int(n / 2) % 2 == 0:
      return n
    else:
      return n ^ 1
  else:
    if int((n + 1) / 2) % 2 == 0:
      return 0
    else:
      return 1

if A == B:
  print(A)
else:
  print(xor(A - 1) ^ xor(B))

Measured memory_bytes: 3060
#include<stdio.h>
int main(){
  int a;
  scanf("%d",&a);
  int b[a+1],c=0;
  for(int i=1; i<=a; i++){
    scanf("%d",&b[i]);
    c+=b[i];
  }
  int d;
  scanf("%d",&d);
  int e[d];
  for(int i=0; i<d; i++){
    int f,g;
    scanf("%d %d",&f,&g);
    e[i]=c-(b[f]-g);
  }
  for(int i=0; i<d; i++){
    printf("%d\n",e[i]);
  }
  return 0;}

Measured memory_bytes: 128
#define _CRT_SECURE_NO_WARNINGS
#pragma comment(linker, "/stack:200000000")
#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#pragma GCC optimize("unroll-loops")
#include <set>
#include <map>
#include <deque>
#include <cmath>
#include <queue>
#include <random>
#include <bitset>
#include <time.h>
#include <string>
#include <cstdio>
#include <vector>
#include <cstdlib>
#include <iomanip>
#include <cassert>
#include <iostream>
#include <algorithm>
#include <unordered_map>
#include <unordered_set>
//++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++
//#define endl '\n'
#define mp make_pair
#define pbc push_back
#define pob pop_back()
#define empb emplace_back
#define sp system("pause")
#define queuel queue<long long>
#define all(x) (x).begin(),(x).end()
#define matrix vector<vector<ll>>
#define pin(p) cin >> p.first >> p.second;
#define rev(v) reverse(v.begin(),v.end());
#define mx(v) max_element(v.begin(), v.end());
#define mn(v) min_element(v.begin(), v.end());
#define sout(s, c) for(auto i : s) cout << i << c;
#define pout(p) cout << p.first << " " << p.second;
#define er(v, l, r) erase(v.begin() + l, v.begin() + r);
#define vin(v) for(ll i = 0; i < v.size(); ++i) cin >> v[i];
#define vout(v, c) for(int i = 0; i < v.size(); ++i) cout << v[i] << c;
#define pushi(v, a) for(int i = 0; i < a.size(); ++i) v.push_back(a[i]);
#define sin(s, n) for(int i = 0; i < n; ++i){int a; cin >> a; s.insert(a);}
#define fastio() ios_base::sync_with_stdio(0);cout.tie(0);cin.tie(0);srand(time(NULL));
//++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++
using namespace std;
//++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++
typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;
//++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++
const ll INF = 1000LL * 1000 * 1000 * 1000 * 1000 * 1000;
const int inf = 1000 * 1000 * 1000;
const ld PI = acos(-1.0);
const ll mod1 = inf + 7;
const ll mod2 = inf + 9;
const int MAXN = 500001;
const ld EPS = 1e-9;
int hp = 179;

signed main()
{
	fastio();
	ll a, b;
	cin >> a >> b;
	cout << max({ a + b,a - b,a*b });
	sp;
}

Measured memory_bytes: 504
#include <bits/stdc++.h>
using namespace std ;
//#define int long long
#define rep(i, a, b) for (int i = (a); i <= (b); i++)
#define per(i, a, b) for (int i = (a); i >= (b); i--)
#define loop(it, v) for (auto it = v.begin(); it != v.end(); it++)
#define cont(i, x) for (int i = head[x]; i; i = e[i].nxt)
#define clr(a) memset(a, 0, sizeof(a))
#define ass(a, sum) memset(a, sum, sizeof(a))
#define lowbit(x) (x & -x)
#define all(x) x.begin(), x.end()
#define SC(t, x) static_cast <t> (x)
#define ub upper_bound
#define lb lower_bound
#define pqueue priority_queue
#define mp make_pair
#define pb push_back
#define pof pop_front
#define pob pop_back
#define fi first
#define se second
#define y1 y1_
#define Pi acos(-1.0)
#define iv inline void
#define enter cout << endl
#define siz(x) ((int)x.size())
#define file(x) freopen(x".in", "r", stdin),freopen(x".out", "w", stdout)
typedef long double ld ;
typedef long long ll ;
typedef unsigned long long ull ;
typedef pair <int, int> pii ;
typedef pair <ll, int> pli ;
typedef pair<int, pii> tri ;
typedef vector <int> vi ;
typedef vector <pii> vii ;
typedef vector <vi> vvi ;
typedef vector <string> vst ;
typedef queue <int> qi ;
typedef queue <pii> qii ;
typedef set <int> si ;
typedef map <int, int> mii ;
typedef map <string, int> msi ;
const int N = 100010 ;
const int INF = 0x3f3f3f3f ;
const int iinf = 1 << 30 ;
const ll linf = 2e18 ;
const int mod = 1000000007 ;
const double eps = 1e-7 ;
void douout(double x){ printf("%lf\n", x + 0.0000000001) ; }
template <class T> void print(T a) { cout << a << endl ; exit(0) ; }
template <class T> void chmin(T &a, T b) { if (a > b) a = b ; }
template <class T> void chmax(T &a, T b) { if (a < b) a = b ; }
template <class T> void Tmin(T &a, T &b, T &c) { return min(a, min(b, c)) ; }
template <class T> void Tmax(T &a, T &b, T &c) { return max(a, max(b, c)) ; }
void add(int &a, int b) { a = a + b < mod ? a + b : a + b - mod ; }
void sub(int &a, int b) { a = (a - b + mod) % mod ; }
void mul(int &a, int b) { a = (ll) a * b % mod ; }
int addv(int a, int b) { return (a += b) >= mod ? a -= mod : a ; }
int subv(int a, int b) { return (a -= b) < 0 ? a += mod : a ; }
int mulv(int a, int b) { return (ll) a * b % mod ; }
int read() {
    int f = 1, x = 0 ;
    char ch = getchar() ;
    while (!isdigit(ch)) { if (ch == '-') f = -1 ; ch = getchar() ; }
    while (isdigit(ch)) { x = x * 10 + ch -'0' ; ch = getchar() ; }
    return x * f ;
}
int pw(int a, int b) {
    int s = 1 ;
    for (; b; b >>= 1, a = (ll) a * a % mod)
    if (b & 1) s = (ll) s * a % mod ;
    return s ;
}

int n, m, k ;
int a[N] ;

signed main() {
	scanf("%d%d%d", &n, &m, &k) ;
	rep(i, 1, k) {
		int x ; scanf("%d", &x) ;
		a[x] ++ ;
	}  
	rep(i, 1, n) a[i] -= k - m ;
	rep(i, 1, n) puts(a[i] > 0 ? "Yes" : "No") ; 
	return 0 ;
}


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

using namespace std;
// ascending order
#define vsort(v) sort(v.begin(), v.end())
// descending order
#define vsort_r(v) sort(v.begin(), v.end(), greater<int>())
#define vunique(v) v.erase(unique(v.begin(), v.end()), v.end())
#define mp make_pair
#define ts(x) to_string(x)
#define rep(i, a, b) for(int i = (int)a; i < (int)b; i++)
#define repm(i, a, b) for(int i = (int)a; i > (int)b; i--)
#define bit(a) bitset<8>(a)
#define des_priority_queue priority_queue<int, vector<int>, greater<int> >
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; }
typedef long long ll;
typedef pair<int, int> P;
const ll INF = 1e18;

#define MAX_E 100000
#define MAX_V 100000

struct edge {
	ll from, to, cost;
};
ll d[MAX_V];
ll V, E;

edge es[MAX_E];

void shortest_path(ll s) {
	rep(i, 0, V) d[i] = INF;
	d[s] = 0;
	while(true) {
		bool update = false;
		rep(i, 0, E) {
			edge e = es[i];
			if(d[e.from] != INF && d[e.to] > d[e.from] + e.cost) {
				d[e.to] = d[e.from] + e.cost;
				update = true;
			}
		}
		if(!update) break;
	}
}

bool find_negative_loop(ll s) {
	//memset(d, 0, sizeof(d));
	fill(d, d + V, INF);
	d[s] = 0;
	rep(i, 0, V) {
		rep(j, 0, E) {
			edge e = es[j];
			if(d[e.from] != INF && d[e.to] > d[e.from] + e.cost) {
				d[e.to] = d[e.from] + e.cost;
				if(i == V - 1 and e.to == V - 1) return true;
			}
		}
	}
	return false;
}

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

  cin >> V >> E;
  rep(i, 0, E) {
    ll a, b, c;
    cin >> a >> b >> c;
    edge e = {--a, --b, -c};
    es[i] = e;
  }

  if(find_negative_loop(0)) {
    cout << "inf" << endl;
    return 0;
  }

  if(d[V - 1] == INF) cout << "inf" << endl;
  else cout << -d[V - 1] << endl;
}



Measured memory_bytes: 384
#include <bits/stdc++.h>
 
using namespace std;
 
#define MD 1000000007
typedef long long int ll;
 
int main(){
    ll n,k;
    cin>>n>>k;
    k--;
    long int sum=n,ans=0;
    while(n-1>0){
        n-=k;
        ans++;
    }
    cout<<ans<<endl;
    
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <queue>
#include <cmath>
#include <climits>
#include <iomanip>
#include <set>
#include <map>
using namespace std;
typedef long long ll;
int main(){
  char c;
  cin >> c;
  char res;
  if(c == 'A')res = 'T';
  if(c == 'T')res = 'A';
  if(c == 'C')res = 'G';
  if(c == 'G')res = 'C';
  cout << res << endl;
}

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

int main(){
	int a,b,tortal=0,price=0,count=0;
	double average;
	while(scanf("%d,%d",&a,&b) != EOF){
		tortal += a*b;
		price += b;
		count++;
	}
	average = floor((double)price/count + 0.5);

	printf("%d\n%d\n",tortal,(int)average);
	return 0;
}

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

#define dump(...) cout<<"# "<<#__VA_ARGS__<<'='<<(__VA_ARGS__)<<endl
#define repi(i,a,b) for(int i=int(a);i<int(b);i++)
#define peri(i,a,b) for(int i=int(b);i-->int(a);)
#define rep(i,n) repi(i,0,n)
#define per(i,n) peri(i,0,n)
#define all(c) begin(c),end(c)
#define mp make_pair
#define mt make_tuple

using uint=unsigned;
using ll=long long;
using ull=unsigned long long;
using vi=vector<int>;
using vvi=vector<vi>;
using vl=vector<ll>;
using vvl=vector<vl>;
using vd=vector<double>;
using vvd=vector<vd>;
using vs=vector<string>;

template<typename T1,typename T2>
ostream& operator<<(ostream& os,const pair<T1,T2>& p){
	return os<<'('<<p.first<<','<<p.second<<')';
}

template<typename Tuple>
void print_tuple(ostream&,const Tuple&){}
template<typename Car,typename... Cdr,typename Tuple>
void print_tuple(ostream& os,const Tuple& t){
	print_tuple<Cdr...>(os,t);
	os<<(sizeof...(Cdr)?",":"")<<get<sizeof...(Cdr)>(t);
}
template<typename... Args>
ostream& operator<<(ostream& os,const tuple<Args...>& t){
	print_tuple<Args...>(os<<'(',t);
	return os<<')';
}

template<typename Ch,typename Tr,typename C>
basic_ostream<Ch,Tr>& operator<<(basic_ostream<Ch,Tr>& os,const C& c){
	os<<'[';
	for(auto i=begin(c);i!=end(c);++i)
		os<<(i==begin(c)?"":" ")<<*i;
	return os<<']';
}

constexpr int INF=1e9;
constexpr int MOD=1e9+7;
constexpr double EPS=1e-9;

bool solve(string s)
{
	return regex_match(s,regex("(dream|dreamer|erase|eraser)+"));
}

int main()
{
	for(string s;cin>>s;){
		cout<<(solve(s)?"YES":"NO")<<endl;
	}
}


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

long long N;
//      active, index
vector<pair<long long, long long> >vec;

//          left,  right
long long dp[2005][2005];

int main(){
	cin >> N;
	for(long long i = 0; i < N; i++) {
		long long a;
		cin >> a;
		vec.push_back(make_pair(a, i));
	}

	sort(vec.begin(), vec.end(), greater<pair<long long, long long> >());

	long long ans = 0;
	for(long long i = 0; i < vec.size(); i++) {
		long long active = vec[i].first;
		long long index = vec[i].second;

		long long curnum = i;
		for(long long left = 0; left <= curnum; left++) {
			long long right = curnum - left;
			//leftにつける場合
			dp[left+1][right] = max(dp[left+1][right], dp[left][right] + active * abs(index - left));
			ans = max(ans, dp[left+1][right]);
			//rightにつける場合
			dp[left][right+1] = max(dp[left][right+1], dp[left][right] + active * abs(index - (N-1-right)));
			ans = max(ans, dp[left][right+1]);
		}
	}
	cout << ans << endl;
}


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

int main() {
  char c;
  int a = 0;
  cin >> c;

  if (c == 'a') 
    a++;
  else if (c == 'i') 
    a++;
  else if (c == 'u')
    a++;
  else if (c == 'e')
    a++;
  else if (c == 'o')
    a++;

  if (a == 0)
    cout << "consonant";
  else
    cout << "vowel";
}

Measured memory_bytes: 256
fun main(args: Array<String>) {
    val n = readLine()!!.toInt()

    val answer = (2..(n / 2 + 1)).map {
        val a = it
        val b = n - a

        val sumA = a.toString()
                .map { Integer.parseInt(it.toString()) }
                .sum()
        val sumB = b.toString()
                .map { Integer.parseInt(it.toString()) }
                .sum()

//        println("a=$a, b=$b, sumA=$sumA, sumB=$sumB")

        Triple(a, b, sumA + sumB)
    }.minBy { it.third }

    println(answer?.third)
}

Measured memory_bytes: 56968
#include<stdio.h>

int main(void)
{
    int N , n , i , j , h , max , min ;
    int a[101] ;

    scanf("%d",&N);
    for(i=0;i<N;i++){

        for(j=0;j<101;j++){
            a[j]=0;
        }
        max = 0 ;
        min = 0 ;

        scanf("%d",&n);
        for(j=1;j<=n;j++){
            scanf("%d",&h);
            a[j] = h ;
            if((max < (a[j] - a[j-1])) && j != 1){
                max = a[j] - a[j-1] ;
            }
            if(min < (a[j-1] - a[j])){
                min = a[j-1] - a[j] ;
            }
        }
        printf("%d %d\n",max,min);
    }
    return 0;
}

Measured memory_bytes: 592
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<ll,ll> P;
typedef pair<int,int> Pi;
#define rep(i, n) for (ll i = 0; i < n; i++)
#define FOR(i, a, b) for (ll i = a; i < b; i++)
#define fi first
#define se second
#define PI (acos(-1))

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;
}
template<typename T> ostream& operator<<(ostream& s,const complex<T>& d) {return s<<"("<<d.real()<<", "<<d.imag()<< ")";}
template<typename T1, typename T2> ostream& operator<<(ostream& s,const pair<T1,T2>& d) {return s<<"("<<d.first<<", "<<d.second<<")";}
template<typename T> ostream& operator<<(ostream& s, const vector<T>& d){
	int len=d.size();
	rep(i,len){
		s<<d[i];if(i<len-1) s<<" ";
	}
	return s;
}
template<typename T> ostream& operator<<(ostream& s,const vector<vector<T>>& d){
	int len=d.size();
	rep(i,len){
		s<<d[i]<<endl;
	}
	return s;
}
template<typename T> ostream& operator<<(ostream& s,const set<T>& v){
	s<<"{ ";
	for(auto itr=v.begin();itr!=v.end();++itr) {
		if (itr!=v.begin()) {s<< ", ";}
		s<<(*itr);
	}
	s<<" }";
	return s;
}
template<typename T1, typename T2> ostream& operator<<(ostream& s,const map<T1,T2>& m){
	s<<"{"<<endl;
	for(auto itr=m.begin();itr!=m.end();++itr){
		s<<" "<<(*itr).first<<" : "<<(*itr).second<<endl;
	}
	s<<"}"<<endl;
	return s;
}

const ll mod=1e9+7;
const ll inf=1e15;
const int INF=1e9;

int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	int k,x;
	cin>>k>>x;
	for(int i=x-k+1;i<=x+k-1;i++){
		cout<<i<<endl;
	}
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define fi first
#define se second
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define drep(i,n) for(int i = (n)-1; i >= 0; --i)
#define srep(i,s,t) for (int i = s; i < t; ++i)
#define rng(a) a.begin(),a.end()
#define sz(x) (int)(x).size()
#define uni(x) x.erase(unique(rng(x)),x.end())
#define show(x) cout<<#x<<" = "<<x<<endl;
#define PQ(T) priority_queue<T,v(T),greater<T> >
#define newline puts("")
#define v(T) vector<T>
#define vv(T) v(v(T))
using namespace std;
typedef long long int ll;
typedef pair<int,int> P;
typedef set<int> S;
typedef queue<int> Q;
typedef queue<P> QP;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<P> vp;
const ll LINF = 1001002003004005006ll;
const int INF = 1001001001;
const int MOD = 1000000007;
  
int main() {
  vi a(3);
  cin >> a[0] >> a[1] >> a[2];
  sort(rng(a));
  int sum = 0;
  rep(i,2) {
    sum += abs(a[i+1]-a[i]);
  }
  cout << sum << endl;
  return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main() {
  int K; cin >> K;
  vector<long long> rec(0);
  for(long long i = 1; i < 10; i++) {
    rec.push_back(i);
  }
  bool judge = false;
  for(long long i = 0; true; i++) {
    long long x = rec.at(i);
    int add = x % 10;
    for(int j = -1; j < 2; j++) {
      if(add + j != -1 && add + j != 10) {
        rec.push_back(x * 10 + add + j);
        if(x * 10 + add + j == 10000000000) {
          judge = true;
        }
      }
      
    }
    if(judge) break;
  }
  sort(rec.begin(), rec.end());
  cout << rec.at(K - 1) << endl;
}

Measured memory_bytes: 2420
#include<bits/stdc++.h>
using namespace std;
#define int long long
typedef unsigned long long ull;
typedef vector<ull> vec;
typedef vector<vec> mat;
typedef pair<int,ull> P;
#define N 4
ull po[N*N+10];
ull m2i(mat m){
  int res=0;
  for(int i=0;i<N;i++)
    for(int j=0;j<N;j++)
      res+=m[i][j]*po[i*N+j];
  return res;
}
mat i2m(ull x){
  mat res(N,vec(N));
  for(int i=0;i<N;i++)
    for(int j=0;j<N;j++)
      if(i==N-1&&j==N-1) res[i][j]=x/po[i*N+j];
      else res[i][j]=(x%po[i*N+j+1])/po[i*N+j];
  return res;
}
int dist(mat m){
  int res=0;
  for(int i=0;i<N;i++){
    for(int j=0;j<N;j++){
      if(!m[i][j]) continue;
      int k=m[i][j]-1;
      int y=k/N,x=k%N;
      res+=abs(i-y)+abs(j-x);
    }    
  }
  return res;
}
signed main(){
  po[0]=1;
  for(int i=0;i<N*N;i++) po[i+1]=po[i]*(N*N);
  mat p(N,vec(N));
  for(int i=0;i<N;i++)
    for(int j=0;j<N;j++)
      cin>>p[i][j];
  mat e(p);
  for(int i=0;i<N;i++)
    for(int j=0;j<N;j++)
      e[i][j]=i*N+j+1;
  e[N-1][N-1]=0;
  ull ans=m2i(e);
  //cout<<ans<<endl;
  priority_queue<P,vector<P>,greater<P> > q;
  map<ull,int> m;
  q.push(P(dist(p),m2i(p)));
  m[m2i(p)]=0;
  int ax[]={1,0,-1,0};
  int ay[]={0,1,0,-1};
  while(!q.empty()){
    P y=q.top();q.pop();
    ull x=y.second;
    if(x==ans) break;
    p=i2m(x);
    int zy,zx;
    for(int i=0;i<N;i++)
      for(int j=0;j<N;j++)
	if(p[i][j]==0) zy=i,zx=j;
    //cout<<zy<<" "<<zx<<endl;
    for(int k=0;k<4;k++){
      int ny=zy+ay[k],nx=zx+ax[k];
      if(ny<0||N<=ny||nx<0||N<=nx) continue;
      swap(p[zy][zx],p[ny][nx]);
      ull t=m2i(p);
      //cout<<t<<endl;
      if(!m.count(t)||m[x]+1<m[t]){
	m[t]=m[x]+1;
	//if(t==ans) break;
	q.push(P(m[t]+dist(p),t));
      }
      swap(p[zy][zx],p[ny][nx]);
    }
  }
  cout<<m[ans]<<endl;
  return 0;
}

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

using namespace std;

int main() {
	int n; cin >> n;
	vector<int> p(n);
	for (int i = 0; i < n; ++i) 
		cin >> p[i];
	int cnt = 0;
	for (int i = 1; i < n - 1; ++i) {
		if ((p[i - 1] > p[i] && p[i] > p[i + 1]) ||
			(p[i + 1] > p[i] && p[i] > p[i - 1])) cnt++;
	}
	cout << cnt << endl;

	return 0;
}

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

int main() {
	
	int n;
	cin >> n;
	int ans = 0;
	rep(i, n){
		int a;
		cin >> a;
		while(a % 2 == 0){
			a /= 2;
			ans++;
		}
	}
	cout << ans << endl;
	return 0;
}

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

int main()
{
	int R, G, B, N;
	cin >> R >> G >> B >> N;

	long long ans = 0;
	for( int r = 0; r <= N / R; r++ ) {
		for( int g = 0; g <= N / G; g++ ) {
			int n = N - (r * R + g * G);
			if( 0 <= n && n % B == 0 ) ans++;
		}
	}

	cout << ans << endl;
}


Measured memory_bytes: 3632
class Dice

  def initialize(given_ary)
    @ary = given_ary
  end

  def topface(val)
    4.times do
      self.roll ("E")
      if self.top == val
        return
      end
    end
    3.times do
      self.roll("N")
      if self.top == val
        return
      end
    end
  end

  def frontface(val)
    4.times do
      tmp = @ary[1]
      @ary[1] = @ary[2]
      @ary[2] = @ary[4]
      @ary[4] = @ary[3]
      @ary[3] = tmp
    if @ary[1] == val
      return
    end
  end
end

def roll(direction)
  case direction.downcase
  when "e"
    tmp = @ary[0]
    @ary[0] = @ary[3]
    @ary[3] = @ary[5]
    @ary[5] = @ary[2]
    @ary[2] = tmp
  when "w"
    tmp = @ary[0]
    @ary[0] = @ary[2]
    @ary[2] = @ary[5]
    @ary[5] = @ary[3]
    @ary[3] = tmp
  when "s"
    tmp = @ary[0]
    @ary[0] = @ary[4]
    @ary[4] = @ary[5]
    @ary[5] = @ary[1]
    @ary[1] = tmp
  when "n"
    tmp = @ary[0]
    @ary[0] = @ary[1]
    @ary[1] = @ary[5]
    @ary[5] = @ary[4]
    @ary[4] = tmp
  end
end

  def top
    @ary[0]
  end

  def front
    @ary[5]
  end

  def right
    @ary[2]
  end

end

  dice = Dice.new(gets.split.map(&:to_i))
  gets.to_i.times do
    top,front = gets.split.map(&:to_i)
    dice.topface(top)
    dice.frontface(front)
    puts dice.right
end

















    
    

Measured memory_bytes: 8680
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <map>

typedef unsigned long long ull;
typedef long long ll;

using namespace std;

int main(void) {
    int N;
    cin >> N;
    vector<int> A(N);

    map<int, int> Acount;

    ll ans = 0;
    for(int i = 0; i < N; ++i) {
        cin >> A[i];
        Acount[A[i]]++;
        if(Acount[A[i]] > A[i]) {
            ans++;
        }
    }

    for(auto pair : Acount) {
        if (Acount[pair.first] < pair.first) {
            ans += pair.second;
        }
    }

    cout << ans << endl;


    return 0;
}


Measured memory_bytes: 5120
#include<bits/stdc++.h>
#include<iostream>
#include<set>
#define ll long long
using namespace std;
int main() {
	ll t;
	cin >>t;
	ll num=0;
	map<string , int> a;
	while(t--) {
		string s;
		cin >>s;
		sort(s.begin(),s.end());
		num +=a[s]++;
	}
	cout<<num<<endl;
	return 0;
}


Measured memory_bytes: 11136
//marico el que lo lea
#include <iostream>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <algorithm>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <stack>
using namespace std;

#define FOR(i,f,t) for(int i=f; i<(int)t; i++)
#define FORR(i,f,t) for(int i=f; i>(int)t; i--)
#define pb push_back
#define ms(obj, val) memset(obj, val, sizeof(obj))
#define ms2(obj, val, sz) memset(obj, val, sizeof(obj[0])*sz)
#define ri(x) scanf("%d",&x)
#define rl(x) scanf("%lld",&x)
#define rii(x,y) ri(x), ri(y)
#define rll(x,y) rl(x), rl(y)

#define fst first
#define snd second

typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef pair<int, int> ii;

const int MAXN = 1e5+5;

int N;
pair<pair<ll, ll>, int> p[MAXN];
vector<pair<ll, ii> > E;

int rep[MAXN];
int find(int v){
	if(rep[v] == v) return v;
	return rep[v] = find(rep[v]);
}

ll kruskal(){
	sort(E.begin(), E.end());
	FOR(i,0,N) rep[i]=i;
	ll ret = 0;
	FOR(i,0,E.size()){
		int v = E[i].snd.fst, u = E[i].snd.snd;
		ll c = E[i].fst;
		v = find(v); u = find(u);
		if(v!=u){
			rep[u] = v;
			ret += c;
		}
	}
	return ret;
}

int main(){
	ri(N);
	FOR(i,0,N) rll(p[i].fst.fst, p[i].fst.snd);
	FOR(i,0,N) p[i].snd = i;
	sort(p, p+N);
	FOR(i,0,N-1){
		E.pb({p[i+1].fst.fst - p[i].fst.fst, {p[i].snd, p[i+1].snd}});
	}
	FOR(i,0,N) swap(p[i].fst.fst, p[i].fst.snd);
	sort(p, p+N);
	FOR(i,0,N-1){
		E.pb({p[i+1].fst.fst - p[i].fst.fst, {p[i].snd, p[i+1].snd}});
	}
	printf("%lld\n",kruskal());
}

Measured memory_bytes: 8816
# -*- coding: utf-8 -*-
from sys import stdin
# import numpy as np

s_in = lambda: stdin.readline()[:-1]  # s = s_in()
d_in = lambda: int(stdin.readline())  # N = d_in()
ds_in = lambda: list(map(int, stdin.readline().split()))  # List = ds_in()


def func(n):
    if n % 2 == 0:
        return n // 2
    else:
        return 3 * n + 1


s = d_in()
searched = [s]
idx = 1
while True:
    s = func(s)
    idx += 1
    if s in searched:
        print(idx)
        exit()
    else:
        searched.append(s)


Measured memory_bytes: 3060
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
using namespace std;
const int INF = 100000000;
const int MAX_N = 100;
typedef pair<int , int> P;
typedef long long ll;
 
int main () {
  double N, K, ans;
  cin >> N >> K;
  ans = 0;
  for (int i = 1; i <= N; ++i) {
    double tmp1 = 1 / N;
    double tmp2 = i;
    for (;;) {
      if (tmp2 < K) {
        tmp1 *= 0.5;
        tmp2 *= 2;
      } else {
        break;
      }
    }
    ans += tmp1;
  }
  printf("%.12lf\n", ans);
  return 0;
}

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

int n,m;
int A[10000][10000];
int c[10000];

int cal(int i){
  int ans=0;
  for(int j=0;j<m;j++){
    ans+=A[i][j]*c[j];
  }
  return ans;
}

int main(){
  
  cin >> n >> m;
  
  for(int i=0;i<n;i++){
    for(int j=0;j<m;j++)
      {
	cin >> A[i][j];
      }
  }

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

  for(int i=0;i<n;i++){
    cout << cal(i) << endl;
  }
}



Measured memory_bytes: 3476
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
using pint = pair<int,  int>;
using edge = int;
using graph = vector<vector<edge>>;
const ll INF = 1LL << 60;
const int INF32 = 1 << 29;
const ll MOD = 1000000007;


int main() {
	ll  n, m;cin >>n>> m;
	map<ll, int> mp;
	for(int i = 0; i < m; ++i) {
		ll a, b;cin >>a>> b;
		mp[a]++; mp[b]++;
    }
    for(auto it : mp){
        if(it.second%2==1){
            cout << "NO" << endl;
            return 0;
        }
    }
    cout << "YES" << endl;
}


Measured memory_bytes: 5632
#include <bits/stdc++.h>
#define int long long
#define pii pair<int,int>
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n) FOR(i,0,n)
#define ALL(c) (c).begin(),(c).end()
#define ZERO(a) memset(a,0,sizeof(a))
#define MINUS(a) memset(a,0xff,sizeof(a))
#define MINF(a) memset(a,0x3f,sizeof(a))
#define POW(n) (1LL<<(n))
#define IN(i,a,b) (a <= i && i <= b)
using namespace std;
template <typename T> inline bool CHMIN(T& a,T b) { if(a>b) { a=b; return 1; } return 0; }
template <typename T> inline bool CHMAX(T& a,T b) { if(a<b) { a=b; return 1; } return 0; }
template <typename T> inline void SORT(T& a) { sort(ALL(a)); }
template <typename T> inline void REV(T& a) { reverse(ALL(a)); }
template <typename T> inline void UNI(T& a) { sort(ALL(a)); a.erase(unique(ALL(a)),a.end()); }
template <typename T> inline T LB(vector<T>& v, T a) { return *lower_bound(ALL(v),a); }
template <typename T> inline int LBP(vector<T>& v, T a) { return lower_bound(ALL(v),a) - v.begin(); }
template <typename T> inline T UB(vector<T>& v, T a) { return *upper_bound(ALL(v),a); }
template <typename T> inline int UBP(vector<T>& v, T a) { return upper_bound(ALL(v),a) - v.begin(); }
template <typename T1, typename T2> ostream& operator<< (ostream& os, const pair<T1,T2>& p) { os << p.first << " " << p.second; return os; }
template <typename T1, typename T2> istream& operator>> (istream& is, pair<T1,T2>& p) { is >> p.first >> p.second; return is; }
template <typename T> ostream& operator<< (ostream& os, const vector<T>& v) { REP(i,v.size()) { if (i) os << " "; os << v[i]; } return os; }
template <typename T> istream& operator>> (istream& is, vector<T>& v) { for(T& in : v) is >> in; return is; }
template <typename T = int> vector<T> make_v(size_t a) { return vector<T>(a); }
template <typename T, typename... Ts> auto make_v(size_t a, Ts... ts) { return vector<decltype(make_v<T>(ts...))>(a,make_v<T>(ts...)); }
template <typename T, typename V> typename enable_if<is_class<T>::value == 0>::type fill_v(T &t, const V &v) { t = v; }
template <typename T, typename V> typename enable_if<is_class<T>::value != 0>::type fill_v(T &t, const V &v) { for(auto &e : t) fill_v(e,v); }
const int MOD = 1000000007;
const int INF = 0x3f3f3f3f3f3f3f3f;
const double EPS = 1e-10;

const int MAX_N = 100010;
bool isp[MAX_N];  // i が素数かどうか
int mf[MAX_N];    // i の最小の素因数
vector<int> prime;

void sieve(int n = MAX_N) {
  fill(isp+2,isp+n,true);
  mf[1] = 1;
  for (int i = 2; i < n; i++) {
    if (isp[i]) {
      prime.push_back(i);
      mf[i] = i;
      for (int j = 2 * i; j < n; j += i) {
        isp[j] = false;
        if (mf[j] == 0) mf[j] = i;
      }
    }
  }
}

int cum[MAX_N];

signed main() {
  cin.tie(nullptr);
  ios::sync_with_stdio(false);
  cout << fixed << setprecision(10);

  sieve();
  for (int i = 3; i < MAX_N; i++) {
    if (isp[i] && isp[(i + 1) / 2]) cum[i]++;
    cum[i] += cum[i-1];
  }

  int Q;
  cin >> Q;
  REP(i,Q) {
    int l,r;
    cin >> l >> r;
    cout << cum[r] - cum[l-1] << endl;
  }

  return 0;
}

Measured memory_bytes: 2560
#include <iostream>
 
#define _USE_MATH_DEFINES
 
#include <cmath>
 
using namespace std;
 
int main()
{
    int n;
    int i;
    double sd;
    double sum, point[1000] = {};
    double ave = 0;
 
    while (1){
        cin >> n;
         
        if (n == 0)
            break;
 
        sd = 0;
        sum = 0;
        for (i = 0; i < n; i++){
            cin >> point[i];
            sum += point[i];
        }
        ave = sum / n;
        for (i = 0; i < n; i++){
            sd += (point[i] - ave)*(point[i] - ave);
        }
        sd = sqrt(sd / n);
 
        cout << fixed << sd << endl;
 
    }
 
    return 0;
}

Measured memory_bytes: 3224
fn main() {
    read::<u32>();
    let mut arr = read_vec::<u32>();
    let mut res = 0;
    'outer: loop {
        for i in 0..arr.len() {
            if arr[i] % 2 == 0 {
                arr[i] = arr[i] / 2;
            } else {
                break 'outer;
            }
        }
        res += 1;
    }
    println!("{}", res);
}

#[allow(dead_code)]
fn read<T: std::str::FromStr>() -> T {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).ok();
    s.trim().parse().ok().unwrap()
}

#[allow(dead_code)]
fn read_vec<T: std::str::FromStr>() -> Vec<T> {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).ok();
    s.trim().split_whitespace()
        .map(|e| e.parse().ok().unwrap()).collect()
}

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

sys.setrecursionlimit(10**7)
inf = 10**20
eps = 1.0 / 10**10
mod = 10**9+7
dd = [(-1,0),(0,1),(1,0),(0,-1)]
ddn = [(-1,0),(-1,1),(0,1),(1,1),(1,0),(1,-1),(0,-1),(-1,-1)]

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


def main():
    a = sorted(LI())
    return a[-1] - a[0]


print(main())


Measured memory_bytes: 7752
import math

def solve(n, k):
    f = lambda i: 1 / 2 ** math.ceil(math.log2(k / i))
    return sum(1 / n * (1 if k <= i else f(i)) for i in range(1, n + 1))

_n, _k = map(int, input().split())
print(solve(_n, _k))

Measured memory_bytes: 3060
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int (i) = 0; (i) < (n); ++(i))
#define rrep(i,n) for(int (i) = (n) - 1; (i) >= 0; --(i)) //Reversi rep
#define nfor(i,a,b) for(int (i) = (a); (i) < (b); ++(i)) //Natural for
#define rfor(i,a,b) for(int (i) = (b); (i) >= (a); --(i)) //Reversi for
#define ll long long
#define mod (1000000007)
#define YES cout << "YES" << endl;
#define Yes cout << "Yes" << endl;
#define NO cout << "NO" << endl;
#define No cout << "No" << endl;

int asc(const void *a, const void *b) {
    return *(int *)a - *(int *)b;
}

int desc(const void *a, const void *b) {
    return *(int *)b - *(int *)a;
}

int main()
{
    string s,ans;
    cin >> s;
    rep(i, s.size()){
        if (s[i] != 'B') {
            ans.push_back(s[i]);
        }else if(ans.size() != 0){
            ans.pop_back();
        }
    }
    cout << ans << endl;
    return 0;
}


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

using namespace std;

bool is_palindromic(int i)
{
    vector<int> v;
    int j = i;
    while (j > 0)
    {
        v.push_back(j % 10);
        j /= 10;
    }

    int s = v.size();
    for (int k = 0; k < s; ++k)
    {
        if (v[k] != v[s - k - 1])
        {
            return false;
        }
    }
    return true;
}

int main()
{
    int A, B;
    cin >> A >> B;

    int sum = 0;
    for (int i = A; i <= B; ++i)
    {
        if (is_palindromic(i))
        {
            ++sum;
        }
    }

    cout << sum << endl;

    return 0;
}

Measured memory_bytes: 256
H,W=map(int,input().split())
A=[list(map(int,input().split())) for i in range(H)]
B=[list(map(int,input().split())) for i in range(H)]
d=[[0]*W for j in range(H)]
m=80*(H+W)
d[0][0]=1<<m
for h in range(H):
    for w in range(W):
        x=abs(A[h][w]-B[h][w])
        if h>0:
            d[h][w]|=d[h-1][w]
        if w>0:
            d[h][w]|=d[h][w-1]
        d[h][w]=d[h][w]<<x|d[h][w]>>x
x,y=1<<m,1<<m
for i in range(99):
    if d[H-1][W-1]&x or d[H-1][W-1]&y:
        print(i)
        exit()
    x<<=1
    y>>=1

Measured memory_bytes: 20468
#include <iostream>
#include <cmath>
#include <vector>
#include <map>
#include <iomanip>
#include <algorithm>
#include <sstream>
#include <string>
#include <math.h>
#include <set>
using namespace std;
typedef long long ll;
 
int main() {
	ios::sync_with_stdio(false);
	int a, b, c;
	cin >> a >> b >> c;
	if ((a * 100 + b * 10 + c) % 4 == 0) cout << "YES\n";
	else cout << "NO\n"; 
}


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

int main() {
	string a, b, c; cin >> a >> b >> c;
	char turn = a[0]; int acnt, bcnt, ccnt;
	acnt = bcnt = ccnt = 0; acnt++;
	for (int i = 0; i < a.size() + b.size() + c.size(); i++) {
		if (turn == 'a') {
			if (a.size() == acnt) {
				cout << 'A' << endl;
				return 0;
			}
			turn = a[acnt++];			
		}
		else if (turn == 'b') {
			if (b.size() == bcnt) {
				cout << 'B' << endl;
				return 0;
			}
			turn = b[bcnt++];
		}
		else {
			if (c.size() == ccnt) {
				cout << 'C' << endl;
				return 0;
			}
			turn = c[ccnt++];
		}
	}

	return 0;
}

Measured memory_bytes: 256
N=int(input())
from collections import defaultdict
data=defaultdict(int)
data[0]+=1
for d in map(int,input().split()):
    data[d]+=1
check=[[]]
ans=1
for d in data.keys():
    if data[d]>2:
        ans=0
        break
    checkc=check.copy()
    if data[d]==2:
        if d==0 or d==12:
            ans=0
            break
        for c in check:
            c+=[d,-1*d]
    elif data[d]==1:
        if d==0:
            for c in check:
                c.append(d)
            continue
        check=[]
        for c in checkc:
            check.append(c+[d])
            check.append(c+[-1*d])
if ans!=0:
    ans=0
    for c in check:
        c.sort()
        now=24
        for i in range(len(c)):
            now=min(now,(c[i]-c[i-1])%24)
        ans=max(now,ans)
print(ans)

Measured memory_bytes: 3436
#include <iostream>

using namespace std;

typedef long long ll;

ll pow3[111111];
ll pow2[111111];

const int MOD = 7 + 1e9;

int main () {
  string s;
  pow2[0] = 1;
  pow3[0] = 1;
  for (int i = 1; i < 111111; i++) {
    pow2[i] = pow2[i-1] * 2 % MOD;
    pow3[i] = pow3[i-1] * 3 % MOD;
  }
  while (cin >> s) {
    ll ans = pow3[s.size()];
    int ones = 0;
    for (int i = 0; i < s.size(); i++) {
      if (s[i] ==  '0') {
        ll next = pow2[ones+1] * pow3[s.size() - 1 - i];
        // cout << i << ' ' << next << endl;
        ans -= next % MOD;
        while (ans < 0) ans += MOD;
      } else {
        ones++;
      }
    }
    cout << ans << endl;
  }
}


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


using namespace std;





int main(){


	//リンゴの味が一番小さいものをつまみ食いすればよい
	int n,L;
	cin >> n >> L;
	int ans = 0;
	int aj;
	aj=n*L+n*(n+1)/2-n;
	//リンゴの味は、LからL+n-1まで
	//小さいほうからやっていこう。すべての味が負の時
	if(L<0&&L+n-1<0){//この場合は、L+n-1をもとの味から引けばいい。
		ans = aj-(L+n-1);	
		//cout<<"all mainasu"<<endl;
	  }
	else if(L<=0&&L+n-1>=0){//0を含む場合
		ans=aj;	
		//cout<<"include zero"<<endl;
	  }
	else if(L>0){// subete sei
		ans = aj - L;
		//cout<<"all plus"<<endl;
	  }



cout << ans <<endl;
}

Measured memory_bytes: 256
import java.util.*;
import java.io.*;
public class Main{
   public static void main(String[] main) throws Exception{
      BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
      StringTokenizer st = new StringTokenizer(br.readLine());
      PrintWriter out = new PrintWriter(System.out);
      int n = Integer.parseInt(st.nextToken());
      int[] a = new int[n];
      int[] b=  new int[n];
      for(int i = 0; i < n; i++) {
          st = new StringTokenizer(br.readLine());
          a[i] = Integer.parseInt(st.nextToken());
          b[i] = Integer.parseInt(st.nextToken());
      }
      Arrays.sort(a);
      Arrays.sort(b);
      if(n%2 == 1)
    	  out.println(b[n/2]-a[n/2]+1);
      else
    	  out.println(b[n/2]+b[n/2-1] - a[n/2]-a[n/2-1] + 1);
      out.close();
   }
}

Measured memory_bytes: 58740
#include<stdio.h>

int main(void) {
    
    int a[100] = {};
    char op[100] = {};
    int b[100] = {};
    
    int i, j;
    int S;
    
    for(i = 0; i < 100; i++) {
        scanf("%d %c %d", &a[i], &op[i], &b[i]);
        
        if(a[i] == 0 && op[i] == '?' && b[i] == 0) {
            break;
        }
    }
    
    for(j = 0; j < i; j++) {
        if(op[j] == '+') {
            S = a[j] + b[j];
        }
        
        else if(op[j] == '-') {
            S = a[j] - b[j];
        }
        
        else if(op[j] == '*') {
            S = a[j] * b[j];
        }
        
        else if(op[j] == '/') {
            S = a[j] / b[j];
        }
        
        else{
            continue;
        }
        
        printf("%d\n", S);
    }
    
    return 0;
}


Measured memory_bytes: 2032
/*  -*- coding: utf-8 -*-
 *
 * d.cc: D - Swap and Flip
 */

#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<iostream>
#include<string>
#include<vector>
#include<map>
#include<set>
#include<stack>
#include<list>
#include<queue>
#include<deque>
#include<algorithm>
#include<numeric>
#include<utility>
#include<complex>
#include<functional>

using namespace std;

/* constant */

const int MAX_N = 18;
const int NBITS = 1 << MAX_N;
const int INF = 1 << 30;

/* typedef */

/* global variables */

int as[MAX_N], bs[MAX_N];
int bnums[NBITS];
int dp[NBITS][MAX_N];

/* subroutines */

inline void setmin(int &a, int b) { if (a > b) a = b; }

inline int cs(int i, int p) {
  return ((i - p) & 1) ? bs[i] : as[i];
}

/* main */

int main() {
  int n;
  scanf("%d", &n);
  for (int i = 0; i < n; i++) scanf("%d", as + i);
  for (int i = 0; i < n; i++) scanf("%d", bs + i);

  int nbits = 1 << n;

  bnums[0] = 0;
  for (int bits = 1, msb = 1; bits < nbits; bits++) {
    if ((msb << 1) <= bits) msb <<= 1;
    bnums[bits] = bnums[bits ^ msb] + 1;
  }

  for (int bits = 0; bits < nbits; bits++)
    fill(dp[bits], dp[bits] + n, INF);
  for (int i = 0; i < n; i++) dp[1 << i][i] = 0;

  for (int bits = 0; bits < nbits; bits++) {
    int pi = bnums[bits] - 1, pj = pi + 1;
    for (int i = 0; i < n; i++)
      if (dp[bits][i] < INF) {
	int ci = cs(i, pi);
	for (int j = 0, bj = 1; j < n; j++, bj <<= 1)
	  if (! (bits & bj) && ci <= cs(j, pj))
	    setmin(dp[bits | bj][j], dp[bits][i] + bnums[bits & ~(bj - 1)]);
      }
  }
    
  int mind = INF;
  for (int i = 0; i < n; i++) setmin(mind, dp[nbits - 1][i]);

  printf("%d\n", (mind >= INF) ? -1 : mind);
  return 0;
}


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


#define reps(i,f,n) for(int i = f; i < int(n); i++)
#define rep(i,n) reps(i,0,n)

#define PII pair<int,int>
#define PP pair< int,PII >


using namespace std;

int main(){
	
	int n;
	char x[128];
	char deco[] ={"5789"};
	int l;
	while(scanf("%d", &n),n){
		sprintf(x, "%o", n);
		l = strlen(x);
		rep(i,l){
			rep(j,4){
				if(x[i] == '4'+j){
					x[i] = deco[j];
					break;
				}
			}
		}
		puts(x);
	}
	return 0;
}

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

int main() {
  int n;
  scanf("%d", &n);
  vector<int> a(n + 2, 0);
  for (int i = 1; i < n + 1; ++i)
    scanf("%d", &a[i]);

  long long s = 0;
  for (int i = 0; i < n + 1; ++i)
    s += abs(a[i] - a[i + 1]);

  for (int i = 1; i < n + 1; ++i) {
    long long cur = s;
    cur -= abs(a[i] - a[i - 1]);
    cur -= abs(a[i] - a[i + 1]);
    cur += abs(a[i - 1] - a[i + 1]);
    printf("%lld\n", cur);
  }
  return 0;
}

Measured memory_bytes: 1664
#include<iostream>

int main() {
	int n;
  	std::cin >> n;
  if (n == 1) { std::cout << "Hello World" << std::endl; }
  else if (n == 2) {
    int a, b;
    std::cin >> a >> b;
    std::cout << a + b << std::endl;
  }
  return 0;
}

Measured memory_bytes: 380
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int main(){
	ll a,b,c;
	cin >> a >> b >> c;
	ll d = c - a - b;
     if(d > 0 && d * d > 4 * a * b) cout << "Yes" << endl;
 	 else cout << "No" << endl;
	return 0;
}

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

int N, K;
vector<int> adj[100005];
const int M = 1e9+7;
int mult(int a, int b) {
    return (1LL*a*b) % M;
}
int fac[100005];
int modexp(int a, int b) {
    int res = 1;
    while (b) {
        if (b&1) res = mult(res,a);
        a = mult(a,a);
        b >>= 1;
    }
    return res;
}
int inverse(int x) {
    return modexp(x,M-2);
}

int dfs(int i, int p) {
    int num = i == 1 ? K-1 : K-2;
    int numChilds = i == 1 ? adj[i].size() : adj[i].size() - 1;
    if (num - numChilds < 0) {
        return 0;
    }
    int res = mult(fac[num],inverse(fac[num-numChilds]));
    /*
    cout << num << '\n';
    cout << i << ": " << res << '\n';
    */
    for (int j: adj[i]) {
        if (j == p) continue;
        res = mult(res,dfs(j,i));
    }
    //cout << i << ": " << res << '\n';
    return res;
}

int main()
{
    ios_base::sync_with_stdio(false); cin.tie(NULL);
    cin >> N >> K;
    for (int i = 0; i < N - 1; i++) {
        int a, b; cin >> a >> b;
        adj[a].push_back(b);
        adj[b].push_back(a);
    }
    fac[0] = 1;
    for (int i = 1; i <= K; i++) {
        fac[i] = mult(fac[i-1],i);
    }
    int ans = mult(K,dfs(1,1));
    cout << ans << '\n';
}



Measured memory_bytes: 10368
#include <bits/stdc++.h>
using namespace std;
 
double sum;
 
void init() {
    sum = 0.0;
    int n;
    cin >> n;
    for(int i = 0; i < n; i++){
        double x;
        cin >> x;
        string u;
        cin >> u;
        if(u == "BTC") x *= 380000.0;
        sum += x;
    }
}
 
int main(void)
{
	cin.tie(0);
	ios::sync_with_stdio(false);
 
	init();
	
    cout << sum << "\n";
 
	return 0;
}

Measured memory_bytes: 256
#include<iostream>
using namespace std;
int main(){
  int a,h[100005];
  cin >> a;
  int i;
  int Max,ans;
  Max=0;
  ans=0;
  for(i=0;i<a;i++){
    cin >> h[i];
  }
  for(i=0;i<a-1;i++){
    if(h[i]>=h[i+1]){
      Max++;
      if(ans<Max){
        ans=Max;
      }
    }else{
      Max=0;
    }
  }
  cout << ans;
  return(0);
}

Measured memory_bytes: 640
import numpy as np
import scipy.sparse as sps
import scipy.misc as spm
import collections as col
import functools as func
import itertools as ite
import fractions as frac
import math as ma
import cmath as cma
import copy as cp
import sys
def sinput(): return sys.stdin.readline().strip()
def iinput(): return int(sinput())
def imap(): return map(int, sinput().split())
def fmap(): return map(float, sinput().split())
def iarr(n=0):
    if n: return [0 for _ in range(n)]
    else: return list(imap())
def farr(): return list(fmap())
def sarr(n=0):
    if n: return ["" for _ in range(n)]
    else: return sinput().split()
def barr(n): return [False for _ in range(n)]
sys.setrecursionlimit(10**7)
MOD = 10**9 + 7; EPS = sys.float_info.epsilon
PI = np.pi; EXP = np.e; INF = np.inf

# 番兵法
h,w = imap()
grid = [[1]*(w+2)] + [[1]+[int(elm == "#") for elm in list(sinput())]+[1] for i in range(h)] + [[1]*(w+2)]

q = col.deque([(1,1)])
dep = col.defaultdict(int)
dep[(1,1)] = 1
while q:
    now = q.popleft()
    if now == (h,w): break
    x,y = now[0],now[1]
    for next in [(x,y+1),(x,y-1),(x+1,y),(x-1,y)]:
        nx,ny = next[0],next[1]
        if grid[nx][ny] or dep[next]: continue # 壁か探索済ならスキップ
        else: dep[next] = dep[now] + 1; q.append(next)

ans = 0
for elm in grid: ans += elm.count(0)
ans = ans - dep[(h,w)] if dep[(h,w)] else -1
print(ans)



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

long long n, a, b;
vector<long long> v;

bool can(long long n){
	long long count = 0;
	vector<long long> vsub = v;
	for(long long i = 0; i < vsub.size(); ++i){
		vsub[i] -= b * n;
		if(vsub[i] > 0){
			long long num = vsub[i] / (a - b) + (vsub[i] % (a - b) ? 1 : 0);
			//vsub[i] -= (a - b) * num;
			count += num;
		}
		if(count > n){
			return 0;
			break;
		}
	}
	return 1;
}
	
int main(){
	cin >> n >> a >> b;
	for(long long i = 0; i < n; ++i){
		int c; cin >> c;
		v.push_back(c);
	}
	sort(v.begin(), v.end());
	long long min = 0;
	long long max = v[v.size() - 1] / b + (v[v.size() -1] % b ? 1 : 0);
	while(1){
		long long mid = (min + max) / 2;
		if(can(mid)){
			max = mid;
		}else{
			min = mid;
		}
		if(can(max) && (!can(max - 1))){
			cout << max << endl;
			break;
		}
	}
	return 0;
}

Measured memory_bytes: 1908
#include<cstdio>
#include<vector>
#include<map>
#include<queue>
#include<algorithm>
#define MAXN 600006
#define INF 2100000000
using namespace std;
struct node
{
	int to,len;
	node(int to=0,int len=0):to(to),len(len){}
};
vector<node> road[MAXN];
int n,m,a,b,camp,in[MAXN],d[MAXN],cnt;
map<int,int> ma[MAXN];
void SPFA()
{
	in[1]=1;
	queue<int> q;
	q.push(1);
	for(int i=2;i<=cnt;i++)
		d[i]=INF;
	while(!q.empty())
	{
		int now=q.front();
		q.pop();
		in[now]=0;
		for(int i=0;i<(int)road[now].size();i++)
		{
			int nex=road[now][i].to;
			if(d[nex]>d[now]+road[now][i].len)
			{
				d[nex]=d[now]+road[now][i].len;
				if(!in[nex])
				{
					in[nex]=1;
					q.push(nex);
				}
			}
		}
	}
}
int main()
{
	scanf("%d%d",&n,&m);
	cnt=n;
	for(int i=1;i<=m;i++)
	{
		scanf("%d%d%d",&a,&b,&camp);
		if(!ma[a][camp]) 
		{
			ma[a][camp]=++cnt;
			road[cnt].push_back(node(a,1));
			road[a].push_back(node(cnt,1));
		}
		if(!ma[b][camp]) 
		{
			ma[b][camp]=++cnt;
			road[cnt].push_back(node(b,1));
			road[b].push_back(node(cnt,1));
		}
		road[ma[b][camp]].push_back(node(ma[a][camp],0));
		road[ma[a][camp]].push_back(node(ma[b][camp],0));
	}
	SPFA();
	if(d[n]==INF) printf("-1");
	else printf("%d",d[n]/2);
}

Measured memory_bytes: 84352