akhauriyash/Code-Regression huggingface dataset:
main :: IO ()                                                                                                              
main = do                                                                                                                  
  x <- getLine                                                                                                             
  case x of                                                                                                                
    "1" -> putStrLn "Hello World"                                                                                          
    "2" -> do                                                                                                              
      a <- (read <$> getLine) :: IO Int                                                                                    
      b <- (read <$> getLine) :: IO Int                                                                                    
      putStrLn $ show (a + b)

Measured memory_bytes: 508
import math
import numpy as np
def get_prime(n):
    if n<= 1:
        return[]
    prime = [2]
    limit = int(math.sqrt(n))
    
    data = [i + 1 for i in range(2,n,2)]
    while limit > data[0]:
        prime.append(data[0])
        data = [j for j in data if j % data[0] != 0]
    return prime + data
def is_prime(n):
    if n == 1: return False

    for k in range(2, int(math.sqrt(n)) + 1):
        if n % k == 0:
            return False

    return True
n = int(input())
l = []
r = []
for i in range(n):
    l_, r_ =map(int,input().split())
    l.append(l_)
    r.append(r_)
a = get_prime(10**5+1)
b = np.array([0]*(10**5+2))
c =0
d = 0
add = 0
for i in range(1,len(a)):
    if is_prime((a[i]+1)/2):
        d = a[i] 
        b[c:d] = add 
        c = d
        add +=1
b[c:] = add 
b[0::2] = 0
for i in range(n):
    e = b[max(0, l[i] - 2)]
    f = b[r[i]]
    print(f - e)

Measured memory_bytes: 38264
#include <bits/stdc++.h>
using namespace std;
 
int sinsuu(char s){
  int t;
  if(s=='A')t=10;
  else if(s=='B')t=11;
  else if(s=='C')t=12;
  else if(s=='D')t=13;
  else if(s=='E')t=14;
  else if(s=='F')t=15;
  return t;
}
int main() {
  char X,Y;
  cin >>X>>Y;
  
  int x,y;
  x=sinsuu(X);
  y=sinsuu(Y);
  
  if(x<y)cout<<"<"<<endl;
  else if(x>y) cout<<">"<<endl;
  else cout<<"="<<endl;
}

Measured memory_bytes: 256
#include <iostream>

using namespace std;

int main()
{
	int n, x = 0;
	char str[100];
	int max = 0;
	
	cin >> n >> str;
	
	for (int i = 0; i < n; i++) {
		if (str[i] == 'I') {
			x++;
		}
		else {
			x--;
		}
		if (x > max) max = x;
	}
	
	cout << max << endl;
	
	return (0);
}

Measured memory_bytes: 256
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <climits>
#include <cfloat>
#include <map>
#include <utility>
#include <set>
#include <iostream>
#include <memory>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <sstream>
#include <complex>
#include <stack>
#include <queue>
#include <cstring>
#include <sstream>
#include <cassert>
#include <list>
#include <fstream>
using namespace std;
static const double EPS = 1e-5;
typedef long long ll;
typedef pair<int,int> PI;
typedef vector<int> vi;
#ifndef M_PI
#define M_PI 3.14159265358979323846
#endif
#define rep(i,n) for(int i=0;i<(int)n;++i)
#define FOR(i,c) for(__typeof((c).begin())i=(c).begin();i!=(c).end();++i)
#define ALL(c) (c).begin(), (c).end()
#define mp(a,b) make_pair(a,b)
#define pb(a) push_back(a)
#define F first
#define S second


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


main(){
  int h,w;
  while(cin>>h>>w,h|w){
    string in[h],pa;
    int sx,sy,bx,by;
    rep(i,h){
      cin>>in[i];
      rep(j,w){
	if(in[i][j]=='A'){
	  sx=i;
	  sy=j;
	  in[i][j]='.';
	}
	if(in[i][j]=='B'){
	  bx=i;
	  by=j;
	  in[i][j]='.';
	}
      }
    }
    cin>>pa;


    int cost[h][w];
    rep(i,h)rep(j,w)cost[i][j]=INT_MAX/2;

    queue<PI> Q;
    Q.push(mp(0,sx*1000+sy));

    while(!Q.empty()){
      int cc=Q.front().F,cx=Q.front().S/1000,cy=Q.front().S%1000;
      Q.pop();
      //cout<<cx<<" "<<cy<<endl;
      if(cost[cx][cy]<=cc)continue;
      cost[cx][cy]=cc;

      rep(i,4){
	int nx=cx+dx[i],ny=cy+dy[i];
	if(nx<0 || h<=nx || ny<0 || w<=ny || in[nx][ny]=='#'){
	  continue;
	}
	Q.push(mp(cc+1,1000*nx+ny));
      }
    }

    int ans=-1,ax,ay;
    set<int> app[h][w];
    int po=0;
    int time=0;
    int imp=0;

    while(true){
      if(cost[bx][by]<=time){
	ans=time;
	ax=bx;
	ay=by;
	break;
      }

      if(app[bx][by].count(po)){
	break;
      }

      if(cost[bx][by]==INT_MAX/2){
	imp++;
      }

      if(cost[bx][by]==INT_MAX/2 && imp>=pa.size()){
	app[bx][by].insert(po);
      }
      
      int px=bx,py=by;
      switch(pa[po]){
      case '8':
	bx--;
	break;
      case '6':
	++by;
	break;
      case '4':
	--by;
	break;
      case '2':
	++bx;
	break;
      }
      if(bx<0 || h<=bx || by<0 || w<=by){
	bx=px;
	by=py;
      }
      ++time;
      ++po;
      if(po>=pa.size()){
	po=0;
	if(imp<pa.size())imp=0;
      }
    }
    if(ans==-1)cout<<"impossible";
    else cout<<ans<<" "<<ax<<" "<<ay;
    cout<<endl;
  }
}

Measured memory_bytes: 0
#include <iostream>
#include <unordered_map>

using namespace std;

int main() {
    int A[3][3];

    for (int i = 0; i < 3; ++i) {
        for (int j = 0; j < 3; ++j) {
            int l;
            cin >> l;
            A[i][j] = l;
        }
    }
    int N;
    cin >> N;

    unordered_map<int, bool> b;
    for (int i = 0; i < N; ++i) {
        int t;
        cin >> t;
        b[t] = true;
    }


    if (b[A[1][1]]) {
        if (b[A[0][0]] && b[A[2][2]]) {
            printf("Yes");
            return 0;
        }
        if (b[A[2][0]] && b[A[0][2]]) {
            printf("Yes");
            return 0;
        }
    }

    for (int i = 0; i < 3; i++) {
        if (b[A[i][0]] && b[A[i][1]] && b[A[i][2]]) {
            printf("Yes");
            return 0;
        }

        if (b[A[0][i]] && b[A[1][i]] && b[A[2][i]]) {
            printf("Yes");
            return 0;
        }
    }
    printf("No");
}



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

int main()
{
	int n;
	double sum = 0;
	cin >> n;
	int a[n+1];
	for(int i=0; i<n; i++){
		cin >> a[i];
		sum += a[i];
	}

	sum = round(sum/n);
	int ans = 0;
	for(int i=0; i<n; i++){
		ans += (a[i]-sum)*(a[i]-sum);
	}

	cout << ans;

    return 0;
}


Measured memory_bytes: 256
#include <stdbool.h>
#include <stdint.h>
#include <stdlib.h>

#define GRAPH_MATRIX_SIZE 256

typedef enum {
  WHITE,
  GRAY,
} color_t;

typedef struct {
  uint32_t index;
  size_t len;
  uint32_t array[GRAPH_MATRIX_SIZE];
  color_t color;
} graph_vertex_t;

typedef void (*graph_depth_first_search_callback_t)(uint32_t);


void graph_depth_first_search(graph_vertex_t *vertexes, uint32_t index, graph_depth_first_search_callback_t callback_pre,
                              graph_depth_first_search_callback_t callback_post)
{
  if (vertexes == NULL) return;
  graph_vertex_t *vertex = &vertexes[index - 1];
  vertex->color = GRAY;
  if (callback_pre) callback_pre(vertex->index);

  if (vertex->len > 0) {
    uint32_t i;
    for (i = 0; i < vertex->len; i++) {
      uint32_t next_vertex_index = vertex->array[i];
      if (vertexes[next_vertex_index - 1].color == WHITE) {
        graph_depth_first_search(vertexes, next_vertex_index, callback_pre, callback_post);
      }
    }
  }
  if (callback_post) callback_post(vertex->index);

  return;
}

#if !defined(TEST)
#include <stdio.h>
#define VERTEXES 256
static graph_vertex_t vertexes[VERTEXES];
static uint32_t cnt = 0;
static uint32_t timestamp[VERTEXES][2];

static void callback_pre(uint32_t index)
{
  cnt++;
  timestamp[index - 1][0] = cnt;
}

static void callback_post(uint32_t index)
{
  cnt++;
  timestamp[index - 1][1] = cnt;
}

int32_t main(void)
{
  uint32_t num;
  scanf("%u", &num);

  uint32_t i, j;
  for (i = 0; i < num; i++) {
    scanf("%u", &vertexes[i].index);
    scanf("%lu", &vertexes[i].len);
    for (j = 0; j < vertexes[i].len; j++) {
      scanf("%u", &vertexes[i].array[j]);
    }
    vertexes[i].color = WHITE;
  }

  for (i = 0; i < num; i++) {
    if (vertexes[i].color == WHITE) {
      graph_depth_first_search(vertexes, i + 1, callback_pre, callback_post);
    }
  }

  for (i = 0; i < num; i++) {
    printf("%d %d %d\n", i + 1, timestamp[i][0], timestamp[i][1]);
  }
  return 0;
}
#endif

Measured memory_bytes: 708
#include <string>
#include <vector>
#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<stack>
#include<queue>
#include<cmath>
#include<algorithm>
#include<functional>
#include<list>
#include<deque>
#include<bitset>
#include<set>
#include<map>
#include<unordered_map>
#include<unordered_set>
#include<cstring>
#include<sstream>
#include<complex>
#include<iomanip>
#include<numeric>
#include<cassert>
#define X first
#define Y second
#define pb push_back
#define rep(X,Y) for (int (X) = 0;(X) < (Y);++(X))
#define reps(X,S,Y) for (int (X) = S;(X) < (Y);++(X))
#define rrep(X,Y) for (int (X) = (Y)-1;(X) >=0;--(X))
#define rreps(X,S,Y) for (int (X) = (Y)-1;(X) >= (S);--(X))
#define repe(X,Y) for ((X) = 0;(X) < (Y);++(X))
#define peat(X,Y) for (;(X) < (Y);++(X))
#define all(X) (X).begin(),(X).end()
#define rall(X) (X).rbegin(),(X).rend()
#define eb emplace_back
#define UNIQUE(X) (X).erase(unique(all(X)),(X).end())
#define Endl endl
#define NL <<"\n"

using namespace std;
using ll=long long;
using pii=pair<int,int>;
using pll=pair<ll,ll>;
template<class T> using vv=vector<vector<T>>;
template<class T> inline bool MX(T &l,const T &r){return l<r?l=r,1:0;}
template<class T> inline bool MN(T &l,const T &r){return l>r?l=r,1:0;}
//#undef NUIP
#ifdef NUIP
#include "benri.h"
#else
#define out(args...)
#endif
#ifdef __cpp_init_captures
template<typename T>vector<T> table(int n, T v){ return vector<T>(n, v);}
template <class... Args> auto table(int n, Args... args){auto val = table(args...); return vector<decltype(val)>(n, move(val));}
#endif
const ll MOD=1e9+7; //998244353

vector<string> ok
	{"6314",
	 "2!2!",
	 "1364",
	 "5!5!"};

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

int main(){
  ios_base::sync_with_stdio(false); cin.tie(0);
  cout<<fixed<<setprecision(0);
	int h,w;
	cin>>h>>w;
	vector<string> mp(h);
	rep(i,h) cin>>mp[i];
	fill(dst[0],dst[112],MOD);
	dst[0][0]=0;
	queue<pii> que; que.emplace(0,0);
	while(que.size()){
		int x,y;
		tie(x,y)=que.front(); que.pop();
		rep(d,4){
			int nx=x+dx[d];
			int ny=y+dy[d];
			if(nx<0||ny<0||nx>=w||ny>=h||mp[ny][nx]!=ok[ny%4][nx%4]) continue;
			if(MN(dst[ny][nx],0)) que.emplace(nx,ny);
		}
	}
	// rep(i,h){rep(j,w) cout<<!!dst[i][j];cout NL;}
	cout<<(dst[h-1][w-1]?"NO":"YES") NL;
  return 0;
}



Measured memory_bytes: 3300
#include<iostream>
#include<algorithm>
#include<vector>
#include<string>
#include<set>
#include<queue>
#include<stack>
#include<functional>
using namespace std;
int p = 998244353;
#define int long long
#define vel vector<long long>
#define vvel vector<vel>
#define rep(i,n) for(long long i=0;i<n;i++)
#define sor(v) sort(v.begin(),v.end())
#define mmax(a,b) a=max(a,b)
#define mmin(a,b) a=min(a,b)
#define mkp make_pair
#define pin pair<int,int>
#define V vector
#define Endl endl
#define veb vector<bool>
#define sq(a) (a)*(a)
int kai_size = 400001;
vel kai(kai_size, 1);
vel ink(kai_size, 1);
vel dist;
int RE() {
	vel v(3, 2);
	return v.at(4); 
}
int ru(int a, int r) {
	if (r == 0) { return 1; }
	int ans = ru(a, r / 2);
	ans *= ans; ans %= p;
	if (r % 2 == 1) { ans *= a; }
	return ans % p;
}
int inv(int a) {
	return ru(a, p - 2);
}
void make_kai() {
	rep(i, kai_size) { kai[i + 1] = (kai[i] * (i + 1)) % p; }
	rep(i, kai_size) { ink[i] = inv(kai[i]); }
}
int com(int n, int r) {
	int ans = kai[n] * ink[r];
	ans %= p; ans *= ink[n - r]; ans %= p;
	return ans;
}
int per(int n, int r) {
	int ans = kai[n] * ink[n - r];
	ans %= p;
	return ans;
}
vel dis(int mid1, vvel &way,vel &con) {
	int n = way.size();
	vel dist(n,-1);
	dist[mid1] = 0;
	queue<int> q;
	q.push(mid1);
	while (!q.empty()) {
		int st = q.front();
		q.pop();
		con.push_back(st);
		rep(i, way[st].size()) {
			int to = way[st][i];
			if (dist[to] == -1) {
				dist[to] = dist[st] + 1;
				q.push(to);
			}
		}
	}
	return dist;
}
int gr(int now, vvel &chi) {
	int ret = 0;
	for(auto to:chi[now]) {
		ret = ret xor (gr(to, chi) + 1);
	}
	return ret;
}
signed main() {
	int n, h; cin >> n >> h;
	h+=3;
	vvel way(2 * h);
	vvel inv_way(2 * h);
	vvel all_way(2 * h);
	rep(i, n) {
		int a, b, c, d;
		cin >> a >> b >> c >> d;
		int st, to;
		if (c == 0) { st = a; }
		else { st = c + h; }
		if (d == 0) { to = b + h; }
		else { to = d; }
		way[st].push_back(to);
		inv_way[to].push_back(st);
		all_way[st].push_back(to);
		all_way[to].push_back(st);
	}
	rep(i, h) {
		if (way[i].size() < inv_way[i].size()) { cout << "NO" << endl; return 0; }
		if (way[i + h].size() > inv_way[i + h].size()) { cout << "NO" << endl; return 0; }
	}
	rep(i, 2 * h) {
		vel con = {};
		dis(i, all_way, con);
		if (con.size() == 1) {
			if (all_way[i].size() > 0) { cout << "NO" << endl; return 0; }
		}
		else {
			bool fl = false;
			for (auto pl : con) {
				if ((pl<h) and (way[pl].size() > inv_way[pl].size())) { fl = true; }
			}
			if (!fl) { cout << "NO" << endl; return 0; }
		}
	}
	cout << "YES" << endl;
	return 0;
}

Measured memory_bytes: 12160
import sys

#fin = open("test.txt", "r")
fin = sys.stdin

[r, c] = list(map(int, fin.readline().split()))

sum_col = [0 for i in range(c + 1)]

for i in range(r):
	input_list = list(map(int, fin.readline().split()))
	for j in range(c):
		sum_col[j] += input_list[j]
		print(input_list[j], end = " ")


	s = sum(input_list)

	sum_col[c] += s
	print(s)

for i in range(c):
	print(sum_col[i], end = " ")

print(sum_col[c])

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

int main(){
	
	string s;
	long long a,b;
	cin >>a>>b;
	cin >> s;
	s[b-1]=s[b-1]-65+97;
	
	cout <<s <<endl; 
	
	 
	
	return 0;
} 

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

using namespace std;

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

const int N = (int)1e5+5;
int n, a[2*N], b[2*N];

bool check(int mid) {
	for (int i = 1; i < 2*n; ++i) b[i] = a[i] >= mid;
	for (int i = 1; i < n; ++i) {
		if (b[n + i] == b[n + i - 1]) return b[n + i];
		if (b[n - i] == b[n - i + 1]) return b[n - i];
	}
	return b[1];
}

int main() {
	scanf("%d", &n);
	for (int i = 1; i < 2*n; ++i) scanf("%d", &a[i]);
	int lo = 1, hi = 2*n-1, ans = -1, mid;
	while (lo <= hi) {
		mid = (lo + hi) >> 1;
		if (check(mid)) ans = mid, lo = mid + 1;
		else hi = mid - 1;
	}
	printf("%d", ans);
	return 0;
}

Measured memory_bytes: 1792
#include <bits/stdc++.h>
#define ll long long
#define ld long double
#define ft first
#define sd second
#define pb push_back
using namespace std;
const ll mod = 1e9+7;
const ll inf = 1e9+9;
 
ll power(ll a, ll b, ll m = mod) {
    ll x = 1;
    while(b) {
        if(b & 1) {
            x = 1ll * x * a % m;
        }
        a = 1ll * a * a % m;
        b /= 2;
    }
    return x;
}
 
mt19937_64 gen (random_device{}());
ll rint(ll a, ll b) { // generate rand int in [a, b]
    return a + gen() % (b - a + 1);
}
const int N = 2e5+9;
long long f[N], a[N], sum[N];
signed main() {  
    ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
    int n; 
    cin >> n;
    // n = 2e5;
    n++;
    a[1] = 2e5+1;
    for(int i = 2; i <= n; i++) {
        cin >> a[i];
        // a[i] = rint(1, (int)2e5);
    }
    f[1] = 1;
    for(int i = 2; i <= n; i++) {
        f[i] = f[i-1];
        if(a[i] == a[i-1]) {
            continue;
        }
        f[i] += sum[a[i]];
        if(f[i] >= mod) f[i] -= mod;
        sum[a[i]] += f[i-1];
        if(sum[a[i]] >= mod) sum[a[i]] -= mod;
    }
    cout << f[n] << "\n";







    return 0;
    
}

Measured memory_bytes: 4992
#include <bits/stdc++.h>
#pragma gcc optimize("ofast")
using namespace std;

#define ll long long //data types used often, but you don't want to type them time by time
#define ull unsigned long long
#define ui unsigned int
#define mod 1000000007
#define us unsigned short
#define IOS ios_base::sync_with_stdio(0); //to synchronize the input of cin and scanf
#define INF LONG_MAX
#define PI 3.1415926535897932384626
#define mp make_pair
#define fi first
#define se second
#define pb push_back
#define rep(x,j,n)for(int x=j;x<n;x++)
typedef vector<pair<ll,ll>> vpi;
typedef vector<ll> vi;
typedef vector<vi> vvi;

ll modexp(ll a,ll b,ll m)
{
    ll r=1;
    a=a%m;
    while(b>0)
    {
        if(b&1){r=(r*a)%m;}
        b=b>>1;
        a=(a*a)%m;
    }
    return r%m;
}
int main(){
    ll n; cin>>n;
    vi arr(n);
    rep(i,0,n)cin>>arr[i];
    vi dp(n,0);
    dp[1] = fabs(arr[1]-arr[0]);
    for(ll i=2;i<n;i++)
    {
        dp[i] = min(dp[i-1]+fabs(arr[i]-arr[i-1]),dp[i-2]+fabs(arr[i]-arr[i-2]));
    }
    cout<<dp[n-1]<<endl;
    return 0;
}


Measured memory_bytes: 1792
#include<bits/stdc++.h>
#define fi first
#define se second
#define rep(i, n) for(int (i) = 0; (i) < (n); (i)++)
#define rrep(i, n) for (int (i) = 1; (i) <= (n); (i++))
#define rng(a) a.begin(),a.end()
#define rrng(a) a.rbegin(),a.rend()
#define pb push_back
#define eb emplace_back
#define yn {puts("Yes");}else {puts("No");}
#define printd(x) printf("%.12f\n", x);
template<class T> bool chmin(T& a, const T& b) {if (a > b) {a = b; return 1;} return 0;}
template<class T> bool chmax(T& a, const T& b) {if (a < b) {a = b; return 1;} return 0;}
using namespace std;
using ll = long long;

int main() {
	int n, m;
	cin >> n >> m;

	vector<pair<int, int>> ans;
	if (n % 2 == 1) {
		for (int l = 1; l <= m; l++) {
			ans.emplace_back(l, n-l);
		}
	}
	else {
		for (int l = 1, r = n / 4 * 2; l <= r; l++, r--) {
			ans.emplace_back(l, r);
		}
		for (int l = n / 4 * 2 + 2, r = n; l != r; l++, r--) {
			ans.emplace_back(l, r);
		}
	}

	rep (i, m) cout << ans[i].first << " " << ans[i].second << endl;
	return 0;
}

Measured memory_bytes: 4292
N, K = map(int, input().split())
S = input()
array = []
count = 1
if S[0] == "0":
  array.append(0)
for i in range(N):
  if i+1 == N or S[i] != S[i+1]: 
    array.append(count)
    count = 1
  elif S[i] == S[i+1]:
    count += 1
if S[-1] == "0":
  array.append(0)
M = len(array)
ans = sum(array[0:2*K+1])
tmp = ans
for l in range(2,M-2*K,2):
  tmp -= array[l-2] + array[l-1]
  tmp += array[l+2*K-1] + array[l+2*K]
  ans = max(ans,tmp)
print(ans)

Measured memory_bytes: 4596
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> pii;
#define X first
#define Y second
#define mod 1e9+7
#define pb push_back
#define mp make_pair
#define abs(x) ((x)>0?(x):(-(x)))
#define F(n) Fi(i,n)
#define Fi(i,n) Fl(i,0,n)
#define Fl(i,l,n) for(int i=l;i<n;i++)
#define memres(a) memset(a,0,sizeof(a))
int gcd(int a,int b){if(b==0)return a;return gcd(b,a%b);}
int dp[200000][3];
char a[200000];
int main(){
	ios_base::sync_with_stdio(0);cin.tie(0);
	int n,k,r,s,p;
	ll out=0;
	cin>>n>>k>>r>>s>>p;
	cin>>a;
	F(n){
		if(i<k||a[i]!=a[i-k]){
			if(a[i]=='r')out+=p;
			if(a[i]=='s')out+=r;
			if(a[i]=='p')out+=s;
		}
		else{
			a[i]='-';
		}
	}
	cout<<out<<endl;
return 0;
}


Measured memory_bytes: 384
#include<bits/stdc++.h>
using namespace std;
#define ll long long int
#define mod 1000000007
	
int main(){
	ll n;
	cin>>n;
	ll ar[3*n];
	for(int i=0;i<3*n;i++){
	 	cin>>ar[i];
	}
	
	sort(ar,ar+3*n,greater<ll>());
	
	ll ans = 0;	 
	int ind = 1;
	for(int i=0;i<n;i++){
		ans+=(ar[ind]);
		ind+=2;
	}
	 	 
	cout<<ans;
	return 0;
}


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

ll gcd(ll x, ll y);
int fac(ll n, vector<int> num);

const int INF = 1001001001;

//mint�p�̒萔 (10��9��)
const int mod = 1000000007;

struct mint {
    ll x; // typedef long long ll;
    mint(ll x = 0) :x((x% mod + mod) % mod) {}
    mint operator-() const { return mint(-x); }
    mint& operator+=(const mint a) {
        if ((x += a.x) >= mod) x -= mod;
        return *this;
    }
    mint& operator-=(const mint a) {
        if ((x += mod - a.x) >= mod) x -= mod;
        return *this;
    }
    mint& operator*=(const mint a) { (x *= a.x) %= mod; return *this; }
    mint operator+(const mint a) const { return mint(*this) += a; }
    mint operator-(const mint a) const { return mint(*this) -= a; }
    mint operator*(const mint a) const { return mint(*this) *= a; }
    mint pow(ll t) const {
        if (!t) return 1;
        mint a = pow(t >> 1);
        a *= a;
        if (t & 1) a *= *this;
        return a;
    }

    // for prime mod
    mint inv() const { return pow(mod - 2); }
    mint& operator/=(const mint a) { return *this *= a.inv(); }
    mint operator/(const mint a) const { return mint(*this) /= a; }
};
istream& operator>>(istream & is, const mint & a) { return is >> a.x; }
ostream& operator<<(ostream & os, const mint & a) { return os << a.x; }

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

    int ans = 0;
    int time = 0;
    rep(i, n) {
        if (i == 0) {
            ans += t;
            time = a[i];
        }
        else {
            if (a[i] <= time + t) {
                ans += t - (time + t - a[i]);
                time = a[i];
            }
            else {
                ans += t;
                time = a[i];
            }
        }
    }

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

/*���C�u�����ő����*/
//���[�O���b�h�̌ݏ��@
ll gcd(ll x, ll y) {
    ll num[3];
    num[0] = (x > y) ? x : y;
    num[1] = (x <= y) ? x : y;
    num[2] = num[0] % num[1];

    while (num[2]) {
        num[0] = num[1];
        num[1] = num[2];
        num[2] = num[0] % num[1];
    }

    return num[1];
}

/*�f��������*/
//���색�C�u����
int fac(ll n, vector<int> num) {
    ll kazu = n;
    for (int i = 2; i <= sqrt(n); i++) {
        while (1) {
            if (kazu % i != 0) break;

            kazu /= i;
            num[i]++;
        }
    }
    if (kazu == n && n != 1) return 1;
    int ans = 0;
    if (kazu != 1) ans++;
    for (int i = 2; i <= sqrt(n); i++) {
        for (int j = 1; j <= num[i]; j++) {
            num[i] -= j;
            ans++;
        }
    }
    return ans;
}

Measured memory_bytes: 3936
#include <stdio.h>
#include <stdlib.h>
#include <vector>

using namespace std;

void dfs1(const vector<vector<long>> &adj_lists, long M, vector<long> &dp1s,
          long i, vector<long> &us) {
  const long N = adj_lists.size();
  long dp = 1;
  us[i] = 1;
  for (long j : adj_lists[i]) {
    if (!us[j]) {
      dfs1(adj_lists, M, dp1s, j, us);
      dp = dp * (dp1s[j] + 1) % M;
    }
  }
  dp1s[i] = dp;
}

void dfs2(const vector<vector<long>> &adj_lists, long M, vector<long> &dp1s,
          vector<long> &dp2s, long i, vector<long> &us) {
  const long N = adj_lists.size();
  // calculate dp1s[i] and dps2[i]
  long dp = 1;
  us[i] = 1;
  for (long j : adj_lists[i]) {
    dp = dp * (dp1s[j] + 1) % M;
    // dp = dp * (dp1s[j] + 1);
  }
  dp1s[i] = dp;
  dp2s[i] = dp;

//   printf("i = %ld\n", i);
//   for (long j = 0; j < N; j++) {
//     printf("j = %ld, dp1s[j] = %ld\n", j, dp1s[j]);
//   }

  // calculate accls, accrs to facilitate calculation of
  // dp1s[i] when calling dfs2 on i's neighbours
  const long K = adj_lists[i].size();
  vector<long> accls(K, 0), accrs(K, 0);
  for (long k = 0; k < K; k++) {
    const long j = adj_lists[i][k];
    accls[k] = dp1s[j] + 1;
    accrs[k] = dp1s[j] + 1;
  }
  for (long k = 1; k < K; k++) {
    accls[k] = accls[k] * accls[k - 1] % M;
  }
  for (long k = K - 2; k >= 0; k--) {
    accrs[k] = accrs[k] * accrs[k + 1] % M;
  }
  for (long k = 0; k < K; k++) {
    const long j = adj_lists[i][k];
    if (!us[j]) {
      dp1s[i] = (k > 0 ? accls[k - 1] : 1) * (k + 1 < K ? accrs[k + 1] : 1) % M;
      dfs2(adj_lists, M, dp1s, dp2s, j, us);
    }
  }
}

int main() {
  // read inputs
  long N, M;
  vector<long> xs, ys;
  scanf("%ld %ld", &N, &M);
  for (long i = 0; i < N - 1; i++) {
    long x, y;
    scanf("%ld %ld", &x, &y);
    x--;  // NOTE : modified input
    y--;  // NOTE : modified input
    xs.push_back(x);
    ys.push_back(y);
  }

  // create tree
  vector<vector<long>> adj_lists(N, vector<long>());
  for (long i = 0; i < N - 1; i++) {
    const long x = xs[i], y = ys[i];
    adj_lists[x].push_back(y);
    adj_lists[y].push_back(x);
  }

  // solve dp
  vector<long> dp1s(N, -1), dp2s(N, -1);
  // calculate dp1s
  vector<long> us(N, 0);
  dfs1(adj_lists, M, dp1s, 0, us);
  //   for (long i = 0; i < N; i++) {
  //     printf("i = %ld, dp1s[i] = %ld\n", i, dp1s[i]);
  //   }

  // calculate dp2s
  for (long i = 0; i < N; i++) {
    us[i] = 0;
  }
  dfs2(adj_lists, M, dp1s, dp2s, 0, us);
  //   for (long i = 0; i < N; i++) {
  //     printf("i = %ld, dp2s[i] = %ld\n", i, dp2s[i]);
  //   }

  // print answer
  for (long i = 0; i < N; i++) {
    printf("%ld\n", dp2s[i]);
  }
}

Measured memory_bytes: 23148
import java.util.*;

public class Main {
    public static void main(String[] args) throws Exception {
        // Your code here!
        Scanner sc = new Scanner(System.in);
        int n = Integer.parseInt(sc.next());
        HashMap<Integer, Integer> map = new HashMap<Integer, Integer>();
        int ans = 0;
        for(int i=0;i<n;i++){
            int num = Integer.parseInt(sc.next());
            map.put(num, map.containsKey(num)?map.get(num)+1: 1);
        }
        long a=0l,b=0l;
        for(int i: map.keySet()){
            if(map.get(i)>1){
                if(map.get(i)<4){
                    if(a<=i){
                        b=a;
                        a=i;
                    }else if(b<i){
                        b = i;
                    }
                }else{
                    if(a<=i){
                        b=i;
                        a=i;
                    }else if(b<i){
                        b = i;
                    }
                }
            }
        }
        System.out.println(a*b);
    }
}


Measured memory_bytes: 48040
#include <bits/stdc++.h>
#define fto(i,a,b) for(int i=a; i<=b; i++)
#define fdto(i,a,b) for(int i=a; i>=b; i--)
#define maxn 1000006
using namespace std;
int n, a[maxn], ans[maxn];

int main()
{
    //freopen("a.inp", "r", stdin);
    //freopen("a.out", "w", stdout);
    cin >> n;
    for (int i=1; i<=n; i++) cin >> a[i];
    int sl=n, m=n;
    while (sl) {
        fdto (i, sl, 1) if (a[i]>i) {cout << -1; return 0;}
        fdto (i, sl, 1) if (a[i]==i) {
            ans[sl]=a[i];
            fto (j, i, sl-1) a[j]=a[j+1];
            --sl;
            break;
        }
    }
    fto (i, 1, m) cout << ans[i] << ' ';
    return 0;
}


Measured memory_bytes: 2304
def count(a)
  numEven = 0
  numOdd  = 0
  
  a.each do |v|
    if v % 2 == 0 then
      numEven += 1
    else
      numOdd  += 1
    end
  end
  
  return [numEven, numOdd]
end

def comb(n, k)
  c = 1
  
  ((n - k + 1) .. n).each do |v|
    c *= v
  end
  
  (2 .. k).each do |v|
    c /= v
  end
  
  return c
end

def main(argv)
  (n, p) = STDIN.gets.chomp.split(' ').map(&:to_i)
  a = STDIN.gets.chomp.split(' ').map(&:to_i)
  
  (numEven, numOdd) = count(a)
  
  x = 2 ** numEven
  
  y = 0
  i = p
  while i <= numOdd do
    y += comb(numOdd, i)
    i += 2
  end
  
  STDOUT.puts (x * y).to_s
end

if self.to_s == 'main' then
  main(ARGV)
end

Measured memory_bytes: 1788
n = int(input())
h = [None] + list(map(int, input().split()))

dp = [None for _ in range(n+1)]
for k in range(1,n+1):
  if k == 1:
    dp[k] = 0
  elif k == 2:
    dp[k] = abs(h[2] - h[1])
  else:
    dp[k] = min(
      dp[k-1] + abs(h[k] - h[k-1]),
      dp[k-2] + abs(h[k] - h[k-2])
    )
print(dp[k])

Measured memory_bytes: 20444
INT = lambda: int(input())
INTM = lambda: map(int,input().split())
STRM = lambda: map(str,input().split())
STR = lambda: str(input())
LIST = lambda: list(map(int,input().split()))
LISTS = lambda: list(map(str,input().split()))
def do():
    w,h,n=INTM()
    X,Y,A=[],[],[]
    for i in range(n):
        x,y,a=INTM()
        X.append(x)
        Y.append(y)
        A.append(a)
    wh=[[0]*w]*h
    for i in range(n):
        if A[i]==1:
            for j in range(h):
                wh[j][0:X[i]]=[1]*X[i]
        elif A[i]==2:
            for j in range(h):
                wh[j][X[i]:w]=[1]*(w-X[i])
        elif A[i]==3:
            wh[0:Y[i]]=[[1]*w]*Y[i]
        else:
            wh[Y[i]:h]=[[1]*w]*(h-Y[i])
        #print(wh)
    ct=0
    
    for i in range(h):
        ct+=sum(wh[i])
    print(h*w-ct)
if __name__ == '__main__':
    do()

Measured memory_bytes: 3192
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
/*締め切りの早いものから順にこなし、時刻tを更新していく
時刻tに次の仕事の処理時間を加えたものが、次の仕事の締め切り
を超えたらアウト
*/
int main() {
  int N;
  cin >> N;
  vector<pair<ll,ll>> p(N);
  rep(i,N){
      cin >> p[i].second;
      cin >> p[i].first;
  }
  sort(p.begin(),p.end());
  bool flag = true;

  ll t = 0;//現在の時刻
  for(int i = 0;i<N;i++){
      t += p[i].second;
    if(t > p[i].first){
      flag = false;
      break;
    }
  }
  if(flag) cout << "Yes" <<endl;
  else cout << "No" <<endl;
}

Measured memory_bytes: 3328
#include <bits/stdc++.h>
#define rep(i,a,b) for(int i=a;i<(b);++i)
#define erep(i,a,b) for(int i=a;i<=(int)(b);++i)
#define per(i,a,b) for(int i=(a);i>(b);--i)
#define eper(i,a,b) for(int i=(a);i>=b;--i)
#define pb push_back
#define mp make_pair
#define INF 100100100100
#define inf 2001001001
#define MOD 1000000007
#define ALL(x) begin(x),end(x)
#define F first
#define S second
using namespace std;
using ll = long long;
using pii = pair<int,int>;
using vii = vector<int>;
using vll = vector<ll>;
using priority_queue_small = priority_queue<int, vector<int>, greater<int> >;
template<class T>using vv = vector<T>;
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a = b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a = b; return 1; } return 0; }
template<class T>void show(const vector<T> &a) { for (int i = 0; i < (int)a.size(); ++i) cout << a[i] << (i != (int)a.size()-1 ? " " : "\n"); }
template<class T>T gcd(T a, T b){ return b ? gcd(b, a % b) : a; }
template<class T>T lcm(T a, T b){ return a / gcd(a, b) * b; }
int dy[]={0, 1, -1, 0};
int dx[]={1, 0, 0, -1};
vector<int> makePrimes(int n) {
  vector<int> res, pr(n + 1, 1);
  pr[0] = pr[1] = 0;
  rep(p, 2, sqrt(n) + 2) 
    if (pr[p]) 
    for (int x = p * 2; x <= n; x += p) pr[x] = 0;
  rep(p, 2, n + 1) 
    if (pr[p]) 
      res.push_back(p);
  return res;
}
int N;
int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
    cin >> N;
    vii primes = makePrimes(N);
    vii cnt(primes.size());
    erep(i, 2, N) {
      rep(j, 0, primes.size()) {
        int t = i;
        while (t % primes[j] == 0) cnt[j]++, t /= primes[j];
      }
    }
    ll ans = 1;
    rep(i, 0, cnt.size()) {
      ans *= (cnt[i] + 1);
      ans %= MOD;
    }
    cout << ans << endl;
    return 0;
}



Measured memory_bytes: 256
//A - Iroha and Haiku (ABC Edition)


#include<bits/stdc++.h>
using namespace std;

int main()
{
    multiset<int> s;
    int a,b,c;
    cin>>a>>b>>c;
    s.insert(a);
    s.insert(b);
    s.insert(c);
    if(s.count(5)==2 && s.count(7)==1)
	cout<<"YES";
    else
	cout<<"NO";
    return 0;
}


Measured memory_bytes: 256
class Tree
    attr_accessor :key, :left, :right
    def initialize(k, l, r)
        @key   = k
        @left  = l
        @right = r
    end
end

def insert(x, tree)
    if tree == nil
        Tree.new(x, nil, nil)
    elsif x < tree.key
        Tree.new(tree.key, insert(x, tree.left), tree.right)
    elsif x > tree.key
        Tree.new(tree.key, tree.left, insert(x, tree.right))
    else
        tree
    end
end

def find(x, tree)
    if tree == nil then
        false
    elsif x < tree.key
        find(x, tree.left)
    elsif x > tree.key
        find(x, tree.right)
    else
        true
    end
end

def goleft(tree, directions, breadcrambs)
    rt = tree.left
    tree.left = nil
    directions << 'L'
    breadcrambs << tree
    [rt, directions, breadcrambs]
end

def goright(tree, directions, breadcrambs)
    rt = tree.right
    tree.right = nil
    directions << 'R'
    breadcrambs << tree
    [rt, directions, breadcrambs]
end

def goup(tree, directions, breadcrambs)
    d = directions[-1]
    xtree = breadcrambs[-1]
    if d == 'L' then xtree.left = tree
    else xtree.right = tree end
    [xtree, directions[0..-2], breadcrambs[0..-2]]
end

def preorder(tree)
    if tree != nil
        print " #{tree.key}"
        preorder(tree.left)
        preorder(tree.right)
    end
end

def inorder(tree)
    if tree != nil
        inorder(tree.left)
        print " #{tree.key}"
        inorder(tree.right)
    end
end

def postorder(tree)
    if tree != nil
        postorder(tree.left)
        postorder(tree.right)
        print " #{tree.key}"
    end
end

#-- main
#------------------------------------------
tree = nil
paths = []
breads = []

x = gets.chomp.to_i
x.times {
    cmd, n = gets.chomp.split
    case cmd
    when "insert"
        tree = insert(n.to_i, tree)
    when "find"
        if find(n.to_i, tree)
            puts "yes"
        else
            puts "no"
        end
    when "delete"
        tree = delete(n.to_i, tree)
    when "print"
        inorder(tree); puts
        preorder(tree); puts
    end
}


Measured memory_bytes: 39840
#include <stdio.h>
#include <stdlib.h>

typedef struct{
  int x;
  int y;
}point;

void shift(point * p , point * q, int dx, int dy){
  (p->x) = (q->x) + dx;
  (p->y) = (q->y) + dy;
}

int main(void){
  point p1, p2;
  scanf("%d %d %d %d", &p1.x, &p1.y, &p2.x, &p2.y);
  point p3, p4;
  shift(&p3, &p2, -(p2.y-p1.y), p2.x-p1.x);
  shift(&p4, &p3, -(p3.y-p2.y), p3.x-p2.x);
  printf("%d %d %d %d\n", p3.x, p3.y, p4.x, p4.y);
  return 0;
}


Measured memory_bytes: 1732
N,X,Y = gets.split.map &:to_i
cs = {}
(1...N).each{ |i|
  (i+1..N).each{ |j|
    a = (i - j).abs
    b = (i - X).abs + 1 + (j - Y).abs
    c = (i - Y).abs + 1 + (j - X).abs
    d = [a,b,c].min
    cs[d] = (cs[d] || 0) + 1
  }
}
(1...N).each{ |k| p cs[k] || 0 }

Measured memory_bytes: 2172
#include <bits/stdc++.h>
using namespace std;
int main(){
  int n;
  cin>>n;
  string s;
  cin>>s;
  int ans=0;
  for(int i=0;i<n;i++)
  {
    if(s[i]=='A' && s[i+1]=='B' && s[i+2]=='C')
    {  
      ans++; i+=2;
    }
      
  }cout<<ans<<endl;
}

Measured memory_bytes: 256
import math

while True:
	l1, l2, l3 = sorted(list(int(i) for i in input().split()))
	if l1 == l2 == l3 == 0:
		break
	n = int(input())
	R = math.sqrt(l1 ** 2 + l2 ** 2) / 2
	for i in range(n):
		r = int(input())
		if r > R:
			print('OK')
		else:
			print('NA')

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

int main(void){
    int N, result = 0;
    scanf("%d", &N);

    vector<int> L(N);

    for(int i = 0; i < N; i ++)
        scanf("%d", &L[i]);
    
    sort(L.begin(), L.end());

    auto comp = [](int a, int b, int c){
        if(a < b + c && b < a + c && c < a + b)
            return true;
        return false;
    };

    for(int i = 0; i < N; i++){
        for(int j = i + 1; j < N; j++){
            for(int k = j + 1; k < N; k++){
                if(comp(L[i], L[j], L[k]))
                    result++;
            }
        }
    }
    
    cout << result << endl;

    return 0;
}

Measured memory_bytes: 256
fun main(args: Array<String>) {
    var (n, k) = readIntList()

    var ans = 0
    while (n > 0) {
        n /= k
        ans++
    }
    println(ans)
}

// Tools
fun readString() = readLine()!!
fun readInt() = readLine()!!.toInt()
fun readLong() = readLine()!!.toLong()
fun readStringList() = readLine()!!.split(" ")
fun readIntList() = readLine()!!.split(" ").map(String::toInt)
fun readLongList() = readLine()!!.split(" ").map(String::toLong)

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

int main()
{
    ios_base::sync_with_stdio(0), cin.tie(0);
    string s;
    cin >> s;
    
    int ans = 0;
    for (int i = 0; i < s.size() / 2; i++)
        if (s[i] != s[s.size() - 1 - i])
            ans++;
            
    cout << ans << '\n';
    return 0;
}


Measured memory_bytes: 256
#include <cstdio>
#include <vector>
#include <algorithm>
char str[100200];

int main(void)
{
	scanf("%s", str);
	int len;
	int i;
	for (len = 0; str[len]; len++);
	if (len == 2 && str[0] == str[1]) 
	{
		printf("%d %d\n", 1, 2);
		return 0;
	} 

	for (i = 0; i < len - 2; i++)
	{
		if (str[i] == str[i+1] || str[i] == str[i + 2] || str[i+1] == str[i+2]) break;
	}

	if (i != len - 2) printf("%d %d\n", i+1, i+3);
	else printf("-1 -1\n");

	return 0;
}


Measured memory_bytes: 256
import math
a, b, x = map(int, input().split())

if x <= a * a * b / 2:
    ans = math.atan(2 * x / (a * b * b))
    print(90 - math.degrees(ans))
else:
    ans = math.atan((2 * b - (2 * x / (a * a))) / a)
    print(math.degrees(ans))

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

#define rep(i, n) REP(i, 0, n)
#define ALL(v) v.begin(), v.end()
#define MSG(a) cout << #a << " " << a << endl;
#define REP(i, x, n) for (int i = x; i < n; i++)
#define OP(m) cout << m << endl
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> pii;

int main()
{
    string s;
    cin >> s;
    int cnt = 0;
    rep(i, s.size() / 2)
    {
        if (s[i] != s[s.size() - 1 - i])
            cnt++;
    }
    OP(cnt);
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define UNIQUE(v) v.erase(unique(all(v)), v.end());
#define ZIP(v) sort(all(v)),UNIQUE(v)
#define ADD(a, b) a = (a + b) % mod
#define SUB(a, b) a = (a+mod-b)%mod
#define MUL(a, b) a = (a * b) % mod
#define repi(i,m,n) for(int i = m;i < n;i++)
#define drep(i,n,m) for(int i = n;i >= m;i--)
#define rep(i,n) repi(i,0,n)
#define rrep(i,n) repi(i,1,n+1)
#define chmin(x,y) x = min(x,y)
#define chmax(x,y) x = max(x,y)
#define all(v) v.begin(),v.end()
#define rall(v) v.rbegin(), v.rend()
#define dmp(x,y) make_pair(x,y)
#define pb(x) push_back(x)
#define fi first
#define se second
typedef pair<int,int> P;
typedef pair<int, P> PP;
typedef pair<P, int> Pi;
typedef vector<int> vi;
typedef deque<int> dq;
const int inf = 1e9+7;
const int INF = 1e18+7;

int dp[31][1<<16], a[30][16], b[30][16], d1[30], d2[30];
int po[16];

int bit_cnt(int bit){
	int ans = 0;
	while(bit > 0){
		ans += bit%2;
		bit /= 2;
	}
	return ans;
}

void init(){
	fill((int*)dp, (int*)(dp+31), -INF);
	dp[0][0] = 0;
	fill(d1, d1+30, 0);
	fill(d2, d2+30, 0);
	int tmp = 0;
	po[0] = 1;
	repi(i,1,16)po[i] = po[i-1]*2;
	sort(po, po+16, greater<int>());
}

signed main(){
	while(1){
		int n, c;
		scanf("%lld%lld", &n, &c);
		if(n == 0 and c == 0)break;
		init();
		rep(i,n)rep(j,16)scanf("%lld", &a[i][j]);
		rep(i,c)rep(j,16)scanf("%lld", &b[i][j]);
		rep(i,n)rep(j,16)d1[i] += a[i][j]*po[j];
		rep(i,c)rep(j,16)d2[i] += b[i][j]*po[j];
		
		rep(i,n){
			rep(j,1<<16){
				if(dp[i][j] == -INF)continue;
				rep(k,c){
					int bit = j | d1[i];
					int bit2 = bit & d2[k];
					int score = bit_cnt(bit2);
					bit -= bit2;
					chmax(dp[i+1][bit], dp[i][j]+score);
				}
			}
		}
		
		int ans = 0;
		rep(i,1<<16)chmax(ans, dp[n][i]);
		printf("%lld\n", ans);
	}
	return 0;
}





Measured memory_bytes: 19184
#include <iostream>
#include <cstdio>
#include <cmath>
#include <string>
#include <algorithm>
using namespace std;
#define mp  std::make_pair
#define ll long long int
#define abs(n) ((n>0)?(n):((n)*(-1)))
#define CEIL(a,b) (((a) + ((b)-1)) / (b))
#define FOR(i,a,b) for(int i=(a);i<=(b);++i)
#define REP(i,n) FOR(i,0,(n)-1)
#define VREP_ll(v) for(std::vector<ll>::iterator itr = (v).begin(); itr != (v).end();itr++)
#define VREP_int(v) for(std::vector<int>::iterator itr = (v).begin(); itr != (v).end();itr++)
#define VALL(v) ((v).begin(),(v).end())
#define errln(v) cerr << (v) << endl;
#define println(v) cout << (v) << endl;

int main(int argc, const char * argv[]) {
	int N;
	cin >> N;
	double sum=0;
	REP(i,N){
		double x;
		string u;
		cin >> x >> u;
		if(u == "BTC")
			x *= 380000;
		sum += x;
	}

	printf("%.5f\n",sum);
	return 0;
}


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

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

  vector<int> vec(N);

  for (int i = 0; i < N; i++) {
	cin >> vec.at(i);  
  }
  
  int num = 1;
  int sum = 0;
  
  for (int i = 0; i < N; i++) {
    
    if (num != 2) {
      num = vec.at(num - 1);
      sum++;
    }
	else {
      cout << sum << endl;
      break;
    }
  }

  if (num != 2) {
    cout << "-1" << endl;
  }
}

Measured memory_bytes: 640
#pragma GCC optimize("Ofast")
#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 (int i = (a); i < (b); ++i)
#define rep(...) _overload3(__VA_ARGS__, repi, _rep, )(__VA_ARGS__)
#define ALL(x) x.begin(), x.end()
#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)
using namespace std;
using ll = long long;
using lld = long double;
using VI = vector<int>;
using VVI = vector<VI>;
using VL = vector<ll>;
using VVL = vector<VL>;
using PII = pair<int, int>;

const ll INF = 1ll << 60;
ll n, k;

bool canbuild(vector<ll> &v, ll num)
{
    vector<int> m(n);
    ll tsum = 0;
    rep(i, n)
    {
        m[i] = v[i] % num;
        tsum += m[i];
    }
    sort(ALL(m), greater<ll>());
    int tail = n - 1;

    assert(tsum % num == 0);
    ll diff = 0;
    ll cost = 0;
    rep(i, n)
    {
        if (m[i] == 0)
            break;
        int diff = 0;
        diff = num - m[i];
        cost += diff;
        while (diff != 0)
        {
            if (diff <= m[tail])
            {
                m[tail] -= diff;
                diff = 0;
            }
            else
            {
                diff -= m[tail];
                m[tail] = 0;
                tail--;
            }
        }
    }

    /*
    rep(i, n)
    {
        //cerr << cost << endl;
        if (diff < 0)
        {
            if (m[i] + diff >= 0)
            {
                m[i] += diff;
                diff = 0;
            }
            else
            {
                diff += m[i];
                m[i] = 0;
            }
        }
        else
        {
            if (m[i] + diff <= num)
            {
                m[i] += diff;
                m[i] %= num;
                diff = 0;
            }
            else
            {
                diff -= num - m[i];
                m[i] = 0;
            }
        }
        if (num - m[i] < m[i]) //足したほうが少ない
        {
            cost += num - m[i];
            diff -= num - m[i];
        }
        else
        {
            cost += m[i];
            diff = m[i];
        }
    }*/
    //cerr << num << " " << cost << endl;
    return cost <= k;
}

int main()
{
    cin >> n >> k;
    vector<ll> v(n);
    ll sum = 0;
    rep(i, n)
    {
        cin >> v[i];
        sum += v[i];
    }
    sort(ALL(v));
    vector<ll> candid;
    ll cur = 1;
    while (cur * cur <= sum)
    {
        if (sum % cur == 0)
        {
            candid.push_back(cur);
            candid.push_back(sum / cur);
        }
        cur++;
    }
    sort(ALL(candid), greater<ll>());
    for (auto x : candid)
    {
        if (canbuild(v, x))
        {
            cout << x << endl;
            return 0;
        }
    }
    return 0;
}

Measured memory_bytes: 256
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
''' 
------------------------
author : iiou16
------------------------
'''
import copy

def make_divisors(n):
    divisors = []
    for i in range(1, int(n**0.5)+1):
        if n % i == 0:
            divisors.append(i)
            if i != n // i:
                divisors.append(n//i)

    divisors.sort()
    return divisors


def main():
    N = int(input())
    yakusu = make_divisors(N)
    max_times = len(yakusu) - 1
    min_times = 0
    result = []
    for i in reversed(yakusu[:-1]):
        if i in result:
            continue
        result.extend(make_divisors(i))
        # print(result)
        min_times += 1
    print(min_times, max_times)


if __name__ == '__main__':
    main()


Measured memory_bytes: 6396
def calc
        mp=gets.split(' ')
        a=mp[0].to_i
        op=mp[1]
        b=mp[2].to_i
        case op
        when '+' then
        ans=a+b
        when '-' then
        ans=a-b
        when '*' then
        ans=a*b
        when '/' then
        ans=a/b
        when '?' then
        ans="end"
        end
        return ans
end

ans = calc
until ans=="end" do
   printf("%d\n",ans)
   ans=calc
end

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

#define HAS_TEST_CASE 0  // Do you forget to complete this?

namespace registerGen
{
typedef long long ll;

const int N=5e5;

int n,m,a[N+10];
char str[N+10];

inline void main()
{
	int n,d,ans=0;
	scanf("%d%d",&n,&d);
	for(int i=1;i<=n;i++)
	{
		double x,y;
		scanf("%lf%lf",&x,&y);
		double dis=sqrt(x*x+y*y);
		if(dis<=d*1.0)ans++;
	}
	printf("%d\n",ans);
}
}

int main()
{
#ifndef ONLINE_JUDGE
	freopen("tmp.out","w",stdout);
#endif
	int T=1;
#if HAS_TEST_CASE
	scanf("%d",&T);
#endif
	while(T--)registerGen::main();
	return 0;
}


Measured memory_bytes: 3744
#include<bits/stdc++.h>
using namespace std;
int main(){
	int x,ans;
	cin>>x;
	if(400<=x&&x<=599) ans=8;
	else if(600<=x&&x<=799) ans=7;
	else if(800<=x&&x<=999) ans=6;
	else if(1000<=x&&x<=1199) ans=5;
	else if(1200<=x&&x<=1399) ans=4;
	else if(1400<=x&&x<=1599) ans=3;
	else if(1600<=x&&x<=1799) ans=2;
	else if(1800<=x&&x<=1999) ans=1;
	cout<<ans;
	return 0;
}

Measured memory_bytes: 3636
#include <stdio.h>

int getMask(int x){
  int m = 0;
  while(x){
    int c = x%10; x/=10;
    if(c==3)m |= 1<<0;
    else if(c==5)m |= 1<<1;
    else if(c==7)m |= 1<<2;
    else m |= 1<<3;
  }
  return m;
}

int getMask(int x, int t){
  int m = 0;
  while(t--){
    int c = x%10; x/=10;
    if(c==3)m |= 1<<0;
    else if(c==5)m |= 1<<1;
    else if(c==7)m |= 1<<2;
    else m |= 1<<3;
  }
  return m;
}

int main(){
  int n;
  scanf("%d",&n);
  int ans = 0;

  // 俺は半分全列挙を行う！
  const int B = 100000;
  const int S = 5;
  // 上の桁が n/B と一致するような場合
  if(getMask(n/B)<8){
    for(int low=0; low<=n%B; low++){
      int x = (n/B)*B + low;
      if(getMask(x)==7)ans++;
    }
  }
  // 上の桁が 0 と一致するような場合
  if(n/B != 0){
    for(int low=0; low<B; low++){
      int x = low;
      if(getMask(x)==7)ans++;
    }
  }
  // 上の桁が 1 以上 n/B 未満の場合
  int cnt[8] = {};
  for(int high=1; high<n/B; high++){
    int m = getMask(high);
    if(m>=8)continue;
    for(int sub=0; sub<8; sub++){
      if((m&sub)==sub)cnt[sub]++;
    }
  }
  for(int low=0; low<B; low++){
    int m = getMask(low, 5);
    if(m>=8)continue;
    ans += cnt[m^7];
  }

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


Measured memory_bytes: 128
a, b, k = map(int, input().split())

if a > k or a == k:
    a = a - k
    print(a, b)
else:
    tem = k - a
    a = 0
    if b > tem or b == tem:
        b = b - tem
        print(a, b)
    else:
        b = 0
        print(a, b)

Measured memory_bytes: 3064