akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>

using namespace std;

int n,ans;
long long int d;

int main()
{
	scanf("%d%lld",&n,&d);
	d=d*d;
	for(int i=1;i<=n;i++)
	{
		long long int x,y;
		scanf("%lld%lld",&x,&y);
		long long int dis=x*x+y*y;
		if(dis<=d)
		    ans++;
	}
	printf("%d\n",ans);
	return 0;
}

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

using namespace std;

typedef unsigned long long ull;
typedef long long ll;

int main(){
	int n;
	cin >> n;
	for(int i=n; i<100010; i++){
		bool flg=true;
		for(int j=2; j*j<=i; j++){
			if(i%j==0) flg=false;
		}
		if(flg){
			cout << i << endl;
			return 0;
		}
	}
	return 0;
}

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

struct Point {
  double x,y;
};
void koch(int n,Point a,Point b) {
  if (n==0) {
    return ;
  }
  Point s,t,u;
  double th=M_PI*60/180.0;
  s.x=(2.0*a.x+1.0*b.x)/3.0;
  s.y=(2.0*a.y+1.0*b.y)/3.0;
  t.x=(1.0*a.x+2.0*b.x)/3.0;
  t.y=(1.0*a.y+2.0*b.y)/3.0;
  u.x=(t.x-s.x)*cos(th)-(t.y-s.y)*sin(th)+s.x;
  u.y=(t.x-s.x)*sin(th)+(t.y-s.y)*cos(th)+s.y;
  koch(n-1,a,s);
  printf("%.8f %.8f\n",s.x,s.y);
  koch(n-1,s,u);
  printf("%.8f %.8f\n",u.x,u.y);
  koch(n-1,u,t);
  printf("%.8f %.8f\n",t.x,t.y);
  koch(n-1,t,b);
}
int main() {
  int n;
  cin>>n;
  Point a,b;
  a.x=0; a.y=0; b.x=100; b.y=0;
  printf("%.8f %.8f\n",a.x,a.y);
  koch(n,a,b);
  printf("%.8f %.8f\n",b.x,b.y);
  return 0;
}



Measured memory_bytes: 3136
#include <bits/stdc++.h>
using namespace std;
#define GET_MACRO(_1, _2, _3, NAME, ...) NAME
#define _repl(i,a,b) for(int i=(int)(a);i<(int)(b);i++)
#define _rep(i,n) _repl(i,0,n)
#define rep(...) GET_MACRO(__VA_ARGS__, _repl, _rep)(__VA_ARGS__)
#define mp(a,b) make_pair((a),(b))
#define pb(a) push_back((a))
#define all(x) (x).begin(),(x).end()
#define uniq(x) sort(all(x)),(x).erase(unique(all(x)),end(x))
#define fi first
#define se second
#define dbg(...) _dbg(#__VA_ARGS__, __VA_ARGS__)
void _dbg(string){cout<<endl;}
template<class H,class... T> void _dbg(string s,H h,T... t){int l=s.find(',');cout<<s.substr(0,l)<<" = "<<h<<", ";_dbg(s.substr(l+1),t...);}
template<class T,class U> ostream& operator<<(ostream &o, const pair<T,U> &p){o<<"("<<p.fi<<","<<p.se<<")";return o;}
template<class T> ostream& operator<<(ostream &o, const vector<T> &v){o<<"[";for(T t:v){o<<t<<",";}o<<"]";return o;}

#define INF 1120000000

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

  vector<int> v;
  for(long k=1; k*k<=n; k++) if(n%k==0){
    v.pb(k);
    v.pb(n/k);
  }
  uniq(v);
  reverse(all(v));

  for(auto k : v){//dbg(k);
    bool ok = true;
    rep(i,n/k){
      rep(j,k){
        if(vec[j*(n/k)+i]!=vec[i]){
          ok=false;
          i=n;j=n;
        }
      }
    }
    if(ok){
      cout << k << endl;
      return 0;
    }
  }

  return 0;
}

Measured memory_bytes: 3608
h,w = map(int, input().split())
m = []
for y in range(h):
  s = input()
  l = []
  for i in s:
    if i == '#':
      l.append(1)
    else:
      l.append(0)
  m.append(l)

for y in range(h):
  s = ''
  for x in range(w):
    bomb = 0
    for i,j in ((-1,-1),(-1,0),(-1,1),(0,-1),(0,1),(1,-1),(1,0),(1,1)):
      if y+j < 0 or x+i < 0 or x+i >= w or y+j >= h:
        continue
      if m[y+j][x+i] == 1:
        bomb += 1
    if m[y][x] == 1:
      bomb = '#'
    s += str(bomb)
  print(s)
    

Measured memory_bytes: 3064
S = input()


def check_mm(x):
    return (0 < int(x) and int(x) <= 12)


if check_mm(S[:2]) and check_mm(S[2:]):
    print("AMBIGUOUS")
elif check_mm(S[:2]) == False and check_mm(S[2:]):
    print("YYMM")
elif check_mm(S[:2]) and check_mm(S[2:]) == False:
    print("MMYY")
else:
    print("NA")


Measured memory_bytes: 3060
N, W = map(int, input().split())
Weight = [0]
Value = [0]

for i in range(N):
    w, v = map(int, input().split())
    Weight.append(w)
    Value.append(v)

DP = [[0]*(W+1) for i in range(N+1)]
for n in range(1, N + 1):
    for wei in range(W+1):
        if Weight[n] > wei:
            DP[n][wei] = DP[n-1][wei]
        else:
            DP[n][wei] = max(DP[n-1][wei], DP[n-1][wei - Weight[n]] + Value[n])
print(DP[N][W])

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

#define pb push_back
#define pf push_front
#define pp pop_back
#define sz(a) (int)(a.size())
#define mp make_pair
#define F first
#define S second
#define next _next
#define prev _prev
#define left _left
#define right _right
#define y1 _y1
#define all(x) x.begin(), x.end()

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;

const int N = (int)1e6 + 123;
const ll INF = (ll)1e18 + 123;
const int inf = (int)1e9 + 123;
const int MOD = (int)1e9 + 7;

void megaRandom() {
	unsigned int FOR;
 	asm("rdtsc" : "=A"(FOR));
  srand(FOR);
}

int n, m, a[311][311];
set<int> st;
int cnt[311], p[311][311];

int main() {
	megaRandom();
	cin >> n >> m;
	for(int i = 1; i <= n; i ++) {
		for(int j = 1; j <= m; j ++) {
			cin >> a[i][j];
			p[i][a[i][j]] = j;
		}
	}
	for(int j = 1; j <= m; j ++) 
		st.insert(j);
	int res = inf;
	while(sz(st) > 0) {
		memset(cnt, 0, sizeof cnt);
		for(int i = 1; i <= n; i ++) {
			int mn = inf, mn_x = -1;
			for(auto v : st) 
				if(p[i][v] < mn)
					mn = p[i][v], mn_x = v;
			cnt[mn_x] ++;		
		}
		int mx = -inf, mx_x = -1;
		for(auto v : st) {
			if(cnt[v] > mx)
				mx = cnt[v], mx_x = v;
		}
		res = min(res, mx);
		st.erase(mx_x);
	}
	cout << res;
	return 0;         
}


Measured memory_bytes: 1024
#define  _CRT_SECURE_NO_WARNINGS
#include<cstdio>
#include<iostream>
#include<cmath>
#include<vector>
using namespace std;

bool ok(vector<int>& v) {
	for (int i = 0; i < v.size() - 1; i++) {
		if (v[i] > v[i + 1]) return false;
	}
	return true;
}

int main() {
	int n; scanf("%d", &n);
	long long ans = 0;
	vector<long long> a, b; a.resize(n+1); b.resize(n);
	for (int i = 0; i < n+1; i++) scanf("%lld", &a[i]);
	for (int i = 0; i < n; i++) scanf("%lld", &b[i]);
	

	for (int i = 0; i < b.size(); i++) {
		//a[i]
		if (a[i] >= b[i]) {
			ans += b[i];
			a[i] -= b[i];
			b[i] = 0;
		}
		else {
			ans += a[i];
			b[i] -= a[i];
			a[i] = 0;
		}

		//a[i+1]
		if (a[i+1] >= b[i]) {
			ans += b[i];
			a[i+1] -= b[i];
			b[i] = 0;
		}
		else {
			ans += a[i+1];
			b[i] -= a[i + 1];
			a[i+1] = 0;
		}
	}
	printf("%lld", ans);
	return 0;
}

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

typedef long long ll;
typedef long double lld;

#define ci(x) cin >> x 
#define pb push_back
#define mp make_pair
#define all(v) v.begin(),v.end()
#define x first
#define y second
#define ub upper_bound
#define lb lower_bound
#define pii pair <int ,int >
#define pll pair <ll ,ll > 
#define vpii vector<pii > v;
#define fore(i, a, b) for (int i=a; i<(b); i++)
#define cs(x) cout<<x<<" "
#define Yes printf("YES\n")
#define No printf("NO\n")
#define cl(x) cout<<x<<endl;
#define boost ios::sync_with_stdio(false);cin.tie(0)
#define SET(arr,val) memset(arr,val,sizeof arr)



int main() {
	string n;
	ci(n);
	fore(i,0,n.size()) {
		if (n[i] == '1')
			n[i] = '9';
		else n[i] = '1';
	}
	cout << n;
}

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

int main(void){
  int n, m, x, fee, cost0 = 0, costN = 0;
  cin >> n >> m >> x;
  for(int i = 0; i < m; i++){
    cin >> fee;
    if(fee > x) costN++;
    else cost0++;
  }
  cout << min(cost0, costN) << endl;
  return 0;
}


Measured memory_bytes: 256
import numpy
N=int(input())
S=list(map(str,input()))
S_modify = [0 if i=="." else 1 for i in S]
count_list = []

sum_list=numpy.cumsum(S_modify)
sum_list_reverse=numpy.cumsum(S_modify[::-1])
for i in range(N):
    count = sum_list[i]+((N-i-1)-sum_list_reverse[N-i-1])
    count_list.append(count)
print(min(count_list))

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

int main(){

  int N;
  cin >> N;
int t =N , c =0;
while (t >0) c += t %10 , t /=10;
if ( N % c ==0){ cout <<" Yes "<< endl;}
else{ cout <<" No "<< endl;
}
}

Measured memory_bytes: 256
use std::io;
use std::cmp;

// read a line(without line feed)
fn read_line() -> String {
    let mut in_str = String::new();
    io::stdin().read_line(&mut in_str).unwrap();
    return in_str.trim().to_string();
}

// read wods on a line
pub fn read_words_in_line() -> Vec<String> {
    let s = read_line();
    return s.split_whitespace().map(|x| x.to_string()).collect::<Vec<String>>()
}

// read type t on a line
pub fn read_t_in_line<T : std::str::FromStr>() -> Vec<T> {
    let mut v : Vec<T> = Vec::new();
    for e in read_words_in_line().iter().map(|x| x.parse::<T>()) {
        if let Ok(r) = e {
            v.push(r);
        }
        else{
            return Vec::new();
        }
    }
    return v;
}

// sort slice
pub fn sort<T : std::cmp::Ord>(slice : &mut [T]) {
    slice.sort();
}
// sort slice by reverse order
pub fn sort_rev<T : std::cmp::Ord>(slice : &mut [T]) {
    slice.sort_by(|x, y| y.cmp(x));
}

pub fn min<T : std::cmp::Ord>(a : T, b : T) -> T{
    return cmp::min(a, b);
}

pub fn max<T : std::cmp::Ord>(a : T, b : T) -> T{
    return cmp::max(a, b);
}

fn check(init : i32, d : i32, x : &Vec<i32>) -> bool {
    for a in x {
        if (a - init).abs() % d != 0 {
            return false;
        }
    }
    return true;
}

fn main() {
    let l = read_t_in_line::<i32>();
    let (_n, x) = (l[0], l[1]);
    let mut city = read_t_in_line::<i32>();
    city.sort();
    
    // (city[0] - x).abs() の約数を全部tryする
    let mut i = 1;
    let mut ans = 1;
    while i * i <= (city[0] - x).abs() {
        if (city[0] - x).abs() % i == 0 {
            let v1 = i;
            let v2 = (city[0] - x).abs() / i;
            if check(x, v1, &city) {
                ans = max(ans, v1);
            }
            if check(x, v2, &city) {
                ans = max(ans, v2);
            }
        }
        i += 1;
    }
    println!("{}", ans);
}


Measured memory_bytes: 10740
/*** author: yuji9511 ***/
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using lpair = pair<ll, ll>;
const ll MOD = 1e9+7;
const ll INF = 1e18;
#define rep(i,m,n) for(ll i=(m);i<(n);i++)
#define rrep(i,m,n) for(ll i=(m);i>=(n);i--)
#define printa(x,n) for(ll i=0;i<n;i++){cout<<(x[i])<<" \n"[i==n-1];};
void print() {}
template <class H,class... T>
void print(H&& h, T&&... t){cout<<h<<" \n"[sizeof...(t)==0];print(forward<T>(t)...);}

void solve(){
    ll N;
    cin >> N;
    ll A[100010];
    rep(i,0,N+1) cin >> A[i];
    ll max_val[100010] = {};
    ll cur = 0;
    rrep(i,N,0){
        cur += A[i];
        max_val[i] = cur;
    }
    ll ans = 0;
    cur = 1;
    bool ok = true;
    rep(i,0,N+1){
        cur = min(cur, max_val[i]);
        ans += cur;
        cur -= A[i];
        if(cur < 0){
            ok = false;
        }
        cur *= 2;
    }
    if(ok){
        print(ans);
    }else{
        print(-1);
    }

    

}

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

Measured memory_bytes: 5220
# = map(int, input().split())
n = int(input())
# = input()
a = list(map(int, input().split()))

a.sort()
while 1:
	lst = []
	lst.append(a[0])
	for i in range(1, len(a)):
		if a[i] % a[0] != 0:
			lst.append(a[i]%a[0])
	if len(lst) == 1:
		break
	a = []
	a = lst
	a.sort()
print(lst[0])


Measured memory_bytes: 14252
using System;

class Program
{
    static void Main(string[] args)
    {
        var nm = Console.ReadLine().Split(' ');
        var n = int.Parse(nm[0]);
        var m = int.Parse(nm[1]);

        if (m % n == 0) Console.WriteLine(m + n);
        else Console.WriteLine(m - n);
    }
}

Measured memory_bytes: 11092
#include<bits/stdc++.h>
using namespace std;
#define mod 1000000007
#define ll long long int
#define N 200100
#define pii pair<int,int>
#define rep(i,k,n) for(int i=k;i<n;i++)
#define vi vector<int>
#define inf 1e9
ll gcd(ll a,ll b)
{
	if(a==0)
	{
		return b;
	}
	return gcd(b%a,a);
}
 
 
ll lcm(ll a,ll b)
{
	ll pro=a*b;
	ll ans=gcd(a,b);
	pro=pro/ans;
	return pro;
}
void solve(){
	int a,b;
	cin>>a>>b;
	ll ans=lcm(a,b);
	cout<<ans<<endl;
}

int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	solve();
}

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

// 深さ優先探索
vector<bool> seen;
void dfs(const Graph &G,int v,int before,int step,vector<int> &Array) {
		Array[v]=step;
    for(int i=0;i<G[v].size();i++)
			if(G[v][i]!=before) dfs(G,G[v][i],v,step+1,Array);
}

int main()
{
	int a,b;
	int N;
	int ans=0;
	cin>>N;
	vector<int> Fennec(N+10);
	vector<int> Sunuke(N+10);
	Graph G(N+10);
	for(int i=0;i<N-1;i++){
		cin>>a>>b;
		a--,b--;
		G[a].push_back(b);
		G[b].push_back(a);
	}
	dfs(G,0,-1,0,Fennec);
	dfs(G,N-1,-1,0,Sunuke);

//	for(int i=0;i<N;i++) cout<<Fennec[i]<<" ";
//	cout<<endl;
//	for(int i=0;i<N;i++) cout<<Sunuke[i]<<" ";
	for(int i=0;i<N;i++) ans+=(Fennec[i]<=Sunuke[i])?1:-1;
	printf("%s",(ans>0)?"Fennec":"Snuke");
}


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

int main() {
  int N;
  int mem = 0;
  cin >> N;
  for (int i = 0; i < N; i++) {
    int l, r;
    cin >> l >> r;
    mem = mem + r - l + 1;
  }
  cout << mem << endl;
}

Measured memory_bytes: 256
#[allow(unused_imports)]
use std::cmp;
use std::io::Write;

// Input macro from https://qiita.com/tanakh/items/0ba42c7ca36cd29d0ac8
macro_rules! input {
  (source = $s:expr, $($r:tt)*) => {
    let mut iter = $s.split_whitespace();
    input_inner!{iter, $($r)*}
  };
  ($($r:tt)*) => {
    let s = {
      use std::io::Read;
      let mut s = String::new();
      std::io::stdin().read_to_string(&mut s).unwrap();
      s
    };
    let mut iter = s.split_whitespace();
    input_inner!{iter, $($r)*}
  };
}

macro_rules! input_inner {
  ($iter:expr) => {};
  ($iter:expr, ) => {};

  ($iter:expr, $var:ident : $t:tt $($r:tt)*) => {
    let $var = read_value!($iter, $t);
    input_inner!{$iter $($r)*}
  };
}

macro_rules! read_value {
  ($iter:expr, ( $($t:tt),* )) => {
    ( $(read_value!($iter, $t)),* )
  };

  ($iter:expr, [ $t:tt ; $len:expr ]) => {
    (0..$len).map(|_| read_value!($iter, $t)).collect::<Vec<_>>()
  };

  ($iter:expr, chars) => {
    read_value!($iter, String).chars().collect::<Vec<char>>()
  };

  ($iter:expr, usize1) => {
    read_value!($iter, usize) - 1
  };

  ($iter:expr, [ $t:tt ]) => {{
    let len = read_value!($iter, usize);
    (0..len).map(|_| read_value!($iter, $t)).collect::<Vec<_>>()
  }};

  ($iter:expr, $t:ty) => {
    $iter.next().unwrap().parse::<$t>().expect("Parse error")
  };
}

fn main() {
  let out = std::io::stdout();
  let mut out = std::io::BufWriter::new(out.lock());
  macro_rules! puts {
    ($($format:tt)*) => (write!(out,$($format)*).unwrap());
  }
  input! {
    _n: usize,
    s: String,
  }

  puts!("{}\n", s.matches("ABC").count());
}


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

int main() {
  int A = 0;
  int N;
  cin >> N;
  vector<int> vec(N);
  for (int i = 0; i < N; i++) {
  cin >> vec.at(i);
  }
   for (int j=0; j < N-1; j++){
     for (int k = j; k < N-1; k++){
       A += vec.at(j)*vec.at(k+1);
     }
   }
     cout << A << endl;
}


Measured memory_bytes: 3608
#include<bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(int)n;i++)
#define all(c) (c).begin(),(c).end()
#define pb push_back
#define dbg(...) do{cerr<<__LINE__<<": ";dbgprint(#__VA_ARGS__, __VA_ARGS__);}while(0);

using namespace std;

namespace std{template<class S,class T>struct hash<pair<S,T>>{size_t operator()(const pair<S,T>&p)const{return ((size_t)1e9+7)*hash<S>()(p.first)+hash<T>()(p.second);}};template<class T>struct hash<vector<T>>{size_t operator()(const vector<T> &v)const{size_t h=0;for(auto i : v)h=h*((size_t)1e9+7)+hash<T>()(i)+1;return h;}};}
template<class T>ostream& operator<<(ostream &os, const vector<T> &v){os<<"[ ";rep(i,v.size())os<<v[i]<<(i==v.size()-1?" ]":", ");return os;}template<class T>ostream& operator<<(ostream &os,const set<T> &v){os<<"{ "; for(const auto &i:v)os<<i<<", ";return os<<"}";}
template<class T,class U>ostream& operator<<(ostream &os,const map<T,U> &v){os<<"{";for(const auto &i:v)os<<" "<<i.first<<": "<<i.second<<",";return os<<"}";}template<class T,class U>ostream& operator<<(ostream &os,const pair<T,U> &p){return os<<"("<<p.first<<", "<<p.second<<")";}
void dbgprint(const string &fmt){cerr<<endl;}template<class H,class... T>void dbgprint(const string &fmt,const H &h,const T&... r){cerr<<fmt.substr(0,fmt.find(","))<<"= "<<h<<" ";dbgprint(fmt.substr(fmt.find(",")+1),r...);}
typedef long long ll;typedef vector<int> vi;typedef pair<int,int> pi;const int inf = (int)1e9;const double INF = 1e12, EPS = 1e-9;

int n, K;
int cnt[2010][2010];
int query(int y, int x, int Y, int X){
	return cnt[Y][X] - cnt[y][X] - cnt[Y][x] + cnt[y][x];
}
int calc(int y, int x, int Y, int X){
	assert(y != Y && x != X);
	//dbg(y, x, Y, X);
	if(Y > 2 * K) Y -= 2 * K;
	if(X > 2 * K) X -= 2 * K;
	if(y > Y) return calc(y, x, 2 * K, X) + calc(0, x, Y, X);
	if(x > X) return calc(y, x, Y, 2 * K) + calc(y, 0, Y, X);
	return query(y, x, Y, X);
}

int main(){
	cin.tie(0); cin.sync_with_stdio(0);
	cin >> n >> K;
	rep(i, n){
		int x, y; char c; cin >> x >> y >> c;
		if(c == 'W') x += K;
		x %= 2 * K; y %= 2 * K;
		//dbg(x, y);
		cnt[y + 1][x + 1]++;
	}
	rep(i, 2009) rep(j, 2009) cnt[i + 1][j + 1] += cnt[i + 1][j] + cnt[i][j + 1] - cnt[i][j];
	
	
	//rep(i, 10) rep(j, 10) cerr<<query(i, j, i + 1, j + 1)<<(j==9?"\n":" ");
	
	int ans = 0;
	rep(i, K) rep(j, K){
		int num = calc(i, j, i + K, j + K) + calc(i + K, j + K, i + 2 * K, j + 2 * K);
		ans = max(ans, num);
		ans = max(ans, n - num);
	}
	cout << ans << endl;
	
	return 0;
}

Measured memory_bytes: 16000
/*
For Bantako San
By shyyhs.

Using hash to insert and search for a perticular number.
Every insert and search is O(1) ideally.
*/

#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<cmath>
#include<cstring>
#include<string>
using namespace std;
#define ll long long
//#define Hsize 100009
#define Hsize (1<<17)
#define MAXN 210001 
ll sumZ=0; //sum from the beginning
int Ai; //This is Ai in the problem, we use it only once so array is not necessary.
int N; //N in the problem

struct T
{
    ll number,times;
    T* next;
}hashBucket[MAXN];
int top=0;
int hashIndex[Hsize];


//x->hash(x)
inline int hashFunc(ll x)
{
    return (x&(0x0001FFFF));
}

//add the current sumZ to the hash table
inline void addToHash(ll sumZ)
{
    int HsumZ;
    T *index, *beginP;
    HsumZ = hashFunc(sumZ);
    for (beginP=index=&hashBucket[hashIndex[HsumZ]]; (index->times>0); index=index->next)
        if (index->number==sumZ)
        {
            index->times++;
            return;
        }
    top++;
    hashIndex[HsumZ]=top;
    index=&hashBucket[top];
    index->number = sumZ;
    index->times = 1;
    index->next = beginP;
}

void init()
{
    scanf("%d",&N);
    addToHash(0);
    for (int i=0; i<N; ++i)
    {
        scanf("%d",&Ai);
        sumZ=sumZ+Ai;
        addToHash(sumZ);
    }
}

void work()
{
    ll answer=0;
    for (int i=1; i<=top; ++i)
    if (hashBucket[i].times>1)
        answer=answer+(((hashBucket[i].times)*(hashBucket[i].times-1))>>1) ;
    cout<<answer<<endl;
}
    
int main()
{
    init();
    work();
    return 0;
}


Measured memory_bytes: 5504
#include <iostream>
#include <string>
#include <algorithm>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <vector>
#include <stack>
#include <queue>
#include <utility>
#include <map>
#include <functional>
typedef long long ll;
using namespace std;
const int MOD = 1000000007;
int main(){
    int n;
    cin >> n;
    map<int,int> mp;
    for(int i = 0;i < n;i++){
        int a;
        cin >> a;
        mp[a]++;
    }

    int ans = 0;

    for(auto p:mp){
        if(p.second % 2 == 1)ans++;
    }
    cout << ans << endl;
}


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

#define N 55

using namespace std;

int n,m;
char t[N][N];

template<typename Drake>
void read(Drake &x){
	x=0;char ch=getchar();bool f=1;
	while(!isdigit(ch)){
		if(ch=='-')f^=1;
		ch=getchar();
	}
	while(isdigit(ch)){
		x=(x<<1)+(x<<3)+(ch^48);
		ch=getchar();
	}
	x*=(2*f-1);
}

template<typename Drake>
void write(Drake x){
	if(x<0){x=-x;putchar('-');}
	if(x>9)write(x/10);
	putchar(x%10+'0');
}

template<typename Drake>
void writeln(Drake x){
	write(x);
	puts("");
}

void init(){
	char ch;
	read(n);read(m);
	for(register int i=0;i<=n+1;i++){
		for(register int j=0;j<=m+1;j++)
		t[i][j]='.';
	}
	for(register int i=1;i<=n;i++){
		for(register int j=1;j<=m;j++){
			t[i][j]=getchar();
		}
		ch=getchar();
	}
}

bool judge(int i,int j){
	if(t[i-1][j]=='#')
	return true;
	if(t[i+1][j]=='#')
	return true;
	if(t[i][j-1]=='#')
	return true;
	if(t[i][j+1]=='#')
	return true;
	return false;
}

int main(){
	init();
	bool check=true;
	for(register int i=1;i<=n;i++){
		for(register int j=1;j<=m;j++)
		if(t[i][j]=='#'&&!judge(i,j))
		check=false;
	}
	if(check)
	puts("Yes");
	else puts("No");
	return 0;
}

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

int main(int argc, char const *argv[])
{
    string S;
    cin >> S;
    long t;
    long counter = 0;
    long plus = 1;
    vector<int> vec(S.size() + 1, 0);

    for (int i = 0; i < S.size(); i++)
    {
        if (vec.at(i) == 1)
        {
            continue;
        }
        t = 0;
        plus = 1;
        for (int j = i; j < S.size(); j++)
        {
            t += (long)(S[j] - '0');
            t %= 2019;
            if (t == 0)
            {
                counter += plus;
                vec.at(j + 1) = 1;
                plus++;
            }
            t *= 10;
        }
    }

    cout << counter << endl;
    return 0;
}


Measured memory_bytes: 4368
import java.util.*;

public class Main {
    public static void main(String[] args) {
        Scanner s = new Scanner(System.in);
        int n = s.nextInt();
        List<Double> l = new ArrayList<>();
        for (int i = 0; i < n; i++) {
            l.add(s.nextDouble());
        }
        Collections.sort(l);
        double ch = 0;
        double ans = 0;
        for (double i : l) {
            if (ans == 0) {
                ans = i;
            }
            ans=(ans+i)/2;
        }
        System.out.print(ans);
    }
}

Measured memory_bytes: 24532
import java.util.*;
public class Main {
    public static void main(String[] args) throws Exception {
        // Your code here!
        Scanner sc = new Scanner(System.in);
        int a = sc.nextInt();
        int b = sc.nextInt();
        int x = sc.nextInt();
       
       if(a > x || a + b < x){
           System.out.println("NO");
       }else{
           System.out.println("YES");
       }
       
    }
}


Measured memory_bytes: 21844
from collections import defaultdict
N,X=map(int,input().split())
S=[int(i) for i in input().split()]
S=sorted(S,reverse=True)
mod=10**9+7
P=[1]*(N+1)#1/i
for i in range(1,N+1):
    P[i]=pow(i,mod-2,mod)
#print(P)
dd=defaultdict(int)
dd[X]=1
for i in range(N):
    ndd=defaultdict(int)
    for x,p in dd.items():
        ndd[x]+=((1-P[N-i])*p)
        ndd[x]%=mod
        ndd[x%S[i]]+=(P[N-i]*p)
        ndd[x%S[i]]%=mod
    dd=ndd
    #print(dd)
t=1
table=[1]*(N+3)
for i in range(1,N+3):
    t*=i
    t%=mod
    table[i]=t
ans=0
for x,p in dd.items():
    ans+=(x*p*table[N])%mod
    ans%=mod
print(ans)

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

const int INF = 1e9;
const int MOD = 1e9+7;
const ll LINF = 1e18;

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n) for(int i=0;i<(n);++i)
#define REPR(i,n) for(int i=n;i>=0;i--)
#define ALL(v) (v.begin(),v.end())
#define COUT(x) cout<<(x)<<"\n"

int main(){
    int n;
    cin >> n;
    string t;
    vector<string>map1;
    REP(i,n){
        cin >> t;
        map1.push_back(t);
    }
    int count = 0; 
    REP(i,n){
        if(map1[i]=="AC"){
            count++;
        }
    }
    cout << "AC" << " " << "x " << count << endl; 
    count = 0; 
    REP(i,n){
        if(map1[i]=="WA"){
            count++;
        }
    }
    cout << "WA" << " " << "x " << count << endl; 
    count = 0; 
    REP(i,n){
        if(map1[i]=="TLE"){
            count++;
        }
    }
    cout << "TLE" << " " << "x " << count << endl; 
    count = 0; 
    REP(i,n){
        if(map1[i]=="RE"){
            count++;
        }
    }
    cout << "RE" << " " << "x " << count << endl; 
    
}

Measured memory_bytes: 7376
#include <iostream>

using namespace std;

int main() {

	int Array[32] = { 1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51 };
	int K;

	cin >> K;


	cout << Array[K-1] << endl;
	
}

Measured memory_bytes: 256
#include<iostream>
#include<set>
#include<string>
using namespace std;
int main()
{
	string ss;
	cin>>ss;
	bool cc=false;
	int brojac=ss.size();
int s1=0,t1=0;
bool imatt=true;

	for(int i=0;i<ss.size();i++)
	{
		if(ss[i]=='S'&&imatt)
		{
			brojac-=2*min(s1,t1);
			if(t1==min(s1,t1))
			s1-=t1,s1++,t1=0;
			else
				s1=1,t1=0;
			cc=true;
			imatt=false;
		}
		else if(ss[i]=='S'&&cc)
			s1++;
		else if(ss[i]=='T'&&cc){
			t1++;
			imatt=true;
		}
	}
	brojac-=2*min(s1,t1);
	cout<<brojac<<endl;
	return 0;
}

Measured memory_bytes: 640
import java.util.Scanner;

public class Main {
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		int a = sc.nextInt();
      int b = sc.nextInt();
      int c = sc.nextInt();
      int d = sc.nextInt();
		sc.close();
		if(a+b > c+d){
          System.out.println("Left");
        }else if(a+b == c+d){
          System.out.println("Balanced");
        }else{
          System.out.println("Right");
        }
	}
}

Measured memory_bytes: 21844
package main

import "fmt"

func getMax(a, b int) int {
	if a < b {
		return b
	} else {
		return a
	}
}

var N int
var a []int
var b []int
var c []int

var values [][]int

func getValues(i int) (int, int, int) {
	value1 := getMax(values[i-1][1]+a[i], values[i-1][2]+a[i])
	value2 := getMax(values[i-1][0]+b[i], values[i-1][2]+b[i])
	value3 := getMax(values[i-1][0]+c[i], values[i-1][1]+c[i])
	return value1, value2, value3
}

func main() {
	fmt.Scan(&N)
	a = make([]int, N)
	b = make([]int, N)
	c = make([]int, N)
	var tmpA, tmpB, tmpC int
	for i := 0; i < N; i++ {
		fmt.Scan(&tmpA, &tmpB, &tmpC)
		a[i] = tmpA
		b[i] = tmpB
		c[i] = tmpC
	}
	values = make([][]int, N)
	for i := 0; i < N; i++ {
		values[i] = make([]int, 3)
	}

	values[0][0] = a[0]
	values[0][1] = b[0]
	values[0][2] = c[0]
	for i := 1; i < N; i++ {
		values[i][0], values[i][1], values[i][2] = getValues(i)
	}
	max := 0
	for i := 0; i < 3; i++ {
		if max < values[N-1][i] {
			max = values[N-1][i]
		}
	}
	fmt.Println(max)
}


Measured memory_bytes: 8704
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		try (Scanner scanner = new Scanner(System.in)) {
			int n = scanner.nextInt();
			int k = scanner.nextInt();
			System.out.println(k * ((long) Math.pow(k - 1, n - 1)));
		}
	}
}


Measured memory_bytes: 21844
#include <iostream>
#include <string>
#include <algorithm>

using namespace std;

int main() {
	string s;
	cin >> s;
	string s2 = s;
	reverse(s2.begin(), s2.end());
	if (s == s2) {
		cout << "Yes" << endl;
	}
	else {
		cout << "No" << endl;
	}
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int A, B, ans;
  bool judge = false;
  cin >> A >> B;
  for (int i=0; i<1000000001; i++){
    if(abs(A-i) == abs(B-i)){
      ans = i;
      judge = true;
      break;
    }
  }
  if(judge)
    cout << ans << endl;
  else
    cout << "IMPOSSIBLE" << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(k,i,n) for(ll i=k;i<n;++i)
int main(void){
    ll x,y,a,b,c;
    cin>>x>>y>>a>>b>>c;
    vector<ll>r(x+y+c);
    vector<ll>p(a),q(b);
    rep(0,i,a){
        cin>>p[i];
    }
    rep(0,i,b){
        cin>>q[i];
    }
    sort(p.rbegin(),p.rend());
    sort(q.rbegin(),q.rend());
    rep(0,i,x){
        r[i]=p[i];
    }
    rep(0,i,y){
        r[x+i]=q[i];
    }
    rep(0,i,c){
        cin>>r[x+y+i];
    }
    sort(r.rbegin(),r.rend());
    ll ans=0;
    rep(0,i,x+y){
        ans+=r[i];
    }
    cout<<ans;
}

Measured memory_bytes: 3968
#include <stdio.h>
char str[201];
char hyou[30] = "abcdefghijklmnopqrstuvwxyz.?! ";
int main() {
	int i, flag;
	while(scanf("%s", str) != EOF) {
		flag = 0;
		for(i = 0; flag == 0 && str[2 * i] != 0; ++ i) {
			if('1' <= str[2 * i] && str[2 * i] <= '6' && '1' <= str[2 * i + 1] && str[2 * i + 1] <= '5') str[i] = hyou[5 * (str[2 * i] - '1') + (str[2 * i + 1] - '1')];
			else flag = 1;
		}
		str[i] = 0;
		if(flag == 1) printf("NA\n");
		else printf("%s\n", str);
	}
	return 0;
}

Measured memory_bytes: 524
import sys
sys.setrecursionlimit(1000000)
input = sys.stdin.readline
from bisect import *
from collections import *
from heapq import *
INF = 500000
mod = 10**9+7

S = input()
if 'A' in S and 'B' in S:
    print('Yes')
else:
    print('No')


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

int main(){
  int N;
  std::cin >> N;
  int posP[200010] = {0};

  for (int i=1;i<=N;i++) {
    int tmp;
    std::cin >> tmp;
    posP[tmp] = i;
  }
/*
  std::cout << '\n';
  for (int i=1;i<=N;i++) std::cout << posP[i] << '\n';
  std::cout << '\n';
*/
  int cnt = 0;
  int maxCnt = 0;
  for (int i=1;i<=N;i++) {
    if (posP[i-1]>posP[i]) {
      maxCnt = std::max(maxCnt,cnt);
      cnt=0;
    }
    cnt++;
  }

  maxCnt = std::max(maxCnt,cnt);
  std::cout << N-maxCnt << '\n';

}


Measured memory_bytes: 1024
#include <iostream>

using namespace std;

int main (){
  int M, N, A[1000];
  int sum=0;
  int count=0;
  cin >> N >> M;
  for (int i=0; i<N; i++) {
    cin >> A[i];
    sum += A[i];
  }
  for (int i=0; i<N; i++) {
    if (A[i] * 4 * M >= sum)
      count ++;
  }
  cout << (count>=M?"Yes":"No") << endl;
}

Measured memory_bytes: 256
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
    ($($r:tt)*) => {
        let s = {
            use std::io::Read;
            let mut s = String::new();
            std::io::stdin().read_to_string(&mut s).unwrap();
            s
        };
        let mut iter = s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
}

macro_rules! input_inner {
    ($iter:expr) => {};
    ($iter:expr, ) => {};
    ($iter:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($iter, $t);
        input_inner!{$iter $($r)*}
    };
}

macro_rules! read_value {
    ($iter:expr, ( $($t:tt),* )) => {
        ( $(read_value!($iter, $t)),* )
    };
    ($iter:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($iter, $t)).collect::<Vec<_>>()
    };
    ($iter:expr, chars) => {
        read_value!($iter, String).chars().collect::<Vec<char>>()
    };
    ($iter:expr, usize1) => {
        read_value!($iter, usize) - 1
    };
    ($iter:expr, $t:ty) => {
        $iter.next().unwrap().parse::<$t>().expect("Parse error")
    };
}

fn main() {
    input! {
        n: i32,
    }
    let mut n = n;
    let mut res = false;
    while n > 0 {
        let m = n % 10;
        if m == 7 {
            res = true;
            break;
        }
        n /= 10;
    }
    if res {
        println!("Yes");
    } else {
        println!("No");
    }
}


Measured memory_bytes: 2128
//#include <bits/stdc++.h>
#include <unordered_set>
#include <map>
#include <string>
#include <vector>
#include <algorithm>
#include <utility>
#include <iostream>
#include <istream>
#include <ostream>
#include <sstream>

using namespace std;

/* macros */
#define all(v)			((v).begin()), ((v).end())
#define SIZE(v)			((int)((v).size()))
#define LOG(x)			log((double)x)
#define TOLOWER(x)          transform(all(x),x.begin(),::tolower)
#define TOUPPER(x)          transform(all(x),x.begin(),::toupper)
#define ROUND(x,m)			(round((double)x/m)*m)
#define DIGITS(x)			(floor(log10((double)x))+1)
#define READSTR(x)			getline(cin,x)
#define sort_g(a,b)              sort(a, b, greater<int>());
#define IOS() ios_base::sync_with_stdio(0);cin.tie(NULL);
#define REP(i, n) for (int i = 0; i < n; i++)
#define FILE_INPUT() 	freopen( "input.txt", "r", stdin)
#define FILE_OUTPUT()   freopen( "output.txt", "w", stdout)

/*typedefs*/
typedef long long ll;

/*functions*/
bool myCmp(pair<int,int> &p1 , pair<int,int>&p2)
{
    return p1.first > p2.first;
}
unsigned long long
choose(unsigned long long n, unsigned long long k) {
    if (k > n) {
        return 0;
    }
    unsigned long long r = 1;
    for (unsigned long long d = 1; d <= k; ++d) {
        r *= n--;
        r /= d;
    }
    return r;
}
int toInt(string str) {
    int num;
    istringstream iss(str); //put string in input stream
    iss>>num; return num; //read from stream as integer
}

template <class T> string toStr(T par) {
    ostringstream oss;  //output stream string
    oss<<par;    //write par to the stream
    return oss.str(); //return string of output
}

const int MAXN = 10e5;
int arr[MAXN]= {0};
int ans[MAXN] = {0};
int main() {
    IOS();
    int n;
    cin>>n;
    REP(i,n)
    {
        cin>>arr[i];
    }

    //draw and solve 2*x 2*y ..
    //x+y =
    //y+z =
    //z+w =
    //w+v =
    //v+x

    // + - + = 2*first
    // 2 2 4
    int sgn = 1;
    ll acc =0;
    for(int i =0 ; i < n ; ++i)
    {
        acc += sgn*arr[i];
        sgn *=-1;
    }
    ans[0] = acc;
    for(int i = 1 ; i < n ; i++)
    {
        ans[i] = (arr[i-1] -ans[i-1]/2)*2;
    }
    REP(i,n)
    {
        cout<<ans[i]<<" ";
    }
    cout<<std::endl;

    return 0;
}


Measured memory_bytes: 5760
// WARNING: Add compile option "-std=c++11" for C++11 compile.

#include <iostream>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
#include <algorithm>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <regex>
#include <numeric>
using namespace std;

// Macro
#define REP(i, N) for(int i=0; i<(int)N; i++)
#define REPR(i, N) for(int i=(int)N-1; i>=0; i--)
#define mp make_pair
#define pb push_back

// Type
typedef long long ll;
typedef pair<int, int> Pi;
typedef pair<ll, ll> Pll;

// Constants
const ll MOD = 1000000007;

/**
  型に合わせたINFを返す
  int: 214,748,364 (2.14 * 1e8)
  ll : 922,337,203,685,477,580 (9.22 * 1e17)
*/
template <typename T>
T getINF() {
  // NOTE: INF同士を足してもオーバーフロー起こさないように、10で割っている
  return numeric_limits<T>::max() / 10;
}

// Floating
const double EPS = 1e-11;
#define EQ0(x) (abs(x) < EPS)
#define EQ(x, y) (abs(a-b) < EPS)

char change(char c) {
  if(c == 'A') return 'a';
  if(c == 'B') return 'b';
  if(c == 'C') return 'c';
  return '_';
}

int main() {
  int n, k;
  string s;
  cin >> n >> k >> s;

  s[k-1] = change(s[k-1]);
  cout << s << endl;

  return 0;
}

Measured memory_bytes: 256
//参考：http://ehafib.hatenablog.com/entry/2015/12/23/164517
//インクルード
#include<algorithm>//sort,二分探索,など
#include<bitset>//固定長bit集合
#include<cmath>//pow,logなど
#include<complex>//複素数
#include<deque>//両端アクセスのキュー
#include<functional>//sortのgreater
#include<iomanip>//setprecision(浮動小数点の出力の誤差)
#include<iostream>//入出力
#include<map>//map(辞書)
#include<numeric>//iota(整数列の生成),gcdとlcm(c++17)
#include<queue>//キュー
#include<set>//集合
#include<stack>//スタック
#include<string>//文字列
#include<unordered_map>//イテレータあるけど順序保持しないmap
#include<unordered_set>//イテレータあるけど順序保持しないset
#include<utility>//pair
#include<vector>//可変長配列

using namespace std;
typedef long long ll;

//マクロ
#define REP(i,n) for(ll i=0;i<(ll)(n);i++)
#define REPD(i,n) for(ll i=(ll)(n)-1;i>=0;i--)
#define FOR(i,a,b) for(ll i=(a);i<=(b);i++)
#define FORD(i,a,b) for(ll i=(a);i>=(b);i--)
#define ALL(x) (x).begin(),(x).end() //sortなどの引数を省略したい
#define SIZE(x) ((ll)(x).size()) //sizeをsize_tからllに直しておく
#define MAX(x) *max_element(ALL(x))
#define INF 1000000000000
#define MOD 10000007
#define PB push_back
#define MP make_pair
#define F first
#define S second

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

  int n, m, ans = 0;
	cin >> n >> m;

  ans += n * (n-1) / 2;
  ans += m * (m-1) / 2;
	cout << ans << "\n";
}


Measured memory_bytes: 256
#include <iostream>

int main(int argc, char const* argv[])
{
    std::string in_str;
    std::cin >> in_str;

    bool found_C = false;
    for(int i=0; i<in_str.length(); ++i)
    {
        if(i == 0)
        {
            if(in_str[i] != 'A')
            {
                std::cout << "WA" << std::endl;
                return 0;
            }
        }
        else if( i >= 2 && i <= in_str.length() - 2)
        {
            if(in_str[i] == 'C')
            {
                if(!found_C)
                {
                    found_C = true;
                }
                else
                {
                    std::cout << "WA" << std::endl;
                    return 0;
                }
            }
        }
        else
        {
            auto c = in_str[i];

            if(c >= 'a' && c <= 'z')
            {
            }
            else
            {
                std::cout << "WA" << std::endl;
                return 0;
            }

        }
    }
    if(found_C)
    {
        std::cout << "AC" << std::endl;
    }
    else
    {
        std::cout << "WA" << std::endl;
    }

}

Measured memory_bytes: 256
#include <stdio.h>

int main(void){
    int h,w,t,i;
    while(1){
        scanf("%d %d\n",&h,&w);//h,w scan
        if(h==0 && w==0){
            break;
        }else{
            for(t = 0;t < h;t++){
                for(i = 0;i < w;i++){
                    printf("#");
                }
                printf("\n");
            }
        }
        printf("\n");
    }
    return 0; /*0?????????*/
}

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

int main()
{
    int a, b;
    cin >> a >> b;
    if (a >= b)
    {
        for (int i = 0; i < a; i++)
        {
            cout << b;
        }
    }
    else
    {
        for (int i = 0; i < b; i++)
        {
            cout << a;
        }
    }
    cout << endl;
}



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

int main() {
	int N;
	cin >> N;
	vector<double> v(N);
	rep(i, N) {
		cin >> v.at(i);
	}

	double a = 0;
	vector<vector<double>> dp(N+1, vector<double>(N+1));
	dp[0][0] = 1;
	rep(i, N) {
		rep(j, i+1) {
			dp[i+1][j+1] += dp[i][j] * v.at(i);
			dp[i+1][j] += dp[i][j] * (1-v.at(i));
		}
	}
	rep(i, (N+1)/2) {
		a += dp[N][N-i];
	}
	cout << fixed << setprecision(10) << a << '\n';
}


Measured memory_bytes: 73816
#include<bits/stdc++.h>
#define rep(i, n) for (ll i = 0; i < (ll)(n); ++i)
#define repk(i,k,n) for (ll i = k; i < (ll)(n); ++i)
#define INF 500000001000000000
#define MOD 1000000007
typedef long long  ll;

using namespace std;

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

	string S;
	cin >> S;

	rep(i,3){
		cout << S[i];
	}

	cout << endl;
	return 0;
}

Measured memory_bytes: 3552
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <string>
#include <algorithm>
#define N 1234
#define NN 5678
template<typename T> inline void read(T &x) {
  x = 0; char c = getchar(); bool flag = false;
  while (!isdigit(c)) { if (c == '-') flag = true; c = getchar(); }
  while (isdigit(c)) { x = (x << 1) + (x << 3) + (c ^ 48); c = getchar(); }
  if (flag) x = -x;
}
using namespace std;
const int inf = 7654321;
inline void MIN(int &a, int b) {
  if (b < a)  a = b;
}
int n;
struct edge{
  int nxt, to;
}e[N << 1];
int head[N], ecnt;
inline void addedge(int from, int to) {
  e[++ecnt] = (edge){head[from], to};
  head[from] = ecnt;
}
int fa[N];
int val[N];
int f[N][2], g[NN], og[NN];
inline void calc(int cur, int t) {
  memset(g, 0x3f, sizeof(g)); g[0] = 0;
  for (signed int i = head[cur]; i; i = e[i].nxt) {
    int to = e[i].to; memcpy(og, g, sizeof(g)); memset(g, 0x3f, sizeof(g));
    for (signed int j = val[cur]; ~j; --j) {
      if (j >= val[to] && og[j - val[to]] <= inf) MIN(g[j], og[j - val[to]] + f[to][t]);
      if (j >= f[to][t ^ 1] && og[j - f[to][t ^ 1]] <= inf) MIN(g[j], og[j - f[to][t ^ 1]] + val[to]);
    }
  }
  for (signed int j = 0; j <= val[cur]; ++j)  MIN(f[cur][t], g[j]);
}
void dfs(int cur) {
  for (signed int i = head[cur]; i; i = e[i].nxt) {
    int to = e[i].to; dfs(to);
  }
  calc(cur, 0); calc(cur, 1);
  if (f[cur][0] > inf && f[cur][1] > inf) {
    puts("IMPOSSIBLE");
    exit(0);
  }
}

int main() {
  memset(f, 0x3f, sizeof(f));
  read(n);
  for (signed int i = 2; i <= n; ++i) read(fa[i]), addedge(fa[i], i);
  for (signed int i = 1; i <= n; ++i) read(val[i]);
  dfs(1);
  puts("POSSIBLE");
  return 0;
}


Measured memory_bytes: 3168
#include <algorithm>
#include <bitset>
#include <cmath>
#include <iostream>
#include <limits>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>

using namespace std;
using ll = long long;
const int IINF = 1e9;
const ll INF = 1e18;
const int MOD = 1e9 + 7;

#define dump(x) cout << #x << " = " << (x) << endl;
#define YES(n) cout << ((n) ? "YES" : "NO") << endl

template <typename T>
void dumpvec(vector<T> vec) {
  for (T cnt : vec) {
    cout << cnt << ", ";
  }
  cout << endl;
}

void chmin(ll &a, ll b) {
  if (a > b) {
    a = b;
  }
}
void chmax(ll &a, ll b) {
  if (a < b) {
    a = b;
  }
}

vector<string> split(string s, string delimiter) {
  int first = 0;
  int last = s.find_first_of(delimiter);
  vector<string> result;

  while (first < s.size()) {
    string sub = s.substr(first, last - first);
    result.push_back(sub);
    first = last + 1;
    last = s.find_first_of(delimiter, first);

    if (last == string::npos) {
      last = s.size();
    }
  }

  return result;
}

string join(vector<string> strings, string delimiter) {
  string result = "";
  for (int i = 0; i < strings.size(); i++) {
    if (result != "") result += delimiter;
    result += strings[i];
  }
  return result;
}

int main() {
  int N, L;
  cin >> N >> L;
  priority_queue<string, vector<string>, greater<string>> pq;
  for (int i = 0; i < N; i++) {
    string w;
    cin >> w;
    pq.push(w);
  }

  string ans = "";
  while (pq.size() > 0) {
    ans += pq.top();
    pq.pop();
  }
  cout << ans << endl;
}

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

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

using namespace std;

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

int main(){
	int n; scanf("%d",&n);
	vector<int> p(n*n);
	rep(i,n*n) scanf("%d",&p[i]), p[i]--;

	vector<string> B(n,string(n,'#'));
	vector<vector<int>> d(n,vector<int>(n));
	rep(i,n) rep(j,n) d[i][j]=min({i,n-1-i,j,n-1-j});

	int ans=0;
	for(int q:p){
		int i0=q/n,j0=q%n;

		B[i0][j0]='.';
		ans+=d[i0][j0];

		queue<pair<int,int>> Q; Q.emplace(i0,j0);
		while(!Q.empty()){
			int y,x; tie(y,x)=Q.front(); Q.pop();

			rep(k,4){
				int yy=y+dy[k],xx=x+dx[k];
				if(0<=yy && yy<n && 0<=xx && xx<n){
					int d2=d[y][x]+(B[y][x]=='.'?0:1);
					if(d[yy][xx]>d2){
						d[yy][xx]=d2;
						Q.emplace(yy,xx);
					}
				}
			}
		}
	}
	printf("%d\n",ans);

	return 0;
}


Measured memory_bytes: 5616
#include <stdio.h>
#include <math.h>
static int a[100010];
int 
main(){
	 int N,i;
	 int cnt=0;
	int K;
	scanf("%d",&N);

	int tmp;
	for(i=0;i<N;i++){
		scanf("%d",&tmp);
		a[tmp]=i+1;
	}
	
	for(i=1;i<N+1;i++){
		printf("%d ",a[i]);
	}
	printf("\n");
 return 0;
}

Measured memory_bytes: 1152
#include <stdio.h>
#include <ctype.h>
#include <stdlib.h>

int main()
{
	int i, n;
	short a[101];

	scanf("%d", &n);
	for (i = 0; i < n; i++) scanf("%d", &a[i]);
	if (n >= 1) printf("%d", a[n - 1]);
	for (i = n - 2; i >= 0; i--) printf(" %d", a[i]);
	putchar('\n');
	return 0;
}



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

int main(){
    string s, t;
    cin>>s>>t;
    for(int i=s.size()-t.size(); i>=0; i--){ // TをSの右端から詰めて探索していく
        for(int j=0; j<t.size(); j++){
            if(s[i+j]!='?' && s[i+j]!=t[j]){goto ER;} // 文字が一致しない場合はgotoしてER:へ飛ぶ
        }
        for(int j=0; j<t.size(); j++){ // 判明している文字が全て一致する場合はその部分をtに書き換える
          s[i+j]=t[j];}
        for(int j=0; j<s.size(); j++){ // ?文字があるならaに書き換える
            if(s[j]=='?'){s[j]='a';}
        }
        cout<<s;
        return 0;
        ER:;
    }
  cout<<"UNRESTORABLE"; // 最後まで一致する文字がない場合はこれを出力
}


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

N = int(input())
A = list(map(int, input().split()))
cnt = [0] * (10**5 + 1)
ans = 0
for a in A:
    cnt[a] += 1
    ans += a
Q = int(input())
for _ in range(Q):
    B, C = map(int, input().split())
    ans += cnt[B] * (C - B)
    cnt[C] += cnt[B]
    cnt[B] = 0
    print(ans)

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

typedef long long int ll;
ll MOD = 1000000007;
ll INFL = 1ll << 60;
ll INF = 1 << 28;

// vector確認用
template <typename T>
ostream& operator<<(ostream& os, vector<T>& vec) {
  cout << "{";
  for (int i = 0; i < vec.size(); i++)
    os << vec[i] << (i + 1 == vec.size() ? "" : " ");
  cout << "}";
  return os;
}

vector<ll> kai(100010);

// ====================================================================

int main() {
  int n;
  cin >> n;
  string s;
  cin >> s;

  // 端がW、っていう例外（0を返す）
  if (s[0] == 'W' || s[s.size() - 1] == 'W') {
    cout << 0 << endl;
    return 0;
  }

  // まず、右側の候補になるものを記録する
  vector<int> v(s.size());
  char bef = 'x';
  int res = 1, sum = 0;
  for (int i = 0; i < s.size(); i++) {
    if (s[i] == bef)
      res *= -1;
    v[i] = res;
    bef = s[i];

    sum += v[i];
    if (sum < 0) {  // 右端の候補が多すぎるタイミングがある
      cout << 0 << endl;
      return 0;
    }
  }

  // 左端や右側の候補が全体的にみて多すぎる
  if (sum != 0) {
    cout << 0 << endl;
    return 0;
  }

  // cout << v << endl;  // 「右端」が1になってるvector

  // 階乗テーブル作成
  kai[0] = 1;
  for (int i = 1; i < kai.size(); i++) kai[i] = kai[i - 1] * i % MOD;

  // 左側の並び替えのぶんの階乗を掛ける（階乗）
  ll ans = kai[n], lcou = 0, rcou = 0;
  for (int i = 0; i < s.size(); i++) {
    if (v[i] == 1) {  // lだったら;
      lcou++;
    } else {  // rだったら
      ans = ans * (lcou - rcou) % MOD;
      rcou++;
    }
  }

  // 答えを出力
  cout << ans << endl;
}


Measured memory_bytes: 2180
#include<bits/stdc++.h>
using ll = long long;
using  INT = long long;
#define REP(i,n) for(ll i=0;i<ll(n);i++)
#define REPD(i,n) for(ll i=n-1;i>=0;i--)
#define FOR(i,a,b) for(ll i=a;i<=ll(b);i++)
#define FORD(i,a,b) for(ll i=a;i>=ll(b);i--)
#define ALL(x) x.begin(),x.end()

#define INF (int)1e9 //10^9:∞
#define LLINF (long long)1e12
#define MOD (int)1e9+7 //10^9+7:合同式の法
#define PI 3.141592653589

#define YESNO(T) if(T){cout<<"YES"<<endl;}else{cout<<"NO"<<endl;}
#define yesno(T) if(T){cout<<"yes"<<endl;}else{cout<<"no"<<endl;}
#define YesNo(T) if(T){cout<<"Yes"<<endl;}else{cout<<"No"<<endl;}

#define Graph vector<vector<int>>
#define PII pair<int,int>
#define VI vector<int>
#define VVI vector<vector<int>>
#define VPII vector<pair<int,int>>

#define DDD fixed<<setprecision(10)

using namespace std;
/*........................................DEFINE FUNCTIONS.........................................*/


/*....................................DEFINE GLOBAL VARIABLES .....................................*/



/*.........................................kemkemG0................................................*/
signed main() {
	ios::sync_with_stdio(false);
	cin.tie(nullptr);


	int N;
	cin>>N;
	int ans=0;
	REP(i,N){
		int a;
		cin>>a;
		ans+=a-1;
	}
	cout<<ans<<endl;

	return 0;
}








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

using namespace std;

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


int main(){
    int n;
    cin >> n;
    string s;
    cin >> s;
    string a = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
    for (int i = 0; i < s.size(); i++){
        for (int j = 0; j < 26; j++){
            if (s[i] == a[j]){
                // cout << i << " " << (j+n)%26 << endl;
                s[i] = a[(j+n)%26];
                break;
            }
        }
    }
    cout << s << endl;
}

Measured memory_bytes: 256
/* ex4_1
   masaaki52	*/

#include <stdio.h>
#include <math.h>

int main(void){
    float tree,surveillance;//割り算で小数点以下も出したいので、floatを使う
    int answer;
    scanf("%f %f",&tree,&surveillance);//tree,surveillanceに値を入力
    answer = ceil(tree/(2*surveillance + 1));//answerに、必要な監視員の最低人数を代入
    printf("%d\n",answer);//answerを出力
    return 0;
}

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

int main() {
  int c[3], n, a;
  
  while(1) {
    for(int i=0; i<3; i++)
      cin>>c[i];
    if(c[0]==0) break;
    
    sort(c, c+3);
        
    cin>>n;
    for(int i=0; i<n; i++) {
      cin>>a;
      cout<<((sqrt(c[0]*c[0]+c[1]*c[1])<2*a)?"OK":"NA") << endl;
    }
  }
  return 0;
}

Measured memory_bytes: 1168