akhauriyash/Code-Regression huggingface dataset:
import math
n,m = [int(i) for i in input().split()]
if abs(n-m)>=2:
  print(0)
elif abs(n-m)==1:
  print((math.factorial(n) * math.factorial(m))%(10**9 +7))
elif abs(n-m)==0:
  print((math.factorial(n) * math.factorial(m))*2 %(10**9 +7))

Measured memory_bytes: 5192
#include <algorithm>
#include <cassert>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <functional>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <string>
#include <vector>
using namespace std;

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

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

// Self settings
// clang-format off
#define MAX_N 100000
#define REP(i, N) for (int i = 0; i < (int)(N); ++i)
// clang-format on
ll A, B;

void solve()
{
  ll ans = 0;
  ll a = A, b = B;
  if (a % 2 == 0 && b % 2 == 0) {
    ans = b ^ (((b - a) / 2) % 2 == 1 ? 1 : 0);
  }
  else if (a % 2 == 0 && b % 2 == 1) {
    ans = (((b - a + 1) / 2) % 2 == 1 ? 1 : 0);
  }
  else if (a % 2 == 1 && b % 2 == 0) {
    ans = a ^ (((b - a - 1) / 2) % 2 == 1 ? 1 : 0) ^ b;
  }
  else {
    ans = a ^ (((b - a) / 2) % 2 == 1 ? 1 : 0);
  }
  cout << ans << endl;
}

int main(void)
{
  cin >> A >> B;
  solve();
  return 0;
}


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

typedef long long LL;

#define FOR(i, a, b) for (int i = (a), i##_END_ = (b); i <= i##_END_; i++)
#define DNF(i, a, b) for (int i = (a), i##_END_ = (b); i >= i##_END_; i--)

template <typename Tp> void in(Tp &x) {
	char ch = getchar(), f = 1; x = 0;
	while (ch != '-' && (ch < '0' || ch > '9')) ch = getchar();
	if (ch == '-') ch = getchar(), f = -1;
	while (ch >= '0' && ch <= '9') x = x * 10 + ch - '0', ch = getchar();
	x *= f;
}

template <typename Tp> void out(Tp x) {
	if (x > 9) out(x / 10);
	putchar(x % 10 + '0');
	return;
}

template <typename Tp> Tp Max(const Tp &x, const Tp &y) {return x > y ? x : y;}
template <typename Tp> Tp Min(const Tp &x, const Tp &y) {return x < y ? x : y;}
template <typename Tp> bool chkmax(Tp &x, Tp y) {return x >= y ? 0 : (x=y, 1);}
template <typename Tp> bool chkmin(Tp &x, Tp y) {return x <= y ? 0 : (x=y, 1);}

int A, B, C, x, y;

int main()
{
	in(A); in(B); in(C); in(x); in(y);

	int ans = 0x3f3f3f3f;
	
	FOR(i, 0, x) {
		int need = i * A + 2 * (x - i) * C;
		int two = y - (x - i);
		if (two <= 0) chkmin(ans, need);
		else chkmin(ans, need + Min(2 * C, B) * two);
	}

	printf("%d\n", ans);
	
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define FOR(i,a,b) for (int i = (a); i < (b); ++i)
#define rep(i,n) for (int i = (0); i < (n); ++i)
#define rng(x) (x).begin(),(x).end()
#define rrng(x) (x).rbegin(),(x).rend()
#define show(x) cout << #x << " = " << (x) << endl
#define show2(x,y) cout << #x << " = " << (x) << ", " << #y << " = " << (y) << endl
#define show3(x,y,z) cout << #x << " = " << (x) << ", " << #y << " = " << (y) <<  ", " << #z << " = " << (z) << endl
#define showv(v) rep(i,v.size()) printf("%d%c", v[i], i==v.size()-1?'\n':' ')
#define showv2(v) rep(j,v.size()) showv(v[j])
#define showt(t,n) rep(i,n) printf("%d%c", t[i], i==n-1?'\n':' ')
#define showt2(t,r,c) rep(j,r) showt(t[j],c)
#define printv(v) rep(i,v.size()) printf("%d\n", v[i])
#define printt(t,n) rep(i,n) printf("%d\n", t[i])
#define fi first
#define se second
#define pb push_back
#define eb emplace_back
#define sz(x) (int)(x).size()
#define bn(x) ((1<<x)-1)
#define dup(x,y) (((x)+(y)-1)/(y))
#define uni(x) x.erase(unique(rng(x)),x.end())
#define SP << " " <<
using namespace std;
using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vll = vector<ll>;
using pii = pair<int, int>;
using tiii = tuple<int, int, int>;
const int mod = 1000000007;
const double EPS = 1e-9;
const int INF = (1<<30)-1;
const ll INFLL = (1LL<<62)-1;
//cout << fixed << setprecision(10);

int main () {
  int n;
  cin >> n;
  string s, t;
  cin >> s >> t;
  rep(i,n) {
    cout << s[i] << t[i];
  }
  cout << endl;
  return 0;
}

Measured memory_bytes: 256
#include <set>
#include <cstring>
#include <algorithm>
#include <iostream>
#include <cstdio>
#include <cmath>
#include <queue>
#include <stack>
#include <vector>

#define  mp make_pair
#define pb push_back
#define  X first
#define  Y second

using namespace std;
typedef long long LL;
const int maxn = 100005;
char res[maxn];
int id;
void init() {
    int a,b;
    char op[10];
    scanf("%d",&a);
    scanf("%s",&op);
    scanf("%d",&b);
    if(op[0]=='+')
        cout<<a+b<<endl;
    else cout<<a-b<<endl;
}

int main() {
#ifdef LOCAL
    freopen("in.txt", "r", stdin);
#endif // LOCAL
    init();
    return 0;
}


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

int main() {
  
  string n;
  
  cin >> n;
  
  if(n.at(0)=='7' || n.at(1)=='7' || n.at(2)=='7') {
    
    cout << "Yes" << endl;
    
  } else {
    
    cout << "No" << endl;
    
  }
  
  return 0;
  
}

Measured memory_bytes: 3628
a, b = map(int, input().split())

if a <= 0 and b >= 0:
    print("Zero")
elif a <= 0 and b <= 0:
    if a == 0 or b == 0:
        print("Zero")
    else:
        if abs(b-a) % 2 == 0:
            print("Negative")
        else:
            print("Positive")
elif a >= 0 and b >= 0:
    if a == 0 or b == 0:
        print("Zero")
    else:
        print("Positive")

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

using namespace std;

int main(){
    int n;
    cin>>n;
    long long sum=0;
    for(int i=2;i<n;i++){
        sum+=i;
    }
    if(n==1){
        cout<<sum;
    }
    else{
        sum++;
        cout<<sum;
    }
}


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

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

    unsigned int ans = k;
    for (int i = 0; i < n - 1; i++) {
        ans *= (k - 1);
    }

    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 < (int)(n); i++)
using ll = long long;
using P = pair<string,int>;
const double PI = acos(-1);
 
 ll a,b,c,d;
ll f(ll x){
  return x-(x/c + x/d - x/lcm(c,d));
}
int main() {
 cin >> a >> b >> c >> d;
 cout << f(b) - f(a-1) << endl;
}

Measured memory_bytes: 3620
let S =
    stdin.ReadLine()
    |> int
let Mod = 1000000007L

let rec culcPow value pow i =
    if i=0L then value
    else
        let newPow = (pow * pow) % Mod
        let newI = i >>> 1
        if i%2L=1L then culcPow ((value*pow)%Mod) newPow newI
        else culcPow value newPow newI

let Factorial = Array.scan (fun state item -> state * item % Mod) 1L [|1L..int64(S)|]

let conv n k = Factorial.[n] * (culcPow 1L (Factorial.[k]) (Mod-2L)) % Mod * (culcPow 1L (Factorial.[n-k]) (Mod-2L)) % Mod

[|1..S/3|]
|> Array.map (fun k -> conv (S-k*2-1) (k-1))
|> Array.fold (fun state item -> (state+item)%Mod) 0L
|> stdout.WriteLine

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

int main(){

	ll n,d,a,b;

	cin >> n >> d;

	ll bound = d*d;
	ll x= 0;
	for(int i = 0; i < n; i++){
		cin >> a >> b;

		if( a*a + b * b <= bound){
			x++;
		}
	}

	cout << x << "\n";
}

Measured memory_bytes: 3632
#include<bits/stdc++.h>
using namespace std;
const int N=200005;
int x,y,n,m;
vector<int> v[N];
struct Tree{
	int l,r,num,flag;
}T[N*4];
void build(int x,int l,int r){
	T[x].l=l;T[x].r=r;
	if (l==r){
		T[x].num=l;
		return;
	}
	int mid=(l+r)/2;
	build(x*2,l,mid);
	build(x*2+1,mid+1,r);
	T[x].num=max(T[x*2].num,T[x*2+1].num);
}
void down(int x){
	T[x*2].num+=T[x].flag;
	T[x*2+1].num+=T[x].flag;
	T[x*2].flag+=T[x].flag;
	T[x*2+1].flag+=T[x].flag;
	T[x].flag=0;
}
void insert(int x,int l,int r){
	if (T[x].l>r||l>T[x].r)return;
	if (T[x].l>=l&&T[x].r<=r){
		T[x].num++;
		T[x].flag++;
		return;
	}
	down(x);
	insert(x*2,l,r);
	insert(x*2+1,l,r);
	T[x].num=max(T[x*2].num,T[x*2+1].num);
}
int find(int x,int l,int r){
	if (T[x].l>r||l>T[x].r)return -1e9;
	if (T[x].l>=l&&T[x].r<=r)return T[x].num;
	down(x);
	return max(find(x*2,l,r),find(x*2+1,l,r));
}
int main(){
	scanf("%d%d",&n,&m);
	build(1,0,m+1);
	for (int i=1;i<=n;i++)scanf("%d%d",&x,&y),v[x].push_back(y);
	int ans=0;
	for (int i=0;i<=m+1;i++){
		for (int j:v[i])insert(1,0,j);
		ans=max(ans,find(1,i+1,m+1)-i-m-1);
	}
	printf("%d\n",max(n-m,ans));
}


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

int main(void){
    int n; cin >> n;
    vector<int> vec(n+1);
    for(int i=1;i<=n;i++) cin >> vec.at(i);
    int light = 1;
    int push = 0;
    vector<int> ever(n+1);
    ever.at(1)++;
    while(1){
        light = vec.at(light); push++;
        //cout << light << endl;
        ever.at(light)++;
        if(light==2){
            cout << push << endl;
            return 0;
        }
        if(ever.at(light)==2){
            cout << "-1" << endl;
            return 0;
        }
    }

}

Measured memory_bytes: 1024
#include <iostream>

using namespace std;

int main() {
    string str;
    cin >> str;
    
    int y=0, m=0, d=0;
    int i=0;
    for(; i<4; i++) {
        y *= 10;
        y += (int)(str[i]-'0');
    }
    i++;
    for(; i<5+2; i++) {
        m *= 10;
        m += (int)(str[i]-'0');
    }
    
    if(y<2019) {
        cout << "Heisei" << endl;
    } else if(m<=4) {
        cout << "Heisei" << endl;
    } else {
        cout << "TBD" << endl;
    }


    return 0;
    
}

Measured memory_bytes: 256
IDENTIFICATION DIVISION.
PROGRAM-ID. 123B.
DATA DIVISION.
WORKING-STORAGE SECTION.
01 N     PIC 9(3).
01 N-R   REDEFINES N.
   03 N1 PIC 9(2).
   03 N2 PIC 9(1).
01 N-R2  REDEFINES N.
   03 N3 PIC 99V9.
01 W1    PIC 9(3).
01 N2W   PIC 9(2).
01 M1    PIC 9(3).
01 M2    PIC 9(3).
01 I     PIC 9(1).
01 GK    PIC 9(3).
01 OUT   PIC ZZ9.
*>
PROCEDURE DIVISION.
  MOVE 10 TO N2W.
  MOVE  0 TO GK M1 M2.
  PERFORM VARYING I FROM 1 BY 1 UNTIL I > 5
    ACCEPT N
    COMPUTE W1 = N3 + 0.9
    COMPUTE W1 = W1 * 10
    IF (N2 > 0) AND (N2 < N2W)
      COMPUTE GK = GK + M1 - M2 + N
      MOVE W1 TO M1
      MOVE N  TO M2
      MOVE N2 TO N2W
    ELSE
      ADD  W1 TO GK 
    END-IF
  END-PERFORM.  
*>
  MOVE GK TO OUT.
  DISPLAY FUNCTION TRIM(OUT).
*>
  STOP RUN.


Measured memory_bytes: 636
#include <bits/stdc++.h>
#define rep(i, a, b) for (int i = a; i < (b); i++)
#define rrep(i, a, b) for (int i = a; i >= (b); i--)
#define all(x) (x).begin(), (x).end()
using namespace std;
using ll = long long;
using P = pair<int, int>;
template <class T>
inline bool chmin(T& a, T b) {
   if (a > b) {
      a = b;
      return true;
   }
   return false;
}
template <class T>
inline bool chmax(T& a, T b) {
   if (a < b) {
      a = b;
      return true;
   }
   return false;
}
const int INF = 2e9;
const int MOD = 1e9 + 7;

int main() {
   int a, b;
   cin >> a >> b;
   int ans = 0;
   rep(i, a, b + 1) {
      string num = to_string(i);
      string num2 = num;
      reverse(num2.begin(), num2.end());
      if (num2[0] != '0' && num == num2) ans++;
   }
   cout << ans << endl;
   return 0;
}

Measured memory_bytes: 256
#include <stdio.h>




int main(void){
    int N;
    scanf("%d",&N);
    char po[310000];
    scanf(" %s",po);
    int A[N+1];
    A[0]=0;
    for(int i=1;i<=N;i++)A[i]=A[i-1]+(po[i-1]=='W'?1:0);
    int ans=1145141919;
    for(int i=1;i<=N;i++){
        int buri=A[i-1]+N-i-(A[N]-A[i]);
        if(ans>buri)ans=buri;
    }
    printf("%d",ans);
    return 0;
}


Measured memory_bytes: 1664
#include<iostream>
#include<vector>
 
using namespace std;

int main()
{
    int n, k, soc= 1, count = 0;

    cin >> n >> k;

    while(soc < k)
    {
        soc = soc - 1 + n;
        count++;
    }

    cout << count;
}

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

int main(int argc, char *argv[]) { ios::sync_with_stdio(false);cin.tie(nullptr);cout.tie(nullptr);


  
    int n;cin>>n;
    int ans=0;
    int mn=2000000;
    for(int i=0;i<n;i++){
      int t;cin>>t;
      if(t<mn){
        mn=t;
        ans++;
      }
    }
    cout<<ans<<endl;
  return 0;
}


Measured memory_bytes: 256
package main

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

func main(){
	var sc = bufio.NewScanner(os.Stdin)
	var s string
	if sc.Scan() {
		s = sc.Text()
	}
	// ここからロジック
	var (
		n int
		d int
	)
	fmt.Sscanf(s, "%d %d", &n, &d)
	r := d * 2 + 1
	tmp1, tmp2 := n / r, n % r
	if tmp2 != 0 {
		tmp1 += 1
	}
	fmt.Println(tmp1)
}

Measured memory_bytes: 640
#include <iostream>
#include <algorithm>
#include <queue>
using namespace std;
#define int long long
char map[60][60];
int map1[60][60], cnt;
queue<pair<int, int>>q;
signed main() {
	int h, w; cin >> h >> w;
	for (int i = 1; i <= h; i++) {
		for (int j = 1; j <= w; j++) {
			cin >> map[i][j];
			map1[i][j] = h * w + 100;
			if (map[i][j] == '#')cnt++;
		}
	}
	map1[1][1] = 1;
	q.push(make_pair(1, 1));
	while (q.size()) {
		int x = q.front().first, y = q.front().second;
		if (x == h && y == w) {
			cout << h * w - cnt - map1[h][w] << endl;
			return 0;
		}
		q.pop();
		if (map[x - 1][y] == '.'&&map1[x - 1][y] > map1[x][y] + 1) {
			map1[x - 1][y] = map1[x][y] + 1;
			q.push(make_pair(x - 1, y));
		}
		if (map[x][y + 1] == '.'&&map1[x][y + 1] > map1[x][y] + 1) {
			map1[x][y + 1] = map1[x][y] + 1;
			q.push(make_pair(x, y + 1));
		}
		if (map[x][y - 1] == '.'&&map1[x][y - 1] > map1[x][y] + 1) {
			map1[x][y - 1] = map1[x][y] + 1;
			q.push(make_pair(x, y - 1));
		}
		if (map[x + 1][y] == '.'&&map1[x + 1][y] > map1[x][y] + 1) {
			map1[x + 1][y] = map1[x][y] + 1;
			q.push(make_pair(x + 1, y));
		}
	}
	cout << "-1\n";
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long LL;
typedef unsigned long long ULL;
#define BIG_NUM 2000000000
#define MOD 1000000007
#define EPS 0.000000001
int hako[20];
int main(){
  int n;
  cin >> n;
  for(int i=0;i<n;i++){
    cin >> hako[i];
  }
  int res = 0;
  for(int i=0;i<n-2;i++){
    int ma = max(hako[i],max(hako[i+1],hako[i+2]));
    int mi = min(hako[i],min(hako[i+1],hako[i+2]));
    if(ma != hako[i+1] and mi != hako[i+1])res++;
  }
  cout << res << endl;
}



Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define SPEED ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define ll long long
#define mp make_pair
#define pb push_back
int main()
{
	SPEED
	int n,m,l,r;
	cin >> n >> m;
	int arr[n];
	memset(arr,0,sizeof(arr));
	for (int i = 0; i < m; ++i)
	{
		cin >> l >> r;
		l-=1;
		r-=1;
		arr[l]+=1;
		if (r==n-1)
		{
			continue;
		}
		arr[r+1]+=-1;
	}
	for (int i = 1; i < n; ++i)
	{
		arr[i]+=arr[i-1];
	}
	/*
	for (int i = 0; i < n; ++i)
	{
		cout << arr[i] << " ";
	}
	cout << '\n';*/
	int count = 0;
	for (int i = 0; i < n; ++i)
	{
		if (arr[i]==m)
		{
			count++;
		}
	}
	cout << count << '\n';
	return 0;
}

Measured memory_bytes: 640
k = gets.strip.to_i
a, b = gets.strip.split.map(&:to_i)

if a % k == 0 then
  puts 'OK'
  exit
end

if b % k == 0 then
  puts 'OK'
  exit
end

if b / k - a / k > 0 then
  puts 'OK'
  exit
end

puts 'NG'


Measured memory_bytes: 14232
N=int(input().split()[0])
W=list(map(int,input().split()))
S=0
for i in range(N):
    S=S+W[i]
min_S=S
S1=0
S2=S
for i in W:
    S1=S1+i
    S2=S2-i
    min_S=min(min_S, abs(S1-S2))
print(min_S)

Measured memory_bytes: 3064
#include<stdio.h>
int main(void){
	int n;
	int i;
	int x;
	int sum = 0;
	while(scanf("%d",&n)){
		if(n == 0){
			break;
		}
		for(i = 0;i < n / 4; i++){
			scanf("%d",&x);
			sum += x;
		}
		printf("%d\n",sum);
		sum = 0;
	}
	return 0;
}

Measured memory_bytes: 600
#!/usr/bin/env ruby

n = gets.to_i
d = gets.split.map(&:to_i).group_by(&:itself).map { |a, b| [a, b.size] }.to_h
m = gets.to_i
t = gets.split.map(&:to_i).group_by(&:itself).map { |a, b| [a, b.size] }.to_h

if t.all? { |a, b| !d[a].nil? && d[a] >= b }
  puts 'YES'
else
  puts 'NO'
end


Measured memory_bytes: 87872
N = int(input())
N753 = set()


def dfs(depth, s):
    if depth == 9:
        n = int(s)
        if '0' not in str(n) \
            and '3' in str(n) \
            and '5' in str(n) \
            and '7' in str(n):
            N753.add(n)
        return

    dfs(depth+1, s+'0')
    dfs(depth+1, s+'3')
    dfs(depth+1, s+'5')
    dfs(depth+1, s+'7')

dfs(0, '')

ans = len([n for n in N753 if n <= N])
print(ans)


Measured memory_bytes: 6348
n=int(input())
a=[0]+list(map(int,input().split()))+[0]
ans=0
for i in range(n+1):
  ans+=abs(a[i]-a[i+1])
for i in range(1,n+1):
  s=sorted(a[i-1:i+2])
  if a[i]==s[0]:
    print(ans-(s[1]-s[0])*2)
  elif a[i]==s[2]:
    print(ans-(s[2]-s[1])*2)
  else:
    print(ans)

Measured memory_bytes: 14048
#include<bits/stdc++.h>
#define il inline
#define vd void
#define mod 1000000007
typedef long long ll;
il int gi(){
	int x=0,f=1;
	char ch=getchar();
	while(!isdigit(ch)){
		if(ch=='-')f=-1;
		ch=getchar();
	}
	while(isdigit(ch))x=x*10+ch-'0',ch=getchar();
	return x*f;
}
int a[200010],b[200010];
int p[8010],inv[8010],pinv[8010];
int f[4010][4010];
il int C(int n,int m){return 1ll*p[n]*pinv[m]%mod*pinv[n-m]%mod;}
int main(){
	int n=gi();
	for(int i=1;i<=n;++i)a[i]=gi(),b[i]=gi(),++f[2005-a[i]][2005-b[i]];
	for(int i=1;i<4010;++i)
		for(int j=1;j<4010;++j)
			f[i][j]=(0ll+f[i][j]+f[i-1][j]+f[i][j-1])%mod;
	int ans=0;
	p[0]=1;for(int i=1;i<8001;++i)p[i]=1ll*p[i-1]*i%mod;
	inv[1]=1;for(int i=2;i<8001;++i)inv[i]=mod-1ll*(mod/i)*inv[mod%i]%mod;
	pinv[0]=1;for(int i=1;i<8001;++i)pinv[i]=1ll*pinv[i-1]*inv[i]%mod;
	for(int i=1;i<=n;++i)ans=(0ll+ans+f[2005+a[i]][2005+b[i]]-C(a[i]*2+b[i]*2,a[i]*2)+mod)%mod;
	printf("%d\n",1ll*ans*inv[2]%mod);
	return 0;
}


Measured memory_bytes: 64768
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
using pll=pair<ll,ll>;
#define all(v) v.begin(), v.end()
#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
#define rep2(i,l,r) for(ll i = (l); i <= (ll)(r); i++)
#define rep3(i,l,r) for(ll i = (l); i >= (ll)(r); i--)
#define dup(x,y) (((x)+(y)-1)/(y)) //a/bの除算の切り上げ
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; }
const int inf = 1001001001;
const ll INF = 1LL << 60;
const ll mod = 1000000007;
const ld pi = acos(-1);
 
// union by size + path having
class UnionFind {
public:
   vector <ll> par; // 各元の親を表す配列
   vector <ll> siz; // 素集合のサイズを表す配列(1 で初期化)
 
   // Constructor
   UnionFind(ll sz_): par(sz_),siz(sz_, 1LL){
       for (ll i=0; i<sz_; i++) par[i]=i; // 初期では親は自分自身
   }
   void init(ll sz_){
       par.resize(sz_);
       siz.assign(sz_, 1LL);  // resize だとなぜか初期化されなかった
       for (ll i=0; i<sz_; i++) par[i]=i; // 初期では親は自分自身
  }
 
   // Member Function
   // Find
   ll root(ll x){ // 根の検索
      while (par[x]!=x){
           x=par[x]=par[par[x]]; // x の親の親を x の親とする
       }
       return x;
  }
 
   // Union(Unite, Merge)
   bool unite(ll x, ll y){
       x=root(x);
       y=root(y);
       if (x==y) return false;
       // merge technique（データ構造をマージするテク．小を大にくっつける)
       if (siz[x]<siz[y]) swap(x, y);
       siz[x]+=siz[y];
       par[y]=x;
       return true;
  }
 
  bool same(ll x, ll y){ // 連結判定
       return root(x)==root(y);
  }
 
  ll size(ll x){ // 素集合のサイズ
      return siz[root(x)];
  }
};
 
ll modpow(ll x, ll n){
   x=x%mod;
   if(n==0) return 1;  //再帰の終了条件
 
   else if(n%2==1){
       return (x*modpow(x, n-1))%mod;  //nが奇数ならnを1ずらす
   }
   else return modpow((x*x)%mod, n/2)%mod;  //nが偶数ならnが半分になる
}
 
ll com(ll n, ll k){
   ll x=1;
   for(int i=n-k+1; i<=n; i++){
      x=x*i%mod;
   }
 
   ll y=1;
   for(int i=1; i<=k; i++){
       y=y*i%mod;
   }
   y=modpow(y, mod-2);
 
   return x*y%mod;
}
 
bool is_prime(const unsigned n){
   switch(n){
       case 0: // fall-through
       case 1: return false;
       case 2: // fall-through
       case 3: return true;
  } // n>3 が保証された
 
   if(n%2==0 || n%3==0) return false;
   // nは2と3のいずれの倍数でもないことが保証された
   // これよりnは(6の倍数)-1か(6の倍数)+1である
 
   // 6の倍数前後の数を使って試し割りをする
   for(unsigned i = 5; i*i<=n; i+=6) {
       if(n%i==0) return false; // (6の倍数)-1
       if(n%(i+2)==0) return false; // (6の倍数)+1
   }
 
   return true;
}
 
int digsum(int n){
   int res=0;
   while(n > 0) {
       res+=n%10; //ここをres++;に変えたら桁数を求める関数になる,res+=n%10;なら格桁の和
       n/=10;
   }
   return res;
}
vector<ll> divisor(ll n){
   vector<ll> ret;
   for(ll i=1; i*i<=n; i++){
       if(n%i==0){
           ret.push_back(i);
           if(i*i!=n) ret.push_back(n/i);
       }
   }
   sort(ret.begin(),ret.end());
   return ret;
}
 
int main(){

    char x;
    cin >> x;
    if('a'<=x && x<= 'z'){
        cout << 'a' << endl;
    }
    else{
        cout << 'A' << endl;
    }
 
}

Measured memory_bytes: 3620
#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++)
#define all(v) v.begin(),v.end()
#define rall(v) v.rbegin(), v.rend()
#define P pair<int, int>
typedef long long ll;
const ll mod = 1e9+7;

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;}

//繰り返し自乗法による累乗計算
//a**n
ll pow(ll a, ll n){
  if(n == 0) return 1;
  if(n%2 == 0){
    ll res = pow(a, n/2);
    return res * res;
  }
  return a * pow(a, n-1);
}
//繰り返し自乗法によるmod累乗計算
//a**n (mod)
ll modpow(ll a, ll n){
  if(n == 0) return 1;
  if(n%2 == 0){
    ll res = modpow(a, n/2);
    return res * res % mod;
  }
  return a * modpow(a, n-1) % mod;
}
//組み合わせ
//nCa
ll com(ll n, ll a){
  ll x = 1, y = 1;
  rep(i,a){
    x *= n-i;
    y *= i+1;
  }
  ll res = x / y;
  return res;
}
//組み合わせ(mod)
//nCa (mod)
ll modcom(ll n, ll a){
  ll x = 1, y = 1;
  rep(i, a){
    x = x * (n-i) % mod;
    y = y * (i+1) % mod;
  }
  ll ans = x * modpow(y, mod-2) % mod;
  return ans;
}
//gcd 最大公約数
ll gcd(ll x, ll y){
  if(x % y == 0) return y;
  return gcd(y, x%y);
}
//lcm 最小公倍数
ll lcm(ll x, ll y){
  return x * y / gcd(x, y);
}
//ngcd n個の最大公約数
ll ngcd(vector<ll> a){
  ll res;
  res = a[0];
  for(ll i = 1; i < a.size() && res != 1; i++) {
    res = gcd(a[i], res);
  }
  return res;
}
//nlcm n個の最小公倍数
ll nlcm(vector<ll> a) {
  ll res;
  res = a[0];
  for (ll i = 1; i < a.size(); i++) {
    res = lcm(res, a[i]);
  }
  return res;
}
// 素数判定
bool isprime(ll x){
  ll i;
  if(x < 2) return false;
  else if(x == 2) return true;
  if(x % 2 == 0) return false;
  for(i = 3; i*i <= x; i += 2){
    if(x % i == 0) return false;
  }
  return true;
}
// 桁和
ll digsum(ll x){
  ll res = 0;
  while(x > 0){
    res += x % 10;
    x /= 10;
  }
  return res;
}


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






Measured memory_bytes: 256
/**
 *    Author:  "Robin Singh" !!!!    
**/
#include <bits/stdc++.h>
using namespace std;
#define pb push_back
#define eb emplace_back
#define all(x) (x).begin(),(x).end()
#define ff first
#define ss second
#define mp make_pair
#define str string 
#define szz(v) ((int)(v).size())  
#define fr(i, j, k) for(int i = j; i < k; i++)     // 0 -> n-1 (i,0,n)
#define bk(i, j, k) for(int i = j-1; i >= k; i--)  // n-1 -> 0 (i,n,0)
#define frit(it, a) for(__typeof((a).begin()) it = a.begin(); it != a.end(); ++it)
#define mem(ptr)  memset(ptr, 0, sizeof ptr)  // use fill() for value other than 0 //
#define rtn return 
#define itt(a)   __typeof((a).begin())
#define RT  (cerr << "\nTime elapsed: " << 1000 * clock() / CLOCKS_PER_SEC << " ms\n")  // Run Time
#define nl "\n"  // New Line
#define dbg(x) (cerr << #x << " = " << x << "  ")
#define enl (cerr << "\n")
#define dbgg(x,y) (cerr << #x << " = " << x << " -> " << #y << " = " << y << "\n")
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<long long> vll;
typedef vector< pair<int,int> > vpii;
typedef vector< pair<ll, ll> > vpll;
const long long mod = 1e9+7;
const ld eps = 1e-9;
const int inf = (1<<30);
const ll INF = (1LL<<61);

ll gcd(ll a,ll b) { return b==0 ? a : gcd(b, a%b); }
ll expo(ll x, ll y){ ll res = 1; x = x % mod;  while (y > 0) { if (y & 1)res = (res*x) % mod; y = y>>1;x = (x*x) % mod;}return res;}
void matmul(ll a[][2], ll b[][2]) { ll tmp[2][2]; for(int i=0; i<2; i++) { for(int j=0; j<2; j++) { tmp[i][j] = 0; for(int k=0; k<2; k++) tmp[i][j] = (tmp[i][j] + a[i][k]*b[k][j]) % mod; }} for(int i=0; i<2; i++) for(int j=0; j<2; j++) a[i][j] = tmp[i][j]; }  // answer stored in matrix A
ll fibo(int n)    // returns nth fibonacci number, also S(n) = f(n+2)-1
{ if(n == 0) return 0; else if(n == 1) return 1; ll T[2][2] = { {0, 1} , {1, 1} }; ll res[2][2] = { {1, 0}, {0,1} }; n--; while(n) { if(n & 1) matmul(res, T); n >>= 1; matmul(T, T); } return res[1][1]; }
ll ainv, binv;
void extgcd(ll a, ll b){ if(b==0){/* hcf = a; */ ainv = 1; binv = 0; } else{ extgcd(b, a%b); ll temp = ainv; ainv = binv; binv = temp - (a/b)*binv; } }

int main()
{
    ios_base::sync_with_stdio(false); cin.tie(0);
    int n;
    cin >> n;
    int a[n], mx = 0, ans = 0;
    // m = lcm() - 1 for max of each
    fr(i, 0, n){
        cin >> a[i];
        ans += a[i]-1;
    }
    cout << ans;
    return 0;
}

Measured memory_bytes: 256
// Problem : F - Laminate
// Contest : AtCoder Beginner Contest 145
// URL : https://atcoder.jp/contests/abc145/tasks/abc145_f
// Memory Limit : 1024 MB
// Time Limit : 2000 ms
// Powered by CP Editor (https://github.com/cpeditor/cpeditor)

#include <cstring>
#include <iostream>
using namespace std;
long long f[305][305];
int h[305];
int main()
{
 int n,k;
 long long ans=1e18;
 cin>>n>>k;
 for(int i=1;i<=n;i++)
  cin>>h[i];
 memset(f,63,sizeof(f));
 if(n==k)
 {
  cout<<0<<endl;
  return 0;
 }
 for(int i=n;i;i--)
 {
  f[i][1]=h[i];
  for(int j=2;j<=n-k;j++)
   for(int p=i-1;p;p--)
    f[p][j]=min(f[p][j],f[i][j-1]+max(0,h[p]-h[i]));
 }
 for(int i=1;i<=n;i++)
  ans=min(ans,f[i][n-k]);
 cout<<ans<<endl;
 return 0;
}

Measured memory_bytes: 1024
//----------BHAVIK DIWANI(PICT_COMP)---------------
#include<bits/stdc++.h>
#include<stdlib.h>
#include<stdio.h>
#define test ll t; cin>>t; while(t--)
#define FOR(p,n) for(ll i=p;i<(ll)n;i++)
#define fastio ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define mod 1000000007
#define ll long long
#define int long long
#define ull unsigned long long
#define MAX 1000005
#define pb push_back
#define mkp make_pair
#define vi vector<int>
#define pii pair<int,int>
#define endl '\n'
#define vs vector<string>
#define mii map<int,int>
#define msi map<string,int>
#define vpii vector< pair<int, int > >
#define vpsi vector< pair< string ,int > >
#define forci(p,q) for(int i=p;i<q;i++)
ll gcd(ll a,ll b){ if(b==0) return a;    return gcd(b,a%b);}
ll lcm(ll a,ll b) { return (a/gcd(a,b)*b);}
ull power(ull a, ull b) {a %= mod;  ull res = 1;  while (b > 0) { if (b & 1) res = res * a % mod;  a = a * a % mod;  b >>= 1; }  return res%mod; }
ll modmul(ll x, ll y){return (x*y)%mod;}
ll modadd(ll x, ll y){return (x+y)%mod;}
ll modsub(ll x, ll y){return (x-y+mod)%mod;}
ll fact[1000007]={0};
void facto() {fact[0]=1;fact[1]=1;for(int i=2;i<100007;i++)fact[i]=(fact[i-1]*i)%mod;}
ll ncr(ll n,ll r) {ll res=1; res=fact[n]; res=(res*(power(fact[r],mod-2)))%mod; res=(res*(power(fact[n-r],mod-2)))%mod; return res;}
ll npr(ll n,ll r) {ll res=1; res=fact[n]; res=(res*(power(fact[n-r],mod-2)))%mod; return res;}
inline long long toint(const std::string &s) {std::stringstream ss; ss << s; long long x; ss >> x; return x;}
inline std::string tostring(long long number) {std::stringstream ss; ss << number; return ss.str();}
inline std::string tobin(long long x) {return std::bitset<63>(x).to_string();}
/*bool prime[MAX];
ull sieve(){memset(prime,true,sizeof(prime));for(ull p=2;p*p<MAX;p++){if(prime[p]==true){for(ull i=2*p;i<MAX;i+=p){prime[i]=false;}}}prime[0]=0;prime[1]=0;
}*/
/*int inv[1000001]={0};
void findinverse(){inv[1] = 1;for(int i = 2; i <=1e6 ; ++i)	inv[i] = (mod - (mod/i) * inv[mod%i] % mod) % mod;}
*/
using namespace std;
int solve()
{
	int a,b;
	cin>>a>>b;
	if(a<=2*b)
		cout<<"0"<<endl;
	else
		cout<<a-2*b<<endl;
	return 0;
}
signed main()
{
	fastio;
//	test
		solve();
}






Measured memory_bytes: 3648
/*
????????¢?????????

??????H cm ?????? W cm ???????????¢?????????????????°?????????????????????????????????
1 cm ?? 1cm ???????????¢??? '#'??§??¨????????????
*/
#include <iostream>

int main() {
	int h, w;
	while(1){
		std::cin >> h >> w;
		if (h == 0 && w == 0) break;
		for (int i = 0; i < h; i++)
		{
			for (int j = 0; j < w; j++)
			{
				std::cout << "#";
			}
			std::cout << std::endl;
		}
		std::cout << std::endl;
	}
	return 0;
}

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

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

#define p_ary(ary,a,b) do { cout << "["; for (int count = (a);count < (b);++count) cout << ary[count] << ((b)-1 == count ? "" : ", "); cout << "]\n"; } while(0)
#define p_map(map,it) do {cout << "{";for (auto (it) = map.begin();;++(it)) {if ((it) == map.end()) {cout << "}\n";break;}else cout << "" << (it)->first << "=>" << (it)->second << ", ";}}while(0)

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

const char newl = '\n';
struct UnionFind {
private:
    vector<int> par,depth;
public:
    UnionFind (int n) {
        par.resize(n);
        depth = vector<int>(n,0);
        for (int i = 0;i < n;++i) par[i] = i;
    }

    int find(int x) {
        if (par[x] == x) return x;
        else return par[x] = find(par[x]);
    }

    void unite(int x,int y) {
        x = find(x);
        y = find(y);
        if (x == y) return;
        if (depth[x] < depth[y]) par[x] = y;
        else {
            par[y] = x;
            if (depth[x] == depth[y]) depth[x]++;
        }
    }

    bool same(int x,int y) {
        return find(x) == find(y);
    }
};

int main() {
    int n,m;
    cin >> n >> m;
    UnionFind uf(n);
    for (int i = 0;i < m;++i) {
        int a,b;
        cin >> a >> b;
        uf.unite(a-1,b-1);
    }
    set<int> st;
    for (int i = 0;i < n;++i) st.insert(uf.find(i));
    cout << st.size()-1 << newl;
}

Measured memory_bytes: 7948
#include<iostream>
#include<cstdio>
#include<string>
#include<cmath>
#include<algorithm>
#include<utility>
#include<vector>

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

using namespace std;


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

    int r ;
    cin >> r;
    if(r < 1200){
        cout << "ABC\n";
    }else if(r<2800){
        cout << "ARC\n";
    }else{
        cout << "AGC\n";
    }
    
    return 0;
}


Measured memory_bytes: 256
#include "bits/stdc++.h"
#define FOR(i, a, b) for (int i = a; i < b; i++)
#define mFOR(i, a, b) for (int i = a; i > b; i--)
#define MP make_pair
#define PB push_back
#define ALL(v) v.begin(), v.end()
#define N 100007
#define INF 1000000007
using namespace std;

typedef long long ll;

ll gcd(ll a, ll b) { return b == 0 ? a : gcd(b, a % b); }
ll fceil(ll a, ll b) { return (a % b == 0 ? a / b : a / b + 1); }
int main()
{
   int n, a;
   string ans = "APPROVED";
   cin >> n;
   FOR(i, 0, n)
   {
      cin >> a;
      if (a % 2 == 0 && a % 3 != 0 && a % 5 != 0)
      {
         ans = "DENIED";
         break;
      }
   }

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


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <functional>
#include <numeric>
#include <stack>
#include <queue>
#include <map>
#include <set>
#include <utility>
#include <sstream>
#include <complex>
#include <fstream>
#include <bitset>
#include <time.h>
#include <tuple>

using namespace std;

typedef long long ll;
typedef pair<ll, ll> P;
typedef vector<ll> V;
typedef complex<double> Point;

#define PI acos(-1.0)
#define EPS 1e-10
const ll INF = 1e12;
const ll MOD = 1e9 + 7;

#define FOR(i,a,b) for(ll i=(a);i<(b);i++)
#define rep(i,N) for(ll i=0;i<(N);i++)
#define ALL(s) (s).begin(),(s).end()
#define EQ(a,b) (abs((a)-(b))<EPS)
#define EQV(a,b) ( EQ((a).real(), (b).real()) && EQ((a).imag(), (b).imag()) )
#define fi first
#define se second
#define N_SIZE (1LL << 20)
#define NIL -1
#define MAX_N 100100

ll sq(ll num) { return num*num; }
ll mod_pow(ll x, ll n) {
	if (n == 0)return 1;
	if (n == 1)return x%MOD;
	ll res = sq(mod_pow(x, n / 2));
	res %= MOD;
	if (n % 2 == 1) {
		res *= x;
		res %= MOD;
	}
	return res;
}
ll mod_add(ll a, ll b) { return (a + b) % MOD; }
ll mod_sub(ll a, ll b) { return (a - b + MOD) % MOD; }
ll mod_mul(ll a, ll b) { return a*b % MOD; }

int n, k;
int x;
int ans = 0;

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

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
#define REP(i, n) for (int i = 0; i < (n); ++i)
#define REPR(i, n) for (int i = n - 1; i >= 0; --i)
#define FOR(i, m, n) for (int i = m; i < n; ++i)
#define FORR(i, m, n) for (int i = m; i >= n; --i)
#define ALL(v) (v).begin(),(v).end()
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; }
const ll INF=1LL<<60;
const int inf=(1<<30)-1;
const int mod=1e9+7;
int dx[8]={1,0,-1,0,-1,-1,1,1};
int dy[8]={0,1,0,-1,-1,1,-1,1};
int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll n,x,m;cin >> n >> x >> m;
    vector<vector<int>> d(41,vector<int>(m));
    vector<vector<ll>> s(41,vector<ll>(m));
    for(ll i=0;i<m;i++){
        d[0][i]=i*i%m;
        s[0][i]=i*i%m;
    }
    REP(i,40){
        REP(j,m){
            d[i+1][j]=d[i][d[i][j]];
            s[i+1][j]=s[i][j]+s[i][d[i][j]];
        }
    }
    n--;
    ll ans=x;
    int cnt=0;
    while(n){
        if(n&1){
            ans+=s[cnt][x];
            x=d[cnt][x];
        }
        cnt++;
        n>>=1;
    }
    cout << ans << endl;
}

Measured memory_bytes: 52164
import java.util.Scanner;

class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		String s = sc.next();
		String t = sc.next();
		
		int cnt = 0;
		for (int i = 0; i < s.length(); i++)
			if (s.charAt(i) == t.charAt(i))
				cnt++;
		
		System.out.println(cnt);
		
		sc.close();
	}
}


Measured memory_bytes: 22740
def read_input():
    a, b, c = map(int, input().split())
    return a, b, c


def submit():
    a, b, c = read_input()

    d = {}
    d[a] = 1
    d[b] = 1
    d[c] = 1

    print(len(d))

if __name__ == '__main__':
    submit()
    

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

int main() {
    int res=0;
    int N, M;
    cin >> N;
    vector <int> T(N);
    for (int i=0; i<N; i++) {
        cin >> T.at(i);
        res+=T.at(i);
    }
    cin >> M;
    vector <int> P(M);
    vector <int> X(M);
    for (int i=0; i<M; i++) {
        cin >> P.at(i) >> X.at(i);
    }

    for (int i=0; i<M; i++) {
        cout << res-T.at(P.at(i)-1)+X.at(i) << "\n";
    }
}

Measured memory_bytes: 256
#include <cstdio>
#include <algorithm>

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

using namespace std;

typedef long long ll;

int h, w;
ll l;
char c[100][101];
int d[100][100][4];

int main(){
	while(scanf("%d%d%lld", &h, &w, &l), w){
		rep(i, h){
			scanf("%s", c[i]);
		}

		int p, q, r;
		rep(i, h){
			rep(j, w){
				if(c[i][j] == 'N'){
					r = 0;
				}
				else if(c[i][j] == 'E'){
					r = 1;
				}
				else if(c[i][j] == 'S'){
					r = 2;
				}
				else if(c[i][j] == 'W'){
					r = 3;
				}
				else{
					continue;
				}
				p = i;
				q = j;
				break;
			}
		}

		rep(i, h){
			rep(j, w){
				fill_n(d[i][j], 4, -1);
			}
		}
		d[p][q][r] = 0;

		int dx[4] = {-1, 0, 1, 0};
		int dy[4] = {0, 1, 0, -1};
		while(true){
			int v = d[p][q][r];
			int x = p + dx[r];
			int y = q + dy[r];
			if(0 <= x && x < h && 0 <= y && y < w && c[x][y] != '#'){
				p = x;
				q = y;
				++v;
			}
			else{
				r = (r + 1) % 4;
			}

			if(v == l){
				char k[5] = "NESW";
				printf("%d %d %c\n", p + 1, q + 1, k[r]);
				break;
			}

			int a = d[p][q][r];
			if(a != -1){
				l -= a;
				l %= (v - a);

				if(!l){
					d[p][q][r] = v;

					int i = (r + 1) % 4;
					while(true){
						if(d[p][q][i] == v){
							r = i;
							break;
						}
						i = (i + 1) % 4;
					}

					char k[5] = "NESW";
					printf("%d %d %c\n", p + 1, q + 1, k[r]);
					break;
				}

				rep(i, h){
					rep(j, w){
						fill_n(d[i][j], 4, -1);
					}
				}
				v = 0;
			}

			d[p][q][r] = v;		
		}
	}
	return 0;
}

Measured memory_bytes: 1196
#include <iostream>
#include <fstream>
#include <cstdio>
#include <cmath>
#include <vector>
#include <cstring>
#include <string>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <algorithm>
using namespace std;
 
#define REP(i,n) for(int i=0; i<n; ++i)
#define FOR(i,a,b) for(int i=a; i<=b; ++i)
#define FORR(i,a,b) for (int i=a; i>=b; --i)
#define ALL(c) (c).begin(), (c).end()
 
typedef long long ll;
typedef vector<int> VI;
typedef vector<ll> VL;
typedef vector<VI> VVI;
typedef vector<VL> VVL;
typedef pair<int,int> P;
typedef pair<ll,ll> PL;
 
const ll mod = 1e9 + 7;
ll dp[311][311][311];
 
int main(void){
    int n, m;
    cin >> n >> m;
    dp[0][1][0] = 1;
    REP(i,m) REP(j,n+1) REP(k,n+1){
        if (j + k > n) continue;
        dp[i+1][j][k] = (dp[i+1][j][k] + k * dp[i][j][k]) % mod;
        dp[i+1][j+k][0] = (dp[i+1][j+k][0] + j * dp[i][j][k]) % mod;
        dp[i+1][j][k+1] = (dp[i+1][j][k+1] + (n - k - j) * dp[i][j][k]) % mod;
    }
 
    // FOR(i,1,m){
    //     cout << i << endl;
    //     REP(j,n+1){
    //         REP(k,n+1) cout << dp[i][j][k] << " ";
    //         cout << endl;
    //     }
    //     cout << endl;
    // }
    cout << dp[m][n][0] << endl;
 
    return 0;
}

Measured memory_bytes: 228864
import java.util.*;


public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        Set<String> set = new HashSet<>();
        for (int i = 0; i < N; i++) {
            set.add(sc.next());
        }
        System.out.println(set.size());
    }
}


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

int a[100];
int main(){
	int n;
	scanf("%d", &n);
	for(int i = 0;i < n;i++)scanf("%d", &a[i]);
	sort(a, a+n);
	printf("%d\n", a[n-1]-a[0]);
	return 0;
}

Measured memory_bytes: 256
#include <cstdio>
#include <vector>

int main() {
  int n;
  scanf("%d", &n);
  std::vector<double> dp(n + 1);
  dp[0] = 1;
  for (int i = 0; i < n; ++i) {
    std::vector<double> g(n + 1);
    double p;
    scanf("%lf", &p);
    for (int j = 0; j <= i; ++j) {
      g[j] += dp[j] * (1 - p);
      g[j + 1] += dp[j] * p;
    }
    dp.swap(g);
  }
  double ret = 0;
  for (int i = n / 2 + 1; i <= n; ++i) ret += dp[i];
  printf("%.10f\n", ret);
  return 0;
}


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

int main() {
    int N;
    cin >> N;
    long long sum = 0;
    for (int i = 1; i <= N; i++) {
        if (i % 3 != 0 && i % 5 != 0) {
            sum += i;
        }
    }
    cout << sum << endl;
}

Measured memory_bytes: 3624
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < n; i++)
#define repp(i, n, m) for (int i = (int)(n); i < (int)(m); i++)
#define rrep(i, n, m) for (int i = n; i >= m; i--)
#define ALL(a) (a).begin(), (a).end()
#define p(a, b) printf(a, b);
#define c(s) cout << (s) << endl;
#define yes cout << "Yes" << endl;
#define no cout << "No" << endl;
#define YES cout << "YES" << endl;
#define NO cout << "NO" << endl;
#define cyn(c) cout << (c ? "Yes" : "No") << endl;
#define cYN(c) cout << (c ? "YES" : "NO") << endl;
#define pyn(c) printf("%s\n", c ? "Yes" : "No");
#define pYN(c) printf("%s\n", c ? "YES" : "NO");
#define INF 1e18
typedef long long LL;
typedef unsigned long long ULL;
typedef pair<LL, LL> P;
template <class T>
bool contain(const std::string &s, const T &v)
{
  return s.find(v) != std::string::npos;
}
ULL mod = 1e9 + 7;

int main(){
    int n,flag=0; cin>>n;
    int h[25]={},ans=0; rep(i,n)cin>>h[i];
    for(int i=0; i<n; i++){
      int now = h[i];
      // cout << "now: " << now << endl;
      for(int j=0; j<=i; j++){
        // cout<<"h[j]: "<<h[j]<<endl;
        if(now < h[j]){
          flag=1;
        }
      }
      if(flag){
        flag=0;
        continue;
      }else{
        ans++;
      }
    }
    cout<<ans<<endl;
}


Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<iomanip>
#include<cmath>
#include<vector>
#include<algorithm>

using namespace std;

#define int long long
#define endl "\n"

const long long INF = (long long)1e18;
const long long MOD = 1'000'000'007; 

string yn(bool f){return f?"Yes":"No";}
string YN(bool f){return f?"YES":"NO";}



signed main(){
	cin.tie(nullptr);
	ios::sync_with_stdio(false);
	cout<<fixed<<setprecision(10);
	
	int N;
	vector<int> H;
	bool flag = true;
	cin>>N;
	
	H.resize(N);
	
	for(int i = 0; i < N; i++){
		cin>>H[i];
	}
	
	for(int i = N-2; i >= 0; i--){
		if(H[i+1]+1 < H[i]){
			cout<<"No"<<endl;
			return 0;
		} else if(H[i+1] < H[i]){
			H[i]--;
		}
		// cout<<H[i]<<endl;
	}
	cout<<"Yes"<<endl;
	
	
	return 0;
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
#define ALL(a)  (a).begin(),(a).end()
using namespace std;
int main(){
  long long n,i,sum;
  cin >> n;
  vector<long long> A(n),S(n);
  for(a:A)cin>>a;
  S.at(0)=A.at(0);
  for(i=1;i<n;i++)S.at(i)=S.at(i-1)+A.at(i);
  sum=S.at(n-1);

//  for(s:S)cerr<<s<<' ';
//  cerr<<endl<<sum<<endl;
  
  for(s:S)s*=2;
  
//  for(s:S)cerr<<s<<' ';
//  cerr<<endl;

  if(binary_search(ALL(S),sum)){
  	cout<<0<<endl;
    return 0;
  }

  
  auto lb = lower_bound(ALL(S),sum)-1;
  auto ub = upper_bound(ALL(S),sum);
  cerr << *lb << ' ' << sum*2-*lb << endl << sum*2-*ub << ' ' << *ub;
  cout << min(sum-*lb,*ub-sum) << endl;
  return 0;
}

Measured memory_bytes: 3328
#include <stdio.h>
#include <string.h>

int main(){
    char s[101];
    scanf("%s",s);

    int res = 0;
    int n = strlen(s);
    for(int i = 0; i < n; i++){
        if(s[i] != s[n - 1 - i]) res++;
    }
    printf("%d",res / 2);

    return 0;
}

Measured memory_bytes: 128
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <cmath>
#include <vector>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <queue>
#include <ctime>
#include <cassert>
#include <complex>
#include <string>
#include <cstring>
#include <chrono>
#include <random>
#include <queue>
#include <bitset>
#include <stack>
#include <iomanip>
using namespace std;
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
typedef vector <int> vi;
typedef pair<int,int> ii;
typedef long long ll;
typedef long double ld;
const int mod = 1e9 + 7;
const ll inf = 3e18 + 5;
int add(int a, int b) { return (a += b) < mod ? a : a - mod; }
int mul(int a, int b) { return 1LL * a * b % mod; }

const int maxn = 2e5 + 5;
int cnt[maxn][27];

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

  string s;
  cin >> s;
  int n = int(s.size());
  for(int i = n - 1; i >= 0; i--){
    cnt[i][s[i] - 'a']++;
    if(i != n - 1){
      for(int j = 0; j < 26; j++){
        cnt[i][j] += cnt[i + 1][j];
      }
    }
  }
  ll res = 1;
  for(int i = 0; i < n; i++){
    for(int j = 0; j < 26; j++){
      if(s[i] - 'a' == j) continue;
      res += cnt[i][j];
    }
  }
  cout << res;
}

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

using namespace std;

const int maxn = 100001;

vector<int> G[maxn], tsort;

bool vis[maxn];
int dp[maxn];

void dfs(int u){
    vis[u] = 1;
    for(int v:G[u])
        if(!vis[v]) dfs(v);
    tsort.push_back(u);
}

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

    int V, E;
    cin >> V >> E;
    while(E--){
        int u, v;
        cin >> u >> v;
        G[u].push_back(v);
    }

    for(int i = 1; i <= V; i++)
    if(!vis[i]) dfs(i);

    int ans = 0;
    for(int u:tsort){
        for(int v:G[u])
            dp[u] = max(dp[v] + 1, dp[u]);
        ans = max(ans, dp[u]);
    }

    cout << ans;


    return 0;
}


Measured memory_bytes: 8824
#include <iostream>
#include <cstdio>
 
int main(){
    for(int i=0; i<4; ++i){
        int t, n;
        long p;
        scanf(" %d %d", &t, &n);
         
        switch(t){
            case 1:
                p=n*6000;
                break;
            case 2:
                p=n*4000;
                break;
            case 3:
                p=n*3000;
                break;
            case 4:
                p=n*2000;
                break;
            default:
                break;
        }
     
        printf("%ld\n", p);
    }   
     
    return 0;
}


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

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;
}

using namespace std;

int main() {
  string s;
  cin >> s;
  rep(i, s.length()) cout << 'x';
  cout << endl;

  return 0;
}

Measured memory_bytes: 256
#include<iostream>
using namespace std;
int n,a,p,c,ans;
main()
{
	cin>>n;
	for(int i=0;i<n;i++)
	{
		cin>>a;
		if(a==p)c++;
		else ans+=c/2,c=1;
		p=a;
	}
	ans+=c/2;
	cout<<ans<<endl;
}


Measured memory_bytes: 256
n,k = map(int, input().split())
a = list(map(int, input().split()))
for i in range(n):
    a[i] -= 1
INF = 1001001001
dist = [INF]*n
dist[0]=0
now=0
flag = True
while 1:
    to = a[now]
    if dist[to]!=INF and flag:
        loop = dist[now] + 1 - dist[to]
        k-=1
        k %= loop
        flag = False
    else:
        dist[to]=dist[now]+1
        k-=1
    now = to
    if k == 0:
        print(to+1)
        break

Measured memory_bytes: 92320
#include<bits/stdc++.h>
using namespace std;
typedef unsigned long long int ull;
typedef long long int ll;
typedef pair<ll,ll> pll;
typedef pair<int,int> pii;
typedef long double D;
//typedef complex<D> P;
#define F first
#define S second
//const ll MOD=1000000007;
const ll MOD=998244353;

template<typename T,typename U>istream & operator >> (istream &i,pair<T,U> &A){i>>A.F>>A.S; return i;}
template<typename T>istream & operator >> (istream &i,vector<T> &A){for(auto &I:A){i>>I;} return i;}
template<typename T,typename U>ostream & operator << (ostream &o,const pair<T,U> &A){o<<A.F<<" "<<A.S; return o;}
template<typename T>ostream & operator << (ostream &o,const vector<T> &A){int i=A.size(); for(auto &I:A){o<<I<<(--i?" ":"");} return o;}



int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  ll N;
  cin>>N;
  vector<ll> A(N);
  cin>>A;
  sort(A.begin(),A.end());
  ll mi=A[0],sum=0;
  for(auto &I:A){sum+=I-mi;}
  if(N&1){
    cout<<((mi+sum)&1?"First":"Second")<<endl;
  }
  else if(mi&1){
    cout<<"First"<<endl;
  }
  else{cout<<(sum&1?"First":"Second")<<endl;}

  return 0;
}



Measured memory_bytes: 4360
#include<cstdio>
#include<cstring>
#include<vector>
#include<queue>
#include<algorithm>
#include<cmath>
#include<climits>
#include<string>
#include<numeric>
#include<set>
#include<map>
#include<iostream>
using namespace std;
#define rep(i,n) for(int i = 0;i<((int)(n));i++)
#define reg(i,a,b) for(lli i = ((int)(a));i<=((int)(b));i++)
#define irep(i,n) for(int i = ((int)(n)-1);i>=0;i--)
#define ireg(i,a,b) for(int i = ((int)(b));i>=((int)(a));i--)
typedef long long int lli;
typedef pair<int, int> mp;
#define fir first
#define sec second
#define IINF INT_MAX
#define LINF LLONG_MAX
#define eprintf(...) fprintf(stderr,__VA_ARGS__)
#define pque(type) priority_queue<type,vector<type>,greater<type> >
#define memst(a,b) memset(a,b,sizeof(a))

vector<vector<int>> v;

int dfs(int m){
	vector<int> t;
	rep(i, v[m].size()) t.push_back(dfs(v[m][i]));
	sort(t.rbegin(), t.rend());
	rep(i, t.size()) t[i] += i + 1;
	if(t.size() != 0) return *(max_element(t.begin(), t.end()));
	else return 0;
}
 
int main(void){
	int n; cin >> n;
	v.resize(n);
	reg(i, 1, n-1){
		int	t; cin >> t; t--;
		v[t].push_back(i);
	}
	
	cout << dfs(0) << endl;
	
	return 0;
}

Measured memory_bytes: 15104
#coding:utf-8

n, k = map(int, input().split(' '))
r, s, p = map(int, input().split(' '))
t = input()

str_arr = []
for i in range(k):
    j = i
    chars = ''
    while j < n:
        chars += t[j]
        j += k
    str_arr.append(chars)

total = 0
for chars in str_arr:
    pre_char = ''
    for char in chars:
        if pre_char == char:
            pre_char = ''
            continue
        else:
            if char == 'r':
                total += p
            elif char == 'p':
                total += s
            else:
                total += r
        pre_char = char
print(total)

Measured memory_bytes: 6260