akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <string>
#include <math.h>

using namespace std;
int main() {
    int a,b;
    cin>>a>>b;
    int sum=0;
    for(int i=a;i<=b;i++){
        string s=to_string(i);
        if(s[0]==s[4] and s[1]==s[3] ) sum++;
    }
    cout<<sum<<endl;
}

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

using namespace std;

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

#define int ll

const ll mod = 1e9 + 7;


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

	cout << (x/500)*1000 + (x%500)/5*5 << endl;

	return 0;
}


Measured memory_bytes: 3608
from heapq import *

n,m=map(int,input().split())
a=list(map(lambda x:int(x)*-1,input().split()))

heapify(a)

for i in range(m):
    x=heappop(a)
    x*=-1
    x//=2
    x*=-1
    heappush(a,x)


print(sum(a)*-1)

Measured memory_bytes: 86000
#include <iostream>
#include <vector>
#include <algorithm>

using namespace std;

const int inf = 1 << 30;

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

	vector<int> a(M);
	vector<int> c(M);
	for (int i = 0; i < M; ++i) {
		int b;
		cin >> a[i] >> b;

		c[i] = 0;
		for (int j = 0; j < b; ++j) {
			int x;
			cin >> x;
			c[i] |= 1 << (x - 1);
		}
	}

	vector<int> dp(1 << N, inf);
	dp[0] = 0;

	for (int i = 0; i < M; ++i) {
		vector<int> t = dp;
		for (int k = 0; k < (1 << N); ++k) {
			t[k | c[i]] = min(t[k | c[i]], t[k] + a[i]);
		}
		dp.swap(t);
	}

	auto ans = dp.back() == inf ? -1 : dp.back();
	cout << ans << endl;
}


Measured memory_bytes: 256
using System;
using System.Collections;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Numerics;
using System.Text;
using System.Threading.Tasks;
using static System.Console;
using static System.Math;
class Z { static void Main() => new K(); }
class K
{
	int F => int.Parse(Str);
	long FL => long.Parse(Str);
	int[] G => Strs.Select(int.Parse).ToArray();
	long[] GL => Strs.Select(long.Parse).ToArray();
	string Str => ReadLine();
	string[] Strs => Str.Split(new char[] { ' ', '\t' }, StringSplitOptions.RemoveEmptyEntries);
	const int MOD = 1000000007;
	public K()
	{
		SetOut(new StreamWriter(OpenStandardOutput()) { AutoFlush = false });
		Solve();
		Out.Flush();
	}
	void Solve()
	{
		var S = Str;
		WriteLine(S[0] == 'A' && S.Substring(2, S.Length - 3).Count(c => c == 'C') == 1 && S.Substring(1).Count(c => char.IsUpper(c)) == 1 ? "AC" : "WA");
	}
}


Measured memory_bytes: 13140
#include <stdio.h>
#include <stdlib.h>
#include <algorithm>

#define MAX_N (300)
#define INF (100000000000000000L)

using namespace std;

long dp[MAX_N][MAX_N][MAX_N + 1];

int main(int argc, char *argv[]) {
  // read inputs
  long N, ass[MAX_N][MAX_N];
  scanf("%ld", &N);
  for (long i = 0; i < N; i++) {
    for (long j = 0; j < N; j++) {
      scanf("%ld", &ass[i][j]);
    }
  }

  // warshall-floyd
  // initialize
  for (long i = 0; i < N; i++) {
    for (long j = 0; j < N; j++) {
      dp[i][j][0] = ass[i][j];
    }
  }
  // calculate
  for (long k = 0; k < N; k++) {
    for (long i = 0; i < N; i++) {
      for (long j = 0; j < N; j++) {
        dp[i][j][k + 1] = min(dp[i][j][k], dp[i][k][k] + dp[k][j][k]);
      }
    }
  }
  // for (long i = 0; i < N; i++) {
  //   for (long j = 0; j < N; j++) {
  //     printf("%ld ", dp[i][j][N]);
  //   }
  //   printf("\n");
  // }
  // check that it matches ass
  for (long i = 0; i < N; i++) {
    for (long j = 0; j < N; j++) {
      if (dp[i][j][N] != ass[i][j]) {
        printf("-1\n");
        return 0;
      }
    }
  }

  // solve
  long ans = 0;
  for (long i = 0; i < N; i++) {
    for (long j = i + 1; j < N; j++) {
      long is_removable = 0;
      for (long k = 0; k < N; k++) {
        if (k != i && k != j && ass[i][j] == ass[i][k] + ass[k][j]) {
          is_removable = 1;
        }
      }
      if (!is_removable) {
        ans += ass[i][j];
      }
    }
  }
  printf("%ld\n", ans);

  return 0;
}


Measured memory_bytes: 212480
import sys
readline = sys.stdin.readline
sys.setrecursionlimit(10**8)
mod = 10**9+7
#mod = 998244353
INF = 10**18
eps = 10**-7

N = int(readline())
A = list(map(int,readline().split()))
from collections import Counter
Ac = Counter(A)
s = sum(A)
Q = int(readline())
for i in range(Q):
    b,c = map(int,readline().split())
    s += (c-b)*Ac[b]
    Ac[c] += Ac[b]
    Ac[b] = 0
    print(s)


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

#define ALL(v) (v).begin(), (v).end()
#define rep(i, n) for (ll i = 0, __##i##_length = (n); i < __##i##_length; i++)
#define rep_reverse(i, n) for (ll i = (n)-1; 0 <= i; i--)
#define FOR(i, from, to) for (ll i = (from), __##i##_end = (to); i < __##i##_end; i++)
#define FOR_REVERSE(i, from, to) for (ll i = (to)-1, __##i##_end = (from); __##i##_end <= i; i--)
#define foreach(e, v) for (const auto e : (v))
#define vfree(v) std::vector<int>().swap(v)
#define DEBUG(x) cout << #x << " = " << (x) << endl

using namespace std;
typedef int64_t ll;
typedef vector<ll> llv;
typedef vector<llv> llvv;

ll gcd(ll a, ll b)
{
    return (a < b) ? gcd(b, a) : ((a % b) ? gcd(b, a % b) : b);
}

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

int main()
{
    ll A, B, C, D;
    cin >> A >> B >> C >> D;
    ll c = B / C - (A - 1) / C;
    ll d = B / D - (A - 1) / D;
    ll cd = B / lcm(C, D) - (A - 1) / lcm(C, D);
    cout << (B - A + 1) - (c + d - cd) << endl;
    return 0;
}


Measured memory_bytes: 256
package main

import(
    "fmt"
    "sort"
    "strings"
)



func main() {
    var n int
    fmt.Scan(&n)
    ans := 1
    for i:=2;i<=n;i*=2{
        ans = i
    }
    fmt.Println(ans)
}





// Pairsort
type Pair struct {
    first,second int64
}

type By func(p1, p2 *Pair) bool

func (by By) Sort(pairs []Pair) {
    ps := &pairSorter{
            pairs : pairs,
            by: by,
    }
    sort.Sort(ps)
}

type pairSorter struct {
    pairs []Pair
    by func(p1, p2 *Pair) bool
}

func (s *pairSorter) Len() int {
    return len(s.pairs)
}

func (s *pairSorter) Swap(i, j int) {
    s.pairs[i], s.pairs[j] = s.pairs[j], s.pairs[i]
}

func (s *pairSorter) Less(i, j int) bool {
    return s.by(&s.pairs[i], &s.pairs[j])
}

func first (p1, p2 *Pair) bool {
        return p1.first < p2.first
}

func second (p1, p2 *Pair) bool {
        return p1.second < p2.second
}
// end



func abs32(a int) int {
    if a<0{
        return -a
    }
    return a
}

func abs64(a int64) int64 {
    if a<0{
        return -a
    }
    return a
}

func min32(a, b int) int {
    if a >= b {
        return b
    }
    return a
}

func max32(a, b int) int {
    if a >= b {
        return a
    }
    return b
}

func min64(a, b int64) int64 {
    if a >= b {
        return b
    }
    return a
}

func max64(a, b int64) int64 {
    if a >= b {
        return a
    }
    return b
}

func gcd(a, b int64) int64 {
    if a % b == 0 {
        return b
    } else {
        return gcd(b, a%b)
    }
}

func lcm(a, b int64) int64 {
    return a / gcd(a, b) * b
}

func scanNums(len int) (nums []int){
    var num int
    for i:=0; i<len; i++{
        fmt.Scan(&num)
        nums = append(nums,num)
    }
    return
}

func scanNums64(len int) (nums []int64){
    var num int64
    for i:=0; i<len; i++{
        fmt.Scan(&num)
        nums = append(nums,num)
    }
    return
}

func scanString(len int) (str []string){
    var s string
    for i:=0; i<len; i++{
        fmt.Scan(&s)
        str = append(str,s)
    }
    return
}

func makeTwoNums(n,m int) ([][]int){
    Nums := make([][]int, n)
    for i:=0; i<n; i++{
        Nums[i] = make([]int, m)
    }
    return Nums
}

func sortString(s string) string{
    t := strings.Split(s, "")
    sort.Strings(t)
    return strings.Join(t, "")
}

func reverseString(s string) string{
    t := []rune(s)
    for i,j := 0, len(s)-1 ; i < j ; i, j = i+1, j-1 {
        t[i], t[j] = t[j], t[i]
    }
    return string(t)
}

func inside(h,w,H,W int) bool{
    if h>=0 && h<H && w>=0 && w<W{
        return true
    }
    return false
}


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

const int N = 100000 + 10;
int n, p, x, m1, m2, tmp;
int a[N], b[N], dp[N];

int main() 
{
	cin >> n;
	for (int i = 0; i < n; i++){
		cin >> a[i];
	}
	dp[0] = 0;
	dp[1] = abs(a[0] - a[1]);
//	dp[2] = min(dp[0] + abs(a[2] - a[0]), dp[1] + abs(a[2] - a[1]));
	for (int i = 2; i < n; i++) {		
		m1 = dp[i - 2] + abs(a[i] - a[i - 2]);
		m2 = dp[i - 1] + abs(a[i] - a[i - 1]);
		dp[i] = min(m1, m2);
	}
	cout << dp[n - 1];
	return 0;
}


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

using namespace std;

#define S scanf
#define P printf
#define G getline
#define SZ size()
#define C clear()
#define B begin()
#define F front()
#define T top()
#define E end()
#define EM empty()
#define V vector
#define Q queue
#define DQ deque
#define PQ priority_queue
#define ST stack
#define FI first
#define SE second
#define PI acos(-1)
#define PS push
#define PP pop()
#define PSF push_front
#define PSB push_back
#define PPF pop_front()
#define PPB pop_back()
#define MP make_pair
#define LL long long int
#define ULL unsigned long long int
#define PII pair<int,int>
#define PSI pair<string,int>
#define PIS pair<int,string>
#define PLI pair<long long int,int>
#define PLL pair<long long int,long long int>
#define MII map<int,int>
#define MSI map<string,int>
#define MIS map<int,string>
#define MLI map<long long int,int>
#define FAST() ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)





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






int main()
{
//    FAST();

//    freopen("input.txt","r",stdin);
//    freopen("output.txt","w",stdout);

    int i,n;
    char s[102];
    S("%d %s",&n,s+1);
    if(n & 1)P("No");
    else
    {
        for(i=1;i<=n/2;i++)
        {
            if(s[i] != s[n/2+i])
            {
                P("No");
                return 0;
            }
        }
        P("Yes");
    }
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main(){
    long n,k,r,s,p,ans = 0;
    string t;
    cin >> n >> k >> r >> s >> p >> t;
    for(int i=0;i<k;i++){
        char cur = 'n';
        long cnt = 0;
        for(int j=0;j<=(n/k)*k;j+=k){
            if(n<=i+j) continue;
            char a = t[i+j];
            if(cur!=a){
                cur = a;
                if(a=='r') cnt += p;
                if(a=='s') cnt += r;
                if(a=='p') cnt += s;
                continue;
            }
            if(cur==a) cur = 'n';
        }
        ans += cnt;
    }
    cout << ans << endl;
}

Measured memory_bytes: 512
import sys
from collections import deque  # 双方向キュー
from collections import defaultdict  # 初期化済み辞書
from heapq import heapify, heappush, heappop, heappushpop  # プライオリティキュー
from bisect import bisect_left, bisect_right  # 二分探索
#import numpy as np  # 1.8.2
#import scipy  # 0.13.3

s2nn = lambda s: [int(c) for c in s.split(' ')]
ss2nn = lambda ss: [int(s) for s in ss]
ss2nnn = lambda ss: [s2nn(s) for s in ss]
i2s = lambda: sys.stdin.readline().rstrip()
i2n = lambda: int(i2s())
i2nn = lambda: s2nn(i2s())
ii2ss = lambda n: [sys.stdin.readline().rstrip() for _ in range(n)]
ii2nn = lambda n: ss2nn(ii2ss(n))
ii2nnn = lambda n: ss2nnn(ii2ss(n))

def main():
    N, K = i2nn()
    if K == 1:
        print(0)
    else:
        print(N - K)

main()


Measured memory_bytes: 38384
/**
 * @brief  : c++ code for AtCoder
 * @author : rk222
 * @created: 2019.05.19 20:58:39
 */

#include <algorithm>
#include <cmath>
#include <cstdio>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
using namespace std;

typedef long long ll;
typedef long double ld;
typedef pair<int, int> P;
typedef pair<int, P> P1;

#define fr first
#define sc second
#define mp make_pair
#define pb push_back
#define rep(i, x) for (int i = 0; i < x; i++)
#define rep1(i, x) for (int i = 1; i <= x; i++)
#define rrep(i, x) for (int i = x - 1; i >= 0; i--)
#define rrep1(i, x) for (int i = x; i > 0; i--)
#define sor(v) sort(v.begin(), v.end())
#define rev(s) reverse(s.begin(), s.end())
#define lb(vec, a) lower_bound(vec.begin(), vec.end(), a)
#define ub(vec, a) upper_bound(vec.begin(), vec.end(), a)
#define uniq(vec) vec.erase(unique(vec.begin(), vec.end()), vec.end())
#define mp1(a, b, c) P1(a, P(b, c))

#define disp(x) cout << #x << ": " << x << endl
#define disp_vec(v)                                                                           \
    cout << #v << ":";                                                                        \
    rep(i, v.size()) cout << " " << v[i];                                                     \
    cout << endl

const int INF = 100000000;
const int M = 100000000;
const int dir_4[4][2] = {{1, 0}, {0, 1}, {-1, 0}, {0, -1}};
const int dir_8[8][2] = {{1, 0}, {1, 1}, {0, 1}, {-1, 1}, {-1, 0}, {-1, -1}, {0, -1}, {1, -1}};

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

int main() {
    double n, k;
    scanf("%lf%lf", &n, &k);

    int i = 0;
    int pre = n + 1;
    int now = k;
    int cnt = 0;
    double ret = 0;
    while (1) {
        if (pre - now <= 0) {
            i++;
            now = (now + 1) / 2;
            continue;
        } else {
            cnt = pre - now;
            ret += (double)cnt / n * (1 / (double)(1 << i));

            pre = now;
            i++;
            if (now == 1)
                break;
            // cout << "i:" << i << ret << endl;
            now = (now + 1) / 2;
        }
    }

    printf("%.12lf\n", ret);

    /* --------------------------------- */
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define repd(i,a,b) for (int i=(a);i<(b);i++)
#define rep(i,n) repd(i,0,n)
//#define int long long
typedef long long ll;
using namespace std;
const int MOD = 1000000007;
const int INF = 1010000000;
const double EPS = 1e-10;
const pair<int,int> fd[] = {make_pair(1,0),make_pair(-1,0),make_pair(0,1),make_pair(0,-1)}; 

signed main(){
  int s;cin>>s;
  bool a[100000000];rep(i,100000000)a[i] = false;
  a[s] = true;
  rep(i,INF){
    if(s%2 == 0){
      s /= 2;
    }else{
      s = 3*s+1;
    }
    if(a[s]){
      cout << i+2 << endl;
      return 0;
    }
    a[s] = true;
  }

}


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

using namespace std;

int main ()
{
    int n;
    cin >> n;
    int arrived;
    vector<int> order(n);

    for(int i=0; i<n; i++){    
        cin >> arrived;
        order.at(arrived-1) = i;
    }

    for(int i=0; i<n; i++)
        cout << order.at(i)+1 << endl;

    return 0;
}


Measured memory_bytes: 3632
K = int(input())
S = input()
L = len(S)
MOD = 10**9+7

MAXN = K+L+5
fac = [1,1] + [0]*MAXN
finv = [1,1] + [0]*MAXN
inv = [0,1] + [0]*MAXN
for i in range(2,MAXN+2):
    fac[i] = fac[i-1] * i % MOD
    inv[i] = -inv[MOD%i] * (MOD // i) % MOD
    finv[i] = finv[i-1] * inv[i] % MOD

def comb(n,r):
    if n < r: return 0
    if n < 0 or r < 0: return 0
    return fac[n] * (finv[r] * finv[n-r] % MOD) % MOD

ans = 0
for i in range(K+1):
    ans += comb(L-1+i,i) * pow(25,i,MOD) * pow(26,K-i,MOD)
    ans %= MOD
print(ans)

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

using namespace std;
 
int main() {
 char N;
  
  cin >> N;
  
  if(N == 'a' || N == 'i' || N == 'u' || N == 'e' || N == 'o'){
    cout << "vowel" << endl;
  }
  else{
    cout << "consonant" << endl;
  }
}

Measured memory_bytes: 256
// Problem : A - Sandglass2
// Contest : AtCoder - AtCoder Beginner Contest 072
// URL : https://atcoder.jp/contests/abc072/tasks/abc072_a
// Memory Limit : 256 MB
// Time Limit : 2000 ms
// Powered by CP Editor (https://github.com/cpeditor/cpeditor)

//#pragma GCC optimize("Ofast")
//#pragma GCC optimize ("unroll-loops")
//#pragma GCC target("avx,avx2,fma")
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#define eb emplace_back
#define pb push_back
#define size(s) (int)s.size()
#define int long long
#define vi vector<int>
#define vs vector<string>
#define vv vector<vector<int>>
#define pii pair<int,int>
#define m_p(x,y) make_pair(x,y)
#define vp vector<pair<int,int>>
#define setbits(x) __builtin_popcountll(x)
#define f first
#define se second
#define inc(v,n,x) v.assign(n,x)
#define incd(v,n) v.resize(n)
#define iniz(n) memset(n,0,sizeof(n))
#define inin(n) memset(n,-1,sizeof(n))
#define inimi(n) memset(n,0xc0,sizeof(n))
#define inima(n) memset(n,0x3f,sizeof(n))
#define all(v) (v).begin(),(v).end()

using namespace std;

template<typename T1,typename T2>istream &operator>>(istream &is, vector<pair<T1,T2>> &v) { for (pair<T1,T2> &t : v) is >> t.f>>t.se; return is; }
template<typename T>istream &operator>>(istream &is, vector<T> &v) { for (T &t : v) is >> t; return is; }
template<typename T>ostream &operator<<(ostream &os, const vector<T> &v) { for (const T &t : v) {os << t <<" ";} os << '\n'; return os; }

const int N=200001;
double pi=acos(-1.0);
int md=1e9+7;
const int INF=1e15;
int dx1[]={0,0,-1,1};
int dy1[]={1,-1,0,0};

template<class T>
T abst(T a)
{return a<0?-a:a;}

template<class T>
T max2(T a,T b){return a>b?a:b;}
template<class T>
T min2(T a,T b){return a<b?a:b;}

void solve()
{
int x,t;cin>>x>>t;
if(t>=x)
cout<<0;
else
cout<<x-t;
}

int32_t main(){
ios_base::sync_with_stdio(0);cin.tie(NULL);cout.tie(NULL);
int t=1;
//cin>>t;
for(int i=1;i<=t;i++)
{
    solve();
}
return 0;
}


Measured memory_bytes: 3632
sixexp=[6**i for i in range(1,7)]
nineexp=[9**i for i in range(1,6)]
lis=[1]+sixexp+nineexp

n=int(input())

F=[0,1]

for i in range(2,n+1):
    dplis=[]
    for j in lis:
        if i-j>=0:
            dplis.append(F[i-j]+1)
    F.append(min(dplis))

print(F[n])

Measured memory_bytes: 45148
n, m, q = gets.split(" ").map(&:to_i)

array = (1..m).to_a.repeated_combination(n).to_a
scores = Array.new(array.length, 0)

for i in 1..q
  a, b, c, d = gets.split(" ").map(&:to_i)
  array.each_with_index do |arr, i|
    scores[i] += d if arr[b-1] - arr[a-1]  == c
  end
end

p scores.max

Measured memory_bytes: 28704
#include <bits/stdc++.h>
#define rep(i, n) for (int i=0; i<(n); ++i)
#define repr(i, a, b) for (int i=a; i<(b); ++i)
#define reprev(i, n) for (int i=n-1; i>=0; --i)
#define reprrev(i, a, b) for (int i=b-1; i>=(a); --i)
using namespace std;
using ll = long long;
using P = pair<int, int>;

int dh[4] = {-1, 0, 1, 0},
    dw[4] = {0, 1, 0, -1};

int main() {
    cout << fixed << setprecision(10);
    
    int H, W; cin >> H >> W;
    vector<vector<int>> a(H, vector<int>(W));
    rep(i, H) rep(j, W) cin >> a[i][j];

    stack<P> stk;
    stk.emplace(make_pair(0, 0));
    vector<vector<int>> thr(H, vector<int>(W));
    thr[0][0] = 1;
    int has_odd = 0;
    vector<P> troute;
    if (a[0][0] % 2 == 1) {
        has_odd = 1;
        troute.emplace_back(make_pair(0, 0));
    }

    vector<vector<P>> route;
    int n = 0;

    while (!stk.empty()) {
        auto p = stk.top(); stk.pop();
        int ch = p.first, cw = p.second;
        rep(i, 4) {
            int nh = ch + dh[i], nw = cw + dw[i];
            if (nh >= 0 && nw >= 0 && nh < H && nw < W && thr[nh][nw] == 0) {
                stk.emplace(make_pair(nh, nw));
                thr[nh][nw] = 1;
                if (has_odd) {
                    troute.emplace_back(make_pair(nh, nw));
                    if (a[nh][nw] % 2 == 1) {
                        route.emplace_back(troute);
                        n += troute.size() - 1;
                        troute.clear();
                        has_odd = 0;
                    }
                } else {
                    if (a[nh][nw] % 2 == 1) {
                        troute.emplace_back(make_pair(nh, nw));
                        has_odd = 1;
                    }
                }
                break;
            }
        }
    }

    cout << n << endl;
    rep(i, route.size()) {
        rep(j, route[i].size()-1) {
            cout << route[i][j].first + 1 << " " << route[i][j].second + 1 << " ";
            cout << route[i][j+1].first + 1 << " " << route[i][j+1].second + 1 << endl;
        }
    }


    return 0;
}

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

using namespace std;

string s, t;

void Main() {
    cin >> s >> t;
    //vector<vector<string>> memo(s.size() + 10, vector<string>(t.size() + 10, "0"));
    //string ans = lcs(0, 0, memo);
    vector<vector<pair<int, int>>> prev(s.size() + 1, vector<pair<int, int>>(t.size() + 1, make_pair(-1, -1)));
    vector<vector<int>> lcs(s.size() + 1, vector<int>(t.size() + 1, -1));
    for (int i = s.size() - 1; i >= 0; --i) {
        for (int j = t.size() - 1; j >= 0; --j) {
            if (s[i] == t[j]) {
                if (i == s.size() - 1 || j == t.size() - 1) {
                    lcs[i][j] = 1;
                }
                else {
                    lcs[i][j] = lcs[i + 1][j + 1] + 1;
                }
                prev[i][j] = make_pair(i + 1, j + 1);
            }
            else {
                int from_i = (i < s.size() - 1) ? lcs[i + 1][j] : 0;
                int from_j = (j < t.size() - 1) ? lcs[i][j + 1] : 0;
                if (from_i > from_j) {
                    lcs[i][j] = from_i;
                    prev[i][j] = make_pair(i + 1, j);
                }
                else {
                    lcs[i][j] = from_j;
                    prev[i][j] = make_pair(i, j + 1);
                }
            }
        }
    }

    string common = "";
    pair<int, int> curr = make_pair(0, 0);
    while (common.size() < lcs[0][0]) {
        if (s[curr.first] == t[curr.second]) {
            common += s[curr.first];
        }
        curr = prev[curr.first][curr.second];
    }
    cout << common << endl;
}

int main() {
    std::cout << std::fixed << std::setprecision(15);
    Main();
    return 0;
}


Measured memory_bytes: 109092
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cmath>
#include <vector> 
#include <cstring>
#include <queue>
#include <stack>
#include <ctime>
#include <set>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int,int> pii;
typedef pair<ll,int> pli;
typedef pair<int,ll> pil;
  
  
namespace io{
    const int L = (1 << 20) + 1;
     
    char buf[L], *S , *T, c;
      
    char getchar() {
        if(S == T) {
            T = (S = buf) + fread(buf, 1, L, stdin);
            return (S == T ? EOF : *S++);
        }
        return *S++;
    }
     
    int inp() {
        int x = 0, f = 1; char ch;
        for(ch = getchar(); !isdigit(ch); ch = getchar())
            if(ch == '-') f = -1;
        for(; isdigit(ch); x = x * 10 + ch - '0', ch = getchar());
        return x * f;
    }
     
    ll inp_ll() {
        ll x = 0; int f = 1; char ch;
        for(ch = getchar(); !isdigit(ch); ch = getchar())
            if(ch == '-') f = -1;
        for(; isdigit(ch); x = x * 10 + ch - '0', ch = getchar());
        return x * f;
    }
     
    char B[25], *outs=B+20, *outr=B+20;
    template<class T>
    inline void print(register T a,register char x=0){
        if(x) *--outs = x, x = 0;
         
        if(!a)*--outs = '0';
        else
            while(a)
                *--outs = (a % 10) + 48, a /= 10;
         
        if(x)
            *--outs = x;
         
        fwrite(outs, outr - outs , 1, stdout);
        outs = outr;
    }
};
  
using io :: print;
using io :: inp;
using io :: inp_ll;
const int maxN = 2e5 + 10;
const int MOD = 1e9 + 7;
ll c[2*maxN][40];
int n,M;
vector<pii> cnt;
void cal(int X)
{
	int x = sqrt(X);
	for(int i=2;i<=x;i++)
	{
		if(M%i == 0)
		{
			int t = 0;
			while(X%i == 0)
			{
				t++;
				X /= i;	
			}
			cnt.push_back(pii(i,t));		
		}
	}
	if(X > 1)
	cnt.push_back(pii(X,1));
		
}
ll init()
{
	for(int i=0;i<=2*maxN-1;i++)
	{
		c[i][0] = 1;	
	}	
	for(int i=1;i<=2*maxN-1;i++)
	{
		for(int j =1;j<=30;j++)
		{
			c[i][j] = (c[i-1][j] + c[i-1][j-1])%MOD;
		}
	}
}
int main()
{
	n = inp();
	M = inp();
	cal(M);
	init();
	ll ans = 1;
	for(auto p:cnt)
	{
		int k = p.first;
		int len = p.second;
		(ans *= c[n+len-1][len])%=MOD;
	}
	printf("%lld\n",ans);
    return 0;
}

Measured memory_bytes: 125312
#include <stdio.h>
#include <stdint.h>
#include <inttypes.h>
#include <stdlib.h>
#include <string.h>

typedef unsigned long long int uint64;
typedef long long int          int64;
 
#define MAX(a,b) ((a)>(b)?(a):(b))
#define MIN(a,b) ((a)<(b)?(a):(b))
#define ABS(a) ((a)>(0)?(a):-(a))

void get_N (int64 *n)
{
  int cnt;
  
  cnt = scanf("%lld", n);

  return;
}

void get_NK (int64 *n, int64 *k)
{
  int cnt;
  
  cnt = scanf("%lld %lld", n, k);

  return;
}

void omit_LF (void)
{
  char c;
  int  cnt;
  
  cnt = scanf("%c", &c);
  return;
}

char *get_S (int64 n)
{
  char *buf;
  int  i;
  int  cnt;

  buf = malloc((size_t)(n * sizeof(char)));
  if (buf == NULL) {
    return NULL;
  }

  cnt = scanf("%s", buf);

  return buf;
}

char *get_SN (int64 max, int64 *size)
{
  char *buf;
  int  i;
  int  n;

  buf = malloc((size_t)(max * sizeof(char)));
  if (buf == NULL) {
    return NULL;
  }

  scanf("%s", buf);

  n = strlen(buf);

  *size = n;
  
  return buf;
}

typedef struct _tmp_t {
  int64    a;
  int64    b;
} tmp_t;


tmp_t *get_NSeq (int64 n)
{
  tmp_t *buf;
  int64 i;

  buf = malloc((size_t)(n * sizeof(tmp_t)));
  for (i=0; i<n; i++) {
    get_N(&buf[i].a);
  }

  return buf;
}

int compare_a(const void *a, const void *b)
{
  tmp_t *x;
  tmp_t *y;

  x = (tmp_t *)a;
  y = (tmp_t *)b;

  if (x->a > y->a) return 1;
  if (x->a < y->a) return -1;

  return 0;
}

int compare_b(const void *a, const void *b)
{
  tmp_t *x;
  tmp_t *y;

  x = (tmp_t *)a;
  y = (tmp_t *)b;

  if (x->b > y->b) return 1;
  if (x->b < y->b) return -1;

  return 0;
}

void qsort_a (tmp_t *array, int size)
{
  qsort(array, size, sizeof(tmp_t), compare_a);
}

void qsort_b (tmp_t *array, int size)
{
  qsort(array, size, sizeof(tmp_t), compare_b);
}

int main()
{
  int64 N;
  tmp_t *A;
  int64 i;
  
  get_N(&N);

  A = get_NSeq(N);

  qsort_a (A, N);

  for (i=1; i<N; i++) {
    if (A[i-1].a == A[i].a) {
      printf ("NO");
      return 0;
    }
  }

  printf ("YES");
  return 0;
}



Measured memory_bytes: 6396
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#include <queue>
using namespace std;
int main() {
	string S,T;
	cin >> S;
	cin >> T;
	int count = 0;
	for (int i = 0; i < S.size(); i++) {
		if (S[i] != T[i])count++;
	}
	cout << count;
}

Measured memory_bytes: 3920
# -*- coding: utf-8 -*-
# 整数の入力
N = int(input())
cards = [int(s) for s in input().split()]

alice_total = 0
bob_total = 0

cards.sort(reverse=True)

for i in range(len(cards)):
  if i % 2 == 0:
    alice_total += cards[i]
  else:
    bob_total += cards[i]

diff = alice_total - bob_total
print(diff)


Measured memory_bytes: 9032
#include<cstdio>
#include<cstring>
#include<cmath>
#include<cstdlib>
#include<algorithm>
#include<iostream>
using namespace std;
int a,b,c;
int X,Y;
int n,m;
int main()
{
	cin>>n>>m;
	cin>>X>>Y;
	a=X;b=Y;
	for(register int i=1;i<=n;++i) cin>>c,a=max(a,c);
	for(register int i=1;i<=m;++i) cin>>c,b=min(b,c);
	if(a<b) puts("No War");
	else puts("War");
}
 

Measured memory_bytes: 256
class B169
  def call(n, a_s)
    limit = 10 ** 18
    result = 1
    return 0 unless a_s.find_index(0).nil?
    a_s.each do |x|
      result *= x
      return -1 if result > limit
    end
    result
  end

  def main
    n = gets
    a_s = gets.split(' ').map { |x| x.to_i }
    puts call(n, a_s)
  end
end

B169.new.main

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

#define pb push_back
#define ll long long
#define maxn 100005
#define fr(i,j,k) for(int i=j;i<k;i++)
#define f(n) fr(i,0,n)
#define f1(n) fr(i,1,n+1)
#define ms(i) memset(i,0,sizeof(i));
#define ms1(i) memset(i,-1,sizeof(i));
#define F first
#define S second

int main(){
	ios_base::sync_with_stdio(0);
	cin.tie(0);
    int n;
    cin >> n;
    string s;
    cin >> s;
    if(n&1){
        cout << "No" << endl;
        exit(0);
    }
    if(s.substr(0,n/2) == s.substr(n/2)){
        cout << "Yes" << endl;
    }
    else{
        cout << "No" << endl;
    }
}


Measured memory_bytes: 256
#include<stdio.h>
int ans = 0;
int a[100000];
int num;
int  binsearch(int key)
{
	int mid;
	int left = 0;
	int right = num ;
	while (left<right)
	{
		mid = (left + right) / 2;
		if (key < a[mid])
		{
			right = mid;
		}
		else if (key > a[mid])
		{
			left = mid+1;
		}
		else if (key == a[mid])
		{
			return 1;
		}
	}
	return 0;
}
int main()
{
	int i;
	int n;
	int j;
	int key;
	scanf("%d", &num);
	for (i = 0;i < num;i++)
	{
		scanf("%d", &a[i]);
	}
	scanf("%d", &n);
	for (j = 0;j < n;j++)
	{
		scanf("%d", &key);
		if (binsearch(key) )
		{
			ans++;
		}
	}	
	printf("%d\n", ans);
    return 0;
}



Measured memory_bytes: 2128
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
def main():
    X = int(readline())
    for b in range(-1000, 1001):
        for a in range(b, 1001):
            if a**5 -b**5 == X:        
                A = a
                B = b
                break
    print(A, B)            
if __name__ == '__main__':
    main()

Measured memory_bytes: 9248
import java.util.Scanner;
public class Main{
 public static void main(String[] args) {
   Scanner kbd = new Scanner(System.in);
   int n =kbd.nextInt();
   int a=n/100;
   int b=(n-100*a)/10;
   int c=(n-100*a-10*b);
   if(a!=7&&b!=7&&c!=7){
     System.out.println("No");
   }else{
     System.out.println("Yes");
   }
 }
}


Measured memory_bytes: 35756
#include <iostream>
#include <climits>
#include <cmath>
#include <algorithm>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <string>
#include <deque>
#define INF_INT (INT_MAX / 2)
#define INF_LONG (LONG_MAX / 2)
//#define DEBUG true
#define DEBUG false
using namespace std;

const int MAX = 100001;
const int MOD = 1000000007;

typedef long long ll;
typedef pair< int, int > pii;
typedef pair< ll, ll > pll;
typedef pair< ll, int > pli;
typedef pair< int, ll > pil;

int ceil(int x, int y){
  return (x % y == 0) ? x / y : x / y + 1;
}

int gcd(int x, int y){
  return y ? gcd(y, x % y) : x;
}

int lcm(int x, int y){
  return x / gcd(x, y) * y;
}

bool check(ll x, ll k, ll a[], ll f[], int n){
  ll sum = 0;
  for(int i = 0; i < n; i++){
    if(a[i] * f[n - i - 1] > x){
      sum += a[i] - (x / f[n - i - 1]);
    }
  }
  return sum <= k;
}

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

  int n;
  ll k;
  cin >> n >> k;
  ll a[n], f[n];
  for(int i = 0; i < n; i++) cin >> a[i];
  for(int i = 0; i < n; i++) cin >> f[i];

  sort(a, a + n);
  sort(f, f + n);

  ll low = -1, high = INF_LONG;
  while(high - low > 1){
    ll mid = (high + low) / 2;
    if(check(mid, k, a, f, n)) high = mid;
    else low = mid;
  }

  cout << high << endl;

  return 0;
}


Measured memory_bytes: 3328
#include <iostream>
#include <stdio.h>
#include <cmath>
#include <algorithm>
#include <climits>
#include <vector>
#include <iomanip>
#include <string>
#include <queue>
#include <numeric>
#include <functional>
#include <array>
#include <map>

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

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

	//約数
	vector<int>divisor;
	double count = sqrt(sum);
	for (int i = 1; i < count; ++i) {
		if (sum % i == 0) {
			divisor.push_back(i);
			divisor.push_back(sum / i);
		}
	}

	int ans = 1;
	vector<int> amari(N);
	for (int div : divisor) {
		long long total = 0;
		for (int i = 0; i < N; ++i) {
			amari[i] = A[i] % div;
			total += amari[i];
		}
		sort(amari.begin(), amari.end());

		int minusCount = total / div;
		int plusCountIndex = N - minusCount;
		int count = 0;
		for (int i = 0; i < plusCountIndex; ++i)count += amari[i];
		if (count <= K) ans = max(ans, div);
	}
	cout << ans << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main(void){
    string w, t;
    int sum = 0;
    cin >> w;
    for (int i = 0; i < w.size(); i++){
        if(w[i] >= 'A' && w[i] <= 'Z')
            w[i] += 'a' - 'A'; 
    }
    cin >> t;
    while (t != "END_OF_TEXT") {
        for (int i = 0; i < t.size(); i++){
            if(t[i] >= 'A' && t[i] <= 'Z')
                t[i] += 'a' - 'A';
        }
    if (w == t)
        sum++;
    cin >> t;
    }
    
    cout << sum << endl;
}



Measured memory_bytes: 3204
#include <iostream>
#include <vector>
#include <cmath>

using namespace std;

int main(void){
  int data;
  cin >> data;
  int w = data/1000;
  int x = (data - w*1000)/100;
  int y = (data - w*1000 - x*100)/10;
  int z = data - w*1000 - x*100 - y*10;
  int ans=w;
  if((w+x+y+z) < 7) {
    cout << w << "+" << x << "+"<< y << "+"<< z << "=7";
    return 0;
  }

  char a[8][3]= {
    {'+','+','+'},
    {'+','+','-'},
    {'+','-','+'},
    {'+','-','-'},
    {'-','+','+'},
    {'-','+','-'},
    {'-','-','+'},
    {'-','-','-'},
  };

  int b[3] = {x,y,z};
  for (int i=0;i<8;i++){
    ans = w;
    for (int j=0;j<3;j++){
      if(a[i][j] == '+')ans+=b[j];
      else ans-=b[j];
    }
    if (ans==7){
      cout << w << a[i][0] << x << a[i][1]<< y << a[i][2]<< z << "=7";
      return 0;
    }
  }
  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <cmath>
#include <string>
#include <array>
#include <vector>
#include <functional>
#include <unordered_map> 
#include <map> 
#include <numeric>
#include <limits>
#include <utility>
#include <queue>
#include <random>
#include <bitset>
#include <memory>
#include <complex>
using namespace std;
typedef long long LL;

int main() {
	LL n,ans=1;
	cin >>n;
	for (int i = 1; i <= n; i++) {
		ans*=i;
		ans%=1000000000+7;
	}
	cout <<ans<<endl;
    return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
#include<string.h>
#define N 3
#define LIM 32
#define HN 362897
typedef struct {
    int depth,key;
}dep;
dep  h[HN];
int ans[N][N]={{1,2,3},{4,5,6},{7,8,0}},min = LIM;
int hash1(int k) {
    return k % HN;
}
int hash2(int k){
    return 1 + k%(HN-1);
}
int hash(int k, int i){
    return (hash1(k) + i*hash2(k))%HN;
}
void dfs(int p[N][N], int n){
    int i,j,i0,j0,a=0,b=1,f=0,tmp[N][N];
    for(i=0;i<N;i++){
        for(j=0;j<N;j++){
            if(ans[i][j]!=p[i][j])f++;
            if(p[i][j]==0){
                i0=i;
                j0=j;
            }
            a+=p[i][j]*b;
            b*=10;
        }
    }
    if(f==0&&min>=n) {
        min=n;
        return;
    }
    if(n>min) return;
    i=0;
    while(1){
        b=hash(a, i);
        if(h[b].key == 0){
            h[b].key=a;
            h[b].depth=n;
            break;
        }else if(h[b].key == a){
            if(h[b].depth>n){
                h[b].depth=n;
                break;
            }
            else return;
        }
        i++;
    }
    if(i0>0 && i0<N){
        memcpy(tmp,p,sizeof(int)*N*N);
        f=tmp[i0][j0];
        tmp[i0][j0]=tmp[i0-1][j0];
        tmp[i0-1][j0]=f;
        dfs(tmp, n+1);
    }
    if(j0>0 && j0<N){
        memcpy(tmp,p,sizeof(int)*N*N);
        f=tmp[i0][j0];
        tmp[i0][j0]=tmp[i0][j0-1];
        tmp[i0][j0-1]=f;
        dfs(tmp, n+1);
    }
    if(i0>=0 && i0<N-1){
        memcpy(tmp,p,sizeof(int)*N*N);
        f=tmp[i0][j0];
        tmp[i0][j0]=tmp[i0+1][j0];
        tmp[i0+1][j0]=f;
        dfs(tmp, n+1);
    }
    if(j0>=0 && j0<N-1){
        memcpy(tmp,p,sizeof(int)*N*N);
        f=tmp[i0][j0];
        tmp[i0][j0]=tmp[i0][j0+1];
        tmp[i0][j0+1]=f;
        dfs(tmp, n+1);
    }
}
int main(){
    int i,j,p[N][N];
    for(i=0;i<N;i++)
        for(j=0;j<N;j++)
            scanf("%d",&p[i][j]);
    dfs(p,0);
    printf("%d\n",min);
    return 0;
}


Measured memory_bytes: 4688
#include <bits/stdc++.h>
using namespace std;
main(){
int a,n,max=-1000000,min=1000000;
long long int sum=0;
cin>>n;
for(int i=0;i<n;i++){
  cin>>a;
  if(max<a)max=a;
  if(min>a)min=a;
  sum+=a;
}
cout<<min<<" "<<max<<" "<<sum<<endl;
  return 0;
}



Measured memory_bytes: 3096
#include<iostream>

int main(){
	int n;
	while(std::cin >> n, n){
		while(n--){
			int x1, y1, z1, w1, x2, y2, z2, w2;
			std::cin >> x1 >> y1 >> z1 >> w1 >> x2 >> y2 >> z2 >> w2;
			std::cout << (x1*x2-y1*y2-z1*z2-w1*w2) << " " << (x1*y2+x2*y1+z1*w2-w1*z2) << " "
								<< (x1*z2-y1*w2+z1*x2+w1*y2) << " " << (x1*w2+y1*z2-z1*y2+w1*x2) << std::endl;
		}
	}
}

Measured memory_bytes: 1160
from itertools import accumulate
# python template for atcoder1
import sys
sys.setrecursionlimit(10**9)
input = sys.stdin.readline

N = int(input())
A = list(map(int, input().split()))
A = sorted(A)
a_acc = list(accumulate(A))

ans = N

seq = 1
for i in range(N-1):
    if a_acc[i]*2 >= A[i+1]:
        seq += 1
    else:
        ans -= seq
        seq = 1
print(ans)


Measured memory_bytes: 62104
n = gets.to_i

n.times do |vez|
  gets.chomp
  map = []
  8.times do
    map << gets.chomp.chars.map(&:to_i)
  end
  x = gets.to_i - 1
  y = gets.to_i - 1

  current_bomb = [y, x]

  until current_bomb.empty?
    x = current_bomb.pop
    y = current_bomb.pop
    
    -3.upto(3) do |i|
      if (0..7).include?(x+i) && map[y][x+i] == 1
        current_bomb.push(y)
        current_bomb.push(x+i)
        map[y][x+i] = 0
      end
      if (0..7).include?(y+i) && map[y+i][x] == 1
        current_bomb.push(y+i)
        current_bomb.push(x)
        map[y+i][x] = 0
      end
    end
  end

  puts "Data #{vez+1}:"
  8.times { |i| puts map[i].join }
end

Measured memory_bytes: 6116
#include <bits/stdc++.h>
#define INF 2e9
#define MOD 1000000007
#define MOD9 998244353
#define intMAX 51000;
#define PI 3.14159265359
using namespace std;
typedef long long llong;
// typedef long double ldouble;

using Graph = vector<vector<int>>;

// int ctoi(const char c){
//   if('0' <= c && c <= '9') return (c-'0');
//   return -1;
// }

// int gcd(int a, int b){
//   int ma = max(a,b);
//   int mi = min(a,b);
//   if(mi == 0) return ma;

//   return gcd(mi, ma%mi);
// }

// llong POW(llong a, llong b){
//   if(b == 0) return 1;
//   else{
//     if(b%2 == 0) return POW(a * a % MOD, b / 2) % MOD;
//     else return a * POW(a * a % MOD, b / 2) % MOD;
//   }
// }

int main(){
  int N, A, B;
  cin >> N >> A >> B;
  cout << min(N * A, B) << endl;
}

Measured memory_bytes: 256
package main

import "fmt"

func main() {
	var a [3]int
	fmt.Scanln(&a[0], &a[1], &a[2])
	for i := 0; i < 2; i++ {
		for j := i + 1; j < 3; j++ {
			if a[i] > a[j] {
				t := a[i]
				a[i] = a[j]
				a[j] = t
			}
		}
	}
	fmt.Println(a[0], a[1], a[2])
	return
}



Measured memory_bytes: 1164
#include<bits/stdc++.h>
using namespace std;
int main()
{
	int n;
	cin>>n;
	string s,t;
	cin>>s;
	if(s.size()<=n)
	cout<<s<<endl;
	else
	{
		for(int i=0;i<n;i++)
		t=t+s[i];
		cout<<t<<"..."<<endl;
	}
}

Measured memory_bytes: 3600
#include <bits/stdc++.h>
#define rep(i,a,b) for(int i=a;i<(b);++i)
#define erep(i,a,b) for(int i=a;i<=(int)(b);++i)
#define per(i,a,b) for(int i=(a);i>(b);--i)
#define eper(i,a,b) for(int i=(a);i>=b;--i)
#define pb push_back
#define mp make_pair
#define INF (1<<31)-1
#define MOD 1000000007
#define all(x) (x).begin(),(x).end()
#define vii vector<int>
#define vll vector<long long>
using namespace std;
typedef long long ll;
typedef pair<int,int> Pii;
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a = b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a = b; return 1; } return 0; }
int dy[]={0, 0, 1, -1};
int dx[]={1, -1, 0, 0};
int gcd(int a,int b){return b?gcd(b,a%b):a;}
int lcm(int a,int b){return a/gcd(a, b)*b;}

int n, m;
int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
    cin >> n;
    map<ll, ll> d;
    rep(i, 0, n) {
        ll a; cin >> a;
        d[a]++;
    }
    cin >> m;
    rep(i, 0, m) {
        ll t;
        cin >> t;
        if (d[t] > 0) {
            d[t]--;
        } else {
            cout << "NO" << endl;
            return 0;
        }
    }
    cout << "YES" << endl;
    return 0;
}


Measured memory_bytes: 12800
#include <bits/stdc++.h>
using namespace std;
using Graph = vector<vector<int>>;
using info = vector<int>;
Graph G;
info v;

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

  for (int i = 1; i <= N; ++i) {
    v.push_back(i);
  }

  int count = 0;
  do {
    if (v.at(0) != 1) break;
    
    bool cont = false;
    for (int i = 0; i < N-1; ++i) {
      cont = false;
      for (auto nv : G[v.at(i)]) {
        if (nv == v.at(i+1)) {
          cont = true;
          break;
        }
      }
      if (!cont) break;
    }
    if (cont) count++;
    
  } while (next_permutation(v.begin(), v.end()));

  cout << count << endl;
}


Measured memory_bytes: 256
#include <iostream> 
#include <string> 
#include <vector> 
#include <cmath> 
#include <algorithm> 
#include <cstdlib> 
#include <ctime> 
#include <cstdio> 
#include <functional> 
#include <set> 
#include <sstream> 
#include <cctype>
#include <stack>
#include <queue>
#include <cstring>
#include <map>

using namespace std;

int slove(int s,int t){
	if(s==t) return 0;
	
	int res=0;
	if(s%2!=0){res++; s++;}
	if(t%2!=0){res++; t--;}
	res+=slove(s/2,t/2);
	
	return res;
	
}

int main(){
	
	int n;
	cin>>n;
	for(int i=0;i<n;i++){
		int s,t;
		cin>>s>>t;
		cout<<slove(s,t)<<endl;
	}
	
	return 0;
}

Measured memory_bytes: 3092
using System;
using System.Collections.Generic;
using System.Collections;
using System.Linq;

namespace Atcoder_0404
{
    class Program
    {
        static void Main(string[] args)
        {
            var K = GetInput_int()[0];
            long sum = 0;
            for (int a = 1; a <= K; a++)
            {
                for (int b = 1; b <= K; b++)
                {
                    for (int c = 1; c <= K; c++)
                    {
                        var s = koby(b, c);
                        var t= koby(a, s);
                        sum += t;
                    }
                }
            }
            Console.WriteLine(sum);
        }

        static int koby(int a,int b)
        {
            var x = a * b;
            if (a < b)
            {
                var temp = a;
                a = b;
                b = temp;
            }
            var r = a % b;
            while (r != 0)
            {
                a = b;
                b = r;
                r = a % b;
            }
            return b;
        }
        #region input
        

        static string[] GetInput_string()
        {
            var input = Console.ReadLine().Split(' ');
            return input;
        }

        static int[] GetInput_int()
        {
            var input = GetInput_string();
            var result = new int[input.Length];
            for (int i = 0; i < result.Length; i++)
            {
                result[i] = int.Parse(input[i]);
            }
            return result;
        }
        static long[] GetInput_long()
        {
            var input = GetInput_string();
            var result = new long[input.Length];
            for (int i = 0; i < result.Length; i++)
            {
                result[i] = long.Parse(input[i]);
            }
            return result;
        }
        #endregion
        #region sonota
        static void Swap_array<T>(T[] target, int a, int b)
        {
            T temp = target[a];
            target[a] = target[b];
            target[b] = temp;
        }
        static void Swap_list<T>(List<T> target, int a, int b)
        {
            T temp = target[a];
            target[a] = target[b];
            target[b] = temp;
        }
        #endregion
    }
}

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

using namespace std;
typedef long long ll;
const int MAXN = 100100;

int N;
int arr[MAXN];

int main()
{
    ios_base::sync_with_stdio(0);
    
    cin >> N;
    for (int i = 0; i < N; i++)
        cin >> arr[i];

    int ctot = 0;

    for (int i = 0; i < N; i++)
        ctot += arr[i];

    int ans = 0;
    if (ctot % 10)
        ans = max (ans, ctot);
    for (int i = 0; i < N; i++)
    {
        if (arr[i] % 10 != 0)
            ans = max (ans, ctot - arr[i]);
    }
    cout << ans << "\n";
}

Measured memory_bytes: 256
use proconio::{input, fastout};

#[fastout]
fn main() {
    input! {
        n: u16,
        y: u32,
    }
    let y = y / 1000;

    for i in 0..=n {
        for j in 0..=(n-i) {
            let k = n - i - j;
            let total = 10*i + 5*j + k;
            if y == total.into() {
                println!("{} {} {}", i, j, k);
                return
            }
        }
    }
    println!("-1 -1 -1");
}


Measured memory_bytes: 2180
n = int(input())
dp = [0] * n
h = [int(i) for i in input().split()]
dp[1] = abs(h[1] - h[0])
for i in range(2, n):
    dp[i] = min(dp[i-1] + abs(h[i] - h[i-1]), dp[i-2] + abs(h[i] - h[i-2]))
print(dp[n-1])


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

int main() {
  int n;
  cin >> n;
  vector<int> cnt(4);
  for (int i = 0; i < n; i ++) {
    string s;
    cin >> s;
    if (s[0] == 'B' && s.back() == 'A') cnt[0] ++;
    else if (s[0] == 'B') cnt[1] ++;
    else if (s.back() == 'A') cnt[2] ++;

    for (int j = 1; j < s.size(); j ++) {
      if (s[j - 1] == 'A' && s[j] == 'B') cnt[3] ++;
    }
  }

  int ans = cnt[3];
  if (cnt[0] > 0) {
    ans += cnt[0] - 1;
    if (cnt[1]) {
      ans ++;
      cnt[1] --;
    }
    if (cnt[2]) {
      ans ++;
      cnt[2] --;
    }
  }
  ans += min(cnt[1], cnt[2]);

  cout << ans << endl;
}

Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<cmath>
#include<cstdio>
#include<vector>
#include<cassert>
#include<climits>
#include<map>
#include<set>

#define REP(i,s,n) for(int i=s;i<n;i++)
#define rep(i,n) REP(i,0,n)
#define IINF (INT_MAX)
#define MAX_V 1010000

using namespace std;

typedef pair<int,int> ii;

//RMQ

int rn;
ii dat[2*MAX_V-1];
void init(int n_){
  rn = 1;
  while(rn<n_)rn*=2;
  for(int i=0;i<2*rn-1;i++)dat[i] = ii(IINF,IINF);//ii(depth,index)
}
 
// k番めの値(0-indexed)をaに変更
void update(int k,ii a){
  k += rn-1;
  dat[k] = a;
  while(k > 0){
    k = (k-1)/2;
    dat[k] = (dat[k*2+1].first>dat[k*2+2].first?dat[k*2+2]:dat[k*2+1]);
  }
}

ii _query(int a,int b,int k,int l,int r){
  if(r<=a || b<=l)return ii(IINF,-1);
  else if(a<=l && r<=b)return dat[k];
  
  ii vl = _query(a,b,k*2+1,l,(l+r)/2);
  ii vr = _query(a,b,k*2+2,(l+r)/2,r);
  
  return min(vl,vr);
}

//nの範囲でミスしないように極力こっちを利用 
ii query(int a,int b){
  return _query(a,b,0,0,rn);
}

//

int V;
vector<int> G[MAX_V];
int root;

int vs[MAX_V*2-1];
int depth[MAX_V*2-1];
int id[MAX_V];

void dfs(int v,int p,int d,int &k){
  id[v] = k;
  vs[k] = v;
  depth[k++] = d;
  for(int i=0;i<G[v].size();i++){
    if(G[v][i] != p){
      dfs(G[v][i],v,d+1,k);
      vs[k] = v;
      depth[k++] = d;
    }
  }
}

void RQMinit(){
  int k = 0;
  dfs(root,-1,0,k);
  
  init(k+1);  
  rep(i,k)update(i,ii(depth[i],vs[i]));
}

int lca(int u,int v){
  return query(min(id[u],id[v]),max(id[u],id[v])+1).second;
}


int main(){
  int n;
  cin >> n;
  V = n;
  rep(i,V){
    int k,c;
    cin >> k;
    rep(j,k){
      cin >> c;
      G[i].push_back(c);
      G[c].push_back(i);
    }
  }

  RQMinit();
  int q,u,v;
  cin >> q;
  rep(i,q){
    cin >> u >> v;
    cout << lca(u,v) << endl;
  }

  return 0;
}

Measured memory_bytes: 61484
#include <bits/stdc++.h>
#define ll long long
using namespace std;
const int M=1010,MOD=1e9+7;
int n,m,dp[M][M];
char g[M][M];
int main()
{
    scanf("%d%d",&n,&m);
    for(int i=1;i<=n;i++)
        scanf("%s",g[i]+1);
    dp[0][1]=1;
    for(int i=1;i<=n;i++)
        for(int j=1;j<=m;j++)
            if(g[i][j]=='.')
                dp[i][j]=((ll)dp[i-1][j]+dp[i][j-1])%MOD;
    printf("%d\n",dp[n][m]);
    return 0;
}


Measured memory_bytes: 5248
#include <iostream>

using namespace std;

int main(){
  int W,H;
   
while(1){
  
  cin >> W >> H;
  
  if(W==0&&H==0){
    
    break;
  }
  
  for(int i=0;i<W;i++){
    
    for(int j=0;j<H;j++){
      
      cout << '#';
    }
    
  cout << endl;
    
}
  cout << endl;
}
}


Measured memory_bytes: 3116