akhauriyash/Code-Regression huggingface dataset:
using System;
using System.Linq;
using System.Collections.Generic;
using static System.Console;
using System.Text;
using System.IO;

namespace AOJ
{
    class Program
    {
        static public long[] Sarray() { return ReadLine().Split().Select(long.Parse).ToArray(); }
        static public List<long> Slist() { return ReadLine().Split().Select(long.Parse).ToList(); }

        class node
        {
            public node left = null;
            public node right = null;
            public long value = -1;
            public node oya = null;
        }
        static void Main(string[] args)
        {
            var N = Sarray()[0];
            var nodes = new node[N];

            node root = null;
            Action<node> insert = null;
            insert = z =>
                  {
                      node y = null;
                      node x = root;
                      while (x != null)
                      {
                          y = x;
                          if (z.value < x.value)
                              x = x.left;
                          else
                              x = x.right;
                      }
                      if (y == null)
                          root = z;
                      else if (z.value < y.value)
                          y.left = z;
                      else
                          y.right = z;
                  };
            Action<node> order = null;
            var preorder = new List<long>();
            var inorder = new List<long>();
            order = n =>
            {
                if (n == null)
                    return;
                preorder.Add(n.value);
                order(n.left);
                inorder.Add(n.value);
                order(n.right);
            };

            for (var i=0;i<N;++i)
            {
                var tmp = ReadLine().Split();
                if (tmp[0] == "insert")
                { insert(new node() { value = long.Parse(tmp[1]) }); }
                else
                {
                    preorder = new List<long>();
                    inorder = new List<long>();
                    order(root);
                    WriteLine(" " + string.Join(" ", inorder));
                    WriteLine(" " + string.Join(" ", preorder));
                }
            }
        }
    }
}


Measured memory_bytes: 78460
#include <bits/stdc++.h>
#define l_ength size
const int inf = (1<<30);
const int mod = 1000000007;
using ll = long long;
using namespace std;

int main(){
	int x; cin >> x;
	for( int i = 1; i <= 100000; ++i ){
		if( x <= i*(i+1)/2 ){
			cout << i << endl;
			break;
		}
	}
}

Measured memory_bytes: 256
from itertools import permutations


L = [int(input())for _ in range(5)]
P = []
for _ in range(5):
    P.append(_)

ans = float('inf')
for p in permutations(P):
    now = 0
    for i, a in enumerate(p):
        if i == 4:
            now += L[a]
        else:
            now += ((L[a]-1)//10)*10 + 10

    ans = min(ans, now)

print(ans)

Measured memory_bytes: 38384
N = input()
K = int(input())

digit = len(N)
dp = [[[0]*(K+1) for _ in range(2)] for _ in range(digit)]

cd = int(N[0])
dp[0][0][0] = 0
dp[0][0][1] = 1
dp[0][1][0] = 1
dp[0][1][1] = cd-1

for i in range(1, digit):
    for k in range(K+1):
        cd = int(N[i])
        if k == 0:
            dp[i][1][0] = 1
        else:
            if cd == 0:
                dp[i][0][k] = dp[i-1][0][k]
                dp[i][1][k] = dp[i-1][1][k] + dp[i-1][1][k-1]*9
            else:
                dp[i][0][k] = dp[i - 1][0][k - 1]
                dp[i][1][k] = dp[i-1][0][k-1]*(cd-1)+dp[i-1][0][k]\
                          +dp[i-1][1][k]+dp[i-1][1][k-1]*9


print(dp[-1][0][K]+dp[-1][1][K])

Measured memory_bytes: 3064
import Data.List

main = print . solve . map read . drop 1 . words =<< getContents

solve :: [Integer] -> Integer
solve xs
    | (odd $ length xs) && head xs' /= 0 = 0
    | any (\((x,y),(x',y')) -> x /= y || x'-x /= 2 || y'-y /= 2) $ zip pairs (drop 1 pairs) = 0
    | otherwise = 2^(length xs' `div` 2) `mod` (10^9 + 7)
    where
        xs' = sort xs
        pairs = if (odd $ length xs) then tuplify (0:xs') else tuplify ((-1):(-1):xs')

tuplify (x:y:xs) = (x,y):tuplify xs
tuplify [] = []


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

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

    rep(i,n) {
        cin >> a.at(i);
        cin >> b.at(i);
    }

    sort(a.begin(),a.end());
    sort(b.begin(),b.end());
    ll res;
    if(n%2 == 1){
        res = b.at((n)/2) - a.at((n)/2)+1;
    }
    else {
        res = b.at(n/2-1)+b.at(n/2)-a.at(n/2-1)-a.at(n/2)+1;
    }
    cout << res << endl;

    return 0;
}

Measured memory_bytes: 4736
// lcmとか__builtin_popcountとかはg++ -std=c++17 default.cppみたいなかんじで

#include <bits/stdc++.h>
#define mod 1000000007
#define INF LLONG_MAX
#define ll long long
#define ln cout<<endl
#define Yes cout<<"Yes"<<endl
#define No cout<<"No"<<endl
#define REP(i,m,n) for(ll i=(ll)(m);i<(ll)(n);i++)
#define rep(i,n) REP(i,0,n)
using namespace std;

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

    ll a,b,c,d,m,n,maxi=0,f=0,mini=INF,sum=0;
    string str;
    cin>>n>>a;
    //vector<vector<ll>> v(tate,vector<ll> (yoko));
    vector<double> v(n);
    vector<double> w(n);
    rep(i,n)   cin >> v[i]>>w[i];
    rep(i,n){
        //cout<<sqrt(v[i]*v[i]+w[i]*w[i])<<endl;
        if(sqrt(v[i]*v[i]+w[i]*w[i])<=a) sum++;
    }
    cout<<sum<<endl;

    return 0;
}


Measured memory_bytes: 6364
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<cmath>
#include <queue>
#include <utility>
#include <tuple>

using ull = unsigned long long;
using ll = long long;
using namespace std;

int main(void) {
    int H, W;
    cin >> H >> W;
    vector<string> S(H);
    vector<int> dx {0, 1, -1, 0};
    vector<int> dy {1, 0, 0, -1};

    for (int i = 0; i < H; ++i) {
        cin >> S[i];
    }

    int dp[H+1][W+1][H+1][W+1];

    for (int i = 0; i < H+1; ++i) {
        for (int j = 0; j < W+1; ++j) {
            for (int u = 0; u < H+1; ++u) {
                for (int z = 0; z < W+1; ++z) {
                    dp[i][j][u][z] = 1<<29;
                }
                // dp[i][i][u][u] = 0;
            }
        dp[i][j][i][j] = 0;
        }
    }

    for (int x = 0; x < H; ++x) {
        for (int y = 0; y < W; ++y) {
            if (S[x][y] == '#') continue;
            for (int di = 0; di < 4; ++di) {
                int nx = x + dx[di];
                int ny = y + dy[di];

                if (nx < 0 || nx >= H || ny < 0 || ny >= W || S[nx][ny] == '#') {
                    continue;
                }
                dp[x][y][nx][ny] = 1;
                dp[nx][ny][x][y] = 1;
            }
        }
    }

    //FW
    for (int kx =0; kx < H; ++kx) {
        for (int ky =0; ky < W; ++ky) {
            for (int i = 0; i < H; ++i) {
                for (int j = 0; j < W; ++j) {
                    for (int u = 0; u < H; ++u) {
                        for (int z = 0; z < W; ++z) {
                            if (dp[i][j][u][z] > dp[i][j][kx][ky] + dp[kx][ky][u][z]) {
                                dp[i][j][u][z] = dp[i][j][kx][ky] + dp[kx][ky][u][z];
                            }
                        }
                    }
                }
            }
        }
    }

    // ans
    int ans = 0;
    for (int x = 0; x < H; ++x) {
        for(int y = 0; y < W; ++y) {
            if (S[x][y] == '#') continue;
            for(int xx = 0; xx < H; ++xx) {
                for (int yy = 0; yy <W; ++yy) {
                    if (S[xx][yy] == '#') continue;
                    if (ans < dp[x][y][xx][yy]) {
                        ans = dp[x][y][xx][yy];
                    }
                }
            }
        }
    }

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

Measured memory_bytes: 4408
#include <bits/stdc++.h>
#include <iostream>
#include <string>

#define ll long long int
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define phi 3.1415926535
#define fastio() ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define endl '\n'
 
using namespace std;

const ll mod = 1000000007;    

ll tc, cnt = 0, number, many, total = 0, query;
// vector <vector <int> > adjList;
int rmove[8] = {-1, 0, 1, 0, -1, 1, -1, 1};
int cmove[8] = {0, 1, 0, -1, 1, -1, -1, 1};

ll power(ll x, ll y, ll mod)
{
    if(y == 0)
        return 1;
    else if(y % 2 == 0)
        return (power(x, y / 2, mod) % mod * power(x, y / 2, mod) % mod) % mod;
    else
        return x * (power(x, y / 2, mod) % mod * power(x, y / 2, mod) % mod) % mod;
}

int main()
{
    fastio();
        
    // freopen("input.txt","r", stdin);
    // freopen("output.txt","w", stdout);
    // g++ -std=c++11 Default.cpp  -o test
    // g++ -Wl,--stack=268435456 -std=c++11 Default.cpp  -o test

    cin >> many >> number;

    pair <int, ll> arr[many];
    for(int i = 0; i < many; i++)
        cin >> arr[i].fi >> arr[i].se;

    ll dp[number + 1];
    memset(dp, 0, sizeof(dp));

    for(int i = 0; i < many; i++)
    {
        for(int j = number; j >= arr[i].fi; j--)
        {
            dp[j] = max(dp[j], dp[j - arr[i].fi] + arr[i].se);
        }
    }

    cout << dp[number] << endl;

    //
    return 0;
}

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

int H, W, sx[32], sy[32], s[10][10], idx[1009][1009];
char c[1009][1009];
int t[32][32], u[1009][1009];
pair<int, int> dp[1 << 10][32];

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

int main() {
	cin >> W >> H;
	for (int i = 1; i <= H; i++) {
		for (int j = 1; j <= W; j++) {
			cin >> c[i][j]; idx[i][j] = -1;
			if (c[i][j] == 'S') { sx[30] = i; sy[30] = j; }
			if (c[i][j] == 'T') { sx[31] = i; sy[31] = j; }
			if (c[i][j] >= '0' && c[i][j] <= '9') {
				sx[0 + (c[i][j] - '0')] = i;
				sy[0 + (c[i][j] - '0')] = j;
			}
			if (c[i][j] >= 'A' && c[i][j] <= 'J') {
				sx[10 + (c[i][j] - 'A')] = i;
				sy[10 + (c[i][j] - 'A')] = j;
			}
			if (c[i][j] >= 'a' && c[i][j] <= 'z') {
				sx[20 + (c[i][j] - 'a')] = i;
				sy[20 + (c[i][j] - 'a')] = j;
			}
		}
	}
	for (int i = 0; i < 10; i++) {
		for (int j = 0; j < 10; j++) cin >> s[i][j];
	}
	for (int i = 0; i <= 31; i++) { idx[sx[i]][sy[i]] = i; for (int j = 0; j <= 31; j++) t[i][j] = (1 << 25); }

	for (int i = 0; i <= 31; i++) {
		if (sx[i] == 0 && sy[i] == 0) continue;
		for (int j = 1; j <= H; j++) { for (int k = 1; k <= W; k++) u[j][k] = (1 << 25); }

		queue<pair<int, int>> Q;
		Q.push(make_pair(sx[i], sy[i]));
		u[sx[i]][sy[i]] = 0;

		while (!Q.empty()) {
			int cx = Q.front().first, cy = Q.front().second; Q.pop();

			for (int j = 0; j < 4; j++) {
				int ex = cx + dx[j], ey = cy + dy[j];
				if (ex <= 0 || ey <= 0 || ex > H || ey > W || c[ex][ey] == '#') continue;

				if (idx[ex][ey] == -1) {
					if (u[ex][ey] == (1 << 25)) {
						Q.push(make_pair(ex, ey));
						u[ex][ey] = u[cx][cy] + 1;
					}
				}
				else {
					t[i][idx[ex][ey]] = min(t[i][idx[ex][ey]], u[cx][cy] + 1);
				}
			}
		}
	}

	for (int i = 0; i < (1 << 10); i++) {
		for (int j = 0; j < 32; j++) dp[i][j] = make_pair((1 << 25), (1 << 25));
	}
	dp[0][30] = make_pair(0, 0);

	pair<int, int> maxn = make_pair((1 << 25), -1);

	for (int i = 0; i < (1 << 10); i++) {
		for (int j = 0; j < 32; j++) {
			if (dp[i][j] == make_pair((1 << 25), (1 << 25))) continue;

			// 幅優先探索
			int dist[32]; for (int k = 0; k < 32; k++) dist[k] = (1 << 25); dist[j] = 0;
			vector<int> V;
			for (int k = 0; k < 10; k++) V.push_back(k);
			for (int k = 0; k < 10; k++) { if ((i / (1 << k)) % 2 == 0) V.push_back(10 + k); }
			for (int k = 0; k < 10; k++) { if ((i / (1 << k)) % 2 == 1) V.push_back(20 + k); }
			V.push_back(30); V.push_back(31);

			for (int tt = 0; tt < 22; tt++) {
				for (int k : V) {
					for (int l : V) {
						if (t[k][l] == -(1 << 25)) continue;
						dist[l] = min(dist[l], dist[k] + t[k][l]);
					}
				}
			}

			if (i == 1023) {
				maxn = min(maxn, make_pair(dp[i][j].first + dist[31], dp[i][j].second));
			}

			// DP の更新
			for (int k = 0; k < 10; k++) {
				if (dist[k] == (1 << 25) || (i / (1 << k)) % 2 == 1) continue;
				dp[i + (1 << k)][k] = min(dp[i + (1 << k)][k], make_pair(dp[i][j].first + dist[k], dp[i][j].second - s[j][k]));
			}
		}
	}

	if (maxn.first == (1 << 25)) cout << "-1" << endl;
	else cout << maxn.first << " " << -maxn.second << endl;
	return 0;
}


Measured memory_bytes: 12212
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

# 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")

    S = iss()
    ret = ""
    for s in S:
        if s == '1':
            ret += '9'
        elif s == '9':
            ret += '1'
        else:
            ret += s
    print(ret)


if __name__ == '__main__':
    main()


Measured memory_bytes: 10092
N = int(input())
S = input()

i = S[1:].count('E')
ans = [i]

for n in range(N):
    if n == 0:
        continue

    if S[n] == 'E':
        i -= 1

    if S[n - 1] == 'W':
        i += 1
    ans.append(i)

print(min(ans))

Measured memory_bytes: 15564
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll MOD = 1e9 + 7;
ll kai[200010];

ll mydiv(ll a, ll b) {
  if (b == 0) return 1LL;
  ll ans = mydiv(a, b / 2);
  ans *= ans;
  ans %= MOD;
  if (b&1) ans *= a;
  return ans % MOD;
}

ll pos(ll hh, ll ww) {
  hh--;
  ww--;
  ll p = kai[hh + ww];
  p *= mydiv(kai[ww], MOD - 2);
  p %= MOD;
  p *= mydiv(kai[hh], MOD - 2);
  p %= MOD;
  return p;
}

int main(){
  kai[0] = 1;
  for (int i = 1; i <= 200000; i++) {
    kai[i] = kai[i - 1] * i;
    kai[i] %= MOD;
  }

  ll h, w, a, b;
  cin >> h >> w >> a >> b;
  ll ans = 0;
  for (int hh = 1; hh <= h - a; hh++) {
    ans += pos(hh, b) * pos(h - hh + 1, w - b);
    ans %= MOD;
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 1792
#include <iostream>

using namespace std;

int main(){
  int n, a, b, ans=0;
  cin >> n >> a >> b;

  for (int i=1; i<=n; i++) {
    int t=i, sum=0;
    while (t) {
      sum+=(t%10);
      t/=10;
    }
    if (sum>=a && sum<=b) ans+=i;
  }

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

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

int main() {
	int n,x,y;
	
	while(true)
	{
		y=0;
		cin>>n>>x;
		if(n==0 && x==0) break;
		for(int i=n;i>=3;i--)
		{
			for (int j = i-1; j>=2; --j)
			{
				for (int k = j-1; k >=1; --k)
				{
					if (i+j+k==x) y=y+1;
				}
			}
		}
		cout<<y<<endl;


	}

	return 0;
}

Measured memory_bytes: 1164
from itertools import permutations

def solve():
    n = int(input())
    p = tuple(map(int, input().split()))
    q = tuple(map(int, input().split()))

    perm_p = sorted(permutations(p))
    perm_q = sorted(permutations(q))

    a, b = 0, 0
    for i, _p in enumerate(perm_p):
        if p == _p:
            a = i
            break
    
    for i, _q in enumerate(perm_q):
        if q == _q:
            b = i
            break
    
    print(abs(a - b))
    

if __name__ == "__main__":
    solve()

Measured memory_bytes: 12788
///Bismillahir Rahmanir Rahim
#include<bits/stdc++.h>

#define                           int                         long long
#define                           fi                          first
#define                           si                          second
#define                           mp                          make_pair
#define                           pb                          push_back
#define                           pi                          pair<int,int>
#define                           f(i,l,r)                    for(int i=l;i<=r;i++)
#define                           rf(i,r,l)                   for(int i=r;i>=l;i--)
#define                           done(i)                     cout<<"done = "<<i<<endl;
#define                           fast                        ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);




using namespace std;

const int inf=1e18;
const int mod=1e9+7;
const int M=100009;

inline int bigmod(int B,int P){int R=1;while(P>0){if(P&1){R=(R*B)%mod;}P>>=1;B=(B*B)%mod;}return R;}
inline int ad(int x,int y){int ret=(x%mod+y%mod)%mod;if(ret<0){ret+=mod,ret=ret%mod;}return ret;}
inline int sub(int x,int y){int ret=((x%mod)-(y%mod)+mod)%mod;if(ret<0){ret+=mod,ret=ret%mod;}return ret;}
inline int gun(int x,int y){int ret=((x%mod)*(y%mod))%mod;if(ret<0){ret+=mod,ret=ret%mod;}return ret;}


 main()

{
    fast
    string s;
    cin>>s;
    int n=s.back()-'0';
    if(n==3)
    {
        cout<<"bon"<<endl;
    }
    else if(n==0 || n==1 || n==6 || n==8)
    {
        cout<<"pon"<<endl;
    }
    else
    {
        cout<<"hon"<<endl;
    }
    return 0;

}





































Measured memory_bytes: 3648
class Node:
    parent = ""
    depth = ""

    def __init__(self, children=[]):
        self.children = children
        if len(children) == 0:
            self.type = 'leaf'
        else:
            self.type = 'internal node'


def add_parent_node_and_depth(nodes, parent_node_no, node_no, depth):
    nodes[node_no].parent = parent_node_no
    nodes[node_no].depth = depth
    for child in nodes[node_no].children:
        add_parent_node_and_depth(nodes, node_no, child, depth+1)
    return


def main():
    n = int(input())
    nodes = {}
    leafs = {}
    for i in range(n):
        node_no, child_num, *children = [int(x) for x in input().split()]
        if child_num == 0:
            leafs[node_no] = Node([])
        else:
            nodes[node_no] = Node(children)

    nodes.update(leafs)
    # search root node no
    node_no = list(leafs.keys())[0]
    while True:
        parent_node_no = [key for key, value in nodes.items() if node_no in value.children]
        if len(parent_node_no) == 0:
            root_node_no = node_no
            nodes[root_node_no].type = 'root'
            break
        node_no = parent_node_no[0]

    # add parent node no and depth to all nodes
    add_parent_node_and_depth(nodes, parent_node_no=-1, node_no=root_node_no, depth=0)

    for i in range(n):
        node = nodes[i]
        print("node {}: parent = {}, depth = {}, {}, [{}]".
              format(str(i), node.parent, node.depth, node.type, ", ".join(map(str, node.children))))

    return


main()


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

using namespace std;

int main(void) {
	int N = 0;
	cin >> N;
	vector<int>H(N);
	int pre = 0;
	int con = 0;
	for (int i = 0; i < N; i++) {
		cin >> H[i];
	}
	for (int i = 0; i < N - 1; i++) {
		if (H[i] >= H[i + 1]) {
			pre++;
		}
		else {
			break;
		}
	}
	for (int i = 0; i < N-1; i++) {
		if (H[i] >= H[i+1]) {
			con++;
			if (pre <= con) {
				pre = con;
			}
		}
		else {
			con = 0;
		}
	}
	cout << pre;
}

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

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

    if (n < 3) {
        cout << 1 << endl;
        return 0;
    }

    int count = 1;
    bool increase = a[0] <= a[1];
    bool neutral = false;
    for (int i = 2; i < n; i++) {
        if (neutral) {
            if (a[i] == a[i-1]) continue;
            neutral = false;
            increase = a[i] > a[i-1];
        } else if (increase) {
            if (a[i] < a[i-1]) {
                neutral = true;
                count++;
            }
        } else {
            if (a[i] > a[i-1]) {
                neutral = true;
                count++;
            }
        }
    }
    cout << count << endl;
    return 0;
}

Measured memory_bytes: 640
inp = require('fs').readFileSync('/dev/stdin', 'utf8').trim().split('\n')
const S = inp.shift()
const T = inp.shift()
let counter = 0
for (let i=0; i<S.length; i++){
    if (S[i] !== T[i]){
        counter++
    }
}
console.log(counter)


Measured memory_bytes: 32808
#include<bits/stdc++.h>
#define MOD 1000000007
#define MOD2 1000000006
#define TEMPMOD1 998244353
#define TEMPMOD2 998244352
#define INF 1000000000000000007
#define NEGINF -1000000000000000007
#define vll vector<ll> 
#define vvll vector<vector<ll>>
#define pll pair<ll,ll>
#define pii pair<int,int>
#define plll pair<ll,pll>
#define vpll vector<pll>
using namespace std;
typedef long long int ll;

ll modexpo(ll base,ll power)
{
	ll result=1;
	while(power)
	{
		if(power&1)
		{
			result=(result*base)%MOD;
		}
		base=(base*base)%MOD;
		power=power>>1;
	}
	return result;
}

ll modinverse(ll num)
{
	ll temp=MOD-2;
	return modexpo(num,temp);
}

ll factorial[100010];
ll inversefact[100010];

void initialise()
{
	factorial[0]=factorial[1]=inversefact[0]=inversefact[1]=1;
	for(ll i=2;i<100010;i++)
	{
		factorial[i]=(factorial[i-1]*i)%MOD;
		inversefact[i]=modinverse(factorial[i]);
	}
	return;
}


int main()
{

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

    ll n,k;
    cin>>n>>k;
    ll arr1[n];
    for(ll i=0;i<n;i++)
    {
    	cin>>arr1[i];
    }
    sort(arr1,arr1+n);
    ll ans=0,store;
    for(ll i=k-1;i<n;i++)
   	{
   		store=factorial[i];
   		store=(store*inversefact[i+1-k])%MOD;
   		store=(store*inversefact[k-1])%MOD;
   		store=(store*arr1[i])%MOD;
   		ans+=store;
   		if(ans>=MOD)
   		{
   			ans-=MOD;
   		}
   	}
   	reverse(arr1,arr1+n);
   	for(ll i=k-1;i<n;i++)
   	{
   		store=factorial[i];
   		store=(store*inversefact[i+1-k])%MOD;
   		store=(store*inversefact[k-1])%MOD;
   		store=(store*arr1[i])%MOD;
   		ans-=store;
   		if(ans<=0)
   		{
   			ans+=MOD;
   		}
   	}
  	ans=ans%MOD;
   	cout<<ans;
   	return 0;
}

Measured memory_bytes: 2560
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int a,b,c,d=0,e,f,i;
    cin>>a;
   for(i=1;i<=a;i++)
   {
       cin>>b;
       c=b*b;
       if(i%2!=0&&c%2!=0)
       {
           d++;
       }
   }
   cout<<d;
}

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

int main() {
    std::ios::sync_with_stdio(false);
    std::cin.tie(0);
    std::string S;
    std::cin >> S;
    int n = S.length();
    int ans = 0;
    for (int i = 1; i < n; ++ i)
        ans += S[i] != S[i - 1];
    std::cout << ans << std::endl;
}


Measured memory_bytes: 512
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.NoSuchElementException;

public class Main {
	public static void main(String[] args) {
		FastScanner sc = new FastScanner();
		int A = sc.nextInt();
		int B = sc.nextInt();
		int C = sc.nextInt();

		PrintWriter out = new PrintWriter(System.out);

		int result = C - (A - B);
		out.println(result > 0 ? result : 0);

		out.flush();
	}

	public static int gcd(int a, int b) {
	    if (b == 0) return Math.abs(a);
	    return gcd(b, a % b);
	}
}

class FastScanner {
	private final InputStream in = System.in;
	private final byte[] buffer = new byte[1024];
	private int ptr = 0;
	private int buflen = 0;

	private boolean hasNextByte() {
		if (ptr < buflen) {
			return true;
		} else {
			ptr = 0;
			try {
				buflen = in.read(buffer);
			} catch (IOException e) {
				e.printStackTrace();
			}
			if (buflen <= 0) {
				return false;
			}
		}
		return true;
	}

	private int readByte() {
		if (hasNextByte())
			return buffer[ptr++];
		else
			return -1;
	}

	private static boolean isPrintableChar(int c) {
		return 33 <= c && c <= 126;
	}

	public boolean hasNext() {
		while (hasNextByte() && !isPrintableChar(buffer[ptr]))
			ptr++;
		return hasNextByte();
	}

	public String next() {
		if (!hasNext())
			throw new NoSuchElementException();
		StringBuilder sb = new StringBuilder();
		int b = readByte();
		while (isPrintableChar(b)) {
			sb.appendCodePoint(b);
			b = readByte();
		}
		return sb.toString();
	}

	public long nextLong() {
		if (!hasNext())
			throw new NoSuchElementException();
		long n = 0;
		boolean minus = false;
		int b = readByte();
		if (b == '-') {
			minus = true;
			b = readByte();
		}
		if (b < '0' || '9' < b) {
			throw new NumberFormatException();
		}
		while (true) {
			if ('0' <= b && b <= '9') {
				n *= 10;
				n += b - '0';
			} else if (b == -1 || !isPrintableChar(b)) {
				return minus ? -n : n;
			} else {
				throw new NumberFormatException();
			}
			b = readByte();
		}
	}

	public int nextInt() {
		long nl = nextLong();
		if (nl < Integer.MIN_VALUE || nl > Integer.MAX_VALUE)
			throw new NumberFormatException();
		return (int) nl;
	}

	public double nextDouble() {
		return Double.parseDouble(next());
	}
}


Measured memory_bytes: 22228
N,K,Q=gets.split.map(&:to_i)
point_count=Array.new(N,0)

Q.times {
    answer=gets.to_i
    point_count[answer-1]+=1
}

point_count.each {|a|
    if K-(Q-a)>0
        puts "Yes"
    else
        puts "No"
    end
}

Measured memory_bytes: 3196
n=int(input())
x=[]
for i in range(n):
    a,b,c=map(int,input().split())
    x.append([a,b,c])
dp=[[0]*3 for i in range(n+1)]
for i in range(n):
    dp[i+1][0]=max(max(dp[i][1],dp[i][2])+x[i][0],dp[i+1][0])
    dp[i+1][1]=max(max(dp[i][0],dp[i][2])+x[i][1],dp[i+1][1])
    dp[i+1][2]=max(max(dp[i][1],dp[i][0])+x[i][2],dp[i+1][2])

print(max(dp[-1]))

Measured memory_bytes: 74584
import math

A, B = map(int, input().split())

# 消費税が8%のときA円になる税抜き価格xの範囲
per8_list = []
for i in range(math.ceil(A / 0.08), math.ceil(A / 0.08)+13):
  if math.floor(i*0.08) == A:
    per8_list.append(i)
per8_set = set(per8_list)
per10_set = set(range(math.ceil(B / 0.1), math.ceil(B / 0.1)+10))

x = per8_set & per10_set

if len(x) == 0:
  print(-1)
else:
  print(min(x))

Measured memory_bytes: 3188
#include <iostream>
#include <vector>
#include <utility>
#include <algorithm>
#include <cmath>
#include <queue>
#include <string>
#include <set>
#include <map>
#include <cassert>
#include <fstream>
#include <iomanip>

using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;

const ll mod = 1e9 +7;


int main() {
    
    ll n, m;
    
    cin >> n >> m;
    
    vector<vector<ll>> dp(m, vector<ll>(1 << n, mod));
    
    for (int i = 0; i < m; ++i)
    {
        ll a, b;
        cin >> a >> b;
        vector<ll> c(b);
        ll cur = 0;
        for (int j = 0; j < b; ++j)
        {
            ll tmp;
            cin >> tmp;
            tmp--;
            cur |= (1 << tmp);
        }
        dp[i][0] = 0;
        if (i != 0)
        {
            dp[i] = dp[i - 1];
        }
        for (int j = 0; j < 1 << n; ++j)
        {
            dp[i][j | cur] = min(dp[i][j | cur], dp[i][j] + a);
        }
    }
    
    if (dp[m - 1][(1 << n) - 1] >= mod)
    {
        cout << -1 << endl;
        return 0;
    }
    
    cout << dp[m - 1][(1 << n) - 1] << endl;
    
    return 0;
}

Measured memory_bytes: 32256
import sys

def wantp(n):

    nq = []
    while n != p[n]:
        nq.append(n)
        n = p[n]

    for i in nq:
        p[i] = n

    return n


N = int(input())

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

A2 = []
B2 = []

for i in range(N):

    A2.append([A[i],i])
    B2.append([B[i],i])

A2.sort()
B2.sort()

p = [i for i in range(N)]
rank = [1] * N

for i in range(N):

    if A2[i][0] > B2[i][0]:
        print ("No")
        sys.exit()

for i in range(N):

    na = A2[i][1]
    nb = B2[i][1]

    ap = wantp(na)
    bp = wantp(nb)

    if ap != bp:

        if rank[ap] > rank[bp]:
            p[bp] = ap

        elif rank[bp] > rank[ap]:
            p[ap] = bp

        else:
            p[ap] = bp
            rank[bp] += 1

nloop = 0

for i in range(N):

    if p[i] == i:
        nloop += 1

if nloop != 1:
    print ("Yes")
    sys.exit()


for i in range(N-1):

    if B2[i][0] >= A2[i+1][0]:
        print ("Yes")
        sys.exit()

print ("No")


Measured memory_bytes: 99984
#include<iostream>
#include<algorithm>
#include<cstdio>
#include<fstream>
#include<cstdlib>
#include<iomanip>
#include<string>
#include<cstring>
#include<cmath>
#include<cfloat>
using namespace std;

int main()
{
    int n;
    cin>>n;
    int hb=0,maxi=0;
    for(int i=0;i<n;i++)
    {
        char t;
        cin>>t;
        if(t=='I')hb++;
        else if(t=='D')hb--;
        maxi=max(maxi,hb);
    }
    cout<<maxi;
	exit(0);
}

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

int main() {
    int N, a, count;
    cin >> N;

    count = 0;
    for (int i=1; i<=N; i++) {
        cin >> a;
        if (i%2 == 1 && a%2 == 1) {
            count++;
        }
    }
    cout << count << endl;

    return 0;
}

Measured memory_bytes: 3620
#include <iostream>
#include <cstdio>
#include <vector>

using namespace std;
int main(void){
    
    vector<int> p4;
    int c = 1, t = 0;
    while (1) {
        t = c*(c+1)*(c+2)/6;
        if (t >= 1e6) break;
        p4.push_back(t);
        c++;
    }
    
    int a[1010101] = {};
    int b[1010101] = {};
    for (int i = 1; i < 1010101; i++) {
        a[i] = 1e6;
        b[i] = 1e6;
    }
    
    for (int i = 0; i < 1010101; i++) {
        for (int j = 0; j < p4.size(); j++) {
            int t = i + p4[j];
            if (t > 1010101) break;
            a[t] = min(a[t], a[i]+1);
            if (p4[j]&1) b[t] = min(b[t], b[i]+1);
        }
    }
    int n;
    while (cin>>n && n) {
        cout << a[n] << " " << b[n] << endl;
    }
}

Measured memory_bytes: 11024
import math
a,b,h,m = map(int,input().split())

#h_k = h * 30
h_k = h * 360/12 + m * 1/2
m_k = m * 360/60

if m == 0:
    m_k = 360
#else:
 #   m_k = m * 6

kakudo = abs(h_k - m_k)
#print(kakudo)
result = math.sqrt(a*a + b*b -2*(a * b *math.cos(math.radians(kakudo)) ))
print(result)

Measured memory_bytes: 9544
import java.util.*;
import java.io.*; 
import java.text.*;
//Solution Credits: Taranpreet Singh
public class Main{
    //SOLUTION BEGIN
    void solve(int TC) throws Exception{
        int n = ni(), k = ni();
        long ans = IINF;
        long[] a = new long[n];
        for(int i = 0; i< n; i++)a[i] = nl();
        for(int i = k-1; i< n; i++){
            long mi = a[i-k+1], ma = a[i];
            if(Math.max(mi, ma)<=0)ans = Math.min(ans, -mi);
            else if(Math.min(mi, ma)>=0)ans = Math.min(ans, ma);
            else
                ans = Math.min(ans, ma-mi + Math.min(ma, -mi));
        }
        pn(ans);
    }
    //SOLUTION ENDS
    long mod = (int)1e9+9, IINF = (long)1e17;
    final int MAX = (int)1e5+1, INF = (int)1e9, root = 3;
    DecimalFormat df = new DecimalFormat("0.00000000");
    double PI = 3.141592653589793238462643383279502884197169399375105820974944, eps = 1e-8;
    static boolean multipleTC = false, memory = true;
    FastReader in;PrintWriter out;
    void run() throws Exception{
        in = new FastReader();
        out = new PrintWriter(System.out);
        int T = (multipleTC)?ni():1;
        //Solution Credits: Taranpreet Singh
        for(int i = 1; i<= T; i++)solve(i);
        out.flush();
        out.close();
    }
    public static void main(String[] args) throws Exception{
        if(memory)new Thread(null, new Runnable() {public void run(){try{new Main().run();}catch(Exception e){e.printStackTrace();}}}, "1", 1 << 28).start();
        else new Main().run();
    }
    long gcd(long a, long b){return (b==0)?a:gcd(b,a%b);}
    int gcd(int a, int b){return (b==0)?a:gcd(b,a%b);}
    int bit(long n){return (n==0)?0:(1+bit(n&(n-1)));}
    void p(Object o){out.print(o);}
    void pn(Object o){out.println(o);}
    void pni(Object o){out.println(o);out.flush();}
    String n(){return in.next();}
    String nln(){return in.nextLine();}
    int ni(){return Integer.parseInt(in.next());}
    long nl(){return Long.parseLong(in.next());}
    double nd(){return Double.parseDouble(in.next());}

    class FastReader{
        BufferedReader br;
        StringTokenizer st;
        public FastReader(){
            br = new BufferedReader(new InputStreamReader(System.in));
        }

        public FastReader(String s) throws Exception{
            br = new BufferedReader(new FileReader(s));
        }

        String next(){
            while (st == null || !st.hasMoreElements()){
                try{
                    st = new StringTokenizer(br.readLine());
                }catch (IOException  e){
                    e.printStackTrace();
                }
            }
            return st.nextToken();
        }

        String nextLine(){
            String str = "";
            try{    
                str = br.readLine();
            }catch (IOException e){
                e.printStackTrace();
            }   
            return str;
        }
    }
}

Measured memory_bytes: 38672
use std::str::FromStr;
use std::collections::{HashMap,HashSet,VecDeque,BinaryHeap};
use std::cmp::{max,min,Ordering};
use std::io::Read;

fn main() {

    let mut buf = String::new();
    std::io::stdin().read_to_string(&mut buf).unwrap();
    let mut buf_it = buf.split_whitespace();

    let N = buf_it.next().unwrap().parse::<usize>().unwrap();

    let mut P = Vec::new();
    P.push(Point{x:0.0,y:0.0});
    P.push(Point{x:100.0,y:0.0});
    
    for _ in 0..N{
        let M = P.len();
        let mut Q = Vec::new();
        for i in 0..M-1{
            split(&mut Q,&P[i],&P[i+1]);
        }
        Q.push(P[M-1].clone());
        P = Q;
    }

    for p in &P{
        p.print();
    }

}

#[derive(Clone,Debug)]
struct Point{
    x:f64,
    y:f64,
}

impl Point{
    fn print(&self){
        println!("{} {}",self.x,self.y);
    }
}

fn split(P:&mut Vec<Point>,a:&Point,b:&Point){
    let d = 1.0/(12.0f64.sqrt());
    P.push(a.clone());
    P.push(Point{x:(2.0*a.x+b.x)/3.0,y:(2.0*a.y+b.y)/3.0});
    P.push(Point{x:(a.x+b.x)/2.0-(b.y-a.y)*d,y:(a.y+b.y)/2.0+(b.x-a.x)*d});
    P.push(Point{x:(a.x+2.0*b.x)/3.0,y:(a.y+2.0*b.y)/3.0});
}


Measured memory_bytes: 5060
def main():
    a, b, q = map(int, input().rstrip("\n").split(" "))

    jinja_list = []

    for i in range(a):
        jinja_list.append(int(input().rstrip("\n")))

    temple_list = []
    for i in range(b):
        temple_list.append(int(input().rstrip("\n")))

    from bisect import bisect

    for i in range(q):
        pos = int(input().rstrip("\n"))

        jinja_index = bisect(jinja_list, pos)
        jinja_left = jinja_list[jinja_index - 1:jinja_index]
        jinja_right = jinja_list[jinja_index:jinja_index + 1]

        temple_index = bisect(temple_list, pos)
        temple_left = temple_list[temple_index - 1:temple_index]
        temple_right = temple_list[temple_index:temple_index + 1]

        distances = []
        #distances.append((pos, jinja_left, jinja_right, temple_left, temple_right))
        if jinja_left and temple_left:
            distances.append(pos - min(jinja_left[0], temple_left[0]))
            #distances.append("jinja_left and temple_left")
        if jinja_right and temple_right:
            distances.append(max(jinja_right[0], temple_right[0]) - pos)
            #distances.append("jinja_right and temple_right")
        if jinja_left and temple_right:
            left_right = abs(pos - jinja_left[0]) + abs(temple_right[0] - jinja_left[0])
            right_left = abs(pos - temple_right[0]) + abs(jinja_left[0] - temple_right[0])
            distances.append(left_right)
            distances.append(right_left)
            #distances.append("jinja_left and temple_right")
        if jinja_right and temple_left:
            left_right = abs(pos - temple_left[0]) + abs(jinja_right[0] - temple_left[0])
            right_left = abs(pos - jinja_right[0]) + abs(temple_left[0] - jinja_right[0])
            distances.append(left_right)
            distances.append(right_left)
            #distances.append("jinja_right and temple_left")
        #print(distances)
        print(min(distances))
        
if __name__ == '__main__':
    main()


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

//cmdで g++ test.cpp とするとコンパイルできる
typedef long long ll;

const int MOD=1000000007;



//https://qiita.com/ofutonfuton/items/92b1a6f4a7775f00b6ae

ll mpow(ll x, ll n){ //x^n(mod M) ←普通にpow(x,n)では溢れてしまうため，随時mod計算
    ll ans = 1;
    while(n != 0){
        if(n&1) ans = ans*x % MOD;
        x = x*x % MOD;
        n = n >> 1;
    }
    return ans;
}

int main() {
    int n,a,b;
    cin>>n>>a>>b;
    ll ans;
    ans=mpow(2,n)-1;

    ll p=1,q=1;
    ll pa,qa;
    for(int i=1;i<=b;i++){
        p*=i;
        p%=MOD;
        if(i==a)pa=p;
    }
    for(int i=n;i>=n-b+1;i--){
        q*=i;
        q%=MOD;
        if(i==n-a+1)qa=q;
    }
    ans-=qa*mpow(pa,MOD-2)%MOD;
    if(ans<0)ans+=MOD;
    ans-=q*mpow(p,MOD-2)%MOD;
    if(ans<0)ans+=MOD;
    cout<<ans<<endl;
}


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

#define pb push_back
#define mp make_pair
#define fs first
#define se second
#define pi 2*acos(0)
#define PI 3.14159265358979323846264338

typedef long long ll;
typedef unsigned long long ull;
typedef pair < int , int > pii;
typedef pair < ll , ll > pll;

const int N = 100010;
const int MX = 123456;
const int mod = (int)1e9 + 7;
const int base = 1023456789;
const ull BS1 = 10000019ULL;
const int INF = (1 << 29);

template < class T > inline void fastScan(T &x){
    register char c = getchar();
    int neg = 0; x = 0;
    for(   ; (c < 48 || c > 57) && (c != '-'); c = getchar());
    if(c == '-') { neg = 1; c = getchar(); }
    for(   ; c > 47 && c < 58; c = getchar()){
        x = (x << 1) + (x << 3) + c - 48;
    }
    if(neg) x = -x;
}

int n;
int lft, rgt;
ll inp[N];
ll arr[N + N];

ll f(ll v){
    return max(llabs(v - arr[lft]), llabs(v - arr[rgt]));
}

void P(ll v){
    if(llabs(v - arr[lft]) > llabs(v - arr[rgt])){
        lft--;
        arr[lft] = v;
    } else {
        rgt++;
        arr[rgt] = v;
    }
}

int main(){
    fastScan(n);
    for(int i = 1; i <= n; i++){
        fastScan(inp[i]);
    }
    sort(inp + 1, inp + n + 1);
    ll ans = 0;
    arr[n] = inp[1];
    lft = n; rgt = n;
    int l = 2, r = n;
    while(l <= r){
        if(f(inp[l]) > f(inp[r])){
            ans += f(inp[l]);
            P(inp[l]);
            l++;
        } else {
            ans += f(inp[r]);
            P(inp[r]);
            r--;
        }
    }
    printf("%lld\n", ans);
}


Measured memory_bytes: 1792
#include <stdio.h>
int main(int argc, char const *argv[]) {
  int num[2];
  int i,j,tmp;
  scanf("%d%d%d\n",&num[0],&num[1],&num[2]);

  for(i=0;i<2;i++){
    for(j=2;j>i;j--){
      if(num[j-1]>num[j]){
        tmp=num[j];
        num[j]=num[j-1];
        num[j-1]=tmp;
      }
    }
  }
  printf("%d %d %d\n",num[0],num[1],num[2]);

  return 0;
}

Measured memory_bytes: 600
def getInv(N):
    inv = [0] * (N + 1)
    inv[1] = 1
    for i in range(2, N + 1):
        inv[i] = (-(Q // i) * inv[Q % i]) % Q
    return inv

from itertools import accumulate
N = int( input())
A = list( map( int, input().split()))
Q = 10**9 + 7
fact = [1]*(N+1)
invs = getInv(N)
accI = [0]*(N+1)
for i in range(N):
    fact[i+1] = fact[i]*(i+1)%Q
    accI[i+1] = (accI[i]+invs[i+1])%Q
factN = fact[-1]
ans = 0
for i in range(N):
    C = factN*(accI[i+1] + accI[N-i]-1)*(A[i]%Q)%Q
    ans += C
    ans %= Q
print(ans)

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

using namespace std;

int main(){
	vector<int> dp1(1000000,1000000);
	dp1[0] = 0;
	vector<int> dp2(1000000,1000000);
	dp2[0] = 0;
	for(int i=1;i*(i+1)*(i+2)/6<1000000;i++){
		int x = i*(i+1)*(i+2)/6;
		for(int j=0;j<1000000-x;j++){
			dp1[j+x] = min(dp1[j+x],dp1[j] + 1);
			if(x%2 == 1) dp2[j+x] = min(dp2[j+x],dp2[j] + 1);
		}
	}
	
	int a;
	while(cin >> a,a > 0){
		cout << dp1[a] << " " << dp2[a] << endl;
	}
	
	return 0;
}



Measured memory_bytes: 10528
#include <bits/stdc++.h>
using namespace std;
//define
#define int long long
#define UNIQUE(v) v.erase(unique(all(v)), v.end());
#define ZIP(v) sort(all(v)),UNIQUE(v)
#define ADD(a, b) a = (a + b) % mod
#define SUB(a, b) a = (a+mod-b)%mod
#define MUL(a, b) a = (a * b) % mod
#define repi(i,m,n) for(int i = m;i < n;i++)
#define drep(i,n,m) for(int i = n;i >= m;i--)
#define rep(i,n) repi(i,0,n)
#define rrep(i,n) repi(i,1,n+1)
#define chmin(x,y) x = min(x,y)
#define chmax(x,y) x = max(x,y)
#define all(v) v.begin(),v.end()
#define rall(v) v.rbegin(), v.rend()
#define dmp(x,y) make_pair(x,y)
#define pb(x) push_back(x)
#define fi first
#define se second
// 許容する誤差ε
#define EPS (1e-10)
// 2つのスカラーが等しいかどうか
#define EQ(a,b) (abs((a)-(b)) < EPS)
// 2つのベクトルが等しいかどうか
#define EQV(a,b) ( EQ((a).real(), (b).real()) && EQ((a).imag(), (b).imag()) )
//template
template <typename T, typename U>
ostream &operator<<(ostream &os, const pair<T, U> &p){
  os << "(" << p.first << "," << p.second << ")";return os;
}
template <typename T>
ostream &operator<<(ostream &os, const vector<T> &v){
  for (auto it = v.begin();it != v.end();++it){
    if(it != v.begin())os << " ";os << *it;
      }return os;
}
template <typename T, typename U>
ostream &operator<<(ostream &os, const map<T, U> &mp){
  for(auto x: mp)os << "(" << x.first << "," << x.second << ")" << endl;
  return os;
}
template<typename T, int SIZE>
int array_length(const T (&)[SIZE]){return SIZE;}
template<typename T, int N>
void PRINTF(const T (&a)[N], int s = N, int t = -1, bool f = true){
	if(t == -1){rep(i,s){if(i)cout << " ";cout << a[i];}}
	else repi(i,s,t){if(i!=s)cout << " ";cout << a[i];}
	if(f)cout << "\n";
}
template<typename T, int N1, int N2>
void PRINTF(const T (&a)[N1][N2], int h = N1, int w = N2){
	rep(i,h){rep(j,w){cout << a[i][j] << " \n"[j==w-1];}}
}
//typedef
typedef complex<double> Point;
typedef pair<int,int> P;
typedef pair<int, P> PP;
typedef pair<P, int> Pi;
typedef vector<int> vi;
typedef deque<int> dq;
const int inf = 1e9+7;
const int INF = 1e18+7;


vi get_bit(int s){
  vector<int> vec;
  while(s > 0){
    vec.pb(s%2);s /= 2;
  }
  reverse(all(vec));
  return vec;
}
deque<int> d[2];
signed main(){
  int n;
  scanf("%lld", &n);
  vi vec = get_bit(n);
  int num = 1;
  if(n == 1){printf("2\n1 1\n");return 0;}
  
  d[0].push_back(num);d[1].push_front(num);num++;
  if(vec[1] == 1){d[0].pb(num);d[1].push_front(num);num++;}
  repi(i,2,vec.size()){
    d[0].push_front(num);d[1].push_front(num);num++;
    if(vec[i]){d[0].pb(num);d[1].push_front(num);num++;}
  }
  d[0].pb(num);d[1].push_front(num);num++;
  
  int m = d[0].size()*2;
  vector<int> ans;
  rep(i,m/2){ans.pb(d[0].front());d[0].pop_front();}
  rep(i,m/2){ans.pb(d[1].front());d[1].pop_front();}
  printf("%lld\n", m);
  rep(i,m){
    printf("%lld%c", ans[i], " \n"[i == m-1]);
  }
	return 0;
}









Measured memory_bytes: 256
import sys


def solve(inp):
    S = inp.readline()

    alphas = {}
    for c in S:
        if c not in alphas:
            alphas[ord(c)] = 0
        alphas[ord(c)] += 1

    for c in range(ord('a'), ord('z') + 1):
        if c not in alphas:
            return chr(c)

    return "None"


def main():
    result = solve(sys.stdin)
    if result:
        print(result)


if __name__ == '__main__':
    main()


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

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

#define FOR(i, s, e) for (ll(i) = (s); (i) < (e); (i)++)
#define FORR(i, s, e) for (ll(i) = (s); (i) > (e); (i)--)
#define debug(x) cout << #x << ": " << x << endl
#define mp make_pair
#define pb push_back
const ll MOD = 1000000007;
const int INF = 1e9;
const ll LINF = 1e16;
const double PI = acos(-1.0);
int dx[8] = {0, 0, 1, -1, 1, 1, -1, -1};
int dy[8] = {1, -1, 0, 0, 1, -1, 1, -1};

/* -----  2017/04/22  Problem: ARC 072 B / Link: http://arc072.contest.atcoder.jp/tasks/arc072_b  ----- */
/* ------問題------



-----問題ここまで----- */
/* -----解説等-----



----解説ここまで---- */

ll N,M;

ll ans = 0LL;

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

  cin >> N>>M;
  if (N > M) swap(N, M);
  if (M == N || M == N + 1) cout << "Brown" << endl;
  else cout << "Alice" << endl;
  return 0;
  cout << ans << endl;

  return 0;
}


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

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

	ll N;
	ll i,k,l;
	ll ans=0;
	ll ctr=0;

	cin >> N;

	vector<ll> gv(N);
	rep(i,N) cin >> gv[i];

	for(i=0;i<N-2;i++){
		for(k=i+1;k<N-1;k++){
			for(l=k+1;l<N;l++){
				//if((gv[i]*gv[i])==(gv[k]*gv[k])+(gv[l]*gv[l])){
				if(gv[i]+gv[k]>gv[l] && gv[k]+gv[l]>gv[i] && gv[l]+gv[i]>gv[k] && gv[i]!=gv[k] && gv[k]!=gv[l] && gv[i]!=gv[l]){
					ctr++;
					/*
					cout << "---" << endl;
					cout << gv[i] << " " << gv[k] << " " << gv[l] << " " << endl;
					cout << i+1 << " " << k+1 << " " << l+1 << " " << endl;
					*/
				}
			}
		}
	}

	ans=ctr;
	cout << ans << endl;

	return 0;
}



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

using namespace std;

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

  int n, h;
  cin >> n;
  set<int> hash;
  for (int i = 0; i < n; ++i) {
    cin >> h;
    hash.insert(h);
  }
  cout << hash.size() << endl;


  return 0;
}



Measured memory_bytes: 256
import math
N, M = map(int, input().split())
ulim = M//N
mid = int(math.sqrt(M))
if ulim >= mid:
    ans = []
    for i in range(1, mid+1):
        if M%i == 0:
            ans.append(i)
            if M//i <= ulim:
                ans.append(M//i)
    print(max(ans))
 
else:
    for i in reversed(range(1, ulim+1)):
        if M%i == 0:
            print(i)
            break

Measured memory_bytes: 3064
/*
Hokudai Practice Contest 2014
H - Altair and Vega

ティツァツ」テヲツウツ陛ッツシツ堙ァツつケテ」ツ?ョテ・ツ??・ツ個?・ツ按、テ・ツョツ?
ティツィツ暗ァツョツ療・ツケツセテ、ツスツ陛」ツ?ョテ・ツ閉湘ゥツ。ツ古」ツ??
テァツつケテ」ツ?古、ツクツ嘉ィツァツ津・ツスツ「テ」ツ?ォテ・ツ??・ツ個?」ツ?陛」ツつ古」ツ?ヲテ」ツ??」ツつ凝」ツ?凝」ツつ津・ツ按、テ・ツョツ堙」ツ?ァテ」ツ?催」ツつ古」ツ?ーテ」ツつ暗」ツ??」ツ??
テ・ツ??・ツ個?・ツ按、テ・ツョツ堙」ツ?ォテ」ツ?ッテ」ツ??」ツつ催」ツ??」ツつ催」ツ?ェテヲツ鳴ケテヲツウツ陛」ツ?古」ツ?づ」ツつ凝」ツ?古」ツ??
 |テ「ツ鳴ウabc| = |テ「ツ鳴ウabx| + |テ「ツ鳴ウbcx| + |テ「ツ鳴ウcax|
テ」ツ?古ヲツ按静」ツつ甘ァツォツ凝」ツ?」テ」ツ?ヲテ」ツ??」ツつ凝」ツ?凝」ツ?ゥテ」ツ??」ツ?凝」ツつ津」ツδ?」ツつァテ」ツδε」ツつッテ」ツ?凖」ツつ凝ヲツ鳴ケテヲツウツ陛」ツ?古ァツーツ。テ・ツ債佚」ツ?ァテ」ツ?づ」ツつ凝」ツ??

テァツ可ステァツ可崚」ツ?ィテァツケツ氾・ツ・ツウテ」ツ?古」ツ?ィテ」ツつづ」ツ?ォテ・ツ青古」ツ?佚、ツクツ嘉ィツァツ津・ツスツ「テ」ツ?ォテ・ツ青ォテ」ツ?セテ」ツつ古」ツつ凝」ツつアテ」ツδシテ」ツつケテ」ツ?ォテヲツウツィテヲツ?湘」ツ?凖」ツつ凝」ツ??

テ・ツケツセテ、ツスツ陛・ツ閉湘ゥツ。ツ古」ツ?ィテ」ツ?療」ツ?ヲテ」ツ?ッテ」ツ?凝」ツ?ェテ」ツつ甘・ツ按敕ァツュツ嘉」ツ?ョテ・ツ閉湘ゥツ。ツ古」ツ?ァテ」ツ?！CPCテ」ツ?ァテ・ツョツ淌ゥツ堋崚」ツ?ォテ・ツ?コテゥツ。ツ古」ツ?陛」ツつ古」ツつ凝・ツケツセテ、ツスツ陛」ツ?ッテヲツ閉ーテヲツョツオテゥツ崢」テ」ツ?療」ツ??」ツ??

テヲツ卍づゥツ鳴禿ィツィツ暗ァツョツ療ゥツ?湘ッツシツ唹(1)
*/

#include<iostream>
#include<complex>
using namespace std;

//テ・ツケツセテ、ツスツ陛・ツ閉湘ゥツ。ツ古」ツ?ァテ」ツ?ッテゥツ?づァツつケテ」ツつ津ィツ。ツィテ」ツ?凖」ツ?ョテ」ツ?ォcomplexテ・ツ楪?ティツ、ツ?ァツエツ?ヲツ閉ーテ・ツ楪?テ」ツつ津ァツ板ィテ」ツ??」ツつ凝」ツ?禿」ツ?ィテ」ツ?古」ツ?ァテ」ツ?催」ツつ?
//ティツ、ツ?ァツエツ?ヲツ閉ーテ」ツつ津」ツ??ィツ、ツ?ァツエツ?・ツケツウテゥツ敖「テ、ツクツ甘」ツ?ョテ」ツδ凖」ツつッテ」ツδ暗」ツδォテ」ツ?ィティツヲツ凝」ツ?ェテ」ツ?療」ツ?ヲテ・ツ?ヲテァツ青?」ツ?凖」ツつ?
//テ、ツセツソテ・ツ按ゥテ」ツ?ェテゥツ鳴「テヲツ閉ーテ」ツ?ィテ」ツ?療」ツ?ヲテ」ツ??・ツ環?ヲツクツ崚ァツョツ療」ツつ?」ツつケテ」ツつォテ」ツδゥテ」ツδシテ・ツ?催」ツ??ァツオツカテ・ツッツセテ・ツ?、ティツィツ暗ァツョツ療」ツ?ェテ」ツ?ゥテ」ツ?古・ツ按ゥテァツ板ィテ」ツ?ァテ」ツ?催」ツつ?
typedef complex<double> P;
const double EPS = 1e-9;

//テ・ツ、ツ姪ァツゥツ?
double cross(P x,P y){return real(x)*imag(y) - imag(x)*real(y);}

//テ、ツクツ嘉ィツァツ津・ツスツ「テ」ツ?ョテゥツ敖「テァツゥツ?
double area(P a,P b,P c){ return abs(cross(b-a,c-a)/2); }

//テ、ツクツ嘉ィツァツ津・ツスツ「abcテ」ツ?ォテァツつケxテ」ツ?古・ツ青ォテ」ツ?セテ」ツつ古」ツ?ヲテ」ツ??」ツつ凝」ツ?凝」ツ?ゥテ」ツ??」ツ?凝」ツつ津・ツ按、テ・ツョツ?
bool inter(P a,P b,P c,P x){
  //テヲツオツョテ・ツ仰陛・ツーツ湘ヲツ閉ーテァツつケテヲツシツ氾ァツョツ療」ツ?ァテ」ツ?ッティツェツ、テ・ツキツョテ・ツ?ヲテァツ青?」ツつ津ィツ。ツ古」ツ??
  //テ」ツ?警 > y +EPSテ」ツ?催」ツ?ッテゥツ?堙・ツクツクテ」ツ?ョティツィツ暗ァツョツ療」ツ?ォテ」ツ?甘」ツ?妥」ツつ凝」ツ?警>yテ」ツ?催」ツ?ォテ・ツスツ禿」ツ?淌」ツつ?
  //テ」ツ?警 > y -EPSテ」ツ?催」ツ?づ」ツつ凝」ツ??」ツ?ッテ」ツ?警 +EPS > yテ」ツ?催」ツ?ッテゥツ?堙・ツクツクテ」ツ?ョティツィツ暗ァツョツ療」ツ?ォテ」ツ?甘」ツ?妥」ツつ凝」ツ?警>=yテ」ツ?催」ツ?ォテ・ツスツ禿」ツ?淌」ツつ?
  if( area(a,b,x) + area(b,c,x) + area(c,a,x) > area(a,b,c) + EPS)return false;
  return true;
}

int main(){
  int n;
  P p1,p2,p3,pk,ps;

  cin >> n;

  for(int i=0;i<n;i++){
    double x,y;
    cin >> x >> y; p1 = P(x,y);
    cin >> x >> y; p2 = P(x,y);
    cin >> x >> y; p3 = P(x,y);
    cin >> x >> y; pk = P(x,y);
    cin >> x >> y; ps = P(x,y);

    //テ、ツクツ嘉ィツァツ津・ツスツ「テ」ツ?ォテ・ツ青古ヲツ卍づ」ツ?ォテ・ツ青ォテ」ツ?セテ」ツつ古」ツ?ヲテ」ツ??」ツ?ェテ」ツ??」ツ?凝・ツ按、テ・ツョツ?
    if(inter(p1,p2,p3,pk) != inter(p1,p2,p3,ps) )cout << "OK" << endl;
    else cout << "NG" << endl;
  }
  
}

Measured memory_bytes: 1224