akhauriyash/Code-Regression huggingface dataset:
N, M, Q = list(map(int, input().split()))
A, B, C, D = [], [], [], []
for _ in range(Q):
    a, b, c, d = list(map(int, input().split()))
    A.append(a-1)
    B.append(b-1)
    C.append(c)
    D.append(d)
    
arrays = []
def backtrack(l, N, M, cur):
    if len(cur) == N:
        arrays.append(cur[:])
    else:
        for num in range(l, M+1):
            cur.append(num)
            backtrack(num, N, M, cur)
            cur.pop()
backtrack(1, N, M, [])

ans = 0
for arr in arrays:
    tmp = 0
    for i in range(Q):
        a, b, c, d = A[i], B[i], C[i], D[i]
        if arr[b] - arr[a] == c:
            tmp += d
    ans = max(ans, tmp)

print(ans)

Measured memory_bytes: 23044
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
using namespace std;

typedef long long ll;
typedef pair<int,int> ii;
typedef tree<ii,null_type,less<ii>,rb_tree_tag,tree_order_statistics_node_update> indexed_set;

int main() {
	cin.tie(0); cout.tie(0); ios_base::sync_with_stdio(0);
	string s; cin>>s;
	if (s=="Sunny") cout<<"Cloudy";
	else if (s=="Cloudy") cout<<"Rainy";
	else if (s=="Rainy") cout<<"Sunny";
	else cout<<endl;	
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
using namespace std;
int main(int argc, char* argv[])
{
	string s;
	cin>>s;
	int i;
	int aw=0;
	char ch=s[0];
	for (i=0;i<s.length();i++){
		if (ch==s[i]){
			aw++;
		}else{
			if (aw<3){
				aw=1;
				ch=s[i];
			}
		}
	}
	if (aw>=3){
		cout<<"Yes"<<endl;
	}else{
		cout<<"No"<<endl;
	}
	return 0;
}

Measured memory_bytes: 256
n = str(input())
a = int(n[0])
b = int(n[1])
c = int(n[2])
d = int(n[3])

def m(x):
    re = a
    ls = [str(a)]
    for i in range(3):
        if (x>>i)&1 == 1 :
            re +=int(n[i+1])
            ls.append('+'+n[i+1])
        else:
            re -=int(n[i+1])
            ls.append('-'+n[i+1])
    return re, ls

for j in range(8):
    if m(j)[0]==7:
        print(''.join(m(j)[1])+'=7')
        exit()

Measured memory_bytes: 9164
#include <iostream>
#include <cstring>
#include <vector>
#include <algorithm>
#include <queue>
#include <functional>

using namespace std;
typedef pair<int, int> P;
typedef pair<P, int> PP;     // building, height, jump
static const int INF = 1e8;
int A[2][103];
bool visited[2][103];
int n;

int check(queue<PP> que)
{
	while (!que.empty())
	{
		PP pp = que.front();
		que.pop();
		if (A[pp.first.first][pp.first.second] == 1)
		{
			while (A[pp.first.first][pp.first.second] == 1)
			{
				++pp.first.second;
			}
			--pp.first.second;
			
		}
		else if (A[pp.first.first][pp.first.second] == 2)
		{
			while (A[pp.first.first][pp.first.second] == 2)
			{
				--pp.first.second;
			}
		}
		if (visited[pp.first.first][pp.first.second])
		{
			continue;
		}
		visited[pp.first.first][pp.first.second] = true;
		if (pp.first.second == n - 1)
		{
			return(pp.second);
		}
		int building = (pp.first.first + 1) % 2;
		for (int i = 0; i < 3; ++i)
		{
			que.push(PP(P(building, pp.first.second + i), pp.second + 1));
		}
	}
	return(INF);
}

void solve()
{
	cin.tie(0);
	ios::sync_with_stdio(false);
	while (cin >> n, n)
	{
		memset(A, 0, sizeof(A));
		for (int i = 0; i < 2; ++i)
		{
			for (int j = 0; j < n; ++j)
			{
				cin >> A[i][j];
			}
		}
		int minJump = INF;
		memset(visited, 0, sizeof(visited));
		queue<PP> que;
		que.push(PP(P(0, 0), 0));
		que.push(PP(P(1, 0), 0));
		minJump = min(minJump, check(que));
		if (minJump == INF)
		{
			cout << "NA" << endl;
		}
		else
		{
			cout << minJump << endl;
		}
	}
}

int main()
{
	solve();
	return(0);
}

Measured memory_bytes: 1220
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <numeric>

using namespace std;

int main(){
  int n,k,k2,u=0,m=0;
  cin >> n>>k;
  k2 =n-2;
  while(k2>0){
    u+=k2;
    k2--;
  }
  if(u<k){
    cout << -1 << endl;
    return 0;
  }
  cout << n*(n-1)/2 - k << endl;
  
  for(int i=1;i<n;i++){
    if(k>=n-i-1){
        cout << i <<" "<< n << endl;
      k -= n-i-1;
    }
    else{
      int p=n;
      for(int j=1;j<=n-i-k;j++){
        cout << i <<" " << p << endl;
        p--;
      }
      k=0;
    }
  }
  }

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

#define pb push_back
#define fi first
#define se second
typedef long long ll;

int main()
{
	ios_base::sync_with_stdio(false); cin.tie(NULL);

	int n, k, ans = 0;
	cin >> n >> k;
	for (int i = 0; i < n; ++i) {
		int h;
		cin >> h;
		ans += (h >= k);
	}
	cout << ans << '\n';
}


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

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

// nCrの計算
const int MAX = 510000;
const int MOD = 1000000007;
ll M = 1000000000 + 7;

long long fac[MAX], finv[MAX], inv[MAX];

// テーブルを作る前処理
void COMinit() {
  fac[0] = fac[1] = 1;
  finv[0] = finv[1] = 1;
  inv[1] = 1;
  for (int i = 2; i < MAX; i++){
    fac[i] = fac[i - 1] * i % MOD;
    inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
    finv[i] = finv[i - 1] * inv[i] % MOD;
  }
}

// 二項係数計算
long long COM(int n, int k){
  if (n < k) return 0;
  if (n < 0 || k < 0) return 0;
  return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}

int main() {
    // 前処理
    COMinit();

    ll N;
    cin >> N;
    map<int,int> m;
    int left_index, right_index;
    for(int i = 1; i <= N+1; i++){
      int tmp;
      cin >> tmp;
      if(m.count(tmp) == 0){
        m[tmp] = i;
      } else {
        left_index = m[tmp];
        right_index = i;
        break;
      }
    }

    ll X = left_index-1; // 1つめの左側の個数
    ll Z = N + 1 - right_index; // 2つめの右側の個数

    cerr << "X: " << X << " Z: " << Z << endl;

    for(ll i = 1; i <= N+1; i++){
      ll ans = COM(N+1, i);

      if(i == 1){
        cout << N << endl;
        continue;
      }
      if(i == 2){
        ans -= X;
        ans += M;
        ans -= Z;
        ans += M;
        ans %= M;
        cout << ans << endl;
        continue;
      }
      if(i == N+1){
        cout << 1 << endl;
        continue;
      }

      ll tmp = COM(X+Z, i -1);
      ans -= tmp;
      ans += MOD;
      ans %= MOD;

      cout << ans << endl;
    }

}


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

using namespace std;

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

#define fi first
#define se second
#define mp make_pair
#define fastIO ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);

const int MOD = (int)1e9 + 7;
const int AL = 26;
int cnt[AL];

int main(){
    fastIO;
    int n;
    cin >> n;
    char x;
    for(int i = 0 ; i < n ; i ++ ){
        cin >> x;
        cnt[x - 'a'] ++ ;
    }
    int ans = 1;
    for(int i = 0 ;i  < AL; i ++ ){
        ans = (ans * 1ll * (cnt[i] + 1)) % MOD;
    }
    cout << ans - 1;
    return 0;
}


Measured memory_bytes: 256
#define _USE_MATH_DEFINES
#include <iostream>
#include <memory>
#include <memory.h>
#include <fstream>
#include <cmath>
#include <math.h>
#include <numeric>
#include <vector>
#include <stack>
#include <string>
#include <queue>
#include <sstream>
#include <cstdlib>
#include <cassert>
#include <cstdio>
#include <map>
#include <iomanip>
#include <list>
#include <cctype>
#include <algorithm>
#include <complex>

#define rep(i, n) for(int i = 0; i < n; i++)
#define rep2(i, m, n) for(int i = m; i < n; i++)
using namespace std;

typedef complex<double> xy_t;
typedef pair<xy_t, xy_t> line;
typedef long long ll;
typedef pair<int, int> P;
typedef pair<double, double> Pd;
typedef pair<int, P> PP;
typedef pair<int, PP> PPP;
const int INF = 1 << 29;
const double EPS = 1E-10;

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

char field[100][100];
int dp[100][100];

int main(){
	int h, w;
	fill(&dp[0][0], &dp[99][99]+1, INF);
	dp[1][0] = 0;
	cin >> h >> w;
	rep(i, h)rep(j, w) cin >> field[i+1][j+1];
	rep(i, h)rep(j, w) dp[i+1][j+1] = field[i+1][j+1] - '0' + min(dp[i][j+1], dp[i+1][j]);
	cout << dp[h][w] << endl;
	return 0;
}

Measured memory_bytes: 0
#include<stdio.h>
int main(void){
	int N,K,x[100],i,s=0;
	scanf("%d",&N);
	scanf("%d",&K);
	for(i=0;i<N;i++){
		scanf("%d",&x[i]);
		s+=(x[i]<K-x[i])?x[i]:K-x[i];
	}
	printf("%d\n",s*2);
	return 0;
}

Measured memory_bytes: 128
//https://atcoder.jp/contests/dp/tasks/dp_e

#include <bits/stdc++.h>
#include <limits.h>
#include <algorithm>  


#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;


using namespace std;

typedef long long int ll;

const int precision = 16;
const int modulo =  1000000007; // 10^9 + 7
using ll = long long;
const double EPS = 1e-9;
const ll INF = 1e18L + 5;

template <class T>
void print(vector<T> v) {
	for(auto it : v) {
		cout << it << " " ;
	}
	cout <<endl;
}

ll solveSK2()
{
	int n, C; cin >> n >> C;

	vector<int> weight(n), value(n);

	for(int i = 0; i < n; ++i) {
		cin >> weight[i] >> value[i];
	}

	int sum_value = accumulate(value.begin(), value.end(), 0);


	vector<ll> dp(sum_value + 1, INF), dp0(sum_value + 1, INF);
	dp[0] = 0;
	dp0[0] = 0;

	for(int i = 0; i < n; ++i) {
		for(int v = sum_value - value[i]; v >= 0; --v) {
			dp[v + value[i]] = min(dp0[v + value[i]], dp0[v] + weight[i]);
		}
		dp0 = dp;
	}

	ll ans = 0;
	for(ll i = 0; i <= sum_value; ++i) {
		if(dp[i] <= C) {
			ans = max(ans, i);
		}
	}

	return ans;

}

int main() {
	ios_base::sync_with_stdio(false);
	cin.tie(nullptr);
	cout.tie(nullptr);
	cout.precision(precision);
	cout.setf(ios_base::fixed);

	auto ret = solveSK2();
	cout << ret;
	return 0;
}




Measured memory_bytes: 1792
# AtCoder Petrozavodsk Contest 001 - A
# -*- encoding: UTF-8 -*-
x, y = map(int, input().split())

result = -1

if x % y == 0 :
  result = -1
else: 

  n = (10 ** 18) // x

  for i in range(2, n+1) :
    m = x * i
    if (m % y) != 0 :
      result = m
      break

print(result)


Measured memory_bytes: 2940
#include <algorithm>
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(), (x).end()
#define ll long long
#define inf 1e9
#define INF 1000000000000000000

int main() {
    ll N, A, B;
    cin >> N >> A >> B;
    vector<ll> X(N);
    rep(i, N) { cin >> X[i]; }

    ll res = 0;
    rep(i, N - 1) {
        ll diff = X[i + 1] - X[i];
        res += min(diff * A, B);
    }

    cout << res << endl;
}

Measured memory_bytes: 1024
using System;
using System.Collections.Generic;
using System.Linq;

public class Solution
{
    public static void Main()
    {
        var n = int.Parse(Console.ReadLine());
        var s = Console.ReadLine();
        var t = new string(s.Select(c => (char)(((c - 'A' + n) % 26) + 'A')).ToArray());

        Console.WriteLine(t);
    }
}

Measured memory_bytes: 13268
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(n);++i)
#define ALL(A) A.begin(), A.end()
#define INF ((int)1e9 + 9)

using namespace std;

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

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

	int N, K; cin >> N >> K;
	vector<int> h(N, 0);
	rep (i, N){
		cin >> h[i];
	} // end rep

	sort(ALL(h));

	int res = INF;
	for (int i = 0; i < N - K + 1; ++i){
		int diff = h[K - 1 + i] - h[i];
		res = min(res, diff);
	} // end for
	
	cout << res << endl;

	return 0;
}

Measured memory_bytes: 640
#include <iostream>
#include <string>
#include <algorithm>
#include <cmath>
#include <deque>
#include <queue>
#include <stack>
#include <vector>
#include <utility>
#include <iomanip>
#include <bitset>
#include <set>
#include <map>
#include <stdio.h>
#include <numeric>
#include <cstring>

#define rep(i,n) for (int i = 0; i < (n); i++)
#define rep1(i,n) for (int i = 1; i < (n); i++)
#define FOR(i,a,b) for (int i=(a); i < (b); i++)
#define MOD 1000000007 //10^9+7
using namespace std;
using ll = long long;
using PII = pair<int, int>;
using PLL = pair<ll, ll>;
const int INF = numeric_limits<int>::max();
const ll INFL = numeric_limits<ll>::max();


// 負の数にも対応した % 演算
long long mod(long long val, long long m) {
    long long res = val % m;
    if (res < 0) res += m;
    return res;
}

//greatest common divisor
long long gcd(ll a, ll b) 
{
    if (a % b == 0) {
        return b;
    } else {
        return gcd(b, a % b);
    }
}

//least common multiple
long long lcm(ll a, ll b)
{
    return a / gcd(a, b) * b ;
}

ll factorial(ll n) {
    ll res = 1;
    for (ll i = 1; i <= n; i++) {
        res *= i;
    }
    return res;
}

int main()
{
    int n; cin >> n;
    vector<int> v(n), c(n);
    rep(i,n) cin >> v[i];
    rep(i,n) cin >> c[i];
    int ans = 0;
    rep(i,n) {
        if (v[i] > c[i])
            ans += v[i] - c[i];
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 3608
from collections import defaultdict
def primeFact(n):
    factors = defaultdict(int)
    i = 2
    while i*i <= n:
        if n % i == 0:
            n //= i
            factors[i]+=1
        else:
            i += 1
    if n > 1:
        factors[n]+=1
    return factors

N = int(input())

if N<=1:
    print(0)
    exit()

ans=0
primes = primeFact(N)

for val in primes.values():
    i=1
    while val>=i:
        val-=i
        i+=1
        ans+=1
print(ans)



Measured memory_bytes: 65832
n, m = map(int, input().split())
A = list(map(int, input().split()))

CB = []
for _ in range(m):
    b, c = map(int, input().split())
    CB.append([c, b])

CB.sort(reverse=True)
A.sort()
index = 0
for i in range(m):
    if index >= n:
        break
    elif A[index] >= CB[i][0]:
        break

    for j in range(CB[i][1]):
        if index >= n:
            break
        elif A[index] >= CB[i][0]:
            break

        A[index] = CB[i][0]
        index += 1

print(sum(A))


Measured memory_bytes: 24484
n,x=map(int,input().split())
L=input().split()
L=[int(i) for i in L]
key=0
d=0
for i in range(n):
    d+=L[i]
    if x<d:
        key=i+1
        break
    if i==n-1:
        key=n+1
print(key)

Measured memory_bytes: 3060
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

using namespace std;
using namespace __gnu_pbds;

#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define fbo find_by_order
#define ook order_of_key

typedef long long ll;
typedef pair<ll,ll> ii;
typedef vector<int> vi;
typedef long double ld;
typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> pbds;

const long long mod = 1000000007;

int main(){
    ios_base::sync_with_stdio(0); cin.tie(0);
    int n;
    cin>>n;
    vector<ll> v;
    for(int i=0;i<n;i++){
        ll a;
        cin>>a;
        v.pb(a);
    }
    if((n&1)==0){
        for(int i=n-1;i>=0;i-=2){
            cout<<v[i]<<' ';
        }
        for(int i=0;i<n;i+=2){
            cout<<v[i]<<' ';
        }
    }
    else{

        for(int i=n-1;i>=0;i-=2){
            cout<<v[i]<<' ';
        }
        for(int i=1;i<n;i+=2){
            cout<<v[i]<<' ';
        }
    }
    return 0;
}


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

int main()
{
  ll n;
  cin >> n;
  map<ll, ll> m;

  for (ll i = 0; i < n; i++)
  {
    ll a;
    cin >> a;
    m[a]++;
  }
  ll cnt = 0;
  for (auto v : m)
  {
    cnt += v.second % 2;
  }
  cout << cnt << endl;
}


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

int n;
vector<vector<int>> tree;
vector<int> cnt;

void dfs(int current, int par)
{
  cnt[current] += cnt[par];
  for (auto i : tree[current])
    if (i != par)
      dfs(i, current);
}

int main()
{
  int q;
  cin >> n >> q;
  tree.resize(n + 1);
  cnt.resize(n + 1);
  rep(i, n - 1)
  {
    int a, b;
    cin >> a >> b;
    tree[a].push_back(b);
    tree[b].push_back(a);
    cnt[i] = 0;
  }
  tree[0].push_back(1);
  cnt[n-1] = cnt[n] = 0;
  rep(i, q)
  {
    int p, x;
    cin >> p >> x;
    cnt[p] += x;
  }
  dfs(1, 0);
  for (int i=1; i<=n; i++)
  {
    if (i != 1)
      printf(" ");
    printf("%d", cnt[i]);
  }
  cout << endl;
}

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

using namespace std;


int main(){
    long long n,m;

    cin>>n>>m;

    long long ans;
    if(n>1&&m>1){
        ans = (n-2)*(m-2);
    }else if(n==1&&m>1){
        ans = m-2;
    }else if(n>=2&&m==1){
        ans = n-2;
    }else if(n==1&&m==1){
        ans = 1;
    }

    cout<<ans<<endl;

}


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

int cross[102] = {}; //100???????????????????¬???°?????¨??????

//??????????????§???????????????????????¢??°
int hitohude() {
  if(cross[1] % 2 == 0 || cross[2] % 2 == 0)
    return 0;

  for(int i = 3; i <= 101; i++) {
    if(cross[i] % 2 == 1)
      return 0;
  }
  return 1;
}

int main() {
  int a,b;
  while(cin >> a >> b) {
    ++cross[a];
    ++cross[b];
    if(a == 0) {
      if(hitohude() == 1)
	cout << "OK" << endl;
      else
	cout << "NG" << endl;

      for(int i = 0; i <= 101; i++){
	cross[i] = 0;
      }
    }
  }
  return 0;
}

Measured memory_bytes: 3092
#include <bits/stdc++.h>
using namespace std;
 
int main()
{
    int n;cin>>n;
    bool marc=0;
    while(n>0){
        if((n%10)==7){
            marc=1;
            break;
        }
        n/=10;
    }
    if(marc==1) cout<<"Yes";
    else cout<<"No";
 
    return 0;
}

Measured memory_bytes: 3624
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int a = sc.nextInt();
        int b = sc.nextInt();
        if (a == b) {
            System.out.println("Draw");
            return;
        }
        if (a == 1 || (b != 1 && a > b)) {
            System.out.println("Alice");
            return;
        }
        System.out.println("Bob");
    }

}


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

int  main()
{
	int n; cin >> n;
	vector <int> a(n);
	rep(i, n)
	{
		cin >> a[i];
	}
	// sort(a.begin(), a.end());
	int tmp = INT_MAX;
	int ans;
	for (int i = -100; i <= 100; i++)
	{
		ans = 0;
		for (int j = 0; j < n; j++)
		{
			ans += abs(i - a[j]) * abs(i - a[j]);
		}
		ans = min(ans, tmp);
		tmp = ans;
	}
	cout << ans << endl;
	return 0;
}


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

int N, M, Q;
int erased[200001];
int Right[200001];
int Left[200001];

int main() {
    cin >> N >> M >> Q;
    for (int i = 0; i < N; i++) Right[i] = (i + 1) % N;
    for (int i = 0; i < N; i++) Left[Right[i]] = i;
    for (int i = 0; i < N; i++) erased[i] = 1;

    int c = 0;
    for (int i = 0; i < M; i++) {
        int a; cin >> a;
        bool flag = a % 2 ? true : false;
        for (int j = 0; j < a - 1; j++) {
            if (flag) c = Left[c];
            else c = Right[c];
        }

        if (flag) erased[Left[c]] = 0;
        else erased[Right[c]] = 0;
        if (flag) {Left[c] = Left[Left[c]]; Right[Left[c]] = c;}
        else {Right[c] = Right[Right[c]]; Left[Right[c]] = c;}
        if (!flag) c = Right[c];
        N--;
    }

    for (int i = 0; i < Q; i++) {
        int a; cin >> a;
        cout << erased[a] << endl;
    }

    return 0;
}

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

using namespace std;
typedef long long ll;
typedef pair<ll,ll> P;
#define a first
#define b second
#define sz(x) (ll)((x).size())
#define pb push_back
#define mp make_pair 
#define bg begin()
#define ed end()
#define all(x) (x).bg,(x).ed
#define rep(i,n) for(ll i=0;i<n;i++)
#define rep1(i,n) for(ll i=1;i<=n;i++)
#define rrep(i,n) for(ll i=n-1;i>=0;i--)
#define rrep1(i,n) for(ll i=n;i>=1;i--)
#define FOR(i,a,b) for(ll i=a;i<b;i++)
const ll MOD=1000000007;
const ll INF=1000000000000000;

vector<ll> pw2(51,1); vector<ll> pw10(19,1);
vector<ll> divisor(ll x){vector<ll> div;for(ll i=1;i*i<=x;i++){if(x%i==0){div.pb(i);if(i*i!=x)div.pb(x/i);}}sort(div.bg,div.ed);return div;}
map<ll,ll> prime_factor(ll x){map<ll,ll> ret;ll tmp=x;for(ll i=2;i*i<=x;i++){while(tmp%i==0){ret[i]++;tmp/=i;}}if(tmp!=1) ret[tmp]++;return ret;}
template<class T> inline bool chmin(T& a, T b){if(a>b){a=b;return true;}return false;}
template<class T> inline bool chmax(T& a, T b){if(a<b){a=b;return true;}return false;}
ll maxx(ll x,ll y,ll z){return max(max(x,y),z);}
ll minn(ll x,ll y,ll z){return min(min(x,y),z);}
ll mid(ll x,ll y,ll z){return x>y?y>=z?y:min(z,x):x>=z?x:min(y,z);}
ll gcd(ll x,ll y){if(x%y==0) return y;else return gcd(y,x%y);}
ll lcm(ll x,ll y){return x*(y/gcd(x,y));}
ll digsz(ll x){if(x==0) return 1;else{ll ans=0;while(x){x/=10;ans++;}return ans;}}
ll digsum(ll x){ll sum=0;while(x){sum+=x%10;x/=10;}return sum;}
ll power(ll x,ll n,ll mod){ll ret=1;while(n>0){if(n&1) (ret*=x)%=mod;(x*=x)%=mod;n>>=1;}return ret;}

int main(){
	ll N,K; cin>>N>>K;
	vector<ll>A(N+1);
	rep1(i,N) cin>>A[i];
	map<ll,ll> m;
	rep1(i,N){
		m[A[i]]++;
	}
	ll ans=0,tmp=0,tmpK;
	if(K%2==0){
		tmpK=(K-1)*(K/2);
		tmpK%=MOD;
	}
	else{
		tmpK=((K-1)/2)*K;
		tmpK%=MOD;
	}
	for(auto itr=m.bg;itr!=m.ed;itr++){
		ans+=((tmpK*tmp)%MOD)*(itr->b);
		ans%=MOD;
		tmp+=itr->b;
	}
	tmp=0;
	rep1(i,N-1){
		FOR(j,i+1,N+1){
			if(A[i]>A[j]) tmp++;
		}
	}
	ans+=(tmp*K)%MOD;
	ans%=MOD;
	cout<<ans;
}

Measured memory_bytes: 384
import sys
from collections import deque

sr = lambda: sys.stdin.readline().rstrip()
ir = lambda: int(sr())
lr = lambda: list(map(int, sr().split()))

K = ir()
A = deque([x for x in range(1, 10)])
count = 0
while True:
    cur = A.popleft()
    count += 1
    if count == K:
        answer = cur
        break
    next = 10 * cur + (cur % 10)
    if cur % 10 != 0:
        A.append(next-1)
    A.append(next)
    if cur % 10 != 9:
        A.append(next+1)

print(answer)


Measured memory_bytes: 40816
import itertools
n=int(input())
numbers=0
uselists=[]
for j in itertools.product(["3","5","7"],repeat=len(str(n))):
        s="".join(j)
        uselists.append(s) 

for _ in uselists:
    if int(_)<=n and len(set(_))>=3:
        numbers+=1
        
        
    else:
        continue
        
listss=[0, 0, 0, 6, 36, 150, 540, 1806, 5796, 18150]
for x in range(len(str(n))):
    numbers+=listss[x]
print(numbers) 

Measured memory_bytes: 4340
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
const ll N=2e5+8;
const ll MOD=1e9+7;
#define  pb push_back
ll H,W,n,dp[N],fact[N],ifact[N];
pair<ll,ll> a[N];
ll pow_mod(ll x,ll n){
    ll ans=1;
    while(n){
        if(n&1)ans=(ans*x)%MOD;
        x=(x*x)%MOD;
        n/=2;
    }
    return ans;
}

void init(){
    fact[0]=ifact[0]=1;
    for(ll i=1;i<N;i++){
        fact[i]=(i*fact[i-1])%MOD;
        ifact[i]=(pow_mod(i,MOD-2)*ifact[i-1])%MOD;
    }
}
ll compute_ways(ll x1,ll y1,ll x2,ll y2){
    ll x=abs(x2-x1),y=abs(y2-y1);
    ll ans=(fact[x+y]);
    ans=(ans*ifact[x])%MOD;
    ans=(ans*ifact[y])%MOD;
    return ans;
}
bool ok(ll x1,ll y1,ll x2,ll y2){
    return x2>=x1 && y2>=y1;
}
int main(){
    init();
    cin>>H>>W>>n;
    for(ll i=0;i<n;i++){
        cin>>a[i].first>>a[i].second;
    }
    a[n].first=H;a[n].second=W;
    n++;
    sort(a,a+n);
    for(ll i=0;i<n;i++)
        dp[i]=compute_ways(1,1,a[i].first,a[i].second);
    //cout<<dp[n-1]<<"\n";
    //cout<<(fact[7]*ifact[4])%MOD<<"\n";
    for(ll i=0;i<n;i++){
        for(ll j=i-1;j>=0;j--){
            if(!ok(a[j].first,a[j].second,a[i].first,a[i].second))continue;
      //      cout<<"dpj:"<<dp[j]<<" compute:"<<compute_ways(a[j].first,a[j].second,a[i].first,a[i].second)<<"\n";
            dp[i]=(MOD+(dp[i]-(dp[j]*compute_ways(a[j].first,a[j].second,a[i].first,a[i].second))%MOD)%MOD)%MOD;
        }
    }
    //cout<<compute_ways(1,4,3,4)<<"\n";
    cout<<dp[n-1]<<"\n";
    return 0;
}

Measured memory_bytes: 4988
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
const int mod = 1000000007;

int main() {
    ios::sync_with_stdio(false);
    int n;
    ll a, b, h[100005] = {};
    cin >> n >> a >> b;
    for (int i = 0; i < n; i++) cin >> h[i];
    ll l = 0, r = mod;
    while (l + 1 < r) {
        ll m = (l + r) >> 1, c = 0;
        for (int i = 0; i < n; i++) if (h[i] > m * b) {
            c += (h[i] - m * b - 1) / (a - b) + 1;
        }
        if (c <= m) r = m;
        else l = m;
    }
    cout << r;
}


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

int main(){
  ll a, b, x; cin >> a >> b >> x;
  ll res1 = (a-1) / x, res2 = b / x;
  if(a == 0){
    cout << b / x + 1 << endl;
  }
  else{
 	 cout << res2 - res1 << endl;
  }
  return 0;
}

Measured memory_bytes: 256
N = int(input())
S = input()
s1 = set()
s2 = set()
s3 = set()

for i in S:
  for j in s2:
    s3.add(j+i)
  for k in s1:
    s2.add(k+i)
  s1.add(i)
print(len(s3))


Measured memory_bytes: 9200
#include <iostream>

using namespace std;

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

    int ans = 3e8+1;
    for (int i = 0; i <= n - k; i++) {
        int x1 = x[i], x2 = x[i+k-1];

        int t;
        if (x2 <= 0) {
            t = -x1;
        } else if (x1 >= 0) {
            t = x2;
        } else if (-x1 < x2) {
            t = -x1 * 2 + x2;
        } else {
            t = -x1 + x2 * 2;
        }

        if (t < ans) {
            ans = t;
        }
    }

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 640
#include <bits/stdc++.h>
#include <iostream>
#include<math.h>
using namespace std;
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
int main()
{
    int64_t N;
    cin >> N;
    vector<int64_t>vec(3*N);
    for (int64_t i=0; i<3*N; i++) {
        cin >> vec.at(i);
    }

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

    int64_t sum = 0;
    for (int64_t i=N; i<N+N; i++) {
        sum += vec[i];
    }

    bool guusuu = (N % 2 == 0);
    int64_t kouho = 0;
    for (int64_t i=3*N-1; i>=N; i--) {
        if (guusuu && i%2==0) {
            kouho += vec[i];
        } else if (!guusuu && i%2!=0) {
            kouho += vec[i];
        }
    }

    cout << max(sum, kouho) << endl;
    return 0;
}

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

int main() {
  
  int a, b, c, d;
  cin >> a >> b >> c >> d;
  
  while(1) {
    c -= b;
    a -= d;
    
    if(c <= 0) {
      cout << "Yes" << endl;
      break;
    }
    
    else if (a <= 0) {
      cout << "No" << endl;
      break;
    }
  }
}

Measured memory_bytes: 3564
#include <bits/stdc++.h>
using namespace std;
int main(void)
{
	long long n, m;
	cin >> n >> m;
	long long s[n];
	map<long long, long long> ma;
	for (int i = 0; i < n; i++) {
		long long a;
		cin >> a;
		if (i == 0)
			s[i] = a;
		else
			s[i] = s[i-1] + a;
		ma[s[i]%m]++;
	}
	long long ans = 0;
	for (auto e : ma) {
		if (e.first == 0)
			ans += e.second;
		if (e.second >= 2) {
			ans += e.second * (e.second-1)/2;
		}
	}
	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 8260
#include <iostream>
#include <string>
using namespace std;
string s;
const string leftk = "qwertasdfgzxcvb";

void solve() {
  // l .. 0 , r .. 1
  int res = 0;
  int mode = (leftk.find(s[0]) != -1) ? 0 : 1 ;
  for (int i = 1; i < s.size(); i += 1) {
    if ((mode == 0 && leftk.find(s[i]) == -1) ||
        (mode == 1 && leftk.find(s[i]) != -1) ) {
      mode = !mode;
      res++;
    }
  }
  cout<<res<<endl;
}

int main (int argc, char const* argv[]) {
  while (cin>>s) {
    if (s != "#") solve();
  }
  return 0;
}

Measured memory_bytes: 0
#include <stdio.h>
int main(){
  int x, y, z;
  while(1){
    scanf("%d %d", &x, &y);
    if ( x == 0 && y == 0) break;
    if ( x < y )
    printf("%d %d\n", x, y);
    else
    printf("%d %d\n", y, x);

  }
  return 0;
}



Measured memory_bytes: 2036
SA = input()
SB = input()
SC = input()

import sys

Alist = []
Blist = []
Clist = []

for i in range(len(SA)):
    Alist.append(SA[i])
for i in range(len(SB)):
    Blist.append(SB[i])
for i in range(len(SC)):
    Clist.append(SC[i])
    
card = SA[0]
    
while len(Alist) >= 0 and len(Blist) >= 0 and len(Clist) >= 0:
    if card == 'a':
        if len(Alist) == 0:
            print('A')
            sys.exit()
        card = Alist.pop(0)
    elif card == 'b':
        if len(Blist) == 0:
            print('B')
            sys.exit()
        card = Blist.pop(0)
    elif card == 'c':
        if len(Clist) == 0:
            print('C')
            sys.exit()
        card = Clist.pop(0)

Measured memory_bytes: 3064
#include<bits/stdc++.h>
using namespace std;
int main(){
  long long n,k,i,p = 0;vector<long long> t;scanf("%lld%lld",&n,&k);
  long long a[n];bool c[n] = {};
  for(i=0;i<n;i++){
    scanf("%lld",&a[i]);a[i]--;
  }
  while(true){
    k--;
    if(c[p]){
      long long m = p;t.push_back(p);p = a[p];
      while(p!=m){
        t.push_back(p);p = a[p];
      }
      break;
    }
    if(k==0){
      printf("%lld\n",a[p]+1);return 0;
    }
    c[p] = 1;p = a[p];
  }
  long long ans = t[(k+1)%t.size()];
  printf("%lld\n",ans+1);
}

Measured memory_bytes: 5980
#include <bits/stdc++.h>
 
#define pb push_back
#define ff first
#define ss second
#define all(x) (x).begin(), (x).end()
#define ll long long
#define ii pair<int,int>
#define vi vector<int>
#define vll vector<ll>
#define vii vector<ii>
#define debug cout << "Ok" << endl;

using namespace std;

void solve(){

	return;
}
 
int32_t main(){
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	
	long long int n,cont=1,aux,l;
	queue<long long int>q;
	for(int i=1;i<10;i++){
		q.push(i);
	}

	cin >> n;

	while(true){
		aux = q.front();
		q.pop();
		if(n==cont){
			cout << aux << endl;
			return 0;
		}
		l = aux%10;
		aux*=10;
		if(l!=0){
			q.push(aux+l-1);
		}
		q.push(aux+l);
		if(l!=9){
			q.push(aux+l+1);
		}
		cont++;
	}
	return 0;
}

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

int main(){
  int X, Y, Z;
  cin >> X >> Y >> Z;
  int ans = 0;
  int j = 0;
  
  for(int i=1; i<X; i++){
    ans = i*Y + (i+1)*Z;
    j++;
    if(ans > X){
      break;
    }
  }
  
  cout << j - 1 << endl;
  
}

Measured memory_bytes: 256
#include<iostream>
using namespace std;
#include<string>
#define REP(i,a,b) \
for(int i=a; i<b; i++)
#include<bits/stdc++.h>
#include<algorithm>
#define ll long long int
typedef vector<int> vi;
typedef pair<int,int> ii;
#define sz(a) int((a).size())
#define pb push_back
#define all(c) (c).begin(),(c).end()
#define present(c,x) ((c).find(x) != (c).end())
#define tr(c,i) for(typeof(c.begin()) i = (c).begin(); i != (c).end();i++)
int main()
{
	int n;
	cin >> n;
	vector< pair< pair<string,int>, int> > arr;
	REP(i,0,n)
	{
		string s;
		int p;
		cin >> s >> p;
		arr.push_back(make_pair(make_pair(s,-1*p),i+1));
	}
	sort(arr.begin(),arr.end());
	REP(i,0,n)
	{
		cout << arr[i].second << "\n";
	}
}



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

int main() {
  int A,B,C;
  cin >> A >> B >> C;
  if(C - (A - B) <= 0) {
    cout << 0 << endl;
  }
  else if(C - (A - B) > 0) {
    cout << C - (A - B) << endl;
  }
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
	public static void main(String[] args){
		Scanner scan = new Scanner(System.in);
		
		int n, q;
		int[] s;
		int t;
		int j;
		int ans = 0;

		n = scan.nextInt();
		s = new int[n];
		for(int i = 0; i <= n - 1; i++){
			s[i] = scan.nextInt();
		}
		
		q = scan.nextInt();
		for(int i = 0; i < q; i++){
			t = scan.nextInt();
			ans += linearSearch(s, t);
		}
		System.out.println(ans);
	}
	
	public static int linearSearch(int[] a, int key){
		int i = 0;
		a[a.length - 1] = key;
		while(a[i] != key){
			i++;
			if(i == a.length - 1)return 0;
		}
		return 1;
	}
}

Measured memory_bytes: 40128
#include<bits/stdc++.h>
#define int long long
#define F first
#define S second
#define pb push_back
#define mp make_pair
#define all(v) v.begin(),v.end()
#define hell 1000000007
#define rep(i,a,b) for(int i=a;i<b;i++)
using namespace std;
bool prime[200005];
void sieve(){
    memset(prime, true, sizeof(prime)); 
    for (int p=2; p*p<200005; p++) 
    {
        if (prime[p] == true) 
        {
            for (int i=p*p; i<200005; i += p) 
                prime[i] = false; 
        } 
    }
}
int powmod(int x,int y,int mod){
    int res = 1;
    x = x%mod;
    while(y>0){
        if(y&1){
            res = (res*x)%mod;
        }
        y = y>>1;
        x = (x*x)%mod;
    }
    return res;
}
signed main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    int t=1;
    //cin>>t;
    while(t--){
        int a,b;
      	cin>>a>>b;
      	cout<<max(a+b,max(a*b,a-b))<<endl;
    }
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <map>
#include <algorithm>
#include <queue>
using namespace std;
typedef long long int ll;

int main(){
	int n; cin >> n;
	vector<int> a(n);
	for(int i=0;i<n;i++){
		cin >> a[i];
	}
	sort(a.begin(),a.end());
	double m=a[0];
	for(int i=1;i<n;i++){
		m=m/2.0+a[i]/2.0;
	}
	printf("%.8f\n",m);
}

Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>	
#include<map>
#include<set>
#include<utility>
#include<cmath>
#include<cstring>
#include<queue>
#include<stack>
#include<cstdio>
#include<sstream>
#include<iomanip>
#include<assert.h>
#define loop(i,a,b) for(int i=a;i<b;i++) 
#define rep(i,a) loop(i,0,a)
#define pb push_back
#define all(in) in.begin(),in.end()
#define shosu(x) fixed<<setprecision(x)
using namespace std;
//kaewasuretyuui
typedef long long ll;
typedef int Def;
typedef pair<Def,Def> pii;
typedef vector<Def> vi;
typedef vector<vi> vvi;
typedef vector<pii> vp;
typedef vector<vp> vvp;
typedef vector<string> vs;
typedef vector<double> vd;
typedef vector<vd> vvd;
typedef pair<Def,pii> pip;
typedef vector<pip>vip;
//#define mt make_tuple
//typedef tuple<double,int,double> tp;
//typedef vector<tp> vt;
template<typename A,typename B>bool cmin(A &a,const B &b){return a>b?(a=b,true):false;}
template<typename A,typename B>bool cmax(A &a,const B &b){return a<b?(a=b,true):false;}
const double PI=acos(-1);
const double EPS=1e-7;
Def inf=sizeof(Def)==sizeof(long long)?2e18:1e9;
int dx[]={0,1,0,-1};
int dy[]={1,0,-1,0};
int main(){
	string s;
	cin>>s;
	vi co(26);
	rep(i,s.size())co[s[i]-'a']=1;
	rep(i,27)if(i==26)cout<<"None"<<endl;
	else if(co[i]==0){
		cout<<(char)(i+'a')<<endl;
		return 0;
	}
}








Measured memory_bytes: 512
import sys
import math
import itertools
import bisect
from copy import copy,deepcopy
from collections import deque,Counter
from decimal import Decimal
def s(): return input()
def i(): return int(input())
def S(): return input().split()
def I(): return map(int,input().split())
def L(): return list(input().split())
def l(): return list(map(int,input().split()))
def lcm(a,b): return a*b//math.gcd(a,b)
sys.setrecursionlimit(10 ** 9)
INF = 10**9
mod = 10**9+7

class UnionFind:
  def __init__(self,n):
    self.n=[-1]*n
    self.r=[0]*n
  def find_root(self,x):
    if self.n[x]<0:
      return x
    else:
      self.n[x]=self.find_root(self.n[x])
      return self.n[x]
  def unite(self,x,y):
    x=self.find_root(x)
    y=self.find_root(y)
    if x==y:return
    elif self.r[x]>self.r[y]:
      self.n[x]+=self.n[y]
      self.n[y]=x
    else:
      self.n[y]+=self.n[x]
      self.n[x]=y
      if self.r[x]==self.r[y]:
        self.r[y]+=1
  def root_same(self,x,y):
    return self.find_root(x)==self.find_root(y)
  def count(self,x):
    return -self.n[self.find_root(x)]

N,M = I()
u = UnionFind(N)
for i in range(M):
    a,b = I()
    u.unite(a-1,b-1)
li = []
q = []
ans = 0
for i in range(N):
    num = u.count(i)
    if num not in li:
        li.append(num)
    q.append(num)
for i in li:
    ans += q.count(i)//i
print(ans-1)

Measured memory_bytes: 86536
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int M=1000000007;
const int N=2000100;

ll pwr(ll a, ll e){
  if(e==0)return 1;
  if(e%2==1)return a*pwr(a,e-1)%M;
  ll h=pwr(a,e/2);
  return h*h%M;
}

ll inv(ll a){return pwr(a,M-2);}

ll f[N+1];
ll fi[N+1];

ll C(ll n, ll k){
if(n<0||k<0) return 0;
  return f[n]*fi[k]%M*fi[n-k]%M;
}

int main(){
  f[0]=1;
  for(int i=1;i<=N;i++)
    f[i]=f[i-1]*i%M;
  for(int i=0;i<=N;i++)
    fi[i]=inv(f[i]);
int x,y;
  cin>>x>>y;
  ll a=2*x-y;
  ll b=2*y-x;
  if(a%3!=0||b%3!=0||a<0||b<0){
    cout<<0;
  }else{
    a/=3;
    b/=3;
    cout <<C(a+b,a);
  }
}


Measured memory_bytes: 31488
#include <iostream>
#include <stdio.h>
#include <fstream>
#include <algorithm>
#include <string>
#include <map>
#include <set>
#include <queue>
#include <vector>
#include <limits.h>
#include <math.h>
#include <functional>

#define repeat(i,n) for (long long i = 0; (i) < (n); ++ (i))
#define debug(x) cerr << #x << ": " << x << '\n'
#define debugArray(x,n) for(long long i = 0; (i) < (n); ++ (i)) cerr << #x << "[" << i << "]: " << x[i] << '\n'

using namespace std;

typedef long long ll;
typedef pair<int,int> Pii;
typedef vector<int> vint;
typedef vector<ll> vll;
const ll INF = INT_MAX;

int main() {
  int N;
  cin >> N;
  cout << 0 << endl;
  string in;
  cin >> in;
  if(in == "Vacant"){
    return 0;
  }
  bool lg = (in == "Male");
  int l=0,r=N;
  repeat(i,19){
    int mid = (l+r)/2;
    cout << mid << endl;
    cin >> in;
    if(in == "Vacant"){
      return 0;
    }
    if((mid-l)%2 == 0){
      if(lg == (in == "Male")){
        l = mid;
      }else{
        r = mid;
      }
    }else{
      if(lg == (in == "Male")){
        r = mid;
      }else{
        l = mid;
        lg = !lg;
      }
    }
  }
  return 0;
}


Measured memory_bytes: 852
carrot,maxstock,duration,normal,fast,goal = ((int(n) for n in input().split(" ")))
stack,used = [],0
for c in range(carrot):
    newcar = int(input())
    stack = list(filter(lambda x:x>newcar,stack))
    
    if len(stack) == 0:
        stack.append(newcar + (fast * duration))
        used += fast*duration
    else:
        if len(stack) == maxstock + 1:
            used += fast*duration - (stack[0]-newcar)
            stack = list(map(lambda x:x+(fast*duration - (stack[0]-newcar)),stack))
        else:
            stack.append(stack[-1]+fast * duration)
            used += fast*duration
if stack[-1] > goal:
    used -= stack[-1] - goal
print((goal - used) / normal + used / fast)

Measured memory_bytes: 7760
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <iostream>
#include <set>
#include <math.h>
#include <algorithm>
#include <limits.h>
using namespace std;

int main()
{
    //freopen("input.in", "r", stdin);
    string S;
    set<string> tmp={"dream", "dreamer", "erase", "eraser"};
    while(cin>>S){
        set<string> cur={""};
        int flag=false;
        while(cur.size()>0){

            set<string> ans=cur;
            cur.clear();
            for(auto it : tmp){
                for(auto res : ans){
                    res+=it;
                    //cout<<"res: "<<res<<endl;
                    if(res.length()<=S.length() && res==S.substr(0, res.length())){
                        cur.insert(res);
                        if(res.length()==S.length()){
                            flag=true;
                            cur.clear();
                            ans.clear();
                            break;
                        }
                    }
                }
            }
        }

        if(flag) cout<<"YES"<<endl;
        else cout<<"NO"<<endl;
    }
    return 0;
}


Measured memory_bytes: 1300
#include <stdio.h>

int main()
{
    int a, b, c;
    int resp = 0, count = 0;

    scanf("%d %d %d", &a, &b, &c);

    //printf("%d %d %d\n", a, b, c);

    for(int i = 1; i <= b; i++)
    {
        if(i%a == 0)
        {
            if (count == c)
            {
                resp = count;
            }
            count++;
        }

        //printf("%d\n", count);
    }

    if (resp > 0)
    {
        printf("%d\n", resp);
    }
    else
    {
        printf("%d\n", count);
    }


    return 0;
}


Measured memory_bytes: 128
#include<stdio.h>

int main(void){
  char t[200001];
  scanf("%s",t);

  for(int i = 0;t[i] != '\0';i ++){
    if(t[i] == '?'){
      putchar('D');
    }
    else{
      printf("%c",t[i]);
    }
  }

  return 0;
}

Measured memory_bytes: 1844
#include <bits/stdc++.h>
using namespace std;
namespace UnionTree {
	template <typename T>
	int root(vector<T> &u, int x) {
		if(x < 0 || u.size() <= x) return -1;
		if(u[x].parent == -1) return x;
		else return u[x].parent = root(u, u[x].parent);
	}
	template <typename T>
	bool connect(vector<T> &u, int a, int b) {
		a = root(u, a), b = root(u, b);
		if(a == b || a < 0 || b < 0) return false;
		u[b].parent = a;
        u[a].l = u[b].l = min(u[a].l, u[b].l);
        u[a].r = u[b].r = max(u[a].r, u[b].r);
		return true;
	}
}; // namespace UnionTree

struct Node {
    int parent;
    int64_t l, r;
    int value;
};

int main() {
    // 小さい値からUnionFindすればよい。
    // (i - l + 1) * (r - i + 1) * x
    #ifdef DEBUG
    std::ifstream in("/home/share/inputf.in");
    std::cin.rdbuf(in.rdbuf());
    #endif
    int N;
    cin >> N;
    vector<int> A(N);
    vector<Node> B(N + 1);
    for(int i = 0; i < N; i++) {
        int tmp;
        cin >> tmp;
        B[tmp].value = B[tmp].l = B[tmp].r = i;
        A[i] = tmp;
        B[tmp].parent = -1;
    }
    int64_t ans = 0;
    for(int64_t x = N; x > 0; x--) {
        int i = B[x].value;
        if(i > 0 && A[i - 1] > x) UnionTree::connect(B, x, A[i - 1]);
        if(i < N - 1 && A[i + 1] > x) UnionTree::connect(B, x, A[i + 1]);
        int p = UnionTree::root(B, x);
        ans += (i - B[p].l + 1) * (B[p].r - i + 1) * x;
    }
    cout << ans << endl;
    return 0;
}

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

#define F first
#define S second
#define MP make_pair
#define pb push_back
#define all(a) a.begin(), a.end()
#define lcm( a, b ) (a)/__gcd((a),(b))*(b)
#define endl '\n'

using namespace std;

typedef long long LL;
typedef pair< int, int > P;
typedef pair< LL, LL > LP;

static const int INF = INT_MAX;
static const LL LINF = LLONG_MAX;
static const int MIN = INT_MIN;
static const LL LMIN = LLONG_MIN;
static const int MOD = 1000000007;
static const int SIZE = 200005;

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

LL fac[SIZE], finv[SIZE], inv[SIZE];
void combInit() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for( int i = 2; i < SIZE; ++i ) {
        fac[i] = (fac[i - 1] * i) % MOD;
        inv[i] = MOD - inv[MOD % i] * (MOD / i) % MOD;
        finv[i] = (finv[i - 1] * inv[i]) % MOD;

    }
}

LL comb(int n, int k) {
    if( n < k ) return 0;
    if( n < 0 || k < 0 ) return 0;
    return (fac[n] * (finv[k] * finv[n - k] % MOD)) % MOD;

}

vector< int > Div( int n ) {
    vector< int > ret;
    for( int i = 1; i * i <= n; ++i ) {
        if( n % i == 0 ) {
            ret.pb( i );

            if( i * i != n ) ret.pb( n / i );
        }
    }
    sort( all( ret ) );
    return ret;
}

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

    int n;
    cin >> n;
    vector< LL > v(n);
    for( int i = 0; i < n; ++i ) {
        cin >> v[i];

    }

    LL bi_cnt[128] = {};
    for( int i = 0; i < n; ++i ) {
        LL tmp = v[i];
        int bi = 0;
        while( tmp > 0 ) {
            bi_cnt[bi] += tmp & 1;
            tmp >>= 1;
            ++bi;

        }

    }

    LL res = 0;
    for( int i = 0; i < 61; ++i ) {
        LL t = bi_cnt[i] * (n - bi_cnt[i]) % MOD;
        if( t == 0 ) continue;
        LL tmp = (1ll << i) % MOD;
        res += t * tmp % MOD;
        res %= MOD;

    }
    cout << res << endl;

    return 0;
}



Measured memory_bytes: 2560
#include <iostream>

int main()
{
    int n = 0;
    int r = 0;
    int rtn = 0;
    std::cin >> n >> r;

    if (n >= 10) {
        rtn = r;
    } else {
        int out = 100 * (10 - n);
        rtn = r + out; 
    }
    std::cout << rtn << std::endl;
    return 0;
}


Measured memory_bytes: 256
package main

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

var sc = bufio.NewScanner(os.Stdin)
var out = bufio.NewWriter(os.Stdout)

func main() {
	sc.Buffer(make([]byte, 0), 1e6) // maxTokenSize
	sc.Split(bufio.ScanWords)
	defer out.Flush()
	/* --- code --- */
	a := nextInt()
	b := nextInt()
	fmt.Println(a * b)

}

// -*-*-*-*-*-*-*-*-
// * I/O utilities *
// -*-*-*-*-*-*-*-*-

func next() string {
	sc.Scan()
	return sc.Text()
}

func nextInt() int {
	a, _ := strconv.Atoi(next())
	return a
}

func nextInt64() int64 {
	a, _ := strconv.ParseInt(next(), 10, 64)
	return a
}

func nextFloat64() float64 {
	a, _ := strconv.ParseFloat(next(), 64)
	return a
}

func nextInts(n int) []int {
	ret := make([]int, n)
	for i := 0; i < n; i++ {
		ret[i] = nextInt()
	}
	return ret
}
func nextFloats(n int) []float64 {
	ret := make([]float64, n)
	for i := 0; i < n; i++ {
		ret[i] = nextFloat64()
	}
	return ret
}
func nextStrings(n int) []string {
	ret := make([]string, n)
	for i := 0; i < n; i++ {
		ret[i] = next()
	}
	return ret
}

func split(s string) []string {
	ret := make([]string, len([]rune(s)))
	for i, v := range []rune(s) {
		ret[i] = string(v)
	}
	return ret
}

// -*-*-*-*-*-*-*-*-
// * tool snippets *
// -*-*-*-*-*-*-*-*-
func duplicate2Int(base [][]int) (ret [][]int) {
	ret = make([][]int, len(base))
	for i, v := range base {
		ret[i] = append([]int{}, v...)
	}
	return
}

func max(a, b int) int {
	return int(max64(int64(a), int64(b)))
}

func max64(a int64, b int64) int64 {
	if a < b {
		return b
	}
	return a
}

func min(a, b int) int {
	return int(min64(int64(a), int64(b)))
}

func min64(a int64, b int64) int64 {
	if a < b {
		return a
	}
	return b
}

// *-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-
// * math flavor typical theories *
// *-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-
func gcd(a, b int) int {
	if a > b {
		return gcd(b, a)
	}
	for a != 0 {
		a, b = b%a, a
	}
	return b
}

func pow(a, b int) (ret int) {
	ret = a
	for i := 0; i < b-1; i++ {
		ret *= a
	}
	return
}

func powMod(n, m, mod int) (ret int) {
	ret = 1
	for m > 0 {
		if m&1 == 1 {
			ret *= n
			ret %= mod
		}
		n *= n
		n %= mod
		m >>= 1
	}
	return ret
}


Measured memory_bytes: 1756
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
sys.setrecursionlimit(10 ** 7)

from functools import lru_cache

t = int(readline())
for _ in range(t):
    n, a, b, c, d = map(int, readline().split())

    @lru_cache(None)
    def check(n):
        if n == 0:
            return 0
        if n == 1:
            return d
        res = n * d
        if n % 2 == 0:
            res = min(res, check(n // 2) + a)
        else:
            res = min(res, check(n // 2) + a + d, check(n // 2 + 1) + a + d)
        if n % 3 == 0:
            res = min(res, check(n // 3) + b)
        else:
            res = min(res, check(n // 3) + b + (n % 3) * d, check(n // 3 + 1) + b + (3 - n % 3) * d)
        if n % 5 == 0:
            res = min(res, check(n // 5) + c)
        else:
            res = min(res, check(n // 5) + c + (n % 5) * d, check(n // 5 + 1) + c + (5 - n % 5) * d)
        return res


    print(check(n))


Measured memory_bytes: 11560
#include <iostream>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/assoc_container.hpp>
#include <bits/stdc++.h>
#define FIO ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define ll long long
using namespace std;
using namespace __gnu_pbds;

typedef tree<pair<long long int,long long int>,null_type,less<pair<long long int,long long int> >,rb_tree_tag,tree_order_statistics_node_update> ordered_set;

bool v[210002];
int ans[210002];
vector<int> adj[210002];
vector<int> a;
vector<int> curr;
stack<pair<int,int> > s;

void dfs(int node)
{
    v[node]=1;
    int idx=lower_bound(curr.begin(),curr.end(),a[node-1])-curr.begin();
    int init_val=curr[idx];
    curr[idx]=a[node-1];
    ans[node]=lower_bound(curr.begin(),curr.end(),INT_MAX)-curr.begin()-1;
    for(int i=0;i<adj[node].size();i++)
    {
        if(!v[adj[node][i]])
            dfs(adj[node][i]);
    }
    curr[idx]=init_val;
}
void go()
{
    memset(v,0,sizeof(v));
    memset(ans,1,sizeof(ans));
    int n;
    cin>>n;
    a.resize(n);
    for(int i=0;i<n;i++)
        cin>>a[i];
    for(int i=0;i<n-1;i++)
    {
        int p,q;
        cin>>p>>q;
        adj[p].push_back(q);
        adj[q].push_back(p);
    }
    curr.resize(n+1,INT_MAX);
    curr[0]=INT_MIN;
    dfs(1);
    for(int i=1;i<=n;i++)
        cout<<ans[i]<<endl;
}
int main()
{
    FIO;
//    int t;
//    cin>>t;
//    while(t--)
        go();
    return 0;
}


Measured memory_bytes: 25588