akhauriyash/Code-Regression huggingface dataset:
import java.util.Scanner;

public class Main {

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

        StringBuilder sb = new StringBuilder();
        for(int i = 0 ;i < onEditor.length(); i++){
             char onScreen = onEditor.charAt(i);

             if(onScreen == 'B'){
                if(sb.length() > 0)
                 sb.replace(sb.length() - 1, sb.length(), "");
             }else{
                 sb.append(onScreen);
             }
        }

        System.out.println(sb.toString());
    }
}


Measured memory_bytes: 35736
#include <bits/stdc++.h>
using namespace std;
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);

    int n,a;
    cin>>n>>a;
    int *arr=new int[n];
    for(int i=0;i<n;i++)
    {
        cin>>arr[i];
    }

    sort(arr,arr+n,greater<int>());

    long long int sum=0;
    for(int i=a;i<n;i++)
    {
        sum+=arr[i];
    }

    cout<<sum<<"\n";

    return 0;
}


Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
/*
vector<string> v(n, string(m,"*"));
vector<vector<int>>
*/
int main() {
	int n,b,i;
	cin >> n;
	vector<int> a(n+1);

	for (i = 1; i <= n; i++) {
		cin >> a.at(i);
	}
	b = 1;

	for (i = 1; i <= n; i++) {
		if (a.at(b) == 2)break;
		b = a.at(b);
	}
	if (a.at(b) == 2)cout << i << endl;
	else			cout << -1 << endl;
	return 0;
}

Measured memory_bytes: 640
#include <stdio.h>

int syumid(int,int);

int main()
{
  int x,y,d;

  scanf("%d%d",&x,&y);

  if(x >= y)
    d = syumid(x,y);
  else
    d = syumid(y,x);

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

  return 0;
}

int syumid(int a,int b)
{
  int c;

  while(1){

    c = a%b;
    if(c == 0) break;
    else ;
    a = b;
    b = c;
  }

  return b;
}
  



Measured memory_bytes: 2048
#include<stdio.h>

int main(){
    int a,b,c;
    scanf("%d %d %d",&a,&b,&c);

    a = a + b;
    b = a - b;
    a = a - b;
    a = a + c;
    c = a - c;
    a = a -c;

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

    return 0;
}


Measured memory_bytes: 1728
#include <bits/stdc++.h>
using namespace std;
int main(){
int n,sum=0;
double x_n,y_n,d;
cin>>n>>d;
pair<double,double> tmp; 
map<pair<double,double>,int> M;
for (int i=0;i<n;i++){
	cin>> x_n >> y_n;
	if (sqrt(x_n*x_n+y_n*y_n)<=d){
		sum+=1;
	}
}	
	cout<<sum;
	return 0;
} 

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

const long long int INF = 1e17;

long long int dis[305][305], g[305][305];

int main(void) {
    long long int n, m, l;
    cin >> n >> m >> l;
    for(int i = 1; i <= n; i++) {
        for(int j = 1; j <= n; j++) {
            dis[i][j] = INF;
        }
        dis[i][i] = 0;
    }
    for (int i = 0; i < m; i++) {
        int a, b, c;
        cin >> a >> b >> c;
        dis[a][b] = dis[b][a] = c;
    }
    for (int k = 1; k <= n; k++) {
        for (int i = 1; i <= n; i++) {
            for (int j = 1; j <= n; j++) {
                if (dis[i][k] + dis[k][j] < dis[i][j]) {
                    dis[i][j] = dis[i][k] + dis[k][j];
                }
            }
        }
    }
    for (int i = 1; i <= n; i++) {
        for (int j = 1; j <= n; j++) {
            g[i][j] = dis[i][j] <= l ? 1LL : INF;
        }
        g[i][i] = 0;
    }
    for (int k = 1; k <= n; k++) {
        for (int i = 1; i <= n; i++) {
            for (int j = 1; j <= n; j++) {
                if (g[i][k] + g[k][j] < g[i][j]) {
                    g[i][j] = g[i][k] + g[k][j];
                }
            }
        }
    }
    int q;
    cin >> q;
    
    for (int i = 0; i < q; i++) {
        int s, t;
        cin >> s >> t;
        //if(g[s][t] < INF) cout << g[s][t] - 1 << "\n";
        //else cout << -1 << "\n";
        if (g[s][t] >= INF) {
            cout << -1 << endl;
        } else {
            cout << g[s][t] - 1 << endl;
        }
    }
    
    return 0;
}

Measured memory_bytes: 1920
package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
)

const debug = false

var sc = bufio.NewScanner(os.Stdin)

/*-----------Main-----------*/

func main() {
	N := readI()
	K := readI()
	x := 0
	var ans int
	for i := 0; i < N; i++ {
		x = readI()
		if x <= K-x {
			ans += x * 2
		} else {
			ans += (K - x) * 2
		}
	}
	fmt.Println(ans)

}

/*-----------Utilities-----------*/

func init() {
	if debug {
		testFile, err := os.Open("./test/sample-3.in")
		if err == nil {
			sc = bufio.NewScanner(testFile)
		}

	}
	const maxBuf = 200100
	var buf []byte = make([]byte, maxBuf)
	sc.Split(bufio.ScanWords)
	sc.Buffer(buf, maxBuf)
}

func readS() string {
	sc.Scan()
	return sc.Text()
}

func readI() int {
	sc.Scan()
	r, _ := strconv.Atoi(sc.Text())
	return r
}

func readF() float64 {
	sc.Scan()
	r, _ := strconv.ParseFloat(sc.Text(), 64)
	return r
}


Measured memory_bytes: 1784
#include <bits/stdc++.h>
using namespace std;
#define endl '\n'

typedef long long ll;
typedef vector<ll> vec;
typedef vector<vec> mat;

ll add(ll a, ll b, ll M)
{
  a += b;
  if (a >= M) a -= M;
  return a;
}

ll mul(ll a, ll b, ll M)
{
  ll q = (long double) a * (long double) b / (long double) M;
  ll r = a * b - q * M;
  return (r + 5 * M) % M;
}

mat eye(int n)
{
  mat I(n, vec(n));
  for (int i = 0; i < n; ++i)
  	I[i][i] = 1;
  return I;
}

mat mul(mat A, mat B, ll M)
{
  int l = A.size(), m = B.size(), n = B[0].size();
  mat C(l, vec(n));
  for (int i = 0; i < l; ++i)
    for (int k = 0; k < m; ++k)
      for (int j = 0; j < n; ++j)
      	C[i][j] = add(C[i][j], mul(A[i][k], B[k][j], M), M);
  return C;
}

mat pow(mat A, ll b, ll M)
{
  mat X = eye(A.size());
  for (; b > 0; b >>= 1)
  {
    if (b & 1) X = mul(X, A, M);
    A = mul(A, A, M);
  }
  return X;
}

const ll mod = 1e9+7;

int main()
{
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  
  ll n, k;
  cin >> n >> k;
  mat A(n,vec(n));
  for(int i = 0; i < n; ++i)
    for(int j = 0; j < n; ++j)
      cin >> A[i][j];

  mat B = pow(A, k, mod);
  
  ll ans = 0;
  for(auto &x:B)
    for(auto &y:x)
      ans = (ans + y) % mod;
  
  cout << ans << endl;
}


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

#define pq priority_queue
#define mp make_pair
#define cauto const auto &

#define REP(i, n) for (int i = 0, i##_len = (n); i < i##_len; ++i)
#define all(x) (x).begin(), (x).end()
#define SZ(x) ((int)(x).size())

#define clr(ar, val) memset(ar, val, sizeof(ar))

typedef long long int64;
typedef long long lint;
typedef long long lli;
typedef long long ll;
typedef unsigned int uint;
typedef unsigned long long ull;

typedef pair<int, int> pint;
typedef pair<long, long> plong;
typedef pair<int, int> pii;
typedef pair<ll, int> pli;
typedef pair<int, ll> pil;
typedef pair<ll, ll> pll;

const int iinf = 1 << 29;
const long long linf = 1ll << 61;

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;
}
template <class T = int> T in() {
    T x;
    cin >> x;
    return (x);
}
template <class T> void print(T &x) {
    cout << x << '\n';
    return;
}

template <class T> ll sized_subset(T &comb) {
    T x = comb & -comb, y = x + comb;
    return ((comb & ~y) / x) >> 1 | y;
}

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

int n, a, b, c;
int abuf, bbuf, cbuf;
int l[10];
bool used[10];
ll ans = linf;
ll gousei;

int rec(int index) {
    if (index == n) {
        if(abuf!=0&&bbuf!=0&&cbuf!=0)
        ans = min(ans, (ll)abs(abuf - a) + abs(bbuf - b) + abs(cbuf - c) +
                           gousei * 10);
    } else {
        if (abuf != 0) {
            gousei++;
            abuf += l[index];
            used[index] = 1;
            rec(index + 1);
            abuf -= l[index];
            used[index] = 0;
            gousei--;
        } else {
            abuf += l[index];
            used[index] = 1;
            rec(index + 1);
            abuf -= l[index];
            used[index] = 0;
        }

        if (bbuf != 0) {
            gousei++;
            bbuf += l[index];
            used[index] = 1;
            rec(index + 1);
            bbuf -= l[index];
            used[index] = 0;
            gousei--;
        } else {
            bbuf += l[index];
            used[index] = 1;
            rec(index + 1);
            bbuf -= l[index];
            used[index] = 0;
        }

        if (cbuf != 0) {
            gousei++;
            cbuf += l[index];
            used[index] = 1;
            rec(index + 1);
            cbuf -= l[index];
            used[index] = 0;
            gousei--;
        } else {
            cbuf += l[index];
            used[index] = 1;
            rec(index + 1);
            cbuf -= l[index];
            used[index] = 0;
        }
        
        rec(index+1);
    }
    return 0;
}
int solve() {
    rec(0);
    cout << ans << endl;
    return 0;
}

int main() {
    cin >> n >> a >> b >> c;
    REP(i, n) { cin >> l[i]; }
    solve();
    return 0;
}


Measured memory_bytes: 256
from itertools import accumulate

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

    a = list(map(int, input().split()))
    acc = list(accumulate(a))
    ans = 0
    mod = 10**9+7
    for i in range(n-1):
        ans = (ans + a[i] * (acc[-1] - acc[i])) % mod

    print(ans)

if __name__ == "__main__":
    resolve()


Measured memory_bytes: 31640
n = int(raw_input())
s = [int(raw_input()) for _ in range(n)]
mod = int(1e9+7)

previous_idx = {}
dp = [1] * n
ans = 1

for i in range(n):
	c = s[i]
	if c in previous_idx and previous_idx[c] != i-1:
		ans += dp[previous_idx[c]]

	previous_idx[c] = i
	dp[i] = ans % mod

print(ans % mod)


Measured memory_bytes: 36324
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <string>
#include <string.h>

using namespace std;

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    int n;
    cin >> n;
    vector<int> a(n);
    for (int i=0; i<n; i++) cin >> a[i]; 
    int cnt = 1;
    int m = a[0];
    for (int i=1; i<n; i++) {
        if (m >= a[i]) {
            m = a[i];
            cnt++;
        }
    }
    cout << cnt << '\n';
    
    return 0;
}

Measured memory_bytes: 3952
#include<iostream>
using namespace std;
int main() {

	while (true) {
		int m, f, r;

		cin >> m >> f >> r;

		if (m == -1 && f == -1 && r == -1)break;

		int score = m + f;

		if (m == -1 || f == -1) {
			cout << "F" << endl;
		}
		else if (score >= 80) {
			cout << "A" << endl;
		}
		else if (65 <= score && score < 80) {
			cout << "B" << endl;
		}
		else if (50 <= score && score < 65) {
			cout << "C" << endl;
		}
		else if (score < 50 && score>=30) {
			if (r >= 50) {
				cout << "C" << endl;
			}
			else {
				cout << "D" << endl;
			}
		}
		else {
			cout << "F" << endl;
		}


	}



	return 0;

}



Measured memory_bytes: 3084
#include<bits/stdc++.h>
#define int           long long
#define pb            push_back
#define ppb           pop_back
#define si            set <int>
#define endl          '\n'
#define fr            first
#define sc            second
#define mii           map<int,int>
#define msi           map<string,int >
#define mis           map<int,string>
#define rep(i,a,b)    for(int i=a;i<b;i++)
#define f(i,n)   		  for(int  i=0;i<n;i++)
#define all(v)        v.begin(),v.end()
#define sort(v)       sort(all(v))
#define sm(v)			accumulate(v.begin(),v.end(),0)
#define pii           pair<int ,int >
#define vi            vector<int >
#define vii           vector<pair<int , int >>
#define vs            vector<string>
#define sz(x)         (int )x.size()
#define M             1000000007
#define bs            binary_search
#define mp            make_pair
#define sp(n)         setprecision(n)
#define spl           " "
#define arr(a,n)      rep(i,0,n) cin>>a[i]
#define mod           998244353
#define MAX           1000000
    using namespace std;
    void sv(vector<int>v)
    {
        vector<int>::iterator i;
        for(i=v.begin();i!=v.end();i++)
            cout<<*i<<' ';
        cout<<endl;
    }
     
    signed main()
    {
                ios_base::sync_with_stdio(false);
                cin.tie(0);
                cout.tie(0);
                #ifndef ONLINE_JUDGE
            //   freopen("input.txt","r",stdin);
              // freopen("output.txt","w",stdout);
                #endif
                int t=1;
                //cin>>t;
                while(t--)
                {
                	
                	int n;
                	cin>>n;
                	cout<<(n-1)*n/2;
    }}
    	

Measured memory_bytes: 256
v,e,r = map(int,input().split())
D = [float('inf')]*v
L = []
find_negative = False
for i in range(e):
    s,t,d = map(int,input().split())
    L.append([s,t,d])
D[r] = 0
for i in range(v):
    update = False
    for j in range(e):
        a,b,c = L[j][0],L[j][1],L[j][2]
        if D[b] > D[a]+c:
            D[b] = D[a]+c
            update = True
            if i == v-1:
                find_negative = True
                break
    if not update:
        break
if find_negative:
    print('NEGATIVE CYCLE')
else:
    for i in range(v):
        if D[i] == float('inf'):
            print('INF')
        else:
            print(D[i])


Measured memory_bytes: 6028
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int N;
  cin >> N;
  int a,b;
  b=0;
  for(int i=0;2*i+1<=N;i++){
    a=0;
    for(int j=1;j<=N;j++){
      if((2*i+1)%j==0){a++;}
    }
    if(a==8){b++;}
  }
  cout << b << endl;
}

Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cassert>
#include<cmath>
#include<vector>
#include<map>
#include<set>
#include<string>
#include<queue>
#include<stack>
#include <cstring>
using namespace std;
#define MOD 1000000007
#define MOD2 998244353
#define INF ((1<<30)-1)
#define LINF (1LL<<60)
#define EPS (1e-10)
typedef long long Int;
typedef pair<Int, Int> P; 
const int N = 1000006;
//////////////////////////////

Int n, m, x, y;
vector<int> edge[110000];
Int dp1[110000];
Int dp2[110000];
Int ans[110000];

void dfs1(int x, int last = -1)
{
	Int prod = 1;
	for (auto to : edge[x]) {
		if (to == last) continue;
		dfs1(to, x);
		prod = prod * dp1[to] % m;
	}
	dp1[x] = prod + 1;
}

void dfs2(int x, int last = -1)
{
	if (last == -1) dp2[x] = 1;
	vector<Int> lprod = vector<Int>(edge[x].size(), 1);
	vector<Int> rprod = vector<Int>(edge[x].size(), 1);

	for (int i = 0; i < edge[x].size(); i++) {
		int to = edge[x][i];
		if (i - 1 >= 0) lprod[i] = lprod[i - 1];
		if (to == last) continue;
		lprod[i] *= dp1[to];
		lprod[i] %= m;
	}

	for (int i = (int)edge[x].size() - 1; i >= 0; i--) {
		int to = edge[x][i];
		if (i + 1 < rprod.size()) rprod[i] = rprod[i + 1];
		if (to == last) continue;
		rprod[i] *= dp1[to];
		rprod[i] %= m;
	}

	for (int i = 0; i < edge[x].size(); i++) {
		int to = edge[x][i];
		if (to == last) continue;
		Int rest_prod = 1;
		if (i - 1 >= 0) rest_prod = rest_prod * lprod[i - 1] % m;
		if (i + 1 < rprod.size()) rest_prod = rest_prod * rprod[i + 1] % m;
		dp2[to] = (dp2[x] * rest_prod + 1) % m;
		dfs2(to, x);
	}
}

void dfs3(int x, int last = -1) 
{
	ans[x] = dp2[x];
	for (auto to : edge[x]) {
		if (to == last) continue;
		ans[x] *= dp1[to];
		ans[x] %= m;
		dfs3(to, x);
	}
}

int main() { 
	ios_base::sync_with_stdio(0); cin.tie(0);//fflush(stdout);
	cin >> n >> m;
	for (int i = 0; i < n - 1; i++) {
		cin >> x >> y;
		edge[x].push_back(y);
		edge[y].push_back(x);
	}

	dfs1(1);
	dfs2(1);
	dfs3(1);

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

	return 0;
}



Measured memory_bytes: 20608
#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ull = unsigned long long; 
using pii =  pair<int, int>;
using pll =  pair<long long, long long>;
#define rep(i, n) for(int i = 0; i < (n); ++i)
#define all(x) (x).begin(),(x).end()
constexpr char ln =  '\n';
constexpr long long MOD = 1000000007LL;
//constexpr long long MOD = 998244353LL;
template<class T, class U> inline bool chmax(T &a, U b) { if (a < b) { a = b; return true;} return false; }
template<class T, class U> inline bool chmin(T &a, U b) { if (a > b) { a = b; return true;} return false; }
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

int main() {
    ios::sync_with_stdio(false); cin.tie(nullptr);
/*
    int n,m; cin >> n >> m;
    int h[n]; rep(i,n) cin >> h[i];
    int a[m],b[m];
    rep(i,m){
        cin >> a[i] >> b[i];
        a[i]--;
        b[i]--;
    }     
    
    int cnt = 0;

    rep(i,n){
        rep(j,m){
            cout << "i=" << i << " j=" << j << " a[i]=" << a[i] << " b[j]=" << b[j] << ln;
            if(a[j]==i && h[b[j]]<h[i]) cnt++;
            else if(b[j]==i && h[a[j]]<h[i]) cnt++;
        }
    }
    
    cout << cnt << ln;
*/
    int n,m; cin >> n >> m;
    vector<int> h(n); rep(i,n) cin >> h[i];
    vector<vector<int>> graph(n);
    while(m--){
        int a,b; cin >> a >> b; --a; --b;
        graph[a].emplace_back(b);
        graph[b].emplace_back(a);
    }
    
    int ans = 0;
    int i=1;
    rep(i,n){
        bool ok = true;
        for(int e : graph[i]){
            ok &= h[e] < h[i];
        }
        ans += ok;
    }
    
    cout << ans << ln;
    return 0;
}

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

long long int n;
long long int m;
int main(){
	scanf("%lld%lld", &n, &m);
	long long int ans = min(n, m / 2LL);
	m -= ans * 2LL;
	ans += m / 4LL;
	printf("%lld\n", ans);
	return 0;
}

Measured memory_bytes: 256
while 1:
    a,b,c = map(int,input().split())
    if a == -1 and b == -1 and c == -1:
        break
    score = a+b
    if a == -1 or b == -1 or score < 30:
        print("F")
    elif 30 <= score < 50:
        if c >= 50:
            print("C")
        else:
            print("D")
    elif 50 <= score < 65:
        print("C")
    elif 65 <= score < 80:
        print("B")
    else:
        print("A")
        


Measured memory_bytes: 5596
#include <bits/stdc++.h>
using namespace std;
int main()
{
    int n;
    cin>>n;
    int v[n][3];
    for(int i=0;i<n;i++)
    {
        cin>>v[i][0];
        cin>>v[i][1];
        cin>>v[i][2];
    }
    int dp[n][3];
    for(int j=0;j<3;j++)
    {
        dp[0][j]=v[0][j];
    }
    for(int i=1;i<n;i++)
    {
        dp[i][0]=max(dp[i-1][1],dp[i-1][2])+v[i][0];
        dp[i][1]=max(dp[i-1][0],dp[i-1][2])+v[i][1];
        dp[i][2]=max(dp[i-1][1],dp[i-1][0])+v[i][2];
    }
    int ans=0;
    for(int j=0;j<3;j++)
    {
        ans=max(ans,dp[n-1][j]);
    }
    cout<<ans<<endl;
}


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


int main(){
  int H,W;
  cin >> H >> W;
  vector<vector<char>> data(H+2, vector<char>(W+2,'.'));

  for(int i = 1;i<=H;i++){
    for(int j = 1;j<=W;j++){
      cin >> data[i][j];
    }
  }
  for(int i = 1;i<=H;i++){
    for(int j = 1;j<=W;j++){
      int c = 0;
      if(data[i][j] == '.'){
      for(int k = i-1;k<=i+1;k++){
        for(int l = j-1;l<=j+1;l++){
       
          if(data[k][l] == '#') c++;
        }
      }
       char C = '0' + c;
      data[i][j] = C;
     }
    }
  }
  for(int i = 1;i<=H;i++){
    for(int j = 1;j<=W;j++){
      cout << data[i][j];
      if(j == W) cout << endl;
    }
  }
  
 }

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

int main(){
  int n,m;
  while(1){
    cin >> n >> m;
    if(n == 0 && m == 0) break;
    int cnt[111]={0};
    for(int i=0;i<n;i++){
      int a; cin >> a;
      for(int j=0;j<a;j++){
	int num; cin >> num;
	cnt[num]++;
      }
    }
    int ans = 0;
    int pos = 0;
    for(int i=1;i<105;i++){
      if(cnt[i] >= m){
	if(ans < cnt[i]){
	  ans = cnt[i];
	  pos = i;
	}
      }
    }
    cout << pos << endl;
  }
}

Measured memory_bytes: 1160
#素因数分解、計算量はO(√N)
from collections import defaultdict
def factorize(n):
  b = 2
  dic = defaultdict(lambda: 0)
  while b * b <= n:
    while n % b == 0:
      n //= b
      dic[b] += 1
    b = b + 1
  if n > 1:
    dic[n] += 1
  return dic
N = int(input())
fct = factorize(2*N)
lis = []
for k,v in fct.items():
  lis.append(pow(k,v))
ans = 10**18
from itertools import groupby, accumulate, product, permutations, combinations
for pro in product([1,0],repeat=len(lis)):
  prod1 = 1
  for i,p in enumerate(pro):
    if p==1:
      prod1 *= lis[i]
  prod2 = (N*2)//prod1
  if prod1<prod2:
    prod1,prod2 = prod2,prod1
    # continue
  for i in range(1,prod2+1):
    if prod1*i>ans:
      break
    if (prod1*i-1)%prod2==0:
      ans = min(ans, prod1*i-1)
      break
    if (prod1*i+1)%prod2==0:
      ans = min(ans, prod1*i)
      break
print(ans)



Measured memory_bytes: 68700
#include<bits/stdc++.h>
using namespace std;
const int size=1e4+5;
const int mod=1e9+7;
using ll = long long int;
ll dp[size][105][2];
void add(ll &a,ll b)
{
    a = (a+b);
    a %= mod;
}
ll solve(int idx,int rem,bool flag,int arr[],int n,int d)
{
//    cout<<idx<<" "<<rem<<" "<<flag<<endl;
    if(idx==n)
    {
        return (rem==0);
    }
    int limit = ((flag)?9:arr[idx]);
//    if(dp[idx][(d-rem)%d]!=-1)
//        return dp[idx][(d-rem)%d];
    ll &res = dp[idx][rem][flag];
    if(res!=-1)
        return res;
    res = 0;
    for(int i=0;i<=limit;i++)
    {
        add(res,solve(idx+1,(rem+i)%d,(flag|(i!=arr[idx])),arr,n,d));
    }
    return res;
}
int main()
{
    memset(dp,-1,sizeof dp);
    string s;
    cin>>s;
    int n = s.size();
    int d;
    cin>>d;
    int arr[n];
    for(int i=0;i<n;i++)
        arr[i] = (s[i]-'0');
    cout<<(solve(0,0,0,arr,n,d)-1+mod)%mod<<"\n";
    return 0;
}


Measured memory_bytes: 17664
#include <iostream>
#include <vector>
#include <numeric>
#include <cmath>
#include <climits>
using namespace std;

int main(){
	long long int n,s=0,rsum;
	cin >> n;
	vector<long long int>a(n);
	for(auto& v : a){
		cin >> v;
		s += v;
	}
	rsum = s;
	
	long long int out = LLONG_MAX;
	for(int i = 0; i < n - 1; ++i){
		rsum -= a[i];
		if(abs(s - rsum - rsum) < out){
			out = abs(s - rsum - rsum);
		}
	}

	cout << out << endl;
	return 0;
}

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

#define CIN_ONLY if(1)
struct cww{cww(){
    CIN_ONLY{
        ios::sync_with_stdio(false);cin.tie(0);
    }
}}star;
#define fin "\n"
#define FOR(i,bg,ed) for(int i=(bg);i<(ed);i++)
#define REP(i,n) FOR(i,0,n)
#define ALL(v) (v).begin(),(v).end()
#define fi first
#define se second
#define pb push_back
#define DEBUG if(0)
#define REC(ret, ...) std::function<ret (__VA_ARGS__)>
template <typename T>inline bool chmin(T &l,T r)
{bool a=l>r;if(a)l=r;return a;}
template <typename T>inline bool chmax(T &l,T r)
{bool a=l<r;if(a)l=r;return a;}
template <typename T>
istream& operator>>(istream &is,vector<T> &v){
    for(auto &it:v)is>>it;
    return is;
}
    
int main(){
    LL N,T;
    cin>>N>>T;
    LL t =0;
    LL res=0;
    REP(i,N){
        LL ti;
        cin>>ti;
        res+=ti+T-max(t,ti);
        t=ti+T;
    }
    cout<<res<<endl;
    
    return 0;
}


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

typedef long long int int64;

#define MAX(a,b) ((a)>(b)?(a):(b))
#define MIN(a,b) ((a)<(b)?(a):(b))
#define ABS(a) ((a)>(0)?(a):-(a))

void run(void){
  int n,a,b;
  scanf("%d%d%d",&n,&a,&b);
  int64 cost=0;
  int now;
  scanf("%d",&now);
  int i;
  for(i=2;i<=n;i++){
    int x;
    scanf("%d",&x);
    int64 ca=(int64)(x-now)*a;
    cost+=ca>=b?b:ca;
    now=x;
  }
  printf("%lld\n",cost);
  return;
}

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


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

int main(){
    int i = 1;
    int x;
    
    while(1){
        cin >> x;
        if ( x == 0) break;
        
        cout << "Case"<< " " << i << ":" << " " << x << endl;
        
        i++;
    }
    
    return 0;
}


Measured memory_bytes: 3064
#include<bits/stdc++.h>
using namespace std;
struct P{
  int x,y,d;
  P(int y,int x,int d):y(y),x(x),d(d){}
};
int main(){
  int h,w;cin>>h>>w;
  int pr=1<<28,so=1<<28,i,j,k;
  char m[h+2][w+2];
  memset(m,'#',sizeof(m));
  P p=P(0,0,0);
  vector<P> ss;
  for(i=1;i<=h;i++){
    for(j=1;j<=w;j++){
      cin>>m[i][j];
      if(m[i][j]=='@') p.y=i,p.x=j,p.d=0;
      if(m[i][j]=='$') ss.push_back(P(i,j,0));
    }
  }
  queue<P> q;
  bool used[h+2][w+2];
  int ax[]={1,-1,0,0};
  int ay[]={0,0,1,-1};
  memset(used,0,sizeof(used));
  q.push(p);
  while(!q.empty()){
    p=q.front();q.pop();
    if(m[p.y][p.x]=='%') {
      pr=p.d;
      break;
    }
    if(used[p.y][p.x]) continue;
    used[p.y][p.x]=true;
    for(k=0;k<4;k++){
      if(m[p.y+ay[k]][p.x+ax[k]]!='#'&&!used[p.y+ay[k]][p.x+ax[k]])
	q.push(P(p.y+ay[k],p.x+ax[k],p.d+1));
    }
  }
  while(!q.empty()) q.pop();
  memset(used,0,sizeof(used));
  for(i=0;i<ss.size();i++) q.push(ss[i]);
  while(!q.empty()){
    p=q.front();q.pop();
    if(m[p.y][p.x]=='%') {
      so=p.d;
      break;
    }
    if(used[p.y][p.x]) continue;
    used[p.y][p.x]=true;
    for(k=0;k<4;k++){
      if(m[p.y+ay[k]][p.x+ax[k]]!='#'&&!used[p.y+ay[k]][p.x+ax[k]])
	q.push(P(p.y+ay[k],p.x+ax[k],p.d+1));
    }
  }
  //cout << pr << " " << so << endl;
  cout << ((pr<so)?"Yes":"No") << endl;
  return 0;
}

Measured memory_bytes: 4048
use std::vec::Vec;

fn read<T: std::str::FromStr>() -> T {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).ok();
    s.trim().parse().ok().unwrap()
}

fn read_vec<T: std::str::FromStr>() -> Vec<T> {
    read::<String>().split_whitespace().map(|e| e.parse().ok().unwrap()).collect()
}

fn main() {

    let (n, m, c): (usize, usize, i64) = {
      let v = read_vec::<i64>();
      (v[0] as usize, v[1] as usize, v[2])
    };

    let b: Vec<i64> = read_vec();

    let mut a: Vec<Vec<i64>> = Vec::new();

    for i in 0..n {
      a.push(read_vec::<i64>());
    }

    let mut res = 0;


    for i in 0..n {
      let mut sum = 0;
      for j in 0..m {
        sum += a[i][j] * b[j];
      }
      sum += c as i64;

      if sum > 0 {
        res += 1;
      }
    }

    println!("{}", res);
}


Measured memory_bytes: 4352
#include <bits/stdc++.h>
using namespace std;
#define what_is(x) cerr << #x << " is " << x << endl;
#define IOS ios::sync_with_stdio(false); cin.tie(0);
#define st first
#define nd second
#define endl '\n'

typedef long long ll;
typedef pair<int,int> pii;
const int N = 1e5+5;
const int INF = 1e9;
const int MOD = 1e9+7;

ll n;

int main()
{
	IOS
	//freopen("input.txt", "r", stdin);
	cin >> n;
	for(ll i = sqrt(n); ;i--){
		if (n%i == 0){
			ll j = n/i;
			ll ans = i-1 + j-1;
			cout << ans << endl;
			return 0;
		}
	}
	return 0;
}


Measured memory_bytes: 256
N, M = map(int, input().split())
Q = [tuple(map(int, input().split())) for i in range(M)]

Q.sort(key=lambda x: x[1])
ans = 0
prev = 0
for ai, bi in Q:
    if prev < ai:
        ans += 1
        prev = bi - 1
print(ans)


Measured memory_bytes: 18244
#include <iostream>
using namespace std;
int n,m,data[220],cp[220],k;
int main (){
	cin>>n>>m;
	for(int i=1;i<=(2*n);i++){
		data[i]=i;
	}
	for(int i=0;i<m;i++){
		cin>>k;
		for(int j=1;j<=(2*n);j++){
			if(k==0){
				if(j<=n){
					cp[2*(j-1)+1]=data[j];
				}
				else{
					cp[2*(j-n)]=data[j];
				}
			}
			else{
				if(j<=k){
					cp[(2*n)-k+j]=data[j];
				}
				else{
					cp[j-k]=data[j];
				}
			}
		}
		for(int k=1;k<=(2*n);k++){
			data[k]=cp[k];
		}
	}
	for(int i=1;i<=(2*n);i++){
		cout<<data[i]<<endl;
	}
	return 0;
}

Measured memory_bytes: 1160
#include <bits/stdc++.h>
using namespace std;
int main(){
	string a,b,c;
	cin>>a>>b>>c;
	if(a[a.size()-1]==b[0]&&b[b.size()-1]==c[0]){
		cout<<"YES"<<endl;
	}
	else{
		cout<<"NO"<<endl;
	}
}


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

using namespace std;
typedef long long ll;
typedef pair<int,int> P;

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

	while(true){
		int sum; cin >> sum;
		if(sum == 0) break;
		int a = 0;
		for (int i = 0;i < 9;i++){
			int tmp; cin >> tmp;
			a += tmp;
		}
		cout << sum-a << endl;
	}	

	return 0;

}



Measured memory_bytes: 3112
t=input()
ans=0
for i in range(len(t)):
  s=[i for i in t]
  for j in range(i):
    s.pop()
  for j in range(len(s)):
    q=''.join(s)
    q=q.lstrip('ACGT')
    ans=max(ans,len(s)-len(q))
    s.pop(0)
print(ans)

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

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep1(i, n) for (int i = 1; i < (int)(n); i++)
typedef long long ll;

int main() {
    ll x; cin >> x;
    ll res = 100;
    ll cnt = 0;
    while(x < 1000000000000000001){
        res *= 1.01;
        cnt++;
        if(res >= x) break;
    }
    cout << cnt << endl;
}

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

int main(){
    int n;
    cin >> n;
    int A[n+1] = {};
    int B[n+1];
    int C[10001] = {};

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

    for(int i = 1; i <= 10000; i++){
        C[i] += C[i-1];
    }

    for(int i = n; i >= 1; i--){
        B[C[A[i]]] = A[i];
        C[A[i]]--;
    }

    for(int i = 1; i <= n; i++){
        if(i != 1)  cout << " ";
        cout << B[i];
    }

    cout << endl;
    return 0;
}


Measured memory_bytes: 18744
#include <bits/stdc++.h>
// #include <atcoder/all>
// using namespace atcoder;
#define rep(i, n) for (ll i = 0; i < (ll)(n); ++i)
#define rep2(i, s, n) for (ll i = s; i < (ll)(n); i++)
#define repr(i, n) for (ll i = n; i >= 0; i--)
#define pb push_back
#define COUT(x) cout << (x) << "\n"
#define COUTF(x) cout << setprecision(15) << (x) << "\n"
#define ENDL cout << "\n"
#define DF(x) x.erase(x.begin())
#define ALL(x) x.begin(), x.end()
#define SORT(x) sort(ALL(x))
#define RSORT(x) sort(x.rbegin(), x.rend())
#define REVERSE(x) reverse(ALL(x))
#define MAX(x) *max_element(ALL(x))
#define MAXI(x) max_element(ALL(x)) - x.begin()
#define SUM(x) accumulate(ALL(x), 0ll)
#define COUNT(x, y) count(ALL(x), y);
#define ANS cout << ans << "\n"
#define YES cout << "YES\n";
#define NO cout << "NO\n";
#define Yes cout << "Yes\n";
#define No cout << "No\n";
#define YN YES else NO
#define yn Yes else No
#define init() \
  cin.tie(0);  \
  ios::sync_with_stdio(false)
#define LINE cerr << "[debug] line: " << __LINE__ << "\n";
#define debug(x) cerr << "[debug] " << #x << ": " << x << "\n";
#define debugV(v)                       \
  cerr << "[debugV] " << #v << ":";     \
  rep(z, v.size()) cerr << " " << v[z]; \
  cerr << "\n";
using namespace std;
using ll = long long;
using ld = long double;
using vll = vector<ll>;
using vvll = vector<vector<ll>>;
using mll = map<ll, ll>;
using qll = queue<ll>;
using P = pair<ll, ll>;
using vp = vector<P>;
using vs = vector<string>;

template <typename T>
inline istream& operator>>(istream& i, vector<T>& v) {
  rep(j, v.size()) i >> v[j];
  return i;
}

template <typename T1, typename T2>
inline istream& operator>>(istream& i, pair<T1, T2>& v) {
  return i >> v.first >> v.second;
}

constexpr ll INF = 0x3f3f3f3f3f3f3f3f;
constexpr ld PI = 3.141592653589793238462643383279;
ll get_digit(ll x) {
  return to_string(x).size();
}

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

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

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

signed main() {
  init();
  ll K;
  cin >> K;

  vll ans(50);
  rep(i, 50) ans[i] = K / 50 + 50;

  ll yobun = 50 - K % 50;
  // debug(K);
  // debug(yobun);
  rep(i, yobun) {
    SORT(ans);
    ans[49] -= 51;
    rep(j, 50) ans[j]++;
    // debugV(ans);
  }

  COUT(ans.size());
  rep(i, 50) {
    if (i == 0)
      cout << ans[i];
    else
      cout << " " << ans[i];
  }
  ENDL;
  return 0;
}

Measured memory_bytes: 3616
use proconio::{fastout, input};

#[fastout]
fn main() {
    input! {n: usize, b: [u64; n]};
    let mut b: Vec<u64> = b;

    let init_len = b.len();

    b.sort();
    b.dedup();

    let dedup_len = b.len();

    if init_len == dedup_len {
        println!("YES")
    } else {
        println!("NO")
    }
}


Measured memory_bytes: 6228
#include<stdio.h>
#include<string.h>
#include<ctype.h>

int main (void){
	
	int count=0,i;
	char buff[256];
	char buff1[256];
	char buff2[256];
	
	scanf("%s",buff1);
	
	while(1){
	scanf("%s",buff2);
	
	if(strcmp(buff2, "END_OF_TEXT")==0)break;
	for(i=0;buff2[i] != '\0';i++){
		buff2[i] = tolower(buff2[i]);
	}
	if(strcmp(buff2,buff1) == 0){
		count++;
	}else{
		;
	}
	
	}
	printf("%d\n",count);
	
return 0;
}

Measured memory_bytes: 552
import bisect
import collections

s = input().rstrip()
t = input().rstrip()

counter_s = collections.Counter(s)
counter_t = collections.Counter(t)
for c in counter_t.keys():
    if c not in counter_s.keys():
        print(-1)
        exit()

s_indices = collections.defaultdict(list)
for i, c in enumerate(s):
    if c in counter_t.keys():
        s_indices[c].append(i)

index = 0
count = 0
offset = 0
while index < len(t):
    c = t[index]
    i = bisect.bisect_left(s_indices[c], offset)
    if i == len(s_indices[c]):
        count += 1
        offset = 0
    else:
        offset = s_indices[c][i] + 1
        index += 1
print(len(s) * count + offset)

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

int main(){
    int N, maxNum=0, maxNum2=0;
    cin >> N;
    vector<int> a(N);
	
    for(int i=0; i<N; i++){
	cin >> a[i];
	if(maxNum <= a[i]){
	    maxNum2 = maxNum;
	    maxNum = a[i];	    
	}
	else if(maxNum2 <= a[i]){
	    maxNum2 = a[i];	    
	}

    }


    for(int i=0; i<N; i++)
	cout << (a[i] != maxNum? maxNum: maxNum2 ) << endl;

}





Measured memory_bytes: 2432
import java.io.IOException;
import java.io.InputStream;
import java.util.NoSuchElementException;

public class Main {

	public static void main(String[] args) {

		FastScanner sc = new FastScanner();
		long N = sc.nextInt();
		long M = sc.nextInt();

		if (N == 1 && M == 1)
			System.out.println(1);
		else if (N == 1 || M == 1)
			System.out.println(N * M - 2);
		else
			System.out.println(N * M - (2 * N + 2 * M - 4));

	}
	//以下、自作ライブラリ

	//最大公約数
	public static long gcd(long a, long b) {
		if (a < b)
			return gcd(b, a);
		long c = 0;
		c = a % b;
		if (c == 0)
			return b;
		return gcd(b, c);
	}

	//最小公倍数
	public static long lcm(long m, long n) {
		return m * n / gcd(m, n);
	}

	//素数判定
	public static boolean isPrime(int n) {
		if (n < 2)
			return false;
		if (n == 2)
			return true;
		if (n % 2 == 0)
			return false;

		for (int i = 3; i * i <= n; i += 2) {
			if (n % i == 0)
				return false;
		}
		return true;
	}
}

//以下、高速スキャナークラス
class FastScanner {
	private final InputStream in = System.in;
	private final byte[] buffer = new byte[1024];
	private int ptr = 0;
	private int buflen = 0;

	private boolean hasNextByte() {
		if (ptr < buflen) {
			return true;
		} else {
			ptr = 0;
			try {
				buflen = in.read(buffer);
			} catch (IOException e) {
				e.printStackTrace();
			}
			if (buflen <= 0) {
				return false;
			}
		}
		return true;
	}

	private int readByte() {
		if (hasNextByte())
			return buffer[ptr++];
		else
			return -1;
	}

	private static boolean isPrintableChar(int c) {
		return 33 <= c && c <= 126;
	}

	public boolean hasNext() {
		while (hasNextByte() && !isPrintableChar(buffer[ptr]))
			ptr++;
		return hasNextByte();
	}

	public String next() {
		if (!hasNext())
			throw new NoSuchElementException();
		StringBuilder sb = new StringBuilder();
		int b = readByte();
		while (isPrintableChar(b)) {
			sb.appendCodePoint(b);
			b = readByte();
		}
		return sb.toString();
	}

	public long nextLong() {
		if (!hasNext())
			throw new NoSuchElementException();
		long n = 0;
		boolean minus = false;
		int b = readByte();
		if (b == '-') {
			minus = true;
			b = readByte();
		}
		if (b < '0' || '9' < b) {
			throw new NumberFormatException();
		}
		while (true) {
			if ('0' <= b && b <= '9') {
				n *= 10;
				n += b - '0';
			} else if (b == -1 || !isPrintableChar(b)) {
				return minus ? -n : n;
			} else {
				throw new NumberFormatException();
			}
			b = readByte();
		}
	}

	public int nextInt() {
		long nl = nextLong();
		if (nl < Integer.MIN_VALUE || nl > Integer.MAX_VALUE)
			throw new NumberFormatException();
		return (int) nl;
	}

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


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

int main()
{
   string s;
   cin >> s;
   if(s[0] == s[1] and  s[1] == s[2])cout << "Yes\n";
   else if(s[1] == s[2] and s[2] == s[3])cout << "Yes\n";
   else if(s[0] == s[1] and s[1] == s[2] and s[2] == s[3])cout << "Yes\n";
   else cout << "No\n";

   return 0;
}


Measured memory_bytes: 256
s=str(input())
if(s[0]!=s[1]):
	if(s.count(s[0])==2 and s.count(s[1])==2):
		print("Yes")
	else:
		print("No")
else:
	if(s[2]!=s[0]):
		if(s.count(s[0])==2 and s.count(s[2])==2):
			print("Yes")
		else:
			print("No")
	else:
		print("No")


Measured memory_bytes: 3060
#include <iostream>
#include <stdio.h>
#include <string>
#include <algorithm>
#include <vector>
#include <map>
#include <math.h>

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

int main() {
	string S;
	cin >> S;
	int i;
	rep(i, S.length()) {
		if (S[i] == 'L') {
			cout << "No";
			return 0;
		}
		if (S[i + 1] == 'R') {
			cout << "No";
			return 0;
		}
		i++;
	}

	cout << "Yes";

	return 0;
}



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

#define rep(i, n) for(long long i=0;i<(long long)(n);i++)
#define rep2(i, s, n) for(long long i=(s);i<(long long)(n);i++)
#define repi(i, n) for(int i=0;i<(int)(n);i++)
#define rep2i(i, s, n) for(int i=(s);i<(int)(n);i++)
#define all(v) v.begin(), v.end()
#define rall(v) v.rbegin(), v.rend()
#define chmax(s, t) s=max(s,t);
#define chmin(s, t) s=min(s,t); 

#define deg2rad(deg) (((deg)/360)*2*M_PI)
#define rad2deg(rad) (((rad)/2/M_PI)*360)

using ll = long long;
using ld = long double;
using vll = vector<ll>;
using vvll = vector<vll>;
using P = pair<ll, ll>;
using vi = vector<int>;
using vvi = vector<vi>;

const ll INF = (1LL<<60);
const int INFi = (1<<29);

/*素数判定*/
bool is_prime(ll n){
    if(n==1) return false;
    for(ll i=2;i*i<=n;i++){
        if(n%i==0) return false;
    }
    return true;
}

/*約数列挙*/
vll enum_divisors(ll n){
    vll l;
    for(ll i=1;i*i<=n;i++){
        if(n%i==0){
            l.push_back(i);
            if(n/i != i) l.push_back(n/i);
        }
    }
   sort(all(l));
   return l;
}

/*素因数分解*/
vector<P> prime_factorize(ll n){
    vector<P> l;
    for(ll i=2;i*i<=n;i++){
        if(n%i!=0) continue;
        ll e = 0;
        while(n%i==0){
            e++;
            n /= i;
        }
        l.push_back({i, e});
    }
    if(n!=1) l.push_back({n, 1});
    return l;
}

/*最小公倍数*/
ll lcm(ll a, ll b){
    return a*b/__gcd(a,b);
}

/*最大公約数*/
ll gcd(ll a, ll b){
    return __gcd(a,b);
}

/*組み合わせ(Combination)*/
const ll CMAX = 1010000;
const ll CMOD = 1e9+7;
ll fac[CMAX], finv[CMAX], inv[CMAX];
// テーブルを作る前処理
void combinit() {
	fac[0] = fac[1] = 1;
	finv[0] = finv[1] = 1;
	inv[1] = 1;
	for (ll i = 2; i < CMAX; i++) {
		fac[i] = fac[i - 1] * i % CMOD;
		inv[i] = CMOD - inv[CMOD%i] * (CMOD / i) % CMOD;
		finv[i] = finv[i - 1] * inv[i] % CMOD;
	}
}
// 二項係数計算
ll comb(ll n, ll k) {
	if (n < k) return 0;
	if (n < 0 || k < 0) return 0;
	return fac[n] * (finv[k] * finv[n - k] % CMOD) % CMOD;
}

/*階乗*/
ll factorial(ll n){
    const ll FMOD = 1e9+7;
    ll ret = n;
    for(ll i=n-1;i>0;i--){
        ret*=i;
        ret%=FMOD;
    }
    return (ret?ret:1);
}


int main(){

    ll n; cin >> n;

    cout << (n==1?0:1) << endl;

    return 0;
}

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


int main(){
	int h, w;
	cin >> h >> w;
	vector<string> a(h);
	rep(i,h){
		cin >> a.at(i);
	}
	rep(i,h+2){
		if(i==0||i==h+1){
			rep(j,w+2){
				cout << "#";
			}
			cout << endl;
		}
		else{
			cout << "#" << a.at(i-1) << "#" << endl;
		}
	}
			

}


	







Measured memory_bytes: 256
//Date and time of submission: 
 
#include<bits/stdc++.h>
#define ll long long
using namespace std;
const ll N=1e5+5;
string s;
int main() {
	ios_base::sync_with_stdio(false); 
	cin.tie(NULL);
	cin>>s;
	ll cnt=0;
	for(char ch: s)
	cnt+=(ch=='1');
	cout<<cnt;
	return 0;
}


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

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

	for (int i = 0; i < 3; i++) {
		if (n.at(i) == '1')
			n.at(i) = '9';
		else n.at(i) = '1';
	}
	cout << n << endl;

	return 0;
}


Measured memory_bytes: 256
a,b,k=map(int,input().split())
for i in range(1,k+1):
    if (i % 2) == 1:
        if (a % 2) == 1:
            a -= 1
            a //= 2
            b += a
        else:
            a //= 2
            b += a
    else:
        if (b % 2) == 1:
            b -= 1
            b //= 2
            a += b
        else:
            b //= 2
            a += b
print(str(a)+" "+str(b))


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

int day[12] = {31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
string date[7] = {
    "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday", "Sunday"
};

int main() {
    int m, d;
    while (cin >> m >> d, m && d) {
        int t = d + accumulate(day, day + m - 1, 0);
        cout << date[(t + 2) % 7] << endl;
    }
    return 0;
}

Measured memory_bytes: 1196
#include<iostream>
#include<string>
#include<algorithm>
#include<cstdlib>
#include<cmath>
#include<vector>
#include<list>

using namespace std;

int main(void){
  int n;
  cin >> n;
  vector<int> x(n);
  vector<int> y(n);
  vector<long long int> h(n);
  int d=0;
  for(int i=0;i<n;i++){
    cin >> x[i];
    cin >> y[i];
    cin >> h[i];
    if(h[i] >= 1) d=i;
  }

  //auto itr=lower_bound(h.begin(),h.end(),1);
  //auto d=distance(h.begin(),itr);
  //cout << x[d] << "," << y[d] << "," << h[d] << endl;
  int tx,ty;
  long long int h_max;

  auto match=0;

  for(int cx=0;cx<=100 && match==0;cx++){
    for(int cy=0;cy<=100 && match==0;cy++){
      h_max=h[d] + abs(cx-x[d]) + abs(cy-y[d]);
      h_max=max(h_max,0LL);
      //cout << cx << "," << cy << "," << h_max << endl;
      match=1;
      for(int i=0;i<h.size();i++){
        auto tmp=h_max - abs(cx-x[i]) - abs(cy-y[i]);
        if( h[i] != max(tmp , 0LL) ){
          match=0;
          break;
        }
      }
      if(match == 1){
        tx=cx;
        ty=cy;
      }

    }
  }

  cout << tx << " " << ty << " " << h_max << endl;

  return 0;
}


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

int dir[100010],to[100010],cnt[100010];
int main(){
	int N,M,iti,lit,res;
	cin>>N>>M;
	for(int i=1;i<N;i++){
		cin>>dir[i];
	}
	for(int i=1;i<=M;i++){
		cin>>to[i];
	}
	iti=lit=1;
	for(int i=1;i<=M;i++){
		lit=iti;
		iti+=to[i];
		for(int j=min(iti,lit);j!=max(iti,lit);j++){
			cnt[j]++;
		}
	}
	res=0;
	for(int i=1;i<N;i++){
		res=(res+cnt[i]*dir[i])%100000;
	}
	cout<<res<<endl;
	return 0;
}

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

int main() {
  string s;
  cin >> s;
  long int k;
  cin >> k;
  int S = s.size();
  int a = 0;
  int ind = 1;
  int last = 1;
  int first = 1;
  int flag = 1;
  long int out = 0;
  for(int i = 0; i < S - 1; i++){
    
    
    if(s.at(i) == s.at(i + 1)){
      ind++;
      if(flag == 1){
        first++;
      }
    }else{
      flag = 0;
      if(ind > 1){
        a += ind / 2;
        ind = 1;
      }
    }
    
    if(i == S - 2){
      if(ind > 1){
        last = ind;
        ind = 1;
      }
    }
  }

  a = a - first / 2;
  out = a * k;
  if(s.at(0) == s.at(S - 1)){
    int p = first + last;
    out = out + (p / 2) * (k - 1);
    out = out + first / 2;
    out = out + last / 2;
   }else{
     out = out + ((first / 2) + (last / 2)) * k;
  }
    if(first == S){
    out = (S * k) / 2;
  }
   cout << out;
  
}

Measured memory_bytes: 256
using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.CompilerServices;
using System.Text;
using static System.Console;
using static System.Math;

namespace Atcoder
{
    class Program
    {
        static void Main(string[] args)
        {
            try
            {
                Solve.Answer();
            }
            catch (Exception ex)
            {
                WriteLine(ex.ToString());
            }
        }
    }

    public class Solve
    {
        public static void Answer()
        {
            var a = IO.ReadSplitInt;
            for (int i = 0; i < a[0]; i++)
            {
                var s = ReadLine();
                WriteLine(s);
                WriteLine(s);
            }
        }

        public class IO
        {
            #region Input
            public static string ReadString => ReadLine();
            public static int ReadInt => int.Parse(ReadLine());
            public static long ReadLong => long.Parse(ReadLine());
            public static double ReadDouble => double.Parse(ReadLine());

            public static List<string> ReadSplitString => ReadLine().Split().ToList();
            public static List<int> ReadSplitInt => ReadLine().Split().Select(s => int.Parse(s)).ToList();
            public static List<long> ReadSplitLong => ReadLine().Split().Select(s => long.Parse(s)).ToList();
            public static List<double> ReadSplitdouble => ReadLine().Split().Select(s => double.Parse(s)).ToList();
            #endregion

            #region Output
            public static void OutJoinSpace<T>(IEnumerable<T> list) => WriteLine(string.Join(" ", list));
            public static void WriteLineYes_or_No(bool flag) => WriteLine(flag ? "Yes" : "No");

            #endregion
        }

        public class Mod
        {
            #region
            private readonly static long M = 1000000007;

            public static long Add(long a, long b) => (a * b) % M;
            public static long Sub(long a, long b) => (a - b) % M >= 0 ? (a - b) % M : (a - b) % M + M;
            public static long Multi(long a, long b) => (a * b) % M;
            #endregion
        }

        public static long GCD(long x, long y)
        {
            #region
            if (x < y)
            {
                var tmp = x;
                x = y;
                y = tmp;
            }
            while (true)

            {
                if (x % y == 0)
                {
                    return y;
                }
                else
                {
                    var tmp = x;
                    x = y;
                    y = tmp % y;
                }
            }
            #endregion
        }

        public static long Choice2(long n)
        {
            #region
            if (n <= 1)
                return 0;
            if (n == 2)
                return 1;
            else
                return n * (n - 1) / 2;
            #endregion
        }
    }
}

Measured memory_bytes: 11348
#include<iostream>
#include<string.h>
#include<cstdio>
#include<algorithm>
#include<stack>
#include<queue>
#include<vector>
#include<cmath>
#include<utility>
#define ll long long int
#define ld long double
#define INF 1000000000
#define EPS 0.0000000001
#define rep(i,n) for(i=0;i<n;i++)
using namespace std;
typedef pair<int, int> P;

string str;

int main()
{
  int n;
  int a[105];
  int i,j;
  int sum=0;
  double ave=0;

  cin>>n;

  rep(i,n){
    scanf(" %d",&a[i]);
    ave+=a[i];
  }
  ave/=n;//平均の算出
  int c;
  if(ave>0){
    ave+=0.5;
    c=ave;
  }else{
    ave-=0.5;
    c=ave;
  }


  rep(i,n)
    sum+=(a[i]-c)*(a[i]-c);
  cout<<sum<<endl;

}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define all(X) (X).begin(),(X).end()
#define rall(X) (X).rbegin(),(X).rend()
#define pub push_back
#define puf push_front
#define pob pop_back
#define pof pop_front
#define ff first
#define ss second
#define P 1000000007
#define in(x, a, b) (a <= x && x < b)
#define CASET int ___T; scanf("%d", &___T); for(int cs=1;cs<=___T;cs++)

using namespace std;
using ll = long long;
typedef pair<int, int> ii;
typedef vector<ii> vii; 
typedef vector<int> vi;
const ll inf = 1000000001, INF = (ll)1e18 + 1;

void solve() {
	int n;
	cin >> n;
	vi a(n);
	for(int i = 0; i < n; i++) cin >> a[i];
	
	int ans = 0;
	for(int i = 0; i < n; i += 2) {
		if(a[i] % 2) ans++;
	} 
	
	cout << ans << endl;
}

int main(){
#define MULTITEST 0
#if MULTITEST   
 
    CASET {
        solve();
    }
    
#else

    solve();
    
#endif

    return 0;
}

Measured memory_bytes: 3568