akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
 
#define REP(i, s) for (int i = 0; i < s; ++i)
#define ALL(v) (v).begin(), (v).end()
#define COUT(x) cout << #x << " = " << (x) << " (L" << __LINE__ << ")" << endl
#define EACH(i, s) for (__typeof__((s).begin()) i = (s).begin(); i != (s).end(); ++i)
#define DEBUG
#define int long long
#define 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; }
template<class T1, class T2> ostream& operator << (ostream &s, pair<T1,T2> P)
{ return s << '<' << P.first << ", " << P.second << '>'; }
template<class T> ostream& operator << (ostream &s, vector<T> P)
{ for (int i = 0; i < P.size(); ++i) { if (i > 0) { s << " "; } s << P[i]; } return s; }
template<class T> ostream& operator << (ostream &s, vector<vector<T> > P)
{ for (int i = 0; i < P.size(); ++i) { s << endl << P[i]; } return s << endl; }
template<class T> ostream& operator << (ostream &s, set<T> P)
{ EACH(it, P) { s << "<" << *it << "> "; } return s << endl; }
template<class T1, class T2> ostream& operator << (ostream &s, map<T1,T2> P)
{ EACH(it, P) { s << "<" << it->first << "->" << it->second << "> "; } return s << endl; }
template<class T>void show(vector<T>v){for (int i = 0; i < v.size(); i++){cerr<<v[i]<<" ";}cerr<<"\n";}
typedef long long ll;

signed main()
{
    int n, k;
    cin >> n >> k;
    vector<bool> a(n, false);
    for (int i = 0; i < k; i++)
    {
        int d;
        cin >> d;
        REP(j,d){
            int b;
            cin >> b;
            b--;
            a[b] = true;

        }
    }
    int cnt = 0;
    for (int i = 0; i < n; i++)
    {
        if(!a[i])
            cnt++;
    }
    cout << cnt << endl;

    return 0;
}

Measured memory_bytes: 3600
import java.util.*;
public class Main{
    public static void main(String[] args) {
        Scanner scan = new Scanner(System.in);
        int n = Integer.parseInt(scan.next());
        int[] lst = new int[n+1];
        int x = Integer.parseInt(scan.next());
        for(int a = 0; a <= n; a++){
            if(a == 0){
                lst[0] = 0;
            }
            else{
                lst[a] = Integer.parseInt(scan.next());
            }
        }
        for (int a = 0; a <= n; a++) {
            if(a!=n) {
                lst[a + 1] = lst[a] + lst[a + 1];
            }
            else if(a == n){
                System.out.println(n+1);
                break;
            }
            if (lst[a + 1] > x){
                System.out.println(a + 1);
                break;
            }
        }
    }
}



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

public class Main {

	static int d[];

	static List<edge> edges;

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

		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));

		String[] v_e_r = br.readLine().split(" ");

		int v = Integer.parseInt(v_e_r[0]);

		int e = Integer.parseInt(v_e_r[1]);

		int r = Integer.parseInt(v_e_r[2]);

		d = new int[v];

		edges = new ArrayList<>();

		for(int i=0; i<e; i++){
			String[] from_to_cost_edge = br.readLine().split(" ");

			edges.add(new edge(Integer.parseInt(from_to_cost_edge[0]), Integer.parseInt(from_to_cost_edge[1]), Integer.parseInt(from_to_cost_edge[2])));
		}

		bellford(r);

		for(int i=0; i<d.length; i++){
			if(d[i] == Integer.MAX_VALUE/2){
				System.out.println("INF");
			}else {
				System.out.println(d[i]);
			}
		}

	}

	static void bellford(int now){

		Arrays.fill(d, Integer.MAX_VALUE/2);
		d[now] =0;

		while(true){
			boolean judge =false;

			for(edge e: edges){
				if(d[e.to]> d[e.from] +e.cost){
					d[e.to] = d[e.from]+e.cost;
					judge = true;
				}
			}
			if(!judge){
				break;
			}
		}
	}



	static class edge{
		int from;
		int to;
		int cost;

		public edge(int a, int b, int c) {
			this.from =a;
			this.to = b;
			this.cost = c;
		}
	}
}

Measured memory_bytes: 119056
#include <iostream>

using namespace std;

int solve(int W, int a, int b)
{
	if (a + W < b) {
		return b - (a + W);
	}
	else if (b + W < a) {
		return a - (b + W);
	}
	else {
		return 0;
	}
}

int main()
{
	int W, a, b;
	cin >> W >> a >> b;
	cout << solve(W, a, b) << endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <cstdio>
#include <algorithm>
#include <set>
#include <map>
#include <cassert>
#include <numeric>
#include <string>
#include <cstring>
#include <cmath>
using namespace std;

#ifdef LOCAL
	#define eprintf(...) fprintf(stderr, __VA_ARGS__)
#else
	#define eprintf(...) 42
#endif

typedef long long int int64;

char str[105];

const int K = 20;
int cntFrac[2 * K][2 * K];

void readNum()
{
    scanf("%s", str);
    int len = strlen(str);
    int pt = 0;
    while (pt < len && str[pt] != '.')
        pt++;
    str[pt] = 0;

    int a = atoi(str);
    int b = 0;
    if (pt < len)
        b = atoi(str + pt + 1);

    eprintf("a = %d, b = %d\n", a, b);
    int blen = len - pt - 1;
    int d = 1;
    for (int i = 0; i < blen; i++)
        d *= 10;
   
    int a2 = 0, a5 = 0;
    int d2 = 0, d5 = 0;
    long long A = a * 1LL * d + b;
    while (A % 2 == 0)
    {
        A /= 2;
        a2++;
    }
    while (A % 5 == 0)
    {
        A /= 5;
        a5++;
    }
    while (d % 2 == 0)
    {
        d /= 2;
        d2++;
    }
    while (d % 5 == 0)
    {
        d /= 5;
        d5++;
    }

    eprintf("%d %d\n", a2 - d2, a5 - d5);
    cntFrac[min(K - 1, a2 - d2) + K][min(K - 1, a5 - d5) + K]++;
}


int main(int,  char **)
{
#ifdef LOCAL
	freopen("input.txt", "r", stdin);
//	freopen("output.txt", "w", stdout);
#endif

    int n;
    scanf("%d", &n);
    for (int i = 0; i < n; i++)
        readNum();


    long long ans = 0;
    for (int i = 0; i < 2 * K; i++)
        for (int j = 0; j < 2 * K; j++)
        {
            long long x = cntFrac[i][j];
            if (i >= K && j >= K)
            ans += x * (x - 1) / 2;

            for (int ii = i; ii < 2 * K; ii++)
                for (int jj = ((ii == i) ? j + 1 : 0); jj < 2 * K; jj++)
                {
                    if (ii + i >= 2 * K && jj + j >= 2 * K)
                        ans += x * cntFrac[ii][jj];
                }
        }
    printf("%lld\n", ans);


	return 0;
}




Measured memory_bytes: 3824
#define _USE_MATH_DEFINES
#include<stdio.h>
#include<string>
#include<iostream>
#include<cctype>
#include<cstdio>
#include<vector>
#include<stack>
#include <algorithm>
#include<math.h>
#include<set>
#include<map>
#include<iomanip>

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

double round(double r) {
    return (r > 0.0) ? floor(r + 0.5) : ceil(r - 0.5);
}

using namespace std;




int main() {
	
	
	double a,b,c;
	cin>>a>>b>>c;
	cout<<(a+b)*c/2<<endl;

    return 0;
}

	
	


	

Measured memory_bytes: 256
import bisect

M=[]
D=[]
N=[]
count=0

def insert(M,D,N,count,key,x):
    y=bisect.bisect_left(D,key)
    if y<count and D[y]==key:
        M[y][1]=x
        N[y]=x
    else:
        M.insert(y,[key,x])
        D.insert(y,key)
        N.insert(y,x)
        count+=1
    return M,D,N,count

def get(D,N,count,key):
    y=bisect.bisect_left(D,key)
    if y<count and D[y]==key:
        print(N[y])
    else:
        print(0)

def erase(M,D,N,count,key):
    y=bisect.bisect_left(D,key)
    if y<count and D[y]==key:
        M.pop(y)
        D.pop(y)
        N.pop(y)
        count-=1
    return M,D,N,count

def dump(M,D,N,L,R):
    s=bisect.bisect_left(D,L)
    e=bisect.bisect_right(D,R)
    if e-s>0:
        for i in range(s,e):
            print(M[i][0]+" "+str(M[i][1]))

q=int(input())
for i in range(q):
    query=list(map(str,input().split()))
    query[0]=int(query[0])
    if query[0]==0:
        M,D,N,count=insert(M,D,N,count,query[1],int(query[2]))
    elif query[0]==1:
        get(D,N,count,query[1])
    elif query[0]==2:
        M,D,N,count=erase(M,D,N,count,query[1])
    else:
        dump(M,D,N,query[1],query[2])



Measured memory_bytes: 45140
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); i++)
using namespace std;
using ll = long long;
const int INF = (1<<30)-1;
const long long LINF = (1LL<<62)-1;
const int dx[] = {-1, 0, 1, 0};
const int dy[] = {0, 1, 0, -1};
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; }

struct Sec {
  vector<double> l, r;
  Sec() : l(3, INF), r(3, -INF) {}
  void set(double x, int d) {
    ++d;
    chmin(l[d], x);
    chmax(r[d], x);
  }
  vector<double> times() {
    vector<double> event;
    rep(i, 3) rep(j, i) {
      double t = (l[j]-l[i])/(i-j);
      if (t > 0)
        event.push_back(t);
    }
    rep(i, 3) rep(j, i) {
      double t = (r[j]-r[i])/(i-j);
      if (t > 0)
        event.push_back(t);
    }
    return event;
  }
  double get(double t) {
    double lmin = INF, rmax = -INF;
    rep(i, 3) {
      chmin(lmin, l[i]+i*t);
      chmax(rmax, r[i]+i*t);
    }
    return rmax-lmin;
  }
};

signed main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int n;
  cin >> n;
  Sec x, y;
  rep(i, n) {
    int tx, ty;
    char d;
    cin >> tx >> ty >> d;
    if (d == 'U') {
      x.set(tx, 0);
      y.set(ty, 1);
    }
    if (d == 'D') {
      x.set(tx, 0);
      y.set(ty, -1);
    }
    if (d == 'R') {
      x.set(tx, 1);
      y.set(ty, 0);
    }
    if (d == 'L') {
      x.set(tx, -1);
      y.set(ty, 0);
    }
  }
  vector<double> event = {0, INF}, tx = x.times(), ty = y.times();
  event.insert(event.end(), tx.begin(), tx.end());
  event.insert(event.end(), ty.begin(), ty.end());
  sort(event.begin(), event.end());
  event.erase(unique(event.begin(), event.end()), event.end());
  double ans = LINF;
  for (auto e : event)
    chmin(ans, x.get(e)*y.get(e));
  cout << fixed << setprecision(11) << ans << endl;
  return 0;
}

Measured memory_bytes: 256
def cin():  return list(map(int,input().split()))
K, A, B = cin()
ans1 = K + 1
kk = K - (A - 1)
ans2 = 0
if kk > 0:
    if kk % 2:  ans2 = A + 1 + kk // 2 * (B - A)
    else:  ans2 = A + kk // 2 * (B - A)
ans = max(ans1, ans2)
print(ans)

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

int main(){
    int N;
    cin >> N;
    vector<int> p(N), q(N), a(N);
    rep(i, N) cin >> p.at(i);
    rep(i, N) cin >> q.at(i);
    rep(i, N) a.at(i) = i+1;
    map<vector<int>, int> m;
    do {
       m[a] = m.size();
    } while(next_permutation(a.begin(), a.end()));
    cout << abs(m.at(p) - m.at(q)) << endl;
}

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

using namespace std;

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

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

#endif

void Main() {
    string S;
    cin >> S;
    S = S;
    ll N = S.size();
    vector<vector<ll>> dp(N + 1, vector<ll>(2, INF));
    dp[0][0] = 0;
    dp[0][1] = 1;
    rep(i, N) {
        ll d = S[i] - '0';
        dp[i + 1][0] = min(dp[i + 1][0], dp[i][0] + d);
        dp[i + 1][0] = min(dp[i + 1][0], dp[i][1] + 10 - d);
        dp[i + 1][1] = min(dp[i + 1][1], dp[i][0] + d + 1);
        dp[i + 1][1] = min(dp[i + 1][1], dp[i][1] + 10 - d - 1);
    }
    cout << dp[N][0] << '\n';
}

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


Measured memory_bytes: 55964
#include<bits/stdc++.h>
using namespace std;
int main()
{
    long long int a,b,c,d,e,f;
    vector<long long int>v;
    while(cin>>a)
    {

        for(b=1;b<=a;b++)
        {

            cin>>c;
            v.push_back(c);


        }
        d=0;
        e=0;
        sort(v.begin(),v.end());
        reverse(v.begin(),v.end());
        for(b=0;b<v.size();b++)
        {

            if((b+1)%2!=0)
            {
                d=d+v[b];
            }
            else
            {
                e=e+v[b];
            }


        }
        cout<<d-e<<endl;
      v.clear();

    }




    return 0;
}


Measured memory_bytes: 256
n=int(input())
s =list(input())
l=["A","B","C","D","E","F","G","H","I","J","K","L","M","N","O","P","Q","R","S","T","U","V","W","X","Y","Z"]
ans=[]

for i in range(len(s)):
    if l.index(s[i])+n>25:
        ans.append(l[l.index(s[i])+n-26])
    else:
        ans.append(l[l.index(s[i])+n])

for i in ans:
    print(i,end="")

Measured memory_bytes: 4596
#include<iostream>
#include<vector>

using namespace std;
int main(){
  int N; cin >> N; int M = 0; int S = 0;
  vector<int> L(N); for(int i = 0; i < N; i++){cin >> L[i]; M = max(M,L[i]); S += L[i];}
  
  if( 2 * M < S ) {cout<< "Yes" << endl;}
  else{cout << "No" << endl;}
  
  return 0;
}
  

Measured memory_bytes: 256
import queue

S = list(input().split())
stack = queue.LifoQueue()

for i in range(len(S)):
  if S[i] != "+" and S[i] != "-" and S[i] != "*":
    S[i] = int(S[i])
    stack.put(S[i])
  else:
    x = stack.get()
    y = stack.get()
    if S[i] == "+":
      stack.put(y + x)
    elif S[i] == "-":
      stack.put(y - x)
    elif S[i] == "*":
      stack.put(y * x)

print(stack.get())



Measured memory_bytes: 6872
import std.stdio, std.algorithm, std.conv, std.array, std.string, std.range;

void main()
{
    auto o = readln.chomp;
    auto e = readln.chomp;
    auto ret = o.zip(e).map!(t => [t[0], t[1]]).joiner.to!string;
    writeln(o.length > e.length ? ret ~ o[$-1] : ret);
}


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

#define FOR(i, a, b) for (int i = (a); i < int(b); ++i)
#define RFOR(i, a, b) for (int i = (b)-1; i >= int(a); --i)
#define REP(i, n) FOR(i, 0, n)
#define REP1(i, n) FOR(i, 1, int(n) + 1)
#define RREP(i, n) RFOR(i, 0, n)
#define RREP1(i, n) RFOR(i, 1, int(n) + 1)
#define ALL(c) begin(c), end(c)

int _ = (
#ifndef LOCAL
    std::cin.tie(nullptr), std::ios::sync_with_stdio(false),
#endif
    std::cout.precision(10), std::cout.setf(std::ios::fixed));

using ll = long long;
using ull = unsigned long long;
using ld = long double;
template <typename T> using vec = std::vector<T>;
using namespace std;

static inline constexpr ll generate_choco_date(ll c, ll Ai) {
  return c * Ai + 1;
}

int main() {
  ll N, D, X;
  cin >> N >> D >> X;
  vec<ll> A(N);
  REP(i, N) cin >> A[i];

  ll answer = X;
  REP(i, N) {
    for (ll j = 0;; j++) {
      const ll choco_date = generate_choco_date(j, A[i]);
      if (choco_date <= D) {
        answer++;
      } else {
        break;
      }
    }
  }

  cout << answer << endl;
  return 0;
}


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

int main(){

    int n; cin >> n;
    vector<int> a(n);
    vector<int> b(n);
    for(int i = 0; i < n; i++) cin >> a[i];
    for(int i = 0; i < n; i++) b[i] = i + 1;

    map<vector<int>, int> mb;
    queue<pair<vector<int>, int> > qb;
    
    mb[b] = -1;
    qb.push({b, 0});
    

    while(1){

        vector<int> now(n);
        now = qb.front().first;
        int cost = qb.front().second;
        qb.pop();
        
        if(cost == 4) break;

        bool ok = true;
        for(int i = 0; i < n; i++){
            if(a[i] != now[i]){
                ok = false;
                break;
            }
        }

        if(ok){
            cout << cost << endl;
            return 0;
        }

        for(int i = 0; i < n - 1; i++){
            for(int j = i + 1; j < n; j++){
                vector<int> next(n);
                next = now;

                for(int k = i; k <= j; k++){
                    next[k] = now[j - k + i];
                }


                if(mb.find(next) == mb.end()){
                    mb[next] = cost + 1;
                    qb.push({next, cost + 1});
                }
            }
        }
    }


    //cout << "junnbihadeketa" << endl;
    map<vector<int>, int> ma;
    queue<pair<vector<int>, int> > qa;
    ma[a] = -1;
    qa.push({a, 0});

    while(1){

        vector<int> now(n);
        now = qa.front().first;
        int cost = qa.front().second;
        qa.pop();

        if(cost == 4) break;

        if(mb.find(now) != mb.end()){
            cout << cost + mb[now] << endl;
            return 0;
        }

        for(int i = 0; i < n - 1; i++){
            for(int j = i + 1; j < n; j++){
                vector<int> next(n);
                next = now;
                for(int k = i; k <= j; k++){
                    next[k] = now[j + i - k];
                }

                if(ma.find(next) == ma.end()){
                    ma[next] == cost + 1;
                    qa.push({next, cost + 1});
                }
            }
        }
    }

    cout << 9 << endl;
    return 0;
}


Measured memory_bytes: 102896
N = int(input())
A = sorted(list(map(int,input().split())))
n = A[-1]
k = A[0]
for i in range(1,N-1):
    j = A[i]
    if k<=n//2 and j<=n//2:
        k = max(k,j)
    elif k<=n//2 and j>n//2:
        if k<n-j:
            k = j
    elif k>n//2 and j<=n//2:
        if n-k<j:
            k = j
    elif k>n//2 and j>n//2:
        if n-k<n-j:
            k = j
print(n,k)

Measured memory_bytes: 62704
#include <iostream>
#include <algorithm>
#include <string>
#include <queue>
using namespace std;
typedef long long ll;
typedef pair<int, int> P;


int main(void) {
    int h, w, i, j, k;
    ll ans = 0;
    string s[403];
    bool u[403][403] = { false };
    const int di[4] = { 1,0,-1,0 }, dj[4] = { 0,1,0,-1 };

    cin >> h >> w;
    for (i = 0; i < h; i++) {
        cin >> s[i];
    }

    for (i = 0; i < h; i++) for (j = 0; j < w; j++) {
        if (s[i][j] == '#' && !u[i][j]) {

            int pi, pj, ni, nj;
            ll ws = 0, bs = 0;
            P p;
            queue<P> q;
            q.push(P(i, j));
            u[i][j] = true;
            while (!q.empty()) {
                p = q.front();
                q.pop();
                pi = p.first;
                pj = p.second;
                if (s[pi][pj] == '.') ws++;
                if (s[pi][pj] == '#') bs++;
                for (k = 0; k < 4; k++) {
                    ni = pi + di[k];
                    nj = pj + dj[k];
                    if (ni >= 0 && ni < h && nj >= 0 && nj < w && !u[ni][nj] && s[pi][pj] != s[ni][nj]) {
                        q.push(P(ni, nj));
                        u[ni][nj] = true;
                    }
                }
            }
            ans += ws * bs;

        }
    }

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 640
#include<bits/stdc++.h>
#define ll long long
#define pii pair<int,int>
#define pb push_back
#define f first
#define s second
#define MOD 1000000007
 
using namespace std;

void solve(){
	ll k, x;
	cin>>k>>x;
	if(k*500 >= x) cout<<"Yes";
	else cout<<"No";
}


int main()
{ 
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	//cout<<fixed<<setprecision(12);
	
	int t =1; 
	//cin>>t;

	for(int i=1; i<=t; i++){
		solve();
		cout<<"\n";
	}
	return 0;

}




Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef pair<ll, ll> P;
typedef vector<ll> VI;
typedef vector<VI> VVI;
const ll MOD = 1000000007;
const ll INF = 1e18;
#define REP(i, n) for(int i = 0; i < n; i++)
#define ALL(v) v.begin(), v.end()

template<typename T>
class BIT {
    int N;
    vector<T> data;
public:
    BIT(int N) : N(N) {
        data.resize(N + 1, 0);
    }
    T sum(int k) {
        T res = 0;
        for (; k > 0; k -= k & -k) {
            res += data[k];
        }
        return res;
    }
    void add(int k, T x) {
        for (; k <= N; k += k & -k) {
            data[k] += x;
        }
    }
    //v1 + v2 + ... + vx ≧ W となる最小の𝑥
    int lowerBound(int w) {
        if (w <= 0) return 0;
        int x = 0;
        int k = 1;
        while (k * 2 <= N) k *= 2;
        for (; k > 0; k /= 2) {
            if (x + k <= N && data[x + k] < w) {
                w -= data[x + k];
                x += k;
            }
        }
        return x + 1;
    }
};

struct que{
	int l;
	int r;
	int p;
	bool operator<(const que &another) const {return l < another.l;};
};

int main() {
	int n, q; cin >> n >> q;
	VI c(n); 
	REP(i,n){
		cin >> c[i];
		c[i]--;
	}
	vector<queue<int>> cq(n);
	REP(i,n){
		cq[c[i]].push(i);
	}
	BIT<int> bit(n+1);
	REP(i,n){
		if(!cq[i].empty()){
			bit.add(cq[i].front()+1,1);
		}
	}
	vector<que> query(q);
	int l, r;
	REP(i,q){
		cin >> l >> r;
		query[i]={l,r,i};
	}
	sort(ALL(query));
	VI ans(q);
	int nowl=1;
	REP(i,q){
		que nowq=query[i];
		for(int j=nowl;j<nowq.l;j++){
			bit.add(cq[c[j-1]].front()+1,-1);
			cq[c[j-1]].pop();
			if(!cq[c[j-1]].empty())
				bit.add(cq[c[j-1]].front()+1,1);
		}
		nowl=nowq.l;
		ans[nowq.p]=bit.sum(nowq.r)-bit.sum(nowq.l-1);
	}
	REP(i,q)
		cout << ans[i] << endl;
	return 0;
}

Measured memory_bytes: 357048
import java.io.*;
import java.util.*;
import java.util.function.*;

final class Quad {
	int a, b, c, d;

	Quad(int a, int b, int c, int d) {
		this.a = a;
		this.b = b;
		this.c = c;
		this.d = d;
	}
}

final class Solver {
	static final Solver INSTANCE = new Solver();

	void solve(Supplier<String> sc) {
		int N = Integer.parseInt(sc.get());
		int M = Integer.parseInt(sc.get());
		int Q = Integer.parseInt(sc.get());
		Quad[] quads = new Quad[Q];
		for (int i = 0; i < Q; i++) {
			quads[i] = new Quad(Integer.parseInt(sc.get()) - 1, Integer.parseInt(sc.get()) - 1, Integer.parseInt(sc.get()), Integer.parseInt(sc.get()));
		}

		int max = createArrays(new int[N], 1, M ,0, array -> {
			int point = 0;
			for (Quad quad : quads) {
				if (array[quad.b] - array[quad.a] == quad.c) point += quad.d;
			}
			return point;
		});

		System.out.println(max);
	}

	int createArrays(int[] filled, int min, int max, int target, ToIntFunction<int[]> op) {
		if (target >= filled.length) return op.applyAsInt(filled);
		int result = 0;
		for (int i = min; i <= max; i++) {
			filled[target] = i;
			result = Math.max(result, createArrays(filled, i, max, target + 1, op));
		}
		return result;
	}
}

class Main {
	public static void main(String... args) {
		try (var reader = new BufferedReader(new InputStreamReader(System.in))) {
			Solver.INSTANCE.solve(new Supplier<>() {
				StringTokenizer line;

				public String get() {
					while (line == null || !line.hasMoreTokens()) try {
						line = new StringTokenizer(reader.readLine());
					} catch (IOException e) {
						throw new UncheckedIOException(e);
					}
					return line.nextToken();
				}
			});
		} catch (IOException e) {
			throw new UncheckedIOException(e);
		}
	}
}

Measured memory_bytes: 34676
n = gets.chomp.to_i
@k = gets.chomp.to_i
@a = 1

def result(a)
  tmp_multiplication = a * 2
  tmp_adding_up = a + @k
  @a = tmp_multiplication <= tmp_adding_up ? tmp_multiplication : tmp_adding_up
end

n.times do
  result(@a)
end

puts @a

Measured memory_bytes: 1788
require 'pp'
# IS_DEBUG = true
IS_DEBUG = false
def dputs str
	if(IS_DEBUG)
		puts str
	end
end
def dpp str
	if(IS_DEBUG)
		pp str
	end
end

MAX_INT = 9999999999999999

S=gets.chomp
if(S.size < 4 || S[0..3]!="YAKI")
	puts "No"
else
	puts "Yes"
end


Measured memory_bytes: 2300
/**********************************************************/
/**            Bismillahir-rahmanir-rahim                **/
/**  In the name of Allah, the Beneficent, the Merciful. **/
/**********************************************************/
/****@author: Sayed Sohan, CSE 13th batch(2016), MBSTU*****/
/**********************************************************/

#include <bits/stdc++.h>
using namespace std;
//              Typedefs
typedef long long               ll;
typedef unsigned long long      ull;

//              Templates
template<class T>               using min_heap = \
                                priority_queue<T, \
                                std::vector<T>, std::greater<T>>;

//              Basic-Defs
#define PB                      push_back
#define MP                      make_pair
#define SP                      " "
#define NL                      "\n"
#define all(v)                  v.begin(), v.end()

//              DEBUG--SECTION
#define DE                      cout<<"HERE\n";
#define DE1(x)                  cout<<x<<"###\n";
#define DE2(x,y)                cout<<x<<"####"<<y<<"\n";
#define Pause                   system("pause");

//              Functions
#define clr(arr,value)          memset(arr,value,sizeof(arr))
#define __FAST_IO               ios_base::sync_with_stdio(0);\
                                cin.tie(0);cout.tie(0);
#define NUM1(x)                 __builtin_popcount(x)
#define LCM(x,y)                (x*y)/__gcd(x,y)

//              Sizes--Math     0123456789
#define MOD                     1000000007   //1e9+7 
#define MAX                     100050      
#define INF                     1e18
#define PI                      acos(-1)
#define eps                     1e-6

//** your code goes from here

struct st
{
	ll a[13];
	ll c;
}arr[20];
ll n,m,k;

int main()
{
    //freopen("input.txt","r",stdin);
    //freopen("output.txt","w",stdout);
    __FAST_IO;
    
    ll i,j,T; //basic variables
    cin>>n>>m>>k;
    for(i=0;i<n;i++){
    	ll x;
    	cin>>x;
    	arr[i].c = x;
    	for(j=0;j<m;j++){
    		cin>>x;
    		arr[i].a[j] = x;
    	}
    }
    ll ans = INF;
    for(i=0;i<(1<<n);i++){
    	bitset<15> bt(i);
    	ll brr[15] = {0};
    	ll coun = 0;
    	for(j=0;j<n;j++){
    		if(bt[j]){
    			coun+=arr[j].c;
    			for(ll l=0;l<m;l++){
    				ll x = arr[j].a[l];
    				brr[l]+=x;
    			}
    		}
    	}
    	ll check = 0;
    	for(j=0;j<m;j++){
    		if(brr[j]<k) check = 1;
    	}
    	if(!check) ans = min(ans,coun);
    }

    if(ans==INF) cout<<-1<<NL;
    else cout<<ans<<NL;




    /// Don't forget to set array size....
    return 0;
}




Measured memory_bytes: 3652
#include <bits/stdc++.h>
using namespace std;
#define _GLIBCXX_DEBUG
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define REP(i,x,n) for(int i = (x); i < (n); ++i)
#define ll long long
#define P pair<ll,ll>
#define all(v) (v).begin(),(v).end()
#define rall(v) (v).rbegin(),(v).rend()

const ll mod = 1e9+7;
const ll INF = 1e18;
const double pi = acos(-1);

int main(void)
{
    ll n;
    cin >> n;
    map<ll,ll> mp;
    rep(i,n){
        ll a;
        cin >> a;
        mp[a]++;
    }
    ll w=0, h=0;
    for(auto x:mp){
        if(x.second >= 2){
            w = max(w, x.first);
        }
    }
    mp[w] -= 2;
    for(auto x:mp){
        if(x.second >= 2){
            h = max(h, x.first);
        }
    }
    cout << w*h << endl;
    return 0;
}


Measured memory_bytes: 9836
#include <stdio.h>

int main (void){

	int a,b;
	scanf("%d %d",&a,&b);
	
	if(a>b){
		printf("a > b\n");
	}
	if(a<b){
		printf("a < b\n");
	}
	if(a==b){
		printf("a == b\n");
	}
	return 0;
}

Measured memory_bytes: 580
#include <iostream>
#include <iomanip> 
#include <cstdlib>
#include <cmath>
#include<map>
#include<string.h>
#include <algorithm>
#include <bits/stdc++.h> 
#include<vector>

using namespace std;
#define rep(i,a,b) for(int i=a;i<b;i++)
#define repb(i,a,b) for(int i=a;i>=b;i--)
#define replb(i,a,b) for(ll i=a;i>=b;i--)
#define repl(i,a,b) for(ll i=a;i<b;i++)
#define repit(arr)  for(auto it=arr.begin();it!=arr.end();it++)  
#define vi vector<int>
#define vb vector<bool>
#define vs vector<string>
#define vl vector<long long int>
#define Vi vector<vector<int>>
#define seti set <int>
#define setl set <ll>
#define dseti set <int, greater <int> >
#define dsetl set <ll, greater <ll> >
#define mseti multiset <int>
#define msetl multiset <ll>
#define dmseti multiset <int, greater <int> >
#define dmsetl multiset <ll, greater <ll> >
#define sortA(arr)   sort(arr.begin(),arr.end())
#define ssort(arr) stable_sort(arr.begin(),arr.end())
#define search(arr,c)  binary_search(arr.begin(),arr.end(),c)
#define pb   push_back
#define ll long long
#define cl_bf cin.ignore(numeric_limits<streamsize>::max(), '\n');
#define castl static_cast<ll>
int gcd(int a,int b){
    if (a < b) swap(a, b);
    if (b == 0) return a;
    else return gcd(b, a % b);
}
int main(){
    ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
    ll t,n;cin>>n;ll sum=1;
    vl v(n+1,1);
    if(n==1)cout<<1;
    else{
        rep(i,2,n+1){
            sum+=i*(v[i]+1);
            for(int j=i*2;j<=n;j+=i){
                if(j%i==0)v[j]++;
            }
        }
        cout<<sum;
    }
    return 0;
}

Measured memory_bytes: 81336
#include<bits/stdc++.h>
#include<string>
#include<vector>
#include<algorithm>
#include<iomanip>
using namespace std;


int main(){
    int a[6];
    int lane[6];
    int k=0;
    for(int i=0;i<6;i++){
        cin >> lane[i];
    }
    for(int j=1;j<5;j++){
        a[k] = count(lane,lane+(sizeof(lane)),j);
        k++;
    }
    if(a[0]>2 || a[1]>2 || a[2]>2 || a[3]>2){
        cout << "NO" << endl;
    }else{
        cout << "YES" << endl;
    }
}

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

using namespace std;

inline int toInt(string s) {int v; istringstream sin(s);sin>>v;return v;}
template<class T> inline string toString(T x) {ostringstream sout;sout<<x;return sout.str();}
template<class T> inline T sqr(T x) {return x*x;}

typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<string> vs;
typedef pair<int, int> pii;
typedef long long ll;

#define all(a)  (a).begin(),(a).end()
#define rall(a) (a).rbegin(), (a).rend()
#define pb push_back
#define mp make_pair
#define each(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define exist(s,e) ((s).find(e)!=(s).end())
#define range(i,a,b) for(int i=(a);i<(b);++i)
#define rep(i,n)  range(i,0,n)
#define clr(a,b) memset((a), (b) ,sizeof(a))
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;

const double eps = 1e-10;
const double pi  = acos(-1.0);
const ll INF =1LL << 62;
const int inf =1 << 29;


pii in[40010];

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

int main(void){
	int n;
	while(cin >> n){
		if(n==0) break;

		map<pii,int> memo;
		bool check[40010];
		rep(i,2*n) check[i]=false;
		rep(i,n){
			char dir;
			cin >> in[2*i].first >> in[2*i].second >> dir;
			in[2*i+1]=in[2*i];
			int d=(dir=='x')?2:3;
			in[2*i+1].first+=dx[d],in[2*i+1].second+=dy[d];
			memo[in[2*i]]=2*i;
			memo[in[2*i+1]]=2*i+1;
		}

		bool ans=true;
		rep(i,n){
			if(check[2*i]) continue;
			bool ok=false;
			rep(j,2){
				bool ok2=true;
				map<int,int> color;
				queue<int> q;

				color[2*i]=j;
				color[2*i+1]=j^1;
				check[2*i]=true;
				check[2*i+1]=true;
				q.push(2*i);
				q.push(2*i+1);

				while(!q.empty()){
					int cur=q.front();q.pop();
					pii xy=in[cur];
					rep(l,4){
						pii next=xy;
						next.first+=dx[l],next.second+=dy[l];
						if(memo.find(next)==memo.end()) continue;
						int index=memo[next];
						if(color.find(index)==color.end()){
							color[index]=color[cur];
							color[index^1]=color[cur]^1;
							check[index]=true;
							check[index^1]=true;
							q.push(index);
							q.push(index^1);
						}else if((cur^1)!=index&&color[index]!=color[cur])
							ok2=false;
					}
				}
				if(ok2) ok=true;
			}
			if(!ok) ans=false;
		}
		if(ans)
			puts("Yes");
		else
			puts("No");
	}
	return 0;
}

Measured memory_bytes: 5748
// #pragma comment(linker, "/stack:200000000")
// #pragma GCC optimize("Ofast")
// #pragma GCC target("avx,avx2,fma")
// #pragma GCC optimization("unroll-loops")

#include "bits/stdc++.h"
#define pb push_back
#define mp make_pair
#define mt make_tuple
#define endl '\n'
#define F first
#define S second
#define IO ios::sync_with_stdio(0);cin.tie(0);cout.tie(0)
#define cf ll testcases;cin>>testcases;while(testcases--)
#define prn(x) if(x) cout<<"YES"<<endl; else cout<<"NO"<<endl;
#define all(x) x.begin(),x.end()
#define rall(x) x.rbegin(),x.rend()
#define minel(x) (*min_element(all(x)))
#define maxel(x) (*max_element(all(x)))
#define cou dbg=1;cout
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<ll,ll> pi;
typedef vector<ll> vi;
typedef vector<ld> vd;
typedef vector<pi> vp;
ll dbg=0;
template<typename A, typename B> ostream& operator<<(ostream &cout, pair<A, B> const &p);
template<typename A> ostream& operator<<(ostream &cout, vector<A> const &v);
template<typename A, typename B> istream& operator>>(istream& cin, pair<A, B> &p);
template<typename A> istream& operator>>(istream& cin, vector<A> &v);
int dx[] = {-1, -1, -1,  0, 0,  1, 1, 1};
int dy[] = {-1,  0,  1, -1, 1, -1, 0, 1};

void solve(){
    ll n;
    cin>>n;
    vector<vi> arr(n+1,vi(3));
    for(ll i=1;i<=n;i++){
        cin>>arr[i][0]>>arr[i][1]>>arr[i][2];
    }
    vector<vi> dp(n+1,vi(3,0));
    for(ll i=1;i<=n;i++){
        dp[i][0]=max(dp[i-1][1],dp[i-1][2])+arr[i][0];
        dp[i][1]=max(dp[i-1][0],dp[i-1][2])+arr[i][1];
        dp[i][2]=max(dp[i-1][0],dp[i-1][1])+arr[i][2];
    }
    //cou<<dp<<endl;
    cout<<max({dp[n][0],dp[n][1],dp[n][2]})<<endl;
}

int main(){
    IO;
    // cf
    solve();
    return 0;
}


template<typename A, typename B> ostream& operator<<(ostream &cout, pair<A, B> const &p) { 
    if(dbg){
        return cout << "(" << p.F << ", " << p.S << ")"; 
    }else{
        return cout<<p.F<<' '<<p.S;
    }
        dbg=0;}
template<typename A> ostream& operator<<(ostream &cout, vector<A> const &v) {
    if(dbg){
        cout << "["; for(ll i = 0; i < v.size(); i++) {if (i) cout << ", "; cout << v[i];} return cout << "]";
    }else{
        for(ll i=0;i<v.size()-1;i++) cout<<v[i]<<' ';
        return cout<<v[v.size()-1];
    dbg=0;}
}
template<typename A, typename B> istream& operator>>(istream& cin, pair<A, B> &p) {
   cin >> p.first;
   return cin >> p.second;
}
template<typename A> istream& operator>>(istream& cin, vector<A> &v) {
   for(ll i=0;i<v.size()-1;i++) cin>>v[i];
   return cin >> v[v.size()-1];
}

Measured memory_bytes: 14268
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int A, B, C;
  cin >> A >> B;
  C = (A * B) % 2;
  if (C == 0){
    cout << "Even" << endl;
  } else {
    cout << "Odd" << endl;
  }
}

Measured memory_bytes: 256
import itertools
N,M = map(int,input().split())
A = []

for i in range(M):
  tmp = list(map(int,input().split())) 
  A.append(tmp)
P = list(map(int,input().split()))

#スイッチの状態: 全通りがmaxで2^10 = 10^3
ans = 0 #答え格納用変数
Comb = [0,1]
Comb = itertools.product(Comb, repeat=N)
Comb = list(Comb)

#各スイッチの状態
for i in range(len(Comb)):
  switch_num = [0]*M #各電球について繋がっているスイッチがon状態になっているモノの数
  switch = list(Comb[i])
  for j in range(N):

#スイッチの状態が1つ決まった時の電球の状態
   if(switch[j] == 1):
    for k in range(M):
     for l in range(A[k][0]+1):
      if(l != 0):
       #print(A[k],'l:',l,'j:',j)
       if(A[k][l] == j+1): 
        switch_num[k] += 1
     
  judge = 1
  for k in range(M):
   if(switch_num[k]%2 != P[k]): 
     judge = 0
     break
  if(judge == 1): ans += 1
 
print(ans)  
#
'''
  print('sw',switch)
  print('sw_num',switch_num)
  print('ans',ans)
  print("=====")
'''
#

Measured memory_bytes: 3188
x, y, z = map(int, input().split())
lst = list(map(int, input().split()))
cnt = 0
for _ in range(x):
    lst_a = list(map(int, input().split()))
    total = z
    for i in range(y):
        total += lst[i] * lst_a[i]
    if total > 0:
        cnt += 1
print(cnt)

Measured memory_bytes: 3060
from collections import deque
import sys

r,c = map(int,input().split())
m = [input() for _ in range(r)]


def maze(sy,sx):
    q = deque()
    vm = [[-1] * c for _ in range(r)]

    vm[sy][sx] = 0
    q.append([sy,sx])

    while q:
        y,x = q.popleft()

        for i,j in ([1, 0], [-1, 0], [0, 1], [0, -1]):
            xi , yj = x + i , y + j
            if xi >= 0 and yj >= 0 and xi < c and yj < r and vm[yj][xi] == -1 and m[yj][xi] != "#":
                vm[yj][xi] = vm[y][x] + 1
                q.append([yj,xi])

    ret=0
    for ss in vm:
        ret=max(ret,max(ss))

    return ret

res=0
for h in range(r):
    for w in range(c):
        if m[h][w] == '#':
            continue

        res=max(res,maze(h,w))

print(res)

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

bool ok(ll a,ll b,ll c)
{
    if(a!=b&&a!=c&b!=c&&a+b>c&&a+c>b&&b+c>a) return true;
    return false;
}
int main(void)
{
    int n;
    cin>>n;
    int a[n];
    for(int i=0;i<n;++i)
        cin>>a[i];
    int ans=0;
    for(int i=0;i<n;++i)
        for(int j=i+1;j<n;++j)
            for(int k=j+1;k<n;++k)
                if(ok(a[i],a[j],a[k]))
                    ans++;
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 3612
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(int)n;++i)
#define rrep(i,n) for(int i=(int)n-1;i>=0;--i)
using namespace std;
using ll = long long;
template<typename T> inline bool chmax(T& a,T b){if(a<b){a=b;return 1;}return 0;}
template<typename T> inline bool chmin(T& a,T b){if(b<a){a=b;return 1;}return 0;}
template<typename T> vector<T> make_vec(size_t a){return vector<T>(a);}
template<typename T,typename... Ts>
auto make_vec(size_t a,Ts... ts){return vector<decltype(make_vec<T>(ts...))>(a,make_vec<T>(ts...));}
template<typename T,typename U,typename... V>
typename enable_if<is_same<T,U>::value>::type fill_v(U& u,const V... v){u=U(v...);}
template<typename T,typename U,typename... V>
typename enable_if<!is_same<T,U>::value>::type fill_v(U& u,const V... v){for(auto& e:u)fill_v<T>(e,v...);}

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

    ll r, d, x;
    cin >> r >> d >> x;
    rep(i, 10) {
        x = r * x - d;
        cout << x << endl;
    }
}


Measured memory_bytes: 3596
#include <iostream>
#include <set>

using namespace std;

int main() {
  int N;
  cin >> N;
  set<int> s;


  for(int i = 0; i < N; i++) {
    int input;
    cin >> input;
    s.insert(input);
  }

  cout << s.size();
  return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<cstdio>
#include<vector>
#include<cmath>
#include<algorithm>
#include<functional>
#include<iomanip>
#include<queue>
#include<ciso646>
#include<random>
#include<map>
#include<set>
#include<complex>
#include<bitset>
#include<stack>
#include<unordered_map>
#include<utility>
using namespace std;
typedef long long ll;
typedef unsigned int ui;
const ll mod = 1000000007;
typedef long double ld;
const ll INF = mod*mod;
typedef pair<int, int> P;
#define stop char nyaa;cin>>nyaa;
#define rep(i,n) for(int i=0;i<n;i++)
#define per(i,n) for(int i=n-1;i>=0;i--)
#define Rep(i,sta,n) for(int i=sta;i<n;i++)
#define rep1(i,n) for(int i=1;i<=n;i++)
#define per1(i,n) for(int i=n;i>=1;i--)
#define Rep1(i,sta,n) for(int i=sta;i<=n;i++)
typedef complex<ld> Point;
const ld eps = 1e-8;
const ld pi = acos(-1.0);
typedef pair<ld, ld> LDP;
typedef pair<ll, ll> LP;
int n, p;
int a[50];
ll dp[2];
int main() {
	cin >> n >> p;
	rep(i, n) {
		cin >> a[i]; a[i] %= 2;
	}
	dp[0] = 1;
	rep(i, n) {
		if (a[i] % 2==0) {
			dp[0] *= 2; dp[1] *= 2;
		}
		else {
			ll s = dp[0] + dp[1];
			dp[0] = dp[1] = s;
		}
	}
	cout << dp[p] << endl;
	//stop
	return 0;
}

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

int main(void){
    int n;
    cin >>n;
    vector<long long>ans(100001);
    for(long x=1;n>=x*x*3;x++){
        ans[x*x*6-1]+=1;
    }
    
    for(long x=1;n>=x*x*3;x++){
        for(long y=x+1;n>=x*x*3+y*y+x*y*2;y++){
            ans[x*x*3+y*y+x*y*2-1]+=3;
            
            ans[y*y*3+x*x+x*y*2-1]+=3;
        }
    }
    
    
    for(long x=1;n>=x*x*3;x++){
        for(long y=x+1;n>=x*x*3+y*y+x*y*2;y++){
            for(long z=y+1;n>=x*x+y*y+z*z+x*y+y*z+z*x;z++){
                ans[x*x+y*y+z*z+x*y+y*z+z*x-1]+=6;
            }
        }
    }
    
    for(int i=0;i<n;i++){
        cout << ans.at(i)<<endl;
    }
}


Measured memory_bytes: 3980
module ArrayL = ArrayLabels
module ListL = ListLabels

let dbg = Printf.printf "[debug]%s"

let max_num = 100_000_000_000

let id = fun x -> x
let tuple2 x y = (x,y)
let tuple3 x y z = (x,y,z)
let succ x = x + 1
let pred x = x - 1

let (++) n m =
  let rec aux i =
    if i = m then [m]
    else i :: aux (i+1) in
  if n > m then [] else aux n


let (++^) n m = n ++ (m-1)
let (--) n m = List.rev @@ m++n
let (--^) n m = List.rev @@ (m+1) ++ n

let scan fmt f = Scanf.sscanf (read_line ()) fmt f

let scan_lines n fmt f =
  List.map (fun _ -> scan fmt f) (0++^n)

let scan_matrix n m e conv =
  let arr = Array.make_matrix n m e in
  Array.iteri (fun i line ->
      let s = Scanf.Scanning.from_string @@ read_line () in
      Array.iteri (fun j _ ->
          arr.(i).(j) <- Scanf.bscanf s " %s" conv;
        ) line) arr; arr

let between n x m = n <= x && x < m

let string_to_list s =
  List.map (String.get s) (0 ++^ String.length s)

let print_array arr =
  Array.iteri (fun i a ->
      if i <> 0 then Printf.printf " ";
      Printf.printf "%d" a) arr;
  Printf.printf "\n"

let print_arrayf arr f =
  Array.iteri (fun i a ->
      if i <> 0 then Printf.printf " ";
      f a) arr;
  Printf.printf "\n"

let () =
  let area (w,d) = w*d in

  let rec solve () =
    let (n,w,d) = scan "%d %d %d" tuple3 in
    if n = 0 && w = 0 && d = 0 then ()
    else
      let a = Array.make (succ n) (0,0) in
      a.(0) <- (w, d);
      let k = ref 1 in
      ListL.iter (0 ++^ n) ~f:(fun _ ->
          let (p,s) = scan "%d %d" tuple2 in
          let p = pred p in
          let (w, d) = a.(p) in
          let s = s mod (2*(w+d)) in
          let (x, y) = if s <= w then ((s, d), (w-s, d))
            else if s <= w + d then ((w, s-w), (w, (d-(s-w))))
            else if s <= 2*w + d then ((s-(w+d), d), (w-(s-(w+d)), d))
            else ((w, s-(2*w+d)),(w, d-(s-(2*w+d))))
          in
          ListL.iter (p ++^ Array.length a) ~f:(fun i ->
              if i+1 < Array.length a then a.(i) <- a.(i+1));
          if let (<) (w0,d0) (w1,d1)=  w0*d0 < w1*d1 in x < y then
            (a.(pred !k) <- x; a.(!k) <- y;)
          else (a.(pred !k) <- y; a.(!k) <- x);
          k := succ !k;
          (* Printf.printf "%d => %d, %d => %d\n" p (area a.(p)) (succ p) (area a.(p+1));
           * print_arrayf a (fun (x,y) -> Printf.printf "(%d, %d)" x y);
           * print_array @@ ArrayL.map a ~f:area; *)
        );
      let b = ArrayL.map a ~f:area in
      Array.sort compare b;
      print_array b;
      solve ()
  in
  solve ()



Measured memory_bytes: 4388
#include<iostream>
#include<algorithm>
using namespace std;
int main(){
	int n;
	while(cin >> n && n){
		long long int p;
		long long int jo[65005];
		long long int total = 0;
		for(int i=0;i<n;i++){
			cin >> p;
			total += p;
		}
		for(int i=0;i<n-1;i++){
			cin >> jo[i];
		}
		sort(jo,jo+(n-1),greater<long long int>() );
		long long int ans = 0;
		long long int k = n;
		long long tmp = total;
		for(int i=0;k>0;k--,i++){
			ans = max(ans,tmp*k);
			tmp += jo[i];
		}
		cout << ans << endl;
	}
}

Measured memory_bytes: 1688
#include<iostream>
#include<string>
#include<cmath>
#include<cstdio>
#include<vector>
#include<stack>
#include<queue>
#include<algorithm>
#include<complex>
using namespace std ;
typedef vector<int> vi ;
typedef vector<vi> vvi ;
typedef vector<string> vs ;
typedef pair<int, int> pii; 
typedef long long ll ;

#define loop(i,a,b) for(int i = a ; i < b ; i ++)
#define rep(i,a) loop(i,0,a)
#define all(a) (a).begin(),(a).end()
#define EPS 1e-9

int main(void){
  int a,b,c,d,e,f;
  float x,y,dx,dy;
  while(cin >> a >> b >> c >> d >> e >> f){
    x = (c*e-b*f) / (float)(a*e-b*d);
    y = (c - a*x) / (float)b;
    printf("%.3f %.3f\n",x+EPS,y+EPS);
  }
}

Measured memory_bytes: 1196
#include <iostream>
#include <vector>
#include <algorithm>
#include <stack>
using namespace std;
typedef pair<char, int> P;

const int MAX_N = 100000, MAX_Q = 100000;
int N, Q;

int par[MAX_N+5];
int par2[MAX_N+5];
bool marked[MAX_N+5];

stack<P> s;

void init(int N) {
    for(int i = 0; i <= N; i++) {
        par[i] = i;
        par2[i] = i;
        marked[i] = false;
    }
}

int find(int n) {
    if(par[n] == n) return n;
    par[n] = find(par[n]);
    return par[n];
}

bool same(int x, int y) {
    return find(x) == find(y);
}

void unite(int x, int y) {
    // x is above
    if(same(x, y)) return;
    par[y] = x;
}

void show_par() {
    for(int i = 1; i <= N; i++) {
        cout << i << ": " << par[i] << ", ";
    }
    cout << endl;
}

int main() {
    while(true) {
        // input
        cin >> N >> Q;
        if(!N && !Q) break;
        init(N);
        int p;
        for(int i = 2; i <= N; i++) {
            cin >> p;
            par2[i] = p;
        }
        char c;
        int t;
        for(int i = 0; i < Q; i++) {
            cin >> c >> t;
            if(c == 'M') {
                if(marked[t]) continue;
                marked[t] = true;
            }
            P q;
            q.first = c;
            q.second = t;
            s.push(q);
        }

        // solve
        for(int i = 1; i <= N; i++) {
            if(!marked[i]) unite(par2[i], i);
        }
        long long int ans = 0;
        // show_par();
        while(!s.empty()) {
            P q = s.top(); s.pop();
            if(q.first == 'M') {
                unite(par2[q.second], q.second);
            } else {
                ans += find(q.second);
            }
            // cout << v[i].first << " " << v[i].second << endl;
            // show_par();
        }
        cout << ans << endl;
    }
    return 0;
}

Measured memory_bytes: 2824
#include <iostream>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
#include <cstring>
#include <bitset>
#include <cmath>

#define ll long long

using namespace std;

//struct UnionFind{vector<int> par,rank;UnionFind(int n=1){init(n);}init(int n=1){par.resize(n);rank.resize(n);for(int i=0;i<n;++i)par[i]=i,rank[i]=0;}int root(int x){if(par[x]==x)return x;else{int r=root(par[x]);return par[x]=r;}}bool issame(int x,int y){return root(x)==root(y);}bool merge(int x,int y){x=root(x),y=root(y);if(x==y)return false;if(rank[x]<rank[y])swap(x,y);if(rank[x]==rank[y])++rank[x];par[y]=x;return true;}};

vector<string> ACGT = {"A", "C", "G", "T"};
bool check(string s, string a) {
    bool res = true;
    // *AGC
    res &= !(s.substr(1, 2) == "AG" && a == "C");
    // *ACG
    res &= !(s.substr(1, 2) == "AC" && a == "G");
    // *GAC
    res &= !(s.substr(1, 2) == "GA" && a == "C");
    // A*GC 
    res &= !(s[0] == 'A' && s[2] == 'G' && a == "C");
    // AG*C
    res &= !(s.substr(0, 2) == "AG" && a == "C");

    return res;
}

int main() {
    int N; cin >> N;
    ll MOD = pow(10, 9) + 7;

    vector<map<string, ll>> dp(110, map<string, ll>());
    for (auto a: ACGT) {for (auto b: ACGT) {for (auto c: ACGT) {
        string last3 = a + b + c;
        if (last3 != "AGC" && last3 != "ACG" && last3 != "GAC") dp[3][last3] = 1;
    }}}

    for (int i = 3; i < N; ++i) {
        for (auto x: dp[i]) {
            for (auto a: ACGT) {
                if (check(x.first, a)) dp[i+1][x.first.substr(1, 2) + a] += dp[i][x.first]%MOD;
            }
        }
    }

    ll res = 0;
    for (auto x: dp[N]) res = res%MOD + x.second;
    cout << res%MOD << endl;
}


Measured memory_bytes: 896