akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
const int maxn = 2e5 + 10;
typedef long long ll;
int n;
int a[maxn], prep[maxn], sufp[maxn];
ll ans = 1e18;
ll pre[maxn], suf[maxn];
int main()
{
	scanf("%d", &n);
	for(int i = 1; i <= n; ++i) scanf("%d", &a[i]);
	
	int cur = 1;
	pre[1] = a[1];
	for(int i = 2; i <= n; ++i) 
	{
		pre[i] = pre[i - 1] + a[i];
		while(pre[cur] * 2 <= pre[i]) ++cur;
		prep[i] = cur - 1;
	}
	
	cur = n;
	suf[n] = a[n];
	for(int i = n - 1; i; --i)
	{
		suf[i] = suf[i + 1] + a[i];
		while(suf[cur] * 2 <= suf[i]) --cur;
		sufp[i] = cur - 1;
	}
	
	for(int i = 3; i < n; ++i)
	{
		int l2 = i - 1;
		for(int j = 0; j < 2; ++j)
			for(int k = 0; k < 2; ++k)
			{
				int l1 = prep[i - 1] + j;
				int l3 = sufp[i] + k;
				if(l1 < l2 && l2 < l3 && l3 < n)
				{
					ll x1 = pre[l1], x2 = pre[l2] - pre[l1], x3 = pre[l3] - pre[l2], x4 = pre[n] - pre[l3];
					//cout << i << ' ' << x1 << ' ' << x2 << ' ' << x3 << ' ' << x4 << endl;
					ans = min(ans, max(max(x1, x2), max(x3, x4)) - min(min(x1, x2), min(x3, x4)));
				}
			}
	}
	printf("%lld\n", ans);
	return 0;
}
			
		
	

Measured memory_bytes: 5760
#include<bits/stdc++.h>
using namespace std;
int l,r,a[100009],b[100009]={0,1};
int main(){
    for(int i=2;i<=100000;i++)
        for(int j=2*i;j<=100000;j+=i)
            b[j]=1;
    for(int i=1;i<=100000;i++){
        if(!b[i] && !b[(i+1)/2] && i!=2)
            a[i]=a[i-1]+1;
        else a[i]=a[i-1];
    }
    cin>>l;
    while(cin>>l>>r) cout<<a[r]-a[l-1]<<endl;
    return 0;
}

Measured memory_bytes: 1408
#include <iostream>
#include <iomanip>
#include <vector>
#include <set>
#include <string>
#include <queue>
#include <algorithm>
#include <map>
#include <cmath>
#include <numeric>
#include <list>
#include <stack>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <tuple>
#include <deque>
#include <complex>

using namespace std;

/*
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef pair<int, int> pii;
typedef vector<pii> vpii;
*/

typedef long long ll;
typedef vector<ll> vll;
typedef vector<vll> vvll;
typedef pair<long long, long long> pll;
typedef vector<pll> vpll;

typedef long double ld;
typedef vector<ld> vld;

typedef vector<bool> vb;

#define rep(i, n) for (ll i = 0; i < (n); i++)
#define reps(i, n) for (ll i = 1; i <= (n); i++)
#define rrep(i, n) for (ll i = (n) - 1; i >= 0; i--)
#define rreps(i, n) for (ll i = (n); i >= 1; i--)
#define all(v) (v).begin(), (v).end()

template <class T> void chmin(T& a, T b) { a = min(a, b);}
template <class T> void chmax(T& a, T b) { a = max(a, b);}

constexpr int INF = 1 << 30;
constexpr ll INFL = 1LL << 60;
constexpr ll MOD = 1000000007;
constexpr ld EPS = 1e-12;
ld PI = acos(-1.0);

void solve() {
    ll l, r, d;
    cin >> l >> r >> d;
    ll ans = 0;
    for(ll i = l; i <= r; ++i) {
        if(i % d == 0) ++ans;
    }
    cout << ans << endl;
    return;
}

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

Measured memory_bytes: 3632
#include <stdio.h>


/*struct heap{
  int key;

  };*/
void buildMaxHeap(int *);
void maxHeapify(int *,int);
int H;

int main(){
  int i;

  scanf("%d",&H);
  int A[H+1];

  for(i=1;i<H+1;i++){
    scanf("%d",&A[i]);
  }

  buildMaxHeap(A);
  for(i=1;i<H+1;i++)printf(" %d",A[i]);
  printf("\n");

  return 0;
}



void buildMaxHeap(int *A){
  int i;
  for(i=H/2;i>=1;i--){
    maxHeapify(A,i);
  }
} 


void maxHeapify(int *A,int i){
  int l,r,largest,tmp;
  l=2*i;
  r=2*i+1;
  if(l<=H && A[l]>A[i])
    largest = l;
  else
    largest = i;
  if(r<=H && A[r]>A[largest])
    largest = r;


  if(largest != i){
    tmp=A[i];
    A[i]=A[largest];
    A[largest]=tmp;
    maxHeapify(A,largest);
  }
}  

Measured memory_bytes: 2552
#include <cstdio>
#include <cmath>
#include <cctype>
#include <cstdlib>
#include <cstring>
#include <cassert>
#include <climits>
#include <sstream>
#include <fstream>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <algorithm>
#include <set>
#include <map>
#include <list>
#include <deque>
#include <vector>
#include <string>
#include <bitset>
#define y0 y3487465
#define y1 y8687969
#define j0 j1347829
#define j1 j234892
#define next asdnext
#define prev asdprev
#define INF 1000000007
#define PI acos(-1.0)
#define endl "\n"
#define REP(i,n) for(int i=0;i<(int)(n);++i)
#define REP_R(i,n) for(int i=((int)(n)-1);i>=0;--i)
#define FOR(i,m,n) for(int i=((int)(m));i<(int)(n);++i)
#define FOR_R(i,m,n) for(int i=((int)(m)-1);i>=(int)(n);--i)
#define ALL(v) (v).begin(),(v).end()
#define RALL(v) (v).rbegin(),(v).rend()
#define SIZ(x) ((int)(x).size())
typedef long long int lli;
using namespace std;

int main()
{
  int A,B;
  cin >> A >> B;

  int C = 0;

  REP(i,2)
    {
      if( A > B )
	{
	  C += A;
	  -- A;
	  
	}
      else
	{
	  C += B;
	  -- B;
	  
	}
      
    }

  cout << C << endl;
  
  

}


Measured memory_bytes: 256
import sys
import copy
n = int(input())
p = list(map(int, input().split()))

def checkSort(inp, n):
    for x in range(1, n):
        if inp[x] < inp[x-1]:
            return False
    return True

count = 0
if checkSort(p, n) == True:
    print("YES")
    sys.exit()

for i in range(n-1):
    for j in range(i+1, n):
        q = copy.copy(p)
        q[i] = p[j]
        q[j] = p[i]
        if checkSort(q, n) == True:
            print("YES")
            sys.exit()

print("NO")

Measured memory_bytes: 40304
import collections


def solve():
    N, X, Y = map(int, input().split())

    inf = 10**9

    # 頂点=v 距離=d
    def pus(v, d, dist, q):
        if dist[v] == inf:
            dist[v] = d
            q.append(v)
        return 0

    ans = [0]*N

    for i in range(N):
        q = collections.deque()
        dist = [inf]*N
        pus(i, 0, dist, q)

        while(len(q)):
            v = q.popleft()
            d = dist[v]

            if v-1 >= 0:
                pus(v-1, d+1, dist, q)
            if v+1 < N:
                pus(v+1, d+1, dist, q)
            if v == X-1:
                pus(Y-1, d+1, dist, q)
            if v == Y-1:
                pus(X-1, d+1, dist, q)

        for i in range(N):
            ans[dist[i]] += 1

    [print(ans[i]//2) for i in range(1, N)]


if __name__ == "__main__":
    solve()


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

using namespace std; 

typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef vector<PII> VPII;
typedef long long LL;
typedef priority_queue<int> PQ_DESC;
typedef priority_queue<int, vector<int>, greater<int>> PQ_ASC;
typedef priority_queue<PII> PQ_DESC_PII;
typedef priority_queue<PII, vector<PII>, greater<PII>> PQ_ASC_PII;

#define ALL(c) (c).begin(),(c).end()
#define PB push_back
#define MP make_pair
#define SORT_ASC(c) sort(ALL(c))
#define SORT_DESC(c) sort(ALL(c), greater<typeof(*((c).begin()))>())
#define SIZE(a) int((a).size())

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

const double EPS = 1e-10;
const double PI  = acos(-1.0);
const int LARGE_INT = 1e9+100;
const int INF = 2e9+100;
const LL INF_LL = (LL)INF * 300 * 300;
const int MOD = 1e9+7;

//debug
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;

LL modpow(LL a, LL n) {
    LL res = 1;
    while (n > 0) {
        if (n & 1) res = res * a % MOD;
        a = a * a % MOD;
        n >>= 1;
    }
    return res;
}

LL modinv(LL a) {
    LL b = MOD, u = 1, v = 0;
    while (b) {
        LL t = a / b;
        a -= t * b; swap(a, b);
        u -= t * v; swap(u, v);
    }
    u %= MOD;
    if (u < 0) u += MOD;
    return u;
}

LL moddev(LL a, LL b){
	return a * modinv(b) % MOD;
}

void Main()
{
    int h,w,n;
    cin >> h >> w >> n;

    int big = max(h,w);
    
    if(n%big == 0){
        cout << n/big << endl;
    }
    else{
        cout << n/big+1 << endl;
    }

	return;
}

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

Measured memory_bytes: 256
#include <algorithm>
#include <iostream>
#include <iomanip>
#include <cstring>
#include <string>
#include <vector>
#include <queue>
#include <cmath>
#include <stack>
#include <set>
#include <map>
typedef long long ll;
using namespace std;

int main(){
  string s;
  cin >> s;
  int N = s.size();

  int cnt = 0;
  for(int i=0;i<N;i++){
    if(s[i] == 'o') cnt++;
  }

  if(cnt + 15 - N >= 8) cout << "YES" << endl;
  else cout << "NO" << endl;
  return 0;
}


Measured memory_bytes: 768
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define double long double
#define fo(a,b) for(int a=0;a<b;a++)
#define Sort(a) sort(a.begin(),a.end())
#define rev(a) reverse(a.begin(),a.end())
#define fi first
#define se second
#define bgn begin()
#define sz size()
#define en end()
#define pb push_back
#define pp() pop_back()
#define V vector
#define P pair
#define yuko(a) setprecision(a)
#define uni(a) a.erase(unique(a.begin(),a.end()),a.end())
#define Q queue
#define pri priority_queue
#define Pri priority_queue<int,vector<int>,greater<int>> //小さい順に取り出す
#define PriP priority_queue<P<int,int>,vector<P<int,int>>,greater<P<int,int>>>
#define all(a)  (a).begin(),(a).end()
#define ff first.first
#define fs first.second
#define sf second.first
#define ss second.second
priority_queue<int> q;
void dfs(int n, int a){
  if(pow(n , a) > 1000)
    return;
  if(a > 12)
    return;
  q.push(pow(n , a));
  dfs(n , a + 1);
}
signed main(){
  int x;
  cin >> x;
  q.push(1);
  for(int i = 2; i < 32; i++){
    dfs(i , 2);
  }
  while(!q.empty()){
    if(q.top() <= x){
      cout << q.top() << endl;
      return 0;
    }
    q.pop();
  }
}

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

int main() {
  int N, sum=0;
  cin >> N;
  
  if(N % 10 ==2) sum++;  
  if(N /10 %10 ==2) sum++;
  if(N /100 %10 ==2) sum++;
  if(N /1000 %10 ==2) sum++;
  
  cout << sum << endl;
}


Measured memory_bytes: 3648
#include <bits/stdc++.h>
#define LOCAL
using namespace std;
template <typename A, typename B>
ostream& operator <<(ostream& out, const pair<A, B>& a) {
out << "(" << a.first << "," << a.second << ")";
return out;
}
template <typename T, size_t N>
ostream& operator <<(ostream& out, const array<T, N>& a) {
out << "["; bool first = true;
for (auto& v : a) { out << (first ? "" : ", "); out << v; first = 0;} out << "]";
return out;
}
template <typename T>
ostream& operator <<(ostream& out, const vector<T>& a) {
out << "["; bool first = true;
for (auto& v : a) { out << (first ? "" : ", "); out << v; first = 0;} out << "]";
return out;
}
template <typename T, class Cmp>
ostream& operator <<(ostream& out, const set<T, Cmp>& a) {
out << "{"; bool first = true;
for (auto& v : a) { out << (first ? "" : ", "); out << v; first = 0;} out << "}";
return out;
}
template <typename U, typename T, class Cmp>
ostream& operator <<(ostream& out, const map<U, T, Cmp>& a) {
out << "{"; bool first = true;
for (auto& p : a) { out << (first ? "" : ", "); out << p.first << ":" << p.second; first = 0;} out << "}";
return out;
}
#ifdef LOCAL
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
#else
#define trace(...) 42
#endif
template <typename Arg1>
void __f(const char* name, Arg1&& arg1){
cerr << name << ": " << arg1 << endl;
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args){
const char* comma = strchr(names + 1, ',');
cerr.write(names, comma - names) << ": " << arg1 << " |";
__f(comma + 1, args...);
}
#define rep(i,n) for(int i=0; i<(n); i++)
using ll = long long;
#define int long long
using P = pair<int,int>;
//#########################################
signed main(){
	string res[2];
	string s;cin >> s;
	int q;cin >> q;
	int f = 0;
	while(q--){
		int t;cin >> t;
		if(t == 1){
			f = f^1;
		}
		else if(t == 2){
			int a;
			char c;
			cin >> a >> c;
			a--;
			res[a^f] += c;
		}
	}
	reverse(res[0].begin(),res[0].end());
	string ret = res[0] +s +  res[1];
	if(f)reverse(ret.begin(),ret.end());
	cout << ret << endl;
	return 0;
}

Measured memory_bytes: 4216
#include <algorithm>
#include <bitset>
#include <tuple>
#include <cstdint>
#include <cstdio>
#include <cctype>
#include <assert.h>
#include <stdlib.h>
#include <stdio.h>
#include <cassert>
#include <cfloat>
#include <climits>
#include <cmath>
#include <complex>
#include <ctime>
#include <deque>
#include <fstream>
#include <functional>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <list>
#include <limits>
#include <map>
#include <memory>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>
using namespace std;
using ll = long long; 
using ld = long double;
#define endl "\n"
//#define int long long
#define all(V) V.begin(),V.end()
#define rep(i, n) for (int i = 0; i < n; i++)
#define REP(i,n) for(int i=1;i<=(n);i++)
const int MOD = 1e9 + 7;
const ll INF = 1LL << 60;
const int inf = 1 << 25;
constexpr long double pi = 3.141592653589793238462643383279;
int dx[] = { 1,0,-1,0 };
int dy[] = { 0,1,0,-1 };
template<class T> inline bool chmin(T& a, T b) {
    if (a > b) {
        a = b;
        return true;
    }
    return false;
}
template<class T> inline bool chmax(T& a, T b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}
ll fact_mod(ll n, ll mod) {
    ll f = 1; for (int i = 2; i <= n; i++) f = f * (i % mod) % mod;
    return f;
}
ll gcd(ll a, ll b) {
    if (b == 0) return a;
    return gcd(b, a % b);
}
ll lcm(ll a, ll b) {
    return a * b / gcd(a, b);
}
ll keta(ll n) {
    if (n == 0) return 1;
    ll count = 0;
    while (n != 0) {
        n /= 10;
        count++;
    }
    return count;
}
ll ketasum(ll n) {
    ll sum = 0;
    while (n != 0) {
        sum += n % 10;
        n /= 10;
    }
    return sum;
}
ll mch(ll n) {
    if (n == 1) return 1;
    else return n * mch(n - 1);
}
ll pow_mod(ll x, ll n, ll mod) {
    ll res = 1;
    while (n > 0) {
        if (n & 1) res = (res * x) % mod; //ビット演算(最下位ビットが1のとき)
        x = (x * x) % mod;
        n >>= 1; //右シフト(n = n >> 1)
    }
    return res;
}
ll inv_mod(ll a, ll mod) {
    ll b = mod, u = 1, v = 0;
    while (b) {
        ll t = a / b;
        a -= t * b; swap(a, b);
        u -= t * v; swap(u, v);
    }
    u %= mod;
    if (u < 0) u += mod;
    return u;
}
bool is_prime(const unsigned n) {
    switch (n) {
    case 0: // fall-through
    case 1: return false;
    case 2: // fall-through
    case 3: return true;
    } // n > 3 が保証された
    if (n % 2 == 0 || n % 3 == 0) return false;
    for (unsigned i = 5; i * i <= n; i += 6) {
        if (n % i == 0) return false; // (6の倍数)-1
        if (n % (i + 2) == 0) return false; // (6の倍数)+1
    }
    return true;
}
//関数とか

//宣言とか

/*signed*/int main(void) {
    ll a, b, c, d;
    cin >> a >> b >> c >> d;
    //int x, y    
    cout << max({ a * c,a * d,b * c,b * d }) << endl;
}

Measured memory_bytes: 3640
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n, m) for (int i = n; i <= m; ++i)
#define mem(a, b) memset(a, b, sizeof(a))
#define dbg(x) cout << #x << "=" << x << endl
const int maxm = 1e9 + 7;
const int maxn = 2e5 + 10;
#define gc getchar
#define ll long long
#define P pair<int, int>
template <class I>
inline void read(I &x)
{
    char c;
    I f;
    for (f = 1, c = gc(); c < '0' || c > '9'; c = gc())
        if (c == '-')
            f = -1;
    for (x = 0; c <= '9' && c >= '0'; c = gc())
        x = (x << 1) + (x << 3) + (c & 15);
    x *= f;
}
int main()
{
    int T;
    // read(T);
    T=1;
    while (T--)
    {
        int a[4];
        cin>>a[1]>>a[2]>>a[3];
        sort(a+1,a+4);
        if((a[1]==a[2]&&a[1]!=a[3])||(a[2]==a[3]&&a[2]!=a[1])||(a[3]==a[1]&&a[3]!=a[2]))
        puts("Yes");
        else puts("No");
    }
}

// abcda
// cbad

Measured memory_bytes: 256
#define A scanf("%d"
a[100],n,k,t,f;main(i){for(;A"%d",&n,&k)&&n&&k;puts(f?"No":"Yes")){for(i=0;i<k;A,a+i++));for(f=0;n--;)for(i=0;i<k;f|=(a[i++]-=t)<0)A,&t);}}

Measured memory_bytes: 380
#include <bits/stdc++.h>
 
#define INF 100100100
#define MOD 1000000007
 
using namespace std;
using ll = long long;
using ull = unsigned long long ;
 
int main(){
   int x, y, z;
   cin>>x>>y>>z;

   if(x<y){
       if(x<=z && z<=y){
                cout<<"Yes"<<endl;
                return 0;
        }
   } else if(x>y) {
       if(y<=z && z<=x){
            cout<<"Yes"<<endl;
            return 0;
       }
   }
cout<<"No"<<endl;

   return 0;
}

Measured memory_bytes: 256
import java.util.*;
import java.io.*;
 
public class Main{
    public static void main(String[] args){
        Main m = new Main();
        m.input();

    }
 
    
    public void input(){
        Scanner sc = new Scanner(System.in);
        String x = sc.next();
        int ans = 700;
        for(int i = 0; i < x.length(); i++){
            if(x.charAt(i) == 'o'){
                ans += 100;
            }
        }
        sc.close();
        System.out.println(ans);
    }

}

Measured memory_bytes: 21716
import sys
import math
import itertools
import bisect
from copy import copy
from collections import deque,Counter
from decimal import Decimal
def s(): return input()
def i(): return int(input())
def S(): return input().split()
def I(): return map(int,input().split())
def L(): return list(input().split())
def l(): return list(map(int,input().split()))
def lcm(a,b): return a*b//math.gcd(a,b)
sys.setrecursionlimit(10 ** 9)
mod = 10**9+7

S = s()
N = len(S)
num = 1
num2 = 1
ans = 0
Flag = 0
for i in range(N-1):
    if S[i] == S[i+1]:
        ans += num
        num += 1
    if S[i] == '>' and S[i+1] == '<':
        ans += max(num,num2)
        num = 1
        Flag = 0
    if S[i] == '<' and S[i+1] == '>':
        num2 = num
        num = 1
        Flag = 1
if Flag:
    ans += max(num2,num)
else:
    ans += num
print(ans)


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

#define INF 0x7fffffff

const int N=700010;

using namespace std;

 

inline int read(){

	char ch=getchar();int x=0,f=1;	while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}

	while(ch>='0'&&ch<='9'){x=x*10+ch-'0';ch=getchar();}

	return x*f;

} 

 

struct edge{

	int v,nxt,w;

}e[N*20];

int head[N<<4],cnt;

long long inf;

int n,m,s;

 

void add(int u,int v,int w){

	e[++cnt].v=v;

	e[cnt].w=w;

	e[cnt].nxt=head[u];

	head[u]=cnt;

}

 

int tin[N<<4],tout[N<<4],temp;

long long dis[N<<4];

 

void build(int k,int l,int r){

	if(l==r){

		tin[k]=tout[k]=l;

		return ;

	}

	int mid=(l+r)>>1;

	build(k<<1,l,mid);

	build(k<<1|1,mid+1,r);

	tin[k]=++temp;tout[k]=++temp;

	add(tout[k<<1],tout[k],0);

	add(tout[k<<1|1],tout[k],0);

	add(tin[k],tin[k<<1],0);

	add(tin[k],tin[k<<1|1],0);

}

 

void update1(int k,int l,int r,int L,int R,int u,int w){

	if(L<=l&&r<=R){

		add(u,tin[k],w);

		return ;

	}

	int mid=(l+r)>>1;

	if(mid>=L){

		update1(k<<1,l,mid,L,R,u,w);

	}

	if(mid<R){

		update1(k<<1|1,mid+1,r,L,R,u,w);

	}

}

 

void update2(int k,int l,int r,int L,int R,int u,int w){

		if(L<=l&&r<=R){

		add(tout[k],u,w);

		return ;

	}

	int mid=(l+r)>>1;

	if(mid>=L){

		update2(k<<1,l,mid,L,R,u,w);

	}

	if(mid<R){

		update2(k<<1|1,mid+1,r,L,R,u,w);

	}

}

 

struct node{

	int u;

	long long d;

	bool operator<(const node&h)const{return d>h.d;};

};

 

void dij(){

	memset(dis,0x3f,sizeof(dis));

	inf=dis[1];

	priority_queue<node> q;

	dis[s]=0;

	q.push((node){s,0});

	while(!q.empty()){

		node now=q.top();

		int u=now.u;

		long long d=now.d;

		q.pop();

		if(d!=dis[u])continue;

		for(int i=head[u];i;i=e[i].nxt){

			int v=e[i].v,w=e[i].w;

			if(dis[v]>dis[u]+w){

				dis[v]=dis[u]+w;

				q.push((node){v,dis[v]});

			}

		}

	}

}

 

int main(){

	

	n=read(),m=read(),s=1;

	temp=n+m; 

	

	build(1,1,n+m);

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

		int l=read(),r=read(),w=read();

		update1(1,1,n+m,l,r,n+i,0);

		update2(1,1,n+m,l,r,n+i,w);

	}

	dij(); 

	//cout<<inf<<endl;

	if(dis[n]!=inf){

		printf("%lld ",dis[n]);

	}

	else printf("-1 ");

	return 0;

}

Measured memory_bytes: 145780
#include <bits/stdc++.h>
using namespace std;
int main(){
	int N;
	cin >> N;
	vector<int> A;
	for(int i=0;i<N;i++){
		int x;
		cin >> x;
		A.push_back(x);
	}
	sort(A.begin(), A.end());
	int Amax = A[N-1];
	int chk[Amax + 1];
	for(int i=0;i<=Amax;i++){
		chk[i] = 0;
	}
	for(int i = 0;i<N;i++){
		if(chk[A[i]] == 0){
			for(int j=2;j * A[i]<=Amax;j++){
				chk[j * A[i]]++;
			}
		}
		if(i > 0 && A[i] == A[i - 1])chk[A[i]]++;
	}
	// for(int i=0;i<=Amax;i++){
	// 	cout << i << ":" << chk[i] << endl;
	// }
	int ans = 0;
	for(int i=0;i<N;i++){
		if(chk[A[i]] == 0)ans++;
	}
	cout << ans << endl;
}


Measured memory_bytes: 7892
#include<bits/stdc++.h>
using namespace std;
int main(int argc, char const *argv[])
{
	int a[3][3], b[3][3] = {0};
	for (int i = 0; i < 3; ++i)
	{
		for (int j = 0; j < 3; ++j)
			cin >> a[i][j];
	}
	int n;
	cin >> n;
	while (n --)
	{
		int num;
		cin >> num;
		for (int i = 0; i < 3; ++i)
		{
			for (int j = 0; j < 3; ++j)
			{
				if (num == a[i][j])
					b[i][j] = 1;
			}
		}
	}
	int ans = 0;
	for (int i = 0; i < 3; ++i)
	{
		if (b[i][0] && b[i][1] && b[i][2])
			ans = 1;
		if (b[0][i] && b[1][i] && b[2][i])
			ans = 1;
	}
	if (b[0][0] && b[1][1] &&  b[2][2])
		ans = 1;
	if (b[0][2] && b[1][1] && b[2][0])
		ans = 1;
	if (ans)
		cout << "Yes" << '\n';
	else
		cout << "No" << '\n';
 
	return 0;
}


Measured memory_bytes: 3620
fn main() {
    let (n, max_w) = read_tuple();
    let items = read_vec2::<u64>(n as u32);
    println!("{}", solve(n, max_w, items));
}

fn solve(n: usize, max_w: usize, items: Vec<Vec<u64>>) -> u64 {
    let max_v = 1000 * n;
    let mut dp: Vec<Vec<u64>> = Vec::new();
    for _ in 0..n+1 {
        let v = vec![u64::max_value(); max_v + 1];
        dp.push(v);
    }

    dp[0][0] = 0;
    for i in 1..n+1 {
        for v in 0..max_v+1 {
            let cur_w = items[i-1][0];
            let cur_v = items[i-1][1];

            if v >= (cur_v as usize) && dp[i-1][v-(cur_v as usize)] != u64::max_value() {
                let w = dp[i-1][v-(cur_v as usize)] + cur_w;
                chmin(&mut dp[i][v], w)
            }
            let w = dp[i-1][v];
            chmin(&mut dp[i][v], w);
        }
    }

    let mut max = 0;
    for v in 0..max_v+1 {
        if dp[n][v] as usize <= max_w {
            max = v;
        }
    }
    max as u64
}

#[test]
fn test1() {
    let n = 3;
    let max_w = 8;
    let items = vec![vec![3, 30], vec![4, 50], vec![5, 60]];
    assert_eq!(90, solve(n, max_w, items));
}

#[test]
fn test2() {
    let n = 1;
    let max_w = 1000000000;
    let items = vec![vec![1000000000, 10]];
    assert_eq!(10, solve(n, max_w, items));
}

#[test]
fn test3() {
    let n = 6;
    let max_w = 15;
    let items = vec![vec![6, 5], vec![5, 6], vec![6, 4], vec![6, 6], vec![3, 5], vec![7, 2]];
    assert_eq!(17, solve(n, max_w, items));
}

fn chmin(a: &mut u64, b: u64) {
    if *a > b {
        *a = b;
    }
}

fn read_tuple() -> (usize, usize) {
    let v = read_vec::<usize>();
    (v[0], v[1])
}

fn read_vec<T: std::str::FromStr>() -> Vec<T> {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).ok();
    s.trim().split_whitespace().map(|e| e.parse().ok().unwrap()).collect()
}

fn read_vec2<T: std::str::FromStr>(n: u32) -> Vec<Vec<T>> {
    let mut v2 = Vec::new();
    for _ in 0..n {
        let mut s = String::new();
        std::io::stdin().read_line(&mut s).ok();
        let v = s.trim().split_whitespace().map(|e| e.parse().ok().unwrap()).collect();
        v2.push(v);
    }
    v2
}



Measured memory_bytes: 106748
from subprocess import*
with open('e.cpp','w')as f:f.write(r"""
#include<iostream>
using namespace std;
main(){
  int n;
  string s;
  cin>>n>>s;
  int a=0;
  for(int i=0;i<n;++i){
    int t=0;
    for(int j=0;j<n-i;++j){
      t=(t+1)*(s[j]==s[j+i]);
      a=max(a,min(t,i));
    }
  }
  cout<<a;
}""")
call(('g++','e.cpp'))
call('./a.out')

Measured memory_bytes: 36924
#pragma GCC optimize("Ofast")
#pragma GCC target("avx2,tune=native")
#pragma GCC optimize("unroll-loops")
//#pragma GCC optimize("trapv")
#include <bits/stdc++.h>
//#include <ext/pb_ds/assoc_container.hpp>
//using namespace __gnu_pbds;
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
#define pb push_back
using namespace std;
using ll = long long;
using vi = vector<ll>;
using vvi = vector<vi>;
using pi = pair<ll, ll>;
const int mod = 1000000007;
const ll inf = 1e18;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
int main() { //DINIC ORZ
	ios::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
	map<char, int> x;
	string s;
	cin >> s;
	for(auto i : s) x[i]++;
	ll ans = 0;
	for(auto i : x) {
		ans += i.second*(s.size()-i.second);
	}
	ans/=2, ++ans;
	cout << ans << "\n";
}



Measured memory_bytes: 720
N, M = [int(x) for x in input().split()]

s = set()
A = [int(x) for x in input().split()]
s = set(A[1::])
for _ in range(N - 1):
    A = [int(x) for x in input().split()]
    s &= set(A[1::])

# print(s)
print(len(s))

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

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

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

#define pb(a) push_back(a)
#define all(x) (x).begin(),(x).end()

const int INF = (int)1e9;
const LL INFL = (LL)1e18;
const int MOD = (int)1e9 + 7;

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

    int n, t, a;
    cin >> n >> t >> a;
    vector<int> h(n);
    REP(i, n) cin >> h[i];

    a *= 1000; t *= 1000;
    int ans = INFL, ans_i = 1;
    REP(i, n){
        if(ans > abs(a - (t - h[i] * 6))){
            ans = abs(a - (t - h[i] * 6));
            ans_i = i+1;
        }
    }
    cout << ans_i << endl;
}

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

map<string, long long> dp[101];
string atgc = "ATGC";
const int MOD = 1000000007;
int N;

bool ok(const string& s) {
  // AGC?, GAC?, ACG?, A?GC, AG?C
  string t = s.substr(0, 3);
  if (t == "AGC" || t == "GAC" || t == "ACG")
    return false;
  if ((s[0] == 'A' && s[2] == 'G' && s[3] == 'C') ||
      (s[0] == 'A' && s[1] == 'G' && s[3] == 'C'))
    return false;
  return true;
}

long long dfs(int i, const string& p, const string& pp, const string& ppp) {
  if (i == N) return 1;
  string prev = p + pp + ppp;
  
  if (dp[i][prev] != 0) return dp[i][prev];
  long long ret = 0;
  for (auto b : atgc) {
    string s = b + prev;
    if (ok(s))
      ret += dfs(i + 1, string(1, b), p, pp) % MOD;
  }
  return dp[i][prev] = ret % MOD;
}

int main(void) {
  cin >> N;
  long long ret = 0;
  cout << dfs(0, "$", "$", "$") << endl;

  return 0;
}

Measured memory_bytes: 896
from collections import deque
h,w = map(int, input().split())
data = []
ans = h*w
for i in range(h):
    s = input()
    for x in s:
        if x == "#":
            ans -= 1
    data.append(s)
dist = [[-1]*w for _ in range(h)]
dist[0][0] = 0
queue = deque()
queue.append((0,0))
while queue:
    x,y = queue.popleft()
    for dx,dy in [[-1,0],[1,0],[0,1],[0,-1]]:
        tox = x+dx
        toy = y+dy
        if 0<=tox<h and 0<=toy<w and dist[tox][toy] == -1 and data[tox][toy] == ".":
            dist[tox][toy] = dist[x][y] + 1
            queue.append((tox,toy))

if dist[-1][-1] == -1:
    print(-1)
else:
    print(ans-dist[-1][-1]-1)

Measured memory_bytes: 41072
// ABC 081

// inputに入力データ全体が入る
function Main(input) {
  input = input.split("");
  var result = parseInt(input[0],10) + parseInt(input[1],10) + parseInt(input[2],10);
  console.log(result)
}


Main(require("fs").readFileSync("/dev/stdin", "utf8"));


Measured memory_bytes: 7372
// Reverse Polish Notation
// http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=ALDS1_3_A&lang=jp
// 所要時間　２０分　{中央}×{中央}
// Stack

#include <iostream>
#include <string>
#include <stack>
#include <cstdlib>

using namespace std;

int main() {
  string word;
  stack<int> S;
  while (cin >> word) {
    if (word == "*") {
      int n = S.top();
      S.pop(); 
      n *= S.top();
      S.pop();
      S.push(n);
    }
    else if (word == "+") {
      int n = S.top();
      S.pop(); 
      n += S.top();
      S.pop();
      S.push(n);
    }
    else if (word == "-") {
      int n = S.top();
      S.pop();
      n = S.top() - n;
      S.pop();
      S.push(n);
    }
    else {
      int num = atoi(word.c_str());
      S.push(num);
    }
  }
  cout << S.top() << endl;
}



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

using namespace std;
using ll = long long;

namespace mod {

template <class T, int M>
class MInt;

template <class T, int M>
MInt<T, M> Pow(const MInt<T, M> &base, T exp);

template <class T, int M>
MInt<T, M> Inv(const MInt<T, M> &n);

template <class T, int M>
class MInt {
  T n_;

 public:
  MInt() : n_(0) {}
  MInt(T n) : n_((n % M + M) % M) {}

  MInt &operator+=(const MInt &rhs) {
    n_ += rhs.n_;
    if (n_ >= M) {
      n_ -= M;
    }

    return *this;
  }

  MInt &operator-=(const MInt &rhs) {
    n_ += M - rhs.n_;
    if (n_ >= M) {
      n_ -= M;
    }

    return *this;
  }

  MInt &operator*=(const MInt &rhs) {
    n_ = n_ * rhs.n_ % M;
    return *this;
  }

  MInt &operator/=(const MInt &rhs) { return (*this) *= Inv(rhs); }

  T Get() { return n_; }
};

template <class T, int M>
MInt<T, M> operator-(const MInt<T, M> &lhs, const MInt<T, M> &rhs) {
  MInt<T, M> res(lhs);
  return res -= rhs;
}

template <class T, int M>
MInt<T, M> operator+(const MInt<T, M> &lhs, const MInt<T, M> &rhs) {
  MInt<T, M> res(lhs);
  return res += rhs;
}

template <class T, int M>
MInt<T, M> operator*(const MInt<T, M> &lhs, const MInt<T, M> &rhs) {
  MInt<T, M> res(lhs);
  return res *= rhs;
}

template <class T, int M>
MInt<T, M> operator/(const MInt<T, M> &lhs, const MInt<T, M> &rhs) {
  MInt<T, M> res(lhs);
  return res /= rhs;
}

template <class T, int M>
MInt<T, M> Pow(const MInt<T, M> &base, T exp) {
  if (exp == 0) {
    return 1;
  }

  auto a = Pow(base, exp / 2);
  a *= a;
  if (exp % 2 == 1) {
    a *= base;
  }

  return a;
}

template <class T, int M>
MInt<T, M> Inv(const MInt<T, M> &n) {
  return Pow(n, static_cast<T>(M - 2));
}
}  // namespace mod

const int md = 1e9 + 7;
using MInt = mod::MInt<long long, md>;
class BinCoef {
  vector<MInt> f;

 public:
  BinCoef(int n) : f(n + 1) {
    f[0] = f[1] = 1;
    for (int i = 2; i <= n; i++) {
      f[i] = MInt(i) * f[i - 1];
    }
  }

  MInt NCM(int n, int m) {
    if (n < m) {
      return 0;
    }
    return f[n] * mod::Inv(f[m] * f[n - m]);
  }

  MInt HCM(int n, int m) { return NCM(n + m - 1, m); }
};

int main(int argc, const char *argv[]) {
  ll k, n;
  string s;
  cin >> k >> s;
  n = s.size();

  BinCoef bc(n + k);
  MInt ans = 0;
  for (ll i = 0; i <= k; ++i) {
    auto now = mod::Pow(MInt(26), k - i);
    now *= mod::Pow(MInt(25), i);
    now *= bc.HCM(i + 1, n - 1);
    ans += now;
  }

  cout << ans.Get() << '\n';
  return 0;
}


Measured memory_bytes: 20052
n, k = map(int, input().split())
X = []
Y = []
for x in map(int, input().split()):
    if x < 0:
        X.append(x)
    else:
        Y.append(x)
X.reverse()
INF = 10**9
ans = INF
if len(X) == 0:
    ans = Y[k-1]
elif len(Y) == 0:
    ans = X[k-1]*(-1)
else:
    for i in range(k):
        L = k-i-1
        R = i-1
        if L >= len(X) or R >= len(Y):
            continue
        a = X[L]*(-1)
        b = Y[R]
        ans = min(ans, min(a, b)+a+b)
print(ans)


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

using namespace std;

const int maxn = 200005;

struct node
{
	int tag,mi;
}T[maxn * 4];

vector<int> lk[maxn];
int b[maxn],n,q;

void mark(int jd,int tag)
{
	T[jd].tag += tag,T[jd].mi += tag;
}

void down(int jd)
{
	if (!T[jd].tag) return;
	mark(jd << 1,T[jd].tag),mark(jd << 1 | 1,T[jd].tag),T[jd].tag = 0;
}

int query(int l,int r,int i,int j,int jd)
{
	if (j < l || i > r) return (1 << 30);
	if (i <= l && r <= j) return T[jd].mi;
	int mid = l + r >> 1;
	down(jd);
	return min(query(l,mid,i,j,jd << 1),query(mid + 1,r,i,j,jd << 1 | 1));
}

void update(int l,int r,int p,int v,int jd)
{
	if (l == r) T[jd].mi = min(T[jd].mi,v); else
	{
		int mid = l + r >> 1;
		down(jd);
		if (p <= mid) update(l,mid,p,v,jd << 1); else update(mid + 1,r,p,v,jd << 1 | 1);
		T[jd].mi = min(T[jd << 1].mi,T[jd << 1 | 1].mi);
	}
}

void add(int l,int r,int i,int j,int ad,int jd)
{
	if (j < l || i > r) return;
	if (i <= l && r <= j) mark(jd,ad); else
	{
		int mid = l + r >> 1;
		down(jd);
		add(l,mid,i,j,ad,jd << 1),add(mid + 1,r,i,j,ad,jd << 1 | 1);
		T[jd].mi = min(T[jd << 1].mi,T[jd << 1 | 1].mi);
	}
}

void build(int l,int r,int jd)
{
	if (l == r)
	{
		if (!l) T[jd].mi = 0; else T[jd].mi = (1 << 30);
		return;
	}
	int mid = l + r >> 1;
	build(l,mid,jd << 1),build(mid + 1,r,jd << 1 | 1);
	T[jd].mi = min(T[jd << 1].mi,T[jd << 1 | 1].mi);
}

int main()
{
	scanf("%d", &n);
	int sum = 0;
	for(int i = 1;i <= n;i ++)
		scanf("%d", &b[i]),sum += (!b[i]);
	int q;
	scanf("%d", &q);
	for(int l,r;q;q --)
	{
		scanf("%d%d", &l, &r);
		lk[l].push_back(r);
	}
	build(0,n,1);
	for(int i = 1;i <= n;i ++)
	{
		for(int j = 0;j < lk[i].size();j ++)
		{
			int r = lk[i][j];
			update(0,n,r,query(0,n,0,r - 1,1),1);
		}
		add(0,n,0,i - 1,b[i] ? 1 : -1,1);
	}
	printf("%d\n", T[1].mi + sum);
	return 0;
}


Measured memory_bytes: 14464
import sys
input=sys.stdin.readline
sys.setrecursionlimit(10**9)
n=int(input())
Cost=[]
s1,s2=0,0
for i in range(n):
    a,b=map(int,input().split())
    s1+=a
    s2+=b
    Cost.append([a,i])
    Cost.append([b,i])
Cost.sort()
s3=sum([Cost[i][0] for i in range(n)])
if len(set([Cost[i][1] for i in range(n)]))==n:
    if Cost[n-1][1]==Cost[n][1]:
        s3+=min(Cost[n+1][0]-Cost[n-1][0],Cost[n][0]-Cost[n-2][0])
    else:
        s3+=Cost[n][0]-Cost[n-1][0]
print(min(s1,s2,s3))

Measured memory_bytes: 40660
num = gets.to_i
ary = gets.split.map(&:to_i)
  
count = 0
  
for i in 0 .. num-2
  
  min = ary[i]
  min_index = i
  
  for j in i .. num-1
  
    if min > ary[j]
      min = ary[j]
      min_index = j
    end
  end
  
  if ary[i] != ary[min_index]
    ary[i], ary[min_index] = ary[min_index], ary[i]
    count += 1
  end
end

puts ary.join(" "), count


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

using namespace std;
using llong = long long;
using P = pair<llong, llong>;

#define BE(x) x.begin(), x.end()

const llong inf = llong(1e18)+7;
const llong mod = 1e9+7;

string s;

llong solve(vector<int> v){
	if(v.size() == (int)s.size()-1){
		llong sum = 0;
		llong res = s[0] - '0';
		for(int i = 0; i < v.size(); i++){
			if(v[i] == 0)
				(res *= 10) += s[i+1] - '0';
			else{
				// cerr << res << " ";
				sum += res, res = s[i+1] - '0';
			}
		}
		// cerr << res << endl;
		sum += res;

		return sum;
	}

	llong ret = 0;
	v.push_back(0);
	ret += solve(v);
	v.pop_back();
	v.push_back(1);
	ret += solve(v);

	return ret;
}

int main(){
	cin >> s;
	cout << solve(vector<int>()) << endl;
	return 0;
}

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

int com_int(const void *a, const void *b){
    return *(int*)a - *(int*)b;
}


int main(){
    int N,K,tmp;
    cin >> N >> K;
    int buf[200000];
    for(int i = 0; i < N;i++){
        cin >> buf[i];
    }
    qsort(buf,N,sizeof(int),com_int);
    unsigned long long ans = 0;
    for(int i = 0;i < N-K;i++){
        ans += buf[i];
    }
    cout << ans << endl;
}

Measured memory_bytes: 1788
#include <iostream>

using namespace std;

int main(){
  long long A, V, B, W, T;
  cin >> A >> V >> B >> W >> T;
  if (A < B && (A + V*T >= B + W*T)) {
    cout << "YES\n";
  }
  else if (A > B && (A - V*T <= B - W*T)){
    cout << "YES\n";
  }
  else {
    cout << "NO\n";
  }
  return 0;
}

Measured memory_bytes: 3632
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define INF (INT_MAX / 4)
#define REP(i, n) for (ll i = 0, i##_len = (n); i < i##_len; ++i)
#define ALL(a) (a).begin(), (a).end()
/* clang-format off */
#define TIMER_S(start) chrono::system_clock::time_point start = chrono::system_clock::now();
#define TIMER_E(end) chrono::system_clock::time_point end = chrono::system_clock::now();
#define TIME(start, end) cout << static_cast<double>(chrono::duration_cast<chrono::microseconds>(end - start).count()) << "ms" << "\n";
/* clang-format on */

int main() {
  int n,ans=0;
  cin >> n;
  unordered_map<string, int> m;
  REP(i, n) { string s;
    cin >> s;
    if (m.count(s))
      m.at(s)++;
    else
      m[s] = 1;
    }

    cout << m.size()<< "\n";
  return 0;
}


Measured memory_bytes: 17616
from itertools import permutations
 
N,M = map(int,input().split())
ans=0
s = []
 
for i in range(M):
    a,b = map(int,input().split())
    s.append([a,b])

#print(s) #[[1, 2], [1, 3], [2, 3]]

t=list(permutations(list(range(1,N+1))))

##print(t) [(1, 2, 3), (1, 3, 2), (2, 1, 3), (2, 3, 1), (3, 1, 2), (3, 2, 1)]

for i in range(len(t)):
    flag=True
    if t[i][0]!=1: continue #1スタートのみ。continue文はfor文やwhile文などループ内の処理をスキップ
    for j in range(N-1):
        a=sorted([t[i][j],t[i][j+1]]) #(1,2,3)なら[(1,2)]や[(2,3)]
        #print(i)# 0 0 1 1
        #print(j)# 0 1 0 1
        #print(a)# [1, 2] [2, 3] [1,3] [2,3]
        if a not in s: flag=False
    if flag == True:
        ans = ans + 1

print(ans)

Measured memory_bytes: 8052
n,k=map(int,input().split())
mod=10**9+7
fac=[1]*n
for i in range(n-1):
  fac[i+1]=((i+2)*fac[i])
def comb(a,b):
  if a==0:
    return 1
  if b==0 or b==a:
    return 1
  return (fac[a-1]//(fac[a-b-1]*fac[b-1]))%mod
for i in range(k):
  print((comb(n-k+1,i+1)*comb(k-1,i))%mod)


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

using namespace std;

long long MOD = 1000000007;

int main(){
    int N;
    cin >> N;
    vector<int> A(N,0);
    int max1, max2;
    max1=0;
    max2=0;
    for(int i=0; i<N; i++){
        cin >> A[i];
        if(A[i]>max1){
            int tmp=max1;
            max1=A[i];
            if(tmp>max2){
                max2=tmp;
            }
        }else if(A[i] > max2){
            max2=A[i];
        }
    }

    for(int i=0; i<N; i++){
        if(A[i]==max1){
            cout << max2 << endl;
        }else{
            cout << max1 << endl;
        }
    }
}

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

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

  int input;
  vector<unsigned int> f(n, 0);
  for(int i = 0; i < n; i++){
    for(int j = 0; j < 10; j++){
      cin >> input;
      if(input == 1){ f[i] |= (1 << j); }
    }
  }

  vector<vector<int> > p(n, vector<int>(11));
  for(int i = 0; i < n; i++){
    for(int j = 0; j <= 10; j++){
      cin >> p[i][j];
    }
  }

  int ans = -1e9;
  for(unsigned int i = 1; i < (1 << 10); i++){
    int profits = 0;
    for(int j = 0; j < n; j++){
      unsigned int open = i & f[j];
      profits += p[j][__builtin_popcount(open)];
    }

    if(ans < profits){
      ans = profits;
    }
  }

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


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <iomanip>

using namespace std;

int main()
{
    uint32_t N,K;
    cin >> N >> K;

    vector<int> P(N);
    for (uint32_t i = 0; i < N; i++) { cin >> P[i]; }

    vector<uint64_t> sum(N + 1);
    for (uint32_t i = 0; i < N; i++) { sum[i + 1] = sum[i] + P[i]; }

    uint64_t ans = 0;
    for (uint32_t i = 0; i <= N - K; i++) { ans = max(ans, sum[i + K] - sum[i]); }

    cout << setprecision(10) << (double)(ans+K)/2 << endl;
}


Measured memory_bytes: 2560
#include <bits/stdc++.h>
using namespace std;
const int N = 22;
int dp[N][1<<22];
int n , a[N][N];
int mod = 1000000007;

vector<int> msk[22];

int32_t main(){
	scanf("%d" , &n);
	for(int i = 0 ; i < n ; i ++){
		for(int j = 0 ; j < n ; j++){
			scanf("%d" , &a[i][j]);
		}
	}
	for(int j = 1 ; j < (1<<n) ; j++){
		msk[__builtin_popcount(j)].push_back(j);
	}
	int mask = 0;
	for(int i = 0 ; i < n; i ++){
		mask |= (1<<i);
		for(auto j : msk[i+1]){
			for(int k = 0 ; k < n ; k ++){
				if((j & 1<<k )&& a[i][k]){
					if(i > 0){
					dp[i][j] += dp[i-1][j ^ (1<<k)];
					}
					else{
						dp[i][j]++;
					}
					dp[i][j] %= mod;
				}
			}
		}
	}
	printf("%d\n" , dp[n-1][mask]);
}

Measured memory_bytes: 187836
import java.io.BufferedReader;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.IOException;
import java.lang.management.ManagementFactory;
import java.lang.management.ThreadMXBean;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;
import java.util.List;
import java.util.PriorityQueue;
import java.util.Scanner;

public class Main {

	public static void main(String[] args) throws IOException {

		Scanner scan = new Scanner(System.in);
		// Scanner scan = new Scanner(new
		// File("D:\\UserArea\\J0124567\\Downloads\\ALDS1_3_C-in10.txt"));
		// while (scan.hasNext()) {

		String s = scan.next();

		boolean start = false;
		int pt = 0;
		int depth = 0;
		int[] xl = new int[10001];
		int[] yl = new int[10001];
		int mid = 0;
		int l = 0;
		int totl = 0;
		int totk = 0;
		for (int x = 0; x < s.length(); x++) {
			if (start) {
				if (s.charAt(x) == '\\') {
					l += (1 + depth);
					depth += 2;
				} else if (s.charAt(x) == '_') {
					l += depth;
				} else if (s.charAt(x) == '/') {
					depth -= 2;
					l += (1 + depth);
					if (depth == 0) {
						start = false;
						xl[pt] = l;
						totl += l;
						totk++;
						mid = x;
						pt++;
					}
				}
			} else if (s.charAt(x) == '\\') {
				start = true;
				l = 1;
				depth = 2;
			}
		}

		pt = 0;
		start = false;
		for (int x = s.length() - 1; x >= mid; x--) {
			if (start) {
				if (s.charAt(x) == '/') {
					l += (1 + depth);
					depth += 2;
				} else if (s.charAt(x) == '_') {
					l += depth;
				} else if (s.charAt(x) == '\\') {
					depth -= 2;
					l += (1 + depth);
					if (depth == 0) {
						start = false;
						yl[pt] = l;
						totl += l;
						totk++;
						pt++;
					}
				}
			} else if (s.charAt(x) == '/') {
				start = true;
				l = 1;
				depth = 2;
			}
		}

		System.out.println(totl / 2);
		System.out.print(totk);
		for (int i = 0; xl[i] > 0; i++)
			System.out.print(" " + xl[i] / 2);
		int j;
		for (j = 0; yl[j] > 0; j++)
			;
		for (int i = j - 1; i >= 0; i--)
			System.out.print(" " + yl[i] / 2);
		System.out.println();
		
		scan.close();
		System.exit(0);
	}
}

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

// practice

int dp[100010];
const ll INF = 1e9 + 7;

int main(){
    int n;
    cin >> n;
    rep(i, 100005){
        dp[i + 1] = INF;
        int power = 1;
        while (power <= i + 1){
            dp[i + 1] = min(dp[i + 1], dp[i + 1 - power] + 1);
            power *= 6;
        }
        power = 1;
        while (power <= i + 1){
            dp[i + 1] = min(dp[i + 1], dp[i + 1 - power] + 1);
            power *= 9;
        }
    }
    cout << dp[n] << endl;
    return 0;
}

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

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

using namespace std;

int main() {
    int n;
    int h[20];
    cin >> n;
    rep(i, n){
        cin >> h[i];
    }
    int max = 0, cnt = 0;
    rep(i, n){
        if(h[i] >= max){
            cnt++;
            max = h[i];
        }
    }
    cout << cnt << endl;
}


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

int main(){
  int64 n,a,b;
  cin>>n>>a>>b;
  if(a>b){
    cout<<0<<endl;
  }else if(n>=2){  
    cout<<(n-2)*(b-a)+1;
  }else if(a==b){
    cout<<1<<endl;
  }else{
    cout<<0<<endl;
  }
}


Measured memory_bytes: 256
#include <iostream>
#include <queue>

using namespace std;

int main()
{
    string s[3];
    for (int i = 0; i < 3; i++) {
        cin >> s[i];
    }

    queue<int> q[3];
    for (int i = 0; i < 3; i++) {
        for (auto& ch : s[i]) {
            q[i].push(ch - 'a');
        }
    }

    int cur = 0;
    while (!q[cur].empty()) {
        int c = cur;
        cur = q[cur].front();
        q[c].pop();
    }
    cout << (char)(cur + 'A') << endl;
    return 0;
}


Measured memory_bytes: 256
import sys
input = sys.stdin.readline

def main():
    N, M = [int(x) for x in input().split()]
    XYZ = [[int(x) for x in input().split()] for _ in range(N)]

    ans = 0
    for i in range(2 ** 3):
        tmp = []
        for x, y, z in XYZ:
            total = 0
            if i >> 0 & 1:
                total += x
            else:
                total -= x
            if i >> 1 & 1:
                total += y
            else:
                total -= y
            if i >> 2 & 1:
                total += z
            else:
                total -= z
            tmp.append(total)

        tmp.sort(reverse=True)
        ans = max(ans, sum(tmp[:M]))

    print(ans)




if __name__ == '__main__':
    main()




Measured memory_bytes: 3300
#include <algorithm>
#include <cmath>
#include <deque>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <tuple>
#include <vector>
using namespace std;
typedef long long ll;
ll const INF = 1LL << 60;

int main() {
  ll N, H, W;
  cin >> N >> H >> W;
  cout << (N - H + 1) * (N - W + 1) << endl;
  return 0;
}

Measured memory_bytes: 3640
N = input()
K = len(N)
ans = 0
flg = True
for i in range(1,K):
  if N[i] != "9":
    flg = False
    break
print(int(N[0]) + 9 * (K - 1) if flg else int(N[0]) + 9 * (K - 1) - 1)
      

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

//aまで出るサイコロの期待値は(a + 1)/2なのでk個選んだ時は(a + 1)/2 + (b + 1)/2 + ...　= (sum + k)/ 2
int main(){
    int n, k; cin >> n >> k;
    vector<double> sum(n + 1);
    for(int i = 0; i < n; i++){
        int a; cin >> a;
        sum.at(i + 1) = sum.at(i) + a;
    }
    double tmp = 0;
    for(int i = 0; i + k <= n; i++){
        // iからi+k-1までの和で最大のものをとってくる
        tmp = max(sum.at(i + k) - sum.at(i), tmp);
    }
    cout << fixed << setprecision(12) << (tmp + k)/ 2 << endl;
}

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


int main() {
  ll a, b, c;
  int x, y;
  cin >> a >> b >> c >> x >> y;

  ll ans = 1e18;
  for (int i = 0; i <= max(x, y) * 2; ++i) {
    int rx = max(0, x - i / 2);
    int ry = max(0, y - i / 2);
    ll total = (c * i) + (a * rx) + (b * ry);
    ans = min(ans, total);
  }
  cout << ans << '\n';
  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <cmath>
#include <cstdio>

#define MAX 100

using namespace std;


int main(){
    
    int x[MAX], y[MAX], n;

    cin >> n;

    for(int i=0; i<n; i++){
        cin >> x[i];
    }
    for(int j=0; j<n; j++){
        cin >> y[j];
    }

    double manh=0;
    for(int i=0; i<n; i++){
        manh+=abs(x[i] - y[i]);
    }

    double euclid_square=0;
    for(int i=0; i<n; i++){
        euclid_square+=pow(x[i] - y[i], 2);
    }
    double euclid = sqrt(euclid_square);

    double third_distance_cube=0;
    for(int i=0; i<n; i++){
        third_distance_cube+=pow(abs(x[i] - y[i]), 3);
    }
    double third_distance = pow(third_distance_cube, 1.0/3.0);

    double max=abs(x[0] - y[0]);
    double distance;
    for(int i=1; i<n; i++){
        distance = abs(x[i] - y[i]);
        if(distance > max){
            max = distance;
        }
    }

    printf("%f\n", manh);
    printf("%f\n", euclid);
    printf("%f\n", third_distance);
    printf("%f\n", max);

    return 0;
}




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

#define REP(i, n, N) for(ll i=(n); i<(N); i++)
#define RREP(i, n, N) for(ll i=(N-1); i>=(n); i--)
#define LREP(lst,itr) for(auto itr = lst.begin(); itr != lst.end(); ++itr)
#define CK(n, a, b) ((a)<=(n)&&(n)<(b))
#define ALL(v) (v).begin(),(v).end()
#define MCP(a, b) memcpy(b,a,sizeof(b))
#define P(s) cout<<(s)<<endl
#define P2(a, b) cout<<(a)<<" "<<(b)<<endl
#define P3(a, b, c) cout<<(a)<<" "<<(b)<<" "<<(c)<<endl
#define V2(T) vector<vector<T>>
typedef long long ll;
using namespace std;
const ll MOD = 1e9 + 7;
const ll INF = 1e18;

int main(){
    int M1,M2,a;
    cin >> M1 >> a;
    cin >> M2 >> a;
    if(M1!=M2){
        P(1);
    }else{
        P(0);
    }
}

Measured memory_bytes: 256