akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#define ALL(a)  (a).begin(),(a).end()
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
typedef pair<long long, long long> Pll;
typedef vector<int> vi;
typedef vector<vector<int>> vvi;
typedef vector<long long> vll;
typedef vector<vector<long long>> vvll;
template <typename T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template <typename T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
const long long INF = 1LL << 60;
const int INT_INF = 1 << 30;
#define MOD 1000000007LL

int main(){
  ll Q;
  cin >> Q;

  vll abox(0);
  priority_queue<Pll, vector<Pll>, greater<Pll>> ue;
  priority_queue<Pll> shita;
  ll uenum = 0, shitanum = 0;
  Pll mid = Pll(-1, -1);
  ll C = 0;
  ll sum = 0;
  vector<Pll> ans(0);
  for(int tmp = 0; tmp < Q; tmp++){
    int query;
    cin >> query;
  
    if(query == 1){
      ll a, b;
      cin >> a >> b;
      C += b;
      if(mid.first == -1){
        mid = Pll(a, 1);
      }
      else{
        if(a == mid.first) mid.second++;
        else if(a > mid.first){
          sum += a - mid.first;
          uenum++;
          ue.push(Pll(a, 1));
        }
        else{
          sum += mid.first - a;
          shitanum++;
          shita.push(Pll(a, 1));
        }
      }
      
      if(uenum > mid.second + shitanum){ //上が大きくなりすぎた
        ll newmid = ue.top().first;
        ll newmidnum = ue.top().second;
        ue.pop();
        while(!ue.empty() && ue.top().first == newmid){
          newmidnum += ue.top().second;
          ue.pop();
        }
        sum -= (newmid - mid.first) * uenum;
        sum += (newmid - mid.first) * (shitanum + mid.second);
        uenum -= newmidnum;
        shitanum += mid.second;
        shita.push(mid);
        mid = Pll(newmid, newmidnum);
      }
      else if(uenum + mid.second <= shitanum){
        ll newmid = shita.top().first;
        ll newmidnum = shita.top().second;
        shita.pop();
        while(!shita.empty() && shita.top().first == newmid){
          newmidnum += shita.top().second;
          shita.pop();
        }
        sum += (mid.first - newmid) * (uenum + mid.second);
        sum -= (mid.first - newmid) * shitanum;
        shitanum -= newmidnum;
        uenum += mid.second;
        ue.push(mid);
        mid = Pll(newmid, newmidnum);
      }
    }
    else{
      ans.push_back(Pll(mid.first, sum+C));
    }
  }
  for(int i = 0; i < ans.size(); i++){
    cout << ans.at(i).first << ' ' << ans.at(i).second << endl;
  }
}

Measured memory_bytes: 6308
#include <bits/stdc++.h>
using namespace std;
 
int main() {
    int N,K;
    cin >> N >> K;
    
    int ans = 1;
    for (int i=0 ; i<N ;i++) {
        if (ans < K) {
            ans *= 2;
        } else {
            ans += K;
        }
        //cout << ans << endl;
    }
    
    cout << ans << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <map>
#include <vector>
#include <algorithm>
#include <numeric>

using namespace std;

int main(void){
    long long a, b, c, d;
    cin >> a >> b >> c >> d;

    long long all;
    all = b - a + 1;
    long long cd;
    cd = __gcd(c, d);
    cd = c*d/cd;

    //cout << cd << endl;
    long long ans;
    ans =  all - (b/c-(a-1)/c + b/d-(a-1)/d - b/cd+(a-1)/cd);
    cout << ans << endl;

    return 0;
}

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

int main() {
    int n;
    string s;
    cin >> n >> s;
    
    set<int> r, g, b;
    for (int i = 0; i < n; i++) {
        if (s[i] == 'R') r.emplace(i);
        if (s[i] == 'G') g.emplace(i);
        if (s[i] == 'B') b.emplace(i);
    }
    
    long long ans = 0;
    for (const int &i : r) {
        for (const int &j : g) {
            const int d = abs(i - j);
            ans += (long long)b.size();
            if (b.count(max(i, j) + d)) ans--;
            if (b.count(min(i, j) - d)) ans--;
            if (d % 2 == 0) {
                if (b.count(min(i, j) + d / 2)) ans--;
            }
        }
    }
    
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 3796
#include <bits/stdc++.h>
#define REP(i, a, n) for (int i = (a); i < (int)(n); ++i)
#define REPC(i, a, n) for (int i = (a); i <= (int)(n); ++i)
#define ALL(t) t.begin(), t.end()
#define RALL(t) t.rbegin(), t.rend()
#define MATINIT(type, row, col, init)                                          \
  vector<vector<type>>(row, vector<type>(col, init));
#define Yes(cond) cout << (cond ? "Yes" : "No") << endl;
#define YES(cond) cout << (cond ? "YES" : "NO") << endl;
using namespace std;
using LL = long long;
using ULL = unsigned long long;
template <class T> using VEC = std::vector<T>;
template <class T> using MAT = std::vector<std::vector<T>>;
void DUMP() { cerr << endl; }
template <class Head, class... Tail> void DUMP(Head &&head, Tail &&... tail) {
  cerr << head << ", ";
  DUMP(std::move(tail)...);
}
template <typename T> ostream &operator<<(ostream &os, vector<T> &vec) {
  os << "{";
  for (auto v : vec)
    os << v << ",";
  os << "}";
  return os;
}
template <typename T1, typename T2>
ostream &operator<<(ostream &os, map<T1, T2> &m) {
  os << "{";
  for (auto p : m)
    os << p << ",";
  os << "}";
  return os;
}
template <typename T1, typename T2>
ostream &operator<<(ostream &os, pair<T1, T2> p) {
  os << "[" << p.first << " " << p.second << "]";
  return os;
}
bool isPrime(int n) {
  // returns whether n is prime number or not
  // n should be in range [0, lim].
  // to see detail, search "Sieve of Eratosthenes"
  static int lim = 1e5;
  static bool done = false;
  static vector<bool> isp(lim + 1, 1);
  if (!done) {
    isp[0] = isp[1] = false;
    for (int i = 2; i <= lim; i++) {
      if (isp[i]) {
        for (int j = i + i; j <= lim; j += i) {
          isp[j] = false;
        }
      }
    }
    done = true;
  }
  return isp[n];
}


int main() {
  int n;
  cin>>n;
  int cnt = 0;
  int i = 0;
  while(cnt<n){
    if(isPrime(i) && i%5==1){
      cout<<i<<" ";
      ++cnt;
    }
    ++i;
  }
  


  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <tr1/unordered_map>
#define ri register int
using namespace std;
typedef double db;
typedef long double ld;
typedef long long ll;
typedef vector <int> poly;
typedef pair <int, int> pii;
typedef pair <ll, int> pli;
typedef pair <int, ll> pil;
typedef pair <ll, ll> pll;
typedef unsigned long long ulll;
typedef unsigned int uii;
typedef string strr;
#define fi first
#define se second
#define pb push_back
#define ppp pop_back
#define rez resize
const ll Inf = 1e18;
const int rlen = 1 << 20, inf = 0x3f3f3f3f;
char buf[rlen], *ib = buf, *ob = buf;
#define gc() (((ib == ob) && (ob = (ib =  buf) + fread(buf, 1, rlen, stdin)), ib == ob) ? -1 : *ib++)
inline int read() {
  static int ans, f;
  static char ch;
  ans = 0, ch = gc(), f = 1;
  while (!isdigit(ch)) f ^= ch == '-', ch = gc();
  while (isdigit(ch)) ans = (ans << 3) + (ans << 1) + (ch ^ 48), ch = gc();
  return f ? ans: -ans;
}
inline ll readl() {
  static ll ans;
  static char ch;
  for (ans = 0, ch = gc(); !isdigit(ch); ch = gc());
  while (isdigit(ch)) ans = ((ans << 2) + ans << 1) + (ch ^ 48), ch = gc();
  return ans;
}
inline int Read(char *s) {
  static int top;
  static char ch;
  top = 0, ch = gc();
  while (!isalpha(ch) && !isdigit(ch)) ch = gc();
  while (isalpha(ch) || isdigit(ch)) s[++top] = ch, ch = gc();
  return top;
}
namespace modular {
  const int mod = 998244353;
  int ret;
  inline int add(int a, int b) { return a + b < mod ? a + b : a + b - mod; }
  inline int dec(int a, int b) { return a < b ? a - b + mod : a - b; }
  inline int mul(int a, int b) { return (ll) a * b % mod; }
  inline void Add(int &a, int b) { a = a + b < mod ? a + b : a + b - mod; }
  inline void Dec(int &a, int b) { a = a < b? a - b + mod : a - b; }
  inline void Mul(int &a, int b) { a = (ll) a * b % mod; }
  inline int ksm(int a, int p) {
    for (ret = 1; p; p >>= 1, Mul(a, a)) (p & 1) && (Mul(ret, a), 1);
    return ret;
  }
  inline int Inv(int a) { return ksm(a, mod - 2); }
  inline int sqr(int a) { return (ll) a * a % mod; }
  inline int cub(int a) { return (ll) a * a % mod * a % mod; }
} using namespace modular;
template <typename T> inline void ckmax(T &a, T b) { a < b ? a = b : 0; }
template <typename T> inline void ckmin(T &a, T b) { a > b ? a = b : 0; }
template <typename T> inline T Abs(T a) { return a < 0 ? -a : a; }
template <typename T> inline T gcd(T a, T b) {
  T t;
  while (b) t = a, a = b, b = t - t / a * a;
  return a;
}
const int N = 2e5 + 5;
int n, m, K, fac[1000005], ifac[1000005];
inline void init_fac() {
  int lm = n;
  fac[0] = fac[1] = ifac[0] = ifac[1] = 1;
  for (ri i = 2; i <= lm; ++i) fac[i] = mul(fac[i - 1], i);
  ifac[lm] = Inv(fac[lm]);
  for (ri i = lm - 1; i > 1; --i) ifac[i] = mul(ifac[i + 1], i + 1);
}
inline int C(int n, int m) { return n < m || m < 0 ? 0 : mul(fac[n], mul(ifac[m], ifac[n - m])); }
int main() {
  #ifdef ldxcaicai
  freopen("lx.in", "r", stdin);
  #endif
  n = read(), m = read(), K = read();
  init_fac();
  int res = 0;
  for (ri i = n - K; i <= n; ++i) {
    int mt = mul(ksm(m - 1, i - 1), m);
    Add(res, mul(mt, C(n - 1, i - 1)));
  }
  cout << res;
  return 0;
}

Measured memory_bytes: 5200
//BISMILLAH
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define lli long long int
#define ve vector<int>
#define FOR(n)          for(int i=0; i<(int)(n); ++i)
#define TEST_CASE(t)    for(int z=1;z<=t;z++)
#define PRINT_CASE      printf("Case %d: ",z)
#define pb push_back
#define maxx 100
#define mod 1000000007

int main()
{
    int x;
    scanf("%d",&x);
    if(x == 0) printf("1\n");
    else if(x == 1) printf("0\n");


    return 0;
}


Measured memory_bytes: 3764
import sys
inp = sys.stdin.readline

"""
sysというモデュ―ルを使ったinputの仕方
"""

class UnionFind:
    def __init__(self, n):
        self.tree = [-1]*n

    def size(self, a):
        return -self.tree[self.root(a)]

    def root(self, a):
        if(self.tree[a] < 0):
            return a
        res = self.root(self.tree[a])
        self.tree[a] = res
        return res
  
    def union(self, a, b):
        a = self.root(a)
        b = self.root(b)
        if(a == b):
            return
        if(self.size(a) < self.size(b)):
            a, b = b, a
        self.tree[a] += self.tree[b]
        self.tree[b] = a

N,M = map(int,input().split())
A, B = [], []
for i in range(M):
    a,b = map(int,input().split())
    A.append(a-1)
    B.append(b-1)
"""
zero index is used in UnionFind so this cord adjust list A,B to zero index
""" 
    
uf = UnionFind(N)
"""
inputされてるNをUnionFindに代入
"""

res = N*(N-1)//2
result = [0]*M

"""resultというリストを作る⇒結果表示用
result = [0,0,...M個]
 """
for i in range(M-1, -1, -1):
    result[i] = res
    if(uf.root(A[i]) != uf.root(B[i])):
        res -= uf.size(A[i]) * uf.size(B[i])
        uf.union(A[i], B[i])
for r in result:
    print(r)


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

const long long INF = 1LL << 60;

template <class T> bool chmin(T& a, T b)
{
  if (a > b) {
    a = b; return true;
  } else return false;
}

template <class T> bool chmax(T& a, T b)
{
  if (a < b) {
    a = b; return true;
  } else return false;
}


int main()
{
  int N, A, B, C;
  cin >> N >> A >> B >> C;
  vector<int> l(N);
  for (int i = 0; i < N; i++) cin >> l.at(i);
  
  long long ans = INF;
  
  for (int i = 0; i < pow(4, N); i++)
  {
    long long at = 0, bt = 0, ct = 0;
    long long al = 0, bl = 0, cl = 0;
    
    for (int j = 0, p = 1; j < N; j++)
    {
      int Z = (i / p) % 4;
      if (Z == 1) {at++; al += l.at(j);}
      else if (Z == 2) {bt++; bl += l.at(j);}
      else if (Z == 3) {ct++; cl += l.at(j);}
      p *= 4;
    }
    
    if (at > 0 && bt > 0 && ct > 0)
    {
      long long MP = (at + bt + ct - 3) * 10 
                    + abs(A - al) + abs(B - bl) + abs(C - cl);
      chmin(ans, MP);
    }
  }
  
  cout << ans << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
//#define kk
#define int long long
#define FOR(i, n) for(int i=1; i<=n; i++)
#define ff first
#define ss second
#define ll int
#define inf 1000000000
#define pb push_back
#define mod 1000000007
 
const long long INF=1e18+5;
typedef pair<int, int> pi;

int arr[405];
int dp[405][405];
//dp[i][j] - represents minimum cost to add numbers between interval [i......j]

int get(int i, int j){
	if(i>=j) return 0;
	if(dp[i][j]!=-1) return dp[i][j];
	
	int sum=0;
	for(int k=i; k<=j; k++){
		sum+=arr[k];
	}
	
	int ans=INF;
	for(int k=i; k<=j-1; k++){
		int temp=get(i, k)+get(k+1, j)+sum;
		ans=min(temp, ans);
	}
	return dp[i][j]=ans;
}

void solve(){
	int n;
	cin>>n;
	
	FOR(i, n) cin>>arr[i];
	
	memset(dp, -1, sizeof dp);
	
	cout<<get(1, n)<<endl;
}
 
signed main(){
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	
	cout<<fixed<<setprecision(10);
	
	#ifdef kk
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
	#endif
	
	int T=1;
	//cin>>T;
	
	while(T--){
		solve();
	}
}


Measured memory_bytes: 4908
#include <iostream>
#include <iomanip>
#include <map>
#include <set>
#include <vector>
#include <algorithm>
#include <utility>

#include <cstring>
#include <cstdio>
#include <cstdlib>
#include <cstdint>
#include <cmath>

using namespace std;

typedef long long ll;

double a,b,x;

int main() {
	cin >> a >> b >> x;
	x = x / a * 2;
	double l = 0;
	if(x > a * b) {
		x = b * 2 - x / a;
		l = atan(a/x);
	} else {
		l = atan(x/b/b);
	}
	cout << setprecision(20) << 90-(l*180.0/M_PI) << endl;
}


Measured memory_bytes: 256
import java.io.IOException;
import java.math.BigDecimal;
import java.math.RoundingMode;
import java.util.Scanner;

public class Main {

    public static void main(String[] args) throws IOException {
        final String SPACE = " ";
        Scanner sc = new Scanner(System.in);

        final int a1 = sc.nextInt();
        final int b1 = sc.nextInt();

        final BigDecimal a2 = new BigDecimal(a1);
        final BigDecimal b2 = new BigDecimal(b1);

        final long d = a1 / b1;
        final long r = a1 % b1;
        final BigDecimal f = a2.divide(b2, 5, RoundingMode.HALF_UP);

        StringBuilder sb = new StringBuilder();
        sb.append(d).append(SPACE).append(r).append(SPACE).append(f);

        System.out.println(sb);
    }
}

Measured memory_bytes: 17224
using System.Linq;
using System.Collections.Generic;
using System;

public class P
{
    public int x { get; set; }
    public int y { get; set; }
}

public class Hello
{
    public static void Main()
    {
        var alist = new List<int>();
        var n = long.Parse(Console.ReadLine().Trim());
        var n2 = (int)Math.Sqrt(n + 1);
        for (int i = 1; i <= n2; i++)
            if (n % i == 0) alist.Add(getF(i, n / i));
        Console.WriteLine(alist.Min());
    }
    public static int getF(int a, long b)
    {
        var wa = a.ToString().Length;
        var wb = b.ToString().Length;
        if (wa >= wb) return wa;
        else return wb;
    }
}

Measured memory_bytes: 13268
#include <iostream>
#include <algorithm>
#include <string>

typedef long long ll;
#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define REP(i, n) for (int i = 0; i < (n); i++)
#define ALL(a) (a).begin(), (a).end()
using namespace std;

int N;
string S[300];

bool check(int i, int j) {
    FOR(di, 1, N) REP(dj, di)
        if (S[(i + di) % N][(j + dj) % N] != S[(i + dj) % N][(j + di) % N])
            return false;
    return true;
}

int main() {
    cin >> N;
    REP(i, N) cin >> S[i];

    int count = 0;
    REP(i, N)
        if (check(i, 0)) count += N;
    cout << count << endl;
    return 0;
}

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

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

#define rep(i,n) for(ll i=0;i<n;i++)
#define REP(i,a,n) for(ll i=a;i<n;i++)

typedef long long ll;
typedef long double ld;
typedef pair<int,int> pii;
typedef tuple<int,int,int> tiii;
typedef pair<ll, ll> pll;

const int INF = 100000000;
const ll LINF = 1e18+5;

int main() {
    ll N, K;
    vector<ll> H;
    cin >> N >> K;
    rep(i,N){
        ll h = 0;
        cin >> h;
        H.push_back(h);
    }
    sort(H.begin(), H.end());
    ll ans = 0;
    if(N<=K){
        cout << 0 << endl;
        return 0;
    }
    rep(i,N-K){
        ans += H[i];
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 2420
#include <iostream>
#include <cstdio>
#include <string>
#include <vector>
#include <stack>
#include <deque>
#include <queue>
#include <set>
#include <cmath>
#include <algorithm>
#include <map>
#include <list>

using namespace std;

#define FOR( i, k, n ) for ( int i = ( k ); i <= ( int )( n ); ++i )
#define REP( i, n ) FOR( i, 1, n )

typedef long long ll;
typedef pair< int, int > P;

#define MAX_N 1300000

bool is_prime[ MAX_N + 1 ];

int main()
{
	// エラトステネス
	for( int i = 3; i <= MAX_N; i += 2 ) is_prime[ i ] = true;
	is_prime[ 2 ] = true;
	for( int i = 3; i * i <= MAX_N; i += 2 ) {
		if( !is_prime[ i ] ) continue;
		for( int j = i * 2; j <= MAX_N; j += i ) is_prime[ j ] = false;
	}

	int n;
	while( cin >> n, n ) {
		if( is_prime[ n ] ) { cout << 0 << endl;  continue; }
		int left, right;
		for( left = n; left >= 1; --left ) if( is_prime[ left ] ) break;
		for( right = n; right <= MAX_N; ++right ) if( is_prime[ right ] ) break;
		cout << right - left << endl;
	}
	return 0;
}

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

using namespace std;

int N, M;
vector<pair<int, int>> graph[100005];
pair<int, int> edge[100005];
int order[100005];
bool tree[100005];
int pare[100005], parn[100005];
bool vis[100005];
int outdgr[100005];
bool used[100005];

void dfs1(int n){
    vis[n] = 1;
    for(auto e : graph[n]){
        if(e.first != parn[n] && !used[e.second]){
            used[e.second] = 1;
            if(e.first == edge[e.second].first){
                swap(edge[e.second].first, edge[e.second].second);
            }
            outdgr[n]++;
            if(!vis[e.first]){
                pare[e.first] = e.second;
                parn[e.first] = n;
                tree[e.second] = 1;
                dfs1(e.first);
            }
        }
    }
}

int dfs2(int n){
    int tot = outdgr[n]&1;
    for(auto e : graph[n]){
        if(e.first != parn[n] && tree[e.second]){
            int sub = dfs2(e.first);
            if(sub > tot){
                swap(sub, tot);
            }
            tot -= sub;
        }
    }
    if(tot&1){
        order[pare[n]]++;
    }
    return tot;
}

int main(){
    cin.sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    cin >> N >> M;
    for(int i = 1; i<=M; i++){
        int a, b;
        cin >> a >> b;
        edge[i] = {a, b};
        graph[a].push_back({b, i});
        graph[b].push_back({a, i});
    }
    if(M%2 == 1){
        cout << -1 << endl;
        return 0;
    }
    dfs1(1);
    dfs2(1);
    for(int i = 1; i<=M; i++){
        if(order[i]){
            cout << edge[i].second << " " << edge[i].first << "\n";
        }
        else{
            cout << edge[i].first << " " << edge[i].second << "\n";
        }
    }
}


Measured memory_bytes: 14208
#include <stdio.h>
#include <limits.h>

#define MAX 100
#define WHITE 0
#define GRAY 1
#define BLACK 2

void dijkstra(int);

int color[MAX],M[MAX][MAX],d[MAX],p[MAX];
int n;

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

  for (i = 0;i < MAX;i++)
    for (j = 0;j < MAX;j++)
      M[i][j] = INT_MAX;
  
  scanf("%d",&n);

  for (i = 0;i < n;i++){
    scanf("%d %d",&u,&k);

    for (j = 0;j < k;j++){
      scanf("%d %d",&v,&c);

      M[u][v] = c;
    }
  }

  dijkstra(0);

  for (i = 0;i < n;i++)
    printf("%d %d\n",i,d[i]);
  
  return 0;
}

void dijkstra(int s){
  int i;
  int mincost,u;

  for (i = 0;i < n;i++){
    color[i] = WHITE;
    d[i] = INT_MAX;
  }

  d[s] = 0;
  color[s] = GRAY;
  p[s] = -1;

  while (1){
    mincost = INT_MAX;

    for (i = 0;i < n;i++)
      if (color[i] != BLACK && d[i] < mincost){
	mincost = d[i];
	u = i;
      }

    if (mincost == INT_MAX)
      break;

    color[u] = BLACK;

    for (i = 0;i < n;i++)
      if (color[i] != BLACK && M[u][i] != INT_MAX)
	if (d[u] + M[u][i] < d[i]){
	  d[i] = d[u] + M[u][i];
	  p[i] = u;
	  color[i] = GRAY;
	}
  }
}



Measured memory_bytes: 2112
#include <cstring>
#include <sstream>
#include <cstdio>
#include <algorithm>
#include <iostream>
#include <vector>
#include <map>
#include <unordered_map>
#include <cmath>
#include <queue>
#include <set>
#include <stack>

using namespace std;
typedef long long ll;
#define rep(i, n) for(ll i = 0; i < (ll)(n); i++)
#define repr(i, n) for(ll i = n - 1; i >= 0; i--)
#define repone(i, n) for(ll i = 1; i <= (ll)(n); i++)
#define each(i, mp) for(auto i:mp)
const int dx[4] = {1, 0, -1, 0}, dy[4] = {0, 1, 0, -1};
const ll mod = 1000000007;
const ll inf = ll(1e9);
const ll half_inf = ll(1e5);
const ll ll_inf = ll(1e9) * ll(1e9);
typedef map<pair<ll, ll>, ll> ump;
typedef pair<ll, ll> P;

ump mp;
ll h, w, n;

void solve() {
    map<int, ll> ans;
    set<pair<ll, ll>> see;
    each(m, mp) {
        ll x = m.first.first;
        ll y = m.first.second;
        for (int i = -1; i <= 1; ++i) {
            for (int j = -1; j <= 1; ++j) {
                int nx = x + i, ny = y + j;
                if (nx >= 1 && ny >= 1 && nx <= h - 2 && ny <= w - 2) {
                    see.insert(make_pair(nx, ny));
                }
            }
        }
    }
    each(s, see) {
        ll x = s.first;
        ll y = s.second;
        ll tmp = 0;
        for (int i = -1; i <= 1; ++i) {
            for (int j = -1; j <= 1; ++j) {
                int nx = x + i, ny = y + j;
                tmp += mp[make_pair(nx, ny)];
            }
        }
        ans[tmp]++;
    }
    ans[0] = (h - 2) * (w - 2) - see.size();
    rep(i, 10) cout << ans[i] << endl;
}

int main() {
#ifdef MY_DEBUG
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wmissing-noreturn"
    while (true) {
        mp = ump();
#pragma clang diagnostic pop
#endif
        cin >> h >> w >> n;
        rep(i, n) {
            ll a, b;
            cin >> a >> b;
            a--, b--;
            mp[make_pair(a, b)]++;
        }

        solve();

#ifdef MY_DEBUG
    }
#endif
    return 0;
}

Measured memory_bytes: 212736
#include <iostream>
using namespace std;
int main(void)
{
	int i,c;
	int k = 0;
	int j = 0;
	int b;
	unsigned long long s[200];
	cin>>c;
	for(i=0;i<c;i++)
	cin>>s[i];
	while(1)
	{
		for(i=0;i<c;i++)
	    {
			b = s[i] % 2;
		   if(b)
		   {
			   j = 1;
		       break;
		    }
		   b = s[i];
		   s[i] = b / 2;
	    }
	    if(j)
	    break;
	    k++;
    }
	 
	 cout<<k;
	
	return 0;
}

Measured memory_bytes: 384
#include <iostream>
#include <string>
#include <vector>
#include <set>
#include <stack>
#include <queue>
#include <map>
#include <algorithm>
#include <iomanip>
#include <math.h>
#include <string.h>
#include <cstdio>
#include <tuple>
using namespace std; using ll = long long; using ld = long double;  using pll = pair<ll, ll>;
using vl = vector<ll>; using vll = vector<vl>; using vpll = vector<pll>;
const ld PI = 3.1415926535897932;
#define debug(...) cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)
#define rep1(n) for(ll i=0;i<n;++i)
#define rep2(i,n) for(ll i=0;i<n;++i)
#define rep3(i,a,b) for(ll i=a;i<b;++i)
#define rep4(i,a,b,c) for(ll i=a;i<b;i+=c)
#define rep(...) overload4(__VA_ARGS__,rep4,rep3,rep2,rep1)(__VA_ARGS__)
#define mp make_pair
#define mt make_tuple
#define INT(...) int __VA_ARGS__;in(__VA_ARGS__)
#define LL(...) ll __VA_ARGS__;in(__VA_ARGS__)
#define ULL(...) ull __VA_ARGS__;in(__VA_ARGS__)
#define STR(...) string __VA_ARGS__;in(__VA_ARGS__)
#define CHR(...) char __VA_ARGS__;in(__VA_ARGS__)
#define DBL(...) double __VA_ARGS__;in(__VA_ARGS__)
#define LD(...) ld __VA_ARGS__;in(__VA_ARGS__)
void in() {}
void debug_out() { cerr << endl; }
template<typename Head, typename... Tail>
void debug_out(Head h, Tail... t) {
	cerr << " " << h;
	if (sizeof...(t) > 0) cerr << " :";
	debug_out(t...);
}
template <typename T>
ostream& operator<<(ostream& os, vector<T> vec) {
	for (size_t i = 0; i < vec.size(); i++)os << vec[i] << (i + 1 == vec.size() ? "" : " ");
	return os;
}
ll ctoi(char c) {
	switch (c) {
	case '0': return 0; case '1': return 1; case '2': return 2;
	case '3': return 3; case '4': return 4; case '5': return 5;
	case '6': return 6; case '7': return 7; case '8': return 8;
	case '9': return 9;  default: return 0;
	}
}
bool pairCompare(const pll firstElof, pll secondElof)
{
	return firstElof.first > secondElof.first;
}
//**Snippetリスト**//
//rep, vin, all, iteLoop//
//bitSearch, bitList, nod, gcdlcm, isPrime, primeFactorize, Npow, divisor, modinv, dfs, bfs, eratos//
//dijkstra, WarshallFloyd, BellmanFord, UnionFind, COM, digitDP ,RMQ//
ll i, j, k, l; ll N, M, K, H, W, L, X, Y, Z, R;
ll MOD = 1000000007; ll INF = 1LL << 62; ll ans = 1; ll z = 0, o = 1;
vl flag, color, D; vll path;
int main() {
	cin >> N;
	vl A(N);
	for (i = 0; i < N; i++) cin >> A[i];
	sort(A.begin(), A.end());
	ll key1 = A[N - 1];
	ll key2 = A[0];
	if (key1 % 2 == 1) {
		ll mini = INF;
		ll target = key1 / 2 + 1;
		for (i = 0; i < N - 1; i++) {
			if (abs(target - A[i]) < mini) {
				key2 = A[i];
				mini = abs(target - A[i]);
			}
		}
	}
	else {
		ll mini = INF;
		ll target = key1 / 2;
		for (i = 0; i < N - 1; i++) {
			if (min(abs(target - A[i]),abs(target+1-A[i])) < mini) {
				key2 = A[i];
				mini = min(abs(target - A[i]), abs(target + 1 - A[i]));
			}
		}
	}
	cout << key1 << " " << key2;
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
#include <boost/range/algorithm.hpp>
#include <boost/range/numeric.hpp>
#include <boost/integer/common_factor.hpp>

#define rep_ui(k,n)      for(ui  i = (k); i < (n); ++i)
#define rep_si(k,n)      for(int i = (k); i < (n); ++i)
#define rep_ul(k,n)      for(ul  i = (k); i < (n); ++i)
#define rep_sl(k,n)      for(ll  i = (k); i < (n); ++i)
#define rep_ui_down(k,n) for(ui  i = (k); i > (n); --i)
#define rep_si_down(k,n) for(int i = (k); i > (n); --i)
#define rep_ul_down(k,n) for(ul  i = (k); i > (n); --i)
#define rep_sl_down(k,n) for(ll  i = (k); i > (n); --i)

#define rep_uj(k,n)      for(ui  j = (k); j < (n); ++j)
#define rep_sj(k,n)      for(int j = (k); j < (n); ++j)
#define rep_uj_down(k,n) for(ui  j = (k); j > (n); --j)
#define rep_sj_down(k,n) for(int j = (k); j > (n); --j)

#define rep(k,n)         rep_ui(k,n)

typedef uintmax_t    ull;
typedef intmax_t     ll;
typedef uint64_t     ul;
typedef uint32_t     ui;
typedef uint8_t      uc;

template<class T>
std::ostream& operator<<(std::ostream& os, const std::vector<T>& vc)
{
#ifdef BOOST_RANGE_ALGORITHM_FOR_EACH_HPP_INCLUDED
  boost::for_each(vc, [&os](T value) {
#else
  std::for_each(vc.begin(), vc.end(), [&os](T value) {
#endif
    os << value << '\n';
    });
  return os;
    }

template<class T1, class T2>
inline
std::ostream & operator<<(std::ostream & os, const std::pair<T1, T2> & p)
{
  return os << p.first << ' ' << p.second;
}

void solve(void)
{
  using std::string;
  using std::vector;
  using std::map;
  using std::pair;
  using std::cin;
  //string S{}; std::cin >> S;
  //ui N{}; cin >> N;
  vector<ui> vc(5);
  vector<ui> res{};
  ui k{};
  rep(0, vc.size()) cin >> vc[i];
  cin >> k;

  ull ans{};
  ans = (vc[4] - vc[0] > k) ? false : true;


  using std::cout;
  cout << (ans ? "Yay!" : ":(" ) << '\n';
  return;
}

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

  solve();

  return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<algorithm>
#include<map>
#include<cstring>
#include<math.h>
#include<bitset>
#include<queue>
#include<set>
#include<iomanip>
#include<math.h>
#include<assert.h>
#include<string>
#include<cstdlib>
#include<cctype>
#include<unordered_map>
#include<sstream>
// #include<bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<int,int>;
constexpr ll INF = 1LL<<60;
const double INFD = 1e100;
const ll mod = 1000000007;
const double PI = 3.1415926535897932384626433832795028841971;
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};
template<class T> inline bool chmin(T& a, T b) {
    if (a > b) {
        a = b;
        return true;
    }
    return false;
};
template<class T> inline bool chmax(T& a, T b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
};

// intやllをstringに変換
template<typename T> inline string toString(const T &a){
  ostringstream oss;
  oss << a;
  return oss.str();
};
// ----------------------------------------------------------------------------
ll dp[1010][10010];
int main(){
  int H,N;
  cin >> H >> N;
  for(int i=0; i<=N; i++){
    for(int j=0; j<=H; j++){
      dp[i][j] = INF;
    }
  }
  vector<int> A(N),B(N);
  for(int i=0; i<N; i++){
    cin >> A[i] >> B[i];
  }
  dp[0][0] = 0;
  for(int i=0; i<N; i++){
    for(int j=0; j<=H; j++){
      chmin(dp[i+1][j],dp[i][j]);
      chmin(dp[i+1][min(H,j+A[i])],dp[i+1][j]+B[i]);
    }
  }
  cout << dp[N][H] << endl;
  return 0;
}


Measured memory_bytes: 78592
#include <iostream>
#include <stdlib.h>
#include <string>
#include <sstream>
#include <vector>

int main(void){

	std::string input;

	while(std::cin >> input){
		std::vector<int> Station;

		std::stringstream ss(input);
		std::string buffer;
		while(std::getline(ss, buffer, ',')){
			Station.push_back(atoi(buffer.c_str()));
		}
		double Va = Station[Station.size()-2];
		double Vb = Station[Station.size()-1];

		double ratio = Va / (Va + Vb);

		double distance = 0.0;
		for(unsigned int i=0; i<Station.size()-2; i++){
			distance += Station[i];
		}
		double position = distance * ratio;

		for(unsigned int i=0; i<Station.size()-2; i++){
			position -= Station[i];
			if(position <= 0.0){
				std::cout << i+1 << std::endl;
				break;
			}
		}
	}

	return 0;
}



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

typedef long long ll;
#define FAST ios_base::sync_with_stdio(0);cin.tie(0);

void solveA() {
	int a[3];
	for(int i = 0; i < 3; i++) 
		cin >> a[i];
	int ans = 10000000;
	do {
		int here = 0;
		for(int i = 1; i < 3; i++)
			here += abs(a[i] - a[i-1]);
		ans = min(here, ans);
	} while(next_permutation(a,a+3));
	cout << ans << endl;
}
void solveB() {

}
void solveC() {

}
void solveD() {

}

int main() {
	solveA();
	//solveB();
	//solveC();
	//solveD();
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
unsigned long long int mod = 1000000000 + 7;
 
void comb(vector<vector<unsigned long long int>>& vs){
    
  for(int i = 0 ; i < vs.size() ;i++){
    vs[i][0] = 1;
    vs[i][i] = 1;
  }
  
  for(int i = 1; i < vs.size(); i++){
      for(int j = 1; j < i ; j++){
        vs[i][j] = (vs[i-1][j-1] +vs[i-1][j]) % mod;
      }
  }
 
 // return vs;
}
 
int main(){
  unsigned long long int N, K;
  cin >> N >> K;
  vector<vector<unsigned long long int>> v(N + 1, vector<unsigned long long int>(N + 1, 0));

  comb(v);
  
  for(int i = 1; i <= K ;i++){   
   unsigned long long int c = v[K-1][i-1] % mod;
   unsigned long long int c1 = v[N-K+1][i] % mod;
   cout <<c * c1 % mod << endl;
  }
  
  return 0;
}


Measured memory_bytes: 31616
#include<bits/stdc++.h>
#pragma GCC optimize("Ofast")
using namespace std;
typedef long long ll;
typedef pair<ll, ll> PLL;
typedef vector<int> VI;
typedef vector<char> VC;
typedef vector<double> VD;
typedef vector<string> VS;
typedef vector<ll> VLL;
typedef vector<PLL> VP;
const static int INF = 1000000000;
const static int MOD = 1000000007;
const int dx[4]={1, 0, -1, 0};
const int dy[4]={0, 1, 0, -1};
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; }
#define rep(i,n) for (ll i=0; i<(ll)(n); i++)
#define repd(i,n) for (ll i=n-1; i>=0; i--)
#define rept(i,m,n) for(ll i=m; i<n; i++)
#define stl_rep(itr, x) for (auto itr = x.begin(); itr != x.end(); ++itr)
#define all(x) (x).begin(), (x).end()
#define F first
#define S second
#define PF push_front
#define PB push_back
#define SORT(V) sort((V).begin(), (V).end())
#define RVERSE(V) reverse((V).begin(), (V).end())
#define paired make_pair
#define PRINT(V) for(auto v : (V)) cout << v << " "
//charを整数に
int ctoi(char c) { if (c >= '0' && c <= '9') { return c - '0'; } return 0; }
// 累積和 for (int i = 0; i < N; ++i) s[i+1] = s[i] + a[i]; 
void cum_sum(int N,vector<double> a, vector<double> &s){ for(int i=0; i<N; i++){ s[i+1]=s[i]+a[i];}}
//ユークリッドの控除法
ll gcd(ll a,ll b){
    if(b == 0) return a;
    return gcd(b,a%b);
}
//最小公倍数
ll lcm(ll a,ll b){
    ll g = gcd(a,b);
    return a / g * b; // Be careful not to overflow
}
//素数判定
bool is_prime(long long n) {
    if (n <= 1) return false;
    for (long long p = 2; p * p <= n; ++p) {
        if (n % p == 0) return false;
    }
    return true;
}
int getdigit(ll num){
    unsigned digit=0;
    while(num!=0){
        num /= 10;
        digit++;
    }
    return digit;
}
//空白文字も入力 getline(cin, S);
//桁数指定 setprecision

int main()
{
    ios::sync_with_stdio(0); 
    cin.tie(0); 
    cout.tie(0);
    ll A, B, V, W, T;
    cin >> A >> V;
    cin >> B >> W;
    cin >> T;
    if(A==B){
        cout << "YES" << endl;
    }
    else{
        if(W>=V){
            cout << "NO" << endl;
        }
        else{
            ll dif=abs(V-W);
            ll c_dif=abs(A-B);
            if(c_dif<=T*dif){
                cout << "YES" << endl;
            }
            else{
                cout << "NO" << endl;
            }
        }
    }
}

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

using namespace std;

#define db(...) ZZ(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1> void ZZ(const char* name, Arg1&& arg1){std::cerr << name << " = " << arg1 << endl;}
template <typename Arg1, typename... Args>void ZZ(const char* names, Arg1&& arg1, Args&&... args)
{
	const char* comma = strchr(names + 1, ',');
	std::cerr.write(names, comma - names) << " = " << arg1;
	ZZ(comma, args...);
}

#define IOS ios_base::sync_with_stdio(0); cin.tie(0);
#define endl '\n'

int main()
{
	IOS;
	string s;
	cin >> s;
	int cur = 0, ans = 0;
	for (int i = 0; i < s.size(); i++) {
		if (s[i]=='A' || s[i]=='C' || s[i]=='G' || s[i]=='T') {
			cur++;
			ans = max(ans, cur);
		}
		else 
			cur = 0;
	}
	cout << ans << endl;
	return 0;
}



Measured memory_bytes: 256
#include <cstdio>
#include <climits>
#include <algorithm>
#include <vector>
#include <functional>
using namespace std;

int main() {
  int R, C, N; scanf("%d%d%d", &R, &C, &N);
  vector<vector<pair<int,long long>>> graph(R+C);
  for(int i = 0; i < N; ++i) {
    int r, c, a; scanf("%d%d%d", &r, &c, &a); --r; --c;
    graph[r].emplace_back(R+c, -a);
    graph[R+c].emplace_back(r, a);
  }
  vector<char> vis(R+C, false);
  vector<long long> rel(R+C, 0);
  long long rmin = LLONG_MAX/5;
  long long cmax = LLONG_MIN/5;
  bool ok = true;
  function<void(int, long long)> search = [&](int v, long long vrel){
    if(vis[v]) {
      if(vrel != rel[v]) ok = false;
      return;
    }
    vis[v] = true;
    rel[v] = vrel;
    if(v < R) {
      rmin = min(rmin, vrel);
    } else {
      cmax = max(cmax, vrel);
    }
    for(auto edge : graph[v]) {
      search(edge.first, vrel+edge.second);
    }
  };
  for(int v = 0; v < R+C; ++v) {
    if(vis[v]) continue;
    rmin = LLONG_MAX/5;
    cmax = LLONG_MIN/5;
    search(v, 0);
    // printf("%d: ok=%d, rmin=%lld, cmax=%lld\n", v, ok, rmin, cmax);
    if(!ok || rmin-cmax<0) {
      printf("No\n");
      return 0;
    }
  }
  printf("Yes\n");
  return 0;
}


Measured memory_bytes: 19712
#include<bits/stdc++.h>
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>
#define FAST ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0)
#define dofloat cout<<fixed<<setprecision(8)
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define bitcount _builtin_popcount
#define all(vec) vec.begin(),vec.end()
#define rall(vec) vec.rbegin(),vec.rend()
using namespace __gnu_pbds;
using namespace std;
//typedef
typedef long long ll;
typedef long double ld;
typedef vector<long long> vl;
typedef pair<long long,long long> pll;
typedef vector<pair<long long,long long> > vll;
typedef vector<pair<int,int> > vii;
typedef vector<int> vi;
typedef pair<int,int> ii;
//constants
const long long MOD=1000000007;
const long long MAX=100005;
const long double PI=3.14159265359;
const long double G=9.807;
const long long INF=1e18;
const long double EPS=1e-6;
// gcd of a and b
long long gcd(long long a,long long b){return b?gcd(b,a%b):a;}
// distance between (a,b) and (c,d)
long double dis(long long a,long long b,long long c,long long d){return sqrt( ((a)-(c))*((a)-(c))+((b)-(d))*((b)-(d)) );}
// simple prime check
bool isprime(long long a){
if(a==2)return 1;
if(!(a&1))return 0;
for(ll i=3;i*i<=a;i+=2){
	if(a%i==0)return 0;
}
return 1;
}
// fast expo
long long mpow(long long base,long long exponent,long long modulus){
if(modulus==1)return 0;
long long result = 1;
base=base%modulus;
while(exponent){
		if(exponent%2 == 1)
			result=(result*base)%modulus;
		exponent=exponent>>1;
		base=(base*base)%modulus;
	}
return result;
}
// modular inverse
ll minv(ll a,ll mod){
	ll _gcd=gcd(a,mod);
	assert(_gcd==1);
	return mpow(a,mod-2,mod);
}

/*
template <typename T>
using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
*/

/*
ll dx[]={1,0,-1,0,1,1,-1,-1};
ll dy[]={0,-1,0,1,1,-1,-1,1};
*/

/*
void sieve(int N){
	for(int i=0;i<=N;i++){
		spf[i]=i;
	}
	for(int i=2;i*i<=N;i++){
		if(spf[i]==i){
			for(int j=i*i;j<=N;j+=i){
				spf[j]=min(spf[j],i);
			}
		}
	}
	return;
}
*/

/*
void nCr(ll n,ll k){
	ll i,j;
	for(i=0;i<=n;i++){
		for(j=0;j<=min(i,k);j++){

			if(j==0 or j==i)C[i][j]=1LL;
			else  C[i][j]=(C[i-1][j-1]+C[i-1][j])%MOD;

		}
	}
	return;
}
*/
/*
ll ncr(ll N,ll K){
	if(N<K)return 0;
	if(K==0)return 1;
	if(N==0)return 0;

	ll den=1;
	for(ll i=1;i<=K;i++)den*=i;
	ll num=1;
	while(K--){
		num*=N;
		if(num%den==0){
			num/=den;
			den=1;
		}
		N--;
	}

	return num;
}
*/
vl a,b,c;
ll k,x,y,z;
int main(){FAST;
cin>>x>>y>>z>>k;
for(ll i=0;i<x;i++){
	ll temp;cin>>temp;
	a.pb(temp);
}
for(ll i=0;i<y;i++){
	ll temp;cin>>temp;
	b.pb(temp);
}
for(ll i=0;i<z;i++){
	ll temp;cin>>temp;
	c.pb(temp);
}
sort(rall(c));
vl v;
for(ll i=0;i<min(x,k);i++){
	for(ll j=0;j<min(x,k);j++){
		ll sum = a[i]+b[j];
		v.pb(sum);
	}
}
sort(rall(v));
vl vv;
for(ll i=0;i<min(k,(ll)v.size());i++){
	for(ll j=0;j<min(z,k);j++){
		vv.pb(v[i]+c[j]);
	}
}
sort(rall(vv));
for(ll i=0;i<k;i++)
	cout<<vv[i]<<'\n';
return 0;
}


Measured memory_bytes: 43384
#include <iostream>

using namespace std;

int main() {
    int a,b;
    cin>>a>>b;
    if
            (a>b)cout<<"a > b"<<endl;
    else if
            (a==b)cout<<"a == b"<<endl;
    else if
            (a<b)cout<<"a < b"<<endl;

    return 0;
}

Measured memory_bytes: 3028
from collections import defaultdict
from copy import copy
N,W = map(int,input().split())
src = [tuple(map(int,input().split())) for i in range(N)]

dp = defaultdict(lambda: 0)
dp[0] = 0
for w,v in src:
    dp2 = copy(dp)
    for pw,pv in dp.items():
        if pw+w > W: continue
        defv = dp[pw+w] if pw+w in dp else 0
        dp2[pw+w] = max(defv, pv+v)
    dp = dp2
print(max(dp.values()))

Measured memory_bytes: 4132
#include <bits/stdc++.h>
 
using namespace std;
 
typedef vector<int> Vec;
 
void solve(Vec &s){
    int ans = 20;
    const int dx[8] = {-1,-1,-1,0,0,1,1,1};
    const int dy[8] = {-1,0,1,-1,1,-1,0,1};
    queue<Vec> Q;
    Q.push(s);
    set<Vec> visited;
    visited.insert(s);
    while(!Q.empty()){
	Vec v = Q.front(); Q.pop();
	int size = v.size();
	ans = min(ans,size);
	for(int i = 0 ; i < size ; i++){
	    for(int j = 0 ; j < 8 ; j++){
		Vec next;
		int nx = i%4 + dx[j];
		int ny = i/4 + dy[j];
		if(nx < 0 || ny < 0 || nx >= min(4,size) || ny >= 5) continue;
		if(nx+ny*4 < 0 || nx+ny*4 >= size) continue;
		if(v[i] == v[nx+ny*4]){
		    for(int k = 0 ; k < size ; k++){
			if(i == k || nx+ny*4 == k) continue;
			next.push_back(v[k]);
		    }
		    if(!visited.count(next)){
			visited.insert(next);
			Q.push(next);
		    }
		}
	    }
	}
    }
    cout << ans << endl;
}
 
int main(){
    int Tc;
    cin >> Tc;
    while(Tc--){
	Vec vec(20);
	for(int i = 0 ; i < 20 ; i++){
	    cin >> vec[i];
	}
	solve(vec);
    }
    return 0;
}

Measured memory_bytes: 3252
#define SUBMIT

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

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

    for (int i = 0; i < k; ++i) {
        if (i % 2 == 0) {
            auto half = a / 2;
            a = half;
            b += half;
        }
        else {
            auto half = b / 2;
            b = half;
            a += half;
        }
    }
    cout << a << " " << b << endl;
    return 0;
}

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



#define SIZE 200005

int N;
ll A[SIZE],B[SIZE];


int main(){

	scanf("%d",&N);

	for(int i = 0; i < N; i++){

		scanf("%lld %lld",&A[i],&B[i]);
	}
	sort(A,A+N);
	sort(B,B+N);

	ll mid_A,mid_B;

	if(N%2 == 0){

		mid_A = (A[N/2]+A[N/2-1]);
		mid_B = (B[N/2]+B[N/2-1]);;

	}else{

		mid_A = A[(N-1)/2];
		mid_B = B[(N-1)/2];
	}

	if(mid_A > mid_B){

		swap(mid_A,mid_B);
	}

	printf("%lld\n",mid_B-mid_A+1);

	return 0;
}


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

using namespace std;

int main() {
  int N;
  cin >> N;
  vector<int> C(N-1), S(N-1), F(N-1);
  for (int i = 0; i < N-1; i++)
    cin >> C[i] >> S[i] >> F[i];

  for (int i = 0; i < N-1; i++) {
    int station = i;
    int time = 0;
    for (int j = i; j < N-1; j++) {
      if (time < S[j]) {
        time = S[j];
      } else if (time % F[j] != 0) {
        time += F[j] - (time - S[j]) % F[j];
      }
      time += C[j];
    }
    cout << time << endl;
  }
  cout << 0 << endl;

  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define stoi stoll
using ll=long long;
using vi=vector<int>;
using pii=pair<int,int>;
#define ALL(c) begin(c),end(c)
#define RALL(c) rbegin(c),rend(c)
#define ITR(i,b,e) for(auto i=(b);i!=(e);++i)
#define FORE(x,c) for(auto &x:c)
#define REPF(i,a,n) for(int i=a,i##len=(int)(n);i<i##len;++i)
#define REP(i,n) REPF(i,0,n)
#define REPR(i,n) for(int i=(int)(n);i>=0;--i)
#define SZ(c) ((int)c.size())
#define CONTAIN(c,x) (c.find(x)!=end(c))
#define OUTOFRANGE(y,x,h,w) (y<0||x<0||y>=h||x>=w)
#define dump(...)
const signed INF_=1001001001; const ll INF=1001001001001001001LL;
const int DX[9]={0,1,0,-1,1,1,-1,-1,0},DY[9]={-1,0,1,0,-1,1,1,-1,0};
template<class T> ostream& operator<<(ostream &os,const vector<T> &v) {
    ITR(i,begin(v),end(v))os<<*i<<(i==end(v)-1?"":" ");return os;}
template<class T> istream& operator>>(istream &is,vector<T> &v) {
    ITR(i,begin(v),end(v)) is>>*i;return is;}
template<class T,class U> istream& operator>>(istream &is, pair<T,U> &p) {
    is>>p.first>>p.second;return is;}
template<class T> bool chmax(T &a,const T &b){if(a<b){a=b;return 1;}return 0;}
template<class T> bool chmin(T &a,const T &b){if(a>b){a=b;return 1;}return 0;}
template<class T> using heap=priority_queue<T,vector<T>,greater<T>>;
struct{template<class T> operator T(){T x;cin>>x;return x;}} IN;
struct before_main_function {
    before_main_function() {
        cin.tie(0);ios::sync_with_stdio(false);
        cout<<setprecision(15)<<fixed;
        #define endl "\n"
    }
} before_main_function;
//------------------8<------------------------------------8<--------------------

/*
<expression> ::= <term> | <term> ('+' | '-') <term>
<term> ::= <factor> | <factor> ('*' | '/') <factor>
<factor> ::= <number> | '(' <expression> ')'
<number> ::= 0~9 | <number> <number>
*/
int expression(string &s,int &i);
int term(string &s,int &i);
int factor(string &s,int &i);
int number(string &s,int &i);

int expression(string &s,int &i) {
    int ret=term(s,i);
    while(s[i]=='+' || s[i]=='-') {
        char op=s[i++];
        int right=term(s,i);
        if(op=='+') ret+=right;
        else ret-=right;
    }
    return ret;
}
int term(string &s,int &i) {
    int ret=factor(s,i);
    while(s[i]=='*' || s[i]=='/') {
        char op=s[i++];
        int right=factor(s,i);
        if(op=='*') ret*=right;
        else ret/=right;
    }
    return ret;
}
int factor(string &s,int &i) {
    if(s[i]=='(') {
        i++;
        int expr=expression(s,i);
        i++;
        return expr;
    } else {
        return number(s,i);
    }
}
int number(string &s,int &i) {
    int num=0;
    while('0'<=s[i] && s[i]<='9') {
        num*=10;
        num+=s[i]-'0';
        i++;
    }
    return num;
}

int solve() {
    string s=IN;
    int i=0;
    return expression(s,i);
}
signed main() {
    int n=IN;
    while(n--) {
        cout<<solve()<<endl;
    }
    return 0;
}



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

// def
#define debug(x) cout << #x << ": " << x << endl
#define out(x) cout << x << endl
#define repeat(i, a, b) for (int i = (a); i < (b); i++)
#define revrepeat(i, a, b) for (int i = (b)-1; i >= (a); i--)
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define revrep(i, n) for (int i = (n)-1; i >= 0; i--)
typedef long long ll;
typedef pair<int, int> P;
const int M = 1e9 + 7;
const int INF = 1e9;
const int MAX_V = 100 + 5;
const int MAX_N = 1e5 + 5;

int dfs(int start, int currTime, int goal) {
    if (start >= goal) return currTime;
    dfs(start + currTime, currTime + 1, goal);
}

int main() {
    int goal;
    cin >> goal;
    cout << dfs(0, 1, goal) - 1 << endl;
}


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

#define ll long long

int main() {
    int N, M, C;
    scanf("%d%d%d", &N, &M, &C);
    int B[M];
    int A[N][M];

    for(int i = 0;i < M;i++) {
        scanf("%d", &B[i]);
    }
    for(int i = 0;i < N;i++) {
        for(int j = 0;j < M;j++) {
            scanf("%d", &A[i][j]);
        }
    }

    int count = 0;
    for(int i = 0;i < N;i++) {
        int sum = C;
        for(int j = 0;j < M;j++) {
            sum += A[i][j]*B[j];
        }
        if(0 < sum) {
            count++;
        }
    }

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

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <numeric>
using namespace std;
#define ll long long
#define mod107 1000000007
#define rep(i, n) for (int i = 0; i < n; ++i)
using Graph = vector<vector<int>>;
#define grepq priority_queue<double, std::vector<double>, std::greater<double>>
#define all(v) v.begin(), v.end()
#define PI acos(-1)

const ll INF = 10010001010;
const int inf = 2000000000;

typedef tuple<string, int, int> TUP;

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

int main()
{
    int X, Y;
    cin >> X >> Y;
    bool OK = false;
    for (int i = 0; i <= X;i++)
    {
        if(i * 2 + (X-i)*4 == Y){
            OK = true;
            break;
        }
    }
    if(OK){
        cout << "Yes" << endl;
    }
    else{
        cout << "No" << endl;
    }
}


Measured memory_bytes: 3632
#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;
  cin >> n;
  vector<int> a(n), b(n);
  rep(i, n) cin >> a[i] >> b[i];
  ll ans = 0;
  for (int i = n - 1; i >= 0; i--) {
    int dif = (b[i] - (a[i] + ans) % b[i]) % b[i];
    ans += dif;
    // cerr << dif << " " << ans << endl;
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 1024
r,c = map(int,input().split())
n = [list(map(int,input().split())) for _ in range(r)]
m = []
for i in range(r):
    n[i].append(sum(n[i]))
for j in range(c+1):
    num = 0
    for k in range(r):
        num += n[k][j]
    m.append(num)
n.append(m)
for l in range(r+1):
    print(*n[l])


Measured memory_bytes: 6200