akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#pragma GCC optimize("Ofast")
#pragma GCC target("avx,avx2,fma")
using namespace std;
#define testing 0
#define FOR(i,s,e) for(ll i = s; i <= (ll)e; ++i)
#define DEC(i,s,e) for(ll i = s; i >= (ll)e; --i)
#define IAMSPEED ios_base::sync_with_stdio(false); cin.tie(0);
#define db(x) cerr << #x << "=" << x << "\n"
#define db2(x, y) cerr << #x << "=" << x << " , " << #y << "=" << y << "\n"
#define db3(a,b,c) cerr<<#a<<"="<<a<<","<<#b<<"="<<b<<","<<#c<<"="<<c<<"\n"
#define dbv(v) cerr << #v << ":"; for (auto ite : v) cerr << ite << ' '; cerr <<"\n"
#define dbvp(v) cerr << #v << ":"; for (auto ite : v) cerr << "{"  << ite.f << ',' << ite.s << "} "; cerr << "\n"
#define dba(a,ss,ee) cerr << #a << ":"; FOR(ite,ss,ee) cerr << a[ite] << ' '; cerr << "\n"
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
#define ll long long 
#define pb push_back
#define all(x) (x).begin(), (x).end()
#define f first
#define s second
#define reach cerr << "LINE: " << __LINE__ << "\n";
typedef pair <int, int> pi;
typedef tuple<int,int,int> ti3;
string cts(char x) {string t(1,x); return t;}
ll rand(ll a, ll b) { return a + rng() % (b-a+1); }
const int MOD = 1e9 + 7;
const int inf = (int)1e9 + 500;
const long long oo = (ll)1e18 + 500;
template <typename T> void chmax(T& a, T b) { a = max(a, b); }
template <typename T> void chmin(T& a, T b) { a = min(a, b); }
const int MAXN = 2e5+5;
#if !testing
#define cerr if(0)cout
#endif

struct node {
	ll v=0;
	node *l = 0, *r = 0;
	node (ll s, ll e) {
		v = 0;
		l=r=0;
	}
	void update(ll s, ll e, ll x, ll nval) {
		ll m = floor(((double)s+e)/2.0);
		if(s==e) {
			v+=nval;
			return;
		}
		if (x>m) {
			if (!r) r = new node(m+1,e);
			r->update(m+1,e,x,nval);
		} else {
			if (!l) l = new node(s,m);
			l->update(s,m,x,nval);
			
		}
		v=(l?l->v:0)+(r?r->v:0);
	}
	ll query(ll s, ll e, ll qs, ll qe) {
		ll m = floor(((double)s+e)/2.0);
		if (s==qs&&qe==e) return v;
		if (qs>m) return r?r->query(m+1,e,qs,qe):0;
		else if (qe<=m) return l?l->query(s,m,qs,qe):0;
		else return (l?l->query(s,m,qs,m):0) + (r?r->query(m+1,e,m+1,qe):0);
	}
		
} *seg;

ll A[MAXN],sum[MAXN];

int32_t main() 
{
	IAMSPEED
	ll n,k; cin >> n >> k;
	reach
	seg = new node((ll)-1e15,(ll)1e15);
	reach
	ll mnp=((ll)-1e15), mxp = ((ll)1e15);
	FOR(i,1,n) cin >> A[i];
	FOR(i,1,n)sum[i]=sum[i-1]+A[i]-k;
	reach
	seg->update(mnp,mxp,0,1);
	reach
	ll ans = 0;
	FOR(i,1,n) {
		db(i);
		ll now = sum[i];
		chmin(now,mxp);
		chmax(now,mnp);
		ans+=seg->query(mnp,mxp,mnp,now);
		db(now);
		seg->update(mnp,mxp,now,1);
		db(ans);
	}
	cout << ans;
}

Measured memory_bytes: 189952
let n = Int(readLine()!)!
if n > 888 {
  print(999)
} else if n > 777 {
  print(888)
} else if n > 666 {
  print(777)
} else if n > 555 {
  print(666)
} else if n > 444 {
  print(555)
} else if n > 333 {
  print(444)
} else if n > 222 {
  print(333)
} else if n > 111 {
  print(222)
} else {
  print(111)
}

Measured memory_bytes: 7740
#include<bits/stdc++.h>
#define int long long
#define for0(i, n) for(int i = 0; i < (n); i++)
using namespace std;
int l, n, ans; string s;
signed main() {
	cin >> l >> n >> s; ans = l;
	l = 0; for0(i, ans - 1)if (s[i] == 'o' && s[i + 1] == 'o')l++;
	for0(i, n) { ans += l * 3; l *= 2; }printf("%lld\n", ans);
}


Measured memory_bytes: 3340
n = int(input())
for _ in range(n):
    x1,y1,x2,y2,x3,y3 = map(float, input().split())
    gx = (x1+x2+x3)/3
    gy = (y1+y2+y3)/3
    G=( y2*x1-y1*x2 +y3*x2-y2*x3 +y1*x3-y3*x1 )
    Xc= ((x1*x1+y1*y1)*(y2-y3)+(x2*x2+y2*y2)*(y3-y1)+(x3*x3+y3*y3)*(y1-y2))/(2*G)
    Yc=-((x1*x1+y1*y1)*(x2-x3)+(x2*x2+y2*y2)*(x3-x1)+(x3*x3+y3*y3)*(x1-x2))/(2*G)
    r = ( (x1 - Xc) * (x1 - Xc) + (y1 - Yc) * (y1 - Yc) )**0.5
    print("%.3f %.3f %.3f"%(Xc,Yc,r))



Measured memory_bytes: 5660
#include <bits/stdc++.h>
#define long long long
#define up(i,a,b) for (int i=a; i<=b; i++)
#define down(i,a,b) for (int i=a; i>=b; i--)
#define endl '\n'
#define X first
#define Y second
#define II pair<int, int>
#define III pair<int, pair<int, int> >
#define debug(X) cerr<< #X << " = " <<X << endl
#define debug2(X,Y) cerr<< #X << " = " <<X << ","<<#Y<<" = "<<Y<<endl
#define show(X,a,b) {cerr << #X << " = "; up(__,a,b) cerr << X[__] << ' '; cerr << endl;}
#define gc getchar
#define pc putchar
using namespace std;

inline void read(int &x)
{
    register int c = gc();
    x = 0;
    int neg = 0;
    for (;((c<48 || c>57) && c != '-') ;c = gc());
    if(c=='-') {neg=1;c=gc();}
    for(;c>47 && c<58;c = gc()) {x = (x<<1) + (x<<3) + c - 48;}
    if(neg) x=-x;
}
inline void writeln(int x){

         char buffor[21];
         register int i=0;
         int neg=0; if (x<0) {neg=1; x= -x;}
         do{
               buffor[i++]=(x%10)+'0';
               x/=10;
            } while(x);
           i--;
           if (neg) pc('-');
           while(i>=0) pc(buffor[i--]);
           pc('\n');
       }
int x,y;
void input()
{
    cin>>x>>y;
}
void solve()
{
    if (x== y) cout<<0;
    else
    if (abs(x)<= abs(y))
	{
        if (x>=0 and y>=0) cout<<y-x;
        else if (x<0 and y<0) cout<<abs(y)- abs(x)+ 2;
        else if (x>=0 and y<0) cout<<abs(y)- abs(x)+ 1;
        else if (x<0 and y>=0) cout<<abs(y)- abs(x)+ 1;
	}
	else
	{
		if (x>=0 and y>=0)
		{
			if (y!=0) cout<<x-y+2; else cout<<x-y+1;
		}
        else if (x<0 and y<0) cout<<abs(x)- abs(y);
        else if (x>=0 and y<0) cout<<abs(x)- abs(y)+ 1;
        else if (x<0 and y>=0)
		{
			if (y!=0) cout<<abs(x)- abs(y)+1;
			else cout<<abs(x)- abs(y);
		}
	}
}

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);// don't use when interactive

    #ifdef I_Love_Pork
    #define TASK "tmp"
    freopen(TASK".inp","r",stdin);
    freopen(TASK".out","w",stdout);
	  #endif

    input();
    solve();

    return 0;
}


Measured memory_bytes: 256
#include<stdio.h>
int main(){
	int a;
	while(scanf("%d",&a),a){
		int ret1=0;
		int ret2=0;
		for(int i=0;i<a;i++){
			int b,c,d;
			scanf("%d%d%d",&b,&c,&d);
			if(c+d>ret1){
				ret1=c+d;
				ret2=b;
			}
		}
		printf("%d %d\n",ret2,ret1);
	}
}

Measured memory_bytes: 768
N = int(input())

h = list(map(int,input().split()))
h.append(0)

ans = 0

for loop in range(100):
        
        start = 102

        for flo in range(N + 1):

            if (h[flo] > loop and start > 101):
                start = flo

            elif (h[flo] <= loop and start < flo):
                ans += 1
                start = 102

print (ans)


Measured memory_bytes: 3060
class RMaxQ:
    
    __slots__ = ["n", "data"]
    
    def __init__(self, li):
        self.n = len(li)
        self.data = [-float("inf")]*self.n + li
        for i in range(self.n - 1, 0, -1):
            self.data[i] = max(self.data[2*i], self.data[2*i+1])
    
    def get(self, i):
        return self.data[i+self.n]
    
    def update(self, i, a):
        i += self.n
        self.data[i] = a
        while i > 1:
            i //= 2
            self.data[i] = max(self.data[2*i], self.data[2*i+1])
    
    def add(self, i, a):
        i += self.n
        self.data[i] += a
        while i > 1:
            i //= 2
            self.data[i] = max(self.data[2*i], self.data[2*i+1])
    
    def fold(self, l, r):
        l += self.n
        r += self.n
        res = -float("inf")
        while l < r:
            if l % 2:
                res = max(self.data[l], res)
                l += 1
            if r % 2:
                r -= 1
                res = max(res, self.data[r])
            l //= 2
            r //= 2
        return res
    
    def max_right(self, l, r, check):
        l += self.n
        r += self.n
        left_li = []
        right_li = []
        while l < r:
            if l % 2:
                left_li.append(l)
                l += 1
            if r % 2:
                r -= 1
                right_li.append(r)
            l //= 2
            r //= 2
        temp = -float("inf")
        for idx in (left_li + right_li[::-1]):
            if not check(max(temp, self.data[idx])):
                temp = max(temp, self.data[idx])
            else:
                break
        else:
            return -1
        while idx < self.n:
            if check(max(temp, self.data[2*idx])):
                idx = 2*idx
            else:
                temp = max(temp, self.data[2*idx])
                idx = 2*idx+1
        return idx - self.n
    
    def min_left(self, l, r, check):
        l += self.n
        r += self.n
        left_li = []
        right_li = []
        while l < r:
            if l % 2:
                left_li.append(l)
                l += 1
            if r % 2:
                r -= 1
                right_li.append(r)
            l //= 2
            r //= 2
        temp = -float("inf")
        for idx in (right_li + left_li[::-1]):
            if not check(max(self.data[idx], temp)):
                temp = max(self.data[idx], temp)
            else:
                break
        else:
            return -1
        while idx < self.n:
            if check(max(self.data[2*idx+1], temp)):
                idx = 2*idx+1
            else:
                temp = max(temp, self.data[2*idx+1], temp)
                idx = 2*idx
        return idx - self.n

import sys
input = sys.stdin.readline
n, q = map(int, input().split())
A = list(map(int, input().split()))
seg = RMaxQ(A)
for _ in range(q):
    t, x, v = map(int, input().split())
    x -= 1
    if t == 1:
        seg.update(x, v)
    elif t == 2:
        print(seg.fold(x, v))
    else:
        ans = seg.max_right(x, n, lambda x: x>=v)
        if ans == -1:
            print(n+1)
        else:
            print(ans+1)

Measured memory_bytes: 96096
my $p = <STDIN>;
chomp($p);
my ($n, $x) = split / /, $p;
my $q = <STDIN>;
chomp($q);
my @l = split / /, $q;

my ($s,$d) = (0,1);
for (@l){
    $s+=$_;
    if($s <= $x){$d+=1;}
    }
print $d."\n";

1;


Measured memory_bytes: 512
package main

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

const (
	initialBufSize = 1e4
	maxBufSize     = 1e6 + 7
)

var buf []byte = make([]byte, maxBufSize)
var sc = bufio.NewScanner(os.Stdin)

func init() {
	sc.Split(bufio.ScanWords)
	sc.Buffer(buf, maxBufSize)
}

func main() {
	T := nextLine()
	fmt.Println(strings.ReplaceAll(T, "?", "D"))
}

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

func nextInt() int {
	sc.Scan()
	i, e := strconv.Atoi(sc.Text())
	if e != nil {
		panic(e)
	}
	return i
}

func abs(a int) int {
	if a > 0 {
		return a
	} else {
		return -a
	}
}

func pow(p, q int) int {
	res := p
	if q == 0 {
		return 1
	}
	for i := 0; i < q-1; i++ {
		res *= p
	}
	return res
}

func MinOf(vars ...int) int {
	min := vars[0]
	for _, i := range vars {
		if min > i {
			min = i
		}
	}
	return min
}

func MaxOf(vars ...int) int {
	max := vars[0]
	for _, i := range vars {
		if max < i {
			max = i
		}
	}
	return max
}

func gcdof2numbers(a int, b int) int {
	if b == 0 {
		return a
	}
	return gcdof2numbers(b, a%b)
}

func lcmof2numbers(a int, b int) int {
	return a / gcdof2numbers(a, b) * b
}

// マイナスの場合は考慮していない
func fuctorial(a int) int {
	if a == 1 || a == 0 {
		return 1
	} else {
		return fuctorial(a-1) * a
	}
}

func NextPermutation(x sort.Interface) bool {
	n := x.Len() - 1
	if n < 1 {
		return false
	}
	j := n - 1
	for ; !x.Less(j, j+1); j-- {
		if j == 0 {
			return false
		}
	}
	l := n
	for !x.Less(j, l) {
		l--
	}
	x.Swap(j, l)
	for k, l := j+1, n; k < l; {
		x.Swap(k, l)
		k++
		l--
	}
	return true
}

// 素因数分解したmapを返す
func primeFuctorize(n int) map[int]int {
	pf := map[int]int{}
	for i := 2; i*i <= n; i++ {
		for n%i == 0 {
			pf[i]++
			n /= i
		}
	}
	if n != 1 {
		pf[n]++
	}
	return pf
}


Measured memory_bytes: 2796
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <set>
#include <cmath>
#include <stdio.h>
#include <list>
#include <numeric>
#include <stack>
#include <queue>
#include <tuple>
#include <bitset>
#include <map>
#include <math.h>
//　ceil(a/b)   (a + (b - 1))/ b
using namespace std;
#define rep(i,n) for(int i = 0; i < (n); i++)
typedef long long ll;
typedef pair<int,int> P;
const int inf=1000000007;
const ll mod=1000000007;
const double PI=3.14159265358979323846;
int dx[] = {1,-1,0,0};
int dy[] = {0,0,1,-1};

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

int cans(bool f){
  if(f) cout << "Yes" << endl;
  else cout << "No" << endl;
  return 0;
}





int main(){
  string s;
  bool f = false;
  cin >> s;
  if(s[2] == s[3] && s[4] == s[5]) f = true;
  cans(f);
  return 0;
}



Measured memory_bytes: 256
#include <bits/stdc++.h>
#define fi first
#define se second
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define drep(i,n) for(int i = (n)-1; i >= 0; --i)
#define srep(i,s,t) for (int i = s; i < t; ++i)
#define rng(a) a.begin(),a.end()
#define sz(x) (int)(x).size()
#define uni(x) x.erase(unique(rng(x)),x.end())
#define show(x) cout<<#x<<" = "<<x<<endl;
#define PQ(T) priority_queue<T,v(T),greater<T> >
#define newline puts("")
#define v(T) vector<T>
#define vv(T) v(v(T))
#define chmin(x,y) x=min(x,y)
#define chmax(x,y) x=max(x,y)
#define EPS (1e-10)
#define equals(a, b) (fabs((a)-(b)) < EPS)
using namespace std;
typedef long long int ll;
typedef pair<int,int> P;
typedef set<int> S;
typedef queue<int> Q;
typedef queue<P> QP;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<P> vp;
const ll LINF = 1001002003004005006ll;
const int INF = 1001001001;
const int MOD = 1000000007;
  
int main() {
  int A,B;
  char op;
  cin >> A >> op >> B;
  if(op=='+') {
    cout << A+B << endl;
  } else {
    cout << A-B << endl;
  }
  return 0;
}

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

int main() {
    int w, h, n;
    cin >> w >> h >> n;
    int x[n], y[n], a[n];
    for(int i = 0; i < n; i++){
        cin >> x[i] >> y[i] >> a[i];
    }

    int minx = 0, miny = 0;
    int maxx = w, maxy = h;
    for(int i = 0; i < n; i++){
        if(a[i] == 1){
            minx = max(minx, x[i]);
        }
        if(a[i] == 2){
            maxx = min(maxx, x[i]);
        }
        if(a[i] == 3){
            miny = max(miny, y[i]);
        }
        if(a[i] == 4){
            maxy = min(maxy, y[i]);
        }
    }
    // cout << maxx << minx << maxy << miny << endl;
    int ans = (maxx - minx) * (maxy - miny) ;
    if(ans < 0 || maxx - minx < 0 || maxy - miny < 0) cout << 0 << endl;
    else cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define repi(i,a,b) for(int i=(int)(a);i<(int)(b);++i)
#define rrepi(i,a,b) for(int i=((int)(b)-1);i>=(a);--i)
#define rep(i,n) repi(i,0,n)
#define rrep(i,n) rrepi(i,0,n)
#define ALL(x) (x).begin(),(x).end()
#define SZ(x) ((int)(x).size())
#define ZERO(x) memset(x,0,sizeof(x))
#define MINUS(x) memset(x,-1,sizeof(x))
#define UNIQUE(x) (x).erase(unique(ALL(x)), (x).end())
#define TOUPPER(x) transform(ALL(x), (x).begin(), ::toupper)
#define TOLOWER(x) transform(ALL(x), (x).begin(), ::tolower)
#define debug(var)  do{std::cout << #var << " : "; view(var);}while(0)
#define fi first
#define se second
using namespace std;
using ll = long long;
using P = pair<int,int>;
template<typename T> void view(const std::vector<T>& v){for(const auto& e : v){ std::cout << e << " "; } std::cout << std::endl;}
template<typename T> void view(const std::vector<std::vector<T> >& vv){for(const auto& v : vv){ view(v); } }
template<typename T> void view(T e){std::cout << e << std::endl;}
template<typename T> void viewarr(T arr[], int n) { for(int i = 0; i < n; ++i) std::cout << arr[i] << " "; std::cout << std::endl; }
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; }
ll qp(ll a,ll b){ll ans=1;do{if(b&1)ans=1ll*ans*a;a=1ll*a*a;}while(b>>=1);return ans;}
ll qp(ll a,ll b,ll mo){ll ans=1;do{if(b&1)ans=1ll*ans*a%mo;a=1ll*a*a%mo;}while(b>>=1);return ans;}
int gcd(int a,int b){return b?gcd(b,a%b):a;}
int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};
const int INF = 1e9;
const ll INFL = 1e18;
const int MOD = 1e9 + 7;
const int MAX_N = 1e5;

int main() {
    int N; cin >> N;
    int c = N% 10;
    if(c == 2 || c == 4 || c == 5 || c == 7 || c == 9) {
        cout << "hon" << endl;
    } else if(c == 3) {
        cout << "bon" << endl;
    } else {
        cout << "pon" << endl;
    }
    return 0;
}


Measured memory_bytes: 3636
#include <cstdio>


int main() {
  int c = getchar();
  while (c <= 32) c = getchar();
  int ans = 0;
  int cs = 0;
  while (c > 32) {
    if (c == 'T') {
      if (cs > 0) {
        --cs;
      } else {
        ++ans;
      }
    } else {
      cs++;
    }
    c = getchar();
  }
  ans += cs;
  printf("%d\n", ans);
}

Measured memory_bytes: 128
N = int(input())


prime = [2,3,5]

def isPrime(n):
    if n == 1:
        return False

    if n == 2 or n==3 or n==5:
        return True

    for div in prime:
        if n % div == 0:
            return False
    
    prime.append(n)
    return True

for x in range(1, N+1):
    isPrime(x)


#%%
def factoring(n):

    for div in prime:
        if div > n:
            break

        while n % div == 0:
            part[div] += 1
            n /= div

#%%
part = {x:0 for x in prime}
for x in range(1, N+1):
    factoring(x)

use = {3:0, 5:0, 15:0, 25:0, 75:0}
for x in part:
    if part[x] >= 2:
        use[3] += 1
    if part[x] >= 4:
        use[5] += 1
    if part[x] >= 14:
        use[15] += 1
    if part[x] >= 24:
        use[25] += 1
    if part[x] >= 74:
        use[75] += 1

ans = 0
# 75 = 75 * 1
if 75 in use:
    ans += use[75]
# 75 = 25 * 3
if 25 in use:
    ans += use[25] * (use[3] - 1)
# 75 = 15 * 5
if 15 in use:
    ans += use[15] * (use[5] - 1)
# 75 = 5 * 5 * 3
if 5 in use:
    ans += use[5] * (use[5] - 1) / 2 * (use[3] - 2)

print(int(ans))


Measured memory_bytes: 3064
#include<iostream>
#include<vector>
using namespace std;
#define rep(i,n) for(int i=0;i<(n);++i)
using ll = long long;
using P = pair<ll, ll>;
#include<algorithm>
#include<math.h>
#include<map>
#include<queue>
#include<set>
const int INF = 1e9;
int main() {
	int n, m;
	cin >> n >> m;
	//vector<int>a(n);
	vector<P>b(m);

	rep(i, n) {
		ll a;
		cin >> a;
		b.push_back(make_pair(a, 1));
	}
	
	rep(i, m) {
		ll B, C;
		cin >> B >> C;
		b.push_back(make_pair(C, B));
	}
	sort(b.rbegin(), b.rend());
	int k = 0;
	ll ans(0);
	for (auto p : b) {
		if (k + p.second <= n) {
			ans += p.first * p.second;
			k += p.second;
		}
		else {
			ans += p.first * (n - k);
			break;
		}
	}
	cout << ans;
	return 0;
}



Measured memory_bytes: 9400
#include <bits/stdc++.h>
#ifdef DEBUG
  #include "debug.hpp"
#else
  #define DUMP(var)
#endif

using namespace std;
template< class T1, class T2 > inline istream &
operator>>( istream & fin, pair< T1, T2 > & pr )
{ fin >> pr.first >> pr.second; return fin; }
template< class T0, class T1, class T2 > inline istream &
operator>>( istream & fin, tuple< T0, T1, T2 > & t )
{ fin >> get<0>(t) >> get<1>(t) >> get<2>(t); return fin; }
template< class T > inline istream &
operator>>( istream & fin, vector< T > & a ) {
for(auto & u: a) fin >> u; return fin; }
template<class T, size_t n> inline istream &
operator>>( istream & fin, array<T, n> & a ) {
for(auto & u: a) fin >> u; return fin; }
template<class FwdIter> inline auto
dump(FwdIter first, FwdIter last, const char * dlm = " ") -> void {
using value_type = typename iterator_traits<FwdIter>::value_type;
copy(first, last, ostream_iterator<value_type>(cout, dlm)); }
template<typename T> vector<T> & operator--(vector<T> & a)
{ for(auto & i: a) --i; return a; }
/* @@@ ----------------------------------- */


int main(const int /*argc*/, char ** /*argv*/) {
  ios_base::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr);

  size_t n;
  cin >> n;
  vector<vector<size_t>> a(n, vector<size_t>(n - 1));
  for (auto & r: a) {
    cin >> r;
    --r;
  }

  vector<size_t> pos(n);
  vector<size_t> next;
  vector<bool> tag(n, false);
  for (size_t i = 0; i < n; ++i) {
    if (tag[i]) { continue; }
    const size_t j = a[i][pos[i]];
    if (a[j][pos[j]] == i) {
      tag[i] = tag[j] = true;
      next.push_back(i);
      next.push_back(j);
    }
  }

  size_t out = 0;
  for (size_t done = 0; done < n; ++out) {
    if (next.empty()) {
      cout << -1;
      return 0;
    }

    for (const auto i: next) {
      ++pos[i];
      tag[i] = false;
    }

    vector<size_t> buf;
    for (const auto i: next) {
      if (tag[i]) { continue; }
      if (pos[i] == n - 1) {
        ++done;
      } else {
        const size_t j = a[i][pos[i]];
        if (a[j][pos[j]] == i) {
          tag[i] = tag[j] = true;
          buf.push_back(i);
          buf.push_back(j);
        }
      }
    }

    next = std::move(buf);
  }

  cout << out;

  return EXIT_SUCCESS;
}


Measured memory_bytes: 8192
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<ll> vec;
typedef vector<vec> mat;
typedef pair<ll,ll> pll;
const ll mod=1e9+7;
//const ll mod=998244353;
const ll inf=5e18;

int main() {
  ll big=1e9;
  ll n,k;
  cin >> n >> k;
  vec a(n+1);
  for(ll i=1;i<=n;i++) {
    cin >> a[i];
    a[i]+=a[i-1];
  }
  for(ll i=0;i<=n;i++) {
    a[i]=(a[i]-i+big*k)%k;
  }
  map<ll,ll> b;
  ll ans=0;
  for(ll i=0;i<=n;i++) {
    if(i>=k) {
      b[a[i-k]]--;
    }
    ans+=b[a[i]];
    b[a[i]]++;
  }
  cout << ans << endl;
}

Measured memory_bytes: 14336
import java.util.*;
public class Main{
public static void main(String[] args){
Scanner sc=new Scanner(System.in);
int i=1;
int n=sc.nextInt();
long T=sc.nextLong();
long[] t=new long[n];
long rtn=T;
t[0]=sc.nextLong();
for(i=1;i<n;i++){
t[i]=sc.nextLong();
rtn+=Math.min(T,t[i]-t[i-1]);
}
System.out.println(rtn);
}
}

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

int main() {
  int N, i, l, r, sum = 0;
  cin >> N;
  
  for(i = 0; i < N; i++)
  {
    cin >> l >> r;
    sum += r - l + 1;
  }
  cout << sum << endl;
}


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

int main() {
	int a, b, c, d, p;
	cin >> a >> b >> c >> d >> p;
	int X,Y;
	X = a * p;
	if (p <= c) {
		Y = b;
	}
	else {
		Y = b + d*(p-c);
	}
	cout << std::min(X, Y) << std::endl;
}


Measured memory_bytes: 3088
#include <iostream>
using namespace std;
long long n, m, ans=1, cnt, M=1e9+7, C[100050][35]={1};
int main() {
	int i, j, t;
	cin>>n>>m;
	for(i=1; i<=n+30; i++) {
		C[i][0] = 1;
		for(j=1; j<=min(i,30); j++) C[i][j] = (C[i-1][j-1] + C[i-1][j]) % M;
	}
	t = m;
	for(i=2; i*i<=m; i++) {
		cnt = 0;
		while(t%i==0) cnt++, t /= i;
		if(cnt>0) ans = (ans * C[cnt+n-1][cnt]) % M;
	}
	if(t>1) ans = (ans * n) % M;
	cout<<ans;
	return 0;
}

Measured memory_bytes: 27648
#include <bits/stdc++.h>
#define ll long long
#define mod 1000000007
#define inf 10000000000000007
#define eps 1e-13
#define PI 3.14159265359
#define sp printf(" ")
#define vi vector<int>
#define vl vector<long long>
#define vc vector<char>
#define vs vector<string>
#define pii pair<int, int>
#define pll pair<long long, long long>
#define pcc pair<char, char>
#define mp make_pair
#define FF first
#define SS second
#define pb(x) push_back(x)
#define sd(x) scanf("%d", &(x))
#define pd(x) printf("%d", (x))
#define pdn(x) printf("%d\n", (x))
#define sld(x) scanf("%ld", &(x))
#define pld(x) printf("%ld", (x))
#define pldn(x) printf("%ld\n", (x))
#define slf(x) scanf("%lf", &(x))
#define plf(x) printf("%.9lf", (x))
#define plfn(x) printf("%.9lf\n", (x))
#define sch(x) scanf("%c", &(x))
#define pch(x) printf("%c", (x))
#define pchn(x) printf("%c\n", (x))
#define gtl(x) getline(cin, (x))
#define flsh fflush(stdout)
#define ios ios::sync_with_stdio(false); cin.tie(0)
#define endl '\n'
using namespace std;
ll x[100004],y[100004];
int main()
{
    int n,m;
    cin>>n>>m;
    for(int i=1;i<=n;i++)cin>>x[i];
    for(int i=1;i<=m;i++)cin>>y[i];
    sort(x+1,x+n+1);
    sort(y+1,y+m+1);
    ll x1=0,y1=0;
    for(int i=1;i<=n;i++)
    {
        ll h=n-2*i+1;
        ll r=h*x[i];
        r=r%mod;
        x1+=r+mod;
        x1%=mod;

    }
    for(int i=1;i<=m;i++)
    {
        ll h=m-2*i+1;
        ll r=h*y[i];
        r=r%mod;
        y1+=r+mod;y1%=mod;
    }
    x1=x1*y1;
    x1=x1%mod;
    cout<<x1<<endl;

}




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

vector<int> parent(100000);
vector<int> sizes(100000);

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

bool unite(int x, int y){
  x = find(x);
  y = find(y);
  if (x == y) return false;
  if (sizes[x] > sizes[y]) swap(x, y);
  sizes[x] += sizes[y];
  parent[y] = x;
  return true;
}

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

int size(int x) { return sizes[find(x)]; }

int main(){
  int n, m;
  cin >> n >> m;
  rep(i, n) parent[i] = i;
  rep(i, n) sizes[i] = 1;
  int a, b;
  rep(i, m){
    cin >> a >> b;
    unite(a - 1, b - 1);
  }

  vector<bool> d(n, false);
  rep(i, n){
    int root = find(i);
    d[root] = true;
  }
  int ans = 0;
  rep(i, n){
    if (d[i] == true) ans++;
  }
  cout << ans - 1 << endl;
  return 0;
}

Measured memory_bytes: 3808
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cctype>
#include <cmath>
#include <string>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <algorithm>
#include <utility>
#include <deque>
#include <stack>
#include <bitset>
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef pair<int,ll> pil;
typedef pair<ll,int> pli;
#define rep(i,n) for (int i=0;i<n;++i)
#define REP(i,n) for (int i=1;i<=n;++i)
#define all(x) x.begin(),x.end()
#define mp make_pair
#define pb push_back
#define pf push_front
#define F first
#define S second
#define read(x) scanf("%d",&x)
int n,m;
int c[45];
vector<int> E[45];
int ans=1e9;
inline void dfs(int v,ll seen,int cost){
	ll nseen=seen;int ncost=cost;
	if (!(nseen&(1ll<<v))){
		nseen|=1ll<<v;
		ncost+=c[v];
	}
	for (int i=0;i<E[v].size();++i){
		int u=E[v][i];
		if (!(nseen&(1ll<<u))){
			ncost+=c[u];
			nseen|=1ll<<u;
		}
	}
	if (ncost>=ans) return;
	if (v==n){
		ans=ncost;return;
	}
	for (int i=0;i<E[v].size();++i){
		int u=E[v][i];
		if (!(seen&(1ll<<u))) dfs(u,nseen,ncost);
	}
	
}
int main(){
	ios::sync_with_stdio(false);
	cin>>n>>m;
	for (int i=1;i<=n;++i) cin>>c[i];
	for (int i=1;i<=m;++i){
		int x,y;
		cin>>x>>y;
		E[x].pb(y);E[y].pb(x);
	}
	dfs(1,0,0);
	cout<<ans<<endl;
	return 0;
}


Measured memory_bytes: 3236
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
using vl = vector<ll>; using vvl = vector<vl>;
#define FOR(i,a,b) for(ll i=a;i<b;i++)
#define rep(i,n) FOR(i,0,n)
const ll INF = 9223372036854775807;

int main() {
  int n;cin >> n;
  if(n%1000 == 0) cout << 0 << endl;
  else cout << 1000 - n%1000 << endl;
}

Measured memory_bytes: 3636
n=int(input())
l = list(map(int,input().split()))

l.sort(reverse=True)
c=0

for x in range(0,n-2):
    max1=l[x]
    for y in range(x+1,n-1):
        max2=l[y]
        for z in range(y+1,n):
            max3=l[z]

            if(max1<max2+max3 and max1!=max2 and max2!=max3):
                c+=1

print(c)





Measured memory_bytes: 9120
#include <bits/stdc++.h>
#define REP(i,s,e) for(int i=(s); i<(e);i++)
#define rep(i,n) REP(i,0,n)
#define rep1(i,n) REP(i,1,n)
#define repe(i,n) for(auto &&i:n)
#define all(v) (v).begin(),(v).end()
#define decimal fixed<<setprecision(20)
#define fastcin() cin.tie(0);ios::sync_with_stdio(false)
using namespace std;
using LL = long long;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
const int INF = 1e9;
const LL LLINF = 1e16;

using Graph = vector<vector<int>>;

vector<int> tsort(Graph &G){
    vector<int> tsorted;
    vector<int> used(G.size(), 0);
    bool f = false;
    function<void(int)> dfs = [&](int u){
        if(used[u] > 0){
            if(used[u] == 1) f = true;
            return;
        }
        used[u] = 1;
        for(auto &e : G[u]) dfs(e);
        used[u] = 2;
        tsorted.push_back(u);
    };
    rep(i, G.size()) dfs(i);
    if(f){
        // 閉路が存在
        return vector<int>();
    }
    reverse(all(tsorted));
    return tsorted;
}

int main(){
    int n;
    cin >> n;
    Graph G(n*n);
    rep(i, n){
        int u = -1;
        rep(j, n-1){
            int a = i;
            int b;
            cin >> b;
            b--;
            if(a > b) swap(a, b);
            int v = a*n+b;
            if(u >= 0) G[u].push_back(v);
            u = v;
        }
    }
    auto ts = tsort(G);
    if(ts.empty()){
        cout << -1 << endl;
        return 0;
    }
    vector<int> tidx(n*n);
    rep(i, n*n){
        // cout << i << " " << ts[i] <<endl;
        tidx[ts[i]] = i;
    }

    vector<int> dp(n*n, 0);
    rep(i, n*n){
        repe(j, G[ts[i]]){
            int k = tidx[j];
            chmax(dp[k], dp[i]+1);
        }
    }
    cout << *max_element(all(dp))+1 << endl;
}

Measured memory_bytes: 51116
#include <stdio.h>
#include <math.h>
#define LEN 1000000

int main(void) {
	int i,j,n,ans,s=(int)sqrt(LEN),p[LEN]={};
	for (i=1;i<LEN;i++) p[i]=1;
	for (i=1;i<s;i++){
		if (p[i]){
			for (j=2*i+1;j<LEN;j+=i+1){
				p[j]=0;
			}
		}
	}
	while (scanf("%d",&n)!=EOF){
		ans=0;
		for (i=1;i<n;i++){
			ans+=p[i];
		}
		printf("%d\n",ans);
	}
	return 0;
}

Measured memory_bytes: 4508
# import sys
# sys.setrecursionlimit(10**5)
# from collections import defaultdict
geta = lambda fn: list(map(fn, input().split()))
gete = lambda fn: fn(input())

def main():
    N, K = geta(int)
    h = geta(int)

    INF = 10 << 60
    dp = [INF]*N
    dp[0], dp[1] = 0, abs(h[0] - h[1])

    for i in range(2, N):
        lb = i-K if i > K else 0
        tmp, hi = INF, h[i]
        for dpj, hj in zip(dp[lb:i], h[lb:i]):
            upd = dpj + abs(hi-hj)
            if tmp > upd:
                tmp = upd
        dp[i] = tmp

    print(dp[-1])

if __name__ == "__main__":
    main()

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

using namespace std;

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define REP(i, k, n) for (int i = (int)(k); i < (int)(n); i++)
#define rrep(i, n) for (int i = (int)(n)-1; i >= 0; i--)
#define rREP(i, k, n) for (int i = (int)(n)-1; i >= k; i--)

#define fi first
#define se second

#define vi vector<int>
#define pb push_back
#define mp make_pair

#define pcnt __builtin_popcount

typedef long long ll;

const int inf = 100100100;
const int MOD = (int) 1e9 + 7;
const double EPS = 1e-9;

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

int main() {
    int n;
    cin >> n;
    int a[210] = {};
    REP(i,1,201){
        REP(j,1,201){
            if(i*j>200) break;
            a[i*j] += 1;
        }
    }
    int cnt = 0;
    for(int i=1;i<=n;i+=2){
        if(a[i]==8) cnt++;
    }
    cout << cnt << endl;
    return 0;
}

Measured memory_bytes: 256
#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>;
using namespace std;

template<class T> void vin(vector<T>& v, int n) {
    v.resize(n);
    for (int i = 0; i < n; ++i) {
        cin >> v[i];
    }
}

int main() {
    int A, P;
    cin >> A >> P;
    cout << (A*3+P)/2 << endl;
    return 0;
}


Measured memory_bytes: 384
#include <iostream> // {{{
#include <string>
#include <vector>
#include <stack>
#include <queue>
#include <map>
#include <algorithm>
#include <cstdio> // }}}

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

using ll = long long;

using namespace std;

int main() {
    ll n;
    ll x;
    vector<ll> a,b,c;
    cin >> n;

    rep(i,n){scanf("%lld", &x); a.push_back(x);}
    rep(i,n){scanf("%lld", &x); b.push_back(x);}
    rep(i,n){scanf("%lld", &x); c.push_back(x);}

    sort(a.begin(),a.end());
    sort(c.begin(),c.end());

    ll sum=0;
    for(auto i:b) {
        auto ia = lower_bound(a.begin(), a.end(), i);
        auto ic = upper_bound(c.begin(), c.end(), i);
        sum += distance(a.begin(), ia)*distance(ic, c.end());
    }

    cout << sum << endl;
    return 0;
}


Measured memory_bytes: 3316
h,w=map(int,input().split())
C=[list(map(int,input().split())) for i in range(10)]
W=[list(map(int,input().split())) for i in range(h)]

for i in range(10):
    for j in range(10):
        for k in range(10):
            C[j][k]=min(C[j][k],C[j][i]+C[i][k])

cost=[C[i][1] for i in range(10)]
cnt=0
for i in range(h):
    for j in range(w):
        if W[i][j]!=-1:
            cnt +=cost[W[i][j]]

print(cnt)

Measured memory_bytes: 3444
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.PrintStream;
import java.io.StreamTokenizer;
import java.util.InputMismatchException;


public class Main {

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

		int n = sc.nextInt();
		int[] heap = new int[n];
		for (int i = 0; i < n; i++) {
			heap[i] = sc.nextInt();
    	}

		for (int i = 0; i < n; i++) {
			int id = i + 1;
			pr.print("node ");
			pr.print(id);
			pr.print(": key = ");
			pr.print(heap[i]);
			pr.print(", ");
			// parent
			if (id / 2 >= 1 ) {
				pr.print("parent key = ");
				pr.print(heap[id / 2 - 1]);
				pr.print(", ");
			}
			if (id * 2 <= n ) {
				pr.print("left key = ");
				pr.print(heap[id * 2 - 1]);
				pr.print(", ");
			}
			if (id * 2 + 1 <= n ) {
				pr.print("right key = ");
				pr.print(heap[id * 2 + 1 - 1]);
				pr.print(", ");
			}
			pr.println("");
    	}
		
    	pr.close();
        sc.close();
	}

	private static class Scanner {
		InputStreamReader isr;
		BufferedReader br;
		StreamTokenizer st;
		
		Scanner (InputStream in) {
			isr = new InputStreamReader(in);
			br = new BufferedReader(isr);
			st = new StreamTokenizer(br);
		}
		
		String next() throws RuntimeException  {
			try {
				if (st.nextToken() != StreamTokenizer.TT_WORD) {
				}
			} catch (IOException e) {
				throw new IllegalStateException();
			}
			
			return st.sval;
		}
		
		int nextInt() throws RuntimeException {
			try {
				if (st.nextToken() != StreamTokenizer.TT_NUMBER) {
					throw new InputMismatchException();
				}
			} catch (IOException e) {
				throw new IllegalStateException();
			}
			
			return (int)st.nval;
		}

		void close() {
		}
	}
	
	private static class Printer {
		PrintStream out;
		StringBuffer strbuf;
		int bufSize;
		final String CR;

		Printer(PrintStream out) {
			this.out = out;
			strbuf = new StringBuffer();
			bufSize = 64 * 1024;
			CR = System.getProperty("line.separator");
		}

		void println(String str) {
			strbuf.append(str);
			strbuf.append(CR);
			checkStringBuffer();
		}

		void print(String str) {
			strbuf.append(str);
			checkStringBuffer();
		}

		void println(int n) {
			strbuf.append(n);
			strbuf.append(CR);
			checkStringBuffer();
		}

		void print(int n) {
			strbuf.append(n);
			checkStringBuffer();
		}

		void print(char c) {
			strbuf.append(c);
			checkStringBuffer();
		}

		void printArray(int[] array) {
			for (int i = 0; i < array.length; i++) {
				checkStringBuffer();
				strbuf.append(array[i]);
				strbuf.append(" ");
			}
			strbuf.delete(strbuf.length() - 1, strbuf.length());
			strbuf.append(CR);
		}

		void close() {
			flashStringBuffer();
		}
		
		private void flashStringBuffer() {
			if (strbuf.length() > 0) {
				out.print(strbuf);
				strbuf.setLength(0);
			}
		}
		
		private void checkStringBuffer() {
			if (strbuf.length() > bufSize) {
				out.print(strbuf);
				strbuf.setLength(0);
			}
		}
	}
}

Measured memory_bytes: 17896
//#include <bits/stdc++.h>
#include <iostream>
#include <vector>
#include <string>
#include <cmath>
#include <algorithm>
#include <map>
#include <iomanip>
#include <stdlib.h>
#include <queue>

using namespace std;

const int nmax = 1e9 + 7;
const long long INF = 1e18;
const double PI = 2 * asin(1);
typedef long long ll;


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

  vector <ll> loc(N + 1);
  for (int i = 0; i < N; i++){
    loc[P[i]] = i + 1;
  }

  vector <ll> checked;
  checked.push_back(0);
  checked.push_back(loc[N]);
  checked.push_back(N + 1);

  ll ans = 0;
  for (ll i = N - 1; i >= 1; i--){
    ll now = loc[i];
    ll L = 0, R = checked.size() - 1;

    ll here;
    while (true){
      here = (L + R) / 2;
      if (now < checked[here]) R = here;
      else L = here;
      
      if (here == (L + R) / 2) break;
    }
    here++;
    checked.insert(checked.begin() + here, now);

    ll cnt = 0;
    if (here - 2 >= 0){
      cnt += (checked[here - 1] - checked[here - 2]) * (checked[here + 1] - checked[here]);
    }

    if (here + 2 < checked.size()){
      cnt += (checked[here + 2] - checked[here + 1]) * (checked[here] - checked[here - 1]);
    }
    ans += cnt * i;
  }

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


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

int main(){
  int s;
  cin >> s;
  int nt = s;
  vector<int> v(1, s);
  for (int i = 2; true; i++){
    if (nt % 2 == 0) nt /= 2;
    else nt = 3 * nt + 1;
    for (int j = 0; j < v.size(); j++){
      if (nt == v.at(j)){
        cout << i << endl;
        return 0;
      }
    }
    v.push_back(nt);
  }
}

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

int fun(int a[], int b[], int c[], int dp[][3], int n, int i, int prev)
{

	if(i > n-1)
		return 0;
	if(dp[i][prev] >= 0 )
		return dp[i][prev];
	else
	{
		int l[3];
		l[0] = a[i], l[1] = b[i], l[2] = c[i];
		for (int j = 0; j < 3; ++j)
		{
			if(j!=prev)
				dp[i][prev] = max(dp[i][prev], l[j] + fun(a, b, c, dp, n, i+1, j)); 			
		}
		return dp[i][prev]; 
	}
}

int main()
{
	ios::sync_with_stdio(false);
	cin.tie(NULL);
	int n;
	cin >> n;
	int a[n], b[n], c[n];
	int dp[n][3];
	for (int i = 0; i < n; ++i)
	{
		cin >> a[i] >> b[i] >> c[i];
		for (int j = 0; j < 3; ++j)
		{
			dp[i][j] = -1;
		}
	}

	int k1= 0;
	int l[3] = {a[0], b[0], c[0]};
	for (int i = 0; i < 3; ++i)
	{
		k1 = max(k1, l[i] + fun(a, b, c, dp, n, 1, i));
	}
	
	// for (int i = 0; i < n; ++i)
	// {
	// 	for (int j = 0; j < 3; ++j)
	// 	{
	// 		cout << dp[i][j]<<" ";
	// 	}
	// 	cout << "\n";
	// }
	cout << k1;
	return 0;
}


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

int main(){
	int n;
  	cin >> n;
  
  	n = (n+1)/2; //(n+a-1)/a 切り上げ
  	cout << n << endl;
}

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

int main(){
    int N, ans;
    cin >> N;
    int a[N];
    double ave;
    double sum = 0.0;
    rep(i, N) {
        cin >> a[i];
        sum += a[i];
    }
    
    ave = sum / N;

    double distance = 0.0, tmp = 100.0;

    rep(i, N) {
        distance = fabs(ave - a[i]);

        if(distance < tmp) {
            ans = i;
            tmp = distance;
        }
    }

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
int main(){
    int H, W;    /* 幅、高さの格納用変数*/
    int i, j;       /* カウンタ用変数*/
    while(1){
        scanf("%d %d", &H, &W);
        if(H == 0 && W == 0){
            break;
        }
        for(i = 0;i < H;i++){
            printf("#");
            for(j = 0;j < W - 2;j++){
                if(i == 0 || i == H - 1){
                    printf("#");
                }
                else{
                    printf(".");
                }
            }
            printf("#\n");
        }
        printf("\n");
    }
    return 0;
}


Measured memory_bytes: 2100
#include<iostream>
#include<string>
#include<string.h>
using namespace std;
int main(){
  int count=0;
  char s[100005];
  cin>>s;
  for(int i=0;i<strlen(s)-1;i++){
    if(s[i]!=s[i+1])count++;
  }
  cout<<count<<"\n";
  return 0;
}


Measured memory_bytes: 384
#include<bits/stdc++.h>
using namespace std;
int main() {
    int n;
    cin>>n;
    for(int i=0;i<=n/4;i++)
        for(int j=0;j<=n/7;j++)
            if(i*4+j*7==n) {
                puts("Yes");
                return 0;
            }
    puts("No");
    return 0;
}

Measured memory_bytes: 256
#define _CRT_SECURE_NO_WARNINGS
#define _USE_MATH_DEFINES
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <vector>
#include <algorithm>
#include <functional>
#include <ccomplex>
#include <unordered_map>
#include <cstring>
#include <iostream>
#include <numeric>
#include <sstream>
#include <set>
#include <map>
#include <tuple>
#include <iomanip>

using namespace std;
#define MAX 1LL << 60
#define MOD 1000000007

typedef long long ll;

#define rep(i, s, e) for(ll i = s; i < e; i++)
#define repR(i, s, e) for(ll i = s; i > e; i--)
#define reft0(i, j) setfill('0') << setw(i) << j
#define fix(i) fixed << setprecision(i)


template<class T> inline bool chMax(T& a, T b){ if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chMin(T& a, T b){ if (a > b) { a = b; return true; } return false; }
template<class T> inline ll gcd(T a, T b){ if (a % b == 0){ return b; } else{ return gcd(b, a%b); } }
template<class T> inline ll lcm(T a, T b){ return a * b / gcd(a, b); }
template<class T> inline ll fact(T a){ if (a <= 1){ return 1; } else{ return a * fact(a - 1); } }
template<class T> inline ll comb(T a, T b){ return a == 0 ? 0 : fact(a) / fact(b) / fact(a - b); }

int main(){
    ll A, B;
    cin >> A >> B;

    double AA = ceil((double)A * 12.5);
    double BB = ceil((double)B * 10);
    if (floor(AA * 0.1) == B){
        cout << AA << endl;
    }
    else if (floor(BB * 0.08) == A){
        cout << BB << endl;
    }
    else{
        cout << -1 << endl;
    }
    return 0;

}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, srt, end) for (long long i = (srt); i < (long long)(end); i++)

int main(){
    ll D;
    cin >> D;
    vector<ll> c(26), t(D), last(26, -1);
    vector< vector<ll> > s(365, vector<ll> (26));
    rep(i, 0, 26) cin >> c[i];
    rep(i, 0, D){
        rep(j, 0, 26) cin >> s[i][j];
    }
    srand((unsigned int)time(NULL));
    rep(i, 0, D){
        t[i] = max_element(s[i].begin(), s[i].end()) - s[i].begin();
    }
    ll M = 2e6;
    vector<ll> rec(26, 0);
    /*
    vector<ll> d(M), q(M), rec(26, 0);
    rep(i, 0, M){
        d[i] = (ll) (rand() % D);
        q[i] = (ll) (rand() % 26);
    }
    */
    ll res = 0;
    rep(d, 0, D){
        res += s[d][t[d]];
        last[t[d]] = d;
        rep(j, 0, 26) {
            res -= c[j] * (d - last[j]);
            rec[j] += c[j] * (d - last[j]);
        }
    }
    vector<ll> median(D);
    rep(i, 0, D){
        auto cp = s[i];
        sort(cp.begin(), cp.end());
        median[i] = cp[20];
    }
    ll rec_sum = 0;
    rep(i, 0, 26) rec_sum += rec[i]; 
    // t[d[m]] := 0 - 25
    rep(m, 0, M){
        ll prev_res = res;
        // ll d = (ll) (rand() % D);
        ll d = m % D;
        ll q = (ll) (rand() % 26);
        // ll q = m % 26;
        // if(rec[q] < c[q] * 100) continue; 
        if(s[d][q] < median[min(25LL, 13 * m / M + 13)]) continue;
        res -= s[d][t[d]];
        res += s[d][q];
        res += rec[t[d]];
        res += rec[q];
        ll tdrec = 0, qrec = 0;
        ll lst = -1;
        rep(i, 0, D){
            if(i != d && t[i] == t[d]){
                lst = i;
            }
            res -= c[t[d]] * (i - lst);
            // rec[t[d[m]]] +=  c[t[d[m]]] * (i - lst);
            tdrec +=  c[t[d]] * (i - lst);
        }
        lst = -1;
        rep(i, 0, D){
            if(i == d || t[i] == q){
                lst = i;
            }
            res -= c[q] * (i - lst);
            // rec[q[m]] += c[q[m]] * (i - lst);
            qrec += c[q] * (i - lst);
        }
        if(res > prev_res){
            rec_sum -= rec[t[d]];
            rec_sum += tdrec;
            rec_sum -= rec[q];
            rec_sum += qrec;
            rec[t[d]] = tdrec;
            rec[q] = qrec;
            t[d] = q;
        }else{
            res = prev_res;
        }
        // cout << res << endl;
    }
    rep(i, 0, D) cout << t[i]+1 << endl;
    return 0;
}

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

int main(){
int N; cin >> N;
int s = 0;
string S = to_string(N);
for (int i = 0; i < S.size(); i++) {
    int tmp = S[i] - '0';
    s += tmp; 
}

if (N % s == 0) {
    cout << "Yes" << endl;
} else {
    cout << "No" << endl;
}
}





Measured memory_bytes: 256
N = int(input())
s = 0
for i in range(1, N + 1):
    if i % 15 == 0:
        s = s # print("FizzBuzz")
    elif i % 3 == 0:
        s = s # print("Fizz")
    elif i % 5 == 0:
        s = s # print("Buzz")
    else:
        # print(i)
        s = s+i
print(s)


Measured memory_bytes: 9116
#include<iostream>
#include<sstream>
#include<fstream>
#include<cstring>/*The header <string> and
<string.h> does not contain the useful
function 'memset' and 'memcpy'.*/
#include<vector>
#include<stack>
#include<map>
#include<set>
#include<queue>
#include<deque>
#include<bitset>
#include<utility>
#include<algorithm>
#include<functional>
#include<ctime>
#include<cmath>
#include<cstdlib>
#include<cstdio>
using namespace std;
int main()
{
	string S;
	cin>>S;
	int res=S.length();
	for(int i=0;i<S.length()-1;i++)
		if(S[i]!=S[i+1])
			res=min(res,max((int)S.length()-i-1,i+1));
	cout<<min(res,(int)S.length())<<endl; ;
	return 0;
}

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

#define int long long

#define rep(i,n) for(int i=0;i<(n);i++)
#define pb push_back
#define all(v) (v).begin(),(v).end()
#define fi first
#define se second
typedef vector<int>vint;
typedef pair<int,int>pint;
typedef vector<pint>vpint;

template<typename A,typename B>inline void chmin(A &a,B b){if(a>b)a=b;}
template<typename A,typename B>inline void chmax(A &a,B b){if(a<b)a=b;}

const int INF=1001001001;

int K,N;

int w[333333];

signed main(){
    cin>>K>>N;


    if(K%2==0){
        cout<<K/2;
        rep(i,N-1)cout<<" "<<K;
        cout<<endl;
        return 0;
    }

    vint ans;
    w[N]=1;
    for(int i=N-1;i>=0;i--){
        w[i]=w[i+1]*K+1;
        chmin(w[i],INF);
    }



    int d=0;
    bool f=0;
    for(int i=0;i<N;i++){
        int a=K;
        if(!f&&(w[i+1]+1)/2<=d){
            a=K/2;
            d-=(w[i+1]+1)/2;
            f=1;
        }

        if(f){
            a-=d/(w[i+1]);
            d%=w[i+1];
            if(a==0)break;
            ans.pb(a);
            continue;
        }

         if((N-i)%2){//w[i]%2==1
            ans.pb((K+1)/2);
            continue;
        }
        else{
            d++;
            ans.pb((K+1)/2);
            /*
            if(1||(w[i+1]+1)/2>d){
                ans.pb((K+1)/2);
                continue;
            }
            */
        }
    }

    rep(i,ans.size()){
        if(i)cout<<" ";cout<<ans[i];
    }cout<<endl;
    return 0;
}


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

#define int long long

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

int N, A, B;

signed main() {
    cin >> N >> A >> B;
    int ans = 0;
    if (N == 10000 && A == 1) {
        ans += 10000;
    }
    for (int i = 0; i < 10; i++) {
        for (int j = 0; j < 10; j++) {
            for (int k = 0; k < 10; k++) {
                for (int l = 0; l < 10; l++) {
                    int num = i * 1000 + j * 100 + k * 10 + l;
                    if (num > N) {
                        cout << ans << endl;
                        return 0;
                    }
                    if (i + j + k + l >= A && i + j + k + l <= B) {
                        ans += num;
                    }
                }
            }
        }
    }
    cout << ans << endl;
    return 0;
}


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

int main()
{
    int a[4];
  	cin>>a[0]>>a[1]>>a[2];
  	int ans=a[0]+a[1];
  	for(int i=0 ; i<3 ; ++i)
    {
    	for(int j=0 ; j<3 ; ++j)
        {
          	if(i!=j)
        	ans=min(ans,a[i]+a[j]);
        }
    }
	cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 256