akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
#define lli long long int
#define uli unsigned long long int
#define rep(i, m, n) for (lli i = m; i < (n); i++)
#define repe(i, m, n) for (lli i = m; i <= (n); i++)
#define ALL(x) (x).begin(), (x).end()
#define SIZE(x) ((lli)(x).size())
#define MAX(x) *max_element(ALL(x))
#define MIN(x) *min_element(ALL(x))
#define _GLIBCXX_DEBUG
const lli INF = 2147483647;
const lli MINF = -2147483648;
const lli LINF = 9223372036854775807;
const lli MOD = 1000000007; //10^9+7
const double PI = acos(-1);
#define SORT(n) sort(n.begin(), n.end())
#define SORTR(n) sort(n.begin(), n.end(), greater<int>())
#define REV(n) reverse(n.begin(), n.end())
#define pb push_back
#define eb emplace_back
#define mp make_pair
#pragma GCC optimize("Ofast")
using vi = vector<int>;
using vvi = vector<vi>;
using vvvi = vector<vvi>;
using vlli = vector<lli>;
using vvli = vector<vlli>;
using vs = vector<string>;
using vvs = vector<vs>;
using vb = vector<bool>;
using vvb = vector<vb>;
using ll = long long;
// vector入力
template <typename T>
istream &operator>>(istream &is, vector<T> &vec)
{
  for (T &x : vec)
    is >> x;
  return is;
}
// vector出力
template <typename T>
ostream &operator<<(ostream &os, vector<T> &vec)
{
  // os << '{';
  for (int i = 0; i < vec.size(); i++)
  {
    os << vec[i] << (i + 1 == vec.size() ? "" : "");
  }
  // os << '}';
  return os;
}
// aよりもbが大きいならばaをbで更新する(更新されたならばtrueを返す)
template <typename T>
bool chmax(T &a, const T &b)
{
  if (a < b)
  {
    a = b; // aをbで更新
    return true;
  }
  return false;
}
// aよりもbが小さいならばaをbで更新する(更新されたならばtrueを返す)
template <typename T>
bool chmin(T &a, const T &b)
{
  if (a > b)
  {
    a = b; // aをbで更新
    return true;
  }
  return false;
}

int main()
{
  ios::sync_with_stdio(false);
  cin.tie(0);
  lli a, b, c, h, k, n, w, ans = 0, count = 0;
  string s, t;
  vector<pair<string, pair<lli, lli>>> pr;
  cin >> a >> b;

  cout << a * b << endl;
}

Measured memory_bytes: 3640
L,R = map(int, input().split())
ans=2019
if L+2019<=R:
    for i in range(0,2019):
        for j in range(i+1,2019):
            if (i*j)%2019<ans:
                ans=(i*j)%2019
elif L%2019<R%2019:
    for i in range(L%2019,R%2019+1):
        for j in range(i+1,R%2019+1):
            if (i*j)%2019<ans:
                ans=(i*j)%2019
else:
    for i in range(L%2019,R%2019+2020):
        for j in range(i+1,R%2019+2020):
            if (i*j)%2019<ans:
                ans=(i*j)%2019
print(ans)

Measured memory_bytes: 3064
#include<bits/stdc++.h>
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define rep2(i, m, n) for(int i = (int)(m); i < (int)(n); i++)
#define rep_inv(i, n, m) for(int i = (int)(n); i > (int)(m); i--)
using namespace std;
using ll = long long;
using vl = vector<ll>;
using vc = vector<char>;
using vvl = vector<vl>;
using vvc = vector<vc>;
using pll = pair<ll, ll>;
using vpii = vector<pll>;

int main(){
  string S, T, U;
  ll A, B;
  cin >> S >> T;
  cin >> A >> B;
  cin >> U;

  if(S == U){
    cout << A - 1 << ' ' << B << endl;
  } else{
    cout << A << ' ' << B - 1 << endl;
  }
   
  return 0;
}

Measured memory_bytes: 256
/******************************************************************************

                         بسم الله الرحمن الرحيم
                     Author: Mst: Mhamuda Khatun
                               RUCSE27

*******************************************************************************/

#include<bits/stdc++.h>
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;
#define ll long long
#define ull unsigned long long
#define OrderSetTree tree<ll,null_type/*mapped_type*/,less<ll>,rb_tree_tag,tree_order_statistics_node_update>
#define pi 2*acos(0.0)
#define f first
#define s second
#define pb push_back
#define gap ' '
#define fastio {ios_base::sync_with_stdio(false);cin.tie(NULL);}
#define mod 1000000007
#define MAX 1000000000000
#define N 305

int main()
{
    fastio;
    //OrderSetTree ost;
    ll i,j,t,n,p;
    string alice,bob,charlie,ans="";

    cin>>alice>>bob>>charlie;

    ans+=alice.front();
    alice.erase(0,1);

    while(1)
    {
        if(ans.back()=='a')
        {
            if(alice.empty())
                break;
            else
            {
                ans+=alice.front();
                alice.erase(0,1);
            }
        }
        else if(ans.back()=='b')
        {
            if(bob.empty())
                break;
            else
            {
                ans+=bob.front();
                bob.erase(0,1);
            }
        }
       else
        {
            if(charlie.empty())
                break;
            else
            {
                ans+=charlie.front();
                charlie.erase(0,1);
            }
        }
    }

    cout<<(char)(ans.back()-32);
    cout<<"\n";
    return 0;   //:D
}




Measured memory_bytes: 3556
#include<iostream>
#include<cmath>
#include<climits>
#include<algorithm>
using namespace std;
int main()
{
    int n;
    long long a[200000], s = 0, ss = 0, absmin = INT_MAX;
    cin >> n;
    for(int i = 0; i < n; i++){
        cin >> a[i];
        s += a[i];
    }
    for(int i = 0; i < n-1; i++){
        ss += a[i];
        absmin = min(absmin, abs(s - (2 * ss)));
    }
    cout << absmin << endl;
    return 0;
}

Measured memory_bytes: 1792
// 144 B - 81
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
int main() {
    int N;
    cin >> N;
    
    string result = "No";

    if (N < 10) {
        result = "Yes";
    } else {
        for (int i = 1; i <= 9; i++) {
            if (N % i == 0 && N/i <=9) {
                    result = "Yes";
                    break;
            }
        }
    }
    cout << result << endl;
}

Measured memory_bytes: 256
#include<iostream>
#include<list>
#include<vector>
#include<algorithm>
#include<string>
#include<stdio.h>
#include<math.h>
#include<unordered_map>
#include<map>

using namespace std;
using ll = long long;
using vec = vector<ll>;
using mat = vector<vec>;


int main()
{
	int n; cin >> n;

	vec p(n);

	for (int i = 0; i < n; ++i)cin >> p[i];

	int ans = 0;
	for (int i = 1; i < n - 1; ++i)
	{
		if (p[i - 1] < p[i] && p[i] < p[i + 1])
		{
			++ans;
		}
		if (p[i - 1] > p[i] && p[i] > p[i + 1])
		{
			++ans;
		}
	}

	cout << ans << endl;

	return 0;
}

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


#define FOR(i, start, end) for(uint64_t i=start; i<end; i++)
#define REP(i, n) FOR(i, 0, n)

// 最大公約数gcd
// 最小公倍数lcm=m*n/gcd
uint64_t gcd(uint64_t m, uint64_t n) {
  uint64_t temp;
  while (m % n != 0){
    temp = n;
    n = m % n;
    m = temp;
  }
  return n;
}

uint64_t lcm(uint64_t m, uint64_t n) {
  return (m*n)/gcd(m,n);
}

// vector<vector<uint64_t> > v(n+1, vector<uint64_t>(n+1, 0))
// v[n][k]に組み合わせ数が入る。
void comb(vector<vector <uint64_t> > &v){
  for(uint64_t i = 0;i <v.size(); i++){
    v[i][0]=1;
    v[i][i]=1;
  }
  for(uint64_t k = 1;k <v.size();k++){
    for(uint64_t j = 1;j<k;j++){
      v[k][j]=(v[k-1][j-1]+v[k-1][j]);
    }
  }
}

// 掛け算オーバーフロー判定
bool is_product_overflow(uint64_t a, uint64_t b) {

	uint64_t prod = a * b;
	
	return (prod / b != a);
}

//素因数分解
void primeFactorization(uint64_t a, list<uint64_t> &factors){ //素因数分解を出力するプログラム
  long i,sq;
  if(a%2==0){ //偶数の場合
    factors.push_back(2);
    primeFactorization(a/2,factors); //2で割った値で再帰
    return;
  }
  sq = sqrt(a);
  for(i=3;i<=sq;i+=2){ //3以上√a以下の奇数の場合
	if(a%i==0){
	  factors.push_back(i);
      primeFactorization(a/i,factors); //割れた値で再帰
      return;
	}
  }
  //偶数でも3以上√a以下の奇数の場合でも割り切れない場合
  if(a!=1){ //aが1でないなら、a自身は素数
    factors.push_back(a);
  }
}

// フェルマーの小定理
// mod. m での a の逆元 a^{-1} を計算する
int64_t modinv(int64_t a, int64_t m) {
    int64_t b = m, u = 1, v = 0;
    while (b) {
        int64_t t = a / b;
        a -= t * b; swap(a, b);
        u -= t * v; swap(u, v);
    }
    u %= m;
    if (u < 0) u += m;
    return u;
}

// 円周率
// M_PI

// #include <iomanip> // setprecisionを使用するのに必要
// cout << std::fixed << std::setprecision(15) << y << endl;

// 昇順
// priority_queue<int, vector<int>, greater<int> > queue;
signed main() {
  int64_t d;
  cin >> d;
  int64_t c[26];
  vector<vector<int64_t>> s(d);
  for(int i=0;i<26;i++){
    cin >> c[i];
  }
  
  for(int i=0;i<d;i++){
    for(int j=0;j<26;j++){
      int x;
      cin >> x;
      s[i].push_back(x);
    }
  }
  
  int64_t satis[26] = {0};
  int lastD[26] = {0};

  int t[d];

  int64_t totalSatis = 0;
  for(int i=0;i<d;i++){
    cin >> t[i];
    t[i]--;
    satis[t[i]] += s[i][t[i]];
    totalSatis += s[i][t[i]];
    lastD[t[i]]=i+1;
    for(int j=0;j<26;j++){
      if(j==t[i])continue;
      satis[j] -= c[j]*(i+1-lastD[j]);
      totalSatis -= c[j]*(i+1-lastD[j]);
    }
    cout << totalSatis << endl;
  }
  
  return 0;
}




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

# define REP(i,n) for (int i=0;i<(n);++i)
# define rep(i,a,b) for(int i=a;i<(b);++i)
# define p(s) std::cout << s ;
# define pl(s)  std::cout << s << endl;
# define printIf(j,s1,s2) cout << (j ? s1 : s2) << endl;
# define YES(j) cout << (j ? "YES" : "NO") << endl;
# define Yes(j) std::cout << (j ? "Yes" : "No") << endl;
# define yes(j) std::cout << (j ? "yes" : "no") << endl;
# define all(v) v.begin(),v.end()
# define showVector(v) REP(i,v.size()){p(v[i]);p(" ")} pl("")
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;}
typedef long long int ll;
typedef pair<ll,ll> P_ii;
typedef pair<double,double> P_dd;

int main(){
    int n;
    cin >> n;

    vector<string> s(n);

    cout << 0 << endl;
    cin >> s[0];

    if(s[0] == "Vacant"){
        return 0;
    }

    int left = 0, right = n, mid;

    while(true){
        mid = ( left + right) / 2;

        cout << mid << endl;
        cin >> s[mid];

        if(s[mid] == "Vacant"){
            return 0;
        }

        if(s[left] == s[mid] && (mid - left) % 2 == 1){
            right = mid;
        } else if (s[left] != s[mid] && (mid - left) % 2 == 0){
            right = mid;
        } else {
            left=mid;
        }
    }

    return 0;
}

Measured memory_bytes: 1620
import sys
sys.setrecursionlimit(4100000)

import math

import logging

logging.basicConfig(level=logging.DEBUG)

logger = logging.getLogger(__name__)


def resolve():
    # S = [x for x in sys.stdin.readline().split()][0]  # 文字列 一つ
    N = [int(x) for x in sys.stdin.readline().split()][0]  # int 一つ
    p_list = [int(x) for x in sys.stdin.readline().split()]  # 複数int
    # grid = [list(sys.stdin.readline().split()[0]) for _ in range(N)]  # 文字列grid
    # grid = [[int(x) for x in sys.stdin.readline().split()]
    #         for _ in range(N)]  # int grid

    logger.debug('{}'.format([N, p_list]))

    ans = 0
    _min = 2 * 10**5 + 1
    for p in p_list:
        if p <= _min:
            ans += 1
            _min = p
    print(ans)


if __name__ == "__main__":
    resolve()

# AtCoder Unit Test で自動生成できる, 最後のunittest.main は消す
# python -m unittest template/template.py で実行できる
# pypy3 -m unittest template/template.py で実行できる

import sys
from io import StringIO
import unittest


class TestClass(unittest.TestCase):
    def assertIO(self, input, output):
        stdout, stdin = sys.stdout, sys.stdin
        sys.stdout, sys.stdin = StringIO(), StringIO(input)
        resolve()
        sys.stdout.seek(0)
        out = sys.stdout.read()[:-1]
        sys.stdout, sys.stdin = stdout, stdin
        self.assertEqual(out, output)

    def test_入力例_1(self):
        input = """5
4 2 5 1 3"""
        output = """3"""
        self.assertIO(input, output)

    def test_入力例_2(self):
        input = """4
4 3 2 1"""
        output = """4"""
        self.assertIO(input, output)

    def test_入力例_3(self):
        input = """6
1 2 3 4 5 6"""
        output = """1"""
        self.assertIO(input, output)

    def test_入力例_4(self):
        input = """8
5 7 4 2 6 8 1 3"""
        output = """4"""
        self.assertIO(input, output)

    def test_入力例_5(self):
        input = """1
1"""
        output = """1"""
        self.assertIO(input, output)


Measured memory_bytes: 123724
h,w,d=gets.split.map(&:to_i)
c=[]
h.times{|i|s=gets.split;w.times{|j|c[s[j].to_i-1]=[i,j]}}
b=[0]*d
(h*w-d).times{|k|b[k+d]=b[k]+(c[k][0]-c[k+d][0]).abs+(c[k][1]-c[k+d][1]).abs}
gets.to_i.times{l,r=gets.split;p b[r.to_i-1]-b[l.to_i-1]}

Measured memory_bytes: 13820
#include<iostream>
#include<vector>
#include<algorithm>
using namespace std;
typedef long long ll;
#define INF 100000000000

signed main(){
  ll n,m,r;cin >> n >> m >> r;
  vector<ll> rx(r);for(int i=0;i<r;i++)cin >> rx[i];
  vector<vector<ll>> wf(n,vector<ll>(n,INF));
  for(int i=0;i<n;i++) wf[i][i]=0;
  for(int i=0;i<m;i++){
    ll a,b,c;cin >> a >> b >> c;
    wf[a-1][b-1]=c;
    wf[b-1][a-1]=c;
  }
  for(int k=0;k<n;k++){
    for(int i=0;i<n;i++){
      for(int j=0;j<n;j++){
        wf[i][j]=min(wf[i][j],wf[i][k]+wf[k][j]);
      }
    }
  }
  ll cnt=INF;
  vector<ll> v(r);for(int i=0;i<r;i++) v[i]=i;
  do{
    ll cnt_sub=0;
    for(int i=0;i<r-1;i++){
      cnt_sub+=wf[rx[v[i]]-1][rx[v[i+1]]-1];
    }
    cnt=min(cnt,cnt_sub);
  }while(next_permutation(v.begin(),v.end()));
  cout << cnt << endl;
}


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

int n;

int main() {
    int max_num = 0;
    int sum = 0;
    std::cin >> n;
    int p[n];
    for (int i = 0; i < n; i++) {
        std::cin >> p[i];
        sum += p[i];
        if (p[i] > max_num) {
            max_num = p[i];
        }
    }
    sum -= max_num;
    if (max_num < sum) {
        std::cout << "Yes" << std::endl;
    }
    else {
        std::cout << "No" << std::endl;
    }
}


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


struct Dsu {
  struct node_struct {
    int par, size, len[2];
    node_struct(int p, int s, int b) : par(p), size(s) { 
      for (int c: {0, 1}) len[c] = b == c; 
    }
    void merge(node_struct &b) {
      b.par = par;
      size += b.size;
      len[0] += b.len[0];
      len[1] += b.len[1];
    }
  };
  vector<node_struct> nodes;
  Dsu(int n) {
    nodes.reserve(n);
    for (int i = 0; i < n / 2; ++i) nodes.emplace_back(i, 1, 0);
    for (int i = 0; i < n / 2; ++i) nodes.emplace_back(i + n / 2, 1, 1);
  }
  int anc(int x) {
    while (x != nodes[x].par) x = nodes[x].par;
    return x;
  }
  bool unite(int x, int y) {
    int a = anc(x);
    int b = anc(y);
    if (a == b) return false;
    if (nodes[a].size < nodes[b].size) swap(a, b);
    nodes[a].merge(nodes[b]);
    return true;
  }
};

int main() {
  ios_base::sync_with_stdio(false); cin.tie(0);
  int n, x, y; cin >> n;
  const int MAXN = 1e5 + 10;
  Dsu djs(MAXN * 2);
  for (int i = 0; i < n; ++i) {
    cin >> x >> y;
    djs.unite(x, y + MAXN);
  }
  vector<bool> vis(MAXN * 2, false);
  LL ans = 0;
  for (int i = 0; i < MAXN * 2; ++i) if (not vis[djs.anc(i)]) {
    int j = djs.anc(i);
    ans += 1ll * djs.nodes[j].len[0] * djs.nodes[j].len[1];
    vis[j] = 1;
  }
  cout << ans - n << '\n';
}


Measured memory_bytes: 3456
N = int( input())
SU = list( input())
SD = list( input())
Q = 10**9 + 7
i = 0
yokocnt = 0
tatecnt = 0
ans = 3
while i <= N-1:
    if SU[i] == SD[i]:
        yokocnt = 0
        i += 1
        tatecnt += 1
        if tatecnt >= 2:
            ans = (ans*2)%Q
    else:
        tatecnt = 0
        i += 2
        yokocnt += 1
        if yokocnt >= 2:
            ans = (ans*3)%Q
        else:
            ans = (ans*2)%Q
print(ans)

Measured memory_bytes: 3064
#include<bits/stdc++.h>
using namespace std;
typedef pair<int,int> P;
int main(){
    int ans,n,r;
    cin>>n>>r;
    for(int i=1;i<10000000;++i){
        if(pow(r,i)>n){
            ans=i;
            break;
        }
    }
    cout<<ans<<endl;
    return 0;
}


Measured memory_bytes: 256
#define _CRT_SECURE_NO_WARNINGS
#include "bits/stdc++.h"
using namespace std;
#define rep(i, n) for(int i=0; i<(n); ++i)
#define FOR(i, m, n) for(int i=(m); i<(n); ++i)
#define sz(x) ((int)(x).size())
#define all(x) (x).begin(),(x).end()
#define mp make_pair
#define pb push_back
#define Cout(x) cout << (x) << endl
#define Cout2(x, y) cout << (x) << " " << (y) << endl
#define dump(x) cerr << #x << " = " << (x) << endl;
#define forauto(i, a) for(auto i : a)cout << i << " "; puts("");
typedef long long LL;
typedef vector<int> VI;
typedef vector<LL> VL;
typedef vector<string> VS;
typedef vector<bool> VB;
typedef vector<vector<int>> VVI;
typedef pair<int, int> PII;
const int inf = 1e9;
const double pi = acos(-1.0);

int main() {
	int a, b; cin >> a >> b;
	dump(a);
	puts(a <= 8 && b <= 8 ? "Yay!" : ":(");
}

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

#define ll long long
#define fornum(A,B,C) for(A=B;A<C;A++)
#define mp make_pair
#define pii pair<int,int>
#define pll pair<ll,ll>

using namespace std;

/////////////////////////////////////////////////////

ll N,Q;
vector<ll> abv[202020];
ll mk[202020];
ll anss[202020];
ll i, j, k, ans;

void dfs(ll p,ll a,ll c){
    anss[a] = c + mk[a];
    ll i = 0;
    fornum(i,0,abv[a].size()){
        ll b = abv[a][i];
        if(p==b)
            continue;
        dfs(a, b, anss[a]);
    }
}

int main(){
    scanf("%lld%lld", &N,&Q);
    fornum(i,1,N){
        ll a, b;
        scanf("%lld%lld", &a, &b);
        abv[a].push_back(b);
        abv[b].push_back(a);
    }
    fornum(i,0,Q){
        ll p, x;
        scanf("%lld%lld", &p, &x);
        mk[p] += x;
    }
    dfs(-1, 1, 0);
    fornum(i,0,N){
        printf("%lld ", anss[i + 1]);
    }
    return 0;
}

Measured memory_bytes: 25728
#include<bits/stdc++.h>
using namespace std;
inline int read()
{
	char c=getchar();int x=0;bool f=0;
	while(c<'0'||c>'9') {if(c=='-') f=1;c=getchar();}
	while(c>='0'&&c<='9') {x=(x<<1)+(x<<3)+(c^48);c=getchar();}
	if(f) x=-x;
	return x;
}
inline void write(int x)
{
	if(x<0) putchar('-'),x=-x;
	if(x>=10) write(x/10);
	putchar(x%10+'0');
}
int main()
{
	int a,b,c;
	a=read();b=read();c=read();
	if(a+b+c>=22) puts("bust");
	else puts("win");
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cstring>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <utility>
#include <ctime>
#define INF 1000000000
#define LINF 9000000000000000000
#define mod 1000000007
 
#define rep(i,n) for(int i=0;i<int(n);i++)
#define rrep(i,n) for(int i=(n);i>=0;i--)
#define REP(i,a,b) for(int i=(a);i<int(b);i++)
#define all(x) (x).begin(),x.end()
#define rsort(x) sort(all(x));reverse(all(x))
#define pb push_back
#define mp make_pair
#define MOD(x) (x%(mod))
using namespace std;
 
typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef pair<int,int> pi;
 
int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};
 
bool debug=false;
/*---------------------------------------------------*/

int main(){
  pi tmp[100005];
  vector<int> data;
  int n,h;
  cin>>n>>h;
  int maxi=-1;
  rep(i,n){
    int a,b;
    cin>>a>>b;
    tmp[i]=mp(a,b);
    maxi=max(maxi,a);
  }
  rep(i,n){
    if(maxi<tmp[i].second)data.pb(tmp[i].second);
  }
  sort(all(data));reverse(all(data));
  int cnt=0;
  rep(i,data.size()){
    if(h<=0)break;
    cnt++;h-=data[i];
  }
  if(h>0){
    cnt+=h/maxi+(h%maxi!=0?1:0);
  }
  cout<<cnt<<endl;
  return 0;
}


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

int main(){
    int n,a[4][3][10]={};
    cin>>n;
    for(int i=0;i<n;i++){
        int b,c,d,e;
        cin>>b>>c>>d>>e;
        a[b-1][c-1][d-1]+=e;
    }
    for(int j=0;j<4;j++){
        for(int k=0;k<3;k++){
            for(int l=0;l<10;l++){
                if(a[j][k][l]>0){
                    cout<<" "<<a[j][k][l];
                }
                else{
                    cout<<" "<<0;
                }
            }
            cout<<endl;
        }
        if(j<3){
            cout<<"####################"<<endl;
        }
        
    }
    return 0;
}


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

int main() {
  ll X, Y, Z, K; cin >> X >> Y >> Z >> K;
  vector<ll> a, b, c;
  set<T> s;
  vector<T> v;
  for (ll i = 0; i < X; i++) {ll n; cin >> n; a.push_back(n);}
  for (ll i = 0; i < Y; i++) {ll n; cin >> n; b.push_back(n);}
  for (ll i = 0; i < Z; i++) {ll n; cin >> n; c.push_back(n);}
  sort(a.begin(), a.end());
  sort(b.begin(), b.end());
  sort(c.begin(), c.end());
  
  s.insert(T(X-1, Y-1, Z-1));
  v.push_back(T(X-1, Y-1, Z-1));
  
  while (v.size() < K) {
    ll val = 0; ll xval, yval, zval;
    for (ll i = 0; i < v.size(); i++) {
      T t = v[i]; ll x = get<0>(t); ll y = get<1>(t); ll z = get<2>(t);
      if (s.count(T(x-1,y,z))==0 && x>=1 && a[x-1]+b[y]+c[z] > val) {
        xval = x-1; yval = y; zval = z; val = a[x-1]+b[y]+c[z];
      }
      if (s.count(T(x,y-1,z))==0 && y>=1 && a[x]+b[y-1]+c[z] > val) {
        xval = x; yval = y-1; zval = z; val = a[x]+b[y-1]+c[z];
      }
      if (s.count(T(x,y,z-1))==0 && z>=1 && a[x]+b[y]+c[z-1] > val) {
        xval = x; yval = y; zval = z-1; val = a[x]+b[y]+c[z-1];
      }
    }
    s.insert(T(xval, yval, zval));
    v.push_back(T(xval, yval, zval));
  }
  
  for (ll i = 0; i < K; i++) {
    T t = v[i]; ll x = get<0>(t); ll y = get<1>(t); ll z = get<2>(t);
    cout << a[x]+b[y]+c[z] << endl;
  }
}

Measured memory_bytes: 512
#include <iostream>
#include <string>

const char BLACK = 'B';
const char WHITE = 'W';

int main() {
	std::string S;
	std::cin >> S;

	long long result = 0;
	int blackNum = 0;
	for(int i = S.length() - 1; i >= 0; i--) {
		if(S.at(i) == BLACK) {
			result += (S.length() - 1) - i - blackNum;
			blackNum++;
		}
	}

	std::cout << result << std::endl;

	return 0;
}

Measured memory_bytes: 640
import sys
input = sys.stdin.readline

n = int(input())
ss = [[""]]*n
for i in range(n):
    s = list(input())
    s.sort()
    ss[i] = s

ss.sort()

ans = 0
while len(ss) != 0:
    f = ss.pop(0)
    c = 1
    while len(ss) > 0:
        d = ss[0]
        if f == d:
            ss.pop(0)
            ans += c
            c += 1
        else:
            break

print(ans)

Measured memory_bytes: 26160
import sys
sys.setrecursionlimit(10 ** 5 + 10)
def input(): return sys.stdin.readline().strip()

def resolve():
    

    s=str(input())
    al=list(chr(ord('A')+i) for i in range(26))
    if s in al: print('A')
    else: print('a')
    
resolve()

Measured memory_bytes: 61700
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ull = unsigned long long;
#define MOD 1000000007

int main(){
  ll q,h,s,d,n;
  cin>>q>>h>>s>>d>>n;
  q*=4; h*=2;
  int x=min(q,min(h,s));
  ull ans=0;
  if(2*x<=d){
    ans+=n*x;
  }else{
    if(n%2){
      ans+=(n-1)/2*d+x;
    }else{
      ans+=n/2*d;
    }
  }
  cout<<ans<<endl;
  return 0;
}

Measured memory_bytes: 256
N = int(input())

dic = {"M" : 0, "A": 0, "R": 0, "C": 0, "H": 0}
for _ in range(N):
  s = input()
  if s[0] in dic:
    dic[s[0]] += 1
      
char = ["M", "A", "R", "C", "H"]
ans = 0
for i in range(5):
  for j in range(i+1,5):
    for k in range(j+1,5):
      ans += dic[char[i]] * dic[char[j]] * dic[char[k]]
      
print(ans)

Measured memory_bytes: 70036
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.stream.IntStream;
import java.util.HashMap;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.UncheckedIOException;
import java.util.StringTokenizer;
import java.util.Map;
import java.io.BufferedReader;
import java.io.InputStream;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 *
 * @author mikit
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        LightScanner in = new LightScanner(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        DConnectivity solver = new DConnectivity();
        solver.solve(1, in, out);
        out.close();
    }

    static class DConnectivity {
        public void solve(int testNumber, LightScanner in, PrintWriter out) {
            int n = in.ints(), k = in.ints(), l = in.ints();
            UnionFind road = new UnionFind(n);
            for (int i = 0; i < k; i++) {
                road.union(in.ints() - 1, in.ints() - 1);
            }
            UnionFind rail = new UnionFind(n);
            for (int i = 0; i < l; i++) {
                rail.union(in.ints() - 1, in.ints() - 1);
            }
            Map<Long, Integer> count = new HashMap<>();
            for (int i = 0; i < n; i++) {
                count.merge(road.find(i) + 300_000L * rail.find(i), 1, (x, y) -> x + y);
            }
            for (int i = 0; i < n; i++) {
                out.println(count.get(road.find(i) + 300_000L * rail.find(i)));
            }
        }

    }

    static class UnionFind {
        private final int[] groups;

        public UnionFind(int size) {
            groups = IntStream.range(0, size).toArray();
        }

        public int find(int i) {
            int ans = groups[i];
            while (ans != groups[ans]) {
                ans = groups[ans];
            }
            return groups[i] = ans;
        }

        public int union(int a, int b) {
            return groups[find(b)] = find(a);
        }

    }

    static class LightScanner {
        private BufferedReader reader = null;
        private StringTokenizer tokenizer = null;

        public LightScanner(InputStream in) {
            reader = new BufferedReader(new InputStreamReader(in));
        }

        public String string() {
            if (tokenizer == null || !tokenizer.hasMoreTokens()) {
                try {
                    tokenizer = new StringTokenizer(reader.readLine());
                } catch (IOException e) {
                    throw new UncheckedIOException(e);
                }
            }
            return tokenizer.nextToken();
        }

        public int ints() {
            return Integer.parseInt(string());
        }

    }
}



Measured memory_bytes: 68468
#include <bits/stdc++.h>
using namespace std;
#define REP(i,x,n) for(int i=x;i<(int)n;i++)
#define rep(i,n) REP(i,0,n)
#define sp(p) cout<<setprecision(16)<<fixed<<p<<endl;
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define SORT(a) sort(all(a))
#define RSORT(a) sort(rall(a))
#define UNIQ(a) unique(all(a))
#define UNIQNUM(a) UNIQ(a)-a.begin()
#define UNIQIT(a) a.erase(UNIQ(a), a.end());
#define VOUT(v,i) rep(i,v.size())cout<<v[i]<<(i==v.size()-1?"\n":" ");
#define vout(v) VOUT(v,z);
#define vdbg(v,i) cout<<#v<<": ";for(int i=0;i<(int)v.size();i++){cout<<v[i]<<" ";}cout<<"\n";
#define vmin(v) *min_element(all(v))
#define vmax(v) *max_element(all(v))
#define vsum(v) accumulate(all(v), 0LL)
#define MOUT(m,r,c) rep(i,r){rep(j,c){cout<<m[i][j]<<" ";}cout<<endl;}
#define mout(m) MOUT(m,m.size(),m[0].size())
#define debg(a) cout<<#a<<": "<<a<<endl;
#define show(a) for(cont &y:a){for(cont &x:y){cout<<x<<" ";}cout<<endl;}
#define digit(a) to_string(a).length();
template<class T>inline int out(const T &t){ print(t); putchar('\n'); return 0; }
// template<class T>inline T gcd(T a,T b){if(b==0)return a; return(gcd(b,a%b));}
// template<class T>inline T lcm(T a,T b){return a/gcd(a,b)*b;}
bool is_palindrome(string s){return s == string(s.rbegin(),s.rend());}
#define popcount __builtin_popcount
typedef long long ll;
typedef long double ld;
typedef pair<ll,ll> P;
typedef vector<ll> V;
typedef vector<vector<ll>> VV;
// const long long MOD=1000000007;
const long long INF = 1e18;
#define EPS (1e-7)
#define PI (acos(-1))
template<class T>
inline bool chmax(T &a, T b) {
    if(a < b) { a = b; return true; }
    return false;
}
template<class T>
inline bool chmin(T &a, T b) {
    if(a > b) { a = b; return true; }
    return false;
}



int main(){
    long long K;
    scanf("%lld",&K);
    ll seven=0;
    ll ret=-1;
    for (long long i = 0; i < 1e7; i++) {
        seven = (seven*10 + 7)%K;
        if(seven==0) {
            ret=i+1;
            break;
        }
        // if(i<10) debg(seven);
    }
    cout << ret << endl;
    return 0;
}


Measured memory_bytes: 3756
a,b,c,x,y=map(int,input().split())
ans=a*x+b*y
m=min(x,y)
ans=min(ans,c*m*2+a*(x-m)+b*(y-m))
m=max(x,y)
ans=min(ans,c*m*2+max(a*(x-m),0)+max(b*(y-m),0))
print(ans)

Measured memory_bytes: 3188
#include <bits/stdc++.h>
#define REP(i, n) for(int i = 0;i < n;i++)
#define VSORT(v) sort(v.begin(), v.end())
#define VRSORT(v) sort(v.rbegin(), v.rend())
#define ll long long
using namespace std;
typedef pair<int, int> P;
typedef pair<ll, ll> LP;
typedef pair<int, P> PP;
typedef pair<ll, LP> LPP;
typedef vector<unsigned int>vec;
typedef vector<vec> mat;
typedef vector<vector<int>> Graph;

const int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1};
const int dy[8] = {0, 1, 0, -1, 1, 1, -1, -1};
const int INF = 1000000000;
const ll LINF = 1000000000000000000;//1e18
const ll  MOD = 1000000007;
const double PI = acos(-1.0);
const double EPS = 1e-10;

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; }
template<class T> inline void add(T &a, T b){a = ((a+b) % MOD + MOD) % MOD;};

int UP[2020][2020],DOWN[2020][2020],LEFT[2020][2020],RIGHT[2020][2020];

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int H, W;
    cin >> H >> W;
    vector<string> fi(H);
    REP(i,H) cin >> fi[i];

    REP(i,H){
        int cur = 0;
        for(int j=0;j<W;j++){
            if(fi[i][j] == '#') cur = 0;
            else cur++;
            RIGHT[i][j] = cur;
        }
    }
    REP(i,H){
        int cur = 0;
        for(int j=W-1;j>=0;j--){
            if(fi[i][j] == '#') cur = 0;
            else cur++;
            LEFT[i][j] = cur;
        }
    }
    REP(j,W){
        int cur = 0;
        for(int i=0;i<H;i++){
            if(fi[i][j] == '#') cur = 0;
            else cur++;
            UP[i][j] = cur;
        }
    }
    REP(j,W){
        int cur = 0;
        for(int i=H-1;i>=0;i--){
            if(fi[i][j] == '#') cur = 0;
            else cur++;
            DOWN[i][j] = cur;
        }
    }
    int ans = 0;
    REP(i,H) REP(j,W){
        if(fi[i][j] == '#') continue;
        chmax(ans, UP[i][j] + DOWN[i][j] + LEFT[i][j] + RIGHT[i][j] - 3);
    }
    cout << ans << endl;
}


Measured memory_bytes: 68096
#include <iostream>
#include <string>
#include <fstream>
#include <sstream>
#include <vector>
#include <algorithm>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <set>
#include <cmath>
#include <map>
#include <queue>
#define rep(i,n) for(int i=0;i<(int)n;i++)
#define repp(i,k,n) for(int i=k;i<(int)n;i++)
#define PB(a) push_back(a)
using namespace std;
typedef vector<int>  vi;
int debu(string a)
{
	cout << a << endl;
}
int debu()
{
	cout << "ok" << endl;
}
int debu(int a)
{
	cout << a << endl;
}
int in()
{
	int x; cin >> x;
	return x;
}
string kkk(string hoge, int a, int A, int b, int B, int c, int C, int d, int D, int e, int E)
{
	swap(hoge[a], hoge[A]);
	swap(hoge[b], hoge[B]);
	swap(hoge[c], hoge[C]);
	swap(hoge[d], hoge[D]);
	swap(hoge[e], hoge[E]);
	return hoge;
}
bool kakunin(string a)
{
	for (int i = 1; i <= 9; i++)if (a[i] != a[1] || a[i + 21] != a[22])return false;
	for (int i = 1; i <= 3; i++)if (a[9 + i] != a[10] || a[i + 12] != a[13] || a[i + 15] != a[16] || a[i + 18] != a[19])return false;
	return true;
}
int main()
{
	int n;
	cin >> n;
	rep(hoge, n)
	{
		string a = "a";
		rep(i, 30)
		{
			char f;
			cin >> f;
			a += f;
		}

		map<string, int> mp;
		mp[a] = 0;
		if (kakunin(a))
		{
			cout << 0 << endl;
			continue;
		}
		queue<string> qu;
		qu.push(a);

		while (!qu.empty())
		{
			string now = qu.front();
			qu.pop();
			string b;

			b = kkk(now, 1, 28, 2, 29, 3, 30, 19, 21, 15, 16);
			if (mp.count(b) == 0)
			{
				mp[b] = mp[now] + 1;
				qu.push(b);
				if (kakunin(b))
				{
					cout << mp[b] << endl;
					break;
				}
			}

			b = kkk(now, 7, 22, 8, 23, 9, 24, 13, 18, 10, 12);
			if (mp.count(b) == 0)
			{
				mp[b] = mp[now] + 1;
				qu.push(b);
				if (kakunin(b))
				{
					cout << mp[b] << endl;
					break;
				}
			}


			b = kkk(now, 1, 24, 4, 27, 7, 30, 10, 21, 16, 18);
			if (mp.count(b) == 0)
			{
				mp[b] = mp[now] + 1;
				qu.push(b);
				if (kakunin(b))
				{
					cout << mp[b] << endl;
					break;
				}
			}


			b = kkk(now, 3, 22, 6, 25, 9, 28, 12, 19, 13, 15);
			if (mp.count(b) == 0)
			{
				mp[b] = mp[now] + 1;
				qu.push(b);
				if (kakunin(b))
				{
					cout << mp[b] << endl;
					break;
				}
			}



		}
	}
}

Measured memory_bytes: 1256
#include <iostream>
using namespace std;
int main(void){
    int n;
    cin>>n;
    int f=0;
    int p;
    for(int i=1;i<=n;i++){
        cin>>p;
        if(p!=i) f++;
    }
    if(f<=2) cout<<"YES";
    else cout<<"NO";
}


Measured memory_bytes: 256
#include <stdio.h>

int main(){
  int x,y;
  int A[13]={0,1,3,1,2,1,2,1,1,2,1,2,1};
  scanf("%d %d",&x,&y);
  if(A[x]==A[y]){
    printf("Yes\n");
  }else{
    printf("No\n");
  }
}


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

#define ll long long
#define fornum(A,B,C) for(A=B;A<C;++A)
#define pii pair<int,int>
#define pll pair<ll,ll>

using namespace std;

/////////////////////////////////////////////////////
ll A, B, M;
ll a[101010], b[101010];
ll i, j, k,ans;
int main(){
    scanf("%lld%lld%lld", &A,&B,&M);
    j = 1e9;
    fornum(i,0,A){
        scanf("%lld", &a[i]);
        j = min(j, a[i]);
    }
    k = 1e9;
    fornum(i,0,B){
        scanf("%lld", &b[i]);
        k = min(k, b[i]);
    }
    ans = j + k;

    fornum(i,0,M){
        ll x, y,c;
        scanf("%lld%lld%lld", &x, &y, &c);
        ans = min(ans, a[x - 1] + b[y - 1] - c);
    }
    printf("%lld", ans);
    return 0;
}

Measured memory_bytes: 1792
n = int(input())

aa = [[int(n) for n in input().split()] for i in range(n)]

s = [0] * 3

for a in aa:
    s = [max(s[1], s[2]) + a[0], 
        max(s[0], s[2]) + a[1],
        max(s[0], s[1]) + a[2]
    ]

print(max(s))

Measured memory_bytes: 24308
def main():
    import sys
    input = sys.stdin.readline
    sys.setrecursionlimit(10**7)
    from collections import Counter, deque
    #from collections import defaultdict
    from itertools import combinations, permutations, accumulate, groupby, product
    from bisect import bisect_left,bisect_right
    from heapq import heapify, heappop, heappush
    from math import floor, ceil
    #from operator import itemgetter

    #inf = 10**17
    #mod = 10**9 + 7

    s = input().rstrip()
    for i in range(3):
        if s[i] == s[i+1]:
            print('Bad')
            exit()
    print('Good')

if __name__ == '__main__':
    main()

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

#define ll long long
#define ull unsigned long long
#define vii vector<int>
#define pii pair<int,int>
#define pll pair<long long,long long>
#define pdd pair<double,double>
#define pldld pair<long long double, long long double>
#define ff first
#define ss second
#define pb push_back
#define read freopen("alu.txt","r",stdin);
#define write freopen("vorta.txt","w",stdout);
#define fastio ios::sync_with_stdio(false); cin.tie(NULL);
#define PI 2*acos(0.0)
#define DEBUG(x) cerr << #x << " = " << x << endl

const int MAX = 2e6 + 5, MOD = 998244353  , MAXLG = log2(MAX)+1;
const ll inf = 1e18 + 5;

ll arr[MAX];
int main(){

    fastio;
    ll n,a,b;
    cin>>n>>a>>b;

    if((b-a)%2 == 1){
        if(a == 1 && b == n){
            cout<<min(n-1, 1 + (n-2)/2)<<"\n";
            return 0;
        }
        if(a == 1){
            cout<<min(b-a, 1 + (b-a-1)/2);
            return 0;
        }
        if(b == n){
            cout<<min(n-a, 1 + (n-a-1)/2);
            return 0;
        }
        ll d = b-a;
        ll m = a-1;
        ll p = m + 1 + (d/2);
//        cout<<"p = " <<p<<"\n";
        m = n-b;
        ll q = m + 1 + (d/2);
//        cout<<"q = "<<q<<"\n";
        cout<<min(n-a, min(b-1, min(p,q)))<<"\n";
    }
    else{
        ll d = (b-a);
        d/=2;
        ll e = min(n-a,b-1);
        ll p = min(d,e);
        cout<<p<<"\n";
    }


}


Measured memory_bytes: 256
import sys
import math
import collections
import itertools
import array
import inspect

# Set max recursion limit
sys.setrecursionlimit(1000000)


# Debug output
def chkprint(*args):
    names = {
        id(v): k
        for k, v in inspect.currentframe().f_back.f_locals.items()
    }
    print(', '.join(
        names.get(id(arg), '???') + ' = ' + repr(arg) for arg in args))


# Binary converter
def to_bin(x):
    return bin(x)[2:]


def li_input():
    return [int(_) for _ in input().split()]


def gcd(n, m):
    if n % m == 0:
        return m
    else:
        return gcd(m, n % m)


def gcd_list(L):
    v = L[0]

    for i in range(1, len(L)):
        v = gcd(v, L[i])

    return v


def lcm(n, m):
    return (n * m) // gcd(n, m)


def lcm_list(L):
    v = L[0]

    for i in range(1, len(L)):
        v = lcm(v, L[i])

    return v


# Width First Search (+ Distance)
def wfs_d(D, N, K):
    """
    D: 隣接行列(距離付き)
    N: ノード数
    K: 始点ノード
    """

    dfk = [-1] * (N + 1)
    dfk[K] = 0

    cps = [(K, 0)]
    r = [False] * (N + 1)
    r[K] = True
    while len(cps) != 0:
        n_cps = []
        for cp, cd in cps:
            for i, dfcp in enumerate(D[cp]):
                if dfcp != -1 and not r[i]:
                    dfk[i] = cd + dfcp
                    n_cps.append((i, cd + dfcp))
                    r[i] = True

        cps = n_cps[:]

    return dfk


# Depth First Search (+Distance)
def dfs_d(v, pre, dist):
    """
    v:  現在のノード
    pre: １つ前のノード
    dist: 現在の距離

    以下は別途用意する
    D: 隣接リスト(行列ではない)
    D_dfs_d: dfs_d関数で用いる，始点ノードから見た距離リスト
    """

    global D
    global D_dfs_d

    D_dfs_d[v] = dist

    for next_v, d in D[v]:
        if next_v != pre:
            dfs_d(next_v, v, dist + d)

    return


def sigma(N):
    ans = 0
    for i in range(1, N + 1):
        ans += i
    return ans


def comb(n, r):
    if n - r < r: r = n - r
    if r == 0: return 1
    if r == 1: return n

    numerator = [n - r + k + 1 for k in range(r)]
    denominator = [k + 1 for k in range(r)]

    for p in range(2, r + 1):
        pivot = denominator[p - 1]
        if pivot > 1:
            offset = (n - r) % p
            for k in range(p - 1, r, p):
                numerator[k - offset] /= pivot
                denominator[k] /= pivot

    result = 1
    for k in range(r):
        if numerator[k] > 1:
            result *= int(numerator[k])

    return result

def bisearch(L, target):
    low = 0
    high = len(L) - 1
    
    while low <= high:
        mid = (low + high) // 2
        guess = L[mid]
        if guess == target:
            return True
        elif guess < target:
            low = mid + 1
        elif guess > target:
            high = mid - 1
    if guess != target:
        return False

# --------------------------------------------

dp = None


def main():
    N = int(input())

    if N <= 999:
        print("ABC")
    else:
        print("ABD")


main()


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

void fast()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
}

void solve()
{
    int n;
    cin>>n;
    long long int arr[n];
    for(int i=0;i<n;i++)
        cin>>arr[i];
    sort(arr,arr+n,greater<int>());
    long long int res=0;
    int target=n-1;
    int i=0,count=0;
    while(count!=target)
    {
        if(i==0)
        {  res=res+arr[0]; i++; count++;}
        else
        {   
            res=res+arr[i];
            count++;
            if(count==target)
                break;
            res=res+arr[i];
            count++;
            i++;
        }
        
    }
    //cout<<count<<endl;
    cout<<res<<endl;
}

int main()
 {
	fast();
	solve();
    return 0;
}

Measured memory_bytes: 5180
#include <bits/stdc++.h>
using namespace std;
#define fastio ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define int long long

main()
{
    fastio;
    int x, cnt=0;
    int n=100;
    cin>>x;
    while(1) {
        n=n+(int)(0.01*n);
        cnt++;
        if(n>=x) {
            cout<<cnt;
            return 0;
        }
    }
}


Measured memory_bytes: 3612
#include <iostream>
#include <math.h>
using namespace std;

int main (){
    
    //合計値を算出するあれ。
    int total = 0;

    int a,b,c,d;
    cin >>  a;
    cin >>  b;
    cin >>  c;
    cin >>  d;
  
    if(a >= b){
        total += b;
    }else{
        total += a;
    }

    if(c >= d){
        total += d;
    }else{
        total += c;
    }
    
    cout << total << "\n";
    return 0;
    
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
const int N = 1001;
int f[1000] = {2, 3};
int par[1000];

void init()
{
	for (int i = 0; i < 1000; i++) par[i] = i;
}

int find(int x)
{
	if (par[x] == x) return x;
	return par[x] = find(par[x]);
}

void _union(int x, int y)
{
	x = find(x);
	y = find(y);
	if (x == y) return;
	par[x] = y;
}

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

int main()
{
	for (int i = 2; i < 1000; i++){
		f[i] = (f[i - 2] + f[i - 1]) % N;
	}
	
	int v, d;
	while (scanf("%d %d", &v, &d) != EOF){
		init();
		for (int i = 0; i < v; i++){
			for (int j = 1; j < v; j++){
				if (abs(f[i] - f[j]) < d){
					_union(i, j);
				}
			}
		}
		
		int res = 0;
		for (int i = 0; i < v; i++){
			res += (i == par[i]);
		}
		printf("%d\n", res);
	}
	
	return 0;
}

Measured memory_bytes: 1200
#include <iostream>
#include <algorithm>
#include <vector>
#include <queue>
using namespace std;
  
const int MAXR = 21;
const int MAXC = 21;
const int di[] = {0,1,0,-1};
const int dj[] = {1,0,-1,0};
  
struct State {
  int i, j, d, m;
  State();
  State(int i, int j, int d, int m)
    : i(i), j(j), d(d), m(m) {}
};
  
int R, C;
char G[MAXR][MAXC];
bool vis[MAXR][MAXC][4][16];
  
bool canFinish() {
  State s(0,0,0,0);
  queue<State> que;
  que.push(s);
  fill(vis[0][0][0], vis[MAXR][0][0], false);
  vis[s.i][s.j][s.d][s.m] = true;
  
  while(!que.empty()) {
    s = que.front();
    que.pop();
  
    if(isdigit(G[s.i][s.j])) {
      s.m = G[s.i][s.j] - '0';
    } else {
      switch(G[s.i][s.j]) {
      case '<':
        s.d = 2;
        break;
      case '>':
        s.d = 0;
        break;
      case '^':
        s.d = 3;
        break;
      case 'v':
        s.d = 1;
        break;
      case '_':
        if(s.m == 0) s.d = 0;
        else s.d = 2;
        break;
      case '|':
        if(s.m == 0) s.d = 1;
        else s.d = 3;
        break;
      case '?':
        s.d = -1;
        break;
      case '.':
        //
        break;
      case '@':
        return true;
      case '+':
        s.m = (s.m+1)%16;
        break;
      case '-':
        s.m = (s.m-1+16)%16;
        break;
      }
    }
  
    vector<State> next;
    if(s.d == -1) {
      for(s.d = 0; s.d < 4; ++s.d) {
        next.push_back(s);
      }
    } else {
      next.push_back(s);
    }
  
    for(int k = 0; k < next.size(); ++k) {
      State &t = next[k];
      t.i = (t.i + di[t.d] + R) % R;
      t.j = (t.j + dj[t.d] + C) % C;
      if(vis[t.i][t.j][t.d][t.m]) continue;
      vis[t.i][t.j][t.d][t.m] = true;
      que.push(t);
    }
  }
  return false;
}
  
int main() {
  while(cin >> R >> C) {
    for(int i = 0; i < R; ++i) {
      for(int j = 0; j < C; ++j) {
        cin >> G[i][j];
      }
    }
    if(canFinish()) {
      cout << "YES" << endl;
    } else {
      cout << "NO" << endl;
    }
  }
  return 0;
}

Measured memory_bytes: 1256
#include<cstdio>
#include<string>
#include<cstring>
#include<stack>
#include<queue>
#include<vector>
#include<map>
#include<set>
#include<cmath>
#include<bitset>
#include<iostream>
#include<algorithm>
#include<numeric>
#include<complex>
#define inf 0x3f3f3f3f3f3f3f3f
#define fi first
#define se second
#define pb push_back
#define ll long long
#define pii pair<int,int> 
const int N=1e6+10;
const int mod=998244353;
using namespace std;
 

void solve(){
    ll x; cin>>x;
    ll ans=x/500*1000;
    x%=500; x-=x%5;
    cout<<(ans+x)<<endl;
}
int main() 
{
    int _=1;  //scanf("%d",&_);
    while(_--) solve();
return 0;
}
/*
*/
 

Measured memory_bytes: 256
s=list(map(int, list(input())))
cnt1=0
cnt2=0
for i in range(len(s)):
    if i%2==0:
        if s[i]==0:
            cnt1+=1
        else:
            cnt2+=1
    else:
        if s[i]==1:
            cnt1+=1
        else:
            cnt2+=1
print(min(cnt1, cnt2))

Measured memory_bytes: 4652
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <queue>
#include <limits>
#include <cassert>
constexpr long MOD = 1e9 + 7;
using namespace std;
using VI = vector<int>;
using P = pair<int, int>;
constexpr P all_visited = P(-1, -1);

VI adj[101010];
int visited[101010];
int pre[101010];
int s, t;

P unvisited() {
    for (auto i: adj[s]) {
        if (!visited[i]) return P(s, i);
    }
    for (auto i: adj[t]) {
        if (!visited[i]) return P(t, i);
    }
    return all_visited;
}

int main() {
    int n, m;
    cin >> n >> m;
    for (int i = 0; i < 101010; i++) {
        pre[i] = -1;
    }
    for (int i = 0; i < m; i++) {
        int a, b;
        cin >> a >> b;
        a--;
        b--;
        if (i == 0) {
            s = a;
            t = b;
            visited[s] = 1;
            visited[t] = 1;
            pre[s] = -2;
            pre[t] = -2;
        }
        adj[a].push_back(b);
        adj[b].push_back(a);
    }
    P u;
    while ((u = unvisited()) != all_visited) {
        int from = u.first;
        int to = u.second;
        pre[to] = from;
        visited[to] = 1;
        if (from == s) {
            s = to;
        } else {
            t = to;
        }
    }
    
    VI path1, path2;
    path1.push_back(s);
    path2.push_back(t);
    while (pre[s] != -2) {
        s = pre[s];
        path1.push_back(s);
    }
    while (pre[t] != -2) {
        t = pre[t];
        path2.push_back(t);
    }
    reverse(path2.begin(), path2.end());
    cout << path1.size() + path2.size() << endl;
    for (int i: path1) {
        cout << i + 1 << " ";
    }
    for (int i = 0; i < path2.size(); i++) {
        if (i != path2.size() - 1) {
            cout << path2[i] + 1 << " ";
        } else {
            cout << path2[i] + 1 << endl;
        }
    }
}


Measured memory_bytes: 7672