akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
using namespace std;
#define lint long long
#define inf 100000000000000000
#define mod 1000000007
#define MAX 1000005
#define pb push_back
#define vit vector<int>::iterator
typedef pair<int,int> pii;
map<int,int>M;
vector<int> V[MAX];
int main()
{
    ios::sync_with_stdio(0);
    cin.tie(0);
    lint n,p1,p2,sum=0;
    string S;
    cin>>n;
    cin>>S;
    p1=0;
    while(p1<n && S[p1]=='R') p1++;
    p2=n-1;
    while(p2>=0 && S[p2]=='W') p2--;
    while(p1<p2){
        sum++;
        swap(S[p1],S[p2]);
        while(p1<n && S[p1]=='R') p1++;
        while(p2>=0 && S[p2]=='W') p2--;
    }
    cout<<sum;
    return 0;
}


Measured memory_bytes: 27212
#include<iostream>
#include<algorithm>
#include<vector>
#include<map>
#include<string>
#include<set>

using namespace std;

int main(void){

  int n;
  cin >> n;
  set<string>S;

  for(int i=0;i<n;i++){
    string in;
    cin >> in;
    S.insert(in);
  }

  bool now=false;
  cin >> n;
  for(int i=0;i<n;i++){
    string in;
    cin >> in;
    if(!S.count(in))cout << "Unknown " << in << endl;
    else if(!now)cout << "Opened by " << in << endl,now=!now;
    else if(now)cout << "Closed by " << in << endl,now=!now;
  }

  return 0;
}

Measured memory_bytes: 1232
<?php
//$N = (int)trim(fgets(STDIN));
//$S = trim(fgets(STDIN));
list($N,$K) = array_map('intval',explode(" ",trim(fgets(STDIN))));
$A = array_map('intval',explode(" ",trim(fgets(STDIN))));

$rw[0]=0;
for($i=0;$i<$N;$i++) {
  $rw[$i+1]=$rw[$i]+$A[$i];
}
//足してもかけても大小はかわらない？
for($i=0;$i<$N-$K;$i++) {
  if ($rw[$K+$i]-$rw[$i]<$rw[$K+$i+1]-$rw[$i+1]) {
    printf("Yes\n");
  }
  else {
    printf("No\n");
  }
}

Measured memory_bytes: 39264
#!/usr/bin/env python3



# Generated by 1.1.4 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    h, w = map(int, input().split())
    C = []
    for i in range(h):
        C.append(input())
    
    for i in range(2 * h):
        j = i // 2
        print(C[j])

if __name__ == '__main__':
    main()


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

int main(){
    long int H,W;
    while(H!=0&&W!=0){
            cin>>H>>W;
        for(int i=0; i<H; i++){
            for(int j=0; j<W; j++){
                cout<<'#';
            }
        cout<<endl;
        }
        if(H!=0&&W!=0){
            cout <<endl;
        }
    }
    return 0;
}


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

using namespace std;

int dfs(int x, int n, int s)
{
    if (n == 0) {
        return (s == 0);
    }
    if (x == 10) return 0;
            
    int res = 0;
    for (int i = x; i <= 9; i++) {
        res += dfs(i + 1, n - 1, s - i);
    }
    return res;
}

int main()
{
    int n, s;
    while (cin >> n >> s, n) {
        cout << dfs(0, n, s) << endl;
    }
    return 0;
}

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

ll S(ll x)
{
    ll ret=0;
    while(x) ret+=x%10,x/=10;
    return ret;
}

int main()
{
    ll k; scanf("%lld",&k);
    st.clear();
    for(int i=1;i<=9;i++) st.insert(i);
    for(int i=1;i<=9;i++) st.insert(i*10+9);
    ll now=99,base=100;
    while(now<=(ll)1e15)
    {
        while(S(now+base)*base>=now+base) 
        {
            now+=base;
            st.insert(now);
        }
        base*=10;
    }
    while(k--)
    {
        printf("%lld\n",*st.begin());
        st.erase(st.begin());
    }
}

Measured memory_bytes: 3752
// Probably getting a WA/Tle
// Still trying
// Apna time ayega

#include<bits/stdc++.h>
#define ll long long int
#define FastRead ios_base::sync_with_stdio(false);cin.tie(0),cout.tie(0);
using namespace std;
int main()
{
    ll n,l,a,b,c,m,k,i,j,s,sum=0;
    cin>>a;
    for(i=1;i<=a;i++){
        for(j=1;j<=a;j++){
            s=__gcd(i,j);
            for(k=1;k<=a;k++){
                sum+=__gcd(s,k);
            }
        }
    }
    cout<<sum<<endl;


    return 0;
}


Measured memory_bytes: 3652
#include <iostream>
#include <algorithm>
#include <numeric>

using namespace std;
const int INF = 1e9;
const long long LLINF = 1e18;

int main(void)
{
	long long N, W;
	cin >> N >> W;
	int w[N], v[N];
	for (int i = 0; i < N; i++) {
		cin >> w[i] >> v[i];
	}

	long long max_sum_v = accumulate(&v[0], &v[N], 0);
	long long d[N][max_sum_v+1];
	for (int i = 0; i < N; i++) {
		for (int j = 0; j < max_sum_v+1; j++) {
			d[i][j] = LLINF;
		}
	}
	d[0][0] = 0;
	d[0][v[0]] = w[0];
	for (int i = 1; i < N; i++) {
		for (int j = 0; j < max_sum_v+1; j++) {
			if (j-v[i] < 0)
				d[i][j] = d[i-1][j];
			else
				d[i][j] = min(d[i-1][j-v[i]] + w[i],
					d[i-1][j]);
			if (d[i][j] >= LLINF)
				d[i][j] = LLINF;

		}
	}



	for (int j = max_sum_v; j >= 0; j--) {
		if (d[N-1][j] <= W) {
			cout << j << endl;
			break;
		}
	}

	return 0;
}

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

using namespace std;

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

struct UnionFind {
	vector<int> data;

	UnionFind(int size) : data(size, -1) { }

	bool union_set(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 find_set(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)];
	}
};

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

	UnionFind uf(n);

	rep(i, q) {
		int c, x, y;
		cin >> c >> x >> y;

		if (c == 0) {
			uf.union_set(x, y);
		} else {
			cout << uf.find_set(x, y) << endl;
		}
	}
}

Measured memory_bytes: 1236
#include <float.h>
#include <limits.h>
#include <math.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <time.h>

// 内部変数
static FILE *szpFpI;											// 入力

// 内部変数 - テスト用
#ifdef D_TEST
	static int siRes;
	static FILE *szpFpA;
	static int siTNo;
#endif

// １行出力
int
fOutLine(
	char *pcpLine				// <I> １行
)
{
	char lc1Buf[1024];

#ifdef D_TEST
	fgets(lc1Buf, sizeof(lc1Buf), szpFpA);
	if (strcmp(lc1Buf, pcpLine)) {
		siRes = -1;
	}
#else
	printf("%s", pcpLine);
#endif

	return 0;
}

// 実行メイン
long long
fMain(
)
{
	char lc1Buf[1024];

	// N - 取得
	long long llN;
	fgets(lc1Buf, sizeof(lc1Buf), szpFpI);
	sscanf(lc1Buf, "%lld", &llN);

	// 最大値 - 取得
	long long llMax = (llN - 1) * llN / 2;

	return llMax;
}

// １回実行
int
fOne(
)
{
	long long llRet;
	char lc1Buf[1024];

	// 入力 - セット
#ifdef D_TEST
	sprintf(lc1Buf, ".\\Test\\T%d.txt", siTNo);
	szpFpI = fopen(lc1Buf, "r");
	sprintf(lc1Buf, ".\\Test\\A%d.txt", siTNo);
	szpFpA = fopen(lc1Buf, "r");
	siRes = 0;
#else
	szpFpI = stdin;
#endif

	// 実行メイン
	llRet = fMain();

	// １行出力
	sprintf(lc1Buf, "%lld\n", llRet);
	fOutLine(lc1Buf);

	// 残データ有無
#ifdef D_TEST
	lc1Buf[0] = '\0';
	fgets(lc1Buf, sizeof(lc1Buf), szpFpA);
	if (strcmp(lc1Buf, "")) {
		siRes = -1;
	}
#endif

	// テストファイルクローズ
#ifdef D_TEST
	fclose(szpFpI);
	fclose(szpFpA);
#endif

	// テスト結果
#ifdef D_TEST
	if (siRes == 0) {
		printf("OK %d\n", siTNo);
	}
	else {
		printf("NG %d\n", siTNo);
	}
#endif

	return 0;
}

// プログラム開始
int
main()
{

#ifdef D_TEST
	int i;
	for (i = D_TEST_SNO; i <= D_TEST_ENO; i++) {
		siTNo = i;
		fOne();
	}
#else
	fOne();
#endif

	return 0;
}



Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
#define rep(i,m,n) for(int i=m;i<n;i++)
const ll mod=1e9+7;

ll power(ll x,ll n){
  if(n==0) return 1;
  ll res=power(x*x%mod,n/2);
  if(n&1) res=res*x%mod;
  return res;
}

int main(){
  int n;
  cin>>n;
  int x[n],y[n];
  rep(i,0,n) cin>>x[i]>>y[i];
  int z[n],w[n];
  rep(i,0,n){
    z[i]=x[i]+y[i];
    w[i]=x[i]-y[i];
  }
  sort(z,z+n);
  sort(w,w+n);
  cout<<max(z[n-1]-z[0],w[n-1]-w[0])<<endl;
}

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


signed main(){
    bool Ans[104][104];
    int A,B;
    cin >> A >> B;
    REP(i,100){
        REP(j,50){
            Ans[i][j]=1;
        }
    }
    REP(i,100){
        REP(j,50){
            Ans[i][j+50]=0;
        }
    }
    REP(i,B-1){
        Ans[(i%25)*2][(i/25)*2]=0;
    }
    REP(i,A-1){
        Ans[(i%25)*2][(i/25)*2+51]=1;
    }
    cout << "100 100" << endl;
    REP(i,100){
        REP(j,100){
            if(Ans[j][i]){
                cout << '.';
            }else{
                cout << '#';
            }
        }cout << endl;
    }
    return 0;
}


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

int main(){
        double n;
        while (cin >> n && n != 0){
                int ans = 0;
                double wa = 0;
                vector<double> a(n);
                for (int i = 0; i < n; i++){
                        cin >> a[i];
                        wa += a[i];
                }
                double avg = wa / n;
                for (int i = 0; i < n; i++){
                        if (avg >= a[i]) ans++;
                }
                cout << ans << endl;
        }
        return 0;
}



Measured memory_bytes: 3288
#include<stdio.h>
#include<iostream>
#include<string>
using namespace std;
int main() {
	char M[200020], R[200010];
	int count = 0,i=0;
	cin >> M >> R;
	//cout << M << ' ' << R;
	while (M[i]!=NULL) {
		if (M[i] != R[i]) {
			count++;
		}
		i++;
		
	}
	cout << count << endl;


}

Measured memory_bytes: 3552
S = list(input())
flg = True
for i in range(len(S)):
    if i%2==0:
        if S[i] not in {"R","U","D"}:
            flg = False
            break
    else:
        if S[i] not in {"L","U","D"}:
            flg = False
            break

print("Yes" if flg else "No")

Measured memory_bytes: 3060
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
class Program
{
    static void Main(string[] args)
    {
            // 準備
            List<ClsJew> lstJew = new List<ClsJew>();
            List<ClsJew> lstJe2 = new List<ClsJew>();

            // 入力
            string[] sS = System.Console.ReadLine().Trim().Split(' ');
            int iN = int.Parse(sS[0]);
            string[] s2 = System.Console.ReadLine().Trim().Split(' ');
            string[] s3 = System.Console.ReadLine().Trim().Split(' ');
            for (int i = 0; i < s2.Length; i++)
            {
                ClsJew oneUsr = new ClsJew();
                oneUsr.iV = int.Parse(s2[i]);
                oneUsr.iC = int.Parse(s3[i]);
                oneUsr.iP = (decimal)oneUsr.iV / (decimal)oneUsr.iC;
                lstJew.Add(oneUsr);
                if (oneUsr.iP > 1) { lstJe2.Add(oneUsr); }                  // 価格対価が1以上のみ
            }

            System.Diagnostics.Stopwatch sw = new System.Diagnostics.Stopwatch();
            sw.Start();

            // 解析
            int iV = lstJe2.Sum(x => x.iV);
            int iC = lstJe2.Sum(x => x.iC);
            int iOut = iV - iC;

            // 出力
            System.Console.WriteLine("{0}", iOut.ToString());

            sw.Stop();
#if DEBUG
            Console.WriteLine();
            Console.WriteLine("{0}", sw.Elapsed.ToString());
            Console.WriteLine("続行するには何かキーを押してください．．．");
            Console.ReadKey();
#endif
    }

        private class ClsJew
        {
            public int     iC { get; set; } = 0;
            public int     iV { get; set; } = 0;
            public decimal iP { get; set; } = 0;
        }

}


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

#define int long long

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

int n, m;
int x[100000], y[100000];
int mod = 1e9 + 7;

signed main() {
    cin >> n >> m;
    for (int i = 0; i < n; i++) {
        cin >> x[i];
    }
    for (int i = 0; i < m; i++) {
        cin >> y[i];
    }
    int x_sum = 0, y_sum = 0;
    for (int i = 1; i < n; i++) {
        x_sum = (x_sum + (x[i] - x[i - 1]) * i * (n - i) % mod) % mod;
    }
    for (int i = 1; i < m; i++) {
        y_sum = (y_sum + (y[i] - y[i - 1]) * i * (m - i) % mod) % mod;
    }
    cout << x_sum * y_sum % mod << endl;
    return 0;
}


Measured memory_bytes: 1792
import sys
sys.setrecursionlimit(1 << 25)
read = sys.stdin.readline


def read_ints():
    return list(map(int, read().split()))


def read_a_int():
    return int(read())


def read_tuple(H):
    '''
    H is number of rows
    '''
    ret = []
    for _ in range(H):
        ret.append(tuple(map(int, read().split())))
    return ret


def read_col(H, n_cols):
    '''
    H is number of rows
    n_cols is number of cols

    A列、B列が与えられるようなとき
    '''
    ret = [[] for _ in range(n_cols)]
    for _ in range(H):
        tmp = list(map(int, read().split()))
        for col in range(n_cols):
            ret[col].append(tmp[col])

    return ret


def read_matrix(H):
    '''
    H is number of rows
    '''
    ret = []
    for _ in range(H):
        ret.append(list(map(int, read().split())))
    return ret
    # return [list(map(int, read().split())) for _ in range(H)] # 内包表記はpypyでは遅いため


def read_map(H):
    '''
    H is number of rows
    文字列で与えられた盤面を読み取る用
    '''
    return [read()[:-1] for _ in range(H)]


def read_map_as_int(H):
    '''
    #→1,.→0として読み込む
    '''
    ret = []
    for _ in range(H):
        ret.append([1 if s == '#' else 0 for s in read()[:-1]])
        # 内包表記はpypyでは若干遅いことに注意
        # #numpy使うだろうからこれを残しておくけど
    return ret


# default import
from collections import defaultdict, Counter, deque
from operator import itemgetter
from itertools import product, permutations, combinations
from fractions import gcd


def lcm(a, b):
    # 最小公約数
    g = gcd(a, b)
    return a * b // g


A, B, M = read_ints()
a = read_ints()
b = read_ints()

ans = 10 ** 9
for _ in range(M):
    x, y, c = read_ints()
    nedan = a[x - 1] + b[y - 1] - c
    ans = min(ans, nedan)

print(min(ans, min(a) + min(b)))


Measured memory_bytes: 20632
#include<bits/stdc++.h>
using namespace std;
#define ll long long int 

int main()
{
    priority_queue<ll>xa;
    priority_queue<ll>yb;
    priority_queue<ll>cc;
    ll x, y, a, b, c;
    cin>>x>>y>>a>>b>>c;
    ll val;
    for(int i=0;i<a;i++)
    {
        cin>>val;
        xa.push(val);
    }
    for(int i=0;i<b;i++)
    {
        cin>>val;
        yb.push(val);
    }
    for(int i=0;i<c;i++)
    {
        cin>>val;
        cc.push(val);
    }
    ll ans=0;
    ll n=x+y;
    while(x--)
    {
        cc.push(xa.top());
        xa.pop();
    }
    while(y--)
    {
       cc.push(yb.top());
       yb.pop();
    }
    while(n--)
    {
        ans+=cc.top();
        cc.pop();
    }
    cout<<ans<<endl;

    return 0;
}

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

#define fi first
#define se second
#define pb push_back
#define rep(i,n) for(int i=0; i<(int)(n); i++)

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; }

int main() {
	int n;
	cin >> n;
	vector<int> v(n);
	vector<int> p(n), q(n);
	rep(i,n) v[i] = i+1;
	rep(i,n) cin >> p[i];
	rep(i,n) cin >> q[i];
	int countp=1, countq=1;
	do{
		if (v != p) {
			countp++;
		}
		else break;
	}
	while(next_permutation(v.begin(), v.end())); 
	sort(v.begin(), v.end());
	do{
		if(v != q) {
			countq++;
		}
		else break;
	}
	while(next_permutation(v.begin(), v.end())); 
	//cout << countp << " " << countq << endl;
	cout << abs(countp-countq) << endl;
	
  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <string>
#include <map>
#include <math.h>
using namespace std;

#define ll long long

int main(){
    int n,p;
    cin >> n;
    for(int i = 0; i < 3; i++){
        p = 1;
        for(int j = 0; j < i; j++)p *= 10;
        if((n%(p*10))/p == 9)n -= 8*p;
        else n += 8*p;
    }
    cout << n << endl;
    return 0;
}

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

typedef long long ll;
const int maxn = 200005;
const ll mod = 1e9+7;
const int MAX_int = 1e9;
const double eps = 1e-9;
int used[105];
int nice[105][105];
int girl[105];

int n;
struct P
{
    int a,b;
} p1[105],p2[105];

int find1(int x)
{
    int j;
    for (j=0; j<n; j++)   //扫描每个妹子
    {
        if (nice[x][j]==1 && used[j]==0)
            //如果有暧昧并且还没有标记过(这里标记的意思是这次查找曾试图改变过该妹子的归属问题，但是没有成功，所以就不用瞎费工夫了）
        {
            used[j]=1;
            if (girl[j]==-1 || find1(girl[j]))
            {
                //名花无主或者能腾出个位置来，这里使用递归
                girl[j]=x;
                return 1;
            }
        }
    }
    return 0;
}
int action()
{
    memset(nice,0,sizeof(nice));
    memset(girl,-1,sizeof(girl));


    scanf("%d",&n);
    for(int i=0; i<n; i++)
    {
        int a,b;
        scanf("%d%d",&a,&b);
        p1[i].a=a;
        p1[i].b=b;
    }
    for(int i=0; i<n; i++)
    {
        int a,b;
        scanf("%d%d",&a,&b);
        p2[i].a=a;
        p2[i].b=b;
    }
    for(int i=0; i<n; i++)
        for(int j=0; j<n; j++)
        {
            if(p1[i].a <p2[j].a && p1[i].b <p2[j].b)
            {
                nice[i][j]=1;

            }
        }
    int all=0;

    for (int i=0; i<n; i++)
    {
        memset(used,0,sizeof(used));    //这个在每一步中清空
        if (find1(i))
            all+=1;
    }
    printf("%d\n",all);
}

int main()
{
    action();
    return 0;
}



Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <iostream>
using namespace std;
int main() {
  int n;

  cin >> n;
  vector<int> a(n);
  for (int i = 0; i < n; ++i) {
    int num;
    cin >> num;
    a.at(i) = num;
  }

  int cnt = 0;
  bool flag = true;
  while (flag) {
    for (auto &a_i : a) {
      if (a_i % 2 == 0)
        a_i /= 2;
      else {
        flag = false;
        break;
      }
    }
    if (flag) ++cnt;
  }
  cout << cnt << endl;
  return 0;
}


Measured memory_bytes: 256
import java.util.*;
import java.lang.*;


public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        long t[] = new long[n];
        for (int i = 0; i < n; i++) {
            t[i] = sc.nextLong();
        }
        Arrays.sort(t);
        long l = 1;
        for (int i = 0; i < n; i++) {
            l = lcm(l, t[i]);
        }
        System.out.println(l);
    }
    static long lcm(long m, long n) {
        return m / gcd(m, n) * n;
    }
    static long gcd(long m, long n) {
        if (m < n) {
            return gcd(n, m);
        }
        if (n == 0) {
            return m;
        }
        return gcd(n, m % n);
    }
}


Measured memory_bytes: 21844
#include <iostream>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <vector>
#include <string>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <algorithm>

using namespace std;

#define rep(i,j) REP((i), 0, (j))
#define REP(i,j,k) for(int i=(j);(i)<(k);++i)
#define BW(a,x,b) ((a)<=(x)&&(x)<=(b))
#define ALL(v) (v).begin(), (v).end()
#define LENGTHOF(x) (sizeof(x) / sizeof(*(x)))
#define AFILL(a, b) fill((int*)a, (int*)(a + LENGTHOF(a)), b)
#define MP make_pair
#define PB push_back
#define F first
#define S second
#define INF 1 << 30
#define EPS 1e-10

typedef pair<int, int> pi;
typedef pair<int, pi> pii;
typedef vector<int> vi;
typedef queue<int> qi;
typedef long long ll;

int D, N, C[200], T[200], A[200], B[200], dp[200][200];

int dfs(int d, int prev){
  //  printf("%d %d\n", d, prev);
  if(d == D) return 0;
  if(dp[d][prev] >= 0) return dp[d][prev];

  int res = 0;
  rep(i, N){
    if(A[i] > T[d] || B[i] < T[d]) continue;
    res = max(res, dfs(d+1, i) + abs(C[i] - C[prev]));
  }
  return dp[d][prev] = res;
}

int main(){
  scanf("%d%d", &D, &N);
  rep(i, D) scanf("%d", T+i);
  rep(i, N) scanf("%d%d%d", A + i, B + i, C + i);
  memset(dp, -1, sizeof(dp));

  int res = 0;
  rep(i, N) if(A[i] <= T[0] && T[0] <= B[i]) res = max(res, dfs(1, i));
  printf("%d\n", res);
  return 0;
}

Measured memory_bytes: 1364
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i,n) for(ll i=0; i<n; ++i)
#define rep1(i,n) for(ll i=1; i<=n; ++i)
#define revrep(i,n) for(ll i=n-1; n>=0; --i)
inline constexpr ll Inf = (1ULL << 62) -1;

const ll Mod = 1e9+7;
int main() {
    ll ans=0, N;
    cin >> N;
    vector<ll> a(N+1);
    rep1(i,N) cin >> a[i];
    ll s = 0;
    rep1(i,N) {
        ans += a[i]*s;
        ans %= Mod;
        s += a[i];
        s %= Mod;
    }
    cout << ans << endl;
}


Measured memory_bytes: 4800
#!/usr/bin/python3
import sys
import re
from decimal import *

l = sys.stdin.readline()
l = l.split(' ')
l = [int(str) for str in l]

n = Decimal(l[0])
a = Decimal(l[1])
b = Decimal(l[2])

pre = 10**19
if(abs(a-b)%2==0):
	pre = int(abs(a -b)/2)
smax = ( a + b - 2 + 1) / 2
emax = ( n - a + n - b + 1) / 2
tmin = min( smax, emax)
v = int(tmin)
print(min(v,pre))

sys.stdout.flush()


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

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

const ll mod=1e9+7;
const ll inf=1ll<<60;

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

ll n;
string s;
vector<bool> b;

ll kaijo(ll n){
    return n?(kaijo(n-1)*n)%mod:1;
}

int main(){
    cin>>n>>s;
    b.resize(n*2);
    if(s[0]=='W'||s[n*2-1]=='W'){
        cout<<0<<endl;
        return 0;
    }

    b[0]=1;
    FOR(i,1,n*2){
        b[i]=b[i-1]^s[i]==s[i-1];
    }

    ll num=0,ans=1;
    rep(i,n*2){
        if(b[i])num++;
        else{
            (ans*=num)%=mod;
            num--;
        }
    }

    cout<<(num?0:(ans*kaijo(n))%mod)<<endl;
}

Measured memory_bytes: 2180
import java.util.*;
public class Main {
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    
    int n = sc.nextInt();

    int a[] = new int[n+1];
    a[0] = 0;
    for(int i = 1 ; i < n+1 ; ++i){
      a[i] = sc.nextInt();
    }
    
    int count = 0;
 
    for(int i = 1 ; i < n+1 ; ++i){
      if(i%2==1 && a[i]%2==1){
        count++;
      }
    }
    
    System.out.println(count);
    
  }
}

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

int main()
{
    ll l,r,i,j,k; cin>>l>>r;
    if(r-l+1>=2019) cout<<0;
    else
    {
        ll m=2018;
        for(i=l;i<r;i++)
        {
            for(j=i+1;j<r+1;j++)
            {
                m=min(m,(i*j)%2019);
            }
        }
        cout<<m;

    }
}


Measured memory_bytes: 256
n, x, y = map(int,input().split())

ans = [0] * (n - 1)
for i in range(n - 1):
    for j in range(i + 1, n):
        k = min(abs(x - i - 1) + abs(y - j - 1) + 1, j - i)
        ans[k - 1] += 1
print(*ans,sep= '\n')




Measured memory_bytes: 3444
#include<stdio.h>
#include<stdlib.h>
#define N 100000
#define NIL -1

int getDepth(int);
void print(int);
int rec(int,int);

struct Node{
  int p,l,r;
    };
struct Node T[N];
int D[N];


int main(){

  int i,j,v,d,c,l,r,n;

  scanf("%d",&n);
  for(i=0;i<n;i++){
    T[i].p=T[i].l=T[i].r=NIL;
  }
  for(i=0;i<n;i++){
    scanf("%d%d",&v,&d);
    for(j=0;j<d;j++){
      scanf("%d",&c);
      if(j==0)
	T[v].l=c;
      else T[l].r=c;
      l=c;
      T[c].p=v;
    }
  }

  for(i=0;i<n;i++){
    if(T[i].p==NIL) r=i;
  }
  rec(r,0);

  for(i=0;i<n;i++){
    print(i);
    }
  return 0;
}


int getDepth(int u){
  int d=0; 
  while(T[u].p!=NIL){
    u=T[u].p;
    d++;
      }
  return d;
}


  void print(int u){
    int i,c;
    printf("node %d: ",u);
    printf("parent = %d, ",T[u].p);
    printf("depth = %d,",getDepth(u));
    if(T[u].p==NIL)
      printf(" root, ");
    else if (T[u].l==NIL)
      printf(" leaf, ");
    else printf(" internal node, ");
    printf("[");
    for(i=0,c=T[u].l;c!=NIL;i++,c=T[c].r){
      if(i!=0)
	printf(", ");
      printf("%d",c);
    }
    printf("]\n");
  }


int rec(int u,int p){
  D[u]=p;
  if(T[u].r!=NIL) rec(T[u].r,p);
  if(T[u].l!=NIL) rec(T[u].l,p+1);
}

Measured memory_bytes: 5296
#include <iostream>
#include <fstream>
#include <cassert>
#include <typeinfo>
#include <vector>
#include <stack>
#include <cmath>
#include <set>
#include <map>
#include <string>
#include <algorithm>
#include <cstdio>
#include <queue>
#include <iomanip>
#include <cctype>
#include <random>
#include <complex>
#define syosu(x) fixed<<setprecision(x)
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> P;
typedef pair<double,double> pdd;
typedef pair<ll,ll> pll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<double> vd;
typedef vector<vd> vvd;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<char> vc;
typedef vector<vc> vvc;
typedef vector<string> vs;
typedef vector<bool> vb;
typedef vector<vb> vvb;
typedef vector<P> vp;
typedef vector<vp> vvp;
typedef vector<pll> vpll;
typedef pair<int,P> pip;
typedef vector<pip> vip;
const int inf=1<<30;
const ll INF=1ll<<59;
const double pi=acos(-1);
const double eps=1e-7;
const ll mod=1e9+7;
const int dx[4]={0,1,0,-1},dy[4]={1,0,-1,0};

int n;
vi a,b,c;

int main(){
	cin>>n;
	a=b=c=vi(n);
	for(int i=0;i<n;i++) cin>>a[i];
	for(int i=0;i<n;i++) cin>>b[i];
	for(int i=0;i<n;i++) cin>>c[i];
	sort(a.begin(),a.end());
	sort(b.begin(),b.end());
	sort(c.begin(),c.end());
	ll res=0;
	for(int i=0;i<n;i++){
		ll A=lower_bound(a.begin(),a.end(),b[i])-a.begin();
		ll B=n-(upper_bound(c.begin(),c.end(),b[i])-c.begin());
		res+=A*B;
	}
	cout<<res<<endl;
}

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

int main() {
  int n;
  std::cin >> n;
  if (n / 10 == 9 || n % 10 == 9) {
    std::cout << "Yes" << std::endl;
  } else {
    std::cout << "No" << std::endl;
  }
  return 0;
}


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

long long n, a[(1<<20)];

pair < long long, long long > proj ( long long y, long long x ) {
    long long c = min( x, y );
    return make_pair( y-c, x-c );
}

void printS( long long c ) {
    if ( c%2 ) { cout << "First\n"; }
    else { cout << "Second\n"; }
}

int main () {
    cin >> n;
    for ( long long i = 0 ; i < n ; i ++ ) {
        cin >> a[i];
    }
    sort( a, a+n );
    reverse( a, a+n );
    int szX, szY;

    for ( long long i = 0 ; i < n ; i ++ ) {
        if ( i == n-1 || a[i+1] < a[i] ) {
            pair < long long , long long > c = proj( a[i]-1, i );
            if ( c.first == 0 && c.second == 0 ) { cout << "Second\n"; return 0; }
        }
    }

    long long t = -1, r = -1;

    for ( long long i = 0 ; i < n ; i ++ ) {
        if ( i == n-1 || a[i+1] < a[i] ) {
            if ( proj( a[i]-1, i ).first == 0 ) { r = proj( a[i]-1, i ).second; szY = a[i]; break; }
        }
    }
    for ( long long i = n-1 ; i >= 0 ; i -- ) {
        if ( i == n-1 || a[i+1] < a[i] ) {
            if ( proj( a[i]-1, i ).second == 0 ) { t = proj( a[i]-1, i ).first; szX = i+1; break; }
        }
    }

    if ( r == -1 ) {
        printS( t );
        return 0;
    }
    if ( t == -1 ) {
        printS( r );
        return 0;
    }

    if ( r%2 == t%2 ) {
        printS( r );
    }else {
        pair < int, int > cc = proj ( szY, szX );
        if ( cc.first <= 1 && cc.second <= 1 ) {
            if ( cc.first == 0 && cc.second == 0 ) {
                cout << "First\n";
                return 0;
            }else if ( cc.first == 1 ) {
                if ( t%2 == 0 ) {
                    cout << "First\n";
                }else {
                    cout << "Second\n";
                }
            }else {
                if ( r%2 == 0 ) {
                    cout << "First\n";
                }else {
                    cout << "Second\n";
                }
            }
        }
        else {
            if ( szX < szY ) {
                printS ( r );
            }else {
                printS( t );
            }
        }
    }
    return 0;
}


Measured memory_bytes: 1024
#include <iostream>

using namespace std;

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

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

    int ans = 0;
    for (int i = 1; i < n-1; i++)
    {
        if ((p[i] > p[i-1] && p[i] < p[i+1]) || (p[i] < p[i-1] && p[i] > p[i+1]))
        {
            ans++;
        }
    }

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


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

#define PB push_back
#define MP make_pair

ll rows, cols, points;
std::vector<ll> v;
std::vector<pair<ll, ll> > coordi;
set<ll> st;
ll ans[10];

bool vis[100005][9];

ll getId(ll x, ll y)
{
	return (x - 1)* cols + y;
}

bool isOnBoard(ll x, ll y)
{
	if(x < 1 || x > rows || y < 1 || y > cols)
		return 0;
	return 1;
}




int main()
{
	int i, j;
	cin >> rows >> cols >> points;

	// int dx[] = {0, 0, 0, -cols, -cols, -cols, -2*cols, -2*cols, -2*cols};
	// int dy[] = {0, -1, -2, 0, -1, -2, 0, -1, -2};
	int dx[] = {0, 0, 0, -1, -1, -1, -2, -2, -2};
	int dy[] = {0, -1, -2, 0, -1, -2, 0, -1, -2};

	for(i = 0; i < points; i++)
	{
		int x, y;
		cin >> x >> y;
		v.PB(getId(x, y));
		coordi.PB(MP(x, y));
		st.insert(getId(x, y));
	}

	sort(coordi.begin(), coordi.end());

	for(i = 0; i < points; i++)
	{
		for(j = 0; j < 9; j++)
		{
			// ll topLeftId = v[i] + dx[j] + dy[j];

			ll topLeftX = coordi[i].first + dx[j];
			ll topLeftY = coordi[i].second + dy[j];

			// cout << coordi[i].first << " " << coordi[i].second << " : " << j << " " << topLeftX << " " << topLeftY << "\n";

			if(vis[i][j] == 1)	continue;

			ll c = 0;
			for(int k = 0; k < 9; k++)
			{
				ll x = topLeftX - dx[k];
				ll y = topLeftY - dy[k];
				if(!isOnBoard(x, y))
					c = -1;
			}

			if(c == -1)	continue;

			for(int k = 0; k < 9; k++)
			{
				ll x = topLeftX - dx[k];
				ll y = topLeftY - dy[k];
				// cout << x << " " << y << "\n";
				if(st.find(getId(x, y)) != st.end())
				{
					int ind = lower_bound(coordi.begin(), coordi.end(), MP(x,y)) - coordi.begin();
					vis[ind][k] = 1;
					c++;
				}
			}
			ans[c]++;
		}
	}

	ll tot = (rows - 2) * (cols - 2);
	for(int i = 1; i < 10; i++)
		tot -= ans[i];
	ans[0] = tot;

	for(int i = 0; i < 10; i++)
		cout << ans[i] << "\n";
}

Measured memory_bytes: 8164
#define _USE_MATH_DEFINES

#include "bits/stdc++.h"
using namespace std;

typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<double> vd;
typedef vector<vd> vvd;
typedef vector<vvd> vvvd;
typedef pair<int, int> pii;
typedef vector<pii> vpii;

#define LL long long


int main() {
	string s;
	int Aplace = 10000000, Zplace = 0;
	cin >> s;

	for (int i = 0; i < s.size(); i++) {
		if (s[i] == 'A') {
			if (Aplace >= i) Aplace = i;
			break;
		}
	}
	for (int i = s.size(); i > 0; i--){
		if (s[i] == 'Z') {
			if (Zplace <= i) Zplace = i;
			break;
		}
	}
	cout << Zplace - Aplace + 1 << endl;

}

Measured memory_bytes: 768
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> pll;
typedef tuple<ll, ll, ll> tll;

/**
 * 最大公約数 
 */
ll gcd(ll numA, ll numB)
{
    return numB ? gcd(numB, numA % numB) : numA;
}

int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll N, X;
    cin >> N >> X;
    vector<ll> points(N + 1);
    for(int i = 0; i < N; i++)
    {
        cin >> points.at(i);
    }
    points.at(N) = X;
    sort(points.begin(), points.end());
    vector<ll> distances(N);
    for(int i = 0; i < N; i++)
    {
        distances.at(i) = points.at(i + 1) - points.at(i);
    }

    ll answer = distances.at(0);
    for(int i = 1; i < N; i++)
    {
        answer = gcd(answer, distances.at(i));
    }
    cout << answer << endl;
    return 0;
}


Measured memory_bytes: 1792
#include <bits/stdc++.h>
  
using namespace std;
  
#define rep(i,n) REP(i,0,n)
#define REP(i,s,e) for(int i=(s); i<(int)(e); i++)
#define repr(i, n) REPR(i, n, 0)
#define REPR(i, s, e) for(int i=(int)(s-1); i>=(int)(e); i--)
#define pb push_back
#define all(r) r.begin(),r.end()
#define rall(r) r.rbegin(),r.rend()
#define fi first
#define se second
  
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
 
const int INF = 1e9;
const ll MOD = 1e9 + 7;
double EPS = 1e-8;

const int MAX_N = 2e5+10;
vector<int> es[MAX_N];


int dist[MAX_N];
void dfs (int cur, int par) {
    int d = dist[cur];
    for(auto& to: es[cur]) {
        if(to == par) continue;
        dist[to] = d + 1;
        dfs(to, cur);
    }
}

int dist2[MAX_N];
void dfs2 (int cur, int par) {
    int d = dist2[cur];
    for(auto& to: es[cur]) {
        if(to == par) continue;
        dist2[to] = d + 1;
        dfs2(to, cur);
    }
}

int dp[MAX_N];

int main(){
    int n;
    cin >> n;
    rep(i, n-1) {
        int a, b;
        cin >> a >> b;
        a--; b--;
        es[a].pb(b);
        es[b].pb(a);
    }
    dist[0] = 1;
    dfs(0, -1);
    int x = 0;
    REP(i, 1, n) if(dist[x] < dist[i]) x = i;

    dist2[x] = 1;
    dfs2(x, -1);
    int y = x;
    rep(i, n) if(dist2[y] < dist2[i]) y = i;

    int d = dist2[y];
    dp[1] = 1;
    dp[2] = 0;
    REP(i, 3, d+1) {
        if(dp[i-1] == 0 || dp[i-2] == 0) dp[i] = 1;
        else dp[i] = 0;
    }
    cout << (dp[d] ? "First" : "Second") << endl;
    
    return 0;
}

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

using ll = long long;
#define rep(n, i) for(ll i = 0; i < n; ++i)

void solve(void){
  ll n, k; cin >> n >> k;
  vector<ll> vh(n, 0);
  rep(n, i) cin >> vh[i];

  sort(vh.begin(), vh.end());

  ll res = 1e9;
  for (ll i = 0; i + (k-1) < n; ++i) {
    res = min(res, vh[i+(k-1)] - vh[i]);
  }

  cout << res << endl;

}

int main(void) {
  solve();
  return 0;
}

Measured memory_bytes: 1024
#include<bits/stdc++.h>
#include<string>
#include<cmath>

using namespace std;

#define ll long long int
#define ld long double
#define pb push_back
#define all(v) v.begin(),v.end()
#define sz(x) ((int)(x).size())
#define fi first
#define se second
#define deb(x) cout<< #x << '=' << x <<endl
#define MOD 1000000007
const int N = 1e5 + 1;
int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);

    ll n , x, m;
    cin>>n>>x>>m;
    ll ans = 0;
    if(x == 1){
        cout<<n<<"\n";
        return 0;
    }else if(x == 0){
        cout<<"0\n";
        return 0;
    }
    set<ll> s;
    vector<ll> rem;
    ll sum = 0;   
    ll same = -1;
    while(1){
        ans += x;
        s.insert(x);
        rem.pb(x);
        n--;
        if(n == 0){
            break;
        }
        x *= x;
        x %= m;
        if(s.find(x) != s.end()){
            same = x;
            break;
        }
    }
    ll l = 0;
    bool ok = 0;
    for(auto it : rem){
        if(it == same){
            ok = 1;
        }
        if(ok){
            sum += it;
            l++;
        }
    }
    if(l != 0){
        ans += (n/l)*sum;
        n -= ((n/l)*l);
    }
    ok = 0;
    for(auto it : rem){
        if(it == same){
            ok = 1;
        }
        if(ok){
            if(n == 0){
                break;
            }
            ans += it;
            n--;
        }
    }
    cout<<ans<<"\n";
    return 0;
}

Measured memory_bytes: 5856
#include<bits/stdc++.h>
#define int long long
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define mt make_tuple
#define ld(a) while(a--)
#define tci(v,i) for(auto i=v.begin();i!=v.end();i++)
#define tcf(v,i) for(auto i : v)
#define all(v) v.begin(),v.end()
#define rep(i,start,lim) for(long long (i)=(start);i<(lim);i++)
#define sync ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define osit ostream_iterator
#define INF 		0x3f3f3f3f
#define LLINF       1000111000111000111LL
#define PI 			3.14159265358979323
#define endl '\n'
#define trace1(x)                cerr<<#x<<": "<<x<<endl
#define trace2(x, y)             cerr<<#x<<": "<<x<<" | "<<#y<<": "<<y<<endl
#define trace3(x, y, z)          cerr<<#x<<":" <<x<<" | "<<#y<<": "<<y<<" | "<<#z<<": "<<z<<endl
#define trace4(a, b, c, d)       cerr<<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<endl
#define trace5(a, b, c, d, e)    cerr<<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<" | "<<#e<< ": "<<e<<endl
#define trace6(a, b, c, d, e, f) cerr<<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<" | "<<#e<< ": "<<e<<" | "<<#f<<": "<<f<<endl
const int N=1000006;
using namespace std;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef long long ll;
typedef vector<long long> vll;
typedef vector<vll> vvll;
typedef long double ld;
typedef pair<int,int> ii;
typedef vector<ii> vii;
typedef vector<vii> vvii;
typedef tuple<int,int,int> iii;
typedef set<int> si;
typedef complex<double> pnt;
typedef vector<pnt> vpnt;
typedef priority_queue<ii,vii,greater<ii> > spq;
const ll MOD=1000000007LL;
template<typename T> T gcd(T a,T b){if(a==0) return b; return gcd(b%a,a);}
template<typename T> T power(T x,T y,ll m=MOD){T ans=1;while(y>0){if(y&1LL) ans=(ans*x)%m;y>>=1LL;x=(x*x)%m;}return ans%m;}
int32_t main(){
	string s; cin>>s;
	set<char> t;
	tcf(s,i) t.insert(i);
	if(t.size()==s.size()) cout<<"yes";
	else cout<<"no";
}



Measured memory_bytes: 256
import java.util.Arrays;
import java.util.Scanner;

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

    int N = scanner.nextInt();
    int M = scanner.nextInt();
    boolean[] possible = new boolean[N];
    possible[0] = true;
    int[] count = new int[N];
    Arrays.fill(count, 1);
    for (int i = 0; i < M; i++) {
      int x = scanner.nextInt() - 1;
      int y = scanner.nextInt() - 1;
      possible[y] |= possible[x];
      count[x]--;
      count[y]++;
      if (count[x] == 0) possible[x] = false;
    }
    int cnt = 0;
    for (int i = 0; i < N; i++) if (possible[i]) cnt++;
    System.out.println(cnt);
  }
}


Measured memory_bytes: 65004
N = int(input())
a = 0
valid = False
for i in range(N):
    d1, d2 = map(int,input().split())
    if d1 == d2:
        a += 1
        if a == 3:
            valid = True
    else:
        a = 0
if valid:
    print("Yes")
else:
    print("No")


Measured memory_bytes: 62248
import java.io.*
import java.util.*

fun solve(N: Long, A: LongArray){
    val n = N.toInt()
    val a = A.sortedDescending()
    val max = a.first()!!
    val smax = a.getOrNull(1)!!
    repeat(n){
        if (A[it] == max) println(smax)
        else println(max)
    }
    return
}


fun main(args: Array<String>) {
    fun StringArray(size: Int, init: (Int) -> String = { "\u0000" }): Array<String> {
        return Array<String>(size, init)
    }
    class Scanner(stream: InputStream) {
        private val reader = BufferedInputStream(stream).bufferedReader()
        private var st: StringTokenizer? = null
        fun next(): String {
            while (!(st?.hasMoreTokens() ?: false)) st = StringTokenizer(reader.readLine())
            return st!!.nextToken()
        }
    }
    val sc = Scanner(System.`in`)
    val N = sc.next().toLong()
    val A = LongArray(N.toInt())
    for (i in 0 until N.toInt()) {
        A[i] = sc.next().toLong()
    }
    solve(N, A)
}



Measured memory_bytes: 58864
import math,itertools,fractions,heapq,collections,bisect,sys,queue,copy

sys.setrecursionlimit(10**7)
inf=10**20
mod=1000000007
dd=[(-1,0),(0,1),(1,0),(0,-1)]
ddn=[(-1,0),(-1,1),(0,1),(1,1),(1,0),(1,-1),(0,-1),(-1,-1)]

def LI(): return [int(x) for x in sys.stdin.readline().split()]
def I(): return int(sys.stdin.readline())
def LS(): return sys.stdin.readline().split()
def S(): return input()

def main():
  n,k=LI()
  l=LI()

  cnt=min(n,k)
  ans=0
  for i in range(cnt+1):
    for j in range(cnt-i+1):
      q=[]
      for _i in range(i):
        heapq.heappush(q,l[_i])

      for _j in range(j):
        heapq.heappush(q,l[-(_j+1)])

      ln=len(q)
      for _ in range(min(k-i-j,ln)):
        x=heapq.heappop(q)
        if x>0:
          q.append(x)
          break
      # print(q)
      ans=max(ans,sum(q))

  return ans

# main()
print(main())


Measured memory_bytes: 5204
#include<bits/stdc++.h>
#include<iostream>
#include<math.h>
#include<string>
using namespace std;
int main()
{
    long long int a,b,c[100001],d,e,h,i,j,k=1,temp,n,x,y,m,z;
    cin>>a>>b;

        if(a>b) cout<<"safe"<<endl;
        else cout<<"unsafe"<<endl;

}


Measured memory_bytes: 3624
#include<bits/stdc++.h>
using namespace std;
int main()
{
	int n;
	cin >> n;
	long long arr[n];
	for (int i = 0; i < n; ++i)
	{
		cin >> arr[i];
	}

	int zero =0;
	for(int i=0;i<n;i++) if(arr[i]==0) zero ++;

	if(zero >0)
	{
		printf("0\n");
		return 0;
	}
	long long prod =1;
	for(int i=0;i<n;i++)
	{
		if(arr[i] <=1000000000000000000/ prod )
		{
			prod *=arr[i];
		}
		else
		{
			printf("-1\n");
			return 0;
		}
	}
	printf("%lld\n",prod );

	return 0;
}

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

int main() {
  int p = 2019;
  string s;
  cin >> s;
  int n = s.size();
  int total = 0;
  int k = 1;
  long long ans = 0;
  vector<int> count(p);
  count[0] = 1;
  reverse(s.begin(), s.end());
  for (int i = 0; i < n; i++) {
    total += (s[i] - '0') * k;
    int mod = total % p;
    ans += count[mod];
    count[mod]++;
    k *= 10;
    k %= p;
  }
  cout << ans << endl;
}

Measured memory_bytes: 3748
/*
	  Chase
	   Your
	  Legend

	英雄志逐传奇
*/

#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <cmath>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <math.h>
#include <stdio.h>

#define rep(i, n) for(int i = 0; i < (n); i++)
typedef long long ll;
using namespace std;

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

	for (int i = a; i <= min(b, a + k - 1); i++) {
		cout << i << endl;
	}
	for (int i = max(b - k + 1, a + k); i <= b; i++) {
		cout << i << endl;
	}
}


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

int a[2005],total=0;

int main()
{
	int n;
	cin>>n;
	for (int i=1;i<=n;i++)  cin>>a[i];
	sort(a+1,a+n+1);
	for (int i=1;i<=n-2;i++)
	{
		for (int j=i+1;j<=n-1;j++)
		{
			int l=j+1,r=j+1;
			while (1)
			{
				if (r>n)
				{
					r--;
					break;
				}
				if (a[r]>=a[i]+a[j])
				{
					r--;
					break;
				}
				r++;
			}
			total=total+(r-l+1);
		}
	}
	cout<<total<<endl;
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define REP(i, n) for (int i = 0; i < (n); i++)
#define RREP(i, n) for (int i = (n); i >= 0; i--)
#define FOR(i, m, n) for (int i = (m); i < (n); i++)
#define ALL(obj) begin(obj), end(obj)
using namespace std;
using ll = unsigned long long;
const int MOD = 1e9 + 7;
int main() {
    ll N;
    vector<ll> A;
    cin >> N;
    REP(i, N) {
        ll a;
        cin >> a;
        A.push_back(a);
    }
 
    ll ans;
    REP(i, 63) {
        ll zc, oc;
        zc = oc = 0;
        REP(j, N) {
            if (A[j] % 2 == 0) {
                zc++;
            } else {
                oc++;
            }
            A[j] /= 2;
        }
        zc %= MOD;
        oc %= MOD;
 
        ans = (ans + (((zc * oc) % MOD * ((1LL << i) % MOD)) % MOD)) % MOD;
    }
 
    cout << ans << endl;
 
    return 0;
}

Measured memory_bytes: 6384
import java.util.*;
public class Main{
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    int n = sc.nextInt();
    int l[] = new int[n];
    int sum = 0;
    int k[] = new int[n];
    for(int i=0;i<n;i++){
      l[i]=sc.nextInt();
      sum = sum+l[i];
    }
    for(int i=0;i<n;i++){
      k[i] = sum - l[i];
    }
    for(int i=0;i<n;i++){
      if(l[i]>=k[i]){
        System.out.println("No");
        return;
      }
    }
    System.out.println("Yes");
      
    
    
  }
  

  
}

Measured memory_bytes: 23124
#include <stdio.h>
int a[1010];
int main(void)
{
    int i;
    for(i=1;i<1010;++i) a[i]=i+a[i-1];
    while (1) {
        int n, res, s, t;
        scanf("%d", &n);
        if (n==0) break;

        res=0;
        s=0, t=1;
        while (a[t]<n) ++t;

        while (t<n) {
            while (a[t]-a[s]>n) ++s;
            if (a[t]-a[s]==n) ++res;
            ++t;
        }
        printf("%d\n", res);
    }
    return 0;
}

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

using namespace std;

int main(){
   int n,k,a=0;
   cin >> n >> k;
   for(int i =0; i<n;i++){
       int h;
       cin >> h;
       if(h>=k){
           a++;
       }
   }
   cout << a << endl;
}

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

using namespace std;

int N;
string s;
unsigned long long a[100005];

int main(){
    cin >> N;
    // 0 除外
    unsigned long long prod = 1; unsigned long long tmp;
    rep(i,N){
        cin >> tmp;
        if(tmp == 0) { cout << "0"; return 0;}
        a[i] = tmp;
    }
    unsigned long long max_;
    rep(i,N){
        max_ = 1000000000000000000 / prod;
        if(a[i] > max_) {cout << "-1";  return 0;}
        prod *= a[i];
    }
    cout << prod;
	return 0;
}


Measured memory_bytes: 4404
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp> 

using namespace __gnu_pbds;
using namespace std;

#define mod 1000000007

#define ft first
#define sd second
#define pb push_back
#define all(x) x.begin(),x.end()
#define ll long long int
#define db long double
#define vlli vector<long long int >
#define mp make_pair
#define ms(x, v) memset(x, v, sizeof x)
#define cnl cout<<"\n";
#define fr(i,b) for(ll i=0; i<=b; i++)
#define frr(i,b) for(ll i=0;i<b;i++)
#define fb(i,b) for(ll i=b-1; i>=0; i--)
#define PI 3.14159265



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

 bool comp(pair<long int ,long int>v1,pair<long int ,long int>v2){
          if(v1.ft==v2.ft) return v1.sd>v2.sd;
          else return v1<v2;
 }

 typedef tree<int,null_type,less<int>,rb_tree_tag, tree_order_statistics_node_update> indexed_set;
ll i,j,k;
 

int main(){
   ll n,d; cin>>n>>d;
   ll x=2*d +1;
   if(n%x==0) cout<<n/x<<endl;
   else cout<<(n/x)+1<<endl;



return 0;
}


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

string s;

int main()
{
    ios::sync_with_stdio(false);
    cin >> s;
    for (int i = 0; i < s.size(); i++)
        for (int j = i; j < s.size(); j++)
        {
            if (s.substr(0, i) + s.substr(j) == "keyence")
            {
                cout << "YES" << endl;
                return 0;
            }
            // cout << s.substr(0, i) + s.substr(j) << endl;
        }
    cout << "NO" << endl;
}

Measured memory_bytes: 256
import java.util.Scanner;

/**
 * Main
 */
public class Main {

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

        double N = sc.nextInt();
        double D = sc.nextInt();

        double watch = 1 + D*2;

        double answer = Math.ceil(N/watch);

        // System.out.println(N);
        // System.out.println(watch);
        System.out.println((int)answer);


    }
}

Measured memory_bytes: 21844
#include <bits/stdc++.h>
#include <algorithm>
using namespace std;
#include <bits/stdc++.h>
using namespace std;
long long int Inv(long long int a, long long int m) {
  int c[50];
  long long int e[50];  
  c[0] = (m-2) % 2, e[0] = (m-2) / 2; 
  for (int i = 0; i < 49; ++i){
     c[i+1] = e[i] % 2;
     e[i+1] = e[i] / 2;  
  }
  long long int d[50]; 
  d[0] = a; 
  for (int j = 0; j < 49; ++j){
     d[j+1] = (d[j] * d[j]) % m; 
  }
  long long int Q; 
  Q = 1; 
  for(int k = 0; k < 49; ++k){
  if (c[k] == 0) Q = Q; 
  if (c[k] == 1) Q = (Q * d[k]) % m; 
  }
 return Q;
}
int main(){
long long int p = 1000000007; 
long long int N; 
long long int A[114514] = {}; 
cin >> N; 
for(int i = 0; i < N; i++){
cin >> A[i]; 
}
long long int Fac[114514] = {};
Fac[0] = 1;  
for(int i = 1; i < 114514; i++){
Fac[i] = (Fac[i-1] * i) % p; 
}
long long int G[114514] = {}, H[114514] = {};
for(int i = 1; i <= N; i++){
G[i] = (Fac[N] * Inv(i, p)) % p; 
H[i] = (H[i-1] + G[i]) % p; 
}
long long int I[114514] = {}; 
I[0] = H[N]; 
for(int i = 1; i < N; i++){
long long int J = (((Fac[N-1] * (N-1-i)) % p) * Inv(i+1, p)) % p; 
long long int K = (((Fac[N-1] * (i-1)) % p) * Inv(N-i+1, p)) % p; 
I[i] = (((I[i-1] + J) % p) + p - K) % p; 
}
long long int L[114514] = {}; 
for(int i = 0; i < N; i++){
L[i] = (A[i] * I[i]) % p; 
}
long long int ans = 0;
for(int i = 0; i < N; i++){
ans = (ans + L[i]) % p; 
}
cout << ans << endl; 
}

Measured memory_bytes: 4736