akhauriyash/Code-Regression huggingface dataset:
import sys

input = sys.stdin.readline


def main():
    N = int(input())
    S = input().rstrip()

    n_E = S.count("E")

    ans = N
    n_W = 0
    for i in range(N):
        if S[i] == "E":
            n_E -= 1
        num = n_E + n_W
        if num < ans:
            ans = num
        if S[i] == "W":
            n_W += 1

    print(ans)


if __name__ == "__main__":
    main()


Measured memory_bytes: 3676
#include <bits/stdc++.h>
#define rep(i, n) for (int i=0; i<(int)(n); i++)
#define all(v) v.begin(), v.end()
#define PRINT(v) for (auto x : (V)) cout <<x <<" " <<endl;
using namespace std;
using ll = long long;
using Graph = vector<vector<int>>;
const ll MOD = 1000000007;
const ll INF = 10000000000000000;
vector<int> x4 = {0, 1, 0, -1}, x8 = {0, 1, 1, 1, 0, -1, -1, -1};
vector<int> y4 = {1, 0, -1, 0}, y8 = {1, 1, 0, -1, -1, -1, 0, 1};
template<class T> struct edge { int from, to; T cost;};
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;}
template<class T> inline T powerM(T a,T b){if (b==0) return 1;
T tmp = powerM(a,b/2); if (b%2==0) return tmp*tmp%MOD; else return tmp*tmp%MOD*a%MOD; }
template<class T> inline T power(T a,T b,T m){ if (b==0) return 1;
  T tmp = power(a,b/2,m); if (b%2==0) return tmp*tmp%m; else return tmp*tmp%m*a%m; }
template<class T> inline T gcd(T a, T b){if (b==0) return a; return gcd(b, a%b);}
template<class T> inline T lcm(T a, T b){return a / gcd(a,b) * b;}
// ax+by=gcd(a,b)を解く
template<class T> inline T extgcd(T a,T b,T &x,T &y){if (b==0){x=1; y=0; return a;} T d=extgcd(b,a%b,y,x); y -= a/b*x; return d;}
void hey(){ cout <<"hey" <<endl; }


int magic(int x, vector<int> &l, vector<bool> &use){
  // 竹の集合l と どれを使用するかの情報 use から
  // 目標 x の竹にするためにどれだけの魔力を必要とするか計算
  // 但し l のサイズと use のサイズは同じとする
  int res = -10;
  int take = 0;
  rep(i, l.size()){
    if (use[i]){
      take += l[i];
      res += 10;
    }
  }
  if (res == -10) return 100000000;
  res += abs(take - x);
  return res;
}

int main() {
  int N,A,B,C; cin >>N >>A >>B >>C;
  vector<int> L(N); rep(i, N) cin >>L[i];
  int res = INT_MAX;
  // まず、使用する全体の竹を選ぶ
  vector<bool> use(N, false);
  vector<int> Labc;
  vector<bool> usea;
  vector<int> Lbc;
  vector<bool> useb;

  for (int S=1; S<(1<<N); S++){
    // 256通り以下
    use.assign(N, false);
    for (int i=0; i<N; i++) if (S & (1<<i)) use[i] = true;

    // 使用する竹が3本未満なら無理なので確認
    int num = 0;
    rep(i, N) num += use[i];
    if (num < 3) continue;

    // 選んだnum(<=8)本の竹からA,B,Cを生成したい
    Labc.assign(num, 0); // 使用するnum本の竹を格納
    {
      int ai = 0;
      rep(i, N) if (use[i]) Labc[ai++] = L[i];
    }

    // Aに使用する竹を選ぶ
    for (int Sa=1; Sa<(1<<num); Sa++){
      // 256通り以下
      usea.assign(num, false);
      for (int i=0; i<N; i++) if (Sa & (1<<i)) usea[i] = true;
      int resa = magic(A, Labc, usea);

      int numbc = num;
      rep(i, num) numbc -= usea[i];

      // 残りnumbc本からBとCを生成する
      Lbc.assign(numbc, 0); // BとCで使用するnumbc本の竹を格納
      {
        int ai = 0;
        rep(i, num) if (!usea[i]) Lbc[ai++] = Labc[i];
      }

      for (int Sb=1; Sb<(1<<numbc); Sb++){
        useb.assign(numbc, false);
        rep(i, numbc) if (Sb & (1<<i)) useb[i] = true;
        int resb = magic(B, Lbc, useb);
        rep(i, numbc) useb[i] = useb[i] ^ true;
        int resc = magic(C, Lbc, useb);
        chmin(res, resa + resb + resc);
      }
    }
  }
  cout <<res <<endl;
}


Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		// TODO ?????????????????????????????????????????????
		Scanner sc = new Scanner(System.in);
		int S = sc.nextInt();

		int h,m,s;

		int M = S / 60; // S?§????M???????§?
		s = S % 60;

		h = M / 60;
		m = M % 60; // M?????????????????????

		System.out.println(h + ":" + m + ":" + s);
	}

}

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

int main() {
	int n;
	cin >> n;
	int c[550], s[550], f[550];
	for (int i = 0;i < n - 1;i++)cin >> c[i] >> s[i] >> f[i];
	int time = 0;
	int t[550];
	for (int i = 0;i < n - 1;i++) {
		time = s[i];
		for (int j = i;j < n - 1;j++) {
			while (!(s[j] <= time && time%f[j] == 0))time++;
			time += c[j];
		}
		t[i] = time;
	}
	t[n - 1] = 0;
	for (int i = 0;i < n;i++)cout << t[i] << endl;
}

Measured memory_bytes: 256
class UnionFind:
	def __init__(self, n):
		self.groups = [g for g in range(n)]

	def get_root(self, i):
		parent = self.groups[i]
		if parent == i:
			return parent
		else:
			root = self.get_root(parent)
			self.groups[i] = root
			return root
	
	def set_root(self, i, root):
		parent = self.groups[i]
		self.groups[i] = root
		if parent == i:
			return
		else:
			self.set_root(parent, root)
	
	def combine(self, i1, i2):
		self.set_root(i2, self.get_root(i1))
	
	def in_same_group(self, i1, i2):
		return self.get_root(i1) == self.get_root(i2)
	
	def to_dic(self):
		table = {}
		for i in range(len(self.groups)):
			g = self.get_root(i)
			if g in table:
				table[g].append(i)
			else:
				table[g] = [i]
		return table
	
	def to_list(self):
		table = self.to_dic()
		return [table[g] for g in table]





N, M = map(int, input().split())
ab_list = []
for i in range(N):
	a, b = map(int, input().split())
	ab_list.append((b, a))
ab_list.sort()
ab_list.reverse()

index_list = UnionFind(M)
used_list = [False] * M

reward = 0
for b, a in ab_list:
	index = M - a
	prev_index = None
	while index >= 0:
#		print(index, M, a, N)
		if not used_list[index]:
			used_list[index] = True
			reward += b
			break
		if prev_index != None:
			index_list.combine(index, prev_index)
		prev_index = index
		index = index_list.get_root(index) - 1

print(reward)


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

#define FOR(i, a, b) for(int i=(a); i<(b); i++)
#define RFOR(i, a, b) for(int i=(a); i>=(b); i--)
#define REP(i, n) FOR(i, 0, n)
#define RREP(i, n) RFOR(i, n, 0)
#define CEIL(n, m) ceil(n/pow(10.0, m))*pow(10.0, m)
#define FLOOR(n, m) floor(n/pow(10.0, m))*pow(10.0, m)
#define ROUND(n, m) round(n/pow(10.0, m))*pow(10.0, m)
#define ALL(x) (x).begin(),(x).end()
#define SORT(x) sort((x).begin(),(x).end())
#define RSORT(x) sort((x).begin(),(x).end(),greater<int>())
#define SZ(x) ((int)(x).size())
#define UNIQUE(v) v.erase( unique(v.begin(), v.end()), v.end() );
#define llong long long
#define dump(x)  cout << #x << " = " << (x) << endl;
#define debug(x) cout << #x << " = " << (x) " (L" << __LINE__ << ") " << __FILE__ << endl;

void solve()
{
  int ans=0;

  int n; cin >> n;
  vector<int> a(n); REP(i, n) cin >> a[i];
  vector<int> pre(n+1, 0);
  vector<int> suf(n+1, 0);

  for(int i=1; i<=n; i++) {
    pre[i] = __gcd(pre[i-1], a[i-1]);
  }
  for(int i=n; i>=1; i--) {
    suf[i-1] = __gcd(suf[i], a[i-1]);
  }
  for(int i=0; i<=n; i++) {
  }
  for(int i=1; i<=n; i++) {
    ans = max(ans, __gcd(pre[i-1], suf[i]));
  }

  cout << ans << endl;
}

int main()
{
  solve();
  return 0;
}


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

#define dv(i) for (int c=0; c<(int)(i).size(); c++) cout<<(i)[c]<<(c==(int)(i).size()-1?"\n":" ")
#define dm(i) for (auto f: i) cout<<f.first<<" "<<f.second<<"\n"
#define FOR(i, a, b) for (int i=a; i<(b); i++)
#define F0R(i, a) for (int i=0; i<(a); i++)
#define FORd(i,a,b) for (int i = (b)-1; i >= a; i--)
#define F0Rd(i,a) for (int i = (a)-1; i >= 0; i--)

typedef long long ll;
typedef long double ld;
typedef complex<ld> cd;

typedef pair<int, int> pi;
typedef pair<ll,ll> pl;
typedef pair<ld,ld> pd;

typedef vector<int> vi;
typedef vector<string> vs;
typedef vector<ld> vd;
typedef vector<ll> vl;
typedef vector<pi> vpi;
typedef vector<pl> vpl;
typedef vector<cd> vcd;

#define sz(x) (int)(x).size()
#define mp make_pair
#define pb push_back
#define f first
#define s second
#define lb lower_bound
#define ub upper_bound
#define all(x) x.begin(), x.end()
#define alp(i) (i),(i)+sizeof((i))/sizeof((i)[0])

const int MOD = 1000000007;

int main() {
    ios_base::sync_with_stdio(false); cin.tie(0);
    ll D,N; cin>>D>>N;
    if (N<=99) cout<<(ll)pow(100,D)*N<<'\n';
    else cout<<(ll)pow(100,D)*101<<'\n';
    return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
int main(){
int i,a[5],b[2];
 for(i=0;i<5;i++){
        scanf("%d",&a[i]);}
if(a[0]-a[1]>=0){b[0]=a[1];}
else {b[0]=a[0];}
if(b[0]-a[2]>=0){b[0]=a[2];}

if(a[3]-a[4]>=0){b[1]=a[4];}
else{b[1]=a[3];}

printf("%d\n",b[0]+b[1]-50);
return 0;
}

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

using namespace std;

int main(){
    int a, b;
    cin >> a>> b;

    int sum = a + b;
    int diff = a - b;
    int mul = a * b;

    int max = sum;

    if(max < diff){
        max = diff;
    }
    if(max < mul){
        max = mul;
    }

    cout << max << endl;
}

Measured memory_bytes: 256
<?php

fscanf(STDIN, '%d %d', $row, $column);
fscanf(STDIN, '%d %d', $inputRow, $inputColumn);

$cells = $row * $column;

$blackCells = $inputRow * $column + $inputColumn * $row - $inputRow * $inputColumn;

$whiteCells = $cells - $blackCells;

echo $whiteCells . PHP_EOL;

Measured memory_bytes: 4856
from sys import stdin


if __name__ == "__main__":
    _in = [_.rstrip() for _ in stdin.readlines()]
    N = int(_in[0])  # type:int
    A_arr = []
    x_y_arr = []
    line = 1
    for i in range(N):
        _ = int(_in[line])  # type:int
        A_arr.append(_)
        tmp = {}
        for j in range(_):
            x,y = list(map(int,_in[line+j+1].split(' ')))  # type:list(int)
            tmp[x] = y
        x_y_arr.append(tmp)
        line += _+1
    # vvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvv
    cnt = 0
    for bit in range(1<<N):
        # bit = 0: Unkind, 1: Honest
        for i in range(N):
            if bit&(1<<i): # Honest
                for k,v in x_y_arr[i].items():
                    if bit&(1<<(k-1))==0 and v==1:
                        break
                    elif bit&(1<<(k-1))>0 and v==0:
                        break
                else:
                    continue
                break
        else:
            _ = bin(bit).count('1')
            cnt = max(cnt,_)
    # ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
    print(cnt)


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

#define INF 1000010000
#define nl '\n'
#define pb push_back
#define ppb pop_back
#define mp make_pair
#define fi first
#define se second
#define pii pair<int,int>
#define pdd pair<double,double>
#define all(c) (c).begin(), (c).end()
#define SORT(c) sort(all(c))
#define sz(c) (c).size()
#define rep(i,n) for( int i = 0; i < n; ++i )
#define repi(i,n) for( int i = 1 ; i <= n; ++i )
#define repn(i,n) for( int i = n - 1 ; i >= 0 ; --i )
#define repf(j,i,n) for( int j = i ; j < n ; ++j )
#define die(s) {std::cout << s << nl;}
#define dier(s) {std::cout << s; return 0;}
#define vi vector<int>
typedef long long ll;

using namespace std;

int a[100][100];

vi dx = {1 , 0 , 0 , -1 , 1 , 1 , -1 , -1};
vi dy = {0 , 1 , -1 , 0 , 1 , -1 , 1 , -1};

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

	int h , w;
	cin >> h >> w;
	
	vector<string> v(h);
	rep(i , h)cin >> v[i];
	
	
	
	rep(i , h){
		rep(j , w){
			if(v[i][j] == '#'){
				rep(k , 8){
					++a[i + dx[k] + 1][j + dy[k] + 1];
				}
			}	
		}
	}
	
	rep(i , h){
		rep(j , w){
			if(v[i][j] == '#'){
				cout << '#';
			}else{
				cout << a[i + 1][j + 1];
			}
		}
		cout << nl;
	}

	return 0;
}

Measured memory_bytes: 256
#include"bits/stdc++.h"
#include<boost/multi_array.hpp>
#include<boost/optional.hpp>
#include<boost/range/irange.hpp>
#include<boost/range/algorithm.hpp>
#include<boost/range/adaptor/reversed.hpp>
namespace adaptor = boost::adaptors;
template<class T>using p_queue = std::priority_queue<T, std::vector<T>, std::greater<>>;

void Main()
{
	int N, M;
	std::cin >> N >> M;
	int left = 1;
	int right = N + 1;
	for (int i : boost::irange(0, M))
	{
		int L, R;
		std::cin >> L >> R;
		++R;
		left = std::max(L, left);
		right = std::min(R, right);
	}
	std::cout << std::max(0, right - left) << std::endl;
}

int main()
{
	std::cin.tie(nullptr);
	std::ios_base::sync_with_stdio(false);
	std::cout << std::fixed << std::setprecision(15);
	Main();
}

Measured memory_bytes: 256
#define _CRT_SECURE_NO_WARNINGS
#include <algorithm>
#include<cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include<iostream>
#include<list>
#include<queue>
#include<set>
#include<string>
#include<utility>
#include <vector>

#define ll long long
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)   FOR(i,0,n)
#define FORR(i,a,b) for(int i=(a);i>=(b);--i)
#define REPR(i,n)   FORR(i,n,0)

using namespace std;

int main() {
	string S, T;
	cin >> S >> T;

	vector<int> a(26, -1), b(26, -1);

	bool f = true;
	REP(i, S.length()) {
		if (a[S[i] - 97] == -1 && b[T[i] - 97] == -1) {
			a[S[i] - 97] = T[i] - 97;
			b[T[i] - 97] = S[i] - 97;
		}
		else if (a[S[i] - 97] != T[i] - 97 || b[T[i] - 97] != S[i] - 97) {
			f = false;
		}
	}

	

	if (f) {
		cout << "Yes" << endl;
	}
	else {
		cout << "No" << endl;
	}

	return 0;
}

Measured memory_bytes: 776
//#pragma GCC         optimize("O3")
#include            <bits/stdc++.h>
#include            <ext/pb_ds/assoc_container.hpp>
#include            <ext/pb_ds/tree_policy.hpp>
#define FastIO      ios_base::sync_with_stdio(0);cin.tie(0),cout.tie(0)
#define pb          push_back
#define mp          make_pair
#define mem(x,i)    memset(x,i,sizeof(x))
#define ff          first
#define ss          second
#define popcount(x) __builtin_popcount(x)
#define all(x)      x.begin(),x.end()
#define Case(t)     for(int ks=1;ks<=t;ks++)
#define fileout     freopen("output.txt","w",stdout)
#define filein      freopen("input.txt","r",stdin)
#define D(x)        cerr<< __LINE__ <<": "<< #x << " = "<<(x) <<'\n';
#define endl        '\n'

using namespace std;
using namespace __gnu_pbds;

using ll  = long long;
using ld  = long double;
using ull = unsigned long long;
using pii = pair<int,int>;
using pll = pair<ll,ll>;
using pil = pair<int,ll>;

const int INF    = 0x3f3f3f3f;
const ll LL_INF  = 0x3f3f3f3f3f3f3f3f;
const double PI  = acos(-1);
const double eps = 1e-4;
const int mod    = 998244353;
const int mx     = 100005;
template <typename T>  using orderedSet =
    tree<T, null_type, less_equal<T>,
    rb_tree_tag, tree_order_statistics_node_update>;//find_by_order,order_of_key*/

/*------------------------------Graph Moves----------------------------*/
//const int fx[]= {+1,-1,+0,+0};
//const int fy[]= {+0,+0,+1,-1};
//const int fx[]={+0,+0,+1,-1,-1,+1,-1,+1};   // Kings Move
//const int fy[]={-1,+1,+0,+0,+1,+1,-1,-1};  // Kings Move
//const int fx[]={-2, -2, -1, -1,  1,  1,  2,  2};  // Knights Move
//const int fy[]={-1,  1, -2,  2, -2,  2, -1,  1}; // Knights Move
/*---------------------------------------------------------------------*/

//ll powmod(ll a,ll b){ll res=1;a%=mod;assert(b>=0);for(; b; b>>=1){if(b&1)res=res*a%mod;a=a*a%mod;}return res;}
/*----------------------BitMask-----------------------------------------*/
//inline int setBit(int N,int pos){return N=N | (1<<pos);}
//inline int resetBit(int N,int pos){return N= N & ~(1<<pos);}
//inline bool checkBit(int N,int pos){return (bool) (N& (1<<pos));}

int main()
{
    ll w,h,x,y;
    cin>>w>>h>>x>>y;
    ll mix=w/2+w%2;
    ll my = h/2+h%2;
    double ara=w*h*1.0;cout<<ara/2;
    if(x*2==w && y*2==h)
        cout<<' '<<1;
    else cout<<' '<<0;
}


Measured memory_bytes: 3744
#include "bits/stdc++.h"

#define pb push_back
#define pob pop_back
#define pf push_front
#define pof pop_front
#define eb emplace_back
#define rep(i, a, b) for (long i = (a); i <= (b); ++i)
#define per(i, a, b) for (long i = (a); i >= (b); --i)
#define mmst(v) memset(v, 0, sizeof(v))

const long kMax2 = 109;
const long kMax3 = 1009;
const long kMax4 = 10009;
const long kMax5 = 100009;
const long kMax6 = 1000009;
const long kInfI = 0x3F3F3F3F;
const float kInfF = 1e15;

const long kMAX = 1000000000;

using namespace std;
using ll = long long;

inline int readInt() {
  char c = getchar();
  while(!isdigit(c) && c != '-') c = getchar();
  int sigma = 1;
  if (c == '-') {
    sigma = -1;
    c = getchar();
  }
  int x = 0;
  while (isdigit(c)) {
    x = x * 10 + c - '0';
    c = getchar();
  }
  return x * sigma;
}

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

  int n;
  vector<int> a;
  cin >> n;
  rep(i, 0, n - 1) {
    int a0;
    cin >> a0;
    a.pb(a0);
  }

  if (is_sorted(a.begin(), a.end())) {
    cout << "YES\n";
    return 0;
  } else {
    rep(i, 0, n - 2) {
      rep(j, i + 1, n - 1) {
        int tmp = a[i];
        a[i] = a[j];
        a[j] = tmp;
        if (is_sorted(a.begin(), a.end())) {
          cout << "YES\n";
          return 0;
        }
        tmp = a[i];
        a[i] = a[j];
        a[j] = tmp;
      }
    }
  }
  cout << "NO\n";

  return 0;
}


Measured memory_bytes: 256
#include<cstdio>
#include<map>
#include<set>
#include<queue>
#include<cstring>
#include<algorithm>
using namespace std;
const int MAXN=100005;
int n;
int fa[MAXN];
int find(int x)
{
	if(fa[x]==x)
		return x;
	return fa[x]=find(fa[x]);
}
struct node
{
	int x,y;
	node(){}
	node(int xx,int yy)
	{
		x=xx,y=yy;
	}
};
queue<node>Q;
map<long long,int>a;
set<int>w[MAXN];
long long getid(int x,int y)
{
	if(x<y)
		swap(x,y);
	return 1ll*x*n+y;
}
void link(int x,int y)
{
	w[x].insert(y);
	w[y].insert(x);
	a[getid(x,y)]++;
	if(a[getid(x,y)]>=3)
	{
		printf("NO\n");
		exit(0);
	}
	if(a[getid(x,y)]==2)
		Q.push(node(x,y));
}
int main()
{
	//freopen("bluered.in","r",stdin);
	//freopen("bluered.out","w",stdout);
	scanf("%d",&n);
	for(int i=1;i<=2*n-2;i++)
	{
		int u,v;
		scanf("%d %d",&u,&v);
		link(u,v);
	}
	for(int i=1;i<=n;i++)
	{
		fa[i]=i;
	}
	for(int i=1;i<n;i++)
	{
		int x=0,y=0;
		while(1)
		{
			if(Q.empty())
			{
				printf("NO\n");
				return 0;
			}
			x=find(Q.front().x);
			y=find(Q.front().y);
			Q.pop();
			if(x!=y)
				break;
		}
		if(w[x].size()>w[y].size())
			swap(x,y);
		fa[x]=y;
		a.erase(getid(x,y));
		w[y].erase(x);
		for(set<int>::iterator it=w[x].begin();it!=w[x].end();it++)
		{
			int v=find(*it);
			if(v==y)
				continue;
			a.erase(getid(x,v));
			link(v,y);
			w[v].erase(x);
			w[x].erase(v);
		}
	}
	printf("YES\n");
	//fclose(stdin);
	//fclose(stdout);
}

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

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  string x;
  cin >> x;
  stack<char> st;
  st.push(' ');
  for(auto c : x) {
    if(c == 'T' && st.top() == 'S')
      st.pop();
    else
      st.push(c);
  }
  cout << st.size() - 1 << "\n";
}

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

int d[100];

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

	int a, b;
	while(cin >> a >> b) {
		memset(d, 0, sizeof d);
		int n = 0;
		while(a + b) {
			a--, b--;
			d[a]++;
			d[b]++;
			n = max({ n, a, b });
			cin >> a >> b;
		}

		bool ok = true;
		if(d[0] % 2 == 0 || d[1] % 2 == 0) {
			ok = false;
		}
		for(int i = 2; ok && i < n; i++) {
			if(d[i] % 2) {
				ok = false;
				break;
			}
		}
		if(ok) {
			cout << "OK" << endl;
		}
		else {
			cout << "NG" << endl;
		}
	}
}

Measured memory_bytes: 3104
while str = STDIN.gets
  n = str.split(" ")
  a = n[0].to_i
  b = n[1].to_i

  if a == 0 && b == 0
    break
  else
      for w in 1..b do
        print "#"
      end
      print "\n"
      for h in 1..a-2 do
        print "#"
        for ten in 1..w-2 do
          print "."
        end
        print "#"
         print "\n"
      end
      for w in 1..b do
        print "#"
      end
      print "\n"
  end
  print "\n"
end


Measured memory_bytes: 6868
#include <iostream>
#include <cstring>
#include <algorithm>
#include <vector>
#include <string>
#include <math.h>
#include <iomanip>
#include <limits>
#include <list>
#include <queue>
#include <tuple>
#include <map>
#include <stack>
#include <set>
#include <bitset>
#include <functional>
#include <cassert>
using namespace std;
#define fast_io ios_base::sync_with_stdio (false) ; cin.tie(0) ; cout.tie(0) ;
#define ll long long int
#define rep(i,n) for(int i=0; i<(int)(n); i++)
#define reps(i,n) for(int i=1; i<=(int)(n); i++)
#define REP(i,n) for(int i=n-1; i>=0; i--)
#define REPS(i,n) for(int i=n; i>0; i--)
#define MOD (long long int)(1e9+7)
#define INF (int)(1e9)
#define LINF (long long int)(1e18)
#define chmax(a, b) a = (((a)<(b)) ? (b) : (a))
#define chmin(a, b) a = (((a)>(b)) ? (b) : (a))
#define all(v) v.begin(), v.end()
typedef pair<int, int> Pii;
typedef pair<ll, ll> Pll;

ll mpow(ll a, ll b){
  if(b==0) return 1;
  else if(b%2==0){ll memo = mpow(a,b/2); return memo*memo%MOD;}
  else return mpow(a,b-1) * a % MOD;
}
ll lpow(ll a, ll b){
  if(b==0) return 1;
  else if(b%2==0){ll memo = lpow(a,b/2); return memo*memo;}
  else return lpow(a,b-1) * a;
}
ll gcd(ll a, ll b){
  if(b==0) return a;
  else return gcd(b, a%b);
}
vector<ll> kaijo_memo;
ll kaijo(ll n){
  if(kaijo_memo.size() > n) return kaijo_memo[n];
  if(kaijo_memo.size() == 0) kaijo_memo.push_back(1);
  while(kaijo_memo.size() <= n) kaijo_memo.push_back(kaijo_memo[kaijo_memo.size()-1] * kaijo_memo.size() % MOD);
  return kaijo_memo[n];
}
vector<ll> gyaku_kaijo_memo;
ll gyaku_kaijo(ll n){
  if(gyaku_kaijo_memo.size() > n) return gyaku_kaijo_memo[n];
  if(gyaku_kaijo_memo.size() == 0) gyaku_kaijo_memo.push_back(1);
  while(gyaku_kaijo_memo.size() <= n) gyaku_kaijo_memo.push_back(gyaku_kaijo_memo[gyaku_kaijo_memo.size()-1] * mpow(gyaku_kaijo_memo.size(), MOD-2) % MOD);
  return gyaku_kaijo_memo[n];
}

ll nCr(ll n, ll r){
  if(n == r) return 1;//0個の丸と-1個の棒みたいな時に時に効く？不安.
  if(n < r || r < 0) return 0;
  ll ret = 1;
  if(n <= 1e7){
    ret *= kaijo(n); ret %= MOD;
    ret *= gyaku_kaijo(r); ret %= MOD;
    ret *= gyaku_kaijo(n-r); ret %= MOD;
  }else{
    rep(i,r){
      ret *= n-i; ret %= MOD;
      ret *= mpow(r-i, MOD-2); ret %= MOD;
    }
  }
  return ret;
}

/*
std::mt19937 mt{ std::random_device{}() };

std::uniform_int_distribution<int> dist(1, 6);
dist(mt);

while(1){
	val;
	cout << val << endl;
	sol1 = solver1();
	sol2 = solver2();
	if(sol1==sol2){
	cout << "OK" << endl;
	}else{
	cout << "NG" << endl;
	cout << sol1 << endl;
	cout << sol2 << endl;
	break;
	}
}
*/

int main(void){
  fast_io
  cout<<fixed<<setprecision(15);
  ll a,b,c,d;
  cin >> a >> b >> c >> d;
  ll ans = -1*LINF;
  ans = max(ans, a*c);
  ans = max(ans, a*d);
  ans = max(ans, c*b);
  ans = max(ans, d*b);
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 3640
//
//  main.cpp
//  F
//
//  Created by 曾憲揚 on 2020/8/12.
//  Copyright © 2020 曾憲揚. All rights reserved.
//

#include <bits/stdc++.h>
using namespace std;
const int maxn = 3005;
const int MOD = 998244353;
int a[maxn];
long long dp[maxn][maxn];

int main(int argc, const char * argv[]) {
    memset(dp, 0, sizeof(dp));
    
    int n, s; cin >> n >> s;
    for(int i=1; i<=n; i++) cin >> a[i];
    
    
    long long ans = 0;
    //dp[0][0] = 0;
    for(int i=1; i<=n; i++){
        for(int j=0; j<=s; j++){
            dp[i][j] = dp[i-1][j];
        }
        dp[i][a[i]] += i;
        for(int j=1; j+a[i]<=s; j++){
            dp[i][j+a[i]] += dp[i-1][j];
            dp[i][j+a[i]] %= MOD;
        }
        ans += dp[i][s];
        ans %= MOD;
    }
    
    /*for(int i=0; i<=n; i++){
        for(int j=0; j<=s; j++){
            cout << dp[i][j] << " ";
        }
        cout << endl;
    }
    cout << dp[n][s] << endl;*/
    cout << ans << endl;
    return 0;
}


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

typedef long long ll;
typedef unsigned long long llu;

int main(int argc, char *argv[]) {
  ll n;
  cin >> n;

  vector<ll> d(n, 0);
  for (ll i = 0; i < n; ++i) {
    cin >> d[i];
  }
  sort(d.begin(), d.end(), greater<ll>());

  ll ans = 0;
  ll prev = -1;
  for (auto itr = d.begin(); itr != d.end(); ++itr) {
    if (prev != *itr) ++ans;
    prev = *itr;
  }

  cout << ans << endl;

  return 0;
}

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

int main()
{
    int h, w, distance[2704]{}, block_num{}, goal;
    bool is_block[2704]{};
    std::fill(distance, distance + 2704, 10000);
    scanf("%d%d", &h, &w);
    goal = (w + 2) * (h + 1) - 2;
    for (int i = 0; i <= h + 1; i++)
        is_block[i * (w + 2)] = is_block[(i + 1) * (w + 2) - 1] = true;
    for (int i = 0; i <= w + 1; i++)
        is_block[i] = is_block[(h + 1) * (w + 2) + i] = true;

    for (int i = 1; i <= h; i++)
    {
        for (int j = 1; j <= w; j++)
        {
            char tmp;
            scanf(" %c", &tmp);
            is_block[i * (w + 2) + j] = (tmp == '#');
            block_num += (tmp == '#');
        }
    }
    distance[w + 3] = 0;
    std::priority_queue<std::pair<int, int>, std::vector<std::pair<int, int>>, std::greater<std::pair<int, int>>> que;
    que.push({0, w + 3});

    while (!que.empty())
    {
        auto here = que.top();
        que.pop();
        if (is_block[here.second])
            continue;
        is_block[here.second] = true;
        distance[here.second] = here.first;
        if (here.second == goal)
            break;
        que.push({here.first + 1, here.second + 1});
        que.push({here.first + 1, here.second - 1});
        que.push({here.first + 1, here.second + w + 2});
        que.push({here.first + 1, here.second - w - 2});
    }

    if (distance[goal] == 10000)
        printf("-1\n");
    else
        printf("%d\n", w * h - block_num - distance[goal] - 1);

    return 0;
}

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

int main(void){
    int a = 0;
    int b = 0;
    int c = 0;
    int d = 0;
    int N;
    int i = 0;
    scanf("%d", &N);
    while(i<N){
        char str[3];
        scanf("%s", str);
        if(strcmp("AC",str)==0){
            a++;
        }else if(strcmp("WA",str)==0){
            b++;
        }else if(strcmp("TLE",str)==0){
            c++;
        }else if(strcmp("RE",str)==0){
            d++;
        }
        i++;
    }
    printf("AC x %d\n", a);
    printf("WA x %d\n", b);
    printf("TLE x %d\n", c);
    printf("RE x %d\n", d);
    return 0;
}


Measured memory_bytes: 1728
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
 
int main(){
    int N;
    cin >> N;
    ll a[200001];
    for(int i=1;i<=N;i++)
        cin >> a[i];

    ll b[200001] = {}, sum, count = 0;
    for(int i=N;i>=1;i--){
        sum = 0;
        for(int j=i;j<=N;j+=i){
            sum += b[j];
        }
        if(sum % 2 != a[i])
            b[i]++;
    }

    for(int i=1;i<=N;i++){
        b[i] = b[i] % 2;
        if(b[i] == 1)
            count++;
    }

    cout << count << endl;
    for(int i=1;i<=N;i++){
        if(b[i] == 1)
            cout << i << ' ';
    }
    cout << endl;

}

Measured memory_bytes: 4096
#include<bits/stdc++.h>
using namespace std;
#define INF 1e9
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define ALL(x) (x).begin(), (x).end()
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef pair<int, int> pii;
template<typename T1,typename T2> inline void chmin(T1 &a,T2 b){if(a>b) a=b;}
template<typename T1,typename T2> inline void chmax(T1 &a,T2 b){if(a<b) a=b;}
const int MOD = 1000000007;

void solve() {
  int n;
  cin >> n;
  int m = n % 1000;
  cout << ((m != 0) ? (1000 - m) : 0) << endl;
}

int main() {
  solve();
  return 0;
}

Measured memory_bytes: 3596
def main():
    N = int(input())
    A = list(map(int, input().split()))

    if N % 2 == 1:
        A.append(0)

    A.sort()
    ev = tuple(A[::2])
    od = tuple(A[1::2])

    if ev == od:
        comb = (2 ** (N // 2)) % 1000000007
        print(str(comb))
    else:
        print('0')

main()


Measured memory_bytes: 14004
# coding:utf-8

import sys
import math
import time
#import numpy as np
import collections
from collections import deque
from collections import Counter
import queue
import copy
import bisect
import heapq
import itertools


#sys.setrecursionlimit(10**7)
#N, Q = map(int, input().split())
#G = [list(input()) for i in range(H)]
#INF = V * 10001
#A = [int(i) for i in input().split()]
#AB = [list(map(int, input().split())) for _ in range(K)]


S = str(input())
T = str(input())
ans = 0

for i in range(len(S)):
    if(S[i]==T[i]):
        pass
    else:
        ans+=1

print(ans)


Measured memory_bytes: 70692
#include <iostream>
#include <string>
#include <math.h>

using namespace std;

int main(int argc, char const *argv[]){
    int a, b;
    scanf("%d %d",&a, &b);
    if(a == 1 && b == 1){
        printf("Draw\n");
        return 0;
    }
    else if(a == 1){
        printf("Alice\n");
        return 0;
    }
    else if(b == 1){
        printf("Bob\n");
        return 0;
    }

    if(a == b){
        printf("Draw\n");
        return 0;
    }
    else if(a > b){
        printf("Alice\n");
        return 0;
    }
    else{
        printf("Bob\n");
        return 0;
    }
    return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
     
    void QSort(long x[ ], int left, int right)
    {
        int i, j;
        int pivot;
     
        i = left;                      /* ソートする配列の一番小さい要素の添字 */
        j = right;                     /* ソートする配列の一番大きい要素の添字 */
     
        pivot = x[(left + right) / 2]; /* 基準値を配列の中央付近にとる */
     
        while (1) {                    /* 無限ループ */
     
            while (x[i] < pivot)       /* pivot より大きい値が */
                i++;                   /* 出るまで i を増加させる */
     
            while (pivot < x[j])       /* pivot より小さい値が */
                j--;                   /*  出るまで j を減少させる */
            if (i >= j)                /* i >= j なら */
                break;                 /* 無限ループから抜ける */
     
            Swap(x, i, j);             /* x[i] と x[j]を交換 */
            i++;                       /* 次のデータ */
            j--;
        }
     
        if (left < i - 1)              /* 基準値の左に 2 以上要素があれば */
            QSort(x, left, i - 1);     /* 左の配列を Q ソートする */
        if (j + 1 <  right)            /* 基準値の右に 2 以上要素があれば */
            QSort(x, j + 1, right);    /* 右の配列を Q ソートする */
    }
     
      /* 配列の要素を交換する */
    void Swap(long x[ ], int i, int j)
    {
        long temp;
     
        temp = x[i];
        x[i] = x[j];
        x[j] = temp;
    }
     
     
    int main(){
      int n,i;
      long x[200000],xx[200000];
      scanf("%d",&n);
      for(i=0;i<n;i++){
        scanf("%ld",&x[i]);
        xx[i]=x[i];
      }
      QSort(xx, 0, n - 1);
      for(i=0;i<n;i++){
        if(x[i]>xx[n/2-1])
          printf("%ld\n",xx[n/2-1]);
        else
          printf("%ld\n",xx[n/2]);
      }
    }

Measured memory_bytes: 5248
#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; }
template<typename T>
struct RangeSumQuery {
	// SegmentTree (1-indexed)
	int n;
	vector<T>d;
	RangeSumQuery(int m) {
		for (n = 1; n < m; n <<= 1);
		d.assign(2 * n, 0);
	}
	void add(int i, T x) {
		d[n + i] += x;
		for (int j = (n + i) / 2; j > 0; j >>= 1) {
			d[j] += x;
		}
	}
	T sum(int a, int b) {
		return sum(a, b, 1, 0, n);
	}
	T sum(int a, int b, int k, int l, int r) {
		// [a,b) [l,r)
		if (r <= a || b <= l)return 0;
		else if (a <= l&&r <= b)return d[k];
		else {
			T vl, vr;
			vl = sum(a, b, k * 2, l, (l + r) / 2);
			vr = sum(a, b, k * 2 + 1, (l + r) / 2, r);
			return (vl + vr);
		}
	}
};

signed main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	int n, q; cin >> n >> q;
	RangeSumQuery<int> rsq(n);
	rep(i, 0, q) {
		int com, x, y; cin >> com >> x >> y;
		if (com)cout << rsq.sum(x - 1, y) << endl;
		else rsq.add(x - 1, y);
	}
	dump(rsq.d);
	return 0;
}

Measured memory_bytes: 3892
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		String ALPHABETS = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";

		try (Scanner sc = new Scanner(System.in)) {
			// 整数の入力
			int n = sc.nextInt();
			// 文字列の入力
			String s = sc.next();
			StringBuilder sb = new StringBuilder();
			for (int i = 0; i < s.length(); i++) {
				int index = ALPHABETS.indexOf(s.charAt(i));
				sb.append(ALPHABETS.charAt((index + n) % 26));
			}
			System.out.println(sb);
		}
	}
}


Measured memory_bytes: 21844
import Data.List

f a b k
  | k < div range 2 + mod range 2 = (++) <*> (map (+ (b - (k - 1) - a))) $ take k [a..b]
  | otherwise = [a..b]
  where range = b - a + 1

main = do
   [a,b,k] <- map read . words <$> getLine
   mapM_ print $ f a b k

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

vector<string> map = vector<string>(12);
int chk[12][12];
int cnt;

void rec( int x, int y)
{
	
	if( x < 0 || x >= 12 || y < 0 || y >= 12 || chk[x][y] == 1 || map[x][y] == '0')
		return;
	
	chk[x][y] = 1;
	map[x][y] = '0';
	
	rec(x+1,y);
	rec(x-1,y);
	rec(x,y+1);
	rec(x,y-1);
	
}

int main()
{
	
	while(1)
	{
		cnt = 0;
		
		for( int i = 0; i < 12; i++)
		{	
			cin >> map[i];
			
			if(cin.eof())
				return 0;
			
			for( int j = 0; j < 12; j++)
			{
				chk[i][j] = 0;
			}
		}
		
		for(int i = 0; i < 12; i++)
		 	for(int j = 0; j < 12; j++)
			{
				if( chk[i][j] == 0 && map[i][j] == '1')
				{
					rec(i, j);
					cnt++;
				}
			}
		
		cout << cnt << endl;
		
	}
}

Measured memory_bytes: 0
#pragma warning(disable:4996)
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <math.h>
#define MAX_STRING 4
#define QNUM_LIMIT 100

int main() {

	char  sInput[MAX_STRING]="";
	char* psInput=NULL;
	char* psTemp=NULL;

	int nQNum=0;
	int anScore[QNUM_LIMIT];
	int nSum=0;
	int nMinNum = 10000;
	int nAnswer=0;

	int i=0;
	int j=0;


	// read line 1
	psTemp = fgets(sInput,MAX_STRING,stdin);
	if (strchr(sInput, '\n') != NULL) {
	    sInput[strlen(sInput) - 1] = '\0';
	} else {
		while(getchar() != '\n');
	}
	nQNum=atoi(sInput);

	for (i=0;i<nQNum;i++){
		psTemp = fgets(sInput,MAX_STRING,stdin);
		if (strchr(sInput, '\n') != NULL) {
			sInput[strlen(sInput) - 1] = '\0';
		} else {
			while(getchar() != '\n');
		}
		anScore[i]=atoi(sInput);
		nSum = nSum + anScore[i];

		if (anScore[i]%10 != 0 && anScore[i]<nMinNum){
			nMinNum=anScore[i];
		}
	}

	if (nSum%10 != 0 ){
		nAnswer = nSum;
	} else {
		nAnswer = nSum - nMinNum;
		if ( nAnswer <= 0 || nAnswer%10 == 0){
			nAnswer=0;
		}
	}


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

}



Measured memory_bytes: 128
#include <iostream>

using namespace std;

int main() {
  int N;
  int t[100001], x[100001], y[100001];
  t[0] = x[0] = y[0] = 0;
  cin >> N;
  for (int i = 1; i <= N ; i++) {
    cin >> t[i] >> x[i] >> y[i];
  }

  bool is_ok = true;
  //cout << "-------------" << endl;
  for (int i = 0; i <= N - 1; i++) {
    int z = abs(x[i+1] - x[i]) + abs(y[i+1] - y[i]);
    int t_diff = t[i+1] - t[i];
    if (t_diff < z) {
      is_ok = false;
    }
    // 偶数、奇数が一致する必要あり
    if (z % 2 != t_diff % 2) {
      is_ok = false;
    }
  }
  if (is_ok) {
    cout << "Yes" << endl;
  } else {
    cout << "No" << endl;
  }
}


Measured memory_bytes: 1408
#include <math.h>

#include <algorithm>
#include <cstring>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <string>
#include <vector>
using namespace std;
#define rep(i, n) for (int i = 0; i < (n); i++)
using ll = long long;
using P = pair<int, int>;

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

  int cnt = 0;
  rep(i, s.size()) { cnt += s[i] - '0'; }
  // cout << cnt;
  cout << (cnt % 9 == 0 ? "Yes" : "No");
  return 0;
}


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

int main(){
    rep(i,5){
        int x;
        cin >> x;
        if(x==0){
            cout << i+1 << endl;
            return 0;
        }
    }


    }

Measured memory_bytes: 3568
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int n,flag=0;
    cin>>n;
    if(n<10)
    {
        cout<<"Yes\n";
        return 0;
    }
    else
    {
        for(int i=2; i<10; i++)
        {
            if(n%i==0 && (n/i)<10)
            {
                cout<<"Yes\n";
                return 0;
            }
        }
    }
    cout<<"No\n";
    return 0;
}


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

using namespace std;

#define sz(v)           ((int)((v).size()))
#define clr(v, d)       memset(v, d, sizeof(v))
#define rep(i, v)       for(int i=0; i<sz(v); ++i)
#define lp(i, n)        for(int i=0; i<(int)(n); ++i)
#define lpi(i, j, n)    for(int i=(j); i<(int)(n); ++i)
#define lpd(i, j, n)    for(int i=(j); i>=(int)(n); --i)
#define INF             1000000000

typedef long long ll;
typedef pair<int, int> ii;
typedef vector<ii> vii;
typedef vector<int> vi;

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

const int N = 1e6;

int main()
{
	init();
	ll n;
	cin >> n;
	ll l = 0, r = N, mid;
	while(l < r){
		mid = (r-l)/2 + l;
		if(mid*mid <= n)
			l = mid+1;
		else
			r = mid;
	}
	for(ll i = l; i > 0; --i)
		if(n % i == 0){
//			cout << i << endl;
			cout << (i + n/i) - 2;
			return 0;
		}
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define _overload3(_1,_2,_3,name,...) name
#define _rep(i,n) repi(i,0,n)
#define repi(i,a,b) for(ll i=ll(a);i<ll(b);++i)
#define rep(...) _overload3(__VA_ARGS__,repi,_rep,)(__VA_ARGS__)
#define inf (ll)1e9
#define mod (ll)(1e9+7)
#define d(x) cerr<<#x<<"="<<x<<endl;
#define p(x) cout<<(x)<<endl
#define ps(x) cout<<(x);
#define pfix(d,x) cout << fixed << setprecision(d) << x << endl;
#define pb push_back
#define all(v) (v).begin(), (v).end()
#define minel(v) *min_element(all(v))
#define minind(v) distance((v).begin(), min_element(all(v)))
#define maxel(v) *max_element(all(v))
#define maxind(v) distance((v).begin(), max_element(all(v)))
#define fi first
#define se second
ll a[31][100001],b,c[100001],d,n,m,p,q,x,y,k,h,w,sum,mi,ma,ans[100001],l,r,res,tmp;
bool flag;
int dx[4]={1,0,-1,0},dy[4]={0,1,0,-1};
int dx8[8]={1,1,0,-1,-1,-1,0,1},dy8[8]={0,1,1,1,0,-1,-1,-1};
char cha;
string s;
typedef vector<int> VI;
typedef vector<pair<int,int> > VP;

vector<vector<ll> > combi(int n){
    vector<vector<ll> > v(n+1, vector<ll>(n+1, 0));
    rep(i,n+1){v[i][0]=1;v[i][i]=1;}
    rep(i,1,n+1)rep(j,1,i){v[i][j]=(v[i-1][j-1]+v[i-1][j])%mod;}
    return v;
}

//i回操作のボールの並べ方： {N-K+1}C{i}*{K-1}C{i-1}

int main(){
    cin>>n>>k;
    vector<vector<ll> > v = combi(n+1);
    rep(i,1,k+1)p(v[n-k+1][i]*v[k-1][i-1]%mod);
    return 0;
}


Measured memory_bytes: 31616
import sys
from bisect import *
from collections import *
from copy import deepcopy
from datetime import *
from heapq import *
from itertools import *
# from math import *
from operator import *
from pprint import *

sys.setrecursionlimit(10**8)

input = sys.stdin.readline

def main():
    """ main """
    N = int(input())
    PS = [int(input()) for _ in range(N)]
    PS.sort()
    PS[-1] >>= 1
    print(sum(PS))

if __name__ == '__main__':
    main()

Measured memory_bytes: 3952
#include <bits/stdc++.h>
using namespace std;
int main(){
    string s;
    cin >> s;
    if ((s.at(0)==s.at(1)&&s.at(0)==s.at(2))&&s.at(0)==s.at(3)){
        cout << "No" << endl;
    }else{
        if(s.at(0)==s.at(1)&&s.at(2)==s.at(3)){cout << "Yes"<<endl; }
        else if  (s.at(0)==s.at(2)&&s.at(1)==s.at(3)){cout << "Yes"<<endl;}
        else if (s.at(0)==s.at(3)&&s.at(1)==s.at(2)){cout << "Yes"<<endl;}
        else {cout << "No" << endl;}
    }
}


Measured memory_bytes: 256
package main

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

type card struct {
	num int
	mark string
}

var scanner = bufio.NewScanner(os.Stdin)

func nextCard() card {
	newCard := card{num: 0, mark: ""}
	scanner.Scan()
	cardInfo := scanner.Text()
	newCard.num, _ = strconv.Atoi(cardInfo[1:])
	newCard.mark = cardInfo[0:1]

	return newCard
}

func bubbleSort(deck []card) []card {
	n := len(deck)
	for i := 0; i < n; i++ {
		for j := n - 1; j >= i + 1; j-- {
			if deck[j].num < deck[j-1].num {
				tmp := deck[j]
				deck[j] = deck[j-1]
				deck[j-1] = tmp
			}
		}
	}
	return deck
}

func selectionSort(deck []card) []card {
	n := len(deck)
	for i := 0; i < n; i++ {
		minj := i
		for j := i; j < n; j++ {
			if deck[j].num < deck[minj].num {
				minj = j
			}
		}
		tmp := deck[i]
		deck[i] = deck[minj]
		deck[minj] = tmp
	}
	return deck
}

func isStable(in, out []card) bool {
	for i := 0; i < len(in); i ++ {
		if in[i].mark != out[i].mark {
			return false
		}
	}
	return true
	//for i := 1; i <= len(in)-1; i++ {
	//	for j := i+1; j <= len(in); j++ {
	//		for a := 1; a <= len(in)-1; a++ {
	//			for b := a+1; b <= len(in); b++ {
	//				if in[i].num == out[j].num &&
	//					in[i] == out[b] &&
	//						in[j] == out[a] {
	//					return false
	//				}
	//			}
	//		}
	//	}
	//}
	//return true
}

func main() {
	scanner.Split(bufio.ScanWords)
	var n int
	fmt.Scan(&n)
	deck := make([]card, n)
	for i := range deck {
		deck[i] = nextCard()
	}
	// fmt.Printf("%+v", deck)

	Borigin := make([]card, len(deck))
	_ = copy(Borigin, deck)
	Sorigin := make([]card, len(deck))
	_ = copy(Sorigin, deck)

	Bdeck := bubbleSort(Borigin)
	Sdeck := selectionSort(Sorigin)

	for i, card := range Bdeck {
		if i == len(Bdeck)-1 {
			fmt.Printf("%s%d\n", card.mark, card.num)
		} else {
			fmt.Printf("%s%d ", card.mark, card.num)
		}
	}

	if isStable(Bdeck, Bdeck) {
		fmt.Println("Stable")
	} else {
		fmt.Println("Not stable")
	}

	for i, card := range Sdeck {
		if i == len(Sdeck)-1 {
			fmt.Printf("%s%d\n", card.mark, card.num)
		} else {
			fmt.Printf("%s%d ", card.mark, card.num)
		}
	}

	if isStable(Bdeck, Sdeck) {
		fmt.Println("Stable")
	} else {
		fmt.Println("Not stable")
	}
}


Measured memory_bytes: 1176
#include <bits/stdc++.h>
#define ll long long int
#define FASTIO std::ios::sync_with_stdio(false);
#define pb push_back
#define mp make_pair
#define ld long double
#define F first
#define S second
#define inf 1e18
#define err(x) cout<<x<<endl
#define all(x) x.begin(),x.end()
#define input_from_file  freopen("input.txt", "r", stdin);



using namespace std;
int main()
{


    FASTIO
    ll a,b,c,d;
    cin>>a>>b>>c>>d;
    ll w1 =b/c - a/c;
    if(a%c==0)
    w1++;
    ll w2 = b/d - a/d;
    if(a%d==0)
    w2++;
    ll e = c*d/__gcd(c,d);


    ll w3 = b/e - a/e;
    if(a%e==0)
    w3++;
    ll tot = w1+w2-w3;
    ll all = b-a+1ll;
    all-=tot;
    cout<<all;



cout << endl ;
return 0;
}


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

using namespace std;
#define inf 1000000000
#define unvisited -1
#define visited 1
#define eps 1e-9
#define mp make_pair
#define pb push_back
#define pi acos(-1.0)
#define uint64 unsigned long long
typedef long long ll;
typedef vector<int> vi;
typedef pair<int,int> ii;
typedef vector<ii> vii;

const int maxn = 3001;

double dp[maxn][maxn];
double a[maxn];
int n;

double solve(int idx, int head) {
	if(idx == n+1){
		if(head == 0){return 1;}
		else
			return 0;
	}
	
	if(fabs(dp[idx][head] + 1) > eps){return dp[idx][head];}
	return dp[idx][head] = a[idx] * solve(idx+1, head-1) + (1.0 - a[idx]) * solve(idx+1, head);
}

int main(){
	int i,j;
	for(i=0;i<maxn;i++){
		for(j=0;j<maxn;j++){
			dp[i][j] = 0;
		}
	}
	
	scanf("%d",&n);
	for(i=1;i<=n;i++){scanf("%lf",&a[i]);}
	// top down approach

	// int minim = n/2 + 1;
	// double ans = 0;
	// for(i=minim;i<=n;i++){
	// 	ans += solve(1, i);
	// }


	// bottom up approach
	// dp[idx][head] = prob that at index idx we have number of head up
	int minim = n/2 + 1;
	double ans = 0;
	dp[1][1] = a[1];
	dp[1][0] = 1-a[1];
	for(i=2;i<=n;i++){
		dp[i][0] = dp[i-1][0]*(1-a[i]);
		for(j=1;j<=i;j++){
			dp[i][j] = dp[i-1][j-1]*a[i] + dp[i-1][j]*(1-a[i]);
		}
	}
	for(i=1;i<=n;i++){
		int head = i, tail = n-i;
		if(head > tail)
			ans += dp[n][i];
	}

	printf("%.10lf\n",ans);
	return 0;
};

Measured memory_bytes: 70656
def main():
    N = int(input())
    A = [int(a) for a in input().split()]
    div = pow(10, 9) + 7

    # print(A)
    d = dict()
    for i in range(N+1):
        if A[i] not in d: d[A[i]] = [i]
        else: d[A[i]].append(i)

    i1, i2 = 0, 0
    for a in d:
        if len(d[a]) == 2:
            i1, i2 = d[a]
            break
    M = i1 + N-i2
    # print(N, i1, i2)

    # N+1_C_l
    pow1 = [1, 1]
    for i in range(2, N+2):
        pow1.append(pow1[-1]*i % div)

    pow2 = []
    j = powquick(pow1[-1], div-2, div)
    pow2.append(j)
    for i in range(N, -1, -1):
        pow2.append(pow2[-1]*(i+1) % div)
    pow2 = pow2[::-1]


    # pow2 = [1, 1]
    # for i in range(2, N+2):
    #     j = powquick(i, div-2, div)
    #     pow2.append(pow2[-1]*j % div)

    # pow2 = [1, 1]
    # inv = [0, 1]
    # for i in range(2, N+2):
    #     inv.append((-inv[div % i]) *(div // i) % div)
    #     pow2.append(pow2[-1] * inv[-1] % div)

    for l in range(1, N+2):
        v = (pow1[N+1]*pow2[l]*pow2[N+1-l]) % div
        # print(v)
        if l <= M+1:
            v -= (pow1[M]*pow2[l-1]*pow2[M-l+1]) % div
        print(v % div)

def powquick(x, y, div):
        if y == 0: return 1
        if y == 1: return x % div
        if y % 2 == 0: return pow(powquick(x, y // 2, div), 2) % div
        if y % 2 == 1: return pow(powquick(x, y// 2, div), 2) * x % div


if __name__ == '__main__':
    main()

Measured memory_bytes: 79464
from math import factorial

n,p = map(int,input().split())
a = list(map(int,input().split()))

cnt = [0,0]
for i in a:
    cnt[i%2] += 1

ans = 0

while True:
    if p > cnt[1]:
        break
    ans += factorial(cnt[1]) // factorial(p) // factorial(cnt[1] - p)
    p += 2

print(ans * 2 ** cnt[0])


Measured memory_bytes: 9136
#include <bits/stdc++.h>
using namespace std;
#define ll long long int
#define ul unsigned long long int
#define ld long double
#define f(t) for(ll i =0;i<t;i++)
#define vi vector<int>
#define vl vector<ll>
#define pb push_back
#define ff first
#define ss second
#define MOD 1000000007
#define inf 4e18
#define EPS 1e-3
#define PI 3.1415926535897932385
#define display(v) f(v.size())cout << v[i]<<" "
const double h = 1e-6;
const int MAX_  = 200005;
#define all(v) v.begin(),v.end()

inline ll mul(ll a, ll b){ return (a * 1ll * b) % MOD; }
inline ll sub(ll a, ll b){ ll c = a - b; if(c < 0) c += MOD; return c; }
inline ll add(ll a, ll b){ ll c = a + b; if(c > MOD) c -= MOD; return c; }
ll sqr(ll x)
{
    return x*x;
}
 //////////////////////*********CODE***********/////////////////////
 //////////////////////////////////////////////////////////////////


int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    int x,a;  cin>>x>>a;
    if(x<a)cout << 0 ;
    else cout << 10;
    
   
   
    return 0;
}
    

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i =0;i<(int)(n);i++)
typedef pair<int,int> P;
typedef long long ll;
int main(){
    int n,k;
    cin >> n >> k;
    vector<int> v(n);
    rep(i,n){
        cin >> v[i];
    }
    sort(v.begin(),v.end(),greater<int>());
    int res = 0;
    rep(i,k){
        res+=v[i];
    }
    cout << res << endl;
}

Measured memory_bytes: 256
# 入力割り当て
N, Y = map(int, input().split())

# 変数割り当て
## 順に10000円札、5000円札、1000円札の枚数
a, b, c = 0, 0, 0

# 式変形
## a+b+c=N
## 10a+5b+c=Y/1000
## 9a+4b=Y/1000-N

# 組み合わせ計算
flg = True
while flg:
	x = Y/1000 - N - 9*a
	b = int(x//4)
#	c = int(x%4)
	c = N -a - b
	if  10*a+5*b+c == Y/1000 and a >=0 and b >= 0 and c >= 0:
		flg = False
	elif x < 0:
		a, b, c = -1, -1, -1
		flg = False
	else:
		a += 1

# 結果の表示
#ans = str(a) + ' ' + str(b) + ' ' + str(c)
print(a, b, c)

Measured memory_bytes: 3064
#include <iostream>
#include <cmath>

using namespace std;

int solve(int n){
    int res = 0;
    for(int x=0; x*x <= n - x; ++x){
        for(int y=x; x*x + y*y <= n - x - y; ++y){
            for(int z=y; x*x + y*y + z*z <= n - x - y - z; ++z){
                int w = sqrt(n - x*x - y*y - z*z);
                if(x*x + y*y + z*z + w*w != n || w < z)continue;
                res++;
            }
        }
    }
    return res;
}

int main(){
    for(int n; cin >> n, n; cout << solve(n) << '\n');
    return 0;
}

Measured memory_bytes: 1160