akhauriyash/Code-Regression huggingface dataset:
package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
)

func out(x ...interface{}) {
	fmt.Println(x...)
}

var sc = bufio.NewScanner(os.Stdin)

func getInt() int {
	sc.Scan()
	i, e := strconv.Atoi(sc.Text())
	if e != nil {
		panic(e)
	}
	return i
}

func getString() string {
	sc.Scan()
	return sc.Text()
}

func main() {
	sc.Split(bufio.ScanWords)

	N, A, B := getInt(), getInt(), getInt()
	x := make([]int, N)
	for i := 0; i < N; i++ {
		x[i] = getInt()
	}

	cost := 0
	for i := 1; i < N; i++ {
		diff := (x[i] - x[i-1]) * A
		if diff > B {
			cost += B
		} else {
			cost += diff
		}
	}

	out(cost)
}


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

int main() {
  int A, B;
  string S;
  cin >> A >> B >> S;

  if (S[A] != '-') {
    cout << "No" << endl;
  } else {
    string a = S.substr(0, A);
    string b = S.substr(A+1, B);
    if (a.find('-') == -1 && b.find('-') == -1)
      cout << "Yes" << endl;
    else
      cout << "No" << endl;
  }

  return 0;
}


Measured memory_bytes: 256
q,h,s,d = map(int, input().split())
n = int(input())
q_cp=q*4
h_cp=h*2
s_cp=s
d_cp=d/2

vals = [[q_cp,0.25],[h_cp,0.5],[s_cp,1],[d_cp,2]]
vals.sort()

if vals[0][1] <= 1:
        print(n * vals[0][0])
else:
        ans=d*(n//2)
        if n%2==0:
                print(ans)
        else:
                ans+=vals[1][0]
                print(ans)

Measured memory_bytes: 3064
#include <algorithm>
#include <cassert>
#include <cmath>
#include <cstdio>
#include <deque>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>
using std::cerr;
using std::cin;
using std::cout;
using std::endl;

template <int64_t n>
struct Matrix{
  int64_t v[n][n]={};
  int64_t m;
  Matrix operator*(const Matrix& another)const{
    Matrix<n> result;
    result.m=this->m;
    for(int r=0;r<n;r++){
      for(int c=0;c<n;c++){
        for(int k=0;k<n;k++){
          result.v[r][c]+=v[r][k]*another.v[k][c];
          if(result.v[r][c]!=0){
            result.v[r][c]%=m;
          }

        }
      }
    }
    return result;
  }
};

template<int64_t n>
Matrix<n> RepeatedPow(const Matrix<n>& base, int exponent){
  if(exponent==1){
    return base;
  }else if(exponent%2==0){
    Matrix<n> tmp=RepeatedPow(base,exponent/2);
    return tmp*tmp;
  }else{
    Matrix<n> tmp=RepeatedPow(base,exponent/2);
    return tmp*tmp*base;
  }
}

std::vector<int64_t> Solve(const int n,const int m,int a,int b,int c,int t){
  std::vector<int64_t> vec(n);
  for(int i=0;i<n;i++){
    cin>>vec[i];
  }
  Matrix<50> opr;
  opr.m=m;
  opr.v[0][0]=b;opr.v[1][0]=c;
  for(int ci=1;ci<n-1;ci++){
    opr.v[ci-1][ci]=a;
    opr.v[ci][ci]=b;
    opr.v[ci+1][ci]=c;
  }
  opr.v[n-2][n-1]=a;opr.v[n-1][n-1]=b;
  if(t==0){
    return vec;
  }
  Matrix<50> opr_final=RepeatedPow(opr,t);
  Matrix<50> base;
  for(int r=0;r<n;r++){
    for(int ci=0;ci<n;ci++){
      base.v[r][ci]=vec[ci];
    }
  }
  base.m=m;
  base=base*opr_final;
  std::vector<int64_t> result(n);
  for(int i=0;i<n;i++){
    result[i]=base.v[0][i];
  }
  return result;

}

int main(void) {
  cout << std::fixed << std::setprecision(10);
  cin.tie(0);
  std::ios::sync_with_stdio(false);

  while(true){
    int n,m,a,b,c,t;
    cin>>n>>m>>a>>b>>c>>t;
    if(n==0) break;
    std::vector<int64_t> result=Solve(n,m,a,b,c,t);
    for(int i=0;i<n-1;i++){
      cout<<result[i]<<" ";
    }
    cout<<result[n-1]<<endl;
  }

  return 0;
}



Measured memory_bytes: 4340
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
#define pb push_back
#define mp make_pair
#define f first
#define s second
#define sc(n) scanf("%d",&n)
#define scl(n) scanf("%lld",&n)
#define pr(n) printf("%d",n)
#define prl(n) printf("%lld",n)
#define nl printf("\n")
#define fast_io ios_base::sync_with_stdio(false);cin.tie(NULL)
ll pow1(ll a, ll b)
{
	ll ans=1;
	while(b)
	{
		if(b&1)
		{
			ans=ans*a;
		}
		a=a*a;
		b=b>>1;
	}
	return ans;
}
int main()
{
	int i,j;
	int a,b;
	cin>>a>>b;
	if(b == 1)
	{
		cout<<0<<endl;
		return 0;
	}
	int ans = 0,cnt = 0;
	while(cnt<b)
	{
		cnt += a;
		ans++;
		if(cnt<b)
			cnt--;
	}
	cout<<ans<<endl;
	return 0;
}

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

using namespace std;
using ll = long long;
#define int ll
using VI = vector<int>;
using VVI = vector<VI>;
using PII = pair<int, int>;

#define FOR(i, a, n) for (ll i = (ll)a; i < (ll)n; ++i)
#define REP(i, n) FOR(i, 0, n)
#define ALL(x) x.begin(), x.end()
#define PB push_back

const ll LLINF = (1LL<<60);
const int INF = (1LL<<30);
const int MOD = 1000000007;

template <typename T> T &chmin(T &a, const T &b) { return a = min(a, b); }
template <typename T> T &chmax(T &a, const T &b) { return a = max(a, b); }
template <typename T> bool IN(T a, T b, T x) { return a<=x&&x<b; }
template<typename T> T ceil(T a, T b) { return a/b + !!(a%b); }
template<class S,class T>
ostream &operator <<(ostream& out,const pair<S,T>& a){
  out<<'('<<a.first<<','<<a.second<<')';
  return out;
}
template<class T>
ostream &operator <<(ostream& out,const vector<T>& a){
  out<<'[';
  REP(i, a.size()) {out<<a[i];if(i!=a.size()-1)out<<',';}
  out<<']';
  return out;
}

// 下、右、上、左
int dx[] = {0, 1, 0, -1}, dy[] = {1, 0, -1, 0};

int d[55][55][4][4];
signed main(void)
{
  cin.tie(0);
  ios::sync_with_stdio(false);

  int h, w;
  cin >> h >> w;
  h += 2, w += 2;
  vector<string> s(h);
  s[0] = s[h-1] = string(w, '#');
  FOR(i, 1, h-1) {
    cin >> s[i];
    s[i] = "#" + s[i] + "#";
  }

  int sx=-1, sy=-1, sdir=-1, gx=-1, gy=-1;
  REP(i, h) REP(j, w) {
    if(s[i][j] == 'v') {
      sdir = 0, sx = j, sy = i;
    } else if(s[i][j] == '>') {
      sdir = 1, sx = j, sy = i;
    } else if(s[i][j] == '^') {
      sdir = 2, sx = j, sy = i;
    } else if(s[i][j] == '<') {
      sdir = 3, sx = j, sy = i;
    } else if(s[i][j] == 'G') {
      gx = j, gy = i;
    }
  }

  VVI used(h, VI(w, 0));
  int x = sx, y = sy, dir = sdir, cnt = 0;
  while(x!=gx||y!=gy) {
    // cout << x << " " << y << " " << dir << endl;
    used[y][x] = 1;
    int tmpx = x + dx[(dir+3)%4], tmpy = y + dy[(dir+3)%4];
    bool right = s[tmpy][tmpx]=='#';
    tmpx = x + dx[dir], tmpy = y + dy[dir];
    bool front = s[tmpy][tmpx]=='#';
    tmpx = x + dx[(dir+1)%4], tmpy = y + dy[(dir+1)%4];
    bool left = s[tmpy][tmpx]=='#';
    if(!right) {
      // cout << "r" << endl;
      dir = (dir+3)%4, x += dx[dir], y += dy[dir];
    } else if(right && !front) {
      // cout << "f" << endl;
      x += dx[dir], y += dy[dir];
    } else if(!left) {
      // cout << "l" << endl;
      dir = (dir+1)%4, x += dx[dir], y += dy[dir];
    } else {
      dir = (dir+2)%4, x += dx[dir], y += dy[dir];
    }
    cnt++;
    if(cnt > 20000) {
      cout << -1 << endl;
      return 0;
    }
  }

  int ans = 1;
  REP(i, h) REP(j, w) ans += used[i][j];
  cout << ans << endl;

  return 0;
}



Measured memory_bytes: 3268
#include <stdio.h>
#include <string.h>

int main() {
	char s[10];
	scanf("%s", s);
	int n = strlen(s);
	int t = 0, ans = 0;
	for (int i = 0; i < n; i++) {
		if (s[i] == 'A' || s[i] == 'T' || s[i] == 'C' || s[i] == 'G') {
			t++;
			if (ans < t)ans = t;
		}
		else {
			t = 0;
		}
	}
	printf("%d", ans);
	return 0;
}

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

const int N=500005,INF=0x3f3f3f3f;
int n,a[N],dp[N],len,ans[N];
int v[N],nxt[N],head[N];

void dfs(int x,int fa)
{
//	cout<<x<<' '<<fa<<endl;
	int L=1,R=n,id,ls;
	while(L<=R)
	{
		int mid=(L+R)>>1;
		if(dp[mid]<a[x]) L=mid+1;
		else id=mid,R=mid-1;
	}
	ls=dp[id],dp[id]=a[x];
	if(ls==INF) len++;
	ans[x]=len;
	for(int i=head[x];i>0;i=nxt[i])
	{
		if(v[i]==fa) continue;
		dfs(v[i],x);
	}
	dp[id]=ls;
	if(ls==INF) len--;
}

int main()
{
	memset(dp,0x3f,sizeof(dp));
	scanf("%d",&n);
	for(int i=1;i<=n;i++) scanf("%d",&a[i]);
	for(int i=1;i<n;i++)
	{
		scanf("%d%d",&v[i],&v[i+n]);
		nxt[i]=head[v[i+n]],head[v[i+n]]=i;
		nxt[i+n]=head[v[i]],head[v[i]]=i+n;
	}
	dfs(1,0);
	for(int i=1;i<=n;i++) printf("%d\n",ans[i]);
}

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

using namespace std;

#define dump(n) cout<<"# "<<#n<<"="<<(n)<<endl
#define debug(n) cout<<__FILE__<<","<<__LINE__<<": #"<<#n<<"="<<(n)<<endl
#define repi(i,a,b) for(int i=int(a);i<int(b);i++)
#define rep(i,n) repi(i,0,n)
#define iter(c) __typeof((c).begin())
#define foreach(i,c) for(iter(c) i=(c).begin();i!=(c).end();i++)
#define allof(c) (c).begin(),(c).end()
#define mp make_pair

typedef unsigned int uint;
typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<string> vs;
typedef pair<int,int> pii;

int fairfield(int y,int m,int d)
{
	if(m<=2){
		y--;
		m+=12;
	}
	return 365*y+y/4-y/100+y/400+153*(m+1)/5+d-428;
}

int main()
{
	int meiji=fairfield(1868,9,8),
		taisho=fairfield(1912,7,30),
		showa=fairfield(1926,12,25),
		heisei=fairfield(1989,1,8);
	
	for(int y,m,d;cin>>y>>m>>d;){
		int ff=fairfield(y,m,d);
		if(heisei<=ff)
			printf("heisei %d %d %d\n",y-1988,m,d);
		else if(showa<=ff)
			printf("showa %d %d %d\n",y-1925,m,d);
		else if(taisho<=ff)
			printf("taisho %d %d %d\n",y-1911,m,d);
		else if(meiji<=ff)
			printf("meiji %d %d %d\n",y-1867,m,d);
		else
			puts("pre-meiji");
	}
	
	return 0;
}

Measured memory_bytes: 0
#include <iostream>
#include <stack>
#include <vector>

using namespace std;

int
main(int argc, const char *argv[])
{
    char c;
    stack<int> S1;
    stack<pair<int, int>> S2;
    int s = 0;
    for (int i = 0; cin >> c; ++i) {
        if (c == '\\') S1.push(i); 
        else if (c == '/' && !S1.empty()) {
            int j = S1.top();
            S1.pop();
            s += i - j;
            int e = i - j;
            while (!S2.empty() && S2.top().first > j) {
                e += S2.top().second;    
                S2.pop();
            }
            S2.push(make_pair(j, e));
        }
    }
    vector<int> vi;
    while (!S2.empty()) {
        vi.push_back(S2.top().second);
        S2.pop();
    }
    cout << s << endl;
    cout << vi.size();
    for (auto iter = vi.crbegin(); iter != vi.crend(); ++iter) {
        cout << " " << *iter;
    }
    cout << endl;

    return 0;
}

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

int a,b,c,x;
int sum=0;
 
int main() {
  cin>>a>>b>>c>>x;
  
  for(int i=0;i<=a;i++){
    for(int k=0;k<=b;k++){
        for(int t=0;t<=c;t++){
          int total = 500*i+100*k+50*t;
          if(total==x)
            sum++;
        }
    }
  }
  cout<<sum<<endl;
          

  

}


Measured memory_bytes: 256
#include <stdio.h>

int main()
{
  int n;
  int arr[10000];
  int b, s;
  long long t=0;
  scanf("%d", &n);
  for(int i = 0; i < n; i++)
    {
      scanf("%d", &arr[i]);
      if(i == 0)
	{
	  b = arr[0];
	  s = arr[0];
	}
      if(arr[i] > b)
	{
	  b = arr[i];
	}
      if(arr[i] < s)
	{
	  s = arr[i];
	}
      t += arr[i];
    }
  printf("%d %d %lld\n", s, b, t);
}



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

int main()
{
    string s;
    cin >> s;
    int n = s.length() + 1;
    vector<int> a(n);

    for (int i = 0; i <= n - 2; i++)
    {
        if (s[i] == '<')
            a[i + 1] = a[i] + 1;
    }

    for (int i = n - 2; i >= 0; i--)
    {
        if (s[i] == '>')
            a[i] = max(a[i + 1] + 1, a[i]);
    }

    ll ans = 0;
    rep(i, n) ans += a[i];
    cout << ans << endl;
}

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

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

if (b < a) {
temp = a;
a = b;
b = temp;
} if (c < b) {
temp = b;
b = c;
c = temp;
} if (b < a) {
temp = a;
a = b;
b = temp;
}
cout <<a << " " << b << " " << c << endl;
return 0;
}



Measured memory_bytes: 3068
import java.util.*;

public class Main {
  public static void main(String[] args) throws Exception {
    Scanner sc = new Scanner(System.in);
    int num   = sc.nextInt();
    int day   = sc.nextInt();
    int choco = sc.nextInt();
    int eat   = 0;
    
    for(int i = 0 ; i < num ; i++){
      int element = sc.nextInt();
      for(int j = 0 ; j < day ; j++){
        int ans = j * element + 1;

        if(ans <= day){
          eat++;
        }else{
          continue;
        }
      }
    }
    System.out.println(eat + choco);
  }
}

Measured memory_bytes: 21716
import java.util.Scanner;

public class Main {
    public static void main(String args[]) {
        try (Scanner in = new Scanner(System.in)) {
            int N = in.nextInt();
            int M = in.nextInt();

            int NminusM = N - M;

            int timePer1submission = 1900 * M + 100 * NminusM;
            int bunbo = 1 << M;

            double sum = timePer1submission;
            for (double probability = (1.0 - 1.0 / bunbo); probability >= 1e-99; probability *= (1.0 - 1.0 / bunbo)) {
                sum += timePer1submission * probability;
            }

            System.out.println("" + ((int) (sum + 1e-9)));
        }
    }
}


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

// #include <atcoder/all>
// using namespace atcoder;

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


void solve(long long K){
    rep(i, K) cout << "ACL";
    cout << endl;
}

// Generated by 1.1.7.1 https://github.com/kyuridenamida/atcoder-tools
int main(){
    long long K;
    scanf("%lld",&K);
    solve(K);
    return 0;
}


Measured memory_bytes: 3652
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
using ll = long long;
using namespace std;
int main()
{
    string s;
    int n,m;
    cin >> s;
    n = s.length();
    m = (n - 1) / 2; 

    rep(i, n) {
        if (s[i] != s[n-i-1]) {
            cout << "No" << endl;
            return 0;
        }
    }
    rep(i, m) {
        if (s[i] != s[m - i - 1]) {
            cout << "No" << endl;
            return 0;
        }
    }
    rep(i, m) {
        if (s[m+1+i] != s[n - 1 - i]) {
            cout << "No" << endl;
            return 0;
        }
    }
    cout << "Yes" << endl;
    return 0;
}


Measured memory_bytes: 256
#pragma GCC optimize ("O3")
#include <bits/stdc++.h>
using namespace std;
#define MuhammedAly ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define all(x) (x).begin(),(x).end()
#define allr(x) (x).rbegin(),(x).rend()
#define pb push_back
#define eb emplace_back
#define popc(x) __builtin_popcount(x)
#define LLMX 1e18
#define NotinRange(n,m) i<0||i>=(n)||j<0||j>=(m)
#define mem(x,y) memset((x),(y),sizeof (x))
#define sz(a) (int)(a).size()
#define inFile(s) freopen((s),"r",stdin)
#define	outFile(s) freopen((s),"w",stdout)
#define biEdge(v, a, b) (v)[(a)].pb((b)), (v)[(b)].pb((a))
#define pi (2 * acos(0))
#define X real()
#define Y imag()
#define cross(a, b) ((conj(a) * (b)).Y)
#define dot(a, b) ((conj(a) * (b)).X)
#define vec(a,b) ((b) - (a))
#define ll long long
typedef long double ld;
typedef complex<double>point;
typedef tuple<int, int, int> line;
typedef pair<point, point>segment;
typedef vector<point>polygon;
const int N = 1e5 + 5, M = 20 + 5, OO = 0x3f3f3f3f, mod = 1e9 + 7, base = 131, mod2 = 1000136437, mod3 = 998244353;
const double EPS = 1e-9;
ll n, w, memo[105][N], W[105], v[105], sum;
ll solve(int i, int V)
{
    if(V == 0)
        return 0;
    if(i == n)
        return LLMX;
    ll &ret = memo[i][V];
    if(~ret)
        return ret;
    ret = solve(i + 1, V);
    if(V - v[i] >= 0)
        ret = min(ret, solve(i + 1, V - v[i]) + W[i]);
    return ret;
}
int main()
{
    MuhammedAly
    mem(memo, -1);
    cin >> n >> w;
    for(int i = 0 ; i < n ;i++)
        cin >> W[i] >> v[i], sum += v[i];
    for(int i = sum ; ~i ; i--)
        if(solve(0, i) <= w)
            return cout << i, 0;
    return 0;
}

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

vector<ll> f;

ll add(ll a,ll b){ return (a+b)%mod;}

ll sub(ll a,ll b){ return (a-b)%mod;}

ll mul(ll a,ll b){ return (a*b)%mod;}

ll power(ll n, ll r){
    if(r==0) return 1;
    return mul(power(mul(n,n),r/2),(r&1 ? n : 1));
}

ll divm(ll a,ll b){ return mul(a, power(b, mod-2));}

ll fact(ll n){
    if(f[n]) return f[n];
    if(n==0) return 1;
    return f[n] = mul(n,fact(n-1));
}

ll com(ll n,ll r){
    if(n<r) return 0;
    return divm(fact(n),mul(fact(n-r),fact(r)));
}

int main(void){
    ll N,A,B,K;
    cin>>N>>A>>B>>K;
    f.resize(N+1);
    ll res = 0;
    rep(a,N+1){
        if(A*a > K) break;
        if((K-A*a)%B == 0){
            ll b = (K-A*a)/B;
            res = add(res,mul(com(N,a),com(N,b)));
        }
    }
    cout<<res<<endl;

    return 0;
}


Measured memory_bytes: 11904
#include<bits/stdc++.h>
using namespace std;
int main(){
  int n,c=0;
  cin>>n;
  int a[n+2];
  a[0]=a[n+1]=0;
  for(int i=1;i<=n;i++){
    cin>>a[i];
    c+=abs(a[i]-a[i-1]);
  }
  c+=abs(a[n+1]-a[n]);
  for(int i=1;i<=n;i++){
    if(a[i]<=a[i-1]&&a[i]>=a[i+1]||a[i]<=a[i+1]&&a[i]>=a[i-1]){
      cout<<c<<endl;
    }else{
      cout<<c-(abs(a[i]-a[i-1])+abs(a[i]-a[i+1]))+(abs(a[i+1]-a[i-1]))<<endl;
    }
  }
}

Measured memory_bytes: 1664
#include<stdio.h>

int main(){

long int n,i,c;
c=0;
scanf("%ld",&n);
long int a[n+1],b[n];
  for(i=0;i<n+1;i++){
  scanf("%ld ",&a[i]);
  }
 for(i=0;i<n;i++){
  scanf("%ld ",&b[i]);
  }

for(i=0;i<n;i++){
  if(a[i]==b[i]||a[i]>b[i]){c+=b[i];}
  else{
    long int p=a[i+1];
    a[i+1]=a[i+1]-(b[i]-a[i]);
    if(a[i+1]<0){
      
      c+=a[i]+p;
      a[i+1]=0;
    }
    else
    {c+=b[i];
    }
  }
}
    
  printf("%ld",c);
    
    
    
      
   
  
return 0;

}


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

using namespace std;

using ll = long long;

int main() {
    string S, T;
    cin >> S >> T;
    int ans = 0;
    for (int i = 0; i < S.size(); ++i) {
        ans += (S[i] != T[i]);
    }
    cout << ans << endl;
    return 0;
}



Measured memory_bytes: 3916
#include <bits/stdc++.h>
using namespace std;
 
int main() {
string o, e;
cin >> o >> e;
string out;
    for(int i = 0; i < o.size(); ++i){
        out += o.at(i);
        if(i != o.size()-1 || o.size() == e.size())out += e.at(i);
    }
    cout << out << endl;
}


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

using namespace std;

#define INF 999999999

int main(){
	int i, j, q, n;
	int ans;
	
	cin >> q; 
	for(i=0;i<q;i++){
		ans = 0;
		cin >> n;
		while(n>=10){
			ans++;
			int mo=0;
			//cout << n << endl;
			for(j=1;n/pow(10,j)>0;j++){
				if(mo<(n/(int)pow(10,j))*(n%(int)(pow(10,j)))){
					mo = (n/(int)pow(10,j))*(n%(int)(pow(10,j)));
				}
			}
			n = mo;
		}
		cout << ans << endl;
	}
	return 0;
}

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

#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define repr(i,n) for(int i=n;i>=0;i--)
#define FOR(i,m,n) for(int i=m;i<(int)(n);i++)
#define INF 999999999

    /*Solve*/
int main(){
    ll n,a,b;
    cin >> n >> a >> b;
    ll ans1;
    if(n<a+b){
        ans1=abs(n-(a+b));
    }else ans1=0;
    cout << min(a,b) << " " << ans1;
}

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

using namespace std;

#define FOR(k,a,b) for(int k=(a); k < (b); k++)
#define FORE(k,a,b) for(int k=(a); k <= (b); k++)
#define REP(k,a) for(int k=0; k < (a); k++)

#define ALL(c) (c).begin(), (c).end()
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define RANGE(lb, x, ub) ((lb) <= (x) && (x) < (ub))

#define dump(x) cerr << #x << ": " << (x) << endl;

typedef long long ll;
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;

const int INF = 1000000000;
const double EPS = 1e-10;
const double PI = acos(-1.0);

int main(void) {
    int a, p;
    cin >> a >> p;
    printf("%d\n", (3 * a + p) / 2);
    return 0;
}


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

typedef struct {
	int a;
	int b;
}job_t;

int cmp(const void* p, const void* q) {
	return ((job_t*)p)->b - ((job_t*)q)->b;
}

int main(void) {
	int n;
	job_t job[200000] = { 0 };
	int total = 0;

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

	qsort(job, n, sizeof(job_t), cmp);
	//for (int i = 0; i < n; i++)printf("job[%d].b=%d\n", i, job[i].b);
	for (int i = 0; i < n; i++) {
		total += job[i].a;
		//printf("total=%d job[i].b=%d\n", total, i, job[i].b);
		if (total > job[i].b) {
			printf("No");
			break;
		}
		else if (i == n - 1) {
			printf("Yes");
		}
	}
	return 0;
}


Measured memory_bytes: 3324
#input()
X=int(input())
#A,B=map(int,input().split())
#list(map(int,input().split()))
#[input() for i in range(N)]

import math
m = 100
cnt = 0
while m<X:
    a = math.floor(m*0.01)
    m += a
    cnt += 1
print(cnt)


Measured memory_bytes: 9160
#include<iostream>
#include<string>
#include<algorithm>
using namespace std;
int main(){
	int a;
	cin>>a;
	for(int i=0;i<100000;i++){
		if(a<i*i){
			cout<<(i-1)*(i-1)<<endl;
			break;
		}
	}	




}

Measured memory_bytes: 256
#define _USE_MATH_DEFINES

#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <cmath>
#include <algorithm>
#include <vector>
#include <queue>
#include <map>
#include <list>

using namespace std;

long long int INF = 1e18;
long long int MOD = 1e9 + 7;

long long int a[110000] = {};

int main(){
	
	int N, S;
	cin >> N >> S;
	
	for(int i = 0; i < N; i++){
		cin >> a[i];
	}
	
	long long int ans = INF;
	long long int P = 0, id = 0;
	
	for(int i = 0; i < N; i++){
		while(P < S && id != N){
			P += a[id];
			id += 1;
		}
		if(P >= S){
			ans = min(ans, id - i);
		}
		P -= a[i];
	}
	
	if(ans == INF){
		cout << 0 << endl;
	}else{
		cout << ans << endl;
	}
	
	return 0;
}



Measured memory_bytes: 3888
import bisect

n=int(input())
a=list(map(int,input().split()))
a=sorted(a)

ans=0
for i in range(n-2):
    for j in range(i+1,n-1):
        tmp=a[i]+a[j]
        index=bisect.bisect_left(a,tmp)
        ans+=index-j-1

print(ans)

Measured memory_bytes: 3188
#include <bits/stdc++.h>
#define N (long long)(1e9 + 7)
using namespace std;

long long n,k,sqn;
vector<long long> cnt;
vector<vector<long long>> dp;

long long solve();

int main(){
    cin >> n >> k;
    sqn = sqrt(n);
    cout << solve() << endl;
    return 0;
}

long long solve(){
    long long bf = sqn;
    for(long long i = sqn;i > 0;--i){
        cnt.push_back(n / i - bf);
        bf = n / i;
    }
    dp.assign(k + 1,vector<long long>(2 * sqn,0));
    for(int i = 0;i < sqn;++i)dp[0][i] = 1;
    for(int i = 0;i < k;++i){
        for(int j = 0;j < sqn;++j){
            // <= sqrt(n)
            dp[i+1][j] = (dp[i][sqn-1] + dp[i][2 * sqn - 1 - j]) % N;
            if(j != 0)(dp[i+1][j] += dp[i+1][j-1]) %= N;
            // >sqrt(n)
            dp[i+1][j+sqn] = dp[i][sqn-1-j] * cnt[j] % N;
            if(j != 0)(dp[i+1][j+sqn] += dp[i+1][j-1+sqn]) %= N;
        }
    }
    return (dp[k][sqn-1] + dp[k][2 * sqn - 1]) % N;
}


Measured memory_bytes: 51196
#include <iostream>
using namespace std;
int main(void){
    // Your code here!
    int n;
    std::cin >> n;
    int ans[4]={0};
    for(int i=0;i<n;i++){
        string t;
        std::cin >> t;
        if(t=="AC"){
            ans[0]++;
        }else if(t=="WA"){
            ans[1]++;
        }else if(t=="TLE"){
            ans[2]++;
        }else if(t=="RE"){
            ans[3]++;
        }
    }
    
    std::cout <<"AC x "<< ans[0] << std::endl;
    std::cout <<"WA x "<< ans[1] << std::endl;
    std::cout <<"TLE x "<< ans[2] << std::endl;
    std::cout <<"RE x "<< ans[3] << std::endl;

}


Measured memory_bytes: 3608
#include <bits/stdc++.h>
#define rep(i, n) for(int i=0; i<(n); ++i)
#define rep1(i,n) for(int i=1; i<=(n); ++i)
#define repi(i,a,b) for(int i=a; i<=(b); ++i)
#define ALL(obj) (obj).begin(), (obj).end()
#define pb push_back
#define mp make_pair
#define sz(v) (int)v.size()
#define UNIQUE(v) v.erase( unique(v.begin(), v.end()), v.end() );
using ll = long long;
using namespace std;
struct aaa{aaa(){ cin.tie(0); ios::sync_with_stdio(0); cout<<fixed<<setprecision(20);};}aaaaaaa;
int MOD = 1e9 + 7;
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 dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};
int N,x;
int main(){
    cin >> N >> x;
    vector<int> a(N);
    rep(i,N) cin >> a[i];
    
    ll ct = 0;
    rep(i,N-1){
        if(a[i] + a[i+1] > x){
            ct += a[i] + a[i+1] - x;
            a[i+1] = max(x - a[i],0); 
        }
    }
    cout << ct << endl;
    
}

Measured memory_bytes: 640
//
//AtCoder Beginner Contest 167
//D - Teleporter
//

#include <iostream>
#include <algorithm>
#include <vector>

using namespace std;

#define REP(i,n) for(ll i=0;i<(ll)(n);i++)
#define REPD(i,n) for(ll i=n-1;i>=0;i--)
#define FOR(i,a,b) for(ll i=a;i<=(ll)(b);i++)
#define FORD(i,a,b) for(ll i=a;i>=(ll)(b);i--)
#define ALL(x) (x).begin(),(x).end()
#define RALL(x) (x).rbegin(),(x).rend()

using ll = long long;

const double PI = 3.14159265358979323846;
const int MOD = 1000000007;

ll gcd(ll x, ll y) { return (x % y)? gcd(y, x % y): y; }
ll lcm(ll x, ll y) { return x / gcd(x, y) * y; }

int main()
{
    int n;
    ll k;

    cin >> n >> k;

    int a[n];

    REP(i, n) cin >> a[i];

    vector<int> trs;
    vector<int> trsCK(n, -1);

    int v = 0;
    while(trsCK[v] == -1){
        trsCK[v] = trs.size();
        trs.push_back(v);
        v = a[v] - 1;
    }
    int cycle = trs.size() - trsCK[v];
    int q = trsCK[v];

    if (k < q) cout << trs[k]+1 << endl;
    else {
        k -= q;
        k %= cycle;
        cout << trs[q+k]+1 << endl;
    }

  return 0;
}


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

int main() {

  string s;
  int ans;
  cin >> s;

  if(s[0] == 'o')
    ans++;
  if(s[1] == 'o')
    ans++;
  if(s[2] == 'o')
    ans++;

  cout << 700 + ans * 100 << endl;

  return 0;
}

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

signed main(){
  lint N; cin >> N;
  vector<lint> a(N);
  for(lint i = 0; i < N; i++) cin >> a[i];
  lint p = *max_element(a.begin(), a.end());
  sort(a.begin(), a.end());
  lint q = a[0], r = abs(p - 2*a[0]);
  for(lint i = 1; i < N; i++){
    if(r > abs(p - 2*a[i])){
      q = a[i]; r = abs(p - 2*a[i]);
    }
  }
  cout << p << " " << q << endl;
}

Measured memory_bytes: 1024
#include<bits/stdc++.h>
#define D(...) fprintf(stderr,__VA_ARGS__)
#define int long long
#define LL long long
#define MP make_pair
#define PB push_back
#define fi first
#define se second
#define ALL(x) (x).begin(),(x).end()
#define SZ(x) ((int)(x).size())
#define rep(i,a,b) for(int i=(a);i<=(b);++i)
#define per(i,a,b) for(int i=(a);i>=(b);--i)
using namespace std;
typedef pair<int,int>PII;typedef vector<int>VI;typedef vector<PII>VII;
template<typename T>void rd(T&x){int f=0,c;while(!isdigit(c=getchar()))f^=!(c^45);x=(c&15);while(isdigit(c=getchar()))x=x*10+(c&15);if(f)x=-x;}
template<typename T>void pt(T x,int c=-1){if(x<0)putchar('-'),x=-x;if(x>9)pt(x/10);putchar(x%10+48);if(c!=-1)putchar(c);}
int A,B;
signed main(){
	rd(A),rd(B);
	int y=(B-A*2);
	if(y<0||(y&1)){
		puts("No");
		return 0;
	}
	y/=2;
	int x=A-y;
	if(x<0){
		puts("No");
		return 0;
	}
	puts("Yes");
	return 0;
}


Measured memory_bytes: 3620
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<n;++i)
using namespace std;
 
int main()
{
  int n, k;
  cin >> n >> k;
  
  vector<int> a(n);
  
  rep(i,n) cin >> a[i];
  
  int up = *max_element(a.begin(),a.end());
  int low = 0;
  int mid;
  int cnt = 0;
  
  while(up - low > 1)
  {
    cnt = 0; 
    mid = (up + low) / 2;
        
    rep(i, n)
    {
      if(a[i] % mid == 0) cnt += a[i] / mid -1;
      else cnt += a[i] / mid;
      
      if(cnt > k)
      {
        low = mid;
        break;
      }
    }
    if(cnt <= k) up = mid;
  }
  cout << up;
  return 0;
}

Measured memory_bytes: 3980
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int X = sc.nextInt();
		sc.close();
		
		if(X == 7 || X == 5 || X == 3)
			System.out.println("YES");
		else
			System.out.println("NO");
	}
}


Measured memory_bytes: 21076
#include <stdio.h>

int main(void)
{
	int H, W;

	while(1){
		scanf("%d %d", &H, &W);
		
		if(H == 0 && W == 0){
			break;
		}
		for(int i = 0; i < H; i++){
			for(int j = 0; j < W; j++){
				printf("#");
			}
			printf("\n");
		}
		printf("\n");
	}
   return 0;
}

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

using namespace std;
using ll = long long;
using ld = long double;

//#define int long long
//signed main(){
int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int n;
    string ss;
    cin >> n >> ss;
    ss+=ss[0];
    vector<int> s(n+1);
    for(int i = 0; i <= n; i++) {
        if(ss[i]=='o') s[i]=1;
        else s[i]=0;
    }
    vector<int> t(n+1,-1);
//    for(int i = 0; i < n; i++) {
//        cout << i+1 << "";
//    }
//    cout << "\n";
    for(int j = 0; j < 4; j++) {
        t[0]=j%2;
        t[1]=j/2;
        for(int i = 1; i < n; i++) {
            if(s[i]==t[i]) t[i+1]=t[i-1];
            else t[i+1]=1-t[i-1];
        }

        if(t[n]==t[0] && (((s[0]==t[0])&&(t[1]==t[n-1])) || ((s[0]!=t[0])&&(t[1]!=t[n-1])))){
            for(int i = 0; i < n; i++) {
                if(t[i]) cout << "S";
                else cout << "W";
            }
            cout << "\n";
            return 0;
        }
    }

    cout << "-1" << "\n";
    return 0;
}

Measured memory_bytes: 4208
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <utility>
#include <ctime>
#define INF 999999999
#define mod 1000000007

#define rep(i,n) for(int i=0;i<int(n);i++)
#define rrep(i,n) for(int i=(n);i>=0;i--)
#define REP(i,a,b) for(int i=(a);i<int(b);i++)
#define all(x) (x).begin(),x.end()
#define pb push_back
#define MOD(x) (x%(mod))
using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef pair<int,int> pi;

bool debug=false;
/*---------------------------------------------------*/

bool prime[1000000];
int ans[1000000];

void is_prime(){
  rep(i,1000000)prime[i]=true;
  prime[0]=prime[1]=false;
  REP(i,2,1000000){
    if(prime[i]==true){
      for(int j=i+i;j<1000000;j+=i)prime[j]=false;
    }
  }
  if(debug)rep(i,1000)if(prime[i])cout<<i<<endl;
}

void calc(){
  ans[0]=0;
  REP(i,1,1000000){
    ans[i]=ans[i-1]+prime[i];
  }
}

int main(){
  int n;
  is_prime();
  calc();
  while(cin>>n){
    cout<<ans[n]<<endl;
  }
  return 0;
}

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

int binarySearch(int num, int *array, int left, int right)
{
    int mid = (left + right) / 2;

    if(num == array[mid])
        return 1;
    if(left > right)
        return 0;
    if(num < array[mid]) {
        binarySearch(num, array, left, mid - 1);
    } else {
        binarySearch(num, array, mid + 1, right);
    }
}

int main(void)
{
    int i, n, s, q, t, cnt = 0;
    int *s_array;

    scanf("%d", &n);
    s_array = malloc(sizeof(int) * n);
    for(i = 0; i < n; i++) {
        scanf("%d", &s);
        s_array[i] = s;
    }
    scanf("%d", &q);
    for(i = 0; i < q; i++) {
        scanf("%d", &t);
        cnt += binarySearch(t, s_array, 0, n - 1);
    }
    printf("%d\n", cnt);

    return 0;
}

Measured memory_bytes: 992
#include<cstdio>
#include<algorithm>
using namespace std;
#define MAXN 100010
int a[5][MAXN],n,tg[5],to[MAXN];
int Abs(int x)
{
	return x>=0?x:-x;
}
int main()
{
	scanf("%d",&n);
	for(int i=0;i<3;i++)
		for(int j=1;j<=n;j++)
			scanf("%d",&a[i][j]);
	
	for(int i=1;i<=n;i++)
	{
		to[i]=a[1][i]/3+1;
		if(!((a[0][i]-a[1][i]==-1&&a[1][i]-a[2][i]==-1&&a[0][i]%3==1)||(a[0][i]-a[1][i]==1&&a[1][i]-a[2][i]==1&&!(a[0][i]%3)))||(Abs(i-to[i])&1))
		{
			printf("No\n");
			return 0;
		}
		tg[i&1]^=(a[0][i]>a[1][i]);
	}
	
	for(int i=1;i<=n;i++)
	{
		while(to[i]!=i)
		{
			tg[i&1^1]^=1;
			swap(to[i],to[to[i]]);
		}
	}
	if(tg[0]||tg[1]) printf("No\n");
	else printf("Yes\n");
}

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

#define int long long
#define rep(i, n) for (int i = 0; i < (n); i++)
#define reps(i, n) for (int i = 1; i <= (n); i++)
#define all(x) begin(x), end(x)
#define uniq(x) (x).erase(unique(all(x)), end(x))
#define bit(n) (1LL << (n))
#define cdiv(a, b) (((a) - 1) / (b) + 1)
#define dump(x) cerr << #x " = " << (x) << endl
using vint = vector<int>;
using vvint = vector<vint>;
using pint = pair<int, int>;
using vpint = vector<pint>;
template<typename T> using priority_queue_rev = priority_queue<T, vector<T>, greater<T>>;
constexpr long double PI = 3.1415926535897932384626433832795028L;
constexpr int DY[8] = {0, 1, 0, -1, 1, 1, -1, -1};
constexpr int DX[8] = {1, 0, -1, 0, 1, -1, -1, 1};
int gcd(int a, int b) {
    while (b) { swap(a %= b, b); }
    return a;
}
int lcm(int a, int b) { return a / gcd(a, b) * b; }
template<typename T> void fin(T mes) {
    cout << mes << endl;
    exit(0);
}
template<typename T, typename U> bool chmax(T &a, const U &b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}
template<typename T, typename U> bool chmin(T &a, const U &b) {
    if (b < a) {
        a = b;
        return true;
    }
    return false;
}
template<typename T, typename U> ostream &operator<<(ostream &os, const pair<T, U> &rhs) {
    os << "(" << rhs.first << ", " << rhs.second << ")";
    return os;
}
template<typename T> ostream &operator<<(ostream &os, const vector<T> &rhs) {
    os << "{";
    for (auto itr = rhs.begin(); itr != rhs.end(); itr++) {
        os << *itr << (next(itr) != rhs.end() ? ", " : "");
    }
    os << "}";
    return os;
}
struct setup {
    static constexpr int PREC = 20;
    setup() {
        cout << fixed << setprecision(PREC);
        cerr << fixed << setprecision(PREC);
    };
} setup;

string S;
signed main() {
    cin >> S;
    if (S == "ABC") { cout << "ARC" << endl; }
    else { cout << "ABC" << endl; }
}


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

#define F(i, a, b) for (int i = a; i <= b; i ++)
#define G(i, a, b) for (int i = a; i >= b; i --)
#define max(a, b) ((a) > (b) ? (a) : (b))
#define min(a, b) ((a) < (b) ? (a) : (b))
#define mx(a, b) ((a) = max(a, b))
#define mn(a, b) ((a) = min(a, b))
#define mem(a, b) memset(a, b, sizeof a)
#define mec(a, b) memcpy(a, b, sizeof a)
#define low(x) ((x) & (- (x)))
#define abs(x) max((x), - (x))
#define outarr(a, L, R) { printf(#a"[%d..%d] = ", L, R); F(i, L, R) W(a[i]), putc(' '); putc('\n'); }
#define outtag(x) { printf(#x" = "), W(x); putc('\n'); }
#define outline(x) { puts("--------------------"#x"-----------------------"); }
#define putc putchar
#define get getchar()

using namespace std;

#define ll long long
#define ld long double

template <typename Int>
void Re(Int &x) {
	char c = get; x = 0; Int t = 1;
	for (; !isdigit(c); c = get) t = (c == '-' ? - 1 : t);
	for (; isdigit(c); x = (x << 3) + (x << 1) + c - '0', c = get); x *= t;
}
template <typename Int>
void Wr(Int x) {
	if (x < 0) { putc('-'); x = - x; }
	if (x > 9) Wr(x / 10); putc(x % 10 + '0');
}

const int N = 3e5 + 10;
int w, h, n, Ans;
struct node {
	int x, y;
	friend bool operator < (node a, node b) { return (a.y < b.y || ((a.y == b.y) && (a.x < b.x))); } 
} d[N], L[N], R[N];
struct Segment_Tree {
	int mx, tag;	
} tr[4 * N];

#define Ls (x << 1)
#define Rs (Ls | 1)
#define Md ((st + en) >> 1)
void Update(int x, int st, int en, int l, int r, int add) {
	if (l > en || r < st) return;
    if (l <= st && en <= r) {
        tr[x].tag += add, tr[x].mx += add;
        return;
    }
    if (tr[x].tag) {
    	tr[Ls].tag += tr[x].tag, tr[Ls].mx += tr[x].tag;
	    tr[Rs].tag += tr[x].tag, tr[Rs].mx += tr[x].tag;
	    tr[x].tag = 0;
	}
	Update(Ls, st, Md, l, r, add);
	Update(Rs, Md + 1, en, l, r, add);
    tr[x].mx = max(tr[Ls].mx, tr[Rs].mx);
}

void Solve() {
	mem(tr, 0), sort(d + 1, d + n + 1);
//	F(i, 1, n)
//		printf("%d %d\n", d[i].x, d[i].y);
    int l = 0, r = 0;
    F(i, 1, n - 1) {
        int tmp = i - 1;
        if (d[i].x <= w / 2) {
            while (l && d[i].x > L[l].y) {
                Update(1, 1, n, L[l].x, tmp, L[l].y - d[i].x);
                tmp = L[l].x - 1;
                -- l;
            }
			L[++ l] = {tmp + 1, d[i].x};
        }
		else {
            while (r && d[i].x < R[r].y) {
                Update(1, 1, n, R[r].x, tmp, d[i].x - R[r].y);
                tmp = R[r].x - 1;
                -- r;
            }
			R[++ r] = {tmp + 1, d[i].x};
        }
        L[++ l] = {i, 0};
		R[++ r] = {i, w};
        Update(1, 1, n, i, i, w - d[i].y);
        mx(Ans, 2 * (d[i + 1].y + tr[1].mx));
    }
}

int main() {
	Re(w), Re(h), Re(n);
	F(i, 1, n) Re(d[i].x), Re(d[i].y);

	d[++ n] = {0, 0};
	d[++ n] = {w, h};

	Solve();

	swap(w, h);
	F(i, 1, n) swap(d[i].x, d[i].y);

	Solve();

	Wr(Ans);
}

Measured memory_bytes: 16640
#include<cstdio>
#include<cstring>
#include<algorithm>
#define mod 1000000007
#define MN 405
using namespace std;
inline int in(){
    int x=0;bool f=0;char c;
    for (;(c=getchar())<'0'||c>'9';f=c=='-');
    for (x=c-'0';(c=getchar())>='0'&&c<='9';x=(x<<3)+(x<<1)+c-'0');
    return f?-x:x;
}
int f[MN][MN],sum[MN][MN],a[MN],b[MN];
int n,c,mx;
inline int qpow(int x,int k){
	int res=1;
	while (k){
		if (k&1) res=(1ll*res*x)%mod;
		x=(1ll*x*x)%mod;k>>=1;
	}return res;
}
int main()
{
	n=in();c=in();
	for (int i=1;i<=n;++i) a[i]=in(),mx=max(mx,a[i]);
	for (int i=1;i<=n;++i) b[i]=in(),mx=max(mx,b[i]); 
	for (int i=0;i<=c;++i)
	for (int j=1;j<=mx;++j) sum[i][j]=(sum[i][j-1]+qpow(j,i))%mod;
	f[0][0]=1;
	for (int i=1;i<=n;++i){
		int I=i&1;memset(f[I],0,sizeof(f[I]));
		for (int j=0;j<=c;++j)
		for (int k=0;k<=j;++k) f[I][j]=(1ll*f[I][j]+(1ll*f[I^1][k]*((1ll*sum[j-k][b[i]]+mod-sum[j-k][a[i]-1])%mod)%mod)%mod)%mod;
	}printf("%d",f[n&1][c]);return 0;
}

Measured memory_bytes: 768
function main(A) {
  A = A.replace(/\r?\n/g,' ');
  A = A.split(' ');
  let N = A.shift(); //sortNum | A.length
  let s = A.map(Number); 
  let kekka = 'APPROVED';

  for(let i = 0; i < s.length; i++){
	if(s[i] % 2 == 0){

      	if(s[i] % 3 == 0 || s[i] % 5 == 0){
        	kekka = 'APPROVED';
        }else {
        	kekka = 'DENIED';
          	break;
        }
    
    }
  }
  
  console.log(kekka);
  
}
 
main(require("fs").readFileSync("/dev/stdin", "utf8"));


Measured memory_bytes: 29672
#include <bits/stdc++.h>
#define _GLIBCXX_DEBUG
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep2(i, s, n) for (int i = s; i < (int)(n); i++)
#define Clear(a) a = decltype(a)();
typedef long long ll;
typedef pair<int,int> p;
//const ll big=998244353;
const ll big=1000000007;
const int dx[4]={1,0,-1,0};
const int dy[4]={0,1,0,-1};
ll max(ll x,ll y){
if(x>y)return x;
else return y;
}
ll min(ll x,ll y){
if(x<y)return x;
else return y;
}
ll expm(ll x,ll y){
    if(y==0)return 1;//0^0=1
    if(x==1||x==0)return x;
    if(y%2==1)return (expm(x,y-1)*x)%big;
    ll t=expm(x,y/2);
    return (t*t)%big;
}
ll exp(ll x,ll y){
    if(y==0)return 1;//0^0=1
    if(x==1||y==0)return x;
    if(y%2==1)return exp(x,y-1)*x;
    ll t=exp(x,y/2);
    return t*t;
}
ll inv(ll x){
    return expm(x,big-2);
}

ll f(vector<ll> &a){
    vector<ll> sums(61);
    rep(i,a.size()){
        bitset<61> now(a[i]);
        rep(j,61)sums[j]+=now[j];
    }
    ll ans=0;
    ll pows=1;
    rep(i,61){
        ans+=((sums[i]*((int)a.size()-sums[i]))%big*pows)%big;
        ans%=big;
        pows*=2;
        pows%=big;
    }
    return ans;
}

int main(){
    ios::sync_with_stdio(false);
    std::cin.tie(nullptr);
    cout << fixed << setprecision(10);
    /*--------------------------------*/

    int n;cin >> n;
    vector<ll> a(n);
    rep(i,n)cin >> a[i];
    ll ans=0;
    cout << f(a) << endl;
}

Measured memory_bytes: 5576
#include "bits/stdc++.h"

#define REP(i,n) for(ll i=0;i<ll(n);++i)
#define RREP(i,n) for(ll i=ll(n)-1;i>=0;--i)
#define FOR(i,m,n) for(ll i=m;i<ll(n);++i)
#define RFOR(i,m,n) for(ll i=ll(n)-1;i>=ll(m);--i)
#define ALL(v) (v).begin(),(v).end()
#define UNIQUE(v) v.erase(unique(ALL(v)),v.end());
#define DUMP(v) REP(aa, (v).size()) { cout << v[aa]; if (aa != v.size() - 1)cout << " "; else cout << endl; }
#define INF 1000000001ll
#define MOD 1000000007ll
#define EPS 1e-9

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


using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<vi> vvi;
typedef vector<vl> vvl;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
ll max(ll a, int b) { return max(a, ll(b)); }
ll max(int a, ll b) { return max(ll(a), b); }
ll min(ll a, int b) { return min(a, ll(b)); }
ll min(int a, ll b) { return min(ll(a), b); }
///(´・ω・`)(´・ω・`)(´・ω・`)(´・ω・`)(´・ω・`)(´・ω・`)///

struct Edge { int to, cap, rev, cost; };
typedef vector<Edge> Edges;
typedef vector<Edges> Graph;

struct MaxFlow {
	Graph G;
	vi level, iter;
	MaxFlow(Graph g) {
		int n = g.size();
		level.resize(n);
		iter.resize(n);
		G = g;
	}
	void add_edge(int from, int to, int cap, int cost = 0) {
		G[from].push_back(Edge{ to, cap, (int)G[to].size(),cost });
		G[to].push_back(Edge{ from,0,(int)G[from].size() - 1,-cost });
	}

	void bfs(int s) {
		fill(ALL(level), -1);
		queue<int> q;
		level[s] = 0;
		q.push(s);
		while (!q.empty()) {
			int v = q.front(); q.pop();
			for (int i = 0; i < G[v].size(); i++) {
				Edge &e = G[v][i];
				if (e.cap > 0 && level[e.to] < 0) {
					level[e.to] = level[v] + 1;
					q.push(e.to);
				}
			}
		}
	}
	int dfs(int v, int t, int f) {
		if (v == t)return f;
		for (int &i = iter[v]; i < G[v].size(); i++) {
			Edge &e = G[v][i];
			if (e.cap > 0 && level[v] < level[e.to]) {
				int d = dfs(e.to, t, min(f, e.cap));
				if (d > 0) {
					e.cap -= d;
					G[e.to][e.rev].cap += d;
					return d;
				}
			}
		}
		return 0;
	}
	int max_flow(int s, int t) {
		int flow = 0;
		for (;;) {
			bfs(s);
			if (level[t] < 0)return flow;
			fill(ALL(iter), 0);
			int f;
			while ((f = dfs(s, t, INF)) > 0) {
				flow += f;
			}
		}
	}
};

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


int main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	int m, n;
	while (cin >> m >> n,m) {
		vi b(m), r(n);
		REP(i, m) {
			cin >> b[i];
		}
		REP(i, n) {
			cin >> r[i];
		}
		Graph g(n + m + 2);
		MaxFlow f(g);
		REP(i, m) {
			REP(j, n) {
				if (gcd(b[i], r[j]) != 1) {
					f.add_edge(i + 1, j + m + 1, 1);
				}
			}
		}
		REP(i, m) {
			f.add_edge(0, i + 1, 1);
		}
		REP(i, n) {
			f.add_edge(i + m + 1, m + n + 1, 1);
		}
		cout << f.max_flow(0, m + n + 1) << endl;
	}
}

Measured memory_bytes: 8656
//By Vlgd
#include<bits/stdc++.h>
using namespace std;
int G[101][101],n,dis[101],vis[101]={0},cur=0;
queue<int>q;
void bfs(int u){
	q.push(u);
	vis[u]=1;
	dis[u]=0;
	while(!q.empty()){
		int w=q.front();q.pop();
		for (int v=1;v<=n;v++) 
			if (G[w][v]&&!vis[v]){ 
				dis[v]=dis[w]+1;
				q.push(v);
				vis[v]=1;
			}
	}
}
main(){
	int u,v,deg;
	scanf("%d",&n);
	for (int i=1;i<=n;i++) dis[i]=-1;
	for (int i=0;i<n;i++){
		scanf("%d%d",&u,&deg);
		for (int j=0;j<deg;j++){
			scanf("%d",&v);
			G[u][v]=1;
		}
	}
	bfs(1);
	for (int i=1;i<=n;i++) printf("%d %d\n",i,dis[i]);
}


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

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  string A, B;
  cin >> A >> B;
  if(A.size() > B.size()) {
    cout << "GREATER" << endl;
  } else if(A.size() < B.size()) {
    cout << "LESS" << endl;
  } else {
    for(int i = 0; i < A.size(); i++) {
      char na = A[i];
      char nb = B[i];
      if(na > nb) {
        cout << "GREATER" << endl;
        return 0;
      } else if(na < nb) {
        cout << "LESS" << endl;
        return 0;
      } else {
        continue;
      }
    }
    cout << "EQUAL" << endl;
  }
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define pp pair<int,int>
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define rep2(i,m,n) for(int (i)=(m);(i)<(n);(i)++)
#define ll long long
#define ld long double
#define all(a) (a).begin(),(a).end()
#define mk make_pair
int main(){
  int n;
  cin>>n;
  vector<int> a(n);
 rep(i,n) cin>>a[i];
 vector<int> color(9);
 rep(i,n){
     if(a[i]<=399) color[0]++;
else if(a[i]<=799) color[1]++;
else if(a[i]<=1199) color[2]++;
else if(a[i]<=1599) color[3]++;
else if(a[i]<=1999) color[4]++;
else if(a[i]<=2399) color[5]++;
else if(a[i]<=2799) color[6]++;
else if(a[i]<=3199) color[7]++;
else  color[8]++;
 }
  int ans1=0;
  int ans2=0;
rep(i,8){
  if(color[i]!=0){
    ans1++;
    ans2++;
  }
}
cout<<max(ans2,1)<<" "<<ans1+color[8];
return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <map>

using namespace std;

using VI = vector<int>;
using LL = long long;

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n) FOR(i,0,n)
#define IN(v) int v;cin>>v;
#define OUT(v) cout<<v<<endl

void inc(map<int, int> &m, int i) {
  if (m.find(i) == m.end())
    m[i] = 0;
  ++m[i];
}
int main() {
  IN(N); IN(M);

  VI A(N);
  vector<LL> sum(N+1, 0);
  map<int, int> counter;
  counter[0] = 1;
  REP(i, N) {
    cin >> A[i];
    sum[i + 1] = sum[i] + A[i];
    inc(counter, sum[i + 1] % M);
  }

  LL ans = 0;
  REP(l, N) {
    ans += --counter[sum[l] % M];
  }
  OUT(ans);

  return 0;
}


Measured memory_bytes: 4352
#include <iostream>

using namespace std;

#define CALC_PRIME_MAX 10007  // _/10 ^ 8 + next prime
#define PRIME_ELEMENT_MAX 1230 // prime( _/10 ^ 8 ) + 1(10007)

int prime_number[PRIME_ELEMENT_MAX];

bool isPrime(int element)
{
	for (int i = 0; prime_number[i] * prime_number[i] <= element; i++) {
		if (element % prime_number[i] == 0)
			return false;
	}
	return true;
}

void calcPrime()
{
	// add 2, 3 (prime)
	int prime_index = 2;
	prime_number[0] = 2;
	prime_number[1] = 3;
	// next prime is 5
	for (int element = 5; element <= CALC_PRIME_MAX; element += 2) {
		bool is_prime = true;
		// judge prime
		for (int i = 1; prime_number[i] * prime_number[i] <= element; i++) {
			if (element % prime_number[i] == 0) {
				is_prime = false;
				break;
			}
		}
		// add prime
		if (is_prime) prime_number[prime_index++] = element;
	}
//	cout << "prime_element_num = " << prime_index << endl;
	return;
}


int main()
{
	int n, element, count = 0;
	calcPrime();
	cin >> n;
	for (int i = 0; i < n; i++) {
		cin >> element;
		if (isPrime(element)) count++;
	}
	cout << count << endl;
	return 0;
}

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

using namespace std;

typedef long long ll;

const ll ts = 100005;

#define IOS  ios::sync_with_stdio(0); cin.tie(0);
#define endl "\n"

signed main() {

    IOS;
    ll n ; cin >> n ;
	 
    ll m = log2(n) + 1; 
    ll ans = 1 ;
    for(int i = 1; i <= m ; i++) ans*= 2;
    cout << ans - 1;
 }


Measured memory_bytes: 512
#include "bits/stdc++.h"

using namespace std;
typedef long long int ll;
typedef pair<ll, ll > pi;  
typedef pair<pair<ll, ll >, ll > pii;  
vector<ll > vec;
vector<vector<ll > > vec2;
ll MOD = 1000000007;
ll INF = 1145141919454519;

int main() {

    ll N;
    cin >> N;

    map<ll, ll> mp;
    for(ll i = 0; i < N; i++){
        ll t; cin >> t;
        if(t >= 3200) mp[8]++;
        else mp[t/400]++;
    }
    //mapは参照しただけで要素数が増えるのでクソ
    ll num = mp.size();
    ll red = mp[8];

    ll mn = num;
    if(red > 0) mn = max((ll)1, num-1);

    ll mx = num;
    if(red > 0) mx = mx-1+red;

    cout << mn << " " << mx << endl;
}

Measured memory_bytes: 256