akhauriyash/Code-Regression huggingface dataset:
import os

import sys

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

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


# MOD = 998244353

def strongly_connected_components(graph):
    """
    強連結成分分解; SCC
    ret[v]: v のコンポーネント番号
    コンポーネント番号はトポロジカル順で前にある方が小さい
    Verify: https://atcoder.jp/contests/arc030/submissions/14035565
    :param list of (list of int) graph:
    :rtype: list of int
    """
    N = len(graph)

    rev_graph = [[] for _ in range(N)]
    for v in range(N):
        for u in graph[v]:
            rev_graph[u].append(v)

    # 帰りがけ順
    pre_order = []
    seen = [False] * N
    for v in range(N):
        if seen[v]:
            continue
        seen[v] = True
        stack = [(v, 0)]
        while stack:
            v, pos = stack.pop()
            for i in range(pos, len(graph[v])):
                u = graph[v][i]
                if seen[u]:
                    continue
                seen[u] = True
                # 中断して次の頂点を Stack に詰む
                stack.append((v, i + 1))
                stack.append((u, 0))
                break
            else:
                # 帰りがけ
                pre_order.append(v)

    # 帰りがけ順が遅い順に DFS
    cid = 0
    ret = [-1] * N
    seen = [False] * N
    for v in reversed(pre_order):
        if seen[v]:
            continue
        seen[v] = True
        stack = [v]
        while stack:
            v = stack.pop()
            ret[v] = cid
            for u in rev_graph[v]:
                if seen[u]:
                    continue
                seen[u] = True
                stack.append(u)
        cid += 1
    return ret


V, E = list(map(int, sys.stdin.buffer.readline().split()))
ST = [list(map(int, sys.stdin.buffer.readline().split())) for _ in range(E)]
Q = int(sys.stdin.buffer.readline())
VU = [list(map(int, sys.stdin.buffer.readline().split())) for _ in range(Q)]

graph = [[] for _ in range(V)]
for s, t in ST:
    graph[s].append(t)
scc = strongly_connected_components(graph)
ans = []
for v, u in VU:
    ans.append(int(scc[v] == scc[u]))
print(*ans, sep='\n')



Measured memory_bytes: 30268
X, N = map(int, input().split())
P = list(map(int, input().split()))

delta, notP = [], []
for i in range(0, 102):
    if not i in P:
        delta.append(abs(X-i))
        notP.append(i)

i = delta.index(min(delta))
print(notP[i])

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

using namespace std;

typedef long long ll;
using pii = pair<int, int>;

static const int INTINF = (2147483647);
static const ll LLINF = (9223372036854775807);
static const int MAX = 100001;
static const ll MOD = 1000000007;


//--global--//

string make(int n){
    string str = to_string(n);
    while(str.size()<3){
        str = '0' + str;
    }
    return str;
}

//----------//

int main(int argc, const char * argv[]) {
    //提出時、消す----//
    //--------------//
    
    ll t1, t2;
    ll a1, a2;
    ll b1, b2;
    cin >> t1 >> t2 >> a1 >> a2 >> b1 >> b2;
    ll dist1 = abs(t1*a1 - t1*b1);
    ll dist2 = abs((t2*a2 + t1*a1) - (t2*b2 + t1*b1));
    if(dist2 == 0){
        cout << "infinity" << endl;
        return 0;
    }
    else{
        if(t1*a1 < t1*b1 && t2*a2+t1*a1>t2*b2+t1*b1 ||
            t1*a1 > t1*b1 && t2*a2+t1*a1<t2*b2+t1*b1 ){
                if(dist1 % dist2 == 0){
                    ll ans = (dist1 / dist2)*2;
                    cout << ans << endl;
                }
                else{
                    ll ans = (dist1 / dist2)*2 + 1;
                    cout << ans << endl;
                }
        }
        else{
            //ずっと追い越しつまり、0?
            cout << 0 << endl;
        }

    }
    
    return 0;
}


Measured memory_bytes: 384
s=list(input())
out=[]
for i in s:
    if(i=='1'):
        out.append(1)
    elif(i=='0'):
        out.append(0)
    elif(i=='B'):
        if(len(out)==0):
            continue
        del out[-1]
for x in out:
    print(x,end="")
print()

Measured memory_bytes: 3064
#include<iostream>
#include<set>
#include<vector>
#include<array>
#include<algorithm>
#include<chrono>

uint64_t xor64(void) {
  static uint64_t x = 88172645463325252ULL;
  x = x ^ (x << 7);
  return x = x ^ (x >> 9);
}

auto b_cl = std::chrono::system_clock::now();
inline double get_time() {
  auto e_cl = std::chrono::system_clock::now();
  double msec = std::chrono::duration_cast<std::chrono::milliseconds>(e_cl - b_cl).count();
  return msec;
}

int main() {
  std::cin.tie(0); std::ios::sync_with_stdio(false);
  int D; std::cin >> D;
  int c[26];
  for(auto& ci: c) std::cin >> ci;
  std::vector<std::array<int,26>> s(D);
  for(int d = 0; d < D; ++d) {
    for(auto& si: s[d]) std::cin >> si;
  }
  std::vector<int> t(D);
  {
    int sum = 0;
    for(int ci: c) sum += ci;
    std::vector<int> sc(26, 0);
    int d = 0;
    for(;;) {
      for(int i = 0; i < 26; ++i) sc[i] += c[i];
      for(int i = 0; i < 26; ++i) if(sc[i] >= sum) {
        if(d < D) { t[d] = i; ++d; }
        sc[i] -= sum;
      }
      if(d >= D) break;
    }
  }
  std::set<int> last[26];
  for(auto& li: last) li.insert(-1); // sentinel
  int ans = 0;
  for(int d = 0; d < D; ++d) {
    int t1 = t[d];
    ans += s[d][t1];
    last[t1].insert(d);
    for(int i = 0; i < 26; ++i) {
      ans -= c[i]*(d - *last[i].rbegin());
    }
  }
  for(auto& li: last) li.insert(D); // sentinel
  
  // additional score when t[d] = i compare to t[d] = -1
  auto sum_up = [](int d) { return d*(d-1)/2; };
  auto score = [&](int d, int i)->int {
    int res = s[d][i];
    auto it = last[i].lower_bound(d);
    int nd = *it;
    int pd = *--it;
    int diff = sum_up(d-pd) + sum_up(nd-d) - sum_up(nd-pd);
    res -= c[i]*diff;
    return res;
  };
  int lm = 0, renew = 0;
  int sc[26];
  auto one_day = [&](int d) {
    int pi = t[d];
    last[pi].erase(d);
    for(int i = 0; i < 26; ++i) sc[i] = score(d, i);
    int mi = std::max_element(sc, sc+26) - sc;
    if(mi != pi) {
      ans += sc[mi] - sc[pi];
      ++renew;
    }
    last[mi].insert(d);
  };
  
  // hill climbing
  int range = 50;
  for(int rep = 0;; ++rep) {
    if((xor64()>>25)%2) {
      one_day(xor64()%365);
    } else {
      // swap
      int d1 = xor64()%D, d2 = xor64()%D;
      while(d1 < d2-range || d2 < d1-range || t[d1] == t[d2]) {
          d1 = xor64()%D; d2 = xor64()%D;
      }
      int pi1 = t[d1], pi2 = t[d2];
      last[pi1].erase(d1);
      int diff = score(d1, pi2) - score(d1, pi1);
      last[pi2].insert(d1);
      last[pi2].erase(d2);
      diff += score(d2, pi1) - score(d2, pi2);
      if(diff > 0) {
        last[pi1].insert(d2);
        t[d1] = pi2;
        t[d2] = pi1;
        lm = 0;
      } else {
        last[pi2].insert(d2);
        last[pi2].erase(d1);
        last[pi1].insert(d1);
      }
    }
    if(rep%100 == 0) {
      int x = get_time();
      if(x > 1950) break;
      if(x > 200) range = 25;
      if(x > 400) range = 20;
      if(x > 700) range = 15;
      if(x > 1000) range = 10;
    }
  }
  for(auto ti: t) std::cout << ti+1 << "\n";
  return 0;
}


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

//    for(int i=0;i<n;i++){
//        cout<<dp[i]<<" ";
//    }
//    cout<<endl;
  return dp[n-1];
}
int main(){
  int n;
  cin>>n;
  int arr[n];
  for(int i=0;i<n;i++){
    cin>>arr[i];
  }
  cout<<sol(n,arr)<<endl;
  return 0;
}


Measured memory_bytes: 1024
import itertools

N = int(input())
march = {
    "M": 0,
    "A": 0,
    "R": 0,
    "C": 0,
    "H": 0
    }

for i in range(N):
    member = input()
    for key in march:
        if member[0] == key:
            march[key] += 1
            break

combi_list = list(itertools.combinations((list(march.values())), 3))
count = sum([i[0] * i[1] * i[2] for i in combi_list])
print(count)

Measured memory_bytes: 3064
// https://atcoder.jp/contests/abc173/tasks/abc173_a

const main = (args) => {
  const [N] = args[0].split(' ').map(Number);
  const x = N % 1000;
  
  console.log(x ? 1000-x: 0);
}
main(require('fs').readFileSync('/dev/stdin', 'utf8').trim().split('\n'));


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

int a[200005];


int main(){
	ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
	int n;
	cin >> n;
	for (int i = 1; i <= n; ++i)
		cin >> a[i];

	int mini = 2e9;
	int cnt = 0;

	for (int i = 1; i <= n; ++i){
		if (a[i] <= mini){
			cnt++;
			mini = a[i];
		}
	}
	cout << cnt << "\n";
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;using ll=int_fast64_t;using ld=long double;using pll=pair<ll,ll>;using pld=pair<ld,ld>;
const ll INF=1LL<<60;void solve();int main(){cin.tie(0);ios::sync_with_stdio(false);cout<<fixed<<setprecision(10);solve();}
#define fi first
#define se second
#define SELECTOR(_1,_2,_3,_4,SELECT,...) SELECT
#define rep(...) SELECTOR(__VA_ARGS__,_rep2,_rep1,_rep0)(__VA_ARGS__)
#define _rep0(i,n) for(ll i=0;i<n;++i)
#define _rep1(i,k,n) for(ll i=k;i<n;++i)
#define _rep2(i,k,n,d) for(ll i=k;d!=0&&d>0?i<n:i>n;i+=d)
template<class T> vector<T> make_v(size_t a,T b){return vector<T>(a,b);}
template<class... Ts> auto make_v(size_t a,Ts... ts){return vector<decltype(make_v(ts...))>(a,make_v(ts...));}
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;}
template<class T> void contout(const T &v){for(auto it=v.begin();it!=v.end();++it,cout<<(it!=v.end()?" ":"\n"))cout<<*it;}

template <std::uint_fast64_t Modulus> class mint {
public:
  ll a;
  constexpr mint(const ll x = 0) noexcept : a(x % Modulus) {}
  constexpr ll &value() noexcept { return a; }
  constexpr const ll &value() const noexcept { return a; }
  constexpr mint operator+(const mint rhs) const noexcept {
    return mint(*this) += rhs;
  }
  constexpr mint operator-(const mint rhs) const noexcept {
    return mint(*this) -= rhs;
  }
  constexpr mint operator*(const mint rhs) const noexcept {
    return mint(*this) *= rhs;
  }
  constexpr mint operator/(const mint rhs) const noexcept {
    return mint(*this) /= rhs;
  }
  constexpr mint &operator+=(const mint rhs) noexcept {
    a += rhs.a;
    if (a >= Modulus) {
      a -= Modulus;
    }
    return *this;
  }
  constexpr mint &operator-=(const mint rhs) noexcept {
    if (a < rhs.a) {
      a += Modulus;
    }
    a -= rhs.a;
    return *this;
  }
  constexpr mint &operator*=(const mint rhs) noexcept {
    a = a * rhs.a % Modulus;
    return *this;
  }
  constexpr mint &operator/=(mint rhs) noexcept {
    ll exp = Modulus - 2;
    while (exp) {
      if (exp % 2) {
        *this *= rhs;
      }
      rhs *= rhs;
      exp /= 2;
    }
    return *this;
  }
};

constexpr ll MOD=1000000007;
void solve(){
  ll L,R; cin>>L>>R;
  auto dp=make_v(2,2,2,mint<MOD>(0)); // dp[msb][mt][lt]
  dp[0][0][0]=1;
  rep(d,60,-1,-1){ // 0-paddingと見て、上からd桁目を見ている
    ll lb=(L>>d)&1,rb=(R>>d)&1;
    auto newdp=make_v(2,2,2,mint<MOD>(0));
    rep(msb,2)rep(mt,2)rep(lt,2)rep(x,2)rep(y,2){
      ll nmsb=msb,nmt=mt,nlt=lt;
      if(x>y) continue;
      // msb
      if((!msb)&&(x!=y)) continue;
      if(x==1&&y==1) nmsb=1;
      // more than L
      if((!mt)&&x<lb) continue;
      if(x>lb) nmt=1;
      // less than R
      if((!lt)&&y>rb) continue;
      if(y<rb) nlt=1;
      newdp[nmsb][nmt][nlt]+=dp[msb][mt][lt];
    }
    dp=newdp;
  }
  mint<MOD> ans=0;
  rep(msb,2)rep(mt,2)rep(lt,2) ans+=dp[msb][mt][lt];
  cout<<ans.a<<"\n";
}

Measured memory_bytes: 256
#include<cstdio>
#include<cstring>
#include<algorithm>
#define ll long long
using namespace std;
const ll N=2e5+10,XJQ=998244353;
ll n,q,s[N];
ll lazy[N*4],t[N*4];
void Downdata(ll x,ll l,ll m,ll r){
	if(!lazy[x])return;
	ll val=lazy[x];
	lazy[x*2]=lazy[x*2+1]=lazy[x];
	t[x*2]=(s[m]-s[l-1]+XJQ)%XJQ*val%XJQ;
	t[x*2+1]=(s[r]-s[m]+XJQ)%XJQ*val%XJQ;
	lazy[x]=0;return;
}
void Change(ll x,ll L,ll R,ll l,ll r,ll val){
	if(L==l&&R==r){
		lazy[x]=val;
		t[x]=(s[R]-s[L-1]+XJQ)%XJQ*val%XJQ;
		return;
	}
	ll mid=(L+R)>>1;
	Downdata(x,L,mid,R);
	if(r<=mid)Change(x*2,L,mid,l,r,val);
	else if(l>mid)Change(x*2+1,mid+1,R,l,r,val);
	else Change(x*2,L,mid,l,mid,val),Change(x*2+1,mid+1,R,mid+1,r,val);
	t[x]=(t[x*2]+t[x*2+1])%XJQ;
}
int main()
{
	scanf("%lld%lld",&n,&q);
	s[1]=1;
	for(ll i=2;i<=n;i++)
		s[i]=s[i-1]*10%XJQ;
	for(ll i=1;i<=n;i++){
		s[i]=(s[i]+s[i-1])%XJQ;
		Change(1,1,n,i,i,1);
	}
	while(q--){
		ll l,r,d;
		scanf("%lld%lld%lld",&l,&r,&d);
		l=n-l+1;r=n-r+1;swap(l,r);
		Change(1,1,n,l,r,d);
		   printf("%lld\n",t[1]);
	}
	return 0;
}


Measured memory_bytes: 12096
function Main(input) {
input = input.split("\n");
    var a1 = input[1].split(' ').map(e => { return parseInt(e) })
    var a2 = input[2].split(' ').map(e => { return parseInt(e) })
    var j = a1.length - 1
    var m = 0, n = a1.length - 2
    var r = 0;
    var temp;

    for (var i = j; i >= m; i--) {
        temp = sum(a1.slice(m, i+1)) + sum(a2.slice(i))
        if (r < temp) r = temp
    }

    function sum(arr) {
        var r = 0
        for (var i = 0; i < arr.length; i++) {
            r += arr[i]
        }
        return r
    }

    console.log(r)
}
Main(require("fs").readFileSync("/dev/stdin", "utf8"));

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

#define int long long
#define flash ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define pb push_back
#define all(x) begin(x),end(x)

int mod = 1e9+7;
int inf = 4e18;
const int N = 5e5+5;
		
signed main()
{
    flash
    int tt = 1;
    //cin>>tt;
    while(tt--)
    {
		int n;
		cin>>n;
		int arr[n];
		int pre[n];
		for(int i=0;i<n;++i)
		{
			cin>>arr[i];
		}		
		pre[0] = arr[0];
		int sum  =0;
		for(int i=1;i<n;++i)
		{
			pre[i] = max(pre[i-1],arr[i]);
			sum+=(pre[i]-arr[i]);
		}
		cout<<sum;
		
    }
    return 0;
}


Measured memory_bytes: 6676
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
#define all(x) (x).begin(),(x).end()
#define pll pair<ll,ll>
#define pii pair<int,int>
#define rep(i,n) for(int i=0;i<n;i++)
#define For(i,a,b) for(int i=a;i<b;i++)
#define sz(x) ((ll)(x).size())
#define pb push_back
#define mp make_pair
#define bit(n) (1LL<<(n))
#define F first
#define S second
#define debug(x) cerr << x << endl
#define Complex complex<double>
int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};
const ll INF = 1LL<<60;
const ll mod = (int)1e9 + 7;

int main() {
    double l;
    cin >> l;
    cout << fixed;
    cout << setprecision(10) << pow(l/3,3);
    


}

/*



 */



Measured memory_bytes: 512
#include <iostream>
#include <vector>
#include <cmath>
#include <cstdlib>
#include <cstdio>
using namespace std;

#define INF 1e9;

int main(){
  int d, e;
  while(true){
    cin >> d >> e;
    if(d == 0)
      break;
    
    double nmin = INF;
    vector< vector<double> > cost(d+1, vector<double>(d+1));
    for(int i=0; i<=d/2; i++){
      int j = d-i;
      cost[i][j] = sqrt(i*i + j*j);
      cost[i][j] = abs(cost[i][j] - e);
      nmin = min(nmin, cost[i][j]);
    }

    printf("%.4f\n", nmin);
  }
  
  return 0;
}

Measured memory_bytes: 3328
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner input = new Scanner(System.in);
		int N = input.nextInt();
		int K = input.nextInt();
		N-=K;
		K--;
		long ans = 1;
		ans+=N/K;
		if (N%K!=0) ans++;
		System.out.println(ans);
	}
}

Measured memory_bytes: 22228
#include<bits/stdc++.h>
#define mp make_pair
#define pii pair<int,int>
#define pdd pair<double,double>
#define pll pair<ll,ll>
#define mst(a,b) memset(a,b,sizeof(a))
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
const double eps = 1e-9;
const int maxn = 1e5+9;
const double pi=3.14159265358979323846264;
const int inf = 1e9;
const ll mod = 1e9+7;

int main()
{
    ios::sync_with_stdio(false);
    int a,b,c,k;
    cin>>a>>b>>c>>k;
    if(a>=k) cout<<k;
    else if(a+b>=k) cout<<a;
    else cout<<a-(k-a-b);
    return 0;
}


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

struct UnionFind {
    vector<int> par; // parent
    UnionFind(int N) {
        par = vector<int>(N, -1); // negative num is size
    }
    int root(int x) {
        return par[x] < 0 ? x : par[x] = root(par[x]);
    }
    int size(int x) {
        return -par[root(x)];
    }
    bool same(int x, int y) {
        return root(x) == root(y);
    }
    void unite(int x, int y) {
        x = root(x);
        y = root(y);
        if (x == y) return;

        if (size(x) < size(y)) swap(x, y);
        par[x] += par[y];
        par[y] = x;
    }
};

int main() {
    int N, M;
    cin >> N >> M;
    int a[M], b[M];
    rep(i, M) {
        cin >> a[i] >> b[i];
        a[i]--; b[i]--;
    }
    
    UnionFind Uni(N);
    vector<ll> ans(M);
    ans[M-1] = (ll)N * (N - 1) / 2;
    for (int i = M - 1; i >= 1; i--) {
        ans[i-1] = ans[i];
        if (!Uni.same(a[i], b[i])) {
            ans[i-1] -= (ll)Uni.size(a[i]) * Uni.size(b[i]);
            Uni.unite(a[i], b[i]);
        }
    }
    rep(i, M) cout << ans[i] << endl;
}

Measured memory_bytes: 3328
#include<bits/stdc++.h>
using namespace std;
#define FOR(i,l,r) for(long long i=(l);i<(r);++i)
#define REP(i,n) FOR(i,0,n)
#define int long long

signed main(){
    string S;
    cin>>S;
    map<char,int>memo;
    bool ok=true;
    REP(i,S.size()){
        if(memo[S[i]]!=0){
            ok=false;
            break;
        }
        memo[S[i]]++; 
    }
    if(ok)cout<<"yes"<<endl;
    else cout<<"no"<<endl;
}


Measured memory_bytes: 256
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.List;
import java.util.ArrayList;
import java.util.Arrays;

public class Main {
	public static void main(String[] args) throws Exception {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));

		// 1行、2つ(複数)数字
		String[] ss0 = br.readLine().trim().split(" ", 0);
		long N = Integer.parseInt(ss0[0]);
		long A = Integer.parseInt(ss0[1]);
		long B = Integer.parseInt(ss0[2]);
		long C = Integer.parseInt(ss0[3]);
		long D = Integer.parseInt(ss0[4]);
		String ans = "NO";

		//dp(N + ", A=" + A + ", B=" + B + ", C=" + C + ", D=" + D);

		long m=0;
		do {
			if( (-1*D*m + C*(N-1-m)) <= (B-A) ) {
			if( (B-A) <= (-1*C*m + D*(N-1-m) ) ) { 
				ans="YES"; break;
			}
			}
			m++;
			if(m==N){break;}
		} while (true);


		System.out.println(ans);
	return;
	}
	//-----------------------------------------------------------------
	// Debug.Print
	static void dp(String s) {
		System.out.println(s);
	}
	static void dp(StringBuilder s) { dp(s.toString()); }
	static void dp(int i) { dp(String.valueOf(i)); }
	static void dp(long i) { dp(String.valueOf(i)); }


}


Measured memory_bytes: 21460
#pragma GCC optimize("O3")
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
//mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
ll N;
ll memo[109][100010];
vector<pair<ll,ll> >v;
ll sol(ll pos,ll peso){
  if(peso<0)return -1000000000;
  if(pos>=N)return 0;
  if(memo[pos][peso])return memo[pos][peso];
  return memo[pos][peso]=max(sol(pos+1,peso),sol(pos+1,peso-v[pos].first)+v[pos].second);
}
int main(){
		ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
		//freopen("input.txt","r",stdin);
		//freopen("output.txt","w",stdout);
		ll W;
    cin>>N>>W;
    for(ll i=0;i<N;i++){
      ll a,b;
      cin>>a>>b;
      v.push_back({a,b});
    }
    cout<<sol(0,W);
    return 0;
}

Measured memory_bytes: 78080
#include "bits/stdc++.h"
using namespace std;
//#include <stdio.h>
//#include <assert.h>

#define MIN(x, y) ((x) < (y) ? (x) : (y))
#define MAX(x, y) ((x) > (y) ? (x) : (y))

#define DIVUP(x, y) (((x) + ((y) - 1)) / (y))
#define DIVOFF(x, y) (((x) + ((y) / 2)) / (y))
#define REMAINDER(x, y) ((x) % (y))

char abcd[4 + 1];

bool dfs(int depth, array<char, 4> sign) {
  if (depth >= 4) {
    int ans = abcd[0] & 0xF;
    for (int i{1}; i < 4; ++i) {
      if (sign[i] == '+') {
        ans += abcd[i] & 0xF;
      } else {
        ans -= abcd[i] & 0xF;
      }
    }
    if (ans == 7) {
      printf("%c", abcd[0]);
      for (int i{1}; i < 4; ++i) {
        printf("%c%c", sign[i], abcd[i]);
      }
      printf("=7\n");
      return true;
    }
    return false;
  }

  sign[depth] = '+';
  if (dfs(depth + 1,sign)) return true;
  sign[depth] = '-';
  if (dfs(depth + 1,sign)) return true;

  return false;
}

int main() {
  scanf("%4s", abcd);

  array<char, 4> sign;
  dfs(1, sign);
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define MAX (ll)(8e1 + 7)
#define INF (ll)(1e18)
#define MOD (ll)(1e9 + 7)

using namespace std;
using ll = long long;
using cd = complex<double>;

int main () {
	int x, y;
	cin >> x >> y;	
	bool fl = 0;
	for (int i = 0; i <= x; i++) {
		if (2 * i + (x - i) * 4 == y) {
			fl = 1;
		}
	}
	cout << (fl ? "Yes\n" : "No\n");
}



Measured memory_bytes: 3604
#include<iostream>
#include<cstdio>
#include<cstring>
using namespace std;
int a[100001],b[100001],c[100001];
int n,dp[100001][3];
int main()
{
	scanf("%d",&n);
	for(int i=1;i<=n;i++)
	{
		scanf("%d%d%d",&a[i],&b[i],&c[i]);
	}
	for(int i=1;i<=n;i++)
	{
		dp[i][0]=max(dp[i][0],max(dp[i-1][1]+a[i],dp[i-1][2]+a[i]));
		dp[i][1]=max(dp[i][1],max(dp[i-1][0]+b[i],dp[i-1][2]+b[i]));
		dp[i][2]=max(dp[i][2],max(dp[i-1][0]+c[i],dp[i-1][1]+c[i]));
	}
	cout<<max(max(dp[n][0],dp[n][1]),dp[n][2]);
	return 0;
}


Measured memory_bytes: 2688
#include<iostream>
#include<stdio.h>
#include<vector>
#include<ctype.h>
#include<string>
#include<cmath>
#include<string.h>
#include<sstream>
#include<limits.h>
#define rep(i,n) for(int i=0;i<(n);++i)
using namespace std;
typedef long long int ll;
typedef vector<int> vi;

//最大公約数
int gcd(int a,int b){
    return b ? gcd(b,a%b):a;
}

//最小公倍数
int lcm(int a,int b){
    return a/gcd(a,b)*b;
}

//素数判定
bool isPrime(int x){
    if(x<2)return 0;
    else if(x==2)return 1;
    if(x%2==0)return 0;
    for(int i=3;i*i<=x;i+=2){
        if(x%i==0)return 0;
    }
    return 1;
}

//桁ごとの足し算
int digsum(int n){
    int res=0;
    while(n>0){
        res+=n%10;
        n/=10;
    }
    return res;
}

//約数列挙
vector<int> enum_div(int n){
    vector<int> ret;
    for(int i=1;i*i<=n;++i){
        if(n%i==0){
            ret.push_back(i);
            if(i*i !=n){
                ret.push_back(n/i);
            }
        }
    }
    return ret;
}

//累乗の計算とあまり,0で累乗そのまま出力
long long modpow(long long a,long long n,long long mod){
    if(mod==0)mod=__LONG_LONG_MAX__;
    long long res=1;
    while(n>0){
        if(n & 1)res=res*a%mod;
        a=a*a%mod;
        n>>=1;
    }
    return res;
}

int N;
vi a;
int ans=0;
int main(){
    cin>>N;
    a.resize(N+1);
    for(int i=1;i<=N;i++){
        cin>>a[i];
        if(a[i]%2==1 && i%2==1)ans++;
    }
    cout<<ans<<endl;
    return 0;
}

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

using namespace std;
typedef long long lint;

char s[55];
int i, a[55], b[55];

char pm(int x)
{
    if(x == 0)
        return '-';
    else return '+';
}

bool solution()
{
    int sum = a[1];
    if(b[1] == 0)
    sum -= a[2]; else sum += a[2];
    if(b[2] == 0)
    sum -= a[3]; else sum += a[3];
    if(b[3] == 0)
    sum -= a[4]; else sum += a[4];
    if(sum == 7) return true;
    else return false;
}

void bk(int k)
{
    for(int i = 0; i <= 1; i ++)
    {
        b[k] = i;
        if(k == 3)
            {
                if(solution())
                    {
                        printf("%d%c%d%c%d%c%d=7", a[1], pm(b[1]), a[2], pm(b[2]),
                                                    a[3], pm(b[3]), a[4]);
                        exit(0);
                    }
            }
        else bk(k+1);
    }
}

int main()
{
    //freopen("f.in", "r", stdin);
    //freopen("f.out", "w", stdout);

    scanf("%s", s);
    for(i = 0; i < 4; i ++)
        a[i+1] = s[i] - '0';

    bk(1);

    return 0;
}


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

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

using namespace std;
using ll = long long;
using P = pair<int, int>;

void Main() {
  int n;
  cin >> n;
  vector<int> P(n);
  rep(i, n) cin >> P[i];

  int count = 0;
  rep(i, n) if (P[i] != i+1) count++;
  if (count > 2) cout << "NO" << endl;
  else cout << "YES" << endl;
  return;
}

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


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ll long long
#define pb push_back
#define sz size
#define se second
#define fe first
#define mper make_pair
#define all(x) x.begin(), x.end()
#define mal ios_base::sync_with_stdio(NULL);cin.tie(NULL);cout.tie(NULL);
#define saken string
#define erba continue
using namespace std;

const ll MAXN = 1e5 + 10;
ll n, a[MAXN], sum, ans;

int main(){

cin >> n;

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



for(int i = 1; i <= n; ++i) {


    if(a[i] % 2 != 0){

        if(a[i + 1]) {a[i]--; a[i + 1]--; ans++;}

    }

    ans += (a[i] / 2);

}

cout << ans;

return 0;
}



Measured memory_bytes: 1024
#include<bits/stdc++.h>
#define endl '\n';
#define rep(i,n) for(int i=0; i<(n); i++)
using namespace std;
using ll = long long;
using P = pair<int,int>;
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#pragma GCC optimize("Ofast")
constexpr ll INF = 1e18;
constexpr int inf = 1e9;
constexpr double INFD = 1e100;
constexpr ll mod = 1000000007;
constexpr ll mod2 = 998244353;
const double PI = 3.1415926535897932384626433832795028841971;
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};
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; }
// ios::sync_with_stdio(false);
// cin.tie(nullptr);
// ---------------------------------------------------------------------------

int main(){
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    int A,L;
    cin >> A >> L;
    while(L != 0){
        map<int,int> mp;
        mp[A] = 0;
        int cnt = 0;
        while(1){
            cnt++;
            string s = to_string(A);
            sort(s.begin(),s.end());
            int mn = stoi(s);
            sort(s.begin(),s.end(),greater<char>());
            while(s.size() != L){
                s += '0';
            }
            int mx = stoi(s);
            A = mx - mn;
            if(mp.count(A)){
                cout << mp[A] << " " << A << " " << cnt-mp[A] << endl;
                break;
            }
            mp[A] = cnt;
        }
        cin >> A >> L;
    }
    return 0;
}


Measured memory_bytes: 3280
#include <cstdio>
#include <algorithm>
using namespace std;
const int mod = 1000000007;
long long inv[100100]={0,1},fact[100100]={1,1},ifact[100100]={1,1};
int N,M,U[16]; long long prv[1<<16];
int main()
{
	for (int i=2;i<100100;i++){
		inv[i] = (mod - mod / i) * inv[mod % i] % mod;
		fact[i] = fact[i-1] * i % mod;
		ifact[i] = ifact[i-1] * inv[i] % mod;
	}
	scanf ("%d %d",&N,&M);
	for (int i=0;i<M;i++) scanf ("%d",&U[i]);
	sort(U,U+M);
	reverse(U,U+M);
	prv[0] = 1;
	for (int i=0;i<M;i++){
		for (int j=(1<<N)-1;j>=0;j--) if (prv[j]){
			int rem = (1<<N) - U[i] - j;
			if (rem < 0) continue;
			for (int k=0;k<N;k++) if (~j & (1 << k)){
				if (rem < (1<<k)-1) break;
				long long coeff = (1<<k) * prv[j] % mod * fact[rem] % mod * ifact[rem-(1<<k)+1] % mod;
				prv[j+(1<<k)] = (prv[j+(1<<k)] + mod - coeff) % mod;
			}
		}
	}
	long long ans = 0;
	for (int j=0;j<(1<<N);j++){
		ans = (ans + prv[j] * fact[(1<<N)-1-j]) % mod;
	}
	for (int i=0;i<N;i++) ans = ans * 2 % mod;
	printf ("%lld\n",ans);
	return 0;
}

Measured memory_bytes: 3072
import java.util.*;

public class Main {
    static int fun(int n){
        int ans=0;
        for(int i=0;i<10;i++){
            for(int j=0;j<10;j++){
                for (int k=0;k<10;k++){
                    for (int l=0;l<10;l++){
                        if(i+j+k+l==n)ans+=1;
                    }
                }
            }
        }
        return ans;
    }
    public static void main(String[] args) throws Exception {
        Scanner sc = new Scanner(System.in);
        while(sc.hasNext()){
        System.out.println(fun(sc.nextInt()));
    }
    }
}


Measured memory_bytes: 26432
#include <bits/stdc++.h>
using namespace std;
typedef long long  ll;
#define FOR(i,a,n) for(ll i=(ll)a;i<(ll)n;i++)
#define RFOR(i,a,n) for(ll i=(ll)n-1;i >= (ll)a;i--)
#define rep(i,n) FOR(i,0,n)
#define rrep(i,n) RFOR(i,0,n)
#define ALL(v) v.begin(), v.end()
#define bra(x,y) '(' << x << ',' << y << ')'
ll MOD = 1000000007;
ll INF = 214748364700000000;
long double EPS = 1e-11;
long double PI = 3.141592653589793238;
template<typename T>
void remove(std::vector<T>& vector, unsigned int index){
    vector.erase(vector.begin() + index);
}

using Graph = vector<vector<pair<ll,ll>>>;



int main(){
   ll X,Y,Z,K;
   cin >> X >> Y >> Z >> K;
   vector<ll> A(X),B(Y),C(Z);
   rep(i,X) cin >> A[i];
   rep(i,Y) cin >> B[i];
   rep(i,Z) cin >> C[i];
   sort(ALL(A));reverse(ALL(A));
   sort(ALL(B));reverse(ALL(B));
   sort(ALL(C));reverse(ALL(C));
   vector<ll> ans;
   rep(i,X) rep(j,Y) rep(k,Z){
      if(i*j + j+k + k+i > K) break;
      ans.push_back(A[i] + B[j] + C[k]);
   }
   sort(ALL(ans));reverse(ALL(ans));
   rep(i,K) cout << ans[i] << endl;
}


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

typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;

#define REP(i, n) for (int i = 0; i < (int)(n); i++)
#define FOR(i, a, b) for (int i = (int)(a); i < (int)(b); i++)
#define FORR(i, a, b) for (int i = (int)(b)-1; i >= (int)(a); i--)

#define CHMIN(a, b) (a) = min((a), (b))
#define CHMAX(a, b) (a) = max((a), (b))

#define DEBUG(x) cout << #x << ": " << (x) << endl

int main() {
  int x;
  cin >> x;
  if (x == 5 || x == 3 || x == 7)
    cout << "YES" << endl;
  else
    cout << "NO" << endl;
}

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

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

	int count;
	// ceil(a / b) = (a + b - 1) / b
	// 下の例で，a = N, b = 2 とすればわかる
	count = (N + 1) / 2;

	double ans;
	ans = (double)count / N;
	printf("%.10f\n", ans);
}


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


Measured memory_bytes: 3580
#pragma GCC optimize ("O3")
#include <bits/stdc++.h>
#define endl "\n"
#define sz(x) ((ll)(x).size())
#define pb push_back
#define all(x) (x).begin(),(x).end()
#define prt(x) cout << (x)
#define prtl(x) cout << (x) << endl
#define rep(i,a,b) for(ll i=a; i<b; i++)
#define rrep(i,a,b) for(ll i=a; i>b; i--)
#define mp(a, b) make_pair(a, b)
#define chmin(x, y) x = min(x, y)
#define chmax(x, y) x = max(x, y)
#define debug(v) cout << #v<< ": " << v <<endl;
using namespace std;
using vi = vector<int>;
using vll = vector<long long int>;
using vb = vector<bool>;
using vvb = vector<vector<bool>>;
using vc = vector<char>;
using vvi = vector<vector<int>>;
using vvll = vector<vector<long long int>>;
using vvc = vector<vector<char>>;
using ll = long long int;
using P = pair<long long int, long long int>;
using Map = map<long long int, long long int>;
using Set = set<long long int>;
ll INF = 1LL<<60;
ll M = 1000000007;

int main(){
    ll N; cin >> N;
    vll a(N);
    rep(i, 0, N){
        cin >> a[i];
    }
    Map m; Set s;
    s.insert(INF);
    s.insert(-INF);
    ll mx= -INF, mn = INF;
    ll ans = 0;
    rep(i, 0, N){
        if(i == 0){
            ans++;
            s.insert(a[i]);
            m[a[i]]++;
            mx = a[i]; mn = a[i];
        }else{
            if(a[i] > mx){
                mx = a[i];
                auto n = s.end();
                --n; --n;
                ll k = *n;
                if(m[k] == 1){
                    s.erase(k);
                    m[k]--;
                }else{
                    m[k]--;
                }
                s.insert(mx);
                m[mx]++;
            }else if(a[i] < mn){
                ans++;
                mn = a[i];
                s.insert(mn);
                m[a[i]]++;
            }else{
                auto n = s.lower_bound(a[i]);
                --n;
                ll k = *n;
                if(k == -INF){
                    ans++;
                    s.insert(a[i]);
                    m[a[i]]++;
                    continue;
                }
                if(m[k] == 1){
                    s.erase(k);
                    m[k]--;
                }else{
                    m[k]--;
                }
                if(m[a[i]] == 0){
                    m[a[i]]++;
                    s.insert(a[i]);
                }else{
                    m[a[i]]++;
                }
            }
        }
    }
    prtl(ans);
}



Measured memory_bytes: 14704
#define _CRT_SECURE_NO_WARNINGS
#include <iostream>
#include <cstdio>
#include <vector>
#include <cmath>
#include <cstring>
#include <numeric>
#include <algorithm>
#include <functional>
#include <fstream>
#include <array>
#include <map>
#include <queue>
#include <time.h>
#include <limits.h>
#include <set>
#include <stack>
#include <random>
#include <complex>
#include <unordered_map>
#include <assert.h>
#include <unordered_set>
#define rep(i,s,n) for(int i = (s); (n) > i; i++)
#define REP(i,n) rep(i,0,n)
#define RANGE(x,a,b) (min(a,b) <= (x) && (x) <= max(a,b)) //hei
#define DUPLE(a,b,c,d) (RANGE(a,c,d) || RANGE(b,c,d) || RANGE(c,a,b) || RANGE(d,a,b))
#define INCLU(a,b,c,d) (RANGE(a,c,d) && (b,c,d))
#define PW(x) ((x)*(x))
#define ALL(x) (x).begin(), (x).end()
#define RALL(x) (x).rbegin(), (x).rend()
#define MODU 1000000007LL 
#define bitcheck(a,b)   ((a >> b) & 1)
#define bitset(a,b)      ( a |= (1 << b))
#define bitunset(a,b)    (a &= ~(1 << b))
#define MP(a,b) make_pair((a),(b))
#define Manh(a,b) (abs((a).first-(b).first) + abs((a).second - ((b).second))
#define pritnf printf
#define scnaf scanf
#define itn int
#define PI 3.141592653589
 
 
#define izryt bool
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
template<typename A, size_t N, typename T>
void Fill(A(&array)[N], const T & val) {
	std::fill((T*)array, (T*)(array + N), val);
}
 
//[a, b)
#define Getsum(ar, a,b) (ar[b] - ar[a])
#define INF 10000000000000000LL
#define chmax(a,b) a = max(a,b)
#define chmin(a,b) a = min(a,b)
 
struct Edge {
	int from, to;
	ll w;
	bool operator<(const Edge& rhs) const {
		return MP(w, MP(from, to)) < MP(rhs.w, MP(rhs.from, rhs.to));
	}
 
};
typedef vector<vector<Edge>> Graph;
typedef unsigned long long ull;

ll gcd(ll a, ll b) {
	if (b == 0) return a;
	return gcd(b, a%b);
}

ll lcm(ll m, ll n)
{
	return m * n / gcd(m, n);
}
ll mod_pow(ll x, ll n) {
	ll res = 1;
	while (n > 0) {
		if (n & 1) res = (res * x) % MODU;
		x = (x*x)%MODU;
		n >>= 1;
	}
	return res;
}
ll divmod(ll a, ll b) { // a/b(mod m)
								  // a/b (mod m)
								  // a*b^-1
								  // b^-1 * b = 1
								  // b^(m-1) = 1 
								  // b^(m-2) * b = 1
								  // b^-1 = b^(m-2)

								  // a/b = a * b^(m-2)

	return (a * mod_pow(b, MODU - 2)) % MODU;
}


ll fmemo[10000] = {};
ll factorial(ll n) {//階乗

	if (n > 0) {
    assert(n < 10000);
if(fmemo[n] != 0) return fmemo[n];
		return fmemo[n] = (n * factorial(n - 1))%MODU;
	}
	else {
		return 1;
	}
}

int main(){
  int n, k;
  cin >> n >> k;
  ll dp[100001] = {};

  rep(i,1, k + 1){
    dp[i] = mod_pow(k / i, n);
  }
  ll ans = 0;
  for(int i = k; 1 <= i; i--){
    for(int j = 2; i * j <= k; j++){
      dp[i] -= dp[i * j];
      dp[i] %= MODU;
    }
    ans += dp[i] * i;
    ans %= MODU;
  }
  cout << (MODU + ans)%MODU << endl;
  return 0;
} 

Measured memory_bytes: 3976
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

#include <iostream>
#include <string>
#include <vector>
#include <map>
#include <unordered_map>
#include <queue>
#include <algorithm>

#include <bits/stdc++.h>
#include <cmath>
#include <limits>

using namespace std;

#define MAX 200002
long long MOD = 1000000007;
long long MODPOW2[MAX] = {0};

void initModPow2(){
	MODPOW2[0] = 1;
	for(int i=1; i<MAX; i++){
		MODPOW2[i] = (MODPOW2[i-1]*2)%MOD;
	}
}

long long GCD(long long x, long long y){
        long long r=0;
        if( x<y ) swap(x, y);
        r = x % y;
        while(r!=0){
                x = y;
                y = r;
                r = x % y;
        }
        return y;
}

// U(u個)とV(v個)が直交しているとき、どの2つも内積が0にならない選び方の数
// 余事象で考えて、2**(u+v)から内積が0になりうる選び方の数を引く
long long countUV(long long u, long long v){
	long long a=0, b=0, c=0, ret=0;
	a = MODPOW2[u+v] % MOD;
	b = (MODPOW2[u] - 1) % MOD;
	b = (b*(MODPOW2[v] - 1)) % MOD;
	ret = (a - b) % MOD;
	if(ret<0) ret += MOD;
	return ret;
}

class Tilt{
public:
	long long x;
	long long y;
	Tilt(){x = 0, y = 0;}
	Tilt(long long x, long long y){
		if(x == 0){
			this->x = 0; this->y = 1;
		}
		else if(y == 0){
			this->x = 1; this->y = 0;
		}
		else{
			long p, a, b;
			p = GCD(x, y);
			a = x / p; b = y / p;
			if(a > 0){
				this->x = a; this->y = b;
			}
			else{
				this->x = 0 - a; this->y = 0 - b;
			}
		}
	}
	inline bool operator==(const Tilt &t) const{
		if(x == t.x && y == t.y){
			return true;
		}
		else{
			return false;
		}
	}
	inline bool operator!=(const Tilt &t) const{
		return !(this->operator==(t)) ;
	}
};

//ハッシュ関数定義
//約分されている前提で、分子の値を返す
class MyHash {
public:
	std::size_t operator() (const Tilt& t) const {
		return (std::size_t) abs(t.x);
	}
};

unordered_map<Tilt, long long, MyHash> m1;

int main(int argc, char* argv[]){
	int N, M;
	long long zero = 0;

	cin >> N;
	m1.reserve(N);

	initModPow2();
	long long ans=1; 
	for(int i=1; i<=N; i++){
		long long a, b;
		cin >> a >> b;

		if(a == 0 && b == 0){
			zero++;
			continue; //(0, 0)は除外するが、数えておく
		}
		Tilt t =Tilt(a, b);
		if(m1.count(t)==0){
			m1[t] = 1;
		}
		else{
			long long v = m1[t];
			m1[t] = v+1;
		}
	}
	for(auto itr = m1.begin(); itr != m1.end(); itr++){
		long long x, y, u, v;
		Tilt t = itr->first;
		if(m1[t] == -1){
			continue;
		}
		u = itr->second;
		if(u == -1) continue;
		x = t.x;
		y = t.y;
		Tilt w = Tilt(0 - y, x); //法線ベクトル
		auto tmpitr2 = m1.find(w);
		if( tmpitr2 != m1.end()){
			v = m1[w];
			m1[w] = -1;
		}
		else{
			v = 0;
		}
		long long uvcnt = countUV(u, v);
		ans = (ans * uvcnt) % MOD;
		m1[t] = -1;
	}
	ans = ans + (zero % MOD) -1 ; //(0, 0)は他のどの要素とも直交するので足す。まったく選ばないを引く。
	ans = ans % MOD;
	if(ans < 0) ans += MOD;
	cout << ans << endl;
	return 0;
}



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

using namespace std;

using ll = long long;
using P = pair<ll, ll>;
using Graph = vector<vector<ll>>;
#define rep(i, n) for(ll i=0;i<(ll)(n);i++)
#define rep2(i, m, n) for(ll i=m;i<(ll)(n);i++)
#define rrep(i, n, m) for(ll i=n;i>=(ll)(m);i--)
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};
const int ddx[8] = {0, 1, 1, 1, 0, -1, -1, -1};
const int ddy[8] = {1, 1, 0, -1, -1, -1, 0, 1};
const ll MOD = 1000000007;
const ll INF = 1000000000000000000L;
#ifdef __DEBUG

/**
 * For DEBUG
 * https://github.com/ta7uw/cpp-pyprint
 */
#include "cpp-pyprint/pyprint.h"

#endif

void Main() {
    ll N, K;
    cin >> N >> K;
    vector<ll> L(N);
    rep(i, N) cin >> L[i];
    sort(L.rbegin(), L.rend());
    ll s = accumulate(L.begin(), L.begin() + K , 0);
    cout << s << '\n';
}

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


Measured memory_bytes: 256
def main():
    H, W = map(int, input().split())
    a = [None] * H
    i = 0
    while i < H:
        a[i] = str(input())
        i += 1

    print('#' * (W + 2))
    for s in a:
        print('#{}#'.format(s))
    print('#' * (W + 2))

main()


Measured memory_bytes: 3060
#include <bits/stdc++.h>
using namespace std;
using lint = long long;
const lint mod = 998244353;
#define all(x) (x).begin(), (x).end()
#define bitcount(n) __builtin_popcountl((lint)(n))
#define fcout cout << fixed << setprecision(15)
#define highest(x) (63 - __builtin_clzl(x))
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; }
template<class T = string, class U = char>int character_count(T text, U character){ int ans = 0; for(U i: text){ ans += (i == character); } return ans; }
lint power(lint base, lint exponent, lint module){ if(exponent % 2){ return power(base, exponent - 1, module) * base % module; }else if(exponent){ lint root_ans = power(base, exponent / 2, module); return root_ans * root_ans % module; }else{ return 1; }}
struct position{ int y, x; }; position mv[4] = {{0, -1}, {1, 0}, {0, 1}, {-1, 0}}; // double euclidean(position first, position second){ return sqrt((second.x - first.x) * (second.x - first.x) + (second.y - first.y) * (second.y - first.y)); }
template<class T, class U> string to_string(pair<T, U> x){ return to_string(x.first) + "," + to_string(x.second); } string to_string(string x){ return x; }
template<class itr> void array_output(itr start, itr goal){ string ans; for(auto i = start; i != goal; i++) ans += to_string(*i) + " "; if(!ans.empty()) ans.pop_back(); cout << ans << endl; }
template<class itr> void cins(itr first, itr last){ for(auto i = first; i != last; i++){ cin >> (*i); } }
template<class T> T gcd(T a, T b){ if(a && b){ return gcd(min(a, b), max(a, b) % min(a, b)); }else{ return a; }} template<class T> T lcm(T a, T b){ return a / gcd(a, b) * b; }
struct combination{ vector<lint> fact, inv; combination(int sz) : fact(sz + 1), inv(sz + 1){ fact[0] = 1; for(int i = 1; i <= sz; i++){ fact[i] = fact[i - 1] * i % mod; } inv[sz] = power(fact[sz], mod - 2, mod); for(int i = sz - 1; i >= 0; i--){ inv[i] = inv[i + 1] * (i + 1) % mod; } } lint C(int p, int q) const{ if(q < 0 || p < q) return 0; return (fact[p] * inv[q] % mod * inv[p - q] % mod); } };
template<class itr> bool next_sequence(itr first, itr last, int max_bound){ itr now = last; while(now != first){ now--; (*now)++; if((*now) == max_bound){ (*now) = 0; }else{ return true; } } return false; }
template<class itr, class itr2> bool next_sequence2(itr first, itr last, itr2 first2, itr2 last2){ itr now = last; itr2 now2 = last2; while(now != first){ now--, now2--; (*now)++; if((*now) == (*now2)){ (*now) = 0; }else{ return true; } } return false; }

int main(){
    string S;
    cin >> S;
    int ans = 0, now = 0;
    bool is_back = true;
    while(now < S.size()){
        if(is_back){
            is_back = false;
            ans++, now++;
            continue;
        }
        if(S[now] == S[now - 1]){
            if(now + 1 == S.size()){
                break;
            }else{
                ans++, now += 2;
                is_back = true;
            }
        }else{
            ans++, now++;
        }
    }
    cout << ans << endl;
}




Measured memory_bytes: 640
/*-----rk_98-----*/
#include<bits/stdc++.h>
#define fast() ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define ll long long
#define mod 1000000007
#define eps 1e-9
#define ff first
#define ss second
#define pb push_back
#define endl "\n"
using namespace std;
vector<vector<ll> > mat_expo (vector<vector<ll> > a, ll b , ll m, ll s)
{
	if(b==1)
		return a;
	vector<vector<ll> > temp = mat_expo(a,b/2,m,s), foo( s);
	for(ll i=0;i<s;i++)
	{
		foo[i].reserve(s);
		for(ll j =0;j<s;j++)
		{
			ll sum=0;
			for(ll k =0;k<s;k++)
			{
				sum+= (temp[i][k]*temp[k][j]) % m;
				sum%=m;
			}
			foo[i][j]=sum;
		}
	}
	if(b %2)
	{
		for(ll i=0;i<s;i++)
		{
			for(ll j =0;j<s;j++)
			{
				ll sum=0;
				for(ll k =0;k<s;k++)
				{
					sum+= (foo[i][k]*a[k][j]) % m;
					sum%=m;
				}
				temp[i][j]=sum;
			}
		}
		return temp;
	}
	return foo;
}
int main()
{
    //fast();
    ll n,k;
    cin>>n>>k;
    vector<vector<ll> > foo( n , vector<ll>(n) );
    for( ll i=0 ;i<n;i++)
    {
    	for(ll j=0 ; j< n ; j++)
    		cin>>foo[i][j];
    }
    foo = mat_expo(foo , k , mod , n);
    ll ans=0;
    for(ll i=0 ; i < n ;i++)
    	for( ll j =0 ; j< n ; j++ )
    		ans  = (ans + foo[i][j]) % mod;
    cout<<ans<<endl;
}


Measured memory_bytes: 1536
#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>;
const int INF = 1 << 29;
 
int main() {
	int n, m;
	cin >> n >> m;
	int left = -1, right =  n + 1;
	rep(i,m) {
		int l, r;cin >> l >> r;
		left = max(left, l);
		right = min(right, r);
	}
	if (left > right) cout << 0 << endl;
	else cout << right - left + 1 << endl;
	return 0;
}

Measured memory_bytes: 256
//
//  main.cpp
//  ABC 065 A
//
//  Created by Shuangyi Zhang on 2017/6/24.
//  Copyright © 2017年 Shuangyi Zhang. All rights reserved.
//

#include <iostream>
using namespace std;
int main() {
    int x,a,b;
    cin>>x>>a>>b;
    if (b-a<=0){
        cout<<"delicious";
    }else if (b-a<=x){
        cout<<"safe";
    }else{
        cout<<"dangerous";
    }
    cout<<endl;
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
using namespace std;
#define MAX 100005
#define NIL -1

struct Node {
  int p, l, r;
};

Node T[MAX];
int D[MAX];
int n;

void printNode(int u) {
  int i, c;
  cout << "node " << u << ": ";
  cout << "parent = " << T[u].p << ", ";
  cout << "depth = " << D[u] << ", ";

  if (T[u].p == NIL) {
    cout << "root, [";
  } else if (T[u].l == NIL) {
    cout << "leaf, [";
  } else{
    cout << "internal node, [";
  }

  // 複雑に見えるが、iは単にコンマを出力するかどうかの判定に使っているだけ
  // 実質はT[u]の最も左の子供、すなわりT[u].lから右に右に兄弟をたどっていってるだけ
  for (int i = 0, c= T[u].l; c != NIL; i++, c=T[c].r) {
    // コンマ出力
    if (i) {
      cout << ", ";
    }
    cout << c;
  }
  cout << "]" << endl;
}

// ノードuに深さpをsetする関数
void rec(int u, int p) {
  D[u] = p;
  if (T[u].r != NIL) {
    rec(T[u].r, p);
  }
  if (T[u].l != NIL) {
    rec(T[u].l, p+1);
  }
}

int main() {

  cin >> n;

  // 各ノードを初期化
  for(int i = 0; i < n; i++) {
    T[i].p = T[i].l = T[i].r = NIL;
  }

  // 入力を一行ずつ処理していく
  for(int i = 0; i < n; i++) {
    int v, d;
    cin >> v >> d;
    // それぞれの子ノードを突っ込んでいく
    int l;
    for (int j = 0; j < d; j++) {
      int c;
      cin >> c;
      if (j == 0) {
        // j=0のときだけ、
        // vの最も左の子(=l)を定義
        T[v].l = c;
      } else {
        // lのすぐ右の子(=lの兄弟)を定義
        T[l].r = c;
      }
      // 次のループ用に、lにcを代入
      l = c;
      // cの親はvだと名乗る
      T[c].p = v;
    }
  }

  int r;
  for (int i = 0; i<n; i++) {
    if (T[i].p == NIL) {
      r = i;
    }
  }
  rec(r, 0);

  for (int i = 0; i < n; i++) {
    printNode(i);
  }
}



Measured memory_bytes: 7776
#include <bits/stdc++.h>
#define rep(i, n) for(int i = 0; i < (n); i++)
#define all(a) a.begin(), a.end()
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; }
using namespace std;

// AtCoder Beginner Contest 141
int main(){

    string s;
    cin >> s;

    if(s == "Sunny"){
        cout << "Cloudy" << endl;
    } else if(s == "Cloudy"){
        cout << "Rainy" << endl;
    } else {
        cout << "Sunny" << endl;
    }

}

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

int main(){
    int N, M;
    while(scanf("%d%d", &N, &M) != EOF && (N||M)){
        int h[1505], w[1505];
        h[0] = 0;
        for(int i = 1; i <= N; i++){
            scanf("%d", h+i);
            h[i] += h[i-1];
        }
        w[0] = 0;
        for(int i = 1; i <= M; i++){
            scanf("%d", w+i);
            w[i] += w[i-1];
        }
        int pat[1500001];
        fill(pat, pat+1500001, 0);
        for(int i = 0; i < N; i++){
            for(int j = i+1; j <= N; j++){
                ++pat[h[j] - h[i]];
            }
        }
        int ret = 0;
        for(int i = 0; i < M; i++){
            for(int j = i+1; j <= M; j++){
                ret += pat[w[j] - w[i]];
            }
        }
        printf("%d\n", ret);
    }
    return 0;
}

Measured memory_bytes: 7060