akhauriyash/Code-Regression huggingface dataset:
/*==============================================*\
ID:          shahidul_brur

Name:     Md. Shahidul Islam
Study:      CSE, BRUR
Address:  Rangpur, Bangladesh

 mail: shahidul.cse.brur@gmail.com
 FB  : fb.com/shahidul.brur
 Blog: shahidul-brur.blogspot.com(in Bengali),
       shahidul-brur-en.blogspot.com(in English)
\*===============================================*/
#include<bits/stdc++.h>
//#include <ext/pb_ds/assoc_container.hpp> // Common file
//#include <ext/pb_ds/tree_policy.hpp> // Including tree_order_statistics_node_update
//using namespace __gnu_pbds;
using namespace std;
//typedef tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update> ordered_set;

//#pragma GCC optimize("O3")
//#pragma GCC optimize("unroll-loops")
//#pragma GCC target("avx,avx2,fma")

typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef pair<int, int> ii;
typedef pair<ll, int> li;
typedef pair<int, ll> il;
typedef vector<ii> vii;
typedef vector<il> vil;
typedef vector<li> vli;

#define ff first
#define ss second
#define pb push_back
#define mp make_pair
#define sz size()
#define all(a)  a.begin(), a.end()
#define mem(a, b)     memset(a, b, sizeof(a))
#define f0(i,b) for(int i=0;i<(b);i++)
#define f1(i,b) for(int i=1;i<=(b);i++)
#define f2(i,a,b) for(int i=(a);i<=(b);i++)
#define fr(i,b,a) for(int i=(b);i>=(a);i--)
#define rep(i,a,b,c) for(int i=(a);i!=(b);i+=(c))

int dx8[] = {0, 0, 1, 1, 1, -1, -1, -1};
int dy8[] = {1,-1, 1, -1, 0, 0, -1, 1};
int dx4[] = {0, 0, 1, -1};
int dy4[] = {1, -1, 0, 0};

const double pi = acos(-1.0);
const double eps = 1e-6;
const int mod = (int)1e9+7;
const int maxn = 300005;
const int logn = 20;
int a[maxn];
int main()
{
    ios_base::sync_with_stdio(0); cin.tie(NULL); cout.tie(NULL);
//    freopen("in_a.txt", "r", stdin);
//    freopen("out_a.txt", "w", stdout);
    int n;
    cin>>n;
    ll s = 0LL;
    f0(i,n) 
    {
        cin>>a[i];
        s+=a[i];
    }
    ll t = 0LL;
    f0(i,n-1)
    {
        s-=a[i];
        t += ((a[i]%mod) * (s%mod) ) % mod;
        t %= mod;
    }
    cout << t << "\n";
    return 0;
}


Measured memory_bytes: 4368
# -*- coding: utf-8 -*-
"""
http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=0186

"""
import sys
from sys import stdin
input = stdin.readline


def Cond(q1, b, mid, c1, c2):
    b -= (c1 * mid)
    if b < 0:
        return False
    b -= (c2 * (q1 - mid))
    if b < 0:
        return False
    return True


def solve(q1, b, c1, c2, q2):
    ub = q2
    lb = 1
    aizu_chicken = 0

    while (ub - lb) > 1:
        mid = (ub + lb) // 2
        if Cond(q1, b, mid, c1, c2):
            lb = mid
            aizu_chicken = max(aizu_chicken, mid)
        else:
            ub = mid

    if Cond(q1, b, lb, c1, c2):
        aizu_chicken = max(aizu_chicken, lb)
    if Cond(q1, b, ub, c1, c2):
        aizu_chicken = max(aizu_chicken, ub)

    b -= (aizu_chicken * c1)
    normal_chicken = b // c2
    if normal_chicken < 0 or aizu_chicken == 0:
        return False, 0, 0
    else:
        return True, aizu_chicken, normal_chicken


def main(args):
    while True:
        txt = input().strip()
        if txt[0] == '0':
            break

        q1, b, c1, c2, q2 = map(int, txt.split())
        result, aizu, normal = solve(q1, b, c1, c2, q2)
        if result is False:
            print('NA')
        else:
            print(aizu, normal)


if __name__ == '__main__':
    main(sys.argv[1:])
    

Measured memory_bytes: 7804
def main():
	N = int(input())
	a = list(map(int, input().split()))
	dp = [0 for i in range(N)]
	for i in range(N-1, -1, -1):
		dp[i] = a[i]
		prev = dp[i]
		for j in range(i+1, N):
			right = a[i] - dp[j]
			left = a[j] - prev
			if right > left:
				dp[j] = right
				prev = right
			else:
				dp[j] = left
				prev = left
	print(dp[-1])

main()

Measured memory_bytes: 3444
#include <algorithm>
#include <iostream>
#include <string>

using namespace std;

#define RPT(i, b, e) for (int i = (b); i <= (e); i++)
#define RPT0(i, n) RPT(i, 0, n - 1)
#define ALL(v) v.begin(), v.end()

void resolve()
{
    string S;
    int Q;
    cin >> S >> Q;

    string f, b;
    bool hanten = false;
    RPT0(i, Q)
    {
        int T;
        cin >> T;
        if (T == 1) {
            hanten = !hanten;
            continue;
        }

        int F;
        char C;
        cin >> F >> C;
        if ((!hanten && F == 1) || (hanten && F == 2))
            f.push_back(C);
        else
            b.push_back(C);
    }

    if (!hanten) {
        reverse(ALL(f));
        string ans = f + S + b;
        cout << ans << endl;
    } else {
        reverse(ALL(b));
        reverse(ALL(S));
        string ans = b + S + f;
        cout << ans << endl;
    }
}

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


Measured memory_bytes: 1300
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <set>
#include <queue>
#include <stack>
#include <tuple>
#include <cmath>
#include <iomanip>
#include <map>
#include <cstring>
#include <functional>
#include <cctype>
#include <locale>
#define ll long long
#define rep(i,n) for(int i=0;i<(n);i++)
#define rrep(i,n) for(int i=n-1;i>=0;i--)
#define fi first
#define se second
#define pb push_back
#define ALL(a) (a).begin(),(a).end()
using namespace std;
template<typename T1,typename T2> inline void chmin(T1 &a,T2 b){if(a>b) a=b;}
template<typename T1,typename T2> inline void chmax(T1 &a,T2 b){if(a<b) a=b;}
typedef pair<int,int> P;
typedef pair<long long,long long> Pll;
#define fout(num) cout << fixed << setprecision(20) << (num) << endl
//s[i]=tolower(s[i]); islower(s[i]); cout << tolower(s[i])はバグ
//vector<vector<ll>> dp(n,vector<ll>(n))
//2-dim:vector<vector<Type>> vv(n, vector<Type>(m, d));
//3-dim:vector<vector<vector<Type>>> vvv(n, vector<vector<Type>>(m, vector<Type>(l, d)));
const ll INF = 1e18;
signed main(){
    std::cin.tie(nullptr);
    std::ios_base::sync_with_stdio(false);
    ll a,b,c,d; cin >> a >> b >> c >> d;
    ll ans=-INF;
    chmax(ans,a*c);
    chmax(ans,a*d);
    chmax(ans,b*c);
    chmax(ans,b*d);
    cout << ans << endl;
}




Measured memory_bytes: 3648
n,m = map(int, input().split())
AC = 0
WA = 0
ACflag = [False for i in range(n)]
thisWA = [0 for i in range(n)]
for i in range(m):
    p,S = map(str, input().split())
    if ACflag[int(p)-1] == False:
        if S == 'AC':
            AC+=1
            ACflag[int(p)-1] = True
        if S == 'WA':
            thisWA[int(p)-1]+=1
            
for i in range(n):
    if ACflag[i] == True:
        WA+=thisWA[i]

print('{} {}'.format(AC, WA))

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

int n;
string s;

int main(){

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

    cin>>n;
    cin>>s;
    for(int i=0;i<s.size();i++){
        cout<<char((s[i]-'A'+n)%26+'A');
    }

    return 0;
}

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

int T,N,P[9],R[9],res,c;
char S[9];

void dfs(char *p,int d)
{
	int i,t;
	char s[9]={0};
	if(p[0]==0)
	{
		for(i=t=0;i<d;i++)t+=P[i];
		if(t==res)c++;
		if(T>=t&&abs(T-t)<abs(T-res))
		{
			c=0;
			memcpy(R,P,sizeof(R));
			res=t;
		}
		return;
	}
	for(i=0;i<strlen(p);i++)
	{
		s[i]=p[i];
		P[d]=atoi(s);
		dfs(p+i+1,d+1);
		P[d]=-1;
	}
	return;
}

int main()
{
	int i;
	for(;scanf("%d %s",&T,S),T;)
	{
		res=-1000000;
		c=0;
		memset(P,-1,sizeof(P));
		dfs(S,0);
		if(res==-1000000)puts("error");
		else if(c)puts("rejected");
		else
		{
		printf("%d",res);
		for(i=0;R[i]!=-1;i++)printf(" %d",R[i]);
		puts("");
		}
	}
	return 0;
}

Measured memory_bytes: 616
#include<iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<cmath>
#include<map>
#include<cstdio>
#include<stack>
#include<queue>
#include<fstream>
#include<cstdio>

using namespace std;
#define ok1 printf("ok1\n");
#define ok2 printf("ok2\n");
#define M 1000000
#define rep(i,n) for(int i=0;i<n;i++)
#define REP(i,s,n) for(int i=(s);i<(n);i++)
#define repr(i,n) for(int i=n-1;i>=0;i--)
#define REPR(i,s,n) for(int i=(s);i>=(g);(i)--)
#define all(a) (a).begin(),(a).end()
#define reall(a) (a).rbegin(),(a).rend()
#define pb push_back
#define MIN(a,b) a=min((a),(b))
#define MAX(a,b) a=max((a),(b))
#define SIZE(v) (int)v.size()


typedef vector<int> vi;
typedef vector<string> vs;
typedef long long ll;
typedef vector<ll> vll;

#ifdef TESTING
#define DEBUG fprintf(stderr,"====TESTING====\n")
#define VALUE(x) cerr << "The value of " << #x << " is " << x << endl
#define debug(...) fprintf(stderr, __VA_ARGS__)
#else
#define DEBUG 
#define VALUE(x)
#define debug(...)
#endif
/*
inline string IntToString(ll a) {
	char x[100];
	sprintf_s(x, "%lld", a); string s = x;
	return s;
}

inline ll StringToInt(string a) {
	char x[100]; ll res;
	strcpy_s(x, a.c_str()); sscanf_s(x, "%lld", &res);
	return res;
}
*/

inline string uppercase(string s) {
	int n = SIZE(s);
	rep(i, n) if (s[i] >= 'a' && s[i] <= 'z') s[i] = s[i] - 'a' + 'A';
	return s;
}

inline string lowercase(string s) {
	int n = SIZE(s);
	rep(i, n) if (s[i] >= 'A' && s[i] <= 'Z') s[i] = s[i] - 'A' + 'a';
	return s;
}


int main()
{
	ll n, t, ans = 0;
	cin >> n >> t;
	vll v(n);
	for (int i = 0; i < n; i++) {
		cin >> v[i];
	}
	ans += t;
	for (int i = 1; i < n; i++) {
		if (v[i] - v[i - 1] > t)
			ans += t;
		else
			ans += (v[i] - v[i - 1]);

			
		//cout << ans << " ";
	}
	//cout << endl;
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 1792
#include <iostream>
#include <cstring>
#include <utility>
#include <vector>
#include <cmath>
#include <algorithm>
using namespace std;
typedef long long ll;


int main() {
    int N;
    cin >> N;
    int h[N];
    for (int i =0; i < N; i++) {
        cin >> h[i];
    }
    int c[N];
    c[0] = 0;
    c[1] = abs(h[1] - h[0]);
    for (int i = 2; i < N; i++) {
        c[i] = min(c[i-1]+abs(h[i]-h[i-1]), c[i-2]+abs(h[i]-h[i-2]));
    }
    cout << c[N-1] << endl;
}


Measured memory_bytes: 1024
def main():
    N = int(input())
    mod = 1000000007

    nine, eight, seven = 1, 1, 1
    for i in range(N):
        nine *= 10
        eight *= 9
        seven *= 8
        nine %= mod
        eight %= mod
        seven %= mod

    res = nine - (2 * eight) + seven
    res %= mod

    print(res)


if __name__ == "__main__":
    main()

Measured memory_bytes: 63100
import re

A,B=map(int,input().split())
S=input()

if len(S)==A+B+1:
    for i in range(A):
        if not('0'<=S[i]<='9'):
            print('No')
            exit()
    if S[A]!='-':
        print('No')
        exit()
    for j in range(B):
        if not('0'<=S[A+1+j]<='9'):
            print('No')
            exit()
    print('Yes')
    exit()
print('No')


Measured memory_bytes: 3188
#include <algorithm>
#include <cmath>
#include <cstdio>

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

using namespace std;

int main(){
	int n; scanf("%d",&n);
	int x[100],y[100],h[100];
	rep(i,n) scanf("%d%d%d",x+i,y+i,h+i);

	rep(cy,101) rep(cx,101) {
		int lo=0,hi=1e9+1000;
		while(lo<hi){
			int mi=(lo+hi+1)/2;
			bool b=true;
			rep(i,n) if(max(mi-abs(x[i]-cx)-abs(y[i]-cy),0)>h[i]) b=false;
			if(b) lo=mi;
			else  hi=mi-1;
		}

		bool ok=true;
		rep(i,n) if(max(lo-abs(x[i]-cx)-abs(y[i]-cy),0)!=h[i]) ok=false;
		if(ok){
			printf("%d %d %d\n",cx,cy,lo);
			break;
		}
	}


	return 0;
}


Measured memory_bytes: 256
import collections


def bfs(s_node):
    q = collections.deque()
    q.append(s_node)
    used = set()
    used.add(s_node)
    points[s_node] += X[s_node]

    while len(q) > 0:
        prv_node = q.popleft()
        for node in g[prv_node]:
            if node in used:
                continue
            else:
                points[node] += points[prv_node] + X[node]
                q.append(node)
                used.add(node)


N, Q = map(int, input().split())
g = {i: [] for i in range(N)}
for _ in range(N-1):
    a, b = map(int, input().split())
    g[a-1].append(b-1)
    g[b-1].append(a-1)

X = [0 for _ in range(N)]
for _ in range(Q):
    p, x = map(int, input().split())
    X[p-1] += x

points = [0 for _ in range(N)]
bfs(0)
print(*points)


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

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

    ll N, M;
    cin >> N >> M;
    cout << abs(N-2)*abs(M-2) << endl;
}

Measured memory_bytes: 256
#pragma GCC optimize ("O3")
#pragma GCC target ("sse4")
#pragma GCC optimize("Ofast")
#pragma GCC target("avx,avx2,fma")
#include <bits/stdc++.h>
using namespace std;
#include <ext/pb_ds/assoc_container.hpp> 
#include <ext/pb_ds/tree_policy.hpp> 
using namespace __gnu_pbds; 
#define ordered_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update> 
#define FAST  ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
#define ll long long int 
#define ar array
#define pb push_back
#define fi(a,b) for(int i=a;i<(b);i++)
#define fj(a,b) for(int j=a;j<(b);j++)
#define fk(a,b) for(int k=a;k<(b);k++)
#define lb lower_bound
#define ub upper_bound
//hash base 177013

const int mod=1e9+7;

int main()
{
	FAST;
	//#ifndef ONLINE_JUDGE
	//	freopen("input.txt","r",stdin);
	//	freopen("output.txt","w",stdout);
	//#endif
	//ll testcase;
	//cin>>testcase;
	//while(testcase--)
	{
		int n;
		cin>>n;
		int a[n+1][n+1];
		fi(0,n)
		{
			fj(0,n)
			{
				cin>>a[i][j];
			}
		}
		//return 0;
		int dp[1<<n];
		for(int i=0;i<(1<<n);i++)
		{
			dp[i]=0;
		}
		dp[0]=1;
		//return 0;
		for(int i=0;i<(1<<n);i++)
		{
			//return 0;
			int x=0;
			//cout<<q<<'\n';
			//exit(0);
			//cout<<i<<'\n';
			//return 0;
			for(int j=0;j<n;j++)
			{
				if(i&(1<<j)) x++;
			}
			//exit(0);
			if(x>=n) break;
			//return 0;
			//cout<<x<<'\n';
			for(int j=0;j<n;j++)
			{
				//assert(x<n);
				//return 0;
				if(!(i&(1<<j))&&a[j][x])
				{
					//assert((i|(1<<j))<n);
					dp[i|(1<<j)]=(dp[i|(1<<j)]+dp[i])%mod;
				}
			}
			//return 0;
		}
		//fi(0,21)
		//{
			//cout<<dp[i]<<' ';
		//}
		//cout<<dp[0];
		cout<<dp[(1<<n)-1];
		
		
	}
}


Measured memory_bytes: 11820
#include<bits/stdc++.h>
using namespace std;
int main(){
  int a,b,c,x;
  cin>>a>>b>>c>>x;

  int cnt=0;

  for(int i=0;i<=a;i++){
    for(int j=0;j<=b;j++){
      for(int  k=0;k<=c;k++){
	if(500*i+100*j+50*k==x){
	  cnt++;
	}
      }
    }
  }

  cout<<cnt<<endl;

  return 0;
}


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

using namespace std;

int main()
{
  string in;
  cin >> in;

  int n = 0;
  for( int i=0;i<in.length(); i++)
    {
      if( in[i] == '+')
	n++;
      else
	n--;
    }

  cout << n << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ll long long
#define ull unsigned long long
#define FOR(i,a,b) for (int i=(a);i<(b);++i)
#define REP(a,b) for(int a=0;a<(b);++a)
#define REP1(i,n) for(int i=1;i<=(n);++i)
#define debug(x) cerr<<#x<<": "<<x<<'\n'
#define all(x) (x).begin(),(x).end()
#define YES() printf("YES\n")
#define NO() printf("NO\n")
#define isYES(x) printf("%s\n",(x) ? "YES" : "NO")
#define Yes() printf("Yes\n")
#define No() printf("No\n")
#define isYes(x) printf("%s\n",(x) ? "Yes" : "No")
#define SZ(x) ((int)(x).size())
#define pb push_back
#define mp make_pair
#define INF (1<<29)
#define Sp(p) cout<<setprecision(25)<< fixed<<p<<endl
#define vi vector<int>
#define vl vector<ll>
#define vii vector< vector<int> >
#define vll vector< vector<ll> >
#define vs vector<string>
#define pii pair<int,int>
#define pis pair<int,string>
#define psi pair<string,int>
#define pll pair<ll,ll>
#define X first
#define Y second
#define pie 3.14159265358979323846
using namespace std;
typedef pair<int, int> P;
typedef pair<ll, ll> LP;
typedef pair<int, P> PP;
typedef pair<ll, LP> LPP;
template<class T=int>
T in(){T x;cin>>x;return (x);}
template<class T>
void print(T& x){cout<<x<<'\n';}

const int MOD =(int)1e9+7;
const int mod =(int)1e9+7;
const int MAX =510000;
ll fac[MAX],finv[MAX],inv[MAX];
void COMint(){
    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;
    }
}
ll 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;
}
ll gcd(ll a,ll b){
    if(b==0)return a;
    if(a>b){
        swap(a,b);
    }
    return gcd(a,b%a);
}
ll lcm(ll a,ll b){
    ll g;g=gcd(a,b);
    return a*b/g;
}
bool compare_by_b(pair<int, int> a, pair<int, int> b) {
    if(a.second != b.second){
        return a.second < b.second;
    }else{
        return a.first < b.first;
    }
}

bool compare_by_a(pair<int, int> a, pair<int, int> b) {
    if(a.first != b.first){
        return a.first < b.first;
    }else{
        return a.second < b.second;
    }
}
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 RS(ll N,ll P,ll M){
    if(P==0){
        return 1;
    }else{
        if(P%2==0){
            ll t=RS(N,P/2,M);
            return t*t%M;
        }else{
            return N*RS(N,P-1,M)%M;
        }
    }
}
bool greater_pair(pair<ll,ll> a,pair<ll,ll> b){
    if(a.first!=b.first){
        return a.first>b.first;
    }else{
        return a.second>b.second;
    }
}
int main() {
    ios::sync_with_stdio(false);
    int N,K;
    cin>>N>>K;
    vector<int> ans(N,0);
    REP(i,K){
        int d=in();
        REP(j,d){
            int a=in();
            a--;
            if(ans[a]==0)ans[a]=1;
        }
    }
    int answer=0;
    REP(i,N){
        if(ans[i]==0)answer++;
    }
    cout<<answer<<endl;
    return 0;
}

Measured memory_bytes: 3656
#include "bits/stdc++.h"
using namespace std;
int main() {
	long long j; cin >> j;
		long long N = j, tmp = 1, M = 1;
		for (long long i = 1; tmp + pow(26, i) <= N; i++) {
			tmp += (long long)pow(26, i);
			M++;
		}
		N -= tmp;
		vector<char>S(M, 'a'); //52
		for (long long i = M - 1; i >= 0; i--) {
			if (i != 0) {
				long long mod = N / (long long)pow(26, i);
				S.at(M - 1 - i) += mod;
				N -= mod * (long long)pow(26, i);
			}
			else {
				S.at(M - 1) += (N % 26);
			}
		}
		for (long long i = 0; i < M; i++) {
			cout << S.at(i);
		}
		cout << endl;
}

Measured memory_bytes: 4000
import java.util.*;
public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int a = sc.nextInt();
		int b = sc.nextInt();
		int count = 0;
		for(int i = a; i <= b; i++) {
			int n5 = i / 10000;
			int n4 = (i / 1000) % 10;
			int n2 = (i / 10 ) % 10;
			int n1 = i % 10;
			if(n5 == n1 && n4 == n2) count++;			
		}
        System.out.println(count);
		}	
}


Measured memory_bytes: 21844
from scipy.sparse import*
e=enumerate
_,*s=open(0)
r=s+['#'*20]
*g,=eval('[0]*500,'*500)
for i,t in e(s):
 for j,u in e(t):k=i*20+j;g[k][k+1]=u>'#'<t[j+1];g[k][k+20]=u>'#'<r[i+1][j]  
a=csgraph.johnson(csr_matrix(g),0)
print(int(max(a[a<999])))

Measured memory_bytes: 19244
#include <iostream>
#include <vector>
#include <string>
#include <utility>
#include <algorithm>
#include <map>
#include <cstdio>
#include <cassert>
using namespace std;

const int MOD = 1e9 + 7;
const int MAXN = 10000;
const int MAXD = 100;
int dp[MAXN+1][MAXD][2];

void add_self(int& a, int b) {
	a += b;
	if (a >= MOD) a -= MOD;
}

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

	string s;
	int d;
	cin >> s >> d;
	
	int n = s.length();
	dp[0][0][0] = 1;
	for (int i = 0; i < n; i++) {
		for (int j = 0; j < d; j++) {
			int k = s[i] - '0';
			add_self(dp[i+1][(j+k)%d][0], dp[i][j][0]);

			for (int x = 0; x < k; x++) {
				add_self(dp[i+1][(j+x)%d][1], dp[i][j][0]);
			}
			
			for (int x = 0; x < 10; x++) {
				add_self(dp[i+1][(j+x)%d][1], dp[i][j][1]);
			}
		}
	}
	
	int answer = (dp[n][0][0] + dp[n][0][1]) % MOD - 1;	// exclude 0
	if (answer < 0) answer += MOD;
	cout << answer << endl;
}


Measured memory_bytes: 8064
#include <stdio.h>
#include <math.h>
#include <string.h>
#include <stdlib.h>
#include <stdbool.h>
#define _USE_MATH_DEFINES

int main()
{
    char t[4]="";
    scanf("%s",t);

    if(t[1]=='R')
	printf("ABC\n");
    else
	printf("ARC\n");

    return 0;
}



Measured memory_bytes: 1620
N=int(input())
a=list(map(int,input().split()))
ans=0
def f(n):
  ans=0
  while n%2==0:
    n=int(n/2)
    ans+=1
  return ans
List=[]
for i in range(N):
  if a[i]%2==1:
    pass
  else:
    List.append(a[i])
if len(List)==0:
  print(0)
else:
  for i in range(len(List)):
    ans+=f(List[i])
  print(ans)

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

typedef long long ll;

ll gcd(ll a, ll b){
    return b == 0 ? a : gcd(b, a%b);
}

ll lcm(ll a, ll b){
    return a*b/gcd(a,b);
}

int main(){
    int n;
    while(cin >> n, n){
        ll d[n], v[n], mother, child;
        cin >> d[0] >> v[0];
        ll g = gcd(d[0], v[0]);
        d[0] /= g, v[0] /= g;
        mother = v[0], child = d[0];
        for(int i = 1; i < n; i++){
            cin >> d[i] >> v[i];
            ll g = gcd(d[i], v[i]);
            d[i] /= g, v[i] /= g;
            mother = gcd(v[i], mother);
            child = lcm(d[i], child);
        }
        
        for(int i = 0; i < n; i++){
            cout << (child*v[i])/(d[i]*mother) << endl;
        }
    }
    return 0;
}


Measured memory_bytes: 3068
'use strict'

const main = (input) => {
    const s = input.split('\n')[0]
    const t = input.split('\n')[1]

    const s1 = s.split('').sort().join('')
    const t1 = t.split('').sort().reverse().join('')

    if(s1 < t1){
        console.log('Yes')
    }else{
        console.log('No')
    }
}

main(require('fs').readFileSync('/dev/stdin', 'utf-8'))

Measured memory_bytes: 7500
#include <stdio.h>
#include <algorithm>
using namespace std;
using ll = long long;

int n, v[20], c[20], s = 0;
int main() {
	scanf("%d", &n);
	for (int i = 0; i < n; i++)
		scanf("%d", v + i);
	for (int i = 0; i < n; i++)
		scanf("%d", c + i);
	for (int i = 0; i < n; i++)
		if (c[i] < v[i])
			s += v[i] - c[i];
	printf("%d\n", s);
}

Measured memory_bytes: 128
#include <iostream>
#include <string>
#include <algorithm>
#include <map>
#include <vector>

using namespace std;

int main()
{
    int A, B;
    cin >> A >> B;
    if(A >= 13){
        cout << B << endl;
    }else if(A >= 6 && A <= 12){
        cout << B/2 << endl;
    }else{
        cout << 0 << endl;
    }
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define mod 1000000007
vector<vector<int>>dp; // dp(i,j) ways when i children and ith children get j candies
vector<int>v;



void solve(){
    int n,k;cin>>n>>k;
    v.resize(n);
    dp.resize(n,vector<int>(k+1,-1));
    for(int i=0;i<n;i++){
        cin>>v[i];
    }
    for(int i=0;i<=k;i++){
        dp[0][i] = i<=v[0] ? 1 :0;
    }
    for(int i=0;i<n;i++){
        dp[i][0]=1;
    }
    for(int i=1;i<n;i++){
        for(int j=1;j<=k;j++){
            dp[i][j] = (mod + (dp[i-1][j] +dp[i][j-1])%mod - ((j-v[i]-1>=0) ? dp[i-1][j-v[i]-1]: 0))%mod;
        }
    }
    cout<<dp[n-1][k]<<"\n";
}

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

    cout.precision(10);
    int t=1;//cin>>t;
    while(t--){

        solve();
    }
    return 0;
}


Measured memory_bytes: 39808
#include <iostream>
#include <string>
#include <unordered_set>

using namespace std;

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

  unordered_set<char> set;

  for ( auto& c : s ) {
    if ( set.count( c ) == 0 ) {
      set.emplace( c );
    } else {
      cout << "no" << endl;
      return 0;
    }
  }

  cout << "yes" << endl;

  return 0;
}


Measured memory_bytes: 256
use proconio::*;

#[fastout]
fn run() {
    input! {
        n: usize,
    }
    let mut ans = vec![0; n + 1];
    let w = 100usize;
    for x in 1..=w {
        for y in 1..=w {
            for z in 1..=w {
                let k = x.pow(2) + y.pow(2) + z.pow(2) + x * y + y * z + z * x;
                if k <= n {
                    ans[k] += 1;
                }
            }
        }
    }
    for ans in ans.iter().skip(1) {
        println!("{}", *ans);
    }
}

fn main() {
    run();
}

Measured memory_bytes: 2204
using System;
using System.Collections.Generic;
using System.Linq;
using System.Numerics;

namespace AtCoder
{
    class Program
    {
        static void Main(string[] args)
        {
            //[summary]B - Training Camp
            var lines = ReadLines<int>(1).ToList();
            int n = lines[0][0];

            long remainder = CalcRemainder(n);
            Console.WriteLine(remainder);
        }

        static long CalcRemainder(int n)
        {
            long power = 1;
            int divisor = (int)Math.Pow(10, 9) + 7;

            for (int i = 1; i <= n; i++)
            {
                power *= i;

                if (power > divisor)
                {
                    power %= divisor;
                }
            }

            return power % divisor;
        }
                               
        static IEnumerable<List<T>> ReadLines<T>(int count = 0, char separator = ' ')
        {
            //[summary]コンソールの値を読み込んで、List<T>のコレクションを返却

            //読み込む行数が未指定のときは、1行目の値を"count"とみなす
            if (count == 0)
            {
                string line = Console.ReadLine().TrimEnd();
                count = int.Parse(line);
            }

            for (int i = 0; i < count; i++)
            {
                //コンソールを1行読み込み
                string line = Console.ReadLine().TrimEnd();

                //char型のときは1文字ずつに分割
                if (typeof(T) == typeof(char))
                {
                    var list = line.ToCharArray().ToList();
                    yield return (List<T>)(object)list;
                }
                else
                {
                    //読み込んだ値を"separator"で区切る
                    var list = line.Split(separator).ToList();

                    //int型のときは数値に変換
                    if (typeof(T) == typeof(int))
                    {
                        var numbers = list.ConvertAll(int.Parse);
                        yield return (List<T>)(object)numbers;
                    }
                    else
                    {
                        yield return (List<T>)(object)list;
                    }
                }
            }
        }
    }
}


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

bool possible(const int N, const int M, const int K)
{
    for (int n = 0; n <= N; n++)
        for (int m = 0; m <= M; m++)
            if (n*M + m*N - 2*m*n == K)
                return true;
    return false;
}

int main()
{
    int N, M, K;
    cin >> N >> M >> K;
    cout << (possible(N, M, K) ? "Yes" : "No") << endl;
}


Measured memory_bytes: 384
//This is the Property of Rishabh Agarwal
#include <bits/stdc++.h> 
#define F first 
#define S second 
#define MAX 10000003 
using namespace std; 
 
typedef long long int ll; 
const ll mod = 1000000007;
ll isPalindrome(string str) 
{ 
    int l = 0; 
    int h = str.length() - 1; 
  
    while (h > l) 
    { 
        if (str[l++] != str[h--]) 
        { 
            return 0; 
        } 
    } 
    return 1;
} 
map<ll,ll>f;
vector<ll>v;
int main() 
{ 
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    long double l;
    ll n;
    cin>>n;
    for(ll x=0; x<n; x++){
        ll y;
        cin>>y;
        v.push_back(y);
        f[v[x]]++;
    }
    ll a[2][n];
    ll sum=0;
    for(ll x=1; x<=n; x++){
        ll p=0,q=0;
        if(f[x]>1){
            p=f[x]*(f[x]-1)/2;
        }
        if(f[x]>2){
            q=(f[x]-1)*(f[x]-2)/2;
        }
        sum+=p;
        a[0][x-1]=p;
        a[1][x-1]=q;
        //cout<<p<<" "<<q<<"\n";
    }
    //cout<<sum<<" \n";
    for(ll x=0; x<n; x++){
        ll ans=sum+a[1][v[x]-1]-a[0][v[x]-1];
        cout<<ans<<"\n";
    }
    return 0;
}

Measured memory_bytes: 19824
using System;
using System.Collections;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Numerics;
using System.Text;
using System.Text.RegularExpressions;
using System.Threading.Tasks;
using static System.Math;
using MethodImplAttribute = System.Runtime.CompilerServices.MethodImplAttribute;
using MethodImplOptions = System.Runtime.CompilerServices.MethodImplOptions;

public static class P
{
    public static void Main()
    {
        var nk =  Console.ReadLine().Split().Select(int.Parse).ToArray();
        var res = 0;
        while (nk[0] != 0)

        {
            nk[0] /= nk[1];
            res++;
        }
        Console.WriteLine(res);
    }
}

Measured memory_bytes: 13268
import java.util.Scanner;

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

		int[] n = new int[6];
		for(int i=0; i<6; i++)
		{
			n[i] = scanner.nextInt();
		}
		
		String str = scanner.next();
		for(int i=0; i<str.length(); i++)
		{
			String s = str.substring(i, i+1);
			
			int[] buf = new int[6];
			for(int j=0; j<6; j++)
			{
				buf[j] = n[j];
			}
			
			switch(s)
			{
				case "S":
					n[0] = buf[4];
					n[1] = buf[0];
					n[5] = buf[1];
					n[4] = buf[5];
					break;
				case "N":
					n[0] = buf[1];
					n[1] = buf[5];
					n[5] = buf[4];
					n[4] = buf[0];
					break;
				case "W":
					n[0] = buf[2];
					n[2] = buf[5];
					n[5] = buf[3];
					n[3] = buf[0];
					break;
				case "E":
					n[0] = buf[3];
					n[3] = buf[5];
					n[5] = buf[2];
					n[2] = buf[0];
					break;
			}
		}
		System.out.println(n[0]);
	}
}

Measured memory_bytes: 26212
#include<bits/stdc++.h>
using namespace std;
/*#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
typedef tree<long long,null_type,less<long long>,rb_tree_tag,tree_order_statistics_node_update> ordered_set;
s.find_by_order(x) xth element in set
x.order_of_key(x) number of elements <x*/
#define ll long long
#define vi vector<int>
#define si set<int>
#define mii map<int,int>
#define pb push_back
#define pf push_front
#define pii pair<int,int>
#define extract_word(s)  stringstream str(s); while(str>>word)
#define fastio ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define SET(s) cout<<fixed<<setprecision(s)
#define chotu 1000000007
#define set0(a) memset(a,0,sizeof(a))
#define endl "\n"
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define lower_string(s) transform(all(s),s.begin(),::tolower())
#define upper_string(s) transform(all(s),s.begin(),::toupper())
#define size(s) s.size()
template<class T> bool umin(T &a, T b) { return a > b ? (a = b, true) : false; }
template<class T> bool umax(T &a, T b) { return a < b ? (a = b, true) : false; }
template<typename T,typename U>
bool compare(T x,U y){return(abs(x-y)<=1e-9);}
void solve()
{
fastio
int n,a,b;
cin>>n>>a>>b;
cout<<min((n*a),b);
}
int main()
{
//code
fastio
int t;
t=1;
while(t--)
{
solve();
cout<<endl;
}
}


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

using Pii = pair<int, int>;
using Pll = pair<ll, ll>;

#define REP(i, l, n) for(int i=(l), i##_len=(n); i<i##_len; ++i)
#define ALL(x) (x).begin(),(x).end()
#define pb push_back

ll gcd(ll a,ll b){return b ? gcd(b,a%b) : a;}
ll lcm(ll a,ll b){return a/gcd(a,b)*b;}

template<class T>
inline bool chmax(T &a, T b) {
    if(a < b) {
        a = b;
        return true;
    }
    return false;
}
 
template<class T>
inline bool chmin(T &a, T b) {
    if(a > b) {
        a = b;
        return true;
    }
    return false;
}

char alpha[26] = {'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z'};

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

int main(){
    ll n; cin >> n;
    n--;
    string ans = "";
    while(n >= 0){
        //cout << n << endl;
        int c = n % 26;
        //cout << c << endl;
        ans = alpha[c] + ans;
        n /= 26;
        n--;
    }
    cout << ans << endl;
}

Measured memory_bytes: 3624
#include<bits/stdc++.h>
#define r(i,n) for(int i=0;i<n;i++)
using namespace std;
int n,q1,q2;
double a[86400],L,t;
bool check(double x){
  double p=L;
  r(i,86400){
    p-=a[i]-x;
    if(p>L)p=L;
    if(p<0)return 0;
  }
  double tx=p;
  r(i,86400){
    tx-=a[i]-x;
    if(tx>L)tx=L;
    if(tx<0)return 0;
  }
  return p-tx<1e-5;
}
int main(){
  while(cin>>n>>L,n){
    memset(a,0,sizeof(a));
    r(i,n){
      cin>>q1>>q2>>t;
      for(int i=q1;i<q2;i++)a[i]=t;
    }
    double r=1e11,l=0;
    r(i,147){
      double mid=(r+l)/2.0;
      if(check(mid))r=mid;
      else l=mid+1e-10;
    }
    printf("%.10f\n",l);
  }
}

Measured memory_bytes: 3952
#include <iostream>
#include <vector>
#include <algorithm>
#include <list>

using namespace std;

int calc(vector<int> ABC){
    int sum = 0;
    int max_abc;
    max_abc = *std::max_element(ABC.begin(),ABC.end());
    for(auto abc : ABC){
        sum += (max_abc - abc)/2;
    }
    return sum;
}


int main(){

    vector<int> ABC;
    ABC.resize(3);
    cin >> ABC[0] >> ABC[1] >> ABC[2];

    int ki_c = 0;
    for(auto abc : ABC){
        if(abc%2 != 0) ki_c ++;
    }

    int sum = 0;
    if(ki_c == 0 || ki_c == 3){
        cout << calc(ABC) << endl;
    }
    else if(ki_c == 1){

        for(auto &abc : ABC){
            if(abc%2 == 0) abc++;
        }
        cout << calc(ABC)+1 << endl;
    }
    else{

        for(auto &abc : ABC){
            if(abc%2 != 0) abc++;
        }
        cout << calc(ABC)+1 << endl;
    }

    return 0;
}

Measured memory_bytes: 256
def sol():
    n=int(input())
    a=list(map(int,input().split()))
    if 0 in a:
        print(0)
        return
    prod=1 
    for i in a:
        prod*=i 
        if prod>1000000000000000000:
            print(-1)
            return
    print(prod)
    
sol()

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

int main(){
  int n,a;
  cin >> n >> a;
  if(n/500==0){
    cout << "Yes" <<endl;
  }
  else if(n%500<=a){
    cout << "Yes"<< endl;
  }
  else{
    cout <<"No"<<endl;
  }
}


Measured memory_bytes: 3576
import math
from collections import Counter


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

n_pears = 0
counter = Counter(A)

for i in reversed(range(0, len(A))):
    if counter[A[i]] <= 0:
        continue
    counter[A[i]] -= 1
    Aj = 2 ** int(math.log2(A[i]) + 1) - A[i]
    if counter[Aj] > 0:
        n_pears += 1
        counter[Aj] -= 1

print(n_pears)

Measured memory_bytes: 33288
N, K = map(int, input().split())
d = ((N-2)+1)*(N-2)//2
# 一番多いパターンは、1つの頂点に他のすべての頂点が隣接しているパターン

if d < K:
    print(-1)
    exit(0)

ret = N-1 + (d - K)
print(ret)
# 頂点１にすべての頂点をつけていく
for i in range(2, N+1):
    print(1, i)
d -= K
idl = 2
idr = 3
while(d):
    print(idl, idr)
    d -= 1
    idr += 1
    if idr > N:
        idl += 1
        idr = idl+1



Measured memory_bytes: 3608
def resolve():
  N, K = map(int, input().split(" "))
  A = [int(x) - 1 for x in input().split(" ")]

  current = 0
  if K < N:
    for i in range(K):
      current = A[current]
    print(current + 1)
    return True
  else:
    history = [False] * N
    load_map = []
    while True:
      load_map.append(current)
      current = A[current]
      if history[current]:
        loop_length = len( load_map[load_map.index(current):] )
        if loop_length == 0:
          print(current + 1)
          return True

        length_to_loop = len( load_map[:load_map.index(current)] )
        additional_way = (K-length_to_loop)%loop_length
        print(load_map[length_to_loop + additional_way] + 1)
        return True
      else:
        history[current] = True

if __name__ == "__main__":
    resolve()

Measured memory_bytes: 103176
#include <cstdio>
#include <vector>
#include <algorithm>
#include <iostream>


using namespace std;

int n;
int a[100001];
int b[100001];
long long ans;
int i, j;
int main( void ) {
  scanf("%d", &n);
  for (int i = 0; i < n; i++)
    scanf("%d %d", a + i, b + i);

  for (int i = n -1; i >= 0; i--)
    if ((a[i] + ans) % b[i] != 0)
        ans += (b[i] - (a[i] + ans) % b[i]);
  cout << ans << endl;


  return 0;
}


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

using namespace std;
#define inf 1000000000
#define unvisited -1
#define visited 1
#define eps 1e-9
#define mp make_pair
#define pb push_back
#define pi acos(-1.0)
#define uint64 unsigned long long
#define FastSlowInput ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
#define debug if(true)
typedef long long ll;
typedef vector<int> vi;
typedef pair<int,int> ii;
typedef vector<ii> vii;

int main(){
	int n;
	map<string, int> mapper;
	scanf("%d",&n);
	int cnt = 0;
	for(int i=0;i<n;i++){
		string s;
		cin>>s;
		if(mapper.find(s) == mapper.end()){
			cnt++;
			mapper[s] = 1;
		}
	}
	printf("%d\n",cnt);
	
	return 0;
};

Measured memory_bytes: 19416
n, y = gets.split.map(&:to_i)
 
y/=1000
y-=n # 全部千円の場合の不足額

if y < 0
  puts [-1,-1,-1] * " "
  exit
end

if y == 0
  puts [0,0,n] * " "
  exit
end

# p y
m=y%4; y-=9*m # 万札必要量
if y < 0
  puts [-1,-1,-1] * " "
  exit
end
m+=y/36*4; y%=36 # 万札貪欲
g=y/4 # 五千円札
s=n-m-g # 残りが千円札
ans = s < 0 ? [-1,-1,-1] : [m, g, s]
puts ans * " "

Measured memory_bytes: 1788
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<math.h>
using namespace std;
/*int main()
{
	int n; cin>>n;
	int a[n];
	for(int i=0;i<n;i++) cin>>a[i];
	sort(a,a+n);
//	for(int i=0;i<n;i++) cout<<a[i];
	int sum=0;
	for(int i=n-1;i>1;i--)
	{
		for(int j=i-1;j>0;j--)
		{
			if(a[i]==a[j]) continue;
			for(int k=j-1;k>=0;k--)
			{
				if(a[k]!=a[i] and a[k]!=a[j] and a[i] < (a[k] + a[j])) 
				{
					sum++;
				}
				
				if(a[k]!=a[i] and a[k]!=a[j] and a[i] >= (a[k] + a[j])) 
				{
					break;
				}
				
			}
		}
	}
	
	cout<<sum;
}

int main()
{
	int n,d,ans=0;
	cin>>n>>d;
	while(n--)
	{
		int a,b; cin>>a>>b;
		long long int fl=a*a + b*b;
		float sum=sqrt(fl);
		if(sum<=d) ans++;
		
	}
	cout<<ans;
}
int main()
{
	int n,k; cin>>n>>k;
	int a[n],sum=0;
	for(int i=0;i<n;i++) cin>>a[i];
	sort(a,a+n);
	for(int i=0;i<k;i++) sum+=a[i];
	cout<<sum; 
}

int main()
{
	int n,k; cin>>n>>k;
	k%2==0 and k>=2*n and k<=4*n ? cout<<"Yes" : cout<<"No";
}

int main()
{
	int n; cin>>n;
	int a[n];
	for(int i=0;i<n;i++) cin>>a[i];
	unsigned long long ans=1,ANS;
	vector<int>v;
	for(int i=0;i<n;i++)
	{
		ans*=a[i];
		ANS=ans;
		while(ANS)
		{
			v.push_back(ANS%10);
			ANS/=10;
		}
		if(v.size()>1000000000000000000)
		{
			cout<<"HRE";
			cout<<"-1";
			return 0;
		}
		v.clear();
	}
	cout<<ans;
}

int main()
{
	int n; cin>>n;
	string s; cin>>s;
	if(s.size()<=n) cout<<s;
	else {
		
	for(int i=0;i<n;i++) cout<<s[i];
	cout<<"...";
}}

int main()
{
	long long int a,b,c,d; cin>>a>>b>>c>>d;
	long long int sum=0,count=0;
	if(a<=d)
	{
		sum+=a;
		d-=a;
		if(d==0)
		{
			cout<<sum;
			return 0;
		}
	}
	else 
	{
		cout<<d;
		return 0;
	}
	
		if(b<=d)
	{
		
		d-=b;
		if(d==0)
		{
			cout<<sum;
			return 0;
		}
	}
	else 
	{
		cout<<d;
		return 0;
	}
	
		if(c<=d)
	{
		sum-=c;
		d-=c;
		if(d==0)
		{
			cout<<sum;
			return 0;
		}
	}
	else 
	{
		cout<<sum-d;
		return 0;
	}
	
	
}


int main()
{
	int n,k; cin>>n>>k;
	int a[n];
	for(int i=0;i<n;i++) a[i]=0;
	while(k--)
	{
		int d; cin>>d;
		for(int i=0;i<d;i++) 
		{
			int x; cin>>x;
			a[x-1]++;
		}
	}
	//cout<<a[2];
	int ans=0;
	for(int i=0;i<n;i++) if(a[i]==0) ans++; cout<<ans;
}
int main()
{
	long long int n,year=0; cin>>n;
	int a=100;
	while(a<n)
	{
		float aa=(1.0/100)*a;
		a+=floor(aa);
		year++;
	}
	cout<<year;
}
int main()
{
	long long int n,m; cin>>n>>m;
	long long int sum=0,a[n];
	for(long long int i=0;i<n;i++)
	{
		cin>>a[i];
		sum+=a[i];	
	} 
	sort(a,a+n,greater<int>());
	float min=sum*1.0/(4*m);
	a[m-1]<min?cout<<"No": cout<<"Yes\n";	
}

int main()
{
	int n; cin>>n;
	long long sum=(n/500)*1000 + ((n-(n/500)*500)/5)*5;
	cout<<sum;
}

int main()
{
	string s; cin>>s;
	
	if(s.size()%2==0) 
	{
		cout<<"No";
		return 0;
	}
	
	if(s.size()==3) 
	{
		cout<<"Yes";
		return 0;
	}
	int si=s.size()/2;
	for(int i=0;i<si/2;i++)
	{
		if(s[i]!=s[si-i-1]) 
		{
			cout<<"No";
			return 0; 
		}
	}
	int aa=s.size();
	for(int i=si+1;i<si+si/2+1;i++)
	{
		if(s[i]!=s[aa-1]) 
		{
			cout<<"No";
			return 0;
		}
		aa--;
	}
	
	cout<<"Yes";
}
*/

int main()
{
	long long int n,a,b; cin>>n>>a>>b;
	long long int sum=n/(a+b)*a;
	n=n%(a+b);
	if(n<=a) sum+=n;
	else sum+=a;
	cout<<sum;
}


Measured memory_bytes: 3224
A, B, C, D = [int(i) for i in input().split()]
player1 = C//B
if C % B != 0:
    player1 += 1
player2 = A//D
if A % D != 0:
    player2 += 1
if player1 <= player2:
    print("Yes")
else:
    print("No")

Measured memory_bytes: 61656
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll,ll> P;
bool dp[85][85][12800]={0};
ll val[85][85]={0};
ll k1[85][85]={0},k2[85][85]={0};
int main(){
  ll h,w;
  cin>>h>>w;
  for(int i=0;i<85;i++){
    for(int j=0;j<85;j++){
      for(int k=0;k<12800;k++) dp[i][j][k]=false;
    }
  }
  for(int i=1;i<=h;i++){
    for(int j=1;j<=w;j++) cin>>k1[i][j];
  }
  for(int i=1;i<=h;i++){
    for(int j=1;j<=w;j++) cin>>k2[i][j];
  }
  for(int i=1;i<=h;i++){
    for(int j=1;j<=w;j++){
      ll a1=k1[i][j],a2=k2[i][j];
      val[i][j]=abs(a1-a2);
    }
  }
  dp[1][1][val[1][1]]=true;
  for(int i=1;i<=h;i++){
    for(int j=1;j<=w;j++){
      for(int k=0;k<12800;k++){
        if(dp[i][j][k]){
          if(i<h){
            ll nval=abs(k+val[i+1][j]),nval2=abs(k-val[i+1][j]);
            dp[i+1][j][nval]=true;
            dp[i+1][j][nval2]=true;
          }
          if(j<w){
            ll nval=abs(k+val[i][j+1]),nval2=abs(k-val[i][j+1]);
            dp[i][j+1][nval]=true;
            dp[i][j+1][nval2]=true;
          }
        }
      }
    }
  }
  for(int i=0;i<12800;i++){
    if(dp[h][w][i]){
      cout<<i<<endl;
      return 0;
    }
  }
}


Measured memory_bytes: 90752
#include <bits/stdc++.h>
using namespace std;
using str = string;
using ll = long long;
#define REP(i,n) for(int i=0; i<int(n); i++)
#define RREP(i,n) for(int i=int(n)-1; i>=0; i--)
#define FOR(i,f,t) for(int i=int(f); i<=int(t); i++)
#define RFOR(i,f,t) for(int i=int(f); i>=int(t); i--)
#define ALL(vec) (vec).begin(),(vec).end()
#define ASORT(vec) sort(ALL(vec))
#define DSORT(vec) sort(ALL(vec), greater<int>());
#define MAX(x) *max_element(ALL(x))
#define MIN(x) *min_element(ALL(x))
#define YES(ans) if(ans) cout<<"YES"<<endl; else cout<<"NO"<<endl;
#define Yes(ans) if(ans) cout<<"Yes"<<endl; else cout<<"No"<<endl;
#define yes(ans) if(ans) cout<<"yes"<<endl; else cout<<"no"<<endl;

int main() {
    int n, m, s=0;
    cin >> n;
    REP(i, n) {
        cin >> m;
        if(i%2 == 0) {
            if(m%2 == 1) {
                s++;
            }
        }
    }
    cout << s << endl;
}


Measured memory_bytes: 3628
# C - Many Requirements

from itertools import combinations_with_replacement

n, m, q = map(int, input().split())
lst = []
for i in range(q):
    a, b, c, d = map(int, input().split())
    lst.append((a, b, c, d))

x = max(sum(d for a, b, c, d in lst if seq[b-1] - seq[a-1] == c)
        for seq in combinations_with_replacement(range(1, m+1), n))
print(x)


Measured memory_bytes: 9052
import java.util.*;

public class Main{
   public static void main(String[] args) {
	  Scanner sc =new Scanner(System.in);
int a,b;
while(sc.hasNext()){
int n1=sc.nextInt();
int n2=sc.nextInt();
a=Math.max(n1,n2);
b=Math.min(n1,n2);
for(;;){
a =a%b;
if(a==0)break;
int temp=b;
b=a;
a=temp;
}
System.out.println(b+" "+(long)n1*n2/b);
   }
   }
}

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

#define _p(...) (void)printf(__VA_ARGS__)
#define forr(x,arr) for(auto&& x:arr)
#define _overload3(_1,_2,_3,name,...) name
#define _rep2(i,n) _rep3(i,0,n)
#define _rep3(i,a,b) for(int i=int(a);i<int(b);++i)
#define rep(...) _overload3(__VA_ARGS__,_rep3,_rep2,)(__VA_ARGS__)
#define _rrep2(i,n) _rrep3(i,0,n)
#define _rrep3(i,a,b) for(int i=int(b)-1;i>=int(a);i--)
#define rrep(...) _overload3(__VA_ARGS__,_rrep3,_rrep2,)(__VA_ARGS__)
#define all(x) (x).begin(), (x).end()
#define bit(n) (1LL<<(n))
#define sz(x) ((int)(x).size())
#define fst first
#define snd second
using ll=long long;
using pii=pair<int,int>;using pll=pair<ll,ll>;using pil=pair<int,ll>;using pli=pair<ll,int>;
using vs=vector<string>;using vvs=vector<vs>;using vvvs=vector<vvs>;
using vb=vector<bool>;using vvb=vector<vb>;using vvvb=vector<vvb>;
using vi=vector<int>;using vvi=vector<vi>;using vvvi=vector<vvi>;
using vl=vector<ll>;using vvl=vector<vl>;using vvvl=vector<vvl>;
using vd=vector<double>;using vvd=vector<vd>;using vvvd=vector<vvd>;
using vpii=vector<pii>;using vvpii=vector<vpii>;using vvvpii=vector<vvpii>;
template<class T,class U>istream&operator>>(istream&is,pair<T,U>&P){is>>P.fst;is>>P.snd;return is;}
template<class T>T read(){T t;cin>>t;return t;}
template<class T,class U>ostream&operator<<(ostream&o,const pair<T,U>&p){return o<<'('<<p.fst<<", "<<p.snd<<')';}
template<class T>ostream&operator<<(ostream&o,const vector<T>&t){o<<"{";rep(i,sz(t))o<<t[i]<<",";o<<"}"<<endl;return o;}
vs s_p_l_i_t(const string&s,char c){vs v;stringstream ss(s);string x;while(getline(ss,x,c))v.emplace_back(x);return move(v);}
void e_r_r(vs::iterator it){cerr<<endl;}
template<class T,class... Args>void e_r_r(vs::iterator it,T a,Args... args){cerr<<it->substr((*it)[0]==' ',it->length())<<" = "<<a<<", ";e_r_r(++it,args...);}
#define out(args...){vs a_r_g_s=s_p_l_i_t(#args,',');e_r_r(a_r_g_s.begin(),args);}

bool solve() {
  int n = read<int>();
  vector<int> A(n);
  rep(i, n) A[i] = read<int>();

  ll sum = accumulate(all(A), 0LL);

  ll nn = ((1LL + n) * n / 2);
  if (sum % nn) return false;

  ll dec_count = sum / nn;

  int neg_count = 0;
  ll neg_sum = 0;
  vi B(n);
  rep(i, n) {
    B[i] = A[i] - A[(i-1+n)%n];
    if (B[i] <= 0) {
      neg_count++;
      neg_sum += B[i];
    }
    else if (B[i] != dec_count) return false;
  }

  if (neg_count > dec_count) return false;

  if (-neg_sum != (n - neg_count) * dec_count) return false;

  return true;
}

void Main() {
  cout << (solve() ? "YES" : "NO") << endl;
}
int main() { cin.tie(nullptr); ios::sync_with_stdio(false); Main(); return 0; }


Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define rep(i,n)   FOR(i,0,n)
#define pb emplace_back
typedef long long ll;
typedef pair<int,int> pint;

int dp[301][301];
int w[301];
int main(){
    int n;
    while(cin>>n,n){
        rep(i,n)cin>>w[i];
        memset(dp,0,sizeof(dp));
        FOR(d,2,n+1){
            rep(i,n-d+1){
                int l=i,r=i+d-1;
                if(abs(w[l]-w[r])<2&&dp[l+1][r-1]==d-2) dp[l][r]=dp[l+1][r-1]+2;
                else{
                    int mx=0;
                    FOR(j,l,r) mx=max(mx,dp[l][j]+dp[j+1][r]);
                    dp[l][r]=max(mx,dp[l][r]);
                }
            }
        }
        cout<<dp[0][n-1]<<endl;
    }
    return 0;
}


Measured memory_bytes: 3464
import sys
sys.setrecursionlimit(1 << 25)
read = sys.stdin.readline
ra = range
enu = enumerate


def read_ints():
    return list(map(int, read().split()))


def read_a_int():
    return int(read())


def read_tuple(H):
    '''
    H is number of rows
    '''
    ret = []
    for _ in range(H):
        ret.append(tuple(map(int, read().split())))
    return ret


def read_col(H):
    '''
    H is number of rows
    A列、B列が与えられるようなとき
    ex1)A,B=read_col(H)    ex2) A,=read_col(H) #一列の場合
    '''
    ret = []
    for _ in range(H):
        ret.append(list(map(int, read().split())))
    return tuple(map(list, zip(*ret)))


def read_matrix(H):
    '''
    H is number of rows
    '''
    ret = []
    for _ in range(H):
        ret.append(list(map(int, read().split())))
    return ret
    # return [list(map(int, read().split())) for _ in range(H)] # 内包表記はpypyでは遅いため


MOD = 10**9 + 7
INF = 2**31  # 2147483648 > 10**9
# default import
from collections import defaultdict, Counter, deque
from operator import itemgetter
from itertools import product, permutations, combinations
from bisect import bisect_left, bisect_right  # , insort_left, insort_right
# https://atcoder.jp/contests/abc051/tasks/abc051_a
s = list(input().split(','))
print(*s)


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

using namespace std;

int main()
{
    int k,num,i;
    cin >> k>> num;
    int arr[num],s;
    for(i=0;i<num;i++){
        cin >> arr[i];
    }
    s=k-arr[num-1]+arr[0];
    for(i=1;i<num;i++){
        if((arr[i]-arr[i-1])>s)
        s=arr[i]-arr[i-1];
    }

    cout<<(k-s);

    return 0;
}


Measured memory_bytes: 1024