akhauriyash/Code-Regression huggingface dataset:
#include <stdio.h>
#include <string.h>
#define MAX 1000000

int H, A[MAX + 1];

void maxHeapify(int);
void insert(int);
void increasekey(int, int);
int maxExtract(void);

int main(){
  int key;
  char array[10];

  while(1){
    scanf("%s", &array[0]);
    if(!strcmp(array, "end")) break;
    if(!strcmp(array, "insert")){
      scanf("%d", &key);
      insert(key);
    }
    else printf("%d\n", maxExtract());
  }
  
  return 0;
}

void maxHeapify(int i){
  int r, l, largest, temp;

  l = i * 2;
  r = i * 2 + 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){
    temp = A[largest];
    A[largest] = A[i];
    A[i] = temp;
    maxHeapify(largest);
  }
}
void insert(int key){
  H++;  //H = H + 1 で木の一番深いレベルの一番右側の葉に入れる添え字を作る。
  A[H] = key;  
  increasekey(H, key);
}
void increasekey(int i, int key){
  int temp;
  
  while(i > 1 && A[i / 2] < A[i]){  //親と子を比較して、入れ替え。あるいはそのまま。
    temp = A[i / 2];
    A[i / 2] = A[i];
    A[i] = temp;
    i = i / 2;
  }
}
int maxExtract(void){
  int max; //最大値を extract したいから、木構造の root が最大値である。もちろん return するのは max。

  max = A[1];
  A[1] = A[H--];
  maxHeapify(1);
  return max;
}



Measured memory_bytes: 5612
<?php
$all_days = trim(fgets(STDIN));
$front_day = trim(fgets(STDIN));
$front_money = trim(fgets(STDIN));
$back_money = trim(fgets(STDIN));

$all_money = 0;
for ($day=1; $day<=$all_days; $day++){
  if($day<=$front_day){
    $all_money += $front_money;
  }else{
    $all_money += $back_money;
  }
}
echo $all_money;

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

#define lint long long
#define P pair<int, int>
#define LLP pair<long long, long long>
#define REP(i, x, n) for(int i = x ; i < n ; ++i)
#define rep(i, n) for(int i = 0 ; i < n ; ++i)
#define repr(i, n) for(int i = n - 1 ; i >= 0 ; --i)
#define SORT(x) sort((x).begin(), (x).end())

const int IINF = 1e9 + 10;
const long long LLINF = (long long)1e18 + 10;
const long long MOD = (long long)1e9 + 7;
const int dx4[] = {1, 0, -1, 0}, dy4[] = {0, 1, 0, -1};
const int dx8[] = {1, 1, 0, -1, -1, -1, 0, 1}, dy8[] = {0, -1, -1, -1, 0, 1, 1, 1};
const double EPS = 1e-8;

int main(){
    int n, k;
    cin >> n >> k;
    vector<int> h(n);
    rep(i, n){
        cin >> h[i];
    }
    int dp[100010];
    fill(dp, dp + n, IINF);
    dp[0] = 0;
    rep(i, n){
        REP(j, 1, k + 1){
            if(i + j < n){
                dp[i + j] = min(dp[i + j], dp[i] + abs(h[i] - h[i + j]));
            }
        }
    }
    cout << dp[n - 1] << endl;
    return 0;
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
#ifdef __LOCAL
    #define DBG(X) cout << #X << " = " << (X) << endl;
    #define SAY(X) cout << (X) << endl;
#else
    #define DBG(X)
    #define SAY(X)
#endif

#ifdef __LOCAL
    #include <filesystem>
    namespace fs = std::filesystem;
#endif

using namespace std;

using ll = long long int;
using ull = unsigned long long int;
using ld = long double;
using pii = pair<int, int>;
using pll = pair<ll, ll>;

static mt19937 _g(time(nullptr));
inline ll randint(ll a, ll b) { ll w = (_g() << 31LL) ^ _g(); return a + w % (b - a + 1); }
inline void fast_io() { ios_base::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr); };
template<typename T, typename S> inline ostream& operator<<(ostream& os, const pair<T, S> p) { cout << "[" << p.first << ";" << p.second << "]"; return os; }
template<typename T, typename S> inline ostream& operator<<(ostream& os, const map<T, S> p) { for (auto el : p) os << "[" << el.first << " " << el.second << "]"; return os; }
template<typename T> inline ostream& operator<<(ostream& os, const vector<T>& v) { for (auto el : v) os << el << " "; return os; }
template<typename T> inline vector<T> fetch_vec(int sz) { vector<T> ret(sz); for (auto& elem : ret) cin >> elem; return ret; }

int N;
vector<ll> A;
vector<ll> AS;
void input(){
    fast_io();
    #ifdef __LOCAL
        fs::path p = __FILE__;
        fs::path input,output;
        input = output = p.parent_path();
        input += string("/input/") + string(p.stem()) + string(".txt");
        output += string("/output/") + string(p.stem()) + string(".txt");
        freopen(input.c_str(), "r", stdin);
        freopen(output.c_str(), "w", stdout);
    #endif
    cin >> N;
    AS.assign(N+1,0);
    for (int i = 0; i < N; i++)
    {
      ll a;
      cin >> a;
      A.push_back(a);
      AS[i+1] = AS[i] + a;
    }
}

// そもそも貪欲が間違い？
ll dfs(vector<ll> v){
  if(v.size()<=1) return 0;
  ll ret = 0LL;
  vector<ll> x=v;
  vector<ll> sum;
  for (int i = 0; i < x.size()-1; i++)
  {
    sum.push_back(x[i]+x[i+1]);
  }
  auto itr = min_element(sum.begin(),sum.end());
  int idx = itr-sum.begin();
  x.erase(x.begin()+idx+1);
  x[idx] = *itr;
  ret += *itr;
  ret += dfs(x);
  return ret;
}

ll dp[410][410];

ll rec(int l=0,int r=N){
  if(r-l<=1) return 0;
  if(dp[l][r]!=-1) return dp[l][r];
  ll ret = 1e18;
  for (int i = l+1; i < r; i++)
  {
    ret = min(ret, rec(l,i) + rec(i,r) + AS[r] - AS[l]);
  }
  return dp[l][r] = ret;
}

int solve(){
  memset(dp,-1,sizeof(dp));
  cout << rec() << endl;
  return 0;
}

int maketestcase(int n){
  #ifdef __LOCAL
      fs::path p = __FILE__;
      fs::path input,output;
      input = output = p.parent_path();
      input += string("/input/") + string(p.stem()) + string(".txt");
      output += string("/output/") + string(p.stem()) + string(".txt");
      // freopen(output.c_str(), "r", stdin);
      freopen(input.c_str(), "w", stdout);
  cout << n << endl;
  for (int i = 0; i < n; i++)
  {
    cout << randint(0,1000000000) << " ";
  }
  cout << "\n";
  #endif
  return 0;
}

int main()
{
  // maketestcase(400);
  input();
  solve();
  return 0;
}


Measured memory_bytes: 1664
/*
    Author:zeke
    
    pass System Test!
    GET AC!!
*/
#include <iostream>
#include <queue>
#include <vector>
#include <iostream>
#include <vector>
#include <string>
#include <cassert>
#include <algorithm>
#include <functional>
#include <cmath>
#include <queue>
#include <set>
#include <stack>
#include <deque>
#include <map>
#include <iomanip>
#include <utility>
#include <stack>
#include <bitset>
using ll = long long;
using ld = long double;
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(), (x).end()
#define rep3(var, min, max) for (ll(var) = (min); (var) < (max); ++(var))
#define repi3(var, min, max) for (ll(var) = (max)-1; (var) + 1 > (min); --(var))
#define Mp(a, b) make_pair((a), (b))
#define F first
#define S second
#define Icin(s) \
    ll(s);      \
    cin >> (s);
#define Scin(s) \
    ll(s);      \
    cin >> (s);
template <class T>
bool chmax(T &a, const T &b)
{
    if (a < b)
    {
        a = b;
        return 1;
    }
    return 0;
}
template <class T>
bool chmin(T &a, const T &b)
{
    if (b < a)
    {
        a = b;
        return 1;
    }
    return 0;
}
typedef pair<ll, ll> P;
typedef vector<ll> V;
typedef vector<V> VV;
typedef vector<P> VP;
ll mod = 1e9 + 7;
ll MOD = 1e9 + 7;
ll INF = 1e18;

int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll n,r;
    cin>>n>>r;
    if(n>=10){
        cout<<r<<endl;
    }else{
        cout<<r+(10-n)*100<<endl;
    }
}


Measured memory_bytes: 256
import itertools
N,M=list(map(int,input().split()))
l=[]
t=1
for i in range(N):
   l.append(t)
   t+=2
t=2
for i in range(M):
   l.append(t)
   t+=2
count=0
for v in itertools.combinations(l,2):
    #print(v[0],v[1])
    if (v[0]+v[1])%2==0:
        count+=1
print(count)

Measured memory_bytes: 3064
#pragma comment(linker, "/STACK:1024000000,1024000000")
#include<iostream>
#include<cstdio>
#include<cstring>
#include<string>
#include<algorithm>
#include<cmath>
#include<queue>
#include<map>
#include<vector>
#include<list>
#include<set>
#include<bitset>
#include<stack>
#include<cctype>
#define sc(x) scanf("%d",&x);
#define pr(x) cout<<#x<<": "<<x<<" ";
#define prln(x) cout<<#x<<": "<<x<<endl;
#define bug() cout<<"bug: "<<endl;
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> P;
const double eps = 1e-4;
const int mod = 1e9+7;
const ll INF = 0x3f3f3f3f3f3f3f3f;
const int inf = 0x3f3f3f3f;
const int maxn = 1e5+7;
const int maxm = 1e6+7;
const double pi = acos(-1.0);

int main(){
	int n; scanf("%d",&n);
	char s1[maxn],s2[maxn];
	scanf("%s%s",s1,s2);
	ll ans=1; int flag=0; int i;
	//flag==0 shu
	//flag==1 heng
	if(s1[0]==s2[0]){
		ans=3; i=1;
	}
	else{
		ans=6; i=2;
		flag++;
	}
	for(; i<n; ){
		if(s1[i]==s2[i]){
			if(flag%2){
				flag=0;
			}
			else{
				flag=0;
				ans=ans*2%mod;
			}
			i++;
		}
		else{
			if(flag%2){
				flag=1;
				ans=ans*3%mod;
			}
			else{
				flag=1;
				ans=ans*2;
			}
			i+=2;
		}
	}
	cout<<ans<<endl;
}

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

using namespace std;

#ifdef LOCAL
#define DBG_MACRO_NO_WARNING
#include <dbg.h>
#else
#define dbg(...) 0
#endif

using ll = long long;
using ull = unsigned long long;

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

#ifdef LOCAL
  freopen("input.txt", "r", stdin);
  freopen("output.txt", "w", stdout);
#endif

  ll n;
  cin >> n;

  vector<ll> a(n);

  map<ll, ll> cnt;

  for (auto &i : a) {
    cin >> i;
    cnt[i]++;
  }

  ll sum = 0;

  auto choose = [](ll x) {
    ll ans = (x * (x - 1)) / 2;
    return ans;
  };

  for (auto i : cnt) {
    dbg(i.first);
    sum += choose(i.second);
  }

  for (auto i = 0; i < n; ++i) {
    ll ans = sum - choose(cnt[a[i]]) + choose(cnt[a[i]] - 1);
    cout << ans << "\n";
  }

  dbg(sum);

  return 0;
}

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

template <typename T> void chmax(T &x,const T &y)
{
	if(x<y)x=y;
}
template <typename T> void chmin(T &x,const T &y)
{
	if(x>y)x=y;
}
typedef long long ll;
typedef unsigned int ui;
#define rep(i,l,r) for(int i=l;i<=r;++i)
#define per(i,r,l) for(int i=r;i>=l;--i)
const int N=1e5+5,M=2e5+5,inf=1e9+1;
int t[N];
struct edge
{
	int to,next,w;
};
edge l[M*2];int e;
int g[N],mn,mx;

void out()
{
	puts("No");exit(0);
}
void dfs(int x)
{
	for(int i=t[x];i;i=l[i].next)
	{
		int y=l[i].to;
		int g_y=g[x]+l[i].w;
		if(g_y>=inf)out();
		chmin(mn,g_y);chmax(mx,g_y);
		if(g[y]>inf){g[y]=g_y;dfs(y);}
		else 
		if(g[y]!=g_y)out();
	}
}

int main()
{
	//freopen("1.in","r",stdin);
	int	n,m; 
	cin>>n>>m;
	rep(i,1,m)
	{
		int x,y,w;
		scanf("%d %d %d",&x,&y,&w);
		l[++e]=(edge){y,t[x],w};t[x]=e;
		l[++e]=(edge){x,t[y],-w};t[y]=e;
	}
	memset(g,(1<<7)-1,sizeof(g));
	rep(x,1,n)
	if(g[x]>inf)
	{
		mx=mn=0;
		g[x]=0;dfs(x);
		if(mx-mn>=inf)out();
	}
	puts("Yes");
}


Measured memory_bytes: 7680
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int>P;
const double eps = 1e-8;
const int NINF = 0xc0c0c0c0;
const int INF  = 0x3f3f3f3f;
const ll  mod  = 1e9 + 7;
const ll  maxn = 1e6 + 5;

double L;

int main(){
	// ios::sync_with_stdio(false);
	// cin.tie(0);
	cin>>L;
	printf("%.10lf\n",(L/3.0)*(L/3.0)*(L/3.0));
	return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<string>
using namespace std;
int main(){
    int n;
    cin>>n;
    string a;
    cin>>a;
    int t;
    cin>>t;
    for(int i=0;i<n;i++){
        if(a[i]!=a[t-1]) a[i]='*';
    }
    cout<<a<<endl;
    return 0;
}


Measured memory_bytes: 256
data Tree a = Leaf a | Branch Char (Tree a) (Tree a) deriving Show

showTree :: Show a => Tree a -> String
showTree (Leaf x) = show x
showTree (Branch o t1 t2) = "(" ++ showTree t1 ++ " " ++ [o] ++ " " ++ showTree t2 ++ ")"

make :: [Tree Int] -> [Tree Int] -> [Tree Int]
make ts1 ts2 = concatMap (\ [t1,t2] -> [Branch '+' t1 t2 , Branch '-' t1 t2 , Branch '-' t2 t1 , Branch '*' t1 t2]) $ sequence [ts1 , ts2]

makeAllTree :: [Int] -> [Tree Int]
makeAllTree xs = abcd
    where
        abcd = concat $ [make abc d , make abd c , make acd b , make bcd a , make ab cd , make ac bd , make ad bc]
        abc = concat $ [make ab c , make ac b , make bc a]
        abd = concat $ [make ab d , make ad b , make bd a]
        acd = concat $ [make ac d , make ad c , make cd a]
        bcd = concat $ [make bc d , make bd c , make cd b]
        ab = make a b
        ac = make a c
        ad = make a d
        bc = make b c
        bd = make b d
        cd = make c d
        [a,b,c,d] = sequence [map Leaf xs]

calc :: Tree Int -> Int
calc (Leaf x) = x
calc (Branch '+' x y) = calc x + calc y
calc (Branch '-' x y) = calc x - calc y
calc (Branch '*' x y) = calc x * calc y
calc _ = error "cannot calc"

solve :: [Int] -> IO ()
solve = putStrLn . maybe "0" showTree . foldr (\ x y -> case x of Nothing -> y ; z -> z) Nothing . map (\ t -> if calc t == 10 then Just t else Nothing) . makeAllTree

main :: IO ()
main = getContents
    >>= return . takeWhile (/= [0,0,0,0]) . map (map read) . map words . lines
    >>= mapM_ solve

Measured memory_bytes: 4076
#include<iostream>
#include<vector>
#include<algorithm>
#include<iomanip>
#include<utility>
#include<iomanip>
#include<map>
#include<cmath>
#include<cstdio>
#define rep(i,n) for(int i=0; i<(n); ++i)
using namespace std;
using ll =long long;
using P = pair<int,int>;

int main(){
    long double l;
    cin >> l;
    cout << fixed << setprecision(30) << l*l*l/27 << endl;
    return 0;
}

Measured memory_bytes: 256
#include<cstdio>
#include<algorithm>

using namespace std;

long long Q, H, S, D, n, ans;

int main(){
	scanf("%lld %lld %lld %lld", &Q, &H, &S, &D);
	H = min(Q << 1, H);
	S = min(H << 1, S);
	D = min(S << 1, D);
	
	scanf("%lld", &n);
	ans = n / 2 * D + n % 2 * S;
	printf("%lld\n", ans); 
	return 0;
}

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

#define itn int
#define all(x) (x).begin(), (x).end()
#define make_unique(x) sort(all((x))); (x).resize(unique(all((x))) - (x).begin())

using namespace std;

inline int nxt() {
	int x;
	cin >> x;
	// scanf("%d", &x);
	return x;
}

int main() {
	cin.sync_with_stdio(0);
	int n = nxt();
	string s;
	cin >> s;
	vector<int> a(n);
	for (int i = 0; i < n; ++i) {
		a[i] = s[i] - '1';
	}
	// while (a.size()) {
	// 	cerr << string(n - (int)a.size(), ' ');
	// 	for (int x : a) {
	// 		cerr << x << " ";
	// 	}
	// 	cerr << "\n";
	// 	vector<int> b;
	// 	for (int i = 0; i < (int)a.size() - 1; ++i) {
	// 		b.push_back(abs(a[i] - a[i + 1]));
	// 	}
	// 	a.swap(b);
	// }
	// return 0;
	n -= 1;
	int ans = 0;
	for (int i = 0; i <= n; ++i) {
		if ((i & n) == i) {
			ans ^= a[i] % 2;
		}
	}
	if (ans % 2 == 0 && s.find('2') == string::npos) {
		ans = 0;
		for (int i = 0; i <= n; ++i) {
			if ((i & n) == i) {
				ans ^= a[i];
			}
		}
	}

	cout << ans << "\n";

	return 0;
}


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


def readstr():
    return input().strip()


def readint():
    return int(input())


def readnums():
    return map(int, input().split())


def readstrs():
    return input().split()


def main():
    N = readstr()
    c = 0
    for n in N:
        c += int(n)
    print("Yes" if not c % 9 else "No")


if __name__ == "__main__":
    main()


Measured memory_bytes: 9292
N,P=map(x->parse(Int,x),split(readline()))
A=zeros(Int,2)
for a=map(x->parse(Int,x),split(readline()))
  A[mod1(a,2)]+=1
end
ans=0
for i=0:A[1]
  if i%2==P
    ans+=binomial(A[1],i)
  end
end
println(ans*2^A[2])

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

int main(){
  ll n,sum=0;
  cin >> n;
  vector<ll> a(n);
  for(ll i=0;i<n;i++){
    cin >> a.at(i);
    sum += a.at(i);
    sum %= 1000000007;
  }
  
  ll t = 0;
  for(ll i=0;i<n-1;i++){
    sum -= a.at(i);
    if(sum < 0) sum += 1000000007;
    
    t += a.at(i)*sum;
    t %= 1000000007;
  }
  
  cout << t << endl;
  
  return 0;
}


Measured memory_bytes: 4836
#include <bits/stdc++.h>
#define rep(i,n) for (ll i = 0; i < (n); ++i)
using namespace std;
typedef long long ll;
typedef pair<ll,ll> P;
typedef vector<vector<ll> > Graph;
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; }
const ll INF = 1e16;



int main(){
    string s,t;
    cin >> s >> t;
    int ls = s.size();
    int lt = t.size();
    reverse(t.begin(),t.end());
    reverse(s.begin(),s.end());
    bool done = false;
    for(int i=0;i<=ls-lt;i++){
        if(done)continue;
        bool flag=true;
        rep(j,lt){
            if(s[i+j]!='?'&&s[i+j]!=t[j]){
                flag=false;
            }
        }
        if(flag){
            done=true;
            rep(j,lt){
                s[i+j]=t[j];
            }
        }
    }
    if(!done){
        cout << "UNRESTORABLE" << endl;
        return 0;
    }
    string ans="";
    reverse(s.begin(),s.end());
    for(int i = 0;i<ls;i++){
        if(s[i]=='?'){
            ans+='a';
        }
        else{
            ans+=s[i];
        }
    }
    cout << ans << endl;
    return 0;
}



Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std ; 
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define fast ios_base:: sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define int long long int
#define endl "\n"
#define pb push_back
#define bs binary_search
#define lb lower_bound
#define ub upper_bound
#define f first
#define s second
#define pii pair<int,int> 
long long MOD  = 1e9+7;


signed main(){
    fast;
    int n; cin >> n;
    cout << (int)n*n*n << endl;    

    cerr << endl;
}

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

using namespace std;

struct SegmentTree {
  const int INF = numeric_limits<int>::max();
  int n;
  vector<int> node;

  SegmentTree(vector<int> v) {
    int sz = (int)v.size();
    n = 1;
    while (n < sz) n *= 2;
    node.resize(2 * n - 1, INF);
    for (int i = 0; i < sz; i++) node[i + n - 1] = v[i];
    for (int i = n - 2; 0 <= i; i--)
      node[i] = min(node[i * 2 + 1], node[i * 2 + 2]);
  }

  SegmentTree(vector<int> v, int x) {
    int sz = (int)v.size();
    n = 1;
    while (n < sz) n *= 2;
    node.resize(2 * n - 1, x);
    for (int i = 0; i < sz; i++) node[i + n - 1] = v[i];
    for (int i = n - 2; 0 <= i; i--)
      node[i] = node[i * 2 + 1] + node[i * 2 + 2];
  }

  // x番目の要素をvalに更新する
  void update(int x, int val) {
    x += (n - 1);
    node[x] = val;
    while (x > 0) {
      x = (x - 1) / 2;
      node[x] = min(node[2 * x + 1], node[2 * x + 2]);
    }
  }

  // 区間[a, b)の要素の最小値を返す. k := 自分がいるノードのインデックス
  int getmin(int a, int b, int k = 0, int l = 0, int r = -1) {
    if (r < 0) r = n;
    if (r <= a || b <= l) return INF;

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

  void add(int k, int val) {
    k += (n - 1);
    node[k] += val;
    while (k > 0) {
      k = (k - 1) / 2;
      node[k] = node[2 * k + 1] + node[2 * k + 2];
    }
  }

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

    if (b <= l || r <= a) return 0;
    if (a <= l && r <= b) return node[k];

    int vl = getsum(a, b, 2 * k + 1, l, (l + r) / 2);
    int vr = getsum(a, b, 2 * k + 2, (l + r) / 2, r);
    return vl + vr;
  }
};

// AOJ DSL_2_A Range Minimum Query (RMQ)
void RMQ() {
  int n, q, com, x, y;
  cin >> n >> q;
  SegmentTree seg(vector<int>(n, numeric_limits<int>::max()));
  for (int i = 0; i < q; i++) {
    cin >> com >> x >> y;
    if (com)
      cout << seg.getmin(x, y + 1) << endl;
    else
      seg.update(x, y);
  }
}

// AOJ DSL_2_B Range Sum Query (RSQ)
void RSQ() {
  int n, q, com, x, y;
  cin >> n >> q;
  SegmentTree seg(vector<int>(n, 0), 0);
  for (int i = 0; i < q; i++) {
    cin >> com >> x >> y;
    if (com)
      cout << seg.getsum(x - 1, y) << endl;
    else
      seg.add(x - 1, y);
  }
}

int main() {
  // RMQ();
  RSQ();
  return 0;
}



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

long long f(long long i, long long j)
{
    long long ans;
    string s1, s2;

    s1 = to_string(i);
    s2 = to_string(j);
    if (s1.size() >= s2.size())
        ans = s1.size();
    else
        ans = s2.size();

    //    cout << ans <<"=" << s1 << ":" << s2 << endl;
    return(ans);
}


int main()
{
    long long n, m;
    long long ans;

    cin >> n;

    ans = 100000000000;
    for (long i = 1;i <= n;++i) {
        m = n / i;
        if (m <= 0)
            break;
        if (m < i)
            break;
        if (i * m == n) {
            long j = f(m, i);
            if (ans > j) {
                ans = j;
            }
        }
    }

    cout << ans << endl;
}


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

int main()
{
    int a, b;
    cin >> a >> b;
    int max = a+b;
    if(max<a-b){
        max=a-b;
    }
    if(max<a*b){
        max=a*b;
    }
    cout << max << endl;
    return 0;
}

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

int main(){
    stack<char> st;
    string s;
    cin>>s;
    if((s[0]==s[1])&&(s[1]==s[2])&&(s[2]==s[3])){
        cout<<"No"<<endl;
    }
    else{
        int c=1,k=-1,i,p;
        st.push(s[0]);
        for(i=1;i<s.length();i++){
            if(s[i]==st.top()){
                c++;
                st.pop();
                p=i;
                break;
            }
            else{
                k=i;
            }
        }
        if(c!=2){
            cout<<"No"<<endl;
        }
        else{
            c++;
            if(k==-1){
                k=i+1;
            }
            st.push(s[k]);
            for(i=1;i<s.length();i++){
                if(s[i]==st.top() && k!=i && k!=p){
                    c++;
                    st.pop();
                    break;
                }
            }
            if(c==4){
                cout<<"Yes"<<endl;
            }
            else{
                cout<<"No"<<endl;
            }
        }
    }
}


Measured memory_bytes: 256
/**
 *    Author:  "Robin Singh" !!!!    
**/
#include <bits/stdc++.h>
using namespace std;
#define ll long long int
#define ld long double
#define pb push_back
#define pf push_front
#define eb emplace_back
#define ef emplace_front
#define all(x) (x).begin(),(x).end()
#define ff first
#define ss second
#define pii pair<int,int>
#define pll pair<ll,ll>
#define mp make_pair
#define str string 
#define szz(v) ((int)(v).size())  
#define vi vector<int>
#define vll vector<ll>
#define fr(i, j, k) for(i = j; i < k; i++)
#define bk(i, j, k) for(i = j; i >= k; i--)
#define frit(it, a) for(__typeof((a).begin()) it = a.begin(); it != a.end(); ++it)
#define mem(ptr)  memset(ptr, 0, sizeof ptr)  // use fill() for value other than 0 //
#define rtn return 
#define time fprintf(stderr, "\nTIME = %lf\n", 1.0 * clock()/CLOCKS_PER_SEC)
#define nl "\n"
#define INF 1LL<<61
#define inf 1<<30
#define dbg(x) (cerr << #x << ": " << x << "\n")
const long long mod = 1e9+7;

ll gcd(ll a,ll b) { return b==0 ? a : gcd(b, a%b); }
ll expo(ll x, ll y){ ll res = 1; x = x % mod;  while (y > 0) { if (y & 1)res = (res*x) % mod; y = y>>1;x = (x*x) % mod;}return res;}
void matmul(ll a[][2], ll b[][2]) { ll tmp[2][2]; for(int i=0; i<2; i++) { for(int j=0; j<2; j++) { tmp[i][j] = 0; for(int k=0; k<2; k++) tmp[i][j] = (tmp[i][j] + a[i][k]*b[k][j]) % mod; }} for(int i=0; i<2; i++) for(int j=0; j<2; j++) a[i][j] = tmp[i][j]; }
ll fibo(int n)    // returns nth fibonacci number, also S(n) = f(n+2)-1
{ if(n == 0) return 0; else if(n == 1) return 1; ll T[2][2] = { {0, 1} , {1, 1} }; ll res[2][2] = { {1, 0}, {0,1} }; n--; while(n) { if(n & 1) matmul(res, T); n >>= 1; matmul(T, T); } return res[1][1]; }

int main()
{
    ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
    ll a, b;
    cin >> a >> b;
    ll i, j;
    for(i=0; (i*(i+1)/2) < a; i++);
    ll aa = i*(i+1)/2;
    j = i+1;
    ll bb = j*(j+1)/2;
    while((aa - a) != (bb - b))
    {
        i++;
        j++;
        aa = i*(i+1)/2;
        bb = j*(j+1)/2;
    }
    cout << aa-a;
    return 0;
}

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

int main(){
	int N;
	cin >> N;
	vector<int> d(N);
	for (int i = 0; i < N; i++){
		cin >> d[i];
	}
	sort(d.begin(), d.end());
	cout << d[(N / 2)] - d[(N / 2)-1] << endl;
	return 0;
}

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

int main(){
	int n, l;
	cin >> n >> l;
	string s[100];
	for (int i = 0; i < n; i++) {
		cin >> s[i];
	}
	sort(s, s + n);
	for (int i = 0; i < n; i++) {
		cout << s[i] << flush;
	}
	cout << endl;
}

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

int main(){
  int K, S;
  cin >> K >> S;
  int count =0;
  for(int i=0; i<=K; i++){
    for(int j=0; j<=K; j++){
      if(0<=S-i-j && S-i-j<=K)
        count++;
    }
  }
  cout << count << endl;
}

Measured memory_bytes: 384
#include <cstdio>

const int MOD = 1e9 + 7;

int fpm(int x, int exp) {
  int res(1);
  for (; exp; x=(long long)x*x%MOD, exp>>=1)
    if (exp&1)
      res = (long long) res*x % MOD;
  return res;
}

int totp;
int pri[10000];

int dfs(int x, int mi, int k) {
  int i, res(0);
  if (k == 0 && x == 1)
    return 1;
  for (i=mi; i<=x; ++i)
    if (x%i == 0)
      res += dfs(x/i, i+1, k-1);
  return res;
}

int getprisum(int N) {
  int i, j, tot(0);
  for (i=2; i<=N; ++i) {
    for (j=2; j*j<=i; ++j)
      if (i%j == 0)
	break;
    if (j*j > i)
      pri[totp++] = i;
  }
  return tot;
}

int n;

int getddd(int p) {
  int from = p, sum(0);
  while (p <= n) {
    sum += n/p;
    p *= from;
  }
  return sum;
}

void exec() {
  int i, ans(1);
  getprisum(1000);
  scanf("%d", &n);
  for (i=0; i<totp; ++i)
    ans = (long long) ans * (getddd(pri[i])+1) % MOD;
  printf("%d\n", ans);
}

int main() {
  if (fopen("C.in", "r") != NULL) {
    freopen("C.in", "r", stdin);
    freopen("C.out", "w", stdout);
  }
  exec();
  return 0;
}


Measured memory_bytes: 256
function prime(max){
   var arr=[];
   for(var i=0;i<=max;i++)arr[i]=i;
   arr[0]=false;
   arr[1]=false;
   var sqrt=Math.floor(Math.sqrt(max));
   for(var i=2;i<=sqrt;i++){
      if(arr[i]==false)continue;
      for(var j=i+i;j<=max;j+=i){
         arr[j]=false;
      }
   }
   var result=[];
   for(var i=0;i<=max;i++){
      if(arr[i]!==false)result.push(arr[i]);
   }
   return result;
}
var p=prime(9999999);
var input = require('fs').readFileSync('/dev/stdin', 'utf8');
var Arr=(input.trim()).split("\n").map(Number);
for(var i=0;i<Arr.length;i++){
   var a=Arr[i];
   if(a==0)break;
   var quad="";
   for(var j=5;j<p.length;j++){
   if(p[j]>a)break;
   var x=p[j]-8;
   if(x==p[j-3] && x+2==p[j-2] && x+6==p[j-1])quad=p[j];
   }
   console.log(quad);
}

Measured memory_bytes: 205948
#include <iostream>
#include <cmath>
#include <string>
#include <algorithm>
#include <set>
#include <vector>
#include <map>
#include <list>
#include <stack>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <queue>
#define pr(num) printf("%lld\n", num)
#define max(a, b) ((a)>(b) ? (a):(b))
#define min(a, b) ((a)<(b) ? (a):(b))
#define INF 1000000000000000000
#define MOD 1000000007LL
#define MAX 100010
#define BLACK 0
#define WHITE 1
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
typedef map<ll, ll> Map;


int main(void) {
    ll N, M;
    cin >> N >> M;
    ll i, j;
    vector<P> city[MAX];
    ll p, y;
    P id[MAX];
    
    for(i=0; i<M; i++) {
        cin >> p >> y;
        p--;
        city[p].push_back({y, i});
    }
    
    for(i=0; i<N; i++) {
        sort(city[i].begin(), city[i].end());
    }
    
    for(i=0; i<N; i++) {
        for(j=0; j<city[i].size(); j++) {
            id[city[i][j].second]={i, j};
        }
    }
    
    for(i=0; i<M; i++) {
        printf("%06lld%06lld\n", id[i].first+1, id[i].second+1);
    }
    
}

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

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

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

    int d[n];
    for(int i=0; i<n; i++) d[i]=1e9+5;
    d[0]=0;

    for(int i=0; i<n; i++){
      for(int j=i+1; j<=i+k; j++){
        if(j<n) d[j] = min(d[j], d[i]+abs(h[i]-h[j]));
      }
    }

    cout<<d[n-1]<<"\n";
}

Measured memory_bytes: 1024
#include<unordered_map>
#include<stdio.h>
#include<iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<string.h>

#ifdef LOCAL
#define eprintf(...) fprintf(stderr, __VA_ARGS__)
#else
#define NDEBUG
#define eprintf(...) do {} while (0)
#endif
#include<cassert>

using namespace std;

typedef long long LL;
typedef vector<int> VI;

#define REP(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define EACH(i,c) for(__typeof((c).begin()) i=(c).begin(),i##_end=(c).end();i!=i##_end;++i)

template<class T> inline void amin(T &x, const T &y) { if (y<x) x=y; }
template<class T> inline void amax(T &x, const T &y) { if (x<y) x=y; }
template<class Iter> void rprintf(const char *fmt, Iter begin, Iter end) {
    for (bool sp=0; begin!=end; ++begin) { if (sp) putchar(' '); else sp = true; printf(fmt, *begin); }
    putchar('\n');
}

LL encode(LL l, LL r, LL a, LL b) {
    return ((l * 32 + r) * 4096 + a) * 4096 + b;
}

unordered_map<LL, LL> mem;
int N;
int A[18];


LL rec(int l, int r, int a, int b) {
    // eprintf("%d %d %d %d\n", l, r, a, b);
    if (l + 1 >= r) {
	return 0;
    }

    LL key = encode(l, r, a, b);
    auto it = mem.find(key);
    if (it != mem.end()) return it->second;

    LL ret = 1LL<<60;
    for (int k=l+1; k<r; k++) {
	amin(ret, (LL)A[k]*(a+b) + rec(l, k, a, a+b) + rec(k, r, a+b, b));
    }
    return mem[key] = ret;
}

void MAIN() {
    scanf("%d", &N);
    REP (i, N) scanf("%d", A+i);

    LL ans = A[0] + A[N-1] + rec(0, N-1, 1, 1);

    printf("%lld\n", ans);
}

int main() {
    int TC = 1;
//    scanf("%d", &TC);
    REP (tc, TC) MAIN();
    return 0;
}



Measured memory_bytes: 14280
x1,y1,x2,y2 = map(int,input().split())

xlen = x2-x1
ylen = y2-y1

y3 = y2 + xlen
x3 = x2 - ylen
y4 = y3 - ylen
x4 = x3 - xlen

print(x3,y3,x4,y4)

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

//template
#define rep(i,a,b) for(int i=(a);i<(b);i++)
#define rrep(i,a,b) for(int i=(a);i>(b);i--)
#define ALL(v) (v).begin(),(v).end()
typedef long long int ll; typedef pair<ll, ll> P;
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; }
template<typename A,size_t N,typename T>void Fill(A(&array)[N],const T &val){fill((T*)array, (T*)(array+N), val);}
const int inf = INT_MAX / 2; const ll INF = LLONG_MAX / 2;
//template end

int xors[2010][2010]={},precalc[2010][2010]={};

int main(){
    int h,w; scanf("%d%d",&h,&w);
    vector<string> g(h);
    rep(i,0,h)cin>>g[i];
    rep(i,0,h)rep(j,0,w-1){
        if(g[i][j]!=g[i][j+1])xors[i][j]=1;
    }
    rep(i,0,h)rep(j,0,w-1){
        if(precalc[i][j]==0)precalc[i][j]=1;
        if(i!=h-1&&xors[i][j]==xors[i+1][j])precalc[i+1][j]=precalc[i][j]+1;
    }
    ll ans=max(h,w);
    rep(i,0,h){
        vector<int> list;
        rep(j,0,w-1)list.push_back(precalc[i][j]);
        list.push_back(0);
        stack<P> st; //pos,height
        rep(j,0,w){
            if(st.empty()||st.top().second<list[j]){
                st.push({j,list[j]}); continue;
            }
            if(st.top().second==list[j])continue;
            int idx=j;
            while(st.size()&&st.top().second>list[j]){
                P area=st.top(); st.pop();
                chmax(ans,area.second*(j-area.first+1));
                idx=area.first;
            }
            st.push({idx,list[j]});
        }
    }
    printf("%lld\n",ans);
    return 0;
}

Measured memory_bytes: 35840
#include <bits/stdc++.h>
#define FOR(i, begin, end) for(int i=(begin);i<(end);i++)
#define REP(i, n) FOR(i,0,n)
#define IFOR(i, begin, end) for(int i=(end)-1;i>=(begin);i--)
#define IREP(i, n) IFOR(i,0,n)
#define SORT(a) sort(a.begin(), a.end())
#define REVERSE(a) reverse(a.begin(), a.end())
#define int long long
#define INF 1000000000000000
using namespace std;

typedef vector<int> vec;
typedef vector<vec> mat;
typedef pair<int, int> Pii;

template<typename T>
void readvec(vector<T> &a);
void readindex(vector<int> &a);



signed main(){

    int H, W; cin >> H >> W;
    mat a(H, vec(W));
    REP(i, H) readvec(a[i]);

    mat ans(0, vec(4));

    REP(i, H - 1){
        REP(j, W){
            if(a[i][j] % 2 == 1){
                a[i][j]--;
                a[i + 1][j]++;
                ans.push_back(vec({i + 1, j + 1, i + 2, j + 1}));
            }
        }
    }
    REP(j, W - 1){
        if(a[H - 1][j] % 2 == 1){
            a[H - 1][j]--;
            a[H - 1][j + 1]++;
            ans.push_back(vec({H, j + 1, H, j + 2}));
        }
    }

    cout << ans.size() << endl;
    REP(i, ans.size()){
        cout << ans[i][0] << " " << ans[i][1] << " " << ans[i][2] << " " << ans[i][3] << endl;
    }
    
    return 0;
}


template<typename T>
void readvec(vector<T> &a){
    REP(i, a.size()){
        cin >> a[i];
    }
}
void readindex(vector<int> &a){
    REP(i, a.size()){
        cin >> a[i];
        a[i]--;
    }
}

Measured memory_bytes: 12848
#include <iostream>
#include <vector>
using namespace std;
int main()
{
  for(;;){
    int n;
    cin >> n;
    if(n==0) break;
    vector<vector<int> > v(n,vector<int>(4));
    for(int i=0; i<n; i++){
      cin >> v[i][0] >> v[i][1] >> v[i][2] >> v[i][3];
    }
    int P,Q,R,C;
    cin >> P >> Q >> R >> C;
    bool bfind = false;
    for(int i=0; i<n; i++){
      if(v[i][1] > P) continue;
      if(v[i][2] > Q) continue;
      if(v[i][3] > R) continue;
      if((v[i][1]+v[i][3])*4+v[i][2]*9 > C) continue;
      cout << v[i][0] << endl;
      bfind = true;
    }
    if(!bfind) cout << "NA" << endl;
  }
  return 0;      
}

Measured memory_bytes: 1268
//https://atcoder.jp/contests/nikkei2019-qual/tasks/nikkei2019_qual_d
#include <bits/stdc++.h>
using namespace std;
using ll=int64_t;
#define FOR(i,a,b) for(int64_t i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)

struct Edge{
    ll st; //start
    ll tr; //end
    ll weight;
	Edge(ll s, ll t, ll w) : st(s), tr(t), weight(w) {}
	Edge() : Edge(0, 0, 0) {}
};
using Edges = vector<Edge>;
using Graph = vector<Edges>;
//topological sort の一つを得る、１つの入力に対して複数の解答がる。
std::vector<int> tsort(const Graph &g) {
    int n = g.size();
    enum class State { NEW, ACTIVE, FINISHED };
    std::vector<int> res;
    vector <State> state(n, State::NEW);
    static const std::function<bool(int)> dfs = [&](int v) {
        state[v] = State::ACTIVE;
        for (auto &e : g[v]) {
            int w = e.tr;
            if (state[w] == State::ACTIVE) return false;
            else if (state[w] == State::NEW) if (!dfs(w)) return false;
        }
        state[v] = State::FINISHED;
        res.push_back(v);
        return true;
    };
    for (int i = 1; i < n; ++i) //1start
        if (state[i] == State::NEW && !dfs(i)) return {-1};
    std::reverse(res.begin(), res.end());
    return res;
}

struct Node{
    vector<ll> iri;
    ll topo=-1;
};

int main() {
    // cin.tie(0);
    // ios::sync_with_stdio(false);
#if LOCAL&01
    std::ifstream in("./test/sample-1.in"); //input.txt
    std::cin.rdbuf(in.rdbuf());
#endif
    ll n,m; cin>>n>>m;
    Graph graph(n+1);
    vector<Node> nodes(n+1);
    FOR(i,1,(n+m-1+1)){
        ll a,b; cin>>a>>b;
        graph.at(a).emplace_back(a,b,0);
        nodes.at(b).iri.push_back(a);
    }
    auto ord=tsort(graph);
    FOR(i,0,ord.size()){
        nodes[ord.at(i)].topo=i;
        //cout<<ord.at(i)<<endl;
    }

    //topologyがしたのedgeを出力していく
    for(ll i=1;i<nodes.size();++i){
        const auto& cn = nodes[i];
        vector<pair<ll,ll>> tmp;
        for(auto iri_n: cn.iri){
             tmp.push_back({nodes[iri_n].topo,iri_n});
        }
        sort(tmp.begin(),tmp.end(),[](auto& a,auto& b){ return a.first > b.first;}); //topology降順にsort
        
        cout<<(tmp.size()<=0?0:tmp.begin()->second)<<endl;
    }

    return 0;
}

Measured memory_bytes: 16256
n,x,y = map(int,input().split())

x,y = x-1,y-1

d={}
for k in range(1,n):
    d[k]=0


for i in range(n):
    for j in range(i+1,n):
     
        dist=min(abs(i-j) , abs( i - x ) + 1 + abs(y - j) ,abs( i - y ) + 1 + abs(x - j))

        d[dist]+=1

for k in range(1,n):
    print(d[k])

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

using namespace std;

#define YES cout << "YES" << endl;
#define NO  cout << "NO"  << endl;
#define Yes cout << "Yes" << endl;
#define No  cout << "No"  << endl;
 
#define INF INT_MAX
#define MOD 1000000007
#define PI  acos(-1)

using ll  = long long;
using ull = unsigned long long;
using Pii = pair<int, int>;
using Pll = pair<ll, ll>;

#define rep(i, n) for (ll i = 0; i < (n); i++)
#define rrep(i, n) for (ll i = (n)-1; i >= 0; i--)

int main(int argc, char *argv[])
{
    cin.tie(0);
    ios::sync_with_stdio(false);

    ll n, m;
    cin >> n >> m;

    vector<ll> x(n);
    rep (i, n) {
        cin >> x[i];
    }

    vector<ll> y(m);
    rep (i, m) {
        cin >> y[i];
    }

    ll xsum = 0;
    rep (i, n-1) {
        ll j = i+1;
        xsum += (x[j]-x[i])%MOD*(i+1)%MOD*(n-j)%MOD;
        xsum %= MOD;
    }

    ll ysum = 0;
    rep (i, m-1) {
        ll j = i+1;
        ysum += (y[j]-y[i])%MOD*(i+1)%MOD*(m-j)%MOD;
        ysum %= MOD;
    }

    cout << xsum%MOD*ysum%MOD << endl;
    return 0;
}

Measured memory_bytes: 1792
#include <algorithm>
#include <cassert>
#include <cfloat>
#include <climits>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <deque>
#include <iostream>
#include <iterator>
#include <limits>
#include <map>
#include <numeric>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <string>
#include <tuple>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>

#define FOR(i,k,n) for(int(i)=(k);(i)<(n);++(i))
#define rep(i,n) FOR(i,0,n)
#define all(v) begin(v),end(v)
#define debug(x) std::cerr<<#x<<": "<<x<<"\n"
#define debug2(x,y) std::cerr<<#x<<": "<<x<<", "<<#y<<": "<<y<<"\n"
#define debug3(x,y,z) std::cerr<<#x<<": "<<x<<", "<<#y<<": "<<y<<", "<<#z<<": "<<z<<"\n"

using ll=long long;
using vi=std::vector<int>;
using vvi=std::vector<vi>;
using vll=std::vector<ll>;
using vvll=std::vector<vll>;
template<typename T> using vvec=std::vector<std::vector<T>>;
template<typename T>
auto make_v(size_t sz){return std::vector<T>(sz);}
template<typename T,typename... Ts>
auto make_v(size_t sz,Ts...ts){return std::vector<decltype(make_v<T>(ts...))>(sz,make_v<T>(ts...));}
template<typename T>
void fill_v(T&var,const T&x){var=x;}
template<typename V,typename T>
void fill_v(V&v,const T&x){for(auto&& w:v){fill_v(w,x);}}

template<typename T> std::ostream& operator<<(std::ostream&s,const std::vector<T>&v){
  int sz=v.size();s<<"\n";rep(i,sz){s<<v[i];if(i<sz-1){s<<"\t";}}s<<"\n";return s;}
template<typename T> std::ostream& operator<<(std::ostream&s,const std::vector<std::vector<T>>&v){
  for(auto&& w:v){s<<w;}return s;}
template<typename T> std::ostream& operator<<(std::ostream&s,const std::deque<T>&v){
  int sz=v.size();s<<"\n";rep(i,sz){s<<v[i];if(i<sz-1){s<<"\t";}}s<<"\n";return s;}
template<typename T> std::ostream& operator<<(std::ostream&s,const std::deque<std::deque<T>>&v){
  for(auto&& w:v){s<<w;}return s;}
template<typename T> std::ostream& operator<<(std::ostream&s, const std::set<T>&v){
  s<<"\n";for(auto&& elm:v){s<<elm<<"\t";}s<<"\n";return s;}

inline void scan(int&a){scanf("%d",&a);}
inline void scan(ll&a){scanf("%lld",&a);}
inline void scan(char&a){scanf(" %c",&a);}
inline void scan(double&a){scanf("%lf",&a);}
template<typename T>
inline void scan(std::vector<T>&v){for(auto&& sv:v){scan(sv);}}
template<typename First,typename...Args>
inline void scan(First&f,Args&...args){scan(f);scan(args...);}
inline void scan(std::string&s){char BUF[3000000];scanf(" %s",BUF);s=std::string(BUF);}
inline void print(int a){printf("%d\n",a);}
inline void print(ll a){printf("%lld\n",a);}
inline void print(double a){printf("%.12f\n",a);}
inline void print(std::string s){std::cout<<s<<"\n";}

using namespace std;

int main() {
  int n;
  scan(n);
  vvi f(n, vi(10));
  scan(f);
  vvll p(n, vll(11));
  scan(p);

  ll ans = LLONG_MIN;
  FOR (i, 1, (1 << 10)) {
    ll profit = 0;
    rep (j, n) {
      int cnt = 0;
      rep (k, 10) {
        if (((i >> k) & 1) && f[j][k] == 1) {
          cnt += 1;
        }
      }
      profit += p[j][cnt];
    }
    ans = max(ans, profit);
  }
  print(ans);

  return 0;
}


Measured memory_bytes: 256
#include <vector>
#include <iostream>
using namespace std;
int main() {
	int N, K, M;
	cin >> N >> K >> M;
	vector<vector<int> > comb(N);
	for (int i = 0; i < N; ++i) {
		comb[i].resize(i + 1);
		comb[i][0] = 1;
		for (int j = 1; j <= i; ++j) {
			comb[i][j] = comb[i - 1][j - 1];
			if (j != i) comb[i][j] = (comb[i][j] + comb[i - 1][j]) % M;
		}
	}
	vector<vector<int> > dp(N + 1, vector<int>(K + 1));
	vector<vector<int> > sum(N + 1, vector<int>(K + 2));
	for (int i = 0; i <= K; ++i) {
		dp[0][i] = 1;
		sum[0][i] = K - i + 1;
	}
	for (int i = 1; i <= N; ++i) {
		for (int j = 0; j <= K; ++j) {
			for (int k = 0; k <= i - 1; ++k) {
				int sub = (long long)(sum[k][j + 1]) * dp[(i - 1) - k][j] % M * comb[i - 1][k] % M;
				dp[i][j] = (dp[i][j] + sub) % M;
			}
		}
		for (int j = K; j >= 0; --j) {
			sum[i][j] = (sum[i][j + 1] + dp[i][j]) % M;
		}
	}
	cout << dp[N][0] << endl;
	return 0;
}

Measured memory_bytes: 1152
while True:
    m, f, r = map(int, input().split())
    if m == -1 and f == -1 and r == -1:
        break
    elif m == -1 or f == -1:
        print('F')
    elif m + f >= 80:
        print('A')
    elif m + f >= 65:
        print('B')
    elif m + f >= 50 or r >= 50:
        print('C')
    elif m + f >= 30:
        print('D')
    else:
        print('F')


Measured memory_bytes: 5596
#include <iostream>
#include <cstring>
#include <cstdio>
using namespace std;
int main()
{
	char a[10];
	cin>>a;
	int l=strlen(a);
	if(l==2)
		cout<<a[0]<<a[1];
	else
		cout<<a[2]<<a[1]<<a[0];
	return 0;		
}

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


#define MOD 1000000007
#define INF 1001001001
#define MIN -1001001001
#define rep(i,k,N) for(int i=k;i<N;i++)
#define MP make_pair
#define MT make_tuple //tie,make_tuple は別物
#define PB push_back
#define PF push_front
#define all(x) (x).begin(),(x).end()


using namespace std;
typedef long long ll;
typedef vector<ll> v;
typedef vector<vector<ll>> vv;

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

int main(){
    ll N,M;
    cin>>N>>M;
    map<ll,bool> m;
    ll las = N;
    ll cnt = 0;
    rep(i,0,M){
        if(las < i)break;
        while(m[las-(i+1)-1] || m[N-2-las+(i+1)+1]){
            las--;
        }
        if(las < i)break;
        m[las-(i+1)-1] = true;
        m[N-2-las+(i+1)+1] = true;
        cnt++;
        las--;
    }
    if(cnt>=M){
        las = N;
        m.clear();
        rep(i,0,M){
        if(las < i)break;
        while(m[las-(i+1)-1] || m[N-2-las+(i+1)+1] || las-(i+1)-1 == N-2-las+(i+1)+1){
            las--;
        }
        if(las < i)break;
        m[las-(i+1)-1] = true;
        m[N-2-las+(i+1)+1] = true;
        cout<<i+1<<" "<<las<<endl;
        las--;
    }
    }
    else{
        las = N-1;
        m.clear();
        rep(i,0,M){
        if(las < i)break;
        while(m[las-(i+1)-1] || m[N-2-las+(i+1)+1]){
            las--;
        }
        if(las < i)break;
        m[las-(i+1)-1] = true;
        m[N-2-las+(i+1)+1] = true;
        cout<<i+1<<" "<<las<<endl;
        las--;
    }
    }
    return 0;
}

Measured memory_bytes: 14756
using System;
using System.Globalization;
using System.IO.Pipes;
using System.Runtime.InteropServices;

namespace ConsoleApp2
{
    class Program
    {
        static void Main(string[] args)
        {
            string[] str = Console.ReadLine().Split(' ');
            int n, i;
            n = int.Parse(str[0]);
            i = int.Parse(str[1]);

            Console.WriteLine(n - i + 1);
        }

    }
}


Measured memory_bytes: 27440
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define PI 3.141592653589793
#define rep(i, n) for (int i = 0; i < (n); i++)
#define rrep(i, n, k) for (int i = (n); i >= (k); i--);
#define all(x) (x).begin(), (x).end()
template<class T> istream &operator>>(istream&is,vector<T>&v){for(auto &elemnt:v)is>>elemnt;return is;}
template<class T,class U> istream &operator>>(istream&is,pair<T,U>&p){is>>p.first>>p.second;return is;}
template<class T>vector<T> make_vector(size_t a){return vector<T>(a);}
template<class T, class... Ts>auto make_vector(size_t a, Ts... ts){return vector<decltype(make_vector<T>(ts...))>(a, make_vector<T>(ts...));}
const int inf = 2e17;
const int mod = 1e9 + 7;

signed main() {
    int A, B;
    cin >> A >> B;
    cout << (500 * A >= B ? "Yes" : "No") << endl;
}


Measured memory_bytes: 764
#include <iostream>
#define REP(i, a, n) for(int i = ((int) a); i < ((int) n); i++)
#define INF 100000000000000000LL
using namespace std;
typedef long long ll;

int N, M, A[100010];
ll s[100010], p[100010], q[100010];

int main(void) {
  cin >> N >> M;
  REP(i, 0, N) cin >> A[i], A[i]--;

  s[0] = 0;
  REP(i, 0, N - 1) {
    if(A[i] > A[i + 1] && A[i] != 0) s[0] += A[i + 1] + 1;
    else s[0] += (A[i + 1] - A[i] + M) % M;
  }

  REP(i, 0, N) p[i] = 0;
  REP(i, 0, N - 1) p[A[i + 1]] += (A[i + 1] - A[i] - 1 + M) % M;

  REP(i, 0, M) q[i] = 0;
  REP(i, 0, N - 1) {
    if(A[i] < A[i + 1]) {
      q[A[i] + 1]++;
      q[A[i + 1]]--;
    } else {
      q[A[i] + 1]++;
      q[M]--;
      q[0]++;
      q[A[i + 1]]--;
    }
  }
  REP(i, 0, M) q[i + 1] += q[i];

  REP(i, 0, M - 1) s[i + 1] = s[i] + p[i] - q[i];

  ll ans = INF;
  REP(i, 0, M) ans = min(ans, s[i]);
  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 2944
import sys
def input(): return sys.stdin.readline().rstrip()

def main():
    n = int(input())
    a, b, c = [tuple(map(int, input().split())) for i in range(3)]
    ans = 0
    a_bef = -2

    for i in a:
        ans += b[i-1]
        if a_bef + 1 == i:
            ans += c[a_bef-1]
        a_bef = i
    print(ans)

if __name__ == '__main__':
    main()


Measured memory_bytes: 3060
#include <iostream>
#include <string>
#include <algorithm>
#include <cstdio>
#include <vector>
#include <queue>
#include <set>
#include <numeric>
#include <cmath>

using namespace std;

typedef long long int ll;

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

const ll mod = 1e9+7;
const ll INF = 1e9;
const ll MAXN = 1e9;



struct BIT{
    ll N;
    vector<ll> bit;
    BIT(ll N) : bit(N+1),N(N){};

    ll sum(ll i){
        ll s = 0;
        while(i>0){
           s += bit[i];
           i -= i & -i;
        }
        return s;
    }

    void add(ll i,ll x){
        while(i <= N){
            bit[i] += x;
            i += i & -i;
        }
    }
};


vector<ll> convert_array(vector<ll> a){
    vector<ll> temp = a;
    sort(all(temp));
    for(ll i = 0; i < a.size(); i++){
        a[i] = lower_bound(all(temp), a[i]) - temp.begin() + 1;
    }
    return a;
}

ll inverse_number(vector<ll> z){
    ll n = z.size();
    ll inv_num = 0;
    z = convert_array(z);


    // for(ll i = 0; i < n; i++){
    //     cout << z[i] << " ";
    // }prllf("\n");


    BIT b(n);
    for(ll i = 0; i <= n; i++){
        b.bit[i] = 0;
    }

    for(ll i = 0; i < n; i++){
        inv_num += i - b.sum(z[i]);
        b.add(z[i],1);
    }

    return inv_num;
}

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

    a = convert_array(a);

    // for(ll i = 0; i < n; i++){
    //   cout << a[i] << " ";
    // }prllf("\n");

    cout << inverse_number(a) << endl;

  return 0;
}


Measured memory_bytes: 10564
import java.util.*;
public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int L = sc.nextInt();//日数
		int A = sc.nextInt();//国語のページ数
		int B = sc.nextInt();//算数のページ数
		int C = sc.nextInt();//国語の最大進行ページ
		int D = sc.nextInt();//算数の最大進行ページ
		int need1 = 0;
		int need2 = 0;
		if(A%C!=0){
			need1 += A/C+1;
		}else{
			need1 += A/C;
		}
		if(B%D!=0){
			need2 += B/D+1;
		}else{
			need2 += B/D;
		}
		if(need1>need2){
			System.out.println(L-need1);			
		}else{
			System.out.println(L-need2);
		}
	}
}

Measured memory_bytes: 17160