akhauriyash/Code-Regression huggingface dataset:
#include<iostream>
#include<cstdio>
#include <cstring>
using namespace std;
int main()
{
	    int n;
		bool a[1000001]; 
		memset(a,0,sizeof(a));
		for(int i=2;i<=1000;++i)
		{
			for(int j=2;j*i<=1000000;++j)
			{
				a[i*j]=1;
			}
		}

	while(cin>>n)
	{
		int count=0;
		for(int k=2;k<=n;k++)
		{
			if(!a[k])
			count++;
		}
		cout<<count<<endl;
	
	
		
	}
	return 0;
}

Measured memory_bytes: 2144
#include <iostream>
#include <iomanip>
using namespace std;
int main(){
  int d , n , pow = 1;
  cin >> d >> n;
  for (int i = 0 ; i < d ; i ++) {
    pow *= 100;
  }
  if (n == 100) {
    n ++;
  }
  cout << pow * n << endl;
}

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

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

    vector<pair<int, int>> AB(N);
    for(int i = 0; i < N; i++)
    {
        AB[i] = make_pair(A[i], B[i]);
    }
    sort(AB.begin(), AB.end());

    long long ans = 0;
    for(int i = 0; i < N; i++)
    {
        int buy = min(M, AB[i].second);

        ans += (long long)buy * AB[i].first;
        M -= buy;
    }

    cout << ans << endl;
}

Measured memory_bytes: 1792
#include <stdio.h>
int main(){
  int n ,i ,arrow ,total=0;
  while( scanf( "%d" ,&n ) ){
    if( n == 0 ){
      break;
    }

    n /= 4;

    for( i=0 ; i<n ; i++ ){
      scanf( "%d" ,&arrow );
      total += arrow;
    }

    printf( "%d\n" ,total );
    total = 0;
  }

  return 0;
}

Measured memory_bytes: 600
# coding: utf-8
# Your code here!

A = int(input())

total = 0
for B in range(A):
    #print(B)
    if (B + 1) % 3 == 0 and (B + 1) % 5 ==0:
        #print("FizzBuzz")
        pass
    elif (B + 1) % 3 == 0:
        #print("Fizz")
        pass
    elif (B + 1) % 5 == 0:
        #print("Buzz")
        pass
    else:
        total += (B + 1)
print(total)
        


Measured memory_bytes: 9172
#include <bits/stdc++.h>
using namespace std;
 
typedef long long int ll;
 
typedef pair<int, int> pii;
typedef pair<ll,ll> pll;
 
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<pii> vpii;
typedef vector<pll> vpll;
typedef map<int,int> mii;
 
#define ff first
#define ss second
#define pb push_back
#define all(x) (x).begin(), (x).end()
#define mem(a) memset(a , 0 ,sizeof a)
#define rep(i,a,b) for(int i=a ; i<b ; ++i)
#define deb(x) cout << #x << " - " << x << "\n";
#define deb2(x,y) cerr<<#x<<" :: "<<x<<"\t"<<#y<<" :: "<<y<<"\n"
#define IOS ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
#define D2(x) { cerr << "[" << #x << ": "; for(auto it:x) cerr << it << " "; cerr << "]\n"; }
#define ps(x,y) fixed<<setprecision(y)<<x
#define clz(x) __builtin_clzll(x)
#define setbit(x) __builtin_popcount(x)
 
#define PI 3.141592653589793
const ll MOD = 1e9 + 7;
const ll INF = 10000005;
const ll MAX_N = 1e4 + 10;
/*
hon when the digit in the one's place of 
N
 is 
2
, 
4
, 
5
, 
7
, or 
9
;
pon when the digit in the one's place of 
N
 is 
0
, 
1
, 
6
 or 
8
;
bon when the digit in the one's place of 
N
 is 
3
.
Given 
N
, print the pronunciation of "本" in the phrase*/
int main() {
    IOS;
    int n; cin>>n;
    string s = to_string (n);
    if(n==2||n==4||n==5||n==7||n==9||s[(int)s.length()-1]-'0'==2||s[(int)s.length()-1]-'0'==4||s[(int)s.length()-1]-'0'==5||s[(int)s.length()-1]-'0'==7||s[(int)s.length()-1]-'0'==9) cout << "hon";
    else if(n==0||n==1||n==6||n==8||s[(int)s.length()-1]-'0'==0||s[(int)s.length()-1]-'0'==1||s[(int)s.length()-1]-'0'==6||s[(int)s.length()-1]-'0'==8) cout << "pon";
    else cout << "bon";
    return 0;
}

Measured memory_bytes: 3720
package main

import "fmt"

func main() {
	fmt.Println(solve())
}

func solve() int {
	var a, b, k int
	fmt.Scan(&a, &b, &k)
	var ds []int
	for n := 1; n <= 100; n++ {
		if a % n + b % n == 0 {
			ds = append(ds, n)
		}
	}
	return ds[len(ds)-k]
}


Measured memory_bytes: 512
fun main(args: Array<String>) = IO().exec {
    val n = int()
    val v = DoubleArray(n){double()}
    v.sort()
    var s = v[0]
    for (i in 1 until n) s = (s + v[i]) / 2
    println(s)
}

// region template
operator fun Int.iterator() = 0.until(this).iterator()

class IO {
    val printable = 33..126
    val buffer = ByteArray(1024)
    var ptr = 0
    var buflen = 0
    val out = java.io.PrintWriter(System.out)
    fun hasNextByte(): Boolean = if (ptr < buflen) true else {
        ptr = 0
        buflen = System.`in`.read(buffer)
        buflen > 0
    }

    fun readByte(): Byte = if (hasNextByte()) buffer[ptr++] else -1
    fun hasNext(): Boolean {
        while (hasNextByte() && buffer[ptr] !in printable) ptr++
        return hasNextByte()
    }

    fun string(): String {
        if (!hasNext()) throw java.util.NoSuchElementException()
        val sb = StringBuilder()
        var b = readByte()
        while (b in printable) {
            sb.appendCodePoint(b.toInt())
            b = readByte()
        }
        return sb.toString()
    }

    fun long(): Long {
        if (!hasNext()) throw java.util.NoSuchElementException()
        var n = 0L
        var minus = false
        var b = readByte()
        if (b == '-'.toByte()) {
            minus = true
            b = readByte()
        }
        if (b !in '0'.toByte()..'9'.toByte()) {
            throw NumberFormatException()
        }
        while (true) {
            if (b in '0'.toByte()..'9'.toByte()) {
                n *= 10
                n += b - '0'.toByte()
            } else if (b == (-1).toByte() || b !in printable) {
                return if (minus) -n else n
            } else {
                throw NumberFormatException()
            }
            b = readByte()
        }
    }

    fun int(): Int {
        val nl = long()
        if (nl !in Integer.MIN_VALUE..Integer.MAX_VALUE) throw NumberFormatException()
        return nl.toInt()
    }

    fun double(): Double = string().toDouble()
    fun print(obj: Any) = out.print(obj)
    fun print(i: Int) = out.print(i)
    fun print(l: Long) = out.print(l)
    fun println(obj: Any) = out.println(obj)
    fun println(i: Int) = out.println(i)
    fun println(l: Long) = out.println(l)
    inline fun exec(block: IO.() -> Unit) {
        block()
        out.flush()
    }
}
// endregion

Measured memory_bytes: 33728
#include<iostream>
#include<cmath>
using namespace std;
int main()
{
          int a;
          cin>>a;

          while(a>1000)
          {
          a =a%1000;
          }
          if(a==0)
          {
                    cout<<"0"<<endl;
          }
          else
          {cout<<1000-a<<endl;}
}


Measured memory_bytes: 3608
def digit():
    global S
    global cur
    if S[cur].isdigit():
        n = int(S[cur])
        cur += 1
        return n
def number():
    global S
    L = len(S)
    global cur
    n = digit()
    while (cur < L and S[cur].isdigit()):
        n = n*10 + digit()
    return n
def expression():
    global S
    global cur
    L = len(S)
    a = term()
    while (cur < L and (S[cur] == '+' or S[cur] == '-')):
        op = S[cur]
        cur += 1
        b = term()
        if op == '+':
            a += b
        else:
            a -= b
    return a
import math
def term():
    global S
    global cur
    L = len(S)
    a = factor()
    while (cur < L and (S[cur] == '*' or S[cur] == '/')):
        op = S[cur]
        cur += 1
        b = factor()
        if op == '*':
            a *= b
        else:
            a = math.trunc(a/b)
    return a
def factor():
    global S
    global cur
    if (S[cur] != '('):
        return number()
    else:
        cur += 1
        n = expression()
        if S[cur] == ')':
            cur += 1
            return n

N = int(input().strip())
for _ in range(N):
    S = str(input().strip())
    S = S[:-1]
    cur = 0
    ans = expression()
    print(ans)



Measured memory_bytes: 5664
#include<bits/stdc++.h>
using namespace std;
#define int long long 
#define mod 1000000007
#define nn 200008
struct mat{
	int a[3][3];
	mat(){
		memset(a,0,sizeof a);
	}
};
void add(int&x,int y){
	x=(x+y)%mod;
}
mat operator*(mat a,mat b){
	mat c=mat();
	for(int k=0;k<3;k++) for(int i=0;i<3;i++) for(int j=0;j<3;j++) 
		add(c.a[i][j],a.a[i][k]*b.a[k][j]);
	return c;
}

mat qpow(mat x,int y){
	mat res=mat();for(int i=0;i<3;i++) res.a[i][i]=1;
	while(y){
		if(y&1) res=res*x;x=x*x;y=y/2;
	}return res;
}

mat t0,t1;
int n,m,xi[nn];
signed main(){
	scanf("%lld%lld",&n,&m);for(int i=0;i<m;i++) scanf("%lld",&xi[i]),xi[i]--;sort(xi,xi+m);
	
	t0.a[0][0]=1;t0.a[0][1]=1;t0.a[0][2]=1;
	t0.a[1][0]=0;t0.a[1][1]=1;t0.a[1][2]=2;
	t0.a[2][0]=1;t0.a[2][1]=1;t0.a[2][2]=1+1;
	
	
	t1.a[0][0]=1;t1.a[0][1]=1;t1.a[0][2]=1;
	t1.a[1][0]=0;t1.a[1][1]=1;t1.a[1][2]=2;
	t1.a[2][0]=0;t1.a[2][1]=0;t1.a[2][2]=1;
	
	
	mat now=mat();
	now.a[0][0]=1;now.a[0][1]=1;now.a[0][2]=1; 
	
	int lst=0;
	for(int i=0;i<m;i++){
		now=now*qpow(t0,xi[i]-lst)*t1;
		lst=xi[i]+1;
	}
	now=now*qpow(t0,n-1-lst);
	
	cout<<(now.a[0][2]%mod+mod)%mod;
	return 0;
}

Measured memory_bytes: 1024
import sys
from math import ceil, floor, sqrt, sin, cos, pi
from itertools import accumulate, permutations, combinations
from fractions import gcd # 最大公約数
from collections import deque, Counter
from operator import itemgetter
from heapq import heappop,heappush
sys.setrecursionlimit(10**7)
def lcm(x, y): return ((x * y) // gcd(x, y)) # 最小公倍数
# list(map(int, input().split()))
t = ['Sunny', 'Cloudy', 'Rainy' ,'Sunny']
s = input()
for i in range(len(t)):
    if s == t[i]:
        print(t[i+1])
        sys.exit()

Measured memory_bytes: 5076
#include <bits/stdc++.h>
using namespace std;
#ifdef ENABLE_DEBUG_OUTPUT
#define DEBUG_LOG(s) cout << s << endl;
#else
#define DEBUG_LOG(s) void();
#endif

int main(){
    string s;
    cin >> s;

    int ans = 0;
    for (auto i = 0; i < s.size(); i++) {
        for (auto j = 0; j < s.size(); j++) {
            bool flg = true;
            string t = s.substr(i, (s.size() - j));
            for (auto elm : t) {
                if (elm != 'A' and elm != 'C' and elm != 'G' and elm != 'T') {
                    flg = false;
                    break;
                }
            }
            if(flg) {
                ans = max(ans, (int)t.size());
            }
        }
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
#include<cstdio>
#include<string>
#include<map>
#include<vector>
#include<algorithm>
using namespace std;
typedef pair<int,string>P;
int main()
{
	int n,m,i,j,k,x;
	char r[9];
	vector<P>v;
	v.reserve(1000);
	string s;
	while(scanf("%d%d",&n,&m),n)
	{
		v.clear();
		for(i=0;i<n;++i)scanf("%s%d",r,&x),v.push_back(P(x,r));
		sort(v.begin(),v.end());
		for(x=i=0;i<m;++i)
		{
			scanf("%s",r);
			for(j=v.size()-1;j>=0;--j)
			{
				s=v[j].second;
				for(k=0;k<9;++k)
					if(s[k]!='*'&&s[k]-r[k])goto E;
				x+=v[j].first;
				break;
E:;
			}
		}
		printf("%d\n",x);
	}
	return 0;
}

Measured memory_bytes: 860
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define ll long long
#define all(x) (x).begin(),(x).end()
template<class T> inline bool chmax(T& a, T b) {if (a < b) {a = b;return true;}return false;}
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
const int INF = 1000000000;


bool is_in(int x, vector<int>nodes){
    for (int i=0; i<nodes.size(); i++){
        if (nodes[i] == x)return true;
    }
    return false;
}

int main() {
    int N;
    cin >> N;
    vector<int>a(N);
    vector<vector<int>>graph(N);
    for (int i=0; i<N; i++)cin >> a[i];
    for (int i=0; i<N; i++){
        int ai = a[i];
        ai--;
        graph[i].push_back(ai);
    }

    int cnt = 0;
    for (int i=0; i<N; i++){
        // graph[i][j] in graph[graph[i][j]] -> cnt++
        vector<int>nodes = graph[i];
        for (int j=0; j<nodes.size(); j++){
            if (is_in(i, graph[nodes[j]]))cnt++;
        }
    }
    cout << cnt/2 << endl;

}

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

int main()
{
  string c;
  cin >> c ;
  if(c=="a"||c=="i"||c=="u"||c=="e"||c=="o"){
    cout<<"vowel"<<endl;
  }
  else{
    cout<<"consonant"<<endl;
  }
}


Measured memory_bytes: 384
#include<bits/stdc++.h>
using namespace std;
#define ALL(obj) (obj).begin(), (obj).end()
#define REP(i, n) for(int i = 0;i < (n);++i)
#define RREP(i, n) for(int i = (n)-1; i >= 0; --i)

#define endl '\n'
#define pb push_back
#define eb emplace_back
#define pque priority_queue
#define umap unordered_map
#define BIG 2000000000
#define VERYBIG 1000000000000000ll
#define PI 3.1415926
#define coutdb cout<<fixed<<setprecision(15)

const int dx[]={1,0,-1,0,1,1,-1,-1}, dy[]={0,-1,0,1,1,-1,1,-1};
const long long MOD = 1e9+7;

// typedef int_fast64_t ll;
#define int long long

template<typename T> inline T GCD(T a,T b){T c;while(b!=0){c=a%b;a=b;b=c;}return a;}
template<typename T> inline T LCM(T a,T b){T c=GCD(a,b);a/=c;return a*b;}
template<typename T> inline T nCr(T a,T b){T i,r=1;for(i=1;i<=b;i++){r*=(a+1-i);r/=i;}return r;}
template<typename T> inline T nHr(T a,T b){return nCr(a+b-1,b);}

typedef pair<int, int> INTP;
typedef vector<int> INTV;
struct edge2 {int to, cost;};
struct edge3 {int from, to, cost;};

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

  int N, A[300000]; cin >> N;
  int onecnt[62] = {}, zerocnt[62] = {};

  REP(i, N){
  	cin >> A[i];
  	REP(j, 62){
      if((A[i]>>j) & 1) onecnt[j]++;
      else zerocnt[j]++;
  	}
  }

  // REP(i, N) for(int j = i+1; j < N; j++){
  //   hoge += A[i]^A[j]; hoge %= MOD;
  // }
  // cerr << hoge << endl;

  int ans = 0;
  REP(i, 62){
    ans += ((((1ll<<i) % MOD) * zerocnt[i]%MOD) * onecnt[i]%MOD);
    ans %= MOD;
  }
  cout << ans << endl;
}

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

int main(){
    int N;
    long long s=0;
    cin >> N;
    vector<int> v(N);

    for (int i=0;i<N;++i){
        cin >> v[i];
        v[i] -= (i+1);
    }
    
    sort(v.begin(),v.end());
    
    for (int i=0;i<N;++i){
        s += abs(v[i]-v[N/2]);
    }
    cout << s << endl;
}

Measured memory_bytes: 1024
#!/usr/bin/env ruby

require 'set'

class Hash
  def push(key, value)
    self[key] = [] if self[key] == nil
    self[key].push(value)
  end
end

class Array
  def lower_bound(value)
    left = -1;
    right = self.length;
    while left + 1 < right
      mid = left + (right - left) / 2;
      if self[mid] >= value
        right = mid
      else
        left = mid
      end
    end
    right
  end

  def unique
    res = [self.first]
    each_cons(2) do |a, b|
      if a != b
        res.push(b)
      end
    end
    res
  end
end

def get_ints
  gets.chomp.split.map(&:to_i)
end

def get_ints_minus_one
  get_ints.map { |x| x - 1 }
end

def get_int
  gets.chomp.to_i
end

N, K = get_ints
TD = []
N.times do |i|
  TD[i] = [i] + get_ints
end

TD.sort! { |a, b| a[2] <=> b[2] }.reverse!

if K == 1
  puts TD[0][2] + 1
else
  sets = Array.new(N+1) { Set.new }
  kind_bonus = Set.new
  points = 0

  TD[0...K].each.with_index do |(i, t, d)|
    sets[t].add(i)
    kind_bonus.add(t)
    points += d
  end


  max = points + kind_bonus.length ** 2

  left = K-1
  right = K

  while left >= 0
    i, t, d = TD[left]
    # 重複しているものを低い値から探す
    if sets[t].length > 1
      # 重複しているので、これを除いた新しい種類の最大のものを探す
      while right < N
        right_i, right_t, right_d = TD[right]
        unless kind_bonus.include?(right_t)
          points += right_d - d
          kind_bonus.add(right_t)
          sets[t].delete(i)
          sets[right_t].add(right_i)
          stock = points + kind_bonus.length ** 2
          max = stock if stock > max
          break
        end
        right += 1
      end
    end
    left -= 1
  end

  puts max
end



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

n,k=I()
a = l()
x = a.index(1)
if n == k:
    print(1)
    sys.exit()

print(1+math.ceil((n-k)/(k-1)))


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

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

#define ALL(c)   c.begin(), c.end()
#define SORT(c)  std::sort(ALL(c))
#define RSORT(c) std::sort(ALL(c), std::greater<decltype(c)::value_type>())

using namespace std;
using ll = long long;

const int MOD  = (int)1e9 + 7;
const int INF  = (int)1e9 + 1;
const ll  LINF = (ll)1e18 + 1;

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

    int N;
    std::cin >> N;

    vector<pair<int, int>> odd_map(100000);
    REP(i, 100000) {
        odd_map[i].second = i;
    }
    auto even_map = odd_map;

    REP(i, N) {
        int v;
        std::cin >> v;
        if(i % 2 == 0) {
            even_map[v].first++;
        }
        else {
            odd_map[v].first++;
        }
    }

    RSORT(even_map);
    RSORT(odd_map);

    int even, odd;
    if(even_map[0].second == odd_map[0].second) {
        if(even_map[1].first <= odd_map[1].first) {
            even = even_map[0].first;
            odd  = odd_map[1].first;
        }
        else {
            even = even_map[1].first;
            odd  = odd_map[0].first;
        }
    }
    else {
        even = even_map[0].first;
        odd  = odd_map[0].first;
    }

    std::cout << N - even - odd << std::endl;

    return 0;
}


Measured memory_bytes: 1792
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <vector>
#include <sstream>
#include <cmath>
#include <queue>

using namespace std;

bool a[10000001];

int main(){
	
	int N = 10000001;
	
	for(int i = 0; i < N; i++){
		a[i] = true;
	}
	
	a[0] = false;
	a[1] = false;
	
	for(int i = 2; i < N; i++){
		if(a[i]){
			for(int j = i * 2; j < N; j += i){
				a[j] = false;
			}
		}
	}
	
	int n;
	
	while(true){
		cin >> n;
		if(n == 0){
			break;
		}
		
		int ans;
		
		for(int i = n; i >= 13; i--){
			if(a[i] && a[i - 2] && a[i - 6] && a[i - 8]){
				ans = i;
				break;
			}
		}
		
		cout << ans << endl;
	}
	
	return 0;
}

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

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

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

    int dir = 1;
    vector<int> b;
    for( int i = 0; i < n; ++i ){
        if( dir == 1 ) b.push_back(a[i]);
        else if( dir == -1 ) b.insert(b.begin(), a[i]);
        dir *= -1;
    }

    if( dir == 1 ){
        for( int i = 0; i < n; ++i )
            cout << b[i] << ( i != n-1 ? " " : "\n");
    } else if( dir == -1 ){
        for( int i = n-1; -1 < i; --i )
            cout << b[i] << ( i != 0 ? " " : "\n");
    }

    return 0;
}


Measured memory_bytes: 3828
from collections import*
INF=10**18
n,d,a=map(int,input().split())
mon=[]
for _ in range(n):
  mon+=[list(map(int,input().split()))]
mon.sort()
ans=0
tot=0
q=deque()
for i in range(n):
  x,h=mon[i]
  while q and q[0][0]<x:
    tot-=q.popleft()[1]
  h-=tot
  if h>0:
    b=(h+a-1)//a
    tot+=b*a
    ans+=b
    q.append((x+2*d,b*a))
print(ans)

Measured memory_bytes: 110840
#include <iostream>
#include <cmath>
#include <iomanip>
#include <limits>
#include <string>
#include <vector>
#include <algorithm>
#include <stack>
#include <queue>
#include <map>
#include <list>
#include <cctype>
using namespace std;
typedef long long ll;
#define rep(i,n) for(ll i=0;i<(n);i++)

int main(){
    string W;
    cin >> W;
    ll ans=0;
    while(1){
        string T;
        cin >> T;
        if(T == "END_OF_TEXT") break;
        if(T.size() == W.size()){
            bool match=true;
            rep(i,T.size()){
                if(T.at(i) != W.at(i) && T.at(i) != W.at(i) - 0x20) match = false;
            }
            if(match) ans++;
        }
    }
    cout << ans << endl;
}


Measured memory_bytes: 3160
#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define EPS (1e-7)
#define INF (1e9)
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define all(x) x.begin(),x.end()
const double PI = acos(-1);
const ll MOD = 1000000007;
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;
}
///////////////////////////////////////////////////////////////

class UnionFind {
public:
  vector <ll> par;
  vector <ll> siz;
  UnionFind(ll sz_): par(sz_), siz(sz_, 1LL) {
	for (ll i = 0; i < sz_; ++i) par[i] = i;
  }
  void init(ll sz_) {
	par.resize(sz_);
	siz.assign(sz_, 1LL);
	for (ll i = 0; i < sz_; ++i) par[i] = i;
  }
  ll root(ll x) {
	while (par[x] != x) {
	  x = par[x] = par[par[x]];
	}
	return x;
  }
	bool merge(ll x, ll y) {
		x = root(x);
		y = root(y);
		if (x == y) return false;
		if (siz[x] < siz[y]) swap(x, y);
		siz[x] += siz[y];
		par[y] = x;
		return true;
	}
	bool issame(ll x, ll y) {
		return root(x) == root(y);
	}
	ll size(ll x) {
		return siz[root(x)];
	}
};

int main() {
    ios::sync_with_stdio(false); cin.tie(nullptr);
	int N; cin >> N;
	vector<pair<ll, int>> x(N),y(N);
	rep(i,N) {
		int xx,yy; cin >> xx >> yy;
		x[i] = make_pair(xx,i);
		y[i] = make_pair(yy,i);
	}

	sort(all(x)); sort(all(y));
    priority_queue<tuple<ll, int, int>, vector<tuple<ll, int, int>>, greater<tuple<ll, int, int>>> pq;
    rep(i,N-1) {
		pq.emplace(x[i+1].first - x[i].first,x[i].second,x[i+1].second);
	}
	rep(i,N-1) {
		pq.emplace(y[i+1].first - y[i].first,y[i].second,y[i+1].second);
	}

    UnionFind uf(N);
	ll ans = 0;
	while(!pq.empty()) {
		ll k; int p,q;
		tie(k,p,q) = pq.top(); pq.pop();
		if (uf.issame(p,q)) continue;
        ans += k;
		uf.merge(p,q);
	}

	cout << ans << endl;
}


Measured memory_bytes: 9584
#include <iostream>
#include <iomanip>
#include <string>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <algorithm>
#include <numeric>
#include <cmath>
#include <cassert>

using namespace std;
typedef long long LL;
template <typename F, typename S> std::ostream& operator<<(ostream& os, const pair<F,S>& p) {
    os << "(" << p.first << "," << p.second << ")"; return os; }
template <typename T> ostream& operator<<(ostream& os, const vector<T>& v) {
    os << "["; for(const T& a: v){ os << a << ", "; } os << "]"; return os; }
template <typename K, typename V> ostream& operator<<(ostream& os, const map<K,V>& m) {
    os << "{"; for(const auto& p: m){ os << p.first <<":"<< p.second << ", "; } os << "}"; return os; }


int main(){
    LL n;
    cin >> n;
    LL ans = 1;
    double check = 1.;
    vector<LL> a(n);
    for(LL i = 0; i < n; ++i){
        cin >> a[i];
        if(a[i] == 0){
            cout << 0 << endl;
            return 0;
        }
    }
    for(LL i = 0; i < n; ++i){
        check *= a[i];
        if(check > 2e+18){
            cout << -1 << endl;
            return 0;
        }
        ans *= a[i];
    }
    if(ans > 1000000LL*1000000*1000000){
        cout << -1 << endl;
        return 0;
    }
    cout << ans << endl;
    return 0;
}



Measured memory_bytes: 3676
#include <iostream>
#include <string>
#define rep(i, n) for(int i = 0; i < n; i++)
using namespace std;

int main(){
  int a, b;
  cin >> a >> b;
  int now = 1;
  int ans = 0;
  while(now < b){
    now += a - 1;
    ans++;
  }
  cout << ans << endl;
  
  return 0;
}

Measured memory_bytes: 3676
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cmath>
#include <vector>
#include <list>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <cctype>
#include <cassert>
#include <climits>
#include <string>
#include <bitset>
#include <cfloat>
#include <unordered_set>
#include <unordered_map>
#include <iomanip>
//#pragma GCC optimize("Ofast")
//#define _GLIBCXX_DEBUG
using namespace std;
typedef long double ld;
typedef long long int ll;
typedef unsigned long long int ull;
//#define int ll
typedef vector<int> vi;
typedef vector<char> vc;
typedef vector<bool> vb;
typedef vector<double> vd;
typedef vector<string> vs;
typedef vector<ll> vll;
typedef pair<int,int> pii;
typedef vector<pair<int,int> > vpii;
typedef vector<vector<int> > vvi;
typedef vector<vector<char> > vvc;
typedef vector<vector<string> > vvs;
typedef vector<vector<ll> > vvll;
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define rrep(i,n) for(int i = 1; i <= (n); ++i)
#define irep(it, stl) for(auto it = stl.begin(); it != stl.end(); it++)
#define drep(i,n) for(int i = (n) - 1; i >= 0; --i)
#define fin(ans) cout << (ans) << '\n'
#define mp(p,q) make_pair(p, q)
#define pb(n) push_back(n)
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define floatprec(dig) fixed << setprecision(dig)
#define Sort(a) sort(a.begin(), a.end())
#define Rort(a) sort(a.rbegin(), a.rend())
#define MATHPI acos(-1)
#define itn int;
#define invar(typ, var) typ var; cin >> var;
int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1};
int dy[8] = {0, 1, 0, -1, 1, 1, -1, -1};
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;}
struct io{io(){ios::sync_with_stdio(false);cin.tie(0);}};
const int INF = INT_MAX / 2;
const ll LLINF = 1LL<<60;
constexpr ll MOD = 1000000007;
const double EPS = 1e-9;

ll gcd(ll a, ll b) {
  return b ? gcd(b, a%b) : a;
}

signed main(void) {
  cin.tie(0); ios::sync_with_stdio(false);
  
  ll N, K;
  cin >> N >> K;
  
  ll amax = 0;
  vll A(N);
  rep(i, N){
    cin >> A[i];
    chmax(amax, A[i]);
  }
  
  ll g;
  if(N >= 2) {
    g = A[0];
    rep(i, N - 1) {
      g = gcd(g, A[i + 1]);
    }
  } else {
    g = A[0];
  }
  
  if(K % g == 0 && K <= amax) {
    fin("POSSIBLE");
  } else {
    fin("IMPOSSIBLE");
  }
}

Measured memory_bytes: 1024
#include"bits/stdc++.h"
using namespace std;
int main()
{
string A,B;
cin>>A>>B;
int c=0;
int x=A.size();
for(int i=0;i<x;i++)
    if(A[i]!=B[i])
    c++;
cout<<c<<endl;
return 0;
}


Measured memory_bytes: 3848
#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>;

int main(){
  int r,g;
  cin >> r >> g;
  cout << 2*g-r << endl; 
  return 0;
}


Measured memory_bytes: 256
s = input()
p = input()
flag = 0
for i in range(len(s)):
    if flag == 1:
        break
    if s[i] == p[0]:
        if len(p) == 1:
            print("Yes")
            flag = 1
            break
        for j in range(1, len(p)):
            i = (i + 1) % len(s)
            if s[i] != p[j]:
                break
            if j == len(p)-1:
                print("Yes")
                flag = 1
                break
if flag == 0:
    print("No")

Measured memory_bytes: 7496
#include<cstdio>
using namespace std;
int m[100],a[100],b[100],n;
bool judge(int x){
    int w=0;
    for(int i=0;i<n;i++)
        if(a[i]<=x&&b[i]>x)w+=m[i];
    return w<=150;
}
int main(){
    while(scanf("%d",&n)&&n){
        for(int i=0;i<n;i++)scanf("%d%d%d",m+i,a+i,b+i);
        bool res=true;
        for(int i=0;i<n;i++)res&=judge(a[i]);
        for(int i=0;i<n;i++)res&=judge(b[i]);
        puts(res?"OK":"NG");
    }
    return 0;
}

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

using namespace std;
typedef long long ll;
#define MOD 1000000007
template<typename T1,typename T2> inline void chmin(T1 &a,T2 b){if(a>b) a=b;}
template<typename T1,typename T2> inline void chmax(T1 &a,T2 b){if(a<b) a=b;}

int main() {
    int N;
    cin >> N;

    int d[N];
    for(int i=0; i<N; i++) cin >> d[i];

    ll sum = 0;
    for(int i=0; i<N; i++) {
        for(int j=i+1; j<N; j++) {
            sum += d[i] * d[j];
        }
    }

    cout << sum << endl;

    return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
int main(void){
    int i, n, a[1000];
    
    scanf("%d\n", &n);
    for(i=0; i<n; i++) {
        scanf("%d", &a[i]);
    }

    for (i=n-1; i>=0; i--) {
        printf("%d",a[i]);
        if(i != 0) printf(" ");
    }
    printf("\n");
    return 0;
}


Measured memory_bytes: 2104
from collections import defaultdict
from typing import Counter

N = int(input())
XY = [list(map(int, input().split())) for _ in range(N)]
cnt = defaultdict(Counter)

ans = 0

for i in range(N):
    for j in range(N):
        if i == j:
            continue
        a = XY[i][0]-XY[j][0]
        b = XY[i][1]-XY[j][1]
        cnt[a][b] += 1
        ans = max(cnt[a][b], ans)

print(N-ans)

Measured memory_bytes: 11212
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
 
def main():
    N, M = map(int, readline().split())
    #空の部分列を考えるために適当な値で0番目の要素を埋めてインデックスを調節している
    #dpの更新で考えるのは1番目以降であるから0番目の要素が同じ要素であろうとなかろうと影響しない
    S = [0] + [int(i) for i in readline().split()]
    T = [0] + [int(i) for i in readline().split()]
    
    #共通部分列の集合と共通部分列の数対応について考えるために補助的にDPを定義
    #DP(i, j):=Sのi文字目、Tのj文字目までの共通部分列の集合

    #実際に求める数を導くためのdpテーブル
    #dp(i, j):=Sのi文字目、Tのj文字目までの共通部分列の数

    #「受け継ぐ要素（変化しない共通部分列）」と「増える分の要素」に注目して考える
    #S_i+1 != T_j+1のとき、DP(i+1, j+1) = DP(i+1, j) ∩ DP(i, j+1) 
    #S_i+1 = T_j+1のとき、DP(i+1, j+1) = DP(i+1, j) ∩ DP(i, j+1) ∩ (操作によって増えた共通部分列の集合)
    #（操作によって増えた共通部分列の集合）の要素数はdp(i, j)である
    # ∵ DP(i, j)の各要素である共通部分列の最後にそれぞれS_iを追加してできた共通部分列の集合が（操作によって増えた共通部分の集合）である

    #DPをdpに対応付けながら実装していく

    dp = [[0 for _ in range(M+1)] for _ in range(N+1)] 

    #空の部分列が共通部分列となるので、dp[0][x]およびdp[x][0]の値は1として初期化する
    for i in range(N+1):
        dp[i][0] = 1
    for i in range(M+1):
        dp[0][i] = 1
    
    #dpの更新
    P = int(1e9)+7
    for i in range(N):
        for j in range(M):
            if S[i+1] != T[j+1]:
                #和集合の要素数を考えるとき、重複部分の要素数を引かなければならない
                #DP(i+1, j)とDP(i, j+1)の重複部分はDP(i, j)であり要素数はdp(i, j)である
                dp[i+1][j+1] = dp[i+1][j] + dp[i][j+1] - dp[i][j]
                dp[i+1][j+1] %= P
            else:
                #下の式の最後のdp[i][j]は増えた共通部分列の数である
                #dp[i+1][j+1] = dp[i+1][j] + dp[i][j+1] - dp[i][j] + dp[i][j] 
                #整理すると以下の式になる
                dp[i+1][j+1] = dp[i+1][j] + dp[i][j+1] 
                dp[i+1][j+1] %= P
    print(dp[N][M])
if __name__ == '__main__':
    main()


Measured memory_bytes: 74460
#include <stdio.h>
int isprime(int n){
	int i;
	for(i=2;i*i<=n;i++){
		if(n % i==0) return 0;
	}
	return 1;
}
int main(){
	int n,i, max=0;
	while(1){
		  scanf("%d",&n);
		  if(n==0) break;
		  for(i=n;i>=1;i--){
		  	if(isprime(i)==1 && isprime(i-2)==1){
			max=i;
			break;
			}
	    }
	    printf("%d %d\n",max-2,max);
	}
	return 0;
}
	

Measured memory_bytes: 1748
import sys

sys.setrecursionlimit(10 ** 8)

input = sys.stdin.readline


def main():
    N, M = [int(x) for x in input().split()]
    XY = [[int(x) for x in input().split()] for _ in range(M)]
    ans = [0] * (N + 1)
    ans[1] = 1
    cnt = [1] * (N + 1)
    for x, y in XY:
        if ans[x] == 1:
            ans[y] = 1
        if cnt[x] == 1:
            ans[x] = 0
        cnt[x] -= 1
        cnt[y] += 1

    print(sum(ans))


if __name__ == '__main__':
    main()


Measured memory_bytes: 27096
#include <cstdio>
#include <cstring>
#include <iostream>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <algorithm>
#define maxn 100009
using namespace std;
int cnt[maxn];
int n;
int main(){
	cin >> n;
	for(int i = 1; i <= n; i++){
		int x;
		cin >> x;
		if(x == i)
			cnt[i] = 1;
	}
	int cur = 1, ans = 0;
	while(cur <= n){
		int L = cur;
		while(cur + 1 <= n && cnt[cur] == cnt[cur + 1])
			cur++;
		int R = cur;
		if(cnt[L] == 1){
			ans += (R - L + 1 + 1) / 2;
		}
		cur++;
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 640
#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < (int)(n); i++)
#define rrep(ri,n) for(int ri = (int)(n-1); ri >= 0; ri--)
#define rep2(i,x,n) for(int i = (int)(x); i < (int)(n); i++)
#define repit(itr,x) for(auto itr = x.begin(); itr != x.end(); itr++)
#define rrepit(ritr,x) for(auto ritr = x.rbegin(); ritr != x.rend(); ritr++)
#define ALL(n) begin(n), end(n)
using ll = long long;
using namespace std;

int main(){
  int a, b, h;
  cin >> a >> b >> h;
  int ans = (a+b)*h/2;
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 3672
#include<bits/stdc++.h>
using namespace std;
const long long md=2038077799;
long long n,a[202020],b[202020],aa[202020],bb[202020],ha,hb,bs=1400312813;
vector<long long>v;
long long pw(long long x,long long y)
{
	long long rt=1;
	while(y)
	{
		if(y&1)
		{
			rt*=x;
			rt%=md;
		}
		y>>=1;
		x*=x;
		x%=md;
	}
	return rt;
}
int main()
{
	cin>>n;
	for(int i=0;i<n;i++)
	{
		cin>>a[i];
	}
	for(int i=0;i<n;i++)
	{
		cin>>b[i];
	}
	for(int i=0;i<n;i++)
	{
		aa[i]=a[(i+1)%n]^a[i];
		bb[i]=b[(i+1)%n]^b[i];
	}
	for(int i=0;i<n;i++)
	{
		ha*=bs;
		ha%=md;
		ha+=aa[i];
		ha%=md;
	}
	for(int i=0;i<n;i++)
	{
		hb*=bs;
		hb%=md;
		hb+=bb[i];
		hb%=md;
	}
	long long nw=pw(bs,n-1);
	for(int i=0;i<n;i++)
	{
		if(ha==hb)
		{
			v.push_back(i);
		}
		long long vl=nw*aa[i];
		vl%=md;
		ha+=md-vl;
		ha%=md;
		ha*=bs;
		ha%=md;
		ha+=aa[i];
		ha%=md;
	}
	for(int i=0;i<v.size();i++)
	{
		cout<<v[i]<<' '<<(a[0]^(b[(n-v[i])%n]))<<endl;
	}
	return 0;
}

Measured memory_bytes: 11376
#include <stdio.h>

int main() {
  int a,b,c,x;
  int d = 0;
  int e =0;

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

  for(x=a; x<=b; x++) {
    d = c % x;
    if(d == 0){
      e = e+1;
  }
  }
  printf("%d\n",e);

  return 0;
}

Measured memory_bytes: 596
import sys
input = sys.stdin.readline

def solve():
    N = int(input())
    items = [tuple(map(int, input().split())) for _ in range(N)]

    capW = max([w+s for w, s, v in items])
    items.sort(key=lambda x: x[0]+x[1])

    def knapsack01(items, capW):
        dp = [0] * (capW+1)
        for wi, si, vi in items:
            for w in reversed(range(wi, si+wi+1)):
                v0 = dp[w-wi] + vi
                if v0 > dp[w]:
                    dp[w] = v0
        return max(dp)

    ans = knapsack01(items, capW)
    print(ans)


solve()


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

using namespace std;

int dp[3001][3001];
char pp[3001][3001];
string s,t,p;
void print(int i,int j)
{
	if(i<0 || j<0)return ;
	if(pp[i][j]=='0')
	{
		print(i-1,j-1);
		p+=s[i-1];
	}
	else if(pp[i][j]=='1')
	{
		print(i-1,j);
	}
	else 
	{
		print(i,j-1);
	}
}
int main()
{

ios_base::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);

cin>>s>>t;
int n=s.size(),m=t.size();
for(int i=0;i<=n;i++)
{
dp[i][0]=0;
	
}
for(int i=0;i<=m;i++)
{
	dp[0][i]=0;
	
}
for(int i=1;i<=n;i++)
{
	for(int j=1;j<=m;j++)
	{
		if(s[i-1]==t[j-1])
		{
			dp[i][j]=dp[i-1][j-1]+1;
			pp[i][j]='0';
		}
		else
		{
			if(dp[i-1][j]>=dp[i][j-1])
			{
				dp[i][j]=dp[i-1][j];
				pp[i][j]='1';
			}
			else 
			{
				dp[i][j]=dp[i][j-1];
				pp[i][j]='2';
			}
		}
	}
}
print(n,m);
cout<<p;

}

Measured memory_bytes: 44288
input = gets.chomp.split ''
stack1 = []
stack2 = []
answer = 0

input.each_with_index do |char, index|
  stack1 << index if char == '\\'
  next unless char == '/' && !stack1.empty?
  j = stack1.pop
  a = index - j
  answer += a
  a += stack2.pop[1] while !stack2.empty? && stack2[-1][0] > j
  stack2 << [j, a]
end

puts answer
areas = []
stack2.each do |array|
  areas << array[1]
end
result = [areas.size].concat(areas)
puts result.join ' '



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

using namespace std;

using P = pair<long long, long long>;
using Q = priority_queue<P, vector<P>, greater<P> >;
using E = pair<long long, long long>;

int main() {
    long long n, m, s, t;
    cin >> n >> m >> s >> t; s--; t--;
    
    vector<vector<E> > a(n), b(n);
    long long u, v, _a, _b;
    for (int i = 0; i < m; i++) {
        cin >> u >> v >> _a >> _b; u--; v--;
        a[u].push_back(E(v, _a));
        a[v].push_back(E(u, _a));
        b[u].push_back(E(v, _b));
        b[v].push_back(E(u, _b));
    }
    
    vector<long long> ad(n, 1e15); ad[s] = 0;
    Q aque; aque.push(P(0, s));
    
    while (!aque.empty()) {
        P p = aque.top(); aque.pop();
        if (ad[p.second] < p.first) continue;
        for (auto e : a[p.second]) {
            if (ad[e.first] > ad[p.second] + e.second) {
                ad[e.first] = ad[p.second] + e.second;
                aque.push(P(ad[e.first], e.first));
            }
        }
    }
    
    vector<long long> bd(n, 1e15); bd[t] = 0;
    Q bque; bque.push(P(0, t));
    
    while (!bque.empty()) {
        P p = bque.top(); bque.pop();
        if (bd[p.second] < p.first) continue;
        for (auto e : b[p.second]) {
            if (bd[e.first] > bd[p.second] + e.second) {
                bd[e.first] = bd[p.second] + e.second;
                bque.push(P(bd[e.first], e.first));
            }
        }
    }
    
    long long d[100000];
    for (int i = 0; i < n; i++) d[i] = ad[i] + bd[i];
    for (int i = 1; i < n; i++) if (d[n-i-1] > d[n-i]) d[n-i-1] = d[n-i];
    for (int i = 0; i < n; i++) cout << ((long long)1e15) - d[i] << endl;

    return 0;
}

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

typedef double du ;
typedef string st ;
typedef long long ll ;
typedef long double ld ;
typedef long long int lli ;

#define vi vector <lli>
#define loop(num) for (lli i = 0 ; i < num ; i ++ )
#define loopcin(num , ar ) for (lli i = 0 ; i < num ; i ++ ) {cin >> ar [i] ;}
#define loopcout(num , ar) for (lli i = 0 ; i < num ; i ++ ) {cout << ar [i] << ' '; }

#define forr(num1 , num2) for (lli i = num1 ; i < num2 ; i ++ )
#define forrcin(num1 , num2 , ar ) for (lli i = num1 ; i < num2 ; i ++ ) {cin >> ar [i] ;}
#define forrcout(num1 , num2 , ar) for (lli i = num1 ; i < num2 ; i ++ ) {cout << ar [i] << ' '; }

#define D2forrcin(num1_1 , num1_2 , num2_1 , num2_2 , A ) for (lli i = num1_1 ; i < num1_2 ; i ++){ for (lli j = num2_1 ; j < num2_2 ; j++){cin >> A[i][j] ;}}
#define D2forrcout(num1_1 , num1_2 , num2_1 , num2_2 , A ) for (lli i = num1_1 ; i < num1_2 ; i ++){ for (lli j = num2_1 ; j < num2_2 ; j++){cout << A[i][j] << ' ' ;}cout << endl ;}

#define YES cout << "YES" << endl
#define Yes cout << "Yes" << endl
#define NO cout << "NO" << endl
#define No cout << "No" << endl

#define F first
#define S second

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

int main ()
{
    fastio
    lli num1 , num2 ;
    cin >> num1 >> num2 ;
    cout << --num1 * --num2 ;

    return 0 ;
}

/*___________________________________________________________________functions___________________________________________________________________________*/



Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(n);++i)
using namespace std;
using ll = long long;
int main(){
    int n;
    cin >> n;
    vector<int> v(n),c(n);
    rep(i,n) cin >> v[i];
    rep(i,n) cin >> c[i];
    int ans=0;
    rep(i,n) ans+=max(0,v[i]-c[i]);
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
int main(){
  char a[3]={0};
  
  scanf("%s %s %s",&a[0],&a[1],&a[2]);
  
  if(a[0]!=a[1]&&a[1]!=a[2]&&a[0]!=a[2]){
    printf("Yes");}
  else{
    printf("No");
  }
  return(0);
}
 

Measured memory_bytes: 128
#include <stdio.h>

int main(void) {
    for(;;) {
        int W, H;
        scanf("%d %d", &W, &H);
        if (W == 0 || H == 0) {
            return 0;
        } else {
            for (int i = 1; i <= W; i++) {
                if (i == 1 || i == W) {
                    for (int j = 1; j <= H; j++) {
                        printf("#");
                    }
                } else {
                    printf("#");
                    for (int j = 2; j <= H - 1; j++) {
                        printf(".");
                    }
                    printf("#");
                }
                puts("");
            }
            puts("");
        }
    }
}


Measured memory_bytes: 2064
#include<stdio.h>

void insertionSort(int* A, int N){

    for(int m=0; m<N; m++){
        if(m!=N-1) printf("%d ", A[m]);
        if(m==N-1) printf("%d\n", A[m]);
        }

    for(int i=1; i<N; i++){
        int v;
        v = A[i];
        int j = i-1;
        while((j>=0)&&(A[j]>v)){
            A[j+1] = A[j];
            j--;
        }
        A[j+1] = v;
        
        for(int m=0; m<N; m++){
            if(m!=N-1) printf("%d ", A[m]);
            if(m==N-1) printf("%d\n", A[m]);
        }
    }
}

int main(){

    int n;
    scanf("%d", &n);

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

    insertionSort(A, n);

    return 0;
}


Measured memory_bytes: 2696
from collections import Counter,defaultdict,deque
from heapq import heappop,heappush,heapify
import sys,bisect,math,itertools,fractions
sys.setrecursionlimit(10**8)
mod = 10**9+7
INF = float('inf')
def inp(): return int(sys.stdin.readline())
def inpl(): return list(map(int, sys.stdin.readline().split()))

def err():
    print(0)
    quit()

n = inp()
a = inpl()
b = inpl()
if a[-1] != b[0]: err()
de = [-1] * n
mx = [INF] * n
now = -1
for i in range(n):
    if a[i] > now:
        now = a[i]
        de[i] = now
    else:
        mx[i] = now
now = -1
for i in range(n)[::-1]:
    if b[i] > now:
        now = b[i]
        if de[i] != -1 and de[i] != now:
            err()
        de[i] = now
    else:
        if now < de[i]: err()
        mx[i] = min(mx[i], now)
res = 1
for i in range(n):
    if de[i] == -1:
        res *= mx[i]
        res %= mod
print(res)

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

using namespace std;
typedef long long ll;
#define int ll

#define REP(i,n) for(int i=0;i<n;++i)
#define SORT(name) sort(name.begin(), name.end())
#define ZERO(p) memset(p, 0, sizeof(p))
#define MINUS(p) memset(p, -1, sizeof(p))
#if 1
#  define DBG(fmt, ...) printf(fmt, ##__VA_ARGS__)
#else
#  define DBG(fmt, ...)
#endif

const ll LLINF = (1LL<<60);
const int INF = (1LL<<30);
const double DINF = std::numeric_limits<double>::infinity();
const int MOD = 1000000007;
#define MAX_N 50

ll N;
ll fact[MAX_N] = {};
bool ans[MAX_N] = {};

void Disp() {
    ll max_digit = 0;
    for(ll i = MAX_N - 1; i >= 0; --i) {
        if(ans[i]) {
            max_digit = i;
            break;
        }
    }
    for(ll i = max_digit; i >= 0; --i) {
        printf("%d", ans[i] ? 1 : 0);
    }
    printf("\n");
}

signed main()
{

    fact[0] = 1;
    for(ll i = 1; i < MAX_N; ++i) {
        fact[i] = fact[i-1] * (-2);
    }

    cin >> N;

    if(N == 0) {
        printf("0\n");
        return 0;
    }

    while(N != 0) {
        if(N > 0) {
            ll digit_max = 1;   // この桁数の最大値
            ll length = 1;
            ll ind = 2;
            while(N > digit_max) {
                digit_max += fact[ind];
                ind += 2;
                length += 2;
            }
            ans[length-1] = true;
            N -= fact[length-1];
        } else {
            ll digit_min = -2;   // この桁数の最小値
            ll length = 2;
            ll ind = 3;
            while(N < digit_min) {
                digit_min += fact[ind];
                ind += 2;
                length += 2;
            }
            ans[length-1] = true;
            N -= fact[length-1];
        }
    }

    Disp();
    return 0;
}


Measured memory_bytes: 256
import java.util.Scanner;

public class Main{
	public static void main(String[] args){
	Scanner scan = new Scanner(System.in);
	int A = scan.nextInt();
	int B = scan.nextInt();
	if(A >= B*2){
		int Ans = A - B*2;
		System.out.println(Ans);
	}else{
		System.out.println("0");
		}
	}
}	

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

int     main() {
        int a, b;
        cin >>a >>b;
        int c=b-a;
        int S=0;
        for (int i=1; i<c; i++)
                S +=i;
        S -=a;
        cout <<S <<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)
#define FOR(i, a, b) for(int i = a; i < (int)b; ++i)
#define rrep(i, n) for(int i = ((int)n - 1); i >= 0; --i)

using ll = long long;
using ld = long double;

const ll INF = 1e18;
const int Inf = 1e9;
const double EPS = 1e-9;
const ll MOD = 1e9 + 7;

int main() {
    cin.tie(nullptr);
    ios::sync_with_stdio(0);
	int a, b;
	cin >> a >> b;
	if ((a + b) % 2 == 0) cout << (a + b) / 2 << endl;
	else cout << "IMPOSSIBLE" << endl;
    
    return 0;
}



Measured memory_bytes: 3596
#include"bits/stdc++.h"
using namespace std;
#define rep(i, N) for(int i=0; i<N; ++i)
using ul = unsigned long;
using ll = long long;

int main() {
    int N;
    string S;
    cin >> N >> S;
    int length = S.length();
    if (length % 2 == 1) {
        cout << "No" << endl;
        return 0;
    }
    for(int i=0; i<length/2; ++i) {
        if (S[i] != S[length/2+i]) {
            cout << "No" << endl;
            return 0;
        }
    }
    cout << "Yes" << endl;
    return 0;
}


Measured memory_bytes: 256
#include <algorithm>
#include <iostream>
#include <set>
#include <string>
#include <vector>

using namespace std;

string s;
int K;

int main() {
    cin >> s;
    cin >> K;

    string s_ = s;
    sort(s_.begin(), s_.end());
    s_.erase(std::unique(s_.begin(), s_.end()), s_.end());

    set<string> substr;
    for (auto c : s_) {
        auto pos = s.find(c);
        while (pos != string::npos) {
            for (int i = 1; i <= min((int)(s.size() - pos), 5); ++i) {
                substr.insert(s.substr(pos, i));
            }
            pos = s.find(c, pos + 1);
        }
    }
    auto it = substr.begin();
    for (int i = 0; i < K - 1; ++i) ++it;
    cout << *it << endl;
}


Measured memory_bytes: 1152
#include<bits/stdc++.h>
#define M 1000000007
#define pi ld(acos(-1.0))
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define Rep(i,n) for(int i=1;i<(int)(n);i++)
#define repp(i,a,b)  for(int i=a;i<=(int)(b);i++)
#define Repp(i,a,b)  for(int i=a;i>=(int)(b);i--)
#define cs ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define fi first
#define se second
#define ii pair<int,int>
#define bye(x) {cout<<x;return 0;}
typedef long long ll;
typedef long double ld;
using namespace std;

int main() {
    cs
    int n,k;cin>>n>>k;
    vector<int> v(n);
    for(auto &i:v) cin>>i;
    vector<int> ans(n);
    ans[0]=0;
 
    repp(i,1,n-1) {
        int t=M;
        Repp(j,i-1,max(i-k,0)) {
            t=min(t,ans[j]+abs(v[j]-v[i]));
        }
        ans[i]=t;
    }
    cout<<ans[n-1];
}

Measured memory_bytes: 1024
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner scanner = new Scanner(System.in);
		int n = scanner.nextInt();
		int k = n/7;
		for (int i=0;i<=k;i++){
			if ((n-(7*i))%4==0) {
				System.out.println("Yes");
				System.exit(0);
			}
		}
		System.out.println("No");
	}
}

Measured memory_bytes: 23124
#include <iostream>
#include <cstdio>
#define N 305
using namespace std;

typedef long long ll;
ll n, m, l, q, d1[N][N], d2[N][N];
int main()
{
	ll i, j, k, t1, t2, t3;
	cin >> n >> m >> l;
	for (i = 1; i <= n; i++) {
		for (j = 1; j <= n; j++) {
			if (i != j)	d1[i][j] = d2[i][j] = 1e18;
		}
	}
	while (m--) {
		scanf("%lld %lld %lld", &t1, &t2, &t3);
		if (t3 > l) continue;
		d1[t1][t2] = min(d1[t1][t2], t3);
		d1[t2][t1] = min(d1[t2][t1], t3);
	}
	for (k = 1; k <= n; k++) {
		for (i = 1; i <= n; i++) {
			for (j = 1; j <= n; j++) {
				d1[i][j] = min(d1[i][j], d1[i][k] + d1[k][j]);
			}
		}
	}
	for (i = 1; i <= n; i++) {
		for (j = 1; j <= n; j++) {
			if (d1[i][j] <= l) d2[i][j] = 1;
		}
	}
	for (k = 1; k <= n; k++) {
		for (i = 1; i <= n; i++) {
			for (j = 1; j <= n; j++) {
				d2[i][j] = min(d2[i][j], d2[i][k] + d2[k][j]);
			}
		}
	}
	cin >> q;
	while (q--) {
		scanf("%lld %lld", &t1, &t2);
		if (d2[t1][t2] < 1e18) printf("%lld\n", d2[t1][t2] - 1);
		else puts("-1");
	}
    return 0;
}

Measured memory_bytes: 2048
n, m = map(int, input().split())
a = list(map(int, input().split()))
# print(n, m)
# for i in a:
#    print(i)
# print(a)
b = sum(a)
x = b / (4 * m)
# print(x)
cnt = 0
for i in a:
    if i >= x:
        cnt = cnt + 1
# print(cnt)
if cnt >= m:
    print("Yes")
else:
    print("No")


Measured memory_bytes: 3060