akhauriyash/Code-Regression huggingface dataset:
#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 - 1; 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());
 
using ll = long long;
using vll = vector<ll>;
using vvll = vector<vector<ll>>;
using P = pair<ll, ll>;

ll mod = 1e9 + 7;

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

    ll n;
    cin >> n;
    ll a, b, c, d;
    cin >> a >> b >> c >> d;
    a--, b--, c--, d--;
    string s;
    cin >> s;

    //a->c or b->d is unreachable
    REP(i, n - 1){
        if(s[i + 1] == '#' && s[i] == '#'){
            if((a < i && c > i + 1) || (b < i && d > i + 1)){
                cout << "No" << endl;
                return 0;
            }
        }
    }

    //need not to swap
    if(c < d){
        cout << "Yes" << endl;
        return 0;
    }

    ll swappable = 0;
    REP(i, n - 2){
        if(s[i + 2] == '.' && s[i + 1] == '.' && s[i] == '.' && b <= i + 1 && d >= i + 1) swappable = 1;
    }
    if(swappable) cout << "Yes" << endl;
    else cout << "No" << endl;
    return 0;
}

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

int main()
{
    int a,b;
    cin >> a >> b;

    int sum = 1;
    int cnt = 0;
    while(sum < b)
    {
        sum += a-1;
        ++cnt;
    }

    cout << cnt;
    return 0;
}

Measured memory_bytes: 256
def make_divisors(n):
    divisors = []
    for i in range(1, int(n**0.5)+1):
        if n % i == 0:
            divisors.append(i)
            if i != n // i:
                divisors.append(n//i)

    divisors.sort()
    return divisors


N = int(input())
minimum = N+1
for i in make_divisors(N):
    if i + (N // i) <= minimum:
        minimum = i + (N // i)


print(minimum - 2)


Measured memory_bytes: 3272
import sys
input = sys.stdin.readline
def main():
    N = int(input())
    A = list(map(int, input().split()))
    W = [0]*N
    W[0] = A[0]
    for i in range(1,N):
        W[i] += W[i-1] + A[i]
    ans = 0
    for i in range(N-1):
        ans += A[i]*(W[N-1] - W[i])
    print(ans%(10**9+7))

if __name__ == '__main__':
    main()

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

using namespace std;

typedef long long ll;
typedef pair<long, int> pli;

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

	int N, M;
	cin >> N >> M;

	map<int, vector<ll>> mp;
	rep(i, N){
		int a;
		ll b;
		cin >> a >> b;

		mp[M - a].push_back(b);
	}

	priority_queue<int> pq;
	ll ans = 0;
	for(int i = M-1; i >= 0; i--){
		for(int j = 0; j < mp[i].size(); j++){
			pq.push(mp[i][j]);
		}

		if(!pq.empty()){
			ans += pq.top();
			pq.pop();
		}
	}

	cout << ans << endl;
}


Measured memory_bytes: 10880
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
constexpr ll MOD = 1e9 + 7;
//constexpr ll MOD = 998244353;
//constexpr ll MOD = ;
ll mod(ll A, ll M) {return (A % M + M) % M;}
constexpr ll INF = 1LL << 60;
template<class T> bool chmin(T& a, T b) {if (a > b) {a = b; return true;} return false;}
template<class T> bool chmax(T& a, T b) {if (a < b) {a = b; return true;} return false;}
ll divceil(ll A, ll B) {return (A + (B - 1)) / B;}
#define FINALANS(A) do {cout << (A) << '\n'; exit(0);} while (false)

using ld = long double;

struct edge
{
  ll to;
  ld cost;
  edge(ll to, ld cost) : to(to), cost(cost) {}

  bool operator<(const edge& right) const
  {
    return (cost == right.cost) ? (to < right.to) : (cost < right.cost);
  }

  bool operator>(const edge& right) const
  {
    return (cost == right.cost) ? (to > right.to) : (cost > right.cost);
  }
};

ld d(ll x0, ll y0, ll r0, ll x1, ll y1, ll r1)
{
  return max(0.0L, sqrtl((x1 - x0) * (x1 - x0) + (y1 - y0) * (y1 - y0)) - r0 - r1);
}

int main()
{
  ll xs, ys, xt, yt;
  cin >> xs >> ys >> xt >> yt;
  ll N;
  cin >> N;
  vector<ll> X(N), Y(N), R(N);
  for (ll i = 0; i < N; i++)
  {
    cin >> X.at(i) >> Y.at(i) >> R.at(i);
  }
  X.push_back(xs), Y.push_back(ys), R.push_back(0);
  X.push_back(xt), Y.push_back(yt), R.push_back(0);

  vector<vector<edge>> G(N + 2);
  for (ll i = 0; i < N + 2; i++)
  {
    for (ll j = i + 1; j < N + 2; j++)
    {
      ld d0 = d(X.at(i), Y.at(i), R.at(i), X.at(j), Y.at(j), R.at(j));
      G.at(i).push_back(edge(j, d0));
      G.at(j).push_back(edge(i, d0));
    }
  }

  using pdl = pair<ld, ll>;

  vector<ld> dist(N + 2, -1);
  priority_queue<pdl, vector<pdl>, greater<pdl>> que;
  que.push(make_pair(0, N));

  while (!que.empty())
  {
    auto p = que.top();
    que.pop();
    ld d = p.first;
    ll v = p.second;

    if (dist.at(v) != -1)
      continue;
    dist.at(v) = d;

    for (auto e : G.at(v))
    {
      if (dist.at(e.to) == -1)
        que.push(make_pair(d + e.cost, e.to));
    }
  }

  cout << fixed << setprecision(15) << dist.at(N + 1) << endl;
}

Measured memory_bytes: 51116
#include <bits/stdc++.h>
using namespace std;
#define int long long
const int MOD = 1000000007;


signed main(){
 int n,suma=0;
 cin>>n;
 int a[n],m=0,mina=MOD;
    for(int i=0;i<n;i++){
        cin>>a[i];
        if(a[i]<0&&m>=0)m++;
        if(a[i]==0)m=-2;
        suma+=abs(a[i]);
        mina=min(mina,abs(a[i]));
    }
    if(m%2 ==0)cout<<suma;
    else cout << suma-2*mina;


  
    return 0;
}

Measured memory_bytes: 1024
/*
Though leaves are many , the root is one.
Through all the lying days of my youth
I swayed my leaves and flowers in the sun.
Now I may wither into the truth.
	  	  	- William Butler Yeats
*/
//#pragma GCC optimize("Ofast,no-stack-protector")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx")
//#pragma GCC target("avx,tune=native")
#include<bits/stdc++.h>
//#include<ext/pb_ds/assoc_container.hpp>
using namespace std;
//using namespace __gnu_pbds;
const int inf=0x3f3f3f3f;
const double eps=1e-6;
const int mod=1000000007;
typedef long long ll;
#ifndef LOCAL
#define cerr if(0)cout
#endif
#define eprintf(...) fprintf(stderr, __VA_ARGS__)
inline string getstr(string &s,int l,int r){string ret="";for(int i=l;i<=r;i++)ret.push_back(s[i]);return ret;}
int modpow(int x,int y,int md=mod){if(y==0)return 1;int ret=modpow(x,y>>1,md);ret=(ll)ret*ret%md;if(y&1)ret=(ll)ret*x%md;return ret;}
int n;
multiset<int>S,T;
int main(){
	cin>>n;
	for(int i=0;i<(1<<n);i++){
		int x;cin>>x;S.insert(x);
	}
	T.insert(*S.rbegin());
	S.erase(S.find(*S.rbegin()));
	for(int i=1;i<=n;i++){
		vector<int>Insert;
		auto x=T.rbegin();
		for(;x!=T.rend();x++){
			auto itr=S.lower_bound(*x);
			if(itr==S.begin()){
				puts("No");
				return 0;
			}
			itr--;
			Insert.push_back(*itr);
			S.erase(itr);
		}
		for(auto x:Insert)T.insert(x);
	}
	puts("Yes");
	return 0;
}

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

using namespace std;

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

using ll = long long;

const int Inf = 100100100;
const double EPS = 1e-9;

template <typename T>
T gcd(T a, T b) {
    if (b == 0) {
        return a;
    } else {
        return gcd(b, a % b);
    }
}

template <typename T>
T lcm(T a, T b) {
    return a / gcd(a, b) * b;
}

template <typename T>
class SegmentTree {
    public:
        int n;
        vector<T> data;
        T e;
        function<T(T, T)> operation;
        function<T(T, T)> process;

        SegmentTree() {}
        SegmentTree(int n_, T e_, function<T(T, T)> operation_, 
            function<T(T, T)> process_) : e(e_), operation(operation_), process(process_) {
            n = 1;
            while (n < n_) n <<= 1;
            data.assign(2 * n, e);
        }

        T query(int a, int b) {
            return query(a, b + 1, 1, 0, n);
        }

        T query(int a, int b, int k, int l, int r) {
            if (a >= r || b <= l) return e;
            if (a <= l && b >= r) return data[k];
            T c = query(a, b, 2 * k + 0, l, (l + r) / 2);
            T d = query(a, b, 2 * k + 1, (l + r) / 2, r);
            return operation(c, d);
        }

        void update(int idx, T v) {
            idx += n;
            data[idx] = process(data[idx], v);
            while (idx >>= 1) {
                data[idx] = operation(data[2 * idx + 0], data[2 * idx + 1]);
            }
        }

        T operator[](int idx) {
            return data[idx + n];
        }
};

int main() {
    cin.tie(nullptr);
    ios::sync_with_stdio(0);
    int n;
    cin >> n;
    SegmentTree<ll> seg = SegmentTree<ll>(n, 0,
            [](ll a, ll b) { return gcd(a, b); }, [](ll a, ll b) { return b; });

    rep (i, n) {
        ll a;
        cin >> a;
        seg.update(i, a);
    }
    ll res = 0;
    rep (i, n) {
        ll l = seg.query(0, i - 1);
        ll r = seg.query(i + 1, n);
        res = max(res, gcd(l, r));
    }
    cout << res << endl;
 
    return 0;
}


Measured memory_bytes: 5296
package main

import "fmt"

var n int

func hasDigit(a, b int) bool {
	for a > 0 {
		if a%10 == b {
			return true
		}
		a /= 10
	}
	return false
}

func dfs(a int) int {
	if a > n {
		return 0
	}
	ret := 0
	if hasDigit(a, 3) && hasDigit(a, 5) && hasDigit(a, 7) {
		ret++
	}
	return ret + dfs(a*10+3) + dfs(a*10+5) + dfs(a*10+7)
}

func main() {
	fmt.Scan(&n)
	fmt.Println(dfs(0))
}


Measured memory_bytes: 512
/*
 * a.cc: 
 */

#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<iostream>
#include<string>
#include<vector>
#include<map>
#include<set>
#include<stack>
#include<list>
#include<queue>
#include<deque>
#include<algorithm>
#include<numeric>
#include<utility>
#include<complex>
#include<functional>

using namespace std;

/* constant */

const int MAX_N = 10000;
const int MAX_Q = 500;

/* typedef */

/* global variables */

int ss[MAX_N];

/* subroutines */

/* main */

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

  for (int i = 0; i < n; i++) cin >> ss[i];

  int q;
  cin >> q;

  int cnt = 0;
  while (q--) {
    int ti;
    cin >> ti;

    for (int i = 0; i < n; i++)
      if (ti == ss[i]) {
	cnt++;
	break;
      }
  }

  printf("%d\n", cnt);
  return 0;
}



Measured memory_bytes: 3156
using System;
using static System.Console;

class Program
{
    public static void Main(string[] args)
    {
        string input = ReadLine();
        int inputcount = input.Length;
        char[] chararray = input.ToCharArray();
        WriteLine(chararray[0] + (inputcount - 2).ToString() + chararray[inputcount - 1]);
    }
}

Measured memory_bytes: 13140
#include<iostream>
#include<vector>
#include<algorithm>

using namespace std;

struct bridge{
  int qual;
  int max_w;
  bool operator<(const bridge &br)const{
    return max_w < br.max_w;
  }
};

int main(){
  while(true){
    int n;
    bool visi[26]={false,};
    vector<bridge> brs;
    cin >> n;
    if(n==0)break;
    for(int i = 0; i < n; ++i){
      bridge br;
      cin >> br.qual >> br.max_w;
      brs.push_back( br );
    }
    int nowW = 0;
    bool bSucceeded = true;
    sort( brs.begin(), brs.end() );
    for(int i = 0; i < brs.size(); ++i){
      if( nowW + brs[i].qual <= brs[i].max_w )
	nowW += brs[i].qual;
      else{
	bSucceeded = false;
	break;
      }
    }
    cout << ( ( bSucceeded ) ? "Yes" : "No" ) << endl;
  }
  return 0;
}

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

int main() {
  string s;
  cin >> s;
  int counter;
  if(s[0] == '1') ++counter;
  if(s[1] == '1') ++counter;
  if(s[2] == '1') ++counter;
  cout << counter << endl;
}

Measured memory_bytes: 256
/*
 * a.c
 *
 *  Created on: 2017/06/13
 *      Author: AWV060608
 */

#include	<stdio.h>

int		main(void)
{
	int		a, b;

	scanf("%d",&a);
	scanf("%d",&b);

	if( a == b )
	{
		printf("a == b\n");
	}
	else if( a > b )
	{
		printf("a > b\n");
	}
	else
	{
		printf("a < b\n");
	}
	return 0;
}

Measured memory_bytes: 580
#include <iostream>
#include <vector>
using namespace std;
typedef long long LL;
int main(int argc, char* argv[])
{
	int N,i;
	cin>>N;
	vector<LL> A(N+1),B(N);
	for (i=0;i<N+1;i++){
		cin>>A[i];
	}
	for (i=0;i<N;i++){
		cin>>B[i];
	}
	LL Max=0;
	for (i=0;i<N;i++){
		if (A[i]+A[i+1]>=B[i]){
			Max+=B[i];
			A[i]-=B[i];
			if (A[i]<0){
				A[i+1]+=A[i];
			}
			B[i]=0;
		}else{
			Max+=A[i]+A[i+1];
			B[i]-=A[i]+A[i+1];
			A[i]=0;
			A[i+1]=0;
		}
	}
	if (A[N]>=B[N-1]){
		Max+=B[N-1];
	}else{
		Max+=A[N];
	}
	cout<<Max<<endl;
	return 0;
}

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


int main() {
  long long x;
  cin >> x;
  int a, b, c, ans;
  a = x / 500;
  b = x % 500;
  c = b / 5;
  
  ans = 1000 * a + 5 * c;
  cout << ans;
  
}

Measured memory_bytes: 256
from collections import deque

room_num, path_num = map(int, input().split(" "))
graph = [[] for _ in range(room_num)]
dis = [-1] * room_num
for _ in range(path_num):
    a, b = map(int, input().split(" "))
    graph[a-1].append(b-1)
    graph[b-1].append(a-1)
dis[0] = 0
q = deque()
q.append(0)
while q:
    pop = q.popleft()
    for n in graph[pop]:
        if dis[n] > 0:
            pass
        else:
            dis[n] = pop+1
            q.append(n)
if -1 in dis:
    print("No")
else:
    del dis[0]
    print("Yes")
    for s in dis:
        print(s)

Measured memory_bytes: 36848
#include<bits/stdc++.h>
using namespace std;
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
#define ordered_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update>
#define ll long long
#define si(n) scanf("%d",&n);
#define PI acos(-1.0)
#define sl(n) scanf("%lld",&n);
#define sf(n) scanf("%lf",&n);
#define ss(n) scanf("%s",n);
#define for0(i,n) for(ll i=0;i<n;i++)
#define for1(i,n) for(ll i=1;i<=n;i++)
#define forc(i,j,n) for(ll i=j;i<n;i++)
#define pb push_back
#define sor(n) sort(n.begin(),n.end())
#define sorcmp(n) sort(n.begin(),n.end(),cmp)
#define rev(n) reverse(n.begin(),n.end())
#define pi(x)  printf("%d",x);
#define pl(x)  printf("%lld",x);
#define pf(x)  printf("%.10lf",x);
#define ps(x)  printf("%s",x);
#define en() printf("\n");
#define random_shuffle(r...)random_shuffle(r,[](int _){return rand()%_;})
#define SQR(a) (a)*(a)
#define sp(x) fixed<<setprecision(x)
#define mod 1000000007
#define endl '\n'
#define pii pair<int,int>
#define pll pair<ll,ll>
#define bug cout<<"Here"<<endl
void fastio(){ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);}
template <typename T> T POW(T B,T P){ if(P==0) return 1; if(P&1) return B*POW(B,P-1);  else return SQR(POW(B,P/2));}
ll powmod(ll a, ll b){ll ans = 1;while(b){if(b&1) ans = ans*a%mod;a = a*a%mod;b >>= 1;}return ans;}



int main(){
fastio();


     string str;
     cin>>str;
     int cnt=0;

     int mx=0;

     for(auto u:str)
     {
         if(u=='R') cnt++;
         else
         {
             mx=max(mx,cnt);
             cnt=0;
         }
     }

     mx=max(mx,cnt);

     cout<<mx<<endl;








return 0;
}



Measured memory_bytes: 3640
// editorialを読んだ
#include<iostream>
#include<vector>
using namespace std;

int main(){
    string s;
    cin >> s;
    int n = s.length();
    if(n == 1){
        cout << 1 << endl;
        return 0;
    }
    vector<vector<int>> dp(2, vector<int>(n, 0));
    dp[0][0] = 1;
    dp[1][1] = 1;
    dp[0][1] = s[1]!=s[0] ? 2 : 0;
    for(int i = 2; i < n; i++){
        dp[0][i] = dp[1][i-1]+1;
        if(s[i] != s[i-1])  dp[0][i] = max(dp[0][i], dp[0][i-1]+1);
        dp[1][i] = dp[0][i-2]+1;
        if(i-3 >= 0 && s.substr(i-3,2)!=s.substr(i-1,2))    dp[1][i] = max(dp[1][i], dp[1][i-2]+1);
    }
    cout << max(dp[0][n-1], dp[1][n-1]) << endl;
    return 0;
}

Measured memory_bytes: 2948
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<n;i++)
#define all(x) (x).begin(),(x).end()
using namespace std;
const int INF=1145141919,MOD=1e9+7;
const long long LINF=8931145141919364364,LMOD=998244353;
inline long long mod(long long n,long long m){return(n%m+m)%m;}
// const int dx[]={1,0,-1,0,1,1,-1,-1},dy[]={0,-1,0,1,1,-1,-1,1};

int main(){
    long long n,k; cin>>n>>k;
    long long a[n]; rep(i,n) cin>>a[i];
    long long cnt[40][2]={};
    rep(i,n){
        for(long long j=0;j<40;j++){
            cnt[j][a[i]>>j&1]++;
        }
    }
    long long ans=0;
    for(long long i=39;i>=0;i--){
        if(cnt[i][0]==0&&cnt[i][1]==0){
            if(ans+(1ll<<i)<=k){
                ans+=(1ll<<i);
            }
        }else{
            if(cnt[i][0]>cnt[i][1]){
                if(ans+(1ll<<i)<=k){
                    ans+=(1ll<<i);
                }
            }
        }
    }
    // cout<<ans<<endl;
    long long sum=0;
    rep(i,n){
        sum+=ans^a[i];
    }
    cout<<sum<<endl;
    return 0;
}


Measured memory_bytes: 1024
package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
)

var sc = bufio.NewScanner(os.Stdin)

func next() string {
	sc.Scan()
	return sc.Text()
}

func nextInt() int {
	sc.Scan()
	i, _ := strconv.Atoi(sc.Text())
	return i
}

func nextFloat64() float64 {
	f, _ := strconv.ParseFloat(next(), 64)
	return f
}

func nextInts(n int) []int {
	slice := make([]int, n)
	for i := 0; i < n; i++ {
		slice[i] = nextInt()
	}
	return slice
}

func main() {
	sc.Split(bufio.ScanWords)
	n := nextInt()
	a := nextInts(n)

	ans := 0
	l, r := 0, 0
	for r < n {
		if r+1 < n && a[r] == a[r+1] {
			r++
		}
		ans += (r - l + 1) / 2
		l, r = r+1, r+1
	}
	fmt.Println(ans)
}


Measured memory_bytes: 640
use std::io;


fn main() {
    loop {
        let s = read::<String>();
        let a = s[0].parse::<isize>().unwrap();
        let op = s[1].clone();
        let b = s[2].parse::<isize>().unwrap();
        if op == "?" { break; }
        let ans = match op.as_ref() {
            "+" => a + b,
            "-" => a - b,
            "*" => a * b,
            "/" => a / b,
            _   => unreachable!()
        };
        println!("{}", ans);
    }
}


#[allow(dead_code)]
fn read<T>() -> Vec<T>
where T:
std::str::FromStr,
T::Err: std::fmt::Debug {

    let mut buf = String::new();
    io::stdin().read_line(&mut buf).unwrap();
    buf.split_whitespace()
        .map(|s| s.trim().parse().unwrap())
        .collect()
}

#[allow(dead_code)]
fn read_one<T>() -> T
where T:
std::str::FromStr,
T::Err: std::fmt::Debug {

    let mut buf = String::new();
    io::stdin().read_line(&mut buf).unwrap();
    buf.trim().parse().unwrap()
}


Measured memory_bytes: 5036
#include <iostream>
#include <cmath>
#include <algorithm>
using namespace std;

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

	int ret = 0;
	int m2 = sqrt(m) + 1;
	for (int i = 1; i <= m2; ++i) {
		if (m % i != 0) {
			continue;
		}

		int t = m / i;
		if (n <= t) {
			ret = max(ret, i);
		}
		if (n <= i) {
			ret = max(ret, t);
		}
	}

	cout << ret << endl;

	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
 
using namespace std;
 
typedef long long LL;
typedef long double LD;


LL mod = 1000000007;

int main()
{
	LL h;
	cin >> h;

	LL sum = 0;
	LL tp = 1;
	while (h > 0) {
		sum += tp;
		h /= 2;
		tp *= 2;
	}

	cout << sum << "\n";



	
}

Measured memory_bytes: 256
n = gets.chomp.to_i
t0 = 1
a0 = 1
n.times do
  t1, a1 = gets.chomp.split(" ").map(&:to_i)
  dd = [(t0.to_r / t1).ceil, (a0.to_r / a1).ceil].max
  t0 = t1 * dd
  a0 = a1 * dd
end
puts t0 + a0

Measured memory_bytes: 1788
# include <iostream>
# include <cmath>
# include <algorithm>
# include <stdio.h>
# include <cstdint>
# include <cstring>
# include <string>
# include <cstdlib>
# include <vector>
# include <bitset>
# include <map>
# include <queue>
# include <ctime>
# include <stack>
# include <set>
# include <list>
# include <random>
# include <chrono>
# include <deque>
# include <functional>
# include <iomanip>
# include <sstream>
# include <fstream>
# include <complex>
# include <numeric>
# include <immintrin.h>
# include <cassert>
# include <array>
# include <tuple>
# include <cctype>
# include <unordered_map>
# include <unordered_set>
//#include <bits/stdc++.h>
 
#pragma GCC optimize("Ofast")
//#pragma GCC optimization("unroll-loops, no-stack-protector")
//#pragma GCC target("avx,avx2,fma")
 
#define forn(i, n) for (int i = 0; i < (n); i++)
#define forx(i,x,n) for (int i = x; i < (n); i++)
#define form(i, n) for (int i = n-1; i>=0; i--)
#define all(x) (x).begin(), (x).end()
#define vi vector<int>
#define vl vector<long long>
#define pb push_back
#define pf push_front
#define mp make_pair
#define ll long long
#define ld long double
#define ull unsigned ll
#define srt(a) sort(a.begin(), a.end());
#define pll pair<ll, ll>
#define pii pair<int,int>
#define pld pair<ld,ld>
#define ar array
#define endl '\n';
 
using namespace std;
 
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
 
template <class T> inline T gcd(T a, T b) { while (b) { a %= b; swap(a, b); } return a; }
template <class T> inline T lcm(T a, T b) { return a * b / gcd(a, b); }
 
const ll MAXN = 32005, K = 200043, M = 1000043, INF = 1e18 + 7;
// the good way to get PI number
const ld PI = acos(-1.0);
ll MOD = 1e9 + 7;

template <class T> T sqr(T a) {
    return a * a;
}

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

ll sum(ll a, ll b) {
    return ((a % MOD) + (b % MOD)) % MOD;
}

ll sub(ll a, ll b) {
    return sum(a, MOD - b);
}

ll bin_pow(ll a, ll n) {
    ll res = 1;
    while (n > 0) {
        if (n & 1)
            res = mul(res, a);
        a = mul(a, a);
        n >>= 1;
    }
    return res;
}

void solve() {
    ll n;
    cin >> n;
    
    vector<pll> a(n);
    for (ll i = 0; i < n; ++i) {
        cin >> a[i].first;
        a[i].second = i + 1;
    }
    
    sort(a.begin(), a.end());
    set <ll> s;
    s.insert(0);
    s.insert(n + 1);
    
    ll ans = 0;
    for (ll i = 0; i < n; ++i) {
        auto r = *s.upper_bound(a[i].second);
        auto l = *--s.upper_bound(a[i].second);
        ans += (r - a[i].second) * (a[i].second - l) * a[i].first;
        s.insert(a[i].second);
    }
    
    cout << ans << endl;
}

int main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    
    int t = 1;
//    cin >> t;
    
    while (t --> 0)
        solve();
    return 0;
}


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

int main(void){
	int n, m;
	cin >> n >> m;
	vector<vector<int>> s(m);
	for(int i = 0; i < m; ++i){
		int k;
		cin >> k;
		s[i].resize(k);
		for(int j = 0; j < k; ++j){
			cin >> s[i][j];
			s[i][j]--;
		}
	}
	vector<int> p(m);
	for(int i = 0; i < m; ++i){
		cin >> p[i];
	}
	int ans = 0;
	for(int bit = 0; bit < pow(2,n); ++bit){
		//cout << bit << " : ";
		bool on = true;
		for(int i = 0; i < m; ++i){
			int now = 0;
			for(int j = 0; j < s[i].size(); ++j){
				//cout << ((1<<s[i][j])&bit) << " ";
				if(((1<<s[i][j])&bit) != 0){
					now++;
				}
			}
			//cout << " / ";
			if(now%2!=p[i]){
				on = false;
			}
		}
		if(on){
			ans++;
			//cout << bit;
		}
		//cout << endl;
	}
	cout << ans << endl;
	return 0;

}

Measured memory_bytes: 512
import java.io.*;
import java.math.*;
import java.security.*;
import java.text.*;
import java.util.*;
import java.util.concurrent.*;
import java.util.regex.*;
public class Main{
	static BufferedReader br;
	static int cin() throws Exception
	{
		return Integer.valueOf(br.readLine());
	}
	static int[] split() throws Exception
	{
		String[] cmd=br.readLine().split(" ");
		int[] ans=new int[cmd.length];
		for(int i=0;i<cmd.length;i++)
		{
			ans[i]=Integer.valueOf(cmd[i]);
		}                                              
		return ans;
	} 
	static long mod=1000000007;
	static long power(long x,long y) 
    { 
        long res = 1; 
        x = x % mod; 
        while (y > 0) { 
            if (y % 2 == 1) 
                res = (res * x) % mod; 
            y = y >> 1;
            x = (x * x) % mod; 
        } 
        return res%mod; 
    } 
    static long modInverse(long n) 
    { 
        return power(n, mod-2); 
    } 
    static int digits(int n)
    {
    	int ans=0;
    	while(n!=0)
    	{
    		ans++;
    		n=n/10;
    	}
    	return ans;
    }
    public static void main(String[] args) throws Exception {
        br = new BufferedReader(new InputStreamReader(System.in));
        int n=cin();
        ArrayList<Integer>[]gr=new ArrayList[n+1];
        for(int i=0;i<=n;i++)
        {
        	gr[i]=new ArrayList<>();
        }
        HashMap<String,Integer> index=new HashMap<>();
        for(int i=0;i<n-1;i++)
        {
        	int[]ar=split();
        	int x=ar[0];
        	int y=ar[1];
        	gr[x].add(y);
        	gr[y].add(x);
        	index.put(x+" "+y,i);
        	index.put(y+" "+x,i);
        }
        int c=0;
        for(int i=1;i<=n;i++)
        {
        	c=Math.max(c, gr[i].size());
        }
        int[] color=new int[n-1];
        Queue<int[]>q=new LinkedList<>();
        q.add(new int[] {0,1});
        
        int[] vis=new int[n+1];
        vis[1]=1;
        while(!q.isEmpty())
        {
        	int[] arr=q.poll();
        	int col=-1;
        	if(arr[0]!=0)
        	{
        		col=color[index.get(arr[0]+" "+arr[1])];
        	}
        	int z=1;
        	for(int i=0;i<gr[arr[1]].size();i++)
        	{
        		int y=gr[arr[1]].get(i);
        		if(vis[y]==0)
        		{
        			vis[y]=1;
        			if(z!=col)
        			{
        				color[index.get(arr[1]+" "+y)]=z;
        				z++;
        			}
        			else
        			{
        				color[index.get(arr[1]+" "+y)]=z+1;
        				z=z+2;
        			}
        			q.add(new int[] {arr[1],y});
        		}
        	}
        }
        System.out.println(c);
        for(int i=0;i<n-1;i++)
        {
        	System.out.println(color[i]);
        }
    }
}

Measured memory_bytes: 106268
#include <stdio.h>

int main(void){
	int line[10000];
	int tem;
	line[0]=2;
	for(int i=1;i<10000;i++)
		line[i]=line[i-1]+i+1;
	while(scanf("%d",&tem)!=EOF)
		printf("%d\n",line[tem-1]);
	return 0;
}

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

using namespace std;

const int inf = 1e9;

int main(int argc, char *argv[]) {
  int n, m, r;
  cin >> n >> m >> r;
  vector<int> a(r);
  for (int i = 0; i < r; i++) {
    cin >> a[i];
  }
  vector<vector<int>> d(n + 1, vector<int>(n + 1, inf));
  for (int i = 0; i < m; i++) {
    int u, v, w;
    cin >> u >> v >> w;
    d[u][v] = d[v][u] = min(d[v][u], w);
  }
  for (int k = 1; k <= n; k++) {
    for (int i = 1; i <= n; i++) {
      for (int j = 1; j <= n; j++) {
        d[i][j] = min(d[i][j], d[i][k] + d[k][j]);
      }
    }
  }
  vector<int> p;
  for (int i = 0; i < r; i++) {
    p.push_back(i);
  }
  int ans = inf;
  do{
    int sum = 0;
    for (int i = 1; i < r; i++) {
      sum += d[a[p[i]]][a[p[i - 1]]];
    }
    ans = min(ans, sum);
  }while(next_permutation(p.begin(), p.end()));
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 384
/*

    author : s@if

*/

#include<bits/stdc++.h>
#include<ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
using namespace std;

#define 		NIL 			-1
#define		 	fi	 		    first
#define 		sec 			second
#define 		MAX 			INT_MAX
#define			INF 			1e9
#define 		ll 			    long long
#define 		PI 			    acos(-1.0)
#define			MOD 			1000000007
#define 		PLL 			pair<ll,ll>
#define 		PII			    pair<int,int>
#define 		ull 			unsigned long long
#define 		For(i,a,b) 		for(int i=a;i<=(int)b;i++)
typedef tree<int, null_type, less<int>, rb_tree_tag,
            tree_order_statistics_node_update> new_data_set;

//*find_by_order(k)  gives the kth element;
//order_of_key(item)   gives the index(number of element strictly less than item) of item;


inline int in() {int x; scanf("%d", &x); return x; }
bool Check(int N , int pos)	{	return (bool) (N & (1<<pos));}
int Set(int N, int pos) {	return N = N | (1<<pos);}

int fx[]={+0,+0,+1,-1,-1,+1,-1,+1};    // King's move
int fy[]={-1,+1,+0,+0,+1,+1,-1,-1};
int hx[]={-2,-2,-1,+1,+2,+2,-1,+1};    // Knight's move
int hy[]={+1,-1,+2,+2,-1,+1,-2,-2};
int dx[]={+1,-1,+0,+0};
int dy[]={+0,+0,+1,-1};

const int MAXN = (int)2e5+9;


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

    int i,j,k,l,m,n,p,q,x,y,u,v,r,tc,t;

    cin>>n>>m;
    x = 0;

    for(i=1; i<=n; i++) x = x*10+9;

    int a[m+9], b[m+9];

    for(i=1; i<=m; i++)
    {
        cin>>a[i]>>b[i];
    }

    int ans = -1;

    for(v=0; v<=x; v++)
    {
        bool flag = true;

        stringstream sso; sso<<v;
        string s; sso>>s;
        if(s.size()<n) continue;
        if(s.size()==1 && s[0]=='0') s+="00";
       // cout<<s<<endl;
        for(j=1; j<=m; j++)
        {
           // cout<<"R";
            if((s[a[j]-1]-'0')!=b[j]){
                flag  = false; break;
            }
        }

        if(flag)
        {
            ans = v; break;
        }
    }

    if(ans==-1) cout<<-1<<endl;
    else
    {
        stringstream sso; sso<<ans;
        string s; sso>>s;

        if((int)s.size()==n) cout<<ans<<endl;
        else
            cout<<-1<<endl;
    }

    return 0;
}

// read the question correctly (is y a vowel? what are the exact constraints?)
// look out for SPECIAL CASES (n=1?) and overflow (ll vs int?)


Measured memory_bytes: 256
res=0
h,w=map(int,input().split())
m=[[None for j in range(w)] for i in range(h)]
c=[[-1 for j in range(w)] for i in range(h)]
for i in range(h):
    s=input()
    for j in range(w):
        if s[j]==".":
            m[i][j]=0
        else:
            m[i][j]=1

for i in range(h):
    j=0
    start=-1
    while(j<w):
        if start==-1:
            if m[i][j]==0:
                start=j
                count=1
        else:
            if m[i][j]==1:
                for k in range(start,j):
                    c[i][k]+=count
                    res=max(res,c[i][k])
                start=-1
            else:
                count+=1
        j+=1
    if start!=-1:
        for k in range(start,w):
            c[i][k]+=count
            res=max(res,c[i][k])
for j in range(w):
    i=0
    start=-1
    while(i<h):
        if start==-1:
            if m[i][j]==0:
                start=i
                count=1
        else:
            if m[i][j]==1:
                for k in range(start,i):
                    c[k][j]+=count
                    res=max(res,c[k][j])
                start=-1
            else:
                count+=1
        i+=1
    if start!=-1:
        for k in range(start,h):
            c[k][j]+=count
            res=max(res,c[k][j])
print(res)

Measured memory_bytes: 118236
import sys
from bisect import bisect_left
sys.setrecursionlimit(10**7)
INF=10**10

changed=[]
input=sys.stdin.readline
n=int(input())
a=list(map(int,input().split())) 
g=[[] for i in range(n)]
for i in range(n-1):
    u,v=map(int,input().split())
    g[u-1].append(v-1)
    g[v-1].append(u-1)
LIS=[INF]*n

def dfs(i, pre, Ans):
    changeID = bisect_left(LIS, a[i])
    changed.append((changeID, LIS[changeID]))
    LIS[changeID] = min(a[i], LIS[changeID])
    Ans[i] = bisect_left(LIS, INF) 
    for nextN in g[i]:
        if nextN != pre: dfs(nextN, i, Ans)
    backID, backV = changed.pop()
    LIS[backID] = backV
    return 0

def main():
    Ans=[1]*n
    dfs(0,0,Ans)
    for i in Ans:
        print(i)
    
    return 0

if __name__ == "__main__":
    main()


Measured memory_bytes: 370752
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;

int main() {
	// your code goes here
	int N;
	cin >> N;
	vector<int> A;
	int input;
	for(int i=0;i<N;i++){
		cin >> input;
		A.push_back(input);
	}
	
	sort(A.begin(),A.end());
	int bef=0;
	int cnt = 0; 
	for(int i=0;i<A.size();++i){
		if(A[i]==bef) cnt++;
		bef = A[i];
	}
	if(cnt%2 != 0) cnt+=1;
	int ans = N - cnt;
	cout << ans;
	
	return 0;
}

Measured memory_bytes: 892
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

public class MainClass
{
	public const long Giri = 1000000007;

	class Obj
	{
		public int Sa {get;set;}
		public int Index {get;set;}
		public bool Pin{get;set;}
	}
	public static void Main(string[] args)
	{
		var p = Input().ToInt();
		var x = Input().ToInt();
		int n = p[0];
		int m = p[1];
		
		if(m==1)
		{
			Console.WriteLine(0);
			return;
		}
			
		Array.Sort(x);
		var sa = new Obj[m-1];
		bool[] at = new bool[m];
		for(int i = 0; i < m-1; i++)
		{
			sa[i] = new Obj() {Sa = (x[i+1] - x[i]), Index = x[i]};
		}
		
		Array.Sort(sa, (c,d)=>c.Sa-d.Sa);
		
		int r = 0;
		for(int i = 0; i < m - n; i++)
		{
			r+= sa[i].Sa;
			//Console.WriteLine("+= {0}", sa[i].Sa);
		}
		Console.WriteLine(r);
		
	}
	
	static long GCD(long a, long b)
	{
		var v = new[] { a, b };
		while (v[1] != 0) { v = new[] { v[1], v[0] % v[1] }; }
		return v[0];
	}
	public static string[] Input() { return Console.ReadLine().Split(' '); }
	public static int Clamp(int val, int max, int min = 0) { return Math.Min(max, Math.Max(min, val)); }
}

public static class Smarter
{
	public static int ToInt(this string str) { return int.Parse(str); }
	public static long ToLong(this string str) { return long.Parse(str); }
	public static int[] ToInt(this string[] str)
	{
		int[] r = new int[str.Length];
		for(int i = 0; i < str.Length; i++) r[i] = str[i].ToInt();
		return r;
	 }
	
}

Measured memory_bytes: 27744
#include <bits/stdc++.h>
    #define rep(i,n) for(int i = 0; i < (n); i++)
     
    using namespace std;  
    using ll = long long;
    using P = pair<int,int>; 
    
    int main() {
   
     char a[4];
     rep(i,4)	cin >> a[i];
     
     if(a[0] == '7' ||a[1] == '7' ||a[2] == '7' ||a[3] == '7')
     	cout << "Yes" <<'\n';
     else cout << "No" <<'\n';
     
     return 0;
    }
    
    

Measured memory_bytes: 3636
#include<bits/stdc++.h>
using namespace std;
#define M 998244353
#define F first
#define S second
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef pair<double,ll> pll;
#define pb push_back
#define M6 5000009
#define M5 500009
#define pi 3.14159265
ll power(ll x,ll n){
    ll res=1;
    while(n>0){
        if(n&1) res=(res*x)%M;
        n/=2;
        x=(x*x)%M;
    }
    return res;
}
ll prime[M6];
void sieve(){
    for(int i=2;i<M6;i++) prime[i]=1;
    for(int i=2;i*i<M6;i++){
        if(prime[i]==0) continue;
        for(int j=i*2;j<M6;j+=i) prime[j]=0;
    }
}
ll n,m,A[M5];
int  main()
{   ios_base::sync_with_stdio (0), cin.tie (0);
    //sieve();
    //init();
    //freopen("input.txt","r",stdin);
    //freopen("output.txt","w",stdout);
    ll tc=1,t=0,i,j,k,l,a,b,c,d;
    //cin>>tc;
    while(t++<tc){
        cin>>a>>b;
        cout<<max(a+b,max(a-b,a*b));
    }
    return 0;
}

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

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

int main() {
  intll a,b,c ;
  cin >> a >> b >> c ;
  if(a*b*c % 2 == 0){
    cout << 0 ; 
    return 0 ;
  }
  
  else {
    cout << min(a*b,min(b*c,a*c))  ;
  }
  
  
}


Measured memory_bytes: 3604
import numpy as np


def main():
    n, m, x = map(int, input().split())
    cas = np.array([list(map(int, input().split())) for _ in range(n)])

    ans = -1
    for i in range(2 ** n):
        if i == 0:
            continue
        books = []
        for j in range(n):
            if ((i >> j) & 1):
                books.append(cas[j])

        books = np.array(books)
        if np.all(np.sum(books[:, 1:], axis=0) >= x):
            ans_temp = np.sum(books[:, 0])
            if ans == -1:
                ans = ans_temp
            else:
                ans = min(ans, ans_temp)
    print(ans)


if __name__ == "__main__":
    main()


Measured memory_bytes: 27244
#include <iostream>
#include <algorithm>
#include <vector>
#include <queue>
#include <iomanip>
#include <cmath>
#include <map>
using namespace std;
using ll = long long;
constexpr ll MOD = 1e9 + 7;
constexpr ll INF = 1LL << 60;

int N, A[100010], B[100010];
map<ll, int> ans;
vector<int> G[100010];

void dfs(int v, int pv, int col) {
  int nc = 1;
  for(int nv: G[v]) {
    if(nv == pv) continue;
    if(col == nc) ++nc;
    dfs(nv, v, nc);

    ans[v*100000 + nv] = nc;
    ++nc;
  }
}

int main() {
  cin.tie(0); ios_base::sync_with_stdio(false);
  cin >> N;
  for(int i = 0; i < N - 1; ++i) {
    cin >> A[i] >> B[i];
    --A[i], --B[i];
    G[A[i]].push_back(B[i]);
    G[B[i]].push_back(A[i]);
  }

  dfs(0, -1, 0);

  int k = 0;
  for(int i = 0; i < N-1; ++i) {
    k = max(k, ans[A[i]*100000+B[i]]);
  }
  cout << k << endl;
  for(int i = 0; i < N-1; ++i) {
    cout << ans[A[i]*100000+B[i]] << '\n';
  }

  return 0;
}

Measured memory_bytes: 14976
#include <stdio.h>
#include <string.h>

int main(void) {
	int i, j;
	int number; //tango no kazu
	int lmnumber; //tango no moji suu no saidai
	int lmword;
	char str[500][33];
	int sstr[500]; //str no narabekae you
	int swap;
	int count;
	
	i = j = lmnumber = number = 0;
	while (str[j][i] = getchar()) {
		lmnumber = i > lmnumber ? i : lmnumber;
		if( str[j][i] == ' ') {
			str[j][i] = '\0';
			j++;
			i = -1;
		}
		else if( str[j][i] == '\n') {
			str[j][i] = '\0';
			break;
		}
		i++;
	}
	number = j + 1;
	for (i = 0; i < number; i++)
		sstr[i] = i;
	for (i = number; i > 1; i--)
		for (j = 0; j < i - 1; j++)
			if( strcmp(str[sstr[j]], str[sstr[j+1]]) == 1) {
				swap = sstr[j];
				sstr[j] = sstr[j+1];
				sstr[j+1] = swap;
			}
	for (i = j = count = 0; i < number; i++) {
		if( strlen(str[i]) == lmnumber)
			lmword = i;
		if( strcmp(str[sstr[i]], str[sstr[i+1]]) == 0) {
			if( j == 0)
				j = 2;
			else
				j++;
			count = j > count ? sstr[i] : count;
		}
		else
			j = 0;
	}
	printf("%s %s\n", str[count], str[lmword]);
	return 0;
}

Measured memory_bytes: 532
#include<bits/stdc++.h>
using namespace std;
int main(){
	int n;
  	while(cin>>n){
      	int ans=0;
    	for(int i=1;i<=n;i++){
        	for(int j=1;j<=n;j++){
            	for(int k=1;k<=n;k++)
                  	ans++;
            }
        }
  		cout << ans << endl;
    }
}

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

typedef struct DICE{
    int s[6];
}dice;

dice dice_rotate(dice d, char rotate){
    int swap;
    if(rotate == 'E'){
        swap = d.s[2];
        d.s[2] = d.s[0];
        d.s[0] = d.s[3];
        d.s[3] = d.s[5];
        d.s[5] = swap;
    }else if(rotate == 'N'){
        swap = d.s[4];
        d.s[4] = d.s[0];
        d.s[0] = d.s[1];
        d.s[1] = d.s[5];
        d.s[5] = swap;
    }else if(rotate == 'S'){
        swap = d.s[1];
        d.s[1] = d.s[0];
        d.s[0] = d.s[4];
        d.s[4] = d.s[5];
        d.s[5] = swap;
    }else if(rotate == 'W'){
        swap = d.s[3];
        d.s[3] = d.s[0];
        d.s[0] = d.s[2];
        d.s[2] = d.s[5];
        d.s[5] = swap;
    }

    return d;
}

int main(){
    dice d,proto;
    char rotate;
    int i,j,q,top,flont;

    for(i=0;i<6;i++){
        cin >> d.s[i];
    }

    proto = d;

    cin >> q;
    for(j=0;j<q;j++){
        d = proto;
        cin >> top;
        cin >> flont;
        i=0;
        while(d.s[0] != flont){
            if(i%2==0){
                d = dice_rotate(d, 'S');
            }else if(i%2==1){
                d = dice_rotate(d, 'E');
            }
            i++;
        }
        d = dice_rotate(d, 'S');
        while(d.s[0] != top){
            d = dice_rotate(d, 'E');
        }
    cout << d.s[2] << endl;

    }
    return 0;
}




Measured memory_bytes: 3100
#include <iostream>
#include <algorithm>
#include <functional>
using namespace std;
#define INF 1000000000

int man[10010],kaz[510],ned[510],dp[2][10010];
int main(){
	int M,N,sum,a,b,cnt,hog;
	cin>>M>>N;
	for(int i=0;i<M;i++) cin>>man[i];
	for(int i=0;i<N;i++) cin>>kaz[i]>>ned[i];
	for(int i=0;i<=M;i++) dp[0][i]=INF;
	dp[0][0]=0;
	sort(man,man+M,greater<int>());

	for(int i=0;i<N;i++){
		a=i%2;
		b=(i+1)%2;
		for(int j=0;j<=M;j++){
			dp[b][j]=dp[a][j];
		}
		for(int j=0;j<M;j++){
			hog=min(j+kaz[i],M);
			dp[b][hog]=min(dp[b][hog],dp[a][j]+ned[i]);
			
		}
	}
	b=N%2;
	sum=cnt=0;
	for(int i=1;i<=M;i++){
		sum+=man[i-1];
		cnt=max(cnt,sum-dp[b][i]);
		//cout<<i<<" "<<sum<<" "<<dp[b][i]<<endl;//
	}
	cout<<cnt<<endl;
}

Measured memory_bytes: 1296
#include <bits/stdc++.h>
using namespace std;
///////////////////////////////////////////
const long long int INF = 1LL<<60;
const long long int Mod = 1000000007;
using ll = long long int; using ci = const int;
using vi = vector<int>;  using Vi = vector<long long int>;
using P = pair<int, int>;  using PLL = pair<ll, ll>;
using matrix = vector<vector<ll>>;
#define pb(x) push_back(x)
#define mp(x,y) make_pair(x,y)
#define all(x) (x).begin(),(x).end()
#define rp(i,N) for(ll i = 0; i < (ll)N; i++)
#define repi(i,a,b) for(ll i = ll(a); i < ll(b); ++i)
template<class T>bool chmax(T &former, const T &b) { if (former<b) { former=b; return true; } return false; }
template<class T>bool chmin(T &former, const T &b) { if (b<former) { former=b; return true; } return false; }
template<class T>T sqar(T x){ return x*x; }//sqrt(x)は平方根;
#define Sort(v) std::sort(v.begin(), v.end(), std::greater<decltype(v[0])>()) //降順でVをソート
#define p_queue(v) priority_queue<v, vector<v>, greater<v> >
template<class T> inline void princ(T x){cout<<x<<" ";}; 
template<class T> inline void print(T x){cout<<x<<"\n";};
template<class T> inline void Yes(T condition){ if(condition) cout << "Yes" << endl; else cout << "No" << endl; }
template<class T> inline void YES(T condition){ if(condition) cout << "YES" << endl; else cout << "NO" << endl; }
///////////////////////////////////////////////////////////////////////////////////

void solve(){
    ll d,g;
    cin >> d >> g;
    g /= 100;
    Vi p(d),c(d);
    rp(i,d) {
        cin >> p.at(i) >> c.at(i);
        c.at(i)/=100;
    }
    ll ans=INF;
    rp(mask,(1<<d)){
        ll rem=g;
        ll ctr=0;
        rp(i,d){
            if(mask&(1ll<<i)){
                rem-=c[i];
                rem-=(i+1)*p[i];
                ctr+=p[i];
            }
        }
        //if(mask==2)print(rem);
        if(rem<=0) chmin(ans,ctr);
        else{
            for(ll i=d-1; i>=0; i--){
                //if(mask==2) print(mask&(1ll<<i));
                if(mask&(1ll<<i)){}else{
                    //if(mask==2) print(i);
                    if(rem-(i+1)*(p[i]-1)<=0){
                        //if(mask==2) print("here");
                        ctr+=(rem+i)/(i+1);
                        rem=0;
                        break;
                    }
                    else{
                        ctr+=p[i]-1;
                        rem-=(i+1)*(p[i]-1);
                    }
                }
            }
            if(rem<=0)chmin(ans,ctr);
        }
    }
    print(ans);
    return;
}
int main(){
    cin.tie(0);ios::sync_with_stdio(false);
    std::cout<<std::fixed<<std::setprecision(30);
    solve();
    return 0;
}

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

using namespace std;
using ll =long long;
using vi = vector<int>; 
using vvi = vector<vi>; 
using vl = vector<ll>; 
using vvl = vector<vl>; 
using vs = vector<string>;
using vvs = vector<vs>; 
using vc = vector<char>;
using vvc = vector<vc>; 
using vb = vector<bool>;
using vvb = vector<vb>; 

#define rep(i,n) ;for( int i =0; i < n ; i ++)
#define all(a) a.begin(),a.end()
#define pb(a) push_back(a)
#define pd(a) printf("%.10f\n",a)
#define mem(a) memset(a,0,sizeof(a))
#define f(i,a,b) for(int i=a;i<b;i++)
#define pri(a)  printf("%.14lf\n",a);
#define MOD 1000000007
bool is_int_lround(double x){
  return std::lround(x)==x;
}
ll keta(ll x){
  ll n=0;
  while(x>0){
    x /=10 ;
    n ++;
  }
  return n;
}

ll conbi(int n,int m){
  
  cin>>n>>m;
  vector<ll> a(100);
  a[0] =1;
  for(int i=0;i<14;i++){
    a[i+1]=a[i]*(i+1);
  }
  return a[n] /(a[m] *a[n-m]);
}

long long modpow(long long a, long long n, long long mod) {
    long long res = 1;//繰り返し二乗法
    while (n > 0) {
        if (n & 1) res = res * a % mod;
        a = a * a % mod;
        n >>= 1;
    }
    return res;
}
ll kaijo(ll x){
  ll z=1;
  if(x==0){
    return 1;
  }
  while(x>0){
    z *=x;
    z %=MOD;
    x--;
  }
  return z;
}
ll yakusu_num(ll n){
  vl yakusu(n+1,1);
  for(ll i=2;i*i<=n;i++){ 
    while(n%i==0){
      n /=i;
      yakusu[i]++;
    }
  }
  if(n!=1)yakusu[n]++;
  ll num=1;
  for(ll i=0;i <=n;i++){
    num*=yakusu[i];
  }
  return num;
}


//cout<<""<<endl;
int main(){
  string S,T,U;int A,B;cin>>S>>T>>A>>B>>U;
  if(U ==S)cout << A-1 <<" "<<B<<endl;
  else cout<<A<<" "<<B-1<<endl;
}





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

int main() {
	int a, b;
	string s;
	cin >> a >> s >> b;
	if (s == "+") {
		cout << (a + b) << endl;
	}
	else {
		cout << (a - b) << endl;
	}
	return 0;
}

Measured memory_bytes: 256
str_line = input()
str_line = list(str_line)
str_line.sort()
#print(str_line)
temp = 0
stnum_list = []

for i in range(1,len(str_line)-1):
    if str_line[i] == str_line[i-1]:
        temp += 1
        
    else:
        stnum_list.append(temp)
        temp = 0
        

rsult = 1
#print(len(str_line))

if len(str_line) == 1:
    rsult = 0
else:
    for i in range(len(stnum_list)):
        rsult *= stnum_list[i]

if rsult%2 == 1:
    print("Yes")
else:
    print("No")

Measured memory_bytes: 9076
#include<cstdio>
#include<cstdlib>
using namespace std;

typedef unsigned long long int ulln;

int main(void)
{
    int m,n;
    int dist[100001] = {0};
    scanf("%d%d",&m,&n);

    int s;
    for(int i = 0;i < m-1;i++)
    {
        scanf("%d",&s);
        dist[i+1] = dist[i] + s;
    }

    int a,cur = 0;
    ulln ans = 0;
    for(int i = 0;i < n;i++)
    {
        scanf("%d",&a);
        ans += (ulln)abs(dist[cur]-dist[cur+a]);
        cur += a;
    }
    printf("%d\n",ans%100000);
    return 0;
}

Measured memory_bytes: 1424
# -*- coding: utf-8 -*-
N,X = [int(i) for i in input().split(" ")]
L = [int(i) for i in input().split(" ")]
sum = 0
count = 1
for val in L:
    sum = sum + val
    if X < sum:
        break
    count = count + 1
print(count)


Measured memory_bytes: 2940
#include <cstdio>
#include <vector>
#include <algorithm>
typedef long long LL;
using namespace std;

int n;
vector<LL> a, b;
LL getmax(LL p, LL q) {return p>q?p:q;}

int main() {
    scanf("%d", &n);
    for (int i = 0 ; i < n ; i++) {
        LL x, y;
        scanf("%lld%lld", &x, &y);
        a.push_back(x + y);
        b.push_back(x - y);
    }
    sort(a.begin(), a.end());
    sort(b.begin(), b.end());
    printf("%lld", getmax(a.back() - a.front(), b.back() - b.front()));
}


Measured memory_bytes: 6140
/**
 *    author:  otera    
**/
#include<iostream>
#include<string> 
#include<cstdio>
#include<cstring>
#include<vector>
#include<cmath>
#include<algorithm> 
#include<functional>
#include<iomanip>
#include<queue>
#include<deque>
#include<ciso646>
#include<random>
#include<map>
#include<set>
#include<complex>
#include<bitset>
#include<stack>
#include<unordered_map>
#include<unordered_set>
#include<utility>
#include<cassert>
using namespace std;

#define int long long
typedef long long ll;
typedef unsigned long long ul;
typedef unsigned int ui;
typedef long double ld;
const int inf=1e9+7;
const ll INF=1LL<<60 ;
const ll mod=1e9+7 ;
#define rep(i,n) for(int i=0;i<n;i++)
#define per(i,n) for(int i=n-1;i>=0;i--)
#define Rep(i,sta,n) for(int i=sta;i<n;i++)
#define rep1(i,n) for(int i=1;i<=n;i++)
#define per1(i,n) for(int i=n;i>=1;i--)
#define Rep1(i,sta,n) for(int i=sta;i<=n;i++)
typedef complex<ld> Point;
const ld eps = 1e-8;
const ld pi = acos(-1.0);
typedef pair<int, int> P;
typedef pair<ld, ld> LDP;
typedef pair<ll, ll> LP;
#define fr first
#define sc second
#define all(c) c.begin(),c.end()
#define pb push_back
#define debug(x)  cerr << #x << " = " << (x) << endl;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

void solve() {
	int x; cin >> x;
    cout << (x ^ 1) << endl;
}

signed main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	//cout << fixed << setprecision(10);
	//int t; cin >> t; rep(i, t)solve();
	solve();
    return 0;
}

Measured memory_bytes: 3648