akhauriyash/Code-Regression huggingface dataset:
A,B = map(int,input().split())
#greedy O(B-A)*len(B)(=5)
kaibun = 0 # num of kaibun
for i in range(A,B+1,1):
  s = str(i)
  #print(s)
  for i in range(len(s)):
    if s[i] != s[len(s)-1-i]:
      break
    if i == len(s)-1:
      kaibun += 1
print(kaibun)
    

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

struct StCity
{
  StCity() : m_nPref(0), m_nYear(0) { }

  int m_nPref;
  int m_nYear;
};

void fnInput(int& rnPrefSiz, vector<StCity>& rvoCity)
{
  int nCitySiz;
  cin >> rnPrefSiz >> nCitySiz;
  rvoCity.resize(nCitySiz);

  for (StCity& roCity : rvoCity)
  {
    cin >> roCity.m_nPref >> roCity.m_nYear;
    --roCity.m_nPref;
  }
}

void fnIdNum(int nPrefSiz, const vector<StCity>& cnrvoCity)
{
  vector<vector<int>> vvnCity(nPrefSiz);
                                           // 
  for (int i = 0; i < cnrvoCity.size(); ++i)
    vvnCity[ cnrvoCity[i].m_nPref ].push_back( cnrvoCity[i].m_nYear );

  for (int i = 0; i < vvnCity.size(); ++i)
  {
    sort( begin(vvnCity[i]), end(vvnCity[i]) );
    vvnCity[i].erase( unique( begin(vvnCity[i]), end(vvnCity[i]) ), end(vvnCity[i]) );
  }

  for (int i = 0; i < cnrvoCity.size(); ++i)
  {
    int nPref = cnrvoCity[i].m_nPref;
    cout << setfill('0') << setw(6) << nPref + 1;

    int nIdNum = lower_bound( begin( vvnCity[ nPref ] ), end( vvnCity[ nPref ] ), 
                              cnrvoCity[i].m_nYear ) - begin( vvnCity[ nPref ] );   
    cout << setfill('0') << setw(6) << nIdNum + 1 << endl;
  }
}
  
int main()
{
  int nPrefSiz;
  vector<StCity> voCity;
  
  fnInput(nPrefSiz, voCity);
  fnIdNum(nPrefSiz, voCity);

  return 0;
}

Measured memory_bytes: 9532
#include<bits/stdc++.h>
using namespace std;
#define ALL(x) x.begin(),x.end()
#define rep(i,n) for(int i=0;i<n;i++)
#define debug(v) cout<<#v<<":";for(auto x:v){cout<<x<<' ';}cout<<endl; 
#define INF 1000000000
#define mod 1000000007
typedef long long ll;
const ll LINF = 1001002003004005006ll;
int dx[]={1,0,-1,0};
int dy[]={0,1,0,-1};
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }

signed main(){
    cin.tie(0);
    ios::sync_with_stdio(0);
    
    ll n;cin>>n;
    vector<ll> d(n);
    rep(i,n) cin>>d[i];

    ll ans=0;
    rep(i,n){
        for(int j=i+1;j<n;j++){
            ans+=d[i]*d[j];
        }
    }
    cout<<ans<<endl;
    return 0;
}


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

struct Point
{
    double x, y;
    Point() : x(0), y(0)
    {
        return;
    }
    Point(double x, double y) : x(x), y(y)
    {
        return;
    }
    Point operator+(const Point &a) const
    {
        return Point(x + a.x, y + a.y);
    }

    Point operator-(const Point &a) const
    {
        return Point(x - a.x, y - a.y);
    }

    Point operator*(const double &a) const
    {
        return Point(x * a, y * a);
    }

    Point operator/(const double &a) const
    {
        return Point(x / a, y / a);
    }

    bool operator<(const Point &a) const
    {
        return x == a.x ? y < a.y : x < a.x;
    }
};

double cross(const Point &a, const Point &b)
{
    return a.x * b.y - a.y * b.x;
}

vector<Point> getConvex(vector<Point> ps)
{
    const int N = ps.size();
    sort(ps.begin(), ps.end());
    int k = 0;
    vector<Point> convex(N * 2);

    for (int i = 0; i < N; i++)
    {
        while (2 <= k && cross(convex[k - 1] - convex[k - 2], ps[i] - convex[k - 1]) <= 0)
        {
            k--;
        }

        convex[k++] = ps[i];
    }

    for (int i = N - 2, t = k; 0 <= i; i--)
    {
        while (t < k && cross(convex[k - 1] - convex[k - 2], ps[i] - convex[k - 1]) <= 0)
        {
            k--;
        }

        convex[k++] = ps[i];
    }
    convex.resize(k - 1);
    return convex;
}

void solve()
{
    int N;
    cin >> N;
    vector<Point> ps(N);
    rep(i, N) {
        cin >> ps[i].x >> ps[i].y;
    }
    auto A = getConvex(ps);
    int64_t ans = 0;
    rep(i, A.size()) for(int j = i + 1; j < A.size(); ++j) {
        ans = max(ans, (int64_t)abs(A[i].x - A[j].x) + (int64_t)abs(A[i].y - A[j].y));
    }
    cout << ans << '\n';
}

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


Measured memory_bytes: 15940
#include <bits/stdc++.h>
#define BIT(n) (1LL << (n))
#define REP(i, n) for (int i = 0; i < n; i++)
#define REPB(i, n) for (int i = 0; i < BIT(n); i++)
#define REPS(i, x) for (int i = 1; i <= (int)(x); i++)
#define REPR(i, n) for (int i = n; i >= 0; i--)
#define FOR(i, m, n) for (int i = m; i < n; i++)
#define FORA(i, n) for (auto &&i : n)
#define FORS(i, m, n) for (int i = m; i <= n; i++)
#define DEBUG(x) cerr << #x << ": " << x << "\n"
#define PRINTALL(V)                                                            \
  for (auto v : (V)) {                                                         \
    cout << v << " ";                                                          \
  }                                                                            \
  cout << "\n";
#define ALL(v) v.begin(), v.end()
#define fst first
#define snd second
#define mp make_pair
#define pb push_back
#define epb emplace_back
#define int long long
using namespace std;
template < class T > bool chmax(T &a, const T &b) {
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}
template < class T > bool chmin(T &a, const T &b) {
  if (a > b) {
    a = b;
    return 1;
  }
  return 0;
}
template < class T > using vec = std::vector< T >;
template < class T > void print(const T &x) { cout << x << "\n"; }
const int MOD = 1000000007, INF = 1061109567;
const double EPS = 1e-10, PI = acos(-1.0);
const int dx[4] = {1, 0, -1, 0}, dy[4] = {0, 1, 0, -1};
signed main() {
  cin.tie(0), ios::sync_with_stdio(false);
  cout << fixed << setprecision(10);
  string S;
  cin >> S;
  sort(ALL(S));
  if (S == "abc") {
    print("Yes");
  } else {
    print("No");
  }
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define ALL(v) std::begin(v),std::end(v)
using lint=long long;
using lubl=long double;
int main(){
    std::cin.tie(nullptr);std::ios_base::sync_with_stdio(false);
    std::cout.setf(std::ios_base::fixed);std::cout.precision(15);
    lint n;std::cin>>n;
    if(n==2){
        std::cout<<1<<'\n';
        return 0;
    }
    auto ok=[&](lint k){
        lint x=n;
        while(true){
            if(x%k)return x%k==1;
            else x/=k;
        }
        throw;
    };
    lint ans=0;
    ans+=ok(n);
    for(lint k=2;k*k<=n;k++){
        if(n%k)continue;
        ans+=ok(k);
        if(k*k!=n)ans+=ok(n/k);
    }
    ans++;
    for(lint k=2;k*k<=n-1;k++){
        if((n-1)%k)continue;
        ans++;
        if(k*k!=n-1)ans++;
    }
    std::cout<<ans<<'\n';
}



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

using namespace std;

const int OO = 1e9;
const double EPS = 1e-9;

#define ndl cout << '\n'
#define sz(v) int(v.size())
#define pb push_back
#define mp make_pair
#define fs first
#define sc second
#define present(a, x) (a.find(x) != a.end())
#define db(x) cout << "> " << #x << " = " \
	<< (x) << '\n'
#define db2(x, y) cout << "> " << #x << " = " \
	<< (x) << ", " << #y << " = " << (y) << '\n'
#define db3(x, y, z) cout << "> " << #x << \
	" = " << (x) << ", " << #y << " = " << \
	(y) << ", " << #z << " = " << (z) << '\n'

typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<pii> vii;
typedef vector<vector<int>> vvi;
typedef map<int, int> mii;
typedef set<int> si;

const int MX = 1e5 + 5;
int n, d[MX];

int main() {
	ios::sync_with_stdio(false);
	cout.precision(10);
	cin >> n;
	for (int i = 0; i < n; ++i) {
		cin >> d[i];
	}
	sort(d, d + n);
	cout << d[n / 2] - d[n / 2 - 1] << '\n';
	return 0;
}


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

int main() {
	int n, l;
	cin >> n >> l;
	vector<string>s(n);

	 rep(i, n)cin >> s.at(i);
	 sort(s.begin(), s.end());
	 rep(i, n) {
	 cout << s.at(i);
	}
	 cout << endl;
}

Measured memory_bytes: 256
#include<iostream> 
using namespace std;
int main(){
	int a,b,c;
	cin>>a>>b>>c;
	if(a==c && b!=a && b!=c)cout<<"Yes";
	else if(a==b && c!=a && c!=b)cout<<"Yes";
	else if(c==b && a!=c && a!=b)cout<<"Yes";
	else cout<<"No";
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ll long long
#define MODV 1000000007
#define INF INT_MAX // 2147483647
#define INFLL LLONG_MAX // 9223372036854775807
#define rep(i, n) for(ll i=0, i##_len=(ll)(n); i<i##_len; i++)
#define repf(i, n) for(ll i=1, i##_len=(ll)(n+1); i<i##_len; i++)
#define per(i, n) for(ll i=((ll)(n))-1; i>=0; i--)
#define perf(i, n) for(ll i=((ll)(n)); i>0; i--)
#define all(v) v.begin(), v.end()
#define endl "\n"
#define vi vector<ll>
#define vvi vector<vector<ll>>
#define Yes() cout << "Yes" << endl
#define YES() cout << "YES" << endl
#define No() cout << "No" << endl
#define NO() cout << "NO" << endl
template<class T>bool chmax(T &a, const T &b){ if(a<b){ a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b){ if(b<a){ a=b; return 1; } return 0; }
using namespace std;

int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout << fixed << setprecision(10);
    string s; cin >> s;
    bool heisei = false;
    ll y = (s[0]-'0')*1000 + (s[1]-'0')*100 + (s[2]-'0')*10 + (s[3]-'0');
    ll m = (s[5]-'0')*10 + (s[6]-'0');
    ll d = (s[8]-'0')*10 + (s[9]-'0');
    if(y < 2019) heisei = true;
    else if(y == 2019 && m <= 4 && d <= 30) heisei = true;
    cout << ((heisei) ? "Heisei" : "TBD") << endl;  
}

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

int main() {
 int a=0;
  string s;
  cin >> s;
  for(int i=0;i<s.size();i++){
    if(s.at(i)=='1'){
      a++;
    }
  }
cout << a << endl;
}

Measured memory_bytes: 256
c = str(input())

if c == 'a':
        print('vowel')

elif c == 'i':
        print('vowel')


elif c == 'u':
        print('vowel')


elif c == 'e':
        print('vowel')


elif c == 'o':
        print('vowel')

else:
    print('consonant')

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

#[allow(dead_code)]
fn read<T: FromStr>() -> T {
    let stdin = stdin();
    let stdin = stdin.lock();
    let token: String = stdin
        .bytes()
        .map(|c| c.expect("failed to read char") as char)
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect();
    token.parse().ok().expect("failed to parse token")
}

fn calc(l: usize, r: usize, h: usize) -> usize {
    (r - l + 1) * h
}
fn main() {
    let h = read::<usize>();
    let w = read::<usize>();
    let mut field = vec![vec![]; h];
    for y in 0..h {
        field[y] = read::<String>().chars().collect::<Vec<char>>();
    }
    let mut ans = std::cmp::max(h, w);
    let mut heights = vec![vec![1; w]; h];
    for y in 0..h - 1 {
        for x in (0..w - 1).rev() {
            if (field[y][x] == field[y][x + 1]) == (field[y + 1][x] == field[y + 1][x + 1]) {
                heights[y][x] += heights[y][x + 1];
            }
        }
    }
    for x in 0..w - 1 {
        let mut stack = vec![(0, 0)];
        for y in 0..h {
            let mut py = y;
            let lh = heights[y][x];
            while stack.last().unwrap().1 > lh {
                py = stack.last().unwrap().0;
                let ph = stack.last().unwrap().1;
                ans = std::cmp::max(ans, calc(py, y, ph));
                stack.pop();
            }
            stack.push((py, lh));
        }
    }
    println!("{}", ans);
}


Measured memory_bytes: 61692
#include<iostream>
#include<map>
#include<algorithm>
using namespace std;
const int N=52;
pair<int,int> ar[N];
map<pair<int,int>,int> lis;
int main(){
	int n,i,j,k,l=0;
	cin>>n;
	for(i=1;i<=n;i++){
		cin>>ar[i].first>>ar[i].second;
	}
	sort(ar+1,ar+1+n);
	for(i=1;i<=n;i++){
		for(j=1;j<=n;j++){
			if(i==j){
				continue;
			}
			lis[{ar[i].first-ar[j].first,ar[i].second-ar[j].second}]++;
			l=max(l,lis[{ar[i].first-ar[j].first,ar[i].second-ar[j].second}]);
		}
	}
	cout<<n-l;
}

Measured memory_bytes: 384
#include<bits/stdc++.h>
#define lli long long int
#define pb push_back
#define rep(i,s,n) for(lli i=s;i<n;i++)
#define irep(i,n,s) for(lli i=n-1;i>=s;i--)
#define mp make_pair
#define mod 1000000007
using namespace std;

int main()
{
#ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
#endif
    ios_base::sync_with_stdio;
    cin.tie(NULL);
    int i, j, k, m, n, t;
    cin >> n >> k;
    int a[n];
    rep(i, 0, n)
    {
        cin >> a[i];
    }
    int dp[n + 1];
    dp[0] = 0;

    rep(i, 1, n)
    {

        dp[i] = INT_MAX;

        for (j = i - 1; j >= i - k && j >= 0; j--)
        {

            dp[i] = min(dp[j] + abs(a[i] - a[j]), dp[i]);
        }

    }
    cout << dp[n - 1] << "\n";

}




Measured memory_bytes: 4400
import java.util.*;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int k = sc.nextInt();
        int x = sc.nextInt();
        for(int i = x - k + 1; i <= x + k - 1; i++) {
            System.out.print(i);
            if(i < x + k - 1) {
                System.out.print(" ");
            }else {
                System.out.println("");
            }
        }
    }
}

Measured memory_bytes: 23764
#include <stdio.h>

void swap(int *a, int *b);

int main(void)
{
    int i, j, n, min;
    int count = 0;
    int data[100];

    scanf("%d", &n);

    for (i = 0; i < n; i++) {
        scanf("%d", &data[i]);
    }

    for (i = 0; i < n - 1; i++) {
        min = i;
        for (j = i; j < n; j++) {
            if (data[j] < data[min]) {
                min = j;
            }
        }
        swap(&data[i], &data[min]);
        if (i != min) count++;
    }

    for (i = 0; i < n; i++) {
        printf("%d", data[i]);
        if (i < n - 1) {
            printf(" ");
        }
    }
    printf("\n");
    printf("%d\n", count);

    return 0;
}

void swap(int *a, int *b)
{
    int tmp = *a;
    *a = *b;
    *b = tmp;
}



Measured memory_bytes: 2132
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

class Program
{
    static void Main()
    {
        Scanner cin = new Scanner();
        int N = cin.Int();
        int[] a = cin.ArrayInt(N);

        var dic = new Dictionary<int, int>();
        for(int i = 0; i < N; i++)
        {
            if (dic.ContainsKey(a[i])) dic[a[i]]++;
            else dic.Add(a[i], 1);
        }

        int ans = 0;
        foreach(var x in dic)
        {
            if (x.Value < x.Key) ans += x.Value;
            else if (x.Value == x.Key) continue;
            else ans += x.Value - x.Key;
        }

        Console.WriteLine(ans);
        Console.ReadLine();
    }

}

class Scanner //標準入力
{
    string[] s;
    int i;

    char[] cs = new char[] { ' ' };

    public Scanner()
    {
        s = new string[0];
        i = 0;
    }

    public string next()
    {
        if (i < s.Length) return s[i++];
        string st = Console.ReadLine();
        while (st == "") st = Console.ReadLine();
        s = st.Split(cs, StringSplitOptions.RemoveEmptyEntries);
        if (s.Length == 0) return next();
        i = 0;
        return s[i++];
    }

    public int Int()
    {
        return int.Parse(next());
    }
    public int[] ArrayInt(int N, int add = 0)
    {
        int[] Array = new int[N];
        for (int i = 0; i < N; i++)
        {
            Array[i] = Int() + add;
        }
        return Array;
    }

    public long Long()
    {
        return long.Parse(next());
    }

    public long[] ArrayLong(int N, long add = 0)
    {
        long[] Array = new long[N];
        for (int i = 0; i < N; i++)
        {
            Array[i] = Long() + add;
        }
        return Array;
    }

    public double Double()
    {
        return double.Parse(next());
    }


    public double[] ArrayDouble(int N, double add = 0)
    {
        double[] Array = new double[N];
        for (int i = 0; i < N; i++)
        {
            Array[i] = Double() + add;
        }
        return Array;
    }
}


Measured memory_bytes: 29276
#include <iostream>
#include <vector>
#include <string>
#include <cstring>
#include <queue>
#include <set>
#include <stack>
#include <map>
#include <unordered_map>
#include <cmath>
#include <utility> // pair make_pair
#include <algorithm>
#include <functional>
#include <iomanip>
#include <climits> // LLONG_MAX, LLONG_MIN, INT_MIN, INT_MAX
#include <assert.h>

#define m0(x) memset(x,0,sizeof(x))
#define m1(x) memset(x,63,sizeof(x))
#define fill(x,y) memset(x,y,sizeof(x))
#define ll long long
//#define int ll
#define INF INT_MAX/10

using namespace std;
using Pi = pair<int, int>;
using Graph = vector<vector<int> >;
using WeightGraph = vector<vector<Pi> >;

int Input[100100];

int main() {
  int P, Q, R; cin >> P >> Q >> R;
  cout << P + Q + R - max(P, max(Q, R)) << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef vector<int> vi;
typedef vector<vector<int>> vvi;
typedef pair<int,int> pii;
typedef long long ll;
const long long MOD=1000000007;
#define rep(i,n) for(int i=0;i<n;i++)
#define rep2(i,m,n) for(int i=m;i<n;i++)
#define ALL(v) v.begin(), v.end()
#define pb push_back





int main(){

    int a,b,c,d,e;
    cin>>a>>b>>c>>d>>e;

    if (a==0){
        cout<<1<<endl;
    }
    if (b==0){
        cout<<2<<endl;
    }
    if (c==0){
        cout<<3<<endl;
    }
    if (d==0){
        cout<<4<<endl;
    }
    if (e==0){
        cout<<5<<endl;
    }


















}

Measured memory_bytes: 3616
import java.util.Scanner;

class Main{
	public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        long N = sc.nextLong();
        long A = sc.nextLong();
        long B = sc.nextLong();

        
        
        if((B-A)%2==0) {
        	System.out.println((B-A)/2);
        } else {
        	System.out.println(Math.min(A-1,N-B)+1+(B-A-1)/2);
        } 
 

	}
}



Measured memory_bytes: 23764
def check(s):
    t = 'keyence'
    if s == t:
        return 'YES'
    for i in range(len(s)):
        for j in range(i + 1, len(s)):
            if t == s[:i] + s[j:]:
                return 'YES'
    return 'NO'


s = input()
print(check(s))


Measured memory_bytes: 9040
#include <iostream>
#include <vector>
using namespace std;
int main()
{
    int N, W; cin >> N >> W;
    vector<int> v(N), w(N);
    for (int i = 0; i < N; i++)
        cin >> v[i] >> w[i];
    vector<int> dp(W+1, 0);
    for (int i = 1; i <= W; i++)
        for (int j = 0; j < N; j++)
            if (w[j] <= i)
                dp[i] = max(dp[i-w[j]]+v[j], dp[i]);

    cout << dp[W] << endl;
    return 0;
}


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

using lint = long long int;
using pint = pair<int, int>;
using plint = pair<lint, lint>;
#define ALL(x) (x).begin(), (x).end()
#define SZ(x) ((lint)(x).size())
#define POW2(n) (1LL << (n))
#define FOR(i, begin, end) for (int i = (begin), i##_end_ = (end); i < i##_end_; i++)
#define IFOR(i, begin, end) for (int i = (end)-1, i##_begin_ = (begin); i >= i##_begin_; i--)
#define REP(i, n) FOR(i, 0, n)
#define IREP(i, n) IFOR(i, 0, n)
#ifdef LOCAL
#define eprintf(...) fprintf(stderr, __VA_ARGS__)
#else
#define eprintf(...) 42
#endif

int main()
{
    int l, r, d,ans=0;
    cin >> l >> r >>d;
    FOR(i,l,r+1) {
        if(i%d==0)
            ans++;
    }
    cout << ans <<"\n";
    return 0;
}

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

int main(){
    int A;
    cin >> A;
    if((A-7) % 10 == 0){
        cout << "Yes" << endl;
    }
    else if(((A/10)-7)%10 == 0){
        cout << "Yes" << endl;
    }
    else if(A/100 == 7){
        cout << "Yes" << endl;
    }
    else cout << "No" << endl;
}

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

using namespace std;

const int N = 9e5+2;

int mod;

int n;
char x[N];

//0 (mod is number of ones - 1)
//1 (mod is number of ones + 1)
int prf[N][2];
int suf[N][2];

int dp[N];

int f(int r){
	if(r == 0)return 0;
	return 1 + f(r % __builtin_popcount(r));
}

int fastP(int b, int e){
    if(!e)
        return 1;
    if(e & 1)
        return b * 1ll * fastP(b * 1ll * b % mod, e >> 1) % mod;
    return fastP(b * 1ll * b % mod, e >> 1) % mod;
}

int main(){
    cin >> n;
    for(int i = 1; i <= n; i++){
        cin >> x[i];
        mod += x[i] - '0';
    }
    if(mod - 1 > 0){
        long long res = 0;
        mod --;
        for(int i = 1; i <= n; i++){
            prf[i][0] = prf[i - 1][0] + ((x[i] == '1') ? (fastP(2 , n - i)) : 0);
            prf[i][0] %= mod;
        }
        for(int i = n; i >= 1; i--){
            suf[i][0] = suf[i + 1][0] + ((x[i] == '1') ? (fastP(2 , n - i)) : 0);
            suf[i][0] %= mod;
        }
        mod++;
    }
    mod ++;
    for(int i = 1; i <= n; i++){
        prf[i][1] = prf[i - 1][1] + ((x[i] == '1') ? (fastP(2 , n - i)) : 0);
        prf[i][1] %= mod;
    }
    for(int i = n; i >= 1; i--){
        suf[i][1] = suf[i + 1][1] + ((x[i] == '1') ? (fastP(2 , n - i)) : 0);
        suf[i][1] %= mod;
    }
    mod --;

    for(int i = 1; i <= n; i++){
        if(x[i] == '0'){
           mod ++;
           long long res = fastP(2 , n - i);
           res += suf[i+1][1] + prf[i-1][1];
           cout << f(res % mod) + 1 << "\n";
           mod --;
        } else {
           mod --;
           long long res = (suf[i+1][0] + prf[i-1][0]);
           if(mod <= 0){
                cout << 0 << "\n";
           } else {
                cout << f(res % mod) + 1 << "\n";
           }
           mod ++;
        }
    }

}


Measured memory_bytes: 6928
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<ll, ll> l_l;
typedef vector<int> vei;
typedef vector<string> ves;
typedef vector<vector<int>> ve_vei;
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define rep1(i,n) for(int i=1;i<(int)(n);i++)
#define rep2(i,n) for(int i=2;i<(int)(n);i++)
#define fs first
#define sc second
#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))
 
int main() {
	//cout.precision(10);
	cin.tie(0);
	ios::sync_with_stdio(false);

    int N, D, X; cin >> N >> D >> X;
    vei A(N);

    int sum = X;
    rep(i,N) {
        cin >> A[i];
        rep(j,100) if (j * A[i] + 1 <= D) sum++;
    }
    cout << sum << 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))
using ll = long long;
using P = pair<int, int>;
using namespace std;

int dist[101010];
vector<int> G[101010];

int solve(int v) {
    int u = G[v][0];
    if (G[u][0] == v) {
        // 戻ってきたら
        dist[u] = dist[v] = 0;
        return 0;
    }
    dist[v] = solve(u) + 1;
    return dist[v];
}

int main() {
    string s;
    cin >> s;

    rep(i, s.size()) {
        if (s[i] == 'L') G[i].push_back(i-1);
        else G[i].push_back(i+1);
    }

    rep(i, s.size()) dist[i] = -1;

    rep(i, s.size()) {
        if (dist[i] == -1) {
            if (s[i] == 'L' and i+1<s.size() and s[i+1] == 'L') continue;
            solve(i);
        }
    }

    vector<int> ans(s.size(), 0);

    rep(i, s.size()) {
        if (s[i] == 'R') {
            if (dist[i]%2 == 0) ans[i + dist[i]]++;
            else ans[i + dist[i] + 1]++;
        }
        else {
            if (dist[i]%2 == 0) ans[i - dist[i]]++;
            else ans[i - dist[i] - 1]++;
        }
    }

    rep(i, s.size()) {
        if (i) cout << " ";
        cout << ans[i];
    }
    cout << endl;


}


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

int main() {
  int n, l;
  cin >> n >> l;
  vector<LL> a(n);
  LL sum = 0;
  rep(i, n) cin >> a[i];

  int t = -1;
  rep(i, n - 1) {
    if (a[i] + a[i + 1] >= l) t = i + 1;
  }
  if (t == -1) {
    cout << "Impossible" << endl;
    return 0;
  }

  cout << "Possible" << endl;
  for (int i = 1; i <= t - 1; i ++) {
    cout << i << endl;
  }
  for (int i = n - 1; i >= t; i --) {
    cout << i << endl;
  }
}

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

using S = long long;
using F = long long;

const S INF = 8e18;
const F ID = 8e18;

S op(S a, S b) { return std::max(a, b); }
S e() { return -INF; }
S mapping(F f, S x) { return (f == ID ? x : f); }
F composition(F f, F g) { return (f == ID ? g : f); }
F id() { return ID; }

const long long SZ = 300005;
void solve() {
    int n, k;
    cin >> n >> k;
    vector<S> v(SZ);
    // 1点更新、区間最大値なので遅延ではないセグ木で十分だが、
    // 勉強のため遅延セグ木を用いる。
    lazy_segtree<S, op, e, F, mapping, composition, id> seg(v);

    while (n--) {
        long long x;
        cin >> x;
        // 過去に存在した x±k の座標に対する点の数の最大値を求める
        long long me = seg.prod(max(0LL, x - k), min(SZ, x + k + 1));
        // 現在のx座標に対して上記+1をセット（区間更新）
        seg.apply(x, x + 1, me + 1);
    }
    cout << seg.all_prod() << endl;
}

signed main() {
    cin.tie(nullptr)->sync_with_stdio(false);
    solve();
}

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

using namespace std;

using ll = long long;

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

    ll x;
    cin >> x;

    if (x <= 6) cout << 1 << endl;
    else if (x <= 11) cout << 2 << endl;
    else {
        --x;
        ll n = x / 11;
        x -= 11 * n;
        n *= 2;
        if (x < 6) ++n;
        else n += 2;
        cout << n << endl;
    }

    return 0;
}


Measured memory_bytes: 256
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <iostream>
#include <string>
#include <vector>
#include <map>
#include <set>
#include <stack>
#include <list>
#include <queue>
#include <deque>
#include <algorithm>
#include <numeric>
#include <utility>
#include <complex>
#include <functional>
#include <climits>
#include <iomanip>

using namespace std;

int main() {
	long n, q;
	cin >> n >> q;
	vector<long> a(n), x(q);
	for (size_t i = 0; i < n; i++)
	{
		cin >> a[i];
	}
	for (size_t i = 0; i < q; i++)
	{
		cin >> x[i];
	}
	for (size_t z = 0; z < q; z++)
	{
		long ans = 0, s = 0, j = 0;
		for (size_t i = 0; i < n; i++)
		{
			while(s + a[j] <= x[z] && j < n) {
				s += a[j];
				j++;
			}
			ans += j-i;
			if(i == j) j++;
			else s -= a[i];
		}
		cout << ans << endl;
	}
}



Measured memory_bytes: 3620
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<n;i++)
int main(){
  int n,ans; cin>>n; ans=0;
  int p[n];
  rep(i,n) cin>>p[i];
  for(int i=1;i<n-1;i++) if( (p[i-1]<p[i]&&p[i]<p[i+1]) || (p[i-1]>p[i]&&p[i]>p[i+1])) ans++;
  cout<<ans<<endl;
}

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

int main() {
	int a,b;
	cin >> a >> b;
	if (a == b) {
		cout << "Draw";
	} else if (a > b){
		if (b == 1){
			cout << "Bob";
		} else {
			cout << "Alice";
		}
	} else {
		if (a == 1){
			cout << "Alice";
		} else {
			cout << "Bob";
		}
	}
    return 0;
}

Measured memory_bytes: 256
# Balance
def balance
	n = gets.chomp.to_i
	w = gets.chomp.split(/\s/).map{|x| x.to_i}

#	p n
#	p w

	min = 100*100

	left = w[0]
	right = w[1..-1]
	#r = right.sum # for RUby 2.4
	r = right.inject(0){|sum,x| sum + x }

	for i in 1..n-1 do
		min = [min, (left-r).abs].min
#		p min
		item = right.shift
		left += item
		r -= item
	end

	p min
end

balance

Measured memory_bytes: 1916
#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;
using ll = long long;
using ull = unsigned long long; 
using pii =  pair<int, int>;
using pll =  pair<long long, long long>;
#define rep(i, n) for(int i = 0; i < (n); ++i)
#define all(x) (x).begin(),(x).end()
constexpr char ln =  '\n';
constexpr long long MOD = 1000000007LL;
//constexpr long long MOD = 998244353LL;
template<class T, class U> inline bool chmax(T &a, U b) { if (a < b) { a = b; return true;} return false; }
template<class T, class U> inline bool chmin(T &a, U b) { if (a > b) { a = b; return true;} return false; }
////////////////////////////////////////////////////////////////////////////////////////////////////////////
 
int main() {
    ios::sync_with_stdio(false); cin.tie(nullptr);
    
    int N;
    vector<string> S;
    ll ans = 0;
    
    cin >> N;
    rep(i, N){
        string a;
        cin >> a;
        S.push_back(a);
    } 

    sort(S.begin(), S.end());
    S.erase(unique(S.begin(), S.end()), S.end());
    
    ans = S.size();

    cout << ans << ln;
}

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

public class Main {
    private long max;
    private int[][] qs;
    private int N;
    private int M;
    private int Q;

    private long getScore(int[] A) {
        long score = 0;
        for (int[] q : qs) {
            if (A[q[1] - 1] - A[q[0] - 1] == q[2]) {
                score += q[3];
            }
        }
        return score;
    }

    private void dfs(int i, int k, int[] A) {
        A[i] = k;
        if (i == N - 1) {
            max = Math.max(max, getScore(A));
            return;
        }

        for (int t = k; t <= M; ++t) {
            dfs(i + 1, t, A);
        }
    }

    private void solve() {
        N = sc.nextInt();
        M = sc.nextInt();
        Q = sc.nextInt();

        qs = new int[Q][4];
        for (int i = 0; i < Q; i++) {
            for (int j = 0; j < 4; j++) {
                qs[i][j] = sc.nextInt();
            }
        }

        int[] A = new int[N];
        for (int i = 1; i <= M; ++i) {
            dfs(0, i, A);
        }
        out.println(max);
    }

    private static PrintWriter out;
    private static MyScanner sc;

    private static class MyScanner {
        BufferedReader br;
        StringTokenizer st;

        private MyScanner() {
            br = new BufferedReader(new InputStreamReader(System.in));
        }

        String next() {
            while (st == null || !st.hasMoreElements()) {
                try {
                    st = new StringTokenizer(br.readLine());
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
            return st.nextToken();
        }

        int nextInt() {
            return Integer.parseInt(next());
        }

        long nextLong() {
            return Long.parseLong(next());
        }

        double nextDouble() {
            return Double.parseDouble(next());
        }
    }

    public static void main(String[] args) {
        out = new PrintWriter(new BufferedOutputStream(System.out));
        sc = new MyScanner();
        new Main().solve();
        out.close();
    }
}

Measured memory_bytes: 33584
import fractions 
n=int(input())
for _ in range(n):
    a,b,c,d=map(int,input().split())
    if d<b:
        print("No")
        continue
    elif a<b:
        print("No")
        continue
    elif c>=b:
        print("Yes")
        continue
    g=fractions.gcd(b,d)
    h=((b-1-a%b)//g)*g
    if a%b+h>c:
        print("No")
        continue
    print("Yes")

Measured memory_bytes: 5600
#include"bits/stdc++.h"
#include<boost/multi_array.hpp>
#include<boost/optional.hpp>
#include<boost/range/irange.hpp>
#include<boost/range/algorithm.hpp>
#include<boost/range/adaptor/reversed.hpp>
#include<boost/operators.hpp>
#include<boost/dynamic_bitset.hpp>
namespace adaptor = boost::adaptors;
template<class T>using p_queue = std::priority_queue<T, std::vector<T>, std::greater<>>;

void Main()
{
	int N, L;
	std::cin >> N >> L;
	int sum = 0;
	int min = L;
	int max = L + N - 1;
	for (int i : boost::irange(0, N))
	{
		sum += L + i;
	}
	if (0 < min)
	{
		std::cout << sum - min << std::endl;
	}
	else if (max < 0)
	{
		std::cout << sum - max << std::endl;
	}
	else
	{
		std::cout << sum << std::endl;
	}

}

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

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main(void){
    int n;
    cin >> n;
    vector<int>h(n);
    vector<int>dp(n);
    for(int i=0;i<n;i++) cin >> h[i];
    
    dp[0]=0;
    dp[1]=abs(h[0]-h[1]);
    for(int i=2;i<n;i++){
        dp[i]=min(dp[i-1]+abs(h[i]-h[i-1]),dp[i-2]+abs(h[i]-h[i-2]));
    }
    cout <<dp[n-1];
    //for(int i=0;i<n;i++) cout << dp[i]<<" ";
}

Measured memory_bytes: 4044
#include <bits/stdc++.h>
using namespace std;
struct Fast { Fast() { cin.tie(0); ios::sync_with_stdio(false); cout << fixed << setprecision(20);} } fast;

int main() {
    int n, k, a;
    double prob = 0;
    cin >> n >> k;
    for (int i = 1; i <= n; i++){
        a = i;
        for (int j = 0; j <= 20; j++){
            if (a >= k){
                prob = prob + (1.0 / n) * (1.0 / pow(2, j));
                break;
            }
            a = a * 2;
        }
    }
    cout << prob << endl;
}

Measured memory_bytes: 512
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Globalization;
using System.IO;
using System.Linq;
using System.Reflection.Emit;
using System.Text;
using static System.Console;
using static System.Math;


namespace CS_Contest
{
    internal class Program
    {
        private static void Main(string[] args)
        {
            
            string str1 = Console.ReadLine();
            int a = int.Parse(str1);
            //int a = 10;
            string str2 = Console.ReadLine();
            //string str2 = "2184 2126 1721 1800 1024 2528 3360 1945 1280 1776";
            string[] str2s = str2.Split(' ');

            int[] hairetu = new int[a];
            for (int i = 0; i < a; i++)
            {
                hairetu[i] = int.Parse(str2s[i]);
            }

            int count = 0;
            for (int i = 0; i < a; i++)
            {
                count += Func1(hairetu[i]);
            }
            Console.WriteLine(count);
        }

        private static int Func1(int a) 
       {
            int count = 0;
            while(true)
            {
                if (a / 2 == 0)
                {
                    return count;
                }
                else if ( a % 2 != 0)
                {
                    return count;
                }
                else
                {
                    a = a / 2;
                    count++;
                }
            }
       }
    }

    
}


Measured memory_bytes: 11744
#include <bits/stdc++.h>
#define INF INT_MAX
#define ll  long long
#define ull unsigned long long
#define rep(i,n) for(ll i=0; i<n; ++i)
#define FOR(i, s, e) for(ll i=s; i<e; ++i)
#define MOD 1000000007
using namespace std;
template<class T> inline bool chmin(T& a, T b) { if(a>b) {a=b; return true;} return false;}
template<class T> inline bool chmax(T& a, T b) { if(a<b) {a=b; return true;} return false;}

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  int A, B;
  cin >> A >> B;
  cout << 6-A-B << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main()
{   ios_base::sync_with_stdio(false); 
    cin.tie(NULL); 
    int n,m;
    cin>>n>>m;
    vector<bool>vec(n,true);
    vector<int>arr(n, 0);
    int ac=0,pen=0;
    for(int i=0;i<m;i++){
        int p;
        string s;
        cin>>p>>s;
        p--;
       if(vec[p]) {
          if (s=="WA") arr[p]++;
         else {ac++;
              vec[p]=false;
               pen+=arr[p];
             }
       }
    }

  cout<<ac<<" "<<pen<< '\n';

  return 0;
}



Measured memory_bytes: 3720
/*input
8 3 4

*/
#include <iostream>
#include <bits/stdc++.h>
#include <math.h> 

using namespace std;
#define gc getchar_unlocked
#define fo(i,n) for(ll i=0;i<n;i++)
#define Fo(i,k,n) for(ll i=k;k<n?i<n:i>n;k<n?i+=1:i-=1)
#define ll long long
#define si(x)	scanf("%d",&x)
#define sl(x)	scanf("%lld",&x)
#define ss(s)	scanf("%s",s)
#define pi(x)	printf("%d\n",x)
#define pl(x)	printf("%lld\n",x)
#define ps(s)	printf("%s\n",s)
#define deb(x) cout << #x << "=" << x << endl
#define deb2(x, y) cout << #x << "=" << x << "," << #y << "=" << y << endl
#define pb push_back
#define mp make_pair
#define F first
#define S second
#define all(x) x.begin(), x.end()
#define clr(x) memset(x, 0, sizeof(x))
#define sortall(x) sort(all(x))
#define tr(it, a) for(auto it = a.begin(); it != a.end(); it++)
#define PI 3.1415926535897932384626
#define ms(a,x) memset(a, x, sizeof(a));
typedef pair<int, int>	pii;
typedef pair<ll, ll>	pl;
typedef vector<int>		vi;
typedef vector<ll>		vl;
typedef vector<pii>		vpii;
typedef vector<pl>		vpl;
typedef vector<vi>		vvi;
typedef vector<vl>		vvl;
int mpow(int base, int exp); 
void ipgraph(int m);
void dfs(int u, int par);
const int mod = 1000000007;
const int N = 3e5, M = N;


int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    ll n, a, b;
    cin>>n>>a>>b;
    ll ans = (n/(a+b))*a;
    ll r =  n%(a+b);
    cout<<ans+min(a,r)<<endl;
    return 0;
}

Measured memory_bytes: 256
// Atcoder011-A.cpp : Defines the entry point for the console application.
//

#include<stdio.h>
#include<algorithm>
#include<stdlib.h>
using namespace std;
int main()
{
	int N, C, K;
	int current;
	int cnt = 1;
	int bus = 0;
	int bustop = 0;
	int man[100001];
	scanf("%d %d %d", &N, &C, &K);
	for (int i = 0; i < N; i++)
		scanf("%d",&man[i]);
	sort(man, man + N);
	bustop = man[0];
	for (int i = 1; i <= N-1; i++)
	{
		if ((man[i] - bustop) <= K)
		{
			if (cnt < C)
				cnt++;
			else
			{
				cnt = 1;
				bustop = man[i];
				bus++;
			}
		}
		else
		{
			cnt = 1;
			bustop = man[i];
			bus++;
		}
	}
	printf("%d\n",++bus);
    return 0;
}



Measured memory_bytes: 512
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.math.BigInteger;
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner scan = new Scanner(new BufferedReader(new InputStreamReader(System.in)));
        String a = scan.next();
        String b = scan.next();
        String c = scan.next();
        String k = scan.next();
        System.out.println(solve(a,b,c,k));
    }
    public static String solve(String a, String b, String c, String k) {
        BigInteger big_a = new BigInteger(a);
        BigInteger big_b = new BigInteger(b);
        BigInteger big_c = new BigInteger(c);
        BigInteger big_k = new BigInteger(k);
        BigInteger answer = big_a.subtract(big_b);
        if (big_k.mod(new BigInteger("2")) != BigInteger.ZERO) {
            answer = answer.multiply(new BigInteger("-1"));
        }
        if (new BigInteger("1000000000000000000").compareTo(answer) < 0) {
            return "Unfair";
        } else {
            return answer.toString(10);
        }
    }
}


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

signed main() {
  cin.tie(0); ios::sync_with_stdio(false);
  long long n, a, b; cin >> n >> a >> b;
  vector<long long> x(n); for (int i = 0; i < n; i++) cin >> x[i];
  long long res = 0;
  for (int i = 0; i < n - 1; i++) {
    res += min((x[i + 1] - x[i]) * a, b);
  }
  cout << res << '\n';
  return 0;
}

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

int main(){
  int R;
  double pi, l;
  cin >> R;
  pi = 3.141592;
  l = 2 * R * pi;
  cout << fixed;
  cout << setprecision(3) << l << endl;
  return 0;
}

Measured memory_bytes: 3264
#include <bits/stdc++.h>
using namespace std;
typedef long long   signed int LL;
typedef long long unsigned int LU;
#define incII(i, l, r) for(int i = (l)    ; i <= (r); ++i)
#define incID(i, l, r) for(int i = (l)    ; i <  (r); ++i)
#define decII(i, l, r) for(int i = (r)    ; i >= (l); --i)
#define decID(i, l, r) for(int i = (r) - 1; i >= (l); --i)
#define inc(i, n)  incID(i, 0, n)
#define inc1(i, n) incII(i, 1, n)
#define dec(i, n)  decID(i, 0, n)
#define dec1(i, n) decII(i, 1, n)
#define inII(v, l, r) ((l) <= (v) && (v) <= (r))
#define inID(v, l, r) ((l) <= (v) && (v) <  (r))
#define PB push_back
#define EB emplace_back
#define MP make_pair
#define FI first
#define SE second
#define  ALL(v)  v.begin(),  v.end()
#define RALL(v) v.rbegin(), v.rend()
template<typename T> bool setmin  (T & a, T b) { if(b <  a) { a = b; return true; } else { return false; } }
template<typename T> bool setmax  (T & a, T b) { if(b >  a) { a = b; return true; } else { return false; } }
template<typename T> bool setmineq(T & a, T b) { if(b <= a) { a = b; return true; } else { return false; } }
template<typename T> bool setmaxeq(T & a, T b) { if(b >= a) { a = b; return true; } else { return false; } }
LL mo(LL a, LL b) { assert(b > 0); a %= b; if(a < 0) { a += b; } return a; }
LL fl(LL a, LL b) { assert(b > 0); return (a > 0 ? a / b : (a - b + 1) / b); }
LL ce(LL a, LL b) { assert(b > 0); return (a < 0 ? a / b : (a + b - 1) / b); }
#define bit(b, i) (((b) >> (i)) & 1)
#define BC __builtin_popcountll
#define SC(T, v) static_cast<T>(v)
#define SI(v) SC(int, v.size())
#define SL(v) SC( LL, v.size())
#define RF(e, v) for(auto & e: v)
#define ei else if
#define UR assert(false)

// ---- ----

LL n, dp[101][4][4][4], ans, MOD = 1e9 + 7;

bool g(vector<int> v) {
	vector<int> x = { v[0], 0, 1, 2 };
	vector<int> y = { 0, 1, 2, v[3] };
	return (v != x && v != y);
}

bool ok(vector<int> v) {
	bool f = g(v);
	inc(i, 3) {
		vector<int> w = v;
		swap(w[i], w[i + 1]);
		f &= g(w);
	}
	return f;
}

int main() {
	cin >> n;
	
	dp[0][3][3][3] = 1;
	inc(i, n) {
		inc(a, 4) {
		inc(b, 4) {
		inc(c, 4) {
		inc(d, 4) {
			if(! ok({ a, b, c, d })) { continue; }
			
			(dp[i + 1][b][c][d] += dp[i][a][b][c]) %= MOD;
			
			if(i + 1 == n) { (ans += dp[i][a][b][c]) %= MOD; }
		}
		}
		}
		}
	}
	
	cout << ans << endl;
	
	return 0;
}



Measured memory_bytes: 256
#include<iostream>
#define int long long
using namespace std;
const int N=1e5+2;
const int mod=1e9+7;
int ar[N],sum[N];
int binpow(int x,int y){
	int tich=1;
	while(y){
		if(y&1){
			tich*=x;
			tich%=mod;
		}
		x*=x;
		x%=mod;
		y>>=1;
	}
	return tich;
}
signed main(){
	ios::sync_with_stdio(0);
	cin.tie(0);
	int n,i,j,k,l,ans=0;
	cin>>n;
	for(i=1;i<=n;i++){
		cin>>ar[i];
	}
	for(i=2;i<=n;i++){
		sum[i]=sum[i-1]+binpow(i,mod-2);
		if(sum[i]>=mod){
			sum[i]-=mod;
		}
	}
	for(i=1;i<=n;i++){
		ans+=ar[i]*(sum[i]+sum[n+1-i]+1);
		//cout<<sum[2]<<endl;
		ans%=mod;
	}
	for(i=2;i<=n;i++){
		ans*=i;
		ans%=mod;
	}
	cout<<ans;
}

Measured memory_bytes: 1792
#include <iostream>
#include <vector>
#include <list>
#include <tuple>
#include <unordered_set>
#include <queue>
using namespace std;

constexpr int INF = 1 << 30;
using P = pair<int, int>;

class Graph {
private:
	const int N, M;
	vector<int> d;
	vector< tuple<int, int, int> > E;
	vector< list< P > > List;
	unordered_set<int> S;
	priority_queue< P, vector<P>, greater<P> > Q;
public:
	Graph(int n, int m) : N(n), M(m), d(n, INF), List(n) {}
	void InputEdge(int s, int t, int d) {
		E.push_back(make_tuple(s, t, d));
		List[s].push_back(make_pair(t, d));
	}
	void BellmanFord(int r);
	void Dijkstra(int r);
};

void Graph::BellmanFord(int r){
	d[r] = 0;
	for (int i = 0; i < N - 1; i++) {
		bool update = false;
		for (int j = 0; j < M; j++) {
			int u = get<0>(E[j]), v = get<1>(E[j]), w = get<2>(E[j]);
			if (d[v] > d[u] + w) {
				d[v] = d[u] + w;
				update = true;
			}
		}
		if (!update)
			break;
	}
	for (int i = 0; i < N; i++) {
		if (d[i] == INF)
			cout << "INF" << endl;
		else
			cout << d[i] << endl;
	}
}

void Graph::Dijkstra(int r) {
	d[r] = 0;
	for (int i = 0; i < N; i++)
		Q.push(make_pair(0, r));
	while (!Q.empty()) {
		int u = Q.top().second;
		Q.pop();
		if (S.find(u) != S.end())
			continue;
		S.insert(u);
		for (auto i = List[u].begin(); i != List[u].end(); ++i) {
			int v = (*i).first;
			if (S.find(v) != S.end())
				continue;
			else {
				int w = (*i).second;
				if (d[v] > d[u] + w) {
					d[v] = d[u] + w;
					Q.push(make_pair(d[v], v));
				}
			}
		}
	}
	for (int i = 0; i < N; i++) {
		if (d[i] == INF)
			cout << "INF" << endl;
		else
			cout << d[i] << endl;
	}
}

int main() {
	int n, m, r;
	cin >> n >> m >> r;
	Graph G(n, m);
	for (int i = 0; i < m; i++) {
		int s, t, d;
		cin >> s >> t >> d;
		G.InputEdge(s, t, d);
	}
	G.Dijkstra(r);
}


Measured memory_bytes: 30576
#include <algorithm>
#include <bits/stdc++.h>
#include <deque>
#include <iostream>
#include <queue>
#include <string>
#include <vector>
using namespace std;
#define INF 1LL << 40;
#define MOD 1000000007;
#define ll long long
#define REP(i, a, b) for(int i = a; i < b; i++)
#define rep(i, n) REP(i, 0, n)
#define prique priority_queue
typedef pair<int, int> P;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<P> vp;
typedef vector<ll> vl;
int dx[4] = {0, 1, 0, -1};
int dy[4] = {1, 0, -1, 0};
template <class T> inline void chmax(T &a, T b) { a < b ? a = b : a; };
template <class T> inline void chmin(T &a, T b) { a > b ? a = b : a; };
vector<int> factoring(int n0) {
    vector<int> factor;
    int num;    // 整数
    int ns = 2; // 素因数
    int j;      // 乗数
    int sq = (int)sqrt(num);
    for(num = n0, ns = 2; sq > ns && num >= ns; ns++) {
        for(j = 0; num % ns == 0; j++) // 割り切れる間繰り返す
        {
            num /= ns;
        }

        if(j == 0)
            continue; // 1回も割り切れなかった

        rep(i, j) factor.push_back(ns);
    }
    if(num != 1) {
        factor.push_back(num);
    }
    return factor;
}
int main() {
    int n;
    cin >> n;
    auto f = factoring(n);
    cout << n << ":";
    for(auto num : f) {
        cout << " " << num;
    }
    cout << endl;
}



Measured memory_bytes: 3152
#include<stdio.h>
#include<iostream>
using namespace std;
int main(){
    int n,a;
    cin >> n >> a;
    n = (n % 500);
    while(a >= 0){
        if( n == a){
            cout << "Yes" << endl;
            return 0;
        }
        a--;
    }
    cout << "No" << endl;
}


Measured memory_bytes: 256
#include <stdio.h>

int main() {
    char s[3];
    int rnum = 0;
    int flag = 0;

    scanf("%s", s);

    for (int i = 0; i < 3; i++) {
        if (s[i] == 'R') {
            rnum++;
        }
        else if (i == 1) {
            flag++;
        }
    }
    if (flag == 1 && rnum == 2) {
        printf("1\n");
    }
    else
    {
        printf("%d\n", rnum);
    }
    return 0; 
}

Measured memory_bytes: 1728
#include<iostream>
#include<stdio.h>
#include<string.h>
#include<algorithm>
#include<vector>
#include<queue>
#include<map>
#include<set>
#include<iomanip>
#include<cmath>

#define REP(i,n) for (int i = 0; (i) < (n); ++ (i))
#define FOR(i,n) for (int i = 1; (i) <= (n); ++ (i))
#define dump(x)  cout << #x << " = " << (x) << endl;
#define pb push_back
#define int long long

const int INF = 1e18;
const int MOD = 1e9+7;
//const lint LINF = 1e18;
const double eps = 0.000000001;//もとの値の10^(-16)まで

using namespace std;

typedef pair<int, int> P;
//priority_queue< int, vector<int>, greater<int> > q;//ダイクストラの時、greaterで小さい順
//priority_queue< P, vector<P>, greater<P> > q;//ダイクストラの時、greaterで小さい順
//cout << fixed << setprecision(10) << ans << endl;
//int gcd(int a,int b){return b?gcd(b,a%b):a;}

signed main(){
    int t;
    cin >> t;
    REP(i22,t){
        int n;
        cin >> n;
        vector<P>hidari;
        vector<P>migi;
        int ans = 0;
        REP(i,n){
            int k1,l1,r1;
            cin >> k1 >> l1 >> r1;
            
            if(l1>=r1){
                hidari.pb(P(k1,l1-r1));
                ans += r1;
            }
            else{
                migi.pb(P(k1,r1-l1));
                ans += l1;
            }
        }
        sort(hidari.begin(),hidari.end());
        sort(migi.begin(),migi.end());
        reverse(hidari.begin(),hidari.end());

        int hi_s = hidari.size();
        int mi_s = migi.size();

        priority_queue< int, vector<int> > q;
        int mi_ind = 0;
        for(int i=hi_s+1;i<=n;i++){
            while(mi_ind < mi_s && migi[mi_ind].first<i){
                q.push(migi[mi_ind].second);
                mi_ind ++;
            }
            if(q.size()==0) continue;
            ans += q.top();
            q.pop();
        }

        priority_queue< int, vector<int> > q2;
        int hi_ind = 0;
        for(int i=hi_s;i>=1;i--){
            while(hi_ind < hi_s && hidari[hi_ind].first>=i){
                q2.push(hidari[hi_ind].second);
                hi_ind ++;
            }
            if(q2.size()==0) continue;
            ans += q2.top();
            q2.pop();
        }
        cout << ans << endl;
    }



    return 0;
}

Measured memory_bytes: 8216