akhauriyash/Code-Regression huggingface dataset:
#include<iostream>
#include<vector>
#include<string>

using namespace std;

string S;

int main() {
	cin >> S;
	char a = -1, b = -1;
	int anum = 0; int bnum = 0;
	a = S[0];
	anum = 1;
	for (int i = 1; i < 4; i++) {
		if (S[i] == a) { anum++; }
		else if (S[i] == b) { bnum++; }
		else { b = S[i]; bnum = 1; }
	}
	if (anum == 2 && bnum == 2) {
		cout << "Yes" << endl;
	}
	else {
		cout << "No" << endl;
	}


}

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

int main(void)
{
    char ch[1201];
    char enter;
    int x;
    int count[26] = {0};
    int num;
    
    while (fgets( ch, 1201, stdin) != NULL){
        x = strlen(ch);

        for(int i = 0; i < x; i++){
            if( 65 <= ch[i] && ch[i] <= 96){
                num = (ch[i] + 32) - 97;
                
                count[num]++;
            }
            else if(97 <= ch[i] && ch[i] <= 122){
                num = ch[i] - 97;
                count[num]++;
            }

        }
    }

    for(int k = 0;k < 26; k++){
        printf("%c : %d\n", 97 + k, count[k]);
    }
    return (0);
}



Measured memory_bytes: 2108
#include <bits/stdc++.h>
#define syosu(x) fixed<<setprecision(x)
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> P;
typedef pair<double,double> pdd;
typedef pair<ll,ll> pll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<double> vd;
typedef vector<vd> vvd;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<string> vs;
typedef vector<P> vp;
typedef vector<vp> vvp;
typedef vector<pll> vpll;
typedef pair<P,int> pip;
typedef vector<pip> vip;
const int inf=1<<30;
const ll INF=1ll<<60;
const double pi=acos(-1);
const double eps=1e-8;
const ll mod=1e9+7;
const int dx[4]={-1,0,1,0},dy[4]={0,-1,0,1};

int a,b;

int main(){
	cin>>a>>b;
	cout<<a-(a>b?1:0)<<endl;
}

Measured memory_bytes: 256
#define rep(i,n) for(ll i=0, i##_len=(n); i<i##_len; ++i)
#define rrep(i,n) for(ll i##_len=(n) ,i=i##_len-1;i>=0;--i)
#define repi(i,a,b) for(ll i=ll(a);i<ll(b);++i)
#define printd(val) std::cout<< #val" = " <<val<<"\n";
#include<bits/stdc++.h>
using ll = long long;
using pii = std::pair<ll,ll>;
using namespace std;
template<class T>T chmin(T& a,T b){if(a>b){a^=b;b^=a;a^=b;return 1;}return 0;}
template<class T>T chmax(T& b,T a){if(a>b){a^=b;b^=a;a^=b;return 1;}return 0;}
template <class T> T gcd(T a, T b){if (a < b) {a ^= b;b ^= a;a ^= b;} return b ? gcd(b, a % b) : a;}
template <class T> T lcm(T a, T b){return a * b / gcd(a, b);}

template<class T> vector<pair<T,T>> duplicator(const vector<T>& input){
    vector<pair<T,T>> out(input.size()-1);
    rep(i,input.size()-1){
        out[i].first =input[i  ];
        out[i].second=input[i+1];
    }
    return(out);
}
vector<char> String_to_vector_char(const string& input){
    vector<char> out(input.size());
    rep(i,input.size()){
        out[i]=input[i];
    }
    return out;
}

int n;
vector<ll> w;
void input(){
    cin>>n;
    w.resize(n);
    rep(i,n){
        cin>>w[i];
    }
}
void src(){
    int s1=0,s2=0;
    s2 = accumulate(w.begin(),w.end(),0);
    int dif = 1e9;
    rep(i,n-1){
        s1  +=w[i];
        s2  -=w[i];
        chmin(dif,abs(s1-s2));
    }
    cout<<dif;
}

int main(int argc,char* argv[]){
    ios::sync_with_stdio(false);
    //ifstream in( argv[1] ); cin.rdbuf(in.rdbuf());
    input();
    src();    
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
typedef long long ll;
using namespace std;


// 以下はpairを用いた解法
//
//ll n, k, a, b;
//vector < pair<ll,ll> > vec;
//
//int main() {
//    cin >> n >> k;
//    for (int i = 0; i < n; i++) {
//        cin >> a >> b;
//        vec.push_back(make_pair(a,b));
//    }
//    sort(vec.begin(), vec.end());
//    for (int i = 0; i < n; i++) {
//        k -= vec[i].second;
//        if (k <= 0) {
//            cout << vec[i].first << endl;
//            break;
//        }
//    }
//
//    return 0;
//}


// 以下はバケツソートを用いた解法
const int AMAX = 100000;
ll cnt[AMAX+1];

int main(void) {
    int N;
    ll K;
    cin >> N >> K;

    for (int i = 0; i < N; ++i) {
        int A, B;
        cin >> A >> B;
        cnt[A] += B;
    }

    for (int ans = 1; ans <= AMAX; ++ans) {
        if (K <= cnt[ans]) {
            cout << ans << endl;
            break;
        }
        K -= cnt[ans];
    }

    return 0;
}

Measured memory_bytes: 1024
S = input()
a = ['R', 'U', 'D']
b = ['L', 'U', 'D']
for i in range(len(S)):
    if i % 2 != 0:
        if not S[i] in b:
            break
    else:
        if not S[i] in a:
            break
else:
    print('Yes')
    exit()
print('No')

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

int n;
vector<vector<int>> graph;
vector<int> ord, low;
vector<pair<int, int>> bridge;

void dfs(int v, int p, int& k) {
    ord[v] = low[v] = k++;
    for (int u : graph[v]) {
        if (u == p) continue;
        else if (ord[u] == -1) {
            dfs(u, v, k);
            low[v] = min(low[v], low[u]);
            if (low[u] == ord[u]) {
                bridge.emplace_back(v, u);
            }
        }
        else {
            low[v] = min(low[v], low[u]);
        }
    }
}

void build() {
    ord.assign(n, -1);
    low.resize(n);

    int k = 0;
    dfs(0, -1, k);
}

int main() {
    int V, E;
    cin >> V >> E;
    graph.resize(V);
    for (int i = 0; i < E; ++i) {
        int s, t;
        cin >> s >> t;
        graph[s].push_back(t);
        graph[t].push_back(s);
    }

    n = V;
    build();
    for (auto&& e : bridge) {
        if (e.first > e.second) swap(e.first, e.second);
    }
    sort(bridge.begin(), bridge.end());
    for (auto&& e : bridge) {
        cout << e.first << ' ' << e.second << endl;
    }
}


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

	public static void main(String[] args) {
		// TODO Auto-generated method stub
		Scanner sc = new Scanner(System.in);
		int a = sc.nextInt();
		int b = sc.nextInt();
		int c = sc.nextInt();
		int ch = 0;
		for(int i = 1;i < 10000;i++) {
			if(c == a*i % b) {
				System.out.println("YES");
				ch =1;
				break;
			}
		}
		if(ch == 0) {
			System.out.println("NO");
		}
	}

}


Measured memory_bytes: 21844
#include <cmath>
#include <cstdio>
#include <vector>
#include <iostream>
#include <algorithm>
#include <queue>
#include <string>
#include <set>
#include <map>
#define REP(i,n) for(ll i = 0; i < (ll)n; i++)
#define INF 1000000000000000
using namespace std;
typedef long long ll;
typedef double db;
typedef string str;

int main(){
  ll n,k;
  cin >> n >> k;
  if(n%k==0){
    cout << 0 << endl;
  }else{
    cout << 1<< endl;
  }
  return 0;
}


Measured memory_bytes: 256
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <cmath>

const int MaxN = 2e5;
using namespace std;

int a[MaxN + 5], p[MaxN + 5];
int main() 
{
	int n;
	while(~scanf("%d", &n)) {
		for (int i = 1; i <= n; i++) scanf("%d", &a[i]), p[a[i]] = i;
		int t = 1, res = 0;
		for (int i = 2; i <= n; i++) {
			if(p[i] > p[i - 1]) t++; else t = 1;
			res = max(res, t);
		}
		if(n == 1) res = n;
		printf("%d\n", n - res);
	}
}

Measured memory_bytes: 1664
#!/bin/bash

read K
read S

s_no_nagasa=$(echo $S | awk '{print length($0)}')

if [ ${s_no_nagasa} -le $K ]; then
  echo $S
elif [ ${s_no_nagasa} -gt $K ]; then
  echo "$(echo $S | awk -v K=${K} '{print substr($0, 0, K)}')..."
fi

Measured memory_bytes: 4212
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int maxn = 200005;
const int maxm = maxn*2;
const int inf = 0x3f3f3f3f;
const ll mod = 1e9 + 7;

int vis[maxn];
int main() {
	int n,k;
	cin>>n>>k;
	for(int i = 1;i<=n;i++) vis[i%k]++;
	ll ans = 0;
	for(int  i = 1;i<=n;i++) {
		if(i%k==0) ans += 1ll*vis[0]*vis[0];
		else if(i%k*2==k) ans +=1ll*vis[k/2]*vis[k/2];
	}
	cout<<ans;
}

Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define FOR(i, s, e) for (int i = (int)(s); i <= (int)(e); i++)
#define printYesNo(is_ok) puts(is_ok ? "Yes" : "No");
#define printVector(v) rep(i, v.size()) cout << v[i] << endl;

int main()
{
  string S;
  cin >> S;
  int ans = 700;
  rep(i, 3)
  {
    if (S[i] == 'o')
      ans += 100;
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 256
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;


public class Main {

	private static final int BIG_NUM  = 2000000000;

	public static void main(String[] args) {

		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));

		int H,W;

		String work[] = new String[2];

		while(true){

			try {
				work = br.readLine().split("[\\s]+");
				if(work[0].equals("0") && work[1].equals("0"))break;

				H = Integer.parseInt(work[0]);
				W = Integer.parseInt(work[1]);

				for(int row = 0; row < H; row++){
					for(int col = 0; col < W; col++){
						System.out.printf("#");
					}
					System.out.printf("\n");
				}

				System.out.printf("\n");

			} catch (IOException e) {
				e.printStackTrace();
			}
		}
	}
}



Measured memory_bytes: 60816
#include <bits/stdc++.h>
using namespace std;
#define maxn 100010
long long a[maxn], b[maxn];
int main()
{
	int n;
	scanf("%d", &n);
	for (int i = 0; i < n; i++) {
		scanf("%lld%lld", &a[i], &b[i]);
	}
	long long s = 0;
	for (int i = n - 1; i >= 0; i--) {
		a[i] += s;
		b[i] = (a[i] / b[i] + (a[i] % b[i] != 0)) * b[i];
		s += b[i] - a[i];
	}
	printf("%lld\n", s);
}

Measured memory_bytes: 1792
#include<iostream>
#include<vector>
#include<algorithm>
#include<queue>
#include<iomanip>
#include <math.h>
using namespace std;
int main(){
    long long int n,k,a=0,b=0;
    cin>>n>>k;
    for(long long int i=1;i<n+1;i++){
        if(i%k==0){
            a++;
        }
        if((k%2==0&&i%k==k/2)){
            b++;
        }
    }
    cout<<a*a*a+b*b*b<<endl;
    return 0;
}


Measured memory_bytes: 3612
#include <bits/stdc++.h>
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define SIZE_OF_ARRAY(array) (sizeof(array)/sizeof(array[0]))

using namespace std;

int main(){
    long long int n;
    cin >> n;
    map<string,long long int> m;
    long long int cnt = 0;
    string s;
    rep(i,n) {
        cin >> s;
        sort(s.begin(), s.end());
        if(m[s] == 0) {
            m[s] = 1; 
        } else {
            cnt += m[s];
            m[s] += 1; 
        }
        


    }
    

    cout << cnt << endl;
    
}

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

const int maxn(1e5 + 5);
const int mod(1e9 + 7);

inline void Inc(int &x, int y) {
    x = x + y >= mod ? x + y - mod : x + y;
}

inline void Dec(int &x, int y) {
    x = x - y < 0 ? x - y + mod : x - y;
}

inline int Add(int x, int y) {
    return x + y >= mod ? x + y - mod : x + y;
}

inline int Sub(int x, int y) {
    return x - y < 0 ? x - y + mod : x - y;
}

int n, cir[maxn], cnt, fa[maxn], vis[maxn], len, d[maxn], in[maxn];
int ans, f[maxn], a[maxn], chain[maxn], que[maxn << 1];

inline void GetCircle() {
	int i;
	for (i = 1; i <= len; ++i) if (d[que[i]] ^ 1) return;
	cir[++cnt] = len;
	for (i = 1; i <= len; ++i) vis[que[i]] = 2;
}

void Dfs1(int u) {
	int cur;
	vis[u] = 1, in[u] = 1;
	if (!vis[a[u]]) fa[a[u]] = u, Dfs1(a[u]);
	else if (in[a[u]]) {
		len = 0;
		for (cur = u; ; cur = fa[cur]) {
			que[++len] = cur, vis[cur] = 3;
			if (cur == a[u]) break;
		}
		GetCircle();
	}
	in[u] = 0;
}

void Dfs2(int u) {
	chain[a[u]] = chain[u] + 1;
	if (vis[a[u]] > 1) return;
	Dfs2(a[u]);
}

int Solve(int x) {
	int cur, i, j, ret = 1;
	que[len = 1] = x;
	for (cur = a[x]; cur ^ x; cur = a[cur]) que[++len] = cur;
	reverse(que + 1, que + len + 1), cur = len + len;
	for (i = 1; i <= len; ++i) vis[que[i]] = 4, que[len + i] = que[i];
	for (i = 1; i <= len; ++i)
		if (chain[que[i]]) {
			for (j = i + 1; j <= cur && !chain[que[j]]; ++j);
			if (chain[que[i]] > j - i) puts("0"), exit(0);
			if (chain[que[i]] < j - i) Inc(ret, ret);
			i = j - 1;
		}
	return ret;
}

int main() {
	int i, j, k, ret = 1;
	scanf("%d", &n);
	for (i = 1; i <= n; ++i) scanf("%d", &a[i]), ++d[a[i]];
	for (i = 1; i <= n; ++i) if (!d[i]) Dfs1(i);
	for (i = 1; i <= n; ++i) if (!vis[i]) Dfs1(i);
	for (i = 1; i <= n; ++i)
		if ((vis[i] > 1 && d[i] > 2) || (vis[i] == 1 && d[i] > 1)) return puts("0"), 0;
	sort(cir + 1, cir + cnt + 1);
	for (i = 1; i <= n; i = j) {
		for (j = i; j <= n && cir[j] == cir[i]; ++j);
		f[i - 1] = 1;
		for (k = i; k < j; ++k) {
			f[k] = f[k - 1];
			if (cir[i] > 1 && (cir[i] & 1)) Inc(f[k], f[k - 1]);
			if (k > i) Inc(f[k], (ll)f[k - 2] * (k - i) % mod * cir[i] % mod);
		}
		ret = (ll)ret * f[j - 1] % mod;
	}
	for (i = 1; i <= n; ++i) if (vis[i] == 1) vis[i] = 0;
	for (i = 1; i <= n; ++i) if (!d[i]) Dfs2(i);
	for (i = 1; i <= n; ++i) if (vis[i] == 3) ret = (ll)ret * Solve(i) % mod;
	printf("%d\n", ret);
	return 0;
}

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

int main()
{
	int H=0 , W=0 ;
	while(true)
	{
		cin >> H >> W ;
		if(H==0&&W==0) break ;

		for(int i=0 ; i<H ; i++)
		{
			for(int ii=0 ; ii<W ; ii++)
			{
				if((i+ii)%2==0)
				{
					cout << "#" ;
				}
				else if((i+ii)%2==1)
				{
					cout <<  "." ;
				}
			}
			cout << endl ;
		}
		cout << endl ;
	}
	return 0 ;
}



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

int main()
{
   int N,type = 0;
   cin >> N;
   for(int i=0;i<N;i++)
   {
      char c;
      cin >> c;
      if (c=='Y') type = 1;
   }

   if (type==0) cout << "Three" << endl;
   else cout << "Four" << endl;
}

Measured memory_bytes: 256
import java.util.*;

public class Main {
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    int N = sc.nextInt();
    int N1 = N % 10;
    int N2 = (N % 100 - N1) /10;
    int N3 = (N % 1000 - N2 - N1) /100;
    int N4 = N / 1000;
    if (N1 == N2 && N2 == N3) {
      System.out.println("Yes");
    } else if (N2 == N3 && N3 == N4) {
      System.out.println("Yes");
    } else {
      System.out.println("No");
    }
  }
}

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

#define rep(i,a,b) for(int i=a;i<b;i++)
#define repd(i,a,b) for(int i=a;i>=b;i--)
#define fore(i,a) for(auto &i:a)
#define all(x) (x).begin(),(x).end()
using namespace std;
void _main(); int main() { cin.tie(0); ios::sync_with_stdio(false); _main(); }
typedef long long ll; const int inf = INT_MAX / 2; const ll infl = 1LL << 60; const ll MOD = 1000000007;
template<class T>bool chmax(T& a, const T& b) { if (a < b) { a = b; return 1; } return 0; }
template<class T>bool chmin(T& a, const T& b) { if (b < a) { a = b; return 1; } return 0; }

//---------------------------------------------------------------------------------------------------
void _main() {
    ll N, M; cin >> N >> M;
    vector<pair<ll, ll>> ng(M);
    rep(i, 0, M) {
        ll x,y;
        cin >> x >> y;
        ng[i] = make_pair(y, x);
    }
    sort(all(ng));
    ll count = 0;
    ll end = 0;
    rep(i, 0, M) {
        if (ng[i].second >= end) {
            end = ng[i].first;
            ++count;
        }
    }
    cout << count << endl;
}

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

import sys
import math
from bisect import bisect_right as br
from bisect import bisect_left as bl
sys.setrecursionlimit(2147483647)
from heapq import heappush, heappop,heappushpop
from collections import defaultdict
from itertools import accumulate
from collections import Counter
from collections import deque
from operator import itemgetter
from itertools import permutations
mod = 10**9 + 7
inf = float('inf')
def I(): return int(sys.stdin.readline())
def LI(): return list(map(int,sys.stdin.readline().split()))

n = input()
ans = ''
for i in n:
    if i == '1':
        ans += '9'
    elif i == '9':
        ans += '1'
    else:
        ans += i
print(ans)

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

typedef long long ll;
typedef pair<int, int> P;
#define MOD 1000000007
#define INF (1 << 30)
#define REP(i, m, n) for(int i = (int)m; i < (int)n; ++i)
#define rep(i, n) REP(i, 0, n)


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

    rep(i, 3) {
        int ih, im, is, oh, om, os;
        cin >> ih >> im >> is >> oh >> om >> os;
        int in = 3600*ih + 60*im + is;
        int out = 3600*oh + 60*om + os;
        int tmp = out - in;
        int resh = tmp/3600;
        tmp -= 3600*resh;
        int resm = tmp/60;
        tmp -= 60*resm;

        cout << resh << " " << resm << " " << tmp << '\n';
    }
    return 0;
}


Measured memory_bytes: 3180
#include<iostream>
#include<algorithm>
#include<string>
#include<vector>
#include<stack>
#include<queue>
#include<unordered_map>
using namespace std;
int main(){
    int N;
    int A[100010], B[100010];
    cin >> N;
    
    long long ans = 0;
    
    for(int i = 0;i <= N;i++){
        cin >> A[i];
    }
    
    for(int i = 0;i < N;i++){
        cin >> B[i];
    }
    
    for(int i = 0;i < N;i++){
        if(B[i] >= A[i] + A[i+1]){
            ans += A[i] + A[i+1];
            A[i+1] = 0;
        }
        else if (B[i] >= A[i]){
            ans += B[i];
            A[i+1] -= (B[i] - A[i]);
        }
        else{
            ans += B[i];
        }
        
    }
    cout << ans;
}


Measured memory_bytes: 1024
n,m = gets.split.map &:to_i

p = []

m.times{
	p << ( gets.split.map(&:to_i) << 0)
}

ps = p.sort{ |a, b| a[0] != b[0] ? a[0] <=> b[0] : a[1] <=> b[1] }

temp_p = ps[0][0]
count = 0
ps.each{ |x|
	if temp_p == x[0] then
		count += 1
		x[2] = count
	else
		temp_p = x[0]
		count = 1
		x[2] = count
	end
}

p.each{ |x|
	puts sprintf("%06d%06d", x[0], x[2])
}


Measured memory_bytes: 12396
import java.io.BufferedReader;
import java.io.InputStreamReader;

public class Main {

	public static void main(String[] args) {
		try {
			BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
			String str;
			while ((str = br.readLine()) != null) {
				String capital = str.toUpperCase();
				System.out.println(capital);
			}

		} catch (Exception e) {
			System.out.println(e);
		}
	}

}

Measured memory_bytes: 24084
import java.io.*;
import java.util.Arrays;
import java.util.Comparator;
import java.util.StringTokenizer;


public class Main {


    private void solve(InputReader in, PrintWriter out) {
        Integer[] arr = new Integer[3];
        for (int i = 0; i < 3; i++) {
            arr[i] = in.nextInt();
        }
        Arrays.sort(arr, Comparator.reverseOrder());
        out.println(Integer.parseInt("" +arr[0] + arr[1] +"") + arr[2]);


    }


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

    private void run() {
        try (
                InputReader in = new InputReader(System.in);
                PrintWriter out = new PrintWriter(System.out)) {
            solve(in, out);
        }
    }


    static class InputReader implements AutoCloseable {
        private BufferedReader reader;
        private StringTokenizer tokenizer;

        public InputReader(InputStream stream) {
            reader = new BufferedReader(new InputStreamReader(stream), 32768);
            tokenizer = null;
        }

        public String next() {
            while (tokenizer == null || !tokenizer.hasMoreTokens()) {
                try {
                    tokenizer = new StringTokenizer(reader.readLine());
                } catch (IOException e) {
                    throw new RuntimeException(e);
                }
            }
            return tokenizer.nextToken();
        }


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

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

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

        @Override
        public void close() {

        }
    }

}


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

int main()
{
    int n;
    cin >> n;
    int x[n];
    int maxPoint = 0;
    for (int i = 0; i < n; i++) {
        cin >> x[i];
        maxPoint = max(maxPoint, x[i]);
    }
    int minPoints = INT_MAX;
    for (int i = 0; i <= maxPoint; i++ ) {
        int points = 0;
        for (int j = 0; j < n; j++) {
            points += pow((x[j] - i), 2);
        }
        minPoints = min(minPoints, points);
    }
    cout << minPoints;
    return 0;
}


Measured memory_bytes: 256
N =int(input())
A =[int(i) for i in input().split()]
B =[int(j) for j in input().split()]
ans =0
for i in range(N):
  x=B[i]-A[i]
  if x <= 0:
    ans += B[i]
  if x > 0:
    ans += A[i]
    if A[i+1] >= x:
      A[i+1] -= x
      ans +=x
    else:
      ans += A[i+1]
      A[i+1] =0
      
      
print(ans)  
  

Measured memory_bytes: 18624
#include <cstdio>
#include <cmath>
#include <iostream>
#include <sstream>
#include <string>
#include <vector>
#include <map>
#include <queue>
#include <algorithm>

#ifdef _DEBUG
#define DMP(x) cerr << #x << ": " << x << "\n"
#else
#define DMP(x) ((void)0)
#endif

const int MOD = 1000000007, INF = 1111111111; 
using namespace std;
typedef long long lint;

int main() {

	cin.tie(nullptr);
	ios::sync_with_stdio(false);

	int N, K;
	cin >> N >> K;

	vector<lint> p_x(1), n_x;
	lint x_tmp;
	for (int i = 0; i < N; i++) {

		cin >> x_tmp;

		if (x_tmp < 0) n_x.emplace_back(-x_tmp);
		else if (x_tmp == 0) K--;
		else p_x.emplace_back(x_tmp);

	}
	n_x.emplace_back(0);
	reverse(n_x.begin(), n_x.end());

	lint ans = INF;
	for (int i = 0; i <= K; i++) {
		if (i < (int)p_x.size() && K - i < (int)n_x.size()) ans = min(ans, min(2 * p_x[i] + n_x[K - i], p_x[i] + 2 * n_x[K - i]));
	}

	cout << ans << "\n";

	return 0;
}

Measured memory_bytes: 1656
#include <iostream>
#include <queue>

int main(){
	int n,m;
	while(std::cin >> n >> m){
		if(n == 0 && m == 0){
			break;
		}
		std::priority_queue<int> vegetable;
		int each_price;
		for(int i = 0; i < n; ++i){
			std::cin >> each_price;
			vegetable.push(each_price);
		}
		int sum_price = 0;
		for(int i = 0; i < n; ++i){
		    if((i % m) != (m - 1)){
	  	        sum_price += vegetable.top();
		    }
		    vegetable.pop();
		}
		std::cout << sum_price << std::endl;
	}
	return 0;
}

Measured memory_bytes: 1228
#include <iostream>
#include <vector>
using namespace std;
long long ans;
int main(){
  long long N,M;
  cin >> N >> M;
  if(N == 1 && M == 1){
    ans = 1;
  } else if(N == 1 || M == 1){
    ans = N*M -2;
  } else {
    ans = (N-2)*(M-2);
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <cmath>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <iomanip>
using namespace std;
typedef long long ll;
typedef vector<int> VI;
typedef vector<ll> VL;
typedef vector<string> VS;
typedef vector< vector<int> > VVI;
typedef vector< vector<ll> > VVL;
typedef pair<int,int> PII;
typedef pair<ll,ll> PLL;
#define rep(i,n) for(int i=0;i<(n);i++)
#define all(a) (a).begin(),(a).end()
#define pb push_back
#define mp make_pair
#define ub upper_bound
#define lb lower_bound
 
int main(){
  string S;
  cin>>S;
  VI A(3);
  rep(i,S.size()) A[S[i]-'a']++;
  sort(all(A));
  if(A[2]-A[0]>1) cout<<"NO"<<endl;
  else cout<<"YES"<<endl;
}

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

int main() {
  int D;
  cin >> D;
  string s;
  
  if(D == 25) s = "Christmas";
  else if(D == 24) s = "Christmas Eve";
  else if(D == 23) s = "Christmas Eve Eve";
  else if(D == 22) s = "Christmas Eve Eve Eve";
  
  cout << s << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <sstream>
#include <cmath>
#include <fstream>

using namespace std;

int length, angle, currentAngle;
double px, py;

void walk(void)
{
	px += length * cos (currentAngle * M_PI/180. );
	py += length * sin (currentAngle * M_PI/180. );
	currentAngle -= angle;
}

int main()
{
//	cut here before submit 
//	freopen("testcase.th", "r", stdin);
	string str = "";
	px = py = 0.;
	currentAngle = 90;

	while (getline (cin, str ) ){
		str = str.replace (str.find (','), 1, " " );
		stringstream ss(str);
		ss >> length >> angle;		
		if (length == 0 && angle == 0 ){
			break;
		} // end if
		walk();
	} // end while

	cout << (int)px << endl;
	cout << (int)py << endl;	
	
	return 0;
}

Measured memory_bytes: 824
#include <bits/stdc++.h>
using namespace std;
int i,j,n,m,p,x,t[100],sum;
int main(){
  for(cin>>n;i<n;sum+=t[i],i++)cin>>t[i];
  for(i=0,cin>>m;i<m;cout<<sum-t[p-1]+x<<endl,i++)cin>>p>>x;
}

Measured memory_bytes: 256
use std::io::*;
use std::str::FromStr;

#[allow(unused_macros)]
macro_rules! scan {
  ($e:expr; $t:ty) => {
    $e.get::<$t>()
  };
  ($e:expr; $($t:ty), *) => {
    ($($e.get::<$t>(),)*)
  }
}

struct Scanner<R: Read> {
  reader: R
}

#[allow(dead_code)]
impl<R: Read> Scanner<R> {
  fn new(reader: R) -> Scanner<R> {
    Scanner { reader: reader }
  }
  fn safe_get<T: FromStr>(&mut self) -> Option<T> {
    let token = self.reader.by_ref().bytes().map(|c| c.unwrap() as char)
      .skip_while(|c| c.is_whitespace())
      .take_while(|c| !c.is_whitespace())
      .collect::<String>();
    if token.is_empty() { None } else { token.parse().ok() }
  }
  fn get<T: FromStr>(&mut self) -> T {
    if let Some(v) = self.safe_get() { v } else {
      writeln!(stderr(), "Terminated with EOF").unwrap();
      std::process::exit(0);
    }
  }
}

fn main() {
  let cin = stdin();
  let cin = cin.lock();
  let mut sc = Scanner::new(cin);
  let (_, s, k) = scan!(sc; i32, String, usize);
  let ch = s.chars().nth(k - 1).unwrap();
  println!("{}", s.chars().map(|c| if c == ch { c } else { '*' }).collect::<String>());
}


Measured memory_bytes: 4352
import itertools
import math
import string
import collections
from collections import Counter
from collections import deque
import sys
sys.setrecursionlimit(2*10**5)
INF = 2**60


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


def nCr(n, r):
    return math.factorial(n)//(math.factorial(n-r)*math.factorial(r))


def has_duplicates2(seq):
    seen = []
    for item in seq:
        if not(item in seen):
            seen.append(item)
    return len(seq) != len(seen)


def divisor(n):
    divisor = []
    for i in range(1, n+1):
        if n % i == 0:
            divisor.append(i)
    return divisor


# coordinates
dx = [-1, -1, -1, 0, 0, 1, 1, 1]
dy = [-1, 0, 1, -1, 1, -1, 0, 1]
a, b, c, d = map(int, input().split())
while((c > 0)or(a > 0)):
    c = c-b
    a = a-d
    if c <= 0:
        print('Yes')
        break
    if a <= 0:
        print('No')
        break


Measured memory_bytes: 68672
#include <bits/stdc++.h>
#include <math.h>
#include <vector>
#include <queue>
#include <iomanip>
#include <string>
#include <algorithm>
using namespace std;
using Graph = vector<vector<int>>;
#define rep(i,n) for(int i=0;i<n;i++)
#define rep_1 (i,j,n) for(int i=j;i<n;i++)
typedef long long ll;
const ll l_INF = 1010101010101010;
const int INF = 1010101010;
const int dx[4] = {-1,0,1,0};
const int dy[4] = {0,-1,0,1};
using vi = vector<int>;
using vll = vector<ll>;
using vvi = vector<vi>;
using vvll = vector<vll>;
using pii = pair<int,int>;
using pll = pair<ll,ll>;
int n,m;

struct UnionFind{
  vector<int> r;

  UnionFind(int n){
    r=vector<int>(n,-1);
  }
  int root(int x){
    if(r[x]<0) return x;
    return r[x]=root(r[x]);
  }
  bool unite(int x, int y){
    x=root(x),y=root(y);
    if(x==y) return false;
    if(r[x]<r[y]) swap(x,y);
    r[x]+=r[y];
    r[y]=x;
    return true;
  }
  int size(int x){
    return -r[root(x)];
  }
};

int main(){
  cin>>n>>m;
  int ans=0;
  vi a(m),b(m);
  rep(i,m){
    cin>>a[i]>>b[i];
    a[i]--;b[i]--;
  }
  rep(i,m){
    UnionFind UF(n);
    rep(j,m){
      if(j==i) continue;
      UF.unite(a[j],b[j]);
    }
    bool bridge=false;
    /*rep(j,n){
      if(UF.root(j+1)!=0){
        bridge=true;
        cout<<UF.root(j+1)<<" ";
      }
    }*/
    int x = UF.root(0);
    rep(j,n-1){
      if(UF.root(j+1)!=x) bridge=true;
    }
    if(bridge) ans++;
  }
  //cout<<endl;
  cout<<ans<<endl;
}

Measured memory_bytes: 3552
#define mod 1000000007
#include<time.h>
#include<stdio.h>
#include<string.h>
#include<math.h>
#include<map>
#include<queue>
#include<iostream>
#include<vector>
#include<algorithm>
using namespace std;
typedef long long ll;
const ll INF=0x7fffffffffffffff;
const int inf=0x7fffffff;
const int N=2e5+5;
clock_t start,finish;
void time_in(){start=clock();}
void time_out(){finish=clock();double tim=(double)(finish-start)/CLOCKS_PER_SEC;printf("Running time is %lf\n",tim);}
ll mul(ll a,ll b){ll s=0;while(b){if(b&1)s=(s+a)%mod;a=(a<<1)%mod;b>>=1;}return s%mod;}
ll pow_mul(ll a,ll b){ll s=1;while(b){if(b&1)s=mul(s,a);a=mul(a,a);b>>=1;}return s;}
ll poww(ll a,ll b){ll s=1;while(b){if(b&1)s=(s*a)%mod;a=(a*a)%mod;b>>=1;}return s%mod;}
int t,cas;
int n,m,k;
int main()
{
	int x,y;
	while(~scanf("%d%d",&n,&x))
	{
		int ans=1;
		int sum=0;
		int v=1;
		while(n--)
		{
			scanf("%d",&y);
			if(v==1&&sum+y<=x)
			{
				sum+=y;
				ans++;
			}
			else v=0;
		}
		printf("%d\n",ans);
	}
}


Measured memory_bytes: 256
N = int(input())
A = list(map(int, input().split()))
color = [0] * 9

for i in range(N):
    if A[i] <= 399:
        color[0] += 1
    elif 400 <= A[i] and A[i] <= 799:
        color[1] += 1
    elif 800 <= A[i] and A[i] <= 1199:
        color[2] += 1
    elif 1200 <= A[i] and A[i] <= 1599:
        color[3] += 1
    elif 1600 <= A[i] and A[i] <= 1999:
        color[4] += 1
    elif 2000 <= A[i] and A[i] <= 2399:
        color[5] += 1
    elif 2400 <= A[i] and A[i] <= 2799:
        color[6] += 1
    elif 2800 <= A[i] and A[i] <= 3199:
        color[7] += 1
    else:
        color[8] += 1

num = 0
for i in range(8):
    if color[i] != 0:
        num += 1

ans = [max(1,num), num + color[8]]
print(" ".join(str(s) for s in ans))

Measured memory_bytes: 3064
#include <bits/stdc++.h>
#define all(x) x.begin(), x.end()
using namespace std;
using ll = long long;
using pii = pair<int, int>;
const int MN = 305 + 5;
int N,K,a[MN];
ll dp[MN][MN];

int main() {
    ios_base::sync_with_stdio(0), cin.tie(0);
    memset(dp,0x3f,sizeof(dp));
    cin>>N>>K;
    for(int i=1; i<=N; i++) cin>>a[i];
    for(int k=0; k<=K; k++) dp[0][k]=0;
    for(int i=1; i<=N+1; i++) {
        for(int k=0; k<=min(i-1,K); k++) {
            for(int j=0; j<=k; j++) {
                dp[i][k]=min(dp[i][k],dp[i-1-j][k-j]+max(0,a[i]-a[i-1-j]));
            }
        }
    }
    cout<<*min_element(dp[N+1],dp[N+1]+K+1)<<'\n';
    return 0;
}

Measured memory_bytes: 4388
// https://atcoder.jp/contests/abc126/tasks/abc126_a
#include <bits/stdc++.h>
#define all(v) v.begin(), v.end()
using namespace std;
typedef long long ll;

int main()
{
    int n, k;
    cin >> n >> k;
    string text;
    cin >> text;
    for (int i = 0; i < text.size(); i++)
    {
        if (i + 1 == k)
            cout << (char)(text[i] + 'a' - 'A');
        else
            cout << text[i];
    }
    cout << endl;
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N=2e5+5;
int n,l,a[N],b[N];
ll sum1[N],sum2[N];
int main()
{
    scanf("%d%d",&l,&n);
    for(int i=1;i<=n;i++)
        scanf("%d",&a[i]),b[n-i+1]=l-a[i];
    for(int i=1;i<=n;i++) sum1[i]=sum1[i-1]+a[i]*2,sum2[i]=sum2[i-1]+b[i]*2;
    ll ans=0;
    for(int i=1;i<=n;i++)
    {
        int t=n-i;
        ll res=sum1[i+t/2]-sum1[i-1]+sum2[t/2+t%2];
        if(t&1) res-=b[t/2+t%2];
        else res-=a[i+t/2];
        ans=max(ans,res);
        res=sum2[i+t/2]-sum2[i-1]+sum1[t/2+t%2];
        if(t&1) res-=a[t/2+t%2];
        else res-=b[i+t/2];
        ans=max(ans,res);
    }
    printf("%lld\n",ans);
}


Measured memory_bytes: 4992
import sys

sys.setrecursionlimit(10 ** 7)
f_inf = float('inf')
mod = 10 ** 9 + 7


def resolve():
    n, k = map(int, input().split())
    H = list(map(int, input().split()))

    dp = [f_inf for _ in range(n)]
    dp[0] = 0
    for i in range(1, n):
        for j in range(1, k + 1):
            if i - j >= 0:
                dp[i] = min(dp[i], dp[i - j] + abs(H[i] - H[i - j]))

    print(dp[-1])


if __name__ == '__main__':
    resolve()


Measured memory_bytes: 58848
import sys

sys.setrecursionlimit(10 ** 7)
f_inf = float('inf')
mod = 10 ** 9 + 7


def resolve():
    n = int(input())
    s = input()

    r = s.count("R")
    g = s.count("G")
    b = s.count("B")

    res = r * g * b
    for i in range(n):
        for j in range(i, n):
            k = 2 * j - i
            if 0 <= k < n:
                if s[i] != s[j] and s[i] != s[k] and s[j] != s[k]:
                    res -= 1

    print(res)


if __name__ == '__main__':
    resolve()


Measured memory_bytes: 9152
import std.stdio;
import std.conv;
import std.string;
import std.typecons;
import std.algorithm;
import std.array;
import std.range;
import std.math;
import std.regex : regex;
import std.container;
import std.bigint;


void main()
{
  auto n = readln.chomp.to!int;
  auto f = false;
  foreach (i; 1..n+1) {
    auto d = (i * 1.08).to!int;
    if (d == n) {
      writeln(i);
      return;
    }
  }
  writeln(":(");
}


Measured memory_bytes: 256
import java.util.*;

public class Main {
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    int n = sc.nextInt();
    long[] sum = new long[n];
    long sumb = 0;
    for(int i = 0; i < n; i++) {
      long a = sc.nextLong();
      long b = sc.nextLong();
      sum[i] = (a + b);
      sumb += b;
    }
    Arrays.sort(sum);
    long ans = ((-1) * sumb);
    for(int i = 1; i <= n; i++) {
      if(i % 2 == 1) ans += sum[n - i];
    }
    System.out.println(ans);
  }
}

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

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		
		int n = sc.nextInt();
		int l = sc.nextInt();
		
		String[] input = new String[n];
		
		for (int i=0; i<n; i++) {
			input[i] = sc.next();
		}
		
		Arrays.sort(input);
		
		String result = "";
		for (int j=0; j<n; j++) {
			result += input[j];
		}
		
		System.out.println(result);
		sc.close();
	}

}

Measured memory_bytes: 24912
#include <bits/stdc++.h>
using namespace std;
int main()
{
	double n,m,a1,a2;
	cin>>n>>m>>a1>>a2;
	cout<<fixed<<setprecision(6)<<(n*m*1.0/(2*1.0))<<' ';
	if (n/2.0==a1&&m/2.0==a2)  cout<<1<<endl;
	else cout<<0<<endl;
	return 0;
}

Measured memory_bytes: 256
import sys
s=input()
l=[]
for i in range(2,len(s)-1):
    l.append(s[i])
if l.count("C")!=1:
    print("WA")
    sys.exit()
else:
    k=s[1:s.index("C")]+s[s.index("C")+1:]

if s[0]=="A" and l.count("C")==1 and k==k.lower():
    print("AC")
else:
    print("WA")

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

int main() {
  vector<int> x(100100);
  int n;
  cin >> n;
  for(int i=0;i<n;i++){
    int a;
    cin >> a;
    x.at(a)++;
    x.at(a+1)++;
    x.at(a+2)++;
  }
  sort(x.begin(),x.end());
  reverse(x.begin(),x.end());
  
  cout << x.at(0);
}


Measured memory_bytes: 640
#include<iostream>

using namespace std;

int main()
{
  double A, B;

  cin >> A >> B;

  long int C = (A + B)/2;
  if ((A + B)/2 - C == 0)
  {
    cout << C << endl;
  }else{
    cout << "IMPOSSIBLE" << endl;
  }
  return 0;

}


Measured memory_bytes: 256
N = int(input())
D,X = map(int, input().split())
A = []
for n in range(N):
  A.append(int(input()))

ate_cnt = 0
for a in A:
  target_day = 1
  while target_day <= D:
    ate_cnt += 1
    target_day += a

ans = X+ate_cnt
print(ans)

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

typedef long long ll;
#define REP(i,n) for(int i=0,_n=(int)(n);i<_n;++i)
#define ALL(v) (v).begin(),(v).end()
#define CLR(t,v) memset(t,(v),sizeof(t))
template<class T1,class T2>ostream& operator<<(ostream& os,const pair<T1,T2>&a){return os<<"("<<a.first<<","<<a.second<< ")";}
template<class T>void pv(T a,T b){for(T i=a;i!=b;++i)cout<<(*i)<<" ";cout<<endl;}
template<class T>void chmin(T&a,const T&b){if(a>b)a=b;}
template<class T>void chmax(T&a,const T&b){if(a<b)a=b;}


int nextInt() { int x; scanf("%d", &x); return x;}

const int MAX_V = 20000+5;
typedef int CAP;
const CAP INF = (int)1e9;

struct Edge{ int dst; CAP cap; int rev; };
vector<Edge> adj[MAX_V];
int level[MAX_V];
int done[MAX_V];
void clearedge() { REP(i, MAX_V) adj[i].clear(); }
void addedge(int u, int v, CAP c1, CAP c2) {
  adj[u].push_back( (Edge){v, c1, (int)adj[v].size() + (u == v)} );
  adj[v].push_back( (Edge){u, c2, (int)adj[u].size() - 1} );
}

CAP dinic_dfs(int v, CAP flow, int t) {
  if (v == t || flow == 0) return flow;
  for ( ; done[v] < (int)adj[v].size(); done[v]++) {
    Edge &e = adj[v][done[v]];
    if (level[v] >= level[e.dst]) continue;
    CAP f = dinic_dfs(e.dst, min(flow, e.cap), t);
    if (f > 0) {
      e.cap -= f;
      adj[e.dst][e.rev].cap += f;
      return f;
    }
  }
  return 0;
}

bool dinic_bfs(int s, int t) {
  memset(level, -1, sizeof(level));
  queue<int> q; q.push(s); level[s] = 0;
  while (!q.empty()) {
    int here = q.front(); q.pop();
    for (const Edge &e : adj[here]) {
      if (e.cap > 0 && level[e.dst] == -1) {
        level[e.dst] = level[here] + 1;
        q.push(e.dst);
      }
    }
  }
  return level[t] >= 0;
}

CAP dinic(int s, int t) {
  CAP res = 0;
  while (dinic_bfs(s,t)) {
    memset(done, 0, sizeof(done));
    for (CAP f; (f = dinic_dfs(s, INF, t)) > 0; ) res += f;
  }
  return res;
}

int main2() {
  clearedge();
  int H = nextInt();
  int W = nextInt();
  string m[H];
  REP(i, H) cin >> m[i];

  int s = H+W+1;
  int t = H+W+2;

  REP(i, H) REP(j, W) {
    if (m[i][j] == 'o') {
      addedge(i, j+H, 1, 0);
      addedge(j+H, i, 1, 0);
    }
    if (m[i][j] == 'S') {
      addedge(s, i, INF, 0);
      addedge(s, j+H, INF, 0);
    }
    if (m[i][j] == 'T') {
      addedge(i, t, INF, 0);
      addedge(j+H, t, INF, 0);
    }
  }

  ll ans = dinic(s, t);
  if (ans >= INF/2) ans = -1;
  cout << ans << endl;
  return 0;
}

int main() {
  for (;!cin.eof();cin>>ws)
    main2();
  return 0;
}


Measured memory_bytes: 1536
#include <bits/stdc++.h>
#define syosu(x) fixed<<setprecision(x)
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> P;
typedef pair<double,double> pdd;
typedef pair<ll,ll> pll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<double> vd;
typedef vector<vd> vvd;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<string> vs;
typedef vector<P> vp;
typedef vector<vp> vvp;
typedef vector<pll> vpll;
typedef pair<int,P> pip;
typedef vector<pip> vip;
const int inf=1<<30;
const ll INF=1ll<<60;
const double pi=acos(-1);
const double eps=1e-8;
const ll mod=1e9+7;
const int dx[4]={-1,0,1,0},dy[4]={0,-1,0,1};

int n;
vi a;

int main(){
	cin>>n;
	int A=-1,B=-1;
	a=vi(n);
	for(int i=0;i<n;i++){
		cin>>a[i];
		if(A==-1) A=a[i];
		else if(A!=a[i]&&B==-1) B=a[i];
	}
	if(B==-1&&A==0) cout<<"Yes"<<endl;
	else{
		vi b(n);
		b[0]=A,b[1]=B;
		for(int i=2;i<n;i++) b[i]=b[i-1]^b[i-2];
		bool flag=1;
		if(b[0]!=(b[n-1]^b[n-2])) flag=0;
		if(b[1]!=(b[0]^b[n-1])) flag=0;
		sort(a.begin(),a.end());
		sort(b.begin(),b.end());
		if(a!=b) flag=0;
		cout<<(flag?"Yes":"No")<<endl;
	}
}

Measured memory_bytes: 1024
//package com.zhangyong.algorithm;

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

public class Main {

    FastScanner in;
    PrintWriter out;

    class FastScanner {

        BufferedReader br;
        StringTokenizer st;

        private FastScanner(File f) {
            try {
                br = new BufferedReader(new FileReader(f));
            } catch (FileNotFoundException e) {
                e.printStackTrace();
            }
        }

        private FastScanner(InputStream f) {
            br = new BufferedReader(new InputStreamReader(f));
        }

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

    }

    private void solve() {
        int n, m;
        n = in.nextInt();
        m = in.nextInt();
        String[] str = new String[n];
        for (int i = 0; i < n; i++) {
            str[i] = in.next();
        }
        for (int i = 0; i < m + 2; i++) {
            if (i != m + 1) {
                out.print("#");
            } else {
                out.println("#");
            }
        }
        for (int i = 0; i < n; i++) {
            out.print("#");
            out.print(str[i]);
            out.println("#");
        }
        for (int i = 0; i < m + 2; i++) {
            out.print("#");
        }
    }

    private void run() {
        in = new FastScanner(System.in);
        out = new PrintWriter(System.out);
        solve();
        out.close();
    }

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


Measured memory_bytes: 21460
#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;
  string s;
  cin >> n >> s;
  vector<vector<int> > dp(n + 1, vector<int>(n + 1));
  dp[n - 1][n - 1] = 0;
  int ans = 0;
  for (int i = n - 1; i >= 0; i--) {
    for (int j = n - 1; j >= 0; j--) {
      if (i == j) continue;
      if (s[i] != s[j]) continue;
      dp[i][j] = dp[i + 1][j + 1] + 1;
    }
  }
  rep(i, n) {
    rep(j, n) {
      if (i >=j)continue;
      int now =min(dp[i][j], j-i);
      ans = max(ans, now);
    }
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 98176
#include<bits/stdc++.h>
using namespace std;
#define Yes(n) cout << ((n) ? "Yes" : "No") << endl
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
int main()
{
    int fee,have,ulimit;
    cin >> fee >> have >> ulimit;
    if(ulimit * fee <= have)
    {
        cout << ulimit;
    }
    else
    {
        cout << have / fee;
    }
}

Measured memory_bytes: 256
// " --- IN THE NAME OF ALLAH --- " // ;)
// ------------sphr_agz------------ // ;)

//#pragma GCC optimize("Ofast,no-stack-protector,unroll-loops")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
//#include <ext/pb_ds/assoc_container.hpp>
//#include <ext/pb_ds/tree_policy.hpp> 
#include <bits/stdc++.h>
#include <iostream>
#include <algorithm>
#include <iomanip>
#include <string>
#include <vector>
#include <queue>
#include <deque>
#include <set>
#include <map>
#include <math.h>
#include <cmath>
#include <list>
#include <stack>
#include <bitset>
#include <ctime>
using namespace std;
 
typedef long double ld;
typedef long long int lli;
typedef pair <lli, pair <lli, lli> > pii;
#define pb(x) push_back(x)
#define recout(x) return cout << (x), 0
#define f first
#define s second
#define fast ios::sync_with_stdio(false), cin.tie(0), cout.tie(0)
#define stp(x) cout << setprecision(x) << fixed
#define mk make_pair
const lli N = 1e6 + 10, N2 = 5e3 + 10, delta = 46639, mod = 1e9 + 7, oo = 1e16, LOG = 20;
const ld PI = 3.141592653589793;

//lli a[N];
string t, q;
bool check (string s) {
	string u = s;
	reverse(s.begin(), s.end());
	return u == s;
}

int main(){
	string s;
	cin >> s;
	for (lli i = 0; i < (s.size() - 1) / 2; i++)
		t += s[i];
	for (lli i = (s.size() + 3) / 2 - 1; i < s.size(); i++)
		q += s[i];
	if (check (t) && check (s) && check (q))
		return cout << "Yes", 0;
	cout << "No";
}


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

namespace abc155_c
{
  class Program
  {
    static void Main(string[] args)
    {
      var N = CIn.ReadInt();

      var dic = new Dictionary<string, int>();

      for (int i = 0; i < N; i++)
      {
        var s = CIn.Read();
        if (dic.ContainsKey(s)) dic[s]++;
        else dic.Add(s, 1);
      }

      var list = new List<Result>();

      foreach (var item in dic)
      {
        list.Add(new Result(item.Key, item.Value));
      }

      list.Sort();

      var sb = new StringBuilder();
      sb.AppendLine(list[0].Name);

      for (int i = 1; i < list.Count; i++)
      {
        if (list[i - 1].Count == list[i].Count) sb.AppendLine(list[i].Name);
        else break;
      }

      Console.Write(sb.ToString());
    }
  }

  class Result : IComparable<Result>
  {
    public string Name { get; }
    public int Count { get; }

    public Result(string name, int count)
    {
      Name = name;
      Count = count;
    }

    public int CompareTo(Result other)
    {
      return Count != other.Count ? other.Count.CompareTo(Count) : StringComparer.Ordinal.Compare(Name, other.Name);
    }
  }

  static class CIn
  {
    private static readonly Queue<string> fieldBuffer = new Queue<string>();

    public static string Read()
    {
      if (fieldBuffer.Count == 0)
      {
        foreach (var field in Console.ReadLine().Split())
        {
          fieldBuffer.Enqueue(field);
        }
      }
      return fieldBuffer.Dequeue();
    }

    public static int ReadInt() => int.Parse(Read());
    public static long ReadLong() => long.Parse(Read());
    public static double ReadDouble() => double.Parse(Read());

    public static string[] ReadStringArray(int n)
    {
      var array = new string[n];
      for (var i = 0; i < n; i++)
      {
        array[i] = Read();
      }
      return array;
    }

    public static int[] ReadIntArray(int n)
    {
      var array = new int[n];
      for (var i = 0; i < n; i++)
      {
        array[i] = ReadInt();
      }
      return array;
    }

    public static long[] ReadLongArray(int n)
    {
      var array = new long[n];
      for (var i = 0; i < n; i++)
      {
        array[i] = ReadLong();
      }
      return array;
    }

    public static double[] ReadDoubleArray(int n)
    {
      var array = new double[n];
      for (var i = 0; i < n; i++)
      {
        array[i] = ReadDouble();
      }
      return array;
    }

    public static char[,] ReadCharMatrix(int h, int w)
    {
      var array = new char[h, w];
      for (var i = 0; i < h; i++)
      {
        var l = Console.ReadLine().ToCharArray();
        for (var j = 0; j < w; j++)
        {
          array[i, j] = l[j];
        }
      }
      return array;
    }
  }
}

Measured memory_bytes: 49592
#include<bits/stdc++.h>
/*
g++ -std=c++11 -Wall -g -fsanitize=undefined -D_GLIBCXX_DEBUG arc/arc099/c.cpp
*/
using namespace std;
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define SZ(x) ((int)(x).size())
#define INF (1e16)
typedef long long ll;

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);//おまじないでcin, cout早くする
    int N, K;
    cin >> N >> K;
    if((N - 1)%(K - 1) == 0) cout << (N - 1)/(K - 1) << "\n";
    else cout << (N - 1)/(K - 1) + 1 << "\n"; 
    return 0;
}

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

typedef long long ll;
typedef pair<int, int> pii;

#define rep(i, n) for (int i = 0; i < (n); i++)
#define repp(i, s, e) for (int i = (s); i < (e); i++)
#define all(x) x.begin(), x.end()

#define endl "\n"

void use_cio() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
}

template <class L, class R>
ostream &operator<<(ostream &os, pair<L, R> P) {
  return os << "(" << P.first << "," << P.second << ")";
}
template <class T>
ostream &operator<<(ostream &os, vector<T> V) {
  os << "[";
  for (auto x : V) os << x << ", ";
  return os << "]";
}

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

int main() {
  use_cio();
  ll r, d, x;

  cin >> r >> d >> x;
  rep(i, 10) {
    x = r * x - d;
    cout << x << endl;
  }
}


Measured memory_bytes: 384
import sys
import math
import itertools
import bisect
from copy import copy
from collections import deque,Counter
from decimal import Decimal
def s(): return input()
def k(): return int(input())
def S(): return input().split()
def I(): return map(int,input().split())
def X(): return list(input())
def L(): return list(input().split())
def l(): return list(map(int,input().split()))
def lcm(a,b): return a*b//math.gcd(a,b)
sys.setrecursionlimit(10 ** 9)
mod = 10**9+7
count = 0
ans = 0
inf = float("inf")

n,k=I()
a = l()
b = Counter(a)
c = b.most_common()
x = len(c)-k
for i in range(x):
    count += c[-1][1]
    del c[-1]

print(count)


Measured memory_bytes: 44340