akhauriyash/Code-Regression huggingface dataset:
from copy import *
from sys import *
from math import *
import queue
from collections import defaultdict,Counter,deque

setrecursionlimit(1000000)

#dp[x][y] 最終日にyを選択した際のx日目までの最大の幸福度
def main():
	n = int(input())
	abc = [list(map(int, input().split())) for i in range(n)]
	dp = [[0,0,0]]
	for i in range(1,n+1):
		temp = []
		temp.append(max(dp[i-1][1], dp[i-1][2]) + abc[i-1][0])
		temp.append(max(dp[i-1][0], dp[i-1][2]) + abc[i-1][1])
		temp.append(max(dp[i-1][1], dp[i-1][0]) + abc[i-1][2])
		dp.append(temp)
	print(max(dp[-1]))

def zip(a):
	mae = a[0]
	ziparray = [mae]
	for i in range(1,len(a)):
		if(mae != a[i]):
			ziparray.append(a[i])
			mae = a[i]
	return ziparray

def base_10_to_n(X, n):
	X_dumy = X
	out = ''
	while X_dumy>0:
		out = str(X_dumy%n)+out
		X_dumy = int(X_dumy/n)
	if(out == ''): return '0'
	return out

def gcd(m,n):
	x = max(m,n)
	y = min(m,n)
	while(x%y!=0):
		z = x%y
		x = y
		y = z
	return y

class Queue():
	#競プロ用のQueue
	def __init__(self):
		self.q = deque([])
	def push(self,i):
		self.q.append(i)
	def pop(self):
		return self.q.popleft()
	def size(self):
		return len(self.q)

class Stack():
	#怯プロ用のStack
	def __init__(self):
		self.q = []
	def push(self,i):
		self.q.append(i)
	def pop(self):
		return self.q.pop()
	def size(self):
		return len(self.q)

main()

Measured memory_bytes: 48384
#include <algorithm>
#include <assert.h>
#include <bitset>
#include <cfloat>
#include <complex>
#include <deque>
#include <fstream>
#include <functional>
#include <iomanip>
#include <iostream>
#include <limits.h>
#include <list>
#include <map>
#include <math.h>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <string>
#include <string.h>
#include <time.h>
#include <unordered_map>
#include <unordered_set>
#include <vector>
#define rep(i,n) for(int i = 0;i < n; i++)
#define REP(i,n) for(int i = 1;i <= n; i++)
// ----GCC ONLY---- //
#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
// ----        ---- //
#define ll long long
#define MOD 10000007
#define PB push_back
 
using namespace std;

int main(){

    string s;
    cin >> s;

    if(s == "Sunny") cout << "Cloudy" <<endl;
    else if(s == "Cloudy") cout << "Rainy" <<endl;
    else if(s == "Rainy") cout << "Sunny" <<endl;

    return 0;
}

Measured memory_bytes: 256
import sys
sys.setrecursionlimit(10 ** 6)
def input():
    return sys.stdin.readline()[:-1]
N , Q = map(int,input().split())
graph = [[] for _ in range(N)]
# The directly connecting nodes of each node are written in "graph".
point = [0] * N
for _ in range(N - 1):
    a , b = map(int,input().split())
    graph[a - 1].append(b - 1)
    graph[b - 1].append(a - 1)
    # graph can be

for _ in range(Q):
    p , x = map(int,input().split())
    point[p-1] += x

def dfs(now , prev = -1):
    for nx in graph[now]:
        if nx == prev:
            continue
        point[nx] += point[now]
        dfs(nx, now)

dfs(0)
print(*point)


Measured memory_bytes: 282840
#define  _CRT_SECURE_NO_WARNINGS
#pragma comment (linker, "/STACK:526000000")

#include "bits/stdc++.h"

using namespace std;
typedef string::const_iterator State;
#define eps 1e-11L
#define MAX_MOD 1000000007LL
#define GYAKU 500000004LL

#define MOD 998244353LL
#define seg_size 262144*2LL
#define pb push_back
#define mp make_pair
typedef long long ll;
#define REP(a,b) for(long long (a) = 0;(a) < (b);++(a))
#define ALL(x) (x).begin(),(x).end()

unsigned long xor128() {
	static unsigned long x = 123456789, y = 362436069, z = 521288629, w = time(NULL);
	unsigned long t = (x ^ (x << 11));
	x = y; y = z; z = w;
	return (w = (w ^ (w >> 19)) ^ (t ^ (t >> 8)));
}

void init() {
	iostream::sync_with_stdio(false);
	cout << fixed << setprecision(20);
}
#define int ll

void solve(){
	while (true) {
		int p, q;
		cin >> p >> q;
		if (p == 0) return;
		vector<string> bases, ans;
		REP(i, p) {
			string a;
			cin >> a;
			bases.push_back(a);
		}
		REP(i, q) {
			string a;
			cin >> a;
			ans.push_back(a);
		}
		vector<tuple<int, int, int, int>> findings;
		int a = 0, b = 0, c = 0;
		REP(i, p) {
			int cnt = 0;
			REP(q, bases[i].size()) {
				if (bases[i][q] == '.') {
					cnt++;
				}
				else break;
			}
			findings.push_back(make_tuple(a, b, c, cnt));
			REP(q, bases[i].size()) {
				if (bases[i][q] == '{') {
					a++;
				}
				else if (bases[i][q] == '}') {
					a--;
				}
				else if (bases[i][q] == '(') {
					b++;
				}
				else if (bases[i][q] == ')') {
					b--;
				}
				else if (bases[i][q] == '[') {
					c++;
				}
				else if (bases[i][q] == ']') {
					c--;
				}
			}
		}
		vector<tuple<int, int, int>> now_itr;
		for (int r = 1; r <= 20; ++r) {
			for (int c = 1; c <= 20; ++c) {
				for (int s = 1; s <= 20; ++s) {
					int ok = 1;
					REP(j,findings.size()) {
						if (get<3>(findings[j]) != get<0>(findings[j]) * r + get<1>(findings[j]) * c + get<2>(findings[j]) * s) {
							ok = 0;
						}
					}
					if (ok == 1) {
						now_itr.push_back(make_tuple(r, c, s));
					}
				}
			}
		}
		vector<tuple<int, int, int>> geko;
		REP(i, q) {
			geko.push_back(make_tuple(a, b, c));
			REP(q, ans[i].size()) {
				if (ans[i][q] == '{') {
					a++;
				}
				else if (ans[i][q] == '}') {
					a--;
				}
				else if (ans[i][q] == '(') {
					b++;
				}
				else if (ans[i][q] == ')') {
					b--;
				}
				else if (ans[i][q] == '[') {
					c++;
				}
				else if (ans[i][q] == ']') {
					c--;
				}
			}
		}
		set<int> going[100];
		REP(i, now_itr.size()) {
			REP(q, geko.size()) {
				going[q].insert(get<0>(now_itr[i]) * get<0>(geko[q]) + get<1>(now_itr[i]) * get<1>(geko[q]) + get<2>(now_itr[i]) * get<2>(geko[q]));
			}
		}
		REP(i, q) {
			if (i != 0) cout << " ";
			if (going[i].size() == 1) {
				cout << *(going[i].begin());
			}
			else {
				cout << -1;
			}
		}
		cout << endl;
	}
}

#undef int
int main() {
	init();
	solve();
}


Measured memory_bytes: 3344
var
	N,K,i,u,v:Longint;
	S:String;
procedure f(u:Longint);
begin
	if u=100 then S:=S+'100'
	else begin
		if u>9 then S:=S+chr(u div 10+48);
		S:=S+chr(u mod 10+48);
	end;
end;
begin
	read(N,K);
	if (N-1)*(N-2)<K*2 then begin
		writeln(-1);
		exit;
	end;
	K:=(N-1)*(N-2)div 2-K;
	writeln(K+N-1);
	for i:=2 to N do begin
		S:=S+'1 ';
		f(i);
		S:=S+' ';
	end;
	for u:=2 to N do begin
		if K=0 then break;
		for v:=u+1 to N do begin
			if K=0 then break;
			f(u);
			S:=S+' ';
			f(v);
			S:=S+' ';
			dec(K);
		end;
	end;
	writeln(S);
end.


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

typedef long long ll;

int N;
ll X;
vector<ll> L, P;

void calcu_level_len(void) {
	L.resize(N + 1);
	P.resize(N + 1);
	L[0] = P[0] = 1;
	for (int i = 1; i <= N; ++i) {
		L[i] = 2 * L[i - 1] + 3;
		P[i] = 2 * P[i - 1] + 1;
	}
}

ll rec(int n, ll x) {
	if (n == 0)
		return P[0];
	if (x == (ll)1)
		return (ll)0;
	else if (x > 1 && x <= 1 + L[n - 1])
		return rec(n - 1, x - 1);
	else if (x == 2 + L[n - 1])
		return P[n - 1] + 1;
	else if (x > 2 + L[n - 1] && x <= 2 + 2 * L[n - 1])
		return P[n - 1] + 1 + rec(n - 1, x - L[n - 1] - 2);
	else if (x == 3 + 2 * L[n - 1])
		return 2 * P[n - 1] + 1;

	return 0;
}

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

	calcu_level_len();
	ll ans = rec(N, X);

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


Measured memory_bytes: 256
p[1<<17],h[1<<17],i,I,n;main(k){for(scanf("%*d%d",&k);~scanf("%d",h+n);)p[n]=n++*1e4;for(;i<n;I=++i)for(;I<k+i;)p[++I]=fmin(p[I],p[i]+abs(h[I]-h[i]));printf("%d",p[n-1]);}

Measured memory_bytes: 1024
#include<bits/stdc++.h>
#define all(x) (x).begin(),(x).end()

using ll = long long;
using ld = long double;
using namespace std;

const ll inf = 2e18;
const ll mod = 1e9 + 7;
const ll N = 2e5 + 5;

int n, a[N];

ll fastpow(ll a, ll n, ll m) {
    ll res = 1;
    while (n) {
        if (n & 1)res = (res * a) % m;
        n >>= 1;
        a = (a * a) % m;
    }
    return res;
}
ll add(ll a, ll b, ll m) {
    return (a % m + b % m) % m;
}
ll sub(ll a, ll b, ll m) {
    return ((a - b) % m + m) % m;
}
ll mul(ll a, ll b, ll m) {
    return (a % m * b % m) % m;
}
ll div(ll a, ll b, ll m) {
    return mul(a, fastpow(b, m - 2, m), m);
}

ll findProductSum()
{
    // calculating array sum (a1 + a2  ... + an)
    ll array_sum = 0;
    for (int i = 0; i < n; i++)
        array_sum = add(array_sum, a[i], mod);

    // calcualting square of array sum
    // (a1 + a2 + ... + an)^2
    ll array_sum_square = mul(array_sum, array_sum, mod);

    // calcualting a1^2 + a2^2 + ... + an^2
    ll individual_square_sum = 0;
    for (int i = 0; i < n; i++)
        individual_square_sum = add(individual_square_sum, mul(a[i], a[i], mod), mod);

    // required sum is (array_sum_square -
    // individual_square_sum) / 2
    return div(sub(array_sum_square, individual_square_sum, mod), 2, mod);
}

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

    cout << findProductSum() << "\n";
}

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    cout.tie(nullptr);

    int t = 1;
    // cin>>t;

    while (t-- > 0) {
        code();
    }
}

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

using namespace std;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<string> vs;
typedef vector<bool> vb;
typedef vector<vb> vvb;
typedef pair<int, int> pii;
typedef long long ll;
typedef unsigned long long ull;
#define all(a)  (a).begin(),(a).end()
#define rall(a) (a).rbegin(), (a).rend()
#define pb push_back
#define mp make_pair
#define loop(i,a,b) for(ull i=(a);i<ull(b);++i)
#define rep(i,n) loop(i,0,n)
#define iter(i,c) for(auto i=(c).begin(); i!=(c).end(); ++i)
#define riter(i,c) for(auto i=(c).rbegin(); i!=(c).rend(); ++i)
const double eps = 1e-10;
const double pi  = acos(-1.0);
const double inf = (int)1e8;
namespace std {
    template<typename T>ostream&operator<<(ostream&os, vector<T>const&v){
        iter(it,v) os<<*it<<(it+1==v.end()?"":",");
        return os;
    }
    template<typename T, typename U>ostream&operator<<(ostream&os,const pair<T,U>&p){
        return os << "[" << p.dirst << "," << p.second << "]";
    }
}

#include <iostream>
#include <iomanip>
#include <cmath>
 
using namespace std;

const int b[]={
    0b0111111,
    0b0000110,
    0b1011011,
    0b1001111,
    0b1100110,

    0b1101101,
    0b1111101,
    0b0100111,
    0b1111111,
    0b1101111
};
 
void print(int n){
    cout << (bitset<7>(n)) << endl;
}

int main(){
    int n;
    while(cin >> n && n!=-1){
        vi v(n);
        rep(i,n) cin >> v[i];
        rep(i,n){
            if(i==0) print(0^b[v[i]]);
            else print(b[v[i-1]]^b[v[i]]);
        }
    }
}

Measured memory_bytes: 1200
#include<bits/stdc++.h>
using namespace std;
int main(){
  int N;
  cin >> N;
  vector<vector<char>> vec(N,vector<char>(N));
  for(int i=0; i<N; i++){
    for(int j=0; j<N; j++){
      cin >> vec.at(i).at(j);
    }
  }
  
  int INF = 1e9;
  
  vector<vector<int>> dist(N,vector<int>(N));
  for(int i=0; i<N; i++){
    for(int j=0; j<N; j++){
      if(i == j){
        dist.at(i).at(j) = 0;
      }
      else if(vec.at(i).at(j) == '0'){
        dist.at(i).at(j) = INF;
      }
      else{
        dist.at(i).at(j) = 1;
      }
    }
  }
  
  for(int k=0; k<N; k++){
    for(int i=0; i<N; i++){
      for(int j=0; j<N; j++){
        dist.at(i).at(j) = min(dist.at(i).at(j), dist.at(i).at(k) + dist.at(k).at(j));
      }
    }
  }
  
  int MAX = 0;
  int start = 0;
  
  for(int i=0; i<N; i++){
    for(int j=0; j<N; j++){
      if(dist.at(i).at(j)> MAX){
        MAX = dist.at(i).at(j);
        start = i;
      } 
      //cout << dist.at(i).at(j) << " ";
    }
    //cout << endl;
  }
  MAX++;
  
  
  vector<vector<int>> ans(MAX,vector<int>(0));
  map<int,int> mp;
  ans.at(0).push_back(start);
  mp[start] = 0;
  
  int cnt = 1;
  queue<int> Q;
  Q.push(start);
  int q = Q.size();
  int p = 0;
  
  while(Q.size()){
    p++;
    int x = Q.front();
    Q.pop();
    for(int i=0; i<N; i++){
      if(dist.at(x).at(i) == 1){
        if(!mp.count(i)){
          ans.at(cnt).push_back(i);
          Q.push(i);
          mp[i] = cnt;
        }
      }
    }
    if(p == q){
      cnt++;
      p = 0;
      q = Q.size();
    }
  }
  
  /*for(int i=0; i<MAX; i++){
    for(int j=0; j<ans.at(i).size(); j++){
      cout << ans.at(i).at(j) << " ";
    }
    cout << endl;
  }*/
  
  bool flag = true;
  for(int i=0; i<N; i++){
    for(int j=0; j<N; j++){
      if(mp[i] == mp[j] && vec.at(i).at(j) != '0'){
        flag = false;
      }
      if(vec.at(i).at(j) == '1' && abs(mp[i] - mp[j]) != 1){
        flag = false;
      }
    }
  }
  
  if(flag){
    cout << MAX << endl;
  }
  else{
    cout << -1 << endl;
  }
}   

Measured memory_bytes: 512
N = int(input())
H = list(map(int,input().split()))
max_H = H[0]
for i in range(1,N):
  if H[i]-H[i-1] < -1:
    print('No')
    break
  if H[i]-max_H < -1:
    print('No')
    break
  if max_H < H[i]:
    max_H = H[i]
else:
  print('Yes')

Measured memory_bytes: 14396
#include <bits/stdc++.h>
using namespace std;
#define r(i,a,n) for(int i=a;i<n;i++)
int a[9][9],n,v[9][9];
int dfs(int s,int d){
	int ss=0;
	if(d==n-1)return 1;
	r(i,1,n+1){
		r(j,1,n+1)v[j][s]=1;
		if(a[s][i]&&!v[s][i])ss+=dfs(i,d+1);
		r(j,1,n+1)v[j][s]=0;
	}
	return ss;
}
int main(){
	int m,qq,ww,s;
	cin>>n>>m;
	r(i,0,m){
		cin>>qq>>ww;
		a[qq][ww]=1;
		a[ww][qq]=1;
	}
	r(i,1,n+1){
		r(j,0,n+1)r(k,0,n+1)v[i][j]=0;
		if(a[1][i]){
			r(k,1,n+1)v[k][1]=1;
			s+=dfs(i,1);		}
	}
	cout<<s<<endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define Hello ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define ll long long
#define endl '\n'
void trace(int n, int arr[]){for(int i = 0; i < n; i++){cout << arr[i] << " ";} cout << endl << endl;}
vector<vector<int>> row, col;
vector<int> temp;
int h, w, k, ans;
char arr[8][8], tempArr[8][8];
bool paint(vector<int> r, vector<int> c){
    for(int i = 0; i < h; i++)
        for(int j = 0; j < w; j++)
            tempArr[i][j] = arr[i][j];
    for(int i = 0; i < r.size(); i++){
        for(int j = 0; j < w; j++)
            tempArr[r[i]][j] = 'R';
    }
    for(int i = 0; i < c.size(); i++){
        for(int j = 0; j < h; j++)
            tempArr[j][c[i]] = 'R';
    }
    int cntr = 0;
    for(int i = 0; i < h; i++)
        for(int j = 0; j < w; j++)
            if(tempArr[i][j] == '#')
                cntr++;
    return (cntr == k);
}
void solve(int idx, bool Brow, int limit){
    if(idx >= limit){
        if(Brow) row.push_back(temp);
        else col.push_back(temp);
        return;
    }
    temp.push_back(idx);
    solve(idx + 1, Brow, limit);
    temp.pop_back();
    solve(idx + 1, Brow, limit);
}
int main()
{
    Hello
    cin >> h >> w >> k;
    for(int i = 0; i < h; i++)
        for(int j = 0; j < w; j++)
            cin >> arr[i][j];
    temp.clear();
    solve(0, 1, h);
    temp.clear();
    solve(0, 0, w);
    for(int i = 0; i < row.size(); i++)
        for(int j = 0; j < col.size(); j++)
            if(paint(row[i], col[j]))
                ans++;
    cout << ans;
    return 0;
}

Measured memory_bytes: 3612
#include<bits/stdc++.h>
 
using namespace std;
 
const int backet = 333;
 
int N, Q;
vector< int > g[100000];
int in[100000], out[100000], ptr;
 
int sz[(100000 + backet - 1) / backet][10];
int convert[(100000 + backet - 1) / backet][10];
int data[100000];
 
void tour(int idx, int par = -1)
{
  in[idx] = ptr++;
  for(int &to : g[idx]) if(to != par) tour(to, idx);
  out[idx] = ptr;
}
 
void push(int k)
{
  for(int i = k * backet; i < min(N, (k + 1) * backet); i++) {
    data[i] = convert[k][data[i]];
  }
  for(int i = 0; i < 10; i++) {
    convert[k][i] = i;
    sz[k][i] = 0;
  }
  for(int i = k * backet; i < min(N, (k + 1) * backet); i++) {
    sz[k][data[i]]++;
  }
}
 
int main()
{
  cin >> N >> Q;
  for(int i = 1; i < N; i++) {
    int U, V;
    cin >> U >> V;
    g[U].push_back(V);
    g[V].push_back(U);
  }
  tour(0);
 
  int all = (N + backet - 1) / backet;
  for(int i = 0; i < all; i++) {
    sz[i][0] += min(N, (i + 1) * backet) - i * backet;
    for(int j = 0; j < 10; j++) convert[i][j] = j;
  }
 
  while(Q--) {
    int t, s, x, y;
    cin >> t >> s >> x >> y;
 
    int a = in[s], b = out[s];
 
    if(t == 1) {
      int sum = 0;
      for(int i = 0; i < all; i++) {
        int l = i * backet, r = min(N, (i + 1) * backet);
        if(a >= r || b <= l) continue;
        if(a <= l && r <= b) {
          for(int k = 0; k < 10; k++) {
            if(x <= convert[i][k] && convert[i][k] <= y) sum += sz[i][k];
          }
        } else {
          push(i);
          for(int j = max(a, l); j < min(b, r); j++) {
            if(x <= data[j] && data[j] <= y) sum++;
          }
        }
      }
      cout << sum << endl;
    } else {
      for(int i = 0; i < all; i++) {
        int l = i * backet, r = min(N, (i + 1) * backet);
        if(a >= r || b <= l) continue;
        if(a <= l && r <= b) {
          for(int k = 0; k < 10; k++) {
            if(convert[i][k] == x) convert[i][k] = y;
          }
        } else {
          push(i);
          for(int j = max(a, l); j < min(b, r); j++) {
            if(data[j] == x) {
              data[j] = y;
              --sz[i][x];
              ++sz[i][y];
            }
          }
        }
      }
    }
  }
}

Measured memory_bytes: 14124
#include <bits/stdc++.h>
#define FOR(i, begin, end) for(int i=(begin);i<(end);i++)
#define REP(i, n) FOR(i,0,n)
#define IFOR(i, begin, end) for(int i=(end)-1;i>=(begin);i--)
#define IREP(i, n) IFOR(i,0,n)
#define SORT(a) sort(a.begin(), a.end())
#define REVERSE(a) reverse(a.begin(), a.end())
#define Lower_bound(v, x) distance(v.begin(), lower_bound(v.begin(), v.end(), x))
#define Upper_bound(v, x) distance(v.begin(), upper_bound(v.begin(), v.end(), x))
#define int long long
#define INF 1000000000000000000
using namespace std;

typedef vector<int> vec;
typedef vector<vec> mat;
typedef pair<int, int> Pii;

template<typename T>
void readv(vector<T> &a){ REP(i, a.size()) cin >> a[i]; }
void readi(vector<int> &a){ REP(i, a.size()){cin >> a[i]; a[i]--;} }



signed main(){

    int N, C, K; cin >> N >> C >> K;
    vec T(N); readv(T);
    SORT(T);
    T.push_back(INF);

    int ans = 0;
    int t = T[0], n = 0;

    REP(i, N){
        if(T[i] <= t + K){
            n++;
        }else{
            ans++;
            t = T[i];
            n = 1;
        }
        if(n == C || i == N - 1){
            ans++;
            n = 0;
            t = T[i + 1];
        }
    }
    cout << ans;
    
    return 0;
}

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

public class Main {

	public static void main(String args[]) {
		Scanner sc = new Scanner(System.in);

		while (true) {
			final long a = sc.nextLong();
			final String ops = sc.next();
			final long b = sc.nextLong();

			if("?".equals(ops)){
				break;
			}else if("+".equals(ops)){
				System.out.println(a + b);
			}else if("-".equals(ops)){
				System.out.println(a - b);
			}else if("*".equals(ops)){
				System.out.println(a * b);
			}else if("/".equals(ops)){
				System.out.println(a / b);
			}
			
			
		}
	}

}

Measured memory_bytes: 18056
#include <bits/stdc++.h>
#include <iostream>
#include <string>
#include <cstdlib> 
#include <string.h>
#include <vector>
#include <cstdio>
#include <iomanip>
#include <stack>
#include <set>
#include <map>
#include <list>
#include <ctime>
#include <algorithm>
#include <cmath>
#define PI 3.1415926535897932384626433832795l
#define IOS ios :: sync_with_stdio(false); cin.tie(0); cout.tie(0)
#define deci(n) cout<<fixed<<setprecision(n);
#define F first
#define S second
#define mk make_pair
#define pb push_back
#define ALPHA 27
#define ll long long int
#define ld long double
#define mmset(arr, n) memset(arr, n, sizeof arr)
#define debug(x) cerr << '#' << ' ' << x << '\n'
#define len(s) s.length()
#define ForA(i,a,b) for(int i = a; i < b; i++)
#define ForA1(i,a,b) for(int i = b - 1; i >= a; i--)
#define ForB1(i,a,b) for(int i = b; i > a; i--)
#define ForB(i,a,b) for(int i = a; i <= b; i++)
#define INT_SIZE 18 
#define maxn 100010

using namespace std;

const ll INF = (ll)(8e18);
const ll MOD = 1000000007;

int a[maxn], dp[maxn][3], b[maxn], c[maxn];

int main()
{
    IOS;     
    int n; cin >> n;
    ForB(i,1,n) cin >> a[i] >> b[i] >> c[i];
    dp[1][0] = a[1];
    dp[1][1] = b[1];
    dp[1][2] = c[1];
    ForB(i,2,n){
        dp[i][0] = max(dp[i - 1][1] , dp[i - 1][2]) + a[i];
        dp[i][1] = max(dp[i - 1][0] , dp[i - 1][2]) + b[i];
        dp[i][2] = max(dp[i - 1][0] , dp[i - 1][1]) + c[i];
    }
    cout << max(dp[n][0], max(dp[n][1], dp[n][2])) << '\n';
    #ifdef LOCAL_DEFINE
    cerr << "Time elapsed: " << 1.0 * clock() / CLOCKS_PER_SEC << " s.\n";
    #endif
    return 0 ;
}


Measured memory_bytes: 2560
#include<bits/stdc++.h>
#define int long long
using namespace std;
main(){
int n;
cin>>n;
int A[n];
for(int i=0 ; i<n ;i++)
    cin>>A[i];

sort(A , A+n);
vector<int>sides;
for(int i=n-1 ; i>=1 ; i--){
    if(A[i] == A[i-1])
    sides.push_back(A[i]) , i--;

}

if(sides.size()>=2){
    cout<<sides[0] * sides[1]<<endl;
}

else
    cout<<0<<endl;
}


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

using namespace std;

#define int long long
#define endl '\n'
#define maxn 100010
const int MOD = 1000000007;

vector<int> z_function(string s) {
    int n = (int) s.length();
    vector<int> z(n);
    for (int i = 1, l = 0, r = 0; i < n; ++i) {
        if (i <= r)
            z[i] = min(r - i + 1, z[i - l]);
        while (i + z[i] < n && s[z[i]] == s[i + z[i]])
            ++z[i];
        if (i + z[i] - 1 > r)
            l = i, r = i + z[i] - 1;
    }
    return z;
}

void solve() {
    int n;
    cin >> n;

    string s;
    cin >> s;

    n = s.size();
    int ans = 0;
    for (int i = 0; i < n; i++) {
        vector<int> v = z_function(s.substr(i));
        for (int i = 0; i < v.size(); i++) {
            if (v[i] > i)continue;
            ans = max(ans, v[i]);
        }
    }
    cout << ans << endl;
}

int32_t main() {
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);

    int t = 1;
//    cin >> t;

    while (t--)
        solve();
    return 0;
}

Measured memory_bytes: 384
A, B, C = input(), input(), input()

card = A[0]
while(1) :
  if card == 'a' :
    if not A : print("A"), exit(0)
    card = A[0]
    A = A[1:]
    continue
  if card == 'b' :
    if not B : print("B"), exit(0)
    card = B[0]
    B = B[1:]
    continue
  if card == 'c' :
    if not C : print("C"), exit(0)
    card = C[0]
    C = C[1:]
    continue


Measured memory_bytes: 3064
#include<stdio.h>
#include<math.h>
#define N 6
 
typedef struct{
  double x;
  double y;
}XY;
 
void koch(int,XY,XY);
 
int main()
{
  int n,i;
 
  XY p1 = {0.0,0.0},p2 = {100.0,0.0};
  scanf("%d",&n);
  printf("%.8f %.8f\n",p1.x,p1.y);
  koch(n,p1,p2);
  printf("%.8f %.8f\n",p2.x,p2.y);
 
  return 0;
}
 
void koch(int n,XY p1,XY p2)
{
  XY s,t,u;
 
  if(n == 0) return;
 
  s.x = (2 * p1.x + 1 * p2.x) / 3;
  s.y = (2 * p1.y + 1 * p2.y) / 3;
  t.x = (1 * p1.x + 2 * p2.x) / 3;
  t.y = (1 * p1.y + 2 * p2.y) / 3;
  u.x = (t.x - s.x) * 1 / 2 - (t.y - s.y) * sqrt(3) / 2 + s.x;
  u.y = (t.x - s.x) * sqrt(3) / 2 + (t.y - s.y) * 1 / 2 + s.y;
 
  koch(n-1,p1,s);
  printf("%.8f %.8f\n",s.x,s.y);
 
  koch(n-1,s,u);

 printf("%.8f %.8f\n",u.x,u.y);
  koch(n-1,u,t);

  
  printf("%.8f %.8f\n",t.x,t.y);
  koch(n-1,t,p2);


 

}

Measured memory_bytes: 640
#include "bits/stdc++.h"
using namespace std;

struct root {
	int to;
	long long cost;
};

int N, Q, K;
vector<root> Root[100010];
static long long Dis[100010] = {};

void DFS(int v, int p, long long d) {
	Dis[v] = d;
	for (root x : Root[v]) {
		if (x.to == p) continue;
		DFS(x.to, v, d + x.cost);
	}
}

int main() {
	cin >> N;
	for (int i = 0; i < N - 1; i++) {
		int a, b, c;
		cin >> a >> b >> c;
		a--, b--;
		Root[a].push_back(root{ b, c });
		Root[b].push_back(root{ a, c });
	}
	cin >> Q >> K;
	K--;
	DFS(K, -1, 0);
	for (int i = 0; i < Q; i++) {
		int x, y;
		cin >> x >> y;
		x--, y--;
		cout << Dis[x] + Dis[y] << endl;
	}
}

Measured memory_bytes: 14336
#include<iostream>
using namespace std;
int main(){
int a,b;
char op;
while(1){
cin >> a >> op >> b;
if(op=='?')break;

if(op=='+') cout << a+b <<endl;
else if(op=='-') cout << a-b <<endl;
else if(op=='*') cout << a*b <<endl;
else if(op=='/') cout << a/b <<endl;
}
return 0;
}


Measured memory_bytes: 3080
#include <iostream>
#include <numeric>
#include <math.h>
#include <algorithm>
#include <float.h>
#include <limits>
#include <vector>
#include <string.h>
#include <iomanip>
#include <sstream>

#define rep(i,a,n) for(ll int (i) = (a);(i) < (n);(i)++)
#define urep(i,a,n) for(ll int (i) = (a);(i) > (n);(i)--)
#define MOD 1000000007
#define INF 2147483647
#define ll long long
#define asort(a) sort(a.begin(),a.end());
#define usort(a) sort(a.rbegin(),a.rend());

using namespace::std;

ll int jo(ll int a, ll int b){//累乗
    ll int num=1;
    rep(i,0,b) num=num*a;
    return num;
}
char tobig(char s){//char大文字化
  return (s-0x20);
}
char tolow(char s){//char小文字化
  return (s+0x20);
}
int ctoi(char a){//char->int
  if('0'<=a&&a<='9') return (a-'0');
  return -1;
}
ll int gcd(ll int a,ll int b) {//最大公約数
  if(a<b) return gcd(b,a);
  int c;
  while ((c=a%b)) {
    a=b;
    b=c;
  }
  return b;
}
ll int lcm(ll int a,ll int b){//最小公倍数
 return (a*b)/gcd(a,b);
}


int main(){
  char c;
  cin>>c;
  cout<<(c-'A'<28?"A":"a");

}
// int *p = new int[N];

//  sort(変数名.begin(),変数名.end());//昇順ソート
//  sort(変数名.rbegin(),変数名.rend());//降順ソート

// vector<vector<int>> 変数名(左の個数, vector<int>(右の個数));

//cout<<fixed<<setprecision(n);  //小数点n桁まで表示

//  vector<pair<int,int>> data(N);  //2つのデータを格納、.first/.secondで参照
// pairのソートはfirst優先の昇順

//cout.fill('0');
//cout<<setw(N)<<value;  //整数の左側を0梅して指定桁数出力

//    str tmp,str;　　　　　//一行の入力を指定した文字で分割//a[i]はあらかじめ宣言しておくこと
//    getline(cin,str);
//    stringstream ss{str};  //これがないとバグる
//    while(getline(ss,tmp,'分割したい文字')){
//      a[i]=tmp;
//      i++;
//  }


//    int N=atoi(変換したい文字列.c_str());//stringをintに変換


Measured memory_bytes: 3552
#include<iostream>
#include<string>
#include<vector>
#include<math.h>
#include<map>
#include<algorithm>
#include<set>
#define rep(i,N) for(int i=0;i<(N);i++)
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
using namespace std;
const long long MOD = 1e9 + 7;
const long long INF = 1e12;
int main(void){
    long long a,b,x;
    vector<int> v(3,0);
    cin>>a>>b;

    if(a-b>0) cout<<a-b<<endl;
    else cout<<"0"<<endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define ld double
#define ll long long
#define pb emplace_back
#define mk make_pair
#define mod 1000000007
#define ff first
#define ss second
#define sz(x) (int)x.size()
#define FIO ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
#define all(x) x.begin(),x.end()
ll power(ll a, ll b) {ll res = 1; a = a % mod; while (b) {if (b & 1)res = (res * a) % mod; a = (a * a) % mod; b /= 2;} return res;}
ll invmod(ll a) {return power(a, mod - 2);}
int main(void)
{
	FIO
	int t = 1;
	// cin>>t;
	while (t--)
	{
		int n;
		string s;
		cin >> n >> s;
		ll x = 0, ans = 0;
		while ((x = s.find("ABC", x)) != string::npos) {
			ans++;
			x++;
		}
		cout << ans << "\n";
	}
	return 0;
}

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

typedef long long int ll;

#define endl '\n'

string s,t;
ll dp[3005][3005];
ll sp[3005][3005];

ll solve(ll i,ll j)
{
    if(i==s.size() || j==t.size())return 0;

    if(dp[i][j]==-1)
    {

        if(s[i]==t[j]){
            ll vala = 1 + solve(i+1,j+1);
            ll valb = solve(i+1,j);
            ll valc = solve(i,j+1);
            ll ma = max({vala,valb,valc});
            dp[i][j] = ma;
            if(ma==valc){
                sp[i][j] = 2;
            }
            else{
                if(ma==valb){
                    sp[i][j] = 1;
                }
                else{
                    sp[i][j] = 0;
                }
            }

        }
        else{
            ll valb = solve(i+1,j);
            ll valc = solve(i,j+1);
            dp[i][j] = max(valb,valc);

            if(dp[i][j]==valb){
                sp[i][j] = 1;
            }
            else{
                sp[i][j] =2;
            }

        }

    }
    return dp[i][j];


}

string gen(ll i,ll j)
{

    if(i>=s.size() || j>=t.size())return "";

    if(sp[i][j]==0){
        return s[i]+gen(i+1,j+1);
    }
    else{
        if(sp[i][j]==1){
            return gen(i+1,j);
        }
        else{
            return gen(i,j+1);
        }
    }

}

int main()
{
    std::ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    memset(dp,-1,sizeof(dp));
    memset(sp,-1,sizeof(sp));
    cin>>s>>t;

    ll x = solve(0,0);

    cout<<gen(0,0)<<endl;



}


Measured memory_bytes: 141696
#include <bits/stdc++.h>
#define ll          long long
#define pb          push_back
#define pii         pair<int,int>
#define vi          vector<int>
#define all(a)      (a).begin(),(a).end()
#define F           first
#define S           second
#define sz(x)       (int)x.size()
#define hell        1000000007
#define endl        '\n'
using namespace std;
int main()
{
    //std::ios::sync_with_stdio(false);
    //cin.tie(0);
    //cout.tie(0);
    ll x,y;
    int res=0;
    cin>>x>>y;
    while(x<=y){
    	res++;
    	x*=2;
    }
    cout<<res;
    return 0;
}



Measured memory_bytes: 256
A, B, C, X = map(lambda x: int(x) + 1, [input() for q in range(4)])
r = 0
for a in range(A):
    for b in range(B):
        for c in range(C):
            if (500 * a + 100 * b + 50 * c) == (X - 1):
                r += 1
print(r)

Measured memory_bytes: 2940
#include <iostream>
#include <string.h>
using namespace std;

void a_something_on_it(void) {
	string s;
	cin >> s;
	int sum = 0;
	for (int i = 0; i < 3; i++) {
		if (s[i] == 'o') sum += 100;
	}
	cout << sum+700 << endl;
}

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

Measured memory_bytes: 3636
import java.util.*;
public class Main {
    public static void main(String[] args) throws Exception {
        Scanner sc = new Scanner(System.in);
        int a = sc.nextInt();
        int b = sc.nextInt();
        String c[] = new String [a];
        for(int i = 0;i < c.length;i++){
            c[i] = sc.next();
            System.out.println(c[i]);
            System.out.println(c[i]);
        }
    }
}


Measured memory_bytes: 24788
use std::io::{BufRead, StdinLock};

fn main() {
    // stdin()のロックを取得
    let stdin = std::io::stdin();
    let mut stdin = stdin.lock();
    let stdin = &mut stdin;

    let mut buf = String::new();
    stdin.read_line(&mut buf).unwrap();

    let mut num = buf.trim().parse::<i32>().unwrap();
    let mut i32_vector = read_line_with_whitespace(stdin); // 1行複数要素
                                                           // let mut i32_vector = read_parallel_line(stdin, num); // 複数行各1要素

    let result = solve(&mut i32_vector);
}

// 答えを作成する関数
fn solve(int_vector: &mut Vec<i32>) -> String {
    let mut result = String::with_capacity(1000);
    // --解法作成開始
    trace(int_vector);
    for index in 1..int_vector.len() {
        let temporary_number = *&int_vector[index];
        let mut degrease_counter = index - 1;

        while int_vector[degrease_counter] > temporary_number {
            int_vector.swap(degrease_counter + 1, degrease_counter);
            if degrease_counter == 0 {
                break;
            }
            degrease_counter -= 1;
        }
        trace(int_vector);
    }
    // --解法作成終了
    result
}

fn trace(int_vector: &Vec<i32>) {
    let mut message = String::with_capacity(1000);
    message += &format!("{}", int_vector[0]);
    for index in 1..int_vector.len() {
        message += &format!(" {}", int_vector[index]);
    }
    println!("{}", message);
}

fn insert_sort(int_vector: &mut Vec<i32>) {}

#[test]
fn solve_check() {
    let mut int_vector = vec![]; // 初期入力
    assert_eq!("".to_string(), solve(&mut int_vector))
}

#[warn(dead_code)]
fn read_line_with_whitespace(stdin: &mut StdinLock) -> Vec<i32> {
    let mut buf = String::new();
    stdin.read_line(&mut buf).unwrap();

    let mut iter = buf.trim().split_whitespace();
    let i32_vector = iter
        .map(|iter| iter.parse::<i32>().unwrap())
        .collect::<Vec<i32>>();
    i32_vector
}

#[warn(dead_code)]
fn read_parallel_line(stdin: &mut StdinLock, length: i32) -> Vec<i32> {
    let mut i32_vector = vec![];
    for _ in 0..length {
        let mut buf = String::new();
        stdin.read_line(&mut buf).unwrap();
        let message = buf.trim();
        let num: i32 = message.parse().unwrap();
        i32_vector.push(num);
    }
    i32_vector
}



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

int main(){
    string K;
    cin >> K;
    if(K[0] == 'R' && K[1] == 'R' && K[2] == 'R'){
      cout << 3 << endl;
      return 0;
    } else if (K[0] == 'R' && K[1] == 'R' && K[2] != 'R'){
      cout << 2 << endl;
      return 0;
    } else if (K[0] != 'R' && K[1] == 'R' && K[2] == 'R'){
      cout << 2 << endl;
      return 0;
    } else if (K[0] != 'R' && K[1] != 'R' && K[2] != 'R'){
      cout << 0 << endl;
      return 0;
    } else {
      cout << 1 << endl;
    }
}

Measured memory_bytes: 3592
// https://atcoder.jp/contests/abc122/tasks/abc122_b
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define REP(i, n) FOR(i, 0, n)
#define REPR(i, n) for (int i = n - 1; i >= 0; i--)
#define FOR(i, s, n) for (int i = (s), i##_len = (n); i < i##_len; ++i)
#define ALL(obj) (obj).begin(), (obj).end()
#define ALLR(obj) (obj).rbegin(), (obj).rend()
#define DIV(a, b) ((a - 1) / b + 1)

signed main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    string str;
    cin >> str;
    regex patern("[ACGT]+");
    smatch match;

    size_t maxv = 0;
    while (regex_search(str, match, patern)) {
        maxv = max(maxv, match.str().length());
        str = match.suffix();
    }
    cout << maxv << endl;

    return 0;
}


Measured memory_bytes: 3740
import java.util.*;

public class Main {

    public static void main(String[] args) {
    	Scanner sc = new Scanner(System.in);
    	int N = sc.nextInt();
    	if (N % 2 == 0) {
    		System.out.println((double)1/2);
    	} else {
    		System.out.println((double)(N/2+1) / N);
    	}
	}
}


Measured memory_bytes: 21972
#include <bits/stdc++.h>
using namespace std;
 
#define rep(i, n) for (int i = (int)(0); i < (int)(n); ++i)
#define reps(i, n) for (int i = (int)(1); i <= (int)(n); ++i)
#define rrep(i, n) for (int i = ((int)(n)-1); i >= 0; i--)
#define rreps(i, n) for (int i = ((int)(n)); i > 0; i--)
#define irep(i, m, n) for (int i = (int)(m); i < (int)(n); ++i)
#define ireps(i, m, n) for (int i = (int)(m); i <= (int)(n); ++i)
#define FOR(e, c) for (auto &e : c)
#define SORT(v, n) sort(v, v + n);
#define vsort(v) sort(v.begin(), v.end());
#define rvisort(v) sort(v.begin(), v.end(), greater<int>());
#define all(v) v.begin(), v.end()
#define mp(n, m) make_pair(n, m);
#define cout(d) cout<<d<<endl;
#define coutd(d) cout<<std::setprecision(10)<<d<<endl;
#define cinline(n) getline(cin,n);
#define replace_all(s, b, a) replace(s.begin(),s.end(), b, a);
 
using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vll = vector<ll>;
using vvll = vector<vll>;
using pii = pair<int, int>;
using vpii = vector<pii>;
using vs = vector<string>;
using vd = vector<double>;
using ul = unsigned long;
 
template<class T, class C> void chmax(T& a, C b){ a>b?:a=b; }
template<class T, class C> void chmin(T& a, C b){ a<b?:a=b; }
 
int main()
{
  cin.tie( 0 );
  ios::sync_with_stdio( false );
  
  int n;cin>>n;
  int ans=1;
  for(int i=1;i*i<=n;i++){
    ans=i*i;
  }
  cout(ans);
  return 0;
}

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

using namespace std;

#define ALL(x) (x).begin(), (x).end()
#define AND(x,y,z) 
#define DUMP(xs) for (auto x:xs) cout<<x<<' ';cout<<endl
#define DUMPP(xs) for (auto x:xs) cout<<'('<<x.first<<','<<x.second<<')';cout<<endl
#define FOR(i,a,b) for (ll i=(ll)(a);i<(ll)(b);++i)
#define OUT(x) cout<<x<<endl
#define REP(i,n) FOR(i,0,n)
#define YES(cond) cond ? OUT("YES") : OUT("NO")
#define Yes(cond) cond ? OUT("Yes") : OUT("No")

template<class T> T gcd(const T x,const T y){if(!y){return x;}return gcd(y,x%y);}
template<class T> T lcm(const T x,const T y){return x/gcd(x,y)*y;};
template<class T> T modpow(const T x,const T n,const T mod) {
  T res=1;while(n>0){if(n%2)res=res*x%mod;x=x*x%mod;n/=2;};return res;
}
template<class T> bool alltrue(const T &a){return all_of(ALL(a),[](bool x){return x;});}
template<class T> bool anytrue(const T &a){return any_of(ALL(a),[](bool x){return x;});}
template<class T> bool contain(const T &a,const T &b){for(auto x:b){if (a.find(x)==a.end()){return false;}}return true;}
template<class T> bool mmax(T &m,const T q){ if (m < q) {m = q; return true;} else return false; }
template<class T> bool mmin(T &m,const T q){ if (m > q) {m = q; return true;} else return false; }
template<class T> int siz(const T &a) {return (int)a.size();}
template<class T> set<T> devisers(T n) {
  set<T> res;for(T i=1;i<(T)sqrt(n)+1;i++){if(n%i==0){res.insert(i);res.insert(n/i);}}return res;
}
template<class T> void concat(T &a, const T &b){a.insert(a.end(),b.begin(),b.end());}
template<class T> void getand(const T &a,const T &b,T &c) {
  set_intersection(a.begin(),a.end(),b.begin(),b.end(),inserter(c,c.end()));
}
template<class T> void getor(const T &a,const T &b,T &c) {
  set_union(a.begin(),a.end(),b.begin(),b.end(),inserter(c,c.end()));
}

typedef long long ll;
typedef pair<ll, ll> P;

const ll MOD=1e9+7;
const int MAX=1e5+100;

ll gcd(ll a, ll b) {
  if (!b) return a;
  return gcd(b,a%b);
}
ll lcm(ll a, ll b) {
  return a/gcd(a,b)*b;
}

int main() {
  ll A,B;cin>>A>>B;
  OUT(lcm(A,B));

  return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <stdio.h>
#include <algorithm>
#include <vector>
#include <utility>
#include <cstdio>
#include <iomanip>
#include <cmath>
#include <string>
#include <stack>
#include <queue>
#include <map>
#include <stdlib.h>
#include <set>
typedef long long ll;
using namespace std;

int main() {
	int n,cr=0,cb=0;
	string s,w;
	cin>>n>>s;
	for(int i=0;i<n;i++){
		if(s.substr(i,1)=="R"){
			cr++;
		}else{
			cb++;
		}
	}
	if(cr>cb){
		cout<<"Yes"<<endl;
	}else{
		cout<<"No"<<endl;
	}

	return 0;
}



Measured memory_bytes: 256
#include<bits/stdc++.h>
typedef long long int ll;
typedef unsigned long long int ull;
#define BIG_NUM 2000000000
#define HUGE_NUM 1000000000000000000
#define MOD 1000000007
#define EPS 0.000000001
using namespace std;




int main(){

	int N;
	scanf("%d",&N);

	int tmp = N,sum = 0;

	while(tmp > 0){

		sum += tmp%10;
		tmp /= 10;
	}

	if(N%sum == 0){

		printf("Yes\n");
	}else{

		printf("No\n");
	}

	return 0;
}


Measured memory_bytes: 3600
// aribon2-3-5_c
// https://atcoder.jp/contests/arc083/tasks/arc083_c
#include <bits/stdc++.h>
#ifdef LOCAL
#include "../cxx-prettyprint/prettyprint.hpp"
#endif
using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> P;

#define REP(i, n) for (int (i) = 0 ; (i) < (int)(n) ; ++(i))
#define REPN(i, m, n) for (int (i) = m ; (i) < (int)(n) ; ++(i))
#define REP_REV(i, n) for (int (i) = (int)(n) - 1 ; (i) >= 0 ; --(i))
#define REPN_REV(i, m, n) for (int (i) = (int)(n) - 1 ; (i) >= m ; --(i))
#define ALL(x) x.begin(), x.end()

#define INF ((1 << 29)-1)
#define MOD (1000000007)

#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 << x << endl;}
template<class T, class... A> void print(const T& first, const A&... rest) { cout << first << " "; print(rest...); }
struct PreMain {PreMain(){cin.tie(0);ios::sync_with_stdio(false);cout<<fixed<<setprecision(20);}} premain;

int N;
int X[1000];
vector<int> G[1000];
int memo[1001]; // 部分木の、自分の色じゃないほうの和の最小値

int dfs(int v){

    if (memo[v] >= 0) return memo[v];

    int sz = G[v].size();
    if (sz == 0) return 0;

    vector<vector<bool>> dp;
    dp.assign(sz+1, vector<bool>(X[v]+1, false));
    dp[0][0] = true;
    int sm = 0;
    REP(i, sz){
        int c = G[v][i];
        memo[c] = dfs(c);
        if (memo[c] == -1) return -1;
        sm += memo[c] + X[c];
        REP_REV(j, X[v]+1){
            bool tmp = false;
            if (j >= X[c]) tmp |= dp[i][j - X[c]];
            if (j >= memo[c]) tmp |= dp[i][j - memo[c]];
            dp[i+1][j] = tmp;
        }
    }

    REP_REV(j, X[v]+1){
        if (dp[sz][j]) {return sm - j;}
    }
    return -1;
}


int main() {
#ifdef LOCAL
    ifstream in("../arg.txt");
    cin.rdbuf(in.rdbuf());
#endif

    cin >> N;
    REPN(i, 1, N) {
        int p; cin >> p;
        G[--p].emplace_back(i);
    }
    REP(i, N) cin >> X[i];
    REP(i, N) memo[i] = -1;

    int ans = dfs(0);
    if (ans == -1) {
        print("IMPOSSIBLE");
    } else {
        print("POSSIBLE");
    }

    return 0;
}


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

int main(){
  int a,b,c;
  cin >>a>>b>>c;
  if (a==7||b==7||c==7){
    if ((a==5&&b==5)||(a==5&&c==5)||(b==5&&c==5)){
      cout<<"YES"<<endl;
      return 0;
    }
  }
  cout<<"NO"<<endl;
}

Measured memory_bytes: 256
//#include <bits/stdc++.h>
#include <iostream>
#include <algorithm>
#include <string>
using namespace std;
int n;


int main(){
  cin >> n;
  int x;
  int minNum ;
  int maxNum ;
  for(int i = 0; i < n; i++){
    cin >> x;
    if(i == 0){
     minNum = x;
     maxNum = x;
   }else{
      minNum = min(minNum,x);
      maxNum = max(maxNum,x);
    }
  }
  int ans = abs(maxNum - minNum);
  cout <<  ans << endl;



  return 0;
}


Measured memory_bytes: 256
import java.util.*;
class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int l = sc.nextInt()+sc.nextInt();
        int r = sc.nextInt()+sc.nextInt();
        if(l>r) {
            System.out.println("Left");
        }else if (l==r) {
            System.out.println("Balanced");
        }else {
            System.out.println("Right");
        }
    }
}

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

#define REP(i,n) for(long long i = 0; i < (n); i++)
#define FOR(i, m, n) for(long long i = (m);i < (n); ++i)
#define ALL(obj) (obj).begin(),(obj).end()

template<class T> using V = vector<T>;
template<class T, class U> using P = pair<T, U>;

const ll MOD = (ll)1e9 + 7;
const ll MOD2 = 998244353;
const ll LLINF = (ll)1e18;
const ll INTINF = (ll)1e9;
const long double PI = 3.1415926535897932384626433;

template <class T> void corner(bool flg, T hoge) {if (flg) {cout << hoge << endl; exit(0);}}
template <class T, class U>ostream &operator<<(ostream &o, const map<T, U>&obj) {o << "{"; for (auto &x : obj) o << " {" << x.first << " : " << x.second << "}" << ","; o << " }"; return o;}
template <class T>ostream &operator<<(ostream &o, const set<T>&obj) {o << "{"; for (auto itr = obj.begin(); itr != obj.end(); ++itr) o << (itr != obj.begin() ? ", " : "") << *itr; o << "}"; return o;}
template <class T>ostream &operator<<(ostream &o, const vector<T>&obj) {o << "{"; for (int i = 0; i < (int)obj.size(); ++i)o << (i > 0 ? ", " : "") << obj[i]; o << "}"; return o;}
template <class T, class U>ostream &operator<<(ostream &o, const pair<T, U>&obj) {o << "{" << obj.first << ", " << obj.second << "}"; return o;}
template <template <class tmp>  class T, class U> ostream &operator<<(ostream &o, const T<U> &obj) {o << "{"; for (auto itr = obj.begin(); itr != obj.end(); ++itr)o << (itr != obj.begin() ? ", " : "") << *itr; o << "}"; return o;}
void print(void) {cout << endl;}
template <class Head> void print(Head&& head) {cout << head;print();}
template <class Head, class... Tail> void print(Head&& head, Tail&&... tail) {cout << head << " ";print(forward<Tail>(tail)...);}
template <class T> void chmax(T& a, const T b){a=max<T>(a,b);}
template <class T> void chmin(T& a, const T b){a=min<T>(a,b);}
void YN(bool flg) {cout << ((flg) ? "YES" : "NO") << endl;}
void Yn(bool flg) {cout << ((flg) ? "Yes" : "No") << endl;}
void yn(bool flg) {cout << ((flg) ? "yes" : "no") << endl;}


int main() {
	int N,M; cin >> N >> M;
	V<int> A(10,0),B = {0,2,5,5,4,5,6,3,7,6};
	while(M--){
		int a; cin >> a;
		A[a] = 1;
	}
	V<P<int,int>> dp(N + 10,{-1,-1});
	dp[0] = {0,0};
	for(int i = 0; i < N; ++i){
		int digit = dp[i].first;
		if(digit == -1) continue;
		for(int j = 1; j < 10; ++j){
			if(!A[j]) continue;
			chmax(dp[i+B[j]],{digit+1,j});
		}
	}

	while(N>0){
		int maxi = dp[N].second;
		cout << maxi;
		N -= B[maxi];
	}
	cout << endl;
	return 0;
}


Measured memory_bytes: 384
#include <stdio.h>


int main(void){
   long long int M= 1000000007;
  long long int n;
  //char a[1000005]="0";
  scanf("%lld", &n);
  long long int ans=0;
  long long int sum = 1;
  long long int hiki1=1;
    long long int hiki2=1;

  //ans = n*(n-1)
  
  for(long long int i=0;i<n;i++){
    sum = (10*sum)%M;
    hiki1= (8*hiki1)%M;
    hiki2=(9*hiki2)%M; 
    //sum%=M;
    //hiki1%=M;
    //hiki2%=M;

    //ans =  sum-((2*hiki2)-hiki1);
  }
  ans = (sum+2*(M-hiki2)+hiki1)%M;
  //ans = (ans+M) %M;
   //ans = ans%1000000007;

  printf("%lld\n", ans);
  
  


  return 0;
}
  

Measured memory_bytes: 1684
#include <bits/stdc++.h>
using namespace std;
#define repd(i,a,b) for (int i=(a);i<(b);i++)
#define rep(i,n) repd(i,0,n)
#define all(x) (x).begin(),(x).end()
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
typedef long long ll;
const long long INF = 1LL << 60;
typedef pair<int, int> P;

vector<ll> divisor(ll n)
{
    vector<ll> res;
    for (ll i = 1; i * i <= n; i++) {
        if (n % i == 0) {
            res.push_back(i);
            if (i != n / i) {
                res.push_back(n / i);
            }
        }
    }

    return res;
}

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

    vector<ll> res = divisor(N);
    ll ans = INF;
    rep(i, res.size()) {
        ll a, b;
        a = res[i];
        b = N / res[i];
        ans = min(ans, (a - 1) + (b - 1));
    }

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

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

int main(){
    int x, n;
    cin >> x >> n;
    int *p = new int[n];
    for (int i = 0; i < n;i++)
    {
        cin >> p[i];
    }

    int sml = INT_MAX;
    int lar = INT_MIN;
    int flag = 0;
    for (int i = 0; i <= n;i++)
    {
        flag = 1;
        for (int j = 0; j < n;j++)
        {
            if(x-i==p[j])
            {
                flag = 0;
                break;
            }
        }
        if(flag==1)
        {
            sml = x - i;
            break;
        }
    }
    for (int i = 0; i <= n;i++)
    {
        flag = 1;
        for (int j = 0; j < n;j++)
        {
            if(x+i==p[j])
            {
                flag = 0;
                break;
            }
        }
        if(flag==1)
        {
            lar = x + i;
            break;
        }
    }
    if((lar-x)<(x-sml))
    {
        cout << lar << endl;
    }else
    {
        cout << sml << endl;
    }
    return 0;
}

Measured memory_bytes: 3568
#include <iostream>
#include <string.h>
using namespace std;

int main()
{
    string str;
    int ans = 0;
    cin >> str;
        if(str == "SSS")
        {
            ans = 0;
        }
          if(str == "RSS")
        {
            ans = 1;
        }
          if(str == "SRS")
        {
            ans = 1;
        }
          if(str == "SSR")
        {
            ans = 1;
        }  if(str == "RRS")
        {
            ans = 2;
        }
          if(str == "RSR")
        {
            ans = 1;
        }
          if(str == "SRR")
        {
            ans = 2;
        }
          if(str == "RRR")
        {
            ans = 3;
        }
    cout << ans << endl;
    return 0;
}

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

int main(){
  string s, p;
  cin >> s >> p;
  string t;
  t = s + s;
  if(t.find(p)!=string::npos) cout << "Yes" <<endl;
  else cout << "No" << endl;
  return 0;
}




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

//int max(int l, int a){
//    return l > a ?  l : a;
//}

using namespace std;
int main(){
   int n, m; cin >> n >> m;
   int l = 1, r = n;
   for(int i = 0; i < m; i++){
       int a, b; cin >> a >> b;
       l = max(l, a);
       r = min(r, b);
   }
   cout << max(r - l + 1, 0) << endl;

    return 0;
}


Measured memory_bytes: 3632