akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;

int main() {
  int A,B,C,D;
  cin>>A>>B>>C>>D;
  if(A+B>C+D){
    cout<<"Left"<<endl;
  }else if(A+B==C+D){
   cout<<"Balanced"<<endl; 
  }else{
   cout<<"Right"<<endl; 
  }
}

Measured memory_bytes: 256
import fractions
A, B, C, D = map(int, input().split())

## b = qa + r
#b = C
#a = D
#r = C%D
#while r != 0:
#    b = a
#    a = r
#    r = b%a
#gcd = a
gcd = fractions.gcd(C, D)
CDlcm = C*D//gcd

total = B-(A-1)
Cmuls = B//C - (A-1)//C
Dmuls = B//D - (A-1)//D
CDmuls = B//CDlcm - (A-1)//CDlcm
ans = total - Cmuls - Dmuls + CDmuls
print(ans)


Measured memory_bytes: 5052
#include <bits/stdc++.h>
#define itn int
#define REP(i, n) for (int i = 0; i < (n); i++)
#define IREP(i, n) for (int i = n - 1; i >= 0; i--)
#define FOR(i, k, n) for (int i = (k); i < (n); i++)
#define REPEACH(itr, k) for (auto &&itr : k)
#define MOD 1000000007

using namespace std;
typedef long long ll;

const ll INF = 1LL<<60;
template<class T> inline bool chmin(T &a, T b){if (a > b){a = b;return true;}return false;}
template<class T> inline bool chmax(T &a, T b){if (a < b){a = b;return true;}return false;}

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

int64_t divc_map(map<int64_t, int> ret)
{
    int64_t res = 1;
    for (auto const &i : ret)
    {
        res *= (i.second+1);
        res %= MOD;
    }
    return res;
}

int main()
{
    int n;
    cin >> n;
    ll ans=1;
    for(int i=1;i<=n;i++){
        prime_factor(i);
    }
    cout << divc_map(ret) << endl;
}

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

int main() {
  int n, a, x, y;
  cin >> n >> a;
  x = n % 500;
  y = x - a;
  if (x = 0 || y <= 0) {
    cout << "Yes" << endl;
  } else {
    cout << "No" << endl;
  }
}


Measured memory_bytes: 256
def warshall_floyd(d,n):
    #d[i][j]: iからjへの最短距離
    for k in range(n):
        for i in range(n):
            for j in range(n):
                d[i][j] = min(d[i][j],d[i][k] + d[k][j])
    return d

H,W = [int(x) for x in input().split()]
C = [[int(x) for x in input().split()]for _ in range(10)]
A = [[int(x) for x in input().split()]for _ in range(H)]
cnt = 0
warshall_floyd(C,10)
for line in A:
    for a in line:
        if(a==-1):
            pass
        else:
            cnt += C[a][1]
print(cnt)


Measured memory_bytes: 3316
#include <iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<string.h>
#include<map>
#include<set>
#include<stack>
#include<queue>
#include<math.h>
using namespace std;
typedef long long ll;
#define int long long
typedef vector<int> VI;
typedef pair<int, int> pii;
typedef vector<pii> VP;
typedef vector<string> VS;
typedef priority_queue<int> PQ;
template<class T>bool chmax(T &a, const T &b) { if (a < b) { a = b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b < a) { a = b; return 1; } return 0; }
#define fore(i,a) for(auto &i:a)
#define REP(i,n) for(int i=0;i<n;i++)
#define eREP(i,n) for(int i=0;i<=n;i++)
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define eFOR(i,a,b) for(int i=(a);i<=(b);++i)
#define SORT(c) sort((c).begin(),(c).end())
#define rSORT(c) sort((c).rbegin(),(c).rend())
#define LB(x,a) lower_bound((x).begin(),(x).end(),(a))
#define UB(x,a) upper_bound((x).begin(),(x).end(),(a))
#define INF 10000000000000
#define LLINF 9223372036854775807
#define mod 1000000007
//priority_queue<int,vector<int>, greater<int> > q2;

#define MAX_V 500
struct edge { int to, cap, rev; };

vector<edge> G[MAX_V];
int level[MAX_V];
int iter[MAX_V];

void add_edge(int from, int to, int cap) {
	G[from].push_back((edge) { to, cap, (int)G[to].size() });
	G[to].push_back((edge) { from, 0LL, (int)G[from].size() - 1 });
}

void bfs(int s) {
	memset(level, -1LL, sizeof(level));
	queue<int> que;
	level[s] = 0;
	que.push(s);
	while (!que.empty()) {
		int v = que.front(); que.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;
				que.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;
		memset(iter, 0, sizeof(iter));
		int f;
		while ((f = dfs(s, t, INF)) > 0) {
			flow += f;
		}
	}
}


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

	int N; cin >> N;
	int sum = 0;
	int s = N, t = N + 1;

	REP(i, N) {
		int a; cin >> a;
		if (a >= 0) {
			add_edge(s, i, 0);
			add_edge(i, t, a);
			sum += a;
		}
		else {
			add_edge(s, i, -a);
			add_edge(i, t, 0);
		}
	}
	REP(i, N) {
		FOR(j, i + 1, N) {
			if ((j + 1) % (i + 1) == 0)add_edge(i, j, INF);
		}
	}
	int res = max_flow(s, t);
	cout << sum - res << endl;
	return 0;
}



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

#include <iostream>
#include <complex>
#include <string>
#include <algorithm>
#include <numeric>
#include <vector>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <unordered_map>
#include <unordered_set>

#include <functional>
#include <cassert>

typedef long long ll;
using namespace std;

#ifndef LOCAL
#define debug(x) ;
#else
#define debug(x) cerr << __LINE__ << " : " << #x << " = " << (x) << endl;

template <typename T1, typename T2>
ostream &operator<<(ostream &out, const pair<T1, T2> &p) {
  out << "{" << p.first << ", " << p.second << "}";
  return out;
}

template <typename T>
ostream &operator<<(ostream &out, const vector<T> &v) {
  out << '{';
  for (const T &item : v) out << item << ", ";
  out << "\b\b}";
  return out;
}
#endif

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


int main() {
  int L, R;

  cin >> L >> R;

  ll ans = LLINF;

  for (int i=L; i<=R; i++) {
    for (int j=i+1; j<=R; j++) {
      ans = min(ans, (ll)i * j % 2019);
      if (ans == 0) break;
    }
    if (ans == 0) break;
  }

  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) repi(i,0,n)
#define repi(i,a,b) for(int i=(int)(a);i<(int)(b);i++)
#define pb push_back
#define MAX 200
typedef pair<int,int> pi;
#define INF (1145141919/3)
int N,M,R;
int G[MAX][MAX], H[MAX][MAX];
int dp[MAX][2];
int main()
{
  while(true)
    {
      cin>>N>>M;
      if(N==0||M==0)return 0;
      rep(i,N)
	{
	  rep(j,N)
	    {
	      G[i][j]=INF;
	      H[i][j]=INF;
	      if(i==j)
		{
		  G[i][j]=0;
		  H[i][j]=0;
		}
	    }
	}
      rep(i,M)
	{
	  int x,y,t; char sl;
	  cin>>x>>y>>t>>sl;
	  x--; y--;
	  if(sl=='L')
	    {
	      G[x][y]=min(t,G[x][y]);
	      G[y][x]=min(t,G[y][x]);
	    }
	  else
	    {
	      H[x][y]=min(t,H[x][y]);
	      H[y][x]=min(t,H[y][x]);
	    }
	}
      rep(k,N)
	{
	  rep(i,N)
	    {
	      rep(j,N)
		{
		  G[i][j]=min(G[i][j],G[i][k]+G[k][j]);
		  H[i][j]=min(H[i][j],H[i][k]+H[k][j]);
		}
	    }
	}

      rep(i,N)
	{
	  dp[i][0]=INF;
	  dp[i][1]=INF;
	}
      
      cin>>R;      
      int now;
      cin>>now;
      now--;
      dp[now][1]=0;
      rep(i,R-1)
	{
	  int z;
	  cin>>z;
	  z--;
	  
	  rep(j,N)//j ni hune wo oiteiku
	    {
	      dp[j][i%2]=min(INF,dp[j][(i+1)%2]+G[now][z]);//hune wo tsukawanai
	      rep(k,N)//k ni hune wo toriniiku
		{
		  dp[j][i%2]=min(dp[j][i%2],dp[k][(i+1)%2]+G[now][k]+H[k][j]+G[j][z]);
		}
	    }
	  /*rep(j,N)
	    {
	      cout << dp[j][i%2] << " ";
	    }
	    cout << endl;*/
	  now=z;
	}
      int ans = INF;
      rep(k,N)
	{
	  ans=min(ans,dp[k][R%2]);
	}
      cout << ans << endl;
    }
}

Measured memory_bytes: 3400
#include <bits/stdc++.h>
using namespace std;
 
#define ll long long
#define vvi vector< vector<int> >
#define vi vector<int>
#define All(X) X.begin(),X.end()
#define FOR(i,a,b) for(int i=(int)(a);i<(int)(b);i++)
#define REP(i,n) for(int i=0;i<(int)(n);i++)
#define pb push_back
#define pii pair<int,int>
#define mp make_pair
#define pi 3.14159265359
#define shosu(X) fixed << setprecision(X)
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
ll lcm(ll a,ll b){return a/gcd(a,b)*b;}
 
int main(){
int a,b;
cin >> a >> b;
REP(i,a){
string s;
cin >> s;
cout << s << endl;
cout << s << endl;
}
}

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

public class Main {
    public static void main(String[] args) {
        MyScanner sc = new MyScanner();
        PrintWriter out = new PrintWriter(new BufferedOutputStream(System.out));
        int n = sc.nextInt();
        int [] p = new int[n];
        int [] a = new int[n + 1];
        for (int i = 0; i < n; i++) {
            p[i] = sc.nextInt();
            a[p[i]] = i;
        }
        TreeSet<Integer> set = new TreeSet<>();
        long res = 0;
        for (int i = n; i >= 1; i--) {
            int idx = a[i];
            if (i == n) {
                set.add(idx);
                continue;
            }
            Integer lower = set.lower(idx);
            Integer higher = set.higher(idx);
            if (lower == null) {
                Integer above = (set.higher(higher) == null ? n - 1 : set.higher(higher) - 1);
                res += ((long) above - higher + 1) * (idx + 1) * i;
                set.add(idx);
                continue;
            } else if (higher == null) {
                Integer below = (set.lower(lower) == null ? 0 : set.lower(lower) + 1);
                res += ((long)lower - below + 1) * (n - idx) * i;
                set.add(idx);
                continue;
            }
            Integer below = (set.lower(lower) == null ? 0 : set.lower(lower) + 1);
            Integer above = (set.higher(higher) == null ? n - 1 : set.higher(higher) - 1);
            res = res + ((long) idx - (lower + 1) + 1) * (above - higher + 1) * i;
            res = res + ((long) (higher - 1) - idx + 1) * (lower - below + 1) * i;
            set.add(idx);
        }
        out.println(res);
        out.close();
    }


    //-----------MyScanner class for faster input----------
    public static class MyScanner {
        BufferedReader br;
        StringTokenizer st;

        public MyScanner() {
            br = new BufferedReader(new InputStreamReader(System.in));
        }

        String next() {
            while (st == null || !st.hasMoreElements()) {
                try {
                    st = new StringTokenizer(br.readLine());
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
            return st.nextToken();
        }

        int nextInt() {
            return Integer.parseInt(next());
        }

        long nextLong() {
            return Long.parseLong(next());
        }

        double nextDouble() {
            return Double.parseDouble(next());
        }

        String nextLine() {
            String str = "";
            try {
                str = br.readLine();
            } catch (IOException e) {
                e.printStackTrace();
            }
            return str;
        }


    }

}

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

double dis(double xa, double ya, double xb, double yb){
    double disx, disy, result;
    
    disx = fabs(xa - xb);
    disy = fabs(ya - yb);
    result = sqrt(pow(disx, 2) + pow(disy, 2));
    
    return result;
}

double sumr(double ra, double rb){
    double result;
    
    result = ra + rb;
    
    return result;
}

double gapr(double ra, double rb){
    double result;
    
    result = fabs(ra - rb);
    
    return result;
}

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

    int num;
    int i;
    double distance, sumradius, gapradius;
    double xa, ya, ra, xb, yb, rb;
    
    scanf("%d",&num);
    for (i = 0; i < num; i++) {
        scanf("%lf %lf %lf %lf %lf %lf",&xa ,&ya ,&ra ,&xb ,&yb ,&rb);
        distance = dis(xa, ya, xb, yb);
        //printf("%f\n",distance);
        sumradius = sumr(ra, rb);
        //printf("%f\n",sumradius);
        gapradius = gapr(ra, rb);
        //printf("%f\n",gapradius);
        
        if (distance < gapradius) printf("%d\n",(1 - 2 *(ra < rb)) * 2);
        else if (gapradius <= distance && distance <= sumradius) printf("1\n");
        else if (sumradius < distance) printf("0\n");
    }
    return 0;
}

Measured memory_bytes: 648
#include <bits/stdc++.h>
using namespace std;
#define debug(x) cerr << #x << ": " << x << endl; 
#define MAX_K 1001
#define rep(i, n) for(int i=0; i<n; i++)
int N, K;
int s[3*MAX_K][3*MAX_K], a[2][MAX_K][MAX_K];
signed main(void){
	cin >> N >> K;
	for(int i=0; i<N; i++){
		int x, y;
		char c;
		cin >> x >> y >> c;
		if(c == 'B') x += K;
		x %= 2*K;
		y %= 2*K;
		s[x][y]++;
		s[x + K][y]--;
		s[x][y + K]--;
		s[x + K][y + K]++;
	}

	rep(i, 3*K) rep(j, 3*K) s[i][j+1] += s[i][j];
	rep(i, 3*K) rep(j, 3*K) s[i+1][j] += s[i][j];
	rep(i, 3*K) rep(j, 3*K){
		int k = (i / K + j / K) % 2;
		a[k][i%K][j%K] += s[i][j];
	} 
	rep(k, 2) rep(i, K){
		rep(j, K) cerr << a[k][i][j] << ' ';
		cerr << endl;
	}
	int ret = 0;
	rep(k, 2) rep(i, K) rep(j, K) ret = max(ret, a[k][i][j]);
	cout << ret << endl;
}

Measured memory_bytes: 43264
#include<stdio.h>
#include <algorithm>
#include <cassert>
#include <cctype>
#include <climits>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <iostream>
#include <iterator>
#include <list>
#include <map>     
#include <numeric>
#include <utility>
#include <queue>
#include <set>
#include <sstream>
#include <iomanip>
#include <stack>
#include <string>
#include <vector>
using namespace std;
#define ll long long
#define ld long double
#define rep(a,t) for(int a=0;a<t;++a) 
#define forever while(true)
#define Sort(a) sort(a.begin(),a.end())
#define Reverse(a) reverse(a.begin(),a.end())
#define pb push_back
#define int_maxvalue numeric_limits<int>::max()
#define print_double(val,a) cout << fixed << setprecision(a) << val << endl;
ll mod = 1e9 + 7;
int main()
{
	cin.tie(0);
	ios::sync_with_stdio(false);
	vector<int>a(3);
	cin >> a[0] >> a[1] >> a[2];
	Sort(a);
	int n;
	cin >> n;
	int maxval = a[2];
	rep(i, n) {
		maxval *= 2;
	}
	cout << maxval + a[0] + a[1] << endl;
	return 0;
}


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

int main() {
  int n, k;
  cin >> n >> k;
  int ans = 0;
  for (int i = 0; i < n; i++){
    int x;
    cin >> x;
    ans += min(x, abs(k - x)) * 2;
  }
  cout << ans << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll mod=1e9+7;
const int maxn=1e4+5;
const int maxm=5e2+5;
const int maxq=55;
const int INF=0x3f3f3f3f;
int main()
{
    int k;
    while(~scanf("%d",&k))
    {
        int even=k/2;
        int odd=k-even;
        int ans=even*odd;
        printf("%d\n",ans);
    }
}


Measured memory_bytes: 256
w = input()

str =""
while True:
        t =  input()
        if t == "END_OF_TEXT":
                break
        else:
                str += t + " "
        
str = str.lower()

num = 0
i = -1
l = len(w)

while True:
        i = str.find(w, i + 1)
        if i == -1:
                break
        elif (i == 0 or str[i-1] == " ") and (i+l == len(str) or str[i+l] == " " or str[i+l] == "." or str[i+l] == ","):
                num += 1

print(num)


Measured memory_bytes: 5556
#include <iostream>
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#define lli long long int
using namespace std;
#define S second
#define F first
#define pb push_back 
#define M1 1000000007
#define M2 998244353
#define plli pair<lli,lli>
#define setit set<lli>::iterator seti
#define mapit map<lli,lli> ::iterator mapi
#define MP make_pair
#define MT make_tuple
// map      iterator->first  iterator.first
// map      mp[key]=value
// set      *s.begin()
// vector   v[j]=value
// pair     p.first p.second
// vector of pairs v[j].first v[j].second
// tuple    get<index>(tuple_name)
// vector of tuples get<index>(v[j])  sort(v.begin(),v.end())
//priority queue .top() .pop() .push()
// __gcd(x,y)
#define mini(x,y) (y + ((x - y) & ((x - y) >>(sizeof(int) * CHAR_BIT - 1))))
#define maxi(x,y) (x - ((x - y) & ((x - y) >> (sizeof(int) * CHAR_BIT - 1))))
#define fr(j,a,b) for(j=a;j<b;j++)

int power(int x, unsigned int y, int p)  
{    int res = 1;    
     x = x % p;
     if (x == 0) return 0;
     while (y > 0)  
     {  if (y & 1)  
        res = (res*x) % p;  
        y = y>>1;
        x = (x*x) % p;  
     }  
    return res;  
}

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    lli t,i,j,n,x;
    cin>>n;
    x=n%10;
    if(x==3){cout<<"bon";}
    else if(x==0||x==1||x==6||x==8){cout<<"pon";}
    else{cout<<"hon";}
}

Measured memory_bytes: 3612
def main():

    N, K = map(int, input().split())

    nums = [i for i in range(N + 1)]
    total = 0


    mini = sum(nums[0:K])
    maxx = sum(nums[-K:])


    for i in range(K, N + 1):
        total += maxx - mini + 1

        index = i + 1
        
        if (i == N):
            break
        else:
            mini += nums[index-1]
            maxx += nums[-index]

    total += 1
    ans = total % (10 ** 9 + 7)

    print(ans)

if __name__ == '__main__':
    main()

Measured memory_bytes: 18428
#include <cstdio>
#include <algorithm>
#include <queue>
using namespace std;

int N, M, P, A[5050], B[5050], C[5050];
bool visit[2555], rvisit[2555]; long long dist[2555];
bool nvisit[2555]; long long ndist[2555];

int main()
{
	scanf ("%d %d %d", &N, &M, &P);
	for (int i = 0; i < M; i++) scanf ("%d %d %d", &A[i], &B[i], &C[i]), C[i] -= P;

	for (int i = 1; i <= N; i++) dist[i] = -1e18;
	visit[1] = 1; dist[1] = 0;
	rvisit[N] = 1;
	for (int k = 0; k < N; k++){
		for (int i = 1; i <= N; i++){
			nvisit[i] = 0;
			ndist[i] = -1e18;
		}
		for (int i = 0; i < M; i++){
			if (visit[A[i]]){
				if (ndist[B[i]] < dist[A[i]] + C[i]){
					ndist[B[i]] = dist[A[i]] + C[i];
					nvisit[B[i]] = 1;
				}
			}
			if (rvisit[B[i]]) rvisit[A[i]] = 1;
		}
		for (int i = 1; i <= N; i++) if (nvisit[i]){
			visit[i] = 1;
			dist[i] = max(dist[i], ndist[i]);
		}
	}

	for (int i = 0; i < M; i++) if (visit[A[i]] && rvisit[A[i]] && visit[B[i]] && rvisit[B[i]]){
		if (dist[B[i]] < dist[A[i]] + C[i]){
			puts("-1");
			return 0;
		}
	}
	printf ("%lld\n", max(0ll, dist[N]));
	return 0;
}


Measured memory_bytes: 384
(defun main ()
  (let ((a (read))
        (b (read))
        (c (read))
        (k (read))
        (ans 0))
    (if (<= k a)
        (setf ans k)
        (progn
          (setf ans a)
          (setf k (- k a))
               (unless (<= k b)
                 (setf k (- k b))
                 (setf ans (- ans k)))))
    (format t "~d~%" ans)))

(main)
                 


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

#define ll long long
#define vi vector<int>
#define vl vector<ll>
#define pii pair<int,int>
#define pll pair<ll,ll>
// pll pp; -> (pp.first,pp.second)
// vector<vl> pp(n,vl(2)); sort(pp.begin(),pp.end(),[](vl a,vl b){return a[0]<b[0];});

#define REP(i,n) for(ll (i)=0;(i)<(n);(i)++)
#define RREP(i,n) for(ll (i)=(n)-1;(i)>=0;(i)--)
#define FOR(i,a,b) for(ll (i)=(a);(i)<(b);(i)++)
#define FORR(i,a,b) for(ll (i)=(b)-1;(i)>=(a);(i)--)
#define DEBUG(x) cout << #x << ": " << x << endl
#define CHMAX(a,b) a=max((a),(b))
#define CHMIN(a,b) a=min((a),(b))
/*}}}*/
int main() {
  ll n,u,v;
  cin >> n >> u >> v;
  u--;
  v--;

  vector<vl> edge(n,vl(0));

  REP(i,n-1){
    ll a,b;
    cin >> a >> b;
    a--;
    b--;
    edge[a].push_back(b);
    edge[b].push_back(a);
  }

  vl vdist(n,1e9);
  vdist[v] = 0;

  queue<ll> que;
  que.push(v);

  while(!que.empty()){
    ll node = que.front();
    que.pop();
    REP(i,edge[node].size()){
      ll ch = edge[node][i];
      if(vdist[ch]!=1e9) continue;
      vdist[ch] = vdist[node]+1;
      que.push(ch);
    }
  }

  vl udist(n,1e9);
  udist[u] = 0;

  ll ans = 0;
  que.push(u);
  while(!que.empty()){
    ll node = que.front();
    que.pop();
    REP(i,edge[node].size()){
      ll ch = edge[node][i];
      if(udist[ch]!=1e9) continue;
      udist[ch] = udist[node]+1;
      que.push(ch);
    }
  }

  REP(i,n){
    if(vdist[i]>udist[i]) CHMAX(ans,vdist[i]);
  }
  
  //cout << fixed << setprecision(10);
  cout << ans-1 << endl;
  return 0;
}


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

#include <algorithm>
#include <bitset>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <vector>

constexpr long long INFLL = 1e18;

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

int main() {
  int h, w;
  cin >> h >> w;
  int ch, cw, dh, dw;
  cin >> ch >> cw >> dh >> dw;
  ch--;
  cw--;
  dh--;
  dw--;
  char temp;

  vector<vector<int>> s(h, vector<int>(w));
  for (int i = 0; i < h; i++) {
    for (int k = 0; k < w; k++) {
      cin >> temp;
      if (temp == '.') {
        s.at(i).at(k) = 1e6;
      } else {
        s.at(i).at(k) = -10;
      }
    }
  }
  vector<int> x = {1, 0, -1, 0};
  vector<int> y = {0, 1, 0, -1};
  queue<P> que;
  int count = 0;
  que.emplace(ch, cw);
  int th, tw;

  vector<int> wx = {2, 1, 0, -1, -2};
  vector<int> wy = {2, 1, 0, -1, -2};
  queue<P> wq;
  bool check;

  while (!que.empty() || !wq.empty()) {
    while (!que.empty()) {
      th = que.front().first;
      tw = que.front().second;
      check = false;

      for (int i = 0; i < 4; i++) {
        if (y.at(i) + th >= h || x.at(i) + tw >= w || y.at(i) + th < 0 ||
            x.at(i) + tw < 0) {
          continue;
        }
        if (s.at(y.at(i) + th).at(x.at(i) + tw) == -10) {
          check = true;
        }
        if (s.at(y.at(i) + th).at(x.at(i) + tw) > count) {
          s.at(y.at(i) + th).at(x.at(i) + tw) = count;
          que.emplace(y.at(i) + th, x.at(i) + tw);
        }
      }
      if (check) {
        wq.emplace(th, tw);
      }
      que.pop();
    }

    count++;
    while (!wq.empty()) {
      th = wq.front().first;
      tw = wq.front().second;
      for (int i = 0; i < 5; i++) {
        for (int k = 0; k < 5; k++) {
          if (wy.at(i) + th >= h || wx.at(k) + tw >= w || wy.at(i) + th < 0 ||
              wx.at(k) + tw < 0) {
            continue;
          }
          if (s.at(wy.at(i) + th).at(wx.at(k) + tw) > count) {
            s.at(wy.at(i) + th).at(wx.at(k) + tw) = count;
            que.emplace(wy.at(i) + th, wx.at(k) + tw);
            // wq.emplace(i + th, i + tw);
          }
        }
      }
      wq.pop();
    }
  }

  if (s.at(dh).at(dw) == 1e6) {
    cout << -1 << endl;
  } else {
    cout << s.at(dh).at(dw) << endl;
  }
  /*
    for (int i = 0; i < h; i++) {
      for (int k = 0; k < w; k++) {
        cout << s.at(i).at(k) << ' ';
      }
      cout << endl;

    }
    */

  return 0;
}

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

const int INF = 1e9;
const int MOD = 1e9+7;
const ll LINF = 1e18;

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n) for(int i=0;i<(n);++i)
#define REPR(i,n) for(int i=n;i>=0;i--)
#define ALL(v) (v).begin(),(v).end()
#define COUT(x) cout<<(x)<<"\n"



int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n;
    cin >> n;
    int count[5][4][11]={};
    int a,b,c,d;
    REP(i,n){
        cin >> a >> b >> c >> d;
        count[a][b][c]+=d;
    }
    for(int k=1;k<5;k++){
        for(int i=1;i<4;i++){
            cout << " ";
            for(int j=1;j<11;j++){
                cout << count[k][i][j];
                if(j!=10)cout << " ";
            }
            cout << endl;
        }
        if(k!=4)cout << "####################" << endl;
    }
    return 0;
}


Measured memory_bytes: 3176
# -*- coding: utf-8 -*-
import math
while True:
    try:
        list = [float(x) for x in raw_input().split(" ")]
        x = (list[2]*list[4]-list[1]*list[5])/(list[0]*list[4]-list[1]*list[3])
        y = (list[0]*list[5]-list[2]*list[3])/(list[0]*list[4]-list[1]*list[3])
        if x == -0:
            x = 0
        if y == -0:
            y = 0
        print("%.3f %.3f" %(x, y))
    except EOFError:
        break

Measured memory_bytes: 4388
import numpy as np
N = int(input()) 
X_ls = np.array(list(map(int, input().split())))

#N=2
#X_ls =np.array( [1,4])

ans = 0
for p in range(max(X_ls)+1):
    sub = X_ls-p
    ans_1 = sum(sub**2)
    if ans_1 <= ans or ans ==0:
        ans = ans_1
print(ans)

Measured memory_bytes: 27104
#include <bits/stdc++.h>
using namespace std;
#define ll long long 
#define endl "\n"
#define pb push_back
#define f(i,n) for(i=0;i<n;i++)
#define F(i,a,b) for(i=a;a<=b;i++)
#define arr(a,n) for( i=0;i<n;i++)cin>>a[i];
#define fi first
#define se second
#define mp make_pair
#define mod 1000000007
#define YES cout<<"YES"<<endl;
#define Yes cout<<"Yes"<<endl;
#define NO cout<<"NO"<<endl;
#define No cout<<"No"<<endl;
#define yes cout<<"yes"<<endl;
#define no cout<<"no"<<endl;
#define vi vector<ll>
#define ed end()
#define bg begin()
#define sz size()
#define ln length()
#define s() sort(a,a+n);
#define sr() sort(a,a+n,greater<ll>());
#define v()  sort(v.begin(),v.end());
#define vr() sort(v.begin(),v.end(),greater<ll>());
#define mod 1000000007
#define fast() ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
ll gcd(ll a, ll b){if(!b)return a;return gcd(b, a % b);}
ll power(ll x,ll y,ll p){ll res=1;x%=p;while(y>0){if(y&1)res=(res*x)%p;y=y>>1;x=(x*x)%p;}return res;}
int main() {
   /* #ifndef ONLINE_JUDGE
        // for getting input from input.txt
        freopen("input.txt", "r", stdin);
        // for writing output to output.txt
        freopen("output.txt", "w", stdout);
    #endif*/
        

fast();
//ll t;cin>>t;while(t--)
{
   ll a,b;
   cin>>a>>b;
   cout<<a*b<<endl; 
}
return 0;
}

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

int main(){
    int a;
    cin >> a;
    int ans = a + a * a + a * a * a;
    cout << ans << endl;
}

Measured memory_bytes: 3616
import java.util.*;

public class Main{
  public static void main(String[]args){
    Scanner sc = new Scanner(System.in);
    int N = Integer.parseInt(sc.next());
    int K = Integer.parseInt(sc.next());
    String S = sc.next();
    char[] c1 = S.toCharArray();
    char[] c3 = S.toCharArray();
    boolean flag = false;
    int count = 0;
    for(int i = 0; i < N; i++){
      if(flag && c1[i] == 'R'){
        flag = false;
        count++;
      }
      if(count == K){
        break;
      }
      
      if(c1[i] == 'L'){
        flag = true;
        c1[i] = 'R';
      }
    }
    flag = false;
    count = 0;
    for(int i = 0; i < N; i++){
      if(flag && c3[i] == 'L'){
        flag = false;
        count++;
      }
      if(count == K){
        break;
      }
      
      if(c3[i] == 'R'){
        flag = true;
        c3[i] = 'L';
      }
    }
    
    String S1 = new String(c1);
    String S3 = new String(c3);
    
    count = 1;
    int sum1 = 0;
    char bef = S1.charAt(0);
    for(int i = 1; i < N; i++){
      if(S1.charAt(i) == bef){
        count++;
        if(i == N-1){
          sum1 += count-1;
        }
      }else{
        bef = S1.charAt(i);
        sum1 += count-1;
        count = 1;
      }
    }

    count = 1;
    int sum3 = 0;
    bef = S3.charAt(0);
    for(int i = 1; i < N; i++){
      if(S3.charAt(i) == bef){
        count++;
        if(i == N-1){
          sum3 += count-1;
        }
      }else{
        bef = S3.charAt(i);
        sum3 += count-1;
        count = 1;
      }
    }
    
    System.out.println(Math.max(sum1, sum3));
  }
}

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

int main() {
	int N,K,ans=0;
	cin>>N>>K;
vector<bool>S(N,false);
	for(int i=0;i<K;i++){
		int d;
		cin>>d;
		for(int j=0;j<d;j++){
			int A;
			cin>>A;
			S[A-1] = true;
		}
	}
	for(int i=0;i<N;i++){
		if(S[i])ans++;
	}
	cout<<N-ans<<endl;
}

Measured memory_bytes: 3632
//package atcoder.tokio_marine_insurance_2020;

import java.io.*;
import java.util.StringTokenizer;

public class Main {

    public static void main (String[] args) throws Exception {

//        String s = "5 1\n" +
//                "1 0 0 1 0";

//        String s = "5 2\n" +
//                "1 0 0 1 0";

        String s = "40 40\n" +
                "0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0";

//        br = new BufferedReader(new StringReader(s));
        br = new BufferedReader(new InputStreamReader(System.in));
        bw = new BufferedWriter(new OutputStreamWriter(System.out));

        rl(); int N=nin(), K=nin();
        rl(); int A[] = new int[N]; for (int i=0; i<N; ++i) A[i] = nin();
        boolean cont=true;
        while (K>0 && cont) {
            int _A[] = new int[N];
            for (int i=0; i<N; ++i) {
                int from=Math.max(0, i-A[i]);
                ++_A[from];
                int to=i+A[i]+1;
                if (to<N) --_A[to];
            }
            int v=0;
            for (int i=0; i<N; ++i) {
                v+=_A[i];
                A[i] = v;
            }
            cont = false;
            for (int i:A) {
                if (i<N) cont = true;
                break;
            }

            --K;
        }

        bw.write(Integer.toString(A[0]));
        for (int i=1; i<N; ++i) {
            bw.write(" " + Integer.toString(A[i]));
        }
        bw.newLine();
        bw.flush();

    }

    static BufferedReader br;
    static BufferedWriter bw;
    static StringTokenizer st;
    static void rl() throws Exception{
        st = new StringTokenizer(br.readLine());
    }
    static long nlo(){
        return Long.parseLong(st.nextToken());
    }
    static int nin(){
        return Integer.parseInt(st.nextToken());
    }
    /*private static void te(){
      }*/
    static double ndo(){
        return Double.parseDouble(st.nextToken());
    }
    static char[] nca(){
        return st.nextToken().toCharArray();
    }
    static String nstr(){
        return st.nextToken();
    }
}

Measured memory_bytes: 59240
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int x;
		for(int i = 1; ; i++) {
			x = sc.nextInt();
			if(x == 0) {
				break;
			} else {
				System.out.println("Case " + i + ": " + x);
			}
		}
		sc.close();
	}
}


Measured memory_bytes: 41340
#include <bits/stdc++.h>
typedef long long ll;
typedef long double ld;
const int INF=1e9,MOD=1e9+7,ohara=1e6+10;
const ll LINF=1e18;
using namespace std;

#define rep(i,n) for(int (i)=0;(i)<(int)(n);(i)++)
#define rrep(i,a,b) for(int i=(a);i<(b);i++)
#define rrrep(i,a,b) for(int i=(a);i>=(b);i--)
#define all(v) (v).begin(), (v).end()
#define Size(n) (n).size()
#define Cout(x) cout<<(x)<<endl
#define Cerr(x) cerr<<(x)<<endl
#define fi first
#define se second
#define P pair<ll,ll> 
#define m_p make_pair
#define V vector<ll> 

ll n,cnt,ans,a[ohara],b,c,d,tmp,tmpp,m,h,w,x,y,sum,pos,k;
ld doua;
int dy[]={1,0,-1,0};
int dx[]={0,1,0,-1};
//int dy[]={-1,0,1,-1,1,-1,0,1};
//int dx[]={-1,-1,-1,0,0,1,1,1};
string alph("abcdefghijklmnopqrstuvwxyz"),s;
bool fl;
struct edge{int to,cost;};
ll dp[ohara];//太郎が勝ちなら2

//-------------------------↓↓↓↓↓↓------------------------

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

    cin>>n>>k;
    rep(i,n)cin>>a[i];

    rrep(i,1,k+1){
        int ok=0;
        rep(j,n){
            if(i-a[j]>=0)ok=1;
        }
        if(!ok)dp[i]=1;
        else{
            int okk=0;
            ok=0;
            rep(j,n){
                if(i-a[j]>0){
                    if(dp[i-a[j]]==1)ok=1;
                }
                else if(i-a[j]==0){
                    okk=1;
                }
            }
            if(okk)dp[i]=2;
            else dp[i]=(ok==0?1:2);
        }
    }

    cout<<(dp[k]==2?"First":"Second")<<"\n";
    return 0;
}


Measured memory_bytes: 3072
#define _USE_MATH_DEFINES
#include<iostream>
#include<cstdlib>
#include<algorithm>
#include<cmath>
#include<string>
#include<set>
#include<map>
#include<stdbool.h>
#include<math.h>
#include<sstream>
#include<math.h>
#include<vector>
#include<functional>
#include<queue>
#include<utility>
#include<bitset>
typedef long long ll;
#define N (1000000000+7)
#define INF 1e16
using namespace std;
typedef pair<ll, ll> P;


int main(void) {
	ll n, a, ans = 0, num = 0;
	cin >> n;
	vector<ll>p, m;
	for (ll i = 0;i < n;i++) {
		cin >> a;
		if (a > 0)p.push_back(a);
		else {
			if (a == 0)num++;
			else m.push_back(a);
		}
	}
	for (ll i = 0;i < (ll)p.size();++i)ans += p[i];
	for (ll i = 0;i < (ll)m.size();++i)ans -= m[i];
	if ((ll)m.size() % 2 == 0) cout << ans << endl;
	else {
		if(num!=0)cout << ans << endl;
		else {
			ll sump = 0, summ = 0;
			ll ma_p = 10000000000, ma_m = -10000000000;
			for (ll i = 0;i < (ll)p.size();++i) {
				if (ma_p > p[i])ma_p = p[i];
			}
			for (ll i = 0;i < (ll)m.size();++i) {
				if (ma_m < m[i])ma_m = m[i];
			}
			if (ma_p > -ma_m) {
				cout << ans + 2 * ma_m << endl;
			}
			else {
				if (ma_p < -ma_m)cout << ans - 2 * ma_p << endl;
				else cout << ans << endl;
			}
		}
	}
	return 0;
}

Measured memory_bytes: 1656
#include <stdio.h>
#include <iostream>
#include <vector>
#include <queue>
#include <stack>
#include <algorithm>

using ll = long long int;
const int INF = (1<<30);
const ll INFLL = (1ll<<60);
const ll MOD = 998244353ll;

#define l_ength size

void mul_mod(ll& a, ll b){
	a *= b;
	a %= MOD;
}

void add_mod(ll& a, ll b){
	a = (a<MOD)?a:(a-MOD);
	b = (b<MOD)?b:(b-MOD);
	a += b;
	a = (a<MOD)?a:(a-MOD);
}

ll dp[3333][6666];

int main(void){
	int n,s,a,i,j;
	std::cin >> n >> s;
	dp[0][0] = 1ll;
	for(i=0; i<n; ++i){
		std::cin >> a;
		for(j=0; j<=s; ++j){
			add_mod(dp[i+1][j],dp[i][j]*2%MOD);
			add_mod(dp[i+1][j+a],dp[i][j]);
		}
	}
	std::cout << dp[n][s] << std::endl;
	return 0;
}


Measured memory_bytes: 97688
#include<bits/stdc++.h>
#define LL long long
#define REP(i,n) for(int i=0;i<(n);++i)
#define REPA(i,n) for(int i=1;i<(n);++i)
#define foreach(i, n) for(auto &i:(n))
#define PII pair<int,int>
#define PLI pair<long long, int>
#define PLL pair<long long, long long>
#define MOD ((int)1e9 + 7)
#define INF ((int)1e9+5)
#define INFLL ((LL)4e18)
#define ALL(x) (x).begin(),(x).end()
#define BIT(x) (1 << (x))
using namespace std;

int main(){
	int a, b;
	cin >> a >> b;
	if(abs(a-b)&1){
		cout << "IMPOSSIBLE" << endl;
	}else{
		cout << (a+b)/2 << endl;
	}
	return 0;
}


Measured memory_bytes: 764
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
int main() {
  char input[100];
  scanf("%s",input);
  char num[5];
  num[0] = input[0];
  num[1] = input[1];
  num[2] = input[2];
  num[3] = input[3];
  int year = atoi(num);
  char mon[3];
  mon[0] = input[5];
  mon[1] = input[6];
  int month = atoi(mon);
  if (year >= 1989 && year < 2019) {
    printf("Heisei\n");
  } else if (year == 2019 && month <= 4) {
    printf("Heisei\n");
  } else {
    printf("TBD\n");
  }
  return 0;
}

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

int main() {
  int n;
  string s;
  cin >> n >> s;
  int b = count(s.begin(), s.end(), 'B'), r = count(s.begin(), s.end(), 'R');
  cout << ((b < r) ? "Yes" : "No") << endl;
  return 0;
}

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

int main()
{
  ll n;
  cin >> n;
  vector<int> a(n, 0);
  vector<ll> ans(n, 0);
  ll fee = 0;
  for (ll i = 0; i < n; i++)
  {
    cin >> a[i];
  }

  ll tmp = 0;
  for (ll i = 0; i < n + 1; i++)
  {
    if (i == n)
    {
      fee += abs(tmp - 0);
      break;
    }

    fee += abs(tmp - a[i]);
    tmp = a[i];
  }

  for (ll i = 0; i < n; i++)
  {
    ans[i] = fee - (abs(a[i] - a[i - 1]) + abs(a[i + 1] - a[i])) + (abs(a[i + 1] - a[i - 1]));
  }

  for (ll i = 0; i < n; i++)
  {
    cout << ans[i] << endl;
  }
}


Measured memory_bytes: 4420
#include <iostream>
#include <vector>
#include <algorithm>
#include <stack>
#include <cmath>

using namespace std;

int main(){
    long long N, M, K;
    cin >> N >> M >>K;

    vector<long long> A(N);
    vector<long long> B(M);
    for(int i=0; i<N; ++i) cin >> A[i];
    for(int i=0; i<M; ++i) cin >> B[i];

    vector<long long> cumsumA(N+1);
    cumsumA[0] = 0; 
    vector<long long> cumsumB(M+1);
    cumsumB[0] = 0;
    for(int i=1; i<=N; ++i) cumsumA[i] = cumsumA[i-1] + A[i-1];
    for(int i=1; i<=M; ++i) cumsumB[i] = cumsumB[i-1] + B[i-1];

    long long ans = 0;
    long long b_p = M;
    
    for(long long i=0; i<=N; ++i){
        long long tmpk = K - cumsumA[i];
        if(tmpk >= 0){
            while( cumsumB[b_p] > tmpk && b_p >=0 ){
                b_p--;
            }
            ans = max(ans, i + b_p);
        }
    }

    cout << ans << endl;
}

Measured memory_bytes: 9596
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#include<math.h>
#define FOR(n) for(int i=0;i<n;i++)
#define FORJ(n) for(int j=0;j<n;j++)
#define PRN(n) printf("%d\n",n)
#define PRF(n) printf("%lf\n",n)
#define PRL(n) printf("%lld\n",n)
#define PRS(s) printf("%s\n",s)
#define PRC(c) printf("%c",c)
#define mod 1000000007
typedef long long int ll;
ll dp[100001];
int u(const void *a, const void *b){
    return *(ll*)a-*(ll*)b;
}
int d(const void *a, const void *b){
    return *(ll*)b-*(ll*)a;
}
int z(int a){
  if(a<1)a*=-1;
  return a;
}
int min(int a,int b){
  if(a>b)return b;
  return a;
}
int max(int a,int b){
  if(a>b)return a;
  return b;
}
int gcd(int a,int b){
  if(!b)return a;
  return gcd(b,a%b);
}
int main(void) {
  int ans=0;
  char s[4],t[4];
  scanf("%s %s",s,t);
  FOR(3)if(s[i]==t[i])ans++;
  PRN(ans);
  return 0;
}

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

using namespace std;

typedef long long ll;

ll MOD = 1000000007;

int main(int, char**) {
	int n;
	cin >> n;
	double ainv;
	for (int i=0; i<n; i++) {
		int a; cin >> a;
		ainv += pow(a, -1);
	}
	cout << setprecision(10) << pow(ainv, -1) << endl;
	return 0;
}

Measured memory_bytes: 256
a=list(map(int,input().split()))
def kaisuu(a,b):
    #aを守りの体力、bを攻めの攻撃力として倒すまでのターン数を計算
    if a%b == 0:
        return a/b
    else:
        return a//b+1
if kaisuu(a[2],a[1])>kaisuu(a[0],a[3]):
    print("No")
else:
    print("Yes")

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

int main(void){
    int n;
    cin>>n;
    int a[n+1];
    for(int i=0;i<n;++i){
        cin>>a[i];
    }
    int mm = *max_element(a,a+n);
    int mi = *min_element(a,a+n);
    cout<<mm-mi<<endl;

}

Measured memory_bytes: 256
#include <iostream>

template <int MOD>
struct ModInt {
    using lint = long long;
    int val;

    // constructor
    ModInt(lint v = 0) : val(v % MOD) {
        if (val < 0) val += MOD;
    };

    // unary operator
    ModInt operator+() const { return ModInt(val); }
    ModInt operator-() const { return ModInt(MOD - val); }
    ModInt inv() const { return this->pow(MOD - 2); }

    // arithmetic
    ModInt operator+(const ModInt& x) const { return ModInt(*this) += x; }
    ModInt operator-(const ModInt& x) const { return ModInt(*this) -= x; }
    ModInt operator*(const ModInt& x) const { return ModInt(*this) *= x; }
    ModInt operator/(const ModInt& x) const { return ModInt(*this) /= x; }
    ModInt pow(lint n) const {
        auto x = ModInt(1);
        auto b = *this;
        while (n > 0) {
            if (n & 1) x *= b;
            n >>= 1;
            b *= b;
        }
        return x;
    }

    // compound assignment
    ModInt& operator+=(const ModInt& x) {
        if ((val += x.val) >= MOD) val -= MOD;
        return *this;
    }
    ModInt& operator-=(const ModInt& x) {
        if ((val -= x.val) < 0) val += MOD;
        return *this;
    }
    ModInt& operator*=(const ModInt& x) {
        val = lint(val) * x.val % MOD;
        return *this;
    }
    ModInt& operator/=(const ModInt& x) { return *this *= x.inv(); }

    // compare
    bool operator==(const ModInt& b) const { return val == b.val; }
    bool operator!=(const ModInt& b) const { return val != b.val; }

    // I/O
    friend std::ostream& operator<<(std::ostream& os, const ModInt& x) noexcept { return os << x.val; }
};

constexpr int MOD = 1e9 + 7;
using mint = ModInt<MOD>;

int main() {
    int m, n;
    std::cin >> m >> n;
    std::cout << mint(m).pow(n) << std::endl;
    return 0;
}



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

//#define int long long
typedef long long ll;
//const int INF = 2e9;
//const ll INF = 9e18;


signed main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    int x1,x2,x3,x4,x5;
    cin >> x1 >> x2 >> x3 >> x4 >> x5;
    int ans = 0;
    if (x1 == 0) ans = 1;
    if (x2 == 0) ans = 2;
    if (x3 == 0) ans = 3;
    if (x4 == 0) ans = 4;
    if (x5 == 0) ans = 5;
    cout << ans << "\n";
}

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

int main() {
  int N;
  cin >> N ;
  int sum=0;
  for(int i =0; i<N;i++){
    int l,r;
    cin >> l >> r;
    sum += r - l + 1;
  }
  cout << sum << endl;
      
    

  // ここにプログラムを追記
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
inline int_fast64_t read(){int_fast64_t x=0,f=1;char c=getchar();while(c<'0'||c>'9'){if(c=='-')f=-1;c=getchar();}while(c>='0'&&c<='9')x=x*10+c-'0',c=getchar();return x*f;}
inline string read_s(){string s="";char c=getchar();while(c<'!'||c>'~'){c=getchar();}while(c>='!'&&c<='~'){s+=c;c=getchar();}return s;}
void Main(){
    int N = read(), ans = 0;
    int V[N], C[N];
    for (auto &v:V) v = read();
    for (auto &c:C) c = read();
    for (int i = 0; i<N; i++) {
        if (V[i]>C[i]) ans += V[i]-C[i];
    }
    printf("%d\n", ans);
}
int main(){cin.tie(nullptr);ios::sync_with_stdio(false);Main();return 0;}

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

int main(){
	int H,W;
	cin >> H >> W;
	vector< vector<int> > A(H,vector<int>(W));
	vector< vector<int> > B(H,vector<int>(W));
	int M = (H+W)*81;
	vector< vector <vector<bool> > > 
	DP(H,vector<vector<bool>>(W,vector<bool>(M,false)));
	
	
	for (int i = 0; i < H; i++){
		for (int j = 0; j < W; j++){
			cin >> A[i][j];
		}
	}

	for (int i = 0; i < H; i++){
		for (int j = 0; j < W; j++){
			cin >> B[i][j];
		}
	}


	DP[0][0][abs(A[0][0]-B[0][0])] = true;

	for (int i = 0; i < H; i++){
		for (int j = 0; j < W; j++){
			for(int k =0; k < M; k++){
				if(!DP[i][j][k])continue;

				int dis_j = abs(A[i][j+1]-B[i][j+1]);

				if(i < H-1){
					int dis_i = abs(A[i+1][j]-B[i+1][j]);
					DP[i+1][j][abs(k-dis_i)] = true;
					DP[i+1][j][k+dis_i] = true;
				}

				if(j < W-1){
					int dis_j = abs(A[i][j+1]-B[i][j+1]);
					DP[i][j+1][abs(k-dis_j)] = true;
					DP[i][j+1][k+dis_j] = true;
				}
			}
		}
	}

	for(int val = 0; val < M; val++){
		if(DP[H-1][W-1][val]){
			cout << val << endl;
			break;
		}
	}

	return 0;
}

Measured memory_bytes: 10880
N = int(input())
A = [int(input()) for _ in range(N)]
        
x = 0
ans = 0
for i in range(N-1, -1, -1):
    if A[i] > x:
        ans += A[i]
        x = A[i]
    elif x > A[i]:
        ans = -1
        break
    x -= 1
if A[0] > 0:
    ans = -1    
print(ans)

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

#define pb push_back
#define sz(X) ((int)(X).size())
#define all(X) (X).begin(),(X).end()
#define ll long long
#define pi pair<int,int>
const int N=1e5+5,MOD=100;

using namespace std;
int n,k;
string a;
int howmany(int x){
	int ret = 0;
	while(x<k){
		x*=2;
		ret++;
	}
	return ret;
}
double power(int x){
	double ret = 0.5;

	for(int i=1;i<x;i++)ret*=0.5;
	return ret;
}
int main() {
	ios::sync_with_stdio(0);
	cin.tie(0);
	

	scanf("%d %d",&n,&k);
	double ans = 0;
	for(int i=1;i<min(n+1,k);i++){
		int x = howmany(i);
		ans+=(1.0/n)*power(x);
	}

	if(n>=k){
		for(int i=k;i<=n;i++)ans+=1.0/n;
	}

	printf("%.9f\n",ans );
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define ll long long
using namespace std;
int main()
{
    ll int n,h,ara[10040],val[1022],wt[1002];
    cin>>h>>n;
    for(int i=0;i<n;i++)cin>>val[i]>>wt[i];
    ara[0]=0;
    for(ll int i=0;i<h;i++) ara[i+1]=10000000000;

    for(int i=0;i<h;i++)
    {
        for(int j=0;j<n;j++)
        {
        ll int x=i+val[j],y=wt[j];
        x=min(x,h);
        ara[x]=min(ara[x],y+ara[i]);
        }
    }
   cout<<ara[h]<<endl;

}


Measured memory_bytes: 384
#include <algorithm>
#include <iostream>
#include <map>
#include <numeric>
#include <set>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <vector>
#include <queue>
#include <bitset>
#define MOD (1000000007l)
#define INF (1000000007l)
#define rep(i, n) for(long i = 0; i < (n); i++)

long first[310][310];
long second[310][310];

using namespace std;

void solve() {
  long N, M, L;
  cin >> N >> M >> L;

  rep (i, 310) rep(j, 310) first[i][j] = i == j ? 0 : INF;
  rep (i, 310) rep(j, 310) second[i][j] = i == j ? 0 : INF;

  rep (i, M) {
    long a, b, c;
    cin >> a >> b >> c;
    if (c > L) continue;
    first[a][b] = c;
    first[b][a] = c;
  }

  for (long k = 1; k <= N; k++)
    for (long i = 1; i <= N; i++)
      for (long j = 1; j <= N; j++)
        if (first[i][j] > first[i][k] + first[k][j])
          first[i][j] = first[i][k] + first[k][j];

/*
  for (long i = 1; i <= N; i++) {
    for (long j = 1; j <= N; j++) cout << first[i][j] << " ";
    cout << endl;
  }
*/

  rep (i, 310) rep(j, 310)
    if (first[i][j] <= L)
      second[i][j] = 1;

  for (long k = 1; k <= N; k++)
    for (long i = 1; i <= N; i++)
      for (long j = 1; j <= N; j++)
        if (second[i][j] > second[i][k] + second[k][j])
          second[i][j] = second[i][k] + second[k][j];

  long Q;
  cin >> Q;
  rep (i, Q) {
    long s, t;
    cin >> s >> t;
    long ans = second[s][t];
    if (ans >= INF) ans = 0;
    ans--;
    cout << ans << endl;
  }
}

int main(void) {
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout.precision(12);
  solve();
  return 0;
}


Measured memory_bytes: 2048
#include<bits/stdc++.h>
#include<cctype>
using namespace std;
#define rep(i,n) for (int i=0;i<(n);i++)
#define all(v) (v).begin(),(v).end()
typedef long long int ll;
#define pi 3.1415926535897932384
#define E9 1000000000
#define eps 1e-4
#define pii pair<int,int>



int main(){
  int N; cin >> N;
  int A[N]; rep(i,N) cin >> A[i];
  ll x[N];

  int parity = 0;
  ll tot = 0;
  rep(i,N){
    tot += (1-2*parity)*A[i];
    (parity+=1) %= 2;
  } 
  x[0] = tot/2;
  for (int i=1;i<N;i++){
    x[i] = A[i-1] - x[i-1];
  }
  rep(i,N){
    if (i>0) cout << " ";
    cout << 2*x[i];
  }
  cout << endl;
  

  // cout << fixed << setprecision(10);
  
  return 0;
}


Measured memory_bytes: 4772
#include <iostream>
#include <cmath>
#include <vector>
#include <queue>
#include <string>
#include <map>
#include <algorithm>
#include <limits>
#include <ios>
#include <iomanip>
using namespace std;

#define rep(i,N) for(int i=0; i<N; i++)
#define revrep(i,N) for(int i=N-1; i>=0; i--)

typedef long long ll;

int main(void)
{
    int H, W;
    cin >> H >> W;
    
    int h, w;
    cin >> h >> w;

    int ret = H*W;

    ret -= (h*W);
    ret -= (w*(H-h));

    cout << ret << endl;



    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <cmath>

using namespace std;

int main() {
    int N;
    cin >> N;

    int low_bound = N / 1.08f;
    bool has_answer = 0;

    for (int i = low_bound; i * 1.08f <= (N+1); i++) {
        if (floor(i * 1.08) == N) {
            cout<<i<<endl;
            has_answer=true;
        }
    }

    if (!has_answer)
        cout<<":("<<endl;

    return 0;
}

Measured memory_bytes: 256
import java.util.*;
public class Main {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
  int K = sc.nextInt();
  int S = sc.nextInt();
  int counter = 0;
  for(int i = 0;i <= K;i++){
    for(int j = 0;j <= K;j++){
        if(S-i-j >=0 && S-i-j <= K)counter++;
      }
    }
  System.out.println(counter);
}}


Measured memory_bytes: 21844