akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
#define rep(i,a,n) for(int i = a;i < n;i++)
#define INF 1e9
#define fs first
#define sc second
typedef unsigned long long ull;
typedef long long ll;


int main(){
	ll n,p,temp,memo = 0,cnt = 1;
	cin >> n >> p;
	vector<ll> vec,vec2;
	
	if(n == 1 ){
		cout << p << endl;
		return 0;
	}
	
	temp = p;
	
	rep(i,1,sqrt(p)+1){
		if(temp % i == 0){
			vec.push_back(i);
			if(i != temp / i) vec.push_back(temp/i);
		}
	}
	sort(vec.begin(),vec.end());
	
	
	
	rep(i,1,vec.size()){
		while(temp % vec[i] == 0){
			vec2.push_back(vec[i]);
			temp /= vec[i];
		}
	}
	
	sort(vec2.begin(),vec2.end());
	
	rep(i,1,vec2.size()){
		memo++;
		if(vec2[i] != vec2[i-1]){
			
			rep(j,0,memo / n){
				cnt *= vec2[i-1];
			}
			memo = 0;
		}
	}
	
	memo++;
	if(memo >= n)cnt *= vec2[vec2.size()-1];
	
	cout << cnt << endl;
	
	
	return 0;
}


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

using namespace std;

int main() {
	int N, M;
	cin >> N >> M;
	vector<int> H(N);
	for (int i = 0; i < N; ++i) { cin >> H[i]; }
	vector<vector<int>> g(N);
	for (int i = 0; i < M; ++i) {
		int a, b;
		cin >> a >> b;
		--a; --b;
		g[a].emplace_back(b);
		g[b].emplace_back(a);
	}

	int ans = 0;
	for (int i = 0; i < N; ++i) {
		bool ok = true;
		for (auto v : g[i]) {
			if (H[v] >= H[i]) { ok = false; }
		}
		ans += ok;
	}
	cout << ans << endl;

	return 0;
}


Measured memory_bytes: 8804
A = int(input())
B = int(input())
C = int(input())
X = int(input())

ans = 0
for a in range(A+1):
  for b in range(B+1):
    for c in range(C+1):
      Y = 500*a + 100*b + 50*c
      if X == Y:
        ans += 1
print(ans)


Measured memory_bytes: 3060
#include <bits/stdc++.h>
#include <stdio.h>
#include <ios>     
#include <iomanip> 

using namespace std;
#define inputInt(a) int a; cin >> a; 
#define inputInt2(a,b) int a; int b; cin >> a >> b; 
#define inputInt3(a,b,c) int a; int b; int c; cin >> a >> b >> c;
#define inputLong(a) long a;cin >> a; 
#define inputIntArray(a,N) int a[N];for(int i=0;i<N;i++){cin >> a[i];}
#define inputLongArray(a,N) long a[N];for(int i=0;i<N;i++){cin >> a[i];}
#define inputIntArray2(a,b,N) int a[N]; int b[N]; for(int i=0;i<N;i++){cin >> a[i] >> b[i];}
#define output(answer) cout << answer << endl;
#define fN(i,N)    for(int i=0; i<N; i++)
#define fSE(i,s,e) for(int i=s; i<=e; i++)
#define ll long long
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }

//互除法
ll GCD(ll a, ll b){
  return b ? GCD(b,a%b) : a;
}

ll LCM(ll a, ll b){
  return (a / GCD(a,b))*b;
}

int main()
{
  //input
  inputInt(N);
  vector<ll> T(N);
  for(int i=0; i<N; i++){ cin >> T[i]; }
  
  //main
  ll l = 1;
  for(int i=0; i<N; i++){
     l = LCM(l, T[i]);
  }
  
  // output
  cout << l << endl;
  
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ALL(obj) begin(obj), end(obj)
#define debug(x) cerr << #x << ": " << x << '\n'
using namespace std;
template <class T>
vector<T> make_vec(size_t a) {
    return vector<T>(a);
}
template <class T, class... Ts>
auto make_vec(size_t a, Ts... ts) {
    return vector<decltype(make_vec<T>(ts...))>(a, make_vec<T>(ts...));
}
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;
}

using ll = long long;
using ull = unsigned long long;
const int INF = 2100100100;
// const int MOD = 1e9 + 7;

int main() {
    int N;
    cin >> N;
    vector<int> d(N);
    for (int i = 0; i < N; i++) {
        cin >> d.at(i);
    }
    sort(ALL(d));

    cout << d[N / 2] - d[N / 2 - 1] << endl;
}


Measured memory_bytes: 640
#include<stdio.h>
#define MAX 100

int V[MAX][MAX];

int main(){
  int n,i,j,u,k,l;
  scanf("%d",&n);

  for(i=0;i<n;i++)
    for(j=0;j<n;j++) V[i][j]=0;

  for(i=0;i<n;i++){
    scanf("%d",&u);
    scanf("%d",&k);
    for(j=0;j<k;j++){
      scanf("%d",&l);
      V[u-1][l-1]=1;
    }
  }
  for(i=0;i<n;i++){
    for(j=0;j<n;j++){
      if(j>0) printf(" ");
      printf("%d",V[i][j]);
    }
    printf("\n");
  }
  return 0;
}



Measured memory_bytes: 2072
#include <iostream>
int main(){
    int n,m,l;
    long int t;
    std::cin >> n >> m >>l;
    long int A [n][m]={0},B [m][l]={0};
    long int C [n][l]={0};
    for(int a = 0;a < n;a++){
        for(int b = 0;b < m;b++){
            std::cin >> A[a][b];
        }
    }
    for(int c = 0;c < m;c++){
        for(int d = 0;d < l;d++){
            std::cin >>B[c][d];
        }
    }
    for(int e = 0;e < l;e++){
        for(int g = 0;g < n;g++){
            t = 0;
            for(int f = 0;f < m;f++){
                t = A[g][f] * B[f][e] + t;
            }
            C[g][e] = t;
        }
    }
    for(int h = 0;h<n;h++){
        for(int i = 0;i < l;i++){
            if(i <l-1){
                std::cout << C[h][i]<<" ";
            }
            if(i == l-1){
                std::cout << C[h][i];
            }
        }
        std::cout <<std::endl;
    }
}

Measured memory_bytes: 3248
n = int(input())
s = [input() for _ in range(2)]

if s[0][0] == s[1][0]:
    c = 3
    last = 'x'
    p = 1
else:
    c = 6
    last = 'y'
    p = 2

while p < n:
    if s[0][p] == s[1][p]:
        if last == 'x':
            c *= 2
        else:
            c *= 1
        last = 'x'
        p += 1
    else:
        if last == 'x':
            c *= 2
        else:
            c *= 3
        last = 'y'
        p += 2
    c %= 10 ** 9 + 7

print(c)

Measured memory_bytes: 3064
package main

import (
	"bufio"
	"fmt"
	"math"
	"os"
	"strconv"
)

var sc = bufio.NewScanner(os.Stdin)

func nextInt() int {
	sc.Scan()
	i, e := strconv.Atoi(sc.Text())
	if e != nil {
		panic(e)
	}
	return i
}

func main() {
	var s []int
	var c []int

	sc.Split(bufio.ScanWords)
	n := nextInt()
	m := nextInt()

	for i := 0; i < m; i++ {
		s = append(s, nextInt())
		c = append(c, nextInt())
	}

	// fmt.Printf("%v %v\n", n, m)
	// for i := 0; i < m; i++ {
	// 	fmt.Printf("%v %v\n", s[i], c[i])
	// }

	for i := 0; i < int(math.Pow10(n)); i++ {
		si := strconv.Itoa(i)
		if len(si) != n {
			continue
		}
		j := 0
		for ; j < m; j++ {
			if si[s[j]-1] != '0'+byte(c[j]) {
				break
			}
		}
		if j == m {
			fmt.Printf("%s\n", si)
			return
		}
	}
	fmt.Println("-1")
}


Measured memory_bytes: 1776
#include <iostream>

using namespace std;

int coins[] = {500, 100, 50, 10, 5, 1};

int main()
{
	int n;
	while (cin >> n && n)
	{
		int remaind = 1000 - n;
		int ans = 0;
		for (int i = 0; i < 6; i++)
		{
			ans += remaind / coins[i];
			remaind %= coins[i];
		}
		cout << ans << endl;
	}
	return 0;
}

Measured memory_bytes: 1160
from operator import itemgetter
N = int(input())
AB = [list(map(int, input().split())) for _ in range(N)]
A, B = zip(*AB)
ABC = [[A[i], B[i], A[i]+B[i]] for i in range(N)]
ABC.sort(key=itemgetter(2, 0, 1), reverse=True)
ans = 0
for i in range(N):
    if i % 2 == 0:
        ans += ABC[i][0]
    else:
        ans -= ABC[i][1]
print(ans)


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

using namespace std;

int main() {
    char a[1000]={};
    int i, j, n=0, f=0, t=0;
    scanf("%s", a);
    while(a[n]!='\0')
        n++;
    for(i=0;i<n;i++)
        f+=(a[i]==a[n-1-i]);
    for(i=0;i<(n-1)/2;i++)
        t+=(a[i]==a[((n-3)/2)-i]);

    if((f==n)&&(t==((n-1)/2)))
        printf("Yes");
    else
        printf("No");


    return 0;
}

Measured memory_bytes: 256
/* ---------- STL Libraries ---------- */
// IO library
#include <cstdio>

#include <fstream>
#include <iomanip>
#include <ios>
#include <iostream>

// algorithm library
#include <algorithm>

#include <cmath>
#include <numeric>
#include <random>
#include <cstring>
#include <cassert>

// container library
#include <array>
#include <bitset>
#include <deque>
#include <map>
#include <unordered_map>
#include <queue>
#include <set>
#include <string>
#include <tuple>
#include <vector>
#include <stack>

// type
#include <cstdint>

/* ---------- Namespace ---------- */
using namespace std;

/* ---------- Type ---------- */
using ll = long long;
#define int ll
template <class T> using MaxHeap = priority_queue<T>;
template <class T> using MinHeap = priority_queue<T, vector<T>, greater<T>>;
#define P pair<ll, ll>

/* ---------- Constants  */
const double PI = 3.141592653589793238462643383279;
const ll MOD = 1e9 + 7;
const int INF = 1LL << 55;

/* ---------- Functions */
template<class T> bool chmax(T &a, const T &b) { if (a < b) { a = b; return true; } return false; }
template<class T> bool chmin(T &a, const T &b) { if (a > b) { a = b; return true; } return false; }

/* v-v-v-v-v-v-v-v-v Main Part v-v-v-v-v-v-v-v-v */
signed main() {
    cin.sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);

    int H, W;
    cin >> H >> W;
    vector<vector<bool>> table(H, vector<bool>(W));
    vector<vector<char>> tb(H, vector<char>(W));
    for (int i = 0; i < H; i++) {
        string str;
        cin >> str;
        for (int j = 0; j < W; j++) {
            tb[i][j] = str[j];
            table[i][j] = str[j] == '#';
        }
    }

    vector<vector<int>> dp(H, vector<int>(W, INF));
    dp[0][0] = 0;
    for (int i = 0; i < H; i++) {
        for (int j = 0; j < W; j++) {
            if (j < W-1) {
                if (table[i][j] != table[i][j + 1]) {
                    dp[i][j + 1] = min(dp[i][j] + 1, dp[i][j + 1]);
                } else {
                    dp[i][j + 1] = min(dp[i][j + 1], dp[i][j]);
                }
            }

            if (i < H-1) {
                if (table[i][j] != table[i + 1][j]) {
                    dp[i + 1][j] = min(dp[i][j] + 1, dp[i + 1][j]);
                } else {
                    chmin(dp[i + 1][j], dp[i][j]);
                }
            }
        }
    }

    int ret = (int)ceil(dp[H-1][W-1] / 2.0);
    if (tb[0][0] == '#' && tb[H-1][W-1] == '#') ret++;
    cout << ret << endl;

    return 0;
}

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

const int maxn=3010;

int n;
int a[maxn];

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

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

using namespace std;
typedef long long ll;
typedef pair<int, int> P;
#define rep(i, n) for(ll i = 0; i < (ll)(n); i++)
#define repr(i, n) for(ll i = n - 1; i >= 0; i--)
#define repone(i, n) for(ll i = 1; i <= (ll)(n); i++)
#define each(i, mp) for(auto i:mp)
#define FOR(i, m, n) for(ll i = m;i < n;i++)
const int dx[4] = {1, 0, -1, 0}, dy[4] = {0, 1, 0, -1};
const ll mod = 1000000007;
const ll inf = ll(1e9);
const ll half_inf = ll(1e5);
const ll ll_inf = ll(1e9) * ll(1e9);

ll n;
vector<ll> h;

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

void solve() {
    ll dp[n];
    rep(i, n) dp[i] = inf;
    dp[0] = 0;
    dp[1] = abs(h[1] - h[0]);
    for (int i = 2; i < n; ++i) {
        chmin(dp[i], dp[i - 1] + abs(h[i] - h[i - 1]));
        chmin(dp[i], dp[i - 2] + abs(h[i] - h[i - 2]));
    }
    cout << dp[n - 1] << endl;
}

int main() {
    cin >> n;
    h.resize(n);
    rep(i, n) cin >> h[i];
    solve();
    return 0;
}

Measured memory_bytes: 1792
#include <iostream>
#include <cstdio>
#include <string>
#include <algorithm>
#include <utility>
#include <cmath>
#include <vector>
#include <stack>
#include <queue>
#define rep(i, n) for(int i = 0; i < n; i++)
using namespace std;
typedef long long ll;
ll mod = 1000000007;

int main() {
    ll n, a, b, c, d;
    cin >> n >> a >> b >> c >> d;

    if(c == d) {
        rep(j, n) {
            ll k = a + (n-1-2*j)*c;
            if(b == k) {
                cout << "YES" << endl;
                return 0;
            }
        }

        cout << "NO" << endl;
        return 0;
    }

    /*m = (d + c)/(d - c);

    if(m <= n-1) {
        cout << "YES" << endl;
        return 0;
    }*/

    rep(j, n) {
        ll u = a + (n-1-j)*c - j*d;
        ll v = a - j*c + (n-1-j)*d;
        if(u <= b && b <= v) {
            cout << "YES" << endl;
            return 0;
        }
    }

    cout << "NO" << endl;

    return 0;
}

Measured memory_bytes: 256
import math

a,b,deg_c = map(float,input().split())

h = b*math.sin(math.radians(deg_c))
S = (a*h)/2
c = math.sqrt((a**2 + b**2 +(-2*a*b*math.cos(math.radians(deg_c)))))
L = a+b+c

print("{}\n{}\n{}".format(S,L,h))


Measured memory_bytes: 5696
#include <iostream>
#include <sstream>
#include <algorithm>
#include <string>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <stack>
#include <memory>
#include <complex>
#include <numeric>
#include <cstdio>
#include <iomanip>
#include <random>

#define REP(i,m,n) for(int i=int(m);i<int(n);i++)
#define RREP(i,m,n) for(int i=int(n)-1;i>=int(m);--i)
#define EACH(i,c) for (auto &(i): c)
#define all(c) begin(c),end(c)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort(begin(c),end(c))
#define pb emplace_back
#define MP make_pair
#define SZ(a) int((a).size())
//#define int long long

#ifdef LOCAL
#define DEBUG(s) cout << (s) << endl
#define dump(x)  cerr << #x << " = " << (x) << endl
#define BR cout << endl;
#else
#define DEBUG(s) do{}while(0)
#define dump(x) do{}while(0)
#define BR 
#endif
using namespace std;

using UI = unsigned int;
using UL = unsigned long;
using LL = long long;
using ULL = unsigned long long;
using VI = vector<int>;
using VVI = vector<VI>;
using VLL = vector<LL>;
using VVLL = vector<VLL>;
using VS = vector<string>;
using PII = pair<int,int>;
using VP = vector<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 gcd(int m, int n) {
    if (n == 0) return m;
    if (m < n) return gcd(n,m);
    return gcd(n, m % n);
}

void solve() {
    int a,b;
    cin >> a >> b;
    cout << 1LL * a * b / gcd(a,b) << endl;
}

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

Measured memory_bytes: 256
# -*- coding: utf-8 -*-
"""
"""
# 

def gcd(x, y):
    if x < y:
        temp = x
        x = y
        y = temp
    while y > 0:
        r = x % y
        x = y
        y = r
    return x


def lcm(x, y):
    return x * y // gcd(x, y)


def solve(clocks):
    temp_lcm = clocks[0]
    for n in clocks[1:]:
        temp_lcm = lcm(temp_lcm, n)
    return temp_lcm


def main():
    N = int(input())
    clocks = [int(input()) for _ in range(N)]
    result = solve(clocks)
    print(result)


if __name__ == '__main__':
    main()
    


Measured memory_bytes: 3064
#include <bits/stdc++.h>
#define REP(i, n) for(int i = 0; i < n; i++)
#define REPR(i, n) for(int i = n; i >= 0; i--)
#define FOR(i, m, n) for(int i = m; i < n; i++)
#define INF 2e9
#define ALL(v) (v).begin(), (v).end()
using namespace std;
typedef long long ll;
int GCD(int a,int b){return b?GCD(b,a%b):a;}
int LCM(int a,int b){return (a*b)/GCD(a,b);}
int abs(int x){return x>0?x:-x;}
 
//const int dx[] = {1, 0, -1, 0, 1, -1, -1, 1};
//const int dy[] = {0, 1, 0, -1, 1, 1, -1, -1};

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

	for (int i = 0; i <= n; i++){
		for (int j = 0; j <= m; j++){
			if (i * (m - j) + j * (n - i) == k){
				cout << "Yes" << endl;
				return 0;
			}
		}
	}

	cout << "No" << endl;

}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define INF 100000000
#define fi first
#define se second
const int LEN = 2e5+5;
typedef long long ll;
int n, dp[3][LEN];
int main() {

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

   // ios_base::sync_with_stdio(0); cin.tie(NULL);
   scanf("%d",&n);
   int ar[3][LEN];
   for(int i =1;i<=n;i++) {
   		scanf("%d%d%d",&ar[0][i],&ar[1][i],&ar[2][i]);
   }

   dp[0][1] = ar[0][1];
   dp[1][1] = ar[1][1];
   dp[2][1] = ar[2][1];

   for(int i =2;i<=n;i++) {
      dp[0][i] = ar[0][i]+max(dp[1][i-1],dp[2][i-1]);
      dp[1][i] = ar[1][i]+max(dp[0][i-1],dp[2][i-1]);
      dp[2][i] = ar[2][i]+max(dp[0][i-1],dp[1][i-1]);
   }
   cout<<max(max(dp[0][n],dp[1][n]),dp[2][n])<<endl;
}   

Measured memory_bytes: 3712
s = input(); n = len(s); a = [-1]*26; b = [0]*26
for i in range(n): j = ord(s[i])-97; b[j] = max(b[j], i-a[j]-1); a[j] = i
for i in range(26): b[i] = max(b[i], n-a[i]-1)
print(min(b))

Measured memory_bytes: 9076
N = int(input())
H_ = list(map(int,input().split()))
for i in reversed(range(N-1)):
    if H_[i+1] < H_[i]:
        H_[i] = H_[i] -1

ans = 1
for i in range(N-1):
    if H_[i+1] < H_[i]:
        ans = 0
if ans == 0:
    print("No")
else:
    print("Yes")

Measured memory_bytes: 14252
#include<bits/stdc++.h>
using namespace std;
const long long mod=1e9+7,INF=1e18;
#define ll long long
#define pll pair<ll,ll>
#define pii pair<int,int>
#define pb(a) push_back(a)
#define mp(a,b) make_pair(a,b)
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    ll t=1;
    // cin>>t;
    while(t--)
    {
        int ans=-1;
        string s;
        cin>>s;
        for(int i=0;i<s.size()-2;i++)
        {
            if(s[i]==s[i+1]||s[i]==s[i+2]||s[i+1]==s[i+2])
            {
                ans=i;
                break;
            }
        }
        if(s.size()==2)
        {
            if(s[0]==s[1])
            cout<<1<<" "<<2<<"\n";
            else
            cout<<-1<<" "<<-1<<"\n";
            continue;
        }
        if(ans!=-1)
        cout<<ans+1<<" "<<ans+3<<"\n";
        else
        cout<<ans<<" "<<ans<<"\n";
    }
    return 0;
}

Measured memory_bytes: 3792
from sys import stdin
 
A, B, N = [int(x) for x in stdin.readline().rstrip().split()]
 
ans1 = (A*N)//B-A*(N//B)
 
if B-1<=N:
	ans2 = (A*(B-1))//B
else:
  	ans2=0
 
print(max(ans1,ans2))

Measured memory_bytes: 9156
#include <iostream>

using namespace std;
int main (){
    int a,b,k;
    cin >> a >> b >> k;
    if(b-a+1<2*k){
        for (int i = a; i <= b; i++){
            cout << i << "\n";
        }
    }
    else{
        for (int i = a; i < a+k; i++){
            cout << i << "\n";
        }
        for (int i = b-k+1; i <= b; i++){
            cout << i << "\n";
        }
    }
}

Measured memory_bytes: 256
iN,iM = [int(x) for x in input().split()]
iD = 10**9 +7 #法

def fPrimeCounter(iM):
    iS = int(iM ** 0.5) + 1
    aRet = []
    for i in range(2,iS + 1):
        iCounter = 0
        while iM % i == 0:
            iM = iM / i
            iCounter += 1
        if 0 < iCounter : aRet.append(iCounter)
        if iM == 1 : break
    if 1 < iM  : aRet.append(1)
    return aRet

#二分累乗法 iDを法として
def fBiPow(iX,iN,iD):
    iY = 1
    while iN > 0:
        if iN % 2 == 0:
            iX = iX * iX % iD
            iN = iN // 2
        else:
            iY = iX * iY % iD
            iN = iN - 1
    return iY

aP = fPrimeCounter(iM)
if len(aP) == 0:
    print(1)
    exit()
iMax = max(aP) + iN - 1
aM = [1] * (iMax + 1)
#階乗 iD を法とした
for i in range(1,iMax + 1):
    aM[i] = aM[i-1] * i  % iD
aInvM = [1]* (iMax + 1)
aInvM[iMax] = fBiPow(aM[iMax],iD-2,iD)
#階乗の逆元 iD を法とした
for i in range(iMax,0,-1):
    aInvM[i-1] = aInvM[i]*i % iD

iRet = 1
for i in aP:
    # i + iN -1  C  iN -1
    iRet *= aM[i+iN-1] * aInvM[iN-1] * aInvM[i] % iD
iRet %= iD
print(iRet)


Measured memory_bytes: 10996
package main

import (
  "fmt"
)

func main(){
  var A, B, K int
  
  fmt.Scan(&A)
  fmt.Scan(&B)
  
  K = (B + A)/2
  
  if(K > A && K < B){
    if( K - A == B - K){
    	fmt.Print(K)
    }else{
      fmt.Print("IMPOSSIBLE")
    }
  }else if(K < A && K > B){
    if( A - K == K - B){
    	fmt.Print(K)
    }else{
      fmt.Print("IMPOSSIBLE")
    }
    }else{
      fmt.Print("IMPOSSIBLE")
    }
    
}

Measured memory_bytes: 512
#define _USE_MATH_DEFINES
#define _CRT_SECURE_NO_WARNINGS

#include <iostream>
#include <string>
#include <sstream>
#include <iomanip>
#include <cmath>
#include <cstring>
#include <cstdlib>
#include <algorithm>
#include <stack>
#include <queue>
#include <vector>
#include <list>
#include <set>
#include <map>
#include <bitset>
#include <utility>
#include <numeric>

using namespace std;

using ll = long long;
using ull = unsigned long long;

const ll inf = (ll)1e9 + 1;
const ll mod = (ll)1e9 + 7;

int main()
{
	ll n, x, y;
	cin >> n >> x >> y;

	vector<ll> a(n);

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

	ll ans = -1;
	if (n == 1)
	{
		ans = abs(a.at(0) - y);
	}
	else
	{
		ans = max(abs(a.back() - y), abs(a.back() - a.at(n - 2)));
	}

	cout << ans << endl;


}

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

using pii = pair<int, int>;

using ll = long long;

constexpr ll mod = 1e9 + 7;

int main() {
    int n; cin >> n;
    vector<pii> ps;
    for(int i = 0; i < n; ++i) {
        int a; cin >> a;
        ps.emplace_back(a, 0);
    }
    for(int i = 0; i < n; ++i) {
        int b; cin >> b;
        ps.emplace_back(b, 1);
    }
    sort(begin(ps), end(ps));

    ll ans = 1, acnt = 0;
    for(int i = 0; i < 2 * n; ++i) {
        if(ps[i].second == 0) {
            if(acnt < 0) {
                (ans *= -acnt) %= mod;
            }
            acnt += 1;
        } else {
            if(acnt > 0) {
                (ans *= acnt) %= mod;
            }
            acnt -= 1;
        }
    }

    cout << ans << endl;
}


Measured memory_bytes: 2420
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define ld long double
const int MOD=1e9+7;
const long double Pi=acos(-1);
using  P=pair<ll,ll>;
ll gcd(ll a,ll b){//aとbの最大公約数を返す
  if(a%b==0){return b;}
  else{return gcd(b,a%b);}
}
ll lcm(ll a,ll b){//aとbの最小公倍数を返す
  return a*b/gcd(a,b);
}
ll pow(ll x,ll y){//x^yを返す
  ll tmp=x,res=1;
  while(y){
    if(y%2){res=res*tmp%MOD;}
    y>>=1;
    tmp=tmp*tmp%MOD;
  }
  return res;
}
ll nature(ll a){//絶対値を返す
  if(a>=0){return(a);}
  else{return(-1*a);}
}
ll prime(ll a){//素数なら1を返す
  if(a==2){return 1;}
  else if(a%2==0 || a==1){return 0;}
  for(ll i=3;i*i<=a;i+=2){if(a%i==0){return 0;}}
  return 1;
}
int main(){
  ll N,a,rock=0,ans=0;
  cin>>N;
  unordered_map<ll,ll> mp;
  for(ll i=0;i<N;i++){
    cin>>a;
    mp[a]++;
    if(a==0){rock++;}
  }
  if(N%3!=0 && rock!=N){cout<<"No"<<endl;return 0;}
  if(rock==N){cout<<"Yes"<<endl;return 0;}
  if(rock==N/3 && mp.size()==2){cout<<"Yes"<<endl;return 0;}
  if(mp.size()==3){
    ll checker=0;
    for(auto itr=mp.begin();itr!=mp.end();itr++){
      ans^=(itr->first);
      if(itr->second==N/3){checker++;}
    }
    if(ans==0 && checker==3){cout<<"Yes"<<endl;return 0;}
    else{cout<<"No"<<endl;return 0;}
  }
  cout<<"No"<<endl;
}

Measured memory_bytes: 3620
#include <bits/stdc++.h>
#include <cstdlib>  // abs() for integer
#include <cmath>    // abs() for float, and fabs()
#include <algorithm>
#include <vector>
#include <iostream>
using namespace std;

int main() {
  int n,m, k;
  double l,d;	
  cin >> n;
  vector<int> a(n);
  for (int i =0; i<n; i++){
    cin >> a[i];
  }
  
  int p = 0;
  for (int i =0; i<n; i++){
    if(a[p]<a[i]){
      p = i;
    }
  }
  m =a[p];
  a.erase(a.begin() + p);
  d= m;
  for (int i=0; i<n-1; i++){
    l = abs(m/2.0 -a[i]);
    if(d > l){
      d= l;
      k = i;
    }
  }
  cout << m << " " << a[k];
}


Measured memory_bytes: 640
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
#define ll long long
#define rep(i,l,r)for(ll i=(l);i<(r);i++)
#define repp(i,l,r,k)for(ll i=(l);i<(r);i+=(k))
#define INF ((1LL<<62)-(1LL<<31))
#define max(p,q)((p)>(q)?(p):(q))
#define min(p,q)((p)<(q)?(p):(q))
#define bit(n,m)(((n)>>(m))&1)
int upll(const void*a, const void*b){return*(ll*)a<*(ll*)b?-1:*(ll*)a>*(ll*)b?1:0;}
int downll(const void*a, const void*b){return*(ll*)a<*(ll*)b?1:*(ll*)a>*(ll*)b?-1:0;}
void sortup(ll*a,int n){qsort(a,n,sizeof(ll),upll);}
void sortdown(ll*a,int n){qsort(a,n,sizeof(ll),downll);}
ll pom(ll a,ll n,int m){ll x=1;for(a%=m;n;n/=2)n&1?x=x*a%m:0,a=a*a%m;return x;}
//#define MOD 998244353
#define MOD 1000000007
#define invp(a,p)pom(a,p-2,p)


//階乗,二項係数
//*
ll fact[100010];
ll invfact[100010];
void makefact(int n,ll m){
	n=min(n,m-1);
	fact[0]=1;
	rep(i,0,n)fact[i+1]=fact[i]*(i+1)%m;
	invfact[n]=invp(fact[n],m);
	for(int i=n;i>0;i--)invfact[i-1]=invfact[i]*i%m;
}
ll choose(int n,int r,int m){return n<0||r<0||n-r<0?0:fact[n]*invfact[r]%m*invfact[n-r]%m;}
//*/

ll dp[30][1010];
ll n,k;
ll a[1010];
int main(){
	makefact(3000,MOD);
	scanf("%lld%lld",&n,&k);
	rep(i,0,k)scanf("%lld",a+i);
	dp[0][0]=fact[n];
	rep(i,0,k)rep(j,0,n+1){
		rep(m,0,n-j+1)dp[i+1][j+m]=(dp[i+1][j+m]+dp[i][j]*choose(n-m,a[i]-m,MOD)%MOD*invfact[m])%MOD;
	}
	printf("%lld",dp[k][n]);
}



Measured memory_bytes: 384
S = list(str(input()))
like = 753

ans = 1000

for i in range(len(S)):
  S[i] = int(S[i])

for i in range(len(S)-2):
  X = S[i] * 100 + S[i+1] * 10 + S[i+2]
  if ans > abs(X - like):
    ans = abs(X - like)
    
print(ans)

Measured memory_bytes: 3060
/*
  Motto - try hard to become an expert
*/
#include <bits/stdc++.h>
#include <map>
#include <algorithm>
#include <vector>
#include <string.h>
#include <math.h>
#include <stdio.h>
#include <stdlib.h>
#include <chrono>
#include <thread>
#include <iomanip>
 
//define
#define rep(i,n)    for(int i=0;i<n;i++)
#define repu(i,k,n) for(int i=k;i<=n;i++)
#define repd(i,k,n) for(int i=k;i>=n;i--)
#define se second
#define fi first
#define pb push_back
#define mp make_pair
#define INF (int)INT_MAX
#define all(v)  v.begin(), v.end()
#define endl "\n"
 
//typedef
typedef long long int ll;
typedef long double ld;
typedef std::pair<int, int> pii;
typedef std::vector<int> vi;
typedef std::vector< pii > vii;
typedef std::vector< ll > vll;
typedef std::vector< std::pair < pii, int > > vpp;
 
const int N = 3*1e5 +5 ;
const long long MOD = 998244353;
const long long inf = 1e18;
 
using namespace std;
 
ll MAXN=100001;
ll spf[100001]; 
 
ll modpow(ll x,ll n){
    ll res=1;
    while(n>0){
        if(n&1) res=res*x%MOD;
        x=x*x%MOD;
        n>>=1;
    }
    return res;
}
 
ll modFact(ll n, ll p) 
{ 
    if (n >= p) 
        return 0; 
  
    ll result = 1; 
    for (ll i = 1; i <= n; i++) 
        result = (result * i) % p; 
  
    return result;  
} 
 
bool isPrime(int x)
{
    if(x%2==0)
        return 0;
    for(int i=3;i<=sqrt(x);i+=2)
    {
        if(x%i==0)
            return 0;
    }
    return 1;
}



void solve()
{
	int n ,  m ; 
	cin>>n>>m;
	vector<vector<int>>g(n);
	 int parent[n] ;
	  bool vis[n] ;

	rep(i , m){
		int u , v; 
		cin>>u>>v ; 
		u--;
		v-- ;
		g[u].pb(v) ; 
		g[v].pb(u) ;
	}
	memset(vis,false,sizeof(vis));
	memset(parent , -1 , sizeof(parent));
	queue<int>q;

	q.push(0);
	vis[0] = true;
	while(!q.empty()){
		int tnode = q.front() ;
		q.pop() ;
		for(int temp : g[tnode]){
			if(!vis[temp]){
				vis[temp] = true;
				parent[temp]  = tnode ;
				q.push(temp);
			}
		}
	}
	rep(i , n){
		if(!vis[i]){
			cout<<"No";
			return;
		}
	}
	cout<<"Yes\n";
	repu(i,1 , n-1){
		cout<<parent[i]+1<<endl;
	}


}
 
int main() {
    #ifndef ONLINE_JUDGE
        // for getting input from input.txt
        freopen("input.txt", "r", stdin);
        // for writing output to output.txt
        freopen("output.txt", "w", stdout);
    #endif
    
    ios_base::sync_with_stdio(0);
    cin.tie(NULL);
    int t = 1;
    // cin>>t;
    while(t--)
    {
        solve();
    } 
    cerr << "Time : " << 1000 * ((double)clock()) / (double)CLOCKS_PER_SEC << "ms\n";
}

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

using namespace std;

using int64 = long long;

string S;

int dfs(int idx, int num = 0, int sz = 0) {
  if(idx == S.size()) return sz == 4 && num == 0;
  int ret = 0;
  if(S[idx] == '0') {
    int nxt = num * 10;
    if(num == 0) {
      ret += dfs(idx + 1, 0, sz + 1);
    } else {
      ret += dfs(idx + 1, nxt, sz);
      if(0 <= nxt && nxt < 256) ret += dfs(idx + 1, 0, sz + 1);
    }
  } else {
    int nxt = num * 10 + S[idx] - '0';
    ret += dfs(idx + 1, nxt, sz);
    if(0 <= nxt && nxt < 256) ret += dfs(idx + 1, 0, sz + 1);
  }
  return ret;
}

int main() {

  cin >> S;
  cout << dfs(0) << endl;


}


Measured memory_bytes: 3172
#include <bits/stdc++.h>
#define REP(i,n) for (int i = 0; i <(n); ++i)
#define REP2(i,x,n) for (int i = x; i <(n); ++i)
#define ALL(v) v.begin(), v.end()
#define RALL(v) v.rbegin(), v.rend()
using namespace std;
using ll = long long;
using P = pair<int,int>;
static const double PI = acos(-1);
static const int INF = 1e9+7;



int main(){
  string s1, s2, s3;
  cin >> s1 >> s2 >> s3;
  s1[0] -= 32;
  s2[0] -= 32;
  s3[0] -= 32;

  cout << s1[0] << s2[0] << s3[0] << endl;
  //<<  s2[0] + 32 << s3[0] + 32 << endl;
  return 0;
}


Measured memory_bytes: 3628
N = int(input())
L = list(map(int, input().split()))
L.sort()

ans = 0

for i in range(N):
  for j in range(i+1, N):
    for k in range(j+1, N):
      if L[i] == L[j] or L[j] == L[k]:
        continue
      if (L[i] + L[j]) > L[k]:
        ans += 1

print(ans)


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

int N;
int h[100010];

int dp[100010];

int INF = 1 << 29;

int main ()
{
    cin >> N;
    for (int i = 1; i <= N; ++i) cin >> h[i];

    //memset(dp, INF, sizeof(dp));
    dp[0] = 0;
    dp[1] = 0;
    dp[2] = abs(h[2] - h[1]);

    for( int j = 3; j <= N; ++j)
    {
        dp[j] = min(dp[j - 1] + abs(h[j]-h[j - 1]), dp[j - 2] + abs(h[j] - h[j - 2]));

    }
    cout << dp[N] << endl;



}

Measured memory_bytes: 1024
#include <iostream>
#include <iomanip>
#include <vector>
#include <set>
#include <string>
#include <queue>
#include <algorithm>
#include <map>
#include <cmath>
#include <numeric>
#include <list>
#include <stack>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <tuple>

#define rep(i, n) for (int i = 0; i < (n); i++)
#define rep1(i, n) for (int i = 1; i <= (n); i++)
#define show(a, n) rep(i,n) {cout<<a[i]<<' ';} cout<<endl;

using namespace std;
typedef vector<int> vi;
typedef pair<int, int> pii;
typedef long long ll;
typedef pair<long long, long long> pll;

const int INF = 1 << 30;
const long long INFL = 1LL << 62;
const int MOD = 1000000007;
const int MAX = 100000;
const int N = 100010;

int main() {
	ll n, t;
	cin >> n >> t;
	ll a[N];
	rep(i, n) cin >> a[i];
	ll min_a[N][2], max_a[N][2];
	min_a[0][0] = a[0];
	min_a[0][1] = 1;
	for(int i = 1; i < n; i++) {
		min_a[i][0] = min(min_a[i-1][0], a[i]);
		if(a[i] < min_a[i-1][0]) min_a[i][1] = 1;
		else min_a[i][1] = min_a[i-1][1] + (min_a[i-1][0] == a[i]);
	}
	max_a[n-1][0] = a[n-1];
	max_a[n-1][1] = 1;
	for(int i = n-2; i >= 0; i--) {
		max_a[i][0] = max(max_a[i+1][0], a[i]);
		if(a[i] > max_a[i+1][0]) max_a[i][1] = 1;
		else max_a[i][1] = max_a[i+1][1] + (max_a[i+1][0] == a[i]);
	}
	ll diff_max = 0ll;
	rep(i, n) diff_max = max(max_a[i][0] - min_a[i][0], diff_max);

	ll min_tmp = -1, max_tmp = -1;
	ll min_count = 0, max_count = 0;
	ll ans = 0;
	rep(i, n) {
		if(diff_max != max_a[i][0] - min_a[i][0]) continue;
		if(min_a[i][0] != min_tmp) {
			ans += min(min_count, max_count);
			min_count = 1;
			max_count = 1;
			min_tmp = min_a[i][0];
		}
		else {
			min_count = max(min_a[i][1], min_count);
			max_count = max(max_a[i][1], max_count);
		}
	}
	ans += min(min_count, max_count);
	cout << ans << endl;
}


Measured memory_bytes: 4096
s=input()
l=len(s)
sum1=0
sum2=0

a=[0 for i in range(l)]
c=[0 for i in range(l)]
d=[0 for i in range(l)]

for i in range(l):
  a[i]=int(s[i])

for i in range(l):
  if i%2==0:
    c[i]=1

for i in range(l):
  if i%2==1:
    d[i]=1
    
for i in range(l):
  sum1+=abs(a[i]-c[i])
  sum2+=abs(a[i]-d[i])
  

print(min(sum1,sum2))


Measured memory_bytes: 5628
import cmath
EPS = 1e-4

#外積
def OuterProduct(one, two):
	tmp = one.conjugate() * two
	return tmp.imag

#内積
def InnerProduct(one, two):
	tmp = one.conjugate() * two
	return tmp.real

#点が線分上にあるか
def IsOnSegment(point, begin, end):
	if abs(OuterProduct(begin-point, end-point)) <= EPS and InnerProduct(begin-point, end-point) <= EPS:
		return True
	else:
		return False

#3点が反時計回りか
#一直線上のときの例外処理できていない→とりあえずF
def CCW(p, q, r):
	one, two = q-p, r-q
	if OuterProduct(one, two) > -EPS:
		return True
	else:
		return False

def solve(p, q, r):
	if abs(OuterProduct(q-r, p-r)) <= EPS:
		if InnerProduct(q-r, p-r) <= EPS:
			return "ON_SEGMENT"
		elif abs(p-r) < abs(q-r):
			return "ONLINE_BACK"
		else:
			return "ONLINE_FRONT"
	elif CCW(p, q, r):
		return "COUNTER_CLOCKWISE"
	else:
		return "CLOCKWISE"

a, b, c, d = map(int, input().split())
p, q = complex(a, b), complex(c, d)
n = int(input())
for _ in range(n):
	x, y = map(int, input().split())
	r = complex(x, y)
	print(solve(p, q, r))


Measured memory_bytes: 5708
n = int(input())
s = input()

kuro_li = [0]*(n+1)

if s[0] == "#":
    kuro_li[1] = 1

for i in range(1,n):
    #print(i)
    kuro_li[i+1] = kuro_li[i]
    if s[i] == "#":
        kuro_li[i+1] += 1
        
siro_li = [0]*(n+1)

if s[-1] == ".":
    siro_li[-2] = 1

for i in range(n,0,-1):
    #print(i)
    siro_li[i-1] = siro_li[i]
    if s[i-1] == ".":
        siro_li[i-1] += 1
    
#print(kuro_li)
#print(siro_li)


ans = 10**10

for i in range(n+1):
    tmp = kuro_li[i] + siro_li[i]
    ans = min(ans,tmp)
    
print(ans)

Measured memory_bytes: 73032
#include <stdio.h>

int main(void)
{
	int d, s, x, y;
	
	while (scanf("%d", &d) != EOF){
		s = 0;
		for (x = d; x < 600; x += d){
			y = x * x;
			s += y * d;
		}
		
		printf("%d\n", s);
	}
	
	return (0);
}

Measured memory_bytes: 596
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define dup(x,y) (((x)+(y)-1)/(y))
#define ALL(x) (x).begin(), (x).end()
typedef long long ll;
typedef pair<int, int> pii;
const double EPS = 1e-10;
const int INF = 1e9;
const ll LINF = 1e18;
const int MOD = 1000000007;
const double PI = acos(-1);
int dx[4] = {0,1,0,-1};
int dy[4] = {1,0,-1,0};

int main() {
	int n;
	cin >> n;
	vector<int> v(n);
	rep(i,n) cin >> v[i];
	int mx = 0;
	int p = -1;
	int mn = 0;
	int q = -1;
	rep(i,n) {
		if (mx < v[i]) {
			mx = v[i];
			p = i;
		}
		if (mn > v[i]) {
			mn = v[i];
			q = i;
		}
	}

	if (mx == mn) {
		cout << 0 << endl;
	} else if (abs(mx) > abs(mn)) {
		vector<pii> ans;
		rep(i,n) {
			if (p == i) continue;
			ans.push_back(pii(p, i));
			v[i] += mx;
		}
		for (int i = 1; i < n; i++) {
			ans.push_back(pii(i-1, i));
		}

		cout << ans.size() << endl;
		rep(i,(int)ans.size()) {
			cout << ans[i].first + 1 << " " << ans[i].second + 1 << endl;;
		}
	} else {
		vector<pii> ans;
		rep(i,n) {
			if (q == i) continue;
			ans.push_back(pii(q, i));
			v[i] += mn;
		}
		for (int i = n-1; i >= 1; i--) {
			ans.push_back(pii(i, i-1));
		}

		cout << ans.size() << endl;
		rep(i,(int)ans.size()) {
			cout << ans[i].first + 1 << " " << ans[i].second + 1 << endl;
		}
	}
}

Measured memory_bytes: 3620
#pragma GCC optimize("Ofast")
#include<bits/stdc++.h>
using namespace std;
using ll=long long;
using datas=pair<ll,ll>;
using ddatas=pair<double,double>;
using tdata=pair<ll,datas>;
using vec=vector<ll>;
using mat=vector<vec>;
using pvec=vector<datas>;
using pmat=vector<pvec>;
#define For(i,a,b) for(i=a;i<(ll)b;i++)
#define bFor(i,a,b) for(i=a;i>=(ll)b;i--)
#define rep(i,N) For(i,0,N)
#define rep1(i,N) For(i,1,N)
#define brep(i,N) bFor(i,N-1,0)
#define all(v) (v).begin(),(v).end()
#define allr(v) (v).rbegin(),(v).rend()
#define vsort(v) sort(all(v))
#define vrsort(v) sort(allr(v))
#define endl "\n"
#define pb push_back
#define print(v) cout<<v<<endl
#define printyes cout<<"Yes"<<endl
#define printno cout<<"No"<<endl
#define printYES cout<<"YES"<<endl
#define printNO cout<<"NO"<<endl
#define output(v) do{bool f=0;for(auto outi:v){cout<<(f?" ":"")<<outi;f=1;}cout<<endl;}while(0)
const ll mod=1000000007;
const ll inf=1LL<<60;
const double PI = acos(-1);
const double eps = 1e-9;
template<class T> inline bool chmax(T& a,T b){bool x=a<b;if(x)a=b;return x;} 
template<class T> inline bool chmin(T& a,T b){bool x=a>b;if(x)a=b;return x;} 

void startupcpp(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout<<fixed<<setprecision(15);
}

double distance(ddatas& x,ddatas& y){
  double a=x.first-y.first,b=x.second-y.second;
  return sqrt(a*a+b*b);
}

ll modinv(ll a) {
  ll b=mod,u=1,v=0,t;
  while(b){
    t=a/b;
    a-=t*b; swap(a,b);
    u-=t*v; swap(u,v);
  }
  return (u+mod)%mod;
}

ll moddevide(ll a,ll b){return (a*modinv(b))%mod;}

vec modncrlistp,modncrlistm;

ll modncr(ll n,ll r){
  ll i,size=modncrlistp.size();
  if(size<=n){
    modncrlistp.resize(n+1);
    modncrlistm.resize(n+1);
    if(!size){
      modncrlistp[0]=modncrlistm[0]=1;
      size++;
    }
    For(i,size,n+1){
      modncrlistp[i]=modncrlistp[i-1]*i%mod;
      modncrlistm[i]=modinv(modncrlistp[i]);
    }
  }
  return modncrlistp[n]*modncrlistm[r]%mod*modncrlistm[n-r]%mod;
}

ll modpow(ll a,ll n){
  ll res=1;
  while(n){
    if(n&1)res=res*a%mod;
    a=a*a%mod;
    n>>=1;
  }
  return res;
}

ll gcd(ll a,ll b){if(!b)return a;return (a%b==0)?b:gcd(b,a%b);}
ll lcm(ll a,ll b){return a/gcd(a,b)*b;}

ll countdigits(ll n){
  ll ans=0;
  while(n){n/=10;ans++;}
  return ans;
}

ll sumdigits(ll n){
  ll ans=0;
  while(n){ans+=n%10;n/=10;}
  return ans;
}

int main(){
  // startupcpp();
  // ll test;cin>>test;while(test--){
  ll i,j,k,H,W,ans=0;
  string s;
  cin>>H>>W;
  vec v(H*W);
  mat mp(H*W),dist(H*W,vec(H*W,inf));
  rep(i,H){
    cin>>s;
    rep(j,W){
      if(v[i*W+j]=(s[j]=='.')){
        if(i&&v[(i-1)*W+j]){
          dist[i*W+j][(i-1)*W+j]=1;
          dist[(i-1)*W+j][i*W+j]=1;
        }
        if(j&&v[i*W+j-1]){
          dist[i*W+j][i*W+j-1]=1;
          dist[i*W+j-1][i*W+j]=1;
        }
      }
      dist[i*W+j][i*W+j]=0;
    }
  }
  rep(k,H*W)rep(i,H*W)rep(j,H*W)chmin(dist[i][j],dist[i][k]+dist[k][j]);
  rep(i,H*W){
    ll res=0;
    rep(j,H*W){
      if(dist[i][j]!=inf)chmax(res,dist[i][j]);
    }
    if(res!=inf)chmax(ans,res);
  }
  print(ans);
  return 0;
}

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

typedef int integer;

#define FIN ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define ll long long
#define ld long double
#define pb push_back
#define bs binary_search
#define up upper_bound
#define lw lower_bound
#define fs first 
#define sd second 
#define mp make_pair    

#define fore(i,a,b) for(ll i = a; i < b; i++)
#define rfore(i, a, b) for(ll i = a - 1; i >= b; i--)
#define forev(a,b) fore(i,0,b)cout<<a[i]<<" "; 
#define mm(a,b) memset(a , b , sizeof a) 
#define ALL(a) a.begin(),a.end() 
#define SZ(n) ((ll) (n).size())

#define infi  2e9
#define int long long
#define endl '\n'
const ld pi = 3.14159265358979323846;
const ll mod = 1e9+7;
const ll INF = 1e10;
const ld EPS = 1e-8;

typedef pair<ll,ll> pll;

ll gcd(ll a, ll b) { return b == 0 ? a : gcd(b,a%b); } 
ll lcm(ll a, ll b) { return a * (b / gcd(a, b)); }

const int MAXN = 200000;
const int K=20;

int n,k;
int h[MAXN];
int dp[MAXN];

int solve(int pos){
	if(pos>=n-1)return 0;
	int &r=dp[pos];
	if(r!=-1)return dp[pos];
	r = INF;
	fore(i,1,k+1){
		r=min(r,abs(h[pos]-h[pos+i])+solve(pos+i));
	}
	return r;
}

integer main(){
	cin>>n>>k; 
	fore(i,0,n)cin>>h[i];
	fore(i,0,k){
		h[n+i]=INF;
	}
	mm(dp,-1);
	cout<<solve(0);
    return 0;
}

Measured memory_bytes: 5760
from sys import stdin
import sys
import math
from functools import reduce
import functools
import itertools
from collections import deque,Counter,defaultdict
from operator import mul
import copy
# ! /usr/bin/env python
# -*- coding: utf-8 -*-
import heapq
sys.setrecursionlimit(10**6)
# INF =  float("inf")
INF = 10**18
import bisect
import statistics
mod = 10**9+7
# mod = 998244353

r = int(input())

print(3*r**2)

Measured memory_bytes: 77040
#include<bits/stdc++.h>
#include <math.h>
using namespace std;
#define rep(i,n) for(ll i=0;i<n;i++)
#define repl(i,l,r) for(ll i=(l);i<(r);i++)
#define per(i,n) for(ll i=n-1;i>=0;i--)
#define lper(i,r,l) for(ll i=r-1;i>=l;i--)
#define fi first
#define se second
#define mp make_pair
#define all(x) (x).begin(),(x).end()
#define CST(x) cout<<fixed<<setprecision(x)
using ll=long long;
using vl=vector<ll>;
using vvl=vector<vector<ll>>;
using pl=pair<ll,ll>;
const ll MOD=1000000007;
const ll MOD9=998244353;
const int inf=1e9;
const ll INF=4e18;
const ll dy[4]={1,0,-1,0};
const ll dx[4]={0,-1,0,1};
int main() {
 ll H;
  ll W;
  cin >>H>>W;
  
  ll data[10][10];
  
  rep(i,10) {
rep(j,10) {
  cin >>data[i][j];
}
  }
  
  ll A[H][W];
  rep(i,H) {
rep(j,W) {
  cin >>A[i][j];
}
  }
  

  for (int k = 0; k < 10; k++){       // 経由する頂点
    for (int i = 0; i < 10; i++) {    // 始点
      for (int j = 0; j < 10; j++) {  // 終点
        data[i][j] = min(data[i][j], data[i][k] + data[k][j]);
      }
    }
  }

  
  vl vec(10);
  rep(i,10) {
    vec.at(i)=data[i][1];
  }
  
  ll sum=0;
  rep(i,H) {
    rep(j,W) {
if(A[i][j]==-1) {
continue;
}
      else {
        sum +=vec.at(A[i][j]);
      }
    }
  }
  
  
  cout<<sum<<endl;
 
}
 

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

#define pb(n) push_back(n)
#define fi first
#define se second
#define all(r) (r).begin(),(r).end()
#define gsort(st,en) sort((st),(en),greater<int>())
#define vmax(ary) *max_element(all(ary))
#define vmin(ary) *min_element(all(ary))
#define debug(x) cout<<#x<<": "<<x<<endl
#define fcout(n) cout<<fixed<<setprecision((n))
#define scout(n) cout<<setw(n)
#define vary(type,name,size,init) vector< type> name(size,init)

#define rep(i,n) for(int i = 0; i < (int)(n);++i)
#define REP(i,a,b) for(int i = (a);i < (int)(b);++i)
#define repi(it,array) for(auto it = array.begin(),end = array.end(); it != end;++it)
#define repa(n,array) for(auto &n :(array))

using ll = long long;
using vi = vector<int>;
using vl = vector<ll>;
using dict = map<string,int>;
using pii = pair<int,int> ;

constexpr int imax = ((1<<30)-1)*2+1 ;
constexpr int inf = 100000000;
constexpr double PI = acos(-1.0) ;
double eps = 1e-10 ;
const int dy[] = {-1,0,1,0};
const int dx[] = {0,-1,0,1};

inline bool value(int x,int y,int w,int h){
  return (x >= 0 && x < w && y >= 0 && y < h);
}

template<typename T>
void Unique(vector<T> &v){
  sort(all(v));
  v.erase(unique(all(v)),v.end());
}

template<typename T>
T ston(string& str, T n){
  istringstream sin(str) ;
  T num ;
  sin >> num ;
  return num ;
}

void Ans(bool f){
  if(f) cout << "YES"<<endl;
  else cout << "NO"<<endl;
}

int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  int y,m,d;
  while(cin >> y >> m >> d){
    if(y < 1868 || (y == 1868 && m < 9) || (y == 1868 && m == 9 && d < 8)){
      cout << "pre-meiji"<<endl;
    }
    else if(y < 1912 ||( y == 1912 && m < 7) || (y == 1912 && m == 7 && d < 30)){
      cout << "meiji " << y - 1868+1 << " " << m << " " << d << endl;
    }
    else if(y < 1926 ||( y == 1926 && m < 12) || (y == 1926 && m ==12 && d <25)){
      cout << "taisho " << y - 1912+1 << " " << m << " " << d<<endl;
    }
    else if(y < 1989 || ( y == 1989 && m == 1 && d < 8)){
      cout << "showa " << y - 1926+1 << " " << m << " " << d << endl;
    }
    else{
      cout << "heisei "<< y - 1989 + 1<< " " << m << " " << d << endl;
    }
  }
  return 0;
}

Measured memory_bytes: 3084
/*
*          Name : chaitanya
*
*     Institute : ANITS,Visakhapatnam
*
*/
#include<cstdio>
#include<iostream>
#include<sstream>
#include<fstream>
#include<iomanip>
#include<algorithm>
#include<cmath>
#include<complex>
#include<cstring>
#include<vector>
#include<list>
#include<queue>
#include<stack>
#include<set>
#include<map>
#include<bitset>
#include<numeric>
#include<limits>
#include<climits>
#include<cfloat>
#include<functional>
#include<iterator>
#include <random>
#define infy  1000000000
#define all(x) begin(x),end(x)
#define ll long long int
#define ff first
#define ss second
#define pb push_back
const ll mod = 1000000007;
#pragma GCC optimization ("O3")
const int N = 1000010;
using namespace std;
vector<string> vec_splitter(string s) {
  s += ',';
  vector<string> res;
  while(!s.empty()) {
    res.push_back(s.substr(0, s.find(',')));
    s = s.substr(s.find(',') + 1);
  }
  return res;
}
void debug_out(
vector<string> __attribute__ ((unused)) args,
__attribute__ ((unused)) int idx, 
__attribute__ ((unused)) int LINE_NUM) { cerr << endl; } 
template <typename Head, typename... Tail>
void debug_out(vector<string> args, int idx, int LINE_NUM, Head H, Tail... T) {
  if(idx > 0) cerr << ", "; else cerr << "Line(" << LINE_NUM << ") ";
  stringstream ss; ss << H;
  cerr << args[idx] << " = " << ss.str();
  debug_out(args, idx + 1, LINE_NUM, T...);
}
#ifndef ONLINE_JUDGE
#define debug(...) debug_out(vec_splitter(#__VA_ARGS__), 0, __LINE__, __VA_ARGS__)
#else
#define debug(...) 42
#endif
ll lcm(ll a,ll b)
{
  return (a*b)/__gcd(a,b);
}
int main()
{
  // int x = -1, y = 10000;
  // double z = 0.2;
  // string s2 = "beginner1010";
  // long long b = 1LL << 60;
    
  // // debug(x, y, z, s, b);
    
  // double aux = 1010.0;
  // string code = "code";
    
  // debug(code + "forces",-aux / 10 * 2.3);
  // freopen("input.txt","r",stdin);
  // freopen("output.txt","w",stdout);
  //ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
  int n,m;
  ll at = 0;
  cin >> n >> m;
  vector <int> v(n); 
  for (int i = 0; i < n; ++i)
  {
    cin >> v[i];
  }
  sort(all(v));
  reverse(all(v));
  for (int i = 0; i < min(n,m); ++i)
  {
    v[i] = 0;
  }
  for (int i = 0; i < n; ++i)
  {
    if(v[i] > 0)
      at += v[i];
  }
  cout << at;
  return 0;
}


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

typedef long long ll;
typedef pair<ll, ll> pll;

#define m0(x) memset(x, 0, sizeof(x))
#define all(x) x.begin(), x.end()
#define rep(i, n) for(int i = 0; i < (n); i++)
#define asort(x) sort(all(x));
#define dsort(x, t) sort(x.begin(), x.end(), greater<t>());
#define dump(x)  cout << #x << " = " << (x) << endl
#define vuniq(v) v.erase(unique(v.begin(), v.end()), v.end());
#define minse(m, s) m.insert(make_pair(s, 1));
#define mfin(m, s) m.find(s) != m.end()

#define YES(n) cout << ((n) ? "YES" : "NO" ) << endl
#define Yes(n) cout << ((n) ? "Yes" : "No" ) << endl

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

int main(){
    int a, b;
    cin >> a >> b;
    
    int max_ = -INF;
    max_ = max(a+b, a-b);
    max_ = max(max_, a*b);
    cout << max_ << endl;
    return 0;
}

Measured memory_bytes: 3608
#include<iostream>
using namespace std;
//Minimum Cost Flow O(FE log V)
#include<algorithm>
#include<utility>
#include<vector>
#include<queue>
#include<limits>
template<typename T>
struct MCF{
	vector<vector<pair<pair<int,int>,pair<int,T> > > >G;
	vector<T>h,d;
	vector<int>pv,pe;
	MCF(int n_=0):G(n_),h(n_,0),d(n_),pv(n_),pe(n_){}
	void add_edge(int from,int to,int cap,T cost)
	{
		G[from].push_back(make_pair(
			make_pair(to,G[to].size()),make_pair(cap,cost)
		));
		G[to].push_back(make_pair(
			make_pair(from,G[from].size()-1),make_pair(0,-cost)
		));
	}
	T min_cost_flow(int s,int t,int f)//ans or -1
	{
		T ret=0;
		while(f>0)
		{
			priority_queue<pair<T,int>,vector<pair<T,int> >,greater<pair<T,int> > >P;
			fill(d.begin(),d.end(),numeric_limits<T>::max());
			d[s]=0;
			P.push(make_pair(0,s));
			while(!P.empty())
			{
				pair<T,int>p=P.top();P.pop();
				if(d[p.second]<p.first)continue;
				for(int i=0;i<G[p.second].size();i++)
				{
					pair<pair<int,int>,pair<int,T> >&e=G[p.second][i];
					if(e.second.first>0&&
						d[e.first.first]>d[p.second]+e.second.second+h[p.second]-h[e.first.first])
					{
						d[e.first.first]=d[p.second]+e.second.second+h[p.second]-h[e.first.first];
						pv[e.first.first]=p.second;
						pe[e.first.first]=i;
						P.push(make_pair(d[e.first.first],e.first.first));
					}
				}
			}
			if(d[t]==numeric_limits<T>::max())return -1;
			for(int u=0;u<G.size();u++)h[u]+=d[u];
			int d=f;
			for(int u=t;u!=s;u=pv[u])d=min(d,G[pv[u]][pe[u]].second.first);
			f-=d;
			ret+=d*h[t];
			for(int u=t;u!=s;u=pv[u])
			{
				G[pv[u]][pe[u]].second.first-=d;
				G[u][G[pv[u]][pe[u]].first.second].second.first+=d;
			}
		}
		return ret;
	}
};
main()
{
	int N,E,F;
	cin>>N>>E>>F;
	MCF<int>mf(N);
	for(int i=0;i<E;i++)
	{
		int u,v,c,d;cin>>u>>v>>c>>d;
		mf.add_edge(u,v,c,d);
	}
	cout<<mf.min_cost_flow(0,N-1,F)<<endl;
}


Measured memory_bytes: 3160