akhauriyash/Code-Regression huggingface dataset:
from collections import deque
H, W = map(int, input().split())
c = tuple(int(x)+1 for x in input().split())
d = [int(x)+1 for x in input().split()]
maze = [[-1] * (W+4), [-1] * (W+4)]

for i in range(H):
    temp = []
    s0 = input()
    s0 = '11' + s0.replace('.', '0').replace('#', '1') + '11'
    for j, s in enumerate(s0):
        temp.append(-int(s))
    maze.append(temp)
maze.append([-1] * (W+4))
maze.append([-1] * (W+4))

def check55(i, j):
    cset = {(ii, jj) for ii in range(i-2, i+3) for jj in range(j-2, j+3) if maze[ii][jj]==0}
    cset = cset - {(i-1, j), (i, j), (i+1, j), (i, j-1), (i, j+1)}
    return cset

def check(i, j, delta):
    if delta[0] != 0:
        ii = i + 3 * delta[0]
        for jj in range(j-2, j+3):
            if maze[ii][jj]==0:
                dset.add((ii, jj))

    else:
        jj = j + 3 * delta[1]
        for ii in range(i-2, i+3):
            if maze[ii][jj]==0:
                dset.add((ii, jj))

    return

#bfs

k = 1
tempbfs = deque([[c[0], c[1], k]])
flag = 0
while tempbfs:
    if flag == 1:break
    p = tempbfs.popleft()

    #dfs
    if maze[p[0]][p[1]] != 0:continue
    maze[p[0]][p[1]] = p[2]
    if p[0] == d[0] and p[1] == d[1]:
        flag = 1
        k = p[2]
        break
    temp = [(p[0], p[1])]
    dset = set()
    while temp:
        p0 = temp.pop()
        for delta in [(-1, 0), (1, 0), (0, -1), (0, 1)]:
            y = p0[0] + delta[0]
            x = p0[1] + delta[1]
            if maze[y][x] != 0: continue
            maze[y][x] = p[2]
            if y == d[0] and x == d[1]:
                flag = 1
                k = p[2]
                break
            temp.append((y, x))
            check(p0[0], p0[1], delta)

    if flag == 1: break
    for l in dset:
        if maze[l[0]][l[1]] == 0:
            tempbfs.append([l[0], l[1], p[2]+1])
    dset = check55(p[0], p[1])
    for l in dset:
        tempbfs.append([l[0], l[1], p[2]+1])

print(k - 1 if flag else -1)

Measured memory_bytes: 23424
#include "bits/stdc++.h"
using namespace std;

int main(void) {
    int a, b, c, d;
    cin >> a >> b >> c >> d;

    if ((a + b) == (c + d)) {
        cout << "Balanced" << endl;
    } else if ((a + b) > (c + d))  {
        cout << "Left" << endl;
    } else {
        cout << "Right" << endl;
    }

    return 0;
}


Measured memory_bytes: 384
#include<stdio.h>
    #include<math.h> 
    #include<string.h>
    int main(){
    	int n,a[100007];
    	scanf("%d",&n);
    	for(int j = 1;j<=n;j++){
    		scanf("%d",&a[j]);
    	}
    	int i = 1,sum = 0;
    	while(i!=2){
    		i = a[i];
    		sum++;
    		if(sum>100000) break;
    	}
    	if(i==2) printf("%d\n",sum);
    	else printf("-1\n");
    }

Measured memory_bytes: 512
#include<bits/stdc++.h>
using namespace std;
typedef long long LL;
int k[1005]; 
const LL mod=1e9+7;
int main()
{
	int n;
	cin>>n;
	for(int i=2;i<=n;i++)
	{
		int l=i;
		for(int j=2;j<=l;j++)
		{
			while(l%j==0)
			{
				k[j]++;
				l/=j;
			}	
		}
		if(l) k[l]++;
	}
	LL sum=1;
	for(int i=2;i<=n;i++)
	{
		if(k[i])
		{
			sum*=(k[i]+1);
			sum=sum%mod;
		}
	}					
	printf("%lld\n",sum%mod);
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
using namespace std;
using namespace __gnu_pbds;

const long long MOD = 1000000007LL;
const long long INF = 1e18;

int GCD(int a, int b){return b == 0 ? a : GCD(b, a % b);}
long long fast_exp(long long base, long long exp, long long mod = MOD) {
    long long tot = 1;
    for(;exp > 0;exp >>= 1) {
       if((exp & 1) == 1) tot = tot * base % mod;
       base = base * base % mod;
    }
    return tot;
}
long long slow_mult(long long base, long long exp, long long mod = MOD) {
    long long tot = 0;
    for(;exp > 0;exp >>= 1){
       if((exp & 1) == 1) tot = (tot + base) % mod;
       base = base * 2 % mod;
    }
    return tot;
}

struct chash {
    static uint64_t splitmix64(uint64_t x) {x += 0x8e3779b97f4a7c15; x = (x ^ (x >> 30)) * 0xbf54876d1ce4e5b9; x = (x ^ (x >> 27)) * 0x94d049bb133111eb; return x ^ (x >> 31);}
    size_t operator()(uint64_t x) const { static const uint64_t FIXED_RANDOM = chrono::steady_clock::now().time_since_epoch().count(); return splitmix64(x + FIXED_RANDOM);}
    size_t operator()(pair<uint64_t,uint64_t> x) const { static const uint64_t FIXED_RANDOM = chrono::steady_clock::now().time_since_epoch().count(); return splitmix64(x.first + FIXED_RANDOM)^(splitmix64(x.second + FIXED_RANDOM) >> 1);}
};

long long arr[100];

int main(){

    cin.sync_with_stdio(0); cin.tie(0); cout.tie(0);

    //freopen("input.txt", "r", stdin);
    //freopen("output.txt", "w", stdout);

    int n; cin >> n;

    long long tot = 0;

    for(int i = 0; i < n; ++i){
        cin >> arr[i];
        for(int j = 0; j < i; ++j)
            tot += arr[i] * arr[j];
    }

    cout << tot;

    return 0;

}


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

typedef long long ll;

ll solve(ll a) {
  ++a;
  ll ans = 0;

  for (size_t i = 0; i < 50; ++i) {
    ll loop = 1LL << (i + 1);
    ll count = (a / loop) * (loop / 2);
    count += std::max(0LL, (a % loop) - (loop / 2));

    if(count % 2 == 1) ans += (1LL << i);
  }
  return ans;
}

int main() {
  ll a, b;

  std::cin >> a >> b;

  if(a == b) {
    std::cout << a << std::endl;
    return 0;
  }

  std::cout << (solve(a - 1) ^ solve(b)) << std::endl;
}

Measured memory_bytes: 256
#include "bits/stdc++.h"
using namespace std;
#define rep(i,N) for(int i=0;i<(int)N;++i)
#define rep1(i,N) for(int i=1;i<=(int)N;++i)
#define all(x) x.begin(),x.end()
#define rall(x) x.rbegin(),x.rend()
#define SZ(x) (int)x.size()
#define e_b emplace_back
using ll = long long;
const ll LINF=1LL<<60;
const int INF=1<<30;

struct StarrySkyTree{
	int n;
	vector<int> node,lazy;
	
	StarrySkyTree(int sz){
		n=1;
		while(sz>n) n<<=1;
		node.assign(2*n,0);
		lazy.assign(2*n,0);
	}
	
	void eval(int k,int l,int r){
		if(lazy[k]){
			node[k]+=lazy[k];
			if(r-l>1){
				lazy[2*k]+=lazy[k];
				lazy[2*k+1]+=lazy[k];
			}
			lazy[k]=0;
		}
	}
	
	void add(int a,int b,int x,int k=1,int l=0,int r=-1){
		if(r<0) r=n;
		eval(k,l,r);
		if(r<=a||b<=l) return;
		if(a<=l&&r<=b){
			lazy[k]+=x;
			eval(k,l,r);
		}
		else{
			add(a,b,x,2*k,l,(l+r)/2);
			add(a,b,x,2*k+1,(l+r)/2,r);
			node[k]=min(node[2*k],node[2*k+1]);
		}
	}
	
	int getMin(int a,int b,int k=1,int l=0,int r=-1){
		if(r<0) r=n;
		eval(k,l,r);
		if(r<=a||b<=l) return INF;
		if(a<=l&&r<=b) return node[k];
		else{
			int vl=getMin(a,b,2*k,l,(l+r)/2);
			int vr=getMin(a,b,2*k+1,(l+r)/2,r);
			return min(vl,vr);
		}
	}
};

int main(){
	int n,q; cin>>n>>q;
	StarrySkyTree tree(n);
	rep(i,q){
		int m,s,t,x;
		cin>>m;
		if(m==0){
			cin>>s>>t>>x;
			tree.add(s,t+1,x);
		}else{
			cin>>s>>t;
			cout<<tree.getMin(s,t+1)<<endl;
		}
	}
}

	



Measured memory_bytes: 4920
#include <iostream>
#include <string>
#include <algorithm>
#include <math.h>
#include <set>
using namespace std;
typedef long long ll;
#define rep(i,s,n)for(int i = s;i<n;i++)
#define repe(i,s,n)for(int i = s;i<=n;i++)

int main() {
	string s; cin >> s;
	cout << s[0] << s.size() - 2 << s[s.size() - 1] << endl;

	return 0;
}

Measured memory_bytes: 256
#include <unordered_map>
#include <unordered_set>
#include <algorithm>
#include <iostream>
#include <iostream>
#include <fstream>
#include <numeric>
#include <cstring>
#include <cassert>
#include <string>
#include <vector>
#include <queue>
#include <deque>
#include <cmath>
#include <set>
#include <map>
#include <functional>
#include <bitset>
#include <iomanip>
#include <stack>
#include <list>
using namespace std;
#define     loop(n,i,a)     for(int i=a;i<n;i++)
#define     loopR(n,i,a)    for(int i=n-1;i>=a;i--)
#define     all(arr,n)      arr,arr+n
#define     allv(v)         (v).begin(),(v).end()
#define     rallv(v)        (v).rbegin(),(v).rend()
#define     m_p             make_pair
#define     ll              long long
#define     pii             pair<ll,ll>
#define     vi              vector<int>
#define     vll             vector<ll>
#define     vii             vector<pair<ll,ll>>
#define     sz(x)           (int)x.size()
#define     pb              push_back
#define     endl            "\n"
#define     Endl            "\n"
#define     f               first
#define     s               second
#define     mem(dp,n)       memset(dp,n,sizeof dp)
int dx[] = { 1 , 0 ,-1 , 0 ,-1 ,-1 , 1 , 1 };
int dy[] = { 0 , 1 , 0 ,-1 ,-1 , 1 ,-1 , 1 };
void fast(){
    std::ios_base::sync_with_stdio(0);
    cin.tie(NULL);
    cout.tie(NULL);
}
vector<string> vec_splitter(string s) {
    s += ',';
    vector<string> res;
    while(!s.empty()) {
        res.push_back(s.substr(0, s.find(',')));
        s = s.substr(s.find(',') + 1);
    }
    return res;
}
void debug_out(
        vector<string> __attribute__ ((unused)) args,
        __attribute__ ((unused)) int idx,
        __attribute__ ((unused)) int LINE_NUM) { cerr << endl; }
template <typename Head, typename... Tail>
void debug_out(vector<string> args, int idx, int LINE_NUM, Head H, Tail... T) {
    if(idx > 0) cerr << ", "; else cerr << "Line(" << LINE_NUM << ") ";
    stringstream ss; ss << H;
    cerr << args[idx] << " = " << ss.str();
    debug_out(args, idx + 1, LINE_NUM, T...);
}
#define debug(...) debug_out(vec_splitter(#__VA_ARGS__), 0, __LINE__, __VA_ARGS__)
const ll mxN=2e6+10,oo=0x3f3f3f3f,MOD=998244353;
const double PI = acos(-1);

void solve(){
    int n,k;
    cin>>n>>k;
    int arr[n];
    int res=0;
    loop(n,i,0)
        cin>>arr[i];
    sort(all(arr,n));
    loop(k,i,0)
        res+=arr[i];
    cout<<res<<endl;
}
int main() {
#ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
#endif
    fast();
    solve();
}

Measured memory_bytes: 3592
#include <bits/stdc++.h>
#define lint long long
#define ALL(x) (x).begin(),(x).end()
#define PB push_back
#define MP make_pair
using namespace std;

// cout << fixed << setprecision(12)

int main(){
  lint N;
  cin >> N;
  bool even = (N%2==0);
  vector<lint> A(N);
  vector<lint> B(N);
  
  for(lint i=0; i<N; i++){
    cin >> A[i] >> B[i];
  }
  sort(ALL(A));
  sort(ALL(B));
  
  lint small;
  lint large;
  
  if(even){// bunshi nomi, bunbo ha 2 
    small = (A[N/2]+A[N/2 - 1]);
    large = (B[N/2]+B[N/2 - 1]);
  }
  else{
    small = A[N/2];
    large = B[N/2];
  }
  
  cout << large - small + 1 << endl;
}
    
  
 

Measured memory_bytes: 6424
#include "bits/stdc++.h"
 
using namespace std;

using ll = long long;
using ull = unsigned long long;
using ld = long double;

#define REP(i,n) for(int i=0; i<int(n); i++)
#define REREP(i,n) for(int i=int(n-1); i>=0; i--)
#define FOR(i,m,n) for(int i=int(m); i<int(n); i++)
#define REFOR(i,m,n) for(int i=int(n-1); i>=int(m); i--)
#define ALL(obj) (obj).begin(),(obj).end()
 
#define VI vector<int>
#define VVI vector<vector<int>>
#define VVVI vector<vector<vector<int>>>
#define VD vector<double>
#define VVD vector<vector<double>>
#define VVVD vector<vector<vector<double>>>
#define VL vector<ll>
#define VVL vector<vector<ll>>
#define VVVL vector<vector<vector<ll>>>
#define VB vector<bool>
#define VVB vector<vector<bool>>
#define VVVB vector<vector<vector<bool>>>
#define VS vector<string>
#define VVS vector<vector<string>>
#define VVVS vector<vector<vector<string>>>
 
#define PII pair<int,int>
#define PDD pair<double,double>
#define PLL pair<ll,ll>
#define VPII vector<pair<int,int>>
#define VVPII vector<vector<pair<int,int>>>
#define VVVPII vector<vector<vector<pair<int,int>>>>
#define VPLL vector<pair<ll,ll>>
#define VVPLL vector<vector<pair<ll,ll>>>
#define VVVPLL vector<vector<vector<pair<ll,ll>>>>
 
#define SUMI(obj) accumulate((obj).begin(), (obj).end(), 0)
#define SUMD(obj) accumulate((obj).begin(), (obj).end(), 0.)
#define SUML(obj) accumulate((obj).begin(), (obj).end(), 0LL)
#define SORT(obj) sort((obj).begin(), (obj).end()) // 1,2,3,4,5...
#define RESORT(obj) sort((obj).begin(), (obj).end(), greater<int>()) // 5,4,3,2,1...
#define UB(obj,n) upper_bound((obj).begin(), (obj).end(), n) //itr > n
#define LB(obj,n) lower_bound((obj).begin(), (obj).end(), n) //itr>= n

#define PB push_back
#define Cout(str) cout << str << endl

const ll MOD = (ll)1e9 + 7;
const ll HINF = (ll)1e18;
const ll LINF = (ll)1e9;
const ll EPS = (ll)1e-8;

int main(){
	int n,m;
	int a,b;
	int sum;
	string str;
	string s,t;
	char c;
	VI vi;
	vector<char> vc;
	VS vs;
	int reserve_vi = 100;
	map<int, int> table; 

	//cin >> a >> b;
	//cin >> a >> b >> m;
	//cin >> str;
	//cin >> n;
	
	//cin >> s >> t;
	//cin >> c;

	//swap(a, b);
	//vi.resize(N);
	//fill(vi.begin(), vi.end(), 1);
	//vi.reserve(reserve_vi);
	//vi.PB(n);

	//vc.resize(5);
	//vc[i] = (str[i]);

	//sort(vc.begin(), vc.end(), greater<char>());
	//sort(vc.begin(), vc.end());

	//for(auto itr = table.begin(); itr != table.end(); ++itr) {
	table[5] = 2;
	table[7] = 1;
	REP(i, 3){
		cin >> n;
		table[n]--;
	}

	if(!table[5] && !table[7]) cout << "YES" << endl;
	else cout << "NO" << endl;


	return 0;
}



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

int main() {
  int N;
  cin >> N;
  vector <int> a(N);
  
  for (int i=0; i<N; i++){
    cin >> a.at(i);
  }
  
  vector <int> now(1);
  now.at(0) = 1;
  
  for (int i=0; i<100000; i++){
    now.push_back(a.at(now.at(i)-1));
    
    if (now.at(i+1)==2){
      cout << now.size()-1 << endl;
      break;
    }
   
  }
    if (now.size()==100001){
      cout << -1 << endl;
    }
  
}


Measured memory_bytes: 1276
#!/usr/bin/env python3

import sys
# import math
# import re                                    # re.compile(pattern) => ptn obj; p.search(s), p.match(s), p.finditer(s) => match obj; p.sub(after, s)
# from collections import deque                # deque class. deque(L): dq.append(x), dq.appendleft(x), dq.pop(), dq.popleft(), dq.rotate()
from collections import defaultdict          # subclass of dict. defaultdict(facroty)
# from collections import Counter              # subclass of dict. Counter(iter): c.elements(), c.most_common(n), c.subtract(iter)
# from heapq import heapify, heappush, heappop # built-in list. heapify(L) changes list in-place to min-heap in O(n), heappush(heapL, x) and heappop(heapL) in O(lgn).
# from heapq import nlargest, nsmallest        # nlargest(n, iter[, key]) returns k-largest-list in O(n+klgn).
# from itertools import count, cycle, repeat   # count(start[,step]), cycle(iter), repeat(elm[,n])
# from itertools import groupby                # [(k, list(g)) for k, g in groupby('000112')] returns [('0',['0','0','0']), ('1',['1','1']), ('2',['2'])]
# from itertools import starmap                # starmap(pow, [[2,5], [3,2]]) returns [32, 9]
# from itertools import product                # product(iter, repeat=n)
# from itertools import accumulate             # accumulate(iter[, f])
# from functools import reduce                 # reduce(f, iter[, init])
# from functools import lru_cache              # @lrucache ...arguments of functions should be able to be keys of dict
# from bisect import bisect_left, bisect_right # bisect_left(a, x, lo=0, hi=len(a)) returns i such that all(val<x for val in a[lo:i]) and all(val>-=x for val in a[i:hi]).
# from copy import deepcopy                    # to copy multi-dimentional matrix without reference
# from fractions import gcd                    # for Python 3.4


def main():
    mod = 1000000007                  # 10^9+7
    inf = float('inf')
    sys.setrecursionlimit(10**6)    # 1000 -> 1000000
    def input(): return sys.stdin.readline().rstrip()
    def ii():  return int(input())
    def mi():  return map(int, input().split())
    def mi_0(): return map(lambda x: int(x)-1, input().split())
    def lmi(): return list(map(int, input().split()))
    def lmi_0(): return list(map(lambda x: int(x)-1, input().split()))
    def li():  return list(input())
    
    
    n = ii()
    a = lmi()
    d = defaultdict(int)
    for num in a:
        d[num] += 1
    total = 0
    for _, v in d.items():
        total += v * (v-1) // 2
    for num in a:
        print(total - (d[num] - 1))

if __name__ == "__main__":
    main()

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

using namespace std;

typedef double D;
typedef long long int LL;

#define st first
#define nd second
#define PLL pair <LL, LL>
#define PII pair <int, int>

const int N = 507;
const int DX[] = {-1, 0, 0, 1};
const int DY[] = {0, -1, 1, 0};

int n;
bool is[N][N];
int dist[N][N];

inline bool exist(int x, int y){
	return 1 <= x && x <= n && 1 <= y && y <= n;
}

void update(int x, int y){
	queue <PII> Q;
	Q.push({x, y});
	
	while(!Q.empty()){
		auto p = Q.front();
		Q.pop();
		
		for(int t = 0; t < 4; ++t){
			int nx = p.st + DX[t], ny = p.nd + DY[t];
			if(exist(nx, ny) && dist[nx][ny] > dist[p.st][p.nd] + is[nx][ny]){
				dist[nx][ny] = dist[p.st][p.nd] + is[nx][ny];
				Q.push({nx, ny});
			}
		}
	}
}

int main(){
	scanf("%d", &n);
	for(int i = 1; i <= n; ++i)
		for(int j = 1; j <= n; ++j){
			is[i][j] = true;
			dist[i][j] = min(min(i, j), min(n - i, n - j) + 1);
		}
	
	int ans = 0;
	for(int i = 1; i <= n * n; ++i){
		int p;
		scanf("%d", &p);
		
		int x = (p - 1) / n + 1;
		int y = (p - 1) % n + 1;

		is[x][y] = false;
		dist[x][y]--;

		ans += dist[x][y];
		update(x, y);
	}
	
	printf("%d\n", ans);
	return 0;
}

Measured memory_bytes: 5032
import java.util.Scanner;

public class Main {


	public static void main(String[] args) {
		//?????°?¨????
		Scanner sc = new Scanner(System.in);
		double max = Integer.MIN_VALUE;
		double min = Integer.MAX_VALUE;


		while(sc.hasNext()) {
			double num = sc.nextDouble();
			max = Math.max(max, num);
			min = Math.min(min, num);
		}

		System.out.println(max - min);
	}

}

Measured memory_bytes: 27948
import math
N, K = map(int, input().split())

p = 0.0

if K <= N:
    p += (N-K+1)/N

for init_n in range(1, min([K, N+1])):
    p += 1/N * ((1/2)**math.ceil(math.log2(K/init_n)))

print(p)


Measured memory_bytes: 2940
#include <iostream>
#include <algorithm>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <string.h>
#include <vector>
#include <queue>
#include <cmath>
#include <bitset>
#include <complex>
#include <functional>
#include <numeric>
#include <iomanip>

#define SPBR(w, n) std::cout<<(w + 1 == n ? '\n' : ' ');
#define YES cout << "YES" << endl
#define Yes cout << "Yes" << endl
#define NO cout << "NO" << endl
#define No cout << "No" << endl
#define ALL(i) (i).begin(), (i).end()
#define FOR(i, a, n) for(int i=(a);i<(n);++i)
#define RFOR(i, a, n) for(int i=(n)-1;i>=(a);--i)
#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)
#define IN(a, x, b) (a<=x && x<b)
#define OUT(a, x, b) (x<a || b<=x)
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; }

#define int ll
using ll = long long;
using ull = unsigned long long;
using ld = long double;
const int MOD = 1000000007;
/* const int MOD = 998244353; */
const int INF = 1e18;
const double PI = acos(-1);

using namespace std;
struct INIT { INIT(){
  cin.tie(0); ios::sync_with_stdio(false);
  cout << fixed << setprecision(10);
}}INIT;


signed main() {
  int N, T; 
  cin >> N >> T;

  vector<int> A(N);
  REP(i, N) cin >> A[i];

  int MIN = INF;

  pair<int, int> gap = {-INF, 0};
  REP(i, N){
    chmin(MIN, A[i]);

    if(gap.first == A[i]-MIN){
      gap.second++;
    }
    if(gap.first < A[i]-MIN){
      gap = {A[i]-MIN, 1};
    }
  }

  cout << gap.second << "\n";

  return 0;
}

Measured memory_bytes: 1024
n = int(input())
a = list(map(int, input().split()))

a.sort()

colors = [0,0,0,0,0,0,0,0]
mulch = 0

for i in a:
  if i < 400:
    colors[0] += 1
  elif i < 800:
    colors[1] += 1
  elif i < 1200:
    colors[2] += 1
  elif i < 1600:
    colors[3] += 1
  elif i < 2000:
    colors[4] += 1
  elif i < 2400:
    colors[5] += 1
  elif i < 2800:
    colors[6] += 1
  elif i < 3200:
    colors[7] += 1
  else:
    mulch += 1
    
if len([j for j in colors if j > 0]) > 0:
  mi = len([j for j in colors if j > 0])
else:
  mi = 1

if mulch > 0:
  if len([j for j in colors if j > 0]) == 0:
    ma = mulch
  else:  
    ma = mi + mulch
else:
  ma = mi
  
print(mi, ma)

Measured memory_bytes: 38256
#include <iostream>
#include <vector>
#include <unordered_map>
#include <map>
#include <algorithm>
#include <set>
#include <unordered_set>
#include <deque>
#include <cmath>
#include <stack>
#include <queue>
#include <string>
#include <iomanip>
#include <cstring>
#include <climits>
#include <cstdio>

#define nl '\n'

using namespace std;

int n, a, b;

int main(){

    int arr[3][3];

    vector<int> v;

    for(int i = 0; i < 8; i++){ //C1, C2, C3, R1, R2, R3, DLR, DRL
        v.push_back(0);
    }

    for(int i = 0; i < 3; i++){
        for(int j = 0; j < 3; j++){
            cin >> arr[i][j];
        }
    }

    cin >> n;

    for(int i = 0; i < n; i++){
        cin >> b;
        for(int x = 0; x < 3; x++){
            for(int y = 0; y < 3; y++){
                if(arr[x][y] == b){
                    if(y == 0){
                        v[0]++;
                    } else if(y == 1){
                        v[1]++;
                    } else if(y == 2){
                        v[2]++;
                    }
                    if(x == 0){
                        v[3]++;
                    } else if(x == 1){
                        v[4]++;
                    } else if(x == 2){
                        v[5]++;
                    }
                    if(x == 0 && y == 0){ //Top Left
                        v[6]++;
                    } else if(x == 1 && y == 1){
                        v[6]++;
                    } else if(x == 2 && y == 2){
                        v[6]++;
                    }
                    if(x == 0 && y == 2){ //Top Right
                        v[7]++;
                    } else if(x == 1 && y == 1){
                        v[7]++;
                    } else if(x == 2 && y == 0){
                        v[7]++;
                    }
                }
            }
        }
    }

    for(int i = 0; i < v.size(); i++){
        if(v[i] >= 3){
            cout << "Yes";
            return 0;
        }
    }

    cout << "No";









}
 
//g++ -std=c++14 comp.cpp -o c && c.exe
//g++ -std=c++14 comp.cpp -o c; ./c.exe
//g++ -std=c++14 comp.cpp && ./a.out


//Surely this is going to AC

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep2(i, s, n) for (int i = (s); i < (int)(n); i++)
#define _GLIBCXX_DEBUG
static const int MAX = 20;

int main(){
  int N, A[MAX], b, C[MAX], sum = 0;
  cin >> N;

  rep(i, N) cin >> A[i];
  rep(i, N){
    cin >> b;
    sum += b;
  }
  rep(i, N-1) cin >> C[i];
  rep(i, N-1){
    if(A[i]+1 == A[i+1]) sum += C[A[i]-1];
  }
  

  cout << sum << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define kaj_start int main()
#define kaj_shesh return 0

kaj_start{
    int n, x;
    cin >> n;
    vector<int> v;

    for(int i = 0; i < n; i++){
        cin >> x;
        v.push_back(x);
    }

    int ans = 0;

    for(int i = 1; i < n - 1; i++){
        if((v[i] > v[i - 1] && v[i] < v[i + 1]) || (v[i] < v[i - 1] && v[i] > v[i + 1])){
            ans++;
        }
    }

    cout << ans;
    kaj_shesh;
}


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

using namespace std;

//----------------------- Print Function ----------------------//

inline void print() {
    cout << '\n';
}
template <typename First, typename... Rest>
void print(const First &first, const Rest &... rest) {
    cout << first << ' ';
    print(rest...);
}

template <typename T>
void print(const vector<T> &v) {
    for (auto e : v) cout << e << ' ';
    cout << '\n';
}

//------------------------- Libraries -------------------------//

//--------------------------- Solve ---------------------------//

void solve() {
    int N; cin >> N;
    vector<int> A(N);
    for (int i = 0; i < N; i++) cin >> A[i];

    long long ans = 0;
    int sum = 0, xor_sum = 0;
    int r = 0;
    for (int l = 0; l < N; l++) {
        while (r < N && (sum + A[r] == (xor_sum ^ A[r]))) {
            sum += A[r];
            xor_sum ^= A[r];
            r++;
        }
        ans += r - l;
        
        if (r == l) r++;
        else {
            sum -= A[l];
            xor_sum ^= A[l];
        }
    }

    cout << ans << '\n';
}

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

    solve();

    return 0;
}

Measured memory_bytes: 3964
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp> 
using namespace std;
using namespace __gnu_pbds; 
#define pb          push_back
#define ff          first
#define ss          second
#define ll          int64_t
#define ld          long double
#define mod         1000000007
#define mod2        998244353
#define inf         1000000000000007
#define pi          3.14159265358979323846
#define nl          cout<<"\n"
#define dbg(x)      cerr<<#x<<" = "<<x<<"\n"
#define all(v)      v.begin(),v.end()
#define forn(i,a,b) for(int64_t i=int64_t(a);i<int64_t(b);++i)
#define forb(i,a,b) for(int64_t i=int64_t(a);i>=int64_t(b);--i)
#define fastio()    ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);

template<typename T,typename U> static inline void amin(T &x,U y)   {if(y<x)x=y;}
template<typename T,typename U> static inline void amax(T &x,U y)   {if(x<y)x=y;}  

ll lcm(ll a,ll b)       {return (a*b)/__gcd(a,b);} 
ll count_digits(ll n)   {ll dig=floor(log10(n)+1);return dig;}
ll mpow(ll x,ll y,ll p) {ll r=1;x=x%p;while(y>0){if(y&1)r=(r*x)%p;y=y>>1;x=(x*x)%p;}return r;} 
string dec_bin_32(ll n) {string s;for(ll i=31;i>=0;i--){ll k=n>>i;s+=(k&1)?'1':'0';}return s;} 
string dec_bin_64(ll n) {string s;for(ll i=63;i>=0;i--){ll k=n>>i;s+=(k&1)?'1':'0';}return s;} 
ll mod_inv(ll a,ll m)   {ll m0=m,y=0,x=1;if(m==1)return 0;while(a>1){ll q=a/m,t=m;m=a%m,a=t;t=y;y=x-q*y;x=t;}if(x<0)x+=m0;return x;} 

//-------------------------------L_I_Erq34-------------------------------

ll dp[100007][3];
ll a[100007][3];

int main()
{
	fastio();
	ll z,n,m,t,k,i,j,l,d,h,r;
	cin>>n;
	forn(i,0,n)
		cin>>a[i][0]>>a[i][1]>>a[i][2];
	dp[0][0]=a[0][0];
	dp[0][1]=a[0][1];
	dp[0][2]=a[0][2];
	forn(i,1,n)
	{
		forn(j,0,3)
			forn(k,0,3)
				if(j^k)
					dp[i][j]=max(dp[i][j],dp[i-1][k]+a[i][j]);
	}
	cout<<max({dp[n-1][0],dp[n-1][1],dp[n-1][2]})<<"\n";
	cerr<<"\nTime elapsed: "<<1000*clock()/CLOCKS_PER_SEC<<"ms\n";
	return 0;
}


Measured memory_bytes: 4992
#define _USE_MATH_DEFINES

#include <cstdio>
#include <cstdlib>
#include <iostream>
#include <cmath>
#include <cstring>
#include <algorithm>
#include <vector>
#include <queue>
#include <map>
#include <set>
#include <unordered_map> 
#include <unordered_set>
#include <functional>

using namespace std;

typedef pair<long long int, long long int> P;
typedef tuple<int, int, int> T;

long long int INF = 1e18;
long long int MOD = 1e9 + 7;

long long int DP[6100];

int main(){
	int N, T;
	cin >> N >> T;
	vector<P> v(N);
	for(int i = 0; i < N; i++){
		cin >> v[i].first >> v[i].second;
	}
	sort(v.begin(), v.end());
	long long int ans = 0;
	for(int i = 0; i < N; i++){
		int A = v[i].first;
		int B = v[i].second;
		for(int j = T + A - 1; j >= A; j--){
			DP[j] = max(DP[j], DP[j - A] + B);
			ans = max(ans, DP[j]);
		}
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 384
use proconio::{input, fastout};
use proconio::marker::Usize1;

const TYPE_COUNT: usize = 26;

#[fastout]
fn main() {
    input! {
        d: usize,
        cc: [usize; TYPE_COUNT],
        ss: [[usize; TYPE_COUNT]; d],
        tt: [Usize1; d],
    }

    let mut last = vec![0; TYPE_COUNT];

    let mut v = 0;
    for (s, t) in ss.into_iter().zip(tt.into_iter()) {
        v += s[t] as isize;
        for l in last.iter_mut() {
            *l += 1;
        }
        last[t] = 0;
        v -= last.iter().zip(cc.iter()).map(|(&l, &c)| (l * c) as isize).sum::<isize>();
        println!("{}", v);
    }
}

Measured memory_bytes: 2300
import java.util.*

fun main(args: Array<String>) {
    val pw = java.io.PrintWriter(System.out)
    Problem.solve(Scanner(System.`in`), pw)
    pw.flush()
}

object Problem {
    fun solve(sc: Scanner, pw: java.io.PrintWriter) {
        val S = sc.next().toInt()
        val W = sc.next().toInt()
        pw.println(if (S <= W) "unsafe" else "safe")
    }
}


Measured memory_bytes: 36432
#include<cmath>
#include<cstdio>
#include<cstring>
#include<iostream>
#include<algorithm>
using namespace std;
#define maxn 16005

int n,m;
bool f[maxn],g[maxn],tmp[maxn];
char s[maxn];

inline int read(){
	int x=0,f=1; char ch=getchar();
	for (;ch<'0'||ch>'9';ch=getchar()) if (ch=='-') f=-1;
	for (;ch>='0'&&ch<='9';ch=getchar()) x=x*10+ch-'0';
	return x*f;
}

int main(){
	scanf("%s",s+1); n=strlen(s+1);
	int x=read()+8000,y=read()+8000;
	int l=1;
	for (;l<=n&&s[l]=='F';l++);
	f[l-1+8000]=1,g[8000]=1;
	int op=0;
	for (;l<=n;l++){
		if (s[l]=='T'){op^=1; continue;}
		bool *h=op?g:f; memset(tmp,0,sizeof(tmp)); int r=l;
		for (;r<=n&&s[r]==s[l];++r); --r; int pps=r-l+1;
		for (int i=pps;i<=16000-pps;i++) tmp[i]|=h[i-pps]|h[i+pps];
		for (int i=0;i<pps;i++) tmp[i]|=h[i+pps];
		for (int i=16001-pps;i<=16000;i++) tmp[i]|=h[i-pps];
		for (int i=0;i<=16000;i++) h[i]=tmp[i]; l=r;
	}
	puts((f[x]&&g[y])?"Yes":"No");
	return 0;
}


Measured memory_bytes: 256
#include <cstdio>
#include <iostream>
#include <sstream>
#include <fstream>
#include <iomanip>
#include <algorithm>
#include <cmath>
#include <string>
#include <vector>
#include <list>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <bitset>
#include <numeric>
#include <climits>
#include <cfloat>
using namespace std;

int main()
{
    int a[][7] = {{2, 3, 6, 2, 5, 1, 6},
                  {3, 2, 4, 6, 1, 3, 6}};

    for(;;){
        string s;
        cin >> s;
        if(s == "#")
            return 0;

        int x = 0;
        for(unsigned i=0; i<s.size(); ++i)
            x = a[s[i]-'0'][x];

        if(x == 1)
            cout << "Yes" << endl;
        else
            cout << "No" << endl;
    }
}

Measured memory_bytes: 1180
# -*- coding: utf-8 -*-
from collections import defaultdict
import sys
#input = sys.stdin.readline
def inpl(): return list(map(int, input().split()))

N, K, Q = inpl()
X = [0]*N
for _ in range(Q):
    X[int(input())-1] += 1

for i in range(N):
    print(["No", "Yes"][K-Q+X[i] > 0])

Measured memory_bytes: 50904
#[allow(unused_imports)]
use proconio::marker::*;
use proconio::*;

#[fastout]
#[allow(non_snake_case)]
fn main() {
    input! {
        N: usize, D: f64,
        XY: [[f64; 2]; N]
    }
    let mut ans = 0;
    for xy in XY {
        let x2 = xy[0].powf(2.0);
        let y2 = xy[1].powf(2.0);
        let d = (x2 + y2).powf(0.5);
        if d <= D {
            ans += 1
        }
    }
    println!("{}", ans);
}


Measured memory_bytes: 15768
use std::io::*;
use std::str::FromStr;

fn read<T: FromStr>() -> T {
    let stdin = stdin();
    let stdin = stdin.lock();
    let token: String = stdin
        .bytes()
        .map(|c| c.expect("failed to read char") as char)
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect();
    token.parse().ok().expect("failed to parse token")
}

fn main() {
    let n: usize = read();
    let k: usize = read();
    let a: Vec<i32> = (0..n).map({|_| read()}).collect();

    let p = (0..n).min_by_key({|i| a[*i]}).unwrap();
    let q = n - p - 1;
    let t = k - 1;

    let l = p / t;
    let r = q / t;
    let remaining = n - (l + r) * t;

    let mut ans= l + r;

    ans += if remaining <= 1 {
        0
    } else if remaining <= k {
        1
    } else {
        2
    };

    println!("{}", ans);
}


Measured memory_bytes: 4352
#include<iostream>
#include<vector>
#include<algorithm>
#include<map>

using namespace std;

#define rep(i, s, n) for(int i = s;i<n;i++)
#define repe(i, s, n) for(int i = s;i<=n;i++)
#define pb push_back
#define fi first
#define se second
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef vector<int> vi;
typedef vector<int> vll;
typedef vector<pii> vpii;
typedef vector<pll> vpll;
static const ll maxLL = (ll) 1 << 62;
const ll MOD = 1000000007, INF = 1e18;
int dy[] = {-1, 0, 1, 0};
int dx[] = {0, 1, 0, -1};

template<typename T1, typename T2>
bool pairCompare(const pair<T1, T2> &firstElof, const pair<T1, T2> &secondElof) {
    return firstElof.second > secondElof.second;
}

int mapMaxValue(std::map<ll, int> m) {
    int max = 0;
    for (std::map<ll, int>::iterator it = m.begin(); it != m.end(); it++) {
        if (max < it->second) max = it->second;
    }
    return max;
}

int main(void) {
    int n;
    cin >> n;
    vi value(n, 0);
    for (int i = 0; i < n; ++i) {
        cin >> value[i];
    }

    sort(value.begin(), value.end());

    float prev_value = (value[0] + value[1]) / 2.0f;
    float max_value = prev_value;

    for (int i = 2; i < n; ++i) {
        max_value = (prev_value + value[i]) / 2.0f;
        prev_value = max_value;
    }

    cout << max_value << endl;
}

Measured memory_bytes: 256
N = int(input())
B = list(map(int, input().split()))

A = [B[0]] + [0] * (N-2) + [B[-1]]
for i, (prv, nxt) in enumerate(zip(B[:-1], B[1:]), 1):
    A[i] = min(prv, nxt)
print(sum(A))


Measured memory_bytes: 3060
#include<bits/stdc++.h>
#define rep(i,n) for(int i=0;i<n;++i)
#define rrep(i,n) for(int i=n-1;i>=0;--i)
#define yesno(flg) if(flg){cout<<"YES"<<endl;}else{cout<<"NO"<<endl;}
#define MAX_N 1002
#define i197 1000000007

using namespace std;

typedef long long ll;
typedef pair<ll,ll> P1;
typedef pair<int,int> Pi;
typedef pair<double,Pi> Pdi;
typedef pair<ll,int>Pli;
typedef pair<P1,ll> P2;
const ll INF=1000000000000000001;
struct edge{int to,cost;};
int dy[]={0, 0, 1, -1};
int dx[]={1, -1, 0, 0};
struct Road{double cost;int a,b;};

int a[1001];
int b[1001];
int main() {

	int n;
	ll a2=0,b2=0;

	cin>>n;

	rep(i,n){
		cin>>a[i]>>b[i];
	}
	a2=a[0];
	b2=b[0];

	ll a3=0,b3=0;
	rep(i,n-1){
		if(a2<=a[i+1]&&b2<=b[i+1]){
			a2=a[i+1];
			b2=b[i+1];
		}else{
			a3=a2/a[i+1];
			if(a2%a[i+1]>0)a3++;

			b3=b2/b[i+1];
			if(b2%b[i+1]>0)b3++;

			a2=max(a3,b3)*a[i+1];
			b2=max(a3,b3)*b[i+1];
		}
	}
	cout<<a2+b2<<endl;
	return 0;
}


Measured memory_bytes: 256
grid = [[0, 0, 0, 0]]
3.times do
  grid.push([0] + gets.split(' ').map(&:to_i))
end

a1 = 0
b1 = grid[1][1] - a1
b2 = grid[2][1] - a1
b3 = grid[3][1] - a1
a2 = grid[1][2] - b1
a3 = grid[1][3] - b1
if a2 + b2 == grid[2][2] && a2 + b3 == grid[3][2] && 
  a3 + b2 == grid[2][3] && a3 + b3 == grid[3][3]
  puts 'Yes'
else
  puts 'No'
end

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

#define SZ(x) (int)(x).size()
#define FOR(i,a,b) for(int i=(a);i<=(b);++i)
#define RFOR(i, a, b) for (int i=a;i>=b;--i)

const int MX_N = 1e5+5;
const int MOD = 1e9+7;

int N;
long long A, B, S[MX_N];

int dp[MX_N];

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    
    cin >> N >> A >> B;
    if (A > B) swap(A,B);
    bool impossible = false;
    FOR(i,1,N){
        cin >> S[i];
        if (i > 2 && S[i]-S[i-2] < A) impossible = true;
    }

    if (impossible) { cout << 0; return 0; }

    dp[0] = dp[1] = 1;
    int s = 0, e = 1, cur = dp[s];
    FOR(i,2,N){
        while (e < i && S[i]-S[e] >= B) {
            cur += dp[e++];
            if (cur >= MOD) cur -= MOD;
        }
        dp[i] = cur;

        if (S[i]-S[i-1] < A) {
            while (s < i-1) {
                if (s < e) {
                    cur -= dp[s];
                    if (cur < 0) cur += MOD;
                }
                dp[s++] = 0;
            }
        }

        //cout << "i=" << i << " s e " << s << " " << e << " :: ";
        //FOR(j,0,i) cout << dp[j] << ' ';
        //cout << endl;
    }

    int ans = 0;
    FOR(i,0,N) {
        ans = ans + dp[i];
        if (ans >= MOD) ans -= MOD;
    }
    cout << ans;
}



Measured memory_bytes: 1408
#include<bits/stdc++.h>
typedef long long ll;
ll gi(){
	ll x=0,f=1;
	char ch=getchar();
	while(!isdigit(ch))f^=ch=='-',ch=getchar();
	while(isdigit(ch))x=x*10+ch-'0',ch=getchar();
	return f?x:-x;
}
std::mt19937 rnd(time(NULL));
#define rand rnd
#define pr std::pair<int,int>
#define all(x) (x).begin(),(x).end()
#define fi first
#define se second
template<class T>void cxk(T&a,T b){a=a>b?a:b;}
template<class T>void cnk(T&a,T b){a=a<b?a:b;}
#ifdef mod
int pow(int x,int y){
	int ret=1;
	while(y){
		if(y&1)ret=1ll*ret*x%mod;
		x=1ll*x*x%mod;y>>=1;
	}
	return ret;
}
template<class Ta,class Tb>void inc(Ta&a,Tb b){a=a+b>=mod?a+b-mod:a+b;}
template<class Ta,class Tb>void dec(Ta&a,Tb b){a=a>=b?a-b:a+mod-b;}
#endif
ll dp[100010],w[111],v[111];
int main(){
#ifdef LOCAL
	freopen("in.in","r",stdin);
	//freopen("out.out","w",stdout);
#endif
	int n=gi(),W=gi();
	for(int i=1;i<=n;++i){
		w[i]=gi(),v[i]=gi();
		for(int j=W;j>=w[i];--j)cxk(dp[j],dp[j-w[i]]+v[i]);
	}
	printf("%lld\n",dp[W]);
	return 0;
}



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

int solve(vector<int64_t> &a, string s = "") {
	if (a.size() == s.size()) {
		int64_t p = 1;
		for (int i = 0; i < a.size(); i++) {
			p *= a[i] + (s[i] - '0' - 1);
		}
		return p % 2 == 0;
	}
	int r = 0;
	for (int i = 0; i < 3; i++) {
		r += solve(a, s + "012"[i]);
	}
	return r;
}

int main() {
	int n;
	cin >> n;
	vector<int64_t> a(n);
	for (auto &i : a) {
		cin >> i;
	}
	cout << solve(a) << endl;
	return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner scanner = new Scanner(System.in);
		int n = scanner.nextInt();
		int[] a = new int[n];
		for (int i = 0; i < a.length; i++) {
			a[i] = scanner.nextInt();
		}
		print(a);
		sort(a);
		scanner.close();
	}

	static void sort(int[] a) {
		for (int i = 1; i < a.length; i++) {
			int v = a[i];
			int j = i - 1;
			while ((j >= 0) && (a[j] > v)) {
				a[j + 1] = a[j];
				j--;
			}
			a[j + 1] = v;
			print(a);
		}
	}

	static void print(int[] a) {
		for (int i = 0; i < a.length; i++) {
			System.out.print(a[i]);
			if (i != a.length - 1) {
				System.out.print(" ");
			}
		}
		System.out.println();
	}

}



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

int main() {
    int n, r, p, c;
    while (cin >> n >> r, n | r) {
        vector<int> deck;
        for (int i = n; i > 0; i--) deck.push_back(i);
        while (r--) {
            cin >> p >> c;
            rotate(deck.begin(), deck.begin() + p - 1, deck.begin() + p - 1 + c);
        }
        cout << deck[0] << endl;
    }
    return 0;
}

Measured memory_bytes: 1224
#include <stdio.h>
#include <string>
#include <cstring>
#include <stdlib.h>
#include <math.h>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <list>
#include <iterator>
#include <assert.h>
#pragma warning(disable:4996) 
 
typedef long long ll;
#define MIN(a, b) ((a)>(b)? (b): (a))
#define MAX(a, b) ((a)<(b)? (b): (a))
#define LINF 9223300000000000000
#define INF 2140000000
const long long MOD = 1000000007;
//const long long MOD = 998244353;
using namespace std;
 
char str[100005];

int main(int argc, char* argv[])
{
    scanf("%s", str);
    int n=strlen(str);
    int i;
    int sum=0;
    for(i=0; i<n; i++) {
        if(str[i]=='g') {
            if(i%2==0) ;
            else sum++;
        }
        else {
            if(i%2==0) sum--;
            else ;
        }
    }
    printf("%d\n", sum);

    return 0;
}

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

int main(){
  ll n;
  cin >>n;
  ll ans = 1;
  while(ans*2<=n) ans *= 2;
  cout << ans*2-1 << endl;
  return 0;
}

Measured memory_bytes: 256
/*  -*- coding: utf-8 -*-
 *
 * c.cc: C - Alternating Path
 */

#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<iostream>
#include<string>
#include<vector>
#include<map>
#include<set>
#include<stack>
#include<list>
#include<queue>
#include<deque>
#include<algorithm>
#include<numeric>
#include<utility>
#include<complex>
#include<functional>

using namespace std;

/* constant */

const int MAX_H = 400;
const int MAX_W = 400;
const int MAX_N = MAX_H * MAX_W;

const int dxs[] = { 1, 0, -1, 0 }, dys[] = { 0, -1, 0, 1 };

/* typedef */

typedef long long ll;
typedef vector<int> vi;
typedef queue<int> qi;
typedef pair<int,int> pii;

/* global variables */

char flds[MAX_H][MAX_W + 4];
bool used[MAX_H][MAX_W];

/* subroutines */

/* main */

int main() {
  int h, w;
  scanf("%d%d", &h, &w);
  for (int y = 0; y < h; y++) scanf("%s", flds[y]);

  memset(used, false, sizeof(used));
  ll sum = 0;

  for (int y = 0; y < h; y++)
    for (int x = 0; x < w; x++)
      if (! used[y][x]) {
	used[y][x] = true;
	int bn = 0, wn = 0;
	(flds[y][x] == '#') ? bn++ : wn++;
	queue<pii> q;
	q.push(pii(x, y));

	while (! q.empty()) {
	  pii u = q.front(); q.pop();
	  int &ux = u.first, &uy = u.second;
	  char &uf = flds[uy][ux];

	  for (int di = 0; di < 4; di++) {
	    int vx = ux + dxs[di], vy = uy + dys[di];
	    if (vx >= 0 && vx < w && vy >= 0 && vy < h &&
		! used[vy][vx] && flds[vy][vx] != uf) {
	      used[vy][vx] = true;
	      (flds[vy][vx] == '#') ? bn++ : wn++;
	      q.push(pii(vx, vy));
	    }
	  }
	}

	sum += (ll)bn * wn;
      }

  printf("%lld\n", sum);
  return 0;
}


Measured memory_bytes: 512
#include <bits/stdc++.h>
#define int long long
#define db(x) cerr<<#x<<" = "<<x<<'\n'
using namespace std;

const int MAX=3e5+5,INF=1e18;

int n,sum=0,rs=-INF,a[MAX],f[MAX];
multiset<int> S;

void add(int x) {
	sum+=x;
	S.insert(x);
}

void remove(int x) {
	sum-=x;
	S.erase(S.find(x));
}

int32_t main() {
	ios_base::sync_with_stdio(false);
	//freopen("input","r",stdin);
	cin>>n;
	for(int i=1;i<=3*n;i++)
		cin>>a[i];
	for(int i=1;i<=3*n;i++) {
		add(a[i]);
		if(S.size()>n)
			remove(*S.begin());
		if(S.size()==n)
			f[i]=sum;
	}
	sum=0;
	S.clear();
	for(int i=3*n;i>n;i--) {
		add(a[i]);
		if(S.size()>n)
			remove(*S.rbegin());
		if(S.size()==n)
			rs=max(rs,f[i-1]-sum);
	}
	cout<<rs;
}


Measured memory_bytes: 12260
#include <cmath>
#include <iostream>
#include <vector>
#include <queue>
#include <deque>
#include <map>
#include <set>
#include <stack>
#include <tuple>
#include <bitset>
#include <algorithm>
#include <functional>
#include <utility>
#include <iomanip>

#define int long long int
#define rep(i, n) for(int i = 0; i < (n); ++i)
#define ALL(x) (x).begin(), (x).end()
#define SZ(x) ((int)(x).size())
#define UNIQUE(v) v.erase( unique(v.begin(), v.end()), v.end() )

using namespace std;

typedef pair<int, int> P;

const int INF = 1e15;
const int MOD = 1e9+7;

template <typename T>
using vector2 = vector<vector<T>>;
template <typename T>
vector2<T> initVec2(size_t n0, size_t n1, T e = T()){
    return vector2<T>(n0, vector<T>(n1, e));
}

template <typename T>
using vector3 = vector<vector<vector<T>>>;
template <typename T>
vector3<T> initVec3(size_t n0, size_t n1, size_t n2, T e = T()){
    return vector3<T>(n0, vector2<T>(n1, vector<T>(n2, e)));
}

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

    int n, m;
    cin >> n >> m;
    vector<int> x(n);
    rep(i, n) cin >> x[i];
    sort(ALL(x));

    auto a = initVec2<P>(m, 0);
    rep(i, n){
        int y = x[i] % m;
        if(a[y].empty() || a[y].back().first != x[i]){
            a[y].emplace_back(x[i], 0);
        }
        a[y].back().second++;
    }

    int ans = 0;
    for(int i = 0; i <= m / 2; i++){
        int j = m - i;

        int ci = 0;
        int di = 0;
        for(P p : a[i]){
            ci += p.second;
            di += p.second / 2;
        }
        if(i == 0 || (i == m / 2 && m % 2 == 0)){
            ans += ci / 2;
            continue;
        }

        int cj = 0;
        int dj = 0;
        for(P p : a[j]){
            cj += p.second;
            dj += p.second / 2;
        }

        if(ci < cj){
            swap(ci, cj);
            swap(di, dj);
        }

        ans += cj + min(di, (ci - cj) / 2);
    }
    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 6528
#include <iostream>
#include <vector>
#include <set>
#include <queue>
#include <stack>
#include <map>
#include <limits>
#include <string>
#include <algorithm>
#include <bitset>
#include <unordered_set>
#include <unordered_map>
#include <map>
#include "math.h"
#include "assert.h"

using namespace std;

#define ll long long

#define BUFF ios::sync_with_stdio(false)
#define epsilon 1e-07
#define pi 2 * acos(0.0);
#define mod 1000000007   // 1e9+7
#define cerr if(false)cerr
#define watch(x) cerr << #x << " = " << x << endl;

#define inf std::numeric_limits<int>().max();

int main() {
	int n;
	cin >> n;
	int ct=0;
	for(int i=1; i<=n; i++) {
		if (i < (n-i)) ct++; 
	}
	cout << ct << endl;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define F first
#define S second
#define mp make_pair
#define pb push_back
#define ll long long
#define mod 1000000007
#define M 1000000
using namespace std;

ll fa[100003];

ll power(ll n){
    ll t=1;
    if(n==0) return 1;
    while(n--){
        t=t*2;
        t = t%mod;
    }
    return t;
}

void answer(){
    ll n,ans=0,c=0,f=0;
    cin>>n;
    ll a[2*n+1];
    vector<pair<string,int>> m;
    string s;
    for(int i=0;i<n;i++){
        cin>>s>>c;
        m.pb(mp(s,c));
    }
    cin>>s;
    for(auto i=m.begin();i!=m.end();i++){
        if(i->F==s){ f=1; c=i->S; }
        if(f==1) ans+=i->S;
    }
    cout<<ans-c<<"\n";
}

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    fa[1]=1,fa[0]=1;
    for(int i=2;i<100001;i++){
        fa[i]=fa[i-1]*i;
        fa[i] = fa[i]%mod;
    }
    int q;
    //>>q;
    //while(q--){
        answer();
    //}
    return 0;
}

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


int m, n;
int mem[177147];


int rec(const vector<bitset<11>>& v, int S = 0){
    if(v.size() <= 1) return 0;
    int& res = mem[S];
    if(res != -1) return res;
    res = m;
    for(int i = 0;i < m;++i){
        if(S/(int)pow(3, i)%3 != 0) continue;
        vector<bitset<11>> a, b;
        for(auto bit : v) if(bit[i]) a.push_back(bit); else b.push_back(bit);
        res = min(res, 1+max(rec(a, S+(int)pow(3, i)), rec(b, S+2*(int)pow(3, i))));
    }
    return res;
}


int main(){
    while(cin >> m >> n, m+n){
        fill(begin(mem), end(mem), -1);
        vector<bitset<11>> v(n);
        for(auto& bit : v) cin >> bit;
        cout << rec(v) << endl;
    }
    return 0;
}


Measured memory_bytes: 3916
/*01 02 03 12 13 23　と６回見ていくパターン 
for(int i=0;i<n-1;i++){
  for(int j=i+1;j<n;j++){
    }
  }
*/
//vector<vector<int>> data(3, vector<int>(4));//int型の2次元配列(3×4要素の)の宣言
//int64_t a;
//10のi乗pow(10, i);
/*string s; stringでの文字列を数字型に変える方法
  cin >> s;
  rep(i,s.size()-2) {
  int a= (s.at(i)-'0')*100 + (s.at(i+1)-'0')*10+ s.at(i+2) -'0';
    */
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
int main() {
  int x1,y1,x2,y2;
  cin >> x1>>y1>>x2>>y2;
  int x3,y3,x4,y4;
  x3 = x2 - (y2-y1);
  y3 = y2 - (x1-x2);
  x4 = x1 - (y2-y1);
  y4 = y1 - (x1-x2);
  cout << x3 << " "<< y3 <<" "<<x4 <<" " << y4 <<endl;
}

Measured memory_bytes: 256
import Data.List
 
getInts :: IO [Int]
getInts = (map read . words) <$> getLine
 
solve :: Int -> Int -> [Int] -> Int
solve n k ls = foldl (+) 0 $ take (length v - k) v
    where v = sort $ map length $ group (sort ls)
 
main :: IO ()
main = do
    [n, k] <- getInts
    ls <- getInts
    print $ solve n k ls

Measured memory_bytes: 63868
n = gets.strip.to_i
v = gets.strip.split.map(&:to_i)
c = gets.strip.split.map(&:to_i)

value=0
cost=0
(0..n-1).each do |i|
	if v[i]>c[i]
		value+=v[i]
		cost+=c[i]
	end
end

puts value-cost



Measured memory_bytes: 1788
N, K = map(int, input().split())
data = [0 for _ in range(10**5+1)]
for _ in range(N):
    a, b = map(int, input().split())
    data[a] += b

counter = 0
for i in range(10**10):
    if counter >= K:
        print(i-1)
        break
    counter += data[i]


Measured memory_bytes: 5896