akhauriyash/Code-Regression huggingface dataset:
/*
confirm 0LL and 1LL
confirm cornercases such as 0
confirm times of cin < 10^6
*/
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
using P = pair<ll, ll>;
using Pld = pair<ld, ld>;
using Vec = vector<ll>;
using VecP = vector<P>;
using VecB = vector<bool>;
using VecC = vector<char>;
using VecD = vector<ld>;
using VecS = vector<string>;
using Graph = vector<VecP>;
template <typename T>
using Vec1 = vector<T>;
template <typename T>
using Vec2 = vector<Vec1<T> >;
#define REP(i, m, n) for(ll (i) = (m); (i) < (n); ++(i))
#define REPN(i, m, n) for(ll (i) = (m); (i) <= (n); ++(i))
#define REPR(i, m, n) for(ll (i) = (m)-1; (i) >= (n); --(i))
#define REPNR(i, m, n) for(ll (i) = (m); (i) >= (n); --(i))
#define rep(i, n) REP(i, 0, n)
#define repn(i, n) REPN(i, 1, n)
#define repr(i, n) REPR(i, n, 0)
#define repnr(i, n) REPNR(i, n, 1)
#define all(s) (s).begin(), (s).end()
#define pb push_back
#define fs first
#define sc second
template <typename T>
bool chmax(T &a, const T b){if(a < b){a = b; return true;} return false;}
template <typename T>
bool chmin(T &a, const T b){if(a > b){a = b; return true;} return false;}
template <typename T>
ll pow2(const T n){return (1LL << n);}
template <typename T>
void cosp(const T n){cout << n << ' ';}
void co(void){cout << '\n';}
template <typename T>
void co(const T n){cout << n << '\n';}
template <typename T1, typename T2>
void co(pair<T1, T2> p){cout << p.fs << ' ' << p.sc << '\n';}
template <typename T>
void co(const Vec1<T> &v){for(T i : v) cosp(i); cout << '\n';}
template <typename T>
void co(initializer_list<T> v){for(T i : v) cosp(i); cout << '\n';}
template <typename T>
void ce(const T n){cerr << n << endl;}
void sonic(){ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);}
void setp(const ll n){cout << fixed << setprecision(n);}
constexpr ll INF = 1e9+1;
constexpr ll LINF = 1e18+1;
constexpr ll MOD = 1e9+7;
//constexpr ll MOD = 998244353;
constexpr ld PI = acos(-1);
constexpr ld EPS = 1e-11;

ll cnt[1000001] = {};

int main(void){
	ll n;
	cin >> n;
	string s;
	cin >> s;
	Vec a(n);
	bool flg = true;
	rep(i, n){
		a[i] = s[i] - '1';
		flg &= (a[i] != 1);
	}

	if(flg){
		rep(i, n) a[i] /= 2;
	}else{
		rep(i, n) if(a[i] == 2) a[i] = 0;
	}

	repn(i, 1e6){
		ll t = 0;
		ll m = i;
		while(m % 2 == 0){
			t++;
			m /= 2;
		}
		cnt[i] = cnt[i - 1] + t;
	}

	ll ans = 0;
	rep(i, n){
		if(cnt[n - 1] <= cnt[i] + cnt[n - 1 - i]) ans += a[i];
	}
	ans %= 2;
	if(flg) ans *= 2;
	co(ans);

	return 0;
}


Measured memory_bytes: 17028
ABCD = list(input())
ope = ['+', '-']
for i in range(2**3):
    f = ABCD[0]
    for j in range(3):
        if i >> j & 1:
            f += '+'
        else:
            f += '-'
        f += ABCD[j+1]
    if eval(f) == 7:
        print(f+"=7")
        exit()

Measured memory_bytes: 9064
'use strict'
function main(input) {
    const tmp = Array.from(input.split(' '));

    const N = parseInt(tmp[0], 10);
    const A = parseInt(tmp[1], 10);
    const taxiFee = parseInt(tmp[2], 10);

    const trainFee = A * N;

    console.log(Math.min(trainFee, taxiFee));
}
main(require('fs').readFileSync('/dev/stdin', 'utf8'));

Measured memory_bytes: 22080
#include<bits/stdc++.h>
using namespace std;
int main(){
  int N,T;cin>>N>>T;
  vector<int> S(N),A(N),B(N);
  for(int i=0;i<N;i++){
    cin>>S[i];
  }
  A[0]=S[0];
  B[N-1]=S[N-1];
  for(int i=1;i<N;i++){
    if(S[i]<A[i-1]) A[i]=S[i];
    else A[i]=A[i-1];
  }
  for(int i=N-2;i>=0;i--){
    if(S[i]>B[i+1]) B[i]=S[i];
    else B[i]=B[i+1];
  }
  int rieki=0,cnt=0,x=0,y=0;
  for(int i=0;i<N-1;i++){
    if(B[i+1]-A[i]>rieki){
      rieki=B[i+1]-A[i];
      cnt=1;
    }
    else if(B[i+1]-A[i]==rieki&&!(A[i]==A[i-1]&&B[i+1]==B[i])) cnt++;
  }
  cout<<cnt<<endl;
}

Measured memory_bytes: 1408
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner s = new Scanner(System.in);
		
		while(true) {
			int x = s.nextInt();
			int y = s.nextInt();
			if(x == 0 && y == 0) {
				return;
			} else if(x <= y) {
				System.out.println(x + " " + y);
			} else {
				System.out.println(y + " " + x);
			}
			
		}
	}

}

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

int main ()
{
	string a,b,c;  cin>>a>>b>>c;
	
	char m='A'-'a';
	
	printf("%c%c%c\n",a[0]+m,b[0]+m,c[0]+m);
	
     return 0;

}



Measured memory_bytes: 3720
import java.util.*;

public class Main {
	public static void main(String[] args)  {
		Scanner scan = new Scanner(System.in);
		int n=Integer.parseInt(scan.next());
		int[] ans =new int [n];
		Arrays.fill(ans, 0);
		int a;
		for (int i=0;i<n-1;++i){
			a=Integer.parseInt(scan.next());
			ans[a-1]+=1;
		}

		for(int i=0;i<n;++i){
			System.out.println(ans[i]);
		}




	}
}
//end

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


int main(){
	int h, w;
	cin >> h >> w;
	vector<string> grid(h);
	rep(i,h) cin >> grid[i];

	vector<vector<int>> dist(h, vector<int>(w,-1));
	dist[0][0] = 0;
	queue<pair<int,int>> que;
	que.push(make_pair(0,0));
	int dir[4] = {0,1,0,-1};

	while(!que.empty()){
        auto t = que.front();
        que.pop();
        rep(i,4){
            int nr = t.first + dir[i];
            int nc = t.second + dir[3-i];
            if(0 <= nr && nr < h && 0 <= nc && nc < w && grid[nr][nc] != '#' && dist[nr][nc] == -1){
                dist[nr][nc] = dist[t.first][t.second] + 1;
                que.push(make_pair(nr, nc));
            }
        }
	}
	int shortest_dist = dist[h-1][w-1];
	if(shortest_dist == -1){
        cout << -1 << endl;
        return 0;
	}

	int cnt = 0;
	rep(i,h)rep(j,w) if(grid[i][j] == '#') cnt++;
	cout << h*w - cnt - shortest_dist-1 << endl;
}


Measured memory_bytes: 256
N = gets.to_i
arr = gets.split.map(&:to_i)

arr_with_i = arr.map.with_index do|num, index|
  [num, index + 1]
end

sorted_arr = arr_with_i.sort_by { |num, i| num }

puts sorted_arr.map { |_num, i| i }.join(" ")

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

int main() {
	int n,m_front,m_back;
	cin >> n;
	vector<pair<long long,int>> x(n);
	vector<long long> y(n);

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

		cin >> y.at(i);
		x.at(i).first = y.at(i);
		x.at(i).second = i;
	}
	sort(x.begin(), x.end());

	m_front = x.at(n / 2 - 1).second;
	m_back = x.at(n / 2).second;

	for (int i = 0; i < n; i++) {
		if (i == m_front) {
			cout << x.at(n / 2).first << endl;
		}
		else if (i == m_back){
			cout << x.at(n / 2 - 1).first << endl;
		}
		else if (y.at(i) <= x.at(n / 2 - 1).first) {
			cout << x.at(n / 2).first << endl;
		}
		else{
			cout << x.at(n / 2 - 1).first << endl;
		}
	}
}

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

#define ONLINE_JUDGE
#define pb(a) push_back(a)
#define all(a) (a.begin(), a.end())

using ll = long long;

const int E5 = 1e5;

//////////// Solution /////////////////////////////////

int n,h[100];

bool water() {
	bool flag = false;
	int i = 0;
	while (i < n) {
		if (h[i] != 0) {
			flag = true;
			break;
		}
		++i;
	}

	while (i < n && h[i] != 0) {
		h[i]--;
		++i;
	}

	return flag;
}

void solve() {
	cin >> n;
	for (int i = 0;  i< n; ++i) {
		cin >> h[i];
	}

	int ans = 0;
	bool flag = true;
	while (1) {
		flag = water();
		if (!flag) break;
		++ans;
	}

	cout << ans << '\n';
}	

/////////// End Solution ///////////////////////////////////////

//////// Initialization ////////////////////////////////////

int main() {

	#ifndef ONLINE_JUDGE
	FILE *FIN = freopen("/home/danil/prog/input.txt", "r", stdin);
	clock_t time_start = clock();
	#endif

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

	solve();

	#ifndef ONLINE_JUDGE
	fclose(FIN);
	cerr << "\x1b[031m\n-----------------\nTime=" << (ll)((double)(clock()-time_start) / CLOCKS_PER_SEC * 1000) << "ms\n\x1b[0m";
	#endif

	return 0;
}

//////// End Initialization ///////////////////////////////////////

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

#define NDEBUG
#ifdef DEBUG
#include "../cout11.h"
#undef NDEBUG
#endif
#include <cassert>

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> ii;
typedef pair<ll,ll> llll;
typedef pair<double,double> dd;

typedef vector<int> vi;
typedef vector<vector<int>> vvi;
typedef vector<ii> vii;
typedef vector<vector<ii>> vvii;
typedef vector<ll> vll;

#define sz(a)  int((a).size())
#define pb  push_back
#define FOR(var,from,to) for(int var=(from);var<=(to);++var)
#define rep(var,n)  for(int var=0;var<(n);++var)
#define rep1(var,n)  for(int var=1;var<=(n);++var)
#define repC2(vari,varj,n)  for(int vari=0;vari<(n)-1;++vari)for(int varj=vari+1;varj<(n);++varj)
#define ALL(c)  (c).begin(),(c).end()
#define RALL(c)  (c).rbegin(),(c).rend()
#define tr(i,c)  for(auto i=(c).begin(); i!=(c).end(); ++i)
#define found(s,e)  ((s).find(e)!=(s).end())
#define mset(arr,val)  memset(arr,val,sizeof(arr))
#define mid(x,y) ((x)+((y)-(x))/2)
#define IN(x,a,b) ((a)<=(x)&&(x)<=(b))

#define INTSPACE 12
char _buf[INTSPACE*1000000 + 3];

int loadint() {
    if (fgets(_buf, INTSPACE+3, stdin)==NULL) return 0;
    return atoi(_buf);
}

int loadvec(vector<int>& v, int N=-1) {
    if (N == -1) {
        N = loadint();
        if (N==0) return 0;
    }
    int bufsize = INTSPACE*N + 3;
    if (fgets(_buf, bufsize, stdin)==NULL) return 0;
    v.resize(N);

    int i=0;
    bool last = false;
    for (char *p=&_buf[0]; ;) {
        char *q = p;
        while (*q > ' ') ++q;
        if (*q == 0x0D || *q == 0x0A) last = true;
        *q = 0;
        v[i++] = atoi(p);
        if (last || i == N) break;
        p = q+1;
    }
    // assert(i <= N);
    return i;
}

ll gcd(ll a, ll b) { while(a) swap(a, b%=a); return b; }

const ll M=1000000007LL;

ll ADD(ll x, ll y) { return (x+y) % M; }
ll SUB(ll x, ll y) { return (x-y+M) % M; }
ll MUL(ll x, ll y) { return x*y % M; }
ll POW(ll x, ll e) { ll v=1; for(; e; x=MUL(x,x), e>>=1) if (e&1) v = MUL(v,x); return v; }
ll DIV(ll x, ll y) { assert(y%M!=0); return MUL(x, POW(y, M-2)); }
// ll comb(ll n, ll k) { ll v=1; for(ll i=1; i<=k; i++) v = DIV(MUL(v, n-i+1),i); return v; }

ll solve(int N, vi& a) {
    vi st(N, 0);
    for (int item: a) ++st[item];

    ll sum = 0;
    rep(i,N) sum += st[i];
    if (sum != N) return 0;

    ll ans = 1LL;

    if (N % 2 == 1 && st[0] == 1) {
        int h = N/2;
        for (int i=1; i<=h; ++i) {
            if (st[2*i] != 2) return 0;
            ans = MUL(ans, 2);
        }
    } else if (N % 2 == 0 && st[0] == 0 && st[1] == 2) {
        int h = N/2;
        for (int i=0; i<h; ++i) {
            if (st[2*i+1] != 2) return 0;
            ans = MUL(ans, 2);
        }
    } else {
        return 0;
    }
    return ans;
}

int main() {
    vi a;
    int N = loadvec(a);
    cout << solve(N,a) << endl;
    return 0;
}


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

int main() {
  string s;
  cin >> s;
  if (s.at(0) == '7' || s.at(1) == '7' || s.at(2) == '7')
    cout << "Yes" << endl;
  else
    cout << "No" << endl;
}


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

inline int toInt(string s) {int v; istringstream sin(s);sin>>v;return v;}
template<class T> inline string toString(T x) {ostringstream sout;sout<<x;return sout.str();}

template<class T> inline T sqr(T x) {return x*x;}

typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> P;
typedef long long ll;

#define ALL(a)  (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define MP make_pair
#define SZ(a) int((a).size())
#define EACH(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort((c).begin(),(c).end())
#define REVERSE(c) reverse((c).begin(),(c).end())

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

const double EPS = 1e-10;
const double PI  = acos(-1.0);
const long long INF = 1000000007;

#define CLR(a) memset((a), 0 ,sizeof(a))

#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;

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

int main(void){
    int H,W; cin >> H >> W;
    char a[H][W]; REP(i,H)REP(j,W) cin >> a[i][j];
    ll dp[H][W]; memset(dp, 0, sizeof(dp));
    dp[0][0] = 1;
    REP(i,H)REP(j,W){
        if(a[i][j] == '#') continue;
        if(i<H-1) dp[i+1][j] = (dp[i+1][j] + dp[i][j])%INF;
        if(j<W-1) dp[i][j+1] = (dp[i][j+1] + dp[i][j])%INF;
    }
    cout << dp[H-1][W-1] << endl;
    return 0;
}

Measured memory_bytes: 9088
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <stack>
#include <queue>
#include <list>
#include <set>
#include <map>
#include <numeric>
#include <regex>
#include <tuple>
#include <iomanip>
#include <math.h>
using namespace std;

typedef long long ll;
typedef pair<int, int> P;
#define MOD 1000000007 // 10^9 + 7
#define INF 1000000000 // 10^9
#define LLINF 1LL<<60
const double PI = 3.14159265358979323846;

vector<vector<P>> G(100009);
int Col[100009]; // i番目の辺の色
bool isfound[100009];

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

	int N; cin >> N;
	for (int i = 1; i < N; i++) {
		int a, b;
		cin >> a >> b;
		G[a].push_back(P(b, i));
		G[b].push_back(P(a, i));
	}
	//cout << "ok1" << endl;

	int ans = 0;
	for (int i = 1; i <= N; i++) {
		int num = G[i].size();
		ans = max(ans, num);
	}
	//cout << "ok2" << endl;

	queue<int> Q;
	Q.push(1); isfound[1] = true;
	while (!Q.empty()) {
		int pos = Q.front();
		Q.pop();
		int used_color = -1;
		for (int i = 0; i < G[pos].size(); i++) {
			if (Col[G[pos][i].second] != 0) used_color = Col[G[pos][i].second];
		}
		int cnt = 1;
		for (int i = 0; i < G[pos].size(); i++) {
			if (!isfound[G[pos][i].first]) {
				isfound[G[pos][i].first] = true;
				Q.push(G[pos][i].first);
				if (cnt == used_color) cnt++;
				Col[G[pos][i].second] = cnt;
				cnt++;
				//cout << "(" << pos << "," << G[pos][i].first << ")" << endl;
			}
		}
		//cout << "for loop 内" << pos << endl;
	}
	cout << ans << endl;
	for (int i = 1; i < N; i++) cout << Col[i] << endl;

	return 0;
}

Measured memory_bytes: 7040
#include <malloc.h>
#include <math.h>
#include <stdio.h>
#include <string.h>
#include <stdlib.h>

//ABC124A
int main(void) {
  int n, k, i, cou=0, a, b, tmp;
  scanf("%d %d", &a, &b);
  if(a==b) printf("%d", a+b);
  else if(a>b) printf("%d", 2*a-1);
  else printf("%d", 2*b-1);
}

Measured memory_bytes: 128
N = int(input())
li = list(map(int, input().split()))

ans = 0
k = 1

flags = [li[i] >= k for i in range(N)]
flags.append(False)

while any(flags):
    cnt = 0
    for i in range(N):
        if flags[i] and not flags[i + 1]:
            cnt += 1

    k += 1
    ans += cnt
    flags = [li[i] >= k for i in range(N)]
    flags.append(False)

print(ans)


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





int main() {
  vector<int> vec{0,2,0,1,0,1,0,0,1,0,1,0};
  int A,B;
  
  
  cin>>A>>B;
  
  if (vec.at(A-1)==vec.at(B-1)){
    cout<<"Yes"<<endl;
  }
  else {
    cout<<"No"<<endl;
  }
  
}













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

#define debug(x) cout <<"DEBUG"<<" "<< #x << ":" << x << '\n'

// n回繰り返し
#define rep(i,n) for(int i = 0; i < ((int)(n)); i++)   // 0-indexed昇順
#define rep1(i,n) for(int i = 1; i <= ((int)(n)); i++) // 1-indexed昇順
#define rrep(i,n) for(int i = ((int)(n)-1); i >= 0; i--)  // 0-indexed降順
#define rrep1(i,n) for(int i = ((int)(n)); i >= 1; i--)   // 1-indexed降順
#define all(x) (x).begin(),(x).end()

typedef long long ll;
typedef long double ld;
typedef vector<int> vi;
typedef vector<vi> vii;  // 2次元配列
typedef vector<ll> vll;
typedef vector<double> vd;
typedef pair<int, int> PII;

template<typename T>
using vec = vector<T>;
template<class T>
using maxheap = std::priority_queue<T>;
template<class T>
using minheap = std::priority_queue<T, std::vector<T>, std::greater<T>>;

template<class T,class U> inline bool chmax(T &a, const U &b){if(a<b){a=b;return 1;}return 0;}
template<class T,class U> inline bool chmin(T &a, const U &b){if(a>b){a=b;return 1;}return 0;}

const ld Pi = std::acos(-1.0L);
const ll infll = (1LL<<62)-1;
const int inf = (1<<30)-1;
const int mod = 1000000007;
// const int mod = 998244353;


/*FUNCs=================================================*/


/*MAIN==================================================*/
signed main(){
    int _StartTime_ = clock();
    cin.tie(nullptr);
    ios::sync_with_stdio(false);   //cin cout 高速化
    // cout << fixed << setprecision(15);

    int n, total = 0; cin >> n;
    vec<int> d(n); rep(i,n) cin >> d[i];
    rep(i,n) total+=d[i];

    vec<int> m(n);
    m[0] = [&]() {
        int ret = 0;
        for(int i = 0; i < n; i += 2) ret += d[i];
        return ret - total/2;
    }();

    for(int i = 0; i < n-1; ++i) {
        m[(i+1)%n] = d[i%n] - m[i%n];
    }

    rep(i,n) cout << 2*m[i] << (i==n-1 ? '\n' : ' ');

    // printf("ExecutionTime: %d /ms\n",1000*(int)((clock()-_StartTime_)/CLOCKS_PER_SEC));
}

Measured memory_bytes: 2176
// SeeAlso: https://atcoder.jp/contests/abc142/tasks/abc142_d

#include <bits/stdc++.h>

using namespace std;

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

#define MAX 100000
#define NIL -1
#define MOD 1000000007

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

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

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

// 最大公約数
inline constexpr ll gcd(ll a,ll b){if(!a||!b)return 0;while(b){ll c=b;b=a%b;a=c;}return a;}
// 最小公倍数
inline constexpr ll lcm(ll a,ll b){if(!a||!b)return 0;return a*b/gcd(a,b);}

#define print2D(h, w, arr) REP(i, h) { REP(j, w) cout << arr[i][j] << " "; cout << endl; }
template<class T> void print(const T& x){cout << setprecision(12) << x << endl;}
template<class T, class... A> void print(const T& first, const A&... rest) { cout << first << " "; print(rest...); }

ll A, B;

/// 互いに素
bool coprime(ll a, ll b) {
  return (gcd(a, b) == 1);
}

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

    ll g = gcd(A, B);
    ll ans = 1;

    for(ll i =2;i*i<g;i++) { 
        if(g%i==0){
            ans++;
            while(g%i==0){
                g/=i;
            }
            
        }
    }

    if(g!=1){ans++;}
    
    print(ans);
    return 0;
}


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

#define N 101
#define RIGHT 100

int shiki[N];
int n;
long long memo[N][21];

// i番目の数字, 今までの合計値
long long getWay(int i, int num)
{
	long long ret = 0;
	int dx[] = {1, -1};
	int j;
	
	if (memo[i][num] != -1){
		return (memo[i][num]);
	}
	
	if (i == n - 2){
		if (num == shiki[RIGHT]){
			return (1);
		}
		return (0);
	}
	
	for (j = 0; j < 2; j++){
		int val = num + shiki[i + 1] * dx[j];
		
		if (val >= 0 && val <= 20){
			ret += getWay(i + 1, val);
		}
	}
	
	return (memo[i][num] = ret);
}

int main(void)
{
	int i;
	
	memset(memo, -1, sizeof(memo));
	
	scanf("%d", &n);
	for (i = 0; i < n - 1; i++){
		scanf("%d", shiki + i);
	}
	scanf("%d", shiki + RIGHT);
	
	printf("%lld\n", getWay(0, shiki[0]));
	
	return (0);
}

Measured memory_bytes: 628
#include <iostream>
#include <vector>
#include <cmath>
#include <map>

typedef long long int ll;

using namespace std;
int A, B;

int main()
{
  int n;

  cin >> A >> B;

  for (n=B*10; n<B*10+10; n++) {
    if (n*8/100 == A) {
      break;
    }
  }
//printf("n = %d\n", n);
  if (n*8/100 == A && n/10 == B)
    printf("%d\n", n);
  else
    printf("-1\n");

  return 0;
}

/*
  n * 0.08 = A
  n * 0.1  = B

  n = A*100/8
  n = A*10..A*10+1
  */


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define ull unsigned long long
#define pb push_back
#define ps push
#define pf push_front
#define mp make_pair
#define And &&
#define Or ||
#define inf INT_MAX
#define sz(name) name.size()
#define len(name) name.length()
#define ig cin.ignore()
#define sc1(name) scanf("%d",&name)
#define sc2(name1,name2) scanf("%d%d",&name1,&name2)
#define sc3(name1,name2,name3) scanf("%d%d%d",&name1,&name2,&name3)
#define scl1(name) scanf("%lld",&name)
#define scl2(name1,name2) scanf("%lld%lld",&name1,&name2)
#define scl3(name1,name2,name3) scanf("%lld%lld%lld",&name1,&name2,&name3)
#define Sort(name) sort(name.begin(),name.end())
#define SSort(name) sort(name.rbegin(),name.rend())
#define For(name,start,finish) for(int name=start;name<finish;name++)
#define Forr(name,start,finish) for(int name=start;name>=finish;name--)
#define fast_in_out ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);


int row[]={0,1,0,-1,-1,-1,1,1};
int col[]={1,0,-1,0,1,-1,-1,1};

const ll N=2e5+10;
const ll M=1e18+7;
const ll H=1e9+7;
const ll base=131;

ll logx(ll a,ll bs){return log(a)/log(bs);}
ll Max(ll a,ll b){if(a>b)return a;return b;}
ll Min(ll a,ll b){if(a>b)return b;return a;}
ll big_mul(ll a,ll b,ll m){ll x=0,y=a%m;while(b>0){if(b&1)x=(x+y)%m;y=(2*y)%m;b>>=1;}return x%m;}
ll big_mod(ll a,ll b,ll m){ll x=1,y=a%m;while(b>0){if(b&1)x=(x*y)%m;y=(y*y)%m;b>>=1;}return x%m;}
ll Big_mod(ll a,ll b,ll m){ll x=1,y=a%m;while(b>0){if(b&1)x=big_mul(x,y,m);y=big_mul(y,y,m);b>>=1;}return x%m;}
ll mod_inverse(ll a,ll m){return big_mod(a,m-2,m);}  //a^-1 mod m = a^(m-2) mod m
ll GCD(ll a,ll b){if(!a)return b;return GCD(b%a,a);}



int main()
{
    fast_in_out;


    ll n,d;
    cin>>n>>d;

    int ans=0;

    For(i,0,n)
    {
        ll a,b;
        cin>>a>>b;

        if(a*a+b*b<=d*d)
            ans++;
    }

    cout<<ans<<endl;

    return 0;
}



Measured memory_bytes: 3700
#include <stdio.h>

int 
main(){
	
	long int N,i;
	scanf("%ld",&N);
	long int a[N];
	long int b[N];
	long int cnt=0;

	for(i=0;i<=N;i++){
		scanf("%ld",&a[i]);
	}
	for(i=0;i<N;i++){
		scanf("%ld",&b[i]);
	//}

	//for(i=0;i<N;i++){
		if(a[i]>=b[i]){ cnt += b[i];
		//	printf("[-%d]%ld,%ld,%ld,%ld,\n",cnt,a[i],a[i+1],b[i]);
		}
		else{
			long int a_ = a[i+1]+a[i];
			if(a_>=b[i]){
				cnt+= b[i];
				a[i+1] -= b[i]-a[i]; 
		//		printf("[%d]%ld,%ld,%ld,%ld,\n",cnt,a[i],a[i+1],b[i]);
			}
			else{
				cnt+= a_;
				a[i+1]=0;
		//		printf("[e%d]%ld,%ld,%ld,%ld,\n",cnt,a[i],a[i+1],b[i]);
			}
				
		}
	}
	printf("%ld\n",cnt);
 return 0;
}


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

const int N=2010,mo=int(1e9+7);
int n,k,f[N][N],fac[N*N],ifac[N*N];

int qpow(int a,int b)
{
	int x=a;  a=1;
	while (b)
		{
			if (b&1)  a=1LL*a*x%mo;
			x=1LL*x*x%mo,b>>=1;
		}
	return a;
}

int C(int n,int m){return 1LL*fac[n]*ifac[m]%mo*ifac[n-m]%mo;}

void work()
{
	scanf("%d %d",&n,&k);
	if (k==1)  puts("1"),exit(0);
	fac[0]=1;
	for (int i=1; i<=n*k; i++)  fac[i]=1LL*fac[i-1]*i%mo;
	ifac[n*k]=qpow(fac[n*k],mo-2);
	for (int i=n*k; i; i--)  ifac[i-1]=1LL*ifac[i]*i%mo;
	f[0][0]=1;
	for (int i=0; i<=n; i++)
		for (int j=i; j<=n; j++)
			{
				if (i<j)  (f[i+1][j]+=f[i][j])%=mo;
				if (j<n)  f[i][j+1]=(f[i][j+1]+1LL*f[i][j]*C(i-1+(k-1)*(j+1),k-2))%mo;
			}
	printf("%d",int(1LL*f[n][n]*fac[n]%mo));
}

int main()
{
	work();
	return 0;
}


Measured memory_bytes: 47488
#include <stdio.h>

#include <algorithm>
#include <iostream>
#include <vector>
using namespace std;

int main() {
    long long int N, K;
    cin >> N >> K;
    vector<long long int> H(N);
    for (long long int i = 0; i < N; i++) {
        int tmp;
        cin >> tmp;
        H[i] = tmp;
    }
    std::sort(H.begin(), H.end(), std::greater<int>());

    long long int counter = 0;
    for (long long int i = 0; i < N; i++) {
        if (i <= K - 1) {
            continue;
        } else {
            counter += H[i];
        }
    }
    cout << counter << endl;
}


Measured memory_bytes: 1792
#include <bits/stdc++.h>
#define ll long long int
#define FASTIO std::ios::sync_with_stdio(false);
#define pb push_back
#define mp make_pair
#define F first
#define S second
#define inf 1e18
#define g(x) cout<<x<<" "<<endl;
#define gg(x,y) cout<<x<<" & "<<y<<" "<<endl
#define jam(t) cout<<"Case #"<<t<<": "
#define ggg(x,y,z) cout<<x<<" & "<<y<<" & "<<z<<" "<<endl
#define all(x) x.begin(),x.end()
#define input_from_file  freopen("input.txt", "r", stdin);
#define mod 1000000007ll
#define sz 400005
#define bitcnt(x) __builtin_popcountll(x)
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
using namespace std;
template <typename Arg1>
void __f(const char* name, Arg1&& arg1){
    cout << name << " : " << arg1 << endl;
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args){
    const char* comma = strchr(names + 1, ',');cout.write(names, comma - names) << " : " << arg1<<" | ";__f(comma+1, args...);
}


template<int SZ> struct Combo {
    ll fac[SZ+1], ifac[SZ+1];
    
    Combo() {
        fac[0] = ifac[0] = 1;
        for(ll i=1;i< (SZ+1);i++) {
            fac[i] = i*fac[i-1] % mod;
            ifac[i] = inv(fac[i]);
        }
    }
    
    ll po (ll b, ll p) {
        return !p?1:po(b*b%mod,p/2)*(p&1?b:1)%mod;
    }
    
    ll inv (ll b) { return po(b,mod-2); }
    
    ll comb(ll a, ll b) {
        if (a < b) return 0;
        ll tmp = fac[a]*ifac[b] % mod;
        tmp = tmp*ifac[a-b] % mod;
        return tmp;
    }
};
Combo <1000000> C;
void solve(){
    ll n,k;
    cin >> n >> k;
    k = min(k,n-1);
    ll an = 0;
    for(ll i=0;i<=k;i++){
        an += (C.comb(n,i) * C.comb(n-1,n-i-1))%mod;
        an%=mod;
    }
    g(an);
}
int main()
{

 
    FASTIO
    cin.tie(NULL);
    fflush(stdout);
    ll t = 1;
    //cin >> t;
    for(ll tcase = 1;tcase <= t;tcase++){
        solve();
        
    }
return 0;
}

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

int main() {
    int N; cin >> N;
    string s = to_string(N);
    int a = 0;
    for (int i = 0; i < s.size(); i++)
    {
        a += s[i] - '0';
    }
    if(N%a==0) cout << "Yes" << endl;
    else cout << "No" << endl;
}

Measured memory_bytes: 256
n,k = gets.split.map &:to_i
h = gets.split.map &:to_i

INF = 10**12
dp = Array.new(n,INF)
dp[0] = 0

1.upto(n-1) do |i|
  min = 10000000001
  [0,i-k].max.upto(i-1) do |j|
    cost = (h[i] - h[j]).abs + dp[j]
    min = cost if min > cost
  end
  dp[i] = min
end

puts dp[-1]

Measured memory_bytes: 11396
import sys
sys.setrecursionlimit(10**8)
def ii(): return int(sys.stdin.readline())
def mi(): return map(int, sys.stdin.readline().split())
def li(): return list(map(int, sys.stdin.readline().split()))
def li2(N): return [list(map(int, sys.stdin.readline().split())) for i in range(N)]
def dp2(ini, i, j): return [[ini]*i for i2 in range(j)]
#import bisect #bisect.bisect_left(B, a)
#from collections import defaultdict #d = defaultdict(int) d[key] += value
#from collections import Counter # a = Counter(A).most_common()
#from itertools import accumulate #list(accumulate(A))
from collections import deque

N = ii()
A = sorted(li(), reverse=True)

l = deque([A[1], A[1]])

ans = A[0]
for num in A[2:]:
    #print(l)
    ans += l.popleft()
    l.append(num)
    l.append(num)

print(ans)

Measured memory_bytes: 32552
#include <bits/stdc++.h>
#include <math.h>
#define REP(i, n) for(int i = 0; i < (n); i++)
#define ALL(v) (v).begin(), (v).end()
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
const int INF = 1001001001;
const int mINF = -1001001001;


int main() {
int a,b;
cin >> a >> b;
cout << 6-a-b << endl;
return 0;
}


Measured memory_bytes: 256
s = list(input())
k = int(input())
n = len(s)
for i in range(n):
    if s[i]=='a':continue
    d = ord('z')-ord(s[i])+1
    if d<=k:
        s[i] = 'a'
        k -= d

x = (ord(s[-1])-ord('a')+k)%26
s[-1] = chr(ord('a')+x)

print(''.join(s))


Measured memory_bytes: 4156
#include<iostream>
#include<cstdio>
using namespace std;
typedef long long ll;
ll n,k;
int main(){
	cin>>n>>k;
	ll ans=0;
	for (ll b=n;b>k;b--){
		ll l=k,r=b-1;
		ll c=(n+1)/b;
		ans+=c*(r-l+1);
		if (l==0) ans--;
		l=k+c*b;
		if (l<=n){
			ans+=n-l+1;
		}
	}

	cout<<ans;
}

Measured memory_bytes: 256
//C++14 (Clang 3.8.0)
 
#include <vector>
#include <list>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <ctime>
#include <string>
#include <climits>
using namespace std;
typedef long long ll;
typedef pair<long long,long long> P;
 
const int max_n=100001;
int x[max_n],y[max_n],c[max_n];
int dp[4010][4010];
int main(){
  int n,k;
  cin>>n>>k;
  for(int i=0;i<n;i++){
    int t1,t2;
    char cc;
    cin>>x[i]>>y[i]>>cc;
    if(cc=='B'){y[i]+=k;}
  	x[i]%=2*k;
  	y[i]%=2*k;
  	dp[x[i]+k-(k-1)][y[i]+k-(k-1)]++;
  	dp[x[i]+k+1][y[i]+k-(k-1)]--;
  	dp[x[i]+k-(k-1)][y[i]+k+1]--;
  	dp[x[i]+k+1][y[i]+k+1]++;
  }
	for(int i=0;i<4*k+1;i++){
		for(int j=1;j<4*k+1;j++){
			dp[i][j]+=dp[i][j-1];
		}
	}
	for(int i=1;i<4*k;i++){
		for(int j=0;j<4*k;j++){
			dp[i][j]+=dp[i-1][j];
		}
	}
	int res=-1;
	for(int i=0;i<2*k;i++){
		for(int j=0;j<2*k;j++){
			//cout<<i+k<<" "<<j+k<<" "<<<<" "<<j+k<<" "<<i+k<<" "<<(j+k+2*k)%(4*k)<<" "<<(i+k+k)%(4*k)<<" "<<(j+k+k)%(4*k)<<endl;
      int tmp=0;
      tmp+=dp[i+k][j+k];
      tmp+=dp[i+k][(j+k+2*k)%(4*k)];
      tmp+=dp[(i+k+2*k)%(4*k)][j+k];
      tmp+=dp[(i+k+k)][(j+k+k)];
      tmp+=dp[(i+k-k)][(j+k+k)];
      tmp+=dp[(i+k+k)][(j+k-k)];
      tmp+=dp[(i+k-k)][(j+k-k)];
      res=max(res,tmp);	
		}
	}
	cout<<res<<endl;
}

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

int main(){
    int h,w;
    cin>>h>>w;
    vector<vector<char>> s(h+2,vector<char>(w+2,'.'));
    for(int i=1;i<h+1;i++){
        for(int j=1;j<w+1;j++){
            cin>>s.at(i).at(j);
        }
    }
    for(int i=1;i<h+1;i++){
        for(int j=1;j<w+1;j++){
            if(s.at(i).at(j)=='.'){
                int num=0;
                if(s.at(i-1).at(j-1)=='#'){num++;}
                if(s.at(i).at(j-1)=='#'){num++;}
                if(s.at(i+1).at(j-1)=='#'){num++;}
                if(s.at(i-1).at(j)=='#'){num++;}
                if(s.at(i+1).at(j)=='#'){num++;}
                if(s.at(i-1).at(j+1)=='#'){num++;}
                if(s.at(i).at(j+1)=='#'){num++;}
                if(s.at(i+1).at(j+1)=='#'){num++;}
                cout<<num;
            }else{
                cout<<'#';
            }
            if(j==w){
                cout<<endl;
            }
        }
    }

}

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

#define ll long long
void sor(vector<ll> &x)
{
    sort(x.begin(), x.end());
}

ll gcd(ll x, ll y)
{
    if (y == 0)
    {
        return x;
    }
    return gcd(y, x % y);
}

list<ll> a[5];
void bfs(int src)
{
    queue<int> q;
    bool *vis = new bool[5 + 1]{0};
    q.push(src);
    vis[src] = true;
    while (!q.empty())
    {
        int node = q.front();
        cout << node << " ";
        q.pop();
        for (int n : a[node])
        {
            if (!vis[n])
            {
                q.push(n);
                vis[n] = true;
            }
        }
    }
}

ll min(ll x, ll y)
{
    if (x > y)
    {
        return y;
    }
    else
    {
        return x;
    }
}

int main()
{

    ll n, x;
    cin >> n >> x;
    ll ans = 3 * (n - gcd(n, x));
    cout << ans;
    return 0;
}

Measured memory_bytes: 3576
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();
        while(a!=0 && b!=0){
            for(int i=0;i<a;i++){
                for(int j=0;j<b;j++){
                    System.out.printf("#");
                }
                System.out.printf("\n");
            }
            System.out.printf("\n");
            a=sc.nextInt();
            b=sc.nextInt();
        }
    }
}


Measured memory_bytes: 64792
#include<bits/stdc++.h>
    #define REP(i,n) for(int i=0;i<n;i++)
    #define LOOP(i,x,n) for(int i=x;i<n;i++)
    #define ALL(v) (v).begin(),(v).end()
    #define PB push_back
    #define MP make_pair
    #define FIR first
    #define SEC second
    #define int long long
    using namespace std;
    const int MOD=1000000007;
    const int INF=1000000009;
     
     
    signed main(){
      int s;
      cin>>s;
      int d=s%10;
      int c=(s%100-d)/10;
      int b=(s%1000-c-d)/100;
      int a=(s-b-c-d)/1000;
      vector<string> str(20);
      vector<int> t(20);
      REP(i,8){
        str[i]=to_string(a);
        t[i]=a;
      }
      REP(i,4){
        t[i]+=b;
        str[i]+="+";
        str[i]+=to_string(b);
      }
      LOOP(i,4,8){
        t[i]-=b;
        str[i]+="-";
        str[i]+=to_string(b);
      }
      int tmp=1;
      for(int i=0;i<8;i+=2){
        if(tmp>0){
          t[i]+=c;
          str[i]+="+";
          str[i]+=to_string(c);
          t[i+1]+=c;
          str[i+1]+="+";
          str[i+1]+=to_string(c);
          tmp*=(-1);
        }else{
          t[i]-=c;
          t[i+1]-=c;
          str[i]+="-";
          str[i]+=to_string(c);
          str[i+1]+="-";
          str[i+1]+=to_string(c);
          tmp*=(-1);
        }
      }
      REP(i,8){
        if(i%2==0){
          t[i]+=d;
          str[i]+="+";
          str[i]+=to_string(d);
        }else{
          t[i]-=d;
          str[i]+="-";
          str[i]+=to_string(d);
        }
      }
     
      REP(i,8){
        if(t[i]==7){
          cout<<str[i]<<"=7"<<endl;
          return 0;
        }
      }
      
     
      return 0;
    }

Measured memory_bytes: 256
n, m = gets.split.map(&:to_i)
h = Array.new(n+1){Array.new(n+1)}
m.times{
	a, b = gets.split.map(&:to_i)
	h[a][b] = h[b][a] = true
}
puts (2..n).to_a.permutation.count{|a|
	a << 1
	a.each_cons(2).all?{|b| h.dig(*b)}
}


Measured memory_bytes: 1916
#define _GLIBCXX_DEBUG
#include<cmath>
#include <bits/stdc++.h>
typedef long long ll;
using namespace std;
vector<int> arr;
stack<int> st;
queue<int> qu;
queue<pair<int,int> > qu2;
priority_queue<int> pq,pq2;
#define rep(i,n) for(int i=0; i<(int)(n); i++)
#define rep2(i,n) for(int i=1; i<=(int)(n); i++)
typedef set<int> set_t;
typedef set<string> set_g;
typedef complex<double> xy_t;
static const int NIL = -1;

/*int P[10010];
void init(int n){
    for(int i=0;i<n;++i)P[i]=i;
}
int root(int a) {
    if(P[a]==a)return a;
    return (P[a]=root(P[a]));
}
bool is_same_set(int a,int b){
    return root(a) == root(b);//代表元を求める
}
void unite(int a,int b){
    P[root(a)]=root(b);
}//対set,グラフ？
//セグメント木？？？
*/

double dot_product(xy_t a, xy_t b) { return (conj(a)*b).real(); }//内積
double cross_product(xy_t a, xy_t b) { return (conj(a)*b).imag(); }//外積
xy_t projection(xy_t p, xy_t b) { return b*dot_product(p,b)/norm(b); }//投影
//対図形

#define mod 1000000007
/*ll f[2001];
//int n,k とかしておく

ll pw(ll x, ll y){//euclidの互除法より
    ll a= 1;
    while(y){
        if(y&1){//奇数なら
            a = a*x%mod;
        }
        x = x*x%mod;
        y /= 2;
    }
    return a;
}

ll modinv(ll x){//逆元を求める
    return pw(x, mod - 2 );
}

ll comb(int n,int r){
    if(n<r){
        return 0;
    }
    return f[n] * modinv(f[r])%mod*modinv(f[n-r])%mod;
}//対combination//ただしfは用意してね
*/

struct BIT{
    vector<int> dat;
    int sz;
    BIT(int n){
        for(sz=1;sz<n;sz *= 2);
        dat.resize(++sz);
    }
    int q(int n){
        int ret = 0;
        for(int i=n;i>0;i-=i&-i)ret +=dat[i];//和の計算　iから最後の１のbit(i&-i 多分＆はビット積)を減算
        for(int i=n;i<sz;i+=i&-i) dat[i]++;//値の加算　iから最後mの１のbitを加算
        return ret;
    }
};

int main(){
    int n,q;
    cin >> n>> q;
    string s;
    cin >> s;
    int m=s.size();
    int a[m+1];
    a[0]=0;
    rep(i,m){
        if(s[i]=='A'&&s[i+1]=='C'){
            a[i+1]=a[i]+1;
        }else{
            a[i+1]=a[i];
        }
    }
    rep(i,q){
        int l,r;
        cin >> l>> r;
        cout<<a[r-1]-a[l-1]<<endl;
    }
    return 0;
}

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

int main(void){
    int n, ii1;
    long sum = 0;
    scanf("%d", &n);
    for(ii1=0; ii1<=n; ii1++){
        if(ii1%5!=0 && ii1%3!=0)
          sum += ii1;
    }
    printf("%ld\n", sum);

    return 0;
}


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

using namespace std;

string amida[31];
int n, start, goal, d;

bool check(){
    int c = start;
    for(int i=0; i < d; i++){
        if(c < n-1 && amida[i][c] == '1') c++;
        else if(0 < c && amida[i][c-1] == '1') c--;
    }
    return c == goal;
}

bool is(int i, int j){
    if(amida[i][j] != '0') return false;
    if(0 < j && amida[i][j-1] == '1') return false;
    else if(amida[i][j+1] == '1') return false;
    return true;
}

int main(){
    while(cin >> n, n){
        cin >> start >> goal >> d;
        start--; goal--;
        for(int i=0; i < d; i++) cin >> amida[i];
        if(check()){cout << 0 << endl; continue;}
        bool f = false;
        for(int i=0; i< d; i++){
            for(int j=0; j < n-1; j++){
                if(!f && is(i, j)){
                    amida[i][j] = '1';
                    if(check()){cout << i+1 << " " << j+1 << endl; f = true;}
                    amida[i][j] = '0';
                }
            }
        }
        if(!f) cout << 1 << endl;
    }
}

Measured memory_bytes: 1208
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i,n) for(int i=0; i<(n); i++)
const int MX = 200005, MOD = 1e9+7, H = 5e8+4;
int n, p, len[MX], id[MX];
ll a;
vector<int> G[MX];
struct P{ll z,o;};
deque<P> qu[MX];
void merge(P &a, P&b){a.o = (a.o*b.z + a.z*b.o) % MOD; a.z = a.z*b.z % MOD;}
void rev(P &a){a.z = (MOD - a.o + 1) % MOD;}
void dfs(int u){
	int f = id[u] = u, s = 0;
	for(int &nx: G[u]){
		dfs(nx);
		if(len[f] < len[nx]){
			s = len[f];
			swap(f,nx);
		}else if(s < len[nx]) s = len[nx];
		rep(i,len[nx]) merge(qu[id[f]][i], qu[id[nx]][i]);
	}
	rep(i,s) rev(qu[id[f]][i]);
	qu[id[f]].push_front({H,H});
	id[u] = id[f];
	len[u] = len[f] + 1;
}
int main(){
  	cin >> n;
	rep(i,n){
		cin >> p;
		G[p].push_back(i+1);
	}
	dfs(0);
	for(P t: qu[id[0]]) a += t.o;
	a %= MOD;
	for(ll k = n+1, b = 2; k; k /= 2, (b*=b)%=MOD) if(k&1) (a*=b)%=MOD;
	cout << a << endl;
}


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

void display(int a[], int n)
{
	int i = 0;
	
	for (i = 0; i < n; i++) {
		if (i > 0)
			printf(" ");
		
		printf("%d", a[i]);
	}
	printf("\n");
}

int insertion_sort(int a[], int n)
{
	int i = 0, j = 0;
	int v = 0;
	
	for (i = 1; i < n; i++) {
		v = a[i];
		j = i - 1;
		while (j >= 0 && a[j] > v) {
			a[j+1] = a[j];
			j--;
		}
		
		a[j+1] = v;
		
		display(a, n);
	}
	return 0;
}

int main(int argc, char *argv[]) {
	
	int a[100];
	int i = 0;
	int n = 0;
	
	scanf("%d", &n);
	for (i = 0; i < n; i++) {
		scanf("%d", &a[i]);
	}	
	
	display(a, n);
	
	insertion_sort(a, n);

	return 0;
}

Measured memory_bytes: 604
s = input()

odd = 0
even = 0
for i in range(len(s)):
    if(i%2==0):
        even = even + int(s[i])
    else:
        odd = odd + int(s[i])

e_c = int((len(s)+1)/2)
o_c = len(s)-e_c

e1 = e_c - even + odd
o1 = o_c - odd + even
if(e1 > o1):
    print(o1)
else:
    print(e1)

Measured memory_bytes: 3188
import java.util.ArrayDeque;
import java.util.Deque;
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner scanner = new Scanner(System.in);
		 Deque<Integer> stack = new ArrayDeque<Integer>();
		 int result=0;
		 while(scanner.hasNext()) {
		while (scanner.hasNextInt()) {
			stack.push(scanner.nextInt());
		}
		int num1=stack.remove();
		int num2=stack.remove();
		String operate=scanner.next();
		if(operate.equals("+")) {
			result=num2+num1;
		}else if(operate.equals("-")) {
			result=num2-num1;
		}else if(operate.equals("*")) {
			result=num2*num1;
		}
		stack.push(result);
		 }
		 System.out.println(result);
	}

}


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

int main(){
  int n,d;
  cin>> n >> d;
  int ans=0;
  for(int i=0; i<n; i++){
    int64_t x,y;
    cin>> x >> y;
    if(sqrt(x*x+y*y)<=d) ans++;
  }
  cout<< ans <<endl;
}

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

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

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

#define DIV 1000000007

using namespace std;

int main() {
    int n;
    int a[26] = { 0 };
    vector<int> v;
    string s;
    cin >> n >> s;
    for (int i = 0; i < n; ++i) {
        a[s[i] - 'a']++;
    }
    for (int i = 0; i < 26; ++i) {
        if (a[i] > 0) {
            v.push_back(a[i]);
        }
    }
    long result = 0;
    long prev = 0;
    for (vector<int>::iterator it = v.begin(); it != v.end(); ++it) {
        result = result + 1 + prev;
        if (result > DIV) {
            result = result % DIV;
        }
        for (int j = 1; j < *it; ++j) {
            result += 1 + prev;
            if (result > DIV) {
                result = result % DIV;
            }
        }
        prev = result;
    }
    cout << result << endl;    
}

Measured memory_bytes: 512
import sys

sr = lambda: sys.stdin.readline().rstrip()
ir = lambda: int(sr())
lr = lambda: list(map(int, sr().split()))

S = sr()
days = 'SUN,MON,TUE,WED,THU,FRI,SAT'.split(',')
day_to_x = {x: 7 - i for i, x in enumerate(days)}

print(day_to_x[S])


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

public class Main {
static int ans,N;
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int a[]=new int[3];
        for(int i=0;i<3;i++)a[i]=sc.nextInt();
        Arrays.sort(a);
        System.out.println(a[0]+(a[2]*10+a[1]));
        }
    }

Measured memory_bytes: 25044
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
#define rep(i,n) for(ll i=0;i<(ll)(n);i++)
#define all(a)  (a).begin(),(a).end()
#define vi vector<int>
#define pb push_back
#define INF 999999999
//#define INF (1LL<<59)
  
struct edge{int to,cost;};
  
#define MAX_V 100000
vector<edge> G[MAX_V];
  
  
void dijkstra(int s, vector<int> &d){
    priority_queue< pii,vector<pii>,greater<pii> > que;
    rep( i,d.size() )d[i]=INF;
    d[s] = 0;
    que.push( pii(0,s) );
      
    while( que.size() ){
        pii p=que.top();
        que.pop();
          
        int v=p.second;
        if( d[v] < p.first )continue;
        rep(i,G[v].size()){
            edge e=G[v][i];
            if(d[e.to]>e.cost && d[v] <= e.cost ){
                d[e.to]=e.cost;
                que.push(pii(d[e.to],e.to));
            }
        }
    }
}
  
  
int main(){
    int n,m;
    cin>>n>>m;
      
    rep(i,m){
        int a,b,c;
        cin>>a>>b>>c;
        a--,b--;
        G[a].pb(edge{b,c});
    }
      
    vector<int> d(n);
    dijkstra(0,d);
      
      
    int ans = -1;
      
    rep(i,n){
        for(auto &e:G[i]){
            if(e.to==n-1){
                if(d[i]>e.cost)continue;
                ans = max(e.cost,ans);
            }
        }
    }
      
    cout<<ans<<endl;
      
      
}

Measured memory_bytes: 9412
import java.io.BufferedReader;
import java.io.InputStreamReader;

public class Main {
	public static void main(String[] args) throws Exception {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		int n = Integer.parseInt(br.readLine());
		char[][] s = new char[n][n];
		for (int i = 0; i < n; i++) {
			s[i] = br.readLine().toCharArray();
		}
		br.close();

		int ans = 0;
		char[][] t = new char[n][n];
		for (int a = 0; a < n; a++) {
			for (int i = 0; i < n; i++) {
				for (int j = 0; j < n; j++) {
					t[i][j] = s[(i + a) % n][j];
				}
			}
			boolean flg = true;
			for (int i = 0; i < n; i++) {
				for (int j = 0; j < n; j++) {
					if (t[i][j] != t[j][i]) {
						flg = false;
						break;
					}
				}
			}
			if (flg) {
				ans++;
			}
		}
		System.out.println(ans * n);
	}
}


Measured memory_bytes: 26244
#include<stdio.h>
#include <math.h>
#define PI 3.141592653589793

int main()
{
	double a=0,b=0,C=0;
	double unname,rad;
	double S,L,h;

	scanf("%lf %lf %lf",&a,&b,&C);
	rad = C*PI/180.0;

	S=0.5*a*b*sin(rad);
	
	unname=(a*a)+(b*b)-(2*a*b*cos(rad));
	L=a+b+sqrt(unname);

	h=b*sin(rad);

	printf("%.8lf\n %.8lf\n %.8lf\n",S,L,h);

	return 0;
}

Measured memory_bytes: 2952
def main():
    n, k = map(int, input().split())
    nl = list(range(1, n+1))
    al = list()
    for i in range(k):
        d = int(input())
        a = list(map(int, input().split()))
        al.extend(a)
    trick = list(set(nl) ^ set(al))
    print(len(trick))

if __name__ == '__main__':
    main()

Measured memory_bytes: 9052
#include <bits/stdc++.h>
#define all(a) (a).begin(),(a).end()
using namespace std;
#define sim template < class c
#define ris return * this
#define dor > debug & operator <<
#define eni(x) sim > typename \
enable_if<sizeof dud<c>(0) x 1, debug&>::type operator<<(c i) {
sim > struct rge { c b, e; };
sim > rge<c> range(c i, c j) { return rge<c>{i, j}; }
sim > auto dud(c* x) -> decltype(cerr << *x, 0);
sim > char dud(...);
struct debug {
#ifdef LOCAL
~debug() { cerr << endl; }
eni(!=) cerr << boolalpha << i; ris; }
eni(==) ris << range(begin(i), end(i)); }
sim, class b dor(pair < b, c > d) {
ris << "(" << d.first << ", " << d.second << ")";
}
sim dor(rge<c> d) {
*this << "[";
for (auto it = d.b; it != d.e; ++it)
	*this << ", " + 2 * (it == d.b) << *it;
ris << "]";
}
#else
sim dor(const c&) { ris; }
#endif
};
#define imie(...) " [" << #__VA_ARGS__ ": " << (__VA_ARGS__) << "] "

int main(){
	ios_base::sync_with_stdio(false);

	int n;
	cin >> n;

	vector<double>prob(n+1,0.0);
	prob[0] = 1.0;

	for(int i=1;i<=n;i++){
		double p;
		cin >> p;
		for(int j=i;j>=0;j--){
			prob[j] = prob[j]*(1-p) + ( (j>0)?prob[j-1]*p:0 );
		}
	}

	double ans =0;
	for(int i=0;i<=n;i++){
		if(i > n-i) ans += prob[i];
	}

	cout << fixed << setprecision(10) << ans << endl;

	return 0;
}


Measured memory_bytes: 3840
//************************
//** author  :  Alex Hu **
//************************

//  _______        __________         ________        __
//  \      \   ____\______   \ ____  /  _____/  _____/  |_
//  /   |   \ /  _ \|       _// __ \/   \  ____/ __ \   __\
// /    |    (  <_> )    |   \  ___/\    \_\  \  ___/|  |
// \____|__  /\____/|____|_  /\___  >\______  /\___  >__|
//         \/              \/     \/        \/     \/

#include<bits/stdc++.h>

using namespace std;

#define CLEAN(a,b) memset(a,b,sizeof(a))
#define mkp make_pair
#define pb push_back
#define rept(i,a,b) for(int i=(int)(a);i<(int)(b);i++)
#define fi first
#define se second
#define sqr(a) ((a)*(a))

typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;

const ll mod=1e9+7;
const int INF=0x3f3f3f3f;

int a,b,c;

int main()
{
	cin>>a>>b>>c;
	if (a*b>c) cout<<c;
	else cout<<a*b;
	return 0;
}

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

using namespace std;

int main()
{
    int N,counter=0;
    cin>>N;
    vector<int> squares(N);

    for(int i=0 ; i<N ; i++)
    {
        cin>>squares[i];
        if((i+1)%2!=0 && squares[i]%2!=0)
            counter++;
    }
    cout<<counter<<endl;

    return 0;
}


Measured memory_bytes: 3552
#include<stdio.h>
int main()
{
  int N,dig=0,sum=0;
  scanf("%d", &N);
  int num=N;
  while(num){
    dig = num % 10;
    sum = sum + dig;
    num = num / 10;
  }
  if(N%sum==0) printf("Yes\n");
  else printf("No\n");
  return 0;
}

Measured memory_bytes: 128