akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#define ll long long int
#define pb push_back
#define mp make_pair
#define mod 1000000007
#define pi 3.141592653589793
using namespace std;



int main() {
//    cout << setprecision(100);
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);

    int n;
    cin >> n;
    int a[n], pre[n], post[n];
    for (int i = 0; i < n; i++) cin >> a[i];

    pre[0] = a[0];
    post[n - 1] = a[n - 1];

    for (int i = 1; i < n; i++) pre[i] = max(pre[i - 1], a[i]);
    for (int i = n - 2; i >= 0; i--) post[i] = max(a[i], post[i + 1]);


    cout << post[1] << '\n';
    for (int i = 1; i < n - 1; i++) {
        cout << max(pre[i - 1], post[i + 1]) << '\n';
    }

    cout << pre[n - 2];







}




Measured memory_bytes: 3968
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;

internal static class CR
{
    public static string Get() { return Console.ReadLine(); }
    public static IEnumerable<string> GetTexts() { return Console.ReadLine().Split(' '); }
    public static int GetInteger() { return int.Parse(Console.ReadLine()); }
    public static IEnumerable<int> GetIntegers() { return Console.ReadLine().Split(' ').Select(x => int.Parse(x)); }
}

namespace AtCoderBeginnerContest
{
    internal class Program
    {
        private static void Main() { var r = GetResult(); Debug.WriteLine(r); Console.WriteLine(r); }

        private static object GetResult()
        {
            var texts = CR.GetTexts().ToList();
            return string.Join("", texts[1], texts[0]);
        }
    }
}


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

#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define endl "\n"
#define ll long long
#define pii pair<int,int>
#define all(x) begin(x), end(x)
#define loop(i,n) for(int i=0; i<n; i++)
#define rep(i,a,b,c) for(int i=a; i<b; i+=c)
#define brep(i,a,b,c) for(int i=a; i>b; i-=c)
#define tc(t) int t; cin>>t; while(t--)
#define sz(v) int((v).size())
#define pb push_back

const int maxm = 1000000000 + 7;


using namespace std;


int main()
{

#ifndef ONLINE_JUDGE
  freopen("input.txt", "r", stdin);
  freopen("output.txt", "w", stdout);
#endif

  int n;
  cin>>n;

  int a[n];

  loop(i,n)
  {
    cin>>a[i];
  }

  int ans=1;
  int max_h = a[0];

 for(int i=1; i<n; i++)
 {
    if(a[i] >= max_h)
    {
      ans++;
      max_h = a[i];
    }
 }
 
 cout<<ans<<endl;

}

Measured memory_bytes: 3636
#!/usr/bin/env python3
import sys
from itertools import chain

# form bisect import bisect_left, bisect_right, insort_left, insort_right
# from collections import Counter
# import numpy as np


# 0123
# 123
#  35

# 0123
# 124
#  3


def solve(N: int, A: "List[int]"):
    A = sorted(A, reverse=True)
    if N == 1:
        return
    N -= 1
    if N % 2 == 0:
        return A[0] + 2 * sum(A[1 : N // 2]) + A[N // 2]
    else:
        return A[0] + 2 * sum(A[1 : (N - 1) // 2 + 1])


def main():
    tokens = chain(*(line.split() for line in sys.stdin))
    # N, A = map(int, line.split())
    N = int(next(tokens))  # type: int
    A = list(map(int, (tokens)))
    answer = solve(N, A)
    print(answer)


if __name__ == "__main__":
    main()


Measured memory_bytes: 31552
#include <bits/stdc++.h>
#define pb push_back
typedef long double ld;
typedef long long ll;

using namespace std;


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

	string a, b, c; cin >> a >> b >> c;
	cout << a[0] << b[1] << c[2]<< endl;

    return 0;
}

Measured memory_bytes: 256
import java.util.*;

public class Main {

    public static void main(String args[]) {

        // 入力
        Scanner sc = new Scanner(System.in);
        String s = sc.next();
        String t = sc.next();
        sc.close();

        // 主処理
        boolean judge = t.matches(s + ".");
        String result = judge ? "Yes" : "No";

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


Measured memory_bytes: 38632
#include<iostream>
#include<algorithm>
#include<string>
#include<vector>
#include<set>
#include<queue>
#include<cmath>
#include<ctime>
#define R(i, n) for(int i = 0;i < n;i++)
#define S(a) scanf("%d", &a)
#define S2(a, b) scanf("%d%d", &a, &b)
#define S3(a, b, c) scanf("%d%d%d", &a, &b, &c)
#define SA(i, n, a) R(i, n) scanf("%d", a + i)
#define P(a) printf("%d", a)
using namespace std;
using ll = long long;
using PR = pair<int, int>;
const ll MOD = 1e+9 + 7;

int N, A[100001], B[100000];

int main() {
	S(N);
	SA(i, N + 1, A);
	SA(i, N, B);
	ll ans = 0;
	R(i, N) {
		if (B[i] >= A[i]) {
			ans += (ll)A[i] + min(B[i] - A[i], A[i + 1]);
			A[i + 1] = max(A[i + 1] - (B[i] - A[i]), 0);
		}
		else {
			ans += B[i];
		}
	}
	printf("%lld", ans);
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
        using namespace std;
   #define int long long
const int MAX = 510000;
const int MOD = 1000000007;
vector<int> hen[100000];
int score[100000];
int dfs(int a){
   if(score[a]==-1){
      score[a]=0;
      for(auto&& i :hen[a])score[a]=max(score[a],1+dfs(i));
   }
   return score[a];
}

     signed main(){
        int n,m;
        cin>>n>>m;
        int x,y;
for(int i=0;i<m;i++){
   cin>>x>>y;x--;y--;
   hen[x].push_back(y);
}
fill(score,score+n,-1);int ans=0;
for(int i=0;i<n;i++)ans=max(ans,dfs(i));
cout<<ans<<endl;

     }


 


 






    





      

        


Measured memory_bytes: 7808
object Main extends App {
	val pw = new java.io.PrintWriter(System.out)

	@scala.annotation.tailrec
	def loop(start: Int, end: Int)(f: Int => Unit): Unit =
		if (start < end) {
			f(start)
			loop(start + 1, end)(f)
		}

	var ac, wa, tle, re = 0
	loop(0, Scanner.nextInt) { i =>
		Scanner.next match {
			case "AC" => ac += 1
			case "WA" => wa += 1
			case "TLE" => tle += 1
			case "RE" => re += 1
		}
	}

	pw.println(s"AC x $ac")
	pw.println(s"WA x $wa")
	pw.println(s"TLE x $tle")
	pw.println(s"RE x $re")
	pw.flush()
}

object Scanner {
	private val buf = new Array[Byte](1024); private var ptr = 0; private var len = 0

	@inline private def isPrintableChar(c: Int): Boolean = 33 <= c && c <= 126
	@inline private def hasNextByte(): Boolean = if (ptr >= len) { ptr = 0; len = System.in.read(buf); len > 0 } else true
	@inline private def hasNext(): Boolean = {
		while (hasNextByte() && !isPrintableChar(buf(ptr))) ptr += 1
		hasNextByte()
	}
	@inline private def readByte(): Byte = if (hasNextByte()) { val res = buf(ptr); ptr += 1; res } else -1

	def next(): String = {
		if(!hasNext()) ???
		val sb = new StringBuilder; var b = readByte()
		while (isPrintableChar(b)) { sb.append(b.toChar); b = readByte() }
		sb.toString
	}

	def nextInt(): Int = {
		val n = nextLong()
		if (n < Int.MinValue || Int.MaxValue < n) ???
		n.toInt
	}

	def nextLong(): Long = {
		if(!hasNext()) ???
		var minus = false; var b = readByte()
		if (b == '-') { minus = true; b = readByte() }

		@scala.annotation.tailrec
		def go (b: Byte, n: Long = 0): Long = if ('0' <= b && b <= '9') go(readByte(), n * 10 + b - '0') else if (minus) -n else n

		go(b)
	}

	def nextDouble(): Double = next().toDouble
}


Measured memory_bytes: 56144
#include <iostream>
#include <string>
#include <vector>
#include <map>
#include <cmath>
#include <algorithm>
#include <functional>
#include <stack>
#include <numeric>
typedef long long ll;
using namespace std;
const int MOD = (int)1e9 + 7;
const ll INF = (ll)1e18 + 7;
#define int long long
#define vint vector<int>
#define pint pair<int,int>
#define pb(a) push_back(a)
#define all(v) v.begin(),v.end()
#define dbg(x) cerr << #x << " = " << (x) << endl
#define yn(b) cout << ((b) ? "Yes" : "No") << endl
#define YN(b) cout << ((b) ? "YES" : "NO") << endl

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

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

	int N;
	cin >> N;
	vint a(N);

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

	int ans = 0;

	for (int i = 0; i < N-1; i++) {
		if(a[i]==a[i+1]){
			ans++;
			i++;
		}
	}

	cout << ans << endl;

	return 0;
}

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

int main(){
	ios_base::sync_with_stdio(false);
    cin.tie(NULL);
	ll a,b,c,d;
	cin>>a>>b>>c>>d;
	ll m = a*c;
	ll n = a*d;
	ll x = max(m,n);
	ll l = b*c;
	ll o = b*d;
	ll y = max(l,o);
	cout<<max(x,y)<<"\n";
	return 0;
}

Measured memory_bytes: 3636
#include<iostream>
#include <stdio.h>
#include <string>
#include <string.h>
#include <algorithm>
#include <functional>
#include <vector>

using namespace std;
int main()
{
	string s;
	cin >> s;

	int len = s.size();
	string a = to_string(len - 2);

	s = s.replace(1, len - 2, a);

	cout << s;

	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ll long long
vector<ll> app[30];
string s,t;
int main(){
	cin>>s>>t;
	ll at=0,cop=1,last=-1;
	for(ll i=0;i<s.size();i++)
		app[s[i]-'a'+1].push_back(i);
	while(at!=t.size()){
		if(app[t[at]-'a'+1].size()==0){
			printf("-1\n");
			return 0;
		}
		if(app[t[at]-'a'+1][app[t[at]-'a'+1].size()-1]<=last) cop++,last=-1;
		ll l=0,r=app[t[at]-'a'+1].size()-1,mid,ans;
		while(l<=r){
			mid=(l+r)/2;
			if(app[t[at]-'a'+1][mid]>last) r=mid-1,ans=mid;
			else l=mid+1;
		} 
		last=app[t[at]-'a'+1][ans],at++;
	}
	cout<<(cop-1)*s.size()+last+1<<endl;
}

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

int ze(int a)
{
	if (a < 0)return -a;
	return a;
}
int main() {
	int a;
	cin >> a >> a >> a;
	int b, c;
	cin >> b >> c;
	int s = 0;
	for (int d = 0; d < a - 1; d++) {
		int e, f;
		cin >> e >> f;
		if ((e > b&&f > c) || (e < b&&f < c))s += max(ze(e - b), ze(f - c));
		else s += ze(e - b) + ze(f - c);
		b = e; c = f;
	}
	cout << s << endl;
}

Measured memory_bytes: 3112
import java.util.Scanner;

public class Main {
	static Scanner sc = new java.util.Scanner(System.in);

	public static void main(String[] args) {

		while (sc.hasNext()) {
			int n = sc.nextInt();

			if (n == 1) {
				System.out.println(0);
			} else if (n == 2) {
				System.out.println(1);
			} else if (n == 3 || n == 4) {
				System.out.println(2);
			} else if (n == 5 || n == 6) {
				System.out.println(3);
			} else if (n == 7 || n == 8) {
				System.out.println(4);
			} else {
				int count = 4;

				for (int i = 9; i <= n; i = i + 2) {
					boolean type = true;
					for (int j = 3; j <= Math.sqrt(i); j=j+2) {
						if (i % j == 0) {
							type = false;
							break;
						}
					}
					if (type) {
						count++;
					}
				}
				System.out.println(count);
			}

		}

	}

}

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

using namespace std;
#define ll long long
#define pb push_back
#define vi vector<int>
#define inf 1000000100

int main()
{
    int sx, sy, tx, ty;

    cin >> sx >> sy >> tx >> ty;

    string prix, priy, nprix, npriy;

    if(sx > tx)
    {
        prix = "L";
        nprix = "R";
    }
    else
    {
        prix = "R";
        nprix = "L";
    }

    if(sy > ty)
    {
        priy = "D";
        npriy = "U";
    }
    else
    {
        priy = "U";
        npriy = "D";
    }

    for(int i = 0; i < abs(ty - sy); i++)
    {
        cout << priy;
    }
    for(int i = 0; i < abs(tx - sx); i++)
    {
        cout << prix;
    }
    for(int i = 0; i < abs(ty-sy); i++)
    {
        cout << npriy;
    }
    for(int i = 0; i < abs(tx - sx); i++)
    {
        cout << nprix;
    }

    cout << nprix;
    for(int i = 0; i < abs(ty-sy) + 1; i++)
    {
        cout << priy;
    }
    for(int i = 0; i < abs(tx - sx) + 1; i++)
    {
        cout << prix;
    }
    cout << npriy;
    cout << prix;
    for(int i = 0; i < abs(ty-sy) + 1; i++)
    {
        cout << npriy;
    }
    for(int i = 0; i < abs(tx-sx) + 1; i++)
    {
        cout << nprix;
    }

    cout << priy << endl;

}

Measured memory_bytes: 256
import java.util.*;

public class Main{
	int n,m,d;
	public void run(){
		Scanner cin = new Scanner(System.in);
		while(true){
			m = cin.nextInt();
			n = cin.nextInt();
			d = cin.nextInt();
			if(m==0) break;
			int i,j,k,l;
			int[] board = new int[n * m];
			for(i=0;i<n;i++){
				for(j=0;j<m;j++){
					board[i * m + j] = cin.nextInt();
				}
			}
			int[][] matrix = new int[n*m][n*m];
			for(i=0;i<n;i++){
				for(j=0;j<m;j++){
					for(k=0;k<n;k++){
						for(l=0;l<m;l++){
							if(Math.abs(i-k)+Math.abs(j-l) == d){
								matrix[i*m+j][k*m+l] = 1;
							}
						}
					}
					matrix[i*m+j][i*m+j] = 1;
				}
			}
			int len = n*m;
			for(i=0;i<len;i++){
				for(j=i;j<len;j++){
					if(matrix[j][i]==1) break;
				}
				if(j!=len){
					int[] tmp = matrix[j].clone();
					matrix[j] = matrix[i].clone();
					matrix[i] = tmp.clone();
					for(l=i+1;l<len;l++){
						if(matrix[l][i]==0) continue;
						for(k=i;k<len;k++){
							matrix[l][k] ^= matrix[i][k];
						}
					}
				}
			}
			for(i=0;i<len;i++){
				for(j=0;j<len;j++){
					//System.out.print(matrix[i][j] + " ");
				}
				//System.out.println();
			}
			
			int[] ret = new int[len];
			for(i=0;i<len;i++){
				if(ret[i] != board[i]){
					if(matrix[i][i]==0) break;
					else{
						for(j=i;j<len;j++){
							ret[j] ^= matrix[i][j];
						}
					}
				}
			}
			//System.out.println(i);
			if(i!=len) System.out.println(0);
			else System.out.println(1);
		}
	}

	boolean ok(int y, int x){
		return y>=0 && x >=0 && y<n && x<m;
	}
	
	public static void main(String args[]) throws Exception{
		new Main().run();
	}
}

Measured memory_bytes: 17000
//#pragma GCC optimize("Ofast,no-stack-protector")
//#pragma GCC target("avx") 
#include <bits/stdc++.h>

using namespace std;

#define mp make_pair
#define pb push_back
#define makeunique(x) sort(all(x)), (x).resize(unique(all(x)) - (x).begin())
#define re return
#define fi first
#define se second
#define sz(x) ((int) (x).size())
#define all(x) (x).begin(), (x).end()
#define sqrt(x) sqrt(abs(x))
#define y0 y3487465
#define y1 y8687969
#define j0 j5743892
#define j1 j542893
                         
typedef vector<int> vi;
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef double D;
typedef pair<int, int> ii;
typedef vector<ii> vii;
typedef vector<string> vs;
typedef vector<vi> vvi;

template<class T> T abs(T x) { re x > 0 ? x : -x; }
template<class T> T gcd(T a, T b) { re a ? gcd (b % a, a) : b; }
template<class T> T sqr(T a) { re a * a; }
template<class T> T sgn(T a) { re a > 0 ? 1 : (a < 0 ? -1 : 0); }

const double pi = acos(-1.0);

#define filename ""

int n;
int m;

const int N = 510;
int was[N][N], d[N][N];

int main () {
//  freopen (filename".in", "r", stdin);
//  freopen (filename".out", "w", stdout);
    cin >> n;
    vii a(n * n);
    vvi u(n + 10, vi(n + 10));
    for (int i = 0; i < n * n; i++) {
            int z;
            cin >> z; z--;
            int x = z / n, y = z % n;
            a[i] = mp(x + 2, y + 2);
            d[x + 2][y + 2] = min(min(x, y), min(n - x - 1, n - y - 1)) + 1;
            u[x / n + 2][x % n + 2] = i;
        }
    vi dx = {-1, 0, 1, 0};
    vi dy = {0, -1, 0, 1};
    ll ans = 0;
    for (auto start : a) {
        vector <ii> q = {start};
        d[start.fi][start.se] --;
        ans += d[start.fi][start.se];
        was[start.fi][start.se] = 1;
        for (int l = 0; l < sz(q); l++) {
            auto cur = q[l];
            int x = cur.fi, y = cur.se;
            for (int k = 0; k < 4; k++) {
                int nx = x + dx[k], ny = y + dy[k];
                if (d[nx][ny] > d[x][y] + !was[nx][ny]) {
                    q.pb(mp(nx, ny));
                    d[nx][ny] = d[x][y] + !was[nx][ny];
                }
            }
        }
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 12072
#include <bits/stdc++.h> 
using namespace std; 
  
// Function to sort character array b[] 
// according to the order defined by a[] 
void pairsort(unsigned long long int a[],unsigned long long int b[],unsigned long long int n) 
{ 
    pair<unsigned long long int,unsigned long long int> pairt[n]; 
  
    // Storing the respective array 
    // elements in pairs. 
    for (unsigned long long int i = 0; i < n; i++)  
    { 
        pairt[i].first = a[i]; 
        pairt[i].second = b[i]; 
    } 
  
    // Sorting the pair array. 
    sort(pairt, pairt + n); 
      
    // Modifying original arrays 
    for (unsigned long long int i = 0; i < n; i++)  
    { 
        a[i] = pairt[i].first; 
        b[i] = pairt[i].second; 
    } 
} 
int main()
{
    unsigned long long int n,m,i,ans=0;
    cin >> n >> m;
    unsigned long long int a[n],b[n];
    for(i=0;i<n;i++)
    cin >> a[i]>>b[i];
    pairsort(a,b,n);
    for(i=0;i<n;i++)
    {
        if(m==0)
        break;
        else if(m<b[i])
        {
            ans=ans+a[i]*m;
            m=0;
            
        }
        else
        {
            ans=ans+a[i]*b[i];
            m=m-b[i];
        }
    }
    cout << ans;
}

Measured memory_bytes: 3328
mod = 10**9+7
N, K = map(int, input().split())
a = list(map(int, input().split()))
dp = [[0]*(K+1) for i in range(N+1)]
S = [0] * (K+2)
dp[0][0] = 1
for i in range(1,N+1):
    for j in range(1,K+2):
        S[j] = (S[j-1] + dp[i-1][j-1])%mod
    for j in range(K+1):
        dp[i][j] = (S[j+1] - S[max(0, j-a[i-1])])%mod
print(dp[N][K])

Measured memory_bytes: 118384
#include <cstdio>
#include <cctype>
#include <cmath>
#include <cstring>
#include <iostream>
#include <algorithm>
using namespace std;

#define ll long long
#define reg register
#define rep(i, a, b) for (reg int i = (a), i##end = (b); i <= i##end; ++i)
#define dep(i, a, b) for (reg int i = (a), i##end = (b); i >= i##end; --i)

template <typename _typer> inline _typer read() {
    _typer init = 0;
    char ch = getchar(), k = 0;
    for ( ; !isdigit(ch); ch = getchar()) k = (ch == '-');
    for ( ; isdigit(ch); ch = getchar())
        init = (init << 3) + (init << 1) + (ch ^ 48);
    return k ? -init : init;
}
const ll N = 200005, INF = 1e9;
const ll M = 1000005, Mod = 998244353;


int n, A[N];
ll val[M], sum[M], cnt[M];


void Add(int vl, int x) {
//     cerr << vl << " " << x << endl;
    int t = x / vl;
    ((val[vl] += 1ll * sum[vl] * t % Mod) >= Mod && (val[vl] -= Mod));
    ((sum[vl] += t) >= Mod && (sum[vl] -= Mod));
    ((cnt[vl] = (cnt[vl] << 1) + 1) >= Mod && (cnt[vl] -= Mod));
}
void Addition(int x) {
//     cerr << "Addition: " << x << " " << sqrt(x) << endl;
    rep (i, 1, sqrt(x)) if (x % i == 0) {
//         cerr << i << " " << x << endl;
        Add(i, x);
        if (x / i != i) Add(x / i, x);
    }
}

void Del(int x, int y) {
    val[x] -= 1ll * (y / x) * (y / x) % Mod * val[y] % Mod;
    ((val[x] < 0) && (val[x] += Mod));
}

int main() {
    n = read<int>();
    int mx = 0;
    rep (i, 1, n) {
        ((A[i] = read<int>()) >= mx && (mx = A[i]));
        Addition(A[i]);
    }

    ll Ans = 0;
    dep (i, mx, 1) {
//         cerr << i << " " << val[i] << " " << sum[i] << " " << cnt[i] << endl;
        rep (j, 2, mx / i) Del(i, j * i);
//         cerr << i << " " << val[i] << endl;
        ((Ans += 1ll * i * val[i] % Mod) >= Mod && (Ans -= Mod));
    }

//     cerr << Ans << endl;
    printf("%lld\n", Ans);
    return 0;
}



Measured memory_bytes: 24448
#include<iostream>
#include<string>
#include<vector>

using namespace std;

int main(){
	int a,b,c;
	cin>>a>>b>>c;
	
	if(a+b>=b+c){
		if(b+c>=c+a)cout<<c+a<<"\n";
		else cout<<b+c<<"\n";
	}
	else if(a+b<=b+c){
		if(a+b>=a+c)cout<<a+c<<"\n";
		else cout<<a+b<<"\n";
	}

	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, n) for(int i=0; i<(n); ++i)
#define rep2(i, s, n) for(int i=s; i<(n); ++i)
#define ALL(v) (v).begin(), (v).end()

using namespace std;

typedef long long ll;

static const int INTINF = (2147483647 >> 1); // 10^9 + 5000
static const ll LLINF = (9223372036854775807 >> 1);
static const int MAX = 1e5+1;
static const ll MOD = 1e9+7;

namespace Printer{
    template<class T>
    void print(T x){
        cout << x << endl;
    }

    template<class T>
    void print(T x, T y){
        cout << x << "," << y << endl;
    }

    template<class T>
    void print(vector<T> v){
        rep(i, v.size()){
            if(i) cout << " ";
            cout<< v[i];
        }
        cout << endl;
    }

    template<class T>
    void print(vector<vector<T> > vv){
        rep(i, vv.size()){
            rep(j, vv[i].size()){
                if(j) cout << " ";
                cout << vv[i][j];
            }
            cout << endl;
        }
    }

    void print(pair<int, int> p){
        cout << "(" << p.first << ", " << p.second << ")" << endl;
    }
};
using namespace Printer;

//--global--//



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

int bfs(int h,int w, vector<string> vv){
    pair<int, int> start = make_pair(0, 0);
    pair<int, int> goal = make_pair(w-1, h-1);
    int dx[4] = {0, 0, 1, -1};
    int dy[4] = {1, -1, 0, 0};
    int cnt = 0;
    queue<pair<int, int> > q;
    vector<vector<int> > used(h, vector<int>(w));
    rep(i, used.size()){
        fill(ALL(used[i]), 0);
    }
    q.push(make_pair(start.first, start.second));
    bool ok = false;
    while(!q.empty()){
        queue<pair<int, int> > q2;
        while(q.size() > 0){
            pair<int, int> f = q.front(); q.pop();
            int x = f.first;
            int y = f.second;
            if(x == goal.first && y == goal.second) ok = true;
            if(vv[y][x] == '#') continue;
            if(used[y][x] != 0) continue;
            used[y][x] = 1;
            rep(i, 4){ 
                int nx = x + dx[i];
                int ny = y + dy[i];
                if(0<=nx && nx <w && 0<= ny && ny<h){
                    q2.push(make_pair(nx, ny));
                }
            }
        }
        q = q2;
        cnt++;
        if(ok == true) break;
    }

    if(ok == false) return -1;

    return cnt;
}

int main(int argc, const char * argv[]) {
    //提出時、消す----//
    //--------------//

    int h, w;
    vector<string> vv;

    cin >> h >> w;
    int white = 0;
    vv.resize(h);
    rep(i, h){
        cin >> vv[i];
        for(char c : vv[i]){
            if(c == '.'){
                white ++;
            }
        }
    }

    int cnt = bfs(h, w, vv);
    if(cnt == -1) cout << -1 << endl;
    else cout << white - cnt << endl;
    
    
    return 0;
}


Measured memory_bytes: 256
import java.util.Scanner;

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

		int count = 0;
		String inputStr[] = new String[input.length()];
		int currentIndex = 0;
		for(int i = 0; i < input.length(); i++) {
			inputStr[currentIndex]= input.substring(i,i+1);
			if(currentIndex!=0 && !inputStr[currentIndex].equals(inputStr[currentIndex-1])) {
				currentIndex--;
				count+=2;
			}else {
				currentIndex++;
			}
		}
		System.out.println(count);
		sc.close();
	}
}


Measured memory_bytes: 31244
// package com.company;

import java.util.*;
import java.io.*;

public class Main {
    static Scanner input = new Scanner(System.in);

    static boolean ans() {
        int W = input.nextInt();
        int H = input.nextInt();
        int x = input.nextInt();
        int y = input.nextInt();        
        int r = input.nextInt();
        input.close();

        int d1 = W-x;
        int d2 = H-y;
        int d3 = x;
        int d4 = y;

        int[] d = {d1, d2, d3, d4};

        for (int i = 0; i < 4; i ++) {
            if (d[i] < r) return false;
        }
        return true;
    }

    public static void main(String[] args) {
        if (ans()) System.out.println("Yes");
        else System.out.println("No");
    }
}


Measured memory_bytes: 26356
import sys,collections as cl,bisect as bs
sys.setrecursionlimit(100000)
mod = 10**9+7
Max = sys.maxsize
def l(): #intのlist
    return list(map(int,input().split()))
def m(): #複数文字
    return map(int,input().split())
def onem(): #Nとかの取得
    return int(input())
def s(x): #圧縮
    a = []
    aa = x[0]
    su = 1
    for i in range(len(x)-1):
        if aa != x[i+1]:
            a.append([aa,su])
            aa = x[i+1]
            su = 1
        else:
            su += 1
    a.append([aa,su])
    return a
def jo(x): #listをスペースごとに分ける
    return "".join(map(str,x))
def max2(x): #他のときもどうように作成可能
    return max(map(max,x))
def In(x,a): #aがリスト(sorted)
    k = bs.bisect_left(a,x)
    if k != len(a) and a[k] ==  x:
        return True
    else:
        return False
"""
def nibu(x,n,r):
    ll = 0
    rr = r
    while True:
        mid = (ll+rr)//2

    if rr == mid:
        return ll
    if (ここに評価入れる):
        rr = mid
    else:
        ll = mid+1
"""

n = onem()

s = list(input())

k = []

for i in range(len(s)):
    kkk = ord(s[i])
    ppp = kkk+n
    if ppp >= 91:
        ppp = ppp - 91
        ppp = 65 + ppp
    k.append(chr(ppp))
print(jo(k))




Measured memory_bytes: 40816
#include <bits/stdc++.h>
#define RI register int
typedef long long LL;

#define FILEIO(name) freopen(name".in", "r", stdin), freopen(name".out", "w", stdout);

using namespace std;

char buf[1000000], *p1 = buf, *p2 = buf;
inline char gc() {
  if (p1 == p2) p2 = (p1 = buf) + fread(buf, 1, 1000000, stdin);
  return p1 == p2 ? EOF : *(p1++);
}
template <class T> inline void read(T &n) {
  n = 0; RI ch = gc(), f;
  while ((ch < '0' || ch > '9') && ch != '-') ch = gc();
  f = (ch == '-' ? ch = gc(), -1 : 1);
  while (ch >= '0' && ch <= '9') n = n * 10 + (ch ^ 48), ch = gc();
  n *= f;
}

int a[205], G[205][205];
queue <int> q;

int main() {
  
#ifdef LOCAL
  FILEIO("a");
#endif

  int n; read(n);
  for (RI i = 1; i <= n; ++i)
    for (RI j = 1; j <= n; ++j) {
      char ch = gc();
      while (ch != '0' && ch != '1') ch = gc();
      if (ch == '1') G[i][j] = 1;
    }
  int ans = 0;
  for (RI i = 1; i <= n; ++i) {
    memset(a, 0, sizeof(a));
    a[i] = 1;
    q.push(i);
    while (!q.empty()) {
      int t = q.front(); q.pop();
      for (RI i = 1; i <= n; ++i)
        if (G[t][i]) {
          if (!a[i]) a[i] = a[t] + 1, q.push(i);
          else if (abs(a[i] - a[t]) != 1) return puts("-1"), 0;
        }
    }
    for (RI j = 1; j <= n; ++j)
      ans = max(ans, a[j]);
  }
  printf("%d\n", ans);

  return 0;
}

// created by Daniel yuan


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

class Program
{
    static long FibonacciNumber(long[] a, int n)
    {       
        a[0] = 1;
        a[1] = 1;
        
        for(int i = 2; i <= n; i++)
        {
            a[i] = a[i - 1] + a[i - 2];
        }
        return a[n];
    }

    static void Main(string[] args)
    {
        int n = int.Parse(Console.ReadLine());
        long[] a = new long[n + 1];

        Console.WriteLine(FibonacciNumber(a, n));
    }
}


Measured memory_bytes: 17936
import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, tan, asin, acos, atan, radians, degrees, log2, gcd
from itertools import accumulate, permutations, combinations, combinations_with_replacement, product, groupby
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from bisect import bisect, bisect_left, insort, insort_left
from heapq import heappush, heappop
from functools import reduce
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()))
def ZIP(n): return zip(*(MAP() for _ in range(n)))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7 
#mod = 998244353
from decimal import *
#import numpy as np
#decimal.getcontext().prec = 10

N, K = MAP()
A = LIST()

if N == K:
	ans = 1
	for x in A:
		ans = ans*x%mod
	print(ans)
	exit()

a = []
for x in A:
	flg = 0
	if x < 0:
		flg = 1
	a.append([x, abs(x), flg])

a.sort(key = lambda x: -x[1])

#print(a)

flg_sum = sum([x[2] for x in a[:K]])

if flg_sum%2 == 0:
	ans = 1
	for x in a[:K]:
		ans = ans*x[1]%mod
	print(ans)
	exit()


flg = a[K-1][2]
s0 = 0
s1 = 0
for i in range(K, N):
	if a[i][2] != flg:
		s0 = a[K-1][1]
		s1 = a[i][1]
		break

flg = a[K][2]
t0 = 0
t1 = 0
for i in range(K-1, -1, -1):
	if a[i][2] != flg:
		t0 = a[i][1]
		t1 = a[K][1]
		break

if s0+t0 != 0:
	ans = 1
	if s0 == 0:
		for i in range(K):
			if a[i][1] != t0:
				ans = ans*a[i][1]%mod
		print(ans*t1%mod)
		exit()
	elif t0 == 0:
		for i in range(K-1):
			ans = ans*a[i][1]%mod
		print(ans*s1%mod)
		exit()
	elif s1*t0 >= s0*t1 or t0 == 0:
		for i in range(K-1):
			ans = ans*a[i][1]%mod
		print(ans*s1%mod)
		exit()
	else:
		for i in range(K):
			if a[i][1] != t0:
				ans = ans*a[i][1]%mod
		print(ans*t1%mod)
		exit()


ans = 1
for x in a[::-1][:K]:
	ans = ans*x[0]%mod

print(ans)


Measured memory_bytes: 55296
import java.util.*;
public class Main{
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    int n = sc.nextInt();
    int m = sc.nextInt();
    int x = sc.nextInt();
    int c[] = new int[n];
    int a[][] = new int[n][m];
    for(int i = 0;i<n;i++){
      c[i] = sc.nextInt();
      for(int j = 0;j<m;j++){
        a[i][j] = sc.nextInt();
      }
    }

    boolean exist = false;
    int value = 1<<30;
    //bitzenntannsakudeha???
    for(int bit = 0;bit < (1<<n);bit++){
      int tmpvalue = 0;
      int understand[] = new int[m];
      for(int i = 0;i < n;i++){//c ni tuite kakuninn
        int bibi = bit & (1<<i);
        if(bibi != 0){
          tmpvalue += c[i];
          for(int j = 0;j<m;j++){//iroiro kasann
            understand[j] += a[i][j];
          }
        }
      }
      int checkcount = 0;
      for(int i = 0;i<m;i++){
        if(understand[i] >= x){
          checkcount++;
        }
      }
      if(checkcount != m){
        continue;
      }else{//jyoukenn ni tekisiteireba exist -> true nisite,value wo min de
        exist = true;
        value = Math.min(tmpvalue,value);
      }

    }
    if(exist){
      System.out.println(value);
    }else{
      System.out.println(-1);
    }
  }
}


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

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
using P = pair<ll, ll>;
#define rep(i, n) for(ll i=0;i<(ll)(n);i++)
#define rep1(i, n) for(ll i=1;i<=(ll)(n);i++)
#define rep2(i, m, n) for(ll i=m;i<(ll)(n);i++)
#define rrep(i, n, m) for(ll i=n;i>=(ll)(m);i--)
#define ALL(obj) (obj).begin(), (obj).end()
#define MOD 1000000007
#define INF 1000000000

void solve_abc150_b() {
	ll N, ans;
	string S;
	cin >> N >> S;

	ans = 0;
	rep(i, N) {
		if (i + 2 < N) {
			if (S[i] == 'A' && S[i + 1] == 'B' && S[i + 2] == 'C') {
				ans++;
			}
		}
	}

	cout << ans << "\n";
}

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

	solve_abc150_b();

	return 0;
}

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

int main(){
    int n;
    cin >> n;
    bool f = false;
    for(int i = 1; i < 10; i++){
        for(int j = 1; j < 10; j++){
            if(i * j == n) f = true;
        }
    }
    cout << (f ? "Yes" : "No") << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ll long long int
using namespace std;
int main()
{
   int a,b,c[505],i,j,k;
   cin>>a>>b;
   for(i=1;i<=500;i++)
    c[i]=i*i;
   if(b<10)
    k=a*10+b;
   else if(b<100)
    k=a*100+b;
   else
    k=a*1000+b;
   for(i=1;i<=450;i++)
   {
       if(k==c[i])
       {
           cout<<"Yes";
           return 0;
       }
   }
   cout<<"No";
        return 0;
}

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

int main() {
  long n,k,r,s,p,ans=0;
  string t;
  cin >> n >> k >> r >> s >> p >> t;
  for(int i=0;i<n;i++) {
    if(t.at(i)=='r') t.at(i)='p';
    else if(t.at(i)=='p') t.at(i)='s';
    else t.at(i)='r';
  };

  for(int i=0;i<k;i++) {
    for(int j=i+k;j<n;j+=k) {
      if(t.at(j-k)==t.at(j)) t.at(j)='x';
    };
  };
  for(int i=0;i<n;i++) {
    if(t.at(i)=='r') ans+=r;
    else if(t.at(i)=='p') ans+=p;
    else if(t.at(i)=='s') ans+=s;
  };

  cout << ans << endl;
}

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

vector<int> a;
vector<int> dp;
int n;

int ans = INT_MAX;


int go(int i)
{
    if(i == n-1)
        return 0;
   
    int x=INT_MAX, y=INT_MAX;
    
    if(dp[i] != -1)
    {
        return dp[i];
    }
    
    if(i+1 < n)
        x = go(i+1) + abs(a[i] - a[i+1]);
    if(i+2 < n)
        y = go(i+2) + abs(a[i] - a[i+2]);
   
    ans = min(x, y);
    
    dp[i] = ans;
    
    return ans;
}

int main()
{

  cin>>n;
    
  a.resize(n);
    
  for(int i=0; i<n; i++)
      cin>>a[i];
 
  dp.resize(n+1, -1);
   
    cout<<go(0)<<endl;
}

Measured memory_bytes: 5760
#define _CRT_SECURE_NO_WARNINGS
#include<bits/stdc++.h>
#define fi first
#define se second
#define pb push_back
#define E "\n"

using namespace std;
const long long MOD = (long long)1e9 + 7;

string s;
int q, t, f;
char c, ans[300009];
stack<char> stk;
queue<char> qu;
bool flag = false;

int main()
{
	ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
	cin >> s >> q;
	while (q--) {
		cin >> t;
		if (t == 1) flag = !flag;
		else {
			cin >> f >> c;
			if (f == 1) {
				if (flag) qu.push(c);
				else stk.push(c);
			}
			else {
				if (flag) stk.push(c);
				else qu.push(c);
			}
		}
	}
	int cur = 0;
	while (!stk.empty()) {
		ans[cur] = stk.top();
		stk.pop();
		cur++;
	}
	for (int i = 0; i < (int)s.length(); i++) {
		ans[cur++] = s[i];
	}
	while (!qu.empty()) {
		ans[cur++] = qu.front();
		qu.pop();
	}
	if (flag) reverse(ans, ans + cur);
	for (int i = 0; i < cur; i++) {
		cout << ans[i];
	}
	cout << E;
	//system("pause");
	return 0;
}

Measured memory_bytes: 1232
n=int(input())
s=[list(map(int,input().split())) for i in range(n)]
ss=[list(map(int,input().split())) for i in range(n)]
ans=-10**11
for i in range(1,1024):
  status=str("{:b}".format(i)).zfill(10)
  opening=[]
  check=0
  for j in range(10):
    if int(status[j])==1:
      opening.append(j)
  for l in range(n):
    cnt=0
    for k in opening:
      cnt+=s[l][k]
    check+=ss[l][cnt]
  if check>ans:
    ans=check
print(ans)

Measured memory_bytes: 41072
import math
MAX_X = 10**5 + 1000

pt = [True]*MAX_X
pt[0], pt[1] = False, False

for i in range(2, int(math.sqrt(MAX_X))+1):
    for j in range(2*i, MAX_X, i):
       pt[j] = False

primes = [ idx for idx, num in enumerate(pt) if num == True]

X = int(input())

for prime in primes:
    if X <= prime:
        print prime
        break



Measured memory_bytes: 4996
#include <iostream>
#include <array>

#include <cstdio>

using namespace std;

static void printArray(int A[], int N) {
  for (auto i = 0; i < N; i++) {
    cout << (i != 0 ? " " : "") << A[i];
  }
  cout << endl; 
}

static int bubbleSort(int A[], int N) {
  bool flag = true;
  int count = 0, tmp;
  int i = 0;
  while (flag) {
    flag = false;
    for (auto j = N - 1; j > i; j--) {
      if (A[j] < A[j - 1]) {
	tmp = A[j - 1];
	A[j - 1] = A[j];
	A[j] = tmp;
	flag = true;
	count++;
      }
    }
    i++;
  }
  return count;
}

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

  array<int, 100> A;
  for (auto i = 0; i < N; i++) {
    scanf("%d", &A[i]);
  }

  auto count = bubbleSort(A.data(), N);
  printArray(A.data(), N);
  cout << count << endl;

  return 0;
}



Measured memory_bytes: 3252
import java.io.*;

public class Main {
    public static void main(String[] args) {
        int[] abc;
        try (InputScanner is = new InputScanner(System.in)) {
            abc = is.nia(3);
        }
        System.out.println(abc[2] + " " + abc[0] + " " + abc[1]);

    }

    //-------------------------------------------------------------------
    public static class InputScanner implements Closeable {
        private final BufferedReader br;
        private String[] element;
        private int elementIndex;

        public InputScanner(InputStream is) {
            this.br = new BufferedReader(new InputStreamReader(is));
        }

        public String next() {
            return this.nextElement();
        }

        //next int
        public int ni() {
            return Integer.parseInt(this.nextElement());
        }

        //next long
        public long li() {
            return Long.parseLong(this.nextElement());
        }

        //next int array
        public int[] nia(int n) {
            int[] arr = new int[n];
            for (int i = 0; i < n; i++) {
                arr[i] = this.ni();
            }
            return arr;
        }

        private void readLine() {
            try {
                this.element = this.br.readLine().split("\\s");
            } catch (IOException e) {
                e.printStackTrace();
            }
            this.elementIndex = 0;
        }

        private String nextElement() {
            if (!hasElement()) {
                this.readLine();
            }
            return this.element[this.elementIndex++];
        }

        private boolean hasElement() {
            return this.element != null && this.element.length > this.elementIndex;
        }

        @Override
        public void close() {
            if (this.br != null) {
                try {
                    this.br.close();
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
        }
    }
//-------------------------------------------------------------------
}


Measured memory_bytes: 21332
#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<n;i++)
#define per(i,n) for(int i=n;i>0;i--)
#define rep1(i,s,n) for(int i=s;i<n;i++)
#define max0(a,b,c) max(max(a,b),c)
#define min0(a,b,c) min(min(a,b),c) 
using namespace std;
using Graph = vector<vector<int>>;
typedef long long lint;
typedef long long ll;
typedef long double ldouble;
typedef vector<int> vec;
typedef vector<ll> lvec;
typedef vector<pair<int,int>> pvec;
typedef vector<pair<ll,ll>> plvec;

int main(){
   int n;
   cin>>n;
   plvec p(n);
   rep(i,n){
      ll a,b;
      cin>>a>>b;
      p[i]=make_pair(b,a);
   }
   sort(p.begin(),p.end());
   bool flag=true;
   ll count=0;
   rep(i,n){
      count+=p[i].second;
      if(count>p[i].first){
         flag=false;
         break;
      }
   }
   if(flag) cout<<"Yes";
   else cout<<"No";
}

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


int main(void) {
  int x;
  cin >> x;

  if (x >= 30) {
    cout << "Yes" << endl;
  } else {
    cout << "No" << endl;
  }
  
  return 0;
}

Measured memory_bytes: 3616
def genStr(s,i)
  t = ""
  (s.size-i).times do |idx|
    t += s[idx]
  end
  return t
end

N = gets.to_i
s = gets.chomp
t = gets.chomp

i = 0
ans = 0
while(true)do
  u = genStr(s,i) + t
  if /^#{s}/ =~ u && /#{t}$/ =~ u then
    ans = u.size
  end
  i += 1
  break if i > N
end

puts ans

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

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

string s;
cin>>s;

int diff = 0;
for(int i=1;i<s.length();i++){
	if(s[i] != s[i-1]){

		diff++ ;
	}
}
	
if(diff == 0)
	cout<<0;
else
	cout<<diff;
	
}



Measured memory_bytes: 512
#include <cstdio>
#include <vector>
#include <queue>
#include <algorithm>
#include <set>
#include <map>

using namespace std;

int main() {
    int n, m, a, b, ans = 0;
    scanf("%d%d", &n, &m);
    vector< vector<int> > e(n + 1);
    for (int i = 0; i < m; ++i) {
        scanf("%d%d", &a, &b);
        e.at(a).push_back(b);
        e.at(b).push_back(a);
    }
    queue< pair< set<int>, int > > q;
    q.push({{1}, 1});
    while (!q.empty()) {
        auto t = q.front();
        q.pop();
        if (t.first.size() == n) {
            ++ans;
            continue;
        }
        for (auto i = e.at(t.second).begin(); i != e.at(t.second).end(); ++i) if (t.first.find(*i) == t.first.end()) {
                auto s = t;
                s.first.insert(*i);
                s.second = *i;
                q.push(s);
        }
    }
    printf("%d\n", ans);
    return 0;
}


Measured memory_bytes: 2432
S = input()
T = input()
t_len = len(T)
s_len = len(S)
index = 0
if t_len > s_len:
    print("UNRESTORABLE")
    exit()
for i in range((s_len - 1) - (t_len - 1), -1, -1):
    for j in range(t_len):
        if S[i + j] == "?":
            continue
        if S[i + j] != T[j]:
            break
    else:
        index = i
        break
    continue
else:
    print("UNRESTORABLE")
    exit()
S = list(S)
for i in range(s_len):
    if S[i] == "?":
        S[i] = 'a'
S[index:index + t_len] = T
print("".join(S))
#print(S)



Measured memory_bytes: 61816
#include <cmath>
#include <iostream>
#include <cstdio>
using namespace std;

typedef long long ll;
int main() {
    ll a, b, x;
    cin >> a >> b >> x;
    ll ans = b/x;
    ll tmp = a/x;
    if (a % x == 0)ans++;
    printf("%lld\n", ans-tmp);
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
const int N = 1e5 + 100;
vector<int> adj[N];
bool use[N], win;
int n;
void dfs(int v, int p) {
	for (auto u : adj[v]) {
		if (u == p)
			continue;
		dfs(u, v);
		if (!use[u]) {
			if (!use[v]) {
				use[u] = true;
				use[v] = true;
			}
			else
				win = true;
		}
	}
}

int main() {
	ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0);
	cin >> n;
	for (int i = 1; i < n; i++) {
		int v, u;
		cin >> v >> u;
		adj[--v].push_back(--u);
		adj[u].push_back(v);	
	}
	dfs(0, 0);
	return cout << ((win || !use[0]) ? "First" : "Second"), 0;
}

Measured memory_bytes: 5888
#include<bits/stdc++.h>
#define ll long long
#define pii pair<int,int>
#define pll pair<ll,ll>
#define vii vector<int>
#define vll vector<ll>
#define lb lower_bound
#define pb push_back
#define mp make_pair
#define rep(i,n) for(ll i=0;i<n;i++)
#define rep2(i,a,b) for(ll i=a;i<b;i++)
#define repr(i,n) for(ll i=n-1;i>=0;i--)
#define all(x) x.begin(),x.end()
// #define int ll
using namespace std;
const int INF (1 << 30);
const ll LLINF (1LL << 55LL);
const int MOD = 1000000007;
const int MAX = 510000;
const double pi=3.14159265358979;

ll fac[MAX], finv[MAX], inv[MAX];
ll POW[MAX];

ll extgcd(ll a, ll b, ll& x, ll& y){
    ll d=a;
    if(b != 0){
        d = extgcd(b, a%b, y, x);
        y -= (a/b) * x;
    }
    else{
        x=1;y=0;
    }
    return d;
}

void POWinit(){
    POW[0]=0;
    POW[1]=1;
    for(ll i=2;i<MAX;i++){
        POW[i]=POW[i-1]*i;
        POW[i]%=MOD;
    }
}


// テーブルを作る前処理
void COMinit() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (ll i = 2; i < MAX; i++){
        fac[i] = fac[i - 1] * i % MOD;
        inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
        finv[i] = finv[i - 1] * inv[i] % MOD;
    }
}

// 二項係数計算
ll COM(ll n, ll k){
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}

ll mod_inverse(ll a,ll mod){
    ll x,y;
    extgcd(a,mod,x,y);
    return (mod+x%mod)%mod;
}

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll n,k,ans[1010]={},res=0;
    cin>>n>>k;
    COMinit();
    POWinit();
    if(n<=k){
        cout<<1<<endl;
        return  0;
    }
    else{
        cout<<0<<endl;
        return 0;
    }
    return 0;
}


Measured memory_bytes: 19052
/*
[abc128] D - equeue
*/

#include <algorithm>
#include <cassert>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
using namespace std;
typedef long long int ll;
typedef pair<int, int> pii;
typedef pair<ll, int> pli;
typedef pair<ll, ll> pll;

const int MAX_N = 50;
const int INF = 1e9;

int N, K;
int V[MAX_N];

ll solve() {
    ll ans = -INF;
    for (int p = 0; p <= N; p++) {
        for (int q = 0; p + q <= min(N, K); q++) {
            vector<int> d;
            for (int i = 0; i < p; i++) {
                d.push_back(V[i]);
            }
            for (int i = N - 1; i >= N - q; i--) {
                d.push_back(V[i]);
            }
            sort(d.begin(), d.end(), greater<int>());

            ll s = 0;
            for (int i = 0; i < p + q; i++) {
                if (d[i] <= 0 && p + q - i <= K - p - q) {
                    break;
                }
                s += d[i];
            }
            ans = max(ans, s);
        }
    }

    return ans;
}

int main() {
    cin >> N >> K;
    for (int i = 0; i < N; i++) {
        cin >> V[i];
    }

    cout << solve() << endl;

    return 0;
}


Measured memory_bytes: 256
import numpy as np
from itertools import combinations

n, d = map(int, input().split())
x = np.empty((n, d), dtype=np.int64)
for i in range(n):
    x[i] = [int(i) for i in input().split()]

res = 0
for i, j in combinations(range(n), 2):
    if (np.sum((x[i]-x[j])**2)**0.5).is_integer():
        res += 1
print(res)


Measured memory_bytes: 12408
#include <iostream>
#include <iomanip>
#include <algorithm>
#include <vector>

template<typename T> 
void getmat(std::vector<std::vector<T>> &mat,unsigned n,unsigned m)
{
	for (int i = 0; i < n; i++) {
		std::vector<T> v;
		for (int i = 0; i < m; i++) {
			double n;
			std::cin >> n;
			v.push_back(n);
		}
		mat.push_back(v);
	}
}
template<typename T> 
void printmat(std::vector<std::vector<T>> mat)
{
	for (auto&& v : mat) {
		bool b{false};
		for (auto&& n : v) {
			if (b) std::cout << " ";
			b = true;
			std::cout << n ;
		}
		std::cout << std::endl;
	}
}

int main(int argc, char const* argv[])
{
	int n, m, l;
	std::vector<std::vector<unsigned long>> a, b, c;
	std::cout << std::fixed;
	std::cin >> n >> m >> l;
	getmat(a, n, m);
	getmat(b, m, l);
	c.resize(n);
	for (int i = 0; i < n; i++) {
		c[i].resize(l);
		for (int j = 0; j < l; j++) {
			for (int k = 0; k < m; k++) {
				c[i][j] += a[i][k] * b[k][j];
			}
		}
	}
	printmat(c);

	return 0;
}

Measured memory_bytes: 3444
#include <bits/stdc++.h>
using namespace std;
#define REP(i, n) for(int i = 0; i < n; i++)
#define REPR(i, n) for(int i = n - 1; i >= 0; i--)
#define FOR(i, m, n) for(int i = m; i <= n; i++)
#define FORR(i, m, n) for(int i = m; i >= n; i--)
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
#define VSORTR(v) sort(v.rbegin(), v.rend());
#define ALL(v) (v).begin(),(v).end()
 
using ll = long long;
using vll = vector<ll>;
using vvll = vector<vector<ll>>;
using P = pair<ll, ll>;

template<typename T> using min_priority_queue = priority_queue<T, vector<T>, greater<T>>;
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }

const ll mod = 1e9 + 7;
const ll inf = 1e18;

ll n, m, q;
ll res = 0;
vll a(55), b(55), c(55), d(55);

void dfs(int id, int cur, vll& v) {
        if (id == n) {
            ll mem = 0;
            REP(i, q) {
                if (v[b[i]] - v[a[i]] == c[i]) mem += d[i];
            }
            chmax(res, mem);
        }
        else {
            // v[id + 1] を [cur, m] から自由に決めることを再帰的に繰り返す
            for (int nxt = cur; nxt <= m; nxt++) {
                v[id + 1] = nxt;
                dfs(id + 1, nxt, v);
            }
        }
    };

int main(){
	cin.tie(0);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(10);

    cin >> n >> m >> q;
    REP(i, q) {
        cin >> a[i] >> b[i] >> c[i] >> d[i];
        a[i]--, b[i]--;
    }
    vll v(n, 1);
    dfs(0, 1, v);
    cout << res << endl;
    return 0;
}

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

int main(){
  int N;
  cin >> N;
  vector<int> vec(N);
  for(int i=0; i<N; i++){
    cin >> vec.at(i);
  }
  
  int answer=0;
  for(int i=0; i<N; i++){
    if(i==N-1){
      break;
    }
    for(int j=i+1; j<N; j++){
      answer += vec.at(i)*vec.at(j);
    }
  }
  cout <<answer<<endl;
  return 0;
}

Measured memory_bytes: 256