akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
  
using namespace std;
  
#define rep(i,n) REP(i,0,n)
#define REP(i,s,e) for(int i=(s); i<(int)(e); i++)
#define repr(i, n) REPR(i, n, 0)
#define REPR(i, s, e) for(int i=(int)(s-1); i>=(int)(e); i--)
#define pb push_back
#define all(r) r.begin(),r.end()
#define rall(r) r.rbegin(),r.rend()
#define fi first
#define se second
  
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
 
const int INF = 1e9;
const ll MOD = 1e9 + 7;
double EPS = 1e-8;

int main(){
    ll n, m;
    cin >> n >> m;
    string s, t;
    cin >> s >> t;
    // if(s.size() > t.size()) swap(s, t);
    ll g = __gcd(n, m);
    ll l = n * m / g;
    set<int> ss;
    rep(i, n) ss.insert(i*(l/n));
    rep(i, m) {
        int x = i * (l / m);
        if(ss.count(x)) {
            int j = x / (l/n);
            if(s[j] != t[i]) {
                // cout << i << " " << j << endl;
                cout << -1 << endl;
                return 0;
            }
        }
    }
    cout << l << endl;
    return 0;
}

Measured memory_bytes: 4736
a, b, c, x, y = map(int, input().split())


if a + b <= c*2:
  buy = a*x + b*y
elif a + b > c*2:
  num = [x,y]
  num.sort()
  buy = c*2*num[0]
  num_rest = num[1] - num[0]
  if num[1] == x:
    if a <= c*2:
      buy += a*num_rest
    else:
      buy += c*2*num_rest
  elif num[1] == y:
    if b <= c*2:
      buy += b*num_rest
    else:
      buy += c*2*num_rest
      
print(buy)

Measured memory_bytes: 3064
n, m = list(map(int, input().split()))
a = list(map(int, input().split()))
# x = list(map(int, input().split()))
# abc = [int(input()) for i in range(5)]
# n = int(input())
# n, m = list(map(int, input().split()))
bc = [list(map(int, input().split())) for i in range(m)]
a.sort()
bc_sorted = sorted(bc, key=lambda x: x[1], reverse=True)
l = 0
for i in range(m):
    l += bc[i][0]
j = 0
for i in range(min(l, n)):
    if a[i] <= bc_sorted[j][1]:
        a[i] = bc_sorted[j][1]
        bc_sorted[j][0] -= 1
        if bc_sorted[j][0] == 0:
            j += 1
    else:
        break
print(sum(a))


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

int main(){
    string s; cin >> s;
    int n = s.length();
    int I_A,I_Z;
    rep(0,i,n){
        if(s[i]=='A'){
            I_A = i+1;
            break;
        } 
    }
    for(int i=n-1; i>0; i--){
        if(s[i]=='Z'){
            I_Z = i+1;
            break;
        }
    }

    cout << I_Z - I_A + 1 << endl;
}

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

int main() {
	int N;
	cin >> N;
	
	map<int, int> counter;
	for (int i = 0; i < N; i++) {
		int A;
		cin >> A;
		counter[A]++;
	}
	
	int ans = 0;
	for (auto& mp : counter) {
		if (mp.second & 1) ans++;
	}
	cout << ans << endl;
	
	return 0;
}

Measured memory_bytes: 4864
def count(xy, pq):

    cnt = 0
    for k in range(n):
        
        for l in range(k+1, n):
            if (xy[l][0] - xy[k][0] == pq[0]) and (xy[l][1] - xy[k][1] == pq[1]):
                cnt += 1
    return cnt
n = int(input())
xy = []
for i in range(n):
    x, y = map(int, input().split())
    xy.append([x,y])
if n == 1:
    print(1)
else:
    m = 0
    xy.sort()
    for i in range(n):
        for j in range(i+1, n):
            pq = [xy[j][0] - xy[i][0], xy[j][1] - xy[i][1]]
            if m < count(xy,pq):
                m = count(xy,pq)
    print(n-m)

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

namespace ConsoleApp1
{
    class Program
    {
        static void Main(string[] args)
        {
            var list = new List<int>();
            char a = (char)Console.Read();
            char b = (char)Console.Read();
            char c = (char)Console.Read();

            list.Add((int)a);
            list.Add((int)b);
            list.Add((int)c);

            if (list[0] * 100 + list[1] * 10 + list[2] == list[2] * 100 + list[1] * 10 + list[0])
            {
                Console.WriteLine("Yes");
            }
            else
            {
                Console.WriteLine("No");
            }
        }
    }
}

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

#define rep(i, a) for (int i = 0; i < (a); i++ )
#define FOR(i, m, n) for(int i = m; i < n; i++)
 
typedef pair<int,int> P;
typedef long long ll;
 
const int INF = 1001001001;
const int MOD = 1000000007;
const double PI=acos(-1);

int main(){
    string s,t;
    cin >> s >> t;

    vector<vector<int>> A(26,vector<int>(0));

    rep(i,s.size()) {
        int tmp = (int) s[i] - 'a';
        A[tmp].push_back(i);
    }
    set<int> S;
    rep(i,t.size()) {
        int tmp = (int) t[i] - 'a';
        S.insert(tmp);
    }

    bool b = true;
    for (auto tmp: S) {
        if (A[tmp].size()==0) {
            b = false;
        }
    }
    if (!b) {
        cout << -1 << endl;
    }
    else {
        ll ans = 0;
        ll is,it;
        is = it = 0;
        is = -1;
        while(1) {
            auto tmp = A[t[it]-'a'];
            int idx = lower_bound(tmp.begin(),tmp.end(),is+1) - tmp.begin();
            if (idx==tmp.size()) {
                is = -1;
                ans+=s.size();
            }
            else {
                is = tmp[idx];
                it++;
            }
            if (it==t.size()) {
                ans += is+1;
                break;
            }            
        }
        cout << ans << endl;
    }
}


Measured memory_bytes: 4516
package main

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

func main() {
	sc = initScanner(os.Stdin)
	n, t, a := scanInt(sc), scanInt(sc), scanInt(sc)
	h := scanIntSlice(sc, n)
	fmt.Println(solve(t, a, h))
}

func solve(t, a int, h []int) int {
	var point int
	var tmp int

	min := math.MaxInt64
	for i, v := range h {
		tmp = abs(1000 * a - (1000*t - v*6))
		if min >= tmp {
			min, point = tmp, i+1
		}
	}

	return point
}

// --------------- BASE DEFINITIONS ---------------

const (
	initialBufSize = 100000
	maxBufSize     = 1000000
)

var sc *bufio.Scanner

func initScanner(r io.Reader) *bufio.Scanner {
	buf := make([]byte, initialBufSize)

	sc := bufio.NewScanner(r)
	sc.Buffer(buf, maxBufSize)
	sc.Split(bufio.ScanWords)
	return sc
}

func scanInt(sc *bufio.Scanner) int {
	sc.Scan()
	i, _ := strconv.Atoi(sc.Text())
	return i
}

func scanIntSlice(sc *bufio.Scanner, n int) []int {
	is := make([]int, n)
	for i := 0; i < n; i++ {
		is[i] = scanInt(sc)
	}

	return is
}

func scanFloat64(sc *bufio.Scanner) float64 {
	sc.Scan()
	f, _ := strconv.ParseFloat(sc.Text(), 64)
	return f
}

func scanFloat64Slice(sc *bufio.Scanner, n int) []float64 {
	fs := make([]float64, n)
	for i := 0; i < n; i++ {
		fs[i] = scanFloat64(sc)
	}

	return fs
}

func scanString(sc *bufio.Scanner) string {
	sc.Scan()
	return sc.Text()
}

func scanStringSlice(sc *bufio.Scanner, n int) []string {
	ss := make([]string, n)
	for i := 0; i < n; i++ {
		sc.Scan()
		ss[i] = sc.Text()
	}

	return ss
}

func abs(n int) int {
	if n < 0 {
		return -n
	}
	return n
}


Measured memory_bytes: 1796
#include <stdio.h>
int main(){
	int n, cnt=0;
    scanf("%d", &n);
	while(n--){
		int a;
        scanf("%d",&a);
		while(a%2==0){
			cnt++;
			a/=2;
		}
	}
	printf("%d\n",cnt);
	return 0;
}


Measured memory_bytes: 128
b=str(input())
setb=['A','T','C','G']
lenmax=0
lenmaxlist=[]
for i in range(len(b)):
    if b[i] in setb:
        lenmax=lenmax+1;
    else:
        lenmaxlist.append(lenmax)
        lenmax=0
if lenmax>0:
    lenmaxlist.append(lenmax)
if lenmaxlist:
    print(max(lenmaxlist))
else:
    print(0)


Measured memory_bytes: 3060
#include <cstdlib>
#include <iostream>
#include <unordered_map>
#include <vector>
using namespace std;

vector<int> sieve(int n) {
	vector<int> res{2};
	vector<bool> is_prime(n, true);

	for(int i = 3; i < n; i += 2) {
		if(is_prime[i]) {
			res.emplace_back(i);

			for(int j = i * i; j < n; j += i) {
				is_prime[j] = false;
			}
		}
	}
	return res;
}

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

	constexpr int MAX = (1 << 15);
	const auto primes = sieve(MAX);

	unordered_map<int, int> cnt;
	for(unsigned i = 0; i < primes.size(); ++i) {
		for(unsigned j = i; j < primes.size(); ++j) {
			++cnt[primes[i] + primes[j]];
		}
	}

	for(int n; cin >> n && n;) {
		cout << cnt[n] << endl;
	}

	return EXIT_SUCCESS;
}

Measured memory_bytes: 2844
#include<bits/stdc++.h>
using namespace std;
#define REP(i,st,ed) for(register int i=st,i##end=ed;i<=i##end;++i)
#define DREP(i,st,ed) for(register int i=st,i##end=ed;i>=i##end;--i)
typedef long long ll;
template<typename T>inline bool chkmin(T &x,T y){return (y<x)?(x=y,1):0;}
template<typename T>inline bool chkmax(T &x,T y){return (y>x)?(x=y,1):0;}
inline int read(){
	int x;
	char c;
	int f=1;
	while((c=getchar())!='-' && (c>'9' || c<'0'));
	if(c=='-') f=-1,c=getchar();
	x=c^'0';
	while((c=getchar())>='0' && c<='9') x=(x<<1)+(x<<3)+(c^'0');
	return x*f;
}
inline ll readll(){
	ll x;
	char c;
	int f=1;
	while((c=getchar())!='-' && (c>'9' || c<'0'));
	if(c=='-') f=-1,c=getchar();
	x=c^'0';
	while((c=getchar())>='0' && c<='9') x=(x<<1ll)+(x<<3ll)+(c^'0');
	return x*f;
}
const int maxn=100+10;
int a[maxn],l,r;
int Ans[maxn],tmp;
int main(){
	int n=read(),m=read(),num=0;
	REP(i,1,m){
		a[i]=read();
		if(a[i]&1){
			if(l) r=a[i];
			else l=a[i];
			++num;
		}
	}
	if(num>2) return printf("Impossible\n"),0;
	if(l) Ans[++tmp]=l;
	REP(i,1,m) if(a[i]%2==0) Ans[++tmp]=a[i];
	if(r) Ans[++tmp]=r;
	REP(i,1,tmp) printf("%d%c",Ans[i],i==iend?'\n':' ');
	Ans[1]--;
	if(tmp==1) ++tmp;
	Ans[tmp]++;
	printf("%d\n",tmp-(Ans[1]==0));
	REP(i,1,tmp) if(Ans[i]!=0) printf("%d%c",Ans[i],i==iend?'\n':' ');
	return 0;
}


Measured memory_bytes: 256
#include <stdio.h>
#include <string.h>
#define MAX 100


int n , c , d = 0;
int pre[1000] , in[1000],post[1000];

int find(int x)
{
	int i ;
	for( i = 0; i < n; i++)
	{
		if(x == in[i]) return i;
	}
	return 0;
}

void rec(int l , int r)
{
	int a , b;
	if(l >= r) return;
	a = pre[d++];
	b = find(a);
	rec(l,b);
	rec(b+1,r);
	post[c++] = a;
}



int main(void)
{
	int i;
	scanf("%d",&n);
	
	for( i = 0; i < n; i++)
	{
		scanf("%d",&pre[i]);
	}
	
	for( i = 0; i < n; i++)
	{
		scanf("%d",&in[i]);
	}
	
	rec(0,n);
	
	for(i = 0; i < n; i++)
	{
		if(i != n-1)printf("%d ",post[i]);
		else printf("%d\n",post[i]);
	}
	
	return 0;
}


Measured memory_bytes: 2140
# -*- coding: utf-8 -*-
import bisect
import heapq
import math
import random
import sys
from collections import Counter, defaultdict, deque
from decimal import ROUND_CEILING, ROUND_HALF_UP, Decimal
from functools import lru_cache, reduce
from itertools import combinations, combinations_with_replacement, product, permutations
from operator import add, mul, sub

sys.setrecursionlimit(100000)
input = sys.stdin.readline
INF = 2**62-1

def read_int():
    return int(input())


def read_int_n():
    return list(map(int, input().split()))


def read_float():
    return float(input())


def read_float_n():
    return list(map(float, input().split()))


def read_str():
    return input().strip()


def read_str_n():
    return list(map(str, input().split()))


def error_print(*args):
    print(*args, file=sys.stderr)


def mt(f):
    import time

    def wrap(*args, **kwargs):
        s = time.time()
        ret = f(*args, **kwargs)
        e = time.time()

        error_print(e - s, 'sec')
        return ret

    return wrap


def f(n):
    r = 2
    ret = 1
    for i in range(n, n-r, -1):
        ret *= i
    for i in range(1, r+1):
        ret //= i
    return ret * 2 + n


class Bisect:
    def __init__(self, func):
        self.__func = func

    def bisect_left(self, x, lo, hi):
        while lo < hi:
            mid = (lo+hi)//2
            if self.__func(mid) < x:
                lo = mid+1
            else:
                hi = mid
        return lo

    def bisect_right(self, x, lo, hi):
        while lo < hi:
            mid = (lo+hi)//2
            if x < self.__func(mid):
                hi = mid
            else:
                lo = mid+1
        return lo

@mt
def slv(N, M, A):
    A.sort(reverse=True)
    print(A)
    b = Bisect(f)

    i = b.bisect_left(M, 1, N)
    if f(i) != M:
        i -= 1
    l = f(i)

    ans = 0
    for j in range(i):
        ans += A[j] * 2
        ans += A[j] * (i-1)

    rem = M - l
    print(i, l, rem)
    j = 0
    while rem != 0:
        ans += A[j] + A[i]
        rem -= 1
        if rem == 0:
            break
        ans += A[j] + A[i]
        rem -= 1
        if rem == 0:
            break
        j += 1


    return ans

import numpy as np
def slv2(N, M, A):
    C = Counter(A)
    L = 2 ** ((max(A)*2).bit_length() + 1)
    B = [C[i] for i in range(L)]
    D = np.fft.rfft(B)
    D *= D
    E = list(np.fft.irfft(D).real)
    ans = 0
    c = 0
    i = L - 1
    while c != M:
        n = int(round(E[i]))
        if c + n > M:
            n = M-c
        c += n
        ans += i * n
        i -= 1
        assert i != -1

    return ans

def main():
    N, M = read_int_n()
    A = read_int_n()
    print(slv2(N, M,A))

    # N = 10**5
    # M = random.randint(1, N**2)
    # A = [random.randint(1, 10**5) for _ in range(N)]
    # print(slv(N, M, A))


if __name__ == '__main__':
    main()


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

using namespace std;

const int nmax = 100005;
vector<int> g[nmax];
int v[nmax];
bool visited[nmax];
vector<int> pos;
vector<int> val;

void dfs(int node) {
    pos.push_back(node);
    val.push_back(v[node]);
    for(int it : g[node]) {
        if(!visited[it]) {
            visited[it] = 1;
            dfs(it);
        }
    }
}

int main() {
    int n,m;
    cin >> n >> m;
    for(int i = 1;i <= n;i ++)
        cin >> v[i];
    for(int i = 1;i <= m;i ++) {
        int x,y;
        cin >> x >> y;
        g[x].push_back(y);
        g[y].push_back(x);
    }
    int nsol = 0;
    for(int i = 1;i <= n;i ++) {
        if(visited[i] == 0) {
            pos.clear();
            val.clear();
            visited[i] = 1;
            dfs(i);
            sort(pos.begin(),pos.end());
            sort(val.begin(),val.end());
            int ii = 0,j = 0;

            while(ii < pos.size() && j < val.size()) {
                if(pos[ii] == val[j]) {
                    ii ++;
                    j ++;
                    nsol ++;
                } else if(pos[ii] > val[j])
                    j ++;
                else if(pos[ii] < val[j])
                    ii ++;
            }
        }
    }
    cout << nsol;
    return 0;
}


Measured memory_bytes: 10156
#include "bits/stdc++.h"
using namespace std;
#define int long long
#define FOR(i, a, b) for(int i=(a);i<(b);i++)
#define RFOR(i, a, b) for(int i=(b-1);i>=(a);i--)
#define REP(i, n) for(int i=0; i<(n); i++)
#define RREP(i, n) for(int i=(n-1); i>=0; i--)
#define REP1(i, n) for(int i=1; i<=(n); i++)
#define RREP1(i, n) for(int i=(n); i>=1; i--)
#define ALL(a) (a).begin(),(a).end()
#define UNIQUE_SORT(l) sort(ALL(l)); l.erase(unique(ALL(l)), l.end());
#define CONTAIN(a, b) find(ALL(a), (b)) != (a).end()
#define out(...) printf(__VA_ARGS__)
#if DEBUG
#define debug(...) printf(__VA_ARGS__)
#else
#define debug(...) /* ... */
#endif
template<class T>bool chmax(T &a,const T &b){if(a<b){a=b;return true;}return false;}
template<class T>bool chmin(T &a,const T &b){if(b<a){a=b;return true;}return false;}

void solve();
signed main()
{
#if DEBUG
    std::ifstream in("input.txt");
    std::cin.rdbuf(in.rdbuf());
#endif
    cin.tie(0);
    ios::sync_with_stdio(false);
    solve();
    return 0;
}

/*================================*/
#if DEBUG
#define SIZE 100
#else
#define SIZE 223450
#endif

int N,Q,K;
int A[SIZE];

void solve() {
    cin>>N;
    int ans = 0;
    REP(i,N) ans += (i+1)*(N-i);
    int u,v;
    REP(i,N-1) {
        cin>>u>>v;
        if (u>v) swap(u,v);
        ans -= u*(N-v+1);
    }
    
    cout << ans << endl;
}


Measured memory_bytes: 3632
import java.util.*;

// UVa 11504

public class Main {

	public static void main(String[] args) {
		Scanner in = new Scanner(System.in);

		int w = in.nextInt();
		int a = in.nextInt();
		int b = in.nextInt();
		
		if (a < b && a + w < b) {
			System.out.println(b - a - w);
		} else if (a > b && b + w < a) {
			System.out.println(a - b - w);
		} else {
			System.out.println(0);
		}
	}
}


Measured memory_bytes: 21076
N = int(input())
ans = [0] * 10001
for x in range(1, 100):
    for y in range(1, 100):
        for z in range(1, 100):
            n = x**2 + y**2 + z**2 + x*y + y*z + z*x
            if n < len(ans):
                ans[n] += 1
for n in range(1, N + 1):
    print(ans[n])

Measured memory_bytes: 9108
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll mx = 2e4;
int main()
{
	int n;
	cin >> n;
	vector<tuple<ll,ll,ll>> blocks;
	for (int q = 0; q < n; q++)
	{
		ll w,s,v;
		cin >> w >> s >> v;
		blocks.emplace_back(w,s,v);
	}
	sort(blocks.begin(), blocks.end(), [](tuple<ll,ll,ll> a, tuple<ll,ll,ll> b){return (get<0>(a)+get<1>(a)) < (get<0>(b)+get<1>(b));});
	vector<vector<ll>> dp(n+1, vector<ll>(mx+1));
	for (int q = 0; q < n; q++)
	{
		for (int w = 1; w <= mx; w++)
		{
			ll w1 = get<0>(blocks[q]), s1 = get<1>(blocks[q]), v1 = get<2>(blocks[q]);
			dp[q+1][w]=max(dp[q][w], dp[q+1][w-1]);
			if (w >= w1 && s1 >= w-w1)
			{
				dp[q+1][w]=max(dp[q+1][w], dp[q][w-w1]+v1);
			}
		}
	}
	cout << dp[n][mx] << "\n";
	return 0;
}


Measured memory_bytes: 160640
#include<map>
#include<iostream>
#include<deque>
#include<algorithm>
#include<string>
#include<cctype>
#include<iomanip>
#include<vector>
#include<queue>
#include<math.h>
#include<bitset>
#include<random>
using namespace std;
using ll = __int64_t;
using lll = __int128_t;
typedef pair<ll,ll> P;
#define REP(i,b,e) for(int i=(int)b;i<(int)e;i++)
#define rep0(i,n) REP(i,0,n)
#define rep1(i,n) REP(i,1,n+1)
constexpr int inf=(1<<30)-1;
constexpr ll mod=1e9+7;



int main(){
      int a,b;
      cin>>a>>b;
      int cnt=0;
      int kuchi=1;
      while(kuchi<b){
            kuchi+=(a-1);
            cnt++;
      }
      cout<<cnt<<endl;
      return 0;
}


Measured memory_bytes: 256
#include <cstdio>
#include <vector>
#include <string>
#include <algorithm>
using namespace std;


int main()
{
	int m;

	scanf("%d", &m);

	for(int test_case = 0; test_case < m; ++test_case) {

		char buf[128];
		string s;
		vector<string> dict;

		scanf("%s", buf);
		s = buf;

		for(int i = 1; i < s.size(); ++i) {

			string l1 = s.substr(0, i);
			string r1 = s.substr(i, s.size());
			string l2 = l1;
			string r2 = r1;

			reverse(l2.begin(), l2.end());
			reverse(r2.begin(), r2.end());

			dict.push_back(l1 + r1);
			dict.push_back(l1 + r2);
			dict.push_back(l2 + r1);
			dict.push_back(l2 + r2);
			dict.push_back(r1 + l1);
			dict.push_back(r1 + l2);
			dict.push_back(r2 + l1);
			dict.push_back(r2 + l2);
		}

		sort(dict.begin(), dict.end());
		dict.erase(unique(dict.begin(), dict.end()), dict.end());

		int ans = dict.size();

		printf("%d\n", ans);
	}

	return 0;
}

Measured memory_bytes: 1168
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<ll,ll> P;
typedef pair<int,int> Pi;
#define rep(i, n) for (ll i = 0; i < n; i++)
#define FOR(i, a, b) for (ll i = a; i < b; i++)
#define fi first
#define se second
#define endl "\n"

template<typename T> inline bool chmax(T &a, T b){if(a<b){a=b;return true;}return false;}
template<typename T> inline bool chmin(T &a, T b){if(a>b){a=b;return true;}return false;}
template<typename T> ostream& operator<<(ostream& s,const complex<T>& d) {return s<<"("<<d.real()<<", "<<d.imag()<< ")";}
template<typename T1, typename T2> ostream& operator<<(ostream& s,const pair<T1,T2>& d) {return s<<"("<<d.first<<", "<<d.second<<")";}
template<typename T> ostream& operator<<(ostream& s, const vector<T>& d){
	int len=d.size();
	rep(i,len){
		s<<d[i];if(i<len-1) s<<" ";
	}
	return s;
}
template<typename T> ostream& operator<<(ostream& s,const vector<vector<T>>& d){
	int len=d.size();
	rep(i,len){
		s<<d[i]<<endl;
	}
	return s;
}
template<typename T> ostream& operator<<(ostream& s,const set<T>& v){
	s<<"{ ";
	for(auto itr=v.begin();itr!=v.end();++itr) {
		if (itr!=v.begin()) {s<< ", ";}
		s<<(*itr);
	}
	s<<" }";
	return s;
}
template<typename T1, typename T2> ostream& operator<<(ostream& s,const map<T1,T2>& m){
	s<<"{"<<endl;
	for(auto itr=m.begin();itr!=m.end();++itr){
		s<<" "<<(*itr).first<<" : "<<(*itr).second<<endl;
	}
	s<<"}"<<endl;
	return s;
}

const ll mod=1e9+7;
const ll inf=1e17;
const int INF=1e9;
const double PI=acos(-1);
const double EPS=1e-10;

int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	ll n,x,d;
	cin>>n>>x>>d;
	if(d==0){
		if(x==0) cout<<1<<endl;
		else cout<<n+1<<endl;
		return 0;
	}
	if(d<0){
		d*=-1;
		x*=-1;
	}
	map<ll,vector<P>> mp;
	rep(k,n+1){
		ll l=k*(k-1)/2;
		ll r=k*(2*n-k-1)/2;
		ll ret=((k*x)%d+d)%d;
		ll offset=(k*x-ret)/d;
		mp[ret].push_back(P(offset+l,offset+r));
	}
	ll ans=0;
	for(auto itr:mp){
		vector<P> now;
		swap(now,itr.se);
		ll st=-inf,en=-inf;
		now.push_back(P(inf,inf));
		sort(begin(now),end(now));
		for(auto q:now){
			if(q.fi<=en){
				chmax(en,q.se);
			}else{
				if(st!=-inf) ans+=en-st+1;
				st=q.fi;
				en=q.se;
			}
		}
	}
	cout<<ans<<endl;
}

Measured memory_bytes: 22144
#include <bits/stdc++.h>
using namespace std;
int main(void){
	int a,b,c,i,d,f,g;
	string A,B,C;
	cin>>A;
	if(A[0]==A[1]&&A[1]==A[2]||A[1]==A[2]&&A[2]==A[3]){
		cout<<"Yes"<<endl;
	}else{
		cout<<"No"<<endl;
	}
	return 0;
}

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

bitset<100005> isPrime;
int a[100005];

int main()
{
	ios_base::sync_with_stdio(0);
	cin.tie(0); cout.tie(0);

	isPrime.set();
	isPrime[1] = 0;
	for (ll i = 2; i < 100005; i++)
	{
		if (isPrime[i])
		{
			for (ll x = i*i; x < 100005; x += i)
				isPrime[x] = 0;
		}
	}

	for (int i = 1; i <= 100000; i++)
	{
		a[i] = a[i-1];
		if (i & 1 and isPrime[i] and isPrime[(i+1)/2])
			a[i]++;
	}

	int q;
	cin >> q;
	while (q--)
	{
		int l, r;
		cin >> l >> r;
		cout << a[r]-a[l-1] << '\n';
	}
	return 0;
}

Measured memory_bytes: 1024
fun main() {
    val n = readLine()!!.toInt()
    val arr = readLine()!!.split(" ").map { it.toInt() }
    val cnt = IntArray(n+1){0}
    for(d in arr) {
        cnt[d]++
    }
    for(i in 1..n) {
        println(cnt[i])
    }


}

Measured memory_bytes: 70484
#include<bits/stdc++.h>
using namespace std;
int n,a[200001];
int main() {
    scanf("%d",&n);
    for(int i=1; i<=n; ++i) scanf("%d",&a[i]);
    sort(a+1,a+n+1);
    for(int i=2; i<=n; ++i) {
        if(a[i]==a[i-1]) {
            printf("NO\n");
            return 0;
        }
    }
    printf("YES\n");
    return 0;
}

Measured memory_bytes: 1024
// Ver19.03
#include <math.h>
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#define INF (1 << 29) * 2
#define LLINF 4545454545454545454
#define MOD 1000000007
#define ll long long
#define ull unsigned long long
#define MAX(a, b) ((a) > (b) ? (a) : (b))
#define MIN(a, b) ((a) < (b) ? (a) : (b))
int upll(const void *a, const void *b) { return *(ll *)a < *(ll *)b ? -1 : *(ll *)a > *(ll *)b ? 1 : 0; }
int downll(const void *a, const void *b) { return *(ll *)a < *(ll *)b ? 1 : *(ll *)a > *(ll *)b ? -1 : 0; }
void sortup(ll *a, int n) { qsort(a, n, sizeof(ll), upll); }
void sortdown(ll *a, int n) { qsort(a, n, sizeof(ll), downll); }

int main()
{
  ll l, r, ans = 2018;
  scanf("%lld%lld", &l, &r);
  if (r - l >= 2019)
  {
    printf("%d\n", 0);
  }
  else
  {
    for (ll i = l; i <= r; i++)
    {
      for (ll j = i + 1; j <= r; j++)
      {
        int a = (i * j) % 2019;
        ans = MIN(ans, a);
      }
    }
    printf("%lld\n", ans);
    return 0;
  }
}

Measured memory_bytes: 128
i = lambda: list(map(int, input().split()))
N, = i()
M = [i() for j in range(N)]
k = -1
for k in range(len(M)):
    if M[k][2] > 0:
        break
for Cx in range(101):
    for Cy in range(101):
        H = abs(M[k][0] - Cx) + abs(M[k][1] - Cy) + M[k][2]
        if all([False for d in M if d[2] != max(H - abs(d[0] - Cx) - abs(d[1] - Cy), 0)]):
            print(Cx, Cy, H)
            break

Measured memory_bytes: 3064
N = int(input())
S = input()

white_sum = 0
for i in range(N):
    if S[i] == '#':
        continue
    else:
        white_sum += 1

left_black = 0
right_white = white_sum
min_sum = white_sum
for i in range(N):
    if S[i] == '#':
        left_black += 1
    else:
        right_white -= 1

    min_sum = min(min_sum, left_black + right_white)
print(min_sum)


Measured memory_bytes: 9424
import math

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

up = [[] for _ in range(N+1)] # 葉から考慮した場合の、最小値
up[N] = [A[N],A[N]]
#print(up)
for i in reversed(range(N)):
    Min, Max = up[i+1]
    #print(Min,Max)
    Min_n = math.ceil(Min/2) + A[i]
    Max_n = Max + A[i]
    #print(A[i],i)
    up[i] = [Min_n, Max_n]
#print(up)

if up[0][0] >= 2:
    print(-1)
else:
    down = 1
    #print(down)
    ans = 1
    for i in range(1, N+1):
        down *= 2
        down = min(down,up[i][1]) - A[i]
        ans += down + A[i]
    print(ans)

Measured memory_bytes: 87344
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <cmath>
#include <set>
#include <map>
#include <queue>
#include<limits.h>
#include<iomanip>
#define rep(i, n) for(int i = 0; i < n; i++)
#define REP(i, m, n) for(int i = m; i < n; i++)
#define ALL(v) v.begin(),v.end()
#define RALL(v) v.rbegin(),v.rend()
#define check(v) rep(i,v.size()) cout << v[i] << " ";\
cout << endl
#define INF 1e8
typedef long long ll;
using namespace std;
//オーバーフローに気をつけろよおおおおおお
//確認忘れるなよおおおおおお
 
int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    string s; cin >> s;
    ll ans = 0;
    s = "ZZZZZZZZZ" + s;
    ll cnt = 0;
    for(int i = s.size()-1; i >= 8; i--) {
        if(s[i]=='C' && s[i-1]=='B') {
            if(s[i-2]=='A') {
                if(cnt==0) {
                    ans++;
                    s[i] = 'A';
                    s[i-1] = 'C';
                    s[i-2] = 'B';
                }
                else {
                    ans+=cnt+1;
                    s[i] = 'B';
                    s[i-1] = 'C';
                    s[i-2] = 'B';
                }
            }
            else if(s[i-2]=='C' && s[i-3]=='B') {
                cnt++;
                i--;
            }
        }
        else cnt = 0;
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 788
#include<iostream>
#include<vector>
#include<algorithm>
using namespace std;
long long mod=1e9+7;
long long power(long long a,long long b)
{
	return b?power(a*a%mod,b/2)*(b%2?a:1)%mod:1;
}
long long M;
string S,T;
long long P[2<<17];
pair<int,long long>dp[2][2<<17];
void add(pair<int,long long>&a,pair<int,long long>b,long long now)
{
	(a.first+=b.first)%=mod;
	(a.second+=b.first*now+b.second)%=mod;
}
int main()
{
	cin>>S>>T;
	P[0]=1;
	for(int i=1;i<T.size();i++)
	{
		P[i]=P[i-1]*10%mod;
	}
	dp[0][0].first=1;
	for(int i=0;i<T.size();i++)
	{
		long tmp=P[T.size()-i-1];
		for(int j=0;j<2;j++)
		{
			if(T[i]!='?')
			{
				if(j==1||T[i]<=S[i])
				{
					add(dp[j||T[i]<S[i]][i+1],dp[j][i],tmp*(T[i]-'0')%mod);
				}
			}
			else
			{
				int lim=j==1?9:S[i]-'0';
				for(int k=0;k<=lim;k++)
				{
					add(dp[j||k<lim][i+1],dp[j][i],tmp*k%mod);
				}
			}
		}
	}
	cout<<(dp[0][T.size()].second+dp[1][T.size()].second)%mod<<endl;
}



Measured memory_bytes: 11220
package main

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

func main() {
	L := float64(readLineInt()[0]) / 3
	fmt.Printf("%f", L*L*L)
}

/////////////////////////////////////////

func readLineInt() []int {
	result := make([]int, 0)
	for _, v := range strings.Split(readLine(), " ") {
		i, _ := strconv.Atoi(v)
		result = append(result, i)
	}
	return result
}

var reader = bufio.NewReaderSize(os.Stdin, 1e6)

func readLine() string {
	result := make([]byte, 0, 1e6)
	for {
		line, remains, e := reader.ReadLine()
		if e != nil {
			panic(e)
		}
		result = append(result, line...)
		if !remains {
			break
		}
	}
	return string(result)
}


Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops") 
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp> 
#define int long long
#define fr(i,a,b) for(int i = a ; i <= b ; ++i)
#define rep(i, a, b) for(int i = a; i < (b); ++i)
#define trav(a, x) for(auto& a : x)
#define all(x) begin(x), end(x)
#define rall(x) (x).rbegin(), (x).rend()
#define sz(x) (int)(x).size()
#define pb push_back
#define fst first
#define snd second
using namespace __gnu_pbds;
using ordered_set =
 tree<int, null_type,less<int>,
 rb_tree_tag,tree_order_statistics_node_update>;
//find_by_order(k):returns iterator to kth element starting from 0
//order_of_key(k):returns count of elements strictly smaller than k
typedef long long ll;typedef pair<int, int> pii;
typedef vector<int> vi;typedef long double ld;
template<class T>
using min_heap = priority_queue<T,vector<T>,greater<T>>; 
template<typename T> T gcd(T a, T b){return(b?__gcd(a,b):a);}
template<typename T> T lcm(T a, T b){return(a*(b/gcd(a,b)));}
template<typename T> 
void remdup(vector<T>& v) {
	sort(all(v)); v.erase(unique(all(v)), v.end());
}
template<typename T> void re(vector<T> &v) {trav(i,v) cin >> i;}
void unsyncIO() { ios_base::sync_with_stdio(0); cin.tie(0); }
#ifdef np
#include "C:\Users\navodit\Desktop\mycodes\pr.h"
#else
#define trace(...)
#endif

#define MOD 1000000007  





void solve(){
	int n ,  a , b ;
	cin >> n >> a >> b ;
	cout << a*(n/(a+b)) + min(a,n%(a+b));
}



signed main() {
	unsyncIO();
	int tt =1 ;
	// cin >> tt;
	rep(i,0,tt) solve();













#ifdef np
	cout <<endl<<endl<< "Time elapsed: " << 1.0 * clock() / CLOCKS_PER_SEC << " s.\n";
#endif
	return 0;
}


Measured memory_bytes: 3652
#include <bits/stdc++.h>
#define ft first
#define sc second
#define lb lower_bound
#define ub upper_bound
#define pb push_back
#define pt(sth) cout << sth << "\n"
#define chmax(a, b) {if(a<b) a=b;}
#define chmin(a, b) {if(a>b) a=b;}
#define moC(a, s, b) (a)=((a)s(b)+MOD)%MOD
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
static const ll INF=1e18;
static const ll MAX=1e5+7;
static const ll MOD=1e9+7;
ll max(ll a, ll b) {return a>b?a:b;}
ll min(ll a, ll b) {return a<b?a:b;}



int main() {
  ll N;
  cin >> N;
  
  pt(N*(N-1)/2);
  
  
}















Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define inf INT_MAX
#define INF LLONG_MAX
#define ll long long
#define ull unsigned long long
#define M (int)(1e9+7)
#define P pair<int,int>
#define FOR(i,m,n) for(int i=(int)m;i<(int)n;i++)
#define RFOR(i,m,n) for(int i=(int)m;i>=(int)n;i--)
#define rep(i,n) FOR(i,0,n)
#define rrep(i,n) RFOR(i,n,0)
#define all(a) a.begin(),a.end()
const int vx[4] = {0,1,0,-1};
const int vy[4] = {1,0,-1,0};
#define F first
#define S second
#define PB push_back
#define EB emplace_back
#define int ll
#define vi vector<int>
#define IP pair<int,P>
#define PI pair<P,int>
#define PP pair<P,P>
#define Yes(f){cout<<(f?"Yes":"No")<<endl;}
#define YES(f){cout<<(f?"YES":"NO")<<endl;}



struct Mint {
  int x;

  Mint() : x(0) {}

  Mint(int y) : x(y >= 0 ? y % M : (M - (-y) % M) % M) {}

  Mint &operator+=(const Mint &p) {
    if((x += p.x) >= M) x -= M;
    return *this;
  }

  Mint &operator-=(const Mint &p) {
    if((x += M - p.x) >= M) x -= M;
    return *this;
  }

  Mint &operator*=(const Mint &p) {
    x = (int) (1LL * x * p.x % M);
    return *this;
  }

  Mint &operator/=(const Mint &p) {
    *this *= p.inverse();
    return *this;
  }

  Mint operator-() const { return Mint(-x); }

  Mint operator+(const Mint &p) const { return Mint(*this) += p; }

  Mint operator-(const Mint &p) const { return Mint(*this) -= p; }

  Mint operator*(const Mint &p) const { return Mint(*this) *= p; }

  Mint operator/(const Mint &p) const { return Mint(*this) /= p; }

  bool operator==(const Mint &p) const { return x == p.x; }

  bool operator!=(const Mint &p) const { return x != p.x; }

  Mint inverse() const {
    int a = x, b = M, u = 1, v = 0, t;
    while(b > 0) {
      t = a / b;
      swap(a -= t * b, b);
      swap(u -= t * v, v);
    }
    return Mint(u);
  }

  Mint power(int n) const {
    Mint ret(1), mul(x);
    while(n > 0) {
      if(n & 1) ret *= mul;
      mul *= mul;
      n >>= 1;
    }
    return ret;
  }

  friend ostream &operator<<(ostream &os, const Mint &p) {
    return os << p.x;
  }

  friend istream &operator>>(istream &is, Mint &a) {
    int t;
    is >> t;
    a = Mint(t);
    return (is);
  }


};
using mint = Mint;



template< typename T>
T power(T x,int k){
  T ret=1;
  while(k>0){
    if(k&1) (ret*=x);
    (x*=x); 
    k >>= 1;
  }
  return ret;
}

signed main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout<<fixed<<setprecision(20);

  int n;
  cin>>n;
  vi v(n);
  rep(i,n){
    cin>>v[i];
  }
  sort(all(v));

  Mint ans=0;
  int m=2*(n-1);
  Mint mol = power<Mint>(2,m);
  Mint ml=mol;
  mol*=2;
  rrep(i,n-1){
    Mint w=v[i];
    //cout<<mol<<endl;
    ans+=w*mol;
    mol+=ml;
    
  }

  cout<<ans<<endl;


}

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

using namespace std;

int main(){
  int n,w,v;
  while(cin >> n >> w, n){
    int N = 0;
    double p[11] = {0};
    for(int i = 0 ; i < n ; i++){
      cin >> v; p[v/w]++;
      N = max(N,v/w);
    }
    double d = *max_element(p,p+11),ans = 0;
    for(int i = 0 ; i < N ; i++){
      ans += (p[i]/d)*((double)(N-i)/N);
    }
    printf("%f\n",ans+0.01);
  }
  return 0;
}

Measured memory_bytes: 1180
#include <bits/stdc++.h>
#include <algorithm>
using namespace std;
 
int main() {
  int n,x;
  cin >> n >> x;
  int a[n];
  int temp;
  int sum[110];
 
  for(int i = 0; i < n; i++) cin >> a[i];
 
  sort(a, a + n);
  temp = 0;
  
  for(int i = 0; i < n; i++){
      temp = temp + a[i];
      sum[i] = temp;
     if(sum[i] > x ){
       cout << i << endl;
       return 0;
      }
  }
  

  
   if(sum[n-1] <= x && x - sum[n-2] == a[n-1]){
       cout << n << endl;
      }else{
       cout << n - 1 << endl; 
   }
}

Measured memory_bytes: 256
import collections
A, B, M = [int(item) for item in input().split()]
A_list = [int(item) for item in input().split()]
B_list = [int(item) for item in input().split()]
M_list = [[int(item) for item in input().split()] for _ in range(M)]

res_list = collections.deque()

for a, b, c in M_list:
    res_list.append(A_list[a-1] + B_list[b-1] - c)

res_list.append(min(A_list) + min(B_list))

print(min(res_list))

Measured memory_bytes: 36588
#include <iostream>
#include <iomanip>
#include <vector>
#include <algorithm>
#include <utility>
#include <string>
#include <queue>
#include <stack>

using namespace std;

typedef long long int ll;
typedef pair<int, int> Pii;

const ll mod = 998244353;

struct lazy_segtree {
  int n;
  vector<ll> data;
  vector<ll> lazy;
  vector<bool> lazyFlag;

  lazy_segtree(const int s) {
    init(s);
  }

  lazy_segtree(const int s, const int u) {
    init(s);
    for (int i = 0; i < s; i++) {
      data[i+n-1] = u;
    }
    for (int i = n-2; i >= 0; i--) {
      data[i] = min(data[i*2+1], data[i*2+2]);
    }
  }

  lazy_segtree(const vector<ll> &v) {
    int s = v.size();
    init(s);
    for (int i = 0; i < s; i++) {
      data[i+n-1] = v[i];
    }
    for (int i = n-2; i >= 0; i--) {
      data[i] = (data[i*2+1] + data[i*2+2]) % mod;
    }
  }

  void init(const int s) {
    n = 1;
    while (n < s) n <<= 1;
    data = vector<ll>(2*n-1);
    lazy = vector<ll>(2*n-1);
    lazyFlag = vector<bool>(2*n-1);
  }

  void evaluate(int p, int a, int b) {
    if (lazyFlag[p]) {
      data[p] = (data[p] + lazy[p]) % mod;
      if (b - a > 1) {
        lazy[p*2+1] = (lazy[p*2+1] + lazy[p]) % mod;
        lazy[p*2+2] = (lazy[p*2+2] + lazy[p]) % mod;
        lazyFlag[p*2+1] = true;
        lazyFlag[p*2+2] = true;
      }
      lazy[p] = 0;
      lazyFlag[p] = false;
    }
  }

  void update(int l, int r, ll v, int p = 0, int a = 0, int b = -1) {
    if (b < 0) b = n; // init

    // evaluate lazy value
    evaluate(p, a, b);

    if (r <= a || b <= l) return; // out of range
    if (l <= a && b <= r) { // fully covered
      lazy[p] = (lazy[p] + v) % mod;
      lazyFlag[p] = true;
      evaluate(p, a, b);
    }
    else {
      update(l, r, v, p*2+1, a, (a + b) / 2); // left
      update(l, r, v, p*2+2, (a + b) / 2, b); // right
      data[p] = (data[p*2+1] + data[p*2+2]) % mod;; // update
    }
    return;
  }

  ll query(int l, int r, int p = 0, int a = 0, int b = -1) {
    if (b < 0) b = n; // init
    if (r <= a || b <= l) return 0; // out of range

    // evaluate lazy value
    evaluate(p, a, b);

    if (l <= a && b <= r) return data[p];// fully covered

    int vl = query(l, r, p*2+1, a, (a + b) / 2); // left
    int vr = query(l, r, p*2+2, (a + b) / 2, b); // right
    return (vl + vr) % mod;
  }
};

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

  int n, k;
  cin >> n >> k;
  vector<Pii> lr(k);
  for (auto &x: lr) cin >> x.first >> x.second;

  lazy_segtree lst(n);
  lst.update(0, 1, 1);
  for (int i = 0; i < n; i++) {
    ll base = lst.query(i, i+1);
    for (int j = 0; j < k; j++) {
      lst.update(min(n, i+lr[j].first), min(n, i+lr[j].second+1), base);
    }
  }

  ll ans = lst.query(n-1, n);

  cout << ans << endl;

  return 0;
}


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

using namespace std;

int main()
{
    ios_base::sync_with_stdio(0);
    vector<bool> p(100001, true);
    p[0] = p[1] = false;
    for (int i = 2; i < 100001; ++i)
        if (p[i])
            for (int j = 2 * i; j < 100001; j += i)
                p[j] = false;
    vector<int> pref(100001);
    pref[0] = pref[1] = 0;
    for (int i = 2; i < 100001; ++i)
    {
        pref[i] = pref[i - 1];
        if (i % 2 == 1 && p[i] && p[(i + 1) / 2])
            ++pref[i];
    }
    int q;
    cin >> q;
    for (int i = 0; i < q; ++i)
    {
        int L, P;
        cin >> L >> P;
        cout << pref[P] - pref[L - 1] << endl;
    }
    return 0;
}


Measured memory_bytes: 1024
N = int(input())
count = {}

for idx in range(N):
	s = input()
	allist = [c for c in s]
	allist.sort()
	sortedstr = ''.join(allist)
	count[sortedstr] = count.get(sortedstr, 0) + 1

ans = 0
for num in count.values():
	num -= 1
	ans += ((num + 1) * num)//2

print(ans)

Measured memory_bytes: 17892
A = []
for i in range(3):
    a = list(map(int, input().split()))
    A.append(a)

N = int(input())
B = []
for i in range(N):
    b = int(input())
    B.append(b)

T = []
for i in range(3):
    T.append([False]*3)

for bi in B:
    for i in range(3):
        for j in range(3):
            if bi == A[i][j]:
                T[i][j] = True

# for i in range(3):
#     print(T[i])

ans = False
for i in range(3):
    if all(T[i]):
        ans = True

for i in range(3):
    if T[0][i] and T[1][i] and T[2][i]:
        ans = True

if T[0][0] and T[1][1] and T[2][2]:
    ans = True

if T[0][2] and T[1][1] and T[2][0]:
    ans = True

if ans:
    print('Yes')
else:
    print('No')


Measured memory_bytes: 3064
#include <iostream>
using namespace std;
int x[1000][1000],y[1000][1000];int a,b;
int main(){
	cin>>a>>b;
	for(int i=1;i<=a;i++){
		for(int j=1;j<=b;j++){
			char c;
			cin>>c;
			if(c=='#')x[i][j]=1;
			if((i==1||j%2==0)&&(i!=a))y[i][j]=1;
		}
	}
	for(int i=1;i<=a;i++){
		for(int j=1;j<=b;j++){
			if(x[i][j]||!y[i][j])cout<<"#";else cout<<".";
		}
		cout<<endl;
	}
	cout<<endl;
	for(int i=1;i<=a;i++){
		for(int j=1;j<=b;j++){
			if(x[i][j]||y[i][j])cout<<"#";else cout<<".";
		}
		cout<<endl;
	}
}

Measured memory_bytes: 6784
#include <algorithm>
#include <cmath>
#include <deque>
#include <iomanip>
#include <iostream>
#include <queue>
#include <set>
#include <string>
#include <vector>
using namespace std;
typedef long long ll;

#define rep(i, n) for(ll i = 0; i < n; i++)
#define REP(i, n) for(ll i = 1; i < n + 1; i++)


int main(){
    ll N;
    cin >> N;

    char X[N];
    ll ones = 0;
    rep(i, N){
        cin >> X[i];
        if(X[i] == '1'){
            ones++;
        }
    }

    ll baseP = 1;
    ll baseN = 1;
    ll rP[N + 1];
    ll rN[N + 1];
    REP(i, N){
        rP[i] = baseP % (ones + 1);
        baseP = rP[i] * 2;
        if(ones > 1){
            rN[i] = baseN % (ones - 1);
            baseN = rN[i] * 2;
        }
    }
    ll numPBase = 0;
    ll numNBase = 0;
    rep(i, N){
        if(X[i] == '1'){
            numPBase += rP[N - i];
            if(ones > 1){
                numNBase += rN[N - i];
            }
        }//cout << "rP[N - " << i << "]: " << rP[N - i] << endl;
    }
    
    rep(i, N){
        ll num;
        ll ans = 1;
        if(X[i] == '0'){
            num = (numPBase + rP[N - i]) % (ones + 1);//cout << "numPBase: " << numPBase << endl;
        }else{
            if(ones == 1){
                cout << 0 << endl;
                continue;
            }
            num = (numNBase - rN[N - i]) % (ones - 1);
        }//cout << "test num: " << num << endl;

        while(num > 0){
            ll countOnes = 0;
            ll i = 0;//cout << "num: " << num << ", (1<<i): " << (ll)(1<<i) << ", and: " << (num | (ll)(1<<i)) << endl;
            while((num | (ll)(1<<i)) <= num * 2){
                if((num & (ll)(1<<i)) > 0){
                    countOnes++;
                }
                i++;
            }//cout << "test countOnes: " << countOnes << endl;
            num %= countOnes;
            ans++;
        }

        cout << ans << endl;
    }

    return 0;
}


Measured memory_bytes: 6880
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <queue>
#include <set>
#include <map>
#include <functional>
#include <numeric>

using namespace std;
typedef long long int ll;
typedef pair <int,int> P;

int main() {
    int n,x,y = 0;
    int ans = 0;
    vector<int> l;

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

    for (int i = 0; i < n; i++) {
        y += l[i];
        if (y > x) break;
        ans++;
    }
   
    cout << ans + 1 << endl;
}

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

struct data{
	char name[101];		//¼O
	int price;			//li
	int ren;			//BàÅ«é©
	int renkin[101];	//BàÅg¤itemÌzñÌY¦[0]ÉÍÂðüêÄ¨­
};
data item[101];
int visit[101];			//»ÌACeðêxKê½©Ç¤©B

int func(int number){
	int c=item[number].renkin[0];
	int ans=0;
	visit[number]=1;
//	printf("%s\n",item[number].name);
	if(item[number].renkin[0]==0){
		return item[number].price;
	}
	for(int i=1;i<=c;i++){
		if(visit[item[number].renkin[i]]==1){
		//	printf("visited!! %s %d\n",item[item[number].renkin[i]].name,item[item[number].renkin[i]].price);
			ans+=item[item[number].renkin[i]].price;
		}
		else if(item[item[number].renkin[i]].ren==0){
//			printf("Can't!!   %s %d\n",item[item[number].renkin[i]].name,item[item[number].renkin[i]].price);
			ans+=item[item[number].renkin[i]].price;
		}
		else {
//			printf("renkin!!  %s %d\n",item[item[number].renkin[i]].name,item[item[number].renkin[i]].price);
			ans+=func(item[number].renkin[i]);
		}
	}
	if(ans<item[number].price)
		item[number].price=ans;
	
	return item[number].price;
}
			

int main(void){
	int n,i,j,l;
	while(scanf("%d",&n),n){
		
		int m,k,t;
		char temp[101];
		for(i=0;i<n;i++){
			scanf("%s %d",item[i].name,&item[i].price);
		}
		//±±©çBà
		scanf("%d",&m);
		for(i=0;i<m;i++){
			
			//Å«éàÌ
			scanf("%s",temp);
			for(j=0;j<n;j++){
				if(!(strcmp(item[j].name,temp))){
					item[j].ren=1;
					break;
				}
			}
			t=j;
//			puts(item[t].name);
			//´¿
			scanf("%d",&k);
			item[t].renkin[0]=k;
			for(j=0;j<k;j++){
				scanf("%s",temp);
				for(l=0;l<n;l++){
					if(!(strcmp(item[l].name,temp))){
						item[t].renkin[j+1]=l;
						break;
					}
				}
			}
		}
		scanf("%s",temp);
		for(i=0;i<n;i++){
			if(!(strcmp(item[i].name,temp))){
				break;
			}
		}
		//±±ÜÅÇÝÝ
		
		
		//wè³ê½ACeÅÄAµÄ¢­
		//©ªªoÄ«½ç¤BBàÅ«È¢B»±ðKê½©Å»fH
	//	puts("ÄA");
		printf("%d\n",func(i));
		
		for(i=0;i<101;i++){
			visit[i]=0;
			item[i].ren=0;
			item[i].price=0;
		}
	}
}

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

vector<bool> isPr;

//0からnまでの数字が素数かどうかを表す配列isPr
void isPrime( ll n ){
  isPr.assign(n+1,true);
  isPr.at(0) = false;
  isPr.at(1) = false;
  isPr.at(2) = true;
  for(ll now=2;now<=n;++now){
    if( isPr.at(now) ){
      if( (double)now >= sqrt(n) ) return; //√n以上はこれ以前にチェック済み
      ll cnt = 2;
      while( now*cnt <= n ){
        isPr.at(now*cnt) = false;
        cnt++;
      }
    }
  }
}

int main(){
  ll q;
  cin >> q;
  isPrime(100000);
  vector<ll> sum(100001); //0からその数字までの2017に似た数の総数
  ll now = 0;
  for(ll i=1;i<=100000;i+=2){
    if( isPr.at(i) && isPr.at((i+1)/2) ){
      ++now;
      sum.at(i) = now;
    }else{
      sum.at(i) = now;
    }
  }
  rep(i,q){
    ll l,r;
    cin >> l >> r;
    ll ans;
    if( isPr.at(l) && isPr.at((l+1)/2) ){
      ans = sum.at(r)-sum.at(l)+1;
    }else{
      ans = sum.at(r)-sum.at(l);
    }
    printf("%lld\n",ans);
  }
  return 0;
}

Measured memory_bytes: 1408
#include <iostream>
#include <cstdio>
#include <cstring>
#include <vector>
#include <deque>
#include <queue>
#include <array>
#include <set>
#include <map>
#include <cmath>
#include <complex>
#include <algorithm>
#include <numeric>
#include <utility>
#include <tuple>
#include <bitset>
#include <cstdint>
#include <cassert>
#include <random>
#include <iterator>

using namespace std;
using i64 = int64_t;
using i32 = int32_t;

int main() {
    i64 n, a, b;
    cin >> n >> a >> b;
    i64 ans = n / (a + b) * a + min(n % (a + b), a);
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
def RunLengthEncoding(S):
    res = []
    N = len(S)
    i = 0
    while i < N:
        cnt = 1
        while i < N - 1 and S[i] == S[i + 1]:
            cnt += 1
            i += 1
        res.append((S[i], cnt))
        i += 1
    return res


S = input()
N = len(S)
rle = RunLengthEncoding(S)

goal = []
for i, (l, r) in enumerate(zip(S[:-1], S[1:])):
    if l == "R" and r == "L":
        goal.append(i)

ans = [0] * N

p = 0
for i in range(0, len(rle), 2):
    _, nl = rle[i]
    _, nr = rle[i+1]
    g = goal[i//2]
    ans[g] += (nl + 1) // 2
    ans[g+1] += nl // 2
    ans[g+1] += (nr + 1) // 2
    ans[g] += nr // 2

print(*ans)

Measured memory_bytes: 19816
#include <iostream>
#include <string>
#include <vector>
#include <set>
#include <algorithm>
#include <cctype>
#include <cmath>
#include <queue>
#include <map>
#include <numeric>
#include <unordered_map>
#include <iomanip>
#include <functional>
#include <bitset>
#include <complex>
#include <stack>



#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define repi(i,a,b) for(int i=int(a);i<int(b);i++)
#define all(x) (x).begin(),(x).end()

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

typedef long long ll;

using namespace std;


int main()
{
  ios::sync_with_stdio(false);
  cin.tie(0);
  char x,y;
  cin>>x>>y;
  if(x<y)cout<<"<"<<endl;
  else if(x==y)cout<<"="<<endl;
  else cout<<">"<<endl;

  return 0;

}


Measured memory_bytes: 256
#include<iostream>

using namespace std;

int main(){
  //1000以上9999以下の整数n
  string n;
  for(int i=0;i<4;i++){
  	cin>>n[i];
  }
  
  if(n[0]==n[1]&&n[1]==n[2])
    cout<<"Yes"<<endl;
  else if(n[1]==n[2]&&n[2]==n[3])
    cout<<"Yes"<<endl;
  else
    cout<<"No"<<endl;
   
}


Measured memory_bytes: 256
#include<iostream>
#include<string.h>
#include<vector>
#include<algorithm>
#include<map>
using namespace std;

int n,s;

int solve(int now,int last,int count){
    if(count==n&&now==s){
        return 1;
    }
    if(count==n||now>s){
        return 0;
    }
    int co=0;
    for(int i=last+1;i<10;i++){
        co+=solve(now+i,i,count+1);
    }
    return co;
}
int main()
{
    
    while(cin>>n>>s){
        if(n==0&&s==0)break;
        int count=0;
        for(int i=0;i<10;i++){
            count+=solve(i,i,1);
        }
        cout<<count<<endl;
    }
    return 0;
}

Measured memory_bytes: 1160
x=[]
y=[]
for i in range(10):
    s=int(input())
    x.append(int(s))
a=sorted(x)
A=sum(a[7:10])

for i in range(10):
    s=int(input())
    y.append(int(s))
b=sorted(y)
B=sum(b[7:10])
print(A,B)


Measured memory_bytes: 5600