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

int main() {
  int A, B, K, C=0;
  cin >> A >> B >> K;
  for (int i=min(A,B); i>=1; i--) {
    if (A%i==0 && B%i==0) {C++;}
    if (C==K) {
      cout << i << endl;
      break;
    }
  }
}



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

ll f(ll h){
	if(h==1) return 1;
	return (1+2*f(h/2));
}

int main(int argc, char const *argv[])
{
	ll h;
	cin>>h;
	cout<<f(h);
	return 0;
}

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

#define INF 100000000


int main() {
    
    string arr[3] = {"Sunny", "Cloudy", "Rainy"};
    string s; cin >> s;
    for(int i = 0; i < 3; i++) {
        if(s == arr[i]) {
            cout << arr[(i+1)%3] << endl;
        }
    }

    return 0;
}


Measured memory_bytes: 256
#!/usr/bin/env python3
import sys


def solve(s: str):
    a = []
    for c in s:
        if c == "B":
            if a:
                a.pop()
        else:
            a.append(c)
    return "".join(a)


# Generated by 1.1.7.1 https://github.com/kyuridenamida/atcoder-tools
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    s = next(tokens)  # type: str
    print(solve(s))

def test():
    import doctest
    doctest.testmod()

if __name__ == '__main__':
    #test()
    main()


Measured memory_bytes: 9088
#include <stdio.h>

int main(){

    int a, b;
    int counter=0;
    char postal[100];
    scanf("%d %d", &a, &b);
    scanf("%s", postal);
  //  printf("%c", postal);

    for(int i=0;i<(a+b+1);i++){
        if(postal[a]!='-'){
            printf("No\n");
            break;
        }
        if(postal[i]>=48 && postal[i]<=57){
//            printf("masuk if ni");
            counter++;
        }
        else if(postal[i]=='-' && i!=a){
            printf("No\n");
            break;
        }

    }
if(counter==(a+b)){
    printf("Yes\n");
}
 
 
 
    return 0;
}

Measured memory_bytes: 1624
#include <iostream>
#include <cstring>
#include <bitset>
#include <cstdio>
#define MN 101000

int h[MN], nxt[2 * MN], to[2 * MN], K = 1;
int iter[MN], used[MN];
int st[MN], top = 0; bool inq[MN];
int ans = 0; int d[MN];
std::bitset<100001> bs[2];

void ins(int u, int v) {nxt[++K] = h[u]; h[u] = K; to[K] = v;}

void dfs(int x)
{
	if(inq[x])
	{
		do {
			inq[st[top]] = 0;
			if(ans < 2) bs[ans][st[top]] = 1;
		} while(st[top--] != x);
		ans++;
	}
	st[++top] = x; inq[x] = 1;
	while(iter[x] && used[iter[x] / 2]) iter[x] = nxt[iter[x]];
	if(!iter[x])
	{
		if(top == 1) {top--; inq[x] = 0;}
		else ans = -2e9;
		return;
	}
	used[iter[x] / 2] = 1; dfs(to[iter[x]]);
}

int main()
{
	int n, m; scanf("%d%d", &n, &m);
	for(int i = 1; i <= m; i++)
	{
		int a, b; scanf("%d%d", &a, &b);
		ins(a, b); ins(b, a); d[a]++; d[b]++;
	}
	memcpy(iter, h, sizeof(iter));
	for(int i = 1; i <= n; i++)
		if(iter[i])
		{
			dfs(i);
			if(ans < -1e9) return 0 * puts("No");
		}
	if(ans >= 3 || ans == 2 && (bs[0] & bs[1]).count() >= 3) puts("Yes");
	else puts("No");
}

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

typedef complex<int> P;
const int INF = 1<<24;
vector<P> v[2502];
vector<int> cost[2502];
int N;

int dist(P a, P b) {
  return abs(a.real()-b.real()) + abs(a.imag()-b.imag());
}

int main() {
  int w, h;
  while(cin >> w >> h && (w || h)) {
    P g;
    int N = 0;
    for(int i = 0; i < 2502; ++i) {
      v[i].clear();
      cost[i].clear();
    }
    for(int i = 0; i < h; ++i) {
      for(int j = 0; j < w; ++j) {
	string c;
	cin >> c;
	if(c[0] != '.') {
	  if(c[0] == 'G') {
	    g.real() = j;
	    g.imag() = i;
	  } else {
	    if(c[0] == 'S') c = "0";
	    N = max(N, atoi(c.c_str()));
	    v[atoi(c.c_str())].push_back(P(j,i));
	  }
	}
      }
    }
    v[N+1].push_back(g);
    cost[0].push_back(0);
    for(int i = 1; i < N+2; ++i) {
      for(int j = 0; j < v[i].size(); ++j) {
	int value = INF;
	for(int k = 0; k < v[i-1].size(); ++k) {
	  value = min(value, cost[i-1][k]+dist(v[i-1][k],v[i][j]));
	}
	cost[i].push_back(value);
      }
    }
    cout << cost[N+1][0] << endl;
  }
  return 0;
}

Measured memory_bytes: 0
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, a, b) for (int i = a; i < b; i++)
//'A' = 65, 'Z' = 90, 'a' = 97, 'z' = 122

int main() {
    int n;
    cin >> n;
    int cnt[100001] = {};
    rep(i, 0, n) {
        int a;
        cin >> a;
        cnt[a]++;
    }

    int ans = 0;
    rep(i, 0, 100001 - 2) {
        ans = max(cnt[i] + cnt[i + 1] + cnt[i + 2], ans);
    }

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


Measured memory_bytes: 640
#include <bits/stdc++.h>
#define fastio ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define int int64_t
#define pb push_back
#define pf push_front
#define pii pair<int, int>
#define F first
#define S second
#define T  third
#define vecsort(x) sort(x.begin(), x.end())
#define vecrsort(x) sort(x.rbegin(), x.rend())
#define massort(x, n) sort(x, x + n)
using namespace std;
int max(int32_t a, int b){
   return max((int)a, b);
}
int max(vector<int> x){
    return *max_element(x.begin(), x.end());
}


int32_t main(){
    int n;
    cin >> n;
    vector<int> ar(n);
    cout.precision(10);
    cin >> ar[0];
    int mid = ar[0];
    for(int i = 1; i < n; i ++){
        cin >> ar[i];
        mid = (mid * ar[i]) / __gcd(ar[i], mid);
    }
    int cnt = 0;
    for(int i = 0; i < n; i ++){
        cnt += mid / ar[i];
    }
    cout << fixed << (double)mid / (double)cnt;
}




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

int main(){
  string s,ans="";
  cin>> s;
  for(int i=0;i<s.size();i++){
    if(s[i]=='A') ans+='X';
    else if(s[i]=='B') ans+= 'Y'; 
    else if(s[i]=='C') ans+= 'Z';
    else ans+=s[i]-3;
  }
  cout<< ans<< endl;
}

Measured memory_bytes: 1192
import sys

sys.setrecursionlimit(10 ** 8)

input = sys.stdin.readline


def main():
    N = int(input())
    A = [int(x) for x in input().split()]
    B = [int(x) for x in input().split()]

    acnt = 0
    bcnt = 0

    for i in range(N):
        if A[i] == B[i]:
            continue
        elif A[i] > B[i]:
            bcnt += A[i] - B[i]
        else:
            acnt += -(-(B[i] - A[i]) // 2)
            bcnt += (B[i] - A[i]) % 2

    if acnt < bcnt:
        print("No")
    else:
        print("Yes")


if __name__ == '__main__':
    main()



Measured memory_bytes: 10484
def fibonacci(N):
    a = 1
    b = 2
    c = 0

    if N <= 1:
        return 1
    elif N == 2:
        return 2
    else:
        for i in range(N-2):
            c = a+b
            a = b
            b = c
    return c


def main():
    N,M = map(int,input().split())
    A = [int(input()) for _ in range(M)]

    temp = 1
    for i in range(M+1):
        if M == 0:
            temp = fibonacci(N)
            break
        else:
            if i == 0:
                num = fibonacci(A[i]-1)
            else:
                if i <= M-1:
                    if A[i-1] == A[i]-1:
                        print(0)
                        return
                    num = fibonacci(A[i]-A[i-1]-2)
                else:
                    num = fibonacci(N-A[i-1]-1)
        temp *= num
    print(temp%1000000007)


if __name__ == '__main__':
    main()


Measured memory_bytes: 7080
#include <bits/stdc++.h>
typedef long long ll;
const int INF=1e9,MOD=1e9+7,ohara=1e6;
const ll LINF=1e18;
using namespace std;

#define rep(i,n) for(int (i)=0;(i)<(int)(n);(i)++)
#define rrep(i,a,b) for(int i=(a);i<(b);i++)
#define rrrep(i,a,b) for(int i=(a);i>=(b);i--)
#define all(v) (v).begin(), (v).end()
#define pb(q) push_back(q)
#define Size(n) (n).size()
#define Cout(x) cout<<(x)<<endl

ll n,cnt,ans,a,b,c,d,tmp,tmpp,m,h,w,x[ohara],y[ohara],sum,pos,lim=1;
int dy[]={1,0,-1,0};
int dx[]={0,1,0,-1};
//int dy[]={-1,0,1,-1,1,-1,0,1};
//int dx[]={-1,-1,-1,0,0,1,1,1};
string alph("abcdefghijklmnopqrstuvwxyz"),s;
bool visited[ohara];
struct edge{int to,cost;};
unordered_map<ll,ll> mp;

//-------------------------↓↓↓↓↓↓------------------------

int main(void){
       cin.tie(0);
    ios::sync_with_stdio(false);
      
    cin>>h>>w>>n;
    rep(i,n)cin>>x[i]>>y[i];
    rep(i,n){
        if(!visited[x[i]])mp[x[i]]=y[i],visited[x[i]]=true;
        else mp[x[i]]=min(mp[x[i]],y[i]);
    }
    ans=h;
    rrep(i,2,h+1){
        //cout<<i<<" "<<lim<<"\n";
        if(!visited[i]){
            lim++;
        }
        else{
        tmp=mp[i];
        //cout<<i<<" "<<tmp<<" "<<lim<<"\n";
        if(lim+1==tmp){
            continue;
        }
        else if(lim+1<tmp){
            lim++;
        }
        else{
            ans=i-1;
            break;
        }
        }
    }
    Cout(ans);
    return 0;
}


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

#define all(x) (x).begin(),(x).end()

#define MOD 1000000007

using namespace std;

int main(){
	int k;	cin >> k;
	string s;	cin >> s;
	bool dot = false;

	if( (int)s.length() - k > 0 )	dot = true;

	for( int i = 0; i < s.length() && k > 0; i++, k-- ){
		cout << s[i];
	}

	if( dot )	cout << "...";

	cout << endl;

	return 0;
}


Measured memory_bytes: 3624
#include <bits/stdc++.h> 
using namespace std;
#define endl "\n"
typedef long long int ll;
int main(){


    //freopen("in.txt", "r", stdin);  // for writing output to output.txt
   // freopen("out.txt", "w", stdout);
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    
    ll n ,m;
    cin>>n>>m;
  cout<<n*m<<endl;
       
        

    return 0;
    
}

Measured memory_bytes: 3652
#include <iostream>
using namespace std;
int main(void){
    int a,b;
    cin>>a>>b;
    if (a < b) {
        cout<<"a < b"<<endl;
    } else if (a > b) {
        cout<<"a > b"<<endl;
    }else {
        cout<<"a == b"<<endl;
    }
}



Measured memory_bytes: 3080
n, y = gets.split.map(&:to_i)

a = b = c = -1
valid = false

n.downto(0) do |i|
  break if valid

  (n - i).downto(0) do |j|
    k = n - i - j
    valid = 10_000 * i + 5_000 * j + 1_000 * k == y

    if valid
      a, b, c = [i, j, k]
      break
    end
  end
end

puts [a, b, c].join(" ")


Measured memory_bytes: 1788
#include <cstdio>

void CountingSort(int A[], int B[], int len, int maxNum)
{
	//选择排序算法中,　方便起见, 不使用index=0的位置 
	int C[maxNum+1];
	
	for (int i = 0; i <= maxNum; i++) {
		C[i] = 0;
	}
	for (int i = 1; i < len; i++) {
		C[A[i]]++;
	}
	for (int i = 1; i <= maxNum; i++) {
		C[i] += C[i-1];
	}
	
	//从A[]的末尾开始选择,　是为了保证算法的稳定性 
	for (int i = len-1; i >= 1; i--) {
		B[C[A[i]]] = A[i];
		C[A[i]]--;
	}
}

int main(void)
{
	//选择排序算法中,　方便起见, 不使用index=0的位置 
	int n;
	int max = -999999999;
	
	scanf("%d", &n);
	int A[n+1];
	int B[n+1];
	
	for (int i = 1; i <= n; i++) {
		scanf("%d", &A[i]);
		if (A[i] > max) {
			max = A[i];
		}
	}
	CountingSort(A, B, n+1, max);
	for (int i = 1; i <= n; i++) {
		if (i > 1) {
			printf(" ");
		}
		printf("%d", B[i]);
	}
	printf("\n");
	
	
	return 0;
} 


Measured memory_bytes: 18256
#![allow(unused_imports, dead_code)]
use std::f64::*;
use std::cmp::*;
use std::collections::*;

macro_rules! dump{
    ($($a:expr),*) => {
        println!(concat!($(stringify!($a), " = {:?}, "),*), $($a),*);
    }
}

const INF: i64 = 0x3f3f3f3f3f3f3f3f;
const MOD: i64 = 1000000007;
const NOTHING: usize = std::usize::MAX;
const DX: [usize; 4] = [1, 0, std::usize::MAX, 0];
const DY: [usize; 4] = [0, 1, 0, std::usize::MAX];

fn main() {
    let n: usize = readln();
    let xs: Vec<usize> = readln();
    let mut freq: Vec<usize> = vec![0;100001];
    for i in 0..n {
        freq[xs[i]] += 1;
    }
    let mut res = 0;
    for i in 0..99999 {
        res = max(res, freq[i] + freq[i + 1] + freq[i + 2]);
    }
    println!("{}", res);
}

trait Read {
    fn read(s: &str) -> Self;
}

fn readln<T: Read>() -> T {
    let mut buf = String::new();
    std::io::stdin().read_line(&mut buf).unwrap();
    T::read(buf.trim_right())
}

macro_rules! read_impl{
    ($($t:ty)*) => ($(
        impl Read for $t {
            fn read(s: &str) -> $t{
                s.parse().unwrap()
            }
        }
    )*)
}
read_impl! { usize u8 u16 u32 u64 isize i8 i16 i32 i64 f32 f64 }

impl Read for String {
    fn read(s: &str) -> Self {
        s.to_string()
    }
}

impl Read for Vec<char> {
    fn read(s: &str) -> Self {
        s.chars().collect()
    }
}

impl<T: Read> Read for Vec<T> {
    fn read(s: &str) -> Self {
        s.split_whitespace().map(T::read).collect()
    }
}

impl<A: Read, B: Read> Read for (A, B) {
    fn read(s: &str) -> Self {
        let tokens: Vec<_> = s.split_whitespace().collect();
        (A::read(tokens[0]), B::read(tokens[1]))
    }
}

impl<A: Read, B: Read, C: Read> Read for (A, B, C) {
    fn read(s: &str) -> Self {
        let tokens: Vec<_> = s.split_whitespace().collect();
        (A::read(tokens[0]), B::read(tokens[1]), C::read(tokens[2]))
    }
}

impl<A: Read, B: Read, C: Read, D: Read> Read for (A, B, C, D) {
    fn read(s: &str) -> Self {
        let tokens: Vec<_> = s.split_whitespace().collect();
        (A::read(tokens[0]), B::read(tokens[1]), C::read(tokens[2]), D::read(tokens[3]))
    }
}


Measured memory_bytes: 6396
#include <bits/stdc++.h>
using namespace std;
int main(){
    long n;
    cin >> n;
    if(n < 3){
        cout << 1;
        exit(0);
    }

    // vector<int> vec(n);
    // for(int i = 0; i < n; i++){
    //     cin >> vec.at(i);
    // }
    //
    // int increase, cnt;
    // cnt = 1;
    //
    // increase = vec.at(1) - vec.at(0);
    //
    // for(int i = 2; i < n; i++){
    //     int new_inc = vec.at(i) - vec.at(i-1);
    //     if(increase * new_inc < 0){
    //         cnt++;
    //         increase = 0;
    //     }
    //     else if(increase == 0){
    //         increase = new_inc;
    //     }
    // }

    long a1, a2, inc, prev, cnt;
    cin >> a1 >> a2;
    inc = a2 - a1;
    prev = a2;
    cnt = 1;
    for(long i = 0; i < n-2; i++){
        long val, ninc;
        cin >> val;
        ninc = val - prev;
        if(inc * ninc < 0){
            cnt++;
            inc = 0;
        }
        else if(inc == 0){
            inc = ninc;
        }
        prev = val;
    }
    cout << cnt;
}


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

int main(){
    ll a,b;
    cin >> a >> b;
    if(a<=0 && b >= 0){
        cout << "Zero" << endl;
        return 0;
    }
    if(a>0){
        cout << "Positive"<< endl;
        return 0;
    }
    if(b>0 && abs(a)%2 == 0){
        cout << "Positive"<< endl;
        return 0;
    }
    if((b-a+1)%2 == 0){
        cout << "Positive"<< endl;
        return 0;
    }
    cout << "Negative" << endl;
    return 0;
}

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

typedef long long ll;
typedef pair<ll, ll> pll;
const ll mod=1000000007;
const char nl='\n';


void solve(){
    ll i,j,k,l,m,n;
    string s,t;
    cin>>s>>t;
    n=(ll)s.size();
    m=(ll)t.size();
    vector<vector<int> > dp(n+1, vector<int>(m+1,0));
    for(i=1;i<=n;i++){
        for(j=1;j<=m;j++){
            dp[i][j]= max({dp[i][j-1],dp[i-1][j], (int)(s[i-1]==t[j-1])+dp[i-1][j-1]});
        }
    }

//    for(auto x:dp){
//        for(auto y:x) cout<<y<<" ";cout<<nl;
//    }
    string ans="";
    i=n;
    for(j=m;j&&i;j--){
        if(dp[i][j]==dp[i][j-1]) continue;
        if(dp[i][j]==dp[i-1][j]) i--,j++;
        else if(dp[i-1][j-1]+1==dp[i][j]){
            ans+=t[j-1];
            i--;
        }
    }
    reverse(ans.begin(),ans.end());
    cout<<ans<<nl;
}

int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	int t = 1,i=1;
//    cin >> t;
	while (t--)
	{
//	    cout<<"Case #"<< i++ <<": ";
		solve();
	}
	return 0;
}



Measured memory_bytes: 38504
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.StringTokenizer;
import java.io.IOException;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.InputStream;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 */
public class Main {
	public static void main(String[] args) {
		InputStream inputStream = System.in;
		OutputStream outputStream = System.out;
		FastScanner in = new FastScanner(inputStream);
		PrintWriter out = new PrintWriter(outputStream);
		ProblemB solver = new ProblemB();
		solver.solve(1, in, out);
		out.close();
	}

	static class ProblemB {
		public void solve(int testNumber, FastScanner in, PrintWriter out) {
			int k = in.nextInt();
			long[] a = new long[k];
			for (int i = 0; i < k; i++) {
				a[i] = in.nextInt();
			}
			if (a[k - 1] != 2) {
				out.println(-1);
				return;
			}
			long l = 2;
			long r = 3;
			for (int i = k - 2; i >= 0; i--) {
				long min = (l + a[i] - 1) / a[i] * a[i];
				long max = r / a[i] * a[i];
				l = min;
				r = max + a[i] - 1;
			}
			if (l > r) {
				out.println(-1);
			} else {
				out.println(l + " " + r);
			}
		}

	}

	static class FastScanner {
		private BufferedReader in;
		private StringTokenizer st;

		public FastScanner(InputStream stream) {
			in = new BufferedReader(new InputStreamReader(stream));
		}

		public String next() {
			while (st == null || !st.hasMoreTokens()) {
				try {
					String rl = in.readLine();
					if (rl == null) {
						return null;
					}
					st = new StringTokenizer(rl);
				} catch (IOException e) {
					throw new RuntimeException(e);
				}
			}
			return st.nextToken();
		}

		public int nextInt() {
			return Integer.parseInt(next());
		}

	}
}



Measured memory_bytes: 40828
import java.util.*;
import java.math.*;
import java.lang.*;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		// 整数の入力
		int n = sc.nextInt();
		String s = sc.next();

		int numR = 0;
		int numB = 0;

		for (int i = 0; i < n; i++) {
			String si = s.substring(i, i + 1);
			if (si.equals("B")) {
				numB++;
			} else {

				numR++;
			}
		}

		if (numR > numB) {
			System.out.println("Yes");
		} else {
			System.out.println("No");
		}

	}
}


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

using namespace std;
int main()
{
    string a ;
    cin >> a ;

    if( a[ 0 ] == a[ 1 ] ){
        cout << " No " ;
        return 0 ;
    }
    else
        if ( a[ 0 ] == a[ 2 ]){
           cout << " No " ;
           return 0 ;
        }
        else
        if ( a[ 1 ] == a[ 2 ] ){
            cout << " No " ;
            return 0 ;
        }
        else
            cout << " Yes " ;

    return 0;
}


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

using namespace std;

const int N = int(1e5 + 10);
int p[N];
int q[N];
int r[N];

int bs(int *v, int st, int en, int val){
	int r = -1;

	while(st <= en){
		int mid = (st + en) >> 1;

		if(v[mid] <= val){
			r = v[mid];
			
		}
	}

	return r;
}

int main(){
	int x, y, a, b, c;

	scanf("%d %d %d %d %d", &x, &y, &a, &b, &c);

	for(int i = 0 ; i < a ; i++){
		scanf("%d", &p[i]);
	}

	for(int i = 0 ; i < b ; i++){
		scanf("%d", &q[i]);
	}

	for(int i = 0 ; i < c ; i++){
		scanf("%d", &r[i]);
	}

	sort(p, p + a);
	sort(q, q + b);
	sort(r, r + c);

	priority_queue< int > f1, f2;

	for(int i = a - x ; i < a ; i++){
		f1.push(-p[i]);
		// printf("++%d\n", p[i]);
	}

	for(int i = b - y ; i < b ; i++){
		f2.push(-q[i]);
		// printf("+%d\n", q[i]);
	}

	for(int k = c - 1 ; k >= 0 ; k--){
		int t1 = -f1.top();
		int t2 = -f2.top();

		if(min(t1, t2) >= r[k]){
			break;
		}else{
			if(t1 > t2){
				f2.pop();
				f2.push(-r[k]);
			}else{
				f1.pop();
				f1.push(-r[k]);
			}
		}
	}

	long long sum = 0LL;

	while(!f1.empty()){
		sum += -f1.top();
		f1.pop();
	}

	while(!f2.empty()){
		sum += -f2.top();
		f2.pop();
	}

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

	return 0;
}

Measured memory_bytes: 2552
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define rep1(i,n) for(int i=1;i<=(int)(n);i++)
#define all(c) c.begin(),c.end()
#define pb push_back
#define fs first
#define sc second
#define show(x) cout << #x << " = " << x << endl
#define chmin(x,y) x=min(x,y)
#define chmax(x,y) x=max(x,y)
using namespace std;
template<class S,class T> ostream& operator<<(ostream& o,const pair<S,T> &p){return o<<"("<<p.fs<<","<<p.sc<<")";}
template<class T> ostream& operator<<(ostream& o,const vector<T> &vc){o<<"sz = "<<vc.size()<<endl<<"[";for(const T& v:vc) o<<v<<",";o<<"]";return o;}
const int MN = 100000;
int N;
vector<int> G[MN];

int dfs(int v){
	vector<int> chs;
	for(int u:G[v]) chs.pb(dfs(u));
	sort(all(chs));
	reverse(all(chs));
	int ret = 0;
	int K = chs.size();
	rep(i,K) chmax(ret,chs[i]+i);
	return ret+1;
}
int main(){
	cin>>N;
	rep(i,N-1){
		int p;
		cin>>p;
		p--;
		G[p].pb(i+1);
	}
	cout<<dfs(0)-1<<endl;
}


Measured memory_bytes: 13568
#include <bits/stdc++.h>
using namespace std;
 
#define S size()
#define E end()
#define B begin()
#define L length()
 
#define endl "\n"
#define cnt count
#define in insert
#define er erase
#define fi first
#define se second
#define fl float
#define ld long double
#define ll long long

#define gcd __gcd
#define mp make_pair
#define pb push_back
#define popb pop_back()
#define pf push_front
#define popf pop_front()
#define all(v) v.B,v.E
#define acc(v) accumulate(all(v), 0)
#define psum partial_sum
#define lb lower_bound
#define ub upper_bound
#define bs binary_search
#define np next_permutation
#define maxe *max_element
#define mine *min_element
 
#define forl(i,n) for(ll i = 0; i < n; i++)
#define fore(i,m,n) for (ll i = m; i <= n; i++)
#define rforl(i,n) for (ll i = n - 1; i >= 0; i--)
#define rfore(i,m,n) for (ll i = m; i >=n; i--)    
#define iter(s) for(auto it:s)
 

#define prec(n) fixed<<setprecision(n)
#define popcnt(n) __builtin_popcountll(n)
#define parity(n) __builtin_parityll(n)
#define clz(n) __builtin_clzll(n)
#define ctz(n) __builtin_ctzll(n)

#define sll set<ll>
#define sc set<char>
#define mll map<ll,ll>
#define vll vector<ll>
#define vc vector<char>
#define pll pair<ll,ll>
#define vpll vector<pll>
#define msll multiset<ll>
#define msc multiset<char>
#define vvll vector<vector<ll>>
#define rev reverse

#define tc ll q;cin>>q;while(q--)
#define pat ll n;cin>>n
#define pat1 vll a(n);forl(i,n)cin>>a[i]
#define pat2 ll n,k;cin>>n>>k;vll a;forl(i,n) cin>>a[i]
#define pats string s;cin>>s
#define yesno if(flag)cout<<"YES\n";else cout<<"NO\n"
#define loop forl(i,n)

#define p0(a) cout << a << " "
#define p1(a) cout << a << endl
#define p2(a,b) cout << a << " " << b << endl
#define p3(a,b,c) cout << a << " " << b << " " << c << endl
#define p4(a,b,c,d) cout << a << " " << b << " " << c << " " << d << endl
 
#define MAX LLONG_MAX
#define MIN LLONG_MIN
#define mod1 1000000007
#define mod2 998244353
#define PI 3.1415926535897932384626433832
//**********************************
 
int main(){
    
    ll x,k,d;
    cin>>x>>k>>d;
    if(x<0){
        x=abs(x);
    }
    if(x==0){
        if(k%2==0){
            p1(0);
        }else{
            p1(d);
        }
    }else if(x>0){
        ll ans=MAX;
        if(k%2==0){
            ll coeff=x/(2*d);
            if(coeff<=k/2){
                ans=abs(x-2*coeff*d);
            }
            if(coeff+1<=k/2){
                ans=min(ans,abs(x-2*(coeff+1)*d));
            }
            if(coeff>k/2){
                ans=abs(x-(k/2)*2*d);
            }
            p1(ans);
        }else{
            x=x-d;
            k-=1;
            ll coeff=x/(2*d);
            if(coeff<=k/2){
                ans=abs(x-2*coeff*d);
            }
            if(coeff+1<=k/2){
                ans=min(ans,abs(x-2*(coeff+1)*d));
            }
            if(coeff>k/2){
                ans=abs(x-(k/2)*2*d);
            }
            p1(ans);
        }
    }
}

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

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


Measured memory_bytes: 256
// Problem: Security
// Contest: Virtual Judge - AtCoder
// URL: https://vjudge.net/problem/AtCoder-abc131_a#author=0
// Memory Limit: 1048 MB
// Time Limit: 2000 ms
// Powered by CP Editor (https://github.com/cpeditor/cpeditor)

//#pragma GCC optimize("Ofast,no-stack-protector,unroll-loops,fast-math")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4.1,sse4.2,avx,avx2,popcnt,tune=native")
//
//#include <immintrin.h>
//#include <emmintrin.h>

#include <bits/stdc++.h>
//#pragma GCC optimize("O2")
#define vi vector<int>
#define pii pair<int, int >
#define mp make_pair
#define fi first
#define se second
#define pb push_back
#define LL long long
#define rep(i,a,n) for (int i=a;i<=n;i++)
#define per(i,a,n) for (int i=n;i>=a;i--)
#define all(x) (x).begin(), (x).end()
#define all2(x,n) (x+1), (x+1+n)
#define sz(x) ((int)(x).size())
#define mod(x) ((x)%MOD)
#define debug(x) cerr<<#x<<" : "<<x<<endl
#define mt make_tuple
#define eb emplace_back
#define o(X) (1<<(X))
#define oL(X) (1LL<<(X))
#define contain(S,X) (((S)&o(X))!=0)
#define containL(S,X) (((S)&oL(X))!=0)
#define ppt(x) __builtin_popcount(x)
using namespace std;
const int INF=0x3f3f3f3f,N=5e6+5,MOD=1e9+7;
const LL INF_LL=0x3f3f3f3f3f3f3f3fLL;
inline int getplc(int x,int y) { return (x>>y)&1; }
template<typename T>
T square(T x) {return x*x;}
LL qpow(LL a,LL b=MOD-2,LL _MOD=MOD){
	LL res=1;
	for(;b;b>>=1,a=a*a%_MOD){
		if(b&1)res=res*a%_MOD;
	}
	return res;
}
// Smax
//int Smax() { return -INF; }
template <typename T>
T Smax(T x) { return x; }
template<typename T, typename... Args>
T Smax(T a, Args... args) { return max(a, Smax(args...)); }
// Smin
template <typename T>
T Smin(T x) { return x; }
template<typename T, typename... Args>
T Smin(T a, Args... args) { return min(a, Smin(args...)); }
template <typename T>
// erro
#define errorl(args...) { string _s = #args; replace(_s.begin(), _s.end(), ',', ' '); stringstream _ss(_s); istream_iterator<string> _it(_ss); errl(_it, args); }

void errl(istream_iterator<string> it) {}
template<typename T, typename... Args>
void errl(istream_iterator<string> it, T a, Args... args) {
	cerr << *it << " = " << a << endl;
	errl(++it, args...);
}

#define error(args...) { string _s = #args; replace(_s.begin(), _s.end(), ',', ' '); stringstream _ss(_s); istream_iterator<string> _it(_ss); err(_it, args); cerr<<endl;}
void err(istream_iterator<string> it) {}
template<typename T, typename... Args>
void err(istream_iterator<string> it, T a, Args... args) {
	cerr << *it << "=" << a << " # ";
	err(++it, args...);
}
void Solve();
int main() {
#ifndef ONLINE_JUDGE
//	freopen("in.txt","r",stdin);
//    freopen("o1.txt","w",stdout);
#endif
	ios::sync_with_stdio(false);cin.tie(0),cout.tie(0);
	Solve();
	return 0;
}

//////////////////////////////////////////////////////////////////

int a[N];
void Solve(){
  int n,suc=0;
  cin>>n;
  rep(i,1,4){
    a[i]=n%10;n/=10;
    if(i!=1&&a[i]==a[i-1])suc=1;
  }
  if(suc)cout<<"Bad"<<endl;
  else cout<<"Good"<<endl;
  
} 


Measured memory_bytes: 3624
use std::cmp::min;
use std::io::stdin;

fn main() {
    let mut s = String::new();
    stdin().read_line(&mut s).ok();
    let mut itr = s.split_whitespace().map(|e| e.parse().unwrap());
    let n: i64 = itr.next().unwrap();
    let k: i64 = itr.next().unwrap();

    let a = n / k;
    println!("{}", min((n - a * k).abs(), (n - (a + 1) * k).abs()));
}


Measured memory_bytes: 4352
#include<stdio.h>
#include<stdlib.h>
#define ll long long
#define rep(i,l,r)for(ll i=(l);i<(r);i++)

int main(){
	ll n,k;
	scanf("%lld%lld",&n,&k);
	ll ans=0;
	rep(i,1,n){
		ll temp=ans+ans/(k-1);
		if(temp%k==0)temp++;
		if(temp-temp/k-1!=ans)temp++;
		ans=temp;
	}
	printf("%lld\n",ans);
}


Measured memory_bytes: 2108
import java.util.*;
import java.lang.*;
import java.math.*;
import java.io.*;
public class Main
{
public static void main(String args[]) throws java.lang.Exception
{
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 dp[]=new int[n];
  dp[0]=0;
  dp[1]=Math.abs(a[1]-a[0]);
  for(int i=2;i<n;i++)
    dp[i]=Math.min(Math.abs(a[i]-a[i-2])+dp[i-2],Math.abs(a[i]-a[i-1])+dp[i-1]);
  System.out.println(dp[n-1]);
}
}

Measured memory_bytes: 49556
#include <stdio.h>
#include <string.h>
 
int main(){
  char a[]="6 7 8 9 5 4 3 2 1 0 1 2 3 4 5 6 7 8 9";
  char *b,*c,*d,e,f;
  int h,i;
  scanf("%d\n",&h);
  for(i=0;i<h;i++){
    scanf("%c %c\n",&e,&f);
    b=strchr(a,e);
    c=strchr(b+1,e);
    d=strchr(b+1,f);
    if(c==NULL || c>d)c=b;
    for(;c<=d;c++) printf("%c",c[0]); printf("\n");
  }
  return 0;
}

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

using namespace std;

using intL = long long;

#define MOD_NUMBER 1000000007

template <class T> void vector_print(vector<T> vec) {
  for (unsigned int i = 0; i < vec.size(); i++) {
    cout << vec.at(i);
    if (i < vec.size()-1) {
      cout << " ";
    } else if (i == vec.size()-1) {
      cout << endl;
    }
  }
}

int main() {
  int n, ans = 0;
  cin >> n;
  vector<int> a(n);
  for (int i = 0; i < n; i++) {
    cin >> a[i];
  }
  sort(a.begin(), a.end());
  for (int i = 0; i < n-1; i++) {
    if (a[i] == a[i+1]) {
      cout << "NO" << endl;
      return 0;
    }
  }
  cout << "YES" << endl;
  return 0;
}


Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
#define pb push_back
#define mp make_pair
#define F first
#define S second
//-std=c++11
#define print(x) printf("%.12f",x);
#define sz(x) (int)x.size()
#define all(x) (x).begin(), (x).end()
#define Red ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
#define rep(i, n) for(int i =0 ; i < n; ++i)
#define repr(i, n) for(int i=n-1;i>=0;i--)
#define Rep(i,a,b) for(int i=a;i<=b;i++)
#define Repr(i,a,b) for(int i=a;i>=b;i--)
#define pii pair < int, int >
#define iter ::iterator
#define forit(a) for(it=a.begin();it!=a.end();it++)
typedef vector<int> vi;
typedef  long long ll;
const int inf = int(1e9);
const int mod = inf + 7;
const int N = (int)2e5 + 5;
void solve(){
	int a,b;
	cin>>a>>b;
	cout<<(a==b?"Yes":"No");
}


int main(){
	Red;
	int t=1;
	//cin>>t;
	while(t--)
	solve();
	return 0;
}

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

int main(void){
    char b;
    cin>>b;
    if(b=='A')
        b='T';
    else if(b=='T')
        b='A';
    else if(b=='G')
        b='C';
    else if(b=='C')
        b='G';

    cout<<b<<endl;

    return 0;
}


Measured memory_bytes: 256
#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[i];
    }
    sort(s.begin(), s.end());
    for (int i = 0; i < n; i++) {
        cout << s[i];
    }
    cout << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>#include <algorithm>
#include <cstdlib>
#include <cmath>
using namespace std;
int main(){
  int a = 0;
  int b = 0;
  cin >> a >> b;
  if(a == b){
    cout << "Yes" << endl;
  }
  else{
    cout << "No" << endl;
  }
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
typedef long long ll;
using namespace std;
int main(){
    cin.tie(NULL); cout.tie(NULL);
    ios_base:: sync_with_stdio(false);
    ll n,a,b;cin>>n>>a>>b;
    cout<< ( (b-a)%2?"Borys":"Alice" );
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define REP(i,n) for(ll i=0, i##_len=(n); i<i##_len; ++i)
#define REPR(i,n) for(ll i = n;i >= 0;--i)
#define FOR(i,m,n) for(ll i = m, i##_len=(n);i <i##_len; ++i)
#define all(x) (x).begin(),(x).end()
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; }
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
const int INF = 1e9;
const ll LLINF = 1e16;
 
ll modinv(ll a, ll m) {
    ll b = m, u = 1, v = 0;
    while (b) {
        ll t = a / b;
        a -= t * b; swap(a, b);
        u -= t * v; swap(u, v);
    }
    u %= m;
    if (u < 0) u += m;
    return u;
}

int main(void)
{
    int a,b;
    cin >> a >> b;
    vector<int> cnt(3, 0);
    cnt[a - 1]++;
    cnt[b - 1]++;

    REP(i,3){
        if(cnt[i] == 0){
            cout << i + 1 << endl;
            break;
        }
    }

    return 0;
}

Measured memory_bytes: 256
import java.util.*;
public class Main {

  public static void main(String[] args) { 
      Scanner sc = new Scanner(System.in);
      long h = sc.nextInt();
      long w = sc.nextInt();
      
      if(h == 1 || w == 1) {
        System.out.println(1);
        return;
      }
      long res = w * (h / 2);
      if(h % 2 == 1) {
        res += (w + 1) / 2;
      }
      System.out.println(res);
  }
}

Measured memory_bytes: 21972
#include<cstdio>
#include<cstring>
#define mod 1000000007
using namespace std;
char s[10010];
int n,d,dp[10010][100]={},num[10001],ans=0,sum=0;
int main(){
    scanf("%s",s);
    scanf("%d",&d);
    n=strlen(s);
    for(int i=0;i<n;i++){
        num[i]=s[i]-'0';
    }
    dp[0][0]=1;
    for(int i=1;i<=n;i++){
        for(int j=0;j<10;j++){
            for(int k=0;k<d;k++){
                dp[i][(j+k)%d]+=dp[i-1][k];
                dp[i][(j+k)%d]%=mod;
            }
        }
    }
    for(int i=n;i>0;i--){
        for(int j=0;j<=num[n-i];j++){
            if(j!=num[n-i]){
                ans+=dp[i-1][(d*100-j-sum)%d];
                ans%=mod;
            }
            else if(i==1){
                ans+=dp[i-1][(d*100-j-sum)%d];
                ans%=mod;
            }
        }
        sum+=num[n-i];
        sum%=d;
    }
    ans+=mod-1;
    ans%=mod;
    printf("%d\n",ans);
}

Measured memory_bytes: 4224
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rrep(i, n) for (int i = (int)(n); i >= 0; i--)
#define FOR(i, m, n) for(int i = m; i < n; i++)	
#define SORT(c) sort((c).begin(),(c).end())
#define REVERSE(c) reverse((c).begin(),(c).end())
#define REVSORT(c) SORT(c);REVERSE(c)
#define ALL(x) (x).begin(),(x).end()
#define LOOP while(true)
#define INF 1e9
const long long MOD = 1000000007;
typedef long long ll;

int func(string S, int K){
	map<char, bool> mp;
	int cnt = 0;
	for(int i = 0; i < K; i++){
		if(mp.count(S[i]))continue;
		else mp[S[i]] = true;
	}
	for(int i = K; i < S.size(); i++){
		if(mp.count(S[i]) && mp.at(S[i])){
			cnt++;
			mp.at(S[i]) = false;
		} else {
			continue;
		}
	}
	return cnt;
}

int main(){
	int N;
	string S;
	cin >>N >> S;
	int ans = 0;
	for(int i = 1; i < N - 1; i++){
		int A = func(S, i);
		if(A > ans)ans = A;
	}
	cout << ans << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
 using namespace std;
#define rep(i,n) for(int i=0;i<n;i++)
 int main(){
   string s;
   int a;
   cin>>s;
   if(s=="SUN")a=7;
   if(s=="MON")a=6;
   if(s=="TUE")a=5;
   if(s=="WED")a=4;
   if(s=="THU")a=3;
   if(s=="FRI")a=2;
   if(s=="SAT")a=1;
   cout<<a<<endl;    
}


Measured memory_bytes: 256
#include <iostream>
#include <array>
#include <algorithm>
#include <vector>
#include <bitset>
#include <set>
#include <unordered_set>
#include <cmath>
#include <complex>
#include <deque>
#include <iterator>
#include <numeric>
#include <map>
#include <unordered_map>
#include <queue>
#include <stack>
#include <string>
#include <tuple>
#include <utility>
#include <limits>
#include <iomanip>
#include <functional>
#include <cassert>
using namespace std;

using ll=long long;
template<class T> using V = vector<T>;
template<class T, class U> using P = pair<T, U>;
using vll = V<ll>;
using vvll = V<vll>;
#define rep(i, k, n) for (ll i=k; i<(ll)n; ++i)
#define REP(i, n) rep(i, 0, n)
#define ALL(v) v.begin(),v.end()
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; }
#define DEBUG_VLL(vec) REP(sz, vec.size()) std::cerr<<vec[sz]<<(sz==vec.size()-1?'\n':' ');

const long long MOD = 1000000007;
const long long HIGHINF = (long long)1e18;
const int INF = (int)1e9;

ll n;
map<ll, ll> am;

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    cin >> n;
    for (ll i = 0; i < n; i++) {
        ll a; cin >> a;
        am[a]++;
    }
    
    ll ans = 0;
    while (!am.empty()) {
        ll la = (*am.rbegin()).first;
        am[la]--;
        if (am[la] == 0) am.erase(la);
        ll p = 1;
        while (p <= la) p <<= 1;
        ll pa = p - la;
        if (am.find(pa) != am.end()) {
            ans++;
            am[pa]--;
            if (am[pa] == 0) am.erase(pa);
        }
    }
    cout << ans << '\n';
    return 0;
}


Measured memory_bytes: 12800
import java.util.*;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
 
public class Main {
    public static void main(String[] args) throws Exception {
        BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
        String line = reader.readLine();
        String[] abc = line.split(" ", 0);
        
        int A = Integer.parseInt(abc[0]);
        int B = Integer.parseInt(abc[1]);
        int X = Integer.parseInt(abc[2]);
        
        if(X >= A && A + B >= X){
            System.out.println("YES");
        }else{
            System.out.println("NO");
        }
    }
}

Measured memory_bytes: 23124
#include<bits/stdc++.h>
//#pragma comment(linker, "/STACK:102400000,102400000")
#include <stdio.h>
#include <iostream>
#include <iomanip>
#include <fstream>
#include <string.h>
#include <stdlib.h>
#include <time.h>
#include <limits.h>
#include <math.h>
#include <algorithm>
#include <deque>
#include <queue>
#include <stack>
#include <list>
#include <map>
#include <set>
#include <utility>
#include <sstream>
#include <complex>
#include <string>
#include <vector>
#include <bitset>
#include <functional>
using namespace std;
typedef long long LL;
typedef unsigned long long ULL;
typedef double db;
typedef long double ldb;
#define rep(i,a,b) for(i=a;i<b;i++)
#define repu(i,a,b) for(i=a;i<=b;i++)
#define repd(i,a,b) for(i=a;i>=b;i--)
#define repc(i,a,b,c) for(i=a;i<b;i+=c)
#define repcu(i,a,b,c) for(i=a;i<=b;i+=c)
#define repcd(i,a,b,c) for(i=a;i>=b;i-=c)
#define FIN freopen("input.in","r",stdin)
#define FOUT freopen("output.out","w",stdout)
#define CC(a) memset(a,0,sizeof(a))
#define MST(a,b) memset(a,b,sizeof(a))
#define PII pair<int,int>
#define PLL pair<long long,long long>
#define VI vector<int>
#define VL vector<long long>
#define VII vector<PII>
#define VLL vector<PLL>
#define all(x) x.begin(),x.end()
#define mp make_pair
#define pb push_back
#define pf push_front

template<typename T>inline void gn(T &x){
	x=0;T f=1;char ch=getchar();
	while(!isdigit(ch)){if(ch=='-')f=-1;ch=getchar();}
	while(isdigit(ch)){x=x*10+ch-'0';ch=getchar();}
	x*=f;
}
template<typename T>inline void gt(T x){
	if(!x)return;
	gt(x/10);putchar(x%10+'0');
}

const LL N=1e6+5;
struct NODE{
	LL i,r,c,num;
}tt,ss;
LL t,n,m,q,ans;
LL MOD=1e9+7,inf=0x1f1f1f1f;
db eps=1e-5;
map<LL,LL> ma;
LL a[55],dp[55][55][2555];

int main()
{
//	ios_base::sync_with_stdio(false);cin.tie(0);
	LL i,j,k,l,ca=0,u,v,tmp;
	cin>>n>>m;
	repu(i,1,n)cin>>a[i];
	repu(i,0,n)dp[i][0][0]=1;
	
	for(i=1;i<=n;i++){
		for(j=i+1;j;j--){
			for(k=0;k<=2500-a[i];k++){
				dp[i][j][k+a[i]]+=dp[i-1][j-1][k];
			}
			for(k=0;k<=2500;k++){
				dp[i][j][k]+=dp[i-1][j][k];
			}
		}
	}

	for(k=1;k<=n;k++){
		ans+=dp[n][k][k*m]; 
	}
	
	cout<<ans<<endl;
	return 0;
}

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

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; }
const ll INF = 1LL << 60;

//---main---------------------------------------------
int main(){
    //main
    int N;
    cin >> N;
    vector<int> A(N),updown(N+1);
    updown[0] = -1; updown[N] = -1;
    cin >> A[0];
    for(int i=1; i<N ; i++){
        cin >> A[i];
        if(A[i] > A[i-1]) updown[i] = 1;
        else if(A[i] < A[i-1]) updown[i] = -1;
    }

    ll ans = 1000;
    ll kabu = 0;
    int buy_sale = 1;
    rep(i,N+1){
        if(buy_sale == updown[i]){
            if(buy_sale == 1){
                //buy
                kabu += ans/A[i-1];
                ans = ans%A[i-1];
            }else{
                //sale
                ans += A[i-1]*kabu;
                kabu = 0;
            }
            buy_sale *= -1;
        }
    }
    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 3632
#include<bits/stdc++.h>
using namespace std;
#define fast ios::sync_with_stdio(false);cin.tie(0)
#define pb push_back
#define digit(x) floor(log10(x))+1
#define mod 1000000007
#define L_MAX 1e18
using ll = long long;
using ld = long double;
using ii = pair<ll,ll>;
using iii = tuple<ll,ll,ll>;
using matrix = vector<vector<ll>>;
using arr = vector<ll>;
using vs = vector<string>;
using pv = vector<ii>;
using umap = unordered_map<ll,ll>;
#define in1(x) scanf("%lld",&x)
#define in2(x,y) scanf("%lld %lld",&x,&y)
#define in3(x,y,z) scanf("%lld %lld %lld",&x,&y,&z)
#define all(x) x.begin(),x.end()
#define debug(x) cerr << #x << " is " << x << endl;
void showArr(arr a){
    for(auto i : a) cout<<i<<" ";
    cout<<endl;
}
ll dx[]={-1,1,-1,1,0,0,-1,1};
ll dy[]={-1,1,0,0,-1,1,1,-1};
ll Solve(ll index,ll n,arr a,arr b,arr c,ll last,ll dp[][4]){
    if(index>=n)
        return 0;
    if(dp[index][last]!=-1)
        return dp[index][last];
    dp[index+1][1]=Solve(index+1,n,a,b,c,1,dp);
    dp[index+1][2]=Solve(index+1,n,a,b,c,2,dp);
    dp[index+1][3]=Solve(index+1,n,a,b,c,3,dp);
    if(last==1)
        return dp[index][last]=max(dp[index+1][2]+b[index],dp[index+1][3]+c[index]);
    if(last==2)
        return dp[index][last]=max(dp[index+1][1]+a[index],dp[index+1][3]+c[index]);
    if(last==3)
        return dp[index][last]=max(dp[index+1][2]+b[index],dp[index+1][1]+a[index]);
    return dp[index][last]=max({dp[index+1][2]+b[index],dp[index+1][1]+a[index],dp[index+1][3]+c[index]});
}
int main(){
    fast;
    ll n;
    arr a,b,c;
    cin>>n;
    for(int i=0;i<n;i++){
        ll x,y,z;
        cin>>x>>y>>z;
        a.pb(x),b.pb(y),c.pb(z);
    }
    /*ll dp[100009][4];
    memset(dp,-1,sizeof(dp));
    cout<<Solve(0,n,a,b,c,0,dp)<<endl;*/
    ll dp[100009][4];
    dp[n][1]=0,dp[n][2]=0,dp[n][3]=0;
    for(int i=n-1;i>=0;i--){
        dp[i][1]=max(dp[i+1][2]+b[i],dp[i+1][3]+c[i]);
        dp[i][2]=max(dp[i+1][1]+a[i],dp[i+1][3]+c[i]);
        dp[i][3]=max(dp[i+1][1]+a[i],dp[i+1][2]+b[i]);
    }
    cout<<max({dp[0][1],dp[0][2],dp[0][3]})<<endl;
    return 0;
}

Measured memory_bytes: 5984
#include <iostream>
#include <cstring>
#include <queue>

using namespace std;

typedef struct DOLL
{
	int h, r;
	
	bool operator > (const DOLL& d) const
	{
		return (h > d.h && r > d.r);
	}
	
	bool operator < (const DOLL& d) const
	{
		return (h < d.h && r < d.r);
	}
} D;

typedef struct Node
{
	D d;
	int num;
};

const int MAX = 100;

int n, m;
D A[MAX];
D B[MAX];

int AN[MAX];
int BN[MAX];

void solve()
{
	queue<Node> q;
	memset(AN, 0, sizeof(int)*n);
	memset(BN, 0, sizeof(int)*m);
	
	int max =0;
	Node n1 = {A[0], 1};
	Node n2 = {B[0], 1};
	q.push(n1);
	q.push(n2);
	while(!q.empty())
	{
		Node current = q.front();
		q.pop();
		
		if(max < current.num)
		{
			max = current.num;
		}
		
		for(int i=0; i<n; i++)
		{
			if(current.d < A[i])
			{
				if(AN[i] >= current.num+1) continue;
				
				Node new_node = {A[i], current.num+1};
				q.push(new_node);
				AN[i] = current.num+1;
				break;
			}
		}
		
		for(int i=0; i<m; i++)
		{
			if(current.d < B[i])
			{
				if(BN[i] >= current.num +1) continue;
				
				Node new_node = {B[i], current.num+1};
				q.push(new_node);
				BN[i] = current.num+1;
				break;
			}
		}
	}
	
	cout << max << endl;
}

int main(int argc, char** argv)
{
	int h, r;
	
	while(cin >> n, n)
	{
		for(int i=0; i<n; i++)
		{
			cin >> A[i].h >> A[i].r;
		}
		
		cin >> m;
		for(int i=0; i<m; i++)
		{
			cin >> B[i].h >> B[i].r;
		}
		
		solve();
	}
}

Measured memory_bytes: 0
#include<iostream>
#include<cstdio>
#include<algorithm>

using namespace std;

int main(){
	string s;
	cin >> s;
	int len = s.size();
	int n = len / 2;
	int ans = 0;
	for(int i = 0; i <= n; i++)
		if(s[i] != s[len-i-1]) ans++,s[i] = s[len-i-1];
	cout << ans;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include<algorithm>
#include<set>
#include<cmath>
using namespace std;
int gcd(int a, int b) {
	return b ? gcd(b, a % b) : a;
}
int ngcd(vector<int> a) {
	int res;
	res = a[0];
	for (int i = 1; i < a.size() && res != 1; i++) {
		res = gcd(a[i], res);
	}
	return res;
}
#define rep(i,n) for(int i =0;i < n;i++)
int main() {
	int n, k, m = 0;cin >> n >> k;vector<int> a(n);
	
	rep(i, n) {
		cin >> a[i];
		m = max(m, a[i]);
	}
	int G = ngcd(a);
	if (k <= m && k % G == 0) {
		cout << "POSSIBLE" << endl;
	}
	else
		cout << "IMPOSSIBLE" << endl;
}

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

signed main(){
  long h,w;
  cin >> h >> w;
  if(h == 1 || w == 1){
    cout << 1 << endl;
    return 0;
  }
  long result = h * w;
  result = (result % 2 == 1) ? result / 2 + 1 : result / 2;
  cout << result << endl;
}

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

class Stack{
public:
	int S[101];
	int top;

	Stack();
	void push(int x);
	int pop();
	bool isEmpty();
	bool isFull();
};

Stack::Stack(){
	S[0] = 0;
	top = 0;
	return;
}

void Stack::push(int x){
	top++;
	S[top] = x;
	return;
}

int Stack::pop(){
	top--;
	if (top > -1) return S[top + 1];
	return -1;
}

bool Stack::isEmpty(){
	return (top == 0);
}

bool Stack::isFull(){
	return (top == 100);
}

int main(){
	Stack s;
	string text, w;
	int dum, last;
	int pos = 0;
	int rpos;
	getline(cin, text);
	last = 0;
	while (true){
		rpos = pos;
		pos = text.find(' ', pos);
		if (pos == string::npos){
			last = 1;
			pos = text.length();
		}
		w = text.substr(rpos, pos - rpos);
		if (w == "+"){
			dum = s.pop() + s.pop();
		}
		else if (w == "-"){
			dum = -s.pop();
			dum += s.pop();
		}
		else if (w == "*"){
			dum = s.pop() * s.pop();
		}
		else{
			dum = atoi(w.c_str());
		}
		s.push(dum);
		pos++;
		if (last == 1) break;
	}
	cout << s.pop() << endl;
	return 0;
}


Measured memory_bytes: 3228
#include <bits/stdc++.h>
using namespace std;
int main(){
long long int cnt;
string s;
cin>>s;
for (int i=0;i<4;i++){
  if(s[i]==s[i+1]) cnt++;
}
  if (cnt>=1) cout<<"Bad"<<endl;
  else cout<<"Good"<<endl;
return 0;}

Measured memory_bytes: 256
#include <stdio.h>
int main(void){
    int i,j,H,W;
    while(1){
        scanf("%d %d",&H,&W);
        if(H==0 && W==0){
            break;
        }
        for(i=1;i<=H;i++){
            for(j=1;j<=W;j++){
                printf("#");
            }
            puts("");
        }
        puts("");
    }
    return 0;
}

Measured memory_bytes: 588
#include <stdio.h>
int main(){
  int count = 0;
  int a, b, c, x;
  scanf("%d %d %d", &a, &b, &c);
  for(x = a; x <= b; x++){
    if(c%x == 0) count = count++;
  }
  printf("%d\n", count);
  
  return 0;
}
  

Measured memory_bytes: 596
#include<iostream>
#include<cmath>
using namespace std;
int main(){
	long long a,b,c;
	cin>>a>>b>>c;
	if(c-a-b<0)
		cout<<"No";
	else{
		if(a*a+b*b+c*c-2*a*b-2*a*c-2*b*c>0)
			cout<<"Yes";
		else
			cout<<"No";
	}
	return 0;
}

Measured memory_bytes: 256