akhauriyash/Code-Regression huggingface dataset:
N = int(input())
A = [int(i) for i in input().split()]
money = 1000
stocks = 0
for i in range(N-1):
    if A[i] < A[i+1]:
        stocks += money//A[i]
        money %= A[i]
    elif A[i] > A[i+1]:
        money += stocks*A[i]
        stocks = 0
print(money+stocks*A[-1])

Measured memory_bytes: 61784
input_list = list(map(int, input().split()))
n = input_list[0]
a = input_list[1]
b = input_list[2]

clear_list = []
for i in range(1, n+1):

    # 各桁の合計値を出す
    str_n = str(i)
    str_n_array = list(map(int, str_n))

    if a <= sum(str_n_array) <= b:
        clear_list.append(i)
print(sum(clear_list))

Measured memory_bytes: 41708
#include <cstdio>
#include <iostream>
#include <set>
#include <map>
#include <vector>
#include <algorithm>
#include <utility>
#include <string>
#include <cmath>
#include <iomanip>
#include <deque>
#include <queue>
#include <unordered_map>
typedef long long ll;
#define rep(i,n) for(int i=0;i<n;i++)

using namespace std;
ll intpow(ll N, ll P){
    if(P==0) return 1;
    if(P%2==0){
        ll t = intpow(N, P/2);
        return t*t;
    }
    return N * intpow(N, P-1);
}
ll modpow(ll N, ll P,ll k){
    if(P==0) return 1;
    if(P%2==0){
        ll t = modpow(N, P/2,k)%k;
        return t*t%k;
    }
    return N * modpow(N, P-1,k)%k;
}
ll modkai(ll n,ll m,ll k){//n*(n-1)*(n-2)*...(m+1)%k
    if(n == m)return 1;
    return modkai(n-1,m,k)*n%k;
}
ll mod_cnb(ll n,ll m,ll k){//nCm%k,kは十分大きい素数
  int m_=modkai(m,0,k);
  return modkai(n,n-m,k)*modpow(m_,k-2,k)%k;
}
ll gcd(ll n,ll m){
    ll n_ = max(n,m);
    ll m_ = min(n,m);
    if(n_%m_ == 0)return m_;
    return gcd(m_,n_%m_);
}
ll lcm(ll n,ll m){
    return n*m/gcd(n,m);
}
int main(){
    int n,k;cin>>n>>k;
    string s;cin>>s;
    int rcnt=0;
    int ans=0;
    rep(i,n-1){
        if(s[i]==s[i+1])ans++;
        else rcnt++;
    }
    if(rcnt/2>=k)ans+=k*2;
    else ans=n-1;
    cout<<ans<<endl;
   
}

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

const int mx[4] = {1, -1, 0, 0};
const int my[4] = {0, 0, 1, -1};
char map[12][12];

void func(int x, int y){
	if(x >= 0 && x < 12 && y >= 0 && y < 12 && map[x][y] == '1'){
		map[x][y] = '0';
		for(int i = 0; i < 4; ++i){
			func(x + mx[i], y + my[i]);
		}
	}
}

int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	
	char n;
	while(cin >> n){
		for(int i = 0; i < 12; ++i){
			for(int j = 0; j < 12; ++j){
				if(i == 0 && j == 0)
					map[i][j] = n;
				else
					cin >> map[i][j];
			}
		}
	
		int ans = 0;
		for(int i = 0; i < 12; ++i){
			for(int j = 0; j < 12; ++j){
				if(map[i][j] == '1'){
					func(i, j);
					ans++;
				}
			}
		}
		
		cout << ans << endl;
	}
	
	return 0;
}

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

using namespace std;

bool judgePnd(const string str)
{
        int i, j;

        i = 0;
        j = str.length() - 1;
        while (i < j) {
                if (str[i] - str[j]) {
                        break;
                }
                i++; j--;
        }

        return (i >= j) ? true : false;
}

int main()
{
        int ans = 0;
        string str;

        while (cin >> str) {
                bool b = judgePnd(str);
                if (b)
                        ans++;
        }

        cout << ans << endl;

        return 0;
}

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

const vector<int> DRS = {0, 1, 0, -1}, DCS = {1, 0, -1, 0};

int main()
{
    int H, W, N;
    cin >> H >> W >> N;
    vector<int> a(N);
    for (int i = 0; i < N; i++)
    {
        cin >> a.at(i);
    }

    vector<vector<int>> c = vector<vector<int>>(H, vector<int>(W, 0));
    int cr = 0, cc = 0, cd = 0;

    for (int i = 0; i < N; i++)
    {
        int color = i + 1, cnt = a.at(i);
        for (int j = 0; j < cnt; j++)
        {
            c.at(cr).at(cc) = color;
            int nr, nc;
            for (int k = 0; k < 4; k++)
            {
                nr = cr + DRS.at(cd);
                nc = cc + DCS.at(cd);
                if (0 <= nr && nr < H && 0 <= nc && nc < W && c.at(nr).at(nc) == 0)
                    break;
                cd = (cd + 1) % 4;
            }
            cr = nr;
            cc = nc;
        }
    }

    for (int i = 0; i < H; i++)
    {
        for (int j = 0; j < W; j++)
        {
            cout << c.at(i).at(j) << " ";
        }
        cout << endl;
    }
}

Measured memory_bytes: 384
#include <iostream>
#include <vector>
#include <algorithm>
// #include <string>
// #include <set>
// #include <cmath>
// #include <map>
// #include <iomanip>

#define MOD 1000000007

using namespace std;
typedef unsigned long long ull;
// typedef long long ll;

// void p() {
//     cout << "\n";
// }
// template<class Head, class... Body>
// void p(Head head, Body... body) {
//     cout << head << ",";
//     p(body...);
// }


int main(int argc, char const *argv[]) {
    int N;
    ull T;
    cin >> N >> T;

    vector<ull> t(N);
    for (int i = 0; i < N; ++i) {
        cin >> t[i];
    }
    ull ans = 0;
    for (int i = 0; i < N-1; ++i) {
        ans += min(T, t[i+1] - t[i]);
    }
    ans += T;
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 1792
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<cmath>
#define rep(i,n) for(int i = 0;i < (n); ++i)
#define ANS(a, b) a*a*a*a*a - b*b*b*b*b
using namespace std;


typedef long long LL;
typedef long double LD;

int main(void){
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    LL x;
    cin >> x;
    bool flag = true;
    int dis = 0;
    int b;
    LL ans;
    while(flag){
        dis++;
        for(int a = -118; a <= 119; a++){
            b = a - dis;
            ans = ANS(a, b);
            if(ans == x){
                cout << a << " " << b << endl;
                return 0;
            }
        }
    }
}

Measured memory_bytes: 3636
#include <iostream>
#include <vector>
#include <algorithm>
#include <utility>
#include <set>
int n, t;
std::vector<int> a, f;
std::vector<std::vector<std::vector<long long>>> dp;
void dfs(int d, int s, int l, int r) {
    if (d == n - 1)
        return;
    f[s << 1] = l;
    f[s << 1 | 1] = r;
    dfs(d + 1, s << 1, l, l + r);
    dfs(d + 1, s << 1 | 1, l + r, r);
}
long long solve(int l, int r, int x) {
    if (r - l == 1)
        return 0;
    if (dp[l][r][x] != -1)
        return dp[l][r][x];
    long long ans = 1'000'000'000'000'000'000;
    for (int m = l + 1; m < r; ++m)
        ans = std::min(ans, solve(l, m, x << 1) + solve(m, r, x << 1 | 1) + 1LL * a[m] * (f[x << 1] + f[x << 1 | 1]));
    return dp[l][r][x] = ans;
}
int main() {
    std::ios::sync_with_stdio(false);
    std::cin.tie(nullptr);
    std::cin >> n;
    a.resize(n);
    f.resize(1 << (n - 1));
    dp.assign(n, std::vector<std::vector<long long>>(n));
    for (int l = 0; l < n; ++l)
        for (int r = l + 2; r < n; ++r)
            dp[l][r].assign(1 << (n - r + l), -1);
    for (int i = 0; i < n; ++i)
        std::cin >> a[i];
    dfs(1, 1, 1, 1);
    std::cout << a[0] + a[n - 1] + solve(0, n - 1, 1) << "\n";
    return 0;
}

Measured memory_bytes: 16384
#include <iostream>
#include <iomanip>
#include <string>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <algorithm>
#include <numeric>
#include <cmath>
#include <cassert>

using namespace std;
typedef long long LL;
template <typename F, typename S> std::ostream& operator<<(ostream& os, const pair<F,S>& p) {
    os << "(" << p.first << "," << p.second << ")"; return os; }
template <typename T> ostream& operator<<(ostream& os, const vector<T>& v) {
    os << "["; for(const T& a: v){ os << a << ", "; } os << "]"; return os; }
template <typename K, typename V> ostream& operator<<(ostream& os, const map<K,V>& m) {
    os << "{"; for(const auto& p: m){ os << p.first <<":"<< p.second << ", "; } os << "]"; return os; }


int main(){
    LL n, m;
    cin >> n >> m;
    vector<LL> ref_cnt(n);
    vector<vector<LL>> parent_cand(n);
    vector<vector<LL>> children(n);
    for(LL i = 0; i < n-1+m; ++i){
        LL a, b;
        cin >> a >> b;
        --a; --b;
        ref_cnt[a] += 1;
        parent_cand[b].push_back(a);
        children[a].push_back(b);
    }
    vector<LL> st;
    for(LL i = 0; i < n; ++i){
        if(ref_cnt[i] == 0) st.push_back(i);
    }

    vector<LL> answer(n, 0);
    while(!st.empty()){
        LL cur = st.back();
        for(LL c: children[cur]){
            if(answer[c] == 0){
                answer[c] = cur+1;
            }
        }
        //cerr << "cur=" << cur << endl;
        st.pop_back();
        for(LL p: parent_cand[cur]){
            --ref_cnt[p];
            if(ref_cnt[p] == 0){
                //cerr << "cur=" << cur << " parent=" << p+1 << endl;
                st.push_back(p);
            }
        }
    }


    for(LL i = 0; i < n; ++i){
        cout << answer[i] << endl;
    }
    return 0;
}



Measured memory_bytes: 13312
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.Arrays;
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;
        InputReader    in                      = new InputReader(inputStream);
        PrintWriter      out                    = new PrintWriter(outputStream);
        Task                 solver               = new Task();
        solver.solve(1, in, out);
        out.close();
    }

    static class Task {
        public void solve(int testNumber, InputReader in, PrintWriter out) {
        	int N = in.nextInt();
        	String[] W = new String[N];
        	
        	String str = "Yes";

    		for(int i = 0; i < N; i++) {
    			W[i] = in.next();
    			for(int j = 0; j < i; j++) {
        			if(W[i].equals(W[j])) {
        				str = "No";
        				break;
        			}else if(!(W[i - 1].substring(W[i - 1].length() -1).equals(W[i].substring(0, 1)))) {
        				str = "No";
        				break;
        			}
    			}
    		}
    		
    		out.println(str);

        }
    }

    static class InputReader {
        public BufferedReader reader;
        public StringTokenizer tokenizer;

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

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

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

    }
}



Measured memory_bytes: 23252
import java.util.*;

public class Main{
    public static void main(String[]args){
        Scanner sc=new Scanner(System.in);
        int n=sc.nextInt();
        int y=sc.nextInt();
        int a=-1;
        int b=-1;
        int c=-1;
        for(int i=0;i<=n;i++){
            for(int j=0;j<=n;j++){
                    if(y/1000-10*i-5*j==n-j-i && n-j-i>=0){
                        a=i; b=j; c=n-i-j;
                        break;
                }
            }
        }
        System.out.println(a+" "+b+" "+c);
        
    }
}

Measured memory_bytes: 23764
ans=[]
N=int(input())
N-=1
count=0
for l in range(1,15):
    if N>=26**l:
        N-=26**l
        continue
    count=l
    break
for i in range(count):
    d=N%26
    ans.append(chr(d+ord("a")))
    N//=26
ans.reverse()
print(*ans,sep="")

Measured memory_bytes: 9068
use proconio::{fastout, input};
use std::io::*;
use std::str::FromStr;

use std::cmp::{max, min};

fn main() {
    input! {
        n: usize,
        p: [usize; n],
    }
    let mut cnt = 0;
    for i in 0..p.len() - 1 {
        if p[i] != i + 1 {
            cnt += 1;
        }
    }
    // println!("{}", cnt);

    if cnt > 2 {
        println!("NO");
    } else {
        println!("YES")
    }
}


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

int main() {
    long long int n,j=0;
    cin>>n;
    long long int s=0;
    //s+=n-1;
    //s+=n/2;
    for(int i=1;i<n;i++)
    {
        if(n%i==0)
        j++;
    }
    for(int i=1;i<n;i++)
    {
        //if(ni!=0)
        s+=n/i;
    }
    cout<<s-j;
	
	
	return 0;
}


Measured memory_bytes: 3632
#include<cstdio>
#include<algorithm>
#include<cstring>
#include<cctype>
using namespace std;
const int maxM=5010,maxn=1010,inf=0x3f3f3f3f;
int f[maxn],g[2][maxM],n,first[maxn],tot,v[maxn];
struct edge{int v,from;}e[maxn];


int read(){
    char c;int s=0,t=1;
    while(!isdigit(c=getchar()))if(c=='-')t=-1;
    do{s=s*10+c-'0';}while(isdigit(c=getchar()));
    return s*t;
}
void insert(int u,int v){tot++;e[tot].v=v;e[tot].from=first[u];first[u]=tot;}
int min(int a,int b){return a<b?a:b;}
void dfs(int x){
	for(int i=first[x];i;i=e[i].from)dfs(e[i].v);
	memset(g[0],0x3f,sizeof(g[0]));
	int X=0;
	g[X][0]=0;
	for(int i=first[x];i;i=e[i].from){
		int y=e[i].v;
		X=1-X;
		memset(g[X],0x3f,sizeof(g[X]));
		for(int j=0;j<=v[x];j++){
			if(j-v[y]>=0)g[X][j]=min(g[X][j],g[1-X][j-v[y]]+f[y]);
			if(j-f[y]>=0)g[X][j]=min(g[X][j],g[1-X][j-f[y]]+v[y]);
		}
	}
	for(int i=0;i<=v[x];i++)f[x]=min(f[x],g[X][i]);
}
	
int main(){
	n=read();
	for(int i=2;i<=n;i++){
		int p=read();
		insert(p,i);
	}
	for(int i=1;i<=n;i++)v[i]=read();
	memset(f,0x3f,sizeof(f));
	dfs(1);
	//for(int i=1;i<=n;i++)printf("f[%d]=%d\n",i,f[i]);
	if(f[1]<inf)printf("POSSIBLE");else printf("IMPOSSIBLE");
	return 0;
}

Measured memory_bytes: 384
#include<bits/stdc++.h>
#define rep(i, n) for (int i=0;i<(n);i++)
using namespace std;
typedef long long ll;
 
 /*約数列挙アルゴリズム*/
vector< ll > divisor(ll n) {
  vector< ll > ret;
  for(ll i = 1; i * i <= n; i++) {
    if(n % i == 0) {
      //ret.push_back(i);
      ll a = n/i;
      if(a>i+1) ret.push_back(n / i-1);
    }
  }
  return (ret);
}


int main(void){
    ll n;
    cin>>n;
    vector<ll> v=divisor(n);
    ll ans=accumulate(v.begin(), v.end(), 0LL);
    cout<<ans<<endl;
    return 0;
}

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

int main(){
    while(1){
        int h, w;
        cin >> h >> w;
        if(h==0 && w==0) break;
        for(int i=0; i<w; i++){
            cout << "#";
        }
        cout << endl;
        for(int i=0; i<h-2; i++){
            cout << "#";
            for(int j=0; j<w-2; j++){
                cout << ".";
            }
            cout << "#" << endl;
        }
        for(int i=0; i<w; i++){
            cout << "#";
        }
            cout << endl;
            cout << endl;
    }
    return 0;
}


Measured memory_bytes: 3080
#include <iostream>

using namespace std;

int main(){
    
   int color_1 = (cin >> (color_1), color_1),
        color_2=(cin >> (color_2), color_2),
        color_3=(cin >> (color_3), color_3);
  
  if(color_1==color_2 && color_1==color_3){
 cout << "1";
  }
  else if(color_1==color_2 || color_1==color_3 || color_2==color_3){
 cout << "2";
  }
  else{
   cout << "3";
  }

  return 0;
}

Measured memory_bytes: 256
# -*- coding: utf-8 -*-

#############
# Libraries #
#############

import sys
input = sys.stdin.readline

import math
from collections import deque
from fractions import gcd
from functools import lru_cache


#############
# Constants #
#############

MOD = 10**9+7
INF = float('inf')

#############
# Functions #
#############

######INPUT######
def inputI(): return int(input().strip())
def inputS(): return input().strip()
def inputIL(): return list(map(int,input().split()))
def inputSL(): return list(map(str,input().split()))
def inputILs(n): return list(int(input()) for _ in range(n))
def inputSLs(n): return list(input().strip() for _ in range(n))
def inputILL(n): return [list(map(int, input().split())) for _ in range(n)]
def inputSLL(n): return [list(map(str, input().split())) for _ in range(n)]

#####Inverse#####
def inv(n): return pow(n, MOD-2, MOD)

######Combination######
kaijo_memo = []
def kaijo(n):
  if(len(kaijo_memo) > n):
    return kaijo_memo[n]
  if(len(kaijo_memo) == 0):
    kaijo_memo.append(1)
  while(len(kaijo_memo) <= n):
    kaijo_memo.append(kaijo_memo[-1] * len(kaijo_memo) % MOD)
  return kaijo_memo[n]

gyaku_kaijo_memo = []
def gyaku_kaijo(n):
  if(len(gyaku_kaijo_memo) > n):
    return gyaku_kaijo_memo[n]
  if(len(gyaku_kaijo_memo) == 0):
    gyaku_kaijo_memo.append(1)
  while(len(gyaku_kaijo_memo) <= n):
    gyaku_kaijo_memo.append(gyaku_kaijo_memo[-1] * pow(len(gyaku_kaijo_memo),MOD-2,MOD) % MOD)
  return gyaku_kaijo_memo[n]

def nCr(n,r):
  if(n == r):
    return 1
  if(n < r or r < 0):
    return 0
  ret = 1
  ret = ret * kaijo(n) % MOD
  ret = ret * gyaku_kaijo(r) % MOD
  ret = ret * gyaku_kaijo(n-r) % MOD
  return ret

######Factorization######
def factorization(n):
    arr = []
    temp = n
    for i in range(2, int(-(-n**0.5//1))+1):
        if temp%i==0:
            cnt=0
            while temp%i==0:
                cnt+=1
                temp //= i
            arr.append([i, cnt])
    if temp!=1:
        arr.append([temp, 1])

    if arr==[]:
        arr.append([n, 1])
    return arr

#####LCM#####
def lcm(a, b):
    return a * b // gcd (a, b)

#############
# Main Code #
#############

N = inputI()
S = inputS()

r=0
g=0
b=0
for i in S:
  if i =="R":
    r+=1
  elif i =="G":
    g+=1
  else:
    b+=1

count = 0
for d in range(1,(N-1)//2+1):
  for i in range(N-2*d):
    if S[i]!=S[i+d] and S[i]!=S[i+2*d] and S[i+d]!=S[i+2*d]:
      count += 1

print(r*b*g-count)

Measured memory_bytes: 73448
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sysin = new Scanner(System.in);
		final String s = sysin.next();
		sysin.close();

		System.out.println(judge(s.toCharArray()));
	}

	private static String judge(char[] chars) {
		for (int i = 1; i < chars.length; i++) {
			if (chars[i] == chars[i - 1]) {
				return "Bad";
			}
		}

		return "Good";
	}
}


Measured memory_bytes: 21844
import sys

sys.setrecursionlimit(10 ** 7)
input = sys.stdin.readline
f_inf = float('inf')
mod = 10 ** 9 + 7


def resolve():
    x, y = map(int, input().split())
    print(-1 if x % y == 0 else x)


if __name__ == '__main__':
    resolve()


Measured memory_bytes: 2940
program ABC149B
    implicit none
    integer(16)::A,B,K
    read(5,*)A,B,K

    if(K<A)then
        print'(i0)',A-K,B
    else
        print'(i0,1x,i0)',0,max(0,A+B-K)
    end if
end program ABC149B

Measured memory_bytes: 256
#include <stdio.h>
#define N 100005

typedef struct pro{
  char name[10];
  int time;
}data;

void enqueue(data );
data dequeue();

data Q[N];

int head=0,tail;

int main()
{
  int i,n,q,cnt,t=0;
  scanf("%d%d",&n,&q);
  for(i=0;i<n;i++){
    scanf("%s%d",Q[i].name,&Q[i].time);
  }
  tail = n;
  while(cnt != n){
    if(Q[head].time > q){
      Q[head].time -= q;
      t+=q;
      enqueue(dequeue());
    }
    else {
      t += Q[head].time;
      printf("%s %d\n",Q[head].name,t);
      dequeue();
      cnt++;
    }
  }
  return 0;
}

void enqueue(data x){
  Q[tail] = x;
  tail = (tail+1)%N;
}

data dequeue(){
  data tmp;
  tmp = Q[head];
  head = (head+1)%N;
  return tmp;
}



Measured memory_bytes: 3344
#include <bits/stdc++.h>
using ll = long long;
using namespace std;
ll mod=1e9+7;
ll inf=1e10;

int main(){
  int N,X[200000],Y[200000];
  cin>>N;
  for (int i(0);i<N;i++) cin>>X[i];
  for (int i(0);i<N;i++) Y[i]=X[i];
  sort(X,X+N);
  int kouho1 = X[N/2],kouho2 = X[N/2-1];
  for (int i(0);i<N;i++){
    if (Y[i] >= kouho1) cout << kouho2 << endl;
    else if (Y[i] <= kouho2) cout << kouho1 << endl;
  }
  return 0;
}


Measured memory_bytes: 3712
#include<bits/stdc++.h>
using namespace std;
int main()
{
	int a,b,c;
	cin>>a>>b>>c;
	cout<<a<<" "<<b<<" "<<3*c-a-b<<endl;
	cout<<4*c-2*a-b<<" "<<c<<" "<<2*a+b-2*c<<endl;
	cout<<a+b-c<<" "<<2*c-b<<" "<<2*c-a<<endl;
	return 0;
}

Measured memory_bytes: 256
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
const int INF = 1e9;
const ll LINF = 1e18;
inline ll gcd(ll a, ll b) { return b ? gcd(b, a%b) : a; }
inline ll lcm(ll a, ll b) { return a / gcd(a, b)*b; }
template<class S,class T> ostream& operator << (ostream& out,const pair<S,T>& o){ out << "(" << o.first << "," << o.second << ")"; return out; }
template<class T> ostream& operator << (ostream& out,const vector<T>& V){ for(int i = 0; i < V.size(); i++){ out << V[i]; if(i!=V.size()-1) out << " ";} return out; }
template<class T> ostream& operator << (ostream& out,const vector<vector<T> >& Mat){ for(int i = 0; i < Mat.size(); i++) { if(i != 0) out << endl; out << Mat[i];} return out; }
template<class S,class T> ostream& operator << (ostream& out,const map<S,T>& mp){ out << "{ "; for(auto it = mp.begin(); it != mp.end(); it++){ out << it->first << ":" << it->second; if(mp.size()-1 != distance(mp.begin(),it)) out << ", "; } out << " }"; return out; }
template<typename T>vector<T> make_v(size_t a){return vector<T>(a);}
template<typename T,typename... Ts>auto make_v(size_t a,Ts... ts){return vector<decltype(make_v<T>(ts...))>(a,make_v<T>(ts...));}
template<typename T,typename V> typename enable_if<is_class<T>::value==0>::type fill_v(T &t,const V &v){t=v;}
template<typename T,typename V> typename enable_if<is_class<T>::value!=0>::type fill_v(T &t,const V &v){for(auto &e:t) fill_v(e,v);}
/*
 <url:https://atcoder.jp/contests/abc156/tasks/abc156_c>
 問題文============================================================
 C - Rally
 =================================================================
 解説=============================================================
 
 ================================================================
 */

template<class Type>
Type solve(Type res = Type()){
    ll N; cin >> N;
    vector<ll> X(N); for(auto& in:X) cin >> in;
    sort(X.begin(),X.end());
    
    vector<ll> A(101);
    for(auto x:X){
        for(int i = 0; i <= 100; i++){
            A[i] += (x-i)*(x-i);
        }
    }
    res = *min_element(A.begin(), A.end());
    return res;
}
int main(void) {
    cin.tie(0); ios_base::sync_with_stdio(false);
    // solve(0);
    cout << fixed << setprecision(15) << solve<ll>() << endl;
    return 0;
}


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

bool IsPrime(int num)
{
    if (num < 2) return false;
    else if (num == 2) return true;
    else if (num % 2 == 0) return false; // 偶数はあらかじめ除く

    double sqrtNum = sqrt(num);
    for (int i = 3; i <= sqrtNum; i += 2)
    {
        if (num % i == 0)
        {
            // 素数ではない
            return false;
        }
    }

    // 素数である
    return true;
}

int main() {
    // ifstream in("data1.txt");
    // cin.rdbuf(in.rdbuf());
    int N;
    cin >> N;
    if(IsPrime(N)){
        cout << N << endl;
        return 0;
    }

    for (int i = N+1; i < 500000; i++){
        if(IsPrime(i)){
            cout << i << endl;
            return 0;
        }
    }

}


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

int main(){
	int r, c, table[1000][1000], a;

	cin >> r >> c;

	for (int i = 0; i < r; i++){
		for (int j = 0; j < c; j++){
			table[i][j] = 0;
		}
	}

	for (int i = 0; i < r; i++){
		for (int j = 0; j < c; j++){
			cin >> table[i][j];
		}
	}

	for (int i = 0; i < r; i++){
		for (int j = 0; j < c; j++){
			table[i][c] += table[i][j];
		}
	}

	for (int i = 0; i < c; i++){
		for (int j = 0; j < r; j++){
			table[r][i] += table[j][i];
		}
	}

	for (int i = 0; i < r; i++){
		table[r][c] += table[i][c];
	}

	for (int i = 0; i < r + 1; i++){
		for (int j = 0; j < c; j++){
			cout << table[i][j] << " ";
		}
		cout << table[i][c] << endl;
	}

	return 0;
}


Measured memory_bytes: 3396
#include<stdio.h>
#include<stdlib.h>
#include<math.h>
#include<string.h>
typedef long long int ll;
void swap(ll *x,ll *y){ll temp;temp=*x;*x=*y;*y=temp;}
ll asc(const void *a,const void *b){return *(ll*)a-*(ll*)b;}
ll desc(const void *a,const void *b){return *(ll*)b-*(ll*)a;}
ll max(ll x,ll y){return x>y?x:y;}
ll min(ll x,ll y){return x>y?y:x;}

int main(){
    int a,b;
    int high[1000];
    scanf("%d %d",&a,&b);

    high[0]=1;
    for(int i=2;i<=999;i++){
        high[i-1]=high[i-2]+i;
    }
    printf("%d\n",high[b-a-1]-b);
    return 0;
}

Measured memory_bytes: 128
package main

import "fmt"

func main(){
	var a,b,n int
	fmt.Scan(&a,&b,&n)
	if b <= n+1 {
		fmt.Println(int(float64(float64(a)/float64(b))*float64(b-1)))
	} else {
		fmt.Println(int(float64(float64(a)/float64(b))*float64(n)))
	}
}


Measured memory_bytes: 1748
#include<bits/stdc++.h>
 
using namespace std;
using S = set<long long>;
using D = deque<long long>;
using L = vector<long long>;
using M = map<int,long long>;
using A = vector<vector<long long>>;
using Q = priority_queue<long long>;
using U = unordered_map<int,long long>; //mapとの違いはkeyの順番を保持していない

#define sorted(vector) sort(vector.begin(),vector.end()) //O(nlongn)
#define vmin(vector) *min_element(vector.begin(),vector.end()) //O(N)
#define vmax(vector) *max_element(vector.begin(),vector.end()) //O(N)
#define vsum(vector) accumulate(vector.begin(),vector.end(),0) //O(N)
#define vcount(vector,a) count(vector.begin(), vector.end(),a) //O(N)
#define bisect_left(vector,a) (lower_bound(vector.begin(),vector.end(),a)-vector.begin())
#define bisect_right(vector,a) (upper_bound(vector.begin(),vector.end(),a)-vector.begin())
#define vfind(vector,a) find(vector.begin(), vector.end(), a) != vector.end() //遅いからあんまり使うな
//存在確認はmap!!!!!!!!!!!!!
//__gcd(a,b)はコンパイラがGCC時のみ

int main(){
    ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    long long n;
    cin>>n;
    L l(n,0);
    
    for(int i=0  ;i<n  ;i++){
        cin>>l[i];
    }
    sorted(l);
    long long z=0;
    cout<<max(l[n/2]-l[n/2-1],z)<<endl;
}
    


Measured memory_bytes: 1024
import java.util.*;

public class Main {

    public static void main(String args[]) {

        // 入力
        Scanner sc = new Scanner(System.in);
        int n = Integer.parseInt(sc.next());
        String[] s = new String[n];
        for (int i = 0; i < n; i++) {
            s[i] = sc.next();
        }

        // 主処理
        long[] count = new long[5];
        for (int i = 0; i < s.length; i++) {
            if (s[i].startsWith("M")) {
                count[0]++;
            } else if (s[i].startsWith("A")) {
                count[1]++;
            } else if (s[i].startsWith("R")) {
                count[2]++;
            } else if (s[i].startsWith("C")) {
                count[3]++;
            } else if (s[i].startsWith("H")) {
                count[4]++;
            }
        }

        long[] array = Arrays.stream(count).filter(c -> 0 < c).toArray();
        long result = 0;

        if (3 <= array.length) {
            List<Long> list = new ArrayList<>();
            for (int i = 0; i < array.length; i++) {
                for (int j = i + 1; j < array.length; j++) {
                    for (int k = j + 1; k < array.length; k++) {
                        long num = array[i] * array[j] * array[k];
                        list.add(num);
                    }
                }
            }
            result = list.stream().mapToLong(c -> c).sum();
        }

        // 出力
        System.out.println(result);
        sc.close();
    }
}


Measured memory_bytes: 51840
#include <bits/stdc++.h>
#define int long long
#define ll long long
using ull = unsigned long long;
using namespace std;
const int INF = 1e10;
const int MOD = 1e9 + 7;
#define dump(x)                             \
    if (dbg) {                              \
        cerr << #x << " = " << (x) << endl; \
    }
#define overload4(_1, _2, _3, _4, name, ...) name
#define FOR1(n) for (ll i = 0; i < (n); ++i)
#define FOR2(i, n) for (ll i = 0; i < (n); ++i)
#define FOR3(i, a, b) for (ll i = (a); i < (b); ++i)
#define FOR4(i, a, b, c) for (ll i = (a); i < (b); i += (c))
#define FOR(...) overload4(__VA_ARGS__, FOR4, FOR3, FOR2, FOR1)(__VA_ARGS__)
#define FORR(i, a, b) for (int i = (a); i <= (b); ++i)
template <class T>
bool chmin(T& a, const T& b) {
    if (a > b) {
        a = b;
        return 1;
    } else
        return 0;
}
template <class T>
bool chmax(T& a, const T& b) {
    if (a < b) {
        a = b;
        return 1;
    } else
        return 0;
}
void Yes(bool flag = true) {
    if (flag)
        cout << "Yes" << endl;
    else
        cout << "No" << endl;
}
void No(bool flag = true) {
    Yes(!flag);
}
void YES(bool flag = true) {
    if (flag)
        cout << "YES" << endl;
    else
        cout << "NO" << endl;
}
void NO(bool flag = true) {
    YES(!flag);
}
#define pb push_back
#define mp make_pair
#define lb lower_bound
#define ub upper_bound
#define all(v) (v).begin(), (v).end()
#define SZ(x) ((int)(x).size())
#define P pair<int, int>
#define V vector<int>
//#define S set<int>
#define itn int
bool dbg = false;

int N, a[3030];
int dp[3030][3030];
bool check[3030][3030];

int f(int x, int y) {
    if (check[x][y])
        return dp[x][y];
    check[x][y] = true;
    if (x > y)
        return 0;
    int ret = max(f(x + 1, y) * -1 + a[x], f(x, y - 1) * -1 + a[y]);

    return dp[x][y] = ret;
}


void solve() {
    cout << f(0, N - 1) << endl;
}

signed main() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    cin >> N;
    FOR(N)
    cin >> a[i];


    solve();
    return 0;
}


Measured memory_bytes: 80256
#include<iostream>
#include<vector>
using namespace std;
vector<bool>isp(10000010);
int n;
int c;
main()
{
	int m=10000010;
	isp[0]=isp[1]=1;
	for(int i=2;i<m;i++)
	{
		if(!isp[i])
		{
			for(int j=i+i;j<m;j+=i)isp[j]=1;
		}
	}
	cin>>n;
	for(int i=3;i<=n;i++)
	{
		if(!isp[i]&&!isp[i+2])c+=2;
	}
	cout<<c<<endl;
}



Measured memory_bytes: 3984
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		
		int n = sc.nextInt();
		long[] a = new long[n];
		
		for(int i = 0; i < n; i++) {
			a[i] = sc.nextLong();
		}
		
		long sum = 1;
		long max = 1000000000000000000l;
		boolean chk = false;
		boolean zero = false;
		
		for(int i = 0; i < n; i++) {
			if(sum!= 0 && max / sum < a[i]) {
				chk = true;
			}
			if(a[i] == 0) {
				sum = 0;
				zero = true;
				break;
			}else {
				sum*= a[i];
			}
		}
		
		if( zero ) {
			System.out.println(0);
		}else if( chk ){
			System.out.println(-1);
		}else {
			System.out.println(sum);
		}
	}
}

Measured memory_bytes: 50932
#include <string>
#include <cstdio>
#include <map>
#include <vector>
#include <algorithm>
using namespace std;
typedef string key;

char b1[99],b2[99];
void main2(int n){
	map<key,vector<pair<key,long long>>>m;
	for(;n;n--){
		int d;
		scanf(" 1 %s = 10^%d %s",b1,&d,b2);
		string s1=b1,s2=b2;
		m[s1].emplace_back(s2,d);
		m[s2].emplace_back(s1,-d);
	}
	for(;!m.empty();){
		auto s=m.begin()->first;
		vector<pair<key,long long> >st={{s,0}};
		map<key,long long>memo={{s,0}};
		for(;!st.empty();){
			auto p=*st.rbegin();st.pop_back();
			auto cur=p.first;long long d=p.second;
			memo[cur]=d;
			for(auto &e:m[cur]){
				if(memo.find(e.first)==memo.end()){
					st.emplace_back(e.first,d+e.second);
				}else if(memo[e.first]!=d+e.second){
					puts("No");
					return;
				}
			}
		}
		for(auto &e:memo)m.erase(m.find(e.first));
	}
	puts("Yes");
}
int main(){int n;for(;~scanf("%d",&n)&&n;)main2(n);}

Measured memory_bytes: 2852
#include <bits/stdc++.h>
using namespace std;
typedef pair<int,int> P;
typedef pair<P,int> T;
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vll;
#define pb push_back
#define mp make_pair
#define eps 1e-9
#define INF 2000000000
#define LLINF 1000000000000000
#define sz(x) ((int)(x).size())
#define fi first
#define sec second
#define all(x) (x).begin(),(x).end()
#define sq(x) ((x)*(x))
#define rep(i,n) for(int (i)=0;(i)<(int)(n);(i)++)
#define repn(i,a,n) for(int (i)=(a);(i)<(int)(n);(i)++)
#define EQ(a,b) (abs((a)-(b))<eps)
template<class T> void chmin(T& a,const T& b){if(a>b)a=b;}
template<class T> void chmax(T& a,const T& b){if(a<b)a=b;}
struct Point{
	double x,y;
	Point(){}
	Point(double x,double y):x(x),y(y){}
	Point operator + (Point a){
		return Point(x+a.x,y+a.y);
	}
	Point operator - (Point a){
		return Point(x-a.x,y-a.y);
	}
	double dot(Point a){
		return x*a.x+y*a.y;
	}
	double det(Point a){
		return x*a.y-y*a.x;
	}
	double norm(){
		return sqrt(x*x+y*y);
	}
	double norm2(){
		return x*x+y*y;
	}
	void dump(){
		printf("x:%.12f y:%.12f\n",x,y);
	}
};
typedef Point Vector;
double f(double x){
	return x/(sqrt(1.0+x*x)-1.0);
}
double tan(Vector a,Vector b){
	if(abs(a.dot(b))<eps)return 1.0;
	return abs(f(a.det(b)/a.dot(b)));
}
Point v[3];
double solve(){
	Vector ab = v[1]-v[0];
	Vector ac = v[2]-v[0];
	Vector ba = v[0]-v[1];
	Vector bc = v[2]-v[1];
	return ab.norm()/(tan(ab,ac)+tan(ba,bc)+2.0);
}
void rotate(){
	Point tmp = v[2];
	for(int i=1;i>=0;i--)v[i+1]=v[i];
	v[0] = tmp;
}
int main(){
	for(int i=0;i<3;i++){
		int x,y;
		cin >> x >> y;
		v[i] = Point(x,y);
	}
	double ans = 0.0;
	for(int i=0;i<3;i++){
		ans = max(ans,solve());
		rotate();
	}
	printf("%.12f\n",ans);
	return 0;
}

Measured memory_bytes: 256
a,b,c,d = map(int,input().split())
dict = {}
dict[a] = 1
dict[b] = 1
dict[c] = 1
dict[d] = 1
if 1 in dict and 9 in dict and 7 in dict and 4 in dict:
    print("YES")
else:
    print("NO")


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

#define rep(i,a,b) for(ll i = (ll)(a); i < (ll)(b); i++)
#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define fill(x,v) memset(x,v,sizeof(x))
#define all(x) (x).begin(), (x).end()
#define trace(x) cerr << #x <<": " << x << endl
#define fastio ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);

typedef long long ll;
typedef unsigned long long ull;
typedef vector<ll> vi;
typedef pair<ll,ll> ii;
typedef vector<ii> vii;
typedef long double C;


vi arr,suma;

int main(){
    fastio;
    int n;
    cin >> n;
    suma.pb(0);
    ll a;
    rep(i,0,n){
        cin >> a;
        arr.pb(a);
        suma.pb(suma.back()+a);
    }
    ll suma1, suma2;
    vi::iterator it;
    ll val;
    ll p,q,r,s;
    ll maxi, mini;
    ll maxi1, mini1,maxi2, mini2;
    ll aux1,aux2,dif;
    ll rpta = 1LL<<62;
    for(int i = 2; i < n-1; i++){
        suma1 = suma[i];
        it = upper_bound(all(suma), suma1/2);
        it--;
        val = *it;
        if(val+val != suma1){
            p = val;
            q = suma1 - p;
            dif = llabs(p-q);
            it++;
            aux1 = *it;
            aux2 = suma1 - aux1;
            if(llabs(aux2-aux1) < dif){
                p = aux1;
                q = aux2;
            }
        }
        else{
            p = val;
            q = val;
        }
        maxi1 = max(p,q);
        mini1 = min(p,q);
        suma2 = suma[n] - suma[i];
        it = upper_bound(all(suma),suma[i] + suma2/2);
        it--;
        val = *it;
        val-=suma[i];
        if(val+val != suma2){
            p = val;
            q = suma2 - p;
            dif = llabs(p-q);
            it++;
            aux1 = *it;
            aux1-=suma[i];
            aux2 = suma2 - aux1;
            if(llabs(aux2-aux1) < dif){
                p = aux1;
                q = aux2;
            }
        }
        else{
            p = val;
            q = val;
        }
        maxi2 = max(p,q);
        mini2 = min(p,q);
        maxi = max(maxi1,maxi2);
        mini = min(mini1,mini2);
        rpta = min(rpta, maxi - mini);
    }
    
    cout << rpta << endl;
    return 0;
}

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

using namespace std;


#define INF 1000000000

const long long DIMN = 1007;
const long long DIMW = 30007;

long long d[DIMN][DIMW];
long long n,res,MAXW;

typedef struct box{
    long long w,s,v;
};

bool cmp(box &a, box &b ) {
    return a.w+a.s < b.w+b.s;
}

box a[DIMN];

int main() {
    //freopen("input.txt", "r", stdin);

    cin >> n;
    for(int i = 1; i <= n; i++) {
        cin >> a[i].w >> a[i].s >> a[i].v;
    }
    sort(a+1,a+1+n,cmp);
    MAXW = 30000;
    //MAXW = 5;

    d[0][0] = 0;
    for(int i = 1; i <= n; i++)
        for(int j = 0; j <= MAXW; j++) {
            d[i][j] = d[i-1][j];
            if(a[i].w <= j && a[i].s >= j-a[i].w) d[i][j] = max(d[i][j], d[i-1][j-a[i].w] + a[i].v);
        }

    res = 0;
    for(int i = 1; i <= MAXW; i++) res = max(res, d[n][i]);

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


Measured memory_bytes: 235648
#include <stdio.h>
int main(void)
{
	int a, b,r;
	double d,f;
	scanf("%d %d", &a, &b);
	d = a / b;
	r = a % b;
	f = (double)a / b;
	printf("%.0f %d %f\n", d, r, f);

	return 0;
}

Measured memory_bytes: 2732
import bisect

ans =0

n =int(input())
a =list(map(int,input().split()))
a.sort()
b =list(map(int,input().split()))
b.sort()
c =list(map(int,input().split()))
c.sort()

for i in b:
    s = bisect.bisect_right(c,i)
    s_num = n-s

    t = bisect.bisect_left(a,i)
    t_num = t

    ans += s_num * t_num

print(ans)


Measured memory_bytes: 29684
def choose(D, c, s, d, last, depth, p):
    maxpoint = -999999999
    maxnum = 0
    if depth > 0 and d < D:
        for i in range(26):
            point = p
            point += s[d][i]
            point += changepoint(c, d, i, last)*1
            nlast = []
            nlast.extend(last)
            nlast[i] = d
            z, point = choose(D, c, s, d+1, nlast, depth-1, point)
            if point > maxpoint:
                maxpoint = point
                maxnum = i
        return maxnum, maxpoint
    return 0, p


def changepoint(c, d, num, last):
    point = 0
    for j in range(26):
        if j != num:
            point -= c[j]*(d-last[j])
    return point


def main():
    D = int(input())
    c = list(map(int, input().split()))
    s = []
    last = [-1]*26
    for _ in range(D):
        s.append(list(map(int, input().split())))
    point = 0
    for i in range(D):
        num, point = choose(D, c, s, i, last, 3, 0)
        last[num] = i
        print(num+1)


main()


Measured memory_bytes: 72464
#include<stdio.h>
int main(void)
{
int i,n,a,b,c,number=0;
for(i=0;i<50;i++)
{
scanf("%d",&n);
for(a=0;a<10;a++)
{
for(b=0;b<10;b++)
{
for(c=0;c<10;c++)
{
if(n-a-b-c>=0 && n-a-b-c<=9) number++;
}
}
}
printf("%d\n",number);
number=0;
}
return 0;
}

Measured memory_bytes: 596
#include <iostream>
#include <tuple>
#include <sstream>
#include <vector>
#include <cmath>
#include <ctime>
#include <bitset>
#include <cassert>
#include <cstdio>
#include <queue>
#include <set>
#include <map>
#include <fstream>
#include <cstdlib>
#include <string>
#include <cstring>
#include <algorithm>
#include <numeric>

#define mp make_pair
#define mt make_tuple
#define fi first
#define se second
#define pb push_back
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define forn(i, n) for (int i = 0; i < (int)(n); ++i)
#define for1(i, n) for (int i = 1; i <= (int)(n); ++i)
#define ford(i, n) for (int i = (int)(n) - 1; i >= 0; --i)
#define fore(i, a, b) for (int i = (int)(a); i <= (int)(b); ++i)

using namespace std;

typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<pii> vpi;
typedef vector<vi> vvi;
typedef long long i64;
typedef vector<i64> vi64;
typedef vector<vi64> vvi64;
typedef pair<i64, i64> pi64;
typedef double ld;

template<class T> bool uin(T &a, T b) { return a > b ? (a = b, true) : false; }
template<class T> bool uax(T &a, T b) { return a < b ? (a = b, true) : false; }

map<string, int> dp;
const int P = 998244353;

void add(int &x, int y) {
    (x += y) %= P;
}

int count_dp(string s) {
    if (s.empty()) return 1;
    if (dp.count(s)) return dp[s];
    int &res = (dp[s] = count_dp(string(s.begin() + 1, s.end())) * (s[0] == '1' ? 2 : 1) % P);
    for (int l = 1; l <= s.size() / 2; ++l) {
        string t(l, '1');
        for (int k = 1; l * k <= s.size(); ++k) {
            forn(i, l) if (s[(k - 1) * l + i] == '0') t[i] = '0';
            if (k > 1) add(res, 1LL * count_dp(t) * count_dp(string(s.begin() + k * l, s.end())) % P);
        }
    }
//    cerr << s << ' ' << res << '\n';
    return res;
}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cout.precision(10);
    cout << fixed;
#ifdef LOCAL_DEFINE
    freopen("input.txt", "rt", stdin);
#endif

    string s;
    cin >> s;
    cout << count_dp(s) << '\n';

#ifdef LOCAL_DEFINE
    cerr << "Time elapsed: " << 1.0 * clock() / CLOCKS_PER_SEC << " s.\n";
#endif
    return 0;
}


Measured memory_bytes: 5632
#include<bits/stdc++.h>
#define FileIO() freopen("in.txt","r",stdin);
using namespace std;
int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(0); cout.tie(0);
    string s;
    cin>>s;
    if ((s[2]==s[3]) && s[4]==s[5]) cout<<"Yes"<<endl;
    else cout<<"No"<<endl;
    return 0;
}

Measured memory_bytes: 256
//AnkitCode99 here....
#include<bits/stdc++.h>
#define endl "\n"
typedef long long int ll;
#define MOD 1000000007
#define mp make_pair
#define pll pair<ll,ll>
#define pb push_back
//max xor btw range of two numbers..
#define max_XOR(a,b) (1 << int(log2(a ^ b) + 1)) - 1
#define vl vector<ll>
#define inf ll(1e18)
#define all(v) v.begin(),v.end()
#define fast ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
#define rep(i,a,b) for(long long int i=a;i<b;i++)
#define nrep(i,a,b) for(long long int i=a;i>=b;i--)
#define ceil(a,b) a/b+((a%b ==0 )?0:1)
using namespace std;

const ll sz=100005;
const ll szz=1000006;

ll n;
ll ar[4][sz];
ll cache[4][sz];

ll best(ll idx,ll prev)
{
    if(idx==n+1)
        return 0;

    if(cache[prev][idx]!=-1)
        return cache[prev][idx];
    
    ll &ans=cache[prev][idx];
    rep(i,1,4)
    {
        if(i==prev)
            continue;
        ans=max(ans,ar[i][idx]+best(idx+1,i));
    }
    
    //cout<<ans<<" "<<idx<<endl;
    return ans;
}

int main()
{
    fast;
    // #ifndef ONLINE_JUDGE
    // freopen("input.txt","r",stdin);
    // freopen("op.txt","w",stdout);
    // #endif

    cin>>n;
    memset(cache,-1,sizeof cache);
    rep(i,1,n+1)
    {
        rep(j,1,4)
        {
            cin>>ar[j][i];
        }
    }

    cout<<best(1,0)<<endl;
    // rep(i,1,n+1)
    // {
    //     rep(j,1,4)
    //     {
    //         cout<<cache[j][i]<<" ";
    //     }
    //     cout<<endl;
    // }
    
}//Goodbye...

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

int main(){
    int n; cin >> n;
    double ans=0;
    vector <double> A(n);
    for (int i=0; i<n; i++) cin >> A[i];
    
    for (int i=0; i<n; i++) ans+=1.0/A[i];
    
    cout << 1.0/ans << endl;
    return 0;
    
    
}

Measured memory_bytes: 256
#include "bits/stdc++.h"
using namespace std;
using ll = long long;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
using vi = vector<int>;
using vl = vector<ll>;
using vvi = vector<vi>;
using vvl = vector<vl>;
const ll INF = 1LL << 60;
const ll MOD = 1000000007;
template <class T>
bool chmax(T &a, const T &b) {
    return (a < b) ? (a = b, 1) : 0;
}
template <class T>
bool chmin(T &a, const T &b) {
    return (b < a) ? (a = b, 1) : 0;
}
template <class C>
void print(const C &c, std::ostream &os = std::cout) {
    std::copy(std::begin(c), std::end(c), std::ostream_iterator<typename C::value_type>(os, " "));
    os << std::endl;
}

template <typename T> // T : type of cost
struct BellmanFord {
    T inf = numeric_limits<T>::max(); // initial value, reused when clear() is called
    int n;                            // number of nodes
    vector<T> dist;                   // distance from start node
    vector<bool> negative;
    struct edge {
        int from, to;
        T cost;
        edge(int from, int to, T cost) : from(from), to(to), cost(cost) {}
    };
    vector<edge> edges;

    BellmanFord(int n) : n(n), negative(n, false), dist(n, inf){};
    // 0-indexed!
    void addEdge(int from, int to, T cost) { edges.emplace_back(from, to, cost); }
    // calculate dist[i] as a shortest distance from start (to end)
    // return: whether there are negative loops along the path of interest
    bool build(int start, int end = -1) {
        dist[start] = 0;
        for (int i = 0; i < n; ++i) {
            for (auto &e : edges) {
                if (dist[e.from] != inf && dist[e.to] > dist[e.from] + e.cost) {
                    dist[e.to] = dist[e.from] + e.cost;
                }
            }
        }
        // check if there are negative loops
        for (int i = 0; i < n; ++i) {
            for (auto &e : edges) {
                if (dist[e.from] != inf && dist[e.to] > dist[e.from] + e.cost) {
                    dist[e.to] = dist[e.from] + e.cost;
                    negative[e.to] = true;
                }
                if (negative[e.from])
                    negative[e.to] = true;
            }
        }
        if (end != -1)
            return negative[end];
        else {
            bool neg = false;
            for (int i = 0; i < n; ++i) {
                neg |= negative[i];
            }
            return neg;
        }
    }
};

int main() {
    ll n, m, p;
    cin >> n >> m >> p;
    BellmanFord<ll> graph(n);
    vl a(m), b(m), c(m);
    for (int i = 0; i < m; ++i) {
        cin >> a[i] >> b[i] >> c[i];
        a[i]--;
        b[i]--;
        graph.addEdge(a[i], b[i], p - c[i]);
    }

    if (graph.build(0, n - 1)) {
        cout << -1 << "\n";
    } else {
        cout << max(0LL, -graph.dist[n - 1]) << "\n";
    }
    return 0;
}

Measured memory_bytes: 768
#include<bits/stdc++.h>
// __builtin_ctz : no of trailing zeros
#define int long long
#define ll long long
#define pp pair<int,int>
#define mod 1000000007
#define trace(x) cerr<<#x<<": "<<x<<" "<<endl
#define trace2(x, y) cerr<<#x<<": "<<x<<" | "<<#y<<": "<<y<<endl
#define trace3(x, y, z) cerr<<#x<<":" <<x<<" | "<<#y<<": "<<y<<" | "<<#z<<": "<<z<<endl
#define sa(a,n) for(int i =0 ; i<n ; i++) cin>>a[i]
#define max3(a,b,c) max(a,max(b,c))
#define min3(a,b,c) min(a,min(b,c))
#define scan() int n; cin>>n ; int a[n]; for(int i = 0 ; i<n ; i++) cin>>a[i]
#define print(a,n) for(int i = 0 ; i < n ; i++) cout<<a[i]<<' '
using namespace std;
int max(int x, int y)
{
    return x>y ? x : y;
}
int min(int x, int y)
{
    return x<y ? x : y;
}
void _(int&a , int b)
{
    a=(a%mod+b%mod)%mod;
    a=(a+mod)%mod;
}
ll cl(ll a,ll b)
{
    return (a/b)+(!(!(a%b)));
}
int32_t main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    ll n,k;cin >> n >> k;map<ll,ll> m;
    for (int i = 0; i < k; ++i)
    {
     ll d;cin >> d;
     for (int j = 0; j < d; ++j)
        {
            ll x;cin >> x;m[x]++;
        }   
    }
    ll ans=0;
    for(int i=1;i<=n;i++)
        if(m[i]==0)ans++;
    cout << ans;
    }

Measured memory_bytes: 3620
import java.util.*;

class Main{
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        
        int n = Integer.parseInt(sc.next());
        int m = Integer.parseInt(sc.next());
        
        ArrayList<PVector> student = new ArrayList<PVector>();
        
        for(int i=0; i<n; i++){
            student.add(new PVector(Integer.parseInt(sc.next()), Integer.parseInt(sc.next())));
        }
        
        ArrayList<PVector> point = new ArrayList<PVector>();
        for(int i=0; i<m; i++){
            point.add(new PVector(Integer.parseInt(sc.next()), Integer.parseInt(sc.next())));
        }
        
        for(int i=0; i<n; i++){
            int ans_num = 0;
            int ans_dis = Integer.MAX_VALUE;
            for(int j=0; j<m; j++){
                int dis = (int)Math.abs((student.get(i).x - point.get(j).x)) + (int)Math.abs((student.get(i).y - point.get(j).y));
                
                if(ans_dis > dis){
                    ans_dis = dis;
                    ans_num = j+1;
                }
            }
            System.out.println(ans_num);
        }
        
    }
    
    static class PVector{
        int x;
        int y;
        
        PVector(int x, int y){
            this.x = x;
            this.y = y;
        }
    }
}

Measured memory_bytes: 21844
s = input()

n = len(s)

ans = [1]*n

for i in range(n-1):
    if s[i] == 'R' and s[i+1] == 'R':
        ans[i+2] += ans[i]
        ans[i] = 0
for i in range(n-1, 0, -1):
    if s[i] == 'L' and s[i-1] == 'L':
        ans[i-2] += ans[i]
        ans[i] = 0
for i in range(n):
    print(ans[i], end=" ")

Measured memory_bytes: 4848