akhauriyash/Code-Regression huggingface dataset:
import java.util.*; 
class Main{
    public static void main(String[] args){
        Scanner stdIn = new Scanner(System.in);
        int a[] = new int[3];
        int num;
        int min;

        for(int i=0;i<3;i++){
            a[i] = stdIn.nextInt();
        }

        for(int i=0;i<3;i++){
            min = a[i];
            num = i;
            for(int j=i+1;j<3;j++){
                if(min>a[j]){
                    min = a[j];
                    num = j;
                }
            }
            if(num != i){
                a[num] = a[i];
                a[i] = min;
            }
        }
        System.out.println(a[0]+" "+a[1]+" "+a[2]);
    }
}


Measured memory_bytes: 26288
#include<bits/stdc++.h>
typedef long long int ll;
typedef unsigned long long int ull;
#define BIG_NUM 2000000000
#define MOD 1000000007
#define EPS 0.000000001
using namespace std;


int main(){

	int A,B,C;
	scanf("%d %d %d",&A,&B,&C);

	printf("%d %d\n",min(A,min(B,C)),max(A,max(B,C)));

	return 0;
}




Measured memory_bytes: 3204
import sys, os, math, bisect, itertools, collections, heapq, queue
# from scipy.sparse.csgraph import csgraph_from_dense, floyd_warshall
from decimal import Decimal
from collections import defaultdict, deque

# import fractions

sys.setrecursionlimit(10000000)

ii = lambda: int(sys.stdin.buffer.readline().rstrip())
il = lambda: list(map(int, sys.stdin.buffer.readline().split()))
fl = lambda: list(map(float, sys.stdin.buffer.readline().split()))
iln = lambda n: [int(sys.stdin.buffer.readline().rstrip()) for _ in range(n)]

iss = lambda: sys.stdin.buffer.readline().decode().rstrip()
sl = lambda: list(map(str, sys.stdin.buffer.readline().decode().split()))
isn = lambda n: [sys.stdin.buffer.readline().decode().rstrip() for _ in range(n)]

lcm = lambda x, y: (x * y) // math.gcd(x, y)
# lcm = lambda x, y: (x * y) // fractions.gcd(x, y)

MOD = 10 ** 9 + 7
MAX = float('inf')


def main():
    if os.getenv("LOCAL"):
        sys.stdin = open("input.txt", "r")

    K, X = il()
    print(*range(X-K+1, X+K))


if __name__ == '__main__':
    main()


Measured memory_bytes: 10192
a=input()
b=input()

if len(a)>len(b):
    print("GREATER")
elif len(a)<len(b):
    print("LESS")
else:
    for i in range(len(a)):
        if int(a[i])>int(b[i]):
            print("GREATER")
            exit()
        elif int(a[i])<int(b[i]):
            print("LESS")
            exit()
    print("EQUAL")

Measured memory_bytes: 3064
import sys
import math
import bisect
import re

def solve(n, a, b):
    if a > b:
        a, b = (b, a)
    if (b - a) % 2 == 0:
        return (b - a) // 2
    if a == 1:
        return 1 + solve(n, a, b - 1)
    if b == n:
        return 1 + solve(n, a + 1, b)
    delta = b - a
    val1 = (a - 1) + solve(n, 1, 1 + delta)
    val2 = (n - b) + solve(n, n - delta, n)
    return min(val1, val2)

def main():
    n, a, b = map(int, input().split())
    ans = solve(n, a, b)
    print(ans)

if __name__ == "__main__":
    main()


Measured memory_bytes: 3316
#include<bits/stdc++.h>
#define ll long long int
#define ull unsigned long long 
#define ff first
#define ss second
#define fast ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define pb push_back 
#define mp make_pair
#define inf 2000000009
#define mod 1000000007
using namespace std;

int main()
{
    fast;
  
   ll n,a[2];
   cin>>n;
   for(ll i=0;i<2;i++)
    cin>>a[i];

  sort(a,a+2);
  ll diff=a[1]-a[0];

  if(diff%2==0)
    cout<<diff/2;

  else
   {
    ll x=a[0]-1;
    ll y= a[1]-x-1;
    ll z=(y-1)/2;

    ll q=n-a[1];
    ll r= a[0]+q+1;
    ll qq=(n-r)/2;

    cout<<min(min(a[1]-1,n-a[0]),min(x+1+z,qq+1+q))<<endl;
   }

  }

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

int main() {
  int A[101];
    for (int i=0 ; i<101 ;i++){
      A[i]=0 ;
    }
  int a ,b , c ;
  cin >> a >> b >> c ;
  A[a] = 1;
  A[b] =1 ;
  A[c]=1;
  int count =0;
  for (int i=0 ; i<101 ;i++){
    if ( A[i]==1){
      count++;
    }
  }
    cout << count << endl;
}

Measured memory_bytes: 3564
#include "bits/stdc++.h"
using namespace std;
#ifdef _DEBUG
#include "dump.hpp"
#else
#define dump(...)
#endif

//#define int long long
#define rep(i,a,b) for(int i=(a);i<(b);i++)
#define rrep(i,a,b) for(int i=(b)-1;i>=(a);i--)
#define all(c) begin(c),end(c)
const int INF = sizeof(int) == sizeof(long long) ? 0x3f3f3f3f3f3f3f3fLL : 0x3f3f3f3f;
const int MOD = (int)(1e9) + 7;
const double PI = acos(-1);
const double EPS = 1e-9;
template<class T> bool chmax(T &a, const T &b) { if (a < b) { a = b; return true; } return false; }
template<class T> bool chmin(T &a, const T &b) { if (a > b) { a = b; return true; } return false; }

signed main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	int N; cin >> N;
	vector<int> v(N); rep(i, 0, N) { cin >> v[i]; v[i]--; }
	int ans(0);
	rep(i, 0, N) {
		if (v[i] == i) {
			if (i + 1 < N&&v[i + 1] == i + 1)ans++, i++;
			else ans++;
		}
	}
	cout << ans << endl;
	return 0;
}

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

int main(){
    int h[2];
    int k[2];
    cin>>h[0]>>h[1];
    cin>>k[0]>>k[1];
    int a,b,c,d;
    cin>>a>>b>>c>>d;

    int hp=a*h[0]+(h[0]/10)*c+b*h[1]+(h[1]/20)*d;
    int kp=a*k[0]+(k[0]/10)*c+b*k[1]+(k[1]/20)*d;

    if(hp>kp) cout<<"hiroshi"<<endl;
    else if(hp<kp) cout<<"kenjiro"<<endl;
    else cout<<"even"<<endl;

    return 0;
}


Measured memory_bytes: 3100
#include <iostream>
#include <string>

using namespace std;

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

	string okMessage = "Yes";
	string badMessage = "No";

	if (s[0] == s[1] && s[2] == s[3] && s[0] != s[2])
		cout << okMessage;
	else if (s[0] == s[2] && s[1] == s[3] && s[0] != s[1])
		cout << okMessage;
	else if (s[0] == s[3] && s[1] == s[2] && s[0] != s[1])
		cout << okMessage;
	else
		cout << badMessage;

	return 0;
}


Measured memory_bytes: 384
// A-Circle.cpp : このファイルには 'main' 関数が含まれています。プログラム実行の開始と終了がそこで行われます。
//

#include <iostream>

using namespace std;

int main()
{
    int r;
    cin >> r;
    cout << r * r;
}

// プログラムの実行: Ctrl + F5 または [デバッグ] > [デバッグなしで開始] メニュー
// プログラムのデバッグ: F5 または [デバッグ] > [デバッグの開始] メニュー

// 作業を開始するためのヒント: 
//    1. ソリューション エクスプローラー ウィンドウを使用してファイルを追加/管理します 
//   2. チーム エクスプローラー ウィンドウを使用してソース管理に接続します
//   3. 出力ウィンドウを使用して、ビルド出力とその他のメッセージを表示します
//   4. エラー一覧ウィンドウを使用してエラーを表示します
//   5. [プロジェクト] > [新しい項目の追加] と移動して新しいコード ファイルを作成するか、[プロジェクト] > [既存の項目の追加] と移動して既存のコード ファイルをプロジェクトに追加します
//   6. 後ほどこのプロジェクトを再び開く場合、[ファイル] > [開く] > [プロジェクト] と移動して .sln ファイルを選択します


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

using namespace std;

const int INF = (1<<29);

class Point{
public:
  double x,y;

  Point(double x = 0, double y = 0):x(x),y(y){}

  bool operator < (const Point &a)const{
    if(x != a.x) return x < a.x;
    return y < a.y;
  }
};

bool compare(Point a, Point b){
  return a.y < b.y;
}

double solve(Point *a, int n){
  if(n <= 1) return INF;
  int m = n / 2;
  double xx = a[m].x;
  double d = min(solve(a,m),solve(a+m,n-m));
  inplace_merge(a,a+m,a+n,compare);

  vector<Point> v;
  for(int i = 0 ; i < n ; i++){
    if(fabs(a[i].x - xx >= d)) continue;
    int len = (int)v.size();
    for(int j = 0 ; j < len ; j++){
      double dx = a[i].x - v[len-j-1].x;
      double dy = a[i].y - v[len-j-1].y;

      if(dy*dy >= d) break;
      d = min(d,dx * dx + dy * dy);
    }
    v.push_back(a[i]);
  }
  return d;
}

int main(){
  int n;

  cin >> n;
  Point p[n];
  for(int i = 0 ; i < n ; i++){
    cin >> p[i].x >> p[i].y;
  }
  sort(p,p+n);
  cout << solve(p,n) << endl;

  return 0;
}

Measured memory_bytes: 21324
#include <cstdio>
#include <cstdint>
#include <vector>
#include <algorithm>
#include <string>

intmax_t ds(intmax_t n) {
  intmax_t res = 0;
  while (n) {
    res += n % 10;
    n /= 10;
  }
  return res;
}

intmax_t f(intmax_t n) {
  std::string s = std::to_string(n);
  intmax_t res = n;

  auto cmp = [&](__int128 u, __int128 v) { return u*ds(v) < v*ds(u); };

  // "1234567"
  for (size_t i = 0; i < s.length(); ++i) {
    // "12x9999"
    std::string t = s.substr(0, i) + std::string(s.length()-i, '9');
    while (t[i] <= '9') {
      res = std::min(res, std::stol(t), cmp);
      ++t[i];
    }
  }

  // "yy9999999"
  __int128 nines = std::stol(std::string(s.length(), '9'));
  for (size_t i = 1; i < 100; ++i) {
    __int128 cur = i * (nines+1) + nines;
    res = std::min<__int128>(res, cur, cmp);
  }

  return res;
}

int main() {
  size_t k;
  scanf("%zu", &k);

  intmax_t n = 1;
  for (size_t i = 0; i < k; ++i) {
    printf("%jd\n", n);
    n = f(n+1);
  }
}


Measured memory_bytes: 256
n = int(input())
p = list(map(int,input().split()))

count = 0
for i in range(n - 2):
    if p[i] < p[i + 1] and p[i + 1] < p[i + 2]:
        count = count + 1
    elif p[i] > p[i + 1] and p[i + 1] > p[i + 2]:
        count = count + 1


print(count)


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

int main(void) {
  ll a, b, k;
  cin >> a >> b >> k;


  ll aa = max(0LL, a - k);
  if (aa > 0) {
    cout << aa << " " << b << endl;
    return 0;
  }
  cout << aa << " " << max(0LL, b - (k - a)) << endl;
  
  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <numeric>
#include <stdio.h>
#include <iomanip>
#include <string> // string, to_string, stoi
#include <vector> // vector
#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <utility> // pair, make_pair
#include <tuple> // tuple, make_tuple
#include <cstdint> // int64_t, int*_t
#include <cstdio> // printf
#include <map> // map
#include <queue> // queue, priority_queue
#include <set> // set
#include <stack> // stack
#include <deque> // deque
#include <unordered_map> // unordered_map
#include <unordered_set> // unordered_set
#include <bitset> // bitset
#include <cctype> // isupper, islower, isdigit, toupper, tolower
using namespace std;
#define rep(i, n) for (long long i = 0; i < (long long)(n); i++)






int main() {
	int A,B,k=-1;
	cin >> A>>B;
	rep(i, 100000) {
		if (int(i * 0.08) == A && int(i * 0.1) == B) {
			k = i;
			break;
		}
	}
	cout <<k<< endl;
}

Measured memory_bytes: 256
N=int(input())
A=list(map(int,input().split()))
B=sorted([A[i]-i for i in range(N)])
if N%2==0:
	C=int((B[int(N/2)]+B[int(N/2-1)])/2)
else:
	C=B[int((N-1)/2)]
print(sum([abs(b-C) for b in B]))

Measured memory_bytes: 27588
#define MOD_TYPE 2

#pragma region Macros
#include <bits/stdc++.h>
using namespace std;

#if 0
#include <boost/multiprecision/cpp_int.hpp>
#include <boost/multiprecision/cpp_dec_float.hpp>
using Int = boost::multiprecision::cpp_int;
using lld = boost::multiprecision::cpp_dec_float_100;
#endif
#if 1
#pragma GCC target("avx2")
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")
#endif
using ll = long long int;
using ld = long double;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
using pld = pair<ld, ld>;
template <typename Q_type>
using smaller_queue = priority_queue<Q_type, vector<Q_type>, greater<Q_type>>;

constexpr ll MOD = (MOD_TYPE == 1 ? (ll)(1e9 + 7) : 998244353);
//constexpr ll MOD = 1;
constexpr int INF = (int)1e9 + 10;
constexpr ll LINF = (ll)4e18;
constexpr double PI = acos(-1.0);
constexpr double EPS = 1e-11;
constexpr int Dx[] = {0, 0, -1, 1, -1, 1, -1, 1, 0};
constexpr int Dy[] = {1, -1, 0, 0, -1, -1, 1, 1, 0};

#define REP(i, m, n) for (ll i = m; i < (ll)(n); ++i)
#define rep(i, n) REP(i, 0, n)
#define REPI(i, m, n) for (int i = m; i < (int)(n); ++i)
#define repi(i, n) REPI(i, 0, n)
#define MP make_pair
#define MT make_tuple
#define YES(n) cout << ((n) ? "YES" : "NO") << "\n"
#define Yes(n) cout << ((n) ? "Yes" : "No") << "\n"
#define possible(n) cout << ((n) ? "possible" : "impossible") << "\n"
#define Possible(n) cout << ((n) ? "Possible" : "Impossible") << "\n"
#define Yay(n) cout << ((n) ? "Yay!" : ":(") << "\n"
#define all(v) v.begin(), v.end()
#define NP(v) next_permutation(all(v))
#define dbg(x) cerr << #x << ":" << x << "\n";

struct io_init
{
  io_init()
  {
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout << setprecision(30) << setiosflags(ios::fixed);
  };
} io_init;
template <typename T>
inline bool chmin(T &a, T b)
{
  if (a > b)
  {
    a = b;
    return true;
  }
  return false;
}
template <typename T>
inline bool chmax(T &a, T b)
{
  if (a < b)
  {
    a = b;
    return true;
  }
  return false;
}
inline ll CEIL(ll a, ll b)
{
  return (a + b - 1) / b;
}
template <typename A, size_t N, typename T>
inline void Fill(A (&array)[N], const T &val)
{
  fill((T *)array, (T *)(array + N), val);
}
template <typename T, typename U>
constexpr istream &operator>>(istream &is, pair<T, U> &p) noexcept
{
  is >> p.first >> p.second;
  return is;
}
template <typename T, typename U>
constexpr ostream &operator<<(ostream &os, pair<T, U> &p) noexcept
{
  os << p.first << " " << p.second;
  return os;
}
#pragma endregion

void solve()
{
  ll a, b, c, d;
  cin >> a >> b >> c >> d;
  ll p = -LINF;
  chmax(p, a * c);
  chmax(p, a * d);
  chmax(p, b * c);
  chmax(p, b * d);
  if (a <= 0 and b >= 0)
    chmax(p, 0LL);
  if (c <= 0 and d >= 0)
    chmax(p, 0LL);
  cout << p << "\n";
}

int main()
{
  solve();
}


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

int main(){

    int n;
    cin >> n;
    vector<int> d(n);

    for(int i = 0; i < n; ++i){
        cin >> d.at(i);
    }

    int ans = 0;

    for(int i = 0; i < n-1; ++i){
        for(int j = i+1; j < n; ++j){
            ans += d.at(i) * d.at(j);
        }
    }

    cout << ans << endl;
}

Measured memory_bytes: 256
import sys
WS = sys.stdin.read()[:-1].split('\n')
for W in WS:
    a,b,c,d,e,f = map(float,W.split())
    x=(b*f-e*c)/(b*d-e*a)
    y=(c-a*x)/b
    x+=0
    y+=0
    print '%.3f %.3f' % (round(x,3),round(y,3))

Measured memory_bytes: 4244
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		// TODO Auto-generated method stub
		Scanner sc = new Scanner(System.in);

		char[] str = sc.next().toCharArray();

		int result = 0;

		int tmpCount = 0;
		for(int i = 0; i < str.length; i++){
			char tmpC = str[i];

			if(str[i] != 'A' && str[i] != 'C' && str[i] != 'T' && str[i] != 'G'){
				tmpCount = 0;
				continue;
			}
			tmpCount++;
			result = Math.max(result, tmpCount);
		}

		System.out.println(result);
	}

}


Measured memory_bytes: 23764
#define _CRT_SECURE_NO_WARNINGS // #pragma warning(disable:4996)
#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <vector>
#include <string>
#include <queue>
#include <functional>
#include <sstream>
#include <cmath>
#include <set>
#include <map>
using namespace std; 

#define rep(i,a,b) for(int i=(a);i<(b);i++)
#define pb push_back
#define mp(a,b) make_pair(a,b)
#define all(a) a.begin(),a.end()
#define len(x) ((int)(x).size())
#define tmax(a,b,c) max((a),max((b),(c)))
#define tmin(a,b,c) min((a),min((b),(c)))
#define debug(x) cerr << #x << " is " << x << endl;

typedef pair<int, int> Pii;
typedef vector<int> Vi;
typedef vector<vector<int> > VVi;
typedef long long ll;
const int inf = 2e9;
const ll ll_inf = 1e17;
const int mod = 1e9 + 7;
const long double eps = 1e-10;

int dy[4] = {0,-1,0,1}; // w s e n
int dx[4] = {-1,0,1,0};

int main()
{
	while(1) {
		int n;
		cin >> n;
		if (!n) break;
		int w = 0, h = 0;
		int top = 0, bot = 0, left = 0, right = 0;
		vector<Pii> vp;
		vp.pb(mp(h,w));
		rep(i,1,n) {
			int a, b;
			cin >> a >> b;
			int y = vp[a].first;
			int x = vp[a].second;
			y += dy[b];
			x += dx[b];
			if (x < left) left = x;
			if (x > right) right = x;
			if (y < bot) bot = y;
			if (y > top) top = y;
			vp.pb(mp(y,x));
			//printf("x=%d y=%d left=%d bot=%d right=%d top=%d\n", x, y, left, bot, right, top);
		}
		int width = abs(left) + abs(right) + 1;
		int height = abs(top) + abs(bot) + 1;
		cout << width << " " << height << endl;
	}

	return 0;
}

Measured memory_bytes: 1204
#include<iostream>

using namespace std;

long long int arr[100001];
long long int store[100001];

long long int find(long long int n)
{
	if(store[n]!=-1)
	{
		return store[n];
	}
	else
	{
		store[n] = min(abs(arr[n] - arr[n-1]) + find(n-1),abs(arr[n] - arr[n-2]) + find(n-2));
		return store[n];
	}
}

int main()
{
	long long int n,i;
	cin>>n;
	for(i=1;i<=n;++i)
	{
		cin>>arr[i];
	}
	store[1] = 0;
	store[2] = abs(arr[2]-arr[1]);
	for(i=3;i<100001;++i)
	{
		store[i] = -1;
	}
	cout<<find(n)<<endl;
	return 0;
}

Measured memory_bytes: 3328
import sys
n,m,x=map(int,input().split())
ac=[[0]*(m+1) for i in range(n)]
a=[[0]*m for i in range(0,n)]
c=[0 for i in range(n)]
for i in range(n):
  ac[i]=list(map(int,input().split()))
  c[i]=ac[i][0]
  a[i]=ac[i][1:m+1]#sliceは上限+１を:の右に代入
cheap=[]
kaukadouka=[0 for i in range(n)]

def kau(i):
  global a,x,kaukadouka,cheap,c
  rikaido=[0 for i in range(m)]#初期化
  for j in range(i+1,n):
    kaukadouka[j]=0
  if i>=n:
      sys.exit()
  kaukadouka[i]=1
  for j in range(n):
    for k in range(m):
      rikaido[k]+=kaukadouka[j]*a[j][k]
  value=0
  if min(rikaido)>=x:
    for j in range(n):
      value+=c[j]*kaukadouka[j]
    cheap.append(value)
  if i<n-1:
    kau(i+1)
    kawanai(i+1)
    
def kawanai(i):
  global kaukadouka
  for j in range(i,n):
    kaukadouka[j]=0

  if i>=n:
    sys.exit()
  #print('i=',i,'のとき買わないで')
  #print('->',kaukadouka)

  if i<n-1:
    kau(i+1)
    kawanai(i+1)

kau(0)
kawanai(0)
if len(cheap)>0:
	#print(cheap)
	print(min(cheap))
else:
  print('-1')

Measured memory_bytes: 9264
#include<stdio.h>
#include<iostream>
#include<math.h>
#include<algorithm>
#include<string.h>
#include<queue>
typedef long long ll;
typedef unsigned long long ull;
using namespace std;

ll Pow_mod(ll a, ll b, ll c){
    ll ans = 1;
    a %= c;
    while (b){
        if (b & 1) ans = (ans * a) % c;
        a = (a * a) % c;
        b >>= 1;
    }
    return (ans % c);
}

int main(){
    int r;
    scanf("%d", &r);
    printf("%d\n", 3 * r * r);
    return 0;
}


Measured memory_bytes: 256
import java.util.Scanner;
class Main{
    public static void main(String[] args){
		Scanner sc=new Scanner(System.in);
		int r,c;
		int[][] spread=new int[101][101];
		for(int i=0;i<101;i++){
			for(int j=0;j<101;j++){
				spread[i][j]=0;
			}
		}
		r=sc.nextInt();
		c=sc.nextInt();
		for(int i=0;i<r;i++){
			for(int j=0;j<c;j++){
				spread[i][j]=sc.nextInt();
				spread[r][j]+=spread[i][j];
				spread[i][c]+=spread[i][j];
				System.out.print(spread[i][j]+" ");
			}
			System.out.println(spread[i][c]);
			spread[r][c]+=spread[i][c];
		}
		for(int j=0;j<c;j++){
			System.out.print(spread[r][j]+" ");
		}
		System.out.println(spread[r][c]);
    }
}



Measured memory_bytes: 40784
#include <iostream>
#include <algorithm>
#include <cmath>
#include <string>
#include <vector>
#include <queue>
typedef unsigned long long ULL;

int main() {

	long ans = 0;
	long numB = 0;
	std::string str;

	std::cin >> str;

	for (int i = 0; i < str.size(); ++i) {
		if (str[i] == 'B') {
			numB++;
		}
		if (str[i] == 'W') {
			ans += numB;
		}
	}

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

Measured memory_bytes: 640
'use strict';
const main = input => {
  let h = parseInt(input[0]);
  const check = num => {
    let twoPow = 1;
    let sum = 0;
    let count = 0;
    while(sum<=num) {
      sum += twoPow;
      twoPow *= 2;
      count++;
    }
    return count;
  }
  let ans = Math.pow(2, check(h-1))-1;
  console.log(ans);
  
}
main(require("fs").readFileSync("/dev/stdin", "utf8").split('\n'));
/*
1  1   2  1
2  3   4  2
3  7   8  3
4  7   8  3
5  15  16 4
6  15  16 4
7  15  16 4
8  15  16 4
9  31  32 5
10 31  32 5
11 31  32 5
12 31  32 5
13 31  32 5
14 31  32 5
15 31  32 5
16 31  32 5
17 63  64 6

1, 1, 2, 4, 8, 16, ...
*/

Measured memory_bytes: 11468
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); i++) 

using namespace std;

int main() {
  int n;cin>>n;
  vector<string> w(n);
  rep(i,n)cin>>w[i];
  bool ans=true;
  rep(i,n-1){
    if(w[i][w[i].size()-1]!=w[i+1][0])ans=false;
            }
  rep(i,n){
    for(int j=i+1;j<n;j++){
      if(w[i]==w[j])ans=false;
    }
  }
  if(ans)cout<<"Yes"<<endl;
  else cout<<"No"<<endl;
}

Measured memory_bytes: 3584
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
constexpr long long MOD = 1000000007;
constexpr long long INF = 1LL << 60;
const long double PI = acosl(-1.0);
constexpr long double EPS = 1e-11;
template<class T> inline bool chmin(T& a, T b) {
    if (a > b) {
        a = b;
        return true;
    }
    return false;
}
template<class T> inline bool chmax(T& a, T b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}
int main(){
ll n;
cin >> n;
ll a[n];
for (ll i = 0; i < n;i++){
    cin >> a[i];
}
deque<ll> ans;
for (ll i = 0; i < n; i++) {
    if(i%2==0){
        ans.push_back(a[i]);
    }
    else{
        ans.push_front(a[i]);
    }
}
if(n%2==0){
    for (ll i = 0; i < n;i++){
        cout << ans[i] << " ";
    }
}
else{
    for (ll i = 0; i < n;i++){
        cout << ans[n-1-i] << " ";
    }
}
}

Measured memory_bytes: 5376
#include <bits/stdc++.h>
using namespace std;
int main(){
  int A,B,C,D;
  cin >> A >> B >> C >> D;
  int AB, CD;
  AB = A + B;
  CD = C + D;
  if(AB < CD){
    cout << "Right" << endl;
  }
  if(AB == CD){
    cout << "Balanced" << endl;
  }
  if(AB > CD){
    cout << "Left" << endl;
  }
}

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

int n, k;

int main(void)
{
	scanf("%d %d%*c", &n, &k);
	int i;
	double prob = 0.0;
	for(i=1;i<=n;i++) {
		if(i < k) {
			double l = log((double)k/i)/log(2.0);
			int m = (int)l;
			if(l != (double)m) m += 1;
			prob += 1.0/n * pow(0.5, m);
		} else {
			prob += 1.0/n;
		}
	}
	printf("%.15f", prob);
	
	return 0;
}


Measured memory_bytes: 512
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.StringTokenizer;

public class Main {

	private int getMinCost(int n, int[] p) {
		int[][] m = new int[n+1][n+1];
		for (int s = 0; s < n; s++) {
			for (int i = 1, j = s + 2; j <= n; i++, j++) {
				m[i][j] = Integer.MAX_VALUE;
				for (int k = i; k < j; k++) {
					m[i][j] = Math.min(m[i][j], m[i][k] + m[k+1][j] + p[i-1]*p[k]*p[j]);
				}
			}
		}
		return m[1][n];
	}
	
	private void run() throws IOException {
		BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
		int n = Integer.parseInt(reader.readLine());
		int[] p = new int[n+1];
		for (int i = 0, j = 0; i < n; i++) {
			StringTokenizer st = new StringTokenizer(reader.readLine());
			int n1 = Integer.parseInt(st.nextToken());
			int n2 = Integer.parseInt(st.nextToken());
			if (i == 0) {
				p[j++] = n1;
			}
			p[j++] = n2;
		}
		System.out.println(getMinCost(n, p));
	}
	
	public static void main(String[] args) throws IOException {
		new Main().run();
	}
}


Measured memory_bytes: 24500
#include<stdio.h>
#define N 501
#define WHITE 0
#define GRAY 1
#define BLACK 2

static const int INFTY = (1<<21);

int n,M[N][N];
int color[N],d[N],f[N],t;

void visit(int u){
  int v;
  color[u]=GRAY;
    d[u]=++t;
  for(v=0;v<n;v++){
    if(M[u][v]==0) continue;
    if(color[v]==WHITE){
      visit(v);
    }
  }
  color[u]=BLACK;
  f[u]=++t;
}

void dfs(){
  int i,u;
  for(i=0;i<n;i++) color[i]=WHITE;
  t=0;
  for(u=0;u<n;u++){
    if(color[u]==WHITE) visit(u);
  }
  for(i=0;i<n;i++){
    printf("%d %d %d\n",i+1,d[i],f[i]);
  }
}

int main(){
  int u,k,v; 
  int i,j;

  scanf("%d",&n);

  for(i=0;i<n;i++){
    for(j=0;j<n;j++) M[i][j]=0;
  }
  
  for(i=0;i<n;i++){
    scanf("%d%d",&u,&k);
    u--;
    for(j= 0;j<k;j++){
      scanf("%d",&v);
      v--;
      M[u][v]=1;
    }
  }

  dfs();

  return 0;
}



Measured memory_bytes: 2112
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
ll gcd(ll a, ll b)
{
    if (a < b) {
        a ^= b;
        b ^= a;
        a ^= b;
    }
    
    return b ? gcd(b, a % b) : a;
}

ll lcm(ll a, ll b)
{
    return a * b / gcd(a, b);
}
int main(void)
{
  ll a, b;
  cin >> a>>b;
    cout << lcm(a,b)<<endl;

  return 0;
}



Measured memory_bytes: 256
#include <stdio.h>
#include <string.h>
 
#define MAX 100005 

typedef struct pp
{
	char name[100];
	int t;
}P;

P Q[MAX];
int tail, head, n;

void enqueue(P x)
{
	Q[tail] = x;
	tail = (tail + 1) % MAX;
}

P dequeue()
{
	P x = Q[head];
	head = (head + 1) % MAX;
	return x;
}

int main()
{
	P x;
	int i, q, sum = 0;
	scanf("%d %d", &n, &q);
	for(i = 1; i <= n; i++)
	{
		scanf("%s %d", &Q[i].name, &Q[i].t);
	}
	head = 1;
	tail = n + 1;
	while(head != tail)
	{
		x = dequeue();
		if(x.t > q)
		{
			x.t -= q;
			enqueue(x);
			sum += q;
		}
		else
		{
			sum += x.t;
			printf("%s %d\n", x.name, sum);
		}
	}
	
	return 0;
}


Measured memory_bytes: 11872
#include<stdio.h>

#define MAX 500000
#define SENTINEL 2000000000
typedef long long llong;

int L[MAX/2+2],R[MAX/2+2];

llong merge(int a[MAX],int left,int mid,int right){
	int i,j,k;
	llong cnt=0;
	int n1=mid-left;
	int n2=right-mid;
	for(i=0;i<n1;i++)L[i]=a[left+i];
	for(i=0;i<n2;i++)R[i]=a[mid+i];
	L[n1]=R[n2]=SENTINEL;
	i=0;
	j=0;
	for(k=left;k<right;k++){
		if(L[i]<=R[j]){
			a[k]=L[i++];
		}
		else{
			a[k]=R[j++];
			cnt+=n1-i;
		}
	}
	
	return cnt;
}

llong mergeSort(int a[MAX],int left,int right){
	llong v1,v2,v3;
	if(left+1<right){
		int mid=(left+right)/2;
		v1=mergeSort(a,left,mid);
		v2=mergeSort(a,mid,right);
		v3=merge(a,left,mid,right);
		return v1+v2+v3;
	}else return 0;
}

int main(void){
	int a[MAX],n;
	
	scanf("%d",&n);
	for(int i=0;i<n;i++)scanf("%d",&a[i]);
	
	llong ans=mergeSort(a,0,n);
	
	printf("%lld\n",ans);
	
	return 0;
}


Measured memory_bytes: 3364
#include <iostream>
#include <sstream>
#include <algorithm>
#include <functional>
#include <iterator>
#include <numeric>
#include <cstdint>
#include <cmath>
#include <bitset>
#include <string>
#include <list>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <map>

#define N_TIMES(i, n)     for ( uint64_t i = 0;     i <  n; ++i )
#define N_TIMES_REV(i, n) for (  int64_t i = n - 1; i >= 0; --i )

using namespace std;

int main()
{
  uint64_t H, W, N;
  cin >> H >> W >> N;

  vector<uint64_t> a(N);
  N_TIMES(n, N) { cin >> a[n]; }

  vector<vector<uint64_t>> c(H);
  N_TIMES(h, H) { c[h] = vector<uint64_t>(W, 0); }
  
  uint64_t x = 0, y = 0;
  N_TIMES(n, N) {
    N_TIMES(i, a[n]) {
      c[y][x] = n + 1;
      
      if (y % 2 == 0) {
        ++x;
        if (x == W) {
          ++y;
          x = W - 1;
        }
      } else {
        --x;
        if (x == -1) {
          ++y;
          x = 0;
        }
      }
    }
  }

  N_TIMES(h, H) {
    N_TIMES(w, W) {
      cout << c[h][w];
      if (w + 1 < W) { cout << ' '; }
    }
    cout << endl;
  }

  return 0;
}

Measured memory_bytes: 384
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> Pii;
typedef pair<ll,ll> Pll;
#define rep(i,n) for (ll i=0;i<n;++i)
#define rep2(i,a,b) for (ll i=a;i<b;++i)
const ll MOD=1000000007;
string alp="abcdefghijklmnopqrstuvwxyz";

int main(){
    ll X,Y;
    cin >> X >> Y;
    if (abs(X-Y)<2){
        cout << "Brown" << endl;
    }
    else {
        cout << "Alice" << endl;
    }
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>

using namespace std;

long long MOD = 1e9+7;
int MAX_INT = 1e9;

int main(void){
  ios::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);

  long long A, B, V, W, T;
  cin >> A >> V >> B >> W >> T;

  long long D = abs(A-B);
  long long D2 = (V-W)*T;

  cout << (D <= D2 ? "YES" : "NO") << endl;
  return 0;
}


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

char F[102][102];

void
DFS (int Y, int X, char A)
{
  if (F[Y][X] != A)
    return;

  F[Y][X] = '.';

  DFS (Y - 1, X, A);
  DFS (Y, X + 1, A);
  DFS (Y + 1, X, A);
  DFS (Y, X - 1, A);
}

int
main ()
{
  int N, M;
  int cnt;

  while (true)
    {

      cin >> N >> M;
      cnt = 0;
      if (N == 0 && M == 0)
	break;

      for (int y = 1; y <= N; y++)
	{
	  for (int x = 1; x <= M; x++)
	    {
	      cin >> F[y][x];
	    }
	}

      for (int y = 1; y <= N; y++)
	{
	  for (int x = 1; x <= M; x++)
	    {
	      if (F[y][x] == '@' || F[y][x] == '#' || F[y][x] == '*')
		{
		  cnt++;
		  DFS (y, x, F[y][x]);
		}
	    }
	}



      cout << cnt << endl;
    }





  return 0;
}

Measured memory_bytes: 3352
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		@SuppressWarnings("resource")
		Scanner scan = new Scanner(System.in);

		String ins = scan.nextLine();

		for (int i = 0; i < ins.length(); i++)
			System.out.print(revCap(ins.charAt(i)));

		System.out.println();

		System.exit(0);
	}

	private static char revCap(char in) {
		if (in >= 'a' && in <= 'z')
			return (char) (in - 'a' + 'A');
		if (in >= 'A' && in <= 'Z')
			return (char) (in - 'A' + 'a');
		return in;
	}

}

Measured memory_bytes: 26880
N = int(input())
W = list(map(int, input().split()))
ans = 0
def sum():
        for i in range(N):
            sum1 = 0
            sum2 = 0
            for j in range(i+1):
                sum1 += W[j]
            for t in range(i+1, N):
                sum2 += W[t]
            if i == 0:
                ans = abs(sum1-sum2)
            else:
                if ans > abs(sum1-sum2):
                    ans = abs(sum1-sum2)
        print(ans)
sum()

Measured memory_bytes: 3064
"""
気付き
１、float('inf')はちょい遅いみたい
２、input()よりもinput = sys.stdin.readlineの方が爆速らしい（知らんがな）
"""
import sys
inf = 10 ** 15
input = sys.stdin.readline

N, M, L = map(int, input().split())
dp = [[inf] * N for _ in range(N)]
for _ in range(M):
    a, b, c = map(int, input().split())
    dp[a-1][b-1] = c
    dp[b-1][a-1] = c
for i in range(N):
    dp[i][i] = 0

for k in range(N):
    for i in range(N):
        for j in range(N):
            dp[i][j] = min(dp[i][j], dp[i][k] + dp[k][j])
#print('distance={}'.format(dp))


dp2 = [[inf] * N for _ in range(N)]
for a in range(N - 1):
    for b in range(a+1, N):
        if dp[a][b] <= L:
            dp2[a][b] = 1
            dp2[b][a] = 1
for k in range(N):
    for i in range(N):
        for j in range(N):
            dp2[i][j] = min(dp2[i][j], dp2[i][k] + dp2[k][j])
#print('times={}'.format(dp2))


Q = int(input())
for _ in range(Q):
    s, t = map(int, input().split())
    cost = dp2[s-1][t-1]
    if cost != inf:
        print(cost - 1)
    else:
        print(-1)


Measured memory_bytes: 57436
#include<stdio.h>
int linerSearch(int,int S[],int);
int main(){
    int n,S[10000];
    int q,T[500];
    int i,count=0;
    scanf("%d",&n);
    for(i=0;i<n;i++){
       scanf("%d",&S[i]); 
    }
    scanf("%d",&q);
    for(i=0;i<q;i++){
        scanf("%d",&T[i]);
        count+=linerSearch(n,S,T[i]);
    }
    printf("%d\n",count);
    return 0;
}

int linerSearch(int n,int S[],int key){
    int i;
    for(i=0;S[i]!=key;i++){
        if(i==n)
        return 0;
    }
    return 1;
}


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

typedef long long int lli;
typedef long int li;

lli solve(lli x){
    return (sqrt(1 + 8.0 * x) - 1) / 2;
}

int main(){
    ios::sync_with_stdio(0);
	cin.tie(0); cout.tie(0);
	lli n;
    cin >> n;
    vector<int> v;
    lli ans = 0;
    for(int i = 2; i <= sqrt(n); i++){
        int p = 0;
        while(n > 0 && n % i == 0){
            p++;
            n /= i;
        }
        if(p != 0) v.push_back(p);
    }
    if(n > 1) ans++;
    for(lli x : v){
        ans += solve(x);
    }
    cout << ans << '\n';
}	

/*
	check for corner cases.
	When using log check for zeros.
	Use queues and stacks if they are helping.           
                            
    (___)           
    . . )____________ 
   _|__/\           |\
  (o_o_) \__________| \
           /|     ||   )     
          < |     ||  
*/



Measured memory_bytes: 3676
import java.util.*;
import java.util.Scanner;
public class Main {
    public static void main(String[] args) {
    	Scanner scanner = new Scanner(System.in);
    	int n = scanner.nextInt();
    	int a[] = new int [n];
    	for(int i = 0;i < n; i++){
    	    a[i] = scanner.nextInt();
    	}
    		for(int i = 0;i < n; i++){
    		if(i != 0){
    		    System.out.print(" ");
    		}
    		System.out.print(a[n - i - 1]);
    	}
    	System.out.println();
	}
}


Measured memory_bytes: 26504
#include <bits/stdc++.h>
#define fi first
#define se second
#define mp make_pair
using namespace std;

typedef pair <int, int> pii;

pii st1[300010];
int t1;
pii st2[300010];
int t2;

struct Segment_tree {
	int T[1200010], lazy[1200010];
	void pushup(int now) {
		T[now] = max(T[now << 1], T[now << 1 | 1]);
	}
	void pushdown(int now) {
		if (!lazy[now]) return ;
		T[now << 1] += lazy[now], lazy[now << 1] += lazy[now];
		T[now << 1 | 1] += lazy[now], lazy[now << 1 | 1] += lazy[now];
		lazy[now] = 0;
	}
	void Build(int now, int l, int r) {
		lazy[now] = 0;
		if (l == r) {
			T[now] = 0;
			return ;
		}
		int mid = l + r >> 1;
		Build(now << 1, l, mid), Build(now << 1 | 1, mid + 1, r);
		pushup(now);
	}
	void Update(int now, int l, int r, int L, int R, int x) {
		if (l == L && r == R) {
			T[now] += x, lazy[now] += x;
			return ;
		}
		pushdown(now);
		int mid = l + r >> 1;
		if (R <= mid) Update(now << 1, l, mid, L, R, x);
		else if (L > mid) Update(now << 1 | 1, mid + 1, r, L, R, x);
		else Update(now << 1, l, mid, L, mid, x), Update(now << 1 | 1, mid + 1, r, mid + 1, R, x);
		pushup(now);
	}
	int Query() {return T[1];}
}seg;

int solve(int n, int m, vector <pii> &all) {
	sort(all.begin(), all.end());
	seg.Build(1, 0, all.size() - 1);
	t1 = t2 = 0;
	int N = all.size() - 1; 
	int ans = 0;
	for (int i = 0; i < (int)all.size() - 1; i++) {
		int x = all[i].fi, y = all[i].se;
		if (y > m / 2) {
			int last = i - 1;
			while (t1 > 0 && st1[t1 - 1].se > y) {
				seg.Update(1, 0, N, st1[t1 - 1].fi, last, y - st1[t1 - 1].se);
				last = st1[t1 - 1].fi - 1, t1--;
			}
			if (last != i - 1) st1[t1++] = mp(last + 1, y);
		} else {
			int last = i - 1;
			while (t2 > 0 && st2[t2 - 1].se < y) {
				seg.Update(1, 0, N, st2[t2 - 1].fi, last, st2[t2 - 1].se - y);
				last = st2[t2 - 1].fi - 1, t2--;
			}
			if (last != i - 1) st2[t2++] = mp(last + 1, y);
		}
		st1[t1++] = mp(i, m), st2[t2++] = mp(i, 0);
		seg.Update(1, 0, N, i, i, m - x);
		ans = max(ans, seg.Query() + all[i + 1].fi);
	}
	return ans * 2;
}

int main () {
	int n, m, k; scanf("%d%d%d", &n, &m, &k);
	vector <pii> all;
	while (k--) {
		int x, y; scanf("%d%d", &x, &y);
		all.push_back(mp(x, y));
	}
	all.push_back(mp(0, 0)), all.push_back(mp(n, m));
	int ans = solve(n, m, all);
	for (int i = 0; i < all.size(); i++) {
		swap(all[i].fi, all[i].se);
	}
	ans = max(solve(m, n, all), ans);
	printf("%d\n", ans);
	return 0;
}


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

typedef long long ll;

int main() {
  ll N, X, ans;
  cin >> N >> X; ans = X;
  while (X != 0) {
    if (2 * X == N) {
      ans += N;
      break;
    }
    if (2 * X < N) {
      ans += N;
      N = N - X;
      X = N - X;
    } else {
      ll side = N - X, tmp1 = X / side, tmp2 = X % side;
      ans += tmp1 * 2 * side;
      N = N - tmp1 * side;
      X = X - tmp1 * side;
    }
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 764
#include <iostream>
#include <algorithm>
#include <cmath>
#include <vector>
#include <set>

using namespace std;

int main() {
  string str;
  int k;

  vector<string> vec;

  cin >> str;
  cin >> k;

  vec.push_back("");
  
  if (str.length() == (unsigned int)k) {
    cout << str << endl;
    return 0;
  }
    

  for (auto it1 = str.cbegin(); it1 != str.cend(); ++it1) {
    for (auto it2 = it1; it2 != str.cend() && it2 - it1 <= 5; ++it2) {
      string s = str.substr(it1 - str.cbegin(), it2 - it1 + 1);
      // cout << s << endl;
      if (s != "") vec.push_back(s);
    }
  }

  sort(vec.begin(), vec.end());
  vec.erase(unique(vec.begin(), vec.end()), vec.end());

  // for (auto it = vec.cbegin(); it != vec.cend(); ++it) {
  //   string s = *it;
  //   cout << s << endl;
  // }

  for (auto it = vec.cbegin(); it != vec.cend(); ++it) {
    if ((it - vec.cbegin()) == k) {
      string s = *it;
      cout << s << endl;
    }
  }
  
  return 0;
}


Measured memory_bytes: 1916
#include <iostream>
#include <stack>
#include <vector>

using namespace std;

void dfs(vector<vector<int>>& g, vector<int>& color, int id, int c) {
    stack<int> s;
    vector<bool> visited(g.size(), false);
    s.push(id);
    color[id] = c;
    while (!s.empty()) {
        int id = s.top();
        s.pop();
        visited[id] = true;

        for (int i = 0; i < g[id].size(); ++i) {
            int adj = g[id][i];
            if (!visited[adj]) {
                color[adj] = c;
                s.push(adj);
            }
        }
    }
}

void assign_colors(vector<vector<int>>& g, vector<int>& color) {
    int color_id = 1;
    for (int i = 0; i < g.size(); ++i) {
        if (color[i] == -1) {
            dfs(g, color, i, color_id);
            ++color_id;
        }
    }
}

int main() {
    ios::sync_with_stdio(false);

    int n, m;
    cin >> n >> m;

    vector<vector<int>> g(n);
    for (int i = 0; i < m; ++i) {
        int p1, p2;
        cin >> p1 >> p2;
        g[p1].push_back(p2);
        g[p2].push_back(p1);
    }

    vector<int> color(n, -1);
    assign_colors(g, color);

    int p;
    cin >> p;
    for (int i = 0; i < p; ++i) {
        int p1, p2;
        cin >> p1 >> p2;
        if (color[p1] == color[p2])
            cout << "yes\n";
        else
            cout << "no\n";
    }
}



Measured memory_bytes: 8668
#include<iostream>
#include<vector>
#define loop(i,a,b) for(int i=a;i<b;i++)
#define rep(i,a) loop(i,0,a)
#define pb push_back
using namespace std;

int gcd (int a,int b){
	if(b>a){
		int alt=b;
		b=a;
		a=alt;
	}
	if(a%b==0)return b;
	else return gcd(b,a%b);
}

int main(){
	int a,b,c;
	cin>>a>>b>>c;
	if(c%gcd(a,b)==0)cout<<"YES"<<endl;
	else cout<<"NO"<<endl;
	return 0;
}

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

int main() {

  int N, D;
  cin >> N >> D;

  vector<vector<int>> date(N, vector<int>(D));
  for (int i = 0; i < N; i++) {
    for (int j = 0; j < D; j++) {
      cin >> date.at(i).at(j);
    }
  }

  vector<int> vec(N * (N - 1) / 2);
  int con = 0;

  for (int i = 0; i < N - 1; i++) {
    for (int j = 1; j < N; j++) {
      if (i >= j) continue;
      int X = 0;
      for (int k = 0; k < D; k++) {
        int Y = date.at(i).at(k) - date.at(j).at(k);
        X += Y * Y;
      }
      vec.at(con) = X;
      con++;
    }
  }

  int ans = 0;

  for (int i = 0; i < N * (N - 1) / 2; i++) {
    double D = sqrt(vec.at(i));
    if (floor(D) * floor(D) == vec.at(i)) ans++;
  }

  cout << ans << endl;

}

Measured memory_bytes: 256
def insertionsort(A, n, g, cnt):
	for i in range(g, n):
		v = A[i]
		j = i - g
		while (j >= 0 and A[j] > v):
			A[j + g] = A[j]
			j = j - g
			cnt += 1
		A[j + g] = v
	return cnt

A = []
n = int(raw_input())
for i in range(n):
	A.append(int(raw_input()))

cnt = 0

G = [1]
while G[-1] * 3 + 1 < n:
	G.append(G[-1] * 3 + 1)
G.reverse()
m = len(G)
for i in range(m):
	cnt = insertionsort(A, n, G[i], cnt)

print m
print " ".join(map(str, G))
print cnt
for num in A:
	print num

Measured memory_bytes: 69940
#pragma GCC optimize("Ofast")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx")

#include <bits/stdc++.h>
//#include <ext/pb_ds/assoc_container.hpp>
//#include <ext/pb_ds/tree_policy.hpp>

#define ll long long
#define ld long double
#define F first
#define S second
#define pb push_back
#define sqr(x) (x) * (x)

using namespace std;
//using namespace __gnu_pbds;

mt19937_64 gen(time(0));

//typedef tree<
//pair <int, int>,
//null_type,
//less<pair <int, int>>,
//rb_tree_tag,
//tree_order_statistics_node_update>
//ordered_set;

//const int mod = 1e9 + 7;
const int inf = 2e9 + 6555;
const int maxn = 1e3 + 23;

const int si[] = {-1, 0, 0, 1};
const int sj[] = {0, -1, 1, 0};

char a[maxn][maxn];
int d[maxn][maxn];

signed main()
{
    cin.tie(0);
    cout.tie(0);
    ios_base::sync_with_stdio(false);
#ifdef LOCAL
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
#else

#endif
    int h, w;
    int ch, cw, dh, dw;
    cin >> h >> w >> ch >> cw >> dh >> dw;
    --ch;
    --cw;
    --dh;
    --dw;
    for(int i = 0; i < h; ++i)
        for(int j = 0; j < w; ++j)
        {
            cin >> a[i][j];
            d[i][j] = inf;
        }
    deque <pair <int, int>> q;
    q.push_front({ch, cw});
    d[ch][cw] = 0;
    while(!q.empty())
    {
        int x = q.front().F;
        int y = q.front().S;
        q.pop_front();
        for(int c = 0; c < 4; ++c)
        {
            int xx = x + si[c];
            int yy = y + sj[c];
            if (xx >= 0 && xx < h && yy >= 0 && yy < w && a[xx][yy] == '.' && d[xx][yy] > d[x][y])
            {
                d[xx][yy] = d[x][y];
                q.push_front({xx, yy});
            }
        }

        for(int xx = max(0, x - 2); xx <= min(h - 1, x + 2); ++xx)
            for(int yy = max(0, y - 2); yy <= min(w - 1, y + 2); ++yy)
            {
                if (a[xx][yy] == '.' && d[xx][yy] > d[x][y] + 1)
                {
                    d[xx][yy] = d[x][y] + 1;
                    q.push_back({xx, yy});
                }
            }
    }
    if (d[dh][dw] == inf) cout << -1;
        else cout << d[dh][dw];
    return 0;
}


Measured memory_bytes: 8676
#include "bits/stdc++.h"
using namespace std;

string s, t, s2;
long long n, m, a, b, c, ans;
vector<int>v[26];

int main() {
	cin >> s >> t;
	n = s.size(), m = t.size();
	s2 = s;
	sort(s2.begin(), s2.end());
	for (int i = 0; i < m; i++) {
		if (!binary_search(s2.begin(), s2.end(), t[i])) {
			printf("-1\n");
			return 0;
		}
	}
	for (int i = 0; i < n; i++) {
		a = s[i] - 'a';
		v[a].push_back(i);
	}
	for (int i = 0; i < m; i++) {
		a = t[i] - 'a';
		if (i == 0) {
			ans += v[a][0];
			b = v[a][0];
		}
		else {
			c = upper_bound(v[a].begin(), v[a].end(), b) - v[a].begin();
			if (!(c < v[a].size())) {
				ans += n;
				c = 0;
			}
			ans += v[a][c] - b;
			b = v[a][c];
		}
	}
	printf("%lld\n", ans + 1);
}

Measured memory_bytes: 1152
#include <bits/stdc++.h>
typedef long long ll;
typedef long double ld;
const int INF=1e9,MOD=1e9+7,ohara=1e6+10;
const ll LINF=1e18;
using namespace std;

#define rep(i,n) for(int (i)=0;(i)<(int)(n);(i)++)
#define rrep(i,a,b) for(int i=(a);i<(b);i++)
#define rrrep(i,a,b) for(int i=(a);i>=(b);i--)
#define all(v) (v).begin(), (v).end()
#define Size(n) (n).size()
#define Cout(x) cout<<(x)<<endl
#define Cerr(x) cerr<<(x)<<endl
#define fi first
#define se second

ll n,cnt,a,b,c,d,tmp,tmpp,m,h,w,x,y,sum,pos,k,H,W;
ld doua;
int dy[]={1,0,-1,0};
int dx[]={0,1,0,-1};
//int dy[]={-1,0,1,-1,1,-1,0,1};
//int dx[]={-1,-1,-1,0,0,1,1,1};
string alph("abcdefghijklmnopqrstuvwxyz"),s;
bool fl;
struct edge{int to,cost;};
ll ans[505][505];

//-------------------------↓↓↓↓↓↓------------------------

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

    cin>>H>>W>>h>>w;
    rep(i,H)rep(j,W)ans[i][j]=1000;
    pos=1000*(h*w-1)*-1;
    pos--;
    ans[h-1][w-1]=pos;
    for(int i=h-1;i<H;i+=h){
        for(int j=w-1;j<W;j+=w){
            ans[i][j]=pos;
        }
    }
    rep(i,H)rep(j,W)sum+=ans[i][j];
    if(sum<=0)Cout("No");
    else{
        Cout("Yes");
        rep(i,H){
            rep(j,W){
                if(j==W-1)Cout(ans[i][j]);
                else cout<<ans[i][j]<<" ";
            }
        }
    }
    return 0;
}


Measured memory_bytes: 3584
/*input
2 3 9
*/

#include <bits/stdc++.h>

using namespace std;

long double eps = 1e-11;

int main() {
  int a, b, c;
  scanf("%d%d%d", &a, &b, &c);
  long double aa = sqrtl(a), bb = sqrtl(b);
  printf("%s\n", (a + b + 2 * aa * bb + eps) < c ? "Yes" : "No");
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define N 100007
#define inf 1e9+7
using namespace std;
typedef pair<int,int> ii;
int n, k;
int a[N];
int dj[N];

int dsj(){
    priority_queue <ii, vector<ii>, greater<ii> > pq;
    pq.push(ii(0,1));
    dj[1] = 0;
    while(!pq.empty()){
        int val = pq.top().first;
        int pos = pq.top().second;
        pq.pop();
        if (pos == n){
            return val;
        }
        for (int i = 1; i <= k; i ++){
            if (pos + i <= n){
                if (dj[pos+i] > dj[pos] + abs(a[pos] - a[pos+i])){
                    dj[pos+i] = dj[pos] + abs(a[pos] - a[pos+i]);
                    pq.push(ii(dj[pos+i],pos+i));
                }
            }
        }
    }
    return dj[n];
}

int main(){
    cin >> n >> k;
    for (int i = 1; i <= n; i ++){
        cin >> a[i];
        dj[i] = inf;
    }
    cout << dsj();
}


Measured memory_bytes: 2168
import java.util.*;
public class Main {
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
      String S = sc.next();
      if(S.contains("RRR")){
        System.out.println("3");
      }else if(S.contains("RR")){
        System.out.println("2");
      }else if(S.contains("R")){
        System.out.println("1");
      }else{
        System.out.println("0");
      }
    }
}

Measured memory_bytes: 35704
N = int(input())
p = list(map(int, input().split()))

last_matched = False
ans = 0
for i in range(N):
    if i + 1 == p[i]:
        if last_matched:
            ans += 1
            last_matched = False
        else:
            last_matched = True
    else:
        if last_matched:
            ans += 1
            last_matched = False
if last_matched:
    ans += 1
print(ans)

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

typedef long long ll;

const int N = 55;
int n, m, q, ans;
int a[N];
int b[N];
int c[N];
int d[N];
int A[12];

void dfs(int cur, int v) {
    if (cur == n + 1) {
        int res = 0;
        for (int i = 0; i < q; ++i) {
            if (A[b[i]] - A[a[i]] == c[i]) {
                res += d[i];
            }
        }
        ans = max(ans, res);
    } else {
        for (int i = v; i <= m; ++i) {
            A[cur] = i;
            dfs(cur + 1, i);
        }
    }
}

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);

    cin >> n >> m >> q;
    for (int i = 0; i < q; ++i) {
        cin >> a[i] >> b[i] >> c[i] >> d[i];
    }

    dfs(1, 1);
    cout << ans << endl;

    return 0;
}



Measured memory_bytes: 3604
h,w = map(int,input().split())

now = h*w
y = 1
while y < h:
    a = y*w
    if w%2 == 0:
        b = (h-y)*(w//2)
        c = (h-y)*(w//2)
    elif (h-y)%2 == 0:
        b = ((h-y)//2)*w
        c = ((h-y)//2)*w
    else:
        if (h-y) >= w:
            b = (h-y)*(w//2+1)
            c = (h-y)*(w//2)
        else:
            b = w*((h-y)//2+1)
            c = w+((h-y)//2)
    lis = [a,b,c]
    if max(lis)-min(lis) < now:
        now = max(lis)-min(lis)
    y += 1
    
x = 1
while x < w:
    a = x*h
    if h%2 == 0:
        b = (w-x)*(h//2)
        c = (w-x)*(h//2)
    elif (w-x)%2 == 0:
        b = ((w-x)//2)*h
        c = ((w-x)//2)*h
    else:
        if (w-x) >= h:
            b = ((w-x)//2)*h
            c = ((w-x)//2+1)*h
        else:
            b = (h//2+1)*(w-x)
            c = (h//2)*(w-x)
    lis = [a,b,c]
    if max(lis)-min(lis) < now:
        now = max(lis)-min(lis)
    x += 1

print(now)


Measured memory_bytes: 3064
#include<iostream>
const int N=100001;
using namespace std;
int n;
int x[100000+5],y[100000+5],t[100000+5];
int main()
{
    cin>>n;
    for(int i=1;i<=n;i++)
        cin>>t[i]>>x[i]>>y[i];
    for(int i=1;i<=n;i++)
        if(x[i]+y[i]>t[i] or (t[i]-x[i]-y[i])%2!=0)
		{
        	cout<<"No\n";
            return 0;
        }
    cout<<"Yes\n";
    return 0;
}

Measured memory_bytes: 1408