akhauriyash/Code-Regression huggingface dataset:
#ifndef _TEMPLATE_ROOT
#define _TEMPLATE_ROOT
#include "bits/stdc++.h"
using namespace std;
#define rep(i, a, b) for(int i = a; i < (b); ++i)
#define repl(i, a, b) for(ll i = a; i < (b); ++i)
#define repd(i, a, b) for(int i = b; i >= (a); --i)
#define repdl(i, a, b) for(ll i = b; i >= (a); --i)
#define all(x) begin(x), end(x)
#define sz(x) (int)(x).size()
typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;
template<typename H> bool chmin(H& v1, const H v2) { if (v1 > v2) { v1 = v2; return true; } return false; }
template<typename H> bool ihmax(H& v1, const H v2) { if (v1 < v2) { v1 = v2; return true; } return false; }
#endif
#ifndef _TEMPLATE_IO
#define _TEMPLATE_IO

template<typename H> void read(H& head) { cin >> head; }
template<typename H, typename ...T> void read(H& head, T& ...tail) { cin >> head; read(tail...); }
template<typename H> void write(H head) { cout << head << '\n'; }
template<typename H, typename ...T> void write(H head, T ...tail) { cout << head << " "; write(tail...); }
template<typename ...T> void die(T ...tok) { write(tok...); exit(0); }
#endif
#ifndef _TEMPLATE_OPT
#define _TEMPLATE_OPT
#pragma GCC optimize("Ofast")
#pragma GCC target("avx2")
#endif
using namespace std;

int a[500005];

struct Query {
  int l, r, id, ans;
};

// freqcnt
int freq[500005];
int distinct = 0;
void freqadd(int x) { 
//write("FA", x, freq[x], "->", freq[x]+1);
  if (!freq[x]) distinct++; freq[x]++; }
void freqrem(int x) { 
  
//write("FR", x, freq[x], "->", freq[x]-1);
  freq[x]--; if (!freq[x]) distinct--; }
Query query[500005];

int main() {
	cin.tie(0)->sync_with_stdio(0);
	cin.exceptions(cin.failbit);

  int n, q; read(n, q);
  rep(i, 1, n + 1) read(a[i]);
  rep(i, 0, q) read(query[i].l, query[i].r), query[i].id = i;
  
  const int BS = 1500;
  sort(query, query + q, [](const Query& a, const Query& b) {
    if (a.l / BS != b.l / BS) return a.l / BS < b.l / BS;
    else return a.r < b.r;
    });

  // inclusive [cl, cr]
  int cl = 1, cr = 0;
  rep(i, 0, q) {
    int nl = query[i].l, nr = query[i].r;
    while (cl > nl) freqadd(a[--cl]);
    while (cr < nr) freqadd(a[++cr]);
    while (cl < nl) freqrem(a[cl++]);
    while (cr > nr) freqrem(a[cr--]);
    query[i].ans = distinct;
  }

  sort(query, query + q, [](const Query& a, const Query& b) { return a.id < b.id; });
  rep(i, 0, q) write(query[i].ans);
}



Measured memory_bytes: 15520
from bisect import bisect_left

N,M=map(int,input().split())
A=list(map(int,input().split()))

A.sort()

l=1
r=200000+1

def chk(x):
    c=0
    for la in A:
        y=bisect_left(A,x-la)
        c+=N-y
    if c>=M:
        return True
    else:
        return False



while l+1<r:
    mid=(l+r)//2
    if chk(mid):
        l=mid
    else:
        r=mid

AN=l

S=[0]*(N+1)

for i in range(N):
    S[i+1]=S[i]+A[i]

ans1=0
c=0
for la in A:
    ll = -1
    rr = N
    while ll + 1 < rr:
        mi = (ll + rr) // 2
        if A[mi] > AN - la:
            rr = mi
        else:
            ll = mi
    c+=N-rr
    ans1=ans1+la*(N-rr)+S[N]-S[rr]

ans=ans1+(M-c)*AN
print(ans)




Measured memory_bytes: 55372
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cctype>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <time.h>
#include <tuple>
#include <utility>
#include <vector>
#define ll long long
#define itn int
#define endl '\n'
#define co(ans) cout<<ans<<endl
#define COYE cout<<"YES"<<endl
#define COYe cout<<"Yes"<<endl
#define COye cout<<"yes"<<endl
#define CONO cout<<"NO"<<endl
#define CONo cout<<"No"<<endl
#define COno cout<<"no"<<endl
#define FORE(i,a) for(auto &i:a)
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define FFOR(i,a,b) for(int i=(a);i<=(b);++i)
#define REP(i,n)  FOR(i,0,n)
#define RREP(i,n)  FFOR(i,1,n)
#define PB push_back
#define MP make_pair
#define ALL(V) (V).begin(),(V).end()
#define SORT(V) sort((V).begin(),(V).end())
#define REVERSE(V) reverse((V).begin(),(V).end())
#define EACH(V,i) for(typeof((V).begin()) i=(V).begin();i!=(V).end();++i)
#define equals(a,b) (fabs((a)-(b))<EPS)
#define INF ((1LL<<62)-(1LL<<31))
#define EPS 1e-10
#define PI 3.141592653589793238
#define MOD 1000000007
#define MAX 5100000
using namespace std;
using Edge=pair<int,int>;
using Graph=vector<vector<int>>;
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>bool chmax(T &a,const T &b){if(a<b){a=b;return 1;}return 0;}
template<class T>bool chmin(T &a,const T &b){if(b<a){a=b;return 1;}return 0;}
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef long long LL;
const int dx[4]={0,1,0,-1},dy[4]={1,0,-1,0};
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
ll lcm(ll a,ll b){return a/gcd(a,b)*b;}

int main(){
  ll N;
  cin>>N;
  string S="";
  
  while(N>0){
    ll T=N%26;
    if(T==0) T=26;
    
    S+='a'+T-1;
    N=(N-T)/26;
  }
  
  REP(i,S.size()) cout<<S[S.size()-1-i];
  cout<<endl;
  return 0;
}

Measured memory_bytes: 3632
function main(input) {
  const nums = input.split(" ").map(num => parseInt(num, 10))
  console.log(nums[0] >= 13 ? nums[1] : nums[0] >= 6 ? nums[1] / 2 : 0)
}
 
main(require("fs").readFileSync("/dev/stdin", "utf8"))


Measured memory_bytes: 7372
N, M, K = map(int, input().split())
A = list(map(int, input().split()))
B = list(map(int, input().split()))
a, b = [0], [0]
for i in range(N):
  a.append(a[i] + A[i])
for i in range(M):
  b.append(b[i] + B[i])

ans, j = 0, M
for i in range(N + 1):
  if a[i] > K:
     break
  else:
    while b[j] > K - a[i]:
      j -= 1
  ans = max(ans, i + j)
print(ans)

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

int main()
{
	int n, k;
	cin >> n >> k;
	k = k + 1;
	vector<int> c(n);
	vector<int> v(n);
	for (int i = 0; i < n; i++) {
		cin >> v[i];
	}
	c[0] = 0;
	for (int i = 1; i < n; i++) {
		c[i] = c[i - 1] + abs(v[i] - v[i - 1]);
	}
	for (int i = 0; i < n; i++) {
		for (int j = 1; j < k; j++) {
			int t = i - j;
			if (t >= 0)
				if (c[i] > c[t] + abs(v[t] - v[i]))
					c[i] = c[t] + abs(v[t] - v[i]);
		}
	}
	cout << c[n - 1];
}


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

int main() { 	
 int A,B,C,D,E,F,G;
 cin >>A>>B;
 vector<int> AA(1);
  vector<int> BB(1);
  
 C=A+B;
 D=A-B;
 E=A*B;

F=max(C, D);
G=max(F, E);
	cout <<G<<endl; 
 
}

Measured memory_bytes: 256
#include <algorithm>
#include <array>
#include <cstddef>
#include <cstdint>
#include <iomanip>
#include <iostream>
#include <map>
#include <set>
#include <vector>

using namespace std;

int main()
{
    string s;
    cin >> s;
    for (int i = 0; i < s.size(); i += 2)
    {
        cout << s[i];
    }
    cout << endl;
}


Measured memory_bytes: 512
#include <stdio.h>

int main() {
	char ch;
	
	scanf("%c", &ch);
	
	if (ch >= 'A' && ch <= 'Z') {
		printf("A");
	}
	else if (ch >= 'a' && ch <= 'z') {
		printf("a");
	}
	
	return 0;
}

Measured memory_bytes: 1572
#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 N, M;
    cin >> N >> M;
    vector<int> A(M);
    int asi=0;
    rep(i, M){
        cin >> A.at(i);
        asi+=A.at(i);
    }
    int play;
    play = N - asi;
    
    if(play<0){
        cout << -1 << endl;
    }else{
        cout << play << endl;
    }
    return 0;
}

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

using namespace std;
using ll = long long;

//container util
#define SORT(c) sort((c).begin(),(c).end())

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

const int INF = 1e9;

int main(void){


	int N, M; cin >> N >> M;
	vector<int> s(M);
	vector<int> c(M);
	REP(i,M) cin >> s[i] >> c[i];

	int tmp = pow(10, N-1);
	int end = tmp * 10;
	if(N == 1) tmp = 0;

	while(tmp != end){
		string S = to_string(tmp);
		int cnt = 0;
		REP(i,M){
			if(S[s[i]-1] == (char)c[i] + '0') cnt++;
		}
		if(cnt == M){
			cout << tmp << endl;
			return 0;
		}
	tmp++;
	}

	cout << -1 << endl;



	return 0;

}


Measured memory_bytes: 256
# import itertools
# import math
# import sys
# sys.setrecursionlimit(500*500)
# import numpy as np
# import heapq
# from collections import deque

N = int(input())
# S = input()
# n, *a = map(int, open(0))
# N, M = map(int, input().split())
# A = list(map(int, input().split()))
# B = list(map(int, input().split()))
# tree = [[] for _ in range(N + 1)]
# B_C = [list(map(int,input().split())) for _ in range(M)]
# S = input()

# B_C = sorted(B_C, reverse=True, key=lambda x:x[1])
# all_cases = list(itertools.permutations(P))
# a = list(itertools.combinations_with_replacement(range(1, M + 1), N))
# itertools.product((0,1), repeat=n)

# A = np.array(A)
# cum_A = np.cumsum(A)
# cum_A = np.insert(cum_A, 0, 0)

# def dfs(tree, s):
#     for l in tree[s]:
#         if depth[l[0]] == -1:
#             depth[l[0]] = depth[s] + l[1]
#             dfs(tree, l[0])
# dfs(tree, 1)

# def factorization(n):
#     arr = []
#     temp = n
#     for i in range(2, int(-(-n**0.5//1))+1):
#         if temp%i==0:
#             cnt=0
#             while temp%i==0:
#                 cnt+=1
#                 temp //= i
#             arr.append([i, cnt])
#     if temp!=1:
#         arr.append([temp, 1])
#     if arr==[]:
#         arr.append([n, 1])
#     return arr

cnt = 0
for a in range(1, N):
    cnt += (N - 1) // a
print(cnt)

Measured memory_bytes: 9024
// C
 
#include <bits/stdc++.h>
using ll = long long;
using namespace std;
ll mod=1e9+7;
#define pa(x,n) for(ll i=0;i<n;i++){cout<<(x[i])<<" \n"[i==n-1];};
 
int main(){
  int N,K,S;
  cin>>N>>K>>S;
  for (int i(0);i<K;i++){
    cout << S << " ";
  }
  for (int i(0);i<N-K;i++){
    if (S != 1000000000){
      cout << 1000000000 <<" ";
    }else{
      cout << 1 <<" ";
    }
  }
  return 0;
}

Measured memory_bytes: 1280
#include <iostream>
#include <vector>
#include <string>
#include <cmath>
#include <algorithm>
#include <map>
#include <iomanip>
#include <stdlib.h>
#include <queue>

using namespace std;

const int nmax = 1e9 + 7;
typedef long long ll;

int main(){

  int H, W; cin >> H >> W;
  
  char S[H][W];
  for (int i = 0; i < H; i++){
    for (int j = 0; j < W; j++){
      cin >> S[i][j];
    }
  }
  
  bool visited[H][W];
  for (int i = 0; i < H; i++){
    for (int j = 0; j < W; j++){
      visited[i][j] = false;
    }
  }

  queue < pair<int, int> > que;
  que.push(make_pair(0, 0));
  visited[0][0] = true;

  int di[4] = {-1, 0, 1, 0};
  int dj[4] = {0, 1, 0, -1};

  int nowi = 0;

  ll X = 0, Y = 0;
  ll ans = 0;

  while (!que.empty()){
    pair <int, int> P = que.front(); que.pop();

    if (S[P.first][P.second] == '.') X++;
    else Y++;

    for (int i = 0; i < 4; i++){
      int I = P.first + di[i];
      int J = P.second + dj[i];

      if (0 <= I && I < H && 0 <= J && J < W && visited[I][J] == false){
        if (S[P.first][P.second] != S[I][J]){
          visited[I][J] = true;
          que.push(make_pair(I, J));
        }
      }
    }
    
    if (que.empty()){
      ans += X * Y;
      X = 0; Y = 0;

      bool flag = false;
      for (int i = nowi; i < H; i++){
        for (int j = 0; j < W; j++){
          if (visited[i][j] == false){
            que.push(make_pair(i, j));
            visited[i][j] = true;
            flag = true;
            break;
          }
        }
        if (flag == false){
          nowi++;
        }else{
          break;
        }
      }
    }
  }
  
  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 512
const calc = (n) => {
  if (n % 2 === 0) {
    return n / 2
  }
  return n * 3 + 1
}

const solve = (input) => {
  const n = Number(input)
  let r = 1
  let resultMap = {
    [n]: true
  }
  let last = n
  while (1) {
    r++
    last = calc(last)
    if (resultMap[last]) {
      break
    } else {
      resultMap[last] = true
    }
  }
  return r
}

if (process.env.NODE_ENV === "test") {
  module.exports = (input) => solve(input.trim())
} else {
  const input = require("fs").readFileSync("/dev/stdin", "utf8")
  console.log(solve(input.trim()))
}


Measured memory_bytes: 7372
#include<bits/stdc++.h>
using namespace std;
#define ll long long
ll gcd(ll x, ll y)
{
	ll r;
	while ((r = x % y) != 0)
	{
		x = y;
		y = r;
	}
	return y;
}

ll lcm(ll x, ll y)
{
	x /= gcd(x, y);
	//y /= gcd(x, y);
	return (x * y);
}

int main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	long long a, b, c,d;
	cin >> a >> b >> c >> d;
	long long aa = (a-1) / c;
	long long bb = b / c;
	long long cc = (a-1) / d;
	long long dd = b / d;
	long long e = lcm(c, d);
	long long ee = (a-1) / e;
	long long eee = b / e;
	
	cout << (b - a) - (bb - aa) - (dd - cc) + (eee - ee) + 1 << endl;
	return 0;
}


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

using namespace std;
const int S = 1 << 14;

int n, A, X, O;
int U;
vector<int> G[S];

int dfn[S], low[S], timer;
int stk[S], top; bool inS[S];
int cmp[S], scc;
void tarjan(int x) {
    dfn[x] = low[x] = ++timer;
    inS[stk[++top] = x] = true;
    for (auto y : G[x]) {
        if (!dfn[y]) tarjan(y), low[x] = min(low[x], low[y]);
        else if (inS[y]) low[x] = min(low[x], dfn[y]);
    }
    if (low[x] == dfn[x]) {
		++scc;
		do {
			x = stk[top--];
			inS[x] = false, cmp[x] = scc;
		} while (low[x] != dfn[x]);
	}
}

int select[S];
signed main() {
    scanf("%d%d%d%d", &n, &X, &A, &O);
    U = 1 << (n + 1);

    for (int i = 0; i < U; i++) {
        if ((A & i) == A) {
            int j = (~i) & (U - 1);
            for (int k = j; ; k = (k - 1) & j) {
                int p = A | k;
                G[p].push_back(i ^ X);
                G[i].push_back(p ^ X);
                if (!k) break;
            }
        }
        if ((O | i) == O) {
            int j = i;
            for (int k = j; ; k = (k - 1) & j) {
                int p = (O ^ i) | k;
                G[p].push_back(i ^ X);
                G[i].push_back(p ^ X);
                if (!k) break;
            }
        }
    }

    for (int i = 0; i < U; i++)
        if (!dfn[i]) tarjan(i);
    
    for (int i = 0; i < U; i++)
        if (cmp[i] == cmp[i ^ X]) {
            puts("No");
            return 0;
        }
    
    puts("Yes");
    vector<int> ans;

    for (int i = 0; i < U; i++)
        if (cmp[i] < cmp[i ^ X])
            ans.push_back(i);
    
    for (int i = 0; i < (int)ans.size() - 1; i++)
        printf("%d ", ans[i]);

    return printf("%d\n", ans.back()), 0;
}


Measured memory_bytes: 138852
n = int(input())
ls = [0] * n
for i in range(n):
    a = int(input())
    ls[i] = a

ans = 0
for i in range(n-1):
    if ls[i] % 2 == 1 and ls[i+1] > 0:
        ls[i] += 1
        ls[i+1] -= 1
    ans += ls[i] // 2
ans += ls[-1] // 2
print(ans)


Measured memory_bytes: 70872
#include "bits/stdc++.h"
using namespace std;
using lint = long long;
#define low lower_bound
#define upp upper_bound
#define rep(i, n) for (lint i = 0; i < lint(n); ++i)
#define Rep(i, n) for (lint i = lint(n); i >= 0; --i)
#define all(vec) (vec).begin(), (vec).end()
#define cend printf("\n");
#define prique(T) priority_queue<T, vector<T>, greater<T>>
#define prique2(T) priority_queue<T>

struct edge { int to; double cost; };
using P = pair<lint, lint>;
using D = pair<double, double>;
using DI = pair<double, int>;
//const lint mod = 998244353LL;
const lint mod = 1000000007LL;
const lint inf = 3LL * mod * mod;

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;
}

lint modpow(lint x, lint n, lint m) {
	lint ans = 1;
	while (n > 0) {
		if (n & 1) {
			ans *= x;
			if (m <= ans) ans %= m;
		}
		x *= x;
		if (m <= x) x %= m;
		n >>= 1;
	}
	return ans;
}

lint fact[1000000];
void f_init(lint n) {
	if (1000000 <= n) return;
	fact[0] = fact[1] = 1;
	for (lint i = 2; i <= n; ++i) {
		fact[i] = i * fact[i - 1];
		if (mod <= fact[i]) fact[i] %= mod;
	}
	return;
}

lint inver[1000000]; bool inve[100000];
lint inv(lint x) {
	if (x == 0) return 0;
	else if (inve[x]) return inver[x];
	else {
		inve[x] = true;
		return inver[x] = modpow(x, mod - 2, mod);
	}
}

lint comb(lint n, lint r) {
	if (n < r) return 0;
	if (n == r) return 1;
	lint ans = fact[n] * inv(fact[n - r]) % mod * inv(fact[r]) % mod;
	if (ans < 0) return ans + mod;
	return ans;
}

lint nck[1010][1010];
void comb(lint n) {
	rep(i, n + 1) {
		rep(j, i + 1) {
			if (j == 0 || i == j) nck[i][j] = 1;
			else nck[i][j] = nck[i - 1][j - 1] + nck[i - 1][j];
		}
	}
}

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

lint lcm(lint a, lint b) { return a / gcd(a, b) * b; }

bool pri(lint p) {
	for (lint i = 2; i * i <= p; i == 2 ? ++i : i += 2) if (p % i == 0) return false;
	return p > 1;
}

map<lint, lint> factring(lint n) {
	map<lint, lint>ans;
	for (lint i = 2; i * i <= n; ++i) {
		while (n % i == 0) {
			n /= i;
			++ans[i];
		}
	}
	if (n != 1) ++ans[n];
	return ans;
}

double dis(D a, D b) { return sqrt((a.first - b.first) * (a.first - b.first) + (a.second - b.second) * (a.second - b.second)); }

int n, d[55], ans = 24;
int main() {
	cin >> n;
	rep(i, n) {
		cin >> d[i + 1];
	}
	sort(d, d + n + 1);
	for (int i = 0; i < n + 1; i += 2) {
		d[i] = 24 - d[i];
	}
	rep(i, n + 1) {
		for (int j = i + 1; j < n + 1; ++j) {
			ans = min(ans, min(abs(d[i] - d[j]), 24 - abs(d[i] - d[j])));
		}
	}
	cout << ans << endl;


}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define si(a) scanf("%d",&a)
#define fore(i,a,b) for(int i=a;i<b;++i)
#define sorte(a) sort(a.begin(), a.end())
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef pair<int,int> pi;
ll f(ll n,ll k){
	return n/k;
}
int main(){
	ll a,b,c,d,e;
	scanf("%lld %lld %lld %lld",&a,&b,&c,&d);
	e=(c*d)/__gcd(c,d);
	ll par1,par2;
	par1=f(b,c)+f(b,d)-f(b,e);
	par2=f(a-1,c)+f(a-1,d)-f(a-1,e);
	printf("%lld\n",b-a+1-(par1-par2));
	return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<cmath>
#include<queue>
#include<string>
#include<cstring>
#include<algorithm>
#include<set>
#include<map>

#define REP(i,n) for(int i=0;i<(n);i++)
#define EPS (1e-7)
#define INF (3e9)

using namespace std;
typedef long long int ll;

int a,b,c;
int main(void){
    cin >> a >> b >> c;
    if(a+b+c>=22) cout << "bust" << endl;
    else cout << "win" << endl;
    return 0;
}



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

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

    int min_withouttax = ceil(A / 0.08);
    int withouttax = min_withouttax;
    
    while(floor(withouttax * 0.1) != B){
        withouttax++;
        if(floor(withouttax * 0.08) != A){
            cout << -1 << endl;
            return 0;
        }
    }
    cout << withouttax << endl;
    return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
#define N 101

int main(void){

  int n;
  int i, j, vertex;
  int num, e;
  int Matrix[N][N];

  scanf("%d",&n);
 

  for(i = 1;i <= n;i++){
    for(j = 1;j <= n;j++)
      Matrix[i][j] = 0;
  }

  for(i = 1;i <= n;i++){
    scanf("%d %d", &vertex, &e);
    for(j = 1;j <= e;j++){
      scanf("%d", &num);
      if(Matrix[vertex][num] == 0)
	Matrix[vertex][num] = 1;
    }
  }

  for(i = 1;i <= n;i++){
    for(j = 1;j < n;j++)
      printf("%d ",Matrix[i][j]);
    printf("%d\n",Matrix[i][j]);
  }
  
  return 0;
}

Measured memory_bytes: 636
#include <vector>
#include <list>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>
#include <climits>

#define int long long
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define REP(i, n) FOR(i, 0, n)
#define ALL(a) (a).begin(), (a).end()
#define PB push_back
#define MP make_pair
#define FST first
#define SND second
#define SZ(a) (signed)((a).size())
#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 SORT(c) sort((c).begin(), (c).end())

using namespace std;

typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;

const int MOD = 1000000007;
const char ENDL = '\n';

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

vector<set<PII>> vs;

void fn(PII x){
    for (int l = 1; l <10 ; ++l) {
        auto itr=vs[l].find(x);
        if(itr!=vs[l].end()){
            vs[l].erase(itr);
            vs[l+1].insert(x);
            return;
        }
    }
    if(vs[10].find(x)==vs[10].end()){
        vs[1].insert(x);
    }
}

signed main(void) {
    ios::sync_with_stdio(false);
    cout.setf(ios::fixed, ios::floatfield);
    cout.precision(10);
    cin.tie(0);

    int h,w,n;
    cin >> h >> w >> n;
    VI a(n),b(n);
    REP(i,n){
        cin >> a[i] >> b[i];
        a[i]--;
        b[i]--;
    }

    vs.resize(11,set<PII>());

    REP(i,n){
        for (int j = -1; j <=1 ; ++j) {
            for (int k = -1; k <=1 ; ++k) {
                int x=a[i]+j,y=b[i]+k;
                if(x<=0 || h-1 <= x || y<=0 || w-1 <=y){
                    continue;
                }
                fn(MP(x,y));
            }
        }
    }
    int ans = (h-2)*(w-2);
    FOR(i,1,10){
        ans -= vs[i].size();
    }
    cout << ans << ENDL;

    FOR(i,1,10){
        cout << vs[i].size() << ENDL;
    }
    
    return 0;
}

Measured memory_bytes: 58112
import numpy as np

n, k = list(map(lambda x: int(x), input().split(' ')))
teles = list(map(lambda x: int(x)-1, input().split(' ')))

beforeloop = 0
loop = []

done = False

ni, nj = 0, 0
pi, pj = 0, 0
while True:
  pi = teles[pi]
  pj = teles[teles[pj]]
  ni += 1
  nj += 2
  # ni回, piにて確実にループ内
  # ループ一周は nj - ni(= ni)要素&回
  if ni == k:
    print(pi+1)
    done = True
    break
  if pi == pj:
    beforeloop = ni
    break
    
if not done:
  current = pi
  loop.append(current)
  while True:
    current = teles[current]
    if current == pi:
      break
    loop.append(current)
  print(loop[(k - beforeloop) % len(loop)]+1)


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

int main(){
    int m[] = {
        0,
        6000,
        4000,
        3000,
        2000
    };
    rep(i,4){
        int a,b;
        cin >> a >> b;
        cout << m[a] * b << endl;
    }
}

Measured memory_bytes: 1164
#include <algorithm>
#include <cstdio>
#include <iostream>
#include <map>
#include <cmath>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>
#include <stdlib.h>
#include <stdio.h>
#include <bitset>
#include <cstring>
#include <deque>
#include <iomanip>
#include <limits>
#include <fstream>
using namespace std;
#define FOR(I,A,B) for(int I = (A); I < (B); ++I)
#define CLR(mat) memset(mat, 0, sizeof(mat))
typedef long long ll;

int main()
{
  ios::sync_with_stdio(false);
  cin.tie(0);
  double d;
  cin >> d;
  cout << setprecision(10) << max(sqrt(2.0)*d, (int)d+1.0) << endl;
}


Measured memory_bytes: 3300
#include <bits/stdc++.h>
#define GET_REP(_1, _2, _3, NAME, ...) NAME
#define rep(...) GET_REP(__VA_ARGS__, irep, _rep)(__VA_ARGS__)
#define rep1(...) GET_REP(__VA_ARGS__, irep1, _rep1)(__VA_ARGS__)
#define _rep(i, n) irep (i, 0, n)
#define _rep1(i, n) irep1(i, 1, n)
#define irep(i, a, n) for (int i = a; i < (int)(n); ++i)
#define irep1(i, a, n) for (int i = a; i <= (int)(n); ++i)
#define rrep(i, n) for (int i = (int)(n) - 1; i >= 0; --i)
#define rrep1(i, n) for (int i = (int)(n); i >= 1; --i)
#define allrep(X, x) for (auto &&X : x)
#define all(x) begin(x), end(x)
#ifdef LOCAL
  #include "../../Lib/cout_container.hpp"
  #define debug(x) cout << #x " => " << (x) << endl
#else
  #define debug(x) 0
#endif
using lint = long long;
constexpr int    INF  = 1 << 29;
constexpr lint   INFL = 1LL << 61;
constexpr int    MOD  = (int)1e9 + 7;
constexpr double EPS  = 1e-9;
using namespace std;
namespace { struct INIT { INIT() { cin.tie(0); ios::sync_with_stdio(false); cout << fixed << setprecision(15); } } INIT; }

int main(void) {
  int n, m;
  cin >> n >> m;
  map<int, int> ab;
  rep (i, n) {
    int a, b;
    cin >> a >> b;
    ab[a] += b;
  }
  lint sum = 0;
  allrep (x, ab) {
    if (m == 0) break;
    lint num = min(x.second, m);
    sum += x.first * num;
    m   -= num;
  }
  cout << sum << endl;
  return 0;
}

Measured memory_bytes: 4992
N,M,C = map(int,input().split())
B = [int(i) for i in input().split()]
A = [[int(i) for i in input().split()] for _ in range(N)]
count = 0
for i in range(N):
    if(sum(j[0]*j[1] for j in zip(A[i],B))+C>0):
        count = count + 1
print(count)

Measured memory_bytes: 3064
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <cstring>
#include <iterator>

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

using namespace std;

struct Food
{
	vector<int> num;
	double g;

	bool operator < (const Food& f) const
	{
		return g < f.g;
	}
};

int main()
{
	vector<int> num;
	vector<pair<int,int> > a;
	vector<string> name;
	int n;
	while(cin >> n && n)
	{
		num.clear();
		a.clear();
		name.clear();
		rep(i,n)
		{
			string f;
			int w,s;
			cin >> f >> w >> s;

			a.push_back(make_pair(w,s));
			name.push_back(f);
			num.push_back(i);
		}

		vector<Food> food;

		do
		{
			bool flag = true;

			rep(i,num.size()-1)
			{
				int count = 0;
				REP(j,i+1,num.size())
				{
					count += a[num[j]].first;
				}

				if(a[num[i]].second < count)
				{
					flag = false;
				}
			}

			if(flag)
			{
				Food f;
				copy(num.begin(),num.end(),back_inserter(f.num));
				
				double t_a = 0,t_b = 0;
				int j = 1;
				rep(i,num.size())
				{
					t_a += j*a[num[i]].first;
					t_b += a[num[i]].first;
					j++;
				}
				
				f.g = t_a / t_b;
				food.push_back(f);
			}
		}while(next_permutation(num.begin(),num.end()));
		
		sort(food.begin(),food.end());

		rep(i,food[0].num.size())
		{
			cout << name[food[0].num[i]] << endl;
		}

	}
	return 0;
}

Measured memory_bytes: 22044
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		// TODO Auto-generated method stub
		Scanner sc = new Scanner(System.in);

		int n = sc.nextInt();
		int m = sc.nextInt();
		int c = sc.nextInt();

		int b[] = new int[m];

		for(int i = 0; i < m; i++){
			b[i] = sc.nextInt();
		}

		int count = 0;
		for(int i = 0; i < n; i++){
			int tmp = c;
			for(int j = 0; j < m; j++){
				int a = sc.nextInt();

				tmp += a*b[j];
			}

			if(tmp > 0){
				count++;
			}
		}

		System.out.println(count);

	}

}


Measured memory_bytes: 23124
#include "bits/stdc++.h"
// Begin Header {{{
#define all(x) (x).begin(), (x).end()
#define rep(i, s, n) for (i64 i = (s), i##_limit = (n); i < i##_limit; ++i)
#define repr(i, s, t) for (i64 i = (s), i##_limit = (t); i >= i##_limit; --i)
#define repc(i, s, t) for (i64 i = (s), i##_limit = (t); i <= i##_limit; ++i)
#define var(type, ...) \
    type __VA_ARGS__;  \
    read(__VA_ARGS__);
#ifndef DBG
#define dump(...)
#endif
using namespace std;
using i64 = int_fast64_t;
using pii = pair<i64, i64>;
template <class T, class U>
inline bool chmax(T &a, const U &b) {
    return b > a && (a = b, true);
}
template <class T, class U>
inline bool chmin(T &a, const U &b) {
    return b < a && (a = b, true);
}
constexpr int INF = 0x3f3f3f3f;
constexpr i64 LINF = 0x3f3f3f3f3f3f3f3fLL;

template <class T>
inline vector<T> makeV(const T &initValue, size_t sz) {
    return vector<T>(sz, initValue);
}

template <class T, class... Args>
inline auto makeV(const T &initValue, size_t sz, Args... args) {
    return vector<decltype(makeV<T>(initValue, args...))>(
        sz, makeV<T>(initValue, args...));
}

template <class T>
inline istream &operator>>(istream &is, vector<T> &vec) {
    for (auto &e : vec) is >> e;
    return is;
}

inline void read() {}

template <class Head, class... Tail>
inline void read(Head &head, Tail &... tail) {
    cin >> head;
    read(tail...);
}

inline void print() { cout << "\n"; }

template <class Head, class... Tail>
inline void print(Head &&head, Tail &&... tail) {
    cout << head;
    if (sizeof...(tail)) cout << ' ';
    print(forward<Tail>(tail)...);
}

template <class T>
inline ostream &operator<<(ostream &os, const vector<T> &vec) {
    static constexpr const char *delim[] = {" ", ""};
    for (const auto &e : vec) os << e << delim[&e == &vec.back()];
    return os;
}

template <class Container>
struct Rev {
    Container &x_;
    inline Rev(Container &x) : x_(x) {}
    inline auto begin() { return rbegin(x_); }
    inline auto end() { return rend(x_); }
};
// }}} End Header

int N;
vector<pair<int, int>> G[100010];
int deg[100010];
int ans[100010];

void dfs(int v, int ngInk, int from) {
    int ink = 1;
    for (const auto [to, id] : G[v]) {
        if (to == from) continue;
        if (ink == ngInk) ++ink;
        ans[id] = ink;
        dfs(to, ink, v);
        ++ink;
    }
}

signed main() {
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    cout.setf(ios_base::fixed);
    cout.precision(12);

    read(N);
    rep(i, 0, N - 1) {
        var(int, a, b);
        --a, --b;
        G[a].emplace_back(b, i);
        G[b].emplace_back(a, i);
        deg[a]++;
        deg[b]++;
    }

    const int root = max_element(deg, deg + N) - deg;
    const int K = deg[root];

    int ink = 1;
    for (const auto [to, id] : G[root]) {
        ans[id] = ink;
        dfs(to, ink, root);
        ++ink;
    }

    print(K);
    rep(i, 0, N - 1) { print(ans[i]); }

    return 0;
}


Measured memory_bytes: 12692
#include <stdio.h>
int main()
{
	int a, b, c;
	scanf("%d", &a);
	scanf("%d", &b);
	scanf("%d", &c);

	if(a * c <= b)
		printf("%d\n", c);
	else
		printf("%d\n", b/ a);
	return 0;
}

Measured memory_bytes: 128
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <cmath>
#include <vector>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <queue>
#include <ctime>
#include <cassert>
#include <complex>
#include <string>
#include <cstring>
#include <chrono>
#include <random>
#include <queue>
#include <bitset>
#include <stack>
#include <functional>

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

#define rep_(i, a_, b_, a, b, ...) for (int i = (a), i##_len = (b); i < i##_len; ++i)
#define rep(i, ...) rep_(i, __VA_ARGS__, __VA_ARGS__, 0, __VA_ARGS__)
#define reprev_(i, a_, b_, a, b, ...) for (int i = (b-1), i##_min = (a); i >= i##_min; --i)
#define reprev(i, ...) reprev_(i, __VA_ARGS__, __VA_ARGS__, 0, __VA_ARGS__)
#define all(x) (x).begin(), (x).end()
template <class T> bool chmax(T &a, const T &b) { if (a < b) { a = b; return 1; } return 0; }
template <class T> bool chmin(T &a, const T &b) { if (b < a) { a = b; return 1; } return 0; }
// template <class T> T gcd(T a, T b) { return b ? gcd(b, a % b) : a; }
using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef pair <int,int> P;
typedef long double ld;

int main (void)
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    string s; cin >> s;
    cout << s.front() << s.size() - 2 << s.back() << "\n";
    return 0;
}

Measured memory_bytes: 3636
get(Number) :-
 current_input(Input),
 read_string(Input, "\n", "", _, String),
 number_string(Number,String).

solve(0,0).
solve(N,S) :-
 M is N-1, solve(M,T), U is (N mod 3)*(N mod 5),
 (U=0 -> A=0 ; A=N), S=A+T.

main :-
 get(N),solve(N,S),T is S,writeln(T).

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

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

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

using namespace std;
typedef long long LL;
using Graph = vector<vector<int>>;

static long long INF = (1LL<<62);

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

	string S;
	cin >> S;

	LL ans = 0;
	for(int i=0; i<S.size(); i++){
		char c[2] = {0};
		c[0] = S[i];
		int a = atoi(c);
		ans += a;
		ans %= 9;
	}

	if(ans == 0){
		printf("Yes\n");
	}
	else{
		printf("No\n");
	}
	return 0;
}



Measured memory_bytes: 3740
#include<bits/stdc++.h>
using namespace std;
typedef pair<int,int> pi;
int arr[505][505];

int main(){
	int h,w;
	cin>>h>>w;
	for(int i=0; i<h; i++){
		for(int j=0; j<w; j++) cin>>arr[i][j];
	}
	int p = 0;
	int ret = 0;
	vector<pi>start; 
	vector<pi>fin;
	bool forward = true;
	for(int i=0; i<h; i++){
		if(forward){
			for(int j=0; j<w; j++){
				if(arr[i][j]%2 && !(i==h-1 && j==w-1)){
					ret++;
					start.push_back(pi(i,j));
					if(j==w-1){
						 fin.push_back(pi(i+1,j));
						 arr[i+1][j]++;
					}
					else{
						fin.push_back(pi(i,j+1));
						arr[i][j+1]++;
					}
				}
			}
		}
		else{
			for(int j=w-1; j>=0; j--){
				if(arr[i][j]%2 && !(i==h-1 && j!=0)){
					ret++;
					start.push_back(pi(i,j));
					if(j==0){
						 fin.push_back(pi(i+1,j));
						 arr[i+1][j]++;
					}
					else{
						fin.push_back(pi(i,j-1));
						arr[i][j-1]++;
					}
				}
			}
		}
	}
	cout<<ret<<'\n';
	for(int i=0; i<start.size(); i++){
		cout<<start[i].first+1<<" "<<start[i].second+1<<" "<<fin[i].first+1<<" "<<fin[i].second+1<<'\n';
	}
}

Measured memory_bytes: 6336
#include <bits/stdc++.h>
 
const double pi = 3.141592653589793238462643383279;
using namespace std;
//typedef
//------------------------------------------
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef pair<long long, long long> PLL;
typedef pair<int, PII> TIII;
typedef long long LL;
typedef unsigned long long ULL;
typedef vector<LL> VLL;
typedef vector<VLL> VVLL;
 
 
//container util
//------------------------------------------
#define ALL(a)  (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define MP make_pair
#define SZ(a) int((a).size())
#define SQ(a) ((a)*(a))
#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 SORT(c) sort((c).begin(),(c).end())
 
 
//repetition
//------------------------------------------
#define FOR(i,s,n) for(int i=s;i<(int)n;++i)
#define REP(i,n) FOR(i,0,n)
#define MOD 1000000007
 
 
#define rep(i, a, b) for(int i = a; i < (b); ++i)
#define trav(a, x) for(auto& a : x)
#define all(x) x.begin(), x.end()
#define sz(x) (int)(x).size()
 
typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;
 
#define chmin(x,y) x=min(x,y)
#define chmax(x,y) x=max(x,y)

//ここから編集 

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout << fixed << setprecision(10);
  
  int N; cin >> N;
  string s; cin >> s;

  int cntw=0,cntr=0;
  
  REP(i,N){
    if(s[i] == 'W') cntw++;
    else cntr++;
  }
  if(cntw == N) {
    cout << 0 << endl;
  }else if(cntr == N){
    cout << 0 << endl;
  }else{

    int ans = 0;
    for(int i=0; i<cntr; i++){
      if(s[i] == 'W'){
        ans++;
      }
    }
    cout << ans << endl;
  }
  return 0;
}


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

#define mod 1000000007
#define pi 2 * acos(0.0)
#define for0(i, n) for (int i = 0; i < n; i++)
#define for1(i, n) for (int i = 1; i <= n; i++)
#define loop(i, a, b) for (int i = a; i < b; i++)
#define rloop(i, a, b) for (int i = a; i >= b; i--)
void fun()
{
    ios_base::sync_with_stdio(false), cin.tie(NULL), cout.tie(NULL);
#ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
#endif
}

/* DON'T LIMIT YOUR CHALLENGES, CHALLENGE YOUR LIMITS */
void solve()
{
    int n;
    cin >> n;

    vector<vector<int>> v(n, vector<int>(3));
    for (auto &i : v)
    {
        for (auto &j : i)
            cin >> j;
    }

    vector<vector<int>> dp(3, vector<int>(n, 0));
    dp[0][0] = v[0][0], dp[1][0] = v[0][1], dp[2][0] = v[0][2];

    for (int i = 1; i < n; i++)
    {
        dp[0][i] = v[i][0] + max(dp[1][i - 1], dp[2][i - 1]);
        dp[1][i] = v[i][1] + max(dp[0][i - 1], dp[2][i - 1]);
        dp[2][i] = v[i][2] + max(dp[0][i - 1], dp[1][i - 1]);
    }

    cout << max(dp[0][n - 1], max(dp[1][n - 1], dp[2][n - 1]));
}

signed main()
{
    fun();
    int t = 1;
    //cin >> t;
    while (t--)
    {
        solve();
    }

    return 0;
}

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

struct Node{
  Node *right;
  Node *left;
  Node *parent;
  int key;
};

Node *root, *NIL;

void insert(int k){
  Node *y = NIL;
  Node *x = root;
  Node *z;

  z = (Node *)malloc(sizeof(Node));
  z->key = k;
  z->left = NIL;
  z->right = NIL;

  while(x!=NIL){
    y = x;
    if(z->key < x->key) x = x->left;
    else x = x->right;
  }
  z->parent = y;
  if(y==NIL) root = z;
  else{
      if(z->key < y->key) y->left = z;
      else y->right = z;
  }
}

void inorder(Node *u){
  if(u !=NIL){
    inorder(u->left);
    printf(" %d",u->key);
    inorder(u->right);
  }
}

void preorder(Node *u){
  if(u!=NIL){
    printf(" %d",u->key);
    preorder(u->left);
    preorder(u->right);
  }
}

Node * treeMinimum(Node *x) {
    while( x->left != NIL) x = x->left;
    return x;
}

Node * find(Node *u, int k) {
    while( u != NIL && k != u->key ) {
        if(k< u->key) u = u->left;
        else u = u->right;
    }
    return u;
}

Node * treeSuccessor(Node *x) {
    if (x->right != NIL) return treeMinimum(x->right);
    Node *y  = x->parent;
    while(y!=NIL && x == y->right) {
        x = y;
        y = y->parent;
    }
    return y;
}

void treeDelete(Node *u) {
    Node *y;
    Node *x;

    if(u->left == NIL || u->right == NIL) y = u;
    else y = treeSuccessor(u);
    if (y->left != NIL) x = y->left;
    else x = y->right;
    if(x != NIL) x->parent = y->parent;
    if(y->parent == NIL) root = x;
    else {
        if( y == y->parent->left ) y->parent->left = x;
        else y->parent->right = x;
    }
    if(y != u) u->key = y->key;
    free(y);
}


int main(){
  int n, i, x;
  Node *res;
  char com[20];

  scanf("%d", &n);

  for ( i = 0; i < n; i++ ){
    scanf("%s", com);
    if ( com[0] == 'i' ){
      scanf("%d", &x);
      insert(x);
    }
     else if ( com[0] == 'p' ){
      inorder(root);
      printf("\n");
      preorder(root);
      printf("\n");
    }
    else if (com[0] == 'f') {
      scanf("%d", &x);
      res = find(root, x);
        if(res != NIL) printf("yes\n");
        else printf("no\n");
    }
    else if(com[0] == 'd') {
        scanf("%d", &x);
        treeDelete(find(root, x));
    }
  }

  return 0;
}

Measured memory_bytes: 21952
#include<bits/stdc++.h>
using namespace std;
using Int = long long;
signed main(){
  int n;
  cin>>n;
  typedef pair<int,int> P;
  vector<P> v(n);
  for(int i=0;i<n;i++) cin>>v[i].first>>v[i].second;
  sort(v.begin(),v.end());
  cout<<v.back().first+v.back().second<<endl;
  return 0;
}


Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
#define int long long int
#define f first
#define s second
#define pb push_back

const int MOD = 998244353;


int add(int x, int y)
{
	return (x + y) % MOD;
}

int sub(int x, int y)
{
	return add(x, MOD - y);
}

int mul(int x, int y)
{
	return (x * 1ll * y) % MOD;
}

int binpow(int x, int y)
{
	int z = 1;
	while(y > 0)
	{
		if(y % 2 == 1)
			z = mul(z, x);
		x = mul(x, x);
		y /= 2;
	}
	return z;
}

int inv(int x)
{
	return binpow(x, MOD - 2);
}

int value[200005][4];
int val2[200005][4];
int t[800005];

int sum(int v, int tl, int tr, int l, int r) {
    if (l > r) 
        return 0;
    if (l == tl && r == tr) {
        return t[v];
    }
    int tm = (tl + tr) / 2;
    return sum(v*2, tl, tm, l, min(r, tm))
           + sum(v*2+1, tm+1, tr, max(l, tm+1), r);
}

void update(int v, int tl, int tr, int pos, int new_val) {
    if (tl == tr) {
        t[v] = new_val;
    } else {
        int tm = (tl + tr) / 2;
        if (pos <= tm)
            update(v*2, tl, tm, pos, new_val);
        else
            update(v*2+1, tm+1, tr, pos, new_val);
        t[v] = t[v*2] + t[v*2+1];
    }
}

main() {
	int n;
	cin>>n;
	vector<pair<pair<int, int>, int>>v;
	set<int>sx;
	set<int>sy;
	map<int, int>mx;
	map<int, int>my;
	for(int i=0; i<n; i++){
		int x, y;
		cin>>x>>y;
		sx.insert(x);
		sy.insert(y);
		v.pb({{x, y}, i});
	}
	int pt=0;
	for(auto it=sx.begin(); it!=sx.end(); it++){
		mx[(*it)]=pt;
		pt++;
	}
	pt=0;
	for(auto it=sy.begin(); it!=sy.end(); it++){
		my[(*it)]=pt;
		pt++;
	}
	for(int i=0; i<v.size(); i++){
		v[i].f.f=mx[v[i].f.f];
		v[i].f.s=my[v[i].f.s];
	}
	sort(v.begin(), v.end());
	for(int i=0; i<v.size(); i++){
		val2[v[i].s][1]=i;
		val2[v[i].s][0]=n-1-i;
	}
	for(int i=n-1; i>=0; i--){
		value[v[i].s][0]=sum(1, 0, 200000, v[i].f.s, 200000);
		value[v[i].s][1]=sum(1, 0, 200000, 0, v[i].f.s);
		update(1, 0, 200000, v[i].f.s, 1);
	}
	for(int i=0; i<=200000; i++){
		update(1, 0, 200000, i, 0);
	}
	for(int i=0; i<n; i++){
		value[v[i].s][2]=sum(1, 0, 200000, v[i].f.s, 200000);
		value[v[i].s][3]=sum(1, 0, 200000, 0, v[i].f.s);
		update(1, 0, 200000, v[i].f.s, 1);
	}
	vector<pair<pair<int, int>, int>>v2;
	for(auto u:v){
		v2.pb({{u.f.s, u.f.f}, u.s});
	}
	sort(v2.begin(), v2.end());
	for(int i=0; i<n; i++){
		val2[v2[i].s][3]=i;
		val2[v2[i].s][2]=n-1-i;
	}
	int ans=0;
	for(int i=0; i<n; i++){
		int val=0;
		val=add(val, sub(binpow(2, val2[i][0]), 1));
		val=add(val, sub(binpow(2, val2[i][1]), 1));
		val=add(val, sub(binpow(2, val2[i][2]), 1));
		val=add(val, sub(binpow(2, val2[i][3]), 1));
		val=sub(val, sub(binpow(2, value[i][0]), 1));
		val=sub(val, sub(binpow(2, value[i][1]), 1));
		val=sub(val, sub(binpow(2, value[i][2]), 1));
		val=sub(val, sub(binpow(2, value[i][3]), 1));
		ans=add(ans, sub(binpow(2, n), 1));
		ans=sub(ans, val);
	}
	cout<<ans;
	return 0;
}

Measured memory_bytes: 77520
#include<bits/stdc++.h>
#define sci(a) scanf("%d", &a)
#define fto(i, a, b) for (int i = a; i <= b; ++i)
#define fdto(i, a, b) for (int i = a; i >= b; --i)
#define scii(a, b) scanf("%d %d", &a, &b)
#define ll long long
#define ff first
#define ss second
#define vi vector<int>
#define pi pair<int, int>
#define maxN 100005
#define oo 1000000007
#define maxM 2500
#define mp make_pair
#define pb push_back
#define bug(a) cout << #a << "= " << a << endl;
#define bugarr(a, x, y) cout << #a << "[" << x << ", " << y << "]= "; for (int i = x; i <= y; ++i) cout << a[i] << ", "; cout << endl;
#define sz(a) (int)a.size()
#define vii vector<pi>
#define db double
#define forit(var, it) for(__typeof(var.begin()) it = var.begin(); it != var.end(); ++it)

using namespace std;

int n, A, a[100];
ll f[100][10005];

int main() {
   // #ifndef ONLINE_JUDGE
      //  freopen("TakandCards.inp", "r", stdin);
        //freopen("TakandCards.out", "w", stdout);
    //#endif // ONLINE_JUDGE

    scii(n, A);
    fto(i, 1, n) sci(a[i]);
    fto(i, 1, n) a[i]-=A;
    //fto(i, 1, n) cout << a[i] << "\n";
    fto(i, 0, 7000) f[0][i] = 0;
    f[0][2500] = 1;
    fto(i, 1, n) {
        fto(j, -2500, 2500) {
            f[i][j+maxM] = f[i-1][j+maxM];
            if (j - a[i] + maxM >= 0) f[i][j+maxM]+=f[i-1][j-a[i]+maxM];
            //cout << i << " " << j << " " << j-a[i] << " " << f[i][j+maxM] << "\n";
        }
    }
    //cout << f[1][maxM] << "\n";
    cout << f[n][maxM] - 1;

    return 0;
}


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

typedef long long ll;

vector<ll> arr;

int main(){
  int n,m,k,a;
  cin >> n >> m >> k;
  arr.push_back(0);
  for(int i = 0; i < n; i++){
    cin >> a;
    arr.push_back(a + arr.back());
  }
  
  vector<ll>::iterator it;
  it = upper_bound(arr.begin(), arr.end(), k);
  int rpta = it - arr.begin() - 1;
  //cout << rpta << endl;
  ll curr = 0;
  for(int i = 0; i < m; i++){
    cin >> a;
    curr+=a;
    if(curr >= k){
      if(curr == k) rpta = max(rpta, i+1);
      continue;
    }
    it = upper_bound(arr.begin(), arr.end(), k-curr);
    int aux = it - arr.begin() + i;
  	rpta = max(aux, rpta);
    //cout << rpta << endl;
  }
  cout << rpta << endl;
}


Measured memory_bytes: 5344
s = input()
count = 0

for i in range(0, len(s)):
    if i % 2 == 0:
        if s[i] == 'L':
            count += 1
    elif i % 2 == 1:
        if s[i] == 'R':
            count += 1

if count == 0:
    print('Yes')
else:
    print('No')

Measured memory_bytes: 3064
#include <iostream>
#include <cmath>
#include <vector>
#include <map>
#include <set>
#include <string>
#include <cstring>
#include <queue>
#include <ctime>
#include <cassert>
#include <cstdio>
#include <algorithm>
#include <unordered_set>
#include <unordered_map>
#include <bitset>

using namespace std;

#define fr first
#define sc second
#define mp make_pair
#define pb push_back
#define epr(...) fprintf(stderr, __VA_ARGS__)
#define db(x) cerr << #x << " = " << x << endl
#define db2(x, y) cerr << "(" << #x << ", " << #y << ") = (" << x << ", " << y << ")\n"; 
#define db3(x, y, z) cerr << "(" << #x << ", " << #y << ", " << #z << ") = (" << x << ", " << y << ", " << z << ")\n"
#define all(a) (a).begin(), (a).end()
#define sz(a) (int)a.size()

#define equal equalll
#define less lesss
const int N = 1e6 + 10;
const long long INF = 1e9 + 19;
typedef long long ll;

int w, h;
int p[N];
int q[N];

void read() {
    scanf("%d%d", &w, &h);
    for (int i = 0; i < w; i++)
        scanf("%d", &p[i]);

    for (int i = 0; i < h; i++)
        scanf("%d", &q[i]);
}

void solve() {
    ll answer = 0;
    vector<pair<int,int>>tmp;
    for (int i = 0; i < w; i++)
        tmp.pb(mp(p[i], 0));
    for (int i = 0; i < h; i++)
        tmp.pb(mp(q[i], 1));

    sort(all(tmp));
    for (auto x: tmp) {
        if (x.sc == 0) {
            answer += x.fr * 1ll * (h + 1);
            w--;
        }
        else {
            answer += x.fr * 1ll * (w + 1);
            h--;
        }
    }
    cout << answer << endl;
}

void stress() {

}

int main(){
#ifdef MY_DEBUG
    freopen("in", "r", stdin);
    //freopen("out", "w", stdout);
#endif
    if (1) {
        int k = 1;
        for (int tt = 0; tt < k; tt++) {
            read();
            solve();
        }
    }
    else {
        stress();
    }

    return 0;
}


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

int main() {
  string s;
  cin >> s;
  
  if (s == "Sunny"){
  	cout << "Cloudy" << endl;
  }else if(s == "Cloudy"){
  	cout << "Rainy" << endl;
  }else{
    cout << "Sunny" << endl;
  }
  
  return 0;
}


Measured memory_bytes: 256
s = input()
key = 1
change = []
for i in range(len(s)-1):
    if s[i] == s[i+1]:
        key += 1
    else:
        change.append(key)
        key = 1
change.append(key)
anslist = []
for i in range(len(change)//2):
    p, q = change[2*i], change[2*i+1]
    for j in range(p-1):
        anslist.append(0)
    t = p+q
    a = t//2
    b = t-a
    if t % 2 == 0:
        anslist.append(a)
        anslist.append(b)
    else:
        if p % 2 == 0:
            anslist.append(a)
            anslist.append(b)
        else:
            anslist.append(b)
            anslist.append(a)  
    for j in range(q-1):
        anslist.append(0)
for i in anslist:
    print(i, end=" ")

Measured memory_bytes: 5624
class String
  def C
    self.rotate 1
  end

  def J
    self.rotate -1
  end

  def E
    h = self.length/2
    if self.length.odd?
      self.slice(h+1, self.length)+self[h]+self.slice(0,h)
    else
      self.slice(h,self.length)+self.slice(0,h)
    end
  end

  def A
    self.reverse
  end

  def M
    s=''
    self.chars.each do |c|
      if c =~ /[0-9]/
        s += c=='9' ? '0' : (c.to_i+1).to_s
      else 
        s += c
      end
    end
    s
  end

  def P
    s=''
    self.chars.each do |c|
      if c =~ /[0-9]/
        s += c=='0' ? '9' : (c.to_i-1).to_s
      else 
        s += c
      end
    end
    s
  end

  def rotate(n)
    n += self.length if n < 0
    self.slice(n, self.length-n)+self.slice(0,n)
  end
end

n = gets.to_i
n.times do
  s = gets.chomp
  msg = gets.chomp
  s.reverse.chars.each do |c|
    msg = msg.J if c == 'J'
    msg = msg.C if c == 'C'
    msg = msg.E if c == 'E'
    msg = msg.A if c == 'A'
    msg = msg.P if c == 'P'
    msg = msg.M if c == 'M'
  end
  puts msg
end

Measured memory_bytes: 8724