akhauriyash/Code-Regression huggingface dataset:
#include <cstdio>
using namespace std;
const int MaxN = 503,Num = 1000;
int H,W,h,w;
int a[MaxN][MaxN];
int main() {
	scanf("%d%d%d%d",&H,&W,&h,&w);
	for (int i=1;i<=H;i++) for (int j=1;j<=W;j++) 
		if (!(i%h) && !(j%w)) a[i][j]=-Num*(h*w-1)-1;
		else a[i][j]=Num;
	long long sum=0;
	for (int i=1;i<=H;i++) for (int j=1;j<=W;j++) sum+=a[i][j];
	if (sum<0) {
		puts("No");
	} else {
		puts("Yes");
		for (int i=1;i<=H;i++) {
			for (int j=1;j<W;j++) printf("%d ",a[i][j]);
			printf("%d\n",a[i][W]);
		}
	}
	return 0;
} 

Measured memory_bytes: 2432
/* You can't connect the dots looking forward 
   you can only connect them looking backwards. */

#include<iostream>
#include<vector>
#include<map>
#include<set>
#include<algorithm>
#include<bitset>
#include<queue>
#define ll long long
#define ld long double
#define ull unsigned long long
#define boost ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);cout.precision(10);cout << fixed;
#define dbset(x) for(int i=0 ; i<x.size(); i++) cerr << x[i] << " "; cerr << endl;
#define inf 1000000007
#define INF 1000000000000000000LL
#define PI 3.14159265358979323846
#define mod 1000000007
#define mod1 1000696969
#define flusz fflush(stdout);
#define VI vector<int>
#define VPI vector < pair<int,int> >
#define PII pair<int, int>
#define BIT bitset<N>
#define st first
#define nd second
#define pb push_back
#define mp make_pair
#define eb emplace_back
#define endl '\n'
#define REP(x, y) for(int x = 0; x < (y); ++x)
#define FOR(x, y, z) for(int x = y; x <= (z); ++x)
#define FORR(x, y, z) for(int x = y; x >= (z); --x)
using namespace std;

template<class TH> void _dbg(const char *sdbg, TH h){cerr<<sdbg<<"="<<h<<"\n";}
template<class TH, class... TA> void _dbg(const char *sdbg, TH h, TA... a) {
  while(*sdbg!=',')cerr<<*sdbg++;cerr<<"="<<h<<","; _dbg(sdbg+1, a...);
}
#define debug(...) _dbg(#__VA_ARGS__, __VA_ARGS__)

const int N = 4000 + 7;

int test;

int n,k;

int res;

int t[N][N][2];

int get(int x,int y,int l){
    if (x >= 0 && y >= 0)
        return t[x][y][l];
    return 0;
}

int sum(int x,int y,int l){
    return get(x+k-1,y+k-1,l) + get(x-1,y-1,l) - get(x+k-1,y-1,l) - get(x-1,y+k-1,l);  
}

void solve()
{
    cin >> n >> k;

    FOR(i,1,n){
        int x,y;
        char c;

        cin >> x >> y >> c;

        t[x%(2*k)][y%(2*k)][(c=='W' ? 0 : 1)]++;

        t[2*k+x%(2*k)][2*k+y%(2*k)][(c=='W' ? 0 : 1)]++;
        
        t[2*k+x%(2*k)][y%(2*k)][(c=='W' ? 0 : 1)]++;
        
        t[x%(2*k)][2*k+y%(2*k)][(c=='W' ? 0 : 1)]++;
    }

    REP(i,4*k){
        REP(j,4*k){
            REP(l,2){
                t[i][j][l] = (i ? t[i-1][j][l] : 0) + (j ? t[i][j-1][l] : 0) - ((i && j) ? t[i-1][j-1][l] : 0) + t[i][j][l];
            }
        }
    }


    REP(i,2*k){
        REP(j,2*k){
            REP(l,2){
                res = max(res, sum(i,j,l) + sum(i+k,j+k,l) + sum(i+k,j,l^1) + sum(i,j+k,l^1) );
            }
        }
    }

    cout << res;

    return;
}

int32_t main()
{
    boost

    test=1;

    while(test--)
    {
        solve();
    }

  return 0;
}


Measured memory_bytes: 125440
//written by NewbieChd
#include <cstdio>
#include <cctype>
using namespace std;

const int BUF = 1000000;
char buf[BUF], *p1, *p2;
inline char getChar() { return p1 == p2 && (p2 = (p1 = buf) + fread(buf, 1, BUF, stdin), p1 == p2) ? EOF : *p1++; }
inline int read() {
    register int f = 0;
    char c;
    while (!isdigit(c = getChar())) {}
    do
        f = f * 10 + (c ^ 48);
    while (isdigit(c = getChar()));
    return f;
}

const int maxN = 100003;

int main() {
    int a = read(), b = read();
    if (a <= 5)
        printf("0\n");
    else {
        if (a < 13)
            b >>= 1;
        printf("%d\n", b);
    }
    return 0;
}


Measured memory_bytes: 128
h,w = map(int,input().split())
mx = []
for i in range(h):
    mx.append(list(map(str, input().split())))
for i in range(h-1,-1,-1):
    if not '#' in mx[i][0]:
        del mx[i]
l = []
for i in range(w):
    for j in range(len(mx)):
        if mx[j][0][i]=='#':
            break
        if j==len(mx)-1:
            l.append(i)
if l:
    for i in range(1,len(l)+1):
        for j in range(len(mx)):
            if l[-i]==len(mx[j][0])-1:
                mx[j][0]=mx[j][0][:l[-i]]
            else:
                mx[j][0]=mx[j][0][:l[-i]]+mx[j][0][l[-i]+1:]
for m in mx:
    print(m[0])

Measured memory_bytes: 3064
#include<bits/stdc++.h>
typedef long long ll;
using namespace std;
const int mod=1e9+7;
bool cmp(int a,int b)
{
	return a>b;
}
int boom[100005];
int main()
{
	int n;cin>>n;
	for (int i = 1; i <=100; i++)
	{
		for (int j = 1; j <= 100; j++)
		{
			for (int k = 1; k <= 100; k++)
			{
				boom[i*i+j*j+k*k+i*j+i*k+j*k]++;
			}
		}
	}
	for (int i = 1; i <= n; i++)
	{
		cout<<boom[i]<<endl;
	}
}

Measured memory_bytes: 3860
using System;
using static System.Console;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Threading;

namespace Atcoder_Answer
{
    class Program
    {
        const Int32 mod = 1000000007;

        static void Main(string[] args)
        {
            int R = int.Parse(ReadLine());
            Console.WriteLine(R * 2 * Math.PI);
        }
    }

    public static class Extension
    {
        #region 拡張:bool
        #region キャスト関連
        public static int ToInt(this bool Bool)
        {
            if (Bool) return 1;
            else return 0;
        }

        public static string ToString(this bool Bool, string TrueStr, string FalseStr)
        {
            if (Bool) return TrueStr;
            else return FalseStr;
        }
        #endregion
        #endregion

        #region 拡張:int
        #region キャスト関連
        public static char ToAlphaBets(this int Base) => (char)Base;
        #endregion
        #endregion

        #region 拡張:char
        #region 変換関連
        public static char NextAlpha(this char Char) => (char)((Char) + 1); //次の文字を取得
        #endregion
        #endregion

        #region 拡張:int[]
        public static long Sum(this int[] Array)
        {
            int Ret = 0;
            for (int loop = 0; loop < Array.Length; loop++) Ret += Array[loop];
            return Ret;
        }
        #endregion

        #region 拡張: string
        public static string Multi(this string THIS, int Value) 
        {
            string RetValue = "";

            for (int loop = 0; loop < Value; loop++) RetValue += THIS;

            return RetValue;
        }
        #endregion

        #region 拡張: List<string>
        public static string Sum(this List<string> THIS, string Split) 
        {
            string RetValue = "";

            for (int loop = 0; loop < THIS.Count; loop++) 
            {
                RetValue += THIS[loop];
            }

            return RetValue;
        }
        #endregion
    }
}


Measured memory_bytes: 27608
#include<iostream>
#include<algorithm>
#include<functional>
#include<cmath>
#include<string>
#include<vector>
#include<stack>
#include<queue>
#include<map>
#include<set>
#include<deque>
using namespace std;
#define ll long long
const int mod = 1000000007;
const ll INF = 1000000000000000000;

ll X[100010];
int main()
{
	ll N, A, B;
	cin >> N >> A >> B;
	for (int i = 0; i < N; i++) cin >> X[i];
	ll ans = 0;
	for (int i = 0; i < N - 1; i++) {
		ans += min((X[i + 1] - X[i]) * A, B);
	}
	cout << ans << endl;
}


Measured memory_bytes: 1024
#include<bits/stdc++.h>
#define rep(i,a,b) for(int i=(a);i<=(b);i++)
#define per(i,a,b) for(int i=(a);i>=(b);i--)
#define REP(i,n) for(int i=(0);i<(n);i++)
#define fi first
#define se second
#define pb push_back
#define mp make_pair
using namespace std;
typedef pair<int,int> pii;
typedef vector<int> vi;
typedef long long ll;

template<class T> inline void read(T &x){
	int f=0;x=0;char ch=getchar();
	for(;!isdigit(ch);ch=getchar())f|=(ch=='-');
	for(;isdigit(ch);ch=getchar())x=x*10+ch-'0';
	if(f)x=-x;
}

int n,a,b,mn,mx;

void GG(){
	puts("No"),exit(0);
}
void owo(){
	puts("Yes"),exit(0);
}

int main(){
	read(n);
	mn=n,mx=0;
	rep(i,1,n){
		int x; read(x);
		if(x<mn) mn=x,a=0;
		if(x>mx) mx=x,b=0;
		a+=(mn==x);
		b+=(mx==x);
	}
	if(mx-mn>=2) GG();
	if(mn==mx){
		if(mn==n-1) owo();
		if(mx*2>n) GG();
		owo();
	}
	if(mn<a) GG();
	if(b<(mx-a)*2) GG();
	owo();
	return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<algorithm>
#include<stack>
#include<math.h>
#include<map>
#include <unordered_map> 
#include<vector>
#include<queue>
#include <bits/stdc++.h> 
#include<string>
#define ll long long int
#define N 3007
#define MOD 1e9+7
using namespace std;
string s1,s2;
template <typename T> void max_self(T &a, T b){
	if(b>=a){
		a = b;
	}
}
ll dp[N][N];
int vis[N][N];
ll a[N];
//itn dp[N];

int main(){
	int n;
	cin>>n;
	ll sum = 0;
	for(int i=0;i<n;i++){
		cin>>a[i];
		sum+=a[i];
	}
	//ll x = solve(1,n);
	for(int gap =0;gap<n;gap++){
		for(int i=0;i<n;i++){
		    int j = i+gap;
			if(j >= n)
				continue;
			if(gap==0){
				dp[i][j] = a[i];
			}
			else{
				dp[i][j] = max(a[i]+min(dp[i+2][j],dp[i+1][j-1]),a[j]+min(dp[i][j-2],dp[i+1][j-1]));
			}
		}
	}
	ll x = dp[0][n-1];
	/*
	for(int i=0;i<n;i++){
	    for(int j=0;j<n;j++){
	        cout<<dp[i][j]<<" ";
	    }
	    cout<<endl;
	}*/
	cout<<2*x-sum;
	
}


Measured memory_bytes: 70144
let s = Int(readLine()!)!
let s1 = s / 100
let s2 = s % 100
var c = 0
let l = ["NA","YYMM","MMYY","AMBIGUOUS"]
if 1<=s2 && s2<=12 {c += 1}
if 1<=s1 && s1<=12 {c += 2}
print(l[c])

Measured memory_bytes: 7604
X,Y=map(int,input().split())
def pr(n,prize):
    c=0
    if n==1:
        c=c+300000
    elif n==2:
        c=c+200000
    elif n==3:
        c=c+100000
    return prize+c
prize=0
prize=pr(X,prize)
prize=pr(Y,prize)
if (X==1)and(Y==1):
    prize=prize+400000
print(prize)

Measured memory_bytes: 39700
import java.util.HashSet;
import java.util.Scanner;
import java.util.Set;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		final int N = sc.nextInt();
		String[] w = new String[N];
		Set<String> ws = new HashSet<>();
		for (int i = 0; i < N; i++) {
			w[i] = sc.next();
			ws.add(w[i]);
		}
		if (ws.size() != N) {
			System.out.println("No");
			return;
		}
		for (int i = 0; i < w.length - 1 ; i++) {
			if (w[i+1].charAt(0) != w[i].charAt(w[i].length() -1)) {
				System.out.println("No");
				return;
			}
		}
		System.out.println("Yes");
	}
}

Measured memory_bytes: 23124
import std.stdio, std.string, std.conv, std.algorithm, std.numeric;
import std.range, std.array, std.math, std.typecons, std.container, core.bitop;


void main() {
    string s;
    scan(s);

    auto cnt = new int[](3);

    foreach (ch ; s) {
        cnt[ch - 'a']++;
    }

    cnt.sort();

    int k = cnt[0];

    bool ok = (cnt == [k, k, k]) || (cnt == [k, k, k + 1]) || (cnt == [k, k + 1, k + 1]);

    writeln(ok ? "YES" : "NO");
}



struct UnionFind {
    private {
        int N;
        int[] p;
        int[] rank;
    }

    this (int n) {
        N = n;
        p = iota(N).array;
        rank = new int[](N);
    }

    int find_root(int x) {
        if (p[x] != x) {
            p[x] = find_root(p[x]);
        }

        return p[x];
    }

    bool same(int x, int y) {
        return find_root(x) == find_root(y);
    }

    void unite(int x, int y) {
        int u = find_root(x), v = find_root(y);

        if (u == v) return;

        if (rank[u] < rank[v]) {
            p[u] = v;
        }
        else {
            p[v] = u;

            if (rank[u] == rank[v]) {
                rank[u]++;
            }
        }
    }
}


void scan(T...)(ref T args) {
    string[] line = readln.split;
    foreach (ref arg; args) {
        arg = line.front.to!(typeof(arg));
        line.popFront();
    }
    assert(line.empty);
}


void fillAll(R, T)(ref R arr, T value) {
    static if (is(typeof(arr[] = value))) {
        arr[] = value;
    }
    else {
        foreach (ref e; arr) {
            fillAll(e, value);
        }
    }
}



struct Queue(T) {
    private {
        int N, head, tail;
        T[] data;
    }

    this(int n) {
        N = n + 1;
        data = new T[](N);
    }

    bool empty() {
        return head == tail;
    }

    bool full() {
        return (tail + 1) % N == head;
    }

    T front() {
        return data[head];
    }

    void push(T x) {
        assert(!full);
        data[tail++] = x;
        tail %= N;
    }

    void pop() {
        assert(!empty);
        head = (head + 1) % N;
    }

    void clear() {
        head = tail = 0;
    }
}

Measured memory_bytes: 508
////////////////////////////////////////////////////////////////////
// This source code is for Visual Studio
////////////////////////////////////////////////////////////////////
#include <iostream>
#include <string>
#include <vector>
#include <list>
#include <queue>
#include <map>
#include <set>
#include <algorithm>
#include <sstream>
#include <iterator>
#include <stack>
#include <functional>
#include <iomanip>
#include <string>
#include <cstring>
#include <deque>
#include <math.h>
#include <assert.h>

#define	numberof(a)	(sizeof(a) / sizeof(a[0]))
#define	INF32		INT32_MAX
#define	INF64		INT64_MAX
#define Rep(i,n) for(int i = 0; i < (n); ++i )

using namespace std;

typedef vector< vector<int> > MAT;
typedef pair<int, int> PINT;
typedef long long ll;
typedef uint32_t u32;
typedef uint64_t u64;
typedef int32_t s32;
typedef int64_t s64;

//constant
//--------------------------------------------
const double EPS = 1e-10;
const double PI  = acos(-1.0);

// main function
int main()
{
	ll N = 0;
	cin >> N;

	vector<ll> L(N, 0);
	ll sum = 0;
	Rep(i, N) {
		cin >> L[i];
		sum += L[i];
	}
	sort(L.begin(), L.end());
	if (L[N - 1] < sum - L[N - 1]) {
		cout << "Yes" << endl;
	}
	else {
		cout << "No" << endl;
	}

	return 0;
}

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

using namespace std;

//#define int long long
#define FOR(i, j, k) for(int i = j; i < k; ++i)
#define rep(i, j) FOR(i, 0, j)
#define INF 1e9
#define LINF 1e18

typedef unsigned long long ull;
typedef pair<int, int> P;
typedef pair<P, int> Pi;
typedef pair<P, P> PP;

const int MOD = 1e9 + 7;
const int dy[]={0, 0, 1, -1};
const int dx[]={1, -1, 0, 0};

template <class T> void chmin(T& a, const T& b) { a = min(a, b); }
template <class T> void chmax(T& a, const T& b) { a = max(a, b); }

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

    int n;
    int c[500], s[500], f[500];
    cin >> n;
    rep(i, n - 1) cin >> c[i] >> s[i] >> f[i];
    rep(i, n) {
        int res = 0;
        FOR(j, i, n - 1) {
            if(res < s[j]) res = s[j];
            else if(res % f[j]) res = res + f[j] - res % f[j];
            res += c[j];
        }
        cout << res << endl;
    } 
    return 0;
}

Measured memory_bytes: 256
import qualified Data.Text as T
import qualified Data.Text.IO as T
import qualified Data.Text.Read as T

main :: IO ()
main = do
  x <- unsafeTextToInt <$> T.getLine :: IO Int
  let
    fs = factors x :: [Int]
    as = takeWhile ((<= x) . (^ 4)) [0..] :: [Int]
    abs = g <$> as <*> fs :: [(Int, Int)]
      where
        g :: Int -> Int -> (Int, Int)
        g a f = (a, a - f)
    p :: (Int, Int) -> Bool
    p (a, b) = a ^ 5 - b ^ 5 == x
  ((>>) <$> putStr . show . fst <*> putStrLn . (' ' :) . show . snd) . head . filter p $ abs

factors :: Int -> [Int]
factors n = factors' [] 1
  where
    factors' :: [Int] -> Int -> [Int]
    factors' ts d | q < d     = ts
                  | r /= 0    = factors' ts (succ d)
                  | d < q     = d : factors' (q : ts) (succ d)
                  | otherwise = d : ts
      where
        (q, r) = n `divMod` d

unsafeTextToInt :: T.Text -> Int
unsafeTextToInt s = case T.signed T.decimal s of
  Right (n, _) -> n


Measured memory_bytes: 3732
#include <bits/stdc++.h>
using namespace std;
typedef long long  ll;
#define fo(i,n) for(ll i=0;i<n;i++)
#define fok(i,k,n) for(ll i=k;i<n;i++)
#define ci(x) cin>>x
#define ci2(x,y) cin>>x>>y
#define co(x) cout<<x<<"\n"
#define co2(x,y) cout<<x<<" "<<y<<"\n"
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define PI 3.1415926535897932384626
typedef pair<int, int>	pii;
typedef pair<ll, ll>	pll;
typedef vector<int>		vi;
typedef vector<ll>		vl;
typedef vector<pii>		vpii;
typedef vector<pll>		vpll;
typedef vector<vi>		vvi;
typedef vector<vl>		vvl;
const int mod = 1000000007;
const int INF =1e9;


int main(){
	int a,b;
	ci2(a,b);
	int m=max((a-b),(a+b));
	m=max(m,a*b);
	co(m);
}


Measured memory_bytes: 256
import java.util.*;
import java.io.*;
import java.lang.*;
import java.math.*;
public class Main {
    public static void main(String[] args) throws Exception {
        BufferedReader bf = new BufferedReader(new InputStreamReader(System.in));
        PrintWriter out = new PrintWriter(new OutputStreamWriter(System.out));
        int n = Integer.parseInt(bf.readLine());
        int count = 0;
        for(int i=1; i<=n; i++) {
          if((""+i).length() % 2 == 1) count++;

        }
        out.println(count);
        // StringTokenizer st = new StringTokenizer(bf.readLine());
        // int[] a = new int[n]; for(int i=0; i<n; i++) a[i] = Integer.parseInt(st.nextToken());
        // int n = Integer.parseInt(st.nextToken());

        out.close(); System.exit(0);
    }
}


Measured memory_bytes: 31956
#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 main() {
  int N, M, X;
  cin >> N >> M >> X;
  vector<int> C(N);
  vector<vector<int>> A(N, vector<int>(M, 0));
  
  int ans = 1200001;
  rep(i, N){
    cin >> C.at(i);
    rep(j, M) cin >> A.at(i).at(j);
  }
  
  
  for (int tmp = 0; tmp < (1 <<N); tmp++) {
    bitset<12> b(tmp);
    
    
    int sum = 0;
    bool flg = true;
    vector<int> s = vector<int>(M, 0);//skill
    
    rep(i, N){
      
      if(b.test(i)){
        sum += C.at(i);
        rep(j, M){
          
         s.at(j) += A.at(i).at(j); 
        }
      }
    }
    rep(i, M){
      if(s.at(i) < X){
      	flg = false;
        break;
      }
    }
    if(flg){
     ans = min(ans, sum);
    }
    
  }
  if(ans == 1200001) cout << -1 << endl;
  else cout << ans << endl;
 
  return 0;
}

Measured memory_bytes: 3640
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vs = vector<string>;
using msi = map<string, int>;
using mii = map<int, int>;
using psi = pair<string, int>;
using pii = pair<int, int>;
using vlai = valarray<int>;
#define rep(i,n) for(int i=0;i<n;i++)
#define range(i,s,n) for(int i=s;i<n;i++)
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define fs first
#define sc second
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define INF 1e9
#define EPS 1e-9
#define MOD (1e9+7)

ll ans = 0;
deque<int> marge(deque<int> l, deque<int> r) {
	deque<int> d;
	int siz = l.size() + r.size();
	rep(i, siz) {
		//ans++;
		if (r.empty() || (!l.empty() && l.front() < r.front())) {
			d.push_back(l.front());
			l.pop_front();
		}
		else {
			d.push_back(r.front());
			r.pop_front();
			ans+=l.size();
		}
	}
	return d;
}

deque<int> msort(deque<int> d) {
	if (d.size() == 1)return d;
	deque<int> l, r;
	int p = (d.size() + 1) / 2;
	rep(i, d.size()) {
		if (i < p)l.push_back(d[i]);
		else r.push_back(d[i]);
	}
	deque<int>ll = msort(l);
	deque<int>rr = msort(r);
	deque<int>dd = marge(ll, rr);
	return dd;
}


int main() {
	int n, in;
	cin >> n;
	deque<int> d, dans;
	rep(i, n) {
		cin >> in;
		d.push_back(in);
	}
	dans = msort(d);
	cout <<ans << endl;
}


Measured memory_bytes: 8048
str=gets.split(" ")
num=Array.new
W=str[0].to_i
H=str[1].to_i
x=str[2].to_i
y=str[3].to_i
r=str[4].to_i
if x>=r && y>=r && x+r<=W && y+r<=H then
    print("Yes\n")
else
    print("No\n")
end

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

int main(void){
 string S;
  cin >> S;
  int flag = 0, cz = 0, co = 0, count = 0;
  for(int i = 0; i < S.length(); i++){
    if(S[i] == '0'){
      flag = 1;
      cz++;
      //cout << S[i] << cz << endl;
    }
    else if(S[i] == '1'){
      flag = 1;
      co++;
      //cout << S[i] << cz << " " << co << endl;
    }
    
  }
  //cout << cz << " " << co << endl;
  if(co > 0 && cz > 0){
    count +=  min(co, cz) * 2;
  }
  cout << count;
  return 0;
}

Measured memory_bytes: 512
#include <bits/stdc++.h>
using namespace std;
#define endl "\n";
typedef  long long int lli;
#define boost ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define inf (1000*1000*1000+5)
const int NODE =1e4+9;

const int mod=1e9+7;
const lli num=2000000;

vector<lli>a(num);
vector<lli>g(num);
void init(){
   g[1]=1;
   for(lli i=2;i<num;i++)g[i]=1+g[i+1-g[g[i-1]]];
   for(lli i=2;i<num;i++)g[i]=(g[i]%mod*g[i]%mod)%mod;
   for(int i=2;i<num;i++)g[i]=(g[i]%mod+g[i-1]%mod)%mod;
}

bool ch(double x){
   if((int)x==x)return true;
   return false;
}


int main()
{
   boost;
   int t=1;
   //cin>>t;
   init();
   while(t--){
      int n;
      cin>>n;
      lli a[n];
      for(int i=0;i<n;i++)cin>>a[i];
      int dp[n];
      if(n<1){
         cout<<a[0]<<endl;
         continue;
      }
      dp[1]=abs(a[1]-a[0]);
      dp[0]=a[0];
      dp[2]=min(abs(a[2]-a[1])+dp[1],abs(a[2]-a[0]));
      for(int i=3;i<n;i++){
         dp[i]=min(abs(a[i]-a[i-1])+dp[i-1],abs(a[i]-a[i-2])+dp[i-2]);
      }
      cout<<dp[n-1]<<endl;
   }
   return 0;
}


Measured memory_bytes: 35604
#pragma GCC optimize("O3")
#include <bits/stdc++.h>
#define FAST ios_base::sync_with_stdio(false);
#define FO cout.tie(NULL);
#define FI cin.tie(NULL);
#define IN cin>>
#define OUT cout<<
#define loop(i,a,n) for(int i=a; i<n; i++)
#define rloop(i,a,n) for(int i=a; i>=n; i--)
#define endl "\n";
#define pb push_back
#define mp make_pair
#define set_bits(a) __builtin_popcount(a)
#define ll long long int
#define ld long double
#define vll vector<long long int>
#define pll pair<long long int, long long int>
#define mod 1000000007
#define M 998244353
ll gcd(ll a, ll b)
{
    return (b?gcd(b,a%b):a);
}
ll P(ll B, ll power, ll modulo)
{
    ll ans=1LL;
    while(power>0LL)
    {
        if(power%2LL==1LL)
        {
            ans=(ans*B)%modulo;
        }
        B=(B*B)%modulo;
        power/=2LL;
    }
    return ans;
}
bool isPrime(ll n)
{
    if(n<=1LL)
    {
        return false;
    }
    if(n<=3LL)
    {
        return true;
    }
    if(n%2==0LL || n%3==0LL)
    {
        return false;
    }
    for(ll i=5LL; (i*i)<=n; i+=6LL)
    {
        if(n%i==0LL || n%(i+2LL)==0LL)
        {
            return false;
        }
    }
    return true;
}
using namespace std;
bool sortbysec(const pair<int,int> &a, const pair<int,int> &b)
{
    return (a.second<b.second);
}
bool sortbysecll(const pll &a, const pll &b)
{
    return (a.second<b.second);
}
ll modinv(ll x, ll y, ll modulo)
{
    return ((x%modulo)*(P(y,modulo-2LL,modulo)%modulo))%modulo;
}
int main()
{
    FAST
    FO
    FI
    ll n,x,y;
    IN n>>x>>y;
    ll dist[n+1][n+1];
    loop(i,1,n+1)
    {
        loop(j,1,n+1)
        {
            dist[i][j]=abs(i-j);
        }
    }
    loop(i,1,n+1)
    {
        loop(j,1,n+1)
        {
            dist[i][j]=min(dist[i][j], dist[i][x]+1+dist[y][j]);
            dist[i][j]=min(dist[i][j], dist[i][y]+1+dist[x][j]);
        }
    }
    ll ans[n+1];
    memset(ans, 0, sizeof(ans));
    loop(i,0,n+1)
    {
        loop(j,1,i)
        {
            ans[dist[i][j]]++;
        }
    }
    loop(i,1,n)
    {
        OUT ans[i]<<endl
    }
    return 0;
}


Measured memory_bytes: 31616
#include <bits/stdc++.h>
#define IO_OP std::ios::sync_with_stdio(0); std::cin.tie(0);
#define F first
#define S second
#define PB push_back
#define MP make_pair
#define EB emplace_back

using namespace std;

typedef long long ll;
typedef pair<int, int> pi;
typedef vector<int> vi;

const int INF = 1e9 + 7;

int main()
{
	IO_OP;
	
	int n;
	cin >> n;
	cout << 3 * n * n << endl;
	
}



Measured memory_bytes: 892
def getN():
    return int(input())
def getNM():
    return map(int, input().split())
def getList():
    return list(map(int, input().split()))

from collections import defaultdict, deque
from sys import exit
import math
import copy
from bisect import bisect_left

import sys
# sys.setrecursionlimit(1000000)
INF = 10 ** 17

def check(books, x, i, m, n):
    ab = [0 for i in range(m)]
    ret = 0
    for k in range(n):
        if i % 2 == 1:
            book = books[k]
            for tab, b in enumerate(book[1:]):
                ab[tab] += b
            ret += book[0]
        i //= 2
    # print(bin(i), ab)
    for cab in ab:
        if cab < x:
            return INF

    return ret

def main():
    a,b,c,k  = getList()
    if k <= a:
        print(k)
        return

    elif k <= a + b:
        print(a)
        return

    else:
        print(a - (k - a - b))
        return
if __name__ == "__main__":
    main()



Measured memory_bytes: 68976
#include<bits/stdc++.h>
#define f i].first
#define s i].second
using namespace std;pair<long,long>p[1<<18];long I,A,n,r,b,d,t,i;main(){I=b=1e9;for(cin>>n;i<n;i++){cin>>p[f>>p[s;if(p[f>p[s)swap(p[f,p[s);I=min(I,p[f),A=max(A,p[s),r=max(r,p[f),b=min(b,p[s);}i=~0;sort(p,p+n);t=(r-I)*(A-b);b=p[1+f,r=p[n+f;t=min(t,(A-I)*(r-b));for(d=A;++i<n;t=min(t,(A-I)*(r-b)))b=min(min(p[s,i-n+1?p[1+f:A),d),d=min(d,p[s),r=max(r,p[s);cout<<t;}

Measured memory_bytes: 4352
#include <iostream>
#include <cmath>
#include <algorithm>
#include <climits>
#include <vector>
#include <string>
#include <set>
#include <iomanip>
#include <map>
#include <stdio.h>
#include <queue>
#define rep(i,n) for (int i=0;i<(n);++i)
#define REP(i,n) for (int i=0;i<=(n);++i)
#define all(x) (x).begin(), (x).end()

using namespace std;
typedef long long ll;
const int INF = 10000000;
const double PI = 3.14159265358979323;

int main(){
    double a, b, h, m;
    cin >> a >> b >> h >> m;
     
    double hh = h / 12 + (m / 60) / 12;
    double mm = m / 60.0;

    double ans = (a * a + b * b) - (2 * a * b * cos((hh - mm)*PI*2));
    cout << fixed << setprecision(20) << sqrt(ans) <<endl;
    return 0;
}

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

using std::cin;
using std::cout;
using std::endl;

int main(void) {
	int n;
	cin >> n;

	while (n != 0) {
		int count_step = 0;
		int mode = 0;
		for (int i = 0; i < n; i++) {
			char c;
			cin >> c;
			cin >> c;
			if (c == 'u') {
				if (mode != 1) {
					mode = 1;
				}else {
					count_step++;
				}
			}
			if (c == 'd') {
				if (mode != 2) {
					mode = 2;
				}else {
					count_step++;
				}
			}
		}
		cout << count_step << endl;
		cin >> n;
	}
	return 0;
}

Measured memory_bytes: 3064
#include<stdio.h>

int main()
{
    int P,Q,R,min[3],i;
    scanf("%d %d %d",&P,&Q,&R);
    if(P<Q)
    {
        if(P<R) 
        {
            min[0]=P;
            if(Q<R)
            {
                min[1]=Q; min[2]=R;
            }
            else
            {
                min[1]=R; min[2]=Q;
            }
        }
        else
        {
            min[0]=R; min[1]=P; min[2]=Q;
        }
    }
    else
    {
        if(P<R)
        {
            min[0]=Q; min[1]=P; min[2]=R;
        }
        else
        {
            min[2]=P;
            if(Q<R)
            {
                min[0]=Q; min[1]=R;
            }
            else
            {
                min[0]=R; min[1]=Q;
            } 
        }   
    }
    
    //printf("%d %d %d",min[0],min[1],min[2]);

    printf("%d",min[0]+min[1]);

    return 0;
}

Measured memory_bytes: 128
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <map>
#include <set>
#include <vector>
#include <algorithm>
using namespace std;
typedef long long LL;

const int MaxN = 2e5;
int n, a[MaxN + 5];
LL pred[MaxN + 5], succ[MaxN + 5];

int main()
{
	while (~scanf("%d", &n)) {
		for (int i = 1; i <= n; i++) scanf("%d", &a[i]);
		pred[0] = 0;
		for (int i = 1; i <= n; i++) pred[i] = pred[i - 1] + a[i];
		succ[n + 1] = 0;
		for (int i = n; i >= 1; i--) succ[i] = succ[i + 1] + a[i];
		LL ans = 1LL << 60;
		for (int i = 1; i <= n - 1; i++) ans = min(ans, abs(pred[i] - succ[i + 1]));
		printf("%lld\n", ans);
	}
	return 0;
}

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

int main() {
  int n;
  cin >> n;
  vector<int> vec(n);
  for(int i=0;i<n;i++)
    cin >> vec.at(i);
  sort(vec.begin(),vec.end());
  int a = n/2;
  int big = vec.at(a);
  int small = vec.at(a-1);
  if(big == small)
    cout << 0;
  else
    cout << big-small;
}

Measured memory_bytes: 3776
//#define _GLIBCXX_DEBUG
    #include <bits/stdc++.h>
    using namespace std;
    typedef long long ll;
    typedef pair<int, int> pii;
    typedef map<int, int> mii;
    typedef map<char,int> mci;
    typedef vector<int> vi;
    typedef vector<vi> vvi;
    typedef vector<ll> vll;
    typedef vector<pair<int,int>> vii;
    typedef vector<char> vc;
    typedef vector<vc> vcc;
    #define all(x) (x).begin(), (x).end()
    #define rall(x) (x).rbegin(), (x).rend()
    #define pb push_back
    #define mp make_pair
    #define F first
    #define S second
    #define in insert
    #define sz(v) v.size()
    #define mina(a,b) (a)=min((a),(b));
    #define maxa(a,b) (a)=max((a),(b));
    const int INF = 1e9 + 5;
    
    void solve(){
        double n,k; cin>>n>>k;
        double ans=0;
        vector<double> v(n+1);
        for(int i = 1; i <= n; i++){
            int cur=0;
            int t=i;
            while(t<k){
                t*=2;
                cur++;
            }
            v[i]=(double)cur;
        }
        double ha=0.5,f=1/n;
        for(int i = 1; i<= n; i++){
            //cout<<f*pow(ha,v[i])<<" ";
            ans+=f*pow(ha,v[i]);
        }
        //cout<<ans;
        cout<<fixed<<setprecision(12)<<ans;
    }
    int main(){
        int T=1;
        //cin>>T;
        for(int i = 0; i < T; i++) solve(); 
    }

Measured memory_bytes: 1024
#include<stdio.h>
#include<stdlib.h>
#define NIL NULL
typedef struct node{
 struct node *right;
 struct node *left;
  struct node *parent;
  int key;
}*Node;

Node root;
void insert(int);
void inorder(Node);
void preorder(Node);
int main(){
  int n, i, x;
  char S[20];
  scanf("%d", &n);
   
  for ( i = 0; i < n; i++ ){
    scanf("%s", S);
   
      if ( S[0] == 'i' ){
      scanf("%d", &x);
      insert(x);
    } else if ( S[0] == 'p' ){
      inorder(root);
      printf("\n");
      preorder(root);
      printf("\n");
    }
  }
   
  return 0;
}



void insert(int k){
  Node y = NIL;
  Node x = root;
  Node z;
  z = malloc(sizeof(struct node));
  z->key = k;
  z->left = NIL;
  z->right = NIL;
  while(x!=NIL){
    y = x;
    if(z->key < x->key){
      x = x->left;
    }
    else{
      x = x->right;
    }
  }
  z->parent= y;
  if(y==NIL){
    root = z;
  }
  else if(z->key<y->key){
    y->left =z;
  }
  else{
    y->right =z;
  }
   
   
   
   
   
}
 
void inorder(Node A){
  if(A != NIL){
    inorder(A->left);
    printf(" %d",A->key);
    inorder(A->right);
  }
}
 
void preorder(Node A){
  if(A!=NIL){
    printf(" %d",A->key);
    preorder(A->left);
    preorder(A->right);
  }
}
 
 

Measured memory_bytes: 24040
#include<stdio.h>
int main()
{
    int m,f,r,sum=0,i;
    for(;scanf("%d%d%d",&m,&f,&r);)
 
    {
    if(m==-1 && f==-1 && r==-1)
    break;
    else if(m<=50 && f<=50 && r<=100)
       { sum=m+f;
        if(m==-1 || f==-1 || m+f<30)
            printf("F\n");
        else if(sum>=80)
            printf("A\n");
        else if(sum>=65 && sum<80)
            printf("B\n");
        else if(sum>=50 && sum<65)
            printf("C\n");
            else if(sum>=30 && sum<50 && r>=50)
            printf("C\n");
        else if(sum>=30 && sum<50)
            printf("D\n");
         }
    }
    return 0;
}


Measured memory_bytes: 2108
import itertools

def name_count(names):
    counter = [0,0,0,0,0]
    capitals = ["M", "A", "R", "C", "H"]
    for name in names:
        for i in range(5):
            if name[0] == capitals[i]:
                counter[i] += 1
    return counter
    
n = int(input())

names = [""  for i in range(n)]
for i in range(n):
    names[i] = input()

name_counter = name_count(names)

cnt = 0
for comb in itertools.combinations(range(5), 3):
    temp = 1
    for i in comb:
        temp *= name_counter[i]
    cnt += temp

print(cnt)




Measured memory_bytes: 9776
s = input()
check = "R"
ans = [0 for i in range(len(s))]
kisu = 0
gusu = 0
num = 0
for i in range(len(s)):
    if check == "R" and s[i] == "L":
        num = i
        ans[i] += 1
        check = "L"
    elif check == "L" and s[i] == "L":
        if (i - num) % 2 == 0:
            ans[num] += 1
        else:
            ans[num-1] += 1
    if s[i] == "R":
        check = "R"
check = "L"
for i in range(len(s)-1,-1,-1):
    if check == "L" and s[i] == "R":
        check = "R"
        ans[i] += 1
        num = i
    elif check == "R" and s[i] == "R":
        if (num - i) % 2 == 0:
            ans[num] += 1
        else:
            ans[num+1] += 1
    if s[i] == "L":
        check = "L"

for i in range(len(ans)):
    print(ans[i],end = ' ')
print()

Measured memory_bytes: 52640
N = int(input())
ans = 0
n3 = int(N/3)
n5 = int(N/5)
n15= int(N/15)
sn = int((N)*(N+1)/2)
s3 = 3 * int(((n3)*(n3+1)/2))
s5 = 5 * int(((n5)*(n5+1)/2))
s15= 15* int(((n15)*(n15+1)/2))

ans = sn-s3-s5+s15
print(ans)

Measured memory_bytes: 9200
#include <bits/stdc++.h>
using namespace std;
int main()
{
  long long n, i;
  cin>>n;
 // long long dp[100001]={0};
  long long val=0;
  long long arr[100001];
  for(i=0;i<n;i++)
    cin>>arr[i];
  /*dp[0]=0;
  dp[1]=abs(arr[1]-arr[0]);*/
  int temp1=0;
  int temp2=abs(arr[1]-arr[0]);
  val=temp2;
  for(i=2;i<n;i++)
  {
    val=min(abs(arr[i]-arr[i-1])+temp2, abs(arr[i]-arr[i-2])+temp1);
    temp1=temp2;
    temp2=val;
  }
  cout<<val<<" ";
  return 0;
}

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

using namespace std;

#define FOR(i,n) for(int i=0; i<n; ++i)
#define FORR(i,a,n) for(int i=a; i<n; ++i)
#define ALL(c) (c).begin(), (c).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define UNIQ(c) (c).erase(unique(ALL((c))), end((c)))

const int INF = 0x3f3f3f3f;

typedef long long ll;
typedef vector<int> VI;
typedef vector<ll> VL;
typedef vector<VI> VVI;
typedef vector<VL> VVL;
typedef vector<string> VS;
typedef pair<int,int> P;
typedef pair<ll,ll> PL;
 
//int in() { int x; scanf("%d", &x); return x; }
//ll lin() { ll x; scanf("%lld", &x); return x; }
void printfv(VI a){ int n = a.size(); FOR(i, n) cout << a[i] << " "; }

int main(void){


	ll a,b;
	cin >> a >> b;

	if(abs(b-a)%2 == 0){
		cout << (b+a)/2;
	} else {
		cout << "IMPOSSIBLE";
	}

    return 0;
}


Measured memory_bytes: 256
import core.bitop;
import std.algorithm;
import std.ascii;
import std.bigint;
import std.conv;
import std.functional;
import std.math;
import std.numeric;
import std.range;
import std.stdio;
import std.string;
import std.random;
import std.typecons;
import std.container;

alias sread = () => readln.chomp();
alias Point2 = Tuple!(long, "y", long, "x");

T lread(T = long)()
{
    return readln.chomp.to!T();
}

T[] aryread(T = long)()
{
    return readln.split.to!(T[])();
}

void scan(TList...)(ref TList Args)
{
    auto line = readln.split();
    foreach (i, T; TList)
    {
        T val = line[i].to!(T);
        Args[i] = val;
    }
}

void main()
{
    long n = lread();
    string s = sread();
    long max_same = 0;
    foreach (i, e; s)
    {
        long[] lhs_alf = new long[26];
        long[] rhs_alf = new long[26];
        string lhs_str = s[0 .. i];
        string rhs_str = s[i .. $];
        input_to_array(lhs_str, lhs_alf);
        input_to_array(rhs_str, rhs_alf);
        long same = count_same(lhs_alf, rhs_alf);
        max_same = max(same, max_same);
    }
    writeln(max_same);

}

void input_to_array(string s, long[] a)
{
    long key;
    foreach (i, e; s)
    {
        key = e - 'a';
        a[key] = 1;
    }
}

long count_same(long[] a, long[] b)
{
    long count;
    foreach (e; 0 .. a.length)
    {
        if(a[e] && b[e])
        {
            count++;
        }
    }
    return count;
}

Measured memory_bytes: 320
#include<bits/stdc++.h> 
using namespace std;
struct P{int a,b;}q[200005];
int k,l=100000,r=100000;
bool book[100005];
int main(){
    scanf("%d", &k);
    q[l]={1,1};
    while(l<=r){
    	P x=q[l++];
        if(book[x.a]) continue; book[x.a]=1;
        if(x.a==0){printf("%d\n",x.b);break;}
        q[--l]={x.a*10%k,x.b};
        q[++r]={(x.a+1)%k,x.b+1};
    }
}

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

typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
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; }
const int INF = (1<<30) - 1;
const ll LINF = (1LL<<60) - 1;

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

    int res = 0;
    for (int i = 0; i < n-2; ++i) {
        if (s[i] == 'A' && s[i+1] == 'B' && s[i+2] == 'C') res++;
    }
    cout << res << endl;
}

Measured memory_bytes: 3564
"use strict"

function Main(input) {
  input = input.trim().split('\n');
  const N = Number(input[0].trim());
  const B = input[1].trim().split(' ').map(Number);

  let cnt = N-2;
  let ret = B[0] + B[cnt];
  for(let i=0; i<cnt; i++){
    ret += Math.min(B[i], B[i+1])
  }
  console.log(ret);
}
Main(require("fs").readFileSync("/dev/stdin", "utf8"));

Measured memory_bytes: 7372
import java.util.*;

class Main{
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        int[] A = new int[N];
        for (int i = 0; i < N; i++) {
            A[i] = sc.nextInt();
        }
        int start = 0;
        int ans = 0;
        while (start < N) {
            if (start == N - 1) {
                ans++;
                break;
            }
            int end = start + 1;
            while (end < N && A[end] == A[end - 1]) end++;
            if (end == N) {
                ans++;
                break;
            }
            if (A[end] > A[start]) {
                while (end < N && A[end] >= A[end - 1]) end++;
                ans++;
            } else {
                while (end < N && A[end] <= A[end - 1]) end++;
                ans++;
            }
            start = end;
        }
        System.out.println(ans);
    }
}


Measured memory_bytes: 49700
#include <bits/stdc++.h>
using namespace std;
using lint     = long long;
const lint inf = 1LL << 60;
const lint mod = 1000000007;

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

int main() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    lint n;
    cin >> n;
    vector<lint> p(n * n);
    for (int i = 0; i < n * n; ++i) {
        cin >> p[i];
        p[i]--;
    }
    vector<vector<lint>> dist(n, vector<lint>(n, inf));
    vector<vector<lint>> c(n, vector<lint>(n, 1));

    for (int i = 0; i < n; ++i) {
        for (int j = 0; j < n; ++j) {
            chmin(dist[i][j], (lint)(1 + i));
            chmin(dist[i][j], (lint)(n - i));
            chmin(dist[i][j], (lint)(1 + j));
            chmin(dist[i][j], (lint)(n - j));
        }
    }
    const int dx[4] = {-1, 1, 0, 0};
    const int dy[4] = {0, 0, -1, 1};
    auto inside     = [&](int y, int x) { return 0 <= y && y < n && 0 <= x && x < n; };
    lint ret        = 0;
    for (int i = 0; i < n * n; ++i) {
        int h = p[i] / n;
        int w = p[i] % n;
        ret += dist[h][w] - 1;
        dist[h][w]--;
        c[h][w] = 0;
        queue<pair<int, int>> q;
        q.emplace(h, w);
        while (!q.empty()) {
            auto p = q.front();
            q.pop();
            int ch = p.first;
            int cw = p.second;
            for (int j = 0; j < 4; ++j) {
                int nh = ch + dy[j];
                int nw = cw + dx[j];
                if (inside(nh, nw) && dist[nh][nw] > dist[ch][cw] + c[nh][nw]) {
                    dist[nh][nw] = dist[ch][cw] + c[nh][nw];
                    q.emplace(nh, nw);
                }
            }
        }
    }
    cout << ret << "\n";
    return 0;
}

Measured memory_bytes: 8916
#![allow(non_snake_case)]
#![allow(unused_imports)]
#![allow(dead_code)]

use proconio::{input, fastout};
use proconio::marker::*;
use whiteread::parse_line;
use std::collections::*;
use num::*;
use num_traits::*;
use superslice::*;
use std::ops::*;

use itertools::Itertools;
use itertools_num::ItertoolsNum;


#[fastout]
fn solve() {
    const MOD: usize = 1_000_000_007;
    const INF: usize = std::usize::MAX;
    
    input!{
        s: Chars
    }

    let mut ans = String::new();

    for i in 0..s.len() {
        if i % 2 != 0 { continue; }
        ans.push(s[i]);
    }

    println!("{}", ans);
}

fn main() {
    solve()
}

#[cfg(test)]
mod test {
    use super::solve;
}


Measured memory_bytes: 2476
N = int(input())
S = input()
S1, S2 = S[: N], S[2*N-1: N-1: -1]
hash_S1, hash_S2 = {}, {}

for i in range(1<<N): # 赤に塗られた箇所が1
    red = []
    blue = []
    for j in range(N):
        if i >> j & 1:
            red.append(S1[j])
        else:
            blue.append(S1[j])
    
    key = ''.join(red) + '+' + ''.join(blue)
    if key in hash_S1:
        hash_S1[key] += 1
    else:
        hash_S1[key] = 1

ans = 0
for i in range(1<<N): # 赤に塗られた箇所が1
    red = []
    blue = []
    for j in range(N):
        if i >> j & 1:
            red.append(S2[j])
        else:
            blue.append(S2[j])
    
    key = ''.join(blue) + '+' + ''.join(red)
    if key in hash_S1:
        ans += hash_S1[key]

print(ans)

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

int main(){
    int n, k;
    cin >> n >> k;
    int i;
    vector<int> data(n);
    for(i = 0; i < n; i++){
        cin >> data.at(i);
    }
    sort(data.begin(), data.end());
    reverse(data.begin(), data.end());
    for(i = 0; i < k; i++){
        data.at(i) = 0;
        if(i == n-1){
            break;
        }
    }
    int64_t sum = 0;
    for(int x : data){
        sum += x;
    }
    cout << sum << endl;
    return 0;
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
 
using namespace std;
using ll = long long;
using P = pair<int, int>;
 
int main() {
  int x1,y1,x2,y2;
  cin >> x1 >> y1 >> x2 >> y2;
  int x = x2;
  int y = y2;
  int dx = x2 - x1;
  int dy = y2 - y1;
  for(int i = 0; i < 2;i++){
    swap(dx,dy);
    dx = -dx;
    x += dx;
    y += dy;
    cout << x << " " << y << endl;
  }
}

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

const int MAX_N = 1112, MOD = 1e9+7;
int H, W;
string a[MAX_N];
ll dp[MAX_N][MAX_N];

void solve()
{
	dp[0][0]=1;
	for(int j=1;j<W && a[0][j]=='.';++j)dp[0][j]=1;
	for(int i=1;i<H && a[i][0]=='.';++i)dp[i][0]=1;
	for(int i=1;i<H;++i)for(int j=1;j<W;++j){
		if(a[i][j]=='#'){
			dp[i][j]=0;
			continue;
		}
		if(a[i-1][j]=='.') (dp[i][j]+=dp[i-1][j])%=MOD;
		if(a[i][j-1]=='.') (dp[i][j]+=dp[i][j-1])%=MOD;
	}
	cout << dp[H-1][W-1] << '\n';
}

int main()
{
	cin >> H >> W;
	for(int i=0;i<H;++i) cin >> a[i];
	solve();
	return 0;
}

Measured memory_bytes: 9984
#include<stdio.h>
#include<string.h>
#include<stdlib.h>

struct node{
  int key;
  struct node *p,*l,*r;
};
typedef struct node *Node;
Node root;

void insert(int);
void inorder(Node);
void preorder(Node);

int main(){
  int n,i,j;;
  char c[20];
  scanf("%d",&n);
  for(i=0;i<n;i++){
    scanf("%s",c);
    if(c[0]=='i'){
      scanf("%d",&j);
      insert(j);
    }
    else{
      inorder(root);
      printf("\n");
      preorder(root);
      printf("\n");
    }
  }
  return 0;
}

void insert(int k){
  Node y=NULL;
  Node x=root;
  Node z;
  z=malloc(sizeof(struct node));
  z->key=k;
  z->l=NULL;
  z->r=NULL;
  while(x!=NULL){
    y=x;
    if(z->key < x->key)x=x->l;
    else x=x->r;
  }
  z->p=y;
  if(y==NULL)root=z;
  else if(z->key<y->key)y->l=z;
  else y->r=z;
}

void inorder(Node u){
  if(u==NULL)return;
  inorder(u->l);
  printf(" %d",u->key);
  inorder(u->r);
}

void preorder(Node u){
  if(u==NULL)return;
  printf(" %d",u->key);
  preorder(u->l);
  preorder(u->r);
}


Measured memory_bytes: 25168
#include <iostream>
#include <string>
#include <vector>
#include <deque>
#include <list>
#include <set>
#include <unordered_set>
#include <map>
#include <unordered_map>
#include <algorithm>
#include <tuple>

struct SUSHI {
	int t;
	long d;
};

int main()
{
	int K, N;
	std::vector<SUSHI> td;
	std::unordered_map<int, long> dmaxpert; // t -> 最大のd
	std::vector<SUSHI> rests; // 最初に食わなかった寿司のうち、tごとに最大のdを持つ者について、dでソートしたもの
	std::unordered_map<int, int> eatencount; // t -> tの種類の寿司を食った数
	std::vector<SUSHI> eaten; // 食った寿司 // コンテナの真ん中にあるスシを食わないことにする処理があるが、コンテナから削除する必要は無いので list ではなく vector
	long max_manzoku; // 満足ポイント
	long basepoint;

	std::cin >> N >> K;
	td.reserve(N);
	for (int i = 0; i < N; ++i) {
		int tt;
		long dd;
		std::cin >> tt >> dd;
		td.push_back({tt, dd});
		auto it = dmaxpert.find(tt);
		if (it == dmaxpert.end())
			dmaxpert.insert({tt, dd});
		else
			it->second = std::max(it->second, dd);
	}

	std::sort(td.begin(), td.end(), [](auto& a, auto& b)->bool{return a.d > b.d;});

	basepoint = 0;
	for (int i = K-1; i >= 0; --i) {
		basepoint += td[i].d;
		++eatencount[td[i].t];
		dmaxpert.erase(td[i].t);
		eaten.push_back(td[i]);
	}
	for (auto s : dmaxpert) {
		rests.push_back({s.first, s.second});
	}
	std::sort(rests.begin(), rests.end(), [](auto&a,auto&b)->bool{return a.d > b.d;});
	long eatentypes = eatencount.size();

	max_manzoku = basepoint + eatentypes*eatentypes;

	auto next_noteaten = eaten.begin();
	auto next_newlyeaten = rests.begin();
	while (next_newlyeaten != rests.end()) {
		while (next_noteaten != eaten.end()) {
			if (eatencount[next_noteaten->t] > 1) {
				break;
			}
			++next_noteaten;
		}
		if (next_noteaten == eaten.end())
			break;

		basepoint -= next_noteaten->d;
		--eatencount[next_noteaten->t];
		basepoint += next_newlyeaten->d;
		++eatentypes;
		max_manzoku = std::max(max_manzoku, basepoint + eatentypes*eatentypes);
		++next_newlyeaten;
		++next_noteaten;
	}
loopend:
	std::cout << max_manzoku << "\n";
}


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

#define REP(i, x, n) for (int i = x; i < (int)(n); i++)
#define rep(i, n) REP(i, 0, n)
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define sz(x) (int)(x.size())
#define popcount(x) __builtin_popcount(x)
#define popcountll(x) __builtin_popcountll(x)
#define uniq(x) x.erase(unique(x.begin(), x.end()), x.end())
#define F first
#define S second
#define mp make_pair
#define eb emplace_back
#define pii pair<int, int>
#define pll pair<ll, ll>

using namespace std;

typedef long long ll;

/* --- INFの値が適切か確認する --- */
// const int INF = 1 << 30;
// const ll INF = 1LL << 60;
// const int MOD = 1000000007;

int main() {
  string s;
  cin >> s;
  sort(all(s));
  if (s[0] == s[1] && s[2] == s[3] && s[1] != s[2])
    cout << "Yes" << endl;
  else
    cout << "No" << endl;
}


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

int main()
{
  int S[13],H[13],C[13],D[13],n,num;
  char CC;
  cin>>n;
  for(int i=0;i<13;i++){
    S[i]=0;
    H[i]=0;
    C[i]=0;
    D[i]=0;
  }
  for(int i=0;i<n;i++){
    cin>>CC>>num;
    if(CC=='S')S[num-1]=1;
    if(CC=='H')H[num-1]=1;
    if(CC=='C')C[num-1]=1;
    if(CC=='D')D[num-1]=1;
  }
  for(int i=0;i<4;i++){
    for(int j=0;j<13;j++){
      if(i==0&&S[j]!=1)cout<<"S "<<j+1<<endl; 
      if(i==1&&H[j]!=1)cout<<"H "<<j+1<<endl;   
      if(i==2&&C[j]!=1)cout<<"C "<<j+1<<endl;  
      if(i==3&&D[j]!=1)cout<<"D "<<j+1<<endl;
    }
  }
  return 0;
}

Measured memory_bytes: 1160
#include <stdio.h>
#include <stdlib.h>
#include <ctype.h>
#include <string.h>
#include <limits.h>
#include <math.h>
#include <time.h>
#include <stdarg.h>
#include <algorithm>
#include <iostream>
#include <vector>
#include <queue>
#include <functional>
#include <map>
#include <iomanip>

#define ll long long

using namespace std;

void
solve() {
  ll n, k;
  cin>>n>>k;

  vector<ll> a(n, 0);
  for (ll i=0; i<n; i++)
    cin>>a[i];

  vector<bool> dp(k + 1, false);
  for (ll i=1; i<=k; i++) {
    for (auto p : a) {
      if (i - p < 0) break;
      if (dp[i-p] == 0) dp[i] = 1;
    }
  }

  if (dp[k])
    cout<<"First"<<endl;
  else
    cout<<"Second"<<endl;
}

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

  ll t = 1;
  //cin>>t;

  while (t > 0) {
    t--;
    solve();
  }

  return 0;
}



Measured memory_bytes: 3656