akhauriyash/Code-Regression huggingface dataset:
#B - Bishop
import math

H,W = map(int,input().split(' '))

if(H%2 == 0 and W%2 == 0):
    ans = int(W/2)*int(H/2)+int(W/2)*int(H/2)
elif(H%2 == 0 and W%2 == 1):
    ans = math.ceil(W/2)*int(H/2)+int(W/2)*int(H/2)
elif(H%2 == 1 and W%2 == 0):
    ans = int(W/2)*math.ceil(H/2)+int(W/2)*int(H/2)
elif(H%2 == 1 and W%2 == 1):
    ans = math.ceil(W/2)*math.ceil(H/2)+int(W/2)*int(H/2)

if(H == 1 or W == 1):
    ans = 1

print(int(ans))

Measured memory_bytes: 3064
#include <bits/stdc++.h>
#define ll long long
using namespace std;
int main(){
  ll n;cin>>n;
  vector<ll>ar;
  for(int i=0;i<n;i++){
    ll x;cin>>x;ar.push_back(x);
  }
  vector<ll>s=ar;
  for(int i=0;i<n;i++){s[i]=0;}
  s[n-2]=abs(ar[n-2]-ar[n-1]);
  for(int i=n-3;i>=0;i--){
   	ll s1=abs(ar[i]-ar[i+1])+s[i+1];
    ll s2=abs(ar[i]-ar[i+2])+s[i+2];
    s[i]=min(s1,s2);
  }
  cout<<s[0]<<endl;
}

Measured memory_bytes: 1908
N = int(input())
A, B = list(map(int, input().split()))
P = list(map(int, input().split()))
counter = [0] * 3
for p in P:
    if p <= A:
        counter[0] += 1
    elif p <= B:
        counter[1] += 1
    else:
        counter[2] += 1
print(min(counter))

Measured memory_bytes: 9092
#include <algorithm>
#include <cstdio>
#include <iostream>
#include <map>
#include <cmath>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>
#include <stdlib.h>
#include <stdio.h>
#include <bitset>
#include <cstring>
using namespace std;
#define FOR(I,A,B) for(int I = (A); I < (B); ++I)
#define CLR(mat) memset(mat, 0, sizeof(mat))
typedef long long ll;
// ????¬?????´???????
// v ??? 1????????¨1?????????0????????????????´?????????????????????????????????????
void integrate(vector<vector<int> >& v){
    const int n = v.size(), m = v[0].size();
    FOR(i,0,n) FOR(j,0,m-1) v[i][j+1] += v[i][j]; // ?¨??¶?????????????
    FOR(i,0,n-1) FOR(j,0,m) v[i+1][j] += v[i][j]; // ????¶????????????? - > ????????§2?¬????????´?????????????????????????
}
int main()
{
  ios::sync_with_stdio(false);
  cin.tie(0);
  int H, W; cin >> H >> W;
  int K; cin >> K;
  vector<string> vs(H); FOR(i,0,H) cin >> vs[i];
  vector<vector<int> > J(H+1, vector<int>(W+1, 0)), O(H+1, vector<int>(W+1, 0)), I(H+1, vector<int>(W+1, 0));
  FOR(h,1,H+1) {
    FOR(w,1,W+1) {
      if(vs[h-1][w-1] == 'J') J[h][w] = 1;
      if(vs[h-1][w-1] == 'O') O[h][w] = 1;
      if(vs[h-1][w-1] == 'I') I[h][w] = 1;
    }
  }
  integrate(J);
  integrate(O);
  integrate(I);
  FOR(i,0,K) {
    int x, y, xx, yy; cin >> y >> x >> yy >> xx;
    cout << J[yy][xx] - J[yy][x-1] - J[y-1][xx] + J[y-1][x-1];
    cout << " ";
    cout << O[yy][xx] - O[yy][x-1] - O[y-1][xx] + O[y-1][x-1];
    cout << " ";
    cout << I[yy][xx] - I[yy][x-1] - I[y-1][xx] + I[y-1][x-1];
    cout << endl;
  }
}

Measured memory_bytes: 15752
n , m , x = map(int ,input().split())

a = [(list(map(int,input().split()))) for _ in range(n)]

Sum = [0] * (m + 1)
mincost = 999999999

for bit in range(1 << n):
	tmpcost = 0
	Sum = [0] * (m + 1)
	flag = False
	for i in range(0 , n):
		if ((bit >> i) & 1):
			tmpcost += a[i][0]
			for j in range(1 , m + 1):
				Sum[j] += a[i][j]
	for i in range(1 , m + 1):
		if Sum[i] < x:
			flag = True
			break
	if flag == False:
		mincost = min(mincost , tmpcost)

if mincost == 999999999:
	print(-1)
else :
	print(mincost)

Measured memory_bytes: 9236
#include <iostream>
#include <iomanip>
#include <string>
#include <vector>
#include <stack>
#include <queue>
#include <deque>
#include <set>
#include <map>
#include <utility>
#include <tuple>
#include <algorithm>
#include <numeric>
#include <cstdio>
#include <cmath>
#define rep(i, n) for (int i = 0; i < (n); i++)
using namespace std;
using ll = long long;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }

int main() {
  int N, H, W;
  cin >> N >> H >> W;
  cout << (N-H+1)*(N-W+1) << endl;
  return 0;
}

Measured memory_bytes: 256
import sys
n,m = map(int,input().split())
mark = [1 for x in range(n+3)]
score = [0 for x in range(n+3)]
score[0]=1
mod = 1000000007
for i in range(m):
    mark[int(sys.stdin.readline())] = 0
c = 0
for i in range(0,n+1):
    if mark[i+1]:
        score[i+1]+=score[i]
        score[i+1]%=mod
    if mark[i+2]:
        score[i + 2] += score[i]
        score[i + 2]%mod
print(score[n]%mod)

Measured memory_bytes: 7832
// #Sazaの1日1AC
#include<bits/stdc++.h>
using namespace std;
const long long mod=998244353;
const long long INF=9e15;
const double PI=3.14159265358979323846;

//マクロ
//型エイリアス
using ll = long long;
using P=pair<long long,long long>;
using vl=vector<long long>;
using vvl=vector<vector<long long>>;
using vP=vector<pair<long long, long long>>;
//ショートカット
#define rep(i,n) for(long long i = 0; i < n; i++)
#define rep2(i,k,n) for(long long i = k; i < n; i++) //半開区間
#define all(v) v.begin(), v.end()
#define rall(v) v.rbegin(),v.rend()
#define pb push_back
#define mkp make_pair
//入力
#define vin(v,N) for(long long id=0;id<N;id++) cin>>v.at(id)
#define lin(n) long long n;cin>>n
#define chin(x) char x;cin>>x;
#define sin(s) string s;cin>>s;
#define vlin(v,N) vector<long long>v(N);for(long long i=0;i<N;i++)cin>>v.at(i)

#define max(a,b) max((ll)a,(ll)b)
#define min(a,b) min((ll)a,(ll)b)

//関数
//最大公約数
long long gcd(long long m, long long n){
  long long a=max(m,n);
  long long b=min(m,n);
  long long r=a%b;
  while(r!=0){
    a=b; b=r; r=a%b;
  }
  return b;
}
// 最小公倍数
long long lcd(long long m, long long n){
  return m*n/gcd(m,n);
}
//xのn乗
long long power(long long x, long long N){
  long long ret=1;
  for(long long i=0;i<N;i++)   
    ret*=x;
  return ret;
}
//繰り返し二乗法
long long repeat_squaring(long long x, long long n){
  if(n==0) return 1;
  else if(n%2==0){
    long long t=repeat_squaring(x,n/2);
    return t*t%mod;
  }
  else
    return x*repeat_squaring(x,n-1);
}
//素因数分解(mapで返す)
map<long long,long long> factor(long long p){
  ll p1=p;
  map<long long,long long>ret;
  for(long long i=2;i*i<=p1;i++){
     while(p%i==0){
      ret[i]++;
      p/=i;
    }
  }
  if(p!=1)
  ret[p]++;
  return ret;
}
//素数判定
bool is_prime(long long N){
  for(long long i=2;i*i<=N;i++){
    if(N%i==0)
      return false;
  }
  return true;
}
//最大値更新
void chmax(long long &a,long long b){
  a=max(a,b);
}
//最小値更新
void chmin(long long &a,long long b){
  a=min(a,b);
}

//構造体

/////////////////⊂('ω'⊂ )))Σ≡GO!/////////////////


//メイン関数
int main(){
  //doubleの桁数
  cout<<fixed<<setprecision(10);
  
  lin(N);
  N %= 10;
  if(N == 3) cout << "bon" << endl;
  else if(N == 0 || N == 1 || N == 6 || N == 8) cout << "pon" << endl;
  else cout << "hon" << endl;
}

Measured memory_bytes: 3628
# -*- coding: utf-8 -*-


def main():
    n, m = map(int, input().split())
    ab = sorted([list(map(int, input().split())) for _ in range(m)], key=lambda x: x[1])
    ans = 1
    axis = ab[0][1]

    for i in range(1, m):
        if ab[i][0] >= axis:
            ans += 1
            axis = ab[i][1]

    print(ans)


if __name__ == '__main__':
    main()


Measured memory_bytes: 29856
#include<bits/stdc++.h>
using namespace std;
/*#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
/*template <typename T>
using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
*/typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef pair<ll,ll> pl;
typedef pair<int,int> pii;

#define int ll
#define LOCAL 0
#define dbg(x) cout << #x << " is " << x << "\n"
#define gll(x) scanf("%d",&x)
#define gll2(x,y) scanf("%d%d",&x,&y)
#define gll3(x,y,z) scanf("%d%d%d",&x,&y,&z)
#define gllarr(arr,n) f(i,n) gll(arr[i]);
#define sz(x) ((int)x.size())
#define s(x) sort(x.begin(),x.end())
#define all(v) v.begin(),v.end()
#define rs(v) { s(v) ; r(v) ; }
#define r(v) {reverse(all(v));}
#define pb push_back
#define f(i,n) for(int i=0;i<n;i++)
#define fr(i,n) for(int i=n-1;i>=0;i--)
#define rep(i,a,b) for(int i=a;i<=b;i++)
#define repr(i,a,b) for(int i=a;i>=b;i--)

const ll mod = (ll)1e9 + 7;
const ll inf = (ll)1e16;
const ld eps = 1e-12;
const ll N = (int)1e5 + 5;
const ll LOGN = 19;
const ld PI = 3.14159265358979323846;
inline ll mul(ll a, ll b, ll m = mod) { return (ll)(a * b) % m;}
inline ll add(ll a, ll b, ll m = mod) { a += b; if(a >= m) a -= m; if(a < 0) a += m; return a;}
inline ll power(ll a, ll b, ll m = mod) { if(b == 0) return 1; if(b == 1) return (a % m); ll x = power(a, b / 2, m); x = mul(x, x, m); if(b % 2) x = mul(x, a, m); return x;}

int32_t main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    if (LOCAL) {
        freopen("C:\\Users\\Dishant\\Desktop\\Collection-DEV c++\\input.txt", "r", stdin);
        freopen("C:\\Users\\Dishant\\Desktop\\Collection-DEV c++\\output.txt", "w", stdout);
    }
    set< pair< pair<int, int>, int> > S;
    int n, k;
    cin>>n>>k;
    int a[n], f[n];
    f(i, n) cin>>a[i];
    f(i, n) cin>>f[i];
    sort(a, a + n);
    sort(f, f + n);
    reverse(f, f + n);
    int low = 0, high = (int)1e13;
    int ans = -1;
    while(low <= high) {
    	int mid = (low + high) >> 1;
    	//Is score of mid possible?
    	int check = 0;
    	for(int i = 0; i < n; i++) {
    		int to = a[i] * f[i];
    		if(to > mid) {
    			int need = to - mid;
    			need = (need + f[i] - 1)/f[i];
    			check += need;
    		}
    	}
    	//cout<<mid<<' '<<check<<endl;
    	if(check > k) low = mid + 1;
    	else {
    		ans = mid;
    		high = mid - 1;
    	}
    }
    cout<<ans;
    return 0;
}

Measured memory_bytes: 3328
#include <stdio.h>

main()
{
	int a, b, c ,w;

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

	if(a > b)
	{
		w=a; a=b; b=w;
	}
	if(b > c)
	{
		w=b; b=c; c=w;
	}
	if(a > b)
	{
		w=a; a=b; b=w;
	}
	printf("%d %d %d\n", a, b, c);

	return 0;
}

Measured memory_bytes: 596
N, P = map(int, input().split())
A = list(map(int, input().split()))
dp = [[0] * (N + 1) for i in range(2)]
dp[0][0] = 1
for i in range(N):
    if A[i] % 2 == 0:
        # これを選ぶとき
        dp[0][i + 1] += dp[0][i]
        dp[1][i + 1] += dp[1][i]
        # これを選ばない時
        dp[0][i + 1] += dp[0][i]
        dp[1][i + 1] += dp[1][i]
    else:
        # これを選ぶとき
        dp[0][i + 1] += dp[1][i]
        dp[1][i + 1] += dp[0][i]
        # これを選ばない時
        dp[0][i + 1] += dp[0][i]
        dp[1][i + 1] += dp[1][i]


print(dp[P][N])


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

int n;
int a, b, c;

int main()
{
  cin >> n;
  for (int i = 0; i < n; i++){
    cin >> a;
    if (a & 1){
      b++;
    } else {
      c++;
    }
  }

  if (b & 1){
    cout << "NO" << endl;
    return 0;
  }

  cout << "YES" << endl;
}



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

using namespace std;

typedef long long ll;

const int N = 1e5;
const int INF = 1e9;
const int MOD = 1e9 + 7;



int main() {
    int n;
    cin >> n;
    int ans = (n + 1) * n / 2;
    cout << ans;
}

Measured memory_bytes: 256
using System;
using System.Linq;
using System.Collections;
using System.Collections.Generic;
using System.Diagnostics.CodeAnalysis;
using System.Threading;
using System.IO.Pipes;
using System.ComponentModel;
using System.Drawing;
using Microsoft.VisualBasic;

namespace ConsoleApp1
{
    class Program
    {
        static void Main(string[] args)
        {

            string S = Console.ReadLine();

            long sum = 0;

            foreach (char c in S) 
            {
                sum += long.Parse(c.ToString());            
            }

            if (sum % 9 == 0)
            {
                Console.WriteLine("Yes");
            }
            else 
            {
                Console.WriteLine("No");
            }


        }

    }
}


Measured memory_bytes: 32964
#include <bits/stdc++.h>
#define pb push_back
#define mp make_pair
#define int long long
#define inf 1000000007
#define LINF 1000000000000000007LL
#define ll long long
using namespace std;
int dp[101][114514];
signed main(){
	int n,w;
	cin>>n>>w;
	vector<int> we,va;
	for(int i=0;i<n;i++){
		int x,y;
		cin>>x>>y;
		we.pb(x); va.pb(y);
	}
	for(int i=1;i<=n;i++){
		for(int j=0;j<=w;j++){
			if( j + we[i-1] <= w ){
				dp[i][ j + we[i-1] ] = max( dp[i][j+we[i-1]], dp[i-1][ j ] + va[i-1] );
			}
			dp[i][j] = max( dp[i][j], dp[i-1][j] );
		}
	}
	vector<int> ans;
	for(int i=0;i<=w;i++){
		ans.pb( dp[n][i] );
	}
	sort(ans.begin(), ans.end() );
	cout<<ans[ans.size()-1]<<endl;
	return 0;
}

Measured memory_bytes: 90620
main :: IO ()
main = do
  k <- read <$> getLine
  if k `mod` 2 == 0 || k `mod` 5 == 0
    then print (-1)
    else do
      let sevens =
            iterate (\(a, i) -> ((a * 10 + 7) `mod` k, i + 1)) (7 `mod` k, 1)
      let Just answer = lookup 0 sevens
      print $ answer
      return ()


Measured memory_bytes: 71992
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,a,b) for(int i=(a),i##formax=(b);i<i##formax;i++)
#define FORR(i,a,b) for(int i=(a),i##formax=(b);i>=i##formax;i--)
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define pcnt __builtin_popcount
#define sz(x) (int)(x).size()
#define maxs(x,y) x=max(x,y)
#define mins(x,y) x=min(x,y)
#define show(x) cout<<#x<<" = "<<x<<endl;
#define all(a) (a.begin()),(a.end())
#define each(it,c) for(__typeof((c).begin()) it=(c).begin();it!=(c).end();it++)
#define perm(c) sort(all(c));for(bool c##p=1;c##p;c##p=next_permutation(all(c)))
#define bitComb(a,n,k) for(int a##x,a##y,a=(1<<k)-1;a<(1<<n);a##x=a&-a,a##y=a+a##x,a=(((a&~a##y)/a##x)>>1)|a##y)
#define uniq(v) sort(all(v));v.erase(unique(all(v)), v.end())
#define bit(n) (1LL<<(n))
#define randInt(l,r) (uniform_int_distribution<ll>(l,r)(rnd))
#define randDouble(l,r) (uniform_real_distribution<double>(l,r)(rnd))
#define dout(d) printf("%.12f\n",d)

typedef long long ll;
typedef __int128_t lll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
template<class T>using V=vector<T>;
template<class T>using VV=V<V<T>>;
template<class T,class Y>ostream& operator<<(ostream& o,const pair<T,Y>& p){return o<<"("<<p.fi<<", "<<p.se<<")";}
template<typename A,size_t N,typename T>void Fill(A (&array)[N],const T&v){fill((T*)array,(T*)(array+N),v);}
lll gcd(lll a,lll b,lll &x,lll &y){if(!b){x=1;y=0;return a;}lll d=gcd(b,a%b,y,x);y-=a/b*x;return d;}
ll modInv(ll a,ll m){lll x,y;gcd(a,m,x,y);return (x%m+m)%m;}
ll modPow(lll a,lll n,ll m){if(!a)return a;lll p=1;for(;n>0;n>>=1,a=a*a%m)if(n&1)p=p*a%m;return(ll)p;}
bool isPrime(ll n){if(n<2||n%2==0)return n==2;lll t=n-1,d=t/(t&-t);for(lll a:{2,325,9375,28178,450775,9780504,1795265022})if(a%n){for(t=d,a=modPow(a,t,n);t!=n-1&&a!=1&&a!=n-1;a=a*a%n,t=t*2%n);if(a!=n-1&&t%2==0)return 0;}return 1;}
//V<ll>fac,rfac;void setFac(int n,int mod){fac=rfac=V<ll>(++n);fac[0]=1;FOR(i,1,n)fac[i]=fac[i-1]*i%mod;rfac[n-1]=modInv(fac[n-1],mod);FORR(i,n-1,1)rfac[i-1]=rfac[i]*i%mod;}
const int IINF = 1e9+6;
const ll LINF = 1e18;
const int MOD = 1e9+7;
const double PI = acos(-1);
const double EPS = 1e-10;
static random_device rd;
static mt19937 rnd(rd());

const int N = 1e5;
ll a, b, c, d;
ll f(ll l){
  return b/l-a/l;
}
main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  cin >> a >> b >> c >> d;
  a--;
  cout << f(1)-f(c)-f(d)+f(c/__gcd(c,d)*d) << endl;
}

Measured memory_bytes: 256
import itertools

def amida_counter(H_i_amida_list):
    counter = 0

    for amida_bin in range(2**len(H_i_amida_list)):
        if (("11" in format(amida_bin, "b")) == False):
            counter += 1

    return counter

def amida_number(left_amida, right_amida):
    left_counter = amida_counter(left_amida) if(len(left_amida) > 0) else 1
    right_counter = amida_counter(right_amida) if(len(right_amida) > 0) else 1

    return (left_counter * right_counter)

def X_amida_number(W, W_i):
    x_amida = "0" * (W - 1)
    left_x_amida = x_amida[:(W_i-2)] if(W_i-2 >= 0) else ""
    right_x_amida = x_amida[(W_i+1):]

    return amida_number(left_x_amida, right_x_amida)

def Y_amida_number(W, W_i):
    y_amida = "0" * (W - 1)
    left_y_amida = y_amida[:W_i-1] if(W_i-1 >= 0) else ""
    right_y_amida = y_amida[W_i+1:]

    return amida_number(left_y_amida, right_y_amida)

def Z_amida_number(W, W_i):
    z_amida = "0" * (W - 1)
    left_z_amida = z_amida[:W_i-1] if(W_i-1 >= 0) else ""
    right_z_amida = z_amida[W_i+2:]

    return amida_number(left_z_amida, right_z_amida)

def amida_all(amida_list, W):
    for i, j in itertools.product(range(W), range(3)):
        if(j == 0):
            amida_list[i][j] = X_amida_number(W, i)
        elif(j == 1):
            amida_list[i][j] = Y_amida_number(W, i)
        else:
            amida_list[i][j] = Z_amida_number(W, i)

    return amida_list

H, W, K = map(int, input().split())
amida_list = [[0]*3 for i in range(W)]
amida_list = amida_all(amida_list, W)

seed_dp_array = [0 for i in range(W)]
dp_array = [list(seed_dp_array) for i in range(H + 1)]
dp_array[0][0] = 1

for H_i, W_i in itertools.product(range(1, H + 1), range(W)):
    if (W_i == 0):
        if(W == 1):
            dp_array[H_i][0] = dp_array[H_i - 1][W_i] * amida_list[W_i][1]
        else:
            dp_array[H_i][0] = dp_array[H_i - 1][W_i] * amida_list[W_i][1] + dp_array[H_i - 1][W_i + 1] * amida_list[W_i][2]
    elif (W_i == (W - 1)):
        dp_array[H_i][W - 1] = dp_array[H_i - 1][W_i - 1] * amida_list[W_i][0] + dp_array[H_i - 1][W_i] * amida_list[W_i][1]
    else:
        dp_array[H_i][W_i] = dp_array[H_i - 1][W_i - 1] * amida_list[W_i][0] + dp_array[H_i - 1][W_i] * amida_list[W_i][1] + dp_array[H_i - 1][W_i + 1] * amida_list[W_i][2]

print(dp_array[H][K - 1] % 1000000007)

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

int main() {
    int n,k,cnt = 0,j = 0,len = __INT_MAX__;
    cin >> n >> k;
    int a[n],ans[n],flag[n + 1];
    for(int i = 0;i < n;++i){
        cin >> a[i];
        ans[i] = flag[i] = 0;
    }
    flag[n] = 0;
    
    for(int i = 0;i < n;++i){
        flag[a[i]]++;
        if(flag[a[i]] == 1 && a[i] <= k){
            cnt++;
        }
        if(cnt < k){
            ans[i] = 0;
        }else{
            while(flag[a[j]] >= 2 || a[j] > k){
                flag[a[j]]--;
                j++;
            }
            ans[i] = i - j + 1;
        }
    }
    
    for(int i = 0;i < n;++i){
        if(ans[i] != 0){
            len = min(len, ans[i]);
        }
    }
    if(len == __INT_MAX__){
        len = 0;
    }
    cout << len << endl;
}



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

int getmd(int a,int b,int c,int d){
    return abs(a-c)+abs(b-d);
}

int main(){
    string s,t;
    int ans(0);
    cin >> s >> t;

    rep(i,3){
        if(s[i]==t[i]){
            ans++;
        }
    }

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

Measured memory_bytes: 256
#include <bits/stdc++.h>
#pragma GCC optimize("Ofast")
using namespace std;
typedef long long ll;
const ll MOD = 1000000007;
#define SortAsc(c) std::sort(c.begin(), c.end())
#define SortDesc(c) std::sort(c.rbegin(), c.rend())
int dx[8] = {0, 1, 0, -1, 1, 1, -1, -1};
int dy[8] = {1, 0, -1, 0, 1, -1, 1, -1};

int main()
{
    int n, k;
    cin >> n >> k;
    vector<int> p(n);
    for (int i = 0; i < n; i++)
    {
        cin >> p[i];
    }

    SortAsc(p);

    int res = 0;
    for (int i = 0; i < k; i++)
    {
        res += p[i];
    }

    cout << res << endl;
}

Measured memory_bytes: 3600
#include <stdio.h>
#include <vector>
#include <iostream>
#include <queue>
#include <bits/stdc++.h>

using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<double> vd;
typedef vector<vd> vvd;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<string> vs;
typedef vector<vs> vvs;

typedef vector<pair<int, int>> vpi;
typedef vector<tuple<int, int, int>> vti;


int main() {
    ios::sync_with_stdio(0); cin.tie(0);
    ll n;
    cin >> n;
    vl a(n+1), b(n+1);
    for (int i=0;i<n+1;i++) cin >> a[i];
    for (int i=0;i<n;i++) cin >> b[i];
    
    ll prev=0, ans=0;
    for (int i=0;i<n+1;i++){
        ll now = b[i] + prev;
        ans += min(a[i], now);
        if (now > a[i]) prev = min(b[i], now - a[i]);
        else prev = 0;
    }
    cout << ans << endl;
}


Measured memory_bytes: 1792
import sys

# 入力を整数に変換して受け取る
def II(): return int(sys.stdin.readline())
def MI(): return map(int, sys.stdin.readline().split())
def MI1(): return map(int1, sys.stdin.readline().split())
# 入力全てを整数に変換したものの配列を受け取る
def LI(): return list(map(int, sys.stdin.readline().split()))
# 入力全てを整数に変換して1引いたものの配列を受け取る
def LLI(rows_number): return [LI() for _ in range(rows_number)]
# リストを改行区切りで出力する
p2D = lambda x: print(*x, sep="\n")



r=II()

print(3*r**2)

Measured memory_bytes: 3064
#include <bits/stdc++.h>
using ll = long long;
using namespace std;
#define rep(i,n) for(int i=0, i##_len=(int)(n); i<i##_len; i++)
#define reps(i,n) for(int i=1 , i##_len=(int)(n);i<=i##_len;i++)
#define rrep(i,n) for(int i=((int)(n)-1);i>=0;i--)
#define rreps(i,n) for(int i=((int)(n));i>0;i--)
#define repi(i,x) for(auto i=(x).begin(),i##_fin=(x).end();i!=i##_fin;i++)
#define all(x) (x).begin(), (x).end()
#define F first
#define S second
#define mp make_pair
#define mt make_tuple
#define pb push_back
#define eb emplace_back
string solve(bool a) { return ((a) ? "Yes" : "No"); }
typedef vector<int> Vi;
typedef vector<Vi> VVi;
typedef pair<int , int> Pi;
typedef vector<Pi> VPi;
typedef vector<long long> V;
typedef vector<V> VV;
typedef pair<long long , long long> P;
typedef vector<P> VP;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1;} return 0;}
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1;} return 0;}
template <class T, class U>ostream& operator<<(ostream& os, const pair<T, U>& p) {
	os << "(" << p.first << "," << p.second << ")";
	return os;
}
template <class T>ostream& operator<<(ostream& os, const vector<T>& v) {
	os << "{";
	rep(i, v.size()) {
		if (i) os << ",";
		os << v[i];
	}
	os << "}";
	return os;
}
template <class T, class U>istream& operator>>(istream& is, pair<T, U>& p) {
	is >> p.first >>p.second ;
	return is;
}
template <class T>istream& operator>>(istream& is,  vector<T>& v) {
	rep(i, v.size()) {
		is >> v[i];
	}
	return is;
}
const long long INFLL = 1LL<<60;
const int INF = 1<<30;
const double PI=acos(-1);
int main(){
	int h,w,k;
//	int ans=0;
	cin >>h>>w>>k;
	vector<string> s(h);
	cin >> s;
	VVi ans(h, Vi(w, -1));
	bool has = false;
	bool first = false;
	int at     = 0;
	bool init  = false;
	rep(i,h){
		has = false;
		init = false;
		rep(j, w) { has |= (s[i][j] == '#'); }
		if(has){
			at++;
			for (int j = 0; j < w;j++){
				
				if(s[i][j]=='#' and init){
					at++;
				}
				ans[i][j] = at;
				if(s[i][j]=='#'){
					init = true;
				}
			} 	
			if(first==false){
			
				for (int I = 0; I < i;I++){
					rep(J, w) { ans[I][J] = ans[i][J]; }
				}
				first = true;
			}
		}else{
			if(first){
				rep(j, w) { ans[i][j] = ans[i - 1][j]; }
			}
		}

	}
	rep(i,h){
		rep(j, w) { cout << ans[i][j]; 
		if(j!=w-1){
			cout << " ";
		}
		}
		cout << endl;
	}
	//cout<<ans<<endl;
}

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

#include <iostream>
//#include <algorithm>
// #include <iomanip>
#define ll long long
#define map unordered_map
#define set unordered_set
#define pll pair<ll, ll>
#define vll vector<ll>
#define mll map<ll, ll>

using namespace std;

const ll MOD = 1000000007LL;
const ll INF = (1LL << 60LL);

int main() {
  // std::cout << std::fixed << std::setprecision(10);
  ll A, B;
  scanf("%lld %lld", &A, &B);

  cout << (A * B) << endl;
}


Measured memory_bytes: 3716
N=int(input())
a=input()
b=input()
V=[]
C=[]
A=a.split()
B=b.split()
for i in range(len(A)):
  V.append(int(A[i]))
  C.append(int(B[i]))


value=0
cost=0
for i in range(N):
  if (V[i]>C[i]):
    value+=V[i]
    cost+=C[i]
print(value-cost)

Measured memory_bytes: 3064
from collections import Counter
def resolve():
    N = int(input())
    A = list(map(int, input().split()))

    CNT = Counter(A)

    q = 0
    for v in CNT.values():
        if v >= 2:
            q += v - 1

    ans = len(CNT.keys())
    if q % 2 == 0:
        print(ans)
    else:
        print(ans - 1)


if __name__ == "__main__":
    resolve()


Measured memory_bytes: 22120
#include <algorithm>
#include <cassert>
#include <cmath>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>
using namespace std;
typedef long long ll;

#define rep(i, n) for(ll i = 0; i < n; i++)
#define REP(i, n) for(ll i = 1; i < n + 1; i++)
#define PI 3.14159265359
#define EPS 0.0000000001
#define MOD 1000000007
//cout << std::fixed << std::setprecision(15) << y << endl;


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

    ll bits = 0;
    rep(i, w.size()){
        bits = bits ^ (1 << (w[i] - 'a'));
    }
    if(bits == 0){
        cout << "Yes" << endl;
    }else{
        cout << "No" << endl;
    }

    return 0;
}

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

typedef vector<int> vi;

int N, M;
vi H;
vector<vi> G;

void input_init(void) {
	cin >> N >> M;
	H.resize(N + 1, 0);
	for (int i = 1; i <= N; ++i)
		cin >> H[i];
	G.resize(N + 1);
	for (int i = 0; i < M; ++i) {
		int a, b;
		cin >> a >> b;
		G[a].push_back(H[b]);
		G[b].push_back(H[a]);
	}
}

int solve(void) {
	int cnt = 0;
	for (int i = 1; i <= N; ++i) {
		if (G[i].size() == 0)
			++cnt;
		else {
			int val = *(max_element(G[i].begin(), G[i].end()));
			if (H[i] > val)
				++cnt;
		}
	}
	return cnt;
}

int main(void) {
	input_init();
	int ans = solve();
	cout << ans << '\n';
	return 0;
}


Measured memory_bytes: 8728
def bubble_sort(C, key):
    n = len(C)
    flag = True
    i = 0
    while flag:
        flag = False
        for j in range(n - 1, i, -1):
            if key(C[j]) < key(C[j - 1]):
                C[j - 1], C[j] = C[j], C[j - 1]
                flag = True
        i += 1

def selection_sort(C, key):
    n = len(C)
    for i in range(n):
        minj = i
        for j in range(i, n):
            if key(C[j]) < key(C[minj]):
                minj = j
        if i != minj:
            C[i], C[minj] = C[minj], C[i]

def chk_stable(org_arr, sorted_arr):
    n = len(org_arr)

    org_num_cnt = {}
    for i in range(n):
        num = org_arr[i][1]
        if num in org_num_cnt:
            org_num_cnt[num].append(i)
        else:
            org_num_cnt[num] = [i]

    is_stable = True
    _j = 0
    for i in range(1, n):
        if _j > 0:
            _j -= 1
            continue

        if sorted_arr[i-1][1] == sorted_arr[i][1]:
            idx_list = org_num_cnt[sorted_arr[i][1]]
            for j in range(len(idx_list)):
                if org_arr[idx_list[j]][0] != sorted_arr[i-1+j][0]:
                    is_stable = False
                    break
            _j = len(idx_list)-1
        if not is_stable:
            break

    return is_stable

n = int(input())

A = input().split()
C1 = A[:]
C2 = A[:]

bubble_sort(C1, lambda x: x[1])
print(*C1)
if chk_stable(A, C1) == True:
    print("Stable")
else:
    print("Not stable")

selection_sort(C2, lambda x: x[1])
print(*C2)
if chk_stable(A, C2) == True:
    print("Stable")
else:
    print("Not stable")


Measured memory_bytes: 5616
N, x = map(int, input().split())
if N == 2:
    if x == 2:
        print("Yes")
        print("1")
        print("2")
        print("3")
    else:
        print("No")
    exit()

if x == 1 or x == 2 * N - 1:
    print("No")
    exit()

print("Yes")
diff = N - x
if diff < 0:
    ans = list(range(1, 2 * N))
    ans = ans[abs(diff):] + ans[:abs(diff)]
elif diff > 0:
    ans = list(range(1, 2 * N))
    ans = ans[2 * N - diff - 1:] + ans[:-diff]
else:
    ans = list(range(1, 2 * N))
for a in ans:
    print(a)


Measured memory_bytes: 14068
#include<bits/stdc++.h>
using namespace std;    
#define int long long        
#define endl "\n"
#define deb(x) cout<<#x<<" "<<x<<endl
#define sc(ar,n) for(int pen=0;pen<n;pen++){ cin>>ar[pen];}
#define pr(ar) for(int pen=0;pen<sizeof(ar)/8;pen++){ cout<<ar[pen]<<" ";} cout<<endl;
#define fastio ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define rt return 0;
#define mod 1000000007
const int N= 8*1e5+ 10;
int st[N]={0};
const int INF = 1e16;
void update(int ss, int se, int i, int diff, int si)  
{  
    // Base Case: If the input index lies outside the range of  
    // this segment  
    if (i < ss || i > se)  
        return;  
  
    // If the input index is in range of this node, then update  
    // the value of the node and its children  
    st[si] = st[si] + diff;  
    if (se != ss)  
    {  
        int mid = (ss+se)/2;  
        update(ss, mid, i, diff, 2*si);  
        update(mid+1, se, i, diff, 2*si + 1);  
    }  
}  
int get_sum(int ss, int se, int qs, int qe, int si)  
{  
    // If segment of this node is a part of given range, then return  
    // the sum of the segment  
    if (qs <= ss && qe >= se)  
        return st[si];  
  
    // If segment of this node is outside the given range  
    if (se < qs || ss > qe)  
        return 0;  
  
    // If a part of this segment overlaps with the given range  
    int mid = (ss+se)/2;
    return get_sum(ss, mid, qs, qe, 2*si) +  
        get_sum(mid+1, se, qs, qe, 2*si+1);  
}
int dp[101][100001];
int wt[101];
int val[101];
int knap(int i, int vl)
{
    if(vl<0){
        return INF;
    }
    if(i<0){
        if(vl==0)
        {
            return 0;
        }
        return INF;
    }
    if(dp[i][vl]!=-1){
        return dp[i][vl];
    }   
    int j=vl;
    dp[i][j]=INF;
    dp[i][j] = min ( dp[i][j] , knap(i-1, vl));
    dp[i][j]= min ( dp[i][j] , knap(i-1, vl- val[i-1]) + wt[i-1]);
    return dp[i][j];
}
signed main()
{
    int n,w;
    cin>>n>>w;
   // int wt[n],val[n];
    for(int i=0;i<n;i++){
        cin>>wt[i]>>val[i];
    }

    for(int i=0;i<101;i++){
        for(int j=0;j<100001;j++){
            dp[i][j]=-1;
        }
    }
    int ans=0;
    for(int i=100000;i>=0;i--){
        int cal=knap(n,i);
        if(cal<=w){
            ans=i;
            break;
        }
    }
    cout<<ans<<endl;
}

Measured memory_bytes: 80128
#include <bits/stdc++.h>
using namespace std;
typedef long long LL;
int dp[550000];

int main(){
    int n;
    string str;
    cin >> n >> str;
    for(int i = 0; i <= n; i++) dp[i] = -1000000;
    dp[0] = 0;
    for(int i = 0; i < n; i++){
        dp[i+1] = max(dp[i], dp[i+1]);
        if(str[i] == '1') continue;
        int s1 = i;
        int s2 = i;
        while(s1-1 >= 0 && str[s1-1] == '1') s1--;
        while(s2+1 < n  && str[s2+1] == '1') s2++;
        if(s1 == i || s2 == i) continue;
        for(int t = i-1; t >= s1; t--){
            dp[i+2] = max(dp[i+2], dp[t] + i-t);
        }
        for(int t = i+1; t <= s2; t++){
            dp[t+1] = max(dp[t+1], dp[i-1] + t-i);
        }
    }
    cout << dp[n] << endl;
}


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

bool Q;
struct Line {
    mutable ll k, m , p;
    bool operator<(const Line& o) const {
        return Q ? p < o.p : k < o.k;
    }
};

struct LineContainer : multiset<Line> {
    const ll inf = LLONG_MAX;
    ll div(ll a, ll b) {
        return a / b - ((a ^ b) < 0 && a % b);
    }

    bool isect(iterator x, iterator y) {
        if (y == end()) {
            x->p = inf;
            return false;
        }
        if(x->k == y->k)
            x->p = x->m > y->m ? inf : -inf;
        else
            x->p = div(y->m - x->m, x->k - y->k);
        return x->p >= y->p;
    }

    void add(ll k, ll m){
        auto z = insert({k, m, 0}), y = z++, x = y;
        while(isect(y, z))
            z = erase(z);
        if(x != begin() && isect(--x, y))
            isect(x, y = erase(y));
        while((y = x) != begin() && (--x)->p >= y->p)
            isect(x, erase(y));
    }

    ll query(ll x) {
        assert(!empty());
        Q = 1; auto l = *lower_bound({0, 0, x}); Q = 0;
        return l.k*x + l.m;
    }
};

const int MAXN = 2e5 + 5;
ll dp[MAXN], h[MAXN];

int main() {
    LineContainer cht;
    int n;
    ll c;
    cin >> n >> c;
    for(int i = 1; i <= n; i++)
        cin >> h[i];
    dp[1] = 0;
    cht.add(2ll*h[1], -h[1]*h[1]);
    for(int m = 2; m <= n; m++) {
        dp[m] = h[m]*h[m] + c - cht.query(h[m]);
        cht.add(2ll*h[m], -h[m]*h[m] - dp[m]);
    }
    cout << dp[n] << endl;
}

Measured memory_bytes: 15872
#include <cstdio>

int main() {
    int n;
    scanf("%d", &n);
    int r[n];
    for (int i = 0; i < n; i++) {
        scanf("%d", &r[i]);
    }
    int min_r = r[0];
    int max_diff = r[1] - r[0];
    for (int i = 1; i < n; i++) {
        if (r[i] < min_r) {
            min_r = r[i];
        } else {
            if (r[i] - min_r > max_diff) {
                max_diff = r[i] - min_r;
            }
        }
    }
    printf("%d\n", max_diff);
    return 0;
}


Measured memory_bytes: 3452
#include<bits/stdc++.h> 
using namespace std;
const int N=2e5+5;
int n,mod1,mod2;
int md1[N],md2[N];
int ans1,ans2,temp;
char s[N];
void solve(int n)
{
	while (n>0)
	{
		int q=n,p=0;
		while (q>0)
		{
			q=q&(q-1);
			p++;
		}
		n=n%p;
		temp++;
	}
}
int main()
{
	cin>>n;
	scanf("%s",&s);
	for (int i=0;i<n;i++) if (s[i]=='1') mod1++;
	mod2=mod1-1,mod1++;
	if (mod2==0)
	{
		md1[n-1]=md2[n-1]=1;
		for (int i=n-2;i>=0;i--) md1[i]=md1[i+1]*2%mod1;
		for (int i=n-1;i>=0;i--) if (s[i]=='1') ans1=(ans1+md1[i])%mod1;
		for (int i=0;i<n;i++)
		{
			if (s[i]=='1') cout<<0<<endl;
			if (s[i]=='0')
			{
				temp=1;
				int tmp=(ans1+md1[i])%mod1;
				solve(tmp);
				cout<<temp<<endl;
			}
		}
		return 0;
	}
	md1[n-1]=md2[n-1]=1;
	for (int i=n-2;i>=0;i--) md1[i]=md1[i+1]*2%mod1,md2[i]=md2[i+1]*2%mod2;
	for (int i=n-1;i>=0;i--) if (s[i]=='1') ans1=(ans1+md1[i])%mod1,ans2=(ans2+md2[i])%mod2;
	for (int i=0;i<n;i++)
	{
		if (s[i]=='1')
		{
			temp=1;
			int tmp=(ans2-md2[i]+mod2)%mod2;
			solve(tmp);
			cout<<temp<<endl;
		}
		if (s[i]=='0')
		{
			temp=1;
			int tmp=(ans1+md1[i])%mod1;
			solve(tmp);
			cout<<temp<<endl;
		}
	}
}

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

#define REP(i, n) for (int i = 0; i < (int)(n); ++i)
#define ALL(c) (c).begin(), (c).end()

int main() {
    vector<char> buffer(1024*1024);
    cin.rdbuf()->pubsetbuf(&buffer[0], buffer.size());

    int N; cin >> N;
    vector<pair<int64_t, int64_t>> points(N);
    REP(i, N) cin >> points[i].first >> points[i].second;

    vector<vector<int64_t>> f(N);
    REP(i, N) {
        auto [x, y] = points[i];
        f[i] = {x-y, x+y};
    }

    int64_t ans = numeric_limits<int64_t>::min();
    REP(d, 2) {
        auto m1 = numeric_limits<int64_t>::max();
        auto m2 = numeric_limits<int64_t>::min();
        REP(i, N) m1 = min(m1, f[i][d]);
        REP(i, N) m2 = max(m2, f[i][d]);
        ans = max(ans, m2 - m1);
    }
    cout << ans << endl;
}


Measured memory_bytes: 17848
#include <iostream>
#include <algorithm>
#include <vector>

#define REP(i,n) for(int i = 0; i < n; i++)
#define ll long long
#define PI 3.141592653589

using namespace std;

int main(void){
    int A, B, ans;
    cin >> A >> B;

    if(A == 1 && B == 2) ans = 3;
    if(A == 1 && B == 3) ans = 2;
    if(A == 2 && B == 1) ans = 3;
    if(A == 2 && B == 3) ans = 1;
    if(A == 3 && B == 1) ans = 2;
    if(A == 3 && B == 2) ans = 1;
    
    cout << ans;
    return 0;
}

Measured memory_bytes: 256
n = int(input())
s = input()

cnts = [0, 0, 0]
for i in range(n):
    if s[i] == 'R':
        cnts[0] += 1
    elif s[i] == 'G':
        cnts[1] += 1
    else:
        cnts[2] += 1

ans = cnts[0] * cnts[1] * cnts[2]

for i in range(n):
    for j in range(i+1, n):
        k = j + (j - i)
        if k >= n:
            continue
        if len(set([s[i], s[j], s[k]])) == 3:
            ans -= 1
print(ans)

Measured memory_bytes: 68320
#include <bits/stdc++.h>
using namespace std;
 
#define ull     		unsigned long long int
#define ll      		long long int
#define loop(i,s,e)     for(ll i=(s);i<(e);i++)
#define rloop(i,s,e)    for(ll i=(s);i>=(e);i--)
#define scan(any)       for(auto &i:any) cin>>i;
#define print(any)      for(auto i:any) cout<<i<<" "; nl;
#define nl              cout<<'\n'
#define pi 3.141592654
#define hell 1000000007
#define io ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0)
#define fix(n) cout << fixed << setprecision(n)
#define IP(n) int n;cin>>n
#define IP2(a, b) int a,b;cin>>a>>b
#define Max(a,b) ((a)>(b)?(a):(b))
#define Min(a,b) ((a)<(b)?(a):(b))
#define rep(i,a,b) for (__typeof((b)) i=(a);i<(b);i++)
#define ren(i,a,b) for(__typeof((a)) i=(a);i>=(b);i--)
#define mp make_pair
#define pb push_back
#define fi first
#define se second
#define vi vector<int>
#define pii pair<int,int>
#define piii pair<pair<int,int>,int>
#define all(v) (v).begin(), (v).end()
#define sz(x) (int)x.size()
#define set(a,n) memset(a,n,sizeof(a))
#define DEBUG(x) cout << '>' << #x << ':' << x << endl;
const int INF = 1<<29;
inline int two(int n) { return 1 << n; }
inline int last_bit(int n) { return n & (-n); }
inline int test(int n, int b) { return (n>>b)&1; }
inline bool EQ(double a, double b) { return fabs(a-b) < 1e-9; }
inline void unset_bit(int & n, int b) { n &= ~two(b); }
inline void set_bit(int & n, int b) { n |= two(b); }
inline int ones(int n) { int res = 0; while(n && ++res) n-=n&(-n); return res; }
template<class T> void chmax(T & a, const T & b) { a = max(a, b); }
template<class T> void chmin(T & a, const T & b) { a = min(a, b); }
/////////////////////////////////////////////////////////////////////////////////
int main()
{
IP(n);
vi v(n);
scan(v);
int ans=INF;
loop(x,1,101)
{
int cur=0;
loop(i,0,n)
cur+=(v[i]-x)*(v[i]-x);

chmin(ans,cur);
}
cout<<ans<<endl;
return 0;
}	


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main(){
 int a,b;
 cin>>a>>b;
 int c;
 c=a*b;
 
 if(c%2==0){
  cout<<"Even"<<endl;
 }
 else if (c%2!=0){
  cout<<"Odd"<<endl;
 }
}

Measured memory_bytes: 3588
#include <stdio.h>
typedef long long ll;
 
int main(void) {
  ll i, n, ans = 100000;
  scanf("%lld", &n);
  for(i = 0; i < n; ++i) {
    ans = ans + ans / 20;
    if(ans % 1000) ans -= ans % 1000, ans += 1000;
  }
  printf("%lld\n", ans);
  return 0;
}


Measured memory_bytes: 2604
from itertools import accumulate

def main():
    N,Q=map(int,input().split())
    S=input()
    l=[0 for i in range(0,Q)]
    r=[0 for i in range(0,Q)]
    for i in range(0,Q):
        l[i],r[i]=map(int,input().split())
    check=[]
    check_append=check.append
    for i in range(0,N-1):
        if S[i]+S[i+1]=='AC':
            check_append(1)
        else:
            check_append(0)
    ans=list(accumulate(check))
    for i in range(0,Q):
        if l[i]==1:
            print(ans[r[i]-2])
        else:
            print(ans[r[i]-2]-ans[l[i]-2])

if __name__ == '__main__':
    main()


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

using namespace std;

void col(int n,int m,bool p[][605]) {
  int d=0;
  while (m%(1<<(2*(d+1)))==0) d++;
  d=(1<<d);
  int v=(m/(d*d))%4;
  if (v==0||v==3) return;
  if (v==1) {
  	for(int i=0;i<n;i++)
  	  for(int j=0;j<n;j++) p[i][j]=(((i/d)+(j/d))&1);
  }
  else {
  	for(int i=0;i<n;i++)
  	  for(int j=0;j<n;j++) p[i][j]=((i/d)&1);
  }
}

bool f[605][605],g[605][605];

int main() {
  int n,D1,D2;
  scanf("%d%d%d",&n,&D1,&D2);
  col(n<<1,D1,f);
  col(n<<1,D2,g);
  int sz[2][2]={0};
  for(int i=0;i<(n<<1);i++)
    for(int j=0;j<(n<<1);j++) sz[f[i][j]][g[i][j]]++;
  int id1=0,id2=0;
  for(int i=0;i<2;i++)
    for(int j=0;j<2;j++)
      if (sz[i][j]>sz[id1][id2]) {
      	id1=i;
      	id2=j;
	  }
  int cnt=0;
  for(int i=0;i<(n<<1);i++) {
    for(int j=0;j<(n<<1);j++)
      if (f[i][j]==id1&&g[i][j]==id2) {
      	printf("%d %d\n",i,j);
      	cnt++;
      	if (cnt>=n*n) break;
	  }
	if (cnt>=n*n) break;
  }
  return 0;
}

Measured memory_bytes: 1664
import           Control.Monad
import           Control.Monad.ST
import qualified Data.Array                    as A
import qualified Data.Array.Unboxed            as AU
import qualified Data.ByteString.Char8         as BS
import           Data.Char
import           Data.Int
import qualified Data.IntMap                   as IM
import qualified Data.Map                      as M
import           Data.List
import qualified Data.Set                      as S
import           Data.Maybe
import           Data.Ord
import           Data.Time
import qualified Data.Vector                   as V
import qualified Data.Vector.Mutable           as VM
import qualified Data.Vector.Unboxed           as VU
import qualified Data.Vector.Unboxed.Mutable   as VUM

readString = map BS.unpack . BS.words <$> BS.getLine
readStrings n = replicateM n $ BS.unpack <$> BS.getLine
toPair [x, y] = (x, y)

main = do
  n <- read <$> getLine
  s <- replicateM n getLine
  mapM putStrLn $ solve s

solve :: [String] -> [String]
solve s = reverse $ g $ s' s

s' s = sortOn Data.Ord.Down $ map f $ group $ sort s

f s = (length s, head s)

g s =
  snd (head s) : map snd (takeWhile (\(l, _) -> fst (head s) == l) $ tail s)


Measured memory_bytes: 183292
#include<stdio.h>
#include<algorithm>
using namespace std;
int n,a,b,c,d;
char s[1000000];
int main(){
	scanf("%d %d %d %d %d", &n,&a,&b,&c,&d);
	scanf("%s", &s);
	for(int i=min(a,b);i<=max(c,d);i++){
		if(s[i-1]=='#'&&s[i]=='#'){
			printf("No");
			return 0;
		}
	}
	if((a>b&&c<d)||(b>a&&d<c)){
		for(int i=max(a,b)-1;i<min(c,d);i++){
			if(s[i-1]=='.'&&s[i]=='.'&&s[i+1]=='.'){
				printf("Yes");
				return 0;
			}
		}
		printf("No");
	}else printf("Yes");
}


Measured memory_bytes: 384
#include"bits/stdc++.h"
using namespace std;
#define REP(k,m,n) for(int (k)=(m);(k)<(n);(k)++)
#define rep(i,n) REP((i),0,(n))
using ll = long long;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
using tp3 = tuple<int, int, int>;
using Mat = vector<vector<ll>>;
constexpr int INF = 1 << 28;
constexpr ll INFL = 1ll << 60;
constexpr int dh[4] = { 0,1,0,-1 };
constexpr int dw[4] = { -1,0,1,0 };
bool isin(const int H, const int W, const int h, const int w) {
    return 0 <= h && h < H && 0 <= w && w < W;
}
// ============ template finished ============

int main()
{
    string s;
    cin >> s;
    reverse(s.begin(), s.end());

    map<ll, ll> mp;
    mp[0]++;

    const ll MOD = 2019;
    ll acc = 0;
    ll mul = 1;
    for (char c : s) {
        acc = (acc + mul * (c - '0')) % MOD;
        mul = (mul * 10) % MOD;
        mp[acc]++;
    }

    ll res = 0;
    for (auto itr : mp) {
        res += itr.second*(itr.second - 1) / 2;
    }
    cout << res << endl;
    return 0;
}


Measured memory_bytes: 3776
#include <stdio.h>
 
int main(void) {
    unsigned long long n;
    unsigned long long num;
    unsigned long long i;
    unsigned long long sum;
    scanf("%lld",&n);
    sum=0;
    for(i=0;i<n;i++) {
        scanf("%lld",&num);
        sum+=num;
    }
    printf("%lld\n",sum/n);
    return 0;
}

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

int yakusu(int n){
    int cnt = 0;
    for(int i = 1; i < sqrt(n); i++){
        if(n%i == 0) cnt += 2;
    }
    if((int)sqrt(n) == sqrt(n)) cnt++;
    return cnt;
}

int main(){
    ll n;
    cin >> n;
    // cout << yakusu(n);
    ll ans = 0;
    for(int i = 1; i < n; i++){
        ans += yakusu(n-i);
        // cout << ans << endl;
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 3644
#include <iostream>
#include <cstdio>
#include <cstring>
#include <vector>
#include <deque>
#include <queue>
#include <array>
#include <set>
#include <map>
#include <cmath>
#include <algorithm>
#include <numeric>
#include <utility>
#include <tuple>
#include <functional>
#include <bitset>
#include <cstdint>
#include <cassert>
#include <random>

using namespace std;
using i64 = int64_t;
using i32 = int32_t;
template<class T, class U> void init_n(vector<T>& v, size_t n, U x) 
{ v = vector<T>(n, x); }
template<class T> void init_n(vector<T>& v, size_t n) { init_n(v, n, T()); }
template<class T> void read_n(vector<T>& v, size_t n, size_t o = 0) 
{ v = vector<T>(n+o); for (size_t i=o; i<n+o; ++i) cin >> v[i]; }
template<class T> void read_n(T a[], size_t n, size_t o = 0)
{ for (size_t i=o; i<n+o; ++i) cin >> a[i]; }
template<class T> T iabs(const T& x) { return max(x, -x); }
// #define abs gabs

int main() {
    int a, b;
    cin >> a >> b;
    if (a > b) swap(a, b);
    for (int i = 0; i < b; ++i) {
        cout << a;
    }
    cout << endl;
    return 0;
}

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

#define ll long long
#define p_q priority_queue
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)



int main(){
    int n;
    cin>>n;
    
    cout<<(n/2)+(n%2)<<endl;
}


Measured memory_bytes: 256
#include "bits/stdc++.h"
#include <sys/timeb.h>
#include <fstream>

using namespace std;

#define repl(i,a,b) for(int i=(int)(a);i<(int)(b);i++)
#define rep(i,n) repl(i,0,n)
#define replrev(i,a,b) for(int i=(int)(b)-1;i>=(int)(a);i--)
#define reprev(i,n) replrev(i,0,n)
#define repi(itr,ds) for(auto itr = ds.begin(); itr != ds.end(); ++itr)
#define mp make_pair
#define INF 2000000000
#define INFL 2000000000000000000LL
#define EPS 1e-9
#define MOD 1000000007
#define PI 3.1415926536
#define RMAX 4294967295

typedef long long ll;
typedef pair<int, int> P;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<bool> vb;
typedef vector<char> vc;
typedef vector<string> vs;
typedef vector<double> vd;
typedef vector<P> vP;
typedef vector<vector<int> > vvi;
typedef vector<vector<bool> > vvb;
typedef vector<vector<ll> > vvll;
typedef vector<vector<char> > vvc;
typedef vector<vector<double> > vvd;
typedef vector<vector<P> > vvP;
typedef priority_queue<int, vector<int>, greater<int> > pqli;
typedef priority_queue<ll, vector<ll>, greater<ll> > pqlll;
typedef priority_queue<P, vector<P>, greater<P> > pqlP;
typedef pair<int, pair<int, int> > Edge;
typedef vector<Edge> vE;
typedef priority_queue<Edge, vector<Edge>, greater<Edge> > pqlE;


//#define DEBUG

#ifdef DEBUG
#define dprintf printf
#define dbg 
#define drepl(i,a,b) repl(i,a,b)
#define drep(i,n) rep(i,n)
#else
#define dprintf (true)?0:printf
#define dbg if(false)
#define drepl(i,a,b) int i; if(false)
#define drep(i,n) int i; if(false)
#endif // DEBUG

int N, M;
vvi G;
vi route;

void dfs1(int pos, vb &used) {
	rep(i, G[pos].size()) {
		if (used[G[pos][i]])continue;
		used[G[pos][i]] = true;
		dfs1(G[pos][i], used);
		break;
	}
	route.push_back(pos);
}

void dfs2(int pos, vb &used) {
	if (pos != 0) {
		route.push_back(pos);
	}
	rep(i, G[pos].size()) {
		if (used[G[pos][i]])continue;
		used[G[pos][i]] = true;
		dfs2(G[pos][i], used);
		break;
	}
}

int main() {
	cin >> N >> M;
	G = vvi(N);
	route = vi();
	rep(i, M) {
		int a, b;
		cin >> a >> b;
		a--; b--;
		G[a].push_back(b);
		G[b].push_back(a);
	}
	pqlP v;
	rep(i, N) {
		v.push(mp(G[i].size(), i));
	}
	vb used(N, false);
	used[0] = true;

	dfs1(0, used);
	dfs2(0, used);

	cout << route.size() << endl;
	rep(i, route.size()) {
		cout << route[i] + 1;
		if (i == route.size() - 1) {
			cout << endl;
		}
		else {
			cout << ' ';
		}
	}

	return 0;
}

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

int main() {
    int n;
    cin >> n;
    int x[n], y[n];
    rep(i, n) cin >> x[i];
    copy(x, x + n, y);
    sort(x, x + n);

    int l = x[n / 2 - 1];
    int r = x[n / 2];
    rep(i, n) {
        if (y[i] <= l)
            cout << r << endl;
        else
            cout << l << endl;
    }

    return 0;
}


Measured memory_bytes: 3712