akhauriyash/Code-Regression huggingface dataset:
#include "bits/stdc++.h"
#define ll long long
#define lld long double
#define MOD 1000000007LL
#define inf 1000000000000000000ll
#define pii pair<int,int>
#define f first
#define s second
#define pb push_back
#define mp make_pair
#define all(v) v.begin(),v.end()
#define fast ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
ll power(ll x,ll y, ll md=MOD){ll res = 1;x%=md;while(y){if(y&1)res = (res*x)%md;x *= x; if(x>=md) x %= md; y >>= 1;}return res;}
 
using namespace std;

#define endl '\n'
#define int ll

struct node {
	vector<int> v,w;
};



signed main() {
	fast;

	int n;
	cin>>n;
	map<int,int> mp;
	vector<int> cnt(1000002,0);
	for(int i=0;i<n;i++) {
		int temp;
		cin>>temp;
		mp[temp]++;
	}

	int ans = 0;
	for(auto &x: mp) {
		if(cnt[x.f]==0 && x.s==1) ans+=x.s;
		for(int j=x.f;j<1000002;j+=x.f) cnt[j]+=x.s;
	}
	ans = ans;
	cout<<ans;

}

Measured memory_bytes: 23424
#include <iostream>
#include <cstdio>
#include <stack>
#include <cstdlib>

using namespace std;

int main(){
    stack<int> st;
    int op1, op2;
    char s[100];
    while(cin >> s){
        if(s[0] == '+'){
            op1 = st.top();
            st.pop();
            op2 = st.top();
            st.pop();
            st.push(op1 + op2);
        }else if(s[0] == '-'){
            op1 = st.top();
            st.pop();
            op2 = st.top();
            st.pop();
            st.push(op2 - op1);
        }else if(s[0] == '*'){
            op1 = st.top();
            st.pop();
            op2 = st.top();
            st.pop();
            st.push(op1 * op2);
        }else{
            st.push(atoi(s));
        }
    }
    cout << st.top() << endl;
    return 0;
}

Measured memory_bytes: 3112
#include<iostream>
#include<vector>
#include<cstring>
#include<algorithm>
#include<cmath>
#include<queue>
#include<deque>
#include<map>
#include<bitset>
using namespace std;

typedef long long ll;
#define rep(i, n) for(int i = 0;i < (n);i++)
#define repr(i, n) for(int i = (n);i >= 0;i--)
#define repf(i, m, n) for(int i = (m);i < (n);i++)
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1;} return 0;}
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1;} return 0;}
int dx[] = {0, 1, 0, -1}, dy[] = {1, 0, -1, 0};
//////////////////////////////////////////////////


int main() {
    int x; cin >> x;
    ll ans = x/500*1000 + x%500/5*5;
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
def main():
    from builtins import int, map, list, print, len
    from collections import defaultdict
    import sys
    sys.setrecursionlimit(10 ** 6)

    input = (lambda: (sys.stdin.readline()).rstrip())
    input_list = (lambda: input().split())
    input_number = (lambda: int(input()))
    input_number_list = (lambda: list(map(int, input_list())))

    N = input_number()
    A_ls = input_number_list()
    d = defaultdict(lambda: 0)
    for i in range(len(A_ls)):
        d[A_ls[i]] += 1
    Q = input_number()

    total = sum(A_ls)

    for i in range(Q):
        B, C = input_number_list()
        cnt = d[B]
        total -= cnt * B
        total += cnt * C
        d[C] += cnt
        d[B] = 0
        print(total)


if __name__ == '__main__':
    main()


Measured memory_bytes: 24260
#include <map>
#include <set>
#include <list>
#include <cmath>
#include <ctime>
#include <deque>
#include <queue>
#include <stack>
#include <string>
#include <bitset>
#include <cstdio>
#include <limits>
#include <vector>
#include <climits>
#include <cstring>
#include <cstdlib>
#include <fstream>
#include <numeric>
#include <sstream>
#include <cassert>
#include <iomanip>
#include <iostream>
#include <algorithm>
#include <unordered_set>
#include <unordered_map>

using namespace std;

#define f first
#define s second
#define pb push_back
#define pp pop_back
#define mp make_pair
#define ll long long

const int N = 3e5 + 123;
const int inf = 1e9;
const int mod = 1e9 + 7;

int k, s, dp[N];
ll ans;

int main() {
	#ifdef wws
		freopen("in", "r", stdin);
	#endif
	ios_base::sync_with_stdio(0);
	cin >> k >> s;
	for (int i = 0;i <= k;i++) {
		for (int j = 0;j <= k;j++) {
			int z = s - i - j;
			if (z >= 0 && z <= k) {
				ans++;
			}
		}
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <queue>

using namespace std;

int main() {
  priority_queue<int> que;
  int h;

  for(int i = 0; i < 10; i++) {
    cin >> h;
    que.push(h);
  }

  for(int i = 0; i < 3; i++) {
    cout << que.top() << endl;
    que.pop();
  }

  return 0;
}

Measured memory_bytes: 1216
aI, aO, _, aJ, aL, _, _ = map(int, input().split())


def f(i, j, l):
    return aO + 2 * (i // 2 + j // 2 + l // 2)


ans = f(aI, aJ, aL)
if aI and aJ and aL:
    ans = max(ans, 3 + f(aI - 1, aJ - 1, aL - 1))
print(ans)


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

using namespace std;
using ll = long long;

template <class T> ostream &operator<<(ostream &os, vector<T> &v) {
  for (auto i = v.begin(); i != v.end(); i++) {
    os << *i << " ";
  }
  return os;
}


void solve(long long N, std::vector<long long> A){
  sort(A.begin(), A.end());
  ll d[N];
  d[0] = A[0];
  for(int i=1; i<N; i++) {
    d[i] = d[i-1]+A[i];
  }
  ll i = N-2;
  for(; i>=0; i--) {
    if(d[i]*2<A[i+1]) {
      break;
    }
  }
  std::cout << N-i-1 << std::endl;
}

int main(){
  long long N;
  scanf("%lld",&N);
  std::vector<long long> A(N);
  for(int i = 0 ; i < N ; i++){
    scanf("%lld",&A[i]);
  }
  solve(N, std::move(A));
  return 0;
}


Measured memory_bytes: 1792
#![allow(unused_imports)]
use std::io;
use std::cmp::*;
use std::collections::*;
#[allow(dead_code)]
const M: i64 = 1e9 as i64 + 7;

fn read_line() -> String {
    let stdin = io::stdin();
    let mut buf = String::new();
    stdin.read_line(&mut buf).unwrap();
    buf
}
#[allow(dead_code)]
fn read<T>() -> T where T: std::str::FromStr, T::Err : std::fmt::Debug {
    read_line().trim().parse().unwrap()
}
#[allow(dead_code)]
fn readv<T>() -> Vec<T> where T: std::str::FromStr, T::Err : std::fmt::Debug {
    read_line().split(' ').map(|a| a.trim().parse().unwrap()).collect()
}

use std::time::Instant;
fn main() {
    let _ = read::<usize>();
    let aa = readv::<usize>();
    let bb = readv::<usize>();
    let x = aa.iter().fold(0, |acc, &a| acc ^ a);
    let (mut aa, bb): (Vec<_>, Vec<_>) = aa.iter().zip(bb.iter()).filter(|&(&a, &b)| a != b).unzip();
    let n = aa.len();
    aa.push(x);
    let mut nums = HashMap::with_capacity(n + 1);
    for &a in &aa {
        *nums.entry(a).or_insert(0) += 1;
    }
    // let mut nums: HashMap<_, i32> = aa.iter()
    //     .fold(HashMap::with_capacity(n + 1), |mut acc, &a| { *acc.entry(a).or_insert(0) += 1; acc });
    for &b in &bb {
        *nums.entry(b).or_insert(0) -= 1;
        if nums[&b] < 0 {
            println!("{}", -1);
            return;
        }
    }

    let mut dests = bb.iter().enumerate()
        .fold(HashMap::new(), |mut acc, (a, b)| { (acc.entry(b).or_insert(Vec::new())).push(a); acc });
    let mut q: VecDeque<_> = std::iter::once(n).collect();
    let mut rems: BTreeSet<_> = (0..n + 1).collect();
    let mut r2: HashSet<_> = (0..n + 1).collect();
    let mut ans = n;
    #[cfg(local)] println!("{}: {:?}", "(aa, bb)", (&aa, &bb));
    let mut cnt = 1;
    while !rems.is_empty() {
        while let Some(s_idx) = q.pop_front() {
            r2.remove(&s_idx);
            if !rems.remove(&s_idx) { continue; }
            let s_num = aa[s_idx];
            // if let Some(destv) = dests.remove(&s_num) {
            //     for dest in destv {
            //         q.push_back(dest);
            //     }
            // }
            if let Some(destv) = dests.get_mut(&s_num) {
                for &dest in destv.iter() {
                    q.push_back(dest);
                }
                destv.clear();
            }
        }
        if let Some(&rem) = rems.iter().next() {
            q.push_back(rem);
            ans += 1;
        }
        if let Some(&r) = r2.iter().next() {
            cnt += r;
        }
    }
    if cnt > 1e18 as usize{
        println!("{}", "hoge");
    }
    println!("{}", ans);
    std::process::exit(0);
}


Measured memory_bytes: 27576
#include <iostream>

using namespace std;
#include <string>
typedef long long int ll;
#include <algorithm>
#include <stack>
#include <vector>
#include <array>
#include <queue>
#include <bitset>
#include <math.h>

int main(){

  int N;
  cin >> N;
  string a,b;
  cin >> a >> b;

  string c = "";
  for(int i=0;i<N;i++){
    c += a[i];
    c += b[i];
  }

  cout << c;

  return 0;

}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<(n);i++)
typedef long long ll;
int g(int a,int b){
  int r=a%b;
  if(r){
    g(b,r);
  }else return b;
}
int main(){
  ll a,b,c,d;
  cin>>a>>b>>c>>d;
  ll ac,ad,bc,bd,al,bl;
  ac=a/c;
  if(a%c==0)ac--;
  ad=a/d;
  if(a%d==0)ad--;
  bc=b/c;
  bd=b/d;
  int gcd=g(c,d);
  ll lcm=c*d/gcd;
  al=a/lcm;
  if(a%lcm==0)al--;
  bl=b/lcm;
  ll nans=bc-ac+bd-ad+al-bl;
  ll n=b-a+1;
  ll ans=n-nans;
  cout<<ans<<endl;
  
  
}

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

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

    double n;
    while(cin >> n && n >= 0){

        int data[12];
        int m = 128;
        for(int i = 0; i < 8; ++i){
            if(n >= m){
                n -= m;
                data[i] = 1;
            }
            else
                data[i] = 0;
            m /= 2;
        }

        double m2 = 0.5;
        for(int i = 8; i < 12; ++i){
            if(n >= m2){
                n -= m2;
                data[i] = 1;
            }
            else
                data[i] = 0;
            m2 /= 2;
        }

        if(n != 0){
            cout << "NA" << endl;
        }
        else {
            for(int i = 0; i < 8; ++i){
                cout << data[i];
            }
            cout << '.';
            for(int i = 8; i < 12; ++i){
                cout << data[i];
            }
            cout << endl;
        }
    }

   return 0;
}

Measured memory_bytes: 1236
import std.stdio,
      std.array,
      std.conv,
      std.string,
      std.algorithm;

/// ax + by = c 3x + 2y =
/// dx + ey = f x + 3y =
/// 0:a 1:b 2:c 3:d 4:e 5:f
void main(){
  string s;
  for(;;){
    s=readln();
    if(stdin.eof()) break;
    string[] input = split(s);
    double[] params = new double[6];
    for(int j = 0; j < 6;j++){
      params[j] = to!double(input[j]);
    }
    double y =  (params[2]*params[3] - params[5]*params[0]) / (params[1]*params[3] - params[4]*params[0]);
    double x = (params[2] - params[1]*y) / params[0];
    writef("%.3f %.3f\n",x,y);
  }
}

Measured memory_bytes: 2412
n,k = (int(x) for x in input().split())
to = [int(x) for x in input().split()]
st = [True] * n
root = []

now = 1
while(k > 0 and st[now - 1]):
    root.append(now)
    #print(now,"->",end="")
    st[now - 1] = False
    now = to[now - 1]
    k -=1

if k > 0:
    value = root.index(now)
    k %= len(root[value:])
    #print("k = ",k)
    for i in range(k):
        now = to[now-1]
    print(now)
else:
    print(now)


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

#ifdef DEBUG
#include "debug.h"
#endif

using namespace std;

#define mp make_pair
#define mt make_tuple
#define all(a) (a).begin(), (a).end()
#define rep(i, a, b) for (int (i) = (a); (i) < (b); ++(i))
#define sz(a) ((int)(a).size())
#define make_unique(a) (a).resize(unique(all((x))) - (x).begin())

typedef long long ll;

template<typename T> inline bool mmin(T& a, const T &b) { return b < a ? (a = b, true) : false; }
template<typename T> inline bool mmax(T& a, const T &b) { return b > a ? (a = b, true) : false; }

int main() {
    std::ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    
    int a, b;
    cin >> a >> b;
    if (a + b == 15) {
        cout << "+\n";
    } else if (a * b == 15){
        cout << "*\n";
    } else {
        cout << "x\n";
    }
    
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const long long INF = 1LL << 60;
const ll C = 1e9+7;

int main() {
    int N;
    cin >> N;
    int A[2][N];

    for(int i=0; i<2; i++) for(int j=0; j<N; j++) cin >> A[i][j];

    int max_candy = 0, up_count = 0;

    for(int i=0; i<N; i++) {
        up_count += A[0][i];
        int count = up_count;
        for(int j=i; j<N; j++) {
            count += A[1][j];
        }
        max_candy = max(max_candy, count);
    }

    cout << max_candy << endl;
}

Measured memory_bytes: 3608
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int MAXN=1e6+5;
int tab[MAXN];
 
int main(){
    ios::sync_with_stdio(0);
    cout.tie(0);
    cin.tie(0);
    string s;
    cin >> s;
    int n=s.size();
    int res=n;
    for(int i=1;i<n;i++)
		if(s[i]!=s[i-1]) res=min(res,max(i,n-i));
	cout << res;	
}

Measured memory_bytes: 512
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using static System.Console;
using static System.Math;

namespace AtTest.ABC_138
{
    class D
    {
        static void Main(string[] args)
        {
            var sw = new System.IO.StreamWriter(OpenStandardOutput()) { AutoFlush = false };
            SetOut(sw);

            Method(args);

            Out.Flush();
        }

        static void Method(string[] args)
        {
            int[] nq = ReadInts();
            int n = nq[0];
            int q = nq[1];
            List<int>[] graph = new List<int>[n];
            int[] parents = new int[n];
            for (int i = 0; i < n; i++)
            {
                graph[i] = new List<int>();
            }
            for (int i = 0; i < n - 1; i++)
            {
                int[] ab = ReadInts();
                graph[ab[0] - 1].Add(ab[1] - 1);
                graph[ab[1] - 1].Add(ab[0] - 1);
            }
            parents[0] = -1;
            Queue<int> queue = new Queue<int>();
            queue.Enqueue(0);
            while (queue.Count > 0)
            {
                int now = queue.Dequeue();
                for(int i = 0; i < graph[now].Count; i++)
                {
                    int to = graph[now][i];
                    if (parents[now] == to) continue;
                    parents[to] = now;
                    queue.Enqueue(to);
                }
            }
            long[] cnts = new long[n];
            for(int i = 0; i < q; i++)
            {
                int[] px = ReadInts();
                cnts[px[0] - 1] += px[1];
            }

            queue.Enqueue(0);
            while (queue.Count > 0)
            {
                int now = queue.Dequeue();
                for(int i = 0; i < graph[now].Count; i++)
                {
                    int to = graph[now][i];
                    if (parents[now] == to) continue;
                    cnts[to] += cnts[now];
                    queue.Enqueue(to);
                }
            }

            for(int i = 0; i < n; i++)
            {
                Write(cnts[i]);
                if (i < n - 1) Write(' ');
            }
        }

        private static string Read() { return ReadLine(); }
        private static char[] ReadChars() { return Array.ConvertAll(Read().Split(), a => a[0]); }
        private static int ReadInt() { return int.Parse(Read()); }
        private static long ReadLong() { return long.Parse(Read()); }
        private static double ReadDouble() { return double.Parse(Read()); }
        private static int[] ReadInts() { return Array.ConvertAll(Read().Split(), int.Parse); }
        private static long[] ReadLongs() { return Array.ConvertAll(Read().Split(), long.Parse); }
        private static double[] ReadDoubles() { return Array.ConvertAll(Read().Split(), double.Parse); }
    }
}


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

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

    ll ans = 0;

    bool finish = false;

    if (k == a)
    {
        ans = a;
        finish = true;
    }
    else if (k > a)
    {
        ans += a;
        k = k - a;
    }
    else if (k < a)
    {
        ans += k;
        finish = false;
    }

    if (k == b && !finish)
    {
        finish = true;
    }
    else if (k > b && !finish)
    {
        k = k - b;
    }
    else if (k < b && !finish)
    {
        finish = true;
    }

    if (k == c && !finish)
    {
        ans -= c;
        finish = true;
    }
    else if (k > c && !finish)
    {
        ans -= c;
        k = k - c;
    }
    else if (k < c && !finish)
    {
        ans -= k;
        finish = true;
    }

    cout << ans << endl;
}

Measured memory_bytes: 3636
#define ENABLE_DEBUG 1
// Kana's kitchen {{{
#include<bits/stdc++.h>
#define ALL(v) std::begin(v),std::end(v)
#define LOOP(k) for(i64 ngtkana_is_a_genius=0; ngtkana_is_a_genius<(i64)k; ngtkana_is_a_genius++)

using i32 = std::int_least32_t;
using i64 = std::int_least64_t;
using u32 = std::uint_least32_t;
using u64 = std::uint_least64_t;
using usize = std::size_t;

template <class T, class U> using pair = std::pair<U, T>;
template <class T> using diag_pair = std::pair<T, T>;
template <class... Args> using tuple = std::tuple<Args...>;
template <class T> using vec = std::vector<T>;
template <class T> using numr = std::numeric_limits<T>;

#ifdef NGTKANA
#include<debug.hpp>
#else
#define DEBUG(...)(void)0
#endif
/*}}}*/
template<std::size_t Idx, class Container, class Value = std::tuple_element_t<Idx, typename Container::value_type>>
auto project(Container const& container) {
    std::vector<Value> ans(container.size());
    std::transform(ALL(container), ans.begin(), [](auto&& tuple){ return std::get<Idx>(tuple);});
    return ans;
}
void err() {
    std::cout << -1 << '\n';
    exit(0);
}
auto xor_fn = [](auto x, auto y) { return x ^ y; };
int main(){
    std::cin.tie(nullptr);
    std::ios::sync_with_stdio(false);
    std::cout << std::setprecision(15) << std::fixed;

    usize n, m;
    std::cin >> n >> m;
    vec<pair<i64, i64>> abi(n);
    for (usize i=0; i<n; i++) {
        i64 x, y;
        std::cin >> x >> y;
        abi.at(i) = std::make_pair(x, y);
    }
    std::sort(ALL(abi));
    auto a = project<0>(abi);
    auto b = project<1>(abi);

    vec<vec<pair<usize, usize>>> g(n+1);
    for (usize i=0; i<m; i++) {
        i64 x, y;
        std::cin >> x >> y;
        usize u = std::lower_bound(ALL(a), x)-a.begin();
        usize v = std::lower_bound(ALL(a), y+1)-a.begin();
        g.at(u).emplace_back(v, i);
        g.at(v).emplace_back(u, i);
    }

    std::adjacent_difference(ALL(b), b.begin(), xor_fn);
    b.push_back(std::accumulate(ALL(b), i64{0}, xor_fn));

    vec<usize> ans, ckd(n+1);
    auto dfs = [&](auto&& f, usize x) -> void {
        ckd.at(x) = true;
        for (auto&& e: g.at(x)) {
            usize y, i;
            std::tie(y, i) = e;
            if (!ckd.at(y)) {
                f(f, y);
                if (b.at(y)) {
                    b.at(y) ^= 1;
                    b.at(x) ^= 1;
                    ans.push_back(i);
                }
            }
        }
    };
    for (usize i=0; i<n+1; i++) if (!ckd.at(i)) {
        dfs(dfs, i);
        if (b.at(i)) err();
    }
    std::sort(ALL(ans));
    std::cout << ans.size() << '\n';
    for (usize i=0; i<ans.size(); i++) std::cout << (i? " " : "") << 1+ans.at(i); std::cout << '\n';
}


Measured memory_bytes: 22768
import sys
## io
IS = lambda: sys.stdin.readline().rstrip()
II = lambda: int(IS())
MII = lambda: list(map(int, IS().split()))
MIIZ = lambda: list(map(lambda x: x-1, MII()))
## dp
INIT_VAL = 0
DP2 = lambda d1, d2: [[INIT_VAL]*d2 for _ in range(d1)]
DP3 = lambda d1, d2, d3: [[[INIT_VAL]*d3 for _ in range(d2)] for _ in range(d1)]
## math
DIVC = lambda x, y: -(-x//y)
DIVF = lambda x, y: x//y

def main():
    a,b,c,x = [II() for _ in range(4)]
    cnt = 0
    for i in range(a+1):
        for j in range(b+1):
            k = (x-(i*500+j*100))//50
            if 0 <= k <= c: cnt += 1
    print(cnt)


if __name__ == '__main__':
    main()


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

#ifdef SG
	#include <debug.h>
#else
	template<typename T> struct outputer;
	struct outputable {};
	#define PRINT(...)
	#define OUTPUT(...)
	#define show(...)
	#define debug(...)
	#define deepen(...)
	#define timer(...)
	#define fbegin(...)
	#define fend
	#define pbegin(...)
	#define pend
#endif

#define ARG4(_1,_2,_3,_4,...) _4

#define forn3(i,l,r) for (int i = int(l); i < int(r); ++i)
#define forn2(i,n) forn3 (i, 0, n)
#define forn(...) ARG4(__VA_ARGS__, forn3, forn2) (__VA_ARGS__)

#define ford3(i,l,r) for (int i = int(r) - 1; i >= int(l); --i)
#define ford2(i,n) ford3 (i, 0, n)
#define ford(...) ARG4(__VA_ARGS__, ford3, ford2) (__VA_ARGS__)

#define ve vector
#define pa pair
#define tu tuple
#define mp make_pair
#define mt make_tuple
#define pb emplace_back
#define fs first
#define sc second
#define all(a) (a).begin(), (a).end()
#define sz(a) ((int)(a).size())

typedef long double ld;
typedef int64_t ll;
typedef uint64_t ull;
typedef uint32_t ui;
typedef uint16_t us;
typedef uint8_t uc;
typedef pa<int, int> pii;
typedef pa<int, ll> pil;
typedef pa<ll, int> pli;
typedef pa<ll, ll> pll;
typedef ve<int> vi;

template<typename T> inline auto sqr (T x) -> decltype(x * x) {return x * x;}
template<typename T1, typename T2> inline bool umx (T1& a, T2 b) {if (a < b) {a = b; return 1;} return 0;}
template<typename T1, typename T2> inline bool umn (T1& a, T2 b) {if (b < a) {a = b; return 1;} return 0;}

struct Input {
	int a, b, c;
	
	bool read () {
		return !!(cin >> a >> b >> c);
	}

	void init (const Input &input) {
		*this = input;
	}
};

struct Data: Input {
	int ans;
	
	void write () {
		cout << ans << endl;	
	}
};


namespace Main {
	
	struct Solution: Data {
		
		void solve () {
			ans = 0;
			forn (i, 1000) {
				if (a % 2 || b % 2 || c % 2) {
					return;
				}
				int a1 = b / 2 + c / 2;
				int b1 = c / 2 + a / 2;
				int c1 = a / 2 + b / 2;
				a = a1;
				b = b1;
				c = c1;
				++ans;
			}
			ans = -1;
		}
		
		void clear () {
			*this = Solution();
		}
	};
}


Main::Solution sol;

int main () {
	cout.setf(ios::showpoint | ios::fixed);
	cout.precision(20);

	#ifdef SG
		freopen((problemname + ".in").c_str(), "r", stdin);
//		freopen((problemname + ".out").c_str(), "w", stdout);
		while (sol.read()) {
			sol.solve();
			sol.write();
			sol.clear();
		}
	#else
		sol.read();
		sol.solve();
		sol.write();
	#endif
	
	/*
	int t;
	cin >> t;
	forn (i, t) {
		sol.read();
		sol.solve();
		sol.write();
		sol.clear();
	}
	*/
	
	return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <vector>
#define rep(i,n) for(int i=0;i<n;++i)
#define rep1(i,n) for(int i=1;i<=n;++i)
using namespace std;
int main()
{
  int r;cin >> r;
  cout << 3*r*r << "\n";
  return 0;
}


Measured memory_bytes: 256
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#define ll long long
#define rep(i,l,r)for(ll i=(l);i<(r);i++)
int upll(const void*a, const void*b){return*(ll*)a<*(ll*)b?-1:*(ll*)a>*(ll*)b?1:0;}
void sortup(ll*a,int n){qsort(a,n,sizeof(ll),upll);}

ll a[200010];
int main(){
	int n;
	scanf("%d",&n);
	rep(i,0,n)scanf("%lld",a+i);
	sortup(a,n);
	ll l1=-1,r1=n-1;//lはOK,rはNG,a[n-1]/2以下で最大を探す
	while(r1-l1>1){
		ll m=(l1+r1)/2;
		if(a[m]<=(a[n-1]+1)/2)l1=m;
		else r1=m;
	}
	ll l2=-1,r2=n;//lはNG,rはOK,(a[n-1]+1)/2以上で最小を探す
	while(r2-l2>1){
		ll m=(l2+r2)/2;
		if(a[m]>=(a[n-1]+1)/2)r2=m;
		else l2=m;
	}
	if(r2==n)printf("%lld %lld\n",a[n-1],a[l1]);
	else if(l1==-1)printf("%lld %lld\n",a[n-1],a[r2]);
	else printf("%lld %lld\n",a[n-1],a[l1]<a[n-1]-a[r2]?a[r2]:a[l1]);
	return 0;
}



Measured memory_bytes: 1788
import sys
from collections import deque

read = sys.stdin.read
readline = sys.stdin.buffer.readline
sys.setrecursionlimit(10 ** 8)
INF = float('inf')
MOD = 10 ** 9 + 7


def main():
    H, W = map(int, readline().split())
    sh, sw = map(int, readline().split())
    gh, gw = map(int, readline().split())
    sh -= 1
    sw -= 1
    gh -= 1
    gw -= 1
    S = read().split()

    dist = [[INF] * W for _ in range(H)]
    walk = ((1, 0), (-1, 0), (0, 1), (0, -1))
    warp = ((-2, -2), (-2, -1), (-2, 0), (-2, 1), (-2, 2), (-1, -2), (-1, -1), (-1, 1), (-1, 2),
            (0, -2), (0, 2), (1, -2), (1, -1), (1, 1), (1, 2), (2, -2), (2, -1), (2, 0), (2, 1), (2, 2))

    Q = deque()
    Q.append((sh, sw))
    Q2 = deque()
    dist[sh][sw] = 0

    while Q:
        while Q:
            h, w = Q.popleft()
            d = dist[h][w]
            flag = 0
            for dh, dw in walk:
                nh = h + dh
                nw = w + dw
                if 0<=nh<H and 0<=nw<W:
                    if S[nh][nw] == '.':
                        if dist[nh][nw] > d:
                            dist[nh][nw] = d
                            Q.append((nh,nw))
                    else:
                        flag += 1
            if flag:
                Q2.append((h,w))
        while Q2:
            h, w = Q2.popleft()
            d = dist[h][w]
            for dh, dw in warp:
                nh = h + dh
                nw = w + dw
                if 0<=nh<H and 0<=nw<W:
                    if S[nh][nw] == '.' and dist[nh][nw] == INF:
                        dist[nh][nw] = d + 1
                        Q.append((nh,nw))
    if dist[gh][gw] != INF:
        print(dist[gh][gw])
    else:
        print(-1)



if __name__ == '__main__':
    main()


Measured memory_bytes: 100460
#include <algorithm>
#include <iostream> //標準入出力
#include <fstream>  //ファイルでの入出力
#include <vector>
#include <queue>
#include <functional>
#include <string>
#include <utility> //pair
#include <cmath>  //sqrt 
#include <iomanip> //setprecision
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define ll long long
#define ALL(a)  (a).begin(),(a).end()
#define MAX 1000000007
#define pair(a) pair<a,a>

void _main(){
    ll ma = 0;
    ll k,n; cin >> k >> n;
    ll a0,a1,a2;cin >> a0;
    a1=a0;
    rep(i,n-1){
        cin >> a2;
        ma = max(ma,abs(a2-a1));
        a1 = a2;
    }
    ma=max(ma,a0+k-a2);
    cout << k-ma << endl;
    return;
}
int main() {
    cout << fixed << setprecision(10);
    _main();
    return 0;
}

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

int main(){
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  ll N;
  cin >> N;
  vll A(N);
  map<ll, ll> ma;
  for(int i = 0; i < N; i++){
    cin >> A.at(i);
    if(!ma.count(A.at(i))) ma[A.at(i)]++;
    else ma.at(A.at(i))++;
  }
  ll one = 0, two = 0;
  for(auto i = ma.begin(); i != ma.end() ; i++){
    ll num = i -> second;
    if(num % 2 == 1) one++;
    else two++;
  }
  one += two / 2 * 2;
  two %= 2;
  cout << one << endl;
}

Measured memory_bytes: 7296
N,K=map(int,input().split())
x=list(map(int,input().split()))
a=[None]*(N-K+1)
for i in range(N-K+1):
    if x[i]<0 and x[i+K-1]>0:
        if x[i]+x[i+K-1]>0:
            a[i]=-2*x[i]+x[i+K-1]
        else:
            a[i]=-x[i]+2*x[i+K-1]
    elif x[i]>=0:
        a[i]=x[i+K-1]
    else:
        a[i]=-x[i]
print(min(a))

Measured memory_bytes: 14780
import Control.Monad
import Data.Maybe
import qualified Data.ByteString.Char8 as BS

tuplify2 (x:y:_) = (x,y)
tuplify2 _ = undefined

--Input functions with ByteString
readInt = fst . fromJust . BS.readInteger
readIntTuple = tuplify2 . map readInt . BS.words
readIntList = map readInt . BS.words

getInt = readInt <$> BS.getLine
getIntList = readIntList <$> BS.getLine
getIntNList n = map readIntList <$> replicateM (fromIntegral n) BS.getLine
getIntMatrix = map readIntList . BS.lines <$> BS.getContents
getIntTuple = readIntTuple <$> BS.getLine
getIntNTuples n = map readIntTuple <$> replicateM (fromIntegral n) BS.getLine
getIntTuples = map readIntTuple . BS.lines <$> BS.getContents

main = do
    a <- getIntNList 3
    n <- getInt
    b <- replicateM (fromIntegral n) getInt
    let a1 = foldr (\x acc -> if x `elem` b then acc else False) True (a!!0)
    let a2 = foldr (\x acc -> if x `elem` b then acc else False) True (a!!1)
    let a3 = foldr (\x acc -> if x `elem` b then acc else False) True (a!!2)
    let a4 = foldr (\x acc -> if x `elem` b then acc else False) True ([a!!0!!0, a!!1!!0, a!!2!!0])
    let a5 = foldr (\x acc -> if x `elem` b then acc else False) True ([a!!0!!1, a!!1!!1, a!!2!!1])
    let a6 = foldr (\x acc -> if x `elem` b then acc else False) True ([a!!0!!2, a!!1!!2, a!!2!!2])
    let a7 = foldr (\x acc -> if x `elem` b then acc else False) True ([a!!0!!0, a!!1!!1, a!!2!!2])
    let a8 = foldr (\x acc -> if x `elem` b then acc else False) True ([a!!0!!2, a!!1!!1, a!!2!!0])
    putStrLn $ if a1||a2||a3||a4||a5||a6||a7||a8 then "Yes" else "No"

Measured memory_bytes: 380
#include<bits/stdc++.h>
using namespace std;
template <typename T> using vec = vector<T>;

const int MOD = 1e9 + 7;
vector<long long> fact, fact_inv, inv;
/*  init_nCk :二項係数のための前処理
    計算量:O(n)
*/
void init_nCk(int SIZE) {
    fact.resize(SIZE + 5);
    fact_inv.resize(SIZE + 5);
    inv.resize(SIZE + 5);
    fact[0] = fact[1] = 1;
    fact_inv[0] = fact_inv[1] = 1;
    inv[1] = 1;
    for (int i = 2; i < SIZE + 5; i++) {
        fact[i] = fact[i - 1] * i % MOD;
        inv[i] = MOD - inv[MOD % i] * (MOD / i) % MOD;
        fact_inv[i] = fact_inv[i - 1] * inv[i] % MOD;
    }
}
/*  nCk :MODでの二項係数を求める(前処理 int_nCk が必要)
    計算量:O(1)
*/
long long nCk(int n, int k) {
    assert(!(n < k));
    assert(!(n < 0 || k < 0));
    return fact[n] * (fact_inv[k] * fact_inv[n - k] % MOD) % MOD;
}

int main()
{
    init_nCk(2000);
    int n;
    cin >> n;
    long ans = 0;
    for(int k = 1; k <= (n/3); k++)
    {
        int n_new = n-3*k;
        ans += nCk(n_new + k - 1, n_new);
        ans %= MOD;
        //cerr << ans << endl;
    }
    cout << ans << endl;
}

Measured memory_bytes: 3680
while True:
    n = int(input())
    if n==0:
        break

    f = list(input().split())
    cnt = 0
    rf = 0
    lf = 0
    foot = 0
    for i in range(n):
        if lf==0 and f[i]=="lu":
            lf = 1
        elif rf==0 and f[i]=="ru":
            rf = 1
        if foot==0 and lf==1 and rf==1:
            cnt += 1
            foot = 1
        if lf==1 and f[i]=="ld":
            lf = 0
        elif rf==1 and f[i]=="rd":
            rf = 0
        if foot==1 and lf==0 and rf==0:
            cnt += 1
            foot = 0
    print(cnt)


Measured memory_bytes: 5612
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.StringTokenizer;


class Main{

	static int len;
	static int[] arr;

	//メインメソッド
	public static void main(String[] args) throws IOException{
		BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
		int len = Integer.parseInt(reader.readLine());
		int[] arr = new int[len];
		//配列の要素数を1行目から読み取る

		String arrStr = reader.readLine();
        //2行目から配列の要素を読み取る
		StringTokenizer tokenizer = new StringTokenizer(arrStr," ");

		int i = 0;
		while(tokenizer.hasMoreElements()){
			arr[i++] = Integer.parseInt((String)tokenizer.nextElement());
		}
		reader.close();
        
        write(arr);
    
        
        //並べるメソッド
		sort(arr);
	}
	

	//引数は配列、返り値はなしでprintのみ。
	//ソートメソッド
	//printのタイミング・・？

	public static void sort(int[] arr){
        for(int i=1;i<arr.length;i++){
            int key = arr[i];
            int j = i-1;
            //System.out.println(arr[j]);
			while(j>=0 && arr[j]>key){
				int change = arr[j];
				arr[j]=key;
				arr[j+1]=change;
                j--;
			}
			write(arr);
		}
	}
	
	public static void write(int[] arr){
		for(int i=0;i<arr.length-1;i++){
			System.out.print(arr[i]+" ");
		}System.out.println(arr[arr.length-1]);
	}

}

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

#define sz(a) (int)a.size()
#define re return
#define fi first
#define se second
#define pb push_back
#define all(a) a.begin(), a.end()
#define gr greater <int>

#pragma GCC optimize("Ofast")
#pragma GCC optimize("no-stack-protector")
#pragma GCC optimize("unroll-loops")
#pragma GCC target("sse,sse2,sse3,ssse3,popcnt,abm,mmx,tune=native")
#pragma GCC optimize("fast-math")

using namespace std;

typedef long long ll;
typedef string str;
typedef long double ld;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef vector<ll> vll;
typedef vector<int> vi;

///!!!<3<3<3<3<3!!!
void ProdamGaraje () {
   int a, b, c, d;
   cin >> a >> b >> c >> d;
   while (a > 0 && c > 0) {
      a -= d;
      c -= b;
   }
   if (a <= 0 && c <= 0) {
      cout << "Yes";
      re;
   }

   if (a <= 0) {
      cout << "No";
      re;
   }
   cout << "Yes";
}
///!!!<3<3<3<3<3!!!
int main () {
   //freopen ("input.txt", "r", stdin);
   //freopen ("output.txt", "w", stdout);
   ios::sync_with_stdio(0);
   cin.tie(0); cout.tie(0);
   int tt = 1;
   //cin >> tt;
   while (tt--)
      ProdamGaraje ();
}
///GOOOOOOSE!!!!
/*
     ▄▀▀▀▄
▄███▀░0░░░▌
    ▌░░░░░▐
    ▌░░░░░▐
     ▌▌ ▌▌
     ▌▌ ▌▌
     ▌▌ ▌▌
     ▌▌ ▌▌
     ▌▌ ▌▌
   ▄▄▌▌▄▌▌        */


Measured memory_bytes: 3668
import java.util.*;
import static java.lang.System.*;

public class Main{
  public static void main(String[] args){
	  Scanner sc = new Scanner(System.in);
	  
	  int N = sc.nextInt();
	  int[] H = new int[N];
	  for(int i=0; i<N; i++) {
		  H[i] = sc.nextInt();
	  }
	 int[] DP = new int[N];
	 DP[0] = 0; DP[1] = H[1] - H[0];  if(DP[1]< 0) DP[1]= -DP[1];
	 
	 for(int i = 2; i< N; i++) {
		 int oneD = Math.abs(H[i] - H[i - 1]); 
		 int twoD = Math.abs(H[i] - H[i - 2]); 
		 int oneStep = DP[i-1] + oneD;
		 int twoStep = DP[i-2] + twoD;
		 //現在の地点までの最短距離= 直前の地点までの最短距離（DP）+その地点から現在の地点までの移動距離

		 //候補が２つしかないから1行で済んでるが、比較対象が多数にわたる場合は・・・
		 int dp = oneStep > twoStep ? twoStep: oneStep;
		 DP[i] = dp;	
	 }
	out.println(DP[N - 1]);
  }
}

Measured memory_bytes: 48736
#include <iostream>
#include <vector>
#include <cmath>
#include <iomanip>//cout << fixed << setprecision() <<
#include <set>
#include <map>
using ll = long long;
using namespace std;

double Mcos(double k){return cos(k*atan(1.0)*4/180);}
double Msin(double k){return sin(k*atan(1.0)*4/180);}

int main(void){
    string s;
    cin>>s;
    if(s=="AAA" || s=="BBB")cout<<"No";
    else cout<<"Yes";
}


Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<cstring>
#include<cmath>
#define ll long long
using namespace std;
const int N=2e5+2;
ll n,a[N],ans=1e17,tot;
int main() {
	scanf("%lld",&n);
	for (int i=1;i<=n;i++) {
		scanf("%lld",&a[i]);
		tot+=a[i];
	}
	ll now=0;
	for (int i=1;i<n;i++) {
		now+=a[i];
		ans=min(ans,(ll)abs(tot-now-now));
	}
	printf("%lld",ans);
	return 0;
}

Measured memory_bytes: 1792
#include "atcoder/dsu"
#include <bits/stdc++.h>
using namespace std;
///////////////////////////////////////////
const long long int INF = 1LL<<60;
const long long int Mod = 1000000007;
using ll = long long int; using ci = const int;
using vi = vector<int>;  using Vi = vector<long long int>;
using P = pair<int, int>;  using PLL = pair<ll, ll>;
using matrix = vector<vector<ll>>;
#define pb(x) push_back(x)
#define mp(x,y) make_pair(x,y)
#define all(x) (x).begin(),(x).end()
#define rp(i,N) for(ll i = 0; i < (ll)N; i++)
#define repi(i,a,b) for(ll i = ll(a); i < ll(b); ++i)
template<class T>bool chmax(T &former, const T &b) { if (former<b) { former=b; return true; } return false; }
template<class T>bool chmin(T &former, const T &b) { if (b<former) { former=b; return true; } return false; }
template<class T>T sqar(T x){ return x*x; }//sqrt(x)は平方根;
#define Sort(v) std::sort(v.begin(), v.end(), std::greater<decltype(v[0])>()) //降順でVをソート
#define p_queue(v) priority_queue<v, vector<v>, greater<v> >
template<class T> inline void princ(T x){cout<<x<<" ";}; 
template<class T> inline void print(T x){cout<<x<<"\n";};
template<class T> inline void Yes(T condition){ if(condition) cout << "Yes" << endl; else cout << "No" << endl; }
template<class T> inline void YES(T condition){ if(condition) cout << "YES" << endl; else cout << "NO" << endl; }
///////////////////////////////////////////////////////////////////////////////////

void solve(){
    ll n,q;
    cin >> n >> q;
    atcoder::dsu uf(n);
    while(q--){
        ll t,u,v;
        cin >> t >> u >> v;
        if(t==0){
            uf.merge(u,v);
        }else{
            if(uf.same(u,v)){
                print(1);
            }else{
                print(0);
            }
        }
    }
    return;
}
int main(){
    cin.tie(0);ios::sync_with_stdio(false);
    std::cout<<std::fixed<<std::setprecision(30);
    solve();
    return 0;
}

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

using namespace std;
using ll = long long;
using P = pair<int,int>;
using Pl = pair<ll,ll>;
#define REP(i,n) for(ll i = 0;i < (ll)n;i++)
#define REPD(i,n) for(ll i = (ll)n - 1;i >= 0;i--)
#define ALL(x) (x).begin(),(x).end()
#define FILLl(n,first_dimension_size,value) fill((ll*)n,(ll*)(n+first_dimension_size),value)
#define FILL(n,first_dimension_size,value) fill((int*)n,(int*)(n+first_dimension_size),value)
#define INF (1 << 30)
#define MOD 1000000007
//int dy[4] = {-1,0,0,1};
//int dx[4] = {0,1,-1,0};

ll dist[200200];

int main(){

  int n,m;
  cin >> n >> m;
  vector<vector<int>> v(n);
  REP(i,m){
    int x,y;cin >> x >> y;
    x--,y--;
    v[x].push_back(y);
    v[y].push_back(x);
  }
  queue<int> que;
  que.push(0);
  FILLl(dist,200200,-1);
  dist[0] = 0;
  while(!que.empty()){
    ll ov = que.front();que.pop();
    for(auto nv : v[ov]){
      if(dist[nv] != -1)continue;
      dist[nv] = dist[ov] + 1;
      que.push(nv);
    }
  }
  if(dist[n-1] != -1 && dist[n-1] <= 2)cout << "POSSIBLE" << endl;
  else cout << "IMPOSSIBLE" << endl;





  return 0;
}

Measured memory_bytes: 13936
#include <bits/stdc++.h>
#define rep(i, a, b) for(int i = a; i < b; i++)
#define Rep(i, a, b) for(int i = a; i <= b; i++)
#define _GLIBCXX_DEBUG
#define Vl vector<ll>
#define Vs vector<string>
#define Vp vector<pair<ll, ll>>
#define ll long long
#define ALL(v) (v).begin(),(v).end()
using namespace std;  
const double pi = acos(-1.0);
const ll MOD = 1e9 + 7;
const ll INF = 1LL << 60;

//最大公約数
ll gcd(ll a, ll b){
  if (a%b == 0) {
    return(b);
  } else {
    return(gcd(b, a%b));
  }
}

int main() {
  ll n, k; cin >> n >> k;
  Vl a(n);
  rep(i, 0, n){ 
    cin >> a[i];
    if(a[i] == k){
      cout << "POSSIBLE" << endl;
      return 0;
    }
  }
  bool f = true;
  rep(i, 0, n){
    if(a[i] >= k){ 
      f = false;
      }
  }
  if(f){
    cout << "IMPOSSIBLE" << endl;
    return 0;
  }

  sort(ALL(a));

  ll g = a[0];
  rep(i, 1, n-1){
    g = gcd(g, a[i]);
  }

  if(k%g == 0) cout << "POSSIBLE" << endl;
  else cout << "IMPOSSIBLE" << endl;

  return 0;
}


Measured memory_bytes: 1024
#include<iostream>
#include<string>
#include<map>
#include<queue>

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

using namespace std;


class Q{
	public:
	string str;
	int dep;
	//Q(string a,int n){str=a;dep=n;}
	Q(string str, int dep) : str(str), dep(dep) {}
};

int saiki(string imo){
	
	queue<Q> que;
	
	que.push(Q(imo,0));
	
	map<string,int> visit;
	
	while(1){
		
		if(que.empty()==1){
			return -1;
		}
		
		Q u = que.front();
		que.pop();
		
		string s = u.str;
		
		if(visit[s]==1){
			continue;
		}
		visit[s]=1;
		
		
		//printf("%d pop( %s )\n",u.dep,s.c_str());
		char ch=s[0];
		int flg=1;
		rep(i,s.size()-1){
			if(s[i+1]!=ch) {flg=0;break;}
		}
		if(flg==1){
			return u.dep;
		}
		
		rep(i,s.size()-1){
			
			if((s[i]=='r' && s[i+1]=='g')||(s[i+1]=='r' && s[i]=='g')){
				string t=s;
				t[i]=t[i+1]='b';
				que.push(Q(t,u.dep+1));
		//printf("%d push( %s )\n",u.dep,t.c_str());
			}else
			if((s[i]=='b' && s[i+1]=='r')||(s[i+1]=='b' && s[i]=='r')){
				string t=s;
				t[i]=t[i+1]='g';
				que.push(Q(t,u.dep+1));
		//printf("%d push( %s )\n",u.dep,t.c_str());
			}else
			if((s[i]=='g' && s[i+1]=='b')||(s[i+1]=='g' && s[i]=='b')){
				string t=s;
				t[i]=t[i+1]='r';
				que.push(Q(t,u.dep+1));
		//printf("%d push( %s )\n",u.dep,t.c_str());
			}
		}
	}
	return 100;
	
}

int main(){
	while(1){
		string a;
		cin>>a;
		
		if(a=="0"){
			break;
		}
		
		int ans=saiki(a);
		
		if(ans==-1){
			puts("NA");
		}else{
		printf("%d\n",ans);
		}
	}
}

Measured memory_bytes: 2208
def main():
    H, W = map(int,input().split())
    area = H * W
    ans = 10**10
    # 縦に3分割
    for i in range(W//3,W//3+2):
        for j in range(W//3,W//3+2):
            areas = [H*i,H*(W-j-i),H*j]
            ans = min(ans,max(areas)-min(areas))
    # 横に3分割
    for i in range(H//3, H//3+2):
        for j in range(H//3,H//3+2):
            areas = [W*i, W*(H-i-j), W*j]
            ans = min(ans, max(areas)-min(areas))
    
    # 縦に大きく分割したあと横に分割
    for i in range(W//3,W//3+2):
        areas = [H*i]
        w_remain = W - i
        for j in range(H//2,H//2+2):
            h_remain = H - j 
            areas.append(w_remain * j)
            areas.append(w_remain * h_remain)
            ans = min(ans, max(areas)-min(areas))
    
    # 横に大きく分割したあと縦に分割
    for i in range(H//3,H//3+1):
        areas = [W*i]
        h_remain = H - i
        for j in range(W//2, W//2+2):
            w_remain = W - j
            areas.append(h_remain * j)
            areas.append(h_remain * w_remain)
            ans = min(ans, max(areas)-min(areas))


    print(ans)

main()

Measured memory_bytes: 62128
// Problem: B - Substring
// Contest: AtCoder - AtCoder Beginner Contest 177
// URL: https://atcoder.jp/contests/abc177/tasks/abc177_b
// Memory Limit: 1024 MB
// Time Limit: 2000 ms
// Powered by CP Editor (https://github.com/cpeditor/cpeditor)

#include <bits/stdc++.h>
 
using namespace std;
#define int long long
#define ll long long
const int N = 2e5+5;
const int mod = 1e9;
#define ld long double
#define PI 3.14159265358979323846
const int INF = 10000000;
 
void flash()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    cout.setf(ios::fixed);
    cout.setf(ios::showpoint);
    cout.precision(9);
}
 
//3. Structure or classes
//3. Ends here
 
//1. Data structures declaration here
//1. Ends here
 
//2. Extra Functions here
//2. Ends here
 
 
void solve();
int32_t main()
{
    flash();
    int t;
    t = 1;
    //cin>>t;
    while(t--){
        solve();
        //cout<<"\n";
    }
    return 0;
}
 
 
 
void solve()
{
	string s,t;
	cin>>s>>t;
	int ns=s.length();
	int nt=t.length();
	
	int bestMatch=-1;
	
	for(int i=0;i<=ns-nt;i++){
		int cnt=0;
		for(int j=0;j<nt;j++){
			if(s[i+j]==t[j]){
				cnt++;
			}
		}
		bestMatch=max(bestMatch,cnt);
	}
	
	cout<<nt-bestMatch;
    return;
}
// how r u bro

Measured memory_bytes: 3508
from collections import defaultdict

d = defaultdict(int)

N, K, Q = map(int, input().split())
points = {}

for i in range(Q):
    a = int(input())
    d[a] += 1

for i in range(N):
    if K + d[i+1] - Q > 0:
        print("Yes")
    else:
        print("No")
        

Measured memory_bytes: 16156
import sys

INF = 2**31 - 1

SGM = []
n = 0


def init(_n):

    global SGM, n

    n = 1
    while _n > n:
        n *= 2

    SGM = [INF] * (n * 2)


def update(k, x):

    global SGM, n

    k += n - 1  # セグメント木の index に直す
    SGM[k] = x  # i を更新

    # 先祖を更新
    while k > 0:
        k = (k - 1) // 2
        SGM[k] = min(SGM[k * 2 + 1], SGM[k * 2 + 2])


def find(a, b, k, l, r):
    # 節点k がカバーする左側 : l
    # 節点k がカバーする右側 +1 : r

    # 節点 k のエリア [l, r) が、 [a, b) と交差しない場合
    if r <= a or b <= l:
        return INF

    # [a, b) が k -> [l, r) を完全に含む場合
    if a <= l and r <= b:
        return SGM[k]

    # [l, r) に含まれている場合、一段下を捜索
    vl = find(a, b, k * 2 + 1, l, (l + r) // 2)
    vr = find(a, b, k * 2 + 2, (l + r) // 2, r)
    v = min(vl, vr)

    return v


def main():

    global SGM, n
    n, q = map(int, sys.stdin.readline().rstrip().split())

    init(n)

    for i in range(q):
        com, x, y = map(int, sys.stdin.readline().rstrip().split())

        if com == 0:
            update(x, y)
            # print(SGM[n - 1:-1])
        else:
            v = find(x, y + 1, 0, 0, n)  # 区間のとり方の都合上、 y+1 にする
            # print(SGM[n - 1:-1])
            # print(f"find : [{x},{y}]: {v}")
            print(v)


main()



Measured memory_bytes: 9452
#include<cstdio>
#include<algorithm>
#include<queue>
#include<map>
#include<cstring>
using namespace std;
typedef pair<int, int> P;
typedef pair<P, int> T;
#define INF (1 << 30)

priority_queue<T, vector<T>, greater<T> > pq;
int ax, ay, bx, by, n, r, p;
int round, area, left_side, right_side, bottom, top;
int imos[3][10500];
int main(){
    while(scanf("%d%d", &n, &r), r){
	memset(imos, 0, sizeof(imos));
	round = area = 0;
	p = 0;
	left_side = bottom = 10500;
	right_side = top = 1;
	for(int i = 0;i < n;i++){
	    scanf("%d%d%d%d", &ax, &ay, &bx, &by);
	    left_side = min(left_side, ++ax);
	    right_side = max(right_side, ++bx);
	    bottom = min(bottom, ++ay);
	    top = max(top, ++by);	    
	    pq.push(T(P(ax, ay), 1));
	    pq.push(T(P(ax, by), -1));
	    pq.push(T(P(bx, ay), -1));
	    pq.push(T(P(bx, by), 1));
	}
	pq.push(T(P(INF, INF), 0));
	for(int i = left_side;i < right_side + 2;i++){
	    for(int j = bottom;j < top + 2;j++){
		imos[i % 3][j] = imos[i % 3][j - 1];
		while(pq.top().first == P(i, j)){
		    imos[i % 3][j] += pq.top().second;pq.pop();
		}
	    }
	    for(int j = bottom;j < top + 2;j++){
		imos[i % 3][j] += imos[(i - 1) % 3][j];
		if(imos[i % 3][j])area++;
		if(!!imos[i % 3][j] != !!imos[i % 3][j - 1])round++;
		if(!!imos[i % 3][j] != !!imos[(i - 1) % 3][j])round++; 
	    }

	}
	pq.pop();
	printf("%d\n", area);
	if(r == 2)printf("%d\n", round);
    }
    return 0;
}

Measured memory_bytes: 2004