akhauriyash/Code-Regression huggingface dataset:
#include <algorithm>
#include <cmath>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <utility>
#include <vector>
#define rep(i, n) for (int i = 0, i##_len = (n); i < i##_len; ++i)
#define reps(i, n) for (int i = 1, i##_len = (n); i <= i##_len; ++i)
#define rrep(i, n) for (int i = ((int)(n)-1); i >= 0; --i)
#define rreps(i, n) for (int i = ((int)(n)); i > 0; --i)
#define INF 1000000000000
#define MOD 1000000007
#define CHOOSE(a) CHOOSE2 a
#define CHOOSE2(a0, a1, a2, a3, a4, x, ...) x
#define debug_1(x1) cout << #x1 << ": " << x1 << endl
#define debug_2(x1, x2) \
    cout << #x1 << ": " << x1 << ", " #x2 << ": " << x2 << endl
#define debug_3(x1, x2, x3)                                                 \
    cout << #x1 << ": " << x1 << ", " #x2 << ": " << x2 << ", " #x3 << ": " \
         << x3 << endl
#define debug_4(x1, x2, x3, x4)                                             \
    cout << #x1 << ": " << x1 << ", " #x2 << ": " << x2 << ", " #x3 << ": " \
         << x3 << ", " #x4 << ": " << x4 << endl
#define debug_5(x1, x2, x3, x4, x5)                                         \
    cout << #x1 << ": " << x1 << ", " #x2 << ": " << x2 << ", " #x3 << ": " \
         << x3 << ", " #x4 << ": " << x4 << ", " #x5 << ": " << x5 << endl
#ifdef _DEBUG
#define debug(...)                                                        \
    CHOOSE((__VA_ARGS__, debug_5, debug_4, debug_3, debug_2, debug_1, ~)) \
    (__VA_ARGS__)
#else
#define debug(...)
#endif

using namespace std;
using ll = long long;

int main() {
    int n;
    cin >> n;
    string s;
    cin >> s;
    int rcnt = 0, rcnt2 = 0;
    rep(i, s.size()) {
        if (s[i] == 'R') rcnt++;
    }
    rep(i, rcnt) {
        debug(i);
        if (s[i] == 'R') rcnt2++;
    }
    debug(rcnt, rcnt2);
    cout << rcnt - rcnt2 << endl;
    return 0;
}

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

int main(){
  int h, w;
  int d[5] = {0, -1, 0, 1, 0};
  char c;
  bool canvas[50][50] = {}; //'.'true, '#'false
  
  cin >> h >> w;
  for(int i = 0;i < h;i++){
    for(int j = 0;j < w;j++){
      cin >> c;
      if(c == '.') canvas[i][j] = true;
    }
  }
  
  for(int i = 0;i < h;i++){
    for(int j = 0;j < w;j++){
      bool f[4] = {};
      
      if(canvas[i][j]) continue;
      for(int k = 0;k < 4;k++){
        int x = j + d[k], y = i + d[k + 1];
        
        if(0 <= x && x < w && 0 <= y && y < h){
          if(canvas[y][x]) f[k] = true;
        }else f[k] = true; 
      }
      
      if(f[0] && f[1] && f[2] && f[3]){
        cout << "No" << endl;
        return 0;
      }
    }
  }
  
  cout << "Yes" << endl;
  
  return 0;
}

Measured memory_bytes: 256
#include <cstdio>
#include <iostream>
#include <algorithm>
#include <cstring>
#include <cstdlib>
#include <cmath>
#define rep( i, a, n ) for( int i = a; i < n; i++ )
#define per( i, a, n ) for( int i = n - 1; i >= a; i-- )
#define mem( f, x ) memset( f, x, sizeof( f ) )
#define ll long long
#define pii pair<int, int>
#define fi first
#define se second
#define INF 0x3f3f3f3f

using namespace std;
const int N = 1050;
const int M = 35;
const int MAX = 5;
const double g = 9.80;
const double PI = acos( -1.0 );
int m, n, rk, k, t;
int w[N], v[N], dp[N][M], a[M], b[M];

int main( ){
    scanf( "%d %d", &m, &n );
    printf( "%d\n", m * n - m - n + 1 );
    return 0;
}


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

#define int long long
#define itn int
#define For(i, a, b) for (int i = (a); i <= static_cast<int>(b); i++)
#define Forr(i, a, b) for (int i = (a); i >= static_cast<int>(b); i--)
#define rep(i, n) For(i, 0, n - 1)
#define repall(i, arr) for (auto& i : (arr))
#define all(x) (x).begin(), (x).end()
#define pb push_back
#define dump(x) cerr << #x << " = " << (x) << '\n'
#define dump2(x, y) \
    cerr << #x << " = " << (x) << " " << #y << " = " << (y) << '\n'
#define SZ(x) ((int)(x).size())
#define bit(n) (1LL << (n))
constexpr int MOD = 1e9 + 7;

template <typename T>
using pq = priority_queue<T>;
template <typename T>
using pqr = priority_queue<T, vector<T>, greater<T>>;
const int INF = LLONG_MAX / 2;
using P = pair<int, int>;
using vec = vector<int>;
template <typename T>
using mat = vector<vector<T>>;

// clang-format off
template <typename T1, typename T2>
ostream& operator<<(ostream& stream, const pair<T1, T2>& p) { return stream << p.first << "," << p.second; }
template <typename T>
void print(const vector<T> vec) { rep (i, vec.size() - 1) cout << vec[i] << ' '; cout << vec[vec.size() - 1] << '\n'; }
template <typename Arg>
void print(const Arg arg) { cout << arg << '\n'; }
template <typename Head, typename... Args>
void print(const Head head, const Args... args) { cout << head << " "; print(args...); }
template <typename T, typename U>
void init(vector<T>& v, vector<U>& w) { rep (i, v.size()) cin >> v[i] >> w[i]; }
template <typename T>
void init(vector<T>& v) { rep (i, v.size()) cin >> v[i]; }
template <typename T>
T sum_(vector<T> vec, T init = 0) { return std::accumulate(all(vec), T(init)); }
template<typename T>
bool chmax(T& a, const T& b) { if (a < b) { a = b; return true; } return false; }
template<typename T>
bool chmin(T& a, const T& b) { if (a > b) { a = b; return true; } return false; }
template <typename T>
int index(const T& vec, const typename T::iterator it) { return distance(vec.begin(), it); }
template <typename T = int>
mat<T> mmat(int n, int m=0) { return mat<T>(n, vector<T>(m)); }
template <typename T = int>
vector<T> ivec(int n) { vector<T> v(n); init(v); return v; }
// clang-format on

void yn(bool tf) { print(tf ? "Yes" : "No"); }
void YN(bool tf) { print(tf ? "YES" : "NO"); }

int gcd(int a, int b) { return b ? gcd(b, a % b) : a; }
// -------------------------------------------------------------------
// sort 1 2 3 4
// pqr 1 2 3 must impl >

int ppow(int n, int k) {
    if (k == 0)
        return 1;
    else
        return pow(n, k - 1) * n;
}

signed main() {
    cin.tie(0), cout.tie(0), ios::sync_with_stdio(false);
    int n, k;
    cin >> n >> k;
    int cnt = 0;
    while (true) {
        if (n >= ppow(k, cnt))
            cnt++;
        else
            break;
    }
    print(cnt);

    return 0;
}


Measured memory_bytes: 512
mod = 10**9+7
half = 5*10**8+4
n = int(input())
a = list(map(int,input().split()))
ans = 0
for i in range(n):
  ans += a[i]
  ans %= mod
ans **= 2
#print(ans)
ans %= mod
#print(ans)
for i in range(n):
  ans -= a[i] ** 2
  ans %= mod
ans *= half
ans %= mod
print(ans)

Measured memory_bytes: 94032
#include <stdio.h>

int main(){
    char date[10];
    int i;
    int year = 0;
    int month = 0;
    int day = 0;

    scanf("%s", date);

    year = 1000 * (unsigned char) (date[0] - '0');
    year += 100 * (unsigned char) (date[1] - '0');
    year += 10 * (unsigned char) (date[2] - '0');
    year += (unsigned char) (date[3] - '0');

    if (year < 2019){
        printf("Heisei");
    }else if(year > 2019){
        printf("TBD");
    }else{
        month = 10 * (unsigned char) (date[5] - '0') + (unsigned char) (date[6] - '0');
        if(month <= 4){
            printf("Heisei");
        }else if(month >= 5){
            printf("TBD");
        }
    }
}

Measured memory_bytes: 128
n=int(input())
A=[int(i) for i in input().split()]

tar=sum(A)/2

now=0
pre=0
for i in range(n):
    now+=A[i]
    if pre<=tar and tar<=now:
        #print(pre,tar,now)
        break
    pre=now

if tar-pre>now-tar:
    print(abs(now-(sum(A)-now)))
else:
    print(abs(pre-(sum(A)-pre)))

Measured memory_bytes: 26220
#
# Written by NoKnowledgeGG @YlePhan
# ('ω')
#
#import math
#mod = 10**9+7
#import itertools
#import fractions
#import numpy as np
#mod = 10**4 + 7
"""def kiri(n,m):
  r_ = n / m
  if (r_ - (n // m)) > 0:
    return (n//m) + 1
  else:
    return (n//m)"""
  
def main():
  x,y,z = map(int,input().split())
  y,x = x,y
  x,z = z,x
  print(x,y,z)
if __name__ == '__main__':
  main()

Measured memory_bytes: 2940
n = gets.to_i
a = gets.split.map(&:to_i).sort
b = gets.split.map(&:to_i).sort
c = gets.split.map(&:to_i).sort

count = 0
b.each do |bb|
  ai = a.bsearch_index {|x| x >= bb} || n
  ci = c.bsearch_index {|x| x > bb} || n
  count += ai * (n - ci)
end

puts count

Measured memory_bytes: 26368
#include <bits/stdc++.h>
using namespace std;
#define _GLIBCXX_DEBUG
#define rep(i, from, to) for (int i = from; i < (to); ++i)
#define mp(x,y) make_pair(x,y)
#define all(x) (x).begin(),(x).end()
#define sz(x) (int)(x).size()
#define pb push_back
using ll = long long;
using vin=vector<int>;
using vll=vector<ll>;
using P = pair<int, int>;
const int inf=1e9+7;
const ll INF=1e18;
template <typename T> bool chmin(T &a, const T& b){if(a > b){a = b;return true;}return false;}
template <typename T> bool chmax(T &a, const T& b){if(a < b){a = b;return true;}return false;}
template<class T> inline void Yes(T condition){ if(condition) cout << "Yes" << endl; else cout << "No" << endl; }
template<class T> inline void YES(T condition){ if(condition) cout << "YES" << endl; else cout << "NO" << endl; }
const int dx[4] = { 1, 0, -1, 0 };
const int dy[4] = { 0, 1, 0, -1 };

int main(){cout<<fixed<<setprecision(10);
           string s;
           cin>>s;
           int n=s.size();
           bool ok=true;
           map<char,int> cnt;
           rep(i,0,n){
             cnt[s[i]]++;
             if(cnt[s[i]]>1){
              ok=false; 
             }
           }
           if(ok)cout<<"yes"<<endl;
           else cout<<"no"<<endl;
}

Measured memory_bytes: 3592
A,B,M=map(int,input().split())

a=list(map(int,input().split()))
b=list(map(int,input().split()))

mi=min(a)+min(b)
for i in range(M):
    x,y,c=map(int,input().split())
    mi=min(a[x-1]+b[y-1]-c,mi)

print(mi)

Measured memory_bytes: 18864
#include<cstdio>
#include<iostream>
using namespace std;
int main()
{
	int x, a, b;
	while (cin>>x>>a>>b)
	{
		if (a >= b) cout << "delicious"<<endl;
		else if (a < b)
		{
			if (b - a <= x) cout << "safe" << endl;
			else if (b - a > x) cout << "dangerous" << endl;
		}
	}
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <cmath>
#include <vector>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <queue>
#include <ctime>
#include <cassert>
#include <complex>
#include <string>
#include <cstring>
using namespace std;

#ifdef LOCAL
	#define eprintf(...) fprintf(stderr, __VA_ARGS__)
#else
	#define eprintf(...) 42
#endif

typedef long long ll;
typedef pair<int, int> pii;
#define mp make_pair

const int Z = 8003;
const int N = 2 * Z + 1;
bool dp[2][2][N];
int X, Y;
char s[N];
int n;
int t;

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

	dp[0][0][Z] = dp[1][0][Z] = 1;
	scanf("%s", s);
	n = strlen(s);
	scanf("%d%d", &X, &Y);
	int pos = 0;
	while(pos < n && s[pos] == 'F') {
		pos++;
		X--;
	}
	t = 0;
	while(pos < n) {
		pos++;
		t ^= 1;
		int L = 0;
		while(pos < n && s[pos] == 'F') {
			pos++;
			L++;
		}
		for (int i = 0; i < N; i++)
			dp[t][1][i] = 0;
		for (int i = 0; i < N; i++) {
			if (!dp[t][0][i]) continue;
			dp[t][1][i - L] = dp[t][1][i + L] = 1;
		}
		for (int i = 0; i < N; i++)
			dp[t][0][i] = dp[t][1][i];
	}
	if (dp[0][0][Z + X] && dp[1][0][Z + Y])
		printf("Yes\n");
	else
		printf("No\n");

	return 0;
}


Measured memory_bytes: 384
#include <bits/stdc++.h>
typedef long long LL;
#define FOR(i,a,b) for(LL i=(a);i<(b);++i)
#define REP(i,n) FOR(i,0,n)

using namespace std;
LL p = 1000000007ll;

int main(void)
{
  map<string,string> succ;
  succ["Sunny"] = "Cloudy";
  succ["Cloudy"] = "Rainy";
  succ["Rainy"] = "Sunny";
  string s;
  cin >> s;
  cout << succ[s] << endl;
  return 0;
}


Measured memory_bytes: 256
#include <iostream>

using namespace std;
int main() {

	// 1回なら100〜105円
	// 2回なら200〜210円
	// 3回なら300〜315円
	// 4回なら400〜420円
	// 5回なら500〜425円
	// 6回なら600〜630円
	// 7回なら700〜735円
	// 8回なら800〜840円
	// 9回なら900〜945円
	// 10回なら1000〜1050円
	// 19回なら1900〜1995円
	// 20回なら2000〜2100円
	int x;
	cin >> x;

	if (x < 99) {
		cout << 0 << endl;
		return 0;
	} 

	if (x > 2000) {
		cout << 1 << endl;
		return 0;
	}

	int count = x / 100;
	int lower = x % 100;

	if (lower <= count * 5) {
		cout << 1 << endl;
		return 0;		
	}
	cout << 0 << endl;

	return 0;
}

Measured memory_bytes: 888
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class Main {

	public static void main(String[] args) throws IOException {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		String line = "";

		while ((line = br.readLine()) != null) {
			StringBuilder sb = new StringBuilder();
			for (char c : line.toCharArray()) {
				c -= 3;
				if (c < 'A')
					c += 26;
				sb.append(c);
			}
			System.out.println(sb.toString());
		}
	}
}

Measured memory_bytes: 16876
#include <bits/stdc++.h>
#define _overload3(_1, _2, _3, name, ...) name
#define _rep(i, n) repi(i, 0, n)
#define repi(i, a, b) for (ll i = (ll)(a); i < (ll)(b); ++i)
#define rep(...) _overload3(__VA_ARGS__, repi, _rep, )(__VA_ARGS__)
#define ll long long
#define lld long double
#define ALL(x) x.begin(), x.end()
using namespace std;
const int IINF = 1 << 30;

void check(vector<int> &ans, int x)
{
    while (ans.size() != 1)
    {
        vector<int> nans(ans.size() - 2);
        rep(i, ans.size() - 2)
        {
            nans[i] = ans[i] + ans[i + 1] + ans[i + 2] -
                      max({ans[i], ans[i + 1], ans[i + 2]}) -
                      min({ans[i], ans[i + 1], ans[i + 2]});
        }
        ans = nans;
    }
    assert(ans[0] == x);
}

int main(int argc, char const *argv[])
{
    int n, x;
    cin >> n >> x;
    n = 2 * n - 1;

    if (x == 1 || x == n)
    {
        cout << "No" << endl;
    }
    else
    {
        cout << "Yes" << endl;
        if (n == 3 && x == 2)
        {
            cout << "1 2 3" << endl;
            return 0;
        }

        vector<int> ans(n, -1);
        map<int, bool> used;
        used[x] = used[1] = used[n] = true;
        if (x <= n / 2)
        {
            ans[n / 2 - 2] = n;
            ans[n / 2 - 1] = 1;
            ans[n / 2] = x;
            ans[n / 2 + 1] = n - 1;
            used[n - 1] = true;
        }
        else
        {
            ans[n / 2 - 2] = 1;
            ans[n / 2 - 1] = n;
            ans[n / 2] = x;
            ans[n / 2 + 1] = 2;
            used[2] = true;
        }
        int cur = 1;
        rep(i, n)
        {
            if (ans[i] != -1)
                continue;
            while (used[cur])
                cur++;
            ans[i] = cur;
            used[cur] = true;
        }
        rep(i, n) cout << ans[i] << endl;
    }
    return 0;
}


Measured memory_bytes: 11648
/*
 * atcoder/abc119/d.cpp
 */

// C++ 14
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <cstring> // memset
#include <cassert>
using namespace std;
#define ll long long
#define loop(__x, __start, __end) for(int __x = __start; __x < __end; __x++)
template <class T> ostream & operator << (ostream & out, vector<T> const & v) {
  for (auto &&a: v) out << a << " "; out << endl; return out;
}
template <class T> void dump(T &a) { cout << a << endl; }
template <class T> bool chmin(T &a, T b) { if (a > b) {a = b; return true; } return false; }
template <class T> bool chmax(T &a, T b) { if (a < b) {a = b; return true; } return false; }

/*
 * S, Tを座標昇順にソートしてQ回の二分探索はどう？ O(Q x log(max(A, B)))
 * SとTそれぞれ先に訪れる２つの場合の最小値
 * S -> Tの場合)
 * Sをxで二分探索して|S[n]-x|を最小化するnを見つける.
 * 次にTをS[n]で二分探索して、|T[m]-S[n]|を最小化するmを見つける.
 * コストは|S[n]-x| + |T[m]-S[n]|
 *
 * 上記ではダメだ. 最小値を求める事ができない.
 * 以下のようなケース. x = 0, s 100 でt = 101でより小さいt1=1が存在する場合.
 * 最小値は100なのに、sから最も近いt1が選択されて101となる.
 *
 * なので、s, tともにxから最も近い2点(s1, s2, t1, t2)ずつ探して
 * s1 -> t1
 * s1 -> t2
 * s2 -> t1
 * s2 -> t2
 * tも同様につき8通りのうち最短経路.
 *
 * 2000: s0 -> t0 が最短
 * 900 -> 600が最短
 * 100           600
 *          400          900 1000
 *                   899                               2000
 */
const ll INF = 10000000000000000;
int A, B, Q;
vector<ll> S, T;
ll x;
void solve() {
  cin >> A >> B >> Q;
  S.resize(A); T.resize(B);
  loop(i,0,A) cin >> S[i];
  loop(i,0,B) cin >> T[i];
  sort(S.begin(), S.end());
  sort(T.begin(), T.end());
  loop(q,0,Q) {
    cin >> x;
    vector<ll> ss;
    vector<ll> ts;
    int s_n = lower_bound(S.begin(), S.end(), x) - S.begin();
    int t_n = lower_bound(T.begin(), T.end(), x) - T.begin();
    ss.push_back(s_n == S.size() ? INF : S[s_n]);
    ss.push_back(s_n==0 ? -INF : S[s_n-1]);
    ts.push_back(t_n == T.size() ? INF : T[t_n]);
    ts.push_back(t_n==0 ? -INF : T[t_n-1]);
    ll min_ = INF;
    loop(s_i,0,2) loop(t_i,0,2) {
      ll cost = abs(x-ss[s_i]) + abs(ss[s_i]-ts[t_i]);
      ll cost2 = abs(x-ts[t_i]) + abs(ss[s_i]-ts[t_i]);
      // cout << "s" << s_i << " -> t" << t_i << " : cost = " << cost << " s = " << ss[s_i] << " t = " << ts[t_i] << endl;
      // cout << "t" << t_i << " -> s" << s_i << " : cost2 = " << cost2 << " s = " << ss[s_i] << " t = " << ts[t_i] << endl;
      chmin(min_, cost);
      chmin(min_, cost2);
    }

    cout << min_ << endl;
  }
}
int main() {
  // cout.precision(15); cout << fixed;

  solve();

  return 0;
}


Measured memory_bytes: 2944
#include <bits/stdc++.h>
using namespace std;
#define mp       make_pair
#define pb       push_back
#define all(x)   (x).begin(),(x).end()
#define YES() printf("YES\n")
#define NO() printf("NO\n")
#define Yes() printf("Yes\n")
#define No() printf("No\n")
#define in(x,y,h,w) x >= 0 && x < h && y >= 0 && y < w

#define int long long
//typedef    long long          ll;
typedef    vector<bool>       vb;
typedef    vector<int>        vi;
typedef    vector<vb>         vvb;
typedef    vector<vi>         vvi;
typedef    pair<int,int>      P;

template <typename T> T &chmin(T &a, const T &b) { return a = min(a, b); }
template <typename T> T &chmax(T &a, const T &b) { return a = max(a, b); }
 
const int INF=2e+18;
const double EPS=1e-9;
const int MOD=1000000007;

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

signed main(){
	int n,ans = 0,mi = INF,sum = 0;
	cin >> n;
	bool flag = true;
	for(int i = 0;i < n;i++){
		int a,b;
		cin >> a >> b;
		if(a == b) ans += a;
		else{
			flag = false;
			if(a < b) ans += a;
			else{
				ans += a - b;
				sum += b;
				chmin(mi,b);
			}
		}
	}
	if(flag) cout << 0 << endl;
	else cout << ans + sum - mi << endl;
	return 0;
}

Measured memory_bytes: 256
using static System.Math;
using System;

public class Hello
{
    public static void Main()
    {
        var n = int.Parse(Console.ReadLine().Trim());
        var t = 0;
        var max = 0;
        for (int i = 0; i < n; i++)
        {
            var w = int.Parse(Console.ReadLine().Trim());
            t += w;
            max = Max(max, w);
        }
        t -= max / 2;
        Console.WriteLine(t);
    }
}


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

vector<int> G[100010];
int dp[100010];
int INF = 1e9;
int n;

int dfs(int now){
    if(dp[now] != -1) return dp[now];
    if(G[now].size() == 0) return dp[now] = 0;
    vector<int> d;
    for(int i = 0; i < G[now].size(); i++){
        d.push_back(dfs(G[now][i]));
    }
    sort(d.begin(), d.end(), greater<int>());
    int MAX = -1;
    for(int i = 0; i < d.size(); i++){
        MAX = max(MAX, d[i] + i + 1);
    }
    return dp[now] = MAX;
}

int main(){
    cin >> n;
    vector<int> a(n);
    memset(dp, -1, sizeof(dp));
    for(int i = 1; i < n; i++){
        cin >> a[i];
        a[i]--;
        G[a[i]].push_back(i);
    }
    cout << dfs(0) << endl;
}

Measured memory_bytes: 15872
using System;
using static System.Console;

namespace ConsoleApp4
{
    class Program
    {
        static void Main()
        {
            var s = ReadLine().Split(' ');
            var a = int.Parse(s[0]);
            var b = int.Parse(s[1]);
            var c = int.Parse(s[2]);
            var d = int.Parse(s[3]);

            WriteLine((Math.Abs(c - a) <= d) || ((Math.Abs(b - a) <= d) && (Math.Abs(c - b) <= d))
                ? "Yes"
                : "No");

        }

    }
}


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

typedef long long int lli;
typedef unsigned long long int ulli;
typedef pair<int,int> pii;

#define ones(x) __builtin_popcount(x)
#define onesl(x) __builtin_popcountl(x)
#define onesll(x) __builtin_popcountll(x)

#define pb push_back
#define eb emplace_back
#define mp make_pair
#define mt make_tuple
#define scn(n) scanf("%d",&n)
#define scnll(n) scanf("%lld",&n)
#define scn2(n,m) scanf("%d%d",&n,&m)
#define scn3(n,m,w) scanf("%d%d%d",&n,&m,&w)
#define scn2ll(n,m) scanf("%lld%lld",&n,&m)
#define atoz(v) v.begin(),v.end()
#define ratoz(v) v.rbegin(),v.rend()
#define Fill(a,v) memset(a,v,sizeof(a))
#define sz(v) v.size()
#define fi first
#define se second
#define inf 1e9
#define pi acos(-1.0)
#define sqr(x) x*x
#define max3(a,b,c) max(a,max(b,c))
#define min3(a,b,c) min(a,min(b,c))
#define ten(n) (int)1e##n
#define tenll(n) (lli)1e##n
#define mod 1000000007
#define FastIO ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);

int Set(int N,int pos)
{
    return N=N | (1<<pos);
}
int reset(int N,int pos)
{
    return N = N & ~(1<<pos);
}
bool check(int N,int pos)
{
    return (bool)(N & (1<<pos));
}

void we_r_done(){cout<<"NO"; exit(0);}

void debug(string mssg){cout<<mssg; exit(0);}


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

    ///FastIO;

    int a,p;
    scn2(a,p);

    a *= 3;
    cout<<(a+p)/2;

    return 0;
    ///return main();
}

///sin and cos expect input in radians not degrees. so use , sin(degrees * pi / 180)
///priority_queue< int, vector< int >, greater< int > > minHeap;
///using bs = bitset<MX>; // how many distinct number can be form?


Measured memory_bytes: 256
outnum = 1000000
human_sum = int(input())
basyo_list = list(map(int, input().split()))
for i in range(1,101):
  total_sum = 0
  for j in range(human_sum):
    total_sum = total_sum + (i - basyo_list[j]) ** 2
  if total_sum <= outnum:
    outnum = total_sum
print(outnum)

Measured memory_bytes: 3060
#include <stdio.h>

int count;

int binary_search(int array[], int data, int l, int r)
{
	int c = (l + r) / 2;
	
	if (l > r){
		return count;
	}
	count++;
	if (data == array[c]){
		return count;
	}
	else if (data < array[c]){
		return binary_search(array, data, l, c - 1);
	}
	else {
		return binary_search(array, data, c + 1, r);
	}
}

int main(void)
{
	int n;
	int array[100];
	
	while (scanf("%d", &n) * n != 0){
		int i;
		int data;
		
		count = 0;
		for (i = 0; i < n; i++){
			scanf("%d", array + i);
		}
		scanf("%d", &data);
		printf("%d\n", binary_search(array, data, 0, n - 1));
	}
	
	return 0;
}

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

# define rep(i, n) for(int(i)=0;(i)<(n);(i)++)
# define reps(i, n) for(int(i)=1;(i)<=(n);(i)++)
# define rrep(i, n) for(int i=((int)(n)); i>0; --i)
# define rreps(i, n) for(int i=((int)(n)); i>=0; --i)
# define ALL(v) v.begin(), v.end()
template<class T>inline bool chmax(T &a, const T &b) { if (a<b) { a=b; return true; } return false; }
template<class T>inline bool chmin(T &a, const T &b) { if (b<a) { a=b; return true; } return false; }
typedef long long ll;


int main() {
    int N; cin >> N;
    ll r = pow(N, 3);
    cout << r << endl;
}


Measured memory_bytes: 3284
#include <bits/stdc++.h>
#include <math.h>
using namespace std;
typedef long long ll;
typedef long double ld;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
const ll mod = 1000000007;
const ll INF = 1001001001;
const ll LINF = 1001001001001001001;

void prvec(vector<ll> vec){
    ll n = vec.size();
    rep(i,n) cout << "i" << " " << vec.at(i) << "\n";
}

void pr2d(vector<vector<ll>> vvec){
    ll h = vvec.size();
    ll w = vvec.at(0).size();
    rep(i,h){
        rep(j,w){
            cout << vvec.at(i).at(j) << " ";
        }
        cout << "\n";
    }
}

int main(){
    ll n ; cin >> n;
    vector<ll> a(3*n);
    rep(i,3*n) cin >> a.at(i);
    sort(a.rbegin(),a.rend());
    ll ans = 0;
    for(int i=0;i<n;i++){
        ans += a.at(2*i+1);        
    }
    cout << ans << endl;
}

Measured memory_bytes: 2560
fn rec(
    x: &Vec<usize>,
    idx: usize,
    sum: usize,
    num: usize,
    memo: &mut HashMap<(usize, usize, usize), usize>,
    a: usize,
) -> usize {
    if memo.contains_key(&(idx, sum, num)) {
        return memo[&(idx, sum, num)];
    }
    let mut res = 0;
    if idx + 1 < x.len() {
        res += rec(x, idx + 1, sum, num, memo, a);
        res += rec(x, idx + 1, sum + x[idx], num + 1, memo, a);
    }
    if sum + x[idx] == (num + 1) * a {
        res += 1;
    }
    memo.insert((idx, sum, num), res);
    res
}
fn main() {
    let (n, a): (usize, usize) = readln();
    let x: Vec<usize> = readln();
    let mut memo = HashMap::new();
    let ans = rec(&x, 0, 0, 0, &mut memo, a);
    println!("{}", ans);
}

// --- template ---
#[allow(unused_imports)]
use std::cmp::{max, min};
#[allow(unused_imports)]
use std::collections::{HashMap, HashSet, VecDeque};

pub trait FromLn {
    fn fromln(s: &str) -> Self;
}
pub fn readln<T: FromLn>() -> T {
    let mut buf = String::new();
    let _ = ::std::io::stdin().read_line(&mut buf).unwrap();
    T::fromln(buf.trim())
}
pub fn readlns<T: FromLn>(n: usize) -> Vec<T> {
    let mut vs = vec![];
    for _ in 0..n {
        vs.push(readln());
    }
    vs
}
macro_rules! fromln_primitives {
    ($($t:ty),*) => { $(
        impl FromLn for $t {
            fn fromln(s: &str) -> $t {
                s.parse().unwrap()
            }
        }
    )* }
}
fromln_primitives!(
    String,
    bool,
    f32,
    f64,
    isize,
    i8,
    i16,
    i32,
    i64,
    usize,
    u8,
    u16,
    u32,
    u64
);
impl<T> FromLn for Vec<T>
where
    T: FromLn,
{
    fn fromln(s: &str) -> Vec<T> {
        s.split_whitespace().map(T::fromln).collect()
    }
}
impl FromLn for Vec<char> {
    fn fromln(s: &str) -> Vec<char> {
        s.chars().collect()
    }
}
macro_rules! fromln_tuple {
    ($($t:ident),*) => {
        impl<$($t),*> FromLn for ($($t),*) where $($t: FromLn),* {
            fn fromln(s: &str) -> ($($t),*) {
                let mut it = s.split_whitespace();
                let t = ($($t::fromln(it.next().unwrap())),*);
                assert_eq!(it.next(), None);
                t
            }
        }
    }
}
fromln_tuple!(A, B);
fromln_tuple!(A, B, C);
fromln_tuple!(A, B, C, D);
fromln_tuple!(A, B, C, D, E);
fromln_tuple!(A, B, C, D, E, F);


Measured memory_bytes: 34572
#define _USE_MATH_DEFINES
#define _CRT_SECURE_NO_DEPRECATE

#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <climits>
#include <cfloat>
#include <ctime>
#include <cassert>
#include <map>
#include <utility>
#include <set>
#include <iostream>
#include <memory>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <sstream>
#include <complex>
#include <stack>
#include <queue>
#include <numeric>
#include <list>
#include <iomanip>
#include <fstream>
#include <iterator>
#include <bitset>

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> Pii;
typedef pair<ll, ll> Pll;

#define FOR(i,n) for(int i = 0; i < (n); i++)
#define sz(c) ((int)(c).size())
#define ten(x) ((int)1e##x)
#define tenll(x) ((ll)1e##x)

int main(){
	int n; cin >> n;
	vector<tuple<int, int, int, int, int>> v;
	FOR(i, n){
		int f, a, t, x, y;
		cin >> f >> a >> t >> x >> y;
		v.emplace_back(f, a, t, x, y);
	}
	double ans[2][2];
	ans[0][0] = ans[0][1] = ans[1][0] = ans[1][1] = -1;
	FOR(i, n - 1){
		int pf, pa, pt, px, py;
		int f, a, t, x, y;
		tie(pf, pa, pt, px, py) = v[i];
		tie(f, a, t, x, y) = v[i+1];
		if (pt == t && a != pa) {
			double nt = sqrt(pow(x - px, 2) + pow(y - py, 2));
			if (ans[t][0] <= nt) {
				if (abs(ans[t][0] - nt) < 1e-6) {
					ans[t][1] = min<double>(ans[t][1], (f - pf) / 60.);
				} else {
					ans[t][1] = (f - pf)/60.;
				}
				ans[t][0] = nt;
			}
		}
	}

	FOR(i, 2) printf("%.10lf %.10lf\n", ans[i][0], ans[i][1]);
}

Measured memory_bytes: 1216
#include<bits/stdc++.h>
#define pb push_back
#define mp make_pair
#define ll long long
using namespace std;

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

    int r=0,g=0,b=0;
    for(int i=0;i<n;i++)
    {
        if(s[i]=='R') r++;
        else if(s[i]=='G') g++;
        else b++;
    }

    ll ways=(ll)r*g*b;
    for(int i=0;i<n;i++)
    {
        for(int j=1;i+2*j<n;j++)
        {
            if(s[i]!=s[i+j] && s[i+j]!=s[i+2*j] && s[i]!=s[i+2*j]) ways--;
        }
    }
    cout<<ways<<endl;
    return 0;
}


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

#define REP(i,n) for(int i=0;i<(int)(n);i++)
#define ALL(x) (x).begin(), (x).end()

typedef long long ll;
typedef long double ld;

const int INF = 1e9;
const ld EPS = 1e-8;

void solve(string s) {
  REP(i, s.length() - 1) {
    if(s[i] == s[i + 1]) {
      cout << i + 1 << " " << i + 2 << endl;
      return;
    }
  }
  REP(i, s.length() - 2) {
    if(s[i] == s[i + 2]) {
      cout << i + 1 << " " << i + 3 << endl;
      return;
    }
  }
  cout << -1 << " " << -1 << endl;
  return;
}

int main(){
  string s;
  cin >> s;
  solve(s);
  return 0;
}



Measured memory_bytes: 512
Z = int(input())

if Z == 0:
  print(0)

else:
  n = (-2)

  ans = ""

  while abs(Z) >= 1:
    r = Z % n
    if r < 0:
      r = r + 2
    Z = int((Z - r) / n)
    ans += str(r)

  ans = "".join(list(reversed(ans)))


  print(int(ans))

Measured memory_bytes: 3060
#include <bits/stdc++.h>
#define ll long long
#define pb push_back
#define mp make_pair
#define mod 1000000007
#define fast ios_base::sync_with_stdio(false); cin.tie(0);cout.tie(0);
#define filein freopen("input.txt","r",stdin)
#define fileout freopen("output.txt","w",stdout)
using namespace std;
int n;
int ara[100009];
int ara1[100009];
int ara2[100009];
int  main()
{
    scanf("%d",&n);
    for(int i=1;i<=n;i++) scanf("%d",ara+i);
    for(int i=1;i<=n;i++) ara1[i]=__gcd(ara1[i-1],ara[i]);
    for(int i=n;i>=1;i--) ara2[i]=__gcd(ara2[i+1],ara[i]);
    int ans=0;
    for(int i=1;i<=n;i++)
    {
        ans=max(ans,__gcd(ara1[i-1],ara2[i+1]));
    }
    printf("%d\n",ans);
}


Measured memory_bytes: 1408
// B.cpp : このファイルには 'main' 関数が含まれています。プログラム実行の開始と終了がそこで行われます。
//

#include <iostream>
using namespace std;
int main()
{
    int n, m, x, y;

    cin >> n >> m >> x >> y;

    int xmax = x;
    int ymin = y;

    for (int i = 0; i < n; i++) {
        int a;
        cin >> a;
        if (xmax < a) {
            xmax = a;
        }
    }

    for (int i = 0; i < m; i++) {
        int b;
        cin >> b;
        if (ymin > b) {
            ymin = b;
        }
    }

    if (xmax < ymin) {
        cout << "No War" << endl;
    }
    else {
        cout << "War" << endl;
    }
}



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

#define M_PI 3.141592653589793

int main(void) {

	int i, j;
	int n;
	long a[10000];
	long max, min, sum = 0;

	scanf("%d", &n);

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

	max = min = a[0];
	for (i = 0; i < n; i++) {
		sum += a[i];
		if (a[i] > max)		max = a[i];
		if (a[i] < min)		min = a[i];
	}

	printf("%ld %ld %ld\n", min, max, sum);


	return 0;
}

Measured memory_bytes: 2772
#include<bits/stdc++.h>
#include<string>
using namespace std;
int main()
{
	string a;
	cin>>a;
	int i,len,c=0;
	for(i=0; i<4; i++)
    {
        if(a[i]=='+'){c++;}
        else{c--;}
    }
    cout<<c;
}

Measured memory_bytes: 3536
#include <stdio.h>
#include <stdint.h>

#define STR_MAX    (100000)

int main(void)
{
    uint64_t n;
    uint64_t k;
    char s[STR_MAX+1];

    scanf("%ld %ld", &n, &k);
    scanf("%s", s);

    uint64_t ptr = 0;
    char curC;
    char nxtC;

    uint64_t serialNum[STR_MAX+2];
    uint64_t indx   = 0;
    uint64_t head1  = 0;
    uint64_t max    = 0;
    uint64_t cntK   = 0;
    uint64_t curSum = 0;

    curC = s[ptr++];
    /* serialNumは 1 の数 -> 0の数としたいので0ならindxを送る */
    if ( curC == '0' ) {
        indx++;
    }

    do {
        /* nxtCを得る */
        nxtC = s[ptr++];

        serialNum[indx]++;

        uint64_t dbgIndx = indx;

        /* どうやら次は別の文字のようだ */
        if ( curC !=  nxtC ) {
            curSum += serialNum[indx++];

            /* 0の連続が終わったときは昔の0を捨てる場合がある */
            if ( curC == '0' ) {
                /* 逆立ちできる人たちが増える */
                cntK++;

                /* 逆立ちできる人たちがK人より多いとき */
                if ( cntK > k ) {
                    /* 
                     * 1Grp -> 0Grp -> 1Grp -> 0Grp ... 1Grp -> NEW 0Grp
                     * となるので先頭の0Grpと1Grp分を引いて, 0Grpのheadを移動させる
                     */
                    curSum -= (serialNum[head1] + serialNum[head1+1]);
                    head1 += 2;
                }
            }

            /* ここまでで今回のserialNumによるcurSumが決定するので最大値更新 */
            max = ( curSum >= max ) ? curSum : max;
        }

//        printf("%c : cntK=%ld, curSum=%ld, serialNum=%ld, head1=%ld, max=%ld\n", curC, cntK, curSum, serialNum[dbgIndx], head1, max);

        curC = nxtC;
    } while ( curC != '\0' );

    printf("%ld\n", max);

    return 0;
}



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

int main(){
  int a,b,c,ans;
  cin >> a >> b >> c;
  ans = 0;
  for(int i = 0;i < c;i++){
    if(b - a >= 0){
      b -= a;
      ans++;
    }else{
      break;
    }
  }
  cout << ans << endl;
  
  return 0;
}

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

using namespace std;

int main(){

	int dp[31];
	fill(dp,dp+31,0);
	dp[0]=1;
	for(int i = 1; i <= 30; i++){
		for(int j = 1; j <= 3; j++){
			if(i-j>=0)
				dp[i] += dp[i-j];
		}
	}

	int n;
	while(cin>>n&&n!=0){
		int t = (dp[n]-1)/3650;
		t++;
		cout<<t<<endl;
	}

	return 0;
}

Measured memory_bytes: 0
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define REP(i,n) FOR(i,0,n)
#define ALL(v) (v).begin(),(v).end()
#define fi first
#define se second
template<typename A, typename B> inline bool chmax(A &a, B b) { if (a<b) { a=b; return 1; } return 0; }
template<typename A, typename B> inline bool chmin(A &a, B b) { if (a>b) { a=b; return 1; } return 0; }
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<int, pii> pip;
typedef pair<pll, pll> P;
const ll INF = 1ll<<60;
const ll MOD = 1000000007;
const double EPS = 1e-9;
const bool debug = 0;
//---------------------------------//

int n, m, s, t;
vector<pii> g[2][112345]; // 0:yen, 1:snuuk
ll dist[2][112345];
ll ans[112345];

void dijkstra(int st, int mode) {
	fill(dist[mode], dist[mode + 1], INF);
	
	priority_queue<pll, vector<pll>, greater<pll> > pq; // cost, pos
	pq.push(pll(0, st));
	dist[mode][st] = 0;
	while (!pq.empty()) {
		pll cur = pq.top(); pq.pop();
		int curpos = cur.se;
		ll curcost = cur.fi;
		
		if (dist[mode][curpos] < curcost) continue;
		
		REP(i, g[mode][curpos].size()) {
			int nextpos = g[mode][curpos][i].fi;
			ll nextcost = curcost + g[mode][curpos][i].se;
			
			if (chmin(dist[mode][nextpos], nextcost)) {
				pq.push(pll(nextcost, nextpos));
			}
		}
	}
}

int main() {
	cin >> n >> m >> s >> t;
	s--; t--;
	REP(i, m) {
		int u, v, a, b;
		scanf("%d %d %d %d", &u, &v, &a, &b);
		u--; v--;
		g[0][u].push_back(pii(v, a));
		g[0][v].push_back(pii(u, a));
		g[1][u].push_back(pii(v, b));
		g[1][v].push_back(pii(u, b));
	}
	
	dijkstra(s, 0);
	dijkstra(t, 1);
	
	ll prmx = 0;
	for (int i = n - 1; i >= 0; i--) {
		ll cur = 1e15;
		cur -= dist[0][i];
		cur -= dist[1][i];
		chmax(prmx, cur);
		ans[i] = prmx;
	}
	
	REP(i, n) printf("%lld\n", ans[i]);
	
	return 0;
}


Measured memory_bytes: 17020
s=input()
l=[0 for _ in range(len(s))]
st=0
ep=0

for i in range(1,len(s)):
  if s[i-1]=="R" and s[i]=="L":#最終地点
    ep=i
    #print(l,"ep",i)
  if (s[i-1]=="L" and s[i]=="R"):#区間終わり
    if (i-st)%2==0:#要素数が偶数なら半分ずつ
      l[ep]=(i-st)//2
      l[ep-1]=(i-st)//2
    elif (ep-st)%2==0:
      l[ep]=(i-st+1)//2
      l[ep-1]=(i-st-1)//2
    else:
      l[ep]=(i-st-1)//2
      l[ep-1]=(i-st+1)//2
      #print(l,"st",i)
    st=i
i=len(s)
if (i-st)%2==0:#要素数が偶数なら半分ずつ
    l[ep]=(i-st)//2
    l[ep-1]=(i-st)//2
elif (ep-st)%2==0:
    l[ep]=(i-st+1)//2
    l[ep-1]=(i-st-1)//2
else:
    l[ep]=(i-st-1)//2
    l[ep-1]=(i-st+1)//2
   # print(l,"st",i)
print(*l)
    
    
    
  

Measured memory_bytes: 10828
#include <bits/stdc++.h>
using namespace std;
#define REP(i,n) for (int i=0;i<(n);i++)
//#define int long long  
int main(){
    int Ans=0;
    string S;
    cin >> S;
    REP(i,S.size()-1){
        if(S[i]!=S[i+1]){
            Ans++;
        }
    }
    cout << Ans << endl;
	return 0;
}

Measured memory_bytes: 512
// INCLUDES
#include <bits/stdc++.h>
#include<assert.h>
#include <ext/pb_ds/assoc_container.hpp> 
#include <ext/pb_ds/tree_policy.hpp>
//DEFINES
#define MAX 1000001
#define pii pair<int, int>
#define F first
#define S second
#define all(s) begin(s),end(s)
#define MIN3POS(a, b, c) (a) =< (b) ? ((a) =< (c) ? 1 : 3) : ((b) =< (c) ? 2 : 3)
#define MAX3POS(a,b,c) (a) >= (b) ? ((a) >= (c) ? 1 : 3) : ((b) >= (c) ? 2:3)
#define endl '\n'
#define int long long
#define ordered_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update>
#define FOR(i, begin, end) for (__typeof(end) i = (begin) - ((begin) > (end)); i != (end) - ((begin) > (end)); i += 1 - 2 * ((begin) > (end)))
#define IOS   ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define error(args...) { string _s = #args; replace(_s.begin(), _s.end(), ',', ' '); stringstream _ss(_s); istream_iterator<string> _it(_ss); err(_it, args);}
//NAMESPACES
using namespace __gnu_pbds; 
using namespace std;
vector<string> vec_splitter(string s) {
    s += ',';
    vector<string> res;
    while(!s.empty()) {
        res.push_back(s.substr(0, s.find(',')));
        s = s.substr(s.find(',') + 1);
    }
    return res;
}
void debug_out(
vector<string> __attribute__ ((unused)) args,
__attribute__ ((unused)) int idx, 
__attribute__ ((unused)) int LINE_NUM) { cerr << endl; } 
template <typename Head, typename... Tail>
void debug_out(vector<string> args, int idx, int LINE_NUM, Head H, Tail... T) {
    if(idx > 0) cerr << ", "; else cerr << "Line(" << LINE_NUM << ") ";
    stringstream ss; ss << H;
    cerr << args[idx] << " = " << ss.str();
    debug_out(args, idx + 1, LINE_NUM, T...);
}
#ifdef XOX
#define debug(...) debug_out(vec_splitter(#__VA_ARGS__), 0, __LINE__, __VA_ARGS__)
#else
#define debug(...) 42
#endif
//HELPERS

vector<int> powers2(32,0);void initialize(){ for(int i=1;i<powers2.size();i++) powers2[i] = powers2[i-1]*2;}
int32_t main()
{
IOS
int k;
cin>>k;
string s;
cin>>s;
if(s.size() <=k ) cout<<s;
else {
    for(int i=0;i<k;i++) cout<<s[i];
    cout<<"...";
} 
return 0;
}
// Use emplace back in place of pushback
// Use tie function , for object destructuring

Measured memory_bytes: 3640
import java.util.ArrayList;
import java.util.Comparator;
import java.util.List;
import java.util.Scanner;
import java.util.stream.Collectors;

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

        List<Route> routes = new ArrayList<>();
        for (int i = 0; i < n; i++) {
            routes.add(new Route(sc.nextInt(), sc.nextInt()));
        }

        List<Route> sorted = routes.stream()
                .sorted(Comparator.comparing(Route::getCost))
                .collect(Collectors.toList());

        for (int i = 0; i < n; i++) {
            if (sorted.get(i).getTime() <= t) {
                System.out.println(sorted.get(i).getCost());
                return;
            }
        }
        System.out.println("TLE");
    }

    static class Route {
        int cost;
        int time;

        public Route(int cost, int time) {
            this.cost = cost;
            this.time = time;
        }

        public int getCost() {
            return cost;
        }

        public int getTime() {
            return time;
        }
    }
}


Measured memory_bytes: 32868
#include <iostream>
#include <algorithm>
#include <map>
#include <vector>
using namespace std;
 
typedef pair<int, int> P;
 
const int MAX_S = 51;
const int dx[4] = {1,0,-1,0};
const int dy[4] = {0,1,0,-1};
int H, W;
char G[MAX_S][MAX_S];
bool vis[MAX_S][MAX_S];
 
void show() {
  for(int i = 0; i < H; ++i) {
    for(int j = 0; j < W; ++j) {
      cout << G[i][j];
    }
    cout << endl;
  }
}
 
pair<P, P> rec(int x, int y, char c) {
  vis[y][x] = true;
  pair<P, P> p = make_pair(P(x, y), P(x, y));
  for(int i = 0; i < 4; ++i) {
    int nx = x + dx[i];
    int ny = y + dy[i];
    if(nx < 0 || nx >= W) continue;
    if(ny < 0 || ny >= H) continue;
    if(vis[ny][nx]) continue;
    if(G[ny][nx] != c) continue;
    pair<P, P> q = rec(nx, ny, c);
    p.first.first = min(p.first.first, q.first.first);
    p.first.second = min(p.first.second, q.first.second);
    p.second.first = max(p.second.first, q.second.first);
    p.second.second = max(p.second.second, q.second.second);
  }
  return p;
}
 
void make(map<char, pair<P, P> > &m) {
  for(int i = 0; i < H; ++i) fill(vis[i], vis[i]+W, false);
 
  for(int i = 0; i < H; ++i) {
    for(int j = 0; j < W; ++j) {
      if(!vis[i][j] && G[i][j] != '.') {
        pair<P, P> q = rec(j, i, G[i][j]);
        //v.push_back(q);
        if(m.find(G[i][j]) == m.end()) {
          m[G[i][j]] = q;
        } else {
          pair<P, P> &p = m[G[i][j]];
          p.first.first = min(p.first.first, q.first.first);
          p.first.second = min(p.first.second, q.first.second);
          p.second.first = max(p.second.first, q.second.first);
          p.second.second = max(p.second.second, q.second.second);
        }
      }
    }
  }
}
 
bool isShikaku(int sx, int sy, int ex, int ey) {
  char c = 0;
  for(int i = sy; i <= ey; ++i) {
    for(int j = sx; j <= ex; ++j) {
      if(G[i][j] == '.') return false;
      if(c == 0) {
        if(G[i][j] != '#') c = G[i][j];
      } else if(G[i][j] != c && G[i][j] != '#') {
        return false;
      }
    }
  }
  return true;
}
 
void fills(int sx, int sy, int ex, int ey) {
  for(int i = sy; i <= ey; ++i) {
    for(int j = sx; j <= ex; ++j) {
      G[i][j] = '#';
    }
  }
}
 
bool ans() {
  vector<pair<P, P> > v;
  map<char, pair<P, P > > m;
  make(m);
  v.clear();
  for(map<char, pair<P, P> >::iterator it = m.begin(); it != m.end(); ++it) {
    v.push_back(it->second);
  }
  for(;;) {
    bool flag = true;
    for(vector<pair<P, P> >::iterator it = v.begin(); it != v.end();) {
      pair<P, P> p = *it;
      if(isShikaku(p.first.first, p.first.second,
                   p.second.first, p.second.second)) {
 
        fills(p.first.first, p.first.second,
              p.second.first, p.second.second);
 
        it = v.erase(it);
        flag = false;
      } else {
        ++it;
      }
    }
    if(flag) return v.size() == 0;
  }
}
 
int main() {
  int T;
  cin >> T;
  while(T--) {
    cin >> H >> W;
    for(int i = 0; i < H; ++i) {
      for(int j = 0; j < W; ++j) {
        cin >> G[i][j];
      }
    }
    if(ans()) cout << "SAFE" << endl;
    else cout << "SUSPICIOUS" << endl;
    //show();
  }
  return 0;
}

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

struct node{
  struct node *right;
  struct node *left;
  struct node *p;
  int key;
};
typedef struct node * Node;

#define NIL NULL

Node root;


Node treeMinimum(Node x){
  while(x->left != NIL) x = x->left;
  return x;
}
/*
Node treeMaximum(Node x){


}
*/


Node treeSuccessor(Node x){
  if(x->right != NIL) return treeMinimum(x->right);
  Node y = x->p;
  while(y != NIL && x == y->right){
    x = y;
    y = y->p;
  }
  return y;
}

void treeDelete(Node z){
  Node y;//対象
  Node x;//Yの子

  if(z->left == NIL || z->right == NIL) y = z;
  else y = treeSuccessor(z);

  if(y->left != NIL){
    x = y->left;
  }else{
    x = y->right;
  }

  if(x != NIL){
    x->p = y->p;
  }

  if(y->p == NIL){
    root = x;
  }else{
    if(y == y->p->left){
      y->p->left = x;
    }else{
      y->p->right = x;
    }
  }

  if(y != z){
    z->key = y->key;
  }
  free(y);
}

Node treeSearch(Node u, int k){
  while(u != NIL && k != u->key){
    if(k < u->key)
      u = u->left;
    else
      u = u->right;
  }
  return u;
}

void insert(int k){
  Node y = NIL;
  Node x = root;
  Node z;

  z = malloc(sizeof(struct node));
  z->key = k;
  z->left = NIL;
  z->right = NIL;

  while(x != NIL){
    y = x;
    if(z->key < x->key)
      x = x->left;
    else
      x = x->right;
  }
  z->p = y;
  
  if(y == NIL){
    root = z;
  }else if(z->key < y->key){
    y->left = z;
  }else{
    y->right = z;
  }
}

void inorder(Node u){
  if(u == NIL)return;
  inorder(u->left);
  printf(" %d", u->key);
  inorder(u->right);
}
void preorder(Node u){
  if(u == NIL)return;
  printf(" %d", u->key);
  preorder(u->left);
  preorder(u->right);
}


int main(){
  int n, i, x;
  char com[20];
  scanf("%d", &n);
  
  for ( i = 0; i < n; i++ ){
    scanf("%s", com);
    if ( com[0] == 'f' ){
      scanf("%d", &x);
      Node t = treeSearch(root, x);
      if ( t != NIL ) printf("yes\n");
      else printf("no\n");
    } else  if ( com[0] == 'i' ){
      scanf("%d", &x);
      insert(x);
    } else if ( com[0] == 'p' ){
      inorder(root);
      printf("\n");
      preorder(root);
      printf("\n");
    } else if ( com[0] == 'd'){
      scanf("%d", &x);
      treeDelete(treeSearch(root, x));
    }
  }

  return 0;
}



Measured memory_bytes: 20532
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define ll long long
#define sz(a) (int)(a.size())
#define pb push_back
#define all(c) c.begin(),c.end()
#define tr(it,a,c) for(auto it=c.begin()+a;it!=c.end();it++)
#define fr(i,a,n)   for(int i=a;i<n;i++)
#define present(c,x) (c.find(x)!=c.end()) //for set/map etc.
#define cpresent(c,x) (find(all(c),x)!=c.end())
typedef pair<int,int> pi;
typedef vector<int> vi;
typedef vector<vector<int>> vvi;
typedef vector<long long> vll;
typedef vector<pair<int,int>> vp;
int N=100001;
int mod=1e9+7;


int min(int a,int b){if(a<b) return a; else return b;}
int max(int a,int b){if(a>b) return a; else return b;}
int power(int a,int b){int res=1;a%=mod; assert(b>=0); for(;b;b>>=1){if(b&1)res=res*a%mod;a=a*a%mod;}return res;}
int gcd(int p, int q){if(p%q==0) return q; else{return gcd(q,p%q);}} 
bool comp(int a, int b) 
{ 
    return (a > b); 
}

bool comp1(pi a, pi b)
{
    if(a.first==b.first)return a.second<b.second;
    else return a.first>b.first;
}

template<typename T> 
istream& operator>>(istream& in, vector<T>& v)
{
    for (T& x : v) in >> x; return in;
}

template<typename T> 
ostream& operator<<(ostream& out, vector<T>& v)
{
    for (T& x : v) out << x<<" "; return out;
}

// template<typename T>
int sum1(vector<int>& v)
{
    int sum=0;
    // for(auto x: v)sum+=x;
    fr(i,0,v.size())sum+=v[i];
    return sum;
}





 void solve()
{
    int n;
    cin>>n;
    int a = 0;
    int ans=0;
    // cin>>x>>y;
    int x,y;
    fr(i,0,n)
    {
        cin>>x>>y;
        if(x==y)
        {
            a++;
        }
        else
        {
            ans = max(ans,a);
            a=0;

        }
    }
    ans = max(ans,a);
    if(ans>=3)cout<<"Yes";
    else cout<<"No";
}

signed main()
{
    // #ifndef ONLINE_JUDGE
    // freopen("input.txt","r",stdin);
    // freopen("output.txt","w",stdout);
    // #endif
    ios::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    // int t;
    // cin>>t;
    // while(t--)
    // {
    //     solve();
    //     cout<<endl;
    // }
    solve();
    return 0;   
}   

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

long long m[] = {2, 3, 5};
long long cst[3], d;
map<long long, long long> dp;

long long go(long long n) {
	if (n == 0) return 0;
	if (n == 1) return d;
	if (dp.find(n) != dp.end()) return dp[n];

	long long ans = 1e18;
	long long nxt, tmp;

	for (int i = 0; i < 3; i++) {
		nxt = n, tmp = 0;
		while (nxt % m[i]) {nxt--; tmp += d;}	
		ans = min(ans, tmp + min(cst[i], d*min(1000000000LL, nxt - (nxt/m[i]))) + go(nxt/m[i]));

		nxt = n, tmp = 0;
		while (nxt % m[i]) {nxt++; tmp += d;}	
		ans = min(ans, tmp + min(cst[i], d*min(1000000000LL, nxt - (nxt/m[i]))) + go(nxt/m[i]));
	}
	
	return dp[n] = ans;
}

void solve() {
	long long n;
	cin >> n >> cst[0] >> cst[1] >> cst[2] >> d;

	dp.clear();
	cout << go(n) << '\n';
}

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

	int t; cin >> t;
	while (t--) {
		solve();
	}

	return 0;
}


Measured memory_bytes: 4344