akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#define int         long long int
#define pb          push_back
#define endl        "\n"
#define hell        1000000007
#define INF         1000000000000000000

using namespace std;

  void solve()
  {
  string s;
  cin>>s;
  int n=s.size();
  if(s[n-1]=='s')
  {
    cout<<s<<"es";
  }
  else
    cout<<s<<"s";

  }
  
  

 
  signed main()
  {
    ios::sync_with_stdio(false);
      cin.tie(0);
      cout.tie(0);
    #ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    #endif
    int t;
    t=1;
    //cin>>t;
    while(t--)
        solve();

return 0;
  }

Measured memory_bytes: 3656
#include <bits/stdc++.h>
#define f first
#define s second
#define pb push_back
#define mp make_pair
using namespace std;
typedef unsigned int uint;
typedef long long ll;
typedef long double ld;
const int N = 100006;

int main() {
 
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    
    ll n, k;
    cin >> n >> k;

    vector<int> p(n + 1);
    for(int i = 1; i <= n; i++) cin >> p[i];
    vector<ll> c(n + 1);
    for(int i = 1; i <= n; i++) cin >> c[i];

    ll ans = -2e18;

    for(int i = 1; i <= n; i++) {

        ll sum = 0;
        vector<int> cyc;
        int now = i, root = i;

        while(root != p[now]) {
            sum += c[now];
            cyc.pb(now);
            now = p[now];
        }

        cyc.pb(now);
        sum += c[now];

        ll cur = 0, cnt = 0;

        for(int j = 1; j < cyc.size() && cnt < k; j++) {

            cur += c[cyc[j]];
            cnt += 1;
            ll now_k = k - cnt;
            now_k /= (int) cyc.size();

            if(sum < 0) ans = max(ans, cur); else ans = max(ans, cur + sum * now_k);
        }

        ll now_k = k / (int) cyc.size();

        if(now_k > 0) ans = max(ans, sum * now_k);
    }

    cout << ans << '\n';

    return 0;
}

// 


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

int main()
{
    string s;
    cin >> s;
    int n = s.size();
    int cb = 0;
    int cw = 0;
    ll cnu = 0;
    rep(i, n)
    {
        if (s[i] == 'B')
        {
            cb++;
        }
        else
        {
            cnu += cb;
        }
    }
    cout << cnu << endl;
}

Measured memory_bytes: 640
/**
 *    author        : Saurav Paul 
 *    created       : August 14, 2020 9:28 PM
 *    Problem Name  : K - Stones
 *    Problem Limit : 2000 ms , 1024 MB
 *    Problem Url   : https://atcoder.jp/contests/dp/tasks/dp_k
 *    @genarated by : ai-virtual-assistant
**/

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

using ll = long long int ;

void solve(){
    int N , K ;
    cin >> N >> K ;

    bool dp[K+1] = {} ;
    vector<int> v(N) ;
    for(auto &x : v){
        cin >> x;
    }

    for(int stones = 0 ; stones <= K ; stones ++){
        for(auto x : v){
            if(stones >= x){
                if(!dp[stones-x]) dp[stones] = true ;
            }
        }
    }

    cout << (dp[K]?"First":"Second") << endl ;

}

int main(){
    ios_base::sync_with_stdio(false);

    int testcases = 1;
    for(int i = 1 ; i <= testcases ; i ++){
        solve();
    }

    return 0 ;
}


Measured memory_bytes: 3708
#include  <iostream>
#include  <stdio.h>
#include <algorithm>
#include <map>
#include <math.h>

using namespace std;
#include <vector>
#define rep(i,n) for (ll i = 0; i < (n) ; i++)
#define INF 1e9
#define llINF 1e18
#define base10_4 10000      //1e4
#define base10_5 100000     //1e5
#define base10_6 1000000    //1e6
#define base10_7 10000000   //1e7
#define base10_8 100000000  //1e8
#define base10_9 1000000000 //1e9

#define MOD 1000000007
#define pb push_back
#define ll long long
#define ull unsigned long long
#define vint vector<int>
#define vll vector<ll>

//#include <stack>
//#include <queue>

// #include <iomanip>
//  cout << fixed << setprecision(15) << y << endl;

string ans_Yes = "Yes"; 
string ans_No = "No"; 
string ans_yes = "yes"; 
string ans_no = "no"; 

ll A;
ll B;
ll C;
ll D;
ll X;
ll K;

ll ltmp;
string stmp;
double dtmp;

ll llmin(ll a,ll b){
    if(a>=b) return b;
    return a;
}
ll llmax(ll a,ll b){
    if(a<=b) return b;
    return a;
}
int main(){

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

    cin >> X;
    cin >> K;
    cin >> D;

    //X = 1000000000000000;

    X = abs(X);
    ll cnt_to0 = X/D;

    if(K <= cnt_to0){
        X = X - K * D;
        cout << X << endl;
    }else{
        
        X = X - cnt_to0 * D;
        ll X2 = abs(X - D);
        K = K - cnt_to0;
        if(K % 2 ==0){
            cout << X << endl;
        }else{
            cout << X2 << endl;
        }
    }



    

}

Measured memory_bytes: 3652
#include <bits/stdc++.h>
using namespace std;
int main(){
  int N;
  cin >> N;
  vector<int> t, x, y;
  t.push_back(0);
  x.push_back(0);
  y.push_back(0);
  for (int i = 0; i < N; i++){
    int T, X, Y;
    cin >> T >> X >> Y;
    t.push_back(T);
    x.push_back(X);
    y.push_back(Y);
  }
  bool flg = true;
  for (int i = 0; i < N; i++){
    int T = t[i + 1] - t[i];
    int d = abs(x[i + 1] - x[i]) + abs(y[i + 1] - y[i]);
    if (T < d || T % 2 != d % 2){
      flg = false;
    }
  }
  if (flg){
    cout << "Yes" << endl;
  } else {
    cout << "No" << endl;
  }
}

Measured memory_bytes: 1644
from queue import Queue

K = int(input())
Q = Queue()

for q in range(1,9+1):
    Q.put(q)

lun = -1
for i in range(K):
    x = Q.get()
    # print(x)
    lun = x

    if x % 10 != 0:
        Q.put(10*x + (x%10) -1)
        # print("put1 {}".format(10*x + (x//10) -1))

    Q.put(10*x + (x%10))
    # print("put2 {}".format(10 * x + (x // 10)))

    if x%10 != 9:
        Q.put(10*x + (x%10) + 1)
        # print("put3 {}".format(10 * x + (x // 10) + 1))

# print("SSS")
print(lun)




# AR = []
#
# lun = -1
# count = 0
#
# for i in range(1,10000000000+1):
#     # print(lun)
#     if count == K:
#         break
#
#     if i < 10:
#         lun = i
#         # AR[0] = i
#         count += 1
#     else:
#
#         V = str(i)
#         digit = len(V)
#         absc = 0
#
#         for b in range(digit):
#             if b == 0:
#                 continue
#             elif abs(int(V[b]) - int(V[b-1])) <= 1:
#                 absc +=1
#             else:
#                 break
#
#         if absc == digit-1:
#             lun = i
#             count+=1
#
#
#
# print(lun)


Measured memory_bytes: 12452
#include <bits/stdc++.h>
#define endl "\n"
#define sz(x) ((ll)(x).size())
#define pb push_back
#define all(x) (x).begin(),(x).end()
#define prt(x) cout << (x)
#define prtl(x) cout << (x) << endl
#define rep(i,a,b) for(ll i=a; i<b; i++)
#define rrep(i,a,b) for(ll i=a; i>b; i--)
#define mp(a, b) make_pair(a, b)
#define chmin(x, y) x = min(x, y)
#define chmax(x, y) x = max(x, y)
#define debug(v) cout << #v<< ": " << v <<endl;
using namespace std;
using vi = vector<int>;
using vll = vector<long long int>;
using vb = vector<bool>;
using vvb = vector<vector<bool>>;
using vc = vector<char>;
using vvi = vector<vector<int>>;
using vvll = vector<vector<long long int>>;
using vvc = vector<vector<char>>;
using ll = long long int;
using P = pair<long long int, long long int>;
using Map = map<long long int, long long int>;
ll INF = 1LL<<60;
ll M = 1000000007;

vector<ll> fac(300000); //n!(mod M)
vector<ll> ifac(300000); //k!^{M-2} (mod M)
//a,bの範囲的にこれだけ配列を用意していけば十分

ll mpow(ll x, ll n){ //x^n(mod M) ←普通にpow(x,n)では溢れてしまうため，随時mod計算
    ll ans = 1;
    while(n != 0){
        if(n&1) ans = ans*x % M;
        x = x*x % M;
        n = n >> 1;
    }
    return ans;
}

ll comb(ll a, ll b){ //aCbをmod計算
    if(a == 0 && b == 0)return 1;
    if(a < b || a < 0 || b < 0)return 0;
    ll tmp = ifac[a-b]* ifac[b] % M;
    return tmp * fac[a] % M;
}

ll hcomb(int P_,int Q_) { return (P_==0&&Q_==0)?1:comb(P_+Q_-1,Q_);}

int main(){
    fac[0] = 1;
    ifac[0] = 1;
    for(ll i = 0; i<300000; i++){
        fac[i+1] = fac[i]*(i+1) % M; // n!(mod M)
        ifac[i+1] = ifac[i]*mpow(i+1, M-2) % M; // k!^{M-2} (mod M) ←累乗にmpowを採用
    }
    ll n, k; cin >> n >> k;
    vll a(n);
    rep(i, 0, n){
        cin >> a[i];
    }
    sort(a.begin(),a.end());
    ll ans = 0;
    rep(i, 0, n){
        ll t = a[i];
        t *= comb(n-i-1, k-1);
        t %= M;
        ans -= t;
        ans %= M;
    }
    rrep(i, n-1, -1){
        ll s = a[i];
        s *= comb(i, k-1);
        s %= M;
        ans += s;
        ans %= M;
    }
    if(ans < 0){
        ans = M + ans;
    }
    prtl(ans%M);
}


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

#define lint long long
#define P pair<int, int>
#define LLP pair<long long, long long>
#define REP(i, x, n) for(int i = (x), i##_len = (int)(n) ; i < i##_len ; ++i)
#define rep(i, n) for(int i = 0, i##_len = (int)(n) ; i < i##_len ; ++i)
#define repr(i, n) for(int i = (int)(n) - 1 ; i >= 0 ; --i)
#define SORT(x) sort((x).begin(), (x).end())
#define SORT_INV(x) sort((x).rbegin(), (x).rend())

const int IINF = 1e9 + 100;
const long long LLINF = 2e18 + 129;
const long long MOD = 1e9 + 7;
const int dx4[] = {1, 0, -1, 0}, dy4[] = {0, 1, 0, -1};
const int dx8[] = {1, 1, 0, -1, -1, -1, 0, 1}, dy8[] = {0, -1, -1, -1, 0, 1, 1, 1};
const double EPS = 1e-8;

vector<lint> s, t;

LLP nearest(lint x, vector<lint> &v){
    auto it1 = upper_bound(v.begin(), v.end(), x);
    auto it2 = it1;
    if(it1 != v.begin()){
        --it1;
    }
    if(it1 == v.end()){
        --it1;
        --it2;
    }

    return {*it1, *it2};
}

lint calc(lint x, lint a, lint b){
    if(a < x && b < x){
        return x - min(a, b);
    }else if(a < x){
        return b - a + min(x - a, b - x);
    }else if(b < x){
        return a - b + min(x - b, a - x);
    }else{
        return max(a, b) - x;
    }
}

lint query(lint x){
    LLP sh = nearest(x, s);
    LLP te = nearest(x, t);

    return min({calc(x, sh.first, te.first), calc(x, sh.first, te.second), calc(x, sh.second, te.first), calc(x, sh.second, te.second)});
}

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

    lint a, b;
    int q;
    cin >> a >> b >> q;

    s.resize(a);
    rep(i, a){
        cin >> s[i];
    }
    t.resize(b);
    rep(i, b){
        cin >> t[i];
    }

    rep(i, q){
        lint x;
        cin >> x;
        lint ans = query(x);
        cout << ans << endl;
    }

    return 0;
}

Measured memory_bytes: 2944
import java.util.*;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int digits = String.valueOf(n).length();
        int ans = 0;
        for (int i = 1; i <= digits; i++) {
            if (i % 2 == 1) {
                if (i == digits) {
                    ans += n - (int)Math.pow(10, i-1) + 1;
                } else {
                    ans += (int)Math.pow(10, i-1) * 9;
                }
            }
        }
        // 出力
        System.out.println(ans);
    }
}


Measured memory_bytes: 23764
import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner scanner = new Scanner(System.in);
		int ans = 0;
		int n = scanner.nextInt();
		double d = scanner.nextInt();
		List<Integer> x_y = new ArrayList<>();
		List<List<Integer>> x_y_set = new ArrayList<>();
		for (int i = 0; i < n; i++) {
			x_y.add(scanner.nextInt());
			x_y.add(scanner.nextInt());
			x_y_set.add(new ArrayList<>(x_y));
			x_y.clear();
		}
		double distance =0;
		for (int i = 0; i < n; i++) {
			distance = Math.sqrt(Math.pow(x_y_set.get(i).get(0),2)
									+ Math.pow(x_y_set.get(i).get(1),2));
			if(distance <= d) {
				ans+=1;
			}

		}
		System.out.println(ans);
		scanner.close();
	}
}

Measured memory_bytes: 78056
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll MOD = 1000000007;


int main(){
  int n;  cin >> n;
  vector<ll> a(n), b(n);
  ll asum=0, bsum=0;

  for(int i=0; i<n; i++)  cin >> a.at(i);
  for(int i=0; i<n; i++)  cin >> b.at(i);
    
  
  vector<ll> dis(n);
  for(int i=0; i<n; i++){
    asum += a.at(i);
    bsum += b.at(i);
    dis.at(i) = a.at(i)-b.at(i);
  }
  sort(dis.begin(), dis.end(), greater<ll>());
  // for(int i=0; i<n; i++){
  //   cout << a[i] << b[i] << endl;
  // }
  
  ll j=0, next=0, cnt=-1;
  if(bsum<=asum){
    cnt=0;
    for(int i=0; i<n; i++){
      if(b[i]<=a[i]) continue;
      cnt += 1;
      while(next-(b[i]-a[i])<0){
        next += dis[j];
        cnt += 1; j += 1;
      }
      next -= (b[i]-a[i]);
    }
  }
  cout << cnt << endl;
}


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

#define all(v) v.begin(), v.end()
#define intll int long long
#define rep(i, n) for (intll i = 0; i < (int)(n); i++)
const int INF = 1e9;
const int MOD = 1e9 + 7;

  
int main() {
  intll l , r ;
  cin >> l >> r ;
  intll ans = INF ;
  
  for(int i=l;i<min(r,l+2020);i++){
    for(int j=i+1;j<=min(r,l+2020);j++){
      intll now = (i%2019) * (j%2019) %2019 ;
      ans = min(ans,now) ;
    }
  }
  
 
  cout <<  ans  ;
  


}




Measured memory_bytes: 3596
let [|N;K|] =
    stdin.ReadLine().Split()
    |> Array.map int

let rec f x v =
    if x>=K then v
    else f (2*x) (v+1.0)

[|1..N|]
|> Array.sumBy (fun x -> 1.0/float(N)*(0.5**(f x 0.0)))
|> stdout.WriteLine

Measured memory_bytes: 31404
N,M = map(int,input().split())
A = [input() for _ in range(N)]
B = [input() for _ in range(M)]

def comp(x,y):
    for i in range(M):
        for j in range(M):
            if A[x+i][y+j] != B[i][j]:
                return False
    return True
flag = False
for i in range(N-M+1):
    for j in range(N-M+1):
        if comp(i,j):
            flag = True
            break
if flag:
    print('Yes')
else:
    print('No')

Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
#define pb push_back
#define mk make_pair
#define mod 1000000007
#define ll long long
#define lb lower_bound
#define ub upper_bound
#define endl "\n"
#define ff first
#define ss second
#define prec(y,x) fixed<<setprecision(y)<<x
#define inf 1e18
#define pi 3.1415926535

int main()
{
	ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#ifndef ONLINE_JUDGE
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#endif

	int n;
	cin >> n;
	int arr[6] = {0};
	for (int i = 0; i < n; i++)
	{
		string s;
		cin >> s;
		if (s[0] == 'A')
		{
			arr[0]++;
		}
		else if (s[0] == 'T')
		{
			arr[1]++;
		}
		else if (s[0] == 'W')
		{
			arr[2]++;
		}
		else
			arr[3]++;
	}
	cout << "AC x " << arr[0] << endl;
	cout << "WA x " << arr[2] << endl;
	cout << "TLE x " << arr[1] << endl;
	cout << "RE x " << arr[3] << endl;


	return 0;
}

Measured memory_bytes: 3644
#include <cstdio>
#define N 100010
using namespace std;

int n, a, t[N];

inline void ef(int a) {
	int l = 1, r = t[0];
	while (l <= r) {
		int mid = (l + r) >> 1;
		if (t[mid] < a)
			r = mid - 1;
		else
			l = mid + 1;
	}
	t[l] = a;
}

int main() {
	scanf("%d", &n);
	for (int i = 1; i <= n; ++i) {
		scanf("%d", &a);
		if (i == 1)
			t[++t[0]] = a;
		else if (a <= t[t[0]])
			t[++t[0]] = a;
		else
			ef(a);
	}
	printf("%d", t[0]);
	return 0;
}


Measured memory_bytes: 512
#include<bits/stdc++.h>
// #define int long long
#define rep(i, n) for(int i = 0; i < (int)n; i++)
#define repa(i, s, n) for(int i = s; i < (int)n; i++)
#define MOD 1000000007
using namespace std;
using ll = long long;
typedef vector<int> vi;

signed main() {
    ll a;
    string b;
    cin >> a >> b;
    ll b_100 = (b[0] - '0')*100 + (b[2] - '0')*10 + (b[3] - '0');
    cout << a*b_100/100 << endl;

    return 0;
}

Measured memory_bytes: 3636
n = int(input())
l1 = [input() for i in range(n)]

m = int(input())
c = 0
l = ["Opened","Closed"]
for i in range(m):
  s = input()
  if s in l1:
    print(l[c%2]+" by "+ s)
    c += 1
  else:
    print("Unknown "+ s)

Measured memory_bytes: 7732
while True:
    h, w = [int(i) for i in input().split()]
    if (h == 0) & (w == 0):
        break
    for i in range(0, h):
        s = ''
        for j in range(0, w):
            if (i % 2) == (j % 2):
                s += '#'
            else:
                s += '.'
        print(s)
    print('')

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

int main(){
  int n;
  cin >> n;
  P a[n];
  int ans = 0;
  rep(i,n) cin >> a[i].first >> a[i].second;
  sort(a,a+n);
  vector<int> l(n), r(n);
  l[0] = a[0].second, r[n-1] = a[n-1].second;
  for(int i = 1; i < n; i++) {
    l[i] = min(l[i-1],a[i].second);
    r[n-i-1] = min(r[n-i],a[n-i-1].second);
  }
  rep(i,n) {
    int d = a[i].second - a[i].first + 1;
    if(i == 0) ans = max(ans,d+r[1]-a[n-1].first+1);
    else if(i == n-1) ans = max(ans,d+l[n-2]-a[n-2].first+1);
    else ans = max(ans,d+max(0,min(r[i+1],l[i-1])-a[n-1].first+1));
  }
  rep(i,n-1) ans = max(ans,max(l[i]-a[i].first+1,0)+max(r[i+1]-a[n-1].first+1,0));
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 1792
#include<cstdio>
#define RI register int
#define CI const int&
using namespace std;
const int N=200005;
int n,a[N],stk[N],c[N],top,ans;
inline bool check(CI lim)
{
	if (lim==1)
	{
		for (RI i=2;i<=n;++i) if (a[i]<=a[i-1]) return 0; return 1; 
	}
	top=0; for (RI i=2;i<=n;++i) if (a[i]<=a[i-1])
	{
		int x=a[i]; while (top&&stk[top]>x) --top;
		while (top&&stk[top]==x&&c[top]==lim) --top,--x;
		if (!x) return 0; if (stk[top]==x) ++c[top]; else stk[++top]=x,c[top]=2;
	}
	return 1;
}
int main()
{
	RI i; for (scanf("%d",&n),i=1;i<=n;++i) scanf("%d",&a[i]);
	int l=1,r=n,mid; while (l<=r)
	if (check(mid=l+r>>1)) ans=mid,r=mid-1; else l=mid+1;
	return printf("%d",ans),0;
}

Measured memory_bytes: 2500
#include <iostream>
#include <string>
using namespace std;
typedef long long ll;

#if 0
ll stoll(string S)
{
    ll tmp = 0LL;
    for (int i = 0; i < S.size(); ++i) {
        tmp *= 10LL;
        tmp += S[i];
    }
    return tmp;
}
#endif

int main()
{
    string S;
    cin >> S;
    ll Res = 0LL;

    for (int i = 0; i < 1<<(S.size()-1); ++i) {
        int j = 0;
        for (int k = 0; k < S.size()-1; ++k) {
            if ((i>>k) & 1) {
                Res += stoll(S.substr(j, k+1-j));
                j = k+1;
            }
        }
        Res += stoll(S.substr(j, S.size()-j));
    }

    cout << Res << endl;

    return 0;
}

Measured memory_bytes: 256
import collections

N = int(input())

dp = []
for x in range(1,101):
    for y in range(1,101):
        for z in range(1,101):
            a = x**2 + y**2 + z**2 + x*y + y*z + z*x
            if a <= N:
                dp.append(a)

dpc = collections.Counter(dp)

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


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

  bool flag = true;
  int count = 0;
  while (flag) {
    flag = false;
    for (int i = n-1; i > 0; i--) {
      if (a[i] < a[i-1]) {
        swap(a[i], a[i-1]);
        flag = true;
        count++;
      }
    }
  }

  for (int i = 0; i < n; i++) {
    if (i<n-1) cout << a[i] << " ";
    else cout << a[i] << endl;
  }

  cout << count << endl;
}


Measured memory_bytes: 3120
#include <iostream>
#include <cstdio>
#include <vector>
#include <stack>
#include <math.h>

using namespace std;

typedef long long int ll;
typedef long double ld;

#define rep(i,n) for(int i = 0; i < (n); ++i)
#define vsort(a) sort(a.begin(), a.end())
#define rev(a) reverse(a.begin(), a.end())


// a,bの最小公倍数
ll LCM(ll a, ll b){ll lcm = a * b; ll r = a % b;while(r != 0){a = b; b = r; r = a % b;}return lcm /= b;}
// a,bの最大公約数
ll GCD(ll a, ll b){ll r = a % b;while(r != 0){a = b; b = r; r = a % b;}return b;}


const int MOD = 1000000007;
const int INF = INT_MAX;



int main(){

    int n, r;
    cin >> n >> r;

    int ans;
    if (10 <= n) {
        ans = r;
    }
    else {
        ans = r + 100 * (10 - n);
    }

    cout << ans << endl;

    
    
}





//              g++ -std=c++1z


Measured memory_bytes: 888
#pragma warning(disable:4996)
#include <iostream>
#include <algorithm>
#include <cstring>
#include <vector>
#include <string>
#include <cstdio>
#include <cmath>
#include <queue>
#include <stack>
#include <set>
#include <map>
using namespace std;

#define INF 0x3fffffff
typedef long long ll;

#define rep(i,n) for(int i=0;i<n;i++)
#define pb push_back
#define mp make_pair
#define pb push_back

const int maxn = 5e5 + 5;
const double PI = acos(-1.0);
const ll mod = 1e9 + 7;
ll po(ll a, ll b) { ll res = 1; a %= mod; for (; b; b >>= 1) { if (b & 1)res = res*a%mod; a = a*a%mod; }return res; }
ll gcd(ll a, ll b) { if (a == 0) { return b; } else { return gcd(b%a, a); } }

ll n, x;
ll val[maxn], pre[maxn];

void solve()
{
	scanf("%lld%lld", &n, &x);
	ll res = 0;
	for (int i = 0; i < n; i++)
	{
		scanf("%lld", &val[i]);
		res += val[i];
		pre[i] = val[i];
	}
	for (int k = 0; k < n; k++)
	{
		ll sum = 0;
		for (int i = 0; i < n; i++)
		{
			ll t = val[(i - k + n) % n];
			pre[i] = min(pre[i], t);
			sum += pre[i];
		}
		res = min(res, sum + k*x);
	}
	printf("%lld", res);
}

int main()
{
	solve();
	return 0;
}


Measured memory_bytes: 256
package main

import (
	"fmt"
)

func main() {
	var n, x int
	for {
		fmt.Scan(&n)
		fmt.Scan(&x)
		if n == 0 && x == 0 {
			break
		}
		calc(n, x)
	}
}

func calc(n, x int) {
	l := makeNList(n)
	fmt.Println(check(l, n, x))

}

func makeNList(n int) []int {
	var l []int
	for i := 1; i <= n; i++ {
		l = append(l, i)
	}
	return l
}

func check(l []int, n, x int) int {
	cnt := 0
	for k := 2; k < n; k++ {
		for j := 1; j < k; j++ {
			for i := 0; i < j; i++ {
				if l[i]+l[j]+l[k] == x {
					cnt++
				}
			}
		}
	}
	return cnt
}



Measured memory_bytes: 1160
#include <iostream>
#include <string>
#include <vector>

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

using std::cin;
using std::cout;
using std::endl;
using std::string;
using std::vector;

int main()
{
  long long A;
  string B;
  cin >> A >> B;
  B.erase(1, 1);
  int C = std::stoi(B);
  A *= C;
  A /= 100;

  cout << A << endl;

  return 0;
}


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

const int MAX = 100001;
const int MOD = 1000000007;

typedef long long ll;
typedef pair< int, int > pii;
typedef pair< ll, ll > pll;
typedef pair< ll, int > pli;
typedef pair< int, ll > pil;

int ceil(int x, int y){
  return (x % y == 0) ? x / y : x / y + 1;
}

int gcd(int x, int y){
  return y ? gcd(y, x % y) : x;
}

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

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

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

  int m = n * (n + 1) / 2;

  ll b[m];
  int sp = 0;
  for(int i = 0; i < n; i++){
    ll sum = 0;
    for(int j = i; j < n; j++){
      sum += (ll)a[j];
      b[sp++] = sum;
    }
  }

  ll ans = 0;
  for(int i = 50; i >= 0; i--){
    ll mask = 1l << i;
    int count = 0;
    for(int j = 0; j < m; j++){
      if((b[j] & (ans + mask)) == (ans + mask)) ++count;
    }
    if(count >= k) ans += mask;
  }

  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 4224
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cfloat>
#include <climits>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <fstream>
#include <functional>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <memory>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>

// c++11
#include <array>
#include <tuple>
#include <unordered_map>
#include <unordered_set>

#define mp make_pair
#define mt make_tuple
#define rep(i, n) for (int i = 0; i < (n); i++)

using namespace std;

using ll = long long;
using ull = unsigned long long;
using pii = pair<int, int>;

const int INF = 1 << 29;
const ll LL_INF = 1LL << 60;
const double EPS = 1e-9;
const ll MOD = 1000000007;

const int dx[] = {1, 0, -1, 0}, dy[] = {0, -1, 0, 1};
int H, W;
char board[55][55];
int main()
{
    cin >> H >> W;
    for (int i = 0; i < H; i++)
    {
        for (int j = 0; j < W; j++)
        {
            cin >> board[i + 1][j + 1];
        }
    }
    bool ok = true;
    for (int i = 1; i <= H; i++)
    {
        for (int j = 1; j <= W; j++)
        {
            if (board[i][j] == '#')
            {
                bool flag = false;
                for (int k = 0; k < 4; k++)
                {
                    int y = i + dy[k];
                    int x = j + dx[k];
                    if (board[y][x] == '#')
                    {
                        flag = true;
                        break;
                    }
                }
                if (!flag){
                    ok = false;
                }
            }
        }
    }
    cout << (ok ?  "Yes" : "No") << endl;
    return 0;
}


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

template <typename T> class SlideMin {
public:
  vector<int> deq;
  vector<T> res;
  int n, k;
  SlideMin(vector<T> Array, int sz) {
    n = (int) Array.size(), k = sz;
    deq.resize(n), res.resize(n);
    int s = 0, t = 0;
    for (int i = 0; i < n; i++) {
      while (s < t && Array.at(deq.at(t - 1)) <= Array.at(i)) {
        t--;
      }
      deq.at(t++) = i;
      res.at(i) = Array.at(deq.at(s));
      if (deq.at(s) == i - k + 1) {
        s++;
      }
    }
  }
};

int main() {
  int N, M, K;
  cin >> N >> M >> K;
  vector<long> A(N);
  for (int i = 0; i < N; i++) cin >> A.at(i);
  SlideMin<long> SM(A, M);
  for (int i = 0; i + 1 < K; i++) {
    vector<long> tmp(N, -1e18);
    for (int j = 1; j < N; j++) {
      tmp.at(j) = max(tmp.at(j), SM.res.at(j - 1) + (i + 2) * A.at(j));
    }
    SM = SlideMin<long>(tmp, M);
  }
  cout << *max_element(SM.res.begin(), SM.res.end()) << "\n";
}

Measured memory_bytes: 4976
n = gets.to_i
hs = gets.strip.split.map(&:to_i)

inf = 10 << 60

dp = Array.new(n, inf)

dp[0] = 0
dp[1] = (hs[1] - hs[0]).abs

(2...n).each do |i|
    dp[i] = [dp[i], dp[i - 1] + (hs[i] - hs[i - 1]).abs].min
    dp[i] = [dp[i], dp[i - 2] + (hs[i] - hs[i - 2]).abs].min
end

puts dp[n - 1]


Measured memory_bytes: 13828
using System;

namespace atcoderA
{
    class MainClass
    {
        public static void Main(string[] args)
        {
            int[] line = Array.ConvertAll(Console.ReadLine().Split(' '), int.Parse);
            int N = line[0];
            int i = line[1];
            Console.WriteLine(N - i + 1);
        }
    }
}

Measured memory_bytes: 11092
#include <iostream>
#include <string>
#include <algorithm>

using namespace std;

#define ll long long;
#define REP(i, n) for(int i = 1; i <= (int)(n); i++)

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    int x;
    int sum = 0;
    int ans;
    
    cin >> x;

    REP(i, x) {
        sum += i;
        if(sum >= x && (sum - x) <= i) {
            ans = i;
            break;
        }
    }
    cout << ans << endl;

}



Measured memory_bytes: 256
#include<stdio.h>
int gcd(int a,int b)
{   int temp;
    while(b!=0) {
        temp=b;
        b=a%b;
        a=temp;
    }
    return a;
}

int main()
{
    int k,i,j,l,sum=0;
    scanf("%d",&k);
    for(i=1; i<=k; i++) {
        for(j=1; j<=k; j++) {
            for(l=1; l<=k; l++) {

                sum=sum+gcd(gcd(i,j),l);

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


Measured memory_bytes: 1696
// #pragma GCC optimize "trapv" Uncomment when dealing with huge numbers
/*<----------PBDS---------->

#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

using namespace __gnu_pbds;
template <typename T>
using order_set = tree<T,null_type,less<T>,rb_tree_tag,tree_order_statistics_node_update>;

order_set<datatype>oset;
Kth smallest : *oset.find_by_order(k-1); // 0 based index
No of elements less than k : oset.order_of_key(k);
Erase X : oset.erase(x)
<----------PBDS---------->*/
#include<iostream>
#include<bits/stdc++.h>
#define int long long
#define mod 1000000007
#define pb(x) push_back(x)
#define gcd(a,b) __gcd(a,b)
#define all(v) v.begin(),v.end()
#define lcm(a,b) (a*b)/gcd(a,b)
#define bits(x) __builtin_popcountll(x)
#define fast ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
using namespace std;
int dp[3001][3001];
int32_t main()
{
    fast;
    string s,t;
    cin >> s >> t;
    int n = s.size();
    int m = t.size();
    for(int i = 0 ; i <= n ; i++ ){
    	for(int j = 0 ; j <= m ; j++ ){
    		if(i==0||j==0){
    			dp[i][j] = 0;
			}
			else{
				if(s[i-1]==t[j-1]){
					dp[i][j] = 1+dp[i-1][j-1];
				}
				else{
					dp[i][j] = max(dp[i][j-1],dp[i-1][j]);
				}
			}
		}
	}
	int i = n;
	int j = m;
	string res = "";
	while(i>0 && j>0){
		if(s[i-1]==t[j-1]){
			res+=s[i-1];
			i--;
			j--;
		}
		else if(dp[i-1][j]>dp[i][j-1]){
			i--;
		}
		else{
			j--;
		}
	}
	reverse(all(res));
	cout << res;
}





Measured memory_bytes: 70656
N, K, Q = map(int, input().split())
A = [int(input()) for _ in range(Q)]

lis = [K-Q for _ in range(N)]

for i in range(Q):
  lis[A[i]-1] += 1
  
for i in range(N):
  if lis[i] > 0:
    print("Yes")
  else:
    print("No")

Measured memory_bytes: 11780
#include<cstdio>
#include<cstring>
#include<algorithm>
#define MAXN 55
using namespace std;
bool cmp(char a[],char b[]){
	
	return strcmp(a,b)>0?0:1; 
	
}
int main(){
	int n;
	int str[55][30]={0};
	scanf("%d\n",&n);
	char tmp[55];
	for(int i=0;i<n;i++){
		int len=0;
		char ch;
		ch=getchar();
		while(ch!=char(10)){
			str[i][ch-'a'+1]++;
			ch=getchar();
		}
	}
	int len=0;
	for(int j=1;j<=26;j++){
		int mx=55;
		for(int i=0;i<n;i++){
			mx=min(mx,str[i][j]);
			if(mx==0){
				break;
			}
		}
		while(mx--){
			printf("%c",j+'a'-1);
		}
	}
	printf("\n");
	return 0;
} 

Measured memory_bytes: 128
#include <iostream>
#include <cstdio>
#include <string>
#include <algorithm>
#include <cstring>
#include <vector>
#include <queue>
#include <map>
#include <set>
#include <bitset>
#include <stack>
#include <cmath>
#include <time.h>
#include <unordered_set>
#include <unordered_map>
#define ll long long
#define LINF 0x3f3f3f3f3f3f3f3f
#define INF 0x3f3f3f3f
#define PI 3.14159265
#define RAND (rand()*rand())
#define MAX(x, y) ((x) > (y) ? (x):(y))
#define MIN(x, y) ((x) > (y) ? (y):(x))
#define ABS(x) ((x) > 0 ? (x) : -(x))
#define CEIL(x, y) (((x) + (y) - 1)/(y))
using namespace std;

const int MAXN = 1e5 + 5;
const ll MOD = 1e9 + 7;
int N, M, K, Q, T;
int s1, s2;
vector<int> graph[MAXN];
int dp[MAXN][2];

void dfs(int p, int u, int d, int opt) {
    dp[u][opt] = d;
    for (int i = 0; i < graph[u].size(); ++i) {
        int v = graph[u][i];
        if (v == p) continue;
        dfs(u, v, d + 1, opt);
    }
    return;
}

int main()
{
    int i, j, u, v;
    scanf("%d%d%d", &N, &s1, &s2);
    for (i = 1; i <= N - 1; ++i) {
        scanf("%d%d", &u, &v);
        graph[u].push_back(v);
        graph[v].push_back(u);
    }
    dfs(0, s1, 0, 0);
    dfs(0, s2, 0, 1);
    int maxi = 0;
    for (i = 1; i <= N; ++i) {
        if (dp[i][0] > dp[i][1]) continue;
        maxi = MAX(maxi, dp[i][1] - 1);
    }
    printf("%d", maxi);
    return 0;
}


Measured memory_bytes: 12928
#include<bits/stdc++.h>
using namespace std;
int main()
{
  int s=0;
  string str;
  cin>>str;
  int l=str.size();
  for(int i=0;i<l;i++)
    s=s+str[i]-48;
   if(s%9==0)
     cout<<"Yes";
  else
    cout<<"No";
}

Measured memory_bytes: 3720
from collections import defaultdict
S = input()
T = input()
d = defaultdict(set)
for s, t in zip(S, T):
    d[s].add(t)

for v in d.values():
    if len(v) != 1:
        print("No")
        exit()

chars = set()
for k, v in d.items():
    for x in v:
        if x in chars:
            print("No")
            exit()
        chars.add(x)
print("Yes")

Measured memory_bytes: 4144
parseInt(x) = parse(Int, x)

function main()
	n = readline() |> parseInt
	a = map(parseInt, split(readline()))
	d = Dict{Int,Int}()
	for i in 1:n
		if haskey(d,a[i])
			d[a[i]] += 1
		else
			d[a[i]] =1
		end
	end
	x = Int[]
	for i in keys(d)
		if d[i] >= 2
			push!(x,i)
		end
	end
	x = sort!(x,rev=true)
	if length(x) >=1
    	if d[x[1]] >=4
			print(x[1]*x[1])
		elseif length(x) >= 2
			print(x[1]*x[2])
    	end
	else
		print(0)
	end
end

main()

Measured memory_bytes: 191876
#include <bits/stdc++.h>
typedef long long ll;
using namespace std;
#define pb push_back
#define pf push_front
#define ff first
#define ss second
#define vll vector<ll>
#define pll pair<ll, ll>
#define vpll vector<pll>
#define endl "\n"
const ll maxn = 2*(1e5 + 5);

int main()
{
    ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
    ll i, j, k, t, n, m;
    double d;

    cin>>n;

    d = (double)22/7;

    printf("%0.7lf",2*d*n);


 
    return 0;
}

Measured memory_bytes: 3784
#define _CRT_SECURE_NO_WARNINGS
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cmath>
#include<map>
#include<vector>
#include<string>
#include<set>
#include<cstring>
#include<climits>
#include<queue>
using namespace std;

static string s1, s2;

int main()
{
	while (cin >> s1 >> s2)
	{
		sort(s1.begin(), s1.end());
		sort(s2.begin(), s2.end());
		reverse(s2.begin(), s2.end());
		int i = 0, j = 0;
		bool flag = false;
		while (i < s1.length() && j < s2.length())
		{
			if (s1[i] != s2[j])
			{
				flag = (s1[i] < s2[j]);
				break;
			}
			else
			{
				++i;
				++j;
			}
		}
		if (i == s1.length() && j < s2.length()) flag = true;
		else if (i < s1.length() && j == s2.length()) flag = false;
		printf(flag ? "Yes\n" : "No\n");
	}
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define ld long double
#define FOR(i,j,k,inc) for(int i=j ; i<k ; i+=inc)
#define rep(i,n) FOR(i,0,n,1)
#define rfor(i,k,j,dec) for(int i=k-1 ; i>=j ; i-=dec)
#define repr(i,n) rfor(i,n,0,1)

int main()
{	
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	#ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
	#endif

	vector<int>arr(5);
	for(int i=0 ; i<5 ; i++)
	{
		cin>>arr[i];
		if(arr[i]==0) {cout <<i+1; return 0;}
	}
	return 0;


}

Measured memory_bytes: 3648
import java.io.*;
class Main
{
    public static void main(String args[])throws IOException
    {
	BufferedReader input=new BufferedReader(new InputStreamReader(System.in));
	int n=Integer.parseInt(input.readLine());
	for(int i=0;i<n;i++)
	    {
		String str=input.readLine();
		
		int a[]=new int[8];
		int b[]=new int[8];
		for(int j=0;j<8;j++)
		    {
			a[j]=Integer.parseInt(str.charAt(j)+"");
			b[j]=Integer.parseInt(str.charAt(j)+"");
		    }
		for(int j=0;j<8;j++)
		    {
			for(int k=7;j<k;k--)
			    {
				if(a[k-1]>a[k])
				    {
					int tmp=a[k-1];
					a[k-1]=a[k];
					a[k]=tmp;
				    }
				if(b[k-1]<b[k])
				    {
					int tmp=b[k-1];
					b[k-1]=b[k];
					b[k]=tmp;
				    }
			    }

		    }
		
		long sumb=0,suma=0;
		for(int j=0;j<8;j++)
		    {
			sumb+=b[j]*((int)(Math.pow(10,7-j)));
			if(a[j]==0)continue;
			suma+=a[j]*((int)(Math.pow(10,7-j)));
		    }
		System.out.println(sumb-suma);
	    }
    }
}

Measured memory_bytes: 16888
from collections import Counter

n = int(input())

a = list(map(int, input().split()))

c = Counter(a)

can_use = [0, 0]
for i, x in c.items():
    if x >= 2:
        can_use.append(i)
    if x >= 4:
        can_use.append(i)

can_use.sort(reverse=True)

print(can_use[0] * can_use[1])


Measured memory_bytes: 18600
#include<stdio.h>

int calc(int x,int y)
{
	if(y<1)
		return x;
	else
		return calc(y,x%y);
}

int main()
{
	int a,b;

	while(scanf("%d",&a)!=EOF)
	{
		scanf("%d",&b);
		printf("%d\n",		calc(a,b));
	}
}

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

int main() {
    int n;
    cin>>n;
    int i,j;
    int a[100];
    for(i=0;i<100;i++) a[i]=0;
    for(i=1;i<=n;i++){
        int c=i;
        for(int j=2;j*j<=c;j++){
            while(c%j==0) {
                a[j]++;
                c=c/j;
            }
        }
        a[c]++;
    }
    vector<int> v;
    for(i=2;i<100;i++){
        if(a[i]>0) v.push_back(a[i]);
    }
    
    int l=v.size();
    ll ans=0;
    ll a2=0;
    ll a4=0;
    ll a14=0;
    ll a24=0;
    for(i=0;i<l;i++){
        if(v[i]>=74) ans++;
        if(v[i]>=2) a2++;
        if(v[i]>=4) a4++;
        if(v[i]>=14) a14++;
        if(v[i]>=24) a24++;
    }
    ans+=a24*(a2-1);
    ans+=a14*(a4-1);
    ans+=a4*(a4-1)*(a2-2)/2;
    cout<<ans<<endl;

}

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

int main() {
    int g[4][3][10],n;
    for(int i = 0;i < 4;i++)
        for(int k = 0; k < 3;k++)
            for(int j = 0; j < 10;j++)g[i][k][j] = 0;
    cin >> n;
    for(int i = 0;i < n;i++){
        int b,f,r,v;
        cin >> b >> f >> r >> v;
        g[b - 1][f - 1][r - 1] += v;
    }
    for(int f = 0;f < 4;f++){
        if(f > 0)cout << "####################" << endl;
        for(int b = 0;b < 3;b++){
            for(int r = 0;r < 10;r++){
                cout << " " << g[f][b][r];
            }
            cout << endl;
        }
    }
}
            
            


Measured memory_bytes: 3096
#include<iostream>
#include<string>
#include<algorithm>

using namespace std;

int main() {
	string s;
	cin >> s;
	sort(s.begin(), s.end());

	string t;
	cin >> t;
	sort(t.begin(), t.end());
	reverse(t.begin(), t.end());

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

	return 0;
}

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

public class Main{
    public static void main(String args[]){
        Scanner in = new Scanner(System.in);
        
        double x1 = in.nextDouble(), y1 = in.nextDouble(), x2 = in.nextDouble(), y2 = in.nextDouble();

        System.out.printf("%f\n",Math.sqrt(Math.pow(x2 - x1, 2) + Math.pow(y2 - y1, 2)));
    }
}


Measured memory_bytes: 28284
#include<iostream>
#include<vector>
#include<iomanip>
using namespace std;
double dp[3001][3001];
double helper(int numheads,int i,vector<double>&prob,int n){
	if(dp[i][numheads] > -1){
		return dp[i][numheads];
	}
	if(i >= n){
		if(numheads <= n/2){
			return 0;
		}
		else
		return 1;
	}
	else{
		dp[i][numheads] = prob[i]*helper(numheads+1,i+1,prob,n)+helper(numheads,i+1,prob,n)*(1-prob[i]);
		return dp[i][numheads];
	}
}
int main(){
	int n;cin>>n;
	vector<double>prob(n);
	for(int i=0;i<n;i++){
		cin>>prob[i];
	}
	double ans = 0;
	for(int i=0;i<3001;i++){
		for(int j=0;j<3001;j++){
			dp[i][j] = -1;
		}
	}
	cout<<setprecision(15);
	cout<<helper(0,0,prob,n);
}


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

template <typename InputIterator>
typename InputIterator::value_type summation(InputIterator first,
                                             InputIterator last) {
  return std::accumulate(first, last, typename InputIterator::value_type());
}
template <typename T>
std::istream &operator>>(std::istream &stream, std::vector<T> &v);
template <typename T1, typename T2>
std::istream &operator>>(std::istream &stream, std::pair<T1, T2> &p);
template <typename T>
std::istream &operator>>(std::istream &stream, std::vector<T> &v) {
  for (auto &i : v) {
    stream >> i;
  }
  return stream;
}
template <typename T1, typename T2>
std::istream &operator>>(std::istream &stream, std::pair<T1, T2> &p) {
  stream >> p.first >> p.second;
  return stream;
}

int main() {
  int64_t n;
  std::cin >> n;
  std::vector<std::vector<bool>> a(n, std::vector<bool>(62, false));

  for (int64_t i = 0; i < n; i++) {
    int64_t ax;
    std::cin >> ax;

    int64_t j = 0;
    while (ax != 0) {
      if (ax % 2 == 1) {
        a[i][j] = true;
      }
      ax /= 2;
      j++;
    }
  }

  std::vector<std::vector<int64_t>> c(n, std::vector<int64_t>(62, 0));

  for (int64_t i = 0; i < 62; i++) {
    if (a[0][i]) {
      c[0][i] = 1;
    }
  }

  for (int64_t j = 1; j < n; j++) {
    for (int64_t i = 0; i < 62; i++) {
      if (a[j][i]) {
        c[j][i] = c[j - 1][i] + 1;
      } else {
        c[j][i] = c[j - 1][i];
      }
    }
  }

  int64_t ans = 0;
  constexpr int64_t mod = 1000000007;
  for (int64_t j = 0; j < n - 1; j++) {
    for (int64_t i = 0; i < 62; i++) {
      int64_t m = c[n - 1][i] - c[j][i];
      if (a[j][i]) {
        m = n - j - 1 - m;
      }
      ans += (((static_cast<int64_t>(1) << i) % mod) * m) % mod;
      ans %= mod;
    }
  }

  std::cout << ans << std::endl;
  return 0;
}


Measured memory_bytes: 178432
n, k = map(int, input().split())

x = 0
for a in range(1, n + 1):
    if (2 * a) % k == 0:
        x += 1

y = 0
for a in range(1, n + 1):
    if a % k == 0:
        y += 1

print((x - y) ** 3 + y ** 3)


Measured memory_bytes: 2940
a,b = map(int,input().split())
c = [2019]*2
p = 0
flag = 0
if (b-a) >= 2019:
    for j in range(a,a+2020):
        if j%2019 == 0:
            flag = 1
            break
        for l in range(j+1,a+2020):
            if l%2019==0:
                flag = 1
                break
            c[1] = (j*l)%2019
            c[0] = (j*l)%2019 if c[0] > c[1] else c[0]
else:
    for m in range(a,b+1):
        if m%2019 == 0:
            flag = 1
            break
        for n in range(m+1,b+1):
            if n%2019==0:
                flag = 1
                break
            c[1] = (n*m)%2019
            c[0] = (n*m)%2019 if c[0] > c[1] else c[0]
if flag == 1:
    print(0)
else:
    print(c[0])

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

int main(){
	int p,n, y, a, b,a1=0,b1=0,c1=0;
	scanf("%d%d", &n, &y);
	p = y / 1000 - n;
	
	for (a = 0;  a <= n; a++) 
		for (b = 0;  b <= n; b++) {
			if (9 * a + 4 * b == p ) {
				a1 = a;
				b1 = b;
				
				
			if((y - 10000 * a1 - 5000 * b1)>=0)
               c1 = (y - 10000 * a1 - 5000 * b1) / 1000;
			else { a1 = 0; b1 = 0; }
			}
		}
	if (a1 == 0 && b1 == 0 && c1 == 0)printf("%d %d %d", -1, -1, -1);
	else printf("%d %d %d", a1,b1,c1);
	return 0;

}

Measured memory_bytes: 128
#include<iostream>
#include<string>
using namespace std;
int main(){
	int n, l, r, s=0, i;
	cin >> n;
	for(i=0;i<n;i++){
		cin >> l >> r;
		s+=(r-l+1);
	}
	cout << s << endl;
	return 0;
}


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


using namespace std;
const int inf = 1e+9;
int L = 8;
int spos = 0;


map<string, int> st;
struct P{
    int pos;
    string status;
    int step;
};
string str = "01234567";
void dp(){
    queue<P> que;
    que.push((P){spos, str, 0});
    st[str] = 0;

    while(!que.empty()){
        P p = que.front();que.pop();
        int pos = p.pos;
        string status = p.status;
        int step = p.step;

        if((pos+4)<L){//可以下移
            string newstatus = status;
            swap(newstatus[pos], newstatus[pos+4]);
            if(st.find(newstatus) == st.end()){
                que.push((P){pos+4, newstatus, step+1});
                st[newstatus] = step+1;
            }
        }

        if((pos-4)>=0){//可以上移
            string newstatus = status;
            swap(newstatus[pos], newstatus[pos-4]);
            if(st.find(newstatus) == st.end()){
                que.push((P){pos-4, newstatus, step+1});
                st[newstatus] = step+1;
            }
        }

        if((pos+1)%4){//可以右移
            string newstatus = status;
            swap(newstatus[pos], newstatus[pos+1]);
            if(st.find(newstatus) == st.end()){
                que.push((P){pos+1, newstatus, step+1});
                st[newstatus] = step+1;
            }
        }

        if(pos%4){//可以左移
            string newstatus = status;
            swap(newstatus[pos], newstatus[pos-1]);
            if(st.find(newstatus) == st.end()){
                que.push((P){pos-1, newstatus, step+1});
                st[newstatus] = step+1;
            }
        }
    }

}

int main(){
    int num;
    dp();
    while(~scanf("%d", &num)){
        str="";
        str.push_back(num+'0');
        if(num == 0) spos = 0;
        for(int i = 1;i < L;i++){
            scanf("%d", &num);
            str.push_back(num+'0');
            if(num == 0) spos = i;
        }
        if(st.find(str) == st.end()) printf("-1\n");
        else printf("%d\n",st[str]);
    }
    return 0;

}

/*
0 1 2 3 4 5 6 7
1 0 2 3 4 5 6 7
7 6 5 4 3 2 1 0
1 5 2 0 3 7 4 6
 */


Measured memory_bytes: 5568
#include<bits/stdc++.h>
using namespace std;
long long k,a,b;
int main()
{
	scanf("%lld%lld%lld",&k,&a,&b);
	if (k<=a||b<=a+2) cout << k+1 << endl;
	else cout << a+(b-a)*((k-a+1)/2)+((k-a+1)&1) << endl;
}

Measured memory_bytes: 256
a, b, c, k = gets.split.map(&:to_i)

ans = 0
if k > a
  ans += a
  k -= a
else
  ans += k
  k = 0
end

if k > b
  k -= b
else
  k = 0
end

if k > c
  ans -= c
  k -= c
else
  ans -= k
  k = 0
end

p ans

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

using namespace std;

typedef long long ll;
typedef long double ld;

const int N = 2e5 + 10;
ll tree[4 * N];

void update(int node, int l, int r, int idx, ll val)
{
  if(l > r || l > idx || r < idx)
    return;
  if(l == r)
  {
    tree[node] = val;
    return;
  }
  int mid = (l + r) >> 1;
  update(node << 1, l, mid, idx, val);
  update((node << 1) + 1, mid + 1, r, idx, val);
  tree[node] = max(tree[(node << 1)], tree[(node << 1) + 1]);
}

ll query(int node, int l, int r, int st, int en)
{
    if(l > en || r < st || l > r || st > en)
      return 0;
    if(st <= l && r <= en)
      return tree[node];
    int mid = (l + r) >> 1;
    return max(query((node << 1), l, mid, st, en), query((node << 1) + 1, mid + 1, r, st, en));
}

int v[N];
int h[N];

int main()
{
    int n;
    cin >> n;
    for(int i = 0; i < n; i++)
      cin >> v[i];
    for(int i = 0; i < n; i++)
      cin >> h[i];
    for(int i = 0; i < n; i++)
    {
      ll Max = query(1, 1, n, 1, v[i] - 1);
      update(1, 1, n, v[i], Max + h[i]);
    }
    cout << query(1, 1, n, 1, n);
}


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

using namespace std;

typedef long long ll;
const ll inf = 0x3f3f3f3f;
#define case(i) "Case #" << i << ": "
 
template <typename S, typename T>
ostream& operator<<(ostream& out, pair<S, T> const& p) {
    out << '(' << p.first << ", " << p.second << ')';
    return out;
}
template <typename T>
ostream& operator<<(ostream& out, vector<T> const& v) {
    ll l = v.size();
    for (ll i = 0; i < l - 1; i++) out << v[i] << ' ';
    if (l > 0) out << v[l - 1];
    return out;
}

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

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

    ll lcm = -1;

    vector<ll> v;

    for(int i = 0; i < n; ++i) {
        ll x; 
        cin >> x;
        x /= 2;

        v.push_back(x);
        
        if(lcm == -1) lcm = x;

        lcm = (x * lcm) / __gcd(x, lcm);
    }

    ll q = m / lcm;
    ll ans = (q + 1) / 2;

    for(ll x: v) {
        ll temp = lcm / x;
        if(temp % 2 == 0) ans = 0;
    }
    cout << ans << endl;
        
}


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

long long N, M, x[1000010], p[1000010], a, last, ans[100010], P[100010];
long long K;

int main(){
//	freopen("test.in", "r",stdin);
//	freopen("qwq1.out", "w", stdout);
	scanf("%lld", &N);
	for(int i=1; i<=N; i++)	scanf("%lld", &x[i]);
	for(int i=N; i; i--)	x[i]-=x[i-1], p[i]=i;
	scanf("%lld%lld", &M, &K);
	for(int i=1; i<=M; i++){
		scanf("%lld", &a);
		swap(p[a], p[a+1]);
	};
	for(int i=1; i<=N; i++)	ans[i]=i, P[i]=p[i];
	while(K){
		if(K&1)	
			for(int i=1; i<=N; i++)
				ans[i]=p[ans[i]];
		for(int i=1; i<=N; i++)
			P[i]=p[P[i]];
		for(int i=1; i<=N; i++)
			p[i]=P[i]; 
		K>>=1; 
	}
	for(int i=1; i<=N; i++){
		last+=x[ans[i]];
		printf("%lld\n", last);
	}
//	for(int i=1; i<=N; i++){
//		int now=p[i], cnt=1;
//		while(now!=i)	cnt++, now=p[now];
//		now=p[i];
//		if(K%cnt>=1)	for(int j=2; j<=K%cnt; j++)	now=p[now];
//		else			now=i;
//		now=x[now];
//		printf("%lld\n", now+last);
//		last+=now;
//	}
	return 0;
}

Measured memory_bytes: 7424