akhauriyash/Code-Regression huggingface dataset:
#include <cstdio>
#include <iostream>
#include <vector>
#include <set>
#include <string>
#include <algorithm>
#include <cmath>

using namespace std;

const int CMax = 100002;

int n, a, b;

int main() {
    scanf("%d %d %d", &n, &a, &b);

    if ((a - b) % 2 == 0) {
        printf("Alice\n");
    } else {
        printf("Borys\n");
    }
}



Measured memory_bytes: 764
from collections import Counter

n = int(input())
a = [int(x) for x in input().split()]

arr1 = []
arr2 = []
for i in range(1, n + 1):
    arr1.append(i - a[i - 1])
    arr2.append(i + a[i - 1])
    
dis1 = Counter(arr1)
dis2 = Counter(arr2)

ans = 0
for i in dis1.keys():
    ans += dis1[i] * dis2[i]

print(ans)

Measured memory_bytes: 64236
s = input()
q = int(input())
ans = []
for i in range(q):
    command = input().split()
    if command[0] == 'print':
        ans.append(s[int(command[1]):int(command[2])+1])
    elif command[0] == 'reverse':
        s = s[:int(command[1])] + s[int(command[1]):int(command[2])+1][::-1] + s[int(command[2])+1:]
    elif command[0] == 'replace':
        s = s[:int(command[1])] + command[3] + s[int(command[2])+1:]
for a in ans:
    print(a)


Measured memory_bytes: 5616
#!/usr/bin/env python3

import sys
input=sys.stdin.readline

n=int(input())
arr=list(map(int,input().split()))
ans=0
for i in range(n):
    for j in range(i+1,n):
        for k in range(j+1,n):
            tmp=[arr[i],arr[j],arr[k]]
            tmp=sorted(tmp)
            s=set(tmp)
            if len(s)==3 and tmp[0]+tmp[1]>tmp[2]:
                ans+=1
print(ans)

Measured memory_bytes: 68556
use std::io::*;
use std::str::FromStr;

fn read<T: FromStr>() -> 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().expect("failed to parse token")
}

#[allow(dead_code)]
struct Main {}

#[allow(dead_code)]
impl Main {}

fn main() {
    let s = read::<String>();
    let t = read::<String>();
    let (t1, _) = t.split_at(t.len()-1);
    if s == t1.to_string() {
        println!("Yes");
    } else {
        println!("No");
    }
}


Measured memory_bytes: 2068
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll zh=0xff0000,MAXN=1e6+10;
int n,k,m,fa[1005];


int main()
{
    int i,x,d,r;
    cin>>r>>d>>x;
    for(i=0;i<10;i++)
    {
        x=x*r-d;
        cout<<x<<endl;
    }
    return 0;
}


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

int main(void){
  int a, b;
  char op;


  while ( scanf("%d %c %d", &a, &op, &b) != EOF){
if ( op == '+' ){
  printf("%d\n", a + b);
} else if ( op == '-' ){
  printf("%d\n", a - b);
} else if ( op == '*' ){
  printf("%d\n", a * b);
} else if ( op == '/' ){
  printf("%d\n", a / b);
 } else if (op == '?'){
  break;
}
  }
  return 0;
}



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

int main(void)
{
  int n;
  double xa, ya,ra,xb,yb,rb;
  double distance;

  scanf("%d",&n);
  while(n-- > 0){
    scanf("%lf %lf %lf %lf %lf %lf",&xa,&ya,&ra,&xb,&yb,&rb);

    distance = sqrt((xa-xb)*(xa-xb)+(ya-yb)*(ya-yb));
    if(ra-rb > distance)
      printf("2\n");
    else if(rb - ra > distance)
      printf("-2\n");
    else if(ra + rb < distance)
      printf("0\n");
    else
      printf("1\n");
  }
  return 0;
}

Measured memory_bytes: 620
#include<bits/stdc++.h>
using namespace std;
 
#define ll long long
#define lf long double
#define pb push_back
#define mp make_pair
#define F first
#define S second
typedef pair <ll,ll> ii;
typedef vector <ll> vi;
typedef vector <ii> vii;
typedef vector <bool> vb;
typedef vector <vector <ll> > vv;
typedef vector <vector <vector<ll> > > vvv;
typedef vector <string> vs;
typedef vector <lf> vf;
#define tr1(x) cerr << #x << ": " << x << endl
#define tr2(x, y) cerr << #x << ": " << x << " | " << #y << ": " << y << endl
#define tr3(x,y,z) cerr<<#x<<": "<<x<<" | "<<#y<<": "<<y<<" | "<<#z<<": "<<z<<endl
#define trv(a) cerr<<#a<<":\n";for(ll zz=0;zz<a.size();zz++) cerr<<a[zz]<<" ";cerr<<endl
#define mod 1000000007ll
#define inf 9999999999999999ll


int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    ll n,m;
    cin>>n>>m;
    vi ans;
    vi s(m),c(m);
    vi digit(n,-1);
    for(ll i=0;i<m;i++)
    {
        cin>>s[i]>>c[i];
        s[i]--;
    }
    for(ll i=0;i<=999;i++)
    {
        string y=to_string(i);
        if(y.size()==n)
        {
            bool p=true;
            for(ll j=0;j<m;j++)
            {
                if(y[s[j]]-'0'!=c[j])
                {
                    p=false;
                    break;
                }
            }
            if(p)
                ans.pb(i);
        }
    }
    if(ans.size()==0)
    {
        cout<<-1<<"\n";
    }
    else
        cout<<ans[0]<<"\n";
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
using namespace std;
using ll = long long;
using P = pair<int, int>;
#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)
#define all(x) x.begin(),x.end()
template<typename T> using min_priority_queue = priority_queue<T, vector<T>, greater<T>>;
template<typename T> T ceil(T a, T b) { return a/b + !!(a%b); }

string s;
ll solve(){
   ll ans=0;
   ll mx=0;
   rep(i,3){
       if(s[i]=='R')ans++;
       else ans=0;
       mx=max(mx,ans);
   }

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

    cin>>s;
    cout<<solve()<<endl;
    return 0;
}

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

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

#define all(x) begin(x), end(x)

using i64 = int_fast64_t;
using f64 = double;
using p64 = pair<i64, i64>;

constexpr i64 INF = INT_FAST64_MAX / 2;

void solve() {
    i64 n;
    cin >> n;
    vector<i64> a(n);
    for (auto& e : a) cin >> e;
    sort(all(a), greater<>());

    n--;
    i64 ans = a[0];
    for (i64 i = 0; i < (n - 1) / 2; i++) {
        ans += a[i + 1] * 2;
    }
    if (n % 2 == 0) ans += a[n / 2];
    cout << ans << endl;
}

int main() {
    cin.tie(nullptr);
    ios_base::sync_with_stdio(false);
    cout << fixed << setprecision(15);
    solve();
}


Measured memory_bytes: 4780
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define ALL(x) (x).begin(), (x).end()
typedef long long ll;
typedef pair<int, int> pii;
const int INF = 1e9;
const int MOD = 1000000007;
const double PI = acos(-1);
int dx[4] = {0,1,0,-1};
int dy[4] = {1,0,-1,0};

int dp[3001][3001];
string dps[3001][3001];

string solve(string s, string t) {
	memset(dp, 0, sizeof(dp));
	int n = s.size();
	int m = t.size();
	for (int i = 1; i <= n; i++) {
		for (int j = 1; j <= m; j++) {
			if (s[i-1] == t[j-1]) {
				dp[i][j] += dp[i-1][j-1] + 1;
			} else {
				dp[i][j] = max(dp[i][j-1], dp[i-1][j]);
			}
		}
	}
	int mx = dp[n][m];
	int l = n ; // sの最右
	int r = m ; // tの最右
	string res = "";
	while (mx > 0) {
		if (s[l - 1] == t[r - 1]) {
			l--;
			r--;
			mx--;
			res += s[l];
		} else if (dp[l][r] == dp[l-1][r]) {
			l--;
		} else {
			r--;
		}
	}
	reverse(ALL(res));
	return res;
}

int main() {
	string s, t;
	cin >> s >> t;
	cout << solve(s, t) << endl;
}

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

int main(){
   int a,b;
   cin >> a >> b;

   if(a <= 8 && b <= 8) {
     cout << "Yay!" << endl;
   } else {
     cout << ":(" << endl;
   }
}


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

typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll, ll> P;
typedef pair<ll, pair<ll, ll> > P3;

const ll MOD = ll(1e9 + 7);
const ll LLINF = LLONG_MAX;
const int IINF = INT_MAX;
const int MAX_N = int(3e5) + 5;
const double EPS = 1e-8;
const int di[] = {0, 1, 0, -1}, dj[] = {1, 0, -1, 0};
string dir = "RDLU";
#define REP(i, n) for (int i = 0; i < n; i++)
#define REPR(i, n) for (int i = n; i >= 0; i--)
#define FOR(i, m, n) for (int i = m; i < n; i++)
#define SORT(v) sort((v).begin(), (v), end())
#define SORTR(v) sort((v).rbegin(), (v), rend())
#define ALL(v) (v).begin(), (v).end()


int main() {
    int a[3];
    cin >> a[0] >> a[1] >> a[2];
    sort(a,a+3);
    cout << a[2]*10+a[1]+a[0] << endl;
    return 0;
}


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

int main() {
  int n,k;
  cin>>n;
  if(n==1) {int x; cin>>x; cout<<x<<endl;}
  else if (n==2) {
  	int x, y; 
    cin>>x>>y;
   	cout<<max(x,y)-min(x,y)<<endl;
  }
  else {
    ll dp[n][n]={0};
    int a[n];
    ll sum = 0;
    for(int j=0,i=0;j<n;j++,i++) {cin>>a[i]; dp[i][j] = a[i]; sum+=dp[i][j];} 
    for(int i=1,j=0;i<n;j++,i++) dp[j][i] = max(dp[j+1][i], dp[j][i-1]); 

    for(int i=n-3;i>=0;i--) {
      for(int k=i,j=n-1;k>=0;j--,k--) {
        dp[k][j] = max(a[k]+ min(dp[k+2][j], dp[k+1][j-1]), a[j]+min(dp[k+1][j-1],dp[k][j-2]));
      }
    }
    
    // for(int i=0;i<n;i++) {
    //     for(int j=0;j<n;j++) {
    //         cout<<dp[i][j]<<" ";
    //     }cout<<endl;
    // }
    
    ll x = dp[0][n-1];
    ll y = sum - x;
    cout<<x-y<<endl;    
  }
}

Measured memory_bytes: 70528
//#include <algorithm>
//#include <cctype>
//#include <climits>
#include <cmath>
//#include <complex>
//#include <cstdlib>
//#include <cstring>
//#include <ctime>
//#include <deque>
//#include <functional>
//#include <iomanip>
#include <iostream>
//#include <map>
//#include <queue>
//#include <set>
//#include <sstream>
//#include <stack>
//#include <string>
#include <vector>
//const double pi = 3.14159265358979;
using namespace std;
//typedef long long int lli;
//typedef long long llong;
typedef vector <int> vi;
//typedef vector <llong> vll;
//typedef vector <vi> vvi;
//typedef vector <double> vd;
//typedef vector <string> vs;
//typedef map <int,int> mapii;
//typedef map <char,char> mapcc;
//#define EPS 1e-6
//#define REP(i,n) for (int i=0; i<n; i++)
//#define REP1(i,n1,n2) for (int i=n1; i<n2; i++)
//#define x(ALL) x.begin(), x.end()
//vi primes;
//string A2Z="abcdefghijklmnopqrstuvwxyz";
vi SIEVES;
vi sieve(int n){
    vi s;
    int i,j,m,x,h;
    for (i=1;i<n+2;i+=2) s.push_back(i);
    m=pow(n,0.5)+1;
	h=s.size();
    s[0]=0;
    for (i=0;i<h;i++){
        x=s[i];
        if (x>m) break;
        if (x&&x+i<h)
            for (j=i+x;j<h;j+=x) s[j]=0;
    }
	s[0]=2;
	return s;
}
int main(void){
	int m=105000,n,s,c,i;
	SIEVES=sieve(m);
	while (true){
		cin>>n;
		if (n==0) break;
		s=0;
		c=0;
		for(i=0;i<m;i++)
			if(SIEVES[i]!=0){
				s+=SIEVES[i];
				if(++c==n) break;
			}
		cout<<s<<"\n";
	}
} 

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

int main(void){
    int h,w,n,i,black;
    cin >> h >> w >> n;
    black = 0;

    if(h >= w){
        for(i=1; black < n ;i++){
            black += h;
            if(black >= n) break;
        }
    }else{
        for(i=1; black < n ;i++){
            black += w;
            if(black >= n) break;
        }
    }
    cout << i << endl;

    return 0;
}

Measured memory_bytes: 256
#include <stdio.h>

void Syutoku(int N, int* A);
int Sum(int N, int* A, int D);

int main(){

	int N,D,X,ans,A[100] = {0};
	scanf("%d %d %d",&N,&D,&X);
	
	Syutoku(N,&A[0]);
	ans = X + Sum(N,&A[0],D);

	printf("%d",ans);
	
	return 0;
}


void Syutoku(int N, int* A){
	for(int i = 0; i < N; i++){
		scanf("%d",&A[i]);
	}
}

int Sum(int N, int* A, int D){
	int sum = 0;
	for(int i = 0; i < N; i++){
		sum += D / A[i];
		if(D % A[i] != 0) sum++;
	}

	return sum;
}

Measured memory_bytes: 128
import java.io.*;

class Main {
	public static void main(String[] args) {
		BufferedReader kb = new BufferedReader( new InputStreamReader( System.in ) );
		try {
	        String s = kb.readLine();
	        String p = kb.readLine();
	        
	        int slen = s.length();
	        int plen = p.length();
	        int j = 0;
			int ij;	        
			for( int i = 0; i<slen; i++ ) {
				if( p.charAt( 0 ) == s.charAt( i ) ) {

					for( j = 0; j<plen; j++ ) {
						ij = ( i+j ) % slen;
						if( p.charAt( j ) != s.charAt( ij ) ) {
							break;
						}
					}
				}
				if( plen == j ) { break; }
			}
			
			if( plen == j ) {
				System.out.println( "Yes" );			
			} else {
				System.out.println( "No" );
			}
		} catch( IOException e ) {
			System.err.println( e );
		}
	}
}

Measured memory_bytes: 17060
import java.util.*;
public class Main {

	static boolean isprime(int N) {
		if(N <= 1)
			return false;
		else if(N == 2)
			return true;
		for(int i = 2; i <= Math.sqrt(N); i++)
			if(N % i == 0)
				return false;
		return true;
	}
	
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		int i = 0, j = 11;
		while(i < N) {
			if(isprime(j) && j % 5 == 1) {
				System.out.print(j + " ");
				i++;
			}
			j+=2;
		}
	}

}


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

using namespace std;
#define rep(i, n) for(int i=0;i<n;i++)
#define REP(i, n) for(int i=1;i<=n;i++)
typedef long long ll;

int main() {
	int n;
	cin >> n;
	map<int, int> d;
	rep(i, n) {
		int D;
		cin >> D;
		d[D]++;
	}
	int m;
	cin >> m;
	map<int, int> t;
	rep(i, m) {
		int T;
		cin >> T;
		t[T]++;
	}
	bool ok = true;
	for (auto p: t) {
		if (p.second > d[p.first]) ok = false;
	}
	if (ok) {
		cout << "YES" << endl;
	} else {
		cout << "NO" << endl;
	}
	return 0;
}

Measured memory_bytes: 18944
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
using pii = pair<int, int>;



int main() {
    ios_base::sync_with_stdio(false);
    int n, m;
    int x;
    cin >> n;
    map<int, int> A, B;
    set<int> C;
    for(int i = 0; i < n; ++i){
        cin >> x;
        ++A[x];
        C.insert(x);
    }
    cin >> m;

    for(int i = 0; i < m; ++i){
        cin >> x;
        ++B[x];
        C.insert(x);
    }
    bool ans = true;
    for(auto p: C){
        if(A[p] < B[p]){
            cout << "NO" << endl;
            return 0;
        }
    }
    cout << "YES" << endl;
    return 0;


    return 0;
}

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

using namespace std;

#define all(x) (x).begin(), (x).end()
#define pb(x) push_back(x)
#define vi vector<int>

#define ll long long int

int ctoi(char c) {return c-'0';}
int ord(char c) {return c-'a';}
int len(string s) {return s.length();}
int itoc(int i) {return i+'a';}

int main() {
int N;
cin>>N;
if(N==7 or N==5 or N==3) cout<<"YES"<<endl;
else cout<<"NO"<<endl;
return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
typedef long long int ll;
using namespace std;
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
   // ll n,i;
    int n,i;
    cin>>n;
    int a[n];
    for(i=0; i<n; i++){
       cin>>a[i];
    }
    sort(a,a+n);
    ll ans=a[n-1]-a[0];
    cout<<ans<<endl;
    return 0;
}


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

typedef long long ll;
typedef long long LL;
typedef pair<int,int> ii;
typedef vector<ii> vii;
typedef vector<int> vi;

#ifdef DEBUG
    #define cek(x) cout<<x
#else
    #define cek(x) if(false){}
#endif // DEBUG

#define fi first
#define se second
#define INF 1000000000
#define INFLL 1000000000000000000LL
#define EPS 1e-9
#define PI acos(-1.0)
#define pb push_back
#define TC() while(tc--)
#define FOR(i,n) for(int i=0;i<n;i++)
#define FORN(i,n) for(int i=0;i<=n;i++)
#define REP(i,a,b,c) for(int i=a;i<b;i+=c)
#define REPN(i,a,b,c) for(int i=a;i<=b;i+=c)
#define reset(a,b) memset(a,b,sizeof(a))
#define sc(x) scanf("%d",&x)

int n,a,b;

void pre(){

}

void read(){
	cin >> n >> a >> b;
}

void solve(){
	if(a > b){
		printf("0");
		return;
	}else if(n == 1){
		if(a == b){
			printf("1");

		}else printf("0");
		return;
	}

	ll small = 1LL * a * (n - 2);
	ll big = 1LL * b * (n - 2);
	cout << big - small + 1<< endl;
}

int main(void){
	pre();
	read();
	solve();

    return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<algorithm>
using namespace std;
int main(){
  vector<int> W,K;
  for(int i=0,j; i<10; i++){
    cin >>j;
    W.push_back(j);
  }
  for(int i=0,j; i<10; i++){
    cin >>j;
    K.push_back(j);
  }
  sort(W.begin(),W.end());
  sort(K.begin(),K.end());
  cout <<W[9]+W[8]+W[7]<<" "<<K[9]+K[8]+K[7]<<endl;
  return 0;
}

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

int main() {
	int n, m, L, R;
	cin >> n >> m;
	int st = 1, en = n;
	for (int i = 0; i < m; i++) {
		cin >> L >> R;
		st = max(st, L);
		en = min(en, R);
	}
	cout << max(0, en - st + 1) << endl;
	return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define T 20005
#define N 105
using namespace std;
int n,m,t,a[N],A[T],ans;

int main(){
  cin>>n>>m>>t;
  for(int i=0;i<n;i++){
    cin>>a[i];
    A[a[i]-m]++;
    A[a[i]+m+1]--;
  }
  for(int i=1;i<=t;i++)
    A[i]+=A[i-1];
  int f=0;
  for(int i=0;i<=t;i++){
    if(!A[i])ans++;
    else if(i&&f&&!A[i-1])ans++;
    if(A[i])f=1;
  }
  cout<<ans<<endl;
  return 0;
}

Measured memory_bytes: 3140
n = int(input())
d = dict()
for i in range(n):
    a = input()
    if a in d:
        d[a] = d[a] + 1
    else:
        d[a] = 0
m = max(d.values())
l = []
for i in d:
    if d[i] == m:
        l.append(i)
l.sort()
for i in l:
    print(i)

Measured memory_bytes: 32096
import Data.List
main = do
  [n,k] <- map (read::String->Int) . words <$> getLine
  s <- map (map (read::String->Int)) . map words . lines <$> getContents
  print $ length $ foldl1 intersect [[1..n]\\x | (i, x) <- zip [0..] s, odd i]

Measured memory_bytes: 5972
import java.util.*;

public class Main {
    static final int SIZE = 40;
	public static void main (String[] args) {
		Scanner sc = new Scanner(System.in);
		int x = sc.nextInt();
		int y = sc.nextInt();
		int z = sc.nextInt();
		int k = sc.nextInt();
		long[] xArr = new long[x];
		long[] yArr = new long[y];
		long[] zArr = new long[z];
		for (int i = 0 ; i < x; i++) {
		    xArr[i] = sc.nextLong();
		}
		for (int i = 0 ; i < y; i++) {
		    yArr[i] = sc.nextLong();
		}
		for (int i = 0 ; i < z; i++) {
		    zArr[i] = sc.nextLong();
		}
		PriorityQueue<Long> xy = new PriorityQueue<>();
		for (int i = 0; i < x; i++) {
		    for (int j = 0; j < y; j++) {
		        xy.add(- xArr[i] - yArr[j]);
		    }
		}
		PriorityQueue<Long> xyz = new PriorityQueue<>();
		for (int i = 0; i < k && xy.size() > 0; i++) {
		    long tmp = xy.poll();
		    for (int j = 0; j < z; j++) {
		        xyz.add(tmp - zArr[j]);
		    }
		}
		StringBuilder sb = new StringBuilder();
		for (int i = 0; i < k; i++) {
		    sb.append(- xyz.poll()).append("\n");
		}
		System.out.print(sb);
    }
}



Measured memory_bytes: 195724
n=int(input())
p=int(n**0.5)
t=0
for i in range(10**5):
    if i*(i+1)//2>n:
        t=i
        l=t*(t+1)//2-n
        break
for i in range(1,t+1):
    if i!=l:
        print(i)

Measured memory_bytes: 3316
#include <cstdio>
#include <cstring>
#include <cmath>
#include <cassert>
#include <vector>
#include <string>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <algorithm>
#include <iostream>
#include <numeric>

/* debug macros */
#ifdef WAFDAYO
#define DBG_LINE() {std::cerr<<"\e[2m[L"<<__LINE__<<"]\e[m ";}
#define DBG_PRINT(s,t,u) {std::cerr<<(s)<<" \e[2m=\e[m \e[1m"<<(t)<<"\e[m"<<(u);}
#define SELECT_7TH(x1,x2,x3,x4,x5,x6,x7,...) x7
#define dbg1(x1) DBG_PRINT(#x1,x1,std::endl)
#define dbg2(x1,x2) DBG_PRINT(#x1,x1,", ")dbg1(x2)
#define dbg3(x1,x2,x3) DBG_PRINT(#x1,x1,", ")dbg2(x2,x3)
#define dbg4(x1,x2,x3,x4) DBG_PRINT(#x1,x1,", ")dbg3(x2,x3,x4)
#define dbg5(x1,x2,x3,x4,x5) DBG_PRINT(#x1,x1,", ")dbg4(x2,x3,x4,x5)
#define dbg6(x1,x2,x3,x4,x5,x6) DBG_PRINT(#x1,x1,", ")dbg5(x2,x3,x4,x5,x6)
#define dbg(...) DBG_LINE()\
SELECT_7TH(__VA_ARGS__,dbg6,dbg5,dbg4,dbg3,dbg2,dbg1)(__VA_ARGS__)
#else
#define dbg(...) {}
#endif

/* utility functions */
struct read_item{read_item(){};
template<class T>operator T(){T t;std::cin>>t;return t;}};
char splf(int i,int n){return(i+1<n)?' ':'\n';};
template<bool up>
struct _RI{int i;_RI(int a):i(a){}
int operator*(){return i;}void operator++(){i+=(up?1:-1);}
bool operator!=(const _RI& r){return up?i<r.i:i>=r.i;}};
template<bool up>
struct _RX{_RI<up> x,y;_RI<up> begin(){return x;}_RI<up> end(){return y;}
_RX(int a,int b):x(up?a:(a-1)),y(b){}_RX(int a):_RX(up?0:a,up?a:0){}};
typedef _RX<true> range;
typedef _RX<false> revrange;

/* types and constants */
typedef int64_t i64;
typedef uint64_t u64;
// const i64 inf = (i64)1.05e18;
// const int inf = (int)1.05e9;

using namespace std;

int main() {

	int N;
	scanf("%d", &N);

	vector<i64> As(N);
	for(auto i : range(N)) {
		int d;
		char buf[42] = {0};
		scanf("%d.%s", &d, buf);
		for(auto pos : revrange(9)) {
			if(buf[pos] == '\0') {
				buf[pos] = '0';
			}
		}
		int e = atoi(buf);
		As[i] = d * (i64)1e9 + e;
	}

	vector<pair<int,int>> factors;
	for(i64 a : As) {
		int x = 0, y = 0;
		while(a % 5 == 0) {
			a = a / 5;
			x += 1;
		}
		while(a % 2 == 0) {
			a = a / 2;
			y += 1;
		}
		x = min(x, 18);
		y = min(y, 18);
		factors.push_back({x, y});
		dbg(a, x, y);
	}
	sort(factors.begin(), factors.end());

	i64 ans = 0;
	array<int,19> nums = {};
	int it = N - 1;

	for(auto i : range(N)) {

		int x = factors[i].first;
		int y = factors[i].second;

		while(it >= 0 && factors[it].first >= 18 - x) {
			nums[factors[it].second] += 1;
			it = it - 1;
		}

		for(auto j : range(18 - y, 19)) {
			ans += nums[j];
		}

		if(x * 2 >= 18 && y * 2 >= 18) {
			ans -= 1;
		}
	}

	printf("%lld\n", ans / 2);

	return 0;
}

/* wafdayo~~~ */


Measured memory_bytes: 6768
#include <bits/stdc++.h>
using namespace std;
#define repr(i, a, b) for (int i = a; i < b; i++)
#define rep(i, n) for (int i = 0; i < n; i++)
typedef long long ll;
#define mod 1000000007

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

int main(){
    ll ans=1001;
    ll d,g;
    cin >> d >> g;
    vector<ll> p(d);
    vector<ll> c(d);
    vector<ll> flag(d);
    for(int i=0;i<d;i++){
        cin >> p[i] >> c[i];
    }
    for(int i=0;i<(1<<d);i++){
        ll total=0;
        ll kazu=0;
        for(int j=0;j<d;j++){
            flag[j]=1;
        }
        for(int j=0;j<d;j++){
            if(i&(1<<j)){
                flag[j]=0;
                total+=p[j]*(j+1)*100+c[j];
                kazu+=p[j];
            }
        }
        if(total>=g){
            ans=min(ans,kazu);
            continue;
        }
        for(int j=d-1;j>=0;j--){
            if(flag[j]){
                for(int k=0;k<p[j]-1;k++){
                    total+=(j+1)*100;
                    kazu++;
                    if(total>=g){
                        ans=min(ans,kazu);
                        break;
                    }
                }
                break;
            }
        }
    }
    
    cout << ans << endl;

    return 0;
}











Measured memory_bytes: 256
package main

import (
	"fmt"
)

func main() {
	var a int
	fmt.Scan(&a)

	nums := make([]int, a)

	for i := range nums {
		fmt.Scan(&nums[i])
	}

	count := 0
	for i := 1; i < a-1; i++ {
		num1 := nums[i+1] - nums[i]
		num2 := nums[i] - nums[i-1]

		//fmt.Printf("num1:%d,num2:%d\n", num1, num2)
		if num1 < 0 && num2 < 0 {
			count++
		}
		if num1 > 0 && num2 > 0 {
			count++
		}
	}
	fmt.Println(count)
}


Measured memory_bytes: 512
#include <iostream>
#include <vector>
#include<algorithm>
#include<iomanip>
#include<queue>
using namespace std;
#define rep(i,n) for(int i=1;i<=(int)(n);i++)
#define Rep(i,n) for(int i=0;i<=(int)(n-1);i++)

int main() {
	int N,R;
	while(cin>>N>>R && N>0 && R>0){
		int p[R],c[R];
		Rep(i,R) cin>>p[i]>>c[i];
		int card[N];
		Rep(i,N) card[i] = N - i;
		Rep(i,R) rotate(card,card+p[i]-1,card+p[i]+c[i]-1);
		cout<<card[0]<<endl;
	}
	return 0;
}


Measured memory_bytes: 2992
#include<bits/stdc++.h>
#define debug printf("%d %s\n",__LINE__,__FUNCTION__)
typedef long long ll;
typedef std::pair<int,int> pii;
#define pb push_back
#define mk make_pair
#define fi first
#define se second

int _w;FILE* _f;

using namespace std;

const int N=3001;

int R,C,K,val[N][N];

ll f[N][N][4],ans;

int main(){
    scanf("%d%d%d",&R,&C,&K);
    for(int i=1,u,v,w;i<=K;i++){
        scanf("%d%d%d",&u,&v,&w);
        val[u][v]=w;
    }
    for(int i=1;i<=R;i++){
        for(int j=1;j<=C;j++){
            for(int k=1;k<=3;k++){
                f[i][j][k]=max(max(f[i-1][j][3],f[i][j-1][k-1])+val[i][j],f[i][j-1][k]);
                ans=max(ans,f[i][j][k]);
            }
        }
    }
    printf("%lld\n",ans);
    return 0;
}

Measured memory_bytes: 320244
#include <bits/stdc++.h>
#pragma GCC optimize("O3")
#define REP(i,n) for(int i=0;i<n;i++)
#define REPP(i,n) for(int i=1;i<=n;i++)
#define ALL(obj) (obj).begin(), (obj).end()
#define EPS (1e-9)
#define INF (1e17)
#define PI (acos(-1))
//const double PI = acos(-1);
//const double EPS = 1e-15;
//long long INF=(long long)1E17;
#define i_7 (long long)(1e9+7)
//#define i_7 998'244'353
long mod(long a){
    long long c=a%i_7;
    if(c>=0)return c;
    return c+i_7;
}
using namespace std;

bool prime_(int n){
  if(n==1){
    return false;
  }else if(n==2){
    return true;
  }else{
    for(int i=2;i<=sqrt(n);i++){
      if(n%i==0){
        return false;
      }
    }
    return true;
  }
}

long long gcd_(long long a, long long b){
  if(a<b){
    swap(a,b);
  }
  if(a%b==0){
    return b;
  }else{
    return gcd_(b,a%b);
  }
}
 
long long lcm_(long long x, long long y){
  return (x/gcd_(x,y))*y;
}

int main(){
  
  long long n,a,b,c,d,e;
  cin>>n>>a>>b>>c>>d>>e;
  long long m = min(a,min(b,min(c,min(d,e))));
  long long ans = (n+m-1)/m;
  ans += 4LL;
  cout<<ans<<endl;
    
  return 0;
}


Measured memory_bytes: 384
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <iomanip>
#include <functional>
#include <list>
using namespace std;

int main(){
	int n, k;
	cin >> n >> k;
	int x;
	vector <int> no(n + 1,0);
	for (int i = 0; i < n; i++) {
		cin >> x;
		no[x]++;
	}
	sort(no.begin(), no.end(),greater<int>());
	for (x = 0; no[x] != 0; x++);
	int ans = 0;
	for (int i = x - 1; i > k - 1; i--) {
		ans += no[i];
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
#define rep(i, x, y) for (int i = x; i <= y; i++)
using namespace std;

const int N = 1e5 + 10;
typedef long long ll;
ll n, m, lst[26], now[N][26], x;
ll ans;
char s[N], t[N];
vector<int> pos[26];

int main() {
    scanf("%s", s + 1);
    scanf("%s", t + 1);
    n = strlen(s + 1), m = strlen(t + 1);
    rep(i, 1, n) {
        pos[s[i] - 'a'].push_back(i);
    }
    rep(i, 1, m) {
        if (pos[t[i] - 'a'].size() < 1) {
            puts("-1"); return 0;
        }
    }

    for (int i = n; i >= 0; i--) {
        rep(j, 0, 25)
            now[i][j] = lst[j];
        if (i)
            lst[s[i] - 'a'] = i;
    }
    rep(i, 1, m) {
        int id = t[i] - 'a';
        if (i == 1) {
            x = 1, ans = now[0][id];
        } else {
            if (!now[ans - (x - 1) * n][id]) {
                ans = x * n + now[0][id];
                x++;
            } else {
                ans = (x - 1) * n + now[ans - (x - 1) * n][id];
            }
        }
    }
    printf("%lld\n", ans);
    return 0;
}


Measured memory_bytes: 21376
#include <iostream>
#include <string>
#include <sstream>
#include <iomanip> 
#include <math.h>
#include <stdio.h>
#include <string.h>
#include <queue>
#include <stack>
#include <vector>
#include <map>
#include <set>
#include <functional>
#include <algorithm>
#include <unordered_map>
#include <unordered_set>
#include <bitset>

using namespace std;


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

	int n, k, i, j, t;
	long double s, x;
	
	cin >> n >> k;

	s = 0;
	for (i = 1; i <= n; i++) {
		x = 1.0 / n;
		t = i;
		while (t < k) {
			t *= 2;
			x *= 0.5;
		}
		s += x;
	}

	cout << setprecision(10) << fixed << s << "\n";


	
	return 0;
}


Measured memory_bytes: 256
from collections import deque

H, W = map(int, input().split())
grid = [input() for _ in range(H)]

graph = [[float('inf')] * W for _ in range(H)]
offsets = [(1, 0), (-1, 0), (0, 1), (0, -1)]

def bfs(x, y):
    graph[x][y] = 0

    deq = deque()
    deq.append((x, y))
    
    while deq:
        x, y = deq.popleft()
        
        for i, j in offsets:
            if (not 0 <= x + i < H) or (not 0 <= y + j < W):
                continue
                
            if graph[x + i][y + j] < float('inf'):
                continue
                
            if grid[x + i][y + j] == '#':
                continue
                
            graph[x + i][y + j] = graph[x][y] + 1
            deq.append((x + i, y + j))
            

bfs(0, 0)
if graph[-1][-1] == float('inf'):
    print(-1)
else:
    black = sum(s.count('#') for s in grid)
    print(H * W - graph[-1][-1] - black - 1)


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

    string str;
    cin>>str;
    int i=0,s,sum=0;
    while(str[i]!='\0')
    {
         s = str[i] - '0';

       sum = sum + s;
        i++;
    }
    if(sum%9==0)
        cout<<"Yes"<<endl;
    else
        cout<<"No"<<endl;

    return 0;
}


Measured memory_bytes: 3700
#include<bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < n; ++i)
#define rrep(i,n) for (int i = n-1; i >= 0; i--)
#define rep2(i,s,n) for (int i = s; i < n; ++i)
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define tmax(a,b,c) max(a,max(b,c))
#define tmin(a,b,c) min(a,min(b,c))
#define pb push_back
#define eb emplace_back
#define vi vector<int>
#define vvi vector<vector<int>>
#define vl vector<ll>
#define vs vector<string>
#define vc vector<char>
#define vb vector<bool>
#define vp vector<P>
using namespace std;
using ll = long long;
using P = pair<int,int>;
using LP = pair<ll,ll>;
template<class T> istream& operator>>(istream& is,vector<T>& v) { for(T& t:v){is>>t;} return is; }
template<class T> ostream& operator<<(ostream& os,const vector<T>& v) { for(T t:v){os<<t<<" ";} os<<"\n"; return os; }
void Yes(bool b) { cout << (b ? "Yes" : "No") << endl; }
void YES(bool b) { cout << (b ? "YES" : "NO") << endl; }
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;}
const int inf = 1001001001;
const ll linf = 1001001001001001001;

int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr); cout.tie(nullptr);
    int a,b;
    cin >> a >> b;
    char ans[100][100];
    cout << "100 100" << endl;
    rep(i,50) rep(j,100) {
        ans[i][j] = '#';
        ans[i+50][j] = '.';
    }
    rep(i,a-1) {
        int ni,nj;
        ni = i/50*2;
        nj = i%50*2;
        ans[ni][nj] = '.';
    }
    rep(i,b-1) {
        int ni,nj;
        ni = i/50*2+51;
        nj = i%50*2;
        ans[ni][nj] = '#';
    }
    rep(i,100) {
        rep(j,100) cout << ans[i][j];
        cout << endl;
    }
}


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

int main(){
	int n;
	cin >> n;
	double x[n];
	string u[n];
	for(int i = 0; i < n; i++)cin >> x[i] >> u[i];
	double total;
	for(int i = 0; i < n; i++){
		if(u[i] == "JPY")total += x[i];
		else total += x[i] * 380000;
	}
	cout << total << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
const int maxn=1e5+10;
const int mod=1e6+3;
typedef long long ll;
map<int,int>mp,mmp;
#define inf 0x3f3f3f3f
#define mem(a,b) memset(a,b,sizeof(a))
#define pi acos(-1.0)
void read(int &x)
{
	int f=1;x=0;
	char ch=getchar();
	while(ch<'0'||ch>'9')
	{
		if(ch=='-')f=-1;
		ch=getchar();
	}
	while(ch>='0'&&ch<='9')x=x*10+ch-'0',ch=getchar();
	x*=f;
}
char s[maxn];
int main()
{
   scanf("%s",s);
   int len=strlen(s);
   for(int i=1;i<len;i++)
   {
   	if(s[i]==s[i-1])
   	{
   		return 0*puts("Bad");
   	}
   }
   puts("Good");
}

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

#define ll long long
#define MOD 1000000007
#define pb push_back

class grafo {
	int n;
	vector<vector<pair<int, int>>> adj;

public:

    vector<ll> dp_preto, dp_branco;

	grafo(int n) {
		this->n = n;
		adj = vector<vector<pair<int, int>>>(n);
        dp_preto = vector<ll>(n, 1);
        dp_branco = vector<ll>(n, 1);
	}

	void aresta(int u, int v, int w) {
		adj[u].pb({v, w});
		adj[v].pb({u, w});
	}

    void dfs(int u, int pai = -1) {
        for (auto &v : adj[u]) {
            if (v.first == pai) continue;
            dfs(v.first, u);
            dp_branco[u] *= (dp_preto[v.first] + dp_branco[v.first]);
            dp_preto[u] *= dp_branco[v.first];
            dp_branco[u] %= MOD;
            dp_preto[u] %= MOD;
        }
	}

};

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int n, x, y;
    cin >> n;
    grafo g(n);
    for (int i = 0; i < n-1; i++) {
        cin >> x >> y;
        g.aresta(x-1, y-1, 1);
    }
    g.dfs(0);
    cout << (g.dp_preto[0] + g.dp_branco[0]) % MOD;
}

Measured memory_bytes: 16956
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n)for(int i=0;i<(n);i++)
#define ALL(a) (a).begin(), (a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define pb push_back
using ll = long long;
using P = pair<int, int>;

bool dp[2][60000];

bool check(int pos, vector<int> vec){
    memset(dp, 0, sizeof(dp));
    dp[0][30000] = true;//原点
    for(int i = 0; i < vec.size(); ++i){
        for(int j = 0; j < 60000; ++j){
            if(dp[i%2][j] == 0) continue;
            if(j - vec[i] >= 0)     dp[(i+1)%2][j - vec[i]] |= dp[i%2][j];
            if(j + vec[i] < 60000)  dp[(i+1)%2][j + vec[i]] |= dp[i%2][j];
        }
        for(int j = 0; j < 60000; j++){
            dp[i%2][j] = false;
        }
    }
    return dp[vec.size() % 2][pos + 30000];
}

int main(){
    string s; cin >> s;
    int x, y; cin >> x >> y;
    vector<int> vecx, vecy;
    int id = 0;
    int cnt = 0;
    s += 'T';
    bool goright = true;
    int offset = 0;
    for(auto c : s){
        if(c == 'F') cnt++;
        else {
            if(id%2==0){
                if(goright){
                    goright = false;
                    offset = cnt;
                    id++;
                    cnt = 0;
                }else{
                    vecx.push_back(cnt);
                    id++;
                    cnt = 0;
                }
            }else{
                vecy.push_back(cnt);
                id++;
                cnt = 0;
            }
        }
    }
    if(check(x-offset,vecx) && check(y, vecy)) cout << "Yes" << endl;
    else cout << "No" << endl;
}

Measured memory_bytes: 512
#include<bits/stdc++.h>
using namespace std;
#define REP(i, n) for (int i = 0; i < (int)(n); i++)
#define FOR(i, a, b) for (int i= (a); i < (b); ++i)
typedef long long ll;
typedef pair<int,int> P;
const int INF = 100100100;
const int MOD = (int)1e9 + 7;
const double EPS = 1e-9;
int main() { int N;
  cin >> N;
  vector<int> s(N);
  REP(i, N) cin >> s[i];
  sort(s.begin(), s.end());
  ll mx = 0;
  REP(i, N) mx += s[i];
  if (mx % 10 == 0){
    REP(i,N){
      if(s[i]%10!=0){
        mx -= s[i];
        break;
      }
    }
    if (mx % 10 == 0) mx = 0;
  }
  
  cout << mx << endl;
}

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

const int maxn=100005;
char s[maxn];
int n, a, b;

int main(){
    while(~scanf("%d%d%d%s", &n, &a, &b, s)){
        int c1=0, c2=0;
        for(int i=0;i<n;i++){
            if(s[i]=='c'){
                puts("No");
            }
            if(s[i]=='a'){
                if(c1<a+b){
                    puts("Yes");
                    c1++;
                }
                else puts("No");
            }
            if(s[i]=='b'){
                if(c1<a+b&&c2<b){
                    puts("Yes");
                    c1++;c2++;
                }
                else puts("No");
            }
        }
    }
}



Measured memory_bytes: 768
#include<stdio.h>
#include<stdlib.h>
#include<math.h>
#include<string.h>
typedef long long ll;
typedef long double ld;
#define rep(i,l,r)for(ll i=(l);i<(r);i++)
#define repp(i,l,r,k)for(ll i=(l);i<(r);i+=(k))
#define INF (1LL<<60)
#define MOD1 1000000007

void swap(ll *a, ll *b){ll c;c=*b;*b=*a;*a=c;}
ll max2(ll a,ll b){return a>=b?a:b;}
ll min2(ll a,ll b){return a>=b?b:a;}
ll minn(ll n, ll a[n]){ll b=INF;rep(i,0,n) b=min2(b,a[i]);return b;}
ll maxn(ll n, ll a[n]){ll b=-INF;rep(i,0,n) b=max2(b,a[i]);return b;}
ll ABS(ll a){return a>=0?a:(-a);}
ll POW(ll a, ll b){ll c=1;rep(i,0,b) c*=a;return c;}
int upll(const void*a, const void*b){return*(ll*)a<*(ll*)b?-1:*(ll*)a>*(ll*)b?1:0;}
int downll(const void*a, const void*b){return*(ll*)a<*(ll*)b?1:*(ll*)a>*(ll*)b?-1:0;}
void sortup(ll*a,int n){qsort(a,n,sizeof(ll),upll);}
void sortdown(ll*a,int n){qsort(a,n,sizeof(ll),downll);}

typedef struct{
    ll aa;
    ll bb;
}frequent;

int main(void){
    // char ;
    ll n,w;
    scanf("%lld%lld",&n,&w);
    ll we[n],v[n];
    rep(i,0,n){
        scanf("%lld%lld",&we[i],&v[i]);
    }
    ll dp[n+1][w+1];
    // rep(i,0,we[0]){
    //     dp[0][i]=0;
    // }
    // rep(i,we[0],w+1){
    //     dp[0][i]=v[0];
    // }
    rep(i,0,w+1){
        dp[0][i]=0;
    }
    rep(i,1,n+1){
        rep(j,0,w+1){
            dp[i][j] = j>=we[i-1] ? max2( dp[i-1][j-we[i-1]]+v[i-1] , dp[i-1][j] ) : dp[i-1][j];
        }
    }
    
    printf("%lld\n",dp[n][w]);
    return 0;
}


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

using namespace std;
#define rep(i,n) for (int i = 0; i < (int)n; i++)

int main(){
  string s;
  cin >> s;
  if (s.find("A") != std::string::npos && s.find("B") != std::string::npos) {
    cout << "Yes" << endl;
  } else {
    cout << "No" << endl;
  }
}


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

using namespace std;

#define M 1000000007
#define pb push_back
#define f first
#define s second
#define rep(i, st, ed) for(int i=st; i<ed; i++)
#define repn(i, st, ed) for(int i=st; i<=ed; i++)
#define repb(i, ed, st) for(int i=ed; i>=st; i--)

typedef long long ll;
typedef unsigned long long int llt;
typedef long double ld;

const long double PI  = 3.141592653589793238463;
const int N = 5e5 + 10;

vector<int> g[N];
bool viss[N];
int vis[N];

// Normal DFS
void dfs(int curr, int par)
{
  for(auto x: g[curr])
    if(x != par)
      dfs(x, curr);
}

// DFS with visiting status
void dfs1(int curr, int par)
{
  viss[curr] = 1;
  for(auto x: g[curr])
    if(!viss[x])
      dfs1(x, curr);
}

// DFS with strongly connected component
void dfs2(int curr, int par, int num)
{
  vis[curr] = num;
  for(auto x: g[curr])
    if(vis[x] == 0)
      dfs2(x, curr, num);
}

// XOR from 0 to n
ll fxor(ll n)
{
  if(n < 0) return 0;
  if(n % 4 == 3) return 0;
  else if(n % 4 == 0) return n;
  else if(n % 4 == 1) return n^(n-1);
  else if(n%4 == 2) return n^(n-1)^(n-2);
}

// Power in logn with mod 1000000007
llt ppow(llt x, llt y)
{
  llt res = 1;
  while(y > 0){
    if(y&1)
      res = (res * x)%M;
    y = y >> 1;
    x = (x * x)%M;
  }
  return res;
}

// Factorial with dp
llt factdp[N];
llt fact(llt x)
{
  if(x == 0) return 1;
  if(x == 1) return 1;
  if(factdp[x] != -1) return factdp[x];
  return factdp[x] = (x*fact(x-1))%M;
}

// String return to base b
string ansConv ="";
void convert10tob(llt N, int b)
{
     if (N == 0)
        return;
     int x = N % b;
     N /= b;
     if (x < 0)
        N += 1;
     convert10tob(N, b);
     ansConv += to_string(x);
     return;
}

// Convert string to num wiht base b
llt convertstrtob(string a, int b)
{
  llt aa = 0;
  llt mul = 1;
  for(int i=a.length()-1; i>=0; i--)
  {
    int curr = a[i] - '0';
    aa += (curr * mul);
    mul *= b;
  }
  return aa;
}

// Union Find algo with array
// Find()
int findpar(int curr, int arr[])
{
  while(arr[curr] != curr) curr = arr[curr];
  return curr;
}
// Union()
void Union(int b, int spa, int arr[])
{
  while(arr[b] != b)
  {
    int c = arr[b];
    arr[b] = spa;
    b = c;
  }
  arr[b] = spa;
}

// Main Code

int main()
{
  int ans = 0;
  int k, s;
  cin>>k>>s;
  repn(i, 0, k)
    repn(j, 0, k)
    {
      int zz = s - i - j;
      if(zz >= 0 && zz <= k)
      ans++;
    }
  cout<<ans<<endl;
  return 0;
}


Measured memory_bytes: 12160
#include <cstdio>
#include <numeric>
#include <iostream>
#include <vector>
#include <set>
#include <cstring>
#include <string>
#include <map>
#include <cmath>
#include <ctime>
#include <algorithm>
#include <bitset>
#include <queue>
#include <sstream>
#include <deque>
#include <fstream>
#include <stdlib.h>  

using namespace std;

#define ll long long 
vector< vector<int> > vv;

string a, b;
void ans(int i, int j)
{
	if (!vv[i][j])
		return;
	if (vv[i][j] == vv[i - 1][j])
	{
		ans(i - 1, j);
		return;
	}
	if (vv[i][j] == vv[i][j - 1])
	{
		ans(i, j - 1);
		return;
	}

	if (vv[i - 1][j - 1])
		ans(i - 1, j - 1);
	cout << a[i - 1];
	return;
}

signed  main()
{
	cin >> a >> b;

	vv.resize(a.size() + 1, (vector<int>(b.size() + 1)));
	for (int i = 0; i < a.size(); i++)vv[i][0];
	for (int i = 0; i < b.size(); i++)vv[0][i];

	for (int i = 1; i <= a.size(); i++)
		for (int j = 1; j <= b.size(); j++)
		{
			if (a[i - 1] == b[j - 1])
				vv[i][j] = vv[i - 1][j - 1] + 1;
			else
				vv[i][j] = max(vv[i - 1][j], vv[i][j - 1]);
		}
	ans(int(a.size()), int(b.size()));
	cin >> a;
}

Measured memory_bytes: 35712
# -*- coding: utf-8 -*-

def readInts():
  return [int(s) for s in input().split(" ")]

def gcd(m, n):
  m, n = max(m, n), min(m, n)
  if n == 0:
    return m
  return gcd(n, m % n)

def gcds(A):
  ret = A[0]
  for n in A[1:]:
    ret = gcd(ret, n)
  return ret

def main():
  N = readInts()[0]
  A = readInts()

  lgcds = [1 for _ in range(N)]
  lgcds[0] = A[0]
  for i in range(N-1):
    lgcds[i+1] = gcd(lgcds[i], A[i+1])

  rgcds = [1 for _ in range(N)]
  rgcds[N-1] = A[N-1]
  for i in range(1, N):
    rgcds[N-1-i] = gcd(rgcds[N-i], A[N-1-i])

  m = 1
  for i in range(N):
    if i == 0:
      m = max(m, rgcds[i+1])
    elif i == N - 1:
      m = max(m, lgcds[i-1])
    else:
      m = max(m, gcd(lgcds[i-1], rgcds[i+1]))
  print(m)

if __name__ == "__main__":
  main()


Measured memory_bytes: 14052
#include <algorithm>
#include <bitset>
#include <cctype>
#include <cmath>
#include <cstdlib>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <string>
#include <utility>
#include <vector>
#define IOS ios::sync_with_stdio(false); cin.tie(0);
#define FOR(i, s, n) for(int i = s, i##_len=(n); i<i##_len; ++i)
#define REP(i, n) FOR(i, 0, n)
#define ALL(v) (v).begin(), (v).end()
typedef long long ll;
const int MOD = 1000000007;
using namespace std;

int main(){
    int n; cin >> n;
    ll ans = 0;
    vector<int> a(n), b(n), c(n);
    REP(i, n) cin >> a[i];
    REP(i, n) cin >> b[i];
    REP(i, n) cin >> c[i];
    sort(ALL(a)); sort(ALL(c));
    REP(i, n){
        int a_num = distance(a.begin(), lower_bound(ALL(a), b[i]));
        int c_num = distance(upper_bound(ALL(c), b[i]), c.end());
        ans += (ll)a_num * c_num;
    }
    cout << ans << "\n";
    return 0;
}


Measured memory_bytes: 1536
#include <iostream>
#include <cstdio>
#include <string>
#include <vector>
#include <iterator>  // std::back_inserter()
#include <set>
#include <algorithm>  // std::copy()
#include <functional>  // std::greater<T>()
#include <utility>  // std::swap()
#include <numeric>  // accumulate(ALL(vec), 0)  0 は初期値
#include <cmath>
#include <climits>  // INT_MIN
#include <cctype>  // std::isdigit()
using namespace std;

#define ALL(obj) (obj).begin(), (obj).end()
#define REP(i, n) for (int i=0; i < (int)(n); i++)  // 0 ~ n-1
#define REPN(i, n) for (int i=1; i <= (int)(n); i++)  // 1 ~ n
#define MIN(vec) min_element(ALL((vec)))  // イテレータのため、値を取り出すときは * を先頭につける
#define MAX(vec) max_element(ALL((vec)))
#define IDX(vec, element_iter) distance((vec).begin(), element_iter)
#define SUM(vec) accumulate(ALL((vec)), 0)  // 0 は初期値
#define COPY(vec1, vec2) copy(ALL(vec1), back_inserter(vec2))  // vec1をvec2にコピーする vec2は空にしておく必要あり
typedef long long ll;

const int MOD = 1000000007;  // 1 000 000 007


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

    // input
    int N, K;
    cin >> N >> K;
    vector<int> vec(N);
    REP(i, N) cin >> vec[i];
    
    // calculation
    sort(vec.begin(), vec.end(), greater<int>());  // int big -> small
    
    int res = INT_MAX;
    for (int j = 0; j < N-K+1; ++j) {
        res = min(res, vec[j] - vec[j + K - 1]);
    }
    
    cout << res << "\n";
    
    return 0;
}


Measured memory_bytes: 640
#include<stdio.h>
#include<math.h>
#include<string.h>
int main() {
    long long int n,r,i,c=0;
    scanf("%lld %lld",&n,&r);
    
    //printf("%lld",(long long int)log(n)+1);
    for(i=1;n>=1;i++)
    {
        n=n/r;
        c++;
    }
    printf("%lld",c);
    return 0;
}

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

int main() {
    long N, A, B, C, D, E;
    cin >> N;
    cin >> A;
    cin >> B;
    cin >> C;
    cin >> D;
    cin >> E;
    long transport[5] = {A, B, C, D, E}, min = A;
    for (int i = 1; i < 5; i++) {
        if (transport[i] < min) {
            min = transport[i];
        }
        else {}
    }
    long t;
    if (N % min == 0) {
        t = N / min + 4;
    }
    else {
        t = N / min + 5;
    }
    cout << t << endl;
    return 0;
}


Measured memory_bytes: 256
from itertools import permutations
n,m,r=map(int,input().split())
visit=list(map(int,input().split()))
dist=[[10**9]*n for i in range(n)]
for i in range(m):
  a,b,c=map(int,input().split())
  dist[a-1][b-1],dist[b-1][a-1]=c,c
for i in range(n):
  dist[i-1][i-1]=0
for i in range(n):
  for j in range(n):
    for k in range(n):
      dist[j][k]=min(dist[j][k],dist[j][i]+dist[i][k])
ans=10**9
check=permutations(visit)
for i in check:
  c=0
  for j in range(1,r):
    c+=dist[i[j-1]-1][i[j]-1]
  if c<ans:ans=c
print(ans)


Measured memory_bytes: 47320
import java.util.Scanner;
import java.math.BigDecimal;
import java.util.*;

public class Main{
    public static void main(String args[]){
        
        Scanner sc = new Scanner(System.in);
        long W = sc.nextLong();
        long H = sc.nextLong();
        long x = sc.nextLong();
        long y = sc.nextLong();
        double size = (double)(W * H) / 2.0;
        if(W % 2 == 0 && H % 2 == 0){
            if(x == W / 2 && y == H / 2){
                System.out.println(size + " " + 1);
            }else{
                System.out.println(size + " " + 0);
            }
        }else{
            System.out.println(size + " " + 0);
        }
    }
}

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

using namespace std;

int main() {
	int n;
	while (cin >> n) {
		if (n == 0) {
			break;
		} 
		string a, b;
		cin >> a;
		for (int i = 0; i < n; i++) {
			int counter = 1;
			char c = a[0];
			string d;
			b = "";
			for (int j = 1; j <= a.size(); j++) {
				if (j < a.size() && a[j] == c) {
					counter++;
				} else {
					stringstream stm;
					stm << counter;
					stm >> d;
					b += d;
					b += c;
					if (j < a.size()) {
						c = a[j];
						counter = 1;
					}
				}
			}
			a = b;
		}
		cout << a << endl;
	}
	return 0;
}

Measured memory_bytes: 1336
x,n=map(int,input().split())
if n>0:
  p=list(map(int,input().split()))
if n==0:
  p=[]
for i in range(1000):
  if not x-i in p:
    print(x-i)
    break
  if not x+i in p:
    print(x+i)
    break

Measured memory_bytes: 61684
#include <bits/stdc++.h>
#define pb push_back
#define mp make_pair
#define x first
#define y second

using namespace std;

typedef long long ll;

pair <string, int> mas[55];

int main()
{
 	//freopen("input.txt", "r", stdin);
 	//freopen("output.txt", "w", stdout);
 	ios_base::sync_with_stdio(0); cin.tie(0);
 	int n;
 	cin >> n;
 	for (int i = 1; i <= n; i++) cin >> mas[i].x >> mas[i].y;
 	string s;
 	cin >> s;
 	
 	int ans = 0;
 	for (int i = n; i > 0; i--)
 	{
 	 	if (mas[i].x == s) break;
 	 	ans += mas[i].y;
 	}
 	cout << ans << '\n';
 	return 0;
}

Measured memory_bytes: 256