akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i,n) for(int i = 0; i < n; ++i)

int main(){
    int n; cin >> n;
    vector<ll> a(n); rep(i,n) cin >> a[i];
    int judge = 1;
    if(n == 3){ //nが3なら例外
        if(a[0] != (a[1]^a[2])) judge = 0;
    }else if(n % 3 != 0){ //nが3の倍数以外なら全部同じが必要かつ十分
        rep(i,n-1){
            if(a[i] != a[i+1]){
                judge = 0;
                break;
            }
        }
    }else{ //3の倍数なら3を法として等しいところが同じが必要
        map<ll,int> m; //数字の出現回数
        rep(i,n) m[a[i]]++;
        rep(i,n){
            if(m[a[i]] % (n/3) != 0){
                judge = 0;
                break;
            }
        }
        sort(a.begin(),a.end());
        vector<int> b(1); b[0] = a[0];
        rep(i,n-1) if(a[i] != a[i+1]) b.push_back(a[i+1]);
        if(b.size() > 3) judge = 0;
        else{
            if(b.size() == 1 && b[0] != 0) judge = 0; 
            if(b.size() == 2 && b[0] != (b[1]^b[1])) judge = 0;
            if(b.size() == 3 && b[0] != (b[1]^b[2])) judge = 0;
        }
    }


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

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

int main() {
 
  string c;
  cin >> c;
  
  if (c == "a" || c == "e" || c == "i" || c == "o" || c == "u") {
    cout << "vowel" << endl;
  } else {
    cout << "consonant" << endl;
  }

}

Measured memory_bytes: 256
A, B, C, D = map(int, input().split())
E = A - 1
def func(a,b):
    if a%b == 0:
        return b
    return func(b,a%b)

c = min(C,D)
d = max(C,D)
G = func(d,c)
L = (C*D) // G

x = B - ((B//C)+(B//D)-(B//L))
y = E - ((E//C)+(E//D)-(E//L))
print(x-y)


Measured memory_bytes: 3064
#include <iostream>

int main(){
  int N, X;
  std::cin >> N >> X;
  int c = 1, D = 0;
  for(int i = 0; i < N; ++i){
    int L;
    std::cin >> L;
    D += L;
    if(D <= X) c++;
    else break;
  }
  std::cout << c << std::endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define all(c) (c).begin(),(c).end()
#define pb push_back 
#define mp make_pair
typedef long long ll;



int main(){
	double l; cin>>l;	
	
	printf("%.10lf",(l/3)*(l/3)*(l/3));
			
	return 0;
}


Measured memory_bytes: 256
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class Main{

    /**
     * YES
     */
    public static final String JUDGE_YES = "YES";
    /**
     * NO
     */
    public static final String JUDGE_NO = "NO";

    public static void main(String[] args) throws IOException {
	BufferedReader br = new BufferedReader(new InputStreamReader(System.in));

	// roop????????°?????????
	int roop = Integer.parseInt(br.readLine());

	for (int i = 0; i < roop; i++) {
	    // ??\???????????????????´?
	    String[] inputs = br.readLine().split(" ");
	    int[] numbers = new int[10];
	    for (int j = 0; j < 10; j++) {
		numbers[j] = Integer.parseInt(inputs[j]);
	    }

	    String message = pileBalls(numbers);

	    System.out.println(message);
	}
    }

    /**
     * ?????? ????????????B???C??????????????????????????\???????°?????????????????????§???????????????????????????????????°YES????????????
     * 
     * @param numbers
     * @return ?°?????????????????????§???????????????????????????????????????
     */
    private static String pileBalls(int numbers[]) {

	// ????????????????????????????????????
	// ????????´??????0??¨?????????
	int bTubeTop = 0;
	int cTubeTop = 0;

	// ??????????????????????????£?????´?????????NO??¨?????????????????\??????YES??¨?????????
	String message = JUDGE_YES;

	// ??\???????????????????????°???????????§???????????°????????????
	for (int i = 0; i < 10; i++) {
	    int number = numbers[i];

	    if (bTubeTop < number) {
		bTubeTop = number;
	    } else if (cTubeTop < number) {
		cTubeTop = number;
	    } else {
		message = JUDGE_NO;
		break;
	    }
	}
	return message;
    }
}

Measured memory_bytes: 24128
#include <iostream>
#include <map>
#include <set>
#include <cmath>
#include <algorithm>
#include <vector>
#include <string>
#include <fstream>
#include <bitset>
#include <queue>
#include <stack>
#include <deque>
#include <complex>
#include <iomanip>
#include <stdio.h>
#include <string.h>
#include <random>
#include <functional>

using std::cin;
using std::cout;
using std::cerr;
using std::endl;

using std::map;
using std::set;
using std::bitset;
using std::vector;
using std::string;
using std::multimap;
using std::multiset;
using std::deque;
using std::queue;
using std::stack;
using std::pair;
using std::iterator;

using std::sort;
using std::stable_sort;
using std::reverse;
using std::max_element;
using std::min_element;
using std::unique;
using std::ios_base;
using std::swap;
using std::fill;

using std::setprecision;
using std::fixed;

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

ll min(ll a, ll b) {return a < b ? a : b;}
ll min(int a, ll b) {return a < b ? a : b;}
ll min(ll a, int b) {return a < b ? a : b;}
ll min(int a, int b) {return a < b ? a : b;}

ll max(ll a, ll b) {return a > b ? a : b;}
ll max(int a, ll b) {return a > b ? a : b;}
ll max(ll a, int b) {return a > b ? a : b;}
ll max(int a, int b) {return a > b ? a : b;}

namespace MySpace{

};

#define F(i, n) for (int (i) = 0; (i) != (n); (i)++)
#define fi first
#define se second
#define re return
#define all(x) (x).begin(), (x).end()

const long long INF = 1e18;

long long inq(long long a, long long b)
{
    if (b == 0) return 1;
    long long l = inq(a, b / 2);
    if (b % 2)
    {
        long long k = l;
        if (k > INF / l) return INF;
        k = l * l;
        if (k > INF / a) return INF;
        return k * a;
    }
    long long k = l;
    if (k > INF / l) return INF;
    return l * l;
}

long long n, a;
long long ans;

signed main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    cin >> n >> a;
    ans = n;
    for (long long c = 0; c <= 50; c++)
    {
        long long res = c * a;
        long long l = 1, r = n;
        while (l + 1 < r)
        {
            long long m = (l + r) / 2;
            if (inq(m, c + 1) >= n) r = m;
            else l = m;
        }
        long long summ = (c + 1) * r;
        long long p = inq(r, c + 1);
        for (int i = 0; i < c + 1; i++)
        {
            if (p >= n) ans = min(ans, summ + res);
            p = p / r * (r - 1);
            summ--;
            if (p >= n) ans = min(ans, summ + res);
        }
    }
    cout << ans;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define MxV (1<<30)
long long int N, K, p;
int main(){
	cin >> N >> K;
	long long int arr[N];
	long long int mem[N];
	for (int i = 0; i < N; i++)
		cin >> arr[i];
	mem[0] = 0;
	mem[1] = abs(arr[0] - arr[1]);
	for (int i = 2; i < N; i++){
		p = MxV;
		for (int j = 1; j <= i && j <= K; j++)
			p = min(p, abs(arr[i] - arr[i - j]) + mem[i - j]);
		mem[i] = p;
	}
	cout << mem[N-1];
}


Measured memory_bytes: 5160
n = int(input())
a = list(map(int, input().split()))
check = 0
for i in range(n):
    if a[i]%2 == 0 and a[i]%3 != 0 and a[i]%5 != 0:
        check += 1

print('APPROVED' if check==0 else 'DENIED')

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

using namespace std;

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

#define X first
#define Y second

//#include <boost/unordered_map.hpp>
//using namespace boost;

/*
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> rbtree;
rbtree T;
*/

namespace io{
	const int L = (1 << 20) + 1;
	
	char buf[L], *S , *T, c;
	 
	char getchar() {
		if(S == T) {
			T = (S = buf) + fread(buf, 1, L, stdin);
			return (S == T ? EOF : *S++);
		}
		return *S++;
	}
	
	int inp() {
		int x = 0, f = 1; char ch;
		for(ch = getchar(); !isdigit(ch); ch = getchar())
			if(ch == '-') f = -1;
		for(; isdigit(ch); x = x * 10 + ch - '0', ch = getchar());
		return x * f;
	}
	
	ll inp_ll() {
		ll x = 0; int f = 1; char ch;
		for(ch = getchar(); !isdigit(ch); ch = getchar())
			if(ch == '-') f = -1;
		for(; isdigit(ch); x = x * 10 + ch - '0', ch = getchar());
		return x * f;
	}
	
	char B[25], *outs=B+20, *outr=B+20;
	template<class T>
	inline void print(register T a,register char x=0){
		if(x) *--outs = x, x = 0;
		
		if(!a)*--outs = '0';
		else 
			while(a)
				*--outs = (a % 10) + 48, a /= 10;
		
		if(x)
			*--outs = x;
		
		fwrite(outs, outr - outs , 1, stdout);
		outs = outr;
	}
};

using io :: print;
using io :: inp;
using io :: inp_ll;

const int MAXN = 200010;

int n;
int a[MAXN];

int main()
{
	
	scanf("%d", &n);
	for (int i = 1; i <= n; ++ i)
	{
		scanf("%d", &a[i]);
		a[i] -= i;
	}
	sort(a+1, a+n+1);
	int x = a[(n+1)/2];
	ll ans = 0;
	for (int i = 1; i <= n; ++ i)
		ans += abs(x-a[i]);
	cout << ans << endl;
	
	return 0;
}


Measured memory_bytes: 1024
#include <iostream>
#include <vector>
#include <string>
using namespace std;
int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    int H,W;
    cin >> H >> W;
    vector<string> S(H);
    for(int i = 0;i < H; ++i){
        cin >> S[i];
    }
    for(int i = 0; i < H; ++i){
        cout << S[i] << endl;
        cout << S[i] << endl;
    }
    return 0;
}

Measured memory_bytes: 3624
#include<cstdio>
#include<algorithm>
#include<cstring>
#include<queue>
using namespace std;
#define ll long long
ll n,m,i,j,k,a,b,c,cc[500000][2],gg[500000],ans[500000],ct[500000];
char s[300000];
queue<char>q;
int find(int x){
	return gg[x]==x?x:gg[x]=find(gg[x]);
}
int main(){
	scanf("%lld%lld",&n,&m);
	k=((n-1)*(n-1)+n-1)/2;
	for (int i=0;i<m;i++) scanf("%lld%lld",&cc[i][0],&cc[i][1]);
	for (int i=1;i<=n;i++) gg[i]=i;
	for (int i=1;i<=n;i++) ct[i]=1;
	for (int i=m-1;i>=0;i--){
		a=cc[i][0];
		b=cc[i][1];
		ans[i]=k;
		if (find(gg[a])!=find(gg[b])){
			k-=ct[find(gg[a])]*ct[find(gg[b])];
			ct[find(gg[b])]+=ct[find(gg[a])];
			gg[find(gg[a])]=find(gg[b]);
		}
	}
	for (int i=0;i<m;i++) printf("%lld\n",ans[i]);
	return 0;
}

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

int n;
int x[24],y[24],r[24],c[24];
bool memo[1<<24];
char bit_count[1<<24];

bool ok(int a,int bit){
    for(int i=0;i<a;i++){
        if(((bit>>i)&1)==0)continue;
        int dist=(x[i]-x[a])*(x[i]-x[a])+(y[i]-y[a])*(y[i]-y[a]);
        int sum=(r[i]+r[a])*(r[i]+r[a]);
        if(dist<sum)return false;
    }
    return true;
}

int dfs(int bit){
    memo[bit]=true;

    int ret=n;
    for(int i=0;i<n;i++)if((bit>>i)&1)ret--;

    for(int i=0;i<n;i++){
        for(int j=i+1;j<n;j++){
            if(((bit>>i)&1)==0)continue;
            if(((bit>>j)&1)==0)continue;
            int to_bit=(bit^(1<<i))^(1<<j);
            if(c[i]==c[j]&&ok(i,bit)&&ok(j,bit)&&!memo[to_bit]){
                ret=max(ret,dfs(to_bit));
            }
        }
    }


    return ret;
}

void solve(){
    fill_n(memo,1<<n,false);

    cout<<dfs((1<<n)-1)<<endl;
}

bool input(){
    cin>>n;
    if(!n)return false;
    for(int i=0;i<n;i++)cin>>x[i]>>y[i]>>r[i]>>c[i];
    return true;
}

void init(){
    for(int i=0;i<(1<<24);i++){
        for(int j=0;j<24;j++)if((i>>j)&1){
            bit_count[i]++;
        }
    }
}

int main(){
    init();
    while(input())solve();
    return 0;
}

Measured memory_bytes: 33928
#include <bits/stdc++.h>
#define REP(i, n) for (int i = 0; i < (int)(n); i++)
using namespace std;
template<class T>inline bool chmax(T &a, const T &b){if(a < b){a = b; return 1;}return 0;}
template<class T>inline bool chmin(T &a, const T &b){if(a > b){a = b; return 1;}return 0;}
typedef long long ll;
int main(){
  ios::sync_with_stdio(false);
  cin.tie(0);
  ll N, C; cin >> N >> C;
  vector<ll> x(N, 0);
  vector<ll> v(N, 0);
  vector<ll> A(N+1, 0); vector<ll> AA(N+1, 0);
  vector<ll> B(N+1, 0); vector<ll> BB(N+1, 0);
  REP(i, N){
    cin >> x[i] >> v[i];
  }
  ll a = 0, b = 0;
  REP(i, N){
    a += v[i];
    b += v[N-1-i];
    A[i+1] = max(A[i], a - x[i]);
    B[i+1] = max(B[i], b - (C - x[N-1-i]));
    AA[i+1] = max(AA[i], a - x[i]*2);
    BB[i+1] = max(BB[i], b - (C - x[N-1-i])*2);
  }
  ll ans = 0;
  REP(i, N+1){
    ans = max({ans, B[i] + AA[N-i], BB[i] + A[N-i]});
  }
  cout << ans << endl;
}

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

#define ll long long
#define p_b push_back
#define pl pair<ll,ll>

ll modo = 1000000007;
ll MOD = modo;

int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	ll t;
	t = 1;
	//cin >> t;
	while(t--)
	{
		ll h,w,k;
		cin >> h >> w >> k;
		string s[h];
		ll i,j;
		ll first = -1;
		for(i=0;i<h;i++)
		{
			cin >> s[i];
			if(first!= -1)
			{
				continue;
			}
			for(j=0;j<w;j++)
			{
				if(s[i][j]=='#')
				{
					first = i;
					break;
				}
			}
		}

		ll arr[h][w];
		ll cur = 0;
		

		for(i=first;i<h;i++)
		{
			ll count = 0;
			for(j=0;j<w;j++)
			{
				if(s[i][j] == '#')
				{
					count = 1;
					break;
				}
			}
			if(!count)
			{
				for(j=0;j<w;j++)
				{
					arr[i][j] = arr[i-1][j];
				}

			}
			else
			{
				ll flag = 0;
				for(j=0;j<w;j++)
				{
					if(s[i][j] == '#')
					{
						cur++;
						flag = 1;

					}
					if(flag)
					{
						arr[i][j] = cur;
					}
					else
						arr[i][j] = cur+1;

					// << i << " " << j << " " << arr[i][j] << endl;


				}
			}
		}
		for(i=first-1;i>=0;i--)
		{

			for(j=0;j<w;j++)
			{
				arr[i][j] = arr[i+1][j] ;

			}
		}
		for(i=0;i<h;i++)
		{
			for(j=0;j<w;j++)
			{
				cout << arr[i][j] << " ";
			}
			cout << endl;
		}



	}	
	
	return 0;

}

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

int n,m;
char g[1005][1005];
int mod = 1e9+7;
int dp[1005][1005];

int main() {
	scanf("%d%d",&n,&m);
	for (int i=0; i<n; i++) {
		scanf("%s",g[i]);
	}
	dp[0][0] = 1;
	for (int i=0; i<n; i++) {
		for (int j=0; j<m; j++) {
			if (i+j == 0) continue;
			dp[i][j] = 0;
			if (g[i][j] == '#') continue;
			if (i > 0) dp[i][j] += dp[i-1][j];
			if (j > 0) dp[i][j] += dp[i][j-1];
			dp[i][j] %= mod;
		}
	}
	printf("%d\n",dp[n-1][m-1]);
	return 0;
}


Measured memory_bytes: 5120
#include <bits/stdc++.h>
using namespace std;
#define REP(i,m,n) for(int i=(int)(m) ; i < (int) (n) ; ++i )
#define rep(i,n) REP(i,0,n)
#define pll pair<ll,ll>
#define pint pll
using ll = long long;
const int inf=1e9+7;
const ll longinf=1LL<<60 ;
const ll mod=1e9+7 ;

int main(){
  ll m,k;
  cin >> m >> k;
  ll x=1;
  rep(i,m)x*=2;  
  if(m==0 || m==1){
    if(m==0 && k==0){
      cout << 0 << ' ' << 0 << endl;
    }
    else if(m==1 && k==0){
      cout << 0 << ' ' << 0 << ' ' << 1 << ' ' << 1 << endl;
    }else{
      cout << -1 << endl;
    }
    return 0;
  }
  if(k>=x){
    cout << -1 << endl;
    return 0;
  }
  for(ll i=x-1;i>=0;i--){
    if(i!=k)cout << i << ' ';
  }
  cout << k << ' ';
  for(ll i=0;i<x;i++){
    if(i!=k)cout << i << ' ';
  }
  cout << k << endl;
return 0;}

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

void solve(int n)
{
    int ans = 0;
        for (int a = 0; a * a <= n; a++)
        {
            for (int b = a; b * b <= n; b++)
            {
                for (int c = b; c * c <= n; c++)
                {
                    for (int d = c; d * d <= n; d++)
                    {
                        if (a * a + b * b + c * c + d * d == n)
                        {
                            ans++;
                        }
                    }
                }
            }
        }
    cout << ans << endl;
}

int main()
{
    int n;
    while (cin >> n, n)
    {
        solve(n);
    }
    return 0;
}


Measured memory_bytes: 3000
#include <iostream>
#define M 1000000007
using namespace std;
int main() {
    int n; cin >> n;
    string s; cin >> s;
    long long dp[n][2] = {};
    int cur = 0, prev = 1;
    for (int i = 0; i < n; i++) dp[i][prev] = 1;
    for (int i = 1; i < n; i++) {
        if (s[i-1] == '<') {
            dp[0][cur] = dp[0][prev];
            for (int j = 1; j < n-i; j++) dp[j][cur] = (dp[j-1][cur] + dp[j][prev]) % M;
        } else {
            dp[n-i-1][cur] = dp[n-i][prev];
            for (int j = n-i-2; j >= 0; j--) dp[j][cur] = (dp[j+1][cur] + dp[j+1][prev]) % M;
        }
        swap(cur, prev);
    }
    cout << dp[0][prev] << endl;
}


Measured memory_bytes: 256
N, K = map(int, input().split())
x = list(map(int, input().split()))

import bisect

idx_r = bisect.bisect_left(x, 0)

if idx_r < N and x[idx_r] == 0:
    idx_l = idx_r
else:
    idx_l = idx_r - 1

ans = 1000000007
    
# right
if 0 <= idx_r + K - 1 < N:
    ans_tmp = x[idx_r + K - 1]
    ans = min(ans, ans_tmp)

# left
if 0 <= idx_l - K + 1 < N:
    ans_tmp = -x[idx_l - K + 1]
    ans = min(ans, ans_tmp)

# right -> left
for i in range(N):
    if 0 <= idx_r - K + 1 + i < idx_r + i < N:
        ans_tmp = 2 * x[idx_r + i] - x[idx_r - K + 1 + i]
        ans = min(ans, ans_tmp)

# left -> right
for i in range(N):
    if 0 <= idx_l - i < idx_l + K - 1 - i < N:
        ans_tmp = x[idx_l + K - 1 - i] - 2 * x[idx_l - i]
        ans = min(ans, ans_tmp)

print(ans)

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

int width,height;
int map[50][50];
char input_map[50][51];

int main(void) {
	int i,j,k;
	int black,white;
	while(1) {
		scanf("%d%d",&width,&height);
		if(width==0 && height==0)break;
		memset(map,0,sizeof(map));
		for(i=0;i<height;i++) {
			scanf("%s",input_map[i]);
			for(j=0;j<width;j++) {
				if(input_map[i][j]=='B')map[i][j]=5;
				else if(input_map[i][j]=='W')map[i][j]=6;
			}
		}
		for(k=0;k<width*height;k++) {
			for(i=0;i<height;i++) {
				for(j=0;j<width;j++) {
					if((map[i][j] & 4)==0) {
						if(i>0)map[i][j]|=map[i-1][j]&3;
						if(j>0)map[i][j]|=map[i][j-1]&3;
						if(i<height-1)map[i][j]|=map[i+1][j]&3;
						if(j<width-1)map[i][j]|=map[i][j+1]&3;
					}
				}
			}
		}
		black=white=0;
		for(i=0;i<height;i++) {
			for(j=0;j<width;j++) {
				if(map[i][j]==1)black++;
				else if(map[i][j]==2)white++;
			}
		}
		printf("%d %d\n",black,white);
	}
	return 0;
}

Measured memory_bytes: 436
void main()
{
    long n, c;
    ipElems(n, c);
    Sushi[] sushi = n.rdCol!Sushi;

    long[] l = new long[n+1];
    long[] lrev = new long[n+1], lrevmax = new long[n+1];
    long pos;
    foreach (i, s; sushi)
    {
        l[i+1] = l[i] + s.v - s.x + pos;
        lrev[i+1] = l[i+1] - s.x;
        lrevmax[i+1] = max(lrevmax[i], lrev[i+1]);
        pos = s.x;
    }

    long[] r = new long[n+1];
    long[] rrev = new long[n+1], rrevmax = new long[n+1];
    pos = c;
    foreach_reverse (i, s; sushi)
    {
        r[i] = r[i+1] + s.v - pos + s.x;
        rrev[i] = r[i] - c + s.x;
        rrevmax[i] = max(rrevmax[i+1], rrev[i]);
        pos = s.x;
    }

    long result;
    foreach (i; 0 .. n+1)
    {
        result = max(result, l[i]+rrevmax[i], lrevmax[i]+r[i]);
    }

    result.writeln;
}

struct Sushi
{
    long x, v;
}

enum long mod = 10^^9 + 7;
enum long inf = 1L << 60;

T rdElem(T = long)()
if (!is(T == struct))
{
    return readln.chomp.to!T;
}

alias rdStr = rdElem!string;
alias rdDchar = rdElem!(dchar[]);

T rdElem(T)()
if (is(T == struct))
{
    T result;
    string[] input = rdRow!string;
    assert(T.tupleof.length == input.length);
    foreach (i, ref x; result.tupleof)
    {
        x = input[i].to!(typeof(x));
    }
    return result;
}

T[] rdRow(T = long)()
{
    return readln.split.to!(T[]);
}

T[] rdCol(T = long)(long col)
{
    return iota(col).map!(x => rdElem!T).array;
}

T[][] rdMat(T = long)(long col)
{
    return iota(col).map!(x => rdRow!T).array;
}

void ipElems(T...)(ref T data)
{
    string[] input = rdRow!string;
    assert(data.length == input.length);
    foreach (i, ref x; data)
    {
        x = input[i].to!(typeof(x));
    }
}

void wrMat(T = long)(T[][] mat)
{
    foreach (row; mat)
    {
        foreach (j, compo; row)
        {
            compo.write;
            if (j == row.length - 1) writeln;
            else " ".write;
        }
    }
}

import std.stdio;
import std.string;
import std.array;
import std.conv;
import std.algorithm;
import std.range;
import std.math;
import std.numeric;
import std.traits;
import std.container;
import std.functional;
import std.typecons;
import std.ascii;
import std.uni;

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

#include <boost/multiprecision/cpp_int.hpp>

#define rep(i, n) for (int i = 0; i < (n); i++)
using namespace std;
using namespace boost::multiprecision;
typedef long long ll;
const int MOD = 1e9 + 7;

int main() {
  ll n;
  cpp_int ans = 0;
  cin >> n;
  vector<cpp_int> a(n), s(n + 1, 0);
  rep(i, n) cin >> a[i];
  rep(i, n) s[i + 1] = s[i] + a[i];
  rep(i, n - 1) {
    cpp_int t = a[i] * (s[n] - s[i + 1]);
    ans = ans + t;
  }
  ans = ans % MOD;

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

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

int main() {
	ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
	int ans = 0;
	for (int i=1; i<=5; i++) {
		int x;
		cin >> x;
		if (x == 0) ans = i;
	}
	cout << ans << '\n';
}

Measured memory_bytes: 3544
/*   ꧁༒☬महाकाल☬༒꧂ ꧁༒ঔमहाकालঔ༒꧂
                   
                   ঔৣ۝महाकालᴳᵒᵈ۝ঔৣ            
 
 */ 
#include<bits/stdc++.h>
using namespace std;
//#include <ext/pb_ds/assoc_container.hpp>
//#include <ext/pb_ds/tree_policy.hpp>
//using namespace __gnu_pbds;
//template <typename T, typename cmp=less<T>> using oset =tree<T, null_type, cmp, rb_tree_tag, tree_order_statistics_node_update>;
#define ll long long 
#define mod 1000000007
#define inf 100000000000000000
#define fast ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define _it iterator
#define all(_x) _x.begin(),_x.end()
#define f first
#define s second
#define pb push_back
void mahakal(){
	#ifndef ONLINE_JUDGE
	freopen("input.txt","r",stdin);
	freopen("output.txt","w",stdout);
	freopen("error.txt","w",stderr);
	#endif
}
int main(){
	//mahakal(),fast;
	ll n ;
	cin>> n ;
	ll A[n],B[n],C[n];
	for(ll i=1;i<=n ;i++)cin>>A[i];
	for(ll i=1;i<=n ;i++)cin>>B[i];
	for(ll i=1;i<n;i++)cin>>C[i];
	ll prev=-1;
	ll ans = 0 ;
	for(ll i=1;i<=n ;i++){
		if(prev+1==A[i]){
			ans+=B[i]+C[prev];
		}
		else{
			ans+=B[i];
		}
		prev=A[i];
	}
	cout<<ans<<endl;

	return 0;
}

Measured memory_bytes: 256
N, S = map(int, input().split())
mod = 998244353
A = list(map(int, input().split()))
dp = [[0]*(S+1) for _ in range(N+1)]
for i in range(N+1):
    dp[i][0] = i+1
r = 0

for i in range(1, N+1):
    a = A[i-1]
    for j in range(1, S+1):
        dp[i][j] = dp[i-1][j]
        if j-a >= 0:
            dp[i][j] += dp[i-1][j-a]
        dp[i][j] %= mod
    r += dp[i][S]
print(r%mod)


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

#ifdef LOCAL
#define eprintf(...) fprintf(stderr, __VA_ARGS__)
#else
#define NDEBUG
#define eprintf(...) do {} while (0)
#endif
#include<cassert>

using namespace std;

typedef long long LL;
typedef vector<int> VI;

#define REP(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define EACH(i,c) for(__typeof((c).begin()) i=(c).begin(),i##_end=(c).end();i!=i##_end;++i)

template<class T> inline void amin(T &x, const T &y) { if (y<x) x=y; }
template<class T> inline void amax(T &x, const T &y) { if (x<y) x=y; }
template<class Iter> void rprintf(const char *fmt, Iter begin, Iter end) {
    for (bool sp=0; begin!=end; ++begin) { if (sp) putchar(' '); else sp = true; printf(fmt, *begin); }
    putchar('\n');
}

LL T1, T2;
LL A1, A2;
LL B1, B2;

LL a1;
LL a2;
LL b1;
LL b2;

bool ok(LL mid) {
    return (a1+a2)*mid+a1 <= (b1+b2)*mid+b1;
}

void MAIN() {
    scanf("%lld%lld%lld%lld%lld%lld", &T1, &T2, &A1, &A2, &B1, &B2);

    if (A1 > B1) {
	swap(A1, B1);
	swap(A2, B2);
    }

    a1 = T1 * A1;
    a2 = T2 * A2;
    b1 = T1 * B1;
    b2 = T2 * B2;

    if (a1 + a2 == b1 + b2) {
	puts("infinity");
    } else if (a1 < b1 && a1+a2 < b1+b2) {
	puts("0");
    } else {
	LL lo = 0, hi = 1;
	while (ok(hi)) {
	    lo = hi;
	    hi += hi;
	}
	while (hi-lo>1) {
	    LL mid = (lo+hi)/2;
	    (ok(mid)? lo: hi) = mid;
	}

	LL ans = lo*2;
	if ((a1+a2)*lo+a1 < (b1+b2)*lo+b1) ans++;
	printf("%lld\n", ans);
    }
}

int main() {
    int TC = 1;
//    scanf("%d", &TC);
    REP (tc, TC) MAIN();
    return 0;
}



Measured memory_bytes: 256
m, d = map(int, input().split())
c = 0
for i in range(m):
    for j in range(max(0, d - 9)):
        dl = list(map(int, list(str(j + 10))))
        if dl[0] >= 2 and dl[1] >= 2 and dl[0] * dl[1] == i + 1:
            c += 1
print(c)

Measured memory_bytes: 3060
// #include {{{
#include <iostream>
#include <cassert>
#include <cstring>
#include <cstdlib>
#include <cstdio>
#include <cctype>
#include <cmath>
#include <ctime>
#include <queue>
#include <set>
#include <map>
#include <stack>
#include <string>
#include <bitset>
#include <vector>
#include <complex>
#include <algorithm>
using namespace std;
// }}}
// #define {{{
typedef long long ll;
typedef double db;
typedef pair<int,int> pii;
typedef vector<int> vi;
#define de(x) cout << #x << "=" << x << endl
#define rep(i,a,b) for(int i=a;i<(b);++i)
#define per(i,a,b) for(int i=(b)-1;i>=(a);--i)
#define all(x) (x).begin(),(x).end()
#define sz(x) (int)(x).size()
#define mp make_pair
#define pb push_back
#define fi first
#define se second
// }}}

const int N = 5050 , P = 1e9 + 7;
inline void pp(int &x,int d) {if((x+=d)>=P)x-=P;}
int n , fac[N] , ifac[N];
vi g[N];
int sz[N] , mx[N];

int comb(int a,int b) {return ll(fac[a]) * ifac[b] % P * ifac[a-b] % P;}

void dfs(int c,int fa) {
  sz[c] = 1;
  mx[c] = 0;
  for(auto t : g[c]) if(t != fa) {
    dfs(t , c);
    mx[c] = max(mx[c] , sz[t]);
    sz[c] += sz[t];
  }
  mx[c] = max(mx[c] , n - sz[c]);
}

int main(){
  rep(i,0,N) fac[i] = i ? ll(fac[i-1]) * i % P : 1;
  rep(i,0,N) ifac[i] = i > 1 ? P - ll(P/i)*ifac[P%i]%P : 1;
  rep(i,1,N) ifac[i] = ll(ifac[i-1]) * ifac[i] % P;
  cin >> n;
  rep(i,1,n) {
    int x,y;
    cin >> x >> y;
    g[x].pb(y);
    g[y].pb(x);
  }
  dfs(1 , 0);
  vi centroid;
  rep(i,1,n+1) if(mx[i] <= n / 2)
    centroid.pb(i);
  if(sz(centroid) == 2) {
    cout << ll(fac[n / 2]) * fac[n / 2] % P << endl;
  } else {
    int rt = centroid[0];
    dfs(rt , 0);
    vi v , f(n , 0);
    f[0] = 1;
    for(auto t : g[rt]) {
      int sz = ::sz[t];
      vi g(n , 0);
      rep(i,0,n) if(f[i]) {
        rep(j,0,sz+1) {
          pp(g[i + j] , ll(f[i]) * comb(sz , j) % P * comb(sz , j) % P * fac[j] % P);
        }
      }
      swap(f , g);
    }
    int ans = 0;
    rep(i,0,n) {
      int cof = ll(f[i]) * fac[n - i] % P;
      if(i & 1) pp(ans , P - cof);
      else pp(ans , cof);
    }
    cout << ans << endl;
  }
  return 0;
}


Measured memory_bytes: 896
s = input()
if len(s)%2 == 1:
  print("No")
  exit()
  
for i in range(len(s)):
  if i%2 == 0:
    if s[i] != "h":
      print("No")
      exit()
  else:
    if s[i] != "i":
      print("No")
      exit()
print("Yes")

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

using namespace std;

int main(){
    long N, A, B;
    cin >> N >> A >> B;
    long ans = 0;
    if(A + B == 0 || A == 0) {
        cout << 0 << endl;
        return 0;
    }
    ans = A * (N / (A + B)) + min(A, N - (N / (A + B)) * (A + B));
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll MA=4294967295;

int main(){
	int x,y,z;
	cin>>x>>y>>z;
	int ans=min(x+y,x+z);
	ans=min(ans,y+z);
	cout<<ans;	
	return 0;
}

Measured memory_bytes: 256
from itertools import accumulate

N, M, K = map(int, input().split())
*A, = map(int, input().split())
*B, = map(int, input().split())
cumsum_A, cumsum_B = [0] + list(accumulate(A)), [0] + list(accumulate(B))
ans = 0
j = M
for i in range(N+1):
    if cumsum_A[i] > K: break
    while cumsum_A[i] + cumsum_B[j] > K: j -= 1
    ans = max(ans, i + j)
print(ans)

Measured memory_bytes: 50656
#include "bits/stdc++.h"
using namespace std;
#define FOR(i,j,k) for(int (i)=(j);(i)<(int)(k);++(i))
#define rep(i,j) FOR(i,0,j)
#define each(x,y) for(auto &(x):(y))
#define mp make_pair
#define mt make_tuple
#define all(x) (x).begin(),(x).end()
#define debug(x) cout<<#x<<": "<<(x)<<endl
#define smax(x,y) (x)=max((x),(y))
#define smin(x,y) (x)=min((x),(y))
#define MEM(x,y) memset((x),(y),sizeof (x))
#define sz(x) (int)(x).size()
#define pb push_back
typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<ll> vll;

bool f(int a, int b) {
    cout << "? " << a << ' ' << b << endl;
    string res;
    cin >> res;
    return res[0] == 'Y';
}

int main(){
    int A, B, N;
    cin >> A >> B;
    if (B >= A) {
        cout << "Impossible" << endl;
        return 0;
    }

    N = A + B;
    vi path;
    rep(i, N) {
        if (sz(path) == 0) {
            path.push_back(i);
        }
        else {
            if (f(i, path.back())) {
                path.push_back(i);
            }
            else {
                path.pop_back();
            }
        }
    }

    vi ans(N);
    int a = path[0];
    ans[a] = 1;
    rep(i, N)ans[i] = f(a, i);
    cout << "! ";
    rep(i, N) {
        cout << ans[i];
    }
    cout << endl;
}


Measured memory_bytes: 848
class SegmentTree():
    def __init__(self, array, f, ti):
        """
        Parameters
        ----------
        array : list
            to construct segment tree from
        f : func
            binary operation of the monoid
        ti : 
            identity element of the monoid
        """
        self.f = f
        self.ti = ti
        self.n = n = 2**(len(array).bit_length())
        self.dat = dat = [ti] * n + array + [ti] * (n - len(array))
        for i in range(n - 1, 0, -1):  # build
            dat[i] = f(dat[i << 1], dat[i << 1 | 1])

    def update(self, p, v):  # set value at position p (0-indexed)
        f, n, dat = self.f, self.n, self.dat
        p += n
        dat[p] = v
        while p > 1:
            p >>= 1
            dat[p] = f(dat[p << 1], dat[p << 1 | 1])

    def query(self, l, r):  # result on interval [l, r) (0-indexed)
        f, ti, n, dat = self.f, self.ti, self.n, self.dat
        res = ti
        l += n
        r += n
        while l < r:
            if l & 1:
                res = f(res, dat[l])
                l += 1
            if r & 1:
                r -= 1
                res = f(dat[r], res)
            l >>= 1
            r >>= 1
        return res


N, M = [int(_) for _ in input().split()]
S = [i if v == '0' else 10**5 + 5 for i, v in enumerate(input())]
ST = SegmentTree(S, min, 10**5 + 5)
i = N
ans = [i]
while i:
    i2 = ST.query(max(0, i - M), i)
    if i2 == 10**5 + 5:
        print(-1)
        exit()
    i = i2
    ans += [i]
ans = ans[::-1]
print(' '.join(str(b - a) for a, b in zip(ans, ans[1:])))


Measured memory_bytes: 62376
#include<cstdio>
#define RI register int
#define CI const int&
using namespace std;
const int N=1<<18,mod=1e9+7;
int h,n,p[N],tag[N],ans,stk[N],top;
inline void travel2(CI x,int prod,CI opt)
{
	if (x==1) return; prod=1LL*prod*x%mod;
	if (opt) (tag[x]+=prod)%=mod; else (ans+=1LL*(x>>1)*tag[x^1]%mod*prod%mod)%=mod;
	travel2(x>>1,prod,opt);
}
inline void travel1(CI x,int prod,CI opt)
{
	prod=1LL*prod*x%mod;
	if (x>=n) return stk[++top]=n+p[x-n]-1,travel2(n+p[x-n]-1,prod,opt);
	travel1(x<<1,prod,opt); travel1(x<<1|1,prod,opt);
}
int main()
{
	RI i; for (scanf("%d",&h),n=1<<h-1,i=0;i<n;++i)
	scanf("%d",&p[i]); for (i=1;i<n;++i)
	{
		travel1(i<<1,i,1); travel1(i<<1|1,1,0);
		while (top) for (int x=stk[top--];x;x>>=1) tag[x]=0;
	}
	return printf("%d",ans),0;
}

Measured memory_bytes: 3808
#include <iostream>
#include <cstdio>
#include <vector>
#include <algorithm>
using namespace std;
int N;
int a[2][101];
int ma=0;
int main(){
  cin >> N;
  for(int i=0;i<2;i++)
    for(int j=0;j<N;j++)cin >> a[i][j];
  
  for(int i=0;i<N;i++){
    int x=0,y=0;
    int ans=0;
    while(1){
     
      ans+=a[y][x];
      if(x==i){y++;ans+=a[y][x];}
      x++;
      if(x>N-1)break;
      
    }
   
    ma=max(ans,ma);
  }
  cout << ma << endl;
  return 0;
}


Measured memory_bytes: 256
package main

import "fmt"

type island struct {
	name int
	pass []int
	path int
	times int
}

func main(){
	var n,m,a,b int
	fmt.Scan(&n,&m)
	dou := make([]island,n+1)
	for i:=1 ; i<=n ; i++ {
		dou[i].name = i
		dou[i].path = -1
	}
	for i:=1 ; i<=m ; i++ {
		fmt.Scan(&a,&b)
		dou[a].pass = append(dou[a].pass,b)
		dou[b].pass = append(dou[b].pass,a)
	}
//fmt.Println(dou)
	dou[1].path = 0
	dou[1].times = 0
	//prev := 0
	var stack []int
	stack = append(stack,1)
	for ;len(stack) > 0; {
		x := stack[0]
		stack = stack[1:]
		for i:=0 ; i<len(dou[x].pass) ; i++ {
			if dou[dou[x].pass[i]].path == -1 {
				dou[dou[x].pass[i]].path = x
				dou[dou[x].pass[i]].times = dou[x].times + 1
				stack = append(stack,dou[x].pass[i])
			} else if dou[dou[x].pass[i]].times > dou[x].times + 1 {
				dou[dou[x].pass[i]].path = x
				dou[dou[x].pass[i]].times = dou[x].times + 1
				stack = append(stack,dou[x].pass[i])
			}
		}
	}
//fmt.Println(dou)
/*	flag := true
	for i:=2 ; i<=n ; i++ {
		if dou[i].times != dou[dou[i].path].times + 1{
			flag = false
			break
		}
	}
	if flag {*/
		fmt.Println("Yes")
		for i:=2 ; i<=n ; i++ {
			fmt.Println(dou[i].path)
		}
	/*} else {
		fmt.Println("No")
	}*/
}


Measured memory_bytes: 21456
#include <iostream>
#include <string>
#include <array>
#include <vector>
#include <list>
#include <deque>
#include <set>
#include <map>
#include <math.h>
#include <algorithm>

using namespace std;

int main() {

	int n;
	string s;
	int k;
	int a;

	cin >> n >> k >> s;

	if (s[k - 1] == 'A') s[k - 1] = 'a';
	if (s[k - 1] == 'B') s[k - 1] = 'b';
	if (s[k - 1] == 'C') s[k - 1] = 'c';

	cout << s << endl;
	return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define ll long long
#define N 100005
#define oo 1000000000
#define For(i,x,y) for(int i=x;i<=y;i++)
#define Rep(i,x,y) for(int i=x;i>=y;i--)
#define Forn(i,x,y) for(int i=x;i<y;i++)
using namespace std;
inline int read(){
	int x=0,f=0;char ch=getchar();
	for(;ch<'0'||ch>'9';ch=getchar()) if(ch=='-') f=1;
	for(;ch>='0'&&ch<='9';ch=getchar()) x=(x<<1)+(x<<3)+ch-48;
	return f?-x:x;
}
inline void write(ll x){
	if(x<10) putchar(x+48);
	else write(x/10),putchar(x%10+48);
}
inline void writeln(ll x){
	if(x<0) x=-x,putchar('-');
	write(x);putchar('\n');
}
int n,a[N],b[N],c[N];
ll ans;
int main(){
	n=read();
	For(i,1,n) a[i]=read();
	For(i,1,n) b[i]=read();
	For(i,1,n) c[i]=read();
	sort(a+1,a+1+n);
	sort(b+1,b+1+n);
	sort(c+1,c+1+n);
	For(i,1,n){
		if(b[i]<=a[1]) continue;
		if(b[i]>=c[n]) continue;
		int x=lower_bound(a+1,a+1+n,b[i])-a-1;
		int y=upper_bound(c+1,c+1+n,b[i])-c-1;
		y=n-y;
		ans+=1ll*x*y;
	}
	writeln(ans);
	return 0;
}

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

int main () { 
  string S, hint;
  cin >> S >> hint;
  bool S_include = false;
  for (int i = 0; i < S.size() - hint.size() + 1; i++) {
    string sub = S.substr(i, hint.size()); 
    if (sub == hint) {
      S_include = true;    
    } 
  }
  vector<int> include_itr;
  for (int i = 0; i < S.size(); i++) {
    if (S_include) {
      break;  
    }
    int j = S.size() - 1 - i;
    if (i + 1 >= hint.size()) {
      // jからS.size() - 1まででhintを埋められるかチェックする
      for (int l = 0; l < hint.size(); l++) {
        if (S[j + l] != hint[l] && S[j + l] != '?') {  
          break;
        }    
        if (l == hint.size() - 1) {
          include_itr.push_back(j);    
        }
      }      
    } 
  }
  if (!S_include && include_itr.size() == 0) {
    cout << "UNRESTORABLE" << endl;  
  }
  else {
    if (include_itr.size() >= 1) {
      string min_S = "zzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzz";
      int ans = -1;
      for (int j = 0; j < include_itr.size(); j++) {
        string all_S = S;
        for (int i = 0; i < hint.size(); i++) {
          all_S[include_itr[j] + i] = hint[i];     
        }    
        for (int i = 0; i < S.size(); i++) {
          if (all_S[i] == '?') {
            all_S[i] = 'a';  
          }  
        }
        if (min_S > all_S) {
          min_S = all_S;
          ans = j;  
        }
      }
      S = min_S;
      for (int l = 0; l < hint.size(); l++) {
        S[include_itr[ans] + l] = hint[l];  
      }
    }
    for (int i = 0; i < S.size(); i++) {
      if (S[i] == '?') {
        S[i] = 'a';  
      }  
      cout << S[i];
    }
    cout << endl;
  }
  
    
}

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

static const int MOD = 1000000007;
using ll = long long;
using u32 = unsigned;
using u64 = unsigned long long;
using namespace std;

template<class T> constexpr T INF = ::numeric_limits<T>::max()/32*15+208;

template <u32 M>
struct modint {
    u32 val;
public:
    static modint raw(int v) { modint x; x.val = v; return x; }
    modint() : val(0) {}
    template <class T>
    modint(T v) { ll x = (ll)(v%(ll)(M)); if (x < 0) x += M; val = u32(x); }
    modint(bool v) { val = ((unsigned int)(v) % M); }
    modint& operator++() { val++; if (val == M) val = 0; return *this; }
    modint& operator--() { if (val == 0) val = M; val--; return *this; }
    modint operator++(int) { modint result = *this; ++*this; return result; }
    modint operator--(int) { modint result = *this; --*this; return result; }
    modint& operator+=(const modint& b) { val += b.val; if (val >= M) val -= M; return *this; }
    modint& operator-=(const modint& b) { val -= b.val; if (val >= M) val += M; return *this; }
    modint& operator*=(const modint& b) { u64 z = val; z *= b.val; val = (u32)(z % M); return *this; }
    modint& operator/=(const modint& b) { return *this = *this * b.inv(); }
    modint operator+() const { return *this; }
    modint operator-() const { return modint() - *this; }
    modint pow(long long n) const { modint x = *this, r = 1; while (n) { if (n & 1) r *= x; x *= x; n >>= 1; } return r; }
    modint inv() const { return pow(M-2); }
    friend modint operator+(const modint& a, const modint& b) { return modint(a) += b; }
    friend modint operator-(const modint& a, const modint& b) { return modint(a) -= b; }
    friend modint operator*(const modint& a, const modint& b) { return modint(a) *= b; }
    friend modint operator/(const modint& a, const modint& b) { return modint(a) /= b; }
    friend bool operator==(const modint& a, const modint& b) { return a.val == b.val; }
    friend bool operator!=(const modint& a, const modint& b) { return a.val != b.val; }
};
using mint = modint<MOD>;

int main() {
    int n;
    cin >> n;
    vector<mint> dp(n+1);
    dp[0] = 1;
    for (int i = 0; i < n; ++i) {
        for (int j = 3; i+j <= n; ++j) {
            dp[i+j] += dp[i];
        }
    }
    cout << dp.back().val << "\n";
    return 0;
}

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

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


using Edge = pair<int,int>; // (隣接頂点, 辺番号)
using Graph = vector<vector<Edge>>;
int N;
Graph G;

int main() {
    cin >> N;
    G.assign(N, vector<Edge>());
    for (int i = 0; i < N-1; ++i) {
        int a, b; cin >> a >> b; --a, --b;
        G[a].emplace_back(b, i); 
        G[b].emplace_back(a, i);
    }
    int max_color = 0;
    for (int i = 0; i < N; ++i) chmax(max_color, (int)G[i].size());
    vector<int> res(N-1, -1);

    vector<int> dist(N, -1);
    queue<pair<int,int>> que; // (頂点, 前回の色)
    que.push({0, -1});
    dist[0] = 0;
    while (!que.empty()) {
        auto p = que.front(); que.pop();
        int v = p.first, c = p.second;
        int color = 1;
        if (color == c) ++color;
        for (auto e : G[v]) {
            if (dist[e.first] == -1) {
                dist[e.first] = dist[v] + 1;
                que.push({e.first, color});
                res[e.second] = color;
                ++color;
                if (color == c) ++color;
            }
        }
    }
    cout << max_color << endl;
    for (auto v : res) cout << v << endl;
}

Measured memory_bytes: 7424
### constant

MAX_INT = (1 << 31) - 1

### main

while true
  n, m = gets.strip.split(' ').map{|s| s.to_i}
  break if n == 0 && m == 0

  edges = m.times.map{[]}
  nbrs = m.times.map{[]}

  n.times.each do
    a, b, cost, time = gets.strip.split(' ').map{|s| s.to_i}
    a -= 1
    b -= 1

    edges[a][b] = edges[b][a] = [cost, time]
    nbrs[a] << b
    nbrs[b] << a
  end

  k = gets.strip.to_i

  k.times.each do
    st, gl, r = gets.strip.split(' ').map{|s| s.to_i}
    st -= 1
    gl -= 1

    q = (0...m).map{|i| i}
    dists = m.times.map{MAX_INT}
    dists[st] = 0

    while ! q.empty?
      u = q.min{|a, b| dists[a] <=> dists[b]}
      q.delete(u)

      for v in nbrs[u]
        d = dists[u] + edges[u][v][r]
        if dists[v] > d
          dists[v] = d
        end
      end
    end

    puts dists[gl]
  end
end

Measured memory_bytes: 6212
#include <algorithm>
#include <iostream>
#include <cstring>
#include <vector>
using namespace std;

typedef long long ll;

const int MAX_N = 2e5 + 10, MOD = 1e9 + 7;
int n;
int h[MAX_N];
int Arr[MAX_N];
ll fen[MAX_N];
ll dp[MAX_N];

int _sum (int a, int b) {
	int c = a + b;
	if (MOD <= c)
		c -= MOD;
	
	return c;
}

int _mul (int a, int b) {
	int c = 1LL * a * b % MOD;
	return c;
}

void add (int tmp, ll val) {
	for (; tmp < MAX_N; tmp += tmp & -tmp)
		fen[tmp] = max(fen[tmp], val);
}

ll get (int tmp) {
	ll res = 0;
	for (; tmp; tmp -= tmp & -tmp)
		res = max(res, fen[tmp]);

	return res;
}

int main() {
	ios::sync_with_stdio(false), cin.tie(0);
	cin >> n;
	for (int i = 0; i < n; i++)
		cin >> h[i];
	for (int i = 0; i < n; i++)
		cin >> Arr[i];

	for (int i = 0; i < n; i++) {
		dp[i] = Arr[i] + get(h[i] - 1);
		add(h[i], dp[i]);
	}

	cout << get(n) << "\n";
	return 0;
}

Measured memory_bytes: 4992
#include <stdio.h>

int main(void){
    int W, H, x, y, r;
    scanf("%d %d %d %d %d", &W, &H, &x, &y, &r);
    if (x - r >= 0 && y - r >= 0 && x + r <= W && y + r <= H) {
        printf("Yes\n");
    }else{
        printf("No\n");
    }
    return 0;
}


Measured memory_bytes: 2092
import sys

hs = list(map(int, sys.stdin.read().strip().splitlines()[1].split(" ")))
if len(hs) == 1:
  print("Yes")
  sys.exit(0)
if hs[0] > hs[1]:
  hs[0] -= 1

for i in range(1, len(hs)):
  pre = hs[i-1]
  diff = hs[i] - pre
  if diff >= 1:
    hs[i] -= 1
  elif diff < 0:
    print("No")
    sys.exit(0)
print("Yes")


Measured memory_bytes: 14604
#include <bits/stdc++.h>
#define PI 3.14159265359
using namespace std;
template <class T>
inline bool chmax(T &a, T b) {
  if (a < b) {
    a = b;
    return true;
  }
  return false;
}
template <class T>
inline bool chmin(T &a, T b) {
  if (a > b) {
    a = b;
    return true;
  }
  return false;
}
const long long INF = 1LL << 60;
using pll = pair<long long, long long>;

int main() {
  // 標準入力が早くなる。Cスタイルの入出力とC++スタイルの入出力を混合させてはならない。
  cin.tie(nullptr);
  ios_base::sync_with_stdio(false);

  int K, N;
  cin >> K >> N;

  vector<int> A(N);

  for (int i = 0; i < N; i++) {
    cin >> A.at(i);
  }

  int res = 2000000;
  for (int i = 0; i < N - 1; i++) {
    chmin(res, K - abs(A.at(i) - A.at(i + 1)));
  }
  chmin(res, abs(A.at(0) - A.at(N - 1)));

  cout << res << endl;
  return 0;
}


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

using namespace std;

typedef long long int ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;

#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define rep2(i,n) for(int i=1;i<=(int)(n);i++)
#define rep3(i,n) for(int i=0;i<=(int)(n);i++)
#define REP(i,m,n) for(int i=m;i<(int)(n);i++)
#define repll(i,n) for(ll i=0;i<(ll)(n);i++)
#define repll2(i,n) for(ll i=1;i<=(ll)(n);i++)
#define REPLL(i,m,n) for(ll i=m;i<(ll)(n);i++)
#define INF (int)1e9  //
#define LINF (ll)4e18  //
#define MOD (int)(1e9)+7
#define MP make_pair
#define YES(n) cout << ((n) ? "YES" : "NO"  ) << endl
#define Yes(n) cout << ((n) ? "Yes" : "No"  ) << endl
#define PI 3.1415926535898

//------------------------------------------------------

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

    int common = n; //共通する部分文字列の長さのmax

    while (s != t) {
        s.erase(s.begin());
        t.erase(t.end() - 1);
        common--;
    }

    cout << n * 2 - common << endl;

    return 0;
}



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

int prime(int x)
{
	int i = 3;
	if(x == 2) return 1;
	
	if(x < 2 || x % 2 == 0) return 0;
	
	while(i <= sqrt(x))
	{
		if(x % i == 0) return 0;
		i += 2;
	}
	return 1;
}

int main()
{
	int i,n,count = 0;
	int a[10000];
	
	scanf("%d",&n);
	for(i = 0; i < n; i++) 
	{
		scanf("%d\n",a + i);
	}
	for(i = 0; i < n; i++) 
	{
		count += prime(a[i]);
	}
	
	printf("%d\n",count);
	
	return 0;
}

Measured memory_bytes: 632
import math

A, B, H, M = map(int, input().split())

theta_tansin = 360 * H / 12 + 30 * M / 60
theta_chosin = 360 * M / 60

theta = abs(theta_tansin - theta_chosin)
theta = min(theta, 360 - theta)
theta = math.radians(theta)

C = math.sqrt(A ** 2 + B ** 2 - 2 * A * B * math.cos(theta))

print(C)

Measured memory_bytes: 62412
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vs = vector<string>;
using msi = map<string, int>;
using mii = map<int, int>;
using psi = pair<string, int>;
using pii = pair<int, int>;
using vlai = valarray<int>;
#define rep(i,n) for(int i=0;i<n;i++)
#define range(i,s,n) for(int i=s;i<n;i++)
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define fs first
#define sc second
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define INF 1E9
#define EPS 1E-9
#define MOD (ll)(1E9+7)
#define PI 3.1415926535897932384

template <class T>ostream &operator<<(std::ostream &o, const vector<T> &v)
{
	rep(i, v.size()) {
		o << (i > 0 ? " " : "") << v[i];
	}
	return o;
}


int main() {
	string str1,str2;
	cin >> str1 >> str2;
	for (int i = 0; i < str1.size(); i++) {
		if (str1 == str2) { 
			cout << "Yes" << endl;
			return 0;
		}
		string tmp = str1.substr(str1.size() - 1, 1);
		str1.pop_back();
		str1 = tmp + str1;
	}
	cout << "No" << endl;
}


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

using namespace std;
 
#define len(x) (int)((x).size())
#define endl '\n'
#define x first
#define y second
#define int long long
#define double long double
#define all(a) (a).begin(), (a).end()
#define rall(a) (a).rbegin(), (a).rend()
#define vi vector<int> 
#define vvi vector<vector<int>>
#define pb push_back
 
#ifdef LOCAL
    #define dbg(x) cout << #x << " = " << x << endl;
#else 
    #define dbg(x)
#endif 
 
void solve(); signed main() {
#ifdef LOCAL
    freopen("input.txt", "r", stdin);                                       
    freopen("output.txt", "w", stdout);
#endif
    srand(time(0));
    ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    cout.setf(ios::fixed); cout.precision(10);
    solve();    
}

const int INF = 1e18, MAXN = 2e5 + 10, MOD = 1e9 + 7;

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

	vi dt = {1};
	for (int d = 6; d <= n; d *= 6) {
		dt.pb(d);
	}
	for (int d = 9; d <= n; d *= 9) {
		dt.pb(d);
	}

	vi f(n + 1, INF); 
	f[0] = 0;

	for (int i = 1; i <= n; ++i) {
		for (auto it : dt) {
			if (it <= i) {
				f[i] = min(f[i], f[i - it]);
			}
		}
		f[i]++;
	}

	cout << f[n] << endl;
}


Measured memory_bytes: 1024