akhauriyash/Code-Regression huggingface dataset:
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>

#if __cplusplus >= 201103L
#include <array>
#include <atomic>
#include <chrono>
#include <condition_variable>
#include <forward_list>
#include <future>
#include <initializer_list>
#include <mutex>
#include <random>
#include <ratio>
#include <regex>
#include <scoped_allocator>
#include <system_error>
#include <thread>
#include <tuple>
#include <typeindex>
#include <type_traits>
#include <unordered_map>
#include <unordered_set>
#endif
using namespace std;
#define FAST_IO                       \
    ios_base::sync_with_stdio(false); \
    cin.tie(NULL);                    \
    cout.tie(NULL);
#define watch(x) cout << (#x) << " is: " << (x) << endl
#define vw(v)                        \
    cout << (#v) << " is: " << endl; \
    for (long long B : (v))                \
    {                                \
        cout << B << " ";            \
    }                                \
    cout << endl
#define check(x) cout << "here " << (x) << "?" << endl
#define rep(i, a, b) for (long long i = (a); i < (b); i++)
#define per(i, a) for (long long i = (a - 1); i >= 0; i--)
#define all(x) (x).begin(), (x).end()
#define rv(x) (x).rbegin(), (x).rend()
#define pb push_back
long long const MAX = 2147483647, REALMAX = 9223372036854775806;
int main()
{
	FAST_IO
		string s, s1;
	cin >> s >> s1;
	int sum = 0;
	rep(i, 0, 3) {
		if (s[i] == s1[i]) {
			sum++;
		}
	}
	cout << sum << endl;
}

Measured memory_bytes: 256
def insert_sort(A):
    for i in range(1, len(A)):
        k = A[i]
        j = i - 1
        while j >= 0 and A[j] > k:
            A[j + 1] = A[j]
            j -= 1
        A[j + 1] = k
        show(A)

def show(A):
    for i in range(len(A) - 1):
        print(A[i], end=" ")
    print(A[len(A) - 1])

n =  int(input())
line = input()
A = list(map(int, line.split()))
show(A)
insert_sort(A)

Measured memory_bytes: 8164
#include <iostream>
#include <cstdio>
#include <cmath>
#include <vector>
#include <list>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <string>
#include <cstring>
#include <utility>
#include <algorithm>
#include <functional>
#include <deque>
#include <cctype>
#include <ctime>
#include <cstdlib>
#include <iomanip>
using namespace std;

int main(){
   int a, b, x;
   cin >> a >> b >> x;
   if (x>=a && x<=a+b) cout << "YES" << endl;
   else cout << "NO" << endl;
}


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

void solve()
{
    int n;
    scanf("%d",&n);
    int ac=0,wa=0,tle=0,re=0;
    for(int i=0;i<n;i++)
    {
        string a;
        cin>>a;
        if(a=="AC")
        {
            ac++;
        }
        if(a=="WA")
        {
            wa++;
        }
        if(a=="TLE")
        {
            tle++;
        }
        if(a=="RE")
        {
            re++;
        }
    }
    printf("AC x %d\n",ac);
    printf("WA x %d\n",wa);
    printf("TLE x %d\n",tle);
    printf("RE x %d",re);
}
int main()
{
   solve();
}


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

int main()
{
	int p0x = 0, p0y = 0, p1x = 0, p1y = 0, q = 0, px = 0, py = 0;
	int a = 0, b = 0;
	long y = 0;
	double t = 0;

	cin >> p0x >> p0y >> p1x >> p1y;
	cin >> q;

	a = p1x - p0x;
	b = p1y - p0y;

	for (int i = 0; i < q; i++) {
		cin >> px >> py;

		y = a * (py - p0y) - b * (px - p0x);

		if(y > 0)
			cout << "COUNTER_CLOCKWISE" << endl;
		else if(y < 0)
			cout << "CLOCKWISE" << endl;
		else {
			if (a != 0)
				t = (double)(px - p0x) / (double)a;
			else
				t = (double)(py - p0y) / (double)b;
				
			if (t < 0)
				cout << "ONLINE_BACK" << endl;
			else if (t > 1)
				cout << "ONLINE_FRONT" << endl;
			else
				cout << "ON_SEGMENT" << endl;
		}
	}
		
	return 0;
}

Measured memory_bytes: 3104
import java.util.*;
 
public class Main{
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		long[] a = new long[N];
		long[] b = new long[N];
		for(int i=0; i<N; ++i){
			a[i] = sc.nextLong();
			
		}
		long twos = 0;
		long minus = 0;
		for(int i=0; i<N; ++i){
			b[i] = sc.nextLong();
			if(a[i]<=b[i]) twos += (b[i]-a[i])/(long)2;
			else minus += (a[i]-b[i]);
		}
		
		if(twos>=minus) System.out.println("Yes");
		else System.out.println("No");
		return;
	}
}

Measured memory_bytes: 42280
#include <iostream>
#include <algorithm>
#include <unordered_set>

int main(){
    int s;
    std::cin>>s;
    std::unordered_set<int> us;
    int ans=1;
    us.emplace(s);
    while(true){
        ++ans;
        s=s%2==0?s/2:s*3+1;
        if(us.find(s)!=us.end())break;
        us.emplace(s);
    }
    std::cout<<ans<<"\n";
}

Measured memory_bytes: 384
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
template <class T, class U> using Pa = pair<T, U>;
template <class T> using vec = vector<T>;
template <class T> using vvec = vector<vec<T>>;

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int N,M,Q;
    cin >> N >> M >> Q;
    vec<int> A(Q),B(Q),C(Q),D(Q);
    for(int i=0;i<Q;i++){
        cin >> A[i] >> B[i] >> C[i] >> D[i];
        A[i]--; B[i]--;
    }
    int ans = 0;
    auto dfs = [&](auto&& self,int l,vec<int>& v)->void{
        if(v.size()==N){
            int val = 0;
            for(int i=0;i<Q;i++) if(v[B[i]]-v[A[i]]==C[i]) val += D[i];
            ans = max(ans,val);
            return ;
        }
        for(int i=l;i<=M;i++){
            v.push_back(i);
            self(self,i,v);
            v.pop_back();
        }
        return ;
    };
    for(int i=1;i<=M;i++){
        vec<int> v = {i};
        dfs(dfs,i,v);
    }
    cout << ans << "\n";
}

Measured memory_bytes: 3676
#include <bits/stdc++.h>
#include <boost/multiprecision/cpp_int.hpp>

#define repd(i, a, b) for (ll i = (a); i < (b); i++)
#define rep(i, n) repd(i, 0, n)

using namespace std;

namespace mp = boost::multiprecision;
using Bint = mp::cpp_int;

using ll = long long;
ll mod = pow(10, 9) + 7;

template <typename T> void output(T, ll);
ll gcd(ll, ll);
ll lcm(ll, ll);
Bint comb(Bint, Bint);
void prime_map(map<ll, ll> &, ll);

int main() {
    // source
    int n;
    cin >> n;
    int a[n];
    rep(i, n) { cin >> a[i]; }
    sort(a, a + n);
    ll alice = 0, bob = 0;
    rep(i, n) {
        if (i % 2 == 0) {
            alice += a[i];
        } else {
            bob += a[i];
        }
    }
    cout << abs(alice - bob) << endl;
    return 0;
}

Bint comb(Bint a, Bint b) {
    Bint ans = 1;

    if (a < b) {
        return 0;
    }

    rep(i, b) {
        ans *= a - i;
        ans /= i + 1;
    }

    return ans;
}

template <typename T> void output(T a, int precision) {
    if (precision > 0) {
        cout << setprecision(precision) << a << "\n";
    } else {
        cout << a << "\n";
    }
}

template <typename T> T min(T a, T b) {

    if (a < b) {
        return a;
    } else {
        return b;
    }
}

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

ll lcm(ll a, ll b) { return a * b / gcd(a, b); }

void prime_map(map<ll, ll> &m, ll num) {

    if (num == 1) {
        return;
    }
    ll cache = num;
    repd(i, 2, sqrt(num) + 2) {
        if (num % i == 0) {
            if (m[i] == 0) {
                m[i] = 1;
            } else {
                m[i]++;
            }

            num /= i;
            break;
        }
    }
    if (cache == num) {
        if (m[num] == 0) {
            m[num] = 1;
        } else {
            m[num]++;
        }

        return;
    }
    prime_map(m, num);
    return;
}


Measured memory_bytes: 256
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("filed 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")
}

fn main() {
    let s: usize = read();
    let l = s / 100;
    let r = s % 100;
    if 1 <= l && l <= 12 {
        if 1 <= r && r <= 12 {
            println!("AMBIGUOUS");
        } else {
            println!("MMYY");
        }
    } else {
        if 1 <= r && r <= 12 {
            println!("YYMM");
        } else {
            println!("NA");
        }
    }
}


Measured memory_bytes: 2120
/*   ꧁༒☬महाकाल☬༒꧂ ꧁༒ঔमहाकालঔ༒꧂
                   
                   ঔৣ۝महाकालᴳᵒᵈ۝ঔৣ            
 
 */ 
#pragma GCC optimize("Ofast")
#pragma GCC target("avx,avx2,fma")
#pragma GCC optimization ("unroll-loops"
#include<bits/stdc++.h>
using namespace std;
//#include <ext/pb_ds/assoc_container.hpp>
//#include <ext/pb_ds/tree_policy.hpp>
//using namespace __gnu_pbds;
//template <typename T, typename cmp=less<T>> using oset =tree<T, null_type, cmp, rb_tree_tag, tree_order_statistics_node_update>;
#define ll long long 
#define mod 1000000007
#define MOD 998244353
#define inf 100000000000000000
#define fast ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define _it iterator
#define all(_x) _x.begin(),_x.end()
#define f first
#define s second
#define pb push_back
#define ar array
#define ld long double
void mahakal(){
	#ifndef ONLINE_JUDGE
	freopen("input.txt","r",stdin);
	freopen("output.txt","w",stdout);
	freopen("error.txt","w",stderr);
	#endif
}
ll dx[4]={1,0,-1,0};
ll dy[4]={0,1,0,-1};
char c[4]={'D' , 'R' , 'U' , 'L'};
const ll maxN=2e5+5;
ll n ,x , t;
void solve(){
	cin>> n >> x >> t ;
	ll ans=0 , cnt=0;
	for(ll i=t ; ; i+=t){
		ans+=t;
		cnt+=x;
		if(cnt>=n)break;
	}
	cout<<ans<<endl;
}

int main(){
//	mahakal();
	fast;
	ll t =1 ;
	//cin>> t ; 
	while(t--)solve();
	//cerr << "\ntime taken : " << (float)clock() / CLOCKS_PER_SEC << " secs" << endl; 
	return 0;
}

Measured memory_bytes: 3636
a,b,c,d=[x for x in input()]
op='+-'
for op1 in op:
  for op2 in op:
    for op3 in op:
      ans=a+op1+b+op2+c+op3+d
      if eval(ans)==7:
        print('{}=7'.format(ans))
        exit()
      else:
        pass


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

int main() {
  int n; cin >> n;
  int res = 0;

  for(int i = 1; i <= n; i++) {
    int cnt = 0;
    if(i%2 != 0) {
      for(int j = 1; j <= n; j++) {
        if(i%j == 0) cnt++;
      }
      if(cnt == 8) res++;
    }
  }

  cout << res << endl;
}


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

using namespace std;

int main(){

  int n,k;cin>>n>>k;
  string s;cin>>s;

  vector<int>v1;
  vector<int>v0;

  const int sz=s.size();
  s+='e';

  for(int i=0;i<sz;++i){
	int c=1;
	if(s[i]=='0'){
	  while(s[i]==s[i+1]){c++;i++;}
	  v0.push_back(c);
	}
	else {
	  while(s[i]==s[i+1]){c++;i++;}
	  v1.push_back(c);
	}
  }

  int sz1=v1.size(),sz0=v0.size();

  if(k>=sz0){
	cout<<n<<endl;
	return 0;
  }

  int ans=0;
  for(int i=0;i<sz0-k+1;++i){
	int cnt=0;
	for(int j=0+i;j<k+i;++j)
	  cnt+=v0[j]+(sz1>j?v1[j]:0);
	if(s[0]=='0')cnt+=(i-1>=0?v1[i-1]:0);
	else cnt+=(k+i<sz1?v1[k+i]:0);

	if(cnt>ans)ans=cnt;
  }

  cout<<ans<<endl;

  return 0;
}

Measured memory_bytes: 1020
N, H = map(int, input().split())
L = [list(map(int, input().split())) for i in range(N)]


aArgmax = max(enumerate(L), key=lambda x: x[1][0])[0]  # aの値でargmax
a, b = L.pop(aArgmax)
L.sort(key=lambda x: x[1])
cnt = 0
while len(L) >= 1 and L[-1][1] > a:
    if H <= 0:
        print(cnt)
        exit()
    if H <= b:
        print(cnt+1)
        exit()
    H -= L.pop()[1]
    cnt += 1

H -= b
cnt += (H+a-1) // a + 1
print(cnt)


Measured memory_bytes: 28904
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const ll mod=1e9+7;

int main(){
    string S;
    int w;
    cin >> S >> w;
    int cnt=0;
    for(int i=0; i<S.size(); i++){
        if(cnt>=S.size()) return 0;
        cout << S[cnt];
        cnt+=w;
    }
}

Measured memory_bytes: 256
N, K = gets.split.map(&:to_i)
mx = (N-1)*(N-2)/2
if mx < K
    puts "-1"
    exit
end

ans = (2..N).map{|i| [1, i]}
(2..N).each do |i|
    (2...i).each do |j|
        if mx > K
            mx -= 1
            ans.push([j, i])
        end
    end
end
puts ans.size
ans.each do |arr|
    puts arr.join(' ')
end

Measured memory_bytes: 2300
#include <bits/stdc++.h>
#define loop(n, i) for(int i=0;i<n;i++)
#define loop1(n, i) for(int i=1;i<=n;i++)
#define rloop(n, i) for(int i=n;i;i++)
#define HERE cout << "HERE: " << __LINE__ << endl;
#define INSP(v) cout << v << " at " << __LINE__ << endl;
using namespace std;
using ll = long long;
template <class T>
using V = vector<T>;

int main() {
    int k, x; cin >> k >> x;
    int mi = x - k + 1, ma = x + k - 1;
    cout << mi;
    for (int i = mi + 1; i <= ma; i++) {
        cout << " " << i;
    }
    cout << endl;
    return 0;
}



Measured memory_bytes: 256
#define rep(i, n) for (int i = 0; i < (int)(n); i++)

#include <bits/stdc++.h>
using namespace std;


int main() {
	int n;
    cin >> n;
    
    if(n%10 == 3){
		cout << "bon";
	}else if(n%10 == 0 || n%10 == 1 || n%10 == 6 || n%10 == 8){
		cout << "pon";
	}else{
		cout << "hon";
	}
	
	return 0;
}

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

using namespace std;
typedef pair<string, int> psi;

bool pcomp(pair<psi,int> p11,pair<psi,int> p22)
{
    psi p1 = p11.first;
    psi p2 = p22.first;
    if (p1.first < p2.first)
    {
        return true;
    }
    else if (p1.first>p2.first)
    {
        return false;
    }
    else
    {
        if(p1.second>p2.second)
        {
            return true;
        }
        else
        {
            return false;
        }
        }
    
}

int main(){
    int n;
    cin >> n;
    vector<pair<psi, int>> v(n);
    for (int i = 0; i < n; i++)
    {
        psi p;
        cin >> p.first >> p.second;
        v[i].first = p;
        v[i].second = i+1;
    }
    sort(v.begin(), v.end(), pcomp);
    for (int i = 0; i < n; i++)
    {
        cout << v[i].second << endl;
    }
    return 0;
}

Measured memory_bytes: 3628
#include "bits/stdc++.h"
using namespace std;

const int N=2e5+20;

int n,a[N],inf;
long long k;
vector <int> dp[N];

void go(int node,int steps=1)
{
	if(steps>=1000000) return;
	dp[node].push_back(steps);
	int child=a[node];
	go(child,steps+1);
}

int main()
{
	scanf("%d%lld",&n,&k);
	for(int i=1;i<=n;i++) scanf("%d",&a[i]);

	k++;
	go(1);
	for(int i=1;i<=n;i++)
	{
		for(auto j:dp[i])
			if(j==k) return 0 * printf("%d",i);
		if(dp[i].size()>1 and k>=dp[i][0])
		{
			if(dp[i][0]==dp[i][1]) inf=i;
			else if((k-dp[i][0])%(dp[i][1]-dp[i][0])==0)
				return 0 * printf("%d",i);
		}
	}
	printf("%d",inf);
}

Measured memory_bytes: 50104
n=int(input())
h=[list(map(int,input().split())) for i in range(n)]

dp=[[0 for i in range(3)]for j in range(n+1)]

for i in range(1,n+1):
    for j in range(3):
        for k in range(3):
            if j == k:
                continue
            dp[i][j] = max(dp[i][j],dp[i-1][k]+h[i-1][j])

print(max(dp[n]))


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

int main () {
    int N;
    cin >> N;
    string s;
    set<string> S;
    for(int i = 0; i < N; i++)
    {
        cin >> s;
        S.insert(s);
    }
    cout << S.size() << endl;
}


Measured memory_bytes: 19224
from collections import Counter

n = int(input())
s = [input() for i in range(n)]
m = int(input())
t = [input() for i in range(m)]

sc = Counter(s)
tc = Counter(t)
ns = len(sc)
ans = 0

for i in range(ns):
  key = sc.most_common()[i][0]
  if key in tc:
    ans = max(sc[key] - tc[key],ans)
  else:
    ans = max(sc[key],ans)
print(ans)


Measured memory_bytes: 3316
#include <set>
#include <map>
#include <queue>
#include <ctime>
#include <cmath>
#include <cstdio>
#include <bitset>
#include <vector>
#include <cstring>
#include <cassert>
#include <iostream>
#include <algorithm>
using namespace std;
typedef double db;
typedef long long ll;
typedef long double ld;
typedef vector<int> vi;
typedef pair<int,int> pa;
typedef unsigned int uint;
typedef unsigned long long ull;
#define w1 first
#define ls (x<<1)
#define w2 second
#define ins insert
#define rs (x<<1|1) 
#define mp make_pair
#define pb push_back
#define mid ((l+r)>>1)
#define sqr(x) ((x)*(x))
#define cle(x) ((x).clear())
#define lowbit(x) ((x)&(-x))
#define SZ(x) (int((x).size()))
#define ms(x,y) memset(x,y,sizeof (x))
#define rep(i,a,b) for(int (i)=(a);(i)<=(b);(i)++)
#define rep2(i,a,b) for(int (i)=(a);(i)<(b);(i)++)
#define per(i,a,b) for(int (i)=(a);(i)>=(b);(i)--)
#define Rep(p,x) for(int (p)=head[(x)];(p);(p)=nxt[(p)]) 
#define Rep2(p,x) for(int (p)=cur[(x)];(p);(p)=nxt[(p)])
template<class T>inline void read(T&num){
	num=0;T f=1;char ch=getchar();
	while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}
	while(ch>='0'&&ch<='9')num=num*10+ch-'0',ch=getchar();
	num*=f;
}
inline int getgcd(int x,int y){if(!x)return y;return getgcd(y%x,x);}
inline int power(int x,int k,int p){int res=1;for(;k;k>>=1,x=(ll)x*x%p)if(k&1)res=(ll)res*x%p;return res;}
const double pi=acos(-1);	
inline void judge(){
	freopen("input.txt","r",stdin);
} 
//********************************head*************************************
const int maxn=2e3+5;
int n,m,top,ans;
char str[maxn][maxn];
int a[maxn][maxn],h[maxn][maxn],L[maxn],R[maxn];
pa st[maxn];
int main(){
	read(n);read(m);
	rep(i,1,n)scanf("%s",str[i]+1);
	rep(i,1,n-1)rep(j,1,m-1){
		int cnt=0;
		cnt+=(str[i][j]=='.');
		cnt+=(str[i+1][j]=='.');
		cnt+=(str[i][j+1]=='.');
		cnt+=(str[i+1][j+1]=='.');
		a[i][j]=!(cnt&1);
	}
	rep(i,1,n-1)rep(j,1,m-1){
		if(a[i][j])h[i][j]=h[i-1][j]+1;
		else h[i][j]=0;
	}
	ans=max(n,m);
	rep(i,1,n-1){
		st[top=1]=mp(0,-1);
		rep(j,1,m-1){
			while(top&&st[top].w2>=h[i][j])top--;
			L[j]=st[top].w1+1;
			st[++top]=mp(j,h[i][j]);
		}
		st[top=1]=mp(m,-1);
		per(j,m-1,1){
			while(top&&st[top].w2>=h[i][j])top--;
			R[j]=st[top].w1-1;
			st[++top]=mp(j,h[i][j]);
		}
		rep(j,1,m-1)ans=max(ans,(h[i][j]+1)*(R[j]-L[j]+2));
	}
	printf("%d\n",ans);
	return 0;
}

Measured memory_bytes: 35584
#include <bits/stdc++.h>
#define int long long
using namespace std;

signed main() {
	int n;
    cin >> n;
    
    vector<int> a(n);
    for (int i = 0; i < n; ++i) {
        cin >> a[i];
    }
	
	int g = a[0];
	bool pairwise = true;	
	set<int> st, temp; // set of all factors
	
    for (int i = 1; i < n; i++) {
		g = __gcd (g, a[i]);
		int ai = a[i];
        if (pairwise) {
            // factorize ai
            for (int i = 2; i * i <= ai; i++) {
                if (ai % i == 0) {
                    temp.insert(i);
                }
                while (ai % i == 0)
                    ai /= i;
            }
 
            if (ai != 1) temp.insert(ai);
            for (auto& t : temp) {
                if (st.count(t)) {
                    pairwise = false;
                }
                else st.insert(t);
            }
        }
        temp.clear();
	}
	
    if (pairwise) {
        cout << "pairwise coprime" << endl;
    }
    else if (g == 1) {
        cout << "setwise coprime" << endl;
    }
    else {
        cout << "not coprime" << endl;
    }
    
    return 0;
}


Measured memory_bytes: 11168
#include <bits/stdc++.h>
using namespace std;
#define ll          long long int
#define pb          push_back
#define pll         pair<ll,ll>
#define speed_up    ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define mode        998244353
#define mod         1000000007
#define inf         1000000000000000000LL
#define vl          vector<ll>
#define F           first
#define S           second
#define ld          long double
#define sz(x)       (ll)x.size()
#define fix(n)      cout<<fixed<<setprecision(n)
#define rep(i,a,b)  for(ll i=a;i<b;i++)
#define all(x)      x.begin(),x.end()
#define mset(x)     memet(x,0,sizeof x)
#define pi          3.14159265358979323



void solve()
{
       ll n,k;
       cin>>n>>k;
       if(k==1) {cout<<0<<endl; return; }
       ll mn=1, mx=n-(k-1);
       cout<<mx-mn<<endl;
}


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


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

signed main(){
  long long N,M;
  cin>>N>>M;
  int x[N]={};
  int y[N]={};
  int z[N]={};
  int f0[N];
  int f1[N];
  int f2[N];
  int f3[N];
  int f4[N];
  int f5[N];
  int f6[N];
  int f7[N];
  for(int i=0;i<N;i++){
    cin>>x[i]>>y[i]>>z[i];
    f0[i]=x[i]+y[i]+z[i];
    f1[i]=x[i]+y[i]-z[i];    
    f2[i]=x[i]-y[i]+z[i];
    f3[i]=-x[i]+y[i]+z[i];
    f4[i]=x[i]-y[i]-z[i];
    f5[i]=-x[i]+y[i]-z[i];    
    f6[i]=-x[i]-y[i]+z[i];
    f7[i]=-x[i]-y[i]-z[i];    
  }
  long long maxans=0;
  long long ans=0;
  sort(f0,f0+N);
  for(int i=N-1;i>=N-M;i--){
    ans+=f0[i];
  }
  maxans=max(maxans,ans);  
  
  ans=0;
  sort(f1,f1+N);
  for(int i=N-1;i>=N-M;i--){
    ans+=f1[i];
  }   
  maxans=max(maxans,ans);  
  
  ans=0;
  sort(f2,f2+N);
  for(int i=N-1;i>=N-M;i--){
    ans+=f2[i];
  }  
  maxans=max(maxans,ans);   

  ans=0;
  sort(f3,f3+N);
  for(int i=N-1;i>=N-M;i--){
    ans+=f3[i];
  }  
  maxans=max(maxans,ans); 
 
  ans=0;
  sort(f4,f4+N);
  for(int i=N-1;i>=N-M;i--){
    ans+=f4[i];
  }  
  maxans=max(maxans,ans); 

  ans=0;
  sort(f5,f5+N);
  for(int i=N-1;i>=N-M;i--){
    ans+=f5[i];
  }  
  maxans=max(maxans,ans); 
  
  ans=0;
  sort(f6,f6+N);
  for(int i=N-1;i>=N-M;i--){
    ans+=f6[i];
  }  
  maxans=max(maxans,ans);  
  
  ans=0;
  sort(f7,f7+N);
  for(int i=N-1;i>=N-M;i--){
    ans+=f7[i];
  }  
  maxans=max(maxans,ans); 
  
  cout<<maxans<<endl;
  
  return 0;
}

  
    

Measured memory_bytes: 3692
//Littleboy123 Template 1.2
     
    #include <bits/stdc++.h>
    using namespace std;
     
    //pragmas
    /*
    #pragma comment(linker, "/stack:200000000")
    #pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
    #pragma GCC target ("avx2")
    #pragma GCC optimization ("O3")
    #pragma GCC optimization ("unroll-loops")
    */
     
    typedef pair<int, int> ii;
    typedef vector<int> vi;
    typedef vector<ii> vii;
    typedef long long int ll;
    typedef unsigned long long int ull;
    typedef long double ld;
     
    #define FOR(a,b,c) for(ll (a)=(b);(a)<(c);++(a))
    #define FORE(a,b,c) for(ll (a)=(b);(a)<=(c);++(a))
    #define FORN(a,b,c) for(ll (a)=(b);(a)>(c);--(a))
    #define FORNE(a,b,c) for(ll (a)=(b);(a)>=(c);--(a))
    #define COUT(a) cout << (a) << '\n'
    #define MEM(a,b) memset((a), (b), sizeof((a)))
    #define MAX(a,b) (a) = max((a), (b))
    #define MIN(a,b) (a) = min((a), (b))
    #define nl '\n'
    #define fi first
    #define se second
    #define mp make_pair
    #define pb push_back
    #define pi acos(-1.0)
     
    void init(){
    	ios_base::sync_with_stdio(false);
    	cin.tie(NULL);
    	cout.tie(NULL);
    }
     
    void infile(){
    	ifstream in("input.in");
    	streambuf *cinbuf = std::cin.rdbuf();
    	cin.rdbuf(in.rdbuf());
    }
     
    void outfile(){
    	ofstream out("out.txt");
    	streambuf *coutbuf = std::cout.rdbuf();
    	cout.rdbuf(out.rdbuf());
    }
     
    //End of template
     
    int main(){
    	init();
    	//infile();
    	//outfile();
    	
    	int a, b;
    	cin >> a >> b;
    	if(b == 1){
    		cout << 0 << nl;
    		return 0;
    	}
    	int now = a;
    	int cnt = 1;
    	while(now < b){
    		now--;
    		now += a;
    		cnt++;
    	}
    	cout << cnt << nl;
    	return 0;
    }

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

typedef long long lint;

bool p[1000010];
vector<int> pr;

lint gcd(lint a, lint b) { return a % b ? gcd(b, a % b) : b; }

int main() {
	ios::sync_with_stdio(0); cin.tie(0);
	lint A, B;

	cin >> A >> B;

	memset(p, true, sizeof(p));
	for(int i = 2; i < 1000000; i++) if(p[i]) {
		pr.push_back(i);
		for(int j = i * 2; j < 1000000; j += i) p[j] = false;
	}
	lint g = gcd(A, B);
	int ans = 1;
	for(auto a : pr) {
		if(g % a == 0) ans++;
		while(g % a == 0) g /= a;
	}
	if(g != 1) ans++;

	cout << ans;
	return 0;
}


Measured memory_bytes: 1916
#include <iostream>
#include <string>

using namespace std;

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

    int sx, sy, tx, ty, w, h;
    string path("");
    cin >> sx >> sy >> tx >> ty;
    
    w = tx - sx;
    h = ty - sy;

    // 1回目の行き
    path += string(w, 'R') + string(h, 'U');

    // 1回目の帰り
    path += "R" + string(h+1, 'D') + string(w+1, 'L') + "U";

    // 2回目の行き
    path += string(h, 'U') + string(w, 'R');

    // 2回目の帰り
    path += "U" + string(w+1, 'L') + string(h+1, 'D') + 'R';

    cout << path << "\n";
    return 0;
}


Measured memory_bytes: 256
#include<cstdio>
#include<cstdlib>
#include<cmath>
#include<algorithm>
#include<vector>
#include<set>
#include<queue>
#include<iostream>
#include<map>
#include<cstring>
#define INF 0x3f3f3f3f
#define eps 1e-10
using namespace std;
string s;
long long sum;
int main(){
    cin>>s;
    for(int i=0;i<s.size();i++)
        sum+=(s[i]-'0');
    if(!(sum%9))
        printf("Yes");
    else
        printf("No");
}

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

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> pii;
typedef pair<ll, ll> pll;
typedef pair<ull, ull> pullull;
typedef pair<ll, int> plli;
typedef pair<int, pii> pipii;
typedef vector<vector<int> > mati;
typedef vector<vector<double> > matd;
typedef vector<ll> vll;
typedef vector<vector<ll>> vvll;
typedef vector<vector<vector<ll>>> vvvll;
typedef vector<bool> vb;
typedef vector<vector<bool>> vvb;
typedef vector<vector<vector<bool>>> vvvb;
typedef vector<pll> vpll;

#define FOR(i,x,y) for(ll i=(ll)x; i<(ll)y; ++i)
#define REP(i,y) FOR(i, 0, y)
#define RFOR(i,x,y) for(ll i=(ll)x; i>=(ll)y; --i)
#define RREP(i,x) RFOR(i, x, 0)
#define ALL(a) a.begin(), a.end()
#define pb push_back

inline void IN(void){
  return;
}

template <typename First, typename... Rest>
void IN(First& first, Rest&... rest){
  cin >> first;
  IN(rest...);
  return;
}

inline void OUT(void){
  cout << "\n";
  return;
}

template <typename First, typename... Rest>
void OUT(First first, Rest... rest){
  cout << first << " ";
  OUT(rest...);
  return;
}

constexpr int INF = (1<<30);
constexpr ll INFLL = 1LL<<62;
constexpr long double EPS = 1e-12;
constexpr ll MOD = (ll)((1E+9)+7);


ll N;
vpll XL;


int main(){
  IN(N);
  XL.resize(N);
  REP(i,N){
    ll X, L;
    IN(X, L);
    XL[i].first = X+L;
    XL[i].second = X-L;
  }
  sort(ALL(XL));

  ll ans = 1;
  ll max=XL[0].first;
  FOR(i,1,N){
    if(max<=XL[i].second){
      max = XL[i].first;
      ans++;
    }
  }

  OUT(ans);

  return 0;
}


Measured memory_bytes: 1792
#include<iostream>
#include<vector>
#include<queue>
#include<set>
#include<map>
#include<string>
#include<cmath>
#include<algorithm>
using namespace std;
using ll = long long;
#define what(x) cerr << #x << " is " << x << endl;

int main(){
    int N;
    cin >> N;
    vector<ll> A(N);
    for(int i = 0; i < N; ++i) {
        cin >> A[i];
    }
    map<ll, ll> m;
    for(int i = 0; i < N; ++i) {
        m[A[i]]++;
    }
    ll x = -1;
    ll y = -1;
    for(auto it = m.rbegin(); it != m.rend(); it = next(it)) {
        if (it->second >= 2) {
            x = it->first;
            it->second -= 2;
            break;
        }
    }
    for(auto it = m.rbegin(); it != m.rend(); it = next(it)) {
        if (it->second >= 2) {
            y = it->first;
            break;
        }
    }
    if (x == -1 || y == -1) {
        cout << 0 << endl;
    }
    else {
        cout << x * y << endl;
    }
    return 0;
}

Measured memory_bytes: 7296
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<iostream>
#include<algorithm>
#include<string>
#include<iomanip>
#include<set>
#include<map>
#include<vector>
#define FAST ios::sync_with_stdio(false)
typedef long long ll;
const int mod = (int)1e9 + 9;
const int inf = 0x3f3f3f3f;
const int maxn = (int)1e5 + 5;
using namespace std;

int main()
{
	int a, b, c, d;
	cin >> a >> b >> c >> d;
	if(abs(a - c) <= d) return puts("Yes"), 0;
	else if(abs(a - b) <= d && abs(b - c) <= d) puts("Yes"), 0;
	else puts("No");
	return 0;
}

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

using namespace std;

int main(void) {
  long long n;
  while (cin >> n, n) {
    long long sum = 0LL;
    for (int i = 1; i * i <= n; i++) {
      if (n % i) continue;
      sum += i;
      if (i * i != n) sum += n / i;
    }
    if (n == 1 || 2 * n > sum) cout << "deficient number\n";
    else if (2 * n < sum) cout << "abundant number\n";
    else cout << "perfect number\n";
  }

  return 0;
}


Measured memory_bytes: 2984
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Text.RegularExpressions;

namespace AtCoder
{
    class Program
    {
        static void Main(string[] args)
        {
            long N = long.Parse(Console.ReadLine());

            long ans = long.MaxValue;

            for (long i = 1; i * i <= N ; i++)
            {
                if(N % i == 0)
                {
                    ans = Math.Min(Math.Max(i.ToString().Length, (N / i).ToString().Length), ans);
                }
            }

            Console.WriteLine(ans);
        }
    }
}

Measured memory_bytes: 27516
#[allow(unused_imports)]
use std::cmp::*;
#[allow(unused_imports)]
use std::collections::*;
use std::io::{Write, BufWriter};
// https://qiita.com/tanakh/items/0ba42c7ca36cd29d0ac8
macro_rules! input {
    ($($r:tt)*) => {
        let stdin = std::io::stdin();
        let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));
        let mut next = move || -> String{
            bytes
                .by_ref()
                .map(|r|r.unwrap() as char)
                .skip_while(|c|c.is_whitespace())
                .take_while(|c|!c.is_whitespace())
                .collect()
        };
        input_inner!{next, $($r)*}
    };
}

macro_rules! input_inner {
    ($next:expr) => {};
    ($next:expr, ) => {};

    ($next:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };
}

macro_rules! read_value {
    ($next:expr, ( $($t:tt),* )) => {
        ( $(read_value!($next, $t)),* )
    };

    ($next:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
    };

    ($next:expr, chars) => {
        read_value!($next, String).chars().collect::<Vec<char>>()
    };

    ($next:expr, usize1) => {
        read_value!($next, usize) - 1
    };

    ($next:expr, [ $t:tt ]) => {{
        let len = read_value!($next, usize);
        (0..len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
    }};

    ($next:expr, $t:ty) => {
        $next().parse::<$t>().expect("Parse error")
    };
}

fn solve() {
    let M:i64 = 1_000_000_007;
    let out = std::io::stdout();
    let mut out = BufWriter::new(out.lock());
    macro_rules! puts {
        ($($format:tt)*) => (write!(out,$($format)*).unwrap());
    }
    input! {
        n: usize,
        m: usize,
        a: [usize; m],
    }
    let mut dp = vec![0; n+1];
    dp[0] = 1;
    dp[1] = 1;
    for i in 0..m{
        dp[a[i]] = -1;
        if(a[i]<=1){
            dp[a[i]] = 0;
        }
    }
    for i in 2..n+1{
        if(dp[i]==-1) {
            dp[i] = 0;
            continue;
        }
        dp[i] = dp[i-1] + dp[i-2];
        dp[i] %= M;
    }
    println!("{}",dp[n]);
}

fn main() {
    // In order to avoid potential stack overflow, spawn a new thread.
    let stack_size = 104_857_600; // 100 MB
    let thd = std::thread::Builder::new().stack_size(stack_size);
    thd.spawn(|| solve()).unwrap().join().unwrap();
}


Measured memory_bytes: 10620
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <climits>
#include <iomanip>
#include <cmath>

using namespace std;

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

	int n;
	cin >> n;
	vector<int> d;
	long long ans = 0;
	for (int i = 0; i < n; i++) {
		int in_d;
		cin >> in_d;
		for (int j = 0; j < d.size(); j++) {
			ans += in_d * d[j];
		}
		d.emplace_back(in_d);
	}

	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 256
#include <stdio.h>

int main(void){
  long K, N;
  long x = -1;
  scanf("%ld %ld", &K, &N);
  long i;
  long first, old_, new_;
  scanf("%d", &first);
  old_ = first;
  for(i = 1; i < N; i++){
    scanf("%d", &new_);
    if(x == -1 || x < new_ - old_)x = new_ - old_;
    old_ = new_;
  }
  if(x < K - (new_ - first)) x = K - (new_ - first);
  printf("%d\n", K - x);
  return 0;
}

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

int main() {
  int Value,Coin1,Nes_Coin1;
  cin >> Value >> Coin1;
  Nes_Coin1 = Value % 500;
  if (Coin1 >= Nes_Coin1) {
    cout << "Yes" << endl;
  }
  else {
    cout << "No" << endl;
  }
}

Measured memory_bytes: 256
import sys
sys.setrecursionlimit(10000000)
def dfs(s):
  if len(s)==11:
    return
  if s!="":
    a.append(int(s))
  for c in "0123456789":
    if s=="" and c=="0":continue
    if s!="":
      if abs(ord(c)-ord(s[-1]))<=1:
        dfs(s+c)
    else:
      dfs(s+c)

k=int(input())
a=[]
dfs("")
a=list(set(a))
a.sort()
print(a[k-1])




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

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

    int N, C;
    cin >> N >> C;

    vector<vector<bool> > S(pow(10, 5) + 10, vector<bool>(C));
    vector<vector<bool> > T(pow(10, 5) + 10, vector<bool>(C));

    for(int i = 0; i < N; i++) {
        int s, t, c;
        cin >> s >> t >> c;
        c--;
        S[s][c] = true;
        T[t][c] = true;
    }

    int ans = 1;
    int count = 1;

    for(int i = 1; i < pow(10, 5) + 10; i++) {
        int c = 0;
        for(int j = 0; j < C; j++) {
            if(S[i][j] && !T[i][j]) {
                c++;
            }
        }
        if(c > count) {
            ans += c - count;
            count = c;
        }

        count -= c;

        for(int j = 0; j < C; j++) {
            if(T[i][j] && !S[i][j]) {
                count++;
            }
        }
    }

    cout << ans << endl;
}

Measured memory_bytes: 14336
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
const ll MOD = 1e9 + 7;
const ll INF = 1LL << 60;

int main() {
	int A, B;
	cin >> A >> B;
	cout << max(A - 2 * B, 0) << endl;
}

Measured memory_bytes: 256
//おまじない
//#include <bits/stdc++.h>
#include <iostream>
#include<iomanip>
#include <set>
#include <algorithm>
#include <vector>
#include <string>
#include <utility>
#include <queue>
#define INF 1e9+7
#define rep(i,n) for(int i=0;i<n;i++)
#define NO cout<<"NO"<<endl;
#define YES cout << "YES"<<endl;
#define No cout << "No"<<endl;
#define Yes cout << "Yes"<<endl;
#define all(a) a.begin(),a.end()
#define P pair<int,int>
#define space ‘ ‘
using namespace std;
typedef long long int ll;
typedef unsigned long long int ull;

//(int)'a'は97 (int)'A'は65 (int)'1'は49
//おまじない

const int maxn = 100000;

int main(){
  ll n;
  ll ans = 0;
  ll num[maxn];
  ll b_n;
  ll b_sum=0;
  ll s_sum=0;

  cin >> n;
  rep(i,n)cin >> num[i];

  sort(num,num+n);
  reverse(num,num+n);
    
    int _n = (n+1)/2;
    
    if(n%2==0){
        ll sub_ans = 0;
        rep(i,_n){
            if(i==_n-1)sub_ans += num[i];
            else sub_ans += num[i]*2;
        }
        rep(i,n-_n){
            if(i==n-_n-1)sub_ans-=num[n-1-i];
            else sub_ans-= num[n-1-i]*2;
        }
        ans = sub_ans;
    }else{
        ll sub_ans_1 = 0;
        ll sub_ans_2 = 0;
        rep(i,_n){
            if(i<_n-2)sub_ans_1-=num[n-1-i]*2;
            else sub_ans_1 -= num[n-1-i];
        }
        rep(i,n-_n)sub_ans_1 += num[i]*2;
        
        rep(i,n-_n)sub_ans_2-=num[n-1-i]*2;
        rep(i,_n){
            if(i<_n-2)sub_ans_2+=num[i]*2;
            else sub_ans_2+=num[i];
        }
        
        ans = max(sub_ans_1,sub_ans_2);
    }
    

    cout << ans<<endl;

  return 0;
}


Measured memory_bytes: 1024
#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;}

typedef pair<int,int> P;
const int hmax=1001,wmax=1001;
const int INF=1000100100;
char mp[hmax][wmax];
int d[hmax][wmax];
int h,w,n,ans=-1,total=0;
int sy,sx;
int dy[4]={-1,0,1,0},dx[4]={0,1,0,-1};
int gy,gx;


int bfs(){
    cin >> h >> w;
    sy=0,sx=0;
    gy=h-1,gx=w-1;
    rep(i,h)rep(j,w) d[i][j]=INF;
    rep(i,h)rep(j,w){
        cin >> mp[i][j];
        if(mp[i][j]=='.') total++;
    }
    rep(i,h)rep(j,w) d[i][j]=INF;
    queue<P> q;
    d[sy][sx]=1;
    q.push(P(sy,sx));
    while(q.size()){
        P p=q.front();
        q.pop();
        if(p.first==gy&&p.second==gx){
            ans=total-d[gy][gx];
            break;
        }
        rep(i,4){
            int y=p.first+dy[i],x=p.second+dx[i];
            if(0<=y&&y<h&&0<=x&&x<w&&d[y][x]==INF&&mp[y][x]!='#'){
                q.push(P(y,x));
                d[y][x]=d[p.first][p.second]+1;
            }
        }
    }
    return ans;
}

int main(){
    cout << bfs() << endl;
    return 0;
}













Measured memory_bytes: 2432
n=int(input())
l=[]

for i in range(n):
  x,y=map(int,input().split())
  l.append([x,y])

import itertools

seq=[i for i in range(n)]
p=list(itertools.permutations(seq))
import math

ans=0
for pp in p:
  for i in range(n-1):
    xy=math.sqrt((l[pp[i]][0]-l[pp[i+1]][0])**2 + (l[pp[i]][1]-l[pp[i+1]][1])**2)
    ans+=xy

print(ans/len(p))

Measured memory_bytes: 80244
#!/usr/bin/env python3
import sys


def solve(x: int):
    if x==1:
        print(0)
    else:
        print(1)
    return


# Generated by 1.1.7.1 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    x = int(next(tokens))  # type: int
    solve(x)

if __name__ == '__main__':
    main()


Measured memory_bytes: 9160
#include<bits/stdc++.h>
using namespace std;
int main(){
  ios_base::sync_with_stdio(false);cin.tie(0);
  int N;
  int a;
  int sum = 0;
  cin>>N;
  a = N % 1000;
  if(a != 0){
    sum = 1000 - a;    
  }else{
    sum = 0;
  }
  cout<<sum<<'\n';
}

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

using int32 = int_fast32_t;
using int64 = int_fast64_t;

const int32 INF = 1e9;
const int32 MOD = 1e9+7;
const int64 LLINF = 1e18;

#define YES(n) cout << ((n) ? "YES\n" : "NO\n"  )
#define Yes(n) cout << ((n) ? "Yes\n" : "No\n"  )
#define ANS(n) cout << (n) << "\n"
#define REP(i,n) for(int64 i=0;i<(n);++i)
#define FOR(i,a,b) for(int64 i=(a);i<(b);i++)
#define FORR(i,a,b) for(int64 i=(a);i>=(b);i--)
#define ALL(obj) (obj).begin(),(obj).end()
#define pii pair<int32,int32>
#define pll pair<int64,int64>
#define pb(a) push_back(a)
#define mp make_pair

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int64 n,m;
    cin >> n >> m;
    vector<int64> a(n);
    REP(i,n)cin >> a[i];
    sort(ALL(a));
    vector<int64> aSum(n+1);
    aSum[0] = 0;
    REP(i,n){
        aSum[i+1] = aSum[i] + a[i];
    }
    int64 l = 0, r = aSum[n] + 1;
    int64 cnt;
    while(r - l > 1){
        int64 x = (l + r) / 2;
        cnt = 0;
        REP(i,n){
            cnt += a.end() - lower_bound(ALL(a), x - a[i]);
        }
        if(cnt >= m){
            l = x;
        }else{
            r = x;
        }
    }
    int64 ans = 0;
    REP(i,n){
        int32 idx = lower_bound(ALL(a), l - a[i]) - a.begin();
        ans += (n - idx) * a[i] + aSum[n] - aSum[idx];
    }
    cnt = 0;
    REP(i,n){
        cnt += a.end() - lower_bound(ALL(a), l - a[i]);
    }
    if(cnt > m){
        ans -= l * (cnt - m);
    }
    ANS(ans);
    return 0;
}

Measured memory_bytes: 1792
import java.util.*;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int b = sc.nextInt();
		sc.close();
		System.out.println(6-(n+b));
	}

	public static int arrayMax(int[] array) {
		int ans = Integer.MIN_VALUE;
		for (int i = 0; i < array.length; i++) {
			if (array[i] > ans)
				ans = array[i];
		}
		return ans;
	}

	public static long arrayMax(long[] array) {
		long ans = Long.MIN_VALUE;
		for (int i = 0; i < array.length; i++) {
			if (array[i] > ans)
				ans = array[i];
		}
		return ans;
	}

	public static int[] arrayInt(Scanner sc, int n) {
		int[] array = new int[n];
		for (int i = 0; i < n; i++) {
			array[i] = sc.nextInt();
		}
		return array;
	}

	public static long[] arrayLong(Scanner sc, int n) {
		long[] array = new long[n];
		for (int i = 0; i < n; i++) {
			array[i] = sc.nextLong();
		}
		return array;
	}

	public static double[] arrayDouble(Scanner sc, int n) {
		double[] array = new double[n];
		for (int i = 0; i < n; i++) {
			array[i] = sc.nextDouble();
		}
		return array;
	}

	public static String[] arrayString(Scanner sc, int n) {
		String[] array = new String[n];
		for (int i = 0; i < n; i++) {
			array[i] = sc.next();
		}
		return array;
	}
	static String nextPermutation (String s) {

	ArrayList<Character> list = new ArrayList<>();
	for (int i=0; i<s.length(); i++) list.add(s.charAt(i));

	int pivotPos = -1;
	char pivot = 0;
	for (int i=list.size()-2; i>=0; i--) {
		if (list.get(i) < list.get(i+1)) {
			pivotPos = i;
			pivot = list.get(i);
			break;
		}
	}

	if (pivotPos==-1 && pivot==0) return "Final";

	int L = pivotPos+1, R = list.size()-1;
	int minPos = -1;
	char min = Character.MAX_VALUE;
	for (int i=R; i>=L; i--) {
		if (pivot < list.get(i)) {
			if (list.get(i) < min) {
				min = list.get(i);
				minPos = i;
			}
		}
	}

	Collections.swap(list, pivotPos, minPos);
	Collections.sort(list.subList(L, R+1));

	StringBuilder sb = new StringBuilder();
	for (int i=0; i<list.size(); i++) sb.append(list.get(i));

	return sb.toString();
}
}


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

int main(){

    string s;
    cin >> s;

    int cnt=0;
    rep(i,s.size()){
        if(s[i]=='o'){
            cnt++;
        }
    }

    if(cnt+15-s.size()>=8){
        cout << "YES" << endl;
    }else {
        cout << "NO" << endl;
    }

    return 0;
}

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

int n;
vector <int> idx, p, q;

long long int ffact (int num) {
	long long int pro = 1;
	for (int i = 1; i <= num; pro *= i++);
	return pro;
}

void init () {
		idx.assign(n, 0);
		for (int i = 0; i < n; ++i)
				idx[i]	= i;
}

void update (int num) {		// reduce by one all idx's > num
		for (int i = num + 1; i < n; ++i)
				--idx[i];
}

int rrank (vector <int> &input) {
		long long int r = 0;
		long long int n_fact = ffact(n);
		for (int i = 0; i < n; ++i) {
				n_fact /= (n - i);
			 r += n_fact * idx[input[i] - 1];
				//cout << "rank now : " << r << "\n";
				update(input[i] - 1);
		}
		return r;
}

int main () {
		cin >> n;
		p.assign(n, 0);
		q.assign(n, 0);
		for (int i = 0; i < n; cin >> p[i++]);
		for (int i = 0; i < n; cin >> q[i++]);
		
		init();
		int a = rrank(p);
		init();
		int b = rrank(q);
		//cout << a << " " << b << "\n";
		cout << abs(a - b) << '\n';
		/*
		init();
	 cout << rrank(p) << "\n";	
		while (next_permutation(p.begin(), p.end())) {
				init();
				for (int a : p)
						cout << a << " ";
				cout << "\n" << rrank(p) << "\n";
		}
		*/
		return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <stack>
using namespace std;
int a[10];
bool ans;
void dfs(int i,int r,int l){
	if(i==10){
		ans=1;
		return;
	}
	if(a[i]<r&&a[i]<l)return;
	if(ans)return;
	if(r<a[i])dfs(i+1,a[i],l);
	if(l<a[i])dfs(i+1,r,a[i]);

}
int main(){
	int t;
	cin>>t;
	while(t--){
		ans=0;
		for(int i=0;i<10;i++)cin>>a[i];
		dfs(0,0,0);
		if(ans)cout<<"YES"<<endl;
		else cout<<"NO"<<endl;
	}
}

Measured memory_bytes: 1152
#include<bits/stdc++.h>
using namespace std;
int main(){
  int k; cin >> k;
  int a, b; cin >> a >> b;
  for(int i = a; i <= b; ++i){
    if(i % k == 0){
      cout << "OK" << endl;
      return 0;
    }
  }
  cout << "NG" << endl;
}

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

int main() {
  int n,m,sum;
  cin >> n >> m;
  sum = 0;
  vector<int> vec(n);
  for(int i=0;i<n;i++){
    cin >> vec.at(i);
  }
  for(int i=0;i<n;i++){
    sum += vec.at(i);
  }
  sort(vec.begin(), vec.end());
  reverse(vec.begin(), vec.end());
  if(sum % (4*m) == 0){
    if(vec.at(m-1) < sum/(4*m))
      cout << "No";
    else
      cout << "Yes";
  }
  else{
    if(vec.at(m-1) <= sum/(4*m))
      cout << "No";
    else
      cout << "Yes";
  }
}

Measured memory_bytes: 3604
#include <iostream>
#include<cstdlib>
typedef long long ll;
#define MAX 0x6fffffff

int check(ll P);	//checking how many goods can be loaded by k trucks whose largest carrying limits are P
//time complexity O(n)
ll solve();		//use binary search through the interval of input limit to determine min(P)
//time complexity O(logP)
//check(ll P) invoked in solve(), so the total time complexity is O(nlogP)
int n, k;
int T[100005];

using namespace std;
int main()
{
	//freopen("stdin.txt", "r", stdin);
	cin >> n >> k;
	for (int i = 0; i < n; i++)
	{
		cin >> T[i];
	}
	T[n] = MAX;
	ll ans = solve();
	cout << ans << endl;
	//fclose(stdin);
	return 0;
}

int check(ll P)
{
	int i = 0;
	for (int j = 0; j < k; j++)
	{
		ll sum = 0;
		while (sum + T[i] <= P)
		{
			sum += T[i];
			i++;
		}
		if (i >= n)
		{
			return n;
		}
	}
	return i;
}

ll solve()
{
	ll left = 0;
	ll right = 100000 * 10000;
	ll mid;
	while (right - left > 1)
	{
		mid = (left + right) / 2;
		int v = check(mid);
		if (v >= n)
		{
			right = mid;
		}
		else
		{
			left = mid;
		}
	}
	return right;
}


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

#define INF 1000010000
#define nl '\n'
#define pb push_back
#define ppb pop_back
#define mp make_pair
#define fi first
#define se second
#define pii pair<int,int>
#define pdd pair<double,double>
#define all(c) (c).begin(), (c).end()
#define SORT(c) sort(all(c))
#define sz(c) (c).size()
#define rep(i,n) for( int i = 0; i < n; ++i )
#define repi(i,n) for( int i = 1 ; i <= n; ++i )
#define repn(i,n) for( int i = n - 1 ; i >= 0 ; --i )
#define repf(j,i,n) for( int j = i ; j < n ; ++j )
#define die(s) {std::cout << s << nl;}
#define dier(s) {std::cout << s; return 0;}
#define dbg(var) {std::cout << #var << "  = " << var << nl;}
#define vi vector<int>
typedef long long ll;

using namespace std;


int main() {
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.precision(0); 
	
	int n , m;
	cin >> n >> m;
	
	vi v(n + 10);
	rep(i , m)
	{
		int l , r;
		cin >> l >> r;
		++v[l];
		--v[r + 1];
	}
	
	int ans = 0;
	repi(i , n + 5)
	{
		v[i] += v[i - 1];
		if(v[i] == m) ++ans;
	}
	
	die(ans);
	
	return 0;
}

Measured memory_bytes: 640
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
inline int read()
{
	int out=0,fh=1;
	char jp=getchar();
	while ((jp>'9'||jp<'0')&&jp!='-')
		jp=getchar();
	if (jp=='-')
		fh=-1,jp=getchar();
	while (jp>='0'&&jp<='9')
		out=out*10+jp-'0',jp=getchar();
	return out*fh;
}
const int P=1e9+7;
int add(int a,int b)
{
	return (a+b>=P)?(a+b-P):(a+b);
}
int mul(int a,int b)
{
	return 1LL * a * b % P;
}
const int MAXN=2e5+10;
int a[MAXN],n;
char buf[MAXN];
int solve()
{
	int ans=1,t=0;
	for(int i=1;i<=2*n;++i)
	{
		if(a[i])
			++t;
		else
		{
			if(t==0)
				return 0;
			ans=mul(ans,t);
			--t;
		}
	}
	if(t>0)
		return 0;
	for(int i=1;i<=n;++i)
		ans=mul(ans,i);
	return ans;
}
int main()
{
//	freopen("data.in","r",stdin);
//	freopen("c.out","w",stdout);
	n=read();
	scanf("%s",buf+1);
	for(int i=1;i<=2*n;++i)
		a[i]=!(buf[i]=='B')^(i&1);
	cout<<solve()<<endl;
	return 0;
}


Measured memory_bytes: 1280
#include <iostream>
#include <string>

int main()
{
    std::string S;
    std::cin >> S;
    int count = 0;
    int len = S.size();
    for (int i=0; i<S.size()/2; ++i) {
        if (S[i] != S[len - 1 - i]) count += 1;
    }
    std::cout << count << std::endl;
    return 0;
}

Measured memory_bytes: 256