akhauriyash/Code-Regression huggingface dataset:
/*
 * $File: p1001.cpp
 * $Author: Wayne <tletletle@163.com>
 *
 * Task:
 *   Given two binary trees, we need to
 *   calculate the intersection or the
 *   union of them.
 *
 * Solution:
 *   String parsing. Graph theory.
 *   Just Build the trees and implement.
*/

#include <cstdio>
#include <cstring>

const int kMaxVtx = 100;
const int kMaxBuf = 512;
char buf[kMaxBuf];

struct TreeNode {
	TreeNode *son[2];
	TreeNode() {
		son[0] = son[1] = NULL;
	}
};

struct Tree {
	TreeNode *root;
	Tree() {
		root = NULL;
	}
} a, b, c;

TreeNode *BuildTree(int l, int r) {
	if (l > r) return NULL;
	TreeNode *res = new TreeNode;
	if (l + 1 == r - 1) return res;
	int mid, sum = 0;
	for (int i = l + 1; i <= r - 1; ++ i)
		if (buf[i] == '(') ++ sum;
		else if (buf[i] == ')') -- sum;
		else if (buf[i] == ',' && sum == 0) mid = i;
	res->son[0] = BuildTree(l + 1, mid - 1);
	res->son[1] = BuildTree(mid + 1, r - 1);
	return res;
}

void ReadTree(Tree &des) {
	scanf("%s", buf);
	des.root = BuildTree(0, strlen(buf) - 1);
}

TreeNode *DfsIntersection(TreeNode *u, TreeNode *v) {
	if (!u || !v) return NULL;
	TreeNode *res = new TreeNode;
	res->son[0] = DfsIntersection(u->son[0], v->son[0]);
	res->son[1] = DfsIntersection(u->son[1], v->son[1]);
	return res;
}

TreeNode *DfsUnion(TreeNode *u, TreeNode *v) {
	if (!u && !v) return NULL;
	TreeNode *res = new TreeNode;
	res->son[0] = DfsUnion(u ? u->son[0] : NULL, v ? v->son[0] : NULL);
	res->son[1] = DfsUnion(u ? u->son[1] : NULL, v ? v->son[1] : NULL);
	return res;
}

Tree GetIntersection(const Tree &a, const Tree &b) {
	Tree res;
	res.root = DfsIntersection(a.root, b.root);
	return res;
}

Tree GetUnion(const Tree &a, const Tree &b) {
	Tree res;
	res.root = DfsUnion(a.root, b.root);
	return res;
}

void OutputTree(TreeNode *cur) {
	if (!cur) return;
	putchar('(');
	OutputTree(cur->son[0]);
	putchar(',');
	OutputTree(cur->son[1]);
	putchar(')');
}

int main() {
	static char cmd[2];
	while (scanf("%s", cmd) != EOF) {
		ReadTree(a);
		ReadTree(b);
		if (cmd[0] == 'i') c = GetIntersection(a, b);
		else c = GetUnion(a, b);
		OutputTree(c.root);
		puts("");
	}
	return 0;
}

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

int main() {
  int N,T[100],M,P[100],X[100];
  cin>>N;
  for (int i(0);i<N;i++) cin>>T[i];
  cin>>M;
  for (int i(0);i<M;i++) cin>>P[i]>>X[i];
  for (int i(0);i<M;i++) {
    int sum=0;
    for (int n(1);n<=N;n++){
      if (n==P[i]){
        sum+=X[i];
      }else{
        sum+=T[n-1];
      }
    }
    cout<<sum<<endl;
  }
  return 0;
}


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

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

    int Max = 0;
    int Min = 10;
    for(long long i = 1; i*i <= N; i++){
        if(N % i != 0)
            continue;
        string str1 = to_string(i);
        string str2 = to_string(N/i);
        Max = max(str1.size(), str2.size());
        Min = min(Min, Max);
    }

    cout << Min << endl;

    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
    using namespace std;
    
    int main(){
        string str;
        cin >> str;
        vector<long> v;
        v.assign(26 , 0);
        long ans = 0;
        ans = str.length();
        int a;
        for(int i = 0 ; i < str.length() ; i++  ){
            a = str[i] - 'a';
            v[a] = v[a] + 1;
        }
        for(int i = 0 ; i < v.size() ; i++){
            if(v[i] == 0){
                continue;
            }
            string t;
            t = str;
            char b;
            b = 'a' + i;
            int c;
            c = str.length() - v[i] ;
            long d;
            d = 0;
            //cout << b << ":";
            while(c > 0){
                if(t.length() < 2){
                    break;
                }
                string t2;
                t2 = "";
                for(int j = 0 ; j < t.length() - 1 ; j++){
                    if(t[j] == b){
                        t2 = t2 + b;
                    }else if(t[j+1] == b){
                        t2 = t2 + b;
                        c -= 1;
                    }else{
                        t2 = t2 + t[j];
                    }
                }
                if(t[t.length()-1] != b){
                    c -= 1;
                }
                //cout << t2 << endl;
                t = t2;
                d += 1;
            }
            //cout << d << endl;
            ans = min(ans, d);
        }
        
        cout << ans << endl;
        
        return 0;
    }

Measured memory_bytes: 256
import sys
from collections import defaultdict


def main():
    n, v = map(int, sys.stdin.readline().split())
    a = tuple(map(int, sys.stdin.readline().split()))
    b = tuple(map(int, sys.stdin.readline().split()))
    c = tuple(map(int, sys.stdin.readline().split()))
    d = tuple(map(int, sys.stdin.readline().split()))
    mp = defaultdict(int)
    for val1 in c:
        for val2 in d:
            mp[val1 + val2] += 1
    print(sum(mp[v - val1 - val2] for val1 in a for val2 in b))

if __name__ == '__main__':
    main()



Measured memory_bytes: 179068
#include<bits/stdc++.h>
#include <string> 
using namespace std;
bool A[1000000001]={};
int main()
{
  int N,num;
  bool flag=false;
  cin>>N;
  if(N%2!=0){
    cout<<(N/2)+1;
  }else{
    cout<<N/2;
  }
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <unistd.h>
#include <sys/time.h>
#include <stdlib.h>

using namespace std;

typedef long long ll;
typedef pair<ll, ll> P;
typedef pair<P, ll> T;
typedef pair<long double , ll> Ps;
typedef pair<ll, bool> Pb;

const ll INF = 1e18;
const ll fact_table = 3200008;
long double Pi = 3.1415926535897932384626;

priority_queue <ll> pql;
priority_queue <P> pqp;
priority_queue <P> bag;
//big priority queue
priority_queue <ll, vector<ll>, greater<ll> > pqls;
priority_queue <P, vector<P>, greater<P> > pqps;
//small priority queue
//top pop

ll dx[8] = {1, 0, -1, 0, 1, 1, -1, -1};
ll dy[8] = {0, 1, 0, -1, 1, -1, -1, 1};
//↓,→,↑,←


#define endl "\n"
#ifdef ENJAPMA
#undef endl
#endif

#define p(x) cout<<x<<endl;
#define el cout<<endl;
#define pe(x) cout<<x<<" ";
#define ps(x) cout<<fixed<<setprecision(25)<<x<<endl;
#define pu(x) cout<<(x);
#define pb push_back
#define lb lower_bound
#define ub upper_bound
#define CLEAR(a) a = decltype(a)();
#define pc(x) cout << x << ",";
#define rep(i, n) for (ll i = 0; i < (n); i ++)

// const ll mod = 998244353ll;
const ll mod = 1000000007ll;

ll mypow(ll a, ll b, ll mod) {ll x = 1; while (b) {while (!(b & 1)) {(a *= a) %= mod; b >>= 1;}(x *= a) %= mod; b--;} return x;}
void YES(bool cond) { if (cond) { p("YES");} else { p("NO");} return;}
void Yes(bool cond) { if (cond) { p("Yes");} else { p("No");} return;}
void line() { p("--------------------"); return;}

/*
ll fact[fact_table + 5], rfact[fact_table + 5];

void c3_init() {
    fact[0] = rfact[0] = 1;
    for (ll i = 1; i <= fact_table; i++) {
        fact[i] = (fact[i - 1] * i) % mod;
    }
    rfact[fact_table] = mypow(fact[fact_table], mod - 2, mod);
    for (ll i = fact_table; i >= 1; i--) {
        rfact[i - 1] = rfact[i] * i;
        rfact[i - 1] %= mod;
    }
    return;
}
ll c3(ll n, ll r) {
    return (((fact[n] * rfact[r]) % mod ) * rfact[n - r]) % mod;
}
*/
struct Timer {
    int64_t start;
    const int64_t CYCLES_PER_SEC = 2800000000;
    Timer() { reset(); }
    void reset() { start = getCycle(); }
    inline double get() { return (double)(getCycle() - start) / CYCLES_PER_SEC; }
    inline int64_t getCycle() {
        uint32_t low, high;
        __asm__ volatile ("rdtsc" : "=a" (low), "=d" (high));
        return ((int64_t)low) | ((int64_t)high << 32);
    }
};


bool multicase = false;

ll n, m, k, w, a, b, c, d, e, h, q, ans, sum, l;

typedef vector<ll> vec;
typedef vector<vector<ll>> mat;

void solve() {
    cin >> a >> b >> c;
    Yes(b * c >= a);
    return;
}

int main() {
    // init();
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    ll q, testcase = 1;
    if (multicase) {
        cin >> q;
    } else {
        q = 1;
    }
    while (q--) {
        // pu("Case ");pu("#");pu(testcase);pu(": ");
        solve();
        testcase++;
    }
    // solve();
    return 0;
}



Measured memory_bytes: 3648
s=input()
ans=0
for i in range(len(s)):
    for j in range(i,len(s)+1):
        if s[i:j].count("A")+s[i:j].count("T")+s[i:j].count("C")+s[i:j].count("G")==len(s[i:j]):
            ans=max(ans,len(s[i:j]))
print(ans)

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

#define ll long long int

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

int main(){
    ll n;
    cin>>n;
    int ans=0;
    for(ll x : enumDivisor(n)){
        if(x==1) continue;
        ll tmp=n;
        while(tmp%x == 0) tmp /= x;
        tmp %= x;
        if(tmp==1) ++ans;
    }
    ans+=enumDivisor(n-1).size()-1;
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 384
#include<cmath>
#include<cstdio>
#include<cstring>
#include<iostream>
#include<algorithm>
using namespace std;
const int maxn=2000;
const int mod=1e9+7;
int n,k,ans;
int f[maxn+8][maxn+8],g[maxn+8][maxn+8];

int read()
{
    int x=0,f=1;char ch=getchar();
    for (;ch<'0'||ch>'9';ch=getchar()) if (ch=='-') f=-1;
    for (;ch>='0'&&ch<='9';ch=getchar()) x=x*10+ch-'0';
    return x*f;
}

int power(int a,int k)
{
    int sum=1;
    for (;k;k>>=1,a=1ll*a*a%mod)
	if (k&1)
	    sum=1ll*sum*a%mod;
    return sum;
}

int main()
{
    n=read(),k=read();
    f[n+1][0]=g[n+1][0]=1;
    for (int i=n;i;i--)
	for (int j=n-i+1;j;j--)
	    {
		{
		    f[i][j]=(f[i+1][j-1]+g[i+1][j])%mod;
		    g[i][j]=(g[i][j+1]+f[i][j])%mod;
		}
		f[i][0]=g[i+1][0];
		g[i][0]=(g[i][1]+f[i][0])%mod;
	    }
    //printf("%d\n",f[2][0]);
    ans=1ll*f[2][n-k]*power(2,max(n-k-1,0))%mod;
    printf("%d\n",ans);
    return 0;
}


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

public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        InputReader in = new InputReader(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        Task solver = new Task();
        solver.solve(in, out);
        out.close();
    }

    static class Task {
        int N;
        long[] A;

        void solve(InputReader in, PrintWriter out) {
            N = in.nextInt();
            A = in.nextLongArray(N);

            long ans = 0;
            for (int i = 0; i < N; ++i) {
                if ((i >> 0 & 1) == 0) {
                    ans += A[i];
                } else {
                    ans -= A[i];
                }
            }

           StringBuilder ansStr = new StringBuilder();
            for (int i = 0; i < N; ++i) {
                ansStr.append(ans).append(' ');
                ans -= A[i];
                ans *= -1;
                ans += A[i];
            }
            out.println(ansStr.toString().trim());
        }
    }

    static class InputReader {
        BufferedReader reader;
        StringTokenizer tokenizer;

        InputReader(InputStream stream) {
            reader = new BufferedReader(new InputStreamReader(stream));
            tokenizer = null;
        }

        String next() {
            while (tokenizer == null || !tokenizer.hasMoreTokens()) {
                try {
                    tokenizer = new StringTokenizer(reader.readLine());
                } catch (IOException e) {
                    throw new RuntimeException(e);
                }
            }
            return tokenizer.nextToken();
        }

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

        int[] nextIntArray(int size) {
            int[] arr = new int[size];
            for (int i = 0; i < size; i++) {
                arr[i] = nextInt();
            }
            return arr;
        }

        long nextLong() {
            return Long.parseLong(next());
        }

        long[] nextLongArray(int size) {
            long[] arr = new long[size];
            for (int i = 0; i < size; i++) {
                arr[i] = nextLong();
            }
            return arr;
        }
    }
}

Measured memory_bytes: 44136
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10**6)


############ ---- Input Functions ---- ############
def in_int():
    return (int(input()))


def in_list():
    return (list(map(int, input().split())))


def in_str():
    s = input()
    return (list(s[:len(s) - 1]))


def in_ints():
    return (map(int, input().split()))

mod = 7 + 10**9


n = in_int()

a = in_list()


aa = sum(a)//n

ans1 = 0
ans2 = 0

for xx in a:
    ans1 += (xx-aa)**2
    ans2 += (xx-aa-1)**2


print(min(ans1,ans2))

Measured memory_bytes: 3064
n,d = map(int,input().split())
X = [list(map(int,input().split())) for _ in range(n)]

ans = 0
for i,Y in enumerate(X[:-1]):
	for j,Z in enumerate(X[i+1:]):
		res = 0
		for y,z in zip(Y,Z):
			res += (y-z)**2
		if res**0.5%1 == 0:
			ans += 1
print(ans)

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

namespace Poll
{
    class Program
    {
        static void Main(string[] args)
        {
            var nInput = int.Parse(Console.ReadLine());            
            var inputs = new Dictionary<string, int>();
            for (int i = 0; i < nInput; i++)
            {
                var input = Console.ReadLine();

                if (!inputs.ContainsKey(input))
                {
                    inputs[input] = 1;
                }
                else
                {
                    inputs[input]++;
                }
            }
            var maxValue = inputs.Values.Select(x => x).Max();                         
            var sortedList = inputs.Where(x => x.Value == maxValue).Select(y => y.Key).ToList();
            sortedList.Sort(StringComparer.Ordinal);

            for(int i = 0; i< sortedList.Count(); i++)
            {
                Console.WriteLine(sortedList[i]);
            }
                                       
        }
    }
}


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

ll k;
queue <ll> q;

int main() {
	for (int i=1; i<10; i++) {
		q.push(i);
	}
	cin>>k;
	ll ans;
	for (int i=0; i<k; i++) {
		ans=q.front();
		ll add=10*ans+ans%10;
		if (ans%10!=0) q.push(add-1);
		q.push(add);
		if (ans%10!=9) q.push(add+1);
		q.pop();
	}
	cout<<ans<<endl;
}



Measured memory_bytes: 1792
import java.io.*;
import java.util.*;

class Main {

  public static void main(String[] args) {
  
  	try {
    
      BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
      String s = br.readLine();
      int n = Integer.parseInt(s);
	  int[][] dp = new int[n][3];
      for(int i = 0 ; i < n ; i++) {
	        s = br.readLine();
        	String[] actions = s.split(" ");
        	if(i == 0) {
              dp[i][0] = Integer.parseInt(actions[0]);
              dp[i][1] = Integer.parseInt(actions[1]);
              dp[i][2] = Integer.parseInt(actions[2]);
            } else {
            	dp[i][0] = Integer.parseInt(actions[0]) + Math.max(dp[i-1][1], dp[i-1][2]);
				dp[i][1] = Integer.parseInt(actions[1]) + Math.max(dp[i-1][0], dp[i-1][2]);
                dp[i][2] = Integer.parseInt(actions[2]) + Math.max(dp[i-1][0], dp[i-1][1]);
            }
      }
      System.out.println(Math.max(dp[n-1][0], Math.max(dp[n-1][1], dp[n-1][2])));
		                         
    } catch(Exception ex) {
    
    }
  
  }
     

}

Measured memory_bytes: 52240
#include<bits/stdc++.h>
#define ll long long
#define rep(i, n) for(int i=0; i<n; i++)
#define REP(i, n) for(int i=0; i<=n; i++)
#define repr(i, n) for(int i=n; i>0; i--)
#define REPR(i, n) for(int i=n; i>=0; i--)
const ll INF = 1LL<<60;
const int INT_INF = 1e9;
const ll MOD = 1e9+7;
template<class T> void puts(T x) { std::cout << x << std::endl; }
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; }
using namespace std;

ll dp[100010][13];

int main() {
    string s; cin >> s;
    int n = s.length();

    dp[0][0] = 1;
    for (int i = 0; i < n; i++) {
        int c;
        if (s[i] == '?') c = -1;
        else c = s[i] - '0';

        for (int j = 0; j < 10; j++) {
            if (c != -1 && c != j) continue;
            for (int ki = 0; ki < 13; ki++) {
                dp[i+1][(ki * 10 + j) % 13] += dp[i][ki];
            }
        }

        for (int j = 0; j < 13; j++) dp[i+1][j] %= MOD;
    }

    cout << dp[n][5] << endl;
}


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

namespace ABC128_1
{
    class A
    {
        static void Main(string[] args)
        {
            var a = Console.ReadLine().Split().Select(int.Parse).ToArray();
            Console.WriteLine((a[0] * 3 + a[1]) / 2);
        }
    }
}


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

using ll = long long;
const ll MOD = 1e9 + 7;

int main() {
    int K;
    cin >> K;
    cout << (K / 2) * ((K + 1) / 2) << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define ll long long
#define endl "\n"
using namespace std;
const int N=3005;
const int mod=998244353;
ll dp[N][N];
int a[N];

void solve(){
	int n,s;
	cin>>n>>s;
	for(int i=1;i<=n;i++){
		cin>>a[i];
	}
	dp[0][0]=1;
	for(int i=1;i<=n;i++){
		for(int j=s;j>=0;j--){
			dp[i][j]=dp[i-1][j]*2;
			dp[i][j]%=mod;
			if(a[i]+j<=s){
				dp[i][j+a[i]]+=dp[i-1][j];
				dp[i][j+a[i]]%=mod;
				}
			}
			
		}
	cout<<dp[n][s]<<endl;
}
int main(){
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
	int t=1;
	//cin>>t;
	while(t--)solve();
}


Measured memory_bytes: 74088
use std::io::{self, Read};

pub struct Scanner<R>
where
    R: Read,
{
    reader: R,
}

impl<R> Scanner<R>
where
    R: Read,
{
    pub fn new(reader: R) -> Self {
        Self { reader }
    }

    pub fn next<T>(&mut self) -> T
    where
        T: ::std::str::FromStr,
        <T as ::std::str::FromStr>::Err: ::std::fmt::Debug,
    {
        self.reader
            .by_ref()
            .bytes()
            .map(|b| b.unwrap() as char)
            .skip_while(|c| c.is_whitespace())
            .take_while(|c| !c.is_whitespace())
            .collect::<String>()
            .parse::<T>()
            .unwrap()
    }
}

fn main() {
    let stdin = io::stdin();
    let mut sc = Scanner::new(stdin.lock());

    let n:usize = sc.next();
    let mut v: Vec<i32> = (0..n).map(|_| sc.next()).collect();
    let mut swaps: i32 = 0;

    for i in 0_usize..n {
        for j in ((i+1)..n).rev() {
            if v[j-1] > v[j] {
                v.swap(j-1, j);
                swaps += 1;
            }
        }
    }
    for i in 0..(v.len()-1) {
        print!("{} ", v[i]);
    }
    println!("{}", v[v.len() -1]);
    println!("{}", swaps);
}



Measured memory_bytes: 5036
def n0():return int(input())
def n1():return [int(x) for x in input().split()]
def n2(n):return [int(input()) for _ in range(n)]
def n3(n):return [[int(x) for x in input().split()] for _ in range(n)]

a,b,n=n1()

if b<=n:
    i=b-1
else:
    i=n
m=(a*i)//b-a*(i//b)
print(m)

Measured memory_bytes: 9188
#include<stdio.h>


int stack[30];
int top;

void push(int n){
  stack[top] = n;
  top += 1;
}

int pop(void){
  top -= 1;
  return stack[top];
}


void dump(void){
  int n;
  printf("(%d) [", top);
  for(n=0;n<top; n++){
    printf("%d,", stack[n]);

  }
  printf("]\n");

}

int main(){
  int car;
  top = 0;

  //dump();
  while (scanf("%d", &car)==1){
    if (car){
      push(car);
    }else{
      car = pop();
      printf("%d\n", car);
    }
    //dump();
  }
  return 0;
}

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

int main() {
    string s,t; cin >> s >> t;
    sort(s.begin(),s.end());
    for (int i = 0; i < t.size()-1; i++)
    {
        for (int j = i+1; j < t.size(); j++)
        {
            if (t[i] < t[j])
            {
                char tmp = t[i];
                t[i] = t[j];
                t[j] = tmp;
            }
        }
    }
    if (s < t)
    {
        cout << "Yes\n";
    } else {
        cout << "No\n";
    }
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int n,k,sum=0;
    cin>>n>>k;
    int a[n];
    for(int i=0;i<n;i++)
    {
        cin>>a[i];
    }
    sort(a,a+n);
    for(int i=0;i<k;i++)
    {
        sum+=a[i];
    }
    cout<<sum<<"\n";

}


Measured memory_bytes: 3608
#include <iostream>

int main() {
    int H, W;
    std::cin >> H >> W;

    char canvas[H + 2][W + 2];
    for (int i = 0; i <= H + 1; i++) {
        for (int j = 0; j <= W + 1; j++) {
            if (i == 0 || i == H + 1 || j == 0 || j == W + 1) {
                canvas[i][j] = 0;
            } else {
                std::cin >> canvas[i][j];
            }
        }
    }

    bool result = true;
    for (int i = 1; i <= H; i++) {
        for (int j = 1; j <= W; j++) {
            if (canvas[i][j] == '#' &&
                canvas[i - 1][j] != '#' && canvas[i + 1][j] != '#' &&
                canvas[i][j - 1] != '#' && canvas[i][j + 1] != '#') {
                result = false;
                break;
            }
        }
    }

    std::cout << (result ? "Yes" : "No") << std::endl;

    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
template<class T> istream &operator>>(istream&is,vector<T>&v){for(auto &elemnt:v)is>>elemnt;return is;}
signed main(){
  int n;
  cin>>n;
  vector<int> a(n);
  cin>>a;
  
  int allxor = 0;
  for(auto& ai:a)allxor ^= ai;
  
  for(auto& ai:a)cout<< (allxor^ai) <<endl;
}


Measured memory_bytes: 4040
#include <bits/stdc++.h>
using namespace std;
const int maxn = 3005;
using ll = long long;

const ll mod = 1e9 + 7;

ll dp[maxn][maxn];

ll pref[maxn];

int main()
{
  string s;
  int n;
  cin >> n >> s;
  
  dp[1][1] = 1;
  for(int i = 2; i <= n; i++)
  {
    pref[0] = 0;
    for(int j = 1 ; j <= n; j++)
    {
      pref[j] = pref[j - 1] + dp[i - 1][j];
      pref[j] %= mod;
    }

    for(int j = 1; j <= i; j++)
    {
      if(s[i - 2] == '>')
        dp[i][j] = (pref[n] - pref[j - 1] + mod);
      else
        dp[i][j] = pref[j - 1];
      dp[i][j] %= mod;
    }

  }

  ll ans = 0;
  for(int i = 1; i <= n; i++)
    ans = (ans + dp[n][i]) % mod;

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

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

const long long mod = 1e9 + 7;

using ll = long long;
using pii  = pair<int, int>;
using pll = pair<ll, ll>;
#define ull unsigned long long
#define ld long double
#define vi vector<int>
#define vll vector<ll>
#define vc vector<char>
#define vs vector<string>
#define vpii vector<pii>
#define vpll vector<pll>

#define rep(i, n) for (int i = 0, i##_len = (n); i < i##_len; i++)
#define rep1(i, n) for (int i = 1, i##_len = (n); i <= i##_len; i++)
#define repr(i, n) for (int i = ((int)(n)-1); i >= 0; i--)
#define rep1r(i, n) for (int i = ((int)(n)); i >= 1; i--)

#define sz(x) ((int)(x).size())
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()

#define SORT(v, n) sort(v, v + n);
#define VSORT(v) sort(v.begin(), v.end());
#define RSORT(x) sort(rall(x));
#define pb push_back
#define mp make_pair

#define INF (1e9)
#define PI (acos(-1))
#define EPS (1e-7)

ull gcd(ull a, ull b) { return b ? gcd(b, a % b) : a; }
ull lcm(ull a, ull b) { return a / gcd(a, b) * b; }

const string YES = "Yes";
const string NO = "No";

int main(){
    int a, b, c;
    cin >> a >> b >> c;
    int k;
    cin >> k;
    while (b <= a) {
        b *= 2;
        --k;
    }
    while (c <= b) {
        c *= 2;
        --k;
    }
    if (k >= 0) cout << YES << endl;
    else cout << NO << endl;
    return 0;
}


Measured memory_bytes: 3636
#pragma GCC optimize ("O3")
#pragma GCC target ("avx2")
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for(int i = 0; i < (n); i++)
#define rep1(i, n) for(int i = 1; i <= (n); i++)
#define co(x) cout << (x) << "\n"
#define cosp(x) cout << (x) << " "
#define ce(x) cerr << (x) << "\n"
#define cesp(x) cerr << (x) << " "
#define pb push_back
#define mp make_pair
#define chmin(x, y) x = min(x, y)
#define chmax(x, y) x = max(x, y)
#define Would
#define you
#define please


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


	ll N, K;
	cin >> N >> K;

	int A[200001];
	rep1(i, N) cin >> A[i];

	int D[200001] = {};
	int d = 1;
	int p = 1;

	while (D[p] == 0) {
		D[p] = d;

		p = A[p];
		d++;
	}

	int kuri = d - D[p];

	if (K > D[p]) {
		ll k = K - D[p];
		k %= kuri;
		K = D[p] + k;
	}

	rep1(i, N) D[i] = 0;
	d = 1;
	p = 1;
	while (d <= K) {
		D[p] = d;

		p = A[p];
		d++;
	}

	co(p);

	Would you please return 0;
}

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

using namespace std;
using ll=long long;
using ld=long double;
using P=pair<ll,ll>;
#define FOR(i,n,m) for(ll i=n; i<(ll)m;i++)
#define FORr(i,n,m) for(ll i=n; i>(ll)m; i--)
#define cinv(v,n,m) FOR(i,n,m) cin>>v.at(i)
#define coutv(v,n,m) FOR(i,n,m) cout<<v.at(i) <<" "
#define cout(n) cout<<fixed<<setprecision(n)
int main(){
  int N,K;
  cin>>N>>K;
  int res=0;
  if(N%K==0){
    res=0;
  }
  else res=1;
  cout<<res<<endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
 
#define int long long
 
#define pii pair<int, int>
 
#define x1 x1228
#define y1 y1228
 
#define left left228
#define right right228
 
#define pb push_back
#define eb emplace_back
 
#define mp make_pair                                                                
                                                                                                                                        
#define ff first                                                                  
#define ss second   
 
#define matr vector<vector<int> > 
 
#define all(x) x.begin(), x.end()
 
 
using namespace std;
typedef long long ll; 
typedef long double ld; 
                                                                                                   
const int maxn = 3e5 + 7, mod = 998244353, inf = 1e18, MAXN = 1e6 + 7;
const double eps = 1e-9;
mt19937 rnd(time(0));
int n; 
int a[maxn], b[maxn], c[maxn]; 

void solve() { 
    cin >> n; 
    for (int i = 0; i < n; ++i) {
        cin >> a[i], --a[i];
    }
    for (int i = 0; i < n; ++i) {
        cin >> b[i]; 
    }            
    for (int i = 0; i < n - 1; ++i) {
        cin >> c[i]; 
    }
    int ans = 0;
    for (int i = 0; i < n; ++i) {
        int cr = a[i]; 
        ans += b[cr]; 
        if (i && a[i - 1] + 1 == cr) {
            ans += c[cr - 1];         
        }
    }
    cout << ans; 
}                                
   
signed main() {
#ifdef LOCAL
    freopen("TASK.in", "r", stdin);
    freopen("TASK.out", "w", stdout);
#else 
    
#endif // LOCAL
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.precision(20); 
    cout << fixed; 
    int t = 1; 
    for (int i = 0; i < t; ++i) {              
        solve();
    }
    return 0;
}  

Measured memory_bytes: 4352
#include<set>
#include<iostream>
#include<map>
#include<vector>
#include<queue>
#include <utility>
#include<algorithm>

#define fast ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
using namespace std;
int  visit[100005];
long long  dist[100005];
vector<int>vec[100005];
map<pair<int,int>,int>mp;
void bfs(int x)
{

   int s=x;
   visit[s]=1;
   queue<int>q;
   q.push(s);
   while(!q.empty()){
    int y=q.front();
    q.pop();
    for(int i=0;i<vec[y].size();i++)
    {
        if(visit[vec[y][i]]==0)
        {
            visit[vec[y][i]]=1;
            q.push(vec[y][i]);
            dist[vec[y][i]]=dist[y]+mp[{y,vec[y][i]}];
        }




    }




   }





}






int main()
{

int a,b,c,d,e,i;
cin >> a ;
set<int>s;
for(i=0;i<=a;i++)
{
    visit[i]=0;
    dist[i]=0;
}

if(a==1)
{
    cout << 0 << endl;
}
else{

   a--;
while(a--)
{
    cin >> c >> d >> e;
    s.insert(c);
    s.insert(d);
    vec[c].push_back(d);
    vec[d].push_back(c);
    mp[{c,d}]=e;
    mp[{d,c}]=e;


}
bfs(c);
for(auto it=s.begin();it!=s.end();it++)
{
    if(dist[*it]%2==0)
    {
        cout << 0 << endl;
    }
    else{
        cout << 1 << endl;
    }




}



}






}

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

#define INF 1e9
using namespace std;
typedef long long ll;

int main() {

    int n; cin >> n;

    int t[9] = {};

    for (int i = 0; i < n; ++i) {
        int a; cin >> a;

        if (1 <= a && a <= 399) {
            t[0]++;
        }

        if (400 <= a && a <= 799) {
            t[1]++;
        }

        if (800 <= a && a <= 1199) {
            t[2]++;
        }

        if (1200 <= a && a <= 1599) {
            t[3]++;
        }

        if (1600 <= a && a <= 1999) {
            t[4]++;
        }

        if (2000 <= a && a <= 2399) {
            t[5]++;
        }

        if (2400 <= a && a <= 2799) {
            t[6]++;
        }

        if (2800 <= a && a <= 3199) {
            t[7]++;
        }

        if (3200 <= a) {
            t[8]++;
        }
    }

    int type = 0;

    for (int i = 0; i < 8; ++i) {
        if (t[i] > 0) {
            type++;
        }
    }

    cout << max(type, 1) << ' ' << type+t[8] << endl;
}

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

int main() {
  char *s = (char *)malloc(128);
  scanf("%s", s);
  char *end = s + strlen(s);

  int odd = 1;
  while (s < end) {
    if (odd && *s == 'L')
      break;
    if (!odd && *s == 'R')
      break;
    odd = 1 - odd;
    s++;
  }

  printf(s == end ? "Yes\n" : "No\n");
  return 0;
}


Measured memory_bytes: 128
#include<iostream>
#include<fstream>
#include<algorithm>
#include<cstdio>
#include<cmath>
#include<cstring>
#include<string>

using namespace std;
long long h,n,m,k,a;
int main()
{
	cin>>n>>m>>k>>a;
	for(int i=0;i<=n;i++)
	{
		for(int j=0;j<=m;j++)
		{
			for(int q=0;q<=k;q++)
			{
				if(i*500+j*100+q*50==a)h++;
			}
		}
	}
	cout<<h<<endl;
	return 0;
}

Measured memory_bytes: 256
#include<iomanip>
#include<limits>
#include<thread>
#include<utility>
#include<iostream>
#include<string>
#include<algorithm>
#include<set>
#include<map>
#include<vector>
#include<stack>
#include<queue>
#include<cmath>
#include<numeric>
#include<cassert>
#include<random>
#include<chrono>
#include<unordered_set>
#include<unordered_map>
#include<fstream>
#include<list>
#include<functional>
#include<bitset>
#include<complex>
#include<tuple>
using namespace std;
typedef unsigned long long int ull;
typedef long long int ll;
typedef pair<ll,ll> pll;
typedef pair<int,int> pi;
typedef pair<double,double> pd;
typedef pair<double,ll> pdl;
#define F first
#define S second
const ll E=1e18+7;
const ll MOD=1000000007;



int main(){
    ll k;
    cin>>k;
    ll N=50;
    vector<ll> a(N,N-1);
    ll X=(k+N-1)/N;
    for(int i=0;i<N;i++){a[i]+=X;}
    X*=N;
    ll w=0;
    for(int i=0;X>k;i++,X--,w++){a[i]-=N+1;}
    for(auto &I:a){I+=w;}
    cout<<N<<endl;
    for(int i=0;i<N;i++){
        cout<<a[i];
        if(i+1!=N){cout<<" ";}
    }
    cout<<endl;
    
    
    return 0;
}


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

int main()
{
    int n,a,b,c,x,y,d;
    while(~scanf("%d %d %d %d",&a,&b,&c,&d))
    {
        x=a*b;
        y=c*d;
        if(x>y)
        {
            printf("%d\n",x);
        }
        else if(x<y)
        {
            printf("%d\n",y);
        }
        else if(x==y)
        {
            printf("%d\n",x);
        }
    }
    return 0;
}

Measured memory_bytes: 128
/**
 * code generated by JHelper
 * More info: https://github.com/AlexeyDmitriev/JHelper
 * @author cherrypi59
 */

#pragma GCC optimize ("O2")
#pragma GCC optimize ("tree-vectorize")
#pragma GCC target ("sse4")

#include <bits/stdc++.h>
#define FOR(i, a, b) for(int i=(a);i<(b);++i)
#define FFOR(i, a, b) FOR(i, a, b+1)
#define REP(i, n) FOR(i, 0, n)
#define RREP(i, n) FOR(i, 1, n+1)
#define ALL(v) (v).begin(), (v).end()
#define RALL(v) (v).rbegin(), (v).rend()
#define LEN(x) (int)(x).size()
#define DUMP(x) cerr<<__LINE__<<' '<<#x<<"="<<(x)<<endl;
#define pb push_back
#define eb emplace_back
#define mp make_pair

using namespace std;
using lint = long long;
using pii =  pair<int, int>;
using pll =  pair<lint, lint>;
template <typename T> using vc = vector<T>;
template <typename T> using vvc = vector<vector<T>>;
template <typename T> inline bool chmax(T &a, T b){if(a<b){a = b; return true;} return false;}
template <typename T> inline bool chmin(T &a, T b){if(a>b){a = b; return true;} return false;}

constexpr lint ten(int n) {return n==0 ? 1 : ten(n-1)*10;}

class DStringEquivalence {
public:
    int N;
    vc<string> ans;

    void dfs(string cur, int mx){
        if(LEN(cur)==N){
            ans.pb(cur);
            return;
        }
        REP(i, mx+2){
            dfs(cur+char('a'+i), max(mx, i));
        }
    }

    void solve(std::istream& in, std::ostream& out){
        ios_base::sync_with_stdio(false);
        in.tie(nullptr), out.tie(nullptr);
        in>>N;
        dfs("a", 0);
        for(auto& a : ans) out<<a<<'\n';
    }
};


int main() {
	DStringEquivalence solver;
	std::istream& in(std::cin);
	std::ostream& out(std::cout);
	solver.solve(in, out);
	return 0;
}


Measured memory_bytes: 7356
#include<bits/stdc++.h>
#include <assert.h>
using namespace std;
#define rep(a,b,c) for(int a=b;a<=c;a++)
#define ll long long 
#define sum(a,b) a=a+b

int arr[3];
int main() {
rep(i,0,2) cin>>arr[i];

sort(arr,arr+3);

int sum=(arr[2]-arr[1])+(arr[2]-arr[0]);

if(sum%2==0){
    cout<<sum/2;
}else{
    cout<<(sum+3)/2;
}


return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
int n,i,p,c,ans=0;
int a[100000],x[100000],y[100000];

int main(){
  scanf("%d",&n);
  for(i=0;i<n;i++){
    scanf("%d",&a[i]);
    x[i]=-1;
    y[i]=-1;
  }
  for(i=0;i<n;i++){
    p=i;
    c=0;
    while(x[p]==-1){
      x[p]=c;
      c++;
      y[p]=i;
      p=(p+a[p])%n;
    }
    if(y[p]==i)ans+=(c-x[p]);
  }
  printf("%d\n",ans);
  return 0;
}

Measured memory_bytes: 1764
#include <algorithm>
#include <cmath>
#include <climits>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <fstream>
#include <iostream>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>
#include <cassert>
#include <functional>

using namespace std;

#define LOG(...) printf(__VA_ARGS__)
//#define LOG(...)
#define FOR(i,a,b) for(int i=(int)(a);i<(int)(b);++i)
#define REP(i,n) for(int i=0;i<(int)(n);++i)
#define ALL(a) (a).begin(),(a).end()
#define RALL(a) (a).rbegin(),(a).rend()
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort((c).begin(),(c).end())
#define RSORT(c) sort((c).rbegin(),(c).rend())
#define CLR(a) memset((a), 0 ,sizeof(a))

typedef long long ll;
typedef unsigned long long ull;
typedef vector<bool> vb;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<vb> vvb;
typedef vector<vi> vvi;
typedef vector<vll> vvll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;

const int dx[] = { -1, 0, 1, 0 }; const int dy[] = { 0, 1, 0, -1 };

struct UnionFind {
	vector<int> v;
	UnionFind(int n) : v(n)  { for (int i = 0; i < n; i++) v[i] = i; }
	int  find(int x)         { return v[x] == x ? x : v[x] = find(v[x]); }
	void unite(int x, int y) { v[find(x)] = find(y); }
};

int main() {
	int n;
	cin >> n;
	vector<double> vd(n);
	vector<double> vx(n);
	REP(i, n)
		cin >> vd[i];
	vx = vd;
	
	REP(i,n) {
		for (int j = i-1;j >= 0;j--) {
			vx[i] = max(vx[i], vx[j]+sqrt((vd[i]+vd[j])*(vd[i] + vd[j])- (vd[i] - vd[j])*(vd[i] - vd[j])));
		}
	}
	double ans = 0.0;
	REP(i, n)
		ans = max(ans, vx[i] + vd[i]);
	printf("%.8lf\n", ans);
}

Measured memory_bytes: 3320
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <queue>
#include <cmath>
#include <climits>
#include <iomanip>
#include <set>
#include <map>
using namespace std;
typedef long long ll;
int main(){
  ll w,h,n;
  cin >> w >> h >> n;
  ll wmax = w;
  ll wmin = 0;
  ll hmax = h;
  ll hmin = 0;
  for(int i = 0;i < n;i++){
    ll x,y,a;
    cin >> x >> y >> a;
    if(a == 1)wmin = max(wmin,x);
    if(a == 2)wmax = min(wmax,x);
    if(a == 3)hmin = max(hmin,y);
    if(a == 4)hmax = min(hmax,y);
    //cout << hmin << " " << hmax << " " << wmin << " " << wmax << endl;
  }
  cout << max((ll)0,hmax - hmin) * max((ll)0,wmax - wmin) << endl;
}

Measured memory_bytes: 3608
#include <bits/stdc++.h>
#define ll long long
#define all(x) begin(x), end(x)
#define print(x) for (auto &el: x) cout << el << ' '; cout << '\n'
using namespace std;

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0), cout.tie(0);
    
    ll n, k, t;
    cin >> n >> k >> t;

    cout << (n + k - 1) / k * t << endl;


    return 0;
}

Measured memory_bytes: 3600
#include<bits/stdc++.h>
using namespace std;
int a,b,c,d,s[1001];
int main()
{
	cin>>a>>b>>c>>d;
	s[a]=s[b]=s[c]=s[d]=1;
	if(s[1]&&s[9]&&s[7]&&s[4])puts("YES");
	else puts("NO");
}

Measured memory_bytes: 256
import java.util.Scanner;


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

    while(true){
      int A = 0, B = 0;
      
      int N = sc.nextInt();
      
      if(N == 0){
	break;
      }

      for(int i = 0; i < N; i++){
	int a = sc.nextInt();
	int b = sc.nextInt();

	if(a > b){
	  A += a + b;
	}else if(a < b){
	  B += a + b;
	}else{
	  A += a;
	  B += b;
	}
      }
      
      System.out.println(A + " " + B);
    }
  }
}

Measured memory_bytes: 12000
#include <stdio.h>

#define N 100000
int A[N];
int n;

int partition(int,int);

int main(){
  int i,r=0;
  int k;
  scanf("%d",&n);
  
  for(i=1;i<=n;i++){
    scanf("%d",&A[i]);
  }
  
  k=partition(1,n);
  
  for(i=1;i<=n;i++){
    if(i==k) printf("[%d] ",A[i]);
    else if(i==n) printf("%d\n",A[i]);
    else printf("%d ",A[i]);
  }
  return 0;
}

int partition(int p,int r){
  int x=A[r],cn;
  int j;
  int i=p-1;
  for(j=p;j<r;j++){
    if(A[j]<=x){
      i=i+1;
      cn=A[i];
      A[i]=A[j];
      A[j]=cn;
    }
  }
  cn=A[i+1];
  A[i+1]=A[r];
  A[r]=cn;
  return i+1;
}

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

using namespace std;

#define all(x) x.begin(), x.end()
#define sz(x) (int) x.size()
#define pb push_back
#define endl '\n'
#define snd second
#define fst first
#define fastio cin.tie(NULL),cout.sync_with_stdio(true)

typedef long long int ll;
typedef unsigned long long int ull;
typedef vector <int> vi;
typedef pair <ll,int> ii;
typedef pair <ii,int> iii;

const int mod = 1e9 + 7;
const int N = 100005;

ll w[N], v[N], dp[N];

int main(){
	fastio;
    int n,p;
    cin >> n >> p;
    for(int i = 0; i < n; i++)
        cin >> w[i] >> v[i];
    for(int i = 0; i < n; i++){ // try insert on the knap the ith element
        for(int j = p-w[i]; j >= 0; j--){ // iterate over all possible available weights if i put the ith element
            dp[j + w[i]] = max(dp[j + w[i]], dp[j] + v[i]);
        }
    }
    ll ans = 0;
    for(int i = 0; i <= p; i++)
        ans = max(ans, dp[i]);
    cout << ans << endl;
}


Measured memory_bytes: 4368
#include <bits/stdc++.h>
 
using namespace std;
 
#define int long long int
 
int32_t main(){
 
	unordered_map <int, int> m;
	unordered_map <int, int>:: iterator itr;
	int n, i,sum = 0;
	cin >> n;
	vector<int> v(n);
 
	for(i=0; i<n; i++){
 
		cin >> v[i];
		itr  = m.find(v[i]);
		if(itr == m.end())
			m.insert({v[i], 1});
		else
			itr->second++;
	}
 
	for(itr = m.begin(); itr != m.end(); itr++){
		if(itr->second > 1)
			sum += itr->second * (itr->second - 1) / 2;
	}
 
	for( i=0; i<n; i++){
 
		itr = m.find(v[i]);
 
		if(itr->second > 1)
			cout<< sum - (itr->second - 1) ;
		else
			cout<<sum;
		cout<<endl;
	}
 
	return 0;
}

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

int main(){
  int a, b, c, hi, lo;
  cin >> a>>b>>c;

  if(a>b){
    hi = a;
    lo = b;
  }
  else{
    hi = b;
    lo = a;
  }

  if(lo<c && c<hi)
    cout<<"Yes"<<endl;
  else
    cout<<"No"<<endl;
}


Measured memory_bytes: 256
#include<iostream>
#include<vector>
#define all(v) v.begin(),v.end()
#define pb push_back
#define loop(i,a,b) for(int i=a;i<b;i++)
#define rep(i,a) loop(i,0,a)
#define INF 1e9
using namespace std;
int a,b,c;
vector<int> l;

int abs(int a){
	return (a>0)?a:-a;
}

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

int func(int cnt,int sa,int sb,int sc,int ca,int cb,int cc){
	if(cnt==-1){
		if(min(sa,min(sb,sc))>0)return abs(a-sa)+abs(b-sb)+abs(c-sc);
		else return INF;
	}
	int c[4];
	c[0]=func(cnt-1,sa+l[cnt],sb,sc,ca+1,cb,cc)+(ca==0?0:10);
	c[1]=func(cnt-1,sa,sb+l[cnt],sc,ca,cb+1,cc)+(cb==0?0:10);
	c[2]=func(cnt-1,sa,sb,sc+l[cnt],ca,cb,cc+1)+(cc==0?0:10);
	c[3]=func(cnt-1,sa,sb,sc,ca,cb,cc);
	return min(min(c[0],c[1]),min(c[2],c[3]));
}

int main(){
	int n;
	cin>>n>>a>>b>>c;
	int tmp;
	rep(i,n){
		cin>>tmp;
		l.pb(tmp);
	}
	cout<<func(n-1,0,0,0,0,0,0)<<endl;
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
long long x;
int main()
{
	cin>>x;
	for(int i=1;;i++)
	{
		x-=i;
		if(x<=0)
		{
			cout<<i<<endl;
			return 0;
		}
	}
	return 0;
}

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

const int N = 1e5+7;
vector<pair<int, int>> cols[N], rows[N];
vector<pair<int, int>> adj[N];
long long rowbound[N], colbound[N];

bool bad;
bool vis[N];
int id[N];
long long value[N], root[N];
long long dfs(int u, long long val, int s) {
    assert(!vis[u]);
    vis[u] = 1;
    value[u] = val;
    id[u] = s;

    long long ans = value[u];

    for (auto pr: adj[u]) {
        long long v = pr.first;
        long long d = pr.second;

        if (!vis[v])    ans = min(ans, dfs(v, val+d, s));
        if (value[v] != val+d)  bad = true;
    }
    return ans;
}

bool okay(vector<pair<int, int>> *rows, int R, int C, long long *bound) {
    for (int i=1; i<=C; i++) adj[i].clear(), vis[i] = 0;

    for (int i=1; i<=R; i++) {
        for (int j=1; j<rows[i].size(); j++) {
            int x = rows[i][j-1].first, y = rows[i][j].first;
            int d = rows[i][j].second - rows[i][j-1].second;
            adj[x].push_back({y, d});
            adj[y].push_back({x, -d});
//
//            cout<<x << " to " << y<<" "<<d<<endl;
//            cout<<y << " to " << x<<" "<<-d<<endl;
        }
    }
    bad = false;
    for (int i=1; i<=C; i++) {
        if (vis[i])    continue;
        long long mn = dfs(i, 0, i);
        root[i] = mn;
//        cout<<"Comp at "<<i<<" "<<mn<<endl;
    }

    for (int i=1; i<=C; i++) {
        long long lo = value[i] - root[id[i]];
        bound[i] = lo;
//        cout<<"Bound "<<i<<" "<<value[i]<<" "<<id[i]<<" "<<bound[i]<<endl;
        assert(bound[i] >= 0);
    }
    return !bad;
}

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

    int R, C;
    cin>>R>>C;

    int n;
    cin>>n;

    vector<tuple<int, int, int>> cells;
    for (int i=1; i<=n; i++) {
        int x, y, v;
        cin>>x>>y>>v;
        rows[x].push_back({y, v});
        cols[y].push_back({x, v});
        cells.push_back({x, y, v});
    }

    bool good = okay(rows, R, C, colbound) && okay(cols, C, R, rowbound);

    for (auto tp: cells) {
        int x = get<0> (tp);
        int y = get<1> (tp);
        int v = get<2> (tp);

        good &= (rowbound[x]<=v && colbound[y]<=v);
    }
    if (good)   cout<<"Yes\n";
    else        cout<<"No\n";
}


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

int main() {
  int n;
  cin >> n;
  vector<int> h(n);
  int ans = 1;
  rep(i, n) cin >> h[i];
  int mx = h[0];
  rep(i, n-1){
    if(mx <=  h[i+1]) {
      mx = h[i + 1];
      ans++;
    }
  }
  cout << ans << endl;
}

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

class Main {
	static BufferedReader br = new BufferedReader(new InputStreamReader(
			System.in));
	static StringBuilder out = new StringBuilder();

	public static void main(String[] args) throws IOException {
		int n = Integer.parseInt(br.readLine());
		int[] A = new int[n];
		String[] in = br.readLine().split(" ");
		for (int i = 0; i < n; i++)
			A[i] = Integer.parseInt(in[i]);
		int   sw = 0;

	        int t, min;
	        for(int i=0; i<n; ++i) {
	            min=i;
	            for(int j=i; j<n; ++j) {
	                if(A[j]<A[min])  min = j;
	            }
	            if(i!=min) {
	                t = A[i];
	                A[i] = A[min];
	                A[min] = t;
	                ++sw;
	            }
	        }
		for (int k = 0; k < n; k++) {
			if (k > 0)
				System.out.print(" ");
			System.out.print(A[k]);
		}
		System.out.print("\n");
		System.out.println(sw);
	}
}

Measured memory_bytes: 17056
import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;

public class Main{
  public static void main(String[] args){
	  Scanner sc = new Scanner(System.in);
	  long n=sc.nextLong();
	  List<Long> l=divisorEnum(n);
	  long res=0;
	  if(l.size()%2==0) {
		 String s1=String.valueOf(l.get(l.size()/2));
		 String s2=String.valueOf(l.get(l.size()/2-1));
		 res=Math.max(s1.length(), s2.length());
	  }else {
		  String s=String.valueOf(l.get(l.size()/2));
		  res=s.length();
	  }
	  System.out.println(res);

  }
	public static List<Long> divisorEnum(long n) {
		List<Long> l=new ArrayList<>();
		for(long i=1;i<=Math.sqrt(n);i++) {
			if(n%i==0) {
				l.add(i);
				if(i!=Math.sqrt(n))l.add(n/i);
			}
		}
		l.sort(null);
		return l;
	}
}



Measured memory_bytes: 22996
#include <iostream>
#include <vector>
#include <algorithm>
#include <climits>
#include <type_traits>


namespace Jin {
	template<class T, class Func>
	class SegmentTree {
	private:
		std::vector<T> data;
		size_t height;
		size_t bottom_size;
		Func func;
		T invailed;

		T  get(size_t l, size_t r, size_t k, size_t left, size_t right) const {
			if (right <= l || r <= left)return invailed;
			if (l <= left && right <= r)return data[k];
			T a = get(l, r, k * 2 + 1, left, (left + right) / 2);
			T b = get(l, r, k * 2 + 2, (left + right) / 2, right);
			return func(a, b);
		}

	public:
		template<class Itr>
		SegmentTree(Itr first, Itr last, Func func, T invailed) : func(func), invailed(invailed) {
			size_t dif = std::distance(first, last);
			bottom_size = 1;
			height = 1;
			while (bottom_size < dif) {
				bottom_size <<= 1;
				++height;
			}
			data.resize(2 * bottom_size - 1, invailed);
			for (size_t i = 0; i < dif; ++i, ++first)update(i, *first);
		}

		void update(size_t i, int value) {
			i += bottom_size - 1;
			data[i] = value;
			while (i > 0) {
				i = (i - 1) / 2;
				data[i] = func(data[i * 2 + 1], data[i * 2 + 2]);
			}
		}

		T get(size_t l, size_t r) const {
			return get(l, r, 0, 0, bottom_size);
		}

		void show()const {
			for (size_t i = 0; i < 2 * bottom_size - 1; ++i) {
				std::cout << data[i] << ", ";
				if (!((i + 2) & (i + 1)))std::cout << '\n';
			}
		}

	};

	template<class T, class Itr, class Func>
	auto make_segment_tree(Itr first, Itr last, Func func, T init) {
		return SegmentTree<T, Func>(first, last, func, init);
	}

}

using namespace std;
using ll = long long;

int main() {

	cin.tie(nullptr); ios::sync_with_stdio(false);

	int N, Q; cin >> N >> Q;
	string S; cin >> S;
	vector<int> AC(N, 0); for (int i = 1; i < N; i++) {
		if (S[i - 1] == 'A' && S[i] == 'C')AC[i] = 1;
	}

	auto seg = Jin::make_segment_tree(AC.begin(), AC.end(), [](int a, int b) {return a + b; }, 0);

	for (size_t i = 0; i < Q; i++)
	{
		int l, r; cin >> l >> r;
		
		cout << seg.get(l, r) << endl;
	}

	return 0;

}

Measured memory_bytes: 2512
#include <stdio.h>
int fibonacci(int);
int F[50];
int main() {

  int n,i;
  for(i=0;i<50;i++) F[i]=0;

  scanf("%d",&n);
  fibonacci(n);

  printf("%d\n",F[n]);

  return 0;
}
int fibonacci(int n)
{
  if(n==0 || n==1) return F[n]=1;

  if(F[n]!=0) return F[n];
  return F[n]=fibonacci(n-2)+fibonacci(n-1);
}

Measured memory_bytes: 596