akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <numeric>
#include <string>
#include <vector>
#include <algorithm>
#include <sstream>
#include <iterator>
#include <math.h>
#include <cmath>
#include <set>   
#include <bitset>
//#include <boost/math/common_factor_rt.hpp>

#define ll long long
using namespace std;
ll L = 1000000007;

#define MAX 100000

int N;
int A[MAX];

int main()
{
	int a, b, c, d, e, f;
	double ans = 0;
	int answa, anssu;
	cin >> a >> b >> c >> d >> e >> f;
	for (int i = 0; i*a * 100 <= f; i++) {
		for (int j = 0; j*b * 100 <= f - 100 * a*i; j++) {
			if (i == 0 && j == 0)continue;
			int wa = i * a * 100 + j * b * 100;
			for (int k = 0; k*c + wa <= f; k++) {
				for (int kk = 0; kk*d + wa + k * c <= f; kk++) {
					if (k*c + kk * d>wa*e / 100)continue;
					double no = 100 * (double)(k*c + kk * d) / (double)wa;
					if (no >= ans) {
						answa = wa + kk * d + k * c;
						anssu = kk * d + k * c;
						ans = no;
					}
				}
			}
		}
	}
	cout << answa << " " << anssu << endl;
}

int dsum(ll a) {
	int ans = 0;
	while (a != 0) {
		ans += a % 10;
		a /= 10;
	}
	return ans;
}


Measured memory_bytes: 888
#include<iostream>
#include<cstdio>
#include<vector>
#include<queue>
using namespace std; 
priority_queue <int, vector<int>, greater<int> > que;
int ans = -0x7fffffff;
int n; 
int main(){
	scanf("%d", &n);
	int x;
	scanf("%d", &x);
	que.push(x);
	for(int i = 1; i < n; i++){
		scanf("%d", &x);
		int y = x - que.top();
		ans = max(y, ans);
		que.push(x);
	} 
	printf("%d\n", ans);
	return 0;
}


Measured memory_bytes: 3880
#include <iostream>
#include <algorithm>
#include <vector>
using namespace std;
int main(){
  int n;cin>>n;
  vector<int> a;
  int sm = 0;
  for(int i = 0; n > i; i++){
    int tmp;cin>>tmp;
    a.push_back(tmp);
    sm += tmp;
  }
  int ret = 100000000;
  int nw = 0;
  for(int i = 0; n > i; i++){
    nw += a[i];
    ret = min(ret, abs((sm-nw)-nw));
  }
  cout << ret << endl;
}
    

Measured memory_bytes: 384
#include <bits/stdc++.h>
using namespace std;
int main()
  {int N; cin >> N;
  vector<vector<pair<int, int>>> g(N);
  for (int i = 0; i < N - 1; ++i) {int a, b; cin >> a >> b; g[--a].push_back({--b, i}); g[b].push_back({a, i});}
  int m = 0;
  vector<int> cs(N), ans(N - 1); cs[0] = -1;
  queue<int> q; q.push(0);
  while (q.size())
    {auto v = q.front(); q.pop();
    int c = 0;
    for (auto [u, e] : g[v])
      {if (cs[u]) continue;
      q.push(u);
      ++c; if (c == cs[v]) ++c;
      ans[e] = c; cs[u] = c; m = max(m, c);}}
  cout << m << endl;
  for (auto c : ans) cout << c << endl;}

Measured memory_bytes: 10036
#include<bits/stdc++.h>
using namespace std;
#define lli long long int
# define rep(i,n) for(int i=0;i<n;i++)
void solve(){
    lli n,x,t;
    cin>>n>>x>>t;
    lli y = (t*n)/x;
    if(y%t==0)
        cout<<y<<endl;
    else{
        y +=t;
        cout<<y - y%t<<endl;
    }   
}
int main()
{
    int t;
   // cin>>t;
    t=1;
    while(t--){
        solve();
    }
}

Measured memory_bytes: 3516
#include "bits/stdc++.h"
#pragma comment (linker, "/STACK:526000000")
#define  _CRT_SECURE_NO_WARNINGS

using namespace std;
typedef string::const_iterator State;
#define eps 1e-11L
#define MAX_MOD 1000000007LL
#define GYAKU 500000004LL

#define MOD 998244353LL
#define seg_size 262144*2LL
#define pb push_back
#define mp make_pair
typedef long long ll;
#define REP(a,b) for(long long (a) = 0;(a) < (b);++(a))
#define ALL(x) (x).begin(),(x).end()

void init() {
	iostream::sync_with_stdio(false);
	cout << fixed << setprecision(20);
}


#define int ll
void solve(){
	string s;
	cin >> s;
	ll ans[2] = { 0,(long long)1e9 };
	while (s.empty() == false) {
		ll next_ans[2] = { (long long)1e9,(long long)1e9 };
		REP(q, 2) {
			int now_target = s.back() - '0';
			now_target += q;
			if (now_target == 10) {
				next_ans[1] = min(next_ans[1], ans[q]);
				continue;
			}
			next_ans[0] = min(next_ans[0], ans[q] + now_target);
			next_ans[1] = min(next_ans[1], ans[q] + (10 - now_target));
		}
		REP(q, 2) {
			ans[q] = next_ans[q];
		}
		s.pop_back();
	}
	cout << min(ans[0], ans[1] + 1) << endl;
}
#undef int
int main() {
	init();
	solve();
}

Measured memory_bytes: 1948
#include<stdio.h>
#include<iostream>
#include <iomanip>
#include<vector>

using namespace std;

int main(){
  int k,n;
  cin>>k>>n;
  vector<int> a(n);
  for(int i=0;i<n;i++){
    cin>>a[i];
  }

  int max=0;
  for(int i=0;i<n-1;i++){
    if(max<a[i+1]-a[i]){
      max=a[i+1]-a[i];
    }
    //cout<<max<<endl;
  }
  if(max<a[0]+k-a[n-1])
    max=a[0]+k-a[n-1];
  
  
  cout<<k-max;
  return 0;
}

Measured memory_bytes: 1024
#!/usr/bin/env python3
import sys


def solve(S: str, T: str, A: int, B: int, U: str):
    if U == S:
        A-=1
    else:
        B-=1
    return A, B


def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    S = next(tokens)  # type: str
    T = next(tokens)  # type: str
    A = int(next(tokens))  # type: int
    B = int(next(tokens))  # type: int
    U = next(tokens)  # type: str
    s, t = solve(S, T, A, B, U)
    print(s, t)

if __name__ == '__main__':
    main()


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

typedef long long ll;

ll d,t,s;

int main() {
	scanf("%lld%lld%lld",&d,&t,&s );
	if (d <= t * s) printf("Yes");
	else printf("No");

	return 0;
}

Measured memory_bytes: 2152
# ALDS1_3_C: Doubly Linked List

class DoublyLinkedList
  include Enumerable

  def initialize
    @head = Node.new
    @head.next = @head.prev = @head
  end

  def insert(key)
    node = Node.new key
    @head.append node
    node
  end

  def delete(key)
    node = search_node key
    delete_node node
  end

  def deleteFirst
    delete_node @head.next
  end

  def deleteLast
    delete_node @head.prev
  end

  def each
    node = @head.next
    while node != @head
      yield node
      node = node.next
    end
  end

  def to_s
    inject('') do |s, node|
      s << ' ' << node.key.to_s
    end.strip
  end

  private
    def delete_node(node)
      node.disappear unless node.nil?
    end

    def search_node(key)
      find do |node|
        node.key == key && node != @head
      end
    end

    class Node
      attr_accessor :key, :next, :prev

      def initialize(key = nil)
        @key  = key
        @next = @prev = nil
      end

      def append(another)
        another.next   = self.next
        self.next.prev = another
        self.next      = another
        another.prev   = self
      end

      def disappear
        self.prev.next = self.next
        self.next.prev = self.prev
        self
      end
    end
end

list = DoublyLinkedList.new
n_commands = gets.to_i

n_commands.times do
  input   = gets.chomp.split
  command = input.first
  args    = input.drop(1)
  list.send command, *args
end

puts list

Measured memory_bytes: 146264
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(int)(n);i++)
using namespace std;
int main(){
  int N,K;
  cin >> N >> K;
  int A[N];
  rep(i,N){
    int x;
    cin >> x;
    A[i] = x;
  }
  int dist=0;
  rep(i,N){
    dist += min(A[i],K-A[i]);
  }
  cout << dist * 2 << endl;
}


Measured memory_bytes: 256
fn read<T: std::str::FromStr>() -> T {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).ok();
    s.trim().parse().ok().unwrap()
}

fn read_vec<T: std::str::FromStr>() -> Vec<T> {
    read::<String>().split_whitespace()
        .map(|e| e.parse().ok().unwrap()).collect()
}

fn main() {
    let v: Vec<usize> = read_vec();
    let (n, k) = (v[0], v[1]);
    let a = read_vec::<usize>();
    let min_a = *a.iter().min().unwrap();

    let mut win = vec![false; k + 1];
    for i in 1..k + 1 {
        for num in a.iter() {
            if i >= *num {
                win[i] |= !win[i - num];
            }
        }
    }

    if win[k] {
        println!("First");
    } else {
        println!("Second");
    }
}


Measured memory_bytes: 4352
#ifdef DEBUG

#else

#    pragma GCC optimize("O3,no-stack-protector")
#    pragma GCC optimize("unroll-loops")

#    if __cplusplus >= 201703L
#        pragma GCC target("avx2")
#    else
#        pragma GCC target("avx")
#    endif

#endif
// 実数の場合
// #pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")

#define _USE_MATH_DEFINES
#include <bits/stdc++.h>
#define dump(x) cout << x << endl
typedef int64_t Int;
typedef long double Ld;

using namespace std;
using Graph = vector<vector<Int>>;

const double pi = M_PI;
const Int MOD = 1000000007;

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

    Int n;
    cin >> n;
    vector<Int> a(n);
    Int m = 0;
    for (Int i = 0; i < n; i++) {
        cin >> a[i];
        m = max(m, a[i]);
    }

    Int count = 0, index = 0, mm = 0;
    for (Int i = 0; i < n; i++) {
        if (a[i] == m) {
            count++;
            index = i;
        } else {
            mm = max(mm, a[i]);
        }
    }

    if (count == 1) {
        for (Int i = 0; i < n; i++) {
            if (i != index) {
                cout << m << endl;
            } else {
                cout << mm << endl;
            }
        }
    } else {
        for (Int i = 0; i < n; i++) {
            cout << m << endl;
        }
    }

    return 0;
}


Measured memory_bytes: 3200
using System;
using System.Collections.Generic;

class Program {
    static int Main(string[] args) {
        List<int[]> list = new List<int[]>();

        while (true) {
            string v = Console.ReadLine();

            int H = int.Parse(v.Split(' ')[0]);
            int W = int.Parse(v.Split(' ')[1]);
            if ((H == 0) && (W == 0)) { break; }

            list.Add(new int[] { H, W });
        }

        for (int i = 0; i < list.Count; i++) {
            for (int h = 0; h < list[i][0]; h++) {
                for (int w = 0; w < list[i][1]; w++) {
                    if ((h == 0) || (h == list[i][0] - 1) || (w == 0) || (w == list[i][1] - 1)) {
                        Console.Write("#");
                    }
                    else {
                        Console.Write(".");
                    }
                }
                Console.WriteLine("");
            }

            Console.WriteLine("");
        }

        return 0;
    }
}

Measured memory_bytes: 8928
import sys
input = sys.stdin.readline


def main():
    N = input().strip()
    ans = 0
    for i in range(0, len(N)-1, 2):
        ans += 9 * 10**i

    if len(N) % 2 == 1:
        ans += int(N) - 10**(len(N)-1) + 1

    print(ans)


if __name__ == "__main__":
    main()


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

string XOR(string& s1, string& s2) {
    int n = s1.size();
    string s3(n, '0');
    for (int i = 0; i < n; i++) {
        if ((s1[i] == '0' && s2[i] == '1') || (s1[i] == '1' && s2[i] == '0')) {
            s3[i] = '1';
        }
    }
    return s3;
}
int to_int(string& s) {
    int ret = 0;
    for (int i = 0; i < s.size(); i++) {
        ret += (s[i] == '1') * (1 << i);
    }
    return ret;
}
int solve1(int n, int m, vector<string>& t) {
    vector<bitset<500>> a(n);
    for (int i = 0; i < n; i++) a[i] = bitset<500>(t[i]);
    const bitset<500> ZERO(0);
    int ans = 0;
    for (int S = 0; S < 1 << n; S++) {
        bitset<500> acc = ZERO;
        for (int i = 0; i < n; i++) {
            if (S >> i & 1) {
                acc ^= a[i];
            }
        }
        if (acc == ZERO) ans = max(ans, __builtin_popcount(S));
    }
    return ans;
}
int solve2(int n, int m, vector<string>& t) {
    vector<vector<int>> dp(n + 1, vector<int>(1 << m, -1e8));
    dp[0][0] = 0;
    vector<int> a(n);
    for (int i = 0; i < n; i++) {
        int x = to_int(t[i]);
        for (int S = 0; S < 1 << m; S++) {
            dp[i + 1][S] = max(dp[i + 1][S], dp[i][S]);
            int nxt = S ^ x;
            dp[i + 1][nxt] = max(dp[i + 1][nxt], dp[i][S] + 1);
        }
    }
    // for (int i = 0; i < n + 1; i ++) {
    //     for (int S = 0; S < 1 << m; S++) {
    //         cout << dp[i][S] << " ";
    //     }
    //     cout << endl;
    // }
    return dp[n][0];
}
void solve() {
    int n, m; cin >> n >> m;
    if (n == 0) exit(0);
    vector<string> t(n);
    for (int i = 0; i < n; i++) cin >> t[i];
    // assert(solve1(n, m, t) == solve2(n, m, t));
    if (n <= 22) {
        cout << solve1(n, m, t) << endl;
    } else {
        cout << solve2(n, m, t) << endl;
    }
}
int main() {
    // freopen("input", "r", stdin);
    while (1) solve();
}


Measured memory_bytes: 208336
n=int(input())
A=[[2]*n for i in range(n)]
for i in range(n):
  a=int(input())
  for j in range(a):
    x,y=map(int,input().split())
    A[i][x-1]=y
ans=0
for i in range(2**n):
  aa=0
  s=format(i,'18b')
  H=[]
  for j in range(n):
    if s[-1-j]=="1":
      H.append(j)
      aa=aa+1
  h=set(H)
  f=0
  for j in range(len(H)):
    for k in range(n):
      if A[H[j]][k]==2:
        continue
      if A[H[j]][k]==1:
        if k not in h:
          f=1
      else:
        if k in h:
          f=1
  if f==0:
    if aa>ans:
      ans=aa
print(ans)

Measured memory_bytes: 45404
#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[i];
  }
  vector<int> b(n);
  b = a;
  sort(a.begin(), a.end());
  for (int i = 0; i < n; i++) {
    if (a[n-1] == a[n-2]) {
      cout << a[n-1] << endl;
    }
    else {
      if (b[i] == a[n-1]) {
        cout << a[n-2] << endl;
      }
      else {
        cout << a[n-1] << endl;
      }
    }
  }
}

Measured memory_bytes: 4844
#include<iostream>
#include<algorithm>
#include<vector>
#include<functional>
#include<numeric>

using namespace std;


int main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	long long n, a, b;
	cin >> n >> a >> b;
	vector<long long> h(n);
	for (auto& e : h)cin >> e;
	long long ub = INT32_MAX;
	long long lb = 0;
	while (ub - lb > 1) {
		long long mid = (ub + lb) / 2;
		long long tmp = mid;
		for (auto e : h) {
			tmp -= (max(0LL, (e - b * mid)) + (a - b - 1)) / (a - b);
		}
		if (tmp >= 0) { ub = mid; }
		else { lb = mid; }
	}
	cout << ub << endl;
	return 0;
}

Measured memory_bytes: 1024
#include<bits/stdc++.h>
using namespace std;
#define ran 111111
int n,pos1,pos2;
int a[ran],f[ran];

#define mod 1000000007
int add(int x,int y){
	return (x+=y)<mod?x:x-mod;
}
int sub(int x,int y){
	return add(x,mod-y);
}
int mul(int x,int y){
	return (int)((long long int)x*y%mod);
}
int pw(int x,int y){
	int r=1;
	while(1){
		if(y&1)r=mul(r,x);
		if(y>>=1)x=mul(x,x);else
			break;
	}
	return r;
}
int fac[ran],ifac[ran];
int c(int x,int y){
	if(x<y)return 0;
	return mul(fac[x], mul(ifac[y],ifac[x-y]));
}

int main(){
	scanf("%d",&n);
	fac[0] = ifac[0] = 1;
	for(int i=1; i<=n; i++){
		fac[i] = mul(fac[i-1],i);
		ifac[i] = pw(fac[i], mod-2);
	}

	for(int i=1; i<=n+1; i++){
		scanf("%d",&a[i]);
		if(f[a[i]] == 0)
			f[a[i]] = i;
		else{
			pos1 = f[a[i]];
			pos2 = i;
		}
	}
	for(int k=1; k<=n+1; k++){
		int res = 0;
		if(k <= n-1)
			res = add(res, c(n-1, k));
		if(k >= 2)
			res = add(res, c(n-1, k-2));
		res = add(res, mul(2, c(n-1, k-1)));
		res = sub(res, c(n-1 - (pos2-pos1-1), k-1));
		printf("%d\n",res);
	}
	return 0;
}


Measured memory_bytes: 2816
#include <stdio.h>
#include <math.h>

double nibutan1(double a, double b, double x);
double nibutan2(double a, double b, double x);

int main(void)
{
    double a, b, x;

    double theta;//角度
    double ans;

    scanf("%lf %lf %lf",&a, &b, &x);

    //場合分けする（図１の時）

    
    theta = nibutan1(a, b, x);
    if(a >= b*tan(M_PI/2-theta)){
        printf("%.10f",theta*180/M_PI);
        return 0;
    }
        //引き算する方（図２）
    theta = nibutan2(a, b, x);
    printf("%.10f",theta*180/M_PI);
    return 0;
}




double nibutan1(double a, double b, double x)
{
    double small = 0;
    double big = M_PI;
    double half = M_PI/2;

    for(int i=0; i<1000000; i++){
        if(fabs(x - (a*b*b*tan(M_PI/2-half))/2) < 0.00000001){
            return half;
        } else if(x < (a*b*b*tan(M_PI/2-half))/2){
            small = half;
        } else {
            big = half;
        }
        half = (big + small)/2;
    }

    return half;

}


double nibutan2(double a, double b, double x)
{
    double small = 0;
    double big = M_PI;
    double half = M_PI/2;

    long double volume = a*a*b;

    for(int i=0; i<1000000; i++){
        if(fabs(x - volume + (a*a*a*tan(half))/2) < 0.00000001){
            return half;
        } else if(x < volume - (a*a*a*tan(half))/2){
            small = half;
        } else {
            big = half;
        }
        half = (big + small)/2;
    }

    return half;

}

Measured memory_bytes: 2632
#include<iomanip>
#include<limits>
#include<thread>
#include<utility>
#include<iostream>
#include<string>
#include<algorithm>
#include<set>
#include<map>
#include<vector>
#include<stack>
#include<queue>
#include<cmath>
#include<numeric>
#include<cassert>
#include<random>
#include<chrono>
#include<unordered_set>
#include<unordered_map>
#include<fstream>
#include<list>
#include<functional>
#include<bitset>
#include<complex>
#include<tuple>
using namespace std;
typedef unsigned long long ull;
typedef long long ll;
typedef unsigned long long int ulli;
typedef long long int lli;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef long double D;
typedef complex<D> P;
const ll E=1e18+7;
const ll MOD=1000000007;
#define IOS cin.tie(0); ios::sync_with_stdio(0);
#define REP(i,a,b) for(int i=a;i<b;i++)
#define rep(i,n) REP(i,0,n)
#define all(x) (x).begin(),(x).end()
#define sz(x) ((int)(x).size())
#define fill(x,y) memset(x,y,sizeof(x))
#define pcnt __builtin_popcount
#define buli(x) __builtin_popcountll(x)
#define pb push_back
#define mp make_pair
#define F first
#define S second
template<class... A> void prints()      { cout << endl; }
template<class... A> void prints_rest() { cout << endl; }
template<class T, class... A> void prints_rest(const T& first, const A&... rest) { cout << " " << first; prints_rest(rest...); }
template<class T, class... A> void prints(const T& first, const A&... rest)      { cout << first; prints_rest(rest...); }

template<class T> T gcd(T a, T b) { return b ? gcd(b, a % b) : a; }
template<class T> T lcm(T a, T b) { return a / gcd(a, b) * b; }
int main() {
    int W,H,x,y; cin >> W >> H >> x >> y;

    int multi_ans = 0;
    if (W == x*2 && H == y*2) {multi_ans = 1;}

    double area = double(W) * double(H) / 2;
    printf("%.12lf %lld\n", area, multi_ans);
}


Measured memory_bytes: 256
package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
)

func main() {
	sc := NewScanner()
	A := []byte(sc.NextLine())
	s := 0

	for i := len(A) - 1; i >= 0; i-- {
		s += int(A[i] - '0')
	}
	pref := int(A[0] - 1 - '0')
	pref += 9 * (len(A) - 1)
	fmt.Println(max(s, pref))

}

func max(a int, b int) int {
	if a < b {
		return b
	}
	return a
}

type Scanner struct {
	r   *bufio.Reader
	buf []byte
	p   int
}

func NewScanner() *Scanner {
	rdr := bufio.NewReaderSize(os.Stdin, 1000)
	return &Scanner{r: rdr}
}
func (s *Scanner) Next() string {
	s.pre()
	start := s.p
	for ; s.p < len(s.buf); s.p++ {
		if s.buf[s.p] == ' ' {
			break
		}
	}
	result := string(s.buf[start:s.p])
	s.p++
	return result
}
func (s *Scanner) NextLine() string {
	s.pre()
	start := s.p
	s.p = len(s.buf)
	return string(s.buf[start:])
}
func (s *Scanner) NextInt() int {
	v, _ := strconv.Atoi(s.Next())
	return v
}
func (s *Scanner) NextInt64() int64 {
	v, _ := strconv.ParseInt(s.Next(), 10, 64)
	return v
}

func (s *Scanner) NextIntArray() []int {
	s.pre()
	start := s.p
	result := []int{}
	for ; s.p < len(s.buf)+1; s.p++ {
		if s.p == len(s.buf) || s.buf[s.p] == ' ' {
			v, _ := strconv.ParseInt(string(s.buf[start:s.p]), 10, 0)
			result = append(result, int(v))
			start = s.p + 1
		}
	}

	return result
}
func (s *Scanner) NextInt64Array() []int64 {
	s.pre()
	start := s.p
	result := []int64{}
	for ; s.p < len(s.buf)+1; s.p++ {
		if s.p == len(s.buf) || s.buf[s.p] == ' ' {
			v, _ := strconv.ParseInt(string(s.buf[start:s.p]), 10, 64)
			result = append(result, v)
			start = s.p + 1
		}
	}
	return result
}

func (s *Scanner) NextMap() map[int]bool {
	s.pre()
	start := s.p
	mp := map[int]bool{}
	for ; s.p < len(s.buf); s.p++ {
		if s.buf[s.p] == ' ' {
			v, _ := strconv.Atoi(string(s.buf[start:s.p]))
			mp[v] = true
			start = s.p + 1
		}
	}
	v, _ := strconv.Atoi(string(s.buf[start:s.p]))
	mp[v] = true

	return mp
}

func (s *Scanner) pre() {
	if s.p >= len(s.buf) {
		s.readLine()
		s.p = 0
	}
}
func (s *Scanner) readLine() {
	s.buf = make([]byte, 0)
	for {
		l, p, e := s.r.ReadLine()
		if e != nil {
			panic(e)
		}
		s.buf = append(s.buf, l...)
		if !p {
			break
		}
	}
}


Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<int, int>;
using vint = vector<int>;
using vvint = vector<vint>;
using vll = vector<ll>;
using vvll = vector<vll>;
using vchar = vector<char>;
using vvchar = vector<vchar>;
using vp = vector<P>;
using vpp = vector<pair<P, P>>;
using vvp = vector<vp>;

#define rep(i, n) for (int i = 0; i < n; ++i)
#pragma region Debug
istream &operator>>(istream &is, P &a)
{
    return is >> a.first >> a.second;
}
ostream &operator<<(ostream &os, const P &a) { return os << "(" << a.first << "," << a.second << ")"; }

template <typename T>
void view(const std::vector<T> &v)
{
    for (const auto &e : v)
    {
        std::cout << e << " ";
    }
    std::cout << std::endl;
}
template <typename T>
void view(const std::vector<std::vector<T>> &vv)
{
    for (const auto &v : vv)
    {
        view(v);
    }
}
#pragma endregion

// intervals, and number n
//  2 3 4  5  6
// 1 3 6 10 15 21

// n == 6
// 1,2,3
// 1,4,5
// 2,4,6
// 3,5,6

// n == 10
// 1,2,3,4
// 1,5,6,7
// 2,5,8,9
// 3,6,8,10
// 4,7,9,10

// n == 15
//  1, 2, 3, 4, 5
//  1, 6, 7, 8, 9
//  2, 6,10,11,12
//  3, 7,10,13,14
//  4, 8,11,13,15
//  5, 9,12,14,15

// n == 21
//  1, 2, 3, 4, 5, 6
//  1, 7, 8, 9,10,11
//  2, 7,12,13,14,15
//  3, 8,12,16,17,18
//  4, 9,13,16,19,20
//  5,10,14,17,19,21
//  6,11,15,18,20,21

int main()
{
    int n;
    cin >> n;
    int a = 1;
    int k = 1;
    while (k < n)
    {
        a++;
        k = a * (a + 1) / 2;
    }
    if (k != n)
    {
        cout << "No" << endl;
        return 0;
    }
    cout << "Yes" << endl;

    // number of sets = a+1;
    cout << a + 1 << endl;

    vint cache;
    int back = 1;
    rep(i, a + 1)
    {
        // size of set == a
        cout << a << " ";
        for (int j = 0; j < cache.size(); j++)
        {
            int c = cache[j];
            cout << c << " ";
            cache[j]++;
        }
        cache.emplace_back(back);
        for (int j = cache.size() - 1; j < a; j++)
        {
            cout << back << " ";
            back++;
        }
        cout << endl;
    }

    return 0;
}

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

int main() {
  int N;
  scanf("%d", &N);
  string S;
  cin >> S;

  int ans = 0;
  for (int i = 0; i < N - 1; i++) {
    if (S.at(i) != S.at(i + 1)) ans++;
  }

  printf("%d", ans + 1);
  return 0;
}


Measured memory_bytes: 512
import math



def nCast(number):
    if type(number)==str:
        return int(number)
    for idx in range(0,len(number)):
        if type(number[idx])==str:

            number[idx]=int(number[idx])
        else:
            nCast(number[idx])
    return number
    
def inputArr(w):
    l=list()
    for idx in range(0,w):
        l.append(input().split())
    return l

a=nCast(input().split())
if a[2]>a[0]+a[1]:
    a[2]=a[0]+a[1]+1

print(a[1]+a[2])







    

Measured memory_bytes: 3064
N,C = map(int,input().split())
x = [0] * N
v = [0] * N
for i in range(N):
	x[i],v[i] = map(int,input().split())

d = [0] * N
dd = [0] * N
dmax = [0] * N
ddmax = [0] * N

d[0] = v[0] - x[0]
dmax[0] = d[0]
for i in range(1,N):
	d[i] = d[i - 1] + v[i] - x[i] + x[i-1]
	dmax[i] = max(dmax[i-1], d[i])

dd[0] = v[N-1] - (C - x[N-1])
ddmax[0] = dd[0]
for i in range(1,N):
	dd[i] = v[N-1-i] + dd[i-1] - (C - x[N-1-i]) + (C - x[N-i])
	ddmax[i] = max(ddmax[i-1], dd[i])

ans = 0
for i in range(N):
	ans = max(ans, d[i])
	ans = max(ans,dd[i]);

for i in range(N-1):
	ans = max(ans, ddmax[N-i-2] - x[i] + d[i])
	ans = max(ans, dd[i] - C + x[N-1-i] + dmax[N-i-2])

print(ans)

Measured memory_bytes: 22012
#include <stdio.h>
int main(){
int n,m;
while(1){
scanf("%d%d",&n,&m);
if(n==0)return 0;
for(int i=0;i<m;i++){
printf("#");
}
printf("\n");
for(int i=2;i<n;i++){
printf("#");
for(int j=2;j<m;j++){
printf(".");
}
printf("#\n");
}
for(int i=0;i<m;i++){
printf("#");
}
printf("\n\n");
}
}


Measured memory_bytes: 2088
N = int(input())
XYH = [list(map(int,input().split())) for i in range(N)]
XYH.sort(key = lambda x:x[2], reverse = 1)
mx,my,mh = XYH[0]
for Cx in range(101):
    for Cy in range(101):
        H = mh+abs(mx-Cx)+abs(my-Cy)
        if all(h == max(H-abs(X-Cx)-abs(Y-Cy),0) for X,Y,h in XYH):
            print(Cx,Cy,H)
            break

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

const int MOD = 1e9 + 7;

int main() {
	long long ans = 1;
	int n; cin >> n;
	for (int i = n; i > 1; i--) {
		ans *= i; ans %= MOD;
	}
	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
#include<math.h>
#define MM	100000000.0
int main(void)
{
	int n,i,j,k;
	double x[100],y[100],z[100],r[100];
	double a[100][100],rr;
	int flg[100],mink;
	double leng,min;
	
	while(1)	{
		scanf("%d",&n);
		if(n==0)	break;
		for(i=0;i<n;i++)	{
			scanf("%lf %lf %lf %lf",&x[i],&y[i],&z[i],&r[i]);
		}
		for(i=0;i<n;i++)	{
			for(j=0;j<n;j++)	{
				rr=sqrt((x[i]-x[j])*(x[i]-x[j])+(y[i]-y[j])*(y[i]-y[j])+(z[i]-z[j])*(z[i]-z[j]));
				rr=rr-r[i]-r[j];
				if(rr<0)	rr=0.0;
				a[i][j]=rr;
			}
			flg[i]=0;
		}
		
		leng=0.0;
		flg[0]=1;
		for(i=0;i<n-1;i++)	{
			min=MM;
			for(j=0;j<n;j++)	{
				if(flg[j]==1)	{
					for(k=0;k<n;k++)	{
						if(flg[k]==0 && min>a[j][k])	{
							min=a[j][k];
							mink=k;
						}
					}
				}
			}
			flg[mink]=1;
//			printf("min=%lf mink=%d\n",min,mink);
			leng+=min;
		}
		printf("%.3lf\n",leng);
	}
	return 0;
}


Measured memory_bytes: 744
num = int(input())

def to_negative_base(n, neg_base):
    if n == 0:
        return 0

    converted = ""
    while n != 0:
        # remainder = (n % neg_base)
        remainder = n - neg_base * (n // neg_base)
        
        n = n // neg_base

        if remainder < 0:
            remainder += (-neg_base)
            n += 1

        converted = str(remainder) + str(converted)

    return converted

print(to_negative_base(num, -2))

Measured memory_bytes: 3060
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#define MAX_N (100010)
#define INF (1e9 + 10)
typedef struct {
    char suit;
    int num;
} Card;


void quickSort( Card C[], int left, int right );
int partition( Card C[], int left, int right );
void swap( Card C[], int i, int j );

void mergeSort( Card A[], int left, int right );
void merge( Card A[], int left, int mid, int right );



int main()
{
    int n;
    Card C[MAX_N];
    Card C1[MAX_N];
    bool isStable = true;

    scanf("%d", &n);

    for ( int i = 0; i < n; i++ ) {
	scanf(" %c %d", &C[i].suit, &C[i].num);
	C1[i] = C[i];
    }
    
    quickSort( C,  0, n-1 );
    mergeSort( C1, 0, n );
    
    for ( int i = 0; i < n; i++ ) {
	if ( C1[i].suit != C[i].suit ) {
	    isStable = false;
	}
    }
    if ( isStable ) {
	printf("Stable\n");
    }
    else {
	printf("Not stable\n");
    }


    for ( int i = 0; i < n; i++ ) {
	printf("%c %d\n", C[i].suit, C[i].num);
    }


    return 0;
}


void quickSort( Card C[], int left, int right )
{
    if ( right > left ) {
	int part = partition( C, left, right );
	quickSort( C, left, part - 1 );
	quickSort( C, part + 1, right );	
    }
}


int partition( Card C[], int left, int right )
{
    int x = C[right].num;

    int i = left - 1;
    for ( int j = left; j < right; j++ ) {
	if ( C[j].num <= x ) {
	    i++;
	    swap( C, i, j );
	}
    }

    i++;
    swap( C, i, right );
    
    return i;
}


void swap( Card C[], int i, int j )
{
    Card tmp = C[i];
    C[i] = C[j];
    C[j] = tmp;
}




void mergeSort( Card C[], int left, int right )
{
    if ( left + 1 < right ) {	// ????´????2??\???????????´???
	int mid = ( left + right ) >> 1;
	mergeSort( C, left, mid );
	mergeSort( C, mid, right );	
	merge( C, left, mid, right );
    }
    
    return;
}




void merge( Card C[], int left, int mid, int right )
{
    int num_left  = mid - left;
    int num_right = right - mid;
    Card *L = (Card *)malloc( (1 + num_left)  * sizeof(Card) );
    Card *R = (Card *)malloc( (1 + num_right) * sizeof(Card) );
    int i_left = 0;
    int i_right = 0;

    memcpy(L, &C[left], sizeof(Card) * num_left);
    memcpy(R, &C[mid],  sizeof(Card) * num_right);
    L[num_left].num = R[num_right].num = INF;

    for ( int k = left; k < right; k++ ) {
	if ( L[i_left].num <= R[i_right].num ) {
	    C[k] = L[i_left];
	    i_left++;
	}
	else {
	    C[k] = R[i_right];
	    i_right++;
	}
    }
    
    free(L);
    free(R);

    return;
}

Measured memory_bytes: 3208
#include<bits/stdc++.h>
using namespace std;
typedef long long ll ;
int main(){

ll a, b ,c ; cin>>a>>b>>c;
ll ans = 0;
if( ((a+b+c ) == 3*a) && (a%2)) {cout <<ans<<endl; return 0;}
else if(((a+b+c ) == 3*a) && !(a%2)) {cout <<-1<<endl; return 0;}
while(1){
    if((a%2) || (b%2) ||(c%2)) break;
    ans++;
    ll a1 = (b+c) / 2 , b1 = (a+c) / 2 , c1 = (a+b) / 2;
    a= a1 ,b = b1 , c = c1;
}
cout<<ans<<endl;
return 0;
}


Measured memory_bytes: 256
// Problem : B - Judge Status Summary
// Contest : AtCoder - AtCoder Beginner Contest 173
// URL : https://atcoder.jp/contests/abc173/tasks/abc173_b
// Memory Limit : 1024 MB
// Time Limit : 2000 ms
// Powered by CP Editor (https://github.com/cpeditor/cpeditor)

// #pragma GCC optimize ("O3")
// #pragma GCC target ("sse4")

#include <bits/stdc++.h>
 
using namespace std;
 
typedef long long ll;
typedef long double ld;
typedef complex<ld> cd;
 
typedef pair<int, int> pi;
typedef pair<ll,ll> pl;
typedef pair<ld,ld> pd;
 
typedef vector<int> vi;
typedef vector<ld> vd;
typedef vector<ll> vl;
typedef vector<pi> vpi;
typedef vector<pl> vpl;
typedef vector<cd> vcd;
 
#define FOR(i, a, b) for (int i=a; i<(b); i++)
#define F0R(i, a) for (int i=0; i<(a); i++)
#define FORd(i,b,a) for (int i = (b)-1; i >= a; i--)
#define F0Rd(i,a) for (int i = (a)-1; i >= 0; i--)
#define trav(a,x) for (auto& a : x)
 
#define bug(x) cout<<#x<<"="<<x<<endl; 
#define sz(x) (int)(x).size()
#define mp make_pair
#define pb push_back
#define f first
#define s second
#define lb lower_bound
#define ub upper_bound
#define all(x) x.begin(), x.end()
#define ins insert
 
template<class T> bool ckmin(T& a, const T& b) { return b < a ? a = b, 1 : 0; }
template<class T> bool ckmax(T& a, const T& b) { return a < b ? a = b, 1 : 0; }
 
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
 
const ld pii=3.14159265359; 
const int MOD = 1000000007;
const char nl = '\n';
const int MX = 200001; //check the limits, dummy
 
int main() 
{
	// && has higher precedence than ||
	ios_base::sync_with_stdio(0); cin.tie(0);    
	int N;
	cin>>N;
	vi v(4);
	F0R(x,N)
	{
		string str;
		cin>>str;
		if(str[0]=='A')v[0]++;
		else if(str[0]=='W')v[1]++ ;
		else if(str[0]=='T')v[2]++;
		else
			v[3]++;
	}
	cout<<"AC x "<<v[0]<<"\nWA x "<<v[1]<<"\nTLE x "<<v[2]<<"\nRE x "<<v[3];
	return 0;
}
 
// read the question correctly (ll vs int)
// template by bqi343

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

bool binarySearch(int *a, int n, int x){
	int left = 0;
	int right = n;
	while(right > left) {
		int mid = (right + left) / 2;
		if(a[mid] < x) left = mid + 1;
		else if(a[mid] > x) right = mid;
		else return true;
	}
	return false;
}

int main(){
	int n;
	scanf("%d", &n);
	int a[100010] = {0};
	for(int i = 0; i < n; i++)
		scanf("%d", a + i);
	sort(a, a+n);
	int q, x;
	scanf("%d", &q);
	int ans = 0;
	for(int i = 0; i < q; i++) {
		scanf("%d", &x);
		if(binarySearch(a, n, x)) ans++;
	}
	printf("%d\n", ans);
}



Measured memory_bytes: 3668
import java.util.Arrays;
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int[][] array = new int[3][3];
		for (int i = 0; i < 3; i++) {
			for (int j = 0; j < 3; j++) {
				array[i][j] = sc.nextInt();
			}
		}
		int n = sc.nextInt();
		for (int i = 0; i < n; i++) {
			int b = sc.nextInt();
			for (int j = 0; j < 3; j++) {
				for (int k = 0; k < 3; k++) {
					if (array[j][k] == b) {
						array[j][k] = -1;
					}
				}
			}
		}
		boolean flag = false;
		for (int i = 0; i < 3; i++) {
			boolean flag2 = true;
			for (int j = 0; j < 3; j++) {
				if (array[i][j] >= 0) {
					flag2 = false;
					break;
				}
			}
			if (flag2) {
				flag = true;
				break;
			}
		}
		for (int i = 0; i < 3; i++) {
			boolean flag2 = true;
			for (int j = 0; j < 3; j++) {
				if (array[j][i] >= 0) {
					flag2 = false;
					break;
				}
			}
			if (flag2) {
				flag = true;
				break;
			}
		}
		boolean flag2 = true;
		for (int i = 0; i < 3; i++) {
			if (array[i][i] >= 0) {
				flag2 = false;
				break;
			}
		}
		if (flag2) {
			flag = true;
		}
		flag2 = true;
		for (int i = 0; i < 3; i++) {
			if (array[i][2 - i] >= 0) {
				flag2 = false;
				break;
			}
		}
		if (flag2) {
			flag = true;
		}
		if (flag) {
			System.out.println("Yes");
		} else {
			System.out.println("No");
		}
	}
}


Measured memory_bytes: 21844
#include<cstdio>
#include<functional>
#include<algorithm>
using namespace std;
int main(void)
{
	int n,k,i,x;
	scanf("%d",&n);
	scanf("%d",&k);
	x=1;
	for(i=0;i<n;i++)	{
		x=min(x*2,x+k);
	}
	printf("%d\n",x);
	return 0;
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
#define fst first
#define snd second
#define rep(n) for(lint I = 0; (I) < (lint)(n); ++(I))
#define repeat(i, n) for(lint i = 0; (i) < (lint)(n); ++(i))
#define repeat_to(i, n) for(lint i = 0; (i) <= (lint)(n); ++(i))
#define repeat_from(i, m, n) for(lint i = (m); (i) < (lint)(n); ++(i))
#define repeat_from_to(i, m, n) for(lint i = (m); (i) <= (lint)(n); ++(i))
#define repeat_reverse_from_to(i, m, n) for(lint i = (m); (i) >= (lint)(n); --(i))
#define el cout<<endl
#define dump(x) cout<<" "<<#x<<"="<<x
#define vdump(v) for(size_t I=0; I<v.size(); ++I){cout<<" "<<#v<<"["<<I<<"]="<<v[I];} cout<<endl
using namespace std;
using lint = long long;
using ld = long double;

int main(void) {
    int n;
    cin >> n;
    vector<vector<bool>> f(n, vector<bool>(10));
    vector<vector<int>>  p(n, vector<int>(11));
    repeat (i, n) repeat(j, 10) {
        int t;
        cin >> t;
        if (t == 0) f[i][j] = false;
        else f[i][j] = true;
    }
    repeat (i, n) repeat(j, 11) {
        cin >> p[i][j];
    }
    
    auto decode = [&] (int i) {
        vector<bool> ret(10);
        repeat (b, 10) {
            if ((i >> b) & 1) ret[b] = true;
            else ret[b] = false;
        }
        return ret;
    };
    
    auto intersects = [&] (int shop, vector<bool> open) {
        int ret = 0;
        repeat(i, 10) {
            if (open[i] && f[shop][i]) ++ret;
        }
        return ret;
    };
    
    auto calc = [&] (const vector<bool> &open) {
        lint ret = 0;
        repeat(shop, n) {
            ret += p[shop][intersects(shop, open)];
            //dump(shop); dump(intersects(shop, open)); dump(ret); el; vdump(open); el;
        }
        return ret;
    };
    
    lint ans = numeric_limits<lint>::min();
    repeat_from_to (i, 1, 1023) {
        vector<bool> open = decode(i);
        ans = max(ans, calc(open));
        //dump(i); dump(calc(open)); vdump(open);
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include<math.h>
#include<list>
#include <algorithm>
#include<set>
#include<vector>
#include<math.h>
#include<map>
using namespace std;
using ll = long long;
using vll = vector<long long>;
using sll = set<long long>;

template<typename T>
T gcd(T a, T b) { return b ? gcd(b, a % b) : a; }

#define in(x) cin >> x
#define out(x) cout << x
#define outn(x) cout << x << '\n'
#define outs(x) cout << x << ' '
#define rep(i,s,e) for(long i=s;i<e;i++)
#define repeq(i,s,e) for(long i=s;i<=e;i++)

int main() {
	ll n,a;
	in(n);

	sll sa;
	rep(i, 0, n) {
		in(a);
		if (sa.find(a)==sa.end()) {
			sa.insert(a);
		}
		else {
			sa.erase(a);
		}
	}

	outn(sa.size());
	
}

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


int main() {
	vector<int> vec(3);
	for (int i = 0; i < 3; i++) {
		cin >> vec.at(i);
	}

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

	int R=(2 * vec.at(2) - (vec.at(1) + vec.at(0)));

	int Y = 0;

	if (R % 2 == 0) {
		Y = R/2;
	}
	else {
		Y = (3 + R) / 2;
	}

	cout << Y << endl;



	return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
using Int = long long;
template<typename T1,typename T2> inline void chmin(T1 &a,T2 b){if(a>b) a=b;}
template<typename T1,typename T2> inline void chmax(T1 &a,T2 b){if(a<b) a=b;}

//INSERT ABOVE HERE
const int MAX = 404;
int cs[4][MAX];

using A = array<int, 8>;
A rotH(A x){
  A y;
  y[0]=x[1];
  y[1]=x[2];
  y[2]=x[3];
  y[3]=x[0];

  y[7]=x[6];
  y[6]=x[5];
  y[5]=x[4];
  y[4]=x[7];
  return y;
}

A rotN(A x){
  A y;
  y[0]=x[3];
  y[3]=x[4];
  y[4]=x[7];
  y[7]=x[0];

  y[1]=x[2];
  y[2]=x[5];
  y[5]=x[6];
  y[6]=x[1];
  return y;
}

using ll = long long;
ll make_hash(ll a,ll b,ll c,ll d){
  return (a<<30)|(b<<20)|(c<<10)|d;
}

using P = pair<ll, ll>;
P make_hash(A x){
  return P(make_hash(x[0],x[1],x[2],x[3]),
           make_hash(x[4],x[5],x[6],x[7]));
}

map<ll, int> cnt,idx;
ll hs[4][MAX]={};

void inc(ll v){
  int k=idx[v];
  cnt[hs[0][k]]++;
  cnt[hs[1][k]]++;
  cnt[hs[2][k]]++;
  cnt[hs[3][k]]++;
}

void dec(ll v){
  int k=idx[v];
  cnt[hs[0][k]]--;
  cnt[hs[1][k]]--;
  cnt[hs[2][k]]--;
  cnt[hs[3][k]]--;
}

__int128_t check(A x){
  ll a=make_hash(x[0],x[1],x[2],x[3]);
  ll b=make_hash(x[4],x[5],x[6],x[7]);

  ll c=make_hash(x[3],x[2],x[5],x[4]);
  ll d=make_hash(x[2],x[1],x[6],x[5]);
  ll e=make_hash(x[1],x[0],x[7],x[6]);
  ll f=make_hash(x[0],x[3],x[4],x[7]);

  if(!cnt.count(a)) return 0;
  if(!cnt.count(b)) return 0;
  if(!cnt.count(c)) return 0;
  if(!cnt.count(d)) return 0;
  if(!cnt.count(e)) return 0;
  if(!cnt.count(f)) return 0;

  __int128_t res=1;
  res*=cnt[a];dec(a);
  res*=cnt[b];dec(b);
  res*=cnt[c];dec(c);
  res*=cnt[d];dec(d);
  res*=cnt[e];dec(e);
  res*=cnt[f];dec(f);

  inc(a);
  inc(b);
  inc(c);
  inc(d);
  inc(e);
  inc(f);

  return res;
}

signed main(){
  int n;
  cin>>n;
  for(int i=0;i<n;i++){
    cin>>cs[0][i]>>cs[1][i]>>cs[2][i]>>cs[3][i];
    for(int z=0;z<4;z++){
      hs[z][i]=make_hash(cs[(z+0)%4][i],
                         cs[(z+1)%4][i],
                         cs[(z+2)%4][i],
                         cs[(z+3)%4][i]);
      cnt[hs[z][i]]++;
      idx[hs[z][i]]=i;
    }
  }

  ll ans=0;
  set<P> used;

  vector<A> vs;
  {
    A w;
    set<A> rs;
    for(int i=0;i<8;i++) w[i]=i;
    for(int p=0;p<4;p++){
      for(int q=0;q<4;q++){
        for(int r=0;r<4;r++){
          rs.emplace(w);
          w=rotH(w);
        }
        w=rotN(w);
      }
      w=rotH(w);
    }
    vs=vector<A>(rs.begin(),rs.end());
  }

  for(int i=0;i<n;i++){
    for(int j=0;j<i;j++){
      for(int z=0;z<4;z++){
        A x;
        for(int k=0;k<4;k++){
          x[k+0]=cs[(k+z)%4][i];
          x[k+4]=cs[k][j];
        }
        int way=0,flg=0;
        for(auto v:vs){
          A y;
          for(int k=0;k<8;k++) y[k]=x[v[k]];
          if(x==y) way++;
          if(used.count(make_hash(y))){
            flg=1;
            break;
          }
        }
        if(flg) continue;
        ans+=check(x)/way;
        used.emplace(make_hash(x));
      }
    }
  }

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


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

int main()
{
  ll n,gcd=0,sum=0;
  cin>>n;
  for(ll i=1;i<=n;i++)
  {
      for(ll j=1;j<=n;j++)
      {
          for(ll k=1;k<=n;k++)
          {
              gcd=0;
              gcd=__gcd(i,__gcd(j,k));
              sum+=gcd;
          }
      }
  }
  cout<<sum;
}

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

using namespace std;

using int64 = long long;
const int mod = 1e9 + 7;

const int64 infll = (1LL << 62) - 1;
const int inf = (1 << 30) - 1;

struct IoSetup {
  IoSetup() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(10);
    cerr << fixed << setprecision(10);
  }
} iosetup;


template< typename T1, typename T2 >
ostream &operator<<(ostream &os, const pair< T1, T2 > &p) {
  os << p.first << " " << p.second;
  return os;
}

template< typename T1, typename T2 >
istream &operator>>(istream &is, pair< T1, T2 > &p) {
  is >> p.first >> p.second;
  return is;
}

template< typename T >
ostream &operator<<(ostream &os, const vector< T > &v) {
  for(int i = 0; i < (int) v.size(); i++) {
    os << v[i] << (i + 1 != v.size() ? " " : "");
  }
  return os;
}

template< typename T >
istream &operator>>(istream &is, vector< T > &v) {
  for(T &in : v) is >> in;
  return is;
}

template< typename T1, typename T2 >
inline bool chmax(T1 &a, T2 b) { return a < b && (a = b, true); }

template< typename T1, typename T2 >
inline bool chmin(T1 &a, T2 b) { return a > b && (a = b, true); }

template< typename T = int64 >
vector< T > make_v(size_t a) {
  return vector< T >(a);
}

template< typename T, typename... Ts >
auto make_v(size_t a, Ts... ts) {
  return vector< decltype(make_v< T >(ts...)) >(a, make_v< T >(ts...));
}

template< typename T, typename V >
typename enable_if< is_class< T >::value == 0 >::type fill_v(T &t, const V &v) {
  t = v;
}

template< typename T, typename V >
typename enable_if< is_class< T >::value != 0 >::type fill_v(T &t, const V &v) {
  for(auto &e : t) fill_v(e, v);
}


int main() {
  int N, K;
  cin >> N >> K;
  string S;
  cin >> S;
  for(int i = 0; i < N; i++) {
    if(i + 1 == K) cout << (char) tolower(S[i]);
    else cout << S[i];
  }
  cout << endl;


}

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

#define dbg(x) cout<<#x<<"="<<x<<'\n'
#define ll long long
#define pr pair<int,int>
#define pb push_back
#define ff first
#define ss second
#define vi vector<int>
#define rep(i,n) for(int i=0;i<(n);++i)
#pragma GCC optimization("Ofast")
#pragma GCC optimization("unroll-loops")
#define fin ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
#define MOD 1000000007
const int INF=1e9;



void solve(){
  int n,W;
  cin>>n>>W;
  int w[n],v[n];
  //for(int &x:v)cin>>x;
  for(int i=0;i<n;i++) cin>>w[i]>>v[i];
  ll dp[n+1][W+1];
  memset(dp,0LL,sizeof(dp));
  for(int i=1;i<=n;i++){
    for(int j=0;j<=W;j++){
      if(j<w[i-1])dp[i][j]=dp[i-1][j];
      else{
        dp[i][j]=max(dp[i-1][j-w[i-1]]+v[i-1],dp[i-1][j]);
      }
    }
  }
  // for(int i=0;i<=n;i++){
  //   for(int x:dp[i]) cout<<x<<" ";
  //     cout<<endl;
  // }
  cout<<*max_element(dp[n],dp[n]+W+1)<<endl;
}



int main()
{
    fin;
    
      solve();
        //cout<<solve()<<"\n";
    
    return 0;
}

Measured memory_bytes: 82376
#include<stdio.h>

const long long int NUM = 1000000007;

int main(){
  long long int ct=1;
  int ct1=0,ct2=0,ct3=0;
  int n,a;
  scanf("%d",&n);
  for(int i = 0;i < n;i++){
    scanf("%d",&a);
    ct *= (long long int)((a==ct1)+(a==ct2)+(a==ct3));
    ct %= NUM;
    if(a == ct1){ct1++;}
    else if(a == ct2){ct2++;}
    else if(a == ct3){ct3++;}
  }
  printf("%lld\n",ct);
  return 0;
}
  

Measured memory_bytes: 128
N, M = map(int, input().split())
ppp, ppm, pmp, pmm, mpp, mpm, mmp, mmm = list(), list(), list(), list(), list(), list(), list(), list()
for _ in range(N):
    x, y, z = map(int, input().split())
    ppp.append(x + y + z)
    ppm.append(x + y - z)
    pmp.append(x - y + z)
    pmm.append(x - y - z)
    mpp.append(- x + y + z)
    mpm.append(- x + y - z)
    mmp.append(- x - y + z)
    mmm.append(- x - y - z)
tmp = [sum(sorted(ppp, reverse=True)[:M]), sum(sorted(ppm, reverse=True)[:M]), sum(sorted(pmp, reverse=True)[:M]), sum(sorted(pmm, reverse=True)[:M]),
       sum(sorted(mpp, reverse=True)[:M]), sum(sorted(mpm, reverse=True)[:M]), sum(sorted(mmp, reverse=True)[:M]), sum(sorted(mmm, reverse=True)[:M])]
out = max(tmp)
print(out)

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

int M1[100][100], M2[100][100];
int dp[81][81][30000];
int n, m; 

int f(int x, int y, int k){
     if(x>=n or y>=m)return INT_MAX;

     if(x==n-1 and y==m-1){
          int diff=M1[x][y]-M2[x][y];
          return min(abs(k-diff), abs(k+diff));
     }

     int&ans=dp[x][y][k];
	 if(ans!=-1)return ans;

     ans=INT_MAX;
     int diff=M1[x][y]-M2[x][y];
     
     ans=min(ans, f(x+1, y, abs(k+diff)));
     ans=min(ans, f(x, y+1, abs(k+diff)));

     ans=min(ans, f(x+1, y, abs(k-diff)));
     ans=min(ans, f(x, y+1, abs(k-diff)));

     return ans;
}

int main(){
     cin>>n>>m;
     memset(dp, -1, sizeof(dp));
     for(int i=0;i<n;i++){
          for(int j=0;j<m;j++){
               cin>>M1[i][j];
          }
     }

     for(int i=0;i<n;i++){
          for(int j=0;j<m;j++){
               cin>>M2[i][j];
          }
     }
     
     int ans=f(0, 0, 0);
     cout<<ans;
}


Measured memory_bytes: 769152
//13
#include<iostream>
#include<algorithm>
#include<vector>

using namespace std;

int main(){
  int af[1002]={1,1};
  int *f=af+1;
  for(int i=1;i<=1000;i++){
    f[i]=(f[i-1]+f[i-2])%1001;
  }
  for(int v,d;cin>>v>>d;){
    vector<int> vf(f+1,f+v+1);
    sort(vf.begin(),vf.end());
    int p=vf[0];
    int s=1;
    for(int i=1;i<vf.size();i++){
      if(vf[i]-p>=d){
	s++;
      }
      p=vf[i];
    }
    cout<<s<<endl;
  }
  return 0;
}

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

#define rep(i,n) for(i = 0;i < n;++i)
#define all(v) v.begin(), v.end()
using ll = long long;

ll pow_mod(ll a, ll n, ll p)
{
    ll res = 1;
    while(n > 0){
        if(n & 1) res = res*a%p;
        a = a*a%p;
        n >>= 1;
    }
    return res;
}

ll mod_inv(ll a, ll MOD)
{
    ll b = MOD, u = 1, v = 0;
    while(b){
        ll t = a/b;
        a -= t*b;   swap(a,b);
        u -= t*v;   swap(u,v);
    }
    u %= MOD;
    if(u < 0) u+= MOD;
    return u;
}

int main()
{
    ll MOD = 1e9+7;
    ll i,j;
    ll n;
    cin >> n;
    vector<ll> a(n);
    for(i = 0;i < n;++i){
        cin >> a.at(i);
    }
    unordered_map<ll,ll> mp;
    vector<unordered_map<ll,ll>> vmp(n);
    for(i = 0;i < n;++i){
        ll tmp = a.at(i);
        ll sn = sqrt(tmp);
        vector<pair<ll,ll>> insuu;
        ll so = 2;
        ll num = 0;
        while(true){
            if(tmp%so == 0){
                tmp /= so;
                ++num;
            }else{
                if(num != 0){
                    insuu.emplace_back(so,num);
                    num = 0;
                }
                ++so;
            }
            if(tmp == 1){
                insuu.emplace_back(so,num);
                break;
            }
            if(so > sn){
                insuu.emplace_back(tmp,1);
                break;
            }
        }
        for(auto x:insuu){
            vmp.at(i)[x.first] = x.second;
            if(mp.count(x.first)){
                if(mp[x.first] < x.second) mp[x.first] = x.second;
            }else{
                mp[x.first] = x.second;
            }
        }
    }
    ll ans = 0;
    ll lsd = 1;
    for(auto x:mp){
        ll so = x.first;
        ll num = x.second;
        ll tmp = pow_mod(so, num, MOD);
        lsd *= tmp;
        lsd %= MOD;
    }
    unordered_map<ll,ll> somap;
    for(i = 0;i < n;++i){
        ll tmp = lsd;
        for(auto x:vmp.at(i)){
            ll so =  x.first;
            ll num = x.second;
            ll tmp2;
            if(somap.count(so)){
                tmp2 = somap[so];
            }else{
                tmp2 = mod_inv(so, MOD);
                somap[so] = tmp2;
            }
            ll tmp3 = pow_mod(tmp2, num, MOD);
            tmp *= tmp3;
            tmp %= MOD;
        }
        ans += tmp;
        ans %= MOD;
    }
    cout << ans << endl;
    return 0;
}

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

using namespace std;

using ll = long long;

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    int K;
    cin >> K;
    vector<ll> a(K);
    for (int i = 0; i < K; i++) {
        cin >> a[i];
    }
    ll L = 2, R = 2;
    for (int i = K - 1; i >= 0; i--) {
        L = (L + a[i] - 1) / a[i] * a[i];
        R = R / a[i] * a[i];
        if (L > R) {
            cout << -1 << endl;
            return 0;
        }
        R = (R / a[i] + 1) * a[i] - 1;
    }
    cout << L << " " << R << endl;
    return 0;
}

Measured memory_bytes: 1024