akhauriyash/Code-Regression huggingface dataset:
#include<iostream>
using namespace std;
#define MAX 2000000

int H,A[MAX+1];

void maxHeapify(int i)
{
	int l=2*i;
	int r=2*i+1;
	int largest;

	if(l<=H&&A[l]>A[i]) largest=l;
	else largest=i;
	if (r<=H&&A[r]>A[largest])
	{
		largest=r;
	}

	if (largest!=i)
	{
		swap(A[i],A[largest]);
		maxHeapify(largest);
	}
}


int main(int argc, char const *argv[])
{
	cin>>H;
	for (int i = 1; i <= H; ++i)
	{
		cin>>A[i];
	}

	for (int i = H/2; i >0; --i)
	{
		maxHeapify(i);
	}

	for (int i = 1; i <= H; ++i)
	{
		cout<<" "<<A[i]; 
	}

	cout<<endl;
	return 0;
}


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

int main()
{
    int a,b,c,d,t,k;
    while(~scanf("%d%d%d%d",&a,&b,&c,&d))
    {
        t=a*b;
        k=c*d;
        if(t>k)
            printf("%d\n",t);
        if(t<k)
            printf("%d\n",k);
        if(t==k)
            printf("%d\n",t);
    }
    return 0;
}


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



#define pp pair<int,int>
#define oo 100000000
#define RRR ios_base::sync_with_stdio(false);cin.tie(0);
#define ll long long
// #define int ll

int32_t main()
{RRR
    int n;
    cin >> n;
    cout << n/3;
  
    return 0;
}

Measured memory_bytes: 256
local mmi = math.min
local n = io.read("*n")

-- p1 p2 p3 p4 p5
-- ...===---===...

local p1, p2, p3, p4, p5 = 0, 0, 0, 0, 0
for i = 1, n do
  local v1 = mmi(p1, p2)
  local v2 = mmi(v1, p3)
  local v3 = mmi(v2, p4)
  local v4 = mmi(v3, p5)
  local a = io.read("*n")
  p5 = v4 + a
  if a == 0 then
    p4 = v3 + 2
  else
    p4 = v3 + a % 2
  end
  p3 = v2 + (a + 1) % 2
  if a == 0 then
    p2 = v1 + 2
  else
    p2 = v1 + a % 2
  end
  p1 = p1 + a
end
local ret = p1
ret = mmi(ret, p2)
ret = mmi(ret, p3)
ret = mmi(ret, p4)
ret = mmi(ret, p5)
print(ret)


Measured memory_bytes: 760
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
#define _USE_MATH_DEFINES
#include <bits/stdc++.h>
#define int long long
#define rep(i,n) for(int i = 0; i < (n); i++)
#define divup(a,b) ( ( (a) + ( (b) - 1u) ) / (b) ) // a/b の余り切り上げ
// #include <boost/multiprecision/cpp_int.hpp>
// using namespace boost::multiprecision;
ll mod = 1000000007;
ll mod9 = 1000000009;

signed main(){
    ll ans;
    ll x,t=100;
    cin>>x;
    rep(i,10000){
        t *= 1.01;
        if(t>=x){
            ans = i+1;
            break;
        }
    }
    cout<<ans<<endl;
}


Measured memory_bytes: 3652
/*input
3
1 2 3
*/
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define endl "\n"
typedef vector<int> vii;
typedef pair<int,int> pii;
#define F first
#define S second
#define pb push_back
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);

void solve(){
	int n;
	cin>>n;
	int a;
	int o[100]={0};
	int ans =0;
	for(int i = 0; i<n;++i){
		cin>>a;
		for(int j=0;j<=63;++j){
			if(a&(1LL<<j)){
				++o[j];
			}
		}
	}

	for(int i=0;i<=63;++i){
		if(o[i]!=0 && o[i]!=n){
			int x = o[i]*(n-o[i]);
			for(int j=0;j<i;++j){
				x*=2;
				x%= 1000000007LL;
			}
			ans+=x;
			ans%=1000000007LL;
		}
	}	
	cout<<ans%(1000000007LL)<<endl;
}

signed main(){
	IOS
	int t=1;
	//cin>>t;
	while(t--)
		solve();
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, n) for (ll(i) = 0; (i) < (n); (i)++)
#define all(x) (x).begin(), (x).end()
#define print(x) cout << (x) << endl;

typedef long long ll;
const ll INF = 99999999999999;
const ll MOD = 1000000007;
const double PI = acos(-1.0);

ll gcd(ll a, ll b)
{
    if (b == 0)
        return a;
    return gcd(b, a % b);
}
ll lcm(ll number1, ll number2)
{
    return number1 * number2 / gcd(number1, number2);
}
template <class T>
bool contain(const std::string &s, const T &v)
{
    // contain(to_string(N), '3')
    return s.find(v) != std::string::npos;
}

int ctoi(char c)
{
    if (c >= '0' && c <= '9')
        return c - '0';
    return 0;
}
using namespace std;

unsigned GetDigit(unsigned num)
{
    return std::to_string(num).length();
}

int H, W;
int sx, sy;                                       //スタートの座標
int gx, gy;                                       //ゴールの座標
int dx[4] = {1, 0, -1, 0}, dy[4] = {0, 1, 0, -1}; //移動する方向
vector<string> s(H + 100);

typedef pair<int, int> P;

int bfs()
{
    queue<P> que;
    int cnt[H][W]; //スタートからの距離を格納する配列
    //初期化
    for (int i = 0; i < H; ++i)
    {
        for (int j = 0; j < W; ++j)
        {
            cnt[i][j] = -1;
        }
    }
    //スタートをキューに入れ、その地点を0にする
    que.push(P(sx, sy));
    cnt[sx][sy] = 0;
    //キューが0になるまでループ
    while (que.size())
    {
        //先頭のキューを取ってくる
        P p = que.front();
        que.pop();
        //キューがゴールなら探索終了
        if (p.first == gx && p.second == gy)
            break;
        //移動方向にループ
        for (int i = 0; i < 4; ++i)
        {
            int nx = p.first + dx[i];
            int ny = p.second + dy[i];
            if (0 <= nx && nx < H && 0 <= ny && ny < W && s[nx][ny] != '#' && cnt[nx][ny] == -1)
            {
                que.push(P(nx, ny));
                cnt[nx][ny] = cnt[p.first][p.second] + 1;
            }
        }
    }
    return cnt[gx][gy];
}

int main()
{
    //入力
    cin >> H >> W;
    for (int i = 0; i < H; ++i)
        cin >> s[i];
    int ans = 0;
    rep(i, H)
    {
        rep(j, W)
        {
            rep(k, H)
            {
                rep(l, W)
                {
                    sx = i;
                    sy = j;
                    gx = k;
                    gy = l;
                    if (s.at(sx).at(sy) != '#' && s.at(gx).at(gy) != '#')
                    {
                        ans = max(bfs(), ans);
                    }
                }
            }
        }
    }

    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
#include "bits/stdc++.h"
#include <iostream>
#include <string.h>
#include <stdio.h>
#include <map>
#include <vector>
#include <math.h>
#include <algorithm>
#include <queue>
#include <set>
#include <tuple>
using namespace std;

#define FOR(i,init,a) for(int i=init; i<a; i++)
#define rep(i,a) FOR(i,0,a)
#define rrep(i,a) for(int i=a; i>=0; i--)
#define rep1(i,a) for(int i=1; i<=a; i++)
#define cout1(a) cout << a << endl;
#define cout2(a,b) cout << a << " " << b << endl;
#define cout3(a,b,c) cout << a << " " << b << " " << c << endl;
#define cout4(a,b,c,d) cout << a << " " << b << " " << c << " " << d << endl;
#define mem(a,n) memset( a, n, sizeof(a))
#define all(a) a.begin(),a.end()
#define chmin(a,b) a=min(a,b);
#define chmax(a,b) a=max(a,b);

typedef long long ll;
typedef long double ld;
typedef pair<int,int> pii;
typedef vector<int> V;
typedef vector<V> VV;
typedef vector<VV> VVV;
const int INF = 1e9;
const int MOD = 1e9+7;
const ll LLINF = 1e18;
static const double pi = 3.141592653589793;

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    
    string s,ans;
    cin>>s;
    
    rep(i,s.size()){
        if(i%2==0) ans+=s[i];
    }
    cout1(ans)
}

Measured memory_bytes: 592
#include <iostream>

int main()
{
    int a{}, b{};
    std::cin >> a;
    std::cin >> b;
    for (int i = 1; i <= 3; i++) {
        if (a != i && b != i) {
            std::cout << i << std::endl;
            break;
        }
    }
    return 0;
}


Measured memory_bytes: 256
fun main(args: Array<String>) {

    val (N, D) = readLine()!!.split(" ").map(String::toInt)
    val X = Array(N) { readLine()!!.split(" ").map(String::toInt) }

    var sum = 0
    for (i in 0 until N - 1) {
        for (j in i + 1 until N) {
            val result =
                X[i].zip(X[j]).map { (it.first - it.second) }.map { it * it }.sum().let { Math.sqrt(it.toDouble()) }
            if (Math.ceil(result) == result) {
                sum++
            }
        }
    }
    println(sum)
}

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

result = []
if N % 2 != 0:
    for i in range(1, N):
        result.append(str(N)+' '+str(i))
else:
    N = N+1

for i in range(1,N):
    for j in range(1,N):
        if i == j:
            continue
        if N - i == j or N - j == i:
            continue
        if (str(j)+' '+str(i)) in result:
            continue
        result.append(str(i)+' '+str(j))

print(len(result))
for x in result:
    print(x)

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

#define FOR(i,a,b) for(int i= (a); i<((int)b); ++i)
#define RFOR(i,a) for(int i=(a); i >= 0; --i)
#define FOE(i,a) for(auto i : a)
#define ALL(c) (c).begin(), (c).end()
#define RALL(c) (c).rbegin(), (c).rend()
#define DUMP(x)  cerr << #x << " = " << (x) << endl;
#define SUM(x) std::accumulate(ALL(x), 0LL)
#define MIN(v) *std::min_element(v.begin(), v.end())
#define MAX(v) *std::max_element(v.begin(), v.end())
#define EXIST(v,x) (std::find(v.begin(), v.end(), x) != v.end())
#define BIT(n) (1LL<<(n))
#define UNIQUE(v) v.erase(unique(v.begin(), v.end()), v.end());

typedef long long LL;
template<typename T> using V = std::vector<T>;
template<typename T> using VV = std::vector<std::vector<T>>;
template<typename T> using VVV = std::vector<std::vector<std::vector<T>>>;

template<class T> inline T ceil(T a, T b) { return (a + b - 1) / b; }
template<class T> inline void print(T x) { std::cout << x << std::endl; }
template<class T> inline void print_vec(const std::vector<T> &v) { for (int i = 0; i < v.size(); ++i) {  if (i != 0) {std::cout << " ";} std::cout << v[i];} std::cout << "\n"; }
template<class T> inline bool inside(T y, T x, T H, T W) {return 0 <= y and y < H and 0 <= x and x < W; }
template<class T> inline double euclidean_distance(T y1, T x1, T y2, T x2) { return sqrt((x1 - x2) * (x1 - x2) + (y1 - y2) * (y1 - y2)); }
template<class T> inline double manhattan_distance(T y1, T x1, T y2, T x2) { return abs(x1 - x2) + abs(y1 - y2); }

const int INF = 1L << 30;
const double EPS = 1e-9;
const std::string YES = "YES", Yes = "Yes", NO = "NO", No = "No";
const std::vector<int> dy4 = { 0, 1, 0, -1 }, dx4 = { 1, 0, -1, 0 };    // 4近傍（右, 下, 左, 上）
const std::vector<int> dy8 = { 0, -1, 0, 1, 1, -1, -1, 1 }, dx8 = { 1, 0, -1, 0, 1, 1, -1, -1 };

using namespace std;


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

	int N;
	cin >> N;

	vector<int> dp(100100, 0);
	FOR(i, 0, N) {
	    int a, b;
	    cin >> a >> b;
	    dp[a] += 1;
	    dp[b + 1] -= 1;
	}

	FOR(i, 0, dp.size() - 1) {
	    dp[i + 1] += dp[i];
	}

	int ans = 0;
	FOR(i, 0, dp.size()) {
	    if (dp[i] + 1 >= i) {
            ans = max(ans, i - 1);
        }
	}
	print(ans);

	return 0;
}


Measured memory_bytes: 3484
#include<bits/stdc++.h>
typedef long long ll;
#define pii pair<int,int>
#define ff first
#define ss second
using namespace std;
void fast()
{
ios::sync_with_stdio(false);
cin.tie(NULL); cout.tie(NULL);
}

int main()
{
    fast();
       ll x;
   cin >> x;

   ll bank = 100;
   for (int i=1;; i++) {
       bank += bank * 0.01;
       if (bank >= x)
    {
        cout << i << endl;
        return 0;
    }
   }


}

Measured memory_bytes: 3580
#include<iostream>
using namespace std;
int main() {
  int N, M;
  int A[10010];
  cin >> N;
  cin >> M;
  int d = 0;
  for( int i =0; i < M; ++i){
  cin >> A[i];
  d += A[i];
  }
  int c = -1;
  if( d <= N ) c = N - d;
  cout << c << endl;
}


Measured memory_bytes: 3640
#include <iostream>
#include <unordered_map>
#include <functional>
#include <cstdio>
#include <algorithm>
using namespace std;

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

	int r;
	cin >> r;
	printf( "%d\n", (int)(3 * pow(r, 2.0)) );
	return 0;
}


Measured memory_bytes: 512
#!/usr/bin/env python3
import sys
INF = float("inf")


def solve(A: int, B: int):
    print(-(-(B-1)//(A-1)))
    return


def main():

    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    A = int(next(tokens))  # type: int
    B = int(next(tokens))  # type: int
    solve(A, B)


if __name__ == '__main__':
    main()


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

int main(){
  int n, k, q;
  cin >> n >> k >> q;
  vector<int> a(q);
  for(int i = 0; i < q; i++){
    cin >> a[i];
  }	//input
  
  for(int i = 0; i < q; i++){
    a[i]--;
  }	//0-index
  
  vector<int> imos(n, 0);
  for(int i = 0; i < q; i++){
    imos[0]--;
    imos[a[i]]++;
    if(a[i]+1 < n) imos[a[i]+1]--;
  }		
  for(int i = 1; i < n; i++){
     imos[i] += imos[i-1];
     //cout << imos[i] << endl;
  }	//imos method
  
  for(int i = 0; i < n; i ++){
    if(imos[i] <= -k){
      cout << "No" << endl;
    }
    else{
      cout << "Yes" << endl;
    }
  }
}
  
  
  

Measured memory_bytes: 4036
#include<stdio.h>
int main(){
    int sec = 0;
    int h=0,m=0,s=0;
    scanf("%d",&sec);
    h = sec/(60*60);
    m = (sec-(h*60*60))/60;
    s = sec % (60);
//    printf("%d:%d:%d\n",h=sec/24,m=(sec-24*h)/60,sec/(24*60));
    printf("%d:%d:%d\n",h,m,s);
    return 0;
}


Measured memory_bytes: 1992
#include <stdio.h>
int main(void)
{
int a, b, c;
int d = 0;


scanf("%d%d%d", &a, &b, &c);


 while(a<=b){
   
  
   if(c%a == 0){
   d++ ;
   }
   a++;
  }
  printf("%d\n", d);
  
return 0;
}

Measured memory_bytes: 596
/*
   YOU CAN'T TAKE HELP FROM EDITORIAL               .m.

#pragma GCC optimize("Ofast")
#pragma GCC target("avx,avx2,fma")
#pragma GCC optimization ("unroll-loops")

*/

#include "bits/stdc++.h"


#define sp <<" "
#define el <<"\n"
#define S second
#define F first
#define pb push_back
#define all(ar) ar.begin(),ar.end() 
#define showp(x) <<showpoint<<setprecision(x)<<fixed<<
#define pii pair<int,int >

using namespace std;
using ll = long long;
using ld = long double;
 

const ll mod = 1e9 + 7;
const ll mxr = 1e5 + 10;

set<int> ar[200005];
bool vis[200005];

int mx = 0;

void dfs(int i,int &pep){
    vis[i] = true;
    pep += 1;
    for(int r: ar[i]){
        if(!vis[r]) dfs(r,pep);
    }
    return;
}


int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
/*#ifndef ONLINE_JUDGE
    freopen("input.txt","r",stdin);
    freopen("output.txt","w",stdout);
#endif*/
    memset(vis,false,sizeof(vis));
    int n,m; cin>>n>>m;
    while(m--){
        int a,b; cin>>a>>b;
        ar[a].insert(b); ar[b].insert(a);
    }
    for(int i = 1; i <= n; i++){
        if(!vis[i]){
            int pep = 0;
            dfs(i,pep);
            mx = max(pep,mx);
        }
    }
    cout<<mx el;
    return 0;
}

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

int A[310][310], N;

int main() {
    //freopen("input.in","r",stdin);
//    freopen("output.out","w",stdout);

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

    for(int i = 0;i < N;i++) {
        for(int j = 0;j < N;j++) {
            for(int k = 0;k < N;k++) {
                if(i != j && j != k && k != i && A[i][j]+A[j][k] < A[i][k]) {
                    cout << -1 << endl;
                    return 0;
                }
            }
        }
    }

    long long answer = 0;
    for(int i = 0;i < N;i++) {
        for(int j = i+1;j < N;j++) {
            bool exist = false;
            for(int k = 0;k < N;k++) {
                if(k != i and k != j and A[i][k]+A[k][j] == A[i][j]) {
                    exist = true;
                    break;
                }
            }
            if(not exist) answer += A[i][j];
        }
    }

    cout << answer << endl;

    return 0;
}


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

int main()
{
    string s;
    cin >> s;
    int cnt = 0;
    for (char c : s)
    {
        if (c == 'o')
            cnt++;
    }
    if ((15-s.size()+cnt) >= 8)
        cout << "YES";
    else
        cout << "NO";
}


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

using namespace std;

#define sqr(x) ((x) * (x))
#define all(v) (v).begin(), (v).end()
#define rall(v) (v).rbegin(), (v).rend()

typedef vector<int> vi;
typedef map<int, int> mi;
typedef pair<int, int> pi;
typedef long long ll;

void solve() {
  int N;
  cin >> N;
  for (int i = 0; i < 50001; i++) {
    if ((int)(i * 1.08) == N) {
      cout << i << endl;
      return;
    }
  }
  cout << ":(" << endl;
}

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

  solve();

  return 0;
}


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

string s;
int K;

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

  cin >> s >> K;
  for (int i = 0; i < s.size(); i++) {
    if (s[i] == 'a') continue;
    int cost = 26 - (s[i]-'a');
    if (cost > K) continue;
    s[i] = 'a';
    K -= cost;
  }  
  K %= 26;
  s.back() = (s.back() - 'a' + K) % 26 + 'a';
  cout << s << endl;

  return 0;
}

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

int main(){
	int H, W, i, j;
	
	while(1){
		cin >> H >> W;
		if (H == 0 && W ==0){
			break;
		}
		for(i = 0; i < H; i++){
			for(j = 0; j < W;j++){
				if( (i + j)% 2 == 0){
				cout << '#';
				}else{
					cout << '.';
				}
			}
			cout << endl;

		}
		cout << endl;
	}
    return 0;
}

Measured memory_bytes: 3104
import java.util.Scanner;
public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int[] a = new int[4];
		for(int i = 0 ; i < 4 ; i++){
			int t = sc.nextInt();
			int n = sc.nextInt();
			switch (t) {
			case 1:
				a[i] = n * 6000;
				break;
			case 2:
				a[i] = n * 4000;
				break;
			case 3:
				a[i] = n * 3000;
				break;
			case 4:
				a[i] = n * 2000;
				break;
			}
		}
		for(int j : a){
			System.out.println(j);
		}
		sc.close();
	}

}

Measured memory_bytes: 17172
//abc177_e.cpp
//Sat Aug 29 20:53:45 2020

#include <iostream>
#include <string>
#include <queue>
#include <map>
#include <unordered_map>
#include <vector>
#include <algorithm>
#include <math.h>
#include <set>
#define INTINF 2147483647
#define LLINF 9223372036854775807
#define MOD 1000000007
#define rep(i,n) for (int i=0;i<(n);++i)

using namespace std;
using ll=long long;
typedef pair<int,int> P;

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

	vector<int> a(n);
	rep(i,n){
		cin >> a[i];
	}

	int p=0;
	vector<int> is_prime(2100,1);
	vector<int> prime;
	for (int i=2;i<=2000;i++){
		if(is_prime[i]){
			prime.push_back(i);
			for(int j=2*i;j<=2000;j+=i){
				is_prime[j] = 0;
			}
		}
	}

	vector<int> insu(1000000,0);
	rep(i,n){
		int temp = a[i];
		rep(j,prime.size()){
			int x = prime[j];
			if(a[i]<x*x)break;
			if (temp%x == 0){
				insu[x]++;
				temp = temp/x;
				while(temp%x==0){
					temp = temp/x;
				}
			}
		}
		insu[temp]++; //最後の割り算の余りの処理を忘れない
	}

	int pairflag = 1;
	int setflag = 1;
	for (int i=2;i<1000000;i++){
		if (insu[i]!=0){
			if (insu[i]!=1){
				pairflag = 0;
			}
			if (insu[i]==n){
				setflag = 0;
			}
		}
	}

	// rep(i,10){
	// 	cout << i << " " << insu[i] << endl;
	// }

	if(pairflag){
		cout << "pairwise coprime" << endl;
	}else if (setflag){
		cout << "setwise coprime" << endl;
	}else {
		cout << "not coprime" << endl;
	}
}

Measured memory_bytes: 11056
H, W = list(map(int, input().split()))
Ch, Cw = list(map(int, input().split()))
Dh, Dw = list(map(int, input().split()))
S = [[o for o in input()] for i in range(H) ]

def dfs(y, x, c):
    S[y][x] = c
    for dy, dx in [(-1,0), (1,0), (0,1), (0,-1)]:
            ny = y+dy
            nx = x+dx
            if nx>=0 and nx<W and ny>=0 and ny<H and S[ny][nx]=='.':
                dfs(ny, nx, c)

c = 0
for i in range(H):
    for j in range(W):
        if S[i][j]=='.':
            dfs(i, j, c)
            c+=1

arr = {i:[] for i in range(c)}

for i in range(H):
    for j in range(W):
        cla = S[i][j]
        if cla!='#':
            for dx in range(-2, 3):
                for dy in range(-2, 3):
                    nx = j+dx
                    ny = i+dy
                    if nx>=0 and nx<W and ny>=0 and ny<H and S[ny][nx]!='#':
                        if S[ny][nx]!=cla and S[ny][nx] not in arr[cla]:
                            arr[cla].append(S[ny][nx])

current = S[Ch-1][Cw-1]
goal = S[Dh-1][Dw-1]
dis = {current:0}
queue = [current]
cnt = 1
while queue:
    now = queue.pop(0)
    if arr[now]!=[]:
        for one in arr[now]:
            if one not in dis:
                dis[one] = dis[now]+1
                queue.append(one)

if goal in dis:
    print(dis[goal])
else:
    print(-1)
    

Measured memory_bytes: 179428
import heapq
X,Y,Z,K=map(int,input().split())
A=list(map(int,input().split()))
B=list(map(int,input().split()))
C=list(map(int,input().split()))
A.sort(reverse=True)
B.sort(reverse=True)
C.sort(reverse=True)

seen=[(0,0,0)]
Q=[]
heapq.heappush(Q,[-(A[0]+B[0]+C[0]),0,0,0])
for _ in range(K):
  h=heapq.heappop(Q)
  i,j,k=h[1],h[2],h[3]
  print(-h[0])
  if i+1<X:
    if (i+1,j,k) not in seen:
      heapq.heappush(Q,[-(A[i+1]+B[j]+C[k]),i+1,j,k])
      seen.append((i+1,j,k))
  if j+1<Y:
    if (i,j+1,k) not in seen:
      heapq.heappush(Q,[-(A[i]+B[j+1]+C[k]),i,j+1,k])
      seen.append((i,j+1,k))
  if k+1<Z:
    if (i,j,k+1) not in seen:
      heapq.heappush(Q,[-(A[i]+B[j]+C[k+1]),i,j,k+1])
      seen.append((i,j,k+1))
            

  


Measured memory_bytes: 4596
#include <iostream>
using namespace std;
int main()
{
	int matrix[3][3];
  	int a, b;
  	for (int i = 0; i < 3; i++){
    	for (int j = 0; j < 3; j++){
        	cin >> matrix[i][j];
        }
    }
  	a = matrix[1][0] - matrix[0][0];
  	if ((matrix[1][1] - matrix[0][1] != a) || (matrix[1][2] - matrix[0][2] != a)){
    	cout << "No";
      	return 0;
    }
  	b = matrix[2][0] - matrix[0][0];
  	if ((matrix[2][1] - matrix[0][1] != b) || (matrix[2][2] - matrix[0][2] != b)){
    	cout << "No";
      	return 0;
    }
  	cout << "Yes";
}	

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

int main() {
  string a ;
  cin >> a ;
    if(a == "MON") 
  cout << "6" << endl;
  else if(a == "TUE")
  cout << "5" << endl; 
  else if(a == "WED")
  cout << "4" << endl;
  else if(a == "THU")
  cout << "3" << endl;
  else if(a == "FRI")
  cout << "2" << endl;
  else if(a == "SAT")
  cout << "1" << endl;
  else if(a == "SUN")
  cout << "7" << endl;
  
}

Measured memory_bytes: 256
#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>
#include <climits>

using namespace std;


int lcs(string x, string y) {
    int c[1001][1001];
    int n = x.length();
    int m = y.length();
    for(int i = 0; i < n; i++) {
        c[i][0] = 0;
    }
    for(int j = 0; j < m; j++) {
        c[0][j] = 0;
    }
    for(int i = 1; i <= n; i++) {
        for(int j = 1; j <= m; j++) {
            if(x[i-1] == y[j-1]) {
                c[i][j] = c[i-1][j-1] + 1;
            } else {
                c[i][j] = max(c[i][j-1], c[i-1][j]);
            }
        }
    }
    return c[n][m];
}

int main() {
    int n;
    cin >> n;
    for(int i=0; i<n; i++) {
        string s1, s2;
        cin >> s1 >> s2;
        cout << lcs(s1, s2) << endl;
    }
}



Measured memory_bytes: 7124
#include <iostream>
using namespace std;
int main(){
    int A,B,C,x,y,z;
    cin >> A >> B >> C;
    x=0;
    y=0;
    z=0;
    if(A==5)
        x=1;
    if(A==7)
        x=2;
    if(B==5)
        y=1;
    if(B==7)
        y=2;
    if(C==5)
        z=1;
    if(C==7)
        z=2;
    if(x+y+z==4&&x!=0&&y!=0&&z!=0)
        cout << "YES";
    else
        cout << "NO";
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define int long long
using namespace std;
const int N=2e5+5,MOD=1e9+7;
int n,u,v,tmp;
int size[N],f[N];
int cnt,head[N];
struct edge{int next,to;}e[N<<1];
 
inline int pow(int a,int n)
{
	int res=1;
	while (n)
	{
		if (n&1ll) res=res*a%MOD;
		a=a*a%MOD;
		n>>=1ll;
	}
	return res;
}
 
inline void add(int u,int v)
{
	cnt++;
	e[cnt].next=head[u];
	e[cnt].to=v;
	head[u]=cnt;
}
 
void dfs(int u,int fa)
{
	size[u]=1;
	for (register int i=head[u]; i; i=e[i].next)
	if (e[i].to!=fa)
	{
		dfs(e[i].to,u);
		size[u]+=size[e[i].to];
	}
	f[1]=f[1]*size[u]%MOD;
}
 
void dp(int u,int fa)
{
	for (register int i=head[u]; i; i=e[i].next)
	if (e[i].to!=fa)
	{
		f[e[i].to]=f[u]*pow(size[e[i].to],MOD-2)%MOD*(n-size[e[i].to])%MOD;
		dp(e[i].to,u);
	}
}
 
signed main(){
	scanf("%lld",&n);
	for (register int i=1; i<n; ++i) scanf("%lld%lld",&u,&v),add(u,v),add(v,u);
	f[1]=1; dfs(1,0);
	dp(1,0);
	tmp=1;
	for (register int i=1; i<=n; ++i) tmp=tmp*i%MOD;
	for (register int i=1; i<=n; ++i) 
	{	
		f[i]=tmp*pow(f[i],MOD-2)%MOD;
		printf("%lld\n",f[i]);
	}
return 0;	
}

Measured memory_bytes: 13184
#include <iostream>
#include <string>
using std::cin;
using std::cout;
using std::endl;

int main(){
  int N, temp;
  cin >> N;

  float a[N];
  for (int i = 0; i < N; i++){
    cin >> a[i];
  }
  
  for (int i = 0; i < N; i++){
    int minj = i;
    for (int j = i + 1; j < N; j++){
      if (a[j] < a[minj]){
        minj = j;
      }
    }
    temp = a[i];
    a[i] = a[minj];
    a[minj] = temp;
  }
  
  float ans = a[0];
  for (int i = 1; i < N; i++){
    ans = (ans + a[i]) / 2;
  }

  cout << ans << endl;

  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<n;i++)
typedef long long ll;
using namespace std;
 
int main(){
  ll n;
  cin >> n;
  ll ans = 1e18;
  for(ll i=1;i*i<=n;i++){
    if(n%i!=0)continue;
    ll j = n/i;
    ans = min(ans,i+j-2);
  }
  cout << ans << endl;
}

Measured memory_bytes: 256
"""
import random
import functools
import copy
import bisect
import array
import re
import collections
import heapq
import fractions
import itertools
import string
import math
from operator import itemgetter as ig
from bisect import bisect_left, bisect_right, insort_left, insort_right
from itertools import permutations, combinations, product, accumulate, groupby
from heapq import heappush, heappop
from collections import deque, defaultdict, Counter
import sys
sys.setrecursionlimit(10 ** 7)
# import numpy as np

inf = 10 ** 20
INF = float("INF")
mod = 10 ** 9 + 7
dd = [(-1, 0), (0, 1), (1, 0), (0, -1)]
ddn = dd + [(-1, 1), (1, 1), (1, -1), (-1, -1)]
ddn9 = ddn + [(0, 0)]
'''for dx, dy in dd:
        nx = j + dx; ny = i + dy
            if 0 <= nx < w and 0 <= ny < h:'''
"""
from collections import deque, defaultdict, Counter
import math
import sys
sys.setrecursionlimit(10 ** 7)


def wi(): return list(map(int, sys.stdin.readline().split()))
# WideIntPoint


def wip(): return [int(x) - 1 for x in sys.stdin.readline().split()]


def ws(): return sys.stdin.readline().split()


def si(): return int(sys.stdin.readline())  # SingleInt


def ss(): return input()


def hi(n): return [si() for _ in range(n)]


def hs(n): return [ss() for _ in range(n)]  # HeightString


def s_list(): return list(input())


def mi(n): return [wi() for _ in range(n)]  # MatrixInt


def mip(n): return [wip() for _ in range(n)]


def ms(n): return [ws() for _ in range(n)]


def num_grid(n): return [[int(i) for i in sys.stdin.readline().split()[
    0]] for _ in range(n)]  # NumberGrid


def grid(n): return [s_list() for _ in range(n)]


def gcd(a, b):
    while b:
        a, b = b, a % b
    return a

# a/b の切り上げ


def round_up(a, b):
    """ a/b の切り上げ """
    c = (a + b - 1) / b
    return c


def lcm(a, b):
    """a,bの最小公倍数"""
    return a * b // gcd(a, b)


def main():
    s = input()[::-1]

    cnt = [0] * 2019
    # print(cnt)
    cnt[0] = 1
    ans = 0
    b = 0
    t = 1
    for i in s:
        b = b + int(i) * t
        b %= 2019
        cnt[b] += 1
        t *= 10
        t %= 2019

    for i in cnt:
        ans += i * (i - 1) // 2
    print(ans)


if __name__ == '__main__':
    main()


Measured memory_bytes: 69224
#include<bits/stdc++.h>
using namespace std;
using Int = long long;
template<typename T1,typename T2> inline void chmin(T1 &a,T2 b){if(a>b) a=b;}
template<typename T1,typename T2> inline void chmax(T1 &a,T2 b){if(a<b) a=b;}


template<typename T> void drop(const T &x){cout<<x<<endl;exit(0);}

//INSERT ABOVE HERE
signed main(){
  auto is_odd=[](Int z){return z&1;};

  Int k,x,y;
  cin>>k>>x>>y;

  Int fx=1,fy=1;
  if(x<0) x*=-1,fx=-1;
  if(y<0) y*=-1,fy=-1;
  auto print=[&](Int p,Int q){cout<<(p*fx)<<" "<<(q*fy)<<endl;};

  if(!is_odd(k)&&is_odd(x+y)) drop(-1);

  if(x+y==k){
    cout<<1<<endl;
    print(x,y);
    return 0;
  }

  if(x+y<k&&is_odd(x+y)){
    cout<<3<<endl;
    Int diff=(3*k-(x+y))/2;
    assert(k<diff && diff<k*2);
    print(-k,0);
    Int val=diff-k;
    print(-k+(k-val),-val);
    print(x,y);
  }else{
    Int n=(x+y+k-1)/k;
    if(x+y<k) n=2;
    if(is_odd((n*k)-(x+y))) n++;
    Int diff=(n*k-(x+y))/2;

    cout<<n<<endl;
    Int px=0,py=0;
    for(Int i=0;i<n;i++){
      if(diff>=k){
        Int dx=0;
        Int dy=k;
        px-=dx;
        py-=dy;

        diff-=k;
        print(px,py);
      }else if(diff>0){
        if(x-px<y-py){
          Int dx=diff;
          Int dy=k-dx;
          px-=dx;
          py+=dy;
        }else{
          Int dy=diff;
          Int dx=k-dy;
          px+=dx;
          py-=dy;
        }
        diff=0;
        print(px,py);
      }else{
        Int dx=min(x-px,k);
        Int dy=k-dx;
        px+=dx;
        py+=dy;
        print(px,py);
      }
    }
    //assert(x==px&&y==py);
  }
  return 0;
}


Measured memory_bytes: 2304
#include<iostream>
#include<vector>
#include<algorithm>
#include<bitset>
using namespace std;

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

using i64=long long;
void chmax(i64 &l, i64 r){if(l<r)l=r;}

int main(){
  const int k=16;
  while(true){
    int n; cin>> n;
    if(n==0) break;
    vector<i64> dp(1<<k, -1);
    dp[0]=0;
    while(n--){
      int m; i64 x; cin>> m>> x;
      int mask=0;
      while(m--){
        int st, ed; cin>> st>> ed;
        st-=6; ed-=6;
        for(int i=st; i<ed; i++) mask^=(1<<i);
      }
      for(int bit=(1<<k)-1; bit>=0; bit--){
        if((bit&mask)==mask and dp[bit^mask]>=0){
          chmax(dp[bit], dp[bit^mask]+x);
        }
      }
    }
    i64 mx=0;
    rep(bit, (1<<k)) chmax(mx, dp[bit]);
    cout<< mx<< endl;
  }
  return 0;
}


Measured memory_bytes: 3600
import sys
from collections import Counter

sys.setrecursionlimit(10 ** 5)


class UnionFind:
    def __init__(self, n):
        self.parent = [i for i in range(n + 1)]
        self.rank = [0 for _ in range(n + 1)]

    def find(self, x):
        if self.parent[x] == x:
            return x
        else:
            self.parent[x] = self.find(self.parent[x])
            return self.parent[x]

    def union(self, x, y):
        x = self.find(x)
        y = self.find(y)
        if self.rank[x] < self.rank[y]:
            self.parent[x] = y

        else:
            self.parent[y] = x
            if self.rank[x] == self.rank[y]:
                self.rank[x] += 1

    def check_same(self, x, y):
        return self.find(x) == self.find(y)


N, K, L = map(int, input().split())
r_union_find = UnionFind(N)
t_union_find = UnionFind(N)
for i in range(K):
    p, q = map(int, input().split())
    r_union_find.union(p, q)

for i in range(L):
    r, s = map(int, input().split())
    t_union_find.union(r, s)

pair = []

for i in range(1, N + 1):
    count = 0
    r_p = r_union_find.find(i)
    t_p = t_union_find.find(i)
    pair.append((r_p, t_p))

counter = Counter(pair)

answers = []
for p in pair:
    answers.append(counter[p])

answers = map(str, answers)
print(" ".join(answers))


Measured memory_bytes: 128072
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define all(vec) vec.begin(),vec.end()
using ll=long long;
const ll MOD=1e9+7;
const int INF=1<<30;

int main(){
  string S;
  cin >> S;
  int l=S.size();
  int N=(l+1)/2;
  reverse(all(S));
  string T=S;
  reverse(all(S));
  int ans=0;
  rep(i,N){
    if(S[i]!=T[i]) ans++;
  }
  cout << ans << endl;
}

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

using ll = int64_t;
const int MAX = 2e5;

int32_t main()
{
    ios::sync_with_stdio(false), cin.tie(nullptr);
    int k; cin >> k;
    int cnt = 1, rem = 0;
    set<int> st;
    while (1) { 
        rem = (rem*10 + 7)%k;
        if (st.count(rem)) return cout << -1, 0;
        if (rem == 0) return cout << cnt, 0;    
        cnt++;
        st.insert(rem);
    }



    return 0;
}

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

#define int unsigned long long

using namespace std;

const int INF = 11451419190721810893ULL;

signed main(void){
    int N, M, R;
    cin >> N >> M >> R; cin.ignore();
    
    vector<int> dest;
    for (int i = 0; i < R; i++) {
        int r;
        cin >> r;
        dest.push_back(r-1);
    }
    cin.ignore();
    sort(dest.begin(), dest.end());
    
    int distance[202][202];
    for (int i = 0; i < N; i++) {
        for (int k = 0; k < N; k++) {
            distance[i][k] = INF;
        }
    }
    
    for (int i = 0; i < M; i++) {
        int A, B, C;
        cin >> A >> B >> C; cin.ignore();
        A--; B--;
        distance[A][B] = C;
        distance[B][A] = C;
    }
    
    for (int i = 0; i < N; i++) {
        for (int k = 0; k < N; k++) {
            for (int m = 0; m < N; m++) {
                if (distance[k][m] > (distance[k][i] + distance[i][m])) {
                    distance[k][m] = distance[k][i] + distance[i][m];
                }
            }
        }
    }

    vector<int> perm;
    for (int i = 0; i < R; i++) {
        perm.push_back(dest[i]);
    }
    
    int ans = INF;
    do {
        int d = 0;
        int from = perm[0];
        for (int i = 1; i < R; i++) {
            int to = perm[i];
            d += distance[from][to];
            from = to;
        }
        
        if (d < ans) {
            ans = d;
        }
    } while (next_permutation(perm.begin(), perm.end()));

    cout << ans << endl;
} 


Measured memory_bytes: 512
// #pragma GCC target("avx,avx2,fma")
// #pragma GCC optimization ("Ofast")
// #pragma GCC optimization ("unroll-loops")
#include <bits/stdc++.h>

using namespace std;
// #include <ext/pb_ds/assoc_container.hpp>
// #include <ext/pb_ds/tree_policy.hpp>
// using namespace __gnu_pbds;
// template <typename T>
// using o_set = tree <T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
// #define sfind(i) find_by_order(i)
// #define ord(i) order_of_key(i)
typedef long long ll;
typedef pair<int , int> pii;
typedef pair<ll, ll> pll;
typedef vector<pii> vii;
typedef vector<pll> vll;
using cd = complex<double>;
const double pi = acos(-1);
#define mod 1000000007
#define rep(i, a, b) for(ll i = a; i < b; i++)
#define repc(i, a, b, c) for (ll i = a; (c > 0 ? i < b : i > b) and c != 0; i += c)
#define vi vector<int>
#define vl vector<ll>
#define _max(vec) (*max_element(all(vec)))
#define _min(vec) (*min_element(all(vec)))
#define fi first
#define si second
#define pb push_back
#define all(name) name.begin(), name.end()
#define ral(name) name.rbegin(), name.rend()
#define fact(n) rep(i, 1, n+1)ft.pb((ft[i-1]*i)%mod)
#define mod_in(a) power(a, mod - 2)
#define ncr(n, r) (n>=r?((ft[n]*mod_in((ft[r]*ft[(n)-(r)])%mod))%mod):0LL)
#define deb(x) cerr << "[" << #x << " " << x << "]" << endl;
#define endl '\n'  //....????
#define int ll
vector<ll> ft(1, 1LL);


/*======================================================================*/
void solve(){
    int x;
     cin >> x;
     if(x >= 30)cout << "Yes\n";
     else cout << "No\n";
}
signed main() {
	cin.sync_with_stdio(0); cin.tie(0);
	cin.exceptions(cin.failbit);
    int t = 1;
    //cin >> t;
    while(t--){
        solve();
    }
}

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

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

using namespace std;

using ll = long long;
using P = pair<int, int>;

int main() {
  int a;
  cin >> a;
  string s;
  cin >> s;

  string result = "red";
  if (a >= 3200) {
    result = s;
  }
  cout << result << endl;

  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define all(a) a.begin(), a.end()
#define db(a) cout << fixed << #a << " = " << a << endl;

using namespace std;

typedef long long ll;
typedef pair<int, int> pii;
const int MAXN = 1e6 + 100;
vector<int> SD(MAXN, 0);
void init_sieve() {
	for (ll i = 0; i < MAXN; i++) SD[i] = i;
	for (ll i = 2; i < MAXN; i++) {
		for (ll j = i *i; j < MAXN; j += i) {
			if (SD[j] != j) continue;
			SD[j] = i;
		}
	}
}

int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	init_sieve();
	int n;
	cin >> n;
	vector<ll> A(n);
	bool pc = true;
	for (int i = 0; i < n; i++) {
		cin >> A[i];
	}
	vector<bool> D(MAXN, false);
	for (int i = 0; i < n; i++) {
		if (A[i] <= 1) continue;
		ll a = A[i];
		set<ll> divs;
		while (a != 1) {
			ll d = SD[a];
			divs.insert(d);
			a /= d;
		}
		for (int d: divs) {
			if (D[d]) {
				pc = false;
			}
			D[d] = true;
		}
	}
	if (pc) {
		cout << "pairwise coprime\n";
	} else {
		ll gcd_all = __gcd(A[0], A[1]);
		for (int i = 2; i < n; i++) {
			gcd_all = __gcd(gcd_all, A[i]);
		}
		if (gcd_all == 1) {
			cout << "setwise coprime\n";
		} else {
			cout << "not coprime\n";
		}
	}
}


Measured memory_bytes: 15168
//
// じょえチャンネル
// https://www.youtube.com/channel/UCRXsI3FL_kvaVL9zoolBfbQ
//
// Created by yamunaku on 2020/02/22.
//

#include <bits/stdc++.h>

using namespace std;

#define rep(i, n) for(int i = 0; i < (n); i++)
#define repl(i, l, r) for(int i = (l); i < (r); i++)
#define per(i, n) for(int i = ((n)-1); i >= 0; i--)
#define perl(i, l, r) for(int i = ((r)-1); i >= (l); i--)
#define all(x) (x).begin(),(x).end()
#define MOD9 998244353
#define MOD1 1000000007
#define IINF 1000000000
#define LINF 1000000000000000000
#define SP <<" "<<
#define CYES cout<<"Yes"<<endl
#define CNO cout<<"No"<<endl
#define CFS cin.tie(0);ios::sync_with_stdio(false)
#define CST(x) cout<<fixed<<setprecision(x)

using ll = long long;
using ld = long double;
using vi = vector<int>;
using mti = vector<vector<int>>;
using vl = vector<ll>;
using mtl = vector<vector<ll>>;
using pi = pair<int, int>;
using pl = pair<ll, ll>;
template<typename T>
using heap = priority_queue<T, vector<T>, function<bool(const T, const T)>>;

int main(){
    //CFS;
    int n, r;
    cin >> n >> r;
    cout << r + 100 * max(0, 10 - n) << endl;
    return 0;
}

Measured memory_bytes: 256
import copy
H,W,K = [int(i) for i in input().split()]
Chocolate = [[int(i) for i in list(input())]for j in range(H)]
YokoChoko = [[Choc[s] for Choc in Chocolate] for s in range(W)]
minlist = []
for warikata in range(2**(H-1)):#bit全探索
    #[0,1,1,1,2,2,3,3,3,3]みたいなlistを作りたい
    #1start,0なら増やさず1なら増やす
    wareta = [0]
    curw = 0
    for k in range(H-1):
        if (warikata>>k) & 1:
            curw += 1
        wareta.append(curw)
    #curw回割れてcurw + 1ピースに
    nums = [0 for xx in range(curw + 1)]
    watta = curw
    for nbanme,NewChoco in enumerate(YokoChoko):
        newnums = copy.deepcopy(nums)
        for n,choconum in enumerate(NewChoco):
            newnums[wareta[n]] += choconum
        if max(newnums) <= K:#わらんでいい
            nums = newnums
        else:#割る
            if nbanme == 0:
                watta += 9999999999
            watta += 1
            nums = [0 for iii in range(curw + 1)]
            for n,choconum in enumerate(NewChoco):
                nums[wareta[n]] += choconum
    minlist.append(watta)
print(min(minlist))

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

using namespace std;

#define lli long long int
#define REP(i,s,n) for(lli i=s;i<n;i++)
#define RREP(i,s,n) for(lli i=s;i>=n;i--)
#define MOD 1000000007
#define NUM 2520
#define DEBUG 0
#define mp(a,b) make_pair(a,b)
#define SORT(V) sort(V.begin(),V.end())
#define PI (3.141592653589794)
#define INF (1LL<<50)

signed main(){

	lli x,y;
	cin>>x>>y;

	lli cnt=0;
	lli now=x;
	while(now<=y){
		cnt++;
		now*=2;
	}
	cout<<cnt<<endl;
	
}


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

int main() {
    int ans = 0;
    int A, B;
    cin >> A >> B;
    ans = (A + B) / 2;
    if(abs(A - ans) == abs(B - ans))
        cout << ans << endl;
    else
        cout << "IMPOSSIBLE" << endl;
}

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

void Out(int t){

  cout <<  t/60/60 << " ";
  t = t%3600;
  cout << t/60 << " ";
  t = t%60;
  cout << t << endl;

}

int main(){

  int h1,h2,m1,m2,s1,s2;

  for(int i=0; i<3; i++){
      cin >> h1 >> m1 >> s1 >> h2 >> m2 >> s2;
      Out(h2*3600 + m2*60 + s2 - h1*3600 - m1*60 - s1);
  }


  return 0;
}

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

#define mp make_pair
#define pb push_back
#define mt make_tuple
#define eb emplace_back

int mod = 1e9 + 7;
vector<int> fib(112345, -1);
vector<int> brk(112345, 0);

int fibf(int n)
{
    if(brk[n]) return 0;
    if(fib[n] > -1) return fib[n];
    fib[n] = (fibf(n - 1) + fibf(n - 2)) % mod;
    return fib[n];
}

int main()
{
    fib[0] = 1;
    fib[1] = 1;

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

    int prev = 0, current;
    for(int i = 0; i < m; i++)
    {
        cin >> current;
        if(prev == current - 1 && prev)
        {
            cout << 0 << endl;
            return 0;
        }
        else
        {
            brk[current] = 1;
            prev = current;
        }
    }
    cout << fibf(n) << endl;

    return 0;
}

Measured memory_bytes: 5760
#include<stdio.h>
#include<math.h>

int isprime(int);

int main(){
  int n,i,t[10000],b=0;

  scanf("%d",&n);

  for(i = 0; i < n; i++){
    scanf("%d",&t[i]);
  }

  for(i = 0; i < n; i++){
    if(isprime(t[i]) == 1) b++;
  }
  
  printf("%d\n",b);
  
  return 0;
}

int isprime(int x){
  int i = 3;
  
  if(x == 2) return 1;

  if(x < 2 || (x % 2) == 0) return 0;

  while(i <= sqrt(x)){
    if(x % i == 0) return 0;
    i += 2;
  }

  return 1;
}



Measured memory_bytes: 2048
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
typedef pair<int,P> P1;
typedef pair<P,P> P2;
#define pu push
#define pb push_back
#define mp make_pair
#define eps 1e-7
#define INF 1000000000
#define mod 1000000007
#define fi first
#define sc second
#define rep(i,x) for(int i=0;i<x;i++)
#define SORT(x) sort(x.begin(),x.end())
#define ERASE(x) x.erase(unique(x.begin(),x.end()),x.end())
#define POSL(x,v) (lower_bound(x.begin(),x.end(),v)-x.begin())
#define POSU(x,v) (upper_bound(x.begin(),x.end(),v)-x.begin())
string s;
vector<int>pos[26]; int nxt[26];
int dp[200005];
int main(){
	cin >> s;
	rep(i,s.size()){
		pos[s[i]-'a'].pb(i);
	}
	for(int i=0;i<26;i++) nxt[i] = INF;dp[s.size()] = 1;
	for(int i=s.size()-1;i>=0;i--){
		nxt[s[i]-'a'] = i;
		bool ok = 0; int N = 0;
		for(int j=0;j<26;j++){
			if(nxt[j] == INF) ok = 1;
			else N = max(N,nxt[j]);
		}
		if(ok){
			dp[i] = 1;
		}
		else{
			dp[i] = dp[N+1]+1;
		}
	}
	string ans = "";
	int cur = 0;
	while(ans.size() < dp[0]){
		for(int j=0;j<26;j++){
			int k = lower_bound(pos[j].begin(),pos[j].end(),cur)-pos[j].begin();
			if(k==pos[j].size()){
				ans.pb('a'+j); break;
			}
			else if(dp[cur] == dp[pos[j][k]+1]+1){
				ans.pb('a'+j); cur = pos[j][k]+1; break;
			}
		}
	}
	cout << ans << endl;
}

Measured memory_bytes: 2180
#define rep(i,n) for(ll i=0, i##_len=(n); i<i##_len; ++i)
#define rrep(i,n) for(ll i##_len=(n) ,i=i##_len-1;i>=0;--i)
#define repi(i,a,b) for(ll i=ll(a);i<ll(b);++i)
#define printd(val) std::cout<< #val" = " <<val<<"\n";
#include<bits/stdc++.h>
using ll = int;
using pii = std::pair<int,int>;
using namespace std;
template<class T>T chmin(T a,T b){if(a>b){a^=b;b^=a;a^=b;return 1;}return 0;}
template<class T>T chmax(T b,T a){if(a<b){a^=b;b^=a;a^=b;return 1;}return 0;}
int n;
void input(){
    cin>>n;
}
void src(){
    if(n<100){
        if(n>=9){
            cout<<9;
        }else{
            cout<<n;
        }
    }else if(n<10000){
        if(n>=999){
            cout<<909;
        }else{
            cout<<9+n-99;
        }
    }else if(n<1000000){
        if(n>=99999){
            cout<<90909;
        }else{
            cout<<909+n-9999;
        }
    }
    return;
}

int main(int argc,char* argv[]){
    ios::sync_with_stdio(false);
 //   ifstream in( argv[1] ); cin.rdbuf(in.rdbuf());
    input();
    src();    
    return 0;
}

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

#define REP(i,n) for(int i=0;i<(n);i++)
#define ALL(v) (v).begin(),(v).end()
#define int long long
typedef pair<int,int> P;

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

signed main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    
    int n; cin>>n;
    int i=0;
    while(pow(3,i)<n) i++;
    cout<<i<<endl;
}


Measured memory_bytes: 3368
#include<cstdio>
int main()
{
	long long n,i,a;
	a=0;
	scanf("%lld",&n);
	for(i=1;i<=n;i++){
		if(i%3!=0||i%5!=0){
			if(i%3!=0&&i%5!=0) a+=i;
		}
	}
	printf("%lld\n",a);
	return 0;
}


Measured memory_bytes: 1668
let input = require('fs').readFileSync('/dev/stdin', 'utf-8');
let numsArr = (input.trim()).split('\n').map(str => str.split("").map(n => Number(n)));

function newArr(arr) {
    let newArr = [];
    for (let i = 0; i < arr.length -1; i++) {
        newArr.push(arr[i] + arr[i+1]);
    }
    return newArr.map(n => n % 10);
}

function singleDown (arr) {
    if (arr.length === 1) {
        return arr[0];
    } else {
        return singleDown(newArr(arr));
    }
}

let awrs = numsArr.map(nums => singleDown(nums));
awrs.forEach(n => console.log(n));


Measured memory_bytes: 16092
#include <iostream>
#include <vector>
#include <map>
#include <utility>
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <stack>
#include <queue>
#include <set>
#include <unordered_map>
#include <unordered_set>

#define REP(i,a,n) for(int i=a;i<n;++i)
#define rep(i,n) REP(i,0,n)
#define REV(i,a,n) for(int i=n;i>=a;--i)
#define all(e) e.begin(),e.end()
#define rall(e) e.rbegin(),e.rend()
#define pb push_back
#define mp make_pair
#define fs first
#define sc second
#define show(n) cerr<<#n<<" = "<<n<<endl
#define shows(n) for(auto z:n){cerr<<z<<", ";}cerr<<endl

//ここからAtCoder向けdefine
#define yes cout << "YES" << endl
#define no cout << "NO" << endl

using namespace std;

using ll = long long;
using ull = unsigned long long;
using vi = vector<int>;
using pint = pair<int,int>;

const int INF = (1 << 30);

vi grid[51];

vi dis[51];

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

int bfs(int h, int w){
    pint s = mp(0, 0);
    pint g = mp(h - 1, w - 1);
    queue<pint> queue;
    rep(i, h){rep(j, w){dis[i].pb(INF);}}

    queue.push(s);
    dis[s.fs][s.sc] = 0;

    while(queue.size()){
        pint p = queue.front(); queue.pop();
        if(p.fs == g.fs && p.sc == g.sc){ break; }

        rep(i, 4){
            pint next = mp(p.fs + dx[i], p.sc + dy[i]);

            if(0 <= next.fs && next.fs < h && 0 <= next.sc && next.sc < w && grid[next.fs][next.sc] != 1 && dis[next.fs][next.sc] == INF){
                queue.push(next);
                dis[next.fs][next.sc] = dis[p.fs][p.sc] + 1;
            }
        }
    }
    return dis[g.fs][g.sc];
}

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int h, w;
    cin >> h >> w;
    char c;
    int masu = 0;
    rep(i, h){
        rep(j, w){
            cin >> c;
            if(c == '.'){grid[i].pb(0);masu++;}
            else{grid[i].pb(1);}
        }
    }
    int n = bfs(h, w);
    if(n == INF){ cout << -1 << endl; }
    else{ cout << masu - n - 1 << endl; }

    return 0;
}

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

using namespace std;

int main()
{
    string s, t;
    cin >> s >> t;
    vector<vector<int>> u(26), v(26);

    for (int i = 0; i < s.size(); i++)
    {
        char x = s[i] - 'a', y = t[i] - 'a';
        auto itx = find(u[x].begin(), u[x].end(), y);
        auto ity = find(v[y].begin(), v[y].end(), x);
        if (itx == u[x].end())
            u[x].push_back(y);
        if (ity == v[y].end())
            v[y].push_back(x);
        if (u[x].size() > 1 || v[y].size() > 1)
        {
            puts("No");
            exit(0);
        }
    }

    puts("Yes");
    return 0;
}


Measured memory_bytes: 776
#include<stdio.h>

int main()
{
    long long int a,b;
    long long int temp,gcd,lcm,a1,b1;

    while(scanf("%lld%lld",&a,&b)!=EOF)
    {
        a1=a;
        b1=b;
        while(a%b!=0)
        {
           temp=a%b;
           a=b;
           b=temp;
        }
        gcd=b;
        lcm=a1*(b1/gcd);
        printf("%lld ",gcd);
        printf("%lld\n",lcm);
    }
    return 0;
}



Measured memory_bytes: 1968