akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h> 
using namespace std;
typedef long long ll;
const int MM = 1000000000;
const int MOD = MM + 7;
const int MAX = 510000;
#define rep(i, n) for(ll i=0; i<n; i++)
#define Rep(i, j, n) for(ll i=j; i<n; i++)
#define all(vec) vec.begin(), vec.end()
template<class T> inline bool chmin(T& a, T b) {if(a > b) {a = b; return true;} return false;}
template<class T> inline bool chmax(T& a, T b) {if(a < b) {a = b; return true;} return false;}
const ll INF = 1LL << 60;

int main() {
    int n; string s; cin >> n >> s;
    int ans = 0;
    rep(i, 10) {
        rep(j, 10) {
            rep(k, 10) {
                int m = 0, n = 0;
                rep(l, s.size()) {
                    if(i == s[l] - '0') {
                        m = l + 1;
                        break;
                    }
                }
                if(m == 0) break;
                Rep(l, m, s.size()) {
                    if(j == s[l] - '0') {
                        n = l + 1;
                        break;
                    }
                }
                if(n == 0) break;
                Rep(l, n, s.size()) {
                    if(k == s[l] - '0') {
                        ans++;
                        break;
                    }
                }
            }
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
# Problem https://atcoder.jp/contests/abc053/tasks/abc053_b
# Ruby 3rd Try
si = gets.chomp.split('')
answer = 0
firsta = 0
lastz = si.size-1
first = firsta
last = lastz
first.step(last,+1){ |j|
    if si[j] == 'A'
        firsta = j
        break
    end
}
last.step(first,-1){ |j|
    if si[j] == 'Z'
        lastz = j
        break
    end
}
answer = (lastz - firsta)+1
puts(answer)

Measured memory_bytes: 16764
/*
Author: CNYALI_LK
LANG: C++
PROG: d.cpp
Mail: cnyalilk@vip.qq.com
*/
#include<bits/stdc++.h>
#define debug(...) fprintf(stderr,__VA_ARGS__)
#define DEBUG printf("Passing [%s] in LINE %d\n",__FUNCTION__,__LINE__)
#define Debug debug("Passing [%s] in LINE %d\n",__FUNCTION__,__LINE__)
#define all(x) x.begin(),x.end()
using namespace std;
const double eps=1e-8;
const double pi=acos(-1.0);
typedef long long ll;
typedef pair<int,int> pii;
template<class T>int chkmin(T &a,T b){return a>b?a=b,1:0;}
template<class T>int chkmax(T &a,T b){return a<b?a=b,1:0;}
template<class T>T sqr(T a){return a*a;}
template<class T>T mmin(T a,T b){return a<b?a:b;}
template<class T>T mmax(T a,T b){return a>b?a:b;}
template<class T>T aabs(T a){return a<0?-a:a;}
#define min mmin
#define max mmax
#define abs aabs
int read(){
	int s=0,base=1;
	char c;
	while(!isdigit(c=getchar()))if(c=='-')base=-base;
	while(isdigit(c)){s=s*10+(c^48);c=getchar();}
	return s*base;
}
char WriteIntBuffer[1024];
template<class T>void write(T a,char end){
	int cnt=0,fu=1;
	if(a<0){putchar('-');fu=-1;}
	do{WriteIntBuffer[++cnt]=fu*(a%10)+'0';a/=10;}while(a);
	while(cnt){putchar(WriteIntBuffer[cnt]);--cnt;}
	putchar(end);
}
int ib[1024][1024],iw[1024][1024];
int readc(){
	char c;
	while(!isalpha(c=getchar()));
	return c=='B';
}
void iw_add(int xa,int xb,int ya,int yb){
	++iw[xa][ya];
	++iw[xb][yb];
	--iw[xa][yb];
	--iw[xb][ya];
}
void ib_add(int xa,int xb,int ya,int yb){
	++ib[xa][ya];
	++ib[xb][yb];
	--ib[xa][yb];
	--ib[xb][ya];
}
int main(){
#ifdef cnyali_lk
	freopen("d.in","r",stdin);
	freopen("d.out","w",stdout);
#endif
	int n,k,x,y,c;
	n=read();
	k=read();
	for(int i=1;i<=n;++i){
		x=read()+k-1;
		y=read()+k-1;
		c=readc();
		c^=(x/k+y/k)&1;
		x%=k;y%=k;
		if(c){
			iw_add(0,k-x,k-y,k);
			iw_add(k-x,k,0,k-y);
			ib_add(0,k-x,0,k-y);
			ib_add(k-x,k,k-y,k);
		}
		else{
			ib_add(0,k-x,k-y,k);
			ib_add(k-x,k,0,k-y);
			iw_add(0,k-x,0,k-y);
			iw_add(k-x,k,k-y,k);
		}
	}
	int ans=0;
	for(int i=0;i<k;++i){
		for(int j=0;j<k;++j){
			if(i)ib[i][j]+=ib[i-1][j];
			if(j)ib[i][j]+=ib[i][j-1];
			if(i&&j)ib[i][j]-=ib[i-1][j-1];
			if(i)iw[i][j]+=iw[i-1][j];
			if(j)iw[i][j]+=iw[i][j-1];
			if(i&&j)iw[i][j]-=iw[i-1][j-1];
			chkmax(ans,ib[i][j]);
			chkmax(ans,iw[i][j]);
		}
	}	
	printf("%d\n",ans);
	return 0;
}



Measured memory_bytes: 8448
N = int(input())
L1 = [list(map(int,input().split())) for i in range(N)]
L2 = [list(map(int,input().split())) for i in range(N)]

L1 = sorted(L1,key=lambda x: x[1],reverse=True)
L2 = sorted(L2,key=lambda x: x[0],reverse=False)

ans = 0

checked = [0 for i in range(N)]

for i in range(N) :
    c,d = L2[i]
    for j in range(N) :
        a,b = L1[j]
        
        if a < c and b < d :
            if checked[j] :
                continue
            ans += 1
            checked[j] = 1
            break

print(ans)

Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
#define fi first
#define se second
#define repl(i,a,b) for(int i=(int)(a);i<(int)(b);i++)
#define rep(i,n) repl(i,0,n)
#define each(itr,v) for(auto itr:v)
#define pb(s) push_back(s)
#define maxch(x,y) x=max(x,y)
#define minch(x,y) x=min(x,y)
#define mp(a,b) make_pair(a,b)
#define all(x) (x).begin(),(x).end()
#define dbg(x) cout<<#x"="<<x<<endl
#define maxch(x,y) x=max(x,y)
#define minch(x,y) x=min(x,y)
#define uni(x) x.erase(unique(all(x)),x.end())
template<class T,class U>inline void chmin(T &t,U f){if(t>f)t=f;}
template<class T,class U>inline void chmax(T &t,U f){if(t<f)t=f;}
#define MAX(a, b) ((a) > (b) ? (a) : (b))
#define MIN(a, b) ((a) > (b) ? (b) : (a))

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> P;
typedef pair<P, int> PPI;

#define INF INT_MAX/3
#define MAX_N 1000

void solve(){
   cin.tie(0);
  ios::sync_with_stdio(false);
  ll n,m,i;
  cin>>n;
  std::map<string,ll> mpn,mpm;
  rep(i,n){
    string s;
    cin>>s;
    mpn[s]++;
  }
  cin>>m;
  // cout<<m<<endl;
  rep(i,m){
    string s;
    cin>>s;
    mpm[s]++;
  }
  ll ans = 0;
  for(auto x:mpn) maxch(ans,x.second-mpm[x.first]);
  cout<<ans<<endl;
}
int main(){
  solve();
  return 0;
}


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

int main(){
    long A,B,K; cin >> A >> B >> K;
    if(A>=K){
        cout << A-K << " " << B << endl;
    }
    //A<K
    else{
        K-=A;
        A=0;
        if(B>=K){
            B-=K;
        }
        else{
            B=0;
       }
       cout << A << " " << B << endl;
    }
}

Measured memory_bytes: 256
import math

N, K = map(int, input().split())
a_list = list(map(int, input().split()))

K += N
sum_ = sum(a_list)

ideal_d = [(K / sum_) * a for a in a_list]
min_d = [math.floor(i_d) if math.floor(i_d) != 0 else 1 for i_d in ideal_d]

max_ded_a_list = [a/m_d for a, m_d in zip(a_list, min_d) ]
min_ded_a_list = [a/(m_d+1) for a, m_d in zip(a_list, min_d)]
num_replace = K - sum(min_d)
max_ded_a_list.sort(reverse=True)

ans = math.ceil(max_ded_a_list[num_replace])
print(ans)

Measured memory_bytes: 49000
#include<bits/stdc++.h>
using namespace std;
using ll = int64_t;
const ll S = 100 * 100 * 2 + 10;
int main(){
    ll N;
    cin >> N;
    ll t[N], v[N], tsum[N] = {};
    ll now = 0;
    for(ll i = 0; i < N; i++){
        cin >> t[i];
        t[i] *= 2;
        tsum[i] = (i ? tsum[i - 1] : 0) + t[i];
    }
    for(ll i = 0; i < N; i++){
        cin >> v[i];
        v[i] *= 2;
    }
    vector<ll> dp(S + 1, -1);
    dp[0] = 0;
    ll prev = 0;
    for(ll i = 1;; i++){
        if(tsum[now] < i) now++;
        if(now >= N) break;
        ll up = min(S, v[now]);
        if(tsum[now] == i && now + 1 < N) up = min(up, v[now + 1]);
        vector<ll> nextdp(S + 1);
        copy(dp.begin(), dp.end(), nextdp.begin());
        for(ll j = 0; j <= S; j++){
            if(j > up){
                nextdp[j] = -1;
            }else{
                ll tmp = nextdp[j];
                if(dp[j] != -1) tmp = max(dp[j] + 2 * j, tmp);
                if(j && dp[j - 1] != -1) tmp = max(dp[j - 1] + 2 * (j - 1) + 1, tmp);
                if(j < S && dp[j + 1] != -1) tmp = max(dp[j + 1] + 2 * j + 1, tmp);
                nextdp[j] = tmp;
            }
        }
        copy(nextdp.begin(), nextdp.end(), dp.begin());
    }
    ll ans = 0;
    printf("%.1333f\n", (double)dp[0] / 8);
    return 0;
}


Measured memory_bytes: 608
from collections import defaultdict, deque, Counter
from heapq import heappush, heappop, heapify
import math
import bisect
import random
from itertools import permutations, accumulate, combinations, product
import sys
import string
from bisect import bisect_left, bisect_right
from math import factorial, ceil, floor
from functools import reduce


sys.setrecursionlimit(2147483647)
INF = 10 ** 18
def LI(): return list(map(int, sys.stdin.buffer.readline().split()))
def I(): return int(sys.stdin.buffer.readline())
def LS(): return sys.stdin.buffer.readline().rstrip().decode('utf-8').split()
def S(): return sys.stdin.buffer.readline().rstrip().decode('utf-8')
def IR(n): return [I() for i in range(n)]
def LIR(n): return [LI() for i in range(n)]
def SR(n): return [S() for i in range(n)]
def LSR(n): return [LS() for i in range(n)]
def SRL(n): return [list(S()) for i in range(n)]
def MSRL(n): return [[int(j) for j in list(S())] for i in range(n)]
mod = 1000000007


class BIT:
    def __init__(self, size):
        self.bit = [0] * size
        self.size = size
        self.total = 0

    def add(self, i, w):
        x = i + 1
        while x <= self.size:
            self.bit[x - 1] += w
            x += x & -x
        self.total += w
        return

    def sum(self, i):
        res = 0
        x = i + 1
        while x:
            res += self.bit[x - 1]
            x -= x & -x
        return res

    def interval_sum(self, i, j): # i <= x < j の区間
        return self.sum(j - 1) - self.sum(i - 1)

    def search(self, k):
        if k > self.total:
            return -1
        if k == 0:
            return 0
        step = 1 << (self.size.bit_length() - 1)
        now_index = 0
        ret = 0
        while step:
            if now_index + step < self.size and ret + self.bit[now_index + step - 1] < k:
                ret += self.bit[now_index + step - 1]
                now_index += step
            step >>= 1
        # now_indexを伸ばしいって、sumがk以上に達する直前まで伸ばし続けるならreturnのところでnow_index - 1。
        # その場合、bit.sum(now_index - 1) <= k < bit.sum(now_index)
        # 達してすぐのindexであれば-1しない
        return now_index


q = I()
query = []
A = []
for _ in range(q):
    l = LI()
    if l[0] == 1:
        A += [l[1]]
    query += [l]



ind_to_co = sorted(A)
co_to_ind = {}
for i, x in enumerate(ind_to_co):
    co_to_ind[x] = i


bit1 = BIT(len(A))
bit2 = BIT(len(A))
n = 0
B = 0
for l in query:
    if l[0] == 1:
        B += l[2]
        bit1.add(co_to_ind[l[1]], 1)
        bit2.add(co_to_ind[l[1]], l[1])
        n += 1
    else:
        min_ind = bit1.search(n // 2 + bool(n % 2))
        d = n // 2 + bool(n % 2)
        min_val = bit2.interval_sum(min_ind + 1, bit2.size) - bit1.interval_sum(min_ind + 1, bit1.size) * ind_to_co[min_ind] \
            + bit1.sum(min_ind - 1) * ind_to_co[min_ind] - bit2.sum(min_ind - 1) + B
        print(ind_to_co[min_ind], min_val)

Measured memory_bytes: 110936
n = gets.chomp.to_i
a = gets.chomp.split.map(&:to_i)
for b in 0..(n - 1)
  if a[b] % 2 == 0
    if a[b] % 3 != 0 and a[b] % 5 != 0
      puts "DENIED"; exit
    end
  end
end
puts "APPROVED"


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

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

typedef long long ll;
using namespace std;
int mod = 1000000007;

int solve[51]; //最後にACした時間
int num_pr[51];
int wa[51][11]; //waした回数
bool valid[51][11]; //acしたかどうか

void init(){
    rep(i, 51) {solve[i] = 0; num_pr[i] = 0;}
    rep(i, 51) rep(j, 11) {wa[i][j] = 0; valid[i][j] = false;}
}

int main(void){
    int M, T, P, R;

    //<解いた問題数> <解いた時間(短い方がいい)> <チーム番号(大きい方が先に出力)>

    while(true){
        init();
        cin >> M >> T >> P >> R;
        if(M == 0) break;
        pair<int, pair<int, int>> res[T];

        rep(i, R){
            int m, t, p, r; cin >> m >> t >> p >> r;
            t--; p--;
            if(r == 0){
                valid[t][p] = true;
                num_pr[t]++;
                solve[t] -= m;
            }
            else wa[t][p]++;
        }
        rep(i, T){
            rep(j, P){
                if(valid[i][j]) solve[i] -= 20*wa[i][j];
            }
        }

        rep(i, T){
            res[i] = make_pair(num_pr[i], make_pair(solve[i], i+1));
        }
        sort(res, res+T, greater<pair<int, pair<int, int>>>());
        rep(i, T){
            if(i == T-1) cout << res[i].second.second << endl;
            else if(res[i].first == res[i+1].first && res[i].second.first == res[i+1].second.first) cout << res[i].second.second << "=";
            else cout << res[i].second.second << ",";
        }
    }
    return 0;
}


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

#define REP(i,s,n) for(int i=s;i<n;++i)
#define rep(i,n) REP(i,0,n)
#define SORT(c) sort((c).begin(),(c).end())
#define IINF INT_MAX
#define LLINF LLONG_MAX
#define DEBUG false

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

int main() {

	int n, m;
	cin >> n >> m;

	vector<ii> man(n);
	rep(i, n) cin >> man[i].first >> man[i].second;

	vector<ii> pos(m);
	rep(i, m) cin >> pos[i].first >> pos[i].second;

	rep(i, n){
		int ans = 0;
		REP(j, 1, m){
			if(abs(man[i].first - pos[j].first) + abs(man[i].second - pos[j].second) <  abs(man[i].first - pos[ans].first) + abs(man[i].second - pos[ans].second)) ans = j;
		}
		cout << ans + 1 << endl;
	}

	return 0;
}


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

using lint = long long;
constexpr lint INF = std::numeric_limits<lint>::max();

template <class Cost>
using Graph = std::vector<std::vector<Cost>>;

template <class Cost>
Graph<Cost> warshall_floyd(Graph<Cost> graph) {
    for (int k = 0; k < graph.size(); ++k) {
        for (int u = 0; u < graph.size(); ++u) {
            for (int v = 0; v < graph.size(); ++v) {
                if (graph[u][k] < INF && graph[k][v] < INF) {
                    graph[u][v] = std::min(graph[u][v], graph[u][k] + graph[k][v]);
                }
            }
        }
    }
    return graph;
}

int main() {
    int n, m;
    lint l;
    std::cin >> n >> m >> l;

    Graph<lint> graph(n, std::vector<lint>(n, INF));
    for (int v = 0; v < n; ++v) {
        graph[v][v] = 0;
    }

    for (int i = 0; i < m; ++i) {
        int u, v;
        lint c;
        std::cin >> u >> v >> c;
        --u, --v;
        graph[u][v] = graph[v][u] = c;
    }

    graph = warshall_floyd(graph);
    for (auto& v : graph) {
        for (auto& x : v) {
            x = (x == 0 ? 0 : x <= l ? 1 : INF);
        }
    }
    graph = warshall_floyd(graph);

    int q;
    std::cin >> q;
    for (int p = 0; p < q; ++p) {
        int s, t;
        std::cin >> s >> t;
        --s, --t;

        lint d = graph[s][t];
        std::cout << (d == INF ? -1 : d - 1) << std::endl;
    }
    return 0;
}


Measured memory_bytes: 1664
fun main(args: Array<String>) {
    val numN = readLine()?.orEmpty()
    val cardList = mutableListOf<Long>()
    val numList = mutableMapOf<Long,Int?>()
    for(i in 0 until numN!!.toInt()){
        val num = readLine()?.orEmpty()!!.toLong()
        if(!numList.containsKey(num)){
            numList[num] = 1
        }else{
            numList[num] = numList[num]?.plus(1)
        }
    }

    numList.forEach{
        val card = it.value
        if (card != null) {
            if(card % 2 != 0){
                cardList.add(it.key)
            }
        }
    }

    println(cardList.size)
}

Measured memory_bytes: 45460
//Sani buyuk Osman Pasa Plevneden cikmam diyor.
//FatihSultanMehmedHan
//Abdulhamid Han
//Bismillahirrahmanirrahim
//█▀█─█──█──█▀█─█─█
//█▄█─█──█──█▄█─█▄█
//█─█─█▄─█▄─█─█─█─█

#pragma GCC optimize ("O3")
#pragma GCC target ("sse4")

#include <bits/stdc++.h>

using namespace std;

typedef long long int lo;
typedef pair< int,int > PII;

#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define fio() ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
#define FOR for(lo i=1;i<=n;i++)
#define mid ((start+end)/2)
#define ort ((bas+son)/2)

const lo MAX = -1000000000000000000;
const lo MIN = 1000000000000000000;
const lo inf = 1000000000;
const lo KOK = 100000;
const lo LOG = 30;
const lo li = 500005;
const lo mod = 1000000007;

lo n,m,b[li],a[li],k,flag,t;
lo cev;
string s;
vector<lo> v;

int main(void){
	scanf("%lld",&n);
	FOR{
		scanf("%lld",&a[i]);
	}
	sort(a+1,a+n+1);
	cev+=a[n/2+1]-1-a[n/2]+1;
	printf("%lld\n",cev);
	return 0;
}


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

int compare_int(const void *a, const void *b)
{
    return *(int*)a - *(int*)b;
}

int main(){
  int i,j,k;
  int N,min=100000000;
  
  scanf("%d",&N);
  int A[N];
  for(i=0;i<N;i++){
    scanf("%d ",&A[i]);
  }
  
  qsort(A,N,sizeof(int),compare_int);
  for(i=A[0];i<=A[N-1];i++){
    k=0;
    for(j=0;j<N;j++){
      k += (A[j]-i)*(A[j]-i);
    }
    if(k <min)
      min =k;
  }
  printf("%d\n",min);
  return 0;
}

Measured memory_bytes: 128
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
using ull = unsigned long long;
using V = vector<int>;
using VV = vector<V>;
using VVV = vector<VV>;
using VL = vector<ll>;
using VVL = vector<VL>;
using VVVL = vector<VVL>;
template<class T> using VE = vector<T>;
template<class T> using P = pair<T, T>;
#define rep(i,n) for(int i=0;i<(n);i++)
#define rep1(i,n) for(int i=1;i<=(n);i++)
#define REP(i,k,n) for(int i=(k);i<(n);i++)
#define all(a) (a).begin(),(a).end()
#define output(x,y) cout << fixed << setprecision(y) << x << endl;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; }
ll lcm(ll a, ll b) { return a / gcd(a, b) * b; }
// const ll MOD = 1e9 + 7;
const ll MOD = 998244353;
ll upper = MOD + MOD;
ll under = -upper;
ll UPPER = MOD * MOD;
ll UNDER = -UPPER;
const long double pi = 3.141592653589793;
int main() {
	int n;
	cin >> n;
	V a(n);
	map<ll, ll> mp;
	rep(i, n) {
		cin >> a[i];
		mp[i - a[i]]++;
	}
	ll ans = 0;
	rep(i, n) {
		ll x = mp[a[i] + i];
		ans += x;
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 26644
#include "bits/stdc++.h"
using namespace std;
#ifdef _DEBUG
#include "dump.hpp"
#else
#define dump(...)
#endif

//#define int long long
#define rep(i,a,b) for(int i=(a);i<(b);i++)
#define rrep(i,a,b) for(int i=(b)-1;i>=(a);i--)
#define all(c) begin(c),end(c)
const int INF = sizeof(int) == sizeof(long long) ? 0x3f3f3f3f3f3f3f3fLL : 0x3f3f3f3f;
const int MOD = (int)(1e9 + 7);
template<class T> bool chmax(T &a, const T &b) { if (a < b) { a = b; return true; } return false; }
template<class T> bool chmin(T &a, const T &b) { if (a > b) { a = b; return true; } return false; }

// ?¨???°????????? O(n+k)
// ??¶?´?: 0 <= v[i] <= k
void counting_sort(vector<int> &v) {
	int n = v.size(), k = *max_element(v.begin(), v.end());
	vector<int> cnt(k + 1), tmp(v);
	cnt[0]--;
	for (int x : v)cnt[x]++;
	for (int i = 0; i < k; i++)cnt[i + 1] += cnt[i];
	for (int i = n - 1; i >= 0; i--) {
		v[cnt[tmp[i]]] = tmp[i];
		cnt[tmp[i]]--;
	}
}

signed main() {
	int n; cin >> n;
	vector<int> A(n); rep(i, 0, n) { scanf("%d", &A[i]); }
	counting_sort(A);
	cout << A[0]; rep(i, 1, A.size()) { printf(" %d", A[i]); } cout << endl;
	return 0;
}

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

#define int long long

#define rep(i,s,n) for(int i = s;i<n;i++)
#define repe(i,s,n) for(int i = s;i<=n;i++)
#define rrep(i,s,n) for(int i = (n)-1;i>=(s);i--)
#define all(v) (v).begin(),(v).end()
#define pb push_back
#define fi first
#define se second
typedef long long ll;
typedef pair<int,int>pint;
typedef vector<int>vint;
typedef vector<pint>vpint;
typedef pair<pint,int> P1;
typedef pair<int,pint> P2;
static const ll maxLL = (ll)1 << 62;
const ll MOD=1000000007;
const ll INF=1e18;
int dy[]={-1,0,1,0};
int dx[]={0,1,0,-1};
ll gcd(ll x,ll y)
{
	if(x==0) return y;
	return gcd(y%x,x);
}
int lcm(int x, int y)
{
    if(x == 0 || y == 0)  // 引数チェック
    {
        fprintf(stderr, "引数エラーです。\n");
        return 0;
    }

    return (x * y / gcd(x, y));
}
int n,m;
string s,t;

signed main(){
    cin.tie(0);
	ios::sync_with_stdio(false);
    cin>>n>>m>>s>>t;
    
    int l=lcm(n,m);
    int g=gcd(m,n);
    
    int N=n/g;
    int M=m/g;
    
    rep(i,0,g){
        if(s[N*i]!=t[M*i]){
            cout<<"-1"<<endl;
            return 0;
        }
    }
    cout<<l<<endl;
    
    
    
    
    
    
    
    
    
    
    return 0;
}

Measured memory_bytes: 640
#include <bits/stdc++.h>
#define MOD 1000000007LL
using namespace std;
typedef long long ll;
typedef pair<int,int> P;

int h,w,k;
int fie[301][301];
P pos[100000];

int main(void){
	scanf("%d%d%d",&h,&w,&k);
	int cnt=0;
	for(int i=0;i<h;i++){
		string str;
		cin >> str;
		for(int j=0;j<w;j++){
			if(str[j]=='#'){
				pos[cnt]=P(j,i);
				fie[i][j]=cnt+1;
				cnt++;
			}else{
				fie[i][j]=-1;
			}
		}
	}
	for(int i=0;i<w;i++){
		for(int j=0;j<h;j++){
			if(j>0 && fie[j][i]==-1){
				fie[j][i]=fie[j-1][i];
			}
		}
		for(int j=h-2;j>=0;j--){
			if(fie[j][i]==-1){
				fie[j][i]=fie[j+1][i];
			}
		}
	}
	for(int i=0;i<w;i++){
		if(fie[0][i]==-1 && i>0){
			for(int j=0;j<h;j++){
				fie[j][i]=fie[j][i-1];
			}
		}
	}
	for(int i=w-2;i>=0;i--){
		if(fie[0][i]==-1){
			for(int j=0;j<h;j++){
				fie[j][i]=fie[j][i+1];
			}
		}
	}
	for(int i=0;i<h;i++){
		for(int j=0;j<w;j++){
			printf("%d%c",fie[i][j],j+1==w?'\n':' ');
		}
	}
	return 0;
}


Measured memory_bytes: 1792
program dam
  implicit none
  integer(8) :: n, i
  integer(8),allocatable :: water(:)
  integer(8),allocatable :: rain(:)
  
  read *, n 
  allocate(water(n),rain(n))
  read *, water
  rain = 0
  do i = 1, n 
    rain(1) = rain(1) - water(i)*(-1)**i
  end do 
  do i = 2, n 
    rain(i) = 2*(water(i-1)-rain(i-1)/2)
  end do 
  do i = 1, n-1
    write (*,'(i0,a)',advance="no") rain(i), " "
  end do
  write (*,'(i0)',advance="no") rain(n)
  stop
end program dam


Measured memory_bytes: 3456
import sys
from itertools import combinations
sys.setrecursionlimit(10**7)
INTMAX = 9223372036854775807
INTMIN = -9223372036854775808
MOD = 1000000007
def POW(x, y): return pow(x, y, MOD)
def INV(x, m=MOD): return pow(x, m - 2, m)
def DIV(x, y, m=MOD): return (x * INV(y, m)) % m
def LI(): return [int(x) for x in input().split()]
def LF(): return [float(x) for x in input().split()]
def LS(): return input().split()
def II(): return int(input())

N=II()
xs=LI()

res = 0
for i, j in combinations(xs, 2):
    res += i*j

print(res)


Measured memory_bytes: 3064
n, k = map(int, input().split())
favor = [tuple(input().split()) for _ in range(n)]
square = [[0 for _ in range(k)] for _ in range(k)]
initscore = 0
for xc, yc, c in favor:
    x = int(xc)
    y = int(yc)
    x %= 2*k
    y %= 2*k
    if (x in range(k) and y in range(k)) or (x in range(k, 2*k) and y in range(k, 2*k)):
        if c == 'B':
            square[x%k][y%k] += 1
        else:
            square[x%k][y%k] -= 1
            initscore += 1
    else:
        if c == 'B':
            square[x%k][y%k] -= 1
            initscore += 1
        else:
            square[x%k][y%k] += 1
cum = [[0 for _ in range(k+1)] for _ in range(k+1)]
for i in range(k):
    for j in range(k):
        cum[i+1][j+1] = cum[i+1][j] + cum[i][j+1] - cum[i][j] + square[i][j]
maxscore = 0
for i in range(k):
    for j in range(k):
        score = cum[i][k] + cum[k][j] - 2*cum[i][j]
        maxscore = max(maxscore, max(cum[k][k] - score, score))
print(maxscore + initscore)

Measured memory_bytes: 57844
# -*- coding: utf-8 -*-
n = int(input())
a = list(map(int, input().split()))
count = []
for i in range(n):
    count.append(0)
    while a[i] % 2 == 0:
        a[i] = a[i] / 2
        count[i] += 1
print(min(count))

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




int main(){
    long long N,A,B;
    cin >>N>>A>>B;
    long long C=A+B;
    if((N%C)>A)cout<<(N/C)*A+A<<endl;
    else{
        cout<<(N/C)*A +(N%C)<<endl;
    }
    

}

Measured memory_bytes: 256
L = input()
mod = 10**9 + 7

# dp[i][flg] := 上からi桁目まで見たときの、(a,b)の組み合わせの数
#   flg 0: 上からi桁目まで等しい
#   flg 1: 上からi桁目まで等しくない
dp = [[0] * 2 for i in range(len(L)+1)]
dp[0][0] = 1

for i in range(len(L)):
    if L[i] == '0':
        dp[i+1][0] = dp[i][0]
        dp[i+1][1] = dp[i][1]*3
    else:
        dp[i+1][0] = dp[i][0]*2
        dp[i+1][1] = dp[i][0]+dp[i][1]*3
    dp[i+1][0] %= mod
    dp[i+1][1] %= mod

print((dp[len(L)][0]+dp[len(L)][1]) % mod)


Measured memory_bytes: 54236
#include <cstdio>
#include <cstring>
#include <cmath>
#include <algorithm>
#include <vector>
using namespace std;

// あるブロックとその下のブロックを取り除くとき、
// 取り除いた結果更に取り除けるか？
int check_delete(int idx_left, int idx_right,
                 const vector<int> &cubes, int n, int num_del){
  // 下にブロックがない場合はそれ以上取り除けない
  if(idx_left == 0) return num_del;
  // 上にブロックがない場合はそれ以上取り除けない
  if(idx_right == n-1) return num_del;
  // 下のブロックと上のブロックが同じの場合は取り除けない
  if(cubes[idx_left-1] == cubes[idx_right+1]) return num_del;
  // 取り除けるか再帰で探索
  return check_delete(idx_left-1, idx_right+1, cubes, n, num_del+2);
}


int main(){
  char s[100001];
  scanf("%s", s);
  int pre_n = strlen(s);
  
  vector<int> cubes;
  for (int i = 0; i < pre_n; i++){
    cubes.push_back(int(s[i]));
  }
  
  int n = pre_n;
  while(true) {
    bool isnewdelete = false;
    int idx_right;
    for(idx_right=1; idx_right<n; idx_right++){
      if (cubes[idx_right] == cubes[idx_right-1]) continue;
      isnewdelete = true;
      break;
    }
    if(!isnewdelete) break;
    int num_del = check_delete(idx_right-1, idx_right, cubes, n, 2);
    // ずらす
    idx_right = idx_right + num_del/2;
    int idx_left = idx_right - num_del;
    cubes.erase(cubes.begin() + idx_left, cubes.begin() + idx_right);
  	//printf("%d: %s\n", num_del, cubes);
    n -= num_del;
  } 
  
  
  printf("%d", pre_n - n);
  return 0;
}

Measured memory_bytes: 1020
#include<stdio.h>
int main(void){ 
    int i,s[3];

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

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

typedef long long lld;
const int NN = 1e5 + 5;
lld aa[NN], dp[NN];
int nn;

int main() {
    ios::sync_with_stdio(0);
    cin.tie(0); cout.tie(0);
        cin >> nn;
        for (int ii = 1; ii <= nn; ++ii)
            cin >> aa[ii];
        dp[1] = 0;
        dp[2] = abs(aa[2] - aa[1]);
        for (int ii = 3; ii <= nn; ++ii)
            dp[ii] = min(dp[ii - 1] + abs(aa[ii] - aa[ii - 1]), dp[ii - 2] + abs(aa[ii] - aa[ii - 2]));
        cout << dp[nn];
    return 0;
}


Measured memory_bytes: 1792
/*
 * h.cc: 
 */

#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<iostream>
#include<string>
#include<vector>
#include<map>
#include<set>
#include<stack>
#include<list>
#include<queue>
#include<deque>
#include<algorithm>
#include<numeric>
#include<utility>
#include<complex>
#include<functional>

using namespace std;

/* constant */

const int MAX_H = 10;
const int MAX_W = 10;
const int MAX_N = 9;
const int M = 5;
const int DBITS = 1 << (M * 2);

const int INF = 1 << 30;

const int dxs[] = {1, 0, -1, 0}, dys[] = {0, -1, 0, 1};

/* typedef */

struct Stat {
  int d, k, x, y, dbits;
};

/* global variables */

string flds[MAX_H];
int xs[M], ys[M];
int dists[MAX_N][MAX_H][MAX_W][DBITS];

/* subroutines */

bool move(Stat &s, int h, int w, int di) {
  int x0 = s.x + dxs[di], y0 = s.y + dys[di];
  if (x0 < 0 || x0 >= w || y0 < 0 || y0 >= h || flds[y0][x0] == '#')
    return false;
  for (int i = 0, x = s.x, y = s.y; i < M - 1; i++) {
    int dii = ((s.dbits >> (i * 2)) & 3);
    x += dxs[dii], y += dys[dii];
    if (x0 == x && y0 == y) return false;
  }

  s.dbits = ((s.dbits << 2) & (DBITS - 1)) | ((di + 2) & 3);
  s.x = x0, s.y = y0;
  s.d++;
  return true;
}

/* main */

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

  Stat st;
  st.d = st.k = st.dbits = 0;

  for (int y = 0; y < h; y++) {
    cin >> flds[y];
    for (int x = 0; x < w; x++) {
      char ch = flds[y][x];
      if (ch == 'S') st.x = x, st.y = y;
      else if (ch >= 'a' && ch <= 'e') {
	int id = ch - 'a';
	xs[id] = x, ys[id] = y;
      }
    }
  }

  for (int i = 0, x = st.x, y = st.y; i < M; i++) {
    int dx = xs[i] - x, dy = ys[i] - y;
    for (int di = 0; di < 4; di++)
      if (dx == dxs[di] && dy == dys[di]) {
	st.dbits |= (di << (i * 2));
	break;
      }
    x = xs[i], y = ys[i];
  }
  
  for (int i = 0; i < n; i++)
    for (int y = 0; y < h; y++)
      for (int x = 0; x < w; x++)
	for (int bits = 0; bits < DBITS; bits++)
	  dists[i][y][x][bits] = INF;
  dists[0][st.y][st.x][st.dbits] = 0;

  queue<Stat> q;
  q.push(st);
  int ans = -1;
  
  while (! q.empty()) {
    Stat u = q.front(); q.pop();

    int uch = flds[u.y][u.x];
    if (uch == '1' + u.k) {
      if (++u.k >= n) {
	ans = u.d;
	break;
      }
      dists[u.k][u.y][u.x][u.dbits] = u.d;
    }

    for (int di = 0; di < 4; di++) {
      Stat v = u;
      if (move(v, h, w, di) &&
	  dists[v.k][v.y][v.x][v.dbits] > v.d) {
	dists[v.k][v.y][v.x][v.dbits] = v.d;
	q.push(v);
      }
    }
  }

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


Measured memory_bytes: 4848
#include <iostream>
#include <algorithm>
#include <vector>

using namespace std;

int main (){


    // need a way to order the strings lexigraphically ...


    

    int n, l;
    cin >> n >> l;

    vector<string> input(n);

    string result = "";

    for (int i = 0; i < n; i++){
        cin >> input[i];
    }

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

        string current_smallest = input[i];
        
        for (int j = i + 1; j < n; j++){
            if (lexicographical_compare(input[j].begin(),input[j].end(),current_smallest.begin(),current_smallest.end())){
                string temp = current_smallest;
                current_smallest = input[j];
                input[j] = temp;
            }
        }
        result += current_smallest;
    }

    cout << result << endl;

    return 0;
}

Measured memory_bytes: 256
#include "bits/stdc++.h"
using namespace std;
typedef pair<int,int> pii;
typedef long long ll;
#define rep(i,n) for(ll i=0;i<(ll)(n);i++)
#define all(a)  (a).begin(),(a).end()
#define pb emplace_back
#define INF (1e9+1)

int main(){
    int v,e;
    cin>>v>>e;
    set<int> x,y;
    rep(i,e){
        int a,b;
        cin>>a>>b;
        a--,b--;
        if(a>b)swap(a,b);
        
        if(a==0 && b!=v-1)x.insert(b);
        if(b==v-1 && a!=0)y.insert(a);
    }
    
    for(auto e:x){
        if(y.count(e)!=0){
            cout<<"POSSIBLE"<<endl;
            return 0;
        }
    }
    cout<<"IMPOSSIBLE"<<endl;
}

Measured memory_bytes: 9600
#include <iostream>
#include <string>
#include <algorithm>
#include <cmath>
#include <map>
#include <vector>
#include <stack>
#include <queue>
#include <tuple>
#include <cassert>
#include <functional>
#include <set>
#include <deque>
#include <list>
using namespace std;
typedef long long ll;
int dx[4] = {0,0,1,-1};
int dy[4] = {1,-1,0,0};
#define LNF __LONG_LONG_MAX__
const ll MOD = 1000000007;
const int MAX = 200000;

long long fac[MAX], finv[MAX], inv[MAX];

// テーブルを作る前処理
void COMinit() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (int i = 2; i < MAX; i++){
        fac[i] = fac[i - 1] * i % MOD;
        inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
        finv[i] = finv[i - 1] * inv[i] % MOD;
    }
}

// 二項係数計算
long long COM(int n, int k){
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}
// 法mでのaの逆元を計算
long long modinv(long long a, long long m) {
    long long b = m, u = 1, v = 0;
    while (b) {
        long long t = a / b;
        a -= t * b; swap(a, b);
        u -= t * v; swap(u, v);
    }
    u %= m;
    if (u < 0) u += m;
    return u;
}
// a^n mod を計算する
long long modpow(long long a, long long n, long long mod) {
    long long res = 1;
    while (n > 0) {
        if (n & 1) res = res * a % mod;
        a = a * a % mod;
        n >>= 1;
    }
    return res;
}
//最大公約数
long long gcd(long long x, long long y){
    if(y==0) return x;
    else return gcd(y,x%y);
}
//最小公倍数
long long lcm(long long x, long long y){
    return x / gcd(x, y) * y;
}
// nが大きく,kが10^7程度の時の二項係数
long long com[200005];
void combination(long long n,long long k){
    com[0] = 1;
    for(int i=1;i<=k;i++){
        com[i] = (com[i-1]*(n-i+1)%MOD)*modinv(i,MOD)%MOD;
    }
}

int main(){
    int N,H,W; cin >> N >> H >> W;
    cout << (N-H+1)*(N-W+1) << endl;
    return 0;
}


Measured memory_bytes: 3524
#include <iostream>
#include <string>
#include <bitset>
#include <sstream>
#include <vector>

using namespace std;

int main()
{
    int N;
    cin>>N;
    vector<int> A(N);
    for (int i = 0; i < N; i++) {
        cin>>A[i];
    }

    int j = -1;
    long long cnt = 0;
    int sum = 0;
    for (int i = 0; i < N; i++) {
        while (j < N-1 && (sum + A[j+1]) == (sum ^ A[j+1])) {
            sum += A[++j];
        }
        cnt += j-i+1;
        sum -= A[i];
    }

    cout<<cnt<<endl;

  return 0;
}


Measured memory_bytes: 1024
import java.util.*;

class Main{
  public static void main (String[ ] args){
    
    Scanner sc = new Scanner (System.in);

    int a = sc.nextInt();
    
    int b = sc.nextInt();

    if ( (a*b)%2 ==0 ){

       System.out.println("Even");

  }
    else{

       System.out.println("Odd");
  }


  }
}

Measured memory_bytes: 21844
N, A = gets.split.map(&:to_i)
xs = gets.split.map{|x| x.to_i - A}
dp = Array.new(N){Hash.new(0)}
dp[0][0] = 1
dp[0][xs[0]] += 1
(1...N).each do |i|
    dp[i-1].each do |key, val|
        dp[i][key] += val
        dp[i][key+xs[i]] += val
    end
end
puts dp[N-1][0] - 1

Measured memory_bytes: 3196
#include <iostream>
#include <string.h>
#include <vector>
#include <algorithm>
#include <cmath>
#include <map>
#include <functional>
#include <cassert>
#include <utility>
#include <stack>
#include <queue>
using namespace std;
#define min(a,b) ((a)<(b)?(a):(b))
#define max(a,b) ((a)>(b)?(a):(b))
#define REP(i,n) for(int i=0;i<n;i++)
#define FOR(i,n1,n2) for(int i=n1;i<n2;i++)
#define speed_up    ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
typedef pair<int,int> Pi;
typedef long long int ll;
const int INF=(1<<30)-1;
const ll INFl=9223372036854775807;
const int MAX=10000;
const ll MOD=1000000007;
int gcd(int a,int b){return b?gcd(b,a%b):a;}
int lcm(int a,int b){return a/gcd(a, b)*b;}

int n,q;
string s;
int l[100100],r[100100];
int ac[100100];

int main(){
	cin>>n>>q;
	cin>>s;
	REP(i,q){
		int t;
		cin>>t;
		t--;
		l[i]=t;
		cin>>t;
		t--;
		r[i]=t;
	}
	bool flag=false;
	ac[0]=0;
	REP(i,n){
		if(s[i]=='A'){
			flag=true;
			ac[i]=ac[i-1];
		}else if(s[i]=='C'&&flag){
			flag=false;
			ac[i]=ac[i-1]+1;
		}else{
			if(i!=0){
				ac[i]=ac[i-1];
				flag=false;
			}
		}
	}
	
	REP(i,q)
		cout<<ac[r[i]]-ac[l[i]]<<endl;
	return 0;
}

Measured memory_bytes: 2176
#include <stdio.h>
#include <iostream>
#include <algorithm>
#include <math.h>
 
using namespace std;
 
 
int main(){
 
    double d,w,h,r,min_dist,dist1,dist2,dist3;
    int n;
 
    while(true){
        scanf("%lf %lf %lf",&d,&w,&h);
        if(d == 0.0 && w == 0.0 && h == 0.0)break;
 
        scanf("%d",&n);
 
        for(int i=0; i < n; i++){
            scanf("%lf",&r);
            dist1 = (sqrt(d*d+w*w))/2.0;
            dist2 = (sqrt(w*w+h*h))/2.0;
            dist3 = (sqrt(d*d+h*h))/2.0;
            min_dist = min(dist1,min(dist2,dist3));
            if(r > min_dist){
                printf("OK\n");
            }else{
                printf("NA\n");
            }
        }
    }
 
    return 0;
}


Measured memory_bytes: 3208
#include <iostream>
#include <vector>
#include <math.h>
using namespace std;
typedef vector<int> vi;
#define rep(i,n) for(int i=0; i<n; i++)
#define repr(i,a,b) for(int i=a; i<b; i++)

int main() {
  int N;
  cin >> N;
  int cnt = 0;
  repr(i,1,N+1) {
    int ans = (int)log10((double)i) + 1;
    if( ans %2 == 1) {
      cnt++;
    }
  }
  cout << cnt << endl;
  return 0;
}

Measured memory_bytes: 512
#include "bits/stdc++.h"
using namespace std;
int a[100001];
int main()
{
	int n, total = 0;
	scanf("%d", &n);	
	for(int i = 0; i < n; scanf("%d", &a[i++])){}
	sort(a, a + n);
	a[n] = 1000000001;
	for(int i = 0, j = 0, k = 0; i <= n; ++i)
	{
		if(a[i] == j)
		{
			++k;
		}
		else
		{
			total += k >= j ? k - j : k;
			j = a[i];
			k = 1;
		}
	}
	printf("%d\n", total);
}

Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N=1e5+5;

int main(){
	int a,b;cin>>a>>b;
	string A="",B="";
	for(int i=0;i<a;i++){
		B+=char(b+'0');
	}
	for(int i=0;i<b;i++){
		A+=char(a+'0');
	}
	cout<<min(A,B);
}

Measured memory_bytes: 3580
#include <algorithm>
#include <cstdio>
#include <cstring>
#include <queue>
#include <vector>

using namespace std;

int a[1111], b[1111], c[1111], d[1111];
short g[4444][4444];
int w, h, n;
vector<int> xs, ys;

int main(void) {
  for (;;) {
    scanf("%d%d", &w, &h); if(w+h == 0) break;
    xs.clear();
    ys.clear();
    memset(g, 0, sizeof(g));
    scanf("%d", &n);
    for (int i = 0; i < n; i++) {
      scanf("%d%d%d%d", a+i, b+i, c+i, d+i);
      a[i] *= 2;
      b[i] *= 2;
      c[i] *= 2;
      d[i] *= 2;
      xs.push_back(a[i]);
      xs.push_back(c[i]);
      xs.push_back(a[i]+1);
      xs.push_back(c[i]+1);
      ys.push_back(b[i]);
      ys.push_back(d[i]);
      ys.push_back(b[i]+1);
      ys.push_back(d[i]+1);
    }

    xs.push_back(w*2);
    ys.push_back(h*2);
    xs.push_back(0);
    ys.push_back(0);
    sort(xs.begin(), xs.end());
    xs.erase(unique(xs.begin(), xs.end()), xs.end());
    sort(ys.begin(), ys.end());
    ys.erase(unique(ys.begin(), ys.end()), ys.end());

    for (int i = 0; i < n; i++) {
      int x1 = lower_bound(xs.begin(), xs.end(), a[i])-xs.begin();
      int y1 = lower_bound(ys.begin(), ys.end(), b[i])-ys.begin();
      int x2 = lower_bound(xs.begin(), xs.end(), c[i])-xs.begin();
      int y2 = lower_bound(ys.begin(), ys.end(), d[i])-ys.begin();

      g[y1][x1] += 1;
      g[y1][x2+1] += -1;
      g[y2+1][x1] += -1;
      g[y2+1][x2+1] += 1;
    }

    for (int i = 0; i < int(ys.size())-1; i++) {
      for (int j = 0; j < int(xs.size())-1; j++) {
        g[i][j+1] += g[i][j];
      }
    }
    for (int i = 0; i < int(xs.size())-1; i++) {
      for (int j = 0; j < int(ys.size())-1; j++) {
        g[j+1][i] += g[j][i];
      }
    }

    int res = 0;
    int dx[] = {0, 1, 0, -1};
    int dy[] = {1, 0, -1, 0};
    for (int i = 0; i < int(ys.size())-1; i++) {
      for (int j = 0; j < int(xs.size())-1; j++) {
        if (g[i][j] == 0) {
          res += 1;
          queue<int> q;
          q.push(j*10000+i);
          while (!q.empty()) {
            int x = q.front()/10000;
            int y = q.front()%10000;
            q.pop();
            for (int i = 0; i < 4; i++) {
              int nx = x+dx[i], ny = y+dy[i];
              if (nx < 0 || nx >= int(xs.size())-1 ||
                  ny < 0 || ny >= int(ys.size())-1 ||
                  g[ny][nx]) continue;
              g[ny][nx] = 1;
              q.push(nx*10000+ny);
            }
          }
        }
      }
    }

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

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

typedef long long lint;
typedef long double louble;

template<typename T1,typename T2> inline T1 max(T1 a,T2 b){return a<b?b:a;}
template<typename T1,typename T2> inline T1 min(T1 a,T2 b){return a<b?a:b;}

const char lf = '\n';

namespace ae86
{
	const int bufl = 1<<15;

	char buf[bufl],*s=buf,*t=buf;

	inline int fetch()
	{
		if(s==t){t=(s=buf)+fread(buf,1,bufl,stdin);if(s==t)return EOF;}
		return *s++;
	}

	inline int ty()
	{
		int a=0,b=1,c=fetch();
		while(!isdigit(c))b^=c=='-',c=fetch();
		while(isdigit(c))a=a*10+c-48,c=fetch();
		return b?a:-a;
	}
}
using ae86::ty;

const int _ = 100007;

vector<int> e[_];
inline void adde(int a,int b){e[a].emplace_back(b);}
inline void addde(int a,int b){adde(a,b),adde(b,a);}

int bfa[_];
int findbfa(int x){return bfa[x]==x?x:bfa[x]=findbfa(bfa[x]);}

int n,m,ps[_];bool ed[_]={0};
lint lim[_],los[_],res[_],slos[_]={0},f[_];

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

	n=ty(),m=ty();
	for(int i=1;i<=n;i++)lim[i]=ty(),los[i]=ty(),res[i]=max(lim[i]-los[i],0);
	for(int i=1,a,b;i<=m;i++)a=ty(),b=ty(),addde(a,b);

	for(int i=1;i<=n;i++)ps[i]=i;
	sort(ps+1,ps+n+1,[](int a,int b){return res[a]<res[b];});

	for(int i=1;i<=n;i++)bfa[i]=i,slos[i]=los[i],f[i]=res[i];
	for(int i=1;i<=n;i++)
	{
		int a=ps[i];ed[a]=1;
		for(auto b:e[a])
		{
			if(!ed[b])continue;
			int aa=findbfa(a),bb=findbfa(b);
			if(aa==bb)continue;
			bfa[bb]=aa,slos[aa]+=slos[bb];
			f[aa]=min(f[aa],max(f[bb],res[aa]-slos[bb]));
		}
	}

	cout<<slos[findbfa(1)]+f[findbfa(1)]<<lf;
	
	return 0;
}


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

int main() {
  int n, m;
  cin >> n >> m;
  vector<int> a(n);
  int sumAll;
  for(int i=0; i<n; i++){
    cin >> a[i];
    sumAll = sumAll + a[i];
  }
  sort(a.begin(), a.end(), greater<int>());

  int count;

  for(int i=0; i<n; i++){
    if(a[i] >= sumAll/(4.0*m)){
      count++;
    }
  }

  if(count >= m) {
    cout <<"Yes"<< endl;
  }else{
    cout <<"No"<< endl;
  }
  return 0;
}



Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <limits.h>
#include <algorithm>
#include <string>
#include <math.h>
#include <limits.h>
#include <queue>
#include <map>
#include <set>
#include <iomanip>
#include <bitset>
#include <cassert>
#include <random>
#include <functional>
#include <stack>
#include <iomanip>
#include <cassert>
//#include <boost/multiprecision/cpp_int.hpp>
#include <complex>
#include <cstdio>
#include <list>
#include <bitset>

//< in.txt > out.txt
using namespace std;
//std::ios::sync_with_stdio(false);
//std::cin.tie(0);
const long long MOD = 1e9 + 7;
const long long INF = 1e18;
typedef long long LL;
typedef long double LD;
typedef pair<LL, LL> PLL;
typedef pair<LD, LL> pdl;
typedef pair<LD, LD> pdd;
typedef vector<LL> VLL;
typedef vector<VLL> VVLL;
typedef unsigned long long ULL;
//typedef boost::multiprecision::cpp_int bigint;

int main() {
	std::ios::sync_with_stdio(false);
	std::cin.tie(0);
	string S, T;
	cin >> S >> T;
	if (T.substr(0, T.size() - 1) == S)cout << "Yes\n";
	else cout << "No\n";
	return 0;
}

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

using namespace std;

using LL = long long;
LL N, k;
LL arr[504], val[504];
vector < LL > vc;

int main(){
    scanf("%lld %lld", &N, &k);
    for(LL i = 1; i <= N; ++i) scanf("%lld", arr + i);
//    N = 500, k = (int)1e9;
//    mt19937 gen(time(NULL));
//    uniform_int_distribution < int > range(1, (int)1e6);
//    for(int i = 1; i <= N; ++i) arr[i] = range(gen);
    LL sum = 0;
    for(LL i = 1; i <= N; ++i){
        sum += arr[i];
    }
    for(LL i = 1; i * i <= sum; ++i){
        if(sum % i == 0){
            vc.push_back(i);
            vc.push_back(sum / i);
        }
    }
    sort(vc.begin(), vc.end());
    LL a = 0, b = (LL)vc.size() - 1, mid;
    for(int I = b; I >= 0; --I){
        mid = I;
        for(LL i = 1; i <= N; ++i){
            val[i] = -(arr[i] % vc[mid]);
        }
        sort(val + 1, val + N + 1);
        sum = 0;
        for(LL i = 1; i <= N; ++i) sum += val[i];
        sum *= -1;
        for(LL i = 1; i <= sum / vc[mid]; ++i){
            val[i] += vc[mid];
        }
        sum = 0;
        for(LL i = 1; i <= N; ++i){
            sum += abs(val[i]);
        }
        if(sum / 2 <= k){
            printf("%lld\n", vc[mid]); return 0;
        }
        else b = mid - 1;
    }
    printf("%lld\n", vc[a]);
    return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<map>
#include<math.h>
#include<queue>
#include<deque>
#include<stack>
#include<cstdio>
#include<utility>
#include<set>
#include<list>
#include<cmath>
#include<stdio.h>
#include<string.h>
#include<iomanip>
using namespace std;
#define FOR(i, a, b) for (ll i = (a); i <= (b); i++)
#define REP(i, n) FOR(i, 0, n - 1)
#define NREP(i, n) FOR(i, 1, n)
using ll = long long;
using pii = pair<int, int>;
using piii = pair<pii, pii>;
const int dx[4] = { 0, -1, 1, 0 };
const int dy[4] = { -1, 0, 0, 1 };
const int INF = 1e9 + 7;
int gcd(int x, int y) {
	if (x < y)swap(x, y);
	if (y == 0)return x;
	return gcd(y, x%y);
}

template<class T1, class T2> void chmin(T1 &a, T2 b) { if (a>b)a = b; }

template<class T1, class T2> void chmax(T1 &a, T2 b) { if (a<b)a = b; }
template<class T>
void Add(T &a, const T &b, const T &mod = 1000000007) {
	int val = ((a % mod) + (b % mod)) % mod;
	if (val < 0) { val += mod; }
	a = val;
}
////////////////////////////////////////
int main() {
	string S;
	cin >> S;
	bool can[11];
	for (int i = 0; i < S.size(); ++i) {
		can[i] = false;
	}
	for (int i = 0; i < S.size(); ++i) {
		if (S[i] == 'A' || S[i] == 'G' || S[i] == 'C' || S[i] == 'T') {
			can[i] = true;
		}
	}
	int i = 0;
	int count = 0;
	while (i < S.size()) {
		if (can[i]) {
			int j = i;
			while (can[i]) {
				i++;
				if (i == S.size()) {
					break;
				}
			}
			count = max(count, i - j);
		}
		else {
			i++;
		}
	}
	cout << count << endl;
	return 0;
}


Measured memory_bytes: 256
#include<stdio.h>
#define N 100

int main(void){
	int n,s;
	int A[N];
	int i,j,k;
	int p;
	
	scanf("%d",&n);
	
	for(i =0;i<n;i++){
		scanf("%d",&s);
		A[i] = s;
	}

	
	for(i=0;i<n;i++){
		p = A[i];
		j = i-1;
		while(j >= 0 && p < A[j]){
			A[j+1] = A[j];
			j--;
			A[j+1] = p;
		}
		for(j=0;j<n;j++){
			printf("%d",A[j]);
			if(j == n-1)printf("\n");
			else printf(" ");
		}
	}
	
	
	return 0;
}

Measured memory_bytes: 1812
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <vector>
#include <functional>
#include <queue>
#include <string>
#include <cstring>
#include <numeric>
#include <cstdlib>
#include <cmath>
using namespace std;

typedef long long ll;

#define INF 10e10
#define rep(i,n) for(int i=0; i<n; i++)
#define rep_r(i,n,m) for(int i=m; i<n; i++)
#define MAX 100
#define MOD 1000000007
#define pb push_back

/* add vars here */

ll s,c;

/* add your algorithm here */

int main() {
  cin >> s >> c;

  ll ans = 0;
  ll t = 2 * s;

  if (c <= t) {
    ans += c / 2;
    cout << ans << endl;
    return 0;
  }

  ans += s;
  c -= t;

  ans += c / 4;

  cout << ans << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
template <class T> inline bool chmax(T &a, T b) {
    if(a < b) {
        a = b;
        return 1;
    }
    return 0;
}
template <class T> inline bool chmin(T &a, T b) {
    if(a > b) {
        a = b;
        return 1;
    }
    return 0;
}
void print() { cout << "\n"; }
template <class T> void print(const T &x) { cout << x << "\n"; }
template <class T, class... Args> void print(const T &x, const Args &... args) {
    cout << x << " ";
    print(args...);
}
template <class T> void printVector(const vector<T> &v) {
    for(const T &x : v) {
        cout << x << " ";
    }
    cout << "\n";
}
using ll = long long;

#define ALL(v) (v).begin(), (v).end()
#define RALL(v) (v).rbegin(), (v).rend()
const double EPS = 1e-7;
const int INF = 1 << 30;
const ll LLINF = 1LL << 60;
const double PI = acos(-1);
constexpr int MOD = 1000000007;
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};

//-------------------------------------

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    string s;
    cin >> s;
    int n = s.size();
    int ans = n;
    for(int i = 0; i < n - 1; i++) {
        if(s[i] != s[i + 1]) {
            chmin(ans, max(i + 1, n - (i + 1)));
        }
    }
    print(ans);
}

Measured memory_bytes: 512