akhauriyash/Code-Regression huggingface dataset:
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {

		Scanner sc = new Scanner(System.in);

		StringBuilder sb = new StringBuilder();

		sb.append(sc.nextInt()).append(sc.nextInt());

		int inNum = Integer.valueOf(sb.toString());

		for(int i = 4; i < 400 ; i++) {
			if (inNum == i*i) {
				System.out.println("Yes");
				break;
			} else if(inNum < i*i){
				System.out.println("No");
				break;
			}
		}
	}

}


Measured memory_bytes: 21716
# import sys
# input = sys.stdin.readline
from collections import Counter
import string


def main():
    # while True:
        S = input()
        K = int(input())
        S_MAP = Counter(S)

        count_1st = 0
        S1 = list(S * 1)
        for i in range(len(S) - 1):
            if S1[i] == S1[i+1]:
                count_1st += 1
                S1[i+1] = '_'
                # for c in string.ascii_lowercase:
                #     if i == 0:
                #         if c != S1[i+1]:
                #             count_1st += 1
                #             S1[i+1] = c
                #             break
                #     else:
                #         if c != S1[i-1] and c != S1[i+1]:
                #             count_1st += 1
                #             S1[i+1] = c
                #             break

        count_2nd = 0
        S2 = list(S * 2)
        for i in range(len(S) * 2 - 1):
            if S2[i] == S2[i+1]:
                count_2nd += 1
                S2[i+1] = '_'

        count_3rd = 0
        S3 = list(S * 3)
        for i in range(len(S) * 3 - 1):
            if S3[i] == S3[i+1]:
                count_3rd += 1
                S3[i+1] = '_'

        count_4th = 0
        S4 = list(S * 4)
        for i in range(len(S) * 4 - 1):
            if S4[i] == S4[i+1]:
                count_4th += 1
                S4[i+1] = '_'

        # count_k = 0
        # SK = list(S * K)
        # for i in range(len(S) * K - 1):
        #     if SK[i] == SK[i+1]:
        #         for c in string.ascii_lowercase:
        #             if i == 0:
        #                 if c != SK[i+1]:
        #                     count_k += 1
        #                     SK[i+1] = c
        #                     break
        #             else:
        #                 if c != SK[i-1] and c != SK[i+1]:
        #                     count_k += 1
        #                     SK[i+1] = c
        #                     break

        # if K <= 4:
        #     if K == 1:
        #         print(count_1st)
        #     elif K == 2:
        #         print(count_2nd)
        #     elif K == 3:
        #         print(count_3rd)
        #     elif K == 4:
        #         print(count_4th)
        # print(len(S_MAP))
        if len(S_MAP) == 1 and len(S) % 2 == 1:
            d1 = count_2nd - count_1st
            d2 = count_3rd - count_2nd
            # print(d1)
            # print(d2)
            print(d1 * K//2 + d2 * K//2)
        # elif len(S)
        else:
            d = count_3rd - count_2nd
            # last_d = count_4th - count_3rd
            print(count_1st + d * (K-1))
            # print(*S1)
            # print(*S2)
            # print(*S3)
            # print(*S4)
            # print(d * K)
        # # print(K, d, count_1st)
        # # print(count_1st, count_2nd, count_3rd)
        # # print(count_k)
        # # print(*SK)


if __name__ == '__main__':
    main()


Measured memory_bytes: 38512
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rrep(i, n) for (int i = 1; i < (int)(n+1); i++)
int f(int i){
    if(i%2==0){
        return i/2;
    }else{
        return i*3+1;
    }
}
int main() {
    int s;
    cin>>s;
    vector<int>A(1000000);
    bool a=true;
    int ans=1;
    A[s]++;
    while(a==true){
        int b=f(s);
      ans++;
        if(A[b]!=0){
            a=false;
            cout<<ans<<endl;
        }
        else{
            A[b]++;
          s=b;
        }
    }
}

Measured memory_bytes: 7132
#include <bits/stdc++.h>
using namespace std;
const int N = 1e2 + 10;
int a[N];
int main()
{
	int n;
	cin >> n;
	for (int i = 1; i < n; ++i)
		cin >> a[i];
	int ans = 0;
	a[0] = a[n] = 1e9;
	for (int i = 1; i <= n; ++i)
		ans += min(a[i - 1], a[i]);
	cout << ans;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <queue>
using namespace std;
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

const int MAX = 310;
const long long INF = 1LL<<50;

long long G[MAX][MAX];
using pll = pair<long long, long long>;

int main() {
    int N, M; long long L;
    cin >> N >> M >> L;
    
    for (int i = 0; i < MAX; ++i) {
        for (int j = 0; j < MAX; ++j) G[i][j] = INF;
        G[i][i] = 0;
    }
    for (int i = 0; i < M; ++i) {
        int a, b; long long c;
        cin >> a >> b >> c; --a, --b;
        G[a][b] = G[b][a] = c;
    }

    vector<vector<pll> > dist(N, vector<pll>(N, {INF, INF}));
    for (int s = 0; s < N; ++s) {
        dist[s][s] = {0, 0};
        priority_queue<pair<pll, int>,
                       vector<pair<pll, int> >,
                       greater<pair<pll, int> > > que;
        que.push(make_pair(pll(0, 0), s));
        while (!que.empty()) {
            auto p = que.top();
            que.pop();
            
            long long v = p.second;
            long long kaisuu = p.first.first;
            long long used = p.first.second;
            
            if (p.first > dist[s][v]) continue;
            for (int nv = 0; nv < N; ++nv) {
                if (nv == v) continue;
                if (G[v][nv] > L) continue;
                long long nused = used + G[v][nv];
                pll np = {0, 0};
                if (nused > L) np = {kaisuu + 1, G[v][nv]};
                else np = {kaisuu, nused};

                if (chmin(dist[s][nv], np)) que.push(make_pair(np, nv));
            }
        }
    }

    int Q; cin >> Q;
    while (Q--) {
        int a, b; cin >> a >> b; --a, --b;
        
        long long res = dist[a][b].first;
        if (res >= INF) cout << -1 << endl;
        else cout << res << endl;
    }
}

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

int main()
{
    int a,b,c;
    cin>>a>>b>>c;
    
    if(b>=c)
        cout<<"delicious"<<endl;
    else if(c - b<=a)
        cout<<"safe"<<endl;
    else
        cout<<"dangerous"<<endl;
    return 0;
}

Measured memory_bytes: 256
function Picker(input) {
  var lines = input.split('\n');
  var fields = lines.reduce(function(all, line) { return all.concat(line.split(' ')); }, []);
  var p = 0;

  return {
    int: function() {
      return parseInt(fields[p++], 10);
    },
    float: function() {
      return parseFloat(fields[p++]);
    },
    str: function() {
      return fields[p++];
    }
  };
}

function Main(input) {
  var pick = Picker(input);
  var list = [pick.int(), pick.int(), pick.int(), pick.int(), pick.int()];
  var mod = list.map(function(e) { return (e % 10 ? e % 10 : 10) - 10; });
  var minMod = mod.sort(function(a, b){ return a - b; })[0];
  var up = list.map(function(e) { return e % 10 ? (e - e % 10) + 10 : e; });

  console.log(up.reduce(function(p, c) { return p + c; }) + minMod);
}

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

Measured memory_bytes: 7372
#include<bits/stdc++.h>
using namespace std; 
int main(){
  int i; //count=0;
  string s,s1="";//str4;
  cin>>s;
  for(i=0; i<s.length(); i++){
  	if(s[i]=='?') s1+='D';
  	else s1+=s[i];
  }
cout<<s1;
  
  
  return 0;
}

Measured memory_bytes: 3916
def check(i, j, w, h, s):
    if (i+1<h and s[i+1][j]=="#"):
        return True
    if (i-1>=0 and s[i-1][j]=="#"):
        return True
    if (j+1<w and s[i][j+1]=="#"):
        return True
    if (j-1>=0 and s[i][j-1]=="#"):
        return True
    return False

h,w=map(int,input().split())
s = [list(input()) for _ in range(h)]

for i in range(h):
    for j in range(w):
        if s[i][j]=="#":
            if check(i, j, w, h, s):
                True
            else:
                print("No")
                exit()

print("Yes")


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

int main() {
	long long N, K;
	static long long A[200000];
	static vector<long long> V[200000];
	static long long NEXT[200000];
	static bool END[200000] = {};
	static vector<long long> Chain;
	static vector<long long> ANS;
	int NOW = 0;
	cin >> N >> K;
	for (int i = 0; i < N; i++) cin >> A[i], A[i]--;
	ANS.push_back(-1);
	for (int i = 0; i < N; i++) {
		V[A[i]].push_back(i);
	}
	for (int i = 0; i < 200000; i++) {
		if (!V[i].empty()) {
			for (int j = 0; j < V[i].size() - 1; j++) {
				NEXT[V[i][j]] = V[i][j + 1] + 1;
			}
			NEXT[V[i][V[i].size() - 1]] = V[i][0] + 1;
			END[V[i][V[i].size() - 1]] = true;
		}
	}
	while (NOW != N) {
		Chain.push_back(NOW);
		NOW = NEXT[NOW];
	}
	for (int i : Chain) {
		if (END[i]) {
			ANS.push_back(A[i]);
		}
	}
	K = (K - 1) % ANS.size();
	set<long long> S;
	stack<long long> ST;
	if (ANS[K] != -1) {
		ST.push(ANS[K]);
		S.insert(ANS[K]);
	}
	for (int i = 0; i < N; i++) {
		if (S.count(A[i])) {
			while (ST.top() != A[i]) {
				S.erase(ST.top());
				ST.pop();
			}
			S.erase(A[i]);
			ST.pop();
		}
		else {
			ST.push(A[i]);
			S.insert(A[i]);
		}
	}
	stack<int> FINAL;
	while (!ST.empty()) {
		FINAL.push(ST.top());
		ST.pop();
	}
	while (!FINAL.empty()) {
		cout << FINAL.top() + 1;
		FINAL.pop();
		if (!FINAL.empty()) cout << " ";
	}
	cout << endl;
}

Measured memory_bytes: 29940
#include<iostream>
#include<string>
#include<algorithm>
#include<bits/stdc++.h>
#include<iomanip>
using namespace std;

typedef long long ll;
typedef long double ld;

int MOD=1000000007;

int main(){
  ll A,B,C;
  cin >> A >> B >> C;
  swap(A,B);
  swap(A,C);
  cout << A << " " << B << " " << C << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define For(i, begin, end) for(int i=begin;i<end;i++)
#define Rep(i, n) For(i,0,n)
#define Sort(v) sort(v.begin(),v.end())
using namespace std;

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

  return 0;
}

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

int main()
{
	int a, b;
	cin >> a >> b;

	int ans = -1;
	for (int cost = 1; cost < 2000; cost++) {
		int aa = cost * 0.08;
		int bb = cost * 0.1;
		if (aa == a && bb == b) {
			ans = cost;
			break;
		}
	}

	cout << ans << endl;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
const int maxs=1000000000;
int n,k,s;
void solve(){
    cin>>n>>k>>s;
    for(int i=1;i<=k;++i){
        cout<<s<<" ";
    }
    for(int i=k+1;i<=n;++i){
        if(s==maxs){
            cout<<1<<" ";
        }
        else{
            cout<<maxs<<" ";
        }
    }
}
int main(){
    solve();

    return 0;
}

Measured memory_bytes: 1280
use std::str::FromStr;
use std::fmt::Debug;
use std::cmp;
#[allow(dead_code)]
fn read_as_vec<T>() -> Vec<T>
where T: FromStr, <T as FromStr>::Err : Debug{
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).unwrap();
    s.trim().split_whitespace().map(|c| T::from_str(c).unwrap()).collect()

}

#[allow(dead_code)]
fn read_as_string() -> String{
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).unwrap();
    s.trim().to_string()
}

fn main(){
    let line = read_as_string().chars().collect::<Vec<char>>();
    let (a, b) = (line[0], line[2]);

    if (a =='H' && b == 'H') || (a == 'D' && b == 'D'){
        println!("H");
    }else{
        println!("D");
    }
}


Measured memory_bytes: 4352
a, b, c = map(int, input().split())
def iroha(a,b,c):
    if (a==5 or a==7) and (b==5 or b==7) and (c==5 or c==7) and a+b+c==17:
        return "YES"
    else:
        return "NO"
print(iroha(a,b,c))

Measured memory_bytes: 2940
#include<bits/stdc++.h>
using namespace std;
int a,b,d;
char jo[100];
int main(){
    cin>>a>>b;
    cin>>jo;
    for(int i=0;i<a;i++){
        if(jo[i]>='0'&&jo[i]<='9'){}
        else{d++;}
    }
    if(jo[a]=='-'){}
    else{d++;}
    for(int i=0;i<b;i++){
        if(jo[a+1+i]>='0'&&jo[a+1+i]<='9'){}
        else{d++;}
    }
    if(d==0){cout<<"Yes"<<endl;}
    else{cout<<"No"<<endl;}
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long LL;
typedef pair<LL,LL> P;
const LL mod=1000000007;

int main(){
    string s,u="CODEFESTIVAL2016";
    cin >> s;
    int ans=0;
    for(int i=0;i<s.length();i++){
        if(s[i]!=u[i]) ans++;
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 256
"use strict";

var main = function main(input) {
  var N = parseInt(input, 10);
  var power = 1;

  while (N != 0) {
    power = power * N % 1000000007;
    N--;
  }

  console.log(power);
};

main(require('fs').readFileSync('/dev/stdin', 'utf-8'));

Measured memory_bytes: 7372
#include<bits/stdc++.h>
int n,i,ans;
char c[3][105];
int main(){
	scanf("%d%s%s%s",&n,c[0]+1,c[1]+1,c[2]+1);
	for(i=1;i<=n;++i)
		ans+=c[0][i]==c[1][i]?(c[0][i]==c[2][i]?0:1):(c[2][i]==c[0][i] || c[2][i]==c[1][i]
			?1:2);
	printf("%d\n",ans);
	return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int h = sc.nextInt();
		int w = sc.nextInt();
		int h1 = sc.nextInt();
		int w1 = sc.nextInt();
		int ans = h * w - h * w1 - w * h1 + h1 * w1;
		System.out.println(ans);
		sc.close();
	}
}

Measured memory_bytes: 25172
import std.algorithm;
import std.array;
import std.container;
import std.conv;
import std.math;
import std.numeric;
import std.range;
import std.stdio;
import std.string;
import std.typecons;

void scan(T...)(ref T a) {
    string[] ss = readln.split;
    foreach (i, t; T) a[i] = ss[i].to!t;
}
T read(T)() { return readln.chomp.to!T; }
T[] reads(T)() { return readln.split.to!(T[]); }
alias readint = read!int;
alias readints = reads!int;

struct D {
    int row, col, step;
}

int calc(string[] g) {
    int rows = cast(int)g.length;
    int cols = cast(int)g[0].length;
    bool inp(int r, int c) { return 0 <= r && r < rows && 0 <= c && c < cols; }

    auto q = new Queue!(D);
    foreach (r; 0..rows) foreach (c; 0..cols) {
        if (g[r][c] == '#') {
            q.push(D(r, c, 0));
        }
    }

    int ans = 0;
    auto t = new int[][](rows, cols);
    auto dxy = [0, 1, 0, -1];
    while (!q.empty) {
        auto d = q.pop();
        if (t[d.row][d.col]++) continue;

        ans = max(ans, d.step);
        for (int i = 0; i < dxy.length; i++) {
            int r = d.row + dxy[i];
            int c = d.col + dxy[$-1-i];
            if (inp(r, c) && t[r][c] == 0) q.push(D(r, c, d.step + 1));
        }
    }
    return ans;
}

void main() {
    int h, w; scan(h, w);
    string[] g;
    foreach (_; 0..h) g ~= read!string;
    writeln(calc(g));
}

class Queue(T) {
    private DList!(T) _dlist;
    private ulong _size;

    this(T[] ary) {
        _dlist = DList!(T)(ary);
        _size = ary.length;
    }

    this() {
        _dlist = DList!(T)();
        _size = 0;
    }

    void push(T x) {
        _dlist.insertBack(x);
        _size++;
    }

    T pop() {
        T x = _dlist.front;
        _dlist.removeFront();
        _size--;
        return x;
    }

    @property T front() {
        return _dlist.front;
    }

    @property ulong size() {
        return _size;
    }

    @property bool empty() {
        return _dlist.empty;
    }
}


Measured memory_bytes: 95612
#include<iostream>
#include<numeric>
#include<vector>
#include<iomanip>
#include<algorithm>
#include<map>
#include<utility>
#include<cmath>
#include<tuple>
#include<string>
#include<bitset>
#include<set>
#include<queue>
#include<stack>
#include<cstdio>
using namespace std;
typedef long long ll;

int main(){
    int s,w; cin>>s>>w;
    if(w>=s) cout<<"unsafe"<<endl;
    else cout<<"safe"<<endl;
}

Measured memory_bytes: 3620
#include <stdio.h>

int bubbleSort(int A[], int N) {
  int times = 0;
  for (int i = N - 1; i > 0; i--) {
    for (int j = 0; j < i; j++) {
      if (A[j] > A[j + 1]) {
        int tmp = A[j];
        A[j] = A[j + 1];
        A[j + 1] = tmp;
        times++;
      }
    }
  }
  return times;
}

void printArr(int A[], int N) {
  for (int i = 0; i < N; i++) {
    if (i > 0) printf(" ");
    printf("%d", A[i]);
  }
  printf("\n");
}

int main(void) {
  int N;
  scanf("%d", &N);
  int A[N];
  for (int i = 0; i < N; i++) {
    scanf("%d", &A[i]);
  }
  int t = bubbleSort(A, N);
  printArr(A, N);
  printf("%d\n", t);

  return 0;
}


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

ll gcd(ll A, ll B) {
  if (B == 0) {
    return A;
  }
  return gcd(B, A % B);
}

int main() {
  ll A, B;
  cin >> A >> B;
  ll g = gcd(max(A, B), min(A, B));
  cout << A * B / g << endl;
  return 0;
}

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

int main() {
    int n;
    cin >> n;
    vector<pair<int, int>> a(100001, {0, 0});
    vector<pair<int, int>> b(100001, {0, 0});
    for (size_t i = 0; i < n; i++)
    {
        int v;
        cin >> v;

        if (i % 2 == 0)
        {
            a[v] = {v, ++a[v].second};
        }
        else
        {
            b[v] = {v, ++b[v].second};
        }
    }

    sort(a.begin(), a.end(),
    [](const auto &o1, const auto &o2) {
        return o1.second > o2.second;
    });
    sort(b.begin(), b.end(),
    [](const auto &o1, const auto &o2) {
        return o1.second > o2.second;
    });
    if (a[0].first != b[0].first)
    {
        cout << n - a[0].second - b[0].second << endl;
    }
    else
    {
        int cnd1 = n - a[0].second - b[1].second;
        int cnd2 = n - a[1].second - b[0].second;
        cout << min(cnd1, cnd2) << endl;
    }
}


Measured memory_bytes: 1792
#if 1
  #include <bits/stdc++.h>
#else
  #include "../../bits/stdc++.h"
#endif

#define FOR(i,a,b) for(int i = (a);i < (b);i++)
#define RFOR(i,a,b) for(int i = (b)-1;i >= (a);i--)
#define REP(i,n) FOR(i,0,(n))
#define RREP(i,n) RFOR(i,0,(n))

using namespace std;

typedef pair<int, int> P;
#define pb push_back
#define mp make_pair
#define ft first
#define sd second

int n;
int y, m, d;

void input(){
  cin>>y>>m>>d;
}

void solve(){
  int s=0;
  FOR(i, 1, y) {
    if(i%3==0)s+=200;
    else s+=195;
  }
  FOR(i, 1, m) {
    if(y%3!=0&&i%2==0)s+=19;
    else s+=20;
  }
  s+=d-1;
  cout<<196470-s<<endl;
}

int main(){
  cin.tie(0);
  
  cin>>n;
  REP(i, n){
    input();
    solve();
  }
  
  return 0;
}

Measured memory_bytes: 3048
#include<cstdio>
#include<algorithm>
using namespace std;

int n,k,a[2005][2005],ans;
inline int Sum(int x1,int y1,int x2,int y2){
    return a[x2][y2]-a[x1][y2]-a[x2][y1]+a[x1][y1];
}
int main(){
    scanf("%d%d",&n,&k);
    for(int i=1;i<=n;i++){
        int x,y;
        char c=getchar();
        scanf("%d%d",&x,&y);
        while(c!='W'&&c!='B')
            c=getchar();
        a[x%(2*k)+1][(y+(c=='W')*k)%(2*k)+1]++;
    }
    for(int i=1;i<=2*k;i++)
        for(int j=1;j<=2*k;j++)
            a[i][j]+=a[i-1][j]+a[i][j-1]-a[i-1][j-1];
    for(int i=1;i<=k;i++)
        for(int j=1;j<=k;j++){
            int tmp=Sum(0,0,i,j)+Sum(0,j+k,i,2*k)+Sum(i,j,i+k,j+k)+Sum(i+k,0,2*k,j)+Sum(i+k,j+k,2*k,2*k);
            ans=max(ans,max(tmp,n-tmp));
        }
    printf("%d",ans);
}

Measured memory_bytes: 15872
# ABC が開催された次の週には ARC が開催され、ARC が行われた次の週には ABC が開催
# 先週開催されたコンテストを表す文字列Sが与えられる
# 制約: S は ABC または ARC
# S = 'ABC'

S = input()

if S == 'ABC':
    print('ARC')
else:
    print('ABC')

Measured memory_bytes: 9028
# Problem E - Crested Ibis vs Monster

# input
H, N = map(int, input().split())
ab_pattern = []
for i in range(N):
    a, b = map(int, input().split())
    ab_pattern.append([a, b])

# initialization
mp_list = [float('INF')] * (H+1)
mp_list[0] = 0

# dp
for i in range(1, H+1):
    for ab in ab_pattern:
        a = ab[0]
        b = ab[1]
        if i-a>=0:
            mp_list[i] = min(mp_list[i], mp_list[i-a] + b)
        else:
            mp_list[i] = min(mp_list[i], mp_list[0] + b)

# output
print(mp_list[H])


Measured memory_bytes: 42476
import java.util.Scanner;

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

Measured memory_bytes: 60624
#include <bits/stdc++.h>
using namespace std;
#define REP(i, n) for(int i = 0; i < n; i++)
#define REPR(i, n) for(int i = n - 1; i >= 0; i--)
#define FOR(i, m, n) for(int i = m; i < n; i++)
#define FORR(i, m, n) for(int i = m; i >= n; i--)
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
#define ll long long
#define pb(a) push_back(a)

ll mod = 1e09;

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

  int x;
  cin >> x;
  if(x < 1200) cout << "ABC" << endl;
  else cout << "ARC" << endl;

}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/assoc_container.hpp>
using namespace std;

#define LEN(x) (int)x.size()
#define ALL(x) x.begin(), x.end()

using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using pii = pair<int,int>;
using vpii = vector<pii>;

template<typename T, typename M = __gnu_pbds::null_type>
using ordered_set = __gnu_pbds::tree<T, M, less<T>, __gnu_pbds::rb_tree_tag, __gnu_pbds::tree_order_statistics_node_update>;

template<typename T>
const T INF = (is_same<T, int>::value ? 1e9 : 1e18);
const int MOD = 1e9 + 7;
const double EPS = 1e-9;

inline int fcmp(double x, double y)
{ return (x < y + EPS ? (x < y - EPS ? -1 : 0) : 1);}

const int N = 1e6 + 10;
int dp[N][2];
int n;
string s;

int solve(int i, bool j)
{
    if(i == n) return j;

    int& ans = dp[i][j];

    if(ans == -1)
    {
        ans = INF<int>;
        int a = s[i] - '0';
        int b = 10 - (s[i] - '0');

        if(j)
        {
            ans = min(ans, solve(i + 1, j) + b - 1);
            ans = min(ans, solve(i + 1, !j) + a + 1);
        }
        else
        {
            ans = min(ans, solve(i + 1, j) + a);
            ans = min(ans, solve(i + 1, !j) + b);
        }
    }

    return ans;
}

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.precision(10);
    
    cin >> s;
    n = LEN(s);
    reverse(ALL(s));

    memset(dp, -1, sizeof dp);
    cout << solve(0, 0) << endl;

    return 0;
}

Measured memory_bytes: 58856
#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,y;
    cin>>n>>y;
    for(int i=0; i<=n; ++i){
        for(int j=0; j<=n-i; ++j){
            int k=n-i-j;
            if(i*10000+j*5000+k*1000==y){
                cout<<i<<" "<<j<<" "<<k<<endl;
                return 0;
            }
        }
    }
    cout<<-1<<" "<<-1<<" "<<-1<<endl;
    return 0;
}

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

int main() {  
  int N,K;
  cin >> N>>K;
  vector<int> A(N);
  for (int i = 0; i < N; i++) {
    cin >> A.at(i);
  }  
  
  cout<<(N-2)/(K-1)+1<<endl;
}

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

int main(){
    int n,x;
    cin >> n >> x;
    vector<int> a(n);
    rep(i,n) cin >> a.at(i);
    ll cur = 0;
    int bnd = 1;
    rep(i,n){
        cur += a.at(i);
        if(cur <= x) bnd++;
    }
    cout << bnd << endl;

    return 0;
}   

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

template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }

using ll = long long;
using lb = long double;
using P = pair<ll,ll>;
using graph = vector<vector<ll>>;

const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};
const ll INF = 1LL<<60;
const ll mod = 1000000007LL;

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

struct BIT{
  ll bit[1000010];
  void add(ll a,ll w){
    for(ll x = a; x < 1000010; x+=(x&-x)) bit[x]+=w;
  }
  ll sum(ll a){
    ll ret = 0LL;
    for ( ll x = a; x > 0;x-=(x&-x)) ret += bit[x];
    return ret;
  }
};


int main(){
  ll N;
  cin>>N;
  vector<ll> v(N);
  rep(i,N) cin>>v[i];
  vector<ll> ans(N,0);
  BIT B;
  vector<P> vp(N);
  rep(i,N) {
    vp[i].first=v[i];
    vp[i].second=i;
  }
  sort(vp.begin(),vp.end(),[](P a,P b){
    if(a.first!=b.first) return a.first>b.first;
    else return a.second<b.second;
  });
  vector<ll> S(N);
  BIT cn;
  rep(i,N){
    S[vp[i].second] = B.sum(N) - B.sum(vp[i].second)-(cn.sum(N)-cn.sum(vp[i].second))*vp[i].first;
    B.add(vp[i].second+1,vp[i].first);
    cn.add(vp[i].second+1,1);
  };
  vector<ll> C(N);
  ll c = 0;
  rep(i,N){
    if(chmax(c,v[i])) C[i] = i;
    else C[i] = C[i-1];
  }
  ll all = 0;
  rep(i,N) all += v[i];
  ll cnt = 0;
  rep(i,N){
    if(vp[i].second==0){
      ans[0] = all - cnt;
      break;
    }
    if(C[vp[i].second]==C[vp[i].second-1]) {
      ans[vp[i].second] = 0;
      continue;
    }
    ans[vp[i].second] = S[C[vp[i].second-1]]-cnt;
    cnt += ans[vp[i].second];
  }
  rep(i,N) cout<<ans[i]<<endl;
}

Measured memory_bytes: 9704
#include <cmath>
#include <cstdio>
#include <vector>
#include <list>
#include <iostream>
#include <algorithm>
#include <sstream>
#include <stack>
#include <fstream>
#include <queue>
#include <iomanip>
#include <iterator>
#include <map>
#include <unordered_map>
#include <set>
#define fast ios_base::sync_with_stdio(false)
#define ll long long int
#define ld long double
#define vi vector<ll>
#define vvi vector<vi >
#define pi pair<ll,ll>
#define vvpi vector<vector<pi > >
#define vpi vector<pi >
#define vppi vector<pair<ll,pi > >
#define vs vector<string>
#define all(v) v.begin(),v.end()
#define rall(v) v.rbegin(),v.rend()
#define pb push_back
#define eb emplace_back
#define mkp make_pair
#define fs first
#define se second
#define crz(v,n) v.clear(),v.resize(n+1,0)
#define print(v) for(ll it=0;it<v.size();it++) cout<<v[it]<<" ";cout<<endl
#define printp(v) for(ll it=0;it<v.size();it++) cout<<v[it].first<<" "<<v[it].second<<endl
using namespace std;
int main(){
	string s;cin>>s;ll a=(s[0]-48)*10+s[1]-48,b=(s[2]-48)*10+s[3]-48;
	if((a>12&&!b)||(b>12&&!a)||(a>12&&b>12)||(!a&&!b)) cout<<"NA\n";
	else if(a>12||!a) cout<<"YYMM\n";
	else if(b>12||!b) cout<<"MMYY\n";
	else cout<<"AMBIGUOUS\n";

}


Measured memory_bytes: 384
#define NDEBUG
#include <cassert>

template <class Monoid, template <class> class Container> class segment_tree {
public:
	using value_structure = Monoid;
	using value_type = typename value_structure::value_type;
	using container_type = Container<value_type>;
	using const_reference = typename container_type::const_reference;
	using size_type = typename container_type::size_type;

private:
	size_type size_, capacity;
	container_type c;
	static size_type getsize(const size_type size) {
		size_type ret = 1;
		while (ret < size)
			ret <<= 1;
		return ret;
	}
	void recalc(const size_type index) {
		c[index] = value_structure::operation(c[index << 1], c[index << 1 | 1]);
	}

public:
	segment_tree() : size_(0), capacity(0), c() {}
	explicit segment_tree(const size_type size)
		: size_(size), capacity(getsize(size_)),
		c(capacity << 1, value_structure::identity()) {}

	bool empty() const { return !size_; }
	size_type size() const { return size_; }

	const_reference operator[](const size_type index) const {
		assert(index < size());
		return c[index + capacity];
	}
	value_type fold(size_type first, size_type last) const {
		assert(first <= last);
		assert(first <= size());
		assert(last <= size());
		value_type ret_l = value_structure::identity(),
			ret_r = value_structure::identity();
		for (first += capacity, last += capacity; first < last;
			first >>= 1, last >>= 1) {
			if (first & 1)
				ret_l = value_structure::operation(ret_l, c[first++]);
			if (last & 1)
				ret_r = value_structure::operation(c[last - 1], ret_r);
		}
		return value_structure::operation(ret_l, ret_r);
	}
	template <class F> size_type search(const F &f) const {
		if (f(value_structure::identity()))
			return 0;
		if (!f(c[1]))
			return size() + 1;
		value_type acc = value_structure::identity();
		size_type i = 1;
		while (i < capacity)
			if (!f(value_structure::operation(acc, c[i <<= 1])))
				acc = value_structure::operation(acc, c[i++]);
		return i - capacity + 1;
	}

	void update(size_type index, const value_type &value) {
		assert(index < size());
		index += capacity;
		c[index] = value;
		while (index >>= 1)
			recalc(index);
	}
};

template <class T> class plus_monoid {
public:
	using value_type = T;
	static value_type operation(const value_type &x, const value_type &y) {
		return x + y;
	}
	static value_type identity() { return value_type(0); }
	static value_type reverse(const value_type &x) { return x; }
};

#include <cstdio>
#include <vector>

template<class T> using vec_alias = ::std::vector<T>;

int main() {
	using uint = unsigned int;

	uint n, q;
	scanf("%u%u", &n, &q);

	segment_tree<plus_monoid<uint>, vec_alias> seg(n);

	while (q--) {
		uint c, x, y;
		scanf("%u%u%u", &c, &x, &y);

		if (c)
			printf("%u\n", seg.fold(x - 1, y));
		else
			seg.update(x - 1, seg[x - 1] + y);
	}

	return 0;
}



Measured memory_bytes: 3384
import java.io.PrintWriter;
import java.util.*;

public class Main {
		public static void main(String[] args) {
			Scanner stdin = new Scanner(System.in);
			PrintWriter out = new PrintWriter(System.out);
			
			int N = Integer.parseInt(stdin.next());
			int cnt=0;
			
			for(int i=0;i<=N;i++) {
				if(i<=9999999 && i>=1000000) {
					cnt+=1;
				}
				else if(i<=99999 && i>=10000) {
					cnt+=1;
				}
				else if(i<=999 && i>=100) {
					cnt+=1;
				}
				else if(i<=9 && i>=1) {
					cnt+=1;
				}
			}
			out.println(cnt);
			
			out.flush();
	}
}




Measured memory_bytes: 21972
#include<stdio.h>
#include<iostream>
#include<algorithm>
#include<string>
#include<string.h>
#include<math.h>
#include<stdlib.h>
#include<vector>
#include<queue>
#define rep(index,num) for(int index=0;index<num;index++)
#define scan(argument) cin>>argument
#define prin(argument) cout<<argument<<endl
#define kaigyo cout<<endl
#define eps 1e-15
typedef long long ll;
using namespace std;
typedef pair<int,int> pint;
int main(){
	int N;
	ll C;
	ll x[100001];
	ll v[100001];
	ll cloc[100001],turncloc[100001],ccloc[100001],turnccloc[100001];
	ll clocmax[100001]={0},turnclocmax[100001]={0},cclocmax[100001]={0},turncclocmax[100001]={0},allmax;
	scan(N);scan(C);
	x[0]=0;v[0]=0;
	rep(i,N){
		scan(x[i+1]);scan(v[i+1]);
	}
	rep(i,N+1){
		if(i!=0){
			cloc[i]=cloc[i-1]+v[i]-(x[i]-x[i-1]);
			turncloc[i]=cloc[i]-x[i];
		}
		else{
			cloc[0]=0;
			turncloc[0]=0;
		}
		if(i>1){
			ccloc[i]=ccloc[i-1]+v[N+1-i]-(x[N+2-i]-x[N+1-i]);
			turnccloc[i]=ccloc[i]-(C-x[N+1-i]);
		}
		else if(i==1){
			ccloc[1]=v[N]-(C-x[N]);
			turnccloc[1]=ccloc[1]-(C-x[N]);
		}
		else{
			ccloc[0]=0;
			turnccloc[0]=0;
		}
		if(i!=0){
			clocmax[i]=max(cloc[i],clocmax[i-1]);
			turnclocmax[i]=max(turncloc[i],turnclocmax[i-1]);
			cclocmax[i]=max(ccloc[i],cclocmax[i-1]);
			turncclocmax[i]=max(turnccloc[i],turncclocmax[i-1]);
		}
	}
	ll tmax=clocmax[N],hmax=turnclocmax[N],thmax=0,htmax=0;
	rep(i,N+1){
		thmax=max(thmax,turnclocmax[i]+cclocmax[N-i]);
		htmax=max(htmax,turncclocmax[i]+clocmax[N-i]);
	}
	allmax=max(thmax,htmax);
	prin(allmax);
	return 0;
}


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

int main(){
	int n;
	while( cin >> n, n ){
		vector<int> v(n);
		for(int i=0; i<n; i++)
			cin >> v[i];
		sort( v.begin(), v.end() );
		int res = 0;
		for(int i=1; i<n-1; i++)
			res += v[i];
		cout << res/(n-2) << endl;
	}
	return 0;
}

Measured memory_bytes: 1220
from collections import deque

s = input()
que = deque(s)

T_F = True

for i in range(int(input())):
  query = input()
  if query[0] == '1':
    T_F = not T_F
  elif (query[2] == '1' and T_F) or (not query[2] == '1' and not T_F):
    que.appendleft(query[4])
  else:
    que.append(query[4])
if T_F:
  print(''.join(que))
else :
  print(''.join(reversed(que)))

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

using namespace std;

int compute(int y, int m, int d) {
  int ret = 0;
  int a = (y-1)/3;
  int b = (y-1) - a;
  ret += 200*a + 195*b;
  ret += 20*(m-1) - (y%3 == 0 ? 0 : (m-1)/2);
  ret += d;
  return ret;
}

int main() {
  int n;
  cin >> n;
  while(n--) {
    int y, m, d; cin >> y >> m >> d;
    cout << compute(1000, 1, 1) - compute(y, m, d) << endl;
  }
  
  return 0;
}

Measured memory_bytes: 1164
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
vector<long long> u,v;
int main(){
    int i,n; cin >> n;
    for(i=0;i<n;i++){
        long long x,y; cin >> x >> y;
        u.push_back(x + y),v.push_back(x - y);
    }
    sort(u.begin(),u.end()); sort(v.begin(),v.end());
    long long ans = max(u[n - 1] - u[0],v[n - 1] - v[0]);
    cout << ans << endl;
}

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

int main()
{
	int a[100];
	int n,i;
	cin >> n;
	double ans = 0;
	for (int i = 0; i < n; i++)
	{
		cin >> a[i];
	}
	for (i = 0; i < n; i++)
	{
		ans += 1.0 / a[i];
	}
	ans = 1.0 / ans;
	printf("%.5f", ans);
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
typedef long long int ll;
#define endl '\n'
using namespace std;
const ll mod=1e9+7;
ll power(ll x,ll y,ll m)
{
    if (y == 0)
        return 1;
    ll p = power(x, y/2, m) % m;
    p = (p * p) % m;

    return (y%2 == 0)? p : (x * p) % m;
}
int main(){
    ios_base::sync_with_stdio(false),cin.tie(NULL),cout.tie(NULL);
    ll n;
    cin>>n;
    if(n==1)cout<<"0"<<endl;
    else{
        ll tot=power(10ll,n,mod);
        ll sub=power(8ll,n,mod);
        tot-=sub;
        tot=(tot+mod)%mod;
        ll x=(power(9ll,n,mod)-power(8ll,n,mod)+mod)%mod;
        x=(x*2)%mod;
        tot-=x;
        tot%=mod;
        tot=(tot+mod)%mod;
        cout<<tot<<endl;
    }
    return 0;
}


Measured memory_bytes: 3660
n,h=int(input()),list(map(int,input().split()))
dp=[0]*n
dp[1]=abs(h[1]-h[0])
for i in range(2,n):dp[i]=min(dp[i-2]+abs(h[i-2]-h[i]),dp[i-1]+abs(h[i-1]-h[i]))
print(dp[n-1])

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

int main(void)
{
    ll n,a,b;
    cin >> n >> a >> b;
    vector<ll> x(n);
    REP(i, n){
        cin >> x[i];
    }
    ll ans = 0;
    Rep(i, 1, n){
        ll ai = (x[i] - x[i-1]) * a;
        ans += min(ai, b);
    }
    pr(ans);
}

Measured memory_bytes: 1024
from collections import deque
import sys
sys.setrecursionlimit(10**7)
#input = sys.stdin.readline
def solve():
  h,w = (int(i) for i in input().split())
  maze = ["."*(w+2)]
  for i in range(h):
    maze.append("." + input()+ ".")
  maze.append("."*(w+2))
  start = deque([])

  for i in range(h):
    for j in range(w):
      if maze[i][j] == "#":
        start.append((i,j))

  while start:
      height,width = start.popleft()
      isblacknear = False
      d = [(1,0),(0,1),(-1,0),(0,-1)]
      for dy,dx in d:
        nh = height + dy
        nx = width + dx
        if maze[nh][nx] == "#":
          isblacknear = True
          break
      if not isblacknear:
        print("No")
        exit()
  print("Yes")
        
      
      
solve()

Measured memory_bytes: 3444
#include<stdio.h>
#include<math.h>
#include<algorithm>
#include<queue>
#include<deque>
#include<string>
#include<string.h>
#include<vector>
#include<set>
#include<map>
#include<bitset>
#include<stdlib.h>
#include<cassert>
#include<time.h>
#include<bitset>
using namespace std;
const long long mod=1000000007;
const long long inf=mod*mod;
const long long d2=(mod+1)/2;
const double EPS=1e-6;
const double PI=acos(-1.0);
int ABS(int a){return max(a,-a);}
long long ABS(long long a){return max(a,-a);}
int main(){
	int a;scanf("%d",&a);
	long long ret=1;
	for(int i=1;i<=a;i++)ret=ret*i%mod;
	printf("%lld\n",ret);
}

Measured memory_bytes: 128
s = int(input())
sec = int(s % 60)
hm = int(s // 60)
if hm == 0:
    print('0:0:' + str(sec))
else:
    m = int(hm % 60)
    h = int(hm // 60)
    print(str(h) + ':' + str(m) + ':' + str(sec))


Measured memory_bytes: 5592
#include<bits/stdc++.h>
#define rep(i,a,b) for(int i=a;i<b;i++)
#define rrep(i,a,b) for(int i=a;i>=b;i--)
#define fore(i,a) for(auto &i:a)
#define all(x) (x).begin(),(x).end()
//#pragma GCC optimize ("-O3")
using namespace std;

int main() {
  
  int a,b,c,d,x;
  long long la,lb,lc,lx;
  double da,db,dc;
  string s,ss,sss;
  
  int ans = 0;
  string anss = "";
  
  cin >> x >> s >> ss;
  
  int ab [] = {0 , 1 , 3 , 1 , 2 , 1 , 2 , 1 , 1 , 2 , 1 , 2 , 1};
  int result3 = std::max({a, b, c});
//--------------------------------------------------------------------------------
rep(i,0,x){
anss += s[i];
  anss += ss[i];
}
  
  cout << anss << endl;

}

Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<vector>
#include<stdio.h>
#include<algorithm>
#include<stdlib.h>
#define _USE_MATH_DEFINES
#include<math.h>
#include<numeric>
#include<iomanip>

using namespace std;

int main() {
	string s; cin >> s;
	int a = s.find('A');
	//cout << a << endl;
	int z = 0;
	int tmp = 0;
	while (z != -1) {
		z = s.find('Z');
		if (z == -1) {
			break;
		}
		s[z] = 'a';
		//cout << s << endl;
		if (z - a+1 > tmp) {
			tmp = z-a+1;
		}
	}
	cout << tmp << endl;
}



    

Measured memory_bytes: 640
#include <bits/stdc++.h>
#include <numeric>
using namespace std;
#define ll long long
#define mod 1000000007
#define rep(i, n) for (int i = 0; i < n; ++i)
using Graph = vector<vector<int>>;
#define grepq priority_queue<double, std::vector<double>, std::greater<double>>
#define all(v) v.begin(), v.end()
#define PI acos(-1)

const ll INF = 10010001010;
const int inf = 2000000000;
ll lcm(ll a, ll b)
{
    return a * b / __gcd(a, b);
}

typedef tuple<string, int, int> TUP;

bool tuplesort(const TUP &right, const TUP &left)
{
    if (get<0>(right) != get<0>(left))
    {
        return get<0>(left) < get<0>(right);
    }
    if (get<1>(left) != get<1>(right))
    {
        return get<1>(left) > get<1>(right);
    }
    return get<2>(left) < get<2>(right);
}
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};

ll nCr(int n, int r)
{
    ll ans = 1;
    for (int i = n; i > n - r; --i)
    {
        ans = ans * i;
    }
    for (int i = 1; i < r + 1; ++i)
    {
        ans = ans / i;
    }
    return ans;
}

int main()
{
    string S;
    cin >> S;
    int ans = 0;
    for (int i = 0; i < 4;i++)
    {
        if(S[i] == '2'){
            ans++;
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
n = int(input())
l = sorted(list(map(int, input().split())))
ans = 0

for i in range(n - 2):
    for j in range(i + 1, n - 1):
        for k in range(j + 1, n):
            if l[i] != l[j] and l[j] != l[k] and l[k] != l[i] and l[i] < l[j] + l[k] and l[j] < l[k] + l[i] and l[k] < l[i] + l[j]:
                ans += 1

print(ans)


Measured memory_bytes: 9196
def main():
    import sys
    input = sys.stdin.readline
    sys.setrecursionlimit(10**7)
    from collections import Counter, deque
    #from collections import defaultdict
    from itertools import combinations, permutations, accumulate
    #from itertools import product
    from bisect import bisect_left,bisect_right
    import heapq
    from math import floor, ceil
    #from operator import itemgetter

    #inf = 10**17
    #mod = 10**9 + 7

    N,K = map(int, input().split())
    V_l = list(map(int, input().split()))
    V_r = list(reversed(V_l))
    res = 0
    for i in range(K+1):
        if i<=N:
            for l in range(i+1):
                n = []
                r = i - l
                a = V_l[:l] + V_r[:r]
                for j in a:
                    if j<0:
                        n.append(j)
                n.sort()
                temp = sum(a)-sum(n[:K-i])
                res = max(res, temp)

    print(res)

if __name__ == '__main__':
    main()





Measured memory_bytes: 3316
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pll = pair<ll, ll>;
using vi = vector<int>;
using vl = vector<ll>;
#define rep(i, n) for(ll i = 0;i < n;i++)
#define all(i) i.begin(), i.end()
template<class T, class U> bool cmax(T& a, U b) { if (a<b) {a = b; return true;} else return false; }
template<class T, class U> bool cmin(T& a, U b) { if (a>b) {a = b; return true;} else return false; }

void dfs(ll now, ll p, const vector<vector<pll>>& g, vl& path_bit) {
  for (auto&& i : g[now]) {
    if (i.first != p) {
      path_bit[i.first] |= path_bit[now] | (1LL << i.second);
      dfs(i.first, now, g, path_bit);
    }
  }
}

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

  ll n, m;
  cin >> n;
  vl a(n-1), b(n-1);
  vector<vector<pll>> g(n);

  rep(i, n-1) {
    cin >> a[i] >> b[i];
    a[i]--;
    b[i]--;
    g[a[i]].emplace_back(b[i], i);
    g[b[i]].emplace_back(a[i], i);
  }

  cin >> m;
  vl u(m), v(m);
  rep(i, m) {
    cin >> u[i] >> v[i];
    u[i]--;
    v[i]--;
  }

  vl path_bit(n);
  path_bit[0] = 0;
  dfs(0, 0, g, path_bit);
  rep(i, n) {
    //cerr << bitset<10>(path_bit[i]) << endl;
  }

  ll ans = 0;
  rep(bit, 1LL<<m) {
    ll edge_bit = 0;
    rep(i, m) {
      if (bit >> i & 1) {
        edge_bit |= (path_bit[u[i]] xor path_bit[v[i]]);
      }
    }
    ll cnt = __builtin_popcountll(bit);
    ans += (cnt%2 ? -1 : 1) * (1LL << (n-1-__builtin_popcountll(edge_bit)));
    //cerr << ans << endl;
  }
    assert(ans >= 0);
  cout << ans << endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <iomanip>
#include <string>
#include <stack>
#include <queue>
#include <map>
#include <set>
#include <tuple>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <climits>
#include <cassert>
#include <cstdint>
#include <cctype>
#include <numeric>
#include <bitset>
#include <functional>

using namespace std;

using ll =  long long;
using Pll = pair<ll, ll>;
using Pii = pair<int, int>;

constexpr int INF = 1 << 30;
constexpr ll LINF = 1LL << 60;
constexpr ll MOD = 1000000007;
constexpr long double EPS = 1e-10;
constexpr int dyx[4][2] = {
    { 0, 1}, {-1, 0}, {0,-1}, {1, 0}
};

int main() {
    ios::sync_with_stdio(false); cin.tie(nullptr);
    int h, w, k;
    cin >> h >> w >> k;
    vector<vector<bool>> a(h, vector<bool>(w, false));
    char c;
    for(int i=0;i<h;++i) {
        for(int j=0;j<w;++j) {
            cin >> c;
            a[i][j] = (c == '#');
        }
    }

    int ans = 0;
    for(int i=0;i<(1<<h);++i) {
        for(int j=0;j<(1<<w);++j) {
            int cnt = 0;
            for(int ii=0;ii<h;++ii) {
                for(int jj=0;jj<w;++jj) {
                    if(i & (1 << ii)) continue;
                    if(j & (1 << jj)) continue;
                    if(a[ii][jj]) ++cnt;
                }
            }
            if(cnt == k) ++ans;
        }
    }

    cout << ans << endl;
}


Measured memory_bytes: 3648
import std.stdio, std.conv, std.string, std.array, std.range, std.algorithm, std.container;
import std.math, std.random, std.bigint, std.datetime, std.format;
void main(string[] args){ if(args.length > 1) if(args[1] == "-debug") DEBUG = 1; solve(); }
void log()(){ writeln(""); } void log(T, A ...)(T t, lazy A a){ if(DEBUG) write(t, " "), log(a); } bool DEBUG = 0; 
string rstring(){ static string[] ss; while(!ss.length) ss = readln.chomp.split; string res = ss[0]; ss.popFront; return res; }
T rtype(T)(){ return rstring.to!T; } alias rint = rtype!int, rlong = rtype!long, rreal = rtype!real;
T[] rtypes(T)(int n){ return n.iota.map!(i => rtype!T()).array; } alias rint = rtypes!int, rlong = rtypes!long, rreal = rtypes!real;
T[][] rtypess(T)(int n, int m){ return n.iota.map!(i => rtypes!T(m)).array; } alias rint = rtypess!int, rlong = rtypess!long, rreal = rtypess!real;
T chmin(T)(ref T x, T y){ if(x > y) x = y; return x; } T chmax(T)(ref T x, T y){ if(x < y) x = y; return x; }

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

void solve(){
	int a = rint, b = rint;
	foreach(x; 1 .. 1000_000){
		int a1 = x * 8 / 100, b1 = x * 10 / 100;
		if(a1 == a && b1 == b){
			x.writeln;
			return;
		}
	}
	"-1".writeln;
}

Measured memory_bytes: 256
import java.util.Arrays;
import java.util.LinkedList;
import java.util.Scanner;
import java.util.stream.IntStream;

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

    public static void check(String num) {

        String[] strs = num.split(" ");
        int start = Integer.parseInt(strs[1]) - Integer.parseInt(strs[0])+1;
        int end = Integer.parseInt(strs[1]) + Integer.parseInt(strs[0])-1;
        for(int i=start; i<=end; i++) {
            System.out.print(i);
            if(i < end) {
                System.out.print(" ");
            }
        }
    }
}

Measured memory_bytes: 21844
using System;
using static System.Console;
using static System.Math;

public class Hello{
    public static void Main(){
//        string[] input = ReadLine().Split(' ');
        int kazu = int.Parse(ReadLine());
//        int max = int.Parse(input[1]);
        int min = 99999;
        
        for(int i=1;i<=kazu/2;i++){
            int wa = 0;
            //A
            int a = i;
            while(a>0){
                wa += a%10;
                a /= 10;
            }
            //B
            int b = kazu-i;
            while(b>0){
                wa += b%10;
                b /= 10;
            }
            min = Min(min,wa);
        }
        WriteLine(min);
    }
}

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

int main(){
  int N;
  cin >> N;
  int count = 0,max=0;
  for(int i = 0; i < N; i++){
    int tmp;
    cin >> tmp;
    if(tmp >= max){
      max = tmp;
      count++;
    }
  }
  cout << count << endl;
}

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

#define ALL(v) (v).begin(), (v).end()
#define RALL(v) (v).rbegin(), (v).rend()
#define endl "\n"
const double EPS = 1e-7;
const int INF = 1 << 30;
const ll LLINF = 1LL << 60;
const double PI = acos(-1);
constexpr int MOD = 1000000007;
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};

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

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll n, a, b;
    cin >> n >> a >> b;
    ll ans = (n / (a + b)) * a;
    ans += min(n % (a + b), a);
    cout << ans << endl;
}

Measured memory_bytes: 256