akhauriyash/Code-Regression huggingface dataset:
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cctype>
#include <cmath>
#include <algorithm>
#include <cassert>
#define rep(i, a, b) for (int i = (a), _ = (b); i <= _; ++ i)
#define per(i, a, b) for (int i = (a), _ = (b); i >= _; -- i)
#define For(i, a, b) for (int i = (a), _ = (b); i < _; ++ i)
#define fore(e, u, v) for (int p = e(u), v = e[p].y; p; v = e[p = e[p].nxt].y)
#define ri rd<int>
using namespace std;
const int maxN = 2e5 + 7;

template<class T> inline T rd() {
	bool f = 1; char c = getchar(); for (; !isdigit(c); c = getchar()) if (c == '-') f = 0;
	T x = 0; for (; isdigit(c); c = getchar()) x = x * 10 + c - 48; return f ? x : -x;
}

inline void NIE() {puts("IMPOSSIBLE"); exit(0);}
inline void TAK() {puts("POSSIBLE"); exit(0);}

int n;
int bac[maxN], deg[maxN];
int val[maxN][2];
int lop[maxN], tl, vis[maxN];
bool f[maxN][2];
int v[maxN][2];

struct vec {
	static const int maxE = maxN;
	int g[maxN], te;
	struct edge {int y, nxt;} e[maxE << 1];
	inline void push(int x, int y) {e[++te] = (edge){y, g[x]}; g[x] = te;}
	inline void link(int x, int y) {push(x, y), push(y, x);}
	inline int& operator () (int x) {return g[x];}
	inline edge& operator [] (int x) {return e[x];}
}e;

void topu() {
	static int q[maxN]; int h = 0, t = 0;
	rep (i, 1, n) if (deg[i] == 0) q[++t] = i;
	while (h != t) {
		int x = q[++h], y = bac[x];
		if (--deg[y] == 0) q[++t] = y;
	}
	rep (i, 1, n) if (deg[i]) {
		lop[tl = 1] = i;
		for (int x = bac[i]; x != i; x = bac[x]) lop[++tl] = x;
		rep (i, 1, tl) vis[lop[i]] = 1;
		break;
	}
}

void dfs(int x, int fa) {
	static int q[maxN];
	fore (e, x, y) if (y != fa && !vis[y]) {
		dfs(y, x);
	}
	int tq = 0; fore (e, x, y) if (y != fa && !vis[y]) q[++tq] = val[y][0];
	sort(q+1, q+tq+1);
	tq = unique(q+1, q+tq+1) - (q+1);

	for (int cur = 0, i = 1; ; ++ cur) {
		if (i <= tq && q[i] == cur) {++ i; continue;}
		if (val[x][0] == -1) val[x][0] = cur;
		else if (val[x][1] == -1) {val[x][1] = cur; break;}
	}
}

bool ok(int x, int y, int kd) {
	if (kd == 1) {
		if (v[x][0] == v[y][0] && f[x][0]) return 1;
		if (v[x][1] == v[y][0] && f[x][1]) return 1;
	}
	else {
		if (v[x][0] != v[y][0] && f[x][0]) return 1;
		if (v[x][1] != v[y][0] && f[x][1]) return 1;
	}
	return 0;
}

int main() {

	n = ri();
	memset(val, -1, sizeof val);
	rep (i, 1, n) {
		int x = ri();
		e.push(x, i);
		bac[i] = x;
		deg[x]++;
	}
	topu();
	rep (i, 1, tl) dfs(lop[i], 0);
	rep (i, 1, tl) v[i][0] = val[lop[i]][0], v[i][1] = val[lop[i]][1];

	f[1][0] = 1, f[1][1] = 0;
	rep (i, 2, tl) {
		f[i][0] = ok(i-1, i, 0);
		f[i][1] = ok(i-1, i, 1);
	}
	if (ok(tl, 1, 0)) TAK();

	f[1][0] = 0, f[1][1] = 1;
	rep (i, 2, tl) {
		f[i][0] = ok(i-1, i, 0);
		f[i][1] = ok(i-1, i, 1);
	}
	ok(tl, 1, 1) ? TAK() : NIE();

	return 0;
}

Measured memory_bytes: 11392
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
using vi = vector<int>;
using vvi = vector<vi>;
using vvvi = vector<vvi>;
using vll = vector<ll>;
using vvll = vector<vll>;
using vvvll = vector<vvll>;
using vs = vector<string>;
using pll = pair<ll, ll>;
using vp = vector<pll>;
template<class T> using V = vector<T>;
template<class T> using VV = vector<vector<T> >;
#define rep(i, n) for(ll i = 0; i < (n); i++)
#define repb(i, n) for(ll i = (n)-1; i >= 0; i--)
#define repr(i, a, b) for(ll i = (a); i < (b); i++)
#define reprb(i, a, b) for(ll i = (a)-1; i >= (b); i--)
#define ALL(a) (a).begin(), (a).end()
#define SZ(x) ((ll)(x).size())
const ll MOD = 1000000007;
const ll INF = 100000000000000000LL;
inline ll GCD(ll a, ll b){ return b?GCD(b, a % b):a; }
inline ll LCM(ll a, ll b){ return a/GCD(a, b)*b; }
inline ll powint(unsigned long long x, ll y){ ll r=1; while(y){ if(y&1) r*=x; x*=x; y>>=1; } return r; }
inline ll powmod(ll x, ll y, ll m = MOD){ ll r=1; while(y){ if(y&1) r*=x; x*=x; r%=m; x%=m; y>>=1; } return r; }
template<class S, class T>inline bool chmax(S &a, const T &b){ if(a<b) { a=b; return 1; } return 0; }
template<class S, class T>inline bool chmin(S &a, const T &b){ if(b<a) { a=b; return 1; } return 0; }
#ifdef OJ_LOCAL
#include "dump.hpp"
#else
#define dump(...) ((void)0)
#endif

void pr(){
    cout << -1 << endl;
    exit(0);
}

vll a;

// Antsbook p.132
// minimum x (C(x) == true)
bool C(ll d, ll x, ll i){
    return x/a[i] != d/a[i];
}

ll BinarySearchMin(ll lb, ll ub, ll i){
    ll lb_ = lb;
    // 返り値の範囲：(lb, ub]
    // 条件：
    //   (lb, ub]で検証できること
    //   C(lb)==false, C(ub)==true
    while(ub - lb > 1){
        ll mid = ((lb + ub) >> 1);
        if(C(mid, lb_, i)){
            // (lb, mid]
            ub = mid;
        }else{
            // (mid, ub]
            lb = mid;
        }
    }
    return ub;
}

// Antsbook p.132
// maximum x (C(x) == true)
bool C2(ll d, ll x, ll i){
    return x/a[i] == d/a[i];
}

ll BinarySearchMin2(ll lb, ll ub, ll i){
    ll ub_ = ub;
    // 返り値の範囲：(lb, ub]
    // 条件：
    //   (lb, ub]で検証できること
    //   C(lb)==false, C(ub)==true
    while(ub - lb > 1){
        ll mid = ((lb + ub) >> 1);
        if(C2(mid, ub_, i)){
            // (lb, mid]
            ub = mid;
        }else{
            // (mid, ub]
            lb = mid;
        }
    }
    return ub;
}


int main(){
    cin.tie(0); ios::sync_with_stdio(false);
    cout << fixed << setprecision(15);
    ll k;
    cin >> k;
    a.resize(k);
    rep(i, k){
        cin >> a[i];
    }
    if(a[k-1] != 2) pr();
    ll lb = 2, ub = 3; // [2, 3]
    repb(i, k){
        if((lb-1)/a[i] == ub/a[i]) pr();
        // 倍数の探索
        ll minm = BinarySearchMin(lb-1, ub, i);
        ll maxm = BinarySearchMin2(lb-1, ub, i);
        lb = minm, ub = maxm+a[i]-1;
    }
    cout << lb << " " << ub << endl;
    return 0;
}

Measured memory_bytes: 1024
#include <iostream>

using namespace std;

int main() {
  int a, b, c;
  cin >> a >> b >> c;
  if ((a == b && b == c) || (a != b && b != c && a != c)) {
    cout << "No" << endl;
  } else {
    cout << "Yes" << endl;
  }
  return 0;
}


Measured memory_bytes: 256
import java.util.Scanner;

public class Main{
	public static void main(String args[]){

		Scanner sc = new Scanner(System.in);
		int intA = sc.nextInt();
		int intB = sc.nextInt();

		if(intA < intB){
			System.out.println("a < b");
		}else if(intA > intB){
			System.out.println("a > b");
		}else{
			System.out.println("a == b");
		}
	}
}

Measured memory_bytes: 26052
#include <cstdio>
#define NIL -1
#define MAX 10000

struct Node {
    int parent, left, right;
};

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

void setDepth(int u, int d) {
    if(u==NIL) return;
    D[u] = d;
    setDepth(T[u].left, d+1);
    setDepth(T[u].right, d+1);
}

int setHeight(int u) {
    int h1=0, h2=0;
    if(T[u].left != NIL)  h1 = setHeight(T[u].left) + 1;
    if(T[u].right != NIL) h2 = setHeight(T[u].right) + 1;
    
    return H[u] = (h1 > h2 ? h1 : h2);
}

int getSibling(int u) {
    if(T[u].parent == NIL) return NIL;
    if(T[T[u].parent].left != u && T[T[u].parent].left != NIL)
        return T[T[u].parent].left;
    if(T[T[u].parent].right != u && T[T[u].parent].right != NIL)
        return T[T[u].parent].right;
    return NIL;
}

/*
node 0: parent = -1, sibling = -1, degree = 2, depth = 0, height = 3, root
node 1: parent = 0, sibling = 4, degree = 2, depth = 1, height = 1, internal node
node 2: parent = 1, sibling = 3, degree = 0, depth = 2, height = 0, leaf
*/

void print(int u) {
    printf("node %d: ", u);
    printf("parent = %d, ", T[u].parent);
    printf("sibling = %d, ", getSibling(u));
    int deg = 0;
    if(T[u].left != NIL) deg++;
    if(T[u].right != NIL) deg++;
    printf("degree = %d, ", deg);
    printf("depth = %d, ", D[u]);
    printf("height = %d, ", H[u]);
    
    if(T[u].parent == NIL) {
        printf("root\n");
    }else if(T[u].left == NIL && T[u].right == NIL) {
        printf("leaf\n");
    }else{
        printf("internal node\n");
    }
}

int main() {
    int v, l, r, root=0;
    scanf("%d", &n);
    
    for (int i=0; i<n; i++) T[i].parent = NIL;
    
    for (int i=0; i<n; i++) {
        scanf("%d %d %d", &v, &l, &r);
        T[v].left = l;
        T[v].right = r;
        if (l != NIL) T[l].parent = v;
        if (r != NIL) T[r].parent = v;
    }
    
    for (int i=0; i<n; i++) if(T[i].parent == NIL) root = i;
    
    setDepth(root, 0);
    setHeight(root);
    
    for (int i=0; i<n; i++) print(i);
    
    return 0;
}


Measured memory_bytes: 2752
#include <iostream>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <vector>
#include <stack>
#include <queue>
#include <deque>
#include <algorithm>
#include <numeric>
#include <functional>
#include <map>
#include <set>
#define Rep(i, n) for(int i=0;i<n;++i)
#define rep(i, n) for(int i=1;i<=n;++i)
#define ll long long int
#define INF 100000000
#define INFLL 100000000000
#define MOD 1000000007
#define PI 3.14159265359
#define All(a) (a).begin(), (a).end()

using namespace std;
using P = pair<ll, ll>;
 
int dx[4] = {0, 1, 0, -1};
int dy[4] = {1, 0, -1, 0};

struct Edge {
  int to;     
  ll weight; 
  Edge(int t, ll w) : to(t), weight(w) { }
};



int N;
ll a[310000];

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

  ll ans = 0;

  Rep(k, 63) {
    ll mask = 1LL << k;

    ll one_num = 0;
    ll zero_num = 0;

    rep(i, N) {
      if (a[i] & mask) {
        one_num += 1;
      } else {
        zero_num += 1;
      }
    }

    ll tmp = one_num * zero_num;
    tmp %= MOD;

    //cout << tmp << "\n";

    for (int i=1;i<=k;++i) {
      tmp *= 2;
      tmp %= MOD;
    }

    ans += tmp;
    ans %= MOD;

  }

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

Measured memory_bytes: 2560
#include <stdio.h>

int getroman()
{
     char ch = getchar();
     
     switch(ch){
     case 'I': return 1;
     case 'V': return 5;
     case 'X': return 10;
     case 'L': return 50;
     case 'C': return 100;
     case 'D': return 500;
     case 'M': return 1000;
     default : return EOF;
     }
}

int main(void)
{
     int x, t, u;
     char ch;
     
     while(0<1){
	  x = 0;
	  u = 0;

	  while(0<1){
	       t = getroman();
	       if(t==EOF) break;

	       if(u>=t){
		    x = x + t;
		    u = t;
	       }
	       else if(u < t){
		    t = t - u - u;
		    u = t;
		    x = x + t;
	       }
	  }
	  
	  printf("%d\n", x);

	  if(scanf("%c",&ch) == EOF) break;
	  else ungetc(ch, stdin);
     }

     return 0;
}

Measured memory_bytes: 548
#include<iostream>
using namespace std;
int main(){
    int N,K;
    cin>>N>>K;
    int x=(N-1)/(K-1)+1;
    int y=(N%K)+1;
    int z=(N-1)/(K-1);
    if(N==K){cout<<y<<endl;}
    else if(N!=K&&(N-1)%(K-1)==0){cout<<z<<endl;}
    else{cout<<x<<endl;}
    return 0;
}
    

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

const int MAXN = (int)2e5;

int a[MAXN];

int64_t solve(int n) {
  std::map<int, int> count;
  int64_t ans = 0;
  for (int i = 0; i < n; ++i) {
    if (count.count(i - a[i])) {
      ans += count[i - a[i]];
    }
    ++count[i + a[i]];
  }
  return ans;
}

int main() {
  int n;
  std::cin >> n;
  for (int i = 0; i < n; ++i) std::cin >> a[i];
  std::cout << solve(n) << std::endl;
  return 0;
}


Measured memory_bytes: 13640
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.Arrays;
import java.io.IOException;

class Main{
    public static void main(String[] args) throws IOException{
        int arr[] = new int[10];
		if(args.length == 0) {
			BufferedReader br = new BufferedReader(new    InputStreamReader(System.in));
	         
	        for(int i=0;i<10;i++){
	            arr[i] = Integer.parseInt(br.readLine());
	        }
	         
	        Arrays.sort(arr);
	         
	        for(int i=9;i > 6;i--){
	            System.out.println(arr[i]);
	        }
		}
		else {
		for(int i=0;i<10;i++) {
			for(int j=0;j<=i;j++) {
				int height1 = Integer.parseInt(args[i]);
				int height2 = Integer.parseInt(args[j]);
				if(height1>height2) {
					String temp = args[i];
					args[i] = args[j];
					args[j] = temp;
				}
			}
			
		}
		for(int i=0;i<3;i++)
			System.out.println(args[i]);
		}
    }
}

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

int main() {
    int n;cin>>n;
    string s;cin>>s;
    int ans = 0;
    for (int i = 0; i < n - 1; i++)
        if (s[i] != s[i+1]) {
            ans++;
            i++;
        }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 3332
#include<bits/stdc++.h>
using namespace std;
#define rep(i,j,k) for(int i = j;i <= k;++i)
#define repp(i,j,k) for(int i = j;i >= k;--i)
#define rept(i,x) for(int i = linkk[x];i;i = e[i].n)
#define P pair<int,int>
#define Pil pair<int,ll>
#define Pli pair<ll,int>
#define Pll pair<ll,ll>
#define pb push_back 
#define pc putchar
#define mp make_pair
#define file(k) memset(k,0,sizeof(k))
#define ll long long
int rd()
{
    int sum = 0;char c = getchar();bool flag = true;
    while(c < '0' || c > '9') {if(c == '-') flag = false;c = getchar();}
    while(c >= '0' && c <= '9') sum = sum * 10 + c - 48,c = getchar();
    if(flag) return sum;
    else return -sum;
}
int main()
{
	int a = rd(),b = rd();
	if(a <= 0 && b >= 0) printf("Zero");
	else if(a>0 && b>0) printf("Positive");
	else if(a<0 && b<0) ((b-a)%2)?printf("Positive"):printf("Negative");
    return 0;
}


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


using namespace std;

typedef long long int ll;

int main(){
	int n,m;
	ll k;
	cin >> n >> m >> k;
	vector<ll> a(n), b(m);
	for(int i = 0; i < n; i++){
		cin >> a[i];
		if(i!=0) a[i] += a[i-1];
	}
	for(int i = 0; i < m; i++){
		cin >> b[i];
		if(i!=0) b[i] += b[i-1];
	}
	int ans = 0;
	for(int i = 0; i < n; i++){
		ll rem = k - a[i];
		if(rem < 0) break;
		int can = upper_bound(b.begin(),b.end(),rem) - b.begin();
		ans = max(ans,can + i + 1);
	}
	for(int i = 0; i < m; i++){
		ll rem = k - b[i];
		if(rem < 0) break;
		int can = upper_bound(a.begin(),a.end(),rem) - a.begin();
		ans = max(ans,can + i + 1);
	}
	
	
	
	cout << ans << "\n";
	return 0;
}


Measured memory_bytes: 6420
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0; i<(int)(n); i++)
#define INF = numeric_limits<long long>::max();
#define intf int_fast64_t

int main(){
    long long sum = 100;
    int year = 0;
    long long  x; 
    cin >> x;
    while (sum < x){
        sum *= 1.01;
      	sum = floor(sum);
        year++;
    }
    cout << year << endl;
}

Measured memory_bytes: 3592
#include <iostream>
using namespace std;
 
int main()
{
  long num;
  cin >> num;
 
  long * a = new long[num];
  for (long i = 0; i < num; i++)
    cin >> a[i];
 
  long min = a[0];
  for (long i = 0; i < num; i++)
    if (a[i] < min) min = a[i];
 
  long max = a[0];
  for (long i = 0; i < num; i++)
    if (a[i] > max) max = a[i];
 
  long sum = 0;
  for (long i = 0; i < num; i++)
    sum += a[i];
 
  cout << min << " " << max << " " << sum << endl;
 
  delete[] a;
  return 0;
}

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

using namespace std;

typedef long long int ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;

#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define rep2(i,n) for(int i=1;i<=(int)(n);i++)
#define rep3(i,n) for(int i=0;i<=(int)(n);i++)
#define REP(i,m,n) for(int i=m;i<(int)(n);i++)
#define repll(i,n) for(ll i=0;i<(ll)(n);i++)
#define repll2(i,n) for(ll i=1;i<=(ll)(n);i++)
#define REPLL(i,m,n) for(ll i=m;i<(ll)(n);i++)
#define INF (int)1e9  //
#define LINF (ll)4e18  //
#define MOD (int)(1e9)+7
#define MP make_pair
#define YES(n) cout << ((n) ? "YES" : "NO"  ) << endl
#define Yes(n) cout << ((n) ? "Yes" : "No"  ) << endl
#define yes(n) cout << ((n) ? "yes" : "no"  ) << endl
#define PI 3.1415926535898

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

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



Measured memory_bytes: 256
#include <iostream>
#include <math.h>
#include <string.h>

int main (){
	char aho[105];
	scanf("%s", aho);
	int N = int(strlen(aho));
	char* ans = (char*)"Yes";
	for (int i=0; i<N; i++){
		if (i%2==0){
			if (aho[i]=='L'){
				ans = (char*)"No";
			}
		} else {
			if (aho[i]=='R'){
				ans = (char*)"No";
			}
		}
	}
	printf("%s\n", ans);
	return 0;
}

Measured memory_bytes: 888
import sys
sys.setrecursionlimit(100000000)
def input():
    return sys.stdin.readline()[:-1]
from bisect import *
from collections import *
from heapq import *
from math import *
from copy import *

N, A, B, C, D = map(lambda x: int(x)-1, input().split())
S = input()
if "##" in S[A:C] or "##" in S[B:D]:
    print('No')
    exit()
if C < D:
    print('Yes')
else:
    if "..." in S[B-1:D+2]:
        print('Yes')
    else:
        print('No')


Measured memory_bytes: 41072
#include <bits/stdc++.h>
using namespace std;
typedef long long LL;
typedef pair<LL, LL> PII;

// chmax, chmin
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 T>
function<T(T, T)> op_max = [](T a, T b) -> T { return max(a, b); };
template <typename T>
function<T(T, T)> op_min = [](T a, T b) -> T { return min(a, b); };

template <typename T>
function<T(T, T)> op_sum = [](T a, T b) -> T { return a + b; };

namespace detail
{
  template <typename T, std::size_t NDIMS>
  struct vector_builder
  {
    using type = std::vector<typename vector_builder<T, NDIMS - 1>::type>;

    static type make(std::vector<std::size_t> dims, const T &v = {})
    {
      const auto vec = std::vector<T>(dims.empty() ? 0 : dims.back(), v);
      if (!dims.empty())
        dims.pop_back();
      return vector_builder<std::vector<T>, NDIMS - 1>::make(dims, vec);
    }
  };

  template <typename T>
  struct vector_builder<T, 1>
  {
    using type = std::vector<T>;

    static type make(std::vector<std::size_t> dims, const T &v = {})
    {
      return type(dims.empty() ? 0 : dims.back(), v);
    }
  };
} // namespace detail

template <typename T, typename... SIZE_T>
auto exvector(const T &v, SIZE_T... dims)
{
  static_assert(sizeof...(dims) != 0, "invalid dimension");
  std::vector<std::size_t> vec_dims{dims...};
  return detail::vector_builder<T, sizeof...(dims)>::make(vec_dims, v);
}

using namespace std;
//********************  dumps ************************//

template <typename T>
void dump(const T &data, vector<int> &iter)
{
  cout << data << " ";
}
template <typename T>
void dump(const vector<T> &data, vector<int> &iter)
{
  for (auto elem : data)
    dump(elem, iter);
  cout << endl;
}

template <typename T>
void dump(const vector<vector<T>> &data, vector<int> &iter)
{
  for (auto elem : iter)
  {
    cout << "[" << elem << "]";
  }
  cout << endl;
  for (int i = 0; i < data.size(); i++)
  {
    iter.push_back(i);
    dump(data[i], iter);
    iter.pop_back();
  }
  cout << endl;
}

template <typename T>
void dump(const vector<T> &data, int dummy)
{
  for (int i = 0; i < data.size(); i++)
  {
    cout << "[" << i << "] " << data[i] << endl;
  }
}
template <typename T>
void dump(const T &data)
{ // T : data, U = base type val.
  vector<int> iter;
  dump(data, iter);
}
///////////////////////////////////////////////

void solve(long long N, long long X, long long Y)
{

  X--;
  Y--;
  vector<int> count(N, 0);
  for (int i = 0; i < N; i++)
    for (int j = i + 1; j < N; j++)
    {
      LL a = abs(i - X) + 1 + abs(j - Y);
      LL b = abs(i - Y) + 1 + abs(j - X);
      LL c = abs(i - j);
      LL index = min(min(a, b), c);
      count[min(a, min(b, c))]++;
    }
  for (int i = 1; i < N; i++)
    cout << count[i] << endl;
}

int main()
{
  cout << setprecision(10);
  long long N;
  scanf("%lld", &N);
  long long X;
  scanf("%lld", &X);
  long long Y;
  scanf("%lld", &Y);
  solve(N, X, Y);
  return 0;
}


Measured memory_bytes: 3664
//header{{{
#include<bits/stdc++.h>
  
using namespace std;
 
#define rep(i,n) for(int i=0;i<(n);++i)
#define reps(i,n) for(int i=1;i<=(n);++i)
#define all(x) (x).begin(),(x).end()
#define Fixed fixed << setprecision(12)
#define int int64_t
using pii = pair<int,int>;
constexpr int INF  = 0x3f3f3f3f;
constexpr long long LINF = 0x3f3f3f3f3f3f3f3fLL;
constexpr int mod = 1e9+7; 
constexpr int MOD = 998244353;

template <class A, class B> inline bool chmax(A &a, const B &b) { return b > a && (a = b, true); }
template <class A, class B> inline bool chmin(A &a, const B &b) { return b < a && (a = b, true); }

template <class T> using min_heap = priority_queue<T,vector<T>,greater<T> >;
template <class T> using max_heap = priority_queue<T>;
template <class A, class B> using umap = unordered_map<A,B>;
  
int gcd(int a,int b){ return b ? gcd(b,a % b) : a;}
int lcm(int a,int b){ return a / gcd(a,b) * b;}

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

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

    int n,k;
    cin >> n >> k;
    vector<int> v(n);

    rep(i,n){
        cin >> v[i];
    }

    int maxv = 0;

    for(int i = 0;i <= min(n,k);++i){
        for(int j = 0;j <= i;++j){
            vector<int> tmp;
            int sum = 0;
            for(int l = 0;l < j;++l){
                tmp.emplace_back(v[l]);
                sum += v[l];
            }
            for(int l = 1;l <= i-j;++l){
                tmp.emplace_back(v[n-l]);
                sum += v[n-l];
            }
            sort(all(tmp));
            for(int l = 0;l < min(k-i,int(tmp.size()));++l){
                chmax(sum,sum-tmp[l]);
            }
            chmax(maxv,sum);
        }
    }

    cout << maxv << '\n';

    return 0;
}


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

#define rep(i,n) for(int i=0;i<n;i++)
#define repn(i,n) for(int i=1;i<=n;i++)
#define LL long long
#define pii pair <int,int>
#define fi first
#define se second
#define pb push_back
#define mpr make_pair

using namespace std;

const LL MOD=1e9+7;

LL n,ans=0;
vector <int> v;

int main()
{
	cin>>n;
	LL tmp=n;
	for(LL i=2;i*i<=tmp;i++)
	{
		LL nn=0;
		while(n%i==0)
		{
			n/=i;
			nn++;
		}
		if(nn>0) v.pb(nn);
	}
	if(n>1) ans++;
	rep(i,v.size())
	{
		//cout<<i<<' '<<v[i]<<' '<<ans<<endl;
		for(int j=1;v[i]>0;v[i]-=j,j++) if(v[i]-j>=0) ans++;
	}
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 3640
#include<bits/stdc++.h>
using namespace std;
#define ll long long int
int main()
{
    ll n;
    cin>>n;
    unordered_map<string, bool> m;
    ll ans = 0;
    for(ll i=0; i<n; i++)
    {
        string s;
        cin>>s;
        if(m.find(s) == m.end())
        {
            m[s] = true;
            ans++;
        }
    }
    cout<<ans<<'\n';
}

Measured memory_bytes: 17548
#include <bits/stdc++.h>
    #define rep(i,n) for(int i = 0; i < (n); i++)
     
    using namespace std;  
    using ll = long long;
    using P = pair<int,int>; 
    
    
    int main() {
     int a,b,c;
     
     cin >> a >> b >> c;
     
     
     
     
     			cout << c << ' '<< a<< ' '<< b  << '\n';
     			
     
     return 0;
    }

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

int main() {
  int N,M,sum=0;
  cin >> N >> M;
  vector<int> day(M);
  for(int i=0;i<M;i++){
	cin >> day.at(i);
    sum+=day.at(i);
  }
  if(sum<=N){
    cout << N-sum;
  }else{
    cout << -1;
  }
}


Measured memory_bytes: 3596
import math

n = int(input())
x = input().split()
y = input().split()

d1 = d2 = d3 = dinf = 0.0
for i in range(n):
    di = abs(int(x[i]) - int(y[i]))
    d1 += di
    d2 += di ** 2
    d3 += di ** 3
    if di > dinf:
        dinf = di

d2 = math.sqrt(d2)
d3 = math.pow(d3, 1/3)
print(d1, d2, d3, dinf, sep='\n')



Measured memory_bytes: 5696
import java.util.Scanner;

public class Main {
	public static void main(String args[]){
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		boolean tri[] = new boolean[N];
		int a,b,c,x;
		for(int i = 0; i < N; i++){
			a = sc.nextInt();
			b = sc.nextInt();
			c = sc.nextInt();
			if(a < b){
				x = a;
				a = b;
				b = x;
			}
			if(a < c){
				x = a;
				a = c;
				c = x;
			}
			if(a*a == (b*b) + (c*c)){
				tri[i] = true;
			} else {
				tri[i] = false;
			}
		}
		for(int i = 0; i < N; i++){
			if(tri[i] == true){
				System.out.println("YES");
			} else {
				System.out.println("NO");
			}
		}
	}
}

Measured memory_bytes: 34148
#include <iostream>
#include <vector>
#include <algorithm>
#include <cassert>

#define show(x) cerr << #x << " = " << x << endl

using namespace std;
using ll = long long;

template <typename T>
ostream& operator<<(ostream& os, const vector<T>& v)
{
    os << "sz:" << v.size() << "\n[";
    for (const auto& p : v) {
        os << p << ",";
    }
    os << "]\n";
    return os;
}

constexpr ll INF = 1LL << 60;

struct Max {
    using T = ll;
    T operator()(const T& a, const T& b) const
    {
        return max(a, b);
    }
    T inv(const T& a) const
    {
        return -a;  // dame
    }
    static constexpr T identity()
    {
        return -INF;
    }
};
template <typename Base>
class BinaryIndexedTree
{
public:
    using T = typename Base::T;
    using AbelGroup = Base;

    BinaryIndexedTree(const int n) : data_num(n), size(1 << (__lg(2 * data_num - 1))), value(size + 1, AbelGroup::identity()) { assert(n > 0); }
    BinaryIndexedTree(const vector<T>& val) : data_num(val.size()), size(1 << (__lg(2 * data_num - 1))), value(size + 1, AbelGroup::identity())
    {
        for (int i = 1; i <= size; i++) {
            value[i] = val[i - 1];
        }
        for (int x = 1; x < size; x++) {
            value[x + (x & -x)] += value[x];
        }
    }

    T accumulate(const int a) const
    {
        assert(0 <= a and a < data_num);
        int ind = a + 1;
        T sum = AbelGroup::identity();
        while (ind > 0) {
            sum = op(sum, value[ind]);
            ind &= ind - 1;
        }
        return sum;
    }

    void add(const int a, const T& val)
    {
        assert(0 <= a and a < data_num);
        int ind = a + 1;
        while (ind <= size) {
            value[ind] = op(value[ind], val);
            ind += ind & (-ind);
        }
    }

    void set(const int a, const T& val)
    {
        const int v = get(a);
        add(a, op(val, op.inv(v)));
    }

    T get(const int a) const
    {
        assert(0 <= a and a < data_num);
        if (a == 0) {
            return accumulate(a);
        } else {
            return op(op.inv(accumulate(a - 1)), accumulate(a));
        }
    }

    int lowerBound(T w) const
    {
        if (w <= AbelGroup::identity()) {
            return 0;
        }
        int x = 0;
        for (int k = ((size == data_num) ? size : size / 2); k > 0; k /= 2) {
            if (x + k <= size and value[x + k] < w) {
                w = op(w, op.inv(value[x + k]));
                x += k;
            }
        }
        return x;
    }

private:
    const int data_num;
    const int size;
    const AbelGroup op{};
    vector<T> value;
};


int main()
{
    ll n;
    cin >> n;
    vector<ll> a(n + 1, 0);
    for (int i = 1; i <= n; i++) {
        cin >> a[i];
    }
    vector<ll> dp(n + 1, 0);
    BinaryIndexedTree<Max> bit(n + 1);
    for (int i = 0; i <= n; i++) {
        if (i > 0) {
            dp[i] = bit.accumulate(a[i]) + a[i];
        }
        bit.add(a[i], dp[i]);
    }
    const ll maxi = *max_element(dp.begin(), dp.end());
    cout << n * (n + 1) / 2 - maxi << endl;

    return 0;
}

Measured memory_bytes: 5496
#coding:utf-8
n = int(input())
s = input()
x = 0
num = []
num.append(x)

for i in range(n):
    if s[i] == 'I':
        x += 1
    elif s[i] == 'D':
        x -= 1
    num.append(x)

print(max(num))

Measured memory_bytes: 3060
// This file is a "Hello, world!" in C++ language by GCC for wandbox.
#include <iostream>
#include <cstdlib>
#include <algorithm>
using namespace std;
using ll = long long;


ll A[100010], B[100010], C[100010];
int main()
{
    int N; cin >> N;
    for(int i=0; i<N; ++i) cin >> A[i];
    for(int i=0; i<N; ++i) cin >> B[i];
    for(int i=0; i<N; ++i) cin >> C[i];
    
    sort(A, A+N);
    sort(B, B+N);
    sort(C, C+N);
    
    ll ans=0;
    for(int i=0; i<N; ++i){
        ll smaller = lower_bound(A, A+N, B[i])-A;
        ll bigger = (C+N) - upper_bound(C, C+N, B[i]);
        
        ans += smaller*bigger;
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 2560
# import numpy as np  # Pythonのみ！
# from operator import xor
# import re
# from scipy.sparse.csgraph import connected_components  # Pythonのみ！
# ↑cf.  https://note.nkmk.me/python-scipy-connected-components/
# from scipy.sparse import csr_matrix
# import statistics # Pythonのみ
# import string
import sys
sys.setrecursionlimit(10 ** 5 + 10)


def input(): return sys.stdin.readline().strip()


def resolve():

    n = int(input())
    A = list(map(int, input().split()))
    val=0
    ans = 0
    for i in range(len(A)):
        val+=A[i]
        if val>=0 and i%2==0:
            ans+=val+1
            val=-1
        elif val<=0 and i%2==1:
            ans+=abs(val)+1
            val=1
    val=0
    ans2=0
    for i in range(len(A)):
        val+=A[i]
        if val>=0 and i%2==1:
            ans2+=val+1
            val=-1
        elif val<=0 and i%2==0:
            ans2+=abs(val)+1
            val=1


    print(min(ans2,ans))



resolve()

Measured memory_bytes: 86348
import sys
sys.setrecursionlimit(10 ** 7)
input = sys.stdin.readline

n, p = map(int, input().split())
a = list( map(int, input().split()))

for i in range(n):
    a[i] %=2

one = a.count(1)
zero = a.count(0)

ans=0

from operator import mul
from functools import reduce

def cmb(n,r):
    r = min(n-r,r)
    if r == 0: return 1
    over = reduce(mul, range(n, n - r, -1))
    under = reduce(mul, range(1,r + 1))
    return over // under

if p==0:
    for i in range(0,one+1,2):
        ans += cmb(one,i)*2**zero

else:
    for i in range(1,one+1,2):
        ans += cmb(one,i)*2**zero

print(ans)


Measured memory_bytes: 3572
import bisect
N = int(input())
A = sorted(list(map(int, input().split())))
B = sorted(list(map(int, input().split())))
C = sorted(list(map(int, input().split())))

ans=0
for b in B:
    a_index = bisect.bisect_left(A, b)
    c_index = bisect.bisect_right(C, b)
    ans += a_index * (N-c_index)
    
print(ans)

Measured memory_bytes: 29276
#include<stdio.h>
#include<iostream>
#include<string>
using namespace std;

int main() {
	/*
	int a = 0;//整数変数aを作る
	int b = 0;//整数変数bを作る

	cin >> a >> b;//2つの数字を受け取り、a,bに代入

	cout << a * b << endl;//a*bを出力
	*/
	/*
	string S;
	cin >> S;
	if (S[0]=='7'||S[1]=='7'||S[2]=='7') {
		cout << "Yes" << endl;
	}
	else {
		cout << "No" << endl;
	}

	int a = 0;
	int b = 0;
	int ans = 0;

	cin >> a >> b;

	int apb = a + b;
	int akb = a * b;
	int amb = a - b;
	ans = apb;
	if (ans < a - b) {
		ans = a - b;
	}


	if (ans < a * b) {
		ans = a * b;
	}
	cout << ans << endl;

	int N = 0;
	int R = 0;
	int Ans = 0;
	cin >> N >> R;
	if (N >=10) {
		Ans = R;
	}
	else
	{
		Ans = R + (100 * (10 - N));
	}

	cout << Ans << endl;
	
	int A = 0;
	cin >> A;
	cout << A + (A * A) + (A * A * A) << endl;
	*/

	int a, b, c;

	cin >> a >> b >> c;
	if (c >= a && b >= c) {
		cout << "Yes" << endl;
	}
	else {
		cout << "No" << endl;
	}




	return 0;
}



Measured memory_bytes: 3572
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<string> vs;
ll llmax = LLONG_MAX;
string ALP = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
string alp = "abcdefghijklmnopqrstuvwxyz";
vi d1 = {1, 0, -1, 0}, d2 = {0, 1, 0, -1};
void Yes() {cout << "Yes" << endl;}
void No() {cout << "No" << endl;}
void YES() {cout << "YES" << endl;}
void NO() {cout << "NO" << endl;}
void neg() {cout << -1 << endl;}

int main() {
  int x, a, b;
  cin >> x >> a >> b;
  cout << (x - a) % b << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <queue>
#include <vector>
#include <algorithm>
#include <math.h>
#include <map>
#include <iomanip>


using namespace std;



int main() {

	int N, A, B;
	long long int sum = 0, tmp=0;
	string S;

	cin >> N >> A >> B;

	for (int i = 1; i <= N; i++) {
		S = to_string(i);

		for (int j = 0; j < S.size(); j++) {
			tmp = tmp + S[j] -48;
		}
		
		if (tmp >= A && tmp <= B) {
			sum += i;
		}

		tmp = 0;
	}

	cout << sum;

	return 0;

}

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

int n,m,a[200001],l,r,mid,ans1,ans2,ans,Ans;

void getans(int x)
{
	ans1=ans2=0;
	for (int i=1; i<=x; i++) ans1=max(ans1,a[i]+a[(x<<1)-i+1]);
	for (int i=(x<<1)+1; i<n-(i-(x<<1))+1; i++)
		if (a[i]+a[n-(i-(x<<1))+1]<m) ans2=m+1; else
		ans2=max(ans2,a[i]+a[n-(i-(x<<1))+1]-m);
}

int main()
{
	scanf("%d%d",&n,&m),n<<=1;
	for (int i=1; i<=n; i++) scanf("%d",&a[i]);
	sort(a+1,a+1+n),l=0,r=(n>>1)-1;
	while (l<=r)
	{
		mid=(l+r)>>1,getans(mid);
		if (ans2<=m) ans=mid,r=mid-1; else l=mid+1;
	}
	Ans=0;
	for (int i=1; i<=(n>>1); i++) Ans=max(Ans,(a[i]+a[n-i+1])%m);
	getans(ans),Ans=min(Ans,max(ans1,ans2));
	printf("%d\n",Ans);
	return 0;
}

Measured memory_bytes: 1024
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0; i<(n) ;i++)
#define pb push_back
#define all(v) (v).begin(),(v).end()
#define fi first
#define se second
#define sz(x) ((int)(x).size())
using ll=long long;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
#define MOD  1000000007
const ll INF=1e18;
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; }



int main(int argc, char const *argv[]) {
  int n;
  cin >> n;
  vector<int> a(n),b(n),c(n);
  rep(i,n) cin >> a[i];
  rep(i,n) cin >> b[i];
  rep(i,n-1) cin >> c[i];
  ll ans=0;

  rep(i,n){
    ans+=b[i];
  }

  rep(i,n-1){
    if(a[i]+1==a[i+1]) ans+=c[a[i]-1];
  }
  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define srep(i,s,t) for(int i = s; i < t; ++i)
#define drep(i,n) for(int i = (n)-1; i >= 0; --i)
using namespace std;
typedef long long int ll;
typedef pair<int,int> P;
#define yn {puts("Yes");}else{puts("No");}
#define MAX_N 200005

int main() {
    ll n;
    cin >> n;
    ll ans = n*(n+1)*(n+1)/2 - n*(n+1)*(2*n+1)/6;

    rep(i,n-1){
        ll a, b;
        cin >> a >> b;
        if(a > b)swap(a,b);
        ans -= a * (n+1-b);
    }

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




Measured memory_bytes: 3484
import java.util.Scanner;

public class Main {

	public static void main(String args[]) {
		Scanner sc = new Scanner(System.in);
		String s = sc.nextLine();

		if (s.length() == 2) {
			System.out.println(s);
		} else {
			for (int i = s.length() - 1; i >= 0; i--) {
				System.out.print(s.charAt(i));
			}
		}
	}
}

Measured memory_bytes: 23892
import java.io.BufferedOutputStream;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.math.BigInteger;
import java.util.*;


public class Main {
	
	public static class FastReader {
		BufferedReader br;
		StringTokenizer st;
	

		public FastReader() {
			br = new BufferedReader(new InputStreamReader(System.in));
		}

		String next() {
			while (st == null || !st.hasMoreTokens()) {
				try {
					st = new StringTokenizer(br.readLine());
				} catch (Exception r) {
					r.printStackTrace();
				}
			}
			return st.nextToken();
		}

		int nextInt() {
			return Integer.parseInt(next());//converts string to integer
		}

		double nextDouble() {
			return Double.parseDouble(next());
		}

		long nextLong() {
			return Long.parseLong(next());
		}

		String nextLine() {
			String str = "";
			try {
				str = br.readLine();
			} catch (Exception r) {
				r.printStackTrace();
			}
			return str;
		}
	}
	
	public static PrintWriter out = new PrintWriter (new BufferedOutputStream(System.out));
    public static long mod = (long) (1e9+7);
    public final static int MAX = (int) 90000000;
  // static Scanner sc = new Scanner(System.in);
	public static void main(String[] args) {
	   
	 FastReader sc = new FastReader();
	 int n = sc.nextInt();
	 Map<String,Integer> map = new HashMap<>();
	 for(int i=0;i<n;++i) {
		 char[] s = sc.next().toCharArray();
		 Arrays.sort(s);
		 String str = new String(s);
		 if(map.containsKey(str)) {
			 map.put(str,map.get(str)+1);
		 }else map.put(str, 1);
	 }
	 long ans = 0;
	 for(String s : map.keySet()) {
		 long x = map.get(s);
		 ans+=(x*(x-1))/2;
	 }
	out.print(ans);
	 out.close();
		
	}
	
}

Measured memory_bytes: 48528
using namespace std;
#include<bits/stdc++.h>
#define BEGIN ios_base::sync_with_stdio(0);cin.tie(0)
#define END return EXIT_SUCCESS
#define FOR(I,A,B) for((I)=(A);(I)<(B);(I)++)
#define REP(I,N) FOR(I,0,N)
#define UP(I,A,B) for((I)=(A);(I)<=(B);(I)++)
#define DW(I,A,B) for((I)=(A);(I)>=(B);(I)--)
#define IN(P) cin>>(P)
#define IN2(P1,P2) cin>>(P1)>>(P2)
#define IN3(P1,P2,P3) cin>>(P1)>>(P2)>>(P3)
#define INS(I,N,V) REP(I,N) cin>>V[I]
#define INS2(I,N,V1,V2) REP(I,N) cin>>V1[I]>>V2[I];
#define INS3(I,N,V1,V2,V3) REP(I,N) cin>>V1[I]>>V2[I]>>V3[I];
#define OUT(P) cout<<P<<endl
#define OUT2(P1,P2) cout<<P1<<" "<<P2<<endl
#define OUT3(P1,P2,P3) cout<<P1<<" "<<P2<<" "<<P3<<endl
#define OUTS(I,N,V) REP(I,N) cout<<V[i]<<endl
#define ALL(C) (C).begin(),(C).end()
#define RALL(C) (C).rbegin(),(C).rend()
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
typedef unsigned long ul;
const ul INF=1LL<<60;
const ul NN=1e5;
long N,t[NN],x[NN],y[NN],i,T,D;
inline void solve(){
  IN(N);
  INS3(i,N,t,x,y);
  if(t[0]<x[0]+y[0]){
    OUT("No");
    return;
  }
  // if((t[0]-x[0]+y[0])%2){
  if((t[0]+x[0]+y[0])&1){
    OUT("No");
    return;
  }
  FOR(i,1,N){
    T=t[i]-t[i-1];
    D=abs(x[i]-x[i-1])+abs(y[i]-y[i-1]);
    if(T<D){
      OUT("No");
      return;
    }
    // if((T-D)%2){
    if((t[i]+t[i-1]+x[i]+x[i-1]+y[i]+y[i-1])&1){
      OUT("No");
      return;
    }
    if(x[i]==x[i-1]&&y[i]==y[i-1]){
      OUT("No");
      return;
    }
  }
  OUT("Yes");
}

int main(int argc,char**argv){
  BEGIN;
  solve();
  END;
}


Measured memory_bytes: 2560
N, D = map(int, input().split())
X = [list(map(int, input().split()))for _ in range(N)]
ans = 0
for i in range(N):
    for j in range(i+1, N):
        dist = 0
        for k in range(D):
            dist += (X[i][k] - X[j][k]) ** 2
        if int(dist**0.5) == dist**0.5:
            ans += 1
print(ans)

Measured memory_bytes: 38384
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <ctime>
#include <iostream>
#include <algorithm>
#include <sstream>
#include <string>
#include <vector>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <utility>
#include <cctype>
#include <numeric>
using namespace std;

#define rep(i,n) for(int (i)=0; (i)<(int)(n); ++(i))
#define foreach(c,i) for(__typeof((c).begin()) i=(c).begin();i!=(c).end();i++)
typedef pair<int,int> P;

int H, W, S;
int u[35][35];
int mustGrp, sumGrp;
bool visit[32][32][32][32];
P dp[32][32][32][32];

bool is_update(P base, P n1, P n2) {
  if (base.first < (n1.first + n2.first)) return true;
  if (base.first == (n1.first + n2.first)) {
    if (base.second < min(n1.second ,n2.second)) return true;
  }
  return false;
}

P f(int mnx, int mny, int mxx, int mxy) {
  if (visit[mnx][mny][mxx][mxy])
    return dp[mnx][mny][mxx][mxy];
  
  visit[mnx][mny][mxx][mxy] = true;
  P ret(1,0), lhs, rhs;
  for (int i = mny; i <= mxy; ++i)
    for (int j = mnx; j <= mxx; ++j)
      ret.second += u[i][j];
  // printf("%d %d - %d %d : %d\n", mnx, mny, mxx, mxy, ret.second);
  // select horizonal
  for (int i = mny; i <= mxy - 1; ++i) {
    lhs = f(mnx, mny, mxx, i);
    rhs = f(mnx, i+1, mxx, mxy);
    if (lhs.second < mustGrp) continue;        
    if (rhs.second < mustGrp) continue;
    if (is_update(ret, lhs, rhs))
      ret = P(lhs.first + rhs.first, min(lhs.second ,rhs.second));
  }
  // select vertical
  for (int i = mnx; i <= mxx - 1; ++i) {
    lhs = f(mnx, mny, i, mxy);
    rhs = f(i+1, mny, mxx, mxy);
    if (lhs.second < mustGrp) continue;
    if (rhs.second < mustGrp) continue;
    if (is_update(ret, lhs, rhs))
      ret = P(lhs.first + rhs.first, min(lhs.second ,rhs.second));
  }
  return dp[mnx][mny][mxx][mxy] = ret;
}

void solve() {
  sumGrp = 0;
  rep(i,H) rep(j,W) sumGrp += u[i][j];
  mustGrp = sumGrp - S; // assume
  memset(visit, 0, sizeof visit);
  P res = f(0, 0, W - 1, H - 1);
  printf("%d %d\n", res.first, res.second - mustGrp);
}

int main() {
  while (scanf("%d%d%d", &H, &W, &S), H | W) {
    rep(i,H) rep(j,W) scanf("%d", u[i]+j);
    solve();
  }
  return 0;
}

Measured memory_bytes: 9000
#include<bits/stdc++.h>
#define fi first
#define se second
#define LL long long
#define pii pair<LL, int>
using namespace std;
const int N = 1e5 + 10;

int n, m;
int a[N], b[N];
LL d[N], siz[N];
map<LL, int> Map;
priority_queue<pii> Q;

void doit(int cnt) {
	pii tmp = Q.top(); Q.pop();
	int to = Map[d[tmp.se] - (n - siz[tmp.se] * 2)];
	if (!to || tmp.se == to) puts("-1"), exit(0);
	a[cnt] = to;
	b[cnt] = tmp.se;
	if (siz[tmp.se] * 2 > n) puts("-1"), exit(0);
	siz[to] += siz[tmp.se];
}

namespace check {
	LL res = 0;
	int E, fir[N], nex[N << 1], arr[N << 1];

	void Add_Edge(int x, int y) {
		nex[++E] = fir[x];
		fir[x] = E; arr[E] = y;
	}

	void dfs(int x, int fa, LL dx) {
		res += dx;
		for (int i = fir[x]; i; i = nex[i]) {
			if (arr[i] == fa) continue;
			dfs(arr[i], x, dx + 1);
		}
	}
	
	void main() {
		for (int i = 1; i < n; ++i) {
			Add_Edge(a[i], b[i]);
			Add_Edge(b[i], a[i]);
		}
		int tmp = 1;
		for (int i = 1; i <= n; ++i) {
			if (d[i] > d[tmp]) tmp = i;
		}
		dfs(tmp, 0, 0);
		if (res != d[tmp]) puts("-1"), exit(0);
	}
}

int main() {
	scanf("%d", &n);
	for (int i = 1; i <= n; ++i) {
		scanf("%lld", &d[i]);
		Map[d[i]] = i;
		Q.push(make_pair(d[i], i));
	}
	if (n == 1 && d[1]) return 0 * puts("-1");
	for (int i = 1; i <= n; ++i)
		siz[i] = 1;
	for (int i = 1; i < n; ++i)
		doit(i);
	check::main();
	for (int i = 1; i < n; ++i)
		printf("%d %d\n", a[i], b[i]);
	return 0;
}


Measured memory_bytes: 18160
#include <bits/stdc++.h>
using namespace std;
typedef long long LL;
const int maxn=607;
const int inf=1e9;
int n,m,a[maxn*maxn],b[maxn*maxn];
vector <int> vec[maxn];
double f[maxn],ans;
double dp(int p)
{
    for(int i=1;i<=n;i++) 
        f[i]=0;
    f[n]=0;
    for(int i=n-1;i>=1;i--)
    {
        int len=vec[i].size();
        if(p==i&&len==1) 
        { 
            f[i]=inf;
            continue;
        }
        double t=1.0/(len-(p==i)),mx=0;
        for(int j=0;j<len;j++)
        {
            int v=vec[i][j];
            mx=max(mx,(f[v]+1)*t);
            f[i]+=(f[v]+1)*t;
        }
        if(p==i) f[i]-=mx;
    }
    return f[1];
}
int main()
{
    cin>>n>>m;
    for(int i=1;i<=m;i++)
    {
        cin>>a[i]>>b[i];
        vec[a[i]].push_back(b[i]);
    }
    ans=dp(0);
    for(int i=1;i<=n;i++)
        ans=min(ans,dp(i));
    cout<<fixed<<setprecision(9)<<ans<<"\n";
    return 0;
}



Measured memory_bytes: 2816
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i = 0; i < n; i++)
#define rep1(i, n) for(int i = 1; i < n+1; i++)
#define sort(A) sort(A.begin(),A.end())
#define reverse(A) reverse(A.begin(),A.end());
typedef long long ll;

const ll MOD = 1000000007;

int main(){
  int n;
  cin >>n;
  vector<int> a(n+1),b(n+1),c(n+1);
  rep1(i,n) cin >>a[i]>>b[i]>>c[i];
  vector<vector<int>> dp(4, vector<int>(n+1));
  dp[1][1] = a[1];
  dp[2][1] = b[1];
  dp[3][1] = c[1];
  for(int i=2;i<=n;i++){
    int way1;
    int way2;
    way1 = dp[2][i-1] + a[i];
    way2 = dp[3][i-1] + a[i];
    dp[1][i] = max(way1,way2);
    way1 = dp[1][i-1] + b[i];
    way2 = dp[3][i-1] + b[i];
    dp[2][i] = max(way1,way2);
    way1 = dp[1][i-1] + c[i];
    way2 = dp[2][i-1] + c[i];
    dp[3][i] = max(way1,way2);
  }
  int ans = 0;
  rep1(i,3) ans = max(ans,dp[i][n]);
  cout << ans << endl;
}

Measured memory_bytes: 3328
#include<bits/stdc++.h> //Ithea_Myse_Valgulious
namespace chtholly{
typedef long long ll;
#define re0 register int
#define rec register char
#define rel register ll
#define gc getchar
#define pc putchar
#define p32 pc(' ')
#define pl puts("")
/*By Citrus*/
inline int read(){
  int x=0,f=1;char c=gc();
  for (;!isdigit(c);c=gc()) f^=c=='-';
  for (;isdigit(c);c=gc()) x=(x<<3)+(x<<1)+(c^'0');
  return f?x:-x;
  }
template <typename mitsuha>
inline bool read(mitsuha &x){
  x=0;int f=1;char c=gc();
  for (;!isdigit(c)&&~c;c=gc()) f^=c=='-';
  if (!~c) return 0;
  for (;isdigit(c);c=gc()) x=(x<<3)+(x<<1)+(c^'0');
  return x=f?x:-x,1;
  }
template <typename mitsuha>
inline int write(mitsuha x){
  if (!x) return 0&pc(48);
  if (x<0) x=-x,pc('-');
  int bit[20],i,p=0;
  for (;x;x/=10) bit[++p]=x%10;
  for (i=p;i;--i) pc(bit[i]+48);
  return 0;
  }
inline char fuhao(){
  char c=gc();
  for (;isspace(c);c=gc());
  return c;
  }
}using namespace chtholly;
using namespace std;

int n,gg,p[109],c[109];
int dp[10010][109];

int main(){
int i,j,k;
n=read(),gg=read();
for (i=1;i<=n;i++) p[i]=read(),c[i]=read();
for (i=1;i<=n;i++){
  for (k=1000;~k;k--){
    for (j=1;j<p[i];j++) dp[k+j][i]=max(dp[k+j][i-1],dp[k][i-1]+j*i*100);     
	dp[k+p[i]][i]=max(dp[k+p[i]][i-1],dp[k][i-1]+p[i]*i*100+c[i]); 
	}
  }
for (i=1;i<=1000;i++){
  if (dp[i][n]>=gg){
    return write(i);
    }
  }
}

Measured memory_bytes: 768
#include<bits/stdc++.h>
#define fr(i,x,y) for(int i=x;i<=y;++i)
#define rf(i,x,y) for(int i=x;i>=y;--i)
#define LL long long
using namespace std;
const int N=4010,mod=998244353;
LL jc[N]={1},ny[N];

void Mul(LL &x,LL y){
	x=(x*y)%mod;
}

void Add(LL &x,LL y){
	x=(x+y+mod)%mod;
}

LL mul(LL x,LL y){
	return x*y%mod;
}

LL q_pow(LL x,int y=mod-2){
	LL ans=1;
	for(;y;y>>=1){
		if(y&1) Mul(ans,x);
		Mul(x,x);
	}
	return ans;
}

LL C(int x,int y){
	if(x==y||!y) return 1;
	LL pos=mul(jc[x],mul(ny[y],ny[x-y]));
	//printf("%d %d %lld\n",x,y,pos);
	return pos;
}

int main(){
	int n,k;scanf("%d%d",&k,&n);
	fr(i,1,n+k) jc[i]=jc[i-1]*1LL*i%mod,ny[i]=q_pow(jc[i]);
	fr(i,2,2*k){
		int gg=i/2;
		if(i-i/2>k) gg=0;
		else if(i>k+1) gg-=(i-k-1);
		LL ans=0;
		//printf("zz%d %d\n",i,gg);
		fr(j,0,gg) {
			if(j*2>n) break;
			//printf("j=%d gg=%d n-2*j+k-1=%d k-1=%d\n",j,gg,n-2*j+k-1,k-1);
			LL pos=mul(C(gg,j),C(n-2*j+k-1,k-1));
			if(j&1) Add(ans,-pos);
			else Add(ans,pos);
		}
		printf("%lld\n",ans);
	}
	return 0;
}

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

int solve(int n) {
    int sum=0;
    while(n>0) {
    sum+=n%10;
    n/=10;
    }
    return sum;
}

int main() {
    int n,ans=10000; cin >> n;
    for(int i=1;i<n;i++) {
        int a=i, b=n-i;
        int count=solve(a)+solve(b);
        ans=min(count,ans);
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using Graph = vector<vector<int>>;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
const long long MOD=1e9+7;

int main() {
  int n;
  cin>>n;
  int ans=0;
  rep(i,n){
    int l,r;
    cin>>l>>r;
    ans+=r-l+1;
  }
  cout<<ans<<endl;
}

Measured memory_bytes: 256
#include <algorithm>
#include <cassert>
#include <cmath>
#include <cstdio>
#include <deque>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>

using std::cerr;
using std::cin;
using std::cout;
using std::endl;




int main(void){
  cout << std::fixed << std::setprecision(10);
  cin.tie(0);
  std::ios::sync_with_stdio(false);

  int n;

  cin>>n;
  std::vector<int> b(n);
  std::vector<int> count(101);
  for(int i=0;i<n;i++){
    cin>>b[i];
    count[b[i]]++;
  }
  std::vector<int> result_rev;

  for(int i=0;i<n;i++){
    bool found=false;
    for(int j=b.size()-1;j>=0;j--){
      if(j+1==b[j]){
        result_rev.push_back(j+1);
        b.erase(b.begin()+j);
        found=true;
        break;
      }

    }
    if(!found){
      cout<<-1<<endl;
      return  0;
    }
  }

  for(int i=result_rev.size()-1;i>=0;i--){
    cout<<result_rev[i]<<endl;
  }


  
  return 0;
}


Measured memory_bytes: 256