akhauriyash/Code-Regression huggingface dataset:
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        let mut next = || { iter.next().unwrap() };
        input_inner!{next, $($r)*}
    };
    ($($r:tt)*) => {
        let stdin = std::io::stdin();
        let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));
        let mut next = move || -> String{
            bytes
                .by_ref()
                .map(|r|r.unwrap() as char)
                .skip_while(|c|c.is_whitespace())
                .take_while(|c|!c.is_whitespace())
                .collect()
        };
        input_inner!{next, $($r)*}
    };
}

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

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

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

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

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

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

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

fn main() {
    input!{
        n: usize,
        m: usize,
    }
 
    println!("{}", (n + m - 1)/ m);
}

Measured memory_bytes: 4352
def gcd(a, b):
    a, b = max(a, b), min(a, b)
    while a % b > 0: a, b = b, a % b
    return b

def solve():
    N = int(input())
    ans = []
    if N == 3: ans = [2, 5, 63]
    elif N == 4: ans = [2, 5, 20, 63]
    elif N == 5: ans = [2, 5, 20, 30, 63]
    else:
        count = [0, 0, 0, 0]
        for i in range(N // 4):
            ans.append(6 * i + 2)
            ans.append(6 * i + 3)
            ans.append(6 * i + 4)
            ans.append(6 * i + 6)
            count[0] += 1
            count[1] += 1
            count[2] += 1
            count[3] += 1
        mod = [2, 3, 4, 6]
        for j in range(N % 4):
            ans.append(6 * (N // 4) + mod[j])
            count[j] += 1
        total = sum(ans)
        if total % 6 == 2:
            ans[4] = 6 * count[3] + 6
        elif total % 6 == 3:
            ans[5] = 6 * count[3] + 6
        elif total % 6 == 5:
            ans[5] = 6 * count[2] + 4
    print(" ".join(map(str, ans)))
    return

if __name__ == "__main__":
    solve()

Measured memory_bytes: 5220
#include <bits/stdc++.h>
#define int long long

#define rng(i, l, r) for (size_t i = (l); i < (r); ++i)
#define rep(i, n) rng(i, 0, n)
#define gnr(i, l, r) for (size_t i = (r)-1; i >= (l); i--)
#define per(i, b) gnr(i, 0, b)
#define ALL(obj) (obj).begin(), (obj).end()    //1,2,3,...
#define rALL(obj) (obj).rbegin(), (obj).rend() //...,3,2,1

using namespace std;

const int INF = 1e18;

void solve()
{

    // remove the bottom 3 lines when you submit this code.
    std::ifstream in("sample.txt");
    std::cin.rdbuf(in.rdbuf());

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

    int x, n;
    cin >> x >> n;
    vector<int> p(n);
    rep(i, n) cin >> p[i];

    int tmp = INF;
    int ans = INF;
    for (int i = -100; i < 200; i++)
    {
        bool isExist = false;
        for (int j = 0; j < n; j++)
        {
            if (p[j] == i)
                isExist = true;
        }
        if (isExist)
            continue;

        if (abs(x - i) < tmp)
        {
            tmp = abs(x - i);
            ans = i;
        }
    }

    cout << ans << endl;
}

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


Measured memory_bytes: 3628
S = gets.chomp
N = S.chars.size - 1
A = 1.step(N).to_a

ans = []
1.step(N) do |n|
  ans.push(*A.combination(n).to_a)
end
ans.map! do |a|
  s = S.dup
  a.reverse_each {|i| s.insert(i,'+') }
  eval(s)
end
p S.to_i + (N==0 ? 0 : ans.inject(:+))


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

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

//Binary Indexed Tree
//1-indexed
class RAQ{
public:
    explicit RAQ(int n):size(n),init(0){//初期値が0のとき-> v[1]=v[2]=...=v[n]=0
        tbl.resize(static_cast<unsigned long>(size + 10),0);
    }
    RAQ(int n,int first):size(n),init(first){//初期値が0以外->v[1]=v[2]=...v[n]=first
        tbl.resize(static_cast<unsigned long>(size + 10), 0);
    }
    void add(int l,int r,int w){//v[l...r]+=w , 1-indexed
        add(l,w);
        add(r+1,-w);
    }
    ll sum(int a){//v[1]+...+v[a]
        ll res=0;
        for(int i=a;i>0;i-=i&-i)res+=tbl[i];
        return res+a*init;
    }
private:
    vector<ll> tbl;
    int size;
    int init=0;
    void add(int a,ll w){
        for(int i=a;i<=size;i+=i&-i)tbl[i]+=w;
    }
};

int main(){
    int n,q;cin>>n>>q;
    RAQ bit(n);
    for(int i=0;i<q;i++){
        int a;cin>>a;
        if(a==0){
            int s,t,x;cin>>s>>t>>x;
            bit.add(s,t,x);
        }else{
            int b;cin>>b;
            cout<<bit.sum(b)<<endl;
        }
    }
    return 0;
}


Measured memory_bytes: 3628
#!/usr/bin/env python3
import sys, math, itertools, collections, bisect
input = lambda: sys.stdin.buffer.readline().rstrip().decode('utf-8')
inf = float('inf') ;mod = 10**9+7
mans = inf ;ans = 0 ;count = 0 ;pro = 1

n,D,A=map(int,input().split())
XH=[tuple(map(int,input().split())) for i in range(n)]
XH.sort()
x=[];h=[]
for xi,hi in XH:
    x.append(xi); h.append(hi)
x.append(inf); h.append(0)
data=[0]*(n+1)
for  i in range(n):
    xi=x[i]; hi=h[i]
    hi-=data[i]
    K=max(0,(A+hi-1)//A); count += K
    data[i]+=K*A
    data[bisect.bisect_left(x,xi+2*D+1)]-=K*A
    data[i+1]+=data[i]
print(count)


Measured memory_bytes: 104284
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
const int INF = 1e9;
const ll mod = 1e9 + 7;

int main(){
    int k, n;
    cin >> k >> n;
    vector<int> a(n+1);
    rep(i,n) cin >> a[i];
    a[n] = k + a[0];
    vector<int> dist(n);
    rep(i,n) {
        dist[i] = a[i+1] - a[i]; 
    }
    sort(dist.rbegin(), dist.rend());
    int ans = k - dist[0];
    cout << ans << endl;
}

Measured memory_bytes: 1792
/*
 *
 *   Author     : Amit Kumar
 *   Date    	: August 10
 * 
 */

#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <ctime>
#include <memory.h>
#include <cassert>
#define FAST_INPUT_OUTPUT
//#define MORE_THAN_ONE_TESTCASE // COMMENT IT

#define vi vector<int>
#define vl vector<long long>
#define mii map<int , int>
#define mll map<long long , long long>
#define msi map<string , i>
#define msl map<string , long long>
#define umii unordered_map<int,int>
#define umll unordered_map<long long ,long long>
#define umsi unordered_map<string , int>
#define umsl map<string , long long> 
#define si set<int>
#define sl set<long long>
#define pii pair<int , int >
#define psi pair<string,int>
#define psl pair<string , long > 
#define pll pair<long long , long long>
#define vpii vector<pii>
#define vpll vector<pll>
#define vpsi vector<psi>
#define vpsl vector<psl>
#define pqi priority_queue<int>
#define pql priority_queue<long long>
#define ub upper_bound
#define lb lower_bound
#define bint long long int
#define ff first
#define ss second
#define all(x) x.begin(),x.end()
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define iv(v) for(auto &i:v){cin>>i;}
#define ov(v) for(auto i:v){cout<<i<<" ";}cout<<endl;
#define ovn(v) for(auto i:v){cout<<i<<endl;}
#define euv(v) for(auto i:v){cerr<<i<<" ";}cerr<<endl;
#define eovn(v) for(auto i:v){cerr<<i<<endl;}
#define os(s) for(auto itr:s){cout<<itr<<" ";}cout<<endl;
#define osn(s) for(auto itr:s){cout<<itr<<endl;}
#define eos(s) for(auto itr:s){cerr<<itr<<" ";}cerr<<endl;
#define eosn(s) for(auto itr:s){cerr<<itr<<endl;}
#define rep(x) for(auto i=0 ; i<(x); ++i)
#define _rep(a,b) for(auto i=(a); i<(b); ++i)
#define ef else if
#define wh while
#define el else
#define ivv(x) int x; cin>>x
#define lv(x) bint x; cin>>x
#define sv(x) string x; cin>>x
#define cv(x) char x; cin>>x
#define fv(x) float x; cin>>x
#define dv(x) double x; cin>>x
#define endl '\n'
using namespace std;




auto SOLUTION_FUNCTION( void ) ->void {

    // your solution goes here 

    ivv(n);
    ivv(x);
    for(int i=x-n+1;i<x+n;i++){
        cout<<i<<" ";
    }
    puts("");


    return ;
}




int main(void){
#ifdef FAST_INPUT_OUTPUT
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cout.tie(nullptr);
    cout<<setprecision(10);
    cout<<fixed;
    cout<<boolalpha;
#endif
#ifdef MY_LOCAL_PROJECT
    freopen("input","r",stdin);
    freopen("output","w",stdout);
#endif
    int testcase = 1;


#ifdef MORE_THAN_ONE_TESTCASE
    cin>>testcase;
#endif
    
    while(testcase--){
        SOLUTION_FUNCTION();
    }

#ifdef MY_LOCAL_PROJECT
    cout<<"Time : "<<1.0*(double)clock()/CLOCKS_PER_SEC<<endl;
#endif
    return 0;
}

Measured memory_bytes: 256
#include "bits/stdc++.h"
#define LF '\n'
#define ALL(x) x.begin(), x.end()
#define iostreamBooster() { cin.tie(nullptr); ios_base::sync_with_stdio(false); }
using namespace std;
typedef int64_t i64;
typedef pair<int,int> pii;
template<class A, class B>inline bool chmax(A &a, const B &b){return b>a ? a=b,1 : 0;}
template<class A, class B>inline bool chmin(A &a, const B &b){return b<a ? a=b,1 : 0;}
constexpr int INF = 0x3f3f3f3f;
template<class Itr> void dump(Itr begin, Itr end) { for (;begin != end; ++begin) clog << *begin << LF; }

signed main()
{
  int a, b;
  cin >> a >> b;
  a += b;

  cout << ((a+1) / 2) << LF;

  return 0;
}



Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <list>
#include <map>
#include <queue>
#include <stack>
#include <algorithm>
#include <fstream>
#include <sstream>
#include <iomanip>

using namespace std;

long long MOD = 1000000007;

int main(){
    int N;
    cin >> N;
    cout << N*N*N << endl;
}

Measured memory_bytes: 256
N, A, B, C, D = map(int, input().split())
S = input()
# print((A-B)*(C-D))

if (A-B)*(C-D) >= 1:  # A>BかつC>D もしくは A<BかつC<D
    if S[min(A, B)-1:max(C, D)].find('##') == -1:
        print('Yes')
    else:
        print('No')
else:
    # print(S[max(A, B)-2:min(C, D)+1])
    if S[min(A, B)-1:max(C, D)].find('##') == -1 and S[max(A, B)-2:min(C, D)+1].find('...') >= 0:
        print('Yes')
    else:
        print('No')


Measured memory_bytes: 40560
#include<bits/stdc++.h>
#include<time.h>
#include<stdlib.h>
#pragma GCC optimize("Ofast")
#pragma GCC optimize("unroll-loops")
#pragma GCC target("sse4")
#define pb push_back
#define mp make_pair
#define IOS ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define ll long long
#define pll pair<ll,ll>
#define vll vector<ll,ll>
#define all(a) (a).begin(),(a).end()
#define ff first
#define ss second
#define sz(x) (ll)x.size()
#define hell 1000000007
#define repf(i,a,b) for(ll i=a;i<b;i++)
#define repb(i,a,b) for(ll i=a;i>b;i--)
#define lbnd lower_bound
#define ubnd upper_bound
#define bs binary_search
#define gcd(a,b) __gcd((a),(b))
#define EPS 1e-12
#define lcm(a,b) ((a)*(b))/__gcd((a),(b))
#define sqrt sqrtl
#define cbrt cbrtl
using namespace std;
ll n,k,ans;
vector<ll> a;
ll dp[100][100][105];
ll solve(ll ss,ll se,ll cnt)
{
   if(cnt>k)
    return -1e18;
   if(cnt==k||ss>se)
      return 0;
   if(dp[ss][se][cnt]!=-1)
    return dp[ss][se][cnt];
   ll val=0;
   if(a[ss]>=0)
    val=max(val,a[ss]+solve(ss+1,se,cnt+1));
   else
   {
      val=max(val,a[ss]+solve(ss+1,se,cnt+1));
      val=max(val,solve(ss+1,se,cnt+2));
   }
  if(a[se]>=0)
    val=max(val,a[se]+solve(ss,se-1,cnt+1));
   else
   {
    val=max(val,a[se]+solve(ss,se-1,cnt+1));
    val=max(val,solve(ss,se-1,cnt+2));
   }
   dp[ss][se][cnt]=val;  
   return val;
}
int main()
{
  IOS
  cin>>n>>k;
  ll i,x;
  for(i=0;i<n;i++)
  {
    cin>>x;
    a.pb(x);
  }
  memset(dp,-1,sizeof(dp));
  cout<<max(0LL,solve(0,n-1,0));
 // cout<<ans;
//  cout<<ans;
  return 0;
}

Measured memory_bytes: 8448
#include <algorithm>
#include <array>
#include <cassert>
#include <cmath>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <string>
#include <utility>
#include <vector>

using namespace std;
using ll = long long;

constexpr ll infl = 1000000000000000007LL;
constexpr int inf = 1000000007;

int main() {
    int n; cin >> n;
    map<string, int> mp;
    int m = 0;
    for (int i = 0; i < n; ++i) {
        string s; cin >> s;
        ++mp[s];
        m = max(m, mp[s]);
    }
    for (auto v : mp) {
        if (v.second == m) cout << v.first << endl;
    }
    return 0;
}

Measured memory_bytes: 25216
#include<stdio.h>
#include<iostream>
#include<math.h>
#include<string.h>
#include <algorithm>
#include<time.h>
#include <numeric>
#include <vector> 
#include <functional>
#include <list>
#include <ctype.h>
#include<map>
#include <set>
#define N 105
using namespace std;
int main(){
	int n,c=0,a[N];
	scanf("%d",&n);
	for(int i=1;i<=n;i++){
		scanf("%d",&a[i]);
	}
	for(int i=1;i<=n;i=i+2){
		if(a[i]%2==1) c++;
	}
	printf("%d",c);
	
}

Measured memory_bytes: 3824
# coding: utf-8
import math
#n, k, s = map(int,input().split())
n = int(input())
A = list(map(int,input().split()))
ans = 0
MOD=10**9+7
L0 = [0] * 60
L1 = [0] * 60
for i in range(n):
    b = A[i]
    #print(b)
    b = format(b, '060b')
    #print(b)
    for j in range(60):
        if b[60 - j  -1] == "1":
            L1[j] += 1
        else:
            L0[j] += 1
#print(L0)
#print(L1)

for i in range(60):
    ans += L0[i] * L1[i] * 2**i
    ans %= MOD
print(ans)

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

int main(void) {
	int N;
	cin >> N;
	long long sum = 0;
	for (int i = 1; i <= N; i++) {
		if (i % 3 != 0 && i % 5 != 0)
			sum += i;
	}
	cout << sum << endl;
	return 0;
}

Measured memory_bytes: 3572
import os
import sys

if os.getenv("LOCAL"):
    sys.stdin = open("_in.txt", "r")

sys.setrecursionlimit(10 ** 9)
INF = float("inf")
IINF = 10 ** 18
MOD = 10 ** 9 + 7
# MOD = 998244353

N = int(sys.stdin.buffer.readline())


def test():
    ret = 1
    for i in range(2, N + 1, 2):
        ret *= i
    r = 0
    while ret % 10 == 0:
        ret //= 10
        r += 1
    print(r)


def count(c):
    # n 以下の c の倍数が何個あるか
    return N // c


if N & 1:
    print(0)
    exit()
# n 以下の偶数の総乗
ans = 0
c = 10
while c <= N:
    ans += count(c)
    c *= 5
print(ans)


Measured memory_bytes: 3064
#include <bits/stdc++.h>
#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 FORR(i, m, n) for(int i = m;i >= n;i--)
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
#define RVSORT(v) sort(v.rbegin(), v.rend());
#define ll long long
#define pb(a) push_back(a)
#define INF 999999999
#define MOD 1000000007
using namespace std;
typedef pair<int, int> P;
typedef pair<ll, ll> LP;
typedef pair<int, P> PP;
typedef pair<ll, LP> LPP;

int dy[]={0, 0, 1, -1};
int dx[]={1, -1, 0, 0};

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

ll modpow(ll n,ll k){
  if(k == 1){
    return n;
  }else if(k == 0){
    return 1;
  }else if(k%2==0){
    ll memo = modpow(n,k/2)%MOD;
    return memo*memo%MOD;
  }else{
    return n * modpow(n,k-1)%MOD;
  }
}

string strSort(string s){
  REP(i,s.size()){
    char c = s[i];
    int num = i;
    for(int j = i+1;j<s.size();j++){
      if((s[j]-c)<0){
        c = s[j];
        num = j;
      }
    }
    s[num] = s[i];
    s[i] = c;
  }
  return s;
}


int main(){


  ll n;
  cin>>n;
  vector<string> v;

  REP(i,n){
    string str;
    cin>>str;
    v.pb(strSort(str));
  }

  VSORT(v);

  string now = v[0];
  ll count = 1;
  ll ans = 0;
  for(int i=1;i<n;i++){
    if(v[i]!=now){
      ans += count * (count-1) /2;
      count = 1;
      now = v[i];
    }else{
      count++;
    }
  }

  ans += count * (count-1) / 2;

  cout<<ans<<endl;



 

  return 0;
}

Measured memory_bytes: 5748
#include<bits/stdc++.h>
#define pi 3.1415926535897932384626
using namespace std;
      
struct P{
  int x,y;
  bool operator < (const P &a )const{
    //if(y!=a.y)
    return y>a.y;
  };
};

int a,b,c,d,i,k,n,m,e,dx[10]={1,0,-1,0,1,1,-1,-1},dy[10]={0,1,0,-1,1,-1,1,-1};
int o[100101];
long long l[310105];
int j[1];

long long x,y,z,mod=1000000007;
//string r;
char r[1];

P u[1];
queue<int> q;

//stack<int> s;
set<int> s;
map<int,int> p;
vector<P> v;

bool as(P a,P b)
{
  if(a.x==b.x)
  return a.y<b.y;
  return a.x<b.x;
}

long long f(int n,int m)
{
  long long x=0;
  for(;n<m;)
  {
    if(n%2) x+=l[n++];
    else if(m%2==0) x+=l[m--];
    else n/=2,m/=2;
  }
  return x+l[n];
}

int main()
{
  scanf("%d %d %d %d",&a,&b,&c,&d);
  for(int t=1;t<=a;t++)
  scanf("%d",&o[t]);
  sort(o+1,o+a+1);
  reverse(o+1,o+a+1);
  for(i=1;i<a;i*=2);
  for(int t=1;t<=a;t++)
    l[t+i-1]=o[t];
  for(int t=i-1;t;l[t]=l[t*2]+l[t*2+1],t--);
  for(int t=1;t<=a;t++)
  {
    if(!p[o[t]]) p[o[t]]=t;
    if(p[o[t]]<=d) k++;
    else
    {
      if(c<=d-1+(a-p[o[t]]+1)&&b>=o[d]-o[t]) k++;
      else if(c>d-1+(a-p[o[t]]+1)&&max(f(d+i-1,p[o[t]]+i-2)+(long long)(c-(d-1+(a-p[o[t]]+1)))*b,(long long)max(o[d],0)*(p[o[t]]-d))<=(long long)(o[t]+b)*(p[o[t]]-d))
      {
        //printf("***%d %d %lld %d\n",c,d-1+(a-p[o[t]]+1),f(d+i-1,p[o[t]]+i-2)+(long long)(c-(d-1+(a-p[o[t]]+1)))*b,(o[t]+b)*(p[o[t]]-d));
        k++;
      }
      
    }
    //printf("%d %d\n",o[t],k);
  }
  printf("%d",k);
}



Measured memory_bytes: 7168
#include<iostream>
#include<algorithm>
#include<vector>
#include<cmath>
#include<utility>
#include<cstdio>
#include<set>
#include<string>
#include<map>
#include<queue>
#include<stack>
using namespace std;
#define rep(i,x,n) for(int i=x;i<n;i++)
using ll=long long;
typedef pair<int,int> P;
string s;



int main(){
    int n,m;cin>>n>>m;
    int a[n];
    int sum=0;
    rep(i,0,n) {
        cin>>a[i];
        sum+=a[i];
    }
    sort(a,a+n,greater<int>());
    if(a[m-1]<sum*1.0/(double)(4*m)) cout<<"No"<<endl;
    else cout<<"Yes"<<endl;

}    

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

#define rep(i,j,n) for(int i=(j);i<(n);i++)
#define erep(i,j,n) for(int i=(j);i<=(n);i++)
#define all(i) i.begin(),i.end()
#define rall(i) i.rbegin(),i.rend()
#define INF 1e9
const int mod = 1e9+7;

typedef vector<int> vi;
typedef vector<string> vs;
typedef vector<vi> vvi;
typedef pair<int, int> pi;
typedef long long i64;

template <class Monoid, class T = Monoid> struct LazySegmentTree {
  using F = function<Monoid(Monoid, Monoid)>;

  int n;
  vector<T> node, lazy;
  vector<bool> lazyFlag; // 区間更新

  const F f;
  const Monoid M1;

  LazySegmentTree(int sz, const F f, const Monoid M1) : f(f), M1(M1) {
    n = 1;
    while(n < sz) n *= 2;
    node.resize(2 * n - 1, M1);
    lazy.resize(2 * n - 1, 0);
    lazyFlag.resize(2 * n - 1, false);
  }

  void eval(int k, int l, int r) {
    if(lazy[k] = 0) return;

    node[k] += lazy[k];
    if(r - l > 1) {
      lazy[2 * k + 1] += lazy[k] / 2;
      lazy[2 * k + 2] += lazy[k] / 2;
    }
    lazy[k] = 0;
  }

  void lazyEvaluate(int k, int l, int r) {
    if(!lazyFlag[k]) return;

    node[k] = lazy[k];
    if(r - l > 1) {
      lazy[k * 2 + 1] = lazy[k * 2 + 2] = lazy[k];
      lazyFlag[k * 2 + 1] = lazyFlag[k * 2 + 2] = true;
    }
    lazyFlag[k] = false;
  }

  void update(int a, int b, T x, int k = 0, int l = 0, int r = -1) {
    if(r < 0) r = n;

    // eval(k, l, r);
    lazyEvaluate(k, l, r);

    if(b <= l || r <= a) return;

    if(a <= l && r <= b) {
      lazy[k] = x;
      lazyFlag[k] = true;
      // eval(k, l, r);
      lazyEvaluate(k, l, r);
    }
    else {
      update(a, b, x, 2 * k + 1, l, (l + r) / 2);
      update(a, b, x, 2 * k + 2, (l + r) / 2, r);
      node[k] = f(node[k * 2 + 1], node[k * 2 + 2]);
    }
  }

  T query(int a, int b, int k = 0, int l = 0, int r = -1) {
    if(r < 0) r = n;

    // eval(k, l, r);
    lazyEvaluate(k, l, r);

    if(b <= l || r <= a) return INT_MAX;
    if(a <= l && r <= b) return node[k];
    T vl = query(a, b, 2 * k + 1, l, (l + r) / 2);
    T vr = query(a, b, 2 * k + 2, (l + r) / 2, r);
    return f(vl, vr);
  }
};

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

  int n, q;
  cin >> n >> q;
  LazySegmentTree<int> seg(n, [](int a, int b){return min(a, b);}, INT_MAX);

  rep(i, 0, q) {
    int query, s, t;
    cin >> query >> s >> t;
    if(query) cout << seg.query(s, t + 1) << endl;
    else {
      int x;
      cin >> x;
      seg.update(s, t + 1, x);
    }
  }
}



Measured memory_bytes: 5192
// 🐋💭
import Foundation

func readInts() -> [Int] {
    return readLine()!.split(separator: " ").map { Int($0)! }
}

func readInt() -> Int {
    return Int(readLine()!)!
}

func readDoubles () -> [Double] {
    return readLine()!.split(separator: " ").map { Double($0)! }
}

func readDouble() -> Double{
    return Double(readLine()!)!
}

func readLines() -> [String] {
    return readLine()!.map { String($0) }
}
///最大公約数を返す
func gcd(_ m:Int, _ n:Int) -> Int {
    if n == 0 {return m}
    return gcd(n, m % n)
}

///最大公約数を返す
func gcd(_ array: [Int]) -> Int {
    var value = array[0]
    if array.count > 1 {
        for i in 1..<array.count {
            value = gcd(value, array[i])
        }
    }
    return value
}

///最小公倍数を返す
func lcm(_ m:Int, _ n:Int) -> Int {
    return m * n / gcd(m, n)
}

///素数判定(試し割り)
func isPrime(_ x:Int) -> Bool {
    if x <= 1 || x % 2 == 0 { return false }
    if x == 2 { return true }
    for i in stride(from: 3, to: Int(ceil(sqrt(Double(x)))), by: 2){
        if x % i == 0 {
            return false
        }
    }
    return true
}

//https://program-life.com/669
///実行速度の計測
func exectionTime(action: () -> Void) {
    let startDate = Date()
    action()
    let endDate = Date()
    print(endDate.timeIntervalSince(startDate))
}

//https://riptutorial.com/ja/swift/example/14738/インデックスを知らずに配列から要素を削除する
extension Array where Element: Equatable {
    
    mutating func remove(_ element: Element) {
        _ = firstIndex(of: element).flatMap {
            self.remove(at: $0)
        }
    }
}

func binarySearch(rifgt:Int, key:Int, ary:[String]) -> Int{
    var left = 0
    var right = rifgt
    
    while abs(right - left) > 1 {
        let mid = left + (right - left) / 2
        
        if Int(ary[mid])! < key {
            left = mid
            
        } else {
            right = mid
        }
    }
    return left
}

func arrangement (prev:String, ary:[String], returnVal:[String]) -> [String] {
    var returnVal = returnVal
    if ary.count == 0 {
        returnVal.append(prev)
        return returnVal
    }
    
    for s in ary {
        let wprev = prev + s
        var wary = ary
        wary.remove(s)
        returnVal = arrangement(prev: wprev, ary: wary, returnVal: returnVal)
    }
    return returnVal
}
// https://algo-logic.info/divisor/
/// 約数の配列を返す
func divisor(_ n:Int) -> [Int] {
    var ret = [Int]()
    var i = 1
    while i * i <= n {
        if n % i == 0 {
            ret.append(i)
            if i * i != n {
                ret.append(n / i)
            }
        }
        i += 1
    }
    return ret.sorted()
}

func main() {
    let N = readLines()
    //＿＿＿＿＿＿＿＿＿＿＿＿＿＿＿＿＿＿＿＿＿＿＿＿＿＿＿＿＿＿＿ここまで入力
    var add = 0
    for i in N {
        add += Int(i)!
    }
    print(add % 9 == 0 ? "Yes":"No")
}
main()


Measured memory_bytes: 15584
#include<bits/stdc++.h>
using namespace std;
int main(){
  int n,s=0,m=0;
  cin>>n;
  vector<int> l(n);
  for(int i=0;i<n;++i){
    cin>>l[i];
    s+=l[i];
    m=max(m,l[i]);
  }
  if(m<s-m)cout<<"Yes";
  else cout<<"No";
  return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
#include <ctype.h>

int parse(char* str){
	int i,sum=0;
	int d=1;
	for(i=0;str[i];i++){
		if(isdigit(str[i])){
			d=str[i]-'0';
		}else{
			switch(str[i]){
				case 'm':
					sum+=1000*d;
					break;
				case 'c':
					sum+=100*d;
					break;
				case 'x':
					sum+=10*d;
					break;
				case 'i':
					sum+=d;
					break;
				default:
					;
			}
			d=1;
		}
	}
	return sum;
}

void print(int i){
	if(i/1000){
		if((i/1000)==1){
			printf("m");
		}else{
			printf("%dm",i/1000);
		}
	}
	i%=1000;
	if(i/100){
		if((i/100)==1){
			printf("c");
		}else{
			printf("%dc",i/100);
		}
	}
	i%=100;
	if(i/10){
		if((i/10)==1){
			printf("x");
		}else{
			printf("%dx",i/10);
		}
	}
	i%=10;
	if(i){
		if(i==1){
			printf("i");
		}else{
			printf("%di",i);
		}
	}
	printf("\n");
}

void solve(){
	char A[10];
	char B[10];
	scanf("%s %s", A, B);
	int sum=parse(A)+parse(B);
	print(sum);
}

int main(void){
	int n;
	scanf("%d",&n);
	int i;
	for(i=0;i<n;i++){
		solve();
	}
	return 0;
}

Measured memory_bytes: 604
#include<bits/stdc++.h>
using namespace std;
#define NL            "\n"
#define _SAD()        ios::sync_with_stdio(0),cin.tie(0), cout.tie(0);
#define SZ(s)         s.size()
#define SRT(x,y)      sort(x,x+y)
#define REV(a,b)      reverse(a,a+b)
#define VSRT(x)       sort(x.begin(),x.end())
#define VREV(x)       reverse(x.begin(),x.end())
int main()
{
    _SAD()
    int n,ans=0,k,x;
    cin>>n>>k;
    int a[n+1]={0};
    set<int>sad;
    for(int i=0;i<n;i++)
    {
        cin>>x;
        a[x]++;
        sad.insert(x);
    }
    if(SZ(sad)<=k)
    {
        cout<<0<<NL;
    }
    else
    {
        int j=SZ(sad);
        sort(a,a+n+1);

        for(int i=n-k;i>=0;i--)
        {
            ans+=a[i];
        }
        cout<<ans<<NL;
    }
    return 0;
}


Measured memory_bytes: 10368
#include<stdio.h>

int main(){
	int a,b;
	scanf("%d%d",&a,&b);
	while(a|b){
		int data[100]={0};
		for(int i=0;i<a;i++){
			int c;
			scanf("%d",&c);
			for(int j=0;j<c;j++){
				int d;
				scanf("%d",&d);
				data[d]++;
			}
		}
		int max=0;
		int ans=0;
		for(int i=1;i<100;i++)
			if(b<=data[i]&&max<data[i]){
				max=data[i];
				ans=i;
			}
		
		printf("%d\n",ans);
		scanf("%d%d",&a,&b);
	}
}

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

typedef pair<int,int> pii;
typedef vector<int> vec;
typedef unordered_map<int,int> hash;
#define long long long
#define pb push_back
#define all(a) (a).begin(), (a).end()
#define sz(x) (int)x.size()
#define F first
#define S second
#define pb push_back
#define mp make_pair
#define fill(a,v) memset(a,v,sizeof(a))
#define FOR(i, a, b) for(int i = a; i < b; i++)
#define INF 0x3f3f3f3f//infinity for integers
#define JJ ios_base::sync_with_stdio(0); cin.tie(0)//input fast
#define MOD 1000000007


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


	return 0;
}


Measured memory_bytes: 3608
#pragma region RegionDefs
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0,i##_len=(n);i<i##_len;++i)
#define reps(i,l,r) for(int i=(l),i##_len=(r);i<i##_len;++i)
#define all(x) begin(x),end(x)
using namespace std;
typedef long long ll;
const ll INF = 1e9;
template<class T=ll> using V = vector<T>;
template<class T=ll> using PQ = priority_queue<T>;
template<class T=ll> using PQG = priority_queue<T, V<T>, greater<T>>;
const ll MOD = 1000000007LL;
void in() {}
template<class Head, class... Tail>
void in(Head&& head, Tail&&... tail) { cin >> head; in(move(tail)...); }
#define IN(...) ll __VA_ARGS__; in(__VA_ARGS__)
#define INS(T, ...) T __VA_ARGS__; in(__VA_ARGS__)
#define VIN(T, v, n) V<T> v(n); for(auto& _elem:v)cin>>_elem
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;}
#define y0 y__0
#define y1 y__1
#define j0 j__0
#define j1 j__1
#define YN(e) cout << ((e) ? "YES" : "NO") << endl
#define yn(e) cout << ((e) ? "Yes" : "No") << endl
#pragma endregion RegionDefs

void solve()
{
    IN(n, m, k);
    VIN(ll, a, n);
    VIN(ll, b, m);
    vector<ll> v(m);
    rep(i, m) {
        v[i] = i == 0 ? b[0] : v[i-1] + b[i];
    }
    ll s = 0;
    ll c = n;
    rep(i, n) {
        s += a[i];
        if (s > k) {
            c = i;
            s -= a[i];
            break;
        }
    }
    ll res = 0;
    rep(i, c+1) {
        ll h = upper_bound(v.begin(), v.end(), k-s) - v.begin();
        chmax(res, c - i + h);
        s -= a[c-i-1];
    }
    cout << res << endl;
}

int main()
{
    cin.tie(0); cout.tie(0);
    ios::sync_with_stdio(false);
    cout << setprecision(numeric_limits<double>::max_digits10);

    solve();

    return 0;
}

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

int main() {
  int a,x,y,z;
  cin >> a;
  x = (a - (a % 500)) / 500;
  y = (a % 500 - (a % 500 % 5)) / 5;
  z = x * 1000 + y * 5;
  cout << z << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
#include <queue>
#include <cmath>
#include <bitset>
#include <complex>
#include <functional>

// output
#define SPBR(w, n) std::cout<<(w + 1 == n ? '\n' : ' ');
#define YES cout << "YES" << endl
#define Yes cout << "Yes" << endl
#define NO cout << "NO" << endl
#define No cout << "No" << endl
// utility
#define ALL(i) (i).begin(), (i).end()
#define FOR(i, a, n) for(int i=(a);i<(n);++i)
#define RFOR(i, a, n) for(int i=(n)-1;i>=(a);--i)
#define REP(i, n) for(int i=0;i<int(n);++i)
#define RREP(i, n) for(int i=int(n)-1;i>=0;--i)
#define IN(a, x, b) (a<=x && x<b)
#define OUT(a, x, b) (x<a || b<=x)
template<class T> inline T chmax(T & a, const T b) { return a = (a < b) ? b : a; }
template<class T> inline T chmin(T& a, const T b) { return a = (a > b) ? b : a; }

// type/const
#define int ll
using ll = long long;
using ull = unsigned long long;
using ld = long double;
/* const int MOD = 1000000007; */
const int MOD = 998244353;
const int INF = 1e18;
const double PI = acos(-1);

using namespace std;


signed main() {
  int N; 
  cin >> N;

  vector<int> D(N);
  REP(i, N) cin >> D[i];

  map<int, int> m;
  REP(i, N) m[D[i]]++;

  bool ng = false;
  if(m[0] != 1) ng = true;
  if(D[0] != 0) ng = true;

  int ans = 1;
  FOR(i, 1, N){
    if(m[D[i]-1] == 0) ng = true;
    else{
      ans *= m[D[i]-1];
      ans %= MOD;
    }
  }

  if(ng) ans = 0;
  cout << ans << endl;

  return 0;
}

Measured memory_bytes: 7296
#ABC047A https://atcoder.jp/contests/abc047/tasks/abc047_a

a,b,c=(int(x) for x in input().split())

max=a
o1=b
o2=c

if b>max:
    max=b
    o1=a

if c>max:
    max=c
    o2=b

if max==(o1+o2):
    print("Yes")
else:
    print("No")



Measured memory_bytes: 2940
s = input()
first = int("".join(s[:2]))
last = int("".join(s[2:]))

if first > 0 and first <=12:
  if last > 0 and last <= 12:
    ans = 'AMBIGUOUS'
  else:
    ans = 'MMYY'
else:
  if last > 0 and last <= 12:
    ans = 'YYMM'
  else:
    ans = 'NA'
print(ans)

Measured memory_bytes: 3060
#include <iostream>

using namespace std;

int main() {
    int n;
    string s;

    int x = 0;
    int ans = 0;

    cin >> n;
    cin >> s;

    for (int i = 0; i < n; i++) {
        if (s[i] == 'I') {
            x++;
        }

        if (s[i] == 'D') {
            x--;
        }

        if (x > ans) {
            ans = x;
        }
    }

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

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)++)

int main(){
  int inx[5];
  REP(i,5)cin >>inx[i];
  REP(i,5){
    if(inx[i]==0)cout <<i+1;
  }
}


Measured memory_bytes: 3596
#include<iostream>
using namespace std;
int main(){
  string s;
  cin >>s;
  int c;
  if(s[0] =='1') ++c;
  if(s[1] =='1') ++c;
  if(s[2] =='1') ++c;
  
  cout <<c <<endl;
  
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
int main() {
  ll a,b;
  cin>>a>>b;
  if(b==1){
    cout<<0<<endl;
  }
  else if(b==2){
    cout<<1<<endl;
  }
  else{
  cout<<(b-2)/(a-1)+1<<endl;
  return 0;}
  
}


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

#define rep(i,n) for(int i=0;i<(n);++i)
#define loop(i,b,n) for(int i=b;i<(n);++i)
#define each(e,v) for(auto &&e : v)

#define all(v) (v).begin(),(v).end()
#define sz(v) (int)v.size()

using uint = unsigned int;
using ll = long long;
using ull = unsigned long long;

const int INF = 1001001001;
const ll LINF = 1001001001001001001ll;
const double EPS = 1e-9;
const ll MOD = 1e+9 + 7;

template<typename A,typename B> inline void chmin(A &a,B b){ if(a>b) a=b; }
template<typename A,typename B> inline void chmax(A &a,B b){ if(a<b) a=b; }
template <typename T> inline void print(const T& x) { cout << x << endl; }

int main() {
    int n;
    cin >> n;

    std::vector<ll> a(n,0);
    for(int i=0; i<n; ++i) cin >> a[i];

    if(n==1){
        print(a[0]);
        return 0;
    }

    vector<vector<ll>> dp(n,vector<ll>(n,0));
    for(int i=0; i<n-1; ++i){
        dp[i][i+1] = abs(a[i]-a[i+1]);
    }

    for(int d=2; d<=n-1; ++d){
        for(int i=0; i<n-d; ++i){
            dp[i][i+d] = max(a[i] - dp[i+1][i+d], a[i+d] - dp[i][i+d-1]);
        }
    }

    print(dp[0][n-1]);

    return 0;
}

Measured memory_bytes: 73704
#include <stdio.h>
#include <string.h>
#include <algorithm>
#include <queue>

#define rep(i,st,ed) for (register int i=st;i<=ed;++i)
#define fill(x,t) memset(x,t,sizeof(x))

const int INF=0x3f3f3f3f;
const int N=405;
const int E=200505;

struct edge {int y,w,next;} e[E];

int id[N][N],dis[N],ls[N],cur[N],tot,edCnt=1;

char rc[N][N];

void add_edge(int x,int y,int w) {
	e[++edCnt]=(edge) {y,w,ls[x]}; ls[x]=edCnt;
	e[++edCnt]=(edge) {x,0,ls[y]}; ls[y]=edCnt;
}

bool bfs(int st,int ed) {
	std:: queue <int> que;
	fill(dis,0); dis[st]=1;
	for (que.push(st);!que.empty();) {
		int x=que.front(); que.pop();
		for (int i=ls[x];i;i=e[i].next) {
			if (e[i].w&&dis[e[i].y]==0) {
				dis[e[i].y]=dis[x]+1;
				if (e[i].y==ed) return true;
				que.push(e[i].y);
			}
		}
	}
	return false;
}

int find(int x,int ed,int mn) {
	if (x==ed||!mn) return mn;
	int ret=0;
	for (int &i=cur[x];i;i=e[i].next) {
		if (e[i].w&&dis[x]+1==dis[e[i].y]) {
			int d=find(e[i].y,ed,std:: min(e[i].w,mn-ret));
			e[i].w-=d,e[i^1].w+=d,ret+=d;
			if (mn==ret) break;
		}
	}
	return ret;
}

int dinic(int st,int ed) {
	int res=0;
	for (;bfs(st,ed);) {
		rep(i,st,ed) cur[i]=ls[i];
		res+=find(st,ed,INF);
	}
	return res;
}

int main(void) {
	int n,m; scanf("%d%d",&n,&m);
	int sx,sy,tx,ty;
	rep(i,1,n) scanf("%s",rc[i]+1);
	rep(i,1,n) rep(j,1,m) {
		if (rc[i][j]!='.') id[i][j]=++tot;
	}
	rep(i,1,n) rep(j,1,m) if (rc[i][j]!='.') {
		if (rc[i][j]=='S') sx=i,sy=j;
		else if (rc[i][j]=='T') tx=i,ty=j;
		else {
			// add_edge(id[i][j],id[i][j]+tot,1);
			add_edge(i,j+n,1);
			add_edge(j+n,i,1);
		}
	}
	if (sx==tx||sy==ty) return 0&puts("-1");
	add_edge(0,sx,INF),add_edge(0,sy+n,INF);
	add_edge(tx,n+m+1,INF),add_edge(ty+n,n+m+1,INF);
	printf("%d\n", dinic(0,n+m+1));
	return 0;
}

Measured memory_bytes: 896
import java.io.*;
import java.util.*;
public class Main {
	
	public static void main(String[] args) {
	
		MyScanner sc = new MyScanner();
		long n =sc.nextLong();
		long k=sc.nextLong();
		
		System.out.println(k*(int)Math.pow(k-1,n-1));
	}
	
	public static PrintWriter out;

	public static class MyScanner {
		BufferedReader br;
		StringTokenizer st;

		public 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());
		}

		String nextLine() {
			String str = "";
			try {
				str = br.readLine();
			} catch (IOException e) {
				e.printStackTrace();
			}
			return str;
		}

	}
	

}





Measured memory_bytes: 21204
H,N =map(int,input().split()) 
dp = [[0] * (10001) for i in range(1001)]
A,B = map(int,input().split()) 
for j in range(1, H+1):
    dp[0][j] = B * int((j+A-1)/A)

for i in range(1,N):
    A,B = map(int,input().split())
    for j in range(1, A+1):
        dp[i][j] = min(dp[i-1][j], B)
    for j in range(A+1, H+1):
        dp[i][j] = min(dp[i-1][j], dp[i][j-A] + B)

print(dp[N-1][H])

Measured memory_bytes: 120412
#include <iostream>
#include <algorithm>
#include <vector>
#include <queue>
using namespace std;
typedef long long int ll;

struct Edge{
	int to; ll cost;
	Edge(){}
	Edge(int to,int cost):to(to),cost(cost){}
};

vector<Edge> G[100010];
int n,m;

ll d[2][100010];

int main(){
	cin >> n >> m;
	for(int i=0;i<m;i++){
		int a,b; ll c;
		cin >> a >> b >> c;
		a--; b--;
		G[a].push_back(Edge(b,c));
		G[b].push_back(Edge(a,c));
	}
	for(int i=0;i<2;i++){
		for(int j=0;j<n;j++){
			d[i][j]=1e18;
		}
	}
	d[0][0]=0;
	queue<pair<int,int> > q;
	q.push(make_pair(0,0));
	bool ok=true;
	while(q.empty()==false){
		pair<int,int> now=q.front();
		q.pop();
		int eo=now.first; int v=now.second;
		for(auto p:G[v]){
			int tv=p.to;
			ll co=p.cost;
			if(d[1-eo][tv]==1e18){
				d[1-eo][tv]=co-d[eo][v];
				q.push(make_pair(1-eo,tv));
			}
			else{
				if(d[1-eo][tv]!=co-d[eo][v]){ // 辻褄が合わない
					ok=false;
					break;
				}
			}
		}
		if(ok==false){
			cout << 0 << endl;
			return 0;
		}
	}
	if(d[1][0]!=1e18){
		if(d[1][0]<=0||d[1][0]%2==1){
			cout << 0 << endl;
			return 0;
		}
		ll fi=d[1][0]/(ll)2; // 最初の頂点の数が一意に定まる
		ll mi=1e18;
		for(int i=0;i<n;i++){
			mi=min(mi,d[0][i]);
		}
		ll mi1=1e18;
		for(int i=0;i<n;i++){
			mi1=min(mi1,d[1][i]);
		}
		mi=-mi+(ll)1;
		mi1--;
		if(mi<=fi&&fi<=mi1){
			cout << 1 << endl;
			return 0;
		}
		else{
			cout << 0 << endl;
			return 0;
		}
	}
	else{
		ll mi=1e18;
		for(int i=0;i<n;i++){
			mi=min(mi,d[0][i]);
		}
		ll mi1=1e18;
		for(int i=0;i<n;i++){
			mi1=min(mi1,d[1][i]);
		}
		mi=-mi+(ll)1;
		mi1--;
		if(mi<=mi1){
			cout << mi1-mi+1 << endl;
			return 0;
		}
		else{
			cout << 0 << endl;
			return 0;
		}
	}
}

Measured memory_bytes: 9856
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define MOD 1000000007
#define INF 1e9
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define all(x) (x).begin(),(x).end()

int main(){
    string s;
    cin>>s;
    int sl=s.size();
    ll ans=0;
    bool keta=false;
    for(int i=sl-1;i>=0;i--){
        int d=s[i]-'0';
        if(keta) d++;
        keta=false;
        if(d>5 || (d==5 && i>0 && s[i-1]-'0'>4)){
            ans+=10-d;
            keta=true;
        }
        else ans+=d;
    }   
    if(keta) ans++;

    cout<<ans<<endl;
}

Measured memory_bytes: 1412
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <algorithm>

namespace IO{
    const int insiz = 1 << 12, outsiz = 1 << 18;
    char in[insiz], *A(in), *B(in); char out[outsiz], *ptr(out);
    inline char getc(){
    	#ifndef LOCAL
        return (A == B) && (B = (A = in) + fread(in, 1, insiz, stdin), A == B) ? EOF : *A++;
        #endif
        return getchar();
    }
    template <typename T> inline T read(){
        T ret(0), p(1); char ch(getc());
        while(ch < '0' || ch > '9'){
            if(ch == '-') p = -1; ch = getc();
        }
        while(ch >= '0' && ch <= '9') ret = ret * 10 + ch - '0', ch = getc();
        return ret*p;
    }
    inline void flush(){ fwrite(out, 1, ptr - out, stdout); ptr = out; }
    template <typename T> inline void write(T x, char cmd = '\n'){
        if(x < 0) *ptr++ = '-', x = -x;
        if(x == 0) *ptr++ = '0';
        static char s[123]; int cnt = 0;
        for(; x; x /= 10) s[++cnt] = x % 10 + '0';
        for(; cnt; --cnt) *ptr++ = s[cnt];
        *ptr++ = cmd;
        if((outsiz >> 1) > ptr - out) flush();
    }
} using IO::getc; using IO::read; using IO::write; using IO::flush;

const int maxn = 112345;
int seg[maxn << 2];
int gcd(int a, int b){
	return a % b == 0 ? b : gcd(b, a % b);
}
inline void maintain(int node){
	seg[node] = gcd(seg[node << 1], seg[node << 1 | 1]);
}
void build(int l, int r, int node){
	if(l == r){
		seg[node] = read<int>();
		return;
	}
	int mid((l + r) >> 1);
	build(l, mid, node << 1);
	build(mid + 1, r, node << 1 | 1);
	maintain(node);
}

int query(int l, int r, int ql, int qr, int node){
	if(l >= ql && r <= qr){
		return seg[node];
	}
	int mid((l + r) >> 1);
	if(mid >= ql && mid < qr)
		return gcd(query(l, mid, ql, qr, node << 1),
				query(mid + 1, r, ql, qr, node << 1 | 1));
	if(mid >= ql)
		return query(l, mid, ql, qr, node << 1);
	return query(mid + 1, r, ql, qr, node << 1 | 1);
}

int main(){
	int n = read<int>();
	build(1, n, 1);
	int ans(1);
	for(int i(1), l, r; i <= n; ++i){
		if(i == 1){
			ans = std::max(ans, query(1, n, 2, n, 1));
			continue;
		} 
		else 
			l = query(1, n, 1, i - 1, 1);

		if(i == n){
			ans = std::max(ans, query(1, n, 1, n - 1, 1));
			continue;
		}
		else 
			r = query(1, n, i + 1, n, 1);

		ans = std::max(ans, gcd(l, r));
	}
	write(ans);
	flush(); return 0;
}




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

#define ll long long
#define all(a) (a.begin()),(a.end())
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define Rep(i,n,m) for(int i=(int)(n);i<(int)(m);i++)

int manhattan(vector<pair<int,int>> vpA,vector<pair<int,int>> vpB,int i,int j){
    int cur = abs(vpA[i].first-vpB[j].first)+abs(vpA[i].second-vpB[j].second);
    return cur;
}

int main(){
    int n,m; cin >>n>>m;
    vector<pair<int,int>> student(n);
    rep(i,n) cin>>student[i].first>>student[i].second;

    vector<pair<int,int>> checkPoint(m);
    rep(i,m) cin>>checkPoint[i].first>>checkPoint[i].second;

    rep(i,n){
        int num = 1;
        int save = manhattan(student,checkPoint,i,0);
        Rep(j,1,m){
            int distant = manhattan(student,checkPoint,i,j);
            if(save>distant){
                save = distant;
                num = j + 1;
            }            
        }
        printf("%d\n",num);
    }
    return 0;
}

Measured memory_bytes: 256
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<algorithm>
#include<iostream>
#include<vector>
#include<list>
#include<queue>
#include<numeric>
#include<map>
#include<string>

using namespace std;

int main(){
	int n, m;
	vector< pair<int, int> > v;

	scanf("%d%d", &n, &m);

	for (int i = 0; i < m; i++) {
		int a, b;
		scanf("%d%d", &a, &b);
		v.push_back(make_pair(a, b));
	}

	sort(v.begin(), v.end());

	int tail = v[0].second;
	int ans = 1;
	for (int i = 1; i < m; i++) {
		if (v[i].first >= tail) {
			ans++;
			tail = v[i].second;
		} else {
			tail = min(v[i].second, tail);
		}
	}

	printf("%d\n", ans);

	return 0;
}


Measured memory_bytes: 1400
#include <iostream>
#include <string>
#include <vector>
#include <list>
#include <map>
#include <queue>
#include <stack>
#include <algorithm>
#include <fstream>
#include <sstream>
#include <iomanip>
#define ll long long

using namespace std;

long long MOD = 1000000007;

int main(){
    int N;
    cin >> N;

    int all=0;
    vector<int> vec(N,0);
    for(auto &v: vec){
        cin >> v;
        all^=v;
    }

    for(int i=0; i<N; i++){
        if(i!=0){
            cout << ' ';
        }
        cout << (vec[i]^all);
    }
    cout << endl;
}

Measured memory_bytes: 4016
#include <iostream>
#include <vector>
#include <string>
#include <cmath>
#include <cstdio>
#include <algorithm>

using namespace std;

int matrix[20][20];

int main()
{
    while(true)
    {
        int n;

        cin >> n;
        
        if(!n) break;

        vector<int> vec(n);

        for(int i = 0; i < n; i++)
        {
            cin >> vec[i];
        }
        
        sort(vec.begin(), vec.end());

        int sum = 0;
        for(int i = 1; i < n - 1; i++){
            sum += vec[i];
        }
        cout << int(sum / (n - 2)) << endl;
    }

    return 0;
}


Measured memory_bytes: 3112
#include<iostream>
#include<sstream>
#include<cstdio>
#include<cstdlib>
#include<string>
#include<cstring>
#include<cmath>
#include<ctime>
#include<algorithm>
#include<utility>
#include<stack>
#include<queue>
#include<deque>
#include<vector>
#include<set>
#include<map>
#define ll long long 
#define N 105
using namespace std;
const int max =0x7fffffff;
int h,w;
int ans=0;
string str[N];
int visit[N][N];
int dir[4][2]={1,0,0,1,-1,0,0,-1};
void dfs(int x,int y,char ch)
{
	int i,dx,dy; 
	for(i=0;i<4;i++)
	{
		dx=x+dir[i][0];
		dy=y+dir[i][1];
		if(dx<0||dx>=h||dy<0||dy>=w||visit[dx][dy]||str[dx][dy]!=ch)
		continue;
		visit[dx][dy]=1;
		dfs(dx,dy,ch);
	}
}
int main()
{
	ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);//让cin，cout变得快一点
	while(cin>>h>>w,h+w)
	{
		ans=0;
		memset(visit,0,sizeof(visit));
		int i,j;
		for(i=0;i<h;i++)
		{
			cin>>str[i];
		}
		for(i=0;i<h;i++)
		{
			for(j=0;j<w;j++)
			{
				if(!visit[i][j])
				{
					visit[i][j]=1;
					dfs(i,j,str[i][j]);	
					ans++;
				}
			}	
		}
		cout<<ans<<endl;
	}
	return 0;
}


Measured memory_bytes: 4024
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.Arrays;
import java.util.List;
import java.util.stream.Collectors;

public class Main {
    public static void main(final String[] args) throws IOException {
        new Main().run();
    }

    private void run() throws IOException {
        boolean b = true;
        final BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
        while (b) {
            b = runOnce(reader);
        }

        reader.close();
    }

    private boolean runOnce(final BufferedReader reader) throws IOException {
        final String[] params = reader.readLine().split(" ");
        final int count = Integer.parseInt(params[0]);
        final int max = Integer.parseInt(params[1]);
        if (count == 0 && max == 0) return false;
        final List<Integer> prices = Arrays.stream(reader.readLine().split(" "))
                .map(Integer::parseInt)
                .sorted()
                .collect(Collectors.toList());
        int nextLow = 0;
        int maxSum = 0;
        for (int i = prices.size() - 1; i >= 0; i--) {
            final int start = nextLow;
            while (nextLow < i && prices.get(i) + prices.get(nextLow) <= max) {
                nextLow++;
            }
            if (nextLow == start) continue;
            maxSum = Math.max(maxSum, prices.get(i) + prices.get(nextLow - 1));
        }

        System.out.println(maxSum == 0 ? "NONE" : maxSum);
        return true;
    }
}

Measured memory_bytes: 34880