akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for(ll i = 0, i##_len = (n); i < i##_len; i++)
#define reps(i, s, n) for(ll i = (s), i##_len = (n); i < i##_len; i++)
#define rrep(i, n) for(ll i = (n) - 1; i >= 0; i--)
#define rreps(i, e, n) for(ll i = (n) - 1; i >= (e); i--)
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define sz(x) ((ll)(x).size())
#define len(x) ((ll)(x).length())
#define endl "\n"

ll f(ll n) {
    if (n == 0) return 0;
    return f(n % __builtin_popcountll(n)) + 1;
}

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    // ifstream in("input.txt");
    // cin.rdbuf(in.rdbuf());
    ll n;
    string x;
    cin >> n >> x;
    reverse(all(x));
    ll pc = 0;
    rep(i, n) pc += x[i] - '0';
    vector<vector<ll>> raw(3, vector<ll>(n + 1, 0));
    vector<vector<ll>> ket(3, vector<ll>(n + 1, 1));
    rep(i, n) {
        rep(j, 3) {
            if ((pc + (j - 1)) <= 0) continue;
            raw[j][i + 1] = (raw[j][i] + (x[i] - '0') * ket[j][i]) % (pc + (j - 1));
            ket[j][i + 1] = (ket[j][i] * 2) % (pc + (j - 1));
        }
    }
    rrep(i, n) {
        ll ans = 0;
        if (x[i] == '0') {
            ans = f((raw[2][n] + ket[2][i]) % (pc + 1)) + 1;
        }
        else {
            if (pc > 1) ans = f((raw[0][n] - ket[0][i] + (pc - 1)) % (pc - 1)) + 1;
        }
        cout << ans << endl;
    }
    return 0;
}


Measured memory_bytes: 14440
#include<stdio.h>
#include<string.h>
#include<stdlib.h>
#include<math.h>
#define PI 3.141592653589793
#define MOD 1000000007


int main(){
	int n;
	scanf("%d", &n);
	int arr[200005];
	for(int i=0; i<n; i++){
		scanf("%d", &arr[i]);
	}
	int count=1, min = arr[0];
	for(int i=1; i<n; i++){
		if(arr[i]<=min){
			count++;
			min = arr[i];
		}
	}
	printf("%d\n", count);
	return 0;
}

Measured memory_bytes: 896
#include <stdio.h>
#include <math.h>

typedef long long ll;

int main() {
	int n;
	scanf("%d", &n);
	
	ll fdmax[2] = {-1e10, -1e10};
	ll fdmin[2] = {1e10, 1e10};
	for (ll i = 0; i < n; i++)
	{
		ll x, y;
		scanf("%lld %lld", &x, &y);
		ll f0 = x + y, f1 = x - y;
		if (f0 > fdmax[0]) fdmax[0] = f0;
		if (f0 < fdmin[0]) fdmin[0] = f0;
		if (f1 > fdmax[1]) fdmax[1] = f1;
		if (f1 < fdmin[1]) fdmin[1] = f1;
		
	}
	ll dmax = -1e10;
	if (fdmax[0] - fdmin[0] > dmax) dmax = fdmax[0] - fdmin[0];
	if (fdmax[1] - fdmin[1] > dmax) dmax = fdmax[1] - fdmin[1];
	printf("%lld", dmax);
	return 0;
}


Measured memory_bytes: 1652
package main

import "fmt"

func main() {
	var N, M int
	var w string
	fmt.Scan(&N, &M)
	a := make([][]string, N)
	for i := 0; i < N; i++ {
		fmt.Scan(&w)
		wa := make([]string, N)
		for i, v := range w {
			wa[i] = string(v)
		}
		a[i] = wa
	}
	b := make([][]string, M)
	for i := 0; i < M; i++ {
		fmt.Scan(&w)
		wa := make([]string, M)
		for i, v := range w {
			wa[i] = string(v)
		}
		b[i] = wa
	}
	for i := 0; i < N; i++ {
		for j := 0; j < N; j++ {
			flg := true
			for y := 0; y < M; y++ {
				if i+y >= N {
					fmt.Println("No")
					return
				}
				for x := 0; x < M; x++ {
					if j+x >= N {
						flg = false
						break
					}
					if a[i+y][j+x] == b[y][x] {
						continue
					} else {
						flg = false
						break
					}
				}
				if !flg {
					break
				}
			}
			if flg {
				fmt.Println("Yes")
				return
			}
		}
	}
	fmt.Println("No")
}



Measured memory_bytes: 640
#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < (int)(n); i++)
#define fi first
#define se second
#define pb push_back
#define eb emplace_back
#define sz(x) (int)(x).size()
using namespace std;
using ll = long long;
using P = pair<int, int>;
using vi = vector<int>;
using vc = vector<char>;
using vb = vector<bool>;
using vs = vector<string>;
using vll = vector<long long>;
using vp = vector<pair<int, int>>;
using vvi = vector<vector<int>>;
using vvc = vector<vector<char>>;
using vvll = vector<vector<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 (b<a) {a=b; return 1;} return 0;}

template<typename T>
struct BIT {
    int n;
    vector<T> d;
    BIT(int n=0) : n(n), d(n+1) {}

    void add(int i, T x=1) {
        for (i++; i <= n; i += i&-i) {
            d[i] += x;
        }
    }

    T sum(int i) {
        T res = 0;
        for (i++; i; i -= i&-i) {
            res += d[i];
        }
        return res;
    }
};

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    
    int n, q;
    string s;
    cin >> n >> s >> q;
    vector<BIT<int>> bt(26, BIT<int>(n));
    rep(i, n) bt[s[i] - 'a'].add(i, 1);
    while (q--) {
        int type;
        cin >> type;
        if (type == 1) {
            int i;
            char c;
            cin >> i >> c;
            i--;
            if (s[i] == c) continue;
            bt[c - 'a'].add(i, 1);
            bt[s[i] - 'a'].add(i, -1);
            s[i] = c;
        } else {
            int l, r;
            cin >> l >> r;
            l--; r--;
            int res = 0;
            rep(i, 26) {
                if (bt[i].sum(r) - bt[i].sum(l-1)) res++;
            }
            cout << res << endl;
        }
    }
}

Measured memory_bytes: 53660
#include <bits/stdc++.h>
#define be(v) (v).begin(),(v).end()
#define pb(q) push_back(q)
#define doublecout(a) cout<<fixed<<setprecision(10)<<a<<endl;
typedef long long ll;
using namespace std;
const ll mod=1000000007,mod9=1000000009;
template <class T>inline T lcm(T a,T b){return (a*b/__gcd(a,b));}

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll n,m;
    multiset<ll> ms;
    ll a;
    multiset<ll>::iterator itr;
    cin>>n>>m;
    for(int i=0;i<n;i++){
        cin>>a;
        ms.insert(a);   
    }
    for(int i=0;i<m;i++){
        itr=ms.end();
        itr--;
        a=*itr;
        ms.erase(itr);
        ms.insert(a/2);
    }
    ll sum=0;
    for(itr=ms.begin();itr!=ms.end();itr++){
        sum+=*itr;
    }
    cout << sum<<endl;
    return 0;
}



Measured memory_bytes: 4992
#include <iostream>
#include <string>
#include <vector>
#include <set>
#include <queue>
#include <stack>
#include <map>
#include <algorithm>
#include <math.h>
#include <cassert>
#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() {
  string s;
  cin >> s;
  int cnt[2] = {0,0};
  rep(i,s.size()){
    int c = s[i]-'0';
    if(c^(i&1)){
      cnt[0]++;
    }else{
      cnt[1]++;
    }
  }
  cout << min(cnt[0],cnt[1]) << endl;
}


Measured memory_bytes: 512
#include <bits/stdc++.h>
#include <unordered_map> 
using namespace std; 
#define FIO ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define PI1 3.14159265358979311599796346854418516159057617187500

typedef long long int ll;  
ll MOD = 1e9 + 7;

ll power(ll a , ll n)
{
    unsigned long long int result=1,x=a;
    while(n>0)
    {
        if(n % 2 ==1)
            result = (result * x)%MOD;
        x = (x * x)%MOD;
        n=n/2;
    }
    return result;
}

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


int main() 
{ 
    FIO
    int t;
    t=1;
    while(t--)
    {   
        int x,n;
        cin >> x >> n;
        
        if(n==0)
        {
            cout << x << endl;
            return 0;
        }
        
        map<int,int> mp;
        for(int i=0;i<n;i++)
        {
            int x;
            cin >> x;
            mp[x] = 1;
        }
        
        int tarl = x, tarh = x;
        
        while(1)
        {
            if(mp.find(tarl)==mp.end())
            {
                cout << tarl << endl;
                return 0;
            }
            tarl--;
            if(mp.find(tarh)==mp.end())
            {
                cout << tarh << endl;
                return 0;
            }
            tarh++;
        }

    }
    return 0; 
}


Measured memory_bytes: 3652
{-# LANGUAGE BangPatterns #-}
 
module Main
  ( main
  )
where
 
import           Control.Applicative
import           Control.Monad
import           Control.Monad.ST
import           Data.Bits
import qualified Data.ByteString.Char8         as BS
import           Data.Char
import           Data.List
import           Data.Maybe
import           Data.Ord
import qualified Data.Vector                   as V
import qualified Data.Vector.Mutable           as MV
import qualified Data.Vector.Unboxed           as UV

parse = fst . fromJust
parseInt = parse . BS.readInt
parseInteger = parse . BS.readInteger
readInt = parseInt <$> BS.getLine
readInteger = parseInteger <$> BS.getLine
readIntList = map parseInt . BS.words <$> BS.getLine
readIntegerList = map parseInteger . BS.words <$> BS.getLine


main = do
  name <- map head . words <$> getLine 
  putStrLn name


Measured memory_bytes: 508
<?php
  
fscanf(STDIN, "%d %d", $N, $K);
$p_array = trim(fgets(STDIN));
$p_array = explode(" ", $p_array);

sort($p_array);
$r = 0;
for ($i = 0;$i < $K;$i++) {
  $r += $p_array[$i];
  
}

echo $r;

Measured memory_bytes: 16224
#include <iostream>
#include <vector>
#include <algorithm>
#include <functional>
#include <string>
#include <set>
using namespace std;

int main(void) {
	int N;
	scanf("%d", &N);
	vector<int> A = vector<int>(N, 0);
	for (int i = 0; i < N; i++) {
		scanf("%d", &A[i]);
	}
	long long count = 0;

	if (A[N - 1] > N - 1) {
		printf("-1\n");
		return 0;
	}
	count += A[N - 1];
	for (int i = N - 2; i >= 0; i--) {
		if (A[i] > i) {
			printf("-1\n");
			return 0;
		}else if (A[i] < A[i + 1] - 1) {
			printf("-1\n");
			return 0;
		}
		else if (A[i] == A[i + 1] - 1) {
			continue;
		}
		else {
			count += A[i];
		}
	}

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

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

int main()
{
    int n,x,m=0,an=1;
    cin>>n>>x;
    int a[n];
    for(int i=0;i<n;i++) {cin>>a[i];m+=a[i];if(m<=x) an++;}
    cout<<an;
}


Measured memory_bytes: 256
import static java.lang.System.*;

import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;

public class Main{
	static Tree tree;
	static boolean[] visited;
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int q = sc.nextInt();
		tree = new Tree(n);
		for(int i = 0; i < n - 1; i++) {
			tree.union(sc.nextInt(), sc.nextInt());
		}
		for(int i = 0; i < q; i++) {
			tree.nodes[sc.nextInt()].score += sc.nextInt();
		}
		visited = new boolean[n + 1];
		visited[1] = true;
		dfs(1);
		
		for(int i = 1; i <= n; i++) {
			out.print(tree.nodes[i].score + " ");
		}
		
		
	}
	static void dfs(int n) {
		for(int i = 0; i < tree.nodes[n].list.size(); i++) {
			int m = tree.nodes[n].list.get(i);
			if (!visited[m]) {
				visited[m] = true;
				tree.nodes[m].score += tree.nodes[n].score;
				dfs(m);
			}
		}
	}
	
	static class Node{
		List<Integer> list = new ArrayList<>();
		int score = 0;
	}
	static class Tree{
		Node[] nodes;
		Tree(int n){
			nodes = new Node[n + 1];
			for(int i = 1; i <= n ; i++) {
				nodes[i] = new Node();
			}
		}
		void union(int a, int b) {
			nodes[a].list.add(b);
			nodes[b].list.add(a);
		}
	}
}



Measured memory_bytes: 217860
#include<cstdio>
#include<cstring>
bool visited[1005][1005];
int sx,sy,tx,ty;
int main()
{
    scanf("%d%d%d%d",&sx,&sy,&tx,&ty);
    memset(visited,false,sizeof(visited));
    int x,y;
    x=sx,y=sy;
    while(tx!=x||ty!=y)
    {
        if(y!=ty)
        {
            printf("U");
            y=y+1;
        }
        else
        {
            printf("R");
            x=x+1;
        }
    }
    while(sx!=x||sy!=y)
    {
        if(y!=sy)
        {
            printf("D");
            y=y-1;
        }
        else
        {
            printf("L");
            x=x-1;
        }
    }
    printf("L");
    x=x-1;
    while(x!=tx||y!=ty+1)
    {
        if(y!=ty+1)
        {
            printf("U");
            y=y+1;
        }
        else
        {
            printf("R");
            x=x+1;
        }
    }
    printf("D");
    y=y-1;
    printf("R");
    x=x+1;
    while(x!=sx||y!=sy-1)
    {
        if(y!=sy-1)
        {
            printf("D");
            y=y-1;
        }
        else
        {
            printf("L");
            x=x-1;
        }
    }
    printf("U");
    return 0;
}


Measured memory_bytes: 1152
#include <iostream>
#include <iomanip> // << fixed << setprecision(xxx)
#include <algorithm> // do { } while ( next_permutation(A, A+xxx) ) ;
#include <vector>
#include <string> // to_string(nnn) // substr(m, n) // stoi(nnn)
#include <complex>
#include <tuple> // get<n>(xxx)
#include <queue>
#include <stack>
#include <map> // if (M.find(key) != M.end()) { }
#include <set> // S.insert(M);
// if (S.find(key) != S.end()) { }
// for (auto it=S.begin(); it != S.end(); it++) { }
// auto it = S.lower_bound(M);
#include <random> // random_device rd; mt19937 mt(rd());
#include <cctype>
#include <cassert>
#include <cmath>
#include <cstdio>
#include <cstdlib> // atoi(xxx)
#include <valarray>
using namespace std;

#define DEBUG 0 // change 0 -> 1 if we need debug.
// insert #if<tab> by my emacs. #if DEBUG == 1 ... #end

typedef long long ll;

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

// const int C = 1e6+10;
// const ll M = 1000000007;

#define mattype long long

// 行列
struct matrix {
  int row, col;
  valarray<mattype> a;
  matrix(int N, int M) { // matrix A(N, M); で初期化できる。
    a = valarray<mattype>(N * M);
    row = N;
    col = M;
  }
  string to_s() const {
    string res = "";
    for (auto i=0; i<row; i++) {
      for (auto j=0; j<col; j++) {
        res += to_string(a[i*col+j]);
        if (j != col-1) res += " ";
      }
      if (i != row-1) res += "\n";
    }
    return res;
  }
};

ostream& operator<<(ostream& s, const matrix A) { // cout << A << endl; で苦もなく表示。
  return s << A.to_s();
}

mattype MOD = 1000000007; 

matrix mod_multiply(matrix A, matrix B) {
  assert(A.col == B.row);
  int N = A.col;
  matrix C(A.row, B.col);
  for (auto i=0; i<C.row; i++) {
    for (auto j=0; j<C.col; j++) {
      C.a[i*C.col + j] = ((valarray<mattype>)A.a[slice(i*A.col, N, 1)] *
                          (valarray<mattype>)B.a[slice(j, N, B.col)]).sum()%MOD;
    }
  }
  return C;
}

matrix mod_pow(matrix A, mattype n) { // n \geq 1
  if (n%2 == 0) {
    matrix B = mod_pow(A, n/2);
    return mod_multiply(B, B);
  } else if (n == 1) {
    return A;
  } else {
    return mod_multiply(A, mod_pow(A, n-1));
  }
}

int main () {
  int N, M;
  cin >> N >> M;
  int X[100010];
  for (auto i = 0; i < M; ++i) {
    cin >> X[i];
  }
  matrix A(3, 3);
  A.a = {2, 1, 1, 2, 1, 0, 1, 1, 1};
  matrix B(3, 3);
  B.a = {1, 0, 0, 2, 1, 0, 1, 1, 1};
  matrix C(3, 3);
  C.a = {1, 1, 1, 0, 0, 0, 0, 0, 0};
  matrix x(3, 1);
  x.a = {1, 0, 0};
  int cnt = 0;
  for (auto i = 0; i < M; ++i) {
    ll n = X[i] - 1 - cnt;
    if (n > 0) {
      x = mod_multiply(mod_pow(A, n), x);
      // cerr << "x = " << x << endl;
    }
    x = mod_multiply(B, x);
    // cerr << "x = " << x << endl;
    cnt = X[i];
  }
  int n = N - cnt - 1;
  if (n > 0) {
    x = mod_multiply(mod_pow(A, n), x);
  }
  x = mod_multiply(C, x);
  // cerr << "x = " << x << endl;
  cout << x.a[0] << endl;
}


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

#define rep(i, n) REP(i, 0, n)
#define ALL(v) v.begin(), v.end()
#define MSG(a) cout << #a << " " << a << endl;
#define REP(i, x, n) for (int i = x; i < n; i++)
#define OP(m) cout << m << endl
typedef long long ll;
typedef unsigned long long ull;

int main()
{
    int n, m;
    int mod = 1e9 + 7;
    cin >> n >> m;
    ll x[n], y[m];
    rep(i, n) cin >> x[i];
    rep(i, m) cin >> y[i];

    ll sumx = 0;
    rep(i, n)
    {
        sumx = sumx + ((i + 1 - n) * x[i] + i * x[i]) % mod;
    }
    ll sumy = 0;
    rep(i, m)
    {
        sumy = sumy + ((i + 1 - m) * y[i] + i * y[i]) % mod;
    }

    sumx %= mod, sumy %= mod;
    OP((sumx * sumy) % mod);
    return 0;
}

Measured memory_bytes: 1920
#include <bits/stdc++.h>
// #include <ext/pb_ds/assoc_container.hpp>
// #include <ext/pb_ds/tree_policy.hpp>
// #include <ext/pb_ds/detail/standard_policies.hpp>
// using namespace __gnu_pbds;
using namespace std;
using cd = complex<double>;
// template <typename T>
// using ordered_set = tree<T, null_type, less<T>, rb_tree_tag,
//     tree_order_statistics_node_update>;
 
// #pragma GCC optimize("Ofast")
// #pragma GCC target("avx,avx2,fma")
// #pragma GCC optimization ("unroll-loops")
typedef long long int ll;
typedef long double ld;
const ll N = 5e5+9;
// const ll m = 1e9 + 7;
// const ll inf= 1e14;
const ll mod =998244353;
const double PI = acos(-1);
#define x first
#define y second
#define pb push_back
#define mp make_pair
#define pii pair<ll,ll>
#define pld pair<ld,ld>
ll powm(ll a, ll b) { a = a%mod;ll res = 1; while (b) { if (b & 1) res = (res * a) % mod; a = (a * a) % mod; b >>= 1; } return res; }

int main() {
    ios::sync_with_stdio(false);
    cin.tie(NULL);
    #ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout); 
    #endif  
    int t = 1;
    // cin>>t;
    while(t--){
        ll a;cin>>a;
        ll b= a + a*a + a*a*a;
        cout<<b<<'\n';
    }
} 

Measured memory_bytes: 3636
#include <iostream>
#include <algorithm>
#include <bitset>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <cstring>
#include <utility>
#include <vector>
#include <complex>
#include <valarray>
#include <fstream>
#include <cassert>
#include <cmath>
#include <functional>
#include <iomanip>
#include <numeric>
#include <climits>
#include <random>

#define _overload(a, b, c, d, ...) d
#define _rep1(X, A, Y) for (int (X) = (A);(X) <= (Y);++(X))
#define _rep2(X, Y) for (int (X) = 0;(X) < (Y);++(X))
#define rep(...) _overload(__VA_ARGS__, _rep1, _rep2)(__VA_ARGS__)
#define rrep(X,Y) for (int (X) = Y-1;(X) >= 0;--(X))
#define all(X) (X).begin(),(X).end()
#define _size(X) (int)((X).size())
#define mod(n, m) (((n)%(m)+(m))%m)
#define fi first
#define sc second
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> Pii;
typedef pair<ll,ll> Pll;
const int INFINT = 1 << 30;                          // 1.07x10^ 9
const ll INFLL = 1LL << 60;                          // 1.15x10^18
const double EPS = 1e-10;
const int MOD = 1000000007;
const int dx[4] = {1, 0, -1, 0}, dy[4] = {0, 1, 0, -1};

const int MAX_N = 100;
int N;
int a[MAX_N+1];
const int MAX_V = MAX_N+2, INF = 1e9;
struct edge { ll to, cap, rev; };

vector<edge> G[MAX_V];
bool used[MAX_V];

void add_edge(int from, int to, ll cap) {
  G[from].push_back((edge){to, cap, (ll)G[to].size()});
  G[to].push_back((edge){from, 0, (ll)G[from].size() - 1});
}

int dfs(int v, int t, ll f) {
  if (v == t) return f;
  used[v] = true;
  for (int i = 0; i < G[v].size(); ++i) {
    edge &e = G[v][i];
    if (!used[e.to] && e.cap > 0) {
      int d = dfs(e.to, t, min(f, e.cap));
      if (d > 0) {
        e.cap -= d;
        G[e.to][e.rev].cap += d;
        return d;
      }
    }
  }
  return 0;
}

ll max_flow(int s, int t) {
  ll flow = 0;
  for (;;) {
    memset(used, 0, sizeof(used));
    ll f = dfs(s, t, INFLL);
    if (f == 0) return flow;
    flow += f;
  }
}

int main() {
  std::ios::sync_with_stdio(false);std::cin.tie(0);
  
  cin >> N;
  rep(i, 1, N) cin >> a[i];

  ll ans = 0;
  int s = 0, t = N+1;
  rep(i, 1, N) {
      if (a[i] >= 0) {
          add_edge(s, i, a[i]);
          ans += a[i];
      } else {
          add_edge(i, t, -a[i]);
      }
  }

  for (int i = 1; i <= N; ++i) {
      for (int j = 2; j*i <= N; ++j) {
          add_edge(j*i, i, INFLL);
      }
  }

  
  ans -= max_flow(s, t);

  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
int main(void)
{
	int N, K, i, min;
	cin >> N >> K;
	min = 1;
	for (i = 0; i < N; ++i)
    {
      if (min * 2 < min + K)
      {
        min *= 2;
      }
      else
      {
        min += K;
      }
    }
	cout << min << endl;
	return (0);
}

Measured memory_bytes: 3516
import java.util.Scanner;
public class Main { 
    public static void main(String[] args) { 
        Scanner sc = new Scanner(System.in);  
        while (true) { 
            int H = sc.nextInt(); 
            int W= sc.nextInt(); 
            if (H == 0 && W == 0) { 
                break; 
            } else {
                for (int i = 0 ; i < H ; i++){
                    for (int j = 0 ; j < W ; j++){
                        if (j == 0 || j == W-1){
                            System.out.printf("#");
                        } else if (i == 0 || i == H-1){
                            System.out.printf("#");
                        } else {
                            System.out.printf(".");
                        }
                    }
                    System.out.printf("\n");
                } 
                System.out.printf("\n");
            }
        } 
    }
}


Measured memory_bytes: 60040
/*
 root (x1-x2)^2 + (y1-y2)^2 = ((x1-x2) + (y1-y2))^2 - 2*(x1-x2)*(y1-y2)

 (x1-x2)*(y1-y2) = 0
 x1 = x2  
 or
 y1 = y2

 a = (x1 == x2)

 b = (y1 == y2)

 c = (x1==x2 && y1 == y2)

 c = c*(c-1)/2;


 a * b - c;
*/

#include<bits/stdc++.h>
using namespace std;
#define int int64_t
signed main(void)
{

   string s,t;
   cin>>s>>t;
   int n =s.length();int m =t.length();


   int dp[n+1][m+1];

   for(int i =0;i<=n;i++)
   {
   	for(int j =0;j<=m;j++)
   	{
   		if(i==0 || j==0)
   			dp[i][j]=0;
   		else if(s[i-1]==t[j-1])
   			dp[i][j] = dp[i-1][j-1]+1;
   		else
   			dp[i][j] = max(dp[i-1][j],dp[i][j-1]);
   	}

   }
   int index = dp[n][m];
   char lcs[index+1]; 
   lcs[index] = '\0'; // Set the terminating character 
  
   // Start from the right-most-bottom-most corner and 
   // one by one store characters in lcs[] 
   int i = n, j = m; 
   while (i > 0 && j > 0) 
   { 
      // If current character in X[] and Y are same, then 
      // current character is part of LCS 
      if (s[i-1] == t[j-1]) 
      { 
          lcs[index-1] = s[i-1]; // Put current character in result 
          i--; j--; index--;     // reduce values of i, j and index 
      } 
  
      // If not same, then find the larger of two and 
      // go in the direction of larger value 
      else if (dp[i-1][j] > dp[i][j-1]) 
         i--; 
      else
         j--; 
   } 
  
   // Print the lcs 
   cout<<lcs<<endl;

}



Measured memory_bytes: 70656
#include <iostream>
#include <vector>

#include <algorithm>
#include <cstdio>
using namespace std;

int main() {
  int h, w;

  while(cin >> h >> w) {
    if(h == 0 && w == 0) break;

    for(int i=0; i<h; i++) {
      for(int j=0; j<w; j++) {
        if((i%2==0 && j%2==0) || (i%2==1 && j%2==1)) printf("#");
        else printf(".");
      }
      printf("\n");
    }
    printf("\n");
  }
}

Measured memory_bytes: 1112
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <cmath>

using namespace std;

int main()
{
	int N;
	string S;

	cin >> N >> S;

	int ans = N;
	vector<int> w(N, 0), e(N, 0);

	for (int i = 0; i < N; i++)
	{
		if (S[i] == 'W')
		{
			w[i]++;
		}
		else
		{
			e[i]++;
		}
		
		if (i > 0)
		{
			w[i] += w[i - 1];
			e[i] += e[i - 1];
		}
	}

	ans = e[N - 1] - e[0];
	for (int i = 1; i < N; i++)
	{
		int count = w[i - 1] + e[N - 1] - e[i];

		if (count < ans)
		{
			ans = count;
		}
	}

	cout << ans << endl;

	return 0;
}


Measured memory_bytes: 3076
#include <bits/stdc++.h>
#define rep(i, start, end) for (long long i = start; i < end; ++i)
#define repreverse(i, start, end) for (long long i = start; i >= end; --i)
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define len(x) ((long long)(x).size())
#define lcm(a, b) ((a) / __gcd((a), (b)) * (b))
using namespace std;
using ll = long long;
using ld = long double;
using vll = vector<ll>;
using vllvll = vector<vll>;
using vc = vector<char>;
using pll = pair<ll, ll>;
template<class T> void print1d(T x,ll n=-1){if(n==-1)n=x.size();rep(i,0,n){cout<<x[i]<<' ';}cout<<'\n';}
template<class T> void print2d(T x,ll r=-1,ll c=-1){if(r==-1)r=x.size();if(c==-1)c=x[0].size();rep(i,0,r)print1d(x[i],c);}
template<class T, class U> bool haskey(T mp, U key) { return mp.find(key) != mp.end(); }
template<class T, class U> bool isin(T el, U container) { return find(all(container), el) != container.end(); }
template<class T> bool chmax(T& a, const T& b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> bool chmin(T& a, const T& b) { if (b < a) { a = b; return 1; } return 0; }
template<class T> bool even(T n) { return ! (n & 1); }
template<class T> bool odd(T n) { return n & 1; }
template<class T> ll rup(T a, T b) { return a % b ? a / b + 1 : a / b; }
template<class T> ld deg2rad(T deg) { return M_PI * deg / 180.0; }
template<class T> ld rad2deg(T rad) { return 180.0 * rad / M_PI; }
const long double pi = M_PI;
const long long big = 1LL << 50;
const long long inf = 1LL << 60;
const long long mod = 1e9 + 7;
ll intpow(ll a, ll n, ll _mod=numeric_limits<ll>::max()) { ll p=1; while (n) { if (n&1) p=p*a%_mod; a=a*a%_mod; n>>=1; } return p; } 
ll modc(ll a, char op, ll b, ll _mod=mod) { a %= _mod; b %= _mod; ll res = 1; switch(op) {
        case '+': res = (a + b) % _mod; break;
        case '-': res = (a - b) % _mod; break;
        case '*': res = a * b % _mod; break;
        case '/': res = modc(a, '*', modc(b, '^', _mod-2, _mod), _mod); break;
        case '^': res = intpow(a, b, _mod); break;
        case 'P': rep(i, a-b+1, a+1) res = modc(res, '*', i, _mod); break;
        case 'C': res = modc(modc(a, 'P', b, _mod), '/', modc(b, 'P', b, _mod)); break; } if (res < 0) res += _mod; return res; }


int main()
{
        ll N;
        cin >> N;
        ll ans = (N-1) / 2;
        cout << ans << endl;
}


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

const ll mod = 1e9+7;
const ll INF = 1e18;
const double pi = acos(-1.0);

int main(void)
{
    ll h,w; cin>>h>>w;
    vector<string> s(h);
    rep(i,h) cin>>s[i];
    rep(i,h){
        if(i==0){
            rep(j,w+2) cout<<"#";
            cout<<endl;
        }
        cout<<"#"<<s[i]<<"#"<<endl;
    }
    rep(j,w+2) cout<<"#";
    cout<<endl;
    return 0;
}

Measured memory_bytes: 3532
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int a[3];
    int i;
    int k=0;
    for(i=0;i<3;i++)
    {
        cin>>a[i];
    }
    int j;
    for(i=0;i<3;i++)
    {
        for(j=i+1;j<3;j++)
        {
            if(a[i]==a[j])
            {
                k++;
            }
        }
        //cout<<"K = "<<k<<endl;
    }
    if(k>0 && k<=2)
    {
        cout<<"Yes"<<endl;
    }
    else
        cout<<"No"<<endl;
    return 0;
}


Measured memory_bytes: 256
#include <stdio.h>

int main()
{
    int a = 0;
    int b = 0;
    
    scanf("%d%d",&a,&b);
    
    if(a < b){
        printf("a < b\n");
    }
    if(a > b){
        printf("a > b\n");
    }
    
    if(a == b){
        printf("a == b\n");
    }
    
    return 0;
}


Measured memory_bytes: 2052
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#define IO(i, o) freopen(i, "r", stdin), freopen(o, "w", stdout)
#define MOD 1000000007;

using namespace std;
using namespace __gnu_pbds;
//typedef tree<TYPE, null_type, less<TYPE>, rb_tree_tag, tree_order_statistics_node_update> indexed_set;
//typedef tree<TYPE, null_type, less_equal<TYPE>, rb_tree_tag, tree_order_statistics_node_update> indexed_multiset;

int a, b, c;

int main(){
	//IO("input.txt", "output.txt");
	ios::sync_with_stdio(false);
	cin.tie(NULL);
	cin >> a >> b >> c;
	if(a + b + c >= 22) cout << "bust\n";
	else cout << "win\n";
	return 0;
}

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

int main(){
    int n;
    cin >> n;
    string s,t = "";
    int wr = 0,rw = 0;
    for(int i = 0;i < n;i++) t += 'R';
    cin >> s;
    for(int i = 0;i < n;i++){
        if(s[i]=='W' && t[i] == 'R') wr++;
    }
    int minm = wr;
    for(int i = n-1;i >= 0;i--){
        if(s[i] == 'R'){
            rw++;
        }
        if(s[i] == 'W'){
            wr--;
        }
        minm = min(minm,max(rw,wr));
    }
    cout<<minm<<"\n";
}

Measured memory_bytes: 3928
#include <stdio.h>

int main(void){
    int n, k;
    int p[200001];
    int i,sum,summax;
    scanf("%d %d", &n, &k);
    
    for(i = 0; i < n; i++){
        scanf("%d", &p[i]);
    }
    
    sum = 0;
    for(i = 0; i < k; i++){
        sum += p[i];
    }
    summax = sum;
    for(i = k; i < n; i++){
        sum += (p[i] - p[i-k]);
        if(summax < sum){
            summax = sum;
        }
    }
    
    printf("%f", (double)(summax + k)/2);
    
    return 0;
}

Measured memory_bytes: 1024
#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<string>
#include<cmath>
#include<algorithm>
#include<queue>
#include<vector>
#include<map>
#include<set>
using namespace std;
#define N 1005
#define mod 1000000007
#define ll long long
#define db double
#define dbg1(x) cout<<#x<<"="<<x<<" "
#define dbg2(x) cout<<#x<<"="<<x<<"\n"
int n,m,ecnt,last[N],f[N],cnt1,cnt2,mark[N<<1],fa[N][15],Max[N][15],deep[N],ans;ll K,Sum;
struct edge 
{
	int fr,to,v;
	friend bool operator<(edge t1,edge t2) {return t1.v<t2.v;}
}E[N<<1];
struct road{int to,v,nex;}e[N<<1];
void adde(int u,int v,int w) {e[++ecnt]=(road){v,w,last[u]},last[u]=ecnt;}
int find(int x) {return f[x]^x?f[x]=find(f[x]):x;}
int Pow(int x,int y)
{
	int res=1;
	for(;y;y>>=1,x=(ll)x*x%mod) if(y&1) res=(ll)res*x%mod;
	return res;
}
void dfs(int x,int fath=0)
{
	fa[x][0]=fath,deep[x]=deep[fath]+1;
	for(int k=last[x];k;k=e[k].nex)
		if(e[k].to^fath) Max[e[k].to][0]=e[k].v,dfs(e[k].to,x);
}
int ask(int x,int y)
{
	if(deep[x]<deep[y]) swap(x,y);
	int res=0;
	for(int j=14;~j;j--)
		if(deep[x]-(1<<j)>=deep[y]) res=max(res,Max[x][j]),x=fa[x][j];
	if(x==y) return res;
	for(int j=14;~j;j--)
		if(fa[x][j]^fa[y][j]) res=max(res,max(Max[x][j],Max[y][j])),x=fa[x][j],y=fa[y][j];
	return max(res,max(Max[x][0],Max[y][0]));
}
int main()
{
	scanf("%d%d%lld",&n,&m,&K);
	for(int i=1;i<=m;i++) scanf("%d%d%d",&E[i].fr,&E[i].to,&E[i].v);
	sort(E+1,E+1+m);
	for(int i=1;i<=n;i++) f[i]=i;
	for(int i=1,cnt=0,f1,f2;i<=m&&cnt<n-1;i++)
	{
		f1=find(E[i].fr),f2=find(E[i].to);
		if(f1^f2)
		{
			f[f1]=f2,Sum+=E[i].v,cnt++,mark[i]=1;
			adde(E[i].fr,E[i].to,E[i].v),adde(E[i].to,E[i].fr,E[i].v);
		}
	}
	if(Sum>K) return !puts("0");
//	dbg1(Sum),dbg2(K);
	K-=Sum,dfs(1);
	for(int j=1;j<15;j++)
		for(int i=1;i<=n;i++)
			fa[i][j]=fa[fa[i][j-1]][j-1],Max[i][j]=max(Max[i][j-1],Max[fa[i][j-1]][j-1]);
	for(int i=1,res;i<=m;i++)
		if(!mark[i])
		{
			res=ask(E[i].fr,E[i].to);
			if(E[i].v-res==K) cnt1++;
			else if(E[i].v-res>K) cnt2++; 
		}
//	dbg1(cnt1),dbg2(cnt2);
	ans=2ll*(Pow(2,cnt1)-1)*Pow(2,cnt2)%mod;
	if(!K) ans+=(ll)(Pow(2,n-1)-2+mod)*Pow(2,m-n+1)%mod,ans-=ans<mod?0:mod;
	printf("%d\n",ans);
	return 0;
}

Measured memory_bytes: 512
#include <iostream>
#include <string>
#include <vector>
#include <map>
#include <algorithm>
#include <cmath>
#include <sstream>
#include <iomanip>
#include <set>
using namespace std;
typedef long long int ll;

#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define YES cout << "YES" << endl
#define Yes cout << "Yes" << endl
#define yes cout << "yes" << endl
#define NO cout << "NO" << endl
#define No cout << "No" << endl
#define no cout << "no" << endl

const int INF = 1001001001;
const int mod = 1000000007;
#define PI 3.14159265359;

void P(int x) {cout << x << endl;}
void P(long x) {cout << x << endl;}
void P(double x) {cout << x << endl;}
void P(ll x) {cout << x << endl;}
void P(string x) {cout << x << endl;}
void P(char x) {cout << x << endl;}

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

int main() {
  int n, i;
  cin >> n >> i;
  P(n - i + 1);
  return 0;
}



Measured memory_bytes: 256
import math

a, b, h, m = map(int, input().split())

d = h * 30
if d / 5.5 > m:
    d -= 5.5 * m
else:
     d = 5.5 * m - d 

# print(d)

if d == 180:
    print(a + b)
elif d == 0:
    if a > b:
        a, b = b, a
    print(b - a)
else:
    print(math.sqrt(a ** 2 + b ** 2 - 2 * a * b * math.cos(math.radians(d))))

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

#define INF 1001001001
#define LINF 1001001001001001001
#define MOD 1000000007
#define MOD2 998244353

template<class T,class U>bool chmax(T &a, const U &b){if(a<b){a=b;return 1;}return 0;}
template<class T,class U>bool chmin(T &a, const U &b){if(b<a){a=b;return 1;}return 0;}

#define rep(i,n) for(int i=0,_i=(n);i<_i;++i)
#define rep1(i,a,b) for(int a_=(a),b_=(b),i=a_;i<b_;++i)
#define repr(i,n) for(int _i=(n),i=_i;i>0;--i)

#define db(x) cerr<<#x<<" = "<<x<<" ";
#define db2(x,y) cerr<<"("<<#x<<", "<<#y<<") = ("<<x<<", "<<y<<") ";
#define db3(x,y,z) cerr<<"("<<#x<<", "<<#y<<", "<<#z<<") = ("<<x<<", "<<y<<", "<<z<<") ";
#define ln cout<<endl;

#define all(a)  (a).begin(),(a).end()
#define dig(n)  to_string(n).length()

#define pb push_back
#define eb emplace_back
#define mp make_pair
#define se second
#define fi first

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

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

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

int main(){
    bool flag=false;
    ll ans=0,sum=0;

    int a,b;
    cin >>a>>b;

    if(a > b){
        rep(i,a)cout<<b;
    }else{
        rep(i,b)cout<<a;
    }

    //cout <<fixed<<setprecision(16)<< << endl;
    //cout<<ans<<endl;
    //if(flag)cout << "Yes" <<endl;
    //else cout << "No" <<endl;
    
    return 0;
}


Measured memory_bytes: 256
Bi=[]
for i in range(3):
    a=list(map(int,input().split()))
    Bi.append(a)

n=int(input())
b=[]
for i in range(n):
    v=int(input())
    b.append(v)

if Bi[0][0] in b:
    if Bi[0][1] in b:
        if Bi[0][2] in b:
            print("Yes")
            exit()

if Bi[1][0] in b:
    if Bi[1][1] in b:
        if Bi[1][2] in b:
            print("Yes")
            exit()
if Bi[2][0] in b:
    if Bi[2][1] in b:
        if Bi[2][2] in b:
            print("Yes")
            exit()

if Bi[0][0] in b:
    if Bi[1][0] in b:
        if Bi[2][0] in b:
            print("Yes")
            exit()

if Bi[0][1] in b:
    if Bi[1][1] in b:
        if Bi[2][1] in b:
            print("Yes")
            exit()
if Bi[0][2] in b:
    if Bi[1][2] in b:
        if Bi[2][2] in b:
            print("Yes")
            exit()

if Bi[0][0] in b:
    if Bi[1][1] in b:
        if Bi[2][2] in b:
            print("Yes")
            exit()

if Bi[0][2] in b:
    if Bi[1][1] in b:
        if Bi[2][0] in b:
            print("Yes")
            exit()

print("No")

Measured memory_bytes: 3188
#include <bits/stdc++.h>
#define mod 1000000007
#define mod998 998244353
#define sp ' '
#define intmax 2147483647
#define llmax 9223372036854775807
#define mkp make_pair
typedef long long ll;
using namespace std;

string S;
ll K;

int main() {
	cin >> S >> K;
	bool f = true;
	for (int i = 0; i < S.size() - 1; ++i) {
		if (S[i] != S[i + 1]) {
			f = false;
			break;
		}
	}
	if (f) {
		cout << K*S.size() / 2 << endl;
	}
	else {
		ll p = 0, q = 0;
		f = false;
		for (int i = 1; i < S.size(); ++i) {
			if (S[i] == S[i - 1] && !f) {
				f = true;
				++p;
			}
			else {
				f = false;
			}
		}
		string T;
		T = S + S;
		f = false;
		for (int i = 1; i < T.size(); ++i) {
			if (T[i] == T[i - 1] && !f) {
				f = true;
				++q;
			}
			else {
				f = false;
			}
		}
		cout << p + (K - 1)*(q - p) << endl;
	}
}

Measured memory_bytes: 764
import java.util.Scanner
import scala.io.StdIn._

object Main extends App {

  val k = readInt()
  val Array(a, b) = readLine().split(" ").map(_.toInt)


  def solve(): String = {
    (a to b).foreach(i => if(i % k == 0) return "OK")
    "NG"
  }

  println(solve())

}



Measured memory_bytes: 54784
// In The Name Of Allah
#include <bits/stdc++.h>
using namespace std;
const long long inf = 1e10;
typedef long long ll;
typedef long double ld;
typedef pair <ll, ll> pii;
const ll mod = 1e9 + 7;

 
void faster()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
}

const ll M = 500 + 10;
const ll N = 100 * 1000 + 10;

vector <pair <char, char>> tc;

int main()	
{
	faster();
	int n, q;
	string s;
	cin >> n >> q >> s;
	for (int i = 0; i < q; i++)
	{
		char a, b;
		cin >> a >> b;
		tc.push_back({a, b});
	}
	int low = -1, high = n;
	for (int p = 0; p < 80; p++)
	{
		int mid = (low + high) / 2;
		int pos = mid;
		bool is_val = true, vulvul = false;
		for (int i = 0; i < q; i++)
		{
			char a = tc[i].first, b = tc[i].second;
			if(s[pos] == a && b == 'R')
			{
				pos++;
			}
			else if(s[pos] == a)
			{
				pos--;
			}
			if(pos == n)
			{
				is_val = false;
				break;
			}
			if(pos == -1)
			{
				vulvul = true;
				break;
			}
		}
		if(!is_val || !vulvul)
		{
			high = mid;
		}
		else
		{
			low = mid;
		}
	}
	int ans = low + 1;
	if(low == n)
		ans = 0;
	low = -1, high = n;
	for (int p = 0; p < 80; p++)
	{
		int mid = (low + high) / 2;
		int pos = mid;
		bool is_val = true, vulvul = false;
		for (int i = 0; i < q; i++)
		{
			char a = tc[i].first, b = tc[i].second;
			if(s[pos] == a && b == 'R')
			{
				pos++;
			}
			else if(s[pos] == a)
			{
				pos--;
			}
			if(pos == n)
			{
				vulvul = true;
				break;
			}
			if(pos == -1)
			{
				is_val = false;
				break;
			}
		}
		if(!is_val || !vulvul)
		{
			low = mid;
		}
		else
		{
			high = mid;
		}
	}
	cout << high - ans << endl;
}


Measured memory_bytes: 1100
#include <iostream>
  #include <string>
  #include <vector>
  #include <algorithm>
  #include <queue>
  using namespace std;
  typedef long long ll;
  #define rep(i,n) for (int i=0;i < (int)(n);i++)
  const int INF = 10010010;
  
  int main(){
    int n,x,y;
    cin >> n >> x >> y;
    x--;y--;
    vector<int> ans(n);
    rep(sv,n){
      queue<int> q;
      vector<int> dist(n,INF);
      auto push = [&](int v,int d){
        if (dist[v] != INF) return;
        dist[v] = d;
        q.push(v);
      };
      push(sv,0);
      while(!q.empty()){
        int v =q.front();q.pop();
        int d = dist[v];
        if (v-1 >= 0) push(v-1,d+1);
        if (v+1  < n) push(v+1,d+1);
        if (v==x) push(y,d+1);
        if (v==y) push(x,d+1);
      }
      //printf("sv = %d\n",sv);
      //rep(j,n){
      //  cout << dist[j];
      //}
      //printf("\n");

      rep(i,n) ans[dist[i]]++;
      //rep(h,n){
      //  cout << ans[h];
      //}
      //printf("\n");
    }
    rep(i,n) ans[i]/=2;
    for (int i=1;i <= n-1;i++){
      cout << ans[i] << endl;
    }
    return 0;
  }

Measured memory_bytes: 256
import java.util.*;

public class Main {
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        while(true){
            int n = sc.nextInt();
            if(n==0) break;
            int sum = 0;
            int max = 0;
            int min = 1000;
            for(int i = 0; i<n; i++){
                int in = sc.nextInt();
                sum+=in;
                if(max<in) max = in;
                if(min>in) min = in;
            }
            sum -= (min+max);
            sum /= n-2;
            System.out.println(sum);
        }
        sc.close();
    }
}
    


Measured memory_bytes: 29140
#include <bits/stdc++.h>
typedef long long int ll;
using namespace std;
const ll mod=1e9+7;
ll powmod(ll a,ll b) {ll res=1;a%=mod; assert(b>=0); for(;b;b>>=1){if(b&1)res=res*a%mod;a=a*a%mod;}return res;}
ll gcd(ll a,ll b) { return b?gcd(b,a%b):a;}
vector<ll>v;
int main(){
    ll n;
    cin>>n;
    ll k;
    cin>>k;
    vector<ll>dp(n,1e9);
    for(ll i=0;i<n;i++){
        ll s;
        cin>>s;
        v.push_back(s);
    }
    if(n==1){
        cout<<0<<endl;
        return 0;
    }
    for(ll i=0;i<n;i++){
        if(i==0){
            dp[i]=0;
        }
        else if(i==1){
            dp[i]=abs(v[i]-v[i-1]);
        }
        else{
            for(ll j=1;j<=k;j++){
                if(i-j<0)break;
                dp[i]=min(dp[i],dp[i-j]+abs(v[i]-v[i-j]));
            }
        }
    }
    cout<<dp[n-1]<<endl;
    return 0;

    }


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

using namespace std;

typedef long long ll;

const ll INF = 10000000000000;

int main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	int n;
	ll x;
	cin >> n >> x;
	vector<ll> a(n);
	for (int i = 0; i < n; i++) cin >> a[i];
	vector< vector<ll> > memo(n, vector<ll>(n));
	for (int i = 0; i < n; i++) {
		for (int j = 0; j < n; j++) {
			if (j == 0) memo[i][j] = a[i];
			else memo[i][j] = min(memo[i][j - 1], a[(i - j + n) % n]);
		}
	}
	ll ans = INF;
	for (int i = 0; i < n; i++) {
		ll tmp = x * i;
		for (int j = 0; j < n; j++) {
			tmp += memo[j][i];
		}
		ans = min(ans, tmp);
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 31616
#include<iostream>
using namespace std;
int main(){
	for (;;){
		int H;
		int W;
		cin >> H >> W;
		if (H == 0 && W == 0){
			return 0;
		}
		else{
			for (int a = 0; a < H; a++){
				for (int b = 0; b < W; b++){
					cout << "#";
				}
				cout << endl;
			}
		}cout << endl;
	}
}

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

ans = "Yes"
for i in range(len(l)):
    s = 0
    for j in range(len(l)):
        if not j == i:
            s += l[j]
    if l[i] >= s:
        ans = "No"
        break
print(ans)


Measured memory_bytes: 3060
#include <limits.h>
#include <math.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

#include <algorithm>
#include <cassert>
#include <cfloat>
#include <complex>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <regex>
#include <set>
#include <stack>
#include <string>
#include <unordered_map>
#include <vector>

using namespace std;

#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)
#define rep(i, n) for (ll i = 0; i < (n); ++i)
#define repLRE(i, l, r) for (ll i = (l); i <= (r); ++i)
#define rrepLRE(i, l, r) for (ll i = (l); i >= (r); --i)
#define Sort(v) sort(v.begin(), v.end())
#define rSort(v) sort(v.rbegin(), v.rend())
#define Reverse(v) reverse(v.begin(), v.end())
#define Lower_bound(v, x) \
  distance(v.begin(), lower_bound(v.begin(), v.end(), x))
#define Upper_bound(v, x) \
  distance(v.begin(), upper_bound(v.begin(), v.end(), x))

using ll = long long;
using ull = unsigned long long;
using P = pair<ll, ll>;
using T = tuple<ll, ll, ll>;
using vll = vector<ll>;
using vP = vector<P>;
using vT = vector<T>;
using vvll = vector<vector<ll>>;
using vvP = vector<vector<P>>;
using dqll = deque<ll>;

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

/* Macros reg. ends here */

const ll INF = 1LL << 50;
static const long long mod = 1000000007;

int main() {
  cout << fixed << setprecision(15);

  ll n;
  cin >> n;

  ll ans = 0;
  repLRE(i, 1, n){
    ll k = n/i;
    ans += i*k*(k+1)/2;
  }

  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 3576
import java.util.Scanner;

public class Main {
	public static void main(String[] args) throws Exception {
        Scanner sc = new Scanner(System.in);
        Main m = new Main(sc);
        m.show(m.solve());
        sc.close();
    }
    
	//フィールド
    Scanner sc;
    String S;
    
    //入力
    Main(Scanner sc) {
        this.sc = sc;
        this.S = sc.next();
    }
    
    //解答処理
    private int solve() {
        int answer = 0;
        int count = 0;
        
        for (int i=0; i<S.length()-1; i++) {
        	if (S.charAt(i)=='R' || S.charAt(2)=='R') {
        		answer = 1;
        	}
        	if (S.charAt(i)=='R'&&S.charAt(i+1)=='R') {
        		count++;
        	}
        }
        
        if (count==1) {
        	answer = 2;
        }else if (count==2){
        	answer = 3;
        }
        return answer;
    }
    
    //出力
    public void show(int answer) {
        System.out.println(answer);
    }

}


Measured memory_bytes: 35520
import math


def calc_minutes(h, m):
    return 60 * h + m


def to_angle_minutes(h, m):
    minutes = calc_minutes(h, m)

    minutes_角度 = minutes / 60

    shousu = math.modf(minutes_角度)[0]

    angle_minutes = 360 * shousu

    return angle_minutes


def to_angle_hours(h, m):
    minutes = calc_minutes(h, m)

    hours_角度 = minutes / 720

    shousu = math.modf(hours_角度)[0]

    angle_hours = 360 * shousu

    return angle_hours


def to_cosC(angle_hours, angle_minutes):
    C = abs(angle_hours - angle_minutes)
    C_rad = math.radians(C)
    cosC = math.cos(C_rad)

    return cosC


def actual(a, b, h, m):
    angle_hours = to_angle_hours(h, m)
    angle_minutes = to_angle_minutes(h, m)

    cosC = to_cosC(angle_hours, angle_minutes)

    c = math.sqrt(a ** 2 + b ** 2 - 2 * a * b * cosC)

    return c
  
a, b, h, m = map(int, input().split())

print(actual(a, b, h, m))

Measured memory_bytes: 9692
#include "bits/stdc++.h"
using namespace std;
int main() {
	int N, L;
	cin >> N >> L;
	vector<string>A(N);
	for (int i = 0; i < N; i++) {
		cin >> A.at(i);
	}
	sort(A.begin(), A.end());
	for (int i = 0; i < N; i++)
	{
		cout << A.at(i);
	}
	cout << endl;
}

Measured memory_bytes: 256
input1 = input().split()
input2 = list(map(int,input().split()))
input3 = list(map(int,input().split()))
N = int(input1[0])
M = int(input1[1])
X = int(input1[2])
Y = int(input1[3])
max2 = max(input2)
min3 = min(input3)

OK = 0
for Z in range(-100,100+1):
    if X < Z <= Y and max2 < Z and min3 >= Z :
        OK = 1
    else :
        pass

if OK == 1 :
    print("No War")
else :
    print("War")


Measured memory_bytes: 3064
#include <iostream>

int main(){
	int n;
	while( std::cin >> n, n ){
		int sum_pt[2] = { 0, 0 };
		int pt[2];

		while( n-- ){
			std::cin >> pt[0] >> pt[1];

			if( pt[0] > pt[1] ){
				sum_pt[0] += pt[0] + pt[1];
			}else if( pt[0] < pt[1] ){
				sum_pt[1] += pt[0] + pt[1];
			}else{
				sum_pt[0] += pt[0];
				sum_pt[1] += pt[1];
			}
		}

		std::cout << sum_pt[0] << " " << sum_pt[1] << std::endl;
	}

	return 0;
}

Measured memory_bytes: 1160
#include <iostream>
#include <string>
#include <algorithm>
#include <cmath>
#include <functional>
#include <vector>
#define nmax_def 110000
using namespace std;
typedef long long ll;

int main() {
	int i, j;
	int N, A[nmax_def], x[nmax_def], y[nmax_def];
	int Pcount = 0, Mcount = 0;
	int ans = 0;
	int count;
	cin >> N;
	for (i = 0; i < N; i++)
	{
		cin >> A[i];
		if (A[i] > 0)
		{
			Pcount++;
		}
		else if (A[i] < 0)
		{
			Mcount++;
		}
	}
	if (N == 2)
	{
		x[0] = max(A[0], A[1]);
		y[0] = min(A[0], A[1]);
		ans = x[0] - y[0];
	}
	else
	{
		sort(A, A + N, greater<int>());
		if (Pcount == N)
			Pcount--;
		else if (Pcount == 0)
		{
			swap(A[0], A[N - 1]);
		}

		x[0] = A[N - 1];
		y[0] = A[0];
		if (Pcount == 1)
			swap(x[0], y[0]);
		else if (Pcount == 0)
		{
			Pcount++;
		}
		for (i = 1; i < N - 1; i++)
		{
			x[i] = x[i - 1] - y[i - 1];
			y[i] = A[i];
			if (i == Pcount - 1)
				swap(x[i], y[i]);
		}
		ans = x[N - 2] - y[N - 2];
	}
	cout << ans << endl;
	for (i = 0; i < N - 1; i++)
		cout << x[i] << " " << y[i] << endl;
	return 0;
}

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


int main(){
    int n, k;
    cin >> n >> k;
    vector<double> c(n+1);
    c.at(0) = 1;
    for(int i = 1; i <= n; i++){
        //double p_i = 1 / double(n);
        int T;
        if(double(k)/double(i) > 1.0)
            T = int(log2(double(k)/double(i))-0.00000000001) + 1;
        else
            T = 0;
        //cout << T << endl;
        //cout << i << endl;
        //coinで表が出続ける確率
        //long double p_s = pow(0.5, double(T));
        double t = double(T);
        double c_num = pow(2.0, t);
        c.at(i) = c_num;
    }
    double cmax = c.at(1);
    //for(int i = 2; i <= n; i++){
    //    if(cmax < c.at(i)) cmax = c.at(i);
    //}
    double count = 0;
    for(int i = 1; i <= n; i++){
        count += cmax / c.at(i);
    }
    double N = double(n);
    //double P = count / (cmax * N);
    cout << setprecision(12) << count / (cmax * N) << endl;
}

Measured memory_bytes: 1024
"use strict";
    
const main = arg => {
    arg = arg.trim().split("\n");
    const N = parseInt(arg[0]);
    const S = arg.slice(1, N + 1).map(s=>s.split(""));
    
    const map = {};
    let answer = 0;
    
    // Sを辞書順ソートする
    S.forEach(s => {
        s.sort();
        let temp = s.join("");
        
        if(map[temp]) {
            answer += map[temp];
            map[temp]++;
        } else {
            map[temp] = 1;
        }
    })
    
    console.log(answer);
}
main(require('fs').readFileSync('/dev/stdin', 'utf8'));

Measured memory_bytes: 73960