akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
int main(){
    ios_base::sync_with_stdio(false) ;
    cin.tie(NULL) ;
    string s = "" , t = "" , ans = "" ;
    cin >> s >> t ;
    int slen = s.size() , tlen = t.size() , lcs[slen+1][tlen+1] ;
    for(int i = 0 ; i <= slen ; i++)
        for(int j = 0 ; j <= tlen ; j++)
            lcs[i][j] = 0 ;
    for(int i = 1 ; i <= slen ; i++){
        for(int j = 1 ; j <= tlen ; j++){
            if(s[i-1] == t[j-1]) lcs[i][j] = lcs[i-1][j-1] + 1 ;
            else lcs[i][j] = max(lcs[i-1][j] , lcs[i][j-1]) ;
        }
    }
    int i = slen , j = tlen ;
    while(i > 0 && j > 0){
        if(s[i-1] == t[j-1]) ans += s[i-1] , i-- , j-- ;
        else if(lcs[i-1][j] > lcs[i][j-1]) i-- ;
        else j-- ;
    }
    for(int i = ans.size()-1 ; i >= 0 ; i--) 
        cout << ans[i] ;
}

Measured memory_bytes: 38804
import bisect
import collections
import sys
import heapq

sys.setrecursionlimit(100000)
input = sys.stdin.readline
ACMOD = 1000000007
INF = 1 << 32


def lmi():
    return list(map(int, input().split()))


def llmi(n):
    return [lmi() for _ in range(n)]


N = int(input())
A = lmi()

lq = []  # normal
hq = []  # * -1
for a in A[:N]:
    heapq.heappush(lq, a)
for a in A[2 * N:]:
    heapq.heappush(hq, - a)

dpl = [0 for _ in range(N + 1)]  # middle をNまで消費したときの (a′の前半N要素の総和)
dph = [0 for _ in range(N + 1)]  # middle をNまで消費したときの (a′の後半N要素の総和)

middle = A[N:2 * N]
dpl[0] = sum(A[:N])
last_val = dpl[0]
for count in range(1, N + 1):
    heapq.heappush(lq, middle[count - 1])
    v = heapq.heappop(lq)
    dpl[count] = dpl[count - 1] - v + middle[count - 1]

dph[N] = sum(A[2 * N:])
for count in reversed(range(N)):
    heapq.heappush(hq, -middle[count])
    v = -  heapq.heappop(hq)  # bigger value
    dph[count] = dph[count + 1] - v + middle[count]


print(max(dpl[i] - dph[i] for i in range(N+1)))


Measured memory_bytes: 117520
n = int(input())
h = list(map(int,input().split()))
for i in range(n-2,0,-1):
    if h[i] - h[i+1] == 1:
        h[i] -= 1
        #print(i)
    elif h[i] <= h[i+1]:    
        pass
    else:
        print("No")
        exit()
#print(h)
print("Yes")

Measured memory_bytes: 63984
{-# LANGUAGE FlexibleContexts #-}
{-# LANGUAGE UnboxedTuples #-}
{-# LANGUAGE OverloadedStrings #-}
{-# LANGUAGE BangPatterns #-}
{-# LANGUAGE LambdaCase #-}
{-# LANGUAGE ViewPatterns #-}
{-# LANGUAGE TupleSections #-}
{-# LANGUAGE MultiWayIf #-}

import Control.Monad
import Control.Monad.ST
import Control.Monad.State
import Control.Monad.Primitive
import Control.Applicative
import Control.Arrow
import Data.List
import Data.Array
import Data.Array.IO
import Data.Array.ST
import Data.IORef
import Data.STRef
import Data.Maybe
import Data.Bits
import Data.Ord
import Data.Ratio
import Data.Int
import Data.Char
import qualified Data.ByteString.Char8 as BS
import qualified Data.Set as Set
import qualified Data.Vector as V
import qualified Data.Vector.Mutable as VM
import qualified Data.Vector.Unboxed as VU
import qualified Data.Vector.Unboxed.Mutable as VUM
import Data.Tuple
import Data.Function
import Text.Printf
import Debug.Trace
import Numeric

modifyArray arr i f = readArray arr i >>= \x -> writeArray arr i (f x)

listToTuple2 [a,b] = (a,b)
listToTuple3 [a,b,c] = (a,b,c)
listToTuple4 [a,b,c,d] = (a,b,c,d)
listToTuple5 [a,b,c,d,e] = (a,b,c,d,e)

readIntBS = fst . fromJust . BS.readInt

for = flip map

infixr 1 ?
(?) :: Bool -> (a,a) -> a
(?) b t = (if b then fst else snd) t

main :: IO ()
main = do
  [n,k] <- map read . words <$> getLine :: IO [Integer]

  print $ if odd k then
            (length $ filter ((==0) . (`mod`k)) [1..n]) ^ 3
          else
            (length $ filter ((==0) . (`mod`k)) [1..n]) ^ 3 + (length $ filter ((==(k`div`2)) . (`mod`k)) [1..n]) ^ 3
  


Measured memory_bytes: 892
//============================================================================
// Name        : filename.cpp
// Author      : abb
// Version     :
// Copyright   : [My copyright notice]
// Description : test program
//============================================================================

/*
C - Typical Stairs

実行時間制限: 2 sec / メモリ制限: 1024 MB

配点 : 300 点

問題文
N 段の階段があります。高橋君は現在、上り口(0 段目)にいます。
高橋君は一歩で 1 段か 2 段上ることができます。
ただし、a_1, a_2, a_3, ....a_M 段目の床は壊れており、その段に足を踏み入れることは危険です。
壊れている床を踏まないようにしながら、最上段(N 段目)にたどりつくまでの移動方法は何通りあるでしょうか？
総数を 1, 000, 000, 007 で割った余りを求めてください。

制約

・1 <= N <= 10^5
・0 <= M <= N-1
・1 <= a_1 < a_2 < ... < a_M <= N-1

 */

#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")

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

using ll = long long;
using ull = unsigned long long;

#define REP(i, m, n) for (ll i = (m); i < (ll)(n); ++(i))
#define REPM(i, m, n) for (ll i = (m); i <= (ll)(n); ++(i))
#define REPR(i, m, n) for (ll i = (m); i >= (ll)(n); --(i))
#define REPD(i, m, n, d) for (ll i = (m); i < (ll)(n); i += (d))
#define REPMD(i, m, n, d) for (ll i = (m); i <= (ll)(n); i += (d))
#define ALL(x) begin(x), end(x)

/**
 * エントリポイント．
 * @return 0.
 */
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);

    const ll mod = 1e9 + 7;

    ll m, n, a;
    cin >> n >> m;
    vector<bool> ok(n, true); // i 段目を ok[i-1] に入れる
    REP(i, 0, m)
    {
        cin >> a;
        ok[a - 1] = false;
    }

    vector<ll> dp(n + 1, 0LL);
    dp[0] = 1;
    dp[1] = ok[0] ? 1 : 0;
    REP(i, 2, n + 1)
    {
        if (ok[i - 1])
        {
            dp[i] = (dp[i - 2] + dp[i - 1]) % mod;
            // cerr << "+" << dp[i] << endl;
        }
    }
    cout << dp[n] << endl;
    return 0;
}


Measured memory_bytes: 1024
fun main() {
    val n = readLine()!!.toInt()
    val list = List(n){
        readLine()!!.toInt()
    }.sorted()
    var cnt = 1

    for (i in 0..n-2){
        if (list[i]<list[i+1]){
            cnt++
        }
    }
    println(cnt)
}

Measured memory_bytes: 39436
/*Atcoder.83 B--some sums,200'*/ 
#include<iostream>
using namespace std;
int main()
{
	int n,a,b,sum=0,total=0;
	cin>>n>>a>>b;
	for(int i=1;i<=n;i++)
	{
		int p=i;
		sum=0;
		while(p!=0)
		{
			sum+=p%10;
			p/=10;
		}
		if(sum>=a&&sum<=b)total+=i;
	}
	cout<<total;
	return 0;
}

Measured memory_bytes: 256
S = input()

def stringChecker(S):
    if S[0] != 'A':
        return False
    cnt = 0
    for l in S[2:-1]:
        if l == 'C':
            cnt += 1
    if cnt != 1:
        return False
    
    lower_cnt = 0
    for l in S:
        if l.islower():
            lower_cnt += 1
    if lower_cnt != len(S) - 2:
        return False
    
    return True
if stringChecker(S):
    print('AC')
else :
    print('WA')

Measured memory_bytes: 3064
#include <stdio.h>
int main(){
	int a,b,n;
	scanf("%d%d%d",&a,&b,&n);
	for(int i=0;i<n;i++){
		int x,y;
		scanf("%d%d",&x,&y);
		if((a<=x&&x<b) || (a<y&&y<=b) || (x<a&&b<=y)){puts("1");return 0;}
	}
	puts("0");
}

Measured memory_bytes: 1816
#include <bits/stdc++.h>
using namespace std;
//#pragma GCC optimize("Ofast")
#define rep(i,n) for(long long i=0;i<(long long)(n);i++)
#define REP(i,k,n) for(long long i=k;i<(long long)(n);i++)
#define all(a) a.begin(),a.end()
#define eb emplace_back
#define lb(v,k) (lower_bound(all(v),k)-v.begin())
#define ub(v,k) (upper_bound(all(v),k)-v.begin())
#define fi first
#define se second
#define pi M_PI
#define PQ(T) priority_queue<T>
#define SPQ(T) priority_queue<T,vector<T>,greater<T>>
using ll=long long;
using P=pair<ll,ll>;
using PP=tuple<ll,ll,ll>;
using S=multiset<ll>;
using vi=vector<ll>;
using vvi=vector<vi>;
using vvvi=vector<vvi>;
const ll inf=1001001001001001;
const int INF=1001001001;
const int mod=1000000007;
const double eps=1e-10;
template<class T> bool chmin(T&a,T b){if(a>b){a=b;return true;}return false;}
template<class T> bool chmax(T&a,T b){if(a<b){a=b;return true;}return false;}
template<class T> void out(T a){cout<<a<<'\n';}
template<class T> void outp(T a){cout<<'('<<a.fi<<','<<a.se<<')'<<'\n';}
template<class T> void outvp(T v){rep(i,v.size())cout<<'('<<v[i].fi<<','<<v[i].se<<')';cout<<'\n';}
template<class T> void outv(T v){rep(i,v.size()){if(i)cout<<' ';cout<<v[i];}cout<<'\n';}
template<class T> void outvv(T v){rep(i,v.size())outv(v[i]);}
template<class T> bool isin(T x,T l,T r){return (l)<=(x)&&(x)<=(r);}
template<class T> void YesNo(T b){if(b)out("Yes");else out("No");}
void decimal(int x){cout<<fixed<<setprecision(x);}
ll GCD(ll a,ll b){if(b==0) return a; return GCD(b,a%b);}
ll LCM(ll a,ll b){return(a/GCD(a,b))*(b/GCD(a,b))*GCD(a,b);}
ll POW(ll a,ll b){a%=mod;if(b==0)return 1;if(b&1)return a*POW(a,b-1)%mod;ll k=POW(a,b/2);return k*k%mod;}
vi calc(ll x){vi res;while(x>0){res.eb(x%10);x/=10;}reverse(all(res));return res;}

void solve(){
  vi lucas={2,1};
  REP(i,2,100){
    lucas.eb(lucas[i-2]+lucas[i-1]);
  }
  ll n; cin>>n;
  out(lucas[n]);
}

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


Measured memory_bytes: 256
#include<stdio.h>
#include<math.h>

#define FALSE 0
#define TRUE 1

struct point
{
	double x;
	double y;
};

void initialize(double array[], int n);
double calculate_edge(double edge[], double x1, double y1, double x2, double y2, double x3, double y3, double x4, double y4);
double helon(double edge1, double edge2, double edge3);
int judge(double area[]);
void output(int flag);
main()
{
	struct point a = {0, 0};
	struct point b = {0, 0};
	struct point c = {0, 0};
	struct point d = {0, 0};
	int flag = 0;
	double edge[6]; //辺の長さを代入する為の配列
	double area[4]; //面積を代入する為の配列
	initialize(edge, 6);
	initialize(area, 4);
	
	while(scanf("%lf,%lf,%lf,%lf,%lf,%lf,%lf,%lf", &a.x, &a.y, &b.x, &b.y, &c.x, &c.y, &d.x, &d.y) != EOF)
	{
		calculate_edge(edge, a.x, a.y, b.x, b.y, c.x, c.y, d.x, d.y);
		area[0] = helon(edge[0], edge[1], edge[2]);
		//printf("area[0] = %lf\n", area[0]);
		area[1] = helon(edge[0], edge[3], edge[5]);
		//printf("area[1] = %lf\n", area[1]);
		area[2] = helon(edge[1], edge[3], edge[4]);
		//printf("area[2] = %lf\n", area[2]);
		area[3] = helon(edge[2], edge[4], edge[5]);
		//printf("area[3] = %lf\n", area[3]);
		flag = judge(area);
		output(flag);
		initialize(edge, 6);
	initialize(area, 4);
	}
	return 0;
}

void initialize(double array[], int n)
{
	int i = 0;
	for(i = 0; i < n; i++)
	{
		array[i] = 0;
	}
}

double calculate_edge(double edge[], double x1, double y1, double x2, double y2, double x3, double y3, double x4, double y4)
{
	edge[0] = sqrt(pow(x1 - x4, 2) + pow(y1 - y4, 2));
	edge[1] = sqrt(pow(x2 - x4, 2) + pow(y2 - y4, 2));
	edge[2] = sqrt(pow(x1 - x2, 2) + pow(y1 - y2, 2));
	edge[3] = sqrt(pow(x3 - x4, 2) + pow(y3 - y4, 2));
	edge[4] = sqrt(pow(x2 - x3, 2) + pow(y2 - y3, 2));
	edge[5] = sqrt(pow(x1 - x3, 2) + pow(y1 - y3, 2));
}

double helon(double edge1, double edge2, double edge3)
{
	double s = (edge1 + edge2 + edge3) / 2;
	double result = sqrt(s * (s - edge1) * (s - edge2) * (s - edge3));
	return result;
}
int judge(double area[])
{
	int i = 0, j = 0, temp = 0;
	for(i = 0; i < 4; i++)
	{
		for(j = i; j < 4; j++)
		{
			if(area[i] < area[j])
			{
				temp = area[i];
				area[i] = area[j];
				area[j] = temp;
			}
		}
	}
	
	if(area[0] < (area[1] + area[2] + area[3]))
	{
		return TRUE;
	}
	else
	{
		return FALSE;
	}
}
void output(int flag)
{
	if(flag == TRUE)
	{
		puts("YES");
	}
	else
	{
		puts("NO");
	}
}

Measured memory_bytes: 608
#include<bits/stdc++.h>
 
#define rep(i,n) for(ll i = 0;i < n;++i)
#define all(v) v.begin(),v.end()
using namespace std;
using ll = long long;
typedef pair<int,int> P;
 
const int INF = 1001001001;
const long double PI = (acos(-1));
const int mod = 1e9+7;
const int vx[6] = {0,1,0,-1,1,-1};
const int vy[6] = {1,0,-1,0,1,1};




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

    string x;
    cin >> x;
    ll ans = 0;
    ll sum = 0;
    rep(i,x.length()){
        if(x[i] == 'S'){
            sum++;
        }else if(sum > 0){
            sum--;
        }else {
            ans++;
        }
    }
    ans += sum;
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 720
#include <cstdio>
#include <cstdlib>
#include <cassert>
#include <algorithm>
#include <functional>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
#define repi(i,a,b) for(ll i=(a);i<(b);++i)
#define rep(i,a) repi(i,0,a)
#define itr(it,a) for( auto it = (a).begin(); it != (a).end(); ++it )
#define all(a) (a).begin(), (a).end()
#define rall(a) (a).rbegin(), (a).rend()

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

using ll = long long;
using P = std::pair<ll, ll>;

ll N;
ll A[2010];
ll dp[2010][2010];
std::vector<P> ps;

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

  rep( i, N )
  {
    std::cin >> A[i];

    ps.emplace_back( A[i], i );
  }

  std::sort( rall(ps) );

  rep( i, N+1 ) rep( j, N+1 )
  {
    auto p = ps[i+j];

    chmax( dp[i+1][j], dp[i][j]+p.first*llabs(i-p.second) );
    chmax( dp[i][j+1], dp[i][j]+p.first*llabs(N-1-j-p.second) );
  }

  ll ans = 0;

  rep( i, N+1 )
    chmax( ans, dp[i][N-i] );

  std::cout << ans << std::endl;

  return 0;
}

Measured memory_bytes: 34720
#include<stdio.h>
#define ANS(x, y, z) printf("%d %d %d\n", (x), (y), (z))

int main(void)
{
    int a, b, c; scanf("%d %d %d", &a, &b, &c);
    
    if ( a <= b) {
        if ( b <= c)
            ANS(a, b, c);
        else if ( c <= a)
            ANS(c, a, b);
        else
            ANS(a, c, b);
    }else if( c <= b)
        ANS(c, b, a);
    else if( a <= c)
        ANS(b, a, c);
    else
        ANS(b, c, a);
        
    return 0;
}


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

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

  if (S == "SUN")
    cout << 7 << endl;
  else if (S == "MON")
    cout << 6 << endl;
  else if (S == "TUE")
    cout << 5 << endl;
  else if (S == "WED")
    cout << 4 << endl;
  else if (S == "THU")
    cout << 3 << endl;
  else if (S == "FRI")
    cout << 2 << endl;
  else if (S == "SAT")
    cout << 1 << endl;

  return 0;
}

Measured memory_bytes: 3588
#include <stdio.h>

int main(void){
	int r,g,b,num;
	r = 0;
	g = 0;
	b = 0;
	num = 0;
	scanf("%d%d%d",&r,&g,&b);
	
	num = r*100 + g*10 + b;
	
	if(num%4 == 0){
		printf("YES");
	}else{
		printf("NO");
	}
	return 0;
}

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

int main(void) {
  string X;
  cin >> X;
  deque<char> deq;
  for (int i = 0; i < X.length(); i++) {
    if (deq.size() == 0) {
      deq.push_back(X[i]);
    } else {
      char top = deq.back();
      if (top == 'S' && X[i] == 'T') {
        deq.pop_back();
      } else {
        deq.push_back(X[i]);
      }
    }
  }
  cout << deq.size() << endl;
  return 0;
}

Measured memory_bytes: 644
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <string>
#include <cstring>
#include <deque>
#include <list>
#include <queue>
#include <stack>
#include <vector>
#include <utility>
#include <algorithm>
#include <map>
#include <set>
#include <complex>
#include <cmath>
#include <limits>
#include <climits>
#include <ctime>
#include <cassert>
using namespace std;

#define rep(i,a,n) for(int i=a; i<n; i++)
#define repq(i,a,n) for(int i=a; i<=n; i++)
#define repr(i,a,n) for(int i=a; i>=n; i--)
#define pb(a) push_back(a)
#define fr first
#define sc second
#define INF 2000000000
#define int long long int

#define X real()
#define Y imag()
#define EPS (1e-10)
#define EQ(a,b) (abs((a) - (b)) < EPS)
#define EQV(a,b) ( EQ((a).X, (b).X) && EQ((a).Y, (b).Y) )
#define LE(n, m) ((n) < (m) + EPS)
#define LEQ(n, m) ((n) <= (m) + EPS)
#define GE(n, m) ((n) + EPS > (m))
#define GEQ(n, m) ((n) + EPS >= (m))

typedef vector<int> VI;
typedef vector<VI> MAT;
typedef pair<int, int> pii;
typedef long long ll;

typedef complex<double> P;
typedef pair<P, P> L;
typedef pair<P, double> C;

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

namespace std {
    bool operator<(const P& a, const P& b) {
        return a.X != b.X ? a.X < b.X : a.Y < b.Y;
    }
}

struct UnionFind {
    // union-find木
    int uf[100010];
    int rank[100010];

    // 初期化
    void init(int n) {
        rep(i,0,n) {
            uf[i] = i;
            rank[i] = 0;
        }
    }

    // find (木の根を求める)
    int find(int x) {
        if(uf[x] == x) return x;
        else return uf[x] = find(uf[x]);
    }

    // x と y の属する集合を併合
    void unite(int x, int y) {
        x = find(x);
        y = find(y);
        if(x == y) return;

        if(rank[x] < rank[y]) uf[x] = y;
        else {
            uf[y] = x;
            if(rank[x] == rank[y]) rank[x]++;
        }
    }

    // x と y が同じ集合に属するかどうか
    bool same(int x, int y) {
        return find(x) == find(y);
    }
};

signed main() {
    int n, m, k; cin >> n >> m;
    int l;
    UnionFind uf;
    uf.init(n);

    vector<int> a[100010];
    rep(i,0,n) {
        cin >> k;
        rep(j,0,k) {
            cin >> l; l--;
            a[l].pb(i);
            // cout << a[l].size() << endl;
        }
    }

    rep(i,0,m) {
        // cout << a[i].size() << endl;
        rep(j,1,a[i].size()) {
            uf.unite(a[i][0], a[i][j]);
            // printf("%lld %lld\n", a[i][0], a[i][j]);
        }
    }

    int prev = -1;
    rep(i,0,n) {
        // cout << a[i].size() << endl;
        // if(a[i].size() == 0) continue;
        int p = uf.find(i);
        // printf("test: %lld %lld\n", a[i].size() , p);
        if(prev == -1) prev = p;
        else if(prev != -1 && prev != p) {
            cout << "NO" << endl;
            return 0;
        }
    }
    cout << "YES" << endl;
    return 0;
}

Measured memory_bytes: 5500
#include<iostream>
#include<cstdlib>
#include<cstring>
#include<stack>
#include<queue>
#include<algorithm>
#include<vector>
#include<math.h>
#include<bitset>
#include<iomanip>
using namespace std;

typedef stack<int> IntStack;
typedef queue<int> IntQueue;

const double pi = 3.141592653589793;


//文字0~9をint型0~9に変換
int char_to_int(char c)
{
	if (c == '0') return 0;
	if (c == '1') return 1;
	if (c == '2') return 2;
	if (c == '3') return 3;
	if (c == '4') return 4;
	if (c == '5') return 5;
	if (c == '6') return 6;
	if (c == '7') return 7;
	if (c == '8') return 8;
	if (c == '9') return 9;
	else return -1;
}
//a^b mod MODを計算
long long int ModPower(long long int a, long long int b, long long int MOD)
{
	if (b == 0) return 1;
	else if (b % 2 == 0)
	{
		long long int d = ModPower(a, b / 2, MOD);
		return (d*d) % MOD;
	}
	else
	{
		return (a*ModPower(a, b - 1, MOD)) % MOD;
	}
}
//nCr mod MODを計算
long long int ModCombi(long long int n, long long int r, long long int MOD)
{
	if (n == 0 || r == 0) return 1;

	long long int Kn=1, Kr=1, Knr=1;

	long long int temp = 1;
	for (long long int i = 1; i <= n; i++)
	{
		temp *= i;
		temp %= MOD;
		if (i == n) Kn = temp;
		if (i == r) Kr = temp;
		if (i == n - r) Knr = temp;
	}

	long long int x = ModPower(Kr, MOD - 2, MOD);
	long long int y = ModPower(Knr, MOD - 2, MOD);

	long long int ans;
	ans = Kn * x;
	ans %= MOD;
	ans *= y;
	ans %= MOD;

	return ans;
}


/*ここまでテンプレ*//*ここまでテンプレ*//*ここまでテンプレ*//*ここまでテンプレ*/



int main()
{
	int N, K;
	long int V[50];

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

	int ans = 0;

	for (int A = 0; A <= min(N,K); A++)
	{
		for (int B = 0; B <= min(N,K)-A; B++)
		{
			int W[50];
			for (int i = 0; i < A; i++)
			{
				W[i] = V[i];
			}
			for (int i = 0; i < B; i++)
			{
				W[A + i] = V[N - 1 - i];
			}

			sort(W, W + A + B);
			
			for (int i = 0; i < K-A-B; i++)
			{
				if (W[i] < 0) W[i] = 0;
			}

			int sum = 0;

			for (int i = 0; i < A+B; i++)
			{
				sum += W[i];
			}

			ans = max(ans, sum);
		}
	}

	cout << ans;

	return 0;
}

Measured memory_bytes: 256
import core.bitop;
import std.algorithm;
import std.array;
import std.ascii;
import std.container;
import std.conv;
import std.format;
import std.math;
import std.random;
import std.range;
import std.stdio;
import std.string;
import std.typecons;

void main()
{
  int n = readln.chomp.to!int;
  int[] a = readln.chomp.split.map!(to!int).array;
  std.algorithm.sort(a);
  int[] b = readln.chomp.split.map!(to!int).array;
  std.algorithm.sort(b);
  int[] c = readln.chomp.split.map!(to!int).array;
  std.algorithm.sort(c);
  ulong[ulong] memo;
  foreach (i, v; b) {
    memo[i] = c.assumeSorted.upperBound(v).length;
  }
  memo[n] = 0;
  foreach_reverse (i; 0..n) {
    memo[i] += memo[i + 1];
  }
  ulong cnt = 0;
  foreach (v; a) {
    // use v
    ulong len = b.assumeSorted.upperBound(v).length;
    cnt += memo[n - len];
    /+
    foreach (w; find!"a > b"(b, v)) {
      // use w
      cnt += find!"a > b"(c, w).length;
    }
    +/
  }
  cnt.writeln;
}


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

namespace _0038
{
    class Program
    {
        static void Main(string[] args)
        {
            int[] card = new int[5];
            string str = "";
            Poker poker = new Poker();
            while (!((str = Console.ReadLine()) == null))
            {
                card = str.Split(',').Select(int.Parse).ToArray();
                Array.Sort(card);
                Console.WriteLine(poker.Post(card));
            }
        }
    }
    class Poker
    {
        //one pair と two pair の定義に不足あり
        public string Post(int[] card)
        {
            if (card[0] == card[2])
            {
                if (card[1] == card[3])
                {
                    return "four card";
                }
                else if (card[3] == card[4])
                {
                    return "full house";
                }
                else
                {
                    return "three card";
                }
            }
            else if (card[1] == card[3])
            {
                if (card[2] == card[4])
                {
                    return "four card";
                }
                else
                {
                    return "three card";
                }
            }
            else if (card[2] == card[4])
            {
                if (card[0] == card[1])
                {
                    return "full house";
                }
                else
                {
                    return "three card";
                }
            }
            else if (card[0] == card[1])
            {
                if (card[2] == card[3] || card[3] == card[4])
                {
                    return "two pair";
                }
                else
                {
                    return "one pair";
                }
            }
            else if(card[1]==card[2])
            {
                if (card[3] == card[4])
                {
                    return "two pair";
                }
                else
                {
                    return "one pair";
                }
            }
            else if (card[2] == card[3])
            {
                return "one pair";
            }
            else if (card[3] == card[4])
            {
                return "one pair";
            }
            else if (card[0] + 4 == card[4])
            {
                return "straight";
            }
            else if (card[0] == 1 && card[1] == 10)
            {
                return "straight";
            }
            else
            {
                return "null";
            }
        }
    }
}



Measured memory_bytes: 14308
#include <bits/stdc++.h>
using namespace std;
#define endl '\n'
#define int long long
#define SPEED ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
signed main()
{
    SPEED;
    int n;
    cin>>n;
    if(n%2==1)
    {
        cout<<0;
    }
    else
    {
        int c=0,j=5,temp;
        while(j<=n)
        {
            temp=n/j;
            temp/=2;
            c+=temp;
            j*=5;
        }
        cout<<c;
    }
}

Measured memory_bytes: 256
program dice_and_coin
  implicit none
  integer :: n, k, d, i, j
  real(8) :: x = 0.d0, p
  character(64) :: s
  read(*,*) n, k
  do i = 1, n
    d = i
    p = 1.d0
    do while (d < k)
      d = lshift(d,1)
      p = 0.5d0*p
    end do
    x = x+p
  end do
  write(s,'(f32.16)') x/real(n,8)
  write(*,'(a)') trim(adjustl(s))
end program dice_and_coin

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

int main() {
  int N;
  cin >> N;
  vector<int> A(N);
  vector<int> B(N);
  vector<int> C(N - 1);
  for (int i = 0; i<N;i++) {
    cin >> A.at(i);
  }
  for (int i=0;i<N;i++) {
    cin >> B.at(i);
  }
  for (int i=0;i<N-1;i++) {
    cin >> C.at(i);
  }
  int count = B.at(A.at(0) - 1);
  for (int i =1; i < N; i++) {
    count += B.at(A.at(i) - 1);
    if (A.at(i - 1) + 1 == A.at(i)) {
      count += C.at(A.at(i - 1) -1);
    }
  }
  cout << count <<endl;
}

Measured memory_bytes: 256
n, d = map(int, input().split())
A = []
for i in range(n):
    a = list(map(int, input().split()))
    A.append(a)

def dstnc(X, Y):
    res = 0
    for l, x in enumerate(X):
        res += (x - Y[l])**2
    return res


ans = 0
for i in range(n - 1):
    for j in range(i + 1, n):
        su = dstnc(A[i], A[j])**0.5
        if str(su)[-1] == "0" and str(su)[-2] == ".":
            ans += 1
print(ans)


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

class Program
{
    static void Main(string[] args)
    {
        var N = sc.ReadInt();
        var A = sc.ReadIntArray(N);
        var map = new HashMap<long, int>();
        long sum = 0;
        for (int i = 0; i < N; i++)
        {
            sum += A[i];
            map[sum]++;
        }
        sum = 0;
        long ans = 0;
        long zero = 0;
        for (int i = 0; i < N; i++)
        {
            sum += A[i];
            ans += map[sum] - 1;
            if (sum == 0) zero++;
        }
        ans /= 2;
        ans += zero;
        Console.WriteLine(ans);
    }
    static Scanner sc = new Scanner();
}

class Scanner
{
    string[] S = new string[0];
    int Index = 0;
    char[] Separators = new char[] { ' ' };

    public string Next()
    {
        if (this.Index < this.S.Length) return this.S[this.Index++];
        var line = "";
        while (line == "") line = Console.ReadLine();
        this.S = line.Split(this.Separators, StringSplitOptions.RemoveEmptyEntries);
        if (this.S.Length == 0) return this.Next();
        this.Index = 0;
        return this.S[this.Index++];
    }
    public string ReadStr()
    {
        return this.Next();
    }
    public char ReadChar()
    {
        return this.Next()[0];
    }
    public int ReadInt()
    {
        return int.Parse(this.Next());
    }
    public uint ReadUInt()
    {
        return uint.Parse(this.Next());
    }
    public long ReadLong()
    {
        return long.Parse(this.Next());
    }
    public double ReadDouble()
    {
        return double.Parse(this.Next());
    }
    public int[] ReadIntArray(int n)
    {
        var array = new int[n];
        for (int i = 0; i < array.Length; i++)
        {
            array[i] = this.ReadInt();
        }
        return array;
    }
    public long[] ReadLongArray(int n)
    {
        var array = new long[n];
        for (int i = 0; i < array.Length; i++)
        {
            array[i] = this.ReadLong();
        }
        return array;
    }
    public double[] ReadDoubleArray(int n)
    {
        var array = new double[n];
        for (int i = 0; i < array.Length; i++)
        {
            array[i] = this.ReadDouble();
        }
        return array;
    }
    public char[] ReadCharArray(int n)
    {
        var array = new char[n];
        for (int i = 0; i < array.Length; i++)
        {
            array[i] = this.ReadChar();
        }
        return array;
    }
    public string[] ReadStrArray(int n)
    {
        var array = new string[n];
        for (int i = 0; i < array.Length; i++)
        {
            array[i] = this.ReadStr();
        }
        return array;
    }
}

class HashMap<K, V> : Dictionary<K, V> where V : new()
{
    private V DefaltValue = new V();
    public HashMap() { }
    public HashMap(V defaultValue)
    {
        this.DefaltValue = new V();
    }
    new public V this[K i]
    {
        get
        {
            V v;
            return TryGetValue(i, out v) ? v : base[i] = this.DefaltValue;
        }
        set { base[i] = value; }
    }
}

Measured memory_bytes: 42832
import sys
 
stdin = sys.stdin
inf = 1 << 60
mod = 1000000007
 
ni = lambda: int(ns())
nin = lambda y: [ni() for _ in range(y)]
na = lambda: list(map(int, stdin.readline().split()))
nan = lambda y: [na() for _ in range(y)]
ns = lambda: stdin.readline().rstrip()
nsn = lambda y: [ns() for _ in range(y)]
ncl = lambda y: [list(ns()) for _ in range(y)]
nas = lambda: stdin.readline().split()

n = ni()
x = na()

ans = inf
for i in range(100):
    l = 0
    for j in range(n):
        l += (x[j] - i) ** 2
    ans = min(ans, l)

print(ans)

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

long mod = 1000000007;
typedef struct mint
{
    ll x;
    mint(ll x = 0) : x(x % mod) {} //コンストラクタ
    /* 演算子オーバーロード */
    mint &operator+=(const mint a)
    {
        if ((x += a.x) >= mod)
            x -= mod;
        return *this;
    }
    mint &operator-=(const mint a)
    {
        if ((x += mod - a.x) >= mod)
            x -= mod;
        return *this;
    }
    mint &operator*=(const mint a)
    {
        (x *= a.x) %= mod;
        return *this;
    }
    mint operator+(const mint a) const
    {
        mint res(*this);
        return res += a;
    }
    mint operator-(const mint a) const
    {
        mint res(*this);
        return res -= a;
    }
    mint operator*(const mint a) const
    {
        mint res(*this);
        return res *= a;
    }
    mint pow(ll t) const
    {
        if (!t)
            return 1;
        mint a = pow(t >> 1);
        a *= a;
        if (t & 1)
            a *= *this;
        return a;
    }
    // for prime mod
    mint inv() const
    {
        return pow(mod - 2);
    }
    mint &operator/=(const mint a)
    {
        return (*this) *= a.inv();
    }
    mint operator/(const mint a) const
    {
        mint res(*this);
        return res /= a;
    }
} mint_t;


mint dp[100001][13] = {0};

int main()
{
    string s;
    cin >> s;

    int num = s.size();
    mint ans(0);
    int div = 1;
    dp[0][0] = 1;

    rep(i, num){
        char x = s[num-1-i];
        //cout << x << endl;
        rep(j, 13){
            if (x == '?'){
                rep(k, 10){
                    dp[i+1][j] += dp[i][(j + 13 - ((div * k)%13))%13];
                }
            } else {
                dp[i+1][j] = dp[i][(j +13- ((div * (int)(x - '0'))%13))%13];
            }
        }
        div *= 10;
        div %= 13;
    }

    // rep(i, num+1){
    //     rep(j, 13){
    //         cout << dp[i][j] << " ";
    //     }
    //     cout << endl;
    // }
    cout << dp[num][5].x << endl;
}


Measured memory_bytes: 10624
// soon the majic is going to happen !
#include <bits/stdc++.h>
using namespace std;
const int N = 1234567;
const int mod = 1e9+7;
typedef long long ll;
#define mp make_pair
#define pb push_back
#define inf 1e18
int vis[N],dis[N];
vector<int>g[N];
int main()
{
	// ios_base:: sync_with_stdio(false); cin.tie(0);
	// freopen ("inp","r",stdin);
	// freopen ("out","w",stdout);
	int n,m,a,b;
	cin>>n>>m;
	for(int i=0;i<m;i++)
	{
		cin>>a>>b;
		g[a].pb(b);
		g[b].pb(a);
	}
	queue<int>q;
	q.push(1);
	dis[1]=0;
	while(!q.empty())
	{
		int front  = q.front();
		q.pop();
		for(int next : g[front])
		{
			if(!vis[next])
			{
				vis[next]=1;
				q.push(next);
				dis[next]=dis[front]+1;
			}
		}
	}
	if(dis[n]==2)
		cout<<"POSSIBLE\n";
	else
		cout<<"IMPOSSIBLE\n";
	return 0;
}

Measured memory_bytes: 40432
#include <iostream>
#include <iomanip>
#include <vector>
#include <valarray>
#include <map>
#include <set>
#include <list>
#include <queue>
#include <stack>
#include <bitset>
#include <utility>
#include <numeric>
#include <algorithm>
#include <functional>
#include <complex>
#include <string>
#include <sstream>

#include <cstdio>
#include <cstdlib>
#include <cctype>
#include <cstring>
#include <cmath>

using namespace std;

#define all(c) c.begin(),c.end()
#define repeat(i,n) for(int i=0;i<static_cast<int>(n);i++)
#define debug(x) #x << "=" << (x)
#define dump(x) cerr << debug(x) << " (L:" << __LINE__ << ")"<< endl

typedef long long ll;
typedef vector<int> vi;
typedef vector<vector<int> > vvi;
typedef vector<long> vl;
typedef vector<vector<long> > vvl;
typedef vector<string> vs;

template<typename T>
ostream& operator<<(ostream& os, const vector<T>& vec){
    os << "[";
    for(int i = 0; i < vec.size(); i++){
        os << vec[i] << ",";
    }
    os << "]";
    return os;
}

template<typename T>
T input(){
    T t;
    cin >> t;
    return t;
}

template<typename T>
vector<T> input(const int N){
    vector<T> v(N);
    repeat(i,N) cin >> v[i];
    return v;
}

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

long long lcm(long long a, long long b){
    return (a / gcd(a, b)) * b;
}

long long mul(const long long& a, const long long& b, const long long& mod) {
    return ((a % mod) * (b % mod)) % mod;
}

long long power(const long long& x, const long long& y, const long long& mod) {
    if (y == 0) {
        return 1;
    } else if (y == 1) {
        return x % mod;
    } else {
        long long value = power(x, y / 2, mod);
        if (y % 2 == 0) {
            return mul(value, value, mod);
        } else {
            return mul(value, value, mod) * x % mod;
        }
    }
}

long long div(const long long& a, const long long& b, const long long& mod) {
    return mul(a, power(b, mod - 2, mod), mod);
}

map<long long, long long> factorials;
long long factorial(const long long& n, const long long& mod) {
    if (n == 0 || n == 1) {
        return 1;
    }
    if (factorials[n] != 0) {
        return factorials[n];
    }
    factorials[n] = n * factorial(n - 1, mod) % mod;
    return factorials[n] % mod;
}

long long combination(const long long& n, const long long& x, const long long& mod) {
    long long numerator = 1;
    long long denominator = 1;
    repeat(i, x) {
        numerator *= (n - i) % mod;
        numerator %= mod;
        denominator *= (i + 1) % mod;
        denominator %= mod;
    }
    return div(numerator, denominator, mod);
}

int main(){
    int A, B, T;
    cin >> A >> B >> T;
    
    int total = 0;
    for (int t = A; t < T + 0.5; t += A) {
        total += B;
    }
    cout << total << endl;
    return 0;
}


Measured memory_bytes: 384
#include<stdio.h>
int main()
{
    int a,b,c,d,e,i,count=0;
    int x[10];
       for(i=1;i<=5;i++){
            scanf("%d",&x[i]);
        if(x[i]==0){
                printf("%d",i);
        }
    }
 
 
}


Measured memory_bytes: 1708
#include<bits/stdc++.h>
#include<cstring>
#include<cmath>
#include<iterator>
#include<cstdlib>
#define IOS   ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define ses   "\n"
#define whp   " "
#define mxi 99999

#define rep0(i,a,b) for(int i=a; i<b; i++)
#define rep1(i,a,b) for(int i=a; i<=b; i++)
#define rep0in(i,a,b) for(int i=a-1; i>=b; i--)
#define rep1in(i,a,b) for(int i=a; i>b; i--)
#define repv(i,a) for(auto i=a.begin(); i!=a.end();++i)

///set <int, greater <int> > ::iterator it;
///vector<pair<int,int> >a;
#define MS(a,b) memset(a,b,sizeof(a));

typedef long long ll;
typedef unsigned long long ull;
using namespace std;
ll fx[4]= {1,-1,0,0};
ll fy[4]= {0,0,1,-1};
int smallest(int x, int y, int z)
{
    int c = 0;
    while (x && y && z) {
        x--;
        y--;
        z--;
        c++;
    }
    return c;
}
bool rs(ll a, ll b){
    return(a>b);

    }
int main()
{
    ll n;cin>>n;
    vector<ll>v;
    vector<char>vna;



    if(n<26){
        cout<<char('a'+n-1)<<endl;;
    }
    else{
    for(ll i=26; i<=n ; i=i+((i+1)*26)-i){

        v.push_back(i);

    }
    ll ans=0;
    for(ll i=0; i<v.size(); i++){
        if(n==v[i]){
            ans=i;
            break;
        }
    }

    if(ans!=0){
        ans++;
        while((ans)--)cout<<'z';
        cout<<endl;
    }
    else{
        while(n>26){
            ll r=n%26;
            n=n/26;

            char ch;
            if(r==0){ch='z';n--;}
            else
            ch=char('a'+r-1);

            vna.push_back(ch);
        }
        if(n>0)
        {
            char ch=char ('a'+n-1);
            cout<<ch;
        }


        for(ll i=vna.size()-1; i>=0; i--){
            cout<<vna[i];
        }
        cout<<endl;

    }
    }
return 0;
}


Measured memory_bytes: 3632
#include<bits/stdc++.h>
#define r(i,n) for(int i=0;i<n;i++)
using namespace std;
typedef pair<int,int>P;
typedef pair<P,P>P2;

int dp[111][111][1<<5];
int n,m,e,s,t,r;

vector<P>v[100000];

signed main(){
  r(i,111)r(j,1<<5)r(k,111)dp[i][k][j]=1e9;
  cin>>n>>m>>e>>s>>t>>r;

  r(i,m){
    int a,b;
    cin>>a>>b;
    v[a].push_back(P(b,-1));
    v[b].push_back(P(a,-1));
  }

  map<int,int>M;
  int state=0;

  r(i,e){
    int a,b,c;
    cin>>a>>b>>c;
    v[a].push_back(P(b,i));
    v[b].push_back(P(a,i));

    M[c] = i;
    if(c==s)state|=(1<<i);
  }

  priority_queue<P2,vector<P2>,greater<P2> > q;

  q.push(P2(P(0,s),P(r,state))); /// warning

  dp[s][r][state]=0;

  while(!q.empty()){
    P2 PP=q.top();q.pop();

    int now=PP.first.second;
    int cost=PP.first.first;
    int R = PP.second.first;
    int S = PP.second.second;

    // cout<<cost<<' '<<now<<' '<<R<<' '<<S<<endl;

    if(dp[now][R][S] < cost)continue;

    // cout<<cost<<' '<<now<<' '<<R<<' '<<S<<endl;

    if(R){
      r(i,v[now].size()){
	int nex = v[now][i].first;
	int flag = v[now][i].second;

	int f=flag%100;
	int nR=R-1;

	int nS = S;
	if(M.count(nex))nS= (nS|(1<<M[nex]));

	if(flag == -1){

	  if(dp[nex][nR][nS] <= cost+1)continue;
	  dp[nex][nR][nS] = cost+1;
	  q.push(P2(P(cost+1,nex),P(nR,nS)));
	}
	else{
	  if(!(S&(1<<f)))continue;

	  if(dp[nex][nR][nS] <= cost+1)continue;
	  dp[nex][nR][nS] = cost+1;
	  q.push(P2(P(cost+1,nex),P(nR,nS)));
	}
      }
    }

    if(dp[s][r][S] <= cost+1)continue;
    dp[s][r][S] = cost+1;
    q.push(P2(P(cost+1,s),P(r,S)));
  }


  int ans= 1e9;

  r(i,101)r(j,(1<<5)){
    ans=min(ans,dp[t][i][j]);
  }

  if(ans==1e9)cout<<-1<<endl;
  else cout<<ans<<endl;

  
  
  
}



Measured memory_bytes: 7116
#include<iostream>
#include<vector>
#include<algorithm>
#include<cmath>
#include<string>
#include<set>
#include<climits>
#include<map>
#define ll long long
using namespace std;
int main() {
	ll n, a, b;
	cin >> n >> a >> b;
	vector<string>s(n+1);
	vector<ll>sum(n + 1);
	for (ll i = 1; i <= n; i++) {
		s[i] = to_string(i);
		for (ll j = 0; j < s[i].size(); j++) {
			sum[i] += s[i][j] - '0';
		}
		//cout << i<<" "<<sum[i] << endl;
	}
	ll x = 0;
	for (ll i = 1; i <= n; i++) {
		if (sum[i] >= a && sum[i] <= b) {
			x += i;
		}
	}
	cout << x << endl;

}

Measured memory_bytes: 896
#include<bits/stdc++.h>
#define  pb push_back
#define  xx first
#define  yy second
#define ll long long
using namespace std;

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


      int n,k;

      cin >> n >> k;
      ll a[n+10];
      for(int i = 1; i<=n; i++){
        cin >> a[i];
      }
      if(k>=n){
        cout << "0" << endl;return 0;
      }

      sort(a+1,a+1+n);
      for(int i=n,j=1; j<=k; i--,j++)
          a[i] = 0;
      ll sum  = 0;
      for(int i = 1; i<=n; i++) sum +=a[i];
      cout << sum << endl;

   return 0;
}


Measured memory_bytes: 1792
def cmb(n, r, mod):
    if (r < 0 or r > n):
        return 0
    r = min(r, n - r)
    return g1[n] * g2[r] * g2[n - r] % mod


mod = 10**9 + 7  
N = 10**6 #出力の制限
g1 = [1, 1]  # 元テーブル
g2 = [1, 1]  #逆元テーブル
inverse = [0, 1]  #逆元テーブル計算用テーブル

for i in range(2, N + 1):
    g1.append((g1[-1] * i) % mod)
    inverse.append((-inverse[mod % i] * (mod // i)) % mod)
    g2.append((g2[-1] * inverse[-1]) % mod)


X,Y = map(int,input().split())

a = Y - (X+Y) // 3
b = X - (X+Y) // 3

if a < 0 or b < 0 or (X + Y) % 3 != 0:
    print(0)
    exit()


print(cmb(a+b,a,mod))


Measured memory_bytes: 127688
#include <bits/stdc++.h>
using namespace std;
using lint = long long;

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

  int a;
  cin >> a;
  cout << a + a * a + a * a * a << "\n";
  return 0;  
}


Measured memory_bytes: 3632
A,B,M=map(int,input().split())
a = list(map(int,input().split()))
b = list(map(int,input().split()))
xyc=[list(map(int,input().split())) for i in range(M)]
ans = []
for i in range(M):
  ans.append(a[xyc[i][0]-1]+b[xyc[i][1]-1]-xyc[i][2])
mi=min(a)+min(b)
print(min(min(ans),mi))

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

int main() {
  int N;
  cin >> N;
  vector<int> P(N);
  for (int i=0; i<N; i++)
    cin >> P.at(i);
  
  int sum=0, ave;
  for (int i=0; i<N; i++)
    sum+=P.at(i);
  ave=sum/N;
  
  int A1, A2;
  for (int i=0; i<N; i++) {
    A1+=pow((P.at(i)-ave), 2);
    A2+=pow((P.at(i)-ave-1), 2);
  }
  
  int answer=min(A1, A2);
  
  cout << answer << endl;
}

Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<map>
#include<math.h>
#include<queue>
#include<deque>
#include<stack>
#include<cstdio>
#include<utility>
#include<set>
#include<list>
#include<cmath>
#include<stdio.h>
#include<string.h>
#include<iomanip>
using namespace std;
#define FOR(i, a, b) for (ll i = (a); i <= (b); i++)
#define REP(i, n) FOR(i, 0, n - 1)
#define NREP(i, n) FOR(i, 1, n)
using ll = long long;
using pii = pair<int, int>;
using piii = pair<pii, pii>;
const int dx[4] = { 0, -1, 1, 0 };
const int dy[4] = { -1, 0, 0, 1 };
const int INF = 1e9 + 7;
int gcd(int x, int y) {
	if (x < y)swap(x, y);
	if (y == 0)return x;
	return gcd(y, x%y);
}

template<class T1, class T2> void chmin(T1 &a, T2 b) { if (a>b)a = b; }

template<class T1, class T2> void chmax(T1 &a, T2 b) { if (a<b)a = b; }
template<class T>
void Add(T &a, const T &b, const T &mod = 1000000007) {
	int val = ((a % mod) + (b % mod)) % mod;
	if (val < 0) { val += mod; }
	a = val;
}
////////////////////////////////////////
struct UnionFind {
	vector<int>par;
	vector<int>sz;
	ll ans;

	UnionFind(int n=0) {
		if(n>0)initialize(n);
	}

	void initialize(int n) {
		par.resize(n);
		sz.resize(n);
		for (int i = 0; i < n; ++i) {
			par[i] = i;
			sz[i] = 1;
		}
		ans = (ll)n * (n - 1) / 2;
	}

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

	void unite(int x, int y) {
		int rx = find(x);
		int ry = find(y);
		if (rx == ry)return;
		ans -= (ll)sz[rx] * sz[ry];
		if (sz[rx] > sz[ry]) {
			par[ry] = par[rx];
			sz[rx] += sz[ry];
		}
		else {
			par[rx] = par[ry];
			sz[ry] += sz[rx];
		}
	}

	bool same(int x, int y) {
		return find(x) == find(y);
	}
};

int main() {
	int N, M;
	cin >> N >> M;
	int a[100100], b[100100];
	for (int i = 0; i < M; ++i) {
		cin >> a[i] >> b[i];
		a[i]--; b[i]--;
	}
	UnionFind uf(N);
    ll  key[100100];
	for (int i = M - 1; i >= 0; --i) {
		key[i] = uf.ans;
		uf.unite(a[i], b[i]);
	}
	for (int i = 0; i < M; ++i) {
		cout << key[i] << endl;
	}
	return 0;
}



Measured memory_bytes: 3712
def primeFactorize(n):
    if n > 1:
        prime_factors = []
        while n % 2 == 0:
            n //= 2 
            # n is divisible by 2 so 'n //= 2' is equal to 
            # 'n /= 2'. but '//=' returns an integer, whereas 
            # '/=' returns a float.
            prime_factors.append(2)
        
        # n cannot be a even number at this point. 
        # so range is from 3 to int(n**0.5), but step is 2.
        for i in range(3, int(n**0.5)+1, 2):
            while n % i == 0:
                n //= i 
                prime_factors.append(i)
            if n == 1: # otherwise, n > i.
                return prime_factors
        # if n != 1, n > i(int(n**0.5) or int(n**0.5)-1).
        # (i == int(n**0.5) if int(n**0.5) is an odd number.)
        # (i == int(n**0.5)-1 if int(n**0.5) is an even number.)
        prime_factors.append(n)
        return prime_factors
    else:
        return []


def findPrimeNumbers(n):
    # return a list of prime numbers less than or equal to n.
    prime_numbers = [2]
    for i in range(3, n+1, 2):

        for j in prime_numbers:
            if i % j == 0:
                break
        else:
            prime_numbers.append(i)

    return prime_numbers

mod = 10 ** 9 + 7
N = int(input())

prime_factors_of_the_factorial_of_n = []
for i in range(1, N+1):
    prime_factors_of_the_factorial_of_n += primeFactorize(i)

count_of_each_prime_number = []
for i in findPrimeNumbers(N):
    count_of_each_prime_number.append(
        prime_factors_of_the_factorial_of_n.count(i)
    )


ans = 1
for c in count_of_each_prime_number:
    ans *= c + 1

print(ans % mod)


Measured memory_bytes: 3064
//////////////////////////
//      _        ____   //
//  U  /"\  u U /"___|  //
//   \/ _ \/  \| | u    //
//   / ___ \   | |/__   //
//  /_/   \_\   \____|  //
//   \\    >>  _// \\   //
//  (__)  (__)(__)(__)  //
//  Compro by NULL_CT©  //
//////////////////////////
// STL libs
#include <algorithm>
#include <array>
#include <bits/stdint-intn.h>
#include <bitset>
#include <cctype>
#include <chrono>
#include <climits>
#include <cmath>
#include <complex>
#include <cstdint>
#include <cstdio>
#include <cstdlib>
#include <deque>
#include <functional>
#include <iomanip>
#include <ios>
#include <iostream>
#include <iterator>
#include <map>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <thread>
#include <tuple>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>

// Boost
#include <boost/multiprecision/cpp_int.hpp>
#include <boost/range/irange.hpp>

#define ALL(LIST) (LIST.begin()), (LIST.end())

using namespace std;
using boost::irange;
using boost::multiprecision::cpp_int;

constexpr int64_t MOD = 1000000007;

vector<int64_t> divisor(const int64_t &_n) {
  vector<int64_t> head, tail;
  for (int64_t i = 1; i * i <= _n; i++) {
    if (_n % i == 0) {
      head.push_back(i);
      if (i * i != _n)
        tail.push_back(_n / i);
    }
  }
  head.insert(head.end(), tail.rbegin(), tail.rend());
  return head;
}

int64_t kadanes(const vector<int64_t> &_ls) {
  int64_t highestMax = 0, currentMax = 0, length = _ls.size();
  for (int64_t i = 0; i < length; i++) {
    currentMax = max(_ls[i], currentMax + _ls[i]);
    highestMax = max(highestMax, currentMax);
  }
  return highestMax;
}

void execution();

int main() {
  cin.tie(nullptr);
  ios::sync_with_stdio(false);
  // cout<<fixed<<setprecision(20);

  execution();
  return 0;
}

//--------------------------------------------------------------
void execution() {
  int n;
  cin>>n;
  vector<pair<int,int>> d(n);
  for(int i:irange(n)){
    cin>>d[i].first>>d[i].second;
  }

  int cnt=0;
  for(auto i:d){
    if(i.first == i.second){
      cnt++;
    }else{
      cnt=0;
    }
    if(3 <= cnt){
      cout<<"Yes\n";
      return;
    }
  }
  cout<<"No\n";
}


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

int main(){
	string s, ss;
	int v[8][8];
	while(cin >> s){
		int sx = -1, sy = -1;
		if(s[0] == '\n')cin >> s;
		for(int i = 0;i < 8;i++)v[0][i] = s[i]-'0';
		for(int i = 1;i < 8;i++){
			cin >> s;
			for(int j = 0;j < 8;j++)v[i][j] = s[j] - '0';
		}
		
		for(int i = 0;i < 8&&sx==-1;i++){
			for(int j = 0;j < 8&&sx==-1;j++){
				if(v[i][j]){sy = i;sx = j;}
			}
		}
		
		char ans = 'a';
		if(sx<7 && v[sy][sx+1]){//A,C,E,G
			if(sx<6){
				if(v[sy][sx+2])ans = 'C';
				else if(sy<7&&v[sy+1][sx+2])ans = 'E';
			}
			if(0<sx && sy<7 && v[sy+1][sx-1])ans = 'G';
			if(ans == 'a')ans = 'A';
		}else{
			if(0<sx && v[sy+1][sx-1])ans = 'D';
			if(sx<7 && v[sy+1][sx+1])ans = 'F';
			if(ans == 'a')ans = 'B';
		}
		cout << ans << endl;
	}
	return 0;
}

Measured memory_bytes: 3088
import java.util.Scanner;

public class Main {

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

		// 整数の入力
		int N = sc.nextInt();
		int K = sc.nextInt() - 1;
		String S = sc.next();

		char[] c = S.toCharArray();
		String low = String.valueOf(c[K]).toLowerCase();
		c[K] = low.toCharArray()[0];

		System.out.println(String.valueOf(c));

		sc.close();
	}
}


Measured memory_bytes: 21716