akhauriyash/Code-Regression huggingface dataset:
// g++ -std=c++11 a.cpp
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#include<map>
#include<set>
#include<unordered_map>
#include<utility>
#include<cmath>
#include<random>
#include<cstring>
#include<queue>
#include<stack>
#include<bitset>
#include<cstdio>
#include<sstream>
#include<iomanip>
#include<assert.h>
#include<typeinfo>
#define loop(i,a,b) for(long long i=a;i<b;i++)
#define rep(i,a) loop(i,0,a)
#define FOR(i,a) for(auto i:a)
#define pb push_back
#define all(in) in.begin(),in.end()
#define shosu(x) fixed<<setprecision(x)
#define show1d(v) {rep(_,v.size())cout<<" "<<v[_];cout<<endl;}
#define show2d(v) {rep(__,v.size())show1d(v[__]);}
using namespace std;
//kaewasuretyuui
typedef long long ll;
#define int ll
typedef int Def;
typedef pair<Def,Def> pii;
typedef vector<Def> vi;
typedef vector<vi> vvi;
typedef vector<pii> vp;
typedef vector<vp> vvp;
typedef vector<string> vs;
typedef vector<double> vd;
typedef vector<vd> vvd;
typedef pair<Def,pii> pip;
typedef vector<pip>vip;
#define mt make_tuple
typedef tuple<int,int,int> tp;
typedef vector<tp> vt;
template<typename A,typename B>bool cmin(A &a,const B &b){return a>b?(a=b,true):false;}
template<typename A,typename B>bool cmax(A &a,const B &b){return a<b?(a=b,true):false;}
const double PI=acos(-1);
const double EPS=1e-9;
Def inf = sizeof(Def) == sizeof(long long) ? 2e18 : 1e9+10;
int dx[]={-1,0,1,0};
int dy[]={0,1,0,-1};
#define yes cout<<"Yes\n"
#define no cout<<"No\n"

//nCr mod m
#define MOD 998244353
#define M 2200000
vector<ll> fact;
bool h=false;
void init(){
	h=true;
	fact=vector<ll>(M);
	fact[0]=fact[1]=1;
	loop(i,2,M)fact[i]=fact[i-1]*i%MOD;
}
// a^b mod MOD
ll powmod(ll a,ll b,ll m=MOD){
	ll out=1;
	ll p=a%m;
	while(b){
		if(b&1)out=out*p%m;
		p=p*p%m;
		b>>=1;
	}
	return out;
}
//nCr
ll nCr(ll n,ll r,ll m=MOD){
	if(!h)init();
	if(n<0||r<0||n<r)return 1;//??????
	ll out=fact[n]*powmod(fact[r]*fact[n-r]%m,m-2,m)%m;
	return out;
}
int gcd(int a,int b){
	if(b==0)return a;
	return gcd(b,a%b);
}
int lcm(int a,int b){
	return a/gcd(a,b)*b;
}


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

	int a;cin>>a;
	while(1){
		bool h=true;
		for(int i=2;i*i<=a;i++)if(a%i==0)h=false;
		if(h){
			cout<<a<<endl;
			return 0;
		}
		a++;
	}
}


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

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

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

    string s;
    cin >> s;

    long long int sum = 0;

    for (int bit = 0; bit < (1 << s.size() - 1); bit++) {
        vector<string> temp;

        int idx = 0;
        for (int i = 0; i < s.size() - 1; i++) {
            if (1 & (bit >> i)) {
                string t;
                for (int j = idx; j < i + 1; j++) {
                    t += s[j];
                }
                idx = i + 1;
                temp.push_back(t);
                //cout << t << endl;
            }
        }

        string tt;
        for (int j = idx; j < s.size(); j++) {
            tt += s[j];
        }
        temp.push_back(tt);

        for (int i = 0; i < temp.size(); i++) {
            sum += stoll(temp[i]);
        }
    }

    cout << sum << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
typedef long long i64;
using std::cout;
using std::endl;
using std::cin;

int main() {
	std::string a, b, c; cin >> a >> b >> c;
	
	int ma = 0;
	ma = std::max(ma, std::stoi(a + b) + std::stoi(c));
	ma = std::max(ma, std::stoi(b + c) + std::stoi(a));
	ma = std::max(ma, std::stoi(c + a) + std::stoi(b));
	cout << ma << endl;
	return 0;
}


Measured memory_bytes: 256
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cmath>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <string>
#include <vector>

// Acknowledgement: Special thanks to kyomukyomupurin, who developed this
// template.
template <class T, class U>
std::ostream& operator<<(std::ostream& os, const std::pair<T, U>& p) {
  return os << '(' << p.first << ", " << p.second << ')';
}

template <class T>
std::ostream& operator<<(std::ostream& os, const std::vector<T>& vec) {
  int n = 0;
  for (auto e : vec) os << (n++ ? ", " : "{") << e;
  return os << (n ? "}" : "{}");
}

template <class T>
std::ostream& operator<<(std::ostream& os, const std::set<T>& st) {
  int n = 0;
  for (auto e : st) os << (n++ ? ", " : "{") << e;
  return os << (n ? "}" : "{}");
}

template <class T, class U>
std::ostream& operator<<(std::ostream& os, const std::map<T, U>& mp) {
  int n = 0;
  for (auto e : mp) os << (n++ ? ", " : "{") << e;
  return os << (n ? "}" : "{}");
}

template <class T>
std::istream& operator>>(std::istream& is, std::vector<T>& vec) {
  for (T& e : vec) is >> e;
  return is;
}

#ifdef LOCAL
#define debug(...) \
  std::cerr << "[" << #__VA_ARGS__ << "]: ", debug_out(__VA_ARGS__)
#else
#define debug(...)
#endif

void debug_out() { std::cerr << '\n'; }

template <class Head, class... Tail>
void debug_out(Head&& head, Tail&&... tail) {
  std::cerr << head;
  if (sizeof...(Tail) != 0) std::cerr << ", ";
  debug_out(std::forward<Tail>(tail)...);
}
using namespace std;
using int64 = long long;

int main() {
  int64 N, K;
  cin >> N >> K;
  int64 cnt = 0;
  if (K == 0) {
    cout << N * N << endl;
    return 0;
  }
  for (int i = K + 1; i <= N; i++) {
    int shou = (N - K) / i + 1;
    int amari = (N - K) % i;
    if (amari + 1 >= i - K) {
      cnt += shou * (i - K);
    } else {
      cnt += shou * (amari + 1);
      cnt += (shou - 1) * (i - K - amari - 1);
      debug(i, shou, amari);
    }
    debug(i, cnt);
    // for (int j = K; j < i; j++) {
    //   if (j == 0) {
    //     cnt += (N - j) / i;
    //   } else {
    //     cnt += (N - j) / i + 1;
    //   }
    //   debug(i, j, cnt);
    // }
  }
  cout << cnt << endl;
  return 0;
}

Measured memory_bytes: 3636
#include<math.h>
#include<limits.h>
#include<iostream>
#include<string>
#include<vector>
#include<stdio.h>
#include<sstream>
#include<list>
#include<queue>
#include <algorithm>
#include<initializer_list>
using namespace std;

int main() {
	long n, a, b;
	cin >> n >> a >> b;

	if (a > b) {
		cout << 0 << endl;
		return 0;
	}
	if (n == 1) {
		if (a == b) {
			cout << 1 << endl;
		}
		else {
			cout << 0 << endl;
		}
		return 0;

	}

	long minSum = (n - 1)*a + b;
	long maxSum = a + (n - 1)*b;
	
	cout << maxSum - (minSum - 1) << endl;
	return 0;
}

Measured memory_bytes: 256
///******* In the name of Allah *******///

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

void Ok()
{
    int a;
    double aa,bb;
    scanf("%d",&a);
    aa = a;
    bb = 2 * 3.1416 * aa;
    printf("%0.2lf",bb);
}

int main()
{
    Ok();

    return 0;
}


Measured memory_bytes: 3784
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <iostream>
#include <algorithm>
#include <map>
#include <set>
#include <stack>
#include <queue>
#define rep(i,l,r) for(int i=(l);i<=(r);++i)
#define per(i,r,l) for(int i=(r);i>=(l);--i)
using namespace std;
const int maxn=2e5+10;
int a[maxn],b[maxn],ans,n;
bool check(int x){
	rep(i,1,n*2-1) b[i]=a[i]>x;
	for(int i=1,t=b[n];i<n;++i,t^=1) if(b[n-i]==t||b[n+i]==t) return t;
	return b[1];
}
int main(){
	scanf("%d",&n);
	rep(i,1,n*2-1) scanf("%d",&a[i]);
	int l=2,r=2*n-2,ans=n*2-1;
	while(l<=r){
		int mid=(l+r)>>1;
		if(check(mid)) l=mid+1;
		else r=mid-1,ans=mid;
	}
	printf("%d\n",ans);
	return 0;
}

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

namespace AOJ.Volume0
{
    class Program0013
    {
        static void Main(string[] args)
        {
            string line;
            Queue<string> operatingQueue = new Queue<string>();
            Stack<string> trainStack = new Stack<string>();

            while((line = Console.ReadLine()) != null)
            {
                operatingQueue.Enqueue(line);
            }

            foreach (var op in operatingQueue)
            {
                if (op == "0")
                {
                    Console.WriteLine(trainStack.Pop());
                }
                else
                {
                    trainStack.Push(op);
                }
            }
        }
    }
}

Measured memory_bytes: 5628
#include<bits/stdc++.h>
using namespace std;
int main(){
  int a,b,k;
  cin >>a>>b>>k;
  int i;
  vector<int> vec(1000);
  for(i=1;i<=max(a,b);i++){
    if(a%i==0 && b%i==0){
      vec.at(i)=i;
    }
  }
  sort(vec.begin(),vec.end());
  reverse(vec.begin(),vec.end());
  cout << vec.at(k-1);
  }
   


Measured memory_bytes: 256
/*
    ま ご う こ と な き ウ ン コ ー ド&#128169;
 */

#include <cstdio>
#include <vector>
#include <queue>
#include <utility>
#include <algorithm>
using namespace std;

#define INF 0x7fffffff
typedef pair<int, int> Pair;
int N;
int H;
int size;
int life;
int ans;
int segtree[262144];
int addtree[262144];
priority_queue<Pair> cures;

void add(int wishl, int wishr, int k, int watchl, int watchr, int x) {
    int mid;

    if (watchr <= wishl || wishr <= watchl) return;
    if (wishl <= watchl && watchr <= wishr) {
        addtree[k] += x;
        while (k > 0) {
            k = (k-1)/2;
            segtree[k] = max(segtree[k*2+1]+addtree[k*2+1], segtree[k*2+2]+addtree[k*2+2]);
        }
        return;
    }

    mid = (watchl+watchr)/2;
    add(wishl, wishr, k*2+1, watchl, mid, x);
    add(wishl, wishr, k*2+2, mid, watchr, x);
}

int get_max(int wishl, int wishr, int k, int watchl, int watchr) {
    int mid;
    int lval, rval;

    if (watchr <= wishl || wishr <= watchl) return -INF;
    if (wishl <= watchl && watchr <= wishr) return segtree[k] + addtree[k];

    mid = (watchl+watchr)/2;
    lval = get_max(wishl, wishr, k*2+1, watchl, mid);
    rval = get_max(wishl, wishr, k*2+2, mid, watchr);
    return max(lval, rval) + addtree[k];
}

int main() {
    scanf("%d %d", &N, &H);
    size = 1;
    while(size < N) size *= 2;

    life = H;
    for (int i=0; i<N-1; i++) {
        int d, h;
        int prev_times = -1;

        scanf("%d %d", &d, &h);
        add(i, i+1, 0, 0, size, life);
        cures.push(Pair(min(H-life, h), i));

        life -= d;
        while (life <= 0) {
            Pair p;
            int val;
            int idx;
            int at_life;
            int lim;
            int diff;
            int times;
            int amount;

            p = cures.top(); cures.pop();
            val = p.first;
            idx = p.second;
            at_life = get_max(idx, i+1, 0, 0, size);
            if (at_life >= H) {
                continue;
            }

            lim = H-at_life;
            if (lim < val) {
                cures.push(Pair(lim, idx));
                continue;
            }

            diff = 1-life;
            if (lim < diff) {
                times = lim/val;
            } else {
                times = diff/val;
            }

            if (prev_times == 0 && times == 0) times = 1;
            amount = val * times;
            if (amount > lim) amount = lim;
            add(idx, i+1, 0, 0, size, val*times);
            ans += times;
            life += amount;
            cures.push(Pair(min(lim-amount, val), idx));
            prev_times = times;
        }
    }

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

Measured memory_bytes: 2640
//	ZapZu's code hohoho
//	#pragma GCC optimize ("O3")
#include <bits/stdc++.h>
using namespace std;
#define mp make_pair
#define pb push_back
#define eb emplace_back
#define fi first
#define se second
#define lb lower_bound
#define ub upper_bound
#define dfs_black 1
#define dfs_white -1
#define pr pair
#define vt vector
#define fastio ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);

typedef double db;
typedef long long li;
typedef long double ld;

typedef pr<int, int> ii;
typedef pr<ld,ld> dd;

typedef vt<int> vi;
typedef vt<li> vli;
typedef vt<ld> vld;
typedef vt<ii> vii;

typedef map<int, int> mii;
typedef map<int, bool> mib;
typedef map<int, char> mic;

typedef set<int> s_i;
typedef set<char> s_c;

const int MOD = 1e9+7;
const li INF = 1e18;
const ld PI = 4*atan((ld)1);
vi v[2];
signed main()
{
//	freopen(".inp", "r", stdin);
//	freopen(".out", "w", stdout);
	int n, k;
	cin>>n>>k;
	li ans=0;
	for(int i=1; i<=n; i++)
	{
		if(2*i%k==0)
		{
			int temp=k-(i%k);
			li cnt=(n-temp)/k+1;
		ans+=cnt*cnt;
		}
	}
	cout<<ans;
}




Measured memory_bytes: 256
import java.util.*

fun main(args: Array<String>) {
    abc045b()
}

fun abc045b() {
    val abcList = (1..3).map {
        readLine()!!.toCharArray().map {
            when (it) {
                'a' -> 0
                'b' -> 1
                else -> 2
            }
        }
    }.map { ArrayDeque(it) }

    var nextTurn = 0
    while (true) {
        nextTurn = abcList[nextTurn].pollFirst() ?: return println(
            when (nextTurn) {
                0 -> "A"
                1 -> "B"
                else -> "C"
            }
        )

    }
}


Measured memory_bytes: 33620
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
const int INF = 1e9;

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

    int bit = 0, cnt = 0;
    bool allzero = true;
    set<int> st;
    for(int i = 0; i < N; ++i) {
        int a;
        cin >> a;
        bit ^= a;
        if(a != 0)
            allzero = false;
        if(st.find(a) == st.end()) {
            cnt++;
            st.insert(a);
        }
    }

    if(cnt <= 3 && bit == 0 && N % 3 == 0 || allzero)
        cout << "Yes" << endl;
    else
        cout << "No" << endl;
    return 0;
}


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

int main(){
  int s;
  cin >> s;
  map<int,int> mp;

  int cnt = 1;
  mp[s] = 1;
  while(true){
    cnt++;
    if(s%2 == 0){
      s /= 2;
    }else{
      s = 3*s + 1;
    }
    if(mp[s] != 0){
      cout << cnt << endl;
      break;
    }
    mp[s] = 1;
  }
}

Measured memory_bytes: 256
#include <iostream>
#include <iostream>
#include <string>
#include <algorithm>
using namespace std;
int main(void){
    string str="";
    string str2="";
    string p="";
    int Q=0;
    cin >> str >>Q;
    int query=0;
    int f=0;
    int count=0;
    for (int i=0; i<Q;i++){
        cin >> query;
        if(query==1){
            count++;
        }
        else if(query==2){
            if(count%2==0){
            cin >> f >>p;
            if(f==1){
                str.insert(0, p); 
            }
            else if(f==2){
                str.append(p);
                }
            }
            else if(count%2==1){
            cin >> f >>p;
            if(f==2){
                str.insert(0, p); 
            }
            else if(f==1){
                str.append(p);
                }
            }
        }
    }
    if(count%2==1){
        reverse(str.begin(), str.end());
    }
    
    cout << str <<endl;
}


Measured memory_bytes: 900
#include <iostream>
#include <vector>
#include <string>
#include <cmath>
#include <algorithm>
#include <map>
#include <iomanip>
#include <stdlib.h>
#include <queue>

using namespace std;

int main(){

  int N, M; cin >> N >> M;
  
  int ans = M / N;
  for (int i = ans; i >= 1; i--){
    if((M - i * (N - 1)) % i == 0){
      cout << i << endl;
      break;
    }
  }
  


  return 0;
}


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

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

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int n, m, k, cnt(1), tmp;
int Num[302], Ans[302][302];
char C[302][302];
int main()
{
    //freopen("Test.INP","r",stdin);
    //freopen("TEst.OUT","w",stdout);
    cin >> n >> m >> k;
    for (int i = 1; i <= n; i++)
    {
        for (int j = 1; j <= m; j++)
        {
            cin >> C[i][j];
            if (C[i][j] == '#')
                Num[i]++;
        }
    }
    for (int i = 1; i <= n; i++)
    {
        if (Num[i] != 0)
        {
            tmp = i - 1;
            break;
        }
    }
    for (int j = 1; j <= m; j++)
    {
        for (int k = 1; k <= tmp + 1; k++)
            Ans[k][j] = cnt;
        if (C[tmp + 1][j] == '#' && Num[tmp + 1] != 1)
        {
            Num[tmp + 1]--;
            cnt++;
        }
    }
    for (int i = tmp + 2; i <= n; i++)
    {
        if (Num[i] == 0)
        {
            for (int j = 1; j <= m; j++)
                Ans[i][j] = Ans[i-1][j];
        }
        else
        {
            for (int j = 1; j <= m; j++)
            {
                if (j == 1)
                    cnt = Ans[i-1][m] + 1;
                Ans[i][j] = cnt;
                if (C[i][j] == '#' && Num[i] != 1)
                {
                    cnt++;
                    Num[i]--;
                }
            }
        }
    }
    for (int i = 1; i <= n; i++)
    {
        for (int j = 1; j <= m; j++)
        {
            cout << Ans[i][j] << ' ';
        }
        cout << '\n';
    }
    return 0;
}


Measured memory_bytes: 1152
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
 
int main(){
    int N, K;
    cin >> N >> K;
    int H[N];
    for(int i=0;i<N;i++)
        cin >> H[i];

    // 降順ソート
    sort(H, H + N, greater<int>());
    ll ans = 0;
    for(int i=K;i<N;i++)
        ans += H[i];

    cout << ans << endl;

}

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

using namespace std;

typedef vector<int> vi;
typedef set<int> si;
typedef multiset<int> msi;

typedef pair<int, int> ii;

typedef vector<bool> vb;

int main( int argc, char *argv[] ) {
	int a, b;

	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cin >> a >> b;
	if ( a == b )
		std::cout << 2 * a << std::endl;
	else if ( a > b )
		std::cout << 2 * a - 1 << std::endl;
	else
		std::cout << 2 * b - 1 << std::endl;
	return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<algorithm>
#define Max 100001
#define inf 1000000000000000
using namespace std;
int n,m,flag;
int first[Max * 2],nextv[Max * 2],u[Max * 2],v[Max * 2],s[Max * 2];
long long vis[2][Max],l = 0,r = inf,ans;
void dfs(int from,int tag,long long va) {
    if(flag)return;
    int k = first[from];
    while(k != -1) {
        if(flag)return;
        int vtag = (tag == 1);
        int to = v[k];
        long long lva = s[k] - va;
        if(vis[vtag][to] != inf) {
            if(vis[vtag][to] == lva) {
                k = nextv[k];
                continue;
            }
            else {
                flag = 1;
                return;
            }
        }
        vis[vtag][to] = lva;
        if(vtag)r = min(r,lva);
        else l = max(l,-lva);
        dfs(to,-tag,lva);
        k = nextv[k];
    }
}
int main() {
    scanf("%d%d",&n,&m);
    memset(first,-1,sizeof(first));
    for(int i = 1;i <= n;i ++) {
        vis[0][i] = vis[1][i] = inf;
    }
    for(int i = 0;i < m;i ++) {
        scanf("%d%d%d",&u[i],&v[i],&s[i]);
        u[i + m] = v[i];
        v[i + m] = u[i];
        s[i + m] = s[i];
        nextv[i] = first[u[i]];
        first[u[i]] = i;
        nextv[i + m] = first[u[i + m]];
        first[u[i + m]] = i + m;
    }
    dfs(1,1,0);///dfs遍历所有点和第一个点的关系，如果有冲突flag为1
    if(!flag) {///遍历后无冲突
        long long temp = -1;
        for(int i = 1;i <= n;i ++) {
            if(vis[0][i] != inf && vis[1][i] != inf) {
                long long d = (vis[1][i] - vis[0][i]) / 2;
                if(d <= 0) {///解是负数 不成立
                    flag = 1;
                    break;
                }
                if(temp == -1)temp = d;
                else if(temp != d) {///解不一致
                    flag = 1;
                    break;
                }
            }
        }
        if(temp != -1 && !flag) {///有环 且各关系无冲突
            if(temp > l && temp < r)ans = 1;
        }
        else if(r - l - 1 > 0) ans = r - l - 1;
    }
    printf("%lld",ans);
    return 0;
}


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

int main() {
  string S;
  cin>>S;
  int N=S.length();
  int flag=0;
  for(int i=0;i<N;i++){
    if((S.at(i)=='U')||(S.at(i)=='D')){
      continue;
    }   
    else if((i%2==0)&&(S.at(i)=='R')){
      continue;
    }
            else if((!(i%2==0))&&(S.at(i)=='L')){
              continue;
            }
            flag=1;     
    }
            if(flag==1){
              cout<<"No"<<endl;
              return 0;
            }
  else{
  
            cout<<"Yes"<<endl;
  }
            
  return 0;

}



Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int N;
  cin >> N;
  int A[N];
  for(int i = 0; i < N; i++) cin >> A[i];
  sort(A, A + N, std::greater<>());
  int check = A[0];
  bool flag = true;
  for(int i = 1; i < N; i++){
  	if(check == A[i]){
      flag = false;
      break;
    }else check = A[i];
  }
  if(flag) cout << "YES" << endl;
  else cout << "NO" << endl;
}

Measured memory_bytes: 1024
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <iomanip>
#include <cmath>
#include <vector>

using namespace std;

struct P{ int x, y; };

int N;
vector<P> p(200);

bool asc1(const P& p1, const P& p2)
{ 
	return p1.x < p2.x;
}

bool asc2(const P& p1, const P& p2)
{ 
	return p1.y < p2.y;
}

int main(){
	while(1){
		cin >> N;
		if(N == 0) break;
		p[0].x = 0;
		p[0].y = 0;
		for (int i = 1; i < N; i++)
		{
			int n, d;
			cin >> n >> d;
			if(d == 0){
				p[i].x = p[n].x-1;
				p[i].y = p[n].y;
			}else if(d == 1){
				p[i].x = p[n].x;
				p[i].y = p[n].y-1;
			}else if(d == 2){
				p[i].x = p[n].x+1;
				p[i].y = p[n].y;
			}else if(d == 3){
				p[i].x = p[n].x;
				p[i].y = p[n].y+1;
			}
		}
		sort(p.begin(), p.begin()+N, asc1);
		cout << (p[N-1].x - p[0].x)+1 << " ";
		sort(p.begin(), p.begin()+N, asc2);
		cout << (p[N-1].y - p[0].y)+1 << endl;
	}
	return 0;
}

Measured memory_bytes: 1216
from functools import reduce
from fractions import gcd
import math
import bisect
import itertools
import sys
sys.setrecursionlimit(10**7)
input = sys.stdin.readline
INF = float("inf")


def main():
    N, M = map(int, input().split())
    
    key_price = [0]*M
    key_bit = [0]*M
    for i in range(M):
        key_price[i], b = map(int, input().split())
        c = list(map(int, input().split()))
        for j in range(b):
            key_bit[i] = key_bit[i] | (1 << (c[j] - 1))
    
    dp = [[INF] * (2**N) for _ in range(M+1)]
    dp[0][0] = 0
    for m in range(M):
        for bit in range(2**N):
            if dp[m][bit] == INF:
                continue
            dp[m+1][bit] = min(dp[m+1][bit], dp[m][bit])
            dp[m+1][bit | key_bit[m]] = min(dp[m+1][bit | key_bit[m]], dp[m][bit] + key_price[m])

    res = dp[M][2**N-1]
    if res == INF:
        print(-1)
    else:
        print(res)


if __name__ == '__main__':
    main()

Measured memory_bytes: 164204
#include <iostream>
#include <cmath>
#include <iomanip>
using namespace std;

int main()
{
  double x1, y1, x2, y2;
  cin >> x1 >>  y1 >>  x2 >>  y2;

  double s = 0;
  s +=  pow(x2 - x1 , 2) + pow(y2 - y1, 2);

  cout << fixed << setprecision(10) <<  sqrt(s) << endl;
  return 0;
}
 



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

using namespace std;

int main() {
	string S;
	cin >> S;

	if (S.at(0) == S.at(1) && S.at(1) != S.at(2) && S.at(2) == S.at(3)) {
		cout << "Yes" << endl;
	}
	else if (S.at(0) == S.at(2) && S.at(1) != S.at(2) && S.at(1) == S.at(3)) {
		cout << "Yes" << endl;
	}
	else if (S.at(0) == S.at(3) && S.at(0) != S.at(1) && S.at(1) == S.at(2)) {
		cout << "Yes" << endl;
	}
	else {
		cout << "No" << endl;
	}
	
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h> 
#include <vector>
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define size_of_array(array) (sizeof(array)/sizeof(array[0]))
using ll =long long;
using namespace std;
using Graph=vector<vector<int>>;
using Field=vector<vector<int>>;

int main(){
    int n,d;
    cin>>n>>d;
    int c=2*d+1;
    int e=(n/c);
    e+=(n%c==0)?0:1;
    cout<<e<<endl;
}


Measured memory_bytes: 3624
#include <cstdio>
#include <algorithm>
#define LL long long
#define maxn 200010
#define mod 1000000007
using namespace std;
int a[maxn];
LL ans=1,x,y;
int main(){
	int n,k,i,l,r;
	scanf("%d%d",&n,&k);
	for(i=1;i<=n;i++)scanf("%d",&a[i]);
	sort(a+1,a+1+n);
	if(a[1]>=0){
		for(i=n;i>=n-k+1;i--)ans=ans*a[i]%mod;
	}else if(a[n]<0){
		if(k&1){
			for(i=n;i>=n-k+1;i--)ans=ans*a[i]%mod;
			ans=(ans%mod+mod)%mod;
		}else
			for(i=1;i<=k;i++)ans=ans*a[i]%mod;
	}else{
		int cnt1=0,cnt2=0;
		for(i=1;i<=n;i++)
			if(a[i]<0)cnt1++;
			else break;
		cnt2=n-cnt1;
		if(cnt1/2*2+cnt2<k){
			for(i=1;i<=n;i++)ans=ans*a[i]%mod;
			ans=(ans%mod+mod)%mod;
		}else{
			if(k&1) ans=a[n],n--,k--;
			l=1,r=n;
			while(k){
				x=(LL)a[l]*a[l+1],y=(LL)a[r]*a[r-1];
				if(x>y)x%=mod,ans=ans*x%mod,l+=2;
				else y%=mod,ans=ans*y%mod,r-=2;
				k-=2;
			}
			ans=(ans%mod+mod)%mod;
		}
	}
	printf("%lld\n",ans);
	return 0;
}

Measured memory_bytes: 2516
#include<bits/stdc++.h>
using namespace std;
#define LL long long

const int mo=1e9+7;
int n,m,g[15],pow2[233],bit[1<<15],dp[1<<15];

int main()
{
#ifdef h10
	freopen("F.in","r",stdin);
	freopen("F.out","w",stdout);
#endif
	int i,u,v,S,S0;
	scanf("%d%d",&n,&m);
	pow2[0]=1;
	for (i=1;i<233;i++)
		pow2[i]=2*pow2[i-1]%mo;
	for (i=1;i<1<<n;i++)
		bit[i]=bit[i>>1]+(i&1);
	for (i=1;i<=m;i++)
	{
		scanf("%d%d",&u,&v);
		u--; v--;
		g[u]|=1<<v;
	}

	dp[0]=1;
	for (S=1;S<1<<n;S++)
	{
		if ((S&1)^((S&2)>>1)) continue;
		for (S0=S;S0;S0=(S0-1)&S)
		{
			int Sum=dp[S-S0];
			if (!Sum) continue;
			for (i=0;i<n;i++)
				if ((S>>i)&1)
				{
					if ((S0>>i)&1)
						Sum=(LL)Sum*pow2[bit[g[i]&(S-S0)]]%mo;
					else
						Sum=(LL)Sum*(pow2[bit[g[i]&S0]]-1)%mo;
				}
			(dp[S]+=Sum)%=mo;
		}
	}
	printf("%d\n",(pow2[m]+mo-dp[(1<<n)-1])%mo);
}


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

int main()
{
	int a = 0;
	std::cin >> a;

	std::string s = "";
	std::cin >> s;

	if (a >= 3200)
	{
		std::cout << s << "\n";
	}
	else
	{
		std::cout << "red\n";
	}

	return 0;
}

Measured memory_bytes: 256
from collections import deque
n = int(input())
a = list(map(str, input().split()))
b = deque()
if n%2:
    flag = False
else:
    flag = True
for i in range(n):
    if flag:
        if (i+1)%2:
            b.append(a[i])
        else:
            b.appendleft(a[i])
    else:
        if (i+1)%2:
            b.appendleft(a[i])
        else:
            b.append(a[i])
res = list(b)
print(' '.join(res))

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

N = int(input())
S = list(input().rstrip())

A1 = [0]*(N+1)
A2 = [0]*(N+1)

t = 0
for i, s in enumerate(S):
    if s == "W":
        t += 1
    A1[i+1] = t

t = 0
for i in reversed(range(N)):
    if S[i] == "R":
        t += 1
    A2[i] = t

ans = 10**18
for a1, a2 in zip(A1, A2):
    score = abs(a1-a2) + min(a1, a2)
    ans = min(ans, score)

print(ans)

Measured memory_bytes: 81032
import java.util.*;
import java.lang.*;


public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int[] yaku = new int[n + 1];
		for (int i = 1; i <= n; i++) {
			int target = i;
			for (int j = 2; j <= i; j++) {
				while (target % j == 0) {
					target /= j;
					yaku[j]++;
				}
			}
		}
		long mod = 1000000007;
		long count = 1;
		for (int i = 0; i <= n; i++) {
			count *= yaku[i] + 1;
			count %= mod;
		}
		System.out.println(count);
	}
}

Measured memory_bytes: 21844
#include<iostream>
 #include<string>
 using namespace std;
 
 int abs(int x)
 {
 	if(x>=0) return x;
 	else return -x;
 }
 
 int main()
 {
 	int n;
    int arr[100000+5];
 	int dp[100000+5];
 	int ans[100000+5];
 	while(cin>>n)
 	{
 		long long int pos=0;
 		arr[0]=0;
 		for(int i=1;i<=n;i++) cin>>arr[i];
 		for(int i=0;i<n;i++)
 		{
 			if(i==0) dp[i]=abs(arr[i+1]-pos);
 			else dp[i]=dp[i-1]+abs(arr[i+1]-pos);
 			pos=arr[i+1];
		 }
		 dp[n]=dp[n-1]+abs(0-arr[n]);
		 //for(int i=0;i<=n;i++) cout<<dp[i]<<endl;
		 for(int i=0;i<(n-1);i++)
		 {
		 	if(i==0) ans[i]=dp[n]-dp[i+1]+abs(arr[i+2]-arr[i]);
		 	else ans[i]=dp[n]-dp[i+1]+dp[i-1]+abs(arr[i+2]-arr[i]);
		 }
		 ans[n-1]=dp[n-2]+abs(arr[n-1]-0);
		 for(int i=0;i<n;i++) cout<<ans[i]<<endl;
	 }
 	return 0;
 }
 
 
 
 
 

Measured memory_bytes: 2432
we = input()
jud = list(we)
if jud[1] == "R":
	if jud[0] == "R" and jud[2] == "R":
		print(3)
	elif jud[0] == "R" or jud[2] == "R":
		print(2)
	else:
		print(1)
else:
	if jud[0] == "R" or jud[2] == "R":
		print(1)
	else:
		print(0)

Measured memory_bytes: 8984
#include <bits/stdc++.h>
#define lowbit(x) (x & -x)
#define jh(x, y) x ^= y ^= x ^= y
#define loc(x, y) (x - 1) * m + y
#define rg register
#define inl inline
#define PI 3.141592654
typedef long long ll;
const int N = 6e5 + 5, INF = 0x3f3f3f3f, mod = 998244353;
using namespace std;
namespace fast_IO {
	inl ll read() {
		rg char c;
		rg ll x = 0;
		rg bool flag = false;
		while ((c = getchar()) == ' ' || c == '\n' || c == '\r');
		if (c == EOF)return c; if (c == '-')flag = true; else x = c ^ 48;
		while ((c = getchar()) != ' ' && c != '\n' && c != '\r' && ~c)
			x = (x << 1) + (x << 3) + (c ^ 48);
		if (flag)return -x; return x;
	}
	inl ll max(rg ll a, rg ll b) { if (a > b)return a; return b; }
	inl ll min(rg ll a, rg ll b) { if (a < b)return a; return b; }
	void write(rg ll x) { if (x < 0)putchar('-'), x = -x; if (x >= 10)write(x / 10); putchar(x % 10 ^ 48); }
}
char s[N];

int main(void) {
	rg int n = fast_IO::read(), k = fast_IO::read();
	scanf("%s", s + 1);
	s[k] += 32;
	puts(s + 1);
	return 0;
}

Measured memory_bytes: 256
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
using vin=vector<int>;
using vll=vector<long long>;
using vvin=vector<vector<int>>;
using vvll=vector<vector<long long>>;
using vstr=vector<string>;
using vvstr=vector<vector<string>>;
using vch=vector<char>;
using vvch=vector<vector<char>>;
using vbo=vector<bool>;
using vvbo=vector<vector<bool>>;
using vpii=vector<pair<int,int>>;
using pqsin=priority_queue<int,vector<int>,greater<int>>;
#define mp make_pair
#define rep(i,n) for(ll i=0;i<(ll)(n);i++)
#define rep2(i,s,n) for(ll i=(s);i<(ll)(n);i++)
#define all(v) v.begin(),v.end()
#define decp(n) cout<<fixed<<setprecision((int)n)
const int inf=1e9+7;
const ll INF=1e18;

bool prime(int x){
    for(int i=2;i*i<=x;i++){
        if(x%i==0)return false;
    }
    return true;
}

bool similar(int x){
    if(prime(x)&&prime((x+1)/2))return true;
    return false;
}

int main(){
    int q;cin>>q;
    vin sum(100010);
    sum[1]=0;
    for(int i=3;i<100010;i+=2){
        if(similar(i))sum[i]+=sum[i-2]+1;
        else sum[i]=sum[i-2];
    }
    vin ans(q);
    rep(i,q){
        int l,r;cin>>l>>r;
        if(l!=1)ans[i]=sum[r]-sum[l-2];
        else ans[i]=sum[r];
    }
    rep(i,q)cout<<ans[i]<<endl;
}

Measured memory_bytes: 1536
#include <algorithm>
#include <climits>
#include <cmath>
#include <cstdio>
#include <iostream>
#include <numeric>
#include <queue>
#include <string>
#include <vector>

using namespace std;

using ll = long long;

int ord(int n, int* x)
{
    vector<int> v(n);
    iota(v.begin(), v.end(), 1);
    int ord = 0;
    do {
        bool match = true;
        for (int i = 0; i < n; i++) {
            if (x[i] != v[i]) {
                match = false;
                break;
            }
        }
        if (match) {
            return ord;
        }
        ord++;
    } while (next_permutation(v.begin(), v.end()));
    return -1;
}

int main()
{
    int p[8];
    int q[8];
    int n;
    cin >> n;
    for (int i = 0; i < n; i++) {
        cin >> p[i];
    }
    for (int i = 0; i < n; i++) {
        cin >> q[i];
    }
    int ord_p = ord(n, p);
    int ord_q = ord(n, q);

    cout << abs(ord_p - ord_q) << endl;

    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#define lim 100010

using namespace std;

typedef long long int LL;
struct edge { int to; LL cost; };

vector<edge> Graph[lim];
LL depth[lim];

void dfs (int v, int p, LL d) {
    depth[v] = d;
    for (int i = 0; i < Graph[v].size(); i++) {
        if (Graph[v][i].to == p) continue;
        dfs(Graph[v][i].to, v, d + Graph[v][i].cost);
    }
}

int main() {
    int N, a, b, c;
    int Q, K, x, y;
    edge tmp;

    cin >> N;

    for (int i = 0; i < N - 1; i++) {
        cin >> a >> b >> c;
        a--, b--;
        tmp.to = b; tmp.cost = c;
        Graph[a].push_back(tmp);
        tmp.to = a;
        Graph[b].push_back(tmp);
    }

    cin >> Q >> K;
    K--;

    dfs(K, -1, 0);

    for (int i = 0; i < Q; i++) {
        cin >> x >> y;
        x--; y--;
        cout << depth[x] + depth[y] << endl;
    }

    return 0;
}

Measured memory_bytes: 15872
package main

import (
	"fmt"
	"io"
	"os"
)

func Solve(stdin io.Reader, stdout io.Writer) {
	var n int
	_, _ = fmt.Fscan(stdin, &n)

	arr := make([]int, n)
	for i := 0; i < n; i++ {
		var tmp int
		_, _ = fmt.Fscan(stdin, &tmp)
		arr[i] = tmp
	}

	colors := make([]int, 0, n)
	colors = append(colors, arr[n-1])

	for i := n - 2; i >= 0; i-- {
		// どこかで入れ替えられる場合，入れ替えられるもののうち最小の色を入れ替えたい
		// colorsは昇順にソートされているから二分探索を使える
		t := binarySearch(colors, arr[i])
		if t < len(colors) {
			colors[t] = arr[i]
		} else {
			// 既に持っているcolors の最大値よりも大きい場合は新しい色を追加
			colors = append(colors, arr[i])
		}
	}

	_, _ = fmt.Fprintf(stdout, "%d\n", len(colors))
}

func binarySearch(arr []int, target int) int {
	left := -1
	right := len(arr)

	for right-left > 1 {
		mid := left + (right-left)/2

		if arr[mid] > target {
			right = mid
		} else {
			left = mid
		}
	}

	return right
}

func main() {
	Solve(os.Stdin, os.Stdout)
	return
}


Measured memory_bytes: 7296
#include <iostream>
#include <sstream>
#include <vector>
#include <cmath>
#include <algorithm>
#include <map>
#include <set>
#include <string>
#include <stack>

using namespace std;

typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vll;
typedef vector<vll> vvll;
typedef vector<bool> vb;
typedef vector<vb> vvb;

void printVP(vector<pair<long long int,long long int>> vec_of_pairs);
void printV(vector<int> vec);
void printVVI(vector<vector<int>> vec);
void printMapSP(map<string,pair<int,int>> mp);
void printVC(vector<char> vec);
void printCurrMap(map<char,set<char>> mp);

int K, ans;
vi all_a;

bool can_get_height_with_less_cuts_than_k(int height){
    int tot_num_cuts = 0;
    for(int i=0;i<all_a.size();i++){
        int num_curr_cuts = ceil((all_a[i]*1.0)/height - 1);
        tot_num_cuts += num_curr_cuts;
//        cout<<num_curr_cuts<<" "<<height<<" "<<all_a[i]<<endl;
    }
//    cout<<"Total: "<<tot_num_cuts<<" "<<height<<endl;

    if(tot_num_cuts > K)
        return false;
    else
        return true;
}


//Inclusive of heights
void binary_search(int lower_height, int upper_height){
//    cout<<lower_height<<" "<<upper_height<<endl;

    if(upper_height - lower_height == 1) {
        if(can_get_height_with_less_cuts_than_k(lower_height))
            ans = lower_height;
        else
            ans = upper_height;

        return;
    }

    int mid = (upper_height + lower_height)/2;

    if(can_get_height_with_less_cuts_than_k(mid))
        // Then try do more cuts
        upper_height = mid;
    else
        lower_height = mid;

    binary_search(lower_height, upper_height);
}

void solve(){
    int N, Ai, max_Ai;
    cin>>N>>K;

    max_Ai = -1;

    for(int i=0;i<N;i++){
        cin>>Ai;
        all_a.push_back(Ai);
        if(Ai > max_Ai)
            max_Ai = Ai;
    }
  
  	if(max_Ai == 1){
        cout<<1<<endl;
        return;
    }

    binary_search(1, max_Ai);

    cout<<ans<<endl;
}

int main(){
    int t;
//    cin>>t;
    t = 1;
    for(int i=0;i<t;i++){
//        cout<<"Case #"<<i+1<<": ";
        solve();
    }
    return 0;
}


Measured memory_bytes: 3808
N, M = map(int,input().split())
P = [list(map(int,input().split())) for k in range(M)]
ans = 0

for i in range(M):
    T = P[:i]+P[i+1:]
    G = [[] for k in range(N)]
    V = [0 for k in range(N)]
    for e in T:
        G[e[0]-1].append(e[1]-1)
        G[e[1]-1].append(e[0]-1)

    def dfs(visited,graph,ima):
        for e in graph[ima]:
            if visited[e] == 0:
                visited[e] = 1
                dfs(visited,graph,e)
    dfs(V,G,0)
    if sum(V) != N:
        ans += 1
print(ans)


Measured memory_bytes: 42348
/*
 * 2567.cc: SIRO Challenge
 */

#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<iostream>
#include<string>
#include<vector>
#include<map>
#include<set>
#include<stack>
#include<list>
#include<queue>
#include<deque>
#include<algorithm>
#include<numeric>
#include<utility>
#include<complex>
#include<functional>
 
using namespace std;

/* constant */

const int MAX_N = 300;
const int MAX_L = 16;
const int LBITS = 1 << MAX_L;

const int INF = 1 << 29;

/* typedef */

/* global variables */

int cs[MAX_N][MAX_N], ds[MAX_L + 1][MAX_L + 1];
int js[MAX_L + 1], es[MAX_L + 1];
int dp[LBITS][MAX_L], bnums[LBITS];

/* subroutines */

/* main */

int main() {
  for (int bits = 0; bits < LBITS; bits++) {
    bnums[bits] = 0;
    for (int i = 0, bi = 1; i < MAX_L; i++, bi <<= 1)
      if (bits & bi) bnums[bits]++;
  }

  for (;;) {
    int n, m, l, s, t;
    cin >> n >> m >> l >> s >> t;
    if (n == 0) break;
    s--;
    
    for (int i = 0; i < n; i++) {
      for (int j = 0; j < n; j++) cs[i][j] = INF;
      cs[i][i] = 0;
    }

    for (int i = 0; i < m; i++) {
      int ai, bi, ci;
      cin >> ai >> bi >> ci;
      ai--, bi--;
      cs[ai][bi] = cs[bi][ai] = ci;
    }

    for (int i = 0; i < l; i++) {
      cin >> js[i] >> es[i];
      js[i]--;
    }
    js[l] = s;
    es[l] = 0;

    for (int k = 0; k < n; k++)
      for (int i = 0; i < n; i++)
	for (int j = 0; j < n; j++) {
	  int d = cs[i][k] + cs[k][j];
	  if (cs[i][j] > d) cs[i][j] = d;
	}
    
    for (int i = 0; i <= l; i++)
      for (int j = 0; j <= l; j++)
	ds[i][j] = cs[js[i]][js[j]];

    int lbits = 1 << l;
    for (int bits = 0; bits < lbits; bits++)
      for (int i = 0; i < l; i++) dp[bits][i] = INF;

    int maxn = 0;

    for (int i = 0; i < l; i++) {
      int d = ds[l][i] + es[i];
      if (d + ds[i][l] <= t) dp[1 << i][i] = d, maxn = 1;
    }

    for (int bits = 1; bits < lbits; bits++)
      for (int i = 0; i < l; i++)
	if (dp[bits][i] < INF) {
	  for (int j = 0, bj = 1; j < l; j++, bj <<= 1) {
	    if (! (bits & bj)) {
	      int bitsj = bits | bj;
	      int d = dp[bits][i] + ds[i][j] + es[j];
	      if (d + ds[j][l] <= t && dp[bitsj][j] > d) {
		dp[bitsj][j] = d;
		int bn = bnums[bitsj];
		if (maxn < bn) maxn = bn;
	      }
	    }
	  }
	}

    printf("%d\n", maxn);
  }

  return 0;
}

Measured memory_bytes: 5844
#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>;

int main()
{
  // string S;
  // cin >> S;
  // char char1;
  // int char1_count = 0;
  // char char2;
  // int char2_count = 0;
  // rep(i, S.size()) {
  //   char1 = S.at(0);
  //   if (S.at(i) != char1) {
  //     char2 = S.at(i);
  //   }
  // }
  // rep(i, S.size()){
  //   if (S.at(i) == char1) {
  //     char1_count++;
  //   } else if (S.at(i) == char2) {
  //     char2_count++;
  //   } else {
  //     cout << "No" << endl;
  //     return 0;
  //   }
  // }
  // if (char1_count == 2 && char2_count == 2){
  //   cout << "Yes" << endl;
  // } else {
  //   cout << "No" << endl;
  // }

  // mapを使った解法
  const string YES = "Yes";
  const string NO = "No";
  string S;
  cin >> S;
  map<char, int> ma;
  for (auto c : S)
    ma[c]++;
  for (auto pa : ma)
  {
    if (pa.second != 2)
    {
      cout << NO << endl;
      return 0;
    }
  }
  cout << YES << endl;
  return 0;
}

Measured memory_bytes: 256
dp = [0]*(10**6)

N,M = map(int, input().split())
A = {}
for i in range(N+1):
    A[i] = 0
for _ in range(M):
    a = int(input())
    A[a] = 1

dp[0] = 1

for i in range(1,N+1,1):

    if A[i]==1:
        continue
    if i==1:
        dp[i] += dp[i-1]
        continue
    if A[i-1]==0:
        dp[i] += dp[i-1]
    if A[i-2]==0:
        dp[i] += dp[i-2]


print(dp[N]%(10**9+7))

Measured memory_bytes: 479072
#include <bits/stdc++.h>
#define int long long
#define double long double
#define rep(i, a, n) for(int i = (int)(a);(i) < (int)(n);++(i))
#define repe(i, a, n) for(int i = (int)(a);(i) <= (int)(n);++(i))
#define repif(i, a, x) for(int i = (int)(a);(x);++(i))
#define repr(i, a, n) for(int i = ((int)(a)-1);(i) >= (int)(n);--(i))
#define reper(i, a, n) for(int i = (int)(a);(i) >= (int)(n);--(i))
#define SZ(x) ((int)(x).size())
#define ALL(x) begin(x), end(x)
#define CEIL(x) ((int)ceil(((double)x)))
#define POW(x, y) ((int)pow(x, y))
#define UNIQUE(x) (x).erase(unique(ALL((x))), end(x))
#define gcd(x, y) __gcd(x, y)
#define lcm(x, y) ((x)/gcd(x,y)*(y))
#define isin(x, l, r) ((l) <= (x) and (x) < (r))
#define fcout cout << fixed << setprecision(10)
#define rcout(n) cout << right << setw(n)
#define pb push_back
#define eb emplace_back
#define lb lower_bound
#define ub upper_bound
#define PI (acos(-1))
#define EPS (1e-10)
#define INF LLONG_MAX
#define INF32 INT32_MAX
#define MOD 1000000007LL
using namespace std;
using VI = vector<int>;
using PII = pair<int, int>;
using TIII = tuple<int, int, int>;
using VPII = vector<PII>;
using VTIII = vector<TIII>;
using Complex = complex<double>;
template<typename T, template<typename> typename C = less> using PQ = priority_queue<T, vector<T>, C<T>>;
template<typename T> bool chmax(T& a, const T& b, bool t = false){ if(a<b or (t and a == b)){ a=b; return true; } return false; }
template<typename T> bool chmin(T& a, const T& b, bool t = false){ if(a>b or (t and a == b)){ a=b; return true; } return false; }


int N;
string S;


signed main(){
    cin >> N;
    cin >> S;

    rep(i, 0, SZ(S)) cout << (char)('A'+((S[i]-'A'+N)%26));
    cout << endl;

    return 0;
}

Measured memory_bytes: 256
#include<iostream>

using namespace std;

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

    int a[n];
    int conti = 0;
    int single = 0;
    cin >> a[0];
    if(a[0]==1)single++;

    bool flg = false;
    for(int i=1;i<n;i++){
        cin >> a[i];
        if(a[i]==i+1){
            single++;
            if(a[i-1]==i && !flg){
                single -= 2;
                conti++;
                flg = true;
            }else flg = false;
        }
//cout << "single:" << single << " conti:" << conti << endl;
    }
    cout << conti+single << endl;
}


Measured memory_bytes: 640
using System;
using System.Linq;
using System.Text;
using System.Collections.Generic;

class Program
{
	static void Main(string[] args)
	{
		//読み込む
		string[] line = Console.ReadLine().Split(' ');
		long a = long.Parse(line[0]);
		long b = long.Parse(line[1]);
		long c = long.Parse(line[2]);

		bool less = false;

		//root(4ab) < c - a - bとなれば良い
		long diff = c - a - b;

		if(diff > 0){
				long left = 4 * a * b;
				long right = diff*diff;

				if(left < right){
						less = true;
				}
		}

		if(less){
				Console.WriteLine("Yes");
		}else{
				Console.WriteLine("No");
		}
	}
}


Measured memory_bytes: 13140
#include <iostream>
#include<bits/stdc++.h>
#define ll long long
using namespace std;
const ll items = 100;
const ll weights = 100007;
ll n , maxV;
ll dp[weights][items];
vector<ll> w ;
vector<ll> v ;
ll solve(ll rem , ll item){
    if(item==n)
        return 0 ;
    if(dp[rem][item]!=-1)
        return dp[rem][item];
    if(rem-w[item]<0)
        return dp[rem][item]=solve(rem,item+1);
    else
        return dp[rem][item]=max(solve(rem-w[item],item+1)+v[item],solve(rem,item+1));
}
int main()
{
    cin >> n >> maxV ;
    memset(dp,-1, sizeof dp);
    for(ll i=0;i<n;i++){
        ll a , b ;
        cin >> a >> b ;
        w.push_back(a);
        v.push_back(b);
    }
    cout << solve(maxV,0) << endl;
    return 0;
}


Measured memory_bytes: 78336
#include<bits/stdc++.h>
#define ll long long
#define pb push_back
#define mod 1000000007
#define ff first
#define ss second
using namespace std;
/*ll power(ll x,ll y)
{
    ll res=1;
    while(y>0)
    {
        if(y%2==1)
            res=(res*x)%mod;
        x=(x*x)%mod;
        y=y/2;
    }
    return res;
}*/
int main()
{
ll n,c=0;
cin>>n;
ll i,m;
vector<ll>v;
for(i=0;i<n;i++)
{
    cin>>m;
    v.pb(m-1);
}
c=v[0];
for(i=1;i<n;i++)
{
    if(v[i]<c)
    {
        if(v[i]+1<c)
        {
            cout<<"No"<<endl;
            return 0;
        }
        else
            c=v[i]+1;
    }
    else
        c=v[i];
}

cout<<"Yes"<<endl;
}


Measured memory_bytes: 1400
#[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)*}
    };

    ($next:expr, mut $var:ident : $t:tt $($r:tt)*) => {
        let mut $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")
    };
}

#[allow(unused_macros)]
macro_rules! debug {
    ($($a:expr),*) => {
        #[cfg(debug_assertions)]
        writeln!(&mut std::io::stderr(), concat!("[DEBUG] ", $(stringify!($a), "={:?} "),*), $($a),*);
    }
}

#[allow(unused_imports)]
use std::cmp::{min, max};
#[allow(unused_imports)]
use std::io::{stdout, stdin, BufWriter, Write};

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

    input!{
      aa: [usize; 3],
    }
    let sum = aa.iter().sum::<usize>();
    if sum >= 22 {
        puts!("{}\n", "bust");
    } else {
        puts!("{}\n", "win");
    }
}


Measured memory_bytes: 4352
//ITP1_4_A
#include<iostream>
using namespace std;

int main()
{
	int a,b;
	
	cin>>a>>b;
	
	cout<<a/b<<" "<<a%b<<" ";
	cout.setf(ios::fixed,ios::floatfield);
	cout<<(double)a/b<<endl;
	
	return 0;
}

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

int main(){
   int K,A, B;
   cin >> K >> A >> B;
   int C = 0;
   if(A%K>0) C = 1;
   //if(B-A+1>=K){cout << "OK" << endl;}
   if(K*(A/K+C)<=B){cout << "OK" << endl;}
   else{


   cout << "NG" << endl;}
}


Measured memory_bytes: 3636
#include<bits/stdc++.h>
using namespace std;
#define mem(a) memset(a,0,sizeof(a))
#define dbg(x) cout<<#x<<" = "<<x<<endl
#define ll long long
//不要再爆long long了！！！！！！！！不要再爆long long了！！！！！！！ 

int main()
{
	int a,b,c,d,t;
	cin>>a>>b>>c>>d>>t;
	int tt=(c-a)*60+d-b-t;
	cout<<(tt>0?tt:0);
	return 0;
}

Measured memory_bytes: 3608
import java.util.Scanner;
 
public class Main{
 
    public static void main(String[] args){
    	Scanner scan = new Scanner(System.in);
        double a = scan.nextDouble();
        double b = scan.nextDouble();
        double c = scan.nextDouble();
        System.out.printf("%.8f %.8f %.8f%n",
        		a * b * Math.sin(Math.toRadians(c)) / 2,
        		a + b + Math.sqrt(a * a + b * b - 2 * a * b * Math.cos(Math.toRadians(c))),
        		b * Math.sin(Math.toRadians(c)));
    }
}

Measured memory_bytes: 18944