akhauriyash/Code-Regression huggingface dataset:
//Created by Kira

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

#define IOS cin.sync_with_stdio(0);cin.tie(0); cout.tie(0);
#define all(x) x.begin(), x.end()
#define sz(x) (int)x.size()
#define pii pair<int,int> 
#define pb push_back
#define vi vector<int> 
using ll = long long;

const int mod = 1e9 + 7;

ll pwr(ll a, ll b);
    



int main(){
   IOS

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

   vi cnt(p+1, 0);

    ll ans = 0ll;
   if(p==2||p==5){
       for(int i = 0; i < n; i++){
           if((s[i]-'0') % p ==0)
                ans += i+1;
       }
   }else{

       cnt[0] = 1;
       ll sum = 0;
       ll base = 1ll;
       for(int i = n-1; i >= 0; --i){
           sum = (sum + base  * (s[i]-'0'))%p;
           ans += cnt[sum]++;
           base *= 10, base %= p;
       }

      



   }

    cout<<ans<<"\n";


   




   



}

ll pwr(ll a, ll b){
   a %= mod;	//Remove mod if not required
   ll res = 1;
   while(b > 0){
    if(b&1)
        res = res * a % mod;
        a = a * a % mod;
    b >>= 1;
    }

    return res;
}



Measured memory_bytes: 720
import java.io.*;
import java.util.*;

class Main{
    public static void main(String args[])throws IOException{
      try(BufferedReader br = new BufferedReader(new InputStreamReader(System.in))){
        String[] input = br.readLine().split(" ");

        int N = Integer.parseInt(input[0]);
        int M = Integer.parseInt(input[1]);

        if(N == M){
          System.out.println("Yes");
        }else{
          System.out.println("No");
        }
      }
    }
}

Measured memory_bytes: 21076
#include <stdio.h>
#include <iostream>
#include <vector>

//https://atcoder.jp/contests/abc157/tasks/abc157_b

int main()
{
    std::ios::sync_with_stdio(false); // toggler av synkronisjon mellom c og c++ data streams. kan ikke blade de etter skrudd av
    std::cin.tie(NULL);               //gj;r at man ikke venter på cout og de can printe samtidig tror jeg

    //linjen er opp til 100. det er en linje p[ lengde hundre med hus p[ bare de nevte stedene]]

    std::vector<int> vecBool(9);
    std::vector<int> vec(9);
    for (int u = 0; u < 9; u++)
    {
        std::cin >> vec[u];
        vecBool[u] = 0;
    }

    int n;
    std::cin >> n;

    for (int i = 0; i < n; i++)
    {
        //ma enten ha en hashmap eller lagre en ekstra med en og nuller
        int newNumber;
        std::cin >> newNumber;
        for (int u = 0; u < 9; u++)
        {
            if (vec[u] == newNumber)
            {
                vecBool[u] = 1;
            }
        }
    }

    //egen case for midterste
    if (vecBool[4] == 1)
    {

        int before = vecBool[4 - 4];
        int after = vecBool[4 + 4];

        if (after + before == 2)
        {
            std::cout << "Yes\n";
            return (0);
        }

        before = vecBool[4 - 2];
        after = vecBool[4 + 2];

        if (after + before == 2)
        {
            std::cout << "Yes\n";
            return (0);
        }
    }

    //ROW DOWN
    for (int u = 1; u < 9; u += 3)
    {
        int current = vecBool[u];
        if (current == 1)
        {
            if (vecBool[u - 1] + vecBool[u + 1] == 2)
            {
                std::cout << "Yes\n";
                return (0);
            }
        }
    }

    //row horizontal
    for (int u = 3; u <= 6; u++)
    {
        int current = vecBool[u];
        if (current == 1)
        {
            if (vecBool[u - 3] + vecBool[u + 3] == 2)
            {
                std::cout << "Yes\n";
                return (0);
            }
        }
    }

    // for (int u = 0; u < 9; u++)
    // {
    //     int current = vecBool[u];
    //     if (current == 1)
    //     {
    //         for (int offset = 1; offset < 4; offset += 2)
    //         {
    //             std::cout << offset << "----\n";
    //             int before = 0;
    //             int after = 0;
    //             if (u - offset >= 0)
    //             {
    //                 before = vecBool[u - offset];
    //             }
    //             if (u + offset <= 8)
    //             {
    //                 after = vecBool[u + offset];
    //             }

    //             if (after + before == 2)
    //             {
    //                 std::cout << "Yes\n";
    //                 return (0);
    //             }
    //         }
    //     }
    // }

    //sjekke +- 1,2,3 og 4  hvis de eksisterer for alle.

    std::cout << "No\n";
}


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

int main(){
    ll n ;
    cin >>  n ;
    ll c[n-1] , s[n-1] , f[n-1] ;
    for(ll i = 0 ; i < n -1 ; i++ ){
       cin >> c[i] >> s[i] >> f[i] ;
    }
    ll ans = 0 ;
    ll now ;
    for(ll i = 0 ; i < n -1 ;i++){
         ans += s[i] ;
        
        for(ll j = i ; j < n - 1 ; j++){
           if(ans <= s[j]){
               ans += s[j] - ans + c[j];
                // cout << " now "<< ans << endl;
           }else if(ans % f[j] == 0){
               ans += c[j] ;
               //cout << " now "<< ans << endl;
           }else{
                ans += ((ans-s[j])/f[j]+1)*f[j]+s[j] - ans + c[j];
           }
        }

        cout << ans << endl;
        ans = 0 ;
        now = 0 ;
    }

    cout << 0 << endl;

    return 0 ;
}
    

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i=0;i<static_cast<int>(n);++i)
#define per(i, n) for(int i=static_cast<int>(n)-1;i>=0;--i)
#define eee(a) (cerr<<"[@"<<__LINE__<<"] "<<(#a)<<": "<<(a)<<'\n');
#define ppp(a) (cout<<(a)<<'\n'); 
#define cop(a) for(auto x:(a)){cerr<<(x)<<'\n';}
using ll = long long;
constexpr int dx[4]={1,0,-1,0};
constexpr int dy[4]={0,1,0,-1};
constexpr ll MOD = 1e9+7;
constexpr ll Mod = 998244353;
constexpr int INF = 1e9;
constexpr ll LINF = 1e18;
constexpr double phi = (1+sqrt(5))/2;
constexpr double pi = 3.14159265358979323846264338327950288;
inline ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
inline ll lcm(ll a,ll b){return a/gcd(a,b)*b;}
inline ll inverse(ll n,ll m=MOD){ll a=n,b=m,x=1,y=0;while(b){ll t=a/b;a-=t*b;swap(a,b);x-=t*y;swap(x,y);}return (a%m+m)%m;}
inline void Yes(){puts("Yes");}
inline void No(){puts("No");}
inline void Judge(bool b){b?Yes():No();}
inline void YES(){puts("YES");}
inline void NO(){puts("NO");}
inline void JUDGE(bool b){b?YES():NO();}
inline ll powmod(ll b, ll e, ll m=MOD){ll r=1;while(e>0){if(e&1)r=(r%m)*(b%m)%m;b=(b%m)*(b%m)%m;e>>=1;}return r;}
inline double distance(ll x1, ll y1, ll x2, ll y2){return sqrt((x1-x2)*(x1-x2)+(y1-y2)*(y1-y2));}
inline double d2r(double d){return d*pi/180;}
inline double r2d(double r){return r*180/pi;}
template<class T>inline bool chmax(T &a, const T &b){if(a<b){a=b;return 1;}return 0;}
template<class T>inline bool chmin(T &a, const T &b){if(b<a){a=b;return 1;}return 0;}
template<typename T>inline int bs(int g,int k,T c){while(abs(k-g)>1){int m=(g+k)/2;(c(m)?k:g)=m;}return k;}
template<typename T1,typename T2>ostream& operator<<(ostream& s,const pair<T1, T2>& p){return s <<"("<<p.first<<", "<<p.second<<")";}
template<typename T> ostream& operator<<(ostream& s,const vector<T>& v){s<<'[';for(size_t i=0;i<v.size();++i){s<<v[i];if(i<v.size()-1)s<<", ";}s<<']';return s;}
template<typename T> istream& operator>>(istream& s,vector<T>& v){for(T& x:v)s>>x;return s;}

ll dp[200020][2][3];
int main(){
    cin.tie(0); ios::sync_with_stdio(0); cout<<fixed<<setprecision(15);

    fill_n(**dp, 200020*2*3, -LINF);
    int n;  cin >> n;
    vector<ll> a(n);  cin >> a;
    dp[0][1][0] = 0;

    for(int i = 0; i < n; ++i){
        for(int j = 0; j <= 1; ++j){
            for(int k = 0; k <= 2; ++k){
                if(j+k < 3) chmax(dp[i+1][1][j+k], dp[i][j][k]);
                if(j == 1) chmax(dp[i+1][0][k], dp[i][j][k]+a[i]);
            }
        }
    }
    if(n&1) 
        cout << max(dp[n][0][2], dp[n][1][1]) << '\n';
    else
        cout << max(dp[n][1][0], dp[n][0][1]) << '\n';

    return 0;
}


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

long long a,b,c;
/*
int main() {
	cin>>a>>b>>c;
	if(sqrt(a)+sqrt(b)<sqrt(c))
		printf("Yes\n");
	else printf("No\n");
	return 0;
}
*/

int main() {
	cin>>a>>b>>c;
	if(c-a-b<0) printf("No\n");
	else if(4*a*b>=(c-a-b)*(c-a-b)) printf("No\n");
	else printf("Yes\n");
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
int main(){
  int N;
  cin >> N;
  vector<int> A(N);
  for(int i = 0; i < N; ++i) cin >> A[i];
  sort(A.begin(), A.end(), greater<>());
  int ans = 0;
  for(int i = 0; i < N; ++i) ans += (1-2*(i%2))*A[i];
  cout << abs(ans) << endl;
  return 0;
}


Measured memory_bytes: 256
n,m = map(int, input().split())

d = [0]*m
for _ in range(n):
    flag = True
    for a in map(int, input().split()):
        if flag:
            flag = False
            continue
        d[a-1] += 1

cnt = 0
for i in range(m):
    if d[i]==n:
        cnt += 1
print(cnt)

Measured memory_bytes: 3060
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
const int INF = (1<<29);
const ll INFLL = (1ll<<60);
const ll MOD = (ll)(1e9+7);

#define l_ength size

void mul_mod(ll& a, ll b){
	a *= b;
	a %= MOD;
}

void add_mod(ll& a, ll b){
	a = (a<MOD)?a:(a-MOD);
	b = (b<MOD)?b:(b-MOD);
	a += b;
	a = (a<MOD)?a:(a-MOD);
}

int dp[1001001][2];

int main(void){
	int n,ans,i;
	string s;
	fill(dp[0],dp[1001001],INF);
	cin >> s;
	n = s.l_ength();
	for(i=0; i<n; ++i){
		s[i] -= '0';
	}
	dp[0][0] = 0;
	dp[0][1] = 1;
	for(i=0; i<n; ++i){
		dp[i+1][0] = min(dp[i+1][0],dp[i][0]+s[i]);
		dp[i+1][1] = min(dp[i+1][1],dp[i][0]+s[i]+1);
		dp[i+1][1] = min(dp[i+1][1],dp[i][1]+9-s[i]);
		dp[i+1][0] = min(dp[i+1][0],dp[i][1]+10-s[i]);
	}
	cout << dp[n][0] << endl;
	return 0;
}


Measured memory_bytes: 9348
#include <iostream>
#include <algorithm>
#include <math.h>
#define F(i,a,n) for(int i = (a); i < (n); ++i)
#define Fl(i,a,n) for(long long i = (a); i < (n); ++i)
using namespace std;
int main(){
  int N;
  cin >> N;
  int A[N+2];
  A[0] = 0;
  A[N+1] = 0;
  F(i,1,N+1) cin >> A[i];
  int init = 0;
  F(i,1,N+2){
    init += abs(A[i] - A[i-1]);
  }
  F(i,1,N+1){
    int ans;
    ans = init - abs(A[i] - A[i-1]) - abs(A[i+1] - A[i]) + abs(A[i+1] - A[i -1]);
    cout << ans << endl;
  }
  return 0;
}

Measured memory_bytes: 1664
n = int(input())
a = list(map(int, input().split()))
dic = {}
dic[0] = 1
total = 0
for i in range(n):
  total += a[i]
  if total in dic:
    dic[total] += 1
  else:
    dic[total] = 1
ans = 0
for v in dic.values():
  ans += v*(v-1) // 2
print(ans)


Measured memory_bytes: 39508
#include <bits/stdc++.h>
#define REP(i, n) for (int i = 0; i < (int)(n); i++)
#define REPLL(i, n) for (ll i = 0; i < (ll)(n); i++)
using namespace std;
template<class T>inline bool chmax(T &a, const T &b){if(a < b){a = b; return 1;}return 0;}
template<class T>inline bool chmin(T &a, const T &b){if(a > b){a = b; return 1;}return 0;}
typedef long long ll;

int main(){
  ios::sync_with_stdio(false);
  cin.tie(0);
  int N, K; cin >> N >> K;
  string S; cin >> S;
  string ans;
  REP(i, N){
    if(i == K-1){
      ans += char('a'+(S[i]-'A'));
    }else{
      ans += S[i];
    }
  }
  cout << ans << endl;
}

Measured memory_bytes: 256
#include "bits/stdc++.h"
using namespace std;
#define ll long long int
#define rep(i,n) for( int i = 0; i < n; i++ )
#define rrep(i,n) for( int i = n; i >= 0; i-- )
#define REP(i,s,t) for( int i = s; i <= t; i++ )
#define RREP(i,s,t) for( int i = s; i >= t; i-- )
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define INF 2000000000
#define mod 1000000007
#define INF2 1000000000000000000


int main(void)
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    int S, W; cin >> S >> W;
    if (S <= W) {
        cout << "unsafe" << endl;
    } else {
        cout << "safe" << endl;
    }

    return 0;
}


Measured memory_bytes: 3652
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		int[] a;
		int temp;
		a = new int[3];
		Scanner stIn = new Scanner(System.in);

		for(int i=0;i<3;i++)
			a[i]=stIn.nextInt();

		stIn.close();

		for(int i=0;i<2;i++) {
			for(int j=1;j<3;j++) {
				if(a[i]>a[j]) {
					temp=a[i];
					a[i]=a[j];
					a[j]=temp;
				}
			}
		}

	for(int i=0;i<2;i++)
		System.out.print(a[i]+" ");
	System.out.println(a[2]);

	}
}



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

int main() {
    string name[100];
    int i,n,j;
    std::cin >> n;
    for(i=0;i<n;i++){
        cin >> name[i];
    }
    for(i=0;i<n;i++) {
        for(j=0;j<n;j++){
            if(i==j)break;
            if(name[i]==name[j]){
                cout << "No" <<endl;
                return 0;
             }
        }
    }
        for(i=0;i<n-1;i++) {
       // std::cout << name[i][1] <<std::endl;
       if(name[i+1][0]!=name[i][name[i].size()-1]){
           cout << "No" <<endl;
           return 0;
       }

    }
    cout << "Yes" <<endl;
    // std::cout << "Helloza1ああああ, World!" << std::endl;

    return 0;
}

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

int main(){
  int a,b,c;
  cin >> a >> b >> c;
  vector<int> vec{a,b,c};
  sort(vec.begin(),vec.end());
  cout << vec.at(0)+ vec.at(2)*10+vec.at(1) << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main(){
	int n; cin >> n;
	vector<int> a(n);
	for(int i = 0; i < n; i++) cin >> a[i];
	for(int i = 0; i < n; i++) a[i] %= 2;
	int sum = accumulate(a.begin(), a.end(), 0);
	if(sum%2) printf("NO\n");
	else printf("YES\n");
	return 0;
}


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

typedef long long ll;

int main(void)
{
    //freopen("input.txt", "r", stdin);

    int n, cnt = 0;
    cin >> n;
    cin.ignore();
    string s;
    cin >> s;
    for(int i = 0; i < n; i++)
    {
        if(s[i] == 'A' && s[i+1] == 'B' && s[i+2] == 'C')
        {
            cnt++;
            i += 2;
        }
    }
    cout << cnt << "\n";

    return 0;
}


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

template<class T> void vin(vector<T>& v, int n) {
    v.resize(n);
    for (int i = 0; i < n; ++i) {
        cin >> v[i];
    }
}

int main() {
    ll N;
    cin >> N;
    vector<ll> a(N);
    rep(i, N) cin >> a[i];
    long long ans = 0;
    sort(a.begin(), a.end());
    for (int i=N-1; i>=0; --i) {
        while (a[i]%2 == 0) {
            ans++;
            a[i] /= 2;
        }
    }
    cout << ans << endl;
}


Measured memory_bytes: 384
#include <iostream>
#include <queue>
#include <vector>
#include <algorithm>
#include <set>
#include <cmath>
#include <tuple>
#include <cstring>
#include <map>
#include <iomanip>
#include <ctime>
#include <complex>
#include <cassert>
#include <climits>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
#define _ << " " <<
#define all(X) (X).begin(), (X).end()
#define len(X) (X).size()
#define Pii pair<int, int>
#define Pll pair<ll, ll>
#define Tiii tuple<int, int, int>
#define Tlll tuple<ll, ll, ll>

ll count_pos(ll val, vector<ll> a, vector<ll> d) {
    ll cnt = 0;
    for (int i = 0; i < a.size(); i++) {
        ll bd = val / a[i];
        ll l = -1, r = a.size();
        while (r - l > 1) {
            ll m = (l + r) / 2;
            if (a[m] <= bd) l = m;
            else r = m;
        }
        cnt += l + 1;
        if (i <= l) cnt--;
        //cerr << val _ bd _ i _ l _ cnt << endl;
        //
    }
    for (int i = 0; i < d.size(); i++) {
        ll bd = val / d[i];
        ll l = -1, r = d.size();
        while (r - l > 1) {
            ll m = (l + r) / 2;
            if (d[m] <= bd) l = m;
            else r = m;
        }
        cnt += l + 1;
        if (i <= l) cnt--;
        //cerr << val _ bd _ i _ l _ cnt << endl;
        //
    }
    return cnt / 2;
}

ll count_neg(ll val, vector<ll> b, vector<ll> c) {
    ll cnt = 0;
    for (int i = 0; i < c.size(); i++) {
        ll bd = val / c[i] + bool(val % c[i]);
        ll l = -1, r = b.size();
        while (r - l > 1) {
            ll m = (l + r) / 2;
            if (b[m] < bd) l = m;
            else r = m;
        }
        cnt += b.size() - r;
        //cerr << val _ bd _ i _ l _ cnt << endl;
        //
    }
    return cnt;
}

int main() {
    ll n, k, neg = 0, zero = 0;
    cin >> n >> k;
    vector<ll> a(n), b, c, d;
    for (int i = 0; i < n; i++) {
        cin >> a[i];
        neg += (a[i] < 0);
        zero += (a[i] == 0);
        if (a[i] > 0) b.push_back(a[i]);
        if (a[i] < 0) {
            c.push_back(a[i]);
            d.push_back(-a[i]);
        }
    }

    sort(all(a));
    sort(all(b));
    sort(all(c));
    sort(all(d));

    neg = neg * (n - zero - neg);
    zero = zero * (zero - 1) / 2 + zero * (n - zero);
    cerr << neg _ zero << endl;

    if (neg >= k) {
        ll l = -2e18, r = 0;
        while (r - l > 1) {
            ll m = (l + r) / 2;
            if (count_neg(m, b, c) >= k) r = m;
            else l = m;
        }
        cout << r << endl;
    }
    else if (neg + zero >= k) {
        cout << 0 << endl;
    }
    else {
        k -= neg + zero;
        ll l = 0, r = 2e18;
        //cerr << k << endl;
        while (r - l > 1) {
            ll m = (l + r) / 2;
            //cerr << m _ count_pos(m, b, d) << endl;
            if (count_pos(m, b, d) >= k) r = m;
            else l = m;
        }
        cout << r << endl;
    }
    


}


Measured memory_bytes: 6116
"use strict";
function main(input) {
    const args = input.split('\n');

    const N = parseInt(args[0]);
    const S = args[1];
    const K = parseInt(args[2]);

    const target_s = S.charAt(K - 1);

    let ans = ''

    for(var i = 0; i < S.length; i++) {
        if (S.charAt(i) == target_s) {
            ans += S.charAt(i);
        } else {
            ans += '*';
        }
    }

    console.log(ans)

}
main(require('fs').readFileSync('/dev/stdin', 'utf8'));


Measured memory_bytes: 21064
#include <iostream>
#include <algorithm>
#include <cstdlib>
#include <string>
#include <map>
#include <cmath>
using namespace std;
typedef long long ll;
#define rep(i,n) for(int i=0;i<n;++i)
#define mod 1000000007


int main(){
  string s;
  cin >>s;
  ll res=0,ans=0;
  ll r=0;
  rep(i,s.size()){
    while (r < s.size() && (s[r]=='A' ||s[r]=='T'||s[r]=='G'||s[r]=='C')) {
       ++r;
    }

           /* break した状態で right は条件を満たす最大 */
    res =r - i;
    if (r == i) ++r;
    ans=max(ans,res);
  }

  cout << ans << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define mem(ar,num) memset(ar,num,sizeof(ar))
#define me(ar) memset(ar,0,sizeof(ar))
#define lowbit(x) (x&(-x))
#define Pb push_back
#define  FI first
#define  SE second
#define rep(i,a,n) for (int i=a;i<n;i++)
#define per(i,a,n) for (int i=n-1;i>=a;i--)
#define IOS ios::sync_with_stdio(false)
#define DEBUG cout<<endl<<"DEBUG"<<endl;
using namespace std;
typedef long long LL;
typedef unsigned long long ULL;
const int    prime = 999983;
const int    INF = 0x7FFFFFFF;
const LL     INFF = 0x7FFFFFFFFFFFFFFF;
const double pi = acos(-1.0);
const double inf = 1e18;
const double eps = 1e-6;
const LL     mod = 1e9 + 7;
LL qpow(LL a, LL b) {LL s = 1; while (b > 0) {if (b & 1)s = s * a % mod; a = a * a % mod; b >>= 1;} return s;}
LL gcd(LL a, LL b) {return b ? gcd(b, a % b) : a;}
int dr[2][4] = {1, -1, 0, 0, 0, 0, -1, 1};
typedef pair<int, int> P;
const int maxn = 63;
LL F[maxn][2][2][2][2];

bool A[maxn], B[maxn];
LL solve(int n, int a1, int b1, int a2, int b2) {
	if (n == -1) return 1;
	LL &res = F[n][a1][b1][a2][b2];
	if (res != -1) return res;
	res = 0;
	int a11 = a1 ? A[n] : 0;
	int b11 = b1 ? B[n] : 1;
	int a22 = a2 ? A[n] : 0;
	int b22 = b2 ? B[n] : 1;
	// cout << n << " " << a11 << " " << b11 << " " << a22 << " " << b22 << endl;
	for (int i = a11; i <= b11; ++i) {
		for (int j = a22; j <= b22; ++j) {
			// cout << i << " " << j << endl;
			if (i > j) continue;
			// if (i && j) continue;
			LL t = solve(n - 1, a1 && i == a11, b1 && i == b11, a2 && j == a22, b2 && j == b22);
			t = t  % mod;
			res += t;
			//cout << n << ' ' << i << ' ' << j << " " << t << endl;

			res %= mod;
		}
	}

	return res;
}
int main(void)
{
	LL a, b; cin >> a >> b;
	LL ans = 0;
	for (int i = 62; i >= 0; --i) {
		if (((1LL << i)&b) && ((1LL << i) & a)) {
			LL t2 = b;
			LL t1 = a;
			for (int j = i - 1; j >= 0; --j)
				A[j] = (1LL << j)&t1, B[j] = (1LL << j)&t2;
			memset(F, -1, sizeof(F));
			ans += solve(i - 1, 1, 1, 1, 1);
			ans %= mod;
			break;
		}
		else if ((1LL << i)&b) {
			LL t2 = b;
			LL t1 = (1LL << i);
			for (int j = i - 1; j >= 0; --j)
				A[j] = (1LL << j)&t1, B[j] = (1LL << j)&t2;
			memset(F, -1, sizeof(F));
			ans += solve(i - 1, 1, 1, 1, 1);
			ans %= mod;
			b = t1-1;
		}
	}

	cout << ans << endl;

	return 0;
}

/*

00
*/

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

int main () {
  int N, T;
  cin >> N >> T;
  vector<int> t(N);
  for (int i = 0; i < N; i++) {
    cin >> t.at(i);
  }
  int ans = 0;
  for (int i = 0; i < N-1; i++) {
    if (t.at(i+1)-t.at(i) > T) ans += T;
    else ans += (t.at(i+1)-t.at(i));
  }
  cout << ans + T << endl;
}

Measured memory_bytes: 1024
loop do
  n, m = gets.split.map(&:to_i)
  break if n == 0 && m == 0
  dps = n.times.map { gets.split.map(&:to_i) }
  dps = dps.sort_by { |(d, p)| p }
  while m > 0 && !dps.empty?
    d = dps[-1][0]
    if m >= d
      dps.pop
      m -= d
    else
      dps[-1][0] -= m
      m = 0
    end
  end
  p dps.map { |(d, p)| d * p }.reduce(0, :+)
end


Measured memory_bytes: 7956
t_tairyoku,t_attack,a_tairyoku,a_attack = list(map(int,input().split()))

flag = 0
i = 0

while flag == 0:
    if i%2 == 0:
        a_tairyoku -= t_attack
    else:
        t_tairyoku -= a_attack
    if a_tairyoku <= 0:
        print("Yes")
        exit()
    if t_tairyoku <= 0:
        print("No")
        exit()
    i += 1


Measured memory_bytes: 9108
#include <bits/stdc++.h>
#include <algorithm>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
using namespace std;
 
int main() {
  int i=0,N,count=0;
  cin >> N;
  N=N*2;
  vector <int> vec(N);
  rep(i,N)cin >> vec.at(i);
  i=0;
  while(i<N-1){
    if(vec.at(i)==vec.at(i+1))count++;
    else count=0;
    
    if(count==3){
      cout << "Yes" << endl;
      break;
    }
    i=i+2;
    
  }
  
  
  
  if(i>=N-1)cout << "No" << endl;
  
  return 0;
  
}

Measured memory_bytes: 3604
#include <iostream> // cout, endl, cin
#include <string> // string, to_string, stoi
#include <vector> // vector
#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <utility> // pair, make_pair
#include <tuple> // tuple, make_tuple
#include <cstdint> // int64_t, int*_t
#include <cstdio> // printf
#include <map> // map
#include <queue> // queue, priority_queue
#include <set> // set
#include <stack> // stack
#include <deque> // deque
#include <unordered_map> // unordered_map
#include <unordered_set> // unordered_set
#include <bitset> // bitset
#include <cctype> // isupper, islower, isdigit, toupper, tolower

using namespace std;

#define rep(i, a, b) for (int i = a; i < b; i++)
#define all(A) A.begin(), A.end() 
typedef long long ll;
const ll mod = 1e9 + 7;
const ll inf = 1e9;

int main() {
    int N;
    cin >> N;
    vector<int> L(N);
    rep(i, 0, N) cin >> L[i];

    sort(all(L));
    int ans = 0;
    rep(i, 0, N) {
        rep(j, i+1, N) {
            int k = lower_bound(all(L), L[i] + L[j]) - L.begin();
            ans += max(k - j - 1, 0);
        }
    }

    cout << ans << endl;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main() {
    string s;
    cin >> s;
    int l = s.size();
    vector<int> t(l + 1, 0);
    for (int i = 0; i < l; i++) {
        if (s[i] == '<') {
            t[i + 1] = t[i] + 1;
        }
    }
    for (int i = l; i; i--) {
        if (s[i - 1] == '>') {
            t[i - 1] = max(t[i - 1], t[i] + 1);
        }
    }
    long long sum = 0;
    for (int i = 0; i <= l; i++) {
        sum += t[i];
        //printf("%d ",t[i]);
    }//puts("");
    cout << sum << endl;
    return 0;
}

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

int main() {
  int a, b, o = 1, c = 0;
  cin >> a >> b;
  while (o < b) {
    o += a - 1;
    c++;
  }
  cout << c << endl;
  return 0;
}


Measured memory_bytes: 256
#B問題
N = int(input())
M = int(input())
A = list(map(int,input().split()))
B = [list(map(int,input().split())) for i in range(M)]
C = [0 for i in range(N)]

for i in range(M):
    a = A[i]
    b = B[i]
    for j in range(N):
        if j == a-1:
            C[j]+=1
        else:
            if b[j] == a:
                C[j]+=1
            else:
                C[a-1]+=1
    #print(C)
                
for c in C:
    print(c)
    



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

int main(){
    int k;ll ans=0;
    cin>>k;
    for(int i=1;i<=k;i++){
        for(int j=1;j<=k;j++){
            for(int m=1;m<=k;m++){
                int pp=__gcd(i,j);
                int qq=__gcd(pp,m);
                ans+=qq;
            }
        }
    }
    cout<<ans<<endl;
    
}

Measured memory_bytes: 3576
L,R = map(int,input().split())
if(R-L >= 2019):
    print(0)
else:
    mL = L%2019
    mR = R%2019
    modmin = 2019
    for i in range(mL,mR):
        for j in range(i+1,mR+1):
            modmin = min(modmin,i*j%2019)
    print(modmin)

Measured memory_bytes: 3060
#include <iostream>

using namespace std;

int main(void) {
	int A,B;
	cin >> A >> B;
	if (A%2 == 1 && B%2 ==1) {
		cout << "Odd" << endl;
	}
	else {
		cout << "Even" << endl;
	}
	return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int n,arr[100009],Dp[100009];
int main()
{
    cin>>n;
    for(int i=1;i<=n;i++)
    {
        cin>>arr[i];
    }
    Dp[1]=0;
    //for(int i=2;i<=n;i++)Dp[i]=1000009;
    Dp[2]=abs(arr[1]-arr[2]);
    int sum=0;
    for(int i=3;i<=n;i++)
    {
        Dp[i]=min(Dp[i-1]+abs(arr[i-1]-arr[i]),Dp[i-2]+abs(arr[i-2]-arr[i]));
    }
    cout<<Dp[n];
}

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

#define xx first
#define yy second

using namespace std;

const int sqrInf = (int)(1e9) - 1;

int n, m;
int a[1009][1009];

string s;

const int dl[] = {-1, 1, 0, 0};
const int dc[] = {0, 0, 1, -1};

int sl, sc;
int xl, xc;

priority_queue <pair<pair<int, int>, int>, vector<pair<pair<int, int>, int>>, greater<pair<pair<int, int>, int>> > q;

int dp[1009][1009];
int viz[1009][1009];

void solve()
{
    dp[sl][sc] = 0;
    q.push({{0, sl}, sc});

    while(q.size() > 0)
    {
        auto cr = q.top();
        q.pop();

        int l = cr.xx.yy;
        int c = cr.yy;

        if(viz[l][c] == 0)
        {
            viz[l][c] = 1;

            for(int d = 0; d < 4; d ++)
            {
                int nl = l + dl[d];
                int nc = c + dc[d];

                if(nl >= 1 && nl <= n && nc >= 1 && nc <= m)
                {
                    if(a[nl][nc] == 0)
                    if(dp[l][c] < dp[nl][nc])
                    {
                        dp[nl][nc] = dp[l][c];
                        q.push({{dp[nl][nc], nl},nc });
                    }
                }
            }

            for(int nl = l - 2; nl <= l + 2; nl ++)
            {
                for(int nc = c - 2; nc <= c + 2; nc ++)
                {
                    if(nl >= 1 && nl <= n && nc >= 1 && nc <= m)
                    {
                        if(a[nl][nc] == 0)
                        if(dp[l][c] + 1 < dp[nl][nc])
                        {
                            dp[nl][nc] = dp[l][c] + 1;
                            q.push({{dp[nl][nc], nl},nc });
                        }
                    }
                }
            }
        }
    }
}

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

    cin >> n >> m;
    cin >> sl >> sc;
    cin >> xl >> xc;

    for(int i = 1; i <=n; i ++)
    {
        cin >> s;
        for(int j = 1; j <= m; j ++)
        {
            a[i][j] = s[j - 1] == '#';
            dp[i][j] = sqrInf;
        }
    }

    solve();

    cout << (dp[xl][xc] != sqrInf ? dp[xl][xc] : -1) << "\n";

    return 0;
}


Measured memory_bytes: 15452
#include <stdio.h>

bool ck[3];
int main(){
  char s[3];
  scanf("%s",s);
  for(int i=0;i<3;i++){
    if(s[i]=='a') ck[0]=true;
    else if(s[i]=='b') ck[1]=true;
    else if(s[i]=='c') ck[2]=true;
  }
  if(ck[0]&&ck[1]&&ck[2]) printf("Yes");
  else printf("No");
}


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

using i64 = int64_t;

#define rep(i, x, y) for (i64 i = i64(x), i##_max_for_repmacro = i64(y); i < i##_max_for_repmacro; ++i)
#define debug(x) #x << "=" << (x)

#ifdef DEBUG
#define _GLIBCXX_DEBUG
#define print(x) std::cerr << debug(x) << " (L:" << __LINE__ << ")" << std::endl
#else
#define print(x)
#endif

const int inf = 1.01e9;
const i64 inf64 = 4.01e18;
const double eps = 1e-9;

template <typename T, typename U>
ostream &operator<<(ostream &os, const pair<T, U> &p) {
    os << "(" << p.first << ", " << p.second << ")";
    return os;
}

template <typename T>
ostream &operator<<(ostream &os, const vector<T> &vec) {
    os << "[";
    for (const auto &v : vec) {
        os << v << ",";
    }
    os << "]";
    return os;
}

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

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

template<typename T, size_t size> void fill(T (&ary)[size], const T& val){
    fill_n((T*)ary, size, val);
}

void solve() {
    //const i64 mod = 1'000'000'007;
    
    i64 N,M;
    cin >> N >> M;
    
    vector<vector<i64>> graph(N);
    rep(i,0,M){
        i64 u,v;
        cin >> u >> v;
        --u;
        --v;
        graph[u].emplace_back(v);
    }
    
    i64 S,T;
    cin >> S >> T;
    --S;
    --T;
    
    using tup=tuple<i64,i64,i64>;

    vector<vector<i64>> dist(N,vector<i64>(3,inf));
    priority_queue<tup,vector<tup>,greater<tup>> que;
    que.push(make_tuple(0,S,0));
    dist[S][0]=0;
    
    while(!que.empty()){
        auto t=que.top();
        que.pop();
        
        i64 d,u,s;
        tie(d,u,s)=t;
        if(d>dist[u][s]) continue;
        if(u==T and s==0){
            cout << d << endl;
            return;
        }
        for(auto v:graph[u]){
            i64 nd=d+(s==0?1:0);
            i64 ns=(s+1)%3;
            if(nd>=dist[v][ns]) continue;
            dist[v][ns]=nd;
            que.push(make_tuple(nd,v,ns));
        }
    }
    
    cout << -1 << endl;
}

int main() {
    std::cin.tie(0);
    std::ios::sync_with_stdio(false);
    cout.setf(ios::fixed);
    cout.precision(16);
    solve();
    return 0;
}


Measured memory_bytes: 11264
#include "bits/stdc++.h"
#define FI first.first
#define SE first.second
#define TH second
#define fi first
#define se second
#define th second

using namespace std;

template<typename T>
string to_string(const vector<T>& vc, int w) {
	if(vc.empty()) return "";
	if(w + 1 == vc.size()) return to_string(vc[w]);
	return to_string(vc[w]) + "," + to_string(vc, w + 1);
}

template<typename T>
string to_string(const vector<T>& vc) {
	return "{" + to_string(vc, 0) + "}";
}

void debug_out() { cerr << endl; }
 
template <typename Head, typename... Tail>
void debug_out(Head H, Tail... T) {
  cerr << " " << to_string(H);
  debug_out(T...);
}
 
#ifdef DEBUG
#define debug(...) cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)
#else
#define debug(...) 42
#endif

class DebugStream {}LOG;
template <typename T>DebugStream &operator<<(DebugStream &s, const T&) { return s; }
#ifdef DEBUG
#define LOG clog
#endif

typedef long long ll;
typedef pair<ll, ll> ii;
typedef long double ld;
mt19937 rnd(chrono::steady_clock::now().time_since_epoch().count());

const int maxN = 1e5 + 9, maxV = 1e6 + 9, MOD = 1e9 + 7, SQ = 335, lg = 20, bs = 29;

int main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	#ifdef DEBUG
	freopen("input.txt", "r", stdin);
	#endif

	int n;
	ll k;
	cin >> n >> k;
	vector<ll> arr(n);
	for(auto& el: arr) cin >> el;
	auto slv = [&](ll x) {
		ll sm = 0;
		for(auto el: arr)
			sm += (el - 1) / x;
		return sm <= k;
	};
	int le = 0, ri = MOD, mi;
	while(le + 1 < ri) {
		mi = (le + ri) / 2;
		if(slv(mi)) ri = mi;
		else le = mi;
	}
	cout << ri << '\n';
}



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

int n, r, a[100];

int main()
{
	scanf("%d", &n);
	
	for(int i = 0; i < n; i++) scanf("%d", &a[i]);
	
	for(int i = 0; i < n; i++)
	{
		for(int j = 0; j < i; j++)
		{
			if(a[i] < a[j]) r++;
		}
	}
	
	std::sort(a, a + n);
	
	for(int i = 0; i < n; i++) { if(i) printf(" "); printf("%d", a[i]); }
	
	printf("\n%d\n", r);
	
	return 0;
}

Measured memory_bytes: 3252
#include<stdio.h>
int main(){
    int n,k ;
 
    int a[200002];
    scanf("%d %d", &n, &k);

    for (int i=0; i<n; i++){
        scanf ("%d", a + i);
    }

    for (int i=k; i<n; i++){
        if (a[i] > a[i - k]){  
            printf ("Yes\n");   
        }
        else {
            printf ("No\n");
        }
    }
    return 0;
}

Measured memory_bytes: 2444
#include <cstdio>
#include <string>
using namespace std;

string s;
string r;
char t[17];
int a;

int main(){
	scanf("%s", t);
	s = t;
	r = "CODEFESTIVAL2016";
	for(int i=0; i<16; i++)
		if(s[i] != r[i]) a++;
	printf("%d\n", a);
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
using namespace std;

#define ff              first
#define ss              second
#define int             long long
#define pb              push_back
#define mp              make_pair
#define pii             pair<int,int>
#define vi              vector<int>
#define mii             map<int,int>
#define pqb             priority_queue<int>
#define pqs             priority_queue<int,vi,greater<int> >
#define setbits(x)      __builtin_popcountll(x)
#define zrobits(x)      __builtin_ctzll(x)
#define mod             1000000007
#define inf             1e18
#define ps(x,y)         fixed<<setprecision(y)<<x
#define mk(arr,n,type)  type *arr=new type[n];
#define w(x)            int x; cin>>x; while(x--)
#define FIO             ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
mt19937                 rng(chrono::steady_clock::now().time_since_epoch().count());

typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> pbds;

int path[100001];
int vis[100001];
vi adj[100001];

void dfs(int cur)
{
	vis[cur] = 1;
	for (int nb : adj[cur]) {
		if (!vis[nb])
			dfs(nb);

		path[cur] = max(path[cur], 1 + path[nb]);
	}
}

int32_t main()
{
	FIO;

	int n, m; cin >> n >> m;

	for (int i = 0; i < m; i++) {
		int x, y; cin >> x >> y;
		adj[x].pb(y);
	}

	for (int i = 1; i <= n; i++) {
		if (!vis[i])
			dfs(i);
	}

	int ans = path[1];
	for (int i = 2; i <= n; i++)
		ans = max(ans, path[i]);

	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 13280
N = int(input())

ans = [0] * (N+1)
for a in range(1, 105):
  if a*a > N :
    continue
  for b in range(1, 105):
    if a*a + b*b > N:
      continue      
    for c in range(1, 105):
      if a*a + b*b + c*c + a*b + b*c + c*a > N:
        continue
      ans[a*a + b*b + c*c + a*b + b*c + c*a] += 1

for i in range(1, N+1):
  print(ans[i])

Measured memory_bytes: 9320
#include<iostream>
using namespace std;
//10^9=10億 intの限界寸前
int main(){
	int k,a,b;
	cin >> k >> a >> b;
	for(int i=a;i<=b;i++)
	{
		if(i%k==0)
		{
			cout<<"OK";
			return 0;
		}
	}
	cout << "NG";
	return 0;
}

Measured memory_bytes: 3100
#include <bits/stdc++.h>
using namespace std;
#define lp(i, x, n) for (int i = x; i < (int)n; ++i)
#define all(v) (v).begin(), (v).end()
#define sz(v) (int)(v).size()
#define ll long long
#define N 1000001
int ar[3];
int main() {
        cin >> ar[0]>> ar[1]>> ar[2];
        sort(ar, ar + 3);
        int nm = ar[2] * 10 + ar[1] + ar[0];
        cout << nm;
        return 0;
}


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

using namespace std;

int const maxn = 2e5 + 5;
int a[maxn];
int inf = 1e9;
unordered_map < int, int > val;

inline int oks(int sz, int n) {
    set < int > R = {1};
    val[1] = 1;
    for (int i = 1; i <= n; ++i) {
        if (a[i] > a[i - 1]) continue;
        while (1) {
            int pos = (*R.rbegin());
            if (pos <= a[i]) break;
            R.erase(pos);
        }
        int good = a[i];
        while (1) {
            if ((int)R.size() == 0) return 0;
            int pos = (*R.rbegin()), c = val[pos];
            if (c == sz) {
                good = pos - 1;
                R.erase(pos);
                continue;
            }
            val[good] = c + 1;
            val[good + 1] = 1;
            R.insert(good);
            R.insert(good + 1);
            break;
        }
    }
    return 1;
}

main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    int n;
    cin >> n;
    for (int i = 1; i <= n; ++i) cin >> a[i];
    int lef = 0, righ = n + 1;
    while (righ - lef > 1) {
        int mid = (righ + lef) / 2;
        if (oks(mid, n)) righ = mid;
        else lef = mid;
    }
    cout << righ << '\n';
    return 0;
}


Measured memory_bytes: 9288
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define fastio ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);

int main() {
    fastio
	ll n,t,i,j,x,k;
    cin>>n;
    
    if(n==0) cout<<"1";
    else cout<<"0";
    
	return 0;
}

Measured memory_bytes: 3632
#include <iostream>

using namespace std;

int main() {
    string s;
    cin >> s;
    int answer = 0;
    for (int i = 0; i < 3; ++i) {
        if (s[i] == 'R') {
            ++answer;
            for (int j = i + 1; j < 3; ++j) {
                if (s[j] == 'R') {
                    ++answer;
                } else {
                    break;
                }
            }
            break;
        }
    }
    cout << answer << endl;
}


Measured memory_bytes: 3616
#include<cstdio>
const int N=1e5+10;
int a[N],n,f[N];
int ab(int x){return x<0?-x:x;}
int mi(int a,int b){return a<b?a:b;}
int main()
{
	scanf("%d",&n);
	for(int i=1;i<=n;i++)
	{
		scanf("%d",&a[i]);
		f[i]=1e9;
	}
	f[1]=0;
	f[2]=ab(a[2]-a[1]);
	for(int i=3;i<=n;i++)
		f[i]=mi(f[i-1]+ab(a[i]-a[i-1]),f[i-2]+ab(a[i]-a[i-2]));
	printf("%d",f[n]);
	return 0;
}


Measured memory_bytes: 896
import java.io.*;
import java.util.Scanner;
public class Main {
    public static void main(String[] args) {
        Scanner scan = new Scanner(System.in);
        int N = scan.nextInt();
        int D = scan.nextInt(); 
        int count=0;
        count = (N+2*D)/(2*D+1);
        System.out.println(count);
    }
}

Measured memory_bytes: 21844
#include <bits/stdc++.h>
using namespace std;
using LL  = long long;
using VI  = vector<LL>;
using VVI = vector<VI>;
using VB  = vector<bool>;
using VS  = vector<string>;
using PII = pair<LL, LL>;
using VP  = vector<PII>;
#define PB           push_back
#define MP           make_pair
#define SZ(a)        LL((a).size())
#define EACH(x, c)   for (auto x : (c))
#define ALL(c)       (c).begin(), (c).end()
#define REVERSE(c)   reverse(ALL(c))
#define SORT(c)      stable_sort(ALL(c))
#define RSORT(c)     stable_sort((c).rbegin(), (c).rend())
#define FSORT(c)     stable_sort(ALL(c), [] (auto& x, auto& y) {return x.first < y.first;});
#define FRSORT(c)    stable_sort(ALL(c), [] (auto& x, auto& y) {return x.first > y.first;});
#define SSORT(c)     stable_sort(ALL(c), [] (auto& x, auto& y) {return x.second < y.second;});
#define SRSORT(c)    stable_sort(ALL(c), [] (auto& x, auto& y) {return x.second > y.second;});
#define FOR(i, a, b) for (LL i = (a); i < (b); ++i)
#define REP(i, n)    FOR(i, 0, n)
#define $(x) {cout << #x << " = " << (x) << endl;}


int main() {
    LL W, H, x, y;
    cin >> W >> H >> x >> y;

    double a = (double)W * H / 2;
    LL multiple = 0;
    if (W % 2 == 0 && W / 2 == x && H % 2 == 0 && H / 2 == y) multiple = 1;
    cout << fixed << setprecision(12) << a << " " << multiple << endl;
	
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define ll long long
ll gcd(ll x, ll y) { return (x % y)? gcd(y, x % y): y; }    //最大公約数
ll lcm(ll x, ll y) { return x / gcd(x, y) * y; }     //最小公倍数
using Graph = vector<vector<int>>;
 
const double PI = 3.14159265358979323846;
/*Graph t;
void dfs(int v, int pv=-1){
    for(int vn: t[v]){
        if (vn == pv) continue;
        dfs(vn, v);
    }
}*/
int main() {
  ll n,k;
  cin >> n >> k;
  ll a[n];
  rep(i,n)cin >> a[i];
  ll ans=1000000000000;
  rep(i,n-k+1){
    ll b=a[i],c=a[i+k-1];
    if(b*c>=0)ans=min(ans,max(abs(b),abs(c)));
    else ans=min(ans,abs(b-c)+min(abs(b),abs(c)));
  }
  cout << ans << endl;
}


Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int n;
    cin>>n;
    int a[n];
    int maxa=0;
    int count=0;

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

    for (int i = 0; i < n; ++i) {
        if(a[i]>=maxa)
        {
            maxa=a[i];
            count++;
        }
    }
    cout<<count;
}

Measured memory_bytes: 256
L, R = map(int, input().split())
ans = 10000

if R - L >= 2019:
    print(0)
    exit()
else:
    for i in range(L, R + 1):
        for j in range(i + 1, R + 1):
            if (i * j) % 2019 < ans:
                ans = (i * j) % 2019

print(ans)


Measured memory_bytes: 2940
#include <bits/stdc++.h>
#define rep(i,n) for(int (i)=0;(i)<(n);++(i))
#define all(x) (x).begin(),(x).end()
#define dump(x) cout << #x << " = " << (x) << endl
#define YES(n) cout << ((n) ? "YES" : "NO") << endl
#define Yes(n) cout << ((n) ? "Yes" : "No") << endl
#define yes(n) cout << ((n) ? "yes" : "no") << endl

using namespace std;
using ll = long long;
using P = pair<int, int>;

const int INF = 1001001001;
const vector<int> di = {-1,  0, 1, 0};
const vector<int> dj = { 0, -1, 0, 1};

void chmin(int &a, int b) { if (a > b) a = b; }

ll GCD(ll a, ll b) {
    if (b == 0) return a;
    else return GCD(b, a % b);
}
ll LCM(ll a, ll b) {
    ll g = GCD(a, b);
    return a / g * b;
}


int main(){
    ll N, M;
    cin >> N >> M;
    ll teisyutu_kaisuu = 1LL<<M;
    ll each_time = 1900LL * M + 100LL * (N - M);
    cout <<  each_time * teisyutu_kaisuu << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define int long long
const int LINF=1e18;
 
signed main(){
  int N,K;cin>>N>>K;
  vector<int> a(N),f(N);
  for(int i=0;i<N;i++)cin>>a[i];
  for(int i=0;i<N;i++)cin>>f[i];
  sort(a.begin(),a.end());
  sort(f.rbegin(),f.rend());
  int l=-1,r=LINF;
  while(r-l>1){
    int m=(r+l)>>1;
    int cnt=0;
    for(int i=0;i<N;i++){
      if(a[i]*f[i]>m){
        cnt+=(a[i]*f[i]-m)/f[i];
        if((a[i]*f[i]-m)%f[i])cnt++;
      }
    }
    if(cnt>K)l=m;
    else r=m;
  }
  cout<<r<<endl;
}

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

namespace My
{
class Solver
{
  public:
	Solver() {}
	void Solve(istream &cin, ostream &cout)
	{
      int S, W;
      cin >> S >> W;
      
      if (S <= W){
        cout << "unsafe" << endl;
      }else{
        cout << "safe" << endl;
      }
	}
};
} // namespace My

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

	My::Solver solver;
	solver.Solve(std::cin, std::cout);

	return 0;
}


Measured memory_bytes: 3636
#include<bits/stdc++.h>
#define x first
#define y second
using namespace std;
int w,h,n,ans,st1[300010],st2[300010];
pair<int,int> dt[300010];
struct seg
{
	int mx[3000100],tag[3000100];
	void clear()
	{
		memset(mx,0,sizeof(mx));
		memset(tag,0,sizeof(tag));
	}
	void pushdown(int root)
	{
		mx[2*root]+=tag[root];tag[2*root]+=tag[root];
		mx[2*root+1]+=tag[root];tag[2*root+1]+=tag[root];
		tag[root]=0;
	}
	void modify(int ql,int qr,int w,int root=1,int pl=1,int pr=n)
	{
		if ((pl==ql)&&(pr==qr)) {tag[root]+=w;mx[root]+=w;return;}
		pushdown(root);
		int mid=(pl+pr)>>1;
		if (ql<=mid) modify(ql,min(mid,qr),w,root*2,pl,mid);
		if (qr>mid) modify(max(mid+1,ql),qr,w,root*2+1,mid+1,pr);
		mx[root]=max(mx[root*2],mx[root*2+1]);
	}
}seg;
void work()
{
	sort(dt+1,dt+n+1);
	int top1=0,top2=0;
	if (dt[n].x!=w) dt[++n]=make_pair(w,-1);
	seg.clear();
	for (int i=1;i<=n;i++) seg.modify(i,i,-dt[i-1].x);
	for (int i=1;i<=n;i++)
	{
		seg.modify(i,i,h);
		ans=max(ans,dt[i].x+seg.mx[1]);
		if (dt[i].y>h/2)
		{
			seg.modify(st1[top1]+1,i,dt[i].y-h);
			while ((top1)&&(dt[st1[top1]].y>=dt[i].y))
			{
				seg.modify(st1[top1-1]+1,st1[top1],dt[i].y-dt[st1[top1]].y);
				top1--;
			}
			st1[++top1]=i;
		}
		else
		{
			seg.modify(st2[top2]+1,i,-dt[i].y);
			while ((top2)&&(dt[st2[top2]].y<=dt[i].y))
			{
				seg.modify(st2[top2-1]+1,st2[top2],dt[st2[top2]].y-dt[i].y);
				top2--;
			}
			st2[++top2]=i;
		}
	}
	n-=(dt[n].y<0);
}
int main()
{
	scanf("%d%d%d",&w,&h,&n);
	for (int i=1;i<=n;i++) scanf("%d%d",&dt[i].x,&dt[i].y);
	work();
	swap(w,h);
	for (int i=1;i<=n;i++) swap(dt[i].x,dt[i].y);
	work();
	printf("%d\n",ans*2);
}

Measured memory_bytes: 27136
import math
n = int(input())
from collections import defaultdict
d = defaultdict(list)
s = set()
zc = 0
for i in range(n):
    a,b = map(int, input().split())
    g = math.gcd(a,b)
    if g!=0:
        a //= g; b //= g
        if a<0:
            a,b = -a, -b
        elif a==0 and b<0:
            b *= -1
        d[a,b].append(i)
    if a==b==0:
        zc += 1
v = 1
s = set()
M = 10**9+7
for (a,b),val in d.items():
    aa,bb = b,-a
    if aa<0:
        aa,bb = -aa, -bb
    elif aa==0 and bb<0:
        bb *= -1
    if (a,b) in s or (aa,bb) in s:
        continue
    if (aa,bb) in d.keys():
        v *= (pow(2, len(val), M) + pow(2, len(d[aa,bb]), M) - 1)
    else:
        v *= pow(2, len(val), M)
    v %= M
    s.add((a,b))
    s.add((aa,bb))
v -= 1
v += zc
print(v%M)

Measured memory_bytes: 194568