akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <cmath>
#include <iomanip>
#include <stack>
#include <queue>
#include <numeric>
#include <map>
#include <unordered_map>
#include <set>
#define rep(i,n) for(int i=0;i<(n);i++)
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
#define pb push_back
#define mod 1000000007
using ll = long long;
using namespace std;

int main(){
  int N,X;
  cin >> N >> X;
  vector<int> M(N);
  int sum = 0;
  rep(i,N) {
    cin >> M[i];
    sum += M[i];
  }
  X -= sum;
  sort(all(M));
  cout << N + X/M[0] << endl;
  return 0;
}


Measured memory_bytes: 256
import java.util.*;

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

        char[] a = sc.next().toCharArray();
        char[] b = sc.next().toCharArray();
        char[] c = sc.next().toCharArray();

        int al = a.length;
        int bl = b.length;
        int cl = c.length;

        Set<Integer> ab = new HashSet<>();
        Set<Integer> bc = new HashSet<>();
        Set<Integer> ac = new HashSet<>();

        OUTER: for(int os = -bl-cl; os <= al+cl; os++) {
            if(os <= -bl || os >= al ) {
                ab.add(os);
                continue;
            }
            for(int i=0; i<bl; i++) {
                int ai = os + i;
                if(0<=ai && ai<al && b[i] != '?' && a[ai] != '?' && b[i] != a[ai]) continue OUTER;
            }
            ab.add(os);
        }
        OUTER: for(int os = -bl-cl; os <= al+bl; os++) {
            if(os <= -cl || os >= al ) {
                ac.add(os);
                continue;
            }
            for(int i=0; i<cl; i++) {
                int ai = os + i;
                if(0<=ai && ai<al && c[i] != '?' && a[ai] != '?' && c[i] != a[ai]) continue OUTER;
            }
            ac.add(os);
        }
        OUTER: for(int os = -al-cl; os <= bl+cl; os++) {
            if(os <= -cl || os >= bl ) {
                bc.add(os);
                continue;
            }
            for(int i=0; i<cl; i++) {
                int bi = os + i;
                if(0<=bi && bi<bl && c[i] != '?' && b[bi] != '?' && c[i] != b[bi]) continue OUTER;
            }
            bc.add(os);
        }

        int min = 10000;
        for(Integer abo : ab) {
            for(Integer bco : bc) {
                int aco = abo + bco;
                if(ac.contains(aco)) {
                    int left = Math.min(0, Math.min(abo, aco));
                    int right = Math.max(al, Math.max(abo + bl, aco + cl));
                    min = Math.min(min, right - left);
                }
            }
        }
        System.out.println(min);
    }
}

Measured memory_bytes: 155196
#include <bits/stdc++.h>
using namespace std;
int n,m,a,b,c;
string s,t;
int ct[60005];
int main(){
    cin >> n;
    for (int i = 1; i <= 100; i++){
        for (int j = 1; j <= 100; j++){
            for (int k = 1; k <= 100; k++){
                ct[i*i+i*j+i*k+j*j+j*k+k*k]++;
            }
        }
    }
    for (int i = 1; i <= n; i++){
        cout << ct[i] << endl;
    }

}


Measured memory_bytes: 3820
#include<iostream>
using namespace std;
int main(){
    int n,m;
    cin >> n >> m;
    int k,a,num[m+5]={};
    for(int i=0;i < n;i++){
        cin >> k;
        for(int j=0;j<k;j++){
            cin >> a;
            num[--a]++;
        }
    }
   
    int ans = 0;
    for(int i=0;i<m;i++){
        if(num[i]==n)ans++;
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define INF 1e18
#define Rep(i, a, n) for (int i = (a); i < (n); i++)
#define rep(i, n) Rep(i, 0, n)
#define all(a) (a).begin(), (a).end()
#define MAX 1000
#define ll long long
using namespace std;
const int mod = 1000000007;
char c[MAX][MAX];
int step[MAX][MAX];
int H,W,N; 
int vy[4] ={1,-1,0,0}, vx[4] = {0,0,-1,1}; //up,down,left,right 

signed main(){
    ll x; cin >> x;
    ll f = 100;
    ll ans=0;
    while(x > f){
        ans++;
        f = f * 1.01;
    }
    cout << ans << endl;
    return 0;
}

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

using namespace std;

int main() {
    int a, b, c;
    cin >> a >> b >> c;
    vector<int> vec = {a, b, c};
    sort(vec.begin(), vec.end());
    int cost = 0;
    cost = vec.at(1) - vec.at(0) + vec.at(2) - vec.at(1);
    cout << cost << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
//#include <tr1/unordered_map>
#define debug(x) (cout << "#x = " << (x) << endl)
#define lowbit(x) (x & -x)
#define Set(x, i) memset(x, i, sizeof x)
#define R register
#define For( i, j, k ) for(R int i = (j); i <= (k); ++i)
#define Rep( i, j, k ) for(R int i = (j); i >= (k); --i)
#define Cross( i, j, k ) for(R int i = (j); i; i = (k))
typedef long long ll;
using namespace std;
const ll N = 100011;
const ll INF = 5e16;

namespace IO {

	#define dd ch = getchar()
	inline ll read() {
		ll x = 0; bool f = 0; char dd;
		for (; !isdigit (ch); dd) f ^= (ch == '-');
		for (; isdigit (ch); dd)  x = x * 10 + (ch ^ 48);
		return f? -x: x;
	}
	#undef dd

	inline void write ( ll x ) {
		if (x < 0) putchar ('-'), x = -x;
		if (x > 9) write (x / 10); putchar (x % 10 | 48);
	}

	inline void wrn ( ll x ) { write(x); putchar (' '); }

	inline void wln ( ll x ) { write(x); putchar ('\n'); }

	inline void wlnn ( ll x, ll y ) { wrn(x); wln (y); }

}

using namespace IO;

namespace Cesare {
	
	ll n, lst = -11, a[N], b[N], c[N];
	
	int main() {
		n = read();
		ll Ans = 0;
		For ( i, 1, n ) a[i] = read();
		For ( i, 1, n ) b[i] = read();
		For ( i, 1, n - 1 ) c[i] = read();
		For ( i, 1, n ) {
			Ans += b[i];
			if (lst + 1 == a[i]) Ans += c[lst]; 
			lst = a[i];
		}
		return wln(Ans), 0;
	}
	
}

int main()
{
	return Cesare :: main();
}

/*

*/



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

using namespace std;


typedef long long ll;

const int N = 1e5+20;
const int inf = 1e9;

ll n, k, l, a[N], dp[N];

int main() {

    ios::sync_with_stdio(0);
    cin.tie(0);

    #ifdef LOCAL
        freopen("input.txt", "r", stdin);
        freopen("output.txt", "w", stdout);
    #endif // LOCAL

    cin>>n;

    for(int i=1; i<=n; ++i)
        cin>>a[i];

    dp[1] = 0;
    dp[2] = abs(a[1]-a[2]);

    for(int i=3; i<=n; ++i){
        dp[i]= min(dp[i-1]+abs(a[i]-a[i-1]),dp[i-2]+abs(a[i]-a[i-2]));
    }

    cout<<dp[n]<<endl;

    return 0;
}


Measured memory_bytes: 1792
S = list(input())
opt = ['-', '+']
for i in range(8):
    now = S[0]
    for j in range(3):
        if i >> j & 1:
            now += opt[1]
        else:
            now += opt[0]
        now += S[j + 1]
    if eval(now) == 7:
        print(now + "=7")
        exit()



Measured memory_bytes: 3060
#include <stdio.h>

int main(void) {
	double r;
	//数値を入力
	scanf("%lf", &r);
	//結果を出力
	printf("%lf %lf\n", r * r * 3.14159265359, 2 * 3.14159265359 * r);
	return 0;
}

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

int main() {
  int n;

  cin >> n;

  vector<vector<long>> a(n, vector<long>(3));
  vector<vector<long>> ans(n + 1, vector<long>(3));

  for (int i = 0; i < n; i++) {
    cin >> a[i][0] >> a[i][1] >> a[i][2];
  }

  for (int i = 0; i < n; i++) {
    for (int j = 0; j < 3; j++) {
      for (int k = 0; k < 3; k++) {
        if (j == k) continue;
        ans[i + 1][k] = max(ans[i + 1][k], ans[i][j] + a[i][k]);
      }
    }
  }

  cout << max(max(ans[n][0], ans[n][1]), ans[n][2]);

  return 0;
}

Measured memory_bytes: 11136
/*
Author: Babin Dutta
*/

#include <bits/stdc++.h>
using namespace std;
#define mod 1000000007
#define ll long long int
#define pb push_back
#define mp make_pair
#define boost ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
#define f(i,n) for(int i=0;i<n;i++)
#define ff(i,a,b) for(int i=a;i<=b;i++)
#define all(v) v.begin(),v.end()
#define endl "\n"

vector<int> ad[100001];
int dp[100001], vis[100001];

void dfs(int node){
	vis[node] = 1;
	for(int child : ad[node]){
		if(!vis[child]) dfs(child);
		dp[node] = max(dp[node], 1+dp[child]);
	}
}

void solve(){
	int n,m,u,v; cin>>n>>m;
	f(i,m) cin>>u>>v, ad[u].pb(v);
	ff(i,1,n){
		if(!vis[i]) dfs(i);
	}
	int ans=0;
	ff(i,1,n) ans = max(ans, dp[i]);
	cout<<ans<<endl;
}

int main(){
	#ifdef JUDGE
    freopen("input.txt", "rt", stdin);
    freopen("output.txt", "wt", stdout);
    #endif
	boost;
	int t=1; //cin>>t;
	for(int i=1;i<=t;i++) solve();
	return 0;
}

Measured memory_bytes: 8576
N = int(input())
ans = 1
max_count = 0
n = 2
while (n <= N):
  k = n
  count = 0
  while k%2 == 0:
    k /= 2
    count += 1
  if count > max_count:
    ans = n
    max_count = count
  n += 1
print(ans)


Measured memory_bytes: 2940
import sys
def input(): return sys.stdin.readline().strip()

def resolve():
    n,a,b=map(int, input().split())
    ans=0
    for i in range(1,n+1):
        cnt=0
        if a<=sum([int(j) for j in str(i)])<=b:
            ans+=i
    print(ans)
resolve()


Measured memory_bytes: 2940
import java.util.Scanner;

class Main{
	public static void main(String[] args) {
		Scanner sc=new Scanner(System.in);
		long wa=0;
		int kosu=sc.nextInt();
		for(int i=0; i<kosu; i++) {
			wa+=sc.nextInt()-1;
		}
		System.out.println(wa);
	}
}

Measured memory_bytes: 24812
import java.util.Scanner;


public class Main{

    public static void main(String []args){
       Scanner scan = new Scanner(System.in);
       int A = scan.nextInt();
       int B = scan.nextInt();
       int K = scan.nextInt();

        int count = 0;
        int ans = 0;

        int N = 0;
        
        for(int i=1; i<=Math.min(A,B); i++){
            if(A%i ==0 && B%i==0){
                N += 1;
            }
        }

        K = N-K+1;

        for(int i=1; count<K; i++){
            if(A%i ==0 && B%i==0){
                ans = i;
                count += 1;
            }
        }
        System.out.println(ans);
   
       scan.close();
    }
}

Measured memory_bytes: 22612
#include <iostream>
#include <string>
#include <cstring>
#include <cmath>
#include <cstdio>
#include <algorithm>
using namespace std;
#define int long long
signed main(){
    string a,b,c;
    cin>>a>>b>>c;
    int turn=0;
    int count[3]={};
    while(1){
            if(turn==0){
                if(count[0]==a.size()){
                    cout<<'A'<<endl;
                    break;
                }
                turn=a[count[0]]-'a';
                count[0]++;
            }else if(turn==1){
                if(count[1]==b.size()){
                    cout<<'B'<<endl;
                    break;
                }
                turn=b[count[1]]-'a';
                count[1]++;
            }else{
                if(count[2]==c.size()){
                    cout<<'C'<<endl;
                    break;
                }
                turn=c[count[2]]-'a';
                count[2]++;
            }
    }
    return 0;
}





Measured memory_bytes: 256
t[3600];w,h,c,z;f(x,i){if(t[x]-->0)for(;i;f(x+=";;x>x:="[--i]-60,8));}main(i){for(;scanf("%d%d",&w,&h)*h;printf("%d\n",c)){for(i=++h;--i;)for(c=w;c;)scanf("%d",i*60+c--+t);for(;!i?i=w,--h:1;f(z,8))c+=t[z=h*60+i--]>0;}}

Measured memory_bytes: 0
#include<bits/stdc++.h>
#define _LIBCPP_DEBUG 0
using namespace std;
typedef long long int ll;
ll MOD = 1e9 + 7;
int INF = 1 << 20;

int main(void){

    string S; cin>>S;
    int N = S.length();
    string revS = S;
    reverse(revS.begin(),revS.end());
    if(S != revS){
        cout<<"No"<<endl;
        return 0;
    }

    string S2;
    S2 = S.substr(0,(N-1)/2);
    string revS2 = S2;
    reverse(revS2.begin(), revS2.end());
    if(S2 != revS2){
        cout<<"No"<<endl;
        return 0;
    }

    string S3;
    S3 = S.substr((N+3)/2-1);
    string revS3 = S3;
    reverse(revS3.begin(), revS3.end());
    if(S3 != revS3){
        cout<<"No"<<endl;
        return 0;
    }


    cout<<"Yes"<<endl;
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int n;
std::vector<int> vec;
int c = 0;

int main() {
    cin >> n;
    vec.assign(n, 0);
    for (int i = 0; i < n; i++) {
        std::cin >> vec[i];
    }
    for (int j = 1; j < n; j++) {
        if (vec[j-1] == -1) {
            continue;
        }
        if (vec[j] == vec[j-1]) {
            vec[j] = -1;
            c++;
        }
    }
    std::cout << c << std::endl;
}


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

long long s[200005];
long long cnt[10005];

int main() {
    //freopen("input.txt", "r", stdin);
    ios::sync_with_stdio(0);
    cin.tie(NULL);
    
    int n, p;
    cin >> n >> p;
    string str;
    cin >> str;

    long long res = 0;
    if (p != 2 && p != 5) {
        int base = 1;
        for (int i = n - 1; i >= 0; i--) {
            s[i] = s[i + 1] + base * (str[i] - '0');
            s[i] %= p;
            cnt[s[i]]++;

            base *= 10;
            base %= p;
        }

        cnt[s[n]]++;
        for (int i = 0; i < p; i++) {
            res += cnt[i] * (cnt[i] - 1) / 2;
        }
        cout << res;
    }
    else {
        for (int i = n - 1; i >= 0; i--) {
            if ((str[i] - '0') % p == 0) {
                res += i + 1;
            }
        }
        cout << res;
    }
    return 0;
}

Measured memory_bytes: 5384
#include <bits/stdc++.h>
  
using namespace std;
 
#define ll long long
#define uint unsigned int
#define ull  unsigned long long
#define pb push_back
#define mk make_pair
#define ins insert
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(),(x).rend()
#define X first
#define Y second
#define umap unordered_map
#define speed() ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
#define setvalue(d,s,e,n) for(int qwe = s; qwe < e; ++qwe) d[qwe] = n
#define mset multiset
#define pqueue priority_queue
   
        
const int  N = 2e5 + 314;
const int INF = 1e9;
const double PI = acos(-1);
const int MOD = 1e9 + 7;
const double eps = 1e-9;
const long long LINF = 1e18 + 3141;
int n;
ll a[N];
map <int,int> mp;
void solve(){
    cin >> n;
    ll sum = 0;
    for(int i = 1; i <= n; ++i){
        cin >> a[i];
        sum += a[i];
        mp[a[i]] ++;
    }
    int q;
    cin >> q;
    while(q --) {
        int b, c;
        cin >> b >> c;
        int tmp = mp[b];
        mp[b] = 0;
        mp[c] += tmp;
        sum -= 1ll * b * tmp;
        sum += 1ll * tmp * c;
        cout << sum << "\n";
    }
    
    


}
 
int main(){
    speed();
    int t = 1;
    // cin >> t;
    while(t--)solve();
}

Measured memory_bytes: 8816
package main

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

func main() {
	io, flsuh := NewIO()
	defer flsuh()
	n, m := io.ScanInt(), io.ScanInt()
	nums := io.Scan2DInts(m, 2)
	ans := make([]int, n)
	for i := 0; i < n; i++ {
		ans[i] = -1
	}
	for _, num := range nums {
		digit, to := num[0]-1, num[1]
		if ans[digit] != -1 && to != ans[digit] {
			io.Println(-1)
			return
		}
		if n > 1 && digit == 0 && to == 0 {
			io.Println(-1)
			return
		}
		ans[digit] = to
	}
	for i := 0; i < n; i++ {
		if i == 0 && ans[0] == -1 && n > 1 {
			ans[0] = 1
			continue
		}
		if ans[i] == -1 {
			ans[i] = 0
		}
	}
	io.Println(strings.Trim(strings.Join(strings.Fields(fmt.Sprint(ans)), ""), "[]"))
}

type IO struct {
	scanner *bufio.Scanner
	writer  *bufio.Writer
}

func NewIO() (*IO, func()) {
	io := &IO{
		scanner: newScanner(),
		writer:  newWriter(),
	}
	return io, func() { io.writer.Flush() }
}

func newScanner() *bufio.Scanner {
	s := bufio.NewScanner(os.Stdin)
	s.Buffer(make([]byte, 1000005), 1000005)
	s.Split(bufio.ScanWords)
	return s
}

func newWriter() *bufio.Writer {
	return bufio.NewWriter(os.Stdout)
}

func (io *IO) ScanBytes() []byte {
	if !io.scanner.Scan() {
		panic("scan string failed")
	}
	return io.scanner.Bytes()
}

func (io *IO) ScanString() string {
	if !io.scanner.Scan() {
		panic("scan string failed")
	}
	return io.scanner.Text()
}

func (io *IO) ScanStrings(n int) []string {
	strs := make([]string, n)
	for i := 0; i < n; i++ {
		strs[i] = io.ScanString()
	}
	return strs
}

func (io *IO) Scan2DStrings(y, x int) [][]string {
	strings := make([][]string, y)
	for i := 0; i < y; i++ {
		strings[i] = io.ScanStrings(x)
	}
	return strings
}

func (io *IO) Scan2DGraph(y int) [][]string {
	strs := make([][]string, y)
	for i := 0; i < y; i++ {
		strs[i] = strings.Split(io.ScanString(), "")
	}
	return strs
}

func (io *IO) ScanInt() int {
	return int(io.ScanInt64())
}

func (io *IO) ScanInts(n int) []int {
	ints := make([]int, n)
	for i := 0; i < n; i++ {
		ints[i] = io.ScanInt()
	}
	return ints
}

func (io *IO) Scan2DInts(y, x int) [][]int {
	ints := make([][]int, y)
	for i := 0; i < y; i++ {
		ints[i] = io.ScanInts(x)
	}
	return ints
}

func (io *IO) ScanInt64() int64 {
	i, err := strconv.ParseInt(io.ScanString(), 10, 64)
	if err != nil {
		panic(err)
	}
	return i
}

func (io *IO) ScanFloat64() float64 {
	i, _ := strconv.ParseFloat(io.ScanString(), 64)
	return i
}

func (io *IO) ScanFloat64s(n int) []float64 {
	floats := make([]float64, n)
	for i := 0; i < n; i++ {
		floats[i] = io.ScanFloat64()
	}
	return floats
}

func (io *IO) Println(a ...interface{}) {
	fmt.Fprintln(io.writer, a...)
}


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

using namespace std;

#define sim template <class c
#define ris return *this
#define dor > debug &operator<<
#define eni(x)                                                                        \
	sim > typename enable_if<sizeof dud<c>(0) x 1, debug &>::type operator<<(c i) \
	{
sim > struct rge
{
	c b, e;
};
sim > rge<c> range(c i, c j) { return rge<c>{i, j}; }
sim > auto dud(c *x) -> decltype(cerr << *x, 0);
sim > char dud(...);
struct debug
{
#ifdef LOCAL
	~debug()
	{
		cerr << endl;
	}
	eni(!=) cerr << boolalpha << i;
	ris;
} eni(==) ris << range(begin(i), end(i));
}
sim, class b dor(pair<b, c> d)
{
	ris << "(" << d.first << ", " << d.second << ")";
}
sim dor(rge<c> d)
{
	*this << "[";
	for (auto it = d.b; it != d.e; ++it)
		*this << ", " + 2 * (it == d.b) << *it;
	ris << "]";
}
#else
	sim dor(const c &)
	{
		ris;
	}
#endif
}
;
#define imie(...) " [" << #__VA_ARGS__ ": " << (__VA_ARGS__) << "] "

#define forn(i, n) for (ll i = 0; i < int(n); i++)
#define rfor(n, i) for (ll i = (n - 1); i >= 0; --i)
#define all(V) V.begin(), V.end()
#define rall(V) V.rbegin(), V.rend()
#define len(V) (int)V.size()
#define ll long long
#define ld long double
#define ff first
#define ss second
#define pb push_back
#define mp make_pair
#define endl '\n'
#define M_PI 3.14159265358979323846
#define EPS 1e-7

int cnt = 0;


void solve()
{
	ll n, k; cin >> n >> k;
	vector<ll> a(n);
	forn(i, n) cin >> a[i];
	sort(all(a));
	ll mn = INT_MAX;
	for (int i = 0; i <= n - k; ++i)
	{
		mn = min(mn, a[i + k - 1] - a[i]);
	}
	cout << mn;
}

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


Measured memory_bytes: 3976
#include<bits/stdc++.h>
using namespace std;
int main()
{
	string str1,str2;
  	cin>>str1>>str2;
	int n=str1.size(),c=0;
	for(int i=0;i<n;i++)
    {
      if(str1[i]==str2[i])
      {
        c++;
      }
    }
  cout<<c;
  return 0;
}

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

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

#define FOR(i, n, m) for (ll(i) = (m); (i) < (n); ++(i))
#define REP(i, n) FOR(i, n, 0)
#define OF64 std::setprecision(10)

const ll MOD = 1000000007;
const ll INF = (ll)1e15;

ll X[60], Y[60];

int main()
{
    int N, K;
    cin >> N >> K;
    REP(i, N)
    {
        cin >> X[i] >> Y[i];
    }

    ll min = (1e18 * 5);
    REP(fx, N)
    {
        FOR(lx, N, fx)
        {
            REP(fy, N)
            {
                FOR(ly, N, fy)
                {
                    ll maxx = std::max(X[fx], X[lx]);
                    ll minx = std::min(X[fx], X[lx]);
                    ll maxy = std::max(Y[fy], Y[ly]);
                    ll miny = std::min(Y[fy], Y[ly]);
                    int n = 0;
                    REP(i, N)
                    {
                        ll x = X[i], y = Y[i];
                        if (x >= minx && x <= maxx && y >= miny && y <= maxy)
                            n++;
                    }
                    if (n < K)
                        continue;
                    //! G[f]とG[l]で四角形を作る
                    min = std::min(min, (maxx - minx) * (maxy - miny));
                }
            }
        }
    }
    cout << min << endl;
    return 0;
}

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

int main () {
  int a,b;
  cin >> a >> b;

  if (b>a) swap(a,b);

  if ((a+b)%2==1) cout << "IMPOSSIBLE" << endl;
  else cout << (a+b)/2 << endl;

  return 0;
}


Measured memory_bytes: 256
n = int(input())
A = [int(x) for x in input().split()]
sumA = sum(A)
counter = [0]*(10**5+1)
for i in range(n):
    counter[A[i]] += 1

q = int(input())

queue = [list(map(int,input().split())) for i in range(q)]

for b,c in queue:    
    b_cnt = counter[b]
    sumA -= (b*b_cnt)
    counter[b] = 0
    sumA += c*(b_cnt)
    counter[c] += b_cnt
    print(sumA)
    

Measured memory_bytes: 32740
#include<bits/stdc++.h>
using namespace std;
#define rep(i,j,n) for(int i=(int)(j);i<(int)(n);i++)
#define REP(i,j,n) for(int i=(int)(j);i<=(int)(n);i++)
#define MOD 1000000007
#define int long long
#define ALL(a) (a).begin(),(a).end()
#define vi vector<int>
#define vii vector<vi>
#define pii pair<int,int>
#define priq priority_queue<int>
#define disup(A,key) distance(A.begin(),upper_bound(ALL(A),(int)(key)))
#define dislow(A,key) distance(A.begin(),lower_bound(ALL(A),(int)(key)))
#define tii tuple<int,int,int>
#define Priq priority_queue<int,vi,greater<int>>
#define pb push_back
#define mp make_pair
#define INF (1ll<<60)
signed main(){
    int N; cin>>N;
    vii A(N,vi(N));
    rep(i,0,N){
        rep(j,0,N) cin>>A[i][j];
    }
    vi dp((1ll<<N));
    dp[0]=1;
    rep(i,0,N){
        rep(j,0,(1ll<<N)){
            if(__builtin_popcount(j)==i){
                rep(k,0,N){
                    if(A[i][k]==1){
                        int X=j|(1ll<<k);
                        if(X!=j){
                            dp[X]+=dp[j];
                            dp[X]%=MOD;
                        }
                    }
                }
            }
        }
    }
    cout<<dp[(1ll<<N)-1]<<endl;
}

Measured memory_bytes: 16640
def main():
    N = int(input())
    p = [list(map(int, input().split())) for _ in range(N)]
    for i in range(N):
        if p[i][2] > 0:
            break
    x0, y0, h0 = p[i]
    for cx in range(101):
        for cy in range(101):
            H = h0 + abs(x0 - cx) + abs(y0 - cy)
            for x, y, h in p:
                if h != max(H - abs(x - cx) - abs(y - cy), 0):
                    break
            else:
                print(cx, cy, H)
                exit(0)


if __name__ == '__main__':
    main()

Measured memory_bytes: 3064
/**
 *    author:  Daredevil666
 *    institution: IIT Patna
**/
#define _USE_MATH_DEFINES
#include<bits/stdc++.h>
#define nl cout<<"\n";
#define ll long long int
#define IOS  ios::sync_with_stdio(false);cin.tie(0);
using namespace std;
ll mod=1e9+7;
int main()
{
IOS

    vector<int> v(5);
    for(int i=0;i<5;i++)
    {
        cin>>v[i];
        if(v[i]==0)
        {
            cout<<i+1;
        }
    }

return 0;
}


Measured memory_bytes: 3660
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#include<math.h>
#define ll long long
#define mod 1000000007

ll n,k;
ll a[212345];
char z;

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(){
  scanf("%lld%lld",&n,&k);

  
  for(int i=0;i<n;i++){
    scanf("%lld",&a[i]);}
  
  
  sortup(a,n);
  
  ll right=n-1,left=0;
  ll count=k;
  ll ans=1;
  if(a[right]>=0 || k%2==0){
    //printf("right\n");
  while(count>0){
    if(count>=2){
      if(a[right]*a[right-1]>a[left]*a[left+1] ){
	ans = ans*a[right]%mod*a[right-1]%mod;
	right-=2;}
      else{
	ans = a[left]*a[left+1]%mod*ans%mod;
	left+=2;}
      count-=2;}
    else{
      ans = (ans*a[right]+mod)%mod;
      right--;
      count--;}
  }
  }
  else{
    //printf("left\n");
    while(count>0){
      if(count>=2){
	ans = a[right]*a[right-1]%mod*ans%mod;
	right-=2;
	count-=2;}
      else{
	ans*=a[right];
	right--;
	ans=(ans+mod)%mod;
	count--;}
    }}
  ans = (ans+mod)%mod;
    
  printf("%lld\n",ans);
  
  return 0;
}


Measured memory_bytes: 4680
#include <bits/stdc++.h>
using namespace std;
const int N = 2000 + 10;
int n, x, mn[N][N];
int main() {
    long long ans = 0;
    scanf("%d%d", &n, &x);
    for (int i = 1; i <= n; i++) {
        scanf("%d", &mn[i][i]);
        ans = ans + mn[i][i];
    }
    for (int i = 1; i <= n; i++) {
        for (int j = i + 1; j <= n; j++) {
            mn[i][j] = min(mn[i][j - 1], mn[j][j]);
        }
    }
    for (int k = 1; k <= n; k++) {
        long long tmp = 1ll * k * x;
        for (int i = 1; i <= n; i++) {
            if (i > k)
                tmp = tmp + mn[i - k][i];
            else
                tmp = tmp + min(mn[1][i], mn[n - k + i][n]);
        }
        ans = min(ans, tmp);
    }
    printf("%lld\n", ans);
    return 0;
}

Measured memory_bytes: 15360
#include<stdio.h>

int main(void){
    int num;
    int count=0;
    int check=0;
    scanf("%d",&num);
    for(int i = 1; i <= 9; i++){
        if(check==1)break;
        for(int j = 1; j <= 9; j++){
            if(i*j==num) {
                printf("Yes\n");
                check = 1;
                break;
            }else{
            count++;
            }
        }
    }
    if(count==81) printf("No\n");
    return 0;
}

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

int main() {
  int n;
  cin >> n;
  vector<int> a(n);
  for(int i=0;i<n;i++){
    cin >> a.at(i);
  }
  sort(a.begin(), a.end());
  int x;
  x = a.at(n-1) - a.at(0);
  cout << x << endl;
}


Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
int main(void){

    int n;
    cin>>n;
    int a[30]={0};
    for(int i=1;i<=n;i++){
        int x,y;
        cin>>x>>y;
        a[x] = y;
    }
    int m=0,M=1;
    for(int i=1;i<=n;i++){
        if(m < a[i]){
            M = i;
            m = a[i];
        }



    }
    cout<<M<<" "<<m<<endl;


    return 0;
}

Measured memory_bytes: 1168
def gcd(x,y):
    if y==0:
        return x
    return gcd(y,x%y)

MOD = 10**9+7
N = int(input())
A = list(map(int,input().split()))
lcm = 1
for i in A:
    lcm = (lcm*i)//gcd(lcm,i)
lcm %= MOD
ans = 0
for i in A:
    ans += lcm*pow(i,MOD-2,MOD)
    ans %= MOD
print(ans)


Measured memory_bytes: 68312
import sys
input = sys.stdin.readline
n,m = [int(i) for i in input().split()]
p = [int(i) for i in input().split()]
p = tuple(p)
chk = [[set(),set()] for i in range(n)]
def find(x):
    if par[x] < 0:
        return x
    else:
        par[x] = find(par[x])
        return par[x]

def unite(x,y):
    x = find(x)
    y = find(y)
    
    if x == y:
        return False
    else:
        if par[x] > par[y]:
            x,y = y,x
        par[x] += par[y]
        par[y] = x
        return True
      
def same(x,y):
    return find(x) == find(y)
  
par = [-1]*n
ans = 0
for i in range(m):
  x,y = [int(i) for i in input().split()]
  unite(x-1,y-1)

for i,pi in enumerate(p):
  if same(i,pi-1):
    ans += 1
    
print(ans)

Measured memory_bytes: 64124
#include <stdio.h>
int main()
{
  int i, j, n, r, q, N, R;
  int d[51], sd[51];
  while(1)
    {
      for ( i = 0; i < 51; i++)
	{
	  d[i] = 0;
	  sd[i] = 0;
	}
      scanf("%d %d", &N, &R);
      if ( N == 0 && R == 0 ) return 0;
      for ( i = 1; i <= N; i++)
	{
	  d[i] = N - i + 1;
	}
      for ( i = 1; i <= R; i++)
	{
	  scanf("%d %d", &n, &r);
	  q = n;
	  for( j = 1; j <= r; j++, n++)
	    {
	      sd[j] = d[n];
	    }
	  for ( j = 0; j < n - 1; j++)
	    {
	      d[q+r-1] = d[q-1];
	      q--;
	    }
	  for( j = 1; j <= r; j++)
	    {
	      d[j] = sd[j];
	    }
	}
      printf("%d\n", d[1]);
    }
  return 0;
}

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

using namespace std;

#define rep(i,m,n) for(int i=m;i<n;i++)

typedef long long ll;

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

 ll n,k;
  cin >> n >> k;
  ll res=0;
  if(k==0) res-=n;
  
  rep(b,1,n+1){
   ll p=n/b;
   ll r=n-p*b;
    res+=p*max(0ll,b-k);
    res+=max(0ll,r-k+1);
  }
  
 cout << res << endl;
  
}


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

typedef vector<int> vi;
#define loop(i,a,b) for(int i=(a); i<int(b);i++)
#define rep(i,b) loop(i,0,b)

int main(){
    int n,m;
    while(cin >>n>>m){
        if(n==0&&m==0)break;
        vector<bool> in(n,true);
        int num=-1;
        for(int i=0;i<n-1;i++){
            rep(j,m){
                num++;
                if(num>=n)num=0;
                if(!in[num]){j--;continue;}
            }
            // cout<<num<<endl;
            in[num]=false;
        }

        // cout << "end" << endl;
        rep(i,n){
            if(in[i]){
                cout << i+1 << endl;
            }   
        }
    }
}

Measured memory_bytes: 1196
#include <iostream>
#include <fstream>
#include <cassert>
#include <string.h>
#include <vector>
#include <map>
#include <stack>

template <typename Container, typename Value>
int partition(Container& container, int p, int r)
{
    // 末尾の要素.
    Value x = container[r];

    // 末尾の要素x以下の値が何個あるか.
    int i = p - 1;

    // 先頭から末尾より1個前までの要素分進める.
    for (int j = p; j < r; ++j)
    {
        if (container[j] <= x) {
            //x以下の値が見つかった時点で､カウンタをインクリメントして交換.
            //xより小さい値を段々と確定させていくイメージ.
            i++;
            Value tmp = container[i];
            container[i] = container[j];
            container[j] = tmp;
        }
    }

    i++;
    Value tmp = container[i];
    container[i] = container[r];
    container[r] = tmp;
    return i;
}

template <typename Container>
Container createContainerFronCin(int cnt)
{
    Container ret;
    ret.reserve(cnt);

    int cur = 0;
    for (int i = 0; i < cnt; ++i) {
        std::cin >> cur;
        ret.push_back(cur);
    }

    return ret;
}

int main()
{
    int n = 0;
    std::cin >> n;
    std::vector<int> vec = createContainerFronCin< std::vector<int> >(n);

    int pos = partition<std::vector<int>, int>(vec, 0, n - 1);
    for (int i = 0; i < n; ++i)
    {
        std::string delim = (i + 1 < n) ? " " : "";
        if (i == pos) {
            std::cout << "[" << vec[i] << "]" << delim;
        } else {
            std::cout << vec[i] << delim;
        }
    }
    std::cout << std::endl;
}



Measured memory_bytes: 3148
#include <bits/stdc++.h>
using namespace std;
typedef long long  ll;
const ll mod =1000000007;
int main(){
    long long x,y;
    cin>>x>>y;
    int count =0;
    while(x<=y){
        x *=2;
        count++;
    }
    cout<<count<<endl;
}

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

/*
code credits : ਜ਼ੈਲਦਾਰ
dashan jot singh
*/
using namespace std;
#define ll long long int
#define fast ios_base::sync_with_stdio(0), cin.tie(NULL), cout.tie(NULL)
#define pb push_back
#define mp make_pair
#define inf LLONG_MAX
#define p pair<ll,ll>
ll arr[100010];
int main(){
	fast;
	ll n,m;
	cin>>n>>m;
	priority_queue<ll> q;
	for(ll i=0;i<n;i++){
		cin>>arr[i];
		q.push(arr[i]);
	}
	while(m--){
		ll xx=q.top();
		q.pop();
		q.push(xx/2);
	}
	ll ans=0;
	while(!q.empty()){
		ll temp=q.top();
		q.pop();
		ans+=temp;
	}
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 1912
#include<iostream>
#include<vector>
#define ll long long
#pragma GCC diagnostic error "-std=c++11"
using namespace std;
const int mxn=100005;
struct vertex{
	int nxt,col;ll dist;
	vertex(){}
	vertex(int _x,int _c,int _d):nxt(_x),col(_c),dist(_d){}
};
struct query{
	int id,x,y,f;
	query(){}
	query(int _i,int _x,int _y,int _f):id(_i),x(_x),y(_y),f(_f){}
};
vector<vertex> g[mxn<<1];
int n,m;
ll ans[mxn],cnt[mxn],dis[mxn],dep[mxn];
vector<query> q[mxn];
int fa[mxn][22];
inline void predfs(int u,int par,ll dp){
	fa[u][0]=par;dep[u]=dp;
	for(vertex v:g[u]){
		if(v.nxt==par) continue;
		predfs(v.nxt,u,dp+1);
	}
}
inline void parinit(){
	for(int j=1;j<=19;++j) for(int i=1;i<=n;++i) fa[i][j]=fa[fa[i][j-1]][j-1];
}
inline int lca(int x,int y){
	if(dep[x]>dep[y]) swap(x,y);
	int step=dep[y]-dep[x],i;
	for(i=19;~i;--i) if(step&1<<i) y=fa[y][i];
	if(x==y) return x;
	for(i=19;~i;--i) if(fa[x][i]!=fa[y][i]) x=fa[x][i],y=fa[y][i];
	return fa[x][0];
}
inline void dfs(int u,int par,ll dist){
	int i;
	for(i=0;i<q[u].size();++i){
		int id=q[u][i].id,a=q[u][i].x,b=q[u][i].y,f=q[u][i].f;
		ans[id]+=1ll*f*(dist-dis[a]+cnt[a]*b);
	}
	for(vertex v:g[u]){
		int vv=v.nxt,c=v.col,ds=v.dist;
		if(vv==par) continue;
		++cnt[c],dis[c]+=ds;
		dfs(vv,u,dist+ds);
		--cnt[c],dis[c]-=ds;
	}
}
int main(){
	ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
	cin>>n>>m;
	int i,j,x,y,col,len,u,v;
	for(i=1;i<n;++i){
		cin>>x>>y>>col>>len;
		g[x].push_back(vertex(y,col,len));
		g[y].push_back(vertex(x,col,len));
	}
	predfs(1,0,0);
	parinit();
	for(i=1;i<=m;++i){
		cin>>x>>y>>u>>v;
		q[u].push_back(query(i,x,y,1));
		q[v].push_back(query(i,x,y,1));
		int l=lca(u,v);
		q[l].push_back(query(i,x,y,-2));
	}
	dfs(1,0,0);
	for(i=1;i<=m;++i) cout<<ans[i]<<endl;
}

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

int main(){

    int k,s;
    int sum = 0;
    scanf("%d", &k);
    scanf("%d", &s);

    for(int x = 0; x <=k; x++){
        for(int y = 0; y <= k; y++){
            if(x+y > s){
                break;
            }
            if (s - x- y <= k){
                sum++;
            }
        }
        if(x > s){
            break;
        }
    }

    printf("%d", sum);


    return 0;
}

Measured memory_bytes: 256
import sys

class Node():
    def __init__(self, key):
        self.key = key
        self.left = None
        self.right = None
        self.parent = None

    def prewalk(self):
        nodeList = [self.key]
        if self.left:
            nodeList += self.left.prewalk()
        if self.right:
            nodeList += self.right.prewalk()
        return nodeList

    def inwalk(self):
        nodeList = []
        if self.left:
            nodeList += self.left.inwalk()
        nodeList += [self.key]
        if self.right:
            nodeList += self.right.inwalk()
        return nodeList

class Tree():
    def __init__(self):
        self.root = None

    def insert(self, key):
        Nz = Node(key)
        Ny = None  # ???????£?
        Nx = self.root
        while Nx:
            Ny = Nx
            if Nz.key < Ny.key:
                Nx = Nx.left
            else:
                Nx = Nx.right
        Nz.parent = Ny
        if Ny == None:
            self.root = Nz
        elif Nz.key < Ny.key:
            Ny.left = Nz
        else:
            Ny.right = Nz

    def find(self, key):
        currentNode = self.root
        while currentNode:
            if key == currentNode.key:
                return True
            else:
                if key < currentNode.key:
                    currentNode = currentNode.left
                else:
                    currentNode = currentNode.right
        return False

    def print(self):
        print('', ' '.join(map(str, self.root.inwalk())))
        print('', ' '.join(map(str, self.root.prewalk())))

tree = Tree()

n = sys.stdin.readline()
for line in sys.stdin:
    if line[0] == 'i':
        tree.insert(int(line.split()[1]))
    elif line[0] == 'f':
        if tree.find(int(line.split()[1])):
            print('yes')
        else:
            print('no')
    else:
        tree.print()

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

int main(){
	int h,w;	cin>>h>>w;
	char tile[h+2][w+2];
	for(int y=0;y<=h+1;y++){
		for(int x=0;x<=w+1;x++){
			tile[y][x]='#';
		}
	}

	for(int y=1;y<=h;y++){
		for(int x=1;x<=w;x++){
			cin>>tile[y][x];
		}
	}

	for(int y=0;y<=h+1;y++){
		for(int x=0;x<=w+1;x++){
			cout<<tile[y][x];
		}
		cout<<endl;
	}



	return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define rep(i,n) for(int i=0;i<n;i++)
#define loop(i,s,n) for(int i=s;i<n;i++)
#define all(in) in.begin(), in.end()
#define rep(i,n) for(int i=0;i<n;i++)
#define loop(i,s,n) for(int i=s;i<n;i++)
#define all(in) in.begin(), in.end()
#define MP make_pair
#define INF (sizeof(int) == 4 ? 1e9:1e18)
#define EPS 0.0000000001
using namespace std;
template<class T, class S> void cmin(T &a, const S &b) { if (a > b)a = b; }
template<class T, class S> void cmax(T &a, const S &b) { if (a < b)a = b; }
template<typename Head, typename Value> auto vectors(const Head &head, const Value &v) { return vector<Value>(head, v); }
template<typename Head, typename... Tail> auto vectors(Head x, Tail... tail) { auto inner = vectors(tail...); return vector<decltype(inner)>(x, inner); }
template<class T> void join(T a){int b=0;for(auto itr :a){if(b++!=0)cout << " "; cout << itr;} }
using ll  = long long;
using ld  = long double;
using pii = pair<int,int>;
using piii = pair<int,pii>;
int W,H;
int dx[]={0,0,1,-1}, dy[]={1,-1,0,0};
bool valid(int x,int y){return (0<=x&&x<W)&&(0<=y&&y<H);}
struct Edge{int to,cap,rev;};
class Dinic{//max flow
public:
    int n;
    vector<vector<Edge> >G;
    vector<int> level,iter;
    Dinic(int size): n(size),G(vector<vector<Edge>>(n)){};
    void add_Edge(int from, int to, int cap){
        //rev は逆辺にアクセスできる
        //e = G[from][index]
        //G[e.to][e.rev].to = from,.rev = index
        Edge q={to,cap,int(G[to].size())};
        G[from].emplace_back(q);
        q={from,0,int(G[from].size()-1)};
        G[to].emplace_back(q);
    }
    void bfs(int s){
        level=vector<int>(n,-1);
        queue<int>q;
        level[s]=0;
        q.push(s);
        while(!q.empty()){
            int v=q.front();q.pop();
            for(auto &e :G[v]){
                if(e.cap>0&&level[e.to]<0){
                    level[e.to]=level[v]+1;
                    q.push(e.to);
                }
            }
        }
    }
    int dfs(int v,int t, int f) {
        if(v==t)return f;
        for(int &i=iter[v];i<G[v].size();i++){
            Edge &e=G[v][i];
            if(level[v]>=level[e.to]||e.cap<=0) continue;
            int d =dfs(e.to,t,min(f,e.cap));
            if(d>0){
                e.cap-=d;
                G[e.to][e.rev].cap+=d;
                return d;
            }
        }
        return 0;
    }
    int max_flow(int s,int t) {//from s to t,ford_fulkerson
        int flow=0;
        while(1){
            bfs(s);
            if(level[t]<0)return flow;
            iter=vector<int>(n);
            int f;
            while((f=dfs(s,t,INF))>0)flow+=f;
        }
    }
};
signed main(){
    int v,e;
    cin>>v>>e;
    Dinic yebi(v+1);
    rep(i,e){
        int a,b,c;cin>>a>>b>>c;
        yebi.add_Edge(a,b,c);
    }
    cout<<yebi.max_flow(0, v-1)<<endl;
}



Measured memory_bytes: 3168
#include<bits/stdc++.h>
#define rep(i,a,b) for (int i=(a); i<=(b); i++)
#define per(i,a,b) for (int i=(a); i>=(b); i--)
using namespace std;

const int maxn = 200005;
int a[maxn], n, K, p, det;
char s[maxn];

int main() {
	scanf("%d%d", &n, &K);
	scanf("%s", s + 1);
	rep (i, 1, n) a[i] = (s[i] == 'A');
	p = 1;
	while (K && p <= n) {
		if ((a[p] ^ det) == 1) a[p] ^= 1;
		else det ^= 1, p++;
		K--;
	}
	if (!K) {
		rep (i, p, n)
			if (a[i] ^ det) putchar('A');
			else putchar('B');
		rep (i, 1, p - 1)
			if (a[i] ^ det) putchar('A');
			else putchar('B');
		return 0;
	}
	rep (i, 1, n)
		if (i == 1 && (n & 1)) {
			if (K & 1) putchar('B');
			else putchar('A');
		}
		else if ((i & 1) ^ (n & 1)) putchar('B');
		else putchar('A');
	return 0;
}

Measured memory_bytes: 1408
#include <iostream>
#include <cmath>
#include <numeric>
#include <algorithm>
#include <deque>
#include <vector>
#include <unordered_map>
#include <unordered_set>
#include <set>
#include <iomanip>
#include <map>
#include <stack>
#include <queue>
#include <functional>
#include <climits>
#include <numeric>
#include <bitset>
#include <random>
#include <tuple>
#include <initializer_list>
#include <fstream>
#include <cctype>
#include <string>
#include <cfloat>
#include <array>


int main() {
	constexpr int mod = 2019;
	std::string str; std::cin >> str;
	std::vector<int> num(str.size());
	int d = 1;
	for (int i = str.size() - 1; i >= 0; --i) {
		num[i] = (str[i] - '0') * d % mod;
		if (i + 1 < str.size()) num[i] = (num[i] + num[i + 1]) % mod;
		d = (d * 10) % mod;
	}
	std::vector<long long int> count(2019, 0);
	for (const auto n : num) count[n]++;
	count[0]++;
	long long int result{ 0 };
	for (const auto n : count) {
		result += n * (n - 1) / 2;
	}
	std::cout << result << std::endl;
}

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

int main(){
    ll X;
    cin >> X;
    int ans = 0;
    rep(i,100000){
        ans += i;
        if (ans >= X){
            cout << i << endl;
            break;
        }
    }
}


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

#define req(i,j) for(int i=0;i<j;i++)

int n,m;

int coin[20];

int dp[50001][21];

int rec(int i,int j){

  if(dp[i][j] >= 0){
    return dp[i][j];
  }

  if(j == m){
    return dp[i][j] = 50001;
  }

  if(i == 0){
    return dp[i][j] = 0;
  }

  if(coin[j] > i){
    return dp[i][j] = rec(i,j+1);
  }

  int rec1 = rec(i,j+1);
  int rec2 = rec(i-coin[j],j) + 1;

  return  dp[i][j] = min(rec1,rec2);

}

int main(){

    cin >> n >> m;

    req(i,m){
      cin >> coin[i];
    }

    req(i,n+1){
      req(j,m+1){
        dp[i][j] = -1;
      }
    }

    cout << rec(n,0) << endl;

    return 0;
}

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

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

    auto ans = convolution(a, b);
    for (auto p : ans) cout << p << " ";
    cout << "\n";
    return 0;
}


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

int main(){
    int A, B, C, X, ans=0;
    cin >> A >> B >> C >> X;
    for(int i = 0; i <= A; i++){
        for(int j = 0; j <= B; j++){
            for(int k = 0; k <= C; k++){
                int m = i * 500 + j * 100 + k * 50;
                if(m == X) ans++;
            }
        }
    }
    cout << ans << endl;
    return 0;
}


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

int abs(int i, int j) {
  if (i - j > 0) {
    return i - j;
  } else {
    return j - i;
  }
}
int main() {
  int N, W;
  cin >> N >> W;
  vector<ll> dp(W + 1);
  rep(i, N) {
    int weight, value;
    cin >> weight >> value;
    for (int j = W - weight; j >= 0; --j) {
      dp.at(j + weight) = max(dp.at(j + weight), dp.at(j) + value);
    }
  }
  cout << dp.at(W) << endl;
}


Measured memory_bytes: 1024
// AOJ 2330 (http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=2330)
#include<iostream>
#include<cmath>

int main()
{
	int N;
	std::cin >> N;

	std::cout << (int)ceil(log(N)/log(3.0)) << std::endl;

	return 0;
}

Measured memory_bytes: 1204
#include<iostream>
#include<cstdio>
#include<cmath>
#include<vector>
#include<queue>
#include<map>
#include<algorithm>
#include<set>
#include<complex>
#include<string>
#include<cstring>
using namespace std;
#define rep2(x,from,to) for(long long x=(from);(x)<(to);(x)++)
#define rep(x,to) rep2(x,0,to)
#define INF 100000000
#define debug(x) cout<<#x<<": "<<x<<endl

#define all(x) x.begin(),x.end()
typedef pair<long long,long long> P;
typedef pair<long long,P> PP;
long long n;
long long ans;
long long k;
long long a[1001];
int main()
{
	cin>>n;
	rep2(i,1,n+1)
	{
		k=i;
		rep2(j,2,i+1)
		{
			if(k==1)break;
			while(k%j==0)
			{
				a[j]++;
				k/=j;
			}
		}
	}
	ans=1;
	rep2(i,2,n+1)
	{
		ans*=(a[i]+1);
		ans%=1000000007;
	}
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 764
import java.util.Scanner;

public class Main {
	public static void main(String[]args) {

		Scanner scan = new Scanner(System.in);
		String s = scan.next();
		scan.close();
		long result = 0;
		// 各数字の間の数
		int n = s.length() - 1;

		String[] sArray = s.split("");
		int[] sIntArray = new int[sArray.length];
		for(int i = 0; i < sArray.length; i++) {
			sIntArray[i] = Integer.valueOf(sArray[i]);
		}
		long temp = 0;
		// {0,1 ・・・, n - 1}の部分集合の全探索
		for(int bit = 0; bit < (1 << n); bit++) {
			temp = sIntArray[0];
			for(int i = 0; i < n; i++) {
				if(((bit >> i) & 1) == 1) {
					// プラス記号を挿入する場合の処理
					result += temp;
					temp = 0;
				}
				temp *= 10;
				temp += sIntArray[i + 1];
			}
			result += temp;
		}

		System.out.println(result);
	}
}


Measured memory_bytes: 25172
// 最初に提出したコードを変更
#include <bits/stdc++.h>
#define INF (1<<30)
#define MOD 1000000007
#define l_ength size
using ll = long long;
using namespace std;
typedef pair<ll, ll> pll;

int main(){
	int n, k; cin >> n >> k;
	vector<pll> v;
	// first: 美味しさ
	// second: ネタの種類
	for( int i = 0; i < n; ++i ){
		ll t, d; cin >> t >> d;
        --t;
		v.emplace_back(d, t);
	}
	sort( v.begin(), v.end(), greater<pll>() );
	ll cnt = 0;
	ll candy = 0;
	bool used[n]; 
	fill_n( used, n, false );
	priority_queue<pll> pq;
	priority_queue<ll, vector<ll>, greater<ll>> selected;
	for( int i = 0; i < n; ++i ){
		if( used[v[i].second] || cnt == k ){
			pq.push(v[i]);
		} else {
			candy += v[i].first;
			used[v[i].second] = true;
			selected.push(v[i].first);
			++cnt;
		}
	}
	if( cnt < k ){
		for( int i = cnt; i < k; ++i ){
			candy += (pq.top()).first;
			pq.pop();
		}
	}
	ll ans = candy + cnt*cnt;
	for( ll i = cnt-1; i > 0; --i ){
		if( pq.empty() || (pq.top()).first < selected.top() ) break;
		candy = candy - selected.top() + (pq.top()).first;
		selected.pop(); pq.pop();
		ans = max(ans, candy+(i*i));
	} 
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 5488
#include <bits/stdc++.h>
#define rep(i,a,b) for(int i = (a); i <= (b); i++)
#define rng(a) a.begin(), a.end()
#define ina(n,a) cin >> n; for(int i = 1; i <= n; i++) cin >> a[i]
#define sz(x) (int)(x).size()
#define se second
#define fi first
#define prev            coyhhhhhhyoc    
#define next          sdNNNmNNNNNNNmds  
#define y0           hNNNNy_yNNNNNN_sNh
#define y1          mNNNNNdtdNNNNNNtsNNm
#define yn          mNNNNNNNNy___smNNNms
#define tm            oooooosyysooooot 
#define read               tyhyt        
#define rank              ytmNmo         
#define index              yyy
#define pb push_back
#define pcnt __builtin_popcountll
#define rrep(i,a,b) for(int i = (b); i >= (a); i--)
#define rall(x,a) for(auto x : a)
#define MOD 998244353
#define endl "\n"
#define int long long
typedef long long ll;
using namespace std;

const int N = 3333;
int a[N], dp[N][N][3];
int n, s;

signed main() {
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cin >> n >> s;
    rep(i, 1, n) {
        cin >> a[i];
    }
    dp[0][0][0] = 1;
    rep(r, 1, n) {
        rep(cs, 0, s) {
            int ps = cs - a[r];
            dp[r][cs][0] = dp[r - 1][cs][0];
            dp[r][cs][1] = dp[r - 1][cs][0] + dp[r - 1][cs][1];
            dp[r][cs][2] = dp[r - 1][cs][0] + dp[r - 1][cs][1] + dp[r - 1][cs][2];
            if(ps >= 0) {
                dp[r][cs][1] += dp[r - 1][ps][0] + dp[r - 1][ps][1];
                dp[r][cs][2] += dp[r - 1][ps][0] + dp[r - 1][ps][1];
            }
            dp[r][cs][0] %= MOD;
            dp[r][cs][1] %= MOD;
            dp[r][cs][2] %= MOD;
        }
    }
    cout << dp[n][s][2] << endl;
    return 0;
}


Measured memory_bytes: 235648