akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
using namespace std;

int gcd(int a, int b) {
  while (1) {
    if (a < b) swap(a, b);
    if (b == 0) break;
    a %= b;
  }
  return a;
}

int main() {
  int k;
  cin >> k;
  long long ans = 0;
  for (int a = 1; a <= k; a++) {
    for (int b = 1; b <= k; b++) {
      for (int c = 1; c <= k; c++) {
        //printf("(%d,%d,%d),", a, b, c);
        int g = gcd(gcd(a, b), c);
        //cout << g << endl;
        ans += g;
      }
    }
  }
  cout << ans << endl;
}

Measured memory_bytes: 3624
using System;
using System.Text;
using System.Collections.Generic;
using System.Linq;
using E = System.Linq.Enumerable;
 
class Program
 {
  static int[] A;
        static void Main(string[] args)
        {
          //入力を受け取る
          //var NK = Console.ReadLine().Split(' ').Select(x => int.Parse(x)).ToArray();
          var N = int.Parse(Console.ReadLine());
          
          var ans = 0L;
          var dic = new Dictionary<int,long>();
          for(int i = 0; i < N ; i++){
            var num = int.Parse(Console.ReadLine());
            if(dic.ContainsKey(num)){
              dic[num] += 1;
            }else{
              dic.Add(num,1);
            }
          }
          
          foreach(long Value in dic.Values) {
            if(Value%2 == 1){
              ans++;
            }
          }

          Console.WriteLine(ans);
        }
  
}


Measured memory_bytes: 22240
import sys
from bisect import bisect as br
from collections import Counter
readline = sys.stdin.readline

def check(A, B):
    SA = sorted(A)
    SB = sorted(B)
    if any(a > b for a, b in zip(SA, SB)):
        return 'No'
    if all(a <= b for a, b in zip(A, B)):
        return 'Yes'
    if any(br(SA, SB[i]) != i+1 for i in range(N)):
        return 'Yes'
    if len(set(A)) != N or len(set(B)) != N:
        return 'Yes'
    P = [None]*N
    Aidx = Counter()
    Bidx = Counter()
    for i in range(N):
        a = A[i]
        b = B[i]
        Aidx[a] = i
        Bidx[b] = i
        
    for i in range(N):
        sa = SA[i]
        sb = SB[i]
        P[Aidx[sa]] = Bidx[sb]
    visited = set()
    vn = 0
    while vn not in visited:
        visited.add(vn)
        vn = P[vn]
    if len(visited) == N:
        return 'No'
    return 'Yes'

N = int(readline())
A = list(map(int, readline().split()))
B = list(map(int, readline().split()))
print(check(A, B))

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

int main(){
    int n,m;
    while(cin>>n>>m,n){
        vector<int> s(n);
        vector<int> r(m);
        for(int i=0;i<n;i++)
            cin>>s[i];
        for(int i=0;i<m;i++)
            cin>>r[i];

        int ss=0,rs=0;
        for(int i=0;i<n;i++)
            ss+=s[i];
        for(int i=0;i<m;i++)
            rs+=r[i];

        pair<int,int> res=make_pair(-1,-1);
        for(int i=0;i<n;i++)
            for(int j=0;j<m;j++){
                if(ss-s[i]+r[j]==rs-r[j]+s[i]){
                    if(res.first==-1)
                        res=make_pair(i,j);
                    else{
                        if(s[i]+r[j]<s[res.first]+r[res.second])
                            res=make_pair(i,j);



                    }

                }


            }
        if(res.first!=-1)
            cout<<s[res.first]<<" "<<r[res.second]<<endl;
        else
            cout<<-1<<endl;
    }
    return 0;

}

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

using namespace std;

const int N = 200005;

int n;
int a[N];
long long A[N], B[N];
long long C[N], D[N];
long long sum[N];

#define get(l, r) (sum[r] - sum[l - 1])

int main() {
	ios::sync_with_stdio(false);
	cin >> n;
	for (int i = 1; i <= n; ++i) {
		cin >> a[i], sum[i] = sum[i - 1] + a[i];
	}
	int ptr = 0;
	for (int i = 1; i <= n; ++i) {
		while (ptr <= i && get(1, ptr) < get(ptr + 1, i)) ++ptr;
		long long mn1, mx1, mn2, mx2;
		mn1 = get(1, ptr - 1), mx1 = get(ptr, i);
		mn2 = get(ptr + 1, i), mx2 = get(1, ptr);
		if (mx2 < mx1) swap(mx2, mx1), swap(mn2, mn1);
		A[i] = mn1, B[i] = mx1;
	}
	ptr = n + 1;
	for (int i = n; i >= 1; --i) {
		while (ptr >= i && get(ptr, n) < get(i, ptr - 1)) --ptr;
		long long mn1, mx1, mn2, mx2;
		mn1 = get(ptr + 1, n), mx1 = get(i, ptr);
		mn2 = get(i, ptr - 1), mx2 = get(ptr, n);
		while (mx2 < mx1) swap(mx2, mx1), swap(mn2, mn1);
		C[i] = mn1, D[i] = mx1;
	}
	long long res = 1e18;
	for (int i = 2; i + 2 <= n; ++i) {
		long long mn = min(A[i], C[i + 1]);
		long long mx = max(B[i], D[i + 1]);
		res = min(res, mx - mn);
	}
	cout << res << '\n';
}

Measured memory_bytes: 8832
#include <bits/stdc++.h>
#define rep(i,m,n) for(int i=m;i<n;i++)
#define c(n) cin>>n
#define co(n) cout<<n<<endl
using namespace std;

int main(){
  int c=0,d=0,e,f,g,h,n,m,mx=0;
  cin>>n;
  int a[n];
  rep(i,0,n) cin>>a[i];
  cin>>m;
  int b[m];
  rep(i,0,n) cin>>b[i];
  sort(a,a+n); sort(b,b+m);
  
  rep(i,0,m){
    while(c<n){
      if(a[c]==b[i]){
        c++;
        d++;
        break;
      }
      else c++;
    }
  }
  if(d==m) co("YES");
  else co("NO");
    
  return 0;
}

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

/*第二引数で第一引数を割ったときの切り上げの計算*/
long long int maxtime(long long int x, long long int y) {
	return(x + y - 1) / y;

}
/*最大公約数*/
long long int lcm(long long int number1, long long int number2) {
	long long int m = number1;
	long long int n = number2;

	if (number2 > number1) {
		m = number2;
		n = number1;
	}
	long long int s = -1;
	while (s != 0) {
		s = m % n;
		m = n;
		n = s;
	}
	return m;
}
/*最大公倍数*/
long long int gcd(long long int number1, long long int number2) {
	long long int m = number1;
	long long int n = number2;
	return m / lcm(m, n) * n;
}
int main() {
	int n, d, x;
	cin >> n >> d >> x;
	for (int i = 0; i < n; i++) {
		int a;
		cin >> a;
		for (int j = 1; j <= d; j = j + a) {
			x = x + 1;
		}
	}
	cout << x;
}

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

int main(void)
{
	int i,n;
	double len;
	char data[6][50]={
		{"1:"},
		{"2:"},
		{"3:"},
		{"4:"},
		{"5:"},
		{"6:"}
	};

	scanf("%d",&n);
	for(i=0; i<n; i++){
		scanf("%lf",&len);
		if(len<165.0)
			strcat(data[0],"*");
		else if(len<170.0)
			strcat(data[1],"*");
		else if(len<175.0)
			strcat(data[2],"*");
		else if(len<180.0)
			strcat(data[3],"*");
		else if(len<185.0)
			strcat(data[4],"*");
		else
			strcat(data[5],"*");
	}
	for(i=0; i<6; i++)
		printf("%s\n",data[i]);

	return 0;
}

Measured memory_bytes: 620
import math
import os
mod = 10**9 + 7
N = int(input())
S = input()

operations = ["L" for i in range(len(S))]
operations[len(S)-1] = "R"

for i in range(1, len(S)):
    if S[i-1] == S[i]:
        if operations[i-1] == "L":
            operations[i] = "R"
        else:
            operations[i] = "L"
    else:
        operations[i] = operations[i-1]
if S[0] == "W" or S[-1] == "W" or operations[-1] == "L":
    print(0)
    os.sys.exit()

ans = 1
cnt_r = 0
cnt_l = 0
for ope in operations:
    if ope == "R":
        ans *= (cnt_l - cnt_r) % mod
        ans %= mod
        cnt_r += 1
    else:
        cnt_l += 1
if cnt_l != cnt_r:
    print(0)
    os.sys.exit()
print(ans*math.factorial(N)%mod)

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

int main(){

  int a, b, c, x, y, z;

  cin >> a >> b >> c;

  x = a + b;
  y = b + c;
  z = c + a;

  if(x>=y && z>=y){
    cout << y << endl;
  } else if(y>=x && z>=x){
    cout << x << endl;
  } else if(x>=z && y>=z){
    cout << z << endl;
  }
  
  return 0;
}

Measured memory_bytes: 256
import sys
sys.setrecursionlimit(10**5)
N, X = map(int, input().split())

layers = [1]
patties = [1]

for i in range(1, N+1):
	layer_i = 2 * layers[i-1] + 3
	patty_i = 2 * patties[i-1] + 1
	layers.append(layer_i)
	patties.append(patty_i)
	
def f(n, x):
	if x == 1:
		return 1 if n == 0 else 0
		
	elif 1 < x <= 1 + layers[n-1]:
		return f(n-1, x-1)
		
	elif x == 2 + layers[n-1]:
		return patties[n-1] + 1
		
	elif 2 + layers[n-1] < x <= 2 + 2 * layers[n-1]:
		return patties[n-1] + 1 + f(n-1, x-2-layers[n-1])
		
	else:
		return 2 * patties[n-1] + 1
		
print(f(N, X))

Measured memory_bytes: 9020
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
const ll MOD=1000000007;
const double PI=3.14159265358979;
const ll INF= pow(10,18);
typedef pair<ll,ll> P;
typedef vector<ll> vl;
typedef vector<vl> vvl;
#define FOR(i,a,b) for(ll i=a;i<b;i++)
#define rep(i,n) FOR(i,0,n)
string abc="abcdefghijklmnopqrstuvwxyz";
string ABC="ABCDEFGHIJKLMNOPQRSTUVWXYZ";

int main() {
  string s;
  cin >> s;
  ll k=s.size();
  if(k==2){
    cout << s << endl;
  }
  else{
    char c=s[0];
    s[0]=s[2];
    s[2]=c;
    cout << s << endl;
  }
}

Measured memory_bytes: 256
<?php


fscanf(STDIN, "%d%d%d", $n, $k, $q);

$ans=array_fill(1,$n,0);

for($i=0;$i<$q;$i++){
    fscanf(STDIN, "%d", $a);
    $ans[$a]++;
}

$th = $q - $k;
foreach($ans as $value){
    if($value > $th){
        echo "Yes".PHP_EOL;
    }else{
        echo "No". PHP_EOL;
    }
}


Measured memory_bytes: 9080
#include <iostream>
#include <vector>
#include <queue>
#include <fstream>
#include <list>
#include <algorithm>
#include <set>

#define UNSET 100000000000

using namespace std;

typedef long long int place;

class inf {
public:
    place d;
    place l,r;
    bool operator<(const inf& obj) const {
        return l < obj.l;
    }
    bool operator==(const inf& obj) const {
        return l == obj.l;
    }
};

inf temp;
place p[100010];
int n,m,l,r,d;
vector<inf> is;
queue<place> proc;
set<place> noproc;
set<place> noyet;

void input() {
    is.clear();
    while(!proc.empty())
        proc.pop();
    noyet.clear();
    for(int i = 0;i < 100010;i++)
        p[i] = UNSET;
    cin >> n >> m;
    for(int i = 0;i < m;i++) {
        cin >> l >> r >> d;
        noyet.insert(l);
        noyet.insert(r);
        temp.l = l;
        temp.r = r;
        temp.d = d;
        is.push_back(temp);
        temp.l = r;
        temp.r = l;
        temp.d = d * (-1);
        is.push_back(temp);
    }
}

void input_f(string fn) {
    fstream fs;
    is.clear();
    while(!proc.empty())
        proc.pop();
    noyet.clear();
    fs.open(fn,std::fstream::in);
    for(int i = 0;i < 100010;i++)
        p[i] = UNSET;
    fs >> n >> m;
    for(int i = 0;i < m;i++) {
        fs >> l >> r >> d;
        noyet.insert(l);
        noyet.insert(r);
        temp.l = l;
        temp.r = r;
        temp.d = d;
        is.push_back(temp);
        temp.l = r;
        temp.r = l;
        temp.d = d * (-1);
        is.push_back(temp);
    }
}

string solve() {
    sort(is.begin(),is.end());
    if(is.size() != 0)
        proc.push(is.front().l);
    while(!noyet.empty()) {
        if(proc.empty())
            proc.push(*(noyet.begin()));
        temp.l = proc.front();
        proc.pop();
        if(noyet.count(temp.l) == 1) {
            noyet.erase(temp.l);
            if(p[temp.l] == UNSET)
                p[temp.l] = 0;
            auto range = equal_range(is.begin(), is.end(), temp);
            for(auto itr = range.first;itr != range.second;itr++) {
                proc.push(itr->r);
                if(p[itr->r] == UNSET)
                    p[itr->r] = p[itr->l] + itr->d;
                else if(p[itr->r] != p[itr->l] + itr->d)
                    goto ret_no;
            }
        }
    }
    return "Yes";
ret_no:
    return "No";
}

int main(void) {
    /*
    for(int i = 1;i <= 9;i++) {
    input_f("/Users/linare/Downloads/D/in/0" + std::to_string(i) + ".txt");
    cout << solve() << endl;
    }
     */
    
    input();
    cout << solve() << endl;
     
    return 0;
}


Measured memory_bytes: 19884
package main

import "fmt"

const (
	plus = iota
	minus
)

func main() {
	var abcd string
	fmt.Scan(&abcd)

	a := int(rune(abcd[0]) - '0')
	b := int(rune(abcd[1]) - '0')
	c := int(rune(abcd[2]) - '0')
	d := int(rune(abcd[3]) - '0')

	for i := 0; i < 2; i++ {
		for j := 0; j < 2; j++ {
			for k := 0; k < 2; k++ {
				if calc(calc(calc(a, b, i), c, j), d, k) == 7 {
					fmt.Println(format(a, b, c, d, i, j, k))
					return
				}
			}
		}
	}
}

func calc(a, b int, ope int) int {
	if ope == plus {
		return a + b
	} else {
		return a - b
	}
}

func opeStr(ope int) string {
	if ope == plus {
		return "+"
	} else {
		return "-"
	}
}

func format(a, b, c, d int, opeA, opeB, opeC int) string {
	return fmt.Sprintf("%d%s%d%s%d%s%d=7", a, opeStr(opeA), b, opeStr(opeB), c, opeStr(opeC), d)
}

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

int main()
{
    string S, T;
    cin >> S >> T;
    for (int i = 0; i < S.size(); i++)
    {

        if (S.at(i) != T.at(i))
        {
            cout << "No" << endl;
            break;
        }
        else if (i < S.size() - 1)
        {
            continue;
        }
        else if (i == S.size() - 1)
        {
            cout << "Yes" << endl;
        }
    }
}

Measured memory_bytes: 3608
import sys
sys.setrecursionlimit(10 ** 5 + 10)
def input(): return sys.stdin.readline().strip()

def resolve():

    [x,y]=list(map(int,input().split()))
    ans=0

    for i in [x,y]:
        if i==1:
            ans+=300000
        elif i ==2:
            ans+=200000
        elif i==3:
            ans+=100000
    if x==1 and y==1:
        ans+=400000
    print(ans)


resolve()

Measured memory_bytes: 38256
#include <bits/stdc++.h>
 
using namespace std;
 
int main()
{
    double R0, W0, C, R;
    while (cin >> R0 >> W0 >> C >> R, (R0 > 0)) {        
        for (int X = 0; ; X++) {
            if ((R0 + X * R) / C - W0 >= 0) {
                cout << X << endl;
                break;
            }
        }
    }        
    return 0;
}

Measured memory_bytes: 3132
#![allow(
    non_snake_case,
    unused_variables,
    unused_assignments,
    unused_mut,
    unused_imports,
    dead_code
)]
//use proconio::fastout;
use proconio::input;
use proconio::marker::*;
use std::cmp::*;
use std::collections::*;
use std::ops::Bound::Included;
//use std::collections::VecDeque;

const MOD: i64 = 1_000_000_007;
fn main() {
    input! {
        Q:usize
    }
    let mut al = BinaryHeap::new();
    let mut ar = BinaryHeap::new();
    // first query
    input! {query:i64,a:i64,b:i64}
    al.push(a);
    // binary heap は最大値しかpopできないので、右側は逆順にしておく。
    ar.push(-a);
    let mut l = a;
    let mut r = a;
    let mut ans = 0;
    let mut bsum = b;

    for _ in 1..Q {
        input! {query:i64}
        if query == 1 {
            input! {a:i64,b:i64}
            bsum += b;
            if a < l {
                ans += l - a;
                al.push(a);
                al.push(a);
                r = al.pop().unwrap();
                ar.push(-r);
                l = *al.peek().unwrap();
            } else if a > r {
                ans += a - r;
                ar.push(-a);
                ar.push(-a);
                l = -ar.pop().unwrap();
                al.push(l);
                r = -*ar.peek().unwrap();
            } else {
                al.push(a);
                ar.push(-a);
                l = *al.peek().unwrap();
                r = -*ar.peek().unwrap();
            }
        } else {
            println!("{} {}", l, ans + bsum);
        }
    }
}


Measured memory_bytes: 10432
#define		_CRT_SECURE_NO_WARNINGS
#include <cstdio>

int main()
{
	int		n;
	int		A[100];

	scanf("%d", &n);

	for (int i = 0; i < n; i++)
		scanf("%d", &(A[i]));
	for (int i = n - 1; i >= 0; i--)
	{
		if (i != (n - 1))	printf(" ");
		printf("%d", A[i]);
	}
	printf("\n");

	return 0;
}

Measured memory_bytes: 2612
#include <iostream>
#include <algorithm>
#include <vector>
#include <iterator>
#include <numeric>

long int Euclid(long int A, long int B){
  int C;
  if(A<B){
    C = A;
    A = B;
    B = C;
  }
  long int R  = 1;
  while(R!=0){
    R = A%B;
    A = B; B = R;
    if(R==1){
      return 1;
      break;
    }
  }
  return A;
}

int main(){
  long int N;
  std::cin>>N;
  std::vector<int> A(N);
  std::copy_n(std::istream_iterator<int>(std::cin),N,A.begin());
  std::vector<long int> gcd_front(1, 1);
  std::vector<long int>  gcd_back(1, 1);
  gcd_front.push_back(A[0]);
  gcd_back.push_back(A[N-1]);
  long int gcd_f = A[0]; long int gcd_b = A[N-1];
  for(int i = 1 ; i < N ; i++ ){
    gcd_front.push_back(Euclid(gcd_f, A[i]));
    gcd_back.push_back(Euclid(gcd_b, A[N-i-1]));
    gcd_f = gcd_front[i+1];
    gcd_b = gcd_back[i+1];
  }
  long int gcd = 0;
  long int max_gcd = gcd_back[N-1];
  for(int i = 2 ; i < N ; i++ ){
    gcd = Euclid(gcd_front[i-1],gcd_back[N-i]);
    if(max_gcd<=gcd) max_gcd = gcd;
  }
  gcd = gcd_front[N-1];
  if(max_gcd<=gcd) max_gcd = gcd;
  std::cout<<max_gcd<<std::endl;
  return 0;
}


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

int main() {
    int A, B, C, X, Y;
    cin >> A >> B >> C >> X >> Y;

    int ans = 1000000000;
    for (int i = 0; i <= 100000; ++i) {
        ans = min(ans, i * 2 * C + A * max(0, X - i) + B * max(0, Y - i));
    }

    cout << ans << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define lsb(x) (x & (-x))
#define ll long long
// 82
 
using namespace std;
 
const int MAXN = (int) 1e5;
 
vector < pair <int, int> > g[MAXN + 1];
bool viz[MAXN + 1];
 
int sol[MAXN + 1];
 
void dfs(int nod) {
    viz[nod] = 1;
    for(auto it : g[nod]) {
        if(viz[it.first] == 0) {
            sol[it.first] = sol[nod] + it.second;
            dfs(it.first);
        }
        else if(sol[it.first] != sol[nod] + it.second) {
            cout << "No";
            exit(0);
        }
    }
}
 
int main() {
    //ifstream cin("A.in");
    //ofstream cout("A.out");
    int i, n, m, l, r, d;
    ios::sync_with_stdio(false);
    cin >> n >> m;
    for(i = 1; i <= m; i++) {
        cin >> l >> r >> d;
        g[l].push_back({r, d});
        g[r].push_back({l, -d});
    }
    for(i = 1; i <= n; i++) {
        if(viz[i] == 0) {
            dfs(i);
        }
    }
    cout << "Yes";
    //cin.close();
    //cout.close();
    return 0;
}


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

const int N = 100000;
const int INF = 2e9;
const int mod = 1e9+7;

int ans, n, m, k;
map<int, int> mp;

int main() {
  scanf("%d", &n);
  for (int a, i = 0; i < n; ++i) {
    scanf("%d", &a);
    ++mp[a];
  }
  for (const auto &e: mp) {
    if (e.second < e.first) ans += e.second;
    else if (e.second > e.first) ans += e.second-e.first;
  }

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


Measured memory_bytes: 4736
#include<stdio.h>
int main()
{
	int n,v[20],c[20],result=0;
	scanf("%d",&n);
	for(int i=0;i<n;i++)
	{
		scanf("%d",&v[i]);
	}
	for(int i=0;i<n;i++)
	{
		scanf("%d",&c[i]);
	}
	for(int i=0;i<n;i++)
	{
		if(v[i]-c[i]>0)
		{
			result+=v[i]-c[i];
		}
	}
	printf("%d",result);
	return 0;
} 


Measured memory_bytes: 128
import java.util.*;
import java.lang.*;

public class Main{
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        if(n < 1200){
            System.out.println("ABC");
        }else if(n >= 1200 && n < 2800){
            System.out.println("ARC");
        }else{
            System.out.println("AGC");
        }
    }
}

Measured memory_bytes: 23764
#include <bits/stdc++.h>
using namespace std;
typedef tuple<int,int,int> T;
int main() {
    int n,m,a;
    while(scanf("%d %d %d",&n,&m,&a),n) {
        vector<T> v;
        for(int i=0;i<m;i++) {
            int h,p,q;
            scanf("%d %d %d",&h,&p,&q);
            v.push_back(make_tuple(-h,p,q));
        }
        sort(v.begin(),v.end());
        for(int i=0;i<v.size();i++) {
            if(get<1>(v[i])==a) {
                a=get<2>(v[i]);
            }else if(get<2>(v[i])==a) {
                a=get<1>(v[i]);
            }
        }
        printf("%d\n",a);
    }
}

Measured memory_bytes: 3228
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
while (true) {
int H = sc.nextInt();
int W= sc.nextInt();
if (H == 0 && W == 0) {
break;
}
for(int i=1; i<=H;i++){
for(int j=1; j<=W;j++)System.out.printf("#");
System.out.printf("\n");
}
System.out.printf("\n");
}
}
}


Measured memory_bytes: 65764
d,g = map(int,input().split())
pc = list(list(map(int, input().split())) for _ in range(d))
ans = float("inf")

for i in range(1<<d):
    score = 0
    cnt = 0
    nokori = set(range(1, d+1))
    
    for j in range(d):
        if i>>j &1:
            score += (j+1)*pc[j][0]*100+pc[j][1]
            cnt += pc[j][0]
            nokori.discard(j+1)
            
    if score < g:
        use = max(nokori)
        n = min(pc[use-1][0], -(-(g-score)//(use*100))) # (g-sum)//(use*100)＞0
        cnt += n
        score += n*use*100
    if score >= g:
        ans = min(ans, cnt)
print(ans)

Measured memory_bytes: 9248
#include <iostream>
#include <cstdio>
#include <vector>
#include <list>
#include <cmath>
#include <fstream>
#include <algorithm>
#include <sstream>
#include <string>
#include <cstring>
#include <cstdlib>
#include <climits>
#include <cmath>

using namespace std;
typedef long long ll;


int N;
bool solve(){
  cin>>N;
  int cnt=0;
  for(int i=0;i<N;i++){
    int x;
    char p;
    cin>>p>>x;
    if(p=='(')cnt+=x;
    else{
      cnt-=x;
      if(cnt<0){
        return false;
      }
    }
  }
  return cnt==0;
}

int main(){

  if(solve())cout<<"YES"<<endl;
  else cout<<"NO"<<endl;

  return 0;
}

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

using namespace std;

int main()
{
    int n, m;
    char str[128];
    set<string> s;
    
    scanf("%d", &n);
    
    for (int i = 0; i < n; i++){
        scanf("%s", str);
        s.insert((string)str);
    }
    
    int stat = 0;
    
    scanf("%d", &m);
    
    for (int i = 0; i < m; i++){
        scanf("%s", str);
        if (s.find((string)str) == s.end()){
            printf("Unknown %s\n", str);
        }
        else {
            printf("%s by %s\n", stat ? "Closed" : "Opened", str);
            stat ^= 1;
        }
    }
    
    return (0);
}

Measured memory_bytes: 1248
N, A, B = map(int, input().split())

total = 0
for n in range(1, N + 1):
    tmp = n
    n_sum = 0

    while tmp != 0:
        n_sum += tmp % 10
        tmp //= 10

    if A <= n_sum <= B:
        total += n

print(total)

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

#define ft first
#define sd second
#define pb push_back
#define all(x) x.begin(),x.end()

#define ll long long int
#define vi vector<int>
#define vii vector<pair<int,int> >
#define pii pair<int,int>
#define plii pair<pair<ll, int>, int>
#define piii pair<pii, int>
#define viii vector<pair<pii, int> >
#define vl vector<ll>
#define vll vector<pair<ll,ll> >
#define pll pair<ll,ll>
#define pli pair<ll,int>
#define mp make_pair
#define ms(x, v) memset(x, v, sizeof x)
#define pr_vec(v) for(int i=0;i<v.size();i++) cout << v[i] << " " ;

#define f_in(st) freopen(st,"r",stdin)
#define f_out(st) freopen(st,"w",stdout)

#define fr(i, a, b) for(i=a; i<=b; i++)
#define fb(i, a, b) for(i=a; i>=b; i--)
#define ASST(x, l, r) assert( x <= r && x >= l )
const int  p=31,po=1,N=1e5+10, M=(ll)1e9+1 ;
const int mod = 1e9+7 ;
vl compute(string s){
        vl has(s.length());
        ll i;

        for(i=0;i<s.length();i++){
            if(i==0){
                has[i]=((s[i]-'a'+1))%mod;
            }
            else
                has[i]=(has[i-1]*p + (s[i]-'a'+1))%mod;
        }
        return has;
}
// vl ed[N],g[N],in(N),vis(N,0),cost(N,0);
vl g[N],vis(N,0);
vl ans;
priority_queue<ll,vl,greater<ll>> pq;
void dfs(ll x){
    vis[x]=1;
    ans.pb(x);
    for(auto &it:g[x]){
        if(!vis[it])
            pq.push(it);
      }
}

int main(){
 ios_base::sync_with_stdio(0);
 ll n,i,s=0,a,mi=-1;
 cin >> n;
  for(i=0;i<n;i++){
    cin >> a;
    s+=a;
    mi=max(mi,a);
    // cout << a;
  }
  // cout << mi;
  if((2*mi)<s){
      cout << "Yes";
  }
  else
    cout << "No";
  return 0;
}

Measured memory_bytes: 3328
#include<bits/stdc++.h>
using namespace std;
int main(){
  int n = 0,count = 0;
  string a,b,c;
  cin >> n;
  cin >> a >> b >> c; 
  for(int i=0;i<n;i++){
    if(a.at(i) != b.at(i)){
      if(b.at(i) != c.at(i)){
        if(a.at(i) != c.at(i)){
          b.at(i) = a.at(i);
          c.at(i) = a.at(i);
          count+=2;
        }else{ 
          b.at(i) = a.at(i);
          count++;
        }
      }else{
        a.at(i) = b.at(i);
        count++;
      } 
    }else{
      if(a.at(i) != c.at(i)){
        c.at(i) = a.at(i);
        count++;
      }
    }
  }
  
  cout << count << "\n";
}


Measured memory_bytes: 256
#include <iostream>
#include <string>

using namespace std;

int main() {
  string W, T;
  cin >> W;

  int result = 0;
  for ( ; ; ) {
    cin >> T;
    if (0 == T.compare("END_OF_TEXT")) break;
    if (W.length() == T.length()) {
      size_t i;
      for (i = 0; i < W.length(); ++i) {
        if (tolower(T[i]) != tolower(W[i])) break;
      }
      if (i == W.length()) ++result;
    }
  }
  cout << result << endl;
  return 0;
}



Measured memory_bytes: 3160
#include <bits/stdc++.h>
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>
// #include <boost/multiprecision/cpp_int.hpp> 

#define gc getchar//_unlocked
#define pc putchar//_unlocked
#define ll long long
#define ld long double
#define pb push_back
#define mp make_pair
#define pp pair<int,int>
#define bigint boost::multiprecision::cpp_int
#define finp ios_base::sync_with_stdio(0);cin.tie(0);
#define bc __builtin_popcountll
#define afor(i,a,b) for(int i=a;i<=b;++i)
#define bfor(i,a,b) for(int i=a;i>=b;--i)
#define vi vector<int>
#define vpp vector<pp>
#define vll vector<ll>

using namespace std;
using namespace __gnu_pbds;

char putnb[20];
void putn(ll n) {if(!n)pc('0');if(n<0)pc('-'),n=0-n;int pi=0;while(n)putnb[pi++]=(n%10)+'0',n/=10;while(pi)pc(putnb[--pi]);}
void sci(int *x) {register char c = gc();*x = 0;for(; (c<48)||(c>57);c = gc());for(; (c>47)&&(c<58);c = gc())*x = (int)((((*x)<<1) + ((*x)<<3)) + c - 48);}
void scll(ll *x)  {register char c = gc();*x = 0;for(; (c<48)||(c>57);c = gc());for(; (c>47)&&(c<58);c = gc())*x =  (ll)((((*x)<<1) + ((*x)<<3)) + c - 48);}
ll fp(ll a,ll b,ll c) {if(b==0)return 1%c; if(b==1)return a%c; ll ret=fp(a,b/2,c); ret=(ret*ret)%c; if(b&1)ret=(ret*a)%c; return ret;}

const ll mod=1e9 +7;
const ll mod2=1999999973;
const ll inf=1e18;
const int infs=1e9 + 1000;
const int N=100000;
const long double PI = acos(-1);

template <typename T>
using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;

bool vis[N+5];
bool sure[N+5];
int sz[N+5];

int n,m;
int main()
{
  finp;
 
  cin>>n>>m;
  sure[1]=vis[1]=true;
  afor(i,1,n)sz[i]=1;
  
  afor(i,1,m)
  {
    int x,y;
    cin>>x>>y;

    if(vis[x])
    {
      if(sz[x]==1)
      {
        if(sure[x])
        {
          sure[x]=vis[x]=false;
          sure[y]=vis[y]=true;
        }
        else
        {
          sure[x]=vis[x]=false;
          vis[y]=true;
          sure[y]=false;
        }
      }
      else
      {

        if(sure[x])
        {

          sure[x]=false;
          vis[y]=true;
          sure[y]=false;
        }
        else
        {
          vis[y]=true;
          sure[y]=false;
        }
      }
    }


    
    sz[x]--;
    sz[y]++;
  }




  int ans=0;
  afor(i,1,n)
  {
    if(vis[i])++ans;
  }
  cout<<ans;
  
return 0;
}

Measured memory_bytes: 896
#![allow(non_snake_case, unused)]
use std::cmp::*;
use std::collections::*;
use std::f64::consts::*;

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

macro_rules! input_inner {
    ($next:expr) => {};
    ($next:expr, ) => {};

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

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

macro_rules! read_value {
    ($next:expr, ( $($t:tt),* )) => {
        ( $(read_value!($next, $t)),* )
    };

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

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

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

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

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

    ($next:expr, $t:ty) => {
        $next().parse::<$t>().expect("Parse error")
    };
}

fn main() {
    input! {
        s: chars,
    }
    let mut cnt = s.len();
    let mut pair_flag = false;
    let mut cur = 1;
    while cur < s.len() {
        if pair_flag {
            pair_flag = false;
            cur += 1;
            continue;
        }
        if s[cur - 1] == s[cur] {
            cur += 2;
            cnt -= 1;
            pair_flag = true;
        } else {
            cur += 1;
        }
    }
    println!("{}", cnt);
}


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

typedef long long int ll;
typedef vector<int> vi;			typedef vector<ll> vl;
typedef vector<vi> vvi; 		typedef vector<vl> vvl;
typedef pair<int, int> 	pii;	typedef pair<ll, ll> pll;
typedef vector<pii> vii; 		typedef vector<pll> vll;
typedef map<int,int> mii;
typedef vector<char> vc;
typedef vector<bool> vb;
#define endl '\n'
#define forn(i,n) for(int i=0;i<n;i++)
#define rforn(i,n) for(int i=n-1;i>=0;i--)
#define forne(i,n) for(int i=1;i<=n;i++)
#define rforne(i,n) for(int i=n;i>=1;i--)
#define forse(i,s,e) for(int i=s;i<e;i++)
#define rforse(i,s,e) for(int i=e-1;i>=s;i--)
#define all(x) x.begin(),x.end()
#define sz(x) (ll)x.size()
#define MOD 1000000007
#define F first
#define S second
#define pb push_back
#define in insert
#define mp(a, b) make_pair(a, b)
#define fill(a,x) memset(a,x,sizeof a);
#define trav(a,x) for(auto &a:x)
#define min3(a, b, c) min(min(a, b), c)
#define min4(a, b, c, d) min(min(a, b), min(c, d))
#define max3(a, b, c) max(max(a, b), c)
#define max4(a, b, c, d) max(max(a, b), max(c, d))
#define INF INT_MAX
#ifdef KARAN
	#include "../../trace.h"
#else
    #define trace(args...)
#endif

ll modpow(ll a, ll b, ll m = MOD){a %= m; ll res = 1; 
	while (b) {if (b & 1)res = (res * a) % m; a = (a * a) % m; b >>= 1;} return res;}
ll bpow(ll a, ll b){ll res = 1; while (b) {if (b & 1)res = res * a; a = a * a; b >>= 1;} return res;}
ll modinv(ll a, ll m = MOD) {return modpow(a, m - 2, m);}
void graph(vvi &adj, int m) {int x, y; forn(i, m){cin>>x>>y; adj[--x].pb(--y); adj[y].pb(x);}}

void solve(){
	int n, m;
	cin>>n>>m;
	if(n%2==1){
		forne(i, m)
			cout<<i<<" "<<n+1-i<<endl;
	}
	else{
		forne(i, min(m, n/4))
			cout<<i<<" "<<n+1-i<<endl;
		for(int i=m-n/4, j = n/4+1; i>0; i--, j++)
			cout<<j<<" "<<n-j<<endl; 
	}
}

int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
	#ifdef KARAN
		freopen("inp.txt", "r", stdin);
    	freopen("out.txt", "w", stdout);
    	freopen("err.txt", "w", stderr);
	#endif
	int t=1;
	// cin>>t;
	while(t--)
		solve();
}

Measured memory_bytes: 3656
#include <stdio.h>
#define N 100

int main(){
  int i,j;
  int count=0;
  int n;
  int A[N];
  int a;
  
  scanf("%d",&n);
  for(i=0;i<n;i++) scanf("%d",&A[i]);
  
  for(i=0;i<n-1;i++){
    for(j=n-1;j>i;j--){
      if(A[j]<A[j-1]){
	a=A[j];
	A[j]=A[j-1];
	A[j-1]=a;
	count++;
      }
    }
  }
 
  for(i=0;i<n;i++){
    printf("%d",A[i]);
    if(i!=n-1)printf(" ");
  }
  printf("\n");
  printf("%d\n",count);
  
  return 0;
  
}

Measured memory_bytes: 604
#include<iostream>
#include<vector>
using namespace std;
int main(){
    string S;
    cin >> S;
    vector<string> weather = {"Sunny","Cloudy","Rainy"};
    int ans;
    for(int i=0;i<3;i++){
        if(weather.at(i)==S) ans = i;
    }
    cout << weather.at((ans+1)%3) << endl;
    return 0;
}

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

using namespace std;

int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int n, res=0;
    cin >> n;
    while(n){
    	res+=n%10;
    	n/=10;
    }
    if(res==1) res*=10;
    cout << res;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
/* typedef */
typedef long long ll;
typedef pair<int, int> pii;
/* constant */
const int INF = 1 << 30;
const ll LINF = 1LL << 50;
const int NIL = -1;
const int MAX = 100001;
const int mod = 1000000007;
const double pi = 3.141592653589;
/* global variables */
/* function */
/* main */
int main(){
    int N; cin >> N;
    vector<int> coins;
    coins.push_back(1);
    for (int i = 9; i < MAX; i*=9) coins.push_back(i);
    for (int i = 6; i < MAX; i*=6) coins.push_back(i);
    sort(coins.begin(), coins.end());

    vector<int> dp(MAX, INF);
    dp[0] = 0;
    for (int i = 0; i < coins.size(); i++) {
        for (int j = 0; j + coins[i] < MAX; j++) {
            dp[j + coins[i]] = min(dp[j + coins[i]], dp[j] + 1);
        }
    }
    cout << dp[N] << '\n';
}


Measured memory_bytes: 640
/**
 * ??§?°???¢???

???????????´??° a, b ?????????????????§???a ??¨ b
?????§?°???¢??????????????????????????°?????????????????????????????????

Input
??\??????????????§??????????????????????????´??° a, b ???????§?????????????????????????

Output
a ?????? b ???????????§???????????°

a < b
a ?????? b ??????????°????????????°???

a > b
a ??¨ b ?????????????????°???

a == b
??¨????????????????????????

Constraints
-1,000 ??? a, b ??? 1,000
Sample Input 1
1 2
Sample Output 1
a < b
Sample Input 2
4 3
Sample Output 2
a > b
Sample Input 3
5 5
Sample Output 3
a == b

 */

#include <iostream>
#include <sstream>

int main(int argc, char const *argv[]) {
  int a, b;
  a = b = 0;

  while (true) {
    std::string param;

    getline(std::cin, param);
    std::istringstream iss(param);
    iss >> a >> b;

    if ((a < -1000 || a > 1000) || (b < -1000 || b > 1000)) {
      std::cout << "Error: -1000 <= a, b <= 1000" << std::endl;
    } else {
      break;
    }
  }
  if (a < b) {
    std::cout << "a < b" << std::endl;
  } else if (a > b) {
    std::cout << "a > b" << std::endl;
  } else if (a == b) {
    std::cout << "a == b" << std::endl;
  }
  return 0;
}

Measured memory_bytes: 3172
#include<stdio.h>


//smallest num which can be devided by 2 and N
int main(void){
    int N,i=0;
    scanf("%d",&N);
    if(N%2 == 0){
        printf("%d\n",N);
    }
    else{
        printf("%d\n",2*N);
    }
    return 0;

}

Measured memory_bytes: 128
#include<bits/stdc++.h>
using namespace std ;
#define rep( i, s, t ) for( register int i = s; i <= t; ++ i )
#define re register
#define int long long
int gi() {
	char cc = getchar() ; int cn = 0, flus = 1 ;
	while( cc < '0' || cc > '9' ) {  if( cc == '-' ) flus = - flus ; cc = getchar() ; }
	while( cc >= '0' && cc <= '9' )  cn = cn * 10 + cc - '0', cc = getchar() ;
	return cn * flus ;
}
const int N = 1e5 + 5 ; 
const int inf = 12345678900 ;
int n, dp[N], R[N] ; 
struct node {
	int l, r ; 
} a[N] ; 
bool cmp( node x, node y ) {
	return x.r < y.r ; 
}
int check( int x ) {
	
}
signed main()
{
	n = gi() ; int x, L ;
	rep( i, 1, n ) x = gi(), L = gi(), a[i].l = x - L, a[i].r = x + L ; 
	sort( a + 1, a + n + 1, cmp ), dp[0] = 0, R[0] = -inf ;
	rep( i, 1, n ) {
		R[i] = a[i].r, dp[i] = dp[i - 1] ;
		int l = 0, r = i, ans = 0 ;
		while( l <= r ) {
			int mid = ( l + r ) >> 1 ; 
			if( R[mid] <= a[i].l ) ans = mid, l = mid + 1 ; 
			else r = mid - 1 ; 
		}
		dp[i] = max( dp[i], dp[ans] + 1 ) ;
	}
	printf("%lld\n", dp[n] ) ;
	return 0 ;
}


Measured memory_bytes: 3328
#include<iostream>
#include<algorithm>
#include<vector>
#include<queue>

using namespace std;

int main() {
	int n, m,tmp1,tmp2;
	cin >> n >> m;
	vector<int>* root = new vector<int>[n];
	int* sirube = new int[n];
	for (int i = 0;i < n;i++) {
		sirube[i] = -1;
	}
	sirube[0] = 0;
	for (int i = 0;i < m;i++) {
		cin >> tmp1>>tmp2;
		root[tmp1 - 1].push_back(tmp2 - 1);
		root[tmp2 - 1].push_back(tmp1 - 1);
	}
	queue<int> q;
	q.push(0);
	while (!q.empty()) {
		tmp1 = q.front();
		q.pop();
		for (int i = 0;i < root[tmp1].size();i++) {
			if (sirube[root[tmp1][i]] == -1) {
				sirube[root[tmp1][i]] = tmp1;
				q.push(root[tmp1][i]);
			}
		}
	}
	cout << "Yes\n";
	for (int i = 1;i < n;i++) {
		cout << sirube[i] + 1 << endl;
	}
}


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

const int MAX_N = 100005;
const int mod = 1e9+7;
int n, a[MAX_N];

int pow_mod(LL a, int k, int mod) {
	LL r=1;
	while(k > 0) {
		if(k&1) {
			r=(r*a%mod+mod)%mod;
		}
		a=(a*a%mod+mod)%mod;
		k>>=1;
	}
	return r;
}

void solve() {
	LL ans = 1;
	sort(a, a+n);
	if(n % 2) { // 0, 2, 2, 4, 4
		if(a[0] != 0) {
			printf("0\n");
			return;
		}
		for(int i=1; i<n; i+=2) {
			if(a[i] != a[i+1] && a[i] != i+1) {
				printf("0\n");
				return;
			}
			(ans*=2)%=mod;
		}
	} else {
		for(int i=0; i<n; i+=2) {
			if(a[i] != a[i+1] && a[i] != i+1) {
				printf("0\n");
				return;
			}
			(ans*=2)%=mod;
		}
	}
	printf("%lld\n", pow_mod(2, n/2, mod));
}

int main() {
	cin >> n;
	for(int i = 0; i < n; i++) {
		scanf("%d", &a[i]);
	}
	solve();
	return 0;
}

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

int main ()
{
//	ios_base::sync_with_stdio(false);
//	cin.tie(NULL);
	
//	freopen ("//specify file name","r",stdin);
//	freopen ("output.txt","w",stdout);
	
	int n;
	cin>>n;
	
	int matrix[n][3];
	
	for (int i=0;i<n;i++)
	{
		cin>>matrix[i][0]>>matrix[i][1]>>matrix[i][2];
		
	}
	
	int ans[n][3];
	
	ans[0][0] = matrix[0][0];
	ans[0][1] = matrix[0][1];
	ans[0][2] = matrix[0][2];
	
	for (int i=1;i<n;i++)
	{
		for (int j=0;j<3;j++)
		{
			if (j==0)
			{
				ans[i][j] = max (matrix[i][j]+ans[i-1][1] , matrix[i][j] + ans[i-1][2]);
			}
			else if (j==1)
			{
				ans[i][j] = max (matrix[i][j]+ans[i-1][0] , matrix[i][j] + ans[i-1][2]);
			}
			else if (j==2)
			{
				ans[i][j] = max (matrix[i][j]+ans[i-1][0] , matrix[i][j] + ans[i-1][1]);
			}
		}
	}
	
	int maxi = max (ans[n-1][0],ans[n-1][1]);
	maxi = max (ans[n-1][2], maxi);

	cout<<maxi;

	return 0;
	
}

Measured memory_bytes: 2560
#include <bits/stdc++.h>
#define N 300006
using namespace std;
struct arr{int l,r;}e[N];
int n,x,m,ans,tot,p,f[N],l[N],r[N],ls[20*N],rs[20*N],t[N],s[20*N];
bool operator<(arr x,arr y)
{
	return x.l<y.l;
}
int build(int l,int r)
{
	int mid=(l+r)>>1,rt=++tot;
	if(l==r)return rt;
	ls[rt]=build(l,mid);
	rs[rt]=build(mid+1,r);
	return rt;
}
void add(int rt,int nrt,int l,int r,int x)
{
	s[nrt]=s[rt]+1;
	int mid=(l+r)>>1;
	if(l==r)return;
	if(x<=mid){
		ls[nrt]=++tot;
		rs[nrt]=rs[rt];
		add(ls[rt],ls[nrt],l,mid,x);
	}else{
		rs[nrt]=++tot;
		ls[nrt]=ls[rt];
		add(rs[rt],rs[nrt],mid+1,r,x);
	}
}
int query(int lrt,int rrt,int l,int r,int x,int y)
{
	if(x<=l&&r<=y)return s[rrt]-s[lrt];
	int mid=(l+r)>>1,tmp=0;
	if(x<=mid)tmp=query(ls[lrt],ls[rrt],l,mid,x,y);
	if(y>mid)tmp+=query(rs[lrt],rs[rrt],mid+1,r,x,y);
	return tmp;
}
int main()
{
	scanf("%d%d",&n,&m);
	for(int i=1;i<=n;i++)scanf("%d%d",&e[i].l,&e[i].r),f[e[i].l]++;
	sort(e+1,e+n+1);
	for(int i=1,h=1;i<=m;i++){
		while(e[h].l<i&&h<n)h++;
		if(e[h].l<=i)l[i]=h;else l[i]=h-1;
		while(e[h].l==i&&h<n)h++;
		if(e[h].l<=i)r[i]=h;else r[i]=h-1;
	}
	for(int i=1;i<=m;i++)f[i]+=f[i-1];
	t[0]=build(1,m);
	for(int i=1;i<=n;i++)t[i]=++tot,add(t[i-1],t[i],1,m,e[i].r);
	for(int i=1;i<=m;i++){
		int ans=0;
		for(int j=i,h=0;j<=m;h=j,j+=i){
			int tmp=0;
			if(h+1<=j-1)tmp=query(t[r[h]],t[r[j]],1,m,h+1,j-1);
			ans+=f[j]-f[h]-tmp;
		}
		printf("%d\n",ans);
	}
}

Measured memory_bytes: 69376
#include<bits/stdc++.h>
using namespace std;
#define cases           int T;cin>>T;for(int TC=1;TC<=T;TC++)
#define FastRead        ios_base::sync_with_stdio(0)
#define power(n,i)      (long long)ceil(pow(n,i))
#define ABS(x)          ((x)<0?-(x):(x))
#define MAX(x,y,z)      max(max(x,y),z)
 
int data[100005][4];
int dp[100005][4];
int n;
long long call(int i, int prev)
{
    if(i==n)
      return 0;
 
    if(dp[i][prev]!=-1)
      return dp[i][prev];
 
    long long res1=0,res2=0,res3=0;
 
    if(prev!=1)
      res1=call(i+1,1)+data[i][1];
    if(prev!=2)
      res2=call(i+1,2)+data[i][2];
    if(prev!=3)
      res3=call(i+1,3)+data[i][3];
 
    return dp[i][prev]=MAX(res1,res2,res3);
 
}
int main()
{
   cin>>n;
   memset(dp,-1,sizeof(dp));
   for(int i=0;i<n;i++)
   {
      for(int j=1;j<=3;j++)
          cin>>data[i][j];
   }
   cout<<call(0,0);
}

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

int main()
{
	int a, b, c;
	cin >> a >> b >> c;
	auto r = vector<bool>(b);
	int t = a;
	while(!r[a % b]){
		r[a % b] = true;
		a += t;
	}
	cout << (r[c] ? "YES" : "NO") << endl;
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using intl = long long;
using itnl = long long;
using itn = int;
using ld = long double;
using namespace std;
#define rep(i, n) for(intl i = 0; i < (intl)(n); i++)
#define rrep(i, n) for(intl i = (intl)(n) - 1; i >= 0; i--)
#define repi(i, a, b) for(intl i = (intl)(a); i < (intl)(b); i++)
#define rrepi(i, a, b) for(intl i = (intl)(a); i > (intl)(b); i--)
#define max(a, b) ((a) > (b) ? (a) : (b))
#define min(a, b) ((a) < (b) ? (a) : (b))
#define all(x) (x).begin(),(x).end()
#define m0(x) memset(x,0,sizeof(x))
#define m1(x) memset(x,1,sizeof(x))
#define fill(x,y) memset(x,y,sizeof(x))
#define alength(a) (sizeof(a) / sizeof(a[0]))
#define cin(i, a) rep(i, alength(a))cin >> a[i]
#define ccin(i, j, a) rep(i, alength(a))rep(j, alength(a[i]))cin >> a[i][j]
#define debug(x) cout << #x << ":" << x << endl
#define rdebug(i,x) rep(i, alength(x))cout << #x << "[" << i << "]:" << x[i] << endl
#define sqrt sqrtl
#define itn int
#define double ld
#define pb push_back
#define mp make_pair
#define pii pair<intl,intl>
const intl INF = 1e9;
const intl MOD = 1e9+7;
const ld eps = 1.0e-14;//-9
void fp(bool f){cout << (f ? "Yes" : "No") << endl;}
void fp(bool f, string s, string t){cout << (f ? s : t) << endl;}
intl kai(intl k){
    intl a = 1;
    for(int i = 2; i <= k; i++){
        a *= i;
    }
    return a;
}
intl gcd(intl a, intl b){
    if(!b)return a;
    return gcd(b, a % b);
}
intl lcm(intl a,intl b){
    return a / gcd(a, b) * b;
}
intl digit10(intl a){
    intl b = 0;
    do{
        a /= 10;
        b++;
    }while(a);
    return b;
}
signed main(){
    cout << fixed << setprecision(10);
    intl n;
    cin >> n;
    vector<intl> v;
    intl idx = 2;
    v.pb(n);
    while(true){
        n = (!(n % 2) ? n / 2 : 3 * n + 1);
        if(find(all(v),n) != v.end())break;
        v.pb(n);
        idx++;
    }
    cout << idx << endl;
    return 0;
}

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

typedef long long ll;

int main(){
  ll n,m;
  cin >> n >> m;
  ll a[n],b[n],c[n];
  for(ll i=0;i<n;i++){
    cin >> a[i] >> b[i] >> c[i];
  }
  ll ans=0;
  ll ax[n],bx[n],cx[n],sum[n];
  for(int x=0;x<2;x++){
    for(int y=0;y<2;y++){
      for(int z=0;z<2;z++){
        for(int i=0;i<n;i++){
          if(x==0) ax[i]=a[i];
          else ax[i]=-a[i];
          if(y==0) bx[i]=b[i];
          else bx[i]=-b[i];
          if(z==0) cx[i]=c[i];
          else cx[i]=-c[i];
          sum[i]=ax[i]+bx[i]+cx[i];
        }
        sort(sum,sum+n);
        ll res=0;
        for(int i=n-1;i>n-1-m;i--){
          res+=sum[i];
        }
        ans=max(ans,res);
      }
    }
  }
  cout << ans << endl;
}

Measured memory_bytes: 256
import heapq

n, m = list(map(int, input().split()))
cards = list(map(int, input().split()))
cards.sort()

queries = []
for i in range(m):
    q = list(map(int, input().split()))
    queries.append(q)
queries.sort(key=lambda x: x[1])
queries.reverse()

ans = 0
pos = 0
for q in queries:
    b, c = q
    if cards[min(pos+b-1, n-1)] < c:
        # print('a')
        pos = pos + b
        ans += c * (b - max(0, pos-n))
        if pos >= n:
            break
    else:
        for i in range(b):
            if cards[pos+i] < c:
                # print('b')
                ans += c
            else:
                # print('c')
                pos += i
                for j in range(pos, n):
                    ans += cards[j]

                pos = n
                break
        break

if pos < n:
    for j in range(pos, n):
        ans += cards[j]

print(ans)



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

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

Measured memory_bytes: 384
#include<bits/stdc++.h>
using namespace std;
/**
******************* Author:Bisnu sarkar ****************************
**/
/*
#pragma GCC target ("avx2")
#pragma GCC optimization ("O3")
#pragma GCC optimization ("unroll-loops")
*/
#define fRead(x)       freopen(x,"r",stdin)
#define fWrite(x)      freopen (x,"w",stdout)
#define ull            unsigned long long
#define ll             long long
#define pii            pair<int,int>
#define sit            set<int> :: iterator
#define vrit           vector<int> :: reverse iterator
#define ff             first
#define ss             second
#define endl           '\n';
#define sz(s)          (int)s.size()
#define all(s)         s.begin(),s.end()
#define IO             ios_base::sync_with_stdio(false),cin.tie(NULL);  
#define what_is(x)     cerr << #x << " is " << x << endl;
///*....Debugger....*///
#define error(args...) { string _s = #args; replace(_s.begin(), _s.end(), ',', ' '); stringstream _ss(_s); istream_iterator<string> _it(_ss); err(_it, args); }
void err(istream_iterator<string> it) {cout << endl;}
template<typename T, typename... Args> void err(istream_iterator<string> it, T a, Args... args) {
  cerr << *it << " = " << a << ", ";
  err(++it, args...);
}
///*....Input....*///
template <typename T> inline void Int(T &n) {
  n = 0; int f = 1; register int ch = getchar();
  for (; !isdigit(ch); ch = getchar()) if (ch == '-') f = -1;
  for (; isdigit(ch); ch = getchar()) n = (n << 3) + (n << 1) + ch - '0';
  n = n * f;
}
 
template <typename T, typename TT> inline void Int(T &n, TT &m) { Int(n); Int(m); }
template <typename T, typename TT, typename TTT> inline void Int(T &n, TT &m, TTT &l) { Int(n, m); Int(l);}
double ind(){double x; scanf("%lf",&x);return x;}

///*....Bitmask....*///
int set_1(int n,int pos){return n = (n | (1<<pos));}
int reset_0(int n,int pos){return n= n & ~(1<<pos);}
bool check_bit(int n,int pos){return n = n & (1<<pos);}

int dx[8]= {1,0,-1,0,-1,-1,1,1};
int dy[8]= {0,1,0,-1,-1,1,-1,1};

///*....Constraints....*///
const int N = (int) 1e6 + 5;
const int M = (int) 1e9 + 7;
const double pi=2* acos(0.0);
const double eps=1e-9;


int main()
{
    int t=1,te=0;
    //Int(t);
    while(t--){
      string s;
      cin>>s;

      for(int i=0;i<3;++i){
        cout<<s[i];
      }

        //printf("Case %d: ",++te);
    }
    return 0;
}






Measured memory_bytes: 3596