akhauriyash/Code-Regression huggingface dataset:
import java.util.*;

class Main {
	 
	public static void main(String[] args) {
		
		Scanner cin=new Scanner(System.in);
		
		Dice dice=new Dice();
		
		for(int i=0;i<6;i++) {
			dice.SurfaceNum[i]=cin.nextInt();
		}
		
		int q=cin.nextInt();
		
		for(int i=0;i<q;i++) {
			dice.findRight(cin.nextInt(), cin.nextInt());
		}
	}
	

}


class Dice {
	int SurfaceNum[]=new int[6];
	
	int gridX[]= {1,3,6,4},gridY[]= {1,5,6,2};
	
	int temp=1,i=0,move=0;
	
	void rotateDice(char odr) {
		if(odr=='N') {
			temp=gridY[3];
			System.arraycopy(gridY, 0, gridY, 1, gridY.length-1);
			gridY[0]=temp;
			gridX[0]=gridY[0];
			gridX[2]=gridY[2];
		}
		else if(odr=='S') {
			temp=gridY[0];
			System.arraycopy(gridY, 1, gridY, 0, gridY.length-1);
			gridY[3]=temp;
			gridX[0]=gridY[0];
			gridX[2]=gridY[2];
		}
		else if(odr=='E') {
			temp=gridX[3];
			System.arraycopy(gridX, 0, gridX, 1, gridX.length-1);
			gridX[0]=temp;
			gridY[0]=gridX[0];
			gridY[2]=gridX[2];
		}
		else if(odr=='W') {
			temp=gridX[0];
			System.arraycopy(gridX, 1, gridX, 0, gridX.length-1);
			gridX[3]=temp;
			gridY[0]=gridX[0];
			gridY[2]=gridX[2];
		}
	}
	
	void findRight(int top,int bhd) {
		
		move=0;
		
		if(top!=SurfaceNum[gridX[0]-1]) {
			for(i=1;i<4;i++) {
				if(SurfaceNum[gridX[i]-1]==top)move=i;
			}
			
			if(move!=0) {
				for(i=0;i<move;i++) rotateDice('W');
			}
			else {
				if(SurfaceNum[gridY[1]-1]==top) rotateDice('S');
				else rotateDice('N');
			}
		}
		
		/*for(i=0;i<4;i++) System.out.print(SurfaceNum[gridX[i]-1]+" ");
		System.out.println();
		for(i=0;i<4;i++) System.out.print(SurfaceNum[gridY[i]-1]+" ");
		System.out.println();*/
		
		if(SurfaceNum[gridX[1]-1]==bhd)System.out.println(SurfaceNum[gridY[1]-1]);
		else if(SurfaceNum[gridX[3]-1]==bhd)System.out.println(SurfaceNum[gridY[3]-1]);
		else if(SurfaceNum[gridY[1]-1]==bhd)System.out.println(SurfaceNum[gridX[3]-1]);
		else if(SurfaceNum[gridY[3]-1]==bhd)System.out.println(SurfaceNum[gridX[1]-1]);
		else System.out.println("ERROR");
	}
	

}


Measured memory_bytes: 26480
#include "bits/stdc++.h"
#define ll long long int
using namespace std;
int main()
{
    ll n;
    cin>>n;
    ll ans=0;
    for(ll i=2;i<1000010;i++)
    {
       ll count=0;
        while(n%i==0)
        {
            n/=i;
            count++;
        }
        
        for(ll j=1;j<10000;j++)
        {
            if(count<j)
             break;
            ans++;
 
            count-=j;
            
        }
        
    }
    
    if(n>1)
    { ans++;}
    
    cout<<ans<<endl;
    
    
}


Measured memory_bytes: 3624
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
using VI = vector<int>;
using VL = vector<ll>;
using VS = vector<string>;
template<class T> using PQ = priority_queue<T, vector<T>, greater<T>>;
#define FOR(i,a,n) for(int (i)=(a);(i)<(n);++(i))
#define eFOR(i,a,n) for(int (i)=(a);(i)<=(n);++(i))
#define rFOR(i,a,n) for(int (i)=(n)-1;(i)>=(a);--(i))
#define erFOR(i,a,n) for(int (i)=(n);(i)>=(a);--(i))
#define each(i, a) for(auto &i : a)
#define SORT(i) sort((i).begin(),(i).end())
#define rSORT(i,a) sort((i).begin(),(i).end(),(a))
#define all(i) (i).begin(),(i).end()
#define out(y,x) ((y) < 0 || h <= (y) || (x) < 0 || w <= (x))
#define line cout << "-----------------------------\n" 
#define ENDL(i,n) ((i) == (n) - 1 ? "\n" : " ")
#define stop system("pause")
constexpr ll INF = 1000000000;
constexpr ll LLINF = 1LL << 60;
constexpr ll mod = 1000000007;
constexpr ll MOD = 998244353;
constexpr ld eps = 1e-10;
constexpr ld pi = 3.1415926535897932;
template<class T>inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; }return false; }
template<class T>inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; }return false; }
inline void init() { cin.tie(nullptr); cout.tie(nullptr); ios::sync_with_stdio(false); cout << fixed << setprecision(15); }
template<class T>inline istream& operator>>(istream& is, vector<T>& v) { for (auto& elemnt : v)is >> elemnt; return is; }
template<class T>inline istream& operator>>(istream& is, deque<T>& v) { for (auto& elemnt : v)is >> elemnt; return is; }
template<class T, class U>inline istream& operator>>(istream& is, pair<T, U>& p) { is >> p.first >> p.second; return is; }
template<class T>inline vector<T> vec(size_t a) { return vector<T>(a); }
template<class T>inline vector<T> defvec(T def, size_t a) { return vector<T>(a, def); }
template<class T, class... Ts>inline auto vec(size_t a, Ts... ts) { return vector<decltype(vec<T>(ts...))>(a, vec<T>(ts...)); }
template<class T, class... Ts>inline auto defvec(T def, size_t a, Ts... ts) { return vector<decltype(defvec<T>(def, ts...))>(a, defvec<T>(def, ts...)); }

int main() {
    init();

    int n; ll a, b; cin >> n >> a >> b;
    VL x(n); cin >> x;
    ll ans = 0;
    FOR(i, 1, n)ans += min(b, a * (x[i] - x[i - 1]));
    cout << ans << "\n";
}

Measured memory_bytes: 1024
#include <iostream>
#include <vector>
#include <algorithm>
#include <stack>
#include <string>
#include <map>
#include <functional>
#include <cmath>
#include <cstdio>
using namespace std;

int main(){
  int n;
  cin >> n;
  for(int i = 0; i < n; i++){
    double x1, y1, x2, y2, x3, y3, x, y;
    cin >> x1 >> y1 >> x2 >> y2 >> x3 >> y3;
    x = ((y1-y3) * (y1 * y1 -y2 * y2 +x1 * x1 -x2 * x2) -(y1-y2) * (y1 * y1 -y3 * y3 +x1 * x1 -x3 * x3)) / (2 * (y1-y3) * (x1-x2)-2 * (y1-y2) * (x1-x3));
    y = ((x1-x3) * (x1 * x1 -x2 * x2 +y1 * y1 -y2 * y2) -(x1-x2) * (x1 * x1 -x3 * x3 +y1 * y1 -y3 * y3)) / (2 * (x1-x3) * (y1-y2)-2 * (x1-x2) * (y1-y3));
    double r;
    r = sqrt(pow(x - x1, 2) + pow(y - y1, 2));
    printf("%.3f %.3f %.3f\n", x, y, r);
  }
}

Measured memory_bytes: 1244
import java.util.*;
import java.io.*;
import java.math.*;
 
public class Main {
    public static void main(String[] args) throws Exception {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int m = sc.nextInt();
        long l = 1;
        long prev = 0;
        for(int i = 0; i < n; i++){
            long temp = sc.nextLong()/2;
            l = lcm(l,temp);
            if(i == 0){
                prev = divide2(temp);
            }else{
                if(prev != divide2(temp)){
                    System.out.println(0);
                    return;
                }
            }
        }
        if(m < l){
            System.out.println(0);
        }else{
            if((m/l) % 2 == 0){
                System.out.println(m/(l*2));
            }else{
                System.out.println(1+m/(l*2));
            }
        }
        
    }

    private static long divide2(long l){
        long ret = 0;
        while(l % 2 == 0){
            ret++;
            l /= 2;
        }
        return ret;
    }
    
    private static long gcd(long a, long b)
    {
        while (b > 0)
        {
            long temp = b;
            b = a % b; // % is remainder
            a = temp;
        }
        return a;
    }
    
    private static long lcm(long a, long b)
    {
        return a * (b / gcd(a, b));
    }
}

Measured memory_bytes: 48116
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <list>
#include <set>
#include <numeric>

#include <map>
#include <math.h>
#include <iomanip>
#include <stack>
#include <queue>
#include <bitset>

#define INF 100100100

typedef long long int llint;

using namespace std;

typedef pair<int, int>Pii;

int main() {
	int r, g, b;
	cin >> r >> g >> b;
	if ((r * 100 + g * 10 + b) % 4 == 0)puts("YES");
	else puts("NO");
	return 0;
}

Measured memory_bytes: 256
//Author: Fuadul Hasan(fuadul202@gmail.com)
#include<bits/stdc++.h>
using namespace std;

#define ll long long
const int N   = 2e5 + 5;

int main(){
	
	int n,a,c;
	cin>>n>>a>>c;
	if(a*c>=n){
		cout<<"Yes"<<endl;
	}else{
		cout<<"No"<<endl;
	}


	

	return 0;
}

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

#define mp make_pair
#define pb push_back
#define fi first
#define se second
#define fastt ios_base::sync_with_stdio(false); cin.tie(NULL)
#define debug1(x) cout<<#x<<" : "<<x<<endl
#define debug2(x,y) cout<<#x<<" : "<<x<<" "<<#y<<" : "<<y<<endl
#define debug3(x,y,z) cout<<#x<<" : "<<x<<" "<<#y<<" : "<<y<<" "<<#z<<" : "<<z<<endl

typedef long long ll;
typedef pair<ll,ll> pii;
const ll modd=1e9+7;

ll poww(ll a,ll b){
  ll ans=1;
  while(b>0){
    if(b%2==1) ans=(ans*a);
    a=(a*a);
    b=b/2;
  }
  return ans;
}

/*-----------------------------------------------------------------------*/

int main(){
   fastt;
   
   ll h,w;
   cin>>h>>w;

   string s[h];

   for(ll i=0;i<h;i++)
      cin>>s[i];

   ll dp[h][w];

   memset(dp,0,sizeof(dp));

   dp[0][0]=1;

   for(ll i=0;i<h;i++)
    for(ll j=0;j<w;j++){
       if(i+1<h&&s[i+1][j]=='.')
        dp[i+1][j]=(dp[i+1][j]+dp[i][j])%modd;
       if(j+1<w&&s[i][j+1]=='.')
        dp[i][j+1]=(dp[i][j+1]+dp[i][j])%modd;
    }

   cout<<dp[h-1][w-1]<<endl;
  
   return 0;
}


Measured memory_bytes: 9088
#include<iostream>
#include<vector>
#include<algorithm>
#include<map>
#include<cstring>
#include<math.h>
#include<bitset>
#include<queue>
#include<set>
#include<iomanip>
#include<math.h>
#include<assert.h>
#include<string>
#include<cstdlib>
#include<cctype>
// #include<bits/stdc++.h>
using namespace std;
typedef long long ll;
constexpr ll INF = 1LL << 40;
const double INFD = 1e100;
const ll mod = 1000000007;
const double PI = 3.1415926535897932384626433832795028841971;
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};
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;
}
// ----------------------------------------------------------------------------

int main(){
  int N;
  cin >> N;
  vector<pair<ll,ll>> P(N);
  for(int i=0; i<N; i++){
    ll X,L;
    cin >> X >> L;
    ll r,l;
    r = X-L;
    l = X+L;
    P[i] = make_pair(l,r);
  }
  sort(P.begin(),P.end());
  ll ans = 1;
  ll L = P[0].first;
  for(int i=1; i<N; i++){
    if(P[i].second >= L){
      ans++;
      L = P[i].first;
    }
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 1792
n, m = map(int, input().split())
a = list(map(int, input().split()))
 
needs = [999,2,5,5,4,5,6,3,7,6]

dp=[-1]*(n+10) #needsを探索できるようにするため
dp[0]=0

for i in range(n): #小さい桁数から全探索する
  if dp[i]!=-1:
    for k in sorted(a, reverse=True): #aのうち大きい数字から試す
      matchs = needs[k] #必要なマッチの本数
      dp[i+matchs] = max(dp[i+matchs], dp[i]*10+k) #dpからの遷移
print(dp[n])

Measured memory_bytes: 14836
#include <iostream>
#include <fstream>
#include <vector>
#include <queue>
#include <unordered_map>
#include <map>
#include <string>
#include <iomanip>
#include <cmath>
#include <cstring>
#include <algorithm> 
#include <ctime>

#define MaxN 1005
#define INF 2140000000
 
using namespace std;

int Max=-1,Min=INF,cntmax=0,cntmin=0,N,X;

int main()
{
	cin>>N;
	for(int i=1;i<=N;i++)
	{
		cin>>X;
		if(X>Max)
			Max=X,cntmax=1;
		else if(X==Max) cntmax++;
		if(X<Min)
			Min=X,cntmin=1;
		else if(X==Min) cntmin++;
	}
	if(Min==Max)
	{
		if(2*Min<=N||Min==N-1)
			cout<<"Yes\n";
		else cout<<"No\n";
	}
	else if(Max-Min>=2)
		cout<<"No\n";
	else
	{
		if(Max<=cntmin)
			cout<<"No\n";
		else if(2*Max-cntmin<=N)
			cout<<"Yes\n";
		else cout<<"No\n";
	}
	return 0;
}

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

using namespace std;

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    int n,i,a,b,x;
    cin>>n;
    int arr[n],brr[n];
    i=0,a=1;
    while(i<n) {
      cin>>arr[i];
      brr[i]=arr[i];
      i++;
    }
    i=n-1;
    sort(arr,arr+n);
    b=arr[n-1];
    while(b!=brr[i])
      i--;
    n=i+1;
    i=1,x=brr[0];
    while(i<n) {
      if(brr[i]>=x) {
        a++;
        x=brr[i];
      }
      i++;
    }
    cout<<a<<endl;
    return 0;
}


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

int main() {
    int n;
    cin >> n;
    vector<ll> a(n);
    rep(i, n) {
        cin >> a.at(i);
        a.at(i) *= 2;
    }

    vector<ll> dam(n);
    ll dn = a.at(0) - a.at(n-1);
    for (int i = 1; i < n-1; ++i) {
        dn = a.at(i) - dn;
    }
    dn /= 2;
    dam.at(0) = a.at(n-1) - dn;
    dam.at(n-1) = dn;
    for (int i = 1; i < n-1; ++i) {
        dam.at(i) = a.at(i-1) - dam.at(i-1);
    }
    rep(i,n) {
        cout << dam.at(i);
        if (i < n-1) cout << ' ';
    }
    cout << endl;
    return 0;
}

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

using namespace std;
static const int SIZE = 8;
static const int FREE = 0;
static const int NOT_FREE = 1;

vector<int> row(SIZE, FREE);
vector<int> col(SIZE, FREE);
vector<int> slopeUpperRight(2 * SIZE - 1, FREE);
vector<int> slopeLowerLeft(2 * SIZE - 1, FREE);
vector< vector<char> > field(SIZE, vector<char>(SIZE));

void printBoard()
{
	for (int i = 0; i < SIZE; ++i)
	{
		for (int j = 0; j < SIZE; ++j)
		{
			cout << field[i][j];
		}
		cout << endl;
	}
}

void dfs(int r)
{
	if (r == SIZE)
	{
		printBoard();
		return;
	}
	if (row[r] == NOT_FREE)
	{
		dfs(r + 1);
		return;
	}
	for (int i = 0; i < SIZE; ++i)
	{
		if (col[i] == NOT_FREE || 
			slopeUpperRight[r + i] == NOT_FREE ||
			slopeLowerLeft[r - i + SIZE - 1] == NOT_FREE)
		{
			continue;
		}
		row[r] = col[i] = slopeUpperRight[r + i] = slopeLowerLeft[r - i + SIZE - 1] = NOT_FREE;
		field[r][i] = 'Q';
		dfs(r + 1);
		row[r] = col[i] = slopeUpperRight[r + i] = slopeLowerLeft[r - i + SIZE - 1] = FREE;
		field[r][i] = '.';
	}
}

void solve()
{
	for (int i = 0; i < SIZE; ++i)
	{
		for (int j = 0; j < SIZE; ++j)
		{
			field[i][j] = '.';
		}
	}

	int n;
	cin >> n;
	for (int i = 0; i < n; ++i)
	{
		int r, c;
		cin >> r >> c;
		field[r][c] = 'Q';
		row[r] = NOT_FREE;
		col[c] = NOT_FREE;
		slopeUpperRight[r + c] = NOT_FREE;
		slopeLowerLeft[r - c + SIZE - 1] = NOT_FREE;
	}
	dfs(0);
}

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

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

typedef long long ll;
typedef long double ld;

int Sum(ll x)
{
	int res = 0;
	while (x) {
		res += x % 10;
		x /= 10;
	}
	return res;
}

int Count(ll x)
{
	int res = 0;
	while (x) {
		res++;
		x /= 10;
	}
	return res;
}

vector <ll> seq;

int main()
{
	int k; scanf("%d", &k);
	ll mult = 1;
	for (int i = 0; i <= 15; i++) {
		for (int j = 1; ; j++) {
			if (Count(j) + i > 15) break;
			if (j % 10 == 9) continue;
			ll my = j * mult + (mult - 1);
			ll mysum = Sum(j) + i * 9;
			int mj = j / 10 * 10 + 9;
			ll his = mj * mult + (mult - 1);
			ll hissum = Sum(mj) + i * 9;
			if (ld(my) / mysum <= ld(his) / hissum)
				seq.push_back(j * mult + (mult - 1));
			else break;
		}
		mult *= 10;
		seq.push_back(mult - 1);
	}
	sort(seq.begin(), seq.end());
	assert(k <= seq.size());
	for (int i = 0; i < k; i++)
		cout << seq[i] << endl;
	return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {

        Scanner sc = new Scanner(System.in);
        String s = sc.next();
        int lens = s.length();
        String ans = "Yes";
        int lens2 = (int)(lens-1)/2;

        for(int i=0;i<lens2;i++){
            if (s.charAt(i) != s.charAt(lens2-i-1)) {
                ans = "No";
            }
        }
        for(int i=((lens+3)/2)-1;i<lens;i++){
            if (s.charAt(i) != s.charAt(lens-i-1)) {
                ans = "No";
            }
        }

        System.out.println(ans);

    }
}


Measured memory_bytes: 22740
#include <bits/stdc++.h>
using namespace std;
const int INF=1001001001;
int main() {
    int n;cin>>n;
    vector<int>d(n);
    for(int i=0;i<n;i++)cin>>d[i];
    sort(d.begin(),d.end());
    if(n%2){cout<<0<<endl;return 0;}
    cout<<d[n/2]-d[n/2-1]<<endl;
}

Measured memory_bytes: 640
N, M = map(int,input().split())
num = ["9"]*N
if M == 0:
  if N == 1:
    print(0)
    exit()
  for i in range(N):
    if i == 0:
      num[i] = 1
    else:
      num[i] = 0
  print("".join(map(str,num)))
  exit()
l = [list(map(int,input().split())) for i in range(M)]
l = sorted(l)
if N == 1 and l[0][0]==1 and l[0][1] == 0:
  print(0)
  exit()
for i in range(M):
  if l[i][0] == 1 and l[i][1] == 0:
    print(-1)
    exit()
  if i < M-1 and l[i][0] == l[i+1][0] and l[i][1] != l[i+1][1]:
    print(-1)
    exit()
  num[l[i][0]-1] = l[i][1]
for i in range(N):
  if num[i] == "9" and i != 0:
    num[i] = 0
  elif num[i] == "9" and i == 0:
    num[i] = 1
print("".join(map(str,num)))

Measured memory_bytes: 3064
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
using namespace std;

int main() {
	int N;
	cin >> N;
	vector<int> S(N);
	cin >> S[0];
	for (int i = 1; i < N; i++) {
		int W;
		cin >> W;
		S[i] = S[i - 1] + W;
	}
	auto itr = lower_bound(S.begin(), S.end(), S[N - 1] / 2);
	cout << min(abs(S[N - 1] - 2 * (*itr)), abs(S[N - 1] - 2 * *(itr-1))) << endl;
}

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

#define REP(i,num) for(int i=0;i<(num);++i)
#define ALL(c) c.begin(),c.end()
#define LOOP(i) while(i--)
#define PRINTALL(c) for(auto& x:c){cout<<x<<' ';}cout<<endl;
#define PAIRCOMP(c,comp) [](const pair<ll,ll>& lhs,const pair<ll,ll>& rhs){return lhs.c comp rhs.c;}

using namespace std;
using ll = long long;

constexpr ll atcoder_mod = 1e9+7;

template<typename T=int>
T in(){T x; cin >> x; return (x);}
template<typename T=int,typename C=vector<T>>
C vecin(int N){C x(N);REP(i,N){x[i]=in<T>();}return move(x);}

void vout(){cout << endl;}
template<typename Head,typename... Tail>
void vout(Head&& h,Tail&&... t){cout << ' ' << h;vout(forward<Tail>(t)...);}
void out(){cout << endl;}
template<typename Head,typename... Tail>
void out(Head&& h,Tail&&... t){cout << h;vout(forward<Tail>(t)...);}

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

	int sx=in(),sy=in(),tx=in(),ty=in();
	int dx=tx-sx,dy=ty-sy;
	string S;
	REP(i,dy) S.push_back('U');
	REP(i,dx) S.push_back('R');
	REP(i,dy) S.push_back('D');
	REP(i,dx+1) S.push_back('L');
	REP(i,dy+1) S.push_back('U');
	REP(i,dx+1) S.push_back('R');
	S.push_back('D');
	S.push_back('R');
	REP(i,dy+1) S.push_back('D');
	REP(i,dx+1) S.push_back('L');
	S.push_back('U');
	out(S);
	return 0;
}


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

int main ()
{

    long long int a,b,c,d,e,f,g,h,i,j,k,t,n,sum=0;
    cin >> a>>b;



    if (a==1 && b==2  ||  a==2 && b== 1)
    {
        cout << 3<<"\n";
    }


     else if (a==1 && b==3 ||  a==3 && b== 1)
    {
        cout << 2<<"\n";
    }


     else if (a==2 && b==3 || a==3 && b== 2)
    {
        cout << 1<<"\n";
    }



}


Measured memory_bytes: 256
#include<iostream>
#include<math.h>

using namespace std;

int main(){

    //input
    int a, b, c;
    unsigned long long x;
    unsigned long long ans = 0;
    cin >> a >> b >> c >> x;

    //最小枚数の算出[500,100,50]
    int least[3];
    least[0] = min(a,int(x/500));
    least[1] = min(b,int((x-least[0]*500)/100));
    least[2] = min(c,int((x-least[0]*500-least[1]*100)/50));
//cout << least[0] << "," << least[1] << "," << least[2] << endl;
    //unreachable
    if(least[0]*500+least[1]*100+least[2]*50!=x){
        cout << 0 << endl;
        return 0;
    }

    while(least[1]<=b && least[2]<=c && least[0]>=0){
        int tmp =  min(int((c-least[2])/2),int(least[1]))+1;
        //cout << "[" << least[0] << "," << least[1] << "," << least[2] << "], tmp=" << tmp << endl;
        ans += tmp;
        least[0]--;
        least[1] += 5;
        if(least[1]>b){
            least[2] += (least[1]-b)*2;
            least[1] = b;
        }
    }

    cout << ans << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
//template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
//template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
  
/* attention
    long longのシフト演算には気をつけよう
    タイポした時のデバッグが死ぬほどきつくなるので変数名は最低3字くらい使った方がいいかも
    sizeは(int)とキャストしよう
    ごちゃごちゃ場合分けを考える前に全探索は考えましたか？
*/

const int inf = 1<<29;
int N;
vector<int> fromFen(100005, inf), fromSun(100005, inf);
bool seen[100005];
vector<int> adj[100005];

void bfs(string mode, vector<int> &d){
    queue<int> q;
    for(int i=0; i<N; i++) seen[i] = false;
    if(mode == "f") { q.push(N-1); seen[N-1] = true; }
    else { q.push(0); seen[0] = true; }

    while(!q.empty()){
        int now = q.front(); q.pop();
        for(auto to : adj[now]){
            if(!seen[to]){
                seen[to] = true;
                d[to] = d[now]+1;
                q.push(to);
            }
        }
    }
}

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

    fromSun[0] = fromFen[N-1] = 0;
    bfs("f", fromFen);
    bfs("s", fromSun);

    int sun = 0, fen = 0;
    for(int i=0; i<N; i++){
        if(fromSun[i] <= fromFen[i]) sun++;
        else fen++; 
    }

    if(sun > fen) cout << "Fennec" << endl;
    else cout << "Snuke" << endl;

    // for(int i=0; i<N; i++) cout << fromSun[i] << endl;
    // cout << endl;
    // for(int i=0; i<N; i++) cout << fromFen[i] << endl;
}

Measured memory_bytes: 6784
#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 << "Right" << endl;
    }
    else if ( A + B == C + D) {
      cout << "Balanced" << endl;
    }
    else {
      cout << "Left" << endl;
    }
}


Measured memory_bytes: 3620
n, k = list(map(int, input().split()))

MAX = 2*10**5+1
MOD = 10**9+7
fact = [0 for i in range(MAX)]
inv = [0 for i in range(MAX)]
invfact = [0 for i in range(MAX)]

def comb_build(n):
  fact[0] = inv[0] = invfact[0] = 1
  fact[1] = inv[1] = invfact[1] = 1
  for i in range(2, n):
    fact[i] = fact[i-1]*i%MOD
    inv[i] = inv[MOD%i]*(MOD-MOD//i)%MOD
    invfact[i] = invfact[i-1]*inv[i]%MOD

def nCk(n, k):
  if n<k or n<0 or k<0:
    return 0
  return (((fact[n]*invfact[k])%MOD)*invfact[n-k])%MOD

comb_build(2010)

for i in range(1, k+1):
  if i>n-k+1:
    print(0)
  else:
    print((nCk(k-1, i-1)*nCk(n-(k-1), i))%MOD)

Measured memory_bytes: 56144
#include<bits/stdc++.h>
using namespace std;
int main(){
    int N,i,sum=0,L[200];
    cin>>N;
    for(i=0;i<N*2;++i)cin>>L[i];
    sort(L,L+i);
    for(i=0;i<N*2;i+=2)sum+=L[i];
    cout<<sum;
}

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

#define FOR(a, b, c) for(int a = b; a <= c; ++a)
const int N = 305;

int n, m, ans;
bitset<305> a[N];

signed main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0); cout.tie(0);
    cin >> n >> m;
    for(int i = 1; i <= n; ++i) for(int j = 1; j <= m; ++j) {
        char x; cin >> x;
        if(x == '#') a[i].set(j);
    }
    FOR(i, 1, n) FOR(j, i, n) FOR(t, j, n)  if(i != t)  {
        bitset<305> a1 = a[i], a2 = a[j], a3 = a[t];
        int d1 = j - i, d2 = t - j;
        int s1 = d1, s2 = 2*d1 - d2;
        if(d1 <= d2) s1 = 2*d2 - d1, s2 = d2;
        a1 <<= s1; a3 <<= s2;
        a2 &= a1; a2 &= a3;
        ans += a2.count();

        if(d1 == 0 || d2 == 0) continue;
        a1 = a[i], a2 = a[j], a3 = a[t];
        a1 >>= s1; a3 >>= s2;
        a2 &= a1; a2 &= a3;
        ans += a2.count();
    }
    cout << ans;
}


Measured memory_bytes: 256
# encoding:utf-8
import copy
import numpy as np
import random

n = int(input())
F = []
for i in range(n):
    f = [int(i) for i in input().split()]
    F.append(f)



P = []
for i in range(n):
    P.append([int(i) for i in input().split()])

F = np.array(F)
P = np.array(P)


def cal_val(shop_num,open_time):
    same_time = int(np.dot(F[shop_num],open_time.T))
    # print(open_time)
    return P[shop_num,same_time]
#
# def to2digit(i):
#     open_time = np.zeros([10])
#     for count in range(10):
#         if i%2==1:
#             open_time[count] = 1
#         i = i//2
#     return open_time



values = []
ans = -10**10
for i in range(1,2**10):
    open_time = np.zeros([10])
    for j in range(10):
        if i%2==1:
            open_time[j] = 1
        i = i//2
    value = 0
    for shop_num in range(n):
        value += cal_val(shop_num,open_time)
    values.append(value)
    ans = max(ans,value)


print(ans)
# print(max(values))


Measured memory_bytes: 12928
#include <iostream>
#include <map>
#include <vector>
#include <cmath>
#include <string>
#include <cstring>
#include <algorithm>
#include <climits>
#include <stack>
#include <queue>
#include <set>
#include <cctype>
#include <bitset>
#include <type_traits>

#include <list>
using namespace std;

#define REP(i, n) for (int i = 0; i < (n); ++i)
#define rep(i, a, b) for (int i = a; i < (b); ++i)
#define YES(j) cout << (j ? "YES" : "NO") << endl;
#define Yes(j) std::cout << (j ? "Yes" : "No") << endl;
#define yes(j) std::cout << (j ? "yes" : "no") << endl;

int main(void)
{
    int s;
    cin >> s;
    int k;
    cin >> k;
    vector<int> a;
    while (true)
    {
        int amari;
        amari = s % k;
        s = s / k;
        a.push_back(amari);
        if (s == 0)
            break;
    }
    reverse(a.begin(), a.end());
    cout << a.size() << endl;
}

Measured memory_bytes: 256
from random import random
import math
import re
import fractions

MOD = 10**9+7

N = input()
T = map(int, raw_input().split(" "))
A = map(int, raw_input().split(" "))
# N = 10**5
# A = T = [999999999] * 10**5

result = 1

for i in xrange(N):
    et = bt = ea = ba = 0
    if i == 0 or T[i] != T[i-1]:
        et = T[i]
    else:
        bt = T[i]
    if i == N-1 or A[i] != A[i+1]:
        ea = A[i]
    else:
        ba = A[i]
    if ea + et > 0:
        if ea * et > 0 and et != ea:
            result = 0
            break
        if (ea > bt and bt != 0) or (et > ba and ba != 0):
            result = 0
            break
    else:
        result *= min(ba, bt)
        result %= MOD
print(result % MOD)


Measured memory_bytes: 16128
#include<stdio.h>
#include<algorithm>
#include<string.h>
using namespace std;
#define NIL -2000000001
#define MAX 2000000000000

int main() {
  char s[1001];
  scanf("%s", s);
  long long len;
  for(len=0; s[len]!='\0'; ++len);
  long long k;
  scanf("%lld", &k);
  for (long long i=0; i<len; i++) {
    if (s[i] != '1') {
      printf("%c\n", s[i]);
      break;
    }
    if (i == k-1) {
      printf("1\n");
      break;
    }
  }

  return 0;
}


Measured memory_bytes: 128
#include<cstdio>
#include<algorithm>
#include<functional>
#include<utility>
#define rep(i,a) for( int i = 0; i != (a); ++i )

typedef unsigned int uint;

uint n, p[65000], j[65000];

int main()
{
	while( scanf( "%u", &n ), n )
	{
		uint len = 0;
		rep( i, n )
		{
			scanf( "%u", p+i );
			len += p[i];
		}
		rep( i, n-1 )
		{
			uint t;
			scanf( "%u", &t );
			j[i] = t;
		}

		std::sort( j, j+n-1, std::greater<uint>() );

		uint ans = n*len;
		rep( i, n-1 )
		{
			len += j[i];
			ans = std::max( ans, (n-i-1)*len );
		}

		printf( "%u\n", ans );
	}

	return 0;
}

Measured memory_bytes: 1560
n = gets.to_i
input = Array.new
n.times do |i|
  input << gets.to_i
end

sum = input.inject(:+)
if sum % 10 != 0 then
  puts sum
else
  input.sort!
  n.times do |i|
    if input[i] %10 != 0
      puts sum - input[i]
      exit
    end
  end
  puts 0
end

Measured memory_bytes: 1788
#include<iostream>
#include<algorithm>
#include<cstdio>
#include<cmath>
#include<math.h>
#include<string>
#include<string.h>
#include<stack>
#include<queue>
#include<vector>
#include<utility>
#include<set>
#include<map>
#include<stdlib.h>
#include<iomanip>

using namespace std;

#define ll long long
#define ld long double
#define EPS 0.0000000001
#define INF 1e9
#define MOD 1000000007
#define rep(i,n) for(i=0;i<n;i++)
#define loop(i,a,n) for(i=a;i<n;i++)
#define all(in) in.begin(),in.end()
#define shosu(x) fixed<<setprecision(x)

typedef vector<int> vi;
typedef pair<int,int> pii;

int main(void) {
  int i,j;
  int n,m;
  cin>>n>>m;
  vi v(n,0);
  int a,b;
  rep(i,m){
    cin>>a>>b;
    a--,b--;
    v[a]++;
    v[b]++;
  }
  rep(i,n)
    if(v[i]%2){
      cout<<"NO"<<endl;
      return 0;
    }
    cout<<"YES"<<endl;
}


Measured memory_bytes: 640
#include <cstdio>
#include <algorithm>
#include <cstdlib>

int gcd(int m, int n) {
  while (n) std::swap(m%=n, n);
  return m;
}

int main() {
  int n, x;
  scanf("%d%d", &n, &x);
  int g=0;
  for (int i=0; i<n; ++i) {
    int y;
    scanf("%d", &y);
    y = abs(x-y);
    g = gcd(g, y);
  }
  printf("%d\n", g);
}

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

int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
    double l;
    cin >> l;
    double ans = (l/3) * (l/3) * (l/3);
    cout << fixed << setprecision(12) << ans << endl;
	return 0;
}

Measured memory_bytes: 256
# -*- coding: utf-8 -*-
import sys,copy,math,heapq,itertools as it,fractions,re,bisect,collections as coll

def solve():
    s = raw_input()
    N = len(s)
    for i in xrange(N - 1):
        if s[i] == s[i + 1]:
            return i + 1, i + 2
    for i in xrange(N - 2):
        if s[i] == s[i + 2]:
            return i + 1, i + 3
    return -1, -1

print " ".join(map(str, solve()))


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

int comp(const void *a, const void *b)
{
	return *(unsigned short *)a - *(unsigned short *)b;
}

int main(void)
{
	int cnt;
	unsigned short x, y, size, field[14][14]={0};
	while( scanf("%u,%u,%u", &x, &y, &size) != EOF){
		if((short)x == -1){ break; }
		x += 2;
		y += 2;
		switch(size){
		case 3:
			field[x+2][y]++;
			field[x-2][y]++;
			field[x][y+2]++;
			field[x][y-2]++;
		case 2:
			field[x-1][y-1]++;
			field[x-1][y+1]++;
			field[x+1][y-1]++;
			field[x+1][y+1]++;
		case 1:
			field[x][y]++;
			field[x+1][y]++;
			field[x-1][y]++;
			field[x][y+1]++;
			field[x][y-1]++;
			break;
		}
	}
	for(x=0; x<14; x++){
		field[x][0] = 0;
		field[x][1] = 0;
		field[x][12] = 0;
		field[x][13] = 0;
		field[0][x] = 0;
		field[1][x] = 0;
		field[12][x] = 0;
		field[13][x] = 0;
	}
	qsort(field, 14*14, sizeof(unsigned short), comp);
	for(x=0; x<14; x++){
		for(y=0; y<14; y++){
			if(field[x][y] != 0){
				cnt = x * 14 + (y?y:14) - 96;
				printf("%d\n%u\n", cnt, field[13][13]);
				return 0;
			}
		}
	}
}

Measured memory_bytes: 612
#include <stdio.h>

typedef long long ll;

char s[4444];
ll R[4444], G[4444], B[4444];

int main(void)
{
	ll n, i, j, ans = 0;

	scanf("%lld %s", &n, &s[1]);

	for (i = n; i >= 1; i--)
	{
		R[i] = R[i + 1] + (s[i] == 'R');
		G[i] = G[i + 1] + (s[i] == 'G');
		B[i] = B[i + 1] + (s[i] == 'B');
	}

	for (i = 1; i <= n; i++)
		for (j = i + 1; j <= n; j++)
		{
			if (s[i] == s[j])
				continue;

			if (s[i] == 'G' && s[j] == 'B' || s[i] == 'B' && s[j] == 'G')
				ans += R[j + 1];
			else if (s[i] == 'B' && s[j] == 'R' || s[i] == 'R' && s[j] == 'B')
				ans += G[j + 1];
			else
				ans += B[j + 1];

			ll not_k = j + (j - i);

			if (not_k <= n && s[not_k] != s[i] && s[not_k] != s[j])
				--ans;
		}

	printf("%lld", ans);
	return 0;
}

Measured memory_bytes: 1832
A=[]
B=[]
n,m,l=map(int,input().split())
for i in range(n):
    A.append(list(map(int,input().split())))
for j in range(m):
    B.append(list(map(int,input().split())))
for i in range(n):
    C=[]
    for j in range(l):
        a=0
        for k in range(m):
            a+=A[i][k]*B[k][j]
        C.append(a)
    print(' '.join(map(str,C)))


Measured memory_bytes: 6304
#include <stdio.h>
int main(){
	int n,k,h;
	int ans=0;
	scanf("%d %d",&n,&k);
	int i;
	for(i=0;i<n;i++){
		scanf("%d",&h);
		if(h>=k)	ans++;
	}
	printf("%d\n",ans);
	return 0;
}

Measured memory_bytes: 128
import java.util.Scanner;
public class Main{
  public static void main(String[] args){
	Scanner sc = new Scanner(System.in);
    long N = sc.nextInt();
    int K = sc.nextInt();
    int keta = 0;
    
    for(int i = 1; ; i++){
    	if(N < Math.pow(K, i)){
          keta = i;
          break;
        }
    }
    System.out.println(keta);
  }
}


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

//region Template
#include "ext/pb_ds/assoc_container.hpp"

using namespace __gnu_pbds;
using namespace std;

typedef long long ll;
typedef long double ld;
typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> indexed_set;

const int MOD = 1000000007;
using namespace std;
#define finish(x) cout << x; exit(0);
#define fastIO cin.tie(0); cin.sync_with_stdio(false);
#define endl '\n'

void setIn(string s) { freopen(s.c_str(), "r", stdin); }
void setOut(string s) { freopen(s.c_str(),"w",stdout); }

//const string USCAO_TAG = "mountains";
void usaco(const string& USACO_TAG) { setIn(USACO_TAG + ".in"); setOut(USACO_TAG + ".out"); }
void print() {}
template<typename T, typename... Args>
void print(T firstArg, Args... args) {
	#ifdef LOCAL
	cout << firstArg << " ";
	print(args...);
	#endif
}
//endregion

/* Notes:
 * Farah </3
 */

const int MAXN = 1e6 + 5;

long long modPow(long long b, long long pow){
	long long ans = 1;
	long long p = b;
	while(pow){
		if(pow & 1)
			ans = (ans * p) % 1000000007;
		p = (p * p) % 1000000007;
		pow >>= 1;
	}
	return ans;
}

int main() {
	//usaco("milkvisits");

	#ifdef LOCAL
	setIn("in.txt");
	setOut("out.txt");
	#endif

	string s;
	cin >> s;

	int q;
	cin >> q;

	string b, e;

	int rc = 0;
	while(q--){
		int t;
		cin >> t;

		if(t == 1){
			rc++;
			rc %= 2;
		}

		if(t == 2){
			int f;
			char c;
			cin >> f >> c;

			if(f == 1){
				if(rc == 0) b += c;
				else e += c;
			}
			else if(f == 2){
				if(rc == 0) e += c;
				else b += c;
			}
		}
	}

	if(!rc){
		reverse(b.begin(), b.end());

		cout << b << s << e;
	}
	else{
		reverse(s.begin(), s.end());
		reverse(e.begin(), e.end());
		cout << e << s << b;
	}
}

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

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(){
    cin.tie(0); cout.tie(0);
    ios::sync_with_stdio(false);

    int N, M; cin >> N >> M;
    int T = -1;
    ll L = 1;

    while(N--){
        int a; cin >> a; a /= 2;
        int t; for (t = 0; !(a & 1); t++) a >>= 1;
        if(T<0) T=t;
        if(t!=T){puts("0"); return 0;}
        if((L=lcm(L,a)) > M){puts("0"); return 0;}
    }

    cout << ((M>>T)/L+2-1)/2 << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <utility>

#define co(a) cout << a << endl

int main(){
    using namespace std;
    char n;
    cin>>n;
    pair<char,char> a('A','T');
    pair<char,char> b('G','C');
    if (n==a.first)
        co(a.second);
    else if (n==a.second)
        co(a.first);
    else if (n==b.first)
        co(b.second);
    else if (n==b.second)
        co(b.first);
}

Measured memory_bytes: 256
a, b, m = map(int, input().split())
data = list(map(int, input().split()))
datb = list(map(int, input().split()))
res = 999999999999
for i in range(m):
    x, y, c = map(int, input().split())
    t = data[x - 1] + datb [y - 1] - c
    res = min(res, t)
data.sort()
datb.sort()
res = min(res, data[0] + datb[0])
print(res)

Measured memory_bytes: 68460
#include <bits/stdc++.h>
#include <stdio.h>
#include <math.h>
#include <cmath>
using namespace std;
#define vsort(vec) sort(vec.begin(), vec.end())
#define vreverse(vec) reverse(vec.begin(), vec.end())
using ll =long long;
using ull =unsigned long long;
const ll INF =1001001001;

//10億7。　　　100000007

//最大公約数
ll gcd(ll a, ll b){
   if (a%b==0){
       return(b);
   }else{
       return(gcd(b,a%b));
   }
}
//最小公倍数
ll lcm(ll a, ll b){
   return a*b/gcd(a,b);
}


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

int N;
  cin>>N;
  
  int A=N%10;
  
  if(A==3){cout<<"bon"<<endl;}
  if(A==0||A==1||A==6||A==8){cout<<"pon"<<endl;}
  if(A==2||A==4||A==5||A==7||A==9){cout<<"hon"<<endl;}
}



Measured memory_bytes: 3632
#include<bits/stdc++.h>
using namespace std;
int main()
{
    long long n,w;
    cin>>n>>w;
    vector<pair<long long,long long>> items(n);

    for(int i=0;i<n;i++)
    {
        cin>>items[i].first;
        cin>>items[i].second;
    }

    sort(items.begin(),items.end());
    long long dp[n+1][w+1] ;
    memset(dp[0],0,sizeof(dp[0]));
    for(long long i=0;i<=n;i++)dp[i][0] = 0;

    for(long long i=1;i<=n;i++)
    {
        for(long long j=1;j<=w;j++)
        {
           // cout<<i<<items[i].first<<" ";
            long long  x = j-items[i-1].first>=0? items[i-1].second:0;
            dp[i][j] = max(dp[i-1][j],dp[i-1][max(j-items[i-1].first,(long long)0)]+x);
            //cout<<dp[i][j]<<" ";
        }
         //cout<<endl;
    }

    cout<<dp[n][w];

}



Measured memory_bytes: 79104
#include <iostream>
#include <vector>
#include <map>
#include <unordered_map>
#include <queue>
#include <set>
#include <algorithm>
#include <string>
#include <math.h>
#include <limits.h>
#include <stack>
#include <complex>
#include <stdlib.h>
#include <stdio.h>
#include <functional>
#include <cfloat>
#include <math.h>
#include <numeric>
#include <string.h>
#include <sys/time.h>
#include <random>


#define fs first
#define sc second
#define endl "\n"

using namespace std;

typedef long long ll;
typedef unsigned int uint;
typedef pair<int, int> P;

class modInt{
    ll value;
    static const ll mod = 998244353;

public:
    modInt(ll x=0): value{x % mod}{}

    inline modInt& operator+=(modInt x){
        value = (value + x.value) % mod;
        return *this;
    }

    inline modInt& operator-=(modInt x){
        value = (value + mod - x.value) % mod;
        return *this;
    }

    inline modInt& operator*=(modInt x){
        value = (value * x.value) % mod;
        return *this;
    }


    inline modInt operator/=(modInt x){
        *this *= x.inv();
        return *this;
    }

    inline modInt pow(modInt x, int n){
        modInt res = modInt(1LL);
        while(n > 0){
            if(n & 1)   res *= x;
            x *= x;
            n >>= 1;
        }
        return res;
    }

    inline modInt inv(){
        modInt res = pow(value, mod-2);
        return res;
    }

    inline ll get(){
        return value;
    }
};

modInt operator+(modInt x, modInt y){
    return x += y;
}

modInt operator-(modInt x, modInt y){
    return x -= y;
}

modInt operator*(modInt x, modInt y){
    return x *= y;
}

modInt operator/(modInt x, modInt y){
    return x /= y;
}

ostream& operator<<(ostream& os, modInt x){
    return os << x.get();
}


class modIntCombinations{
    vector<modInt> factArray;

    void make_fact(ll x){
        for(auto i = factArray.size(); i <= x+1; i++){
            modInt y = factArray[i-1] * i;
            factArray.push_back(y);
        }
    }

public:
    modIntCombinations(){
        factArray.emplace_back(1);
    }

    modInt fact(ll x){
        if(factArray.size() < x+1){
            make_fact(x);
        }
        return factArray[x];
    }

    modInt comb(ll n, ll k){
        if(n < k){
            return modInt{0};
        }
        else{
            return fact(n) / fact(k) / fact(n - k);
        }
    }

    modInt perm(ll n, ll k){
        if(n < k){
            return modInt{0};
        }
        else{
            return fact(n) / fact(k);
        }
    }
};


int main(){
    ll n, m, k;
    cin >> n >> m >> k;

    modInt whole = 1;
    for(int i = 0; i < n; i++){
        whole *= m;
    }

    vector<modInt> vec(n+1);
    vec[1] = modInt(m);
    for(int i = 2; i <= n; i++){
        vec[i] = vec[i-1] * modInt(m-1);
    }

    modIntCombinations mic;
    modInt x = 0;
    for(int i = k+1; i < n; i++){
        int num = n - i;
        x += mic.comb(n-1, num-1) * vec[num];
    }

    cout << whole - x << endl;



    return 0;
}


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

const int N = 1e5 + 5;
const int hand[] = {'r', 's', 'p'};
int n, k, r, s, p;
int dp[N][3];
string t;

int result(char x, char y) {
	if (x == 'r' && y == 's') return r;
	if (x == 's' && y == 'p') return s;
	if (x == 'p' && y == 'r') return p;
	return 0;
}

int main() {
	cin >> n >> k >> r >> s >> p >> t;
	for (int i = 0; i < n; ++i) { 
		if (i < k) {
			for (int j = 0; j < 3; ++j) {
				dp[i][j] = result(hand[j], t[i]);
			}
		} else {
			for (int j = 0; j < 3; ++ j) {
				for (int l = 0; l < 3; ++ l) {
					if (j == l) continue;
					dp[i][j] = max(dp[i][j], dp[i - k][l] + result(hand[j], t[i]));
				}
			}
		}
	}
	int res = 0;
	for (int i = n - 1; i > n - k - 1; --i) {
		res += max(dp[i][0], max(dp[i][1], dp[i][2]));
	}
	cout << res;
}

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

using namespace std;

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

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



int main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	cin >> N;
	for (int i = 0; i < N; i++) {
		cin >> L >> R;
		M += (R - L + 1);
	}
	cout << M << endl;
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main() {
    
    long long x,k,d;
    cin>>x>>k>>d;
    long long steps = abs(x/d);
    if(steps>k){
        if(x>0)cout<<abs(x-k*d)<<endl;
        else cout<<abs(x+k*d)<<endl;
        return 0;
    }
    if(x>0)x=x-steps*d;
    else x=x+steps*d;
    if(x==0){
        if((k-steps)%2==0)cout<<0<<endl;
        else cout<<d<<endl;
        return 0;
    }else{
        if((k-steps)%2==0)cout<<abs(x)<<endl;
        else {
            if(x>0)cout<<abs(x-d)<<endl;
            else cout<<abs(x+d)<<endl;
        }
    }
    return 0;
}

Measured memory_bytes: 3640
#include <iostream>

using namespace std;

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

  int s[N];
  for(int i = 0; i < N; i++) {
    cin >> s[i];
  }

  int count = 0;
  int boo;

  while(1) {
    boo = 1;
    for(int i = 0; i < N; i++) {
      if(s[i] % 2 != 0) {
        boo = 0;
      }
    }
    if(boo == 1) {
      count++;
      for(int i = 0; i < N; i++) {
        s[i] /= 2;
      }
    } else {
      break;
    }
  }

  cout << count << endl;
}


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

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

    int n;
    cin >> n;
    int cnt = 1;

    for (int i = 0; i < n; i++) {
        int a;
        cin >> a;
        if (a == cnt) {
            cnt++;
        }
    }

    if (cnt == 1) {
        cout << -1 << endl;
    } else {
        cout << n - cnt + 1 << endl;
    }
}


Measured memory_bytes: 256
package main

import (
	"bufio"
	"fmt"
	"os"
	"strings"
)

func main() {
	var a string
	sc := bufio.NewScanner(os.Stdin)
	if sc.Scan() {
		a = sc.Text()
	}

	n := strings.Split(a, " ")

	count := 1
	for i := 0; i < 5; i++ {
		if n[i] == "0" {
			break
		}
		count += 1
	}
	fmt.Print(count)
}


Measured memory_bytes: 1760
#include "bits/stdc++.h"
using namespace std;
#define int long long
int mod=1e9+7;

int gcd(int a,int b){
  if(a<b)gcd(b,a);
  int r;
  while((r=a%b)){
    a=b;
    b=r;
  }
  return b;
}

signed main(){
  int t;
  cin>>t;
  for(int i=0;i<t;i++){
    int a,b,c,d;
    cin>>a>>b>>c>>d;
    if(b>a||b>d){
      cout<<"No"<<endl;
    }else if(c>=b){
      cout<<"Yes"<<endl;
    }else{
      int g=gcd(b,d);
      if(b-g+(a%g)>c){
        cout<<"No"<<endl;
      }else{
        cout<<"Yes"<<endl;
      }
    }
  }
}


Measured memory_bytes: 256
<?php
  
  $a = fgets(STDIN);
  $b = fgets(STDIN);

  $length = strlen($a);

  $result = 0;

  for($i=0; $i< $length; $i++)
  {
    if($a[$i] !== $b[$i]){
      $result += 1;
    }
  }

  echo $result;

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

#define __STDC_FORMAT_MACROS
#define p64 PRId64

#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define REP(i, n) FOR (i, 0, n)
#define ALL(f, x, ...)                                                         \
    ([&] (decltype ((x)) ALL) {                                                \
        return (f) (begin (ALL), end (ALL), ##__VA_ARGS__);                    \
    }) (x)

using namespace std;
using ll = int64_t;

int main() {
    int a, b;
    cin >> a >> b;
    cout << (a < b ? string (b, '0' + a) : string (a, '0' + b)) << endl;
    return 0;
}


Measured memory_bytes: 256
import           Control.Applicative
import           Control.Monad

import           Data.Array.IArray
import           Data.Array.Unboxed

binarySearch :: Int -> UArray Int Int -> Bool
binarySearch n ary = uncurry go (bounds ary)
  where
    go left right
        | left > right = False
        | midv == n    = True
        | midv <  n    = go (mid + 1) right
        | midv >  n    = go left (mid - 1)
      where
        mid = (left + right) `div` 2
        midv = ary ! mid

main :: IO ()
main = do
    getLine
    ss <- fmap read . words <$> getLine :: IO [Int]
    getLine
    ts <- fmap read . words <$> getLine :: IO [Int]
    let ary = listArray (0, length ss - 1) ss :: UArray Int Int
    print . length $ filter (flip binarySearch ary) ts



Measured memory_bytes: 109600
count = 0
n = int(input())
ns = list(map(int, input().split()))
for i in range(n-2):
    l = [ns[i], ns[i+1], ns[i+2]]
    if max(l) != ns[i+1] and min(l) != ns[i+1]:
        count += 1
print(count)

Measured memory_bytes: 3060
n = int(input())

d = {}
last = None
result = True
for i in range(n):

    h = input()
    if h in d:
        result = False
    d[h] = 1
    if last:
        if last[-1] != h[0]:
            result = False
    last = h
if result:
    print("Yes")
else:
    print("No")


Measured memory_bytes: 3060
from collections import Counter
n,x=[int(i) for i in input().split()]
a=[int(i) for i in input().split()]
b=[]
m=10**9
for i in a:
  if i < m:
    m = i
  else:
    b.append(i-m)

ma=max(b)
c=Counter(b)
print(c[ma])

Measured memory_bytes: 22112
import java.util.*;

public class Main {
	
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		
		char[] s = sc.next().toCharArray();
		int[] c = new int[26];
		for(int i=0;i<s.length;i++) c[(int)s[i]-97]++;
		int odd = 0;
		for(int i=0;i<26;i++){
			if(c[i]%2==1) odd++;
		}
		if(odd > s.length%2){
			System.out.println(0);
		}else{
			long[] p = new long[21];
			p[0] = 1;
			for(int i=1;i<=20;i++) p[i] = p[i-1]*i;
			
			long sum = 1;
			for(int i=0;i<26;i++) sum *= p[c[i]/2];
			System.out.println(p[s.length/2]/sum);
		}
	}	
}

Measured memory_bytes: 17312
from bisect import *
from collections import *
from itertools import *
import functools
import sys
import math
from decimal import *
from copy import *
from heapq import *
from fractions import *
getcontext().prec = 30
MAX = sys.maxsize
MAXN = 1000001
MOD = 10**9+7
spf = [i for i in range(MAXN)]
spf[0]=spf[1] = -1
def sieve():
    for i in range(2,MAXN,2):
        spf[i] = 2
    for i in range(3,int(MAXN**0.5)+1):
        if spf[i]==i:
            for j in range(i*i,MAXN,i):
                if spf[j]==j:
                    spf[j]=i
def fib(n,m):
    if n == 0:
        return [0, 1]
    else:
        a, b = fib(n // 2)
        c = ((a%m) * ((b%m) * 2 - (a%m)))%m
        d = ((a%m) * (a%m))%m + ((b)%m * (b)%m)%m
        if n % 2 == 0:
            return [c, d]
        else:
            return [d, c + d]

def charIN(x= ' '):
    return(sys.stdin.readline().strip().split(x))

def arrIN(x = ' '):
    return list(map(int,sys.stdin.readline().strip().split(x)))

def ncr(n,r):
    num=den=1
    for i in range(r):
        num = (num*(n-i))%MOD
        den = (den*(i+1))%MOD

    return (num*(pow(den,MOD-2,MOD)))%MOD

def flush():
    return sys.stdout.flush()

'''*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*'''
n,k = arrIN()
r,s,p = arrIN()
d = {"r":r,"s":s,"p":p,"x":0}
t = input()
ans = [0]*(n)
for i in range(k):
    if t[i]=='r':
        ans[i] = "p"
    elif t[i]=='s':
        ans[i] = "r"
    else:
        ans[i] = "s"

for i in range(k,n):
    if t[i]=="r":
        if ans[i-k]!="p":
            ans[i] = "p"
        else:
            ans[i] = "x"
    elif t[i]=="s":
        if ans[i-k]!="r":
            ans[i] = "r"
        else:
            ans[i] = "x"
    else:
        if ans[i-k]!="s":
            ans[i] = "s"
        else:
            ans[i] = "x"
print(sum(d[ans[i]] for i in range(n)))



Measured memory_bytes: 45708