akhauriyash/Code-Regression huggingface dataset:
from itertools import permutations, product
import sys
readline = sys.stdin.readline
write = sys.stdout.write
P = [
    "((%d %s %d) %s (%d %s %d))",
    "(%d %s (%d %s (%d %s %d)))",
    "(((%d %s %d) %s %d) %s %d)",
    "((%d %s (%d %s %d)) %s %d)",
    "(%d %s ((%d %s %d) %s %d))",
]
def solve():
    *X, = map(int, readline().split())
    if X[0] == 0:
        return False
    for Y in permutations(X):
        for ops in product("+-*", repeat=3):
            r = []
            for y, op in zip(Y, ops):
                r.append(y)
                r.append(op)
            r.append(Y[-1])
            for p in P:
                s = p % tuple(r)
                if eval(s) == 10:
                    write("%s\n" % s)
                    return True
    write("0\n")
    return True

while solve():
    ...



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

int main(void){
    string s;
    int a=0,u=0;
    int n;
        cin>>n;
        for(int i=0;i<n;i++){
            cin>>s;
            if(s=="A")a+=1;
            if(s=="Un")u+=1;
            if(u>a){cout<<"NO"<<endl;
            return 0;}
        }
        if(a>u)cout<<"NO"<<endl;
        else cout<<"YES"<<endl;
    return 0;
}


Measured memory_bytes: 3140
//created by pyoxiao on 2020/04/26
#include<bits/stdc++.h>
#define LL long long
#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define CL(a, b) memset(a, b, sizeof(a))
using namespace std;
const int mod = 1e9 + 7;
LL fpow(LL a, LL b, LL p = mod){LL ans = 1; a %= p; while(b) {if(b & 1) ans = ans * a % p; b >>= 1; a = a * a % p;} return ans;}
LL gcd(LL a, LL b){return b == 0 ? a : gcd(b, a % b);}
int s, w;
void solve() {
    scanf("%d %d", &s, &w);
    if(w >= s) puts("unsafe");
    else puts("safe");
}
int main() {
    int T = 1;
    // scanf("%d", &T);
    while(T --) 
        solve();
    return 0;
}

Measured memory_bytes: 3656
#include <bits/stdc++.h>
using namespace std;
#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 fi first
#define se second
#define mp make_pair
#define itrfor(itr,A) for(auto itr = A.begin(); itr !=A.end();itr++)
template <class T> using reversed_priority_queue = priority_queue<T, vector<T>, greater<T> >;
typedef long long llong;
char moji[26]={'a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z'};
char moji2[26]={'A','B','C','D','E','F','G','H','I','J','K','L','M','N','O','P','Q','R','S','T','U','V','W','X','Y','Z'};
char moji3[10]={'0','1','2','3','4','5','6','7','8','9'};
#define Sort(a) sort(a.begin(),a.end());
#define Reverse(a) reverse(a.begin(),a.end());
#define print(a) cout << a << endl;
#define MOD llong(1e9+7)
#define MAX int(2 * 1e5 +5)
#define debug(x)  cout << #x << " = " << (x) << endl;
#define pi acos(-1.0)
#define int llong
#define INF llong(1e17)
template<class T> bool chmax(T &a,  T b) {if(a<b){a=b; return 1;} return 0;}
template<class T> bool chmin(T &a,  T b) {if(a>b){a=b; return 1;} return 0;}
bool Add(int &a,int b){a = (a + b) % MOD;}
void myprint(int* A,int A_num){
   REP(i,A_num) cout << A[i] << " ";
   cout << endl;
}

signed main(){
    int n,m;
    cin >> n >> m;
    vector<int> Graph[n + 1];

    REP(i,m){
        int u,v;
        cin >> u >> v;
        Graph[u].push_back(v);
        Graph[v].push_back(u);
    }

    bool vis[n + 1];
    REP(i,n+1) vis[i] =false;

    int l,r;
    l = 1;
    vector<int> ans;

    while(1){
        vis[l] = true;
        ans.push_back(l);
        bool flag = false;
        itrfor(itr,Graph[l]){
            if(vis[*itr]) continue;
            l = *itr;
            flag = true;
            break;
        }
        if(flag == false) break;
    }

    Reverse(ans);
    r = 1;
    while(1){
        bool flag = false;
        itrfor(itr,Graph[r]){
            if(vis[*itr] ) continue;
            r = *itr;
            flag = true;
            break;
        }
        if(flag == false) break;
        ans.push_back(r);
        vis[r] = true;
    }


    cout << ans.size() << endl;
    itrfor(itr,ans){
        cout << *itr << " ";
    }
    cout << endl;

}

Measured memory_bytes: 7284
#include<stdio.h>
#include<string.h>
#include<stdlib.h>
#define LEN 100005

typedef struct{
  char name[100];
  int time;
}Array;


void initialize(void);
int isEmpty(void);
int isFull(void);
void enqueue(Array );
Array dequeue(void);

int head;
int tail;
int MAX = 100;
Array array[LEN+1];
int main(){
  Array hrt;
  int n;
  int q;
  int i=0;
  int timecount=0;

  initialize();
  scanf("%d%d",&n,&q);//個数の入力

  while(i < n){//中身の入力
    scanf("%s %d",hrt.name, &hrt.time);
    enqueue(hrt);
    i++;
  }
  while(head!=tail){//headとtailが同じの場所のとき終了
    hrt = dequeue();//hrtには先頭の値
    if(hrt.time <= q){//timeが 0 になったもの
      timecount += hrt.time;
      printf("%s %d\n",hrt.name,timecount);
    }
    else{ //残りのtime
      timecount += q;//timeを足す
      hrt.time -= q;//実行したtime分減らす
      enqueue(hrt);//一番後ろに格納
    }
  }
  return 0;
}


void initialize(void){//headとtailの初期化
  head = tail = 0;
}

int isEmpty(void){ //headとtailが同じなら中身は空
  return head == tail;
}

/*int isFull(void){//中身がいっぱい
  return head == (tail+1)%MAX;
  }*/

void enqueue(Array x){
  /* if(isFull()){
    printf("Error1\n");
    exit(1);
    }*/
  array[tail] = x;
  if(tail + 1 == LEN+1){
    tail = 0;
  }
  else{
    tail++;
  }
}

Array dequeue(void){
  Array x;

  if(isEmpty()){
      printf("Error2\n");
      exit(2);
    }
  x = array[head];
  if(head + 1 == LEN+1){
    head = 0;
  }
  else{
    head++;
  }
  return x;//先頭の中身を返す
}

Measured memory_bytes: 10756
#include <algorithm>
#include <array>
#include <functional>
#include <iomanip>
#include <iostream>
#include <limits>
#include <map>
#include <math.h>
#include <queue>
#include <set>
#include <stack>
#include <stdlib.h>
#include <string.h>
#include <string>
#include <vector>

using namespace std;

typedef long long ll;
const ll INF = 1e9;
const ll MOD = 1e9 + 7;
#define rep(i, n) for (int i = 0; i < (n); i++)
#define loop(i, a, n) for (int i = a; i < (n); i++)
#define all(in) in.begin(), in.end()
#define vint vector<int>

int main() {
    int ans = 0;
    int index = 0;
    int N;
    cin >> N;
    for (int i = 1; i <= N; i++) {
        int count = 0;
        int r = i;
        while (r % 2 == 0) {
            count++;
            r = r / 2;
        }
        if (count >= ans) {
            index = i;
            ans = max(ans, count);
        }
    }
    cout << index << endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define fi first
#define se second
#define pii pair<int,int>
#define mp make_pair
#define pb push_back
#define space putchar(' ')
#define enter putchar('\n')
#define eps 1e-10
#define MAXN 100005
//#define ivorysi
using namespace std;
typedef long long int64;
typedef unsigned int u32;
typedef double db;
template<class T>
void read(T &res) {
    res = 0;T f = 1;char c = getchar();
    while(c < '0' || c > '9') {
	if(c == '-') f = -1;
	   c = getchar();
    }
    while(c >= '0' && c <= '9') {
    	res = res * 10 +c - '0';
    	c = getchar();
    }
    res *= f;
}
template<class T>
void out(T x) {
    if(x < 0) {x = -x;putchar('-');}
    if(x >= 10) {
    	out(x / 10);
    }
    putchar('0' + x % 10);
}
int N;
int64 T,A;
int64 gcd(int64 a,int64 b) {
    return b == 0 ? a : gcd(b,a % b);
}
void Solve() {
    read(N);
    int64 t = 1,a = 1;
    for(int i = 1 ; i <= N ; ++i) {
        read(T);read(A);
        int64 k = (t - 1) / T + 1,h = (a - 1) / A + 1;
        k = max(k,h);
        t = k * T,a = k * A;
    }
    out(a + t);enter;
}
int main() {
#ifdef ivorysi
    freopen("f1.in","r",stdin);
#endif
    Solve();
    return 0;
}


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

#define  ll long long
#define  il inline
#define INF 0x3f3f3f3f
#define pii pair<int,int>
#define rep(i,a,b) for(int i=(a);i<=(b);++i)
#define dep(i,a,b) for(int i=(a);i>=(b);--i)

const int mod = 1e9 + 7;
const int maxn = 1e6 + 5;
const int maxm = 2e5 + 10;
const double PI = acos(-1.0);

int n,m;
string s,t;

int main()
{
    ios::sync_with_stdio(false);cin.tie(0);
   	cin >> n >> m;
   	rep(i,0,20){
   		if(m <= n * i - i + 1) {
   			cout << i << endl;
   			break;
   		}
   	}
    return 0;
}

Measured memory_bytes: 256
MOD = int(1e9) + 7


def countup(N, s):
    dp = [0] * (s+1)
    dp[s] = 1
    for _ in range(N):
        for i in range(s):
            dp[i] = sum(dp[i:s+1]) % MOD
    return dp[0]


def main():
    N, M = map(int, input().split())
    F = {}
    i = 2
    while M > 1:
        while M % i == 0:
            if i not in F:
                F[i] = 0
            F[i] += 1
            M //= i
        i += 1
    retval = 1
    for i in F:
        retval *= countup(N, F[i])
        retval %= MOD
    print(retval)


if __name__ == "__main__":
    main()


Measured memory_bytes: 41836
#include<cstdio>
int main(void){
	long long a[300][300];
	int n;
	int x = 0;
	int z = 0;
	long long s = 0;
	scanf("%d", &n);
	for (int i = 0; i < n; i++){
		for (int j = 0; j < n; j++){
			scanf("%lld", &a[i][j]);
		}
	}
	for (int i = 0; i < n; i++){
		for (int j = i + 1; j < n; j++){
			z = 0;
			for (int k = 0; k < n; k++){
				if (i != k&&j != k){
					if (a[i][k] + a[k][j] < a[i][j])x = -1;
					if (a[i][k] + a[k][j] == a[i][j])z = 1;
				}
			}
			if (z == 0)s = s + a[i][j];
		}
	}
	if (x == 0)printf("%lld\n", s);
	else printf("-1\n");
	return 0;
}

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

int main(){
    int a,b,x;cin >> a >> b >> x;
    if (a > x) {
        cout << "NO" << endl;
        return 0;
    }

    if ((x-a) <= b) {
        cout << "YES" << endl;
        return 0;
    }

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

Measured memory_bytes: 256
#include <stdio.h>
#include <stdlib.h>
#include <algorithm>
#include <iostream>
#include <map>
#include <numeric>
#include <set>
#include <sstream>
#include <string>
#include <vector>
#include <cmath>
using namespace std;

#define FOR(i,s,e) for (int i = int(s); i != int(e); i++)
#define REP(i,e) for (int i = 0; i != int(e); i++)
#define FORIT(i, A) for (auto i : A)
#define ISEQ(c) (c).begin(), (c).end()
#define PRINT(x) cout << (x) << endl
#define SZ(x) ((int)(x).size())

int main(int argc, char const *argv[])
{
	long a, b;
	while(scanf("%ld %ld", &a, &b) != EOF)
	{
		long x,y;
		if (a > b)
		{
			x = a;
			y = b;
		}
		else
		{
			x = b;
			y = a;
		}
		while(x != y)
		{
			long tmp = x - y;
			x = tmp > y ? tmp : y;
			y = tmp > y ? y : tmp;
		}
		long l = a/x * b;
		printf("%ld %ld\n", x, l);
	}
	return 0;
}

Measured memory_bytes: 3192
#include <stdio.h>

int main(){

    int D, T, S;

    scanf("%d", &D);
    scanf("%d", &T);
    scanf("%d", &S);

    double minute;

    minute = (double) D/S;

    if(T>=minute){
        printf("Yes\n");
    }else{
        printf("No\n");
    }

    return 0;
}

Measured memory_bytes: 2092
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <stack>
#include <queue>
#include <cmath>
#include <tuple>
#include <cstdio>
#include <bitset>
#include <sstream>
#include <iterator>
#include <numeric>
#include <map>

using namespace std;

//#define DEBUG_ //!!提出時にコメントアウト!!
#ifdef DEBUG_
	#define dump(x)  cerr << #x << " = " << (x) << endl;
#else
	#define dump(x)  ; //何もしない文
#endif

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)
#define SZ(x) ((int)(x).size()) //unsignedのサイズをint型に変換

typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef long long LL; 

template <typename T>
std::string printVector(const std::vector<T> &data)
{
    std::stringstream ss;
    std::ostream_iterator<T> out_it(ss, ", ");
    ss << "[";
    std::copy(data.begin(), data.end() - 1, out_it);
    ss << data.back() << "]";
    return ss.str();
}

vector<pair<long long, long long> > prime_factorize(long long n) {
    vector<pair<long long, long long> > res;
    for (long long p = 2; p * p <= n; ++p) {
        if (n % p != 0) continue;
        int num = 0;
        while (n % p == 0) { ++num; n /= p; }
        res.push_back(make_pair(p, num));
    }
    if (n != 1) res.push_back(make_pair(n, 1));
    return res;
}    


const int MOD = 1e9+7;

//ここから書き始める
int main(int argc, char const *argv[])
{
    cin.tie(0);
    ios::sync_with_stdio(false);	
    int N;
    cin >> N;
    map<int, int> prime_division;
    LL dp[101][101];
    REP(i,101)
    {
        REP(j,101)
        {
            dp[i][j] = 0;
        }
    }

    vector<int> div75 = {1,3,5,15,25,75};

    FOR(i,2,N+1)
    {
        auto res = prime_factorize(i);
        for(auto e : res)
        {
            prime_division[e.first] += e.second;
        }

    }

    VI nums;
    for(auto e : prime_division) nums.push_back(e.second);
    int len = nums.size();

    dp[0][1] = 1;

    for(int i=0; i < len; i++)
    {
        for(auto d1 : div75)
        {
            dump(d1)
            for(auto d2 : div75)
            {
                dump(d2)
                if(d1 * d2 <= 75 && nums[i]+1 >= d2)
                {
                    dp[i+1][d1*d2] += dp[i][d1];

                    dump(dp[i][d1])
                    dump(dp[i+1][d1*d2])
                }
            }
        }

    }
    cout << dp[len][75] << endl;

}


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

typedef long long ll;
typedef pair<ll, ll> P;
typedef vector<int> VI;
typedef vector<VI> VVI;
const double EPS = 1e-12;
const int INF = numeric_limits<int>::max() / 2;
const int NEG_INF = numeric_limits<int>::min() / 2;
const int MOD = 1e9 + 7;

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

    int n,k;cin>>n>>k;
	vector<ll> a(n);
	ll sum=0;
	for(int i=0;i<n;i++){
		cin>>a[i];
		if(a[i]>0) sum+=a[i];
	}
	ll htmp=0,stmp=0;
	for(int i=0;i<k;i++){
		if(a[i]>0) stmp+=a[i];
		else htmp+=a[i];
	}
	ll hu=htmp,sei=stmp; // hu:= 負の数の和の最大　sei:= 正の数の和の最小
	for(int i=1;i+k<=n;i++){
		if(a[i-1]>0) stmp-=a[i-1];
		else htmp-=a[i-1];

		if(a[i+k-1]>0) stmp+=a[i+k-1];
		else htmp += a[i+k-1];

		hu=max(hu,htmp);
		sei=min(sei,stmp);
	}
	cout<<max(sum-sei,sum+hu)<<endl;
}


Measured memory_bytes: 1024
using System;
using System.Linq;

namespace ConsoleApp1
{
	class Program
	{
		static void Main(string[] a_asArgs)
		{
			int[] l_aiInput = Console.ReadLine().Split(' ').Select(l_sItem => int.Parse(l_sItem)).ToArray();
			int l_iH = l_aiInput[0];
			int l_iW = l_aiInput[1];
			int l_iK = l_aiInput[2];

			if (l_iW == 1)
			{
				Console.WriteLine("1");
				return;
			}

			byte[][] l_aaiPattern = new byte[][] {
				new byte[] { 0x00, 0x01 },
				new byte[] { 0x02 },
				new byte[] { 0x04, 0x05 },
				new byte[] { 0x08, 0x09, 0x0a },
				new byte[] { 0x10, 0x11, 0x12, 0x14, 0x15 },
				new byte[] { 0x20, 0x21, 0x22, 0x24, 0x25, 0x28, 0x29, 0x2a },
				new byte[] { 0x40, 0x41, 0x42, 0x44, 0x45, 0x48, 0x49, 0x4a, 0x50, 0x51, 0x52, 0x54, 0x55 }
			};

			uint[] l_aiUpper = new uint[l_iW];
			uint[] l_aiLower = new uint[l_iW];
			l_aiUpper[0] = 1;

			for (int l_iY = 0; l_iY < l_iH; l_iY++)
			{
				for (int l_iPatternIndex = 0; l_iPatternIndex < l_iW - 1; l_iPatternIndex++)
				{
					foreach (byte l_iPattern in l_aaiPattern[l_iPatternIndex])
					{
						for (int l_iX = 0; l_iX < l_iW; l_iX++)
						{
							if (l_iX > 0 && (l_iPattern & (1 << l_iX - 1)) != 0)
							{
								l_aiLower[l_iX] += l_aiUpper[l_iX - 1];
							}
							else if (l_iX < l_iW - 1 && (l_iPattern & (1 << l_iX)) != 0)
							{
								l_aiLower[l_iX] += l_aiUpper[l_iX + 1];
							}
							else
							{
								l_aiLower[l_iX] += l_aiUpper[l_iX];
							}
							l_aiLower[l_iX] %= 1000000007;
						}
					}
				}
				l_aiLower.CopyTo(l_aiUpper, 0);
				Array.Clear(l_aiLower, 0, l_iW);
			}
			Console.WriteLine(l_aiUpper[l_iK - 1]);
		}
	}
}


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

#define REP( i, n )     for( int (i) = 0; (i) < (n); (i)++ )
#define ALL( a )        (a).begin(), (a).end()

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

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( a > b ) { a = b; return 1; } return 0; }

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

int main(){
    int a, b, c, d; cin >> a >> b >> c >> d;
    if( a != c ) cout << 1 << endl;
    else cout << 0 << endl;
}

/*
38

*/

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

int main() {
	// your code goes here
int a,b,x,l,l1,d;
cin>>x;
cin>>a;
cin>>b;
l1=x-a;
d=l1%b;
//l=l1-(d*b);
cout<<d;
	return 0;
}

Measured memory_bytes: 256
//sobskdrbhvk
//remember the flying, the bird dies ):(
#include <bits/stdc++.h>

using namespace std;

typedef long long int LL;
typedef pair<int, int> pii;
typedef pair<LL, LL> pll;

#define PB push_back
#define MP make_pair
#define L first
#define R second
#define sz(x) ((int)(x).size())
#define smax(x, y) ((x) = max((x), (y)))
#define smin(x, y) ((x) = min((x), (y)))
#define all(x) x.begin(),x.end()

const int maxn = 2e4 + 85 - 69;
int a[maxn],
	b[maxn],
	p[maxn],
	n;

int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	cin >> n;
	for(int i = 1; i <= n; i++)
		cin >> p[i];
	for(int i = 1; i <= n; i++){
		a[p[i]] = (n - p[i]) * 20010 + i;
		b[p[i]] = (p[i] - 1) * 20010 + i;
	}
	for(int i = 1; i <= n; i++)
		cout << b[i] << ' ';
	cout << '\n';
	for(int i = 1; i <= n; i++)
		cout << a[i] << ' ';
	cout << '\n';
	return 0;
}

Measured memory_bytes: 896
//include
//------------------------------------------
#include <bits/stdc++.h>
using namespace std;
//conversion
//------------------------------------------
inline int toInt(string s) {int v; istringstream sin(s);sin>>v;return v;}
template<class T> inline string toString(T x) {ostringstream sout;sout<<x;return sout.str();}
//math
//-------------------------------------------
template<class T> inline T sqr(T x) {return x*x;}
//typedef
//------------------------------------------
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> P;
typedef long long ll;
//container util
//------------------------------------------
#define ALL(a)  (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define MP make_pair
#define SZ(a) int((a).size())
#define EACH(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort((c).begin(),(c).end())
//repetition
//------------------------------------------
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)
//constant
//--------------------------------------------
const double EPS = 1e-10;
const double PI  = acos(-1.0);
const long long INF = 1000000007;
//clear memory
#define CLR(a) memset((a), 0 ,sizeof(a))
//debug
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;
// chmax chmin
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; }

int main(void){
    int N; cin >> N;
    int T[N]; REP(i,N) cin >> T[i];
    int M; cin >> M;
    int P[M], X[M]; REP(i,M) cin >> P[i] >> X[i];
    REP(i,M){
        int ans=0;
        REP(j,N){
            if(j==P[i]-1) ans += X[i];
            else ans += T[j];
        }
        cout << ans << endl;
    }
    return 0;
}

Measured memory_bytes: 256
s = input()
a = ["A", "G", "C", "T"]
ma = 0
for i in range(len(s)):
    if s[i] in a:
        cnt = 1
        ma = max(ma, cnt)
        for j in range(i+1, len(s)):
            if s[j] in a:
                cnt += 1
                ma = max(ma, cnt)
            else:
                break
print(ma)


Measured memory_bytes: 2940
#include <bits/stdc++.h>
typedef long long ll;
using namespace std;
ll a7=1000000007;
ll inf=1000000000000000;
#define rep(i,l,r) for(ll i=l;i<=r;i++)

ll min(ll a,ll b){
    if(a<b)return a;
    return b;
}
ll max(ll a,ll b){
    if(a>b)return a;
    return b;
}

int main(){
    ll h,w;cin>>h>>w;
    string s[h];
    rep(i,0,h-1){
        cin>>s[i];
    }
    ll seen[h][w];
    ll ans=0;
    queue<pair<ll,ll>> q;
    pair<ll,ll> p;
    rep(i,0,h-1){
        rep(j,0,w-1){
            seen[i][j]=inf;
            if(s[i][j]=='#'){
                seen[i][j]=0;
                q.push(make_pair(i,j));
            }
        }
    }
    ll x,y;
    while(q.size()>0){
        p=q.front();
        q.pop();
        y=p.first;
        x=p.second;
        ans=max(ans,seen[y][x]);
        if(y+1<h){
            if(s[y+1][x]=='.'){
                if(seen[y+1][x]>seen[y][x]+1){
                    seen[y+1][x]=seen[y][x]+1;
                    q.push(make_pair(y+1,x));
                }
            }
        }
        if(y-1>=0){
            if(s[y-1][x]=='.'){
                if(seen[y-1][x]>seen[y][x]+1){
                    seen[y-1][x]=seen[y][x]+1;
                    q.push(make_pair(y-1,x));
                }
            }
        }
        if(x+1<w){
            if(s[y][x+1]=='.'){
                if(seen[y][x+1]>seen[y][x]+1){
                    seen[y][x+1]=seen[y][x]+1;
                    q.push(make_pair(y,x+1));
                }
            }
        }
        if(x-1>=0){
            if(s[y][x-1]=='.'){
                if(seen[y][x-1]>seen[y][x]+1){
                    seen[y][x-1]=seen[y][x]+1;
                    q.push(make_pair(y,x-1));
                }
            }
        }
    }
    /*
    rep(i,0,h-1){
        rep(j,0,w-1){
            cout<<seen[i][j];
        }
        cout<<endl;
    }
    */
    cout<<ans<<endl;
    
    return 0;
}


Measured memory_bytes: 25524
//#include<bits/stdc++.h>
#include <iostream>
#include <cstdio>
#include <cstring>
#include <string>
#include <vector>
#include <queue>
#include <map>
#include <algorithm>
#include <utility>
#include <climits>
#define REP(i, n) for(int i = 0; i < n; ++i)
#define FOR(i, a, b) for(int i = a; i < b; ++i)
#define F first
#define S second
#define OUT(x) cout << x << "\n"
using namespace std;
using point = pair< int,int >;
using ll = long long;

int main() {
    ll l, r;
    cin >> l >> r;

    ll minv = INT_MAX;
    for (ll i = l; i <= r && i < l + 2019; ++i) {
        for (ll j = i + 1; j <= r && j < l + 2019; ++j) {
            minv = min(minv, (i * j) % 2019);
        }
    }

    OUT(minv);
    return 0;
}



Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <algorithm>
#include <queue>
#include <vector>
#include <cstdio>
#include <cmath>
#include <cctype>
#define rep(i,a,b) for(int i=(a);i<b;i++)
#define INF 1000000000
#define MAX_N 105
using namespace std;
bool debug=false;

int main(){
  bool ok=false;
  int a,b,c;
  cin>>a>>b>>c;
  if(a==5&&b==5&&c==7)ok=true;
  if(a==5&&b==7&&c==5)ok=true;
  if(a==7&&b==5&&c==5)ok=true;
  if(ok)cout<<"YES"<<endl;
  else cout<<"NO"<<endl;
  return 0;
}


Measured memory_bytes: 256
import sys
# input = sys.stdin.buffer.readline
def getN():
    return int(input())
def getNM():
    return map(int, input().split())
def getlist():
    return list(map(int, input().split()))
import math
import heapq
import fractions
from collections import defaultdict, Counter, deque
MOD = 10**9 + 7
INF = 10**15

def getyaku(n):
    res = []
    for i in range(1, int(math.sqrt(n)) + 1):
        if n % i == 0:
            res.append(i)
            res.append(n // i)

    return(sorted(list(set(res))))

def factorization(n):
    arr = []
    temp = n
    for i in range(2, int(-(-n**0.5//1))+1):
        if temp%i==0:
            cnt=0
            while temp%i==0:
                cnt+=1
                temp //= i
            arr.append([i, cnt])

    if temp!=1:
        arr.append([temp, 1])

    if arr==[]:
        arr.append([n, 1])

    return arr

def main():
    n,m = getlist()
    wa = [0 for i in range(n)]
    ac = [0 for i in range(n)]
    ansa = 0
    ansp = 0
    for i in range(m):
        p, s = input().split()
        p = int(p) -1
        if s == "AC":
            if not ac[p]:
                ansa += 1
                ansp += wa[p]
                ac[p] = 1
        else:
            wa[p] += 1

    print(ansa, ansp)

    return

if __name__ == '__main__':
    main()

"""
9999
3

2916
"""

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

typedef long long int lli;
typedef pair<int, int> ii;
typedef vector<int> vi;

const int N = 10;
const int D = 10;

int n, d;

int pt[N][D];

lli getDistSquare(int i, int j) {
	lli ans = 0;
	for(int k=0; k<d; k++) {
		ans += (pt[i][k]-pt[j][k])*(pt[i][k]-pt[j][k]);
	}
	return ans;
}

bool checker(int i, int j) {
	int base = getDistSquare(i, j);

	return ((int)sqrt(base)*(int)sqrt(base) == base);
}

int main() {
	ios_base::sync_with_stdio(false);

	cin >> n >> d;

	for(int i = 0; i < n; i++) for(int j=0; j<d; j++) cin >> pt[i][j];

	int ans = 0;
	for(int i = 0; i < n; i++) for(int j = i+1; j<n; j++) if(checker(i, j)) ans++;

	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main()
{
    long long n,test;
    cin>>n;
    long long a[n],all[n+5]={0};
    for(int i=0;i<n;i++)
    {
        cin>>test;
        a[i] = test;
        all[test]++;
    }
    long long sum=0;
    for(int j=1;j<=n;j++)
    {
        sum+=(all[j]*(all[j]-1))/2;
    }
    for(int i=0;i<n;i++)
    {
        cout<<sum-all[a[i]]+1<<endl;
    }
}


Measured memory_bytes: 5760
#include <bits/stdc++.h>
#define FOR(i, l, r) for(int i = (int)l; i <= (int)r; ++i)
#define REP(i, r) for(int i = (int)0; i < (int)r; ++i)
#define X first
#define Y second

using namespace std;
typedef long long ll;
typedef pair<ll, ll> ii;
const int Nmax = 112;

ll n, W;
ll ps[5][Nmax];
ii a[Nmax];
vector<ll> b[5];
ll ans;

int main() {
    ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    cin >> n >> W;
    FOR(i, 1, n) {
        cin >> a[i].X >> a[i].Y;
    }
    FOR(i, 1, n) {
        b[a[i].X - a[1].X].push_back(a[i].Y);
    }
    FOR(i, 0, 3) {
        sort(b[i].begin(), b[i].end(), greater<int>());
        FOR(j, 1, b[i].size()) {
            ps[i][j] = ps[i][j - 1] + b[i][j - 1];
        }
    }
    REP(i, b[0].size() + 1) REP(j, b[1].size() + 1) REP(k, b[2].size() + 1) REP(l, b[3].size() + 1) {
        if (i * a[1].X + j * (a[1].X + 1) + k * (a[1].X + 2) + l * (a[1].X + 3) <= W) {
            ans = max(ans, ps[0][i] + ps[1][j] + ps[2][k] + ps[3][l]);
        }
    }
    cout << ans;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define ll long long
#define ull unsigned long long
#define ld long double
#define rep(i,a,n) for (ll i=a;i<n;i++)
#define per(i,a,n) for (ll i=n-1;i>=a;i--)
#define all(x) (x).begin(),(x).end()
#define sz(x) (ll)x.size()
#define pb push_back


///Input/Output macros!
#define gi(x) scanf("%d", &x)
#define gi2(x, y) scanf("%d%d", &x, &y)
#define gi3(x, y, z) scanf("%d%d%d", &x, &y, &z)
#define gill(x) scanf("%lld", &x)
#define gill2(x, y) scanf("%lld%lld", &x, &y)
#define gill3(x, y, z) scanf("%lld%lld%lld", &x, &y, &z)
#define pi(x) printf("%d\n", x)
#define pill(x) printf("%lld\n", x)


///Basic Debugging macros!
#define printVar(n) cout<<#n<<": "<<n<<endl
#define printArr(a,l) cout<<#a<<": ";for(ll __i__=0;__i__<l;__i__++){cout<<a[__i__]<<" ";}cout<<endl
#define print2dArr(a,r,c) cout<<#a<<":\n";for(ll __i__=0;__i__<r;__i__++){for(ll __j__=0;__j__<c;__j__++){cout<<a[__i__][__j__]<<" ";}cout<<endl;}

using namespace std;

///Power of 2 till 2^31!
ll pow2[32] = {1,2,4,8,16,32,64,128,256,512,1024,2048,4096,8192,16384,32768,65536,131072,262144,524288,1048576,2097152,4194304,8388608,16777216,33554432,67108864,134217728,268435456,536870912,1073741824,2147483648};

///Power function!
ll power(ll x,ll y)
{
        ll res = 1;
        while(y>0){
            if(y&1)
                res *= x;
            y>>=1;
            x*=x;
        }
        return res;
}
map<ll,ll> mp;
///Basic Sieve of Eratosthenes!
void Sieve(ll n)
{
    bool prime[n+1];
    memset(prime, true, sizeof(prime));
    for (ll p=2; p*p<=n; p++)
    {
        if (prime[p] == true)
        {
            for (ll i=p*p; i<=n; i += p)
                prime[i] = false;
        }
    }
    for (ll p=2; p<=n; p++)
       if (prime[p])
        ++mp[p];
          //cout << p << " ";
}

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

bool isPerfectSquare(ll x){ ll s = sqrt(x); return (s*s == x);}

bool isFibonacci(int n){return isPerfectSquare(5*n*n + 4) || isPerfectSquare(5*n*n - 4);}

bool isPrime(int n){if (n <= 1)return false;if (n <= 3)  return true;
    if (n%2 == 0 || n%3 == 0) return false;
    for (int i=5; i*i<=n; i=i+6) if (n%i == 0 || n%(i+2) == 0)return false;
    return true;
}

typedef vector<int> vi;
typedef vector<ld> vd;
typedef vector<ll> vl;


const int MOD = 1000000007;
const long double PI = 4*atan((long double)1);
const ll INF = 1e18;

int main()
{
    ios::sync_with_stdio(false);
    ll n;
    cin>>n;
    ll ans = 0;
    if(n%2==0)
    for(ll i=10;n/i>=1;i*=5) ans += (n/i);
    cout<<ans<<'\n';
    return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<utility>
#include<tuple>
#include<map>
#include<queue>
#include<set>
#include<stack>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>

using namespace std;

using ll = long long;
using pii = pair<int, int>;
using pll = pair<ll, ll>;

#define BIL ((ll)1e9)
#define MOD ((ll)1e9+7)
#define INF (1LL<<60)           //1LL<<63でオーバーフロー

int main(int argc,char* argv[]){
    string s;
    cin >> s;

    if(s[0]==s[1] && s[1]==s[2] && s[0]=='R')
        cout << 3 << endl;
    else if(s[0]==s[1] && s[0]=='R')
        cout << 2 << endl;
    else if(s[2]==s[1] && s[1]=='R')
        cout << 2 << endl;
    else if(s[0]=='R' || s[1]=='R' || s[2]=='R')
        cout << 1 << endl;
    else
        cout << 0 << endl;

    return 0;
}


Measured memory_bytes: 3624
// includes
#include <cstdio>
#include <cstdint>
#include <iostream>
#include <iomanip>
#include <string>
#include <queue>
#include <stack>
#include <vector>
#include <set>
#include <map>
#include <unordered_map>
#include <algorithm>
#include <utility>
#include <functional>
#include <cmath>
#include <climits>
#include <bitset>

// macros
#define ll long long int
#define pb push_back
#define mk make_pair
#define pq priority_queue
#define FOR(i, a, b) for(int i=(a); i<(b);++i)
#define rep(i, n) FOR(i, 0, n)

using namespace std;

//  types
typedef pair<int, int> P;
typedef pair<ll, int> Pl;
typedef pair<ll, ll> Pll;
 
// constants
const int inf = 1e9;
const ll linf = 1LL << 50;
const double EPS = 1e-10;

// solve
ll calc(ll d){
  ll res = 0.0;
  int x = d;
  while(x < 600){
    res += x * x;
    x += d;
  }
  return res * d;
}

int main(int argc, char const* argv[])
{
  int d;
  while(cin >> d){
    cout << calc(d) << endl;
  }
	return 0;
}



Measured memory_bytes: 3084
/**
 *   created: 20 August 2019  11:36:13
**/
#include<bits/stdc++.h>
using namespace std;

typedef vector<int> vi;
typedef pair<int , int> pii;
typedef vector< pair<int , int> > vii;
typedef long long ll;
typedef vector<long long> vl;
typedef pair<long long , long long> pll;
typedef vector< pair<long long , long long> > vll;

#define PB push_back
#define PPB pop_back
#define all(c) c.begin(),c.end()
#define rep(i,a,b) for(int i = (int)(a); i < (int)(b); i++)
#define rrep(i,a,b) for(int i = (int)(a-1); i>=(int)(b); i--)
#define INFLL 2000000000000000007
#define INF 2000000007
#define MOD 1000000007


#define TRACE

#ifdef TRACE
#define trace1(x)                cerr << #x << ": " << x << endl;
#define trace2(x, y)             cerr << #x << ": " << x << " | " << #y << ": " << y << endl;
#define trace3(x, y, z)          cerr << #x << ": " << x << " | " << #y << ": " << y << " | " << #z << ": " << z << endl;
#define trace4(a, b, c, d)       cerr << #a << ": " << a << " | " << #b << ": " << b << " | " << #c << ": " << c << " | " << #d << ": " << d << endl;
#define trace5(a, b, c, d, e)    cerr << #a << ": " << a << " | " << #b << ": " << b << " | " << #c << ": " << c << " | " << #d << ": " << d << " | " << #e << ": " << e << endl;
#define trace6(a, b, c, d, e, f) cerr << #a << ": " << a << " | " << #b << ": " << b << " | " << #c << ": " << c << " | " << #d << ": " << d << " | " << #e << ": " << e << " | " << #f << ": " << f << endl;

#else

#define trace1(x)
#define trace2(x, y)
#define trace3(x, y, z)
#define trace4(a, b, c, d)
#define trace5(a, b, c, d, e)
#define trace6(a, b, c, d, e, f)

#endif


void optimizeIO()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
}

//                                        //AUTHOR: Kaushalesh Shukla

//=========================================================================================================
vector< vector<int> > adj;
vi deg;
vi mem;
int dfs(int node){
	// trace1(node);
	if(mem[node]!=-1)
		return mem[node];
	int temp =0;
	for(int x:adj[node]){
		// trace1(x);
		temp = max(temp,dfs(x));
	}
	return mem[node]=temp+1;
}
int main()
{
	optimizeIO();
	int tt=1;
	//cin>>tt;
	while(tt--){
		int n,m;
		cin>>n>>m;
		adj.resize(n+1);
		deg.resize(n+1);
		mem.resize(n+1,-1);
		while(m--){
			int x,y;
			cin>>x>>y;
			deg[y]++;
			adj[x].push_back(y);
		}
		int res = 0;
		rep(i,1,n+1){
			if(deg[i]==0)
				res = max(res, dfs(i));
		}
		cout<<res-1;
	}
	return 0;
}


Measured memory_bytes: 11264
#include<stdio.h>
#include<stdlib.h>
#include<math.h>
#include<iostream>
#include<string>
#include<algorithm>
#include<queue>
#include<utility>

using namespace std;

int n;

bool judge(int num)
{
	int cnt = 0;

	for (int i = 2; i < num;i++)
	{
		if (num%i==0)
		{
			cnt = 1;

			return false;
		}
	}

	return true;


}

int main(void)
{
	while (cin >> n, n)
	{
		for (int i = n; i > 2;i--)
		{
			if (judge(i)&&judge(i-2))
			{
				cout << i - 2 << " " << i << endl;
				break;
			}
		}

	}


	return 0;
}


Measured memory_bytes: 3096
import itertools

N,A,B,C = list(map(int,input().split()))
l = [int(input()) for i in range(N)]

bamboo = [0,A,B,C]
bit = [0,1,2,3]
ans = int(10e10)
for seq in itertools.product(bit,repeat=N):
  data = [[] for i in range(4)]
  for j in range(N):
    data[seq[j]].append(l[j])
  else:
    for i in range(1,4):
      if len(data[i]) == 0:
        break
    else:
      tmp = 0
      for i in range(1,4):
        tmp += max(0,(len(data[i])-1))*10 + abs(sum(data[i])-bamboo[i])
      else:
        ans = min(ans,tmp)
print(ans)

Measured memory_bytes: 3064
import java.util.*;
import java.lang.*;
import java.io.*;

class Main{


      public static void main(String args[])throws IOException
    {
	BufferedReader in = new BufferedReader(new InputStreamReader(System.in));

       

	while(true)
	    {

		double R = Double.parseDouble(in.readLine());	
		
		if(R == 0.0)
		    break;	

		double denominator,numerator;
		denominator = numerator = 1.0;

		while(Math.abs(Math.PI - numerator/denominator) > R)
		    {
		
			if(numerator/denominator >=  Math.PI)
			    {
				numerator = 1.0;
				denominator++;
			    }
			else
			    {
				numerator++;	
			    }
		    }
		System.out.println((int)numerator + "/" + (int)denominator);
	    }

    }
    
}

Measured memory_bytes: 9700
import std.stdio, std.algorithm, std.conv, std.array, std.string;

void main()
{
    long[long][101] TABLE;

    auto nw = readln.chomp.split(" ");
    auto N = nw[0].to!int;
    auto W = nw[1].to!long;

    long[101] ws;
    long[101] vs;
    foreach (i; 0..N) {
        auto wv = readln.chomp.split(" ").map!(to!long);
        ws[i] = wv[0];
        vs[i] = wv[1];
    }

    long solve(int i, long v_sp) {
        if (v_sp in TABLE[i]) return TABLE[i][v_sp];

        long ret;
        if (i == N) {
            ret = 0;
        } else if (v_sp < ws[i]) {
            ret = solve(i+1, v_sp);
        } else {
            ret = max(solve(i+1, v_sp), solve(i+1, v_sp - ws[i]) + vs[i]);
        }

        return TABLE[i][v_sp] = ret;
    }

    writeln(solve(0, W));
}

Measured memory_bytes: 8956
#include <bits/stdc++.h>
//make_tuple emplace_back next_permutation push_back make_pair second first setprecision


#if MYDEBUG
#include "lib/cp_debug.hpp"
#else
#define DBG(...) ;
#endif

using LL = long long;
constexpr LL LINF=334ll<<53;
constexpr int INF=15<<26;
constexpr LL  MOD=1E9+7;

namespace Problem{
using namespace std;
class Writer{
static ostringstream oss;
public:template<class T> void appendln(const vector<vector<T>> &ans,string spl=" ", string el="\n"){for(int i=0; i<(int)ans.size(); ++i){for(int j=0; j<(int)ans[i].size(); ++j){oss << ans[i][j];oss << (j==(int)ans[i].size()-1?el:spl);}}}
    template<class T> void appendln(const vector<T>& ans, string spl=" "){for(int i=0; i<(int)ans.size(); ++i){oss << ans[i] << (i==(int)ans.size()-1?"\n":spl);}}
    template<class T> void appendln(const T& answer){oss << answer << "\n";}
    template<class T> void append(const T& answer){oss << answer;}
    void appends(const string spl){oss.seekp((int)oss.tellp()-1);oss<<"\n";}
    template<class F, class... R>void appends(const string spl,const F& fi, const R&... rest){oss << fi << spl; appends(spl, rest...);}
    static void write(){cout << oss.str();}
    Writer(){static bool is_single =true;assert(is_single);is_single=false;};
};ostringstream Writer::oss;


class Solver{
public:
    LL n,m;
    Solver(LL n, LL m):n(n),m(m){};

    void solve(){
        if(n>m)swap(n,m);
        if(n==1){
            LL ans;
            if(m==1) ans=1;
            else ans = m-2;
            cout << ans <<"\n";
        }else{
            cout << (n-2)*(m-2)<<"\n";
        }
    }
};
}

int main(){
    std::cin.tie(0);
    std::ios_base::sync_with_stdio(false);
    long long n=0,m;
    std::cin >> n>>m;
    Problem::Solver sol(n,m);
    sol.solve();
    Problem::Writer::write();
    return 0;
}



Measured memory_bytes: 256
#pragma GCC optimize("Ofast")
#include <set>
#include <map>
#include <cmath>
#include <stack>
#include <queue>
#include <vector>
#include <cstdio>
#include <cstdlib>
#include <iostream>
#include <algorithm>
#define endl '\n'
#define fast ios::sync_with_stdio(0),cin.tie(0),cout.tie(0)
#define zy 2333333
#define bql 2147483647
using namespace std;
int n,k;
int main()
{
	fast;
	cin>>n>>k;
	if (k==1)
	   cout<<0<<endl;
	else
	   cout<<n-k<<endl;
	return 0;
}


Measured memory_bytes: 256
#ifndef ___CLASS_MODINT
#define ___CLASS_MODINT

#include <cstdint>

template<std::uint32_t mod>
class modint {
private:
	std::uint32_t n;
public:
	modint() : n(0) {};
	modint(std::uint64_t n_) : n(n_ % mod) {};
	bool operator==(const modint& m) const { return n == m.n; }
	bool operator!=(const modint& m) const { return n != m.n; }
	std::uint32_t get() const { return n; }
	modint& operator+=(const modint& m) { n += m.n; n = (n < mod ? n : n - mod); return *this; }
	modint& operator-=(const modint& m) { n += mod - m.n; n = (n < mod ? n : n - mod); return *this; }
	modint& operator*=(const modint& m) { n = std::uint64_t(n) * m.n % mod; return *this; }
	modint operator+(const modint& m) const { return modint(*this) += m; }
	modint operator-(const modint& m) const { return modint(*this) -= m; }
	modint operator*(const modint& m) const { return modint(*this) *= m; }
	modint binpow(std::uint64_t b) const {
		modint ans = 1, m = modint(*this);
		while (b) {
			if (b & 1) ans *= m;
			m *= m;
			b >>= 1;
		}
		return ans;
	}
	modint inv() { return (*this).binpow(mod - 2); }
};

#endif // ___CLASS_MODINT

#include <vector>
#include <iostream>
#include <functional>
using namespace std;
const int mod = 1000000007;
using modulo = modint<mod>;
vector<modulo> convolve(vector<modulo> v1, vector<modulo> v2) {
	int s1 = v1.size(), s2 = v2.size();
	vector<modulo> ans(s1 + s2 - 1);
	for (int i = 0; i < s1; ++i) {
		for (int j = 0; j < s2; ++j) {
			ans[i + j] += v1[i] * v2[j];
		}
	}
	return ans;
}
modulo solve(int N, int A, int B, int C) {
	if (B % 2 == 1) return 0;
	B /= 2;
	vector<modulo> fact(N + 1), inv(N + 1), factinv(N + 1);
	fact[0] = 1; inv[1] = 1; factinv[0] = 1;
	for (int i = 1; i <= N; ++i) fact[i] = fact[i - 1] * i;
	for (int i = 2; i <= N; ++i) inv[i] = inv[mod % i] * (mod - mod / i);
	for (int i = 1; i <= N; ++i) factinv[i] = factinv[i - 1] * inv[i];
	function<modulo(int, int)> comb = [&](int a, int b) {
		if (a < b || b < 0) return modulo(0);
		return fact[a] * factinv[b] * factinv[a - b];
	};
	vector<modulo> poly1(A + 1), poly2(C + 1);
	for (int i = 0; i <= A; ++i) poly1[i] = comb(A, i);
	for (int i = 0; i <= C; ++i) poly2[i] = comb(B + i - 1, B - 1);
	if (B == 0) poly2[0] = 1;
	vector<modulo> ans = convolve(poly1, poly2);
	modulo res = 0;
	for (int i = C; i >= 0; i -= 3) {
		modulo mul = fact[A + B + (C - i) / 3] * factinv[A] * factinv[B] * factinv[(C - i) / 3];
		res += mul * ans[i];
	}
	return res;
}
int main() {
	int N, A, B, C;
	cin >> N >> A >> B >> C;
	modulo ans = solve(N, A, B, C);
	cout << ans.get() << endl;
	return 0;
}

Measured memory_bytes: 384
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int n,r=0,g=0,b=0,tem=0;
    cin>>n;
    string s;
    long long int ans=0;
    cin>>s;
    for(int i=0;i<n;i++)
    {
        if(s[i]=='R')
        {
            ans+=g*b;
            r++;
        }
        else if(s[i]=='G')
        {
            ans+=r*b;
            g++;
        }
        else
        {
            ans+=r*g;
            b++;
        }
    }
    for(int i=0;i<n-2;i++)
    {
        for(int j=i+2;j<n;j=j+2)
        {
            tem=(i+j)/2;
            if(s[i]!=s[j] && s[i]!=s[tem] && s[tem]!=s[j])
            ans--;
        }
    }
    cout<<ans;
}

Measured memory_bytes: 3632
#include <algorithm>
#include <bitset>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <ctime>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <utility>
#include <vector>
#include <tuple>

#define DEBUG(x) cout<<#x<<": "<<x<<endl

using namespace std;

int main(){

	string S;

	cin >> S;

	int ans = 0, t = 0;
	for(int i = 0; i < S.size(); i++){
		switch(S[i]){
			case 'A': 
			case 'C': 
			case 'G': 
			case 'T':
				t++;
				break;
			default:
				ans = max(ans, t);
				t = 0;
		}
	}
	ans = max(ans, t);
	cout << ans << endl;

	return 0;
}


Measured memory_bytes: 256
#include <stdio.h>

int main(void) {
	while(1){
		int n, i, j, a[10][10], vert[10]={0} , hori[10]={0}, sum=0;
		
		scanf("%d", &n);
		if(n==0) break;
		
		for(i=0; i<n; i++) {
			for(j=0; j<n; j++) {
				scanf(" %d", &a[i][j]);
				sum += a[i][j];
			}
		}
		
		for(i=0; i<n; i++) {
			for(j=0; j<n; j++) {
				vert[i] += a[j][i];
				hori[i] += a[i][j];
			}
		}
	
		for(i=0; i<n; i++) {
			for(j=0; j<n; j++) {
				printf("%5d", a[i][j]);
			}
			printf("%5d\n", hori[i]);
		}
		
		for(i=0; i<n; i++)
			printf("%5d", vert[i]);
		printf("%5d\n", sum);
	
	}

	return 0;
}

Measured memory_bytes: 612
#include <iostream>
#include <string>

using namespace std;

int main(){
  while(1){
    string in;
    getline(cin, in);
    if(in == "END OF INPUT") break;
    in += ' ';
    for(int i=0;i<in.size();i++){
      int cnt = 0;
      for(int j=i;j<in.size();j++){
	if(in[j] == ' '){
	  i = j;
	  break;
	}
	cnt++;
      }
      cout << cnt;
    }
    cout << endl;
  }
  return 0;
}

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

int main(){
  int N, M;
  cin >> N >> M;
  vector<int> a(M);
  vector<int> b(M);
  for (int i = 0; i < M; i++){
    cin >> a.at(i) >> b.at(i);
  }
  vector<int> road(N);
  for (int i = 0; i < N; i++){
    for (int j = 0; j < M; j++){
      if (a.at(j) == i + 1 || b.at(j) == i + 1) road.at(i) += 1;
    }
  }
  for (int i = 0; i < N; i++){
    cout << road.at(i) << endl;
  }
  
}

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

int main(){
    int N;
    cin>>N;
    string s;
    s = "No";
    for(int i=0;i<26;i++){
        for(int j=0;j<15;j++){
            int n = 4*i+7*j;
            if(n==N){
                s = "Yes";
            }
        }
    }
    cout<<s<<endl;
}

Measured memory_bytes: 3596
n = int(input())
a = []
b = []
for _ in range(n):
    p, q = map(int,input().split())
    a.append(p)
    b.append(q)

ans = 0

for i in range(n-1, -1, -1):
    if (a[i] + ans) % b[i] != 0:
        ans += b[i] - (a[i] + ans) % b[i]
    
print(ans)

Measured memory_bytes: 11052
#include"bits/stdc++.h"
#include<boost/multi_array.hpp>
#include<boost/optional.hpp>
#include<boost/range/irange.hpp>
#include<boost/range/algorithm.hpp>
#define rep(i,n) for (int i = 0; i < (n);i++)
typedef long long ll;
using namespace std;
/*#include<boost/range/adaptors.hpp>

namespace adaptor = boost::adaptors;*/


void Main()
{
	int n; cin>>n;
	vector<int> d(n); 
	rep(i,n) {
		cin>>d.at(i);
	}
	sort(d.begin(),d.end());
	cout<<d.at(n/2) - d.at(n/2 - 1) << endl;	
}


int main()
{
	cin.tie(nullptr);
	ios_base::sync_with_stdio(false);
	cout << fixed << setprecision(15);
	Main();
}

Measured memory_bytes: 640
#include <stdio.h>
#define MAX 1001
#define W 0
#define B 1
#define G 2
void DFS(int);
int n,d[MAX],f[MAX],g[MAX][MAX],cl[MAX],t=0;

int main(){
        int i,j,u,v,k;
        scanf("%d",&n);
        for(i=1; i <= n; i++) {
                for(j=1; j<= n; j++) {
                        g[i][j] = 0;
                }
        }
        for(i=1; i<= n; i++) {
                scanf("%d%d",&u,&k);
                for(j=0; j<k; j++) {
                        scanf("%d",&v);
                        g[u][v] = 1;
                }
        }
        for(i=1; i<=n; i++) {
                cl[i] = W;
        }
        for(i=1; i<=n; i++) {
                if(cl[i] == W) DFS(i);
        }
        for(i=1; i<=n; i++) {
                printf("%d ",i);
                printf("%d ",d[i]);
                printf("%d\n",f[i]);
        }
        return 0;
}

void DFS(int u){
        int v;
        cl[u] = G;
        t++;
        d[u] = t;
        v=0;
        while(v<=n) {
                ++v;

                //  printf("check\n");
                if((g[u][v] == 1)&& (cl[v] == W)) {
                        DFS(v);
                }
        }

        cl[u] = B;
        f[u]= ++t;
}

Measured memory_bytes: 992
#include <bits/stdc++.h>
using namespace std;
#define REP(i,n) for(int i=0; i<(n); i++)
#define REP2(i,x,n) for(int i=x; i<(n); i++)
int main()
{
    int n,k;
    cin >> n>>k;

    int ans = n-k;
    if (k==1) ans = 0;
    cout << ans << endl;

   return 0;
}


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

#define SZ(x) (((int)x.size()))
#define all(x) (x).begin(), (x).end()
#define pb push_back

typedef long long ll;
typedef long double ld;

using namespace std;

string s, t;

int main()
{
    cin >> s >> t;
    if (s == t.substr(0, SZ(s)))
        cout << "Yes";
    else
        cout << "No";
	return 0;
}


Measured memory_bytes: 3592
#include <bits/stdc++.h>
using namespace std;
char grid[1005][1005];
int val[1005][1005],h,w;
int cnt;
const int MOD = 1000000007;
void dfs(int i, int j)
{
    if(i>h || j>w || !i || !j || grid[i][j]=='#') return;
    val[i][j] = val[i][j] + 1;
    if(val[i][j]>=MOD) val[i][j]-=MOD;
    dfs(i+1,j);
    dfs(i,j+1);
}
int main()
{
    int i,j;
    scanf("%d%d",&h,&w);
    for(i=1;i<=h;i++)
    {
        getchar();
        for(j=1;j<=w;j++)
        {
            scanf("%c",&grid[i][j]);
            if(grid[i][j]=='#') val[i][j] = -1;
        }
    }
    val[1][0] = 1;
    for(i=1;i<=h;i++)
    {
        for(j=1;j<=w;j++)
        {
            if(val[i][j] != -1){
				if(val[i-1][j] != -1) val[i][j] += val[i-1][j];
				val[i][j] %= MOD;
				if(val[i][j-1] != -1) val[i][j] += val[i][j-1];
				val[i][j] %= MOD;
			}
        }
    }
    //dfs(1,1);
    printf("%d\n",val[h][w]);
}


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

#define all(v) v.begin(), v.end()
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define intll int long long
const int INF = 1e9;
const int MOD = 1e9 + 7;

int main() {
  double x ;
  cin >> x ;
  x *=2;
  
  cout << x * 3.141592 ;
  


}


Measured memory_bytes: 3788