akhauriyash/Code-Regression huggingface dataset:
A, B, C, X, Y = map(int, input().split())

if X < Y:
    print(min(2*C*X + (Y - X) * B, X * A + Y * B, 2*C*Y))
else:
    print(min(2*C*Y + (X - Y) * A, X * A + Y * B, 2*C*X))


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

int main() {
	vector<bool> b(101);
	b[0] = 1;
	for (int i = 0; i < 101; i++) {
		if (b[i]) {
			if (i + 4 < 101)
				b[i + 4] = 1;
			if (i + 7 < 101)
				b[i + 7] = 1;
		}
	}
	int n;
	cin >> n;
	cout << (b[n] ? "Yes" : "No") << endl;
}


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

namespace ALDS_1_3_D
{
    class Program
    {
        static void Main(string[] args)
        {
            //入力
            char[] inputLine = Console.ReadLine().ToCharArray();

            //読み込んだバックスラッシュのインデックスを格納する。
            Stack<int> slashStack = new Stack<int>();

            //これまでの水たまりの面積と、水たまりの左端のスラッシュインデックスを格納する。
            Stack<Pond> pondStack = new Stack<Pond>();

            for (int i = 0; i < inputLine.Length; i++)
            {
                if (inputLine[i] == '\\')
                {
                    slashStack.Push(i);
                }

                if (inputLine[i] == '/' && slashStack.Count() > 0)
                {
                    int tmpIndex = slashStack.Pop();

                    Pond tmpPond = new Pond(tmpIndex, i - tmpIndex);

                    while (pondStack.Count() > 0 && pondStack.Peek().slashIndex > tmpPond.slashIndex)
                    {
                        tmpPond.SumPond(pondStack.Pop());
                    }

                    pondStack.Push(tmpPond);
                }
            }

            int totalVolume = 0;

            pondStack.ToList()
                     .ForEach(p => totalVolume += p.volume);
            //総面積
            Console.WriteLine(totalVolume);

            //水たまり総数
            Console.Write(pondStack.Count());
            
            //各水たまり面積
            pondStack.Reverse()
                     .ToList()
                     .ForEach(p => Console.Write(" " + p.volume));

            Console.WriteLine();
        }
    }

    public class Pond
    {
        public int slashIndex;

        public int volume;

        public Pond(int slashIndex, int volume)
        {
            this.slashIndex = slashIndex;
            this.volume = volume;
        }

        //水たまり同士を加算する。
        public void SumPond(Pond pond)
        {
            this.slashIndex = this.slashIndex < pond.slashIndex ? this.slashIndex : pond.slashIndex;
            this.volume = this.volume + pond.volume;
        }
    }
}



Measured memory_bytes: 20696
#include<stdio.h>
#include<iostream>
#include<string>
#include<math.h>
#include<cmath>
#include<algorithm>
#include<map>
#include<queue>
#include<stack>
#include<vector>
#include<time.h>
#include<ctime>
#include<functional>
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
int inf = 1000000000;
template<typename T>
T GCD(T a, T b) {
	while (max(a, b) % min(a, b)) {
		if (a > b)a = a % b;
		else b = b % a;
	}
	return min(a, b);
}
template<typename T>
T LCM(T a, T b) {
	return a / GCD(a, b)*b;
}
bool prime(ll a) {
	for (int i = 2; i <= sqrt(a); i++) {
		if (!(a%i))return false;
	}
	return true;
}
int main() {
	ll n, c[510], s[510], f[510];
	cin >> n;
	for (int i = 1; i < n; i++)cin >> c[i] >> s[i] >> f[i];
	for (int i = 1; i <= n; i++) {
		ll time = 0;
		for (int j = i; j < n; j++) {
			if (time <= s[j]) {
				time = s[j] + c[j];
			}
			else time = (time + f[j] - 1) / f[j] * f[j] + c[j];
		}
		cout << time << endl;
	}
	return 0;
}

Measured memory_bytes: 256
from itertools import *
from heapq import *

X, Y, A, B, C = map(int, input().split())
P = sorted(map(lambda x:-int(x), input().split()))
Q = sorted(map(lambda x:-int(x), input().split()))
R = sorted(map(lambda x:-int(x), input().split()))

S = sum(islice(merge(islice(P, X),islice(Q, Y),R), X+Y))

print(-S)


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

int main(){
 int A , B;
  cin >> A >> B;
  int C, D ,E;
  C = max (A , B);
  D = A + B;
  E = (C * 2) - 1;
  
  if (D > E) {
    cout << D << endl;
  }else{
    cout << E << endl;
  }
}

Measured memory_bytes: 256
#include <iostream>
#include <cstring>
#include <cmath>
#include <vector>
#include <algorithm>
#include <stdio.h>
#include <math.h>
#include <stdlib.h>
#include <set>
#include <map>
#include <iterator>
#include <stack>
#include <string.h>
#include <cstdlib>
#include <queue>
#include <list>
#include <string>

using namespace std;

int main()
{
    int n;
    int a[100005];
    int ans[100005];
    
    cin >> n;
    for (int i = 0;i < n;i++){
        cin >> a[i];
        ans[a[i]] = i+1;
    }
    
    for (int i = 1;i <= n;i++){
        cout << ans[i] << " ";
    }
    cout << endl;
}


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

int main() {
  int N;
  cin >> N; //N個のボタン
  vector<int> button;
  for (int i = 0; i < N; i++) {
  int nextbutton;
  cin >> nextbutton;
  nextbutton--;
  button.push_back(nextbutton);
  }
  int MIENAI,COUNT;
  for (;;) {
    if(MIENAI == 1){
      cout << COUNT << endl;
      break;
    }
    if(COUNT > N){
      cout << -1 << endl;
      break;
    }
    COUNT++;
    MIENAI = button.at(MIENAI);
  }
}

Measured memory_bytes: 892
#include <iostream>
#include <vector>
#include <algorithm>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <string>
#include <cstdio>
#include <cstdlib>
#include <string>
#include <cstring>
#include <cmath>
#include <climits>
#include <ctime>
#include <fstream>
#include <functional>
#define endl '\n'
#define ll long long
#define mod 1000000007
#define NCONS 200001
//#define NCONS 100001
//#define NCONS 1001
//#define NCONS 101
#define MCONS 2001
#define LIMIT 1000000000
#define TRUE 1
#define FALSE 0
#define toRadian(degree) ((degree) * (M_PI / 180.))
#define toDegree(radian) ((radian) * (180. / M_PI))
using namespace std;
struct Point{int x; int y;};
struct PPoint{Point x; Point y;};
ll gcd(ll a, ll b) { if(a < b) swap(a, b); if(b <= 0) return a; return gcd(b, a % b); }

int N;
struct El{ll A; ll B;};
vector<El> vec;

int main(void)
{
    cin.tie(NULL); ios_base::sync_with_stdio(false);
    cin >> N;
    for(int i = 0; i < N; i++)
    {
        int a, b; cin >> a >> b; vec.push_back(El{ a, b });
    }
    sort(vec.begin(), vec.end(), [](El a, El b){if(a.B == b.B) return a.A < b.A; return a.B < b.B;});
   
    ll cur_time = 0;
    
    for(auto v : vec)
    {
      cur_time += v.A;
        if(cur_time > v.B)
        {
            cout << "No" << endl;
            return 0;
        }
            
    }
    
    cout << "Yes" << endl;
    return 0;
}


Measured memory_bytes: 6128
#include <bits/stdc++.h>
#include <boost/multiprecision/cpp_int.hpp>

using namespace std;
using namespace boost::multiprecision;

#define REP(i, n) for (int i = 0; i < (int)(n); i++)
#define ALL(x) (x).begin(),(x).end()
inline cpp_int between(cpp_int n, cpp_int x) {
  if(n >= 0)
    return (n/x)+1;
  else
    return 0;
}
inline int parse_digit(char a) { return a - '0'; }

int main () {
  string input;
  cin >> input;

  REP(i, 2) {
    REP(j, 2) {
      REP(k, 2) {
        int a = parse_digit(input[0]);
        int b = parse_digit(input[1]);
        int c = parse_digit(input[2]);
        int d = parse_digit(input[3]);
        
        if(i == 1) b*=-1;
        if(j == 1) c*=-1;
        if(k == 1) d*=-1;

        if((a+b+c+d) == 7) {
          cout << input[0] << (i==0 ? '+' : '-') <<
                  input[1] << (j==0 ? '+' : '-') <<
                  input[2] << (k==0 ? '+' : '-') <<
                  input[3] << "=7" << endl;
          return 0;
        }
      }
    }
  }

  return 0;
}


Measured memory_bytes: 256
a,b,c,d=map(int,input().split(" "))
if abs(a-c)>abs(b-d):
    if a>c:
        if b>d:
            print(c+(b-d),d-(a-c),a+(b-d),b-(a-c))
        else:
            print(c-(d-b),d-(a-c),a-(d-b),b-(a-c))
    else:
        if b>d:
            print(c+(b-d),d+(c-a),a+(b-d),b+(c-a))
        else:
            print(c-(d-b),d+(c-a),a-(d-b),b+(c-a))
else:
    if b>d:
        if a>c:
            print(c+(b-d),d-(a-c),a+(b-d),b-(a-c))
        else:
            print(c+(b-d),d+(c-a),a+(b-d),b+(c-a))
    else:
        if a>c:
            print(c-(d-b),d-(a-c),a-(d-b),b-(a-c))
        else:
            print(c-(d-b),d+(c-a),a-(d-b),b+(c-a))
            

Measured memory_bytes: 3064
import java.util.Scanner;

class Problem {
    private int N;
    private int[] A;

    Problem() {
        Scanner sc = new Scanner(System.in);

        N = sc.nextInt();
        A = new int[N];
        for (int i = 0; i < N; i++) {
            A[i] = sc.nextInt();
        }
    }

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

    int solve() {
        int g = A[0];
        for (int i = 1; i < N; i++) {
            g = gcd(Math.max(g, A[i]), Math.min(g, A[i]));
        }

        return g;
    }
}

public class Main {
    public static void main(String[] args) {
        System.out.println(new Problem().solve());
    }
}


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

#define ALL(v) v.begin(), v.end()
#define V vector
#define P pair
using ll = long long;

struct UnionFind {
    vector<int> d;
    UnionFind(int n): d(n,-1) {}
    int root(int x) {
        if (d[x] < 0) return x;
        return d[x] = root(d[x]);
    }
    bool unite(int x, int y) {
        x = root(x); y = root(y);
        if (x == y) return false;
        if (d[x] > d[y]) swap(x,y);
            d[x] += d[y];
            d[y] = x;
            return true;
        }
    bool same(int x, int y) { return root(x) == root(y); }
    int size(int x) { return -d[root(x)];}
};

int main() {
    int n, m; cin >> n >> m;
    UnionFind uf(n);

    for(int i = 0; i < m; i++){
        int a, b; cin >> a >> b;
        --a; --b;
        uf.unite(a,b);
    }

    int ans = 0;
    for(int i = 0; i < n; i++){
        ans = max(ans, uf.size(i));
    }
    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 4032
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,a,b) for(int i=(a),i##formax=(b);i<i##formax;i++)
#define FORR(i,a,b) for(int i=(a),i##formax=(b);i>=i##formax;i--)
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define pcnt __builtin_popcount
#define sz(x) (int)(x).size()
#define maxs(x,y) x=max(x,y)
#define mins(x,y) x=min(x,y)
#define show(x) cout<<#x<<" = "<<x<<endl;
#define all(a) (a.begin()),(a.end())
#define each(it,c) for(__typeof((c).begin()) it=(c).begin();it!=(c).end();it++)
#define perm(c) sort(all(c));for(bool c##p=1;c##p;c##p=next_permutation(all(c)))
#define bitComb(a,n,k) for(int a##x,a##y,a=(1<<k)-1;a<(1<<n);a##x=a&-a,a##y=a+a##x,a=(((a&~a##y)/a##x)>>1)|a##y)
#define uniq(v) sort(all(v));v.erase(unique(all(v)), v.end())
#define bit(n) (1LL<<(n))
#define randInt(l,r) (uniform_int_distribution<ll>(l,r)(rnd))
#define randDouble(l,r) (uniform_real_distribution<double>(l,r)(rnd))
#define dout(d) printf("%.12f\n",d)

typedef long long ll;
typedef __int128_t lll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
template<class T>using V=vector<T>;
template<class T>using VV=V<V<T>>;
template<class T,class Y>ostream& operator<<(ostream& o,const pair<T,Y>& p){return o<<"("<<p.fi<<", "<<p.se<<")";}
template<typename A,size_t N,typename T>void Fill(A (&array)[N],const T&v){fill((T*)array,(T*)(array+N),v);}
lll gcd(lll a,lll b,lll &x,lll &y){if(!b){x=1;y=0;return a;}lll d=gcd(b,a%b,y,x);y-=a/b*x;return d;}
ll gcd(ll a,ll b){lll x=0,y=0;return gcd(a,b,x,y);}
ll modInv(ll a,ll m){lll x,y;gcd(a,m,x,y);return (x%m+m)%m;}
ll modPow(lll a,lll n,ll m){if(!a)return a;lll p=1;for(;n>0;n>>=1,a=a*a%m)if(n&1)p=p*a%m;return(ll)p;}
bool isPrime(ll n){if(n<2||n%2==0)return n==2;lll t=n-1,d=t/(t&-t);for(lll a:{2,325,9375,28178,450775,9780504,1795265022})if(a%n){for(t=d,a=modPow(a,t,n);t!=n-1&&a!=1&&a!=n-1;a=a*a%n,t=t*2%n);if(a!=n-1&&t%2==0)return 0;}return 1;}
const int IINF = 1e9+6;
const ll LINF = 1e18;
const int MOD = 1e9+7;
const double PI = acos(-1);
const double EPS = 1e-10;
static random_device rd;
static mt19937 rnd(rd());

const int N = 1e5;
const int A = 0, C = 1, G = 2, T = 3;
int n;
ll DP[4][4][4], DP2[4][4][4];
main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  cin >> n;
  DP[3][3][3] = 1;
  FOR(_, 0, n){
    FOR(i, 0, 4)FOR(j, 0, 4)FOR(k, 0, 4) DP2[i][j][k] = 0;
    FOR(i, 0, 4)FOR(j, 0, 4)FOR(k, 0, 4)FOR(l, 0, 4){
      if(
        i == A && j == G && k == C ||
        j == A && k == G && l == C ||
        j == A && i == G && k == C ||
        i == A && k == G && l == C ||
        i == A && k == G && j == C ||
        k == A && j == G && l == C ||
        i == A && j == G && l == C ||
        j == A && l == G && k == C
      ) continue;
      DP2[j][k][l] += DP[i][j][k];
    }
    FOR(i, 0, 4)FOR(j, 0, 4)FOR(k, 0, 4) DP2[i][j][k] %= MOD;
    swap(DP, DP2);
  }
  ll ans = 0;
  FOR(i, 0, 4)FOR(j, 0, 4)FOR(k, 0, 4) ans += DP[i][j][k];
  cout << ans%MOD << endl;
}

Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<string>
#include<cmath>
#include<algorithm>
#include<functional>
#include<numeric>
#include<queue>
#include<stack>
#include<map>
#include<unordered_map>
#include<set>
#include<bitset>
#include<random>
#pragma region
using namespace std;
#define FOR(i,r,n) for(ll i = (ll)(r); i < (ll)(n); i++)
#define rep(i,n) FOR(i,0LL,n)
#define RFOR(i,r,n) for(ll i=(ll)(n-1);i>=r;i--)
#define rrep(i,n) RFOR(i,0LL,n)
#define all(x) x.begin(),x.end()
#define rall(x) x.rbegin(),x.rend()
#define COUNT(a,y,x) upper_bound(all(a), y) - lower_bound(all(a), x)
#define UNIQUE(a) sort(all(a)); a.erase(unique(all(a)), a.end())
#define pb push_back
typedef long long int ll;
typedef vector<ll> vll;
typedef vector<vll> vvll;
typedef pair<ll, ll> pll;
typedef vector<pll> vpll;
typedef vector<string> vs;
typedef map<ll, ll> MAP;
const ll inf = 1LL << 61;
const ll mod = 1000000007LL;
//const ll mod = 998244353LL;

ll n = 0, m = 0, ans = 0, tmp = 0, ma = -inf, mi = inf;
string s;
ll dx[9] = { 0,1,0,-1,0,1,1,-1,-1 }, dy[9] = { 0,0,1,0,-1,1,-1,1,-1 };
#define endl '\n'
#pragma endregion
#define MAX 222222






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


  cin >> s;
  bool ok = true;
  rep(i, s.size()) {
    if (i % 2) {
      if (s[i] == 'R') ok = false;
    }
    else {
      if (s[i] == 'L') ok = false;
    }
  }

  if (ok) cout << "Yes" << endl;
  else cout << "No" << endl;




  return 0;
}


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

hoge = [0] * N

for a in A:
    for v in a:
        hoge[v-1] += 1

ans = 0
for i in hoge:
    if i == 0:
        ans += 1

print(ans)

Measured memory_bytes: 9216
#include <iostream>
#include <vector>
#include <algorithm>
#include <map>
#include <queue>
#include <string>
#include <set>
#define INF 1000000000
#define LLINF 2000000000000000
using namespace std;
#define FOR(i,a,b) for(int i=a;i<b;i++)
#define LOOP(i,N) for(int i=0;i<N;i++)
#define LOOP1(i,N) for(int i=1;i<=N;i++)
typedef pair<int,int> P;
typedef pair<int,pair<int,int> > PP;
// #define int long long

int main(){
  int m,k;
  cin >> m >> k;
  int n = 1;
  LOOP(i,m){
    n*=2;
  }
  if(n<=k){
    cout << "-1" << endl;
    return 0;
  }
  if(m==1){
    if(k==0){
      LOOP(i,n){
        cout << i << " " << i;
        if(i!=n-1)cout << " ";
      }cout << endl;
    }
    if(k==1){
      cout << "-1" << endl;
    }
    return 0;
  }
  LOOP(i,n){
    if(i!=k)cout << i << " ";
  }cout << k << " ";
  for(int i = n-1; i>=0; i--){
    if(i!=k)cout << i << " ";
  }cout << k << endl;
}


Measured memory_bytes: 1792
import java.io.*;
import java.math.*;
import java.util.*;
public class Main {
	/**/
	public static void main(String[] args) {  
		FastScanner I = new FastScanner(); //Input
		OutPut O = new OutPut(); //Output
		int N = I.nextInt();
		int[] a = new int[N];
		long ans = 0;
		for (int i = 0; i < N; i++) {
			a[i] = I.nextInt();
		}
		for (int i = 1; i < N; i++) {
			if (a[i]<a[i-1]) {
				long need = a[i-1]-a[i];
				ans+=need;
				a[i] = a[i-1];
			}
		}
		O.pln(ans);
	}
	public static long min(long a, long b) {return Math.min(a,b);}
	public static long max(long a, long b) {return Math.max(a,b);}
	public static int min(int a, int b) {return Math.min(a,b);}
	public static int max(int a, int b) {return Math.max(a,b);}
	public static long abs(long x, long y) {return Math.abs(x-y);}
	public static long ceil(long num, long den) {long ans = num/den; if (num%den!=0) 
	ans++; return ans;}
	public static long GCD(long a, long b) {
		if (a==0||b==0) return max(a,b);
		return GCD(max(a,b),max(a,b)%min(a,b));
	}
	public static long FastExp(long base, long exp, long mod) {
		long ans=1;
		while (exp>0) {
			if (exp%2==1) ans*=base;
			exp/=2;
			base*=base;
			base%=mod;
			ans%=mod;
		}
		return ans;
	}
	public static long ModInv(long num,long mod) {return FastExp(num,mod-2,mod);}
	public static int pop(long x) { //Returns number of bits within a number
		int cnt = 0;
		while (x>0) {
			if (x%2==1) cnt++;
			x/=2;
		}
		return cnt;
	}
	static class FastScanner {
		BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
		StringTokenizer st=new StringTokenizer("");
		String next() {
			while (!st.hasMoreTokens())
				try {
					st=new StringTokenizer(br.readLine());
				} catch (IOException e) {
					e.printStackTrace();
				}
			return st.nextToken();
		}
		int nextInt() {return Integer.parseInt(next());}
		long nextLong() {return Long.parseLong(next());};
		double nextDouble() {return Double.parseDouble(next());}
	}
	static class OutPut{
		PrintWriter w = new PrintWriter(System.out);
		void pln(double x) {w.println(x);w.flush();}
		void pln(boolean x) {w.println(x);w.flush();}
		void pln(int x) {w.println(x);w.flush();}
		void pln(long x) {w.println(x);w.flush();}
		void pln(String x) {w.println(x);w.flush();}
		void pln(char x) {w.println(x);w.flush();}
		void pln(StringBuilder x) {w.println(x);w.flush();}
		void pln(BigInteger x) {w.println(x);w.flush();}
		void p(int x) {w.print(x);w.flush();}
		void p(long x) {w.print(x);w.flush();}
		void p(String x) {w.print(x);w.flush();}
		void p(char x) {w.print(x);w.flush();}
		void p(StringBuilder x) {w.print(x);w.flush();}
		void p(BigInteger x) {w.print(x);w.flush();}
		void p(double x) {w.print(x);w.flush();}
		void p(boolean x) {w.print(x);w.flush();}
	}
}


Measured memory_bytes: 54448
#include <iostream>
#include <algorithm>
#include <cmath>
#include <limits>
#include <iomanip>
#include <vector>
#include <cstring>
#include <queue>
#include <map>
#define rep(i,n) for(int i=0;i<n;i++)
#define rep1(i,n) for(int i=1;i<=n;i++)
const int INF = 1e6;
using namespace std;
using ll = long long;
using ld = long double;
using ull = unsigned long long;
using uld = unsigned long long;
using P = pair<int,int>;
const ll mod = 1e9+7;
const int dx[4] = {0,1,0,-1};
const int dy[4] = {1,0,-1,0};
template<class T> inline bool chmax(T &a,T& b){if(a < b){a = b; return true;} else return false;}
template<class T> inline bool chmin(T &a,T& b){if(a > b){a = b; return true;} else return false;}
int main(){
    int l,r,d;
    cin >> l >> r >> d;
    int count=0;
    for(int i=l;i<=r;i++){
        if(i%d==0){
            count++;
        }
    }
    cout << count << endl;
}

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

#ifdef LOCAL
#define DEBUG(...) debug(#__VA_ARGS__, __VA_ARGS__);
#else
#define DEBUG(...) 6;
#endif

template<typename T, typename S> ostream& operator << (ostream &os, const pair<T, S> &p) {return os << "(" << p.first << ", " << p.second << ")";}
template<typename C, typename T = decay<decltype(*begin(declval<C>()))>, typename enable_if<!is_same<C, string>::value>::type* = nullptr>
ostream& operator << (ostream &os, const C &c) {bool f = true; os << "["; for (const auto &x : c) {if (!f) os << ", "; f = false; os << x;} return os << "]";}
template<typename T> void debug(string s, T x) {cerr << s << " = " << x << "\n";}
template<typename T, typename... Args> void debug(string s, T x, Args... args) {cerr << s.substr(0, s.find(',')) << " = " << x << " | "; debug(s.substr(s.find(',') + 2), args...);}

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    //freopen("input.txt", "r", stdin);
    //freopen("output.txt", "w", stdout);

    int n;
    string s;
    cin >> n >> s;

    int ret = 0;
    for (int i=0; i<=n-3; i++)
        ret += (s.substr(i, 3) == "ABC");

    cout << ret << "\n";

    return 0;
}


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

dp = [float("inf") for _ in range(H+1)]

dp[H] = 0

for a,b in AB:
    for h in range(H,0,-1):
        i = max(0,h-a)
        dp[i] = min(dp[i],dp[h]+b)
print(dp[0])

Measured memory_bytes: 53340
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cstring>
#include<cassert>
using namespace std;
inline int read(){
	int re=0,flag=1;char ch=getchar();
	while(!isdigit(ch)){
		if(ch=='-') flag=-1;
		ch=getchar();
	}
	while(isdigit(ch)) re=(re<<1)+(re<<3)+ch-'0',ch=getchar();
	return re*flag;
}
int n,a[200010],b[200010],na[200010],nb[200010],f[200010];
int find(int x){return ((f[x]<0)?x:f[x]=find(f[x]));}
int main(){
	n=read();int i,xa=0,xb=0,ans=0,cnt,t1,t2;
	for(i=1;i<=n;i++) xa^=(na[i]=a[i]=read());
	for(i=1;i<=n;i++) xb^=(nb[i]=b[i]=read());
	n++;
	na[n]=a[n]=xa;nb[n]=b[n]=xb;
	sort(na+1,na+n+1);sort(nb+1,nb+n+1);
	for(i=1;i<=n;i++) if(na[i]!=nb[i]){puts("-1");return 0;}
	for(i=1;i<n;i++) ans+=(a[i]!=b[i]);
	if(!ans){puts("0");return 0;}
	cnt=unique(na+1,na+1+n)-na-1;
	memset(f,-1,sizeof(f));
//	cout<<"final cnt "<<cnt<<'\n';
//	for(i=1;i<=cnt;i++) cout<<i<<' '<<a[i]<<'\n';
	for(i=1;i<=n;i++){
		a[i]=lower_bound(na+1,na+cnt+1,a[i])-na;
		b[i]=lower_bound(na+1,na+cnt+1,b[i])-na;
//		cout<<"get "<<a[i]<<' '<<b[i]<<'\n';
		t1=find(a[i]);t2=find(b[i]);
		if(t1!=t2) f[t1]+=f[t2],f[t2]=t1;
	}
	if(a[n]==b[n]&&f[find(a[n])]==-1) ans++;
	for(i=1;i<=n;i++) ans+=(f[i]<-1);
	printf("%d\n",ans-1);
}



















Measured memory_bytes: 2560
#include <bits/stdc++.h>
//#include <boost/function.hpp>
using namespace std;
typedef long long int llint;
typedef unsigned long long int ullint;
std::string YesNo[] = {"No","Yes"};
#define loop(i,N) for(int i=0; i<(N); i++)
template<typename T>
auto sort_all(T v) { return std::sort(v.begin(),v.end()); }
template<typename T>
auto sum_all(T v) { auto z = v[0]; z = 0;
    return std::accumulate(v.begin(),v.end(),z); }
template<typename T>
auto input(int N) {
    std::vector<T> v(N);
    loop(i,N) std::cin >> v[i];
    return std::move(v);
}

typedef llint dtype;

void dfs(dtype node, dtype x, dtype parent,
         vector<dtype>& result, vector<dtype>& X,
         vector<vector<dtype>>& neighbor) {
    x += X[node];
    result[node] = x;
    auto n = neighbor[node].size();
    loop(i,n) {
        auto c = neighbor[node][i];
        if(c==parent)
            continue;
        else
            dfs(c,x,node,result,X,neighbor);
    }
}

int main(void)
{
    dtype N, Q;
    cin >> N >> Q;

    auto neighbor = vector<vector<dtype>>(N);
    loop(i,N-1) {
        dtype a, b;
        cin >> a >> b;
        a--; b--;
        neighbor[a].push_back(b);
        neighbor[b].push_back(a);
    }

    auto X = vector<dtype>(N,0);
    loop(i,Q) {
        dtype p, x;
        cin >> p >> x;
        X[p-1] += x;
    }

    auto result = vector<dtype>(N,0);
    dfs(0, 0, -1, result, X, neighbor);

    loop(i, N-1) {
        cout << result[i] << " ";
    }
    cout << result[N-1] << endl;

    return 0;
}

Measured memory_bytes: 35200
//#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
#include <algorithm>
#define rep(i,n) for(int i=0;i<(n);++i)
#define all(a) (a).begin(),(a).end()
using namespace std;
using Graph = vector<vector<int>>;
typedef long long ll;
const int mod= 1e+9+7;

int main(){
    string s; cin>>s;
    rep(i,s.size()){
        if(s[i]==',')cout<<" ";
        else cout<<s[i];
    }
    cout<<endl;
}



















































Measured memory_bytes: 256
N, M = map(int, input().split())
A = []
for _ in [0]*N:
    A.append(list(input().rstrip()))
B = []
for _ in [0]*M:
    B.append(list(input().rstrip()))

def check(x, y):
    for s in range(M):
        for t in range(M):
            if A[x+s][y+t] == B[s][t]:
                continue
            else:
                return False
    return True

def main():
    for x in range(N-M+1):
        for y in range(N-M+1):
            if check(x, y):
                print('Yes')
                return
    print('No')
    return

main()

Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
//template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
//template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }

int main(void){
    string s; cin >> s;
    
    string ans = "";
    for(int i=0; i<s.size(); i++){
        if(s[i] == 'B'){
            if(ans.size()) ans = ans.substr(0, ans.size()-1);
        }
        else ans += s[i];
    }

    cout << ans << endl;
}

Measured memory_bytes: 256
import sys
import itertools
# import numpy as np
import time
import math

sys.setrecursionlimit(10 ** 7)

from collections import defaultdict

read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

n = input()
n = reversed(n)

x = 1
count = [0 for _ in range(2019)]
MOD = 2019
acc = 0
count[0] = 1
ans = 0

for c in n:
    a = x * int(c)
    acc += a
    acc %= MOD
    ans += count[acc]
    count[acc] += 1
    x = (x * 10) % MOD

print(ans)


Measured memory_bytes: 9640
#include<iostream>
#include<iomanip>

using namespace std;

long double power(int n){
  if(n == 0){return 1;}
  return 0.5 * power( n -1 );}

int main()
{ int N, K ; cin >> N >> K;
 
long double ans = 0.0;
 for(int i = 1; i <= N ; i++){ int c = i; int cnt = 0;
                              //iに何回２をかければK 以上になるかを計算
    while( c < K ){ c *= 2; cnt++;} 
                              
     ans += power(cnt);  }
  
    ans /= (long double) N;
 
 cout << setprecision(9) << ans << endl;
 
 return 0;}

Measured memory_bytes: 256
#include <bits/stdc++.h>
 using namespace std;
#define rep(i,n) for(int i=0;i<n;i++)
 int main(){
   int a,b;
   cin>>a>>b;
  if(a==b){
    cout<<"Yes"<<endl;
  }
  else{
    cout<<"No"<<endl;
  }
}

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <string>
#include <sstream>
#include <complex>
#include <vector>
#include <list>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>
#include <fstream>
#include <numeric>
using namespace std;
typedef long long int ll;

#define EPS (1e-7)
#define INF 1e18
#define max(p,q)((p)>(q)?(p):(q))
#define min(p,q)((p)<(q)?(p):(q))
#define PI (acos(-1))

#define REP(i, n) for(int i = 0; i < (int)(n); i++)
#define rep(i, init, n) for(int i = init; i <(int)(n); i++)

int main() {
    ll N;
    cin >> N;
    string c;
    cin >> c;
    c = 'R' + c + 'W';
    ll r = N + 1;
    ll l = 0;
    ll ans = 0;
    bool a = false;
    while(l < r){
        while(c[l] == 'R'){
            l++;
            if (r == l) {
                a = true;
                break;
            }  
        }
        if (a){
            break;
        }


        while(c[r] == 'W'){
            r--;
            if (r == l) {
                a = true;
                break;
            }
        }
        if (a){
            break;
        }


        c[r] = 'W';
        c[l] = 'R';
        ans++;
        if (l + 1 == r) break;

    }
    cout << ans << endl;

    return 0;
}



Measured memory_bytes: 3384
H, N = map(int, input().split())
magics = [tuple(map(int, input().split())) for _ in range(N)]
inf = 10 ** 9 + 1

"""
dp[h]: hの攻撃を与える際の、最小魔力消費量
"""
dp = [inf] * (H + 1 + 10**4)
dp[0] = 0

for h in range(H+1):
    for a, b in magics:
        dp[h + a] = min(dp[h] + b, dp[h + a])

print(min(dp[H:]))


Measured memory_bytes: 40176
s = input()
t = input()
d = len(s)-len(t)+1
max = 0
for i in range(d):
    n = 0
    for j in range(len(t)):
        if s[j+i] == t[j]:
            n += 1
    if n > max:
        max = n
print(len(t)-max)

Measured memory_bytes: 9056
using System;
public class Program {
  public static void Main() {
    int n = int.Parse(Console.ReadLine());
    int result = 0;
    for (int i = 0; i < n; i++) {
      string[] line = Console.ReadLine().Split(' ');
      result += int.Parse(line[1]) - int.Parse(line[0]) + 1;
    }
    Console.WriteLine(result);
  }
}


Measured memory_bytes: 13140
#include <bits/stdc++.h>
using namespace std;
#define reps(i, a, n) for (int i = (a); i < (n); ++i)
#define rep(i, n) reps(i, 0, n)
#define deps(i, a, n) for (int i = (a); i >= (n); --i)
#define dep(i, n) deps(i, n, 0)
#define inf 2147483647
#define int long long

signed main(void)
{
	int n; cin >> n;
	int l[105];
	rep (i, n) cin >> l[i];
	int ans = 0;
	rep (i, n - 2)
	{
		reps (j, i + 1, n - 1)
		{
			reps (k, j + 1, n)
			{
				int x[3];
				x[0] = l[i], x[1] = l[j], x[2] = l[k];
				if (x[0] == x[1] || x[0] == x[2] || x[1] == x[2]) continue;
				sort(x, x + 3);
				if (x[2] < x[0] + x[1]) ans++;
			}
		}
	}
	cout << ans << endl;
}


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

int main() {
	int N, K, ans = 0;
	cin >> N >> K;
	string S;
	cin >> S;
	for (int i = 1;i < N;i++) {
		if (S[i] == S[i - 1])ans++;
	}
	cout << min(ans + K * 2, N - 1) << endl;
}

Measured memory_bytes: 512
#include <iostream>
#include <cctype>

using namespace std;

int main(void) {
  char line[1200];
  string answer = "";
  cin.getline(line, sizeof(line));
  for(int i = 0; line[i] != '\0'; i++) {
    if(line[i] >= 'a' && line[i] <= 'z')
      answer += toupper(line[i]);
    else if(line[i] >= 'A' && line[i] <= 'Z')
      answer += tolower(line[i]);
    else
      answer += line[i];
  }
  cout << answer << endl;
  return 0;
}

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

public class Main {

  public static void main(String[] args) {
    new Main().run();
  }

  public void run() {
    
    try(BufferedReader in = new BufferedReader(new InputStreamReader(System.in))) {

      int n = Integer.parseInt(in.readLine());
      String line = in.readLine();
      int ans = 0;

      char regex = ' ';
      boolean isContinue = true;
      for(int ai=0, offset=0, next=0 ; isContinue; offset = ++next) {
        if((next = line.indexOf(regex, offset)) == -1) {
          next = line.length();
          isContinue = false;
        }

        ai = Integer.parseInt(line.substring(offset, next));
        ans += Integer.numberOfTrailingZeros(ai);
      }

      System.out.println(ans);
    }
    catch(IOException e) {
      System.err.println(e);
    }
  }
}

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

int main() {
    int n; cin >> n;
    vector<long long> t(n);
    vector<long long> a(n);

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

    for (int i = 1; i < n; i++) {
        long long tx = (t[i-1] + t[i] - 1) / t[i];
        long long ax = (a[i-1] + a[i] - 1) / a[i];
        t[i] *= max(tx, ax); a[i] *= max(tx, ax);
    }
    long long ans = t[n-1] + a[n-1];
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
using namespace std;
typedef long long ll;
#define INF 1145141919810
int main() {
	ll n,weight,dp[101][100001],w[101],v[101],ans,sumV=0;//
	cin>>n>>weight;
	for(int i=1;i<=n;i++){
      cin>>w[i]>>v[i];
      sumV+=v[i];
    }
	dp[0][0]=0;
	for(int i=1;i<=sumV;i++)dp[0][i]=INF;
	for(int i=1;i<=n;i++){
	    for(int val=0;val<=sumV;val++){
	        if(val-v[i]<0){
	            dp[i][val]=dp[i-1][val];
	        }
	        else{
	            dp[i][val]=min(dp[i-1][val-v[i]]+w[i],dp[i-1][val]);
	        }
	    }
	}
	for(int i=sumV;i>=0;i--){
	    if(dp[n][i]<=weight){
	        ans=i;
            break;
	    }
	}
	cout<<ans<<endl;
	return 0;
}


Measured memory_bytes: 79232
#include <bits/stdc++.h>
#define rep(i,n) for(ll i=0;i<(n);++i)
#define all(a) (a).begin(),(a).end()
#define rall(a) (a).rbegin(),(a).rend()
const int INF = 2e9;
using namespace std;
using Graph = vector<vector<int>>;
typedef pair<int,int> P;
typedef long long ll;

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

    if(a <= 8 && b <= 8) cout << "Yay!" << endl;
    else cout << ":(" << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define FOR(i, a, b) for (int i = (a); i <= (b); i++)
#define rep(i, n) FOR(i, 0, n - 1)
using namespace std;
typedef long long ll;
template <class T> inline bool dpmin(T &a, T b) {
  if (a > b) {
    a = b;
    return 1;
  }
  return 0;
}
template <class T> inline bool dpmax(T &a, T b) {
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}

void solve(long long A, long long P) {
    cout << (3*A + P) / 2 << endl;
}

// Generated by 1.1.7.1 https://github.com/kyuridenamida/atcoder-tools  (tips:
// You use the default template now. You can remove this line by using your
// custom template)
int main() {
  long long A;
  cin >> A;
  long long P;
  cin >> P;
  solve(A, P);
  return 0;
}


Measured memory_bytes: 3584
#include <iostream>
#include <algorithm>
#include <string>
#include <numeric>
#include <vector>
#define rep(i,n) for(int i=0;i<n;i++)
#define ll long long int
#define MAX 1000000007

using namespace std;


int main(void){
  int n,k,q;
  cin >> n >> k >> q;
  int a[n+1];
  rep(i,n) a[i+1] = 0;

  rep(i,q){
	int work;
	cin >> work;
	a[work]++;
  }

  rep(i,n){
	if(k <= q-a[i+1]) cout << "No" << endl;
	else cout << "Yes" << endl;
  }
  
  return 0;

}


Measured memory_bytes: 1024
from heapq import heappush, heappop

N = int(input())
vLst = list(map(int, input().split()))
v = []
for i in range(N):
    heappush(v, vLst[i])

ans = 0
for i in range(N - 1):
    tmp1 = heappop(v)
    tmp2 = heappop(v)
    ans = float((tmp1 + tmp2) / 2)
    heappush(v, ans)

print(v[0])

Measured memory_bytes: 3064
#include <bits/stdc++.h>
#define rep(i,a,b) for(int i=a; i< (int)(b); ++i)
#define ALL(x) (x).begin(),(x).end()
#define rALL(x) (x).rbegin(),(x).rend()
typedef long double ld;
using ll=long long;
using namespace std;
const int mod=1e9+7;
const ll inf = 1LL << 60;
const ld pi = (acos(-1));
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 main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout << fixed << setprecision(20);

  
  int a,b,k; cin >> a >> b >> k;
  vector<int> A;
  for(int i=100;i>=1;i--){
    if(a%i==0 and b%i==0) A.push_back(i);
  }
  cout << A[k-1] << endl;
}

Measured memory_bytes: 3636
#include <iostream>
#include <numeric>
#include <stdio.h>
#include <iomanip>
#include <string> // string, to_string, stoi
#include <vector> // vector
#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <utility> // pair, make_pair
#include <tuple> // tuple, make_tuple
#include <cstdint> // int64_t, int*_t
#include <cstdio> // printf
#include <map> // map
#include <queue> // queue, priority_queue
#include <set> // set
#include <stack> // stack
#include <deque> // deque
#include <unordered_map> // unordered_map
#include <unordered_set> // unordered_set
#include <bitset> // bitset
#include <cctype> // isupper, islower, isdigit, toupper, tolower
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)




int main() {
	string s,k="Yes";
	cin >> s;
	if (s == "AAA" || s == "BBB") {
		k = "No";

	}
	cout << k << endl;
}



Measured memory_bytes: 256
#include <algorithm>
#include <iostream>
#include <queue>
#include <string>
#include <vector>
#include <math.h>
#include <utility>
#include <map>
#include <queue>
#include <stack>
#include <deque>

using namespace std;

#define INF 210000000
#define int long long

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

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

signed main() {
    int n,a;
    cin >> n >> a;
    cout << n * n - a;
}


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

using namespace std;

const int inf = 2e9;

int h[100100], dp[100100];
int n, k = 2;

int main() {
	cin >> n;
	for (int i = 0; i < n; i++) cin >> h[i];
	
	for (int i = 0; i < n; i++) dp[i] = inf;
	dp[0] = 0;
	for (int i = 0; i < n; i++) {
		for (int j = i - 1; j >= i - k && j >= 0; j--) {
			dp[i] = min(dp[i], dp[j] + abs(h[i] - h[j]));
		}
	}
	
	cout << dp[n - 1] << '\n';
}


Measured memory_bytes: 1024
#include<bits/stdc++.h>
#define rep(i,n) for(int i = 0;i<n;i++)
using namespace std;
using ll = long long;
int main(){
	int n,sum=0;
  cin >> n;
  for(int i = 1;i<=n;i++){
  	if(1 <= i && i <= 9 || 100 <= i&& i <= 999 || 10000 <= i && i <= 99999)sum++;
  }
  cout << sum <<endl;
  return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define fastio() ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define ll long long
#define ull unsigned long long
#define vi vector<int>
#define pi pair<int, int>
#define F first
#define S second
#define PB push_back
#define MP make_pair
#define deb(x) cout << #x << ":" << x << endl;
/* freopen("input.txt", "r", stdin); */
/* freopen("output.txt", "w", stdout); */
const ll inf = 1e17 + 7, MOD = 1e7 + 9;


int main() {
	fastio();
	map<int, int> m;
	int n;
	cin >> n;
	int a;
	for(int i=0;i<n-1;i++) {
		cin >> a;
		m[a]++;
	}
	for(int i=1;i<=n;i++) {
		cout << m[i] << "\n";
	}
	return 0;
}


Measured memory_bytes: 13024
#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 INF 2e9
#define ALL(v) (v).begin(), (v).end()
using namespace std;
typedef long long ll;
int GCD(int a,int b){return b?GCD(b,a%b):a;}
int LCM(int a,int b){return (a*b)/GCD(a,b);}
int abs(int x){return x>0?x:-x;}
 
//const int dx[] = {1, 0, -1, 0, 1, -1, -1, 1};
//const int dy[] = {0, 1, 0, -1, 1, 1, -1, -1};

int main()
{
	int n;
	cin >> n;
	int a[n];
	int ans = 0;
	REP(i, n) cin >> a[i];

	REP(i, n){
		bool flag = 1;
		REP(j, i){
			if (a[i] < a[j]) flag = 0;
		}
		if (flag) ans++;
	}

	cout << ans << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define fastIO ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
typedef long long ll;

int main()
{
	fastIO;
	string s,t;
	cin >> s >> t;
	int n = s.length();
	int m = t.length();
	int ans = INT_MAX;
	int cnt=0;
	for (int i=0; i<=n-m; i++) {
		cnt = 0;
		for (int j=i; j<i+m; j++) {
			if (s[j] != t[j-i]) cnt++;
		}
		ans = min(ans, cnt);
	}
	cout << ans << '\n';
}

Measured memory_bytes: 3660
#include <iostream>
#include <string>
#include <map>
#include <vector>
#include <bitset>
#include <iomanip>
#include <deque>
#include <tuple>
#include <algorithm>

using namespace std;

int main()
{
    string a, b, c;

    cin >> a >> b >> c;

    a[0] -= 0x20; b[0] -= 0x20; c[0] -= 0x20;

    cout << a[0] << b[0] << c[0] << endl;
}


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

int main(){
  int N ; cin >> N ; 
  vector<long long> a(N) ; 
  for(int i = 0 ; i < N ; i++) cin >> a.at(i) ; 
  
  if(N %2 == 0 ){
    for(int i = N-1 ; i >= 0  ; i -= 2){
      cout << a.at(i) << " " ;  
    }
    for(int i = 0 ; i < N ; i+=2){
      cout << a.at(i) << " " ; 
    }
  }
  else{
     for(int i = N-1 ; i >= 0   ; i -= 2){
       cout << a.at(i) << " " ;  
     }
     for(int i = 1 ; i < N ; i+=2){
       cout << a.at(i) << " " ; 
     }
  }
  cout << endl; 
  return 0 ; 
}

Measured memory_bytes: 4788
K, A, B = list(map(int, input().split()))
if B < A + 2:
    print(1 + K)
else:
    x = 1
    k = K
    if k >= A - 1:
        k -= A - 1
        x += A - 1
    z = k // 2
    k -= z * 2
    x += (B - A) * z
    if k == 1:
        x += 1
    print(x)


Measured memory_bytes: 3060
n, a, b = map(int, input().split())

def calc_sum(n):
    dr = 0
    while(True):
        dr += n % 10
        n = n // 10
        if n == 0:
            break
    return dr

count = 0
for i in range(1, n + 1):
    sum = calc_sum(i)
    if (a <= sum) and (b >= sum):
        count += i

print(count) 



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

const int MXN=200005;
const int MOD=1e9+7;
int add(int x,int y){return(x+=y)<MOD?x:x-MOD;}
int sub(int x,int y){return(x-=y)>= 0?x:x+MOD;}
int mul(int x,int y){return(ll)x*y%MOD;}
int pwr(int x,int p){
  if(p==0)return 1;
  if(p%2)return mul(x,pwr(x,p-1));
  return pwr(mul(x,x),p/2);
}
int inv(int x){return pwr(x,MOD-2);}

int n,m,k;
int dp[3005];
int fact[MXN];
int invf[MXN];
array<int,2>blk[MXN];

int bc(int n,int k){
  int den=mul(invf[n-k],invf[k]);
  return mul(fact[n],den);
}

int main(){
  scanf("%d%d%d",&n,&m,&k);
  fact[0]=invf[0]=1;
  for(int i=1;i<=n+m;++i){
    fact[i]=mul(fact[i-1],i);
  }
  invf[n+m]=inv(fact[n+m]);
  for(int i=n+m-1;i;--i){
    invf[i]=mul(invf[i+1],i+1);
  }
  for(int i=0;i<k;++i){
    scanf("%d",&blk[i][0]);blk[i][0]--;
    scanf("%d",&blk[i][1]);blk[i][1]--;
  }
  sort(blk,blk+k);
  blk[k]={n-1,m-1};
  for(int i=0;i<=k;++i){
    int r=blk[i][0];
    int c=blk[i][1];
    dp[i]=bc(r+c,c);
    for(int j=0;j<i;++j){
      if(blk[j][0]>r)continue;
      if(blk[j][1]>c)continue;
      int dr=r-blk[j][0];
      int dc=c-blk[j][1];
      dp[i]=sub(dp[i],mul(dp[j],bc(dr+dc,dc)));
    }
  }
  printf("%d\n",dp[k]);
}


Measured memory_bytes: 1792
//BISMILLAHIR RAHMANIR RAHIM
#include <bits/stdc++.h>
#define mem(a, b) (memset(a, b, sizeof(a)))
#define pb push_back
#define mk make_pair
#define ff first
#define ss second
#define PI acos(-1)
#define INF 2147483647
#define MOD 1000000007
#define MAX 200005
using namespace std;

typedef long long ll;
typedef vector<int> vi;
typedef pair<int, int> ii;
typedef pair<int, ii> pii;
typedef vector<ii> vii;
typedef priority_queue<int,vector<int>,greater<int> > PQ;

int Set(int mask, int pos){return mask = mask | (1<<pos);}
bool check(int mask, int pos){return (bool)(mask & (1<<pos));}

int main()
{
    ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
    ll x;

    cin>>x;

    int ans = -1;
    ll t = x, tx = 7;
    for(int i = 0; i < x; i++) {
        t = tx % x;
        //cout<<t<<" "<<tx<<endl;
        if(t == 0) {
            ans = i + 1;
            break;
        }
        tx = (t * 10 + 7);
    }

    cout<<ans<<endl;

    return 0;
}



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

import sys
sys.setrecursionlimit(10**7)
from pprint import pprint as pp
from pprint import pformat as pf

import math
#from sortedcontainers import SortedList, SortedDict, SortedSet # no in atcoder
import bisect


def choice(n, k):
    #print('n, k') # debug
    #print(n, k) # debug
    max_value = ((n - k + 1) + n) * k // 2
    min_value = (0 + (k - 1)) * k // 2
    c = max_value - min_value + 1
    #print('max_value, min_value, c') # debug
    #print(max_value, min_value, c) # debug
    return c

if __name__ == '__main__':
    n, k = list(map(int, input().split()))
    ans = 0
    for kk in range(k, n + 1 + 1):
        ans += choice(n, kk)
    mod = 10 ** 9 + 7
    print(ans % mod)

    #print('\33[32m' + 'end' + '\033[0m') # debug


Measured memory_bytes: 68780
N=int(input())
TXY=[list(map(int,input().split())) for i in range(N)]

Next=TXY.pop(0)
Flag=1

for i in range(N):
    D=Next[0]-abs(Next[1])-abs(Next[2])
    if D<0 or D%2!=0:
        Flag=0
        break
    else:
        if TXY==[]:
            break
        else:
            Next2=TXY.pop(0)
            Next=[Next2[0]-Next[0],Next2[1]-Next[1],Next2[2]-Next[2]]

print(['No','Yes'][Flag])

Measured memory_bytes: 27380
a, b, c, k = list(map(int, input().split()))

ans = 0

if k > a:
  ans = a * 1
  k = k - a
  if k > b:
    ans += b * 0
    k = k - b
    ans += k * -1
    print(ans)
  elif k <= b:
    ans += k * 0
    print(ans)
elif k <= a:
  ans = k * 1
  print(ans)
      
    



Measured memory_bytes: 9192
#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <stack>
#include <queue>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>

using namespace std;

typedef long long ll;
typedef unsigned long long ull;

static const double EPS = 1e-8;
static const double PI = 4.0 * atan(1.0);
static const double PI2 = 8.0 * atan(1.0);

#define REP(i,n)	for(int i=0;i<(int)n;++i)
#define ALL(c)		(c).begin(),(c).end()
#define CLEAR(v)	memset(v,0,sizeof(v))
#define MP(a,b)		make_pair((a),(b))
#define ABS(a)		((a)>0?(a):-(a))
#define FOR(i,s,n)	for(int i=s;i<(int)n;++i)

#define YES "YES"
#define NO "NO"

ll n, a, b, c, d;

int main(int argc, char **argv) {
	cin >> n >> a >> b >> c >> d;
	ll l = 1 - n, h = n, t = b - a;
	while (true) {
		ll m = (l + h) / 2, m2 = n - 1 - m;
		if (m * c - m2 * d <= t && t <= m * d - m2 * c) {
			cout << YES << endl;
			return 0;
		}
		else if (t < m * c - m2 * d) {
			if (m == l) break;
			h = m;
		}
		else {
			if (m == l) break;
			l = m + 1;
		}
	}
	cout << NO << endl;
	return 0;
}


Measured memory_bytes: 256
import scala.collection.mutable
import scala.io.StdIn.readLine

object Main extends App {

  var h = readLine().toLong
  val m = mutable.Map[Long, Long]()

  def go(hp: Long): Long = hp match {
    case 0 => 0
    case 1 => 1
    case _ => {
      val p = hp / 2
      val q = m.get(p) match {
        case Some(value) => value
        case None =>
          val y = go(p)
          m + (p -> y)
          y
      }
      q * 2 + 1
    }
  }

  println(go(h))
}


Measured memory_bytes: 27084
#include<bits/stdc++.h>
using namespace std;
int n,x,ans;
string s;
int main(){
    cin>>n>>s;
    for (int i=0;i<n;i++){
        if (s[i]=='I') x++;
        if (s[i]=='D') x--;
        if (x>ans) ans=x;
    }
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 256