akhauriyash/Code-Regression huggingface dataset:
//
#include <bits/stdc++.h>

#define endl '\n'
using namespace std;
using ll = long long;

const int N = 100005;
ll n, m;
vector<int> tree[N];
vector<ll> dp[N];
ll ans[N]; // ans[i] = # of ways when i is black root

void init();
void process();

int main()
{
    ios::sync_with_stdio(false); cin.tie(0);
    init();
    process();
    cout.flush();
    return 0;
}

void init()
{
    cin >> n >> m;
    for(int i = 1; i < n; i++)
    {
        int x, y; cin >> x >> y;
        tree[x].emplace_back(y);
        tree[y].emplace_back(x);
        dp[x].emplace_back(1);
        dp[y].emplace_back(1);
    }
}

ll add(ll lhs, ll rhs) { return (lhs + rhs)%m; }
void mul_self(ll &lhs, ll rhs) { lhs = lhs * rhs % m; }

// let v be the root, count ways
ll dfs1(int v, int p)
{
    ll cnt = 1;
    for(size_t i = 0; i < tree[v].size(); i++)
    {
        int c = tree[v][i];
        if(c == p) continue;
        dp[v][i] = dfs1(c, v);
        mul_self(cnt, add(1, dp[v][i]));
    }

    return cnt;
}

// change root from v to its childrens
void dfs2(int v, int p, ll cnt)
{
    if(tree[v].size() == 0) { ans[v] = 1; return; }
    for(size_t i = 0; i < tree[v].size(); i++)
        if(tree[v][i] == p) { dp[v][i] = cnt; break; }
    vector<ll> pre(tree[v].size(), 1), suf(tree[v].size(), 1);
    pre[0] = add(1, dp[v].front()), suf[tree[v].size()-1] = add(1, dp[v].back());
    for(int i = 1; i < dp[v].size(); i++) 
    {
        mul_self(pre[i], pre[i-1]);
        mul_self(pre[i], add(1, dp[v][i]));
    }
    for(int i = dp[v].size()-2; i >= 0; i--)
    {
        mul_self(suf[i], suf[i+1]);
        mul_self(suf[i], add(1, dp[v][i]));
    }
    /*
    cout << "v = " << v << endl;
    for(auto d:dp[v]) { cout << d << " "; } cout << endl;
    for(auto d:pre) { cout << d << " "; } cout << endl;
    for(auto d:suf) { cout << d << " "; } cout << endl;
    */
    ans[v] = pre.back();
    for(size_t i = 0; i < tree[v].size(); i++)
    {
        int c = tree[v][i];
        if(c == p) continue;
        ll tmp = 1;
        if(i > 0) mul_self(tmp, pre[i-1]);
        if(i+1 < tree[v].size()) mul_self(tmp, suf[i+1]);
        dfs2(c, v, tmp);
    }
}

void process()
{
    dfs1(1, 1);
    dfs2(1, 1, 7122);
    for(int i = 1; i <= n; i++) cout << ans[i] << endl;
}



Measured memory_bytes: 23168
#include<bits/stdc++.h>
using namespace std;
const long long md=998244353;
long long a,b,c,d,dp[2][3030][3030];
int main()
{
	cin>>a>>b>>c>>d;
	dp[0][a][b]=1;
	for(int i=a;i<=c;i++)
	{
		for(int j=b;j<=d;j++)
		{
			if(i==a && j==b)
			{
				continue;
			}
			dp[0][i][j]=dp[0][i-1][j]*j+dp[1][i-1][j];
			dp[0][i][j]%=md;
			dp[1][i][j]=dp[0][i][j-1]*i+dp[1][i][j-1]*i;
			dp[1][i][j]%=md;
		}
	}
	cout<<(dp[0][c][d]+dp[1][c][d])%md<<endl;
	return 0;
}

Measured memory_bytes: 145584
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        let mut next = || { iter.next().unwrap() };
        input_inner!{next, $($r)*}
    };
    ($($r:tt)*) => {
        let stdin = std::io::stdin();
        let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));
        let mut next = move || -> String{
            bytes
                .by_ref()
                .map(|r|r.unwrap() as char)
                .skip_while(|c|c.is_whitespace())
                .take_while(|c|!c.is_whitespace())
                .collect()
        };
        input_inner!{next, $($r)*}
    };
}

macro_rules! input_inner {
    ($next:expr) => {};
    ($next:expr, ) => {};

    ($next:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };
}

macro_rules! read_value {
    ($next:expr, ( $($t:tt),* )) => {
        ( $(read_value!($next, $t)),* )
    };

    ($next:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
    };

    ($next:expr, chars) => {
        read_value!($next, String).chars().collect::<Vec<char>>()
    };

    ($next:expr, usize1) => {
        read_value!($next, usize) - 1
    };

    ($next:expr, $t:ty) => {
        $next().parse::<$t>().expect("Parse error")
    };
}

fn main(){

    input!{
        x: usize,
        y: usize,
    }

    for a in 0..x+1 {
        if 2*a+4*(x-a) == y {
            println!("Yes");
            return;
        }
    }

    println!("No");

}

Measured memory_bytes: 2144
n = gets.to_i
p_arr = gets.split.map(&:to_i)

reo_cnt = 0
n.times do |i|
  if p_arr[i] != i + 1
    reo_cnt += 1
    if reo_cnt > 2
      puts 'NO'
      exit
    end
  end
end
puts 'YES'


Measured memory_bytes: 14276
import java.util.*;
 
public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        String b = sc.next();
        if(b.equals("A")) {
            System.out.println("T");
        }else if(b.equals("T")) {
            System.out.println("A");
        }else if(b.equals("C")) {
            System.out.println("G");
        }else {
            System.out.println("C");
        }
    }
}

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

int main() {
  int N, M;
  cin >> N >> M;
  int P[M], Y[M];
  rep(i, M) cin >> P[i] >> Y[i];

  vector<int> vec[N+1];
  rep(i, M) vec[P[i]].push_back(Y[i]);
  rep(i, N+1) sort(vec[i].begin(), vec[i].end());

  rep(i, M) {
    printf("%06d", P[i]);
    printf("%06d", 1 + distance(vec[P[i]].begin(), lower_bound(vec[P[i]].begin(), vec[P[i]].end(), Y[i])));
    cout << endl;
  }
  return 0;
}

Measured memory_bytes: 7808
#include<algorithm>
#include<climits>
#include<cmath>
#include<cstdlib>
#include<iomanip>
#include<iostream>
#include<numeric>
#include<string>
using namespace std;

long gcd(long x, long y) { if (x > y) { return gcd(y, x); } long r; while (y != 0) { r = x % y; x = y; y = r; }return x; }
long lcm(long x, long y) { return(x / gcd(x, y)) * y; }
void indexsort(long* first, long* last, long* func) { sort(first, last, [&](long a, long b) {return func[a] < func[b]; }); }
//--------------------

int main() {

	string res = "No";
	long A, B, C; cin >> A >> B >> C;

	if (A > C && C > B) res = "Yes";

	if (B > C && C > A) res = "Yes";

	cout << res << endl;
}

Measured memory_bytes: 256
import java.util.*;

class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		int[] A = new int[N];
		for (int i=0;i<N;i++) {
			A[i]=sc.nextInt();
		}

		int[] L = new int[N+1];
		int[] R = new int[N+1];
		int[] ans = new int[N];
		for (int i=0;i<N;i++) {
			L[i+1]=gcd(L[i],A[i]);
		}
		for (int i=N;i>0;i--) {
			R[i-1]=gcd(R[i],A[i-1]);
		}
		for (int i=0;i<N;i++) {
			ans[i]=gcd(L[i],R[i+1]);
		}
		int max=0;
		for (int i=0;i<N;i++) {
			max=Math.max(max,ans[i]);
		}
		System.out.println(max);
	}

	static int gcd(int m,int n) {
		if (m<n) {
			return gcd(n,m);
		}
		if (n==0) {
			return m;
		}
		return gcd(n,m%n);
	}
}

Measured memory_bytes: 51128
x = int(input())

for i in range(x//100+1):
  for j in range((x-i*100)//101+1):
    for k in range((x-i*100-j*101)//102+1):
      for l in range((x-i*100-j*101-k*102)//103+1):
        for m in range((x-i*100-j*101-k*102-l*103)//104+1):
          if (x-i*100-j*101-k*102-l*103-m*104)%105 == 0:
            print('1')
            exit()
print('0')

Measured memory_bytes: 3064
N, M = gets.split.map(&:to_i)
a = gets.split.map(&:to_i).sort.push(2**19)

k = 0
q = false
$<.read.split.map(&:to_i).each_slice(2).to_a.sort_by{|x|-x[1]}.each do |b, c|
  
	break if k == N
	b.times do
		if a[k] < c
			a[k] = c
		else
		  q = true
			break
		end
		k+=1
		break if k==N
	end	
	break if q
end

a.pop
p a.inject(:+)

Measured memory_bytes: 30432
using System;
using System.Linq;
using System.Collections.Generic;


class Program
{
    static void Main(string[] args)
    {
        string[] NM = Console.ReadLine().Split(' ');
        int N = int.Parse(NM[0]);
        int M = int.Parse(NM[1]);

        int answer = (N * (N-1) + M * (M-1)) / 2;

        Console.WriteLine(answer);
    }
}

Measured memory_bytes: 11092
import sys


def solve(N: int, M: int, A: "List[int]"):

    a = sum(A)

    if a > N:
        print(-1)
    else:
        print(N-a)

    return


def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    M = int(next(tokens))  # type: int
    A = [int(next(tokens)) for _ in range(M)]  # type: "List[int]"
    solve(N, M, A)

if __name__ == '__main__':
    main()


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

int main() {
    int e, y;
    cin >> e >> y;
    if(e == 0) {
        if(y <= 1911) cout << "M" << (y - 1867) << endl;
        else if(y <= 1925) cout << "T" << (y - 1911) << endl;
        else if(y <= 1988) cout << "S" << y - 1925 << endl;
        else cout << "H" << y - 1988 << endl;
    } else if(e == 1) {
        cout << 1867 + y << endl;
    } else if(e == 2) {
        cout << 1911 + y << endl;
    } else if(e == 3) {
        cout << 1925 + y << endl;
    } else {
        cout << 1988 + y << endl;
    }
}



Measured memory_bytes: 3092
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
using namespace std;

int main() {
  int N, L;
  cin >> N >> L;
  vector<string> s(N);
  for (int i=0; i<N; ++i) cin >> s.at(i);
  
  sort(s.begin(), s.end());
  for (int i=0; i<N; ++i) cout << s.at(i);
}
  

Measured memory_bytes: 256
using System;
class Program{
	private int abcdef(string s){
		int z = 0;
		if (String.Equals(s,"A"))
			z = 1;
		else if (String.Equals(s,"B"))
			z = 2;
		else if (String.Equals(s,"C"))
			z = 3;
		else if (String.Equals(s,"D"))
			z = 4;
		else if (String.Equals(s,"E"))
			z = 5;
		else if (String.Equals(s,"F"))
			z = 6;
		return z;
	}
	public static void Main(){
		Program prog = new Program();
		string[] str = Console.ReadLine().Split(' ');
		int x = prog.abcdef(str[0]);
		int y = prog.abcdef(str[1]);
		Console.WriteLine((x > y) ? ">" : (y > x) ? "<" : "=");
	}
}

Measured memory_bytes: 11092
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll mod=998244353;
const int maxn=300010;
int n;
ll a,b,k,jc[maxn],ivjc[maxn],ans;
ll ksm(ll x,ll y) {
	if (y==0) return 1;
	if (y==1) return x%mod;
	ll res=ksm(x,y/2);
	res*=res; res%=mod;
	if (y%2==1) res*=x,res%=mod;
	return res;
}
ll C(ll x,ll y) {
	return jc[x]*ivjc[y]%mod*ivjc[x-y]%mod;
}
int main() {
	//freopen("1.txt","r",stdin);
	scanf("%d %lld %lld %lld",&n,&a,&b,&k);
	jc[0]=1;
	for (int i=1;i<=n;i++) jc[i]=jc[i-1]*i%mod;
	ivjc[n]=ksm(jc[n],mod-2);
	for (int i=n-1;i>=0;i--) ivjc[i]=ivjc[i+1]*(i+1)%mod;
	for (ll x=0;x<=k/a+1&&x<=n;x++) {
		ll y=(k-x*a)/b;
		if ((k-a*x)%b!=0||y>n||y<0) continue;
		ans+=C(n,x)*C(n,y)%mod; ans%=mod;
	}
	printf("%lld\n",ans);
	return 0;
}


Measured memory_bytes: 4992
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <stdbool.h>
#include <math.h>

int asort(const void *A,const void *B){
    return *(long long*)A>*(long long*)B?1:0;
}

int dsort(const void *A,const void *B){
    return *(long long*)A<*(long long*)B?1:0;
}

int main(void){
    int n,m;
    scanf("%d%d",&n,&m);
    long long x[m];
    for (int i=0; i<m; i++){
        scanf("%lld",&x[i]);
    }
    qsort (x,m,sizeof(long long),asort);
    long long ans=x[m-1]-x[0];
    long long y[m-1];
    for (int i=0; i<m-1; i++){
        y[i]=x[i+1]-x[i];
    }
    qsort (y,m-1,sizeof(long long),dsort);
    if (m<=n){
        ans=0;
    } else {
        for (int i=0; i<n-1; i++){
        ans-=y[i];
        }
    }
    printf("%lld\n",ans);
}

Measured memory_bytes: 2284
#include <iostream>
#include <iomanip>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <algorithm>
#include <cstdio>
#include <utility>
#include <string>
#include <cmath>
#include <cstdlib>
#include <cstring>
#include <deque>
#include <numeric>

using namespace std;

typedef uint64_t u64;
typedef int64_t s64;
typedef uint32_t u32;
typedef int32_t s32;
typedef vector<s32> vs32;
typedef vector<u32> vu32;
typedef vector<s64> vs64;
typedef vector<u64> vu64;

const double PI=3.14159265358979323846;

#define MAX(x, y) ((x) < (y) ? (y) : (x))
#define MIN(x, y) ((x) > (y) ? (y) : (x))

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

#define CEIL(x, y) (((x) + (y) - 1) / (y))
#define MOD 1000000007ULL

#define IN(l, r, x) ((l) <= (x) && (x) < (r))


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

    string s;
    cin >> s;

    bool ans = (s[2] == s[3] && s[4] == s[5]);

    cout << (ans ? "Yes\n" : "No\n");
    return 0;
}



Measured memory_bytes: 256
import java.util.Scanner;

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

        char[] charArray = sc.next().toCharArray();
        int cnt = 0;

        for (int i = 0; i < charArray.length / 2; i++) {
            if (charArray[i] != charArray[charArray.length - 1 - i]) cnt++;
        }

        System.out.println(cnt);
    }
}

Measured memory_bytes: 23764
#include <bits/stdc++.h>
using namespace std;
int main() {
    int r;
    cin >> r;
    string ans = "AGC";
    if(r < 1200) ans = "ABC";
    if(r >= 1200 && r < 2800) ans = "ARC";
    cout << ans <<endl;
    return 0;
}

Measured memory_bytes: 256
#include<cstdio>
#include<cstring>
int main()
{
	int sg=0;
	int n,a,k;
	scanf("%d",&n);
	while(n--)
	{
		scanf("%d %d",&a,&k);
		while(a%k)
		{
			a-=(a/k)+1;
			if(k>a)a=0;
			if(k <= a && a < (k << 1))  {
				a = (a - k + 1) % 2;
				k = 0;
				break;
			}
		}
		if (k)sg^=a/k;
		else sg ^= a;
	}
	if(sg)puts("Takahashi");
		else puts("Aoki");
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define pb push_back
#define mp make_pair
#define f first
#define s second
#define sc(n) scanf("%d",&n)
#define scl(n) scanf("%lld",&n)
#define pr(n) printf("%d",n)
#define prl(n) printf("%lld",n)
#define nl printf("\n")
#define fr(i,n) for(i=0;i<n;i++)
#define rep(i,st,en) for(i=st;i<=en;i++)
#define repv(i,en,st) for(i=en;i>=st;i--)
#define fout cout<<fixed<<setprecision(7)
#define bi(n) __builtin_popcount(n)
#define bil(n) __builtin_popcountll(n)


typedef long long ll;
typedef pair<int,int> pii;
const int N = 100010;
ll mod = 1e9+7;
ll fmod(ll b,ll exp){
    ll res =1;
    while(exp){if(exp&1ll)res=(res*b)%mod;
    b =(b*b)%mod;exp/=2ll;
    }
    return res;
}


int A[N],B[N],C[N];
int dp[N][4];
int main()
{
    //freopen("input.txt", "r", stdin);
    //freopen("output.txt", "w", stdout);
    //ios_base::sync_with_stdio(false);cin.tie(NULL);
    int t=1,n,i,j,m;
    cin>>n;
    rep(i,1,n)cin>>A[i]>>B[i]>>C[i];
    rep(i,1,n)
    {
        dp[i][1] = max(dp[i-1][2],dp[i-1][3])+A[i];
        dp[i][2] = max(dp[i-1][1],dp[i-1][3])+B[i];
        dp[i][3] = max(dp[i-1][1],dp[i-1][2])+C[i];
    }
    cout<<max(dp[n][1],max(dp[n][2],dp[n][3]))<<"\n";

    
    return 0;
}


Measured memory_bytes: 2944
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

int main(void){
	int i;
	char a[10],b[5];
	scanf("%s%s",a,b);
	strcat(a,b);
	int c = atoi(a);
	for(i=0;i<=1000;i++){
		if(c==i*i){
			printf("Yes");
			return 0;
		}
	}
	printf("No");
	return 0;
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
#define PI 3.1415926535897
using namespace std;
typedef long long ll;
const int INF = 1000000000;
const ll LINF = 1000000000000000000; //1e18
const double EPS = 1e-10;

int main(void)
{
    int N;

    cin >> N;
    int sum = 0;
    for (int i = 1; i <= N; i++)
    {
        sum += i;
    }
    cout << sum << endl;
    return (0);
}

Measured memory_bytes: 256
S = list(input())


def dance_checker(S):
    N = len(S)
    for i in range(N):
        if i % 2 == 0:
            if S[i] == "L":
                return("No")
        else:
            if S[i] == "R":
                return("No")

    return("Yes")


print(dance_checker(S))


Measured memory_bytes: 2940
D=int(input())
*c,=map(int,input().split())
s=[]
for i in range(D):
    *x,=map(int,input().split())
    s.append(x)

dt=[]
last=[-1]*26
v=0
for d in range(D):
    news=[s[d][i]+c[i]*(d-last[i])*(d-last[i]-1)//2 for i in range(26)]
    maxi=0
    tmp=-float('inf')
    for i in range(26):
        if tmp<news[i]:
            maxi=i
            tmp=news[i]
    last[maxi]=d
    v+=s[d][maxi]
    for i in range(26):
        v-=c[i]*(d-last[i])
    dt.append(maxi+1)

for i in dt:
    print(i)

Measured memory_bytes: 74060
W,H,N = [int(i) for i in input().split()]
A = [list(map(int, input().split())) for i in range(N)]

x1,y1 = 0,0
x2 = W
y2 = H

for i in range(N):
    if A[i][2] == 1:
        if x1 < A[i][0]:
            x1 = A[i][0]
    elif A[i][2] == 2:
        if x2 > A[i][0]:
            x2 = A[i][0]
    elif A[i][2] == 3:
        if y1 < A[i][1]:
            y1 = A[i][1]
    elif A[i][2] == 4:
        if y2 > A[i][1]:
            y2 = A[i][1]

if (x2-x1) > 0 and (y2-y1) > 0:
    print((x2-x1)*(y2-y1))
else:
    print(0)

    

Measured memory_bytes: 3064
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

#define STRING_LIMIT 201
#define COUNT_SIZE 100
#define DATA_SET_LIMIT 10

typedef struct {
	char str[STRING_LIMIT];
	int strSize;
	int count;
	int* position;
} DataSet;

int InputDataSet(DataSet* dataSet);
void ShiftingDataSet(DataSet* dataSet, int length);
void FreeDataSet(DataSet* dataSet, int length);

int main(void) {
	DataSet dataSet[DATA_SET_LIMIT];
	int length;
	int idx;
	int size = 0;

	for (length = 0; length < DATA_SET_LIMIT; length++) {
		int res = InputDataSet(&dataSet[length]);

		if (res == -1) {
			length--;
			continue;
		}

		if (res == 1) {
			break;
		}
	}

	ShiftingDataSet(dataSet, length);

	for (idx = 0; idx < length; idx++) {
		size += printf("%s\n", dataSet[idx].str);
	}

	FreeDataSet(dataSet, length);
}

int InputDataSet(DataSet* dataSet) {

	int idx;
	char buffer[STRING_LIMIT];
	char* tmpBuffer = buffer;
	int size = 0;
	int count = 0;
	int* position;

	memset(buffer, '\0', STRING_LIMIT);
	scanf(" %[^\n]s", buffer);
	for (size = 0; *(tmpBuffer + size) != '\0'; size++);
	if (size == 1 && buffer[0] == '-') {
		return 1;
	}

	scanf("%d", &count);
	if (count < 1 || count > COUNT_SIZE) {
		return -1;
	}

	position = (int*)malloc(sizeof(int) * count);
	for (idx = 0; idx < count; idx++) {
		int tmp = 0;
		scanf("%d", &tmp);
		if (tmp < 1 || tmp > size) {
			return -1;
		}
		*(position + idx) = tmp;
	}

	memcpy(dataSet->str, buffer, STRING_LIMIT);
	dataSet->strSize = size;
	dataSet->count = count;
	dataSet->position = position;

	return 0;
}

void ShiftingDataSet(DataSet* dataSet, int length) {
	int idx;
	int idc;
	int idp;

	for (idx = 0; idx < length; idx++) {
		DataSet* set = dataSet + idx;
		int strSize = set->strSize;
		char tmpArr[strSize];
		int count = set->count;
		int* position = set->position;

		for (idc = 0; idc < count; idc++) {
			int pos = *(position + idc);
			memset(tmpArr, '\0', strSize);

			for (idp = 0; idp < pos; idp++) {
				tmpArr[idp] = set->str[idp];
			}

			for (idp = 0; idp < strSize - pos; idp++) {
				set->str[idp] = set->str[pos + idp];
			}

			int startIdx = strSize - pos;
			for (idp = startIdx; idp < strSize; idp++) {
				set->str[idp] = tmpArr[idp - startIdx];
			}
		}
	}
}

void FreeDataSet(DataSet* dataSet, int length) {
	int idx;

	for (idx = 0; idx < length; idx++) {
		DataSet* set = dataSet + idx;
		free(set->position);
	}
}


Measured memory_bytes: 2048
N, M, K = map(int, input().split())
A = list(map(int, input().split()))
B = list(map(int, input().split()))

cum_A = [0]
for a in A:
    add_value = cum_A[-1] + a
    if add_value > K:
        break
    cum_A.append(add_value)

cum_B = [0]
for b in B:
    add_value = cum_B[-1] + b
    if add_value > K:
        break
    cum_B.append(add_value)

ix_B = len(cum_B) - 1
ans = 0
for ix_A in range(len(cum_A)):
    while cum_A[ix_A] + cum_B[ix_B] > K:
        ix_B -= 1
    ans = max(ans, ix_A + ix_B)

print(ans)

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

using namespace std;

int main()
{
    string s; cin >> s;
    int abcd[4];

    for (int i =  0; i < 4; i++) abcd[i] = s[i] - '0';

    if (abcd[0] + abcd[1] + abcd[2] + abcd[3] == 7) {
        cout << abcd[0] << "+" << abcd[1] << "+" << abcd[2] << "+" << abcd[3] << "=7" << endl;

    } else if (abcd[0] + abcd[1] + abcd[2] - abcd[3] == 7) {
        cout << abcd[0] << "+" << abcd[1] << "+" << abcd[2] << "-" << abcd[3] << "=7" << endl;

    } else if (abcd[0] + abcd[1] - abcd[2] - abcd[3] == 7) {
        cout << abcd[0] << "+" << abcd[1] << "-" << abcd[2] << "-" << abcd[3] << "=7" << endl;

    } else if (abcd[0] + abcd[1] - abcd[2] + abcd[3] == 7) {
        cout << abcd[0] << "+" << abcd[1] << "-" << abcd[2] << "+" << abcd[3] << "=7" << endl;

    } else if (abcd[0] - abcd[1] + abcd[2] + abcd[3] == 7) {
        cout << abcd[0] << "-" << abcd[1] << "+" << abcd[2] << "+" << abcd[3] << "=7" << endl;

    } else if (abcd[0] - abcd[1] - abcd[2] + abcd[3] == 7) {
        cout << abcd[0] << "-" << abcd[1] << "-" << abcd[2] << "+" << abcd[3] << "=7" << endl;

    } else if (abcd[0] - abcd[1] + abcd[2] - abcd[3] == 7) {
        cout << abcd[0] << "-" << abcd[1] << "+" << abcd[2] << "-" << abcd[3] << "=7" << endl;

    } else if (abcd[0] - abcd[1] - abcd[2] - abcd[3] == 7) {
        cout << abcd[0] << "-" << abcd[1] << "-" << abcd[2] << "-" << abcd[3] << "=7" << endl;
    }

    return 0;
}

Measured memory_bytes: 888
#include<iostream>
#include<vector>
#include<algorithm>
#include<bitset>
#include<map>
#include<queue>
#include<stack>
using namespace std;
typedef long long ll;
#define repi(i,a,b) for(ll i = (ll)(a) ; i < (ll)(b) ; i++)
#define repd(i,a,b) for(ll i = (ll)(a) ; i > (ll)(b) ; i--)

int main() {
	ll a, b, c, x, ans = 0;
	cin >> a >> b >> c >> x;
	repi(i, 0, a+1) {
		repi(j, 0, b+1) {
			repi(k, 0, c+1) {
				if (500 * i + 100 * j + 50 * k == x) ans++;
			}
		}
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <string>
#include <algorithm>
#include <cmath>
#include <vector>
#define rep(i, n) for(int i = 0; i < n; i++)
using namespace std;
typedef long long ll;

int main() {
    int a[3];
    rep(i, 3) {
        cin >> a[i];
    }

    sort(a, a+3);

    cout << a[0]+a[1];
    
    cout << endl;
    return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
int main(void){
  int l,i,j,sum=0;
  scanf("%d",&l);
  int num[l];
  for(i=0;i<l;i++){
    scanf("%d",&num[i]);
  }
  for(i=0;i<l-1;i++){
    for(j=i+1;j<l;j++){
      sum+=(num[i]*num[j]);
    }
  }
  printf("%d",sum);
  return 0;
}

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


int main()
{
  int k, s;
  cin >> k >> s;
  
  int res = 0;
  for(int x = 0; x <= k; x++)
  {
    for(int y = 0; y <= k; y++)
    {
      int z = s - x - y;
      if(z >= 0 && z <= k) res++;
    }
  }
  
  cout << res << endl;
  
  
  return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
#include <iostream>
#include <algorithm>
#include <math.h>
#include <string.h>
#include <string>
using namespace std;
typedef long long ll;
const int maxn = 1000000;
const int MOD = 1e9+7;
char str[20];
int main()
{
	scanf("%s",str);



		int len = strlen(str);
		int i;
		int ans=0;
		for(i=1;i<len;i++)
			if (str[i]!='9')
				break;
		if (i!=len)
		{
			ans = 9*len - 9;
			ans+= str[0]-'0'-1;
		}else
		{
			ans = 9*len - 9;
			ans += str[0]-'0';
		}
		printf("%d",ans);


	return 0;
}


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

#define rep(i, n) for (int i = 0; i < int(n); i++)
#define rrep(i, n) for (int i = int(n) - 1; i >= 0; i--)
#define reps(i, n) for (int i = 1; i <= int(n); i++)
#define rreps(i, n) for (int i = int(n); i >= 1; i--)
#define repc(i, n) for (int i = 0; i <= int(n); i++)
#define rrepc(i, n) for (int i = int(n); i >= 0; i--)
#define repi(i, a, b) for (int i = int(a); i < int(b); i++)
#define repic(i, a, b) for (int i = int(a); i <= int(b); i++)
#define each(x, y) for (auto &x : y)
#define all(a) (a).begin(), (a).end()
#define bit(b) (1ll << (b))
#define uniq(v) (v).erase(unique(all(v)), (v).end())
#define rsort(v) sort(all(v)); reverse(all(v))

using namespace std;

using i32 = int;
using i64 = long long;
using f80 = long double;
using vi32 = vector<i32>;
using vi64 = vector<i64>;
using vf80 = vector<f80>;
using vstr = vector<string>;

inline void yes() { cout << "Yes" << '\n'; exit(0); }
inline void no() { cout << "No" << '\n'; exit(0); }
inline i64 gcd(i64 a, i64 b) { if (min(a, b) == 0) return max(a, b); if (a % b == 0) return b; return gcd(b, a % b); }
inline i64 lcm(i64 a, i64 b) { return a / gcd(a, b) * b; }
void solve(); int main() { ios::sync_with_stdio(0); cin.tie(0); cout << fixed << setprecision(16); solve(); return 0; }
template<typename T> class pqasc : public priority_queue<T, vector<T>, greater<T>> {};
template<typename T> class pqdesc : public priority_queue<T, vector<T>, less<T>> {};
template<typename T> inline void amax(T &x, T y) { if (x < y) x = y; }
template<typename T> inline void amin(T &x, T y) { if (x > y) x = y; }
template<typename T> inline T power(T x, i64 n) { T r = 1; while (n > 0) { if (n & 1) r *= x; x *= x; n >>= 1; } return r; }
template<typename T> istream& operator>>(istream &is, vector<T> &v) { for (auto &x : v) is >> x; return is; }
template<typename T> ostream& operator<<(ostream &os, const vector<T> &v) { rep(i, v.size()) { if (i) os << ' '; os << v[i]; } return os; }

void solve() {
  int N, A, B; cin >> N >> A >> B;
  cout << min(A, B) << " " << max(0, A + B - N) << '\n';
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using lint=long long;
int main(){
    std::cin.tie(nullptr);std::ios_base::sync_with_stdio(false);
    std::cout.setf(std::ios_base::fixed);std::cout.precision(15);
    lint a[]={1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51};
    lint k;std::cin>>k;
    std::cout<<a[k-1]<<'\n';
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define PI 3.14159265358979323846
#define MAXINF (1e18L)
#define INF (1e9L)
#define EPS (1e-9)
#define MOD ((ll)(1e9+7))
#define REP(i, n) for(int i=0;i<int(n);++i)
#define Rep(i,sta,n) for(int i=sta;i<n;i++)
#define RREP(i, n) for(int i=int(n)-1;i>=0;--i)
#define ALL(v) v.begin(),v.end()
#define FIND(v,x) (binary_search(ALL(v),(x)))
#define SORT(v) sort(ALL(v))
#define RSORT(v) sort(ALL(v));reverse(ALL(v))
#define DEBUG(x) cerr<<#x<<": "<<x<<endl;
#define DEBUG_VEC(v) cerr<<#v<<":";for(int i=0;i<v.size();i++) cerr<<" "<<v[i]; cerr<<endl
#define Yes(n) cout<<((n)?"Yes":"No")<<endl
#define YES(n) cout<<((n)?"YES":"NO")<<endl
#define pb push_back
#define fi first
#define se second
using namespace std;
template<class A>void pr(A a){cout << (a) << endl;}
template<class A,class B>void pr(A a,B b){cout << a << " "  ;pr(b);}
template<class A,class B,class C>void pr(A a,B b,C c){cout << a << " " ;pr(b,c);}
template<class A,class B,class C,class D>void pr(A a,B b,C c,D d){cout << a << " " ;pr(b,c,d);}
template<class T> inline bool chmin(T& a, T b){return a>b ? a=b, true : false;}
template<class T> inline bool chmax(T& a, T b){return a<b ? a=b, true : false;}
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll,ll> pll;

int main(void)
{
    int N;
    cin >> N;
    vector<ll> A(N);
    for (int i = 0; i < N; i++) {
        cin >> A[i];
    }
    REP(i, N){
        if(A[i] > i){
            pr(-1);
            return 0;
        }
        if(i!=0&&(A[i]-A[i-1])>1){
            pr(-1);
            return 0;
        }
    }
    ll ans = 0;
    vector<ll> X(N);
    for (int i = N-1; i > 0; i--)
    {
        if(X[i] == A[i]) {
            X[i-1] = X[i]-1;
            continue;
        }
        X[i-1] = A[i]-1;
        ans += A[i];
    }
    pr(ans);
}

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

int gcd(int x, int y);

const int INF = 1001001001;

/*struct mint {
    ll x; // typedef long long ll;
    mint(ll x = 0) :x((x% mod + mod) % mod) {}
    mint operator-() const { return mint(-x); }
    mint& operator+=(const mint a) {
        if ((x += a.x) >= mod) x -= mod;
        return *this;
    }
    mint& operator-=(const mint a) {
        if ((x += mod - a.x) >= mod) x -= mod;
        return *this;
    }
    mint& operator*=(const mint a) { (x *= a.x) %= mod; return *this; }
    mint operator+(const mint a) const { return mint(*this) += a; }
    mint operator-(const mint a) const { return mint(*this) -= a; }
    mint operator*(const mint a) const { return mint(*this) *= a; }
    mint pow(ll t) const {
        if (!t) return 1;
        mint a = pow(t >> 1);
        a *= a;
        if (t & 1) a *= *this;
        return a;
    }

    // for prime mod
    mint inv() const { return pow(mod - 2); }
    mint& operator/=(const mint a) { return *this *= a.inv(); }
    mint operator/(const mint a) const { return mint(*this) /= a; }
};
istream& operator>>(istream & is, const mint & a) { return is >> a.x; }
ostream& operator<<(ostream & os, const mint & a) { return os << a.x; }*/


int main() {
    int n, m;
    cin >> n >> m;
    vector<int> road(n, 0);
    rep(i, m) {
        int a, b;
        cin >> a >> b;
        road[a - 1]++;
        road[b - 1]++;
    }
    rep(i, n) {
        cout << road[i] << endl;
    }
    return 0;
}

/*���C�u�����ő����*/
//���[�O���b�h�̌ݏ��@
int gcd(int x, int y) {
    int num[3];
    num[0] = (x > y) ? x : y;
    num[1] = (x <= y) ? x : y;
    num[2] = num[0] % num[1];

    while (num[2]) {
        num[0] = num[1];
        num[1] = num[2];
        num[2] = num[0] % num[1];
    }

    return num[1];
}

Measured memory_bytes: 256
#include <vector>
#include <iostream>
#include <algorithm>
#include <functional>
using namespace std;
class Graph1 {
public:
	// ------Basics ------ //
	static const int INF = 2147483647;
	int V, E; vector<vector<int> > G;
	Graph1() : V(0), E(0), G(vector<vector<int> >()) {}
	Graph1(int v) : V(v), E(0), G(vector<vector<int> >(v)) {}
	Graph1(vector<vector<int> > g) : V(g.size()), G(g) { for (int i = 0; i < g.size(); i++) E += g[i].size(); }
	int size() { return V; }
	void add1(int v1, int v2) { G[v1].push_back(v2); E++; }
	void add2(int v1, int v2) { add1(v1, v2); add1(v2, v1); }
	friend bool operator==(const Graph1& g1, const Graph1& g2) { return g1.G == g2.G; }
	friend bool operator!=(const Graph1& g1, const Graph1& g2) { return g1.G != g2.G; }
	vector<int> operator[](int x) { return G[x]; }

	// ------ Algorithms ------ //
	vector<int> tsort() {
		int n = G.size();
		vector<int> ret, vis(n);
		function<bool(int)> dfs = [&](int v) {
			vis[v] = true;
			for (auto &e : G[v]) if (!vis[e] && !dfs(e)) return false;
			ret.push_back(v);
			return true;
		};
		for (int i = 0; i < n; i++) if (!vis[i] && !dfs(i)) return {};
		reverse(ret.begin(), ret.end());
		return ret;
	}
};
int V, E, s, t;
int main() {
	scanf("%d%d", &V, &E);
	Graph1 G(V);
	for(int i = 0; i < E; i++) {
		scanf("%d%d", &s, &t);
		G.add1(s, t);
	}
	vector<int> v = G.tsort();
	for(int i = 0; i < v.size(); i++) cout << v[i] << endl;
	return 0;
}

Measured memory_bytes: 3760
// インクルード
#include <iostream>
#include <vector>
#include <string>
#include <cmath>
#include <algorithm>
#include <iomanip>

// 名前空間省略
using namespace std;

// メイン
int main()
{
	// 入出力の高速化
	ios::sync_with_stdio(false);
	cin.tie(nullptr);

	// 表示精度変更
	cout << fixed << setprecision(16);

    string s;
    cin >> s;

    string ans="";
    for(int i=0;i<s.length();i++){
        //cout << s[i] << endl;
        switch(s[i]){
        case '0':
            ans+="0";
            break;

        case '1':
            ans+="1";
            break;

        case 'B':
            if(ans.length()>0) ans.pop_back();
            break;
        }
        //cout << ans << endl;
    }

    cout << ans << endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <algorithm>
#include <cmath>
#include <vector>
using namespace std;
int main() {
	int n, t, a[200001];
	cin >> n >> t;
	for (int i = 0; i < n; i++)cin >> a[i];
	int count = a[0], an = 0;
	for (int i = 0; i < n; i++) {
		int memo = max(count, a[i]);
		count = a[i] + t;
		an += count - memo;
	}

	cout << an << endl;
	getchar();
	getchar();
	return 0;
}

Measured memory_bytes: 1024
import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,random,time,copy,functools

sys.setrecursionlimit(10**7)
inf = 10**20
eps = 1.0 / 10**10
mod = 998244353

def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LI_(): return [int(x)-1 for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def I(): return int(sys.stdin.readline())
def F(): return float(sys.stdin.readline())
def S(): return input()
def pf(s): return print(s, flush=True)


def main():
    rr = []

    while True:
        w,h = LI()
        if w == 0 and h == 0:
            break
        a = [[c for c in S()] for _ in range(h)]
        t = [[0]*w for i in range(h)]
        r = 0
        for i in range(h):
            for j in range(w):
                c = a[i][j]
                if not ('0' <= c <= '9'):
                    continue
                d = int(c) + t[i][j] * 10
                if r < d:
                    r = d
                if i < h-1 and t[i+1][j] < d:
                    t[i+1][j] = d
                if j < w-1 and t[i][j+1] < d:
                    t[i][j+1] = d
        rr.append(r)

    return '\n'.join(map(str, rr))


print(main())




Measured memory_bytes: 9100
#include<bits/stdc++.h>
using namespace std;
long long a,b,c,d,e,s;
int main()
{
    scanf("%lld%lld%lld%lld%lld",&a,&b,&c,&d,&e);
    b=min(b,a<<1); c=min(c,b<<1); d=min(d,c<<1); s=e/2*d+(e&1)*c;
    printf("%lld\n",s);
}

Measured memory_bytes: 256
N,W=map(int,input().split())
table=[[] for i in range(4)]
a,b = map(int,input().split())
table[0].append(b)
for i in range(1,N):
    w,v = map(int,input().split())
    table[w-a].append(v)
for i in range(4):
    table[i].sort()
    table[i]+=[0]
ans=0
for i in range(len(table[3])+1):
    for j in range(len(table[1])+1):
        for k in range(len(table[2])+1):
            t=(W-a*(i+j+k)-j-2*k-3*i)//a
            if t<0:
                break
            else:
                x=sum(table[3][-i-1:]+table[1][-j-1:]+table[2][-k-1:]+table[0][-t-1:])
                ans=max(ans,x)  
print(ans)

Measured memory_bytes: 42216
import math
from functools import reduce

def lcm2(x, y):
    return (x * y) // math.gcd(x, y) 

def lcm(nums):
    return reduce(lambda x, y: lcm2(x, y), nums)

N = int(input())
T = []

for _ in range(N):
    T.append(int(input()))

print(lcm(T))

Measured memory_bytes: 9576
#include <iostream>
 
using namespace std;
 
int main() {
  long long int a,b,c, X, Y;
  cin >> a >> b >> c ;

  X = (c - a - b);
  Y = 4 * a * b;

  cout <<(  (  X > 0 && X * X > Y ) ? "Yes\n" : "No\n" );
  return 0;
}

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

using namespace std;

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

int main()
{
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	int N, K; cin >> N >> K;

	int res = 1;
	rep (i, N) {
		if (i == 0){
			res *= K;
		}else{
			res *= (K-1);
		} // end if
//		cerr << res << endl;
	} // end rep
	
	cout << res << endl;
		
	return 0;
}

Measured memory_bytes: 256
using System;
class Program
{
    static void Main(string[] args)
    {
        int[] a = new int[100001];
        long total = 0;
        int n = int.Parse(Console.ReadLine());

        string[] input = Console.ReadLine().Split(' ');
        for (int i = 0; i < n; i++)
        {
            int tmp = int.Parse(input[i]);
            a[tmp]++;
            total += tmp;
        }

        int q = int.Parse(Console.ReadLine());
        int[,] bc = new int[q, 2];

        for (int i = 0; i < q; i++)
        {
            input = Console.ReadLine().Split(' ');
            bc[i, 0] = int.Parse(input[0]);
            bc[i, 1] = int.Parse(input[1]);
        }

        for (int i = 0; i < q; i++)
        {
            total += ((bc[i, 1] - bc[i, 0]) * a[bc[i, 0]]);
            a[bc[i, 1]] += a[bc[i, 0]];
            a[bc[i, 0]] = 0;

            Console.WriteLine(total);
        }
    }
}

Measured memory_bytes: 49584
#include<iostream>
    #include<algorithm>
        using namespace std;
        int main(){
          int N;
          cin>>N;
          int card[N];
          for(int i=0;i<N;i++){
            cin>>card[i];
          }
          int a=0,b=0;
          sort(card,card+N,greater<int>());
          for(int i=0;i<N;i++){
            if(i%2==0)a+=card[i];
            else b+=card[i];
          }
          cout<<a-b<<endl;
        }

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(n);i++)
#define all(v) v.begin(),v.end()
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
const int INF=1e9;
const int di[] = {-1,0,1,0};
const int dj[] = {0,-1,0,1};

int main() {
  int n;
  cin>>n;
  map<string,int> mp;
  rep(i,n){
    string s;
    cin>>s;
    mp[s]++;
  }
  int mx=0;
  for(auto p:mp) mx=max(mx,p.second);
  for(auto p:mp){
    if(p.second==mx){
      cout<<p.first<<endl;
    }
  }
}

Measured memory_bytes: 19260
//Awwawa! Dis cold yis ratten buy waxberry!
#include <bits/stdc++.h>
#define ll long long
#define maxn 300005 /*rem*/
#define mod 1000000007
#define db double
#define vi vector<int>
#define pb push_back
#define mp make_pair
#define pi pair<int, int>
#define fi first
#define se second

template <typename T> bool chkmax(T &x,T y){return x<y?x=y,true:false;}
template <typename T> bool chkmin(T &x,T y){return x>y?x=y,true:false;}

using namespace std;
ll ksm(ll a, ll b) {
   if (!b) return 1;
   ll ns = ksm(a, b >> 1);
   ns = ns * ns % mod;
   if (b & 1) ns = ns * a % mod;
   return ns;
}
const int L = 100005;
int mx[515][L];
int v[maxn], w[maxn]; 
vector<pi> q[maxn];
int main() {
	int n;
	cin >> n;
	for (int i = 1; i <= n; i++)
		scanf("%d%d", &v[i], &w[i]);
	const int d = 512;
	for (int i = 1; i <= n; i++) {
		int f = (i / 2);
		if (i < d) {
			q[i].pb(mp(0, 0));
			for (int j = L - 1; j >= 0; j--) {
				mx[i][j] = mx[f][j];
				if (j >= w[i])
					chkmax(mx[i][j], mx[f][j - w[i]] + v[i]);
			}
		}
		else {
			q[i].resize(q[f].size() * 2);
			int cnt = 0;
			for (int j = 0; j < q[f].size(); j++)
				q[i][cnt++] = q[f][j], 
				q[i][cnt++] = mp(q[f][j].fi + w[i], q[f][j].se + v[i]);
		}
	}
	int qq;
	cin >> qq;
	while (qq--) {
		int x, l;
		scanf("%d%d", &x, &l);
		int ft = x;
		while (ft >= d) ft /= 2;
		int ans = 0;
		for (auto v : q[x])
			if (v.fi <= l)
				chkmax(ans, v.se + mx[ft][l - v.fi]);
		printf("%d\n", ans);
	}
	return 0;
}


Measured memory_bytes: 915620
#include <bits/stdc++.h>
using namespace std;
//debug
#ifdef grief
#define debug(...) do{\
	fprintf(stderr , "%s - %d : (%s) = " , __PRETTY_FUNCTION__ , __LINE__ , #__VA_ARGS__ );\
	_DO(__VA_ARGS__);\
}while(0)
template<typename I> 				void _DO(I&&x){	cerr<<x<<endl;	}
template<typename I,typename...T>	void _DO(I&&x,T&&...tail){	cerr<<x<<" , ";	_DO(tail...);	}
template<typename _a,typename _b> 	ostream& operator << (ostream &_s,const pair<_a,_b> &_p)
{	return _s<<'('<<_p.first<<','<<_p.second<<')';	}
#define IOS
#else
#define debug(...)
#define IOS do{ios_base::sync_with_stdio(0); cin.tie(0);}while(0);
#endif
//type
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef priority_queue<pll,vector<pll>,greater<pll> > heap;
//macro
#define SZ(x) ((ll)(x).size())
#define ALL(x) (x).begin(),(x).end()
#define F first
#define S second
#define pb push_back
#define eb emplace_back
#define stp setprecision(30)<<fixed
const ll INF=0x3f3f3f3f3f3f3f3f;
const int NF=0x3f3f3f3f;
const ll MAX=1e5+5,Mlg=__lg(MAX)+2;
const ll MOD=1e9+7;
// ready~ go!
// let's coding and have fun!
// I can't solve this problem!
ll L[99];
int main(){
	IOS
	L[0]=2;
	L[1]=1;
	for(int i=2;i<99;i++)	L[i]=L[i-1]+L[i-2];
	int n;	cin>>n;
	cout<<L[n]<< '\n';
	return 0;
}


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

int main(){
  string s;
  bool ans=false;
  cin >> s;
  for(char c : s)if(c=='7')ans=true;
  cout << (ans?"Yes":"No") << endl;
  return 0;
}


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

typedef long long i64;

const int N = 100000 + 10;

int n, m, a[N];
i64 k, x[N], y[N], z[N];

int p[N], q[N];

void comp(int lhs[], int rhs[]) {
  static int res[N];
  for (int i = 1; i < n; ++i) res[i] = rhs[lhs[i]];
  std::copy(res + 1, res + n, lhs + 1);
}

void power(int base[], i64 exp) {
  static int res[N];
  for (int i = 1; i < n; ++i) res[i] = i;
  for (; exp; exp >>= 1) {
    if (exp & 1) comp(res, base);
    comp(base, base);
  }
  std::copy(res + 1, res + n, base + 1);
}

int main() {
  scanf("%d", &n);
  for (int i = 1; i <= n; ++i) scanf("%lld", &x[i]);
  scanf("%d%lld", &m, &k);
  for (int i = 1; i < n; ++i) y[i] = x[i + 1] - x[i];
  for (int i = 1; i < n; ++i) q[i] = i;
  for (int i = 1; i <= m; ++i) scanf("%d", &a[i]);
  for (int i = 1; i <= m; ++i) std::swap(q[a[i]], q[a[i] - 1]);
  for (int i = 1; i < n; ++i) p[q[i]] = i;
  power(p, k);
  for (int i = 1; i < n; ++i) z[p[i]] = y[i];
  for (int i = 1; i < n; ++i) x[i + 1] = x[i] + z[i];
  for (int i = 1; i <= n; ++i) printf("%lld\n", x[i]);
  return 0;
}


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

int main() {
  //宣言
  int H,W;
  string S,F ="";
  
  
  //入力
  cin >> H >> W;
  
  //処理
  for(int i=0;i<W+2;i++){
    F += '#';
  }
  
  cout << F << endl;
  for(int i=0; i<H;i++){
    cin >> S;
    cout << '#'+ S +'#' << endl;
  }
  cout << F << endl;
  
  //出力cout << ans << endl;
}

Measured memory_bytes: 256
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cmath>
#include <ctime>
#include <cstring>
#include <functional>
#include <iostream>
#include <iomanip>
#include <limits>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <regex>
#include <vector>

#define fix(n)          cout<<fixed<<setprecision(n)
#define rep(i,n)        for (int i = 0; i < (n); ++i)
#define sort(a)         sort((a).begin(), (a).end())
#define uniq(a)         sort(a);(a).erase(unique((a).begin(), (a).end()), (a).end())
#define reverse(a)      reverse((a).begin(), (a).end())
#define ctos(c)         string(1, (c))
#define out(d)          cout << (d)
#define outl(d)         std::cout<<(d)<<"\n"
#define YES()           cout << "YES" << endl
#define NO()            cout << "NO" << endl
#define Yes()           cout << "Yes" << endl
#define No()            cout << "No" << endl
#define ceil(x, y)      ((x + y - 1) / (y))
#define debug(x)        cerr << #x << ": " << (x) << '\n'
#define debug2(x, y)    cerr << #x << ": " << (x) << ", " << #y << ": " << (y) << '\n'
#define debug3(x, y, z) cerr << #x << ": " << (x) << ", " << #y << ": " << (y) << ", " << #z << ": " << (z) << '\n'
#define dbg(v)          for (size_t _ = 0; _ < v.size(); ++_){ cerr << #v << "[" << _ << "] : " << v[_] << '\n'; }

using namespace std;
using ll = long long;
using ld = long double;
using P = pair<ll,ll>;

const ll MOD = 1000000007; // 10^9 + 7
const int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1};
const int dy[8] = {0, 1, 0, -1, 1, 1, -1, -1};

void solve() {
  int n; cin >> n;
  vector<int> a(n); rep(i, n) cin >> a[i];
  int comp = 0, ans = 1;

  for (int i = 1; i < n; i++) {
    if (a[i-1] == a[i]) continue;
    else if (a[i-1] < a[i]) {
      if (comp == 0) comp = 1;
      else if (comp == -1) {
        ans++;
        comp = 0;
      }
    } else {
      if (comp == 0) comp = -1;
      else if (comp == 1) {
        ans++;
        comp = 0;
      }
    }
  }

  outl(ans);
}

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  srand((unsigned)time(NULL));
  fix(12);

  solve();
}


Measured memory_bytes: 888
#include<iostream>
#include<algorithm>
#include<cmath>
#include<cstdlib>
#include<string>
#include<vector>
using namespace std;

int main(void) {
	string a, b, c;
	cin >> a >> b >> c;
	if (a[a.size() - 1] == b[0] && b[b.size() - 1] == c[0]) {
		cout << "YES";
		return 0;
	}
	cout << "NO";
	return 0;
}

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

using namespace std;

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

    double r0, w0, c, r;

    while (cin >> r0 >> w0 >> c >> r) {
        if (r0 == 0 && w0 == 0 && c == 0 && r == 0)
            break;

        int x = 0;
        while (true) {
            double y = (r0 + x * r  - c * w0) / c;
            if (0.0 <= y) {
                cout << x << endl;
                break;
            }
            ++x;
        }
    }

    return 0;
}

Measured memory_bytes: 3244
function Main(input) {
	input = input.trim().split(" ").map((list)=>Number(list));
  var output = Math.min(input[1],input[2]) + " ";//両方読んでいる最大
  if(input[0] < input[1] + input[2]){
    if(input[0] == Math.max(input[1],input[2])){ 
    	output += Math.min(input[1],input[2]);
    }else{
      output += input[1] + input[2] - input[0];
    }
     }else{
     output += "0";
     }
  console.log(output);
}

Main(require("fs").readFileSync("/dev/stdin", "utf8"));


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

#define EPS (1e-10)
#define equals(a,b) (fabs((a)-(b))<EPS)

class Point{
    public:
    double x,y;
    Point(double x=0,double y=0):x(x),y(y){}
    Point operator+(const Point &p){
        return Point(x+p.x,y+p.y);
    }
    Point operator-(const Point &p){
        return Point(x-p.x,y-p.y);
    }
    Point operator*(const double &a){
        return Point(a*x,a*y);
    }
    Point operator/(const double &a){
        return Point(x/a,y/a);
    }
    double abs(){
        return sqrt(norm());
    }
    double norm(){
        return x*x+y*y;
    }
    bool operator<(const Point &p){
        return x!=p.x?x<p.x:y<p.y;
    }
    bool operator==(const Point &p){
        return fabs(x-p.x)<EPS&&fabs(y-p.y)<EPS;
    }
};
typedef Point Vector;
struct Segment{
    Point p1,p2;
    Segment(){}
    Segment(Point p1,Point p2):p1(p1),p2(p2){}
};
typedef Segment Line;

double dot(Vector a,Vector b){
    return a.x*b.x+a.y*b.y;
}

double cross(Vector a,Vector b){
    return a.x*b.y-a.y*b.x;
}

bool isOrthogonal(Segment s1,Segment s2){
    return equals(dot(s1.p2-s1.p1,s2.p2-s2.p1),0.0);
}

bool isParallel(Segment s1,Segment s2){
    return equals(cross(s1.p2-s1.p1,s2.p2-s2.p1),0.0);
}

Point project(Segment s,Point p){
    Vector base=s.p2-s.p1;
    double r=dot(p-s.p1,base)/base.norm();
    return s.p1+base*r;   
}

Point reflect(Segment s,Point p){
    return p+(project(s,p)-p)*2;
}

double getDistanceLP(Line l,Point p){
    return abs(cross(l.p2-l.p1,p-l.p1))/(l.p2-l.p1).abs();
}

double getDistanceSP(Segment s,Point p){
    if(dot(s.p2-s.p1,p-s.p1)<0){
        return (p-s.p1).abs();
    }
    if(dot(s.p1-s.p2,p-s.p2)<0){
        return (p-s.p2).abs();
    }
    return getDistanceLP(s,p);
}

int ccw(Point p0,Point p1,Point p2){
    Vector a=p1-p0;
    Vector b=p2-p0;
    if(cross(a,b)>EPS) return 1;
    if(cross(a,b)<-EPS) return -1;
    if(dot(a,b)<-EPS) return 2;
    if(a.norm()<b.norm()) return -2;
    return 0;
}

bool intersect(Point p1,Point p2,Point p3,Point p4){
    return (ccw(p1,p2,p3)*ccw(p1,p2,p4)<=0&&
        ccw(p3,p4,p1)*ccw(p3,p4,p2)<=0);
}

bool intersect(Segment s1,Segment s2){
    return intersect(s1.p1,s1.p2,s2.p1,s2.p2);
}

double getDistance(Segment s1,Segment s2){
    if(intersect(s1,s2)) return 0;
    return min(min(getDistanceSP(s1,s2.p1),getDistanceSP(s1,s2.p2)),
        min(getDistanceSP(s2,s1.p1),getDistanceSP(s2,s1.p2)));
}

Point getCrossPoint(Segment s1,Segment s2){
    Vector base=s2.p2-s2.p1;
    double d1=abs(cross(base,s1.p1-s2.p1));
    double d2=abs(cross(base,s1.p2-s2.p1));
    double t=d1/(d1+d2);
    return s1.p1+(s1.p2-s1.p1)*t;
}

int main(){
    int q;
    double a,b,c,d,e,f,g,h;
    cin>>q;
    Point p1,p2,p3,p4;
    for(int i=0;i<q;i++){
        cin>>a>>b>>c>>d>>e>>f>>g>>h;
        p1=Point(a,b);
        p2=Point(c,d);
        p3=Point(e,f);
        p4=Point(g,h);
        cout<<intersect(p1,p2,p3,p4)<<endl;
    }
}


Measured memory_bytes: 3220