akhauriyash/Code-Regression huggingface dataset:
using System;
using System.Collections.Generic;
using System.Numerics;
using System.Linq;
using System.Text;
using static System.Math;

class MainClass
{

    public static void Main(string[] args)
    {
        var K = LnInt();
        var S = LnStr();
        if (S.Length <= K) { print(S); return; }
        print(S.Substring(0, K) + "...");

    }


    public static long SumAtoB(long a, long b) { var length = b - a + 1; return (a + b) * (length / 2) + (length % 2 == 1 ? (a + b) / 2 : 0); }
    public static long PowLite(long n, long p, int mod = (int)1e9 + 7) { long ans = 1; long now = n; for (; p > 0; p >>= 1) { if ((p & 1) == 1) { ans *= now; ans %= mod; } now *= now; now %= mod; } return ans; }
    public static void print(object obj) { Console.WriteLine(obj); }
    public static long Gcd(long a, long b) { if (a > b) { var r = a % b; if (r == 0) return b; else return Gcd(b, r); } else { var r = b % a; if (r == 0) return a; else return Gcd(a, r); } }
    public static int Gcd(int a, int b) { if (a > b) { var r = a % b; if (r == 0) return b; else return Gcd(b, r); } else { var r = b % a; if (r == 0) return a; else return Gcd(a, r); } }
    public static int[] LnInts() { var vs = Console.ReadLine().Trim().Split(new[] { ' ' }, StringSplitOptions.RemoveEmptyEntries); var ins = new int[vs.Length]; for (int i = 0; i < vs.Length; i++) ins[i] = int.Parse(vs[i]); return ins; }
    public static int LnInt() { var vs = Console.ReadLine().Trim(); return int.Parse(vs); }
    public static long[] LnLngs() { var vs = Console.ReadLine().Trim().Split(new[] { ' ' }, StringSplitOptions.RemoveEmptyEntries); var ins = new long[vs.Length]; for (int i = 0; i < vs.Length; i++) ins[i] = long.Parse(vs[i]); return ins; }
    public static long LnLng() { var vs = Console.ReadLine().Trim(); return long.Parse(vs); }
    public static string[] LnStrs() { var vs = Console.ReadLine().Trim().Split(new[] { ' ' }, StringSplitOptions.RemoveEmptyEntries); return vs; }
    public static string LnStr() { var vs = Console.ReadLine().Trim(); return vs; }
    public static List<T[]> AllPermutation<T>(params T[] array) where T : IComparable { var a = new List<T>(array).ToArray(); var res = new List<T[]>(); res.Add(new List<T>(a).ToArray()); var n = a.Length; var next = true; while (next) { next = false; int i; for (i = n - 2; i >= 0; i--) { if (a[i].CompareTo(a[i + 1]) < 0) break; } if (i < 0) break; var j = n; do { j--; } while (a[i].CompareTo(a[j]) > 0); if (a[i].CompareTo(a[j]) < 0) { var tmp = a[i]; a[i] = a[j]; a[j] = tmp; Array.Reverse(a, i + 1, n - i - 1); res.Add(new List<T>(a).ToArray()); next = true; } } return res; }
}


Measured memory_bytes: 27488
from math import gcd
k=int(input())
cnt=0
for i in range(1,k+1):
  for p in range(1,k+1):
    for q in range(1,k+1):
      gcd1=gcd(i,p)
      
      cnt+=gcd(gcd1,q)

      
print(cnt)
  



Measured memory_bytes: 9152
a, b, c, d = map(int, input().split())
ret = "Yes"
while a > 0 and c > 0:
    c = c - b
    if c <= 0:
        ret = "Yes"
        break
    a = a - d
    if a <= 0:
        ret = "No"
        break
print("{}".format(ret))

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

int main(){
	int N,ans = 0;
	int num[210];
	bool flag = true;

	cin >> N;

	for (int i = 0; i < N; ++i) {
		cin >> num[i];
	}
	
	while (true) {
		for (int i = 0; i < N; ++i) {
			if (num[i] % 2 == 0) {
				num[i] = num[i] / 2;
			}
			else {
				flag = false;
				break;
			}
		}

			if (flag) {
				ans++;
			}
			else break;
	}

	

	cout << ans;

	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <vector>
#include <string>
#include <cmath>
#include <map>
#include <climits>
#include <algorithm>
#include <utility>

using namespace std;
using Int = long long int;
using UInt = unsigned long long int;
using VI = vector<long long int>;

int main(void) {
    Int a, p;
    cin >> a >> p;
    cout << (a * 3 + p) / 2 << endl;
    return 0;
}



Measured memory_bytes: 3628
#include <iostream>
#include <string>
#include <stack>
#include <queue>
#include <vector>
#include <list>
#include <set>
#include <map>
#include <algorithm>

#include <cstdio>

using namespace std;
#define rep(i, n) for (int i = 0; i < (n); i++)
#define rep1(i, s, n) for (int i = (s); i <= (n); i++)
#define rrep(i, n) for (int i = (n) - 1; i >= 0; i--)
#define rrep1(i, s, n) for (int i = (s); i >= (n); i--)
#define print_array(ary, size) cout << ary[0]; rep1(i, 1, size - 1) cout << ' ' << ary[i]; cout << endl;
typedef long long ll;
typedef unsigned long long ull;

int H;
int A[2000001];

void maxHeapify(int i)
{
	int left = i * 2;
	int right = i * 2 + 1;
	int largest = i;
	int tmp;

	if (left <= H && A[largest] < A[left]) largest = left;
	if (right <= H && A[largest] < A[right]) largest = right;

	if (largest != i) {
		tmp = A[i];
		A[i] = A[largest];
		A[largest] = tmp;
		maxHeapify(largest);
	}
}

void insert(int key)
{
	int i, j, tmp;
	H++;
	A[H] = key;
	i = H / 2;
	j = H;
	while (i > 0) {
		if (A[i] < A[j]) {
			tmp = A[i];
			A[i] = A[j];
			A[j] = tmp;
			j = i;
			i /= 2;
		}
		else break;
	}
}

int extractMax()
{
	int ret = A[1];

	A[1] = A[H];
	H--;

	maxHeapify(1);

	return ret;
}

int main()
{
	string direction;
	int key;

	while (true) {
		cin >> direction;
		if (direction == "end") break;
		else if (direction == "insert") {
			cin >> key;
			insert(key);
		}
		else {
			key = extractMax();
			cout << key << endl;
		}
	}

	return 0;
}


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



int main(){

	ll n,k;
	string s;
	cin>>n>>k>>s;
	vector<pair<ll,ll>>v;
	bool f=false;
	ll lef,rig;
	for(int i=0;i<n;i++){
		if(!f&&s[i]=='0'){
			f=1;
			lef=i;
		}
		if(f&&s[i]=='1'){
			f=0;
			rig=i-1;
			v.push_back(make_pair(lef,rig));
		}
		if(i==n-1&&s[n-1]=='0'){
			rig=n-1;
			v.push_back(make_pair(lef,rig));
		}
	}
	ll ans=0;
	if(v.size()<=k)ans=n;
	else{
		ll le,ri;
		for(int i=0;i<=v.size()-k;i++){
			if(!i)le=0;
			else le=v[i-1].second+1;
			if(i==v.size()-k)ri=n-1;
			else ri=v[i+k].first-1;
			ans=max(ans,ri-le+1);
		}
	}
	cout<<ans;
	return 0;
}


Measured memory_bytes: 1528
#include<cstring>
#include<cstdio>
#include<cmath>
#include<iostream>
#include<algorithm>
#include<map>
#include<queue>
#include<string>
#define fi first
#define se second
#define ll long long
#define INF 0x3f3f3f
using namespace std;
int main (void)
{
    ll n,sum,i,j,k,t;
    scanf("%lld",&n);
    t=(ll)0;
    k=(ll)1;
    while(n)
    {
        n/=2;
        t+=k;
        k*=2;
    }
    printf("%lld\n",t);
    return 0;
}

Measured memory_bytes: 256
r, c = map(int, input().split())
M = [[0] * c for _ in range(r)]
for i in range(r):
    m = list(map(int, input().split()))
    for j in range(c):
        M[i][j] = m[j]
for i in range(r):
    M[i].append(sum(M[i]))
Mr = [0] * (c + 1)
for i in range(r):
    for j in range(c + 1):
        Mr[j] += M[i][j]
M.append(Mr)
for i in range(r + 1):
    for j in range(c):
        print(M[i][j], end=' ')
    print(M[i][c])


Measured memory_bytes: 6240
def F(A, B, X):
    p = (A * X) // B
    q = A * (X // B)
    return p - q


if __name__ == "__main__":
    A, B, N = map(int, input().split())
    # B周期、X％B=B-1のときに最大, 単調増加
    if N >= B - 1:
        ans = F(A, B, B - 1)
    else:
        ans = F(A, B, N)
    print(ans)

Measured memory_bytes: 9192
import sys
readline = sys.stdin.readline

N = int(readline())
A = [None] * N
for i in range(N):
  # 後ろからpopできるように逆順リストで持つ
  A[i] = list(map(lambda x:x - 1,map(int,readline().split())))[::-1]
  
# 今日試合ができる可能性がある人リスト
candi = set(range(N))

day = 0
while candi:
  day += 1
  nex = set()
  done = set()
  for player in candi:
    if player in done:
      continue
    # player が試合できるかチェック
    if len(A[player]) == 0:
      continue
    rival = A[player][-1]
    if rival in done:
      continue
    if A[rival][-1] == player:
      # 試合できる
      A[player].pop()
      A[rival].pop()
      if A[player]:
        nex.add(player)
      done.add(player)
      if A[rival]:
        nex.add(rival)
      done.add(rival)
  if len(done) == 0:
    # 一試合もできなかった
    print(-1)
    exit(0)
  candi = nex
  
print(day)

Measured memory_bytes: 40816
#include<iostream>
#include<string>
using namespace std;
string s,t;
int leh;
bool pd(string a,string b)
{
	int ls,ltl;
	bool f=0;
	for(int lt=0;lt<leh&&!f;lt++)
	{
		ls=0;ltl=lt;
		for(int i=0;i<leh;i++)
		{
			if(i==leh-1){f=1;break;}
			if(s[ls]==t[ltl])
			{ls++;ltl=ltl<leh-1?ltl+1:0;}
			else break;
		}
	}
	return f;
}
int main()
{
	cin>>s>>t;
	leh=s.size();
	if(pd(s,t))
		cout<<"Yes"<<endl;
	else cout<<"No"<<endl;
}

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

#define debug(x) cout <<"DEBUG"<<" "<< #x << ":" << x << '\n'
#define rep(i,n) for(int_fast32_t i = 0; i < ((int_fast32_t)(n)); i++)   // 0-indexed昇順
#define rep1(i,n) for(int_fast32_t i = 1; i <= ((int_fast32_t)(n)); i++) // 1-indexed昇順
#define rrep(i,n) for(int_fast32_t i = ((int_fast32_t)(n)-1); i >= 0; i--)  // 0-indexed降順
#define rrep1(i,n) for(int_fast32_t i = ((int_fast32_t)(n)); i >= 1; i--)   // 1-indexed降順
#define all(x) (x).begin(),(x).end()

using namespace std;

template<typename T>
using vec = vector<T>;
using i32 = int_fast32_t;
using i64 = int_fast64_t;
using u32 = uint_fast32_t;
using u64 = uint_fast64_t;
using ll = long long;
using ld = long double;
using vi = vec<int_fast32_t>;
using vl = vec<int_fast64_t>;
using vld = vec<ld>;
using vii = vec<vi>;  // 2次元配列
using PII = pair<int_fast32_t, int_fast32_t>;

template<class T>
using maxheap = std::priority_queue<T>;
template<class T>
using minheap = std::priority_queue<T, std::vector<T>, std::greater<T>>;

template<class T,class U> inline bool chmax(T &a, const U &b){if(a<b){a=b;return 1;}return 0;}
template<class T,class U> inline bool chmin(T &a, const U &b){if(a>b){a=b;return 1;}return 0;}

const ld Pi = std::acos(-1.0L);
constexpr ll infll = (1LL<<62)-1;
constexpr int inf = (1<<30)-1;
const int mod = 1000000007;
// const int mod = 998244353;


/*FUNCs=================================================*/
//nの素因数とその個数のpairのmapを返す
template<typename T_n>
std::map<T_n, int> prime_factor(T_n n) {
    std::map<T_n, int> ret;
    for(T_n i = 2; i*i <= n; i++){
        while(n % i == 0){
            ret[i]++;
            n /= i;
        }
    }
    if(n != 1) ret[n] = 1;
    return ret;
}

/*MAIN==================================================*/
signed main(){
    int START_TIME = clock();
    cin.tie(nullptr);
    ios::sync_with_stdio(false);   //cin cout 高速化
//    cout << fixed << setprecision(15);

    string s,t;
    i64 n,m;
    cin >> n;

    i64 ans = 0;
    auto mp = prime_factor<i64>(n);
    for(auto p : mp) {
        i64 tmp = 0;
        for(i32 i = 1; p.second > 0; ++i) {
            p.second -= i;
            if(p.second < 0) break;
            ++tmp;
        }
//        debug(tmp);
        ans += tmp;
    }

    cout<< ans << '\n';




    // printf("ExecutionTime: %d /ms\n",1000*(int)((clock()-START_TIME)/CLOCKS_PER_SEC));
}


Measured memory_bytes: 3676
import java.io.BufferedReader;
import java.io.InputStreamReader;

public class Main {
	public static void main(String[] args) throws Exception {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		String line;
		while ((line = br.readLine()) != null) {
			String[] arr = line.split(" ");
			int m = Integer.parseInt(arr[0]);
			int f = Integer.parseInt(arr[1]);
			int r = Integer.parseInt(arr[2]);
			if (m == -1 && f == -1 && r == -1)
				break;

			if (m == -1 || f == -1)
				System.out.println("F");
			else if (m + f >= 80)
				System.out.println("A");
			else if (m + f >= 65)
				System.out.println("B");
			else if (m + f >= 50)
				System.out.println("C");
			else if (m + f >= 30) {
				if (r >= 50)
					System.out.println("C");
				else
					System.out.println("D");
			} else
				System.out.println("F");
		}
	}
}

Measured memory_bytes: 16944
#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);
    }
    sort(A.begin(), A.end());
    int ans = A.at(A.size() - 1) - A.at(0);
    if (ans < 0) {
        ans *= -1;
    }
    cout << ans << endl;
}

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

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

typedef long long ll;
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<long long> VL;
typedef vector<vector<long long>> VVL;
typedef vector<string> VS;
typedef pair<int, int> P;
typedef tuple<int,int,int> tpl;

#define ALL(a)  (a).begin(),(a).end()
#define SORT(c) sort((c).begin(),(c).end())
#define REVERSE(c) reverse((c).begin(),(c).end())
#define EXIST(m,v) (m).find((v)) != (m).end()
#define LB(a,x) lower_bound((a).begin(), (a).end(), x) - (a).begin()
#define UB(a,x) upper_bound((a).begin(), (a).end(), x) - (a).begin()

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)
#define RFOR(i,a,b) for(int i=(a)-1;i>=(b);--i)
#define RREP(i,n) RFOR(i,n,0)

#define en "\n"

constexpr double EPS = 1e-9;
constexpr double PI  = 3.1415926535897932;
constexpr int INF = 2147483647;
constexpr long long LINF = 1LL<<60;
constexpr long long MOD = 1000000007; // 998244353;

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

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

void Main(){
    int N,K; cin >> N >> K;
    VI A(N); REP(i,N) cin >> A[i];

    REP(_,K){
        bool flag = true;
        VI imos(N+1,0);
        REP(i,N){
            imos[max(0,i-A[i])]++;
            imos[min(N-1,i+A[i])+1]--;
        }
        REP(i,N){
            imos[i+1] += imos[i];
            A[i] = imos[i];
            if(A[i]<N) flag = false;
        }
        if(flag) break;
    }

    REP(i,N) cout << A[i] << " ";
    cout << en;
    return;
}

int main(void){
    cin.tie(0);cout.tie(0);ios_base::sync_with_stdio(0);cout<<fixed<<setprecision(15);
    int t=1; //cin>>t;
    REP(_,t) Main();
    return 0;
}

Measured memory_bytes: 5004
from collections import deque
import sys
readline = sys.stdin.readline
write = sys.stdout.write
 
root = None
def insert(z):
    global root
    y = None
    x = root
    while x is not None:
        y = x
        if z[2] < x[2]:
            x = x[0]
        else:
            x = x[1]
    z[3] = y
 
    if y is None:
        root = z
    elif z[2] < y[2]:
        y[0] = z
    else:
        y[1] = z
 
def find(k):
    x = root
    while x is not None:
        if x[2] == k:
            return 1
        if k < x[2]:
            x = x[0]
        else:
            x = x[1]
    return 0
 
def debug():
    s0 = [""]
    s1 = [""]
 
    def dfs(nd):
        v = str(nd[2])
        s0.append(v)
        if nd[0] is not None:
            dfs(nd[0])
        s1.append(v)
        if nd[1] is not None:
            dfs(nd[1])
    dfs(root)
    return " ".join(s1), " ".join(s0)
 
 
M = int(readline())
ans = []
for m in range(M):
    cmd, *V, = readline().split()
    if cmd == "print":
        ans.extend(debug())
    elif cmd == "find":
        ans.append("yes" if find(int(V[0])) else "no")
    else:
        insert([None, None, int(V[0]), None])
write("\n".join(ans))
write("\n")


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

int main(){
	string str;
	cin>>str;
	int n=str.length();long long k,sum=0;
	
	for(int i=0;i<(1<<(n-1));i++){	//2^(n-1)通りの全探索
		k=str[0]-'0';
		
		for(int j=0;j<n-1;j++){
			if(i&(1<<j)){	//j桁目が1なら'+'を入れる
				sum+=k;
				k=str[j+1]-'0';
			}else{
				k=10*k+str[j+1]-'0';
			}
		}
		sum+=k;
	}
	
	cout<<sum<<endl;
	
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, a, n) for(int i = a; i < n; i++)
#define repb(i, a, b) for(int i = a; i >= b; i--)
#define all(a) a.begin(), a.end()
#define int long long
using namespace std;
typedef pair<int, int> P;

signed main(){
    int n;
    cin >> n;
    rep(i, 0, n){
        int ans;
        double x[2], y[2], r[2];
        rep(j, 0, 2) cin >> x[j] >> y[j] >> r[j];
        double d = sqrt(pow(x[0] - x[1], 2) + pow(y[0] - y[1], 2));
        if(r[0] + r[1] < d) ans = 0;
        else if(r[0] > d + r[1]) ans = 2;
        else if(r[1] > d + r[0]) ans = -2;
        else  ans = 1;        
        cout << ans << endl;
    }
}

Measured memory_bytes: 3132
#include <iostream>
using namespace std;
int main()
{
	int a,b;
	cin >> a >> b;
	if(a % 3 == 0 || b % 3 == 0 || (a+b) % 3 == 0)
	    {
	    	cout << "Possible" << endl;
		}
		else
		    {
		    	cout << "Impossible" << endl;
			}
	return 0;
}

Measured memory_bytes: 256
#[allow(unused_macros)]
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        let mut next = || { iter.next().unwrap() };
        input_inner!{next, $($r)*}
    };
    ($($r:tt)*) => {
        let stdin = std::io::stdin();
        let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));
        let mut next = move || -> String{
            bytes
                .by_ref()
                .map(|r|r.unwrap() as char)
                .skip_while(|c|c.is_whitespace())
                .take_while(|c|!c.is_whitespace())
                .collect()
        };
        input_inner!{next, $($r)*}
    };
}

#[allow(unused_macros)]
macro_rules! input_inner {
    ($next:expr) => {};
    ($next:expr, ) => {};

    ($next:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };

    ($next:expr, mut $var:ident : $t:tt $($r:tt)*) => {
        let mut $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };
}

#[allow(unused_macros)]
macro_rules! read_value {
    ($next:expr, ( $($t:tt),* )) => {
        ( $(read_value!($next, $t)),* )
    };

    ($next:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
    };

    ($next:expr, chars) => {
        read_value!($next, String).chars().collect::<Vec<char>>()
    };

    ($next:expr, bytes) => {
        read_value!($next, String).into_bytes()
    };

    ($next:expr, usize1) => {
        read_value!($next, usize) - 1
    };

    ($next:expr, $t:ty) => {
        $next().parse::<$t>().expect("Parse error")
    };
}
use std::collections::HashSet;
fn main() {
    input!{
        n:usize,
        s:chars,
    }
    let mut max:i64 = -1;
    for i in 0..n {
        let mut x = HashSet::new();
        let mut y = HashSet::new();
        for j1 in 0..i {
            x.insert(s[j1]);
        }
        for j2 in i..n {
            y.insert(s[j2]);
        }
        let mut v = vec![];
        for z in x.intersection(&y) {
            v.push(z);
        }
        // println!("{:?}", v);
        // println!("{:?} {:?}", x, y);
        // println!("{:?}", x.intersection(&y));
        // max = std::cmp::max(max, x.intersection(&y).collect().len())
        max = std::cmp::max(max, v.len() as i64 );
    }
    println!("{}", max);

}

Measured memory_bytes: 4352
#include<bits/stdc++.h>
#define for_int(i,a,b) for(int i=(a);i<=(b);++i)
#define rep_int(i,a,b) for(int i=(a);i>=(b);--i)
#define for_ll(i,a,b) for(ll i=(a);i<=(b);++i)
#define rep_ll(i,a,b) for(ll i=(a);i>=(b);--i)
#define ull unsigned long long
#define ll long long
#define db double
#define HPMAX 1005
#define KMP_MAX 1005
#define prime_MAX 1e6+5
#define quick_pow_mod 1e9+7
#define PII pair<int,int>
const int factor_N = 1e7 + 5;
const int tree_arr_N = 1e6 + 5;
using namespace std;
//快读
int read() {
	char c = getchar();
	int x = 0, f = 1;
	for (; !isdigit(c); c = getchar())
		if (c == '-') f = -1;
	for (; isdigit(c); c = getchar()) x = x * 10 + c - 48;
	return x * f;
}
int k, ans;
int main() {
	k = read();
	if (k % 2 == 0) {
		cout << -1 << endl;
		return 0;
	}
	int a = 7;
	ans = 1;
	for (int i = 1; i <= k; ++i) {
		if (a % k == 0) {
			a = 0;
			break;
		}
		ans++;
		a = a * 10 + 7;
		a %= k;
	}
	if (a != 0) cout << -1 << endl;
	else cout << ans << endl;
	return 0;
}

Measured memory_bytes: 3632
#include <map>
#include <algorithm>
#include <cassert>
#include <climits>
#include <complex>
#include <cstdio>
#include <string>
#include <iostream>
#include <queue>
#include <string>
#include <tuple>
#include <vector>
using namespace std;
using ll = long long;
using ld = long double;
template <typename T> T &chmin(T &a, const T &b) { return a = min(a, b); }
template <typename T> T &chmax(T &a, const T &b) { return a = max(a, b); }
#define all(a) (a).begin(), (a).end()
#define uni(a) (a).erase(unique(all(a)), (a).end())
#define bit(n, i) (((n) >> (i)) & 1)
#define bitcount(n) __builtin_popcountll(n)
#define DEBUG(X) cerr<<"  "<<#X<<" = "<<X<<endl;
#define DUMP(A, n) for (auto x=begin(A); x!=begin(A)+n;x++){cout <<*x<< ' ';} cout<<endl;
#define DUMPP(A, n, m) for (auto x=begin(A); x != begin(A)+n;x++) {for (auto y=begin(*x); y != begin(*x)+m;)cout <<*y++<< ' '; cout<<endl;};
#define DUMPM(M) for (auto itr=mp.begin(); itr!=mp.end(); itr++) {cout<<itr->first<<" -> "<<itr->second<<endl;}
#define FOR(i,x,y) for(int i=(x);i<(int)(y);i++)
#define FORP(i,x,y) for(int i=(x);i<=(int)(y);i++)
#define REP(i,y) for(int i=0;i<(int)(y);i++)
#define REPP(i,y) for(int i=1;i<=(int)(y);i++)
#define RREP(i,n) for(int i=(int)(n)-1;i>=0;i--)

int H,W;
string maze[500];
char ans[500][500];

bool cnd(int y, int x) {
  return y>=0&&x>=0&&y<H&&x<W&&maze[y][x]=='#';
}

int cntf(int x, int y) {
  int cnt=0;
  if (cnd(y-1,x)) cnt++;
  if (cnd(y+1,x)) cnt++;
  if (cnd(y,x-1)) cnt++;
  if (cnd(y,x+1)) cnt++;
  if (cnd(y-1,x-1)) cnt++;
  if (cnd(y+1,x-1)) cnt++;
  if (cnd(y-1,x+1)) cnt++;
  if (cnd(y+1,x+1)) cnt++;
  return cnt;
}

int main() {
  cin >> H >> W;
  REP(y,H) {
    cin >> maze[y];
  }
  REP(y,H) {
    REP(x,W) {
      if (maze[y][x]!='#')
        ans[y][x]=cntf(x,y)+'0';
      else
        ans[y][x]='#';
    }
  }
  REP(y,H) {
    REP(x,W) {
      cout << ans[y][x];
    }
    cout << endl;
  }
}


Measured memory_bytes: 256
#include <iostream>

using namespace std;

int main(){
    int N;
    cin >> N;
    int ans = 0;
    for(int i = 0; i < N; i++){
        int a;
        cin >> a;
        while(a%2 == 0){
            ans++;
            a /= 2;
        }
    }
    cout << ans << endl;
}

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

int compare_strings(const void *a, const void *b)
{
    return strcmp((char *)a, (char *)b);
}

int main(void)
{
    int N;
    char S[200000][11];
    int array_length;
    int counter, max;
    int i;

    scanf("%d", &N);
    for (i = 0; i < N; i++)
    {
        scanf("%s", S[i]);
    }
    array_length = i;

    // Sorting by alphabetical order
    qsort(S, array_length, sizeof(S[0]), compare_strings);

    // Checking the sorted input
    // printf("--Sorted input--\n");
    // for (i = 0; i < N; i++)
    // {
    //     for (j = 0; S[i][j] != '\0'; j++)
    //     {
    //         printf("%c", S[i][j]);
    //     }
    //     printf("\n");
    // }

    // Couting words by strcmp by neighbours
    counter = 1;
    max = 0;
    for (i = 0; i < N - 1; i++)
    {
        if (strcmp(S[i], S[i + 1]) == 0)
        {
            counter++;
        }
        else
        {
            counter = 1;
        }

        if (max < counter)
        {
            max = counter;
        }
    }

    counter = 1;
    for (i = 0; i < N; i++)
    {
        if (strcmp(S[i], S[i + 1]) == 0)
        {
            counter++;
        }
        else
        {
            counter = 1;
        }

        if (counter == max)
        {
            printf("%s\n", S[i]);
        }
    }
    return (0);
}

Measured memory_bytes: 4476
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n); for(int i = 0;i < (int)(n);i++)
#define all(x) (x).begin(),(x).end()
typedef long long ll;
int main(){
    int n;
    cin >> n;
    int c[n];
    rep(i,n){
        char s;
        cin >> s;
        if(s == 'R')c[i] = 1;
        else c[i] = 0;
    }
    int r = 0;
    int w = 0;
    rep(i,n){
        if(c[i])r++;
        else w++;
    }
    int lw = 0;
    rep(i,r){
        if(c[i] == 0)lw++;
    }
    cout << lw << endl;
    return 0;
}

Measured memory_bytes: 4400
K, N = map(int, input().split())
A = list(map(int, input().split()))
A.append(K - A[-1] + A[0])
sa_max = A[-1]
for i in range(N - 1):
    sa = A[i + 1] - A[i]
    if sa_max < sa:
        sa_max = sa
print((A[-2] - A[0]) + A[-1] - sa_max)


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

using namespace std;

int cost(int n, vector<int> &A){
    int ans = 0;
    for(int i=0;i<A.size();i++){
        ans += (n - A[i]) * (n - A[i]);
    }
    return ans;
}

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

    int ans = 2e9;
    for(int i=-100; i<=100;i++){
        ans = min(ans, cost(i,A));
    }
    cout << ans << endl;
    return 0;
}

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

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

  ll N; cin >> N;
  ll T; cin >> T;
  vector<ll> C(T + 1, 0);
  for (ll i = 0; i < N; i++) {
    ll l, r; cin >> l >> r;
    C[l]++, C[r]--;
  }
  for (ll i = 0; i < T; i++) {
    C[i + 1] += C[i];
  }
  ll ans = *max_element(C.begin(), C.end());
  cout << ans << '\n';
  return 0;
}


Measured memory_bytes: 3584
import math, string, itertools, fractions, heapq, collections, re,  array, bisect, sys, random, time, copy, functools
sys.setrecursionlimit(10**7)
inf = 10 ** 20
eps = 1.0 / 10**10
mod = 10**9+7
dd = [(-1, 0), (0, 1), (1, 0), (0, -1)]
ddn = [(-1, 0), (-1, 1), (0, 1), (1, 1), (1, 0), (1, -1), (0, -1), (-1, -1)]
def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LI_(): return [int(x)-1 for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def _I(): return int(sys.stdin.readline())
def _F(): return float(sys.stdin.readline())
def pf(s): return print(s, flush=True)

N,T=LI()
tl=LI()

ans=0
for tidx, t in enumerate(reversed(tl)):
	#print(tidx)
	if tidx==0:
		ans +=T
		continue
	#print(t,N-tidx)
	ans += min(T,abs(t-tl[N-tidx]))

	
print(ans)

Measured memory_bytes: 105420
#include <bits/stdc++.h>
using namespace std;
#include <ext/pb_ds/assoc_container.hpp> 
#include <ext/pb_ds/tree_policy.hpp> 
using namespace __gnu_pbds; 
#define ordered_set tree<int,null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update> 
#define ordered_set_pair tree<pair<int,int>,null_type,less<pair<int,int>>, rb_tree_tag,tree_order_statistics_node_update> 
#define ordered_set_mutiset tree<int,null_type,less_equal<int>, rb_tree_tag,tree_order_statistics_node_update>
typedef long long int ll;
typedef long double ld;
typedef unsigned long long int ull;
typedef pair<int,int> pi; 
#define PI 3.1415926535897932384
#define FOR(i,vv,n) for(int i=vv;i<n;i++)
#define FORR(i,n,vv) for(int i=n-1;i>=vv;i--)
#define ve vector 
#define maxind(v) (max_element(v.begin(),v.end())-v.begin())
#define minind(v) (min_element(v.begin(),v.end())-v.begin())
#define maxe(v) *max_element(v.begin(),v.end())
#define mine(v) *min_element(v.begin(),v.end())
#define pb push_back
#define pf push_front
#define ppb pop_back
#define ppf pop_front
#define eb emplace_back
#define FAST ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define mp make_pair
#define M 1000000007ll
#define INF 1000000000000000000ll
#define PRECISE cout.precision(18);
#define all(v) v.begin(),v.end()
#define BS(v,n) binary_search(all(v),n)
#define srt(v) sort(v.begin(),v.end())
#define rsrt(v) sort(all(v),greater <ll>())
#define uni(v) v.resize(unique(all(v)-v.begin())
#define F first
#define S second
#define GET(i,p) get<p>(i)


int main(){

    FAST
//	PRECISE


FOR(i,0,5){
	ll x;
	cin>>x;
	if(x==0){
		cout<<i+1;
	return 0;}
}


return 0;
 }



Measured memory_bytes: 3608
#include <algorithm>
#include <assert.h>
#include <bitset>
#include <cfloat>
#include <deque>
#include <fstream>
#include <functional>
#include <iomanip>
#include <iostream>
#include <limits.h>
#include <list>
#include <map>
#include <math.h>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <string>
#include <string.h>
#include <time.h>
#include <unordered_map>
#include <unordered_set>
#include <vector>
#define rep(i,n) for(int i=0;i<n;i++)
#define REP(i,n) for(int i=1;i<=n;i++)
#define int long long
#define ll long long
#define eps LDBL_EPSILON
#define mod (ll)1000000007
#define INF LLONG_MAX/10
#define P pair<int,int>
#define prique priority_queue
using namespace std;
int n, k;
string s;
signed main() {
	cin >> n >> k >> s;
	int ans = 0;
	rep(i, n) {
		if (s[i] == 'R') {
			if (i + 1 < n && s[i + 1] == 'R')ans++;
		}
		if (s[i] == 'L') {
			if (0 <= i - 1 && s[i - 1] == 'L')ans++;
		}
	}
	cout << min(n - 1, ans + 2 * k) << endl;
}

Measured memory_bytes: 512
import java.util.*;

public class Main {
    public static void main(String[] args) throws Exception {
        
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        int M = sc.nextInt();
        int C = sc.nextInt();
        
        int[] B =new int[M];
        int[][] A = new int[N][M];
        
        for(int i=0;i<M;i++){
            B[i] =sc.nextInt();
        }
        
        for(int i=0; i<N; i++){
            for(int j=0;j<M;j++){
                A[i][j] =sc.nextInt();
            }
        }
        int cou = 0;
		for(int i=0; i<N; i++) {
			int al = 0;
			for(int j=0; j<M; j++) {
				al += A[i][j]*B[j];
			}
				if(al+C>0) {
					cou++;
				}				
		}
		System.out.println(cou);
        
    }
}


Measured memory_bytes: 38168
#!/usr/bin/env python3
import sys
def solve(N: int, D: "List[List[int]]"):
    count = 0
    flag = True
    for value in list(map(lambda k: k[0] == k[1], D)):
        if value:
            count += 1
        elif count < 3:
            count = 0
    ans = "Yes" if count >= 3 else "No"
    print(ans)
    return


def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    D = [[int(next(tokens)) for _ in range(2)] for _ in range(N)]  # type: "List[List[int]]"
    solve(N, D)

if __name__ == '__main__':
    main()


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

typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,int> plli;
typedef pair<int,pii> pipii;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<vi> vvi;
typedef vector<vvi> vvvi;
typedef vector<pii> vpii;

#define rep(i,n) for (int i=0;i<(n);i++)
#define rep2(i,a,b) for (int i=(a);i<(b);i++)
#define rrep(i,n) for (int i=(n);i>0;i--)
#define rrep2(i,a,b) for (int i=(a);i>b;i--)
#define pb push_back
#define fi first
#define se second
#define all(a) (a).begin(),(a).end()

const ll mod = 1e9 + 7;
const ll INF = 1<<30;
const int dx4[4] = {1, 0, -1, 0};
const int dy4[4] = {0, 1, 0, -1};
const int dx8[8] = {1, 1, 1, 0, 0, -1, -1, -1};
const int dy8[8] = {0, 1, -1, 1, -1, 0, 1, -1};
const double pi = 3.141592653589793;

int n, a, b, c;
int d[105];

signed main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    cin >> n;
    cin >> a >> b;
    cin >> c;
    rep(i, n) cin >> d[i];
    int low = 0;
    int high = 1e12;
    while (high - low > 1) {
        int mid = (high + low) / 2;
        int db[n] = {};
        rep(i, n) db[i] = d[i] - mid * b;
        sort(db, db + n);
        int tmp = c - mid * a;
        rep(i, n) if(db[i] > 0) tmp += db[i];
        if (tmp >= 0) low = mid;
        else high = mid;
    }
    cout << low << endl;
}

Measured memory_bytes: 3204
#include<stdio.h>
#include<iostream>
#include<algorithm>
#include<cstdio>
#include<string>
#include<cmath>
#include<numeric>
#include<vector>
#include<tuple>
using namespace std;
#define FOR(i,a,b) for(ll i=a;i<b;i++)
#define vint vector<int> 
#define vvint vector<vint>
#define ct(a) cout<<a<<endl
typedef long long ll;
const int MOD = 1e9 + 7;

int N;
int main(void)
{
	cin >> N;
	ll log;
	FOR(i, 1, 100000) {
		ll c = i * (i + 1) / 2;
		if (c >= N) {
			log = i;
			break;
		}
	}
	cout << log << endl;
	return 0;
}

Measured memory_bytes: 256
n, k = map(int, input().split())
h = [int(i) - 1 for i in input().split()]
d = [float('inf')] * n
d[0] = 0
for i in range(1, n):
    costs = []
    for j in range(1, k + 1):
        if i - j >= 0:
            costs.append(d[i - j] + abs(h[i] - h[i - j]))
    d[i] = min(d[i], min(costs))
print(d[-1])

Measured memory_bytes: 55264
def main():
    N, X = map(int, input().split())
    L = list(map(int, input().split()))
    ans = 1
    d = 0
    for i in range(N):
        d += L[i]
        if d <= X:
            ans += 1
    print(ans)


if __name__ == "__main__":
    main()


Measured memory_bytes: 38256
def main():
    n, k = map(int, input().split())
    a = list(map(int, input().split()))
    mod = 10**9+7
    ans = 1
    s, t = [], []
    for i in range(n):
        if a[i] < 0:
            t.append(a[i])
        else:
            s.append(a[i])
    # s, t = [i for i in a if i > 0], [j for j in a if j < 0]

    S, T = len(s), len(t)
    ok = False

    if S > 0:
        if n == k:
            ok = (T % 2 == 0)
        else:
            ok = True
    else:
        ok = (k % 2 == 0)

    if not ok:
        a.sort(key=abs)
        for i in range(k):
            ans *= a[i]
            ans %= mod
    else:
        s.sort()
        t.sort(reverse=True)
        if k % 2 == 1:
            ans *= s.pop()
            ans %= mod
        p = []
        while len(s) >= 2:
            x = s.pop()
            x *= s.pop()
            p.append(x)
        while len(t) >= 2:
            x = t.pop()
            x *= t.pop()
            p.append(x)
        p.sort(reverse=True)
        for i in range(k//2):
            ans *= p[i]
            ans %= mod
    print(ans % mod)


if __name__ == '__main__':
    main()


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

int main() {
    int n, m;
    int a[100][100];
    int b[100];
    int c[100];
    
    cin >> n >> m;
    for(int i=0; i<n; i++){
        for(int j=0; j<m; j++){
            cin >> a[i][j];
        }
    }
    for(int i=0; i<m; i++){
        cin >> b[i];
    }
    for(int i=0; i<n; i++){
        c[i]=0;
        for(int j=0; j<m; j++){
            c[i] += (a[i][j] * b[j]);
        }
    }
    for(int i=0; i<n; i++){
        cout << c[i] << endl;
    }
    return 0;
}

Measured memory_bytes: 1200
n,a,b,c=int(input()),list(map(int,input().split())),[],[]
for i in range(n):
  if i%2==((n+1)%2):c.append(a[i])
  else:b.append(a[i])
ans=c[::-1]+b
print(ans[0],end="")
for i in range(1,n):print(" "+str(ans[i]),end="")

Measured memory_bytes: 26180
#include <iostream>


int main()
{
    std::ios_base::sync_with_stdio(0);

    int X,bt;
    std::cin>>X;
    bt = int(X/1.08);
    if(bt*1.08==X) std::cout<<bt<<'\n';
    else if(int((bt+1)*1.08)==X) std::cout<<bt+1<<'\n';
    else std::cout<<":("<<'\n';
    
    return 0;
}




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

int main(){
    string a;
    char c[10]={'0','1','2','3','4','5','6','7','8','9'};
    int b;
    while(true){
    b=0;
    cin>>a;
    if(a=="0"){
        break;
    }
    for(int i=0;i<a.size();i++){
        for(int j=0;j<10;j++){
            if(a[i]==c[j]){
                b += j;
            }
        }
    }
    cout<<b<<endl;
    }
    return 0;
}

Measured memory_bytes: 1188
takahashi, aoki, n = gets.split(" ").map(&:to_i)
if n >= takahashi
  if aoki - (n - takahashi) < 0
    puts "0 0"
  else
    puts "0 #{aoki - (n-takahashi)}"
  end
else
  puts "#{takahashi - n} #{aoki}"
end

Measured memory_bytes: 1788
#include<iostream>
#include<string>
#include<cstdio>
#include<vector>
#include<cmath>
#include<algorithm>
#include<functional>
#include<iomanip>
#include<queue>
#include<ciso646>
#include<random>
#include<map>
#include<set>
#include<bitset>
#include<stack>
#include<unordered_map>
#include<utility>
#include<cassert>
using namespace std;

#define int long long
typedef long long ll;

typedef unsigned long long ul;
typedef unsigned int ui;
const ll mod = 1000000007;
const ll INF = mod * mod;
typedef pair<int, int> P;
#define stop char nyaa;cin>>nyaa;
#define rep(i,n) for(int i=0;i<n;i++)
#define per(i,n) for(int i=n-1;i>=0;i--)
#define Rep(i,sta,n) for(int i=sta;i<n;i++)
#define rep1(i,n) for(int i=1;i<=n;i++)
#define per1(i,n) for(int i=n;i>=1;i--)
#define Rep1(i,sta,n) for(int i=sta;i<=n;i++)
typedef pair<ll, ll> LP;
typedef vector<ll> vec;
typedef vector<string> svec;
typedef long double ld;
typedef pair<ld, ld> LDP;
const ld eps = 1e-8;

void solve() {
	int n; ll k; cin >> n >> k;
	vector<int> a(n);
	int sum = 0;
	rep(i, n) {
		cin >> a[i]; sum += a[i];
	}
	vector<int> v;
	for (int i = 1; i <= 100000; i++) {
		if (sum%i == 0) {
			v.push_back(i);
			v.push_back(sum / i);
		}
	}
	sort(v.begin(), v.end());
	v.erase(unique(v.begin(), v.end()), v.end());
	int ans = 1;
	rep(i, v.size()) {
		if (v[i] == 1)continue;
		vector<int> b;
		rep(j, n) {
			b.push_back(a[j] % v[i]);
		}
		sort(b.begin(), b.end());
		int sum = 0;
		vector<int> rb(n+1);
		rep(j, n) {
			rb[j + 1] = rb[j] + b[j];
		}
		rep(j, n+1) {
			int le = rb[j];
			int ri = (n - j)*v[i] - (rb[n] - rb[j]);
			if (max(le, ri) <= k) {
				ans = v[i]; break;
			}
		}
	}
	cout << ans << endl;
}

signed main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	//cout << fixed << setprecision(10);
	//init();
	solve();
	//cout << "finish" << endl;
	//stop
	return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N=1e3+5,M=2e4+5,inf=0x3f3f3f3f,mod=1e9+7;
#define mst(a,b) memset(a,b,sizeof a)
#define lx x<<1
#define rx x<<1|1
#define reg register
#define PII pair<int,int>
#define fi first
#define se second
#define pb push_back
#define il inline
int n,m;
PII a[N<<1];
int w[N<<1];
ll d[N];
int main(){
	scanf("%d%d",&n,&m);
	for(int i=1;i<=m;i++){
		scanf("%d%d%d",&a[i].fi,&a[i].se,&w[i]);
	}
	for(int i=1;i<=n;i++) d[i]=-1e15;
	d[1]=0;
	ll d1=0,d2=0;
	for(int i=1;i<=2*n;i++){
		for(int j=1;j<=m;j++){
			d[a[j].se]=max(d[a[j].se],d[a[j].fi]+w[j]);
		}
		if(i==n) d1=d[n]; 
		if(i==2*n) d2=d[n];
	}
	if(d1!=d2) puts("inf");
	else printf("%lld\n",d1);
	return 0;
}

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

int main() {
    int a, b;
    cin >> a >> b;
  	int tmp = a + b;
  	if (tmp % 2 == 0) {
      cout << tmp / 2 << endl;
    } else {
      cout << tmp / 2 + 1 << endl;
    }
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <sstream>
#include <iomanip> 
#include <math.h>
#include <stdio.h>
#include <string.h>
#include <queue>
#include <stack>
#include <vector>
#include <map>
#include <set>
#include <functional>
#include <algorithm>
#include <unordered_map>
#include <unordered_set>
#include <bitset>

using namespace std;

vector<vector<int>> c;

int sum(int x, int y, int xx, int yy) {
	int ans = c[xx][yy] - c[x - 1][yy] - c[xx][y - 1] + c[x - 1][y - 1];
	return ans;
}

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

	int n, m, i, j, k, x, y, ss, top, xx, yy, id, a, b;
	cin >> n >> m >> k;
	vector<string> s(n + 1);
	c.assign(n + 1, vector<int>(m + 1, 0));
	vector<vector<int>> ans(n + 1, vector<int>(m + 1, 0));

	for (i = 1; i <= n; i++) {
		cin >> s[i];
		ss = 0;
		for (j = 0; j < m; j++) {
			if (s[i][j] == '#') ss++;
			c[i][j + 1] = c[i - 1][j + 1] + ss;
		}
	}

	top = 0;
	queue<tuple<int, int, int, int, int>> q;
	q.push({ 1, 1, n, m, 0 });

	while (!q.empty()) {
		tie(x, y, xx, yy, id) = q.front();
		q.pop();

		if (sum(x, y, xx, yy) == 1) {
			top++;
			for (i = x; i <= xx; i++) {
				for (j = y; j <= yy; j++) ans[i][j] = top;
			}
			continue;
		}

		if (id == 0) {
			// cut horizontally 
			for (a = x; (a <= xx) && (sum(a, y, a, yy) == 0); a++);
			if (a >= xx) {
				q.push({ x, y, xx, yy, 1 });
			}
			else {
				for (b = a + 1; (b <= xx) && (sum(b, y, b, yy) == 0); b++);
				a = b - 1;
				q.push({ x, y, a, yy, 1 });
				if (a < xx) 
					q.push({ a + 1, y, xx, yy, 0 });
			}
		}
		else {
			// cut vertically
			for (a = y; (a <= yy) && (sum(x, a, xx, a) == 0); a++);
			if (a >= yy) {
				q.push({ x, y, xx, yy, 0 });
			}
			else {
				for (b = a + 1; (b <= yy) && (sum(x, b, xx, b) == 0); b++);
				a = b - 1;
				q.push({ x, y, xx, a, 0 });
				if (a < yy) 
					q.push({ x, a + 1, xx, yy, 1 });
			}
		}
	}

	for (i = 1; i <= n; i++ ) {
		for (j = 1; j <= m; j++) cout << ans[i][j] << " ";
		cout << "\n";
	}

	return 0;
}



Measured memory_bytes: 1664
#include<iostream>
#include<string>
using namespace std;
string S[18] = { "","Man","Oku","Cho","Kei","Gai","Jo","Jou","Ko","Kan","Sei","Sai","Gok","Ggs","Asg","Nyt","Fks","Mts" };
int dp[2000][20];
int main() {
	int a, b;
	while (true) {
		cin >> a >> b;
		if (a == 0 && b == 0) { break; }
		for (int i = 0; i < 2000; i++) { 
			for (int j = 0; j < 18; j++) {
				dp[i][j] = 0;
			}
		}
		dp[0][0] = 1;
		for (int i = 1; i <= b; i++) {
			for (int j = 0; j < 18; j++) {
				dp[i][j] += dp[i - 1][j] * a;
				dp[i][j + 1] += dp[i][j] / 10000;
				dp[i][j] %= 10000;
			}
		}
		for (int j = 17; j >= 0; j--) {
			if (dp[b][j] >= 1) { 
				cout << dp[b][j] << S[j];
			}
		}
		cout << endl;
	}
}

Measured memory_bytes: 1364
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i,n) for(int i = 0; i < (n); i++)
#define all(v) v.begin(), v.end()
#define MOD 1000000007
const int INF = 1LL<<30;

int main(){
    int n;
    cin>>n;
    vector<int> a(n);
    rep(i,n) cin>>a[i];

    sort(all(a));
    vector<bool> ok(1000010,false);

    rep(i,n){
        if(ok[a[i]]) continue;
        for(int j=2*a[i];j<=a[n-1];j+=a[i]) ok[j]=true;
        if(a[i]==a[i+1]) ok[a[i]]=true;
    }

    int ans=0;
    rep(i,n){
        if(!ok[a[i]]){
            ans++;
            //cout<<a[i]<<endl;
        }
    }

    cout<<ans<<endl;
}

Measured memory_bytes: 4292
#include <bits/stdc++.h>
using namespace std;
using lint = long long int;

int main() {
    lint n;
    cin >> n;

    vector<long double> a(n);
    for(auto& elem : a)  cin >> elem;
    sort(a.begin(), a.end());

    lint ans = 1;
    for(int i=0; i<n; i++) {
        if(ans * a[i] > 1e18) {
            cout << -1 << endl;
            return 0;
        } else {
            ans *= a[i];
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 4772
//#pragma GCC optimize("Ofast")
//#pragma GCC optimize("unroll-loops")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using db = double;
using ld = long double;
template<typename T> using V = vector<T>;
template<typename T> using VV = vector<vector<T>>;
#define fs first
#define sc second
#define pb push_back
#define mp make_pair
#define mt make_tuple
#define eb emplace_back
#define lb lower_bound
#define ub upper_bound
#define all(v) (v).begin(),(v).end()
#define siz(v) (ll)(v).size()
#define rep(i,a,n) for(ll i=a;i<(ll)(n);++i)
#define repr(i,a,n) for(ll i=n-1;(ll)a<=i;--i)
#define ENDL '\n'
typedef pair<int,int> Pi;
typedef pair<ll,ll> PL;
constexpr ll mod = 1000000007;
constexpr ll INF = 1000000099;
constexpr ll LINF = (ll)(1e18 +99);
const vector<ll> dx={-1,1,0,0},dy={0,0,-1,1};
template<typename T,typename U> inline bool chmin(T& t, const U& u){if(t>u){t=u;return 1;}return 0;}
template<typename T,typename U> inline bool chmax(T& t, const U& u){if(t<u){t=u;return 1;}return 0;}
template<typename T> inline T gcd(T a,T b){return b?gcd(b,a%b):a;}
template<typename T,typename Y> inline T mpow(T a, Y n) {
  T res = 1;
  for(;n;n>>=1) {
    if (n & 1) res = res * a;
    a = a * a;
  }
  return res;
}



signed main(){
  cin.tie(0);ios::sync_with_stdio(false);
  cout<<fixed<<setprecision(20);
  ll a,b,m;cin>>a>>b>>m;
  ll ans=LINF,amn=LINF,bmn=LINF;
  V<ll> v(a);
  rep(i,0,a){
    cin>>v[i];
    chmin(amn,v[i]);
  }
  V<ll> u(b);
  rep(i,0,b){
    cin>>u[i];
    chmin(bmn,u[i]);
  }

  ans=amn+bmn;

  rep(i,0,m){
    ll x,y,c;cin>>x>>y>>c;
    x--;y--;
    chmin(ans,v[x]+u[y]-c);
  }

  cout<<ans<<ENDL;



  
}
//! ( . _ . ) ! 
//CHECK overflow,vector_size,what to output?

Measured memory_bytes: 1792
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <deque>
#include <iostream>
#include <numeric>
#include <queue>
#include <string>
#include <utility>
#include <vector>
 
using namespace std;
#define ALL(a) (a).begin(), (a).end()
#define REP(i, n) for (long i = 0; i < (n); i++)
#define nvec(T, v, n) vector<T> v(n); REP(i, n) {cin>>(v)[i];}
#define npairs(T1, T2, v, n) vector<pair<T1, T2>> v(n); REP(i, n){cin>>v[i].first>>v[i].second;}
#define ntuples(T1, T2, T3, v, n) vector<tuple<T1, T2, T3>> v(n); REP(i, n){cin>>get<0>(v[i])>>get<1>(v[i])>>get<2>(v[i]);}
#define vec2d(T, v, m, n) vector<vector<T>> (v)(m, vector<T>(n))
#define nvec2d(T, v, m, n) vec2d(T, v, m, n); REP(j, m){REP(i, n) {cin>>(v[j])[i];}}
 
#define min_index(v) size_t( min_element(all(v)) - (v).begin() )
#define max_index(v) size_t( max_element(all(v)) - (v).begin() )
#define min_e(v) *min_element(ALL(v))
#define max_e(v) *max_element(ALL(v))
 
#define count_le(v, a) size_t( upper_bound(ALL(v), a) - (v).begin() )
#define count_lt(v, a) size_t( lower_bound(ALL(v), a) - (v).begin() )
#define count_ge(v, a) size_t( (v).end() - lower_bound(ALL(v), a) )
#define count_gt(v, a) size_t( (v).end() - upper_bound(ALL(v), a) )
 
#define order(neq_sl) [](const auto s, const auto l){return neq_sl;}
#define make_lr(v,type,l,r) vector<type> l(n+1),r(n+1);FOR(i,n){l[i+1]=l[i]+v[i];r[i+1]=r[i]+v[n-1-i];}
 
#define acm accumulate
#define SUM(v) accumulate(ALL(v), 0l)
#define SORT(v) sort(ALL(v))
 
#define GCD(v) gcd(ALL(v), 0l)
 
/*template <typename T>
T gcd(T a, T b) {
    if (a > b) swap(a, b);
    if (a == 0) return b;
    return gcd(b%a, a);
}
template <typename InputItr, typename T>
T gcd(InputItr first, InputItr last, T init) {
    for (; first != last; ++first) init = gcd(init, *first);
    return init;
}*/
 
template <typename T>
using vec =vector<T>;
 
template <typename T>
using vvec =vector<vector<T>>;
 
int main(){
  long n,m,k;
  cin>>n>>m>>k;
  nvec(long,a,n);
  nvec(long,b,m);
  for (int i = 1; i < n; i++) {
    a[i]+=a[i-1];
  }
  for (int i = 1; i < m; i++) {
    b[i]+=b[i-1];
  }
  long c=0;
  for (int i = 0; i < n; i++) {
    if(a[i]>k)break;
//    cout<<a[i]<<" "<<count_le(b, k-a[i])<<endl;
    c = max(c,(long)count_le(b, k-a[i])+i+1);
//    cout<<c<<endl;
  }
//  cout<<count_le(b, 1000000000);
  cout<<max(c,(long)count_le(b, k));
}
 
 
/* きょむ〜 */

Measured memory_bytes: 6416
#include<cstdio>
#include<iostream>
#include<algorithm>
struct card{
    char suit;
    int num;
    bool operator<(const card &c) const{ return num<c.num; }
    bool operator>(const card &c) const{ return c<*this; }
    bool operator<=(const card &c) const{ return !(*this>c); }
    bool operator>=(const card &c) const{ return !(*this<c); }
    bool operator==(const card &c) const{ return (suit==c.suit && num==c.num); }
    bool operator!=(const card &c) const{ return !(*this==c); }
};
template<typename T>
int partition(T *a,int p,int r){
    T x=a[r];
    int i=p-1;
    for(int j=p;j<r;j++){
        if(a[j]<=x){
            i++;
            T tmp=a[i]; a[i]=a[j]; a[j]=tmp;
        }
    }
    T tmp=a[i+1]; a[i+1]=a[r]; a[r]=tmp;
    return i+1;
}
template<typename T>
void quicksort(T *a,int p,int r){
    if(p<r){
        int q=partition(a,p,r);
        quicksort(a,p,q-1);
        quicksort(a,q+1,r);
    }
}
card a[100000],b[100000];
int main(){
    int n;
    scanf("%d",&n);
    for(int i=0;i<n;i++){
        char c;
        int ai;
        std::cin >> c >> ai;
        a[i]={c,ai};
        b[i]={c,ai};
    }
    quicksort(a,0,n-1);
    std::stable_sort(b,b+n);
    int isstable=true;
    for(int i=0;i<n;i++){
        if(a[i]!=b[i])isstable=false;
    }
    printf("%s\n",isstable?"Stable":"Not stable");
    for(int i=0;i<n;i++){
        printf("%c %d\n",a[i].suit,a[i].num);
    }
    return 0;
}


Measured memory_bytes: 4768
n,q=map(int,input().split())
s=input()
ruiseki = [0]*n

for i in range(1,n):
    if s[i-1]=="A" and s[i] == "C":
        ruiseki[i] += 1
    ruiseki[i] += ruiseki[i-1]
    
for _ in range(q):
    l,r=map(int,input().split())
    print(ruiseki[r-1]-ruiseki[l-1])

Measured memory_bytes: 7668