akhauriyash/Code-Regression huggingface dataset:
#include <stdio.h>

#define N 100000

int partition(int *, int, int);
void swap(int *x, int *y){
  int temp;
  temp = *x;
  *x = *y;
  *y = temp;
}

int main(){
  int n, i, a[N], b;
  scanf("%d",&n);
  for(i = 0; i < n; i++){
    scanf("%d",&a[i]);
  }

  b = partition(a,0,n-1);

  for(i = 0; i < n-1; i++){
    if(i == b){
      printf("[%d] ",a[i]);
      continue;
    }
    printf("%d ",a[i]);
  }
  printf("%d\n",a[i]);

  return 0;
}

int partition(int *a, int p, int r){
  int i, j;
  int x = a[r];
  i = p-1;
  for(j = p; j < r; j++){
    if(a[j] <= x){
      i = i + 1;
      swap(&a[i],&a[j]);
    }
  }
  swap(&a[i+1],&a[r]);
  return i+1;
}



Measured memory_bytes: 2096
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
#define rep(i, n) for(int i = 0; i < (int)(n); ++i)
#define rrep(i, n) for(int i = (int)(n); i>=0; --i)
struct fast_ios { fast_ios(){cin.tie(0); ios::sync_with_stdio(false); cout << fixed << setprecision(20);} } fast_ios_;

int main()
{
    int N;
    cin >> N;
    vector<int> syain(N);
    
    rep(i, N-1)
    {
        int a;
        cin >> a;
        syain[a-1]++;
    }

    rep(i, N)
    {
        cout << syain[i] << endl;
    }
    return 0;
}

Measured memory_bytes: 3992
import math
import itertools
from collections import defaultdict

def primes(n):
    is_prime = [True] * (n + 1)
    is_prime[0] = False
    is_prime[1] = False
    for i in range(2, int(n**0.5) + 1):
        if not is_prime[i]:
            continue
        for j in range(i * 2, n + 1, i):
            is_prime[j] = False
    return [i for i in range(n + 1) if is_prime[i]]


N = int(input())
# N = 100
anslist = []

primelist = primes(N)

for p in primelist:
    tmp = 0
    i = 1
    while True:
        tmp2 = math.floor(N/(p**i))
        if tmp2 == 0:
            break
        else:
            tmp += tmp2
            i += 1
    anslist.append(tmp)

# print(primelist)
# print(anslist)
# print("------")

ans = []

pqrlist = [[4,4,2],[14,4,0],[24,2,0],[74,0,0]]

combs = list(itertools.permutations(range(len(anslist)), 3))
for pqr in pqrlist:
    for c in combs:
        pp,qq,rr = anslist[c[0]], anslist[c[1]], anslist[c[2]]
        if pp >= pqr[0] and qq >= pqr[1] and rr >= pqr[2]:
            p,q,r = primelist[c[0]], primelist[c[1]], primelist[c[2]]
            product = (p**pqr[0])*(q**pqr[1])*(r**pqr[2])
            if product not in ans:
                ans.append(product)

print(len(ans))

Measured memory_bytes: 4468
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<vector>
#include<cmath>
#include<string>
#include<numeric>
#include<limits.h>
#include<utility>
#include<cstdlib>
#define LP(i,n) for(int i=0;i<n;i++)
#define LPIN(n,a) for(int i=0;i<n;i++)cin >> a[i]
using namespace std;
 
int main(){
  int n;
  int first = 0;
  int last = 0;
  int plus = 0;
  int ans =0;
  cin >> n;
string temp;
  LP(i,n){
    cin >> temp;
    if(temp[0] == 'B'){
  //cout << "B = j" << endl;
first++;
}
if(temp[temp.size()-1] == 'A'){
   // cout << "A = j" << endl;
last++;
}
if(temp[0] == 'B' && temp[temp.size()-1] == 'A'){
plus++;
}
    for(int j=1;j<temp.size();j++){
      
if(temp[j-1] == 'A' && temp[j] =='B'){
ans++;
}
    }
    }
//cout << ans << first << last;
if(plus == first && plus == last && plus > 0){
  cout << ans + min(first-1,last-1) << endl;
}
else cout << ans +min(first,last) << endl;
return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define ll long long
#define P pair<int,int>
#define fi first
#define se second
#define rep(i,n) for(int i=0;i<n;i++)
#define all(v) v.begin(),v.end()
#define pb push_back
template<class T>void chmax(T &a,T b){if(a<b)a=b;}
template<class T>void chmin(T &a,T b){if(a>b)a=b;}
constexpr int INF=1000000000000000000;
constexpr int mod=1000000007;
int dx[]={0,1,0,-1},dy[]={1,0,-1,0};
int kaijo[2000010];
int gcd(int a,int b){
    if(b==0)return a;
    return gcd(b,a%b);
}
int lcm(int a,int b){
    return a/gcd(a,b)*b;
}
bool prime(int a){
    if(a==1)return false;
    for(int i=2;i*i<=a;i++){
        if(a%i==0)return false;
    }
    return true;
}
void init_fact(){
    kaijo[0]=1;
    for(int i=1;i<=2000000;i++){
        kaijo[i]=kaijo[i-1]*i;
        kaijo[i]%=mod;
    }
}
int modpow(int a,int b){
    if(b==0)return 1;
    if(b%2)return modpow(a,b-1)*a%mod;
    int memo=modpow(a,b/2);
    return memo*memo%mod;
}
int comb(int a,int b){
    if(!kaijo[0])init_fact();
    return kaijo[a]*modpow(kaijo[a-b],mod-2)%mod*modpow(kaijo[b],mod-2)%mod;
}
int inv(int x){
    x=modpow(x,mod-2);
    return x;
}
bool kosa(double ax,double ay,double bx,double by,double cx,double cy,double dx,double dy){
    double ta=(cx-dx)*(ay-cy)+(cy-dy)*(cx-ax);
    double tb=(cx-dx)*(by-cy)+(cy-dy)*(cx-bx);
    double tc=(ax-bx)*(cy-ay)+(ay-by)*(ax-cx);
    double td=(ax-bx)*(dy-ay)+(ay-by)*(ax-dx);
    return tc*td<0&&ta*tb<0;
}
int n,a[310],A,B,C;
double dp[300][300][300];
double calc(int i,int j,int k){
    int l=i+j+k;
    if(l==0)return 0.0;
    if(dp[i][j][k]>0.0)return dp[i][j][k];
    double res=1.0*n/l;
    if(i)res+=1.0*i/l*calc(i-1,j,k);
    if(j)res+=1.0*j/l*calc(i+1,j-1,k);
    if(k)res+=1.0*k/l*calc(i,j+1,k-1);
    dp[i][j][k]=res;
    return res;
}
signed main(){
    cin>>n;
    rep(i,n){
        cin>>a[i];
        if(a[i]==1)A++;
        if(a[i]==2)B++;
        if(a[i]==3)C++;
    }
    printf("%.12lf\n",calc(A,B,C));
    return 0;
}

Measured memory_bytes: 213248
#include<iostream>
using namespace std;
int h,w,m,D[1401][1401]={m=0},f,i;
main(){
	cin>>h>>w;
	for(i=0;i<h*w;i++){
		cin>>f;
		m=max(m,D[i/w+1][i%w+1]=(min(D[i/w][i%w],min(D[i/w+1][i%w],D[i/w][i%w+1]))+1)*(!f));
	}
    cout<<m*m<<endl;
}


Measured memory_bytes: 10760
#include <bits/stdc++.h>
#define ADD(a, b) a = (a + ll(b)) % mod
#define MUL(a, b) a = (a * ll(b)) % mod
#define MAX(a, b) a = max(a, b)
#define MIN(a, b) a = min(a, b)
#define rep(i, a, b) for(int i = int(a); i < int(b); i++)
#define rer(i, a, b) for(int i = int(a) - 1; i >= int(b); i--)
#define all(a) (a).begin(), (a).end()
#define sz(v) (int)(v).size()
#define pb push_back
#define sec second
#define fst first
#define debug(fmt, ...) Debug(__LINE__, ":", fmt, ##__VA_ARGS__)
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> pi;
typedef pair<ll, ll> pl;
typedef pair<int, pi> ppi;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<vl> mat;
typedef complex<double> comp;
void Debug() {cerr << '\n'; }
template<class FIRST, class... REST>void Debug(FIRST arg, REST... rest){
	cerr<<arg<<" ";Debug(rest...);}
template<class T>ostream& operator<<(ostream& out,const vector<T>& v) {
	out<<"[";if(!v.empty()){rep(i,0,sz(v)-1)out<<v[i]<<", ";out<<v.back();}out<<"]";return out;}
template<class S, class T>ostream& operator<<(ostream& out,const pair<S, T>& v){
	out<<"("<<v.first<<", "<<v.second<<")";return out;}
const int MAX_N = 500010;
const int MAX_V = 100010;
const double eps = 1e-6;
const ll mod = 1000000007;
const int inf = (1 << 30) - 1;
const ll linf = 1LL << 60;
const double PI = 3.14159265358979323846;
mt19937 rng; //use it by rng() % mod, shuffle(all(vec), rng)
///////////////////////////////////////////////////////////////////////////////////////////////////

int N;
ll K;
string S;

void solve() {
	cin >> S;
	cin >> K;
	N = sz(S);
	char a = S.front(), b = S.back();
	if(a == b) {
		int l = 0, r = N - 1;
		while(l < N && S[l] == a) l++;
		while(r >= 0 && S[r] == a) r--;
		if(l == N) {
			cout << N * K / 2 << "\n";
			return;
		}

		char c = a;
		int tmp = 0;
		ll d = 0;
		for(int i = l; i <= r; i++) {
			if(S[i] == c) tmp++;
			else {
				c = S[i];
				d += tmp / 2;
				tmp = 1;
			}
		}
		d += tmp / 2;
		ll res = 0;
		res += d * K;
		res += l / 2;
		res += (N - 1 - r) / 2;
		res += (N - 1 - r + l) / 2 * (K - 1);
		cout << res << "\n";
	}
	else {
		char c = a;
		int tmp = 0;
		ll d = 0;
		for(int i = 0; i < N; i++) {
			if(S[i] == c) tmp++;
			else {
				c = S[i];
				d += tmp / 2;
				tmp = 1;
			}
		}
		d += tmp / 2;
		cout << d * K << "\n";
	}
}

uint32_t rd() {
	uint32_t res;
#ifdef __MINGW32__
	asm volatile("rdrand %0" :"=a"(res) ::"cc");
#else
	res = std::random_device()();
#endif
	return res;
}

int main() {
#ifndef LOCAL
	ios::sync_with_stdio(false);
    cin.tie(0);
#endif
    cout << fixed;
	cout.precision(20);
    cerr << fixed;
	cerr.precision(6);
	rng.seed(rd());
#ifdef LOCAL
	//freopen("in.txt", "wt", stdout); //for tester
	if(!freopen("in.txt", "rt", stdin)) return 1;
#endif	
	solve();
    cerr << "Time: " << 1.0 * clock() / CLOCKS_PER_SEC << " s.\n";
	return 0;
}



Measured memory_bytes: 256
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

def abc138_d():
    N, _ = map(int, readline().strip().split())
    input_data = [tuple(map(int, ln.strip().split())) for ln in readlines()]

    # 隣接リスト作成
    graph = [[] for _ in range(N+1)]
    for a, b in input_data[:N-1]:
        graph[a].append(b)
        graph[b].append(a)

    # クエリをもとにスコア加算　※頂点pだけに加算し、子へは加算しない
    val = [0] * (N+1)
    for p, x in input_data[N-1:]:
        val[p] += x

    # DFSで根元から順に足していく
    stack = [1]
    visited = [False] * (N+1)
    visited[1] = True
    while stack:
        x = stack.pop()
        for y in graph[x]:
            if visited[y]: continue
            stack.append(y)
            visited[y] = True
            val[y] += val[x]

    print(*val[1:], sep=' ')

abc138_d()

Measured memory_bytes: 98780
var input = require('fs').readFileSync('/dev/stdin', 'utf8');
var Arr=(input.trim()).split("\n");
while(true){
var N=Arr.shift()-0;
if(N==0)break;
for(var I=0;I<N;I++){
var A=Arr.shift().split(" ").map(Number);
var x1=A[0];
var y1=A[1];
var z1=A[2];
var w1=A[3];
 
var x2=A[4];
var y2=A[5];
var z2=A[6];
var w2=A[7];
 
   var a = x1 * x2;
   var i = x1 * y2;
   var j = x1 * z2;
   var k = x1 * w2;
 
   i += y1 * x2;
   a -= y1 * y2;
   k += y1 * z2;
   j -= y1 * w2;
              
   j += z1 * x2;
   k -= z1 * y2;
   a -= z1 * z2;
   i += z1 * w2;
              
   k += w1 * x2;
   j += w1 * y2;
   i -= w1 * z2;
   a -= w1 * w2;
console.log(a+" "+i+" "+j+" "+k);
}
}

Measured memory_bytes: 17260
#define _USE_MATH_DEFINES
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cctype>
#include <climits>
#include <clocale>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <ctime>
#include <deque>
#include <fstream>
#include <functional>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <regex>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <tuple>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>

using namespace std;

#define IOS ios::sync_with_stdio(false); cin.tie(0);
#define FOR(i, s, n) for(int i = (s), i##_len=(n); i < i##_len; ++i)
#define FORS(i, s, n) for(int i = (s), i##_len=(n); i <= i##_len; ++i)
#define VFOR(i, s, n) for(int i = (s); i < (n); ++i)
#define VFORS(i, s, n) for(int i = (s); i <= (n); ++i)
#define REP(i, n) FOR(i, 0, n)
#define REPS(i, n) FORS(i, 0, n)
#define VREP(i, n) VFOR(i, 0, n)
#define VREPS(i, n) VFORS(i, 0, n)
#define RFOR(i, s, n) for(int i = (s), i##_len=(n); i >= i##_len; --i)
#define RFORS(i, s, n) for(int i = (s), i##_len=(n); i > i##_len; --i)
#define RREP(i, n) RFOR(i, n, 0)
#define RREPS(i, n) RFORS(i, n, 0)
#define IREP(i, v) for(auto i = (v).begin(); i != (v).end(); ++i)
#define IRREP(i, v) for(auto i = (v).rbegin(); i != (v).rend(); ++i)
#define ALL(v) (v).begin(), (v).end()
#define SORT(v) sort(ALL(v))
#define RSORT(v) sort(ALL(v), greater<decltype(v[0])>())
#define SZ(x) ((int)(x).size())
#define REV(x) reverse(ALL(x))
#define PB push_back
#define EB emplace_back
#define MP make_pair
#define MT make_tuple
#define BIT(n) (1LL<<(n))
#define UNIQUE(v) v.erase(unique(ALL(v)), v.end())

using ld = long double;
using ll = long long;
using ui = unsigned int;
using ull = unsigned long long;
using Pi_i = pair<int, int>;
using Pll_ll = pair<ll, ll>;
using VB = vector<bool>;
using VC = vector<char>;
using VD = vector<double>;
using VI = vector<int>;
using VLL = vector<ll>;
using VS = vector<string>;
using VSH = vector<short>;
using VULL = vector<ull>;

const int MOD = 1000000007; 
const int INF = 1000000000; //1e9
const int NIL = -1;
const ll LINF = 1000000000000000000; // 1e18
const double EPS = 1E-10;

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


int main(){
    ll X; cin >> X;
    ll ans(X / 500 * 1000);
    X %= 500;
    ans += X / 5 * 5;
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
#define debug(a) cout << #a << ": " << a << endl
#define sz(a) int(a.size())
#define rep(i,n) for(int i=0;i<n;i++)
#define forr(i, st, en) for(int i = st; i < en; i++)
#define all(v) (v).begin(),(v).end()
#define fast cin.tie(0); ios::sync_with_stdio(false)

int32_t main(){ fast;
	int n,m ; cin>>n>>m;
	vector<vector<char>> a(n + 2, vector<char>(m + 2, '#'));
	for(int i =1; i<=n; i++){
		string s; cin>>s;
		for(int j = 1; j<=m; j++){
			a[i][j] = s[j-1];
		}
	}
	for(int i =0; i <= n + 1; i++){
		for(int j =0; j <= m + 1; j++){
			cout<<a[i][j];
		}
		cout<<endl;
	}
}


Measured memory_bytes: 256
#include<stdio.h>
#define N 100000
#define Q 50000

int binarySearch();

int S[N],n,key;

int main(){
  int T[Q],q,i,c=0;
  
  scanf("%d",&n);
  for(i=0;i<n;i++){
    scanf("%d",&S[i]);
  }

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

  for(i=0;i<q;i++){
    key=T[i];
    if(binarySearch()) c++;
  }

  printf("%d\n",c);

  return 0;
  
}

int binarySearch(){
  int left,right,mid;

  left=0;
  right=n;

  while(left<right){

    mid = (left + right)/2;

    if(S[mid]==key) return 1;

    else if(key < S[mid]) right = mid;

    else left = mid + 1;
  }

  return 0;
}

Measured memory_bytes: 1184
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<n;i++)
#define rep1(i,n) for(int i=1;i<n+1;i++)
#define sort(A) sort(A.begin(),A.end())
#define reverse(A) reverse(A.begin(),A.end())
typedef long long ll;

int main(){
  int n;
  cin >> n;
  vector<int> h(n);
  rep(i,n) cin >> h[i];
  int ans = 1;
  for(int i=1;i<n;i++){
    for(int j=0;j<=i;j++){
      if(h[j] > h[i]) break;
      if(j == i) ans++;
    }
  }
  cout << ans << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ll          long long
#define pb          push_back
#define pii         pair<int,int>
#define vi          vector<int>
#define vii         vector<pii>
#define mi          map<int,int>
#define mii         map<pii,int>
#define all(a)      (a).begin(),(a).end()
#define ff           first
#define ss           second
#define sz(x)       (int)x.size()
#define endl        '\n'
#define hell        1000000007
#define rep(i,a,b)  for(int i=a;i<b;i++)
using namespace std;

// Most important thing in CP - Have Fun :)

void solve(){
	//write here
   //WRWWRWRR -- > RRWWRWRW --> RRRWWRWWW
   int n;
   cin>>n;
   string s;
   cin>>s;
   int i = 0 , j = n-1;
   int swaps = 0;
   while(i<j){
       while (s[i]=='R')i++;
       while (s[j]=='W')j--;
       if (i<j){
           swaps++;
           i++;
           j--;
       }
   }
   cout<<swaps<<endl;
}

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

Measured memory_bytes: 3764
from collections import deque
import sys
H,W=map(int,input().split())
S =[]
kuro=0
for i in range(H):
    s = list(input())
    for j in s:
        if j=='#':
            kuro +=1
    S.append(s)

visit=[[False]*W for i in range(H)]
dist=[[]]
kei=deque()
kei.append((0,0,1))
visit[0][0]=True
X =[-1,0,1,0]
Y=[0,-1,0,1]
while kei:
    y,x,d=kei.popleft()
    if y==H-1 and x==W-1:
        print(H*W-d-kuro)
        sys.exit()
    for i in range(4):
        nx = x +X[i]
        ny = y +Y[i]
        if (0<=nx< W) and (0<=ny<H) and S[ny][nx]=='.':
            if not visit[ny][nx]:
                kei.append((ny,nx,d+1))
                visit[ny][nx]=True
print(-1)

Measured memory_bytes: 3444
#include<iostream>
using namespace std;
#include<string>
#define REP(i,a,b) \
for(int i=a; i<b; i++)
#include<bits/stdc++.h>
#include<algorithm>
#define ll long long int
typedef vector<int> vi;
typedef pair<int,int> ii;
#define sz(a) int((a).size())
#define pb push_back
#define all(c) (c).begin(),(c).end()
#define present(c,x) ((c).find(x) != (c).end())
#define tr(c,i) for(typeof(c.begin()) i = (c).begin(); i != (c).end();i++)

int main()
{
	string s;
	cin >> s;
	int n = 0;
	REP(i,0,4)
	{
		if(s[i] == '+')n++;
		else n --;
	}
	cout << n;
}


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

int main(){
	int n;cin>>n;
	vector<int> arr(n);
	for(int i=0;i<n;++i)cin>>arr[i];
	for(int i=1;i<n;++i)arr[i]+=arr[i-1];
  
	int result = INT_MAX;
	for(int i=0;i<n;++i) result=min(result,abs(arr[n-1]-arr[i]-arr[i]));
  
  	cout<<result<<endl;
  	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
using namespace std;
using ll = long long;
using P = pair<int, int>;
int main()
{
    int n, x;
    cin >> n >> x;
    int ming = 1e9;
    rep(i, n)
    {
        int m;
        cin >> m;
        x -= m;
        if (ming > m)
            ming = m;
    }
    int cnt = n;
    while (x >= ming)
    {
        x -= ming;
        cnt++;
    }
    cout << cnt << endl;
    return 0;
}

Measured memory_bytes: 3616
using System;

namespace _0011
{
    class Program
    {
        static void Main(string[] args)
        {
            var verticalLineNumber = int.Parse(Console.ReadLine());
            var horizontalLineNumber = int.Parse(Console.ReadLine());

            int[] lines = new int[verticalLineNumber];

            for(int i = 0; i < verticalLineNumber ;i++)
            {
                lines[i] = i + 1;
            }
            for (int i = 0; i < horizontalLineNumber; i++)
            {
                var line = Console.ReadLine();
                string[] linePoints = line.Split(',');
                int[] linePointNumbers = Array.ConvertAll<string, int>(linePoints, delegate(string value) { return int.Parse(value); });
                ExchangeLineResult(lines,linePointNumbers);
            }
            foreach(var line in lines)
            {
                Console.WriteLine(line);
            }
        }

        public static void ExchangeLineResult(int[] lines,int[] linePointsNumbers) 
        {
            int value = lines[(linePointsNumbers[0] - 1)];
            lines[(linePointsNumbers[0] - 1)] = lines[(linePointsNumbers[1] - 1)];
            lines[(linePointsNumbers[1] - 1)] = value;
        }
    }
}

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

int main() {
  int64_t a,b,c,d,e,f;
  cin>>a>>b>>c>>d>>e>>f;
  int64_t i=a*(c-e);
  int64_t j=b*(d-f);
  if(i+j==0){
    cout<<"infinity"<<endl;
  }
  else if(i>0 && j>=0){
    cout<<0<<endl;
  }
  else if(i<0 && j<=0){
    cout<<0<<endl;
  }
  else{
    if(i>0){
      i=-i;
      j=-j;
    }
    if(i+j<0){
      cout<<0<<endl;
    }
    else{
      if((-i)%(i+j)!=0){
        cout<<((-i)/(i+j))*2+1<<endl;
      }
      else{
        cout<<((-i)/(i+j))*2<<endl;
      }
    }
  }
}

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

int main() {
  int H,W;
  cin >> H >> W;
  vector<string> l(H);
  
  for (int i=0; i<H; i++){
    cin >> l.at(i);
  }
  
  for (int i=0; i<W+2; i++)
  	cout << "#";
  cout << endl;
  for (int i=0; i<H; i++)
    cout << "#" << l.at(i) << "#" <<endl;
  for (int i=0; i<W+2; i++)
  	cout << "#";
}



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

int main() {
    int n; cin >> n;
    vector<pair<int, int>> a(n);
    for (int i = 0; i < n; i++) cin >> a[i].first, a[i].second = i;
    sort(a.rbegin(), a.rend());
    for (int i = 0; i < n; i++) {
        if (a[0].second == i) cout << a[1].first << endl;
        else cout << a[0].first << endl;
    }
    return 0;
}

Measured memory_bytes: 3200
#どっちで出すか注意, rstrip注意
#提出前に見返すこと！
def main():
    import sys
    input = sys.stdin.readline
    sys.setrecursionlimit(10**7)
    from collections import Counter, deque
    #from collections import defaultdict
    from itertools import combinations, permutations, accumulate
    #from itertools import product
    from bisect import bisect_left,bisect_right
    import heapq
    from math import floor, ceil
    #from operator import itemgetter

    #inf = 10**17
    #mod = 10**9 + 7

    n,m = map(int, input().split())
    a = list(map(int, input().split()))
    bc = [list(map(int, input().split())) for _ in range(m)]
    bc.sort(key=lambda a: a[1])
    a.sort()
    res = 0
    cnt = 0
    while cnt<n:
        if not bc:
            res += sum(a[cnt-n:])
            break
        if a[-1] >= bc[-1][1]:
            res += a.pop()
            cnt += 1
        else:
            d, e = bc.pop()
            if n-cnt >= d:
                res += d*e
                cnt += d
            else:
                res += (n-cnt)*e
                break

    print(res)


if __name__ == '__main__':
    main()


Measured memory_bytes: 73368
//
//  AAAAAB.cpp
//  my_programs
//
//  Created by Jiatuo Zou on 7/22/20.
//  Copyright © 2020 Jiatuo Zou. All rights reserved.
//

#include <iostream>

int main()
{
    using namespace std;
    
    int n, m, k, f = 0, books = 0, ans = 0, f2 = 0;
    long long int ab[2][200000], prefixs_sum[2][200001] = {{0}};
    cin >> n >> m >> k;
    for(int i = 0; i < n; i++){
        cin >> ab[0][i];
        prefixs_sum[0][i + 1] += (ab[0][i] + prefixs_sum[0][i]);
        if(prefixs_sum[0][i + 1] > k && f2 == 0){
            f = i;
            f2 = 1;
        }
    }
    if(prefixs_sum[0][n] <= k){
        f = n;
    }
    books = f;
    ans = f;
    for(int i = 0; i < m; i++){
        cin >> ab[1][i];
        prefixs_sum[1][i + 1] += (ab[1][i] + prefixs_sum[1][i]);
    }
    for(int i = f, j = 1; j <= m; ){
        if(prefixs_sum[1][j] > k){
            break;
        }
        if(k - prefixs_sum[0][i] >= prefixs_sum[1][j]){
            j++;
            books++;
        } else if(i > 0 && k - prefixs_sum[0][i] < prefixs_sum[1][j]){
            i--;
            books--;
        }
        ans = max(ans, books);
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 9860
#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) ; i>=0 ; i--)
#define ALL(x) (x).begin(),(x).end()
 
int GCD(int a,int b){ return b ? GCD(b,a%b) : a ;}
int LCM(int a,int b){ return a*b / GCD(a,b) ;}
 
typedef long long ll;
typedef unsigned long long ull;
 
const int INF = 1e9;

int main(){
      int n,m;
      cin >> n >> m;
      int maxL=0,minR=INF;
      rep(i,m){
            int l,r;
            cin >> l >> r;
            maxL = max(l,maxL);
            minR = min(r,minR);
      }
      cout << (minR - maxL + 1 <=0 ? 0 : minR - maxL + 1)  << endl;
      return 0;
}


Measured memory_bytes: 256
#include <iostream>
using namespace std;
int main () {
    int arr[5], k;
    for (int i=0; i<5; i++) cin>>arr[i];
    cin>>k;
    for (int i=0; i<5; i++) {
        for (int j=i+1; j<5; j++) {
            if (arr[j]-arr[i]>k) {
                cout<<":(\n";
                return 0;
            }
        }
    }
    cout<<"Yay!\n";
}

Measured memory_bytes: 256
def main():
    N = int(input())
    Tn = tuple(map(int, input().split()))
    Vn = tuple(map(int, input().split()))

    t = (0,) + Tn + (0,)
    v = (0,) + Vn + (0,)
    maxv = [0]
    for i in range(1, N + 1):
        if v[i-1] <= v[i] > v[i+1]:
            maxv += [v[i]] * (t[i] * 2 - 1)
        elif v[i-1] > v[i] <= v[i+1]:
            maxv += [v[i]] * (t[i] * 2 + 1)
        else:
            maxv += [v[i]] * t[i] * 2
    maxv += [0]

    cnt = len(maxv)
    for i in range(1, cnt):
        maxv[i] = min(maxv[i], maxv[i-1] + 0.5)

    for i in range(cnt - 2, -1, -1):
        maxv[i] = min(maxv[i], maxv[i+1] + 0.5)

    s = 0
    for i in range(cnt - 1):
        s += (maxv[i] + maxv[i+1]) * 0.5 / 2
    print(s)

main()


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

using namespace std;

int main(int argc, char const *argv[])
{
    int n;
    long long k;
    cin >> n >> k;
    vector<int> a(n);
    for (int i = 0; i < n; i++)
    {
        cin >> a[i];
    }

    vector<int> num(n+1, -1);
    vector<int> s;
    int v = 1;
    while (num[v] == -1)
    {
        num[v] = s.size();
        //cout << num[v] << endl;
        s.push_back(v);
        //cout << v << endl;
        //cout << a[v-1] << endl;
        v = a[v - 1];
    }

    //cout << num[v] << endl;

    int cycle = s.size() - num[v];
    int l = num[v];

    //cout << "l: " << l << endl;

    if (k < l)
        cout << s[k] << endl;
    else
    {
        //cout << "l+k" << l+k << endl;
        k = (k-l)%cycle;
        cout << s[l + k] << endl;
    }

    // cout << v << endl;
    // int i=1, num=0, remain =0;
    // int before = 0;
    // while(a[i-1][1]==0 && num < k){
    //     before = i;
    //     a[i-1][1] = 1;
    //     //cout << "i: " << i << endl;
    //     //cout << "ai: " << a[i-1][0] << endl;
    //     i = a[i-1][0];
    //     num++;
    //     //cout << "num: " << num << endl;
    // }

    // if(num ==k){
    //     cout << i << endl;
    //     return 0;
    // }

    // int start = i;
    // //cout << "start: " << start << endl;
    // do{
    //     remain++;
    //     //cout << "i: " << i << endl;
    //     //cout << "a[i: " << a[i-1][0] << endl;
    //     i = a[i-1][0];
    //     num++;
    //     //cout << "num: " << num << endl;
    // }while(start!=a[i-1][0] && num < k);

    // if(num ==k){
    //     cout << i << endl;
    //     return 0;
    // }

    // // cout << "num" << num << endl;

    // for(int j = 0; j< (k-num) % remain; j++){
    // //     cout << "start" << start << endl;
    // //     cout << "a[i" << a[start-1][0] << endl;
    //     start = a[start-1][0];
    // }

    // cout << start << endl;

    return 0;
}


Measured memory_bytes: 5856
/* DELAPAN.3gp */
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <stack>
#include <algorithm>
#include <utility>
#include <numeric>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <cstdlib>
#include <ctime>
#include <cassert>
using namespace std;

#ifdef DEBUG
	#define debug(...) printf(__VA_ARGS__)
	#define GetTime() fprintf(stderr,"Running time: %.3lf second\n",((double)clock())/CLOCKS_PER_SEC)
#else
	#define debug(...) 
	#define GetTime() 
#endif

//type definitions
typedef long long ll;
typedef double db;
typedef pair<int,int> pii;
typedef vector<int> vint;

//abbreviations
#define A first
#define B second
#define MP make_pair
#define PB push_back

//macros
#define REP(i,n) for (int i = 0; i < (n); ++i)
#define REPD(i,n) for (int i = (n)-1; 0 <= i; --i)
#define FOR(i,a,b) for (int i = (a); i <= (b); ++i)
#define FORD(i,a,b) for (int i = (a); (b) <= i; --i)
#define FORIT(it,c) for (__typeof ((c).begin()) it = (c).begin(); it != (c).end(); it++)
#define ALL(a) (a).begin(),(a).end()
#define SZ(a) ((int)(a).size())
#define RESET(a,x) memset(a,x,sizeof(a))
#define EXIST(a,s) ((s).find(a) != (s).end())
#define MX(a,b) a = max((a),(b));
#define MN(a,b) a = min((a),(b));

inline void OPEN(const string &s) {
	freopen((s + ".in").c_str(), "r", stdin);
	freopen((s + ".out").c_str(), "w", stdout);
}

/* -------------- end of DELAPAN.3gp's template -------------- */

char s[111];
int c[111];

int main(){
	scanf("%s", s);
	REP(i, strlen(s)) {
		c[s[i] - 'a']++;
	}
	REP(i, 26) {
		if (c[i] & 1) {
			puts("No");
			return 0;
		}
	}
	puts("Yes");
	return 0;
}


Measured memory_bytes: 256
#include<algorithm>     //sort,二分探索,など
#include<bitset>        //固定長bit集合
#include<cmath>         //pow,logなど
#include<complex>       //複素数
#include<deque>         //両端アクセスのキュー
#include<functional>    //sortのgreater
#include<iomanip>       //setprecision(浮動小数点の出力の誤差)
#include<iostream>      //入出力
#include<iterator>      //集合演算(積集合,和集合,差集合など)
#include<map>           //map(辞書)
#include<numeric>       //iota(整数列の生成),gcdとlcm(c++17)
#include<queue>         //キュー
#include<set>           //集合
#include<stack>         //スタック
#include<string>        //文字列
#include<unordered_map> //イテレータあるけど順序保持しないmap
#include<unordered_set> //イテレータあるけど順序保持しないset
#include<utility>       //pair
#include<vector>        //可変長配列

using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<string> vs;
typedef vector<bool> vb;
typedef vector<vector<int>> vvi;
typedef vector<vector<ll>> vvll;
typedef vector<vector<string>> vvs;
typedef vector<vector<bool>> vvb;
const ll MOD = 1000000007;
const ll INF = 1000000000000000000;
#define rep(i,n) for(int i=0;i<n;i++)
#define repl(i,s,e) for(int i=s;i<e;i++)
#define reple(i,s,e) for(int i=s;i<=e;i++)
#define revrep(i,n) for(int i=n-1;i>=0;i--)
#define all(x) (x).begin(),(x).end()

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

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

    int X;
    cin >> X;

    ll ans = 0;

    if (X >= 400 && X <= 599)
    {
        ans = 8;
    }
    else if (X >= 600 && X <= 799)
    {
        ans = 7;
    }
    else if (X >= 800 && X <= 999)
    {
        ans = 6;
    }
    else if (X >= 1000 && X <= 1199)
    {
        ans = 5;
    }
    else if (X >= 1200 && X <= 1399)
    {
        ans = 4;
    }
    else if (X >= 1400 && X <= 1599)
    {
        ans = 3;
    }
    else if (X >= 1600 && X <= 1799)
    {
        ans = 2;
    }
    else if (X >= 1800 && X <= 1999)
    {
        ans = 1;
    }

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

Measured memory_bytes: 3688
import java.util.*;
public class Main {

	public static void main(String[] args) {
		Scanner in=new Scanner(System.in);
		
		while(true) {
			String str="";
			while(true) {
				String s=in.nextLine();
				str=str+s;
				char c[]=s.toCharArray();
				if(c[c.length-1]=='.')break;
			}
			char data[]=str.toCharArray();
			if(data[0]=='.')break;
			System.out.println(solve(data)? "yes":"no");
		}
	}
	
	static boolean solve(char[] data) {
		//System.out.println("::"+String.valueOf(data));
		//char data[]=str.toCharArray();
		Stack<Character> stk=new Stack<>();
		
		for(int i=0;i<data.length;i++) {
			if(data[i]=='(' || data[i]=='[')stk.push(data[i]);
			else if(data[i]==')') {
				if(!stk.isEmpty() && stk.peek()=='(')stk.pop();
				else return false;
			}
			else if(data[i]==']') {
				if(!stk.isEmpty() && stk.peek()=='[')stk.pop();
				else return false;
			}
		}
		
		if(!stk.isEmpty())return false;
		else return true;
	}

}



Measured memory_bytes: 45600
import sys
sys.setrecursionlimit(10**7)
import math

def prime_table(n):
    all_table = [True for _ in range(n+1)]
    all_table[0] = False
    all_table[1] = False    

    for i in range(2, n+1):
        if all_table[i]:
            j = 2 * i
            while j <= n:
                all_table[j] = False
                j += i
    table = [i for i in range(1, n+1) if all_table[i]]
    return table

n_orig = int(input())
n = n_orig

prime_lis = []

for i in prime_table(int(math.sqrt(n))):
    while n % i == 0:
        n /= i
        prime_lis.append(str(i))

if n != 1:
    prime_lis.append(str(int(n)))

print("{}: {}".format(n_orig, " ".join(prime_lis)))


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

int n,a,b,k;  
string s;

int main() {
  cin >> a >> b >> k;
  int c,d;
  rep(i,k){
    if(!(i&1)){
      if(a&1) a--;
      a/=2,b+=a;
    }else{
      if(b&1) b--;
      b/=2,a+=b;
    }
  }
  cout << a << " " << b << endl;
}

Measured memory_bytes: 256
#pragma GCC optimize("O3")
#include<bits/stdc++.h> 
using namespace std;
using ll=long long;
typedef pair<ll,ll> P;
#define fi first
#define se second
#define all(v) (v).begin(),(v).end()
const ll inf=(1e18);
const ll mod=1000003;
//ios_base::sync_with_stdio(false);
//cin.tie(NULL);
ll gcd(ll a,ll b) {return b ? gcd(b,a%b):a;}
struct __INIT{__INIT(){cin.tie(0);ios::sync_with_stdio(false);cout<<fixed<<setprecision(15);}} __init;
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 (a>b) { a=b; return 1; } return 0; }
map<P,ll> mp;
const ll MAX = 2000010;//設定して

long long fac[MAX], finv[MAX], inv[MAX];

// テーブルを作る前処理
void init() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (int 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;
    }
}
//階乗
long long factor(ll n,ll k){
  if (n<k) return 0;
  if (n<0 || k<0) return 0;
  return (fac[n]*finv[k])%mod;
}
// 二項係数計算
long long COM(int n, int k){
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n - k] % mod) % mod;
}
//aの逆元求めるならn=mod-2
long long modpow(long long a, long long n) {
    long long res = 1;
    while (n > 0) {
        if (n & 1) res = res * a % mod;
        a = a * a % mod;
        n >>= 1;
    }
    return res;
}
int main(){
    init();
    int q;
    cin>>q;
    while(q--){
        ll x,d,n;
        cin>>x>>d>>n;
        if(x==0)cout<<0<<endl;
        else if(d==0){
            cout<<modpow(x,n)<<endl;
        }
        else if(n>mod)cout<<0<<endl;
        else if(d==1){
            cout<<factor(x+n-1,x-1)<<endl;
        }
        else{
            x*=modpow(d,mod-2);
            x%=mod;
            cout<<(factor(x+n-1,x-1)*modpow(d,n))%mod<<endl;
        }
    }
}

Measured memory_bytes: 47744
from collections import defaultdict, Counter
from itertools import product, groupby, count, permutations, combinations
from math import pi, sqrt
from collections import deque
from bisect import bisect, bisect_left, bisect_right
from string import ascii_lowercase
from functools import lru_cache
import sys
sys.setrecursionlimit(10000)
INF = float("inf")
YES, Yes, yes, NO, No, no = "YES", "Yes", "yes", "NO", "No", "no"
dy4, dx4 = [0, 1, 0, -1], [1, 0, -1, 0]
dy8, dx8 = [0, -1, 0, 1, 1, -1, -1, 1], [1, 0, -1, 0, 1, 1, -1, -1]


def inside(y, x, H, W):
    return 0 <= y < H and 0 <= x < W


def ceil(a, b):
    return (a + b - 1) // b


# 初項s, 交差dのn個の数列の和
def sum_of_arithmetic_progression(s, d, n):
    return n * (2 * s + (n - 1) * d) // 2


# aとbの最大公約数
def gcd(a, b):
    if b == 0:
        return a
    return gcd(b, a % b)


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


def main():
    N = int(input())
    P = list(map(int, input().split()))

    s = list(sorted(P[::]))

    for i in range(N):
        for j in range(N):
            P[i], P[j] = P[j], P[i]
            if P == s:
                print("YES")
                return
            P[i], P[j] = P[j], P[i]

    print("NO")



if __name__ == '__main__':
    main()


Measured memory_bytes: 3952
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
int dx[] = {1,0,-1,0};
int dy[] = {0,-1,0,1};

int main(){
    int n;
    cin >> n;
    string s;
    cin >> s;
    char prev;
    prev = s[0];
    int ans = 1;
    for(int i=1;i<n;i++){
        if(prev == s[i]) continue;
        prev = s[i];
        ans++;
    }
    cout << ans << endl;
}


Measured memory_bytes: 512
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.Arrays;
import java.util.StringTokenizer;

public class Main {
    int n, a, b;
    double[] vs;
    double precision = 10e-6;

    public static void main(String args[]) {
        new Main().run();
    }

    void run() {
        FastReader sc = new FastReader();
        n = sc.nextInt();
        a = sc.nextInt();
        b = sc.nextInt();
        vs = new double[n];
        for (int i = 0; i < n; i++) {
            vs[i] = sc.nextDouble();
        }
        solve();
    }

    void solve() {
        boolean[] maximums = new boolean[n];
        Arrays.sort(vs);
        double sum = 0.0;
        for (int i = n - 1; i >= n - a; i--) {
            sum += vs[i];
        }
        double maxAverage = sum / a;
        double minInAverage = vs[n - a];
        System.out.printf("%6f\n", maxAverage);

        int minCount = 0;
        int index;
        for (index = 0; index < n; index++) {
            if (Math.abs(vs[index] - minInAverage) < precision) {
                minCount++;
            }
            if (vs[index] > minInAverage &&
                    Math.abs(vs[index] - minInAverage) > precision) {
                break;
            }
        }
        int minNum = index - n + a;
        if (minInAverage < maxAverage &&
                Math.abs(minInAverage - maxAverage) > precision) {
            System.out.println(combination(minCount, minNum));
        } else {
            long ans = 0;
            for (int i = minNum; i <= index - n + b; i++) {
                ans += combination(minCount, i);
            }
            System.out.println(ans);
        }
    }

    long combination(int n, int k) {
        long ret = 1;
        for (long i = 1; i <= k; i++) {
            ret *= n + 1 - i;
            ret /= i;
        }
        return ret;
    }

    static class FastReader {
        BufferedReader br;
        StringTokenizer st;

        public FastReader() {
            br = new BufferedReader(new
                    InputStreamReader(System.in));
        }

        String next() {
            while (st == null || !st.hasMoreElements())
            {
                try
                {
                    st = new StringTokenizer(br.readLine());
                }
                catch (IOException e)
                {
                    e.printStackTrace();
                }
            }
            return st.nextToken();
        }

        int nextInt()
        {
            return Integer.parseInt(next());
        }

        long nextLong()
        {
            return Long.parseLong(next());
        }

        double nextDouble()
        {
            return Double.parseDouble(next());
        }

        String nextLine() {
            String str = "";
            try
            {
                str = br.readLine();
            }
            catch (IOException e)
            {
                e.printStackTrace();
            }
            return str;
        }
    }
}


Measured memory_bytes: 24660
#include <iostream>
#include <algorithm>
#include <string>
#include <cmath>
#include <vector>
#define rep(i,n) for(int i=0;i<n;i++)
#define ll long long int
#define MAX 1000000007
using namespace std;

int main(void){
	int a,b;
	cin>>a>>b;
	if(a%2==1 && b%2==1)cout<<"Yes"<<endl;
	else cout<<"No"<<endl;
	return 0;
}


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

using namespace std;
typedef long long ll;
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<ll> VL;
typedef vector<VL> VVL;
typedef pair<int, int> PII;

#define FOR(i, a, n) for (ll i = (ll)a; i < (ll)n; ++i)
#define REP(i, n) FOR(i, 0, n)
#define ALL(x) x.begin(), x.end()
#define IN(a, b, x) (a<=x&&x<b)
#define MP make_pair
#define PB push_back
#define INF (1LL<<30)
#define LLINF (1LL<<60)
#define PI 3.14159265359
#define EPS 1e-12
//#define int ll

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

struct edge{
  int to, cost;
};

vector<edge> g[200010];
int d[200010];
signed main(void)
{
  int n, m;
  cin >> n;
  cin >> m;
  REP(i, m) {
    int a, b;
    cin >> a >> b;
    a--, b--;
    g[a].PB({b, 1});
    g[b].PB({a, 1});
  }

  priority_queue<PII, vector<PII>, greater<PII>> que;
  fill(d, d+n, INF);
  d[0] = 0;
  que.push({0, 0});

  while(que.size()) {
    PII p = que.top(); que.pop();
    int v = p.second;
    if(d[v] < p.first) continue;
    REP(i, g[v].size()) {
      edge e = g[v][i];
      if(d[e.to] > d[v] + e.cost) {
        d[e.to] = d[v] + e.cost;
        que.push(PII{d[e.to], e.to});
      }
    }
  }

  if(d[n-1] == 2) cout << "POSSIBLE" << endl;
  else cout << "IMPOSSIBLE" << endl;

  return 0;
}


Measured memory_bytes: 15080
#include<bits/stdc++.h>
using namespace std;
int main(){
  int a;
  int key = 0;
  cin >> a;
  vector<string> A(a);
  for(int i = 0;i<a;i++)
    cin >> A.at(i);
  for(int i = 0;i<a;i++){
    for(int j = i+1;j<a;j++){
      if(A.at(i) == A.at(j)){
        key = 1;
      }
    }
  }
  for(int i = 1;i<a;i++){
    if(A.at(i-1).at(A.at(i-1).size()-1) != A.at(i).at(0)){
      key = 1;
    }
  }
  if(key == 1)
    cout << "No" << endl;
  else
    cout << "Yes" << endl;
}
    

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <cstdlib>
#include <vector>
#include <array>
#include <map>
#include <set>
#include <algorithm>
#include <queue>
#include <stack>
#define _USE_MATH_DEFINES
#include <cmath>
#include <climits>
#include <cstdio>
#include <iomanip>
#include <utility>
#include <unordered_map>

using namespace std;
typedef long long int ll;

#define SP(x) setprecision((int)x)
#define ALL(v) v.begin(), v.end()

/* デカい配列はここで宣言 */

int main(int argc, char const *argv[])
{
    ll n;
    cin >> n;
    map<string, vector<pair<ll, ll>>> m;
    for (ll i = 1; i <= n; i++)
    {
        string s;
        cin >> s;
        ll p;
        cin >> p;
        m[s].push_back(make_pair(p, i));
    }

    for (auto k : m)
    {
        if (!k.second.empty())
        {
            sort(ALL(k.second), greater<>());
            for (auto i : k.second)
            {
                cout << i.second << endl;
            }
        }
    }
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
	int a,b;
	cin>>a>>b;
	 if(a>0){
		 cout<<"Positive"<<endl;
	 }
	 else if(0>b&&(a-b)%2){
		 cout<<"Positive"<<endl;
	 }
	 else if(0>b&&(a-b)%2==0){
		 cout<<"Negative"<<endl;
	 }
	 else{
		 cout<<"Zero"<<endl;
	 }
}


Measured memory_bytes: 256
import sys
import numpy as np

stdin = sys.stdin

ri = lambda: int(rs())
rl = lambda: list(map(int, stdin.readline().split()))  # applies to numbers only
rs = lambda: stdin.readline().rstrip()  # ignores trailing space

N, M, V, P = rl() #Vは選べる問題
A = rl()
A.sort(reverse=True)
INF = 10 ** 10
A = A[P-1:] + [-INF] #上位P-1問は捨てる
V -= (P-1)
N = len(A)
answer = P-1

# 残りの問題からトップに立てるかどうか二分探索
high = N-1 #不可能
low = 0 #可能
while high > low + 1:
    mid = (high+low)//2
    num = max(0, V - (N-1-mid)) #INFは捨てる   
    B = np.array(A[:mid])
    #Bの中からM人のジャッジがnum問選ぶ
    count = ((A[mid] + M) - B).sum()
    if count <  M * num:
        high = mid #不可能
    # 他に不可能な場合がある
    elif A[0] > A[mid] + M:
        high = mid
    else:
        low = mid

answer += (low + 1)
print(answer)


Measured memory_bytes: 23176
#include "bits/stdc++.h"

#define ALL(a) (a).begin(),(a).end()
#define SORT(c) sort((c).begin(),(c).end())
#define DESCSORT(c) sort(c.begin(), c.end(), greater<int>())

using namespace std;

using LL = long long int;
using LD = long double;

using pii = pair<int, int>;
using pll = pair<LL, LL>;
using pdd = pair<double, double>;
using vi = vector<int>;
using vvi = vector<vi>;
using vvvi = vector<vvi>;
using vl = vector<LL>;
using vvl = vector<vl>;
using vvvl = vector<vvl>;
using vd = vector<double>;
using vvd = vector<vd>;
using vs = vector<string>;
using vb = vector<bool>;
using vvb = vector<vb>;

const int INF = (1 << 30) - 1;
const LL INF64 = ((LL)1 << 62) - 1;
const double PI = 3.1415926535897932384626433832795;

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

int gcd(int x, int y) { return y ? gcd(y, x % y) : x; }
LL gcd(LL x, LL y) { return y ? gcd(y, x % y) : x; }

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

	string a, b;
	cin >> a >> b;

	if (a == "H") {
		if (b == "H") {
			cout << "H" << endl;
		} else {
			cout << "D" << endl;
		}
	} else {
		if (b == "H") {
			cout << "D" << endl;
		} else {
			cout << "H" << endl;
		}
	}
	return 0;
}

Measured memory_bytes: 256
import Foundation

func main(){
   let n = Int(readLine()!)!

   var cache = [Int](repeating: 0, count: n+1)
   
   outerLoop: for x in 1...n {
      outerLoop1: for y in 1...n {
         for z in 1...n {
            let computed = x*x + y*y + z*z + x*y + y*z + z*x
            if computed <= n {
               cache[computed] += 1
            }
            if computed > n {
               if z == 1 {
                  if y == 1 {
                     break outerLoop
                  }
                  break outerLoop1
               }
               break
            }
         }
      }
   }
   for i in 1...n {
      print(cache[i] ?? 0)
   }
}
main()

Measured memory_bytes: 13024
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<cmath>
#include<set>
#include<map>
#include<iomanip>
#include<queue>
#include<numeric>
typedef long long LL;

using namespace std;

LL gcd(LL a, LL b) {
	LL r;
	while ((r = a % b) != 0) {
		a = b;
		b = r;
	}
	return b;
}
LL lcm(LL a, LL b) {
	return (a / gcd(a, b) * b);
}


int main(void) {
	LL n, y;
	cin >> n >> y;
	for (int i = 0; i <= n; i++) {
		for (int j = 0; j <= n - i; j++) {
			for (int k = 0; k <= n - i - j; k++) {
				if (i + j + k == n && 10000 * k + 5000 * j + 1000 * i == y) {
					cout << k << " " << j << " " << i;
					return 0;
				}
			}
		}
	}
	cout << -1 << " " << -1 << " " << -1;
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#include<iomanip>
using namespace std;
typedef long long ll;
typedef long  l;
typedef pair<int,int> P;
#define rep(i,n) for(int i=0;i<n;i++)
#define fs first
#define sc second
#define pb push_back
#define mp make_pair
#define eb emplace_back
#define ALL(A) A.begin(),A.end()
const int INF=1000000001;
const double PI=3.141592653589;
const ll mod=1000000007;

int main(){
  ll n,a,b; cin>>n>>a>>b;
  ll mid=b-a-1;
  ll top=n-a;
  ll bot=b-1;
  ll ans;
  if(mid%2==0){
    ans=min(mid/2+n-b+1,mid/2+a);
  }else{
    ans=mid/2+1;
  }
  cout<<ans<<endl;

  return 0;
}


Measured memory_bytes: 256
from collections import Counter
import sys


def main():
    sys.setrecursionlimit(10**6)
    readline = sys.stdin.buffer.readline
    N = int(readline())
    A = list(map(int, readline().split()))
    C = Counter(A)

    l, m, n = C[3], C[2], C[1]
    dp = [[[-1]*(N+1) for _ in range(N+1)] for _ in range(N+1)]
    dp[0][0][0] = 0

    def exval(i, j, k):
        if dp[i][j][k]!=-1:
            return dp[i][j][k]
        s = N
        if i > 0:
            s += i*exval(i-1, j+1, k)
        if j > 0:
            s += j*exval(i, j-1, k+1)
        if k > 0:
            s += k*exval(i, j, k-1)
        dp[i][j][k] = s / (i+j+k)
        return dp[i][j][k]


    print(exval(l, m, n))
    
if __name__ == "__main__":
    main()


Measured memory_bytes: 407120
#include <iostream>
#include <vector>
#include <map>
#include <utility>
#include <stack>
#include <string>
#include <algorithm> 
#include <set>
#include <sstream>
#include <bit>
#include <bitset>
#include <cstdint>
#include <iomanip>
#include <queue>
#include <initializer_list>
#include <stdio.h>
typedef long long int ll;
using namespace std;
int main() {
	int N, K; cin >> N >> K;
	vector<ll>data(N);
	ll ans = 0;
	for (int i = 0; i < N; i++)cin >> data[i];
	sort(data.begin(), data.end());
	reverse(data.begin(), data.end());

	if (K >= N) {
		cout << 0 << endl;
	}
	else {
		data.erase(data.begin(),data.begin()+K);
		for (int i = 0; i < data.size(); i++)ans += data[i];
		cout << ans << endl;
	}
}

Measured memory_bytes: 4364