akhauriyash/Code-Regression huggingface dataset:
from collections import deque

INF = 10 ** 6
dx = [-1, 0, 1, 0]
dy = [0, 1, 0, -1]
H, W = map(int, input().split())
maze = [list(input()) for _ in range(H)]
def bfs(sx, sy):
    reached = [[INF for _ in range(W)] for _ in range(H)]
    reached[sx][sy] = 0
    d = deque()
    d.append([sx, sy])
    while d:
        x, y = d.popleft()
        for i in range(4):    
            nx = x + dx[i]
            ny = y + dy[i]
            if nx < 0 or nx > H - 1 or ny < 0 or ny > W - 1 or maze[nx][ny] == "#" or reached[nx][ny] != INF:
                continue
            d.append([nx, ny])
            reached[nx][ny] = reached[x][y] + 1
    gl = 0
    for i in range(H):
        for j in range(W):
            if reached[i][j] != INF:
                gl = max(gl, reached[i][j])
    return gl

ans = 0
for i in range(H):
    for j in range(W):
        if maze[i][j] != "#":
            tmp = bfs(i, j)
            ans = max(ans, tmp)
print(ans)

Measured memory_bytes: 3436
#include<bits/stdc++.h>
using namespace std;
const int N=200002;
struct node{
	int to,ne;
}e[N<<1];
int n,i,dep[N],x,y,h[N],tot,t;
void add(int x,int y){e[++tot]=(node){y,h[x]},h[x]=tot;}
void dfs(int u,int fa){
	for (int i=h[u],v;i;i=e[i].ne)
		if ((v=e[i].to)!=fa) dep[v]=dep[u]+1,dfs(v,u);
}
int main(){
	scanf("%d",&n);
	for (i=1;i<n;i++) scanf("%d%d",&x,&y),add(x,y),add(y,x);
	dfs(1,0);
	for (t=1,i=2;i<=n;i++)
		if (dep[i]>dep[t]) t=i;
	dep[t]=0,dfs(t,0);
	for (i=1;i<=n;i++)
		if (dep[i]>dep[t]) t=i;
	puts(dep[t]%3==1?"Second":"First");
}

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

using namespace std;

long long MOD = 1e9+7;

int main() {
	cin.tie(nullptr);
	ios::sync_with_stdio(false);
	#if LOCAL
	freopen("a.in", "r", stdin);
	#endif

	int N;
	string t;
	int cnt[26]={0};
	cin>>N>>t;
	for(int i=0;i<N;i++) {
		cnt[t[i]-'a']++;
	}
	long long res = 1;
	for(int i=0;i<26;i++) {
		res*=(long long)(cnt[i]+1);
		res%=MOD;
	}
	res-=1;
	cout<<res<<endl;
	return 0;
}



Measured memory_bytes: 512
#include <assert.h>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <vector>
#include <string>
#include <numeric>
#include <sstream>
#include <iostream>
#include <algorithm>
using namespace std;
typedef long long ll;


ll gcd(ll a, ll b)
{
	if(a < b) {
		swap(a,b);
	}
	
	while(b != 0)
	{
		ll c = a;
		a = b;
		b = c % b;
	}
	return a;
}


int main()
{
	ios::sync_with_stdio(false);

	int t;
	cin >> t;
	while(t--)
	{
		ll A, B, C, D;
		cin >> A >> B >> C >> D;
		if(A < B || D < B)
		{
			cout << "No\n";
			continue;
		}

		if(B <= C)
		{
			cout << "Yes\n";
			continue;
		}
		
		ll delta = D-B;
		ll g = gcd(delta, B);
/*		ll x0 = ((A-C)%B + B)%B;
		//ll x0 = (C+1-B+D);
		ll minx = x0 % g;
		ll xx = minx + C+g;//(C+1+g-1)/g*g;
*/
		ll x0 = A - (A-C+B-1)/B*B;
		if(x0 < 0)
		{
			cout << "No\n";
			continue;
		}
		assert(x0 <= C);
		
		ll cc = (C-x0)/g*g + x0;
		
		//dprint(x0, cc);
		//dprint(A, B, C, D);
		//dprint(delta, g, x0, minx, xx);
	
		if(cc+g < B)
			cout << "No\n";
		else
			cout << "Yes\n";
	}

	return 0;
}


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

int main() {
    ll n,k;
    cin >> n >> k;
    vector<int> a(n);
    rep(i,n) cin >> a[i];
    ll k_1,k_2;
    if(k%2 ==0){
        k_1 = ((k/2)%MOD * (k-1))%MOD;
        k_2 = ((k/2)%MOD * (k+1))%MOD;
    }else{
        k_1 = (((k-1)/2)%MOD * k)%MOD;
        k_2 = (((k+1)/2)%MOD * k)%MOD;
    }
    ll ans = 0;
    rep(i,n){
        ll cnt_1 = 0,cnt_2 = 0;
        rep(j,n){
            if(j < i && a[j] < a[i]) cnt_1 ++;
            if(j > i && a[j] < a[i]) cnt_2 ++;
        }
        ans = (ans + (cnt_1 * k_1)%MOD )%MOD;
        ans = (ans + (cnt_2 * k_2)%MOD )%MOD;
    }
    cout << ans << endl;
    return 0;  
}

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

int main() {
  int X;
  cin >> X;
  
  int ans = 0;
  if(X==1) {
    cout << 1 << endl;
    return 0;
  }
  rep(x, X+1) {
  rep(i, 11) {
    rep(j, 36) {
      if(pow(j, i) == x) {
        ans = max(ans, x);
      }
    }
  }
  }
  cout << ans <<endl;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define rep(i, n) for(int i=0; i<n; i++)
#define repo(i, n) for(int i=1; i<=n; i++)
#define ssort(a) sort(a.begin(), a.end())
#define INF 1001001001
#define INFll 100100100100100
// debug用
#define PrintVec(x) for (auto elementPrintVec: x) { cout << elementPrintVec << " "; } cout << endl;

using namespace std;
using ull = unsigned long long;
using ll = long long;
using P = pair<int, int>;
const int mod = 1000000007;


int main(){
  int n,W;
  cin >> n >> W;
  vector<int> w(n);
  vector<int> v(n);
  vector<int> w4[4];
  rep(i, n){
    cin >> w[i] >> v[i];
    w4[w[i]-w[0]].push_back(v[i]);
  }
  rep(i, 4){
    sort(w4[i].begin(), w4[i].end(), greater<int>());
  }
  int sz1=w4[0].size();
  int sz2=w4[1].size();
  int sz3=w4[2].size();
  int sz4=w4[3].size();
  rep(i, sz1-1){
    w4[0][i+1]+=w4[0][i];
  }
  rep(i, sz2-1){
    w4[1][i+1]+=w4[1][i];
  }
  rep(i, sz3-1){
    w4[2][i+1]+=w4[2][i];
  }
  rep(i, sz4-1){
    w4[3][i+1]+=w4[3][i];
  }
  ll ans=0;
  rep(i, sz1+1){
    rep(j, sz2+1){
      rep(k, sz3+1){
        rep(l, sz4+1){
          ll wnum=0, vnum=0;
          wnum+=(ll)i*w[0];
          if(wnum>W)continue;
          wnum+=(ll)j*(w[0]+1);
          if(wnum>W)continue;
          wnum+=(ll)k*(w[0]+2);
          if(wnum>W)continue;
          wnum+=(ll)l*(w[0]+3);
          if(wnum>W)continue;
          if(i!=0){
            vnum+=w4[0][i-1];
          }
          if(j!=0){
            vnum+=w4[1][j-1];
          }
          if(k!=0){
            vnum+=w4[2][k-1];
          }
          if(l!=0){
            vnum+=w4[3][l-1];
          }
          ans=max(ans, vnum);
        }
      }
    }
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 3584
#include<iostream>
#include<math.h>
//#include <boost/multiprecision/cpp_int.hpp>
using namespace std;
//namespace mp = boost::multiprecision;

int main(){
    long long n;
    cin >> n;
    //mp::cpp_int x = 1;
    unsigned long long temp;
    //mp:cpp_int temp;
    if(n % 2 == 0) temp = n / 2 * (n-1);
    else temp = (n-1) / 2 * n;
    
    cout << temp << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define int   long long int
#define mod 2000900000009999990
#define pb push_back
#define mp make_pair
#define bs binary_search
#define lb lower_bound
#define ub upper_bound
#define gcd __gcd
#define fastio ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define min3(a,b,c) min(a,min(b,c))
#define mai3(a,b,c) mai(a,mai(b,c))
#define all(i) i.begin(),i.end()
#define rep(i,a,b) for(int i=a;i<b;i++)
#define set_bit __builtin_popcount //gives number of set_bits
#define ff first
#define ss second
#define cases(t) int t; cin>>t; rep(casn,1,t+1)
#define el cout<<endl;
#define deci(n) int n; cin>>n;
#define decs(n) string n; cin>>n;
//SUNEET KUMAR -->  ਸੁਨੀਤ 
int power(int a,int n)//binary expo
{
    int r;
    if(n==0)
        return 1;
    else if(n==1)
        return a;
    else
        r=power(a,n/2);
    if(n%2==0)
        return ((r)%mod)*((r)%mod)%mod;
    else
        return ((((r)%mod)*((r)%mod))%mod*((a)%mod))%mod;
}
int mai(int a,int b)
{
    if(a>b)
    return a;
    else 
    {
        return b;
    }
}
int madd(int a,int b)
{
    int ans;
    ans=(a%mod+b%mod)%mod;
    return ans;
}
int mmult(int a,int b)
{
    int ans=1;
    ans=((a%mod)*(b%mod))%mod;
    return ans;
}

int modinverse(int a)
{
    return power(a,mod-2);
}
int countr(int n,int r)
{
    int count=0;
    for(int i=1;i<=65;i++)
    {
        int x=power(r,i);
        if(x>n)
        {
            break;
        }
        else
        {
            count+=n/x;
        }
    }
    return count;
}
signed main()
{
      deci(n);
      if(n%2==0)
      {
           n=n/2;
          int cnt2=n,cnt5=0;
          cnt2+=countr(n,2);
           cnt5+=countr(n,5);
          cout<<min(cnt2,cnt5);
      }
      else
      {
          cout<<0;el
      }
}

Measured memory_bytes: 384
#include <iostream>
#include <vector>
#include <limits.h>
#include <algorithm>
#include <string>
#include <math.h>
#include <limits.h>
#include <queue>
#include <map>
#include <set>
#include <iomanip>
#include <bitset>
#include <cassert>
#include <random>
#include <functional>
#include <stack>
#include <iomanip>
#include <cassert>
//#include <boost/multiprecision/cpp_int.hpp>
#include <complex>
#include <cstdio>
#include <list>

//< in.txt > out.txt
using namespace std;
//std::ios::sync_with_stdio(false);
//std::cin.tie(0);
const long long MOD = 1e9 + 7;
typedef long long ll;
typedef long double ld;
typedef pair<ll, ll> pll;
typedef pair<ld, ll> pdl;
typedef pair<ld, ld> pdd;
typedef vector<ll> VLL;
typedef vector<VLL> VVLL;
//typedef boost::multiprecision::cpp_int bigint;

VLL V;
ll N;

int main() {
	std::ios::sync_with_stdio(false);
	std::cin.tie(0);
	ll N;
	VLL A;
	cin >> N;
	A.resize(N);
	for (ll n = 0; n < N; n++) {
		cin >> A[n];
		A[n]++;
	}
	ll ans = 1;
	VLL counter(N + 1, 0);
	counter[0] = 3;
	for (ll n = 0; n < N; n++) {
		ans *= max((ll)0, counter[A[n] - 1] - counter[A[n]]);
		ans %= MOD;
		counter[A[n]]++;
	}
	cout << ans << "\n";
	return 0;
}

Measured memory_bytes: 1792
#include <iostream>
#include <algorithm>
#include <cmath>
#include <vector>
#include <string>
#include <queue>
#include <utility>
#include <map>
#define ll long long
using namespace std;

int main(){
    ll n;
    cin >> n;
    vector<ll> a, check;
    for(ll i = 0; i < n; i++){
        ll b;
        cin >> b;
        a.push_back(b);
    }
    ll ans = 0, count = 1;
    check.push_back(0);
    for(ll i = 0; i < a.size(); i++)
        check.push_back(check[i]+a[i]);
    sort(check.begin(), check.end());
    for(ll i = 1; i < check.size(); i++){
        if(check[i-1]==check[i])
            count++;
        else{
            ans+=count*(count-1)/2;
            count=1;
        }
        if(i==check.size()-1)
            ans+=count*(count-1)/2;
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 4848
import java.util.*;
public class Main {
	
	void doIt() {
		Scanner stdIn = new Scanner(System.in);
		while(true) {
			int N = stdIn.nextInt();
			int P = stdIn.nextInt();
			if(N == -1 && P == -1) break;
			ArrayList<Integer> list = new ArrayList<Integer>(100);
			
			int num = N;
			while(list.size() < 100) {
				boolean flag = true; //素数であると仮定
				if(N == 1) flag = false; //Nが１であればもう見る必要は無い
				for(int c = 2; c <= Math.sqrt(N); c++) {//素数であるか見てみる
					if(N % c == 0) { 
						flag = false;
						break;
					}
				}
				if(flag) list.add(N);
				N++;
			}
		
			for(int r = 0; r < list.size(); r++) {
				if(list.get(r) > num) { 
					num = r; //添字にする 
					break;
				}
			}
			
			ArrayList<Integer> output = new ArrayList<Integer>();
			for(int r = num; r < list.size(); r++) {
				for(int c = r; c < list.size(); c++) {
					output.add(list.get(r) + list.get(c));
				}
			}
			Collections.sort(output);
			System.out.println(output.get(P - 1));
		}
	}
	
	public static void main(String[] args) {
		new Main().doIt();
	}
}

Measured memory_bytes: 102480
#include <stdio.h>
#include <iostream>
#include <iomanip>
#include <algorithm>
#include <sstream>
#include <complex>
#include <vector>
#include <list>
#include <queue>
#include <deque>
#include <stack>
#include <set>
#include <map>
#include <cstdio>
#include <string>
#include <cstdlib>
#include <cstring>
#include <bits/stdc++.h>

using namespace std;
typedef long long ll;
const long double EPS = 1e-9;
const ll mod = 1e9 + 7;
const ll INF = 1e9;

#define rep(i, n) for(ll i = 0; i < n ; i++ )
#define For(i, a, b) for(ll i = (a); i < (b) ; i++ )
#define all(a) (a).begin(), (a).end()
#define rall(a) (a).rbegin(), (a).rend()

const ll MAX_N = 100000;

int main(void){
    ll N, M;
    vector<pair<ll, ll>> yp;
    vector<pair<ll, ll>> order_by_y;
    vector<pair<ll, ll>> answer;
    ll id[MAX_N + 10];
    ll p_cnt[MAX_N + 10];
    rep(i, MAX_N + 10) p_cnt[i] = 0;
    
    cin >> N >> M;
    rep(i, M){
        ll p,y;
        cin >> p >> y;
        yp.push_back(make_pair(y, p));
        order_by_y.push_back(make_pair(y, i));
    }

    sort(all(yp));
    sort(all(order_by_y));

    rep(i, M){
        ll n = yp[i].second;
        p_cnt[n] ++; 
        id[i] = 1000000 * n + p_cnt[n];
    }

    rep(i, M) answer.push_back(make_pair(order_by_y[i].second, id[i]));
    sort(all(answer));

    rep(i, M) cout << setfill('0') << right << setw(12) << answer[i].second << endl;

    return 0;
}

Measured memory_bytes: 8036
#include <bits/stdc++.h>
#define fastio ios_base::sync_with_stdio(false); cin.tie(NULL);
#define ll long long
#define ull unsigned long long
#define FI(i,a,n) for(int i=a; i<=n; i++)
#define RFI(i,n,a) for(int i=n; i>=a; i--)
#define FLL(i,a,n) for(ll i=a; i<=n; i++)
#define RFLL(i,n,a) for(ll i=n; i>=a; i--)
#define vi vector<int>
#define vll vector<ll>
#define all(v) v.begin(),v.end()
#define pll pair<ll,ll>
#define pi pair<int, int>
#define GCD(a,b) __gcd(a,b)
#define MP make_pair
#define PB push_back
#define PF push_front
#define LB lower_bound
#define UB upper_bound
#define debug(x) cout << x << endl
#define MOD 1000000007
#define INF LLONG_MAX
#define PI 3.14159265359
using namespace std;


int main()
{
  fastio

  int n, m;
  cin >> n >> m;
  vector<vi> adj(n+1);

  for(int i=1; i<=m; i++)
  {
    int x, y;
    cin >> x >> y;
    adj[x].PB(y);
    adj[y].PB(x);
  }

  vi ans(n+1, 0);

  queue<int> q;
  vector<bool> vis(n+1, false);

  q.push(1);
  vis[1] = true;

  while(!q.empty())
  {
    int u = q.front();
    q.pop();
    for(auto &v:adj[u])
    {
      if(vis[v]) continue;
      ans[v] = u;
      vis[v] = true;
      q.push(v);
    }
  }


  for(int i=2 ;i<=n; i++) 
  {
    if(ans[i]==0)
    {
      cout << "No";
      return 0;
    }
  }

  cout << "Yes\n";

  for(int i=2; i<=n; i++) cout << ans[i]<< "\n";





	return 0;
}





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

const int N = 301;
const int mod = 1e9+7;

int add(int x,int y) {
   return (x+y)%mod;
}
int dp[N][N][N];

void make(int l,int r,int x) {
   for(int i=0;i<=r;++i) {
      for(int j = 0;j<=r;++j) {
         int cc = 1;
         if(l<=i) {
            ++cc;
         }
         if(l<=j) {
            ++cc;
         }
         if(cc != x) {
            dp[r][i][j] = dp[i][r][j] = dp[i][j][r] = 0;
         }
      }
   }
}
int solveDp(int r,int g,int b,int n) {
   int &ret = dp[r][g][b];
   if(ret!=-1) {
      return ret;
   }
   int ind = max(r,max(g,b)) +1;
   if(ind >n) {
      return ret = 1;
   }
   ret = add( solveDp(ind,g,b,n) ,add(solveDp(r,ind,b,n), solveDp(r,g,ind,n)));
   return ret;
}
void solve() {
   memset(dp,-1,sizeof(dp));
   int n,m;
   scanf("%d%d",&n,&m);
   for(int i=0;i<m;++i) {
      int l,r,x;
      scanf("%d%d%d",&l,&r,&x);
      make(l,r,x);
   }
   printf("%d\n", solveDp(0,0,0,n));
}
int main() {
   //freopen("input.txt","r",stdin);
   solve();
}


Measured memory_bytes: 106880
#include<iostream>
#include<algorithm>
#include<string>
#include<stdio.h>
#include<iomanip>
using namespace std;
int main(){
	int X,Y,Z,people;
	cin >> X >> Y >> Z;
	people = (X-Z)/(Y+Z);
	cout << people << endl;

	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <string.h>
#include <stdio.h>
using namespace std;
#define ll long long
int main(int argc, char const *argv[])
{
    int r;
    cin >> r;
    if (r < 1200) {
        puts("ABC");
    } else if (r >= 1200 && r < 2800) {
        puts("ARC");
    } else {
        puts("AGC");
    }
    return 0;
}

Measured memory_bytes: 256
#coding: utf-8

n, m, l = (int(i) for i in input().split())
nm = [[0 for i in range(m)] for j in range(n)]
ml = [[0 for i in range(l)] for j in range(m)]
nl = [[0 for i in range(l)] for j in range(n)]

for i in range(n):
    nm[i] = input().split()

for i in range(n):
    for j in range(m):
        nm[i][j] = int(nm[i][j])

for i in range(m):
    ml[i] = input().split()

for i in range(m):
    for j in range(l):
        ml[i][j] = int(ml[i][j])


for i in range(n):
    for j in range(l):
        for k in range(m):
            nl[i][j] += nm[i][k] * ml[k][j]

for i in range(n):
    for j in range(l):
        print(nl[i][j], end = ' ' if j != l-1 else '\n')


Measured memory_bytes: 7108
n, m = gets.strip.split.map(&:to_i)

students = []
checkpoints = []
n.times do
    students << gets.strip.split.map(&:to_i)
end
m.times do
    checkpoints << gets.strip.split.map(&:to_i)
end

def manhattan(p, q)
    (p[0] - q[0]).abs + (p[1] - q[1]).abs
end

def search_nearest(s, cs)
    min = 1000000000000
    min_index = 0
    cs.each_with_index do |c, i|
        d = manhattan(s, c)
        if d < min
            min = d
            min_index = i
        elsif d == min
            if i < min_index
                min = d
                min_index = i
            end
        end
    end
    return min_index + 1
end

students.each do |s|
    puts search_nearest(s, checkpoints)
end

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

#define int long long
#define MOD 1000000007

signed main(){
    int n;
    cin >> n;

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

    int c[100010] = {};
    c[0] = 1;

    for(int i = 1;i < n;i++){
        if(a[i] != a[i-1]){
            c[i] = 1;
        }
    }

    if(b[0] != a[n-1]){
        cout << 0 << endl;
        return 0;
    }

    c[n-1] = 1;

    for(int i = n-2;i >= 0;i--){
        if(b[i] != b[i+1]){
            if(b[i] > a[i]){
                cout << 0 << endl;
                return 0;
            }else{
                c[i] = 1;
            }
        }else{
            if(c[i] == 0){
                c[i] = min(a[i], b[i]);
            }
        }
    }

    int ans = 1;
    for(int i = 0;i < n;i++){
        ans = (ans * c[i]) % MOD;
    }

    cout << ans << endl;
    return 0;
}

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

void solv() {
    string w;
    cin >> w;
    map<char, int> mp;
    for (char i = 'a'; i <= 'z';i++){
        mp[i] = 0;
    }
    for (int i = 0; i < w.size();i++){
        mp[w[i]]++;
        //cout << "map" << w[i] << mp[w[i]] << endl;
    }
    for (char i = 'a'; i <= 'z';i++){
        //cout << "map" << i << mp[i] << endl;
        if(mp[i] %2 != 0){
            cout << "No" << endl;
            return;
        }
    }
    cout << "Yes" << endl;
    return;
}

int main() {
    solv();
    return 0;
}

Measured memory_bytes: 384
//
//  main.cpp
//  CoderWork
//
//  Created by Minoru Hayashi on 2020/02/29.
//  Copyright © 2020 Minoru Hayashi. All rights reserved.
//

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

#define REP(i,n) for (int i=0; i<(n); i++)
#define REP2(i,x,n) for (int i=x; i<(n); i++)
#define ALL(n) begin(n), end(n)

using ll = long long;
using P = pair<int,int>;

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

const ll INF = 1LL<<60;

//#define __DBG__


ll DP[100010];
int h[100010];

void solve(void){

  int N;
  cin >> N;

  REP(i,N) {
    cin >> h[i];
    DP[i]=INF;
  }
  
  DP[0]=0;
  
  REP(i,N){
    chmin(DP[i+1], DP[i]+abs(h[i+1]-h[i]));
    chmin(DP[i+2], DP[i]+abs(h[i+2]-h[i]));
  }

  cout << DP[N-1] << endl;
  
  return;
}

int main(int argc, const char * argv[]) {



    // cinを高速にするためのおまじない
    cin.tie(0);
    ios::sync_with_stdio(false);
  
    solve();
 
    return 0;
}





Measured memory_bytes: 1408
#define Oo ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#include <bits/stdc++.h>
using namespace std;
#define PI acos(-1.0)
typedef long long ll;
int main()
{
      Oo
      ll a, b, c;
      cin>> a >>b >> c;
      if (b*c>=a)cout << "Yes" << endl;
      else cout << "No" << endl;
	return 0;
}


Measured memory_bytes: 3604
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define REP(i, n) for (int i = 0; i < (int)(n); i++)
#define FOR(i, m, n) for (int i = m; i < n; i++)
#define SORT(x) sort(x.begin(), x.end())
#define RS(x) rsort(x.begin(),x,end()))
#define REVE(x) reverse(x.begin(), x.end())
#define ALL(x) (x).begin(), (x).end()
int INF = 1e9 + 1;
int MOD = 1e9+7;
struct initon
{
    initon()
    {
        cin.tie(0);
        ios::sync_with_stdio(false);
    };
};
typedef long double ld;
int n,a,b,c,ans;
string s;
signed main(){
cin >>n;
for(int i =n;i>=500;i-=500){
  ans+=1000;
  n-=500;
}
for(int i = n;i>=5;i-=5){
  ans+=5;
  n-=5;
}
cout <<ans;
}

Measured memory_bytes: 256
#include<cstdio>
#include<cmath>
#include<algorithm>
#include<iostream>
#include<vector>
#include<queue>
#include<string>
#include<cstring>
#include<queue>
#include<map>
#include<set>
#include<stack>
using namespace std;
#define ll long long
#define ull unsigned long long
#define up(i,a,b) for(register int i=(a);i<=(b);i++)
#define down(i,a,b) for(register int i=(a);i>=(b);i--)
#define mem(x,y) memset(x,(y),sizeof x)
#define ff first
#define ss second
#define mp(x,y) make_pair(x,y)
#define pb(x) push_back(x)
#define sc(a) scanf("%d",&a)
#define scl(a) scanf("%lld",&a)
#define scs(a) scanf("%s",a)
#define pr(a,b) printf("%d%c",a,b)
#define prl(a,b) printf("%lld%c",a,b)
#define PQ priority_queue
#define ld long double
#define all(v) v.begin(),v.end()
#define IOS ios::sync_with_stdio(false),cin.tie(0),cout.tie(0)

typedef pair<ll,ll> pii;
typedef map<int,int> mii;
typedef vector<int> V;

template<typename T>
T gcd(T a,T b) {
	return !b?a:gcd(b,a%b);
}

inline int read() {
	int input=0,v=1;
	char c=getchar();
	while((c<'0'||c>'9')&&c!='-')c=getchar();
	if(c=='-')v=-1,c=getchar();
	while(c>='0'&&c<='9')input=input*10+c-'0',c=getchar();
	return v*input;
}

ll a[4][1010];
int cnt[4];
struct node {
	ll val;
	int x,y,z;
	node() {};
	node(ll a,int b,int c,int d):val(a),x(b),y(c),z(d) {};
	bool operator<(const node &a)const {
		if(a.val!=val)return val<a.val;
		if(a.x!=x)return x<a.x;
		if(a.y!=y)return y<a.y;
		return z<a.z;
	}
};
PQ<node> pq;
set<node>s;

int main() {
	int k;
	up(i,1,3)sc(cnt[i]);
	sc(k);

	up(i,1,3) {
		up(o,1,cnt[i])scl(a[i][o]);
		sort(a[i]+1,a[i]+1+cnt[i]);
	}

	ll p=0;
	up(i,1,3)p+=a[i][cnt[i]];
	pq.push(node(p,cnt[1],cnt[2],cnt[3]));
	s.insert(node(0,cnt[1],cnt[2],cnt[3]));

	up(i,1,k){
		node x=pq.top();pq.pop();

		if(x.x!=1&&s.find(node(0,x.x-1,x.y,x.z))==s.end())pq.push(node(a[1][x.x-1]+a[2][x.y]+a[3][x.z],x.x-1,x.y,x.z)),s.insert(node(0,x.x-1,x.y,x.z));
		if(x.y!=1&&s.find(node(0,x.x,x.y-1,x.z))==s.end())pq.push(node(a[1][x.x]+a[2][x.y-1]+a[3][x.z],x.x,x.y-1,x.z)),s.insert(node(0,x.x,x.y-1,x.z));
		if(x.z!=1&&s.find(node(0,x.x,x.y,x.z-1))==s.end())pq.push(node(a[1][x.x]+a[2][x.y]+a[3][x.z-1],x.x,x.y,x.z-1)),s.insert(node(0,x.x,x.y,x.z-1));

		prl(x.val,'\n');
	}
}

Measured memory_bytes: 896
#include<iostream>

using namespace std;

int main(){
  int a[5],b[5];
  cin>>a[0]>>a[1]>>a[2]>>a[3]>>a[4];

  for(int i=0;i<5;i++){
    for(int j=i;j<5;j++){
      if(a[i]<a[j]){
	swap(a[i],a[j]);
      }
    }
  }
  for(int i=0;i<4;i++)
    cout<<a[i]<<' ';
  cout<<a[4]<<"\n";
}

Measured memory_bytes: 0
#include <iostream>
#include <array>
int main(){
  long long n;
  std::cin >> n;
  std::array<long long, 5> nums;
  for(int i = 0; i < 5; ++i)
    std::cin >> nums[i];

  long long min = 1000000000000000;
  for(int i = 0; i < 5; ++i){
    if(nums[i] < min)
      min = nums[i];
  }
  long long div = n/min;
  if(n%min > 0)
    ++div;

  std::cout << 4 + div << std::endl;

  return 0;
}


Measured memory_bytes: 256
N, K = map(int, input().split())
Xs = list(map(int, input().split()))

lst = []
for i in range(N):
  lst.append(Xs[i])
  tmp = Xs[i]
  for j in range(i+1,N):
    tmp += Xs[j]
    lst.append(tmp)
  
x = 0
for i in range(40, 0, -1):
  cnt = 0
  t = x + 2**(i-1)
  for l in lst:
    if t&l == t:
      cnt += 1
  if cnt >= K:
    x = t
  
print(x)

Measured memory_bytes: 106660
#include <string>
#include<iostream>
#include<vector>
#include <bits/stdc++.h>
#include <stdio.h>
#include <numeric>
#include<math.h>
#include <ctype.h>
#include <algorithm> // sort
#include <map> // pair
using namespace std;

int main() {
  int a,b;
  cin >> a >> b;
  if(a*b%2==0){
    cout << "Even" << endl;
  }
  else{
    cout << "Odd" << endl;
  }
}

Measured memory_bytes: 256
import java.util.Scanner;

class Main{
    public static void main(String args[]){
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int y = sc.nextInt();
        int a = 10000;
        int b = 5000;
        int c = 1000;
        int count = 0;
        for(int i = 0; i <= n; i++){
            for(int j = 0; (n-i-j) >= 0; j++){
                int sum = a * i + b * j + c * (n - i - j);
                //System.out.println(sum);
                if(sum == y){
                    System.out.println(i + " " + j + " " + (n-i-j));
                    return;
                }
            }
        }
        System.out.println("-1 " + "-1 " + "-1");
    }
}


Measured memory_bytes: 23380
a, b = map(int,input().split())
c = 1 / a
l = []
for i in range(1,a+1):
  count = 0
  d = i
  while d < b:
    d = d*2
    count += 1
  num = c * (0.5**count)
  l.append(num)
print(sum(l))

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

const ll MOD = 1e9 + 7;

int N;
vector<int> chd[100005];
//dp[i][j], i = node, j = black / white
//dp[i][j] = no of possible method to colour with node i as root of tree
ll dp[100005][2];

//node id, parent
void dfs(int x, int p){
	for (auto i : chd[x]){
		if (i == p) continue;
		dfs(i, x);
	}
	dp[x][0] = 1;
	dp[x][1] = 1;
	for (auto i : chd[x]){
		if (i == p) continue;
		dp[x][0] = dp[x][0] * (dp[i][0] + dp[i][1]) % MOD;
		dp[x][1] = dp[x][1] * dp[i][0] % MOD;
	}
}

int main(){
	ios::sync_with_stdio(0);	cin.tie(0);		cout.tie(0);
	cin >> N;
	int x, y;
	for (int i = 1; i < N; ++i){
		cin >> x >> y;
		chd[x].emplace_back(y);
		chd[y].emplace_back(x);
	}
	dfs(1,0);
	cout << (dp[1][0] + dp[1][1]) % MOD << '\n';
	return 0;
}

Measured memory_bytes: 14208
#include <iostream>
#include <vector>
#include <algorithm>
#include <functional>
#include <queue>
#include <deque>
#include <string>
#define endl '\n'
#define ll long long

using namespace std;

int main(void)
{
	cin.tie(NULL); ios_base::sync_with_stdio(false);
	int ret = 0;
	vector<int> input;
	int N; cin >> N;
	for (int i = 0; i < N; i++)
	{
		int temp; cin >> temp;
		input.push_back(temp);
		ret += temp;
	}
	if (ret % 10 != 0)
	{
		cout << ret;
		return 0;
	}
	sort(input.begin(), input.end());
	int idx = -1;
	for (int i = 0; i < input.size(); i++)
		if (input[i] % 10 != 0)
		{
			idx = i; break;
		}
	if (idx == -1)
		cout << 0;
	else
		cout << ret - input[idx];
	return 0;
}

Measured memory_bytes: 256
while True:
    a, b, c = map(str, input().split())
    if b == "?":
        break
    elif b == "+":
        print(int(a) + int(c))
    elif b == "-":
        print(int(a) - int(c))
    elif b == "*":
        print(int(a) * int(c))
    else:
        print(int(int(a) / int(c)))



Measured memory_bytes: 5596
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cmath>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <tuple>
#include <vector>

using namespace std;
typedef long long ll;

#define rep(i, n) for (ll i = 0; i < (n); i++)
#define reps(i, f, n) for (ll i = (f); i < (n); i++)
#define repr(i, n) for (ll i = n; i >= 0; i--)
#define repv(v) for (auto it = (v).begin(); it != (v).end(); it++)
#define ALL(x) (x).begin(), (x).end()
#define SZ(x) ((int)(x).size())
#define pb push_back
#define INIT    \
    cin.tie(0); \
    ios::sync_with_stdio(false);

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

ll const INF = 1LL << 60;
ll const MOD = 1000000007;

bool isOK(ll N, ll M, ll V, ll P, vector<ll>& A, ll x) {
    if (x < P) return true;
    ll now = A[x] + M;

    if (A[P - 1] > now) return false;

    ll score = 0;
    score += (P - 1) * M;
    score += (N - x) * M;

    reps(i, P - 1, x) { score += min(M, max(0LL, now - A[i])); }
    return score >= M * V;
}

int main() {
    INIT;

    ll N, M, V, P;
    cin >> N >> M >> V >> P;

    vector<ll> A(N);
    rep(i, N) cin >> A[i];
    sort(ALL(A), greater<ll>());

    ll ok = -1;
    ll ng = N;

    while (abs(ok - ng) > 1) {
        ll mid = (ok + ng) / 2;

        if (isOK(N, M, V, P, A, mid))
            ok = mid;
        else
            ng = mid;
    }
    cout << ok + 1 << endl;

    return 0;
}

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

int main() {
  
  int N;
  cin >> N;
  vector<string> s(N);
  for(int i; i<N; i++){
  	cin >> s.at(i);
  }
  
  int M;
  cin >> M;
  vector<string> t(M);
  for(int j=0; j<M; j++){
  	cin >> t.at(j);
  }		//ここまでで文字列の入力
  
  int X = 0 ; //Xの設定
  
  for(int k=0; k<N; k++){
    int x = 0;
  	for(int l=0; l<N; l++){
    	if(s.at(k) == s.at(l)){
        	x++;
        }
    }
    for(int m=0; m<M; m++){
    	if(s.at(k) == t.at(m)){
        	x--;
        }
    }
    if(x > X){
      X = x;
    }
  }
  cout << X <<endl;
}



Measured memory_bytes: 256
N = int(input())

ans = 1e9
for i in range(N+1):
  cnt = 0
  tmp = i
  while tmp > 0:
    cnt += tmp%6
    tmp //= 6
  tmp = N-i
  while tmp > 0:
    cnt += tmp%9
    tmp //= 9
  ans = min(ans, cnt)
print(ans)

Measured memory_bytes: 3060
a = list(map(lambda x: ord(x)-ord("a"), list(input())))
n = len(a)
m = 26

b = [1]*(n+1)
prev = [n]*m
G = [[] for i in range(n+1)]
for i in reversed(range(n)):
    ai = a[i]
    tmp = min(b[j] for j in prev)
    for j in prev:
        G[i].append(j)
    b[i] = tmp+1
    prev[ai] = i

cnt = min(b[j] for j in prev)
edge = prev
ans = []
for _ in range(cnt):
    for i, to in enumerate(edge):
        if b[to] == cnt-_:
            ans.append(chr(ord("a")+i))
            edge = G[to]
            break
print("".join(ans))

Measured memory_bytes: 130888
#include <iostream>
#include <fstream>
#include <set>
#include <map>
#include <string>
#include <vector>
#include <bitset>
#include <algorithm>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <cassert>
#include <queue>


typedef long long ll;
typedef long double ld;

using namespace std;

const int MAXN = 1010;

int n, m;
vector<pair<int, int> > eds[MAXN];
vector<pair<int, int> > vv[MAXN];
queue<pair<int, int> > qu;
int ans[200010];

vector<int> e[MAXN], _e[MAXN];
int AA[200010],BB[200010];

bool mark[MAXN];
int ord[MAXN], tim;
int to[MAXN],cc;

void dfs(int x){
	if(mark[x])return;
	mark[x] = true;
	for(vector<int>::iterator it = e[x].begin(); it != e[x].end(); it++){
		int y = *it;
		dfs(y);
	}
	ord[tim++] = x;
}
void _dfs(int x){
	if(!mark[x])return;
	mark[x] = false;
	to[x] = cc;
	for(vector<int>::iterator it = _e[x].begin(); it != _e[x].end(); it++){
		int y = *it;
		_dfs(y);
	}
}
void scc(){
	for(int i=0; i<n; i++)
		if(!mark[i])
			dfs(i);
	while(tim--){
		int x = ord[tim];
		if(mark[x]){
			_dfs(x);
			cc++;
		}
	}
}

int main(){
	scanf("%d%d",&n,&m);

	for (int i = 0; i < n; ++i)
		eds[i].clear();
	for (int i = 0; i < m; ++i) {
		int a, b;
		scanf("%d%d", &a, &b);
		--a;
		--b;
		e[a].push_back(b);
		_e[b].push_back(a);
		eds[a].push_back(make_pair(b, i));
		AA[i] = a;
		BB[i] = b;
	}
	scc();
	for (int i = 0; i < n; ++i) {
		for (int j = 0; j < n; ++j)
			vv[j].clear();
		for (int j = 0; j < (int)eds[i].size(); ++j) {
			int u = eds[i][j].first;
			vv[u].push_back(make_pair(1, j));
			qu.push(make_pair(u, 0));
		}
		while (!qu.empty()) {
			int x = qu.front().first;
			int y = qu.front().second;
			qu.pop();
			for (int j = 0; j < (int)eds[x].size(); ++j) {
				int u = eds[x][j].first;
				if (u == i)
					continue;
				if (vv[u].size() >= 2)
					continue;
				if (vv[u].empty() || vv[u][0].second != vv[x][y].second)
					qu.push(make_pair(u, vv[u].size())), vv[u].push_back(make_pair(vv[x][y].first + 1, vv[x][y].second));
			}
		}
		for (int j = 0; j < (int)eds[i].size(); ++j) {
			int u = eds[i][j].first;
			if (vv[u].size() < 2)
				ans[eds[i][j].second] = 0;
			else
				ans[eds[i][j].second] = vv[u][1].first;
		}
	}
	for(int i=0; i<m; i++){
		puts((ans[i] == 0) == (to[AA[i]] != to[BB[i]]) ? "same" : "diff");
	}
	return 0;
}

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

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

  int N;
  cin >> N;

  int r = N % 1000;

  if (r == 0) cout << 0 << endl;
  else cout << 1000 - r << endl;

  return 0;
}

Measured memory_bytes: 3588
#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<n;i++)
#define max0(a,b,c) max(max(a,b),c)
#define min0(a,b,c) min(min(a,b),c)
#define ft first
#define sc second
#define pb push_back
#define mp make_pair
#define mt make_tuple
#define all(v) (v).begin(),(v).end()
#define mod 1000000007
using namespace std;
using Graph = vector<vector<int>>;
typedef long long lint;
typedef long long ll;
typedef unsigned long long ull;
typedef long double ldouble;
typedef vector<int> vec;
typedef vector<ll> lvec;
typedef vector<ull> ulvec;
typedef vector<double> dvec;
typedef vector<pair<int,int>> pvec;
typedef vector<pair<ll,ll>> plvec;
typedef vector<tuple<ll,ll,ll>> tvec;
typedef vector<string> svec;

int main(){
    ll n;
    cin>>n;
    lvec a(n);
    rep(i,n){
        cin>>a[i];
        a[i]-=i+1;
    }
    sort(all(a));
    ll b=a[n/2];
    ll ans=0;
    rep(i,n){
        ans+=abs(a[i]-b);
    }
    cout<<ans<<endl;
}

Measured memory_bytes: 1792
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(k,i,n) for(ll i=k;i<n;++i)
int main(void){
    ll n;
    cin>>n;
    vector<ll>a(n);
    rep(0,i,n)cin>>a[i];
    sort(a.begin(),a.end());
    ll b=0;
    rep(0,i,n){
        if(b==a[i]){
            cout<<"NO"<<endl;
            return 0;
        }
        b=a[i];
    }
    cout<<"YES"<<endl;
}

Measured memory_bytes: 1792
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
#define ordered_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update>
using namespace std;
const int RANDOM1 = chrono::high_resolution_clock::now().time_since_epoch().count();
struct chash {
    int operator()(int x) const { return hash<int>{}(x ^ RANDOM1); }
};
#define ll long long
#define mod 1000000007
#define pb push_back
#define mp make_pair
#define deb(x) cout<<#x<<" : "<<x<<"\n";
#define debug(x,y) cout<<#x<<" : "<<x<<"\t"<<#y<<" : "<<y<<"\n";
#define ff first
#define ss second
#define ub upper_bound
#define lb lower_bound
#define all(a) (a).begin(),(a).end()
#define bs binary_search
#define sz size()
#define vi vector<int>
#define pii pair<int,int>
#define pll pair<ll,ll>
#define ld long double
#define clr fflush(stdout);
//#define clr cout.flush();
#define N 100001
#define fpr(i,a,b) for(int i=a;i<b;i++)
#define fdr(i,a,b) for(int i=a;i>b;i--)
#define repp(i,a,b,d) for(int i=a;i<b;i+=d)
#define repd(i,a,b,d) for(int i=a;i>b;i-=d)
#define LLMIN LLONG_MIN
#define LLMAX LLONG_MAX
#define AKASH_PATEL ios_base::sync_with_stdio(false);
#define SVNIT_SURAT cin.tie(NULL);cout.tie(NULL);
#define mset(x,a) memset(x,a,sizeof(x));
#define nl cout<<'\n';
#define print(c) cout<<c<<'\n';
#define setp(n) cout << fixed << setprecision(n)
#define take_arr(a,n) fpr(i,0,n) cin>>a[i];
#define print_arr(a,n) for(int i=0;i<n;i++) {cout<<a[i]<<" ";} cout<<'\n';
#define take_mat(mat,n,m) fpr(i,0,n) fpr(j,0,m) cin>>mat[i][j];
#define set_mat(mat,n,m,k) fpr(i,0,n) fpr(j,0,m) mat[i][j]=k;
#define print_mat(dist,n,m) for(int i=0;i<n;i++){for(int j=0;j<m;j++){cout<<dist[i][j]<<" ";}cout<<'\n';}
template< class T > bool inside(T a, T b, T c) { return a<=b && b<=c; }
int main()
{
    AKASH_PATEL;
    SVNIT_SURAT;
    ll a,b,c;
    cin>>a>>b>>c;
    ll t1=4*a*b;
    ll t2=(c-a-b)*(c-a-b);
    if(c-a-b>0 && t1<t2)
    {
        print("Yes")
    } else{
        print("No")
    }
    return 0;
}





Measured memory_bytes: 256
k = ['R','U','D']
g = ['L','U','D']

s = input()
for i in range(len(s)):
  if s[i] == 'U' or s[i] == 'D':
    continue
  else:
    if i%2 != 0:
      if s[i] != 'L':
        print("No")
        exit()
    else:
      if s[i] != 'R':
        print("No")
        exit()
print("Yes")

Measured memory_bytes: 38384
# Ref : https://qiita.com/ct158603292321/items/11122ba8a5be3c97912b
import numpy as np
N, M = map(int, input().split())
L = []
for i in range(M):
    #a = list(map(int, input().split()))
    *a, = map(int, input().split())
    L.append(a[1:])
*P, = map(int, input().split())

ans = 0
for n in range(2 ** N):
    tmp = np.array([n >> s & 1 for s in range(N)])
    S = []
    for i in L :
        s = sum(tmp[np.array(i) - 1]) % 2
        S.append(s)
    if P == S :
        ans += 1
print(ans)

Measured memory_bytes: 12408
#include<iostream>
#include<string>
#include <cmath>
#include <algorithm>
#include <vector>
#include <cstdint>
#include <map>
#define MOD 1000000007
using namespace std;
typedef long long ll;

int main(){

int a,b;
cin >> a >> b;

int ans = b/100 - a/100 - 1;

if(a/10000 + (a/1000 % 10)*10 >= a%100) ans++;
if(b/10000 + (b/1000 % 10)*10 <= b%100) ans++;

cout << max(ans,0) << endl;

return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define REP(i, n) for (int i = (0); i < (n); ++i)
#define ALL(obj) (obj).begin(), (obj).end()
#define DEBUG(val) cout << #val << " : " << val << endl
#define MOD 1000000007

constexpr int mod = 1000000007;
class mint {
 public:
  long long x;
  constexpr mint(long long x = 0) : x((x % mod + mod) % mod) {}
  constexpr mint operator-() const { return mint(-x); }
  constexpr mint& operator+=(const mint& a) {
    if ((x += a.x) >= mod) x -= mod;
    return *this;
  }
  constexpr mint& operator-=(const mint& a) {
    if ((x += mod - a.x) >= mod) x -= mod;
    return *this;
  }
  constexpr mint& operator*=(const mint& a) {
    (x *= a.x) %= mod;
    return *this;
  }
  constexpr mint operator+(const mint& a) const {
    mint res(*this);
    return res += a;
  }
  constexpr mint operator-(const mint& a) const {
    mint res(*this);
    return res -= a;
  }
  constexpr mint operator*(const mint& a) const {
    mint res(*this);
    return res *= a;
  }
  constexpr mint pow(long long t) const {
    if (!t) return 1;
    mint a = pow(t >> 1);
    a *= a;
    if (t & 1) a *= *this;
    return a;
  }

  // for prime mod
  constexpr mint inv() const { return pow(mod - 2); }
  constexpr mint& operator/=(const mint& a) { return (*this) *= a.inv(); }
  constexpr mint operator/(const mint& a) const {
    mint res(*this);
    return res /= a;
  }
};

istream& operator>>(istream& is, const mint& m) {
  is >> m.x;
  return is;
}

ostream& operator<<(ostream& os, const mint& m) {
  os << m.x;
  return os;
}

mint choose(long long n, long long a) {
  mint x, y;
  x.x = 1;
  y.x = 1;
  for (long long i = (0); i < (a); ++i) {
    x *= n - i;
    y *= i + 1;
  }
  return x / y;
}

map<ll, int> ret;
void prime_factor(ll n) {
  for (ll i = 2; i * i <= n; i++) {
    while (n % i == 0) {
      ret[i]++;
      n /= i;
    }
  }
  if (n != 1) ret[n] += 1;
}

int main() {
  int n;
  mint ans_mint;
  cin >> n;
  ans_mint.x = 1;
  FOR(i, 1, n + 1) { prime_factor(i); }

  for (auto iter = ret.begin(); iter != ret.end(); iter++) {
    mint tmp;
    tmp.x = (iter->second) + 1;
    ans_mint *= tmp;
  }

  cout << ans_mint << endl;
}

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

int main() {
    int n;
    cin >> n;
    vector<string> s(n);
    for(int i = 0; i < n; i++){
        cin >> s[i];
    }
    sort(s.begin(), s.end());
    int count = 1;
    for(int i = 0; i < n-1; i++){
        if(s[i] != s[i+1]){
            count++;
        }
    }
    cout << count;
}

Measured memory_bytes: 9592
package main

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

func newScanner() *bufio.Scanner {
	scanner := bufio.NewScanner(os.Stdin)
	scanner.Split(bufio.ScanWords)
	// buf := make([]byte, 10000)
	// scanner.Buffer(buf, 1000000)
	return scanner
}

func scanInt(s *bufio.Scanner) int {
	if s.Scan() {
		t := s.Text()
		v, err := strconv.Atoi(t)
		if err == nil {
			return v
		}
		panic(err)
	} else {
		panic(s.Err())
	}
}

func scanString(s *bufio.Scanner) string {
	if s.Scan() {
		return s.Text()
	}
	panic(s.Err())
}

func main() {
	var a, b int
	fmt.Scan(&a, &b)

	as := strconv.Itoa(a)
	bs := strconv.Itoa(b)

	for i := 0; i < a-1; i++ {
		bs += strconv.Itoa(b)
	}

	for i := 0; i < b-1; i++ {
		as += strconv.Itoa(a)
	}

	if as < bs {
		fmt.Println(as)
	} else {
		fmt.Println(bs)
	}
}


Measured memory_bytes: 640
#include<bits/stdc++.h>
using namespace std;
struct E{long long t,c;};
vector<E>G[1<<17];
long long z[1<<17];
int n,a,b,c,q,i,j;
void d(int x,int p){
  for(auto &e:G[x])if(e.t-p)z[e.t]=z[x]+e.c,d(e.t,x);
}
main(){
  for(cin>>n;++i<n;G[a].push_back({b,c}),G[b].push_back({a,c}))scanf("%d%d%d",&a,&b,&c);
  for(cin>>q>>n,d(n,0);j++<q;printf("%lld\n",z[a]+z[b]))scanf("%d%d",&a,&b);
}


Measured memory_bytes: 14976
#define __USE_MINGW_ANSI_STDIO 0
#include <iostream>
#include <string>
#include <vector>
#include <stdio.h>
#include <cstdlib>
#include <algorithm>
#include <cmath>
#include <set>
#include <numeric>
#include <bitset>
#include <map>
#include <limits.h>
using namespace std;
typedef unsigned long ul;
typedef pair<ul, ul> P;
const int INF = 1e9;




int main(){
    int N;
    long long K;
    cin >> N >> K;
    long long ans[100000+1] = {};
    for(int i = 0; i < N;i++){
        int a,b;
        cin >> a >> b;
        ans[a] += b;
    }
    long long tmp;
    for(int i = 1; i <= 100000;i++){
        tmp += ans[i];
        if(tmp >= K){
            cout << i << endl;
            break;
        }
     
    }
return 0;

}


Measured memory_bytes: 1024
#include <iostream>
#include <iomanip>
#include <utility>
#include <cmath>
#include <random>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <string>
#include <algorithm>
using namespace std;

#define rep(i,n) for(int i = 0; i<n; ++i)
const int INF = 100100100;
const int MOD = (int)1e9 + 7;
typedef long long ll;

int main(){
    int r; cin >> r;
    if(r<1200)cout << "ABC" << endl;
    else if(r<2800) cout << "ARC" << endl;
    else cout << "AGC" << endl;
}


Measured memory_bytes: 256
import java.util.*;
import java.io.InputStreamReader;
import java.io.BufferedReader;

public class Main {
    public static void main(String[] args) throws Exception {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        String[] s = br.readLine().split(" ");
        long r = Long.parseLong(s[0]);
        long d = Long.parseLong(s[1]);
        long x2000 = Long.parseLong(s[2]);
        //int ans = b;
        
        
        long ans = x2000;
        for (int i = 0; i < 10; i++) {
            ans = r*ans-d;
            System.out.println(ans);
        }

        //System.out.println(ans);
    }
}





Measured memory_bytes: 21204
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int a,b,c=0,i;
    string s,p;
    cin>>s>>p;
    for(i=0;i<s.size();i++)
    {
        if(s[i]==p[i])
        {
            c++;
        }
    }
    a=s.size()-c;
    cout<<a;
}

Measured memory_bytes: 3864
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
using namespace std;
 
int main() {
  int N, ans;
  cin >> N;
  ans = 0;
  int A[N];
  rep (i, N) cin >> A[i];
  for (int i = 0; i < N; ++i) {
    if (A[i] % 2 == 0) {
      if (A[i] % 3 != 0 && A[i] % 5 != 0) {
        ++ans;
      }
    }
  }
  if (ans == 0) {
    printf("APPROVED\n");
  }
  else {
    printf("DENIED\n");
  }
  return 0;
}

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

using ll = long long;
using pii = pair<int, int>;
template <class T>
using v = vector<T>;
template <class T>
using vv = v<v<T>>;
#define ALL(c) (c).begin(), (c).end()

int main()
{
    string S, T;
    cin >> S >> T;
    int ans = INT32_MAX;
    for (int i = 0; i < S.size() - T.size()  + 1; i++)
    {
        int ans_b = 0;
        for (int j = 0; j < T.size(); j++)
        {
            if (S[i + j] != T[j])
            {
                ans_b++;
            }
        }
        ans = min(ans_b, ans);
    }

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 3592
function Main(S) {
    max = 0;
    ACGT = S.trim().match(/(A|C|G|T)+/g);
    if (!ACGT) ACGT = [];
    for (i = 0; i < ACGT.length; i++)
        if (ACGT[i].length > max)
            max = ACGT[i].length;
    console.log(max);
}
Main(require("fs").readFileSync("/dev/stdin", "utf8"));

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

using namespace std;

int A[200000];
int cou[200000];

int main()
{
  int N,K;
  cin>> N>> K;
  for(int i=0;i<N;i++)cin>> A[i];

  int ret=0;
  for(int i=0;i<=N;i++)cou[i]=0;
  for(int i=0;i<N;i++)cou[A[i]]++;
  for(int i=0;i<=N;i++)cerr<< ":"<< i<< " "<< cou[i]<< endl;;
  sort(cou,cou+N,greater<int>());
  for(int i=K;i<=N;i++)ret+=cou[i];
  cout<< ret<< endl;

  return 0;
}


Measured memory_bytes: 1792
import sys
rr = lambda: sys.stdin.readline().strip()
ri = lambda: int(rr())
rs = lambda: [int(_) for _ in rr().split()]

N = int(input())
S = [''] * N
for i in range(N):
    S[i] = input()

a = 0
b = 0
c = 0
cnt = 0
for s in S:
    f = False
    for si in s:
        if not f:
            if si == 'A':
                f = True
        else:
            if si != 'A':
                f = False
            if si == 'B':
                cnt += 1
    if s[-1] == 'A':
        if s[0] == 'B':
            c += 1
        else:
            a += 1
    elif s[0] == 'B':
        b += 1

if a == 0 and b == 0:
    cnt += max(c - 1, 0)
else:
    cnt += min(a, b) + c

print(cnt)

Measured memory_bytes: 45272
#include<iostream>
#include<algorithm>
using namespace std;
int main(){
int n,k;
 cin>>n>>k;
  int arr[n];
  for(int i=0;i<n;i++){
    cin>>arr[i];
  }
  sort(arr,arr+n);
  int res=0;
  int i=0;
  while(k){
    res=res+arr[i];
    i++;
    k--;
  }
  cout<<res;
}
      

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

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

#define rep(a,n) for(int a = 0;a < n;a++)

int toInt(char c) {
	return c - '0';
}

int main(void)
{
	string s;
	cin >> s;
	int n = s.size();
	const ll MOD = (ll)1e9 + 7;
	vector<ll> dp1(n+1, 0);
	vector<ll> dp2(n+1, 0);
	dp2[0] = 1;
	for (int i = 1; i <= n; i++) {
		//1
		if (s[i-1] == '1') {
			//00
			dp1[i] += dp1[i - 1] + dp2[i-1];
			//01,10
			dp1[i] += 2 * dp1[i - 1];
			dp2[i] += 2 * dp2[i - 1];
		}
		//0
		else {
			//00
			dp1[i] += 3 * dp1[i - 1];
			dp2[i] += dp2[i - 1];
		}
		dp1[i] %= MOD;
		dp2[i] %= MOD;
	}
	auto sum = dp1[n] + dp2[n];
	sum %= MOD;
	cout << sum << endl;
	return 0;
}

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

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

int main() {
    ll a,b, c,d;
    cin >> a>>b>>c>>d;
    ll e = b/c - (a-1)/c;
    ll f = b/d - (a-1)/d;
    ll g = c*d/gcd(c,d);
    ll h = b/g - (a-1)/g;
    
    cout << (b-a+1)-(e+f-h) <<endl;
    return 0;
}


Measured memory_bytes: 256