akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#include <math.h>
#include <cmath>

using namespace std;
using ll =long long;
using vi = vector<int>; 
using vvi = vector<vi>; 
using vl = vector<ll>; 
using vvl = vector<vl>; 
using vs = vector<string>;
using vvs = vector<vs>; 
using vc = vector<char>;
using vvc = vector<vc>; 
using vb = vector<bool>;
using vvb = vector<vb>; 

#define rep(i,n) ;for( int i =0; i < n ; i ++)
#define all(a) a.begin(),a.end()
#define pb(a) push_back(a)
#define pd(a) printf("%.10f\n",a)
#define mem(a) memset(a,0,sizeof(a))
#define f(i,a,b) for(int i=a;i<b;i++)
#define pri(a)  printf("%.14lf\n",a);
#define MOD 1000000007
bool is_int_lround(double x){
  return std::lround(x)==x;
}
ll keta(ll x){
  ll n=0;
  while(x>0){
    x /=10 ;
    n ++;
  }
  return n;
}

ll conbi(int n,int m){
  
  cin>>n>>m;
  vector<ll> a(100);
  a[0] =1;
  for(int i=0;i<14;i++){
    a[i+1]=a[i]*(i+1);
  }
  return a[n] /(a[m] *a[n-m]);
}

long long modpow(long long a, long long n, long long mod) {
    long long res = 1;//繰り返し二乗法
    while (n > 0) {
        if (n & 1) res = res * a % mod;
        a = a * a % mod;
        n >>= 1;
    }
    return res;
}
ll kaijoMOD(ll x){
  ll z=1;
  if(x==0){
    return 1;
  }
  while(x>0){
    z *=x;
    z %=MOD;
    x--;
  }
  return z;
}
ll yakusu_num(ll n){
  vl yakusu(n+1,1);
  for(ll i=2;i*i<=n;i++){ 
    while(n%i==0){
      n /=i;
      yakusu[i]++;
    }
  }
  if(n!=1)yakusu[n]++;
  ll num=1;
  for(ll i=0;i<=n;i++){
    num*=yakusu[i];
  }
  return num;
}

int H,W;
vs s(50);
vi dv ={-1,0,1,0};vi du={0,-1,0,1};
int cnt=1;
int dfs(int u,int v){
  s[u][v]='.';
  
  rep(i,4){
   
      int nu =u +du[i],nv=v+dv[i];
      if(nu<0||nu>=H||nv<0||nv>=W)continue;
      if(s[nu][nv]=='.')continue;
      cnt ++;
      dfs(nu,nv);
    
  }
  return cnt;

}
int keta_wa(int x){
  int tot=0;
  while(x>0){
    tot +=x%10;
    x/=10;
  }
  return tot;
}

//vc alp ={'a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z'};
//vc Alp ={'A','B','C','D','E','F','G','H','I','J','K','L','M','N','O','P','Q','R','S','T','U','V','W','X','Y','Z'};
//cout<<""<<endl;
int main(){
 
  int N;cin>>N;
  cout<<N*800-200*(N/15)<<endl;
}   





Measured memory_bytes: 256
#include <bits/stdc++.h>
#define F first
#define S second
#define ld long douroote
#define pb push_back
#define sz size
#define ll long long
#define ull unsigned long long
#define INF 0x7f7f7f7f
#define sc(a) scanf("%d",&a)
#define scll(a) scanf("%lld",&a)
#define scd(a) scanf("%lf",&a)
#define scc(a) scanf(" %c",&a)
#define scs(a) scanf(" %s",a)
#define me(a,b) memset(a,b,sizeof a)
#define all(a) a.begin(),a.end()
#define allr(a,n) a,a+n
#define loop(a,s,e) for(ll a=s;a<=e;a++)
#define read_arr(a,s,n) for(int i=s;i<n+s;i++){sc(a[i]);}
#define read_arr_ll(a,s,n) for(int i=s;i<n+s;i++){scll(a[i]);}
#define err(a,s) cerr<<a<<s;
#define err_arr(a,s,n) for(int i=s;i<n+s;i++){cerr<<a[i]<<" ";}cerr<<endl;
#define prtll(x) printf("%lld",x);
#define prt(x) printf("%d",x);
using namespace std;
const int N=1e5+10;
int mod=1e9+7,a[110],mem[110][N],n,k,pr[N];
/**
int dp(int ind,int h){
if(h<0){return 0;}
if(ind==n){return (h==k);}
int &ret=mem[ind][h];
if(ret!=-1){return ret;}
ret=0;
loop(i,0,a[ind]){ret+=dp(ind+1,h-i)%mod;ret%=mod;}
return ret%mod;
}**/
int main(){
sc(n);sc(k);
read_arr(a,0,n);
mem[n][0]=1;
loop(i,0,k){pr[i]=pr[i-1]+mem[n][i];}
loop(i,0,n){mem[i][0]=1;}
for(int i=n-1;i>=0;i--){
   for(int h=1;h<=k;h++){
      int l=(h-a[i]-1>= 0?pr[h-a[i]-1]:0);
      int r=pr[h];
      mem[i][h]=((r-l)%mod+mod)%mod;
   }
   pr[0]=1;
   for(int j=1;j<=k;j++){pr[j]=pr[j-1]+mem[i][j];pr[j]%=mod;}
}
/**
loop(i,0,n){
  loop(j,0,k){
    cerr<<mem[i][j]<<" ";
  }
  cerr<<endl;
}**/
int ans=(((mem[0][k]%mod)+mod)%mod);
printf("%d\n",ans);
}
/**
**/


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



int main(){
    ll n,k;cin>>n>>k;
    deque<ll> q,Q;
    rep(i,0,n){
        ll a;cin>>a;
        q.push_back(a);
    }
    Q=q;
    ll an=0,MX=0;
    priority_queue<ll, vector<ll>, greater<ll> > pq,vc;
    rep(i,0,k+1){
        rep(j,0,k-i+1){
            if(i+j>n)continue;
            an=0;
            rep(I,0,i){
                an+=q.front();
                pq.push(q.front());
                q.pop_front();
            }
            rep(J,0,j){
                an+=q.back();
                pq.push(q.back());
                q.pop_back();
            }
            rep(K,0,k-i-j){
                if(!pq.empty()&&pq.top()<0){
                    an-=pq.top();
                    pq.pop();
                }
            }
            MX=max(MX,an);
            pq=vc;
            q=Q;
        }
    }
    cout<<MX<<endl;
}
    









Measured memory_bytes: 256
#include <iostream>
#include <cmath>
#define ll long long
using namespace std;
int main()
{
  ll x,y;
  cin >> x >> y;
  ll arr1[x][2];
  ll arr2[y][2];
  for(ll i=0;i<x;i++)
  {
    for(ll j=0;j<2;j++)
      cin >> arr1[i][j];
  }
  for(ll i=0;i<y;i++)
  {
    for(ll j=0;j<2;j++)
      cin >> arr2[i][j];
  }
  ll a,b,q,p;
  for(ll i=0;i<x;i++)
  {
    ll distance=1e10,index=10000,
    a=arr1[i][0];
    b=arr1[i][1];
    for(ll j=0;j<y;j++)
    {
      p=abs(a-arr2[j][0]);
      q=abs(b-arr2[j][1]);
      ll k1 = p+q;
      if(k1<distance)
      {
        distance=k1;
        index=j+1;
      }
    }
    cout << index << endl;
  }
 
  return 0;
}

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

struct d{
  int time, prob, team;
};
bool operator<(const d &a, const d &b){
  if(a.prob == b.prob)
  {
    if(a.time == b.time)
    {
      return a.team > b.team;
    }
    return a.time < b.time;
  }
  return a.prob > b.prob;
}
int main(){

  int M, T, P, R;
  int m, t, p, j, i;

  while(cin >> M >> T >> P >> R, M+T+P+R){
    d res[T+1];
    for(i = 1; i <= T; i++){
      res[i].time = res[i].prob = 0;
      res[i].team = i;
    }
    int rank[T+1][P+1];
    for(i = 1; i <= T; i++){
      for(j = 1; j <= P; j++){
        rank[i][j] = 0;
      }
    }
    for(i = 0; i < R; i++){
      cin >> m >> t >> p >> j;
      if(m > M) break;
      if(j){
        rank[t][p]++;
      }else{
        res[t].time += m + rank[t][p]*20;
        res[t].prob++;
      }
    }
    /* cerr << "debug" << endl;
    for(i=1; i<=T; i++)
    {
      cerr << res[i].team << "," << res[i].prob << "," << res[i].time << endl;
    }
    cerr << "debug" << endl;
*/
    sort(res+1, res+T+1);
    cout << res[1].team;
    for(i=2; i<=T; i++)
    {
      cout << ((res[i].prob==res[i-1].prob && res[i].time==res[i-1].time) ? "=" : ",") << res[i].team;
    }
    cout << endl;
    //cerr << endl;
  }
  return 0;
}

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

typedef struct point{
  int x;
  int y;
} point;

int cmpp(const void *lhs, const void *rhs){
  point *l = (point *)lhs;
  point *r = (point *)rhs;
  if(l->x != r->x) return l->x - r->x;
  return l->y - r->y;
}

point p[5001];

int main(){
  int i, j;
  int n, m;
  int ldx, ldy, rux, ruy;

  scanf("%d%d", &n, &m);
  for(i = 0; i < n; i++)
    scanf("%d%d", &p[i].x, &p[i].y);

  qsort(p, n, sizeof(point), cmpp);

  p[n].x = 1000000000 + 1;

  for(i = 0; i < m; i++){
    int ans = 0;

    scanf("%d%d%d%d", &ldx, &ldy, &rux, &ruy);

    for(j = 0; rux >= p[j].x; j++){
      const int x = p[j].x;
      const int y = p[j].y;

      if(ldx <= x && x <= rux &&
         ldy <= y && y <= ruy){
        ans++;
        continue;
      }
    }

    printf("%d\n", ans);
  }

  return 0;
}

Measured memory_bytes: 716
package main

import "fmt"

func main() {
 n := 0
 hp := 0
 //たこ焼きの個数を受け取る
 fmt.Scanf("%d",&n)
 
 //たこ焼きのおいしさを配列に格納
 num := make([]int,n)
 for i:=0; i < n; i++ {
 	fmt.Scanf("%d",&num[i])
 }

 for i:=0; i < n-1; i++ {
   for j:=i+1; j<n; j++ {
     hp += num[i] * num[j]
   }
 }
 fmt.Printf("%d",hp)
}

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

int a[3], ans = 1e8;

int main() {
	cin >> a[0] >> a[1] >> a[2];
	sort(a, a + 3);
	do{
		ans = min(ans, abs(a[1] - a[0]) + abs(a[2] - a[1]));
	}while(next_permutation(a, a + 3));
	cout << ans;
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <cstring>
#include <algorithm>
#include <functional>
#include <cmath>
#include <set>
#include <queue>
#include <deque>
#include <vector>
#include <climits>
#include <sstream>
#include <iomanip>
#include <map>
#include <stack>
using namespace std;
typedef unsigned long long ull;
typedef long long ll;

int main()
{
	int N, M;
	ll X;
	cin >> N >> M >> X;
	vector<ll> C(N);
	vector<vector<ll>> A(N, vector<ll>(M));
	for (auto i = 0; i < N; ++i)
	{
		cin >> C[i];
		for (auto j = 0; j < M; ++j)
		{
			cin >> A[i][j];
		}
	}

	auto ans = LLONG_MAX;
	for (auto i = 1; i < 1 << N; ++i)
	{
		auto sumC = 0ll;
		vector<ll> sumA(M);
		for (auto j = 0; j < N; ++j)
		{
			if ((i & (1 << j)) == 0)
			{
				continue;
			}

			for (auto k = 0; k < M; ++k)
			{
				sumA[k] += A[j][k];
			}

			sumC += C[j];
		}

		for (auto k = 0; k < M; ++k)
		{
			if (sumA[k] < X)
			{
				sumC = ans;
				break;
			}
		}

		ans = min(ans, sumC);
	}

	if (ans >= LLONG_MAX)
	{
		ans = -1;
	}
	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 3648
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define rrep(i,n) for(int i = 1; i <= (n); ++i)
#define drep(i,n) for(int i = (n)-1; i >= 0; --i)
#define all(x) (x).begin(),(x).end()
#define SZ(x) ((int)(x).size())
#define bit(n) (1<<(n))
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<vi> vvi;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
template < typename T > string tost( const T& n ) { ostringstream stm; stm << n; return stm.str();}
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;}
int const INF = 1001001001;

int dp[105][4][2];

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

string S; cin >> S;
int N = S.size();
int K; cin >> K;

dp[0][0][0] = 1;
rep(i,N)rep(j,4)rep(k,2) {
    int D = S[i] - '0';
    rep(d, 10) {
        int ni = i+1, nj = j, nk = k;
        if(d != 0) nj++;
        if(nj > K) continue;
        if(k == 0) {
            if(d > D) continue;
            if(d < D) nk = 1;
        }
        dp[ni][nj][nk] += dp[i][j][k];
    }
}
int ans = dp[N][K][0] + dp[N][K][1];
cout << ans << endl;
return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
int main(){
    long long int n,a=10,b=0;
    scanf("%lld\n",&n);
    if(n%2==0){
        while(a<=n){
            b=b+n/a;
            a=a*5;
        }
    }
    printf("%lld\n",b);
}

Measured memory_bytes: 1736
import sys, re
import math
 
def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
MOD = 10 ** 9 + 7
 
# 整数リストを連結表示    print(''.join(map(str, list)))
 
# -*- coding: utf-8 -*-
 
n = INT()
sum = 0
 
for x in range(0, n + 1):
    if x % 3 != 0 and x % 5 != 0:
        sum += x
 
print(sum)

Measured memory_bytes: 9932
N = int(input())

A = []
for i in range(N):
    A.append(int(input()))
    
Amin = sorted(A)
Amax = sorted(A,reverse=True)

if N%2==0:
    SUM = 0
    SUM += sum(Amax[:N//2-1])*2
    SUM += sum(Amax[N//2-1:N//2])
    SUM -= sum(Amax[N//2:N//2+1])
    SUM -= sum(Amax[N//2+1:N])*2
    print(SUM)
else:
    SUM_A,SUM_B = 0,0
    #並べ方が2通り
    SUM_A += sum(Amax[:N//2])*2
    SUM_A -= sum(Amax[N//2:N//2+2])
    SUM_A -= sum(Amax[N//2+2:N])*2
    
    SUM_B -= sum(Amin[:N//2])*2
    SUM_B += sum(Amin[N//2:N//2+2])
    SUM_B += sum(Amin[N//2+2:N])*2
    
    print(max([SUM_A,SUM_B]))

Measured memory_bytes: 8932
process.stdin.on('data', function(chunk) {
  var inputs = chunk.toString().trim().split(' ');
  var a=Number(inputs[0]);
  var b=Number(inputs[1]);
  // ????????????????????????
console.log(a * b,(a+b)*2);
});
process.stdin.resume();
process.stdin.setEncoding('utf8');

Measured memory_bytes: 15456
#include <algorithm>
#include <bitset>
#include <cmath>
#include <functional>
#include <iostream>
#include <iterator>
#include <limits>
#include <map>
#include <queue>
#include <set>
#include <string>
#include <utility>
#include <unordered_map>
#include <unordered_set>
using namespace std;

#define ABS(a) (((a) >= 0) ? (a) : -(a))
#define MAX(a, b) ((a) > (b) ? (a) : (b))
#define MIN(a, b) ((a) > (b) ? (b) : (a))
#define FOR(i, a, b) for (int i = (a); i <= (b); ++i)
#define RFOR(i, a, b) for (int i = (a); i >= (b); --i)
#define REP(i, n) for (int i = 0; i < (n); ++i)
#define POW_10_5 100000
#define POW_10_9 1000000000
#define MOD 1000000007
#define INF (numeric_limits<int>::max()/2)
#define int long long

typedef pair<int, int> Pair;
typedef unordered_map<int, int> Hash;

int PowMod(int a, int b, int m) {
  int r = 1;
  while (b > 0) {
    if (b&1) { r = r*a % m; }
    a = a*a % m;
    b >>= 1;
  }
  return r;
}

// ---
int M = 998244353;

int N;
int D[POW_10_5];
int C[POW_10_5];

int Ans() {
  if (D[0] != 0) { return 0; }
  FOR(i, 1, N-1) {
    if (D[i] == 0) { return 0; }
  }

  FOR(i, 0, N-1) {
    C[D[i]] += 1;
  }
  // C[0] = 1 であるはず

  // 歯抜けを弾く
  int mc = 0;
  bool yabai = false;
  FOR(i, 1, N-1) {
    if (C[i] == 0) {
      yabai = true;
    } else {
      if (yabai) { return 0; }
      mc = i;
    }
  }

  int a = 1;
  FOR(i, 1, mc) {
    a = (a * PowMod(C[i-1], C[i], M)) % M;
  }

  return a;
}

signed main() {
  cin >> N;
  REP(i, N) { cin >> D[i]; }

  auto ans = Ans();

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


Measured memory_bytes: 1792
from collections import deque


h,w=map(int,input().split())
maze=[list(input()) for i in range(h)]
d=[[-1]*w for i in range(h)]
que=deque([])
dd=((1,0),(0,1),(-1,0),(0,-1))
for i in range(h):
    for j in range(w):
        if maze[i][j]=="#":
            que.append((i,j))           
            d[i][j]=0
ans=0
while que:
    p=que.popleft()
    ans=d[p[0]][p[1]]
    for dx,dy in dd:
        nx=p[0]+dx
        ny=p[1]+dy
        if 0<=nx and nx<h and 0<=ny and ny<w and maze[nx][ny]!="#" and d[nx][ny]==-1:
            d[nx][ny]=ans+1
            que.append((nx,ny))  
print(ans)

Measured memory_bytes: 122588
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		String A = sc.next();
		String S = sc.next();
		String C = sc.next();
		System.out.println("A" + String.valueOf(S.charAt(0)) + "C");
	}
}

Measured memory_bytes: 21716
/*
--------------              |   /
      |                     |  /
      |                     | /
      |             *       |/          |    |         ------            *
      |                     |           |    |        /      \
      |             |       |\          |    |       |       |\          |
   \  |             |       | \         |    |       |       | \         |
    \ |             |       |  \        |    |        \     /   \        |
     V              |       |   \        \__/|         -----     \       |
*/
#include <bits/stdc++.h>
using namespace std;

#define EmiliaMyWife ios::sync_with_stdio(0); cin.tie(NULL);
#define mem(i,j) memset(i,j,sizeof (i));
#define F first
#define S second
#define lowbit(x) ((x)&(-(x)))
#define siz(v) (int)(v).size()
typedef int64_t ll;
typedef uint64_t ull;
typedef long double ld;
const double EPS  = 1e-8;
const int INF     = 0x3F3F3F3F;
const ll LINF     = 4611686018427387903;
const int MOD     = 1e9+7;
/*-----------------------------------------------------------------------------------------------------*/

signed main() {
	EmiliaMyWife

	int n, k;
	cin >> n >> k;
	vector<bool> dp(k+1);
	vector<int> arr(n);
	//dp[0] = 0;
	for(int i = 0; i < n; i++)
		cin >> arr[i];
	for(int i = 1; i <= k; i++) {
		for(int &a : arr) {
			if(a <= i)
				dp[i] =  dp[i] | !dp[i-a];
		}
	}
	cout << (dp[k]?"First":"Second") << '\n';

	return 0;
}


Measured memory_bytes: 3656
#include <stdio.h>
#include <string.h>
#define MAX 100

int main()
{
  int m, n, k, i, j;
  int t=0, base=0, gap=0, count=0;
  int word[MAX];
  char st[MAX], ch;

  /*
  scanf("%s",st);
  printf("%s\n",st);
  */
  
  while(t!=1)
    {
      scanf("%d",&n);
      //printf("Scan n!!\n");
      
      if(n==0)
	t = 1;
      else
	{
	  for(i=0;i<=n-1;i++)
	    {
	      scanf("%s",st);
	      k = strlen(st);
	      word[i] = k;
	      /*CHECK!!*/
	      //printf("strlen No.<%d> %d\n",i,k);
	    }
	  /*CHECK!!!!
	  for(i=0;i<=n-1;i++)
	    {
	      printf("word[%d] %d\n",i,word[i]);
	    }
		*/

	  i = 0;
	  j = 0;
	  m = 0;
	  count = 0;
	  while(i<=n-6)
	    {
		  count = 0;
	      m = i;
		  //printf("m = %d",m);
	      do
		{
		  count =  count + word[i];
		  i++;
		}while(count<5);
	      if(count==5)
		{
		  count = 0;
		  do
		    {
		      count = count + word[i];
		      i++;
		    }while(count<7);
		  base = 0;
		  if(count==7)
		    {
		      count = 0;
		      do
			{
			  count = count + word[i];
			  i++;
			}while(count<5);
		      base = 0;
		      if(count==5)
			{
			  count = 0;
			  do
			    {
			      count = count + word[i];
			      i++;
			    }while(count<7);
			  base = 0;
			  if(count==7)
			    {
			      count = 0;
			      do
				{
				  count = count + word[i];
				  i++;
				}while(count<7);
			      base = 0;
			      if(count==7)
				{
				  i = n;
				  /*count = 0;
				  do
				    {
				      count = base + word[i];
				      i++;
				    }while(count<7);
				    base = 0;*/
				}
			      else
				{
				  m++;
				  i = m;
				  //printf("m = %d (57577)\n",m);
				  }
			    }
			    else
			    {
			      m++;
			      i = m;
				  //printf("m = %d (5757)\n",m);
			      }
			}
		      else
			{
			  m++;
			  i = m;
			  //printf("m = %d (575)\n",m);
			  }
		    }
		      else
		    {
		      m++;
		      i = m;
			  //printf("m = %d (57)\n",m);
		      }
		}
	      else
		{
		  m++;
		  i = m;
		  //printf("m = %d (5)\n",m);
		  }
	    }
	 printf("%d\n",m+1);
	}
    }
  return(0);
}

Measured memory_bytes: 604
#include<iostream>
int main()
{
  int n;std::cin>>n;
  int flag=0;
  while(n>9){
    if(n%10==7)
      flag=1;
    n/=10;
  }
  if(n==7) flag=1;
  if(flag) std::cout<<"Yes";
  else std::cout<<"No";
  return 0;
}

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

#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define repr(i, n) for(int i = (int)(n); i >= 0; i--)
#define repm(i, m, n) for(int i = (int)(m); i < (int)(n); i++)
#define repmr(i, m, n) for(int i = (int)(n); i >= (int)(m); i--)
#define all(x) (x).begin(),(x).end()
#define inf 2e9
#define MOD 1000000007

using namespace std;
typedef long long ll;

int main(){
  
  ll h; cin >> h;

  int fase = 1;
  while(true){
    h /= 2;
    if(h == 0){
      break;
    }
    else{
      fase++;
    }
  }

  ll ans = pow(2,fase) - 1;

  cout << ans << endl;


  
}


Measured memory_bytes: 384
#include <iostream>
#include <vector>
#include <algorithm>
#include <string.h>
#include <iomanip>
#include <math.h>

typedef long long int ll;

#define FOR(i,n,m) for(ll i=(ll)(m);i<(ll)(n);++i)
#define REP(i,n) FOR(i,n,0)
#define IREP(i,n) for(ll i=(ll)(n);i>=0;--i)
#define OF64 std::setprecision(10)

const ll MOD = 1000000007;

using namespace std;

ll A[100005];
ll S[100005];
ll P[100005];

int main()
{
	int N, K;
	cin >> N >> K;
	REP(i, N)
	{
		cin >> A[i];
	}

	S[0] = A[0];
	P[0] = std::max(A[0], (ll)0);
	FOR(i, N, 1)
	{
		S[i] = A[i] + S[i - 1];
		P[i] = P[i - 1] + std::max(A[i], (ll)0);
	}

	ll max = 0;
	REP(i, N - K + 1)
	{
		int l = i, r = i + K - 1;
		ll lS = 0, rS = 0;
		if (l > 0)
		{
			lS = P[l - 1];
		}
		rS = P[N - 1] - P[r];

		ll mS = 0;
		if (l == 0)
		{
			mS = std::max(mS, S[r]);
		}
		else
		{
			mS = std::max(mS, S[r] - S[l - 1]);
		}
		max = std::max(max, rS + lS + mS);
	}
	cout << max << endl;
	return 0;
}

Measured memory_bytes: 2560
#include <bits/stdc++.h>
#define ri register
#define int long long
using namespace std; const int N=5010;
inline int read()
{
    int s=0,w=1; char ch=getchar();
    while(ch<'0'||ch>'9') {if(ch=='-') w=-1; ch=getchar(); }
    while(ch>='0'&&ch<='9') s=(s<<3)+(s<<1)+(ch^48),ch=getchar(); return s*w;
}
int n,X,Y;
int dp[N][N],p[N];
signed main()
{
	n=read(), X=read(), Y=read();
	for(ri int i=1;i<=n;i++) {int x=read(); p[x]=i; }
	for(ri int i=1;i<=n;i++) for(ri int j=0;j<=n;j++) dp[i][j]=LONG_LONG_MAX/2;
	for(ri int i=1;i<=n;i++)
	{
		for(ri int j=0;j<=n;j++)
		{
			if(p[i]==j) dp[i][j]=min(dp[i-1][j-1],dp[i][j]);
			if(j<p[i]) dp[i][j]=min(dp[i][j],dp[i-1][j]+Y);
			else dp[i][j]=min(dp[i][j],dp[i-1][j]+X);
		}
		for(ri int j=1;j<=n;j++) dp[i][j]=min(dp[i][j],dp[i][j-1]);
	}
	printf("%lld\n",dp[n][n]);
    return 0;
}

Measured memory_bytes: 195968
#include <iostream>
#include <algorithm>
#include <fstream>
#include <vector>
#include <deque>
#include <assert.h>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <stdio.h>
#include <string.h>
#include <utility>
#include <math.h>
#include <bitset>
#include <iomanip>
#include <complex>
using namespace std;
#define rng(i,a,b) for(int i=int(a);i<int(b);i++)
#define rep(i,b) rng(i,0,b)
#define gnr(i,a,b) for(int i=int(b)-1;i>=int(a);i--)
#define per(i,b) gnr(i,0,b)
#define ALL(x) (x).begin(),(x).end()
#define RALL(x) (x).rbegin(),(x).rend()
#define IDX(vec, element_iter) distance((vec).begin(), element_iter)
#define print(x) cout<<(x)<<'\n'
#define print_vec(v) rep(i,v.size()){if(i!=0)cout<<" ";cout<<v[i];}cout<<'\n'
#define pe(x) cout<<(x)<<" "
#define DEBUG(x) cout<<#x<<": "<<x<<'\n'
#define DEBUG_VEC(v) cout<<#v<<":";rep(i,v.size())cout<<" "<<v[i];cout<<'\n'
#define pb push_back
#define mp make_pair
#define MOD 1000000007 //10^9+7
#define fi first
#define sc second
using ll=long long;
using pi=pair<ll,ll>;
using vi=vector<int>;
using vll=vector<ll>;
using vstr=vector<string>;
int dx[4]={0,0,-1,1};
int dy[4]={-1,1,0,0};
void Yes(bool c) { if (c)print("Yes"); else print("No"); };
void YES(bool c) { if (c)print("YES"); else print("NO"); };

void solve() {
    int A,B,C,X,Y;
    cin >> A >> B >> C >> X >> Y;
    ll ans = min(A+B,2*C)*min(X,Y) + min(A,2*C)*max(0,X-Y) + min(B,2*C)*max(0,Y-X);
    print(ans);
}
 
int main() {
    cin.tie(nullptr);
    ios_base::sync_with_stdio(false);
	cout<<fixed<<setprecision(20);
    //int q; cin >> q;
	//while (q--)
		solve();
    return 0;
}

Measured memory_bytes: 3588
using System;
using System.IO;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Diagnostics.CodeAnalysis;

namespace AtCoder.Contest.B
{
	static class Program
	{
		public static void Main(string[] args)
		{
			var sw = new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false };
			Console.SetOut(sw);

			var cin = new Scanner();

			var t = new List<char>(cin.Next().ToCharArray());
			char now = 'D';
			for (int i = 0; i < t.Count; i++)
			{
				if (t[i] == '?')
				{
					if (i != 0 && t[i - 1] == 'P')
					{
						t[i] = 'D';
					}
					else if (i != t.Count - 1 && (t[i + 1] == 'D' || t[i + 1] == '?'))
					{
						t[i] = 'P';
					}
					else
					{
						t[i] = 'D';
					}
				}
			}
			Console.WriteLine(string.Concat(t));

			Console.Out.Flush();
		}
	}

	class Scanner
	{
		string[] s;
		int i;

		char[] cs = new char[] { ' ' };

		public Scanner()
		{
			s = new string[0];
			i = 0;
		}

		public string Next()
		{
			if (i < s.Length) return s[i++];
			string st = Console.ReadLine();
			while (st == "") st = Console.ReadLine();
			s = st.Split(cs, StringSplitOptions.RemoveEmptyEntries);
			if (s.Length == 0) return Next();
			i = 0;
			return s[i++];
		}

		public int NextInt()
		{
			return int.Parse(Next());
		}

		public int[] ArrayInt(int N, int add = 0)
		{
			int[] Array = new int[N];
			for (int i = 0; i < N; i++)
			{
				Array[i] = NextInt() + add;
			}
			return Array;
		}

		public long NextLong()
		{
			return long.Parse(Next());
		}

		public long[] ArrayLong(int N, long add = 0)
		{
			long[] Array = new long[N];
			for (int i = 0; i < N; i++)
			{
				Array[i] = NextLong() + add;
			}
			return Array;
		}

		public double NextDouble()
		{
			return double.Parse(Next());
		}

		public double[] ArrayDouble(int N, double add = 0)
		{
			double[] Array = new double[N];
			for (int i = 0; i < N; i++)
			{
				Array[i] = NextDouble() + add;
			}
			return Array;
		}
	}
}

Measured memory_bytes: 28672
#include<iostream>
#include<cstdio>
#include<vector>
#include<algorithm>
using namespace std;
const int N=10005;
int n;
int c[N];
int d[N],tot;
vector<int>G[N];
void dfs(int u,int father)
{
	for(int v:G[u])
	{
		if(v==father) continue;
		dfs(v,u);
	}
	d[u]=c[++tot];
	return;
}
int main()
{
	scanf("%d",&n);
	for(int i=1;i<n;i++)
	{
		int x,y;
		scanf("%d%d",&x,&y);
		G[x].push_back(y);
		G[y].push_back(x);
	}
	for(int i=1;i<=n;i++)
		scanf("%d",&c[i]);
	sort(c+1,c+n+1);
	dfs(1,0);
	int sum=0;
	for(int i=1;i<n;i++)
		sum+=c[i];
	printf("%d\n",sum);
	for(int i=1;i<=n;i++)
		printf("%d ",d[i]);
	return 0;
}

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

void solve() 
{
    int n;string s;cin>>n>>s;
    int count=0;
    REP(i,n){
        if(s[i]=='R')count++;
    }
    if(count>n/2)cout<<"Yes"<<endl;
    else cout<<"No"<<endl;
}

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

Measured memory_bytes: 256
def no2(tar,r,l):
  if tar > r and tar < l:
    return True
  elif tar > l and tar < r:
    return True
  else:
    return False

x = input()
x = input()
nums = x.split()
#print(nums)
n = 0

for i in range(1,len(nums)-1):
  #print(nums[i])
  if no2(int(nums[i]),int(nums[i-1]),int(nums[i+1])) == True:
    n += 1
    
print(n)

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

using namespace std;
typedef long long ll;

#define rep(i, N) for (int i = 0; i < (int)N; i++)
const ll MOD = pow(10,9)+7;
const ll LLINF = pow(2,61)-1;
const int INF = pow(2,30)-1;


int main() {
  int N; cin >> N;
  int p[N]; rep(i,N) { int tmp; cin >> tmp; tmp--; p[tmp]=i; }
  rep(i,N) cout << (i+1)*N << " "; cout << endl;
  rep(i,N) cout << (N-i)*N + p[i] << " "; cout << endl;
  return 0;
}

Measured memory_bytes: 640
#include <iostream>
#include <math.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <queue>
#include <stack>
#include <vector>
#include <algorithm>
#include <map>
#include <unordered_map>
#include <set>
#include <deque>
#include <utility>

int main(){
  long long A;
  long double B;
  scanf("%lld", &A);
  scanf("%Lf", &B);
  long long ans = A*(long long)(B*100+0.1)/(long long)100;
  std::cout << ans << std::endl;
  return 0;
}

Measured memory_bytes: 3200
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cmath>
#include <ctime>
#include <functional>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <tuple>
#include <vector>
using namespace std;

int main() {
    int n;
    string s;
    cin >> n >> s;
    int a[30000];
    for (int i = 0; i < n; i++) {
        a[i] = s[i] - '0';
    }

    int result = 0;
    //1文字目がp,2文字目がq,3文字目がrの暗証番号が、ラッキーナンバーに存在しうるか確認する。
    for (int p = 0; p < 10; p++) {
        int cp = 0;
        for (; cp < n; cp++) if (a[cp] == p) break; //これで、1文字目pが初めてラッキーナンバーに現れるインデックスcpを得られる。
        for (int q = 0; q < 10; q++) {
            int cq = cp+1;
            for (; cq < n; cq++) if (a[cq] == q) break; //これで、2文字目qが初めてラッキーナンバーに現れるインデックスcqを得られる。
            for (int r = 0; r < 10; r++) {
                int cr = cq + 1;
                for (; cr < n; cr++) {
                    if (a[cr] == r) {
                        result++;
                        break;
                    }
                }
            }
        }
    }
    cout << result << endl;

    return 0;
}



Measured memory_bytes: 384
#include <bits/stdc++.h>
typedef long long  ll;
#define press_F_to_pay_respect ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0)
#define forn for(int i=0;i<n;i++) 
#define form for(int j=0;j<n;j++) 
#define fora(i,a,b) for(int i = a; i < (b); i++)
#define pb push_back 
#define pob pop_back()
#define mp make_pair 
#define sc second 
#define f first 
#define kek cout<<endl; 
#define all(v) ((v).begin()), ((v).end()) 
#define pob pop_back() 
#define halt {cout<<"No"; return 0;}
const ll MOD = 1e9 + 7;
const int N = 200005;
const int INF = 1e8;
const ll MOD1=998244353;
using namespace std;

int main()
{
#if defined(_DEBUG)
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#endif
 press_F_to_pay_respect;
 // cout << fixed << setprecision(12) << ans;
int n=1e6;
vector<char> prime (n+1, true);
prime[0] = prime[1] = false;
for (int i=2; i<=n; ++i)
	if (prime[i])
		if (i * 1ll * i <= n)
			for (int j=i*i; j<=n; j+=i)
				prime[j] = false;
int k;
cin>>k;
for(int i=k;i<=1e6;i++)
{
          if(prime[i])
          {
                    cout<<i;
                    return 0;
          }
}
return 0;
 

}

Measured memory_bytes: 1280
using System;

class Program{
    static void Main(string[] args){
        
        int N = int.Parse(Console.ReadLine());
        string[] str = Console.ReadLine().Split(' ');
        int[] a = new int[N];
        int sum = 0;
        for(int i=0;i<N;i++){ 
            a[i] = int.Parse(str[i]);
            sum += a[i];
        }
        
        int c1 = sum/N;
        int c2 = c1 + 1;
        
        int ans1=0, ans2=0;
        for(int i=0;i<N;i++){
            ans1 += (a[i]-c1)*(a[i]-c1);
            ans2 += (a[i]-c2)*(a[i]-c2);
        }
        
        
        Console.WriteLine(Math.Min(ans1, ans2));
    }
}

Measured memory_bytes: 2648
#include <iostream>
using namespace std;
typedef long long ll;
template<class _T> _T MIN(_T p1,_T p2){return (p1<p2)?p1:p2;} 
int main(){
    ll q1, b, c1, c2, q2;
    while(cin >> q1 >> b >> c1 >> c2 >> q2){
        q2 = MIN(q2, b/c1);
        while(q2 > 0 && q2+(b-q2*c1)/c2 < q1) q2--;
        if(q2 == 0){
            cout << "NA" << endl;
        } else {
            cout << q2 << " " << (b-q2*c1)/c2 << endl;
        }
    }
    return 0;
}

Measured memory_bytes: 1156
#include <iostream>
#include<stdio.h>
#include<string>
#include<map>
#include<vector>
#include<stdlib.h>
typedef long long ll;
using namespace std;
#define INF 100000000000
#include<algorithm>
#include<string.h>
bool num[1000000];
int main(){
    int n;
    while(cin >> n){
        memset(num,true,sizeof(num));
        num[0] = num[1] = false;
        for(int i = 2;i<=n;i++){
            if(num[i] == true){
                for(int j = 2*i;j<=n;j+=i){
                    num[j] = false;
                }
            }

        }
        int ans = 0;
        for(int i =2;i<=n;i++){
            if(num[i]){ans++;}
        }
        cout<<ans<<endl;
    }

}

Measured memory_bytes: 4008
#include <algorithm>
#include <cmath>
#include <iomanip>
#include <iostream>
#include <queue>
#include <set>
#include <sstream>
#include <string>
#include <vector>

using namespace std;
using ll = long long;

// inf
constexpr ll infl = 10000000000000000LL;
constexpr int inf = 1000000000;

int main() {
    string S, T;
    cin >> S >> T;

    string ans = "UNRESTORABLE";
    for (int i = S.size() - 1; i >= 0; --i) {
        if ((i + T.size() - 1) < S.size()) {
            bool flag = true;
            for (int j = 0; j < T.size(); ++j) {
                if (S[i + j] != '?' && S[i + j] != T[j]) {
                    flag = false;
                    break;
                }
            }

            if (flag) {
                for (int j = 0; j < T.size(); ++j) {
                    S[i + j] = T[j];
                }

                for (int j = 0; j < S.size(); ++j) {
                    if (S[j] == '?')
                        S[j] = 'a';
                }

                ans = S;
                break;
            }
        }
    }

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

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

using namespace std;

int main() {
    int v[5], k;
    for (int i = 0; i < 5; ++i) {
        cin >> v[i];
    }
    cin >> k;
    if (v[4] - v[0] <= k) {
        cout << "Yay!" << endl;
    } else {
        cout << ":(" << endl;
    }
}


Measured memory_bytes: 256
pub fn read<T: std::str::FromStr>() -> T {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).ok();
    s.trim().parse().ok().unwrap()
}

pub fn read_vec<T: std::str::FromStr>() -> Vec<T> {
    read::<String>()
        .split_whitespace()
        .map(|e| e.parse().ok().unwrap())
        .collect()
}

pub fn read_vec2<T: std::str::FromStr>(n: usize) -> Vec<Vec<T>> {
    (0..n).map(|_| read_vec()).collect()
}

pub fn read_col<T: std::str::FromStr>(n: usize) -> Vec<T> {
    (0..n).map(|_| read()).collect()
}

fn main() {
    let n: usize = read();
    let av: Vec<u32> = read_vec();

    let mut b = true;

    for a in av {
        if a % 2 == 0 {
            if !(a % 3 == 0 || a % 5 == 0) {
                b = false;
            }
        }
    }

    if b {
        println!("APPROVED");
    } else {
        println!("DENIED");
    }
}


Measured memory_bytes: 4352
#include <iostream>
#include <vector>
#include <algorithm>

using std::cin;
using std::cout;
using std::endl;

using std::string;
using std::pair;

using std::vector;
using std::sort;
using std::lower_bound;
using std::upper_bound;
using std::find_if;
using std::copy;
using std::copy_if;

int main(){
    int h,w;
    cin >> h;
    cin >> w;

    int t[h+2][w+2];
    for(int i=0;i<w+2;i++){
        t[0][i]=0;
        t[h+1][i]=0;
    }
    for(int i=1;i<=h;i++){
        string _s;
        cin >> _s;
        t[i][0]=0;
        for(int j=1;j<=w;j++){
            if(_s[j-1]=='#'){
                t[i][j]=1;
            }
            else{
                t[i][j]=0;
            }
        }
        t[i][w+1]=0;
    }

    for(int i=1;i<=h;i++){
        for(int j=1;j<=w;j++){
            if(t[i][j]==1){
                cout << '#';
            }
            else{
                int ans=0;
                for(int x=i-1;x<=i+1;x++){
                    for(int y=j-1;y<=j+1;y++){
                        ans+=t[x][y];
                    }
                }
                cout << ans;
            }
        }
        cout << endl;
    }
    return 0;
}



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

int main(){
  string s;
  int k;
  cin >> s >> k;
  int n = s.size();
  
  set<string> st;
  rep(i,n){
    for(int j=1;j<=k;j++){
      string t=s.substr(i,j);
      st.insert(t);
    }
  }
  auto itr = st.begin();
  for(int i = 0;i<k-1; ++i) ++itr;
  cout << *itr << endl;
  return 0;
  
}

Measured memory_bytes: 1664
import java.util.Scanner;

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


Measured memory_bytes: 21716
"""
ある街に、N 人のすぬけ君(すぬけ君 1 、すぬけ君 2 、 ...、 すぬけ君 N)が住んでいます。
この街には、 K種類のお菓子(お菓子 1 、 お菓子 2 、....、お菓子 K )が売られています。
お菓子 i を持っているのは、すぬけ君 Ai,1,Ai,2,⋯,Ai,di の計 di人です。
高橋君は今からこの街を回り、お菓子を 1つも持っていないすぬけ君にいたずらをします。
このとき、何人のすぬけ君がいたずらを受けるでしょうか。
制約

    入力は全て整数
    1≤N≤100

1≤K≤100
1≤di≤N
1≤Ai,1<⋯<Ai,di≤N
"""
n,k=map(int,input().split())
a=[[] for ii in range(k)]
d=[0]*k
r=[1]*n
for ii in range(k):
  d[ii]=int(input())
  a[ii]=[]*d[ii]
  a[ii][:]=map(int,input().split())
  for jj in range(d[ii]):
    r[a[ii][jj]-1]=0
print(sum(r))

Measured memory_bytes: 9204
#include <iostream>
#include <vector>
#include <string>
#include <cstring>
#include <algorithm>
#include <set>

#define REP(i,k,n) for(int i=k;i<n;i++)
#define rep(i,n) for(int i=0;i<n;i++)
#define INF 1<<30

using namespace std;
typedef long long ll;

int main() {
    int n,m;
    while(cin >> n >> m) {
        if(n == 0 && m == 0) break;
        int N = max(n,m);

        vector<int> a(N),b(N);
        rep(i,n) cin >> a[i];
        rep(i,m) cin >> b[i];
        
        int ac[30],bc[30];
        memset(ac,0,sizeof(ac));
        memset(bc,0,sizeof(bc));
        
        set<int> st;
        rep(i,N) {
            ac[a[i]]++;
            bc[b[i]]++;

            st.insert(a[i]);
            st.insert(b[i]);
        }

        int ans = 0;
        set<int>::iterator ite;
        for(ite = st.begin();ite != st.end();ite++) {
            int i = *ite;
            int cnt = min(ac[i],bc[i]);
            int diff = max(ac[i],bc[i]) - cnt;
            ans += cnt * i;
            ans += diff * i;
        }

        cout << ans << endl;
    }

    return 0;
}

Measured memory_bytes: 1196
#include <cstdio>
#include <cstring>
#include <cmath>
#include <vector>
#include <list>
#include <string>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <algorithm>
#include <iostream>
#include <sstream>
using namespace std;

typedef long long i64;
const int inf = (int)1.05e9;


struct UnionFind {

	vector<int> par;

	void init(int size)
	{
		par.resize(size);
		for(int i = 0; i < size; ++i)
			par[i] = i;
	}

	int root(int x)
	{
		if(par[x] == x)
			return x;
		return par[x] = root(par[x]);
	}

	bool same(int a, int b)
	{
		return root(a) == root(b);
	}

	void unite(int a, int b)
	{
		a = root(a);
		b = root(b);
		par[a] = b;
	}
};


int main()
{
	int n, q;
	UnionFind uf;
	priority_queue<pair<i64,pair<int,int>>> pq;

	scanf("%d%d", &n, &q);
	uf.init(n);

	for(int i = 0; i < q; ++i) {
		int a, b, c;
		scanf("%d%d%d", &a, &b, &c);
		pq.push({-((i64)c), {a, b}});
		pq.push({-((i64)(c + 1)), {(a + 1) % n, b}});
	}

	i64 ans = 0;

	while(!pq.empty()) {

		auto candy = pq.top();
		pq.pop();
		i64 cost = -candy.first;
		int a = candy.second.first;
		int b = candy.second.second;

		if(uf.same(a, b))
			continue;
		uf.unite(a, b);
		//printf("%lld: %d-%d\n", cost, a, b);

		ans += cost;
		pq.push({-((i64)(cost + 2)), {(a + 1) % n, (b + 1) % n}});
	}

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

	return 0;
}


Measured memory_bytes: 9324
#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
using namespace std;
int n,k,a,maxx,fi,pre,now;
int main(){
	scanf("%d%d",&k,&n);
	for(int i=0;i<n;i++){
		scanf("%d",&a);
		pre=now;
		now=a;
		if(i==0) fi=a;
		if(i>=1) maxx=max(maxx,now-pre);
	}
	maxx=max(maxx,k-now+fi);
	printf("%d\n",k-maxx);
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
long long X,Y,Z,K;

int main() {  
  cin >> X >> Y >> Z >> K;
  vector<long long> A(X),B(Y),C(Z);
  for(int i=0;i<X;i++)cin >> A[i];
  for(int i=0;i<Y;i++)cin >> B[i];
  for(int i=0;i<Z;i++)cin >> C[i];
  vector<long long> AB;
  for(int i=0;i<X;i++){
    for(int j=0;j<Y;j++){AB.push_back(A[i]+B[j]);}
  }
  sort(AB.begin(),AB.end());
  reverse(AB.begin(),AB.end());
  vector<long long> ABC;
  for(int i=0;i<min(K,X*Y);i++){
    for(int j=0;j<Z;j++){ABC.push_back(AB[i]+C[j]);}
  }
  sort(ABC.begin(),ABC.end());
  reverse(ABC.begin(),ABC.end());
  for(int i=0;i<K;i++){cout << ABC[i] << endl;}
}

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

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

  vector<int> a(N);
  vector<bool> pushed(N);
  for (int i = 0; i < N; i++)
  {
    cin >> a.at(i);
  }
  int i = 0;
  int result = 1;
  while (!pushed.at(i) && a.at(i) != 2)
  {
    pushed.at(i) = true;
    i = a.at(i) - 1;
    result++;
  }
  if (a.at(i) != 2)
  {
    cout << -1 <<endl;
  }
  else
  {
    cout << result << endl;
  }
}

Measured memory_bytes: 640
import math

while True:
    n = int(input());
    if n == 0:
        break;
        
    A = list(map(int, input().split()));


    h = sum(A) / len(A);
    k = 0;
    for j in range(0,n):
        k += (A[j] - h)**2;
    print(math.sqrt(k/n));




Measured memory_bytes: 5696
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		String s = sc.next();
		sc.close();
		int size = s.length();
		int center = (size + 1) / 2;
		String head = s.substring(0, center - 1);
		String tail = s.substring(center);

		boolean answer = isKaibun(s) && isKaibun(head) && isKaibun(tail);

		printBool(answer);
	}

	public static boolean isKaibun(String s) {
		int size = s.length();
		int center = (size + 1) / 2;
		for (int i = 0; i < center; i++) {
			char head = s.charAt(i);
			char tail = s.charAt(s.length() - 1 - i);
			if (head != tail) {
				return false;
			}
		}
		return true;
	}

	public static void printBool(boolean bool) {
		print(bool ? "Yes" : "No");
	}

	public static void print(Object obj) {
		System.out.println(obj);
	}

}


Measured memory_bytes: 23252
using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.Text;

class TEST{
	static void Main(){
		Sol mySol =new Sol();
		mySol.Solve();
	}
}

class Sol{
	public void Solve(){
		
		HashSet<char> H = new HashSet<char>();
		foreach(var c in S) if(c != ' ') H.Add(c);
		Console.WriteLine(H.Count == 4 ? "Four" : "Three");
		
		
	}
	int N;
	String S;
	public Sol(){
		N = ri();
		S = rs();
	}

	static String rs(){return Console.ReadLine();}
	static int ri(){return int.Parse(Console.ReadLine());}
	static long rl(){return long.Parse(Console.ReadLine());}
	static double rd(){return double.Parse(Console.ReadLine());}
	static String[] rsa(char sep=' '){return Console.ReadLine().Split(sep);}
	static int[] ria(char sep=' '){return Array.ConvertAll(Console.ReadLine().Split(sep),e=>int.Parse(e));}
	static long[] rla(char sep=' '){return Array.ConvertAll(Console.ReadLine().Split(sep),e=>long.Parse(e));}
	static double[] rda(char sep=' '){return Array.ConvertAll(Console.ReadLine().Split(sep),e=>double.Parse(e));}
}


Measured memory_bytes: 13396
#include<queue>
#include<cstdio>
#include<iostream>
using namespace std;


int main()
{
	int n, m;
	cin >> n >> m;

	int a[n][m];
	int b[m];
	for (int i = 0; i < n; i++)
	{
		for (int j = 0; j < m; j++)
		{
			cin >> a[i][j];
		}
	}

	for (int i = 0; i < m; i++)
	{
		cin >> b[i];
	}

	for (int i = 0; i < n; i++)
	{
		int sum = 0;
		for (int j = 0; j < m; j++)
		{
			sum += a[i][j] * b[j];
		}
		cout << sum << '\n';
	}
	
}

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

int main(){
  int N,K,num=1;
  cin >> N >> K;
  
  for(int i=0;i<N;i++){
    if(num*2 <= num+K){
      num *=2;
    }else{
      num +=K;
    }
  }
  
  cout << num << endl;
}
    


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

long long gcd(long long a, long long b) {
	if(b==0) return a;
	if(a < b) swap(a, b);
	return gcd(b, a % b);
}

int main() {
	int N;
	cin >> N;
	long long ans = 1;
	for(int i=0; i<N; ++i) {
		long long T;
		cin >> T;
		ans = ans / gcd(ans,T) * T;
	}
	cout << ans << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define int long long int
#define L_T_S_K ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);  
const int mod = 1e9 + 7;
const int N = 1e3 + 9;

int32_t main(){
 L_T_S_K;
 int n; cin >> n;
 string s;
 cin >> s;
  int cnt = 0;
  for(int i = 0 ; i < s.length() - 2;i++){
    if(s[i] == 'A' and s[i + 1] == 'B' and s[i + 2] == 'C') cnt++; 
  }
  cout << cnt << "\n";
  return 0;
}

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

using namespace std;
typedef long long ll;
typedef pair<ll, ll> p_ll;

template<class T>
void debug(T itr1, T itr2) { auto now = itr1; while(now<itr2) { cout << *now << " "; now++; } cout << endl; }
#define repr(i,from,to) for (int i=(int)from; i<(int)to; i++)
#define all(vec) vec.begin(), vec.end()
#define rep(i,N) repr(i,0,N)
#define per(i,N) for (int i=(int)N-1; i>=0; i--)

const ll MOD = pow(10,9)+7;
const ll LLINF = pow(2,61)-1;
const int INF = pow(2,30)-1;

vector<ll> fac;
void c_fac(int x=pow(10,6)+10) { fac.resize(x,true); rep(i,x) fac[i] = i ? (fac[i-1]*i)%MOD : 1; }
ll inv(ll a, ll m=MOD) { ll b = m, x = 1, y = 0; while (b!=0) { int d = a/b; a -= b*d; swap(a,b); x -= y*d; swap(x,y); } return (x+m)%m; }
ll nck(ll n, ll k) { return fac[n]*inv(fac[k]*fac[n-k]%MOD)%MOD; }
ll gcd(ll a, ll b) { if (a<b) swap(a,b); return b==0 ? a : gcd(b, a%b); }
ll lcm(ll a, ll b) { return a/gcd(a,b)*b; }

int N;
vector<int> p3, result;

void dfs(int n, int count, string dance) {
  if (count==N) return;
  rep(i,3) {
    int now = n + p3[count]*i, pos = i;
    string d;
    rep(j, dance.size()) {
      if (dance[j]=='R') { 
        pos = (pos+1)%3; 
        if (pos==0) d += 'R'; 
      }
      if (dance[j]=='S') { 
        pos = (3-pos)%3;
        if (d.back()=='S') d.pop_back();
        else d += 'S';
      }
    }
    for (int j=now; j<p3[N]; j+=p3[count]*3) result[j] += pos*p3[count];
    // cout << now << "->" << pos << " " << d << endl;
    dfs(now,count+1,d);
  }
}

int main() {
  cin >> N;
  string T; cin >> T;

  p3.resize(N+1); rep(i,N+1) p3[i] = i==0 ? 1 : p3[i-1]*3;
  result.resize(p3[N]);


  dfs(0,0,T);
  debug(all(result));
  return 0;
}

Measured memory_bytes: 6532
#include<stdio.h>
#include<string.h>
int main()
{
char a[100];
gets(a);
int n=strlen(a),x=0,y=0,z=0;
for(int i=0;i<n;i++)
{
if(a[i]!=a[n-i-1]){
x=1;
break;
}
}
for(int i=0;i<(n-1)/2;i++)
{
if(a[i]!=a[(n-1)/2 -i-1]){
y=1;
break;
}
}
for(int i=n/2 +1;i<n;i++)
{
if(a[i]!=a[n-i+ n/2]){
z=1;
break;
}
}
if(x==0&&y==0&&z==0)
printf("Yes");
else
printf("No");
}



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

using namespace std;

int main()
{
  int n, ans;
  double t, a;
  scanf("%d %lf %lf", &n, &t, &a);

  double x[n];
  for (int i = 0; i < n; i++)
  {
    scanf("%lf", &x[i]);
  }

  double ave, ans_ave = 1000000;

  for (int i = 0; i < n; i++)
  {
    ave = t - x[i] * 0.006;

    if (fabs(a - ave) < ans_ave)
    {
      ans_ave = fabs(a - ave);
      ans = i + 1;
    }
  }

  printf("%d", ans);
}

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

#define _overload(_1,_2,_3,name,...) name
#define _rep(i,n) _range(i,0,n)
#define _range(i,a,b) for(int i=int(a);i<int(b);++i)
#define rep(...) _overload(__VA_ARGS__,_range,_rep,)(__VA_ARGS__)

#define _rrep(i,n) _rrange(i,n,0)
#define _rrange(i,a,b) for(int i=int(a)-1;i>=int(b);--i)
#define rrep(...) _overload(__VA_ARGS__,_rrange,_rrep,)(__VA_ARGS__)

#define _all(arg) begin(arg),end(arg)
#define uniq(arg) sort(_all(arg)),(arg).erase(unique(_all(arg)),end(arg))
#define getidx(ary,key) lower_bound(_all(ary),key)-begin(ary)
#define clr(a,b) memset((a),(b),sizeof(a))
#define bit(n) (1LL<<(n))
#define popcount(n) (__builtin_popcountll(n))

using namespace std;

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

using ll=long long;
using R=long double;
const R EPS=1e-9L; // [-1000,1000]->EPS=1e-8 [-10000,10000]->EPS=1e-7
inline int sgn(const R& r){return(r > EPS)-(r < -EPS);}
inline R sq(R x){return sqrt(max(x,0.0L));}

template<typename T> vector<T> make_vector(size_t sz){
	return vector<T>(sz);
}

template<typename T,typename... Ts> 
auto make_vector(size_t sz, Ts... ts){
	return vector<decltype(make_vector<T>(ts...))>(sz, make_vector<T>(ts...));
}

template<typename T,typename U,typename... V> 
typename enable_if<is_same<T, U>::value!=0>::type 
fill_value(U &u, const V... v){
	u=U(v...);
}

template<typename T,typename U,typename... V>
typename enable_if<is_same<T, U>::value==0>::type
fill_value(U &u, const V... v){
	for(auto &e:u){
		fill_value<T>(e,v...);
	}
}

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

const pid_t pid = getpid();
// Problem Specific Parameter:

char board[1010][1010];
int dist[1010][1010];
const int inf = 1 << 25;
queue<int> que;

int main(void){
	int h, w;
	cin >> h >> w;
	rep(i, h) rep(j, w) cin >> board[i][j];

	rep(i, h) rep(j, w){
		dist[i][j] = inf;
		if(board[i][j] == '#'){
			que.push(i);
			que.push(j);
			dist[i][j] = 0;
		}
	}

	while(!que.empty()){
		const int ci = que.front(); que.pop();
		const int cj = que.front(); que.pop();
		rep(dir, 4){
			const int ni = ci + dy[dir];
			const int nj = cj + dx[dir];
			if(ni < 0 or h <= ni) continue;
			if(nj < 0 or w <= nj) continue;
			if(chmin(dist[ni][nj], dist[ci][cj] + 1)){
				que.push(ni);
				que.push(nj);
			}
		}
	}

	int ans = 0;
	rep(i, h) rep(j, w) chmax(ans, dist[i][j]);
	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 13456
#include <stdio.h>
#include <string.h>
	int main(){
	int k;
	char s[100];
	
	scanf("%d",&k);
	scanf("%s",&s);
	int len = strlen(s);
	
	if(len <= k){
		printf("%s",s);
	}
	else{
		for( int i=0 ; i<k ; i++){
			printf("%c",s[i]);
		}
		puts("...");
	}
	return 0;
	}

Measured memory_bytes: 1684