akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
using namespace std;

const int INF = 1e+8;
string s;
int ans;

// k := ステップ数, foot := 足の位置, t := 0 のときは右足を,1のときは左足を動かす, cnt := 解
void solve(int k, int foot, int t, int cnt){
    if( k == s.size() ){
        ans = min(ans, cnt);
        return;
    }
    
    if( t == 0 ){ // 右足を動かす.
        int ly = ((foot - 1) % 3) + 1;
        int next = s[k] - '0';
        int ry = ((next - 1) % 3) + 1;
        
        if( ly <= ry ){ // 動かせるとき
            solve(k + 1, next, (t + 1) % 2, cnt);
        }else{ // 動かせないとき
            solve(k + 1, next, t, cnt + 1);
        }
    }else{ // 左足を動かす.
        int ry = ((foot - 1) % 3) + 1;
        int next = s[k] - '0';
        int ly = ((next - 1) % 3) + 1; 
        
        if( ly <= ry ){ // 動かせるとき
            solve(k + 1, next, (t + 1) % 2, cnt);
        }else{ // 動かせないとき
            solve(k + 1, next, t, cnt + 1);
        }
    }
}

int main(){
    while( cin >> s, s != "#" ){
        ans = INF;
        for(int i = 1 ; i <= 9 ; i++ ){
            if( i == 5 ) continue;
            solve(0, i, 0, 0);
            solve(0, i, 1, 0);
        }
        cout << ans << endl;
    }
}

Measured memory_bytes: 1316
h, n = map(int, input().split())
ab = [list(map(int, input().split())) for _ in range(n)]
dp = [0] + [10000000000] * h
ret = 10000000000
for i in range(h):
    for j in range(n):
        a, b = ab[j]
        if i + a >= h:
            ret = min(ret, dp[i] + b)
        else:
            dp[i + a] = min(dp[i + a], dp[i] + b)
print(ret)


Measured memory_bytes: 74028
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		var sc = new Scanner(System.in);
		var h = sc.nextInt();
		var w = sc.nextInt();
		var k = sc.nextInt();
		var c = new int[h][w];
		for (var i = 0; i < h; i++) {
			var text = sc.next();
			for (var j = 0; j < w; j++) {
				c[i][j] = text.substring(j, j + 1).equals("#") ? 1 : 0;
			}
		}
		sc.close();

		var result = 0;
		for (var i = 0; i < Math.pow(2, h); i++) {
			for (var j = 0; j < Math.pow(2, w); j++) {
				if (count(c, i, j) == k) {
					result++;
				}
			}
		}

		System.out.println(result);
	}

	private static int count(int[][] c, int wi, int wj) {
		var count = 0;
		for (var i = 0; i < c.length; i++) {
			if (!getBit(wi, i)) {
				continue;
			}
			for (var j = 0; j < c[i].length; j++) {
				if (!getBit(wj, j)) {
					continue;
				}
				if (c[i][j] == 1) {
					count++;
				}
			}
		}
		return count;
	}

	public static boolean getBit(int n, int d) {
		return ((n % (int) Math.pow(2, d + 1)) / ((int) Math.pow(2, d))) != 0;
	}
}


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

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

  string s;
  cin >> s;

  int len = s.size();

  int ans = 0;
  for (int i = 0; i < len / 2; i++) {
    char cf = s[i];
    char cb = s[len - 1 - i];

    if (cf == cb) continue;

    ans++;
  }

  cout << ans << endl;

  return 0;
}

Measured memory_bytes: 256
#include<stdio.h>

int main()
{
  int n;
  int data[100]={};
  int i,j;

  scanf("%d",&n);
  
  for(i=0;i<n;i++)
    {
      scanf("%d",&data[i]);
    }

  for(j=n-1;j >-1;j--)
    {
      printf("%d",data[j]);
      if(j)printf(" ");
    }
  printf("\n");
  
  return 0;
}
  



Measured memory_bytes: 2104
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#include<tuple>
#include<map>
#include<queue>
#include<math.h>
#include <numeric>
#include<iomanip>
#define rep(i, n) rep2(i,0,n)
#define rep2(i, s, n) for (int i = (s); i < (int)(n); i++)
#define PI acos(-1);
typedef long long ll;
using namespace std;
const int MOD=1000000007;
//scanf("%d", &a); '\n';


int main() {
	int n;
	cin >> n;
	vector<int> a(n);
	rep(i, n)scanf("%d", &a[i]); '\n';
	int ans = 1;
	int start = -MOD;
	rep(i, n) {
		if (a[i] == 1) {
			start = i; break;
		}
	}
	if (start == -MOD) {
		cout << -1; return 0;
	}
	int now = 1;
	rep2(i, start, n) {
		if (a[i] == now + 1) {
			ans++;
			now++;
		}
	}
	cout << n - ans;

	}

	

Measured memory_bytes: 1024
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <tuple>
#include <queue>
#include <stack>

using namespace std;

class Solver {
public:
};

int main() {
	int max = 1000000;
	vector<bool> prime(max + 10, true);
	prime[1] = false;
	for (int i = 2; i <= max; i++) {
		if (!prime[i])continue;

		for (int j = 2; i * j <= max; j++) {
			prime[i * j] = false;
		}
	}
	while (true) {
		int a, d, n;
		cin >> a >> d >> n;
		if (a == 0 && d == 0 && n == 0)break;

		int now = a;
		int cnt = 0;
		if (prime[a])cnt++;
		while (cnt < n) {
			now += d;
			if (prime[now])cnt++;
		}
		cout << now << endl;
	}
}


Measured memory_bytes: 3188
#include<bits/stdc++.h>
#define st first
#define nd second
#define pb push_back
#define ppb pop_back
#define umax(x,y) x=max(x,y)
#define umin(x,y) x=min(x,y)
#define ll long long
#define ii pair<int,int>
#define iii pair<int,ii>
#define iiii pair<ii,ii>
#define sz(x) ((int) x.size())
#define orta ((bas+son)>>1)
#define all(x) x.begin(),x.end()
#define dbgs(x) cerr<<(#x)<<" --> "<<(x)<<" "
#define dbg(x) cerr<<(#x)<<" --> "<<(x)<<endl;getchar()
#define pw(x) (1ll<<(x))
#define inf 2005000
#define MOD 1000000007
#define N 200005
#define M 1000005
#define LOG 60
#define KOK 4000000
using namespace std;

int n,k,a[N],f[N];
ll ans;
ll pre[N];
vector< pair<ll,int> > v;

int get(int now) {

	int res=0;

	for(int i=now;i>=1;i-=(i&-i)) res+=f[i];

	return res;

}

void up(int now) {

	for(int i=now;i<=n+1;i+=(i&-i)) f[i]++;

}

int main() {

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

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

	for(int i=1;i<=n;i++) {

		scanf("%d",&a[i]);

		a[i]-=k;

	}

	for(int i=1;i<=n;i++) pre[i]=pre[i-1]+a[i];

	v.pb({0,0});

	for(int i=1;i<=n;i++) {

		v.pb({pre[i],i});		

	}

	sort(all(v));

	for(auto x:v) {

		up(x.nd+1);

		if(x.nd==0) continue ;

		ans+=get(x.nd);

	}

	printf("%lld",ans);

}

Measured memory_bytes: 8816
#include <stdio.h>
#include <string.h>
#define MAXN 100005

int main()
{
    int n;
    while(scanf("%d", &n) != EOF)
    {
        int a,num = n,flag = 1;
        int head[MAXN],tail[MAXN];
        int num_i = 0, num_j = 0;
        while(num--)
        {
            scanf("%d", &a);
            if(flag)
                tail[num_j++] = a;
            else
                head[num_i++] = a;
            flag = !flag;
        }
        if(n%2 == 0)
        {
            for(int i = num_i - 1; i >= 0; i--)
            {
                printf("%d ", head[i]);
            }
            for(int j = 0; j < num_j - 1; j++)
            {
                printf("%d ", tail[j]);
            }
            if(num_j)printf("%d\n", tail[num_j - 1]);
            else printf("\n");
        }
        else
        {
            for(int j = num_j - 1; j >= 0; j--)
            {
                printf("%d ", tail[j]);
            }
            for(int i = 0; i < num_i - 1; i++)
            {
                printf("%d ", head[i]);
            }
            if(num_i)printf("%d\n", head[num_i - 1]);
            else printf("\n");
        }
    }
    return 0;
}


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

int main() {
  int n, m;
  scanf("%d %d", &n, &m);
  int a, acc = 0;
  for(int i = 0; i < m; i++) {
    scanf("%d", &a);
    acc += a;
  }
  printf("%d\n", (acc > n ? -1 : n - acc));
}

Measured memory_bytes: 3816
#include <bits/stdc++.h>
#define mp make_pair
#define pb push_back
#define sz(x) (int)x.size()
#define all(x) begin(x), end(x)
#define debug(x) cerr << #x << " " << x << '\n'
using namespace std;
using ll = long long;
using pii = pair<int,int>;
using pli = pair<ll,int>;
const int INF = 0x3f3f3f3f, N = 2e5 + 5;
const ll LINF = 1e18;
int n;
ll a[N];
ll k;
bool check(ll x) //num of <=x 
{
	ll cnt = 0;
	for(int i=1; i<=n; i++)
	{
		if(a[i]==0)
		{
			if(x>=0) cnt += n - 1;
		}
		else if(a[i]<0)
		{
			ll up = x/a[i];
			if(up*a[i]>x) up++;
			int l = 1, r = n, ans = n+1;
			while(l<=r)
			{
				int mid = (l+r)>>1;
				if(a[mid]>=up) ans = mid, r = mid - 1;
				else l = mid + 1;
			}
			//[ans, n]
			if(ans<=i) ans++;
			cnt += n - ans + 1;
		}
		else
		{
			ll up = x/a[i]; 
			if(up*a[i]>x) up--;
			int l = 1, r = n, ans = 0;
			while(l<=r)
			{
				int mid = (l+r)>>1;
				if(a[mid]<=up) ans = mid, l = mid + 1;
				else r = mid - 1;
			}
			//[1, ans] 
			if(ans>=i) ans--;
			cnt += ans;
		}
	}
	assert(cnt%2==0);
	cnt /= 2;
	return cnt >= k;
}
int main()
{
 	ios::sync_with_stdio(false);
 	cin.tie(0);
 	cin >> n >> k;
 	for(int i=1; i<=n; i++) cin >> a[i];
 	sort(a+1, a+n+1);
 	ll l = -LINF, r = LINF, ans = 0;
	while(l<=r)
	{
		ll mid = (l+r)>>1;
		if(check(mid)) ans = mid, r = mid - 1;
		else l = mid + 1;
	}
	cout << ans;
	return 0;
}


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

int main() {
  int i, j, k;
  int n, m;
  int temp;
  char flag = 0;

  char a[52][55];
  char b[52][55];

  scanf("%d %d\n", &n, &m);
  for (i = 1; i <= n; i++) {
    scanf("%[^\n]%*c", a[i]);
  }
  for (i = 1; i <= m; i++) {
    scanf("%[^\n]%*c", b[i]);
  }
  /*
    printf("\n");
    for (i = 0; i < n;i++) {
      printf("%s\n", a[i+1]);
    }
    printf("\n");
    for (i = 0; i < n;i++){
      printf("%s\n", b[i+1]);
    }
  */

  for (i = 1; i <= n - m + 1; i++) {
    for (k = 1; k <= n - m + 1; k++) {
      flag = 0;
      for (j = 1; j <= m; j++) {
        // if (j == i) {
        // temp = strstr(a[j + i - 1], b[j])-a[j+i-1];
        // printf("%p\n", strstr(a[j + i - 1], b[j])-a[j+i-1]);
        //} else {
        // printf("%p\n", strstr(a[j + i - 1], b[j])-a[j+i-1]);
        if (strstr(a[j + i - 1] + k - 1, b[j]) != a[j + i - 1] + k - 1) {
          flag = 1;
          break;
        }
      }
      //}

      if (flag == 0) {
        break;
      }
    }
    if (flag == 0) {
      break;
    }
  }

  if (flag == 0) {
    printf("Yes");
  } else {
    printf("No");
  }

  return 0;
}

Measured memory_bytes: 256
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ConsoleApp1
{
    static class AStrings
    {
        static void Main(string[] args)
        {
            var inputs = Console.ReadLine().Split(' ');
            var s = inputs[0];
            var t = inputs[1];

            Console.WriteLine(t + s);
            Console.ReadLine();
        }
    }
}

Measured memory_bytes: 11092
/* Aditya0412 */
#include <bits/stdc++.h>
using namespace std; 
typedef long long int ll;
#define pb push_back 
#define ve vector
#define vii vector < int >
#define vll vector < ll > 
#define pii pair < int , int >
#define pll pair < ll , ll >
#define vpl vector < pll >
#define fi first
#define all(a)      (a).begin(),(a).end()
#define si(x)       (int)((x).size())
#define debug(x)    cout<<#x<<" is "<<(x)<<endl;cout.flush();  
#define se second 
#define endl        '\n'
#define f(i,a,b)    for(int i=a;i<b;i++)
#define mem(a,x)          memset(a,x,sizeof(a))

// === Debug macro starts here ===

int recur_depth = 0;
#ifdef DEBUG
#define dbg(x) {++recur_depth; auto x_=x; --recur_depth; cerr<<string(recur_depth, '\t')<<"\e[91m"<<__func__<<":"<<__LINE__<<"\t"<<#x<<" = "<<x_<<"\e[39m"<<endl;}
#else
#define dbg(x)
#endif
template<typename Ostream, typename Cont>
typename enable_if<is_same<Ostream,ostream>::value, Ostream&>::type operator<<(Ostream& os,  const Cont& v){
    os<<"[";
    for(auto& x:v){os<<x<<", ";}
    return os<<"]";
}
template<typename Ostream, typename ...Ts>
Ostream& operator<<(Ostream& os,  const pair<Ts...>& p){
    return os<<"{"<<p.first<<", "<<p.second<<"}";
}

// === Debug macro ends here ===


// const ll mod=998244353;
const ll mod = 1000000000+7;
const ll N=1000000+6;
#define M_PI           3.14159265358979323846
void inp(ll *arr,ll n)
{
  for(int i=0;i<n;i++)
    cin>>arr[i];
}
void inp_mat(ll *arr,ll n,ll m)
{
    for(int i=0;i<n;i++)
      for(int j=0;j<m;j++)
        {
          ll x;cin>>x;
          *((arr+i*m) + j)=x;
        }
}
// syntax for inp_mat inp_mat((ll *)arr,n,m);
// int x2[]={+1,-1,+0,+0};
// int y2[]={+0,+0,+1,-1};
ll dp[105][100005];
void init(){
  f(i,0,105)
  {
    f(j,0,100005)
    dp[i][j]=LLONG_MAX;
  }
}
int main() 
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    //  #ifndef ONLINE_JUDGEc
    //   freopen ("INPUT.txt" , "r" , stdin);
    //   freopen ("OUTPUT.txt", "w" , stdout);
    // #endif 
    int t=1;
    // cin>>t;
    while(t--)
    {
      ll n,w;cin>>n>>w;
      ll vrr[n],wrr[n];
      f(i,0,n)
      {
        cin>>wrr[i]>>vrr[i];
      }
      init();
      dp[0][vrr[0]]=wrr[0];
      dp[0][0]=0;
      f(i,1,n)
      {
        f(j,0,100005)
        {
          dp[i][j]=min(dp[i][j],dp[i-1][j]);
          if(j-vrr[i]>=0)
          {
            if(dp[i-1][j-vrr[i]]!=LLONG_MAX)
            dp[i][j]=min(dp[i][j],wrr[i]+dp[i-1][j-vrr[i]]);
            }
        }
      }
      ll ans=0;
      f(i,0,100005)
      {
        if(dp[n-1][i]<=w)
        ans=i;
        dbg(dp[n-1][i]);
      }
      // dbg(dp[n-1][17]);
      cout<<ans;
      
    }    
} 

Measured memory_bytes: 85692
<?php
# 整数の入力

fscanf(STDIN, "%d", $K);

 $arr = [1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51];
 $result = $arr[$K-1];
 echo $result;


?>

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

namespace ziyuutyou
{
    class Program
    {
        static void Main(string[] args)
        {
            var str = Console.ReadLine().Split(' ');
            List<int> candy = new List<int>();

            for(var x=0;x<str.Length;x++)
            {
                candy.Add(int.Parse(str[x]));
            }

            var max = candy.Max();

            candy.Remove(max);

            if(max == candy.Sum())
            {
                Console.WriteLine("Yes");
            }
            else
            {
                Console.WriteLine("No");
            }
           
        }
    }
}


Measured memory_bytes: 13152
D = int(input())
C = list(map(int, input().split()))
S = []
for _ in range(D):
    ver = list(map(int,input().split()))
    S.append(ver)
d = 0
last = [0 for _ in range(26)]

t = []
for d in range(1, D+1):
    dc = [C[i]*(d-last[i]) for i in range(26)]
    best = []
    for i in range(26):
        if_i = S[d-1][i] + dc[i]
        best.append(if_i)
    t.append(best.index(max(best))+1)
    #indexの要素の重複を考えない
    last_i = best.index(max(best))
    last[last_i] += d
for t_i in t:
    print(t_i)

Measured memory_bytes: 9532
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.List;

public class Main {
    public class rectangle{
        public int width;
        public int height;
        public  rectangle(){

        }

        public rectangle(int width, int height){
            this.width = width;
            this.height = height;
        }

        public int getWidth() {
            return width;
        }

        public int getHeight() {
            return height;
        }
    }

    public static void main(String[] args) throws IOException {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        String input = br.readLine();
        Main main = new Main();
        List<Main.rectangle> rectanglelist = new ArrayList<>();
        while(!input.equals("0 0")){
            String[] dataset = input.split(" ");
            int H = Integer.parseInt(dataset[0]);
            int W = Integer.parseInt(dataset[1]);
            rectanglelist.add(main.new rectangle(W, H));
            input = br.readLine();
        }

        for(int i = 0;i < rectanglelist.size(); i++){
            for(int m = 1; m <= rectanglelist.get(i).height; m++){
                for(int n = 1; n <= rectanglelist.get(i).width; n++){
                    System.out.print("#");
                }
                System.out.println("");
            }
            System.out.println("");
        }
    }
}

Measured memory_bytes: 33468
#include <iostream>
#include <string>
#include <utility>
#include <algorithm>
#include <map>
#include <set>
#include <vector>
#include <cmath>
#include <cstdlib>
#include <queue>
#include <stack>
#include <iomanip>


using namespace std;

#define REP(i, n) for(int i = 0;i < n;i++)
#define REPR(i, n) for(int i = n;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 REPO(i, n) for(int i = 1;i <= n;i++)
#define ll long long
#define INF 1999999999
#define MINF -1999999999
#define INF64 1999999999999999999
#define ALL(n) n.begin(),n.end()
#define MOD 1000000007

struct UnionFind {
	vector<int> data;
	UnionFind(int size) : data(size, -1) { }
	bool unionSet(int x, int y) {
		x = root(x); y = root(y);
		if (x != y) {
			if (data[y] < data[x]) swap(x, y);
			data[x] += data[y]; data[y] = x;
		}
		return x != y;
	}
	bool findSet(int x, int y) {
		return root(x) == root(y);
	}
	int root(int x) {
		return data[x] < 0 ? x : data[x] = root(data[x]);
	}
	int size(int x) {
		return -data[root(x)];
	}
};
UnionFind tr(210000), ro(210000);
map<pair<ll, ll>, ll> m;
pair<ll, ll> s[210000];
ll n, k, l;
int main() {
	cin >> n >> k >> l;
	REP(i, k) { ll a, b; cin >> a >> b; a--; b--; tr.unionSet(a, b); }
	REP(i, l) { ll a, b; cin >> a >> b; a--; b--; ro.unionSet(a, b); }
	REP(i, n) {
		s[i] = make_pair(tr.root(i), ro.root(i));
		m[s[i]]++;
	}
	REP(i, n) {
		if (i != 0)cout << " ";
		cout << m[s[i]];
	}
	cout << endl;
}


Measured memory_bytes: 16768
n, m = gets.chomp.split(' ').map(&:to_i)
as = gets.chomp.split(' ').map(&:to_i)

min = as.reduce(:+) / (4 * m).to_f
oks = as.reject { |x| x < min }

puts oks.count >= m ? 'Yes' : 'No'


Measured memory_bytes: 1788
/**
 * code generated by JHelper
 * More info: https://github.com/AlexeyDmitriev/JHelper
 * @author Kein Yukiyoshi
 */

#include "bits/stdc++.h"
#define int long long
#define FOR(i, a, b) for (int i = (int)(a); i < (int)(b); i++)
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define ALL(obj) begin(obj), end(obj)
#define MAX(x) *max_element(ALL(x))
#define MIN(x) *min_element(ALL(x))
#define LOWER_BOUND(A, key) distance(A.begin(), lower_bound(ALL(A), key))
#define UPPER_BOUND(A, key) distance(A.begin(), upper_bound(ALL(A), key))
#define Endl endl

using namespace std;
using ll      = long long;
const int MOD = (int)(1e9 + 7);
const int INF = (int)(1e13 + 7);

int ceil_(int a, int b) { return (a >= 0 ? (a + (b - 1)) / b : (a - (b - 1)) / b); }
int mod(int a, int b) { return a >= 0 ? a % b : a - (b * ceil_(a, b)); }
int bpm(int x, unsigned int y) {
  if (x == 0) return 0;
  if (y == 0) return 1;
  int ans   = 1;
  int digit = (int)((log((double)y) / log((double)2) / 1 + 1));
  x %= MOD;
  for (int i = 0; i < digit; i++) {
    if (((y >> i) & 1u) == 1) ans = ans * x % MOD;
    x = x * x % MOD;
  }
  return ans;
}
template <class T>
void cumulative_sum(T &container) {
  for (int i = 0; i < container.size() - 1; i++) container[i + 1] += container[i];
}
class EDivisibleSubstring {
public:
  static void solve(std::istream &cin, std::ostream &cout) {
    int N, P;
    string S;
    cin >> N >> P >> S;
    if (P == 2 or P == 5) {
      int ans = 0;
      rep(i, N) {
        if ((S[S.size() - 1 - i] - '0') % P == 0) {
          ans += (N - i);
        }
      }
      cout << ans << endl;
      return;
    }
    vector<int> cum_sum = {0};
    map<int, int> check;
    int now = 1;
    rep(i, N) {
      cum_sum.emplace_back((cum_sum[i] + (S[N - i - 1] - '0') * now) % P);
      now *= 10;
      now %= P;
    }
    rep(i, N + 1) {
      check[cum_sum[i]]++;
    }
    now     = 1;
    int ans = 0;
    rep(i, N) {
      check[cum_sum[i]]--;
      ans += check[cum_sum[i]];
      if (i >= 1) now = now * 10 % P;
    }
    cout << ans << endl;
  }
};

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


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

#define ll long long

using namespace std;

int main(){
	ll i,n,x;
	
	cin>>n;
	
	vector<ll> a(n+1);
	
	for(i=1;i<=n;i++){
		cin>>a[i];
	}
	
	for(i=n;i>1;i--){
		cout<<a[i]<<" ";
	}
	cout<<a[1]<<"\n";
}


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

using namespace std;

int main() {
	string s; cin >> s;
	for (int i = 0; i < s.size(); i += 2) {
		if (s.substr(i, 2) != "hi") {
			cout << "No" << endl;
			return 0;
		}
	}
	cout << "Yes" << endl;

	return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
#include<iostream>
#include<algorithm>
using namespace std;
#define LEN 100005

typedef struct pp{
	char name[100];
	int t;
}P;

P Q[LEN];
int head, tail, n, total;

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

P dequeue(){
	P x = Q[head];
	head = (head + 1) % LEN;
	return x;
}

int roundrobin(int rest, int q){
	if (q < rest){
		total += q;
		rest -= q;
	}
	else{
		total += rest;
		rest = 0;
	}
	return rest;
}

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

Measured memory_bytes: 13300
import sys
readline = sys.stdin.buffer.readline
read = sys.stdin.read
 
def main():
    N = int(readline())
    A = [0] *(10**5+1)
    total = 0
    for a in map(int, readline().split()):
        total += a
        A[a] += 1
 
 
    Q = int(readline())
    for _ in range(Q):
        b, c = map(int, readline().split())
        total += A[b]*(c-b)
        print(total)
        A[c] += A[b]
        A[b] = 0
 
 
if __name__ == '__main__':
    main()

Measured memory_bytes: 15916
N=int(input())
S = [input() for i in range(N)]
import collections
c = collections.Counter(S)
values, counts = zip(*c.most_common())

n=0
for i in range(len(counts)-1):
  if counts[i]==counts[i+1]:
    n=n+1
  else:
    break
answer=[]    
for i in range(n+1):
  answer.append(values[i])
answer=sorted(answer)

for i in answer:
  print(i)


Measured memory_bytes: 59532
import java.io.*;
 
public class Main {
    public static void main(String[] args) throws Exception {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
 
        String line = br.readLine();
        int n  = Integer.parseInt(line);
 
        int min = Integer.MAX_VALUE;
        int max = Integer.MIN_VALUE;
        long total = 0L;
 
        String[] numline  = br.readLine().split(" ");
 
        for (int i = 0; i < n; i++) {
            int input = Integer.parseInt(numline[i]);
 
            if (min > input) min = input;
            if (max < input) max = input;
            total += input;
        }
 
        System.out.println(min + " " + max + " " + total);
    }
}

Measured memory_bytes: 28556
def resolve():
    # 整数 1 つ
    n = int(input())
    # 整数複数個
    # a, b, c = list(map(int, input().split()))
    # 整数 N 個 (改行区切り)
    # N = [int(input()) for i in range(N)]
    # 整数 N 個 (スペース区切り)
    A = list(map(int, input().split()))
    # 整数 (縦 H 横 W の行列)
    # A = [list(map(int, input().split())) for i in range(H)]

    sumA=0
    sumB=0
    B = sorted(A, reverse=True)
    turnB = False

    for i in B:
        if turnB == False:
            sumA += i
            turnB = True
        else:
            sumB += i
            turnB = False

    print(int(sumA - sumB))


resolve()

Measured memory_bytes: 38384
#include <iostream>
#include <vector>
#include <set>
#include <queue>
#include <map>
#include <cassert>
#include <algorithm>
#include <functional>
#include <math.h>
#define REP(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define RREP(i,n) for(int i=(n)-1; i>=0; --i)
#define SREP(i,s,n) for(int i=(s), i##_len=(n); i<i##_len; ++i)


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

template <typename T>
T gcd(T a, T b) {
    if(a < b) gcd(b, a);
    if (b == 1) return 1;
    T r;
    while ((r=a%b)) {
        a = b;
        b = r;
    }
    return b;
}

bool comp(pair<int, int> a, pair<int, int> b) {
    return a.second > b.second;
}

struct UnionFind {
    vector<int> par;
    vector<int> rank;
    
    UnionFind(int n = 1) {
        init(n);
    }
    
    void init(int n = 1) {
        par.resize(n); rank.resize(n);
        for (int i = 0; i < n; ++i) {
            par[i] = i;
            rank[i] = 0;
        }
    }
    
    int root(int x) {
        if (par[x] == x) {
            return x;
        }
        else {
            int r = root(par[x]);
            return par[x] = r;
        }
    }
    
    bool issame(int x, int y) {
        return root(x) == root(y);
    }
    
    bool merge(int x, int y) {
        x = root(x); y = root(y);
        if (x == y) return false;
        if (rank[x] < rank[y]) swap(x, y);
        if (rank[x] == rank[y]) ++rank[x];
        par[y] = x;
        return true;
    }
};

#define MOD (1000000007)

int main(int argc, const char * argv[]) {
    cin.tie(0);
    ios::sync_with_stdio(false);
    
    ll N;
    cin >> N;
    cout << N*(N-1)/2 << endl;
}


Measured memory_bytes: 256
#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; void _main(); int main() { cin.tie(0); ios::sync_with_stdio(false); _main(); }
typedef long long ll; const int inf = INT_MAX / 2; const ll infl = 1LL << 60;
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; }

const int MAX_N = 100;
const int MAX_M = 100;

int N, M, X, Y;
int x[MAX_N];
int y[MAX_M];

void _main() {
  cin >> N >> M >> X >> Y;
  rep(i, 0, N) cin >> x[i];
  rep(i, 0, M) cin >> y[i];
  sort(x, x + N);
  sort(y, y + M);

  if (X < Y && X < y[0] && x[N-1] < y[0] && x[N-1] < Y)cout << "No War" << "\n";
  else cout << "War" << "\n";
}

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

const int MOD = 1e9 + 7;

long long MyPow(long long x, long long y) {
	long long c = 1;
	while(y) {
		if(y & 1) c = c * x % MOD;
		x = x * x % MOD;
		y >>= 1;
	}
	return c;
}

int n, k;
long long f[200][20000];

void U(long long &x) {
	if(x > MOD) x -= MOD;
	if(x < 0) x += MOD;
}

int main(void) {
	scanf("%d%d", &n, &k);
	long long ans = 0, pp = MyPow(k + 1, n - 1);
	for(int i = 1; i <= n; i++) {
		for(int j = 1; j <= k; j++)
			ans = (ans + pp * j) % MOD;
	}
	f[n][0] = 1;
	for(int i = n; i; i--) {
		for(int j = 0; j <= 10000; j++) {
			if(!f[i][j]) continue;
			for(int l = 0; l <= k; l++) {
				if(l <= i) 
					U(f[i - 1][j + (l + j) / i] += f[i][j] % MOD);
				else 
					U(f[i - 1][j] += f[i][j]);
			}
		}
	}
	for(int i = 0; i <= 10000; i++)
		U(ans -= i * f[0][i] % MOD);
		printf("%lld\n", ans);
	return 0;
}









Measured memory_bytes: 14720
#include<iostream>
#include<iomanip>
#include<map>
#include<unordered_map>
#include<set>
#include<unordered_set>
#include<vector>
#include<array>
#include<string>
#include<stack>
#include<queue>
#include<algorithm>
#include<cassert>
#include<functional>
#include<random>
#include<complex>
#include<bitset>
#include<chrono>
//#include<boost/multiprecision/cpp_int.hpp>
#define int int64_t
#define uint uint64_t
#define REP(i, a, b) for (int64_t i = (int64_t)(a); i < (int64_t)(b); i++)
#define rep(i, a) REP(i, 0, a)
#define EACH(i, a) for (auto i: a)
#define ITR(x, a) for (auto x = a.begin(); x != a.end(); x++)
#define ALL(a) (a.begin()), (a.end())
#define HAS(a, x) (a.find(x) != a.end())
#define Min(x) *min_element(ALL(x))
#define Max(x) *max_element(ALL(x))
#define Unique(L) (L.erase(unique(ALL(L)), L.end()))
#define intmax (std::numeric_limits<int64_t>::max() / 4)
#define doublemax (std::numeric_limits<double>::max() / 4)
using namespace std;
//typedef boost::multiprecision::cpp_int bigint;
const double EPS = 1e-9;
const double PI = acos(-1.0);



signed main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	
	double xstart, ystart, xend, yend;
	cin >> xstart >> ystart >> xend >> yend;
	int N;
	cin >> N;
	vector<array<double, 3>>bar(N+2);
	rep(i, N) {
		cin >> bar[i][0] >> bar[i][1] >> bar[i][2];
	}
	bar[N] = { xstart,ystart,0.0 };
	bar[N+1] = { xend,yend,0.0 };

	//graph[i][j]:=バリアiの中心からバリアjの中心に行くためのコスト
	vector<vector<double>>graph(N+2, vector<double>(N+2));
	rep(i, N + 2)REP(j, i + 1, N + 2) {
		double dx = bar[i][0] - bar[j][0];
		double dy = bar[i][1] - bar[j][1];
		double dist = sqrt(dx*dx + dy*dy);
		double gain = bar[i][2] + bar[j][2];
		graph[i][j] = max(0.0, dist - gain);
		graph[j][i] = graph[i][j];
	}

	typedef pair<double, int>p;
	vector<int>searched(N + 2, 0);
	priority_queue<p, vector<p>, greater<p>>D;
	D.push(make_pair(0.0, N));
	while (!D.empty()) {
		auto x = D.top(); D.pop();
		double dist = x.first;
		int pos = x.second;
		if (searched[pos]++)continue;
		if (pos == N + 1) {
			cout << setprecision(20)<<dist << endl;
			return 0;
		}
		rep(i, N + 2)if (searched[i] == 0) {
			D.push({ dist + graph[pos][i],i });
		}
	}


	return 0;
}


Measured memory_bytes: 16496
//----------------------Shanu Garg here---------------------
//-------------Search on youtube : Shanu Garg---------------
//-Studying at National Institute of Technology Delhi(NITD)-
//---------------------From Delhi, India--------------------

#include<bits/stdc++.h>
#include<algorithm>
using namespace std;

#define f(i,n) for(auto i=0;i<n;i++)
#define fr(i,n) for(auto i=n-1;i>=0;i--)
#define fs(i,a,b,c) for(auto i=a;i!=b;i+=c)
#define fl(i,x) for(auto i : x)
#define nl cout<<"\n";
#define chk(x) cout<<#x<<" : "<<x, nl
#define ll long long int
#define u unsigned
#define vi vector<int>
#define vvi vector<vi>
#define pr pair<ll, ll>
#define vii vector<pair<int, int>>
#define vll vector<pr>
#define vl vector<ll>
#define m(a,b) map<a, b>
#define ci m(char, ll)
#define ii m(ll, ll)
#define mid(a,b) ((a+b)/2)
#define pb push_back
#define LCM(a,b) ((a*b)/__gcd(x,y))
const int INF = 0x3f3f3f3f, mod = 1e9 + 7;

class triplet{
    ll f, s, t;};

vl in(ll n){vl v;ll x;
    f(i,n)
    cin>>x, v.pb(x);
    return v;}
void out(vl v){
    fl(i,v)cout<<i;
}
void out(vl v, char ch){
    fl(i,v)
    cout<<i<<ch;
}

void solve(){
    ll ans=0;
    string S;
    cin>>S;
    ll size = S.size();
    f(i, size/2)
    if(S.at(i) != S.at(size-1-i))
     ans++;

     cout<<ans;
}

int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    solve();
   return 0;
}

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

struct P{
    int x, y, dist;
    P(){}
    ~P(){}
    P(const P& r) : x(r.x), y(r.y), dist(r.dist) {}
    P(int a, int b, int d) : x(a), y(b), dist(d) {}
};

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


int H, W, N;
char field[1000][1010], cpy[1000][1010];

queue<P> que;

int main(){
    while(scanf("%d%d%d", &H, &W, &N) != EOF){
        for(int x = 0; x < H; ++x){
            scanf(" %s", field[x]);
        }
        P loc[10];
        for(int x = 0; x < H; ++x){
            for(int y = 0; y < W; ++y){
                if(field[x][y] == 'S'){
                    loc[0] = P(x, y, 0);
                }
                if('1' <= field[x][y] && field[x][y] <= '9'){
                    loc[field[x][y]-'0'] = P(x, y, 0);
                }
            }
        }
        int ans = 0;
        for(int n = 0; n < N; ++n){
            for(int x = 0; x < H; ++x){
                for(int y = 0; y < W; ++y){
                    cpy[x][y] = field[x][y];
                }
            }
            while(!que.empty()) que.pop();
            que.push(loc[n]);
            cpy[loc[n].x][loc[n].y] = 'X';
            while(!que.empty()){
                P p = que.front();
                que.pop();
                if(p.x == loc[n+1].x && p.y == loc[n+1].y){
                    ans += p.dist;
                    break;
                }
                for(int i = 0; i < 4; ++i){
                    int nx = p.x + dx[i], ny = p.y + dy[i];
                    if(nx < 0 || H <= nx) continue;
                    if(ny < 0 || W <= ny) continue;
                    if(cpy[nx][ny] == 'X') continue;
                    que.push(P(nx, ny, p.dist+1));
                    cpy[nx][ny] = 'X';
                }
            }
        }
        printf("%d\n", ans);
    }
    return 0;
}

Measured memory_bytes: 3184
package main

import (
	"fmt"
	"math"
)

func main() {
	// Code for B - Similar Arrays
	var N int
	fmt.Scan(&N)

	A := make([]int, N)
	for i := 0; i < N; i++ {
		fmt.Scan(&A[i])
	}

	var count int = 1
	for i := 0; i < N; i++ {
		if A[i]%2 == 0 {
			count *= 2
		}
	}

	fmt.Println(int(math.Pow(3, float64(N))) - count)
}


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

 
int main(){
  string A,B,C;
  cin>>A>>B>>C;
  
  if(A.at(A.size()-1)==B.at(0)&&B.at(B.size()-1)==C.at(0)){
    cout<<"YES"<<endl;
  }
  else cout<<"NO"<<endl;
}
  


Measured memory_bytes: 256
#include <stdio.h>

int main() {
	long long a, b, c, k, output = 0;
	scanf("%lld%lld%lld%lld", &a, &b, &c, &k);
	if (a >= k)output += k;
	else {
		output += a;
		if (b >= (k - a))output += 0;
		else output -= k-a-b;
	}
	printf("%lld", output);
	return 0;
}

Measured memory_bytes: 1736
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
struct edge{ll to,cost;};
int main(){
  ll n,i,a,b,c,q,k,x,y,f;scanf("%lld",&n);
  vector<edge> V[n];ll d[n] = {};
  for(i=0;i<n-1;i++){
    scanf("%lld%lld%lld",&a,&b,&c);a--;b--;
    V[a].push_back(edge{b,c});
    V[b].push_back(edge{a,c});
  }
  scanf("%lld%lld",&q,&k);k--;
  queue<ll> Q;Q.push(k);
  while(!Q.empty()){
    f = Q.front();Q.pop();
    for(i=0;i<V[f].size();i++){
      if(d[V[f][i].to] == 0){
        d[V[f][i].to] = d[f]+V[f][i].cost;
        Q.push(V[f][i].to);
      }
    }
  }
  for(i=0;i<q;i++){
    scanf("%lld%lld",&x,&y);x--;y--;
    printf("%lld\n",d[x]+d[y]);
  }
}

Measured memory_bytes: 12212
#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <vector>
#include <cstdlib>
#include <cmath>
#include <string>
#include <map>
#include <queue>
using namespace std;
int main() {
  string s;
  cin >> s;
  int sum = 0;
  for (int i = 0; i < s.size(); i++)
  {
    if (s[i] == '1') sum++; 
  }
  cout << sum << endl;
  return 0;

}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pii = pair<int, int>;
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; }

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

  ll n;
  cin >> n;
  vector<ll> a(n);
  rep(i, n) cin >> a[i];

  vector<ll> ans(n);

  ll sum = 0;
  rep(i, n) {
    if (i%2 == 0) sum += a[i];
    else sum += -a[i];
  }
  ans[0] = sum;

  for (int i = n-1; i > 0; i--) {
    ans[i] = 2*a[i] - ans[(i+1)%n];
  }

  rep(i, n) {
    cout << ans[i] << " ";
  }
}


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

#define rep(i, s, n) for (Int i = s; i < (Int)(n); i++)
#define rrep(i, n, s) for (Int i = n - 1; i >= s; i--)
#define dump(x) cout << (x) << '\n'
#define Int int64_t
#define fi first
#define se second
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).end()
 
double EPS = 1e-10;
Int INF = 1e18;
int inf = 1e9;
Int mod = 1e9+7;

int main() {
    Int n;
    cin >> n;
    dump(n * n * n);
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
using namespace std;
int cost[200000];
int memo[200000];
int initMemo(){
    for(int i = 0; i < 200000; i++){
        memo[i] = -1;
    }
    memo[0] = 0;
    memo[1] = abs(cost[1] - cost[0]);
    return 0;
}
int getCost(int id){
    if(memo[id] != -1){
        return memo[id];
    }
    int tmp = min(getCost(id - 1) + abs(cost[id] - cost[id - 1]),getCost(id - 2) + abs(cost[id] - cost[id - 2]));
    memo[id] = tmp;
    return tmp;
}
int main() {
    int N;
    cin >> N;

    for(int i = 0; i < N; i++){
        cin >> cost[i];
    }
    initMemo();
    cout << getCost(N - 1) << endl;

    return 0;
}

Measured memory_bytes: 2944
def i():
    return int(input())
def i2():
    return map(int,input().split())
def s():
    return str(input())
def l():
    return list(input())
def intl():
    return list(int(k) for k in input().split())

a=[intl() for _ in range(3)]
n=i()
b=[int(input()) for _ in range(n)]
flag=0
falg=0
for i in range(3):
	for j in range(3):
		if a[i][j] in b:
			a[i][j]=0
for i in range(3):
	for j in range(3):
		if a[i][0]==0 and a[i][1]==0 and a[i][2]==0:
			flag+=1
		elif a[0][j]==0 and a[1][j]==0 and a[2][j]==0:
			flag+=1
		elif i==j and a[i][j]==0:
			falg+=1
			if falg==3:
				flag+=1
if a[0][2]==0 and a[1][1]==0 and a[2][0]==0:
	flag+=1
if flag>=1:
	print('Yes')
else:
	print('No')

Measured memory_bytes: 3064
#include <algorithm>
#include <bitset>
#include <cmath>
#include <cstring>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>

const int MOD = 1e9 + 7;
const int iINF = 1000000000;
const long long int llINF = 1000000000000000000;

using namespace std;
using ll = long long int;
using vl = vector<ll>;
using vvl = vector<vector<ll>>;
using vvvl = vector<vector<vector<ll>>>;
using edge = struct {
  int to;
  int cost;
};
#define REP(i, n) for (ll i = 0; i < (n); i++)
#define RREP(i, n) for (ll i = (n)-1; i >= 0; i--)
#define FOR(i, a, b) for (ll i = (a); i < (b); i++)
#define AUTO(i, m) for (auto &i : m)
#define ALL(a) (a).begin(), (a).end()
#define MAX(vec) *std::max_element(vec.begin(), vec.end())
#define MIN(vec) *std::min_element(vec.begin(), vec.end())
#define ARGMAX(vec)                                                            \
  std::distance(vec.begin(), std::max_element(vec.begin(), vec.end()))
#define ARGMIN(vec)                                                            \
  std::distance(vec.begin(), std::min_element(vec.begin(), vec.end()))
#define BIT(n, num) std::bitset<(n)>((num)).to_string()
#define REV(T) greater<T>()
#define PQ(T) priority_queue<T, vector<T>, greater<T>>
#define VVL(a, b, c) vector<vector<ll>>(a, vector<ll>(b, c))
#define VVVL(a, b, c, d)                                                       \
  vector<vector<vector<ll>>>(a, vector<vector<ll>>(b, vector<ll>(c, d)))

typedef pair<ll, ll> pll;
bool paircomp(const pll &a, const pll &b) {
  if (a.first == b.first)
    return a.second < b.second;
  return a.first < b.first;
}

ll POW(ll n, ll m) {
  if (m == 0) {
    return 1;
  } else if (m % 2 == 0) {
    ll tmp = POW(n, m / 2);
    return (tmp * tmp);
  } else {
    return (n * POW(n, m - 1));
  }
}

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

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  ll N, C;
  cin >> N >> C;
  vector<pll> X;
  vl A(N + 2, 0); // 0から見てi以下の場合のmax
  vl B(N + 2, 0); // 0からみてi以上の場合のmax

  //時計回りの累積和
  X.push_back(make_pair(0, 0));
  FOR(i, 1, N + 1) {
    ll x, v;
    cin >> x >> v;
    X.push_back(make_pair(x, X[i - 1].second + v));
  }

  ll ma = 0;
  FOR(i, 1, N + 1) {
    if (ma < X[i].second - X[i].first)
      ma = X[i].second - X[i].first;
    A[i] = ma;
  }
  ma = 0;
  for (ll i = N; i > 0; i--) {
    if (ma < (X[N].second - X[i - 1].second - (C - X[i].first)))
      ma = X[N].second - X[i - 1].second - (C - X[i].first);
    B[i] = ma;
  }

  ll ans = 0;
  FOR(i, 1, N + 1) {
    ans = max(ans, X[i].second - X[i].first);
    ans = max(ans, X[i].second - (2 * X[i].first) + B[i + 1]);
  }
  for (ll i = N; i > 0; i--) {
    ans = max(ans, X[N].second - X[i - 1].second - (C - X[i].first));
    ans = max(ans, A[i - 1] + X[N].second - X[i - 1].second -
                       (2 * (C - X[i].first)));
  }

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


Measured memory_bytes: 3956
N,K=map(int,input().split())
A=list(map(int,input().split()))
ret = 0
for a in range(N):
  for b in range(N-a+1):
    cmax = K-a-b
    if cmax >= 0:
      W=A[:a]+A[N-b:]
      W.sort()
      tmp=0
      for i in range(len(W)):
        if i<cmax and W[i]<0:
          continue
        else:
          tmp=sum(W[i:])
          break
      ret=max(ret,tmp)
print(ret)

Measured memory_bytes: 3064
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <bitset>
#include <map>
#include <tuple>
#include <unordered_set>
#include <unordered_map>
#include <list>
#include <numeric>
#include <utility>
#include <iterator>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cstring>
#include <climits>
#include <ctime>
#include <cassert>
#include <random>
#include <cstring>

#define rep(i,n) for(int i=0;i<int(n);i++)
#define all(x) (x).begin(),x.end()
#define pb push_back

using namespace std;
using ll = long long;

const ll mod = 1000000007;
int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};
int ddx[8]={-1,-1,0,1,1,1,0,-1};
int ddy[8]={0,1,1,1,0,-1,-1,-1};
bool debug=false;

/*---------------------------------------------------*/

int main() {
  int A, B;
  cin >> A >> B;
  if(A <= 5) cout << 0 << endl;
  else if(A < 13) cout << B / 2 << endl;
  else cout << B << endl;
  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <map>
#include <set>
#include <list>
#include <algorithm>
#include <queue>
#include <cmath>
#include <iomanip>
// #include <fstream>

int main()
{
    int n;
    std::cin >> n;
    std::vector<int> h(n), dp(n, 1e8);
    for(int i=0; i<n; i++) std::cin >> h[i];

    dp[0] = 0;
    dp[1] = abs(h[1]-h[0]);
    int ans = 0, pos = 0;
    
    for(int i=2; i<n; i++)
    {
        dp[i] = std::min(dp[i-2]+abs(h[i]-h[i-2]), dp[i-1]+abs(h[i]-h[i-1]));
    }
    
    std::cout << dp[n-1] << std::endl;
}

Measured memory_bytes: 1024
/*input
5
138 138 138 138 138
*/
/**
    Author: Kristopher Paul
    Date Created: 18-08-2019
    Contest Name:
                _/    _/   _/_/_/_/   _/   _/_/_/_/
               _/  _/     _/    _/   _/   _/
              _/_/       _/_/_/_/   _/   _/_/_/_/
             _/  _/     _/  _/     _/         _/
            _/    _/   _/    _/   _/   _/_/_/_/
**/
#include<bits/stdc++.h>
#define ll long long
#define int ll
#define pb push_back
#define INF 1e18
#define MOD 1000000007
#define mp make_pair
const double PI=3.141592653589793238462643383279502884197169399375105820974944;
#define REP(i,n) for (int i = 0; i < n; i++)
#define FOR(i,a,b) for (int i = a; i < b; i++)
#define REPD(i,n) for (int i = n-1; i >= 0; i--)
#define FORD(i,a,b) for (int i = a; i >= b; i--)
#define remax(a,b) a = max(a,b)
#define remin(a,b) a = min(a,b)
#define umap unordered_map
#define pii pair<int,int>
#define F first
#define S second
#define mii map<int,int>
#define vi vector<int>
#define vvi vector<vi>
#define itr :: iterator it
#define all(v) v.begin(),v.end()
#define WL(t) while(t--)
#define gcd(a,b) __gcd((a),(b))
#define lcm(a,b) ((a)*(b))/gcd((a),(b))
#define out(x) cout << #x << " is " << x << endl
#define FastIO ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
using namespace std;

int ModExp(int x,int y,int m){
    int res = 1;
    x = x % m;
    while (y > 0)
    {
        if (y & 1)
            res = (res*x) % m;

        y = y>>1;
        x = (x*x) % m;
    }
    return res;
}

void solve(){
    int n;
    cin >> n;
    int arr[n];
    FOR(i,0,n){
        cin >> arr[i];
    }
    sort(arr,arr+n);
    double cur = arr[0];
    FOR(i,1,n){
        cur = double(cur+arr[i])/2.0;
    }
    cout << cur << endl;
}

signed main(){
    FastIO;
    int t = 1;
//    cin >> t;
    WL(t){
        solve();
    }
}


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

using namespace std;

const uint64_t B = 103, H = 1e+17+3;

inline uint64_t ctoi(char c) { return c - 'a' + 1; }

uint64_t to_hash(const string &s)
{
  uint64_t _hash = 0;
  for (uint64_t i = 0; i < s.size(); ++i) {
    _hash = (_hash * B) % H;
    _hash = (_hash + ctoi(s[i])) % H;
  }
  return _hash;
}

inline uint64_t build_mask(uint64_t L) {
  uint64_t mask = 1;
  for (uint64_t i = 0; i < L - 1; ++i) {
    mask = (mask * B) % H;
  }
  return mask;
}

inline uint64_t change_hash(uint64_t _hash, uint64_t mask, char c1, char c2)
{
  uint64_t x = (ctoi(c1) * mask) % H;
  _hash = ((_hash + H) - x) % H;
  _hash = (_hash * B) % H;
  _hash = (_hash + ctoi(c2)) % H;
  return _hash;
}

inline bool is_not_overlap(uint64_t lb1, uint64_t ub1, uint64_t lb2, uint64_t ub2)
{
  return (ub2 <= lb1) || (ub1 <= lb2);
}

bool find(uint64_t N, const string &S, uint64_t L)
{
  uint64_t mask = build_mask(L);
  
  uint64_t hash = to_hash(S.substr(0, L));
  
  map<uint64_t, set<uint64_t>> m;
  m[hash].insert(0);
  
  for (uint64_t i = 1; i <= S.size() - L; ++i) {
    hash = change_hash(hash, mask, S[i - 1], S[i + L - 1]);
    
    if (m[hash].size() > 0) {
      for (uint64_t j : m[hash]) {
        if (is_not_overlap(i, i + L, j, j + L)) {
          if (S.substr(i, L) == S.substr(j, L)) {
            return true;
          }
        }
      }
    }
    
    m[hash].insert(i);
  }
  
  return false;
}

int main()
{
  uint64_t N;
  cin >> N;
  
  string S;
  cin >> S;
  
  uint64_t hi = N, lo = 0;
  
  while (hi - lo > 1) {
    uint64_t L = (hi + lo) >> 1;
    if (find(N, S, L)) {
      lo = L;
    } else {
      hi = L;
    }
  }
  
  if (find(N, S, hi)) {
    cout << hi << endl;
  } else {
    cout << lo << endl;
  }
  
  return 0;
}

Measured memory_bytes: 1012
N=list(input())
cnt=0
size=len(N)-1
if size==0:
    print(N[0])
    exit()
N.reverse()

for i in range(size):
    if N[i]!="9":
        N[i]="9"
        N[i+1]=str(int(N[i+1])-1)
for i in range(size+1):
    cnt+=int(N[i])
print(cnt)


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

typedef long long int ll;
ll MOD = 1000000007;

// ====================================================================

int main() {
  ll n, m, ans = 1;
  cin >> n >> m;

  // 無理
  if (abs(n - m) > 1) {
    cout << 0 << endl;
    return 0;
  }

  for (int i = 1; i <= n; i++) ans = ans * i % MOD;
  for (int i = 1; i <= m; i++) ans = ans * i % MOD;
  cout << ans * ((n == m) + 1) % MOD << endl;
}


Measured memory_bytes: 256
INT_MAX = 10**8
h, n = map(int, input().split())
e = [tuple(map(int, input().split())) for _ in range(n)]

dp = [INT_MAX] * (h+1)
dp[0] = 0
for i in range(1, h+1):
  for a, b in e:
    c = dp[max(0, i - a)] + b
    dp[i] = min(dp[i], c)

print(dp[h])

Measured memory_bytes: 42604
//include
//------------------------------------------
#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <queue>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>

using namespace std;
#define EPS (1e-7)

#define SORT(c) sort((c).begin(),(c).end())
#define ANS(ans) cout<<(ans)<<endl;
typedef vector<int> VI;


//repetition
//------------------------------------------
#define FOR(i,a,b) for(int i=(a);i<=(b);++i)
#define REP(i,n)  for (int i = 0; i < (n); ++i)


int main() {
	long long a = 1;
	long long b = 1;
	int n;
	cin >> n;

	long long x, y;
	long long k1, k2;
	REP(i, n) {
		cin >> x >> y;
		if (x >= a && y >= b) {
			a = x;
			b = y;
		}
		else {
			if (a%x == 0) {
				k1 = a / x;
			}
			else {
				k1 = a / x + 1;
			}

			if (b%y == 0) {
				k2 = b / y;
			}
			else {
				k2 = b / y + 1;
			}

			long long k = max(k1, k2);
			a = x*k;
			b = y*k;

		}
		//cout << a << " " << b << endl;
	}

	cout << a + b << endl;




	return 0;
}



Measured memory_bytes: 256
#include <iostream>
using namespace std;
int main(){
  int n;
  while (cin>>n,n|n!=0){
    int b=1;
    int ans=0;
    int count=0;
    for (int k=2;k<n;k++){
      for (int i=1;i<n;i++){
	int j;
	for (j=i;j<i+k;j++){
	  ans=ans+j;
	}
	if (ans==n){
	  count++;
	  ans=0;
	  break;
	}
	else if (ans>n){
	  ans=0;
	  if (i==1)
	    b=0;
	  break;
	}
	ans=0;
      }
      if (b==0){
	break;
      }
    }
    cout<<count<<endl;
  }
}

Measured memory_bytes: 1160