akhauriyash/Code-Regression huggingface dataset:
#include<iostream>
#include<algorithm>
#include<string>
#include<map>
#include<cmath>
#include<vector>
#include<queue>
#include<set>
#include<stdio.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
#define REP(i, x, n) for(int i = x; i < n; i++)
#define rep(i,n) REP(i,0,n)
#define INF 1e9

int h[100001];
int h2[100001];
int main()
{
	int n;
	cin >> n;

	rep(i, n) {
		cin >> h[i];
	}
	h2[0] = 0;
	h2[1] = abs(h[1] - h[0]);
	REP(i, 2, n) {
		h2[i] = min(abs(h[i] - h[i - 1]) + h2[i - 1], abs(h[i] - h[i - 2]) + h2[i - 2]);
	}
	cout << h2[n - 1] << endl;
	return 0;
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
//#include <ext/pb_ds/assoc_container.hpp>
//using namespace __gnu_pbds;
using namespace std;
typedef long long int ll;
typedef long double ld;
//typedef tree <int,null_type,less <int>, rb_tree_tag, tree_order_statistics_node_update> indexed_set;
#define FAST ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define rep(g, i, n) for (ll g = i; g < n; g++)
#define rev(g, n, i) for (ll g = n - 1; g >= i; g--)
#define all(v) v.begin(), v.end()
#define pb push_back
#define mxe(v) *max_element(v.begin(),v.end())
#define mne(v) *min_element(v.begin(),v.end())
#define ve vector
#define rem 1000000007
#define PI 3.141592653589793238462643383279502
ll power(ll x, ll y, ll p) 
{ 
    ll res = 1;      // Initialize result 
    x = x % p;  // Update x if it is more than or 
    while (y > 0) 
    { 
        if (y & 1) 
            res = (res*x) % p; 
        y = y>>1; // y = y/2 
        x = (x*x) % p; 
    } 
    return res; 
} 
ll modInverse(ll n, ll p) 
{ 
    return power(n, p-2, p); 
} 
struct point
{
    ll x,y;
};
int main()
{
    FAST
    // freopen("input1.txt", "r", stdin);
    // freopen("output.txt", "w", stdout);
    /*ll tests;
    cin>>tests;
    rep (gg,0,tests)
    {}*/
    ll n,m;
    cin>>n>>m;
    cout<<(n*(n-1))/2+(m*(m-1))/2;
}


Measured memory_bytes: 256
use std::io::*;
use std::cmp::*;

fn main() {
    let mut input = String::new();
    stdin().read_line(&mut input);

    let v = input.split_whitespace()
        .map(|x| x.parse().unwrap())
        .collect::<Vec<i32>>();

    println!("{}", max(v[2] - v[0] + v[1], 0));
}


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

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

    int n;
    cin >> n;
    int total_count = 0;
    for (int i = 1; i <= n; i += 2) {
        int count = 0;
        for (int j = 1; j <= i; j += 2) {
            count += (i % j == 0);
        }
        total_count += (count == 8);
    }

    cout << total_count << '\n';
    return 0;
}


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

int main() {
	string t;
	cin >> t;
	transform(t.begin(), t.end(), t.begin(), [](char c) { return tolower(c); });

	int count = 0;
	for (;;) {
		string w;
		cin >> w;
		if (w == "END_OF_TEXT") {
			break;
		}
		transform(w.begin(), w.end(), w.begin(), [](char c) { return tolower(c); });
		if (t == w) {
			count++;
		}
	}

	cout << count << endl;

	return 0;
}



Measured memory_bytes: 3212
import java.util.Scanner;

public class Main {
  static final long MOD = 998244353;
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    int n = sc.nextInt();
    int m = sc.nextInt();
    int k = sc.nextInt();
    long answer = 0;
    Combination com = new Combination(n, MOD);
    for(long i = 0; i <= k; i++){
      long temp = (long)m * com.pow(m - 1, n - i - 1) % MOD;
      temp = temp * com.c(n - 1, (int)i) % MOD;
      answer = (answer + temp) % MOD;
    }
    System.out.println(answer);
  }
}
class Combination {
  long[] factorial; //階乗
  long[] inverse; //逆元
  final long MOD;
  public Combination(int n, long mod){
    this.MOD = mod;
    factorial = new long[n + 1];
    inverse = new long[n + 1];
    factorial[0] = 1;
    inverse[0] = 1;
    for (int i = 1; i <= n; i++) {
      factorial[i] = factorial[i - 1] * i % MOD;
      inverse[i] = pow(factorial[i], MOD - 2);
    }
  }
  long p(int n, int r){
    return factorial[n] * inverse[n - r] % MOD;
  }
  long c(int n, int r){
    return factorial[n] * inverse[r] % MOD * inverse[n - r] % MOD;
  }
  long pow(long x, long n) {
    long answer = 1l;
    while (n > 0) {
      if((n & 1) == 1){
        answer = answer * x % MOD;
      }
      x = x * x % MOD;
      n >>= 1;
    }
    return answer;
  }
}

Measured memory_bytes: 38796
#include <iostream>
#define REP(i,n) for (int i = 0; (i) < (n); ++ (i))
using namespace std;
int main(){
    int N;
    cin >> N;
    int s[100];
    int smallest = 101;
    REP(i,N){
        cin >> s[i];
        if(smallest > s[i] && s[i] % 10 != 0){
            smallest = s[i];
        } 
    }
    int ans = 0;
    REP(i,N){
        ans += s[i];
    }
    if(ans % 10 == 0){
        if(smallest != 101){
            cout << ans - smallest << endl;
        }else{
            cout << 0 << endl;
        }
    }else{
        cout << ans << endl;
    }
    return 0;
}

Measured memory_bytes: 256
#pragma GCC optimize ("O3")
#pragma GCC target ("avx")
//#include<bits/stdc++.h>
#include<cstdio>
#include<algorithm>
#include<queue>
using namespace std;
typedef long long ll;
#define rep(i, n) for(int i = 0; i < (n); i++)
#define rep1(i, n) for(int i = 1; i <= (n); i++)
#define co(x) cout << (x) << "\n"
#define cosp(x) cout << (x) << " "
#define ce(x) cerr << (x) << "\n"
#define cesp(x) cerr << (x) << " "
#define pb push_back
#define mp make_pair
#define chmin(x, y) x = min(x, y)
#define chmax(x, y) x = max(x, y)
#define Would
#define you
#define please

const int cm = 1 << 15;
char cn[cm], * ci = cn, ct;
inline int getint() {
	int A = 0;
	while ((ct = *ci++) >= '0') A = A * 10 + ct - '0';
	return A;
}

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


	fread_unlocked(cn, 1, cm, stdin);
	int N = getint(), K = getint(), Q = getint();
	ll A[2002];
	int LR[2002] = {};
	rep1(i, N) A[i] = ((ll)getint() << 16) + i;

	priority_queue<int> q;
	priority_queue<int, vector<int>, greater<int>> q2[1001];
	vector<int> qv[1001];
	int q3[2002] = {};
	int kotae = 1e9;
	int saishou = 2e9;
	sort(A + 1, A + N + 1);
	const int m = (1 << 16) - 1;
	int qn = 1;

	int num[1002] = {};
	int qflg[1002] = {};
	for (int i = N; i >= 1; i--) {
		int a = A[i] >> 16;
		int k = A[i] & m;

		int l = !LR[k - 1] ? k : LR[k - 1];
		int r = !LR[k + 1] ? k : LR[k + 1];
		LR[l] = r;
		LR[r] = l;

		if (l == r) q3[l] = qn++;
		int kosuu = min(K - 1, k - l);
		int kosuu2 = min(K - 1, r - k);
		if (k + k < l + r) {
			swap(q3[l], q3[k + 1]);
			swap(kosuu, kosuu2);
		}
		num[q3[l]] = kosuu + kosuu2 + 1;
		if (num[q3[l]] >= K && !qflg[q3[l]]) qflg[q3[l]] = 1;
	}

	rep1(i, N) LR[i] = 0;
	rep1(i, N) q3[i] = 0;
	qn = 1;

	for (int i = N; i >= 1; i--) {
		int a = A[i] >> 16;
		int k = A[i] & m;

		int l = !LR[k - 1] ? k : LR[k - 1];
		int r = !LR[k + 1] ? k : LR[k + 1];
		LR[l] = r;
		LR[r] = l;

		if (l == r) q3[l] = qn++;
		int kosuu = min(K - 1, k - l);
		int kosuu2 = min(K - 1, r - k);
		if (k + k < l + r) {
			swap(q3[l], q3[k + 1]);
			swap(kosuu, kosuu2);
		}

		if (qflg[q3[l]]) {
			auto L = q2 + q3[l];
			if (qflg[q3[k + 1]]) {
				auto R = q2 + q3[k + 1];
				rep(j, kosuu2) {
					(*L).push((*R).top());
					(*R).pop();
					if (kosuu == K - 1) {
						q.push((*L).top());
						(*L).pop();
					}
					else kosuu++;
				}
			}
			else {
				auto R = qv + q3[k + 1];
				rep(j, kosuu2) {
					(*L).push((*R)[j]);
					if (kosuu == K - 1) {
						q.push((*L).top());
						(*L).pop();
					}
					else kosuu++;
				}
			}
			(*L).push(a);
			if (kosuu == K - 1) {
				q.push((*L).top());
				(*L).pop();
			}
			while (q.size() >= Q) {
				int tmp = q.top();
				chmin(saishou, tmp);
				q.pop();
			}
		}
		else {
			auto L = qv + q3[l];
			auto R = qv + q3[k + 1];
			rep(j, kosuu2) (*L).pb((*R)[j]);
			(*L).pb(a);
		}
		chmin(kotae, saishou - a);
	}

	printf("%d", kotae);

	Would you please return 0;
}

Measured memory_bytes: 384
//#include <bits/stdc++.h>
#include <iostream>
#include <vector>
#include <string>
#include <cmath>
#include <algorithm>
#include <map>
#include <iomanip>
#include <stdlib.h>
#include <queue>
#include <deque>
#include <set>
#include <stack>

using namespace std;

typedef long long ll;
const ll nmax = 1e9 + 7;
const ll mod = 998244353;
const long long INF = 1e18;
const double PI = 2 * asin(1);

int main(){
  
  int A, B; cin >> A >> B;
  cout << 6 - A - B << endl;

  return 0;
}


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

using namespace std;
#define ll long long
#define pb push_back
#define mp make_pair

int gcd(ll a, ll b)
{
   if (b == 0) return a;
   return gcd(b, a % b);
}

int main()
{
	ios::sync_with_stdio(false);
  	cin.tie(0);
	ll n,m;
	cin >> n >> m;
	string s,t;
	cin >> s >> t;
	if(gcd(n,m) == 0)
	{
		cout << "-1\n";
		return 0;
	}
	ll len = (n*m)/gcd(n,m);
	map<ll, char> y,z;
	y[0] = s[0];
	for(ll i=1;i<=n-1;i++)
	{
		char temp = s[i];
		y[(i*len)/n] = temp;
	}
	z[0] = t[0];
	for(ll i=1;i<=m-1;i++)
	{
		char temp = t[i];
		z[(i*len)/m] = temp;
	}
	bool ans = true;
	for(auto it: y)
	{
		if(z.find(it.first) != z.end() && z[it.first] != it.second)
		{
			ans = false;
			break;
		}
	}
	if(ans)
		cout << len << "\n";
	else
		cout <<  "-1\n";

	return 0;
}

Measured memory_bytes: 10880
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
typedef pair<int, int> P;

int main()
{
    int N, M;
    cin >> N >> M;

    auto c = [](P x, P y) { return x.first > y.first; };
    auto d = [](P x, P y) { return x.second < y.second; };

    priority_queue<P, vector<P>, decltype(c)> IN(c);
    priority_queue<P, vector<P>, decltype(d)> OUT(d);
    /*
    priority_queue<P, vector<P>, function<bool(P, P)>> 
    IN (
        [](P x, P y) { return x.first > y.first; }
    );

    priority_queue<P, vector<P>, function<bool(P, P)>>
    OUT (
        [](P x, P y) { return x.second < y.second; }
    );
    */

    for(int i = 0; i < N; ++i) {
        int atmp, btmp;
        cin >> atmp >> btmp;
        IN.push(make_pair(atmp, btmp));
    }

    ll cnt = 0;
    for(int i = 1; i <= M; ++i) {
        while(IN.top().first <= i && IN.size() > 0) {
            int atmp = IN.top().first,
                btmp = IN.top().second;
            OUT.push(make_pair(atmp, btmp));
            IN.pop();
        }

        if(OUT.size() > 0) { 
            cnt += OUT.top().second;
            OUT.pop();
        }
    }

    cout << cnt << endl;
    return 0;
}

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

#define fastio ios_base::sync_with_stdio(0);cin.tie(NULL);cout.tie(NULL)
#define lli long long int
#define rep(i,n,z) for(int i=z;i<n;i++)
#define rrep(i,z) for(int i=z;i>=0;i--)
#define nl cout<<endl
#define vi vector<int>
#define vlli vector<long long int>
#define umap unordered_map
#define pb push_back
#define mp make_pair
#define ss second
#define ff first
#define ipair pair <int,int>
#define llipair pair <lli,lli>
#define pq priority_queue
#define displaymatrix(a,m,n) for(int i=0;i<m;i++){for(int j=0;j<n;j++)cout<<a[i][j]<<" ";cout<<endl;}
#define printarray(a,n) for(int i=0;i<n;i++){cout<<a[i]<<" ";}nl;
#define vinput(a,n) vlli a(n);rep(i,n,0)cin>>a[i]
#define ainput(a,n) rep(i,n,0)cin>>a[i]
#define SO(a) sort(a.begin(),a.end())
#define all(x) (x).begin(),(x).end()
#define SOP(a,comp) sort(a.begin(),a.end(),comp)
#define inf INT_MAX
// #define endl '\n'

int main()
{
    fastio;
    int n;
    cin>>n;
    vinput(a,n);
    vector<llipair> z;
    rep(i,n,0)z.pb(mp(a[i],i));
    SO(z);
    reverse(all(z));
    lli dp[n+5][n+5];
    
    memset(dp,0,sizeof dp);

    for(int i = 0;i < n; i++){
        lli idx,val;
        tie(val,idx) = z[i];
        for(int j = 0; j <= i ; j++){
            dp[i+1][j+1] = max(dp[i+1][j+1],dp[i][j] + val*abs(j - idx));
            dp[i+1][j] = max(dp[i+1][j],dp[i][j] + val*(n-1 - idx - (i-j))); 
        }
    }

    lli ans = 0;
    rep(i,n,0)ans=max(ans,dp[n][i]);
    cout<<ans<<endl;
}

Measured memory_bytes: 35148
#include<iostream>
#include<string>
#include<vector>
#include <algorithm>
using namespace std;
int main() {
    int L,N;
    cin >> N >> L;
    int lengh = N * L;
    vector<string> str_S(N);
    for(int i=0;i<N;i++){
        string S;
        cin >> S ;
        str_S.at(i) = S;
    }
    sort(str_S.begin(), str_S.end());
    for(int i=0;i<N;i++){
        if(i==N-1){
            cout << str_S.at(i) << endl;
        }
        else{
            cout << str_S.at(i) ;
        }
        
    }
}

Measured memory_bytes: 3616
#include<iostream>
#include<cstdio>
#include<cstring>
#include<vector>
#include<algorithm>
#define ll long long
#define rep(i, a, b) for(int i = a; i <= b; i++)
void read(int &x) {
    x = 0; int flag = 1; char ch = ' ';
    while(ch < '0' || ch > '9') { if(ch == '-') flag = -1; ch = getchar(); }
    while(ch >= '0' && ch <= '9') x = x * 10 + ch - '0', ch = getchar();
    x *= flag;
}
void read(ll &x) {
    x = 0; int flag = 1; char ch = ' ';
    while(ch < '0' || ch > '9') { if(ch == '-') flag = -1; ch = getchar(); }
    while(ch >= '0' && ch <= '9') x = x * 10 + ch - '0', ch = getchar();
    x *= flag;
}
using namespace std;
const int maxn = 310;
int n, a[maxn], s[4];
double dp[maxn][maxn][maxn];
int main()
{
    read(n);
    rep(i, 1, n) read(a[i]), s[a[i]]++;
    dp[0][0][0] = 0;
    rep(k, 0, n)
        rep(j, 0, n - k)
            rep(i, 0, n - j - k) {
                if(!i && !j && !k) continue;
                int x = i + j + k;
                dp[i][j][k] += 1.0 * n / x;
                if(i) dp[i][j][k] += dp[i - 1][j][k] * i / x;
                if(j) dp[i][j][k] += dp[i + 1][j - 1][k] * j / x;
                if(k) dp[i][j][k] += dp[i][j + 1][k - 1] * k / x;
            }
    printf("%.12lf\n", dp[s[1]][s[2]][s[3]]);
    return 0;
}

Measured memory_bytes: 225536
#include<iostream>
using namespace std;
int const N=10;
int src[N];
int a[N+1], b[N+1];//a存放左边的球，b存放右边
int aindex;//记录左边有多少球
int bindex;//右边有多少球
int ans;//标记是否能找到

void dfs(int i){//dir 标记球放在哪一边
	if (i == N){ ans = 1; return; }
	//球i放在左边
	if (src[i]>=a[aindex]){
		a[++aindex] = src[i];
		dfs(i+1);
		aindex--;
	}
	//球放在左边
	if (src[i] >= b[bindex]){
		b[bindex] = src[i];
		dfs(i + 1);
		bindex--;
	}
	return;
}
int main(){
	int n;
	cin >> n;
	while (n--){
		ans = 0;
		aindex = 0; bindex = 0;
		a[aindex] = -9999; b[bindex] = -9999;
		for (int i = 0; i < N; i++){
			cin >> src[i];
		}
		dfs(0);
		if (ans)cout << "YES" << endl;
		else cout << "NO" << endl;
	}
}




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

int main() {
  ll n;cin>>n;
  vector<ll> v(n);
  rep(i,n) cin>>v.at(i);
  ll sum4 = 0,sum2 = 0;
  rep(i,n){
    if (v.at(i) % 4 == 0){
      sum4++;
    }
  }
  if (sum4*2 + 1 >= n){
    cout << "Yes" << endl;
    return 0;
  }
  else {
    rep(i,n){
      if (v.at(i) % 2 == 0){
        sum2++;
      }
    }
    if (sum4*2 + (sum2 - sum4) >= n){
      cout << "Yes" << endl;
      return 0;
    }
  }
  cout << "No" << endl;
}

Measured memory_bytes: 1024
#include<bits/stdc++.h>
using namespace std; 
typedef long long ll;
typedef long double ld;
#define pb push_back
#define fi first
#define se second
const ll mod = 1e9+7;
const int N = 2e5+5;
void solve(){
	int x; 
	cin>>x; 
	ll ans = 1;
	for(ll i=2;i*i<=x;i++){
		for(ll j=i*i;j<=x;j*=i){
			if(j<=x)ans = max(ans,j);
		}
	}
	cout<<ans<<endl;
}
int main(){
	ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
	int t=1; 
//	cin>>t; 
	while(t--){
		solve();
	}
	return 0;
}


Measured memory_bytes: 3632
' Imports System.Collections.Generic
' Imports System.Text.RegularExpressions

Class Main
    Public Shared Sub Main()
        Dim S As String = Console.ReadLine()
        Dim T As String = Console.ReadLine()
        Console.WriteLine(If(S = T.Substring(0, T.Length - 1), "Yes", "No"))
        Return
    End Sub
End Class


Measured memory_bytes: 26628
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define db double
#define pii pair<int,int>
#define pli pair<ll,int>
#define pil pair<int,ll>
#define pll pair<ll,ll>
const int inf = 1 << 30;
const ll linf = 1e18;
template<class T> void chmin(T& x, T y){if(x > y) x = y;}
template<class T> void chmax(T& x, T y){if(x < y) x = y;}

int N;
int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cin >> N;
    cout << (N + 1) / 2 << endl;
    return 0;
}

Measured memory_bytes: 256
S=[nil]+gets.chomp.codepoints
a,b,c,q="ABC?".codepoints
dp=Array.new(S.size){Array.new(4,0)}
dp[0][0]=1
for i in 1..S.size-1
  if S[i]==q
    4.times do |j|
      dp[i][j]+=dp[i-1][j]*3
    end
  else
    4.times do |j|
      dp[i][j]+=dp[i-1][j]
    end
  end
  dp[i][1]+=dp[i-1][0] if S[i]==a || S[i]==q
  dp[i][2]+=dp[i-1][1] if S[i]==b || S[i]==q
  dp[i][3]+=dp[i-1][2] if S[i]==c || S[i]==q
  4.times do |j|
    dp[i][j]%=1000000007
  end
end
puts dp[S.size-1][3]


Measured memory_bytes: 12268
#include<bits/stdc++.h>
using namespace std;
const int mod=1e9+7;
#define M 3
struct matrix{
	int a[M][M];
	matrix(){memset(a,0,sizeof(a));}
	matrix(int v[M][M]){memcpy(a,v,sizeof(a));}
    matrix one(){
        matrix ret;
        for(int i=0;i<M;i++) ret.a[i][i]=1;
        return ret;
    }
	matrix operator *(const matrix &b){
		matrix ret;
		for(int i=0;i<M;i++)
			for(int j=0;j<M;j++)
				for(int k=0;k<M;k++)
					ret.a[i][k]=(ret.a[i][k]+a[i][j]*1LL*b.a[j][k])%mod;
		return ret;
	}
    matrix operator ^(int k){
		matrix ret=one(),t=*this;
		while(k){
            if(k&1) ret=ret*t;
            t=t*t;k>>=1;
        }
        return ret;
	}
};

matrix tra1,tra2;//tra1可以放置隔板 tra2不行
void add(matrix &x,int k,int from,int to){//to += k*from
    x.a[to][from]+=k;
}
void buildtra(){//构建转移矩阵
    for(int i=0;i<=2;i++){
        add(tra1,1,i,i);//不放
        if(i!=2){//放一个球
            add(tra1,i==0? 2:1,i,i+1);
        }
        if(i==0){//放两个球
            add(tra1,1,i,i+2);
        }
    }
    tra2=tra1;
    //放隔板
    for(int i=0;i<=2;i++)
        tra1.a[0][i]+=tra1.a[2][i];
}

int n,m,pos[100005];
int main(){
    buildtra();
    scanf("%d%d",&n,&m);
    for(int i=1;i<=m;i++) scanf("%d",&pos[i]);
    matrix ans=ans.one();
    for(int i=1;i<=m;i++)
        ans=tra2*(tra1^(pos[i]-pos[i-1]-1))*ans;
    ans=(tra1^(n-pos[m]))*ans;
    cout<<ans.a[2][0]<<endl;
    return 0;
}

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

int main(){
  string S;
  cin >> S;
  
  int n = S.size(), ans = 0;
  for(int i = 0;i < n;i++){
    int cnt = 0;
    for(int j = i;j < n;j++){
      char b = S.at(j);
      if(b == 'A' || b == 'C' || b == 'G' || b == 'T') cnt++;
      else break;
      ans = max(ans, cnt);
    }
  }
  
  cout << ans << endl;
  
  return 0;
}

Measured memory_bytes: 3600
#include <iostream>
#include <algorithm>
using namespace std;
using ll = long long int;

ll MOD;
const int MAXN = 3010;
ll comb[MAXN + 10][MAXN + 10];

ll mod_pow(ll N, ll K, ll mod=MOD) {
    ll ret = 1; N %= mod;
    for(; K>0; K>>=1) {
        if(K & 1) (ret *= N) %= mod;
        (N *= N) %= mod;
    }
    return ret;
}

void init() {
    for(int i=0; i<MAXN; i++) {
        comb[i][0] = 1;
        for(int j=1; j<MAXN; j++) {
            comb[i][j] = (comb[i-1][j] + comb[i-1][j-1]) % MOD;
        }
    }
}

ll dp[3010][3010], ways[3010], ans;
int main() {
    int N; cin >> N >> MOD; init();// MOD はグローバル
    // dp (ways2 を求める)
    dp[0][0] = 1;
    for(int i=1; i<=N; i++) for(int j=0; j<=i; j++) {
        if(j > 0) (dp[i][j] += dp[i-1][j-1]) %= MOD;
        (dp[i][j] += (dp[i-1][j] * (j+1))) %= MOD;
    }
    // ways1 を求め、答えに足す
    for(int i=0; i<=N; i++) {
        for(int j=0; j<=i; j++) {
            (ways[i] += (dp[i][j] * mod_pow(2, (N-i)*j))) %= MOD;
        }
        (ways[i] *= mod_pow(2, mod_pow(2, N-i, MOD-1))) %= MOD;
        ll val = ways[i] * comb[N][i] % MOD;
        if(i % 2 == 0) ans = (ans + val      ) % MOD;
        else           ans = (ans - val + MOD) % MOD;
    }
    cout << ans << endl;
    return 0;
}

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

using namespace std;

const int N = 21;
int n;
int v[N], c[N];

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

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

    int ans = 0;
    for(int i = 0; i < n; i++)
    {
        if(v[i] < c[i])
            continue;
        ans += v[i] - c[i];
    }

    cout << ans;

    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define PI 3.14159265358979323846
#define MAXINF (1e18L)
#define INF (1e9L)
#define EPS (1e-9)
#define MOD ((ll)(1e9+7))
#define REP(i, n) for(int i=0;i<int(n);++i)
#define Rep(i,sta,n) for(int i=sta;i<n;i++)
#define RREP(i, n) for(int i=int(n)-1;i>=0;--i)
#define ALL(v) v.begin(),v.end()
#define FIND(v,x) (binary_search(ALL(v),(x)))
#define SORT(v) sort(ALL(v))
#define RSORT(v) sort(ALL(v));reverse(ALL(v))
#define DEBUG(x) cerr<<#x<<": "<<x<<endl;
#define DEBUG_VEC(v) cerr<<#v<<":";for(int i=0;i<v.size();i++) cerr<<" "<<v[i]; cerr<<endl
#define Yes(n) cout<<((n)?"Yes":"No")<<endl
#define YES(n) cout<<((n)?"YES":"NO")<<endl
#define pb push_back
#define fi first
#define se second
using namespace std;
template<class A>void pr(A a){cout << (a) << endl;}
template<class A,class B>void pr(A a,B b){cout << a << " "  ;pr(b);}
template<class A,class B,class C>void pr(A a,B b,C c){cout << a << " " ;pr(b,c);}
template<class A,class B,class C,class D>void pr(A a,B b,C c,D d){cout << a << " " ;pr(b,c,d);}
template<class T> inline bool chmin(T& a, T b){return a>b ? a=b, true : false;}
template<class T> inline bool chmax(T& a, T b){return a<b ? a=b, true : false;}
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll,ll> pll;

int main(void)
{
    ll Q,H,S,D;
    cin >> Q >> H >> S >> D;
    ll N;
    cin >> N;
    vector<ll> yen = {Q,H,S,D};
    vector<double> l = {0.25, 0.5, 1.0, 2.0};
    vector<pair<double, int>> a;
    REP(i, 4){
        a.pb(pair<double, int>(yen[i]/l[i], i));
    }
    SORT(a);

    ll ans = 0;
    REP(i, 4){
        while(N >= l[a[i].se]){
            ll n = N / l[a[i].se];
            ans += n * yen[a[i].se];
            N -= n * l[a[i].se];
        }
    }
    pr(ans);
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,a,b) for(int i=int(a);i<int(b);++i)
#define SIZE 200005
#define INF 1000000005LL
#define MOD 1000000007

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

int N;
string s;
int a[SIZE];

int solve(int i){
	if(s[i] == 'o'){
		if(a[i] == 1) return 1;
		else return -1;
	}else{
		if(a[i] == 1) return -1;
		else return 1;
	}
}

int main()
{
	cin >> N;
	cin >> s;
	int p[2] = {1,-1};
	int q[2] = {1,-1};
	rep(g,0,2) rep(h,0,2){
		a[0] = p[g];
		a[1] = q[h];
		rep(i,1,N-1){
			a[i+1] = a[i-1]*solve(i);
		}
		if(a[1]*solve(0) == a[N-1] && a[N-2]*solve(N-1) == a[0]){
			rep(i,0,N) cout << (a[i]==1?'S':'W') ;
			cout << endl;
			return 0;
		}
	}
	cout << -1 << endl;


	return 0;
}


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

long long rng(long long l, long long r) {
  static mt19937 mt(chrono::steady_clock::now().time_since_epoch().count());
  return uniform_int_distribution<long long>(l, r - 1)(mt);
}

struct RollingHash {
  static constexpr uint64_t m31 = (1LL << 31) - 1;
  static int mod_m31(uint64_t a) {
    a = (a >> 31) + (a & m31);
    return a >= m31 ? a - m31 : a;
  }
  static long long base[2];
  static vector<int> powb[2];
  vector<int> h[2];
  RollingHash(const vector<int>& s) : h{{0}, {0}} {
    for (int k : {0, 1}) {
      for (auto c : s) h[k].push_back(mod_m31(h[k].back() * base[k] + c));
      while (powb[k].size() <= s.size())
        powb[k].push_back(mod_m31(powb[k].back() * base[k]));
    }
  }
  int get(int l, int r, int k) const {
    return mod_m31(h[k][r] + (m31 - h[k][l]) * powb[k][r - l]);
  }
  auto get(int l, int r) const { return make_pair(get(l, r, 0), get(l, r, 1)); }
  int size() const { return h[0].size() - 1; }
  static int get(const vector<int>& s, int k) {
    long long res = 0;
    for (auto c : s) res = mod_m31(res * base[k] + c);
    return res;
  }
  static pair<int, int> get(const vector<int>& s) {
    return {get(s, 0), get(s, 1)};
  }
};
long long RollingHash::base[2] = {rng(1e9, 2e9), rng(1e9, 2e9)};
vector<int> RollingHash::powb[2] = {{1}, {1}};

int main() {
  cin.tie(nullptr);
  ios::sync_with_stdio(false);
  int n;
  cin >> n;
  vector<int> a(n);
  for (auto&& e : a) {
    cin >> e;
  }
  vector<int> b(n);
  for (auto&& e : b) {
    cin >> e;
  }
  vector<int> c(2 * n), d(n);
  for (int i = 0; i < 2 * n; ++i) {
    c[i] = a[i % n] ^ a[(i + 1) % n];
    if (i < n) {
      d[i] = b[i] ^ b[(i + 1) % n];
    }
  }
  RollingHash rh(c);
  auto h = rh.get(d);
  for (int k = 0; k < n; ++k) {
    if (rh.get(k, k + n) == h) {
      cout << k << ' ' << (a[k] ^ b[0]) << '\n';
    }
  }
}


Measured memory_bytes: 13808
#!usr/bin/env python3
from collections import defaultdict, deque
from heapq import heappush, heappop
from itertools import permutations
import sys
import math
import bisect

def LI(): return [int(x) for x in sys.stdin.readline().split()]


def I(): return int(sys.stdin.readline())


def LS(): return [list(x) for x in sys.stdin.readline().split()]


def S():
    res = list(sys.stdin.readline())
    if res[-1] == "\n":
        return res[:-1]
    return res


def IR(n):
    return [I() for i in range(n)]


def LIR(n):
    return [LI() for i in range(n)]


def SR(n):
    return [S() for i in range(n)]


def LSR(n):
    return [LS() for i in range(n)]


sys.setrecursionlimit(1000000)
mod = 1000000007


def solve():
    n, k = LI()
    p = LI()
    q = sorted(p)
    ans = 0
    for i in range(k):
        ans += q[i]
    print(ans)
    return


if __name__ == "__main__":
    solve()


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

/*#pragma GCC optimize("Ofast")
#pragma GCC optimize("no-stack-protector")
#pragma GCC optimize("unroll-loops")
#pragma GCC target("sse,sse2,sse3,ssse3,popcnt,abm,mmx,tune=native")   */


//#include <ext/pb_ds/assoc_container.hpp>

using namespace std;
//using namespace __gnu_pbds;

#define ss second
#define ff first
#define int long long
//#define double long double
#define pb push_back

const int N = 2e6 + 51, MOD = 1e9 + 7, mod = 998244353, INF = 2e18;

mt19937 Flash_new_51(51515);

using vi = vector <int>;
using vp = vector <pair <int, int>>;



signed main() {
    #ifdef Flash
     freopen("input.txt", "r", stdin);
    // freopen("output.txt", "w", stdout);
    #endif
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    string s, s1, s2, kek, kek1;
    cin >> s;
    kek = kek1 = s;
    reverse(kek.begin(), kek.end());
    int n = s.size();
    s = "3" + s;
    for (int i = 1; i <= (n - 1) / 2; i++) s1 += s[i];
    for (int i = (n + 3) / 2; i <= n; i++) s2 += s[i];
    string k = s1, k1 = s2;
    reverse(k.begin(), k.end());
    reverse(k1.begin(), k1.end());
    if (k == s1 && k1 == s2 && kek1 == kek) {
        cout << "Yes";
    }
    else cout << "No";

}


Measured memory_bytes: 256
## グリッドに関する処理
# ABC075B_Minesweeper

## 考え方：
# A NG:pandasに入れて、df.ilocによる行×列のスライスでうまくやる -> pandasはimport不可
# B:np.arrayに入れて、うまいことやる  # PyPy3ではnumpyもimport不可。python3は、numpyはimport可。
# C:シンプルに、きれいに書き直す

## for test
# # 1
# height, width = 3, 5
# _s_list = ['.....', '.#.#.', '.....']

# # 2
# height, width = 3, 5
# _s_list = ['#####', '#####', '#####']

# 3
# height, width = 6, 6
# _s_list = ['#####.', '#.#.##', '####.#', '.#..#.', '#.##..', '#.#...']


## for submit
import numpy as np
height, width = map(int, input().split())
_s_list = [input() for i in range(height)]
s_list = [list(ss) for ss in _s_list]  # 列×行に1文字ずつ区切ってリストへ追加 -> 2次元配列化
s_arr  = np.array(s_list)
# print(s_list)  # debug
# print(s_arr)  # debug

ans_list = []
for _h in range(height):
    ans_row_str = ''
    for _w in range(width):
        # # 周囲1マスずつを取得
        # 条件式が真のときに返す値 if 条件式 else 条件式が偽のときに返す値
        h_s = 0 if _h <= 1 else _h-1
        h_e = _h + 2  # 範囲外アクセスはエラーにならない（負の値でなければOK）
        
        w_s = 0 if _w <= 1 else _w-1
        w_e = _w + 2
        
        # チェック対象の中心が#なら#, それ以外はcount_nonzeroで'#'をカウントした結果の数値を文字列として保存
        if s_arr[_h, _w] == '#':
            ans_row_str += '#'
        else:
            ans_row_str += str(np.count_nonzero(s_arr[h_s:h_e, w_s:w_e] == '#'))
    
    print(ans_row_str) # 1行を出力


Measured memory_bytes: 21344
#include "bits/stdc++.h"
using namespace std;
#ifdef _DEBUG
#define dlog(str) cout << "====" << str << endl;
#else
#define dlog(str)
#endif
#define INF 999999999
#define MOD 1000000007
#define REP(i, n) for(int i = 0, i##_l = (n); i < i##_l; i++)
#define FOR(i, s, e) for(int i = s, i##_l = (e); i < i##_l; i++)
#define LLI long long int
#define _min(a,b) ((a<b)?a:b)
#define _max(a,b) ((a<b)?b:a)
#define chmax(a, b) a = _max(a, b)
#define chmin(a, b) a = _min(a, b)
#define bit(a, shift) ((a>>shift)&1))
#define pm(a) ((a)?1:-1)
#define SORT(v) sort(v.begin(),v.end())
#define RSORT(v) sort((v).rbegin(), (v).rend())
// int 2.14E±9    lli 9.2E±18    double 1.7E±380


int main()
{
	cout << fixed << setprecision(10);

	int a;
	cin >> a;


	cout << a+a*a+a*a*a;

	return 0;
}

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

int mod_num = 1e9 + 7;

int main(){
    long long N, K;
    std::cin >> N >> K;
    
    long long cnt = 0;
    for(long long i=K; i<=N+1; i++){
        long long min = i * (i - 1) / 2;
        long long max = N * i - min;
        cnt += max - min + 1;
        cnt = cnt % mod_num;
//    std::cout << max << " " << min << " " << cnt << std::endl;
    }
    std::cout <<  cnt << std::endl;
    
    
    return 0;
}



Measured memory_bytes: 3596
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
#define pii pair<int,int>
#define pll pair<ll,ll>
#define pb push_back
#define fi first
#define se second
#define UP(a,b,c) for(ll (a)=(b);(a)<(c);(a)++)
#define UU(a,b,c) for(ll (a)=(b);(a)<=(c);(a)++)
#define DN(a,b,c) for(ll (a)=(b);(a)>(c);(a)--)
#define DU(a,b,c) for(ll (a)=(b);(a)>=(c);(a)--)
#define MOD 1000000007

ll n, fact[1000005], p10[1000005], p8[1000005];

void reset()
{
	fact[0] = 1;
	p10[0] = 1;
	p8[0] = 1;
	UU(i,1,1000000)
	{
		p10[i] = p10[i - 1] * 10LL;
		if(p10[i] >= MOD)
		{
			p10[i] %= MOD;
		}
		
		p8[i] = p8[i - 1] * 8LL;
		if(p8[i] >= MOD)
		{
			p8[i] %= MOD;
		}
		
		fact[i] = fact[i - 1] * i;
		if(fact[i] >= MOD)
		{
			fact[i] %= MOD;
		}
	}
}

ll fast(ll times, ll val)
{
	if(times == 0)
	{
		return 1;
	}
	else if(times == 1)
	{
		return val;
	}
	else
	{
		ll ret = fast(times / 2, val);
		if(ret >= MOD)
			ret %= MOD;
		
		ret *= ret;
		if(ret >= MOD)
			ret %= MOD;
					
		if(times & 1)
		{
			ret *= val;
		}
		if(ret >= MOD)
			ret %= MOD;
					
		return ret;
	}
}

ll modex(ll val)
{
	return fast(MOD - 2, val) % MOD;
}

void input()
{
	cin>>n;
}

ll comb(ll n, ll r)
{
	ll ret = fact[n];
	ret *= modex(fact[n - r]);
	ret %= MOD;
	
	ret *= modex(fact[r]);
	ret %= MOD;
	
	return ret;
}

void solve()
{
	if(n < 2)
	{
		cout<<0<<endl;
		return ;
	}
	
	ll ret = p10[n];
	ret -= p8[n];
	
	ll temp = 0;
	
	UU(i,1,n)
	{
		temp += p8[n - i] * comb(n, i);
		if(temp >= MOD)
		{
			temp %= MOD;
		}
	}
	temp *= 2LL;
	temp %= MOD;
	
	ret -= temp;
	
	ret %= MOD;
	while(ret < 0) ret += MOD;
	ret %= MOD;
	
	cout<<ret<<endl;
}

void LetsRock()
{
	solve();
}

int main()
{
	ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
		
		reset();
		input();
		LetsRock();
	
	return 0;
}

Measured memory_bytes: 27064
#pragma GCC optmize("0fast")
#include <bits/stdc++.h>

using namespace std;

#define rep(i,n) for(int i=0;i<(n);++i)
#define reps(i,n) for(int i=1;i<=(n);++i)
#define all(x) (x).begin(),(x).end()
#define Fixed fixed << setprecision(12)
#define int int_fast64_t
using pii = pair<int,int>;
constexpr int INF  = 0x3f3f3f3f;
constexpr long long LINF = 0x3f3f3f3f3f3f3f3fLL;
constexpr int mod1 = 1e9+7; 
constexpr int mod2 = 998244353;
 
template <class A, class B> inline bool chmax(A &a, const B &b) { return b > a && (a = b, true); }
template <class A, class B> inline bool chmin(A &a, const B &b) { return b < a && (a = b, true); }
 
template <class T> using min_heap = priority_queue<T,vector<T>,greater<T> >;
template <class T> using max_heap = priority_queue<T>;
template <class A, class B> using umap = unordered_map<A,B>;

inline int updiv(int a,int b){ return (a + b - 1) / b; }
 
constexpr int dx[] = {1,0,-1,0,1,1,-1,-1};
constexpr int dy[] = {0,-1,0,1,1,-1,-1,1};

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

    int n ,k;
    cin >> n >> k;

    vector<int> a(n);

    rep(i,n){
        cin >> a[i];
    }

    //vector table(n+1, vector(64, 0));
    vector<vector<int> > table(n+1, vector<int>(64));

    rep(i,n){
        table[i+1][0] = a[i];
    }

    for(int i = 0; i < 63; ++i){
        for(int j = 1; j <= n; ++j){
            table[j][i+1] = table[table[j][i]][i];
        }
    }

    int now = 1;
    for(int i = 0; i < 63; ++i){
        if(1ll << i & k){
            now = table[now][i];
        } 
    }

    cout << now << '\n';

    return (0);
}

Measured memory_bytes: 112456
#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<cassert>
using namespace std;
inline int read(){
	int re=0,flag=1;char ch=getchar();
	while(!isdigit(ch)){
		if(ch=='-') flag=-1;
		ch=getchar();
	}
	while(isdigit(ch)) re=(re<<1)+(re<<3)+ch-'0',ch=getchar();
	return re*flag;
}
int n,first[100010],cnte;
struct edge{
	int to,next;
}a[200010];int sg[100010];
inline void add(int u,int v){
	a[++cnte]=(edge){v,first[u]};first[u]=cnte;
	a[++cnte]=(edge){u,first[v]};first[v]=cnte;
}
void dfs(int u,int f){
	int i,v;sg[u]=0;
	for(i=first[u];~i;i=a[i].next){
		v=a[i].to;if(v==f) continue;
		dfs(v,u);
		sg[u]^=(sg[v]+1);
	}
}
int main(){
	memset(first,-1,sizeof(first));
	n=read();int i,t1,t2;
	for(i=1;i<n;i++){
		t1=read();t2=read();
		add(t1,t2);
	}
	dfs(1,0);
	if(sg[1]) puts("Alice");
	else puts("Bob");
}

Measured memory_bytes: 7296
import java.util.*;
import java.io.*;

public class Main {
	
	public static void main(String[] args) throws Exception {
		FastScanner fs = new FastScanner();
		int x = fs.nextInt();
		if(x == 0)
			System.out.println(1);
		else
			System.out.println(0);
		
	}
	
	static class FastScanner {
		BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
		StringTokenizer st=new StringTokenizer("");
		String next() {
			while (!st.hasMoreTokens())
				try {
					st=new StringTokenizer(br.readLine());
				} catch (IOException e) {
					e.printStackTrace();
				}
			return st.nextToken();
		}
		
		int nextInt() {
			return Integer.parseInt(next());
		}
		int[] readArray(int n) {
			int[] a=new int[n];
			for (int i=0; i<n; i++) a[i]=nextInt();
			return a;
		}
		long nextLong() {
			return Long.parseLong(next());
		}
	}
}


Measured memory_bytes: 32676
#include<stdio.h>
#define MAX 10000
#define NIL -1

struct Node{int p,l,r;};
struct Node T[MAX];

void Preorder(int u) {
    if (u == NIL) return;
    printf(" %d", u); 
    Preorder(T[u].l); 
    Preorder(T[u].r); 
}


void Inorder(int u) {
    if (u == NIL) return;
    Inorder(T[u].l);  
    printf(" %d", u); 
    Inorder(T[u].r); 
}

void Postorder(int u) {
    if (u == NIL) return;
    Postorder(T[u].l); 
    Postorder(T[u].r);
    printf(" %d", u);
}

int main(){
  int i,n,e,l,r,root;

  scanf("%d", &n);
  for(i=0;i<n;i++){
    T[i].p=NIL;
  }

  for(i=0;i<n;i++){
    scanf("%d %d %d", &e, &l, &r);
        T[e].l = l;
        T[e].r = r;
        if (l != NIL)T[l].p = e;
        if (r != NIL)T[r].p = e;
  }

  for(i=0; i<n; i++){
        if(T[i].p == NIL)root = i;
  }


  printf("Preorder\n");
  Preorder(root);
  printf("\nInorder\n");
  Inorder(root);
  printf("\nPostorder\n");
  Postorder(root);
  printf("\n");
  return 0;

}



Measured memory_bytes: 2132
#include <iostream>
#include <vector>
#include <utility>
#include <algorithm>
#include <cstdlib>
#include <cmath>
#include <iomanip>

typedef long long ll;

using namespace std;

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

    vector<int> charge(b);

    for (int i = 0; i < b; i++) {
        cin >> charge[i];
    }

    // ソート後昇順
    sort(charge.begin(), charge.end(), greater<int>());

    bool flg = false;
    for (int i = 0; i < b; i++) {
        a -= charge[i];
        if (a <= 0) {
            flg = true;
            break;
        }
    }

    if (flg) {
        cout << "Yes" << endl;
    } else {
        cout << "No" << endl;
    }

    return 0;
}

Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
typedef int int__;
#define int long long
#define pb push_back
#define pi pair<int,int>
#define vpi vector<pi>
#define vi vector<int>
#define vvi vector<vi>
#define fi first
#define se second
#define forn(i, n)for(int i=0;i<int__(n);i++) 
#define sz(a)int__(a.size())
template <class A, class B> ostream& operator << (ostream& out, const pair<A, B> &a){return out << "(" << a.first << ", " << a.second << ")";}
template<class A>ostream& operator<<(ostream& out,const vector<A>&v){out<<"[";forn(i,sz(v)){if(i)out<<", ";out<<v[i];}return out<<"]";}
#define fast ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0)
int Mod(int x){const int mm=1000000007;x%=mm;if(x<0)x+=mm;return x;}
int Pow(int x,int n){if(n==0)return 1;int t=Pow(x,n/2);t=Mod(t*t);if(n&1)t=Mod(t*x);return t;}
#define watch(x) cout << #x << " : " << x << endl;
int gcd(int a,int b){if(b==0)return a;return gcd(b,a%b);}
#define all(x) x.begin(), x.end()

int__ main() {
	fast;

	int h,n; cin >> h >> n;
	vi a(n+1),b(n+1);

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

	vvi dp(n+1,vi (h+1,1e12));

	dp[0][0]=0;

	for(int i=1;i<=n;i++) {
		for(int j=0;j<=h;j++) {
			if(j - a[i] < 0) {
				dp[i][j] = min(dp[i-1][j],b[i]);
			}
			else {
				dp[i][j] = min(dp[i-1][j],dp[i][j-a[i]] + b[i]);
			}
		}
	}

	cout << dp[n][h] << endl;
}

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


def solve(N: int, A: int, B: int):
    count = N // (A + B)
    print(A * count + min(N - (A+B)*count, A))
    return


# Generated by 1.1.6 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    A = int(next(tokens))  # type: int
    B = int(next(tokens))  # type: int
    solve(N, A, B)

if __name__ == '__main__':
    main()


Measured memory_bytes: 3060
#include<bits/stdc++.h>
#define INF 1e9
#define llINF 1e18
#define MOD 1000000007
#define pb push_back
#define mp make_pair 
#define F first
#define S second
#define ll long long
#define vi vector<ll>
#define vvi vector<vi>
#define BITLE(n) (1LL<<((ll)n))
#define SHIFT_LEFT(n) (1LL<<((ll)n))
#define SUBS(s,f,t) ((s).substr((f),(t)-(f)))
#define ALL(a) (a).begin(),(a).end()
using namespace std;

int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  ll a,b;cin>>a>>b;
  for(ll i=1;i<=1111111;i++){
    if((ll)((double)i*0.08) == a &&
       (ll)((double)i*0.1) == b){
      cout<<i<<endl;
      return 0;
    }
  }
  cout<<-1<<endl;
  return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<algorithm>
#include <stdio.h>
#include<iostream>
#include<iomanip>
#include<cmath>
#include<array>
#include<vector>
#include<set>
#include <utility>
#include <map>
using namespace std;

long long int  euclid(long long int a,long long int b){
  if(a<b){
    long long int swap;
    swap=b;
    b=a;
    a=swap;
  }
  long long int r=a%b;
  while(r>0){
    a=b;
    b=r;
    r=a%b;
  }
  return b;
}

long long int lcm(long long int a, long long int   b){
  return a/euclid(a,b)*b;
}
int main(){
int n; cin>>n;

long long int t[100];

for(int i=0;i<n;i++)
cin>>t[i];


long long int ans=1LL;
for(int i=0;i<n;i++){
  ans=lcm(t[i],ans);
}

cout <<ans<<endl;
}


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

int	main()
{
  int	n, a = 0, b = 0;
  
  cin >> n;
  vector<int>	v(n);
  
  for (int i = 0; i < n; i++)
    cin >> v.at(i);
  sort(v.begin(), v.end(), greater<int>());
  int	i;
  for (i = 0; i < n - 1; i += 2)
  {
    a += v.at(i);
    b += v.at(i + 1);
  }
  if (i == v.size() - 1)
    a += v.at(i);
  cout << a - b << endl;
  return (0);
}

Measured memory_bytes: 3592
n = int(input())

s = input()

mm = 0

for i in range(1,n):
    s1 = s[0:i]
    s2 = s[i:n]
    a = set(s1)
    b = set(s2)
    c = a & b
    mm = max(mm, len(c))

print(mm)

Measured memory_bytes: 3064
#include<bits/stdc++.h>
using namespace std;
 
typedef long long ll;  
#define pb push_back
#define F first
#define S second
#define ppp pair<ll,pair<ll,ll>>
#define pp pair<ll,ll>
#define all(x) (x).begin(),(x).end()
#define pi 3.14159265358
#define MOD 998244353



int main()
{

    // #ifndef ONLINE_JUDGE
    // freopen("input.txt", "r", stdin);
    // freopen("output.txt", "w", stdout); 
    // freopen("error.txt", "w", stderr); 
    // #endif
    
     ios_base::sync_with_stdio(false);
     cin.tie(NULL);


     ll n,i,j,k;

     cin>>n;

     ll a[n];


     ll val=0;
     for(i=0;i<n;i++)
     {
        cin>>a[i];
        val=(val^a[i]);
     }


     for(i=0;i<n;i++)
      cout<<(val^a[i])<<" ";
     
      

}



Measured memory_bytes: 5176
#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <stack>
#include <queue>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>

using namespace std;

typedef long long ll;
typedef unsigned long long ull;

static const double EPS = 1e-8;
static const double PI = 4.0 * atan(1.0);
static const double PI2 = 8.0 * atan(1.0);

#define REP(i,n)	for(int i=0;i<(int)n;++i)
#define ALL(c)		(c).begin(),(c).end()
#define CLEAR(v)	memset(v,0,sizeof(v))
#define MP(a,b)		make_pair((a),(b))
#define ABS(a)		((a)>0?(a):-(a))
#define FOR(i,s,n)	for(int i=s;i<(int)n;++i)

int main(int argc, char **argv) {
	string S;
	cin >> S;
	bool a[4] = {};
	REP(i, S.length()) {
		switch (S[i])
		{
		case 'N': a[0] = true; break;
		case 'W': a[1] = true; break;
		case 'S': a[2] = true; break;
		case 'E': a[3] = true; break;
		}
	}
	cout << (a[0] != a[2] || a[1] != a[3] ? "No" : "Yes") << endl;
	return 0;
}


Measured memory_bytes: 256
//フィボナッチ数列
#include <iostream>

using namespace std;

int main(){
	int n;
	cin >> n;
	if (n < 2){
		cout << 1 << endl;
		return 0;
	}
	int* fibnum = new int [n];
	fibnum[0] = 1; fibnum[1] = 1;
	for (int i = 2; i <= n; ++i){
		fibnum[i] = fibnum[i - 1] + fibnum[i - 2];
	}
	cout << fibnum[n] << endl;

	return 0;
}

Measured memory_bytes: 1192
#include <stdio.h>
#include <stdlib.h>

const long int M = 998244353; // 64-bits

int main(void)
{
  int N;
  int* A;
  int i, s, len, k;
  int *lengths, *heads, *tails;
  int tail;
  int killed;
  long int result; // 64-bits
  
  scanf("%d",&N);
  A = malloc(sizeof(int)*N);
  for(i=0; i<N; i++) {
    scanf("%d",A+i);
    A[i]--;
  }

  s=0;
  if(A[0]==A[N-1]) {
    while(s<=N-1 && A[s]==A[0]) {
      s++;
    }
  }

  if(s==N) {
    if(A[0]==0) {
      result = 1;
      for(i=1;i<=N;i++) {
	result = (result * i) % M;
      }
    } else {
      result = 0;
    }
    printf("%ld\n",result);
    return(0);
  }

  lengths = calloc(N,sizeof(int));
  heads = malloc(sizeof(int)*N);
  tails = malloc(sizeof(int)*N);

  if(s > 0) {
    tail = A[0];
  } else {
    tail = A[N-1];
  }

  len= 1;
  for(i=s; i<N; i++) {
    if(i<N-1 && A[i+1]==A[i]) {
      len++;
    } else {
      if(i<N-1) {
	if(lengths[A[i+1]]>0) {
	  printf("%d\n",0);
	  return(0);
	} else {
	  heads[A[i]] = A[i+1];
	}
      } else {
	heads[A[i]] = A[0];
      }

      lengths[A[i]] = len;
      len = 1;
      tails[A[i]] = tail;
      tail = A[i];
    }
  }

  if(s > 0) {
    heads[A[0]] = A[s];
    lengths[A[0]] += s;
  }

  k = lengths[0];
  if(k == 0) {
    printf("%d\n",0);
    return(0);
  }

  result = 1;
  killed = 0;
  for(i=1; i<N; i++) {
    if(lengths[i] == 0) {
      result = (result * killed) % M;
      killed--;
    } else if(lengths[i] > k) {
      printf("%d\n",0);
      return(0);
    } else if(heads[i] > i && tails[i] > i) {
      if(lengths[i] != k) {
	printf("%d\n",0);
	return(0);
      }
    } else if(heads[i] < i && tails[i] < i) {
      result = (result * (k-lengths[i]+1)) % M;
      killed += (lengths[i]+k-2);
    } else {
      // head < i && tail > i
      // head > i && tail < i
      killed += (lengths[i]-1);
    }

    if(result == 0) {
      break;
    }
  }
  
  printf("%ld\n",result);

  return(0);
}

Measured memory_bytes: 4864
//clear adj and visited vector declared globally after each test case
//check for long long overflow
//while adding and subs check if mod becomes -ve
//while using an integer directly in a builtin function add ll

#include <bits/stdc++.h>
#define int long long
#define IOS std::ios::sync_with_stdio(false); cin.tie(NULL);cout.tie(NULL);cout.precision(dbl::max_digits10);
#define pb push_back
#define mod 1000000007 //998244353
#define lld long double
#define mii map<int, int>
#define mci map<char, int>
#define msi map<string, int>
#define pii pair<int, int>
#define ff first
#define ss second
#define all(x) (x).begin(), (x).end()
#define rep(i,x,y) for(int i=x; i<y; i++)
#define fill(a,b) memset(a, b, sizeof(a))
#define vi vector<int>
#define setbits(x) __builtin_popcountll(x)
typedef std::numeric_limits< double > dbl;
using namespace std;
const long long N=200005, INF=2000000000000000000;
int power(int a, int b)
    {
        if(a==0)
        return 0;
        int res=1;
        //a%=p;
        while(b>0)
        {
            if(b&1)
            res=(res*a);
            b>>=1;
            a=(a*a);
        }
        return res;
    }

int32_t main()
{
    IOS;
    int x;
    cin>>x;
    for(int i=0;i<=2000;i++)
    {
        for(int j=-1000;j<=1000;j++)
        {
            if((power(i, 5)-power(j, 5))==x)
            {
                cout<<i<<" "<<j;
                return 0;
            }
        }
    }
    return 0;
}

Measured memory_bytes: 3636
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
const ll MAX=50000;
ll mod=1e9+7;
#define setbits(x) __builtin_popcount(x)
#define setbitsll(x) __builtin_popcountll(x)
//#define endl '\n'
#define pb push_back
#define se second
#define fi first
#define maxe max_element
#define mine min_element
#define debug(x) cout<<#x<<" :: "<<x<<endl;
#define debug2(x,y) cout<<#x<<" :: "<<x<<"\t"<<#y<<" :: "<<y<<endl;
#define debug3(x,y,z) cout<<#x<<" :: "<<x<<"\t"<<#y<<" :: "<<y<<"\t"<<#z<<" :: "<<z<<endl;
#define debug4(x,y,z,w) cout<<#x<<" :: "<<x<<"\t"<<#y<<" :: "<<y<<"\t"<<#z<<" :: "<<z<<"\t"<<#w<<" :: "<<w<<endl;
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#define boost  ios::sync_with_stdio(0); cin.tie(0); cout.tie(0)

long long expo(ll x,ll n,ll M)
{
    if(n==0)
        return 1;
    else if(n%2 == 0)        //n is even
        return expo((x*x)%M,n/2,M);
    else                             //n is odd
        return (x*expo((x*x)%M,(n-1)/2,M))%M;

}

bool prime[10000001];
void fin()
{
    for(int i=2;i*i<=1000000;i++)
    {
        if(!prime[i])
        for(int j=i*i;j<=1000000;j+=i)
            prime[j]=true;
    }
}

void solve()
{
  string s;
  cin>>s;
  int n=s.length();
  if(s.length()%2)
    cout<<"No"<<endl;
  else
  {
      int i;
      for(i=0;i<n;i+=2)
      {
          if(s[i]!='h' || s[i+1]!='i')
            break;
      }
     // debug(i);
      if(i==(n))
        cout<<"Yes"<<endl;
      else
        cout<<"No"<<endl;
  }
}
int main(){
    boost;
  solve();
}


Measured memory_bytes: 256
n, m = gets.split.map(&:to_i)
m2 = 2*m

if n.even?
  m.times{|i|
    if i<(m/2)
      puts "#{i+1} #{m2-i+1}"
    else
      puts "#{i+1} #{m2-i}"
    end
  }
else
  m.times{|i| puts "#{i+1} #{m2-i}" }
end


Measured memory_bytes: 14356
#include <bits/stdc++.h>
using namespace std;
const int INF=1000000;
int dp[100010];
int main(){
  dp[0]=0;
  for(int n=1;n<=100000;n++){
    dp[n]=INF;
    int power=1;
    while(power<=n){
      dp[n]=min(dp[n],dp[n-power]+1);
      power*=6;
    }
    int power9=1;
    while(power9<=n){
      dp[n]=min(dp[n],dp[n-power9]+1);
      power9*=9;
    }
  }
  int N;
  cin>>N;
  cout<<dp[N]<<endl;
  return 0;
}


Measured memory_bytes: 640