akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
using namespace std;
const int mod=998244353;
inline void Add(int &a,int b){a=a+b>=mod?a+b-mod:a+b;}
char s[301];int n,k;
int f[301][301][301];
int cnt[301],tot,now=0,suf[302];
int main()
{
	scanf("%s%d",s+1,&k);n=strlen(s+1);k=min(k,n);
	for(int i=1;i<=n;i++)
	{
		if(s[i]=='0') cnt[++tot]=now,now=0;
		else now++;
	}
	if(now) cnt[++tot]=now;
	for(int i=tot;i;i--) suf[i]=suf[i+1]+cnt[i];
	f[0][0][0]=1;
	for(int i=1;i<=tot;i++)
	{
		for(int lst=0;lst<=n;lst++) for(int st=0;st<=k;st++) if(f[i-1][lst][st])
		{
			for(int v=0;v<=cnt[i];v++) if(lst>=cnt[i]-v&&lst-cnt[i]+v<=suf[i+1])
				Add(f[i][lst-cnt[i]+v][st],f[i-1][lst][st]);
			for(int v=cnt[i]+1;lst+v-cnt[i]<=suf[i+1];v++)
				Add(f[i][lst+v-cnt[i]][st+v-cnt[i]],f[i-1][lst][st]);
		}
	}
	int ans=0;
	for(int i=0;i<=k;i++) Add(ans,f[tot][0][i]);
	cout<<ans<<endl;
}

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

#define gc getchar
#define t ll t; cin>>t; while(t--)
#define rep(i,j,k) for(i=j; i<k; i++)
#define rrep(i,j,k) for(i=j; i>=k; i--)
#define repm(i,j,n,m) for(i=0; i<n; i++) for(j=0; j<m; j++)
#define tr(c,it) for(auto it = (c).begin(); it != (c).end(); it++)
#define ZERO(a) memset(a,0,sizeof(a))
#define lowbit(x) (x&(-x))
#define sz(a) int((a).size()) 
#define pb push_back 
#define all(c) (c).begin(),(c).end()
#define fin scan_int()
#define fout(x) fast_out(x)
#define pd(x) printf("%d ",x)
#define newl printf("\n")
#define xx first
#define yy second
#define INOUT take_input_and_output_from_file();
#define FAST ios_base::sync_with_stdio(false);cin.tie(NULL);
#define strtoint(s,n) if (!(istringstream(s) >> n) ) n = 0;
#define mod 1000000007
typedef long long ll;
typedef vector<ll > vi;
typedef vector<string> vs;
typedef vector<vi> vvi;
typedef pair<string,ll > psi; 
typedef pair<ll ,ll > pii;

string inttostr(ll str){stringstream stream;stream << str;return stream.str();}
ll modexpo(ll a,ll b,ll n){ll d=1;while(b){if(b&1)d=(d*a)%n;b>>=1;a=(a*a)%n;}return d;}
ll expo(ll a,ll b){ll d=1;while(b){if(b&1)d=d*a;b>>=1;a=a*a;}return d;}
inline ll gcd(ll a, ll b){return b?gcd(b,a%b):a;}
inline ll lcm(ll a,ll b) {return (a*b)/gcd(a,b);}
ll inv(ll a,ll m){return modexpo(a,m-2,m);}
void parr(ll a[],ll n){ll i;rep(i,0,n)cout<<a[i]<<" ";cout<<endl;}

void take_input_and_output_from_file() {
    #ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
    #endif
}

inline ll scan_int() {
    ll NR=0,sign=1;
    char c=gc();
    while( c < 48 || c > 57 ) {
        if(c=='-') sign=0;
        c=gc();
    }
    while(c>47 && c< 58) {
        NR = (NR << 3) + (NR << 1) + (c - 48);
        c=gc();
    }
    return (sign?NR:(-NR));
}

////////////////////////////////////////////////////////////////////////////////////////////



int main(){
    //INOUT;
    
    string s;
    cin>>s;
    ll i=0;
    ll k=fin;
    if(s[0] != '1') {
        printf("%c\n", s[0]);
        return 0;
    }

    ll z=0;
    while(s[z] == '1' && z<s.length()) z++;
    if(k-1<z) cout<<1<<endl;
    else cout<<s[z]<<endl;

    return 0;
}


Measured memory_bytes: 256
#include <iostream>

using namespace std;

int main(void)
{
	int x, y;
	cin >> x >> y;

	int a[7] = { 1,3,5,6,8,10,12 };
	int b[4] = { 4,6,9,11 };
	int c = 2;

	int gX, gY;
	for (int i = 0; i < 7; i++) {
		if (a[i] == x) { gX = 0; }
		if (a[i] == y) { gY = 0; }
	}
	for (int i = 0; i < 4; i++) {
		if (b[i] == x) { gX = 1; }
		if (b[i] == y) { gY = 1; }
	}
	if (c == x) { gX = 2; }
	if (c == y) { gY = 2; }
	
	if (gX == gY) { cout << "Yes" << endl; }
	else { cout << "No" << endl; }

	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <vector>
#include <cmath>

using namespace std;

double dis(vector<double>& y, vector<double>& z, int d)
{
    int tmp = 0;
    for (int i = 0; i < d; ++i) {
        tmp += abs((y[i] - z[i]) * (y[i] - z[i]));
    }
    return sqrt((double)tmp);
}

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

    int n, d, cnt = 0;
    cin >> n >> d;
    vector< vector<double> > v(n, vector<double>(d));

    for (int i = 0; i < n; ++i) {
        for (int j = 0; j < d; ++j) {
            cin >> v[i][j];
        }
    }

    for (int i = 0; i < n-1; ++i) {
        for (int j = i+1; j < n; ++j) {
            double ans = dis(v[i], v[j], d);
            if (ceil(ans) == floor(ans)) ++cnt;
        }
    }

    printf("%d\n", cnt);

    return 0;
}


Measured memory_bytes: 256
#include <cstdio>

int main(){
    int n,i;
    scanf("%d",&n);

    int a[n];

    for(int i = 0; i < n; i++) {
        scanf("%d",&a[i]);
    }

    for(int i = n - 1; i > 0; i--) {
        printf("%d ",a[i]);
    }
    if(i == 0){
        printf("%d",a[i]);
    }

    printf("\n");
    return 0;
}


Measured memory_bytes: 2684
n=int(input())
#山の数

S=input().split()
damrainfall=list(S)
#各ダムに降った量　damrainfall[0]はNと1の間のダムのものとする

for i in range(n):
    damrainfall[i]=int(damrainfall[i])
#print(damrainfall)

totalrainfall=0
for i in range(n):
  totalrainfall+=damrainfall[i]

#totalrainfallは降った雨の総量

nigai=0
j=1
while j<n:
  nigai+=(damrainfall[j]*2)
  j+=2


mountainrainfall=[]
for i in range(n):
  mountainrainfall.append(0)

mountainrainfall[n-1]=totalrainfall-nigai

mountainrainfall[0]=damrainfall[0]*2-mountainrainfall[n-1]

k=1
while k<n:
  mountainrainfall[k]=damrainfall[k]*2-mountainrainfall[k-1]
  k+=1
  
print(mountainrainfall[n-1],end=" ")

for i in range(n-1):
      print(mountainrainfall[i],end=" ")



Measured memory_bytes: 19472
#include <bits/stdc++.h>
#include <math.h>
#define _GLIBCXX_DEBUG
using namespace std;
int main() {
  
  int a,b,c,d,e,k;cin>>a>>b>>c>>d>>e>>k;
  
  if(e-a<=k){
    cout<<"Yay!"<<endl;
  }
  else{
    cout<<":("<<endl;
  }
}


Measured memory_bytes: 3596
#include<bits/stdc++.h>
using namespace std;
#define rep(i,j,k) for(int i=j;i<=k;++i)
typedef long long ll;
char cch;
inline ll rd(){
	ll x=0,fl=1;
	cch=getchar();
	while(cch>'9'||cch<'0'){
		if(cch=='-') fl=-1;
		cch=getchar();
	}
	while(cch>='0'&&cch<='9') x=(x<<3)+(x<<1)+cch-'0',cch=getchar();
	return x*fl;
}
const int N=1e5+3;
int a[N];
ll p[N];
int main(){
	int n=rd(),s=rd();
	rep(i,1,n) a[i]=rd(),p[i]=(ll)rd();
	ll ans=0;
	int l=1,r=n;
	while(l<=r){
		if(a[l]>s){
			ans=ans+a[r]-s;break;
		}
		if(a[r]<s){
			ans=ans+s-a[l];break;
		}
		ans+=a[r]-a[l];
		if(p[l]<p[r]) while(p[l]<p[r]&&l<r) p[r]+=p[l],++l;
		else if(p[l]>=p[r])while(p[l]>=p[r]&&l<r) p[l]+=p[r],--r;
	}
	cout<<ans;
}

Measured memory_bytes: 1408
#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;

int main(){
  int N;
  double T, A;
  cin >> N >>  T >> A;
  vector<pair<double, int>> H(N);
  
  for(int i = 0; i < N; i++){
    double h;
    cin >> h;
    H.at(i).first = abs(A - (T - h * 0.006));
    H.at(i).second = i + 1;
  }
  sort(ALL(H));
  cout << H.at(0).second << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define LL long long
const LL MOD = 1e9 + 7;
const int SZ = 1e5 + 5;
using namespace std;

int main()
{
    int n;
    cin >> n;
    LL sum = 0;
    while(n--){
        LL x;
        cin >> x;
        sum += (x-1);
    }
    cout << sum << "\n";
    return 0;

}


Measured memory_bytes: 384
import java.io.IOException
import java.lang.NumberFormatException
import java.lang.StringBuilder

object AMain{
    fun solve(){
        val n = nextLong()
        val d = nextLong()
        var ans = 0
        for (i in 1..n){
            val x = nextLong()
            val y = nextLong()
            if(x * x + y * y <= d * d) ans++
        }

        println(ans)
    }

    // Scanner based on uwi-san's Java code
    val stream = System.`in`
    val buffer = ByteArray(1024)
    var ptr = 0
    var buflen = 0

    fun hasNextByte(): Boolean{
        if(ptr < buflen){
            return true
        }else{
            ptr = 0
            try{
                buflen = stream.read(buffer)
            }catch (e: IOException){
                e.printStackTrace()
            }
            if(buflen <= 0){
                return false
            }
        }
        return true
    }

    fun readByte() =
        if(hasNextByte()) buffer[ptr++]
        else -1

    fun isPrintableChar(c: Byte) = c in 33..126

    fun hasNext(): Boolean{
        while(hasNextByte() && !isPrintableChar(buffer[ptr])) ptr++
        return hasNextByte()
    }

    fun next(): String{
        if(!hasNext()) throw NoSuchElementException()
        val sb = StringBuilder()
        var b = readByte()
        while(isPrintableChar(b)){
            sb.appendCodePoint(b.toInt())
            b = readByte()
        }
        return sb.toString()
    }

    fun nextLong(): Long{
        if(!hasNext()) throw NoSuchElementException()
        var n = 0L
        var minus = false
        var b = readByte()
        if(b == '-'.toByte()){
            minus = true
            b = readByte()
        }
        if(b !in '0'.toByte()..'9'.toByte())
            throw NumberFormatException()
        while(true){
            if(b in '0'.toByte()..'9'.toByte()){
                n *= 10
                n += b - '0'.toByte()
            }else if(!isPrintableChar(b)){
                return if(minus) -n else n
            }else{
                throw NumberFormatException()
            }
            b = readByte()
        }
    }

    fun nextInt(): Int{
        val n1 = nextLong()
        if(n1 !in Int.MIN_VALUE..Int.MAX_VALUE)
            throw NumberFormatException()
        return n1.toInt()
    }

    fun NextDouble() = next().toDouble()
}

fun main(){
    AMain.solve()
}



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

int main()
{
    int k,i,count1=0,count2=0,count;
    cin>>k;
    for(i=1;i<=k;i+=2){
        count1++;
    }
    for(i=2;i<=k;i+=2){
        count2++;
    }
    count=count1*count2;
    cout<<count<<endl;
}


Measured memory_bytes: 256
#include <stdio.h>

int main(void) {
  int a, b, s, l;
  scanf("%d %d", &a, &b);
  s = a * b;          //Calc area
  l = 2 * (a + b);  //Calc circumference
  printf("%d %d\n", s, l);
  return 0;
}


Measured memory_bytes: 2032
import Data.Text
main = do
  a <- getLine
  let date = Prelude.map unpack (splitOn (pack "/") (pack a))
  let y = read (date !! 0)
  let m = read (date !! 1)
  let d = read (date !! 2)
  let ans = if (y <= 2019) && (m <= 4) && (d <= 30) then "Heisei" else "TBD"
  putStrLn ans

Measured memory_bytes: 508
#include<bits/stdc++.h>
using namespace std;
#define N 510000
struct ques{
	int l,r,id;
	int ans;
}q[N];
int pos[N],c[N],s[N],ans,n,m;
bool cmp(ques x,ques y)
{
	if(pos[x.l] == pos[y.l])
	return x.r < y.r;
	return x.l < y.l;
}
bool __id(ques x,ques y)
{
	return x.id < y.id;
}
void add(int color)
{
	s[color]++;
	ans += s[color] == 1;
}
void del(int color)
{
	s[color]--;
	ans -= s[color] == 0;
}
int main()
{
	cin>>n>>m;
	for(int i = 1;i <= n;i++)
	cin>>c[i];
	int size = (int)sqrt(n);
	for(int i = 1;i <= n;i++)
	pos[i] = (i-1)/size+1;
	for(int i = 1;i <= m;i++)
	{
		cin>>q[i].l>>q[i].r;
		q[i].id = i;
	}	
	sort(q+1,q+1+m,cmp);
	int l = 1,r = 0;
	for(int i = 1;i <= m;i++)
	{
		while(q[i].l<l) add(c[--l]);
		while(q[i].l>l) del(c[l++]);
		while(q[i].r>r) add(c[++r]);
		while(q[i].r<r) del(c[r--]);
		q[i].ans = ans;
	}
	sort(q+1,q+1+m,__id);
	for(int i = 1;i <= m;i++ )
	cout<<q[i].ans<<endl;
	return 0;
}

Measured memory_bytes: 17372
#include <stdio.h>
int main(void){
  int a,b,c;
  scanf("%d %d %d",&a,&b,&c);
  if((a+b)<=(a+c)&&(a+b)<=(b+c)){printf("%d",a+b);}
    else if((a+c)<=(a+b)&&(a+c)<=(b+c)){printf("%d",a+c);}
    else if((c+b)<=(a+c)&&(c+b)<=(b+a)){printf("%d",b+c);}
  return 0;
}

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

int main(){
  double a, b, c, d, e, f, x, y;
  while(cin >> a >> b >> c >> d >> e >> f){   
  y = (f-(d*c)/a)/(e-(d*b)/a);
  x = (c-b*y)/a;
  cout << fixed << setprecision(3) << x << " " << y << endl;
  }
  // cin >> a >> b >> c >> d >> e >> f;   
  // y = (f-(d*c)/a)/(e-(d*b)/a);
  // x = (c-b*y)/a;

  // cout << fixed << setprecision(3) << x << " " << y << endl;
    
    
    
  return 0;

}

Measured memory_bytes: 3216
#include <iostream>
#include <vector>
#include <algorithm>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <string>
#include <cstdio>
#include <cstdlib>
#include <string>
#include <cstring>
#include <cmath>
#include <climits>
#include <ctime>
#include <fstream>
#include <functional>
#include <unordered_map>
#include <unordered_set>
#define MAGIC cin.tie(NULL); ios_base::sync_with_stdio(false)
#define endl '\n'
//#define ll long long
#define mod (1000000007)
//#define NCONS 100001
//#define NCONS 100001
//#define NCONS 1001
//#define NCONS 101
//#define MCONS 2001
//#define LIMIT 1000000000
#define TRUE 1
#define FALSE 0
#define toRadian(degree) ((degree) * (M_PI / 180.))
#define toDegree(radian) ((radian) * (180. / M_PI))
#define int long long
//#define double long double
using namespace std;
struct Point{int x; int y;};
struct PPoint{Point x; Point y;};
typedef long long ll;

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

#define YYYY cout << "YES" << endl
#define NNNN cout << "NO" << endl
#define yyyy cout << "Yes" << endl
#define nnnn cout << "No" << endl
int dx[]{0, 1, 0, -1};
int dy[]{1, 0, -1, 0};

const int NCONS = 100001;
//const int MCONS = 101;

int32_t main()
{
    MAGIC;
    int n, m; cin >> n >> m;
    priority_queue<int> pq;
    while(n--)
    {
        int a; cin >> a; pq.push(a);
    }
    
    while(m > 0)
    {
        auto cur = pq.top(); pq.pop();
        cur /= 2; m -= 1;
        pq.push(cur);
    }
    
    int ret = 0;
    while(!pq.empty())
    {
        auto cur = pq.top(); pq.pop();
        ret += cur;
    }
    
    cout << ret;
    
    return 0;
}



Measured memory_bytes: 1400
from itertools import product
def norm(x):
    return abs(x[0])+abs(x[1])+abs(x[2])
N,M = map(int,input().split())
X = {i:list(map(int,input().split())) for i in range(N)}
cmax = 0
for x in product((1,-1),repeat=3):
    Y = {i:[X[i][0]+x[0]*10**10,X[i][1]+x[1]*10**10,X[i][2]+x[2]*10**10] for i in range(N)}
    Z = {i:norm(Y[i]) for i in range(N)}
    Z = sorted(list(Z.items()),key=lambda x:x[1],reverse=True)
    A = [0,0,0]
    for j in range(M):
        ind = Z[j][0]
        A[0] += X[ind][0]
        A[1] += X[ind][1]
        A[2] += X[ind][2]
    cmax = max(cmax,norm(A))
print(cmax)

Measured memory_bytes: 45424
#include <iostream>
#include <string>
#include <algorithm>
#include <iomanip>
#include <vector>
#include <map>
#include <cmath>

int main() {
	int n, a[100000];
	std::cin >> n;
	for (int i = 0;i < n;i++) {
		std::cin >> a[i];
	}
	std::sort(a, a + n);
	long long int ans = 0;
	long long int b = 1000000007;
	if (n % 2 == 1) {
		int nSum = 0;
		if (a[0] == 0)nSum += 1;
		int c = 1;
		for (int i = 1;i < n - 1;i++) {
			if (a[i] == a[i + 1]) {
				if (a[i] == 2 * c) {
					nSum += 2;
					c += 1;
		}
			}
		}
		if (nSum == n) {
			ans = 1;
			for (int i = 0;i < (n - 1) / 2;i++) {
				ans *= 2;
				ans %= b;
			}
		}
	}
	else {
		int nSum = 0;
		int c = 0;
		for (int i = 0;i < n;i++) {
			if (a[i] == a[i + 1]) {
				if (a[i] == c * 2 + 1) {
					nSum += 2;
					c += 1;
				}
			}
		}
		if (nSum == n) {
			ans = 1;
			for (int i = 0;i < n / 2;i++) {
				ans *= 2;
				ans %= b;
			}
		}
	}
	std::cout << ans%b << std::endl;
	return 0;
}

Measured memory_bytes: 640
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#include<utility>
#include<map>
#include<queue>
#include<set>
#include<bitset>
#include<stdio.h>
#include<deque>
using namespace std;
#define rep(i, n) for(int i = 0; i < n; i++)
typedef long long ll;

int main()
{
    int n, m, c, ans = 0;
    cin >> n >> m >> c;
    vector<int> b(m);
    rep(i, m) cin >> b[i];
    vector<vector<int> > a(n, vector<int>(m));
    rep(i, n) rep(j, m) cin >> a[i][j];

    rep(i, n){
        int sum = 0;
        rep(j, m){
            sum += a[i][j]*b[j];
        }
        if(sum + c > 0)ans++;
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <string>
#include <map>
#include <set>
#include <vector>
#include <cmath>
#include <algorithm>
#include <numeric>
#include <bitset>
#include <unordered_map>
#include <unordered_set>
#include <random>
#include <queue>
#include <memory>
#include <fstream>
#include <strstream>


#pragma GCC optimize("no-stack-protector,Ofast,unroll-loops,fast-math")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4.1,sse4.2,popcnt,abm,mmx,tune=native,avx,avx2")

#define int long long
#define ld long double
#define eb emplace_back
#define pb pop_back
#define mp make_pair
#define ss second
#define ff first
#define sqr(x) (x) * (x)
#define all(x) x.begin(), x.end()
#define sz(x) (int)x.size()

typedef int(*func)(int a, int b);

using namespace std;

const int INF = 1e9 + 7;
const int B = 299;
const int MOD = 1e9 + 123;
const ld EPS = 1e-7;
const ld PI = 3.14159265358979323;
const int MAXN = 2100;

random_device rd;
mt19937 get_rand(rd());

int gcd(int a, int b) {
	return (!a ? b : gcd(b % a, a));
}

vector < vector < int > > g;
bool u[2010], c[2010];

bool dfs(int v, bool z) {
	u[v] = 1;
	c[v] = z;
	for (auto i : g[v]) {
		bool k = 1;
		if (!u[i])
			k = dfs(i, !z);
		if (c[i] == z || !k)
			return 0;
	}
	return 1;
}


signed main() {
	//ifstream cin("input.txt");
	//ofstream cout("output.txt");
#ifdef _LOCAL
	freopen("output.txt", "w", stdout);
	freopen("input.txt", "r", stdin);
#endif
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	cout << fixed << setprecision(0);
	srand(time(NULL));

	int t = 1;
	//cin >> t;
	while (t--) {
		int n;
		cin >> n;
		vector < int > dp(n + 1);
		dp[0] = 0;
		for (int i = 1; i <= n; i++) {
			dp[i] = dp[i - 1] + 1;
			for (int e = 6; e <= n; e *= 6)
				if (i - e >= 0)
					dp[i] = min(dp[i], dp[i - e] + 1);
			for (int e = 9; e <= n; e *= 9)
				if (i - e >= 0)	
					dp[i] = min(dp[i], dp[i - e] + 1);
		}
		cout << dp[n];
	}
	return 0;
}

Measured memory_bytes: 1024
#include<iostream>
#include<vector>
#include<algorithm>

using namespace std;

int main() {
	long long n;
	long long pipe[65000] = {};
	vector<long long> joint;
	while (cin >> n,n) {
		long long sum = 0;
		for (long long i = 0; i < n; i++) {
			cin >> pipe[i];
			sum += pipe[i];
		}
		for (long long i = 0; i < n - 1; i++) {
			int a;
			cin >> a;
			joint.push_back(a);
		}
		long long ct = n;
		sort(joint.begin(),joint.end());
		long long max = sum * n;
		for (long long i = joint.size() - 1; i >= 0; i--){ 
			max = std::max(max, (i + 1) * (sum + joint[i]));
			sum += joint[i];
		}
		cout << max << endl;
		joint.clear();
		for (long long i = 0; i < n; i++)pipe[i] = 0;
	}
	return 0;
}

Measured memory_bytes: 2248
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
//#include <math.h>
//#include <algorithm>
#include <vector>

typedef long long ll;
#define MIN(a, b) ((a)>(b)? (b): (a))
#define MAX(a, b) ((a)<(b)? (b): (a))

using namespace std;

#define MOD 1000000007

long h, w;
long a[405][405];

void dfs(long i, long j, long count[2] )
{
    if(a[i][j]>=0) {
        count[a[i][j]] ++;
        long save = a[i][j];
        a[i][j] = -1;
        long k;
        for(k=0; k<4; k++) {
            long x=i, y=j;
            if(k==0) x--;
            if(k==1) x++;
            if(k==2) y--;
            if(k==3) y++;
            if(x>=0 && x<h && y>=0 && y<w && a[x][y]>=0 && save+a[x][y]==1) {
                dfs(x, y, count);
            }
        }
    }
    return;
}

int main(int argc, char* argv[])
{   
    scanf("%ld %ld", &h, &w);

    long i, j;
    for(i=0; i<h; i++) {
        char str[405]={0};
        scanf("%s", str);
        for(j=0; j<w; j++) {
            if(str[j]=='#') {
                a[i][j] = 1;
            }
            else {
                a[i][j] = 0;
            }
        }
    }

    long sum = 0;
    for(i=0; i<h; i++) {
        for(j=0; j<w; j++) {
            if(a[i][j]>=0) {
                long count[2] = {0,0};
                dfs(i,j, count);
                //printf("%ld %ld\n", count[0], count[1]);
                sum += (count[0] * count[1]);
            }
        }
    }

    printf("%ld\n", sum);

    return 0;
}


Measured memory_bytes: 11392
#include <iostream>
#include <sstream>
#include <algorithm>
#include <string>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <stack>
#include <memory>
#include <complex>
#include <numeric>
#include <cstdio>
#include <iomanip>
#include <random>

#define REP(i,m,n) for(int i=int(m);i<int(n);i++)
#define RREP(i,m,n) for(int i=int(n)-1;i>=int(m);--i)
#define EACH(i,c) for (auto &(i): c)
#define all(c) begin(c),end(c)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort(begin(c),end(c))
#define pb emplace_back
#define MP make_pair
#define SZ(a) int((a).size())
//#define int long long

#ifdef LOCAL
#define DEBUG(s) cout << (s) << endl
#define dump(x)  cerr << #x << " = " << (x) << endl
#define BR cout << endl;
#else
#define DEBUG(s) do{}while(0)
#define dump(x) do{}while(0)
#define BR 
#endif
using namespace std;

using UI = unsigned int;
using UL = unsigned long;
using LL = long long;
using ULL = unsigned long long;
using VI = vector<int>;
using VVI = vector<VI>;
using VLL = vector<LL>;
using VVLL = vector<VLL>;
using VS = vector<string>;
using PII = pair<int,int>;
using VP = vector<PII>;
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }

constexpr double EPS = 1e-10;
//constexpr double PI  = acos(-1.0);
//constexpr int INF = INT_MAX;
constexpr int MOD = 1'000'000'007;
//inline void modAdd(LL &l, LL &r) {l = (l + r) % MOD;}

template<class T> inline T sqr(T x) {return x*x;}

void solve() {
    int a,b,c;
    cin >> a >> b >> c;
    if (a == b && a != c) cout << "Yes" << endl;
    else if (a == c && a != b)  cout << "Yes" << endl;
    else if (b == c && b != a)  cout << "Yes" << endl;
    else cout << "No" << endl;
}

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

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <utility>

#define INF 1000000005


using namespace std;

long long ile, pojemnosc;
pair <long long, long long> tab[100000];
long long dp[1000000];
long long minimum = INF;
long long wynik = 0;
int main(){
    
    cin >> ile >> pojemnosc;
    
    
	for(int i = 0; i < ile; i++){
        cin >> tab[i].first >> tab[i].second;
        // first - weight
        // second - value
        minimum = min(minimum, tab[i].first);//do kiedy mam sprawdzac od dp[pojemnosc] do do[pojemnosc - minimum]
	}
    
    long long granica = 0;
    
    for(int element = 0; element < ile; element++){
        //min(pojemnosc, granica)
        for(int i = pojemnosc; i >= 0; i--){
            
            dp[i + tab[element].first] = max(dp[i + tab[element].first], dp[i] + tab[element].second);
            granica = max(granica, i + tab[element].first);//najwiekszy dotychczas osiagniety
            //cout << element << " " << i << "\n";
        }
        
    }
    
    /*
    for(int i = 0; i < pojemnosc; i++){
        cout << dp[i] <<  " ";
    }*/
    
    for(int i = 0; i < minimum; i++){
        //cout << dp[i] << " ";
        wynik = max(wynik, dp[pojemnosc - i]);
    }
    cout << wynik;
}


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

using namespace std;
using namespace __gnu_pbds;

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

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

const long long mod = 1000000007;
const long long inf = 1e18;

int main(){
    ios_base::sync_with_stdio(0); cin.tie(0);
    int n,d,x;
    cin>>n>>d>>x;
    ll ans=0;
    for(int i=0;i<n;i++){
        int a;
        cin>>a;
        ans+=ceil(d/(double)a);
    }
    cout<<ans+x<<endl;
    return 0;
}



Measured memory_bytes: 3552
#include <iostream>
#include <cstdint>
#include <cmath>
#include <string>
#include <vector>
#include <map>
#include <set>
#include <algorithm>
#include <iomanip>
#include <sstream>
 
int main(void)
{
    int64_t N, Q;
    std::string s;
    std::cin >> N >> Q >> s;
    std::vector<std::pair<int64_t, int64_t>> q_list(Q);
 
    for (int64_t i=0; i<Q; ++i) {
        int64_t a, b;
        std::cin >> a >> b;
        q_list.at(i) = std::make_pair(a, b);
    }

    std::vector<int64_t> thousand_list(1000000/1000);
    for (int64_t i=0; i<s.size()-1; ++i) {
        if (s.at(i) == 'A' && s.at(i+1) == 'C') thousand_list.at(i/1000)++;
    }

    auto Count = [&](int64_t l, int64_t r) {
        int64_t count = 0;
        for (int64_t i=l; i<r; ++i) {
            if (s.at(i) == 'A' && s.at(i+1) == 'C') count++;
        }
        return count;
    };

    for (auto& q : q_list) {
        int64_t count = 0;
        int64_t start = q.first-1;
        int64_t end = q.second-1;
        int64_t start_index = start / 1000;
        int64_t end_index = end / 1000;
        if (end_index - start_index >= 2) {
            for (int64_t i=start_index+1; i<end_index; ++i) {
                count += thousand_list.at(i);
            }
            count += Count(start, start+1000-(start%1000));
            count += Count(end-(end%1000), end);
        } else {
            count = Count(start, end);
        }
        std::cout << count << std::endl;
    }

    return 0;
}


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

#define rep(i, n) for(int i = 0; i < (n); ++i)
#define repr(i, n) for(int i = (n-1); i >= 0; --i)

template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }

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

const int MAX = 300005;
const int INF = 1001001001;
const int MOD = 1000000007;

int op(int a, int b) {
    return max(a, b);
}

int e() { return 0; }

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

    vector<int> A(N);
    for (auto &i : A) cin >> i;

    segtree<int, op, e> st(MAX);
    for (auto &i : A) {
        st.set(i, st.prod(max(0, i - K), min(MAX, i + K + 1)) + 1);
    }

    cout << st.prod(0, MAX) << endl;
}

Measured memory_bytes: 9628
h, w, k = gets.chomp.split(" ").map(&:to_i)
map = Array.new(h)
h.times do |i|
  map[i]=gets.chomp.split("")
end

cnt = 0
ans = 0
(1<<h).times do |i|
  (1<<w).times do |j|
    cnt = 0
    h.times do |h_shift|
      w.times do |w_shift|
        next if ((i>>h_shift)&1)==1 or ((j>>w_shift)&1)==1
        if map[h_shift][w_shift] == "#"
          cnt += 1
        end
      end
    end
    if k==cnt
      ans += 1
    end
  end
end
puts ans


Measured memory_bytes: 14336
#include<bits/stdc++.h>
#define ui unsigned int
#define ll long long
#define db double
#define ld long double
#define ull unsigned long long
const int MAXN=300+10,Mod=1e9+7;
int n,m;
ll ans,f[MAXN][MAXN][MAXN];
std::vector< std::pair<int,int> > V[MAXN];
template<typename T> inline void read(T &x)
{
	T data=0,w=1;
	char ch=0;
	while(ch!='-'&&(ch<'0'||ch>'9'))ch=getchar();
	if(ch=='-')w=-1,ch=getchar();
	while(ch>='0'&&ch<='9')data=((T)data<<3)+((T)data<<1)+(ch^'0'),ch=getchar();
	x=data*w;
}
template<typename T> inline void write(T x,char ch='\0')
{
	if(x<0)putchar('-'),x=-x;
	if(x>9)write(x/10);
	putchar(x%10+'0');
	if(ch!='\0')putchar(ch);
}
template<typename T> inline void chkmin(T &x,T y){x=(y<x?y:x);}
template<typename T> inline void chkmax(T &x,T y){x=(y>x?y:x);}
template<typename T> inline T min(T x,T y){return x<y?x:y;}
template<typename T> inline T max(T x,T y){return x>y?x:y;}
#define ft first
#define sd second
int main()
{
	read(n);read(m);
	for(register int i=1;i<=m;++i)
	{
		int l,r,x;read(l);read(r);read(x);
		V[r].push_back(std::make_pair(l,x));
	}
	f[0][0][0]=1;
	for(register int i=1;i<=n;++i)
	{
		for(register int j=0;j<i;++j)
			for(register int k=0;k<i;++k)
				if(!j||!k||(j!=k))
					for(register int p=(j!=i-1&&k!=i-1)?i-1:0;p<i;++p)
						if((!j&&!k)||(!j&&!p)||(!k&&!p)||(j!=p&&k!=p))
						{
							(f[i][k][p]+=f[j][k][p])%=Mod;
							(f[j][i][p]+=f[j][k][p])%=Mod;
							(f[j][k][i]+=f[j][k][p])%=Mod;
						}
		for(register int j=0,lt=V[i].size();j<lt;++j)
		{
			std::pair<int,int> pr=V[i][j];
			for(register int k=0;k<=i;++k)
				for(register int p=0;p<=i;++p)
					if(!k||!p||(k!=p))
						for(register int t=(k!=i&&p!=i)?i:0;t<=i;++t)
							if((!k&&!p)||(!k&&!t)||(!p&&!t)||(k!=t&&p!=t))
								if((k>=pr.ft)+(p>=pr.ft)+(t>=pr.ft)!=pr.sd)f[k][p][t]=0;
		}
	}
	for(register int i=0;i<=n;++i)
		for(register int j=0;j<=n;++j)
			if(!i||!j||(i!=j))
				for(register int k=(i!=n&&j!=n)?n:0;k<=n;++k)
					if((!i&&!j)||(!i&&!k)||(!j&&!k)||(i!=k&&j!=k))(ans+=f[i][j][k])%=Mod;
	write(ans,'\n');
	return 0;
}


Measured memory_bytes: 227584
N = gets.chomp.to_i

w = []

N.times do
  a, b = gets.chomp.split.map(&:to_i)
  w << [a, b]
end

current = 0

w.sort_by!{|_, x| x}

N.times do |i|

  if current + w[i][0] > w[i][1]
    puts 'No'
    exit
  end

  current += w[i][0]
end

puts 'Yes'


Measured memory_bytes: 22392
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <iomanip>
#include <queue>
#include <stack>
#include <cstdlib>
#include <map>
#include <iomanip>
#include <set>
#include <stdio.h>
#include <ctype.h>
#include <random>
#include <string.h>
#include <cmath>
#include <unordered_map>
#include <cstdio>
using namespace std;
#define pie 3.141592653589793238462643383279
#define mod 998244353
#define int long long
#define P pair<int,int>
#define all(vec) vec.begin(),vec.end()

int gcd(int x, int y) {
	if (y == 0)return x;
	return gcd(y, x%y);
}
int lcm(int x, int y) {
	return x / gcd(x, y)*y;
}
int kai(int x, int y) {
	int res = 1;
	for (int i = x - y + 1; i <= x; i++) {
		res *= i; res %= mod;
	}
	return res;
}
int mod_pow(int x, int y, int m) {
	int res = 1;
	while (y > 0) {
		if (y & 1) {
			res = res * x % m;
		}
		x = x * x % m;
		y >>= 1;
	}
	return res;
}

int comb(int x, int y) {
	if (y > x)return 0;
	return kai(x, y) * mod_pow(kai(y, y), mod - 2, mod) % mod;
}

string s;
int d[500010], d2[500010];
int ans;

signed main() {
	cin >> s;
	int n = (int)s.size();
	d[0] = 0;
	for (int i = 0; i < n; i++) {
		if (s[i] == '<')d[i + 1] = d[i] + 1;
		else d[i + 1] = 0;
	}
	d2[n] = 0;
	for (int i = n - 1; i >= 0; i--) {
		if (s[i] == '>')d2[i] = d2[i + 1] + 1;
		else d2[i] = 0;
	}
	for (int i = 0; i <= n; i++)ans += max(d[i], d2[i]);
	cout << ans << endl;
}

Measured memory_bytes: 8708
import sys
import numpy as np
input = sys.stdin.readline

 
def I(): return int(input())
def MI(): return map(int, input().split())
def LI(): return list(map(int, input().split()))
def TL(mylist):
    return np.array(mylist).T.tolist()

mylist1 = [list(map(int, input().rstrip().split())) for i in range(3)]
mylist2 = TL(mylist1)

def chech(mylist):
    result = True
    b1 = mylist[0][0] - mylist[0][1]
    c1 = mylist[0][0] - mylist[0][2]
    for i in range(1, 3):
        if (mylist[i][0] -  mylist[i][1]) != b1 or (mylist[i][0] -  mylist[i][2]) != c1:
            result = False
            break
    return result
    
if chech(mylist1) and chech(mylist2):
    print("Yes")
else:
    print("No")

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

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

    vector<ll> a(N+1,0);
    for(int i=1; i<=N; i++){
        ll A;
        cin>> A;
        a[i] = a[i-1]+A;
    }

    vector<ll> b(M+1,0);
    for(int i=1; i<=M; i++){
        ll B;
        cin>> B;
        b[i] = b[i-1]+B;
    }

    ll ans = 0;
    ll j = M;
    for(int i = 0; i<=N; i++){
        if(a[i]>K){
            break;
        }
        while(b[j] > K-a[i]){
            j--;
        }
        ans = max(ans, i+j);
    }

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

Measured memory_bytes: 6408
#include <iostream>
#include <algorithm>

using namespace std;

int main() {
	int a[5];
	cin >> a[0] >> a[1] >> a[2] >> a[3] >> a[4];
	sort(a, a+5, greater<int>());
	cout << a[0] << " " << a[1] << " " << a[2] << " " << a[3] << " " << a[4] << endl;
	return 0;
}

Measured memory_bytes: 0
#include<bits/stdc++.h>
using namespace std;
#define ll long long
ll i,j,k,l,m,n,o,p,q,r,s,t,u,v,w,x,y,z;
int main()
{
	scanf("%lld",&n);
	for(i=1;i<=n;i++)
	{
		scanf("%lld",&x);
		y=max(y,x);
		s+=y-x;
	}
	printf("%lld\n",s);
}

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

#define ff               first
#define ss               second
#define mp               make_pair
#define pb               push_back
#define pii              pair<int,int>
#define vi               vector<int> 
#define mii              map<int,int>
#define setbits(x)       __builtin_popcountll(x)
#define zerobits(x)      __builtin_ctzll(x)
#define mod              1000000007
#define inf              1e18
#define endl             "\n"

void h_code()
{
 #ifndef ONLINE_JUDGE
     freopen("input.txt", "r", stdin);
     freopen("output.txt", "w", stdout);
 #endif
ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
}

void l_code()
{
 #ifndef ONLINE_JUDGE
     cout<<"\nTime Elapsed: " << 1.0*clock() / CLOCKS_PER_SEC << " sec\n";
 #endif
}
const int N=100005;

int main() {
   // h_code();
    int t=1;
    while(t--)
    {
         int n;
         cin>>n;
         int temp;
         int cnt=0;
         int mini=INT_MAX;
         for(int i=0;i<n;i++)
         {
            cin>>temp;
            if(temp<=mini)
              {
                   cnt++;
                   mini=temp;
                //    cout<<mini;
              } 
         }
         cout<<cnt;

    }
   // l_code();
}

Measured memory_bytes: 256
#include<stdio.h>
int main()
{
	int n, d, count=0, min = 300000;
	scanf("%d", &n);
	while(n--)
	{
		scanf("%d", &d);
		if(d<min)
		{
			min = d;
			count++;
		}

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

Measured memory_bytes: 256
X = input().split()
A = int(X[0])
B = int(X[1])
C = int(X[2])
K = int(X[3])

d = 0

if K < A:
	d = K

elif K <= A + B:
	d = A

else:
	K = K - A - B
	d = A - K

print(d)

Measured memory_bytes: 9112
// AOJ 0546
//
// Lining up the cards

#include <stdio.h>
#include <string.h>
int a[10];
char kekka[5040][9];
int len;          // n
int r;            // k
int pcnt;
      
void print()
{
  if(r==2)
    sprintf(kekka[pcnt],"%d%d\0",a[0],a[1]);
  else if(r==3)
    sprintf(kekka[pcnt],"%d%d%d\0",a[0],a[1],a[2]);
  else if(r==4)
    sprintf(kekka[pcnt],"%d%d%d%d\0",a[0],a[1],a[2],a[3]);    

  pcnt++;
}

void recursive(int j)
{  
  int i,t,k;

     if(j==r){
       print();
       return;  
     }  
     for(i=j;i<len;i++)
       {  
      // j~iを循環右ローテート  
	 t=a[i];  
	 for(k=i;k>j;k--)  
	   a[k]=a[k-1];  
	 a[j]=t;  
	 recursive(j+1);  
      // j~iを循環左ローテート  
	 for(k=j;k<i;k++)  
	   a[k]=a[k+1];  
	 a[i]=t;  
       }  
} 

int comp_str(void * x,void * y)
{
  return(strcmp((char *)x,(char *)y));
}
int uniq_count()
{
  int i;
  char *p;
  int u_cnt = 1;

  qsort(kekka,pcnt,9,comp_str);
  p=&(kekka[0][0]);
  for(i=1;i<pcnt;i++)
    {
      if(strcmp(p,&(kekka[i][0])))
	 u_cnt++;
      p=&(kekka[i][0]);
    }
  return(u_cnt);
}
int main ()
{  
  int i;
  while(EOF != scanf("%d",&len) && EOF!=scanf("%d",&r) && (len || r)) 
    {
      
      for(i=0;i<len;i++)
	scanf("%d",&(a[i]));

      pcnt=0;
      recursive(0);

      printf("%d\n",uniq_count());

      //      for(i=0;i<pcnt;i++)
      // printf("%s\n",kekka[i]);

      //
    }
  return(0);
}  

Measured memory_bytes: 748
#define PI 3.141592
#include<stdio.h>
#include<math.h>

int main(){
	int N,i,k;
	scanf("%d",&N);
	while(N != 0){
		int x[N],y[N],r[N],m[N];
		double j;
		for(i=0;i<N;i++){
			scanf("%d %d %d %d",&x[i],&y[i],&r[i],&m[i]);
		}
		int max = 0;
		for(i=0;i<N;i++){
			for(j=0; j< 2*PI; j=j+0.001){
				double a,b,c,ab;
				if(j == 0 || j == PI){
					a = 1.0;
					b = 0.0;
					c = -x[i]-r[i]*cos(j);
					ab = sqrt(pow(a,2.0)+pow(b,2.0));
				}else{
					a = 1 / tan(j);
					if(a < 0.01 && a > -0.01){
						a = 0.0;
					}
					b = 1.0;
					c = (-x[i]-r[i]*cos(j)) / tan(j) - y[i] - r[i] * sin(j);
					if(a == 0){
						c = (int)(c*1000)/1000;
					}
					ab = sqrt(pow(a,2.0)+pow(b,2.0));
				}
				int tempmax = 0;
				for(k=0;k<N;k++){
					if(i==k){
						tempmax++;
					}else{
						double d = fabs(a*x[k] + b*y[k] + c) / ab;
						if(m[k] == 0){
							if((int)(d+0.5) == r[k]){
								tempmax++;
							}
						}else{
							if(d >= r[k] && d <= r[k] + m[k]){
								tempmax++;
							}
						}
					}
				}
				if(max < tempmax){
					max = tempmax;
				}
			}
		}
		printf("%d\n",max);
		scanf("%d",&N);
	}

}

Measured memory_bytes: 660
s = input()
t = input()
N, M = len(s), len(t)

schr, indchr = dict(), dict()
for i in range(N):
    if s[i] in schr:
        schr[s[i]].append(i+1) 
    else:
        schr[s[i]] = [i+1]
        indchr[s[i]] = 0

schrset = set(schr)
ans, pos, pre, back = 0, 0, set(), True
for i in range(M):
    if t[i] in schrset:
        c = schr[t[i]]
        if c[-1] <= pos:
            ans += N - pos + c[0]
            pos = c[0]
            if not back:
                for x in indchr.keys():
                    indchr[x] = 0
                back, pre = True, set()
        else:
            j = indchr[t[i]]
            while c[j] <= pos:
                j += 1
            if j > 0:
                pre.add(t[i])
            ans += c[j] - pos
            pos, back, indchr[t[i]] = c[j], False, j
    else:
        print(-1)
        exit()
print(ans)

Measured memory_bytes: 7668
package main

import "fmt"

func main() {
	var (
		n, k int
		s, t string
	)
	fmt.Scan(&n, &s, &k)
	for i := 0; i < n; i++ {
		if s[i] != s[k-1] {
			t += "*"
		} else {
			t += string(s[i])
		}
	}
	fmt.Println(t)
}


Measured memory_bytes: 512
#include <bits/stdc++.h>
#define int long long
#define double long double
using namespace std;
const int MOD =  1000000007;
const int INF = 1e11;
using Graph = vector<vector<int>>;

signed main(){
  int N;
  cin >> N;

  int ans = 0;
  for( int A = 1; A < N; A++ ){
    ans += (N-1)/A;
  }
  cout << ans << endl;
}


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

#define int long long
#define ll long long
#define pb push_back
#define mp make_pair
#define f(i,a,n) for(int i=a ; i<(int)n ; i++)
#define rf(i,n,a) for(int i=n ; i>=a ; i--)
#define F first
#define S second
#define all(c) (c).begin(),(c).end()
#define sz(v) (int)(v).size()
#define fill(a,v) memset(a,v,sizeof(a))
#define d1(a) cout << a << "\n"
#define d2(a,b) cout << a << " " << b << "\n"
#define d3(a,b,c) cout << a << " " << b << " " << c << "\n"
#define d4(a,b,c,d) cout << a << " " << b << " " << c << " " << d << "\n"
#define fast ios:: sync_with_stdio(false),cin.tie(nullptr);

typedef long double ld;
typedef vector<int> vi;
typedef pair<int,int> pii;
typedef pair<pii,int> ppi;
typedef vector<pii> vpi;

const int inf = 1e9;
const int inf64 = 1e18;
const int MOD = inf + 7;

int32_t main(){
	fast;
	int n,a,b;
	cin >> n >> a >> b;
	
	int ans = (n / (a + b))*a;
	int rem = n % (a+b);
	
	ans += min(rem , a);
	cout << ans;
}


Measured memory_bytes: 256
let array_of_string s = Array.init (String.length s) (fun i -> s.[i])

let () =
  let s' = read_line () in
  let t = read_line () in
  let regexp =
    array_of_string t
    |> Array.to_list
    |> List.map (Printf.sprintf "[%c\?]")
    |> String.concat ""
    |> Str.regexp in
  try
    let i = Str.search_backward regexp s' (String.length s') in
    Printf.printf "%s%s%s\n"
      (String.map (function '?' -> 'a' | c -> c) (String.sub s' 0 i))
      t
      (String.map (function '?' -> 'a' | c -> c) (String.sub s' (i + String.length t) (String.length s' - i - String.length t)))
  with Not_found -> print_endline "UNRESTORABLE"

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

int main()
{
    int a, b;
    cin >> a >> b;
    int ans = 0;
    for(int i=a;i<=b;i++){
        int tmp = i;
        int x[5];
        for(int j=0;j<5;j++){
            x[j] = tmp%10;
            tmp = tmp/10;
        }
        if(x[0] == x[4]){
            if(x[1] == x[3]){
                ans++;
            }
        }
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
    ($($r:tt)*) => {
        let s = {
            use std::io::Read;
            let mut s = String::new();
            std::io::stdin().read_to_string(&mut s).unwrap();
            s
        };
        let mut iter = s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
}

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

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

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

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

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

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

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

fn main() {
    input! { b: char }
    let ans = match b {
        'A' => 'T',
        'T' => 'A',
        'C' => 'G',
        'G' => 'C',
        _ => 'n',
    };
    println!("{}", ans);
}


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

public class Main {
  private static long count(long v, long x) {
    if (v >= 0) {
      return v / x + 1;
    }
    return 0;
  }
  
  private static long solve(long a, long b, long x) {
    return count(b, x) - count(a - 1, x);
  }
  
  private static void execute(ContestReader reader, PrintWriter out) {
    long a = reader.nextLong();
    long b = reader.nextLong();
    long x = reader.nextLong();
    out.println(solve(a, b, x));
  }
  
  public static void main(String[] args) {
    ContestReader reader = new ContestReader(System.in);
    PrintWriter out = new PrintWriter(System.out);
    execute(reader, out);
    out.flush();
  }
}

class ContestReader {
  private BufferedReader reader;
  private StringTokenizer tokenizer;
  
  ContestReader(InputStream in) {
    reader = new BufferedReader(new InputStreamReader(in));
  }
  
  public String next() {
    while (tokenizer == null || !tokenizer.hasMoreTokens()) {
      try {
        tokenizer = new java.util.StringTokenizer(reader.readLine());
      } catch (Exception e) {
        throw new RuntimeException(e);
      }
    }
    return tokenizer.nextToken();
  }
  
  public int nextInt() {
    return Integer.parseInt(next());
  }
  
  public long nextLong() {
    return Long.parseLong(next());
  }
  
  public double nextDouble() {
    return Double.parseDouble(next());
  }
  
  public String[] next(int n) {
    String[] array = new String[n];
    for (int i = 0; i < n; i++) {
      array[i] = next();
    }
    return array;
  }
  
  public int[] nextInt(int n) {
    int[] array = new int[n];
    for (int i = 0; i < n; i++) {
      array[i] = nextInt();
    }
    return array;
  }
  
  public long[] nextLong(int n) {
    long[] array = new long[n];
    for (int i = 0; i < n; i++) {
      array[i] = nextLong();
    }
    return array;
  }
  
  public double[] nextDouble(int n) {
    double[] array = new double[n];
    for (int i = 0; i < n; i++) {
      array[i] = nextDouble();
    }
    return array;
  }
  
  public char[] nextCharArray() {
    return next().toCharArray();
  }
  
  public int[][] nextInt(int n, int m) {
    int[][] matrix = new int[n][m];
    for (int i = 0; i < n; i++) {
      for (int j = 0; j < m; j++) {
        matrix[i][j] = nextInt();
      }
    }
    return matrix;
  }
  
  public long[][] nextLong(int n, int m) {
    long[][] matrix = new long[n][m];
    for (int i = 0; i < n; i++) {
      for (int j = 0; j < m; j++) {
        matrix[i][j] = nextLong();
      }
    }
    return matrix;
  }
  
  public double[][] nextDouble(int n, int m) {
    double[][] matrix = new double[n][m];
    for (int i = 0; i < n; i++) {
      for (int j = 0; j < m; j++) {
        matrix[i][j] = nextDouble();
      }
    }
    return matrix;
  }
  
  public char[][] nextCharArray(int n) {
    char[][] matrix = new char[n][];
    for (int i = 0; i < n; i++) {
      matrix[i] = next().toCharArray();
    }
    return matrix;
  }
}


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


auto solve(long long N, std::vector<long long> a){
    vector< long long > acc{};
    for(const auto& v : a) {
        auto last = (0 < acc.size()) ? acc.back() : 0LL;
        acc.push_back(last + v);
    }

    long long ret = numeric_limits<long long >::max();
    for(int i = 0; i < (acc.size() - 1); ++i) {
        const auto v = acc[i];
        ret = min(ret, abs(acc.back() - 2 * v));
    }

    return ret;
}

int main(){
    long long N;
    scanf("%lld",&N);
    std::vector<long long> a(N);
    for(int i = 0 ; i < N ; i++){
        scanf("%lld",&a[i]);
    }
    auto result = solve(N, std::move(a));
    cout << result << endl;
    return 0;
}


Measured memory_bytes: 3956
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
using P = pair<ll,ll>;
const ll mod = 1e9+7;
#define ALL(x) (x).begin(),(x).end()
#define REP(i,n) for(ll (i)=0;(i)<(n);(i)++)
#define REPS(i,n) for(ll (i)=1;(i)<=(n);(i)++)
#define RREP(i,n) for(ll (i)=(n-1);(i)>=0;(i)--)
#define RREPS(i,n) for(ll (i)=(n);(i)>0;(i)--)
#define pb push_back
#define mp make_pair
#define F first
#define S second
#define UNIQUE(v) v.erase(unique(ALL(v)),v.end());

template<class T> inline void chmin(T& a, T b){
    if (a > b){
        a = b;
    }
}

template<class T> inline void chmax(T& a, T b){
    if (a < b){
        a = b;
    }
}

signed main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout<<fixed<<setprecision(12);
    ll X;
    cin >> X;
    cout << (X >= 30 ? "Yes" : "No") << "\n";
}

Measured memory_bytes: 3644
#include <bits/stdc++.h>
 
using namespace std;
 
#define sim template < class c
#define ris return * this
#define dor > debug & operator <<
#define eni(x) sim > typename \
  enable_if<sizeof dud<c>(0) x 1, debug&>::type operator<<(c i) {
sim > struct rge { c b, e; };
sim > rge<c> range(c i, c j) { return rge<c>{i, j}; }
sim > auto dud(c* x) -> decltype(cerr << *x, 0);
sim > char dud(...);
struct debug {
#ifdef LOCAL
    ~debug() { cerr << endl; }
    eni(!=) cerr << boolalpha << i; ris; }
    eni(==) ris << range(begin(i), end(i)); }
    sim, class b dor(pair < b, c > d) {
    ris << "(" << d.first << ", " << d.second << ")";
    }
    sim dor(rge<c> d) {
    *this << "[";
    for (auto it = d.b; it != d.e; ++it)
        *this << ", " + 2 * (it == d.b) << *it;
    ris << "]";
    }
#else
sim dor(const c&) { ris; }
#endif
};
#define imie(...) " [" << #__VA_ARGS__ ": " << (__VA_ARGS__) << "] "
 
typedef vector<int> vi;
typedef vector<long long> vll;
typedef vector<long double> vld;
typedef long long ll;
typedef long double ld;
#define PI 3.14159265358979323846
#define sqr(a) ((a) * (a))
#define len(V) (int)V.size()
#define FOR(i, a, b) for(int i = (a); i < (b); ++i)
#define all(a) (a).begin(),(a).end()
#define rall(a) (a).rbegin(),(a).rend()
#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define endl '\n'
#define fix(a) fixed << setprecision(a)
#define readv(x) for(auto &_ : (x)) {cin >> _;}
#define printv(x) for(auto &_ : (x)) {cout << _ << ' ';} cout << endl
#define EPS 1e-6
#define MAXN 100047

int main() {
	ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
	
	int n, m, x; cin >> n >> m >> x;
	vi a(n+1); 
	FOR(i, 0, m){
		int z; cin >> z;
		a[z] = 1;
	}
	
	int c1 = 0, c2 = 0;
	FOR(i, x, n+1) c1 += a[i];
	for (int i = x; i > 0; --i) c2 += a[i];
	
	cout << min(c1, c2) << endl;
	
	return 0;
}


Measured memory_bytes: 3604