akhauriyash/Code-Regression huggingface dataset:
using System;

namespace ConsoleApp1
{
    class Program
    {
        static void Main(string[] args)
        {
            double a;
            a = double.Parse(Console.ReadLine()); //標準入力
                                               //string[] str = Console.ReadLine().Split(' ');//2つ以上のスペース区切り入力の取得
                                               //b = int.Parse(str[0]);  //数値で受け取りたい場合は変換する
                                               //c = int.Parse(str[1]);
                                               //Console.Write("改行なし a = {0} b = {1} c = {2}", a, b, c)//改行なし出力
                                               //Console.WriteLine("改行あり a = {0} b = {1} c = {2}", a, b, c);//改行付き出力
            Console.WriteLine(Math.Ceiling(a/2));
        }
    }
}


Measured memory_bytes: 11220
N, M, X = gets.split.map(&:to_i)

BOOKS = N.times.map { 
  cost, *parameters = gets.split.map(&:to_i)

  [cost, parameters]
}

def f(mask)
  total_cost = 0
  skills = Array.new(M, 0)

  N.times do |i|
    next if mask[i] == 0

    cost, parameters = BOOKS[i]
    total_cost += cost

    parameters.each_with_index do |x, idx|
      skills[idx] += x
    end
  end

  if skills.all? { |x| x >= X }
    total_cost
  else
    Float::INFINITY
  end
end

min_cost = Float::INFINITY

(2 ** N).times do |mask|
  cost = f(mask)

  if min_cost > cost
    min_cost = cost
  end
end

if min_cost == Float::INFINITY
  puts -1
else
  puts min_cost
end


Measured memory_bytes: 14328
#include<bits/stdc++.h>
 
using namespace std;
 
#define pb push_back
#define ll long long
#define endl '\n'
#define vi vector<int>
#define rep(i, n) for (i = 0; i < n; i++)
#define rep1(i, n) for (i = 1; i <=n; i++)
#define rep2(i, n) for (i = 0; i < n-1; i++)
#define all(v) v.begin(),v.end()
#define rall(v) v.rbegin(),v.rend() //Sort in reverse,Vector.
#define present(v,x) (v.find(x)!=v.end()) //set/map etc.


int main()
{  ios_base::sync_with_stdio(false);cin.tie(NULL);
   #ifndef ONLINE_JUDGE
   freopen("input.txt","r",stdin);
   freopen("output.txt","w",stdout);
   #endif
   
   ll i,t,d,s;

   cin>>d>>t>>s;

   ll x= t*s;

   if(d<=x)
    cout<<"Yes";

  else
    cout<<"No";

  

   
    
   
}   


Measured memory_bytes: 3644
n = int(input())
B = [int(x) for x in input().split(" ")]

total = sum(B)
mid = total/2

behind = 0
for i in range(n):
    if behind + B[i] > mid:
        targetIndex = i
        break
    else:
        behind += B[i]

#targetIndexは配列のindex
right = mid - behind
left = behind + B[i] - mid

if right == left:
    print(int(right//0.5))
elif right > left:
    print(int(left//0.5))
elif right < left:
    print(int(right//0.5))

Measured memory_bytes: 26220
#!/usr/bin/env python3
import itertools
import math

d, g = list(map(int, input().split()))
pc = [list(map(int, input().split())) for i in range(d)]


ans = 100*d*100
for d in itertools.product([0, 1], repeat=d):
    ans_tmp = 0
    value = 0

    for i, j in enumerate(d):
        if j == 0:
            continue
        ans_tmp += pc[i][0]
        value += (i+1)*100*pc[i][0] + pc[i][1]

    iter_ = [[i, j] for i, j in enumerate(d)]
    # print(iter_)
    for i, j in reversed(iter_):
        if j == 1:
            continue
        base = (i+1)*100

        shortage = g-value
        if g-value <= 0:
            break

        num = min(math.ceil(shortage/base), pc[i][0]-1)
        ans_tmp += num
        value += base*num
    # print(d)
    # print(value, ans_tmp)
    if value >= g:
        ans = min(ans, ans_tmp)

print(ans)


Measured memory_bytes: 9192
/*
氏名：鈴木丈人
学籍番号：190441067
概要：長方形の円が含まれるかを判定するプログラム
*/
#include<stdio.h>
int main(void)
{
	int W;
	int H;
	int x;
	int y;
	int r;

	scanf("%d %d %d %d %d", &W, &H, &x, &y, &r);
	/*（x-1が0より小さいまたは、x+rがWより大きい）または（y-rが0より小さいまたは、y+rがHより大きい）*/
	if (((x - r)<0 || (x + r)>W) || ((y - r)<0 || (y + r)>H))
	{
		printf("No\n");
	}
	else
	{
		printf("Yes\n");
	}

	return 0;
}



Measured memory_bytes: 2040
import java.util.Scanner;
import java.util.List;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
class Main{
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
	int a = sc.nextInt();
    int b = sc.nextInt();
    int c = sc.nextInt();
    int d = sc.nextInt();
    if (b<=a){
      System.out.println(b*c+(a-b)*d);
    } else {
      System.out.println(a*c);
    }
  }
}


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

#define REP(i, n) for (int i = 0; i < n; i++)
#define FOR(i, n, m) for (int i = n; i < m; i++)
#define ll long long int

using namespace std;

int main() {
  int n;
  ll a[100000];
  cin >> n;
  REP(i,n) {
    cin >> a[i];
  }

  ll m = 1e12;
  ll result = 0;
  int minus = 0;
  REP(i,n) {
    if(a[i] < 0) {
      minus++;
    }
    result += abs(a[i]);
    m = min(abs(a[i]), m);
  }

  if(minus%2 == 0) {
    cout << result << endl;
  } else {
    cout << result - 2*m << endl;
  }

}


Measured memory_bytes: 1024
package main

import (
	"fmt"
	"strings"
)

func main() {
	alphabet := "abcdefghijklmnopqrstuvwxyz"
	var s string
	fmt.Scan(&s)
	for _, c := range s {
		alphabet = strings.Replace(alphabet, string(c), "", 1)
	}
	if len(alphabet) == 0 {
		fmt.Println("None")
	} else {
		fmt.Println(string(alphabet[0]))
	}
}


Measured memory_bytes: 1664
# -*- coding: utf-8 -*-
"""
Sliding Window - The Smallest Window I
http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=DSL_3_A&lang=jp

"""
N, S = map(int, input().split())
A = [int(a) for a in input().split()]

total, l, r = 0, 0, 0
ans = float('inf')
while True:
    while r < N and total < S:
        total += A[r]
        r += 1
    if total < S:
        break
    ans = min(ans, r-l)
    total -= A[l]
    l += 1
print(ans if ans != float('inf') else 0)



Measured memory_bytes: 16368
N,X,M=map(int,input().split())

A=[0,X]
D={}
D[X]=1
for i in range(2,10**7):
    A.append((A[-1]**2)%M)
    if A[-1] not in D:
        D[A[-1]]=i
    else:
        R=i
        L=D[A[-1]]
        break
    
#print(A)
#print(D)
#print(L,R)
    
Front=L-1

if N<=Front:
    print(sum(A[:N+1]))
    exit()
N-=Front
X=N//(R-L)
Y=N%(R-L)
#print(Y)
if Y>0:
    print(sum(A[:Front+1])+X*sum(A[L:R])+sum(A[L:L+Y]))
else:
    print(sum(A[:Front+1])+X*sum(A[L:R]))
#print(sum(A[:Front+1]),sum(A[L:R+1]))

Measured memory_bytes: 77608
N,X,M=map(int,input().split())
a=X
ls=[X]
point=N
for i in range(N):
  a=a*a%M
  if a in ls:
    point=ls.index(a)
    break
  else:
  	ls.append(a)
initial=len(ls[:point])
cycle_len=len(ls[point:])
cycle_sum=sum(ls[point:])
cycles=(N-initial)//cycle_len
cycles_rem=(N-initial)%cycle_len
print(sum(ls[:point])+cycles*cycle_sum+sum(ls[point:point+cycles_rem]))

Measured memory_bytes: 68524
#include <iostream>
#include <string>
#include <sstream>

using namespace std;

int main() {
  string line;
  while (getline(cin, line)) {
    stringstream stream;
    stream << line;
    string command, tree1, tree2;
    stream >> command >> tree1 >>  tree2;
    //cout << command << tree1 << tree2;
    //cout << tree1[0] << endl;

    int open = 0;
    int index1 = 0, index2 = 0;
    while (index1 < tree1.length() && index2 < tree2.length()) {
      if (tree1[index1] == tree2[index2]) { //if same characters
	cout << tree1[index1];
	index1++;
	index2++;
      } else  { //if different characters
	if (tree1[index1] == '(') {
	  open++;
	  index1++;
	  if (command == "u") cout << "(";
	  while (open != 0) {
	    if (tree1[index1] == '(') open++;
	    if (tree1[index1] == ')') open--;
	    if (command == "u") cout << tree1[index1];
	    index1++;
	   
	  }
	} else if (tree2[index2] == '(') {
	  open++;
	  index2++;
	  if (command == "u") cout << "(";
	  while (open != 0) {
	    if (tree2[index2] == '(') open++;
	    if (tree2[index2] == ')') open--;
	    if (command == "u") cout << tree2[index2];
	    index2++;
	    
	  }
	}
      }
     }
     cout << endl;
  }
}

Measured memory_bytes: 1196
from sys import stdin, stdout
def readLine_int_list():return list(map(int, stdin.readline().split()))

def is_biparate(links):
    '''
    0=white,1=blackとする
    2部グラフなら黒に塗られている頂点の数を返す
    2部グラフでないなら-1を返す。
    '''
    
    colors = [-1] * n
    colors[0] = 0
    q = [(0, 0)]  #0=white, 1=blackとする
    visited = set()
    while q:
        v, c = q.pop()
        if v in visited:
            if colors[v] != c: #最初に塗られた色とは反対の色が塗られるなら
                return -1
            continue
        visited.add(v)
        colors[v] = c
        for u in links[v]:
            q.append((u, c ^ 1))  #0^0=1 1^1=0 vとは反対の色を塗る
    return sum(colors)  #1の数 = blackの数
 




n, m = readLine_int_list()
g = [set() for _ in range(n)]

def main():
    for _ in range(m):
        a, b = readLine_int_list()
        a -= 1
        b -= 1
        g[a].add(b)
        g[b].add(a)
    
    
    
    bp1 = is_biparate(g)
    if bp1 == -1:
        '''
        2部グラフではない場合
            結論：完全グラフになるまで辺を追加できる
            →why
                奇サイクル上のある点をvとする
                s → v → tが偶数長でも、 奇サイクルの他の頂点を余計に経由することで奇数長になる
                s → tが奇数長になれば線が引ける
                つまり、任意の頂点間において奇数長が存在することになる
            完全グラフの辺の数は、n * (n - 1) // 2
            これには元あった辺の数まで含まれているので、 -m する
        '''
        max_m = n * (n - 1) // 2
    else:
        '''
        2部グラフの場合
            結論:(blackの数*whiteの数)本、線ができる
            why
                奇数閉路が存在しない => 異なる色間は必ず奇数長、同色間は必ず偶数長 
                1. whiteとblackの間は奇数長のパスが存在する ->線が引ける
                2. 同じ色どうしには奇数長のパスは存在しない -> 線は引かれない
                black=3, white=2の時の線の引き方 = b*w
            b*wにはパスの長さが1つまりもともとのパスが含まれてるので、-m　する
        '''
        max_m = bp1 * (n - bp1)
        
    print(max_m - m)
    

if __name__ == "__main__":
    main()

Measured memory_bytes: 43248
#include <bits/stdc++.h>
#define rep(i,cc,n) for(int i=cc;i<=n;++i)
#define drep(i,cc,n) for(int i=cc;i>=n;--i)
#define sz(s) (int)(s.size())
#define vecprint(v) rep(i,0,v.size()-1)cout << v[i] << " ";cout << endl;
#define arrprint(v,n) rep(i,0,n-1)cout << v[i] << " ";cout << endl;
#define matprint(v,n,m) rep(i,0,n-1){rep(j,0,m-1){cout << v[i][j] << " ";}cout << endl;}
#define SORT(v) sort(v.begin(), v.end())
#define REV(v) reverse(v.begin(), v.end())
using namespace std;
const int mod=1000000007;
const int INF=1001001001;
typedef long long ll;
typedef pair<int,int> P;
template<typename T>
using priority_queue_rev = priority_queue<T, vector<T>, greater<T>>; //小さいものから取り出す

int main(){
    string s;
    cin >> s;
    char prev = '-';
    int ans = 0;
    rep(i,0,sz(s)-1){
        // if((s[i] == 'D') ||(s[i] == '?') ){
        //     if(prev == 'P')ans += 2;
        //     else ans++;
        // }
        // prev = s[i];
        if(s[i] == '?')s[i] = 'D';
    }

    cout << s << endl;
//  printf("%.10f\n",ans);

    return 0;
}

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

int main()
{
  int d;
  cin>>d;
  
  if(d==25)
    cout<<"Christmas "<<"\n";
  else if(d==24)
    cout<<"Christmas Eve"<<"\n";
  else if(d==23)
    cout<<"Christmas Eve Eve"<<"\n";
  else 
    cout<<"Christmas Eve Eve Eve"<<"\n";
  return 0;
}

Measured memory_bytes: 3600
#include<iostream>
#include<algorithm>
#include<numeric>
#include<cstdint>

int const MAXV = 50;

int x[MAXV], N, A;

int64_t dp[2][MAXV+1][MAXV*MAXV+1];

int main() {
  std::cin >> N >> A;
  int maxv = 0;
  for(int i = 0; i < N; ++i) std::cin >> x[i];
  maxv = std::min(A*N, std::accumulate(x, x+N, 0));
  for(int j = 0; j <= N; ++j) for(int v = 0; v <= maxv; ++v) dp[0][j][v] = 0;
  dp[0][0][0] = 1;
  for(int i = 1; i <= N; ++i) for(int j = 0; j <= i; ++j) {
    // see till No. i card incl.,  use j cards
    for(int v = 0; v <= maxv; ++v) {
      int64_t nc = (j>0 && v>=x[i-1])? dp[(i-1)%2][j-1][v-x[i-1]]: 0;
      dp[i%2][j][v] = dp[(i-1)%2][j][v] + nc;
    }
  }
  int64_t ans = 0;
  for(int j = 1; j <= N; ++j) ans += dp[N%2][j][j*A];
  std::cout << ans << std::endl;
  return 0;
}


Measured memory_bytes: 2176
from collections import deque


def upd(a, b, v):
    global N
    dp[a][b] = max(dp[a][b], v)
    dp[b][a] = max(dp[b][a], v)
    dp[N][a] = max(dp[N][a], v)
    dp[N][b] = max(dp[N][b], v)
    dp[a][N] = max(dp[a][N], v)
    dp[b][N] = max(dp[b][N], v)
    dp[N][N] = max(dp[N][N], v)


N = int(input())
A = list(map(lambda x: int(x) - 1, input().split()))

INF = 1 << 32
dp = [[-INF] * (N + 1) for _ in range(N + 1)]
upd(A[0], A[1], 0)
base = 0

for i in range(2, 3 * N - 1, 3):
    x, y, z = A[i], A[i + 1], A[i + 2]
    if x == y == z:  # x, y, z 3文字すべて等しい
        base += 1
    else:
        q = deque()
        for _ in range(3):
            for k in range(N):
                v = dp[k][N]
                if y == z:
                    v = max(v, dp[k][y] + 1)
                q.append((k, x, v))
            v = max(dp[z][z] + 1, dp[N][N])
            q.append((x, y, v))
            x, y, z = z, x, y
        while q:
            a, b, v = q.popleft()
            upd(a, b, v)

l = A[-1]
ans = max(dp[N][N], dp[l][l] + 1)
print(ans + base)


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

int main() {
  int A, B;
  cin >> A >> B;
  for (int i = 1; i <= 100000; i++) {
    bool b = 1;
    if (i * 8 / 100 != A) b = 0;
    if (i * 10 / 100 != B) b = 0;
    if (b) return cout << i << "\n", 0;
  }
  cout << -1 << "\n";
}

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

int main() {
    int n,m;
    cin>>n>>m;
    if(n>=1 && n<=100 && m>=0 && m<=n){
        if(n==m){
            cout<<"Yes";
        }
        else{
            cout<<"No";
        }
    }
    return 0;
}


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

#define PI 3.141592653589
#define ll long long int
#define ld long double
#define vi vector<int>
#define ii pair<int,int>
#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define pll pair<ll,ll>
#define vv vector
int MOD=1e9+7;
ll power(ll a, ll b){//a^b
    ll res=1;
    a=a%MOD;
    while(b>0){
        if(b&1){res=(res*a)%MOD;b--;}
        a=(a*a)%MOD;
        b>>=1;
    }
    return res;
}
ll fermat_inv(ll y){return power(y,MOD-2);}
ll gcd(ll a, ll b){return (b==0)?a:gcd(b,a%b);}
ll min(ll a,ll b){return (a>b)?b:a;}
ll max(ll a,ll b){return (a>b)?a:b;}
bool prime[1000001];
vi primes;
void SieveOfEratosthenes(int n) 
{ 
    memset(prime, true, sizeof(prime)); 
    for (int p=2; p*p<=n; p++) 
    { 
        if (prime[p] == true) 
        { 
            for (int i=p*p; i<=n; i += p) 
                prime[i] = false; 
        } 
    } 
    for(int p=2;p<1000001;p++)
        if(prime[p])
            primes.pb(p);
}
int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	#ifndef ONLINE_JUDGE
		freopen("input.txt", "r", stdin);
		freopen("output.txt", "w", stdout);
	#endif

	int t=1;
	//cin>>t;
	//SieveOfEratosthenes(1000000);
    while(t--){
        ll n;
        cin>>n;
        ll a[n+1][3];
        for(ll i=0;i<n;i++)
            cin>>a[i][0]>>a[i][1]>>a[i][2];
        ll dp[n+1][3];
        for(ll i=0;i<=n;i++){
            if(i==0){
                for(ll j=0;j<3;j++)
                    dp[i][j]=0;
            }
            else{
                for(ll j=0;j<3;j++){
                    dp[i][0]=max(dp[i-1][1],dp[i-1][2])+a[i-1][0];
                    dp[i][1]=max(dp[i-1][0],dp[i-1][2])+a[i-1][1];
                    dp[i][2]=max(dp[i-1][0],dp[i-1][1])+a[i-1][2];
                }
            }
        }
        /*for(int i=0;i<=n;i++){
            for(int j=0;j<9;j++)
                cout<<dp[i][j]<<' ';
            cout<<'\n';
        }*/
        ll ans=0;
        for(ll i=0;i<3;i++)
            ans=max(ans,dp[n][i]);
        cout<<ans;
    }
}

Measured memory_bytes: 8316
#include "bits/stdc++.h"
#ifndef err
#define err(...)(void)0
#endif
using namespace std;
using ll = long long;
using ull = decltype(1ull);
template<class T>int size(T&&a) { return a.size(); }
#define REP(t,a)for(make_signed<decltype(a.second)>::type t=a.first,_l##t=a.second;t<_l##t;t++)
#define RREP(t,a)for(make_signed<decltype(a.second)>::type t=a.second-1,_l##t=a.first;t>=_l##t;t--)
template<class B>pair<int, B>make_pair(B b) { return{ 0,b }; }
#define rep(t,...)REP(t,make_pair(__VA_ARGS__))
#define rrep(t,...)RREP(t,make_pair(__VA_ARGS__))
#define all(a)begin(a),end(a)
#define rall(a)a.rbegin(),a.rend()

void Calc();
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0); cin.exceptions(istream::failbit | istream::badbit);
  cout << fixed << setprecision(15); Calc(); cout.flush(); return 0;
}
template<class A>void amax(A&a, A b) { a = max(a, b); }
template<class A>void amin(A&a, A b) { a = min(a, b); }
struct Scanner {
  template<class A = string>A Next() { A a; cin >> a; return a; }
  template<class A = int>vector<A>Array(int n) { vector<A>a(n); for (A&i : a) cin >> i; return a; }
  string Line() { string s; getline(cin, s); return s; }
  template<class A>Scanner&operator,(A&a) { a = Next<A>(); return *this; }
  template<class A>operator A() { return Next<A>(); }
}in;

/*---------------------------------------------------------------------*/


void Calc() {

  string s = in;
  auto pos = s.find('C');
  if (pos == -1) {
    cout << ("No") << endl;
    return;
  }
  auto a = s.find('F', pos);
  if (a != -1) {
    cout << ("Yes") << endl;
  } else {
    cout << ("No") << endl;
  }


}


Measured memory_bytes: 256
#include <functional>
#include <algorithm>
#include <iostream>
#include <numeric>
#include <iomanip>
#include <utility>
#include <cstdlib>
#include <sstream>
#include <bitset>
#include <vector>
#include <cstdio>
#include <ctime>
#include <queue>
#include <deque>
#include <cmath>
#include <stack>
#include <list>
#include <map>
#include <set>

using namespace std;

typedef vector<int> vi;
typedef pair<int,int> pii;
typedef long long ll;

#define dump(x)  cerr << #x << " = " << (x) << endl
#define rep(i,n) for(int i=0;i<(n);i++)
#define all(a)  (a).begin(),(a).end()
#define pb push_back

#define for_(i,a,b) for(int i=(a);i<(b);++i)
#define for_rev(i,a,b) for(int i=(a);i>=(b);--i)

int main(){
    int n;
    cin>>n;
    
    int f[1000],a[1000],t[1000],x[1000],y[1000];
    rep(i,n){
        cin>>f[i]>>a[i]>>t[i]>>x[i]>>y[i];
    }
    
    double time[2]={999999999,999999999},dir[2]={-1,-1};
    
    for(int i=1;i<n;i++){
        
        if(t[i-1]==t[i] && a[i-1]!=a[i]){
            int team=t[i];
            
            if(  dir[team]<sqrt( pow(x[i]-x[i-1],2)+pow(y[i]-y[i-1],2) )  ){
                dir[team]=sqrt( pow(x[i]-x[i-1],2)+pow(y[i]-y[i-1],2) );
                time[team]=f[i]-f[i-1];
            }
            else if(  dir[team]==sqrt( pow(x[i]-x[i-1],2)+pow(y[i]-y[i-1],2) ) && time[team]>f[i]-f[i-1] ){
                dir[team]=sqrt( pow(x[i]-x[i-1],2)+pow(y[i]-y[i-1],2) );
                time[team]=f[i]-f[i-1];
            }
            
        }
    }
    
    if(time[0]!=999999999)printf("%10.7lf %10.7lf\n",dir[0],time[0]/60);
    else cout<<"-1 -1"<<endl;
    
    if(time[1]!=999999999)printf("%10.7lf %10.7lf\n",dir[1],time[1]/60);
    else cout<<"-1 -1"<<endl;
}

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

template <typename T> T gcd(T x, T y) {
  if (y == 0)
    return x;
  return gcd(y, x % y);
}

template <typename T> T lcm(T x, T y) {
  if (x == 0 || y == 0)
    return 0;
  return x / gcd(x, y) * y;
}

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

vector<int> p;
vector<int> r;

void init(int n) {
  p.reserve(n);
  r.reserve(n);
  for (int i = 0; i < n; i++) {
    p[i] = i;
    r[i] = 0;
  }
}

int root(int x) { return p[x] == x ? x : p[x] = root(p[x]); }

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

void unite(int x, int y) {
  x = root(x);
  y = root(y);
  if (x == y)
    return;

  if (r[x] < r[y])
    p[x] = y;
  else {
    p[y] = x;
    if (r[x] == r[y])
      r[x]++;
  }
}

int main() {
  int N;
  cin >> N;
  vector<int> A(N);
  for (int i = 0; i < N; i++) {
    cin >> A[i];
  }
  long SUM = 0;
  long XOR = 0;
  long ans = N;
  int l = 0;
  for (int r = 0; r < N; r++) {
    XOR ^= A[r];
    SUM += A[r];
    for (; l <= r; l++) {
      if (XOR == SUM)
        break;
      XOR ^= A[l];
      SUM -= A[l];
    }
    ans += r - l;
  }
  cout << ans << endl;
}


Measured memory_bytes: 1024
n = int(input())
a = [int(i) for i in input().split()]
b = [int(i) for i in input().split()]
c = [int(i) for i in input().split()]

a.sort()
b.sort()
c.sort()

a_list = []
b_list = []

tmp = n-1
num = 0

for i in range(n):
    while tmp >= 0 and a[n-i-1] < b[tmp]:
        tmp -= 1
        num += 1
    a_list.append(num)
    #num = 0

tmp = n-1
num = 0

for i in range(n):
    while tmp >= 0 and b[n-i-1] < c[tmp]:
        tmp -= 1
        num += 1
    b_list.append(num)
    #num = 0

b_rui = []
tmp = 0

for i in range(n):
    tmp += b_list[i]
    b_rui.append(tmp)

ans = 0

for i in range(n):
    if a_list[i] == 0:
        continue
    ans += b_rui[a_list[i]-1]
    
print(ans)

Measured memory_bytes: 27192
#include "bits/stdc++.h"
using namespace std;
int main(){
    string s;
    cin >> s;
    int i,n=0,w[s.length()];
    long long int ans=0;
    for(i=0;i<s.length();i++){
        if(s.at(i)=='W'){
            w[n]=i;
            n++;
        }
    }
    for(i=0;i<n;i++){
        ans += w[i]-i;
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 1284
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <utility>
#include <tuple>
#include <cmath>
using namespace std;
using Int = long long;
#define REP(i,n) for(int i=0;i<n;i++)
#define FOR(i,n,m) for(int i=n;i<m;i++)
int main()
{
    string S; cin >> S;
    int N = S.size();
    int r = S.size();
    REP(i, N-1) if (S[i] != S[i+1]) r = min(r, max(i+1, N-i-1));
    cout << r << endl;
    return 0;
}

Measured memory_bytes: 512
#include<bits/stdc++.h>
using namespace std;
#define mod 1000000007
#define mod2 998244353 
#define PI 3.14159265
#define ll long long
#define ld long double
#define pi pair<ll,ll>
#define pb push_back
#define vi vector<ll>
#define sz size()
#define fi first
#define se second
#define lz length()
#define all(x) (x).begin(),(x).end()
#define scf(x) scanf("%lld",&x)
#define rep(i,n) for(ll i=0;i<n;i++)
const int INF = (int)1e9;
const ll IINF=1LL<<62;
const int maxn=10000005;
//int divr[maxn];
/**/
/*void divisor()
{for(int i=2;i<sqrt(maxn);i++)
     {
          if(!divr[i])
          {
               for(int j=i*i;j<maxn;j+=i)if(!divr[j])divr[j]=i;     
          }
     }
     for(int i=1;i<maxn;i++)if(!divr[i])divr[i]=i;
}*/
 
/*const int N=1000005;
ll n;
struct line {
    long long m, c;
    long long eval(long long x) { return m * x + c; }
    long double intersectX(line l) { return (long double) (c - l.c) / (l.m - m); }
};
vector<pair<pi,ll>> rect;
deque<line> dq;
*/
 
 
 
 


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




















int main()
{
     int n;
     cin>>n;
     int c[10][10];
     memset(c,0,sizeof(c));
     for(int i=1;i<=n;i++){
          int t=i;
          int l=t%10;
          while(t>=10)
          {
               t/=10;
          }
          int f=t;
          c[f][l]++;

     }
     ll res=0LL;
     for(int i=1;i<=9;i++){
          for(int j=1;j<=9;j++){
               res+=c[i][j]*c[j][i];
          }
     }
     cout<<res;
}







 
 

















Measured memory_bytes: 256
import java.util.Scanner;
class Main{
  public static void main(String[] args){
    Scanner scan = new Scanner(System.in);
    int n = scan.nextInt();
    int min, max;
    long sum = 0;
    sum = min = max = scan.nextInt();
    for(int i = 1; i < n; i++){
      int ai = scan.nextInt();
      if(min > ai){
        min = ai;
      }
      if(max < ai){
        max = ai;
      }
      sum += ai;
    }
    System.out.println(min + " " + max + " " + sum);
  }
}

Measured memory_bytes: 41508
s = input()

while len(s) >= 5:
    if len(s) >= 5 and s[-5:] == 'dream':
        s = s[:-5]

    elif len(s) >= 7 and s[-7:] == 'dreamer':
        s = s[:-7]

    elif len(s) >= 5 and s[-5:] == 'erase':
        s = s[:-5]

    elif len(s) >= 6 and s[-6:] == 'eraser':
        s = s[:-6]

    else:
        break

if len(s) == 0:
    print('YES')
else:
    print('NO')


Measured memory_bytes: 9212
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0; i<(n); i++)
using ll = long long;
#define fast_io(); std::ios_base::sync_with_stdio(0); std::cin.tie(0); std::cout.tie(0);
const std::string yes = "Yes";
const std::string no  = "No";

int main(){
    int n; std::cin >> n;
    if((n%1000+1000)%1000){
        std::cout << 1000 - (n%1000+1000)%1000 << "\n";
    }else{
        std::cout << 0 << "\n";
    }
    return 0;
}


Measured memory_bytes: 3596
#include<iostream>
using namespace std;
int main (){
    int a,b,c;
    cin >> a >> b >> c;
    int x;
    cin >> x;
    int count = 0;
    for (int i = 0;i <= a;i++){
        for (int j = 0;j <= b;j++){
            for (int k = 0;k <= c;k++){
                if (i * 500 + j * 100 + k * 50 == x) count++;
            }
        }
    }
    cout << count << endl;
    return 0;
}

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

#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
template <typename T>
using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;

// DON'T USE THESE MACROS DURING ICPC PRACTICE
#define For(i,n) for (int i=0; i<n; i++)
#define FOR(i,a,b) for (int i=a; i<=b; i++)
#define Down(i,n) for (int i=n-1; i>=0; i--)
#define DOWN(i,a,b) for (int i=b; i>=a; i--)

typedef long long ll;
typedef long double ld;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef pair<ld,ld> pdd;
typedef complex<ld> pt;
typedef vector<pt> pol;
typedef vector<int> vi;

const char nl = '\n';
const int INF = 0x3f3f3f3f;
const ll INFLL = 0x3f3f3f3f3f3f3f3f;
const ll MOD = 1e9+7;
const ld EPS = 1e-10;
mt19937 rng(chrono::high_resolution_clock::now().time_since_epoch().count());



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

	int n;
	cin >> n;
	int a[n];
	For(i,n) {
		cin >> a[i];
	}

	int dp[n];
	dp[0] = 0;
	FOR(i,1,n-1) {
		dp[i] = dp[i-1] + abs(a[i]-a[i-1]);
		if (i>1) dp[i] = min(dp[i], dp[i-2] + abs(a[i]-a[i-2]));
	}
	cout << dp[n-1] << nl;

	return 0;
}


Measured memory_bytes: 1024
import sys
input = sys.stdin.readline
from collections import Counter, defaultdict
import itertools
from functools import lru_cache

mask = (1 << 10) - 1

symmetry = defaultdict(int)

def encode(a,b,c,d):
    t = 1 << 40
    for x,y,z,w in [(a,b,c,d), (b,c,d,a), (c,d,a,b), (d,a,b,c)]:
        u = x + (y << 10) + (z << 20) + (w << 30)
        if t > u:
            t = u
    if a == b == c == d:
        symmetry[t] = 4
    elif a == c and b == d:
        symmetry[t] = 2
    else:
        symmetry[t] = 1
    return t

@lru_cache(None)
def decode(x):
    return [(x >> n) &mask for n in [0,10,20,30]]

N = int(input())
tiles = []
for _ in range(N):
    a,b,c,d = map(int,input().split())
    tiles.append(encode(a,b,c,d))
counter = Counter(tiles)

P = [(1,n,n*(n-1),n*(n-1)*(n-2),n*(n-1)*(n-2)*(n-3)) for n in range(N+1)]
P += [(0,0,0,0,0)] * (N+1) # 負数代入対策

power = [[n ** e for e in range(5)] for n in range(5)]

answer = 0
for bottom, top in itertools.combinations(tiles,2):
    counter[bottom] -= 1
    counter[top] -= 1
    a,b,c,d = decode(bottom)
    e,f,g,h = decode(top)
    for x,y,z,w in [(e,f,g,h), (f,g,h,e), (g,h,e,f), (h,e,f,g)]:
        # a,b,c,d
        # x,w,z,y 
        tiles = [encode(p,q,r,s) for p,q,r,s in [(b,a,x,w), (c,b,w,z), (d,c,z,y), (a,d,y,x)]]
        need = Counter(tiles)
        x = 1
        for tile, cnt in need.items():
            x *= P[counter[tile]][cnt] # 残っている個数、必要枚数
            x *= power[symmetry[tile]][cnt]
        answer += x
    counter[bottom] += 1
    counter[top] += 1

# 上下を固定した分
answer //= 3
print(answer)



Measured memory_bytes: 136872
#include <stdio.h>

int main(void){
	int t, n, d;
	scanf("%d", &t);
	while (t--) {
		scanf("%d%d", &n, &d);
		if (n % 2) {
			printf("%d\n", 127 * (n - 1) + d);
		} else {
			printf("%d\n", 127 * n - d);
		}
	}
	return 0;
}


Measured memory_bytes: 128
#include <cstdio>
#include <cstring>
#include <algorithm>
#define ll long long
#define inf 1<<30
#define il inline 
#define in1(a) read(a)
#define in2(a,b) in1(a),in1(b)
#define in3(a,b,c) in2(a,b),in1(c)
#define in4(a,b,c,d) in2(a,b),in2(c,d)
il void readl(ll &x){
    x=0;ll f=1;char c=getchar();
    while(c<'0'||c>'9'){if(c=='-')f=-f;c=getchar();}
    while(c>='0'&&c<='9'){x=x*10+c-'0';c=getchar();}
    x*=f;
}
il void read(int &x){
    x=0;int f=1;char c=getchar();
    while(c<'0'||c>'9'){if(c=='-')f=-f;c=getchar();}
    while(c>='0'&&c<='9'){x=x*10+c-'0';c=getchar();}
    x*=f;
}
using namespace std;
/*===================Header Template=====================*/
#define N 505
#define M 200005
int n,m,q;
struct node{
	int l,r,id;
}a[M],ask[M];
bool cmp(node a,node b){
	return a.r<b.r;
}
int c[M],ans[M];
void add(int x,int k){
	while(x<=n){
		c[x]+=k;
		x+=x&(-x);
	}
}
int query(int x){
	int res=0;
	while(x>0){
		res+=c[x];
		x-=x&(-x);
	}
	return res;
}
int main(){
	int i,j;
	in3(n,m,q);
	for(i=1;i<=m;i++){
		in2(a[i].l,a[i].r);
	}
	sort(a+1,a+m+1,cmp);
	for(i=1;i<=q;i++){
		in2(ask[i].l,ask[i].r);
		ask[i].id=i;
	}
	sort(ask+1,ask+q+1,cmp);
	j=1;
	for(i=1;i<=q;i++){
		while(j<=m&&a[j].r<=ask[i].r){
			add(a[j].l,1);
			j++;
		}
		ans[ask[i].id]=query(ask[i].r)-query(ask[i].l-1);
	}
	for(int i=1;i<=q;i++) printf("%d\n",ans[i]);
	return 0;
}

Measured memory_bytes: 5888
#include <stdio.h>

int isTriangle(int a, int b, int c) {
    if (a * a + b * b == c * c ||
        b * b + c * c == a * a ||
        c * c + a * a == b * b)
        return 1;
    else
        return 0;
}

int main(void)
{
    int n, a, b, c;

    scanf("%d", &n);
    while (n) {
        scanf("%d %d %d", &a, &b, &c);
        if (isTriangle(a, b, c)) printf("YES\n");
        else printf("NO\n");
        n--;
    }

    return 0;
}

Measured memory_bytes: 580
#include <iostream>
#include <vector>

using namespace std;

template<typename T>
void chmax(T &a, T b) {
    if (a < b) a = b;
}

struct node {
    int id;
    string type;
    int depth;
    int height;
    node *left;
    node *right;
    node *parent;

    node() {
        left = right = parent = nullptr;
        id = depth = height = -1;
        type = "getRoot";
    }

    int degree() {
        return (left == nullptr ? 0 : 1) + (right == nullptr ? 0 : 1);
    }

    node *getSibling() {
        if (parent == nullptr) return nullptr;
        return parent->left == this ? parent->right : parent->left;
    }

    node *getRoot() {
        return parent == nullptr ? this : parent->getRoot();
    }

    void printInfo() {
        node *sibling = getSibling();
        printf(
                "node %d: parent = %d, sibling = %d, degree = %d, depth = %d, height = %d, %s\n",
                id,
                parent == nullptr ? -1 : parent->id,
                sibling == nullptr ? -1 : sibling->id,
                degree(),
                depth,
                height,
                type.c_str());
    }
};

int dfs(node *current, int depth) {
    if (current == nullptr) return -1;
    current->depth = depth++;
    current->height = max(dfs(current->left, depth), dfs(current->right, depth)) + 1;
    current->type = current->height == 0 ? "leaf" : "internal node";
    return current->height;
}

int main() {
    int n, id, left, right;
    cin >> n;
    vector<node> tree(n);
    for (int i = 0; i < n; ++i) {
        cin >> id >> left >> right;
        tree[id].id = id;
        if (left != -1) {
            tree[id].left = &tree[left];
            tree[left].parent = &tree[id];
        }
        if (right != -1) {
            tree[id].right = &tree[right];
            tree[right].parent = &tree[id];
        }
    }
    node *root = tree[0].getRoot();
    dfs(root, 0);
    root->type = "root";
    for (node &nd:tree) nd.printInfo();
    return 0;
}



Measured memory_bytes: 3272
n = int(input())
k = int(input())
ns = str(n)
digits = len(ns)
dp = [[[0, 0, 0, 0] for i in range(2)] for i in range(digits + 1)]
#dp[i + 1][flag][j]:= 上からi桁目までで条件を満たす数
#flag = 0: 取り出したi桁目までが一致している(次の桁の制約ができる)
#j: 0~3　出てきた0以外の数字の数

dp[0][0][0] = 1
for s in range(digits):
    for t in range(2):
        for u in range(4):
            temp = dp[s][t][u]
            if temp == 0:continue

            if t == 0:
                #上位の桁による制約を受ける

                for i in range(int(ns[s]) + 1):
                    if i == int(ns[s]):
                        if i == 0:
                            dp[s + 1][t][u] += temp
                        elif i != 0 and u + 1 < 4:
                            dp[s + 1][t][u + 1] += temp

                    else:
                        if i == 0:
                            dp[s + 1][t + 1][u] += temp
                        elif i != 0 and u + 1 < 4:
                            dp[s + 1][t + 1][u + 1] += temp

            else:
                #上位の桁からの制約がない
                for i in range(10):
                    if i == 0:
                        dp[s + 1][t][u] += temp
                    elif i != 0 and u + 1 < 4:
                        dp[s + 1][t][u + 1] += temp

ans = dp[-1][0][k] + dp[-1][1][k]
print(ans)

Measured memory_bytes: 39664
import java.util.Scanner;

class Main {
    public static void main(String[] args) {

        Scanner scan = new Scanner(System.in);
        int n = scan.nextInt();
        int Y = scan.nextInt();

        for (int x = 0; x < n + 1; x++) {
            for (int y = 0; x + y < n + 1; y++) {
                int z = n - x - y;
                if (10000 * x + 5000 * y + 1000 * z == Y) {
                    System.out.println(x + " " + y + " " + z);
                    return;
                }
            }
        }
        System.out.println("-1 -1 -1");
    }
}

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

int main(){
  int n;
  cin >> n;
  
  long long int k=0;
  
  for(int i=0;i<n;i++){
    if((i+1)%3!=0&&(i+1)%5!=0)
      k+=(i+1);
  }
  
  cout << k << endl;
}

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

// int/long:		-2147483648 - 2147483648 (-2^31 <= int < 2^31)
// long/long long:	-9223372036854775808 - 9223372036854775807 (-2^63 <= long < 2^63)
#define	INF (1<<29)
//536870912

#define	MOD 1000000007

int	main() {
	int N;
	cin >>N;
	int K;
	K=(1+sqrt(1+8*N))/2;
	if (N != K*(K-1)/2) {
		cout <<"No" <<endl;
		return 0;
	}
	vector<vector<int>> S(K);
	int k=1;
	for (int i=0; i<K-1; i++)
		for (int j=i+1; j<K; j++) {
			S.at(i).push_back(k);
			S.at(j).push_back(k);
			k++;
		}
	cout <<"Yes" <<endl;
	cout <<K <<endl;
	for (int i=0; i<K; i++) {
		cout <<S.at(i).size() <<' ';
		for (int j=0; j<S.at(i).size(); j++)
			cout <<S.at(i).at(j) <<' ';
		cout <<endl;
	}
	return 0;
}



Measured memory_bytes: 2304
#include<stdio.h>
#include<math.h>
int main ()
{
    long long int n;
    scanf("%lld", &n);
    int count=0;
    ///checking prime:
    for(long long  i=2; i*i<=n; i++)
    {
        if (n%i == 0){count++; break ;}
    }
    ///checking prime ends.
    if (count==0){printf("%lld\n", n-1); return 0;}
    long long  root;
    root = sqrt(n);
    int rem;
   up: rem = n%root;
    if (rem!=0){root--; goto up;}
    else {printf("%lld", n/root+root-2);}
    return 0;
}


Measured memory_bytes: 128
/*input
a
aa
*/
/**
    Author: Kristopher Paul
    Date Created: 04-05-2020
    Contest Name:
                _/    _/   _/_/_/_/   _/   _/_/_/_/
               _/  _/     _/    _/   _/   _/
              _/_/       _/_/_/_/   _/   _/_/_/_/
             _/  _/     _/  _/     _/         _/
            _/    _/   _/    _/   _/   _/_/_/_/
**/
#include<bits/stdc++.h>
#include<stdio.h>
//#include <ext/pb_ds/assoc_container.hpp>
//#include <ext/pb_ds/tree_policy.hpp>
#define ll long long
#define int ll
#define pb push_back
#define INF 1e18
#define MOD 1000000007
//#define MOD 998244353
#define mp make_pair
const double PI=3.141592653589793238462643383279502884197169399375105820974944;
#define REP(i,n) for (int i = 0; i < n; i++)
#define FOR(i,a,b) for (int i = a; i < b; i++)
#define REPD(i,n) for (int i = n-1; i >= 0; i--)
#define FORD(i,a,b) for (int i = a; i >= b; i--)
#define remax(a,b) a = max(a,b)
#define remin(a,b) a = min(a,b)
#define umap unordered_map
#define pii pair<int,int>
#define F first
#define S second
#define mii map<int,int>
#define vi vector<int>
#define vvi vector<vi>
#define itr :: iterator it
#define all(v) v.begin(),v.end()
#define WL(t) while(t--)
#define gcd(a,b) __gcd((a),(b))
#define lcm(a,b) ((a)*(b))/gcd((a),(b))
#define out(x) cout << #x << " is " << x << endl
#define FastIO ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
using namespace std;
 
//Uncomment for File I/O
//ifstream fin("input.in")
 
//using namespace __gnu_pbds;
 
//typedef tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update> pbds; // set
//typedef tree<int,null_type,less_equal<int>,rb_tree_tag,tree_order_statistics_node_update> pbds; // multiset
 
int ModExp(int x,int y,int m){
    int res = 1;
    x = x % m;
    while (y > 0)
    {
        if (y & 1)
            res = (res*x) % m;
 
        y = y>>1;
        x = (x*x) % m;
    }
    return res;
}

void solve(){
    string s,t;
    cin >> s;
    cin >> t;
    FOR(i,0,s.length()){
        if(s[i] != t[i]){
            cout << "No" << endl;
            return;
        }
    }
    cout << "Yes" << endl;
}
 
signed main(){
    FastIO;
    int t = 1;
//    cin >> t;
    WL(t){
        solve();
    }
}

Measured memory_bytes: 3656
#include <bits/stdc++.h>
#define LL long long
using namespace std;
const int maxn=200005;
int n,m=1,val[maxn];
LL f[maxn][2][3];
int main()
{
	scanf("%d",&n);
	for (int i=1;i<=n;i++) scanf("%d",&val[i]);
	if (n&1) m++;
	f[1][1][0]=val[1];
	for (int i=2;i<=n;i++)
		for (int j=0;j<=m;j++)
		{
			f[i][0][j]=f[i-1][1][j];
			f[i][1][j]=f[i-1][0][j]+val[i];
			if (j) f[i][0][j]=max(f[i][0][j],f[i-1][0][j-1]);
		}
	printf("%lld\n",max(f[n][0][m-1],f[n][1][m]));
	return 0;
}


Measured memory_bytes: 13912
#include<stdio.h>
int main(void){
	int a,b,k;
	int i=100,cnt=0;
	scanf("%d %d %d",&a,&b,&k);
	while(1){
		if(!(a%i||b%i)){
			cnt++;
		}
		if(cnt==k){
			printf("%d",i);
			return 0;
		}
		i--;
	}
}

Measured memory_bytes: 128
unittest
{
	assert( [ "3", "3", "2", "5" ].parse.expand.solve == 3 );
	assert( [ "15", "3", "1", "4", "1", "5", "9", "2", "6", "5", "3", "5", "8", "9", "7", "9" ].parse.expand.solve == 18 );
}



import std.algorithm;
import std.conv;
import std.range;
import std.stdio;
import std.typecons;

void main()
{
	stdin.byLineCopy.parse.expand.solve.writeln;
}

auto parse( Range )( Range input )
if( isInputRange!Range && is( ElementType!Range == string ) )
{
	auto n = input.front.to!( long );
	auto as = new long[ n ];
	foreach( ref a; as )
	{
		input.popFront;
		a = input.front.to!( long );
	}
	return tuple( as );
}

auto solve( long[] as )
{
	auto ans = 0L;
	auto m = 0L;
	foreach( a; as )
	{
		if( m + 1 < a )
		{
			auto c = ( a - 1 ) / ( m + 1 );
			ans += c;
			a = 1;
		}
		m = max( m, a );
	}
	return ans;
}


Measured memory_bytes: 4092
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<(int)(n);++i)
#define repone(i,n) for(int i=1;i<(int)(n);++i)
#define repo(i,o,n) for(int i=o;i<(int)(n);++i)
#define Rep(j,n) for(int j=0;j<(int)(n);++j)
#define Repo(j,o,n) for(int j=o;j<(int)(n);++j)
#define Repone(j,n) for(int j=1;j<(int)(n);++j)
#define all(v) (v).begin(),(v).end()
#define rall(v) (v).rbegin(),(v).rend()
#define int long long
#define pb(a) push_back(a)
#define eraser(v,i) (v).erase(v.begin()+(i))
#define pbpair(a,b) push_back(make_pair(a,b))
#define MOD 1000000007
#define MODB 998244353
#define INF 9223372036854775807
bool compare_by_b(pair<int, int> a, pair<int, int> b) {
    if(a.second != b.second){
        return a.second < b.second;
    }else{
        return a.first < b.first;
    }
}
signed main()
{
  int x=0,y=1,z=0,w=0,n=0,m=0;
string s,t;
std::cin >> s>>t;
if(s.size()>t.size()){
  std::cout << "GREATER" << '\n';
  return 0;
}else if(t.size()>s.size()){
  std::cout << "LESS" << '\n';
  return 0;
}else{
  rep(i,s.size()){
    if(s[i]>t[i]){
      std::cout << "GREATER" << '\n';
      return 0;
    }else if(t[i]>s[i]){
      std::cout << "LESS" << '\n';
      return 0;
    }
  }
}
std::cout << "EQUAL" << '\n';
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#pragma GCC optimize("Ofast")
// ----- boost -----
#include <boost/rational.hpp>
#include <boost/multiprecision/cpp_int.hpp>
// ----- using directives and manipulations -----
using boost::rational;
using boost::multiprecision::cpp_int;
using namespace std;
#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(),(x).rend()
typedef long long ll;
#define rep(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define REP(i,num,n) for(int i=num, i##_len=(n); i<i##_len; ++i)
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
#define print(x) (cout << (x) << endl)
#define pb push_back
#define mp make_pair
#define sz(x) int(x.size())
template<class T> inline void Yes(T condition){ if(condition) cout << "Yes" << endl; else cout << "No" << endl; }
#define fs first
#define sc second

const int INF = 1e9;
const ll LLINF = 1e16;
const ll MOD = 1e9+7;
template<class T> inline void add(T &a, T b){a = ((a+b) % MOD + MOD) % MOD;};

template<typename T>
vector<T> make_v(size_t a){return vector<T>(a);}
 
template<typename T,typename... Ts>
auto make_v(size_t a,Ts... ts){
  return vector<decltype(make_v<T>(ts...))>(a,make_v<T>(ts...));
}
 

// 指定した文字cが文字列に何文字入ってるか
ll stringcount(string s, char c) {
    return count(s.cbegin(), s.cend(), c);
}


// 割り算の切り上げ処理
template<typename T>
T rp(T a, T b) {
  return (a + b - 1) / b;
}

// 桁和
template<typename T>
T digsum(T n) {
    T res = 0;
    while(n > 0) {
        res += n%10;
        n /= 10;
    }
    return res;
}

// 回文判定
bool kai (string s) {
    string t{s};
    reverse(begin(t), end(t));
    return s == t;
}

using pint = pair<int, int>;
using pll = pair<ll, ll>;
 
int64_t N, K;
vector<ll> A;
vector<ll> F;
 
bool check(int64_t X){
    int64_t need = 0;
    for(int i=0; i<N; i++){
        int64_t ok = X/F[i];
        if(ok < A[i]) need += A[i] - ok;
    }
    return (need <= K);
}
 
int main(){
    cin >> N >> K;
    A.resize(N);
    F.resize(N);
    for(int i=0; i<N; i++) cin >> A[i];
    for(int i=0; i<N; i++) cin >> F[i];
    sort(all(A));
    sort(rall(F));
    int64_t ok = 1e13, ng = -1;
    while(ok-ng>1){
        int64_t mid = (ok+ng)/2;
        (check(mid) ? ok : ng) = mid;
    }
    cout << ok << endl;
    return 0;
}


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

using namespace std;

int main(){
  int k;
  cin >> k;
  cin.ignore();
  int a, b;
  cin >> a >> b;
  cin.ignore();
  for(int i = a; i <= b; i++){
    if(i % k == 0){
      cout << "OK" << endl;
      return 0;
    }
  }
  cout << "NG" << endl;
  return 0;
}


Measured memory_bytes: 3632
#define _CRT_SECURE_NO_WARNINGS
#pragma comment(linker, "/STACK:256000000")
#define _USE_MATH_DEFINES
#include<iostream>
#include<vector>
#include<string>
#include<stack>
#include<algorithm>
#include<cmath>
#include<set>
#include<queue>
#include<sstream>
#include<utility>
#include<map>
#include<ctime>
#include<cstdio>
#include<cassert>
#include<functional>
#include<unordered_map>




using namespace std;

typedef long long ll;
typedef long double ld;
typedef unsigned int uint;
typedef unsigned long long ull;
typedef pair<ll, ll> pll;
typedef pair<int, int> pii;
typedef pair<char, char> pcc;
typedef pair<double, double> pdd;

#define show(x) cerr << x
#define debug(x) show(#x << ": " << (x) << endl)

const long double PI = 3.14159265358979323846;
const long double eps = 1e-5;
const int INF = numeric_limits<int>::max();
const ll LINF = numeric_limits<ll>::max();
const ll mod = 1000 * 1000 * 1000 + 7;



void solve() {
    int n;
    cin >> n;
    vector<string> a(n);
    for (int i = 0; i < n; ++i)
        cin >> a[i];
    int res = 0;
    int x = 0, y = 0, z = 0;
    for (int i = 0; i < n; ++i) {
        if ((a[i][0] == 'B') && (a[i][a[i].size() - 1] == 'A'))
            ++z;
        else {
            if (a[i][0] == 'B')
                ++x;
            else {
                if (a[i][a[i].size() - 1] == 'A')
                    ++y;
            }
        }
        for (int j = 0; j < a[i].size() - 1; ++j) {
            if ((a[i][j] == 'A') && (a[i][j + 1] == 'B'))
                ++res;
        }
    }
    if (z == 0) {
        cout << res + min(x, y) << endl;
        return;
    }
    res += z - 1;
    if (x > 0) {
        ++res;
        --x;
    }
    if (y > 0) {
        ++res;
        --y;
    }
    cout << res + min(x, y) << endl;

    
    
}

//#define LOCAL

int main() {
    ios_base::sync_with_stdio(0);cin.tie(nullptr);cout.tie(nullptr);
#ifdef LOCAL
    freopen("input.txt", "r", stdin);
    //freopen("output.txt", "w", stdout);
#endif
    solve();


#ifdef LOCAL
    cerr << "Time elapsed: " << 1.0 * clock() / CLOCKS_PER_SEC << " s.\n";
#endif	
    return 0;
}


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

const int N = 100;

char res[N + 10][N + 10];

void work(int i, char x, int cc) {
   int j = 0;
   while(cc > 0) {
      
      res[i][j] = x;

      j += 2;

      if(j >= N) {
         i += 2;
         j = 0;
      }

      cc--;
   }

}

int main() {
   int a, b; scanf("%d%d", &a, &b);
   
   for(int i = 0; i < N/2; i++) {
      fill(res[i], res[i] + N, '#');
   }
   for(int i = N/2; i < N; i++) {
      fill(res[i], res[i] + N, '.');
   }

   work(0, '.', a-1);
   work(N/2+1, '#', b-1);

   printf("%d %d\n", N, N);
   for(int i = 0; i < N; i++) {
      printf("%s\n", res[i]);
   }
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
  int N;
  int64_t u;
  int64_t sum = 0;
  int A[200000];
  cin >> N;
  for(int i=0;i<N;i++){
    cin>>A[i];
  }
  if (N == 1){
    cout<<sum<<endl;
  }
  else{
  for(int i=0 ; i < N-1 ; i++){
    int s =i+1;
    //cout<<A[i]<<A[s]<<endl;
  if(A[i] > A[s]){
    u = A[i] - A[s];
    A[s] = A[i] ;
    sum += u;
    //cout << u <<endl;
   }
                 }
  cout << sum << endl;
  }
}

Measured memory_bytes: 4368
#include <iostream>
#include <iomanip>
#include <string>
#include <vector>
#include <stack>
#include <queue>
#include <deque>
#include <set>
#include <map>
#include <utility>
#include <tuple>
#include <algorithm>
#include <numeric>
#include <cstdio>
#include <cmath>
#define rep(i, n) for (int i = 0; i < (n); i++)
using namespace std;
using ll = long long;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }

int main() {
  string s;
  cin >> s;
  for (int i = 1; i < 7; i++) {
    if (s.substr(0, i)+s.substr(s.size()-7+i) == "keyence") {
      cout << "YES" << endl;
      return 0;
    }
  }
  cout << "NO" << endl;
  return 0;
}

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

using namespace std;

typedef long long LL;

LL f[100][100][2];
int a[105];

LL dfs(int pos,int pre,int dd,bool flag)
{
	if (pos<=0) return 1;
	if (!flag&&f[pos][pre][dd]!=-1) return f[pos][pre][dd];
	int maxx;
	if (flag) maxx=a[pos];else maxx=9;
	LL now=0;
	for (int i=0;i<=maxx;++i)
	{
		int delta;
		if (dd==1) delta=0;else delta=abs(pre-i);
		if (delta<=1)now+=dfs(pos-1,i,dd&&(i==0),flag&&(i==maxx));
	}
	if (!flag) f[pos][pre][dd]=now;
	return now;
}
LL calc(LL x)
{
	memset(a,0,sizeof(a));
	while (x!=0)
	{
		++a[0];
		a[a[0]]=x%10;
		x/=10;
	}
	return dfs(a[0],0,1,true)-1;
}
int main()
{
	LL N,X;
	cin>>N>>X;
	N%=X;
	cout<<min(N,X-N)<<endl;
	return 0;
}

Measured memory_bytes: 256
N = int(input())
T, A = map(int,input().split())
H = list(map(int,input().split()))

min_diff = float('inf')
ans = 0
for i in range(1,len(H)+1):
  diff = abs(T - H[i-1]*0.006 - A)
  if diff < min_diff:
    min_diff = diff
    ans = i

print(ans)

Measured memory_bytes: 3064