akhauriyash/Code-Regression huggingface dataset:
package main

import (
        "fmt"
        "math/big"
)

func main() {
        var x1, x2, x3, x4, y1, y2, y3, y4 big.Float
        var n int
        fmt.Scanf("%d", &n)
        for i := 0; i < n; i++ {
                fmt.Scanf("%f %f %f %f %f %f %f %f",
                        &x1, &y1, &x2, &y2, &x3, &y3, &x4, &y4)
                var lx, ly, mx, my, mul1, mul2, sub, zz big.Float
                lx.Sub(&x2, &x1)
                ly.Sub(&y2, &y1)
                mx.Sub(&x4, &x3)
                my.Sub(&y4, &y3)
                mul1.Mul(&lx, &my)
                mul2.Mul(&ly, &mx)
                sub.Sub(&mul1, &mul2)
                zz.SetFloat64(0.0)

                if sub.Cmp(&zz) == 0 {
                        fmt.Println("YES")
                } else {
                        fmt.Println("NO")
                }
        }
}



Measured memory_bytes: 1260
/*
    Author:zeke
    
    pass System Test!
    GET AC!!
*/
#include <iostream>
#include <queue>
#include <vector>
#include <iostream>
#include <vector>
#include <string>
#include <cassert>
#include <algorithm>
#include <functional>
#include <cmath>
#include <queue>
#include <set>
#include <stack>
#include <deque>
#include <map>
#include <iomanip>
#include <utility>
#include <stack>
#include <bitset>
using ll = long long;
using ld = long double;
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(), (x).end()
#define rep3(var, min, max) for (ll(var) = (min); (var) < (max); ++(var))
#define repi3(var, min, max) for (ll(var) = (max)-1; (var) + 1 > (min); --(var))
#define Mp(a, b) make_pair((a), (b))
#define F first
#define S second
#define Icin(s) \
    ll(s);      \
    cin >> (s);
#define Scin(s) \
    ll(s);      \
    cin >> (s);
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;
}
typedef pair<ll, ll> P;
typedef vector<ll> V;
typedef vector<V> VV;
typedef vector<P> VP;
ll mod = 1e9 + 7;
ll MOD = 1e9 + 7;
ll INF = 1e18;

int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll x, y, z;
    cin >> x >> y >> z;
    if (x+y+z>=22){
        cout << "bust" << endl;
    }else{
        cout << "win" << endl;
    }
}


Measured memory_bytes: 256
#include<stdio.h>
#include<string.h>
#include<ctype.h>

int main (void)
{
	char s[1000],target[11],change[1000],check[11];
	int count;
	int i;
	
	count = 0;
	
	for(i = 0 ; i < 1000 ; i++)
	{
		change[i] = '\0';
		s[i] = '\0';
	}
	
	for(i = 0 ; i <11 ; i++ )
	{
		target[i] = '\0';
		check[i] = '\0';
	}
	
	scanf("%s",target);
	
	for(i = 0 ; target[i] != '\0' ; i++)
	{
		check[i] = tolower(target[i]);
	}
	
	while(1)
	{
		scanf("%s",s);
		if(strcmp(s,"END_OF_TEXT") == 0 )
		{
			break;
		}
		
		for(i = 0 ; s[i] != '\0' ; i++)
		{
			change[i] = tolower(s[i]);
		}
		
		if(strcmp(change,check) == 0)
		{
			count++;
		}
		for(i = 0 ; i < 1000 ; i++)
		{
			change[i] = '\0';
		}
	}

	printf("%d\n",count);
	return 0;
}


Measured memory_bytes: 2068
n,m = list(map(int,input().split()))
a = [input() for _ in range(n)]
b = [input() for _ in range(m)]

ans=False
for i in range(n-m+1):
    for j in range(n-m+1):
        flag=True
        for mi in range(m):
            for mj in range(m):
                if a[i+mi][j+mj]!=b[mi][mj]:
                    flag=False
        if flag:
            ans=True

if ans:
    print('Yes')
else:
    print('No')


Measured memory_bytes: 3064
#include<iostream>
#include<vector>
#include<utility>
#include<queue>
#include<algorithm>
using namespace std;

void solve() {
	int n, m, j = 0, ans = 0; cin >> n >> m;
	priority_queue<int> q;
	vector<pair<int, int>>ab(n);
	for (int i = 0; i < n; i++) {
		int a, b; cin >> a >> b;
		ab[i].first = a;
		ab[i].second = b;
	}
	sort(ab.begin(), ab.end());
	for (int i = 1; i <= m; i++) {
		while (ab[j].first <= i) {
			q.push(ab[j].second);
			j++;
		}
		if (!q.empty()) {
			ans += q.top();
			q.pop();
		}
	}
	cout << ans << endl;
}

int main() {
	solve();
}

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

int main(){
  int s, s1, s2, s3;
  cin >> s;
  s = s+1000;
  s1 = (s/100)%10;
  s2 = (s/10)%10;
  s3 = s%10;
  cout << s1+s2+s3 << endl;
}

Measured memory_bytes: 256
#include <iostream>
using namespace std;
#define REP(i, n) for (int i = 0; i < (n); i++)
int main() {
	int n, m, k, sum = 1;
	cin >> n >> m;
	REP(i, n) { cin >> k; }
	cout<<(n + m - 3) / (m - 1);
	return 0;
}


Measured memory_bytes: 256
import std.stdio, std.conv, std.string;
import std.algorithm, std.array, std.container;
import std.numeric, std.math;
import core.bitop;

T RD(T = string)() { static string[] ss; while(!ss.length) ss = readln.chomp.split; string res = ss[0]; ss.popFront; return res.to!T; }
string RDR()() { return readln.chomp; }

long mod = pow(10, 9) + 7;
long moda(long x, long y) { return (x + y) % mod; }
long mods(long x, long y) { return ((x + mod) - (y % mod)) % mod; }
long modm(long x, long y) { return (x * y) % mod; }

void main()
{
	auto n = RD!long;
	auto a = RDR.split.to!(long[]);

	write(a[n-1]);
	for (long i = n-3; i >= 0; i -= 2)
	{
		write(" ", a[i]);
	}
	for (long i = n % 2; i < n; i += 2)
	{
		write(" ", a[i]);
	}
	writeln();
	stdout.flush();
}

Measured memory_bytes: 13168
#![allow(non_snake_case)]

use std::io::{stdin, Read};
use std::str::FromStr;
fn read_option<T: FromStr>() -> Option<T> {
    let stdin = stdin();
    let stdin = stdin.lock();
    let token: String = stdin
        .bytes()
        .map(|c| c.expect("failed to read char") as char)
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect();
    token.parse().ok()
}
fn read<T: FromStr>() -> T {
    let opt = read_option();
    opt.expect("failed to parse token")
}

fn main() {
    let N: u32 = read();
    println!("{}", (N - 1) / 2);
}

Measured memory_bytes: 4352
#include <iostream>
#include <iomanip>
#include <string>
#include <stack>
#include <vector>
#include <math.h>
#include <stdio.h>
#include <algorithm>
#include <utility>
#include <functional>
#include <map>
#include <set>
#include <queue>
#include <list>
using namespace std;
using pii  = pair<int,int>;
using ll=long long;
using ld=long double;
#define pb push_back
#define mp make_pair
#define rep(i,n) for(ll i=0;i<(n);++i)
#define REP(i,a,b) for(ll i=(a);i<(b);++i)
#define crep(i) for(char i='a';i<='z';++i)
#define psortsecond(A,N) sort(A,A+N,[](const pii &a, const pii &b){return a.second<b.second;});
#define ALL(x) (x).begin(),(x).end()
#define endl '\n'
int ctoi(const char c){
  if('0' <= c && c <= '9') return (c-'0');
  return -1;
}
long long gcd(long long a, long long b){return (b == 0 ? a : gcd(b, a%b));}
long long lcm(long long a, long long b){return a*b/gcd(a,b);}
constexpr ll MOD=1000000007;
constexpr ld EPS=10e-8;
template<typename T> istream& operator>>(istream& is,vector<T>& v){for(auto&& x:v)is >> x;return is;}
template<typename T,typename U> istream& operator>>(istream& is, pair<T,U>& p){ is >> p.first; is >> p.second; return is;}
template<typename T,typename U> ostream& operator>>(ostream& os, const pair<T,U>& p){ os << p.first << ' ' << p.second; return os;}
template<class T> ostream& operator<<(ostream& os, vector<T>& v){
    for(auto i=begin(v); i != end(v); ++i){
        if(i !=begin(v)) os << ' ';
        os << *i;
    }
    return os;
}

ll dp[107][100007];

int main(){
  ll N,W;cin>>N>>W;
  pair<ll,ll> wv[107];
  rep(i,N){
      cin >> wv[i+1].first >> wv[i+1].second;
  }
  rep(i,100007){
      dp[0][i]=MOD;
  }
  rep(j,N+1){
      dp[j][0]=0;
  }
  ll sum=0;
  REP(i,1,N+1){
    sum+=wv[i].second;
    REP(j,1,100003){
      if(wv[i].second>j){
        dp[i][j]=min(dp[i-1][j],wv[i].first);
      }
      else if(j<=sum){
        dp[i][j]=min(dp[i-1][j],dp[i-1][j-wv[i].second]+wv[i].first);
      }
      else{
        dp[i][j]=dp[i-1][j];
      }
    }
  }
  for(ll i=100001;i>=0;i--){
    if(dp[N][i]<=W){
      cout << i << endl;
      break;
    }
  }
}

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

constexpr int mod = 1e9 + 7;

int N, X, Y, Z, d;
int dp[64][1 << 17];

int rec(int idx = N, int bit = 0) {
  int &res = dp[idx][bit];
  if (~res) return res;

  if ((bit & d) == d) {
    res = 1;
    while (idx--) res = 10ll * res % mod;
    return res;
  }

  res = 0;
  if (idx == 0) return res;
  for (int i = 1; i <= 10; ++i) {
    (res += rec(idx - 1, ((bit << i) + (1 << (i - 1))) & ((1 << 17) - 1))) %= mod;
  }

  return res;
}

signed main(int argc, char *argv[]) {
  cin >> N >> X >> Y >> Z;
  d = (1 << (Z - 1)) + (1 << (Z + Y - 1)) + (1 << (Z + Y + X - 1));
  memset(dp, -1, sizeof(dp));

  cout << rec() << endl;
}


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

int main(){
    int k;
    cin>>k;
    ll ans=0;
    for(int i=1;i<=k;i++){
        for(int j=1;j<=k;j++){
            for(int l=1;l<=k;l++){
                ans+=gcd(gcd(i,j),l);
            }
        }
    }
    cout<<ans<<endl;
}

Measured memory_bytes: 3624
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using vi = vector<ll>;
using vvi= vector<vi>;
using vs = vector<string>;
#define  rep(i,n) for(ll i = 0; i < (n); ++i)
#define  red(i,n) for(ll i = (n)-1; i >= 0; --i)
#define  all(a)   begin(a),end(a)
#define  pb(a)    push_back(a)
#define  mp(a,b)  make_pair(a,b)
#define  yn(a)    cout << ( (a)?"Yes\n":"No\n" )
inline ll gcd(ll a,ll b) { return b?gcd(b,a%b):a; }
const ll INF = 1e9+9, LINF = 1e18;


int main()
{
    ll x=0;
    string a="CODEFESTIVAL2016",b;
    cin>>b;
    red(i,a.size())x+=a[i]!=b[i];
    cout<<x<<endl;
    
    return 0;
}


Measured memory_bytes: 256
import java.util.*;

public class Main {
	int[] table = {0,1,2,3,5,7,8,9};
	public void MakeNumber( int old ) {
		if ( old >= 8 )
			MakeNumber( old / 8 );
		System.out.print(table[old%8]);
	}
	public static void main ( String[] args ) {
		Main m = new Main();
		Scanner sc = new Scanner(System.in);
		while ( !sc.hasNext("0") ) {
			int num = sc.nextInt();
			m.MakeNumber(num);
			System.out.println("");
		}
	}
}

Measured memory_bytes: 0
import java.util.Scanner

object Main extends App {
  val sc = new Scanner(System.in)

  val n = sc.nextInt
  val x = sc.nextInt
  val ls = Seq.fill(n)(sc.nextInt)

  val dList = ls.foldLeft(Seq(0)){case (ds, l) =>
    ds :+ (l + ds.last)
  }

  val res = dList.count(_ <= x)

  println(res)

}


Measured memory_bytes: 25676
"""
# 0じゃない数字がちょうどK個
dp[i][k][s] 
上からi桁目までみて、
0じゃない数字がk個。
上i桁が一致していたら0,違っていたら1
"""
S = input()
K = int(input())
m = len(S) #桁数

dp = [[[0]*2 for j in range(5)] for i in range(110)]

# 何も決めていない状態で,1以上を使ったのが0で、0桁目まで一致している
dp[0][0][0] = 1
for i in range(m):
    for j in range(4):
        for k in range(2):
            # Sの今の桁 n_digit
            digit = int(S[i])
            i_next = i + 1            
            # 次の桁(0から9)に対して遷移を考える
            for d in range(10):
                # j : 0の数について
                if d == 0: 
                    j_next = j
                else: 
                    j_next = j + 1
                if j_next > K: 
                    #0じゃない数がKを超えたら遷移しない
                    continue
                # k : 最大を取るか問題について
                if k == 0:
                    if d > digit: 
                        continue #Nを超える
                    elif d == digit: 
                        k_next = 0 #一致
                    else: 
                        k_next = 1
                else:
                    k_next = 1 # 変わることはない
                # 今の状態から0~9の遷移先
                dp[i_next][j_next][k_next] += dp[i][j][k]

ans = sum(dp[m][K])
print(ans)

Measured memory_bytes: 3192
/* package codechef; // don't place package name! */

import java.util.*;
import java.lang.*;
import java.io.*;

/* Name of the class has to be "Main" only if the class is public. */
public class Main
{
	public static void main (String[] args) throws java.lang.Exception
	{
		Scanner in = new Scanner(System.in);
		int n=in.nextInt();
		int [] a=new int [n];
		for(int i=0;i<n;i++)
		{
		    a[i]=in.nextInt();
		}
		int [] b=new int [n];
		for(int i=0;i<n;i++)
		{
		    b[i]=in.nextInt();
		}
		int [] c=new int [n-1];
		for(int i=0;i<n-1;i++)
		{
		    c[i]=in.nextInt();
		}
		int ans=0;
		int prev=-2;
		for(int i=0;i<n;i++)
		{
		    ans=ans+b[a[i]-1];
		    if(a[i]==prev+1)
		    {
		        ans=ans+c[prev-1];
		    }
		    prev=a[i];
		}
		System.out.println(ans);
		  
	}
}


Measured memory_bytes: 21844
# import sys
# sys.setrecursionlimit(10 ** 6)
# import bisect
# from collections import deque
# from decorator import stop_watch
# 
# 
# @stop_watch
def solve(N, Ss):
    cntAC, cntWA, cntTLE, cntRE = 0, 0, 0, 0
    cntJudge = {'AC': 0, 'WA': 0, 'TLE': 0, 'RE': 0}
    for S in Ss:
        cntJudge[S] += 1
    print('AC x ' + str(cntJudge['AC']))
    print('WA x ' + str(cntJudge['WA']))
    print('TLE x ' + str(cntJudge['TLE']))
    print('RE x ' + str(cntJudge['RE']))


if __name__ == '__main__':
    # S = input()
    N = int(input())
    # N, M = map(int, input().split())
    # As = [int(i) for i in input().split()]
    # Bs = [int(i) for i in input().split()]
    Ss = [input() for _ in range(N)]
    solve(N, Ss)


Measured memory_bytes: 16136
#include<bits/stdc++.h>
using namespace std;
#define rep(i,j,n) for(int i=(int)(j);i<(int)(n);i++)
#define REP(i,j,n) for(int i=(int)(j);i<=(int)(n);i++)
#define MOD 1000000007
#define int long long
#define ALL(a) (a).begin(),(a).end()
#define vi vector<int>
#define vii vector<vi>
#define pii pair<int,int>
#define priq priority_queue<int>
#define disup(A,key) distance(A.begin(),upper_bound(ALL(A),(int)(key)))
#define dislow(A,key) distance(A.begin(),lower_bound(ALL(A),(int)(key)))
#define tii tuple<int,int,int>
signed main(){
  string A,B; cin>>A>>B;
  string ans="EQUAL";
  if(A.size()>B.size())
    ans="GREATER";
  else if(A.size()<B.size())
    ans="LESS";
  else{
  if(A>B)
    ans="GREATER";
  else if(A<B)
    ans="LESS";
  }
  cout<<ans<<endl;
  }



Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <vector>
#include <string>
#include <cmath>
#include <algorithm>

using namespace std;

#define PB push_back
#define MP make_pair

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

const int MOD = 1e9+7;
const int INF = 1e9;

int main() {
  int N;
  cin >> N;
  cout << N/3 << endl;
  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <stdio.h>
#include <algorithm>
#define _USE_MATH_DEFINES
#include <cmath>
#include <numeric>
#include <iomanip>
#include <deque>
#include <tuple>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <unordered_map>
#include <sstream>
#include <boost/multiprecision/cpp_int.hpp>
#include <boost/multiprecision/cpp_dec_float.hpp>

#define rep(i, x) for (int i = 0; i < (int)(x); i++)
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define all(a) (a).begin(), (a).end()
#define F first
#define S second
#define pb push_back
#define pf push_front

namespace mp = boost::multiprecision;
using cpp_int = mp::cpp_int;
using ll = long long;
using namespace std;

ll M = 1000000007;
typedef pair<int, int> P;


bool ps1(const P &forall_a_in_P, const P &forall_b_in_P)
{ //first昇順
	return forall_a_in_P.first < forall_b_in_P.first;
}
bool ps2(const P &forall_a_in_P, const P &forall_b_in_P)
{ //first降順
	return forall_a_in_P.first > forall_b_in_P.first;
}
bool ps3(const P &forall_a_in_P, const P &forall_b_in_P)
{ //second昇順
	return forall_a_in_P.second < forall_b_in_P.second;
}
bool ps4(const P &forall_a_in_P, const P &forall_b_in_P)
{ //second降順
	return forall_a_in_P.second > forall_b_in_P.second;
}
int main()
{
    int n;
    cin >> n;
    vector<int> a(n);
    vector<pair<int,int>>odd(1e5+1),even(1e5+1);
    rep(i,1e5+1){
        odd[i].first=even[i].first=i;
    }
    rep(i, n)
    {
        cin >> a[i];
        if(i%2==0){
            even[a[i]].second++;
        }else{
            odd[a[i]].second++;
        }
    }
    sort(all(even),ps4);
    sort(all(odd),ps4);
    int ans=1e9;
    rep(i,3)rep(j,3){
     //   cout<<ft[i].first<<" "<<bt[j].first<<endl;
        if(even[i].first!=odd[j].first){
            
            int tmp=abs(n/2-even[i].second)+abs(n/2-odd[j].second);
            ans=min(tmp,ans);
        }
    }
    cout<<ans<<endl;
}


Measured memory_bytes: 2176
n, m = map(int, input().split())
S = list(input())
"""
9 3
0001000100
0010001000
3  2   3 1  
"""
S_r = S[::-1] + ["0"] #スタートのぶん付け足し
ans = []
now = 0
while now < n:
    flg = True
    for i in range(m,0,-1):
        if now + i <= n and S_r[now+i] == "0":
            ans.append(i)
            now += i
            flg = False
            break
    if flg:
        print(-1)
        exit()

print(*ans[::-1])

Measured memory_bytes: 7836
#include <bits/stdc++.h>
#define MAXN 1001000
using namespace std;

int p[MAXN][4];
int pd[MAXN][4];
int n;

int solve(int ind, int e){
	if(ind == n+1) return 0;
	if(pd[ind][e] != 0) return pd[ind][e];
	
	int res = 0;
	for(int i = 1; i <= 3; i++){
		if(i!=e) res = max(solve(ind+1,i)+p[ind][i], res) ;
	}
	
	return pd[ind][e] = res;
}


int main (){
	cin >> n;
	
	int i;
	
	for(i = 1; i <= n; i++)
		cin >> p[i][1] >> p[i][2] >> p[i][3];
		
	cout << solve(1,0) << endl;
	
	
}


Measured memory_bytes: 12160
n = int(input())
a = list(map(int,input().split()))
A = sum(a)
A_odd = [0]
A_even = [0]
for i in range((n+1)//2):
    A_odd.append(A_odd[i] + a[2*i])
for i in range((n-1)//2):
    A_even.append(A_even[i] + a[2*i+1])




for i in range(n):
    if i %2 == 0:
        x = A - 2*A_odd[i//2]-2*(A_even[(n-1)//2]-A_even[i//2])
    else:
        x = A - 2*A_even[(i-1)//2]-2*(A_odd[(n+1)//2]-A_odd[(i+1)//2])
    print(x,end=" ")

print()

Measured memory_bytes: 65636
#include <iostream>
#include <cstdio>
#include <string>
#include <algorithm>
#include <utility>
#include <cmath>
#include <vector>
#include <queue>
#include <set>
#include <map>
#define rep(i, n) for(int i = 0; i < n; i++)
using namespace std;
typedef long long ll;
const ll mod = 1000000007;

int main() {
    string s;
    cin >> s;
    int n = s.size();

    vector<int> ans(n);
    
    int cnteven = 0;
    int cntodd = 0;
    int posR, posL;
    rep(i, n) {

        if(i%2 == 0) {
            cnteven++;
        }
        else {
            cntodd++;
        }

        if(i < n-1 && s[i] == 'R' && s[i+1] == 'L') {
            posR = i;
            posL = i+1;
        }

        if(i < n-1 && s[i] == 'L' && s[i+1] == 'R') {
            if(posR%2 == 0) {
                ans[posR] = cnteven;
                ans[posL] = cntodd;
            }
            else {
                ans[posR] = cntodd;
                ans[posL] = cnteven;
            }
            cntodd = 0;
            cnteven = 0;
        }

        if(i == n-1) {
            if(posR%2 == 0) {
                ans[posR] = cnteven;
                ans[posL] = cntodd;
            }
            else {
                ans[posR] = cntodd;
                ans[posL] = cnteven;
            }
        }

    }

    rep(i, n) {
        cout << ans[i];
        if(i != n-1) {
            cout << " ";
        }
    }

    cout << endl;
    return 0;
}

Measured memory_bytes: 1024
import java.util.*;

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

      int n = Integer.parseInt(sc.next());
      int k = Integer.parseInt(sc.next());

      long[] dp = new long[n];

      long[] h = new long[n];
      for(int i=0;i<n;i++){
        h[i] = Long.parseLong(sc.next());
        dp[i] = 999999999;
      }


      dp[0] = 0;
      for(int i=1;i<n;i++){
        for(int j=1;j<=k;j++){
          if(i-j>=0){
            long costj = Math.abs(h[i]-h[i-j]);
            dp[i] = Math.min(dp[i-j]+costj,dp[i]);
          }
        }
      }

      System.out.println(dp[n-1]);

    }
}


Measured memory_bytes: 48408
#include<stdio.h>

char key[9][5]={{'.',',','!','?',' '}
	        ,{'a','b','c'}
	        ,{'d','e','f'}
	        ,{'g','h','i'}
		,{'j','k','l'}
		,{'m','n','o'}
		,{'p','q','r','s'}
		,{'t','u','v'}
		,{'w','x','y','z'}};

int ctoi(char c){
  return ((int)c)-48;
}

void mbl(char *s){
  int i=0;
  int bc=0;
  int pc=0;
  while(s[i]!='\0'){
    int bt=ctoi(s[i]);
    if(bt==0){
      if(bc!=0){
	int pb;
	if(bc==1){
	  pb=5;
	}
	else if((bc==7)||(bc==9)){
	  pb=4;
	}
	else{
	  pb=3;
	}
	printf("%c",key[bc-1][(pc-1)%pb]);
	bc=0;
	pc=0;
      }
    }
    else{
      bc=bt;
      pc++;
    }
    i++;
  }
  printf("\n");
}

void doit(int n){
  char s[1025];
  int i;
  for(i=0;i<n;i++){
    scanf("%s",s);
    mbl(s);
  }
}

int main(){
  int n;
  scanf("%d",&n);
  doit(n);
  return 0;
}

Measured memory_bytes: 572
from collections import Counter

n = int(input())
s_list = [input() for _ in range(n)]

x = sorted(Counter(s_list).items(),key=lambda x:x[1],reverse=True)
max_num = x[0][1]

result = sorted([i[0] for i in x if i[1] == max_num])

for i in result:
    print(i)

Measured memory_bytes: 45032
loop do
  n, x = gets.chop.split(' ').map(&:to_i)
  if n == 0 && x == 0
    break
  end

  count = 0
  
  1.step n do |a|
    (a+1).step n do |b|
      (b+1).step n do |c|
        count += 1 if a+b+c == x
      end
    end
  end
  puts count
end



Measured memory_bytes: 6860
#include<bits/stdc++.h>
using namespace std;
int main()
{
    long long int n,a,b,ans;
    cin>>n;
    a=(n/500);
    b=(n%500)/5;
    ans=a*1000+b*5;
    //cout<<a<<" "<<b<<endl;
    cout<<ans<<endl;
}


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

using namespace std;

using ll = long long;
using ld = long double;
using P = pair<int, int>;
constexpr ld EPS = 1e-12;
constexpr int INF = numeric_limits<int>::max() / 2;
constexpr int MOD = 1e9 + 7;

template <typename T>
void printv(const vector<T> &v)
{
    int sz = v.size();
    for (int i = 0; i < sz; i++)
    {
        cout << v[i] << " \n"[i == sz - 1];
    }
}

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

ll lcm(ll x, ll y)
{
    return x / gcd(x, y) * y;
}

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

    ll l, r;
    cin >> l >> r;
    if (r - l >= 2018)
    {
        cout << 0 << endl;
        return 0;
    }
    ll ret = INF;
    for (ll i = l; i <= r; i++)
    {
        for (ll j = i + 1; j <= r; j++)
        {
            ret = min(ret, i * j % 2019);
        }
    }
    cout << ret << endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <string>
#include <cmath>
#include <algorithm>
#include <map>
#include <iomanip>
#include <stdlib.h>
#include <queue>

using namespace std;

const int nmax = 1e9 + 7;
typedef long long ll;

int main(){
  int N; cin >> N;
  int half = N / 2;
  double n = N, H = half;
  cout << setprecision(16) << 1 - H / n << endl;
  
  return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<math.h>
#include<algorithm>
#define ll long long int
#define FOR(i,a,b) for(ll i=(ll)(a);i<(ll)(b);i++)
#define REP(i,n) FOR(i,0,n)
#define REP1(i,n) FOR(i,1,n)

using namespace std;

int main(){
	int N, M, X, Y;
	cin >> N >> M >> X >> Y;
	int x[N], y[M], xmax = -200, ymin = 200, z;
	REP(i,N){
		cin >> x[i];
		xmax = max(xmax, x[i]);
	}
	REP(i,M){
		cin >> y[i];
		ymin = min(ymin, y[i]);
	}
	z = xmax;
	while(++z <= ymin){
		if(z > X && z <= Y) {
			cout << "No War" << endl;
			return 0;
		}
	}
	cout << "War" << endl;
	return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <vector>
#include <queue>
#include <stack>
#include <string>
#include <iomanip>
#include <map>
#include <set>
#include <cmath>
#include <cstdio>
using namespace std;
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define FOR(i,m,n) for(int (i)=(m);(i)<(n);(i)++)
#define All(v) (v).begin(),(v).end()
typedef long long ll;

int main(){
    int N,K;
    cin >> N >> K;
    vector<int> x(N),y(N),c(N);
    rep(i,N){
        char bw;
        cin >> x[i] >> y[i] >> bw;
        x[i]%=2*K;
        y[i]%=2*K;
        c[i]=(bw=='W');
    }

    vector<vector<int> > white(K,vector<int>(K,0)),black(K,vector<int>(K,0));

    for(int i=0;i<N;i++){
        c[i]+=(x[i]>=K)+(y[i]>=K);
        x[i]%=K;
        y[i]%=K;
        c[i]%=2;
        if(c[i])white[x[i]][y[i]]++;
        else black[x[i]][y[i]]++;
    }
    
    for(int x=0;x<K;x++){
        for(int y=1;y<K;y++){
            white[x][y]+=white[x][y-1];
            black[x][y]+=black[x][y-1];
        }
    }
    
    for(int x=1;x<K;x++){
        for(int y=0;y<K;y++){
            white[x][y]+=white[x-1][y];
            black[x][y]+=black[x-1][y];
        }
    }
    
    int res = 0;
    rep(x,K)rep(y,K){
        int w = white[K-1][K-1]-white[x][K-1]-white[K-1][y]+2*white[x][y];
        int b = black[x][K-1]+black[K-1][y]-2*black[x][y];
        res = max(res,max(w+b,N-(w+b)));
    }
    cout << res << endl;
    return 0;
}

Measured memory_bytes: 9344
#include<iostream>
#include<cstdio>
using namespace std;
int a[60];
int main(){
	int i=0,j,n;
	scanf("%d",&n);
	if(n==0)a[++i]=0;
	while(n){
		if(n%(-2)!=0){
			n--;
			a[++i]=1;
		}
		else a[++i]=0;
		n/=(-2);
	}
	for(j=i;j>0;j--)
		printf("%d",a[j]);
	return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<vector>
#include<string>
#include<cmath>
#include<cstdio>
#define ll long long
using namespace std;

int main(){
  int M1,D1;cin>>M1>>D1;
  int M2,D2;cin>>M2>>D2;
  if(M1!=M2)cout<<1;
  else cout<<0;
}


Measured memory_bytes: 888
import sys
from collections import deque
sys.setrecursionlimit(10**7)


def BFS(s):
    color=["white" for _ in range(n)]
    D=[float("inf") for _ in range(n)]

    color[s-1]="gray"
    D[s-1]=0
    queue=deque([s-1])

    while len(queue)!=0:
        u=queue.popleft()
        for i in M[u]:
            if color[i]=="white":
                color[i]="gray"
                D[i]=D[u]+1
                queue.append(i)
        color[u]="black"

    return D


n,x,y=map(int,input().split())

M=[[] for _ in range(n)]
for i in range(n-1):
    M[i].append(i+1)
    M[i+1].append(i)
M[x-1].append(y-1)
M[y-1].append(x-1)

C=[0]*n
for i in range(n):
    for j in BFS(i+1)[i:]:
        C[j] +=1

for i in C[1:]:
    print(i)

Measured memory_bytes: 59484
#include <cstdio>
#include <cmath>
#include <limits>
#include <fstream>
#include <iostream>
#include <algorithm>
#include <vector>
#include <utility>
#include <cstring>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <cstdint>
#include <functional>
#define rep(i, s, g) for (i = s; i < g; i++)
using namespace std;
using ll = long long;

const ll mod = 1000000000 + 7; //10^9


// bool is_integer(double x){
//     return floor(x) == x;
// }

// vector<int> bitsearch(int n, int bit) {
//     for (int i = 0; i < n; i++)
//     {
//         vector<int> S(n);
//         if(bit & (1 << i)){
//             S.push_back(i);
//         }
//     }
// }./  

int main() {
    ll N, A, B;
    cin >> N >> A >> B;
    ll b_c = 0;
    b_c = N / (A + B);
    N -= b_c * (A + B);
    ll ans = 0;
    if(N > A) {
        ans += A;
    }else{
        ans += N;
    }
    ans += b_c * A;
    cout << ans << endl;
}


Measured memory_bytes: 3660
#include <bits/stdc++.h>
#define _overload3(_1, _2, _3, name, ...) name
#define _rep(i, n) repi(i, 0, n)
#define repi(i, a, b) for (int i = (a); i < (b); ++i)
#define rep(...) _overload3(__VA_ARGS__, repi, _rep, )(__VA_ARGS__)
#define ALL(x) x.begin(), x.end()
#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)
using namespace std;
using ll = long long;
using lld = long double;
using VI = vector<int>;
using VVI = vector<VI>;
using VL = vector<ll>;
using VVL = vector<VL>;
using PII = pair<int, int>;
random_device rnd;
mt19937 mt(rnd());

const int IINF = 1 << 30;
const ll INF = 1ll << 60;
const ll MOD = 1e9 + 7;

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

ll mpow(ll base, ll num)
{
    if (num == 0)
        return 1ll;
    ll prev = mpow(base, num / 2);
    if (num % 2 == 0)
    {
        return (prev * prev) % MOD;
    }
    else
    {
        return (((prev * prev) % MOD) * base) % MOD;
    }
}
int main()
{
    ios::sync_with_stdio(0);
    cin.tie(0);
    int n;
    cin >> n;
    VL a(n), b(n);
    map<PII, ll> num;
    rep(i, n)
    {
        cin >> a[i] >> b[i];
        ll g = gcd(llabs(a[i]), llabs(b[i]));
        if (g != 0)
        {
            a[i] /= g;
            b[i] /= g;
        }
        num[{a[i], b[i]}]++;
    }
    map<PII, bool> used;
    ll ans = 1;
    ll zero = 0;
    rep(i, n)
    {
        if (a[i] == 0 && b[i] == 0)
        {
            zero += 1;
        }
        else
        {
            if (used[{a[i], b[i]}])
                continue;
            ll tmp = 1;
            tmp += mpow(2, num[{a[i], b[i]}] + num[{-a[i], -b[i]}]) - 1;
            tmp %= MOD;
            tmp += mpow(2, num[{-b[i], a[i]}] + num[{b[i], -a[i]}]) - 1;
            tmp %= MOD;
            used[{a[i], b[i]}] = true;
            used[{-b[i], a[i]}] = true;
            used[{b[i], -a[i]}] = true;
            used[{-a[i], -b[i]}] = true;
            tmp %= MOD;
            ans *= tmp;
        }
        ans %= MOD;
    }
    cout << (ans + MOD - 1 + zero) % MOD << endl;
    return 0;
}

Measured memory_bytes: 106348
import sys
input = sys.stdin.readline
s = list(input()[:-1])
n = len(s)

#0番目を1にする
res = 0
for i in range(n):
    if i%2 == 0 and s[i] == '0':
        res += 1
    elif i%2 == 1 and s[i] == '1':
        res += 1

#0番目を0にする
res2 = 0
for i in range(n):
    if i%2 == 0 and s[i] == '1':
        res2 += 1
    elif i%2 == 1 and s[i] == '0':
        res2 += 1
print(min(res,res2))


Measured memory_bytes: 49392
#define _CRT_SECURE_NO_WARNINGS

#include <set>
#include <map>
#include <deque>
#include <cmath>
#include <queue>
#include <cassert>
#include <random>
#include <bitset>
#include <iomanip>
#include <numeric>
#include <time.h>//////////////
#include <ctime>
#include <string>
#include <cstdio>
#include <vector>
#include <cstdlib>
#include <iostream>
#include <algorithm>
#include <unordered_map>
#include <unordered_set>
//++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++
#define mp make_pair
#define pbc push_back
#define pob pop_back()
#define empb emplace_back
#define queuel queue<long long>
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define matrix vector<vector<ll>>
#define pin(p) cin >> p.first >> p.second;
#define rev(v) reverse(v.begin(), v.end());
#define mx(v) max_element(v.begin(), v.end());
#define mn(v) min_element(v.begin(), v.end());
#define sout(s, c) for (auto i : s) cout << i << c;
#define pout(p) cout << p.first << " " << p.second;
#define er(v, l, r) erase(v.begin() + l, v.begin() + r);
#define vin(v) for (ll i = 0; i < v.size(); ++i) cin >> v[i];
#define vout(v, c) for (int i = 0; i < v.size(); ++i) cout << v[i] << c;
#define pushi(v, a) for (int i = 0; i < a.size(); ++i) v.push_back(a[i]);
#define sin(s, n) for (int i = 0; i < n; ++i){int a; cin >> a; s.insert(a); }
#define fastio() ios_base::sync_with_stdio(0); cout.tie(0); cin.tie(0); srand(time(NULL))
#define sp system("pause")
//++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++
using namespace std;//СЂСџВ¦Р‚СЂСџВ¦Р‚СЂСџВ¦Р‚СЂСџВ¦Р‚СЂСџВ¦Р‚СЂСџВ¦Р‚СЂСџВ¦Р‚СЂСџВ¦Р‚СЂСџВ¦Р‚СЂСџВ¦Р‚
					//++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++
typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;
//++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++
const int MAXN = 1e5 + 228;
const ll inf = 1e9;
const ld EPS = 1e-4;
const ld PI = acos(-1);
const int mod = (int)998244353;
//const int MOD = 1000000007;
const int MOD9 = 1000000009;
const int a228 = 18;
const ll MOD = 1000000007;
const int maxelem = 12000000;
const int fsconst = 12000;

signed main()
{
	fastio();
	int a, b, c;
	cin >> a >> b >> c;
	if (a - b > c)
	{
		cout << 0;
	}
	else
	{
		cout << c - (a - b);
	}
	//sp;
}

Measured memory_bytes: 256
#include <iostream>
#include <climits>
#include <cmath>
#include <algorithm>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <string>
#define INF_INT (INT_MAX / 2)
#define INF_LONG (LONG_MAX / 2)
//#define DEBUG true
#define DEBUG false
using namespace std;

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

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

  int sum = 0;
  for(int i = 0; i + 1 < n + 2; i++){
    sum += abs(a[i] - a[i + 1]);
  }

  string ans;
  for(int i = 1; i <= n; i++){
    int tmp = sum - 
      (abs(a[i] - a[i - 1]) + abs(a[i] - a[i + 1])) +
      abs(a[i - 1] - a[i + 1]);
    ans += to_string(tmp) + "\n";
  }

  cout << ans;

  return 0;
}


Measured memory_bytes: 2676
def main():
    n, m = map(int, input().split())
    field = [list(map(int, input().split())) for _ in range(m)]
    field.sort(key=lambda x: x[1])
    ans = 0
    finish = 0
    for i in field:
        if finish <= i[0]:
            ans += 1
            finish = i[1]
    print(ans)

if __name__ == "__main__":
    main()

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

typedef long long s64;
s64 C2(int n)
{
	return (s64)n*(n-1)/2;
}
#define rep(i,l,r) for(int i=l;i<=r;++i)
const int N=1e5+5;
int fa[N],sz[N];bool d[N],have[N];
int find(int x)
{
	if(fa[x]==x)return x;
	find(fa[x]);
	d[x]^=d[fa[x]];
	return fa[x]=fa[fa[x]];
}

int main()
{
	//freopen("1.in","r",stdin);
	int n,m;
	cin>>n>>m;
	rep(i,1,n){fa[i]=i;sz[i]=1;}
	while(m--)
	{
		int x,y;
		scanf("%d%d",&x,&y);
		int fx=find(x),fy=find(y);
		if(fx==fy)
		{
			have[fx]|=d[x]==d[y];
			continue;
		}
		fa[fy]=fx;d[fy]=d[x]^1^d[y];
		sz[fx]+=sz[fy];
		have[fx]|=have[fy];
	}
	int cnt1=0,cnt[2]={};
	rep(x,1,n)
	if(fa[x]==x)
	if(sz[x]==1)++cnt1;
	else ++cnt[have[x]];
	cout<<(s64)cnt[1]*cnt[0]*2+(s64)cnt1*(n-cnt1)*2
		+(s64)cnt[1]*cnt[1]+(s64)cnt[0]*cnt[0]*2+(s64)cnt1*cnt1;
}

Measured memory_bytes: 1280
#include <stdio.h>

int main(){
  int n, k, i;
  scanf("%d %d", &n, &k);
  double ans = 0.0;
  for(i = 0; i < n; i++){
    int kn = k / (i + 1);
    if(k % (i + 1) != 0){
      kn++;
    }
    int a = 1;
    while(a < kn){
      a <<= 1;
    }
    ans += 1.0 / a;
  }
  printf("%.12f\n", ans / n);
  return 0;
}


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

#define ALL(x) (x).begin(), (x).end()
#define MAX(x) *max_element(ALL(x))
#define MIN(x) *min_element(ALL(x))

using namespace std;
using ll = long long;
using vel = vector<ll>;
using ves = vector<string>;
using veb = vector<bool>;
using qul = queue<ll>;

int main() {
    ll N, sum=0,num,n;
    cin >> N;
    vel yaku(N,1);
    FOR(i, 1, N){
        num = i+1;
        REP(i,N){
            n = num * (i + 1);
            if(n-1>N) break;
            yaku[n - 1]++;
        }
    }

    REP(i,N) sum += (i + 1) * yaku[i];

    cout << sum << endl;
}

Measured memory_bytes: 81332
n=int(input())
s=[input() for _ in range(n)]
from collections import Counter
ans=0
d=Counter()
def combination(n, r):
    a = 1
    b = 1
    for i in range(r):
        a *= (n - i)
        b *= (i + 1)
    return a // b
for i in s:
    a="".join(sorted(list(i)))
    d[a]+=1
for j in d.values():
    ans+=combination(j, 2)

print(ans)

Measured memory_bytes: 75608
import sys

class Node:
    def __init__(self):
        self.id = id
        self.parent = -1
        self.sibling = -1
        self.type = "leaf"

    def printInfo(self):
        print "node {0.id}: parent = {0.parent}, sibling = {0.sibling}, degree = {0.degree}, depth = {0.depth}, height = {0.height}, {0.type}".format(self)

def setTree(id, tree, depth):
    tree[id].depth = depth
    height = degree = 0
    for i in range(2):
        child = tree[id].children[i]
        if child != -1:
            degree += 1
            tree[child].parent = id
            tree[child].sibling = tree[id].children[~i]
            height = max(setTree(child, tree, depth + 1) + 1, height)
    tree[id].height = height
    tree[id].degree = degree
    if height != 0:
        tree[id].type = "internal node"

    return height

if __name__ == "__main__":
    lines = sys.stdin.readlines()
    N = int(lines[0])
    del lines[0]

    tree = []
    for i in range(N):
        tree.append(Node())

    root = N * (N - 1) / 2
    for line in lines:
        info = map(int, line.split())
        tree[info[0]].children = info[1:]
        tree[info[0]].id = info[0]
        for i in tree[info[0]].children:
            if i != -1:
                root -= i

    setTree(root, tree, 0)
    tree[root].type = "root"

    for node in tree:
        node.printInfo()

Measured memory_bytes: 6480
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define INF 1LL<<62
#define inf 1000000007 


int main() {
	ll n,m,a=-100,b=100,A,B;
	cin>>n>>m;
	cin>>A>>B;
	a=max(a,A);b=min(B,b);
	for(int i=0;i<n;i++){
		cin>>A;
		a=max(a,A);
	}
	for(int i=0;i<m;i++){
		cin>>B;
		b=min(b,B);
	}
	cout << (a<b? "No War":"War");
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <map>
#include <set>
#include <vector>
#include <algorithm>
#include <iostream>

#include <bitset>
#include <cassert>
#include <queue>
#include <random>
#include <stack>
#include <iomanip>

using namespace std;

#define rep(i, n) for (int i = 0; i < (int)n;i++)
#define repf(i, a, b) for (int i = (int)a; i < (int)b;i++)
#define repv(x, arr) for (auto& x:arr)
#define all(v) (v).begin(), (v).end()
#define vec(name, num) vector<ll> name((num), 0);
#define mp(a,b) make_pair(a,b)
#define op(i) cout << (i) << endl;

typedef long long ll;
typedef long double ld;
typedef pair<int,int> pii;
typedef pair<ll, ll> pll;
typedef pair<ld, ld> pdd;

const ll mod = 1e9 + 7;

int main(){
    int N, K, X, Y;
    cin >> N >> K >> X >> Y;
    int ans = 0;
    ans += X * min(K,N);
    ans += Y * max(0, N - K);
    cout << ans << endl;
}


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

int main(){
    int a[4], b[2];
    for(int i = 0; i < 4; i++)  cin >> a[i];
    for(int i = 0; i < 2; i++)  cin >> b[i];
    sort(a, a+4);
    sort(b, b+2);
    cout << a[3]+a[2]+a[1]+b[1] << endl;
    return 0;
}


Measured memory_bytes: 3144
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cassert>
#include <algorithm>
#include <numeric>
#include <random>
#include <vector>
#include <array>
#include <bitset>
#include <queue>
#include <set>
#include <unordered_set>
#include <map>
#include <unordered_map>
 
using namespace std;
using uint = unsigned int;
using ll = long long;
using ull = unsigned long long;

int main() {
    int n, k;
    cin >> n >> k;
    int a[n];
    for(int i = 0; i < n; i++){
        cin >> a[i];
    }
    sort(a, a + n);
    int ans = 0;
    for(int j = 0; j < k; j++){
        ans = ans + a[j];
    }
    cout << ans;
    return 0;
}

Measured memory_bytes: 3604
#include <bits/stdc++.h>
using namespace std;
template<class T> bool chmax(T& a,T b) { if (a < b) { a = b; return true; } return false; }
template<class T> bool chmin(T& a,T b) { if (a > b) { a = b; return true; } return false; }

constexpr long long INF = (1LL << 12);

long long f (long long x) { return (x * x * x * x * x); }

long long calc(long long x) {
    long long l = -INF, r = INF;
    while (abs(l - r) > 1) {
        long long mid = (l + r) / 2;
        if (f(mid) <= x) l = mid;
        else r = mid;
    }
    return l;
}

int main() {
    long long n;
    cin >> n;
    
    auto is_five = [&] (long long x) {
        long long l = -INF, r = INF;
        while (abs(l - r) > 1) {
            long long mid = (l + r) / 2;
            if (f(mid) <= x) l = mid;
            else r = mid;
        }
        return (f(l) == x);
    };
    
    long long a, b;
    for (long long i = -INF; i <= INF; i++) {
        long long j = f(i) + n;
        if (is_five(j)) { a = calc(j); b = i; break; }
    }
    assert(f(a) - f(b) == n);
    cout << a << ' ' << b << '\n';
    return 0;
}

Measured memory_bytes: 3632
#include <bits/stdc++.h>
using namespace std;
typedef long long intl;
int main(){
	string s;
	cin>>s;
	intl n=s.size();
	intl ans=0;
	intl where=n-1;
	for(intl i=n-1;i>=0;i--){
		if(s[i]=='B'){
			ans+=(where-i);
			where--;
		}	
	}
	cout<<ans<<endl;
}


Measured memory_bytes: 640
#include<bits/stdc++.h>
using namespace std;
int main()
{

string s,ss;
int a,b,i,j,l;
set<char>q;
cin>>s;
cin>>ss;
if(s.size()==ss.size()){
if(s==ss)
{cout<<"EQUAL\n";}
else if(s>ss)cout<<"GREATER\n";
else if(s<ss)cout<<"LESS\n";
}
else if(s.size()>ss.size())
{
cout<<"GREATER\n";}
else cout<<"LESS\n";
}

Measured memory_bytes: 256
#include<iostream>
#include <string>
#include<vector>
typedef long long ll;

using namespace std;
int main()
{
	int n,t;
	cin >> n>>t;

	vector<int> cs(n);
	vector<int> ts(n);
	for (int i = 0; i < n; i++) {
		cin >> cs[i] >> ts[i];
	}
	int min_cost = 10000;
	for (int i = 0; i < n; i++) {
		if (ts[i] > t) continue;
		min_cost = min_cost < cs[i] ? min_cost : cs[i];
	}
	if (min_cost == 10000) {
		cout << "TLE" << endl;
	}
	else {
		cout<<min_cost << endl;
	}
	
	return 0;
}

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

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
#define REP(i, n) for(int i=0; i<n; i++)
#define REPi(i, a, b) for(int i=int(a); i<int(b); i++)
#define MEMS(a,b) memset(a,b,sizeof(a))
#define mp make_pair
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; }
const ll MOD = 1e9+7;

ll func(ll n){
    if(n < 2)
        return 1;
    else
        return n * func(n-2);
}

ll count(ll n, ll x){
    ll ret = 0;
    ll y = x;
    while(n/y > 0){
        ret += n/y/2;
        y *= x;
    }
    return ret;
}

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

    if(N % 2){
        cout << 0 << endl;
        return 0;
    }

    //ll ans = count(N, 10);
    ll ans = 0;

    ll five = count(N, 5);

    ans = five;
    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 256
#include <algorithm>
#include <array>
#include <cstddef>
#include <cstdint>
#include <iomanip>
#include <iostream>
#include <map>
#include <set>
#include <vector>

using namespace std;

int main()
{
    int n;
    cin >> n;
    vector<int64_t> as(n), bs(n);

    int64_t a_sum = 0, b_sum = 0;

    for (auto& a : as)
    {
        cin >> a;
        a_sum += a;
    }
    for (auto& b : bs)
    {
        cin >> b;
        b_sum += b;
    }

    const auto lim = b_sum - a_sum;
    int64_t a_move = 0, b_move = 0;
    for (int i = 0; i < n; i++)
    {
        if (as[i] > bs[i])
        {
            b_move += as[i] - bs[i];
        }
        else
        {
            a_move += (bs[i] - as[i] + 1) / 2;
        }
    }
    cout << (max(a_move, b_move) <= lim ? "Yes" : "No") << endl;
}


Measured memory_bytes: 384
process.stdin.resume();
process.stdin.setEncoding('utf8');
process.stdin.on('data', function(chunk) {
  var lines = chunk.split("\n");
  var i, len = lines.length;
  var primes = [2, 3];
  var count = 0;

  function isPrime(n) {
    if (n==1) return false;

    var i;
    
    for (i=0; i<primes.length; i++) {
      if (n % primes[i] === 0) {
        return false;
      }
    }
    return true;
  }
  
  for (i=0; i<len; i++) {
    var line = lines[i].split(' ');
    var a = line[0] * 1;
    var b = line[1] * 1;
    var n = line[2] * 1;
    var ans = 0;

    if (!a && !b && !n) {
      break;
    }

    var cnt = 0;
    while (cnt != n) {
      var root = ~~Math.sqrt(a);
      var maxPrime = primes[primes.length-1];
      
      if ( maxPrime < root) {
        for (var j = maxPrime; j <= root; j+=2 ) {
          if (primes.indexOf(j) == -1 && isPrime(j)) {
            primes.push(j);
          }
        }
      }

      if (primes.indexOf(a) > -1 || isPrime(a)) {
       cnt++;
       ans = a;
      } 

      a += b;
    }
    console.log(ans);
  }
});

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

int main() {
    int n , k;
    cin >> n >> k;
    int d[k];
    int a[k][n];
    vector<int> hito(n, 0);
    rep(i, k){
        cin >> d[i];
        rep(j, d[i]){
            cin >> a[i][j];
            hito[a[i][j]-1]++;
        }
    }
    int num = 0;
    rep(i, n){
        // cout << i << " " << hito[i] << endl;
        if(hito[i] == 0){
            num++;
        } 
    }
    cout << num << endl;

}

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

//{{{
/********************************************************************/
struct Fast {Fast(){std::cin.tie(0);ios::sync_with_stdio(false);}} fast;

typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<vector<int> > vii;
typedef queue<int> qi;
typedef stack<int> si;
typedef deque<int> dqi;

#define reps(i, a, b) for (int i = a; i < b; ++i)
#define rep(i, n) reps(i, 0, n)
#define REPS(i, a, b) reps(i, a, b)
#define REP(i, n) rep(i, n)
#define deps(i, a, b) for (int i = a; i >= b; --i)
#define dep(i, n) deps(i, n, 0)
#define DEPS(i, a, b) deps(i, a, b)
#define DEP(i, n) dep(i, n)

#define pf push_front
#define pb push_back
#define mp make_pair
#define fst first
#define FST fst
#define sec second
#define SEC sec
#define sz(obj) ((int)(obj).size())
#define all(v) (v).begin(), (v).end()
#define ALL(v) all(v)

const int INF = 999999999;
const int MOD = 1e9 + 7;
const int dx[] = {0, 1, 0, -1, 1, 1, -1, -1}, dy[] = {1, 0, -1, 0, 1, -1, -1, 1};

vector<int> split(const string &s, char delim) {
  vector<string> elems;
  vector<int> v;
  string item;
  for (char ch: s) {
    if (ch == delim) {
      if (!item.empty()) elems.push_back(item);
      item.clear();
    }
    else item += ch;
  }
  if (!item.empty()) elems.push_back(item);
  for (auto a : elems) v.push_back(stoi(a));
  return v;
}

inline bool inside(int y, int x, int H, int W) {return y >= 0 && x >= 0 && y < H && x < W;}
inline int in() {int x; std::cin >> x; return x;}
template <typename T>
void print(std::vector<T>& v, char c = ' ') {
  REP(i, v.size()) {
    if (i != 0) std::cout << c;
    std::cout << v[i];
  }
  std::cout << endl;
}
template <typename T> void print(T x) { std::cout << x << '\n'; }

/****************************************************************/
//}}}

signed main()
{
  vector<pair<int, int>> vp;
  vector<int> v;
  string str;
  int point = 0, rank = 0;
  map<int, int> m;
  int n;

  while (cin >> str, v = split(str, ','), v[0] + v[1]){
    vp.pb(mp(v[1], v[0] * -1));
  }
  sort(all(vp), greater<pair<int, int>>());
  for (auto a : vp){
    if (point != a.fst){
      rank++;
      point = a.fst;
      m[a.sec * -1] = rank;
    }
    else m[a.sec * -1] = rank;
  }
  while (cin >> n) print(m[n]);

  return (0);
}

Measured memory_bytes: 3000