akhauriyash/Code-Regression huggingface dataset:
#include <array>
#include <iostream>
using namespace std;

array<array<int, 210>, 210> costs;
array<array<int, 210>, 210> times;

int main() {
    int n, m;
    while (cin >> n >> m, n || m) {
        for (auto& ar : costs) ar.fill(1000000);
        for (auto& ar : times) ar.fill(1000000);
        for (int i = 0; i < n; i++) {
            int a, b, c, t;
            cin >> a >> b >> c >> t;
            a--; b--;
            costs[a][b] = costs[b][a] = c;
            times[a][b] = times[b][a] = t;
        }
        for (int i = 0; i < m; i++) {
            costs[i][i] = 0;
            times[i][i] = 0;
        }

        for (int i = 0; i < m; i++) {
            for (int j = 0; j < m; j++) {
                for (int k = 0; k < m; k++) {
                    costs[j][k] = min(costs[j][k], costs[j][i] + costs[i][k]);
                    times[j][k] = min(times[j][k], times[j][i] + times[i][k]);
                }
            }
        }
        int k;
        cin >> k;
        for (int i = 0; i < k; i++) {
            int p, q, r;
            cin >> p >> q >> r;
            p--; q--;
            if (r == 0) {
                cout << costs[p][q] << endl;
            }
            else {
                cout << times[p][q] << endl;
            }
        }
    }
    return 0;
}

Measured memory_bytes: 1504
#include<bits/stdc++.h>
#define ll long long
#define fr(i,x,y) for(int i=(x);i<=(y);i++)
#define rf(i,x,y) for(int i=(x);i>=(y);i--)
#define frl(i,x,y) for(int i=(x);i<(y);i++)
using namespace std;
const int N=200002;
int n,K,a[N];
int h[N],t,w;
int mn[N],mx[N];

void read(int &x){
	char ch=getchar();x=0;
	for(;ch<'0'||ch>'9';ch=getchar());
	for(;ch>='0'&&ch<='9';ch=getchar()) x=(x<<3)+(x<<1)+ch-'0';
}

void push(int x,bool (*cmp)(int,int)){
	while(w>=t&&cmp(a[h[w]],a[x])) w--;
	h[++w]=x;
}

int find(int x){
	while(h[t]<=x-K) t++;
	return a[h[t]];
}

bool big(int x,int y){ return x>y; }
bool small(int x,int y){ return x<y; }

void init(){
	t=1;w=0;
	fr(i,1,n){
		push(i,big);
		mn[i]=find(i);
	}
	t=1;w=0;
	fr(i,1,n){
		push(i,small);
		mx[i]=find(i);
	}
}

int main(){
	read(n);read(K);
	fr(i,1,n) read(a[i]);
	init();
	int flag=0;
	fr(i,2,K) if (a[i-1]>a[i]) flag++;
	int bo=0,ans=0;
	fr(i,K,n){
		if (flag==0) bo=1;
		 else{
		 	if (i==K||a[i-K]!=mn[i-1]||a[i]!=mx[i]) ans++;
		 }
		flag-=a[i-K+1]>a[i-K+2];
		flag+=a[i]>a[i+1];
	}
	cout<<ans+bo<<endl;
	return 0;
}

Measured memory_bytes: 3328
N,K = map(int,input().split())
a = list(map(int,input().split()))

ans = 10**15
for i in range(2**N):
    if bin(i).count('1')!=K:
        continue
    cost = 0
    now = 0
    for j in range(N):
        if i>>j&1:
            if now>=a[j]:
                cost += now-a[j]+1
                now += 1
            else:
                now = a[j]
        else:
            now = max(now,a[j])
    ans = min(ans,cost)
print(ans)



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

typedef pair<int, ll> p;

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

    int N;
    cin >> N;

    vector<vector<p> > x(N, vector<p>());
    vector<bool> C(N);
    vector<ll> L(N);

    for(int i = 0; i < N - 1; i++) {
        int a, b;
        ll c;
        cin >> a >> b >> c;
        a--;
        b--;
        x[a].push_back(make_pair(b, c));
        x[b].push_back(make_pair(a, c));
    }

    stack<p> s;

    int Q, K;
    cin >> Q >> K;
    K--;

    s.push(make_pair(K, 0));

    while(!s.empty()) {
        p y = s.top();
        s.pop();
        int n = y.first;
        ll l = y.second;

        C[n] = true;
        L[n] = l;

        for(int i = 0; i < x[n].size(); i++) {
            if(C[x[n][i].first]) continue;
            s.push(make_pair(x[n][i].first, l + x[n][i].second));
        }
    }

    vector<int> a(Q);
    vector<int> b(Q);

    for(int i = 0; i < Q; i++) cin >> a[i] >> b[i];

    for(int i = 0; i < Q; i++) {
        a[i]--;
        b[i]--;
        cout << L[a[i]] + L[b[i]] << endl;
    }
}

Measured memory_bytes: 10880
import java.util.*;

public class Main {
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        int a = sc.nextInt();
        int b = sc.nextInt();
        double k = (a+b)/2d;
        if (Math.floor(k)==k)System.out.println((int)k);
        else System.out.println("IMPOSSIBLE");
    }
}


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

using namespace std;

int main() {
int n = 0;
cin >> n;
vector<int> a(n+1);
for (int i=1; i<n+1; i++) {
 cin >> a.at(i);
}
vector<int> ans(n+1);
int sum = 0;
for (int i=n; i>=1; i--) {
 int count = 0, j = 2;
 while (i*j < n+1) {
  count += ans.at(i*j);
  j++;
 }
 if (count%2 != a.at(i)) {ans.at(i) = 1; sum++;}
}
cout << sum << endl;
for (int i=1; i<n+1; i++) {
 if (ans.at(i) == 1) cout << i << " ";
}
cout << endl;
return 0;
}


Measured memory_bytes: 2560
/** Author: Dwai
 *  Omae wa mou shindeiru!
**/

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

#define mp make_pair
#define pb push_back
#define eb emplace_back
#define ff first
#define ss second
#define all(a) (a).begin(),(a).end()
#define fr(i,a,b) for (i = a; i <= b; i++)
#define frr(i,a,b) for (i = a; i >= b; i--)
#define rep(i,n) for (i = 0 ; i < n; i++)
#define repr(i,n) for (i = n - 1; i >= 0; i--)
#define fast ios_base::sync_with_stdio(false),cin.tie(0),cout.tie(0);srand(time(NULL));
#define flushinput   cin.ignore(numeric_limits<streamsize>::max(),'\n');

void debug_out() { cerr << endl; }

void clock_out(){
  cerr<<"\nTime Elapsed : " << 1.0*clock() / CLOCKS_PER_SEC << " s\n";
}

void fileio(){
  freopen("/home/dwai/Desktop/cp/input.txt","r", stdin);
  freopen("/home/dwai/Desktop/cp/output.txt", "w", stdout);
  freopen("/home/dwai/Desktop/cp/debug.txt", "w", stderr);
}

void ofileio(){
  freopen("input.txt","r", stdin);
  freopen("output.txt", "w", stdout); 
}

template <typename Head, typename... Tail>
void debug_out(Head H, Tail... T) {
  cerr << " " << H;
  debug_out(T...);
}

#ifndef ONLINE_JUDGE
#define debug(...) cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)
#define fio() fileio()
#define ofio() fileio()
#define clock() clock_out()
#else
#define debug(...) 42
#define fio() 42
#define ofio() ofileio()
#define clock() 42
#endif

typedef long long ll;
typedef unsigned long long ull;
typedef double db;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef vector<ll> vl;
typedef vector<pll> vll;
typedef map<ll,ll> mll;

int IT_MAX = 1 << 20;
const ll MOD = 1000000007;
const int INF = 0x3f3f3f3f;
const ll LL_INF = 0x3f3f3f3f3f3f3f3f;
const db PI = acos(-1);
const db ERR = 1e-10;



void solve()
{
	ll a,b,k;
	cin>>a>>b>>k;

	ll oa=a;
	a=max(0ll,a-k);
	b=max(0ll,b-(k-(oa-a)));
	cout<<a<<" "<<b;
}

int main()
{
	//fio();
	fast
	ll t=1;
	//cin>>t;

	while(t--){
		solve();
	}
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef vector<ll> vl;
typedef pair<ll, ll> PP;
#define rep(i, n) for(ll i = 0; i < ll(n); i++)
#define all(v) v.begin(), v.end()
bool chmin(ll& a, ll  b) { if (b < a) { a = b; return 1; } return 0; }
bool chmax(ll& a, ll b) { if (b > a) { a = b; return 1; } return 0; }
const ll INF = 999999999999999;
const ll MOD = 1000000007;
const ll MAX_N = 500010;
ll a, b, c, d, e, f, p, t, x, y, z, q, m, n, r, h, k, w, l, ans;
int main() {
    cin >> n;
    rep(i, n) {
        cin >> x;
        a += x;
        b += x * x;
    }
    c = a / n;
    d = c + 1;

    cout << min(n * c * c - 2 * a * c + b, n * d * d - 2 * a * d + b) << endl;
}

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

Measured memory_bytes: 128
q[1<<18],t[1<<18],f[1<<18];i,a;
main(n){
	for(scanf("%d",&n);~scanf("%d",&a);i++)q[a]=i;
	for(f[n]=n;--i;t[a]?q[f[a]]<q[i]&q[i]<q[a]|q[i]<q[a]&q[a]<q[f[a]]|q[a]<q[f[a]]&q[f[a]]<q[i]?t[i]=t[a],f[i]=f[a]:(t[i]=t[f[i]=i+1]+1):q[i]<q[a]?t[i]=0,f[i]=i:(f[i]=i+(t[i]=1)))a=i+1;
	printf("%d",t[1]);
}

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

int n, x;

int main()
{
	cin >> n;
	bool fl = true;
	for(int i=0; i<n; i++)
	{
		cin >> x;
		if(x%2==0 and (x%3!=0 and x%5!=0))
			fl = false;
	}

	puts(fl ? "APPROVED" : "DENIED");
}

Measured memory_bytes: 256
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <cstring>

#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <queue>
#include <stack>
#include <map>
#include <set>

#include <functional>
#include <cassert>

typedef long long ll;
using namespace std;

#define debug(x) cerr << #x << " = " << x << endl;


#define mod 1000000007 //1e9+7(prime number)
#define INF 1000000000 //1e9
#define LLINF 2000000000000000000LL //2e18
#define SIZE 10000

int calc(int d,int n,int *a){
  int res = 0;
  
  for(int i=0;i<n;i++){
    res += (d-a[i])*(d-a[i]);
  }

  return res;
}

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

  int ans = INF;

  for(int i=-100;i<=100;i++){
    ans = min(ans,calc(i,n,a));
  }

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


Measured memory_bytes: 256
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

class Program
{
    static void Main(string[] args)
    {
        new Program().Solve();
    }

    void Solve()
    {
        Scanner cin = new Scanner();
        int a = cin.NextInt();
        int b = cin.NextInt();
        
        if (a <= 5)
        {
            Console.WriteLine("0");
        }
        else if (6 <= a && a <= 12)
        {
            Console.WriteLine(b/2);
        }
        else
        {
            Console.WriteLine(b);
        }
    }
}


class Scanner
{
    string[] s;
    int i;

    char[] cs = new char[] { ' ' };

    public Scanner()
    {
        s = new string[0];
        i = 0;
    }

    public string Next()
    {
        if (i < s.Length) return s[i++];
        string st = Console.ReadLine();
        while (st == "") st = Console.ReadLine();
        s = st.Split(cs, StringSplitOptions.RemoveEmptyEntries);
        if (s.Length == 0) return Next();
        i = 0;
        return s[i++];
    }

    public int NextInt()
    {
        return int.Parse(Next());
    }

    public char[] ArrayChar()
    {
        return Next().ToCharArray();
    }
    public int[] ArrayInt(int N, int add = 0)
    {
        int[] Array = new int[N];
        for (int i = 0; i < N; i++)
        {
            Array[i] = NextInt() + add;
        }
        return Array;
    }

    public long NextLong()
    {
        return long.Parse(Next());
    }

    public long[] ArrayLong(int N, long add = 0)
    {
        long[] Array = new long[N];
        for (int i = 0; i < N; i++)
        {
            Array[i] = NextLong() + add;
        }
        return Array;
    }

    public double NextDouble()
    {
        return double.Parse(Next());
    }


    public double[] ArrayDouble(int N, double add = 0)
    {
        double[] Array = new double[N];
        for (int i = 0; i < N; i++)
        {
            Array[i] = NextDouble() + add;
        }
        return Array;
    }
}

Measured memory_bytes: 13140
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define pb push_back
int main()
{
    int n;
    cin>>n;
    ll a[n];
    for(int i=0;i<n;i++)
    {
        cin>>a[i];
    }
    sort(a,a+n);
    ll ans=0;
    ans+=a[n-1];
    int k=2;
    int i;
    for( i=n-2;i>0&&k+2<=n;i--)
    {
        //cout<<k<<endl;
        ans+=2*a[i];
        k+=2;
       // k++;
    }
    if(k<n) ans+=a[i];

    
    cout<<ans<<endl;

}

Measured memory_bytes: 5168
#include <bits/stdc++.h>
using namespace std;
using vi=vector<int>;
using vvi=vector<vi>;
using vs=vector<string>;
using msi=map<string,int>;
using mii=map<int,int>;
using pii=pair<int,int>;
using vlai=valarray<int>;
using ll=long long;
#define rep(i,n) for(int i=0;i<n;i++)
#define range(i,s,n) for(int i=s;i<n;i++)
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define fs first
#define sc second
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define INF 1e9
#define EPS 1e-9

int main(){
	int n,k;cin>>n>>k;
	vvi s(k*2+1,vi(k*2+1,0));

    rep(i,n){
        int x,y;char c;
        cin>>x>>y>>c;
        if(c=='B')x+=k;
        x%=2*k,y%=2*k;
        s[y+1][x+1]++;
    }
    rep(i,k*2+1){
        partial_sum(all(s[i]),s[i].begin());
    }
    rep(i,k*2)rep(j,k*2+1){
        s[i+1][j]+=s[i][j];
    }
    int ans=0;
    rep(i,k+1){
        int xl=i,xr=i+k;
        rep(j,k+1){
            int yl=j,yr=j+k,a=0;
            //cout<<xl<<","<<xr<<","<<yl<<","<<yr<<endl;
            a+=s[yl][xl];
            a+=s[yr][xr]+s[yl][xl]-s[yl][xr]-s[yr][xl];
            a+=s[k*2][k*2]+s[yr][xr]-s[k*2][xr]-s[yr][k*2];
            a+=s[k*2][xl]-s[yr][xl];
            a+=s[yl][k*2]-s[yl][xr];
            ans=max(ans,a);
            ans=max(ans,n-a);
        }
    }
    cout<<ans<<endl;
	return 0;
}


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

int dp[100010];

int f(int n){
  if(n == 0){
    dp[0] = 0;
    return 0;
  }
  if(dp[n] != -1){
    return dp[n];
  }

  int res = f(n-1) + 1;
  int x = 6;
  while(x <= n){
    res = min(res, f(n-x) + 1);
    x *= 6;
  }
  x = 9;
  while(x <= n){
    res = min(res, f(n-x) + 1);
    x *= 9;
  }
  return dp[n] = res;
}

int main(){
  int N;
  cin >> N;
  for(int i = 0; i <= N; ++i){
    dp[i] = -1;
  }
  cout << f(N) << endl;
}


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

static const int c = 1000000007;

long long power(long long m, long long n) {
	if (n == 0) return 1;
	return n % 2 == 0 ? power(m * m % c, n / 2) % c : m * power(m * m % c, n / 2) % c; //????????????????????°
}

int main() {
	int m, n; //?????£??????int??§??§??????
	cin >> m >> n;
	cout << power(m, n) << endl;

	return 0;
}

Measured memory_bytes: 1160
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));
            int N = Integer.parseInt(br.readLine());
            String [] line = br.readLine().split( " ");
            int [] count = new int[N+1];

            for(int i = 0; i < line.length; i++){
                count[Integer.parseInt(line[i])]++;
            }

            for(int i = 1; i < count.length; i++){
                System.out.println(count[i]);
            }
        }
    }

Measured memory_bytes: 65676
#include <bits/stdc++.h>
struct fastio { fastio() { std::ios::sync_with_stdio(false); std::cin.tie(nullptr); } } _fastio_;
template<class T> bool chmin (T &a, const T &b) { if (a > b) { a = b; return 1; } return 0; }
template<class T> bool chmax (T &a, const T &b) { if (a < b) { a = b; return 1; } return 0; }

int main() {
	int n, a, b;
	std::cin >> n >> a >> b;
	std::cout << std::min(a * n, b) << '\n';
	return 0;
}

Measured memory_bytes: 3608
#include<iostream>
#include<iomanip>
#include<cmath>
#include<string>
#include<vector>
#include<list>
#include<algorithm>
#include<map>
#include<set>
#include<queue>
#include<stack>
using namespace std;
typedef long long ll;
#define fi first
#define se second
#define mp make_pair
#define rep(i, n) for(int i=0;i<n;++i)
#define rrep(i, n) for(int i=n;i>=0;--i)
const int inf=1e9+7;
const ll mod=1e9+7;
const ll big=1e18;
const double PI=2*asin(1);

int main() {
  int a, b;
  cin>>a>>b;
  if((a+b)%2==0) cout<<(a+b)/2<<endl;
  else cout<<(a+b+1)/2<<endl;
}



Measured memory_bytes: 3528
#include<stdio.h>
#include<math.h>

int main (void){
	double x1,x2,y1,y2;
	double d;
	
	
	scanf("%lf %lf %lf %lf",&x1,&y1,&x2,&y2);
	d = sqrt((x2-x1)*(x2-x1)+(y2-y1)*(y2-y1));
	
	printf("%f\n",d);
	return 0;
}

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

#define MOD 100000

//ツビツッツトツづ? t[i][j]ツづ個債カツ療猟づィツつゥツづァ(w-1)ツ古つつェJOツづ?つ?づゥツつゥツづ個湘ョツ陛アツづーツ篠敖づ?
int h, w, ALL;
int dp[2][524289][2]; //[ツ催?標][bit][ツ陳シツ前ツつェJツづ?つ?づゥツつゥ]
char t[22][22];

void solve(){
  int to_k = (1 << (w - 1));

  memset(dp, 0, sizeof(dp));
  dp[0][0][0] = 1;

  for(int i = 0; i < h; i++){
    for(int j = 0; j < w; j++){
      int idx = (i * w + j) % 2;
      int nidx = (idx + 1) % 2;
      memset(dp[nidx], 0, sizeof(int) * 524289 * 2);

      for(int k = 0; k < to_k; k++){
        for(int l = 0; l < 2; l++){
          if(dp[idx][k][l] == 0) continue;

          //t[i][j]ツづーJツづ可つキツづゥ
          if(t[i][j] == '?' || t[i][j] == 'J'){
            int nk = (k << 1) % to_k;
            dp[nidx][nk][1] += dp[idx][k][l];
            dp[nidx][nk][1] %= MOD;
          }

          //t[i][j]ツづーOツづ可つキツづゥ
          if(t[i][j] == '?' || t[i][j] == 'O'){
            int nk = (k << 1) % to_k;
            if(l == 1 && j != 0){
              dp[nidx][nk + 1][0] += dp[idx][k][l];
              dp[nidx][nk + 1][0] %= MOD;
            }
            else{
              dp[nidx][nk][0] += dp[idx][k][l];
              dp[nidx][nk][0] %= MOD;
            }
          }

          //t[i][j]ツづーIツづ可つキツづゥ
          if((t[i][j] == '?' || t[i][j] == 'I') &&
             (j == w - 1 || !(k >> (w - 2)))){
            int nk = (k << 1) % to_k;
            dp[nidx][nk][0] += dp[idx][k][l];
            dp[nidx][nk][0] %= MOD;
          }
        }
      }
    }
  }

  int ans = 0;
  int idx = (w * h) % 2;

  for(int k = 0; k < to_k; k++){
    ans += dp[idx][k][0];
    ans += dp[idx][k][1];
    ans %= MOD;
  }

  cout << (ALL + MOD - ans) % MOD << endl;
}

int main(){
  while(cin >> h >> w){
    ALL = 1;

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

      for(int j = 0; j < w; j++){
        if(t[i][j] == '?'){
          ALL *= 3;
          ALL %= MOD;
        }
      }
    }

    solve();
  }
}

Measured memory_bytes: 9028
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <vector>
#include <queue>
#include <map>
#include <iterator>
#include <cmath>
#include <set>
#include <deque> 
#include <string>


using namespace std;

int main()
{
	int k;
	scanf("%d", &k);
	
	for (int i = 0 ; i < k ; i++) {
		printf("ACL");
	}
	printf("\n");
	
	

	return 0;
}


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

typedef long long ll;
using namespace std;

#define all(x) x.begin(), x.end()
#define f(i,a,b) for(int i = (a); i <= (b); i++)
#define fd(i,a,b) for(int i = (a); i >= (b); i--)
#define mp make_pair
#define faster_io() ios_base::sync_with_stdio(false)
#define pb push_back
#define pii pair<int,int>
#define SZ(x) ((int)x.size())
#define vii vector<pair<int,int>>

const int INF = 1000000005;
const ll INFLL = 1000000000000000002ll;
const ll MOD = 1000000007;

inline ll min(ll a, ll b, ll c){return min(min(a,b),c);}
inline ll min(ll a, ll b, ll c, ll d){return min(min(min(a,b),c),d);}
inline ll max(ll a, ll b, ll c){return max(max(a,b),c);}
inline ll max(ll a, ll b, ll c, ll d){return max(max(max(a,b),c),d);}

// -------------------------------------------------------------------------------------------------------------

int N;

int dig(int x)
{
    int ret = 0;
    while(x)
    {
        ret += x%10;
        x /= 10;
    }
    return ret;
}

int main()
{
    cin >> N;
    int ans = INF;
    f(i,1,N-1)
    {
        int j = N-i;
        ans = min(ans, dig(i) + dig(j));
    }
    cout << ans;
}


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

int way(int n){
  int a,x,y;
  x = n%10;
  y = n/10;
  a = x*y;
  
  return a;
}

int main() {
  int m,d;
  cin >> m >> d;
  int ans = 0;
  for(int i=1;i<=m;i++){
    for(int j=1;j<=d;j++){
      if(j%10 >=2 && j/10 >= 2){
        if(i == way(j)){
          ans++;
        }
      }
    }
  }
  
  cout << ans << endl;
}


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

int main(){
  int A,B;
  cin >> A >> B;
  
  int cnt=0;
  while(B+cnt-1 > A*cnt){
    cnt++;
  }
  
  cout << cnt << endl;
}


Measured memory_bytes: 256
# util functions

# debug
$debugFlag = ( ARGV[0] != nil )
p "==== DEBUG MODE ====" if $debugFlag

def pd(str)
  p str if $debugFlag
end

def printd(str)
  print str if $debugFlag
end

# input
inputs = []
lc = 0
while l = $stdin.gets do
  if false
    inputs << l.chomp.split(" ").map(&:to_s)
  else
    inputs << l.chomp.split(" ").map(&:to_i)
  end
  lc += 1
end

aa = inputs[0][0]
bb = inputs[0][1]
cc = inputs[0][2]

# input check
if $debugFlag
  p "--- INPUT (begin) ---"
  inputs.each do |l_i|
    p l_i
  end
  p "--- INPUT (end) ---"
  print "\n"
end

# body
if $debugFlag
end

puts [aa+bb, bb+cc, cc+aa].min


Measured memory_bytes: 1788
{-# OPTIONS_GHC -O2 #-}
{-# LANGUAGE OverloadedStrings #-}
{-# LANGUAGE BangPatterns #-}
{-# LANGUAGE DeriveFunctor #-}
{-# LANGUAGE TypeSynonymInstances #-}
{-# LANGUAGE FlexibleInstances #-}
{-# LANGUAGE FlexibleContexts #-}
{-# LANGUAGE NPlusKPatterns #-}
module Main where

import Data.List (unfoldr)

import Control.Monad (replicateM, forM_)
import Data.Bool (bool)
import Data.Char (isSpace)
import Data.Function (on)
import qualified Data.Foldable as Foldable
import Data.List (unfoldr, foldl', sort, (\\), delete, nub)
import qualified Data.Map as Map
import qualified Data.Set as Set
import qualified Data.Vector.Unboxed as U
import qualified Data.Vector.Unboxed.Mutable as UM
import qualified Data.Vector as V
import qualified Data.Vector.Mutable as VM
import qualified Data.ByteString.Char8 as C
import qualified Data.ByteString.Unsafe as B
import System.IO (hPutStr, hPutStrLn, stdin, stdout, withFile, IOMode(..))

type Parser a = C.ByteString -> Maybe (a, C.ByteString)

parseInt :: Parser Int
parseInt = C.readInt . C.dropWhile isSpace

getInts :: IO [Int]
getInts = unfoldr parseInt <$> C.getLine

getIntVec :: Int -> IO (U.Vector Int)
getIntVec n = U.unfoldrN n parseInt <$> C.getLine


gcd3 (x, y, z) = gcd (gcd x y) z

ans k = foldl' (\t xyz -> gcd3 xyz + t) 0 [(x, y, z) | x <- ks, y <- ks, z <- ks]
  where ks = [1..k]

main = do
  k <- readLn :: IO Int
  print $ ans k

Measured memory_bytes: 4200
#include<stdio.h>

int main(){

  int a[101][101],n;
  int b[101]={};
  int c[101],i,j,count;
  int min1,min2,mini,sum;

  for(i=1;i<=100;i++)
    c[i]=1000000;

  c[1]=0;
  scanf("%d",&n);
 
  for(i=1;i<=n;i++)
    for(j=1;j<=n;j++)
      scanf("%d",&a[i][j]);

  min2=1;
  sum=0;
  b[1]=1;

  while(1){
    
    count=0;
    for(i=1;i<=n;i++)
      if(b[i]==1)count++;
    if(count==n)break;
    
    min1=10000000;
    
    for(i=1;i<=n;i++){
      if(b[i]!=1 && a[min2][i]!=-1 && c[i]>a[min2][i])
	c[i] = a[min2][i];
      if(b[i]!=1 && min1>c[i]){
	mini=i;
	min1=c[i];
      }
    }
  sum += min1;
  b[mini]=1;
  c[mini] = min1;
  min2 = mini;
  }
  printf("%d\n",sum);
  
  return 0;
}



Measured memory_bytes: 2112
import math

a, b, C = map(float, input().split())
S = (a * b * math.sin(math.radians(C))) / 2
L = a + b + (a**2 + b**2 - 2 * a * b * math.cos(math.radians(C)))**0.5
h = b * math.sin(math.radians(C))
print(S)
print(L)
print(h)


Measured memory_bytes: 5696
import math

l = input().split()
N = int(l[0])
T = []

for i in range(N):
    l = input().split()
    T.append(int(l[0]))

# print(N, T)

def gcd(a, b):
    if a < b:
        return gcd(b, a)
    d = a % b
    if d == 0:
        return b
    return gcd(b, d)

lcm = T[0]
for t in T:
    d = gcd(lcm, t)
    lcm = lcm * t // d

print(lcm)


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

int main(){
  int N;
  cin>>N;
  int A[N];
  int cnt=0;
  map<int,int>mp;
  for(int i=0;i<N;i++){
    cin>>A[i];
    if(mp[A[i]]!=0){
      cnt++;
    }
    mp[A[i]]++;
  }
  if(cnt%2==0){
    cout<<N-cnt<<endl;
    return 0;
  }
  cout<<N-cnt-1<<endl;
  return 0;
}

Measured memory_bytes: 5376
#include <iostream>
#include <string>
#include <vector>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <algorithm>
#include <functional>
#include <cstdio>
#include <climits>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;

int main() {
    int N;
    cin >> N;
    vector<int> A(N + 2, 0);
    for (int i = 1; i <= N; i++) {
        cin >> A[i];
    }
    int S = 0;
    for (int i = 1; i <= N + 1; i++) {
        S += abs(A[i] - A[i - 1]);
    }

    for (int i = 1; i <= N; i++) {
        int cost = S - abs(A[i - 1] - A[i]) - abs(A[i] - A[i + 1]) + abs(A[i - 1] - A[i + 1]);
        cout << cost << endl;
    }
    return 0;
}


Measured memory_bytes: 1664
#include "iostream"
#include "climits"
#include "list"
#include "queue"
#include "stack"
#include "set"
#include "functional"
#include "algorithm"
#include "string"
#include "map"
#include "iomanip"
#include "random"

using namespace std;

const long long int MOD = 1000000007;
const long double EPS = 0.00000001;
const long double PI = 3.1415926535897932384626433;

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

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

	cin >> N;
	while (N) {		
		int a, b, c, d;
		vector<int>ans(4);
		int bag = -10000;
		cin >> a >> b >> c >> d;
		for (int i = 0; i <= a; i++) {
			for (int j = 0; j <= b; j++) {
				for (int k = 0; k <= c; k++) {
					for (int l = 0; l <= d; l++) {
						int e, f, g, h;
						if (10 * i + 50 * j + 100 * k + 500 * l < N) {
							continue;
						}
						int box = 10 * i + 50 * j + 100 * k + 500 * l - N;
						//cout << box << endl;
						h = box / 500;
						box -= h * 500;
						g = box / 100;
						box -= g * 100;
						f = box / 50;
						box -= f * 50;
						e = box / 10;
						if ((i&&e) || (j&&f) || (k&&g) || (l&&h)) {
							continue;
						}
						if (bag < i + j + k + l - e - f - g - h) {
							bag = i + j + k + l - e - f - g - h;
							ans[0] = i;
							ans[1] = j;
							ans[2] = k;
							ans[3] = l;
						}
					}
				}
			}
		}
		int box[4] = { 10,50,100,500 };
		for (int i = 0; i < 4; i++) {
			if (ans[i]) {
				cout << box[i] << " " << ans[i] << endl;
			}
		}
		cin >> N;
		if (N) {
			cout << endl;
		}
	}
	return 0;
}

Measured memory_bytes: 3100
H,W = list(map(int,input().split()))
a = [list(map(int,input().split())) for _ in range(H)]

out = []
for i in range(H):
    for j in range(W-1):
        if a[i][j]%2:
            out.append([i+1,j+1,i+1,j+2])
            a[i][j] -=1
            a[i][j+1] +=1
for i in range(H-1):
    if a[i][-1]%2:
        out.append([i+1,W,i+2,W])
        a[i][W-1] -=1
        a[i+1][W-1] += 1

print(len(out))
for sub in out:
    print(" ".join(map(str,sub)))

Measured memory_bytes: 29864
/*Lucky_Glass*/
#include<queue>
#include<vector>
#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;

const int N=1000;

int n,m,Vtmp,Nans;
vector<int> Elnk[N+3];
int Edu[N+3],Efa[N+3],Eans[N+3],Fans[N+3];
bool Evis[N+3];

void BFS(int st){
	for(int i=1;i<=n;i++) Evis[i]=false,Efa[i]=0;
	queue<int> que;
	que.push(st);
	Evis[st]=true;
	while(!que.empty()){
		int u=que.front();que.pop();
		for(auto v : Elnk[u]){
			if(Evis[v]){
				if(v==st){
					int Ncnt=0,Pnt=u;
					while(Pnt!=st) Fans[++Ncnt]=Pnt,Pnt=Efa[Pnt];
					Fans[++Ncnt]=st;
					if(Nans>Ncnt){
						Nans=Ncnt;
						for(int i=1;i<=Ncnt;i++)
							Eans[i]=Fans[i];
					}
					return;
				}
				else continue;
			}
			Efa[v]=u;
			Evis[v]=true;
			que.push(v);
		}
	}
}
int main(){
	scanf("%d%d",&n,&m);
	for(int i=1;i<=m;i++){
		int u,v;
		scanf("%d%d",&u,&v);
		Elnk[u].push_back(v);
	}
	Nans=(1<<29);
	for(int i=1;i<=n;i++){
		BFS(i);
	}
	if(Nans==(1<<29)) printf("-1\n");
	else{
		printf("%d\n",Nans);
		for(int i=1;i<=Nans;i++)
			printf("%d\n",Eans[i]);
	}
	return 0;
}

Measured memory_bytes: 256
using System;
using System.Linq;

namespace agc030_a
{
    class Program
    {
        static void Main(string[] args)
        {
            var text = Console.ReadLine();
            var list = text.Split(' ').ToList();

            var a = int.Parse(list[0]);
            var b = int.Parse(list[1]);

            int leftvalue = 1;
            int rightvalue = a;

            for (int i = 0; i < b; i++)
            {
                text = Console.ReadLine();
                list = text.Split(' ').ToList();

                var c = int.Parse(list[0]);
                var d = int.Parse(list[1]);

                leftvalue = Math.Max(leftvalue, c);
                rightvalue = Math.Min(rightvalue, d);
            }

            var gate = rightvalue - leftvalue;
            if (gate < 0){
                Console.WriteLine("0");
            }
            else{
                Console.WriteLine( rightvalue - leftvalue + 1);
            }

        }
    }
}


Measured memory_bytes: 15312
#!/usr/bin/env python
# -*- coding: utf-8 -*-

"""
input:
0 0 2
2 0 2

output:
1.00000000 -1.73205080 1.00000000 1.73205080
"""

import sys
from math import sin, cos, atan2, acos
from operator import attrgetter
from collections import namedtuple


def arg(p_vector):
    return atan2(p_vector.imag, p_vector.real)


def polar(a, r):
    return a * cos(r) + a * sin(r) * 1j


def get_circles_cross_points(c1, c2):
    centre_distance = abs(c1.centre - c2.centre)
    # triangle cosine theorem
    a = acos((pow(c1.radius, 2) + pow(centre_distance, 2) - pow(c2.radius, 2)) /
             (2 * c1.radius * centre_distance))
    t = arg(c2.centre - c1.centre)
    ans = [c1.centre + polar(c1.radius, t + a), c1.centre + polar(c1.radius, t - a)]
    ans.sort(key=attrgetter('real', 'imag'))

    return ans


def solve(_circles):
    cp1, cp2 = get_circles_cross_points(*_circles)
    print('{0:.8f} {1:.8f} {2:.8f} {3:.8f}'.format(cp1.real, cp1.imag, cp2.real, cp2.imag))
    return None


if __name__ == '__main__':
    _input = sys.stdin.readlines()
    circle_info = map(lambda x: x.split(), _input)

    Circle = namedtuple('Circle', 'centre radius')
    circles = [Circle(centre=int(cx) + int(cy) * 1j, radius=int(r)) for cx, cy, r in circle_info]
    solve(circles)

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

using namespace std;

void solve() {
	int n; cin >> n;
	vector<int> d(n);
	rep(i, n) scanf("%d", &d[i]);
	sort(d.begin(), d.end());
	cout << d[d.size() / 2] - d[d.size() / 2 - 1] << endl;
}

int main(void) {
	solve();
	return 0;
}

Measured memory_bytes: 640
import heapq
INF = 1e7
H,W=map(int, input().split())
sx, sy = map(int, input().split())
dh, dw = map(int, input().split())
sx -= 1
sy -= 1
S = [input() for _ in range(H)]
D = [[INF]*(W) for _ in range(H)] #始点からの距離(重み)
D[sx][sy] = 0
PQ = [(0, (sx, sy))]
heapq.heapify(PQ)
while PQ: # PQに候補がある限り
    _, (ux, uy) = heapq.heappop(PQ) # 最小コストなノードu
    for dx in range(-2, 3):
        for dy in range(-2, 3):
            xx, yy = ux+dx, uy+dy
            if 0 <= xx < H and 0 <= yy < W and S[xx][yy]==".":
                is_not_neighbor = int(abs(dx) + abs(dy) != 1)
                # neighborでなければコストが1増える
                if D[ux][uy] + is_not_neighbor < D[xx][yy]:
                    D[xx][yy] = D[ux][uy] + is_not_neighbor
                    heapq.heappush(PQ, (D[xx][yy], (xx, yy)))
if D[dh-1][dw-1] >= INF:
    print(-1)
else:
    print(D[dh-1][dw-1])

Measured memory_bytes: 123264
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef pair<ll,ll> mp;
#define inf 1e9


int main(){
	int a,b;
	cin>>a>>b;
	if(a>12){
		cout<<b<<endl;
	}else if(a>5){
		cout<<b/2<<endl;
	}else{
		cout<<0<<endl;
	}


	return 0;
}


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

//#define int long long
#define reps(i,s,n) for(int (i)=(s);(i)<(n);++(i))
#define rep(i,n) reps(i,0,n)
#define rept(i,n) rep(i,(n)+1)
#define repst(i,s,n) reps(i,s,(n)+1)
#define reprt(i,n,t) for(int (i)=(n);(i)>=(t);--(i))
#define repr(i,n) reprt(i,n,0)
#define each(itr,v) for(auto &(itr):(v))
#define all(c) (c).begin(),(c).end()
#define rall(c) (c).rbegin(),(c).rend()
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define tmax(x,y,z) max(x,max(y,z))
#define tmin(x,y,z) min(x,min(y,z))
#define chmin(x,y) if((x)>(y))(x)=(y)
#define chmax(x,y) if((x)<(y))(x)=(y)
#define ln '\n'
#define bln(i,n) (((i)==(n)-1)?'\n':' ')
#define dbg(x) cout<<#x" = "<<(x)<<ln<<flush
#define dbga(x,n) {cout<<#x" : ";for(int (i)=0;i<(n);++i){cout<<((x)[i])<<(i==((n)-1)?'\n':' ')<<flush;}}
#define zero(a) memset(a,0,sizeof(a))
#define unq(a) sort(all(a)),a.erase(unique(all(a)),a.end())

typedef long double ld;
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<string> vst;
typedef vector<bool> vb;
typedef vector<ld> vld;
typedef vector<pii> vpii;
typedef vector<pll> vpll;
typedef vector<vector<int> > mat;

const ll inf = (ll)1e9+10;
const ll linf = (ll)1e18+10;
const ll mod = (ll)(1e9+7);
const int dx[] = {0, 1, 0, -1};
const int dy[] = {1, 0, -1, 0};
const int ddx[] = {0, 1, 1, 1, 0, -1, -1, -1};
const int ddy[] = {1, 1, 0, -1, -1, -1, 0, 1};
const double eps = 1e-10;

ll mop(ll a,ll b) {ll res=1;a%=mod; assert(b>=0); for(;b;b>>=1){if(b&1)res=res*a%mod;a=a*a%mod;}return res;}
ll gcd(ll a,ll b) {return b?gcd(b,a%b):a;}
ll lcm(ll a,ll b) {return a*b/gcd(a,b);}

struct oreno_initializer {
	oreno_initializer() {
		cin.tie(0);
		ios::sync_with_stdio(0);
	}
} oreno_initializer;

// ━━━━☆・‥…━━━☆・‥…━━━☆・‥…━━━☆・‥…━━━☆・‥…━━━☆・‥…━━━☆・‥…━━━☆・‥…━━━☆・‥…
// .｡.:( ^ω^)・ﾟ＋.｡.:( ^ω^)・ﾟ＋.｡.:( ^ω^)・ﾟ＋.｡.:( ^ω^)・ﾟ＋.｡.:( ^ω^)・ﾟ＋
// ・‥…━━━☆・‥…━━━☆・‥…━━━☆・‥…━━━☆・‥…━━━☆・‥…━━━☆・‥…━━━☆・‥…━━━☆・‥…━━━☆・

// d[i][j]: 街iに総コストjかけて到着する際に遭遇する盗賊の数の最小値
int n, m, s, a, b, l, x, d[101][101];
vector<pair<int,pii> > e[101];

void dijkstra() {
	priority_queue<pair<pii,int>, vector<pair<pii,int> >, greater<pair<pii,int> > > que;
	rep(i,n) rept(j,s) d[i][j] = inf;
	d[0][0] = 0;
	que.push({{0,0},0});
	while(!que.empty()) {
		int v = que.top().second, th = que.top().fi.fi, cs = que.top().fi.se; que.pop();
		if (d[v][cs]<th) continue;
		for (int i = 0; i < e[v].size(); ++i) {
			int to = e[v][i].first, dist = e[v][i].se.fi, bd = e[v][i].se.se;
			// 護衛を雇う場合
			if (cs+dist<=s && d[to][cs+dist] > d[v][cs]) {
				d[to][cs+dist] = d[v][cs];
				que.push({{d[to][cs+dist], cs+dist}, to});
			}
			// 雇わない場合
			if (d[to][cs] > d[v][cs] + bd) {
				d[to][cs] = d[v][cs] + bd;
				que.push({{d[to][cs], cs}, to});
			}
		}
	}
}

signed main() {
	while (1) {
		cin >> n >> m >> s;
		if (n==0) break;
		rep(i,n) e[i].clear();
		rep(i,m) {
			cin >> a >> b >> l >> x;
			a--, b--;
			e[a].pb({b,{l,x}}), e[b].pb({a,{l,x}});
		}
		dijkstra();
		int res = inf;
		rept(i,s) chmin(res,d[n-1][i]);
		cout << res << ln << flush;
	}
}


Measured memory_bytes: 3504
fun main(args: Array<String>) {
    val (n, k) = readLine()?.split(" ")?.map(String::toLong) ?: return
    val a = readLine()?.split(" ")?.map(String::toLong)?.sorted()?.toLongArray() ?: return
    val nInt = n.toInt()
    fun ok(x: Long): Boolean {
        var total = 0L
        for (i in 0 until nInt) {
            val t = a[i]
            if (t < 0) {
                var s = -1
                var e = nInt
                while (s + 1 < e) {
                    val c = (s + e) / 2
                    if (t * a[c] < x) {
                        e = c
                    } else {
                        s = c
                    }
                }
                total += nInt - e
            } else {
                var s = -1
                var e = nInt
                while (s + 1 < e) {
                    val c = (s + e) / 2
                    if (t * a[c] < x) {
                        s = c
                    } else {
                        e = c
                    }
                }
                total += e
            }
            if (t * t < x) {
                total--
            }
        }
        return total / 2 < k
    }

    // k番目の数字の候補の範囲
    val inf: Long = (1e18 + 1).toLong()
    var l = -inf
    var r = inf
    while (l + 1 < r) {
        // xより小さい値の個数がk未満かどうかを調べる
        val x = (l + r) / 2
        if (ok(x)) {
            l = x
        } else {
            r = x
        }
    }
    println(l)
}

Measured memory_bytes: 85744
#include <bits/stdc++.h>
#define REP(i, n) for(int i = 0;i < n;i++)
#define REPR(i, n) for(int i = n;i >= 0;i--)  
#define FOR(i, m, n) for(int i = m;i < n;i++)
#define FORR(i, m, n) for(int i = m;i >= n;i--)
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
#define ll long long
#define pb(a) push_back(a)
#define INF 999999999
#define MOD 1000000007
using namespace std;
typedef pair<int, int> P;
typedef pair<ll, ll> LP;
typedef pair<int, P> PP;
typedef pair<ll, LP> LPP;

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

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

ll modpow(ll n,ll k){
  if(k == 1){
    return n;
  }else if(k == 0){
    return 1;
  }else if(k%2==0){
    ll memo = modpow(n,k/2)%MOD;
    return memo*memo%MOD;
  }else{
    return n * modpow(n,k-1)%MOD;
  }
}

int main(){

  int a,b;
  cin>>a>>b;
  if(a<=5){
    cout<<0<<endl;
  }else if(a<=12){
    cout<<b/2<<endl;
  }else{
    cout<<b<<endl;
  }
 

  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
const int inf=1e9+7;
int main()
{
//	freopen(".in","r",stdin);
//	freopen(".out","w",stdout);
	for(int i=0;i<2;i++)
	{
		int t;
		cin>>t;
		if(!(t%2))
		{
			cout<<"No"<<endl;
			return 0;
		}
	}
	cout<<"Yes"<<endl;
	return 0;
}


Measured memory_bytes: 256
using System;
using System.Collections.Generic;
using System.Linq;
using static System.Console;
using static System.Math;

namespace A_ABC137
{
    class MainClass
    {

        static int[] s;

        public static void Main(string[] args)
        {
            s = Array.ConvertAll(ReadLine().Split().ToArray(), int.Parse);
            WriteLine(Max(Max(s[0]+s[1],s[0]-s[1]),s[0]*s[1]));
        }
    }
}


Measured memory_bytes: 13268
#include<bits/stdc++.h>
#include <iostream>
using namespace std;
typedef long long int ll;
typedef pair<ll,ll> pp;

int dp[100001];int n,k;
vector<int> g[100001];
int vis[100001];

int dfs(int u,int p)
{
    vis[u]=1;
    int mx=-1;
    for(int i=0;i<g[u].size();i++)
    {
        if(vis[g[u][i]]==0)
        {
            int dist=dfs(g[u][i],u);
            mx=max(mx,dist);
        }
        else
        mx=max(mx,dp[g[u][i]]);
    }
    dp[u]=mx+1;
    return mx+1;
}

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);


    int n,m;
    cin>>n>>m;
    for(int i=1;i<=m;i++)
    {
        int u,v;
        cin>>u>>v;
        g[u].push_back(v);
    }

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

    for(int i=1;i<=n;i++)
    {
        if(vis[i]==0)
        dfs(i,-1);
    }

    int mx=-1;
    for(int i=1;i<=n;i++)
    mx=max(mx,dp[i]);

    cout<<mx<<"\n";

}


Measured memory_bytes: 9216
from sys import stdin
input = stdin.readline
import copy as cp

def VI(N, init=0):
  return [init for _ in range(N)]
def VVI(N, M, init=0):
  return [[init for _ in range(M)] for _ in range(N)]

def VD(N, init=0.0):
  return [init for _ in range(N)]
def VVD(N, M, init=0.0):
  return [[init for _ in range(M)] for _ in range(N)]

def Decimal(x):
  print("{0:.10f}".format(x))

class Pair:
  def __init__(self, x=0, y=0):
    self.first = x
    self.second = y

  def __repr__(self):
    return '{0} {1}'.format(self.first, self.second)

  def __lt__(self, pi):
    return self.first < pi.second

def POW(x, n):
  ret = 1
  while n:
    if n&1:
      ret *= x
    x *= x
    n >>= 1
  return ret

MAX_N = 505
MAX_C = 35
D = VVI(MAX_C, MAX_C)
color = VVI(MAX_N, MAX_N)

N, C = map(int, input().rstrip().split())
for i in range(C):
  tmp_list = list(map(int, input().rstrip().split()))
  for j in range(C):
    D[i][j] = tmp_list[j]

for i in range(N):
  tmp_list = list(map(int, input().rstrip().split()))
  for j in range(N):
    color[i][j] = tmp_list[j]
    color[i][j] -= 1

table = VVI(3, MAX_C)

for i in range(N*N):
  x = i % N
  y = i // N
  c = color[y][x]
  for j in range(3):
    if (x+y+2)%3 == j:
      table[j][c] += 1

ans = int(1e9+7)

def dfs(s, diff):
  global ans
  if len(s) >= 3:
    ans = min(ans, diff)
    return

  for c in range(C):
    ddiff = diff
    ss = cp.deepcopy(s)
    if c in s:
      continue

    for i in range(C):
      ddiff += table[len(s)][i] * D[i][c]
    ss.add(c)
    dfs(ss , ddiff)

s = set([])

dfs(s, 0)

print(ans)




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

int main() {
	ios::sync_with_stdio(0); cin.tie(0);
	char S[110];

	cin >> S;

	bool b = true;
	for(int i = 0; S[i]; i++) if(((i & 1) && S[i] == 'R') || ((i & 1) == 0 && S[i] == 'L')) b = false;
	cout << (b ? "Yes" : "No");
	return 0;
}


Measured memory_bytes: 256
def main():
    import sys
    input=sys.stdin.readline
    n,h=map(int,input().split())
    sword=[list(map(int,input().split())) for i in range(n)]
    m=max([sword[i][0] for i in range(n)])
    sword2=[sword[i][1] for i in range(n)]
    sword2.sort(reverse=True)
    
    cnt=0
    for s in sword2:
        if m<s:
            cnt+=1
            h-=s
            if h<=0:
              print(cnt)
              exit()
        else:
          break
    cnt+=(h+m-1)//m
    print(cnt)
    
if __name__=='__main__':
    main()


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

int i,j,k,set,map[150][150],sss[150][150],q[20000][2],blk,ans;
int m,n,s,t,x,y;

void mark(int x,int y){
	if(x<0 || y<0 || x>=m || y>=n)return;
	if(sss[x][y]!=set){
		map[x][y]=map[q[i][0]][q[i][1]]+1;
		sss[x][y]=set;
		q[j][0]=x;q[j][1]=y;
		j++;
	}
}

void search(int x,int y){
	mark(x-1+y%2,y-1);
	mark(x+y%2,y-1);
	mark(x-1,y);
	mark(x+1,y);
	mark(x-1+y%2,y+1);
	mark(x+y%2,y+1);
}

void check2(int x,int y,int k){
	if(x<0 || y<0 || x>=m || y>=n)return;
	if(sss[x][y]>=set || map[x][y]<=k)return;
	sss[x][y]=set+k;
	q[j][0]=x;q[j][1]=y;
	j++;
}

void check(int x,int y,int k){
	check2(x-1+y%2,y-1,k+1);
	check2(x+y%2,y-1,k+1);
	check2(x-1,y,k+1);
	check2(x+1,y,k+1);
	check2(x-1+y%2,y+1,k+1);
	check2(x+y%2,y+1,k+1);
}

int main(){
	while(scanf("%d",&m)*m){
		set+=300;
		scanf("%d %d",&n,&s);
		for(i=0;i<s;i++){
			scanf("%d %d",&x,&y);
			y--;x--;
			map[x][y]=0;
			sss[x][y]=set;
			q[i][0]=x;
			q[i][1]=y;
		}
		i=0;j=s;
		while(i<j){
			search(q[i][0],q[i][1]);
			i++;
		}
		
		scanf("%d",&t);
		ans=0;
		for(i=0;i<t;i++){
			scanf("%d %d",&x,&y);
			x--;y--;set+=300;
			blk=0;j=1;
			q[0][0]=x;q[0][1]=y;
			sss[x][y]=set;
			while(blk<j){
				check(q[blk][0],q[blk][1],sss[q[blk][0]][q[blk][1]]-set);
				blk++;
			}
			/*
			for(x=0;x<n;x++){
				if(x%2)printf("     ");
				for(y=0;y<m;y++){
					printf("%5d ",sss[y][x]);
				}
				printf("\n");
			}
			printf("\n");
			*/
			if(ans<blk)ans=blk;
		}
		printf("%d\n",ans);

	}
	return 0;
}

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

using LL = long long;

#define ALL(a) begin((a)), end((a))
#define FOR(i, a, b) for (int(i) = (a); (i) < (b); (i)++)
#define RFOR(i, a, b) for (int(i) = (a); (i) > (b); (i)--)
#define debug(x) cout << #x << " : " << x << '\n'

const int INF = 1e9;
const LL LINF = 1e16;

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

  string ans;
  string A, B;
  cin >> A >> B;

  if (A.size() > B.size()) {
    ans = "GREATER";
  } else if (A.size() < B.size()) {
    ans = "LESS";
  } else {
    int size = A.size();
    int i;

    for (i = 0; i < size; i++) {
      if (A[i] > B[i]) {
        ans = "GREATER";
        break;
      } else if (A[i] < B[i]) {
        ans = "LESS";
        break;
      }
    }

    if (i == size) {
      ans = "EQUAL";
    }
  }

  cout << ans << '\n';

  return 0;
}

Measured memory_bytes: 256
x,t,z,k = gets.split.map(&:to_i)
a,b,c = 3.times.map{ gets.split.map(&:to_i).sort }
ab = []
a.each{ |a|
    b.each do |b| ab << a+b end
}
ab.sort!.reverse!
abc = []
ab[0..k-1].each{ |ab|
    c.each do |c| abc << ab+c end
}
puts abc.sort[abc.size-k..-1].reverse

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

using namespace std;

int main()
{

unsigned long long a,b,c,k;
cin>>a>>b>>c>>k;
unsigned long long int i=1,sum=0;
if(a==k){cout<<a<<endl; return 0;}
else if(b==k){cout<<b<<endl; return 0;}
while(a)
{
    if(k>=a)
    {
        k=k-i;
        sum=sum+i;

    }
    if(k<=0){cout<<sum;return 0 ;}
        a--;
}
while(b)
{
    if(k>=b)
    {
        k=k-i;
        sum=sum+0;
    }
    if(k<=0){ cout<<sum;return 0;}
    b--;
}
while(c)
{
    if(k>=c)
    {
        k=k-i;
        sum=sum-1;

    }
    if(k<=0){cout<<sum;return 0;}
    c--;
}


}
*/

#include<iostream>
using namespace std;

int main() {
    int A, B, C, K;
    cin >> A >> B >> C >> K;
    cout << (min(A, K)) - max(K - A - B, 0) << endl;
}


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

#define rep(i, n) for(int i = 0, i##_len = (n); i < i##_len; ++i)
#define repp(i, m, n) for(int i = m, i##_len = (n); i < i##_len; ++i)
#define all(x) (x).begin(), (x).end()
#define clr(ar, val) memset(ar, val, sizeof(ar))
template <class T> bool chmax(T &a, const T &b) { if (a < b) { a = b; return 1; } return 0; }
template <class T> bool chmin(T &a, const T &b) { if (b < a) { a = b; return 1; } return 0; }
int gcd(int a,int b){return b?gcd(b,a%b):a;}
using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef pair <int,int> P;
typedef long double ld;

int main(void)
{
	int n, a[20], b[20], c[20];
	int ans = 0;
	cin >> n;
	rep(i, n) cin >> a[i];
	rep(i, n) cin >> b[i];
	rep(i, n - 1) cin >> c[i];
	rep(i, n) {
		int now = a[i], bef = -1;
		if(i > 0) bef = a[i - 1];
		ans += b[a[i] - 1];
		if(now - bef == 1) ans += c[a[i] - 2];
	}
	cout << ans << endl;
	return 0;
}

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


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

    int ans = 0;
    for(int i = 0; i < n; i++)
    {
        int tmp = 0;
        if (a[i] == b[i] && b[i] == c[i]){
            tmp = 0;
        }else if(a[i] != b[i] && b[i] != c[i] && c[i] != a[i]){
            tmp = 2;
        }else{
            tmp = 1;
        }
        ans += tmp;
    }
    
    cout << ans << endl;

}

Measured memory_bytes: 256
N, M = map(int, input().split())
AB = [list(map(int, input().split())) for _ in range(N)]

AB.sort()
result = 0
num = 0

for i in range(N):
    if num + AB[i][1] <= M:
        num += AB[i][1]
        result += AB[i][0] * AB[i][1]

    else:
        result += AB[i][0] * (M - num)
        break

print(result)


Measured memory_bytes: 27760
import itertools

n=input()

c=[]
for i in range(3,len(n)+1):
    c += list(itertools.product([3,5,7], repeat=i))

m=int(n)
ans=0
for i in range(len(c)):
    if 3 in c[i] and 5 in c[i] and 7 in c[i]:
        search=""
        for g in range(len(c[i])):
            search+=str(c[i][g])
        if m>=int(search):
            ans+=1
print(ans)


Measured memory_bytes: 7028
//B - Addition and Multiplication: 
//Assunto: 
#include<bits/stdc++.h>
#define fi first
#define se second
#define pb push_back
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
#define loop(i, a, b) for(int i = a; i < b; i++)
#define loopBack(i, a, b) for(int i = a; i >= b; i--)
#define INF INT_MAX
#define LINF LLONG_MAX
#define DINF DBL_MAX
#define MAX 100050
#define MOD 1000000007
using namespace std;
typedef long long int ll;
typedef pair<int, int> ii;

int ans = INF;
int n, k;

void solve(int s, int x, int k) {
    if(x >= n) {
        ans = min(s, ans);
        return;
    }
    solve(s+k, x+1, k);
    solve(s*2, x+1, k);
}

int main() {
    ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    //freopen("in.txt", "r", stdin);
    //freopen("out.txt", "w", stdout);
    cin >> n >> k;
    solve(1, 0, k);
    cout << ans << "\n";
}

Measured memory_bytes: 256