akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#define int long long
using namespace std;

signed main(){
	int N,W; cin>>N>>W;
	vector<int>w(N);
	vector<int>v(N);
	for(int i=0;i<N;i++)cin>>w[i]>>v[i];
	vector<vector<int>>dp(110,vector<int>(1000000+100,1e16));
	int V=*max_element(v.begin(),v.end());
	int ans=0;
	dp[0][0]=0;
	for(int i=0;i<N;i++){
		for(int j=0;j<=V*N;j++){
			dp[i+1][j]=min(dp[i+1][j],dp[i][j]);
			dp[i+1][j+v[i]]=min(dp[i+1][j+v[i]],dp[i][j]+w[i]);
		}
	}
	for(int j=0;j<=V*N;j++){
		if(dp[N][j]<=W)ans=j;
	}
	cout<<ans<<endl;
}

Measured memory_bytes: 867840
import sys
from heapq import *
input = sys.stdin.readline


def main():
    n = int(input())
    a = list(map(int, input().split()))

    af = a[:n]
    ab = [-v for v in a[2*n:]]
    af_sum = sum(af)
    ab_sum = -sum(ab)

    heapify(af)
    heapify(ab)
    judge = [0]*(n+1)
    judge[0] += af_sum
    judge[n] -= ab_sum
    
    for i in range(n):
        if a[n+i] > af[0]:
            af_sum -= heappop(af)
            heappush(af, a[n+i])
            af_sum += a[n+i]
        judge[i+1] += af_sum
        
        if -a[2*n-1-i] > ab[0]:
            ab_sum += heappop(ab)
            heappush(ab, -a[2*n-1-i])
            ab_sum += a[2*n-1-i]
        judge[n-1-i] -= ab_sum
    

    ans = max(judge)
    print(ans)

    
if __name__ == "__main__":
    main()


Measured memory_bytes: 114004
#include<cstdio>
#include<algorithm>
#include<cstring>
#define rep(i, s, t) for(i = s; i <= t; ++i)
#define dep(i, s, t) for(i = s; i >= t; --i)

using namespace std;

const int N = 1e5 + 10;
int n, m; bool ans = 1;
int pos[N];
struct edge{int ed, v, ne;} e[N<<1]; int he[N], in[N], en;

void ins(int a, int b, int c) {
	e[++en].ed = b; e[en].v = c; e[en].ne = he[a]; he[a] = en; ++in[b];
}

void dfs(int u) {
	for(int i = he[u], v; i; i = e[i].ne) {
		v = e[i].ed;
		if(!pos[v]) {
			pos[v] = pos[u] + e[i].v;
			dfs(v);
		} else 
			if(pos[u] + e[i].v != pos[v]) ans = 0;
	}
}

int main() {
	int i, x, y, z;
	scanf("%d%d", &n, &m);
	rep(i, 1, m) {scanf("%d%d%d", &x, &y, &z); ins(x, y, z);}
	rep(i, 1, n) if(!in[i]) {pos[i] = 1; dfs(i);}
	rep(i, 1, n) if(!pos[i]) ans = 0;
	if(ans) puts("Yes"); else puts("No");
	return 0;
}

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

const int INF=1e9;
 
int main()
{
  int n,k;
  cin>>n>>k;
  vector<int> h(n);
  int i=0;
  for(int i=0;i<n;i++)
  {
    cin>>h[i];
  }
  
  int cost[n];
  for(int i=0;i<n;i++)
    cost[i]=INF;
  
  for(int i=0;i<n;i++)
  {
    if(i==0)
      cost[i]=0;
    else if(i==1)
      cost[i]=abs(h[i]-h[i-1]);
    else
    {
      for(int j=1;j<=min(k,i);j++)
        cost[i]=min(cost[i],cost[i-j]+abs(h[i]-h[i-j]));
    }
  }
  cout<<cost[n-1]<<endl;
}

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

int main() {
    int K, N;
    cin >> N >> K;
    vector<int> cnt(N, 0);
    rep(i, N) {
        int A;
        cin >> A;
        cnt[--A] += 1;
    }
    sort(cnt.begin(), cnt.end());
    int ans = 0;
    rep(i, N - K) ans += cnt[i];
    cout << ans << endl;
    return 0;
}

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

#define ll long long int
#define pb push_back
#define eb emplace_back
#define xx first
#define yy second
#define INF 0x3f3f3f3f
#define show(x) cerr<<#x<<" : "<<x<<'\n';
#define yogeshk972() cerr<<"\nTime Taken : "<<(float)(clock()-time_p)/CLOCKS_PER_SEC<<"\n";
clock_t time_p=clock();
 
using namespace __gnu_pbds;
using namespace std;
const int N=2e5+1, mod=998244353;

typedef tree< int,null_type, less_equal<int>,rb_tree_tag,tree_order_statistics_node_update>  os;

int main(){
	ios_base::sync_with_stdio(0);	cin.tie(0);
	int n,k;
	cin>>n>>k;
	int a[n];
	for(int i=0;i<n;i++){
		cin>>a[i];
		a[i]%=k;
	}
	
	map<int, os > mp;
	map<pair<int,int>,int> mp2;
	ll pre=0,res=0;
	
	for(int i=0;i<n;i++){
		pre+=a[i];
		if(pre>=k) pre-=k;
		if(pre==i+1) res++;
		
		/*
		for(auto x:mp[pre-i]){
			if(x<pre)res++;
		}
		
		for(auto x:mp[pre-i+k]){
			if(x>pre)res++;
		}
		*/
		
		
		if(mp[pre-i].size()){
			if( *mp[pre-i].begin() <= pre )
				res+=mp[ pre-i ].order_of_key( pre ) + mp2[{pre-i,pre}] ;
		}
		//cout<<res<<"\n";
		if(mp[pre-i+k].size() ){
			if( *mp[pre-i+k].begin() > pre ) res+=mp[pre-i+k].size();
			else res+=mp[pre-i+k].size() - ( mp[ pre-i+k ].order_of_key( pre ) + mp2[{pre-i+k,pre}] ) ;
		}
		//cout<<i<<" : "<<mp[pre-i].size()<<" "<<mp[pre-i+k].size()<<"\n";
		//cout<<mp[ pre-i ].order_of_key( pre ) <<" | "<<mp[pre-i+k].size() - ( mp[ pre-i+k ].order_of_key( pre ) + mp2[pre] ) <<"\n";
		//cout<<i<<" : "<<res<<"\n";
		mp[ pre-i ].insert(pre);
		mp2[{pre-i,pre}]++;
	}
	cout<<res;
	
    yogeshk972();
}


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


void solve() {
  int W, H, N;
  cin >> W >> H >> N;
  int x1 = 0, x2 = W + 1, y1 = 0, y2= H + 1;
  int x , y , a;
  for (int i = 1; i <= N; i++) {
    cin >> x >> y >> a;
    if(a == 1) {
      x1 = max(x1, x);
    }
    else if (a == 2) {
      x2  = min(x2, x);
    }
    else if (a == 3) {
      y1 = max(y1, y);
    }
    else if ( a == 4) {
      y2 = min(y2, y);
    }
  }
  //cout << x1 << " " << x2 << "\n";
  //cout << y1 << " " << y2 << "\n";
  if(x2 <= W){
    W = x2;
  }
  W -= x1;
  if(y2 <= H) {
    H = y2;
  }
  H -= y1;
  //cout << W << " " << H << endl;
  if(W <= 0 || H <= 0) {
    cout << 0;
  }
  else {
    cout << W*H;
  }

}

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


Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<vector>
#include<string>
#include<map>
#include<set>
using namespace std;
#define ll long long
const int maxn = 1e5 + 5;
int a[51][51];
bool r[51], c[51];
long long T, n, m, k, x;
void init()
{
	for (int i = 0; i < 51; i++)r[i] = 0;
	for (int i = 0; i < 51; i++)c[i] = 0;
}
int main()
{
	ios::sync_with_stdio(0);
	cin.tie(0), cout.tie(0);
	ll  a, b, w, v;
	cin >> a >> v >> b >> w >> T;
	//if (a == b) { cout << "YES"; return 0; }
		if (w >= v) { cout << "NO" << endl; return 0; }
		else  {
			ll tt = abs(a - b);
			if ((v - w) * T >= tt) { cout <<"YES"<< endl; return 0; }
			else { cout << "NO" << endl; return 0; }
		}
	
}

Measured memory_bytes: 3652
#include <iostream>
#include <iomanip>
#include <vector>
#include <map>
#include <string>
#include <math.h>
#include <algorithm>
#include <numeric>
#include <queue>
using namespace std;
#define rep(i, n) for (int i = 0; i < (n); i++)

int main() {
    int n;
    cin >> n;
    
    int ans = 0;
    int now = n;
    while (now > 0) {
        now -= 1000;
        ans++;
    }

    cout << 1000*ans - n << endl;
}


Measured memory_bytes: 3632
#include<cstdio>
#define no return puts("No")&0;
#define yes return puts("Yes")&0;
using namespace std;
const int maxn=100005;
long long m;
int n,Q,cnt,a[maxn],b[maxn],c[maxn],fa[maxn];
inline char nc(){
	static char buf[100000],*p1=buf,*p2=buf;
	return p1==p2&&(p2=(p1=buf)+fread(buf,1,100000,stdin),p1==p2)?EOF:*p1++;
}
inline long long read(){
	long long ret=0;bool f=0;char ch=nc();
	while(ch>'9'||ch<'0') f^=ch=='-',ch=nc();
	while(ch<='9'&&ch>='0') ret=ret*10+ch-'0',ch=nc();
	return f?-ret:ret;
}
int getfa(int x){return fa[x]==x?x:fa[x]=getfa(fa[x]);}
int main(){
	n=read(),m=read(),Q=read();
	for (int i=1;i<=n;i++) fa[i]=i;
	for (int i=1;i<=Q;i++){
		a[i]=read()+1,b[i]=read()+1,c[i]=read();
		if(m==n-1&&c[i]) no
		if(!c[i]){
			int fx=getfa(a[i]),fy=getfa(b[i]);
			if(fx^fy) fa[fx]=fy;
		}
	}
	if(m==n-1) yes
	for (int i=1;i<=Q;i++)
	if(c[i]&&getfa(a[i])==getfa(b[i])) no
	for (int i=1;i<=n;i++)
	cnt+=getfa(i)==i;
	if(cnt<=2) no
	if(m-n<=1ll*cnt*(cnt-3)>>1) yes
	else no
}

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

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

    int H[N];
    rep(i,N){
        cin >> H[i];
    }

    int can_ride = 0;
    rep(i,N){
        if(H[i]>=K){
            ++can_ride;
        }
    }

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

    return 0;
}

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

int main(){
int N;
  cin>>N;
  vector<int>V(N);
  vector<int>C(N);
  for(int i=0; i<N; i++){
   cin>>V[i]; }
  for(int i=0; i<N; i++){
   cin>>C[i]; }
 
  int sum=0;
  for(int i=0; i<N; i++){
   if(V[i]-C[i]>0){sum+=V[i]-C[i];}
  }
  
  cout<<sum;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0; i < (n);++i)
using namespace std;
using ll = long long; 
using P = pair<int,int>;
using vv = 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;}

const int INF = 2147483647;
const long long inf = 1ll << 60;
const long long mod = 1000000007;

int dx[4] = {1,0,-1,0};
int dy[4] = {0,-1,0,1};
int main(){
    multiset<int> st;
    vector<int> table(100010,0);
    int n;cin >> n;
    for(int i=0;i<n;i++){ 
	int a;cin >> a;	
	st.insert(a);
	table[a]++;
    }
    int Q;cin >> Q;
    ll ans = 0;
    for(auto itr=st.begin();itr!=st.end();itr++){
        ans += *itr;
    }

    for(int i=0;i<Q;i++){
    	int a,b;cin >> a >> b;
	int k= table[a];
	table[a] = 0;
	table[b] += k;
	ans += k*(b-a);
	cout << ans << endl;
    }
    return 0;
}


Measured memory_bytes: 8256
n = int(input())
coins = [1]
t = 6 
while t <= n:
    coins.append(t)
    t *= 6

t = 9
while t <= n:
    coins.append(t)
    t *= 9

coins.sort()

dp = [ float("inf") for _ in range(n+10) ]
dp[0] = 0

for i in range(n+1):
    for c in coins:
        if i + c > n:
            continue
        dp[i+c] = min(dp[i+c], dp[i]+1)

print(dp[n])

Measured memory_bytes: 6296
#include<bits/stdc++.h>
using namespace std;
#define REP(i,n) for(int i=0;i<(n);i++)
#define REP2(i,a,b) for(int i=(a);i<(b);i++)
#define ALL(v) (v).begin(),(v).end()
#define INF 2e9
typedef long long ll;

int main()
{
  int n;
  cin>>n;
  vector<int> a(n);
  bool f=0;
  int d=0,ans=0;
  REP(i,n){
    cin>>a[i];
    if(i==0) continue;
    if(f==0){
      if(a[i-1]<a[i]){
        d=1;
        f=1;
      }else if(a[i-1]>a[i]){
        d=-1;
        f=1;
      }
      continue;
    }
    if(a[i-1]<a[i]){
      if(d==-1){
        ans++;
        d=0;
        f=0;
        continue;
      }
    }else if(a[i-1]>a[i]){
      if(d==1){
        ans++;
        d=0;
        f=0;
        continue;
      }
    }
  }

  cout<<ans+1<<endl;

  return 0;
}

Measured memory_bytes: 640
#include<cstdio>
#include<cmath>
#include<string>
#include<iostream>
#include<algorithm>
#include<utility>
#include<vector>
#include<map>
#include<set>
#include<limits>
#include<bitset>
#include<array>
#include<numeric>

using namespace std;
typedef long long int ll;

ll n;
int sg,sra,q;

int digits(long long int target){
    int digit=0;
    sg=target;
    while(target!=0){
        sg=target;
        target/=10;
        digit++;
    }
    return digit;
}

int main(){
    scanf("%lld",&n);
    q=digits(n);
    sra=sg;
    digits(n+1);
    if(sra==sg)printf("%d\n",sra-1+(q-1)*9);
    else{
        q=digits(n);
        printf("%d\n",sg+(q-1)*9);
    }
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(n) for (ll i = 0; i < n; ++i)
#define rep2(i, n) for (ll i = 0; i < n; ++i)
#define rep3(i, a, b) for (ll i = a; i < b; ++i)
#define rep4(i, a, b, c) for (ll i = a; i < b; i += c)
#define erep(n) for (ll i = 0; i <= n; ++i)
#define erep2(i, n) for (ll i = 0; i <= n; ++i)
#define erep3(i, a, b) for (ll i = a; i <= b; ++i)
#define erep4(i, a, b, c) for (ll i = a; i <= b; i += c)
#define rrep(i, a, b) for (ll i = a; i > b; --i)
#define rrep2(i, a, b, c) for (ll i = a; i > b; i -= c)
#define errep(i, a, b) for (ll i = a; i >= b; --i)
#define errep2(i, a, b, c) for (ll i = a; i >= b; i -= c)
#define print(a) cout << a << endl;
#define printVec(v) printf("{"); for (const auto& i : v) { std::cout << i << ", "; } printf("}\n");
#define cin(x) cin >> x;
const ll MOD = 1000000007;
inline int newline() { putchar('\n'); return 0; }

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

    vector<ll> p(n);
    rep2(i, n) cin(p[i]);

    ll m = LLONG_MAX;
    ll c = 0;

    rep2(i, n) {
        ll target = p[i];
        if (target < m) {
            m = target;
            c++;
        }
    }

    print(c);
    return 0;
}

Measured memory_bytes: 1792
// Binary search
#include <stdio.h>

int main() {
  int a[100000], b[50000];
  int left, mid, right;
  int i, n, q;
  int cnt = 0;

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

  // input the search number
  scanf("%d", &q);
  for(i = 0; i < q; i++) {
    scanf("%d", &b[i]);
  }

  // search
  for(i = 0; i < q; i++) {
    left = 0;
    right = n;
    while(left < right) {
      mid = (left + right) / 2;
      if(b[i] == a[mid]) {
	cnt++;
	break;
      }
      if(b[i] > a[mid]) {
	left = mid + 1;
      }
      else if(b[i] < a[mid]) {
	right = mid;
      }
    }
  }

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



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

#define TRACE(x) x
#define WATCH(x) TRACE(cout << #x" = " << x << endl)
#define WATCHR(a, b) TRACE(for (auto it=a; it!=b;) cout << *(it++) << " "; cout << endl)
#define WATCHC(V) TRACE({cout << #V" = "; WATCHR(V.begin(), V.end());})

#define all(x) (x).begin(), (x).end()

using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vll = vector<ll>;
using vvll = vector<vll>;
using vb = vector<bool>;
using vs = vector<string>;

mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

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

    int H, W, N;
    cin >> H >> W >> N;

    vvi col(H + 1);
    for (int i = 0; i < N; i++) {
        int x, y;
        cin >> x >> y;
        col[x].push_back(y);
    }

    int ans = H, ym = 1;
    for (int x = 2; x <= H; x++) {
        bool up = true;
        for (int y : col[x]) {
            if (y <= ym) {
                ans = min(ans, x - 1);
            } else if (y == ym + 1) {
                up = false;
            }
        }
        ym += up;
    }
    cout << ans << endl;

    return 0;
}



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

const double EPS = 1e-8;

typedef complex<double> P;
typedef pair<P,P> L;

struct data{
  P p;
  L l;
  bool is_p, correct;
  data(P p):p(p),is_p(true), correct(true){}
  data(L l):l(l),is_p(false), correct(true){}
  data():correct(false){}
};

double dot(P a, P b){ return real(conj(a)*b); }

double cross(P a, P b){ return imag(conj(a)*b); }

P proj(P p, L l){
    return l.first + dot(p - l.first, l.second - l.first) / norm(l.second - l.first) * (l.second - l.first);
}

P reflect(P p, L l){
  return p + (proj(p,l) - p) * 2.0;
}

P crossPoint(L l, L m){
  double A = cross(l.second - l.first, m.second - m.first);
  double B = cross(l.second - l.first, l.second - m.first);
  if(fabs(A) < EPS && fabs(B) < EPS) return m.first;
  else if(fabs(A) >= EPS) return m.first + B / A * (m.second - m.first);
}


data func(const string &str, int &pos);
data exp(const string &str, int &pos){
  data x = func(str, pos);
  
  while(pos < str.size() && str[pos] == '@'){
    pos++;
    data y = func(str, pos);

    if(x.is_p && y.is_p){
      x = data(L(x.p, y.p));
    } else if(!x.is_p && !y.is_p){
      x = data(crossPoint(x.l, y.l));
    } else {
      if(!x.is_p) swap(x, y);
      x = data(reflect(x.p, y.l));
    }
  }

  return x;
}

data func(const string &str, int &pos){
  data res = data();

  if(pos >= str.size()-1);
  else if(str[pos] == '(' && str[pos+1] == '('){
    pos++;
    res = exp(str, pos);
    pos++;
  } else if(str[pos] == '(' && (str[pos+1] >= '0' && str[pos+1] <= '9' || str[pos+1] == '-')){
    pos++;
    double x = 0, y = 0;
    bool is_minus = false;
    if(str[pos] == '-'){
      pos++;
      is_minus = true;
    }
    while(str[pos] >= '0' && str[pos] <= '9'){
      x *= 10;
      x += str[pos] - '0';
      pos++;
    }
    if(is_minus) x *= -1;

    pos++;

    is_minus = false;
    if(str[pos] == '-'){
      pos++;
      is_minus = true;
    }
    while(str[pos] >= '0' && str[pos] <= '9'){
      y *= 10;
      y += str[pos] - '0';
      pos++;
    }
    if(is_minus) y *= -1;

    pos++;
    res = data(P(x, y));
  }

  return res;
}

P solve(const string &str){
  int pos = 0;
  return exp(str, pos).p;
}

int main(){
  string str;
  while(cin >> str && str != "#"){
    P ans = solve(str);
    printf("%.8f %.8f\n", real(ans), imag(ans));
  }
}

Measured memory_bytes: 1292
#include<bits/stdc++.h>
using namespace std;
#define sync ios_base::sync_with_stdio(false), cin.tie(NULL)
#define F first
#define S second
#define pb emplace_back
#define mt make_tuple
#define gcd __gcd
#define PI 3.141592653589
// Input
#define in(a) scanf("%d",&a)
#define in2(a,b) scanf("%d%d",&a,&b)
#define in3(a,b,c) scanf("%d%d%d",&a,&b,&c)
#define llin(a) cin >> a
#define inl(a) scanf("%lld",&a)
#define read(v,i,n) for(i=0;i<n;i++)in(v[i])
#define twod(mat,i,j,n,m) rep(i,n){rep(j,m)in(mat[i][j]);}
#define sc(ch) scanf("%c",&ch)
#define sstr(str) scanf("%s",str)
// Output
#define pr(a) printf("%d ",a)
#define pr2(a,b) printf("%d %d\n",a,b)
#define pr3(a,b,c) printf("%d %d %d\n",a,b,c)
#define out(a) printf("%d\n",a)
#define outl(a) printf("%lld\n",a)
#define llpr(a) cout << a << " "
#define llout(a) cout << a << "\n"
#define yes printf("YES\n")
#define no printf("NO\n")
#define lin printf("\n")
// Iterator
#define lp(i,a,b) for(i=a;i<b;i++)
#define rep(i,n) for(i=0;i<n;i++)
#define all(vec) vec.begin(),vec.end()
#define lower(v,k) lower_bound(v.begin(),v.end(),k)-v.begin()
#define upper(v,k) upper_bound(v.begin(),v.end(),k)-v.begin()
#define tf(mytuple) get<0>(mytuple)
#define ts(mytuple) get<1>(mytuple)
#define tt(mytuple) get<2>(mytuple)
// Debug
#define dbg(v,i,n) for(i=0;i<n;i++)pr(v[i]); lin
#define what(x) cerr << #x << " : " << x << "\n"
#define ck printf("continue\n")
#define debug(args...) { string _s = #args; replace(_s.begin(), _s.end(), ',', ' '); stringstream _ss(_s); istream_iterator<string> _it(_ss); err(_it, args); }
void err(istream_iterator<string> it) {}
template<typename T, typename... Args>
void err(istream_iterator<string> it, T a, Args... args)
{
	cerr << *it << " = " << a << "\n";
	err(++it, args...);
}
// Data Type
#define ll long long int
#define ii pair<int,int>
#define pli pair<ll,int>
#define triple tuple<int,int,int>
#define vi vector<int>
#define vii vector<pair<int,int> >
#define vvi vector<vector<int> >
#define viii vector<pair<pair<int,int>,int> >
#define vvii vector<vector<pair<int,int> > >
#define M 1000000007
#define N 12800
bool dp[80][80][2*N];
vvii ad(80);
int main()
{
    int n,m,i,j,x,y,a,b,k;
    in2(n,m);
    rep(i,n)
    {
        ad[i].resize(m);
        rep(j,m)
            in(x),ad[i][j].F=x;
    }
    rep(i,n)
    {
        rep(j,m)
            in(x),ad[i][j].S=x;
    }
    tie(a,b)=ad[0][0];
    dp[0][0][N+a-b]=1;
    dp[0][0][N-a+b]=1;
    rep(i,n)
    {
        rep(j,m)
        {
            if(i+1<n)
            {
                tie(a,b)=ad[i+1][j];
                rep(k,2*N)
                {
                    if(dp[i][j][k])
                        dp[i+1][j][k+a-b]=1,dp[i+1][j][k-a+b]=1;
                }
            }
            if(j+1<m)
            {
                tie(a,b)=ad[i][j+1];
                rep(k,2*N)
                {
                    if(dp[i][j][k])
                        dp[i][j+1][k+a-b]=1,dp[i][j+1][k-a+b]=1;
                }
            }
        }
    }
    int ans=N;
    rep(k,2*N)
    {
        if(dp[n-1][m-1][k])
            ans=min(ans,abs(k-N));
    }
    out(ans);
}









Measured memory_bytes: 159104
# エラトステネスの篩, フェルマーの小定理
def make_prime_table(n):
    sieve = list(range(n + 1))
    sieve[0] = -1
    sieve[1] = -1
    for i in range(2, int(n ** 0.5) + 1):
        if sieve[i] != i:
            continue
        for j in range(i * i, n + 1, i):
            if sieve[j] == j:
                sieve[j] = i
    return sieve


def prime_factorize(n):
    result = []
    while n != 1:
        p = prime_table[n]
        c = 0
        while n % p == 0:
            n //= p
            c += 1
        result.append((p, c))
    return result


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

m = 1000000007

prime_table = make_prime_table(10 ** 6)

lcm_factors = {}
for a in A:
    for p, c in prime_factorize(a):
        if p not in lcm_factors or lcm_factors[p] < c:
            lcm_factors[p] = c

lcm = 1
for p in lcm_factors:
    lcm *= pow(p, lcm_factors[p], m)
    lcm %= m

result = 0
for i in range(N):
    result += lcm * pow(A[i], m - 2, m)
    result %= m
print(result)


Measured memory_bytes: 49688
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int  i,j,cur=0,t,k,a,b,c=0;
    string s;
    getline(cin,s);
    for(i=0;i<s.size();i++)
    {
        if(s[i]==',')
            s[i]=' ';
    }
    cout<<s<<"\n";



return 0;
}


Measured memory_bytes: 3596
class Tree
  def initialize(size)
    @size = size
    @parents = size.times.map { |i| i }
  end

  def union(x, y)
    ry = root(y)
    @parents[ry] = root(x)
  end

  def root(x)
    arr = []
    while !root?(x)
      arr << x
      x = @parents[x]
    end
    arr.each { |idx| @parents[idx] = x }
    x
  end

  def root?(x)
    @parents[x] == x
  end

  def group_size
    s = 0
    0.upto(@size-1) do |i|
      s += 1 if root?(i)
    end
    s
  end
end

n, m = gets.chomp.split(' ').map(&:to_i)

tree = Tree.new(n)

(m).times do
  x, y, _ = gets.chomp.split(' ').map(&:to_i)
  tree.union(x - 1, y - 1)
end

puts tree.group_size


Measured memory_bytes: 2684
#include<iostream>
#include<fstream>
#include<sstream>
#include<cstdio>
#include<vector>
#include<list>
#include<stack>
#include<queue>
#include<deque>
#include<map>
#include<set>
#include<algorithm>
#include<cmath>
#include<string>
#include<cstring>
#include<cstdlib>
using namespace std;

#define ull unsigned long long
#define ll long long
#define rep(i,j) for(int i=0;i<j;++i)
#define loop(i,a,j) for(int i=a;i<j;++i)
#define mpi(it,table,T,E) for(map<T,E>::iterator it = table.begin();it!=table.end();++it)
#define PI 3.141592654
/*
ifstream fin("input.txt");
ofstream fout("output.txt");
#define cin fin
#define cout fout
*/
#define N 5005

bool visited[N][N];
int data[N];

int solve(int i,int j,int sum){
	if( i == j) return sum;
	if(visited[i][j])return sum;
	
	int a = max(sum,solve(i+1,j,sum-data[i]));
	int b = max(sum,solve(i,j-1,sum-data[j]));

	visited[i][j] = true;
	return max(a,b);
}


int main(){
	int n;
	while(scanf("%d",&n),n){
		memset(visited,0,sizeof(visited));
		int sum = 0;
		rep(i,n){
			scanf("%d",&data[i]);
			sum += data[i];
		}
		sum = solve(0,n-1,sum);
		printf("%d\n",sum);	
	}
	return 0;
}

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

int solve(std::string str, char x)
{
	//std::cout << "on " << str << '\n';
	bool valid = true;
	for(int i = 0; i < str.size(); i++)
		valid = valid && str[i] == x;
	if(valid)
		return 0;
	std::string nxt;
	for(int i = 0; i + 1 < str.size(); i++)
	{
		bool got = str[i] == x || str[i + 1] == x;
		nxt += got ? x : '#';
	}
	return 1 + solve(nxt, x);
}

int main()
{
	std::string str;
	std::cin >> str;
	int ans = str.size();
	for(char i = 'a'; i <= 'z'; i++)
	{
		int cur_ans = solve(str, i);
		ans = std::min(ans, cur_ans);
		//std::cout << "got ans " << cur_ans << '\n';
	}
	std::cout << ans << '\n';
}

Measured memory_bytes: 256
import sys

input = sys.stdin.readline


def main():
    N, K = map(int, input().split())
    h = [0] * N
    for i in range(N):
        h[i] = int(input())
    h.sort()

    ans = float("inf")
    for i in range(N - (K - 1)):
        diff = h[i + (K - 1)] - h[i]
        if diff < ans:
            ans = diff

    print(ans)


if __name__ == "__main__":
    main()


Measured memory_bytes: 7472
#include <algorithm>
#include <iostream>
#include <string>
#include <random>
#include <cassert>
#include <cstring>
#include <chrono>
#include <set>
#include <map>

using namespace std;

typedef long long ll;

const int maxn = 100 * 1000;

int n, m, k;
vector<vector<int>> g;
vector<vector<int>> gBad;
int color[maxn];
int cnt[maxn];

void DFS(int v, int c) {
  if (color[v] != -1) return;
  color[v] = c;
  for (int to : g[v]) DFS(to, c);
}

int main()
{
  cin >> n >> m >> k;
  g.resize(n);
  gBad.resize(n);
  for (int i = 0; i < m; ++i) {
    int a, b;
    cin >> a >> b;
    a--;
    b--;
    g[a].push_back(b);
    g[b].push_back(a);
  }
  for (int i = 0; i < k; ++i) {
    int a, b;
    cin >> a >> b;
    a--;
    b--;
    gBad[a].push_back(b);
    gBad[b].push_back(a);
  }
  memset(color, -1, sizeof(color));
  int cur = 0;
  for (int i = 0; i < n; ++i) if (color[i] == -1) {
    DFS(i, cur);
    cur++;
  }
  for (int i = 0; i < n; ++i) cnt[color[i]]++;
  for (int i = 0; i < n; ++i) {
    int result = cnt[color[i]] - 1;

    set<int> s;

    for (int to : g[i]) {
      result--;
      s.insert(to);
    }

    for (int to : gBad[i]) {
      if (s.find(to) != s.end()) continue;
      if (color[to] == color[i]) result--;
    }

    if (i > 0) cout << " ";
    cout << result;
  }

  cout << endl;
  return 0;
}


Measured memory_bytes: 16888
#include <iostream>
#include <cmath>
#include <algorithm>
using namespace std;
int main(){
  int n, i, c[9], k, ans=0;
  cin >> n;
  int a[n];
  for(i=0; i<9; i++)
    c[i]=0;
  for(i=0; i<n; i++){
    cin >> a[i];
    k=min(a[i]/400, 8);
    c[k]++;
  }
  for(i=0; i<8; i++){
    if(c[i]>0)
      ans++;
  }
  cout << max(ans, 1) << " " << ans+c[8];
  return 0;
}


Measured memory_bytes: 256
/*...Part - 01...*/

#include <iostream>
#include <algorithm>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <string>
#include <cmath>
#include <vector>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <stack>
#include <queue>
#include <deque>
#include <iterator>
#include <bitset>
#include <assert.h>
#include <new>
#include <sstream>
//#include <bits/stdc++.h>
using namespace std ;

/*...Part - 02...*/

typedef long long               ll ;
typedef long double             ld ;
typedef unsigned long long      ull ;
typedef pair<int,int>           pii ;
typedef pair<ll,ll>             pll ;
typedef vector<int>             vi ;
typedef vector<ll>              vll ;
typedef vector<vector<int>>     vvi ;

int Int(){int x ; scanf("%d",&x) ; return x ;}
ll Long(){ll x ; scanf("%lld",&x) ; return x ;}

/*...Part - 03...*/
/*....Debugger....*/

#define error(args...) { string _s = #args; replace(_s.begin(), _s.end(), ',', ' '); stringstream _ss(_s); istream_iterator<string> _it(_ss); err(_it, args); }
void err(istream_iterator<string> it) {cout << endl ;}
template<typename T, typename... Args>
void err(istream_iterator<string> it, T a, Args... args) {
    cerr << *it << " = " << a << ' ' ;
    err(++it, args...);
}

/*...Part - 04...*/
/*...Needed to change according to problem requirements...*/

const int N          = (int)2e5 + 5 ;
const int maxN       = (int)1e6 + 6 ;
const ll  Mod        = (ll)1e9 + 7 ;
const int inf        = (int)2e9 ;
const ll  Inf        = (ll)1e18 ;

/*..........................................................*/
/*...Part - 05...*/

#define     debug(x)    cerr << #x << " = " << x << '\n' ;
#define     rep(i,b,e)  for(__typeof(e) i = (b) ; i != (e + 1) - 2 * ((b) > (e))  ; i += 1 - 2 * ((b) > (e)))
#define     Int         Int()
#define     Long        Long()
#define     all(x)      x.begin() , x.end()
#define     sz(x)       (int)x.size()
#define     ff          first
#define     ss          second
#define     pb          push_back
#define     eb          emplace_back
#define     mem(a)      memset(a , 0 ,sizeof a)
#define     memn(a)     memset(a , -1 ,sizeof a)

/*...Part - 06...*/
/*...... ! Code start from here ! ......*/

ll dp[10002][100][2];
string s ;
int k ;

ll call(int p, int d, int b){
	if(p == sz(s))return !d ;
	ll& ret = dp[p][d][b] ;
	if(~ret)return ret ;
	ret = 0 ;
	int up = (b == 1) ? s[p] - '0' : 9 ;
	for(int i = 0 ; i <= up ; ++i){
		ret += call(p + 1, (d + i) % k , b and i == up) ;
		ret %= Mod ;
	}
	return ret ;
}


int main(){
    int test = 1 , tc = 0 ;
    while(test--){
        cin >> s ;
        k = Int ;
        memn(dp) ;
        ll res = call(0, 0, 1) - 1 ;
        res %= Mod ;
        if(res < 0)res += Mod ;
        cout << res << '\n' ;
    }
    return 0 ;
}

/*...Always look at the part - 04...*/
/*...............END................*/




Measured memory_bytes: 16640
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0; i<(n) ;i++)
#define pb push_back
#define all(v) (v).begin(),(v).end()
#define fi first
#define se second
#define sz(x) ((int)(x).size())
using ll=long long;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
#define MOD  1000000007
const ll INF=1e18;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b){ a = b; return 1; } return 0; }



int main(int argc, char const *argv[]) {
  string s;
  int n;
  cin >> n >> s;
  rep(i,sz(s)){
    char c=s[i];
    int x=c-'A';
    x=(x+n)%26;
    char tmp=x+'A';
    cout << tmp;
    }

  cout  << endl;
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define pb push_back
#define fst first
#define snd second
#define fore(i,a,b) for(int i=a,ggdem=b;i<ggdem;++i)
#define SZ(x) ((int)x.size())
#define ALL(x) x.begin(),x.end()
#define mset(a,v) memset((a),(v),sizeof(a))
#define FIN ios::sync_with_stdio(0);cin.tie(0);cout.tie(0)
using namespace std;
typedef long long ll;

double dp[303][303][303];

ll n;

double f(ll x, ll y, ll z){
	if(x<0||y<0||z<0)return 0;
	double &r=dp[x][y][z];
	if(r>=0)return r;
	if(x==0&&y==0&&z==0){
		r=0; return 0;
	}
	r=(1.*n+f(x-1,y,z)*x+f(x+1,y-1,z)*y+f(x,y+1,z-1)*z)/(x+y+z);
	return r;
}

int main(){FIN;
	cin>>n;
	ll a[3]={0,0,0};
	fore(i,0,n){
		ll lle; cin>>lle; lle--;
		a[lle]++;
	}
	fore(i,0,303){
		fore(j,0,303){
			fore(k,0,303){
				dp[i][j][k]=-1;
			}
		}
	}
	cout<<fixed<<setprecision(12)<<f(a[0],a[1],a[2]);
	
	return 0;
}

Measured memory_bytes: 217600
n = int(input())
t,a = map(int, input().split())
h = list(map(int, input().split()))
ind , temp = 0, float("inf")
for i in range(n):
    x = abs(a-(t-h[i]*0.006))
    if x <= temp:
        ind = i
        temp = x
print(ind+1)


Measured memory_bytes: 3060
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <queue>
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
typedef pair<int, P> Q;

ll mod = 1000000007;
int n, k;
double ans;

int main()
{
	cin >> n >> k;
	for (int i = 1; i <= n; i++)
	{
		double u = (double)1 / n;
		double m = i;
		while (m < k)
		{
			m *= 2;
			u /= 2;
		}
		ans += u;
	}
	printf("%.10f\n", ans);
	cin >> n;
}

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

int main() {
  int N, A, B;
  cin >> N >> A >> B;

  int p1 = A * N;
  int p2 = B;

  if (p1 < p2) {
    cout << p1 << endl;
  }else{
    cout << p2 << endl;
  }

}


Measured memory_bytes: 256
#include <iostream>
#include <cstring>
#include <string>    
#include <vector>
#include <queue>
#include <map>
#include <algorithm>
#include <cmath>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
ll n, ga, sa, ba, gb, sb, bb;
string str;

int main(){
	cin >> n >> ga >> sa >> ba >> gb >> sb >> bb;

	ll dp[n+1];
	for(ll i = 0; i <= n; i++){dp[i] = i;}
	for(ll i = 0; i <= n-1; i++){
		if(i+ga <= n){dp[i+ga] = max(dp[i]+gb, dp[i+ga]);}
		if(i+sa <= n){dp[i+sa] = max(dp[i]+sb, dp[i+sa]);}
		if(i+ba <= n){dp[i+ba] = max(dp[i]+bb, dp[i+ba]);}
	}
	
	n = dp[n];
	ll dp2[n+1];
	for(ll i = 0; i <= n; i++){dp2[i] = i;}
	for(ll i = 0; i <= n-1; i++){
		if(i+gb <= n){dp2[i+gb] = max(dp2[i]+ga, dp2[i+gb]);}
		if(i+sb <= n){dp2[i+sb] = max(dp2[i]+sa, dp2[i+sb]);}
		if(i+bb <= n){dp2[i+bb] = max(dp2[i]+ba, dp2[i+bb]);}
	}
	
	cout << dp2[n] << endl;
	return 0;
}

Measured memory_bytes: 195584
#include <iostream> // cout, endl, cin
#include <string> // string, to_string, stoi
#include <vector> // vector
#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <utility> // pair, make_pair
#include <tuple> // tuple, make_tuple
#include <cstdint> // int64_t, int*_t
#include <cstdio> // printf
#include <math.h>//pow,powl,powf
#include <map> // map
#include <queue> // queue, priority_queue
#include <set> // set
#include <stack> // stack
#include <deque> // deque
#include <unordered_map> // unordered_map
#include <unordered_set> // unordered_set
#include <bitset> // bitset
#include <cctype> // isupper, islower, isdigit, toupper, tolower
#include <stdlib.h>
#include <stdio.h>


using namespace std;
using Graph = vector<vector<int>>;

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

vector<bool> seen;

void dfs(const Graph& G, int v) {
    seen[v] = true; // v を訪問済にする

    // v から行ける各頂点 next_v について
    for (auto next_v : G[v]) {
        if (seen[next_v]) continue; // next_v が探索済だったらスルー
        dfs(G, next_v); // 再帰的に探索
    }
}

int abs_A(int num) {
    if (num > 0)
        return num;
    else
        return -num;
}

int abs_B(long long num, long long numb) {
    if (num - numb >= 0)
        return num - numb;
    else
        return -1 * (num - numb);
}

long long gcd(long long a, long long b) {
    if (b == 0) return a;
    else return gcd(b, a % b);
}
long long lcm(long long a, long long b) {
    return a * b / gcd(a, b);
}

bool permutation(vector<int>& vec, vector<int>& P) {
    bool ok = true;
    for (int i = 0; i < vec.size(); i++) {
        if (vec.at(i) != P.at(i)) {
            ok = false;
        }
    }
    return ok;
}

const long long MOD = 1000000007;
const int INF = 1001001001;

int main() {
    string S;
    cin >> S;
    if (S.size() % 2 == 1) {
        cout << "No" << endl;
        return 0;
    }
    for (int i = 0; i < S.size() - 1; i = i+2) {
        if (S.at(i) != 'h' || S.at(i + 1) != 'i') {
            cout << "No" << endl;
            return 0;
        }
        
    }

    cout << "Yes" << endl;
}


Measured memory_bytes: 256
fun main(args: Array<String>) {
    val N = readInputLine().toInt()

    dfs(N, 1, "a", 1)
}

fun readInputLine(): String {
    return readLine()!!
}

fun dfs(length: Int, currentLen: Int, current: String, adder: Int) {
    if (currentLen == length) {
        println(current)
        return
    }
    repeat(adder) {
        dfs(length, currentLen + 1, current + ('a' + it).toString(), adder)
    }
    dfs(length, currentLen + 1, current + ('a' + adder).toString(), adder + 1)
}


Measured memory_bytes: 48444
#include<iostream>
using namespace std;
 
int main(){
    int y[7];
    int x[6][6]={{0,3,5,2,4,0},{4,0,1,6,0,3},{2,6,0,0,1,5},{5,1,0,0,6,2},{3,0,6,1,0,4},{0,4,2,5,3,0}};
    int a,b,c,d;
    int q;
    cin>>y[1]>>y[2]>>y[3]>>y[4]>>y[5]>>y[6];
    cin>>q;
    for(int i=0;i<q;i++){
        cin>>a>>b;
        for(int j=1;j<=6;j++){
            if(a==y[j]){
                c=j;
            }
            if(b==y[j]){
                d=j;
            }
        }
        cout<<y[x[c-1][d-1]]<<endl;
    }
    return 0;
}


Measured memory_bytes: 3084
#include <stdio.h>

int main(void)
{

	long a, b;
	long ans;
	char op;

	scanf("%ld %c %ld", &a,&op,&b);



	if (op == '-'){
		ans = a - b;
	}
	else {
		ans = a + b;
	}

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

	return 0;
}



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

int main() {
	int n;
	double h, m;
	double ha, ma;
	double x;
	cin >> n;
	for (int i = 0; i < n; i++) {
		scanf("%lf:%lf", &h,&m);
		ha = 30 * h + (m / 2);
		ma = m * 6;
		x = ma - ha;
		if (x < 0) { x*= -1;}
		if (x > 180) {
			x*=-1;
		x += 360;
		}
		if (x >= 0 && x < 30) { cout << "alert" << endl; }
		else if (x >= 90 && x <= 180) { cout << "safe" << endl; }
		else { cout << "warning" << endl; }
	}
	return 0;
}

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

typedef long long ll;
typedef long double ld;

const int MOD = 1000000007;

int add(int a, int b){
    return (a+b)%MOD;
}

int mat[3005][3005];

int main(){
    ios_base::sync_with_stdio(false);
    cout.precision(10);
    cout<<fixed;

    int n, m;
    cin >> n >> m;
    mat[1][1] = 1;
    for(int i=1; i<=n; i++){
        string s;
        cin >> s;
        for(int j=1; j<=m; j++){
            if(s[j-1] == '.'){
                mat[i][j] += add(mat[i-1][j], mat[i][j-1]);
            }
        }
    }
    cout << mat[n][m];
    return 0;
}


Measured memory_bytes: 11904
#include <bits/stdc++.h>
using namespace std;
int main(){
    string a,b,ans = "No";
    cin >> a >> b;
    int num = stoi(a + b);
    if(floor(sqrt(num))*floor(sqrt(num)) == num) ans = "Yes";
    cout << ans << endl;
    return 0;
}

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

int main(void) {
	int n, m, p, i;
	char *s = malloc(sizeof(char)*3);
	scanf("%d%d", &n, &m);
	int *accept = malloc(sizeof(int)*n);
	int *penalty = malloc(sizeof(int)*n);
	for(i = 0; i < n; i++) {
		*(accept + i) = 0;
		*(penalty + i) = 0;
	}
	for(i = 0; i < m; i++) {
		scanf("%d%2s", &p, s);
		if(*s == 'A' && *(s + 1) == 'C')
			*(accept + p - 1) = 1;
		else if(*(accept + p - 1) == 0)
			(*(penalty + p - 1))++;
	}
	int ans1 = 0;
	int ans2 = 0;
	for(i = 0; i < n; i++) {
		ans1 += *(accept + i);
		if(*(accept + i) == 1)
			ans2 += *(penalty + i);
	}
	free(s);
	free(accept);
	free(penalty);
	printf("%d %d\n", ans1, ans2);
	return 0;
}

Measured memory_bytes: 896
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(n);++i)
#define all(a) (a).begin(),(a).end()
#define dunk(a) cout << (a) << endl
using namespace std;
typedef long long ll;

int main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	int x, y;
	cin >> x >> y;

	vector<int> ans = { abs(y - x),abs(y - (-x) + 1),abs(-y - x + 1),abs(-y - (-x) + 2) };

	int just_ans = 1001001001;

	rep(i, 4) {
		if (i == 0 && x <= y) just_ans = min(just_ans, ans[i]);
		if (i == 1 && -x <= y) just_ans = min(just_ans, ans[i]);
		if (i == 2 && x <= -y) just_ans = min(just_ans, ans[i]);
		if (i == 3 && -x <= -y) just_ans = min(just_ans, ans[i]);
	}

	dunk(just_ans);
	
	return 0;
}

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

#define rep(i,n) for (int i = 0; i< (n); ++i)
#define vvec(m,n) vector<vector<int>> (int(m), vector<int>(n))
#define ALL(a) (a).begin(), (a).end()

using ll = long long;

int main(){
    int N;
    cin >> N;
    int dis = N / 15 * 200;
    cout << N * 800 - dis << endl;
}

Measured memory_bytes: 256
#include<iostream>
using namespace std;
 
int main(){
	unsigned long n,b,r,a;

  	cin >> n >> b >> r;
  	if(b == 0){
    	a = 0;
    } else if(b > n){
    	a = n;
    } else if(n < (b + r) && b < n){
      	a = b;
    } else {
      a = ((n / (b + r)) * b);
      if((n % (b + r)) > b){
          a += b;
      } else if ((n % (b + r)) <= b){
          a += (n % (b + r));
      }            
    }
  	cout << a;
	return 0;		 
}

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

const double EPS = 1e-8;
typedef vector<double> vec;
typedef vector<vec> mat;

vec gauss_jordan(const mat& A, const vec& b){
    int n = A.size();
    mat B(n, vec(n + 1));
    for(int i = 0 ; i < n ; ++i){
        for(int j = 0 ; j < n ; ++j){
            B[i][j] = A[i][j];
        }
    }
    for(int i = 0 ; i < n ; ++i){
        B[i][n] = b[i];
    }

    for(int i = 0 ; i < n ; ++i){
        int pivot = i;
        for(int j = i ; j < n ; ++j){
            if(abs(B[j][i]) > abs(B[pivot][i])){
                pivot = j;
            }
        }
        swap(B[i], B[pivot]);

        if(abs(B[i][i]) < EPS){
            return vec();
        }

        for(int j = i + 1 ; j <= n ; ++j){
            B[i][j] /= B[i][i];
        }

        for(int j = 0 ; j < n ; ++j){
            if(i != j){
                for(int k = i + 1 ; k <= n ; ++k){
                    B[j][k] -= B[j][i] * B[i][k];
                }
            }
        }
    }

    vec x(n);
    for(int i = 0 ; i < n ; ++i){
        x[i] = B[i][n];
    }

    return x;
}

int main(){
    mat A(2, vec(2));
    vec b(2);
    while(cin >> A[0][0] >> A[0][1] >> b[0] >> A[1][0] >> A[1][1] >> b[1]){
        vec ans = gauss_jordan(A, b);
        for(int i = 0 ; i < 2 ; ++i){
            if(i){
                cout << " ";
            }
            cout << fixed << setprecision(3) << ans[i];
        }
        cout << endl;
    }

    return 0;
}


Measured memory_bytes: 3268
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <iostream>
#include <algorithm>
#define MOD 1000000007
using namespace std;
typedef long long ll;

template <typename Tp> inline void getint(Tp &num){
	register int ch, neg = 0;
	while(!isdigit(ch = getchar())) if(ch == '-') neg = 1;
	num = ch & 15;
	while(isdigit(ch = getchar())) num = num * 10 + (ch & 15);
	if(neg) num = -num;
}

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

int N, X, a[205], p[205][100005], ans, inv[100005] = {1, 1}, fac = 1;

int main(){
	getint(N), getint(X), p[N + 1][X] = 1;
	for(register int i = 1; i <= N; i++) getint(a[i]), fac = fac * (ll)i % MOD;
	for(register int i = 2; i <= N; i++) inv[i] = (MOD - MOD / i) * (ll)inv[MOD % i] % MOD;
	sort(a + 1, a + N + 1);
	for(register int i = N; i; i--)
		for(register int j = 0; j <= X; j++){
			mkazu(p[i][j % a[i]], p[i + 1][j] * (ll)inv[i] % MOD);
			mkazu(p[i][j], p[i + 1][j] * (MOD + 1LL - inv[i]) % MOD);
		}
	for(register int i = 0; i <= X; i++) mkazu(ans, p[1][i] * (ll)i % MOD);
	return printf("%lld\n", ans * (ll)fac % MOD), 0;
}


Measured memory_bytes: 79360
import java.util.*;
import java.math.*;
     
class Main{
    public static void main(String[] args) {
        
        try(Scanner sc = new Scanner(System.in)){

            String lineA = sc.next();
            String lineB = sc.next();
            String lineC = sc.next();

            System.out.println(lineA.substring(0,1) + lineB.substring(1,2) + lineC.substring(2,3));

        }catch(Exception e){
            e.printStackTrace();
        }        
    }
}

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

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

  if (max({a, b, c}) * 2 == a + b + c)
    cout << "Yes" << endl;
  else
    cout << "No" << endl;
  return 0;
}

Measured memory_bytes: 3596
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class Main {

	public static void main(String[] args) throws IOException {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));

		while(true){
			String[] tmpArray = br.readLine().split(" ");

			int m = Integer.parseInt(tmpArray[0]);
			int n = Integer.parseInt(tmpArray[1]);

			if(m == 0){
				break;
			}

			//上限がこの値であることはわかっている
			boolean flower[] = new boolean[7368792];

			//エラトステネスもどき
			for(int i = m; i < flower.length && n > 0 ; i++){
				if(flower[i]){
					continue;
				}

				n--;
				for(int j = 1; i*j < flower.length ; j++){
					flower[i*j] = true;
				}
			}

			//何年まで花が咲き続けるか
			for(int i = m; i < flower.length ; i++){
				if(!flower[i]){
					System.out.println(i);
					break;
				}
			}
		}
	}

}



Measured memory_bytes: 84640
#pragma GCC optimize(2)
#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<double, double> pdd;

const ll mod = 1e9 + 7;
const int N = 1e5 + 10, M = 1e3 + 10;
const ll INF = 0x3f3f3f3f3f3f3f3f;
const int inf = 0x3f3f3f3f;
const double eps = 1e-6;

#define pi acos(-1)

int main()
{
    int a, b;
    cin >> a >> b;
    int l = 1, r = 1e6;
    int ans = -1;
    while(l <= r)
    {
        int mid = l + r >> 1;
        int x = mid * 0.08, y = mid * 0.1;
        if(x == a && y == b)
        {
            r = mid - 1;
            ans = mid;
        }
        else if(y > b)
            r = mid - 1;
        else if(x > a)
            r = mid - 1;
        else
        {
            l = mid + 1;
        }   
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
#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 a, b, c;
    cin >> a >> b >> c;
    ll ans1 = (a % 2) * b * c;
    ll ans2 = (b % 2) * a * c;
    ll ans3 = (c % 2) * a * b;
    cout << min({ans1, ans2, ans3}) << endl;
    return 0;
}

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

constexpr long long MOD = 1'000'000'007;

class binomial_coefficients {
	long long MAX_VAL;
	vector<long long> fac, mmi;

public:

	binomial_coefficients(){
	}
	
	binomial_coefficients(long long num){
		init(num);
	}
	
	~binomial_coefficients(){
		
	}
	
	void init(long long num){
		MAX_VAL = num+1; 
		fac.resize(MAX_VAL);
		mmi.resize(MAX_VAL);
		
		factorial_mod();
		modular_multiplicatibe_inverse();
	}
	
	void factorial_mod(){
		 fac[0] = 1;
		for(long long i = 1; i < MAX_VAL; fac[i] %= MOD, i++)
			fac[i] = fac[i - 1] * (i % MOD);
	}
	
	long long power(long long x, long long n){
		long long ans = 1;
		for(;n;n >>= 1, x *= x, ans %= MOD, x %= MOD)
			if(n&1)ans*=x;
		return ans % MOD;
	}
	
	void exgcd(long long a, long long b, long long &x, long long &y){
		if(b == 0){
			x = 1;
			y = 0;
			return ;
		}
		exgcd(b, a % b, y, x);
		y -= a / b * x;
	}
	
	void modular_multiplicatibe_inverse(){
		long long x, y;  
		exgcd(fac[MAX_VAL - 1], MOD, x, y);
		mmi[MAX_VAL-1] = (x % MOD + MOD) % MOD;
		// mmi[MAX_VAL-1] = power(fac[MAX_VAL-1], MOD-2);
		for(long long i = MAX_VAL - 2; i >= 0; mmi[i]%=MOD, i--)
			mmi[i] = mmi[i + 1] * ((i + 1) % MOD);
	}
	
	long long combination(long long n, long long r){
		return r < 0 ? 0 :n < r ? 0 :fac[n] * (mmi[r] * mmi[n-r] % MOD) % MOD;
	}
};


int main(){
	
	long long n, k;
	long long ans = 0;
	binomial_coefficients bc;
	
	cin>>n>>k;
	
	if(n > k) ans = 0;
	else ans = 1;
	
	cout<<ans<<endl;
}


Measured memory_bytes: 3116
/* 
 * File:   main.cpp
 * Author: Sebastian Hall
 * Created on August 20, 2020, 4:10 PM
 * Purpose: https://atcoder.jp/contests/dp/tasks/dp_b
 */

#include <bits/stdc++.h>
using namespace std;

typedef long long ll;
typedef long double triple;

int main() {
    ios::sync_with_stdio(false);
    //Declare variables
    int n = 0, k = 0;
    
    //Read input
    cin>>n>>k;
    int arr[n], dp[n];
    for(int i = 0; i < n; ++i) cin>>arr[i];
    
    //Create dp array
    dp[0] = 0;
    for(int i = 1; i < n; ++i) {
        //Take min of all possible answers from [i - 1, i - k]
        dp[i] = numeric_limits<int>::max();
        for(int j = 1; j <= k && j <= i; ++j) {
            dp[i] = min(dp[i], dp[i - j] + abs(arr[i] - arr[i - j]));
        }
    }
    
    //Output answer
    cout<<dp[n - 1]<<endl;

    //A Sebastian Production
    return 0;
}

Measured memory_bytes: 4396
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define repeat(i,s,n) for(int (i)=s; (i)<(n); (i)++)
#define revrep(i,n) for(int (i)=(n)-1;i>=0; i--)

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout<<setprecision(std::numeric_limits<float>::max_digits10);
  cout<<fixed;
  int n,m;
  cin>>n>>m;
  vector<ll> a(n);
  rep(i,n)cin>>a[i];
  sort(a.begin(),a.end());
  vector<pair<ll,ll>> cb(m);
  rep(i,m) {
    ll c,b;
    cin>>b>>c;
    cb.push_back(make_pair(c,b));
  }
  sort(cb.begin(),cb.end());
  reverse(cb.begin(),cb.end());
  int cnt=0;
  vector<ll> x;
  rep(i,m) {
    ll c,b;
    tie(c,b)=cb[i];
    rep(t,b) {
      x.push_back(c);
      cnt++;
      if(cnt==n)
	goto FUCK;
    }
  }
 FUCK:
  int idx=0;
  rep(i,n) {
    if(x[idx]>a[i]) {
      a[i]=x[idx];
      idx++;
    }
  }
  ll ans=accumulate(a.begin(),a.end(),0LL);
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 5988