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

public class Main {
	@SuppressWarnings("resource")
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int A=sc.nextInt();
		int B=sc.nextInt();
		int M=sc.nextInt();
		int a[]=new int[A];
		int b[]=new int[B];
		int minA=100000;
		int minB=100000;
		for(int i=0;i<A;i++) {
			a[i]=sc.nextInt();
			if(a[i]<minA){
				minA=a[i];
			}
		}
		for(int i=0;i<B;i++) {
			b[i]=sc.nextInt();
			if(b[i]<minB){
				minB=b[i];
			}
		}
		int ans=minA+minB;
		int x[]=new int[M];
		int y[]=new int[M];
		int c[]=new int[M];
		for(int i=0;i<M;i++) {
			x[i]=sc.nextInt();
			y[i]=sc.nextInt();
			c[i]=sc.nextInt();
			if(ans>a[x[i]-1]+b[y[i]-1]-c[i]) {
				ans=a[x[i]-1]+b[y[i]-1]-c[i];
			}
		}
		System.out.println(ans);


	}
}


Measured memory_bytes: 135980
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
typedef long long ll;
typedef pair<ll, ll> P;
const ll INF = 1001001001;

ll mp[10000005] = {};
ll mp2[10000005] = {};

ll beki(ll a, ll b) {
  if (b == 0) return 1;
  ll ret = beki(a, b / 2);
  ret = ret * ret;
  if (b & 1) ret = ret * a;
  return ret;
}

int main() {
  ll n;
  cin >> n;
  for (ll i = 1; i <= n; i++) {
    if (i == 1) {
      mp[1] = 1;
      continue;
    }
    if (mp[i] == 0) {
      for (ll j = i; j <= n; j *= i) {
        for (ll k = 1; j * k <= n; k++) {
          mp2[j * k]++;
        }
      }
      for (ll j = 1; i * j <= n; j++) {
        if (mp[i * j] == 0) {
          mp[i * j] = mp2[i * j] + 1;
          mp2[i * j] = 0;
        } else {
          mp[i * j] *= mp2[i * j] + 1;
          mp2[i * j] = 0;
        }
      }
    }
  }
  ll ans = 1;
  for (ll i = 2; i <= n; i++) {
    ans += i * (mp[i]);
    // cout << "i=" << i << ", mp=" << mp[i] << endl;
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 159856
import java.util.*;
public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        int K = sc.nextInt();
        String S = sc.next();
        String[] SH = S.split("");
        SH[K-1] =  SH[K-1].toLowerCase();
        String X = String.join("",SH);
        System.out.println(X);
    }
}

Measured memory_bytes: 21844
#include <iostream>
#include <algorithm>
#include <vector>
#define MAX_N 200
using namespace std;


class Edge {
public:
  int from, to, cost;
  Edge(int from, int to, int cost) : from(from), to(to), cost(cost) {}
  bool operator < (const Edge &e) const {
    return cost < e.cost;
  }
};

int n, m;
vector<Edge> e;

int par[MAX_N];
int rank[MAX_N];

void init(int n) {
  for(int i = 0; i < n; ++i) {
    par[i] = i;
    rank[i] = 0;
  }
}

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

void unite(int x, int y) {
  x = find(x);
  y = find(y);
  if(x == y) return;
  if(rank[x] < rank[y]) {
    par[x] = y;
  } else {
    par[y] = x;
    if(rank[x] == rank[y]) ++rank[x];
  }
}

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

#define INF 99999999

int kruskal() {
  int last;
  int cnt = 1;
  init(n);

  for(int i = 0; i < e.size(); ++i) {
    if(!same(e[i].from, e[i].to)) {
      unite(e[i].from, e[i].to);
      last = i;
      ++cnt;
      if(cnt == n) break;
    }
  }

  return cnt == n ? e[last].cost - e[0].cost : INF;
}

void solve() {
  int ans = INF;
  sort(e.begin(), e.end());
  for(int i = 0; i < m; ++i) {
    int res = kruskal();
    if(res == INF) break;
    ans = min(ans, res);
    e.erase(e.begin());
  }
  if(ans == INF) ans = -1;
  cout << ans << endl;
}

main() {
  while((cin >> n >> m) && (n || m)) {
    e.clear();
    for(int i = 0; i < m; ++i) {
      int u, v, w;
      cin >> u >> v >> w;
      --u; --v;
      e.push_back(Edge(u, v, w));  
    }
    solve();
  }
}

Measured memory_bytes: 1068
import bisect
N = int(input())
L = sorted(list(map(int,input().split())))
ans = 0

for i in range(N):
  for j in range(i+1,N):
    c = bisect.bisect_left(L, L[i]+L[j])
    ans += c - j - 1
print(ans)
         

Measured memory_bytes: 9372
// a

// thanks to http://labelray.top/2018/08/19/agc-012-c-tautonym-puzzle/
// coded myself

// S[t+1] = (len(t)+1) + S[t]
// S[2*t+1] = S[t] + [len(t)+1]

#include <iostream>

using namespace std;

long long N;

const int MAX = 200;
int lft[MAX];
int lp = 0;
int rigt[MAX];
int rp = 0;

int current = 100;

void solve(long long x) {
    if (x<=0) return;
    if (!(x&1)) {
        lft[lp++] = current--;
        solve(x-1);
    } else {
        rigt[rp++] = current--;
        solve(x/2);
    }
}

int main() {
    cin >> N;
    solve(N);
    cout << 2 * (lp + rp) << endl;
    for (int i=0; i<lp; i++) {
        cout << lft[i] << " ";
    }
    for (int i=rp-1; i>=0; i--) {
        cout << rigt[i] << " ";
    }
    for (int i=101-rp-lp; i<101; i++) {
        cout << i << " ";
    }
    cout << endl;
    return 0;
}

Measured memory_bytes: 256
import math

def main():
    N, K = map(int, input().split())
    # 面倒なので、番号を1引いた状態で扱い、最後に1を足す
    A = [ int(x) - 1 for x in input().split()]
    
    # ダブリング用テーブル
    D = [ [A[n] for n in range(N)] ]
    # max(K) = 10^18 なので、max(log2K) = 60
    log2K = int(math.log2(K)) + 1
    for i in range(log2K):
        d = [D[i][n] for n in D[i]]
        D.append(d)
    # print(D)
    town = 0
    for i in range(log2K):
        if K & (1 << i) != 0:
            town = D[i][town]

    print(town + 1)

if __name__ == '__main__':
    main()

Measured memory_bytes: 115228
import java.util.Scanner;

public class Main {

 private static int     max   = 0;
 private static int     count = 100;
 private static int[][] ps;

 public static void main(String[] args) {
	Scanner in = new Scanner(System.in);
	ps = new int[14][14];
	while (in.hasNextLine()) {
	 String[] data = in.nextLine().split(",");
	 int x = Integer.parseInt(data[0]);
	 int y = Integer.parseInt(data[1]);
	 int size = Integer.parseInt(data[2]);
	 spoit(x, y);
	 spoit(x + 1, y);
	 spoit(x - 1, y);
	 spoit(x, y + 1);
	 spoit(x, y - 1);
	 if (size >= 2) {
		if (y - 1 >= 0) {
		 spoit(x + 1, y - 1);
		 spoit(x - 1, y - 1);
		}
		if (y + 1 < 10) {
		 spoit(x + 1, y + 1);
		 spoit(x - 1, y + 1);
		}
	 }
	 if (size >= 3) {
		spoit(x + 2, y);
		spoit(x - 2, y);
		spoit(x, y + 2);
		spoit(x, y - 2);
	 }
	}
	System.out.println(count);
	System.out.println(max);

 }

 private static void spoit(int x, int y) {
	if (0 <= x && x < 10 && 0 <= y && y < 10) {
	 if (ps[x][y] == 0) {
		count--;
	 }
	 int result = ps[x][y] + 1;
	 max = Math.max(result, max);
	 ps[x][y] = result;
	}
 }
}

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

int main() {
    int n, k;
    cin >> n >> k;
    vector<double> e(n), se(n - k + 1);
    for (int i = 0; i < n; i++) {
        double p;
        cin >> p;
        e[i] = (p + 1) / 2;
    }
    double ans = 0;
    for (int i = 0; i < k; i++) {
        se[0] += e[i];
    }
    for (int i = k; i < n; i++) {
        se[i - k + 1] = se[i - k] + e[i] - e[i - k];
    }
    for (int i = 0; i < se.size(); i++) {
        ans = max(ans, se[i]);
    }
    cout << setprecision(10) << ans << endl;
    return 0;
}

Measured memory_bytes: 3328
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>

using namespace std;

int main(void) {

	int C[4];

	vector<int> V;

	for (int i = 1; i <= 3; i++) {
		cin >> C[i];
		V.push_back(C[i]);
	}

	sort(V.begin(), V.end());

	cout << V[0] + V[1] << endl;

	return 0;
}

Measured memory_bytes: 256
# -*- coding: utf-8 -*-

N,K = list(map(int, input().rstrip().split()))
x_list = list(map(int, input().rstrip().split()))
#-----

cnt_time = (10**8)*K
for l in range(N-K+1):
    r=l+K-1

    route1 = abs(x_list[l]) + abs(x_list[r] - x_list[l])
    route2 = abs(x_list[r]) + abs(x_list[r] - x_list[l])
    cnt_time = min( cnt_time, route1, route2 )

print(cnt_time)



Measured memory_bytes: 14228
#include <bits/stdc++.h>
#define ll long long
#define pb push_back
#define fast ios::sync_with_stdio(0);cin.tie(0);
using namespace std;
vector<vector<int>>g;
int main() {
    fast
    int n,m;
    cin>>n>>m;
    ll h[n+1];
    for(int i=1;i<=n;i++)cin>>h[i];
    g.assign(n+1,vector<int>());
    for(int i=1;i<=m;i++)
    {
        int u,v;
        cin>>u>>v;
        g[u].pb(v);
        g[v].pb(u);
    }
    int ans=0;
    for(int i=1;i<=n;i++)
    {
        bool flag=true;
        for(auto u:g[i])
            if(h[i]<=h[u]){flag=false;break;}
        if(flag)ans++;   
    }
    cout<<ans;
    return 0;

}

Measured memory_bytes: 9208
#include<cstdio>

using namespace std;

int simulate(int row,int turn,int weight);

int book[101];

int main(void)
{
   int row,turn;
   while(scanf("%d%d",&row,&turn),row+turn)
   {
      for(int i = 0;i < turn;i++)
         scanf("%d",&book[i]);

      int flag = 0;
      int left = 0,right = 1500000;
      while(left <= right)
      {
         int mid = (left+right)/2;
         int check = simulate(row,turn,mid);

         if(check == -1) left = mid + 1;
         else right = mid - 1;
      }
      printf("%d\n",left);
   }
   return 0;
}

int simulate(int row,int turn,int weight)
{
   int book_id = 0;
   int current_row = 1;
   int remaining_weight = weight;
   while(row >= current_row)
   {
      if(book_id == turn) return 1;
      if(book[book_id] <= remaining_weight)
      {
         remaining_weight -= book[book_id];
         book_id++;
      }
      else
      {
         current_row++;
         remaining_weight = weight;
      }
   }
   return -1;
}

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

#define REP(i, n) for(int i = 0; i < (int)(n); ++i)


int main()
{
    int N, x;
    cin >> N >> x;
    vector<int> a(N);
    REP(i, N) cin >> a[i];

    long long ans = accumulate(a.begin(), a.end(), (long long) 0);
    // 何回魔法を唱えるかを全探索
    for(int i = 1; i < N; ++i){
        long long time = (long long) x * i;
        int tmp = a[N-1];
        for(int j = N-1; j >= 0; --j){
            a[j] = min(a[j], j == 0? tmp: a[j-1]);
            time += a[j];
        }
        ans = min(ans, time);
    }
    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 256
import bisect

N = int(input())
A = list(map(int, input().split()))
B = list(map(int, input().split()))
C = list(map(int, input().split()))

A.sort()
C.sort()

count = 0

for b in B:
    index_b = bisect.bisect_left(A, b)
    index_c = bisect.bisect_right(C, b)
    count += (N - index_c) * index_b

print(count)

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


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

  int M = 0;
  int m = 1001;

  for(int i=0;i<N;i++){
     M = max(M,a[i]);
     m = min(m,a[i]);
  }

  cout << M - m << endl;
  return 0;
}

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

#define all(x) (x).begin(), (x).end()
#define li long long
#define itn int

using namespace std;

inline int nxt(){
	int n;
	scanf("%d", &n);
	return n;
}

int gcd(int x, int y){
	while (y){
		x %= y;
		swap(x, y);
	}
	return x;
}

const int mod = 1000000007;

long long pw(long long a, long long b){
	long long res = 1;
	while (b){
		if (b & 1ll)
			res = res * a % mod;
		b >>= 1;
		a = a * a % mod;
	}
	return res;
}

int main(){

	string s;
	cin >> s;
	int c1 = 0, c2 = 0;
	for (char c : s){
		if (c == 'N')
			c1 |= 1;
		else if (c == 'S')
			c1 |= 2;
		else if (c == 'E')
			c2 |= 1;
		else
			c2 |= 2;
	}

	if ((c1 - 3) * c1 == 0 && (c2 - 3) * c2 == 0)
		puts("Yes");
	else
		puts("No");

	return 0;
}


Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
	public static void main(String args[]) {
		Scanner stdIn = new Scanner(System.in);
		int N = stdIn.nextInt();
		int D = stdIn.nextInt();
		double X;
		double Y;
		int count = 0;
		for(int i = 0; i < N; i ++) {
			X = stdIn.nextDouble();
			Y = stdIn.nextDouble();
			if(Math.sqrt(X * X + Y * Y) <= D) {
				count ++;
			}
		}
		System.out.println(count);
	}
}

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

  int N,K,S,i;
  cin>>N>>K>>S;
  vector<int> arr; 
  int val;
  val=S;
  for(i=0;i<K;i++){
  	arr.push_back(val);
  	 }
  for(i=K;i<N;i++){
  if(S==1000000000){arr.push_back(1);}
  else{
  
  arr.push_back(val+1); 
}
  }
  for(i=0;i<N;i++)
  { cout<<arr[i]<<" " ;  }
  return 0;
  }

Measured memory_bytes: 1784
#include <algorithm>
#include <bitset>
#include <cmath>
#include <iomanip>
#include <iostream>
#include <sstream>
#include <unordered_map>
#include <unordered_set>
#include <vector>

#define rep(i, n) for (int i = 0; i < n; ++i)
#define debug(s, param) std::cerr << s << param << std::endl;

using namespace std;
using ll = long long;

int main() {
  int n, x, t;
  cin >> n >> x >> t;
  for (int i = 0; i < 10000; ++i) {
    if (x * i >= n) {
      cout << i * t << endl;
      break;
    }
  }
  return 0;
}

Measured memory_bytes: 3592
#include<stdio.h>

int main(){

  int x,y,r;

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

  if(x<y){
    x+=y;
    y=x-y;
    x-=y;
  }
  while(y!=0){
    r=x%y;
    x=y;
    y=r;
  }
  
  printf("%d\n",x);

  return 0;
}



Measured memory_bytes: 2072
#include <bits/stdc++.h>
#define M ((ll)1e9+7)
#define F first
#define S second
#define pb push_back
#define mp make_pair
#define pi acos(-1)
typedef long long ll;
using namespace std;


void solve()
{
   ll t1,t2,a1,a2,b1,b2;
   cin>>t1>>t2>>a1>>a2>>b1>>b2;
       if((a1==b1&&a2>b2)||(a1<b1)){
       swap(a1,b1);
       swap(a2,b2);}
   ll d=(a1-b1)*t1+(a2-b2)*t2;
   //cout<<d<<endl;
   if(d==0)
   cout<<"infinity"<<endl;
   else if(d>0)
   cout<<"0"<<endl;
   else
   {
       //cout<<1<<endl;
       ll v=((a1-b1)*t1)/abs(d);
       if(a1==b1)
       cout<<1<<endl;
       else if(((a1-b1)*t1)%abs(d)==0)
       cout<<2*v<<endl;
       else
       cout<<2*v+1<<endl;
   }
}
int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
	solve();
	return 0;
}

Measured memory_bytes: 256
//use proconio::input;
use std::cmp::min;

macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
    ($($r:tt)*) => {
        let s = {
            use std::io::Read;
            let mut s = String::new();
            std::io::stdin().read_to_string(&mut s).unwrap();
            s
        };
        let mut iter = s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
}

macro_rules! input_inner {
    ($iter:expr) => {};
    ($iter:expr, ) => {};

    ($iter:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($iter, $t);
        input_inner!{$iter $($r)*}
    };
}

macro_rules! read_value {
    ($iter:expr, ( $($t:tt),* )) => {
        ( $(read_value!($iter, $t)),* )
    };

    ($iter:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($iter, $t)).collect::<Vec<_>>()
    };

    ($iter:expr, chars) => {
        read_value!($iter, String).chars().collect::<Vec<char>>()
    };

    ($iter:expr, usize1) => {
        read_value!($iter, usize) - 1
    };

    ($iter:expr, $t:ty) => {
        $iter.next().unwrap().parse::<$t>().expect("Parse error")
    };
}

fn main() {
    input! {
        n: usize,
        k: usize,
        h: [i32; n],
    }
    let k = min(n, k);
    let mut dp = vec![0; n];
    for i in 1..k {
        let mut dpi = dp[i - 1] + (h[i] - h[i - 1]).abs();
        for j in 2..(i + 1) {
            dpi = min(dpi, dp[i - j] + (h[i] - h[i - j]).abs());
        }
        dp[i] = dpi;
    }
    for i in k..n {
        let mut dpi = dp[i - 1] + (h[i] - h[i - 1]).abs();
        for j in 2..(k + 1) {
            dpi = min(dpi, dp[i - j] + (h[i] - h[i - j]).abs());
        }
        dp[i] = dpi;
    }

    println!("{}", dp[n - 1]);
}


Measured memory_bytes: 6396
#define _CRT_SECURE_NO_WARNINGS
#define _USE_MATH_DEFINES
#include <iostream>
#include <utility>
#include <algorithm>
#include <set>
#include <map>
#include <string>
#include <queue>
#include <functional>
#include <stdlib.h>
#include <climits>
#include <iomanip>
#include <complex>
#include <cmath>
#include <vector>
using namespace std;
signed main(void)
{
	int n, h;
	cin >> n >> h;
	typedef pair<int, int> P;
	vector<P> num;
	int a, b;
	int t = 0;
	for (int i = 0; i < n; i++) {
		cin >> a >> b;
		num.push_back( P(a, 0));
		num.push_back(P(b,1));
	}
	sort(num.begin(),num.end());
	 t = n*2 - 1;
	int ans = 0;
	while (1) {
		if (h <= 0)break;
		if (num[t].second == 1) { h -= num[t].first; ans += 1; t -= 1; }
		else {
			if (h%num[t].first == 0) { ans += h / (num[t].first); break; }
			else { ans += 1 + h / (num[t].first); break; }
		}
	}
	cout << ans;
	return 0;
}


Measured memory_bytes: 2420
local as = io.read()
local bs = io.read()
local n, m = #as, #bs
local a, b = {}, {}
for i = 1, n do
  a[i] = as:sub(i, i)
end
for i = 1, m do
  b[i] = bs:sub(i, i)
end
if n < m then
  print("LESS")
elseif m < n then
  print("GREATER")
else
  local f = 0
  for i = 1, n do
    if a[i] < b[i] then
      f = 1
      break
    elseif b[i] < a[i] then
      f = -1
      break
    end
  end
  if f == 1 then
    print("LESS")
  elseif f == -1 then
    print("GREATER")
  else
    print("EQUAL")
  end
end


Measured memory_bytes: 760
import math
n,d = map(int, input().split())

list = []
for i in range(n):
  a = [int(i) for i in input().split()] 
  list.append(a)
count = 0
for i in range(n):
  for j in range(n):
    if j > i:
      root = 0
      root2 = 0
      for k in range(d):
        tmp = (list[i][k] - list[j][k])*(list[i][k] - list[j][k])
        root = root + tmp
      root3 = math.sqrt(root)
      if root3.is_integer():
           count = count +1
print(count)
      

Measured memory_bytes: 3064
#define _USE_MATH_DEFINES
#include<iostream>
#include<string>
#include<queue>
#include<cmath>
#include<map>
#include<set>
#include<list>
#include<iomanip>
#include<vector>
#include<random>
#include<functional>
#include<algorithm>
#include<stack>
#include<cstdio>
#include<cstring>
#include<bitset>
#include<unordered_map>
#include<climits>
#include<fstream>
#include<time.h>
#include<cassert>

using namespace std;
#define ll long long
#define ld long double
#define int long long
#define all(a) (a).begin(),(a).end()
#define EPS (1e-13)
#define fs first
#define sc second
#define xx first
#define yy second.first
#define zz second.second
#define P pair<int, int>
#define Q pair<int, pair<int, int>>
#define rep(i,n) for(int (i) = 0 ; (i) < (n) ; (i)++)
#define mkp make_pair
#define pb push_back
#define lb lower_bound
#define ub upper_bound
#define crdcomp(b) sort(all((b)));(b).erase(unique(all((b))),(b).end())
const int Mod = 1e9 + 7;
const int mod = 998244353;
const ll Inf = 3 * 1e18;
const int inf = 15 * 1e8;
ll read() {
	ll u, k = scanf("%lld", &u);
	return u;
}
ll gcd(ll i, ll j) {
	if (i > j) swap(i, j);
	if (i == 0) return j;
	return gcd(j % i, i);
}
ll mod_pow(ll x, ll n, ll p) {
	ll res = 1;
	while (n > 0) {
		if (n & 1) res = res * x % p;
		x = x * x % p;
		n >>= 1;
	}
	return res;
}//x^n%p
ll bcount(ll x) {
	int sum = 0;
	for (int i = 0; i < 20; i++)
		if ((1ll << i) & x) sum++;
	return sum;
}
/*ll fact_[200000];
ll comb(ll x, ll y, ll mod = Mod) {
	if (!fact_[0]) {
		fact_[0] = 1;
		for (int i = 1; i < 200000; i++) {
			fact_[i] = fact_[i - 1] * i % mod;
		}
	}
	if (x < y) return 0;
	return mod_pow(fact_[x], mod, mod) *
		mod_pow(fact_[x - y], mod - 2, mod) % mod *
		mod_pow(fact_[y], mod - 2, mod) % mod;
}*/
//---------------------------------------------------
int btmod(string& s) {
	int res = 0;
	for (int i = 0; i < s.size(); i++) {
		res *= 2;
		(res += (int)(s[i] - '0')) %= mod;
	}
	return res;
}
signed main() {
	int n;
	string s;
	cin >> n >> s;
	vector<int>b(300000);
	int ans = 0;
	for (int i = 1; i <= n; i++) {
		if (n % i || !((n / i) % 2)) continue;
		string tmp = "";
		string k;
		for (int j = 0; j < n; j++) {
			if ((j / i) % 2) {
				if (s[j] == '1') tmp += "0";
				else tmp += "1";
			}
			else tmp += s[j];
			if ((j + 1) % i == 0) {
				if (j / i == 0) {
					(b[i] += btmod(tmp)) %= mod;
					k = tmp;
				}
				else if ((j / i) % 2) {
					if (tmp > k) goto loop;
					if (tmp < k) break;
				}
				else {
					if (tmp < k) goto loop;
					if (tmp > k) break;
				}
				tmp = "";
			}
		}
		b[i]++;
	loop:;
		b[i] = (b[i] % mod + mod) % mod;
		for (int j = i * 2; j <= n; j += i)
			b[j] -= b[i];
		(ans += b[i] * i * 2) %= mod;
	}
	cout << ans << endl;
}

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

#include<cstdio>
#define r(i,n) for(int i=0;i<n;i++)

int main(void){
  int x,maxi=1;
  cin>>x;
  int y=sqrt(x);
  for(int i=2;i<=y+1;i++){
    for(int j=i*i;j<=x;j*=i){
      maxi=max(maxi,j);
    }
  }
  cout<<maxi<<endl;

return 0;}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define pb push_back
#define mod 1000000007

int Max(int x, int y)
{
    return (((y-x)>>(32-1))&(x^y))^y;
}

int Min(int x, int y)
{
    return (((y-x)>>(32-1))&(x^y))^x;
}


int f(int a, int b, int m)
{
    if(a>b)
        return 0;
    if(a==b)
    {
        if(a%m==0)
            return 1;
        return 0;
    }
    if(a%m==0)
        return (b/m)-(a/m)+1;
    return (b/m)-(a/m);
}

int32_t main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    //Initialize variables while declaring them
    int n, l, diff=100000000, sum=0, sub;
    cin>>n>>l;
    vector<int> v;
    for(int i=0; i<n; i++)
    {
        v.pb(l+i);
        sum+=v.back();
        // cout<<v.back()<<" ";
    }
    for(int i=0; i<n; i++)
        if(abs(v[i])<diff)
        {
            diff=abs(v[i]);
            sub=v[i];
        }
    cout<<sum-sub;
    // /cout<<diff;
    return 0;
}

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

set<string> st;
int n;
int mask;
string s;
int pt;
void solve(int len, int used){
  if(len==n){
    // cout<<s<<endl;
    if((used == mask)){
      st.insert(s);
    }
    return;
  }
  for(int i=0;i<=pt;i++){
    if(i > 0 && !(used & (1<<(i-1)) ) )break;
    char c = 'a' + i;
    s[len] = c;
    solve(len+1, used | (1<<i));
  }
}

int main(int argc, char *argv[]) {
  ios::sync_with_stdio(false);cin.tie(nullptr);cout.tie(nullptr);

  cin>>n;

  s="";
  for(int i=0;i<n;i++)s+='a';
  for(int i=0;i<n;i++){
    mask |= (1<<i);
    pt = i;
    solve(0, 0);
  }

  for(auto t : st) {
    cout<<t<<endl;
  }

  return 0;
}


Measured memory_bytes: 12416
import Control.Monad
import Data.Maybe
import qualified Data.ByteString.Char8 as BS
import Data.List
import qualified Data.Vector.Unboxed as VU
import qualified Data.Vector.Unboxed.Mutable as VUM
import qualified Data.Vector as V
import qualified Data.Vector.Mutable as VM
import Data.Maybe
import qualified Data.Sequence as Sq

readInt = fst . fromJust . BS.readInt
readIntList = map readInt . BS.words
getInt = readInt <$> BS.getLine
getIntList = readIntList <$> BS.getLine

main = do
    [n,m] <- getIntList
    ab <- replicateM (n-1+m) $ do
        [a,b] <- getIntList
        return (a-1,b-1)

    din' <- VUM.replicate n (0 :: Int)
    edge' <- VM.replicate n ([] :: [Int])
    pars' <- VUM.replicate n (0 :: Int)
    forM_ ab $ \(a,b) -> do
        VM.modify edge' (b:) a
        VUM.modify din' succ b
    edge <- V.freeze edge'

    (v0:_) <- filterM (fmap (== 0) . VUM.read din') [0..n-1] 

    let go Sq.Empty = return ()
        go ((p,v) Sq.:<| sq) = do
            VUM.write pars' v (p+1)
            let nexts = edge V.! v
            forM_ nexts $ \i -> do
                VUM.modify din' pred i
            nxsq <- filterM (fmap (==0) . VUM.read din') nexts
            let sq' = foldl' (Sq.|>) sq $ map (\x -> (v,x)) nxsq
            go sq'
    go (Sq.singleton (-1,v0))
    pars <- VU.freeze pars'
    VU.mapM_ print pars

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

const int MAX_N = 1005;

int n, t[MAX_N], a[MAX_N];

bool possible(ll total) {
	ll x = total / (t[n - 1] + a[n - 1]);
	ll curr_t = x * t[n - 1];
	ll curr_a = x * a[n - 1];
	
	for(int i = n - 2; i >= 0; i--) {
		if(curr_t == 0 || curr_a == 0) {
			return false;
		}

		ll y = min(curr_t / t[i], curr_a / a[i]);
		curr_t = t[i] * y;
		curr_a = a[i] * y;
	}

	if(curr_t == 0 || curr_a == 0) {
		return false;
	}
	else {
		return true;
	}
}

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

	ll low = 1, high = 1e18 / (t[n - 1] + a[n - 1]), mid, ans;
	while(low <= high) {
		mid = (low + high) / 2;
		
		if(possible(mid * (t[n - 1] + a[n - 1]))) {
			high = mid - 1;
			ans = mid * (t[n - 1] + a[n - 1]);
		}
		else {
			low = mid + 1;
		}
	}

	printf("%lld\n", ans);
	return 0;
}


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

using namespace std;

bool pr[150000];

void erato(){
	fill(pr, pr+150000, true);
	pr[0] = pr[1] = false;
	
	for(int i=2; i < 150000; i++){
		if(!pr[i]) continue;
		for(int j=i+i; j < 150000; j+=i) pr[j] = false;
	}
}

int main(){
	erato();
	int n, p;
	while(cin >> n >> p, n+p!=-2){
		vector<int> prime;
		int count = 0;
		for(int i=n+1;; i++){
			if(pr[i]){ prime.push_back(i); count++;}
			if(count == 100) break;
		}
		
		vector<int> prime_w;
		for(int i=0; i < prime.size(); i++){
			for(int j=i; j < prime.size(); j++){
				prime_w.push_back(prime[i]+prime[j]);
			}
		}
		sort(prime_w.begin(), prime_w.end());
		
		cout << prime_w[p-1] << endl;
	}
}

Measured memory_bytes: 1420
#include <iostream>
#include <algorithm>
#include <complex>
using namespace std;

typedef complex<double> P;

const double eps = 1e-8;

bool equals(double a, double b) {
  return abs(a-b) < eps;
}

double dot(P a, P b) {
  return a.real()*b.real() + a.imag()*b.imag();
}

int main() {
  P ps[4];
  while(1) {
    for(int i = 0; i < 4; ++i) {
      if(cin >> ps[i].real() >> ps[i].imag()) ; else return 0;
    }
    if(equals(dot(ps[0]-ps[1], ps[2]-ps[3]), 0.0)) {
      cout << "YES" << endl;
    } else {
      cout << "NO" << endl;
    }
  }
  return 0;
}

Measured memory_bytes: 1216
#include <iostream>
#include <iomanip>
#include <cmath>
#include <vector>
#include <string>
#include <algorithm>
#include <cstdlib>
#include <limits>
#include <numeric>

using namespace std;

int main()
{
	int a, b;
	string op;
	cin >> a >> op >> b;

	if (op == "+") {
		cout << a + b << endl;
	}
	else {
		cout << a - b << endl;
	}

	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <string>
#include <algorithm>
#include <math.h>
#include <map>
#include <vector>

//#define PI 3.141592653589

using namespace std;




int main()
{
	int n;
	string event;
	int out;
	int rui[4];
	int tokuten;
	
	cin >> n;
	for (int i=0; i<n; i++)
	{
		out = 0;
		tokuten = 0;
		for (int j=0; j<4; j++) rui[j] = 0;
		while (cin >> event)
		{
			if (event == "HIT")
			{
				rui[3] = rui[2];
				rui[2] = rui[1];
				rui[1] = rui[0];
				rui[0] = 1;
				tokuten += rui[3];
				rui[3] = 0;
			} else if (event == "HOMERUN") {
				tokuten += rui[0] + rui[1] + rui[2] + 1;
				rui[0] = rui[1] = rui[2] = 0;
			} else if (event == "OUT") {
				out += 1;
				if (out == 3)
				{
					cout << tokuten << endl;
					break;
				}
			}
		}
	}
	
	return 0;
}

Measured memory_bytes: 1208
#include<iostream>
#include<stdio.h>
#include<string.h>
#include<algorithm>
#define maxn 200005
using namespace std;
typedef long long ll;
const ll mod=998244353;
int n,val;
char s[maxn];
ll dp[maxn][5][5][5];
int check()
{
	int flag=false;
	for(int i=1;i<=n;i++)
	{
		val=(val+s[i]-'a')%3;
		if(s[i]!=s[1])
			flag=true;
	}
	return flag;
}
int main()
{
	scanf("%s",s+1); n=strlen(s+1);
	if(!check())
		return printf("1\n"),0;
	if(n==2)
		return printf("2\n"),0;
	if(n==3)
		return ((s[1]!=s[2] && s[1]!=s[3] && s[2]!=s[3])?printf("3\n"):(s[1]==s[3] ? printf("7\n") : printf("6\n"))),0;
 
	dp[0][0][0][3]=1;
 
	for(int i=0;i<n;i++)
	{
		for(int j=0;j<3;j++)
		{
			for(int k=0;k<=1;k++)
			{
				for(int now=0;now<=3;now++)
				if(dp[i][j][k][now])
				{
					for(int nex=0;nex<=2;nex++)
					{
						ll &temp=dp[i+1][(j+nex)%3][k|(now==nex)][nex];
						temp=temp+dp[i][j][k][now];
						if(temp>=mod)
							temp-=mod;
					}
				}
			}
		}
	}
 
	ll ans=1;
	for(int i=0;i<3;i++)
	{
		ans+=dp[n][val][1][i];
		if(ans>=mod)
			ans-=mod;
	}
	for(int i=1;i<n;i++)
		if(s[i]==s[i+1])
		{
			ans--;
			break;
		}
 
	printf("%lld\n",(ans%mod+mod)%mod);
 
}

Measured memory_bytes: 195712
#include<bits/stdc++.h>
using namespace std;
#define ll long long int 
#define fastio ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
int main(){
	#ifndef ONLINE_JUDGE
		freopen("input.txt","r",stdin);
		freopen("output.txt","w",stdout);
	#endif
	int n;
	cin>>n;
	vector<int>ar;
	set<int>st;
	while(n--){
		int a;
		cin>>a;
		ar.push_back(a);
		st.insert(a);
	}
	if(ar.size()==st.size()) cout<<"YES";
	else cout<<"NO";
	return 0;
}


Measured memory_bytes: 13440
#include <bits/stdc++.h>
using namespace std;
#define REP(i, n) for(int i = 0;i < n;i++)
#define REPR(i, n) for(int i = n;i >= 0;i--)
#define FOR(i, m, n) for(int i = m;i < n;i++)
#define itrfor(itr,A) for(auto itr = A.begin(); itr !=A.end();itr++)
typedef long long llong;
char moji[26]={'a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z'};
char moji2[26]={'A','B','C','D','E','F','G','H','I','J','K','L','M','N','O','P','Q','R','S','T','U','V','W','X','Y','Z'};
char moji3[10]={'0','1','2','3','4','5','6','7','8','9'};
#define Sort(a) sort(a.begin(),a.end());
#define Reverse(a) reverse(a.begin(),a.end());
#define print(a) cout << a << endl; 



int main(){
    llong x;
    cin >> x;
    llong ans=0;
    llong sum=0;
    while( sum < x){
        ans+=1;
        sum+=ans;
    }
    print(ans);

}

Measured memory_bytes: 256
//#pragma GCC optimize ("-O3","unroll-loops")
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<queue>
#include<map>
#include<math.h>
#include<iomanip>
#include<set>
#include<numeric>
#include<cstring>
#include<cstdio>
#include<functional>
#include<bitset>
#include<limits.h>
#include<cassert>
#include<iterator>
#include<complex>
#include<stack>


#define REP(i, n) for(int i = 0;i < n;i++)
#define REPR(i, n) for(int i = n;i >= 0;i--)
#define FOR(i, m, n) for(int i = m;i < n;i++)
#define FORR(i, m, n) for(int i = m;i >= n;i--)
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
#define REVERSE(v,n) reverse(v,v+n);
#define VREVERSE(v) reverse(v.begin(), v.end());
#define ll long long
#define pb(a) push_back(a)
#define m0(x) memset(x,0,sizeof(x))
#define print(x) cout<<x<<'\n';
#define pe(x) cout<<x<<" ";
#define lb(v,n) lower_bound(v.begin(), v.end(), n);
#define ub(v,n) upper_bound(v.begin(), v.end(), n);
#define int long long
#define all(x) (x).begin(), (x).end()
//#define double long double

using namespace std;

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

const int MOD = 1000099253;
const int MOD2 = 1000311461;
const ll INF = 1e17;
const int INT_INF = 1e9;
const double pi = acos(-1);
const double EPS = 1e-10;
typedef pair<int, int>P;
const int MAX = 100010;



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

	string S; cin >> S;
	REP(i, 4) {
		cout << S[i];
	}
	cout << " ";
	FOR(i, 4, 12) {
		cout << S[i];
	}
	cout << endl;
}

Measured memory_bytes: 256
import java.io.IOException;
import java.io.InputStream;
import java.util.*;
import java.lang.Math;

public class Main {
    public static void main(String[] args) {
        FS reader = new FS();
        // write reader
        int N = reader.nextInt();
        for (int i=1; i<10; i++) {
            if (N%i == 0 && N/i < 10) {
                System.out.println("Yes");
                return;
            }
        }
        System.out.println("No");
    }

    public static long[][] warshall(int n, long[][]matrix) {
        long[][] ans = matrix;
        for(int i=0; i<n; i++) {
            ans[i][i] = 0;
        }
        for(int i=0; i<n; i++) {
            for(int j=0; j<n; j++) {
                for(int k=0; k<n; k++) {
                    ans[j][k] = Math.min(ans[j][k], ans[j][i]+ans[i][k]);
                }
            }
        }
        return ans;
    }

    // Read Class
    static class FS {
        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() { return hasNextByte() ? buffer[ptr++] : -1;}
        private boolean isPrintableChar(int c) {return 33 <= c && c <= 126;}
        private void skipUnprintable() {while(hasNextByte() && !isPrintableChar(buffer[ptr])) ptr++;}
    
        public boolean hasNext() { skipUnprintable(); 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 int nextInt() {
            return (int)nextLong();
        }
        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();
            }
        }
    }
}



Measured memory_bytes: 22996
//10のi乗pow(10, i);
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)

int main() {
  int n;
  cin >> n;
  vector<double>a(n);
  rep(i,n) cin>>a.at(i);
  double sum=0;
  rep(i,n) sum += 1/a.at(i);
  cout << 1/sum << endl;
}

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

  #define vi vector<int>
  #define all(v) v.begin(),v.end()
  #define ll long long int
  #define  IOS    ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
  #define D1(x) {cerr<<" [" <<#x<<": "<<x<<"]";cout << endl;}
  #define D2(x) {cerr<<" [" <<#x<<": ";for(auto it:x)cerr<<it<< " ";cerr<<"] ";cout << endl;}

  const ll MOD=1e9+7;

  void solve(){
     int n;
     cin >> n;
     ll prod=1;
     for(ll i = 1;i<=n;i++){
       prod = (prod%MOD*i%MOD)%MOD;
     }
     cout << prod;

  }


  int main(){
    IOS
       solve();
       cerr <<endl <<"[ Time : " << (float)clock() / CLOCKS_PER_SEC << " secs ]" << endl;
  }
// integer overflow
// remember to clear visited array
// take input as vector<string> while using grid
// don't assign after modifying


Measured memory_bytes: 256
n=int(input())
b=list(map(int,input().split()))
a=[0 for _ in range(n)]
for i in range(n):
  if i==0:
    a[i]=b[0]
  elif i==n-1:
    a[i]=b[n-2]
  else:
    a[i]=(min(b[i-1], b[i]))
print(sum(a))

Measured memory_bytes: 61944
#include<iostream>
using namespace std;
int main()
{
	int a,b,c,d,e,f;cin>>a>>b>>c>>d>>e>>f;
	a*=100;b*=100;
	double m=0;
	int all=a,in=0;
	double E=1e2*e/(100+e);
	for(int i=0;i*a<=f;i++)
	{
		for(int j=0;i*a+j*b<=f;j++)
		{
			if(i==0&&j==0)continue;
			for(int k=0;i*a+j*b+k*c<=f;k++)
			{
				for(int l=0;i*a+j*b+k*c+l*d<=f;l++)
				{
					double now=1e2*(k*c+l*d)/(i*a+j*b+k*c+l*d);
					if(m<now&&now<=E)
					{
						m=now;
						all=i*a+j*b+k*c+l*d;
						in=k*c+l*d;
					}
				}
			}
		}
	}
	cout<<all<<" "<<in<<endl;
}


Measured memory_bytes: 256
# -*- coding: utf-8 -*-
import numpy as np
N=int(input())
A=np.zeros((2,N))
X=np.zeros(N)

A[0]=list(map(int,input().split()))
A[1]=list(map(int,input().split()))



for k in range(N):
    j=0
    drop=0
    for i in range(N):
        drop+=A[j,i]
        if i==k:
            j+=1
            drop+=A[j,i]
    X[k]=drop
    
print(int(max(X)))



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

typedef long long int int64;
static const int64 mod = 998244353LL;
int64 inv[8003],fac[8003],invfac[8003];
int64 dp[203][8003];
int64 arr[3][16384];
int64 g[24];
int n,m;
int64 choice(int a,int b)
{
	if(a < b || b < 0) return 0;
	return fac[a] * invfac[b] % mod * invfac[a-b] % mod;
}
void fft(int64 *arr, int n)
{
	int j = 0;
	for(int i = 1;i < (1<<n);++i) {
		int k = (1<<(n-1));
		while((j&k)!=0) { j ^= k;k >>= 1; }
		j ^= k;
		if(i < j) std::swap(arr[i],arr[j]);
	}
	for(int i = 0;i < n;++i) {
		int step = (1<<i);
		for(int j = 0;j < (1<<n);j += (1<<(i+1))) {
			int64 w = 1;
			for(int k = 0;k < (1<<i);++k) {
				int64 v1 = arr[j+k], v2 = arr[j+k+step]*w%mod;
				arr[j+k] = (v1+v2)%mod;
				arr[j+k+step] = (v1-v2+mod)%mod;
				w = w * g[i+1] % mod;
			}
		}
	}
}
void ifft(int64 *arr, int n)
{
	fft(arr,n);
	int64 inv2 = 1;
	for(int k = 0;k < n;++k) inv2 = inv2 * inv[2] % mod;
	for(int i = 1;i < (1<<(n-1));++i) std::swap(arr[i],arr[(1<<n)-i]);
	for(int i = 0;i < (1<<n);++i) arr[i] = (arr[i] * inv2) % mod;
}
int main()
{
	scanf("%d%d",&n,&m);
	fac[0] = inv[1] = invfac[0] = invfac[1] = fac[1] = 1;
	for(int i = 2;i <= 8002;++i) {
		inv[i] = (mod - mod / i) * inv[mod % i] % mod;
		fac[i] = (fac[i-1] * i) % mod;
		invfac[i] = (invfac[i-1] * inv[i]) % mod;
	}
	g[23] = 31;
	for(int i = 22;i >= 0;--i) g[i] = (g[i+1]*g[i+1]) % mod;

	int64 *dp1 = arr[0], *dp2 = arr[1];
	dp1[0] = 1;
	for(int k = 1;k <= n;++k) {
		arr[2][k] = invfac[k+2];
	}
	fft(arr[2],14);
	for(int i = 1;i <= m;++i) {
		memcpy(dp2,dp1,sizeof(arr[0]));
		fft(dp2,14);
		for(int k = 0;k < 16384;++k) dp2[k] = (dp2[k] * arr[2][k]) % mod;
		ifft(dp2,14);
		for(int k = n+1;k < 16384;++k) dp2[k] = 0;
		for(int k = 0;k <= n;++k) dp2[k] = (dp2[k] * (k+1) % mod * (k+2) % mod + dp1[k] * (choice(k+1,2)+1)) % mod;
		std::swap(dp1,dp2);
	}
	/*
	dp[0][0] = 1;
	for(int i = 1;i <= m;++i) {
		for(int j = 0;j <= n;++j) {
			int64 val = 0;
			for(int k = 0;k < j;++k) {
				val += dp[i-1][k] * choice(j+2,k) % mod;
			}
			val += dp[i-1][j] * (choice(j+1,2)+1) % mod;
			dp[i][j] = val % mod;
		}
	}
	int64 ans = 0;
	for(int j = 0;j <= n;++j) {
		ans += dp[m][j] * choice(n,j) % mod;
	}
	*/
	int64 ans = 0;
	for(int j = 0;j <= n;++j) {
		ans += dp1[j] * fac[n] % mod * invfac[n-j] % mod;
	}
	ans %= mod;
	if(ans < 0) ans += mod;
	printf("%lld\n", ans);
}


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

typedef long long ll;

using namespace std;

#define rep(i,n) for(int i=0;i<(n);i++)
#define reps(i,l,n) for(int i=(l);i<(n);i++)

template<class T>
using vt = vector<T>;
template<class T>
using vvt = vector<vector<T>>;


int main(){
    int H,W;
    cin >> H >> W;
    string pic[H+2];
    reps(i,1,H+1) cin >> pic[i];
    pic[0] = ""; pic[H+1] = "";
    rep(i,W){
        pic[0] += "#";
        pic[H+1] += "#";
    }
    reps(i,0,H+2){
        string temp = "#" + pic[i] + "#";
        cout << temp << endl;
    }
    return 0;
}




Measured memory_bytes: 256
class UnionFind():
    # 作りたい要素数nで初期化
    # 使用するインスタンス変数の初期化
    def __init__(self, n):
        self.n = n
        # root[x]<0ならそのノードが根かつその値が木の要素数
        # rootノードでその木の要素数を記録する
        self.root = [-1]*(n+1)
        # 木をくっつける時にアンバランスにならないように調整する
        self.rnk = [0]*(n+1)

    # ノードxのrootノードを見つける
    def Find_Root(self, x):
        if(self.root[x] < 0):
            return x
        else:
            # ここで代入しておくことで、後の繰り返しを避ける
            self.root[x] = self.Find_Root(self.root[x])
            return self.root[x]
    # 木の併合、入力は併合したい各ノード
    def Unite(self, x, y):
        # 入力ノードのrootノードを見つける
        x = self.Find_Root(x)
        y = self.Find_Root(y)
        # すでに同じ木に属していた場合
        if(x == y):
            return
        # 違う木に属していた場合rnkを見てくっつける方を決める
        elif(self.rnk[x] > self.rnk[y]):
            self.root[x] += self.root[y]
            self.root[y] = x

        else:
            self.root[y] += self.root[x]
            self.root[x] = y
            # rnkが同じ（深さに差がない場合）は1増やす
            if(self.rnk[x] == self.rnk[y]):
                self.rnk[y] += 1
    # xとyが同じグループに属するか判断
    def isSameGroup(self, x, y):
        return self.Find_Root(x) == self.Find_Root(y)

    # ノードxが属する木のサイズを返す
    def Count(self, x):
        return -self.root[self.Find_Root(x)]

n, m, k = map(int, input().split())
friendUnion = UnionFind(n)
friend = [[] for i in range(n)]

for i in range(m):
    a, b = map(int, input().split())
    friendUnion.Unite(a - 1, b - 1)
    friend[a - 1].append(b - 1)
    friend[b - 1].append(a - 1)

block = [[] for i in range(n)]

for i in range(k):
    c, d = map(int, input().split()) 
    block[c - 1].append(d - 1)
    block[d - 1].append(c - 1)

ans = []
for i in range(n):
    tmp = friendUnion.Count(i) - 1 - len(friend[i]) 
    for j in block[i]:
        if friendUnion.isSameGroup(i, j):
            tmp -= 1
    ans.append(str(tmp))

print(' '.join(ans))



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

struct Node{
    int key;
    Node *right, *parent, *left;
};

Node *root;
Node *NIL;

void insert(int k){
    Node *y = NIL;
    Node *x = root; // 走査用
    Node *z;

    z = (Node *)malloc(sizeof(Node));
    z->key = k;
    z->left = NIL;
    z->right = NIL;

    while(x != NIL){
        y = x;
        if(x->key > z->key){
            x = x->left;
        }else{
            x = x->right;
        }
    }

    z->parent = y;
    if(y == NIL){
        root = z;
    }else if(y->key > z->key){
        y->left = z;
    }else{
        y->right = z;
    }
}

void inorder(Node *u){
    if(u == NIL)    return;
    inorder(u->left);
    printf(" %d", u->key);
    inorder(u->right);
}

void preorder(Node *u){
    if(u == NIL)    return;
    printf(" %d", u->key);
    preorder(u->left);
    preorder(u->right);
}

Node* find(Node *u, int x){
    while(u != NIL && u->key != x){
        if(u->key < x){
            u = u->right;
        }else{
            u = u->left;
        }
    }
    return u;
}

int main(){
    int n, i, x;
    string com;
    scanf("%d", &n);
    
    for(i = 0; i < n; i++){
        cin >> com;
        if(com == "insert"){
            scanf("%d", &x);
            insert(x);
        }else if(com == "print"){
            inorder(root);
            printf("\n");
            preorder(root);
            printf("\n");
        }else if(com == "find"){
            scanf("%d", &x);
            if(find(root, x) != NIL) printf("yes\n");
            else               printf("no\n");
        }
    }

    return 0;
}



Measured memory_bytes: 21928
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <string>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <iomanip>
#include <utility>
#include <tuple>
#include <functional>
#include <bitset>
#include <cassert>
#include <complex>
#include <time.h>
#define ll long long
#define double long double
#define itn int
#define endl '\n'
#define co(ans) cout<<ans<<endl;
#define COYE cout<<"YES"<<endl;
#define COYe cout<<"Yes"<<endl;
#define COye cout<<"yes"<<endl;
#define CONO cout<<"NO"<<endl;
#define CONo cout<<"No"<<endl;
#define COno cout<<"no"<<endl;
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define FFOR(i,a,b) for(int i=(a);i<=(b);++i)
#define REP(i,n)  FOR(i,0,n)
#define RREP(i,n)  FFOR(i,1,n)
#define ALL(V) ((V).begin(),(V).end())
#define SORT(V) sort((V).begin(),(V).end())
#define REVERSE(V) reverse((V).begin(),(V).end())
#define INF ((1LL<<62)-(1LL<<31))
#define EPS 1e-10
#define PI 3.141592653589793238
#define MOD 1000000007
#define MAX 5100000
template<class T>bool chmax(T &a,const T &b){if(a<b){a=b;return 1;}return 0;}
template<class T>bool chmin(T &a,const T &b){if(b<a){a=b;return 1;}return 0;}
const int vx[4]={0,1,0,-1},vy[4]={1,0,-1,0};
using namespace std;

int main(){
  ll A,B,C;
  cin>>A>>B>>C;
  
  if(A%2==0||B%2==0||C%2==0) cout<<0<<endl;
  else{
    ll mn=min({A,B,C});
    ll mx=max({A,B,C});
    ll md=A+B+C-mx-mn;
    cout<<mn*md<<endl;
  }
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

#define itr(a) begin(a), end(a)
#define pb push_back
#define x first
#define y second
#define endl '\n'

#define FAST cin.tie(0); cout.tie(0); ios_base::sync_with_stdio(0);

#ifndef __LOCAL
#define FILES(namein, nameout) freopen(namein, "r", stdin); freopen(nameout, "w", stdout); FAST;
#else
#define FILES(namein, nameout) FAST;
#endif //__LOCAL

using namespace std;
using namespace __gnu_pbds;
using python = void;

typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;
typedef unsigned short uss;
typedef pair<ll, ll> pll;
typedef tree<ll, null_type> ordered_set;

const ll M = 1e9+7;
const ll N = 228;
constexpr ll inf = 0x3f3f3f3f3f3f3f3f;

pll qs[N];
ll plca[N];
ll vs[N];
ll n, m;
ll up[N][N], tin[N], tout[N], timer = 0;
vector<ll> d[N];

ll adfs(ll v, ll sum = 0, ll p = -1){
	ll xs = 0;
	if(sum != 0) xs = 1;
	sum += vs[v];
	for(auto i : d[v]){
		if(i != p) xs += adfs(i, sum, v);
	}
	return xs;
}

ll get_active(ll mask){
	memset(vs, 0, sizeof(vs));
	bitset<N> aga;
	for(ll i = 0;i<m;i++){
		if(mask&(1LL<<i)){
			if(qs[i].x == plca[i]){
				ll v = qs[i].y;
				while(v != plca[i]) aga[v] = 1, v = up[v][0];
			}else if(qs[i].y == plca[i]){
				ll v = qs[i].x;
				while(v != plca[i]) aga[v] = 1, v = up[v][0];
			}else{
				ll v = qs[i].x;
				while(v != plca[i]) aga[v] = 1, v = up[v][0];
				v = qs[i].y;
				while(v != plca[i]) aga[v] = 1, v = up[v][0];
			}
		}
	}
	return aga.count();
}

void ldfs(ll v, ll p = 0){
	up[v][0] = p;
	for(ll L = 1;L<10;L++) if(up[v][L-1] && up[up[v][L-1]][L-1]) up[v][L] = up[up[v][L-1]][L-1];
	tin[v] = ++timer;
	for(auto i : d[v])
		if(i!=p)
			ldfs(i, v);
	tout[v] = ++timer;
}

bool upper(ll a, ll b){
	return (tin[a] <= tin[b] && tout[a] >= tout[b]);
}

ll lca(ll a, ll b){
	if(upper(a, b)) return a;
	if(upper(b, a)) return b;
	for(ll L = 9;L>=0;L--){
		if(up[a][L] != 0 && !upper(up[a][L], b)) a = up[a][L];
	}
	return up[a][0];
}

python solve(){
	FAST;
	cin >> n;
	for(ll a, b, i = 0;i<n-1;i++){
		cin >> a >> b;
		d[a].pb(b);
		d[b].pb(a);
	}
	ldfs(1);
	cin >> m;
	for(ll i = 0;i<m;i++){
		cin >> qs[i].x >> qs[i].y;
		plca[i] = lca(qs[i].x, qs[i].y);
	}
	ll res = (1LL<<(n-1));
	for(ll mask = 1;mask<(1LL<<m);mask++){
		ll val = (1LL<<(n-1-get_active(mask)));
		if(__builtin_popcountll(mask)&1) res-=val;
		else res += val;
	}
	cout << res << '\x0a';
}

signed main(){
	FAST;
	ll q = 1;
	//cin >> q;
	while(q--){
		solve();
	}
}

Measured memory_bytes: 512
package main

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

func main() {
	scanner := Scanner()
	n := ReadInt(scanner)

	const pay = 1000
	if n%pay == 0 {
		fmt.Println(0)
	} else {
		fmt.Println(pay - (n % pay))
	}

}

func Scanner() *bufio.Scanner {
	scanner := bufio.NewScanner(os.Stdin)
	scanner.Split(bufio.ScanWords)
	return scanner
}

func ReadInt(scanner *bufio.Scanner) int {
	var t string

	if scanner.Scan() {
		t = scanner.Text()
	}

	n, err := strconv.Atoi(t)
	if err != nil {
		log.Fatal(err)
	}

	return n
}


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

#define REP(i, n) for(int i = 0; i < (n); i++)
#define ALL(a) (a).begin(),(a).end()
#define SORT(a) sort((a).begin(),(a).end())
#define RSORT(a) sort((a).rbegin(),(a).rend())
#define ll long long
#define pb(a) push_back(a)

#define PRINTV(v) {for(ll deB=0; deB<(v).size(); deB++){cout << (v)[deB] << " ";}cout << endl;}

int main(){
	
	
	ll N, K;
	cin >> N >> K;
	vector<ll> A(N);
	REP(i,N) cin >> A[i];
	REP(i,N) A[i]--;

	vector<ll> memo(N, -1);
	memo[0] = 0;

	ll p=0;
	for(ll i=1; i<=K; i++){
		if(memo[A[p]] == -1){
			memo[A[p]] = i;
		}else{
			ll loop = i - memo[A[p]];
			if(i+loop < K){
				i += loop*((K-i)/loop);
			}
		}
		p = A[p];
	}
	cout << (p+1) << endl;
	
	return 0;

abnormal:
	cout << "No" << endl;
	return 0;
}

Measured memory_bytes: 6400