akhauriyash/Code-Regression huggingface dataset:
#[allow(unused_macros)]
macro_rules ! input { ( source = $ s : expr , $ ( $ r : tt ) * ) => { let mut iter = $ s . split_whitespace ( ) ; let mut next = || { iter . next ( ) . unwrap ( ) } ; input_inner ! { next , $ ( $ r ) * } } ; ( $ ( $ r : tt ) * ) => { let stdin = std :: io :: stdin ( ) ; let mut bytes = std :: io :: Read :: bytes ( std :: io :: BufReader :: new ( stdin . lock ( ) ) ) ; let mut next = move || -> String { bytes . by_ref ( ) . map ( | r | r . unwrap ( ) as char ) . skip_while ( | c | c . is_whitespace ( ) ) . take_while ( | c |! c . is_whitespace ( ) ) . collect ( ) } ; input_inner ! { next , $ ( $ r ) * } } ; }
#[allow(unused_macros)]
macro_rules ! input_inner { ( $ next : expr ) => { } ; ( $ next : expr , ) => { } ; ( $ next : expr , $ var : ident : $ t : tt $ ( $ r : tt ) * ) => { let $ var = read_value ! ( $ next , $ t ) ; input_inner ! { $ next $ ( $ r ) * } } ; }
#[allow(unused_macros)]
macro_rules ! read_value { ( $ next : expr , ( $ ( $ t : tt ) ,* ) ) => { ( $ ( read_value ! ( $ next , $ t ) ) ,* ) } ; ( $ next : expr , [ $ t : tt ; $ len : expr ] ) => { ( 0 ..$ len ) . map ( | _ | read_value ! ( $ next , $ t ) ) . collect ::< Vec < _ >> ( ) } ; ( $ next : expr , chars ) => { read_value ! ( $ next , String ) . chars ( ) . collect ::< Vec < char >> ( ) } ; ( $ next : expr , usize1 ) => { read_value ! ( $ next , usize ) - 1 } ; ( $ next : expr , $ t : ty ) => { $ next ( ) . parse ::<$ t > ( ) . expect ( "Parse error" ) } ; }

fn main() {
    input! {
        n: usize,
        s: chars
    }

    let front = s[..n].to_vec();
    let mut back = s[n..].to_vec();
    back.reverse();

    let mut hmap = std::collections::HashMap::new();
    for (p,q) in enum_all_subsets(&front) {
        *hmap.entry((p, q)).or_insert(0u64) += 1;
    }
    let mut hmap2 = std::collections::HashMap::new();    
    for (p,q) in enum_all_subsets(&back) {
        *hmap2.entry((p, q)).or_insert(0u64) += 1;
    }

    let mut ret = 0u64;
    for (key, &value) in hmap.iter() {
        if let Some(v) = hmap2.get(key) {
            ret += v * value;
        }
    }
    println!("{}", ret);
}

#[allow(dead_code)]
pub fn bit_filter<T: Clone>(b: usize, v: &[T]) -> Vec<T> {
    let mut ret = vec![];
    for i in 0..v.len() {
        if (b >> i) & 1 == 1 {
            ret.push(v[i].clone());
        }
    }
    ret
}
#[allow(dead_code)]
pub fn enum_all_subsets<'a, T: Clone + 'a>(v: &'a [T]) -> Box<Iterator<Item = (Vec<T>, Vec<T>)> + 'a> {
    Box::new((0..(1 << v.len())).map(move |s| (bit_filter(s, v), bit_filter(!s, v))))
}

Measured memory_bytes: 135332
_ = input()
aa = list(map(int,input().split()))

sums_1,sums_2 = 0,0
ans_1,ans_2 = 0,0

for i in range(len(aa)):
    tmp = sums_1 + aa[i]
    if (i % 2 == 0 and tmp <= 0) or (i % 2 == 1 and tmp >= 0):
        sums_1 = (-1)**(i % 2)
        ans_1 += abs(tmp)+1
    else:
        sums_1 = tmp

for i in range(len(aa)):
    tmp = sums_2 + aa[i]
    if (i % 2 == 0 and tmp >= 0) or (i % 2 == 1 and tmp <= 0):
        sums_2 = (-1)**(i % 2 + 1)
        ans_2 += abs(tmp)+1
    else:
        sums_2 = tmp

print(min(ans_1,ans_2))

Measured memory_bytes: 14468
#include <bits/stdc++.h>
using namespace std;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

#define COUT(x) cout << #x << " = " << (x) << " (L" << __LINE__ << ")" << endl
template<class T1, class T2> ostream& operator << (ostream &s, pair<T1,T2> P)
{ return s << '<' << P.first << ", " << P.second << '>'; }
template<class T> ostream& operator << (ostream &s, vector<T> P)
{ for (int i = 0; i < P.size(); ++i) { if (i > 0) { s << " "; } s << P[i]; } return s; }
template<class T> ostream& operator << (ostream &s, vector<vector<T> > P)
{ for (int i = 0; i < P.size(); ++i) { s << endl << P[i]; } return s << endl; }
template<class T> ostream& operator << (ostream &s, set<T> P)
{ for(auto it : P) { s << "<" << it << "> "; } return s << endl; }
template<class T1, class T2> ostream& operator << (ostream &s, map<T1,T2> P)
{ for(auto it : P) { s << "<" << it.first << "->" << it.second << "> "; } return s << endl; }


const long long INF = 1LL<<60;
int N;
vector<long long> A;

long long solve() {
    vector<long long> left(N+1, 0), right(N+1, 0);
    for (int i = 0; i < N; ++i) {
        if (i % 2 == 0) {
            left[i+1] = left[i] + A[i];
            right[i+1] = right[i] + A[N-i-1];
        }
        else left[i+1] = left[i], right[i+1] = right[i];
    }
    vector<long long> dp(N+1, -INF);
    dp[0] = 0;
    for (int i = 2; i <= N; i += 2) {
        chmax(dp[i], dp[i-2] + A[i-1]);
        chmax(dp[i], left[i-2] + max(A[i-1], A[i-2]));
    }

    if (N % 2 == 0) return dp[N];
    long long res = -INF;
    for (int i = 0; i <= N; i += 2) {
        chmax(res, dp[i] + right[N-i-1]);
    }

    //COUT(left); COUT(right); COUT(dp);

    return res;
}

int main() {
    while (cin >> N) {
        A.resize(N);
        for (int i = 0; i < N; ++i) cin >> A[i];
        cout << solve() << endl;
    }
}

















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

using namespace std;

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

#define mp make_pair
#define F first
#define S second

const ll N = 2e5;
const ll M = 20;
const ll SQ = 320;
const ll INF = 1e16;
const ll MOD = 1e9+7;

int n;
vector<int> v[N];
ll sz[N],down[N],up[N];
ll f[N],inv[N];

ll POW(ll a,ll b)
{
	if (b==1) return a;
	ll ans = POW(a,b/2);
	ans = ans*ans%MOD;
	if (b%2)
		return ans*a%MOD;
	else
		return ans;
}

ll C(ll a,ll b)
{
	return f[b]*inv[a]%MOD*inv[b-a]%MOD;
}

void dfs_down(int x,int p)
{
	for (int i = 0; i<v[x].size(); i++)
		if (v[x][i]!=p)
		{
			dfs_down(v[x][i],x);
			sz[x] += sz[v[x][i]];
		}
	down[x] = 1;
	ll h = sz[x];
	for (int i = 0; i<v[x].size(); i++)
		if (v[x][i]!=p)
		{
			down[x] = down[x]*C(sz[v[x][i]],h)%MOD*down[v[x][i]]%MOD;
			h -= sz[v[x][i]];
		}
	sz[x]++;
}

void dfs_up(int x,int p)
{
	if (sz[x]==1) return;
	ll h = C(n-sz[x],n-1)*up[x]%MOD;
	ll t = sz[x]-1;
	for (int i = 0; i<v[x].size(); i++)
		if (v[x][i]!=p)
		{
			h = h*C(sz[v[x][i]],t)%MOD*down[v[x][i]]%MOD;
			t -= sz[v[x][i]];
		}
	for (int i = 0; i<v[x].size(); i++)
		if (v[x][i]!=p)
		{
			up[v[x][i]] = h*POW(C(sz[v[x][i]],n-1),MOD-2)%MOD*POW(down[v[x][i]],MOD-2)%MOD;
			dfs_up(v[x][i],x);
		}
}

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

	cin >> n;
	f[0] = inv[0] = 1;
	for (int i = 1; i<=n; i++)
	{
		f[i] = f[i-1]*i%MOD;
		inv[i] = POW(f[i],MOD-2);
	}
	for (int i = 0; i<n-1; i++)
	{
		int x,y;
		cin >> x >> y;
		x--; y--;
		v[x].push_back(y);
		v[y].push_back(x);
	}
	dfs_down(0,-1);
	up[0] = 1;
	dfs_up(0,-1);
//	for (int i = 0; i<n; i++)
//		cout << down[i] << ' ' << up[i] << endl;
	ll ans = 0;
	for (int i = 0; i<n; i++)
		cout<<(C(sz[i]-1,n-1)*down[i]%MOD*up[i]%MOD)<<"\n";

	return 0;
}

Measured memory_bytes: 21748
#include <iostream>
#include <set>
#include <list>
#include <utility>
#include <queue>
#include <memory>
#include <cstring>
#include <vector>
#include <algorithm>
#include <functional>

using namespace std; 

int
main(int argc, char const *argv[])
{
    int64_t s;
    cin >> s;
    auto u = s / 100;
    auto v = s - (100 * u);
    if (u < 13 && u > 0 && v < 13 && v > 0) {
	cout << "AMBIGUOUS" << endl;
    } else if (u < 13 && u > 0) {
	cout << "MMYY" << endl;
    } else if (v < 13 && v > 0) {
	cout << "YYMM" << endl;
    } else {
	cout << "NA" << endl;
    }
    return 0;
}
 


Measured memory_bytes: 256
#include<iostream>
#include<string>
using namespace std;
int main(){
  string w;
  string t;
  cin >> w;
  int i;
  for(i=0;i<w.size();i++) {
    if('A'<=w[i]&&w[i]<='Z') w[i]+='a'-'A';
  }
  int o=0;
  cin >> t;
  while(t!="END_OF_TEXT"){
   
    for(i=0;i<t.size();i++) {
      if('A'<=t[i]&&t[i]<='Z') t[i]+='a'-'A';
    }
    if(w==t) o++;
    cin >> t;
  }
  cout << o << endl;
}


Measured memory_bytes: 3148
#include <algorithm>
#include <iostream>
#include <cstdio>
#include <map>
#include <numeric>
#include <cmath>
#include <set>
#include <sstream>
#include <string>
#include <vector>
#include <queue>
#include <stack>
#include <complex>
#include <string.h>
#include <unordered_set>
#include <unordered_map>
#include <bitset>
#include <iomanip>
#include <sys/time.h>
#include <tuple>
#include <random>
using namespace std;

#define endl '\n'
#define ALL(v) (v).begin(), (v).end()
#define RALL(v) (v).rbegin(), (v).rend()
#define UNIQ(v) (v).erase(unique((v).begin(), (v).end()), (v).end())

typedef long long ll;
typedef long double ld;
typedef pair<int, int> P;
typedef complex<double> comp;
typedef vector< vector<ld> > matrix;
struct pairhash {
public:
    template<typename T, typename U>
    size_t operator()(const pair<T, U> &x) const {
	size_t seed = hash<T>()(x.first);
	return hash<U>()(x.second) + 0x9e3779b9 + (seed<<6) + (seed>>2);
    }
};
const ll inf = 1e18 + 9;
const ll mod = 998244353;
const double eps = 1e-8;
const double pi = acos(-1);

int n, s;
int a[3010];

ll dp[3010][3010];

ll solve() {
    for (int i = 1; i <= n; i++) {
        for (int j = 0; j <= s; j++) {
            dp[i][j] = dp[i-1][j];
            if (a[i-1] <= j) {
                dp[i][j] += dp[i-1][j-a[i-1]];
                dp[i][j] %= mod;
            }
            if (a[i-1] == j) {
                dp[i][j] += i;
                dp[i][j] %= mod;
            }
        }
    }

    ll res = 0;
    for (int i = 1; i <= n; i++) {
        res += dp[i][s];
        res %= mod;
    }
    return res;
}

void input() {
    cin >> n >> s;
    for (int i = 0; i < n; i++) cin >> a[i];
}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout << fixed << setprecision(15);

    input();
    cout << solve() << endl;
}


Measured memory_bytes: 73728
#include<iostream>
#include<vector>
#include<bits/stdc++.h>
#define lli long long int
#define mod 1000000007
#define pb push_back
#define mk make_pair
#define fastio ios_base::sync_with_stdio(false); cout.tie(NULL);
using namespace std;

int main()
{
	fastio;
	lli n,i,x,m,sum=0;
	cin>>n>>m;
	for(i=0;i<m;i++)
	{
		cin>>x;
		sum+=x;
	}
	if(n-sum<0)
		cout<<-1;
	else
		cout<<n-sum;
	return 0;
}


Measured memory_bytes: 3652
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> l_l;
typedef pair<int, int> i_i;
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;
}

const long double EPS = 1e-10;
const long long INF = 1e18;
const long double PI = acos(-1.0L);
//const ll mod = 1000000007;

int main() {
    //cout.precision(10);
    cin.tie(0);
    ios::sync_with_stdio(false);
    int A, B;
    cin >> A >> B;
    for(int i = 0; i <= 1e5; i++) {
        if(i * 8 / 100 != A) continue;
        if(i * 10 / 100 != B) continue;
        cout << i << endl;
        return 0;
    }
    cout << -1 << endl;
    return 0;
}

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

#define INF_LL (int64)1e18
#define INF (int32)1e9
#define REP(i, n) for(int64 i = 0;i < (n);i++)
#define FOR(i, a, b) for(int64 i = (a);i < (b);i++)
#define all(x) x.begin(),x.end()
#define fs first
#define sc second

using int32 = int_fast32_t;
using uint32 = uint_fast32_t;
using int64 = int_fast64_t;
using uint64 = uint_fast64_t;
using PII = pair<int32, int32>;
using PLL = pair<int64, int64>;

const double eps = 1e-10;

template<typename A, typename B>inline void chmin(A &a, B b){if(a > b) a = b;}
template<typename A, typename B>inline void chmax(A &a, B b){if(a < b) a = b;}

int main(void){
	int32 N, M, X, Y;
	cin >> N >> M >> X >> Y;
	int32 minX = X, maxX = X, minY = Y, maxY = Y;
	REP(i, N){
		int32 x;
		cin >> x;
		chmax(maxX, x); chmin(minX, x);
	}
	REP(i, M){
		int32 x;
		cin >> x;
		chmax(maxY, x); chmin(minY, x);
	}
	if(maxX < minY){
		cout << "No War" << endl;
	}else{
		cout << "War" << endl;
	}
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
#define ll long long int
#define mod 1000000007
#define lol 200005
#define debug(x) cout<<#x<<" is "<<x<<endl;
#define ffor(i,a,b) for(int i=a;i<b;i++)
#define bfor(i,a,b) for(int i=b;i>=a;i--)
#define mp make_pair
#define pb push_back
#define ff first
#define ss second
#define vp vector<pair<double,double>>
#define vpp vector<pair<int, pair<int,int>>>
#define pp pair<int,int>

int main()
{
   int h,w;
   cin>>h>>w;
   vector<string> v;
   ffor(i,0,h)
   {
   	 string s;
   	 cin>>s;
   	 v.pb(s);
   }
   int dp[h][w];
   memset(dp,0,sizeof(dp));
   dp[0][0]=1;
   ffor(i,1,w)
   {
   	 if(v[0][i]=='.')
   	 	dp[0][i]=1;
   	 else
   	 	break;
   }
   ffor(i,1,h)
   {
   	 if(v[i][0]=='.')
   	 	 dp[i][0]=1;
   	 else
   	 	break;
   }
   ffor(i,1,h)
   {
   	 ffor(j,1,w)
   	 {
   	 	 if(v[i][j]=='.')
   	 	 	dp[i][j]= (dp[i-1][j]+dp[i][j-1])%1000000007;
   	 	 else
   	 	 	dp[i][j]=0;
   	 }
   }
   cout<<dp[h-1][w-1]%1000000007<<endl;
}

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

int main(){
  int X, Y;
  cin >> X >> Y;
  int c = 0;
  bool exist = false;
  for(int i = 0; i <= X; i++){
    c = i * 2 + 4 * (X - i);
    if(c == Y) exist = true;
  }

  if(exist) cout << "Yes" << endl;
  else cout << "No" << endl;
    
}

Measured memory_bytes: 3624
#include <iostream>
#include <algorithm>
#include <math.h>
#include <cmath>
#include <stdio.h>
#include <string>
#include <string.h>
#include <cstring>
#include <sstream>
#include <iomanip>
#include <stdlib.h>

using namespace std;

int main (void)
{
	for (int u = 0; u < 5; u++)
	{
		long n,m,a[1000],b[1000];

		cin >> n >> m;
		if (n == 0 && m == 0)
		{
			break;
		}

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



		int co = 0;
		for (int j = 0; j < m; j++)
		{
			co += b[j];
			co += a[co];
			if (co >= n - 1)
			{
				cout << j + 1 << endl;
				break;
			}
		}
	}
}


Measured memory_bytes: 3100
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define rep1(i, n) for (int i = 1; i < (n); ++i)
using namespace std;
using ll = long long;
using P = pair<int, int>;
const double PI=acos(-1);
const int INF = numeric_limits<int>::max();

int main(){
    int x,y;
    cin >> x >> y;
    int tsuru,kame;
    rep(i,x+1){
        tsuru = i;
        kame = x - i;
        if(2*tsuru + 4*kame == y){
            cout << "Yes" <<endl;
            return 0;
        }
    }
    cout << "No"  << endl;
    return 0;
    
}

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

using namespace std;
using lli = int_fast64_t;
using ulli = uint_fast64_t;
#define debug(x) cerr << #x << " : " << x << endl
#define debugv(x) cerr << #x << " : {";for(auto value_of_x:x){ cerr << value_of_x << ", ";}cerr << endl
#define debugst(x) auto xt = x;cerr << #x << " : {";for(int i=0;i<x.size();i++){ cerr << xt.top() << ", ";xt.pop();}cerr << endl
#define debugvp(x) cerr << #x << " : {";for(auto value_of_x:x){ cerr << value_of_x.first << " : " << value_of_x.second << ", ";}cerr << endl

const lli MOD = 1000000007;
const lli LIMIT = 1000000000000000000 * 5;
const int tenfive = 100000;

int main() {
	int N;
	cin >> N;
	int ans = 0;
	for (int i = 1; i <= N; i++) {
		if (to_string(i).size() % 2)ans++;
	}
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
 
#define ff              first
#define ss              second
#define int             long long
#define pb              push_back
#define mp              make_pair
#define pii             pair<int,int>
#define vi              vector<int>
#define mii             map<int,int>
#define pqb             priority_queue<int>
#define pqs             priority_queue<int,vi,greater<int> >
#define setbits(x)      __builtin_popcountll(x)
#define zrobits(x)      __builtin_ctzll(x)
#define mod             1000000007
#define inf             1e18
#define ps(x,y)         fixed<<setprecision(y)<<x
#define mk(arr,n,type)  type *arr=new type[n];
#define w(x)            int x; cin>>x; while(x--)
#define FIO             ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
mt19937                 rng(chrono::steady_clock::now().time_since_epoch().count());
int  pow(int x,int n) {int res=1; while(n){if(n&1) res=(res*x);x=(x*x);n>>=1;}return res;}
 struct solve{
 	int wt, val;
 };
 
int max_wt(struct solve* arr,int W, int n ){
	int maxval= n*1000;
	int dp[n+1][maxval+1];

		for(int i=1;i<=maxval;i++){
			dp[1][i]= inf;
		}
		dp[1][arr[1].val]= arr[1].wt;
		dp[1][0]=0;

		for(int i=2;i<=n;i++){
			for(int v=0;v<=maxval;v++){
				dp[i][v]= 0 + dp[i-1][v];
				if(arr[i].val <= v)
				dp[i][v]= min(dp[i][v], arr[i].wt + dp[i-1][ v- arr[i].val]);

			}
		}

		int ans=0;
		for(int x=0 ; x <= maxval ; x++){
			if(dp[n][x] <=W)
				ans=x;
		}
		return ans;
}

int32_t main()
{
	//paawan9s
	FIO;
	int n, W; cin>>n>>W;
	mk(arr, n+1, solve );
	for(int i=1;i<=n;i++){
		cin>>arr[i].wt>>arr[i].val;
	}

	cout<< max_wt(arr, W, n);

	return 0;
}

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

int main(int argc, char **argv)
{
  int x, y, diag, rect, loze;
  char c;
  rect = loze = 0;
  for (;;) {
    cin >> x >> c >> y >> c >> diag;
    if (cin.eof())
      break;
    if (x*x+y*y==diag*diag)
      rect++;
    if (x == y)
      loze++;
  }
  cout << rect << endl;
  cout << loze << endl;
  return 0;
}

Measured memory_bytes: 1160
#include <iostream>
#include <stdio.h>
#include <vector> 
#include <algorithm>
#include <functional>
#include <string>

using namespace std;

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

	vector<int> vec(M);
	for (int i = 0; i < M; i++) {
		cin >> vec.at(i);
	}
	
	int sum = 0;
	for (int i = 0; i < M; i++) {
		sum += vec[i];
	}

	int result = N - sum;

	cout << ((result>=0)?result:-1) << endl;
}


Measured memory_bytes: 3664
N = int(input())
lst = [int(x) for x in input().split()]

n = max(lst)
h = 1
ret = 0
while n >= h:
    flg = True
    for x in lst:
        if x >= h and flg:
            ret += 1
            flg = False
        elif h > x:
            flg = True
    h += 1
print(ret)

Measured memory_bytes: 3064
#include <bits/stdc++.h>      
#define pb push_back 
#define fr first 
#define sc second
#define MOD 1000000007
#define len(s) s.size()
#define min3(a, b, c) min(a, min(b, c))
#define max3(a, b, c) max(a, max(b, c))
#define all(v) v.begin(), v.end()
#define f(i,a,n) for(int i=a;i<n;i++)
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef map<int,int> mii; 

int main() {

    /* #ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin) ;
    freopen("output.txt", "w", stdout) ;
    #endif */
    ios_base::sync_with_stdio(false);
    cin.tie(NULL) ; cout.tie(NULL) ;

    //int t; cin>>t; while(t--) { 
    int n,k; cin>>n>>k;
    vi h(n);
    for(int& x:h) cin>>x;
    vi dp(n,MOD);
    dp[0]=0;
    
    f(i,0,n) {
        for(int j=i+1;j<=i+k;j++) {
            if(j<n) dp[j]=min(dp[j],dp[i]+abs(h[i]-h[j]));
            else break;
        }
    }
    cout<<dp[n-1];
    

    return 0 ;
}

Measured memory_bytes: 1024
n, q = gets.split.map(&:to_i)
edges = Array.new(n) { Array.new }
additions = Array.new(n, 0)
answers = Array.new(n, 0)
(n - 1).times {
  a, b = gets.split.map(&:to_i).map(&:pred)
  edges[a] << b
}
q.times {
  spot, count = gets.split.map(&:to_i)
  additions[spot - 1] += count
}

# 現在地、累計ポイント
queue = [[0, additions.first]]

until queue.empty?
  current, point = queue.shift
  if edges[current].empty?
    answers[current] = point
  else
    answers[current] = point
    edges[current].each do |edge|
      queue << [edge, point + additions[edge]]
    end
  end
end

puts answers.join(" ")


Measured memory_bytes: 36276
#include <iostream>
#include <cstdlib>

using namespace std;
int main(){
    int w, h, x, y, r;
    cin >>w >>h >>x >>y >>r;
    int lx,lx2,ly,ly2;
    lx = x+r;
    lx2 = x-r;
    ly = y+r;
    ly2 = y-r;
    if((lx<=w)&&(lx2>=0)&&(ly<=h)&&(ly2>=0)){
      cout <<"Yes\n";
    }
    else{
      cout <<"No\n";
    }
}



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

using namespace std;
using ll=int64_t;
using pii = pair<int, int>;
using pli = pair<ll, int>;
using mii = map<int, int>;
using vi=vector<int>;
using vii=vector<vi>;
using vl=vector<ll>;
using vll=vector<vl>;
using tpi=tuple<int, int, int>;

int main() {
    int N, K;
    cin >> N >> K;
    vi B(N + 1);
    for (auto i = 1; i <= N; i++) {
        int a;
        cin >> a;
        auto tmp = a + B[i - 1];
        B[i] = tmp % K;
    }
    for (auto i = 1; i <= N; i++) {
        B[i] -= i;
        B[i] %= K;
        if (B[i] < 0) {
            B[i] += K;
        }
    }
    
    mii table;
    table[0] = 1;
    ll ans = 0;
    for (auto i = 1; i <= N; i++) {
        if (i >= K) {
            table[B[i - K]]--;
        }

        ans += table[B[i]];
        table[B[i]]++;
    }

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


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

using namespace std;

void input_vector(vector<int> &v, int n) {
  int m;
  for(int i = 0; i < n; i++) {
    cin >> m;
    v.push_back(m);
  }
}

bool binary_search(vector<int> &v, int n, int s) {
  int left = 0;
  int right = n;

  while(left < right) {
    int mid = (int)( left + right ) / 2;
    if(v[mid] < s) {
      left = mid + 1;
    }
    else if(v[mid] > s) {
      right = mid;
    }
    else {
      return true;
    }
  }
  return false;
}

int main(void) {
  int n, m;
  vector<int> u, v;

  cin >> n;
  input_vector(u, n);

  cin >> m;
  input_vector(v, m);

  bool isfound;
  for(int i = 0; i < m; i++) {
    isfound = false;
    if(binary_search(u, n, v[i])) {
      isfound = true;
    }
    if(!isfound) {
      break;
    }
  }
  
  if(isfound) {
    cout << "1" << endl;
  }
  else {
    cout << "0" << endl;
  }
}


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

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;

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

#define DEBUG(x) cout<<#x<<": "<<x<<'\n'
#define DEBUG_VEC(v) cout<<#v<<":";REP(i, v.size())cout<<' '<<v[i];cout<<'\n'
#define ALL(a) (a).begin(), (a).end()

#define CHMIN(a, b) a=min((a), (b))
#define CHMAX(a, b) a=max((a), (b))

const ll MOD=1000000007ll;
// const ll MOD=998244353ll;
#define FIX(a) ((a)%MOD+MOD)%MOD

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

int main(){
	ios::sync_with_stdio(false);
	cin.tie(0);
	int a, b, q;
	ll s[114514], t[114514];
	cin>>a>>b>>q;
	FOR(i, 1, a+1){
		cin>>s[i];
	}
	FOR(i, 1, b+1){
		cin>>t[i];
	}
	s[0]=t[0]=-1e12;
	s[a+1]=t[b+1]=1e12;
	ll x;
	REP(i, q){
		cin>>x;
		ll *itrs=lower_bound(s, s+a+2, x);
		ll *itrt=lower_bound(t, t+b+2, x);
		ll ans=min({max(*itrs, *itrt)-x, x-min(*(itrs-1), *(itrt-1)), 2*(*itrs-x)+x-*(itrt-1), 2*(*itrt-x)+x-*(itrs-1), 2*(x-*(itrs-1))+*itrt-x, 2*(x-*(itrt-1))+*itrs-x});
		cout<<ans<<'\n';
	}
	return 0;
}


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

typedef long long ll;

#define pb push_back
#define mp make_pair
#define fi first
#define se second

const int N = 1e5 + 5;
const ll inf = 1e18;
ll dp[N], h[N];
int n;

ll solve(int n) {
    if (n == 1) return 0;
    if (n == 0) return inf;
    if (dp[n] != -1) return dp[n];
    dp[n] = inf;
    return dp[n] = min(abs(h[n] - h[n - 1]) + solve(n - 1), abs(h[n] - h[n - 2]) + solve(n - 2));
}

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    
    cin >> n;
    for (int i = 1; i <= n; i++) {
        cin >> h[i];
    }
    memset(dp, -1, sizeof(dp));
    ll ans = solve(n);
    cout << ans;
    
    return 0;
}


Measured memory_bytes: 4224
//AGC-A問題
#include <bits/stdc++.h>
using namespace std;
const int dx[4] = {1,0,-1,0};
const int dy[4] = {0,1,0,-1};

int main(){
    int height,width; cin >> height >> width;
    vector<string> A(height);

    for(int h=0;h<height;++h) cin >> A[h];
    vector <vector<int> > dist(height, vector<int>(width,-1));
    queue <pair<int,int> > que;
    for(int h=0;h<height;++h){
        for(int w=0;w<width;++w){
            if(A[h][w]=='#'){
                dist[h][w] = 0;
                que.push(make_pair(h,w));
            }
        }
    }
    while(!que.empty()){
        pair<int,int> current_pos = que.front();
        int y = current_pos.first;
        int x = current_pos.second;
        que.pop();

        for(int direction = 0;direction<4;++direction){
            int next_y = y + dy[direction];
            int next_x = x + dx[direction];
            if(next_x < 0 || next_x >= width || next_y < 0 || next_y >= height) continue;
            if(A[next_y][next_x] == '#') continue;

            if(dist[next_y][next_x] == -1){
                dist[next_y][next_x] = dist[y][x] + 1;
                que.push(make_pair(next_y,next_x));
                A[next_y][next_x] = '#';
            }
        }
    }
    int ans=0;
    for(int h=0;h<height;++h){
        for(int w=0;w<width;++w){
            ans = max(ans,dist[h][w]);
        }
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 13456
#include<stdio.h>

int main(void){
  int a,b;
  int x,y;

  for(;scanf("%d%d",&a,&b)==2;){
    x=a;
    y=b;
    for(;;){
      if(a>b)       a-=b;
      else if(a<b)  b-=a;
      else{
        printf("%d ",a);
        break;
      }
    }
    x/=a;
    printf("%d\n",x*y);
  }
  return 0;
}

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

template<typename T> struct CoordinateCompression
{
	const vector<T> &vals;
	map<T, int> zip;
	vector<T> unzip;
	int size_comp;

	CoordinateCompression(const vector<T> &vals) : vals(vals) {}

	void calc() {
		vector<T> vals(this->vals);
		sort(vals.begin(), vals.end());
		vals.erase(unique(vals.begin(), vals.end()), vals.end());
		size_comp = vals.size();
		unzip.resize(size_comp);
		for (int i = 0; i < size_comp; i++) {
			zip[vals[i]] = i;
			unzip[i] = vals[i];
		}
	}

	vector<int> compression(const vector<T> &v) {
		vector<int> res(v.size());
		for (int i = 0; i < v.size(); i++) {
			res[i] = zip[v[i]];
		}
		return res;
	}
};

template<class M> struct SegmentTree
{
	int n;
	int size;
	vector<M> data;
	const function<M(M, M)> op;
	const M ID;

	SegmentTree(int n, function<M(M, M)> op, M id, const vector<M> &init_vals=vector<M>()) : n(n), op(op), ID(id) {
		size = 1;
		while (size < n) size <<= 1;
		data.assign(size * 2, ID);
		for (int i = 0; i < init_vals.size(); i++) data[size+i] = init_vals[i];
		for (int i = size-1; i > 0; i--) data[i] = op(data[2*i], data[2*i+1]);
	}

	void init(const vector<M> &init_vals) {
		data.assign(size * 2, ID);
		for (int i = 0; i < init_vals.size(); i++) data[size+i] = init_vals[i];
		for (int i = size-1; i > 0; i--) data[i] = op(data[2*i], data[2*i+1]);
	}

	void update(int idx, M x) {
		idx += size;
		data[idx] = x;
		while (idx /= 2) {
			data[idx] = op(data[2*idx], data[2*idx+1]);
		}
	}

	M query(int l, int r) {
		M L = ID, R = ID;
		for (l += size, r += size; l < r; l /= 2, r /= 2) {
			if (l & 1) L = op(L, data[l]), l++;
			if (r & 1) r--, R = op(data[r], R);
		}
		return op(L, R);
	}

	M val(int idx) {
		return data[size + idx];
	}

	vector<M> val_vec() {
		vector<M> res(n);
		for (int i = 0; i < n; i++) res[i] = data[size+i];
		return res;
	}
};

template<typename T> int LIS_leq(vector<T> v) {
	CoordinateCompression<T> C(v);
	C.calc();
	vector<int> c = C.compression(v);
	auto op = [](int x, int y) {
		if (y > x) return y;
		return x;
	};
	SegmentTree<int> dp(C.size_comp, op, 0);
	int res = 0;
	for (int e : c) {
		int a = dp.query(0, e+1) + 1;
		if (a > dp.val(e)) {
			dp.update(e, a);
			res = max(res, a);
		}
	}
	return res;
}

int main() {
	int n;
	cin >> n;
	vector<int> A(n);
	for (int i = 0; i < n; i++) {
		cin >> A[i];
		A[i] = -A[i];
	}
	int ans = LIS_leq(A);
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 9940
#include <bits/stdc++.h>
using namespace std;
#define ll long long int

#define PI 3.14159265358979323846
  
double min(double x, double y)  
{  
    return (x < y)? x: y;  
      
}  
  
double calcAngle(double h, double m)  
{  
    // validate the input  
    if (h <0 || m < 0 || h >12 || m > 60)  
       // printf("Wrong input");  
  
    if (h == 12) h = 0;  
    if (m == 60) m = 0;  
  
    // Calculate the angles moved  
    // by hour and minute hands  
    // with reference to 12:00  
    double hour_angle = 0.5 * (h * 60 + m);  
    double minute_angle = 6 * m;  
  
    // Find the difference between two angles  
    double angle = abs(hour_angle - minute_angle);  
  
    // Return the smaller angle of two possible angles  
    angle = min(360 - angle, angle);  
  
    return angle;  
}  

int main() 
{
    double a,b,h,m;
    cin>>a>>b>>h>>m;
    double d=calcAngle(h,m);
    //cout<<d<<"\n";
    //cout<<fixed<<setprecision(20)<<cos((117*PI)/(180));
    double y=cos((d*PI)/180.0);
   // cout<<y<<"\n";
//     			double ans=(double)a*a+(double)b*b-(double)2*a*b*y;
// 			cout<<fixed<<setprecision(10)<<sqrt(ans);
    // if(d==180)
    // cout<<fixed<<setprecision(20)<<a+b;
    // else if(d==0)
    // cout<<fixed<<setprecision(20)<<abs(b-a);
    // else
    // {
        
          double r=a*a+b*b-(2*a*b*y);
        
        r=sqrt(r);
        cout<<fixed<<setprecision(20)<<r;
   // }
}

/*1.000000000
2.414213562
127.321336469



*/

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

#define rep(i, a, n)  for(ll i=a; i<n; i++)
#define per(i, a, n)  for(ll i=n-1; i>=a; i--)
#define fill0(n)  setfill('0') << right << setw(n)
#define all(x)  (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define LONGMAX 1e18
#define INTMAX 1000000000

using namespace std;
typedef long long ll;
typedef pair<ll ,ll> P;
const ll mod = 1e9+7;
const long double EPS = 0.0000000001;

int n,m;
int main() {
	cin >> n >> m;
	cout << n*(n-1)/2 + m*(m-1)/2 << endl;
}



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

using i64 = int64_t;

int main(){
    i64 n;
    cin >> n;
    vector<i64> c(n+1);
    for(int i=0;i<n;++i){
        i64 a;
        cin >> a;
        c[a]++;
    }
    vector<i64> d(n+1);
    for(i64 i=0;i<=n;++i)d[c[i]]++;
    vector<i64> sum_d(n+2), sum_kd(n+2);
    for(i64 i=1;i<=n+1;++i){
        sum_d[i] = sum_d[i-1] + d[i];
        sum_kd[i] = sum_kd[i-1] + i*d[i];
    }
    vector<i64> f(n+1);
    for(i64 i=1;i<=n;++i){
        f[i] = (sum_kd[i] + i*(sum_d[n]-sum_d[i])) / i;
    }
    f[0] = LLONG_MAX;
    for(i64 i=1;i<=n;++i){
        i64 valid = 0, invalid = n + 1;
        while(abs(valid-invalid) > 1){
            i64 mid = (valid + invalid) / 2;
            if(f[mid] >= i)valid = mid;
            else invalid = mid;
        }
        cout << valid << endl;
    }

    return 0;
}


Measured memory_bytes: 12544
import java.util.*;
// im so stupid im so stupid im so stupid
public class Main {
    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        int n = in.nextInt();
        int min = in.nextInt();
        int max = in.nextInt();
        long[] nums = new long[n];
        for( int i = 0; i < n; i++ ) nums[i] = in.nextLong();
        Arrays.sort(nums);
        boolean same = true;
        long ave = 0;
        int totalPostSame = 0;
        int postSame = 0;
        for( int i = n-1; i >= 0; i-- ) {
            // flag if not everything is the same WITHIN THE BOUNDS OF A
            if( i >= n-min ) if( nums[i] != nums[i-1] ) same = false;
            // get average, best is when using minimum amount
            if( i >= n-min ) ave += nums[i];
            // count nums that are the same as the one at A
            if( nums[i] == nums[n-min] ) {
                totalPostSame++;
                if( i >= n-min ) postSame++; // everything before A (sorted)
            }
        }
        System.out.printf("%.6f\n", (double)ave/min);

        // pascals triangle
        long[][] pascal = new long[n+1][n+1];
        for( int i = 0; i <= n; i++ ) {
            for( int j = 0; j <= i; j++ ) {
                if( i == j ) pascal[i][j] = 1;
                else if( j == 0 ) pascal[i][j] = 1;
                else pascal[i][j] = pascal[i-1][j-1] + pascal[i-1][j];
            }
        }
        // System.out.println(Arrays.deepToString(pascal));
        long total = 0;
        if( same ) {
            for( int i = min; i <= max; i++ ) total += pascal[totalPostSame][i];
        } else {
            total = pascal[totalPostSame][postSame];
        }
        System.out.println(total);
    }
}

Measured memory_bytes: 21844
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>
 
#define REP(i, m, n) for(int i=int(m);i<int(n);i++)
#define EACH(i, c) for (auto &(i): c)
#define all(c) begin(c),end(c)
#define EXIST(s, e) ((s).find(e)!=(s).end())
#define SORT(c) sort(begin(c),end(c))
#define pb emplace_back
#define MP make_pair
#define SZ(a) int((a).size())
 
//#define LOCAL 1
#ifdef LOCAL
#define DEBUG(s) cout << (s) << endl
#define dump(x)  cerr << #x << " = " << (x) << endl
#define BR cout << endl;
#else
#define DEBUG(s) do{}while(0)
#define dump(x) do{}while(0)
#define BR
#endif
 
//改造
typedef long long int ll;
using namespace std;
 
//ここから編集する
 
bool enough(ll t, int h[], int n, int a, int b) {
    ll ch[100005];
    for (int i = 0; i < n; i++) {
        ch[i] = h[i];
    }
 
    ll cnt = 0;
    ll dmg = b * t;
    ll dif = a - b;
    for (int i = 0; i < n; i++) {
//        ch[i] -= b * t;
//        if(ceil((double)ch[i] / (a - b)) > 0) cnt += ceil((double)ch[i] / (a - b)) ;
//        if(ch[i]> 0) cnt += (ch[i] + (a-b) - 1)/(a-b) ;
        if(h[i] <= dmg) continue;
        cnt += (h[i] - dmg + dif - 1)/dif;
 
    }
 
    return cnt <= t;
 
}
 
int main() {
    int n, a, b;
    int h[100005];
 
    cin >> n >> a >> b;
    for (int i = 0; i < n; i++) {
        cin >> h[i];
    }
 
//        if (enough(i, h, n, a, b)) {
//            cout << i << endl;
//            break;
//        }
    //にぶんたんさく！
    ll left = 0;
//    ll right = (ll) 1E10; //これだと正解した
    ll right = (ll) 10e9; //これだと何故か不正解
//    ll right = 10;
 
    while(right - left > 1){
        ll mid = (left + right) / 2;
//        if(mid == left) break;
        if(enough(mid,h,n,a,b)){
            right = mid;
        }else{
            left = mid;
        }
    }
    cout << right << endl;
}
/*
2 10 4
21
20
 */

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

using namespace std;

using int64 = long long;
const int mod = 1e9 + 7;

const int64 infll = (1LL << 62) - 1;
const int inf = (1 << 30) - 1;

struct IoSetup {
  IoSetup() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(10);
    cerr << fixed << setprecision(10);
  }
} iosetup;


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

template< typename T1, typename T2 >
istream &operator>>(istream &is, pair< T1, T2 > &p) {
  is >> p.first >> p.second;
  return is;
}

template< typename T >
ostream &operator<<(ostream &os, const vector< T > &v) {
  for(int i = 0; i < (int) v.size(); i++) {
    os << v[i] << (i + 1 != v.size() ? " " : "");
  }
  return os;
}

template< typename T >
istream &operator>>(istream &is, vector< T > &v) {
  for(T &in : v) is >> in;
  return is;
}

template< typename T1, typename T2 >
inline bool chmax(T1 &a, T2 b) { return a < b && (a = b, true); }

template< typename T1, typename T2 >
inline bool chmin(T1 &a, T2 b) { return a > b && (a = b, true); }

template< typename T = int64 >
vector< T > make_v(size_t a) {
  return vector< T >(a);
}

template< typename T, typename... Ts >
auto make_v(size_t a, Ts... ts) {
  return vector< decltype(make_v< T >(ts...)) >(a, make_v< T >(ts...));
}

template< typename T, typename V >
typename enable_if< is_class< T >::value == 0 >::type fill_v(T &t, const V &v) {
  t = v;
}

template< typename T, typename V >
typename enable_if< is_class< T >::value != 0 >::type fill_v(T &t, const V &v) {
  for(auto &e : t) fill_v(e, v);
}

template< typename F >
struct FixPoint : F {
  FixPoint(F &&f) : F(forward< F >(f)) {}

  template< typename... Args >
  decltype(auto) operator()(Args &&... args) const {
    return F::operator()(*this, forward< Args >(args)...);
  }
};

template< typename F >
inline decltype(auto) MFP(F &&f) {
  return FixPoint< F >{forward< F >(f)};
}

int main() {
  string S, T;
  cin >> S >> T;
  int ret = 0;
  for(int i = 0; i < S.size(); i++) {
    ret += S[i] == T[i];
  }
  cout << ret << endl;

}



Measured memory_bytes: 256
#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>

#define IOS ios::sync_with_stdio(false);cin.tie(0);cout.tie(0)
#define endl '\n'
#define ll long long int
#define ld long double
#define vec vector
#define forn(a) for(ll a=0; a<n; a++)
#define all(x) x.begin(), x.end()
#define deb(x) cerr<<#x<<" = "<<x<<endl

using namespace std;

int main() {
    IOS;

    int n, m; cin>>n>>m;
    map<int, vec<int>> info;
    forn(i){
        int a, b; cin>>a>>b;
        info[m-a].push_back(b);
    }

    map<int, int> candidatos;//nr, apariciones
    ll cont = 0;
    for(int i=m-1; i>=0; i--){
        for(auto it: info[i]) candidatos[it]++;
        if(candidatos.size()==0) continue;

        auto it = candidatos.end(); it--;
        int elijo = it->first;
        cont+=elijo;
        candidatos[elijo]--;
        if(candidatos[elijo]==0)candidatos.erase(elijo);
    }

    cout<<cont<<endl;

    return 0;
}


Measured memory_bytes: 10880
# coding: utf-8
# Your code here!

while True:
    N = int(input())
    if N == 0:
        break
    
    nums = [int(i) for i in input().split()]

    maxNum = 0
    cnt = 0
    for i in range(N):
        if nums[i] > 0:
            cnt = cnt + 1
        maxNum = max(nums[i], maxNum)
        
    if maxNum < 2:
        print("NA")
    else:
        print(cnt + 1)
    
    
    
    




Measured memory_bytes: 7220
#include <bits/stdc++.h>
using namespace std;
double EPS = 0.0000000001;
int sign(double x){
	if (x > EPS){
		return 1;
	} else if (x < -EPS){
		return -1;
	} else {
		return 0;
	}
}
bool equals(double x, double y){
	return abs(x - y) < EPS;
}
struct point{
	double x;
	double y;
	point(){
		x = 0;
		y = 0;
	}
	point(double X, double Y){
		x = X;
		y = Y;
	}
	point operator +(){
		return point(x, y);
	}
	point operator -(){
		return point(-x, -y);
	}
	point operator +(point P){
		return point(x + P.x, y + P.y);
	}
	point operator -(point P){
		return point(x - P.x, y - P.y);
	}
	point& operator +=(point P){
		x += P.x;
		y += P.y;
		return *this;
	}
	point& operator -=(point P){
		x -= P.x;
		y -= P.y;
		return *this;
	}
	point operator *(double k){
		return point(x * k, y * k);
	}
	point operator /(double k){
		return point(x / k, y / k);
	}
	point& operator *=(double k){
		x *= k;
		y *= k;
		return *this;
	}
	point& operator /=(double k){
		x /= k;
		y /= k;
		return *this;
	}
	bool operator ==(point P){
		return equals(x, P.x) && equals(y, P.y);
	}
	bool operator !=(point P){
		return !(*this == P);
	}
	bool operator <(point P){
		return sign(P.x - x) == 1 || (equals(x, P.x) && sign(P.y - y) == 1);
	}
	bool operator >(point P){
		return (P < *this);
	}
	point& rotate(double t){
	    double X = x * cos(t) - y * sin(t);
	    double Y = x * sin(t) + y * cos(t);
	    x = X;
	    y = Y;
	    return *this;
	}
	point& rotate(point P, double t){
	    *this -= P;
	    (*this).rotate(t);
	    *this += P;
	    return *this;
	}
	point& rotate90(){
	    swap(x, y);
	    x = -x;
	    return *this;
	}
};
istream& operator >>(istream &is, point &p){
	double x, y;
	is >> x >> y;
	p = point(x, y);
	return is;
}
ostream& operator <<(ostream &os, point p){
	os << p.x << ' ' << p.y;
	return os;
}
double norm(point P){
	return P.x * P.x + P.y * P.y;
}
double abs(point P){
	return sqrt(norm(P)); 
}
double dot(point P, point Q){
	return P.x * Q.x + P.y * Q.y;
}
struct line{
	point A;
	point B;
	line(){
	}
	line(point P, point Q){
		A = P;
		B = Q;
	}
	line(double a, double b){
		A = point(0, b);
		B = point(1, a + b);
	}
	line(double a, double b, double c){
		if (sign(b) == 0){
			A = point(-c / a, 0);
			B = point(-c / a, 1);
		} else {
			A = point(0, -c / a);
			B = point(1, -(b + c) / a);
		}
	}
};
istream& operator >>(istream &is, line &L){
	point A, B;
	is >> A >> B;
	L = line(A, B);
	return is;
}
ostream& operator <<(ostream &os, line L){
	os << L.A << ' ' << L.B;
	return os;
}
point vec(line L){
	return L.B - L.A;
}
point projection(point P, line L){
	return L.A + vec(L) * dot(P - L.A, vec(L)) / norm(vec(L));
}
point reflection(point P, line L){
	return projection(P, L) * 2 - P;
}
int main(){
  cout << fixed << setprecision(20);
  line L;
  cin >> L;
  int q;
  cin >> q;
  for (int i = 0; i < q; i++){
    point P;
    cin >> P;
    cout << reflection(P, L) << endl;
  }
}


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

template <typename T> inline void read(T& x)
{
    int f = 0, c = getchar(); x = 0;
    while (!isdigit(c)) f |= (c == '-'), c = getchar();
    while (isdigit(c)) x = x * 10 + c - 48, c = getchar();
    if (f) x = -x;
}
template <typename T, typename... Args>
inline void read(T& x, Args&... args)
{
    read(x); read(args...);
}
template <typename T> void write(T x)
{
    if (x < 0) x = -x, putchar('-');
    if (x > 9) write(x / 10);
    putchar(x % 10 + 48);
}
template <typename T> void writeln(T x) { write(x); puts(""); }
template <typename T> inline bool cmin(T& x, const T& y)
{ return y < x ? (x = y, true) : false; }
template <typename T> inline bool cmax(T& x, const T& y)
{ return x < y ? (x = y, true) : false; }

#define LL long long
#define rep(i, a, b) for (int i = a; i <= b; ++ i)
#define dwn(i, a, b) for (int i = a; i >= b; -- i)
#define ptc putchar
#define pii pair<int, int>
#define fi first
#define se second

using namespace std;

const int N = 1e6 + 5;
const double eps = 1e-20;
const int INF = 0x7fffffff;
const LL mod = 1e9 + 7;

int a, b;

void main_solve()
{
    read(a, b);
    if (a <= 9 and a >= 1 and b <= 9 and b >= 1)
    {
        writeln(a * b);
    }
    else writeln(-1);
    return ;
}

signed main()
{
    int T = 1;
    while (T --)
    {
        main_solve();
    }
    return 0;
}


Measured memory_bytes: 256
import java.util.*;

public class Main {
    public static void main(String[] args) throws Exception {
        int A;
        int B;
        int total = 0;
        
        Scanner scanner = new Scanner(System.in);
        A = scanner.nextInt();
        B = scanner.nextInt();
        //System.out.println(A + "" + B);
        
        for(int i = 0; i < 2; i++){
            if(A >= B){
                total += A;
                A--;
            }else{
                total += B;
                B--;
            }
        }
        System.out.println(total);
        
    }
}


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

using namespace std;
typedef long long ll;

const ll mo=1000000007;

ll modpow(ll a, ll n, ll mod){
  ll ret = 1;
  while(n > 0){
    if(n & 1) ret = ret * a % mod;
    a =  a * a % mod;
    n >>= 1;
  }
  return ret;
}

ll MOD(ll a, ll mod){
  ll temp = a % mod;
  if(temp < 0) temp += mod;
  return temp;
}

int main(){
  ll N, K;
  cin >> N >> K;
  vector<ll> dp(K+1, 0);
  
  for(ll i=K; i>=1; i--){
    ll temp = modpow(K/i, N, mo);
    ll b = 2 * i;
    while(b<=K){
      temp = MOD(temp - dp[b] % mo, mo);
      b += i;
    }
    dp[i] = temp;
  }
  
  ll sum=0;
  for(ll i=0; i<=K; i++){
    sum = (sum + dp[i] * i % mo) % mo;
  }
  
  cout << sum << endl;
  return 0;
}

Measured memory_bytes: 3976
//in the name of ALLAH
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
int main()
{
    ll n,m;
    cin>>n>>m;
    ll a[m+1];
    for(int i=0;i<m;i++)
    {
        cin>>a[i];
    }
    ll s=0;
    for(int i=0;i<m;i++)
    {
       s=s+a[i];
    }
   ll ans=n-s;
    if(ans<0)
        cout<<"-1"<<endl;
    else
        cout<<ans<<endl;
}


Measured memory_bytes: 3708
/*
 * Author : Sadi
 * Sat 04/07/2020
 * 20:34:11.97
 */
#include <iostream>
#include <string>
#include <iomanip>
#include <sstream>
#include <algorithm>
#include <vector>
#include <map>
#include <set>
#include <bitset>
#include <cassert>

using namespace std;

#define    watch(x); cout << "\n" <<  #x << " is: " << x << "\n";
#define    all(a) (a).begin(), (a).end()
#define    fi first
#define    se second

template<class A, class B>
ostream& operator << (ostream& output, const pair<A, B>& p) {
    output << "(" << p.first << ", " << p.second << ")";
    return output;
}

template<class A>
ostream& operator << (ostream& output, const vector<A>& a) {
    output << "[";
    for(auto it = a.begin(); it != a.end(); ++it) {
        if(it != a.begin()) {
            output << ", ";
        }
        output << *it;
    }
    output << "]";
    return output;
}

using lld = long long;
using pii = pair<int, int>;
using pll = pair<lld, lld>;

//const int inf = 1e9;
//const int mod = 1e9 + 7;
//const double PI = acos(-1.0);
//const int mx = 1e5 + 5;



int main()
{
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
#ifndef ONLINE_JUDGE
//    freopen("input.txt", "r", stdin);
//    freopen("output.txt", "w", stdout);
#endif // ONLINE_JUDGE

    int n;
    cin >> n;
    double total = 0;
    for(int i = 0; i < n; ++i) {
        double money;
        string type;
        cin >> money >> type;
        if(type == "JPY") {
            total += money;
        }
        else {
            total += money * 380000.0;
        }
    }
    cout << fixed << setprecision(5) << total << endl;
    return 0;
}


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

// グラフ
using Edge = pair<int, ll>;         // {行き先,重み}
using Graph = vector<vector<Edge>>; // グラフ

vector<ll> dist;
Graph G;
void dfs(int v, int p, ll d){
  dist[v] = d;
  for(auto e : G[v]){
    if(e.first == p) continue;
    dfs(e.first, v, d + e.second);
  }
}

int main() {
  int n;
  cin >> n;
  dist.resize(n);
  G.resize(n);
  rep(i, n-1){
    int a, b, c;
    cin >> a >> b >> c;
    a--, b--;
    G[a].push_back(make_pair(b, c));
    G[b].push_back(make_pair(a, c));
  }
  int q, k;
  cin >> q >> k;
  k--;
  dfs(k, -1, 0);
  rep(i,q){
    int x, y;
    cin >> x >> y;
    x--, y--;
    cout << dist[x] + dist[y] << endl;
  }
}

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

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

int main(){
	int N,a[100005]={0};
	scanf("%d",&N);
	for(int i=0;i<N;i++){
		scanf("%d",&a[i]);
	}
	qsort(a,N,sizeof(a[0]),cmp);
	int cnt=1,res=0;
	for(int i=1;i<N;i++){
		if(a[i]!=a[i-1]){
			if(cnt%2!=0){
				res++;
			}
			cnt=1;
		}
		else{
			cnt++;
		}
	}
	if(cnt%2!=0){
		res++;
	}
	printf("%d",res);
}

Measured memory_bytes: 892
#include <string>
#include <vector>
#include <iostream>

#include <atcoder/segtree.hpp>

#ifdef USE_PYTHON_LIKE_PRINT
#include "print.h"
#else
template<char SEP = ' ', char END = '\n'> inline void print(...){}
template<char SEP = ' ', char END = '\n'> inline void printe(...){}
template<char SEP = ' ', char END = '\n'> inline void printo(...){}
#define define_print(...)
#define define_print_with_names(...)
#define define_to_tuple(...)
#endif

using namespace std;

typedef int S;
typedef int F;
S op(S a, S b) { return max(a, b); }
S e() { return 0; }


template<class ST>
std::vector<S> to_vector(ST st, int n){
	std::vector<S> vec(n);
	for(int i = 0; i < n; i ++){
		vec[i] = st.get(i);
	}
	return vec;
}

const int A_MAX = 300000;

int main(void){
	int N, K;
	cin >> N;
	cin >> K;
	
	atcoder::segtree<S, op, e> st(vector<S>(A_MAX + 1, 0));
	
	int A;
	cin >> A;
	st.set(A, 1);
	
	for(int i = 1; i < N; i ++){
		cin >> A;
		st.set(A, st.prod(max(A - K, 0), min(A + K + 1, A_MAX + 1)) + 1);
	}
	
	int result = 0;
	for(int i = 0; i < A_MAX + 1; i ++){
		int count = st.get(i);
		if(count > result){
			result = count;
		}
	}
	cout << result << endl;
	
	return 0;
}


Measured memory_bytes: 8112