akhauriyash/Code-Regression huggingface dataset:
// https://atcoder.jp/contests/abcXXX/tasks/abcXXX_x

#include <iostream>
#include <iomanip>
#include <vector>
#include <tuple>
#include <algorithm>
#include <string>
#include <cmath>
#include <map>
#include <set>
#include <unordered_map>
#include <unordered_set>
#include <queue>

using namespace std;
using ll = long long;
using ull = unsigned long long;
using pll = pair<ll, ll>;

static const ll INF = 1001001001;
static const ll LLINF = 1001001001001001001;

#define REP(i, n) for(ll i = 0; i < (n); ++i)
#define RANGE(i, m, n) for(ll i = (m); i <= (n); ++i)

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

int run(istream& in, ostream& out) {
    ll N, K;
    in >> N >> K;
    vector<ll> v(N, 0);
    REP(i, N) {
        in >> v[i];
    }
    ll total = 0;
    ll max_sum = 0;
    REP(i, K) {
        total += v[i]+1;
    }
    max_sum = total;
    ll sum = total;
    RANGE(i,K,N-1) {
        sum = sum - (v[i-K]+1) + (v[i]+1);
        max_sum = max(max_sum, sum);
    }
    double ans = (double)max_sum/2.0;
    out << std::fixed << std::setprecision(15) << ans << endl;
    return 0;
}

int main() {
    return run(cin, cout);
}


Measured memory_bytes: 1792
#include <bits/stdc++.h>
using namespace std;
//#include "testlib.h"
#define ff first
#define ss second
#define all(v) v.begin(),v.end()
#define int long long
#define ll long long
#define M 1000000007
#define MM 998244353
#define inputarr(a,n) for(int i=0;i<n;++i) cin>>a[i]
#define GCD(m,n) __gcd(m,n)
#define LCM(m,n) m*(n/GCD(m,n))
#define mii  map<ll ,ll >
#define msi  map<string,ll >
#define rep(a,b)    for(ll i=a;i<b;i++)
#define rep0(n)    for(ll i=0;i<n;i++)
#define repi(i,a,b) for(ll i=a;i<b;i++)
#define pb push_back
#define vi vector<ll>
#define vs vector<string>
#define ppb pop_back
#define endl '\n'
#define asdf ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define r0 return 0;
#define FORD(i, a, b) for (int i = (int) (a); i >= (int) (b); --i)
#define inputoutput freopen("input.txt", "r", stdin);freopen("output.txt", "w", stdout);
#define Set(a, s) (a, s, sizeof (a))
#define FOR repi
#define vii vector<pii>
#define pii pair<int,int>
#define REVERSE(v) reverse(all(v))
#define trav(a, x) for(auto& a : x)
#define display(x) trav(a,x) cout<<a<<" ";cout<<endl
#define debug cerr<<"bhau"<<endl
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>
void __f(const char* name, Arg1&& arg1){
    std::cerr << name << " : " << arg1 << endl;
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args){
    const char* comma = strchr(names + 1, ',');std::cerr.write(names, comma - names) << " : " << arg1<<" | ";__f(comma+1, args...);
}
template<typename T, typename U> static inline void amin(T &x, U y) 
{ 
    if (y < x) 
        x = y; 
}
template<typename T, typename U> static inline void amax(T &x, U y) 
{ 
    if (x < y) 
        x = y; 
}
 
ll max(ll a, ll b) { return (a > b)? a : b;}
int min(int a, int b) { return (a < b)? a : b;} 
const int N=3e5+10;
vi v[N];
int cnt[N];
// set<pair<int,int> > s;
multiset<int> q;
int solve(){

    int h,w;cin>>h>>w;
    int m;cin>>m;
    while(m--){
        int x,y;cin>>x>>y;
        v[x].pb(y);
        cnt[y]++;
    }
    for(int i=1;i<=w;i++) q.insert(cnt[i]);
    int ans=1;
    for(int i=1;i<=h;i++){
        for(auto j:v[i]){
            q.erase(q.find(cnt[j]));
            cnt[j]--;
            q.insert(cnt[j]);
        }
        amax(ans,v[i].size()+*q.rbegin());
        for(auto j:v[i]){
            q.erase(q.find(cnt[j]));
            cnt[j]++;
            q.insert(cnt[j]);
        }

    }
    cout<<ans<<endl;

    return 0;
}
signed main(){
    asdf
    int t=1;
    // cin>>t;
    while(t--){
        solve();
    }
    return 0;
}


Measured memory_bytes: 36444
import java.util.*;
 
public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int N = Integer.parseInt(sc.next());
        int[] v = new int[N];

        for(int i = 0; i < N; i++) {
            v[i] = Integer.parseInt(sc.next());
        }
        
        Arrays.sort(v);
        double ans = ((double)(v[0] + v[1]) / 2);
        
       
        for(int i = 2; i < N; i++) {
            ans = ((double)(ans + v[i]) / 2);
        }
        
        System.out.println(ans);
        
    }
}

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

int main(){
    using namespace std;
    string s; cin >> s;

    int cnt1 = 0, cnt2 = 0;
    for (int i = 0, N = s.size(); i < N; i++)
    {
        if(i%2==0 && s[i] =='1') cnt1++;
        else if(i%2==1 && s[i] == '0') cnt1++;
        else if(i%2==0 && s[i] =='0') cnt2++;
        else if(i%2==1 && s[i] =='1') cnt2++;
    }
    cout << min(cnt1, cnt2) << endl;
    
}


Measured memory_bytes: 768
#include<set>
#include<iostream>
#include<algorithm>

using namespace std;

int main()
{
	for(int n,k;cin>>n>>k,n;){
		int card[10];
		for(int i=0;i<n;i++)	cin>>card[i];
		sort(card,card+n);

		set<int> st;
		bool mask[10]={};
		for(int i=0;i<k;i++)	mask[i]=true;
		do{
			int chos[10];
			for(int i=0,j=0;i<n;i++)	if(mask[i])	chos[j++]=card[i];
			do{
				int res=0;
				for(int i=0;i<k;i++){
					if(chos[i]<10)	res=res*10+chos[i];
					else			res=res*100+chos[i];
				}
				st.insert(res);
			}while(next_permutation(chos,chos+k));
		}while(prev_permutation(mask,mask+n));

		cout<<st.size()<<endl;
	}

	return 0;
}

Measured memory_bytes: 0
#include <iostream>
#include <algorithm>
#include <tr1/unordered_map>
using namespace std;

int n , v[20];

tr1::unordered_map<int,int> memo[20];

int f(int pos , int sum){
	return pos == n ? abs(sum) : memo[pos].count(sum) ? memo[pos][sum] : memo[pos][sum] = min( f(pos+1,sum+v[pos] ) , f(pos+1,abs(sum-v[pos])) );
}

int main(){
	while(cin >> n && n){
		for(int i = 0 ; i < n ; i++) cin >> v[i] , memo[i].clear() ;
		cout << f(0,0) << endl;
	}
}

Measured memory_bytes: 0
var input = require('fs').readFileSync('/dev/stdin', 'utf8');
var arr=input.trim().split("\n");
while(true){
   var N=arr.shift()-0;
   if(N==0)break;
   var f="";
   for(var I=0;I<N+1;I++){
      var n=arr.shift()-0;
      var ary=[];
      while(n--)ary.push(arr.shift().split(" ").map(Number));
      var r=[];
      for(var i=1;i<ary.length;i++){
         var a=ary[i-1];
         var b=ary[i];
         if(a[0]==b[0] && a[1]>b[1])r.push(["s",a[1]-b[1]]);
         else if(a[0]==b[0] && a[1]<b[1])r.push(["n",b[1]-a[1]]);
         else if(a[1]==b[1] && a[0]>b[0])r.push(["w",a[0]-b[0]]);
         else if(a[1]==b[1] && a[0]<b[0])r.push(["e",b[0]-a[0]]);
      }
      var rA=r.join("");
      var rB=r.reverse().join("");
      if(I==0){
         f=r.join("").replace(/n/g,"N").replace(/e/g,"E").replace(/s/g,"S").replace(/w/g,"W");
      }else{
         var NrA=rA.replace(/n/g,"N").replace(/e/g,"E").replace(/s/g,"S").replace(/w/g,"W");
         var ErA=rA.replace(/n/g,"E").replace(/e/g,"S").replace(/s/g,"W").replace(/w/g,"N");
         var SrA=rA.replace(/n/g,"S").replace(/e/g,"W").replace(/s/g,"N").replace(/w/g,"E");
         var WrA=rA.replace(/n/g,"W").replace(/e/g,"N").replace(/s/g,"E").replace(/w/g,"S");
         var NrB=rB.replace(/n/g,"N").replace(/e/g,"E").replace(/s/g,"S").replace(/w/g,"W");
         var ErB=rB.replace(/n/g,"E").replace(/e/g,"S").replace(/s/g,"W").replace(/w/g,"N");
         var SrB=rB.replace(/n/g,"S").replace(/e/g,"W").replace(/s/g,"N").replace(/w/g,"E");
         var WrB=rB.replace(/n/g,"W").replace(/e/g,"N").replace(/s/g,"E").replace(/w/g,"S");
         if(f==ErA || f==SrA || f==WrA || f==NrA || f==ErB || f==SrB || f==WrB || f==NrB)console.log(I);
      }
   }
   console.log("+++++");
}

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

int kai(string sk){
	int rt = 1;
	for(int i=0;i<sk.size()/2;i++)
	{
		if(sk.at(i) != sk.at(sk.size()-1 -i))
		{
			rt = 0;
		}
	}
	return rt;
}

int main() {
	string s,s1,s2;
	cin >> s;
	int ss = s.size();
	s1 = s.substr(0,(ss-1)/2);
	s2 = s.substr((ss+1)/2,(ss-1)/2);
	string k = "Yes";
	if(kai(s) * kai(s1) * kai(s2) == 0)
	{
		k = "No";
	}
	cout << k <<endl;
	return 0;
}


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

using namespace std;

int main() {
  int n;
  cin >> n;
  vector<int> a(n),b(n);
  for(int i=0;i<n;i++){
    cin >> a.at(i);
    b.at(a.at(i)-1) = i+1;
  }
  for(int i=0;i<n;i++){
    cout << b.at(i) << endl;
  }
  
  return 0;
}


Measured memory_bytes: 1664
#include <iostream>
#include <vector>

using namespace std;

bool binary_search(vector<int>& v, int& n)
{
    int left = 0;
    int right = v.size();
    while (left < right) {
        int middle = (left + right) / 2;
        if (v[middle] == n) return true;
        if (n < v[middle])
        {
            right = middle;
        }
        else
        {
            left = middle + 1;
        }
    }
    return false;
}

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

    int q;
    cin >> q;

    int count = 0;
    for (int i = 0; i < q; ++i)
    {
        int t;
        cin >> t;
        if (binary_search(S, t)) ++count;
    }
    cout << count << endl;

    return 0;
}

Measured memory_bytes: 1524
a = [list(map(int, input().split())) for _ in range(3)]
for i in range(3):
    if (a[i][0] in a[(i+1) % 3] or a[i][0] in a[(i+2) % 3]) and \
     (a[i][1] in a[(i+1) % 3] or a[i][1] in a[(i+2) % 3]):
        print('YES')
        break
else:
    print('NO')


Measured memory_bytes: 3060
#include <iostream>
#include <string>
#include <algorithm>
#include <cmath>
#include <cstdlib>
#include <vector>
#include <map>
#include <queue> 

using namespace std;
#define rep(i, s, e) for (int(i) = (s); (i) <= (e); ++(i))
#define all(x) x.begin(),x.end()


int main()
{
	long long n, res; cin >> n;
	res = 0;
	for (long long r = 1; r*r <= n; ++r)
	{
		if ((n - r) % r == 0 && (n - r) / r > r) res += (n - r) / r;
	}
	cout << res << endl;
}

Measured memory_bytes: 256
// luogu-judger-enable-o2
#include <algorithm>
#include <assert.h>
#include <iostream>
#include <cstring>
#include <vector>
#include <cstdio>
#include <cmath>

using namespace std;

typedef long long ll;

const int MX = 200005;
const int oo = 1231231231;

template <typename T> void read(T &x)
{
	x = 0; char c = getchar(); bool f = 0;
	while(!isdigit(c) && c!='-') c = getchar();
	if(c == '-') f = 1, c = getchar();
	while(isdigit(c)) x = x*10+c-'0', c = getchar();
	if(f) x = -x;
}

struct NODE
{
	int x, y;
	
	bool operator < (const NODE& t) const {return x < t.x;}
};

int n;
NODE pot[MX];
int ymn[MX];

int main()
{
	read(n);
	for(int i=1; i<=n; i++)
	{
		read(pot[i].x), read(pot[i].y);
		if(pot[i].y > pot[i].x) swap(pot[i].x, pot[i].y);
	}
	sort(pot+1, pot+n+1);
	int xmn = pot[1].x, ymx = 0, xmx = 0;
	ymn[0] = +oo;
	for(int i=1; i<=n; i++) ymn[i] = min(ymn[i-1], pot[i].y), ymx = max(ymx, pot[i].y);
	ll ans = 1ll * (pot[n].x-xmn) * (ymx-ymn[n]);
	for(int i=n; i>=2; i--)
	{
		ymx = max(ymx, pot[i].x);
		xmn = min(xmn, pot[i].y);
		xmx = max(xmx, pot[i].y);
		ans = min(ans, 1ll*(max(xmx, pot[i-1].x)-xmn)*(ymx-ymn[i-1]));
	}
	printf("%lld\n", ans);
	return 0;
}

Measured memory_bytes: 2560
#include <bits/stdc++.h>
typedef long long ll;
#define REP(i, n) for(int i = 0; i < n; i++)
#define REP2(i, a, b) for(int i = a;i <= b;i++)
#define REPR(i, a, b) for(int i = a; i >= b; i--)
#define FOR(i, m, n) for(int i = m; i < n; i++)
#define INF 2e9
#define MOD 1000000007
#define PI 3.14159265358979323846
#define vi vector<int>
#define vll vector<ll>
#define vi2 vector<vector<int>>
#define eb emplace_back
#define fi first
#define se second
#define ALL(v) v.begin(), v.end()
#define sz(x) int(x.size())
using namespace std;
using P = pair<ll,ll>;
const int dx[]{0, 1, 0, -1, -1, -1, 1, 1}, dy[]{1, 0, -1, 0, -1, 1, -1, 1};
#define INT(name) int name;cin >> name;
#define VEC(type,name,n) vector<type> name(n);REP(i,n) cin >> name[i];

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

int main()
{
  INT(K);
  vector<ll> A(K);
  REP(i, K) cin >> A[i];
  reverse(ALL(A));
  if(A[0]!=2){
    cout << -1 << endl;
  }else{
    ll MIN=2;
    ll MAX=3;
    int flag = 0;
    FOR(i,1,K){
      if(MIN%A[i]!=0){
        MIN=(MIN/A[i]+1)*A[i];
      }
      MAX=MAX/A[i]*A[i]+A[i]-1;
      if(MAX<MIN){
        flag=1;
        break;
      }
    }

    if(flag==1){
      cout << -1 << endl;
    }else{
      cout << MIN << " " << MAX << endl;
    }
  }
}

Measured memory_bytes: 4040
#include <bits/stdc++.h>
#define rep(i, s, n) for (int i = s; i < n; i++)
#define pb push_back
#define mp make_pair
#define all(x) (x).begin(), (x).end()
#define all_acc(x) (x).begin(), (x).end(), 0LL
#define int long long
#define absSort(v) sort(a.begin(), a.end(), [](int i, int j) -> bool { return abs(i) < abs(j); });
using namespace std;
using P = pair<int, int>;
using Graph = vector<vector<int>>;
using ll = long long;

//出力するよ
void output(vector<string> s){
    int n = s.size();
    for (int i = 0; i < n; i++){
        //if(i!=0) cout<<" ";
        cout << s[i]<<endl;
    }
    //cout << endl;
}

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

    set<int> numbers;
    for(int tmp=1;tmp<(1<<n);tmp++){
        bitset<20> bit(tmp);
        int ans=0;
        for(int i=0;i<n;i++){
            if(bit.test(i)){
                ans+=a[i];
            }
        }
        numbers.insert(ans);
    }

    int q; cin>>q;
    vector<string> res;
    for(int i=0;i<q;i++){
        int mi; cin>>mi;
        if(numbers.count(mi)) res.push_back("yes");
        else res.push_back("no");
    }

    output(res);
}


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

int main()
{
    long long a, b, c;
    cin >> a >> b >> c;
    if (c - a - b < 0)
    {
        cout << "No" << endl;
        return 0;
    }
    if (4 * a * b < (c - a - b) * (c - a - b))
    {
        cout << "Yes" << endl;
        return 0;
    }
    cout << "No" << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <queue>
#include <vector>
#define endl '\n'
using namespace std;

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

	int n;
	cin>>n;
	cout<<(1000-n%1000)%1000;

	return 0;
}
	


Measured memory_bytes: 3656
#include<iostream>
#include<math.h>
#include<vector>
#include<array>
#include<algorithm>
#include<numeric>
#include<map>
#include<queue>
#include<deque>
#include<set>
#include<cstdio>
#include<cstring>
#include<string>
using namespace std;
typedef long long ll;
typedef vector<ll> vec;
typedef vector<vector<ll>> mat;
typedef pair<ll,ll> P;

struct LazySegmentTree{
    int n;
    vec node,lazy;
    
    LazySegmentTree(int N){
        n=1;
        while(n<N)n*=2;
        node.resize(2*n-1,0);
        lazy.resize(2*n-1,0);
    }

    //k番目のノードについて遅延評価
    void eval(int k,int l,int r){
        if(lazy[k]!=0){
            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;
        }
    }

    //[a,b)にxを加算、kは区間[l,r)の節点
    void add(int a,int b,ll x,int k,int l,int r){
        eval(k,l,r);

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

        if(a<=l && r<=b){
            lazy[k]+=x*(ll)(r-l);
            eval(k,l,r);
        }

        else{
            add(a,b,x,2*k+1,l,(l+r)/2);
            add(a,b,x,2*k+2,(l+r)/2,r);
            node[k]=node[2*k+1]+node[2*k+2];
        }
    }

    //[a,b)の区間和を取得
    ll getsum(int a,int b,int k,int l,int r){
        if(b<=l || r<=a) return 0;

        eval(k,l,r);
        if(a<=l && r<=b) return node[k];
        ll vl=getsum(a,b,2*k+1,l,(l+r)/2);
        ll vr=getsum(a,b,2*k+2,(l+r)/2,r);
        return vl+vr;
    }   
};

LazySegmentTree LST2(200000);
int BS(int x,int l,int r){
    if(r-l==1) return l;
    int m=(l+r)/2;
    if(LST2.getsum(0,m,0,0,LST2.n)<x) return BS(x,m,r);
    else                              return BS(x,l,m);
}

int main(){
    int Q;cin>>Q;
    vec Query,B;
    vector<P> A;
    int k=0;
    for(int q=0;q<Q;q++){
        int s;cin>>s;
        Query.push_back(s);
        if(s==1){
            ll a,b;cin>>a>>b;
            A.push_back((P){a,k});
            B.push_back(b);
            k++;
        }
    }
    sort(A.begin(),A.end());
    vector<P> X(k);
    for(int j=0;j<k;j++){
        X[A[j].second]=(P){A[j].first,j};
    }
    LazySegmentTree LST1(k);
    int count=0;ll rev=0;
    for(int q=0;q<Q;q++){
        if(Query[q]==1){
            rev+=B[count];
            LST1.add(X[count].second,X[count].second+1,X[count].first,0,0,LST1.n);
            LST2.add(X[count].second,X[count].second+1,1,0,0,LST2.n);
            count++;
        }
        else{
            int index=BS((count+1)/2,0,k);
            ll x=A[index].first,g=rev+LST1.getsum(index+1,k,0,0,LST1.n)-LST1.getsum(0,index+1,0,0,LST1.n);
            if(count%2==1) g+=x;
            cout<<x<<" "<<g<<endl;
        }
    }
    return 0;
}

Measured memory_bytes: 28636
#include <iostream>
#include <cstring>
#include <algorithm>
#include <iomanip>
#include <vector>
#include <map>
#include <cmath>
#include <queue>
#include <utility>
#include <functional>
#include <deque>
#include <cctype>
#include <stack>
#include <bitset>

using ll = long long;
using namespace std;
typedef unsigned long long ull;
typedef pair<ll, ll>P;
const ll mod = 1000000007;
const ll INF = 1 << 30;
const ll INF2 = 9000000000000000000LL;
bool fl = false, flag = false;
int dx[4] = { 1,0,-1,0 }, dy[4] = { 0,1,0,-1 };
struct edge { ll to, cost; };

int main() {
	int n, a[100000], ans = 1;
	cin >> n;
	for (int i = 0;i < n;i++)cin >> a[i];
	sort(a, a + n);
	for (int i = n - 1;i > 0;i--) {
		if (a[i] != a[i - 1])ans++;
	}
	cout << ans << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <string>
#include <algorithm>
#include <cmath>
#include <vector>
#define rep(i, n) for(int i = 0; i < n; i++)
using namespace std;
typedef long long ll;

int main() {
    string s;
    cin >> s;
    int n = s.size();
    ll ans = 0;

    if(n == 1) {
        ans = s[0] - '0';
        cout << ans << endl;
        return 0;
    }

    //00…0(0がn-1個)から11…1(1がn-1個)のbit列を全て調べる
    for(int b = 0; b < (1 << (n-1)); b++) {

        ll t = s[0] - '0';  //ansを計算するための補助変数

        //bのn-iビット目について調べる
        for(int i = 1; i <= n-1; i++) {

            //bのn-iビット目が1だったら
            if( b & (1 << (n-1-i)) ) {
                //ansにtを加えて、tにs[i]を代入する
                ans += t;
                t = s[i] - '0';
            }
            //bのn-iビット目が0だったら
            else {
                //tを10倍してs[i]を加える
                t = 10*t + (s[i] - '0');
            }

            //1ビット目まで調べ終わったら
            if(i == n-1) {
                //ansにtを加える
                ans += t;
            }
        }
    }

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

Measured memory_bytes: 256
//#pragma GCC optimize("Ofast")

#pragma GCC optimize("O3")
//#pragma GCC target("avx,avx2,fma")
#include<iostream>
#include<algorithm>
#include<string>
#include<cmath>
#include<cstdlib>
#include<set>
#include<vector>
#include<sstream>
#include<queue>
#include <iomanip>
#include<unordered_set>
#include <stack>
#include <unordered_map>
#include <map>
constexpr auto INF = 9223372036854775807;
typedef long long int ll;
typedef unsigned long long int ull;
typedef unsigned long int ul;
#define f(i,a,b) for(ll i=(ll)a;i<(ll)b;i+=1)
#define rf(i,a,b) for(ll i=(ll)a;i>=(ll)b;i-=1)
#define endl '\n'
#define N 1000000007// prime modulo value 
#define C 1000000001
#define M 998244353
#define all(x) x.begin(),x.end()
using namespace std;
// From Geeksforgeeks
inline ll gcd(ll a, ll b)
{
	if (b == 0)
		return a;
	return gcd(b, a % b);
}
// Power function took from geeksforgeeks
ll power(ll x, ll y)
{
	ll res = 1;

	x = x;
	if (x == 0) return 0;
	while (y > 0)
	{
		if (y & 1)
			res = (res * x);
		y = y >> 1;
		x = (x * x);
	}
	return res;
}
double dist(ll x1,ll y1, ll x2,ll y2)
{
	double ans = sqrt((x1 - x2) * (x1 - x2) + (y1 - y2) * (y1 - y2));
	return ans;
}
int main()
{
	ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
	ll n;
	cin >> n;
	vector<ll> arr(n-1, 0);
	f(i, 0, n-1)
	{
		cin >> arr[i];
	}
	ll ans = arr[0];
	ll pre = arr[0];
	f(i, 1, n - 1)
	{
		ans += min(pre, arr[i]);
		pre = arr[i];
	}
	ans += arr[arr.size() - 1];
	cout << ans;
	return 0;
}


Measured memory_bytes: 256
#include<stdio.h>
int j(char *a,char *b){
	while(*a==*b&&a<b){
		a++;b--;
	}
	if(a>=b) return 1;
	return 0;
}
int main(){
	char a[1000];
	int n=0;
	scanf("%s",a);
	while(a[n]!='\0')
	n++;
	n--;
	if(j(&a[0],&a[n])&&j(&a[0],&a[(n/2)-1])&&j(&a[(n/2)+1],&a[n]))
	printf("Yes");
	else printf("No");
} 

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

int main(){
  int n; cin >> n;
  vector<long long> a(n);
  long long M = -1001001001, m = 1001001001;
  for(int i = 1; i <= n; i++){
    cin >> a.at(i-1);
    a.at(i-1) -= i;
  }
  sort(a.begin(), a.end());
  long long ans1 = 0, ans2 = 0;
  long long tmp1;
  if(n >= 2) tmp1 = a.at(n/2 - 1);
  else tmp1 = 0;
  long long tmp2 = a.at(n/2);
  for(int i = 0; i < n; i++){
    ans1 += abs(a.at(i) - tmp1);
    ans2 += abs(a.at(i) - tmp2);
  }
  cout << min(ans1, ans2) << endl;
}


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

ll mod = 1000000007;

// PowMod( base, index, modulo) return base ** index % modulo {{{
// PowMod = base ** index % mod ( natural numbers )
long long unsigned int PowMod( long long unsigned int base, long long unsigned int index, long long unsigned int modulo = mod ){
    if( index == 0 ) return 1;
    // O( log(index) )
    if( index % 2 ){
        return base * PowMod(base, index - 1, modulo) % modulo;
    }else{
        long long unsigned int Phalf = index / 2;
        long long unsigned int half = PowMod(base, Phalf, modulo);
        return half * half % modulo;
    }
}
// }}}

// CombMod( n, r, modulo ) return nCr % modulo {{{
// CombMod(ination) = nCr % mod ( natural number )
long long unsigned int CombMod( long long unsigned int n, long long unsigned int r, long long unsigned int modulo = mod){
    if( n < r ) return CombMod(r,n,modulo);
    long long unsigned int Upper = 1;
    long long unsigned int Lower = 1;
    for(long long unsigned int i = 0; i < r; i++){
        Upper = Upper * (n-i) % modulo;
        Lower = Lower * (i+1) % modulo;
    }
    // Return (Upper / Lower)
    long long unsigned int ret = Upper * PowMod(Lower,modulo-2,modulo) % modulo;
    return ret;
}
// }}}

// definition {{{ 1

// scaning {{{ 2
#define Scd(x) scanf("%d", &x)
#define Scd2(x,y) scanf("%d%d", &x, &y)
#define Scd3(x,y,z) scanf("%d%d%d", &x, &y, &z)
#define Scll(x) scanf("%llu", &x)
#define Scll2(x,y) scanf("%llu%llu", &x, &y)
#define Scll3(x,y,z) scanf("%llu%llu%llu", &x, &y, &z)
// }}} 2

// constants {{{ 2
#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))
// }}} 2

// systems {{{ 2
#define Rep(x,y) for(int x = 0; x < y; x++)
#define Repe(x,y,z) for(int x = z; x < y; x++)
// }}} 2

// }}} 1

int main() {

    int h,w,a,b;

    Scd2(h,w);
    Scd2(a,b);

    ll turn[100003] = {};
    ll tmp = 1;
    ll upper = h-a;
    ll downer = 1;
    turn[0] = 1;
    Repe(i,w,1){
        turn[i] = upper * PowMod(downer,mod-2) % mod;
        upper = upper * (h-a+i) % mod;
        downer = downer * (i+1) % mod;
    }
    upper = 1;
    downer = 1;
    ll ans = 0;
    ll con = 1;
    Rep(i,w-b){
        ans = ( ans + turn[w-i-1] * con) % mod;
        //printf("%llu * %llu -> ", turn[w-i-1] , con );
        //printf("%llu : ", turn[w-i-1] * con % mod );
        //printf("%llu * %llu = ", upper , PowMod(downer,mod-2) );
        upper = upper * (a+i) % mod;
        downer = downer * (i+1) % mod;
        con = upper * PowMod(downer,mod-2) % mod;
        //con = CombMod(upper++,downer++);
        //printf("%llu\n", con );
    }

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

    return 0;
}


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

#define int long long
#define pb push_back
#define eb emplace_back
#define fi first
#define se second
#define fr(i,j,k) for(i = j; i < (k); i++)
#define all(x) x.begin(), x.end()
#define el '\n'
#define remax(a,b) a = max(a, b)
#define remin(a,b) a = min(a, b)
#define sz(x) int32_t(x.size())

typedef long double ld;
typedef pair<int,int> pii;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<pii> vpi;
// --------------------------------------------------------------------

const pii dxy[] = { {-1, 0}, {1, 0}, {0, 1}, {0, -1} };
const int mod = 1e9 + 7;
const int INF = 2e18;
const ld EPS = 1e-9;
const int NN = 2e5 + 2;

vi nums[3];
int ans[NN];
vvi g(NN);
int record;
bool dfs(int u, int p, int d, int lev) {
      int nxt = d == 1 ? 2 : 1;
      if(!nums[d].empty()) {
            ans[u] = nums[d].back();
            nums[d].pop_back();
      }
      else {
            if(nums[0].empty()) {
                  record = lev;
                  return 0;
            }

            ans[u] = nums[0].back();
            nums[0].pop_back();
      }

      for(int v : g[u]) {
            if(v != p) {
                  if(!dfs(v, u, nxt, lev + 1))
                        return 0;
            }
      }
      return 1;
}

void bfs(int n) {
      int oddity = (record % 2) ^ 1;
      int oth = n%3 == 0 ? n-1 : n, curr = 3;
      queue<pii> q;
      q.push({1, 0});
      vi par(NN);
      par[1] = 0;
      while(!q.empty()) {
            pii v = q.front();
            q.pop();
            if(v.se % 2 == oddity || oth <= 0) {
                  ans[v.fi] = curr;
                  curr += 3;
            } else {
                  ans[v.fi] = oth;
                  oth--;
                  if(oth%3 == 0) oth--;
            }
            for(int nxt : g[v.fi]) {
                  if(par[v.fi] == nxt) continue;
                  par[nxt] = v.fi;
                  q.push({nxt, v.se + 1});
            }
      }
}

void solve() {
      int i = 0, j = 0, k = 0, n = 0, m = 0; 
      cin >> n;
      fr(i, 0, n - 1) {
            cin >> j >> k;
            g[j].pb(k);
            g[k].pb(j);
      }

      fr(i, 1, n+1) {
            nums[i % 3].pb(i);
      }

      if(!dfs(1, 0, 1, 0)) {
            memset(ans, -1, sizeof ans);
            bfs(n);
      }
      fr(i, 0, n) cout << ans[i+1] << ' ';

      cout << el;
}

int32_t main() {
      ios::sync_with_stdio(false); cin.tie(0); 
      int T = 1; 
      // cin >> T;
      for(int tc = 1; tc <= T; tc++) {
            solve();
       }
      return 0;
}

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

#define FOR(i,a,b)  for(ll (i)=a;(i)<(b);++(i))
#define RFOR(i,a,b) for(ll (i)=a;(i)>=(b);--(i))
#define REP(i,n)    FOR(i,0,n)
#define RREP(i,n)   RFOR(i,n,0)
#define ALL(v)      (v).begin(),(v).end()
#define BIT(n)      (1LL<<(n))
#define IN(x,l,r)   ((l)<=(x)&&(x)<=(r))
#define LEN(s)      (string(s)).length()
#define NPOS        string::npos
#define SHOW(x)     cout<<#x<<" = "<<x<<endl
#define SORT(v)     sort(ALL(v))
#define SZ(v)       (ll)(v).size()
#define UNIQ(v)     SORT(v);(v).erase(unique(ALL(v)),(v).end())
#define PERM(v)     for(bool p=1;p;p=next_permutation(ALL(v)))
#define PQ(T)       priority_queue<T,vector<T>,greater<T>>

template<class T>string join(const vector<T>& v,string d=" ")
{stringstream s;REP(i,SZ(v))s<<d<<v[i];return s.str().substr(LEN(d));}

template<class T>ostream& operator<<(ostream& s,const vector<T>& v)
{s<<"{";if(SZ(v))s<<join(v,", ");s<<"}";return s;}

template<class T>bool contain(const string& s,const T& v)
{return s.find(v)!=NPOS;}

template<class T,class U>string& replace(string& s,const T& f,const U& t)
{for(auto p=s.find(f);p!=NPOS;p=s.find(f,p+LEN(t)))s.replace(p,LEN(f),t);}

const ll INF = 1e15;
const ll MOD = 1e9+7;
const double EPS = 1e-10;

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

int main() {
    ll a, b, h; cin >> a >> b >> h;
    cout << (a + b) * h / 2 << endl;
    
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define ios ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define hell1 1e9+7
#define hell2 1e9+9
#define pi 3.1415926535
#define ms(s, n) memset(s, n, sizeof(s))
#define prec(n) fixed<<setprecision(n)
#define eps 0.000001
#define all(v) v.begin(), v.end()
#define allr(v) v.rbegin(), v.rend()
#define ll long long
#define ld long double 
#define no_of_digits(n) floor(log10(n)) + 1
#define see(x) cout << (#x) << " is " << (x) << endl
#define INF 1e9

using namespace std;

ll mult(ll a,ll b, ll p=hell1){   return ((a%p)*(b%p))%p; }
ll multbig(ll a,ll b,ll mod=hell1){   if(a==0 or b==0) return 0;if(a==1 or b==1) return (a*b)%mod;ll cur=multbig(a,b/2,mod);cur=(2*cur)%mod;if(b%2) cur=(cur+a)%mod;return cur;
}
ll add(ll a, ll b, ll p=hell1){ if(a>=p) a%=p; if(b>=p) b%=p; if(a+b>p) return (a + b)%p; else return a+b;}
ll sub(ll a, ll b, ll p=hell1){return (a%p - b%p + p)%p;}
ll fpow(ll n, ll k, ll p = hell1) {ll r = 1; for (; k; k >>= 1) {if (k & 1) r = mult(r,n,p); n = mult(n,n,p);} return r;}
ll inv(ll a, ll p = hell1) {return fpow(a, p - 2, p);}
ll inv_euclid(ll a, ll m = hell1){ll m0 = m;ll y = 0, x = 1;if (m == 1)return 0;while (a > 1){ll q = a / m;ll t = m;m = a % m, a = t;t = y;y = x - q * y;x = t;}if (x < 0)x += m0;return x;}
int isPowerof2(ll x) { return (x && !(x & x-1)); } 
ll log2(ll x) { ll res = 0; while (x >>= 1) res++; return res; } 

// max({a, b, c, d})

vector<ll>adj[200005];
ll update[200005];
ll ans[200005];

int binaryToDecimal(string n) 
{ 
    string num = n; 
    int dec_value = 0; 
  
    // Initializing base value to 1, i.e 2^0 
    int base = 1; 
  
    int len = num.length(); 
    for (int i = len - 1; i >= 0; i--) { 
        if (num[i] == '1') 
            dec_value += base; 
        base = base * 2; 
    } 
  
    return dec_value; 
} 

bool isPerfectSquare(long double x) 
{   
  // Find floating point value of  
  // square root of x. 
  long double sr = sqrt(x); 
  
  // If square root is an integer 
  return ((sr - floor(sr)) == 0); 
} 

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

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

    ll ans = INF;

    ll pre[n];
    pre[0] = a[0];
    for(int i=1;i<n;i++)
        pre[i] = pre[i-1] + a[i];

    for(int i=0;i<n;i++)
    {
        ans = min(ans, abs(sum-2*pre[i]));
    }

    cout << ans << "\n";
}




Measured memory_bytes: 6016
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int H, W;
  cin >> H >> W;
  vector<string> a(H, ".");
  for (int i = 0; i < H; i++) {
    cin >> a.at(i);
  }
  
  vector<bool> row(H);
  vector<bool> column(W);
  
  for (int i = 0; i < H; i++) {
    for (int j = 0; j < W; j++) {
      if(a.at(i).at(j) == '#'){
        row.at(i) = true;
        column.at(j) = true;
      }
    }
  }

  for (int i = 0; i < H; i++) {
    if(row.at(i)) {
      for (int j = 0; j < W; j++) {
        if(column.at(j)){
          cout << a.at(i).at(j);
        }
      }
      
      cout << endl;
    }
  }
}

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

using namespace std;
#define rep(i, n) for(int i = 0; i < (int)(n); ++i)
typedef long long ll;
char mine[55][55];
int main() {
    int h, w;
    cin >> h >> w;
    rep(i, h) rep(j, w) cin >> mine[i+2][j+2];
    for(int i = 0; i < h; i++) {
        string s;
        for(int j = 0; j < w; j++) {
            if(mine[i+2][j+2] == '#') s += '#';
            else {
                int cnt = 0;
                for(int x = -1; x <= 1; x++) {
                    for(int y = -1; y <= 1; y++) {
                        if(mine[i+2+x][j+2+y] == '#') cnt += 1;
                    }
                }
                s += to_string(cnt);
            }
        }
        cout << s << endl;
    }
}

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

int main()
{
	int N;
	cin >> N;
	long long ans = 0;
	for(int i = 1; i <= N; i++)
	{
		int res = N/i;
		if(i*res == N)
		res -- ;
		ans = ans + res;
	}
	cout << ans << endl;
 } 

Measured memory_bytes: 3188
#include<bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i=0; i<n; i++)
typedef long long ll;
typedef pair<int, int> P;
 
int main(){
  string s, t;
  cin >> s;
  cin >> t;

  if(s.size()!=t.size()-1){
    cout << "No" << endl;
    return 0;
  }
  for(int i=0; i<s.size(); i++){
    if(s.at(i)!=t.at(i)){
      cout << "No" << endl;
      return 0;
    }
  }
  cout << "Yes" << endl;
  return 0;
}

Measured memory_bytes: 3628
#include <bits/stdc++.h>
#define REP(i, n) for (int i = 0; i < (int)(n); i++)
using namespace std;
template<class T>inline bool chmax(T &a, const T &b){if(a < b){a = b; return 1;}return 0;}
template<class T>inline bool chmin(T &a, const T &b){if(a > b){a = b; return 1;}return 0;}
typedef long long ll;
int main(){
  ios::sync_with_stdio(false);
  cin.tie(0);
  int N; cin >> N;
  vector<int> A(N, 0);
  for(auto &i : A) cin >> i;
  int q; cin >> q;
  vector<int> m(q, 0);
  for(auto &i : m) cin >> i;
  vector<bool> v(2001, false);
  REP(i, 1<<N){
    int tmp = 0;
    REP(j, N){
      if((i >> j) & 1) tmp += A[j];
    }
    if(tmp <= 2000) v[tmp] = true;
  }
  REP(i, q){
    if(v[m[i]]){
      cout << "yes" << endl;
    }else{
      cout << "no" << endl;
    }
  }
}



Measured memory_bytes: 3216
#include <algorithm>
#include <iostream>
#include <stack>
#include <queue>
#include <cmath>
#include <string>
#include <iterator>
#include <map>
#include <set>
#include <iomanip>
#include <vector>
#include <cstdint>
using namespace std;
using ll = long long;
using ld = long double;
using P = pair<ll, ll>;
using Graph = vector<vector<int>>;
int dx[] = {0, 1, 0, -1};
int dy[] = {1, 0, -1, 0};
#define rep(i, N) for(int i = 0; i < N; i++)
#define rep2(i, l, r) for (ll i = (ll)l; i < (ll)(r); i++)
#define INF 1000000000000000
#define MAX 200001

#pragma GCC target("avx2")
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")
const ll MOD = 998244353;

template <typename T > inline string toString(const T &a) {ostringstream oss; oss << a; return oss.str();};

int main(){
    int N, C;
    cin >> N >> C;
    vector<vector<int>> D(C,vector<int>(C));
    vector<vector<int>> c(N,vector<int>(N));
    rep(i,C)rep(j,C) cin >> D[i][j];
    rep(i,N)rep(j,N) cin >> c[i][j];
    vector<vector<ll>> cnt(3,vector<ll>(C,0));
    rep(i,N)rep(j,N){
        rep(color,C){
            cnt[(i+j) % 3][color] += D[c[i][j]-1][color];
        }
    }
    ll ans = INF;
    rep(i,C)rep(j,C)rep(k,C){
        if(i == j or j == k or k == i) continue;
        ans = min(ans, cnt[0][i] + cnt[1][j] + cnt[2][k]);
    }
    cout << ans << endl;
}

Measured memory_bytes: 4612
#define _CRT_SECURE_NO_WARNINGS
#define _USE_MATH_DEFINES
#include <iostream>
#include <cstdio>
#include <vector>
#include <string>
#include <array>
#include <queue>
#include <deque>
#include <set>
#include <list>
#include <map>
#include <stack>
#include <utility>
#include <bitset>
#include <complex>
#include <algorithm>
#include <numeric>
#include <cstdlib>
#include <cmath>
#include <cctype>
#include <cstring>
#include <climits>
#include <random>
#include <functional>
#include <sstream>
#include <iomanip>

using namespace std;

#define rep(i, n) for(int i=0; i<(n); i++)
#define FOR(i, m, n) for(int i=(m);i<(n);i++)
#define sz(x) ((int)(x).size())
#define all(x) (x).begin(),(x).end()
#define SORT(x) sort((x).begin(),(x).end())
#define REVE(x) reverse((x).begin(),(x).end())
#define mp make_pair
#define pb push_back
#define Cout(x) cout << (x) << endl
#define Cout2(x, y) cout << (x) << " " << (y) << endl
#define dump(x) cout << #x << " = " << (x) << endl;
#define forauto(i, a) for(auto i : a)cout << i << " "; puts("");

typedef long long LL;
typedef vector<int> VI;
typedef vector<LL> VL;
typedef vector<string> VS;
typedef vector<bool> VB;
typedef vector<vector<int>> VVI;
typedef pair<int, int> PII;
typedef pair<double, double> PDD;
typedef complex<double> CD;

void vec_print(VI v) {
	int vsize = sz(v);
	rep(i, vsize) {
		cout << v[i];
		printf(i == vsize - 1 ? "\n" : " ");
	}
}

int main() {
	int n; cin >> n;
	VI a(n); rep(i, n)cin >> a[i];

	VI v = a;
	if (prev_permutation(all(v))) {
		vec_print(v);
	}

	vec_print(a);

	VI w = a;
	if (next_permutation(all(w))) {
		vec_print(w);
	}
}


Measured memory_bytes: 3304
#include <stdio.h>

int main(void)
{
    int H, W, i, j;
    
    while(1)
    {
        scanf("%d %d", &H, &W);
        if(H == 0 && W == 0)
        {
            break;
        }
        else
        {
            for(i = 0; i < H; i++)
            {
                for(j = 0; j < W; j++)
                {
                    if(((i + j) % 2) == 0)
                    {
                        printf("#");
                    }
                    else
                    {
                        printf(".");
                    }
                }
                printf("\n");
            }
            printf("\n");
        }
    }
    
    return 0;
}

Measured memory_bytes: 572
def judge_odd():
    for i in a:
        if i % 2 == 1:
            return True
    return False


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

cnt = 0
while True:
    if judge_odd():
        break
    for idx, v in enumerate(a):
        a[idx] = v // 2
    cnt += 1
print(cnt)


Measured memory_bytes: 2940
#include<bits/stdc++.h>
using namespace std;
#define inf INT_MAX
#define INF LLONG_MAX
#define ll long long
#define ull unsigned long long
#define M (int)(1e9+7)
#define P pair<int,int>
#define PLL pair<ll,ll>
#define FOR(i,m,n) for(int i=(int)m;i<(int)n;i++)
#define RFOR(i,m,n) for(int i=(int)m;i>=(int)n;i--)
#define rep(i,n) FOR(i,0,n)
#define rrep(i,n) RFOR(i,n,0)
#define all(a) a.begin(),a.end()
#define IN(a,n) rep(i,n){ cin>>a[i]; }
const int vx[4] = {0,1,0,-1};
const int vy[4] = {1,0,-1,0};
#define F first
#define S second
#define PB push_back
#define EB emplace_back
#define int ll
#define vi vector<int>
#define IP pair<int,P>
#define PI pair<P,int>
#define PP pair<P,P>
#define Yes(f){cout<<(f?"Yes":"No")<<endl;}
#define YES(f){cout<<(f?"YES":"NO")<<endl;}




template< typename Monoid >
struct segTree {
  using F = function< Monoid(Monoid, Monoid) >;

  int sz;
  vector< Monoid > seg;

  const F f;
  const Monoid M1;

  segTree(int n, const F f, const Monoid &M1) : f(f), M1(M1) {
    sz = 1;
    while(sz < n) sz <<= 1;
    seg.assign(2 * sz, M1);
  }

  void set(int k, const Monoid &x) {
    seg[k + sz] = x;
  }

  void build() {
    for(int k = sz - 1; k > 0; k--) {
      seg[k] = f(seg[2 * k + 0], seg[2 * k + 1]);
    }
  }

  void update(int k, const Monoid &x) {
    k += sz;
    seg[k] = x;
    while(k >>= 1) {
      seg[k] = f(seg[2 * k + 0], seg[2 * k + 1]);
    }
  }

  Monoid get(int a, int b) {
    Monoid L = M1, R = M1;
    for(a += sz, b += sz; a < b; a >>= 1, b >>= 1) {
      if(a & 1) L = f(L, seg[a++]);
      if(b & 1) R = f(seg[--b], R);
    }
    return f(L, R);
  }

  Monoid operator[](const int &k) const {
    return seg[k + sz];
  }
};


signed main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout<<fixed<<setprecision(20);

  int n,m;
  cin>>n>>m;
  vector<PI> v;
  rep(i,m){
    int x,y,z;
    cin>>x>>y>>z;
  
    v.PB(PI(P(x,y),z));
  }
  sort(all(v));

  segTree<int> seg(n+1,[](int a,int b){return min(a,b);},INF);

  seg.update(1,0);


  rep(i,m){
    int sum=seg.get(v[i].F.F,v[i].F.S);
    if(sum==INF) continue;
    if(seg.get(v[i].F.S,v[i].F.S+1)>sum+v[i].S)
      seg.update(v[i].F.S,sum+v[i].S);
  }

  /*
  rep(i,n+1){
    cout<<seg.get(i,i+1)<<endl;
  }
  */

  cout<<(seg.get(n,n+1)==INF?-1:seg.get(n,n+1))<<endl;

  
}

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


Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
#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 For(i,a,b) for(auto i=(a);i<=(b);++i)
#define rFor(i,a,b) for(auto i=(b);i>=(a);--i)
#define call(var) cerr<<#var<<"="<<var<<"\n";
#define dup(x,y) (((x)+(y)-1)/(y))
#define all(x) (x).begin(),(x).end()
using ll=long long;
using vi = vector<int>;
using vl = vector<ll>;
using vb = vector<bool>;
using Graph = vector<vi>;
using P = pair<int,int>;
const int MOD=(int)1e9+7;
const int INF=(int)1e9;
const ll LINF=(ll)1e18;
const double pi = acos(-1);
template<class t,class u> inline bool chmax(t&a,u b){if(a<b){a=b;return true;}return false;}
template<class t,class u> inline bool chmin(t&a,u b){if(b<a){a=b;return true;}return false;}
template<class T> istream& operator>>(istream& is, vector<T>& a){rep(i,a.size()) is >> a[i]; return is;}
template<class T> ostream& operator<<(ostream& os, vector<T>& a){rep(i,a.size()) os << a[i] << " "; return os;}
template<class T, class U> istream& operator>>(istream& is, pair<T,U>& p){is >> p.first >> p.second; return is;}
template<class T, class U> ostream& operator<<(ostream& os, const pair<T,U>& p){os << "("<< p.first << "," << p.second << ")"; return os;}
template<class T, class U> ostream& operator<<(ostream& os, const map<T,U>& mp){for(auto& t : mp) os << t.first << " " << t.second << "\n"; return os;}

int main(){
    int k;cin >> k;
    ll se = 0;
    for(int i=1;i<=k;++i){
        se = (se * 10 + 7) % k;
        if(se == 0){
            cout << i << endl;
            return 0;
        }
    }
    cout << -1 << endl;
}

Measured memory_bytes: 3676
#include<iostream>
#include<algorithm>
#include<cmath>
using namespace std;
int main() {
  int n,s[10000];
  cin >> n;
  for(int i=0; i<n; i++) {
      cin >> s[i];
  }
  int q;
  cin >> q;
  int ans=0;
  while(q--) {
      int a;
      cin >> a;
      for(int i=0; i<n; i++) {
          if(a==s[i]) {
              ans++;
              break;
          }
      }
  }
  cout << ans << endl;
}


Measured memory_bytes: 3124
//#include "debug.h"
#include <string.h>
#include <limits.h>
#include <map>
#include <set>
#include <vector>
#include <algorithm>
using namespace std;

#define MAXN 100000

int n;
char s[MAXN];

int input() {
	if (scanf("%s", s) < 0) return 0;
	return 1;
}

void init() {
}

int solve() {
	int r = 0;
	for (int i=1; s[i]; i++) {
		if (s[i] != s[i-1]) r++;
	}
	return r;
}

void output(int ans) {
	printf("%d\n", ans);
}

void cleanup() {
}

int main() {
	//int ca; scanf("%d", &ca);
	while (input()) {
		init();
		output(solve());
		cleanup();
		//break;
	}
}





Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <string>
#include <vector>
#include <algorithm>
#include <list>
#include <iomanip>
#include <queue>
#include <functional>
#include <cassert>
#include <cmath>
#include <set>
#define REP(i, n) for(int i = 0; i < (n); i++)
#define FOR(i, a, b) for(int i = (a); i < (b); i++)
#define NL << endl
using namespace std;
using ll = long long;
int INFINT = 1 << 30;
ll INFLL = 1LL << 60;
int gcd(int a, int b) {return b ? gcd(b, a%b) : a;}

int main() {

	ll x, y;

	cin >> x >> y;

	int ans = 0;
	while (x <= y) {
		x *= 2;
		ans++;
	}

	cout << ans NL;

	return 0;

}


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

using namespace std;

map<int,int> mymap;

int main(){
    bool flag = true;
    int a,b;
    cin>>a;
    while(a--){
        cin>>b;

        mymap[b]++;
    }

    for(auto a:mymap){
        if(a.second >1){
            flag = false;
            break;
        }
        
    }
    if(flag) cout<<"YES\n";
    else cout<<"NO\n";
    return 0;
}

Measured memory_bytes: 9600
#include <bits/stdc++.h>
#define rep(i, a, b) for(ll i = ll(a); i < ll(b); i++)
#define rer(i, a, b) for(ll i = ll(a) - 1; i >= ll(b); i--)
#define sz(v) (int)(v).size()
#define pb push_back
#define sc second
#define fr first
#define sor(v) sort(v.begin(),v.end())
#define rev(s) reverse(s.begin(),s.end())
#define lb(vec,a) lower_bound(vec.begin(),vec.end(),a)
#define ub(vec,a) upper_bound(vec.begin(),vec.end(),a)
#define uniq(vec) vec.erase(unique(vec.begin(),vec.end()),vec.end())
using namespace std;
typedef long long int ll;
typedef pair <ll, ll> P;

const ll MOD=1000000007;
const int MAX_N=1<<18;
struct LazySegmentTree{
    ll node[2*MAX_N-1];
    ll lazy[2*MAX_N-1];
    ll SIZE; //SIZE:nを２べきにしたもの
    bool lazyflag[2*MAX_N-1];
    //初期化
    void init(int n_){
        //要素数を2べきに
        SIZE=1;
        while(SIZE<n_) SIZE*=2;
        
        //全ての値をI_MAXに
        rep(i,0,2*SIZE-1) node[i]=0;
    }
    
    //k番目のノードについて遅延評価を行う
    void eval(int k, int l, int r){
        // 遅延配列が空でない場合、自ノード及び子ノードへの値の伝播が起こる
        if(lazyflag[k]){
            node[k]+=lazy[k];
            // 最下段かどうかのチェックをしよう
            if(r-l>1){
                lazy[k*2+1] += lazy[k];
                lazy[k*2+2] += lazy[k];
                lazyflag[k*2+1] = lazyflag[k*2+2] = true;
            }
            lazyflag[k] = false;
            lazy[k]=0;
        }
    }
    
    void add(int a, int b, ll x, int k=0, int l=0, int r=-1){
        if(r<0) r=SIZE;
        eval(k,l,r);
        if(b <= l || r <= a) return;
        if(a <= l && r <= b) {
            lazy[k] += x;
            lazyflag[k]=true;
            eval(k, l, r);
        }
        else{
            add(a, b, x, 2*k+1, l, (l+r)/2);
            add(a, b, x, 2*k+2, (l+r)/2, r);
            node[k]=min(node[2*k+1], node[2*k+2]);
        }
    }
    
    ll getmin(int a, int b, int k=0, int l=0, int r=-1){
        if(r<0) r=SIZE;
        eval(k,l,r);
        if(b <= l || r <= a) return 1e8;
        if(a <= l && r <= b) return node[k];
        ll vl=getmin(a, b, 2*k+1, l, (l+r)/2);
        ll vr=getmin(a, b, 2*k+2, (l+r)/2, r);
        return min(vl, vr);
    }
};
LazySegmentTree L,R;
int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    ll N,M;
    cin>>N>>M;
    L.init(M); R.init(M);
    rep(i,0,N){
        ll l,r;
        cin>>l>>r;
        L.add(0, l, 1);
        R.add(r-1, M, 1);
    }
    ll res=1e8;
    ll ans=0;
    rep(i,0,M){
        res=min(res-1,L.getmin(i, i+1));
        if(res==0){
            ans=i;
            break;
        }
        if(i==M-1) ans=M;
    }
    res=1e8;
    rep(i,0,M){
        res=min(res-1,R.getmin(M-1-i, M-i));
        if(res==0){
            ans+=i;
            break;
        }
        if(i==M-1) ans+=M;
    }
    cout <<max(0LL,N-min(ans,M))<<"\n";
}

Measured memory_bytes: 17024