akhauriyash/Code-Regression huggingface dataset:
#define _USE_MATH_DEFINES
#include <array>
#include <cassert>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <string>
#include <sstream>
#include <vector>
#include <queue>
#include <stack>
#include <list>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <algorithm>
#include <complex>
#include <cmath>
#include <numeric>
#include <bitset>
#include <functional>
#include <random>
#include <ctime>

using namespace std;

ostream& operator <<(ostream& out, const pair<int, int>& a) {
  out << "(" << a.first << "," << a.second << ")";
  return out;
}
template <typename T>
ostream& operator <<(ostream& out, const vector<T>& a) {
  out << "["; bool first = true;
  for (auto& v : a) { out << (first ? "" : ", "); out << v; first = 0;} out << "]";
  return out;
}
template <typename T>
ostream& operator <<(ostream& out, const set<T>& a) {
  out << "{"; bool first = true;
  for (auto& v : a) { out << (first ? "" : ", "); out << v; first = 0;} out << "}";
  return out;
}
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>
void __f(const char* name, Arg1&& arg1){
  cerr << name << ": " << arg1 << endl;
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args){
  const char* comma = strchr(names + 1, ',');
  cerr.write(names, comma - names) << ": " << arg1 << " |";
  __f(comma + 1, args...);
}

typedef long long int64;
typedef pair<int64, int64> ii;
const int INF = 1 << 30;
const int MOD = 1e9 + 7;
mt19937 mrand(random_device{}());
int rnd(int x) { return mrand() % x; }

const int N = 2e5 + 10;
int64 c[N];
void add(int x, int64 y) {
  for (; x < N; x += x & -x) {
    c[x] += y;
  }
}
int64 query(int x) {
  int64 ret = 0;
  for (; x; x -= x & -x) {
    ret += c[x];
  }
  return ret;
}

int main() {
  int64 n, D, A;
  scanf("%lld%lld%lld", &n, &D, &A);
  D *= 2;
  vector<ii> a(n);
  for (int i = 0; i < n; ++i) {
    scanf("%lld%lld", &a[i].first, &a[i].second);
  }
  sort(a.begin(), a.end());
  int64 ret = 0;
  for (int i = 0; i < n; ++i) {
    int64 x = query(i + 1);
    if (x >= a[i].second) continue;
    int64 y = (a[i].second - x + A - 1) / A;
    ret += y;
    int k = upper_bound(a.begin(), a.end(), ii{a[i].first + D, 1LL << 60}) - a.begin();
    add(i + 1, y * A);
    add(k + 1, -y * A);
  }
  printf("%lld\n", ret);
  return 0;
}


Measured memory_bytes: 4992
import java.util.Scanner;

public class Main {

  private static int a, b;
  private static String op;

  public static void main(String[] args) {
    Scanner stdIn = new Scanner(System.in);
    while (true) {
      a = stdIn.nextInt();
      op = stdIn.next();
      b = stdIn.nextInt();

      if (op.equals("?")) {
        break;
      }

      switch (op) {
        case "+":
          System.out.println(a+b);
          break;
        case "-":
          System.out.println(a-b);
          break;
        case "*":
          System.out.println(a*b);
          break;
        case "/":
          System.out.println(a/b);
          break;
      }
    }
  }
}

Measured memory_bytes: 26288
#include<cstdio>
using namespace std;
typedef long long int ll;

int N;
char ch[3][111];

int main(){
	scanf("%d", &N);
	for(int i = 0; i < 3; i++) scanf("%s", ch[i]);
	int res = 0;
	for(int i = 0; i < N; i++){
		if(ch[0][i] == ch[1][i] && ch[1][i] == ch[2][i]) continue;
		else if(ch[0][i] == ch[1][i]) res += 1;
		else if(ch[1][i] == ch[2][i]) res += 1;
		else if(ch[2][i] == ch[0][i]) res += 1;
		else res += 2;
	}
	printf("%d\n", res);
	return 0;
}


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

int ans1, ans2;
string s;

int main(){
	cin >> s;
	ans1 = ans2 = 0;
	for(int i = 0; i < s.length(); i++){
		if(s[i]-'0'!=i%2) ans1++;
		else ans2++;
	}
	printf("%d\n", min(ans1,ans2));
	return 0;
}

Measured memory_bytes: 512
// Brijesh Panara (201601074)
// DAIICT (India)
#include <bits/stdc++.h>
#include <time.h>
using namespace std;

#define ll long long
#define ld long double
#define pb push_back
#define mp make_pair
#define ff first
#define ss second

#define FOR(i,a,b) for(ll i=a;i<b;i++)
#define FILL(a,b) memset((a),(b),sizeof((a)))
#define precision(x,d) cout<<fixed<<setprecision(d)<<x
#define minQueue priority_queue<ll,vector<ll>,greater<ll> > 
#define maxQueue priority_queue<ll,vector<ll>,less<ll> > 

#define deb1(x) cout<<#x<<" : "<<x<<endl;
#define deb2(x,y) cout<<#x<<" : "<<x<<" "<<#y<<" : "<<y<<endl;
#define deb3(x,y,z) cout<<#x<<" : "<<x<<"   "<<#y<<" : "<<y<<"  "<<#z<<" : "<<z<<endl;

#define FAST ios_base::sync_with_stdio(false),cin.tie(0),cout.tie(0);
#define READ freopen("input.txt","r",stdin);
#define WRITE freopen("output.txt","w",stdout);
#define RANDOM srand(time(NULL));

#define MOD 1000000007
#define NAX 1000005
#define INF LONG_LONG_MAX
#define MINF LONG_LONG_MIN


ll solve()
{
    ld n;
    cin>>n;

    ld t = n/1.08;

    ll t2 = t;
    ll t1 = t2-1;
    ll t3 = t2+1;
    
    {
        ld z = t1;
        if((ll)(z*1.08)==n)
        {
            cout<<t1<<" ";
            return 0;
        }
    }

    {
        ld z = t2;
        if((ll)(z*1.08)==n)
        {
            cout<<t2<<" ";
            return 0;
        }
    }

    {
        ld z = t3;
        if((ll)(z*1.08)==n)
        {
            cout<<t3<<" ";
            return 0;
        }
    }
    
    cout<<":(";
    return 0;
}


int main()
{
    FAST;
    
    ll t=1;
    // cin>>t;
    
    while(t--!=0)
    {
        ll stat = solve();
    }
    return 0;
}


Measured memory_bytes: 256
macro_rules! get {
    ($t:ty) => {
        {
            let mut line: String = String::new();
            std::io::stdin().read_line(&mut line).unwrap();
            line.trim().parse::<$t>().unwrap()
        }
    };
    ($($t:ty),*) => {
        {
            let mut line: String = String::new();
            std::io::stdin().read_line(&mut line).unwrap();
            let mut iter = line.split_whitespace();
            (
                $(iter.next().unwrap().parse::<$t>().unwrap(),)*
            )
        }
    };
    ($t:ty; $n:expr) => {
        (0..$n).map(|_|
            get!($t)
        ).collect::<Vec<_>>()
    };
    ($($t:ty),*; $n:expr) => {
        (0..$n).map(|_|
            get!($($t),*)
        ).collect::<Vec<_>>()
    };
    ($t:ty ;;) => {
        {
            let mut line: String = String::new();
            std::io::stdin().read_line(&mut line).unwrap();
            line.split_whitespace()
                .map(|t| t.parse::<$t>().unwrap())
                .collect::<Vec<_>>()
        }
    };
    ($t:ty ;; $n:expr) => {
        (0..$n).map(|_| get!($t ;;)).collect::<Vec<_>>()
    };
}

use std::collections::BinaryHeap;

fn main() {
    let (_n, m) = get!(usize, usize);
    let aa = get!(String).split_whitespace().map(|w| w.parse::<u64>().unwrap()).collect::<Vec<_>>();
    let mut q = BinaryHeap::new();
    for a in aa.into_iter() {
        q.push(a);
    }
    for _ in 0..m {
        if let Some(a) = q.pop() {
            q.push(a/2);
        }
    }
    let mut r: u64 = 0;
    while let Some(a) = q.pop() {
        r += a;
    }
    println!("{}", r);
}

Measured memory_bytes: 9464
def solve():
  n = int(input())
  query = []
  for i in range(n):
    s,t = (input().split())
    query.append((s,t))
  x = input()
  
  ans = 0
  sleep = False
  for i in range(n):
    s,t = query[i]
    if sleep:
      ans += int(t)
    if s == x:
      sleep = True
  print(ans)
solve()


Measured memory_bytes: 3060
#include <iostream>
#include <algorithm>
#include <cstdio>
#include <cmath>
#include <string>
#include <vector>
#include <set>
#include <stack>
#include <functional>
using namespace std;

void bubbleSort(int A[], int N)
{
	bool flag = 1;
	for (int i = 0; flag; i++) {
		flag = 0;
		for (int j = N-1; j >= i + 1; j--) {
			if (A[j] < A[j - 1]) {
				swap(A[j], A[j-1]);
				flag = 1;
			}
		}
	}
}


int main()
{
	cin.tie(0);
	ios::sync_with_stdio(false);
    int n, k, l[60];
    cin >> n >> k;
    for (int i = 0;i < n; i++) {
        cin >> l[i];
    }
    bubbleSort(l, n);
    int sum = 0;
    for (int i = 0; i < k; i++) {
        sum += l[n - i - 1];
    }
    cout << sum << endl;
	return 0;
}

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

using namespace std;

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

static const int N = 100;
static const int white = 0;
static const int gray = 1;
static const int black = 2;

int n, M[N][N], color[N], d[N], f[N], tt;

void dfs_visit(int i) {
    color[i] = gray;
    d[i] = ++tt;
    REP(v, n) {
        if (M[i][v] == 0) continue;
        if (color[v] == white) {
            dfs_visit(v);
        }
    }
    color[i] = black;
    f[i] = ++tt;
}

void dfs() {
    REP(i, n) color[i] = white;
    tt = 0;

    REP(i, n) {
        if (color[i] == white) dfs_visit(i);
    }
    REP(i, n) {
        cout << i + 1 << " " << d[i] << " " << f[i] << endl;
    }
}

int main() {
    int u, v, k;

    cin >> n;
    REP(i, n) REP(j, n) M[i][j] = 0;

    REP(i, n) {
        cin >> u >> k;
        u--;
        REP(j, k) {
            cin >> v;
            v--;
            M[u][v] = 1;
        }
    }

    dfs();
    return 0;
}


Measured memory_bytes: 3096
from sys import stdin, setrecursionlimit


def main():
    input = stdin.buffer.readline
    n = int(input())
    a = list(map(int, input().split()))
    a.sort()
    max_a = max(a)

    dp = [True] * (max_a + 1)
    ans = 0

    for i in range(n):
        ai = a[i]
        if dp[ai]:
            if not (i < n - 1 and a[i] == a[i + 1]):
                ans += 1
            x = 1
            while ai * x < max_a + 1:
                dp[ai * x] = False
                x += 1

    print(ans)


if __name__ == "__main__":
    setrecursionlimit(10000)
    main()


Measured memory_bytes: 98148
#include<stdio.h>
struct Card{char suit;int value; };
int main()
{
  struct Card a[101],b[101];
  int n,i,j,k,mini,m,sum=0; 
  char ch;
  scanf("%d%c",&n,&ch);
  for(i=0;i<n;i++){ 
    scanf("%c%d%c",&a[i].suit,&a[i].value,&ch);
  }
  for(i=0;i<n+1;i++){
    b[i]=a[i];
  }
  
  for(i=0;i<n-1;i++){
    for(j=n-1;j>i;j--){
      if(a[j].value<a[j-1].value){
	m=a[j].value;
	a[j].value=a[j-1].value;
 	a[j-1].value=m;
	ch=a[j].suit;
        a[j].suit=a[j-1].suit;
        a[j-1].suit=ch;
      }
    }
  }  
  for(i=0;i<n-1;i++){
    mini=i; 
    m=b[i].value;
    for(j=i;j<n;j++){
      if(b[j].value<m){
	m=b[j].value;
	mini=j;
      }
    }
    if(m!=b[i].value){
      k=b[i].value;
      b[i].value=b[mini].value;
      b[mini].value=k;
      ch=b[i].suit;
      b[i].suit=b[mini].suit;
      b[mini].suit=ch;
    }
  }
  for(i=0;i<n;i++){
    if(a[i].suit==b[i].suit && a[i].value==b[i].value){
    sum++;
    }
  }
  for(i=0;i<n-1;i++){
    printf("%c%d ",a[i].suit,a[i].value);
  }
  printf("%c%d",a[i].suit,a[i].value);
  printf("\nStable\n");

  for(i=0;i<n-1;i++){
    printf("%c%d ",b[i].suit,b[i].value);
  }
  printf("%c%d",b[i].suit,b[i].value);
  if(sum==n)printf("\nStable\n");
  else printf("\nNot stable\n");

  return 0;
}

Measured memory_bytes: 612
#include <bits/stdc++.h>
#define rep(i,n) for (long long i = 0; i < (n); ++i)
using namespace std;
using ll = long long;
using P = pair<ll,ll>;
const ll MOD = 1000000007;
const ll INF = 1000000000000000000;
#define all(v) v.begin(), v.end()


int main(){
  string S;
  cin >> S;
  for (int tmp = 0; tmp < (1 <<(S.size()-1)); tmp++) {
    bitset<3> s(tmp);
    ll ans=S.at(0)-'0';
    rep(i,S.size()-1){
      if(s.test(i)){
        ans+=S.at(i+1)-'0';
      }else{
        ans-=S.at(i+1)-'0';
      }
    }
    if(ans==7){
      cout << S.at(0);
      rep(i,S.size()-1){
        if(s.test(i)){
          cout << '+';
        }else{
          cout << '-';
        }
        cout << S.at(i+1);
      }
      cout << "=7" << endl;
      return 0;
    }
  }
    
}

Measured memory_bytes: 256
a, b = map(int, input().split())

def func(x):
    if x <= 1:
        return x
    elif x == 2:
        return 3
    elif x == 3:
        return 0

    y = 1
    while y*2 <= x:
        y *= 2

    if (x - y + 1) % 2 == 1:
        return y + func(x - y)
    else:
        return func(x - y)

if a == 0:
    ans = func(b)
else:
    c, d =  func(a - 1), func(b)
    
    x = 0
    ans = 0
    while (1<<x) <= c or (1<<x) <= d:
        y, z = (c>>x)&1, (d>>x)&1
        if y ^ z == 1:
            ans += 1<<x
        x += 1

print(ans)


Measured memory_bytes: 3064
a1, a2, a3 = map(int, input().split())

def comp(a1, a2, a3):
    b = abs(a1 - a2)
    c = abs(a2 - a3)
    return b + c

d = comp(a1, a2, a3)
e = comp(a1, a3, a2)
f = comp(a2, a1, a3)
g = comp(a2, a3, a1)
h = comp(a3, a1, a2)
i = comp(a3, a2, a1)

print(min(d, e, f, g, h, i))

Measured memory_bytes: 3064
use std::io::*;

fn main() {
    let mut s: String = String::new();
    std::io::stdin().read_to_string(&mut s).ok();
    let mut itr = s.trim().split_whitespace();

    let n: usize = itr.next().unwrap().parse().unwrap();
    let a: Vec<i64> = (0..n)
        .map(|_| itr.next().unwrap().parse().unwrap())
        .collect();
    let b: Vec<i64> = (0..n)
        .map(|_| itr.next().unwrap().parse().unwrap())
        .collect();

    let mut da = 0i64;
    let mut db = 0i64;
    for i in 0..n {
        if a[i] > b[i] {
            db += a[i] - b[i];
        }
        if a[i] < b[i] {
            da += (b[i] - a[i]) / 2;
        }
    }
    if db <= da {
        println!("Yes");
    } else {
        println!("No");
    }
}


Measured memory_bytes: 2368
import java.util.Scanner

import scala.collection.mutable


object Main {

  def main(args: Array[String]): Unit = {

    val sc = new Scanner(System.in)

    val n = sc.nextInt() //街の数
    val k = sc.nextLong() //移動回数
    val as = Vector.fill(n)(sc.nextInt()) //街


    val ans = if (n >= k) {
      def l(count: Int, index: Int): Int = {
        count match {
          case _ if count == k => index
          case _ => l(count + 1, as(index - 1))
        }
      }
      l(0, 1)
    } else {

      val store = mutable.Set.empty[Int] //行った街を保存
      val history = mutable.ArrayBuffer.empty[Int] //行った街の順番を記録

      //周期を調べる 行ったところで最初に被った街を返す 被られたとこから被ったとこまでが周期
      def loop(nowTown: Int): Int = {
        if (store.contains(nowTown))
          nowTown
        else {
          store += nowTown
          history += nowTown
          val nextTown = as(nowTown - 1)
          loop(nextTown)
        }
      }

      val last = loop(1)
      val notCyclic = history.takeWhile(_ != last) //周期が始まる前の記録
      val cyclic = history.dropWhile(_ != last) //周期

      val i = (k - notCyclic.length) % cyclic.length
      cyclic(i.toInt)
    }


    println(ans)

  }
}


Measured memory_bytes: 75868
#include "bits/stdc++.h"
using namespace std;

int main() {
    long long X, Y, Z, K;
    cin >> X >> Y >> Z >> K;
    vector<long long> A(X);
    vector<long long> B(Y);
    vector<long long> C(Z);
    for (int i = 0; i < X; i++) cin >> A[i];
    for (int i = 0; i < Y; i++) cin >> B[i];
    for (int i = 0; i < Z; i++) cin >> C[i];

    vector<long long> test1 = {};
    for (int i = 0; i < X; i++) {
        for (int j = 0; j < Y; j++) {
            test1.push_back(A[i] + B[j]);
        }
    }
    sort(test1.begin(), test1.end());
    reverse(test1.begin(), test1.end());
    vector<long long> test2 = {};
    long long T = test1.size();
    for (int i = 0; i < min(K, T); i++) {
        for (int j = 0; j < Z; j++) {
            test2.push_back(test1[i] + C[j]);
        }
    }
    sort(test2.begin(), test2.end());
    reverse(test2.begin(), test2.end());

    for (int i = 0; i < K; i++) cout << test2[i] << endl;
}

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

#define ll long long
#define ld long double
#define pi 3.14159265359

int main() {
    int N, M; cin >> N >> M;
    vector<int> A(N);
    double sum = 0;
    for (int i = 0; i < N; i++) {
        cin >> A.at(i);
        sum += A.at(i);
    }
    sum /= 4 * M;
    int cnt = 0;
    for (int i = 0; i < N; i++) {
        if (A.at(i) >= sum) {
            cnt++;
        }
    }
    if (cnt >= M) {
        cout << "Yes" << endl;
    }
    else {
        cout << "No" << endl;
    }
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<int, int>;

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

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

    int H, W;
    cin >> H >> W;
    int sx, sy;
    cin >> sx >> sy;
    sx--; sy--;
    int gx, gy;
    cin >> gx >> gy;
    gx--; gy--;
    vector<string> mp(H);
    for(int i=0; i<H; i++) cin >> mp[i];

    auto dp = vector<vector<int>>(H, vector<int>(W, (1<<30)));
    dp[sx][sy] = 0;
    
    queue<P> q;
    set<P> mq;
    q.emplace(sx, sy);
    while(!q.empty() || !mq.empty())
    {
        if(q.empty())
        {
            for(auto p : mq) q.push(p);
            mq.clear();
        }
        P cp = q.front();
        // cout << cp.first << ", " << cp.second << '\n';
        q.pop();
        for(int i=cp.first - 2; i < cp.first + 3; i++)
        {
            for(int j=cp.second - 2; j < cp.second + 3; j++)
            {
                if(i<0 || j<0 || i>=H || j>=W || mp[i][j]=='#') continue;
                if(i==cp.first && j==cp.second) continue;
                bool is_magic = (llabs(i - cp.first) + llabs(j - cp.second) == 1);
                // cout << i << "/" << j << '/' << boolalpha << is_magic << " dp[i][j]:" << dp[i][j] << ", " << dp[cp.first][cp.second] << '\n';
                if(chmin(dp[i][j], dp[cp.first][cp.second] + (is_magic ? 0 : 1)))
                {
                    if(is_magic) q.emplace(i, j);
                    else mq.emplace(i, j);
                }
            }
        }
    }
    // for(auto v : dp)
    // {
    //     for(auto num : v)
    //     {
    //         cout << num << ' ';
    //     }
    //     cout << '\n';
    // }

    if(dp[gx][gy] == (1<<30)) cout << -1 << endl;
    else cout << dp[gx][gy] << endl;

    return 0;
}


Measured memory_bytes: 9216
fn main() {
    proconio::input! {
        n: usize,
        k: u128,
        a_s: [u128; n],
    }
    let mut tentosu = vec![(0, 0); n];
    for i in 0..n {
        for j in 0..i {
            if a_s[i] > a_s[j] {
                tentosu[i].0 += 1;
            }
        }
        for j in i + 1..n {
            if a_s[i] > a_s[j] {
                tentosu[i].1 += 1;
            }
        }
    }
    const M: u128 = 1_000_000_007;
    let mut count = 0u128;
    for i in 0..n {
        count += tentosu[i].0 * (k - 1) * k / 2;
        count += tentosu[i].1 * (k + 1) * k / 2;
        count %= M;
    }
    println!("{}", count);
}


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

using namespace std;
using ll = long long;

#define REP(i, n) for (ll i = 0; i < n; i++)
#define INF 9223372036854775807
#define all(x) (x).begin(), (x).end()

ll ts = 1000000007;

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

  string s;
  cin >> s;

  ll a, b;
  a = s.size();
  sort(all(s));
  s.erase(unique(s.begin(), s.end()), s.end());
  b = s.size();

  cout << (a == b ? "yes" : "no") << "\n";
}

Measured memory_bytes: 256
L, N = map(int, input().split())
X = [int(input()) for i in range(N)]
Y = [L - X[-i] for i in range(1, N + 1)]


def check(T, N):
    X = [0] + T
    P = [0] * (N + 1)
    Q = [0] * (N + 1)
    for i in range(1, N + 1):
        P[i] = P[i - 1] + X[i]
    for i in range(N, 0, -1):
        Q[i - 1] = Q[i] + L - X[i]
    ans = -1
    for i in range(1, N + 1):
        k = N - i
        if k % 2 == 0:
            a = k // 2
            t = 2 * (P[i + a - 1] - P[i - 1]) + 2 * (Q[i + a]) + X[i + a]
        else:
            a = k // 2
            t = 2 * (P[i + a] - P[i - 1]) + 2 * (Q[i + a + 1]) + L - X[i + a + 1]
        ans = max(ans, t)
        # print(t)
    return ans


print(max(check(X, N), check(Y, N)))

Measured memory_bytes: 75992
#include<iostream>
#include<algorithm>
#include<math.h>
#include<queue>
#include<vector>
#include<climits>
#include<map>
#include<string>
#include<functional>
#include<iomanip>
#include<deque>
#include<random>
#include<set>
#include<bitset>
#include<cassert>

using namespace std;
typedef long long ll;
typedef double lldo;
#define mp make_pair
#define pub push_back
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define sz(x) int(x.size())
#define chmax(x,y) x = max(x,y)
ll gcd(ll a, ll b) { if (a % b == 0) { return b; } else  return gcd(b, a % b); }
ll lcm(ll a, ll b) { if (a == 0) { return b; }return a / gcd(a, b) * b; }
template<class T>ll LBI(vector<T>& ar, T in) { return lower_bound(ar.begin(), ar.end(), in) - ar.begin(); }
template<class T>ll UBI(vector<T>& ar, T in) { return upper_bound(ar.begin(), ar.end(), in) - ar.begin(); }

ll a, b, c, d, ans = -1000000000000000005;

int main() {
	cin >> a >> b >> c >> d;
	chmax(ans, a * c);
	chmax(ans, a * d);
	chmax(ans, b * c);
	chmax(ans, b * d);
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 3632
#include <iostream>
#include <cstring>

int main() {
  char S[200];
  std::cin >> S;

  int n = strlen(S);
  for (int i = n - 2; i; i -= 2) {
    int half = i / 2;
    if ( strncmp(S, S + half, half) == 0 ) {
      std::cout << i << std::endl;
      return 0;
    }
  }

  return 0;
}


Measured memory_bytes: 256
#!/usr/bin/env python
import sys
import re
from collections import deque, defaultdict
from itertools import combinations, combinations_with_replacement
import bisect
from math import factorial, sqrt, log, ceil, floor
sys.setrecursionlimit(1000000)


def main():
    #N, M = map(int, input().split())
    #N, K = map(int, input().split())
    #ps = list(map(int, input().split()))

    N = int(input())
    nums = defaultdict(int)
    As = list(map(int, input().split()))
    for A in As:
        nums[A] += 1

    total = sum([key * value for key, value in nums.items()])

    Q = int(input())
    for i in range(Q):
        B, C = map(int, input().split())
        if B in nums:
            nums[C] += nums[B]
            diff = (C - B) * nums[B]
            del nums[B]
            total += diff
        print(total)



if __name__ == '__main__':
    main()


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

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

    string s;
    cin >> s;

    int cnt = 0;
    REP(i, s.size() - 1)
        if (s[i] != s[i + 1]) cnt++;

    cout << cnt << '\n';
    return 0;
}


Measured memory_bytes: 512
sss = list(map(int, input()))
cnt2 = 0
cnt3 = 0
for i, s in enumerate(sss):
    if i % 2 == 0:
        if s == 1:
            cnt2 += 1
    else:
        if s == 0:
            cnt2 += 1

    if i % 2 == 0:
        if s == 0:
            cnt3 += 1
    else:
        if s == 1:
            cnt3 += 1

print(min(cnt2, cnt3))

Measured memory_bytes: 3956
# encoding: utf-8


import sys


class Solution:
    def __init__(self):
        """
        init input array
        """
        self.__input = sys.stdin.readlines()

    @property
    def solution(self):
        product_num = int(self.__input[0].split()[0])
        truck_num = int(self.__input[0].split()[1])
        weight_list = list(map(int, self.__input[1:]))

        assert product_num == len(weight_list)

        # binary search
        left, right, mid = max(weight_list), sum(weight_list), 0
        while left < right:
            mid = (left + right) // 2
            # check return True : p could be smaller
            if self.check(mid, weight_list, truck_num):
                right = mid
            else:
                mid += 1
                left = mid
        return str(mid)

    @staticmethod
    def check(max_load_cursor, weight_list, truck_num):
        track_count = 1
        current_load = 0
        for item_weight in weight_list:
            current_load += item_weight
            # change to next truck
            if current_load > max_load_cursor:
                current_load = item_weight
                track_count += 1
                if track_count > truck_num:
                    return False
        return True


if __name__ == '__main__':
    case = Solution()
    print(case.solution)

Measured memory_bytes: 18604
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
ll max(ll a, ll b){ 
	if(a >= b) return a;
	else if(a < b) return b;
}

int main(){
	int n, k, x, y;
	cin >> n >> k >> x >>y;
	int ans = 0;
	for(int i = 0; i < n; i++){
		if(i < k)ans += x;
		else ans += y;
	}
	cout << ans << endl;
}


Measured memory_bytes: 256
package main

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

func main() {
	n := nextInt()
	s := make(map[string]int, n)

	for i := 1; i <= n; i++ {
		k := nextLine()
		if _, ok := s[k]; !ok {
			s[k] = 1
		} else {
			s[k] += 1
		}
	}

	fmt.Println(len(s))
}

// =================================
// I/O util
// =================================

var sc = bufio.NewScanner(os.Stdin)


func nextLine() string {
	sc.Scan()
	return sc.Text()
}

func nextInt() int {
	sc.Scan()
	i, e := strconv.Atoi(sc.Text())
	if e != nil {
		panic(e)
	}
	return i
}

// =================================

Measured memory_bytes: 13072
#include<cstdio>
#include<iostream>
using namespace std;
long long a,b,ans=99999999,n;
int main()
{
    scanf("%lld",&a);
    for(int i=1;i<=a;i++)
    {
		n=0;
        scanf("%lld",&b);
        while(b%2==0)
        {
            b/=2;
            n++;
        }
        ans=min(ans,n);
    }
    printf("%lld\n",ans);
}

Measured memory_bytes: 256
h=Hash.new
loop do
  break unless gets
  k,v=$_.chomp.split
  h.key?(k) ? h[k]<<" "+v : h.store(k,v)
end
h.sort.each do |k,v|
  puts "#{k}\n#{v.split.map(&:to_i).sort.join(" ")}"
end

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

#define ls(x) ch[x][0]
#define rs(x) ch[x][1]
#define rep(i , j , k) for(int i = j ; i <= k ; i ++)
#define Rep(i , j , k) for(int i = j ; i >= k ; i --)

using namespace std ;
using ll = long long ;
using pii = pair <int , int> ;
using vii = vector <int> ;
auto ot = [&]() { cerr << "ATS TXDY" << '\n' ; int ATS_nantf_txdy = true ; } ;
auto _ios = [&]() { ios :: sync_with_stdio(false) ; cin.tie(nullptr) ; cout.tie(nullptr) ; } ;
#define int long long
namespace stO_ATS_Orz {
  template < class T > void cmax(T & x , T y) { if(x > y) x = y ; }
  template < class T > void cmin(T & x , T y) { if(x < y) x = y ; }
  template < class T > void abs(T x) { if(x < 0) x = -x ; }
  void main() {
    long long T1,T2,a,b,c,d,e,f;
  	cin>>T1>>T2>>a>>c>>b>>d;
  	if(a*T1+c*T2==b*T1+d*T2){
  		cout<<"infinity";
  		return ;
  	}
  	if(a<b)swap(a,b),swap(c,d);
  	e=a-b;f=c-d;
  	if(e*T1+f*T2>0&&e*T1>0){
  		cout<<0;
  		return ;
  	}
  	if(e*T1+f*T2<0&&e*T1<0){
  		cout<<0;
  		return ;
  	}
  	cout<<2ll*(((a-b)*T1)/(-e*T1-f*T2))+bool(((a-b)*T1)%(1ll*(-e*T1-f*T2)));
  }
}
signed main() {
  _ios() ; ot() ;
  return stO_ATS_Orz :: main() , 0 ;
}


Measured memory_bytes: 256
def root(x):
    if parent[x] == x:
        return(x)
    else:
        parent[x] = root(parent[x])
        return(parent[x])


def same(x, y):
    return(root(x) == root(y))


def union(x, y):
    x = root(x)
    y = root(y)
    if(x == y):
        return False

    parent[x] = min(x, y)
    parent[y] = min(x, y)
    return True





H, W = map(int, input().split())
S = [input() for _ in range(H)]

parent = [i for i in range(H*W)]

neighbor = [(1, 0), (-1, 0), (0, 1), (0, -1)]
for h in range(H):
    for w in range(W):
        for px, py in neighbor:
            tx = w + px
            ty = h + py
            # print(tx, ty, tx < 0 or tx >= w or ty < 0 or ty >= h)
            if tx < 0 or tx >= W or ty < 0 or ty >= H:
                continue
            
            # print({S[h][w], S[ty][tx]})
            if {S[h][w], S[ty][tx]} == {"#", "."}:
                union(h*W+w,ty*W+tx)

ans = {root(r):{"#":0, ".":0} for r in parent}
for i in range(H*W):
    ans[root(i)][S[i//W][i%W]] += 1
# print(parent)
# print(ans)

print(sum(v["#"]*v["."] for v in ans.values()))

Measured memory_bytes: 56412
#include <stdio.h>
#include <string.h>
int main()
{int n,d,i;
	scanf("%d\n",&n);
	char s[n];
	gets(s);
	d=n/2;
	if(n%2!=0){
		printf("No\n");}
		else{
		for(i=0;i<d;i++){
			if(s[i]==s[i+d])
			{continue;
			}else
			{
				break;
			}
	}
	if(i==d)
	{
		printf("Yes\n");
	}else
	{
		printf("No\n");
	}
	}
	
	return 0;
	}

Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
int main(){
  int a, b, c;
  cin >> a >> b >> c;
  int sum = a, m = sum%b;
  string ans = "YES";
  set<int> s;
  while(m != c){
    if(s.count(m)){ ans = "NO"; break; }
    s.insert(m);
    sum += a;
    m = sum%b;
  }
  cout << ans << endl;
}

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

#define ALL(a)  (a).begin(),(a).end()
#define ALLR(a)  (a).rbegin(),(a).rend()
#define spa << " " <<
#define MP make_pair
#define test cout<<"test"<<endl;
#define fi first
#define se second
typedef long long ll;
typedef long double ld;
const ll MOD = 1e9+7;
//const ll MOD = 998244353;
const ll INF = 1e18;
const ll zero=0;
using P = pair<ll, ll>;
void chmin(ll &a,ll b){if(a>b)a=b;}
void chmax(ll &a,ll b){if(a<b)a=b;}
void pmod(ll &a,ll b){a=(a+b)%MOD;}
void pmod(ll &a,ll b,ll c){a=(b+c)%MOD;}
void qmod(ll &a,ll b){a=(a*b)%MOD;}
void qmod(ll &a,ll b,ll c){a=(b*c)%MOD;}
void ans1(bool x){if(x) cout<<"Yes"<<endl;else cout<<"No"<<endl;}
void ans2(bool x){if(x) cout<<"YES"<<endl;else cout<<"NO"<<endl;}
void ans3(bool x){if(x) cout<<"Yay!"<<endl;else cout<<":("<<endl;}
void ans(bool x,ll y,ll z){if(x)cout<<y<<endl;else cout<<z<<endl;}
void ans(bool x,string y,string z){if(x)cout<<y<<endl;else cout<<z<<endl;}   
ll gcd(ll x,ll y){ll r;while((r=x%y)!=0){x=y;y=r;}return y;}

struct UnionFind {
  vector<ll> data;
  UnionFind(ll size) : data(size, -1) { }
  bool unionset(ll x, ll y) {
    x = root(x); y = root(y);
    if (x != y) {
      if (data[y] < data[x]) swap(x, y);
      data[x] += data[y]; data[y] = x;
    }
    return x != y;
  }
  bool findset(ll x, ll y) {
    return root(x) == root(y);
  }
  ll root(ll x) {
    return data[x] < 0 ? x : data[x] = root(data[x]);
  }
  ll size(ll x) {
    return -data[root(x)];
  }
};


int main(){
  ll i,j,o;
  ll res=0,res1=INF,res2=-INF,buf=0;
  bool judge = true;
  ll n;cin>>n;
  vector<ll>a(n+2),b(n+1);
  for(i=1;i<=n;i++)cin>>a[i];
  UnionFind t(n+1);
  //test;
  for(i=1;i<=n;i++){
    b[a[i]]=i;
  }
  //test;
  for(i=n;i>=1;i--){
    ll bufl=0,bufr=0;
    if(a[b[i]-1]>i){
      bufl=t.size(a[b[i]-1]);
      t.unionset(a[b[i]-1],i);
    }
    if(a[b[i]+1]>i){
      bufr=t.size(a[b[i]+1]);
      t.unionset(a[b[i]+1],i);
    }
    buf=t.size(i)+bufl*bufr;
    res+=buf*i;
    //cout<<res<<endl;
  }
  cout<<res<<endl;
  
  return 0;
}

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

int main(){
  int K ;
  cin >> K ;
  string S ;
  cin >> S ;
  int a = S.size();
  if(a<=K) cout << S << endl;
  else {
    string b = S.substr(0,K);
    cout << b+"..." << endl;
  }
  
}


Measured memory_bytes: 3628
#include<bits/stdc++.h>
using namespace std;
int main()
{
	#ifndef ONLINE_JUDGE 
   freopen("in.txt", "r", stdin); 
   freopen("out.txt", "w", stdout); 
   #endif 
    int n,d,a[1000000],b[1000000],count=0,i;
    cin>>n>>d;
    for(i=0;i<n;i++)
    {
    	cin>>a[i];
    	cin>>b[i];
    }
    for(i=0;i<n;i++)
    {
    	if(sqrt(pow(a[i],2)+pow(b[i],2))<=d)
    	{
    		count++;
    	}
    }
    cout<<count<<endl;

}


Measured memory_bytes: 5256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
//Micro Futures scalping to get my tendies
int main()
{
    ll n, k;
    cin >> n >> k;
    ll arr[n];
    for (int i = 0; i < n; i++)
    {
        cin >> arr[i];
    }
    ll pre[n + 1];
    pre[0] = 0;
    for (int i = 1; i < n + 1; i++)
    {
        pre[i] = pre[i - 1] + arr[i - 1];
    }
    for (int i = k + 1; i <= n; i++)
    {
        double sum1 = pre[i - 1] - pre[(i - 1) - k];
        double sum2 = pre[i] - pre[i - k];
        sum1 = sum1 / (double)k;
        sum2 = sum2 / (double)k;
        if (sum2 - sum1 > 0.000000000)
            cout << "Yes\n";
        else
            cout << "No\n";
    }
}

Measured memory_bytes: 6732
#include <iostream>
#include <cstdio>
#include <vector>
#include <cstring>
#include <bitset>
#include <cmath>
#include <iomanip>
#include <stack>
#include <set>
#include <queue>
#include <algorithm>
#include <deque>
#include <map>
#include <cmath>
#include <iomanip>
using namespace std;

#define INF 1e18
#define int long long

template<typename T>
void printVec(vector<T> &v) {
    for(int i = 0; i < v.size(); i++) {
        cout << v[i] << " ";
    }
    cout << endl;
}

signed main() {
    int n; cin >> n;
    vector<int> a(n), b(n), c(n);
    for(int i = 0; i < n; i++) cin >> a[i];
    for(int i = 0; i < n; i++) cin >> b[i];
    for(int i = 0; i < n; i++) c[i] = a[i] - b[i];

    sort(c.rbegin(), c.rend());

    int s = 0;
    int num1 = 0;
    for(int i = 0; i < n; i++) {
        if(c[i] < 0) {
            s += c[i];
            num1++;
        }
    }

    int num2 = 0;
    for(int i = 0; i < n; i++) {
        if(c[i] > 0 && s < 0) {
            s += c[i];
            num2++;
        }
    }

    cout << (s < 0 ? -1 : num1 + num2) << endl;
    return 0;
}


Measured memory_bytes: 2560
// Author : Sarthak Kapoor
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
using namespace std;
using namespace __gnu_pbds;
#define rep(i,n) for(int i=0;i<n;++i)
#define repa(i,a,n) for(int i=a;i<n;++i)
#define repr(i,n) for(int i=n-1;i>=0;--i)
#define repba(i,b,a) for(int i=b;i>=a;--i)
#define repab(i,a,b) for(int i=a;i<b;++i)
#define ll long long
#define ull unsigned long long
#define vi vector<int>
#define msi map<string,int>
#define mii map<int,int>
#define viip vector<pair<int,pair<int,int> > > 
#define mp make_pair
#define vip vector<pair<int,int> >
#define pb push_back 
#define po pop_back
#define fi first
#define sec second
#define all(v) v.begin(),v.end()
#define rall(v) v.rbegin(),v.rend()
#define s(v) v.size()
ll mod = 1000000007;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());//use rng()%n for numbers in range [0,n-1]
ll gcd(ll a,ll b){
	if(b==0)return a;
	return gcd(b,a%b);
}
int main() {
	ios::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
	
	string s;
	cin>>s;
	int n = s(s);
	char cur = 'R';
	// int c = 1;
	int ans[n+10];
	rep(i,n)ans[i] = 0;
	// repa(i,1,n){
	// 	if(s[i] == cur){
	// 		if(c!=0)ans[i-1] = 0;
	// 		c++;
	// 	}
	// 	else{
	// 		if(c % 2){
	// 			ans[i-1] = c;
	// 			ans[i] = 1;
	// 		}	
	// 		else{
	// 			ans[i-1] = 1;
	// 			ans[i] = c;
	// 		}
	// 		c = 1;
	// 		cur = s[i];
	// 	}
	// }
	ans[0] = 0;
	int c = 1;
	int f =  0;
	int c1 = 0; 
	repa(i,1,n){
		if(s[i] == cur){
			c++;
		}
		else{
			int j = i;
			c1 = 0;
			while(i < n && s[i] == 'L'){
				i++;
				c1++;
			}
			if(i == n)f=1;
			if(c%2 == c1%2){
				ans[j-1] = (c+c1)/2;
				ans[j] = (c+c1)/2;
			}
			else{
				int temp = c+c1;
				int x = temp/2;
				if(c%2){
					ans[j-1] = x+1;
					ans[j] = x;
				}
				else{
					ans[j-1] = x;
					ans[j] = x+1;
				}
			}
			c = 1;
		}
	}
	// if(!f){
	// 	while(i < n && s[i] == 'L'){
	// 			i++;
	// 			c1++;
	// 		}
	// 		if(i == n)f=1;
	// 		if(c%2 == c1%2){
	// 			ans[j-1] = (c+c1)/2;
	// 			ans[j] = (c+c1)/2;
	// 		}
	// 		else{
	// 			int temp = c+c1;
	// 			int x = temp/2;
	// 			if(c > c1){
	// 				ans[j-1] = x+1;
	// 				ans[j] = x;
	// 			}
	// 			else{
	// 				ans[j-1] = x;
	// 				ans[j] = x+1;
	// 			}
	// 		}
	// }
	rep(i,n){
		cout<<ans[i]<<" ";
	}
	return 0;
}

Measured memory_bytes: 1104
#include <iostream>
#include <vector>
#include <map>
#include <unordered_map>
#include <queue>
#include <set>
#include <algorithm>
#include <string>
#include <math.h>
#include <limits.h>
#include <stack>
#include <complex>
#include <stdlib.h>
#include <stdio.h>
#include <functional>
#include <cfloat>
#include <math.h>


#define fs first
#define sc second

using namespace std;


typedef long long ll;
typedef pair<int, int> P1;
typedef pair<int, P1> P2;
typedef pair<ll, P2> P3;


priority_queue<pair<ll, P2>> que;
ll a[1100], b[1100], c[1100];
map<P3, int> mp;


P3 make_data(int xi, int yi, int zi){
    P1 t = P1(yi, zi);
    P2 t2 = P2(xi, t);
    P3 t3 = P3(a[xi] + b[yi] + c[zi], t2);
    return t3;
}

int main(){
    int x, y, z, k;
    cin >> x >> y >> z >> k;
    for(int i = 0; i < x; i++){
        cin >> a[i];
    }
    sort(a, a+x);
    for(int i = 0; i < y; i++){
        cin >> b[i];
    }
    sort(b, b+y);
    for(int i = 0; i < z; i++){
        cin >> c[i];
    }
    sort(c, c+z);

    P3 t = make_data(x-1, y-1, z-1);
    que.push(t);
    while(k > 0){
        P3 t3 = que.top();
        que.pop();

        int xxi = t3.sc.fs;
        int yyi = t3.sc.sc.fs;
        int zzi = t3.sc.sc.sc;

        if(!(mp.find(t3) == mp.end())){
            continue;
        }
        mp[t3] = 0;

        cout << t3.fs << endl; // << " " << xxi << " " << yyi << " " << zzi << endl;

        if(xxi > 0){
            que.push(make_data(xxi-1, yyi, zzi));
        }
        if(yyi > 0){
            que.push(make_data(xxi, yyi-1, zzi));
        }
        if(zzi > 0){
            que.push(make_data(xxi, yyi, zzi-1));
        }
        k--;
    }



    return 0;
}


Measured memory_bytes: 640
#include <iostream>
#include <vector>
#include <set>
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <algorithm>
#include <iomanip>
#include <numeric>
#include <queue>
#include <cmath>
using namespace std;


int main() {
    string s;
    int x, y;
    cin >> s >> x >> y;
    int state = -1;
    vector<int> vx, vy;
    int c = 0;
    for (auto ss : s) {
        if (ss == 'T') {
            if (state == -1) {
                state = 1;
            } else {
                if (c > 0) {
                    if (state == 0) 
                        vx.push_back(c);
                    else
                        vy.push_back(c);
                    c = 0;
                }
                state = 1 - state;
            }
        } else {
            if (state == -1) {
                x--;
            } else if (state == 0) {
                c++;
            } else {
                c++;
            }
        }
    }
    if (c > 0) {
        if (state == 0) 
            vx.push_back(c);
        else
            vy.push_back(c);
    }
    x = abs(x), y = abs(y);
    int sx = accumulate(vx.begin(), vx.end(), 0);
    int sy = accumulate(vy.begin(), vy.end(), 0);
    int flag = 0;
    vector<int> v(8001, 0);
    v[0] = 1;
    for (auto step : vx) {
        for (int i = 8000; i - step >= 0; i--) {
            v[i] = max(v[i], v[i - step]);
        }
    }
    for (int i = 0; i <= 8000; i++) {
        if (v[i] == 1 && abs(sx - i - i) == x) {
            flag = 1;
            break;
        }
    }
    if (flag == 0) {
        cout << "No" << endl;
        return 0;
    }
    flag = 0;
    v = vector<int>(8001, 0);
    v[0] = 1;
    for (auto step : vy) {
        for (int i = 8000; i - step >= 0; i--) {
            v[i] = max(v[i], v[i - step]);
        }
    }
    for (int i = 0; i <= 8000; i++) {
        if (v[i] == 1 && abs(sy - i - i) == y) {
            flag = 1;
            break;
        }
    }
    if (flag == 0) {
        cout << "No" << endl;
    } else {
        cout << "Yes" << endl;
    }
}




Measured memory_bytes: 3700
#include<algorithm>
#include<bitset>
#include<cassert>
#include<cfloat>
#include<climits>
#include<cmath>
#include<deque>
#include<functional>
#include<iomanip>
#include<iostream>
#include<map>
#include<queue>
#include<set>
#include<stack>
#include<string>
#include<unordered_map>
#include<unordered_set>
#include<utility>
#include<vector>

using namespace std;

using lint = long long;
using P = pair<int, int>;
using LLP = pair<long long, long long>;

#define REP(i, x, n) for(int i = (x), i##_len = (int)(n) ; i < i##_len ; ++i)
#define rep(i, n) for(int i = 0, i##_len = (int)(n) ; i < i##_len ; ++i)
#define reps(i, n) for(int i = 1, i##_len = (int)(n) ; i <= i##_len ; ++i)
#define rrep(i, n) for(int i = (int)(n) - 1 ; i >= 0 ; --i)
#define rreps(i, n) for(int i = (int)(n) ; i > 0 ; --i)
#define SORT(x) sort((x).begin(), (x).end())
#define SORT_INV(x) sort((x).rbegin(), (x).rend())
#define REVERSE(x) reverse((x).begin(), (x).end())
#define TWINS(x) cout << ((x) ? "Yay!" : ":(") << '\n'
#define endl '\n'

constexpr int IINF = (1 << 30) - 1;
constexpr long long LLINF = 1LL << 61;
constexpr double EPS = 1e-10;

constexpr int dx4[] = {1, 0, -1, 0}, dy4[] = {0, 1, 0, -1};
constexpr int dx8[] = {1, 1, 0, -1, -1, -1, 0, 1}, dy8[] = {0, -1, -1, -1, 0, 1, 1, 1};

class UnionFind{
    vector<int> par;
    int groupCount;

public:
    UnionFind(int n = 0){
        init(n);
    }

    void init(int n = 0){
        par.resize(n);
        fill(par.begin(), par.end(), -1);

        groupCount = n;

        return;
    }

    int root(int x){
        if(par[x] < 0){
            return x;
        }
        return par[x] = root(par[x]);
    }

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

    int size(int x){
        return -par[root(x)];
    }

    bool unite(int x, int y){
        x = root(x);
        y = root(y);

        if(x == y){
            return false;
        }

        if(par[y] < par[x]){
            swap(x, y);
        }

        par[x] += par[y];
        par[y] = x;
        --groupCount;

        return true;
    }

    int size(void){
        return groupCount;
    }
};

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

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

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(10);

    constexpr int n = 1001;

    int fib[n + 1];
    fib[0] = 1;
    fib[1] = 2;
    REP(i, 2, n + 1){
        fib[i] = (fib[i - 1] + fib[i - 2]) % n;
    }

    int v, d;
    while(cin >> v >> d){
        UnionFind uf(v + 1);
        for(int i = 1 ; i <= v ; ++i){
            for(int j = 1 ; j <= v ; ++j){
                if(abs(fib[i] - fib[j]) < d){
                    uf.unite(i, j);
                }
            }
        }
        cout << uf.size() - 1 << endl;
    }

    cout << flush;

    return 0;
}


Measured memory_bytes: 3096
#include <iostream>
#include <string>
#include <vector>
#include <deque>
#include <queue>
#include <algorithm>
#include <set>
#include <map>
#include <bitset>
#include <cmath>
#include <functional>
#define vv(a, b, c, d) vector<vector<d> >(a, vector<d>(b, c))
#define vvi vector<vector<int> >
#define vvl vector<vector<ll> >
#define vll vector<ll>
#define rep(c, a, b) for(ll c=a;c<b;c++)
#define re(c, b) for(ll c=0;c<b;c++)
typedef long long int ll;
typedef long double ld;
using namespace std;

struct Bellman{
  ll INF=1000000000000000000, MAX_V;
  struct edge{ll from, to, cost;};
  vector<edge> es;
  vll d, pre;

  Bellman(ll n){
    MAX_V = n+1;
    d.resize(MAX_V, INF);
    pre.resize(MAX_V, -1);
  }
  void insert(ll a, ll b, ll c){
    es.push_back(edge{a, b, c});
  }
  bool bellman(ll s){
    for(int i=0;i<MAX_V;i++) d[i] = INF;
    d[s] = 0;
    for(int j=0;;j++){
      bool update = false;
      for(int i=0;i<es.size();i++){
        edge e = es[i];
        if(d[e.from]!=INF && d[e.to]>d[e.from]+e.cost){
          d[e.to] = d[e.from]+e.cost;
          pre[e.to] = e.from;
          if(j<=MAX_V||e.to==MAX_V-1) update = true;
        }
      }
      if(!update) break;
      if(update&&j>MAX_V) return false;
    }
    return true;
  }
};

int main(int argc, char const *argv[]) {
  ll x, y, z, n, m;std::cin >> n >> m;
  Bellman b(n);
  re(i, m){
    std::cin >> x >> y >> z;
    b.insert(x, y, -z);
  }
  if(!b.bellman(1)){
    std::cout << "inf" << '\n';
    return 0;
  }
  std::cout << -b.d[n] << '\n';
  return 0;
}


Measured memory_bytes: 384
#include <bits/stdc++.h>
#define rep(X,N) for(ll X = 0; X < (N); X++)
#define PI (acos(-1.0))
#define pback push_back
#define mpair make_pair
#define MODN 1000000007
#define ALL(V) (V).begin(),(V).end()

typedef long long ll;

using namespace std;

int main(){

    int h,w,n;
    cin >> h >> w >> n;

    int m = max(h,w);

    cout << (n + m - 1) / m << endl;
    

    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ss second
#define ff first
#define all(x) x.begin(), x.end()
#define DEBUG

using namespace std;
using ll = long long;
using pii = pair<ll, ll>;

const int oo = 1e9 + 7;
const ll mod = 1e9 + 7, maxn = 52, maxm = (1 << 21);
const double PI = acos(-1);

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

    cout << h/a + (h%a == 0? 0 : 1) << endl;
    return 0;
}

Measured memory_bytes: 256
def check(pattern):
    for i in range(W - 2):
        mask = 0b11 << i
        if pattern & mask == mask:
            return False
    return True


def simulate(a1, pattern):
    pat = [pattern & (1 << w) != 0 for w in range(W - 1)]
    if a1 != W - 1 and pat[a1]:
        return a1 + 1
    elif a1 != 0 and pat[a1 - 1]:
        return a1 - 1
    else:
        return a1


H, W, K = map(int, input().split())
dp = [[0] * W for h in range(H + 1)]
dp[0][0] = 1
for h in range(1, H + 1):
    for pattern in range(2 ** (W - 1)):
        for w in range(W):
            if check(pattern):
                dp[h][simulate(w, pattern)] += dp[h - 1][w]
                dp[h][simulate(w, pattern)] %= 1000000007
print(dp[H][K - 1])


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

int main(){
    int n;cin>>n;
    int ans=0;
    while(n--){
        int d1,d2;cin>>d1>>d2;

        if(ans==3)break;
        if(d1==d2){
            ans++;
        }
        else if(d1!=d2)ans=0;
    }
    if(ans==3){
        cout<<"Yes";
    }else cout<<"No";
    return 0;
}

Measured memory_bytes: 3620
import sys
#import string
#from collections import defaultdict, deque, Counter
#import bisect
#import heapq
#import math
#from itertools import accumulate
#from itertools import permutations as perm
#from itertools import combinations as comb
#from itertools import combinations_with_replacement as combr
#from fractions import gcd
#import numpy as np
import copy

stdin = sys.stdin
sys.setrecursionlimit(10 ** 7)
MIN = -10 ** 9
MOD = 10 ** 9 + 7
INF = float("inf")
IINF = 10 ** 18

def solve():
    #n = int(stdin.readline().rstrip())
    h,w,k = map(int, stdin.readline().rstrip().split())
    #l = list(map(int, stdin.readline().rstrip().split()))
    #numbers = [[int(c) for c in l.strip().split()] for l in sys.stdin]
    words = [stdin.readline().rstrip() for _ in range(h)]
    #number = [[int(c) for c in stdin.readline().rstrip()] for _ in range(n)]
    #zeros = [[0] * w for i in range(h)]
    n = h + w
    ans =0
    for i in range(2**n):
        word = copy.deepcopy(words)
        black= 0
        for j in range(n):
            if ((i >> j) & 1):
                if j <= h-1:
                    wo = "." * w
                    word[j] = wo
                else:
                    gyo = ""
                    for e in range(h):
                        wo = list(word[e])
                        wo[j-h] = "."
                        wo = "".join(wo)
                        word[e] = wo
            else:
                pass
        for j in range(h):
            r = word[j]
            black += r.count("#")
        if black == k:
            ans += 1
    print(ans)


if __name__ == '__main__':
    solve()


Measured memory_bytes: 9356
a = int(input())
b = int(input())
c = int(input())
x = int(input())
l = [0] * ((a + 1) * (b + 1) * (c + 1))
for i in range(a + 1):
    for j in range(b + 1):
        for k in range(c + 1):
            index = (b + 1) * (c + 1) * i + (c + 1) * j + k
            l[index] = 500 * i + 100 * j + 50 * k

result = l.count(x)
print(result)


Measured memory_bytes: 8248
#include <stdio.h>
#include <stdlib.h>

#define ll long long

ll x , y , ans ;

int main() {
	scanf("%lld %lld" , &x , &y) ;

	ll num = x ; ans = 0 ;
	for (; num <= y ; num <<= 1 , ++ans) ;

	printf("%lld\n" , ans) ;

	return 0 ;
}

Measured memory_bytes: 128