akhauriyash/Code-Regression huggingface dataset:
import math
q=int(input())
lr=[list(map(int,input().split())) for _ in range(q)]
n= 10**5
#エラストテネスのふるい
is_prime=[True]*(n+1)
is_prime[0]=is_prime[1]=False
for i in range(2,int(math.sqrt(n))+1):
	if is_prime[i]:
		for j in range(2*i,n+1,i):
			is_prime[j]=False
L=[0,0]
c=0
for i in range(2,n+1):
	if is_prime[i] and is_prime[(i+1)//2]:
		c += 1
	L.append(c)
for l,r in lr:
	print(L[r]-L[l-1])

Measured memory_bytes: 29844
#include <stdio.h>

int main()
{
    int a;
    scanf("%d", &a);
    if ((a % 10) == 2 || (a % 10) == 4 || (a % 10) == 5 || (a % 10) == 7 || (a % 10) == 9)
        printf("hon");
    if ((a % 10) == 0 || (a % 10) == 1 || (a % 10) == 6 || (a % 10) == 8)
        printf("pon");
    if ((a % 10) == 3)
        printf("bon");
}

Measured memory_bytes: 1728
#include<iostream>
#include<vector>
#include<utility>
#include<algorithm>
#include<queue>
#include<cstdio>
using namespace std;
int main() {
  int N, D, A;
  cin >> N >> D >> A;
  vector<pair<int, int>> vp(N);
  for (auto& p : vp) cin >> p.first >> p.second;
  sort(vp.begin(), vp.end());

  queue<pair<int, long long>> q;
  long long ans = 0;
  long long bias = 0;
  for (auto p : vp) {
    int x = p.first;
    int h = p.second;
    for (; q.size() && q.front().first < x;) {
      bias -= q.front().second;
      q.pop();
    }
    h -= bias;
    if (h <= 0) continue;
    int num = (h + A - 1) / A;
    int dmg = num * A;
    bias += dmg;
    ans += num;
    q.push({x + 2 * D, dmg});
  }
  cout << ans << endl;
}

Measured memory_bytes: 3456
l=list(map(int,input().split()))

if l.count(l[0])==3:
    if l[0]%2==0:
        print(-1)
        exit()
    else:
        print(0)
        exit()

count=0
while True:
    temp=list(map(lambda x:x%2,l))
    all=sum(temp)
    if all==3:
        print(count+1)
        exit()
    elif all==2:
        print(count)
        exit()
    elif all==1:
        print(count)
        exit()
    l=list(map(lambda x:x//2,l))
    count+=1



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

typedef long long ll;
#define endl '\n'

int main()
{
    int k;cin>>k;
    string str;cin>>str;
    if(k>=str.size())cout<<str<<endl;
    else
    {
        for(int i=0;i<k;i++)cout<<str[i];
        cout<<"...\n";
    }
    return 0;
}


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


using namespace std;

int dfs_search(int s, vector<vector<int>> &edges, vector<int> &dp){
    if (dp[s] != -1) return dp[s];
    dp[s] = 0;
    for(auto v: edges[s]){
        dp[s] = max(dp[s], 1 + dfs_search(v, edges, dp));
    }
    return dp[s];
}


int main()
{
   ios::sync_with_stdio(0);
   cin.tie(0);
   int N, M;
   cin >> N >> M;
   vector<vector<int>> edges(N+1);
   vector<int> dp(N+1, -1);
   for (int i = 0; i < M; ++i){
       int x, y;
       cin >> x >> y;
       edges[x].push_back(y);
       edges[0].push_back(x);
       edges[0].push_back(y);
   }
   /* sort(edges[0].begin(), edges[0].end()); */
   /* edges[0].erase(unique(edges[0].begin(), edges[0].end()), edges[0].end()); */
   cout << dfs_search(0, edges, dp) - 1<< "\n";
}



Measured memory_bytes: 10356
#dp-a
n=int(input())
h=list(map(int,input().split()))
dp=[0]*n
for i in range(n):
    if i==0:dp[0]=0
    elif i==1:dp[1]=abs(h[0]-h[1])
    else:
        dp[i]=min(dp[i-2]+abs(h[i]-h[i-2]),dp[i-1]+abs(h[i]-h[i-1]))
print(dp[n-1])

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

// #undef DEBUG  // Uncomment this line to forcefully disable debug print.
#if DEBUG
template <typename T>
    void debug(T value) {
  std::cerr << value;
}
template <typename T, typename... Ts>
    void debug(T value, Ts... args) {
  std::cerr << value << ", ";
  debug(args...);
}
#define dbg(...)                              \
  do {                                        \
cerr << #__VA_ARGS__ << ": ";             \
debug(__VA_ARGS__);                       \
cerr << " (L" << __LINE__ << ")" << endl; \
  } while (0)
#else
#define dbg(...)
#endif

void read_from_cin() {}
template <typename T, typename... Ts>
    void read_from_cin(T& value, Ts&... args) {
  std::cin >> value;
  read_from_cin(args...);
}
#define in(type, ...) \
  type __VA_ARGS__;   \
  read_from_cin(__VA_ARGS__);

template <typename T>
    void write_to_cout(const T& value) {
  std::cout << value << std::endl;
}
template <typename T, typename... Ts>
    void write_to_cout(const T& value, const Ts&... args) {
  std::cout << value << ' ';
  write_to_cout(args...);
}
#define out(...) write_to_cout(__VA_ARGS__);

#define all(x) (x).begin(), (x).end()
#define rep(i, n) for (int i = 0; i < (int)(n); ++i)

using ll = long long;

using namespace std;

const ll kMods[] = {
  1000000007,
  1000992299,
  999119999,
};

struct Hash {
  ll hash[3];
  void Add(char c) {
    rep(i, 3) {
      hash[i] = (hash[i] * 26 + c - 'a') % kMods[i];
    }
  }
  bool operator<(const Hash& h) const {
    rep(i, 3) if (hash[i] != h.hash[i]) return hash[i] < h.hash[i];
    return false;
  }
  bool operator==(const Hash& h) const {
    rep(i, 3) if (hash[i] != h.hash[i]) return false;
    return true;
  }
};

Hash hashes[5000];

int main() {
  in(int, n);
  in(string, s);
  rep(i, n) hashes[i].Add(s[i]);
  int ans = 0;
  for (int length = 2; length <= n / 2; ++length) {
    set<Hash> seen;
    for (int i = 0; i + length - 1 < n; ++i) {
      hashes[i].Add(s[i + length - 1]);
      if (ans == length) continue;
      if (i - length >= 0) {
        seen.insert(hashes[i - length]);
      }
      if (seen.count(hashes[i])) {
        ans = length;
      }
    }
  }
  out(ans);
}


Measured memory_bytes: 640
from collections import Counter


def read_int():
    return int(input().strip())


def read_ints():
    return list(map(int, input().strip().split(' ')))


def solve():
    s = input().strip()
    G = Counter()
    for c in s:
        if c.islower():
            G[c] += 1
    return 'Yes' if all(val%2 == 0 for val in G.values()) else 'No'


if __name__ == '__main__':
    print(solve())


Measured memory_bytes: 65008
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
    ($($r:tt)*) => {
        let mut s = {
            use std::io::Read;
            let mut s = String::new();
            std::io::stdin().read_to_string(&mut s).unwrap();
            s
        };
        let mut iter = s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
}

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

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

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

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

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

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

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

use rand::Rng;

fn position_max<T: Ord>(slice: &[T]) -> Option<usize> {
    slice.iter().enumerate().max_by(|(_, value0), (_, value1)| value0.cmp(value1)).map(|(idx, _)| idx)
}

fn main() {
    input! {
        D: usize,
        C: [i64; 26],
        S: [[i64; 26]; D],
    }

    let score = |sol: &Vec<i64>| -> i64 {
        let mut sat: i64 = 0;
        let mut last = vec![0; 26];
        for (d, v) in sol.iter().enumerate() {
            let j: usize = (v - 1) as usize;
            last[j] = d + 1;
            for i in 0..26 {
                sat -= (d + 1 - last[i]) as i64 * C[i];
            }
            sat += S[d][j];
        }

        return sat;
    };


    let mut rng = rand::thread_rng();

    let mut best: Vec<i64>;
    let mut ans:Vec<i64> = vec![];
    for i in 0..D {
        ans.push(rng.gen_range(1, 27));
    }

    let mut s = score(&ans);
    for _ in 0..1000 {
        let c = rng.gen_range(1, 27);
        let d = rng.gen_range(0, D);
        let b = ans[d];
        ans[d] = c;
        let ss = score(&ans);
        if ss > s{
            s = ss;
        }else{
            ans[d] = b;
        }
    }

    for c in ans {
        println!("{}", c);
    }
    // println!("{}", score(&ans));
}


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

int main(){
    using namespace std;
    unsigned long T;
    cin >> T;
    for(unsigned long iter{0}; iter < T; ++iter){
        unsigned long N;
        cin >> N;
        vector<unsigned long> A(N);
        for(auto&& i : A)cin >> i;
        string S;
        cin >> S;
        reverse(begin(A), end(A));
        reverse(begin(S), end(S));
        set<unsigned long, greater<>> st;
        cout << [&]{for(unsigned long i{0}; i < N; ++i){
            if(S[i] == '0'){
                unsigned long tmp{A[i]};
                for(const auto& j : st){
                    if(!tmp)break;
                    if(__builtin_clzl(tmp) > __builtin_clzl(j))continue;
                    if(__builtin_clzl(tmp) < __builtin_clzl(j))break;
                    tmp ^= j;
                }
                if(tmp)st.insert(tmp);
            }else{
                unsigned long tmp{A[i]};
                for(const auto& j : st){
                    if(!tmp)break;
                    if(__builtin_clzl(tmp) > __builtin_clzl(j))continue;
                    if(__builtin_clzl(tmp) < __builtin_clzl(j))break;
                    tmp ^= j;
                }
                if(tmp)return 1;
            }
        }return 0;}() << endl;
    }
    return 0;
}

Measured memory_bytes: 3600
def solve():
    import sys
    sys.setrecursionlimit(10**6)
    def dfs(tree, n, ans):
        for i in tree[n]:
            ans[i] += ans[n]
            tree[i].remove(n)
            dfs(tree, i, ans) #再帰関数になっている。次の木の中を探索
     
    n, q = map(int,input().split())
    ab = [list(map(int,input().split())) for _ in range(n-1)]
    px = [list(map(int,input().split())) for _ in range(q)]
     
    g = [[] for _ in range(n)]
    for i in range(n-1):
        g[ab[i][0]-1].append(ab[i][1]-1)
        g[ab[i][1]-1].append(ab[i][0]-1)
    
    ans = [0]*n
    for i in range(q):
        ans[px[i-1][0]-1] += px[i-1][1]
    dfs(g, 0, ans)
     
    print(*ans)
    
if __name__ == "__main__":
    solve()

Measured memory_bytes: 349632
/*jai_ganeshdeva*/

#include<bits/stdc++.h>
using namespace std;
#define pb push_back
#define pu push  //  adds the value to the last of the queue 
#define lld long long int
#define ins insert /// used in set to insert the values 
#define adv advance  /// used to increment the iterator
#define mp make_pair
#define fi first
#define se second
#define all(c) c.begin(),c.end()
#define PI 3.1415926
#define INF (lld)1e18
#define vl  vector<long long int >
#define vpll vector< pair<lld ,lld> >
#define vvl vector<vector<lld> > 
#define pll pair <lld,lld>
lld p1=1e9 + 7,p2=998244353;

void judge(){
    #ifndef ONLINE_JUDGE
    // for getting input from input.
    freopen("input.txt", "r", stdin);
    // for writing output to output.txt
    freopen("output.txt", "w", stdout);
    #endif
    
}

void fastio(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
}


long long int modp(lld a,lld p,lld n)
{
    lld d[100];
    lld i,j,k,l;
    if(n==0) return 1;
    for(i=0;n>=1;i++)
    {
        d[i]=n%2;
        n/=2;
    }
    l=i;
    long long int e=1;
    if(d[0]==1) e*=(a%p);
    for(i=1;i<l;i++)
    {
        a*=a;
        a=a%p;
        if(d[i]==1) 
        {
            e*=a;
            e=e%p;
        }
    }
    return e%p;
}
lld modInverse(lld n, lld p) 
{ 
    return modp(n, p, p-2); 
}

lld fac[5005]; 

void getfac(lld p)
{
    fac[0] = 1; 
    for (lld i=1 ; i<=5005; i++) 
        fac[i] = fac[i-1]*i%p; 
}    

long long int nCrmodp(lld n, lld r,lld p) 
{ 
   // Base case 
   if (r==0) 
      return 1; 
     
    return (fac[n]* modInverse(fac[r], p) % p * 
            modInverse(fac[n-r], p) % p) % p; 
}


lld l,r,mid,ans=0;
lld n,i,j,k,g,m;
lld x,y,n1,n2,h,z,c;
lld aa=1;

lld ss=1;

void solve()
{ 
    cin>>n;
    ans =0 ;
    i=0;
    while(n>0)
    {
        n-=3;
        if(n<0) break;
        ans+=nCrmodp(i+n,i,p1);
        i+=1;
        ans%=p1;
        // cout<<ans<<" ";
    }
    cout<<ans;
}

int main()
{
    // judge();
    fastio();
    lld t=1;
    // cin>>t;
    lld p1 = 1e9 + 7;
    getfac(p1);
    for(int i=0;i<t;i++)
    {
        // cout<<"Case #"<<i+1<<": ";
        solve();
        cout<<"\n";
    }
    return 0;
}



Measured memory_bytes: 3672
#include<iostream>
#include<algorithm>
#include<string>
#include<vector>
#include<cmath>
#include<map>
#include<iomanip>
#include<queue>
#include<stack>
#include<time.h>
#define rep(i,n)for(ll i=0;i<n;i++)
#define ll long long
#define ggr getchar();getchar();return 0;
#define prique priority_queue
#define inf 1145141919364364
#define double long double
using namespace std;
typedef pair<ll, ll>P;
ll gcd(ll x, ll y) {
	if (y == 0)return x;
	return gcd(y, x % y);
}
ll lcm(ll x, ll y) {
	return x * y / gcd(x, y);
}
signed main() {
	ll n, a, b;
	cin >> n >> a >> b;
	cout << min(b, n * a) << endl;
	ggr
}





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

int main() {
    int n;
    cin >> n;
    double  a[n];
    double total=0;
    for(int i=0;i<n;i++){
        cin >> a[i];
        total+=a[i];
    }
    double ave=total/n;
    int ans=0;
    double com=1e9;
    for(int i=0;i<n;i++){
        if(ave>=a[i]){
            if(ave-a[i]<com){
                com=ave-a[i];
                ans=i;
            }
        }
        else{
            if(a[i]-ave<com){
                com=a[i]-ave;
                ans=i;
            }
        }
        
    }
    cout << ans << endl;
}

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

using namespace std;

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

    int N;
    cin >> N;
    vector<int> p(N);
    for (int i = 0; i < N; ++i) {
        cin >> p[i];
    }
    bool swapped = false;
    for (int i = 0; !swapped && i < N; ++i) {
        for (int j = i + 1; !swapped && j < N; ++j) {
            if (p[i] == j + 1 && p[j] == i + 1) {
                swap(p[j], p[i]);
                swapped = true;
            }
        }
    }
    if (is_sorted(begin(p), end(p))) {
        cout << "YES\n";
    } else {
        cout << "NO\n";
    }
    return 0;
}

Measured memory_bytes: 256
import io.StdIn._

object Main extends App {
  val Seq(k, x): Seq[Int] = readLine().split(" ").map(_.toInt)

  require(1 <= k && k <= 100)
  require(0 <= x && x <= 100)

  println((x until x + k).concat(x - k + 1 to x).toSet.toSeq.sorted.mkString(" "))
}


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

#define rep(i,n) for(int i = 0; i < (n); i++)
#define rrep(i,n) for(int i = (n)-1; i >= 0; i--)
#define rep1(i,n) for(int i = 1; i <= (n); i++)
#define rrep1(i,n) for(int i = (n); i > 0; i--)

#define ll long long
#define pi pair<int, int>
#define pll pair<ll, ll>

#define MOD 1000000007
#define INF 1000000000000000LL

using namespace std;

int main(){
  int h,w;cin>>h>>w;
  vector<string> s(h);
  rep(i, h)cin>>s[i];

  vector<vector<int>> dp(h, vector<int>(w) );
  rep(i, h)rep(j, w)dp[i][j]=1000000;
  dp[0][0]=0;
  rep(i, h)rep(j, w){
    if(i<h-1)dp[i+1][j] = min(dp[i+1][j], dp[i][j]+(s[i][j]!=s[i+1][j] ? 1 : 0) );
    if(j<w-1)dp[i][j+1] = min(dp[i][j+1], dp[i][j]+(s[i][j]!=s[i][j+1] ? 1 : 0) );
  }
  int result=dp[h-1][w-1]/2;
  if(s[0][0]!=s[h-1][w-1])result++;
  else if(s[0][0]==s[h-1][w-1] && s[h-1][w-1]=='#')result++;
  cout<<result<<endl;

  return 0;

  rep(i, h){
    rep(j,w)cout<<dp[i][j];cout<<endl;
  }

  return 0;
}

Measured memory_bytes: 256
import sys
input = sys.stdin.readline
def main():
  n,m=map(int,input().split())
  a=list(map(int,input().split())) #横一列リスト
  ans=0
  for i in range(m):
    ans+=a[i]
  if ans<=n:
      print(n-ans)
  else:
      print('-1')
main()

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

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

fn main() {
    let s:String = read();
    println!("{}", &s[0..3]);
}

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

string s;

int main(){
  cin >> s;
  string left = s, right = s;
  reverse(right.begin(), right.end());
  //cerr<< left << " "<< right << endl;
  
  int res = 0;
  for(int i = 0; i < (left.size() + 1) / 2; i++){
    char r = right.at(i), l = left.at(i);
    int n = left.size();
    //cerr << i << " "<< n - i <<" ";
    if(r == l){
      //cerr << endl;
      continue;
    }
    if(r != 'x' && l != 'x'){ //２つが異なる文字で、かつどちらもxでない
      res = -1;
      cerr << "break" << endl;
      break;
    }
    if(r == 'x'){
      right.insert(n - i, "x");
      left.insert(i, "x");
    }else if(l == 'x'){
      right.insert(i, "x");
      left.insert(n - i, "x");
    }
    //cerr << left << " "<< right << endl;
    res++;
  }
  cout << res << endl;
  return 0;
}


Measured memory_bytes: 1024
#include <iostream>
#include <string>
#include <vector>
#include <stack>
#include <utility>
#include <tuple>
#include <algorithm>

using namespace std;

int main(){

    int N, i, j;
    string S;
    cin >> N;

    vector<pair<int,int>> increasing_part;
    vector<pair<int,int>> decreasing_part;

    int num_total(0);
    int tmp_min, tmp_all;
    int now;

    for(i=0;i<N;++i){

        cin >> S;
        tmp_min = tmp_all = 0;
        now = 0;

        for(j=0;j<S.size();++j){
            if(S[j]=='('){
                ++now;
            }else{
                --now;
            }
            tmp_min = min( tmp_min, now );
        }
        tmp_all = now;
        num_total += now;

        if(tmp_all >= 0){
            increasing_part.push_back(make_pair(tmp_min,tmp_all));
        }else{
            decreasing_part.push_back(make_pair(min( 0, tmp_min - tmp_all), -tmp_all));
        }

    }

    if(num_total != 0){
        cout << "No" << endl;
        return 0;
    }

    sort( increasing_part.begin(), increasing_part.end(), greater<pair<int,int>>() );
    sort( decreasing_part.begin(), decreasing_part.end(), greater<pair<int,int>>() );

    int val(0);
    for(const auto &p : increasing_part){
        if(val + p.first < 0){
            cout << "No" << endl;
            return 0;
        }
        val += p.second;
    }

    val = 0;
    for(const auto &p : decreasing_part){
        if(val + p.first < 0){
            cout << "No" << endl;
            return 0;
        }
        val += p.second;
    }

    cout << "Yes" << endl;
    return 0;
}


Measured memory_bytes: 11160
# coding: utf-8
import numpy as np


def solve(*args: str) -> str:
    n = int(args[0])
    A = np.array(list(map(int, args[1].split())))
    B = np.array(list(map(int, args[2].split())))

    ret = False

    sA = np.sort(A)
    sB = np.sort(B)

    if all(sA <= sB):
        if any(sA[1:] <= sB[:-1]):
            ret = True
        else:
            nA = np.argsort(A)
            nB = np.argsort(B)
            P = dict(zip(nA, nB))

            count = 0
            x = P[0]
            while x != 0:
                x = P[x]
                count += 1

            ret = count < n-1

    return 'Yes' if ret else 'No'


if __name__ == "__main__":
    print(solve(*(open(0).read().splitlines())))


Measured memory_bytes: 33648
#include <algorithm>
#include <iostream>

long long i, o, t, j, l, s, z;

int main() {
    std::cin >> i >> o >> t >> j >> l >> s >> z;

    std::cout << std::max((i / 2 * 2 + o + j / 2 * 2 + l / 2 * 2), ((i - 1) / 2 * 2 + o + (j - 1) / 2 * 2 + (l - 1) / 2 * 2 + (i&&j&&l) * 3)) << std::endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int n;
ll a[100005];
ll p[100005];
ll S[100005];
ll ans=  0;
int main(){
    scanf("%d",&n);
    for (int i = 0; i <= n; i++){
        scanf("%lld",&a[i]);
    }
    for (int i = n; i >= 0; i--){
        p[i] = p[i+1]+a[i];
    }
    for (int i = 0; i <= n; i++){
        S[i] = (i==0?1:2*S[i-1])-a[i];
        S[i] = min(S[i],p[i+1]);
        ans += S[i]+a[i];
        if (S[i] < 0){
            printf("-1\n");
            return 0;
        }
        //printf("%d %lld\n",i,S[i]);
    }
    printf("%lld",ans);

}


Measured memory_bytes: 6172
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<iomanip>
#include<math.h>
#include<complex>
#include<queue>
#include<deque>
#include<stack>
#include<map>
#include<set>
#include<bitset>
#include<functional>
#include<assert.h>
#include<numeric>
using namespace std;
#define REP(i,m,n) for(int i=(int)(m) ; i < (int) (n) ; ++i )
#define rep(i,n) REP(i,0,n)
using ll = long long;
const int inf=1e9+7;
const ll longinf=1LL<<60 ;
const ll mod=1e9+7 ;


ll dp[101010][13];
int main(){
    string s;
    cin>>s;
    dp[0][0]=1;
    int n=s.size();
    rep(i,n)rep(j,13){
        dp[i][j]%=mod;

        if(s[i]=='?'){
            rep(k,10)dp[i+1][(10*j+k)%13]+=dp[i][j];
        }
        else {
            int d = s[i]-'0';
            dp[i+1][(10*j+d)%13]+=dp[i][j];
        }
    }
    cout<<dp[n][5]%mod<<endl;
    return 0;
}

Measured memory_bytes: 10752
#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<cmath>
#include<string>
#include<cstring>
#include<algorithm>
#include<functional>
#include<vector>
#include<map>

using namespace std;
#define endl '\n'
#define pb push_back
#define fst first
#define scd second
#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))
#define ALL(x) (x).begin(), (x).end()
#define RALL(x) (x).rbegin(), (x).rend()
#define REP(i,n) for(int i = 0;i < (n);i++)
#define FOR(i,a,b) for(int i = (a);i <= (b);i++)
#define YES(n) cout << ((n) ? "YES" : "NO" ) << endl
#define Yes(n) cout << ((n) ? "Yes" : "No" ) << endl

constexpr int MOD = 1000000007;

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> P;
typedef vector<int> vi;
typedef vector<vector<int>> vii;

template <class T = int> T in() { T x; cin >> x; return (x); }
template <class T = int> void out(T x) { cout << (x) << endl; }

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

void solve() {

	int N;
	cin >> N;
	vi A(N + 1);
	vi B(N + 1);

	for (int i = 1; i <= N; i++) {
		cin >> A[i];
		B[i] = A[i] - i;
	}

	sort(B.begin() + 1, B.end());
	int b;
	b = B[N / 2 + 1];
	
	ll ans = 0;
	for (int i = 1; i <= N; i++) {
		ans += abs((ll)B[i] - b);
	}

	cout << ans << endl;

	return;

}

int main() {

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

	solve();

	return 0;

}

Measured memory_bytes: 1792
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
using P = pair<ll,ll>;
const ll mod = 1e9+7;
#define ALL(x) (x).begin(),(x).end()
#define REP(i,n) for(ll (i)=0;(i)<(n);(i)++)
#define REPS(i,n) for(ll (i)=1;(i)<=(n);(i)++)
#define RREP(i,n) for(ll (i)=(n-1);(i)>=0;(i)--)
#define RREPS(i,n) for(ll (i)=(n);(i)>0;(i)--)
#define pb push_back
#define mp make_pair
#define F first
#define S second
#define UNIQUE(v) v.erase(unique(ALL(v)),v.end());

template<class T> inline void chmin(T& a, T b){
    if (a > b){
        a = b;
    }
}

template<class T> inline void chmax(T& a, T b){
    if (a < b){
        a = b;
    }
}

signed main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout<<fixed<<setprecision(10);
    int N;
    cin >> N;
    vector<int> A(N);
    REP(i,N)cin >> A[i];
    sort(ALL(A));
    cout << A[N-1] - A[0] << "\n";
}

Measured memory_bytes: 512
#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>
using namespace std;
const int MOD = 1000000007;
typedef long long ll;
typedef pair<ll, ll> p;
const int INF = (1 << 28);
const int dx[4] = {0, 1, 0, -1}, dy[4] = {-1, 0, 1, 0};
const int Dx[8] = {0, 1, 1, 1, 0, -1, -1, -1}, Dy[8] = {-1, -1, 0, 1, 1, 1, 0, -1};
#define yes cout << "Yes" << endl
#define YES cout << "YES" << endl
#define no cout << "No" << endl
#define NO cout << "NO" << endl
#define REP(i, n) for (int i = 0; i < n; i++)
#define REPR(i, n) for (int i = n; i >= 0; i--)
#define FOR(i, m, n) for (int i = m; i < n; i++)
#define INF 2e9
#define ALL(v) v.begin(), v.end()
int x;
int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    cin >> x;
    ll sum=0;
    for(int i=1;;i++){
        sum+=i;
        if(sum>=x){
            cout << i << "\n";
            return 0;
        }
    }
}

Measured memory_bytes: 256
from fractions import gcd
N = int(input())
A = list(map(int,input().split()))
MOD = 10**9+7
 
def lcm(a,b):
  g = gcd(a, b)
  return a*b // g
 
l = 1
for a in A:
  l = lcm(l, a)
 
# print(l)
 
ans = 0
for a in A:
  ans += l//a
  # ans %= MOD
 
print(ans%MOD)

Measured memory_bytes: 77064
#include <bits/stdc++.h>
using namespace std;
using Graph = vector<vector<int>>;
#define rep(i,a,b) for (int i = (a); i < (b); i++ )
typedef pair<int,int> P;
typedef long long ll;
const int INF = 100000000;

int main() {

    ll N;
    cin >> N;

    ll ans = 10000000000000;
    ll y;
    ll x_max = (ll) sqrt(N);

    rep(x,1,x_max+1) {
        if (N%x==0) {
            y=N/x;
            ans = min(ans,x+y);            
        }
    }
    cout << ans-2 << endl;

 }



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

#define REP(i, n) for(int i = 0; i < n; i++)
#define REPR(i, n) for(int i = n; i >= 0; i--)
#define FOR(i, m, n) for(int i = m; i < n; i++)
#define ALL(obj) (obj).begin(), (obj).end()
#define INF 1e9
typedef long long ll;


int main() {
    int A,P;
    cin >> A >> P;
    cout << (A*3+P)/2 << endl;
    return 0;
}

Measured memory_bytes: 3532
#include <iostream>
#include <cstring>
#include <algorithm>

#define ll long long

using namespace std;

int h,w,x,y,dir;
long long l;
char c;
char ansdir[4] = {'E', 'N', 'W', 'S'};
bool f[102][102];
long long memo[102][102][4];
int dx[4] = {1,0,-1,0};
int dy[4] = {0,-1,0,1};

int main(){
    while(cin >> h >> w >> l){
        if((h|w|l) == 0) break;
        memset(f,false,sizeof(f));
        memset(memo,-1,sizeof(memo));
        for(int i=1;i<=h;i++){
            for(int j=1;j<=w;j++){
                cin >> c;
                if(c == '.'){
                    f[i][j] = true;
                }else if(c == '#'){
                    f[i][j] = false;
                }else{
                    f[i][j] = true;
                    y = i;
                    x = j;
                    if(c == 'E'){
                        dir = 0;
                    }else if(c == 'N'){
                        dir = 1;
                    }else if(c == 'W'){
                        dir = 2;
                    }else{
                        dir = 3;
                    }
                }
            }
        }
        long long t=0;
        memo[y][x][dir] = 0;
        while(t != l){
            //search
            int ndir;
            for(int i=0;i<4;i++){
                ndir = (dir - i + 4)%4;
                if(f[y+dy[ndir]][x+dx[ndir]]) break;
            }
            dir = ndir;
            y += dy[ndir];
            x += dx[ndir];
            t++;
            if(memo[y][x][dir] != -1){
                ll loop = t - memo[y][x][dir];
                ll left = l - t;
                ll div = left / loop;
                t += div * loop;
                memset(memo,-1,sizeof(memo));
            }else{
                memo[y][x][dir] = t;
            }
        }
        cout << y << " " << x << " " << ansdir[dir] << endl;
    }
}

Measured memory_bytes: 0
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N = 1e5+1;
int n,p[N],cnt[N*2],is[N];
int main()
{
	cin>>n;
	for(int i=1;i<=n;++i)cin>>p[i];
	for(int i=1;i<=n;++i)if(p[i]==i)is[i]=1;
	int ans=0,cnt=0;
	for(int i=1;i<=n;++i)
	{
		if(p[i]==i)cnt++;
		else
		{
			ans+=(cnt+1)/2;cnt=0;
		}
	}
	ans+=(cnt+1)/2;
	cout<<ans;
}

Measured memory_bytes: 1024
#include <iostream>
#include <fstream>
#include <cstdio>
#include <vector>
#include <map>
#include <unordered_map>
#include <set>
#include <unordered_set>
#include <stack>
#include <queue>
#include <algorithm>
#include <string.h>
#include <string>
#include <math.h>
#include <iomanip>
using namespace std;

#define SORT(v) sort((v).begin(), (v).end())
#define RSORT(v) sort((v).rbegin(), (v).rend())
#define pb push_back

typedef pair<int, int> pii;
typedef long long ll;
typedef unsigned long long ull;

const int mod = (int)1e9 + 7;
const int mod2 = 998244353;

ll exp(ll taban, ll us, ll md) {
    ll carpan = taban % md;
	if(carpan == 0) return 0;
    ll temp = us;
    ll res = 1;
    while(temp){
        if(temp % 2) res = (res*carpan) % md;
        temp /= 2;
        carpan = (carpan*carpan) % md;
    }
    return res;
}
 
ll ebob(ll a, ll b){
    if(!a)return b;
    return ebob(b%a, a);
}

ll ekok(ll a, ll b){
    return (a*b)/ebob(a, b);
}

ll mul(ll a, ll b, ll md){
	return a*b % md;
}

vector<ll> fact;
vector<ll> inv_fact;
void fact_init(int n){
	fact.resize(n+5);
	inv_fact.resize(n+5);
	fact[0] = inv_fact[0] = 1;
	for(int i = 1; i <= n; i++){
		fact[i] = (fact[i-1] * i) % mod;
		inv_fact[i] = exp(fact[i], mod-2, mod);
	}
}

ll komb(ll a, ll b){
	if(a < b) return 0;
	return fact[a] * (inv_fact[a-b] * inv_fact[b] % mod) % mod;
}

const int N = 1e5+5;

int main(){
	ios::sync_with_stdio(false); cin.tie(NULL);
	int x, n; cin>>x>>n;
	bool var[200] = {};
	for(int i = 0; i < n; i++){
		int s; cin>>s;
		var[s] = true;
	}
	int l = x, r = x;
	while(var[l] && var[r]){
		l--;
		r++;
	}
	int ans;
	if(!var[l]) ans = l;
	else ans = r;
	cout<<ans<<endl;
}

Measured memory_bytes: 3652
#include <bits/stdc++.h>
using namespace std;
int n, maxw;
int w[100], v[100];
long long dp[100][100005];
long long calc(int u, int weight)
{
    if(u == n-1) return maxw < weight + w[u] ? 0 : v[u];

    if(dp[u][weight] != -1)
        return dp[u][weight];

    dp[u][weight] = calc(u+1, weight);
    if(maxw >= weight + w[u]) dp[u][weight] = max(dp[u][weight], v[u] + calc(u+1, weight+w[u]));

    return dp[u][weight];
}

int main( )
{
    ios::sync_with_stdio(0);
    cin.tie(0);
    for (int i = 0; i < 100; ++i) {
        memset(dp[i], -1, sizeof(dp[i]));
    }
    cin >> n >> maxw;
    for (int i = 0; i < n; ++i) {
        cin >> w[i] >> v[i];
    }
    cout << calc(0, 0) << endl;
}

Measured memory_bytes: 78336
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
int main(){
    vector<int>t(3);
    for(int i=0; i<3; i++) cin >> t[i];
    sort(t.begin(),t.end());
    cout << t[0] << " " << t[1] << " " << t[2] << endl;
    return 0;
}


Measured memory_bytes: 3152
import java.util.Scanner;
public class Main {
	public static void main(String[] args){
		Scanner scan = new Scanner(System.in);
		int[] dice_num,dice_num0;
		dice_num = new int[10];
		dice_num0 = new int[10];
		int[] dice_s;
		dice_s = new int[10];
		int i,m;
		for(i = 0; i < 6; i++){
			dice_num0[i] = scan.nextInt();
		}
		int n = scan.nextInt();
		for(i = 0; i < n; i++){
			dice_num[0] = dice_num0[0];
			dice_num[1] = dice_num0[1];
			dice_num[2] = dice_num0[2];
			dice_num[3] = dice_num0[3];
			dice_num[4] = dice_num0[4];
			dice_num[5] = dice_num0[5];
			int dice1 = scan.nextInt();
			int dice2 = scan.nextInt();
			for(m = 0; m < 4; m++){
				if(dice_num[0] == dice1)
					break;
				else{
					dice_s[0] = dice_num[4];
					dice_s[1] = dice_num[0];
					dice_s[2] = dice_num[2];
					dice_s[3] = dice_num[3];
					dice_s[4] = dice_num[5];
					dice_s[5] = dice_num[1];
					dice_num[0] = dice_s[0];
					dice_num[1] = dice_s[1];
					dice_num[2] = dice_s[2];
					dice_num[3] = dice_s[3];
					dice_num[4] = dice_s[4];
					dice_num[5] = dice_s[5];
 				}
			}
			for(m = 0; m < 4; m++){
				if(dice_num[0] == dice1)
					break;
				else{
					dice_s[0] = dice_num[3];
					dice_s[1] = dice_num[1];
					dice_s[2] = dice_num[0];
					dice_s[3] = dice_num[5];
					dice_s[4] = dice_num[4];
					dice_s[5] = dice_num[2];
					dice_num[0] = dice_s[0];
					dice_num[1] = dice_s[1];
					dice_num[2] = dice_s[2];
					dice_num[3] = dice_s[3];
					dice_num[4] = dice_s[4];
					dice_num[5] = dice_s[5];
				}
			}
			for(m = 0; m < 4; m++){
				if(dice_num[1] == dice2)
					break;
				else{
					dice_s[0] = dice_num[0];
					dice_s[1] = dice_num[3];
					dice_s[2] = dice_num[1];
					dice_s[3] = dice_num[4];
					dice_s[4] = dice_num[2];
					dice_s[5] = dice_num[5];
					dice_num[0] = dice_s[0];
					dice_num[1] = dice_s[1];
					dice_num[2] = dice_s[2];
					dice_num[3] = dice_s[3];
					dice_num[4] = dice_s[4];
					dice_num[5] = dice_s[5];
			}
			}
				System.out.println(dice_num[2]);
		}
	}
}

Measured memory_bytes: 26048
#include <algorithm>
#include <cmath>
#include <deque>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <set>
#include <stack>
#include <string>
#include <vector>

using namespace std;
using LLONG = long long;
const LLONG MOD = 1000000007;
const double PI = 3.14159265359;

int main()
{
    int N, K; cin >> N >> K;
    vector<int> ps(N); for (auto &pi : ps) cin >> pi;
    sort(ps.begin(), ps.end());
    int ans = 0;
    for (int i = 0; i < K; ++i) ans += ps[i];
    cout << ans << endl;
}


Measured memory_bytes: 3628
#include<iostream>
#include<algorithm>
using namespace std;
int i[5];
int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  int a,b,c,d,e,f;
  cin >>a>>b;
  for(int n=b-a+1;n<b+a;n++){
    if(n!=b-a+1) cout <<' ';
    cout <<n;
  }
  cout <<'\n';
  return(0);
}


Measured memory_bytes: 256
#!/usr/bin/python3
# -*- coding: utf-8 -*-
h = int(input())
i = 0
count = 0
if h == 1:
    count = 1
else:
    while(True):
        if h % 2 == 0:
            h = h // 2
        else:
            h = h // 2
        count += 2 ** i
        i += 1
        if h == 1:
            break
    count += 2 ** i
print(count)

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

   ll x ,y ; ll sum =0 ,cont=0 ;
   cin >> x >>y ;
int a[x] ;
for(int i=0 ; i< x ; i++)
{
    cin >> a[i] ;
}
for (int i=0 ; i<x;i++)
{
  sum+=a[i] ;
  if(sum<=y){cont ++ ;}

}
cout <<cont +1 <<endl ;

    return 0 ;
}


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

signed main(void){
    int n,k; cin >> n >> k;
    vector<P>p;
    for(int i=0;i<n;i++){
        int a,b; cin >> a >> b;
        p.push_back(P{a,b});
    }
    sort(p.begin(),p.end());
    for(int i=0;i<p.size();i++){
        k -= p[i].second;
        if(k<=0){
            cout << p[i].first << endl;
            break;
        } 
    }
    return 0;
}



Measured memory_bytes: 2420
#include <algorithm>
#include <iostream>
#include <vector>
#include <string>
#include <iomanip>

using namespace std;

int main() {
    int n;
    cin >> n;
    vector<pair<int, int> > a(n);
    for (int i = 0; i < n; ++i) {
        int x;
        cin >> x;
        a[i] = {x, i};
    }
    sort(a.begin(), a.end());
    for (auto x : a)
        cout << x.second + 1<< ' ';
    cout << '\n';
    return 0;
}


Measured memory_bytes: 1536
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.Arrays;
import java.util.StringTokenizer;

/**
 * Problem A: Sleeping Cats
 */
public class Main {

	public static void main(String[] args) throws IOException {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		String line = "";

		StringBuilder sb = new StringBuilder();
		while (!(line = br.readLine()).equals("0 0")) {
			int l = Integer.parseInt(line.substring(0, line.indexOf(' ')));
			int q = Integer.parseInt(line.substring(line.indexOf(' ') + 1));

			int[] wall = new int[l];
			Arrays.fill(wall, -1);

			StringTokenizer st;
			int c, w, s;
			for (int i = 0; i < q; i++) {
				st = new StringTokenizer(br.readLine());
				if (st.nextToken().equals("s")) {
					c = Integer.parseInt(st.nextToken());
					w = Integer.parseInt(st.nextToken());
					s = sleep(c, w, wall);
					if (s > -1) {
						sb.append(s + "\n");
					} else {
						sb.append("impossible\n");
					}
				} else {
					c = Integer.parseInt(st.nextToken());
					wakeup(c, wall);
				}
			}
			sb.append("END\n");
		}
		System.out.print(sb.toString());
	}

	static int sleep(int cat, int width, int[] wall) {
		int begin = -1;
		int space = 0;
		for (int i = 0; i < wall.length; i++) {
			if (wall[i] == -1) {
				space++;
				if (space == 1)
					begin = i;
				if (space == width)
					break;
			} else {
				space = 0;
				begin = -1;
			}
		}
		if (space == width) {
			for (int i = 0; i < width; i++) {
				wall[begin + i] = cat;
			}
		} else {
			begin = -1;
		}
		return begin;
	}

	static void wakeup(int cat, int[] wall) {
		for (int i = 0; i < wall.length; i++) {
			if (wall[i] == cat)
				wall[i] = -1;
		}
	}
}

Measured memory_bytes: 17072
#include<bits/stdc++.h>
using namespace std;
#define endl "\n"
#define int ll
typedef long long ll;
const int N=2e5+5;
ll ma[N*4];
int n,q;

void update(int l,int r,int id,int i,int v){
    if(l==r){
        ma[id]=v;
        return;
    }
    int mid=(l+r)>>1;
    ma[id]=0;
    if(i<=mid)update(l,mid,id*2,i,v);
    else update(mid+1,r,id*2+1,i,v);
    ma[id]=max(ma[id*2],ma[id*2+1]);
}

ll query_mi(int l,int r,int ql,int v,int id){
    if(l==r){
        if(ma[id]>=v)return l;
        else return -1;
    }
    int mid=(l+r)>>1;
    int ans=-1;
    int good=0;
    if(ql<=mid)ans=query_mi(l,mid,ql,v,id*2);
    if(ans!=-1)return ans;
    ans=query_mi(mid+1,r,ql,v,id*2+1);
    return ans;
}
//vector<int> a;
/*
ll mi(int x,int v){
    for(int i=x;i<=n;i++){
        if(a[i]>=v)return i;
    }
    return n+1;
}
*/
ll query_ma(int l,int r,int ql,int qr,int id){
    if(l>=ql&&r<=qr)return ma[id];
    int mid=(l+r)>>1;
    int a=0,b=0;
    if(ql<=mid)a=query_ma(l,mid,ql,qr,id*2);
    if(qr>mid)b=query_ma(mid+1,r,ql,qr,id*2+1);
    return max(a,b);
}


signed main(){
    ios_base::sync_with_stdio(0);cout.tie(0);cin.tie(0);

    cin>>n>>q;
    //a.resize(n+1);
    for(int i=1;i<=n;i++){
        int x;cin>>x;
        //a[i]=x;
        update(1,n,1,i,x);
    }
    while(q--){
        int mode,x,y;cin>>mode>>x>>y;
        if(mode==1){
            update(1,n,1,x,y);
            //a[x]=y;
        }
        else if(mode==2){
            cout<<query_ma(1,n,x,y,1)<<endl;
        }
        else if(mode==3){

            ll ans=query_mi(1,n,x,y,1);
            if(ans==-1)cout<<n+1<<endl;
            else cout<<ans<<endl;

            //cout<<mi(x,y)<<endl;
        }
    }
}


Measured memory_bytes: 7752
#include<stdio.h>
int main(void){
   int h[10], a[10], i;
   scanf("%d", &h[1]);
   while ( h[1] ) {
      for ( i = 1; i <= 3; i++ ) a[i] = 0;
      scanf("%d %d %d %d", &h[2], &h[3], &h[4], &h[5]);
      for ( i = 1; i <= 5; i++ ) {
         a[h[i]]++;
      }
      if ( a[1] != 0 && a[2] != 0 && a[3] == 0 ) {
         for ( i = 1; i <= 5; i++ ) {
            if ( h[i] == 1 ) printf("1\n");
            else printf("2\n");
         }
      }
      else if ( a[1] == 0 && a[2] != 0 && a[3] != 0 ) {
         for ( i = 1; i <= 5; i++ ) {
            if ( h[i] == 2 ) printf("1\n");
            else printf("2\n");
         }
      }
      else if ( a[1] != 0 && a[2] == 0 && a[3] != 0 ) {
         for ( i = 1; i <= 5; i++ ) {
            if ( h[i] == 3 ) printf("1\n");
            else printf("2\n");
         }
      }
      else {
         for ( i = 1; i <= 5; i++ ) printf("3\n");
      }
      scanf("%d", &h[1]);
   }
   return 0;
}

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

using namespace std;

using ll = long long;

struct Graph {
    const int n;
    std::vector<std::vector<int>> adj;
    std::vector<int> ord, low;
    std::vector<std::pair<int, int>> bridge;

    Graph(int _n) : n(_n), adj(n), ord(n, -1), low(n, -1) {}

    void add_edge(int u, int v) { adj[u].push_back(v); adj[v].push_back(u); }

    int Bridge() {
        for (int v = 0, idx = 0; v < n; ++v)
            if (ord[v] == -1) Dfs(-1, v, idx);

        for (int v = 0; v < n; ++v)
            for (int u : adj[v])
                if (ord[v] < low[u])
                    bridge.push_back({v, u});
        return bridge.size();
    }

    void Dfs(const int prev, const int cur, int &idx) {
        low[cur] = ord[cur] = idx++;
        for (int v : adj[cur]) {
            if (ord[v] == -1) {
                Dfs(cur, v, idx);
                low[cur] = std::min(low[cur], low[v]);
            }
            else if (v != prev) low[cur] = std::min(low[cur], ord[v]);
        }
    }
};

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

    int n, m;
    cin >> n >> m;
    Graph g(n);
    for (int i = 0; i < m; ++i) {
        int v[2];
        cin >> v[0] >> v[1];
        g.add_edge(v[0] - 1, v[1] - 1);
    }

    cout << g.Bridge() << endl;

    return 0;
}


Measured memory_bytes: 256
let cnt = ref 0

let merge a l m r =
  let init_ary n p =
    let ret = Array.make (n + 1) max_int in
    for i = 0 to n - 1 do
      ret.(i) <- a.(p + i)
    done;
    ret in
  let ai = init_ary (m - l) l in
  let aj = init_ary (r - m) m in
  let rec doit = function
    | (_, _, k) when k = r -> ()
    | (i, j, k) ->
      incr cnt;
      if ai.(i) <= aj.(j) then begin
        a.(k) <- ai.(i);
        doit (i + 1, j, k + 1)
      end else begin
        a.(k) <- aj.(j);
        doit (i, j + 1, k + 1)
      end in
  doit (0, 0, l)

let rec merge_sort a l r =
  if (l + 1) < r then begin
    let m = (l + r) / 2 in
    merge_sort a l m;
    merge_sort a m r;
    merge a l m r
  end

let () =
  let n = read_int () in
  let a = Array.init n (fun _ -> Scanf.scanf "%d " (fun i -> i)) in
  merge_sort a 0 n;
  print_int a.(0);
  for i = 1 to n - 1 do
    print_string " ";
    print_int a.(i);
  done;
  print_newline ();
  print_int !cnt;
  print_newline ()

Measured memory_bytes: 19416
# by the authority of GOD   author: manhar singh sachdev #

import os,sys
from io import BytesIO, IOBase

def main():
    mod = 10**9+7
    n = int(input())
    arr = list(map(int,input().split()))
    lst = [arr[-1]]
    for i in range(n-2,-1,-1):
        lst.append(lst[-1]+arr[i])
    ans = 0
    for i in range(n-1):
        ans += (arr[i]*lst[-i-2])%mod
        ans %= mod
    print(ans)

#Fast IO Region
BUFSIZE = 8192
class FastIO(IOBase):
    newlines = 0
    def __init__(self, file):
        self._fd = file.fileno()
        self.buffer = BytesIO()
        self.writable = "x" in file.mode or "r" not in file.mode
        self.write = self.buffer.write if self.writable else None
    def read(self):
        while True:
            b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
            if not b:
                break
            ptr = self.buffer.tell()
            self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
        self.newlines = 0
        return self.buffer.read()
    def readline(self):
        while self.newlines == 0:
            b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
            self.newlines = b.count(b"\n") + (not b)
            ptr = self.buffer.tell()
            self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
        self.newlines -= 1
        return self.buffer.readline()
    def flush(self):
        if self.writable:
            os.write(self._fd, self.buffer.getvalue())
            self.buffer.truncate(0), self.buffer.seek(0)
class IOWrapper(IOBase):
    def __init__(self, file):
        self.buffer = FastIO(file)
        self.flush = self.buffer.flush
        self.writable = self.buffer.writable
        self.write = lambda s: self.buffer.write(s.encode("ascii"))
        self.read = lambda: self.buffer.read().decode("ascii")
        self.readline = lambda: self.buffer.readline().decode("ascii")
sys.stdin, sys.stdout = IOWrapper(sys.stdin), IOWrapper(sys.stdout)
input = lambda: sys.stdin.readline().rstrip("\r\n")

if __name__ == '__main__':
    main()

Measured memory_bytes: 100528
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <climits>
#include <cmath>
#include <complex>
#include <map>
#include <set>
#include <vector>
#include <stack>
#include <queue>
#include <bitset>
#include <algorithm>
#include <numeric>
#include <functional>
#include <cassert>
#include <iomanip>
using namespace std;

#define Rep(b, e, i) for(int i = b; i <= e; i++)
#define Repr(e, b, i) for(int i = e; i >= b; i--)
#define rep(n, i) Rep(0, n-1, i)
#define repr(n, i) Repr(n-1, 0, i)
#define all(v) (v).begin(), (v).end()
#define pb(v) push_back(v)
#define uniq(v) (v).erase(unique(all(v)),(v).end())
#define bitcnt(x) __builtin_popcount(x)
#define fst first
#define snd second
#define Pqaz(T) priority_queue<T,vector<T>,greater<T>>
#define Pqza(T) priority_queue<T>
#define put(x) cout << x;
#define putsp(x) cout << x << ' ';
#define putln(x) cout << x << endl;
#define ENJYU std::ios::sync_with_stdio(false);std::cin.tie(0);

typedef long long ll;
typedef pair<ll, ll> llP;
typedef pair<int, int> intP;
typedef complex<double> comp;
typedef vector <int> vec;
typedef vector <ll> vecll;
typedef vector <double> vecd;
typedef vector <vec> mat;
typedef vector <vecll> matll;
typedef vector <vecd> matd;

//vector の中身を出力
template <class T>ostream &operator<<(ostream &o,const vector<T>&v)
{o<<"{";for(int i=0;i<(int)v.size();i++)o<<(i>0?", ":"")<<v[i];o<<"}";return o;}

const int MAX = 200000;
const double PI = 3.14159265358979323846;
const double EPS = 1e-12;
const int INF = 1<<29;
const ll INFL = 1e18;
const int MOD = 1000000007;

int dx4[4]={1,0,-1,0};
int dy4[4]={0,1,0,-1};
int dx8[8]={1,0,-1,1,-1,1,0,-1};
int dy8[8]={1,1,1,0,0,-1,-1,-1};

//************************************************************************//

struct Dijkstra
{
	//距離の型を決めよう！！！！！！！！！！！！！
	typedef ll dType;
	typedef pair<dType, int> P;

	struct edge{int to; dType cost;};

	//始点からの距離
	vector <dType> dis;
	//隣接リスト
	vector <vector <edge>> adj;

	Dijkstra(int N) : dis(N, INFL), adj(N){}

	void add_edge(int s, int t, dType cost, bool isdirected = 0)
	{
		adj[s].pb((edge{t, cost}));
		if (!isdirected)
		{
			adj[t].pb((edge{s, cost}));
		}
	}

	void calc(int s)
	{
		dis[s] = 0;
		priority_queue<P, vector<P>, greater<P>> q;

		q.push(P(0, s));

		while(!q.empty())
		{
			P p = q.top(); q.pop();
			int now = p.snd;
			if (dis[now] < p.fst)
			{
				continue;
			}
			for (edge e : adj[now])
			{
				if (dis[e.to] > dis[now] + e.cost)
				{
					dis[e.to] = dis[now] + e.cost;
					q.push(P(dis[e.to], e.to));
				}
			}
		}
	}

};



//************************************************************************//

//********************************template END****************************************//

//aoj 単一始点最短経路
void solve(void){

	int V, E, r;
	cin >> V >> E >> r;

	Dijkstra dijkstra(V);

	while(E--)
	{
		int s, g; ll c;
		cin >> s >> g >> c;
		dijkstra.add_edge(s, g, c, 1);
	}
	dijkstra.calc(r);
	rep(V, i)
	{
		ll dis = dijkstra.dis[i];
		if (dis == INFL)
		{
			cout << "INF" << endl;
		}
		else
		{
			cout << dis << endl;
		}
	}
}

int main(void){
	solve();
	//cout << "yui(*-v・)yui" << endl;
	return 0;
}



Measured memory_bytes: 19388
#include <stdio.h>

int main()
{
    int a, x, k = 100000000, g = -100000000;
    long long sum = 0;
    scanf("%d\n", &a);
    for (int i = 0; i < a; i++)
    {
        scanf("%d", &x);
        sum = sum + x;
  
        if (x < k)
            k = x;

        if (x > g)
            g = x;
    }

    printf("%d %d %lli\n", k, g, sum);

    return 0;
}


Measured memory_bytes: 2108