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

#define ll long long
#define FOR(i,a,b) for (int i=(a);i<(b);++i)
#define REP(i,n) for(int i=0;i<(n);++i)
#define debug(x) cerr<<#x<<": "<<x<<'\n'

using namespace std;
typedef pair<int, int> P;
typedef pair<ll, ll> LP;
typedef pair<int, P> PP;
typedef pair<ll, LP> LPP;

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

template<class T=int>
T in(){T x;cin>>x;return (x);}
template<class T>
void print(T& x){cout<<x<<'\n';}

const int MOD =(int)1e9+7;
const int MAX =510000;

ll fac[MAX],finv[MAX],inv[MAX];
void COMint(){
    fac[0]=fac[1]=1;
    finv[0]=finv[1]=1;
    inv[1]=1;
    for(int i=2;i<MAX;i++){
        fac[i]=fac[i-1]*i%MOD;
        inv[i]=MOD-inv[MOD%i]*(MOD/i)%MOD;
        finv[i]=finv[i-1]*inv[i]%MOD;
    }
}
ll COM(int n,int k){
    if(n<k) return 0;
    if(n<0||k<0)return 0;
    return fac[n]*(finv[k]*finv[n-k]%MOD)%MOD;
}

ll gcd(ll a,ll b){
    if(b==0)return a;
    if(a>b){
        swap(a,b);
    }
    return gcd(a,b%a);
}
ll lcm(ll a,ll b){
    ll g;g=gcd(a,b);
    return a*b/g;
}
int main() {
    //COMint();
    int N=in();
    string ans;ans="Yes";
    int now_t=0;
    int now_x=0;
    int now_y=0;
    int next_t;
    int next_x;
    int next_y;
    int dif;
    int dif_t;
    REP(i,N){
        int next_t=in();
        int next_x=in();
        int next_y=in();
        dif=abs(now_x-next_x)+abs(now_y-next_y);
        dif_t=next_t-now_t;
        //debug(dif);
        //debug(dif_t);
        if(dif>dif_t){
            ans="No";
            break;
        }
        if((dif_t-dif)%2==1){
            ans="No";
            break;
        }
        now_t=next_t;
        now_x=next_x;
        now_y=next_y;
    }
    print(ans);
}

Measured memory_bytes: 256
package main

import "fmt"

func main() {
	var n int64
	fmt.Scan(&n)

	if n % 2 == 0 {
		n /= 2
		answer := int64(0)
		for n > 0 {
			n /= 5
			answer += n
		}
		fmt.Println(answer)
	} else {
		fmt.Println(0)
	}
}

Measured memory_bytes: 512
import scala.io.StdIn
 
object Main {
  def main(args: Array[String]){

	val input = StdIn.readLine().split(" ").map(_.toInt)
	val a  = input(0)
	val b  = input(1)
	val op = solve(a, b)
    println(f"a $op%s b")
  }
  
  def solve(a: Int, b: Int): String = {
	if     (a < b) "<"
	else if(a > b) ">"
	else           "=="
  }
}


Measured memory_bytes: 43840
#include <bits/stdc++.h>
using namespace std;
int main() {
	int n, m;
	cin >> n >> m;
	vector<int> l(m),r(m);
	for (int i = 0;i < m;i++)
		cin >> l[i] >> r[i];
	int L=0, M=n-1;
	for (int i = 0;i < m;i++) {
		if (L < l[i] - 1)
			L = l[i] - 1;
		if (M > r[i] - 1)
			M = r[i] - 1;
	}
	cout << max(M - L+1,0) << endl;
}

Measured memory_bytes: 1024
#include <cstdio>
#include <algorithm>
#include <iostream>
#include <string>
#include <cmath>
#include <functional>
#include <vector>
#include <stack>
#include <queue>
#include <map>
using ll = long long;
using namespace std;

void solve(){

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

    int n;
    cin >> n;
    int ans=0,cnt=-1;

    for (int i=1;i<n+1;i++){
        if (cnt==1){
            int m;
            cin >> m;
            cnt*=-1;
        }
        else if (cnt==-1){
            int m;
            cin >> m;
            if (m==i) {
                ans+=1;
                cnt*=-1;
            }
            else continue;
        }
    }

    cout << ans <<endl;
    


    return 0;
}

Measured memory_bytes: 256
#include <stdio.h>

int main(void){
  int H, W, K;
  scanf("%d%d%d", &H, &W, &K);

  for (int i = 0; i <= H; i++) {
    for (int j = 0; j <= W; j++) {
      if(i*W+j*H-i*j*2 == K){
        printf("Yes\n");
        return 0;
      }
    }
  }

  printf("No\n");

  return 0;
}

Measured memory_bytes: 128
def main():
  n = int(input())
  dp = [[0]*3 for _ in range(n)]
  for i in range(n):
    a, b, c = map(int, input().split())
    if i == 0:
      dp[0][0] = a
      dp[0][1] = b
      dp[0][2] = c
    else:
      dp[i][0] = max(dp[i-1][1],dp[i-1][2])+a
      dp[i][1] = max(dp[i-1][0],dp[i-1][2])+b
      dp[i][2] = max(dp[i-1][0],dp[i-1][1])+c
  output = max(dp[i])
  print(output)


if __name__ == "__main__":
  main()

Measured memory_bytes: 22772
#include<iostream>
#include<iomanip>
#include<vector>
#include<string>
#include<cstring>
#include<map>
#include<set>
#include<queue>
#include<stack>
#include<algorithm>
#include<cmath>
#include<cstdio>
#include<cstdlib>
#include<climits>
#include<fstream>

#define MOD (1000000007)

using namespace std;

typedef long long int Int;

constexpr Int TEN(int n) { return n == 0 ? 1 : 10 * TEN(n-1); }

int main(void) {
    int N;
    cin>>N;
    
    vector<int> P;
    vector<int> Ans;
    for(int i = 0;i < N;i++) {
        int p;
        cin>>p;
        P.push_back(p);
        Ans.push_back(p);
    }

    sort(Ans.begin(),Ans.end());

    int ans = 0;
    for(int i = 0;i < N;i++) {
        if(P[i] != Ans[i]) {
            ans++;
        }
    }

    if(ans == 0 || ans == 2) {
        cout<<"YES"<<endl;
    } else {
        cout<<"NO"<<endl;
    }

    return 0;
}





Measured memory_bytes: 256
use std::io::{stdin, Read, StdinLock};
use std::str::FromStr;

struct Scanner<'a> {
    cin : StdinLock<'a>,
}

impl<'a> Scanner<'a> {
    fn new(cin : StdinLock<'a>) -> Scanner<'a> {
        Scanner { cin: cin }
    }

    fn read1<T: FromStr>(&mut self) -> Option<T> {
        let token = self.cin.by_ref().bytes().map(|c| c.unwrap() as char)
            .skip_while(|c| c.is_whitespace())
            .take_while(|c| !c.is_whitespace())
            .collect::<String>();
        token.parse::<T>().ok()
    }

    fn read<T: FromStr>(&mut self) -> T {
        self.read1().unwrap()
    }
}

fn main(){
    let cin = stdin();
    let cin = cin.lock();
    let mut sc = Scanner::new(cin);
    loop {
        let mut s: String = sc.read();
        if s == "#" { break; };
        let mut y: usize = sc.read();
        let m: usize = sc.read();
        let d: usize = sc.read();
        if y > 31 || y == 31 && m > 4 {
            s = "?".to_string();
            y -= 30;
        }
        println!("{} {} {} {}", s, y, m, d);
    }
}



Measured memory_bytes: 5036
#include <bits/stdc++.h>
#include <iostream>
#include <numeric>
#include <string>
#include <list>
#include <limits>
#include <type_traits>
#include <vector>

using namespace std;

int main(void) {

    string s , t;

    cin >> s;
    cin >> t;


    t.erase(t.size() - 1);

    if (t == s) {
        cout << "Yes";
    }
    else {
        cout << "No";
    }
}

Measured memory_bytes: 3628
import collections
import sys
input = sys.stdin.readline

#n = int(input())
#l = list(map(int, input().split()))

'''
A=[]
B=[]
for i in range():
    a, b = map(int, input().split())
    A.append(a)
    B.append(b)'''

n, k = map(int, input().split())

r=[]
mi=0
ma=0
su=range(n+1)
for i in range(n+1):
    mi+=su[i]
    ma+=su[::-1][i]
    r.append(ma-mi+1)

ans=0
for i in range(k-1,n+1):
    #print(r[i])
    ans+=r[i]
print(ans%(1000000007))


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

using namespace std;

#define ll long long




void solve() {

	int n, c;
	cin >> n >> c;
	if(n >= 13) {
		cout << c;
	}
	else if(n >= 6) {
		cout << c / 2;
	}
	else {
		cout << 0;
	}

	




	
}

int main() {

	ios_base::sync_with_stdio(0);
	cin.tie(NULL);
	solve();

	return 0;
}

Measured memory_bytes: 3644
#include <stdio.h>

int main (void)
{
	int A, B;
	int i;
	int sum = 0;
	
	scanf("%d%d",&A,&B);
	
	for(i = 0; i < 2; i++){
		if(A < B){
			sum += B;
			B -= 1;
		} else {
			sum += A;
			A -= 1;
		}
	}
	
	printf("%d\n",sum);
	
	return 0;
}

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

int main() {
  int a,b,c,d;cin>>a>>b>>c>>d;
  int cnt1=max(a,c),cnt2=min(b,d);
  int ans=max(0,cnt2-cnt1);
  cout<<ans<<endl;
}

Measured memory_bytes: 3636
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef pair<int, int> pi;
typedef vector<pi> vii;

int main(){
  ios::sync_with_stdio(false);
  cin.tie(0);
  int x,y;
  cin>>x>>y;

  cout<< (y-x)*(y-x-1)/2 - x <<"\n";
  return 0;
}


Measured memory_bytes: 256
#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <queue>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <complex>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>
#include <fstream>
#include <stdio.h>

using namespace std;

//conversion
//------------------------------------------
inline int toInt(string s) {int v; istringstream sin(s);sin>>v;return v;}
template<class T> inline string toString(T x) {ostringstream sout;sout<<x;return sout.str();}

//typedef
//------------------------------------------
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<double> VEC;
typedef vector<VEC> MAT;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef pair<int, PII> TIII;
typedef long long LL;
typedef vector<LL> VLL;
typedef vector<VLL> VVLL;
//container util

//------------------------------------------
#define ALL(a)  (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define MP make_pair
#define SZ(a) int((a).size())
#define EACH(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort((c).begin(),(c).end())
#define MT(a,b,c) MP(a, MP(b, c))
#define T1 first
#define T2 second.first
#define T3 second.second

//repetition
//------------------------------------------
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)
#define EPS 1.0e-9

string conv(string s, char c){
	int n=s.length();
	if(c=='J'){
		s=s[n-1]+s.substr(0,n-1);
	}else if(c=='C'){
		s=s.substr(1,n-1)+s[0];
	}else if(c=='E'){
		if(n%2)s=s.substr((n+1)/2,n/2)+s[(n-1)/2]+s.substr(0,n/2);
		else s=s.substr(n/2,n/2)+s.substr(0,n/2);
	}else if(c=='A'){
		reverse(ALL(s));
	}else if(c=='P'){
		REP(i,n)if(isdigit(s[i]))s[i]=((s[i]-'0'+9)%10)+'0';
	}else if(c=='M'){
		REP(i,n)if(isdigit(s[i]))s[i]=((s[i]-'0'+1)%10)+'0';
	}
	return s;	
}

int main(){
	int t;
	cin >> t;
	REP(i,t){
		string s, t;
		cin>>s>>t;
		REP(i,s.size())t=conv(t, s[s.size()-i-1]);
		cout << t << endl;
	}
	return 0;
}

Measured memory_bytes: 1208
#include <bits/stdc++.h>
#define mod 1000000007
#define ll long long int
#define pb(x) push_back(x)
#define MP(x,y) make_pair(x,y)
using namespace std;
ll gcd(ll a,ll b)
{
	if(a%b==0)
		return b;
	else
		return gcd(b,a%b);
}
int hashe[5];
void solve()
{
    int a,b;
    cin>>a>>b;
    hashe[a]++,hashe[b]++;

    cin>>a>>b;
    hashe[a]++,hashe[b]++;

    cin>>a>>b;
    hashe[a]++,hashe[b]++;

    sort(hashe,hashe+5);
    if(hashe[4]==2&&hashe[3]==2&&hashe[2]==1&&hashe[1]==1)
    {
        cout<<"YES";
    }
    else{
        cout<<"NO";
    }
}
int main()
{
	int t=1;
	//cin>>t;
	while(t--)
		solve();
	return(0);
}


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

template<class T> inline bool chmin(T& a, T b) {
	if (a > b) {
		a = b;
		return true;
	}
	return false;
}
template<class T> inline bool chmax(T& a, T b) {
	if (a < b) {
		a = b;
		return true;
	}
	return false;
}

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

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



const long double PI = 3.14159265359;
const int MAX_N = 100010;


signed main() {
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	int n; cin >> n;
	int k; cin >> k;
	string s; cin >> s;
	k--;
	s[k] += 0x20;
	cout << s << endl;
	return 0;
}

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

main(void){
  int A,B,C,X,Y;cin >> A >> B >> C >> X >> Y;
  int ans1=A*X + B*Y;
  int ans2=2*C*max(X,Y);
  int ans3=2*C*min(X,Y)+((Y< X) ? A * (X-Y) : B * (Y - X));
  cout << min({ans1,ans2,ans3});
}
  

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

using namespace std;

#define REP(i,n) for(int (i)=0;(i)<(int)(n);(i)++)

template<typename T> void pv(T a, T b) { for (T i = a; i < b; i++) cout << *i << ' '; cout << endl; }
template<typename T, typename U> void chmin(T &x, U y) { if (y < x) x = y; }
template<typename T, typename U> void chmax(T &x, U y) { if (x < y) x = y; }

int main() {
  int A,B,C;

  cin >> A >> B >> C;

  int mx = max({A,B,C});
  while (true) {
    int diff = mx - A + mx - B + mx - C;
    if (diff % 2 == 0) {
      cout << diff / 2 << endl;
      break;
    }
    mx++;
  }

  return 0;
}



Measured memory_bytes: 256
#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
typedef long long ll;
#define rep(i,n) for (int i = 0; i < (n); i++)
#define repe(i,n) for (int i = 0; i <= (n); ++i)
#define repe1(i,n) for (int i = 0; i <= (n); ++i)
#define all(x) (x).begin(),(x).end()
#define pb(x) push_back(x)
#define eb(k,v) emplace_back(k,v)
#define ct(res) cout << res << "\n";
#define vi vector<int>
#define vl vector<ll>
using namespace std;
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 int INF = 1e9;
const ll MOD = 1000000007;
using Graph = vector<vector<int>>;

int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    int n; cin >> n;
    vi a(n); rep(i,n) cin >> a[i];
    int ans = INF;
    sort(all(a));
    for(int j=a[0]; j<=a[n-1]; ++j) {
        int tmp = 0;
        for(int i=0; i<n; ++i) {
            tmp += pow((a[i]-j),2);
        }
        chmin(ans,tmp);
    }
    ct(ans);
}



Measured memory_bytes: 256
#include <cstdio>
#include <vector>
#include <algorithm>
#include <functional>

using namespace std;

int main() {
  int N, K;
  vector<int> L;
  scanf("%d%d", &N, &K);
  for (int i = 0; i < N; ++i) {
    int li;
    scanf("%d", &li);
    L.push_back(li);
  }
  sort(L.begin(), L.end(), greater<int>());
  int sum = 0;
  for (int i = 0; i < K; ++i)
    sum += L[i];
  printf("%d\n", sum);
}


Measured memory_bytes: 256
L, R = map(int, input().split())
# 2019 = 3*673
p = 673
if R-L>=p:
    print(0)
else:
    ans = 2019
    for i in range(L,R+1):
        for j in range(i+1,R+1):
            ans = min((i*j)%2019, ans)
    print(ans)

Measured memory_bytes: 3060
#include <cstdio>
#include <queue>
#include <vector>
#include <algorithm>
#include <iostream>
using namespace std;

const int SIZE=100005;

vector<int> mp[SIZE];
int id[SIZE];

int main(){
    priority_queue<pair<int,int>,vector<pair<int,int> >,greater<pair<int,int> > > que;
    int n,k;
    scanf("%d",&n);
    for(int i=0;i<n-1;i++){
        int a,b;
        scanf("%d%d",&a,&b);
        a--;
        b--;
        mp[a].push_back(b);
        mp[b].push_back(a);
        id[i]=-1;
    }
    id[n-1]=-1;
    scanf("%d",&k);
    for(int i=0;i<k;i++){
        int v,p;
        scanf("%d%d",&v,&p);
        v--;
        id[v]=p;
        que.push(make_pair(p,v));
    }
    while(!que.empty()){
        pair<int,int> tmp=que.top();
        que.pop();
        int v=tmp.second,value=tmp.first;
        for(int i=0;i<mp[v].size();i++){
            int to=mp[v][i];
            if(id[to]==-1){
                id[to]=value+1;
                que.push(make_pair(id[to],to));
            }
        }
    }
    bool ok=true;
    for(int i=0;i<n;i++){
        for(int j=0;j<mp[i].size();j++){
            if(abs(id[mp[i][j]]-id[i])!=1) ok=false;
        }
    }
    if(!ok) puts("No");
    else{
        puts("Yes");
        for(int i=0;i<n;i++) printf("%d\n",id[i]);
    }
    return 0;
}

Measured memory_bytes: 8320
#include<stdio.h>
#include<math.h>
int main(){
  int n,t,a,i,minnum=0;
  double min=1000000;
  scanf("%d%d%d",&n,&t,&a);
  double h[n+1];
  for(i=0;i<n;i++){
    scanf("%lf",&h[i]);
    double ave=t-a;
    ave=fabs(ave-0.006*h[i]);
    if(ave<min){
      min=ave;
      minnum=i+1;
    }
  }
  printf("%d\n",minnum);
  return 0;
}


Measured memory_bytes: 128
/*
このコード、と～おれ!
Be accepted!
∧＿∧　
（｡･ω･｡)つ━☆・*。
⊂　　 ノ 　　　・゜+.
　しーＪ　　　°。+ *´¨)
 　　　　　　　　　.· ´¸.·*´¨) ¸.·*¨)
		  　　　　　　　　　　(¸.·´ (¸.·'* ☆
					*/

#include <stdio.h>
#include <algorithm>
#include <string>
#include <cmath>
#include <cstring>
#include <vector>
#include <numeric>
#include <iostream>
#include <random>
#include <map>
#include <unordered_map>
#include <queue>
#include <deque>
#include <set>
#include <unordered_set>

#pragma GCC optimize("Ofast")
#define rep(i, n) for(int i = 0; i < (n); ++i)
#define rep1(i, n) for(int i = 1; i < (n); ++i)
#define rep2(i, n) for(int i = 2; i < (n); ++i)
#define repr(i, n) for(int i = n; i >= 0; --i)
#define reprm(i, n) for(int i = n - 1; i >= 0; --i)
#define printynl(a) printf(a ? "yes\n" : "no\n")
#define printyn(a) printf(a ? "Yes\n" : "No\n")
#define printYN(a) printf(a ? "YES\n" : "NO\n")
#define printin(a) printf(a ? "possible\n" : "inposible\n")
#define printdb(a) printf("%.16f\n", a)//少数出力
#define all(x) (x).begin(), (x).end()
#define allsum(a, b, c) ((a + b) * c / 2)//等差数列の和、初項,末項,項数
#define pb push_back
#define priq priority_queue

using ll = long long;

const int INF = 1073741824;
const int MINF = -1073741824;
const ll LINF = ll(4611686018427387903);
const ll MOD = 1000000007;
const double PI = acos(-1);

//マクロとかここまで

using namespace std;

/*-----------------------------------------ここまでライブラリとか-----------------------------------------*/

int main() {

	int n;
	scanf("%d", &n);
	vector<int> a(n),  b(n), c(n);
	rep(i, n)scanf("%d", &a[i]);
	rep(i, n)scanf("%d", &b[i]);
	rep(i, n)scanf("%d", &c[i]);
	sort(all(a));
	sort(all(c));
	ll ans = 0;
	rep(i, n) {
		auto ite = lower_bound(all(a), b[i]);
		int distm = distance(a.begin(), ite);

		ite = upper_bound(all(c), b[i]);
		int distb = distance(ite, c.end());
		ans += (ll)distm * distb;
	}

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

}


Measured memory_bytes: 1408
import numpy as np
import scipy.sparse as sps
import scipy.misc as spm
import collections as col
import functools as func
import itertools as ite
import fractions as frac
import math as ma
from math import cos,sin,tan,sqrt
import cmath as cma
import copy as cp
import sys
import re
import bisect as bs
sys.setrecursionlimit(10**7)
EPS = sys.float_info.epsilon
PI = np.pi; EXP = np.e; INF = np.inf
MOD = 10**9 + 7

def sinput(): return sys.stdin.readline().strip()
def iinput(): return int(sinput())
def imap(): return map(int, sinput().split())
def fmap(): return map(float, sinput().split())
def iarr(n=0):
    if n: return [0 for _ in range(n)]
    else: return list(imap())
def farr(): return list(fmap())
def sarr(n=0):
    if n: return ["" for _ in range(n)]
    else: return sinput().split()
def adj(n): return [[] for _ in range(n)]


#

n = iinput()
a = sorted(iarr())
b = sorted(iarr())
c = sorted(iarr())

cnt = 0
for bb in b:
    avar = bs.bisect_left(a,bb) #bbより小さいものたち
    cvar = n - bs.bisect_right(c,bb) #bb含めて除外
    cnt += avar * cvar
print(cnt)


Measured memory_bytes: 57028
use std::io::{BufRead, BufWriter, Write};

fn main() {
    let stdin = std::io::stdin();
    let stdout = std::io::stdout();
    solve(&mut stdin.lock(), &mut BufWriter::new(stdout.lock()));
}

fn solve<R: BufRead, W: Write>(stdin: &mut R, stdout: &mut BufWriter<W>) {
    let (m0, d0): (usize, usize) = stdin.gets().split(' ').values();

    let mut c = 0;
    for m in 1..(m0 + 1) {
        for d in 1..(d0 + 1) {
            let d1 = d % 10;
            let d2 = d / 10;
            if d1 >= 2 && d2 >= 2 && d1 * d2 == m {
                c += 1;
            }
        }
    }
    writeln!(stdout, "{}", c).unwrap();
}

trait Gets { fn gets(&mut self) -> String; }
impl<T: std::io::BufRead> Gets for T {
    fn gets(&mut self) -> String { self.lines().next().unwrap().unwrap() } }

trait Values<T> { fn values(&mut self) -> T; }
impl<'a, I, T1, T2> Values<(T1, T2)> for I
    where I: Iterator<Item=&'a str>,
          T1: std::str::FromStr, T1::Err: std::fmt::Debug,
          T2: std::str::FromStr, T2::Err: std::fmt::Debug {
    fn values(&mut self) -> (T1, T2) {
        (self.next().unwrap().parse().unwrap(),
         self.next().unwrap().parse().unwrap())
    }
}


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

using LL = long long;

#define ALL(x) (x).begin(), (x).end()
#define RALL(x) (x).rbegin(), (x).rend()
#define FOR(i, a, b) for (int(i) = (a); (i) < (b); ++(i))
#define RFOR(i, a, b) for (int(i) = (a); (i) > (b); --(i))
#define SORT(x) sort(ALL((x)))
#define RSORT(x) sort(RALL((x)))
#define SZ(x) (int)(x).size()
#define debug(x) cerr << #x << " : " << x << '\n'

const int INF = 1e9;
const int MOD = 1e9 + 7;
const LL LINF = 1e18;

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

  LL ans = 0;
  int N;
  cin >> N;
  string S;
  cin >> S;
  LL x = 0;

  FOR(i, 0, N){
    if(S[i] == 'I'){
      x++;
    } else {
      x--;
    }

    ans = max(ans, x);
  }

  cout << ans << '\n';

  return 0;
}

Measured memory_bytes: 3572
import sys
read = sys.stdin.read
readline = sys.stdin.readline
readlines = sys.stdin.readlines

def main():
    N = readline().strip()

    n = ord(N)
    low = list(range(97, 97+ 26))

    if n in low:
        print("a")
    else:
        print("A")




if __name__ == "__main__":
    main()


Measured memory_bytes: 9032
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>

using namespace std;
int main() {
	int n,s;
	cin >> n;
	vector<int>w(n,0);
	vector<int>s1(n,0);
	vector<int>s2(n,0);
	for (int i = 0; i < n; i++) {
		cin >> w[i];
	}
	for (int i = 0; i < n-1; i++) {
		for (int j = 0; j < n; j++) {
			if (i < j) {
				s2[i] += w[j];
			}
			if (i>=j) {
				s1[i] += w[j];
			}
		}
	}
	s = abs(s1[0] - s2[0]);
	for (int i = 0; i < n-1; i++) {
		s = min(s, abs(s1[i] - s2[i]));
		//cout << s1[i] << endl;
		//cout << s2[i] << endl;
	}

	cout << s << endl;
}

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

int main(){
	cin.tie(0),ios::sync_with_stdio(false);
	int x; cin>>x;
	int ans=1;
	for(int i=2;i<=x;++i){
		int a=i*i;
		while(a<=x){
			ans=max(ans,a);
			a*=i;
		}
	}
	cout<<ans<<"\n"s;
}

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

using namespace std;

int main(){
    vector<int> A(5);
    copy_n(istream_iterator<int>(cin), 5, A.begin());

    for (int i = 0; i < 5; i++){
        if (i + 1 != A[i]){
            cout << i + 1 << endl;
            return 0;
        }
    }
}

Measured memory_bytes: 3592
#include <bits/stdc++.h>
#define IO_OP std::ios::sync_with_stdio(0); std::cin.tie(0);
#define F first
#define S second
#define V vector
#define PB push_back
#define MP make_pair
#define EB emplace_back
#define ALL(v) (v).begin(), (v).end()
#define debug(x) cerr << #x << " is " << x << endl

using namespace std;

typedef long long ll;
typedef pair<int, int> pi;
typedef V<int> vi;

const int INF = 1e9 + 7;

bool ok(string s) {
	string t = s;
	reverse(ALL(t));
	return s == t;
}

signed main()
{
	IO_OP;
	
	string s;
	cin >> s;
	if(ok(s) && ok(s.substr(0, s.size()/2))) cout << "Yes" << endl;
	else cout << "No" << endl;

}





Measured memory_bytes: 256
N,M,K=map(int,input().split())
A=[0]+list(map(int,input().split()))
B=[0]+list(map(int,input().split()))
import itertools
A = list(itertools.accumulate(A))
B = list(itertools.accumulate(B))
ans=0
b=M
for a in range(N+1):
  if A[a]>K:
    break
  while  A[a]+B[b]>K:
    b-=1
  ans=max(ans,a+b)
print(ans)

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

int main(){
  int N,M,Q;
  cin>>N>>M>>Q;

  vector<vector<int>> v(Q,vector<int>(4));
  for(int i=0;i<Q;++i){
    cin>>v[i][0]>>v[i][1]>>v[i][2]>>v[i][3];
  }


  queue<pair<vector<int>,int>> que;
  pair<vector<int>,int> p;
  for(int i=0;i<=N;++i) p.first.push_back(0);
  p.first[1]=1;
  p.second=1;
  que.push(p);

  int ans=0;

  while(!que.empty()){

    auto x=que.front();
    que.pop();

    vector<int> y=x.first;
    int z=x.second;
    int subans=0;

    if(z==N){
      for(int i=0;i<Q;++i){
        if(y[v[i][1]]-y[v[i][0]]==v[i][2]) subans += v[i][3];
      }
      ans=max(ans,subans);
    }
    else{
      for(int i=y[z];i<=M;++i){
        y[z+1]=i;
        que.push(make_pair(y,z+1));
      }
    }
  }

  cout<<ans<<endl;
}

Measured memory_bytes: 7860
#include<bits/stdc++.h>
using namespace std;
struct Vote{
    int val;
    string name;
};
bool cmp(Vote a,Vote b){
    if(a.val>b.val){
        return true;
    }
    else{
        if(a.val==b.val){
            return a.name<b.name;
        }
        else{
            return false;
        }
    }
}
int main(){
    map<string,int>m;
    int n;
    cin>>n;
    for(int i=1;i<=n;i++){
        string x;
        cin>>x;
        m[x]++;
    }
    vector<Vote>votes;
    for(auto i:m){
        Vote x;
        x.name=i.first;
        x.val=i.second;
        votes.push_back(x);
    }
    sort(votes.begin(),votes.end(),cmp);
    for(int i=0;i<votes.size();i++){
        if(votes[i].val==votes[0].val){
            cout<<votes[i].name<<endl;
        }
    }
}

Measured memory_bytes: 29680
n = int(input())
s = input()
lis = list(s)

left_w_count = 0
right_e_count = lis[1:].count("E")
ans = right_e_count
for i in range(1,n):
    if lis[i-1] == "W":
        left_w_count += 1
    if lis[i] == "E":
        right_e_count -= 1
    ans = min(ans, left_w_count + right_e_count)

print(ans)


Measured memory_bytes: 8224
#include <iostream>
#include <vector>
#include <cmath>
#include <algorithm>
#include <iomanip>
#define rep(i,n) Rep(i,0,n)
#define Rep(i,k,n) for(int i=k ; i<n ; i++)
#define vi vector<int>
#define Sort(v) sort(v.begin(),v.end())

//const int MOD = 1000000007;
//const int INF = 1<<30;
using namespace std;

void rect(int x,int y){
    rep(i,x){
        rep(j,y){
            cout <<"#";
        }
        cout << endl;
    }
    cout << endl;
}

int main(){
    while(true){
        int a,b;
        cin >> a >> b;
        
        if(a==0 and b==0) break;
        
        rect(a,b);
    }
    
    
}








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

int main(){
	ll x,k,d; cin>>x>>k>>d;
	x=abs(x);
	ll r=x/d;
	if(r>=k) cout<<x-d*k<<endl;
	else if(x<=d){
		if(k%2==0) cout<<x<<endl;
		else cout<<abs(x-d)<<endl;
	}else{
		x-=r*d;
		k-=r;
		if(k%2==0) cout<<x<<endl;
		else cout<<abs(x-d)<<endl;
	}
}

Measured memory_bytes: 3608
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N=1e3+5;
#define endl '\n'

int main(){
	ios::sync_with_stdio(false),cin.tie(0),cout.tie(0);
	ll a,b,c,k;
	cin>>a>>b>>c>>k;
	ll ans=0;
	if(k>=a) {
		ans+=a;
		k-=a;
	}
	else {
		ans+=k;
		k=0;
	}
	if(k>=b) k-=b;
	else k=0;
	if(k>=c) {
		ans-=c;
		k-=c;
	}
	else {
		ans-=k;
		k=0;
	}
	cout<<ans<<endl;
	return 0;
}

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

int main() {
	int w, h;
	while (cin >> w >> h, h || w) {
		vector<vector<int>> c(h, vector<int>(w));
		for (vector<int>& i : c) {
			for (int& j : i) cin >> j;
		}
		int ans = 0;
		vector<vector<bool>> a(h, vector<bool>(w));
		for (int i = 0; i < h; ++i) {
			for (int j = 0; j < w; ++j) {
				if (!a[i][j] && c[i][j]) {
					++ans;
					a[i][j] = true;
					queue<pair<int, int>> b;
					b.emplace(i, j);
					while (!b.empty()) {
						if (b.front().first) {
							if (!a[b.front().first - 1][b.front().second] && c[b.front().first - 1][b.front().second]) {
								a[b.front().first - 1][b.front().second] = true;
								b.emplace(b.front().first - 1, b.front().second);
							}
							if (b.front().second) {
								if (!a[b.front().first - 1][b.front().second - 1] && c[b.front().first - 1][b.front().second - 1]) {
									a[b.front().first - 1][b.front().second - 1] = true;
									b.emplace(b.front().first - 1, b.front().second - 1);
								}
							}
							if (b.front().second != w - 1) {
								if (!a[b.front().first - 1][1 + b.front().second] && c[b.front().first - 1][1 + b.front().second]) {
									a[b.front().first - 1][1 + b.front().second] = true;
									b.emplace(b.front().first - 1, 1 + b.front().second);
								}
							}
						}
						if (b.front().first != h - 1) {
							if (!a[1 + b.front().first][b.front().second] && c[1 + b.front().first][b.front().second]) {
								a[1 + b.front().first][b.front().second] = true;
								b.emplace(1 + b.front().first, b.front().second);
							}
							if (b.front().second != w - 1) {
								if (!a[1 + b.front().first][1 + b.front().second] && c[1 + b.front().first][1 + b.front().second]) {
									a[1 + b.front().first][1 + b.front().second] = true;
									b.emplace(1 + b.front().first, 1 + b.front().second);
								}
							}
						}
						if (b.front().second) {
							if (!a[b.front().first][b.front().second - 1] && c[b.front().first][b.front().second - 1]) {
								a[b.front().first][b.front().second - 1] = true;
								b.emplace(b.front().first, b.front().second - 1);
							}
							if (b.front().first != h - 1) {
								if (!a[1 + b.front().first][b.front().second - 1] && c[1 + b.front().first][b.front().second - 1]) {
									a[1 + b.front().first][b.front().second - 1] = true;
									b.emplace(1 + b.front().first, b.front().second - 1);
								}
							}
						}
						if (b.front().second != w - 1) {
							if (!a[b.front().first][1 + b.front().second] && c[b.front().first][1 + b.front().second]) {
								a[b.front().first][1 + b.front().second] = true;
								b.emplace(b.front().first, 1 + b.front().second);
							}
						}
						b.pop();
					}
				}
			}
		}
		cout << ans << endl;
	}
}


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

using namespace std;

#define FOR(i,k,n) for(int i = (k); i < (n); i++)
#define REP(i,n) FOR(i,0,n)
#define INF 114514810
#define ll long long
#define ALL(a) (a).begin(),(a).end()
#define SORT(v) sort(ALL(v))
//#define scanf scanf_s
typedef pair<int, int> P;

int n;

int main()
{
	cin >> n;
	int ny = 195;
	int uy = 200;
	int y, m, d;
	REP(i, n)
	{
		cin >> y >> m >> d;
		int cnt = 0;
		int year = y; int month = m;
		y = 1000 - y - 1;
		cnt += 590 * (y / 3);
		if (y % 3 == 1) cnt += uy;
		else if (y % 3 == 2) cnt += uy + ny;
		if (year % 3 == 0)
		{
			m = 10 - m;
			cnt += m * 20;
			cnt += 20 - d;
		}
		else 
		{
			m = 10 - m;
			if (month % 2 == 0) cnt += 39 * (m / 2) + 19 - d;
			else cnt += 39 * (m / 2) + 19 + 20 - d;
		}
		cnt++;
		cout << cnt << endl;

	}
	return 0;
}

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

const int inf = 1<<24;
const int pmax = 666001;
int rem[pmax];
int p, n[6], c[6] = { 1, 5, 10, 50, 100, 500 };

void rem_init() {
  rem[0] = 0;
  for ( int i = 1; i < pmax; i++ ) {
    rem[i] = inf;
  }

  for ( int i = 0; i <= pmax; i++ ) {
    for ( int j = 0; j < 6; j++ ) {
      int next_i = i + c[j];
      if ( next_i > pmax ) continue;
      rem[next_i] = min( rem[next_i], rem[i] + 1 );
    }
  }
}

void solve() {
  int pm = 0;
  for ( int i = 0; i < 6; i++ ) pm += n[i] * c[i];

  int answer = 1<<24;
  for ( int i = p; i <= p + 1000; i++ ) {
    int k = 0, s = 0;
    for ( int j = 5; j >= 0; j-- ) {
      if ( n[j] == 0 ) continue;
      int remain = i - s;
      if ( c[j] > remain ) continue;
      int use = min( remain / c[j], n[j] );
      s += use * c[j];
      k += use;
    }
    if ( s != i ) continue;
    // cout << i << "(" << k << ")" << " no oturi ha " << i-p << "(" << rem[i-p] << ")" << endl;
    answer = min( answer, k + rem[i-p] );
  }
  cout << answer << endl;
}

int main() {
  rem_init();

  while ( cin >> p && p ) {
    for ( int i = 0; i < 6; i++ ) {
      cin >> n[i];
    }
    solve();
  }
  return 0;
}

Measured memory_bytes: 0
#include <iostream>
#include <string>
#include <vector>
using namespace std;
typedef long long ll;
#define DUMP(x)  cout << #x << " = " << (x) << endl;
#define FOR(i, m, n) for(ll i = m; i < n; i++)
#define IFOR(i, m, n) for(ll i = n - 1; i >= m; i-- )
#define REP(i, n) FOR(i,0,n)
#define IREP(i, n) IFOR(i,0,n)
#define FOREACH(x,a) for(auto& (x) : (a) )
#define ALL(v) (v).begin(), (v).end()

int main() {
  string s; cin >> s;
  ll ans = 1e18;
  ll d = 26;
  REP(i,d){
    char c = 'a' + i;
    ll tmp = 0;
    ll cnt = 0;
    IREP(j,s.size()){
      if(s[j] == c){
        tmp = max(tmp, cnt);
        cnt = 0;
      }else cnt++;
    }
    tmp = max(tmp,cnt);
    ans = min(ans,tmp);
  }
  cout << ans << endl;
}



Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define lint long long
//#define P pair<int, int>

int main(){
    lint N;
    cin >> N;
    
    if(N == 0){
        cout << 0 << endl;
        return 0;
    }
    if(N == 1){
        cout << 1 << endl;
        return 0;
    }
    
    vector<lint> pList;
    vector<lint> mList;
    lint num = 1;
    int bits;
    
    for(int i = 0; ; ++i){
        if(i % 2 == 0){
            if(i / 2 == 0){
                pList.push_back(1);
            } else {
                pList.push_back(num + pList[i / 2 - 1]);
            }
            
            if(N >= 0){
                if(N <= pList[i / 2]){
                    bits = i;
                    break;
                }
            }
        } else {
            if(i / 2 == 0){
                mList.push_back(-2);
            } else {
                mList.push_back(num + mList[i / 2 - 1]);
            }
            if(N < 0){
                if(N >= mList[i / 2]){
                    bits = i;
                    break;
                }
            }
        }
        num *= -2;
    }
    
//    for(auto e : pList){
//        cout << e << endl;
//    }
//    for(auto e : mList){
//        cout << e << endl;
//    }
//    cout << bits << endl;
    
    bool ans[bits];
    
    for(int i = bits; i >= 2; --i){
        if(i % 2 == 0){
            if(N > 0 && pList[i / 2] >= N && pList[i / 2 - 1] < N){
                ans[i] = 1;
                N -= (1LL << i);
            } else {
                ans[i] = 0;
            }
        } else {
            if(N < 0 && mList[i / 2] <= N && mList[i / 2 - 1] > N){
                ans[i] = 1;
                N += (1LL << i);
            } else {
                ans[i] = 0;
            }
        }
//        cout << N << " ";
    }
    
    if(N == 1){
        ans[0] = 1; ans[1] = 0;
    } else if(N == -1){
        ans[0] = 1; ans[1] = 1;
    } else if(N == -2){
        ans[1] = 1; ans[0] = 0;
    } else {
        ans[0] = 0; ans[1] = 0;
    }
    
    for(int i = bits; i >= 0; --i){
        cout << ans[i];
    }
    cout << endl;
}

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

int main(){
	int n;
	while(cin>>n and n>0){
		string s[n]; rep(i,n) cin>>s[i];
		int cnt=0;
		rep(i,n-1){
			if(s[i]=="lu" and s[i+1]=="ru") cnt++;
			if(s[i]=="ru" and s[i+1]=="lu") cnt++;
			if(s[i]=="ld" and s[i+1]=="rd") cnt++;
			if(s[i]=="rd" and s[i+1]=="ld") cnt++;
		}
		cout<<cnt<<endl;
	}
	return 0;
}



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

int main(){
  int N;
  cin >> N;
  int A[N+1];
  int L[N+1];

  for(int i=1;i<N+1;++i){
     cin >> A[i];
  }
  A[0]=-1;
  L[0]=-1;
  L[1]=A[1];
  int length=1;
  
  for(int i=1;i<N+1;++i){
    if(L[length] < A[i]) L[++length] = A[i];
    if(L[1] > A[i] ) L[1]=A[i];
    else{
      int l=1,r=length,mid;
      while(l<=r){
	mid = (l+r)/2;
	if(A[i] == L[mid] || A[i] == L[mid+1]) break;
	else if(A[i]<L[mid+1] && L[mid]<A[i]){
	  L[mid+1] = A[i];
	  break;
	}else if(A[i]<L[mid]) r=mid;
	else  if(A[i]>L[mid]) l=mid;
      }
    }
    
  }
  
  cout << length << endl;
}

Measured memory_bytes: 1936
#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<cmath>
#include<string>
#include<cstring>
#include<algorithm>
#include<sstream>
#include<complex>
#include<functional>
#include<vector>
#include<map>
#include<queue>
#include<deque>
#include<stack>
#include<set>

using namespace std;
#define endl '\n'

using ll = long long;
using ull = unsigned long long;
using pii = pair<int, int>;
using vi = vector<int>;
using vvi = vector<vector<int>>;
using vl = vector<ll>;

template<typename T = long long>
T gcd(T a, T b) { return b ? gcd(b, a%b) : a; }

// value
int H, W;

vector<char> A;
vector <vector<int>> G;
queue<int> q;
vector<int> v;

int bfs() {
	while (!q.empty()) {
		int n = q.front(); q.pop();
		for (int i = 0; i < G[n].size(); i++) {
			if (v[G[n][i]] > v[n] + 1) {
				v[G[n][i]] = v[n] + 1;
				q.push(G[n][i]);
			}
		}
	}
	return *max_element(v.begin(), v.end());
}

void solve() {

	cin >> H >> W;
	A.resize(H * W);
	G.resize(H * W);
	v.resize(H * W, 1000000);
	for (int y = 0; y < H; y++) {
		for (int x = 0; x < W; x++) {
			cin >> A[W * y + x];
			if (A[W * y + x] == '#') {
				v[W * y + x] = 0;
				q.push(W * y + x);
			}
			if (y > 0) G[W * y + x].push_back(W * (y - 1) + x);
			if (y < H - 1) G[W * y + x].push_back(W * (y + 1) + x);
			if (x > 0) G[W * y + x].push_back(W * y + (x - 1));
			if (x < W - 1) G[W * y + x].push_back(W * y + (x + 1));
		}
	}

	cout << bfs() << endl;

	return;

}

int main() {

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

	solve();

	return 0;

}


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

using namespace std;

#define INF 1145141919810364
typedef long long LL;

LL N, A;

void input()
{
  cin >> N >> A;
}

LL keta(LL l){
  LL ret = 0;
  while(l){
    ret++;
    l /= 10;
  }
  return ret;
}

LL mPow(LL t, LL k)
{
  LL ret = 1;
  for (size_t i = 0; i < k; i++) {
    if(keta(ret) + keta(t) > 15){
      return INF;
    }
    ret *= t;
    if(ret > INF){
      return INF;
    }
  }
  return ret;
}

LL mKake(LL l, LL r)
{
  if(keta(l) + keta(r) > 15){
    return INF;
  }
  else{
    return l*r;
  }
}

LL solve()
{
  LL ret = 1145141919810364;

  for (LL eat = 0; eat < 40; eat++) {
    LL l = 0, r = N+1;
    //cerr << "Eat: " << eat << endl;
    while(r - l > 1){
      LL mid = (r+l)/2;
      //cerr << mid << " " << mPow(mid, eat+1) << endl;
      if(mPow(mid, eat+1) >= N){
        r = mid;
      }
      else{
        l = mid;
      }
    }
    //cerr << eat << " " << r << " " << mPow(r, eat+1) << endl;
    LL M = r; LL m = 0;
    for (m = eat+1; 0 <= m; m--) {
      if(mKake(mPow(M-1, m), mPow(M, eat+1-m)) >= N){
        break;
      }
    }

    ret = min(ret, A*eat + m*(M-1) + (eat+1-m)*M);

  }

  return ret;

}

int main()
{
  input();

  cout << solve() << endl;

  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <iomanip>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <numeric>
#include <bitset>
#include <cmath>

static const int MOD = 1000000007;
using ll = long long;
using u32 = uint32_t;
using namespace std;

template<class T> constexpr T INF = ::numeric_limits<T>::max()/32*15+208;

int main() {
    int n;
    cin >> n;
    vector<pair<int, int>> v(n);
    int ans = 0;
    for (int i = 0; i < n; ++i) {
        cin >> v[i].second >> v[i].first;
    }

    sort(v.begin(),v.end());
    vector<int> l1(n+1, -INF<int>), r1(n+1, INF<int>), l2(n+1, -INF<int>), r2(n+1, INF<int>);
    for (int i = 0; i < n; ++i) {
        l1[i+1] = max(l1[i], v[i].second); r1[i+1] = min(r1[i], v[i].first);
    }
    for (int i = n - 1; i >= 0; --i) {
        l2[i] = max(l2[i+1], v[i].second); r2[i] = min(r2[i+1], v[i].first);
    }
    for (int i = 1; i < n; ++i) {
        ans = max(ans, max(r1[i]-l1[i]+1, 0)+max(r2[i]-l2[i]+1, 0));
    }
    for (int i = 0; i < n; ++i) {
        int lx = max(l1[i], l2[i+1]), rx = min(r1[i], r2[i+1]);
        ans = max(ans, max(rx-lx+1, 0)+v[i].first-v[i].second+1);
    }
    cout << ans << "\n";
    return 0;
}

Measured memory_bytes: 2560
#include <iostream>
#include <vector>
#include <set>
#include <map>
#include <algorithm>
#include <cstdlib>
#include <string>
#include <typeinfo>
using namespace std;
int N;
int main()
{
    cin >> N;
    map<long long, long long> mp;
    long long sum=0;
    
    mp[0]++;
    for(int i=0; i<N; ++i){
        long long a; cin >> a;
        sum += a;  
        mp[sum]++;
    }
    long long ans=0;
    for(auto e: mp){
        ans += (mp[e.first]-1)*mp[e.first]/2;
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 12800
#include <iostream>
#include <vector>
#include <set>
#include <unordered_map>
#include <unordered_set>
#include <cstring>
#include <algorithm>
#include <cmath>
using namespace std;

#define ll long long

int main(){

    ll int n, m;
    cin >> n >> m;
    ll int arr[n];
    ll totalNoOfVotes=0;
    for(ll int i=0; i<n; i++){
        cin >> arr[i];
        totalNoOfVotes+=arr[i];
    }

    ll int threshold = ceil((long double)totalNoOfVotes/(4*m));

    ll int count=0;
    for(int i=0; i<n; i++){
        if(arr[i]>=threshold) count++;
    }

    if(count>=m) cout << "Yes\n";
    else cout << "No\n";

    return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
#include<string.h>
int main()
{
    char s[100000];
    int sum1=0,sum2=0;
    scanf("%s",s);
    for(int i=0;i<strlen(s);i++)
    {
        if(s[i]=='0')sum1++;
        else sum2++;
    }
    if(sum1>sum2 && sum2>0)printf("%d",sum2*2);
    if(sum1<=sum2 && sum1>0) printf("%d",sum1*2);
    if(sum1==0 || sum2==0)printf("0");
    return 0;
}


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

int main() {
    ll N, K;
    cin >> N >> K;
    vector<ll> A(N);
    rep(i, N) cin >> A[i];

    int X = 0;
    vector<ll> bits(40, 0);
    rep(i, N) {
        ll mul = 1;
        for(ll j=0; j<40; j++) {
            if(A[i] & mul) bits[j]++;
            mul *= 2;
        }
    }
    /*rep(i, 40) cout << bits[i] << " ";
    cout << endl;*/

    ll x = 0;
    ll mull = pow(2, 39);
    for(int i=39; i>=0; i--) {
        /*if(bits[i] == N/2 && x+mull <= K) {
            ll zsum=0, osum=0;
            rep(j, N) {
                zsum += A[j]^x;
                osum += A[j]^(x+mull);
            }
            if(osum >= zsum) x += mull;
        }*/
        if(bits[i] <= N/2 && x+mull <= K) x += mull;
        mull /= 2;
    }

    ll res = 0;
    rep(i, N) {
        res += x^A[i];
    }

    cout << res << endl;
    return 0;

}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < n; i++)
#define rep1(i,n) for(int i = 1; i < n; i++)
#define repv(i,n) for(int i = n-1; i >= 0; i--)
#define fi first
#define sc second
#define pb push_back
using namespace std;
typedef long long ll;

char BUF[3500000];
inline void I(int&a){scanf("%d",&a);}
inline void I(int&a,int&b){scanf("%d%d",&a,&b);}
inline void I(int&a,int&b,int&c){scanf("%d%d%d",&a,&b,&c);}
inline void I(int&a,int&b,int&c,int&d){scanf("%d%d%d%d",&a,&b,&c,&d);}
inline void L(ll&a){scanf("%lld",&a);}
inline void L(ll&a,ll&b){scanf("%lld%lld",&a,&b);}
inline void L(ll&a,ll&b,ll&c){scanf("%lld%lld%lld",&a,&b,&c);}
inline void L(ll&a,ll&b,ll&c,ll&d){scanf("%lld%lld%lld%lld",&a,&b,&c,&d);}
inline void S(string&str){str.clear();scanf("%s",BUF);int s=strlen(BUF);rep(i,s)str.pb(BUF[i]);}
inline void SV(vector<int>&v){v.clear();scanf("%s",BUF);int s=strlen(BUF);rep(i,s)if('a'<=BUF[i]&&BUF[i]<='z')v.pb(BUF[i]-'a');else v.pb(BUF[i]-'A');}

const auto EPS = 1e-10;
const auto INF = 100000000;
const auto MOD = 1000000007;
typedef pair<ll,ll> P;

int n, ma, mb;
int dp[401][401];

int main(){
    I(n,ma,mb);
    rep(i,401) rep(j,401) dp[i][j] = MOD;
    dp[0][0] = 0;
    rep(i,n){
        int a, b, c;
        I(a,b,c);
        for(int j = 400-a; j >= 0; j--) for(int k = 400-b; k >= 0; k--){
            if(dp[j][k] == MOD) continue;
            dp[j+a][k+b] = min(dp[j+a][k+b],dp[j][k]+c);
        }
    }
    int ans = MOD;
    for(int i = 1; i <= 1000; i++){
        int a = ma*i, b = mb*i;
        if(a > 400 || b > 400) break;
        ans = min(ans,dp[a][b]);
    }
    if(ans == MOD) ans = -1;
    cout << ans << endl;
}


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

int ctn(int a, int b, int c){
    if(a%2==1 || b%2==1 || c%2==1) return 0;
    else return 1;
}

int main(){
    int A,B,C; cin >> A >> B >> C;
    int count = 0;
    
    while(ctn(A,B,C)){
        if(A==B&&B==C) {count = -1; break;}
        count += 1;
        int a=A; int b=B; int c=C;
        A = (b+c)/2; B=(a+c)/2; C=(a+b)/2;
    }
    cout << count << endl;
}

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

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

int main(){
	map<string,int> mp;
	string s;
	getline(cin,s);
	vector<string> sent;

	int len=s.size();




	string maxStr="";
	int maxNum=-1;

	string tmp="";
	rep(i,len){
		if(s[i]!=' '){
			tmp+=s[i];
		}
		else{
			mp[tmp]+=1;
			sent.pb(tmp);
			if(maxNum<(int)tmp.size()){
				sent.pb(tmp);
				maxStr=tmp;
				maxNum=tmp.size();
			}
			tmp="";
		}
	}
	mp[tmp]+=1;
	sent.pb(tmp);
	if(maxNum<(int)tmp.size()){
		sent.pb(tmp);
		maxStr=tmp;
		maxNum=tmp.size();
	}

	string str="";
	int num=-1;
	for(int i=0;i<sent.size();i++){
		if(num<mp[sent[i]]){
			str=sent[i];
			num=mp[sent[i]];
		}

	}
	cout<<str<<" "<<maxStr<<endl;


	return 0;
}

Measured memory_bytes: 1200
// E - Dist Max
#include <bits/stdc++.h>
using namespace std;
using ll = int64_t;

int main(){
	int N; cin>>N;
	vector<ll> p, m;
	while(N--){
		ll x, y; cin>>x>>y;
		p.push_back(x + y);
		m.push_back(x - y);
	}
	sort(p.begin(), p.end());
	sort(m.begin(), m.end());
	cout<< max(p.back() - p[0], m.back() - m[0]) <<endl;
}


Measured memory_bytes: 6648
#include <bits/stdc++.h>
#define MOD 1000000007
using namespace std;

int main() {
  int N; cin >> N;
  map<int,int> map;
  for (int i =2; i<=N; i++) {
    int tmp =i;
    int j =2;
    while (tmp >1) {
      if (tmp % j ==0) {
        if (map[j] == 0) map[j] = 1;
        else map[j]++;
        tmp /= j;
        j =2;
      } else {
        j++;
      }
    }
  }
  long ans =1;
  for (auto x: map) {
    ans *= x.second +1;
    ans %= MOD;
  }
  cout << ans << endl;
}

Measured memory_bytes: 3632
#include <iostream>
#include <string>
#include <algorithm>
#include <queue>
#include <cstring>
#include <stdio.h>

using namespace std;

typedef long long int lli;

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

	int A[200005] = {};
	int mx = 0;
	cin >> A[0];
	for (int i = 1; i < N; i++) {
		cin >> A[i];
		if (A[i] - A[i-1] > mx) {
			mx = A[i] - A[i - 1];
		}
	}

	if (A[0] + K - A[N - 1] > mx) {
		mx = A[0] + K - A[N - 1];
	}

	int result = K - mx;
	cout << result << endl;

	return 0;
}

Measured memory_bytes: 1152
import java.util.*;
public class Main{
  public static void main(String[] args){
    Scanner sc=new Scanner(System.in);
    int a=sc.nextInt();
    int b=sc.nextInt();
    sc.close();
    int max=Math.max(a+b,a-b);
    max=Math.max(max,a*b);
    System.out.println(max);
  }
}

Measured memory_bytes: 21844