akhauriyash/Code-Regression huggingface dataset:
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <stdbool.h>
#include <math.h>

int main(void){
    char s[200500];
    scanf("%s",s);
    long long ans=0,counta=0;
    for (int i=0; i<strlen(s); i++){
        if (s[i]=='A'){
            counta++;
        } else if (s[i]=='B'){
            if (s[i+1]=='C'){
                ans+=counta;
                i++;
            } else {
                counta=0;
            }
        } else {
            counta=0;
        }
    }
    printf("%lld\n",ans);
    return 0;
}


Measured memory_bytes: 384
from fractions import gcd
from functools import reduce


def lcm(a, b):
    return a * b // gcd(a, b)


def solve(string):
    n, m, *a = map(int, string.split())
    c = 2**len(bin(a[0]).split("1")[-1])
    for _a in a:
        if _a % c or not _a // c % 2:
            return "0"
    l = reduce(lcm, a)
    return str(max((m - l // 2) // l + 1, 0))


if __name__ == '__main__':
    import sys
    print(solve(sys.stdin.read().strip()))


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

using namespace std;

int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);cout.tie(0);
    int n,m;
    cin>>n>>m;
    n=n*(n-1)/2;
    m=m*(m-1)/2;
    cout<<n+m<<endl;
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ll long long int
#define fastio ios_base::sync_with_stdio(false);cin.tie(NULL);
#define bs binary_search
#define pb push_back
#define pp pair<ll,ll>
#define all(v) v.begin(),v.end()
#define F first 
#define S second 
#define lc "\n"
ll power(ll x,ll y,ll p){ll res=1;x=x%p;while(y>0){if(y&1)res=(res*x)%p;y=y>>1;x=(x*x)%p;}return res;} 
ll MAX=1e18 , MIN=-1e18 , MOD=1000000007;
void solve()
{
    ll n,k,p,q; cin>>n>>k; 
    p=n%k; q=abs(p-k);
    cout<<min(p,q);
}
int main() 
{
    fastio
    int t=1; //cin>>t;
    while(t--) solve();
    return 0;
}

Measured memory_bytes: 3644
// Not AC: TLE

#include <bits/stdc++.h>

#include <iostream>
using namespace std;
#define rep(i, n) for (int i = 0; i < (n); i++)
using ll = long long;

#define MAX_A 1000000

int main() {
  int n;
  cin >> n;
  vector<int> lst_a(n);
  rep(i, n) cin >> lst_a[i];

  vector<int> lst_b(MAX_A);
  rep(i, MAX_A) lst_b[i] = 0;

  rep(i, lst_a.size()) {
    int a = lst_a[i];
    for (int j = a; j <= MAX_A; j += a) {
      if (j == a) {
        lst_b[a]++;
        if (lst_b[a] > 1) {
          break;
        }
      } else {
        lst_b[j]++;
      }
    }
  }

  int ans = 0;
  rep(i, lst_a.size()) if (lst_b[lst_a[i]] == 1) ans++;
  cout << ans << endl;
  return 0;
}


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

int main()
{
	int all[200];

	int N, M;
	cin >> N;
	int *NTime = new int[N];

	for (int i = 0; i < N; i++) {
		int h, m;
		cin >> h >> m;
		NTime[i] = h * 60 + m;
		all[i] = NTime[i];
	}

	cin >> M;
	int *MTime = new int[M];

	for (int i = 0; i < M; i++) {
		int h, m;
		cin >> h >> m;
		MTime[i] = h * 60 + m;
		all[N + i] = MTime[i];
	}

	int n = M + N;
	
	for(int i=0; i<n; i++){
		for (int j = 0; j < n; j++)
			if (all[i] < all[j]) {
				int tmp = all[j];
				all[j] = all[i];
				all[i] = tmp;
			}
	}
	
	for (int i = 0; i < n; i++) {
		if (i != 0) {
			if (all[i] == all[i - 1])
				continue;
			cout << ' ';
		}

		if ((all[i] % 60) < 10)
			cout << all[i] / 60 << ":" <<'0'<< (all[i] % 60);
		else
			cout << all[i] / 60 << ':' << (all[i] % 60);
	}
	cout << endl;
	return 0;

}

Measured memory_bytes: 3084
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define debug(x) cerr << __LINE__ << " : " << #x << " = " << (x) << endl;
#define REP(i,n) for(int i=0;i<(int)(n);i++)
#define FOR(i,a,b) for(int i=(int)(a);i<(int)(b);i++)
#define FORR(i,a,b) for(int i=(int)(b)-1;i>=(int)(a);i--)
#define CHMIN(a,b) (a) = min((a),(b))
#define CHMAX(a,b) (a) = max((a),(b))

int main()
{
    int n,r;
    int p,c;
    int move[55]={};
    int keep[55]={};
    while(1==1)
    {
        scanf("%d %d\n",&n,&r);
        REP(i,n)move[i]=n-i;
        if(n==0 && r==0)break;
        REP(i,r)
        {
            scanf("%d %d\n",&p,&c);
            REP(j,n)keep[j]=move[j];
            REP(j,c)move[j]=keep[j+p-1];
            for(int j=c;j<c+p-1;j++)move[j]=keep[j-c];
            //REP(j,n)printf("%d ",move[j]);
            //printf("###\n");
        }
        printf("%d\n",move[0]);
    }
    return 0;
}


Measured memory_bytes: 3184
import java.util.*;

class Main{
  public static void main(String args[]) {
    Scanner sc = new Scanner(System.in);
    int n = sc.nextInt();
    int c[] = new int[n];
    int v[] = new int[n];
    for (int i = 0; i < n; i++)
      c[i] = sc.nextInt();
    for (int i = 0; i < n; i++)
      v[i] = sc.nextInt();

    int ans = 0;
      for (int i = 0; i < n; i++)
        if (c[i] > v[i])
          ans += c[i] - v[i];
    System.out.println(ans);
  }
}


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

using namespace std;

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

    int a,fives=0,sevens=0;

    for(int i=0;i<3;i++){
        cin>>a;
        if(a==5){
            fives++;
        }

        if(a==7){
            sevens++;
        }
    }

    if(fives==2 & sevens==1){
        cout<<"YES\n";
    }
    else{
        cout<<"NO\n";
    }


    return 0;
}


Measured memory_bytes: 256
n, a, b = list(map(int, input().split()))
#min > max n == 0
if a > b or n == 0:
    print(0)
    exit()
#n = 1 and  min != max
if n == 1 and  a != b :
    print(0)
    exit()
print((a + b * (n - 1)) - (a * (n - 1) + b) + 1)

Measured memory_bytes: 3060
N,M,X = map(int,input().split())
C = []
A = []
for n in range(N):
    temp = [int(i) for i in input().split()]
    C.append(temp[0])
    A.append(temp[1:])
import numpy as np
np_A = np.array(A)
min_cost = 10**9
if np.all(np_A.sum(axis=0) >= X):
    for i in range(2**N):
        P = str(bin(i)).replace("0b","").zfill(N)
        score = np.zeros(M)
        cost = 0
        for j,p in enumerate(P):
            if p == "1":
                cost += C[j]
                score += np_A[j]
        if np.all(score >= X):
            min_cost = min(min_cost,cost)
    print(min_cost)
else:
    print(-1)


Measured memory_bytes: 27172
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int n;
    scanf("%d",&n);
    vector<long long>a(n);
    for(int i=0;i<n;i++)
    {
        scanf("%lld",&a[i]);
    }
    long long dp[n+1][n+1];
    for(int L=n-1;L>=0;L--)
    {
        for(int R=0;R<n;R++)
        {
            if(L==R)
            {
                dp[L][R]=a[L];
            }
            else
            {
                dp[L][R]=max(a[L]-dp[L+1][R],a[R]-dp[L][R-1]);
            }
        }
    }
    cout<<dp[0][n-1]<<endl;
}

Measured memory_bytes: 70656
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, a, b) for (int i = a; i < (int)(b); i++)
#define all(v) v.begin(), v.end()
const int MOD = 1e9 + 7;
const int INF = 1e9;
//'A' = 65, 'Z' = 90, 'a' = 97, 'z' = 122

int main() {
    int n, m;
    cin >> n >> m;
    vector<vector<int>> g(n);
    rep(i, 0, m) {
        int a, b;
        cin >> a >> b;
        a--;
        b--;
        g[a].push_back(b);
        g[b].push_back(a);
    }
    int ans = 0;
    bool visited[n] = {};
    rep(i, 0, n) {
        if (visited[i]) continue;
        queue<int> que;
        que.push(i);
        visited[i] = true;
        int cnt = 1;
        while (!que.empty()) {
            int v = que.front();
            que.pop();
            for (int nv : g[v]) {
                if (visited[nv]) continue;
                visited[nv] = true;
                que.push(nv);
                cnt++;
            }
        }
        ans = max(ans, cnt);
    }
    cout << ans << endl;
    return 0;
}


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

int main() {
  int n, k, x, y;
  cin >> n;
  cin >> k;
  cin >> x;
  cin >> y;

  if (n <= k) {
    cout << x * n << endl;
  }

  else {
    cout << x * k + y * (n - k) << endl;
  }
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
constexpr long long MOD = 1000000007;
constexpr long long INF = 1LL << 60;
const long double PI = acosl(-1.0);
constexpr long double EPS = 1e-11;
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 main(){
    ll h, w;
    cin >> h >> w;
    string grid[h];
    for (ll i = 0; i < h; i++) cin >> grid[i];
    ll dx[8] = {1, 1, 1, -1, -1, -1, 0, 0};
    ll dy[8] = {0, 1, -1, 0, -1, 1, 1, -1};
    vector<string> ans(h);
    for (ll i = 0; i < h; i++) {
        for (ll j = 0; j < w;j++){
            ll cnt = 0;
            if (grid[i][j] == '#') {
                ans[i].push_back('#');
                continue;
            }
            for (ll k = 0; k < 8; k++) {
                ll newx = j + dx[k];
                ll newy = i + dy[k];
                if (newx >= w || newx < 0 || newy >= h || newy < 0) continue;
                if (grid[newy][newx] == '#') cnt++;
            }
            ans[i].push_back(cnt + '0');
        }
    }
    for (ll i = 0; i < h; i++) cout << ans[i] << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define REP(i, a, n) for(int i = ((int) a); i < ((int) n); i++)
typedef pair<int, int> pii;

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

int main(void) {
  while(cin >> N, N) {
    int minx = 0, maxx = 1;
    int miny = 0, maxy = 1;
    vector<pii> v;
    v.push_back(pii(0, 0));
    REP(i, 0, N - 1) {
      int n, d;
      cin >> n >> d;
      int nx = v[n].first + dx[d];
      int ny = v[n].second + dy[d];
      minx = min(minx, nx);
      maxx = max(maxx, nx + 1);
      miny = min(miny, ny);
      maxy = max(maxy, ny + 1);
      v.push_back(pii(nx, ny));
    }
    cout << (maxx - minx) << " " << (maxy - miny) << endl;
  }
}

Measured memory_bytes: 2992
S = input()
t = S[0]
cnt = 0
bol = 0
for i in range(1,len(S)):
    if bol == 1:
        bol = 0
        continue
    if S[i] == t:
        t = 0
        cnt += 1
        bol = 1
    else:
        t = S[i]
print(len(S)-cnt)

Measured memory_bytes: 9264
n,m = map(int, input().split()) #n person, m pieces
 
counter = []
ans = 0
for i in range(m):
  counter.append(0)
 
for i in range(n):
  ls = list(map(int, input().split()))
  kazu = ls[0]
  for i in range(1, kazu+1):
    num = counter[ls[i] - 1]
    counter[ls[i]-1] = num + 1
for i in range(m):
  if counter[i] == n:
    ans += 1
print(ans)
 

Measured memory_bytes: 3064
n, m, x, y = map(int, input().split())
target_x = list(map(int, input().split()))
target_y = list(map(int, input().split()))

mx = max(target_x)
my = min(target_y)

if mx < my and x < my <= y:
  print('No War')
else:
  print('War')



Measured memory_bytes: 2940
#include<bits/stdc++.h>
#define ll long long
using namespace std;
ll f[10000050],n;
int main(){
	cin >> n;
	for(ll i=1; i<=n; i++){
		for(ll j=i; j<=n; j+=i){
			f[j]++;
		}
	}
	ll cnt=0;
	for(ll i=1; i<=n; i++){
		cnt+=i*f[i];
	}
	cout << cnt << endl;
}

Measured memory_bytes: 81744
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define REP(i, n)    for (ll (i) = 0;   (i) < (n); ++(i))
#define FOR(i, a, b) for (ll (i) = (a); (i) < (b); ++(i))

template<typename T> vector<T> make_v(size_t a) { return vector<T>(a); }
template<typename T, typename... Ts> auto make_v(size_t a, Ts... ts) { return vector<decltype(make_v<T>(ts...))>(a, make_v<T>(ts...)); }
template<typename T, typename U, typename... V> enable_if_t<is_same<T, U>::value != 0> fill_v(U &u, const V... v) { u = U(v...); }
template<typename T, typename U, typename... V> enable_if_t<is_same<T, U>::value == 0> fill_v(U &u, const V... v) { for (auto &e : u) fill_v<T>(e, v...); }

const int INF = 1 << 30;
const int dx[] = { 1, 0, -1,  0 };
const int dy[] = { 0, 1,  0, -1 };
enum {D, R, U, L};

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

int H, W, K;
int x_1, y_1, x_2, y_2;

struct P {
    int cst, rst;   // [何回水かきしたか, あと何回ノーコストで動けるか]
    P(int cst = 0, int rst = 0) : cst(cst), rst(rst) {}
    bool operator<(const P &p) const {
        if (cst != p.cst) return cst < p.cst;
        return rst > p.rst;
    }
};

signed main() {

    cin >> H >> W >> K;
    cin >> x_1 >> y_1 >> x_2 >> y_2;
    --x_1, --y_1, --x_2, --y_2;
    vector<string> board(H);
    REP(i, H) cin >> board[i];

    auto dist = make_v<P>(H, W, 4);
    fill_v<P>(dist, P(INF, INF));
    REP(i, 4) dist[x_1][y_1][i] = P(0, 0);

    using T = pair<P, tuple<int, int, int>>;
    priority_queue<T, vector<T>, greater<T>> pq;
    REP(i, 4) pq.emplace(T(P(0, 0), make_tuple(x_1, y_1, i)));

    while (not pq.empty()) {
        auto [p, q] = pq.top(); pq.pop();
        auto [cst, rst] = p;
        auto [x, y, d] = q;
        // 方向転換
        REP(i, 4) if (i != d) {
            P nxt(cst + 1, K);
            if (chmin(dist[x][y][i], nxt)) {
                pq.emplace(T(nxt, make_tuple(x, y, i)));
            }
        }
        // その方向に直進
        P nxt(cst, rst - 1);
        if (nxt.rst < 0) {
            nxt.cst++;
            nxt.rst = K - 1;
        }
        int nx = x + dx[d];
        int ny = y + dy[d];
        if (nx < 0 or nx >= H or ny < 0 or ny >= W or board[nx][ny] == '@') continue;
        if (chmin(dist[nx][ny][d], nxt)) {
            pq.emplace(T(nxt, make_tuple(nx, ny, d)));
        }
    }

    int res = INF;
    REP(i, 4) chmin(res, dist[x_2][y_2][i].cst);
    if (res > INF / 2) res = -1;
    cout << res << endl;

}


Measured memory_bytes: 144852
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner scan = new Scanner(System.in);
		int n = scan.nextInt();
		int m = scan.nextInt();
		int x = scan.nextInt();
		int[] a = new int[m];
		int i = 0;
		for(i = 0; i < m; i++) {
			a[i] = scan.nextInt();
		}
		int cost_0 = 0;
		int cost_n = 0;
		int[] s = new int[n + 1];
		for(i = 0; i < n + 1; i++) {
			s[i] = 0;
		}
		for(i = 0; i < m; i++) {
			s[a[i]] = 1;
		}
		for(i = x; i != 0; i--) {
			cost_0 = cost_0 + s[i];
		}
		for(i = x; i != n; i++) {
			cost_n = cost_n + s[i];
		}
		if(cost_0 <= cost_n) {
			System.out.println(cost_0);
		} else {
			System.out.println(cost_n);
		}
	}
}

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

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

  if (s < t) printf("Yes\n");
  else printf("No\n");

  return 0;
}


Measured memory_bytes: 256
#include <iostream>
using namespace std;
int main(){
	int y,m,d;
	while(cin >> y >> m >> d){
		int w = y*10000 + m*100 + d;
		if(w<18680908) cout << "pre-meiji" << endl;
		else if(w<19120730) cout << "meiji " << y-1867 << " " << m << " " << d << endl;
		else if(w<19261225) cout << "taisho " << y-1911 << " " << m << " " << d << endl;
		else if(w<19890108) cout << "showa " << y-1925 << " " << m << " " << d << endl;
		else cout << "heisei " << y-1988 << " " << m << " " << d << endl;
	}
}

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

#define REP(i,n) for(int i = 0;i < n;++i)
#define REPS(i,x) for(int i = 1;i <= (int)(x);i++)
#define RREP(i,x) for(int i=((int)(x)-1);i >= 0;i--)
#define RREPS(i,x) for(int i=((int)(x));i > 0;i--)
#define PB push_back
#define F first
#define S second
#define MP make_pair
#define ALL(obj) (obj).begin(),(obj).end()
#define debug(x) cerr << #x << ": " << x << "\n"

int main(){

    char s;
    cin >> s;

    if(isupper(s)){
        cout << "A" << endl;
    }else{
        cout << "a" << endl;
    }


    
    return 0;
}

Measured memory_bytes: 3620
#include <bits/stdc++.h>
#define debug(...)
#include <complex.h>
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<vi> vvi;


int32_t main() {
    ios::sync_with_stdio(false); cin.tie(0);
    int n;
    cin >> n;
    ll  S = 0;
    vl a(n);
    for(int i = 0; i < n; i++){
        cin >> a[i];
        S += a[i];
    }
    ll nw = 0;
    ll ans = (ll)1e18;
    for(int i = 0; i < n - 1; i++){
        nw += a[i];
        ll other = S - nw;
        ans = min(ans , abs(other - nw));

    }
    cout << ans << '\n';


    return 0;
}













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

int main(){
	int n;
	cin >> n;
	int count[5][4][11];
	for (int i = 0; i < 5; i++){
		for (int j = 0; j < 4; j++){
			for (int k = 0; k < 11; k++){
				count[i][j][k] = 0;
			}
		}
	}
	for (int i = 1; i <= n; i++){
		int b, f, r, v;
		cin >> b >> f >> r >> v;
		count[b][f][r] += v;
	}

	for (int i = 1; i <= 4; i++){
		for (int j = 1; j <= 3; j++){
			for (int k = 1; k <= 10; k++){
				cout << " "<<count[i][j][k] ;
			}
			cout << endl;
		}
		if (i < 4) cout << "####################"<<endl;
	}

	return 0;
	}


Measured memory_bytes: 3100
import heapq

X, Y, A, B, C = map(int, input().split())
p = list(map(lambda x:int(x)*(-1), input().split()))
q = list(map(lambda x:int(x)*(-1), input().split()))
r = list(map(lambda x:int(x)*(-1), input().split()))
heapq.heapify(p)
heapq.heapify(q)

for _ in range(X):
    r.append(heapq.heappop(p))
for _ in range(Y):
    r.append(heapq.heappop(q))
heapq.heapify(r)

ans = 0
for _ in range(X+Y):
    ans += (-1) * heapq.heappop(r)
print(ans)


Measured memory_bytes: 120488
#include<stdio.h>
#include<iostream>
#include<string.h>
#include<string>
#include<ctype.h>
#include<math.h>
#include<set>
#include<map>
#include<vector>
#include<queue>
#include<bitset>
#include<algorithm>
#include<time.h>
using namespace std;
void fre() { freopen("c://test//input.in", "r", stdin); freopen("c://test//output.out", "w", stdout); }
#define MS(x, y) memset(x, y, sizeof(x))
#define ls o<<1
#define rs o<<1|1
typedef long long LL;
typedef unsigned long long UL;
typedef unsigned int UI;
template <class T1, class T2>inline void gmax(T1 &a, T2 b) { if (b > a)a = b; }
template <class T1, class T2>inline void gmin(T1 &a, T2 b) { if (b < a)a = b; }
const int N = 0, M = 0, Z = 1e9 + 7, inf = 0x3f3f3f3f;
template <class T1, class T2>inline void gadd(T1 &a, T2 b) { a = (a + b) % Z; }
int casenum, casei;
int n;
map<int, int>mop;
int A, B;
int main()
{
	while (~scanf("%d", &n))
	{
		mop.clear();
		for (int i = 1; i <= n; ++i)
		{
			int x;
			scanf("%d", &x);
			++mop[x];
		}
		A = B = 0;
		for (auto it : mop)
		{
			if (it.second >= 2)
			{
				if (it.first > B)
				{
					B = it.first;
					if (B > A)swap(A, B);
				}
				if (it.second >= 4)
				{
					if (it.first > B)
					{
						B = it.first;
						if (B > A)swap(A, B);
					}
				}
			}
		}
		LL ans = (LL)A * B;
		printf("%lld\n", ans);
	}
	return 0;
}

Measured memory_bytes: 4992
import java.util.Scanner;

public class Main{
	public static void main(String[] args) {
		Scanner scan = new Scanner(System.in);
		
		int[] dice = new int[6];
        for(int i=0; i<6; i++) {
        	 dice[i] = scan.nextInt();		//６面
        }
        
        int num = scan.nextInt();
        for(int i=0; i<num; i++) {
        	
        	int up = scan.nextInt();
        	int front = scan.nextInt();
        	
        	if((up==dice[1]&&front==dice[2])||(up==dice[3]&&front==dice[1])||(up==dice[4]&&front==dice[3])||(up==dice[2]&&front==dice[4])) {
    			System.out.println(dice[0]);
    			
        	}else if((up==dice[0]&&front==dice[3])||(up==dice[2]&&front==dice[0])||(up==dice[5]&&front==dice[2])||(up==dice[3]&&front==dice[5])) {
        			System.out.println(dice[1]);
        			
        	}else if((up==dice[0]&&front==dice[1])||(up==dice[4]&&front==dice[0])||(up==dice[5]&&front==dice[4])||(up==dice[1]&&front==dice[5])) {
            			System.out.println(dice[2]);
            			
        	}else if((up==dice[0]&&front==dice[4])||(up==dice[1]&&front==dice[0])||(up==dice[5]&&front==dice[1])||(up==dice[4]&&front==dice[5])) {
    			System.out.println(dice[3]);
    			
        	}else if((up==dice[0]&&front==dice[2])||(up==dice[3]&&front==dice[0])||(up==dice[5]&&front==dice[3])||(up==dice[2]&&front==dice[5])) {
    			System.out.println(dice[4]);
    			
        	}else 
    			System.out.println(dice[5]);
        }


	}
}


Measured memory_bytes: 25924
n, k = map(int,input().split())
ans_list = [0 for i in range(n)]

for i in range(k):
    d = int(input())
    a = list(map(int,input().split()))
    for j in a:
        ans_list[j-1] = 1

ans = 0

for i in ans_list:
    if i == 0:
        ans += 1

print(ans)


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

int main(){
  int A,B,C;
  cin >> A >> B >> C;

  bool ans = false;
  if(A==B && B!=C) ans=true;
  else if(B==C && C!=A) ans=true;
  else if(C==A && A!=B) ans=true;

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

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

#define sws ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define ll long long
#define vi vector<int>
#define pb push_back
#define pii pair<int, int>
#define mp make_pair
#define ff first
#define ss second
#define vvi vector<vi>
#define all(x) x.begin(), x.end()
#define fo(i, n) for( int i = 0; i < n; i++ )

const int INF = 1e9;
const ll INFLL = 0x3f3f3f3f3f3f3f3f;
const int MOD = 1e9 + 7;


int main() {

    int r, g, b, n;
    cin >> r >> g >> b >> n;
    int ans = 0;

    for ( int red = n / r; red >= 0; red-- ) {
        for( int green = 0; ; green++ ) {
            if ( red * r + green * g > n ) break;
            for ( int blue = 0; ; blue++ ) {
                if ( red * r + green * g + blue * b > n ) break;
                if ( red * r + green * g + blue * b == n ) {
                    ans++;
                    break;
                }
            }
        }
    }

    cout << ans << endl;

    return 0;
}

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

#define rep(i,n) for(int i = 0; i < (n); i++)

using namespace std;

int main(){
  int x;
  cin>>x;
  
  if(x<1200){
    cout<<"ABC";
  }else{
    cout<<"ARC";
  }
  return 0;
}


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

using namespace std;

int64_t N, A, B;

int64_t div_(int64_t a, int64_t b) {
  if (a <= 0)
    return 0;

  if (a % b == 0)
    return a / b;
  else
    return a / b + 1;
}

bool is_ok(const vector<int64_t> &hs, int64_t count) {

  int64_t s = 0;

  for (auto h : hs) {
    s += div_(h - B * count, A - B);
  }

  return s <= count;
}

int64_t attacks(const vector<int64_t> &hs) {

  int64_t ok = 1000000000;
  int64_t ng = 0;

  while (1 < ok - ng) {
    int64_t mid = (ok + ng) / 2;

    if (is_ok(hs, mid))
      ok = mid;
    else
      ng = mid;
  }

  return ok;
}

int main() {

  cin >> N >> A >> B;
  vector<int64_t> hs;
  hs.reserve(N);

  for (int64_t i = 0; i < N; ++i) {
    int64_t h;
    cin >> h;
    hs.push_back(h);
  }

  cout << attacks(hs) << endl;

  return 0;
}


Measured memory_bytes: 1024
// clang-format off
#include <bits/stdc++.h>
#define int long long
#define main signed main()
// #define main int main()
#define loop(i, a, n) for (int i = (a); i < (n); i++)
#define rep(i, n) loop(i, 0, n)
#define all(v) (v).begin(), (v).end()
#define rall(v) (v).rbegin(), (v).rend()
#define prec(n) fixed << setprecision(n)
#define stlice(from, to) substr(from, (to) - (from) + 1)
#define pb push_back
#define mp make_pair
#define mt make_tuple
#define fi first
#define se second
using namespace std;
using pii = pair<int, int>;
using vi = vector<int>;
using vd = vector<double>;
using vc = vector<char>;
using vb = vector<bool>;
using vs = vector<string>;
using vpii = vector<pii>;
using vvi = vector<vi>;
using vvb = vector<vb>;
using vvpii = vector<vpii>;
template<typename A> using fn = function<A>;
constexpr int INF = sizeof(int) == sizeof(long long) ? 1000000000000000000LL : 1000000000;
constexpr int MOD = 1000000007;
constexpr double PI = acos(-1);
template<typename A, typename B> bool cmin(A &a, const B &b) { return a > b ? (a = b, true) : false; }
template<typename A, typename B> bool cmax(A &a, const B &b) { return a < b ? (a = b, true) : false; }
constexpr bool odd(const int &n) { return n & 1; }
constexpr bool even(const int &n) { return !odd(n); }
template<typename V> constexpr typename V::value_type sum(const V &v) { return accumulate(all(v), 0); }
void solve();
main { solve(); return 0; }
// clang-format on

void solve() {
  double x, h;
  while (cin >> x >> h, x) {
    cout << prec(8) << x * x + x * hypot(h, x / 2) * 2 << endl;
  }
}

Measured memory_bytes: 3324
def main():
    n = int(input())
    hs = [int(x) for x in input().split()]
    count = 0
    for i in range(n):
        if i == 0:
            count += 1
        elif max(hs[:i]) <= hs[i]:
            count += 1
    print(count)

if __name__ == '__main__':
    main()


Measured memory_bytes: 2940
#include <algorithm>
#include <cassert>
#include <climits>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <list>
#include <map>
#include <memory>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>
/* #include <regex> */

using namespace std;

/* g++ -g -std=c++11 */

/* freopen("input.txt", "rt", stdin); */
/* freopen("output.txt", "wt", stdout); */

#define ALL(c)          (c).begin(), (c).end()
#define ALLR(c)         (c).rbegin(), (c).rend()
#define FOR(i,a,b)      for (int i=(a); i < (b); ++i)
#define FORR(i,a,b)     for (int i=(a); i > (b); --i)
#define FOR_ALL(i,c)    for (__typeof((c).begin()) i=(c).begin();   \
                             i != (c).end(); ++i)
#define FOR_ALLR(i,c)   for (__typeof((c).rbegin()) i=(c).rbegin(); \
                             i != (c).rend(); ++i)
#define SZ(array)       (sizeof(array)/sizeof(array[0]))
#define lc(x)           (x<<1)     /* 2*x */
#define rc(x)           (x<<1 | 1) /* 2*x+1 */
#define lowbit(x)       (x & (-x)) /* 0b10100 -> 0b100 */

typedef long long       LL;
typedef map<int,int>    MII;
typedef pair<int,int>   PII;
typedef set<int>        SI;
typedef vector<bool>    VB;
typedef vector<double>  VD;
typedef vector<int>     VI;
typedef vector<string>  VS;

/* check if a key is in container C */
template <class C>
inline bool in_(const typename C::key_type& k, const C& A)
{ return A.find(k) != A.end(); }
inline bool in_(const string& s, const string& S)
{ return S.find(s) != string::npos; }

const int maxn = 1e5;
int A[maxn], B[maxn];

int main()
{
#ifdef foo_
    freopen("foo", "rt", stdin);
#endif
    ios::sync_with_stdio(false);
    int n;
    while (cin >> n) {
        FOR(i,0,n)
            cin >> A[i];
        FOR(i,0,n)
            cin >> B[i];
        int i = 0, j = 0;
        for (; j < n; ) {
            if (A[j] > B[j]) {
                while (i < n && B[i]-A[i] <= 1)
                    i++;
                if (i == n)
                    break;
                const int x = (B[i]-A[i])/2;
                const int d = min(x,A[j]-B[j]);
                B[j] += d;
                A[i] += 2*d;
                if (A[j] == B[j])
                    j++;
            }
            else
                j++;
        }
        if (j == n)
            cout << "Yes" << endl;
        else
            cout << "No" << endl;
    }
    return 0;
}


Measured memory_bytes: 384
#include <bits/stdc++.h>
using namespace std;
#pragma GCC optimize("O0")
typedef long long int ll;
typedef long double ld;
const ll mod = 1e9+7;
const ll INF = 1e18;
#define rep(i,n) for (ll i = 0; i < (n); ++i)
#define Rep(i,a,n) for (ll i = (a); i < (n); ++i)
#define All(a) (a).begin(),(a).end()
#define Pi acos(-1)
using Graph = vector<vector<ll>>;
using V = vector<ll>;
using P = pair<ll,ll>;

int main() {
  cin.tie(0);
  ios_base::sync_with_stdio(false);
  cout << setprecision(15) << fixed;
  chrono::system_clock::time_point start,end;
  start = chrono::system_clock::now();

  ll n;
  cin >> n;
  V a(n);
  rep(i,n) cin >> a[i];
  V d(n+1);
  rep(i,n-1) {
    d[i+1] = min(d[i]+abs(a[i+1]-a[i]), d[i-1]+abs(a[i+1]-a[i-1]));
  }
  cout << d[n-1] << '\n';

  end = chrono::system_clock::now();
  auto elapsed = chrono::duration_cast< chrono::milliseconds >(end - start).count();
  cerr << elapsed << "ms" << '\n';
}

Measured memory_bytes: 4812
#include <iostream>
using namespace std;
#define rep(i,q) for(int i = 0; (q) > i; i++)
int main(){
  long long a[100003];
  rep(i,100001)a[i] = 0;
  long long N,K;cin>>N>>K;
  rep(i,N){
    long long tmp,tmp2;cin>>tmp>>tmp2;
    a[tmp] += tmp2; 
  }
  long long sm;
  rep(i,100001){
    sm+=a[i];
    if(sm >= K){
      cout << i << endl;
      break;
    }
  }
}

Measured memory_bytes: 1024
//#pragma GCC optimize("-Ofast","unroll-loops","omit-frame-pointer","inline") //Optimization flags
//#pragma GCC option("arch=native","tune=native","no-zero-upper") //Enable AVX
//#pragma GCC target("avx2")  //Enable AVX
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>

using namespace __gnu_pbds;
using namespace std;
typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;
typedef tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update> indexed_set;
//order_of_key(x) : number of items less than x
//find_by_order(x) : iterator to x

#define mem(dp,a)           memset(dp,a,sizeof dp)
#define rep(i,a,b)          for(ll i=a;i<b;i++)
#define pb(x)               push_back(x)
#define mp(x,y)             make_pair(x,y)
#define fastio              ios_base::sync_with_stdio(false);cin.tie(NULL)
#define F                   first
#define S                   second
#define all(v)              (v).begin(),(v).end()

const ld pi=3.14159265359;
ll INF=1e18+10;
ll MOD=998244353;
ll mod=1e9+7;

inline ll add(ll a,ll b,ll m){
    if((a+b)>=m)return (a+b)%m;
    return a+b;
}

inline ll mul(ll a,ll b,ll m){
    if((a*b)<m)return a*b;
    return (a*b)%m;
}

int main()
{
    //freopen("in.txt","r",stdin);
    //freopen("out.txt","w",stdout);
    ll n;cin>>n;
    set<string> ss;
    rep(i,0,n){
        string s;cin>>s;
        ss.insert(s);
    }
    cout<<ss.size();
}

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

typedef long long ll;

bool a[10]={};

int main() {
	// your code goes here
	int i, j, n, m, k;
	cin>>n>>k;
	for(i=0; i<k; ++i) {
		cin>>j;
		a[j]=true;
	}
	while(1) {
		bool flag=true;
		int m=n;
		while(m) {
			if(a[m%10]) {
				flag=false;
				break;
			}
			m/=10;
		}
		if(flag) {
			cout<<n;
			return 0;
		}
		n++;
	}
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define PI 3.14159265358979323846
#define MAXINF (1e18L)
#define INF (1e9L)
#define EPS (1e-9)
#define MOD ((ll)(1e9+7))
#define REP(i, n) for(int i=0;i<int(n);++i)
#define Rep(i,sta,n) for(int i=sta;i<n;i++)
#define RREP(i, n) for(int i=int(n)-1;i>=0;--i)
#define ALL(v) v.begin(),v.end()
#define FIND(v,x) (binary_search(ALL(v),(x)))
#define SORT(v) sort(ALL(v))
#define RSORT(v) sort(ALL(v));reverse(ALL(v))
#define DEBUG(x) cerr<<#x<<": "<<x<<endl;
#define DEBUG_VEC(v) cerr<<#v<<":";for(int i=0;i<v.size();i++) cerr<<" "<<v[i]; cerr<<endl
#define Yes(n) cout<<((n)?"Yes":"No")<<endl
#define YES(n) cout<<((n)?"YES":"NO")<<endl
#define pb push_back
#define fi first
#define se second
using namespace std;
template<class A>void pr(A a){cout << (a) << endl;}
template<class A,class B>void pr(A a,B b){cout << a << " "  ;pr(b);}
template<class A,class B,class C>void pr(A a,B b,C c){cout << a << " " ;pr(b,c);}
template<class A,class B,class C,class D>void pr(A a,B b,C c,D d){cout << a << " " ;pr(b,c,d);}
template<class T> inline bool chmin(T& a, T b){return a>b ? a=b, true : false;}
template<class T> inline bool chmax(T& a, T b){return a<b ? a=b, true : false;}
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll,ll> pll;

int main(void)
{
    int N,K;
    cin >> N >> K;
    vector<int> x(K);
    for (int i = 0; i < K; i++) {
        cin >> x[i];
    }
    // vector<int> x;
    // REP(i, 10){
    //     if(!FIND(D, i)) x.pb(i);
    // }

    int ans = INF;
    while(1){
        vector<int> y;
        int n = N;
        while(n/10){
            y.pb(n%10);
            n/=10;
        }
        y.pb(n);

        bool f = true;
        REP(i, x.size()){
            REP(j, y.size()){
                if(x[i] == y[j]){
                    f = false;
                    break;
                }
            }
        }
        if(f){
            pr(N);
            return 0 ;
        }
        N++;
    }
}

Measured memory_bytes: 256
#include <stdio.h>

int main(void){
    int A,B,C,D,E,sum;
    scanf("%d%d%d%d%d",&A,&B,&C,&D,&E);
    A<0?(sum=(0-A)*C+D+B*E):(sum=(B-A)*E);
    printf("%d\n",sum);
    return 0;
}

Measured memory_bytes: 596
#include<iostream>
using namespace std;
int calccounts(int n1,int n2,int tot,int num)
{
	int count=0;
	if (num==1){
		if (tot>=n1 && tot<=n2)
		   return 1;
		else
		   return 0;
	}
	else{
		if (tot<num*n1+num*(num-1)/2 || tot>num*n2-num*(num-1)/2 || n2-n1+1<num)
			return 0;
		else{
			for(int i=n1+1;i<=n2;i++)
			    count+=calccounts(i,n2,tot-i+1,num-1);
			return count;
		}
		
	}
}

int main()
{
	int n,x;
	do{
		cin>>n>>x;
		if (n==0 && x==0)
			break;
		cout<<calccounts(1,n,x,3)<<endl;
	} while(1);
	
	return 0;
}


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

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  int N;
  cin >> N;
  vector<int> a(N);
  REP(i, N) cin >> a[i];
  int ans = 0;
  for(int i = 1; i < N; i++) {
    if(a[i - 1] == a[i]) {
      a[i] = 0;
      ans++;
    }
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <algorithm>
#include <functional>
#include <vector>
#include <stack>
#include <queue>
#include <deque>
#include <set>
#include <map>
#include <cstdio>
#include <cmath>
#include <tuple>
#include <iomanip>
#include <numeric>
#include <unordered_map>
#include <sstream>   
#include<limits.h>
#include<float.h>
#include<list>
#include <array>
#include <complex>
#include<stdio.h>
#include<string.h>
#include <bitset>

using namespace std;
#define int  long long

#define I32_MAX 2147483647
#define I64_MAX 9223372036854775807LL
#define I64_MAX2 1223372036854775807LL
#define INF I64_MAX2
#define MOD 1000000007
#define MEM_SIZE 10000
#define DEBUG_OUT true
#define ALL(x) (x).begin(),(x).end()


template<typename T> void DEBUG(T e){if(DEBUG_OUT == false)return; std::cout << e <<" ";}
template<typename T> void DEBUG(const std::vector<T>& v){if(DEBUG_OUT == false)return;for(const auto& e : v){std::cout<< e << " "; } std::cout << std::endl;}
template<typename T> void DEBUG(const std::vector<std::vector<T> >& vv){if(DEBUG_OUT == false)return;for(const auto& v : vv){ DEBUG(v); } }
template<class T,class... Ts> void DEBUG(T d, Ts... e){if(DEBUG_OUT == false)return;DEBUG(d);DEBUG(e...);}
template <class T> void corner(bool flg, T hoge) {if (flg) {cout << hoge << endl; exit(0);}}
template< typename T1, typename T2 > inline bool chmax(T1 &a, T2 b) { return a < b && (a = b, true); }
template< typename T1, typename T2 > inline bool chmin(T1 &a, T2 b) { return a > b && (a = b, true); }



map< int, int > prime_factor(int n) {
  map< int, int > ret;
  for(int i = 2; i * i <= n; i++) {
    while(n % i == 0) {
      ret[i]++;
      n /= i;
    }
  }
  if(n != 1) ret[n] = 1;
  return ret;
}


void solve(void)
{
  int N;cin>>N;
  map<int,int> PF;
  for (int i = 1; i <= N; i++)
  {
    auto X = prime_factor(i);
    for (auto &&i : X)
    {
      PF[i.first] += i.second;
    }
  }
  int P4 = 0, P2 = 0, P24 = 0, P14 = 0,P74 = 0;;
  for (auto &&i : PF)
  {
    if(i.second >= 74)P74++;
    if(i.second >= 24)P24++;
    if(i.second >= 14)P14++;
    if(i.second >= 4)P4++;
    if(i.second >= 2)P2++;
    // DEBUG(i.first,i.second,"\n");
  }
  // P2 += P4 -2 ;
  cout<<P74 + P24 *(P2 - 1) + P14*(P4 -1 ) + (P4)*(P4-1)/2*(P2 - 2)<<endl;
  
  
  return;
}
int32_t main(int32_t argc, const char *argv[])
{
std::ios::sync_with_stdio(false);
std::cin.tie(0);

std::cout << std::fixed;
std::cout << std::setprecision(9);
solve();

return 0;
}


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


int main() {
    
    int a, b, c, x;
    int count = 0;

    
    cin >> a >> b >> c >> x;
    
    for (int i = 0; i <= a; ++i) {
        for (int j = 0; j <= b; ++j) {
            for (int k = 0; k <= c; ++k){
                int price = 500*i + 100*j + 50*k;
                if (price == x) {
                    count++;
                }
            }
        }
    }
    cout << count << endl;
}

Measured memory_bytes: 256
import java.io.*;

class Main {
    public static void main (String[] args) throws Exception {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        int n;
        String[] points;
        int[] s;
        int i;
        double m;
        double a;

        while ((n = Integer.parseInt(br.readLine())) != 0) {
            points = br.readLine().split(" ");
            s = new int[n];

            m = 0;
            for (i = 0; i < n; i++) {
                s[i] = Integer.parseInt(points[i]);
                m += s[i];
            }
            m /= n;

            a = 0;
            for (i = 0; i < n; i++) {
                a += Math.pow(s[i] - m, 2);
            }

            System.out.println(Math.sqrt(a / n));
        }

    }
}

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

using namespace std;

int main(void) {
  int H, W; cin >> H >> W;
  string s[H];

  for (int i = 0; i < H; ++i) cin >> s[i];

  int rvn[H][W];
  memset(rvn, 0x7f, sizeof(rvn));

  for (int i = 0; i < H; ++i) {
    for (int j = 0; j < W; ++j) {
      if (i == 0 && j == 0) {
        if (s[i][j] == '.') {
          rvn[i][j] = 0;
        } else {
          rvn[i][j] = 1;
        }
      } else if (i == 0) {
        if (rvn[i][j-1] & 1) {
          rvn[i][j] = rvn[i][j-1] + (s[i][j] == '.' ? 1 : 0);
        } else {
          rvn[i][j] = rvn[i][j-1] + (s[i][j] == '#' ? 1 : 0);
        }
      } else if (j == 0) {
        if (rvn[i-1][j] & 1) {
          rvn[i][j] = rvn[i-1][j] + (s[i][j] == '.' ? 1 : 0);
        } else {
          rvn[i][j] = rvn[i-1][j] + (s[i][j] == '#' ? 1 : 0);
        }
      } else {
        rvn[i][j] = min(rvn[i-1][j] + (((rvn[i-1][j] & 1) == 1) == (s[i][j] == '.') ? 1 : 0),
                        rvn[i][j-1] + (((rvn[i][j-1] & 1) == 1) == (s[i][j] == '.') ? 1 : 0));
      }
    }
  }

  cout << rvn[H-1][W-1]/2 + rvn[H-1][W-1]%2 << endl;

  return 0;
}

Measured memory_bytes: 256
//Largest Rectangle
#include <iostream>
#include <algorithm>
#include <stack>
#include <vector>

using namespace std;

class Rectangle {
public:
    int pos, height;
    Rectangle(int pos, int height): pos(pos), height(height) {}
};

int largestRectangle(int h, int w, vector<vector<int>> &G) {
    vector<vector<int>> dp(h+1, vector<int>(w+1, 0));

    for(int i=1; i<h+1; i++) {
        for(int j=1; j<w+1; j++) {
            if(G[i][j] == 1) continue;
            dp[i][j] = dp[i-1][j]+1;
        }
    }

    int s = 0;
    stack<Rectangle> st;
    for(int i=1; i<h+1; i++) {
        for(int j=1; j<w+1; j++) {
            Rectangle rect = Rectangle(j, dp[i][j]);
            if(st.empty()) st.push(rect);
            else if(dp[i][j] > st.top().height) st.push(rect);
            else if(dp[i][j] < st.top().height) {
                int pos = j;
                while(!st.empty() && st.top().height > dp[i][j]) {
                    s = max(s, st.top().height * (j - st.top().pos));
                    pos = st.top().pos;
                    st.pop();
                }
                rect.pos = pos;
                st.push(rect);
            }
        }

        while(!st.empty()) {
            s = max(s, st.top().height * (w + 1 - st.top().pos));
            st.pop();
        }
    }

    return s;
}

int main() {
    int h, w;
    cin >> h >> w;

    vector<vector<int>> G(h+1, vector<int>(w+1, 1));
    for(int i=1; i<h+1; i++)
        for(int j=1; j<w+1; j++)
            cin >> G[i][j];

    cout << largestRectangle(h, w, G) << endl;

    return 0;
}



Measured memory_bytes: 18152
from functools import reduce
from fractions import gcd
import heapq
import queue
import math
import bisect
import itertools
import sys
sys.setrecursionlimit(10**7)
input = sys.stdin.readline
INF = float("inf")


def main():
    N, M = map(int, input().split())

    table = set()
    i = 1
    while i * i <= M:
        if M % i == 0:
            table.add(i)
            table.add(M//i)
        i += 1
    
    res = 1
    for p in table:
        if p * N <= M:
            res = max(res, p)
    
    print(res)


if __name__ == '__main__':
    main()

Measured memory_bytes: 64236
#include<bits/stdc++.h>
using namespace std;
int main(){
int a,b,c,d,i,j,k,l;

scanf("%d%d%d%d",&a,&b,&c,&d);
i=abs(a-c);
j=abs(b-d);
//printf("%d %d\n",i,j);
if(a<c&&b<d)
printf("%d %d %d %d\n",c-j,d+i,a-j,b+i);
if(a>c&&b>d)
printf("%d %d %d %d\n",c+j,d-i,a+j,b-i);
if(a<c&&b>d)
printf("%d %d %d %d\n",c+j,d+i,a+j,b+i);
if(a>c&&b<d)
printf("%d %d %d %d\n",c-j,d-i,a-j,b-i);
if(a==c&&b>d)
printf("%d %d %d %d\n",c+j,d+i,a+j,b+i);
if(a>c&&b==d)
printf("%d %d %d %d\n",c+j,d-i,a+j,b-i);
if(a<c&&b==d)
printf("%d %d %d %d\n",c+j,d+i,a+j,b+i);
if(a==c&&b<d)
printf("%d %d %d %d\n",c-j,d+i,a-j,b+i);
return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#pragma GCC target("avx")
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")
using namespace std;
#define rep(i, n)  for(long long i=0;i<(long long)(n);i++)
#define REP(i,k,n) for(long long i=k;i<(long long)(n);i++)
#define all(a) a.begin(),a.end()
#define pb emplace_back
#define eb emplace_back
#define lb(v,k) (lower_bound(all(v),k)-v.begin())
#define ub(v,k) (upper_bound(all(v),k)-v.begin())
#define fi first
#define se second
#define pi M_PI
#define PQ(T) priority_queue<T>
#define SPQ(T) priority_queue<T,vector<T>,greater<T>>
#define dame(a) {out(a);return 0;}
#define decimal cout<<fixed<<setprecision(15);
#define dupli(a) {sort(all(a));a.erase(unique(all(a)),a.end());}
typedef long long ll;
typedef pair<ll,ll> P;
typedef tuple<ll,ll,ll> PP;
typedef tuple<ll,ll,ll,ll> PPP;
typedef multiset<ll> S;
using vi=vector<ll>;
using vvi=vector<vi>;
using vvvi=vector<vvi>;
using vvvvi=vector<vvvi>;
using vp=vector<P>;
using vvp=vector<vp>;
using vb=vector<bool>;
using vvb=vector<vb>;
const ll inf=1001001001001001001;
const ll INF=1001001001;
const ll mod=1000000007;
const double eps=1e-10;
template<class T> bool chmin(T&a,T b){if(a>b){a=b;return true;}return false;}
template<class T> bool chmax(T&a,T b){if(a<b){a=b;return true;}return false;}
template<class T> void out(T a){cout<<a<<'\n';}
template<class T> void outp(T a){cout<<'('<<a.fi<<','<<a.se<<')'<<'\n';}
template<class T> void outvp(T v){rep(i,v.size())cout<<'('<<v[i].fi<<','<<v[i].se<<')';cout<<'\n';}
template<class T> void outvvp(T v){rep(i,v.size())outvp(v[i]);}
template<class T> void outv(T v){rep(i,v.size()){if(i)cout<<' ';cout<<v[i];}cout<<'\n';}
template<class T> void outvv(T v){rep(i,v.size())outv(v[i]);}
template<class T> bool isin(T x,T l,T r){return (l)<=(x)&&(x)<=(r);}
template<class T> void yesno(T b){if(b)out("yes");else out("no");}
template<class T> void YesNo(T b){if(b)out("Yes");else out("No");}
template<class T> void YESNO(T b){if(b)out("YES");else out("NO");}
template<class T> void noyes(T b){if(b)out("no");else out("yes");}
template<class T> void NoYes(T b){if(b)out("No");else out("Yes");}
template<class T> void NOYES(T b){if(b)out("NO");else out("YES");}
void outs(ll a,ll b){if(a>=inf-100)out(b);else out(a);}
ll gcd(ll a,ll b){if(b==0)return a;return gcd(b,a%b);}
ll modpow(ll a,ll b){ll res=1;a%=mod;while(b){if(b&1)res=res*a%mod;a=a*a%mod;b>>=1;}return res;}
#include<atcoder/all>
using namespace atcoder;

int main(){
    ll t;cin>>t;
    rep(tt,t){
        ll n,m,a,b;cin>>n>>m>>a>>b;
        out(floor_sum(n,m,a,b));
    }
}

Measured memory_bytes: 3668
h, w = map(int, input().split())

rets = 10000000000

for i in range(1, w):
    s1 = i * h
    s2 = (w - i) * (h // 2)
    s3 = w * h - s1 - s2
    diff = max(s1, s2, s3) - min(s1, s2, s3)
    if diff < rets:
        rets = diff

for j in range(1, h):
    s1 = j * w
    s2 = (h - j) * (w // 2)
    s3 = w * h - s1 - s2
    diff = max(s1, s2, s3) - min(s1, s2, s3)
    if diff < rets:
        rets = diff

for k in range(1, w):
    s1 = k * h
    s2 = ((w - k) // 2) * h
    s3 = w * h - s1 - s2
    diff = max(s1, s2, s3) - min(s1, s2, s3)
    if diff < rets:
        rets = diff

for l in range(1, h):
    s1 = l * w
    s2 = ((h - l) // 2) * w
    s3 = w * h - s1 - s2
    diff = max(s1, s2, s3) - min(s1, s2, s3)
    if diff < rets:
        rets = diff

print(rets)

Measured memory_bytes: 3064
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll mx = 1e7 + 7;

ll par[mx];
ll p_u, p_v;

ll find_parent(ll x) {
    if(x == par[x]) return x;

    //x er parent je, tar actual parent return korba
    return par[x] = find_parent(par[x]); //return korte hobe
}



void join(ll u, ll v) {

    p_u = find_parent(u);
    p_v = find_parent(v);

   if(p_u == p_v) return; //par[u] ashole u er set er parent na. 
                //find_parent(u) jei node ta return korbe, oita u er set er parent.
                //par array ta ei parent bair korte help kore.

   par[p_u] = p_v; //par[u] = p_v na. u er set er parent je, tar parent p_v diba.
                    //mane par[p_u] = p_v diba.
}

int main() {
    ll n, q;  cin >> n >> q;
    for(ll i = 0; i < n; i++) par[i] = i;

    while(q--) {
        ll t; cin >> t;
        if(t == 1) {
            ll u, v;  cin >> u >> v;
             p_u = par[u]; //no no
             p_v = par[v]; //no no

             //par[u] kintu u er parent na... 
             //not always
             //find_parent(u) dile actual u er parent ase
             //par[u] dile ekta node ashe, tar jodi arekta parent thake?
             //shetar jodi arekta thake?
             //erokom dada por dada hoia finally jei purbo purush
             //shei ashol parent
             //jeta bair kore find_parent(u) function ta.

             //so emon:
             p_u = find_parent(u), p_v = find_parent(v);
            if(p_u == p_v) cout << 1 << endl;
            else cout << 0 << endl;
        }

        else if( t == 0) {
            ll u, v;  cin >> u >> v;
            join(u, v);
        }
    }

    return 0;
}

Measured memory_bytes: 4944
#include <bits/stdc++.h>
#define rep(i,N) for (int i = 0; i < (N); ++i)
#define all(v) v.begin(), v.end()
using namespace std;
using ll = long long;
using P = pair<int, int>;
int main(void){
  int N;
  string S;
  cin >> N >> S;

  /*
  string ans = "Yes";
  if (S.size() % 2 == 1) cout << "No" << endl;
  else{
    for(int i = 0; i <= N / 2 - 1; i++){
      if (S.at(i) != S.at(i + N / 2)){
        ans = "No";
        break;
      }
    }
  }
  cout << ans << endl;
  */
  string ans = "No";
  int K = N / 2;
  if (N % 2 == 0 && S.substr(0, K) == S.substr(K, K)) ans =  "Yes";
  cout << ans << endl;
}


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

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0); cout.tie(0);
    string buf;
    int num;
    cin >> num;
    int ans = 0, leftNum = 0, rightNum = 0, tatNum = 0;
    for (int i = 0; i < num; i++) {
        cin >> buf;
        for (int i = 0; i < (int)buf.size() - 1; i++)
            if (buf[i] == 'A' && buf[i + 1] == 'B')
                ans++;
        if (buf[0] == 'B')
            rightNum++;
        if (buf[buf.size() - 1] == 'A')
            leftNum++;
        if (buf[0] == 'B' || buf[buf.size() - 1] == 'A')
            tatNum++;
    }
    if (leftNum == tatNum)
        leftNum--;
    if (rightNum == tatNum)
        rightNum--;

    cout << ans + max(0, min(leftNum, rightNum)) << endl;

    return 0;
}


Measured memory_bytes: 256
#include <stdio.h>

int main(void)
{
	int S,h,m,s;
	scanf("%d",&S);
	h=S/3600;
	m=(S-3600*h)/60;
	s=S-3600*h-60*m;
	printf("%d:%d:%d\n",h,m,s);
	return 0;
}

Measured memory_bytes: 592