akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <vector>

bool tonari(int i, int j, int h, int w, std::vector<std::vector<char> > s)
{
    if (i != 0) {
        if (s[i - 1][j] == '#') {
            return true;
        }
    }
    if (i != h - 1) {
        if (s[i + 1][j] == '#') {
            return true;
        }
    }
    if (j != 0) {
        if (s[i][j - 1] == '#') {
            return true;
        }
    }
    if (j != w - 1) {
        if (s[i][j + 1] == '#') {
            return true;
        }
    }
    return false;
}

bool hantei(int h, int w, std::vector<std::vector<char> > s)
{
    for (int i = 0; i < h; i++) {
        for (int j = 0; j < w; j++) {
            if (s[i][j] == '#') {
                if (not tonari(i, j, h, w, s)) {
                    return false;
                }
            }
        }
    }
    return true;
}

int main(int argc, char const* argv[])
{
    int h, w;
    bool flag;
    std::cin >> h >> w;
    std::vector<std::vector<char> > s(h, std::vector<char>(w));
    for (int i = 0; i < h; i++) {
        for (int j = 0; j < w; j++) {
            std::cin >> s[i][j];
        }
    }
    if (hantei(h, w, s)) {
        std::cout << "Yes";
    } else {
        std::cout << "No";
    }
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  
  int N;
  int K = 0;
  cin >> N;
  int Na = N;
  
  while (Na > 0){
    Na /= 10;
    K++;    //桁を出す
  }
  int Hn = 0;
  int Z = 1;
  for (int i = 0; i < K; i++){
    Z *= 10;
    Hn += (N % Z) / (Z / 10);
  }
  if (0 == N % Hn){
    cout << "Yes" << endl;
  }
  else {
    cout << "No" << endl;
  }
}

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

const ll INF = 1e16;

struct edge {
    ll from, to, cost;
};
vector<edge> es;

ll d[3000];
ll V, E;

// 頂点sからの最小距離(sに影響する負閉路があるかを返す)
bool BellmanFord(ll s) {
    for (int i = 0; i < V; i++) d[i] = INF;
    d[s] = 0;
    for (int i = 0; i < V - 1; i++) {
        for (int j = 0; j < E; j++) {
            edge e = es[j];
            if (d[e.from] != INF && d[e.to] > d[e.from] + e.cost) {
                d[e.to] = d[e.from] + e.cost;
            }
        }
    }
    for (int i = 0; i < V; i++) {
        for (int j = 0; j < E; j++) {
            edge e = es[j];
            if (d[e.from] != INF && d[e.to] > d[e.from] + e.cost) {
                d[e.to] = -INF;
            }
        }
    }
    return 1;
}

int main() {
    ll P;
    cin >> V >> E >> P;
    for (int i = 0; i < E; i++) {
        ll a, b, c;
        cin >> a >> b >> c;
        a--, b--;
        c = -(c - P);
        es.push_back({a, b, c});
    }
    BellmanFord(0);
    int t = V - 1;
    if (d[t] <= -INF)
        cout << -1 << endl;
    else
        cout << max(-d[t], 0ll) << endl;
    return 0;
}

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

int main(){
  string button, ans;
  string b[] = {"","',.!?","abcABC","defDEF","ghiGHI","jklJKL","mnoMNO","pqrsPQRS","tuvTUV","wxyzWXYZ"};
  int cnt=0;

  while(cin >> button){
    ans = "";
    for(int i = 0 ; i < button.size() ; i++){
      cnt++;
      if(button[i] != button[i+1]){
	if(button[i] != '0'){
	  ans += b[button[i]-'0'][cnt-1];
	  cnt = 0;
	}
	else{
	  for(int j = 0 ; j < cnt-1 ; j++ ) ans += ' ';
	  cnt = 0;
	}
      }
    }
    cout << ans << endl;
  }
  return 0;
}

Measured memory_bytes: 0
#include <stdio.h>

#define ll long long

int main(int argc, char *argv[]) {
	int N;
	scanf("%d", &N);
	int A[81];
	for (int i = 0; i < N; i++) {
		scanf("%d", &A[i]);
	}
	A[N] = 100;

	ll money = 1000;
	for (int i = 0; i < N; i++) {
		if (A[i] < A[i + 1]) {
			ll stock = money / A[i];
			money += (A[i + 1] - A[i]) * stock;
		}
	}

	printf("%lld\n", money);
	return 0;
}


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

using namespace std;

typedef long long ll;
const ll INF = 1LL<<60;

ll gcd(ll a, ll b) {
  if(b == 0) return a;
  return gcd(b, a % b);
}

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

ll modpow(ll a, ll n, ll mod) {
  ll res = 1;
  while (n > 0) {
    if (n & 1) res = res * a % mod;
    a = a * a % mod;
    n >>= 1;
  }
  return res;
}

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

  string S;
  cin >> S;

  int N = S.length();
  S = S + "+";

  int cnt = 0;
  vector<int> cnt_vec;
  for(int i = 0; i < N; i++){
    cnt++;
    if(S[i] != S[i+1]){
      cnt_vec.push_back(cnt);
      cnt = 0;
    }
  }

  int ans = 1e7;
  if(cnt_vec.size() == 1){
    ans = cnt_vec[0];
  }else if(cnt_vec.size() == 2){
    ans = max(cnt_vec[0], cnt_vec[1]);
  }else{
    int tmp = 0;
    for(int i = 0; i < cnt_vec.size(); i++){
      tmp += cnt_vec[i];
      chmin(ans, max(tmp, N-tmp));
    }
  }

  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 748
// +build ignore
package main

import (
	"bufio"
	"fmt"
	"io"
	"os"
	"strconv"
)

// I/O
type Scanner struct {
	sc *bufio.Scanner
}

func NewScanner() *Scanner {
	sc := bufio.NewScanner(os.Stdin)
	sc.Split(bufio.ScanWords)
	sc.Buffer(make([]byte, 1024), int(1e+9))
	return &Scanner{sc}
}

func (s *Scanner) nextStr() string {
	s.sc.Scan()
	return s.sc.Text()
}

func (s *Scanner) nextInt() int {
	i, e := strconv.Atoi(s.nextStr())
	if e != nil {
		panic(e)
	}
	return i
}

func (s *Scanner) nextFloat() float64 {
	f, e := strconv.ParseFloat(s.nextStr(), 64)
	if e != nil {
		panic(e)
	}
	return f
}

func (s *Scanner) nextRuneSlice() []byte {
	return []byte(s.nextStr())
}

func (s *Scanner) nextIntSlice(n int) []int {
	res := make([]int, n)
	for i := 0; i < n; i++ {
		res[i] = s.nextInt()
	}
	return res
}

func (s *Scanner) nextFloatSlice(n int) []float64 {
	res := make([]float64, n)
	for i := 0; i < n; i++ {
		res[i] = s.nextFloat()
	}
	return res
}

func gcd(x, y int) int {
	if x%y != 0 {
		return gcd(y, x%y)
	}
	return y
}

func run(input io.Reader, output io.Writer) int {
	sc := NewScanner()
	N := sc.nextInt()

	switch N % 10 {
	case 2, 4, 5, 7, 9:
		fmt.Println("hon")
	case 0, 1, 6, 8:
		fmt.Println("pon")
	default:
		fmt.Println("bon")
	}

	return 0
}

func main() {
	os.Exit(run(os.Stdin, os.Stdout))
}


Measured memory_bytes: 1756
#include <bits/stdc++.h>
using namespace std;
int a,b;
int main()
{
	ios::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	cin>>a>>b;
	b=b*2+1;
	if (a%b==0) cout<<a/b;
	else cout<<a/b+1;
	return 0;
}

Measured memory_bytes: 384
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<queue>
#include<map>
#include<math.h>
#include<iomanip>
#include<set>
#include<numeric>
#include<cstring>
#include<cstdio>
#include<functional>

#define REP(i, n) for(int i = 0;i < n;i++)
#define REPR(i, n) for(int i = n;i >= 0;i--)
#define FOR(i, m, n) for(int i = m;i < n;i++)
#define FORR(i, m, n) for(int i = m;i >= n;i--)
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
#define REVERSE(v,n) reverse(v,v+n);
#define VREVERSE(v) reverse(v.begin(), v.end());
#define ll long long
#define pb(a) push_back(a)
#define INF 9999999999
#define m0(x) memset(x,0,sizeof(x))
#define fill(x,y) memset(x,y,sizeof(x))
#define p(x) cout<<x<<endl;
#define pe(x) cout<<x<<" ";
//#define int long long


using namespace std;


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




ll gcd(ll x, ll y) {
	ll m = max(x, y), n = min(x, y);
	if (m%n == 0)return n;
	else return gcd(m%n, n);
}
ll lcm(ll x, ll y) {
	return x / gcd(x, y)*y;
}

ll myPow(ll x, ll n, ll m) {
	if (n == 0)
		return 1;
	if (n % 2 == 0)
		return myPow(x * x % m, n / 2, m);
	else
		return x * myPow(x, n - 1, m) % m;
}

ll pow2(ll a, ll n) {//aのn乗を計算します。
	ll x = 1;
	while (n > 0) {//全てのbitが捨てられるまで。
		if (n & 1) {//1番右のbitが1のとき。
			x = x * a;
		}
		a = a * a;
		n >>= 1;//bit全体を右に1つシフトして一番右を捨てる。
	}
	return x;
}

long long nCr(int n, int r) {
	if (r > n / 2) r = n - r; // because C(n, r) == C(n, n - r)
	long long ans = 1;
	int i;

	for (i = 1; i <= r; i++) {
		ans *= n - r + i;
		ans /= i;
	}

	return ans;
}


const int MOD = 1000000007;

bool arr[1050000];
int sosuu[100010];
void Eratosthenes() {
	ll N = 1050000;
	int c = 0;
	for (int i = 0; i < N; i++) {
		arr[i] = 1;
	}
	for (int i = 2; i < sqrt(N); i++) {
		if (arr[i]) {
			for (int j = 0; i * (j + 2) < N; j++) {
				arr[i *(j + 2)] = 0;
			}
		}
	}

	for (int i = 2; i < N; i++) {
		if (arr[i]) {
			sosuu[c] = i;
			//cout << sosuu[c] << " ";
			c++;
		}
	}
	//cout << endl;
	//cout << c << endl;
}

int a[3010];
int main() {
	int N;
	cin>>N;
	ll Lcm=1;
	ll ans=0;
	REP(i,N){
		cin>>a[i];
		ans+=a[i]-1;
	}
	p(ans);
}


Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <algorithm>
#include <numeric>
#include <cmath>
#include <vector>
#include <list>
#include <stack>
#include <queue>
#include <deque>
#include <set>
#include <map>
#include <tuple>
#include <cstring>
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
#define rep(i, n) for(int i=0; i<n; i++)
#define reps(i, s, e) for(int i=s; i<e; i++)
#define repr(i, n) for(int i=n-1; i>=0; i--)
#define reprs(i, s, e) for(int i=e-1; i>=s; i--)

int main(){

    string s; cin >> s;

    if(s == "Sunny"){
        cout << "Cloudy";
    }
    else if(s == "Cloudy"){
        cout << "Rainy";
    }
    else if(s == "Rainy"){
        cout << "Sunny";
    }

    return 0;
}

Measured memory_bytes: 256
import java.util.*;

public class Main {
    public static void main(String args[]) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int[] candidates = new int[9];
        candidates[0] = 111;
        candidates[1] = 222;
        candidates[2] = 333;
        candidates[3] = 444;
        candidates[4] = 555;
        candidates[5] = 666;
        candidates[6] = 777;
        candidates[7] = 888;
        candidates[8] = 999;
        for(int i = 0; i < candidates.length; i++) {
            if(candidates[i] >= n) {
                System.out.println(candidates[i]);
                return;
            }
        }
    }
}

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

int main() {
  int n, k;
  cin >> n >> k;
  
  int ans = 1;
  while(n >= k) {
    n /= k;
    ++ans;
  }
  
  cout << ans << endl;
  
  return 0;
}


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

int main(){
  int x_1;
  double a, b, x_2;
  cin >> a >> b;
  x_1 = (a + b) / 2;
  x_2 = (a + b) / 2;
  if (x_1 == x_2){
    cout << x_1 << endl;
  }else{
    cout << x_1 + 1 << endl;
  }
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main(){
int n, d;
  cin>>n>>d;
  int s = 2*d+1;
  int ans = (int)n/s;
  if(n%s!=0){
  ans+=1;
  }
  cout<<ans<<endl;
  return 0;
}

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

#define ll long long
#define vi vector<int>
#define vl vector<ll>
#define pii pair<int,int>
#define pll pair<ll,ll>
// pll pp; -> (pp.first,pp.second)
// vector<vl> pp(n,vl(2)); sort(pp.begin(),pp.end(),[](vl a,vl b){return a[0]<b[0];});

#define REP(i,n) for(ll (i)=0;(i)<(n);(i)++)
#define RREP(i,n) for(ll (i)=(n)-1;(i)>=0;(i)--)
#define FOR(i,a,b) for(ll (i)=(a);(i)<(b);(i)++)
#define FORR(i,a,b) for(ll (i)=(b)-1;(i)>=(a);(i)--)
#define DEBUG(x) cout << #x << ": " << x << endl
#define CHMAX(a,b) a=max((a),(b))
#define CHMIN(a,b) a=min((a),(b))
/*}}}*/
int main() {
  ll n;
  cin >> n;
  string s,t;
  cin >> s >> t;
  REP(i,n){
    bool fit = true;
    REP(j,n-i){
      if(s[i+j]!=t[j]){
        fit = false;
        break;
      }
    }
    if(fit){
      cout << i+n << endl;
      return 0;
    }
  }
  cout << 2*n << endl;
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define endl '\n'
using namespace std;


int main() {
	ios::sync_with_stdio(0);
	cin.tie(0);
	int t;
	string k;
	cin>>t>>k;
	if ((int)k.size()<=t){
		cout<<k<<endl;
	}
	else{
		for(int i=0;i<t;i++){
			cout<<k[i];
		}
		cout<<"...\n";
	}
	return 0;

}


Measured memory_bytes: 3612
#include <iostream>
#include <vector>
#include <math.h>
#define REP(i,n) for(int i=0;i<n;i++)
#define REP2(i,s,e) for(int i=s;i<e;i++)
using namespace std;

unsigned euclidean_gcd(unsigned a, unsigned b) {
  while(1) {
    if(a < b) swap(a, b);
    if(!b) break;
    a %= b;
  }
  return a;
}

int main() {
	long a,b,c,d;
    cin >> a;
    cin >> b;
    cin >> c;
    cin >> d;
  	
  	if(c==1 || d==1){
    	cout << 0 << endl;
      	return 0;
    }
  	if(a==b){
      	if(a%c==0 || a%d==0){
    		cout << 0 << endl;
        }else{
        	cout << 1 << endl;
        }
      	return 0;
    }

    long cnt1 = ((b)/c) - ((a-1)/c);
    long cnt2 = ((b)/d) - ((a-1)/d);

    long e = c * d / euclidean_gcd(c, d);
    long cnt3 = ((b)/e) - ((a-1)/e);

	cout << b-a+1 - (cnt1+cnt2 - cnt3) << endl;
    return 0;
}

Measured memory_bytes: 256
s = int(input())#入力した数値
t = int(s % 10)#10で割ったあまり＝n桁目の数
u = int(s / 10)#10で割ったもの
while True:
    if t == 7:
        print("Yes")
        break
    elif u == 0:
        print("No")
        break
    t = int(u % 10)
    u = int(u / 10)


Measured memory_bytes: 9112
#include<iostream>
#include<string>
#include<vector>
#include<iomanip>
#include<map>
using namespace std;
#define ll long long
int main(){
  int A,B,C;
  cin >> A >> B >>C;
  if(A+B<C){
    cout << "No";
  }else{
    cout << "Yes";
  }
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int x[3];
int main()
{
ios_base::sync_with_stdio(0);
int m1,m2,d1,d2;
cin>>m1>>d1>>m2>>d2;
if(d2==1)
{
    cout<<1;
}
else
    cout<<0;
 return 0;
}


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

#define REP(i,n) for(long long i = 0; i < (n); i++)
#define FOR(i, m, n) for(long long i = (m);i < (n); ++i)
#define ALL(obj) (obj).begin(),(obj).end()
#define SPEED cin.tie(0);ios::sync_with_stdio(false);

template<class T> using V = vector<T>;
template<class T, class U> using P = pair<T, U>;
template<class T> using PQ = priority_queue<T>;
template<class T> using PQR = priority_queue<T,vector<T>,greater<T>>;

constexpr long long MOD = (long long)1e9 + 7;
constexpr long long MOD2 = 998244353;
constexpr long long HIGHINF = (long long)1e18;
constexpr long long LOWINF = (long long)1e15;
constexpr long double PI = 3.1415926535897932384626433;

template <class T> vector<T> make_v(size_t N,T init){return vector<T>(N,init);}
template <class... T> auto make_v(size_t N,T... t){return vector<decltype(make_v(t...))>(N,make_v(t...));}
template <class T> void corner(bool flg, T hoge) {if (flg) {cout << hoge << endl; exit(0);}}
template <class T, class U>ostream &operator<<(ostream &o, const map<T, U>&obj) {o << "{"; for (auto &x : obj) o << " {" << x.first << " : " << x.second << "}" << ","; o << " }"; return o;}
template <class T>ostream &operator<<(ostream &o, const set<T>&obj) {o << "{"; for (auto itr = obj.begin(); itr != obj.end(); ++itr) o << (itr != obj.begin() ? ", " : "") << *itr; o << "}"; return o;}
template <class T>ostream &operator<<(ostream &o, const multiset<T>&obj) {o << "{"; for (auto itr = obj.begin(); itr != obj.end(); ++itr) o << (itr != obj.begin() ? ", " : "") << *itr; o << "}"; return o;}
template <class T>ostream &operator<<(ostream &o, const vector<T>&obj) {o << "{"; for (int i = 0; i < (int)obj.size(); ++i)o << (i > 0 ? ", " : "") << obj[i]; o << "}"; return o;}
template <class T, class U>ostream &operator<<(ostream &o, const pair<T, U>&obj) {o << "{" << obj.first << ", " << obj.second << "}"; return o;}
template <template <class tmp>  class T, class U> ostream &operator<<(ostream &o, const T<U> &obj) {o << "{"; for (auto itr = obj.begin(); itr != obj.end(); ++itr)o << (itr != obj.begin() ? ", " : "") << *itr; o << "}"; return o;}
void print(void) {cout << endl;}
template <class Head> void print(Head&& head) {cout << head;print();}
template <class Head, class... Tail> void print(Head&& head, Tail&&... tail) {cout << head << " ";print(forward<Tail>(tail)...);}
template <class T> void chmax(T& a, const T b){a=max(a,b);}
template <class T> void chmin(T& a, const T b){a=min(a,b);}
void YN(bool flg) {cout << (flg ? "YES" : "NO") << endl;}
void Yn(bool flg) {cout << (flg ? "Yes" : "No") << endl;}
void yn(bool flg) {cout << (flg ? "yes" : "no") << endl;}

int main() {
	int N; cin >> N;
	string S; cin >> S;
	corner(N%2,"No");
	string T = S.substr(0,N/2);
	string U = S.substr(N/2,N);
	Yn(T==U);
	

	return 0;
}

Measured memory_bytes: 256
#100 C - /\/\/\/ AC
import collections
n = int(input())
A = list(map(int,input().split()))

A1 = A[::2]
A2 = A[1::2]
cnt1 = collections.Counter(A1)
cnt2 = collections.Counter(A2)

items1 = list(cnt1.most_common())
items2 = list(cnt2.most_common())

if items1[0][0] != items2[0][0]:
    ans = (len(A1) - items1[0][1]) + (len(A2) - items2[0][1])
else:
    if len(items1) == len(items2) == 1:
        ans = min(len(A1),len(A2))

    else:
        ans1 = (len(A1) - items1[0][1]) + (len(A2) - items2[1][1])
        ans2 = (len(A1) - items1[1][1]) + (len(A2) - items2[0][1])
        ans = min(ans1,ans2)
print(ans)

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

using namespace std;
typedef long long ll;

bool ok(ll x, ll n, ll s) {
  ll sum = 0;
  while (n) {
    sum += n % x;
    n /= x;
  }
  return sum == s;
}

int main(void) {
  ll n, s;
  cin >> n >> s;

  ll ans = -1;
  if (s == n) {
    ans = n + 1;
  } else {
    for (ll b = 2; b * b <= n; b++) {
      if (ok(b, n, s)) {
        ans = b;
        break;
      }
    }
    if (ans < 0 && n - s > 0) {
      for (ll p = 1; p * p < n; p++) {
        ll q = s - p, b = (n - s) / p + 1;
        if (q < 0 || q >= b) continue;
        if (!ok(b, n, s)) continue;
        ans = (ans < 0) ? b : min(ans, b);
      }
    }
  }

  cout << ans << endl;

  return 0;
}

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

typedef long long ll;
using namespace std;
int main()
{

  ll n;
  cin>>n;

  cout<<800*n-(n/15)*200<<endl;
  return 0;
}


Measured memory_bytes: 3588
nums = input().split()
W = int(nums[0])
H = int(nums[1])
X = int(nums[2])
Y = int(nums[3])
R = int(nums[4])
if (X - R) >= 0 and (X + R) <= W:
    if (Y - R) >= 0 and (Y+ R) <= H:
        print("Yes")
    else:
        print("No")
else:
    print("No")

Measured memory_bytes: 7716
#include<iostream>
#include<string>
using namespace std;
using UL = unsigned int;
using LL = long long;
using ULL = unsigned long long;
#define rep(i,n) for(UL i=0; i<n; i++)

UL to[3][6] = {
	{ 4, 0, 2, 3, 5, 1 },
	{ 2, 1, 5, 0, 4, 3 },
	{ 0, 2, 4, 1, 3, 5 }
};

UL C[6];
UL X[64][6];

int main(){
	rep(i, 6) cin >> C[i];
	rep(i, 6) X[0][i] = C[i];
	rep(a1, 4){
		if (a1) rep(i, 6) X[a1 * 16][i] = X[a1 * 16 - 16][to[0][i]];
		rep(a2, 4){
			if (a2) rep(i, 6) X[a1 * 16 + a2 * 4][i] = X[a1 * 16 + a2 * 4 - 4][to[1][i]];
			rep(a3, 4){
				if (a3) rep(i, 6) X[a1 * 16 + a2 * 4 + a3][i] = X[a1 * 16 + a2 * 4 + a3 - 1][to[2][i]];
			}
		}
	}
	UL Q; cin >> Q;
	rep(q, Q){
		UL x0, x1; cin >> x0 >> x1;
		UL p = 0;
		rep(i, 64){
			if (X[i][0] == x0 && X[i][1] == x1) p = i;
		}
		cout << X[p][2] << endl;
	}
	return 0;
}


Measured memory_bytes: 3092
#include <iostream>
#include <iomanip>
#include <fstream>
#include <sstream>
#include <string>

#include <algorithm>
#include <numeric>
#include <functional>
#include <iterator>
#include <random>
#include <complex>
#include <utility>
#include <tuple>
#include <memory>

#include <array>
#include <unordered_set>
#include <unordered_map>
#include <vector>
#include <list>
#include <stack>
#include <queue>
#include <map>
#include <set>

#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <ctime>
#include <csignal>
#include <cstdint>
#include <cstddef>

#ifdef ONLINE_JUDGE
#define NDEBUG
#endif
#include <cassert>
#include <stdexcept>
#include <exception>

// << pair
template <typename T1, typename T2>
std::ostream&operator<<(std::ostream&os,const std::pair<T1,T2>&p){return os<<"("<<p.first<<", "<<p.second<<")";}
// << container
template <typename C>
std::ostream&_debug_go(std::ostream&os,const C&v) {bool first=true;os<<"[";for(auto i:v){if(!first)os<<", ";os<<i;first=false;}return os<<"]";}
// << {vector, set, map} delegating to _debug_go
template<typename T> std::ostream&operator<<(std::ostream&os,const std::vector<T>&v){return _debug_go(os, v);}
template<typename T> std::ostream&operator<<(std::ostream&os,const std::set<T>&v){return _debug_go(os, v);}
template<typename T1, typename T2> std::ostream&operator<<(std::ostream&os,const std::map<T1,T2>&v){return _debug_go(os, v);}
struct Debugger{template<typename T>Debugger&operator,(const T&v){std::cerr<<v<<" "; return *this;}} dbg;
#ifndef NDEBUG
#define debug(args...) do {dbg,args; cerr << "\n";} while(0)
#else
#define debug(args...)
#endif

#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define REP(i, n) FOR(i, 0, n)
#define ITER(i, s, e) for (auto i((s)); i != (e); ++i)
#define IT(i, c) ITER(i, (c).begin(), (c).end())

using namespace std;

using ui = uint32_t;
using ll = int64_t;
using ull = uint64_t;
template <typename T = int> using Pt = complex<T>;

template <typename T>
T cross(const Pt<T>& a, const Pt<T>& b) { return a.real() * b.imag() - a.imag() * b.real(); }
// END TEMPLATE


constexpr int MAX_N = 1e5 + 10;

int N, M, S, T;
vector<int> E[MAX_N];

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);

    cin >> N >> M;
    REP(i, M) {
        int u, v; cin >> u >> v; --u, --v;
        E[u].push_back(v);
    }
    cin >> S >> T; --S, --T;
    queue<pair<int, int>> q;
    static int d[MAX_N][3];
    REP(u, N) REP(i, 3) d[u][i] = 3*MAX_N;
    q.emplace(S, 0);
    d[S][0] = 0;
    while (!q.empty()) {
        if (q.front() == pair<int, int>{T, 0}) break;
        auto p = q.front(); q.pop();
        int u = p.first, i  = p.second;
        for (int v : E[u]) {
            int& x = d[v][(i + 1) % 3];
            int y = d[u][i];
            if (y + 1 < x) {
                x = y + 1;
                q.emplace(v, (i + 1) % 3);
            }
        }
    }

    int y = d[T][0];
    cout << (y == 3*MAX_N ? -1 : y / 3) << '\n';

    return 0;
}


Measured memory_bytes: 6912
import java.util.*;

public class Main {
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    int n = sc.nextInt();
    long[] a = new long[n];
    for(int i = 0; i < n; i++) {
      a[i] = sc.nextLong();
    }
    int ans = 0;
    for(int i = 0; i < n; i++) {
      int p = 0;
      for(int j = 0; j < 50; j++) {
        if(a[i] % 2 != 0) {
          p = j;
          break;
        }
        a[i] /= 2;
      }
      ans += p;
    }
    System.out.println(ans);
  }
}

Measured memory_bytes: 34548
#include<cstdio>
#include<cstring>
using int64=long long;
constexpr int N=10001,mod=998244353;
char a[N],b[N];
int fact[N],factinv[N],f[N][N];
void exgcd(const int &a,const int &b,int &x,int &y) {
    if(!b) {
        x=1,y=0;
        return;
    }
    exgcd(b,a%b,y,x);
    y-=a/b*x;
}
inline int inv(const int &x) {
    int ret,tmp;
    exgcd(x,mod,ret,tmp);
    return (ret%mod+mod)%mod;
}
inline int C(const int &n,const int &m) {
    if(n<m||n<0||m<0) return 0;
    return (int64)fact[n]*factinv[m]%mod*factinv[n-m]%mod;
}
int main() {
    scanf("%s%s",a,b);
    const int n=strlen(a);
    for(register int i=fact[0]=1;i<=n;i++) {
        fact[i]=(int64)fact[i-1]*i%mod;
    }
    factinv[n]=inv(fact[n]);
    for(register int i=n;i;i--) {
        factinv[i-1]=(int64)factinv[i]*i%mod;
    }
    int s1=0,s2=0;
    for(register int i=0;i<n;i++) {
        if(a[i]=='1'&&b[i]=='1') s1++;
        if(a[i]=='1'&&b[i]=='0') s2++;
    }
    for(register int i=0;i<=s2;i++) {
        f[0][i]=(int64)fact[i]*fact[i]%mod;
    }
    for(register int i=1;i<=s1;i++) {
        for(register int j=1;j<=s2;j++) {
            f[i][j]=((int64)f[i-1][j]*i%mod*j%mod+(int64)f[i][j-1]*j%mod*j%mod)%mod;
        }
    }
    int ans=0;
    for(register int i=0;i<=s1;i++) {
        (ans+=(int64)f[s1-i][s2]*fact[i]%mod*fact[i]%mod*C(s1,i)%mod*C(s1+s2,i)%mod)%=mod;
    }
    printf("%d\n",ans);
    return 0;
}

Measured memory_bytes: 387712
#include <algorithm>
#include <bitset>
#include <cmath>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <limits>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <utility>
#include <vector>
using ll = long long;
#define rep(i, n) for (int i = 0; i < n; i++)
#define repk(i, k, n) for (int i = k; i < n; i++)
#define MOD 1000000007
#define INF 1e9
#define PIE 3.14159265358979323

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;
}
template <class T>
T GCD(T a, T b) {
    if (b == 0)
        return a;
    else
        return GCD(b, a % b);
}
template <class T>
inline T LCM(T a, T b) {
    return (a * b) / GCD(a, b);
}

using namespace std;
//#inculude <bits/stdc++.h>
//#define int long long

signed main() {
    int n;
    cin >> n;
    int a, b;
    vector<set<int>> v(n);
    vector<pair<int, int>> res(n - 1);
    rep(i, n - 1) {
        cin >> a >> b;
        v[a - 1].insert(b - 1);
        v[b - 1].insert(a - 1);
        res.push_back(make_pair(a - 1, b - 1));
    }
    map<pair<int, int>, int> re;
    int m = 0;
    rep(i, n) chmax(m, (int)v[i].size());
    cout << m << endl;
    vector<set<int>> used(n);
    queue<int> q;
    q.push(0);
    while (!q.empty()) {
        int x = q.front();
        q.pop();
        int index = 1;
        for (auto itr = v[x].begin(); itr != v[x].end(); itr++) {
            while (true) {
                if (used[x].find(index) == used[x].end()) {
                    used[x].insert(index);
                    used[*itr].insert(index);
                    v[*itr].erase(x);
                    auto p = make_pair(x, *itr);
                    re[p] = index;
                    q.push(*itr);
                    if (index == m)
                        index = 1;
                    else
                        index++;
                    break;
                }
                if (index == m)
                    index = 1;
                else
                    index++;
            }
        }
    }
    for (auto i : res)
        if (re[i] != 0)
            cout << re[i] << endl;
    return 0;
}

Measured memory_bytes: 34348
#include <bits/stdc++.h>
#include <boost/dynamic_bitset.hpp>

using namespace std;

#define INF 100000000
#define YJ 1145141919
#define INF_INT_MAX 2147483647
#define INF_LL 9223372036854775
#define INF_LL_MAX 9223372036854775807
#define EPS 1e-10
#define MOD 998244353
#define MOD9 998244353
#define Pi acos(-1)
#define LL long long
#define ULL unsigned long long
#define LD long double

#define int long long

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n) FOR(i,0,n)
#define ALL(a)  begin((a)), end((a))
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define MP make_pair
#define SZ(a) int((a).size())

signed main()
{
  int N; string S; cin >> N; cin >> S;
  int r = 0, b = 0;
  REP(i,N) {
    if(S[i] == 'R') {
      r++;
    } else {
      b++;
    }
  }

  cout << (r > b ? "Yes" : "No") << endl;

  return 0;
}

Measured memory_bytes: 256
#pragma GCC target("avx2")
#pragma GCC optimize("03")
#pragma GCC optimize("unroll-loops")
#include <bits/stdc++.h>
using namespace std; typedef long double ld; typedef long long ll;
typedef unsigned long long ull;
#define endl "\n"
#define FOR(i,a,b) for(int i=(a);i<=(b);i++)
#define rep(i,n) for(int i=0;i<(n);i++)
#define PII pair<int, int>
#define PLL pair<ll, ll>
#define ALL(x) (x).begin(), (x).end()
constexpr int INF=1<<30; constexpr ll LINF=1LL<<60; constexpr ll mod=1e9+7; constexpr int NIL = -1;
template<class T>inline bool chmax(T &a, const T &b) { if (a<b) { a = b; return 1; } return 0; }
template<class T>inline bool chmin(T &a, const T &b) { if (b<a) { a = b; return 1; } return 0; }
template<class T>inline int popcount(T a) {return __builtin_popcount(a);}
//-------------------
constexpr int MX = 22;
int a[MX][MX];
vector<ll> dp(1<<21, 0);
int n;

int main() {
    cin.tie(0); ios::sync_with_stdio(false); //cout << fixed << setprecision(15);
    cin >> n;
    rep(i,n) {
        rep(j,n) {
            cin >> a[i][j];
        }
    }
    dp[0] = 1;
    for(int i=1; i<(1<<n); i++) {
        int cur = n - popcount(i);
        for(int j=0; j<n; j++) {
            if(i&(1<<j) and a[cur][j]) {
                dp[i] += dp[i^(1<<j)];
                dp[i] %= mod;
            }
        }
    }
    cout << dp[(1<<n)-1] << endl;
    return 0;
}

Measured memory_bytes: 19480
#include<iostream>
#include<string>
using namespace std;

int main(){
    string n;
    cin >> n;
    for(int i=0; i<3; i++){
        if(n.at(i) == '1'){
            cout << '9';
        }else{
            cout << '1';
        }
    }
    cout << endl;
    return 0;
}

Measured memory_bytes: 3568
#include<bits/stdc++.h>
using namespace std;
long long n,k,a[1000000],misuf[1000000],mxpre[1000000];
int main()
{  scanf("%lld",&n);
   for (int i=1;i<=n;i++)  scanf("%lld",&a[i]);
   k=0; mxpre[1]=a[1]; misuf[n]=a[n];
   for (int i=2;i<=n;i++)  mxpre[i]=max(mxpre[i-1],a[i]);
   for (int i=n-1;i>=1;i--)  misuf[i]=min(misuf[i+1],a[i]);
   for (int i=2;i<n;i++)
   if (a[i]!=i && mxpre[i-1]>a[i] && misuf[i+1]<a[i]) k=1;
   for (int i=1;i<n;i++)
   {  if (a[i]!=i && a[i+1]!=i+1 && mxpre[i]!=i) k=1;
      if (a[i]==i && a[i+1]==i+1 && mxpre[i]!=i) k=1;
   }
   if (k==1)  cout<<"No"<<endl; else cout<<"Yes"<<endl;
}

Measured memory_bytes: 12544
N, M = map(int, input().split())
LR = [list(map(int, input().split())) for i in range(M)]

ListL = []
ListR = []

for i in range(M):
    ListL.append(LR[i][0])

for i in range(M):
    ListR.append(LR[i][1])

if (min(ListR)-max(ListL)+1)<0:
    print(0)

else:
    print(min(ListR)-max(ListL)+1)


Measured memory_bytes: 29032
#include <bits/stdc++.h>
using namespace std;
int n,m;
struct Node{
	int x,y,num;
}Edge[100005];
 
bool cmp(Node a,Node b){
	if(a.x == b.x){
		return a.y < b.y;
	}
	return a.x < b.x;
}
 
bool cmp1(Node a,Node b){
	return a.num < b.num;
}
 
int main()
{
	scanf("%d%d",&n,&m);
	for(int i=0;i<m;i++){
		scanf("%d%d",&Edge[i].x,&Edge[i].y);
		Edge[i].num = i;
	}
	sort(Edge,Edge+m,cmp);
	int num = 1;
	for(int i=0;i<m-1;i++){
		if(Edge[i].x == Edge[i+1].x){
			Edge[i].y = num++;
		}
		else{
			Edge[i].y = num;
			num = 1;
		}
	}
	if(Edge[m-1].x == Edge[m-1].x) Edge[m-1].y = num;
	else Edge[m-1].y = ++num;
	sort(Edge,Edge+m,cmp1);
	for(int i=0;i<m;i++){
		printf("%06d%06d\n",Edge[i].x,Edge[i].y);
	}
	return 0;
}

Measured memory_bytes: 4916
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
#define rep(a, b) for(int a=0; a<b; ++a)

int main () {
    int x;
    scanf("%d", &x);
    int z = 0;
    z += (x / 500)*1000;
    x = (x%500);
    z += (x / 5)*5;
    printf("%d\n", z);
    return 0;
}


Measured memory_bytes: 128
#include <stdio.h>
#define NUM 500000

struct kk {
  int key;
  int parent;
  int right;
  int left;
};


struct kk A[NUM];

void maxHeapify(struct kk A[],int i);
void buildmaxheap(struct kk A[]);

int H;

int main()
{
  int i;
  scanf("%d",&H);

  for(i = 1;i <= H;i++){
    scanf("%d",&A[i].key);
    A[i].parent = A[i/2].key;
    if(i%2 == 0) A[i/2].left = A[i].key;
    if(i%2 == 1) A[i/2].right = A[i].key;
  }

  buildmaxheap(A);

  printf(" %d",A[1].key);
  for(i = 2;i <= H;i++){
    printf(" %d",A[i].key);
  }
  printf("\n");

  return 0;
}

void maxHeapify(struct kk A[],int i)
{
  int l,r,largest,key;
  
  l = 2 * i;
  r = 2 * i + 1;

  if(l <= H && A[l].key > A[i].key) largest = l;
  else largest = i;

  if(r <= H && A[r].key > A[largest].key) largest = r;

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

void buildmaxheap(struct kk A[])
{
  int i;
  for(i = H/2;i > 0;i--) maxHeapify(A,i);
}
  



Measured memory_bytes: 9512
#include<iostream>
#include<deque>
#include<algorithm>

using namespace std;

int main(int argc, char const *argv[])
{
    int N;
    cin >>N;

    deque<long> arr;

    for(int i=0;i<N;i++){
        long tmp;
        cin>>tmp;
        if(i%2==0){
            arr.push_back(tmp);
        }else{
            arr.push_front(tmp);
        }
    }

    if(N%2==1){
        reverse(arr.begin(),arr.end());
    }

    for(auto &x:arr){
        cout<<x<<" ";
    }
    cout<<endl;

    return 0;
}




Measured memory_bytes: 3840
#include<iostream>
#include<stdio.h>
#include<string.h>
#include<algorithm>
#include<vector>
#include<queue>
#include<map>
#include<set>
#include<iomanip>
#include<cmath>

#define REP(i,n) for (int i = 0; (i) < (n); ++ (i))
#define FOR(i,n) for (int i = 1; (i) <= (n); ++ (i))
#define dump(x)  cout << #x << " = " << (x) << endl;
#define pb push_back
#define int long long

const int INF = 1e18;
const int MOD = 1e9+7;
//const lint LINF = 1e18;
const double eps = 0.000000001;//もとの値の10^(-16)まで

using namespace std;

//typedef pair<int, int> P;
//priority_queue< P, vector<P>, greater<P> > q;//ダイクストラの時、greaterで小さい順

signed main(){
    int n;
    cin >> n;
    cout << n*n << endl;



    return 0;
}

Measured memory_bytes: 764
#include <iostream>
#include <math.h>
#include <algorithm>

using namespace std;

int main(){
  int n,k;
  int a[200005];
  cin >> n >> k;

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

  for(int i = k ;i < n; i++){
    if(a[i] > a[i-k]) cout << "Yes";
    else cout << "No";

    if(i != n + 1) cout << endl;
  }
  return 0;
}


Measured memory_bytes: 4420
#include<bits/stdc++.h>
#define F first
#define S second
#define pb push_back
#define mp make_pair
#define full(a) a.begin(),a.end()
#define rfull(a) a.rbegin(),a.rend()

using namespace std;
const double pi=acos(-1.0);
const double pii=2*pi;
const double eps=1e-6;
const long long MOD=1e9+7;

int dp_fun(int h, int n, vector<vector<int>>& dp,vector<int>& a, vector<int>& b){
	if(h<=0)
		return 0;
	if(h>0&&n<0){
		return int(1e9);
	}
	if(dp[h][n]==-1){
		dp[h][n]=min(dp_fun(h,n-1,dp,a,b),dp_fun(h-a[n],n,dp,a,b)+b[n]);
		return dp[h][n];
	}
	return dp[h][n];
}

void solve(){
	int h,n;
	cin>>h>>n;
	vector<int> a(n,0),b(n,0);
	for(int i=0;i<n;i++){
		cin>>a[i]>>b[i];
	}

	vector<vector<int>> dp(h+1,vector<int>(n,-1));
	int ans=dp_fun(h,n-1,dp,a,b);
	cout<<ans<<"\n";
}

int main(){
	std::ios::sync_with_stdio(false);
	std::cin.tie(NULL);
	std::cout.tie(NULL);
	solve();
	return 0;
}

Measured memory_bytes: 39936
a,b,c,x,y=map(int,input().split())
d=c*2*max(x,y)
if x<y:
	e=c*2*x+b*(y-x)
else:
	e=c*2*y+a*(x-y)
f=a*x+b*y
print(min(d,e,f))

Measured memory_bytes: 3060
import sys
input=sys.stdin.readline
#for _ in range(int(input())):
#	n=int(input())
n,k=map(int,input().split())
#	s=input().strip()
a=list(map(int,input().split()))
dp=[False]*(k+1)
for i in range(1,k+1):
	for j in range(n):
		if i-a[j]>=0 and dp[i-a[j]]==False:
			dp[i]=True;break
if dp[-1]:print("First")
else:print("Second")

Measured memory_bytes: 42348
#include<iostream>
#include<vector>
#include<iomanip>
#include<algorithm>
#include<cmath>
#include<queue>
#include<set>
using namespace std;
using ulong = unsigned long;
using ll = long long;

// int judge(string& s, int l){
// 	int nums[26] = {};
// 	int sum = 0;
// 	for(int i=l;i<s.size();i++){
// 		nums[s[i] - 'a']++;
// 		sum++;
// 		if(sum >= 2 && nums[s[i] - 'a'] * 2 > sum){
// 			return i;
// 		}
// 	}
// 	return -1;
// }

int main(){
	string s;
	cin >> s;
	for(int i=0;i<s.size()-1;i++){
		if(s[i] == s[i+1]){
			cout << i+1 << ' ' << i+2 << endl;
			return 0;
		}else if(s[i] == s[i+2]){
			cout << i+1 << ' ' << i+3 << endl;
			return 0;
		}
	}
	//for(int i=0;i<s.size();i++){
	//	int ret = judge(s, i);
	//	if(ret != -1){
	//		cout << i + 1 << ' ' << ret + 1 << endl;
	//		return 0;
	//	}
	//}
	cout << "-1 -1" << endl;
	return 0;
}



Measured memory_bytes: 760
#include <iostream>
#include<math.h>
#include<list>
#include <algorithm>
#include<set>
#include<vector>
#include<math.h>
#include<map>
#include<string>
#include <numeric>
#include <queue>

using namespace std;
using ll = long long;
using vll = vector<long long>;
using sll = set<long long>;

template<typename T>
T gcd(T a, T b) { return b ? gcd(b, a % b) : a; }
template<typename T>
T lcm(T a, T b) { return a / gcd(a, b) * b; }

template<typename T>
map<T, T> primeFactor(T n) {
	map<T, T> res;
	for (T i = 2; i * i <= n; ++i) {
		while (n % i == 0) {
			res[i] ++;
			n /= i;
		}
	}
	if (n != 1) res[n] = 1;
	return res;
}

template<typename T>
bool IsPrimeNumber(T num)
{
	if (num <= 2) return true;
	else if (num % 2 == 0) return false;

	double sqrtNum = sqrt(num);
	for (int i = 3; i <= sqrtNum; i += 2)
	{
		if (num % i == 0)
		{
			return false;
		}
	}

	return true;
}


#define in(x) cin >> x
#define out(x) cout << x
#define outn(x) cout << x << '\n'
#define outs(x) cout << x << ' '
#define rep(i,s,e) for(long i=s;i<e;i++)
#define repeq(i,s,e) for(long i=s;i<=e;i++)



int main() {
	string ans = "Yes";
	vector<vll> c(3, vll(3));
	rep(i, 0, 3) {
		rep(j, 0, 3) {
			in(c[i][j]);
		}
	}

	rep(i, 1, 3) {
		rep(j, 1, 3) {
			if (c[i][j] + c[i - 1][j - 1] != c[i - 1][j] + c[i][j - 1]) {
				ans = "No";
			}
		}
	}

	outn(ans);

	return 0;

}


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

const int mxN=1e5+1;
int n, m, dp[mxN], ans;
vector<int> adj[mxN];

void dfs(int v) {
    dp[v]=1;
    for (int u:adj[v]) {
        if (!dp[u])
            dfs(u);
        dp[v]=max(dp[v], 1+dp[u]);
        ans=max(ans, dp[v]);
    }
}

int main() {
    cin.tie(0)->sync_with_stdio(0);
    cin >> n >> m;
    while (m--) {
        int a, b;
        cin >> a >> b;
        adj[a].pb(b);
    }
    for (int i=1; i<=n; ++i)
        if (!dp[i])
            dfs(i);
    cout << ans-1 << '\n';
}


Measured memory_bytes: 11432
// 8/7過去問
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (ll i = 0; i < (n); ++i)
using ll = long long;
using P = pair<int, int>;

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

    vector<int> A(N+2);
    A[0] = 0;
    rep(i, N) {
        cin >> A[i+1];
    }
    A[N+1] = 0;

    vector<int> S(N+2);
    S[0] = 0;
    rep(i, N + 1) {
        S[i+1] = S[i] + abs(A[i+1] - A[i]);
    }

    int ans = 0;

    rep(i, N) {
        cout << S[N+1] - (S[i+2] - S[i]) + abs(A[i+2] - A[i]) << endl;
    }

}


Measured memory_bytes: 4052
/** 
 *  Author : Parth Prajapati aka (PARTH_4399, hungry_chef)
 * 	Institute : Pandit Deendayal Petroleum University
**/
#include<bits/stdc++.h>

using namespace std; 


int gcd(int a, int b) 
{ 
    if (b == 0) 
        return a; 
    return gcd(b, a % b);  
      
} 

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    long long n, r = 0, g = 0, b = 0, i, j;
    string s;
    cin>>n>>s;
    for(i=0;i<n;++i)
    {
        if(s[i] == 'R') ++r;
        else if(s[i] == 'G')    ++g;
        else    ++b;
    }
    long long sum = r*g*b;
    for(i=0;i<n;++i)
    {
        for(j=i+1;j<n;++j)
        {
            if(s[i] == s[j] || (2*j-i) >= n)
                continue;
            if(s[2*j-i] == s[i] || s[2*j-i] == s[j])
                continue;
            --sum;
        }
    }
    cout<<sum;
	return 0;
}

Measured memory_bytes: 3652
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 = "";

		boolean[] ns = new boolean[1000000];
		for (int i = 2; i < 1000000 / 2 + 1; i++) {
			if (!ns[i]) {
				for (int j = 2; j < 999999 / i + 1; j++) {
					ns[i * j] = true;
				}
			}
		}

		while ((line = br.readLine()) != null && !line.isEmpty()) {
			int n = Integer.parseInt(line);
			int m = 0;
			for (int i = 2; i < n + 1; i++) {
				if (!ns[i]) {
					m++;
				}
			}
			System.out.println(m);
		}
	}
}

Measured memory_bytes: 22420
package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
)

type Scanner struct {
	sc *bufio.Scanner
}

func NewScanner() *Scanner {
	sc := bufio.NewScanner(os.Stdin)
	sc.Split(bufio.ScanWords)
	sc.Buffer(make([]byte, 1024), int(1e+9))
	return &Scanner{sc}
}

func (s *Scanner) nextStr() string {
	s.sc.Scan()
	return s.sc.Text()
}

func (s *Scanner) nextInt() int {
	i, e := strconv.Atoi(s.nextStr())
	if e != nil {
		panic(e)
	}
	return i
}

func (s *Scanner) nextRuneSlice() []rune {
	return []rune(s.nextStr())
}

func (s *Scanner) nextIntSlice(n int) []int {
	res := make([]int, n)
	for i := 0; i < n; i++ {
		res[i] = s.nextInt()
	}
	return res
}

func main() {
	sc := NewScanner()
	N, M := sc.nextInt(), sc.nextInt()
	A := make([][]rune, N)
	B := make([][]rune, M)
	for i := 0; i < N; i++ {
		A[i] = sc.nextRuneSlice()
	}
	for i := 0; i < M; i++ {
		B[i] = sc.nextRuneSlice()
	}
	for i := 0; i+M-1 < N; i++ {
		for j := 0; j+M-1 < N; j++ {
			res := true
			for k := 0; k < M; k++ {
				for l := 0; l < M; l++ {
					a := A[i+k][j+l]
					b := B[k][l]
					// fmt.Println(i, j, k, l, string(a), string(b))
					if a != b {
						res = false
					}
				}
			}
			if res {
				fmt.Println("Yes")
				return
			}
		}
	}
	fmt.Println("No")
}


Measured memory_bytes: 640
#include<iostream>
#include<bits/stdc++.h>
#define db(x) cout<<#x<<"="<<x<<'\n'
#define db2(x,y) cout<<#x<<"="<<x<<","<<#y<<"="<<y<<'\n'
#define db3(x,y,z) cout<<#x<<"="<<x<<","<<#y<<"="<<y<<","<<#z<<"="<<z<<'\n'
#define rep(i,n) for(int i=0;i<(n);++i)
#define fr(i,a,n) for(int i=a;i<=(n);++i)
#define rf(i,a,n) for(int i=a;i>=(n);--i)
#define mod 1000000007
#define eps 1e-9
#define PI 3.14159265358979323846
#define F first
#define S second
#define pb push_back
#define pf push_front
#define mp make_pair
#define pll pair<ll,ll>
#define _ <<" "<<
using namespace std;

typedef long long ll;
typedef vector<ll> vi;
typedef vector<vi> vvi;
typedef pair<int,int> ii;
typedef pair<int,pair<int,int>> iii;
typedef vector<ii> vii;
typedef vector<iii> viii;

vvi dp;

// int words(set<string> a, int n, string s){
// 	// db2(s,n);
// 	if(n==0)
// 		if(s.length()==0)
// 			return 1;
// 		else
// 			return 0;
// 	if(dp[n][s.length()]!=-1)
// 		return dp[n][s.length()];
// 	if(a.find(s.substr(n-1))!=a.end()){
// 		dp[n][s.length()]= max(words(a,n-1,s.substr(0,n-1)),words(a,n-1,s));
// 	}
// 	else
// 		dp[n][s.length()]= words(a,n-1,s);
// 	return dp[n][s.length()];
// }

int main(){
	int t=1;
	while(t--){
		ll n,W;
		cin>>n>>W;
		ll val=0;
		vi w(n),v(n);
		rep(i,n){
			cin>>w[i]>>v[i];
			val+=v[i];
		}
		// db(n);
		dp.clear();
		dp.resize(n+1,vi(val+1,INT_MAX));
		// cout<<words(a,s.length(),s)<<endl;
		int ans=0;
		dp[0][0]=0;
		for(int i=1;i<=n;i++){
			for(int j=0;j<=val;j++){
				// db2(i,j);
				if(j==0){
					dp[i][j]=0;
					continue;
				}
				if(j-v[i-1]>=0)
					dp[i][j]=min(dp[i-1][j],w[i-1]+dp[i-1][j-v[i-1]]); 
				else
					dp[i][j]=dp[i-1][j];
				if(dp[i][j]<=W){
					ans=max(ans,j);
				}
			 	// cout<<dp[i][j]<<' ';
			}
			// cout<<endl;
		}
		cout<<ans<<endl;
	}
	return 0;
}

Measured memory_bytes: 80256
N = gets.to_i
as = gets.split.map(&:to_i)

two_count = 0
four_count = 0
as.each do |a|
  if a % 4 == 0
    four_count += 1
  elsif a % 2 == 0
    two_count += 1
  end
end
n = two_count
m = if two_count > 0
  four_count * 2
else
  four_count * 2 + 1
end
puts(n + m >= N ? 'Yes' : 'No')


Measured memory_bytes: 8452
#include <stdio.h>
#include <string.h>

int main(void) {
	char s[128];
	size_t len;
	if (scanf("%127s", s) != 1) return 1;
	len = strlen(s);
	printf("%c%d%c\n", s[0], (int)(len - 2), s[len - 1]);
	return 0;
}


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

int main(){
	ios_base::sync_with_stdio(false);

	deque<int> d;

	int n;
	cin >> n;

	for(int i = 0; i < n; i++){
		int x;
		cin >> x;
		if(i % 2 == 0){
			d.push_back(x);
		}else{
			d.push_front(x);
		}
	}

	if(n % 2 == 0){
		for(int i = 0; i < n; i++){
			cout << d[i] << ' ';
		}
	}else{
		for(int i = n - 1; i >= 0; i--){
			cout << d[i] << ' ';
		}
	}
	cout << endl;

	return 0;
}


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

#define REP(i,n) for(ll i=0;i<n;++i)
#define RREP(i,n) for(ll i=n-1;i>=0;--i)
#define FOR(i,m,n) for(ll i=m;i<n;++i)
#define RFOR(i,m,n) for(ll i=n-1;i>=m;--i)
#define ALL(v) (v).begin(),(v).end()
#define PB(a) push_back(a)
#define UNIQUE(v) v.erase(unique(ALL(v)),v.end());
#define DUMP(v) REP(aa, (v).size()) { cout << v[a]; if (a != v.size() - 1)cout << " "; else cout << endl; }
#define INF 1000000001ll
#define MOD 1000000007ll
#define EPS 1e-9

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


using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<vi> vvi;
typedef vector<vl> vvl;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
ll max(ll a, int b) { return max(a, ll(b)); }
ll max(int a, ll b) { return max(ll(a), b); }
ll min(ll a, int b) { return min(a, ll(b)); }
ll min(int a, ll b) { return min(ll(a), b); }
///(テつエテ」ツδサテ渉嘉」ツδサ`)(テつエテ」ツδサテ渉嘉」ツδサ`)(テつエテ」ツδサテ渉嘉」ツδサ`)(テつエテ」ツδサテ渉嘉」ツδサ`)(テつエテ」ツδサテ渉嘉」ツδサ`)(テつエテ」ツδサテ渉嘉」ツδサ`)///
int main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	int x, y, s, cmax;
	while (1) {
		cin >> x >> y >> s;
		if (!x) break;
		cmax = -INF;
		FOR(i, 1, s) {
			FOR(j, 1, s) {
				if (i*(100 + x) / 100 + j*(100 + x) / 100 == s) {
					cmax = max(cmax, i*(100 + y) / 100 + j*(100 + y) / 100);
				}
			}
		}
		cout << cmax << endl;
	}

	return 0;
}

Measured memory_bytes: 3132
#include<bits/stdc++.h>
 
using namespace std;
 
#define LL long long int
#define FASTIO ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
const int oo = 1e9 + 5;
const LL ooll = (LL)1e18 + 5;
// const int MOD = 1e9 + 7;
const int MOD = 998244353;

mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
#define rand(l, r) uniform_int_distribution<int>(l, r)(rng)

clock_t start = clock();

const int N = 1e5 + 5;

int v[N], have[N];
void solve() {
    LL n;
    int x, m;
    cin >> n >> x >> m;
    for (int i=0;i<m;++i) have[i] = -1;
    v[0] = x;
    have[v[0]] = 0;
    int period = 0, st = -1;
    for (int i=1;i<N;++i) {
        v[i] = (v[i-1] * 1LL * v[i-1]) % m;
        if (have[v[i]] >= 0 && period == 0) {
            period = i - have[v[i]];
            st = have[v[i]];
            break;
        } 
        have[v[i]] = i;
    }
    // cout << st << " " << period << '\n';
    // return;
    if (n <= st) {
        LL ans = 0;
        for (int i=0;i<n;++i) ans += v[i];
        cout << ans << '\n';
        return;
    }
    LL once = 0, pre = 0, ans = 0;
    for (int i=st;i<st+period;++i) {
        once += v[i];
    }
    for (int i=0;i<st;++i) pre += v[i];
    int rem = (n - st) % period;
    for (int i=st;i<st+rem;++i) ans += v[i];
    ans += ((n - st) / period) * once;
    ans += pre;
    cout << ans << '\n';
}

int main() {
    FASTIO;
    int T = 1;
    // cin >> T;
    while (T--) {
        solve();
    }
    return 0;
} 

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

int main()
{
  int64_t N, ans = (1LL << 62);
  cin >> N;
  vector<int64_t> A(N), S(N + 1, 0);
  for (int i = 0; i < N; i++)
  {
    cin >> A.at(i);
    S.at(i + 1) = A.at(i) + S.at(i);
  }
  for (int k = 3; k <= N - 1; k++) // 1-indexedでDが開始するindex
  {
    auto a = lower_bound(S.begin(), S.begin() + k, S.at(k - 1) / 2);
    int64_t ic = distance(S.begin(), a); // 前半の和の半分以上となる1-indexedのindex
    int64_t s1 = S.at(k - 1);
    int64_t ma1, ma2, maa, mia;
    ma1 = max(S.at(ic), s1 - S.at(ic));
    ma2 = max(S.at(ic - 1), s1 - S.at(ic - 1));
    maa = min(ma1, ma2);
    mia = s1 - maa;

    auto b = lower_bound(S.begin() + k + 1, S.end(), (S.at(N) - S.at(k - 1)) / 2 + S.at(k - 1));
    int64_t ie = distance(S.begin(), b); // 後半の和の半分以上となる1-indexedのindex
    int64_t s2 = S.at(N) - S.at(k - 1);
    int64_t mb1, mb2, mab, mib;
    mb1 = max(S.at(ie) - S.at(k - 1), s2 - (S.at(ie) - S.at(k - 1)));
    mb2 = max(S.at(ie - 1) - S.at(k - 1), s2 - (S.at(ie - 1) - S.at(k - 1)));
    mab = min(mb1, mb2);
    mib = s2 - mab;
    ans = min(ans, max(maa, mab) - min(mia, mib));
  }
  cout << ans << endl;
}

Measured memory_bytes: 6400