akhauriyash/Code-Regression huggingface dataset:
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.StringTokenizer;
import java.io.IOException;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.InputStream;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        MyScanner in = new MyScanner(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        C solver = new C();
        solver.solve(1, in, out);
        out.close();
    }

    static class C {
        public void solve(int testNumber, MyScanner in, PrintWriter out) {
            int N = in.Int();
            int M = in.Int();
            int Q = in.Int();
            int[] a = new int[Q];
            int[] b = new int[Q];
            int[] c = new int[Q];
            int[] d = new int[Q];
            for (int i = 0; i < Q; i++) {
                a[i] = in.Int() - 1;
                b[i] = in.Int() - 1;
                c[i] = in.Int();
                d[i] = in.Int();
            }

            int max = 0;
            for (int i = 1; i <= M; i++) {
                int[] A = new int[N];
                A[0] = i;
                int temp = calc(N, M, a, b, c, d, A, 0);
                max = Math.max(max, temp);
            }
            out.println(max);

        }

        private int calc(int N, int M, int[] a, int[] b, int[] c, int[] d, int[] A, int i) {
            if (i + 1 == N) {
                int Q = a.length;
                int ret = 0;
                for (int j = 0; j < Q; j++) {
                    if (A[b[j]] - A[a[j]] == c[j]) {
                        ret += d[j];
                    }
                }
                return ret;
            }
            int ii = i + 1;
            int max = 0;
            for (int j = A[i]; j <= M; j++) {
                A[ii] = j;
                int temp = calc(N, M, a, b, c, d, A, ii);
                max = Math.max(max, temp);
            }
            A[ii] = A[i];
            return max;
        }

    }

    static class MyScanner {
        private BufferedReader in;
        private StringTokenizer st;

        public MyScanner(InputStream stream) {
            in = new BufferedReader(new InputStreamReader(stream));
        }

        public String next() {
            while (st == null || !st.hasMoreTokens()) {
                try {
                    String rl = in.readLine();
                    if (rl == null) {
                        return null;
                    }
                    st = new StringTokenizer(rl);
                } catch (IOException e) {
                    throw new RuntimeException(e);
                }
            }
            return st.nextToken();
        }

        public int Int() {
            return Integer.parseInt(next());
        }

    }
}



Measured memory_bytes: 34356
#include<bits/stdc++.h>
using namespace std;
#define ll long long 
int main()
{
	ll n,weight;
	cin>>n>>weight;
	ll w[n],val[n];
	for(int i=0;i<n;i++)
	cin>>w[i]>>val[i];
	ll dp[n+1][weight+1];
	memset(dp,0,sizeof dp);
	
	for(int i=1;i<=n;i++)
	{
		for(int j=1;j<=weight;j++)
		{
			if(w[i-1]<=j)
			dp[i][j]=max(dp[i-1][j],val[i-1]+dp[i-1][j-w[i-1]]);
			else
			dp[i][j]=dp[i-1][j];
		}
	}
	
	cout<<dp[n][weight]<<endl;
}

Measured memory_bytes: 79104
n = int(input())
t,a = map(int,input().split())
H = list(map(int,input().split()))
ans = 10000000000
for i in range(n):
    if abs(a-(t-H[i]*0.006)) < ans:
        ans = abs(a-(t-H[i]*0.006))
        final = i

print(final+1)

Measured memory_bytes: 3060
using System;
using System.Collections.Generic;
using System.Linq;

namespace AOJ.Volume1
{
    public class BaseballChampionship
    {
        private class Team
        {
            public int No { get; set; }
            public string Name { get; set; }
            public int Win { get; set; }
            public int Loose { get; set; }
        }

        public static int Main()
        {
            while (true)
            {
                int n = int.Parse(Console.ReadLine());
                if (n == 0) { break; }

                var team_list = new List<Team>();
                for(int i = 0; i < n; i++)
                {
                    var input = Console.ReadLine().Split(' ');
                    var t = new Team();
                    t.No = i;
                    t.Name = input[0];
                    for(int j = 1; j < input.Length; j++)
                    {
                        if(input[j] == "0") { t.Win++; }
                        else if(input[j] == "1") { t.Loose++; }
                    }

                    team_list.Add(t);
                }

                // ????????????????????????????°????????????\????????§????????????
                var sort = team_list.OrderByDescending(a => a.Win).ThenBy(b => b.Loose).ThenBy(c => c.No);
                foreach(var t in sort) { Console.WriteLine(t.Name); }
            }
            return 0;
        }
    }
}

Measured memory_bytes: 9600
#include <iostream>
#include <vector>
#include <deque>
#include <math.h>
#include <set>
#include <iomanip>
#include <time.h>
#include <list>
#include <stdio.h>
#include <queue>
#include <map>
#include <algorithm>
#include <assert.h>
#include <memory.h>

#define mk make_pair
#define sc second
#define fr first
#define pb emplace_back
#define all(s) s.begin(), s.end()
#define sz(s) ( (int)s.size() )

using namespace std;

const int N = 1e5 + 5;

map < int, map<int, long long> > dp, old;
map < int, long long > :: iterator it;

int n, m, ar[N];

main ()
{
    cin >> n >> m;
    for (int i = 1; i <= n; i++)
    {
        scanf("%d", &ar[i]);
        ar[i] -= m;
    }
    old[0][0] = 1;

    for (int i = 1; i <= n; i++)
    {
        for (int j = 1; j <= n; j++)
        {
            for (it = old[j - 1].begin(); it != old[j - 1].end(); it++)
            {
                dp[j][it->fr] += it->sc;
                dp[j][it->fr + ar[i]] += it->sc;
            }
        }
        old.swap(dp);
        dp.clear();
    }
    long long ans = -1;

    for (int i = 1; i <= n; i++)
        ans += old[i][0];

    cout << ans;
}


Measured memory_bytes: 384
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <vector>
#include <cstring>
#include <queue>
#include <set>
#include <map>
#include <functional>
#include <string>
#include <cmath>
#include <cassert>
#define SIZE 200005

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

char str[SIZE];

int main()
{
	scanf("%s",&str);
	int n=strlen(str);
	ll ret=0;
	int cnt=0;
	for(int i=0;i<n;i++)
	{
		if(str[i]=='A') cnt++;
		else if(str[i]=='B')
		{
			if(i+1<n&&str[i+1]=='C')
			{
				ret+=cnt;
				i++;
			}
			else cnt=0;
		}
		else cnt=0;
	}
	printf("%lld\n",ret);
	return 0;
}


Measured memory_bytes: 384
#include<stdio.h>
int main(){
	int k,p,n,c,a;
	scanf("%d",&n);
	for(c=1;c<=n;c++){
		scanf("%d %d",&k,&p);
		if(k%p==0){
			a=p;
		}
		else{
			a=k%p;
		}
		printf("%d\n",a);
	}
	return 0;
}


Measured memory_bytes: 2104
while 1:
	n=int(input())
	if n==0:
		break
	s=list(map(int,input().split()))
	cont=0
	while 1:
		tmp=[]
		for i in range(n):
			tmp.append(s.count(s[i]))
		if s==tmp:
			print(cont)
			break
		else:
			s=tmp
			cont+=1
	for i in range(n):
		if i != n-1:
			print(s[i],end=' ')
		else:
			print(s[i])

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

int i;
int main()
{
    while(cin >> i && i) {
        int a[i];
        for(int k = 0; k < i; k++) 
            cin >> a[k];

        int n = 32;
        for(int k = 0; n != 0; k++) {
            if(k % 2 == 0) n -= (n-1) % 5;
            else n -= a[(k / 2) % i];
            n = (n < 0) ? 0 : n;
            cout << n << endl;
        }
    }
}

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

int main() {
  int a,b,c,count;
  cin >> a >> b >> c;
  count = 1;
  if ( a == b ) {
    count ++;
   if ( b == c ) {
    count ++;
   }
  }
  else if ( b == c ){
    count ++;
  }
  else if ( a == c ) {
    count ++;
  }
  cout << 4 - count << endl;
  return 0;
}



Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
const int MX=100010, inf=2e9;

int n;
int A[MX];

int main(){
    ios::sync_with_stdio(0); cin.tie(0);
    cin>>n;
    for(int i=1; i<=n; i++) cin>>A[i];
    ll ans=0;
    for(int i=1; i<=n; i++){
        if(A[i]<=A[i+1]){
            int x=A[i];
            ans+=x; A[i]-=x; A[i+1]-=x;
        }
        else{
            int x=A[i+1];
            if((A[i]-x)%2==1) x=max(0, x-1);
            ans+=x; A[i]-=x; A[i+1]-=x;
            int y=A[i]/2;
            ans+=y; A[i]-=2*y;
        }
    }
        cout<<ans;
    return 0;
}

Measured memory_bytes: 640
#include <iostream>
#include<vector>

using namespace std;
void show(vector<int> a);

int main()
{
    int num;//数组数量
   cin>>num;
    vector <int>p[num];
    int opr;cin>>opr;
    while(opr--)
    {
        int oper;
        cin>>oper;
        switch(oper)
        {

            case 0:int number,mag;
            cin>>number>>mag;
            p[number].push_back(mag);
            break;
            case 1:int number1;
            cin>>number1;
            show(p[number1]);
            break;
            case 2:
                int number2;
                cin>>number2;
                if(p[number2].empty()==false)
                p[number2].clear();
                break;
        }

    }
}
void show(vector<int> a)
{
     vector<int>::iterator point;
     if(a.empty()==false)
     {
     for(point=a.begin();point!=a.end();point++)
     {
         vector<int>::iterator point1=point;
         if(++point1==a.end())
            cout<<*point<<endl;
         else
            cout<<*point<<" ";
     }
     }
     else cout<<endl;
}



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

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

const int mod = 1000000007;
struct mint {
  ll x; // typedef long long ll;
  mint(ll x=0):x((x%mod+mod)%mod){}
  mint operator-() const { return mint(-x);}
  mint& operator+=(const mint a) {
    if ((x += a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator-=(const mint a) {
    if ((x += mod-a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator*=(const mint a) { (x *= a.x) %= mod; return *this;}
  mint operator+(const mint a) const { return mint(*this) += a;}
  mint operator-(const mint a) const { return mint(*this) -= a;}
  mint operator*(const mint a) const { return mint(*this) *= a;}
  mint pow(ll t) const {
    if (!t) return 1;
    mint a = pow(t>>1);
    a *= a;
    if (t&1) a *= *this;
    return a;
  }

  // for prime mod
  mint inv() const { return pow(mod-2);}
  mint& operator/=(const mint a) { return *this *= a.inv();}
  mint operator/(const mint a) const { return mint(*this) /= a;}
};
istream& operator>>(istream& is, mint& a) { return is >> a.x;}
ostream& operator<<(ostream& os, const mint& a) { return os << a.x;}

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

  vector<int> a(n);
  rep(i,n) cin >> a.at(i);

  vector<mint> first(n);
  vector<mint> other(n);

  rep(i,n){
    for(int j=i; j<n; j++){
      if(a.at(i)>a.at(j)) first.at(i) = first.at(i)+1;
    }
  }
  rep(i,n){
    rep(j,n){
      if(a.at(i)>a.at(j)) other.at(i) = other.at(i)+1;
    }
  }

  mint ans=0;
  rep(i,n){
    mint add = first.at(i)*k + other.at(i)*k*(k-1)/2;
    ans += add;
  }

  cout << ans;  
}


Measured memory_bytes: 3592
import sys
w,h,n = map(int, sys.stdin.readline().split())

x_min = 0
x_max = w
y_min = 0
y_max = h

for i in range(n):
    x,y,a = map(int, input().split())
    if a == 1:
        x_min = max(x, x_min)
    elif a == 2:
        x_max = min(x, x_max)
    elif a == 3:
        y_min = max(y, y_min)
    else:
        y_max = min(y, y_max)

if x_min >= x_max or y_min >= y_max:
    print(0)
else:
    print((x_max - x_min) * (y_max - y_min))

Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
#define pb push_back
#define mp make_pair
#define mod 1000000007
#define pi 3.1415926535897932384626
#define LMAX 9223372036854775807
#define ll long long
#define fi first
#define sec second
#define pii pair<int, int>
int n, m, k, x, y, sum, ans, a[100005], b[100005];
int main () {
	scanf("%d %d", &n, &k);
	for (int i=1; i<=n; i++)scanf("%d", &a[i]);
	for (int i=n; i>=1; i--) b[i]=max(b[i+1], a[i]);
	vector<int>v;
	for (int i=1; i<=n; i++) {
		if (b[i+1]-a[i]>ans) {
			ans=b[i+1]-a[i];
			v.clear();
			v.push_back(i);
		} else if (b[i+1]-a[i]==ans) v.push_back(i);
	}
	printf("%d\n", v.size());
	return 0;
}

Measured memory_bytes: 1408
#include<bits/stdc++.h>
#define ll long long int
#define ul unsigned long long int
#define va vector<long long int> a 
#define vb vector<long long int> b
#define M 1000000007
using namespace std;
ll t;
void fast(){cin.tie(0);cout.tie(0);ios_base::sync_with_stdio(0);}
ll power(ll x,ul y,ll p){ll res = 1;x = x % p;if(x == 0)return 0;while (y > 0){if (y & 1)res = (res*x) % p;y = y>>1;x = (x*x) % p;}return res;}
ll solve(){
		ll a,b,c,k,sum=0;
		cin>>a>>b>>c>>k;
		if(k<=a) return k;
		else sum+=a;
		if(k<=a+b) return a;
		else sum-=k-(a+b);
		return sum; 

 }
int main(){
	fast();
	cout<<solve()<<"\n";
	return 0;
}



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

int main() {  
  int N;
  cin >> N;
  vector<string> A(N);
  for (int i = 0; i < N; i++) {
    cin>>A.at(i);
  }
  int M;
  cin>>M;
  vector<string> B(M);
  for (int i = 0; i < M; i++) {
    cin>>B.at(i);
  }  
  int ans=0;
    
  for (int i = 0; i < N; i++) {
    int b=0;
    for (int j = 0; j < N; j++) {
    if(A.at(i)==A.at(j)){
      b++;
    }
    }
    for (int j = 0; j < M; j++) {
    if(A.at(i)==B.at(j)){
      b--;
    }
    }
     ans=max(ans,b);
  }    
  cout<<ans<<endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
// iostream is too mainstream
#include <cstdio>
// bitch please
#include <iostream>
#include <algorithm>
#include <cstdlib>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <list>
#include <cmath>
#include <iomanip>
#include <time.h>
#define dibs reserve
#define OVER9000 1234567890
#define ALL_THE(CAKE,LIE) for(auto LIE =CAKE.begin(); LIE != CAKE.end(); LIE++)
#define tisic 47
#define soclose 1e-8
#define chocolate win
// so much chocolate
#define patkan 9
#define ff first
#define ss second
#define abs(x) ((x < 0)?-(x):x)
#define uint unsigned int
#define dbl long double
#define pi 3.14159265358979323846
using namespace std;
// mylittledoge

typedef long long cat;

#ifdef DONLINE_JUDGE
	// palindromic tree is better than splay tree!
	#define lld I64d
#endif

void DFS(int R, int par, vector< vector<int> > &G, vector<int> &cnt0, vector<int> &cnt1) {
	ALL_THE(G[R], it) if(*it != par)
		DFS(*it, R, G, cnt0, cnt1);
	// R has an antenna or antenna outside
	int a =0, cnt =0;
	ALL_THE(G[R], it) if(*it != par) {
		if(cnt1[*it] == 0) cnt++;
		a +=cnt1[*it];
	}
	if(cnt > 1) a +=cnt-1;
	cnt1[R] =min(cnt1[R], a);
	cnt0[R] =min(cnt0[R], a+1);
}

int main() {
	cin.sync_with_stdio(0);
	cin.tie(0);
	cout << fixed << setprecision(10);
	int N;
	cin >> N;
	int d3 =-1;
	vector< vector<int> > G(N);
	for(int i =0; i < N-1; i++) {
		int x,y;
		cin >> x >> y;
		G[x].push_back(y);
		G[y].push_back(x);
	}
	for(int i =0; i < N; i++) if((int)G[i].size() >= 3) d3 =i;
	if(d3 == -1) {
		cout << "1\n";
		return 0;
	}
	vector<int> cnt0(N, N+1), cnt1(N, N+1);
	DFS(d3, d3, G, cnt0, cnt1);
	cout << cnt1[d3] << "\n";
	return 0;}

// look at my code
// my code is amazing


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

const ll maxs = 1e5+5;
const ll lmaxs = 20;
ll mod = 1e9+7;
ll oo = 1e15;

#define IOS ios_base::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr);
#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define I insert
#define endl '\n'

void pre(){

}

void solve(){ 
   ll r;
    cin >> r;
    double ans = 3.14*r*2;
    cout << ans;
}

int main(){
    // #ifndef ONLINE_JUDGE
    // freopen("input00.txt","r",stdin);
    // #endif
    IOS;
    pre();
    ll T = 1;   
    //cin>>T;
    while(T--){  
        solve();
    }
    return 0;
}

Measured memory_bytes: 3744
import java.util.*;

public class Main {
    public static void main(String[] args) throws Exception {
        // Your code here!
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        
        int count = 0;
        for (int i = 1; i <= n; i++) {
            int num = sc.nextInt();
            if (num != i) {
                count++;
            }
        }
        
        if (count == 2 || count == 0) {
            System.out.println("YES");
        } else {
            System.out.println("NO");
        }
    }
}


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

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

const ll mod =  1000000007;  //出力は (ans % mod + mod) % mod  (負の剰余を正にする)
const int inf = 1e9;
const long long INF = 1LL << 60;   // INF = 1152921504606846976

int main()
{
    string s; cin >> s;
    int n = s.size();
    int l = -1, r = -1;
    if(n == 2){
        if(s[0] == s[1]){
            l = 1;
            r = 2;
        }
        cout << l << ' ' << r << endl;
    }else{
        rep(i,n-1){
            if(s[i] == s[i+1]){
                if(i == 0){
                    l = 1;
                    r = 3;
                }else{
                    l = i;
                    r = i+2;
                }
            }
        }
        for(int i = 1; i < n-1; i++){
            if(s[i-1] == s[i+1]){
                l = i;
                r = i+2;
            }
        }
        cout << l << ' ' << r << endl;
    }
}

Measured memory_bytes: 512
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<map>
#include<set>
#include<cstdio>
#include<cmath>
#include<numeric>
#include<queue>
#include<stack>
#include<cstring>
#include<limits>
#include<functional>
#include<unordered_set>
#include<iomanip>
#include<cassert>
#define rep(i,a) for(int i=(int)0;i<(int)a;++i)
#define pb push_back
#define eb emplace_back
using ll=long long;
constexpr ll mod = 1e9 + 7;
constexpr ll INF = 1LL << 50;
 
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;
}
using namespace std;


void solve(){
    int n;
    string s;
    cin>>n>>s;
    if(n%2==1){
        cout<<"No\n";
        return;
    }
    string t=s.substr(0,n/2);
    string r=s.substr(n/2,n/2);
    if(t==r)cout<<"Yes\n";
    else cout<<"No\n";
}
 
signed main(){
	ios::sync_with_stdio(false);
    cin.tie(0);
	//cout<<fixed<<setprecision(15);
	solve();
	return 0;
}




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

int main() {
  int n;
  string s;

  cin >> n >> s;

  int ans = -1, x = 0;

  for (int i = 0; i < (int)s.size(); i++) {
    if (s.at(i) == 'I')
      x++;
    else
      x--;
    ans = max(ans, max(x, 0));
  }

  cout << ans;

  return 0;
}

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

#define all(v) v.begin(), v.end()
#define rep(i, n) for (int i = 0; i < n; i++)
typedef long long ll;

int main() {
    int n; cin >> n;
    vector<ll> h(n);
    for(int i = 0; i < n; i++){
        cin >> h[i];
    }
    vector<ll> dp(n);
    for(int i = 0; i < n; i++){
        dp[i] = 1LL << 60;
    }
    dp[0] = 0;
    for(int i = 0; i < n; i++){
        if(i + 1 < n){
            ll cost = abs(h[i] - h[i + 1]);
            dp[i + 1] = min(dp[i + 1], dp[i] + cost);
        }
        if(i + 2 < n){
            ll cost = abs(h[i] - h[i + 2]);
            dp[i + 2] = min(dp[i + 2], dp[i] + cost);
        }
    }
    cout << dp[n - 1] << endl;
}


Measured memory_bytes: 1792
#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <vector>
#include <cmath>
#include <map>
#include <queue>
#include <set>
using namespace std;

#define N 100010
#define M 500010

typedef long long ll;
const int INF = 1 << 30;
const int Mod = 1000000007;

ll Work(ll a, ll b, ll c)
{
	//cout << a << " " << b << " " << c << endl;
	ll Max = max(max(a, b), c);
	ll Min = min(min(a, b), c);
	return Max - Min;
}

int main()
{
	//freopen("in.in", "r", stdin);
	//freopen("out.out", "w", stdout);
	
	int n, m; ll res = 1ll << 60;
	cin >> n >> m;
	
	for (int i = 1; i < n; ++i)
	{
		ll a = 1ll * i * m, b, c;
		if ((n - i) % 2 == 0 || m % 2 == 0) b = c = 1ll * (n - i) * m / 2, res = min(res, Work(a, b, c));
		else
		{
			if (m > 1) 
			{
				b = 1ll * m / 2 * (n - i);
				c = 1ll * (m - m / 2) * (n - i);
				res = min(res, Work(a, b, c));
			}
			if (n - i > 1)
			{
				int t = n - i;
				b = 1ll * t / 2 * m;
				c = 1ll * (t - t / 2) * m;
				res = min(res, Work(a, b, c));
			}
		}
	}
	swap(n, m);

	for (int i = 1; i < n; ++i)
	{
		ll a = 1ll * i * m, b, c;
		if ((n - i) % 2 == 0 || m % 2 == 0) b = c = 1ll * (n - i) * m / 2, res = min(res, Work(a, b, c));
		else
		{
			if (m > 1) 
			{
				b = 1ll * m / 2 * (n - i);
				c = 1ll * (m - m / 2) * (n - i);
				res = min(res, Work(a, b, c));
			}
			if (n - i > 1)
			{
				int t = n - i;
				b = 1ll * t / 2 * m;
				c = 1ll * (t - t / 2) * m;
				res = min(res, Work(a, b, c));
			}
		}
	}
	cout << res << endl;
	
	return 0; 
}

Measured memory_bytes: 256
import copy


def is_vaild(board, i, j):
    if "Q" in board[i]:
        return False

    for k in range(8):
        if board[k][j] == "Q":
            return False

    # fill cross(left-up)
    m, n = i - 1, j - 1
    while m >= 0 and n > 0:
        if board[m][n] == "Q":
            return False
        m -= 1
        n -= 1

    # fill cross(left-down)
    m, n = i + 1, j - 1
    while m < 8 and n >= 0:
        if board[m][n] == "Q":
            return False
        m += 1
        n -= 1

    # fill cross(right-down)
    m, n = i + 1, j + 1
    while m < 8 and n < 8:
        if board[m][n] == "Q":
            return False
        m += 1
        n += 1

    # fill cross(right-up)
    m, n = i - 1, j + 1
    while m >= 0 and n < 8:
        if board[m][n] == "Q":
            return False
        m -= 1
        n += 1

    return True


def fill_board(board, i, j):
    if not is_vaild(board, i, j):
        return

    # fill row
    for k in range(8):
        board[i][k] = "."

    # fill column
    for k in range(8):
        board[k][j] = "."

    # fill cross(left-up)
    m, n = i - 1, j - 1
    while m >= 0 and n >= 0:
        board[m][n] = "."
        m -= 1
        n -= 1

    # fill cross(left-down)
    m, n = i + 1, j - 1
    while m < 8 and n >= 0:
        board[m][n] = "."
        m += 1
        n -= 1

    # fill cross(right-down)
    m, n = i + 1, j + 1
    while m < 8 and n < 8:
        board[m][n] = "."
        m += 1
        n += 1

    # fill cross(right-up)
    m, n = i - 1, j + 1
    while m >= 0 and n < 8:
        board[m][n] = "."
        m -= 1
        n += 1

    board[i][j] = "Q"
    return


def helper(board, rem):
    if rem == 0:
        for line in board:
            print("".join(line))
        quit()

    for i in range(8):
        for j in range(8):
            if board[i][j] == "#" and is_vaild(board, i, j):
                _prev = copy.deepcopy(board)
                fill_board(board, i, j)
                helper(board, rem - 1)
                board = _prev  # BackTracking
    return


board = [["#"] * 8 for _ in range(8)]

K = int(input())
flag = False
for _ in range(K):
    i, j = [int(i) for i in input().split()]
    if board[i][j] == "#" and is_vaild(board, i, j):
        fill_board(board, i, j)


helper(board, 8 - K)



Measured memory_bytes: 6360
#include <iostream>

using namespace std;

int main()
{

    int n;  cin >> n;
    int numOdd = 0;
    int* arr = new int[n];
    for (int i = 0; i < n; i++){
        cin >> arr[i];
        if (arr[i] % 2 != 0 && i % 2 == 0){
            numOdd++;
        }
    }

    cout << numOdd << endl;

    return 0;
}


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

bool judgePrimeNumber( int a )
{
    for( int i = 2; i <= sqrt(a); i++ )
        if( a % i == 0 )
            return false;
    return true;
}

int main()
{
    int n, a[10001];
    vector<int> p;

    for( int i = 2; i < 10000; i++ )
        if( judgePrimeNumber(i) )
            p.push_back(i);

    for( int i = 0; i < 10001; i++ )
        a[i] = 0;

    int pluscnt = 1;
    while( pluscnt <= p.size() )
    {
        for( int i = 0; i < p.size(); i++ )
        {
            int sum = 0;
            for( int j = i; j < p.size() && j < pluscnt + i; j++ )
                sum += p[j];
            if( sum <= 10000 )
                a[sum]++;
        }
        pluscnt++;
    }

    while( cin >> n )
    {
        if( n == 0 )
            break;
        cout << a[n] << endl;
    }
    return 0;
}



Measured memory_bytes: 3192
#include<cstdio>
#include<queue>
using namespace std;
int f[200050],a[200050],n;
bool inq[200050];
inline int lst(int x){return x-1==0?n:x-1;}
inline int nxt(int x){return x+1>n?1:x+1;}
struct node{
	int p;
	node(){}
	node(int p):p(p){}
	inline bool operator <(const node &b)const{return a[p]<a[b.p];}
};
priority_queue<node> Q;
inline bool check(int i){return a[i]>f[i]&&a[i]-f[i]>=a[lst(i)]+a[nxt(i)];}
int main(){
	int i,t1,t2;
	long long ans=0ll;
	scanf("%d",&n);
	for(i=1;i<=n;++i)scanf("%d",f+i);
	for(i=1;i<=n;++i){
		scanf("%d",a+i);
		if(a[i]<f[i]){
			puts("-1");
			return 0;
		}
	}
	for(i=1;i<=n;++i)if(check(i))Q.push(node(i)),inq[i]=1;
	while(!Q.empty()){
		i=Q.top().p;Q.pop();inq[i]=0;
		t1=a[i]-f[i];
		t2=a[lst(i)]+a[nxt(i)];
		ans+=t1/t2;
		a[i]=f[i]+t1%t2;
		if(!inq[lst(i)]&&check(lst(i)))Q.push(lst(i)),inq[lst(i)]=1;
		if(!inq[nxt(i)]&&check(nxt(i)))Q.push(nxt(i)),inq[nxt(i)]=1;
	}
	for(i=1;i<=n;++i)if(f[i]!=a[i]){
		puts("-1");
		return 0;
	}
	printf("%lld\n",ans);
	return 0;
}

Measured memory_bytes: 2684
//in the name of god
#include <bits/stdc++.h>
using namespace std;
#define MAX_N (int)2e5+20
#define INF 2e9+20
#define pb push_back
#define F first
#define S second
typedef long long LL;
#define int LL
typedef pair<int,int> pii;
const int delta=(int)1e9+7;
int a,b; string s;
main(){
	ios_base::sync_with_stdio(false); cin.tie(0);
        cin>>a>>b>>s;
        for(int i=0;i<s.size();++i){
              if((i!=a && (s[i]<'0' || s[i] >'9')) || (i==a && s[i]!='-'))	return cout<<"No\n",0;
        }
	cout<<"Yes";
	return cout<<endl,0;
}

Measured memory_bytes: 256
import itertools
import numpy as np
N,M,X=map(int,input().split())
CA=[]
for i in range(N):
  CA.append(list(map(int,input().split())))
money=9000000000
count=1
for i in range(1,N+1):
  test=itertools.combinations(CA,i)
  for j in test:#組み合わせごとに計算
    pre_ans=np.sum(j, axis=0)
    if pre_ans[0]<money and np.all(pre_ans[1:]>=X):
      money=pre_ans[0]
      count=0
if count==0:
  print(money)
else:
  print(-1)


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

struct Node {int p, l, r;};

struct Node T[MAX];
int n;

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

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

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

int main(){
  int i, v, l, r, root;

  scanf("%d", &n);

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

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

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

  printf("Preorder\n");
  preParse(root);
  printf("\n");
  printf("Inorder\n");
  inParse(root);
  printf("\n");
  printf("Postorder\n");
  postParse(root);
  printf("\n");

  return 0;
}



Measured memory_bytes: 2104
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for(int i = 0, i##_len = (n); i < i##_len; i++)
#define reps(i, s, n) for(int i = (s), i##_len = (n); i < i##_len; i++)
#define rrep(i, n) for(int i = (n) - 1; i >= 0; i--)
#define rreps(i, e, n) for(int i = (n) - 1; i >= (e); i--)
#define all(x) (x).begin(), (x).end()
#define sz(x) ((int)(x).size())
#define uniq(x) (x).erase(unique((x).begin(), (x).end()), (x).end())

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    
    ll n, a , b;
    cin >> n >> a >> b;
    vector<ll> x(n);
    rep(i, n) cin >> x[i];
    ll spos = x[0], cpos = x[0];
    ll ans = 0;
    sort(all(x));
    
    if ((x[0] == spos) || (x[n - 1] == spos)) {
        rep(i, n) {
            int d = min(abs(x[i] - cpos) * a, b);
            cpos = x[i];
            ans += d;
        }
    }
    else if (abs(x[0] - spos) > abs(x[n - 1] - spos)) {
        rep(i, n) {
            if (spos <= x[i]) continue;
            int d = min(abs(x[i] - cpos) * a, b);
            cpos = x[i];
            ans += d;
        }
        
        rrep(i, n) {
            if (spos >= x[i]) continue;
            int d = min(abs(x[i] - cpos) * a, b);
            cpos = x[i];
            ans += d;
        }
    }
    else {
        rrep(i, n) {
            if (spos >= x[i]) continue;
            int d = min(abs(x[i] - cpos) * a, b);
            cpos = x[i];
            ans += d;
        }
        
        rep(i, n) {
            if (spos <= x[i]) continue;
            int d = min(abs(x[i] - cpos) * a, b);
            cpos = x[i];
            ans += d;
        }
    }
    
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 1024
import sys
input=sys.stdin.readline

import math
def make_divisors(n):
    D=[]
    for i in range(1, int(n**0.5)+1):
        if n%i==0:
            D.append(i)
            if i!=n//i:
                D.append(n//i)
    D.sort()
    return D

n=int(input())
A=list(sorted(map(int,input().split())))
D0=list(reversed(make_divisors(A[0])))
D1=list(reversed(make_divisors(A[1])))

ans=1
for d in D0:
    if d==1:
        continue
    cnt=0
    for a in A:
        if a%d!=0:
            cnt+=1
        if cnt>1:
            break
    if cnt<=1:
        ans=max(d,ans)
        break

for d in D1:
    if d==1:
        continue
    cnt=0
    for a in A:
        if a%d!=0:
            cnt+=1
        if cnt>1:
            break
    if cnt<=1:
        ans=max(d,ans)
        break

print(ans)

Measured memory_bytes: 59632
let content = '';
process.stdin.resume();
process.stdin.setEncoding('utf8');
process.stdin.on('data', buf => { content += buf; });
process.stdin.on('end', () => {
    const [w, h] = content.split(' ').map(n => parseInt(n, 10));
    console.log(w * h, w * 2 + h * 2);
});


Measured memory_bytes: 15328
#include <bits/stdc++.h>
using namespace std;
#define scanf___Am_I_a_joke_to_you  ios_base :: sync_with_stdio(false);
#define ll                          long long
#define MAXN                        200007

int h, w, dis[27][27], visited[27][27];
char ch[27][27];

#define BOUNDARY                    (x >= 0 && x < h && y >= 0 && y < w)
int dx[] = {-1, 1, 0, 0};
int dy[] = {0, 0, -1, 1};

int bfs(int Startx, int Starty)
{
    int Max = 0;

    memset(dis, MAXN, sizeof(dis));
    memset(visited, 0, sizeof(visited));

    dis[Startx][Starty] = 0;

    queue <pair <int, int> > q;
    q.push({Startx, Starty});

    while (!q.empty())
    {
        pair <int, int> t = q.front();
        q.pop();

        for (int i = 0; i<4; i++)
        {
            int x = t.first + dx[i];
            int y = t.second + dy[i];

            if (BOUNDARY && !visited[x][y] && ch[x][y] == '.')
            {
                dis[x][y] = min(dis[x][y], dis[t.first][t.second] + 1);
                visited[x][y] = 1;
                q.push({x,y});
            }
        }
    }

    for (int i = 0; i<h; i++)
    {
        for (int j = 0; j<w; j++)
        {
            if (ch[i][j] == '.')
            {
                Max = max(Max, dis[i][j]);
            }
        }
    }

    return Max;

}

int main ()
{
    scanf___Am_I_a_joke_to_you

    cin >> h >> w;

    for (int i = 0; i<h; i++)
        for (int j = 0; j<w; j++)
            cin >> ch[i][j];

    int res = 0;

    for (int i = 0; i<h; i++)
    {
        for (int j = 0; j<w; j++)
        {
            if (ch[i][j] == '.')
            {
                int ans = bfs(i, j);
                res = max(res, ans);
            }
        }
    }
    cout << res << endl;



    return 0;
}



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

int main()
{
	string S;
	int ans = 700;
	cin >> S;
	if (S.at(0) == 'o') ans += 100;
	if (S.at(1) == 'o') ans += 100;
	if (S.at(2) == 'o') ans += 100;
	cout << ans << endl;
}


Measured memory_bytes: 3576
from statistics import mode

N = int(input())
A = list(map(int, input().split()))
MOD = 10 ** 9 + 7

# 2回表れている値とそのインデックスを取得
C = mode(A)
C_indexes = [i for i, x in enumerate(A) if x == C]

# 二つのCの外側にそれぞれ何個ずつあるか
outside = C_indexes[0] + len(A) - C_indexes[1] - 1

# 階乗・逆元の値を保存
factorial = [1]
inverse = [1]
for i in range(1, N+2):
    factorial.append(factorial[-1]*i % MOD)
    inverse.append((pow(factorial[i], MOD-2, MOD)))

# combination計算
def nCr(n, r):
    if n<r or n==0 or r==0:
        return 0
    return factorial[n] * inverse[r] * inverse[n-r] % MOD


print(N)
for i in range(2, N+2):
    print(int(nCr(N+1, i) - nCr(outside, i-1)) % MOD)

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

int main() {
	long long q, h, s, d, n;
	cin >> q >> h >> s >> d >> n;

	long long one = min(s, 2 * min(q * 2, h));
	long long ans = 0;
	if (n % 2 == 0) {
		ans = min(n / 2 * d, n * one);
	}
	else {
		ans = min((n-1) / 2 * d+one, n * one);
	}
	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <algorithm>
#include <iterator>
#include <map>
#include <utility>

using namespace std;

bool check(string &s) {
  if (s.find("AGC") != string::npos) {
    return false;
  }

  for (int i = 1; i < s.size(); ++i) {
    swap(s[i], s[i - 1]);
    if (s.find("AGC") != string::npos) {
      return false;
    }
    swap(s[i], s[i - 1]);
  }

  return true;
}

const int md = 1e9 + 7;

int solve(string s, int n, map<pair<string, int>, int> &memo) {
  auto memo_key = make_pair(s, n);
  if (memo.count(memo_key) > 0) {
    return memo[memo_key];
  }

  if (!check(s)) {
    return 0;
  }

  if (n == 0) {
    return 1;
  }

  vector<char> next_chs{'A', 'C', 'G', 'T'};
  int ans = 0;
  for (auto next_ch : next_chs) {
    string s2;
    if (s.size() > 3) {
      copy(s.begin() + s.size() - 3, s.end(), back_inserter(s2));
    } else {
      copy(s.begin(), s.end(), back_inserter(s2));
    }

    s2 += next_ch;
    ans = (ans + solve(s2, n - 1, memo)) % md;
  }

  return memo[memo_key] = ans % md;
}

int main(int argc, const char *argv[]) {
  int n;
  cin >> n;

  map<pair<string, int>, int> memo;
  int ans = solve("", n, memo);
  cout << ans << '\n';

  return 0;
}

Measured memory_bytes: 2688
#include <iostream>
#include<bits/stdc++.h>
using namespace std;
int m1[10010][10010];
//int m2[1001][1001];
int main()
{
    queue<pair<int,int>> q;

    int k=0;
    int h, w;
    cin>>h>>w;
    for(int i = 1; i<= h;i++)
        for(int j  = 1; j<=w;j++)
        {
            char c;
            cin>>c;
            m1[i][j] = (c == '#' ? 1 : 0);
            if(m1[i][j])
            {
                q.push(make_pair(i,j));
            }
        }

    while(q.size()!=0)
    {
        int i = q.front().first;
        int j = q.front().second;
        bool found   = false;
        if(!m1[i-1][j])
        {

            m1[i-1][j] =m1[i][j]+1;
            if(i-1>=1 && i-1<=h&& j>=1 && j<=w)
            {q.push(make_pair(i-1,j)); k = max(m1[i-1][j], k);}
        }
        if(!m1[i+1][j])
        {

            m1[i+1][j] =m1[i][j]+1;
            if(i+1>=1 && i+1<=h&& j>=1 && j<=w)
            {q.push(make_pair(i+1,j));k = max(m1[i+1][j], k);}
        }
        if(!m1[i][j-1])
        {

            m1[i][j-1] =m1[i][j]+1;
            if(i>=1 && i<=h&& j-1>=1 && j-1<=w)
            {q.push(make_pair(i,j-1));k = max(m1[i][j-1], k);}
        }
        if(!m1[i][j+1])
        {

            m1[i][j+1] =m1[i][j]+1;
            if(i>=1 && i<=h&& j+1>=1 && j+1<=w)
            {q.push(make_pair(i,j+1));k = max(m1[i][j+1], k);}
        }
        if(found)
        {
            //k++;
        }
        q.pop();
    }
    if(k ==0)
    {
        cout<<0;
        return 0;
    }
    cout<<k-1;
    return 0;
}


Measured memory_bytes: 47760
a,b,c,k = map(int, raw_input().split())
t = [a,b,c]
s = 0
h = {0:1, 1:0, 2:-1}
for i,e in enumerate(t): 
	s += min(k, e) * h[i]
	k-= min(e,k)
print s

Measured memory_bytes: 85036
/*
	submission # - User: herp_sy
	https://atcoder.jp/contests/
*/

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
#include <stdbool.h>

#define _CRT_SECURE_NO_WARNINGS
#define TLong long long
#define TBMod 1000000007

// fact(n)
int fact(int n){
	if(n == 1)	return 1;
	else return (n * fact(n - 1));
}

// nCr(n,r)
int nCr(int n, int r){
	if(r == 0 || r == n)	return 1;
	else if(r == 1)	return n;
	return (nCr(n - 1, r - 1) + nCr(n - 1, r));
}

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

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

// swap(&a, &b);
void swap(int *a,int *b){
	int tmp;
	tmp = *a;	*a = *b;	*b = tmp;
	return;
}

// qsort(array, size, sizeof(int),comp);
int ASC(const int *a,const int *b){
	return (*a - *b);
}

int DESC(const int *a,const int *b){
	return (*b - *a);
}

// append(array,*size,addNum)
void append(int *array,int *size,int num){
	realloc(array, sizeof(int) * (*size + 1));
	array[(*size)] = num;
	++(*size);
}

// pop(array,*size) & nongetpop(array,*size)
int pop(int *array,int *size){
	int temp = array[(*size - 1)];
	nongetpop(array,&(*size));
	return temp;
}

int nongetpop(int *array,int *size){
	realloc(array,sizeof(int) * (*size - 1));
	--(*size);
}

int main(int argc, char const *argv[])
{
	int n,a,b;
	scanf("%d%d%d",&n,&a,&b);
	if(n * a < b)	printf("%d\n",n * a);
	else printf("%d\n", b);
	return 0;
}


Measured memory_bytes: 128
#include<bits/stdc++.h>
using namespace std;
#define int long long
using P = pair<int,int>;
int N,M,S,T;
struct edge{int to,idx;};//行先とindex
vector<edge> G[101000];//グラフ,二次元配列っぽくあつかってる？
vector<int> A(101000),B(101000);//円とすぬけ

vector<int> dijkstra(int s,vector<int>& cost){
    vector<int> dist(101000,1e18); dist[s] = 0;//距離を無限に
    priority_queue<P,vector<P>,greater<P>> Q;
    Q.push({0,s});

    while(!Q.empty()){
        P p = Q.top(); Q.pop();
        if(dist[p.second] < p.first) continue;
        for(auto & e : G[p.second]){
            if(dist[e.to] > dist[p.second] + cost[e.idx]){
                dist[e.to] = dist[p.second] + cost[e.idx];
                Q.push({dist[e.to],e.to});
            }
        }
    }
    return dist;
}
signed main(){
    cin>>N>>M>>S>>T;
    for(int i=0;i<M;++i){
        int u,v;
        cin>>u>>v>>A[i]>>B[i];
        G[u].push_back({v,i});//駅uからつながるvと年i
        G[v].push_back({u,i});//駅vからつながる
    }

    auto yen = dijkstra(S,A);
    auto snuke = dijkstra(T,B);

    int ans = 0;
    vector<int> res;
    int base = 1e15;
    for(int i=N;i>0;--i){
        ans = max(ans,base - yen[i] - snuke[i]);
        res.push_back(ans);
    }

    reverse(res.begin(),res.end());

    for(auto x :res) cout<<x<<endl;

}


Measured memory_bytes: 14204
// 2010/12/28 Tazoe

#include <iostream>
using namespace std;

unsigned long long gcd(unsigned long long m, unsigned long long n)
{
	if(n>m){
		unsigned long long tmp = m;
		m = n;
		n = tmp;
	}

	if(n==0)
		return m;

	while(true){
		if(m%n==0)
			return n;

		unsigned long long tmp = m%n;
		m = n;
		n = tmp;
	}
}

unsigned long long lcm(unsigned long long m, unsigned long long n)
{
	return m/gcd(m, n)*n;
}

int main()
{
	while(true){
		int n;
		cin >> n;
		if(n==0)
			break;

		unsigned long long d[10], v[10];
		for(int i=0; i<n; i++){
			cin >> d[i] >> v[i];
			unsigned long long g = gcd(d[i], v[i]);
			d[i] /= g;
			v[i] /= g;
		}

		unsigned long long D = lcm(d[0], d[1]);
		for(int i=2; i<n; i++)
			D = lcm(D, d[i]);

		for(int i=0; i<n; i++)
			v[i] = D/d[i]*v[i];

		unsigned long long V = gcd(v[0], v[1]);
		for(int i=2; i<n; i++)
			V = gcd(V, v[i]);

		for(int i=0; i<n; i++)
			cout << v[i]/V << endl;
	}

	return 0;
}

Measured memory_bytes: 0
#include<bits/stdc++.h>
#define ll long long
#define N 105
using namespace std;
inline int read(){
  int x = 0, f = 0;char ch = getchar();
  for (; ch <'0' || ch>'9'; ch = getchar()) if (ch == '-') f = 1;
  for (; ch >= '0'&& ch<='9'; ch = getchar()) x = (x<<1) + (x<<3) + ch - 48;
  return f ?-x :x;
}
int A, B, C, X, Y, ans, sum;
int main() {
	A = read();
	B = read();
	C = read();
	X = read();
	Y = read();
	ans = A*X+B*Y;
	while (1) {
		if (X <= 0 && Y <= 0) break;
		X--; Y--;
		int sum = ans;
		if (X >= 0) sum -= A;
		if (Y >= 0) sum -= B;
		sum += C*2;
		if (sum > ans) {
			break;
		} else ans = sum;
	}
	printf("%d\n", ans);
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <stdio.h>
 
using namespace std;
 
#define int long long
#define rep(i, a, b) for (int i = (a); i < (b); ++i)
#define trav(i, a) for (auto &i: (a))
#define sz(x) (int)(x).size()
#define all(v) (v).begin(), (v).end()
#define fr(i, a, b) for (int i = (a); i <= (b); ++i)

void solve();

signed main () {
    clock_t beg = clock();
    cout << fixed << setprecision(15);
    ios_base::sync_with_stdio(false);
    cin.tie(0); cout.tie(0);
    #ifdef LOCAL
    freopen("input.txt", "r", stdin);
    #endif 
    int t = 1; 
    // cin >> t;    
    int tt = t;
    while (t--) {
        // cout << "Case #" << tt - t << ": "; 
        solve();
    }
    cerr << "\nExecution time: " << (clock() - beg) / 1000 << '\n';
    return 0;
}
int a, b, c, k;
void solve() {  
    cin >> a >> b >> c >> k;
    if (k <= a + b) {
        cout << min(k, a);
    }
    else {
        cout << a - (k - (a + b));
    }
}       
    

Measured memory_bytes: 3628
#include <bits/stdc++.h>
#include <boost/range/adaptors.hpp>
#include <boost/range/irange.hpp>

using namespace std;
using namespace boost;
using namespace boost::adaptors;

int main() {
    int64_t n, a, b;
    cin >> n >> a >> b;

    cout << n / (a + b) * a + min(n % (a + b), a) << endl;
}

Measured memory_bytes: 256
A, B, K = list(map(int, input().split()))
if K >= (B - A + 1) / 2 :
    for n in range(A, B+1):
        print(n)
else:
    for n in range(A, A + K):
        print(n)
    for n in range(B - K + 1, B + 1):
        print(n)

Measured memory_bytes: 3060
import java.util.*;

public class Main {
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		// 入力値を変数に代入
		double price_tax = sc.nextInt();
        double tax_rate = 1.08;
        double price = price_tax/tax_rate;
        double price_ceil = Math.ceil(price);
      	double price_tax_floor = Math.floor(price_ceil*tax_rate);
      	int out;
      	if(price_tax == price_tax_floor){
          	out = (int)price_ceil;
         	System.out.println(out);
        }
      	else{
         	System.out.println(":("); 
        }
	}
}

Measured memory_bytes: 21844
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int N, K;
  cin >> N >> K;
  int ans = 1;
  
  for (int i = 0; i < N; i++)
    if (ans < K) {
      ans *= 2;
    }
    else {
      ans += K;
    }
  cout << ans << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long int lld;
typedef pair<int,int> pi;
typedef pair<lld,lld> pl;
#define x first
#define y second
#define all(v) v.begin(), v.end()
#define sz(x) (int)x.size()
#define mk(a,b) make_pair(a,b)
bool isrange(int y,int x,int n,int m){
	 if(0<=y&&y<n&&0<=x&&x<m) return true;
	 return false;
}
int dy[4] = {1,0,-1,0},dx[4]={0,1,0,-1},ddy[8] = {1,0,-1,0,1,1,-1,-1},ddx[8] = {0,1,0,-1,1,-1,1,-1};
int arr[222222],dp[222222];
int main(void){
	int n,k;
	scanf("%d%d",&n,&k);
	for(int e=0;e<n;e++) scanf("%d",&arr[e]);
	for(int e=0;e<k;e++){
		int err = 0;
		for(int e=0;e<n;e++) dp[e] = 0;
		for(int e=0;e<n;e++){
			dp[max(0,e-arr[e])]++;
			dp[min(n,e+arr[e]+1)]--;
		}
		for(int e=1;e<n;e++){
			dp[e] += dp[e-1];
			if(dp[e]!=arr[e]) err = 1;
		}
		if(err==0) break;
		for(int e=0;e<n;e++) arr[e] = dp[e]; 
	}
	for(int e=0;e<n;e++) printf("%d ",arr[e]);
	return 0;
}


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

int main(){
  int H,W ;
  cin >> H >> W;

  vector<vector<char>> vec(H, vector<char>(W));
  for (int i = 0; i < H; i++) {
    for (int j = 0; j < W; j++) {
        cin >> vec.at(i).at(j);
    }
  }

  vector<vector<int>> count(H, vector<int>(W));
  for (int i = 0; i < H; i++) {
    for (int j = 0; j < W; j++) {
        if(vec.at(i).at(j)=='#'){
          if (i-1>=0 && j-1>=0 ) count.at(i-1).at(j-1)+=1;
          if (i-1>=0 ) count.at(i-1).at(j)+=1;
          if (i-1>=0 && j+1<W ) count.at(i-1).at(j+1)+=1;
          if (j+1<W ) count.at(i).at(j+1)+=1;
          if (j-1>=0 ) count.at(i).at(j-1)+=1;
          if (i+1<H && j-1>=0 ) count.at(i+1).at(j-1)+=1;
          if (i+1<H ) count.at(i+1).at(j)+=1;
          if (i+1<H && j+1<W ) count.at(i+1).at(j+1)+=1;
        }
    }
  }

  for (int i = 0; i < H; i++) {
    for (int j = 0; j < W; j++) {
        if(vec.at(i).at(j)!='#'){
          cout << count.at(i).at(j);
        }
        else{
          cout << "#" ;
        }
        if (j==W-1){
          cout << endl;
        }
    }
  }
}

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

#define MAX_M 20
#define MAX_N 50000

int c[MAX_M];

int dp[MAX_N + 1];

int main()
{
	int n, m;

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

	for( int i = 0; i < n + 1; i++ ) {
		dp[i] = (1 << 30);
	}
	dp[0] = 0;
	for( int i = 0; i < m; i++ ) {
		int cc = c[i];
		for( int j = 0; j + cc <= n; j++ ) {
			dp[j + cc] = min( dp[j + cc], dp[j] + 1 );
		}
	}
	int ans = dp[n];

	cout << ans << endl;

	return 0;
}



Measured memory_bytes: 3304
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
typedef pair<int,P> P1;
typedef pair<P,P> P2;
#define pu push
#define pb push_back
#define mp make_pair
#define eps 1e-7
#define INF 1000000000
#define mod 1000000007
#define fi first
#define sc second
#define rep(i,x) for(int i=0;i<x;i++)
#define repn(i,x) for(int i=1;i<=x;i++)
#define SORT(x) sort(x.begin(),x.end())
#define ERASE(x) x.erase(unique(x.begin(),x.end()),x.end())
#define POSL(x,v) (lower_bound(x.begin(),x.end(),v)-x.begin())
#define POSU(x,v) (upper_bound(x.begin(),x.end(),v)-x.begin())
vector<pair<string,P> >vec;



int main(){	
	string L;
	cin >> L;
	long long d1[L.length()], d2[L.length()];
	d1[0] = 2;
	d2[0] = 1;

	for (long long i = 1; i < L.length(); i++) {
		if (L[i] == '1') {
			d1[i] = d1[i-1]*2%mod;
			d2[i] = (d1[i-1]+d2[i-1]*3)%mod;
		} else {
			d1[i] = d1[i-1];
			d2[i] = (d2[i-1]*3)%mod;
		}
		// cout << d1[i] << " " << d2[i] << endl; 
	}
	
	cout << (d1[L.length()-1]+d2[L.length()-1])%mod << endl;
	return 0;
}



Measured memory_bytes: 2048
import java.util.*;
public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		String s;
		while(sc.hasNext()) {
			s = sc.nextLine();
			int n_ioi, n_joi;
			n_ioi = n_joi = 0;
			
			int f = 0;
			while(s.indexOf("JOI", f) != -1) {
				f = s.indexOf("JOI", f);
				f++; n_joi++;
			}

			f = 0;
			while(s.indexOf("IOI", f) != -1) {
				f = s.indexOf("IOI", f);
				f++; n_ioi++;
			}
			
			System.out.println(n_joi);
			System.out.println(n_ioi);
		}
	}
}

Measured memory_bytes: 27244