akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
#define REP(i,n) for (int i=0;i<(n);++i)

int main(){
    vector<int> n(3); REP(i,3) cin >> n[i];
    sort(n.begin(),n.end());
    // 1つ選んで１減らす　or 1つ選んで２増やす
    // 中央値に合わせる
    int ans = 0;
    ans += n[2] - n[1];
    ans += (n[1] - n[0]) / 2;
    ans += ((n[1] - n[0]) % 2) * 2; 
    cout << ans << endl;
}



Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <algorithm>
#include <functional>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <bitset>
#include <map>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
using namespace std;
typedef long long ll;
typedef pair<int,int> pint;
typedef vector<int> vint;
typedef vector<pint> vpint;
#define mp make_pair
#define fi first
#define se second
#define all(v) (v).begin(),(v).end()
#define rep(i,n) for(int i=0;i<(n);i++)
#define reps(i,f,n) for(int i=(f);i<(n);i++)
const int INF = 1e9;
int dp[100010][110];
int main(void){
	string s; cin >> s;
	rep(i, 100010)rep(j, 110) dp[i][j] = -INF;
	dp[0][0] = 0;
	for (int i = 0; i < s.size(); ++i){
		for (int j = 0; j <= 100; ++j){//gu - pa
			if(dp[i][j] == -INF) continue;

			int costg, costp;
			if(s[i] == 'g'){
				costg = 0, costp = 1;
			}else{
				costg = -1; costp = 0;
			}

			if(j == 0){//gu
				dp[i + 1][j + 1] = max(dp[i + 1][j + 1], dp[i][j] + costg);
				// printf("1 dp[%d][%d] = %d\n", i + 1, j + 1, dp[i + 1][j + 1]);
			}else{
				//gu
				dp[i + 1][j + 1] = max(dp[i + 1][j + 1], dp[i][j] + costg);
				// printf("2 dp[%d][%d] = %d\n", i + 1, j + 1, dp[i + 1][j + 1]);

				dp[i + 1][j - 1] = max(dp[i + 1][j - 1], dp[i][j] + costp);
				// printf("3 dp[%d][%d] = %d\n", i + 1, j - 1, dp[i + 1][j - 1]);

			}
		}
	}
	int ans = -INF;
	rep(j, 100){
		ans = max(dp[s.size()][j], ans);
	}

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

Measured memory_bytes: 43392
#include <iostream>
#include <vector>
#include <string>
#include <cmath>
#include <set>
#include <algorithm>
#include <array>
#include <complex>
#include <string>
#include <utility>
#include <map>
#include <queue>
#include <list>
#include <functional>
#include <numeric>
#include <stack>
#include <tuple>

using namespace std;
int dx[4] = { -1,0,1,0 };
int dy[4] = { 0,1,0,-1 };
const int INF = 100000000;
const long long LINF = 1000000000000000000;
const int MOD = (int)1e9 + 7;
const double EPS = 1e-6;
using pii = std::pair<int, int>;
using ll=long long;  
using pLL = std::pair<ll, ll>;

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    string N;
    cin >> N;
    int count1=0,count0=0;
    for(size_t i=0;i<N.size();++i){
        if(N[i]=='0') count0++;
        else count1++;
    }
    
    cout << min(count1,count0)*2 <<endl;
    return 0;
}

Measured memory_bytes: 512
#include <iostream>
#include <string>
using namespace std;
int main() {
	int n;
	string s;
	int ac=0,wa=0,tle=0,re=0;
	cin >> n;
	for (int i=0;i<n;i++){
		cin >> s;
		if ( s == "AC")
			ac++;
		if ( s == "WA")
			wa++;
		if ( s == "TLE")
			tle++;
		if ( s == "RE")
			re++;
	}
	cout << "AC x " << ac << endl;
	cout << "WA x " << wa << endl;
	cout << "TLE x " << tle << endl;
	cout << "RE x " << re << endl;
	return 0;
}


Measured memory_bytes: 3636
#include <bits/stdc++.h>
#include <iomanip>
#include <math.h>
#include <unistd.h>
#include <stdio.h>
#define rep(i,x) for(ll i = 0;i<x;i++)
#define all(a) (a).begin(),(a).end()
using ll = long long;
using ld = long double;
using namespace std;
using dou = double;
const ll INF = 1LL << 60;
const ll mod = 1000000007;
typedef pair<ll,ll> P;
using graph = vector<vector<ll>>;
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;}
ll gcd(ll a,ll b){
    if(a < b)swap(a,b);
    if(a % b == 0)return b;
    else return gcd(b,a%b);
}
bool isp(ll n){
    bool res = true;
    if(n == 1)return false;
    else{
        for(ll i = 2;i * i <= n;i++){
            if(n % i == 0){
                res = false;
                break;
            }
        }
        return res;
    }
}
//printf("%.10f\n", N);
/*
ll fibo(ll n){
    if(memo[n] != 0)return memo[n];
    if(n <= 1)return n;
    else return memo[n] = fibo(n - 1)+ fibo(n - 2);
}*/
/*  vector<ll> vec = {1,2,5,6,8,9,10};
    cout << binary_search(all(vec),5) << endl; -> true*/
/*
    vector<ll> vec = {1,2,5,6,8,9,10};
    auto n = upper_bound(all(vec),4);
    cout << *n << endl; -> 5*/
/*
    cout << fixed << setprecision(15);
    */
int main(){
    char one,two,thr,fou;
    cin >> one >> two >> thr >> fou;
    ll n = one - '0',m = two - '0',l = thr - '0',k = fou - '0';
    if(n + m + l + k == 7)cout << n << "+" << m <<"+" <<l<<"+"<<k;
    else if(n + m + l - k == 7)cout << n << "+" << m <<"+" <<l<<"-"<<k;
    else if(n + m - l + k == 7)cout << n << "+" << m <<"-" <<l<<"+"<<k;
    else if(n + m - l - k == 7)cout << n << "+" << m <<"-" <<l<<"-"<<k;
    else if(n - m + l + k == 7)cout << n << "-" << m <<"+" <<l<<"+"<<k;
    else if(n - m + l - k == 7)cout << n << "-" << m <<"+" <<l<<"-"<<k;
    else if(n - m - l + k == 7)cout << n << "-" << m <<"-" <<l<<"+"<<k;
    else cout << n << "-" << m <<"-" <<l<<"-"<<k;
    cout << "=7" << endl;
}

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

typedef long long LL;

#define REP(i, n) for(int i = 0; i < (int)(n); i++)
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define ALL(x) (x).begin(),(x).end()
const int IINF = 1e9;
const LL LINF = 1e18;
const LL MOD = 1e9+7;

LL scoring(int D, vector<vector<LL>> s, vector<int> schedule, vector<LL> c) {
    vector<int> last(26, 0);
    LL score = 0;
    FOR(i, 1, D + 1) {
        LL satisfaction = s[i][schedule[i]];
        last[schedule[i]] = i;
        REP(k, 26) {
            satisfaction -= (i - last[k])*c[k];
        }
        score += satisfaction;
    }
    return score;
}

LL delta(int D, vector<vector<LL>> s, vector<int> schedule, vector<LL> c, int d, int q) {
    int p = schedule[d];
    if(p == q) {
        return 0;
    }

    int lp = 0, rp = D + 1, lq = 0, rq = D + 1;
    for(int i = d - 1;0 <= i;i--) {
        if(schedule[i] == p) {
            lp = i;
            break;
        }
    }
    for(int i = d - 1;0 <= i;i--) {
        if(schedule[i] == q) {
            lq = i;
            break;
        }
    }
    for(int i = d + 1;i <= D;i++) {
        if(schedule[i] == p) {
            rp = i;
            break;
        }
    }
    for(int i = d + 1;i <= D;i++) {
        if(schedule[i] == q) {
            lq = i;
            break;
        }
    }
    return -s[d][p] + s[d][q] - c[p]*(d - lp)*(rp - d) + c[q]*(d - lq)*(rq - d);
}


int main() {
    int D;
    cin >> D;
    vector<LL> c(26);
    vector<vector<LL>> s(D + 1, vector<LL>(26, 0));
    REP(i, 26) {
        cin >> c[i];
    }
    REP(i, D) {
        REP(j, 26) {
            cin >> s[i + 1][j];
        }
    }
    vector<int> last(26, 0);
    vector<int> schedule(D + 1, 0);

    LL score = 0;
    FOR(i, 1, D + 1) {
        int contest = -1;
        int satisfaction = -IINF;
        REP(j, 26) {
            LL x = s[i][j];
            REP(k, 26) {
                x -= (i - last[k])*c[k];
            }
            x += (i - last[j])*c[j];
            if(satisfaction < x) {
                satisfaction = x;
                contest = j;
            }
        }
        last[contest] = i;
        schedule[i] = contest + 1;
        score += satisfaction;
    }

    REP(r, 3) {
        FOR(i, 1, D + 1) {
            LL mdel = -IINF;
            LL q = -1;
            REP(j, 26) {
                LL del = delta(D, s, schedule, c, i, j);
                if(mdel < del) {
                    q = j;
                }
            }
            if(0 < mdel) {
                schedule[i] = q;
            }
        }
    }
    FOR(i, 1, D + 1) {
        cout << schedule[i] << endl;
    }
    return 0;
}


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

using namespace std;

using ll = long long;
using Vi = vector<int>;
using Vl = vector<ll>;
using Pii = pair<int, int>;
using Pll = pair<ll, ll>;

//===

// const ll mod = static_cast<int>(1e9 + 7);





int main() {
	int N;
	cin >> N;
	vector<double> v(N);
	for (int i = 0; i < N; ++i) {
		cin >> v[i];
	}

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

	double ans = v[0];

	for (int i = 1; i < N; ++i) {
		ans = (ans + v[i]) / 2.0;
	}

	printf("%.9f\n", ans);
}


Measured memory_bytes: 256
#define _USE_MATH_DEFINES

#pragma GCC optimize("Ofast,no-stack-protector") 
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native") 
#pragma GCC optimize("unroll-loops") 
#pragma GCC optimize("fast-math")
  
#include <bits/stdc++.h> 
  
using namespace std;
  
#define $(x) (int)((x).size())
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define endl '\n'
#define x first
#define y second    
#define int long long
#define double long double       
#define vec vector            
#define pb push_back
#define pii pair<int, int>
#define pdd pair<double, double> 
#define beg begin
  
#ifdef LOCAL
    #define dbg(x) cerr << #x << " = " << x << endl;
#else 
    #define dbg(x)
#endif 
  
template<class T> ostream& operator<<(ostream &str, vector<T> &a) {
    for (auto &i : a) {
        str << i << " ";
    }
    return str;
}
  
template<class T> istream& operator>>(istream &str, vector<T> &a) {
    for (auto &i : a) {
        str >> i; 
    }
    return str;
}
  
template<class T> ostream& operator<<(ostream &str, pair<T, T> &a) {
    str << a.first << " " << a.second;
    return str;
}
  
template<class T> istream& operator>>(istream &str, pair<T, T> &a) {
    str >> a.first >> a.second;
    return str;
}
 
void solve(); signed main() {
#ifdef LOCAL
    freopen("input.txt", "r", stdin);                                       
    freopen("output.txt", "w", stdout);
#endif
    srand(time(0));
    ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    cout.setf(ios::fixed); cout.precision(6);
    solve();   
    return 0;
}

const int INF = 1e18;

void solve() {
    int n, x, d;
    cin >> n >> x >> d;
    if (d == 0 && x == 0) {
        cout << 1 << endl;
        return;
    }
    if (d == 0) {
        cout << n + 1 << endl;
        return;
    }
    if (d < 0) {
        x = -x, d = -d;
    }

    map<int, vec<pii>> g;
    for (int k = 0; k <= n; ++k) {
        int id = (d * 100000000 + k * x) % d;
        int l = d * (1 + k - 1) * (k - 1) / 2;
        int r = d *     (n - k + n - 1) * k / 2;
        l += k * x, r += k * x;
        g[id].pb({l, r});
    }
    for (auto &it : g) {
        sort(all(it.y));
    }

    int res = 0;
    for (auto el : g) {
        int r = -INF, ans = 0, l = -INF + 1;
        for (auto it : el.y) {
            if (it.x <= r) {
                r = max(r, it.y);
            }
            else {
                if (r - l + 1 != 0)
                    res += (r - l + 1) / d + 1;
                l = it.x, r = it.y;
            }
        }
        res += (r - l + 1) / d + 1;
    }

    cout << res << endl;
}


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

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

typedef long long ll;

const int INF = 1 << 30;
const ll LLINF = 1LL << 62;

int mod = 1000000007;

int main(void){
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cout << "Yes" << endl;
    int N, M; cin >> N >> M;
    vector<int> nodes[N];
    vector<bool> visited(N, false);
    vector<int> ans(N);
    rep(i, M){
        int a, b; cin >> a >> b;
        a--; b--;
        nodes[a].push_back(b);
        nodes[b].push_back(a);
    }
    queue<pair<int, int>> que; //親, 探索ノード
    que.push(make_pair(-1, 0));
    visited[0] = true;
    while(!que.empty()){
        pair<int, int> op = que.front();
        que.pop();
        int p = op.first, s = op.second;
        ans[s] = p+1;
        rep(i, nodes[s].size()){
            int to = nodes[s][i];
            if(to == p) continue;
            if(!visited[to]){
                visited[to] = true;
                que.push(make_pair(s, to));
            }
        }
    }
    for(int i = 1; i < N; i++) cout << ans[i] << endl;
    return 0;
}

Measured memory_bytes: 10416
#include <bits/stdc++.h>
#define MOD 1000000007
#define rep(i,n) for(ll i=0; i<(n); i++)
#define REP(i,a,b) for(ll i=(a); i<(b); i++)
#define RREP(i,a,b) for(ll i=(a); i>=(b); i--)
#define all(x) (x).begin(),(x).end()
using namespace std;
typedef long long ll;
typedef int64_t in;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef pair<ll, ll> p;
typedef vector<pair<ll, ll>> vpl;

int main(){
    ll n,k,x,y; cin >> n >> k >> x >> y;
    ll ans;
    if(n>k) ans= k * x + (n-k) * y;
    else ans = n*x;
    cout << ans << "\n";
    return 0;
}


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


int main(){
    string n;
    cin>>n;
    long long k=n.size();
    long long total=0;
    bool ans=true;
    for(int i=1;i<k;i++){
        if(n[i]!='9') ans=false;
    }
    if(ans){
        total+=(int)n[0]-'0';
        total+=(k-1)*9;  
    }else{
        total+=(int)n[0]-'0'-1;
        total+=(k-1)*9;    
    }
    cout<<total<<endl;
    

}


Measured memory_bytes: 256
N = int(input())
ylst = []
for i in range(1, int(N ** 0.5) + 1):
    if N % i == 0:
        ylst.append(i)
        if i != N // i:
            ylst.append(N // i)

ans = 10 ** 11

for i in range(len(ylst)):
    for j in range(i, len(ylst)):
        if ylst[i] * ylst[j] == N:
            tmp = max(len(str(ylst[i])), len(str(ylst[j])))
            ans = min(ans, tmp)

print(ans)


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

int main(){
    ll n;
    cin >> n;
    vector<pair<ll,ll>> p(n);
    rep(i, 0, n) {
        cin >> p[i].first;
        p[i].second = i+1;
    }
    sort(p.begin(), p.end(), greater<pair<ll,ll>>());
    ll ans = 0;
    multiset<ll> st;
    st.insert(0);
    st.insert(0);
    st.insert(n+1);
    st.insert(n+1);
    rep(i, 0, n) {
        auto itr = st.lower_bound(p[i].second);
        ll r1 = *itr;
        itr++;
        ll r2 = *itr;
        itr = st.lower_bound(p[i].second);
        itr--;
        ll l1 = *itr;
        itr--;
        ll l2 = *itr;
        ans += (l1 - l2) * (r1 - p[i].second) * p[i].first;
        ans += (r2 - r1) * (p[i].second - l1) * p[i].first;

        st.insert(p[i].second);
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 9492
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Text.RegularExpressions;

class Program
{
    static void Main(string[] args)
    {
        int N = int.Parse(Console.ReadLine());
        var TA = Console.ReadLine().Split().Select(int.Parse);
        int T = TA.First(), A = TA.Last();
        var H = Console.ReadLine().Split().Select(int.Parse).ToArray();
        int ans = -1;
        double dist = double.MaxValue;
        for (int i = 0; i < N; i++)
        {
            double temp = T - H[i] * 0.006;
            if (dist > Math.Abs(temp - A))
            {
                dist = Math.Abs(temp - A);
                ans = i + 1;
            }
        }
        Console.WriteLine(ans);
    }
}

Measured memory_bytes: 13332
#include <iostream>
#include <vector>
#include <string>
#include <cmath>
#include <map>
#include <algorithm>
#include <iomanip>
#include <queue>
#include <utility>
#include <set>
#include <stack>
#define int long long
using namespace std;
int32_t main(){
    ios_base::sync_with_stdio(false);cin.tie(NULL);
    int h,n;
    cin >> h >> n;
    int s= 0;
    for(int i = 0; i<n; ++i){
        int t;
        cin >> t;
        s+=t;
    }
    if(s>=h)
        cout << "Yes\n";
    else
        cout << "No\n";
    return 0;
}

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

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

    int l, r;
    cin >> l >> r;

    int modL = l % 2019;
    int divL = l / 2019;
    int modR = r % 2019;
    int divR = r / 2019;

    if (divL == divR) {
        int mini = 2019;
        for (int i = modL; i < modR; i++) {
            for (int j = modL + 1; j <= modR; j++) {
                int tmp = (i * j) % 2019;
                mini = min(mini, tmp);
            }
        }
        cout << mini << '\n';
    }
    else cout << 0 << '\n';
    return 0;
}


Measured memory_bytes: 256
#define _GLIBCXX_DEBUG//TLEの原因になるので注意！！！！！！！！！！！
#include<cmath>
#include <bits/stdc++.h>
typedef long long ll;
using namespace std;
vector<int> arr;
stack<int> st;
queue<int> qu;
queue<pair<int,int> > qu2;
priority_queue<int> pq;
#define rep(i,n) for(int i=0; i<(int)(n); i++)
#define rep2(i,n) for(int i=1; i<=(int)(n); i++)
#define mins(x,y) x=min(x,y)
#define maxs(x,y) x=max(x,y)
typedef set<int> set_t;
typedef set<string> set_g;
typedef complex<double> xy_t;
static const int NIL = -1;
static const int INF = 1000000007;
#define mp make_pair
#define sz(x) int(x.xise())
#define mod 1000000007
/*ll f[2001];
//int n,k とかしておく

ll pw(ll x, ll y){//euclidの互除法より
    ll a= 1;
    while(y){
        if(y&1){//奇数なら
            a = a*x%mod;
        }
        x = x*x%mod;
        y /= 2;
    }
    return a;
}

ll modinv(ll x){//逆元を求める
    return pw(x, mod - 2 );
}

ll comb(int n,int r){
    if(n<r){
        return 0;
    }
    return f[n] * modinv(f[r])%mod*modinv(f[n-r])%mod;
}//対combination//ただしfは用意してね
*/

//cerrはコメントアウトしなくても通る

int main(){
    int h,w,a,b;
    cin >> h>>w>>a>>b;
    rep(i,h){
        rep(j,w){
            if((j<a&&i<b)||(j>=a&&i>=b)){
                cout<<1;
            }else{
                cout<<0;
            }
        }
        cout<<endl;
    }
    return 0;
}

Measured memory_bytes: 1280
#if 1

#include <bits/stdc++.h>
using namespace std;
long long mod = 1000000007,d[55][55][100],a[55][55],b[55][55],m;
int n;

int main()
{
	cin >> n >> m;
	for(int i = 0;i < n;i++)
    {
        for(int j = 0;j < n;j++)
        {
            cin >> d[i][j][0];
        }
    }
	for(int k = 1;k < 60;k++)
	{
		for(int i = 0;i < n;i++)
        {
            for(int j = 0;j < n;j++)
            {
                for(int l = 0;l < n;l++)
                {
                    d[i][j][k] = (d[i][j][k]+d[i][l][k-1]*d[l][j][k-1])%mod;
                }
            }
		}
	}
	for(int i = 0;i < n;i++) a[i][i] = 1;
	for(int k = 0;k < 60;k++)
	{
		if(m&(1LL << k))
		{
			for(int i = 0;i < n;i++)
			{
                for(int j = 0;j < n;j++)
                {
                    b[i][j] = 0;
                    for(int l = 0;l < n;l++)
                    {
                        b[i][j] = (b[i][j]+a[i][l]*d[l][j][k])%mod;
                    }
                }
			}
			for(int i = 0;i < n;i++)
            {
                for(int j = 0;j < n;j++)
                {
                    a[i][j] = b[i][j];
                }
            }
		}
	}
	long ans = 0;
	for(int i = 0;i < n;i++)
    {
        for(int j = 0;j < n;j++)
        {
            ans = (ans+a[i][j]) % mod;
        }
    }
	cout << ans;
}

#endif // 1++

Measured memory_bytes: 2432
#include <stdio.h>
#define N 2000

int n,A[N];

int main(){
  int i,j,k,q,m[N],sum,flag;

  scanf("%d",&n);
  for(i=0;i<n;i++) scanf("%d",&A[i]);
  scanf("%d",&q);
  for(i=0;i<q;i++) scanf("%d",&m[i]);

  for(i=0;i<q;i++){
    if(solve(0,m[i])==1) printf("yes\n");
    else printf("no\n");
  }	

  return 0;
}

int solve(int i,int m){
  int res;
  
  if(m==0) return 1;
  else if(i>=n) return 0;

  res=solve(i+1,m)||solve(i+1,m-A[i]);
  return res;
}

Measured memory_bytes: 588
# coding: utf-8

(a,b,k) = map(int, input().rstrip().split(" "))

ans = []

for i in range(a, min(b+1,a+k)):
    ans.append(i)

for i in range(max(a, b-k+1), b+1):
    ans.append(i)

for i in sorted(set(ans)):
    print(i)



Measured memory_bytes: 3060
#include "iostream"
#include "climits"
#include "list"
#include "queue"
#include "stack"
#include "set"
#include "functional"
#include "algorithm"
#include "string"
#include "map"
#include "unordered_map"
#include "unordered_set"
#include "iomanip"
#include "cmath"
#include "random"
#include "bitset"
#include "cstdio"

using namespace std;

const long long int MOD = 1000000007;


long long int N, M, K, H, W, L, R;

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

	cin >> H >> W;
	vector<string>v(H);
	for (int i = 0; i < H; i++) {
		cin >> v[i];
	}
	int dir[] = { 0,1,0,-1,0 };
	for (int i = 0; i < H; i++) {
		for (int j = 0; j < W; j++) {
			if (v[i][j] == '.') {
				continue;
			}
			bool flag = false;
			for (int k = 0; k < 4; k++) {
				int ny = i + dir[k];
				int nx = j + dir[k + 1];
				if (ny < 0 || nx < 0 || ny >= H || nx >= W) {
					continue;
				}
				if (v[ny][nx] == '#') {
					flag = true;
				}
			}
			if (!flag) {
				cout << "No\n";
				return 0;
			}
		}
	}
	cout << "Yes\n";
	return 0;
}


Measured memory_bytes: 256
pub fn main() {
    use std::io::Read;
    let mut buf = String::new();
    std::io::stdin().read_to_string(&mut buf).unwrap();
    let mut iter = buf.split_whitespace();
    
    let n: usize = iter.next().unwrap().parse().unwrap();
    let a: Vec<i64> = iter.take(n).map(|x| x.parse().unwrap()).collect();

    let mut minus_is_even: bool = true;
    for i in 0..n {
        if a[i] < 0 {
            minus_is_even = !minus_is_even;
        }
    }

    if minus_is_even {
        let sum = a.iter().map(|x| x.abs()).fold(0, |acc, x| acc + x);
        println!("{}", sum);
    } else {
        let mut abs_min_value: (i64, usize) = (std::i64::MAX, 0);
        for i in 0..n {
            if a[i].abs() < abs_min_value.0.abs() {
                abs_min_value = (a[i], i);
            }
        }
        let mut sum = 0;
        for i in 0..n {
            if i == abs_min_value.1 {continue;}
            sum += a[i].abs();
        }
        sum -= abs_min_value.0.abs();
        println!("{}", sum);
    }
}


Measured memory_bytes: 8444
#include <stdio.h>

int main(){
	int A,B;
	int x;
	
	scanf("%d %d", &A, &B);
	if(A<B){
		x=A;
		A=B;
		B=x;
	}
	
	for(x=0;A>0&&B>0&&x<16;x++){
		if(x%2==0){
			A--;
		}else{
			B--;
		}
	}
	
	if(A<=1&&B<=1){
		printf("Yay!");
	}else{
		printf(":(");
	}
	return 0;
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
#define ALL(a)  (a).begin(),(a).end()
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
typedef pair<long long, long long> Pll;
typedef vector<int> vi;
typedef vector<vector<int>> vvi;
typedef vector<long long> vll;
typedef vector<vector<long long>> vvll;
template <typename T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template <typename T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
const long long INF = 1LL << 60;

int main(){
  ll N, K;
  cin >> N >> K;
  vll a(N), aa(N);
  vll highest(N), highestt(N);
  for(int i = 0; i < N; i++){
    cin >> a.at(i);
    if(i == 0) highest.at(0) = a.at(0);
    else if(a.at(i) > highest.at(i-1)) highest.at(i) = a.at(i);
    else highest.at(i) = highest.at(i-1);
  }
  aa = a; highestt = highest;


  ll result = INF;
  for(int tmp = 0; tmp < (1 << (N-1)); tmp++){
    bitset<14> bit(tmp);
    if(bit.count() !=  K-1) continue;
    a = aa; highest = highestt;
    ll sum = 0;
    for(int i = 0; i < N-1; i++){
      if(bit.test(i)){ //i+1番目がみえる
        if(a.at(i+1) <= highest.at(i)){
          sum += (highest.at(i) + 1LL - a.at(i+1));
          a.at(i+1) = highest.at(i) + 1LL;
        }
      }
      highest.at(i+1) = max(a.at(i+1), highest.at(i));
    }
    chmin(result, sum);
  }
  cout << result << endl;
}


Measured memory_bytes: 256
import java.util.*;

/**
 * C
 */
public class Main {
    public static void main(String[] args) {
        
        int prime = 0;
        Scanner sc = new Scanner(System.in);

        int n = sc.nextInt();
        int array[] = new int[n];

        for(int i=0; i<n; i++) {
            array[i] = sc.nextInt();
        }

        sc.close();

        for(int num : array) {
            if(isPrime(num) == true) {
                prime++;
            }
        }

        /*IN : for (int num : array) {
            for (int j = 2; j<num; j++) {
                if (num % j == 0) {
                    continue IN;
                }
            }
            prime++;
        }
        
        これでだめだったから悲しいよなぁ。。。

        */

        System.out.println(prime);

    }

    public static boolean isPrime(int num) {
        if (num < 2)
            return false;
        else if (num == 2)
            return true;
        else if (num % 2 == 0)
            return false; // 偶数はあらかじめ除く

        double sqrtNum = Math.sqrt(num);
        for (int i = 3; i <= sqrtNum; i += 2) {
            if (num % i == 0) {
                // 素数ではない
                return false;
            }
        }

        // 素数である
        return true;
    }
}


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

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

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

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

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

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

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

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

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

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

#[allow(unused_imports)]
use std::cmp::{min, max};

fn main() {
    input!{
        n: usize,
        f: [[usize; 10]; n],
        p: [[i64; 11]; n]
    }
    let mut ans: i64 = i64::min_value();
    for i in 1..1 << 10 {
        let mut t = 0;
        for j in 0..n {
            let mut c = 0;
            for k in 0..10 {
                if i & 1 << k != 0 {
                    c += f[j][k];
                }
            }
            t += p[j][c];
        }
        ans = max(ans, t);
    }
    println!("{}", ans);
}


Measured memory_bytes: 4352
#include <cstdio>
#include <iostream>
#include <algorithm>
#include <cstring>
using namespace std;
const int maxn = 1e5+100;

int n,m;
int a[maxn],b[maxn],ans;
bool ok1=false,ok2=false;

int main()
{
	ios::sync_with_stdio(false);
	cin>>n;
	for(int i=1;i<=n;i++)
	{
		cin>>a[i];b[i]=a[i];
		if(a[i]>=0) ok1=true;
		if(a[i]<=0) ok2=true;
	}
	sort(a+1,a+1+n);
	sort(b+1,b+1+n);
	if(ok1&&ok2)
	{
		for(int i=2;i<=n-1;i++)
		{
			if(b[i]>0) b[1]-=b[i];
		}
		b[n]-=b[1];
		for(int i=2;i<=n-1;i++)
		{
			if(b[i]<=0) b[n]-=b[i];
		}
		cout<<b[n]<<endl;
		for(int i=2;i<=n-1;i++)
		{
			if(a[i]>0)
			{
				cout<<a[1]<<" "<<a[i]<<endl;
				a[1]-=a[i];
			}
		}
		cout<<a[n]<<" "<<a[1]<<endl;
		a[n]-=a[1];
		for(int i=2;i<=n-1;i++)
		{
			if(a[i]<=0) {
				cout<<a[n]<<" "<<a[i]<<endl;
				a[n]-=a[i];
			}
		}
		return 0;
	}
	if(ok1)
	{
		b[1]-=b[n];
		for(int i=2;i<=n-2;i++) b[1]-=b[i];
		b[n-1]-=b[1];
		cout<<b[n-1]<<endl;
		cout<<a[1]<<" "<<a[n]<<endl;
		a[1]-=a[n];
		for(int i=2;i<=n-2;i++) cout<<a[1]<<" "<<a[i]<<endl,a[1]-=a[i];
		cout<<a[n-1]<<" "<<a[1];
		return 0;
	}
	if(ok2)
	{
		b[n]-=b[1];
		for(int i=2;i<n;i++) b[n]-=b[i];
		cout<<b[n]<<endl;
		cout<<a[n]<<" "<<a[1]<<endl;
		a[n]-=a[1];
		for(int i=2;i<n;i++) cout<<a[n]<<" "<<a[i]<<endl,a[n]-=a[i];
		return 0;
	}
	return 0;
}
/*

5
-1 -3 -5 6 3

5
1 3 4 5 6
5
-4 -7 -1 -2 0
 */

Measured memory_bytes: 2688
#include <iostream>
#include <vector>
#include <cmath>
#include <algorithm>
#define r(i,n) for(int i=0;i<n;i++)
using namespace std;

int main(){
  char a[10];
  r(i,3) cin>>a[i];
  int n=700;
  r(i,3) n+= a[i]=='o' ? 100 : 0;
  cout << n << endl;
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#pragma GCC optimize ("O3")
#pragma GCC target ("sse4")

using namespace std;

#define li long long int
#define ld long double
const int MX1 = 1e5 + 5;
const int MX2 = 1e6 + 5;
const li inf = 4e18;
const li mod = 1e9 + 7;

li power(li a, li b) { li res = 1; while (b) { if (b % 2) res = (res * a) % mod;
a = (a * a) % mod; b /= 2; } return res; }

li mmi(li a) { return power(a, mod - 2); }

li cntbit(li n) { li cnt = 0; while (n) { n &= (n - 1); cnt++; } return cnt; }

int n, m;

void solve() {
    cin >> n >> m;
    int ans = mod;
    for (int i = 1; i <= n; i++) {
        int x, y;
        cin >> x >> y;
        if (y <= m) {
            ans = min(ans, x);
        }
    }
    ans == mod ? cout << "TLE" : cout << ans;
}

int main() {
    ios_base::sync_with_stdio(NULL);
    cin.tie(NULL);
    int t = 1;
    // cin >> t;
    while (t--) {
        solve();
    }
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
using dl = long double;
int main()
{
    int n,m;
    int flag=0;
    cin>>n>>m;
int arr[3]={-1,-1,-1};
    for(int i=0;i<m;i++){
        int a,b;
        cin>>a>>b;
        if(n>1&&a==1&&b==0){
            flag=1;
        }
        if(arr[a-1]==-1||arr[a-1]==b){
            arr[a-1]=b;
        }
        else{

            flag=1;
        }
    }
    if(flag==1)cout<<-1;
    else{

        for(int i=0;i<n;i++){
            if(arr[i]==-1&&i!=0)cout<<0;
            else if(arr[i]==-1&&i==0&&n==1)cout<<0;
            else if(arr[i]==-1&&i==0)cout<<1;

    else{
        cout<<arr[i];
    }
        }
    }
    return 0;
}


Measured memory_bytes: 256
#include <algorithm>
#include <cmath>
#include <cstring>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>

using namespace std;
using ll = long long;

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

    vector<int> t(N);
    for (int i = 0; i < N; i++) {
        cin >> t[i];
    }

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

    int X = 0;
    for (int i = 1; i < N; i++) {
        if (t[i] - t[i - 1] < T) {
            X += t[i] - t[i - 1];
        } else {
            X += T;
        }
    }
    cout << X + T << endl;

    return 0;
}


Measured memory_bytes: 3836
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {

        Scanner sc = new Scanner(System.in);
        int a = sc.nextInt();
        int b = sc.nextInt();

        if(a <= 9 && b <= 9) {
            System.out.println(a * b);
        } else {
            System.out.println("-1");
        }


    }
}


Measured memory_bytes: 22740
#include <iostream>
#include <string>
#include <cmath>
#include <vector>
#include <algorithm>
#include <functional>

#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define REP(i,n) FOR(i,0,n)
#define MAX(a, b) ((a)>(b)?(a):(b))
#define MIN(a, b) ((a)<(b)?(a):(b))
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;

using namespace std;
typedef long long ll;

ll cost[100010];
vector< pair<int, ll> > v[100010];

// void bfs(int x){
//   FOR(i, 1, n-1){
//     if(cost[x] != 0) return;
     

//   }
// }
void dfs(int x, ll c){
  // dump(x);
  // if(cost[x] != -1) {cout << "exit" << endl; return;}
  if(cost[x] != -1) return;
  cost[x] = c;

  REP(i, v[x].size()){
    dfs(v[x][i].first, c + v[x][i].second);
  }
}

int main(){
  int n;
  cin >> n;

  int x, y, z;
  pair<int, int> p;
  REP(i, n-1){
    cin >> x >> y >> z;
    p.first = y;
    p.second = z;
    v[x].push_back(p);
    p.first = x;
    v[y].push_back(p);
  }

  int q, k;
  cin >> q >> k;

  REP(i, n+1) cost[i] = -1;
  dfs(k, 0);

  REP(i, q){
    cin >> x >> y;
    cout << cost[x] + cost[y] << endl;
  }

  // FOR(i, 1, n+1) cout << cost[i] << endl;
  
  return 0;
}

Measured memory_bytes: 14336
from collections import deque

n = int(input())
Adj_dict = {x:[] for x in range(1, n+1)}

for _ in range(n-1):
    a, b = map(int, input().split())
    Adj_dict[a].append(b)
    Adj_dict[b].append(a)
C = list(map(int, input().split()))
C = sorted(C, reverse=True)
dq_C = deque(C)

max_node = 0
max_edge_count = 0
for i in range(1,n+1):
    if len(Adj_dict[i]) >= max_edge_count:
        max_edge_count = len(Adj_dict[i])
        max_node = i

dq = deque()
dq.append(max_node)

Visited = [-1 for _ in range(n+1)]
Visited[max_node] = dq_C.popleft()
ans = 0

while dq:
    node = dq.popleft()
    Adjs = Adj_dict[node]
    for next_node in Adjs:
        if Visited[next_node] != -1:
            continue
        dq.append(next_node)
        Visited[next_node] = dq_C.popleft()
        ans += Visited[next_node]

print(ans)
print(' '.join(map(str, Visited[1:])))


Measured memory_bytes: 7032
#include <iostream>
#include <cmath>
#include <algorithm>
#include <string>
#include <iomanip>
#define REP(i,m,n) for(int i = (int) (m);i < (int) (n);i++)
#define rep(i,n) REP(i,0,n)
#define ll long long int
using namespace std;

ll n, x, y;
ll ans = 999999999999;


int main() {
	cin >> n;
	for(int i = 1;i <= 99999999;i++) {
		if (n % i == 0) {
			ans = min(ans, i + (n / i) - 2);
		}
	}
	cout << ans << endl;

}



Measured memory_bytes: 256
/* ---------- STL Libraries ---------- */
// IO library
#include <cstdio>
#include <fstream>
#include <iomanip>
#include <ios>
#include <iostream>

// algorithm library
#include <algorithm>
#include <cmath>
#include <numeric>
#include <random>

// container library
#include <array>
#include <bitset>
#include <deque>
#include <map>
#include <unordered_map>
#include <queue>
#include <set>
#include <string>
#include <tuple>
#include <vector>

/* ---------- Namespace ---------- */
using namespace std;

/* ---------- Type ---------- */
using ll = long long;
#define int ll
#define P pair<ll, ll>

/* ---------- Constants  */
const ll MOD = 1e9 + 7;
// const int INF = 1 << 25;
// const ll INF = 1LL << 50;
// const double PI = acos(-1);
// const double EPS = 1e-10;
// mt19937 mert(LL(time(0)));

/* v-v-v-v-v-v-v-v-v Main Part v-v-v-v-v-v-v-v-v */

signed main() {
    map<string, int> m;
    map<string, int> :: iterator itr;

    int N, M;
    cin >> N;
    for (int i = 0; i < N; i++) {
        string s;
        cin >> s;
        m[s]++;
    }

    cin >> M;
    for (int i = 0; i < M; i++) {
        string s;
        cin >> s;
        m[s]--;
    }

    int ret = -1;
    for (itr = m.begin(); itr != m.end(); itr++) {
        ret = max(ret, itr->second);
    }

    if (ret > 0) {
        cout << ret << endl;
    } else {
        cout << 0 << endl;
    }

    return 0;
}

Measured memory_bytes: 256
public class Main {
    public static void main(String[] srgs) {

        // ???????????????????????°??????????????????????????¨?????????.
        // ?????????????´? (?????????) ??????????????????.
        int[][] trump = new int[4][13];
        for (int i = 0; i < 4; i ++) {
            for (int j = 0; j < 13; j ++) { trump[i][j] = 0; }
        }

        // ??????????????????????????????.
        // ???????????????????????´??° (?????£?????????????????????????????°) ???????????????.
        java.util.Scanner sc = new java.util.Scanner(System.in);
        int n = sc.nextInt();

        // ?????????????????????????????? (??????????????????) ???????????????.
        // ???????????????????????´??° (?????????????????°) ???????????????.
        // ?????¨??°????????????????????????????´? (?????????) ????????¢??????.
        String gara;
        int yoso = 4;
        int kazu;
        for (int i = 0; i < n; i ++) {
            gara = sc.next();
            if ("S".equals(gara)) { yoso = 0; }
            if ("H".equals(gara)) { yoso = 1; }
            if ("C".equals(gara)) { yoso = 2; }
            if ("D".equals(gara)) { yoso = 3; }
            kazu = sc.nextInt();
            trump[yoso][kazu - 1] = 1;
        }

        for (int i = 0; i < 4; i ++) {
            for (int j = 0; j < 13; j ++) {
                if (trump[i][j] == 0) {
                    if (i == 0) { System.out.println("S " + (j + 1)); }
                    if (i == 1) { System.out.println("H " + (j + 1)); }
                    if (i == 2) { System.out.println("C " + (j + 1)); }
                    if (i == 3) { System.out.println("D " + (j + 1)); }
                }
            }
        }
    }
}

Measured memory_bytes: 26228
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <map>
#include <set>
#include <cmath>
#include <random>
#include <queue>

using namespace std;



int main()
{
	int N, D;
	vector<vector<int> > Xs;

	cin >> N >> D;

	int x;
	for(int ni = 0; ni <N; ni++){
		vector<int> Ds;
		for (int di = 0; di < D; di++) {
			cin >> x;
			Ds.push_back(x);
		}
		Xs.push_back(Ds);
	}

	int ans = 0;

	int X2;
	int X;
	for(int ni = 0; ni < N - 1; ni++){
		for(int nj = ni + 1; nj < N; nj++){
			X2 = 0;
			for(int di = 0; di < D; di++){
				X2 += (Xs[ni][di] - Xs[nj][di]) * (Xs[ni][di] - Xs[nj][di]);
			}
			X = (int)sqrt(X2);
			if (X*X == X2){
				ans++;
			}
		}
	}



	printf("%d",ans);

	return 0;
}



Measured memory_bytes: 256
a=[]#入力画面の二文字を別々の文字に格納
a=input().split(" ")
r=int(a[0])
D=int(a[1])
x=int(a[2])

p0=r*x-D
print(p0)
p1=r*p0-D
print(p1)
p2=r*p1-D
print(p2)
p3=r*p2-D
print(p3)
p4=r*p3-D
print(p4)
p5=r*p4-D
print(p5)
p6=r*p5-D
print(p6)
p7=r*p6-D
print(p7)
p8=r*p7-D
print(p8)
p9=r*p8-D
print(p9)


Measured memory_bytes: 3064
package main

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

func getScanner(fp *os.File) *bufio.Scanner {
	scanner := bufio.NewScanner(fp)
	scanner.Split(bufio.ScanWords)
	scanner.Buffer(make([]byte, 500001), 500000)
	return scanner
}

func getNextString(scanner *bufio.Scanner) string {
	scanner.Scan()
	return scanner.Text()
}

func getNextInt(scanner *bufio.Scanner) int {
	i, _ := strconv.Atoi(getNextString(scanner))
	return i
}

func getNextInt64(scanner *bufio.Scanner) int64 {
	i, _ := strconv.ParseInt(getNextString(scanner), 10, 64)
	return i
}

func getNextUint64(scanner *bufio.Scanner) uint64 {
	i, _ := strconv.ParseUint(getNextString(scanner), 10, 64)
	return i
}

func getNextFloat64(scanner *bufio.Scanner) float64 {
	i, _ := strconv.ParseFloat(getNextString(scanner), 64)
	return i
}

func main() {
	fp := os.Stdin
	wfp := os.Stdout

	if len(os.Args) > 1 {
		fp, _ = os.Open(os.Args[1])
		if len(os.Args) > 2 {
			wfp, _ = os.Create(os.Args[2])
		}
	}

	scanner := getScanner(fp)
	writer := bufio.NewWriter(wfp)

	n := getNextInt(scanner)
	tt := make([]int64, n)
	aa := make([]int64, n)

	for i := 0; i < n; i++ {
		tt[i] = getNextInt64(scanner)
	}
	for i := 0; i < n; i++ {
		aa[i] = getNextInt64(scanner)
	}

	var prevt, preva, ans int64
	min := make([]int64, n)
	for i := 0; i < n; i++ {
		if prevt != tt[i] {
			min[i] = tt[i]
		} else {
			min[i] = 1
		}
		prevt = tt[i]
	}
	for i := n - 1; i >= 0; i-- {
		if preva != aa[i] {
			if min[i] > aa[i] {
				fmt.Println(0)
				return
			}
			min[i] = aa[i]
		}
		preva = aa[i]
	}
	ans = 1
	for i := 0; i < n; i++ {
		max := minint64(tt[i], aa[i])
		if min[i] > max {
			fmt.Println(0)
			return
		}
		ans *= (max - min[i] + 1)
		ans %= int64(1e9 + 7)
	}

	fmt.Fprintln(writer, ans)
	writer.Flush()
}

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


Measured memory_bytes: 6272
#include <iostream>
using namespace std;
int main (void)
{
	long int h[3], m[3], s[3], hour[3], min[3], sec[3], tm[3],atm[3],
		ah[3], am[3],as[3];
	for(int i = 0;i < 3;i++)
	{
		cin >> h[i] >> m[i] >> s[i]>> hour[i]>> min[i]>> sec[i];
		tm[i] = h[i]*3600 + m[i]* 60 + s[i];
		atm[i] = hour[i]*3600 + min[i]* 60 +sec[i];
		atm[i] -= tm[i];
		ah[i] = atm[i] / 3600;
		atm[i] -= ah[i] * 3600;
		am[i] = atm[i] / 60;
		as[i] = atm[i] % 60;

	}
	for(int j = 0; j < 3;j++)
	{
		cout << ah[j] <<" "<< am[j] << " "<< as[j] <<endl;
	}
	return 0;
}

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

int main(){
	long long N,A,B;
	cin >> N >> A >> B;
	long long ans=0;
	ans+=N/(A+B)*A;
	N%=(A+B);
	ans+=min(N,A);
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <cmath>
#include <utility>
using namespace std;

typedef long long ll;
ll MOD = 1e9+7;
int c[20];
int v[20];
int main()
{
	int n;
	int ans=0;
	cin>>n;
	for(int i=0;i<n;i++)
		cin>>v[i];
	for(int i=0;i<n;i++)
		cin>>c[i];
	for(int i=0;i<n;i++)
		ans+=max(0,v[i]-c[i]);
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 256
//****** @mdazmat9 **********
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define UB upper_bound
#define LB lower_bound
#define BS binary_search
#define EB emplace_back
#define PB push_back
#define endl "\n"
#define MOD 1000000007
#define MOD2 998244353
#define F first
#define S second
#define ALL(a) (a).begin(),(a).end()
typedef pair<int, int> pr;
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0)
int fast_pow(int x, int y, int p);


void solve() {
    int n;cin>>n;
    map<int,int> mp;
    for(int i=1;i<=n;i++)mp[i]=0;
    for(int i=1;i<n;i++){
        int x;cin>>x;
        mp[x]++;
    }
    for(auto x:mp){
        cout<<x.S<<endl;
    }
}
int32_t main() {
    IOS;
    int test = 1;
//    cin >> test;
    for(int i=1;i<=test;i++){
//        cout<<"Case #"<<i<<": ";
        solve();
    }
    return 0;
}
int fast_pow(int x, int y, int p) {
    int res = 1;
    x = x % p;
    while (y > 0) {
        if (y & 1)
            res = (res * x) % p;
        y = y >> 1;
        x = (x * x) % p;
    }
    return res;
}

Measured memory_bytes: 16176
# -*- coding: utf-8 -*-
import sys
buff_readline = sys.stdin.buffer.readline
readline = sys.stdin.readline

INF = 2**62-1


def read_int():
    return int(buff_readline())


def read_int_n():
    return list(map(int, buff_readline().split()))


def slv(X):
    b = {}
    for i in range(0, 10**3):
        b[i**5] = i

    for a in range(0, 10**3):
        rem = X - (a ** 5)
        if rem in b:
            return (a, -b[rem])
        elif -rem in b:
            return (a, +b[rem])
        a *= -1
        rem = X - (a ** 5)
        if rem in b:
            return (a, -b[rem])
        elif -rem in b:
            return (a, +b[rem])

    assert False



def main():
    X = read_int()
    print(*slv(X))


if __name__ == '__main__':
    main()


Measured memory_bytes: 62312
#include <iostream>
#include <queue>
#define DIFF 75
using namespace std;

typedef pair<int, int> P;

bool point[151][151];
bool searched[151][151];
int recturn[151][151];
P start;

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

int bfs(int t, int n) {
  queue<P> q1;
  P temp;
  int count = 0;
  int turn = 0;
  temp.first = start.first;
  temp.second = start.second;
  searched[temp.first + DIFF][temp.second + DIFF] = true;
  recturn[temp.first + DIFF][temp.second + DIFF] = 0;
  q1.push(temp);
  count++;
  while (q1.empty() == false) {
    temp = q1.front();
    q1.pop();
    if (recturn[temp.first + DIFF][temp.second + DIFF] == t) break;
    for (int i = 0; i < 6; i++) {
      P s;
      s.first = temp.first + dx[i];
      s.second = temp.second + dy[i];
      if (point[s.first + DIFF][s.second + DIFF]
	  && !searched[s.first + DIFF][s.second + DIFF]) {
	q1.push(s);
	searched[s.first + DIFF][s.second + DIFF] = true;
	recturn[s.first + DIFF][s.second + DIFF]
	  = recturn[temp.first + DIFF][temp.second + DIFF] + 1;
	count++;
      }
    }
  }
  return count;
}

int main() {
  while (true) {
    int t, n;
    cin >> t >> n;
    if (t == 0 && n == 0) return 0;

    for (int i = 0; i < 151; i++) {
      for (int j = 0; j < 151; j++) {
	point[i][j] = true;
	searched[i][j] = false;
      }
    }

    for (int i = 0; i < n; i++) {
      int x, y;
      cin >> x  >> y;
      point[x + DIFF][y + DIFF] = false;
    }

    cin >> start.first >> start.second;

    int ans = bfs(t, n);
    cout << ans << endl;
  }
}

Measured memory_bytes: 3260
#include <stdio.h>

typedef unsigned long ulong;

static ulong diff(ulong a, ulong b){
    return __builtin_ctzl(a^b);
}

static void pl(long n){
#define L 6
    char c[L];
    long i=L-1;
    do{
        c[i]=n%10+'0';
        n/=10;
        i--;
    }while(n>0);
    for(i++;i<L;i++){
        putchar_unlocked(c[i]);
    }
}

#define N 17
long data[1<<N];

static void solve(const long n, const long a, const long b, const size_t sp, const size_t ep, const long mask){
    if(n==1){
        data[sp+0] = a;
        data[sp+1] = b;
        return;
    }
    const ulong d = diff(a, b);
    const ulong nmask = mask ^ (1<<d);
    const ulong aa = nmask & a;
    const ulong ab = nmask & (a ^ (nmask&(-nmask)));
    const ulong bb = nmask & b;
    const size_t mp = (sp+ep)/2;
    //printf("%ld %ld %ld\n", aa, ab, bb);
    solve(n-1, aa, ab, sp, mp, nmask);
    solve(n-1, ab, bb, mp, ep, nmask);
    const ulong ad = a&(1<<d);
    const ulong bd = b&(1<<d);
    for(size_t i=sp; i<mp; i++){ data[i] |= ad; }
    for(size_t i=mp; i<ep; i++){ data[i] |= bd; }
}

int main(void){
    long n, a, b;
    scanf("%ld %ld %ld", &n, &a, &b);
    if(__builtin_popcountl(a)%2 == __builtin_popcountl(b)%2){
        printf("NO\n");
        return 0;
    }
    solve(n, a, b, 0, 1<<n, 0xFFFFFFFFFFFFFFFF);
    const size_t m = 1<<n;
    printf("YES\n");
    for(size_t i=0; i<m-1; i++){
        pl(data[i]);
        putchar_unlocked(' ');
        //printf("%ld ", data[i]);
    }
    pl(data[m-1]);
    putchar_unlocked('\n');
    return 0;
}


Measured memory_bytes: 1920
#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<pair<int,int> ,null_type,less<pair<int,int> >,rb_tree_tag,tree_order_statistics_node_update> ordered_set;
long long MOD = 1e9+7;
pair<int,int> dx[4] = {{1,0},{-1,0},{0,1},{0,-1}};
long long fastpow(long long x,long long k)
{
    if(!k)
        return 1;
    if(k & 1)
        return ((x * fastpow(x,k-1) % MOD) % MOD) % MOD;
    long long ans = fastpow(x,k/2);
    ans %= MOD;
    ans *= ans;
    ans %= MOD;
    return ans;
}
long long sumF(long long x)
{
    int s = 0;
    while(x)
        s += x%10,x /= 10;
    return s;
}
int arr[100005];
int DP[100005];
int n;
int solve(int idx)
{
    if(idx == n)
        return 0;
    if(DP[idx] != -1)
        return DP[idx];
    int C = 1e9;
    for(int i = 1;i <= 2 && idx + i <= n;i++)
        C = min(C,abs(arr[idx] - arr[idx+i]) + solve(idx + i));
    return DP[idx] = C;
}
int main()
{
    memset(DP,-1,sizeof DP);
    cin >> n;
    for(int i = 1;i <= n;i++)
        cin >> arr[i];
    cout << solve(1);
    return 0;
}


Measured memory_bytes: 5760