akhauriyash/Code-Regression huggingface dataset:
package main

import (
	"fmt"
	"strconv"
)

func main() {
	// Code for C - Many Formulas
	var S string
	fmt.Scan(&S)

	var n int = len(S) - 1
	var flag string
	var temp string
	var ans int
	var sum int
	var num int
	for i := 0; i < (1 << n); i++ {
		flag = ""
		for j := 0; j < n; j++ {
			flag += S[j : j+1]
			if i>>j&1 == 1 {
				flag += "+"
			}
		}
		flag += S[len(S)-1 : len(S)]

		temp = ""
		ans = 0
		for j := 0; j < len(flag); j++ {
			if flag[j] == '+' {
				num, _ = strconv.Atoi(temp)
				temp = ""
				ans += num
			} else {
				temp += flag[j : j+1]
			}
		}

		if temp != "" {
			num, _ = strconv.Atoi(temp)
			ans += num
		}

		sum += ans
	}

	fmt.Println(sum)
}


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

int main() {
  int N , D , X;
  cin >> N >> D >> X;
  vector<int> vec(N);

  for (int i = 0 ; i < N ; i++){
    cin >> vec.at(i) ;
  }

  vector<int> ko(N) ;

  for ( int i = 0 ; i < N ; i++){
    for( int k = 0 ; k < D ; k++){ 
       if ( D == (vec.at(i)*k) + 1){
        ko.at(i) = k + 1;
        break;
       }
       else if( D < (vec.at(i)*k) + 1) {
         ko.at(i) = k  ;
         break;
       }
    }
  }

  int sum = 0;
  for ( int i = 0 ; i < N ; i++)
    sum += ko.at(i) ;
  cout << sum + X << endl ;

}


Measured memory_bytes: 256
#!/usr/bin/env ruby

require 'set'

class Hash
  def push(key, value)
    self[key] = [] if self[key] == nil
    self[key].push(value)
  end
end

class Array
  def lower_bound(value)
    left = -1;
    right = self.length;
    while left + 1 < right
      mid = left + (right - left) / 2;
      if self[mid] >= value
        right = mid
      else
        left = mid
      end
    end
    right
  end

  def unique
    res = [self.first]
    each_cons(2) do |a, b|
      if a != b
        res.push(b)
      end
    end
    res
  end
end

def get_ints
  gets.chomp.split.map(&:to_i)
end

def get_ints_minus_one
  get_ints.map { |x| x - 1 }
end

def get_int
  gets.chomp.to_i
end

A, B, K = get_ints

max = [A, B].max

stock = []
1.step(max) do |n|
  if A % n == 0 && B % n == 0
    stock << n
  end
end

puts stock[stock.length - K]



Measured memory_bytes: 14500
#include <iostream>
#include <string>

using namespace std;

int main(void) {
	int money = 100000;
	int n;
	
	cin >> n;
	
	for(int i = 0; i < n; i++) {
		money *= 1.05;
		if(money % 1000 != 0) {
			money += 1000;
			money -= money % 1000;
		}
		
	}
	
	cout << money << endl;
	
	return 0;
}

Measured memory_bytes: 1160
#include <iostream>
#include <string>

using namespace std;

int min(int a, int b);

int main() {

	string str;
	int q = 0;
	string order;
	int a = 0;
	int b = 0;

	cin >> str >> q;

	for (int i = 0; i < q; i++) {

		cin >> order >> a >> b;

		if (order == "replace") {

			string replace;

			cin >> replace;

			for (int u = a; u < b + 1; u++) {

				str[u] = replace[u - a];

			}

		}
		else if (order == "reverse") {

			string reverse;

			for (int u = a; u < b + 1; u++) {

				reverse += str[u];

			}

			for (int u = a; u < b + 1; u++) {

				str[u] = reverse[b - u];

			}

		}
		else if (order == "print") {

			for (int u = a; u < b + 1; u++) {

				cout << str[u];

			}

			cout << endl;

		}

	}

	return 0;

}

int min(int a,int b) {

	if (a >= b) {

		return b;

	}
	else {

		return a;

	}

}


Measured memory_bytes: 3212
import java.io.ByteArrayInputStream;
import java.io.PrintWriter;
import java.util.Scanner;

public class Main {
	
	String INPUT = "";
	
	public static void main(String[] args) throws Exception {
		new Main().run();
	}
	
	void run() {
		Scanner sc = INPUT.isEmpty() ? new Scanner(System.in) : new Scanner(new ByteArrayInputStream(INPUT.getBytes()));
		PrintWriter out = new PrintWriter(System.out);
		
		solve(sc, out);
		out.flush();
	}
	
	void solve(Scanner sc, PrintWriter out) {
		int H, W;
		
		for (;;) {
			H = sc.nextInt();
			W = sc.nextInt();
			if (H == 0 && W == 0) break;
			for (int i = 0; i < H; i++) {
				for (int j = 0; j < W; j++) {
					if (i != 0 && i != H-1 && j != 0 && j != W-1) System.out.print(".");
					else System.out.print("#");
				}
				System.out.println();
			}
			System.out.println();
		}
	}
}



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

int n;
long long t = 1, a;

int main()
{
	cin >> n;

	for (int i = 0; i < n; i++) {
		cin >> a;

		if (t == 0 || a == 0)
			t = 0;
		else if (t > 0 && t <= 1000000000000000000 / a)
			t *= a;
		else
			t = -1;
	}

	cout << t << endl;
}


Measured memory_bytes: 3616
#include <functional>
#include <algorithm>
#include <iostream>
#include <iomanip>
#include <cstring>
#include <string>
#include <vector>
#include <random>
#include <bitset>
#include <queue>
#include <cmath>
#include <stack>
#include <set>
#include <map>
typedef long long ll;
using namespace std;
const ll MOD = 1000000007LL;

int main() {
    vector<vector<int>> a(3, vector<int>(3));
    for (int i = 0; i < 3; i++) {
        for (int j = 0; j < 3; j++) {
            cin >> a[i][j];
        }
    }
    
    int n;
    cin >> n;
    
    for (int i = 0; i < n; i++) {
        int b;
        cin >> b;
        for (int j = 0; j < 3; j++) {
            for (int k = 0; k < 3; k++) {
                if (a[j][k] == b) {
                    a[j][k] = 0;
                }
            }
        }
    }
    
    for (int i = 0; i < 3; i++) {
        if (a[i][0] == 0 && a[i][1] == 0 && a[i][2] == 0) {
            cout << "Yes" << endl;
            return 0;
        }
        if (a[0][i] == 0 && a[1][i] == 0 && a[2][i] == 0) {
            cout << "Yes" << endl;
            return 0;
        }
    }
    
    if (a[0][0] == 0 && a[1][1] == 0 && a[2][2] == 0) {
        cout << "Yes" << endl;
        return 0;
    }
    
    if (a[2][0] == 0 && a[1][1] == 0 && a[0][2] == 0) {
        cout << "Yes" << endl;
        return 0;
    }
    
    cout << "No" << endl;
    return 0;
}

Measured memory_bytes: 256
n = int(input())
a = list(map(int,input().split()))
ans = 0
for i in range(n):
  for j in range(i+1,n):
    for k in range(j+1,n):
      b = [a[i],a[j],a[k]]
      b.sort()
      if b[0] == b[1] or b[1] == b[2]:
        pass
      elif b[0] + b[1] > b[2]:
        ans += 1
print(ans)

Measured memory_bytes: 68272
ni = lambda: int(input())
nm = lambda: map(int, input().split())
nl = lambda: list(map(int, input().split()))

a,b,k=nm()
nums=set()
for i in range(a,min(a+k,b)):
  nums.add(i)
for i in range(max(a,b-k+1),b+1):
  nums.add(i)

for n in sorted(nums):
  print(n)


Measured memory_bytes: 9136
#include<bits/stdc++.h>
#define QS ios_base::sync_with_stdio(false);
typedef long long ll;
const ll INF = 1e18;
const ll MOD = 1e9+7;
const int N = 1e5 + 1;
using namespace std;

ll a[N];
int main(){
//freopen("output.txt", "w", stdout);
    QS
    int n, m; cin >> n >> m;
    priority_queue<ll> pq;
    for(int i = 1; i <= n; ++i){
        cin >> a[i];
        pq.push(a[i]);
    }
    ll ans = 0;
    for(int i = 0; i < m; ++i){
        ll fr = pq.top();
        if(fr == 0) break;
        pq.pop();
        fr/=2;
        pq.push(fr);
    }
    for(;!pq.empty();){
        ll t = pq.top();
        pq.pop();
        ans += (t);
    }
    cout << ans << "\n";
}


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

int main() {

    int N;

    cin >> N;

    int a[N];

    map<int,int> a_map;

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

    for (int i = 0; i < N; i++) {

        a_map[a[i]] = 1;
    }

    cout << a_map.size() << endl;

    return 0;
}

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

#define rep(i, n) REP(i, 0, n)
#define REP(i, x, n) for (int i = x; i < n; i++)
#define OP(x) cout << x << endl;

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

    int sum = 0;
    int cnt = 0;
    rep(i, n){
        int l; cin >> l;
        sum += l;
        if(sum <= x) cnt++;
    }
    OP(cnt + 1);
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep2(i, s, n) for (int i = s; i < (int)(n); i++)
#define chmax(a, b) a = max(a, b)
#define chmin(a, b) a = min(a, b)
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()

using namespace std;
using ll = long long;
using pii = pair<int, int>;
using vi = vector<int>;

//const ll INF = 1e18L + 5;
//const int INF = 1e9 + 5;
//const double pi = 3.14159265358979323846;

ll n, k;
vi		path;
vi		visited;
map<int, int> cnt, idx;

void	dfs()
{
	int p = path[0];
	int i = 0;
	while (true) {
		k--;
		cnt[p]++;
		if (cnt[p] >= 2) {
			int d = visited.size() - idx[p];
			int id = k % d;
			cout << visited[idx[p] + id] << endl;
			break;
		} else if (k == 0) {
			cout << p << endl;
			break;
		}
		visited.push_back(p);
		idx[p] = i;
		i++;
		p = path[p - 1];
	}
}

void	solve()
{
	cin >> n >> k;
	rep(i, n) {
		int a;
		cin >> a;
		path.push_back(a);
	};
	dfs();
}

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

	solve();
}


Measured memory_bytes: 19580
#include <iostream>
#include <fstream>
#include <sstream>
#include <iomanip>
#include <vector>
#include <string>
#include <algorithm>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <unordered_set>
#include <unordered_map>
#include <bitset>
#include <limits>
#include <random>
#include <complex>
#include <cmath>
#include <cstdio>
#include <cstdlib>
using namespace std;

#define REP(i,n) for (int i = 0; i < n; i++)
typedef long long ll;

ll N,M;
ll A[100010];
map < ll,ll > acc;

int main ()
{

    cin >> N >> M;
    REP(i,N) cin >> A[i];

    acc[0] = 1;

    ll sum = 0;
    ll ans = 0;
    REP(i,N) {
    	sum += A[i];
    	ll mod = sum % M;
    	if (acc.find(mod) == acc.end()) {
    		acc[mod] = 1;
    	} else {
    		ans += acc[mod];
    		acc[mod]++;
    	}
    }

    cout << ans << endl;

    return 0;
}



Measured memory_bytes: 4992
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<(int)(n);++i)
#define repone(i,n) for(int i=1;i<(int)(n);++i)
#define repo(i,o,n) for(int i=o;i<(int)(n);++i)
#define Rep(j,n) for(int j=0;j<(int)(n);++j)
#define Repo(j,o,n) for(int j=o;j<(int)(n);++j)
#define Repone(j,n) for(int j=1;j<(int)(n);++j)
#define all(v) (v).begin(),(v).end()
#define rall(v) (v).rbegin(),(v).rend()
#define int long long
#define pb(a) push_back(a)
#define eraser(v,i) (v).erase(v.begin()+(i))
#define pbpair(a,b) push_back(make_pair(a,b))
#define Little 1
const long long INF = 1LL<<60;
#define pairint pair<int,int>
signed main(){
  int x=0,y=0,z=0,w=1,n=1,m=0,o=0;
  std::cin >> x>>y>>z;
  n=y;
  while(n<=z){
    if(n%x==0){
      std::cout << "OK" << '\n';
      return 0;
    }
    n++;
  }
  std::cout << "NG" << '\n';
}


Measured memory_bytes: 3516
#include<vector>
#include<iostream>
#include<algorithm> // sort,reverse,min,lower_bound
using namespace std;
#define df 0
#define INF 1000000000
#define rep(i,n) for(int i=0;i<(n);i++)
#define repa(i,a,n) for(int i=(a);i<(n);i++)
#define chmin(a,b) if((a)>(b)) a=(b)
#define chmax(a,b) if((a)<(b)) a=(b)
typedef long int li;
template<typename T>
void print_item(T x) {cout << x;}

// vector 型
template<typename T>
void print(vector<T>& vec,string str=""){
  if(str!="") cout << str << ":";
  for(T x: vec) {print_item(x); cout << " ";}
  cout << endl;
}

int main(){
  if(df) printf("*debug mode*\n");
  li h,n; cin >>h>>n;
  vector<pair<int,int>> ab;
  int m=0;
  rep(i,n){
    pair<int,int> a; cin >>a.first >>a.second;
    chmin(a.first,h);
    ab.push_back(a);
    chmax(m,(h+a.first-1)/a.first*a.first%h);
  }
  m+=h+1;
  if(df)printf("%d\n",m);
  vector<int> v(m,INF);
  v.at(0)=0;
  rep(i,n){
    int a=ab.at(i).first,b=ab.at(i).second;
    repa(j,a,m){
      chmin(v.at(j),v.at(j-a)+b);
    }
    for(int j=m-1;j>0;j--){
      chmin(v.at(j-1),v.at(j));
    }
    if(df)print(v);
  }
  cout << v.at(h);
}

/// confirm df==0 ///


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define fi first
#define se second
#define pb push_back
#define SZ(x) ((int)x.size())
#define L(i,u) for (register int i=head[u]; i; i=nxt[i])
#define rep(i,a,b) for (register int i=(a); i<=(b); i++)
#define per(i,a,b) for (register int i=(a); i>=(b); i--)
using namespace std;
typedef long long ll;
typedef unsigned int ui;
typedef pair<int,int> Pii;
typedef vector<int> Vi;
template<class T> inline void read(T &x){
	x=0; char c=getchar(); int f=1;
	while (!isdigit(c)) {if (c=='-') f=-1; c=getchar();}
	while (isdigit(c)) {x=x*10+c-'0'; c=getchar();} x*=f;
}
template<class T> inline void umin(T &x, T y){x=x<y?x:y;}
template<class T> inline void umax(T &x, T y){x=x>y?x:y;}
inline ui R() {
	static ui seed=416;
	return seed^=seed>>5,seed^=seed<<17,seed^=seed>>13;
}
const int mo = 1e9;
ll n;int a,b,c,d;
int main() {
	read(n);a=mo;b=n/a;if(1LL*a*b<n)b++;
	c=1;d=1LL*a*b-n;
	printf("0 0 %d %d %d %d\n",a,c,d,b);
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define N 100050
using namespace std;
inline int rd() {
	int x=0,f=1;char ch=getchar();
	while (ch>'9'||ch<'0') {if(ch=='-')f=-1;ch=getchar();}
	while (ch>='0'&&ch<='9'){x=(x<<1)+(x<<3)+ch-'0';ch=getchar();}
	return x*f;
}
int n,m,vis[N],tot,ans;
vector<int> e[N];
void link(int a,int b) {e[a].push_back(b), e[b].push_back(a);}

int get(int u) {
	for (int i=0;i<(int)e[u].size();i++)
		if (!vis[e[u][i]]) return e[u][i];
	return 0;
}

int main() {
	n = rd(), m = rd();
	for (int i=1;i<=m;i++) link(rd(), rd());
	deque<int> q;
	q.push_back(1);
	vis[1] = 1;
	ans = 1;
	for (;;) {
		int x,y;
		x = q.front(), y = get(x);
		if (y) {
			ans++;
			vis[y] = 1;
			q.push_front(y);
			continue;
		}
		x = q.back(), y = get(x);
		if (y) {
			ans++;
			vis[y] = 1;
			q.push_back(y);
			continue;
		}
		break;
	}
	
	printf("%d\n",ans);
	while (!q.empty()) {
		int x = q.front(); q.pop_front();
		++tot;
		printf("%d%c",x,tot==ans?'\n':' ');
	}
	return 0;
}


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

typedef int_fast32_t int32;
typedef int_fast64_t int64;

const int32 inf = 1e9+7;
const int32 MOD = 1000000007;
const int64 llinf = 1e18;

#define YES(n) cout << ((n) ? "YES\n" : "NO\n"  )
#define Yes(n) cout << ((n) ? "Yes\n" : "No\n"  )
#define POSSIBLE(n) cout << ((n) ? "POSSIBLE\n" : "IMPOSSIBLE\n"  )
#define ANS(n) cout << (n) << "\n"
#define REP(i,n) for(int64 i=0;i<(n);++i)
#define FOR(i,a,b) for(int64 i=(a);i<(b);i++)
#define FORR(i,a,b) for(int64 i=(a);i>=(b);i--)
#define all(obj) (obj).begin(),(obj).end()
#define rall(obj) (obj).rbegin(),(obj).rend()
#define fi first
#define se second
#define pb(a) push_back(a)
typedef pair<int32,int32> pii;
typedef pair<int64,int64> pll;

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

int32 d;
int32 c[26];
int32 s[365][26];

int32 last[365][26];
int32 S;
int32 score(vector<int32> &t, int32 e = d){
  REP(i,26)last[0][i] = -1;
  S = 0;
  REP(i,e){
    S += s[i][t[i]];
    if(i != 0){
      REP(j,26){
        last[i][j] = last[i-1][j];
      }
    }
    last[i][t[i]] = i;
    REP(j,26)S -= c[j] * (i - last[i][j]);
    // ANS(res);
  }
  return S;
}

int32 chquery(vector<int32> &t, int32 di, int32 nt){
  S -= s[di][t[di]];
  int32 pre = last[di][t[di]];
  if(di == 0){
    last[di][t[di]] = -1;
  }else{
    last[di][t[di]] = last[di-1][t[di]];
  }
  S -= c[t[di]] * (pre - last[di][t[di]]);
  FOR(i,di+1,d){
    if(t[i] == t[di])break;
    S -= c[t[di]] * (last[i][t[di]] - last[i-1][t[di]]);
    last[i][t[di]] = last[i-1][t[di]];
  }

  t[di] = nt;

  S += s[di][t[di]];
  pre = last[di][t[di]];
  last[di][t[di]] = di;
  S += c[t[di]] * (di - pre);
  FOR(i,di+1,d){
    if(t[i] == t[di])break;
    S += c[t[di]] * (di - pre);
    last[i][t[di]] = di;
  }

  return S;
}

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

  // input
  cin >> d;
  REP(i,26)cin >> c[i];
  REP(i,d)REP(j,26)cin >> s[i][j];

  // scoring
  vector<int32> t(d);
  REP(i,d)cin >> t[i];
  REP(i,d)t[i]--;
  score(t);
  // REP(i,d)ANS(score(t,i+1));

  // greedy
  // vector<int32> t(d,-1);
  // REP(i,d){
  //   int32 mx=-inf,mxj=-1;
  //   REP(j,26){
  //     t[i] = j;
  //     if(chmax(mx,score(t,i+1))){
  //       mxj = j;
  //     }
  //   }
  //   t[i] = mxj;
  // }
  // REP(i,d)ANS(t[i]+1);
  // ANS(score(t));

  // incremental scoring
  int32 m;
  cin >> m;
  REP(_,m){
    int32 di,q;
    cin >> di >> q;
    di--;q--;
    ANS(chquery(t,di,q));
  }

  return 0;
}

Measured memory_bytes: 3800
#include <bits/stdc++.h>
#define N 200010
#define mod 1000000007
using namespace std;
typedef long long ll;
inline int read()
{
	int x=0,f=1; char ch=getchar();
	while(ch<'0'||ch>'9'){if(ch=='-')f=-1; ch=getchar();}
	while(ch>='0'&&ch<='9'){x=x*10+ch-'0'; ch=getchar();}
	return x*f;
}
struct edge
{
	int v,next;
}vs[N<<1];
int n,fa[N][20],dep[N],ee,st[N],a[N],s[N];
int top,c[N],dfn,F[N][20],pl[N],Ans;
vector <int> V[N];
inline bool cmp(const int&a,const int &b)
{
    return pl[a]<pl[b];
}
inline void addedge(int u,int v)
{
	//cerr << u << " " << v << endl;
	vs[++ee].v=v;vs[ee].next=st[u];st[u]=ee;
}
inline int qpow(int bas,int pw)
{
	int ret=1; for(;pw;pw>>=1,bas=1ll*bas*bas%mod)
	if(pw&1) ret=1ll*ret*bas%mod; return ret;
}
inline int lca(int x,int y)
{
	if(dep[x]>dep[y]) swap(x,y);
	int t=dep[y]-dep[x];
	for(int i=0;i<20;i++) if(t&(1<<i)) y=fa[y][i];
	for(int i=19;i>=0;i--) 
	if(fa[x][i]!=fa[y][i])
		x=fa[x][i],y=fa[y][i];
	return x==y? x:fa[x][0]; 
}
inline void dfs(int rt)
{
	pl[rt]=++dfn;
	V[dep[rt]].push_back(rt);
	for(int i=1;i<=19;i++) fa[rt][i]=fa[fa[rt][i-1]][i-1];
	for(int i=st[rt];i;i=vs[i].next)
	{
		fa[vs[i].v][0]=rt;
		dep[vs[i].v]=dep[rt]+1;
		dfs(vs[i].v);
	}
}
inline void dfs1(int rt)
{
	c[++dfn]=rt; 
	if(F[rt][0]) return ;
	int ss=1,ww=1;
	for(int i=st[rt];i;i=vs[i].next)
	{
		dfs1(vs[i].v);
		ss=1ll*ss*F[vs[i].v][0]%mod;
		ww=1ll*ww*((F[vs[i].v][0]+F[vs[i].v][1])%mod)%mod;
	}
	for(int i=st[rt];i;i=vs[i].next)
		F[rt][1]=(1ll*F[rt][1]+1ll*qpow(F[vs[i].v][0],mod-2)%mod*F[vs[i].v][1]%mod*ss%mod)%mod;
	F[rt][0]=(ww-F[rt][1])%mod; if(F[rt][0]<0) F[rt][0]+=mod;
}
void solve(int as)
{
    int k=V[as].size();dfn=0;ee=0;
    for(int i=1;i<=k;i++) a[i]=V[as][i-1];
    for(int i=1;i<=k;i++) F[a[i]][0]=F[a[i]][1]=1;
    sort(a+1,a+1+k,cmp);top=0;
    if(a[1]!=1) s[++top]=1;
    for(int i=1;i<=k;i++)
    {
        int t=a[i],f=0;
        while(top>0)
        {
            f=lca(s[top],t); 
            if(top>1&&dep[f]<dep[s[top-1]])
                addedge(s[top-1],s[top]),top--;
            else if(dep[f]<dep[s[top]])
            {
                addedge(f,s[top]);top--; break;
            }
            else break;
        }
        if(s[top]!=f) s[++top]=f;
        s[++top]=t;
    }
    while(top>1) addedge(s[top-1],s[top]),top--;
    dfs1(1);
    Ans+=1ll*F[1][1]*qpow(2,n+1-k)%mod; Ans%=mod;
    for(int i=1;i<=dfn;i++) F[c[i]][0]=F[c[i]][1]=st[c[i]]=0;
  //  puts("");
}
int main()
{
	n=read();
	for(int i=1;i<=n;i++)
	{
		int k=read();
		addedge(k+1,i+1);
	}
	dfs(1); ee=0; memset(st,0,sizeof st);
	for(int i=0;i<=n;i++) solve(i);
	cout << Ans << endl;
	return 0;
}

Measured memory_bytes: 52224
#include <bits/stdc++.h>
 
using namespace std;
 
typedef long long ll;
typedef unsigned long long ull;
 
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define RFOR(i,a,b) for(int i=(b)-1;i>=(a);i--)
#define REP(i,n) for(int i=0;i<(n);i++)
#define RREP(i,n) for(int i=(n)-1;i>=0;i--)
#define VSORT(v) sort(v.begin(), v.end())
#define DVSORT(v) sort(v.begin(), v.end(),greater<int>())
#define SORT(v, n) sort(v, v+n)
#define DSORT(v,n) sort(v, v+n,greater<int>())
#define vi vector<int>
#define pb push_back
#define P pair<int,int>
 
 
template <class T> void chmin(T&a, const T&b) { a = min(a,b); }
template <class T> void chmax(T&a, const T&b) { a = max(a,b); }
 
const double EPS =1e-9;
const long INF =2147483647;//32bit 2*1e+9
const long MOD =1000000007; //10^9+7
#define PI 3.14159265258979
 
int dy[]={0, 0, 1, -1, 1, 1, -1, -1};
int dx[]={1, -1, 0, 0, 1, -1, -1, 1};

int main(void){
	int N,t[101]={},M,sum=0;

	cin>>N;
	FOR(i,1,N+1){
		cin>>t[i];
		sum+=t[i];
	}

	cin>>M;
	int p,x;
	REP(i,M){
		cin>>p>>x;
		printf("%d\n",sum-t[p]+x);
	}
	return 0; 
}


Measured memory_bytes: 256
<?php

$rank = new SplPriorityQueue();
$rank->setExtractFlags(SplPriorityQueue::EXTR_BOTH);
while (true) {
    fscanf(STDIN, '%d,%d', $t, $v);
    if ($t === 0 && $v === 0) {
        break;
    }
    $rank->insert($t, $v);
}
$hash = array();
$i = 0;
$v = 40;
while (!$rank->isEmpty()) {
    $node = $rank->extract();
    if ($node['priority'] < $v) {
        $i++;
        $v = $node['priority'];
    }
    $hash[$node['data']] = $i;
}
while (true) {
    fscanf(STDIN, '%d', $t);
    if (feof(STDIN)) {
        break;
    }
    echo $hash[$t] . PHP_EOL;
}

Measured memory_bytes: 6664
#include<bits/stdc++.h>
using namespace std;
int main()
{
  long long  x;cin>>x;
  long long c=100;\
  if(c>=x)
  {
  	cout<<0<<endl;
  	return 0;
  }
  for(int i=1;c<x;i++)
  {
  	c*=1.01;
  	if(c>=x)
  	{
  		cout<<i<<endl;
  		return 0;
	  }
  }
  return 0;
}

Measured memory_bytes: 3648
#include <bits/stdc++.h>
#define F(i, l, r) for(int i = (l), _end_ = (int)(r); i <= _end_; ++i)
#define f(i, r, l) for(int i = (r), _end_ = (int)(l); i >= _end_; --i)
#define Set(a, v) memset(a, v, sizeof(a))
#define file(a) freopen(a".in","r",stdin),freopen(a".out","w",stdout)
using namespace std;

template<typename T>bool chkmax(T &a,T b){return (a<b)?a=b,1:0;}
template<typename T>bool chkmin(T &a,T b){return (a>b)?a=b,1:0;}

inline int read() {
 int x = 0, fh = 1; char ch = getchar();
    for (; !isdigit(ch); ch = getchar() ) if (ch == '-') fh = -1;
    for (; isdigit(ch); ch = getchar() ) x = (x<<1) + (x<<3) + (ch ^ '0');
    return x * fh;
}
int n;
int a[200005];
#define down(x,y) (a[x]<=k&&a[y]<=k)
#define up(x,y) (a[x]>k&&a[y]>k)
bool check(int k){
    if(down(n-1,n)||down(n,n+1))return 1;
    if(up(n-1,n)||up(n,n+1))return 0;
    F(i,1,n-2){
        if(down(n+i,n+i+1)||down(n-i,n-i-1))return 1;
        if(up(n+i,n+i+1)||up(n-i,n-i-1))return 0;
    }
    return down(1,1);
}
int main () {
#ifndef ONLINE_JUDGE
//file("agc006d");
#endif
    n=read();
	int l=0,r=(n<<1)-1;
	F(i,1,r)a[i]=read();
	int ans=0;
	while(l<=r){
	   int mid=(l+r)>>1;
	   if(check(mid))ans=mid,r=mid-1;
	   else l=mid+1;
	}
	printf("%d\n",ans);
    return 0;
}

Measured memory_bytes: 1024
from itertools import  product
N,M,X = map(int,input().split())
ca = [list(map(int,input().split())) for _ in range(N)]
for i in range(1,M+1):
    count=0
    for j in range(N):
        count+=ca[j][i]
    if count<X:
        print(-1)
        exit()

ans = 10**9
for z in product((0, 1), repeat=N):#bit全探索のくみあわせを勝手に作ってくれるので使うとよい
    count=0
    count2=[0]*M
    for i in range(N):
        if z[i]==1:
            count+=ca[i][0]
            for j in range(1,M+1):
                count2[j-1]+=ca[i][j]
    
    for i in range(M):
        if count2[i]<X:
            break
    else:
        ans=min(count,ans)
print(ans)


Measured memory_bytes: 9172
#include <bits/stdc++.h>
typedef long long int ll;
typedef long double ld;
using namespace std;

int main(){
    string s;
    cin>>s;
    ll ans=1e9;
    string flag;
    ll num;
    for(ll i=0;i<s.size()-2;++i){
        flag=s.substr(i,3);
        num=atoi(flag.c_str());
        if(abs(ans-753)>abs(num-753)){
            ans=num;
        }
    }
    cout<<abs(ans-753)<<endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define rep(i,N) for(int i=0;i<(N);i++)
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
using namespace std;
const long long MOD = 1e9 + 7;
const long long INF = 1e12;
const int inf = 1e9;
typedef long long ll;
typedef pair<ll,int> P;
typedef set<int> S;
string s,t;
int dp[3100][3100]={0};
int main(){
    cin>>s>>t;
    for(int i = 0;i < s.size(); i++){
        for(int j = 0;j < t.size(); j++){
            if(s[i]==t[j]){
                 dp[i+1][j+1]=dp[i][j]+1;
                /*if(i==0 && j==0) {
                    cout<<"first"<<endl;
                    cout<<dp[i][j]+1<<endl;
                    cout<<dp[1][1]<<endl;
                    cout<<"end"<<endl;
                }
                dp[i+1][j+1]=dp[i][j]+1;

            } dp[i+1][j+1]=dp[i][j]+1;*/
            }
            else{
                dp[i+1][j+1]=max(dp[i+1][j],dp[i][j+1]);
            }
        }
    }
    //cout<<dp[1][1]<<endl;
    string res="";
    int i=(int)s.size(),j=(int)t.size();
    while(i>0 & j>0){
        if(dp[i][j]==dp[i-1][j]){
            --i;
        }
        else if(dp[i][j]==dp[i][j-1]){
            --j;
        }
        else{
            res=s[i-1]+res;
            --j;
            --i;
        }
    }
    /*rep(i,s.size()+1){
        rep(j,t.size()+1){
            cout<<dp[i][j]<<" ";
        }
        cout<<endl;
    }
    cout<<dp[1][1]<<endl;
    cout<<dp[s.size()][t.size()]<<endl;*/
    cout<<res<<endl;
    return 0;
}

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

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

	int n,z,w,t;
	vector <int> v;

	cin >> n >> z >> w;

	for(int i=0;i<n;i++)
	{
		cin >> t;
		v.push_back(t);
	}

	int res = 0;
	res = max(res,abs(v[n-1]-w));
	if(n>1)
	{
		res = max(res,abs(v[n-1]-v[n-2]));
	}

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


Measured memory_bytes: 256
#include<stdio.h>

int main(void){
  int a,b,c,count1=0,count2=0;
  
  while(scanf("%d,%d,%d",&a,&b,&c)!=EOF){
    if(c*c==a*a+b*b && (a!=b && b!=c))count1++;
    else if((a==b&&b!=c)||(a==b && b==c))count2++;
  }
  printf("%d\n%d\n",count1,count2);
  
  return 0;
}

Measured memory_bytes: 0
#include<stdio.h>
#include<string.h>
#include<math.h>
#include<algorithm>
using namespace std;
int main()
{
    int i,n,sum1,x,sum,a[200],min;
    while(scanf("%d%d",&n,&x)==2)
    {
        sum=0;
        for(i=0;i<n;i++)
        {
            scanf("%d",&a[i]);
            if(i==0)
                min=a[i];
            else
            {
                if(min>a[i])
                {
                    min=a[i];
                }
            }
            sum+=a[i];
        }
        x=x-sum;
        sum1=n+x/min;
        printf("%d\n",sum1);
    }
    return 0;
}


Measured memory_bytes: 128
#include <cstdio>
#include <cstring>
#include <algorithm>
#define MAXN 200010
using namespace std;

struct edge{
	int to,next;
	edge(int _to=0,int _next=0):to(_to),next(_next){}
}e[MAXN<<1],e2[MAXN<<1];

int n,x1,x2;
int g[MAXN],nume;
int g2[MAXN],nume2;
int dep[MAXN],size[MAXN],son[MAXN],top[MAXN],pre[MAXN],w[MAXN],pt[MAXN],numw;
int pre2[MAXN],h[MAXN],dep2[MAXN];
bool flag;
int ans;

void addEdge(int u,int v){
	e[nume]=edge(v,g[u]);
	g[u]=nume++;
}

void addEdge2(int u,int v){
	e2[nume2]=edge(v,g2[u]);
	g2[u]=nume2++;
}

void dfs(int x,int p){
	size[x]=1; son[x]=0;
	pre[x]=p;
	for(int i=g[x];~i;i=e[i].next)
		if(e[i].to^p){
			dep[e[i].to]=dep[x]+1;
			dfs(e[i].to,x);
			size[x]+=size[e[i].to];
			if(size[e[i].to]>size[son[x]])
				son[x]=e[i].to;
		}
}

void dfs2(int x,int p){
	pt[w[x]=++numw]=x;
	if(son[x]){
		top[son[x]]=top[x];
		dfs2(son[x],x);
	}
	for(int i=g[x];~i;i=e[i].next)
		if(e[i].to!=p && e[i].to!=son[x]){
			top[e[i].to]=e[i].to;
			dfs2(e[i].to,x);
		}
}

int getLCA(int x,int y){
	while(top[x]^top[y]){
		if(dep[top[x]]<dep[top[y]]) swap(x,y);
		x=pre[top[x]];
	}
	return dep[x]<dep[y]?x:y;
}

int getDis(int x,int y){
	return dep[x]+dep[y]-2*dep[getLCA(x,y)];
}

int goUp(int x,int d){
	while(dep[x]-dep[top[x]]+1<=d){
		d-=dep[x]-dep[top[x]]+1;
		x=pre[top[x]];
	}
	return pt[w[x]-d];
}

int step(int x,int y){
	int lca=getLCA(x,y);
	if(lca!=x) return pre[x];
	return goUp(y,dep[y]-dep[x]-1);
}

void dfs3(int x,int p){
	pre2[x]=p;
	for(int i=g2[x];~i;i=e2[i].next)
		if(e2[i].to^p){
			int y=e2[i].to;
			int dis=getDis(x,y);
			if(dis>=3 && x!=h[x]) flag=1;
			if(y==h[x] || x==h[x]) continue;
			h[y]=step(h[x],y);
			dep2[y]=dep2[x]+1;
			dfs3(y,x);
		}
	int res=getDis(h[x],x)*2+dep2[x]*2;
	ans=max(ans,res);
}

int main(){
#ifdef DEBUG
	freopen("E.in","r",stdin);
#endif
	memset(g,-1,sizeof g);
	memset(g2,-1,sizeof g2);
	scanf("%d%d%d",&n,&x1,&x2);
	for(int i=1;i<n;i++){
		int u,v;
		scanf("%d%d",&u,&v);
		addEdge2(u,v);
		addEdge2(v,u);
	}
	for(int i=1;i<n;i++){
		int u,v;
		scanf("%d%d",&u,&v);
		addEdge(u,v);
		addEdge(v,u);
	}
	dfs(1,0);
	top[1]=1;
	dfs2(1,0);
	h[x1]=x2;
	dfs3(x1,0);
	if(flag) puts("-1");
	else printf("%d\n",ans);
	return 0;
}


Measured memory_bytes: 24832
#include <bits/stdc++.h>
#define ll long long int
#define ld long double
#define mp make_pair
#define pi pair<int,int>
#define pl pair<long long int,long long int>
#define pb push_back
#define fi first
#define se second
#define len(a) (int)(a).length()
#define sz(a) (int)(a).size()

using namespace std;

const int M = 1e9 + 7;
int N, K, a[100], dp[100][100001], cum[100][100001];

int main ()
{
	ios_base::sync_with_stdio(false); cin.tie(NULL);
	cin >> N >> K;
	for (int i=0; i<N; ++i)
		cin >> a[i];
	memset(dp, 0, sizeof(dp));
	memset(cum, 0, sizeof(cum));
	for (int i=0; i<=a[0]; ++i)
		dp[0][i] = 1;
	cum[0][0] = 1;
	for (int i=1; i<=K; ++i)
		cum[0][i] = (cum[0][i-1] + dp[0][i]) % M;
	for (int i=1; i<N; ++i)
		for (int j=0; j<=K; ++j) {
			int temp = max(0, j - a[i]), x;
			x = cum[i-1][j];
			if (temp > 0) x = (x - cum[i-1][temp-1] + M) % M;
			dp[i][j] = x;
			if (j > 0) cum[i][j] = (cum[i][j-1] + dp[i][j]) % M;
			else cum[i][j] = dp[i][j];
		}
	cout << dp[N-1][K] << endl;
	return 0;
}


Measured memory_bytes: 78464
var lines =[];

var readline = require("readline");
var rl = readline.createInterface({
  input:  process.stdin,
  output: process.stdout
});

rl.on('line',function(x){
  lines.push(x);
});


rl.on('close',function(){
  var a = Number(lines[0].split(" ")[0]);
  var b = Number(lines[0].split(" ")[1]);

  if(b%a===0){console.log(a+b)}
  else{console.log(b-a)}
});


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

using ll=long long;
ll MOD=1e9+7;

ll formula(string &s,int& p);

ll num(string &s,int& p){
  ll res=0;
  while(p!=s.size() && isdigit(s[p])){
    res*=10;
    res+=s[p]-'0';
    p++;
  }
  return res;
}

ll term(string &s,int &p){
  if(s[p]=='S'){
    p++;
    assert(s[p]=='<');
    p++;
    ll res=formula(s,p);
    assert(s[p]=='>');
    p++;
    return (res*res)%MOD;
  }
  if(isdigit(s[p])){
    return num(s,p);
  }
  throw "unexpected";
}



ll formula(string &s,int &p){
  ll res=term(s,p);
  while(p!=s.size() && s[p]!='>'){
    assert(s[p]=='@');
    p++;
    ll rhs=term(s,p);
    res=(rhs>32) ? 0LL : res>>rhs;
  }
  return res;
}

string killSpace(string &s){
  string res="";
  for(int i=0;i<s.size();i++){
    if(s[i]!=' ') res.push_back(s[i]);
  }
  return res;
}

bool isShift(char x0,char x1,char x2){
  return x0=='>' && x1=='>' && x2!='>';
}
string shiftParse(string &s){
  string res="";
  for(int i=0;i<s.size();i++){
    if(i+2>=s.size()){
      res+=s[i];
    }
    else if(isShift(s[i],s[i+1],s[i+2])){
	res+='@';
	i++;
    }
    else{
      res+=s[i];
    }
  }
  return res;
}
int main(){
  string s;
  while(getline(cin,s),s!="#"){
    s=killSpace(s);
    s=shiftParse(s);
    int p=0;
    cout<<formula(s,p)<<endl;
  }
  return 0;
}


Measured memory_bytes: 6372
#include <iostream>

using namespace std;

int main() {
  int n;
  cin>>n;
  long l[90] = {2,1};
  for (int i = 2; i <= n; i++) {
    l[i] = l[i-2]+l[i-1];
  }
  cout<<l[n]<<endl;
  return 0;
}


Measured memory_bytes: 3124
function Longest(){
   ary.sort(function(a,b){
      if(a[0]==b[0])return a[1]-b[1];
      else return a[0]-b[0]
   });
   var A=ary.filter(function(v,i){
      if(i==0)return true;
      else if(ary[i-1][0]!=v[0])return true;
   });
   A=A.map(function(v){return v[1];});
   var L=[];
   L[0] = A[0];
   var length = 1;
   for(var i=1;i<A.length;i++){
      if (L[length-1] < A[i])L[length++] = A[i];
      else {
         for(var j=0;j<length;j++){
            if(L[j]>=A[i]){L[j]=A[i];break;}
         }
      }
   }
   return length;
}
var input = require('fs').readFileSync('/dev/stdin', 'utf8');
var arr=input.trim().split("\n");
while(true){
   var n=arr.shift()-0;
   if(n==0)break;
   var ary=[];
   for(var i=0;i<n;i++)ary.push(arr.shift().split(" ").map(Number));
   var m=arr.shift()-0;
   for(var i=0;i<m;i++)ary.push(arr.shift().split(" ").map(Number));
   var R=Longest();
   ary=ary.map(function(v){return [v[1],v[0]];});
   var H=Longest();
   console.log(Math.max(R,H));
}

Measured memory_bytes: 17172
//WrittenBiDP
//frog

#include <iostream>
#include <fstream>
#include <vector>
#include <algorithm>

using namespace std;

typedef vector <int> vi;

vi h;
vi ans;

int main() {
	//ifstream In("input.txt");
	//ofstream Out("output.txt");

	int n;
	//In >> n;
	cin >> n;

	for (int i = 0; i < n; i++) {
		int t;
		//In >> t;
		cin >> t;
		h.push_back(t);
	}

	ans.assign(n, 0);
	ans[1] = abs(h[0] - h[1]);

	for (int i = 2; i < n; i++) {
		int step1 = abs(h[i] - h[i - 1]) + ans[i - 1];
		int step2 = abs(h[i] - h[i - 2]) + ans[i - 2];
		ans[i] = min(step1, step2);
	}

	//Out << ans[n - 1];
	cout << ans[n - 1];
	return 0;
}

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


int main(){
  int N ; 
  cin >> N ; 
  vector<int> B(N+1) ; 
  int cnt = 0 ; 
  
  for(int i = 1 ; i <= N-1 ; i++){
    cin >> B.at(i) ;
  }
  
  B.at(0) = 10e6 ; 
  B.at(N) = 10e6 ; 
  
  for(int i = 0 ; i < N ; i++){
    //cout << B.at(i)  << " " << B.at(i+1) << endl ; 
    if(B.at(i) <= B.at(i+1)){
      cnt += B.at(i) ;
    }
    else{
      cnt += B.at(i+1) ; 
    }
  }

  cout << cnt << endl ; 
 
}

Measured memory_bytes: 3624
#include<bits/stdc++.h>
using namespace std;
int n,a[10]={0,1,2,4,8,16,32,64};
int main(){
	cin>>n;
	for(int i=7;i>=1;i--)
		if(n>=a[i]){
			cout<<a[i]<<endl;
			return 0;
		}
	return 0;
}

Measured memory_bytes: 256
module Main where

import Control.Applicative
import Numeric
import Data.Char

main :: IO ()
main = do
  { ln <- getLine
  ; putStrLn (map conv ln)
  }

conv :: Char -> Char
conv c | isLower c = toUpper c
       | otherwise = toLower c

--
getInts :: IO [Int]
getInts = map read . words <$> getLine

putInts :: [Int] -> IO ()
putInts = putStrLn . unwords . map show

getDoubles :: IO [Double]
getDoubles = map read . words <$> getLine

putDoubles ::  [Double] -> IO ()
putDoubles = putStrLn . unwords . map showDoubles

showDoubles :: Double -> String
showDoubles  d = showFFloat Nothing d ""



Measured memory_bytes: 3908
using System;
using System.Collections.Generic;

class Program
{
    static string InputPattern = "InputX";

    static List<string> GetInputList()
    {
        var WillReturn = new List<string>();

        if (InputPattern == "Input1") {
            WillReturn.Add("8");
            //2
        }
        else if (InputPattern == "Input2") {
            WillReturn.Add("2");
            //0
        }
        else if (InputPattern == "Input3") {
            WillReturn.Add("9");
            //3
        }
        else {
            string wkStr;
            while ((wkStr = Console.ReadLine()) != null) WillReturn.Add(wkStr);
        }
        return WillReturn;
    }

    static void Main()
    {
        List<string> InputList = GetInputList();
        int N = int.Parse(InputList[0]);

        Console.WriteLine(N / 3);
    }
}


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

int main() {
    long long int n,m;
    scanf("%lld%lld", &n, &m);
    long long int lo = 0, hi = n+m/2;
    while (hi-lo>0) {
        long long int mid = (hi+lo+1)/2;
        //printf("%lld %lld\n", mid, m-(mid-n)*2);
        long long nd = max((mid-n)*2,0LL);
        if (m-nd<mid*2) hi = mid-1;
        else lo = mid;
    }
    printf("%lld\n", lo);
}


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

int n;
int seq[100002];
long long ans[100002];

void proc() {
	scanf("%d", &n);
	vector<pair<int, int>> stk;
	vector<pair<int, int>> b;
	for (int i = 0; i < n; ++i) {
		scanf("%d", &seq[i]);
		if (stk.empty() || stk.back().first < seq[i]) {
			stk.push_back({ seq[i], i });
		}
		b.push_back({ seq[i], i });
	}
	sort(b.rbegin(), b.rend());

	int j = 0, cnt = 0;
	long long val = 0;
	for (int i = stk.size() - 1; i >= 0; --i) {
		val += (long long)cnt * (stk[i].first - (i == 0 ? 0 : stk[i - 1].first));
		while (j < n && b[j] > (i == 0 ? make_pair(0, -1) : stk[i - 1])) {
			++cnt;
			val += b[j].first - (i == 0 ? 0 : stk[i - 1].first);
			++j;
		}
		ans[stk[i].second] = val;
		val = 0;
	}

	for (int i = 0; i < n; ++i) {
		printf("%lld\n", ans[i]);
	}
}

int main() {
	//freopen("input.txt", "r", stdin);
	proc();
	return 0;
}

Measured memory_bytes: 4076
#include<bits/stdc++.h>
using namespace std;
int main(){
    int N,A=0,B=0;
    int ans=0;

    long ka,gen,zyou,Nmax;

    cin>>A>>B;

    ka=A+B;
    gen=A-B;
    zyou=A*B;

    Nmax=ka;
    Nmax=max(Nmax,gen);
    Nmax=max(Nmax,zyou);
    
    cout<<Nmax<<endl;

}

Measured memory_bytes: 256
import java.util.*;

class Main{
    int N;
    int[] n,d;
    int[][] map;
    int[] dx = {-1,0,1,0};
    int[] dy = {0,1,0,-1};
    void solve(){
	Scanner sc = new Scanner(System.in);
	while(true){
	    N = sc.nextInt();
	    if(N==0) break;
	    map = new int[402][402];
	    for(int i=0; i<402; i++) Arrays.fill(map[i],-1);
	    map[200][200] = 0;
	    n = new int[N];
	    d = new int[N];
	    for(int i=1; i<N; i++){
		n[i] = sc.nextInt();
		d[i] = sc.nextInt();
	    }

	    rec(200,200,0);

	    int firstH = -1; 
	    int lastH = -1;
	    int firstW = -1;
	    int lastW = -1;
	    for(int i=0; i<402; i++){
		for(int j=0; j<402; j++){
		    if(map[i][j]!=-1){
			if(firstH==-1){firstH = i; lastH = i;}
			firstH = Math.min(firstH,i);
			lastH = Math.max(lastH,i);
			if(firstW==-1){firstW = j; lastW = j;}
			firstW = Math.min(firstW,j);
			lastW = Math.max(lastW,j);
		    }
		}
	    }
	    int w = lastW-firstW+1;
	    int h = lastH-firstH+1;

	    System.out.println(w+" "+h);
	}
    }

    void rec(int x, int y, int num){
	for(int i=1; i<N; i++){
	    if(n[i]==num){
		int nx = x+dx[d[i]];
		int ny = y+dy[d[i]];
		map[ny][nx] = i;
		rec(nx,ny,i);
	    }
	}
    }


    public static void main(String[] args){
	new Main().solve();
    }
}

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

int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	ll n,a,b;cin >> n >> a >> b;
	vector<ll> x(n);
	rep(i,n) cin >> x.at(i);
	ll ans=0;
	rep(i,n-1){
		ans+=min(b,a*(x.at(i+1)-x.at(i)));
	}
	cout << ans << endl;
}

Measured memory_bytes: 1024
/**
 * code generated by JHelper
 * More info: https://github.com/AlexeyDmitriev/JHelper
 * @author KY2001
 */


#include "bits/stdc++.h"
#define int long long
#define FOR(i, a, b) for (int i = (int)(a); i < (int)(b); i++)
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define ALL(obj) begin(obj), end(obj)
#define MAX(x) *max_element(ALL(x))
#define MIN(x) *min_element(ALL(x))
#define LOWER_BOUND(A, key) distance(A.begin(), lower_bound(ALL(A), key))
#define UPPER_BOUND(A, key) distance(A.begin(), upper_bound(ALL(A), key))

using namespace std;
using ll      = long long;
const int MOD = (int)(1e9 + 7);
const int INF = (int)(1e13 + 7);

int bpm(int x, int y) {
  if (x == 0)
    return 0;
  else if (y == 0) {
    return 1;
  }
  int ans = 1;
  x %= MOD;
  int digit = (int)((log((double)y) / log((double)2) / 1 + 1));
  for (int i = 0; i < digit; i++) {
    if (((y >> i) & 1u) == 1) {
      ans *= x;
      ans %= MOD;
    }
    x = x * x;
    x %= MOD;
  }
  return ans;
}


class CHSI {
public:
	int solve(std::istream& cin, std::ostream& cout) {
          int N, M;
          cin>>N>>M;
          cout<<(1900*M+100*(N-M))*(bpm(2, M))<<endl;
	}
};


signed main() {
	CHSI solver;
	std::istream& in(std::cin);
	std::ostream& out(std::cout);
	solver.solve(in, out);
	return 0;
}


Measured memory_bytes: 256
import java.util.Arrays;
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner stdin = new Scanner(System.in);
        int n = Integer.parseInt(stdin.nextLine());
        int[] a = new int[n];
        for (int i = 0; i < n; i++) a[i] = Integer.parseInt(stdin.nextLine());
        String answer = Arrays.stream(a).allMatch(v -> v % 2 == 0) ? "second" : "first";
        System.out.println(answer);
    }
}


Measured memory_bytes: 94216
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <string>
#include <numeric>
#include <cstdint>
#include <iomanip>
#include <set>
#include <map>
#include <unordered_map>
#include <cassert>
using ll = long long;
#define rep(i,n) for(int i=0; i<(n); i++)
#define fast_io(); std::ios_base::sync_with_stdio(0); std::cin.tie(0); std::cout.tie(0);

int main(){
    fast_io();

    int n; std::cin >> n;
    std::vector<int> p(n);
    rep(i,n){
        std::cin >> p[i];
    }

    int ans = 0, min_p=1145141919;
    rep(i,n){
        min_p = std::min(min_p, p[i]);
        if(min_p==p[i]) ans++;
    }
    std::cout << ans << "\n";
    return 0;
}

Measured memory_bytes: 3960
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>

using namespace std;
using ll = long long;

int main(){
	ios_base::sync_with_stdio(false);
	ll n, p;
	cin >> n >> p;
	if(n == 1){
		cout << p << endl;
		return 0;
	}
	ll answer = 1;
	for(ll i = 2; i <= p && i < 1000000; ++i){
		ll c = 0;
		while(p % i == 0){
			p /= i;
			++c;
		}
		const ll k = c / n;
		for(ll j = 0; j < k; ++j){
			answer *= i;
		}
	}
	cout << answer << endl;
	return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main()
{
   string s,t;
   cin>>s>>t;
   int m=s.size();
   int n=t.size();
   int ans=0;
   for(int i=0;i<=(m-n);i++)
   {
       int pos=0;
       int sizes=0;
       for(int k=i;k<i+n;k++)
       {
           if(s.at(k)==t.at(pos))
            sizes++;
           pos++;
       }
       ans=max(ans,sizes);
   }
   cout<<n-ans;
}


Measured memory_bytes: 3636
#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 maxs(x,y) (x = max(x,y))
#define mins(x,y) (x = min(x,y))
#define limit(x,l,r) max(l,min(x,r))
#define lims(x,l,r) (x = max(l,min(x,r)))
#define isin(x,l,r) ((l) <= (x) && (x) < (r))
#define pb push_back
#define sz(x) (int)(x).size()
#define pcnt __builtin_popcountll
#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 bn(x) ((1<<x)-1)
#define dup(x,y) (((x)+(y)-1)/(y))
#define newline puts("")
#define v(T) vector<T>
#define vv(T) v(v(T))
using namespace std;
typedef long long int ll;
typedef unsigned uint;
typedef unsigned long long ull;
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;
inline int in() { int x; scanf("%d",&x); return x;}
const ll LINF = 1001002003004005006ll;
const int INF = 1001001001;
const int MOD = 1000000007;
#define dame { puts("-1"); return 0;}
#define yn {puts("YES");}else{puts("NO");}
  
int main() {
  string A;
  cin >> A;
  v(ll) cnt(26,0);
  rep(i,sz(A)) {
    cnt[A[i] - 'a']++;
  }
  ll ans = (((ll)sz(A) - 1)* (ll)sz(A) / (ll)2);
  rep(i,26) {
    ans -= (((ll)cnt[i] - 1) * (ll)cnt[i] / (ll)2);
  }
  cout << ans + 1 << endl;
  return 0;
}

Measured memory_bytes: 640
#include <stdio.h>
#include <iostream>

#include <bits/stdc++.h>


using namespace std;

#define INPUT_INT(valName) int valName; cin >> valName
#define INPUT_LLINT(valName) long long int valName; cin >> valName;
#define INPUT_STR(valName) string valName; cin >> valName;
#define INPUT_LINE(valName) string valName; getline(cin,s);
#define INPUT_VECTOR_INT(valName, N) vector<int> valName(N); for(int i=0; i < N; ++i) { cin >> valName[i]; }
#define INPUT_VECTOR_DOUBLE(valName, N) vector<double> valName(N); for(int i=0; i < N; ++i) { cin >> valName[i]; }

#define OUTPUT(A) cout << (A) << endl;
#define OUTPUT2(A, B) cout << (A) << " " << (B) << endl;
#define OUTPUT3(A, B, C) cout << (A) << " " << (B) << " " << (C) << endl;

#define REP(valName, N) for(int valName = 0; valName < N; ++valName)

vector<string> split(const string& str, char delimiter) {
	vector<string> ret;
	string tmp = "";
	for (auto c : str) {
		if (c != delimiter) {
			tmp.push_back(c);
		} else {
			ret.push_back(tmp);
			tmp = "";
		}
	}
	ret.push_back(tmp);
	return ret;
}

template <typename T> void sortAsc(vector<T>& v) { sort(v.begin(), v.end(), less<T>()); }
template <typename T> void sortDesc(vector<T>& v) { sort(v.begin(), v.end(), greater<T>()); }

template <typename T> void insert(vector<T>& dest, const vector<T>& src) { copy(src.begin(), src.end(), back_inserter(dest)); }

template <long long int MOD> long long int mod_inv(long long int a) {
	long long b = MOD, u = 1, v = 0;
	while (b) {
		long long int t = a / b;
		a -= t * b; swap(a, b);
		u -= t * v; swap(u, v);
	}
	u %= MOD;
	if (u < 0) u += MOD;
	return u;
}

template <long long int MOD> long long int mod_add(long long int a, long long int b) {
	return (a + b) % MOD;
}

template <long long int MOD> long long int mod_sum(long long int a, long long int b) {
	return (a - b) % MOD;
}

template <long long int MOD> long long int mod_mul(long long int a, long long int b) {
	return (a % MOD) * (b % MOD) % MOD;
}

template <long long int MOD> long long int mod_mul(long long int a, long long int b, long long int c) {
	return mod_mul<MOD>(a, mod_mul<MOD>(b, c));
}

template <long long int MOD> long long int mod_div(long long int a, long long int b) {
	return (a % MOD) * mod_inv<MOD>(b) % MOD;
}


//------------------------------------------------------------------------------------------------------------------------------

map< int64_t, int > prime_factor(int64_t n) {
	map< int64_t, int > ret;
	for (int64_t i = 2; i * i <= n; i++) {
		while (n % i == 0) {
			ret[i]++;
			n /= i;
		}
	}
	if (n != 1) ret[n] = 1;
	return ret;
}

int main() {

	// TODO: streamやめる

	cin.tie(0); ios::sync_with_stdio(false);

	INPUT_LLINT(N);

	if (N == 1) { OUTPUT(0); return 0; }

	//auto P = prime_factor(N);

	unsigned long long int n = 1000000000000;

	for (unsigned long long int x = 1; x < sqrtf(N)+1; ++x) {
		if (N % x == 0) {
			unsigned long long int y = N / x;
			if( x + y < n ) n =x+y;
		}
	}

	OUTPUT(n - 2);

	return 0;
}

Measured memory_bytes: 256
#include <iostream>

using namespace std;

int main(int argc, const char * argv[]) {
    int r;
    cin >> r;
    if(r < 1200) {
        cout << "ABC";
    }
    else if(r < 2800) {
        cout << "ARC";
    }
    else {
        cout << "AGC";
    }
    cout << endl;
}


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

int main()
{
	ios::sync_with_stdio(false);
	cin.tie(0);
	string a, s;
	cin >> a;
	for (int i = 0; i < a.size(); i++)
	{
		if (a[i] == 'B')
		{
			if (!s.empty())
				s.pop_back();

		}
		else
			s.push_back(a[i]);
	}
	cout << s << endl;
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
typedef long long LL;
#define SORT(c) sort((c).begin(),(c).end())

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

using namespace std;
int charas[256];
int main(void)
{
  char c;
  for(int i=0;i<256;++i) charas[i]=0;
  while(cin >> c) charas[c]++;
  int answer=0;
  for(int i=0;i<250;++i){
    if(charas[i]&&charas[i+1]&&charas[i+2]){
      answer+=3;
      for(int j=i;j<250;++j){
	if(charas[j]==0) break;
	charas[j]--;
      }
      i=0;
    }
  }
  for(int i=0;i<256;++i) answer+=charas[i];
  cout << answer << endl;
  return 0;
}

Measured memory_bytes: 1140
a=[list(map(int, input().split())) for _ in range(3)]
n=int(input())
b=[int(input()) for _ in range(n)]

for i in range(3):
    for j in range(3):
        if a[i][j] in b:
            a[i][j]=0
flag=False
for i in range(3):
    if a[i][0]==a[i][1]==a[i][2]==0:
        flag=True
for i in range(3):
    if a[0][i]==a[1][i]==a[2][i]==0:
        flag=True
if a[0][0]==a[1][1]==a[2][2]==0:
    flag=True
if a[0][2]==a[1][1]==a[2][0]==0:
    flag=True
print('Yes' if flag else 'No')

Measured memory_bytes: 3064
N = int(input())
D,X = map(int,input().split())
An = [int(input()) for i in range(N)]
ans = X
for n in range(1,N+1):
    ans+=1
    num = An[n-1]
    for i in range(1,100001):
        if num*i+1<=D:
            ans+=1
        else:
            break
print(ans)

Measured memory_bytes: 3064