akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;

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

  int t0=0,x0=0,y0=0,t1,x1,y1;
  bool ans=true;

  for(int i=0;i<n;++i){
    cin>>t1>>x1>>y1;
    if(abs(x1-x0)+abs(y1-y0)<=t1-t0 && (t1-t0-abs(x1-x0)-abs(y1-y0))%2==0)
        continue;
    else ans=false;
  }

  cout << (ans?"Yes":"No") << endl;
  return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<vector>
#define rep(i, start, end) for (int i = (int)start; i < (int)end; ++i)
#define rrep(i, start, end) for (int i = (int)start - 1; i >= end; --i)
#define arep(i, c) for (auto i = (c).begin(); i != (c).end(); ++i)
#define all(x) (x).begin(), (x).end()
using namespace std;
typedef pair<int, int> P;

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    int N;
    cin >> N;
    vector<P> A(N);
    rep(i, 0, N) {
        cin >> A[i].first;
        A[i].second = i + 1;
    }
    sort(all(A));
    rep(i, 0, N) cout << A[i].second << ' ';
    cout << endl;
    return 0;
}

Measured memory_bytes: 1664
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define rep(i,n) for(int i=0;i<n;i++)
#define rep1(i,n) for(int i=1;i<=n;i++)
#define rep2(i,n) for(int i=0;i<=n;i++)
#define repr(i,a,n) for(int i=a;i<n;i++)
#define all(a) a.begin(),a.end()
#define P pair<long long,long long>
#define double long double
#define INF 1e10
#define MOD 1e9+7
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
using Graph = vector<vector<int>>;
signed main(){
  double a,b;
  cin>>a>>b;
  int c=b*2+1;
  cout<<ceil(a/c)<<endl;
}

Measured memory_bytes: 256
#pragma once
#include <sstream>
#include <string>
#include <vector>
#include <map>
#include <algorithm>
#include <iostream>
#include <utility>
#include <set>
#include <cctype>
#include <queue>
#include <stack>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <deque>
#include <numeric>
#include <iomanip>
#define M_PI acos(-1)
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
const int INF = 1000000007;
const int MAX_V = 201;
int now = 0;

const int MAX = 200000;
const int MOD = 1000000007;

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

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

// 二項係数計算
long long COM(int n, int k) {
	if (n < k) return 0;
	if (n < 0 || k < 0) return 0;
	return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}
struct edge {
	int t;
	ll cost;
	edge(int _t, ll _cost) : t(_t)
		, cost(_cost) {
	}
};
bool isPrime(int n) {

	if (n == 1) return false;
	for (ll i = 2; i * i <= n; i++)
	{
		if (n % i == 0) return false;
	}
	return true;
}
void Solve() {
	
	string s;
	cin >> s;
	int res = INF;
	for (char c = 'a'; c <= 'z'; c++)
	{
		string st = s;
		int defc = 0;
		
		for (int p = 0; p < st.size(); p++)
		{
			if (st[p] == c) {
				defc++;
			}
		}
		if (defc == 0) continue;
		if (defc == s.size()) {
			res = 0;
			break;
		}
		
		int turn = 1;
		
		while (true)
		{
			int count = 0;
			for (size_t i = 0; i < st.size() - turn; i++)
			{
				if (st[i + 1] == c) {
					st[i] = c;
				}
				count += st[i] == c;
			}
			if (count + turn >= s.size()) break;
			turn++;
		}
		res = min(turn, res);
	}
	
	cout << res << endl;
}
int main() {
	Solve();
	return 0;
}



Measured memory_bytes: 256
#include <iostream>
using namespace std;
#define rep(i,n) for (int i = 0; i < (n); ++i)

int A[1000000], n;

int binarySearch(int key)
{
    int left = 0;
    int right = n;
    while( right > left ){
        int mid = (right + left) / 2;
        if (A[mid] == key) return 1;
        if (A[mid] < key) left = mid + 1;
        else right = mid; 
    }
    return 0;
}

int main()
{
    int q, key, sum = 0;

    scanf("%d", &n);
    rep(i, n) scanf("%d", &A[i]);

    scanf("%d", &q);
    rep(i, q){
        scanf("%d", &key);
        if (binarySearch(key)) ++sum;
    }
    printf("%d\n", sum);

    return 0;
}


Measured memory_bytes: 3580
/**
 *   @FileName	d.cpp
 *   @Author	kanpurin
 *   @Created	2020.06.01 00:33:05
**/

#include "bits/stdc++.h" 
using namespace std; 
typedef long long ll;

// 素因数分解 O(√n)以下
// (素因数,個数)
template<typename T>
vector<pair<T,int>> prime_factorization(T n) {
    vector<pair<T, int>> res;
    for (T i = 2; i*i <= n; i++) {
        int cnt = 0;
        while (n % i == 0) {
            n /= i;
            cnt++;
        }
        if (cnt > 0) res.push_back({i,cnt});
    }
    if (n > 1) res.push_back({n,1});
    return res;
}
int main() {
    ll n;cin >> n;
    auto v = prime_factorization(n);
    int ans = 0;
    for(auto p : v) {
        int t = 1;
        while(t <= p.second) {
            p.second -= t;
            ans++;
            t++;
        }
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 3596
#include<bits/stdc++.h>
using namespace std;
int main() {
    int A, B, M;
    cin >> A >> B >> M;
    vector<int> a(A);
    vector<int> b(B);
    for (int i = 0; i < A; i++)cin >> a[i];
    for (int i = 0; i < B; i++)cin >> b[i];
    int minA = *min_element(a.begin(), a.end());
    int minB = *min_element(b.begin(), b.end());
    int ans = minA+minB;
    for (int i = 0; i < M; i++) {
        int x, y, c;
        cin >> x >> y >> c; x--; y--;
        ans = min(ans, a[x] + b[y] - c);
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 4044
#include <cstdio>
#include <limits>

using namespace std;

namespace {

static int Merge(int* A, int left, int mid, int right) {
  const int n1 = mid - left;
  const int n2 = right - mid;

  // When sorting large arrays, allocating L and R in heap for
  // each Merge call makes a bit the program slower.
  //
  // In the real application, we should use std::vectors instead of
  // fixed sized arrays, though.
  // vector<int> L(n1+1);
  // vector<int> R(n2+1);
  int L[n1 + 1];
  int R[n2 + 1];

  for (int i = 0; i < n1; ++i) {
    L[i] = A[left + i];
  }
  for (int i = 0; i < n2; ++i) {
    R[i] = A[mid + i];
  }

  static const int kInf = numeric_limits<int>::max();
  L[n1] = kInf;
  R[n2] = kInf;

  int i = 0;
  int j = 0;
  for (int k = left; k < right; ++k) {
    if (L[i] <= R[j]) {
      A[k] = L[i];
      i++;
    } else {
      A[k] = R[j];
      j++;
    }
  }
  return right - left;
}

static int MergeSortInternal(int* A, int left, int right) {
  if (left + 1 >= right) return 0;

  const int mid = (left + right) / 2;
  int ret = MergeSortInternal(A, left, mid);
  ret += MergeSortInternal(A, mid, right);
  return ret + Merge(A, left, mid, right);
}

static int MergeSort(int* A, int n) {
  return MergeSortInternal(A, 0, n);
}
} // namespace

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

  const int swapped = MergeSort(S, n);
  for (int i = 0; i < n; ++i) {
    if (i > 0) printf(" ");
    printf("%d", S[i]);
  }
  printf("\n");
  printf("%d\n", swapped);

  return 0;
}

Measured memory_bytes: 4936
#include <algorithm>
#include <climits>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <iomanip>
#include <iostream>
#include <string>
#include <vector>

typedef long long ll;
using namespace std;

int main() {
    int n = 0;
    cin >> n;
    ll x = 0;
    cin >> x;
    vector<ll> a(n);
    for (int i=0; i<n; i++) {
        cin >> a.at(i);
    } 
    sort(a.begin(), a.end());
    int now = 0;
    int ans = 0;
    while (x > 0 && now < n) {
        if (a.at(now) <= x) {
            ans++;
            x -= a.at(now);
        }
        else break;
        now++;
    }
    if (x > 0 && now == n) ans--;
    cout << ans << endl;
    return 0;
}


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

using namespace std;
typedef long long ll;




int main()
{
    
    
    int N;
    cin >> N;
    vector<int> d(N);
    rep(i,N) cin >> d[i];
    int ans = 0;
    rep(i,N){
        for (int j = i+1; j < N; j++) {
            ans += d[i]*d[j];
        }
    }
    cout << ans << endl;
    return 0;
}



Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <iomanip>
#include <stdlib.h>
#include <string.h>
#include <cstring>
#include <cmath>
#include <map>
#include <queue>
#include <deque>
#include <stack>
#include <set>
#include <stdio.h>
#include <tuple>
#include <bitset>
#include <cfloat>
#include <fstream>
#include <limits.h>
#include <list>
#include <math.h>
#include <random>
#include <unordered_map>
#include <unordered_set>
#include <bitset>
#include <numeric>
#include <utility>
#include <sstream>

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;
}

using namespace std;
#define int long long
#define ll long long
#define rep(i, n) for (ll i = 0; i < (n); i++)
#define FOR(i,a,b) for(ll i=(a);i<(b);i++)
#define FORR(i,a,b)for(ll i=(a);i<=(b);i++)
#define repr(i,n) for(ll i=n;i>=0;i--)
#define P pair<ll, ll>
#define sz(x) (ll)x.size()
#define ALL(x) (x).begin(),(x).end()
#define ALLR(x) (x).rbegin(),(x).rend()
#define VE vector<ll>
#define COUT(x) cout<<(x)<<endl
#define MA map<ll,ll>
#define SE set<ll>
#define PQ priority_queue<ll>
#define PQR priority_queue<ll,VE,greater<ll>>
#define COUT(x) cout<<(x)<<endl
#define YES(n) cout << ((n) ? "YES" : "NO"  ) << endl
#define Yes(n) cout << ((n) ? "Yes" : "No"  ) << endl
#define EPS (1e-10)
ll gcd(ll a, ll b) {
	if (a < b)swap(a, b);
	if (b == 0) return a;
	return gcd(b, a % b);
}
ll lcm(ll a, ll b) {
	ll g = gcd(a, b);
	return a / g * b;
}
bool prime(ll n) {
	for (ll i = 2; i <= sqrt(n); i++) {
		if (n%i == 0)return false;
	}
	return n != 1;
}


const long long MOD = 1000000007;
const long long INF = 1LL << 60;


const int MAX_N = 100010;

signed main() {
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	string s; cin >> s;
	int ans = 0;
	rep(i, s.size()) {
		if (i % 2 == 0) {
			if (s[i] != '1')ans++;
		}
		else {
			if (s[i] != '0')ans++;
		}
	}
	int ans2 = 0;
	rep(i, s.size()) {
		if (i % 2 == 1) {
			if (s[i] != '1')ans2++;
		}
		else {
			if (s[i] != '0')ans2++;
		}
	}
	cout << min(ans, ans2) << endl;
	return 0;
}


Measured memory_bytes: 512
#include<bits/stdc++.h>
using namespace std;
#define ALL(x) (x).begin(),(x).end()
#define uniq(x) (x).erase(unique(ALL(x)),(x).end())
#define SORT(x) sort(ALL(x))
#define REV(x) reverse(ALL(x))
#define foreach(it,x) for(__typeof((x).begin()) it=(x).begin();it!=(x).end();it++)
#define debug(x) cerr<<#x<<"="<<(x)<<endl
#define gett() cerr<<"Time:"<<clock()<<"ms."<<endl
long long MOD=1000000007;
string s;
string abc="ABC";
long long dp[100100][4];
int main(){
	//freopen("input.txt","r",stdin);
	//freopen("output.txt","w",stdout);
	ios::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
	cin>>s;
	long long type=1LL;
	for(int i=s.size();i>=0;i--){
		for(int j=3;j>=0;j--){
			if(i==s.size()){
				dp[i][j]=(j==3?1LL:0LL);
			}
			else{
				dp[i][j]+=dp[i+1][j]*(s[i]=='?'?3LL:1LL);
				if(j<3&&(s[i]==abc[j]||s[i]=='?'))
					dp[i][j]+=dp[i+1][j+1];
				dp[i][j]%=MOD;
			}
		}
	}
	cout<<dp[0][0]<<endl;
	return 0;
}


Measured memory_bytes: 3664
#include <iostream> 
#include<vector>
#include<algorithm>
#include<map>
#include<iomanip>
#include<set>
#include<queue>
#include<deque>
#include<iomanip>
#include<sstream>
#include<cmath>
#include<bitset>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define req(i,n) for(int i = 1;i <=  n; i++)
#define rrep(i,n) for(ll i = n-1;i >= 0;i--)
#define ALL(obj) begin(obj), end(obj)
#define RALL(a) rbegin(a),rend(a)
typedef long long int ll;
typedef long double ld;
const ll INF = 1e15;
template<typename A, size_t N, typename T>
void Fill(A(&array)[N], const T & val) {
    std::fill((T*)array, (T*)(array + N), val);
}
const int MAX = 510000;
const int MOD = 1000000007;
int gcd(int a, int b) {
    return b ? gcd(b, a % b) : a;
}
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
int main(void) {
    ll n, m, a; cin >> n >> m;
    vector<int> v;
    rep(i, n) {
        cin >> a; a /= 2;
        v.push_back(a);
    }while (v[0] % 2 == 0) {
        rep(i, n) {
            if (v[i] % 2 != 0) {
                cout << 0 << endl;
                return 0;
            }v[i] /= 2;
        }m /= 2;
    }rep(i, n) {
        if (v[i] % 2 == 0) {
            cout << 0 << endl;
            return 0;
        }
    }ll lcm = 1;
    rep(i, n) {
        lcm = lcm / gcd(lcm, v[i]) * v[i];
        if (lcm > m) {
            cout << 0 << endl;
            return 0;
        }
    }cout << (m / lcm + 1) / 2<<endl;
}

Measured memory_bytes: 3928
#include <iostream>
#include <vector>
#include <string>

int main() {
    int n, q;
    std::cin >> n >> q;
    std::string s;
    std::cin >> s;
    std::vector<int> acs(n+1);
    int cur = 0;
    for (int i = 0; i < n+1; i++) {
        if (i+1 < n && s[i] == 'A' && s[i+1] == 'C') {
            acs[i] = acs[i+1] = cur;
            cur++;
            i++;
        } else {
            acs[i] = cur;
        }
    }
    for (int i = 0; i < q; i++) {
        int l, r;
        std::cin >> l >> r;
        std::cout << acs[r] - acs[l] << std::endl;
    }
}

Measured memory_bytes: 1472
import java.util.*;

public class Main {
    public static void main(String[] args) throws Exception {
        Scanner sc = new Scanner(System.in);
        int p = 2019;
        char[] s = sc.next().toCharArray();
        int n = s.length;
        long ans = 0;
        int[] cum = new int[n+1];
        int pow = 1;
        for(int i = n-1; i >= 0; i--){
            int tmp = ((s[i] - '0') * pow) % p;
            cum[i] = (cum[i+1]+tmp) % p;
            pow *= 10;
            pow %= p;
        }
        int[] counter = new int[p];
        for(int i = n; i >= 0; i--){
            ans += counter[cum[i]];
            counter[cum[i]]++;
        }
        System.out.println(ans);
    }
}


Measured memory_bytes: 32372
#include <algorithm>
#include <iomanip>
#include <iostream>
#include <queue>
#include <set>
#include <string>
#include <vector>
#define SORT(a) sort((a).begin(), (a).end())
#define RSORT(a) sort((a).rbegin(), (a).rend())
#define REP(i, n) for (int i = 0; i < n; i++)
#define RREP(i, n) for (int i = n; 0 <= i; i--)
#define FOR(i, start, end) for (int i = start; i < end; i++)
#define FORSTEP(i, start, end, step) for (int i = start; i < end; i += step)
#define ALL(a) a.begin(), a.end()
typedef long long ll;
const int INF32 = 2147483647;
const ll INF64  = 9223372036854775807;
using namespace std;

int N;
int ans = 0;

void ck(int x) {
    bool f3 = false, f5 = false, f7 = false;
    while (x != 0) {
        if (x > N)
            break;

        int a = x % 10;
        if (a == 3)
            f3 = true;
        if (a == 5)
            f5 = true;
        if (a == 7)
            f7 = true;
        x /= 10;
    }

    if (f3 && f5 && f7)
        ans++;
}

void dfs(int x) {
    ck(x);
    if (x <= 1E8) {
        dfs(10 * x + 3);
        dfs(10 * x + 5);
        dfs(10 * x + 7);
    }
}

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

    cin >> N;
    dfs(0);

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <vector>
#include <deque>
#include <queue>
#include <set>
#include <map>
#include <limits>
#include <cmath>
#include <iomanip>
#include <functional>
#include <random>
#include <boost/multiprecision/cpp_int.hpp>

using namespace std;
using ll = long long;

int main()
{
    // 整数の入力
    string S;
    cin >> S;
    if (S[2] == S[3] && S[4] == S[5]){
        cout << "Yes" << endl;
    }else{
        cout << "No" << endl;
    }
   return 0;
}

Measured memory_bytes: 256
using System;
using System.Linq;
using System.Collections.Generic;

namespace Algorithm
{
    class Program
    {
        static void Main(string[] args)
        {
            ReversePolishNotation();
        }

        /// <summary>
        /// 逆ボーランドの計算
        /// 1 2 + 3 4 - *とかを演算する
        /// </summary>
        static void ReversePolishNotation()
        {
            var s = Console.ReadLine().Split();
            var operators = new HashSet<string>() { "+", "-", "*" };
            var stack = new Stack<int>();

            foreach (var c in s)
            {
                // リストから引いたものが演算子の場合は2個popして演算した結果をPushする
                // それ以外は普通にリストの値をpushする
                if (operators.Contains(c))
                    stack.Push(Calc(c, stack.Pop(), stack.Pop()));
                else
                    stack.Push(int.Parse(c));
            }

            Console.WriteLine(stack.Pop());
        }

        /// <summary>
        /// popしたものをそのまま計算にに使うから
        /// AとBを逆にする(そうしないとマイナス演算の時にバグる)
        /// </summary>
        /// <param name="ope"></param>
        /// <param name="a"></param>
        /// <param name="b"></param>
        /// <returns></returns>
        static int Calc(string ope, int a, int b)
        {
            if (ope == "+")
                return b + a;
            else if (ope == "-")
                return b - a;
            else
                return b * a;
        }
    }
}



Measured memory_bytes: 18680
///Water Hyacinth
///Hakuna Matata
///WAKE THE FUCK UP SAMURAI;WE HAVE A CODE TO RUN <3
///Any Verdict
///(Aes)  Dekhe (Tic) lagche = Aesthetic <3
///**********************************************************///

#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define D double
int main()
{

	ll a,b;

	cin >> a >> b;

	if((a+b)%2==0)
        cout << (a+b)/2 << endl;
    else
        cout << "IMPOSSIBLE" << endl;

    return 0;
}

///Day:36




Measured memory_bytes: 256
#include<stdio.h>
int main(){
	int a,b,c;
	int cnt=0;
	scanf("%d%d%d",&a,&b,&c);
	for(int i=a;i<=b&&i<=c;i++){
		if(c%i==0)cnt++;
	}
	printf("%d\n",cnt);
}


Measured memory_bytes: 2104
import math,fractions
n = int(input())
a = [int(i) for i in input().split()]
l = [0] * n
r = [0] * n
m = [] 
for i in range(1,n):
    l[i] = fractions.gcd(l[i-1],a[i-1])
for i in range(n-1)[::-1]:
    r[i] = fractions.gcd(r[i+1],a[i+1])
for i in range(n):
    m.append(fractions.gcd(l[i],r[i]))
print(max(m))


Measured memory_bytes: 16148
#include <bits/stdc++.h>
    using namespace std;
    typedef long long int ll;
    #define LONGMAX 1e14
    #define dd double
    #define MOD 998244353  
    # define my_sizeof(type) ((char *)(&type+1)-(char*)(&type)) 
    #define nl cout<<endl
    #define fill(a,val) memset(a,val,sizeof(a))
    #define rt ll Q[100005]={0}
    #define mp make_pair
    #define endl "\n"
    #define test() ll t;cin>>t;while(t--)
    #define pb push_back
    #define ff first    
    #define ss second
    #define all(v) v.begin(),v.end()
    #define s(ar,n) sort(ar,ar+n)
    #define rs(ar,n) sort(ar, ar+n, greater<ll>()) 
    #define oa(a,n) for(ll i=0;i<n;i++)cout<<a[i]<<" ";nl
    #define cn(a,n) for(ll i=0;i<n;i++)cin>>a[i];
    #define ov(a,n) for(ll i=n-1;i>=0;i--)cout<<a[i]<<" ";nl
    #define maxa(ar,N) *max_element(ar,ar+N)
    #define mina(ar,N) *min_element(ar,ar+N)
    #define INF 1e15
    #define fastio() ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
    #define printclock cerr<<"Time : "<<1000*(long double)clock()/(long double)CLOCKS_PER_SEC<<"ms\n";
    ll power(ll x, ll y){ll res=1;while(y>0){if(y&1)res = (res*x);y = y>>1;x = (x*x);}return res;}  
    ll logtwo(ll n){if(n==1)return 0;return logtwo(n/2)+1;}
    void ceilsearch(ll ar[],ll low,ll high,ll x,ll &y){if(low>high)return;ll mid=(low+high)/2;if(ar[mid]>=x){y=mid;ceilsearch(ar,low,mid-1,x,y);}else{ceilsearch(ar,mid+1,high,x,y);}}
    signed main()   
    {
        fastio();   
        ll N,M;
        cin>>N>>M;
        ll ans=N*(N-1);
        ans/=2;
        ll a=M*(M-1);
        a/=2;
        cout<<a+ans<<endl;
    }   

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

using namespace std;


#define MAXN 1000000
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  int n, k[3] = {};
  cin >> n;
  for (int i = 0; i < n; ++i) {
    int a;
    cin >> a;
    if (a%4==0) k[2]++;
    else if (a%2==0) k[1]++;
    else k[0]++;
  }
  int cur = 2;
  for (int i = 0; i < n; ++i) {
    if (cur==2) {
      if (k[0]) cur = 0;
      else if (k[1]) cur = 1;
      else cur = 0;
    } else if (cur==1) {
      if (k[1]) cur = 1;
      else if (k[2]) cur = 2;
      else cur = -1;
    } else if (cur==0) {
      if (k[2]) cur = 2;
      else cur = -1;
    }
    if (cur==-1) {
      cout << "No" << endl;
      return 0;
    }
    k[cur]--;
  }
  cout << "Yes" << endl;
  return 0;
}


Measured memory_bytes: 256
from itertools import groupby


def main():
    n = int(input())
    xs = sorted(list(map(int, input().split())))

    if n == 1:
        if xs[0] == 0:
            print(1)
        else:
            print(0)
        return

    xxs = [list(it) for k, it in groupby(xs)]

    if len([xs for xs in xxs if len(xs) != 2 and xs[0] != 0]) > 0:
        print(0)
        return

    ans = 1
    for i in range(n//2):
        ans *= 2
        ans %= 1000000007
    print(ans)


main()


Measured memory_bytes: 60780
#include <iostream>
#include <climits>
using namespace std;
int main()
{
    int n,minim=INT_MAX;
    cin >> n;
    int a[n+1];
    bool ok=true;
    for (int i=1;i<=n;i++)
    {
        cin >> a[i];
    }
    for (int i=n;i>=1;i--)
    {
        minim=min(minim,a[i]);
        if (a[i]-minim>=2) ok=false;
    }
    if (ok) cout << "Yes";
    else cout << "No";
}

Measured memory_bytes: 640
#include"bits/stdc++.h"


#define PB push_back
#define PF push_front
#define LB lower_bound
#define UB upper_bound
#define fr(x) freopen(x,"r",stdin)
#define fw(x) freopen(x,"w",stdout)
#define iout(x) printf("%d\n",x)
#define lout(x) printf("%lld\n",x)
#define REP(x,l,u) for(ll x = (l);x<=(u);x++)
#define RREP(x,l,u) for(ll x = (l);x>=(u);x--)
#define mst(x,a) memset(x,a,sizeof(x))
#define PII pair<int,int>
#define PLL pair<ll,ll>
#define MP make_pair
#define se second
#define fi first
#define dbg(x) cout<<#x<<" = "<<(x)<<endl;
#define sz(x) ((int)x.size())
#define cl(x) x.clear()

typedef  long long ll;
typedef unsigned long long ull;
typedef double db;
typedef long double ld;
using namespace std;

const int maxn = 200010;
const int mod = 1e9+7;
const double eps = 1e-6;
const double PI = acos(-1);

template<typename T> inline void read(T &x){
x=0;T f=1;char ch;do{ch=getchar();if(ch=='-')f=-1;}while(ch<'0'||ch>'9');do x=x*10+ch-'0',ch=getchar();while(ch<='9'&&ch>='0');x*=f;
}

template<typename A,typename B> inline void read(A&x,B&y){read(x);read(y);}
template<typename A,typename B,typename C> inline void read(A&x,B&y,C&z){read(x);read(y);read(z);}
template<typename A,typename B,typename C,typename D> inline void read(A&x,B&y,C&z,D&w){read(x);read(y);read(z);read(w);}
template<typename A,typename B> inline A fexp(A x,B p){A ans=1;for(;p;p>>=1,x=1LL*x*x%mod)if(p&1)ans=1LL*ans*x%mod;return ans;}
template<typename A,typename B> inline A fexp(A x,B p,A mo){A ans=1;for(;p;p>>=1,x=1LL*x*x%mo)if(p&1)ans=1LL*ans*x%mo;return ans;}

int n;

char st[maxn];

vector<int> G[maxn];

int f[maxn],g[maxn],low[maxn],high[maxn];

void dfs1(int u,int fa){
	low[u]=st[u]=='1'?0:n;
	for(auto v:G[u])if(v!=fa){
		dfs1(v,u);
		f[u]=max(f[u],f[v]+1);
		low[u]=min(low[u],max(low[v],f[v])+1);//move down and touch the bottom
	}
}

void dfs2(int u,int fa){
	int mx=g[u],se=0;
	for(auto v:G[u])if(v!=fa){
		se=max(se,f[v]+1);
		if(se>mx)swap(mx,se);
	}
	high[u]=min(se+1,max(f[u],g[u])-1);
	for(auto v:G[u])if(v!=fa){
		if(f[v]==mx-1)g[v]=se+1,low[v]=min(low[v],max(low[u],se)+1);
		else g[v]=mx+1,low[v]=min(low[v],max(low[u],mx)+1);
		dfs2(v,u);
	}
}

void Work(){
	dfs1(1,0);
	dfs2(1,0);
	ll ans=0;
	REP(i,1,n)ans+=max(0,high[i]-low[i]+1);
	cout<<ans+1<<endl;
}

void Init(){
	read(n);
	REP(i,2,n){
		int u,v;read(u,v);
		G[u].PB(v);G[v].PB(u);
	}
	scanf("%s",st+1);
}

int main(){
	Init();
	Work();
	return 0;
}


Measured memory_bytes: 26368
import heapq
n,m = list(map(int,input().split()))
a = list(map(lambda s: (-1)*int(s),input().split()))

heapq.heapify(a)
#print(a)
for i in range(m):
  x = heapq.heappop(a)
  #print(x)
  x = -1 * (-x // 2)
  heapq.heappush(a,x)

#print(a)
print(-1 * sum(a))

Measured memory_bytes: 72216
#include <iostream>
#include <cstdlib>
#include <queue>
#include <algorithm>

using namespace std;

int main(){
    queue<pair<string, int>> q;
    int n, quantum;
    cin >> n >> quantum;
    for(int i = 0; i < n; i++){
        string tmp; int tmp2;
        cin >> tmp >> tmp2;
        q.push(make_pair(tmp, tmp2));
    }
    
    pair<string, int> process;
    int time = 0;
    
    while(!q.empty()){
        process = q.front(); q.pop();
        int cost = min(quantum, process.second);
        process.second -= cost;
        time += cost;
        if(process.second > 0) q.push(process);
        else cout << process.first << " " << time << endl;
    }

    return 0;
}


Measured memory_bytes: 6340
#include <stdio.h>

#define N 100001
struct sas{
  int num;
  char character;
  int key;
};

struct sas array[N]; 

int DefPar(int,int); 
void DefQuick(int,int);

int main(){
  char cha1,cha2,cha3;
  int n;
  int i,numa;
int numb = 0;
  scanf("%d%c",&n,&cha1);
  for(i = 0;i < n;i++){

    scanf("%c%c%d%c",&array[i].character,&cha2,&array[i].num,&cha3);

    array[i].key = i;
  }
  numa = DefPar(0,n - 1);

  DefQuick(0,n - 1);

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

    if(array[i].key > array[i+1].key && array[i].num == array[i+1].num){

     numb = 1;

      break;
    }
  }
  if(numb == 0) printf("Stable\n");

  if(numb == 1) printf("Not stable\n");

  for(i = 0;i < n;i++){
    printf("%c %d\n",array[i].character,array[i].num);
  }
  return 0;
}
 
int DefPar(int a,int b){
  int i,j;
  struct sas numx,tmp;
  numx.num = array[b].num;
  i = a - 1;
  for(j = a;j < b;j++){
    if(array[j].num <= numx.num){
      i = i + 1;
      tmp = array[i];
      array[i] = array[j];
      array[j] = tmp;
    }
  }
  tmp = array[i+1];

  array[i + 1] = array[b];

  array[b] = tmp;

  return i + 1;
}
 
void DefQuick(int a,int b){
  int numq;
  if(a < b){
    numq = DefPar(a,b);
    DefQuick(a,numq - 1);
    DefQuick(numq + 1,b);
  }
}

Measured memory_bytes: 1776
///created: 13/Jun/2019 14:54:41

#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef pair<int, int> ii;
#define db(x) cerr << "debug: " << #x << " = " << x << '\n';
template<class __Ty> bool minimize(__Ty& a, __Ty b) {
	if (a > b) { a = b; return true; }
	return false;
}
template<class __Ty> bool maximize(__Ty& a, __Ty b) {
	if (a < b) { a = b; return true; }
	return false;
}

int main() {
	ios::sync_with_stdio(0); cin.tie(0);
	ll n, m, ans = 1;
	cin >> n >> m;
	for (ll i = 1; i * i <= m; ++i)
		if (m % i == 0) {
			if (m / i >= n)
				ans = max(ans, i);
			if (i >= n)
				ans = max(ans, m / i);
		}
	cout << ans;
	return 0;
}


Measured memory_bytes: 256
from sys import stdin
import math
from operator import itemgetter, attrgetter
from bisect import bisect_left, bisect_right
n = int(stdin.readline())
lx = []
ly = []
li = []
for i in range(n):
    x, y = map(int, stdin.readline().split())
    lx.append(x)
    ly.append(y)
    li.append(i)
x_width = max(lx) - min(lx)
y_width = max(ly) - min(ly)
if x_width > y_width:
    P = list(zip(lx, ly, li))
else:
    P = list(zip(ly, lx, li))
P.sort()
interval = int(math.sqrt(n))
low = [v1 for v1, v2, i in P[::interval]]
high = [v1 for v1, v2, i in P[interval - 1::interval]] + [float('inf')]
S = []
v2_sec_list = []
for i in range(0, n, interval):
    si = P[i:i + interval]
    si.sort(key=itemgetter(1))
    v2_s = [p[1] for p in si]
    v2_sec_list.append(v2_s)
    S.append(si)
A = []
q = int(stdin.readline())
for _ in range(q):
    sx, tx, sy, ty = map(int, stdin.readline().split())
    if x_width <= y_width:
        sx, sy, tx, ty = sy, sx, ty, tx
    a = []
    for i in range(bisect_left(high, sx), bisect_right(low, tx)):
        v = S[i]
        k = v2_sec_list[i]
        for j in range(bisect_left(k, sy), bisect_right(k, ty)):
            if sx <= v[j][0] <= tx:
                a.append(v[j][2])
    if a:
        a.sort()
        A.extend(a)
    A.append('')
print('\n'.join(map(str, A)))

Measured memory_bytes: 158816
#include <algorithm>
#include <boost/optional.hpp>
#include <climits>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <functional>
#include <iostream>
#include <limits>
#include <list>
#include <numeric>
#include <queue>
#include <sstream>
#include <string>
#include <tuple>
#include <type_traits>
#include <utility>
#include <vector>

#define REP(i, n) for(int i = 0, i##_MACRO = (n); i < i##_MACRO; i++)
#define RANGE(i, a, b) for(int i = (a), i##_MACRO = (b); i < i##_MACRO; i++)
#define EACH(e, a) for(auto&& e : a)
#define ALL(a) (a).begin(), (a).end()
#define AALL(a, n) (a), ((a) + (n))
#define FILL(a, n) memset((a), n, sizeof(a))
#define FILLZ(a) FILL(a, 0)
#define MODNUM (static_cast<int>(1e9 + 7))
#define MOD(x) ((x) % MODNUM)

using namespace std;

using ll = long long;
using VI = vector<int>;
using VI2D = vector<vector<int>>;

const int INF = 2e9;
const double EPS = 1e-10;
const double PI = acos(-1.0);

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

inline int toInt(string s) {
	int v;
	istringstream sin(s);
	sin >> v;
	return v;
}

int sign(ll n) {
	if(n > 0) {
		return 1;
	}
	if(n < 0) {
		return -1;
	}
	return 0;
}

int main() {
	ll t[2];
	ll a[2];
	ll b[2];
	scanf("%lld %lld", &t[0], &t[1]);
	scanf("%lld %lld", &a[0], &a[1]);
	scanf("%lld %lld", &b[0], &b[1]);
	ll ab[2];
	ab[0] = b[0] - a[0];
	ab[1] = b[1] - a[1];
	if(sign(ab[0]) == sign(ab[1])) {
		puts("0");
		return 0;
	}
	ll abt[2];
	abt[0] = ab[0] * t[0];
	abt[1] = ab[1] * t[1];
	if(abt[0] + abt[1] == 0) {
		puts("infinity");
		return 0;
	}
	if(abs(abt[0]) > abs(abt[1])) {
		puts("0");
		return 0;
	}
	ll abti = abs(abt[0] + abt[1]);
	abt[0] = abs(abt[0]);

	ll result = (abt[0] + (abti - 1)) / abti;
	printf("%lld\n", result * 2 - (abt[0] % abti ? 1 : 0));
	return 0;
}

Measured memory_bytes: 256
import sys
def input(): return sys.stdin.readline().rstrip()
def main():
    n=int(input())
    a,b=map(int,input().split())
    P=[int(_) for _ in input().split()]
    P.sort()
    cunt1,cunt2,cunt3=0,0,0
    for p in P:
        if p<=a:
            cunt1+=1
        elif a+1<=p and p<=b:
            cunt2+=1
        else:cunt3+=1
    print(min(cunt1,cunt2,cunt3))

if __name__=='__main__':
    main()

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

using namespace std;
using ll = long long;
using ld = long double;
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define reps(i,s,n) for(int i=(int)(s);i<(int)(n);i++)
#define all(c) begin(c),end(c)
const ll INF = 1e10;
int main() {
	cin.sync_with_stdio(false);
	int H, W;
	cin >> H >> W;
	ll c[10][10] = {};

	rep(i, 10) {
		rep(j, 10)cin >> c[i][j];
	}
	rep(x, 10) {
		rep(k, 10) {
			rep(i, 10) {
				rep(j, 10)if (c[i][k] + c[k][j] < c[i][j])c[i][j] = c[i][k] + c[k][j];
			}
		}
	}
	ll ans = 0;
	rep(i, H) {
		rep(j, W) {
			int A;
			cin >> A;
			if (A >= 0)ans += c[A][1];
		}
	}
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 256
#include "bits/stdc++.h"
#define long int64_t
using namespace std;

struct Solver {
	void solve() {
		string N;
		cin >> N;

		int sum = 0;
		for( int i = 0; i < (int)N.size(); ++i ) {
			sum += N[i] - '0';
		}

		cout << (sum%9 == 0 ? "Yes" : "No") << endl;
	}
};

int main() {
	ios::sync_with_stdio( false );
	cout << fixed << setprecision( 10 );
	Solver().solve();
	return 0;
}


Measured memory_bytes: 3784
#include<bits/stdc++.h>
#include "ext/pb_ds/assoc_container.hpp"
#include "ext/pb_ds/tree_policy.hpp"
using namespace __gnu_pbds;
using namespace std;
#define mem(x,y) memset(x,y,sizeof(x))  
#define lli long long int
#define ll long long 
#define ld long double
#define pb push_back
#define mp make_pair
#define F first
#define S second 
#define LB lower_bound
#define UB upper_bound
#define BS binary_search
#define pii pair<lli,lli>
const long long int mod=1000000007;
//const long long int mod=998244353;
const long double PI=3.141592653589793;
const long long int inf=1e18;
const long long int inf2=LLONG_MAX;
#define setBitCount(x) __builtin_popcountll(x)
#define all(a) (a).begin(), (a).end()
#define all_r(a) (a).rbegin(), (a).rend()
lli gcd(lli a,lli b)
{
    if(b==0)
    return a;
    else
    return gcd(b,a%b);
}
// calculating (x^y)%p
lli power(lli x,lli y,lli p)
{
    lli res = 1;      
    x = x % p;  
    while (y > 0)
    {
        if (y & 1) //y is odd  
        res = (res*x) % p;
        y = y>>1; 
        x = ( (x%p)*(x%p) )% p;  
    }
    return res%p;
}
// calculating modular inverse using fermat little theorem
lli modInverse(lli n,lli p) 
{
    return power(n, p-2, p)%p;
}

// policy based data structures !!
#define ordered_set tree<lli, null_type,less<lli>, rb_tree_tag,tree_order_statistics_node_update>
// s.order_of_key (k) : Number of items strictly smaller than k
// *(s.find_by_order(k)) : K-th element in a set (counting from zero)
lli dp[3005][3005];
lli a[3005];
/*
lli fun(lli i,lli j)
{
   if(i==j)
   return a[i];
   
   if(j-i==1)
   return max(a[i],a[j]);
   
   if(dp[i][j]!=-1)
   return dp[i][j];
   
   lli ans1=a[i]+min(fun(i+2,j),fun(i+1,j-1));
   lli ans2=a[j]+min(fun(i,j-2),fun(i+1,j-1));
   lli ans=max(ans1,ans2);
   
   dp[i][j]=ans;
   return ans;
}
*/
void solve()
{
   lli n;
   cin>>n;
   
   lli sum=0;
   for(lli i=1;i<=n;i++)
   {
      cin>>a[i];
      sum+=a[i];
   }
   for(lli i=1;i<=n;i++)
   dp[i][i]=a[i];
   
   for(lli i=1;i<n;i++)
   dp[i][i+1]=max(a[i],a[i+1]);
   
   for(lli len=3;len<=n;len++)
   {
      for(lli i=1;i<=n-len+1;i++)
      {
         lli j=len+i-1;
         dp[i][j]=max(a[i]+min(dp[i+2][j],dp[i+1][j-1]),a[j]+min(dp[i+1][j-1],dp[i][j-2]));
      }
   }
   
   lli ans=dp[1][n];
   ans=2*ans-sum;
   cout<<ans;
   
}
int main()
{
   
    ios::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);

    lli T;
    //cin>>T;
    T=1;
    while(T--)
    {
        solve();
    }




    return 0;
}

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

#define each(i, c) for (auto& i : c)
#define unless(cond) if (!(cond))

using namespace std;

typedef long long int lli;
typedef unsigned long long ull;
typedef complex<double> point;

template<typename P, typename Q>
ostream& operator << (ostream& os, pair<P, Q> p)
{
  os << "(" << p.first << "," << p.second << ")";
  return os;
}

template<typename P, typename Q>
istream& operator >> (istream& is, pair<P, Q>& p)
{
  is >> p.first >> p.second;
  return is;
}

template<typename T>
ostream& operator << (ostream& os, vector<T> v)
{
  os << "(";
  each (i, v) os << i << ",";
  os << ")";
  return os;
}

template<typename T>
istream& operator >> (istream& is, vector<T>& v)
{
  each (i, v) is >> i;
  return is;
}

struct C {
  lli x, y, z;
  lli operator () () { return abs(x) + abs(y) + abs(z); }
};
C operator + (C a, C b)
{
  a.x += b.x;
  a.y += b.y;
  a.z += b.z;
  return a;
}

bool operator < (C a, C b)
{
  return a.x + a.y + a.z < b.x + b.y + b.z;
}

int main(int argc, char *argv[])
{
  ios_base::sync_with_stdio(0);
  cin.tie(0);

  int n, m;
  while (cin >> n >> m) {
    lli _x[n];
    lli _y[n];
    lli _z[n];
    for (int i = 0; i < n; ++i) {
      cin >> _x[i] >> _y[i] >> _z[i];
    }

    const lli inf = 1LL << 60;
    const int N = 1000 + 5;
    static C dp[N][N];

    lli x[n];
    lli y[n];
    lli z[n];
    
    lli mx = 0;
    for (int a = 0; a < 2; ++a) {
      for (int b = 0; b < 2; ++b) {
        for (int c = 0; c < 2; ++c) {
          copy(_x, _x + n, x);
          copy(_y, _y + n, y);
          copy(_z, _z + n, z);
          if (a) each (j, y) j *= -1;
          if (b) each (j, x) j *= -1;
          if (c) each (j, z) j *= -1;
          fill(&dp[0][0], &dp[N - 1][N - 1] + 1, C{-inf, -inf, -inf});
          dp[0][0] = C{0, 0, 0};
          for (int i = 0; i < n; ++i) {
            for (int j = 0; j <= i; ++j) {
              dp[i + 1][j] = max(dp[i + 1][j], dp[i][j]);
              dp[i + 1][j + 1] = max(dp[i + 1][j + 1], dp[i][j] + (C){x[i], y[i], z[i]});
            }
          }
          mx = max(mx, dp[n][m]());
        }
      }
    }
    cout << mx << endl;
  }

  return 0;
}


Measured memory_bytes: 24064
// In the name of God

#include <iostream>
#include <algorithm>
#include <fstream>
#include <vector>
#include <deque>
#include <assert.h>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <stdio.h>
#include <string.h>
#include <utility>
#include <math.h>
#include <bitset>
#include <iomanip>

using namespace std;

#define rep(i, n) for (int i = 0, _n = (int)(n); i < _n; ++i)
const int N = (int) 0, mod = (int) 0;

int32_t main() {
    ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    int tc;
    cin >> tc;
    while (tc--) {
        int n, d;
        cin >> n >> d;
        for (int i = 0; i < n - 1; ++i)
            d ^= 127;
        cout << (n - 1) * 127 + d << '\n';
    }


}


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

int dp[3333][3333] = {};
pair<int, int> d[3333][3333] = {};
string s, t;

void print(int i, int j) {
	if(i==0 || j==0) return;
	print(d[i][j].first, d[i][j].second);
	if(s[i-1] == t[j-1]) {
		printf("%c", s[i-1]);
	}
}

int main() {
	cin >> s >> t;
	for(int i=1;i<=s.size();i++) {
		for(int j=1;j<=t.size();j++) {
			if(s[i-1] != t[j-1]) {
				if(dp[i-1][j] > dp[i][j-1]) {
					dp[i][j] = dp[i-1][j];
					d[i][j] = {i-1, j};
				} else {
					dp[i][j] = dp[i][j-1];
					d[i][j] = {i,j-1};
				}
			} else {
				dp[i][j] = dp[i-1][j-1] + 1;
				d[i][j] = {i-1,j-1};
			}
		}
	}
	print(s.size(), t.size());
}

Measured memory_bytes: 127488
n, k = map(int, input().split())
m = [True]*n

for i in range(k):
    d = int(input())
    a = (list(map(int, input().split())))
    for j in a:
        m[j-1] = False
        
ans = [i for i in range(n) if m[i]]
print(len(ans))


Measured memory_bytes: 9080
#include <bits/stdc++.h>
#define rep(i,n) for (ll i = 0; i < (n); ++i)
#define All(v) (v).begin(),(v).end()
#define rall(v) (v).rbegin(),(v).rend()   //reverse
#define strall(v) (v).cbegin(),(v).cend() //const_itterator
#define IN(a, b, x) (a<=x&&x<b)
using namespace std;
using ll = long long;
using Pair = pair<int,int>;
using Graph = vector<vector<ll>>;
template<typename T> using min_priority_queue = priority_queue<T, vector<T>, greater<T>>;
template<typename t, typename u, typename Comp=less<>>
bool chmax(t& xmax, const u& x, Comp comp={}) { if(comp(xmax, x)) { xmax = x; return true; } return false;}
template<typename t, typename u, typename Comp=less<>>
bool chmin(t& xmin, const u& x, Comp comp={}) { if(comp(x, xmin)) { xmin = x; return true;} return false;}
const int INF = 1e9;
const ll infl = ll(1e18)+5;

/*
*ios::sync_with_stdio(false);
*cin.tie(0);
*/

int main(){
  ll N ,M;cin >> N >> M;
  vector<vector<int>> G(N);
  rep(i,M) {
    int a,b;
    cin >> a >> b,a--,b--;
    G[a].push_back(b);
    G[b].push_back(a);
  }
  vector<int> seen(N,-1);
  queue<int> que;
  que.push(0);
  seen[0] = 0;
  while(!que.empty()){
    auto v = que.front();que.pop();
    for(auto nd:G[v]){
      if(seen[nd] != -1) continue;
      seen[nd] = seen[v]+1;
      que.push(nd);
    }
  }
  if(seen[N-1] == 2) cout << "POSSIBLE" << endl;
  else cout << "IMPOSSIBLE" << endl;
  

}

Measured memory_bytes: 15892
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define INFL 0x6fffffffffffffffLL

int main() {
	ll		a,b,d,w,h,i,j,k,l,m,n,z;
	double	ans = 0;
	cin >> a >> b >> h >> m;
	double x = m*6;
	double y = h*30+(double)m/2;
	double rad = abs(x-y);
	if (rad>180.0) rad = 360.0 - rad;
	//cout << x << " " << y << " " << rad << endl;
	//cout << cos(0) << endl;
	//cout << cos(180.0*180.0/M_PI) << endl;
	if (rad==180.0) {
		ans = a+b;
	} else {
		ans = sqrt( a*a + b*b - 2*a*b*cos(rad/180.0*M_PI) );
	}
	printf("%.10f\n",ans);
	return 0;
}


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

int main() {
  int X, Y;
  cin >> X >> Y;
  if (Y % 2 != 0) {
    cout << "No" << endl;
    return 0;
  }
  int tsuru, kame;
  tsuru = 2*X - Y/2;
  kame = -1*X + Y/2;
  // cout << tsuru << endl;
  // cout << kame << endl;
  if (tsuru + kame == X && (tsuru >= 0 && kame >= 0)) {
      cout << "Yes" << endl;
      return 0;
  }
  cout << "No" << endl;

  return 0;
}


Measured memory_bytes: 3624
//============================================================================
// Name        : Watchin.cpp
// Author      : alpc92
// Version     :
// Copyright   : Your copyright notice
// Description : Hello World in C++, Ansi-style
//============================================================================

#include <cstdlib>
#include <cctype>
#include <cstring>
#include <cstdio>
#include <cmath>
#include <algorithm>
#include <vector>
#include <string>
#include <iostream>
#include <sstream>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <fstream>
#include <numeric>
#include <iomanip>
#include <bitset>
#include <list>
#include <stdexcept>
#include <functional>
#include <utility>
#include <ctime>
using namespace std;

#define PB push_back
#define MP make_pair

#define REP(i,n) for(int i(0);i<((int)n);++i)
#define FOR(i,l,h) for(int i((int)l);i<=((int)h);++i)
#define FORD(i,h,l) for(int i((int)h);i>=((int)l);--i)
#define CLEAR(arr,k) memset(arr,k,sizeof(arr))
#define SZ (STL) (int)STL.size();
typedef vector<int> VI;
typedef vector<string> VS;
typedef vector<double> VD;
typedef long long LL;
typedef pair<int, int> PII;
map<string, int> mp;
int hash(int d, int st) {
	int h(st / 100), m(st % 100);
	if (h >= 24) {
		++d ;
		h %= 24;
	}
	return m + (h + d * 24) * 60;
}
vector<int> tim, fav;
bool chkfav() {
	FOR(i,1,(int)fav.size()-1)
		if (fav[i] - fav[i - 1] < 30)
			return 0;
	return 1;
}
int chktim() {
	int res(0);
	sort(tim.begin(), tim.end());
	REP(i,(int)tim.size()) {
		bool flag(1);
		REP(j,(int)fav.size())
			if (abs(tim[i] - fav[j]) < 30) {
				flag = 0;
				break;
			}
		if (flag)
			++res, fav.push_back(tim[i]);
	}
	return res;
}
int main() {
	int n, p;
	while (cin >> n, n) {
		string s;
		int d, st;
		mp.clear();
		tim.clear();
		fav.clear();
		REP(i,n) {
			cin >> s >> d >> st;
			int t(hash(d, st));
			mp[s] = t;
			tim.push_back(t);
		}
		cin >> p;
		REP(i,p) {
			cin >> s;
			fav.push_back(mp[s]);
		}
		sort(fav.begin(), fav.end());
		if (chkfav())
			printf("%d\n", p + chktim());
		else
			puts("-1");
	}
	return 0;
}

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

// Shrotening
#define fst first
#define snd second
#define pb push_back

// Loop
#define FOR(i,a,b) for(long i=(a);i<(b);++i)
#define RFOR(i,a,b) for(long i=(a);i>=(b);--i)

#define REP(i,a) for(long i=0;i<(a);++i)
#define RREP(i,a) for(long i=(a);i>=0;--i)

#define EACH(i,a) for(auto (i)=(a).begin(),_END=(a).end();i!=_END;++i)
#define REACH(i,a) for(auto (i)=(a).rbegin(),_END=(a).rend();i!=_END;++i)

//Algorithm
#define ALL(a) (a).begin(), a.end()
#define RALL(a) (a).rbegin(), a.rend()
#define EXIST(a,x) ((a).find(x)!=(a).end())
#define SORT(a) std::sort((a).begin(), (a).end())
#define UNIQUE(a) std::sort((a).begin(), a.end()), a.erase(std::unique((a).begin(), a.end()), a.end());
#define SUM(a) std::accumulate((a).begin(), (a).end(), 0);

//Setting
#define OPT std::cin.tie(0);std::ios::sync_with_stdio(false);

//debug message
bool debug = true;
#define MSG(s)   if(debug){std::cout << s << std::endl;}
#define DEBUG(x) if(debug){std::cout << "debug(" << #x << "): " << x << std::endl;}

//alias
typedef long long LL;
typedef std::vector<char> VC;
typedef std::vector<int>  VI;
typedef std::vector<long> VL;
typedef std::vector<long long> VLL;

typedef std::vector< VC > VC2;
typedef std::vector< VI > VI2;
typedef std::vector< VL > VL2;
typedef std::vector< VLL > VLL2;

typedef std::pair<int,int> PII;

int N, M;
std::vector< std::pair<bool, int> > x;
std::vector< std::vector< std::pair<int, int> > > g;

bool dfs(int i, int X) {
    if(x[i].fst) {
        return x[i].snd == X;
    }

    x[i].fst = true;
    x[i].snd = X;

    for(auto next: g[i]) {
        bool res = dfs(next.fst, next.snd + X);
        if(!res) { 
            return false;
        }
    }
    return true;
}

int main() {
    std::cin >> N >> M;

    x.resize(N);
    g.resize(N);
    REP(i, N) {
        x[i].fst = false;
    }

    int l, r, d;
    REP(i, M) {
        std::cin >> l >> r >> d;
        --l, --r;

        g[l].pb(std::make_pair(r, d));
        g[r].pb(std::make_pair(l, -d));
    }

    bool ans = true;
    REP(i, N) {
        if(!x[i].fst) {
            bool res = dfs(i, 0);
            if(!res) {
                ans = false;
                break;
            }
        }
    }

    if(ans) {
        std::cout << "Yes" << std::endl;
    } else {
        std::cout << "No" << std::endl;
    }
}

Measured memory_bytes: 12416
#include <bits/stdc++.h>
#define For(i, a, b) for(int (i)=(a); (i)<(b); ++(i))
#define rFor(i, a, b) for(int (i)=(a)-1; (i)>=(b); --(i))
#define rep(i, n) For((i), 0, (n))
#define rrep(i, n) rFor((i), (n), 0)
#define fi first
#define se second
using namespace std;
typedef long long lint;
typedef pair<int, int> pii;
typedef pair<lint, int> pli;
typedef complex<double> xy_t;

const lint mod = 1e9 + 7;

int n, m;
vector<int> G[1010];
int sz, d[1010];
bool found, cycle, used[1010];

void dfs1(int v){
    if(used[v]){
        cycle = true;
        return;
    }
    used[v] = true;
    ++sz;
    for(int nv: G[v]){
        dfs1(nv);
        if(cycle) return;
    }
    used[v] = false;
    --sz;
}

void dfs2(int v, int td){
    if(d[v] >= 0 && td - d[v] < sz){
        found = true;
        rep(i, n)if(d[i] < d[v]) d[i] = -1;
        return;
    }
    if(d[v] >= 0) return;
    d[v] = td;
    for(int nv: G[v])if(used[nv]){
        dfs2(nv, td+1);
        if(found) return;
    }
    d[v] = -1;
}

int main(){
    scanf("%d%d", &n, &m);
    rep(i, m){
        int a, b;
        scanf("%d%d", &a, &b);
        --a; --b;
        G[a].push_back(b);
    }

    sz = 0;
    cycle = false;
    rep(i, n) used[i] = false;
    rep(i, n){
        dfs1(i);
        if(cycle) break;
    }

    if(!cycle){
        printf("-1\n");
        return 0;
    }

    while(true){
        rep(i, n) d[i] = -1;
        found = false;
        rep(i, n)if(used[i]){
            dfs2(i, 0);
            break;
        }

        if(!found){
            printf("%d\n", sz);
            rep(i, n)if(used[i]) printf("%d\n", i+1);
            return 0;
        }
        rep(i, n) used[i] &= (d[i] >= 0);
        sz = 0;
        rep(i, n)if(used[i]) ++sz;
    }
}

Measured memory_bytes: 384
#include <bits/stdc++.h>
using namespace std;
#include <math.h>
#include <iomanip>
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
const int INF=1001001001;
vector<pair<int64_t,int64_t>>prime_factorize(int64_t x){
  vector<pair<int64_t,int64_t>>p;
  for(int64_t i=2;i*i<=x;i++){
    int cnt=0;
    if(x%i==0){
    while(x%i==0){cnt++;x/=i;}
    p.push_back(make_pair(i,cnt));
    }
  }
  if(x!=1){p.push_back(make_pair(x,1));}
  return p; 
}
int main() {
  int64_t N,K;
  cin>>N>>K;
  vector<int>a(N),b(N);
  map<int,int64_t>k;
  for(int i=0;i<N;i++){
    cin>>a[i]>>b[i];
    k[a[i]]+=b[i];
  }
  int64_t sum=0;
  for(auto p:k){
    int v=p.first;
    int64_t q=p.second;
    sum+=q;
    if(sum>=K){cout<<v<<endl;return 0;}
  }
  return 0;
}

Measured memory_bytes: 7984
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        Scanner num = new Scanner(System.in);
        int a = num.nextInt();
        int b = num.nextInt();
        int c = num.nextInt();
        int cnt = 0;
        for (int i = a; i <= b; i++) {
            if (c % i == 0) {
                cnt++;
            }
        }
        System.out.println(cnt);
    }
}

Measured memory_bytes: 26320
import java.util.*;

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

    String X=sc.next();
    String Y=sc.next();
    char x=X.charAt(0);
    char y=Y.charAt(0);

    if(x<y){
      System.out.println("<");
    }else if(x>y){
      System.out.println(">");
    }else{
      System.out.println("=");
    }



	}
}


Measured memory_bytes: 22732