akhauriyash/Code-Regression huggingface dataset:
using System;
using System.IO;
using System.Linq;

namespace ABC125C
{
    class Program
    {
        static void Main(string[] args)
        {
            if (args.Length > 0)
            {
                Console.SetIn(new StreamReader(args[0]));
            }

            new Program().Solve2();
        }

        void Solve2()
        {
            var N = int.Parse(Console.ReadLine());
            var A = Console.ReadLine().Split(' ').Select(int.Parse).ToArray();
            var left = new int[N];
            var right = new int[N];
            var g = 0;

            for (int i = 0; i < N; i++)
            {
                if (g == 0)
                {
                    g = A[i];
                }
                else
                {
                    g = Gcd(g, A[i]);
                }

                left[i] = g;
            }

            g = 0;

            for (int i = N - 1; i >= 0; i--)
            {
                if (g == 0)
                {
                    g = A[i];
                }
                else
                {
                    g = Gcd(g, A[i]);
                }

                right[i] = g;
            }

            var max = 0;

            for (int i = 0; i < N; i++)
            {
                var ans = 0;

                if (i == 0)
                {
                    ans = right[i + 1];
                }
                else if (i == N - 1)
                {
                    ans = left[i - 1];
                }
                else
                {
                    ans = Gcd(left[i - 1], right[i + 1]);
                }

                max = Math.Max(max, ans);
            }

            Console.WriteLine(max);
        }

        void Solve()
        {
            var N = int.Parse(Console.ReadLine());
            var A = Console.ReadLine().Split(' ').Select(int.Parse).ToArray();
            var max = 0;

            for (int i = 0; i < N; i++)
            {
                var ans = 0;

                for (int j = 0; j < N; j++)
                {
                    if (i == j)
                    {
                        continue;
                    }

                    if (ans == 0)
                    {
                        ans = A[j];
                    }
                    else
                    {
                        ans = Gcd(ans, A[j]);
                        
                        if (ans < max)
                        {
                            break;
                        }
                    }
                }

                max = Math.Max(max, ans);
            }

            Console.WriteLine(max);
        }

        int Gcd(int a, int b)
        {
            if (a < b)
            {
                return Gcd(b, a);
            }

            while (b != 0)
            {
                var temp = a % b;
                a = b;
                b = temp;
            }

            return a;
        }
    }
}


Measured memory_bytes: 25052
#include <iostream>
#include <algorithm>
#include<cmath>
#include<cstring>
#include<cstdio>
#include<cstdlib>
#include<vector>
#include<iomanip>
#define sqr(x) (x)*(x)
#define llx(c,itr) for(__typeof((c).begin()) itr=(c).begin();itr!=(c).end();itr++)
#define rdst(st,len) {char ss[len];scanf("%s",ss);(st)=ss;}
using namespace std;
int n,m,i,j,num[500005];
string st;
int main()
{
	scanf("%d%d",&n,&m);
	printf("%d\n",(n+m-3)/(m-1));
	return 0;
}

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

int main(){
	ll n,k;
	cin >> n >> k;
	vector<int> l(n);
	rep(i,n) cin >> l[i];
	sort(l.rbegin(),l.rend());
	int ans = 0;
	rep(i,k) ans += l[i];
	cout << ans << endl;
    return 0;
}

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

int N, K; 
int P[3], CNT[3];
string T; 

int main() {
    cin >> N >> K;
    cin >> P[0] >> P[1] >> P[2];
    cin >> T;
    vector<vector<int>> X(K);
    rep(i, N) {
        if(T[i] == 'r') X[i % K].push_back(2);
        else if(T[i] == 's') X[i % K].push_back(0);
        else X[i % K].push_back(1);
    }
    rep(i, K) {
        int j = 0;
        while(j < X[i].size()) {
            if(j == X[i].size() - 1 || X[i][j] != X[i][j + 1]) {
                CNT[X[i][j]]++;;
                ++j;
            } else {
                CNT[X[i][j]]++;
                j += 2;
            }
        }
    }
    int ret = 0;
    rep(i, 3) {
        ret += P[i] * CNT[i];
    }
    cout << ret << endl;
}

Measured memory_bytes: 5120
#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
const int inf=1000000005;
int i,j,k,n,m,f[2101][2101],c[2101][2101],d[2101][2101],t1,t2,a[2101];
int av(int x){
	return (x>0)?x:-x;
}
int main(){
	scanf("%d%d%d",&n,&t1,&t2);
	for (i=1;i<=n;i++) scanf("%d",&a[i]);
	for (i=0;i<=n+1;i++) c[n+1][i]=0,d[i][n+1]=inf;
	for (i=n;i>=0;i--)
	 for (j=n;j>=0;j--){
	 	if (i==j){
	 		if (i){
				c[i][j]=c[i+1][j];d[i][j]=d[i][j+1];
	 			continue;
			}
			f[i][j]=c[i+1][j];
			continue;
		}
		if (i<j){
			if (j==n){
				f[i][j]=av(a[n]-((i==0)?t1:a[i]));
			}else{
				f[i][j]=c[i+1][j];
			}
		}else{
			if (i==n){
				f[i][j]=av(a[n]-((j==0)?t2:a[j]));
			}else{
				f[i][j]=d[i][j+1];
			}
		}
		c[i][j]=max(c[i+1][j],f[i][j]);
		d[i][j]=min(d[i][j+1],f[i][j]);
	 }
	printf("%d\n",f[0][0]);
	return 0;
}

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


using namespace std;
typedef long long ll;
#define REP(i,n) for(int i=0; i<int(n); i++)
#define FOR(i,m,n) for(int i=int(m); i<int(n); i++)
#define ALL(obj) (obj).begin(),(obj).end()
#define VI vector<int>
#define VLL vector<long long>
#define VVI vector<vector<int>>
#define VVLL vector<vector<long long>>
#define VC vector<char>
#define VS vector<string>
#define VVC vector<vector<char>>
#define VB vector<bool>
#define VVB vector<vector<bool>>
#define fore(i,a) for(auto &i:a)

typedef pair <int, int> P;
template<class T> bool chmax(T &a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> bool chmin(T &a, T b) { if (a > b) { a = b; return true; } return false; }
const int  INF = 1 << 29;
const ll INFL = 1LL << 60;
const ll mod = 1000000007;



ll n, m, l;

vector<pair<int, int>> v[305];

int ans[305][305];

template<typename T> using min_priority_queue = priority_queue<T, vector<T>, greater<T>>;


int vis[305];
void dijkstra(int s, vector<vector<pair<int, int>>> &E, vector<vector<ll>> &D) {
	REP(i, n) D[s][i] = INFL;
	REP(i, n) vis[i] = 0;

	min_priority_queue<pair<ll, pair<ll, int>>> que;

	D[s][s] = 0;
	que.push({ 0, {0,s } });

	while (!que.empty()) {
		auto q = que.top();
		que.pop();

		ll cst = q.second.first;
		int cu = q.second.second;

		if (vis[cu]) continue;
		vis[cu] = 1;

		fore(p, E[cu]) {
			ll cst2 = cst + p.second;
			int cnt = q.first;
			if (cst2 > l) {
				cst2 = p.second;
				cnt++;
			}
			int to = p.first;
			if (D[s][to] > cnt||(D[s][to]==cnt&&cst2<ans[s][to])) {
				D[s][to] = cnt;
				D[to][s] = cnt;
				ans[s][to] = cst2;
				ans[to][s] = cst2;
				que.push({ cnt,{cst2,to} });
			}
			//if (chmin(D[s][to], cst2)) que.push({ D[s][to], to });
		}
	}
}


int main() {

	cin >> n >> m >> l;

	vector<vector<pair<int, int>>> c(n);

	VVLL da(305, VLL(305));

	REP(i, m) {
		int a, b, cc;
		cin >> a >> b >> cc;
		a--;
		b--;
		if (cc > l)continue;
		c[a].push_back({ b,cc });
		c[b].push_back({ a,cc });
	}


	REP(i, n) {
		dijkstra(i, c, da);
	}

	REP(i, 305)REP(j, 305) {
		ans[i][j] = INF;
	}

	/*
	cout << "=================" << endl;

	REP(i, n) {
		REP(j, n) {
			cout << da[i][j] << ' ';
		}
		cout << endl;
	}


	cout << "=================" << endl;
	*/

	int q;
	cin >> q;
	REP(i, q) {
		int a, b;
		cin >> a >> b;
		a--; b--;
		//cout << "=============";
		if (da[a][b] == INFL)cout << -1 << endl;
		else cout << da[a][b] << endl;
	}

	
}



Measured memory_bytes: 4108
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <vector>
#include <cstring>
#include <queue>
#include <stack>
#include <functional>
#include <set>
#include <map>
#include <deque>
#define NMAX 100005
#define INF 1000000007

//コメントアウトするとdebug()を実行しない
#define DEBUG

using namespace std;
long long N,ans=1,dp[NMAX];
vector<int > p;
void solve(){
	for (int i = 0; i < N; ++i)
	{
		int k = p.size()+1;
		if(dp[i] >= 2*k-1){
			p.push_back(dp[i]);
		}else{
			ans = ans * (k);
			ans = ans % INF;
		}
	}
	for (int i = 1; i < p.size(); ++i)
	{
		ans = ans * (i+1);
		ans = ans % INF;
	}
}

void debug(){

}

void answer(){
	printf("%lld\n",ans);
}

int main(){
	scanf("%lld",&N);
	for (int i = 0; i < N; ++i)
	{
		scanf("%lld",&dp[i]);
	}
	solve();
	#ifdef DEBUG
	debug();
	#endif
	answer();

	return 0;
}

Measured memory_bytes: 1788
/*

*/
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int MAXN = 1e5 + 5;
const int inf = 0x3f3f3f3f;
int n;
int a[MAXN][5], dp[MAXN][5];
int main()
{
    cin >> n;
    for (int i = 1; i <= n; i++)
        for (int j = 1; j <= 3; j++)
            cin >> a[i][j], dp[i][j] = -1;
    dp[1][1] = a[1][1], dp[1][2] = a[1][2], dp[1][3] = a[1][3];
    for (int i = 2; i <= n; i++)
        for (int j = 1; j <= 3; j++)
            for (int k = 1; k <= 3; k++)
                if (j != k)
                    dp[i][j] = max(dp[i][j], dp[i - 1][k] + a[i][j]);
    cout << max({dp[n][1], dp[n][2], dp[n][3]});
    return 0;
}

Measured memory_bytes: 4096
#include<bits/stdc++.h>
using namespace std;
const int maxn=1e5+10;
int q,presum[maxn];
bool isprime[maxn];
bool check(int x)
{
	return isprime[x]&&isprime[(x+1)/2];
}
void build()
{
	for(int i=2;i<maxn;i++)
		isprime[i]=true;
	for(int i=2;i<maxn;i++)
		if(isprime[i])
			for(int j=i+i;j<maxn;j+=i)
				isprime[j]=false;
	for(int i=2;i<maxn;i++)
		if(i&1)
			presum[i]=presum[i-1]+check(i);
		else
			presum[i]=presum[i-1];
}
void solve()
{
	int l,r;
	cin>>l>>r;
	cout<<presum[r]-presum[l-1]<<endl;
}
int main()
{
	ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
	cin>>q;
	build();
	while(q--)
		solve();
	return 0;
}
/*
1
3 7
output:2

4
13 13
7 11
7 11
2017 2017
output:
1
0
0
1 

6
1 53
13 91
37 55
19 51
73 91
13 49
output:
4
4
1
1
1
2

1
1 2
output:0

1
1 100000
output:672
*/

Measured memory_bytes: 1152
#include <bits/stdc++.h>
#define _GLIBCXX_DEBUG
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define Sort(a) sort(a.begin(), a.end())
#define Reve(a) reverse(a.begin(), a.end())
#define PI 3.14159265359
typedef long long ll;
const ll MOD = 1e9+7;

ll gcd(ll a, ll b){
  if(b==0) return a;
  return gcd(b, a%b);
}
/*ll myPow(ll x, ll n, ll m){
  if(n == 0)
    return 1;
  if(n % 2 == 0)
    return myPow(x * x % m, n / 2, m);
  else
    return x * myPow(x, n - 1, m) % m;
}*/

ll lcm(ll a, ll b){
  ll g = gcd(a, b);
  b /= g;
  a *= b;
  return a;
}

//素数判定 O(√n)
bool is_prime(int64_t n){
  for(int64_t i = 2; i*i<=n; i++){
    if(n%i==0) return false;
  }
  return n!=1;
}

//約数の列挙 O(√n)
vector<int64_t> dividor(int64_t n){
  vector<int64_t> res;
  for(int64_t i=1; i*i<=n; i++){
    if(n%i==0){
      res.push_back(i);
      if(i != n/i) res.push_back(i);
    }
  }
  return res;
}

//素因数分解 O(√n)
map<int64_t, int64_t> prime_factor(int64_t n){
  map<int64_t, int64_t> res;
  for(int64_t i=2; i*i<=n; i++){
    while(n%i==0){
      res[i]++;
      n /= i;
    }
  }
  if(n != 1) res[n] = 1;
  return res;
}
struct UnionFind {
    vector<int> par; // par[i]:iの親の番号　(例) par[3] = 2 : 3の親が2

    UnionFind(int N) : par(N) { //最初は全てが根であるとして初期化
        for(int i = 0; i < N; i++) par[i] = i;
    }

    int root(int x) { // データxが属する木の根を再帰で得る：root(x) = {xの木の根}
        if (par[x] == x) return x;
        return par[x] = root(par[x]);
    }

    void unite(int x, int y) { // xとyの木を併合
        int rx = root(x); //xの根をrx
        int ry = root(y); //yの根をry
        if (rx == ry) return; //xとyの根が同じ(=同じ木にある)時はそのまま
        par[rx] = ry; //xとyの根が同じでない(=同じ木にない)時：xの根rxをyの根ryにつける
    }

    bool same(int x, int y) { // 2つのデータx, yが属する木が同じならtrueを返す
        int rx = root(x);
        int ry = root(y);
        return rx == ry;
    }
};

int main(){
  ll x; cin >> x;
  ll y = 100;
  for(int i=1; i<=3761; i++){
     y *= 1.01;
     y = (ll) y;
     //cout << y << endl;
     if(y>=x) {cout << i << endl; break;} 
  }
}




Measured memory_bytes: 3628
import java.util.Scanner;

public class Main {
    public static void main(String[] args) throws Exception {
        Scanner sc = new Scanner(System.in);
        int A = sc.nextInt();
        int B = sc.nextInt();
        int C = sc.nextInt();
        int rest = A - B;
        int answer = C - rest;
        if (answer < 0) {
            System.out.println(0);
        } else {
            System.out.println(answer);
        }
    }
}


Measured memory_bytes: 22100
#include<iostream>
#include<algorithm>
#include<vector>
#include<string>

#define kuriage(x)  x+=10-x%10;
#define mod(cans) cans%10**9+7;
#define vecin(x,y) for(int i=0;i<x;i++){cin>>y[i];}
#define debug(x) cout << "Debug" << x << "\n"

typedef long long ll;

using namespace std;
int main()
{   
    ll n,r,ans=0;
    cin>>n;
    ll tr[5];
    vecin(5,tr);
    ans=tr[0];
    //debug(1);
    for(int i=0;i<5;i++) ans=min(ans,tr[i]);
    //debug(2);
    if(ans>=n)
    {
        r=5;
    }
    else if(n%ans==0)
    {
        r=(n/ans)+4;    
    }
    else
    {
        r =(n/ans)+5;
    } 
    //debug(3);   
    cout<<r<<"\n";
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define _GLIBCXX_DEBUG
int64_t MOD=1000000007;


int keta(int64_t x){
  int count=1;
  while(x/10!=0){
    x/=10;
    count++;
  }
  return count;
}


int main() {
  int64_t N,M;
  cin>>N>>M;
  vector<vector<pair<int,int>>> SS(N);
  vector<pair<int,int64_t>> ans;
  //県ごとに年と市の番号のpairを作る
  for(int i=0;i<M;i++){
    int a,b;
    cin>>a>>b;
    SS.at(a-1).push_back(make_pair(b,i));
  }
  //県ごとに並び替え
  for(int i=0;i<N;i++){
    if(SS.at(i).size()==0)continue;
  sort(SS.at(i).begin(),SS.at(i).end());
  }
  //認識番号と市の番号のpairを作る
  for(int64_t i=0;i<N;i++){
    for(int64_t j=0;j<SS.at(i).size();j++){
      int c=SS.at(i).at(j).second;
      ans.push_back(make_pair(c,(i+1)*1000000+(j+1)));
    }
  }
  //市の番号順に並び替え
  sort(ans.begin(),ans.end());
  
  for(int i=0;i<(int)ans.size();i++){
    int d=keta(ans.at(i).second);
    for(int j=0;j<12-d;j++) cout<<0; //0を埋める
    cout<<ans.at(i).second<<endl;
  }
  
}

Measured memory_bytes: 8688
N,W=map(int,input().split())

w=[0]*(N)
v=[0]*(N)
for i in range(N):
	w[i],v[i]=map(int,input().split())
V=sum(v)

dp=[[float('inf')]*(V+1) for i in range(N+1)]
dp[0][0]=0

for i in range(N):
	for j in range(V+1):
		if j-v[i]>=0:
			dp[i+1][j]=dp[i][j-v[i]]+w[i]
		dp[i+1][j]=min(dp[i+1][j],dp[i][j])
res=0
for i in range(V+1):
	if dp[N][i]<=W:res=max(i,res)
print(res)

Measured memory_bytes: 312016
using System;
using System.Collections;
using System.Collections.Generic;
using static System.Console;

class Program
{
	static void Main(string[] args)
	{
		int N = int.Parse(ReadLine());
		bool b = true;
		int[] A = new int[N];
		string[] str = ReadLine().Split(' ');
		for (int i = 0; i < N; i++) A[i] = int.Parse(str[i]);

		for(int i = 0;i < N;i++)
		{
			if (A[i] % 2 == 0)
			{
				if (A[i] % 3 == 0 || A[i] % 5 == 0) b = true;
				else
				{
					b = false;
					break;
				}
			}
		}
		if (b) WriteLine("APPROVED");
		else WriteLine("DENIED");
	}
}

Measured memory_bytes: 13140
K = int(input())
ans = 1
dp = [-1] * K
num = 7
while True:
    num = num % K
    if dp[num % K] != -1:
        print(-1)
        break
    elif num % K == 0:
        print(ans)
        break
    else:
        dp[num % K] = 1
    ans += 1
    num = num * 10 + 7



Measured memory_bytes: 71400
#include<bits/stdc++.h>
using namespace std;
#define MAX_N 111111
typedef long long int ll;
ll seg[1<<18];
int N;
ll B[MAX_N];
void add(int a,int b,int k,int l,int r,ll x){
	//printf("%d %d %d %d\n",a,b,l,r);
	if(a<=l&&r<=b){
		seg[k]+=x;
		return;
	}
	else if(r<=a||b<=l){
		return;
	}
	add(a,b,2*k+1,l,(l+r)/2,x);
	add(a,b,2*k+2,(l+r)/2,r,x);
}
ll key(int k){
	ll res=0;
	while(true){
		res+=seg[k];
		k--;
		if(k<0){break;}
		k/=2;
	}
	return res;
}
int main()
{
	scanf("%d",&N);
	for(int i=0;i<N;i++){
		ll X;
		scanf("%lld",&X);
		add(i,i+1,0,0,(1<<17),X);
		scanf("%lld",&B[i]);
	}
	ll ans=0;
	for(int i=N-1;i>=0;i--){
		ll now=key((1<<17)-1+i);
		//printf("%lld %lld\n",now,B[i]);
		if(now%B[i]==0LL){continue;}
		//printf("%lld\n",B[i]-now%B[i]);
		ans+=(B[i]-now%B[i]);
		add(0,i,0,0,(1<<17),B[i]-now%B[i]);
	}
	printf("%lld\n",ans);
	return 0;
}


Measured memory_bytes: 2560
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
#define rep(i, n) for (int i = 1; i < (int)(n); i++)
#define all(x) (x).begin(),(x).end()
#define m1(x) memset(x,-1,sizeof(x))
const int INF = 1e9 + 1;
const ll MOD = 1e9 + 7;
const double PI = 3.141592653589793;

int main(){
  int n;
  cin >> n;
  string s;
  cin >> s;
  int a[100];
  if(s[0] == '(') a[0] = 1;
  else a[0] = -1;
  int k = a[0];
  for(int i = 1; i < s.size(); i++){
    if(s[i] == '('){
      a[i] = a[i-1] + 1;
    }else{
      a[i] = a[i - 1] - 1;
      k = min(k, a[i]);
    }
  }
  while(k < 0){
    cout << '(';
    k++;
    a[s.size() - 1] ++;
  }
  cout << s;
  while(a[s.size() - 1] > 0){
    cout << ')';
    a[s.size()  - 1] --;
  }
  cout << endl;
}



Measured memory_bytes: 256
def is_unbarance2(substring):
    return substring[0] == substring[1]


def is_unbarance3(substring):
    types = set(substring)
    return len(types) < 3


def main(string):
    if len(string) == 2:
        if is_unbarance2(string):
            return 1, 2
        else:
            return -1, -1
    else:
        for i in range(len(string) - 2):
            start = i
            stop = i + 3
            substring = string[start:stop]
            if is_unbarance3(substring):
                return start + 1, stop
        return -1, -1


if __name__ == '__main__':
    s = input()
    result = main(s)
    print(*result)


Measured memory_bytes: 3188
/*author @dhanush*/
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define boost ios_base::sync_with_stdio(false);cin.tie(NULL)
#define pb push_back
#define se second
#define fi first

int main()
{

#ifndef ONLINE_JUDGE
  freopen("input.txt", "r", stdin);
  freopen("output.txt", "w", stdout);
#endif
  int k;
  cin >> k;
  int val = 7 % k;
  int ans = 1;
  while (ans < 1e7 && val != 0)
  {
    ans++;
    val = (10 * val + 7) % k;
  }
  if (ans == 1e7)
  {
    cout << "-1";
  }
  else
  {
    cout << ans;
  }

}





Measured memory_bytes: 3588
#include <iostream>
#include <utility>
#include <tuple>
#include <vector>
#include <string>
#include <map>
#include <unordered_map>
#include <set>
#include <unordered_set>
#include <algorithm>
#include <functional>
#include <climits>
#include <numeric>
#include <queue>
#include <cmath>
#include <iomanip>
#include <array>
#include <string>
#include <stack>
#include <cassert>
#include <memory>
#include <random>

int main() {
	constexpr int MOD = 1000000007;
	int n, m; std::cin >> n >> m;
	std::vector<long long int> factorial(m + 1, 1), div(m + 1, 1), inverse(m + 1, 1);
	for (auto i = 2; i < factorial.size(); ++i) {
		factorial[i] = i * factorial[i - 1] % MOD;
		div[i] = (MOD - MOD / i) * div[MOD % i] % MOD;
		inverse[i] = div[i] * inverse[i - 1] % MOD;
	}
	std::vector<long long int> power(m + 1, 1);
	for (auto i = 1; i < power.size(); ++i) {
		power[i] = m * power[i - 1] % MOD;
	}
	const auto combination = [&factorial, &inverse, MOD](const int n, const int r) {return factorial[n] * inverse[r] % MOD * inverse[n - r] % MOD; };
	const auto permtation = [&factorial, &inverse, MOD](const int n, const int r) {
		return factorial[n] * inverse[n - r] % MOD;
	};
	long long int result{ permtation(m, n) };
	for (auto i = 1; i <= n; ++i) {
		const auto comb = combination(n, i);
		const auto perm = permtation(m - i, n - i);
		if ((i & 1) == 0) {
			result = (result + comb * perm % MOD) % MOD;
		}
		else {
			result = (MOD + result - comb * perm % MOD) % MOD;
		}
	}
	result = result * permtation(m, n) % MOD;
	std::cout << result << '\n';
}

Measured memory_bytes: 18780
#include <iostream>
#include <string.h>
#include <stdio.h>
#include <map>
#include <vector>
#include <math.h>
#include <algorithm>
#include <queue>
using namespace std;

#define rep(i,a) for(int i=0; i<a; i++)
#define rrep(i,a) for(int i=a; i>=0; i--)
#define loop3(i,j,k,a) for(int i=0; i<a; i++)for(int j=0; j<a; j++)if(i!=j)for(int k=0; k<a; k++)if(i!=k&&j!=k)
#define loop4(i,j,k,l,a) for(int i=0; i<a; i++)for(int j=0; j<a; j++)if(i!=j)for(int k=0; k<a; k++)if(i!=k&&j!=k)for(int l=0; l<a; l++)if(i!=l&&j!=l&&k!=l)
#define rep1(i,a) for(int i=1; i<=a; i++)

#define scnd1(a) scanf("%d", &a)
#define scnd2(a,b) scanf("%d%d", &a,&b)
#define scnd3(a,b,c) scanf("%d%d%d", &a,&b,&c)
#define scnd4(a,b,c,d) scanf("%d%d%d%d", &a,&b,&c,&d)

#define cin1(a) cin >> a;
#define cin2(a,b) cin >> a >> b;
#define cin3(a,b,c) cin >> a >> b >> c;
#define cin4(a,b,c,d) cin >> a >> b >> c >> d;
#define cout1(a) cout << a << endl;
#define cout2(a,b) cout << a << " " << b << endl;
#define cout3(a,b,c) cout << a << " " << b << " " << c << endl;
#define cout4(a,b,c,d) cout << a << " " << b << " " << c << " " << d << endl;
#define prtd1(a) printf("%d\n", a)
#define prtd2(a,b) printf("%d %d\n", a,b)
#define prtd3(a,b,c) printf("%d %d %d\n", a,b,c)
#define prtd4(a,b,c,d) printf("%d %d %d %d\n", a,b,c,d)

#define mem(a,n) memset( a, n, sizeof(a))
#define INF 1000000000
typedef long long ll;



int main() {
    string s;
    cin >> s;
    
    char now = s[0];
    int lsize = 1, rsize = s.size()-1, maxk=s.size();
    rep(i,s.size()-1) {
        if ( now != s[i+1]) {
            int t = lsize>rsize ? lsize:rsize;
            maxk = t<maxk ? t:maxk;
        }
        now = s[i+1];
        lsize++; rsize--;
    }
    cout << maxk << endl;
    
}


Measured memory_bytes: 512
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
constexpr long long MOD = 1000000007;
constexpr long long INF = 1LL << 60;
const long double PI = acosl(-1.0);
constexpr long double EPS = 1e-11;
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;
}
char lose(char i){
    if (i == 'r') return 's';
    else if (i == 's') return 'p';
	else
        return 'r';
}
char win(char i){
    if (i == 'r') return 'p';
    else if (i == 's') return 'r';
	else
        return 's';
}
int main(){
    ll n, k, r, s, p;
    cin >> n >> k >> r >> s >> p;
    string t;
    cin >> t;
    string ans;
    for (ll i = 0; i < n;i+=k){
        for (ll j = 0; j < k;j++){
            if (i + j >= n) continue;
            if (t[i + j] == 'r')
                ans += 'p';
            else if (t[i+j] == 's')
                ans += 'r';
			else if(t[i+j]=='p')
                ans += 's';
		if(i+j-k>-1 and ans[i+j-k]==ans[i+j]){
            ans.pop_back();
            if (i + j + k < n) {
                if (ans[i + j - k] == lose(t[i + j + k])) ans += t[i + j + k];
				else
                    ans += lose(t[i + j + k]);
            } else
                ans += win(ans[i+j-k]);
        }
        }
    }
    ll cnt = 0;
    for (ll i = 0; i < n; i++) {
        if (ans[i] == 'r' and t[i] == 's') cnt += r;
		else if (ans[i] == 's' and t[i] == 'p') cnt += s;
		else if (ans[i] == 'p' and t[i] == 'r') cnt += p;
    }
    cout << cnt << endl;
}

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

signed main(){
  string S,T;
  cin>>S>>T;
  int co=0;
  rep(i,3){
    if(S[i]==T[i])co++;
  }
  cout<<co<<endl;
}

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

int main(){
  int l, r;
  cin >> l >> r;
  int d;
  cin >> d;
  int ans = 0;
  for(int i=l;i<=r;i++){
    if(i%d == 0)ans++;
  }

  cout << ans << endl;
}

Measured memory_bytes: 3592
#include <stdio.h>

int max(int a,int b){
	if(a<b) return b;
	else return a;
}
int main(void) {
	int N=0;
	scanf("%d",&N);
	int fun[N][3];
	int dp[N][3];
	for(int i=0;i<N;i++){
		scanf("%d%d%d",&fun[i][0],&fun[i][1],&fun[i][2]);
	}
	dp[0][0] = fun[0][0];
	dp[0][1] = fun[0][1];
	dp[0][2] = fun[0][2];
	for(int i=1;i<N;i++){
		for(int j=0;j<3;j++){
			dp[i][j] = fun[i][j] + max(dp[i-1][(j+1)%3],dp[i-1][(j+2)%3]);
		}
	}
	printf("%d",max(dp[N-1][0],max(dp[N-1][1],dp[N-1][2])));
	/*for(int i=0;i<N;i++){
		for(int j=0;j<3;j++){
			printf("%d ",dp[i][j]);
		}
		printf("\n");
	}*/
	return 0;
	
	
}

Measured memory_bytes: 2560
#include <bits/stdc++.h>
#define double long double
#define int long long
#define MAXN 3010
using namespace std;
	int n;
	double P[MAXN];
	double dp[MAXN][MAXN];

int32_t main(){
	for(int i=0;i<MAXN;i++)for(int j=0;j<MAXN;j++)dp[i][j]=0;
	cin>>n;
	for(int i=1;i<=n;i++)cin>>P[i];
	
	dp[0][0]=0;
	dp[1][0]=1-P[1];
	dp[1][1]=P[1];
	for(int i=2;i<=n;i++)
		for(int j=0;j<=n;j++){
			dp[i][j]=(double)dp[i-1][j-1]*(P[i])+(double)dp[i-1][j]*(1-P[i]);
		}
	double res=0;
	for(int j=n/2+1;j<=n;j++){
		res+=dp[n][j];
	}
	cout<<setprecision(10)<<fixed;
	cout<<res<<endl;	
}


Measured memory_bytes: 141952
let n = stdin.ReadLine() |> int
let a = stdin.ReadLine().Split() |> Array.map int

let aCorrected = a |> Seq.mapi (fun i x -> x-(i+1) ) |> Seq.cache
//中央値を見つける
// n->偶数の場合はどちらでもいい
let center = aCorrected |> Seq.sort |> Seq.item ((n-1)/2)

(aCorrected |> Seq.map(fun x -> x - center |> abs) |> Seq.map int64 |> Seq.sum )
|> stdout.WriteLine

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

int main(){
    ll n , k ;
    cin >> n >> k ;
    vector<ll> P(n) ;
    vector<ll> C(n) ;
    rep(i,n){
        cin >> P.at(i) ;
        P.at(i)-- ;
    }
    rep(i,n){
        cin >> C.at(i) ;
    }
    ll ans = -1e18 ;
    rep(start,n){
        ll tot = 0 ;
        vector<ll> S ;
        ll now = start ;
        //周期を求める．
        while (1){
            now = P[now] ;//場所の更新
            S.push_back(C[now]) ;//移動先の配列をとる．
            tot += C[now] ;//一周した後の合計が正か負かで場合分け
            if(now == start) break ;//一周したらbreak 
        }
        ll l = S.size() ;
        ll tem = 0 ;
        ll t = 0 ;
        rep(i,l){
            t += S[i] ;
            if( i+1 > k ) break ;
            ll now = t ;
            if( tot > 0 ){
                ll e = ( k - i - 1 )/ l ;
                now += tot*e ;
            }
            ans = max(ans,now) ;
        }
    } 
    cout << ans <<endl ; 
}

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

#define reps(i,a,b) for(int i=(a);i<(b);++i)
#define rep(i,n)   reps(i,0,n)
#define all(x) (x).begin(),(x).end()
#define INF (2000000000)
#define MOD (1000000007)
#define PI (acos(-1))

int main(){
  string s;
  cin >> s;
  int k = s.size();
  int cnt=0;
  rep(i,k){
    if(s[i] == 'o')cnt++;
  }
  if(cnt+15-k>=8){
    cout << "YES" << endl;
  }else{
    cout << "NO" << endl;
  }
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		long n;

		Scanner in = new Scanner(System.in);

		while (in.hasNext()) {
			n = in.nextInt();

			System.out.println(primeCount(n));
		}
	}

	private static long primeCount(long n) {

		long[] list = new long[(int) n];
		int count = 0;

		list[0] = 0;
		for (int i = 1; i < n; i++)
			list[i] = 1;

		for (int i = 1; i < (int) Math.sqrt(n); i++) {
			if (list[i] == 1)
				for (int j = (i + 1); (i + 1) * j <= n; j++)
					list[(i + 1) * j - 1] = 0;
		}

		for (int i = 0; i < n; i++)
			if (list[i] == 1)
				count++;

		return count;
	}

}

Measured memory_bytes: 20000
h,w=gets.chomp.split.map(&:to_i)
a=[]
h.times do
    a << gets.chomp.split("")
end
a.reject! {|v| v.count(".") == v.size }
b = a.transpose
b.reject! {|v| v.count(".") == v.size }
a = b.transpose
a.each do |v|
    puts v.join
end

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

int main()
{
	int N;cin >>N;
	vector<int> A(N),B(N),C(N);
	for (int i=0;i<N;i++) cin >> A[i];
	for (int i=0;i<N;i++) cin >> B[i];
	for (int i=0;i<N;i++) cin >> C[i];
	long long ans=0;
	sort(A.begin(),A.end());
	sort(B.begin(),B.end());
	sort(C.begin(),C.end());
	for (int i=0;i<N;i++)
	{
		long long disA=distance(A.begin(),lower_bound(A.begin(),A.end(),B[i]));
		//disA=max(disA-1,0);
		long long disC=distance(upper_bound(C.begin(),C.end(),B[i]),C.end());
		ans+=disA*disC;
		//cout << disA << disC<< endl;
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 1536
#include <bits/stdc++.h>
#define REP(i, s, n) for (int i = s; i < (int)(n); i++)
#define ALL(a) a.begin(), a.end()
#define MOD 1000000007
using namespace std;
using ll = long long;

int N;
vector<vector<int>> D;
vector<vector<bool>> occupied;

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

void dfs(int x, int y) {
    int d = D[x][y] + occupied[x][y];
    REP(i, 0, 4) {
        int nx = x + dx[i];
        int ny = y + dy[i];
        if (nx < 0 || nx >= N || ny < 0 || ny >= N) continue;
        if (D[nx][ny] > d) {
            D[nx][ny] = d;
            dfs(nx, ny);
        }
    }
}

// void print(vector<vector<int>> &D) {
//     cout << "----------" << endl;
//     REP(i, 0, N) {
//         REP(j, 0, N) {
//             cout << D[i][j] << " ";
//         }
//         cout << endl;
//     }
//     cout << "----------" << endl;
// }

int main() {
    cin >> N;

    D.assign(N, vector<int>(N));
    REP(i, 0, N) REP(j, 0, N) {
        D[i][j] = min({
            i,
            j,
            N - 1 - i,
            N - 1 - j,
        });
    }
    
    int ans = 0;
    occupied.assign(N, vector<bool>(N, true));
    REP(i, 0, N * N) {
        int p; cin >> p; p--;
        ans += D[p / N][p % N];
        occupied[p / N][p % N] = false;
        dfs(p / N, p % N);
    }
    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 20032
import java.util.Scanner;

public class Main{
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		String s = sc.nextLine();

		if(s.equals("SUN")) System.out.println("7");
		else if(s.equals("MON")) System.out.println("6");
		else if(s.equals("TUE")) System.out.println("5");
		else if(s.equals("WED")) System.out.println("4");
		else if(s.equals("THU")) System.out.println("3");
		else if(s.equals("FRI")) System.out.println("2");
		else if(s.equals("SAT")) System.out.println("1");
		}
}

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

const ll LINF = 1e18;
const int INF = 1e9;
const ll MOD = 1000000007;

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;
}
vector<bool> seen;
void dfs(const Graph &G, int v){
    seen[v] = true; // vを訪問済みにする
    
    for(auto next_v: G[v]){
        if(seen[next_v]) continue; // next_vが探索済みならスルー
        dfs(G, next_v); // 再帰的に探索
    }
}

int main(){

    vector<char> al;
    al = {'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h',
                        'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p',
                        'q', 'r', 's', 't', 'u', 'v', 'w', 'x',
                        'y', 'z'};
    char c;
    cin >> c;
    for(int i = 0; i < al.size(); i++){
        if(al[i] == c) cout << al[i+1] << endl;
    }

    return 0;
}

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

using namespace std;
using ll = long long;

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

int main() {
  int n, u, v;
  cin >> n >> u >> v;
  --u, --v;
  vector<int> to[n];
  rep(i, n - 1) {
    int a, b;
    cin >> a >> b;
    --a, --b;
    to[a].push_back(b);
    to[b].push_back(a);
  }

  const int INF = 1001001001;
  vector<int> d1(n, INF), d2(n, INF);
  queue<int> q1, q2;

  d1[u] = 0;
  q1.push(u);
  while (!q1.empty()) {
    int s = q1.front();
    q1.pop();

    for (auto t : to[s]) {
      if (d1[t] != INF) continue;
      d1[t] = d1[s] + 1;
      q1.push(t);
    }
  }

  d2[v] = 0;
  q2.push(v);
  while (!q2.empty()) {
    int s = q2.front();
    q2.pop();

    for (auto t : to[s]) {
      if (d2[t] != INF) continue;
      d2[t] = d2[s] + 1;
      q2.push(t);
    }
  }

  int mx = 0;
  rep(i, n) {
    if (d2[i] <= d1[i]) continue;
    mx = max(mx, d2[i]);
  }

  int ans = mx - 1;
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 6656
#include <iostream>
#include <sstream>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <ctime>
#include <cstring>
#include <string>
#include <vector>
#include <stack>
#include <queue>
#include <deque>
#include <map>
#include <set>
#include <bitset>
#include <numeric>
#include <utility>
#include <iomanip>
#include <algorithm>
#include <functional>
using namespace std;

#define COUT(x) cout << #x << " = " << (x) << " (L" << __LINE__ << ")" << endl
#define EACH(i, s) for (__typeof__((s).begin()) i = (s).begin(); i != (s).end(); ++i)

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; }
template<class T1, class T2> ostream& operator << (ostream &s, pair<T1,T2> P)
{ return s << '<' << P.first << ", " << P.second << '>'; }
template<class T> ostream& operator << (ostream &s, vector<T> P)
{ for (int i = 0; i < P.size(); ++i) { if (i > 0) { s << " "; } s << P[i]; } return s; }
template<class T> ostream& operator << (ostream &s, vector<vector<T> > P)
{ for (int i = 0; i < P.size(); ++i) { s << endl << P[i]; } return s << endl; }
template<class T1, class T2> ostream& operator << (ostream &s, map<T1,T2> P)
{ EACH(it, P) { s << "<" << it->first << "->" << it->second << "> "; } return s << endl; }


int n;

int main() {
  while (cin >> n) {
	deque<int> de;
	for (int i = 0; i < n; ++i) {
	  int a; cin >> a;
	  if (i & 1) de.push_front(a);
	  else de.push_back(a);
	}
	if (n & 1) reverse(de.begin(), de.end());
	for (int i = 0; i < n; ++i) {
	  cout << de[i];
	  if (i != n-1) cout << " ";
	}
	cout << endl;
  }
}












Measured memory_bytes: 2944
#![allow(unused_imports)]
use proconio::{
   fastout, input,
   marker::{Bytes, Isize1, Usize1},
};

#[fastout]
fn main() {
   input! {
      n: usize,
      m: usize,
      mut ab: [(Usize1, Usize1); m]
   }
   ab.sort();
   let mut ans = 0;
   let mut bm = ab[0].1;
   for &(a, b) in ab.iter() {
      if bm <= a {
         ans += 1;
         bm = b;
      } else {
         bm = std::cmp::min(bm, b);
      }
   }
   ans += 1;
   println!("{}", ans);
}


Measured memory_bytes: 5540
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <cmath>
#define ll long long int
using namespace std;
ll stock[90];

int main() {
	ll N, buy_num = 0, st_num = 0, money = 1000;
	cin >> N ;
	for (int i = 0; i < N; i++){
		cin >> stock[i];
	}
	for (int i = 0; i < N; i++){
		if (stock[i+1] > stock[i]){
			st_num += money / stock[i];
			buy_num = money / stock[i];
			money = money - buy_num*stock[i];
		}
		else if (stock[i+1] < stock[i]){
			money += st_num*stock[i];
			st_num = 0;
		}
	}
	if (st_num > 0){
		money += st_num*stock[N-1];
		st_num = 0;
	}

	cout << money << endl;
	return 0;
}


Measured memory_bytes: 3580
#include <iostream>
#include <cstring>

using namespace std;

int main() {
        string teks;
        getline(cin,teks);
        int n=teks.size();
        for (int i=n-1; i>=0; i--) {
                cout << teks[i];
        }
        cout << endl;
        return 0;
}

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

const ll mod = 1e9+7;
const int maxn = 5e5+7;
int sum[maxn];
stack<int>sta;
std::vector<int> vec;
int pre[maxn],pos[maxn],a[maxn];;
ll dp[maxn];

int main (){
    int n;cin>>n;
    for(int i=0;i<n*2;i++) pre[i]=0;
    for(int i=1;i<=n;i++) cin>>a[i];
    for(int i=1;i<=n;i++) pre[i]=pos[a[i]],pos[a[i]]=i;
    dp[0]=1;

    for(int i=1;i<=n;i++){
        dp[i]=dp[i-1];
        if(pre[i]!=0&&pre[i]!=i-1) dp[i]=(dp[i]+dp[pre[i]])%mod;
    }
    cout<<dp[n]<<endl;
    return 0;
}




Measured memory_bytes: 9984
use std::io::*;
use std::str::FromStr;
use utils::*;

pub fn main() {
    let i = stdin();
    let mut o = Vec::new();
    run(i.lock(), &mut o);
    stdout().write_all(&o).unwrap();
}

fn run<R: BufRead, W: Write>(i: R, o: &mut W) {
    let mut i = CpReader::new(i);
    let (n, k) = i.read2::<usize, usize>();
    writeln!(o, "{}", solve(n, k)).unwrap();
}
fn solve(n: usize, k: usize) -> usize {
    let mut c = (n / k).pow(3);
    if k % 2 == 0 {
        let mut half = n / k;
        if n % k >= k / 2 {
            half += 1;
        }
        c += (half).pow(3);
    }
    c
}

mod utils {
    use super::*;

    pub struct CpReader<R: BufRead> {
        r: R,
        s: String,
    }

    macro_rules! fn_read {
        { $f:ident($($t:ident),*) } => {
            #[allow(dead_code)]
            pub fn $f<$($t: FromStr),*>(&mut self) -> ($($t),*) {
                let i = &mut self.read_line().split(' ');
                ($(read_next::<$t,_>(i)),*)
            }
        };
    }

    impl<R: BufRead> CpReader<R> {
        pub fn new(r: R) -> Self {
            CpReader {
                r: r,
                s: String::new(),
            }
        }
        pub fn read_line(&mut self) -> &str {
            self.s.clear();
            self.r.read_line(&mut self.s).unwrap();
            self.s.trim()
        }

        fn_read! { read2(T1, T2) }
        fn_read! { read3(T1, T2, T3) }
        fn_read! { read4(T1, T2, T3, T4) }
        fn_read! { read5(T1, T2, T3, T4, T5) }
    }
    fn read_next<'a, T: FromStr, I: Iterator<Item = &'a str>>(i: &mut I) -> T {
        i.next().unwrap().parse().ok().unwrap()
    }
}


Measured memory_bytes: 4352
import java.io.FileNotFoundException;
import java.util.Scanner;

public class Main {
    @SuppressWarnings("deprecation")
	public static void main(String[] args) throws FileNotFoundException {

//    	File file = new File("src/in.txt");

        //コード
//    	Scanner sc = new Scanner(file);
    	Scanner sc = new Scanner(System.in);

    	String S = sc.next();

    	boolean result1 = isPalindrome(S);
    	boolean result2 = isPalindrome(S.substring(0, (S.length()-1)/2));
    	if(result1&&result2) {
    		System.out.println("Yes");
    	} else {
    		System.out.println("No");
    	}
    }

    public static boolean isPalindrome(String s) {

    	boolean result = true;

    	if(s.length()%2==0) {
    		char[] arr = s.toCharArray();
    		for(int i=0;i<s.length()/2;i++) {
    			if(arr[i]!=arr[s.length()-1-i]) {
    				result = false;
    			}
    		}
    	} else {
    		char[] arr = s.toCharArray();
    		for(int i=0;i<(s.length()-1)/2;i++) {
    			if(arr[i]!=arr[s.length()-1-i]) {
    				result = false;
    			}
    		}
    	}

    	return result;
    }

}


Measured memory_bytes: 21844
import java.util.Scanner;
 
public class Main {
 
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int H = sc.nextInt();
        int W = sc.nextInt();
        sc.nextLine();
        char[][] map = new char[H][W];
        for (int i = 0; i < H; i++) {
        	map[i] = sc.nextLine().toCharArray();
        }
        
        boolean exit = false;
        for (int h = 0; h < H; h++) {
        	for (int w = 0; w < W; w++) {
        		if (map[h][w] == '#') 
        			if (!check(map,h,w,H,W)) {
        				exit = true;
        				break;
        			}
        	}
        	if (exit) break;
        }
        if (exit) {
        	System.out.println("No");
        } else {
            System.out.println("Yes");
        }
    }
    
    public static boolean check(char[][] map, int h, int w, int H, int W) {
    	if (h - 1 > -1 && map[h - 1][w] == '#') {//up
    		return true;
    	} else if (h + 1 < H && map[h + 1][w] == '#') {//down
    		return true;
    	} else if (w - 1 > -1 && map[h][w - 1] == '#') {
    		return true;
    	} else if (w + 1 < W && map[h][w + 1] == '#') {
    		return true;
    	}
    	return false;
    }
    
}

Measured memory_bytes: 21716
#include <bits/stdc++.h>
using namespace std;
#define int                 long long   
#define double              long double
#define endl                "\n"
#define pb                  push_back
#define PI                  3.1415926535897932384626433832795l
#define F                   first
#define S                   second
#define mp                  make_pair
#define f(i,n)              for(int i=0;i<n;++i)
#define loop(i,a,b)         for (int i=a ; i<b ;++i)
#define fastio              ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define all(v)              (v).begin(),(v).end()
#define rall(v)             (v).rbegin(),(v).rend()
#define gcd(a,b)            __gcd((a),(b))
#define fill(a,value)       memset(a,value,sizeof(a));
#define minn(v)             *min_element(v.begin(), v.end());
#define maxx(v)             *max_element(v.begin(), v.end());
#define print(x)            cout<<(x)<<endl;
typedef pair<int,int> pii;  
typedef vector<int> vi;
signed main() 
{
    fastio;
    int m,d;
    cin>>m>>d;
    int ans=0;
    for(int i=1;i<=m;i++)
    {
        for(int j=22;j<=d;j++)
        {
            int x=j/10;
            int y=j%10;
            if(x>=2 and y>=2 and x*y==i)
            {
                
                ans++;
            }
        }
    }
    print(ans)
    return 0;
    
    
}

Measured memory_bytes: 3648
INF = 10**9

N, M = map(int, input().split())
key = [[]]
for i in range(M):
    a, b = map(int, input().split())
    C = list(map(int, input().split()))
    tmp = 0
    for c in C:
        tmp += 2**(c-1)
    key.append([a, tmp])

dp = [[INF for _ in range(2**N)] for _ in range(M+2)]
for i in range(1, M+1):
    dp[i][key[i][1]] = min(dp[i][key[i][1]], key[i][0])
    for j in range(2**N):
        dp[i+1][j] = min(dp[i+1][j], dp[i][j])
        dp[i][j|key[i][1]] = min(dp[i][j|key[i][1]], dp[i-1][j]+key[i][0])
if dp[M][2**N-1] == INF:
    print(-1)
else:
    print(dp[M][2**N-1])

Measured memory_bytes: 80856
#include <stdio.h>

int main(void) {
  int N, D, X, cnt = 0;
  (void)scanf("%d %d %d", &N, &D, &X);

  for (int i = 0; i < N; i++) {
    int A;
    (void)scanf("%d", &A);
    cnt += (D-1) / A + 1;
  }
  printf("%d\n", cnt + X);

  return 0;
}


Measured memory_bytes: 128
import scala.io.{StdIn => in}
import scala.collection.{mutable => mu}
import java.lang.{Character => char}

object Main extends App {
  val Array(n,k) = in.readLine.split(" ").map(_.toInt)
  val s = in.readLine.map(char.getNumericValue)

  val table = mu.ArrayBuffer.empty[Int]
  s./:(-1)( (b, i) => {
    val v = if(i == 1) 1 else -1
    if(i != b) table.append(v)
    else table(table.size-1) += v
    i
  })

  val sums = table.scanLeft(0)((acc,i) => acc + i.abs)
  0 +=: table
  // debug(table.mkString(" "))
  // debug(sums.mkString(" "))

  def rec(acc:Int, cnt:Int, left:Int, right:Int, now:Int):Int = {
    // debug(acc, cnt, left, right, now)
    if(right == table.size) acc
    else {
      val nl = if(table(left) < 0) 1 else 0
      if(cnt-nl == k && now == 1)
        rec(acc max (sums(right)-sums(left)), cnt-nl, left+1, right, now)
      else if(cnt <= k)
        rec(acc max (sums(right)-sums(left)), cnt+(now^1), left, right+1, now^1)
      else
        rec(acc, cnt-nl, left+1, right,now)
    }
  }

  val ans = rec(0,0,0,1,s.head)
  println(ans)

  def debug(any:Any*):Unit = {
    if(this.getClass.toString != "class Main$")
      println(any.mkString(" "))
  }
}

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

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

const ll mod =  1000000007;  //出力は (ans % mod + mod) % mod  (負の剰余を正にする)
const int inf = 1e9;
const long long INF = 1LL << 60;   // INF = 1152921504606846976

int main()
{
    int n; cin >> n;
    ll ans = 0;
    rep(i,n){
        int a; cin >> a;
        while(a%2==0){
            ans++;
            a /= 2;
        }
    }
    cout << ans << endl;
}

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

int main(){
	int N;
	scanf("%d",&N);
	int a=N/100;
	int b=N%10;
	if (a==b){
		printf("Yes\n");
	}
	else{
		printf("No\n");
	}
	return 0;
}

Measured memory_bytes: 128
while line = gets do
    x=Array.new(3) { |i|  }
    x[0],x[1],x[2] = line.split.map(&:to_i)
    if x[0]+x[1]+x[2]==0 then
        break
    end
    x=x.sort
    w=Math.sqrt(x[0]**2+x[1]**2)
    #puts w

    gets.to_i.times do
        a = gets.to_i
        if a*2>w then
            puts 'OK'
        else
            puts 'NA'
        end
    end
end

Measured memory_bytes: 6128
#include <stdio.h>


int main(void)
{
  int n, m, a[60], b[60];
  int ans[60]={0};

  scanf("%d %d", &n, &m);

  for (int i=0; i < m; i++) {
    scanf("%d %d", &a[i], &b[i]);
  }
  for (int i=0; i < m; i++) {
    ans[a[i]]++;
    ans[b[i]]++;
  }

  for (int i=1; i <= n; i++) {
    printf("%d\n", ans[i]);
  }


    return 0;
}


Measured memory_bytes: 128
use std::vec::Vec;
use std::cmp::*;

fn read<T: std::str::FromStr>() -> T {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).ok();
    s.trim().parse().ok().unwrap()
}

fn read_vec<T: std::str::FromStr>() -> Vec<T> {
    read::<String>().split_whitespace().map(|e| e.parse().ok().unwrap()).collect()
}

fn main() {
    let (n, k) = {
      let v: Vec<usize> = read_vec();
      (v[0], v[1])
    };
    let mut s: Vec<char> = read::<String>().chars().collect();
    let mut k = k;
    let count = count_same_element(&s);
    for (i, &(left, right)) in count.iter().enumerate() {
      if i % 2 == 1 && k > 0 {
        let c = change(s[left]);
        k -= 1;
        for j in left..right+1 {
          s[j] = c;
        }
      }
    }
    let mut ans = 0;
    for i in 0..n-1 {
      if s[i] == s[i+1] {
        ans += 1;
      }
    }
    println!("{}", ans);
}

fn count_same_element<T: Eq + Copy>(v: &Vec<T>) -> Vec<(usize, usize)> {

  let mut res: Vec<(usize, usize)> = Vec::new();
  if v.len() == 0 {
    return res;
  }

  let mut now: T = v[0];
  let mut count: usize = 0;
  let mut left = 0;
  for (i, &e) in v.iter().enumerate() {
    if e == now {
      count += 1;
    }
    else {
      res.push((left, count+left-1));
      count = 1;
      now = e;
      left = i;
    }
  }
  res.push((left, count+left-1));

  res
}

fn change(c: char) -> char {
  match c {
    'R' => 'L',
    _ => 'R',
  }
}


Measured memory_bytes: 6396
#include <iostream>
#include <algorithm>

using namespace std;

int main()
{
	for(int n;cin>>n;){
		int cs[7]={},d[7][7]={};
		for(int i=0;i<7;i++)
			d[i][i]=1;
		for(int i=0;i<n;i++){
			int x; cin>>x;
			cs[x/10]++;
			cs[x%10]++;
			d[x/10][x%10]=d[x%10][x/10]=1;
		}
		
		for(int k=0;k<7;k++)
			for(int i=0;i<7;i++)
				for(int j=0;j<7;j++)
					d[i][j]|=d[i][k]&d[k][j];
		
		bool yes=count_if(cs,cs+7,[](int n){return n&1;})<=2;
		for(int i=0;i<7;i++)
			for(int j=0;j<7;j++)
				if(cs[i] && cs[j] && !d[i][j])
					yes=false;
		
		puts(yes?"Yes":"No");
	}
	
	return 0;
}

Measured memory_bytes: 1116