akhauriyash/Code-Regression huggingface dataset:
#include<iostream>
#include <algorithm>
#include<string>
#include <bitset>
#include <vector>
#include <functional>
#include <climits>
#include <iomanip>
#include <utility>
#include <stack>
#include <queue>
#include <math.h>
#include <iomanip>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <numeric>
#include <stack>
#include <map> // pair
#include <cstdlib>  // abs() for integer
#include <cmath>    // abs() for float, and fabs()
typedef std::stack<int> IntStack;
typedef std::stack<char> charStack;
#define START 0
#define FORWARD 1
#define BACK 2
using namespace std;
using ll = long long;
typedef pair <ll, ll > pll;
//*********************************************************
// 最大公約数（Greatest Common Divisor）を返す。
// 引数に０がある場合は０を返す。
//*********************************************************
ll gcd(ll a, ll b)
{
	ll tmp, r;
	if (a<b) {
		tmp = a;
		a = b;
		b = tmp;
	}

	/* ユークリッドの互除法 */
	r = a % b;
	while (r != 0) {
		a = b;
		b = r;
		r = a % b;
	}
	return b;
	//// 引数に０がある場合は０を返す
	//if ((0 == m) || (0 == n))
	//	return 0;

	//// ユークリッドの方法
	//while (m != n)
	//{
	//	if (m > n) m = m - n;
	//	else         n = n - m;
	//}
	//return m;
}//gcd
int main()
{
	ll a = 0, b = 0, c = 0, d = 0, e = 0, f = 0, g = 0, h = 0, ans = 0;
	ll x[100004] = {};
	ll y[100004] = {};
	ll z[100004] = {};
	string s;
	string s1, s2;
	//IntStack yStack;
	//charStack Stack;
	//vector<pair<int, int> > pairs(a);

	cin >> a;
	for (int i = 0; i < a; i++)
	{
		cin >> s;
		for (int i = 0; i < s.length(); i++)
		{
			if (s.length()-i>=2&&s[i]=='A'&&s[i+1] == 'B')
			{
				ans++;
			}
		}
		if (s[0]=='B'&&s[s.length()-1]=='A')
		{
			b++;
		}
		else if (s[0] == 'B')
		{
			c++;
		}
		else if (s[s.length() - 1] == 'A')
		{
			d++;
		}
	}
	if (c>0&&d>0)
	{
		cout << ans+min(c,d)+b << endl;
	}
	else if (c>0||d>0)
	{
		cout << ans +b << endl;
	}
	else if(b>0)
	{
		cout << ans + b-1 << endl;
	}
	else
	{
		cout << ans + b << endl;
	}



	//cout << ans << endl;



	//cout << ans << endl;

	////std::cout << std::fixed;
	//cout << std::setprecision(20) << << endl;
	//cout << d+1 << endl;
	//cout << "" << endl;

	return 0;
}
//sort(x, x + a, std::greater<ll>());

//char型の文字数字は、-'0'で数値に変換できる
//accumulate(x, x + a, 0);//int型までの配列の合計
//memcpy(x, visited, sizeof(ll)*n);
//void kansuu(ll num, ll visited[10]) {}
//kansuu(1, zz);
//cout << setprecision(15) << v << endl;
//cout << char(z - 'a');
//log10(i) + 1 //10進数の桁数を取得
//
//int temp;
//for (int i = 0; i < n - 1; i++) {
//	for (int j = n - 1; j > i; j--) {
//		if (w[j - 1] < w[j]) {  /* 前の要素の方が大きかったら */
//			temp = w[j];        /* 交換する */
//			w[j] = w[j - 1];
//			w[j - 1] = temp;
//		}
//	}
//}
//
//最小公倍数
//ll x = a * b;
//ll tmp;
///* 自然数 a > b を確認・入替 */
//if (a<b) {
//	tmp = a;
//	a = b;
//	b = tmp;
//}
///* ユークリッドの互除法 */
//ll r = a % b;
//while (r != 0) {
//	a = b;
//	b = r;
//	r = a % b;
//}
//a = x / b;//答え

Measured memory_bytes: 256
#include <stdio.h>
#include <iostream>
#include <cmath>
#include <algorithm>

using namespace std;

void solve()
{
	unsigned long long x;
	cin >> x;
	long double r = 100;
	int c = 0;
	while(true)
	{
		++c;
		r = (long long)(r) * 1.01;
		if(r >= x)
		{
			cout << c << endl;
			return;
		}
	}
}

int main()
{
	solve();

	return 0;
}

Measured memory_bytes: 3636
n,k = [int(i) for i in input().split()]

D = [i for i in input().split()]
c = n

def match(A,B):
    for a in A:
        if a in B:
            return True
    else:
        return False
        
while True:
    if match(D,list(str(c))):
        c += 1
        continue
    else:
        break
    
    
print(c)

Measured memory_bytes: 3060
import sys
def input():
	return sys.stdin.readline()[:-1]
MOD = 10**9+7
n, K = map(int, input().split())
dp = [[[0 for _ in range(K+1)] for _ in range(n+1)] for _ in range(n+1)]
dp[0][0][0] = 1

for i in range(1, n+1):
	for j in range(n+1):
		for k in range(K+1):
			if k >= 2*j:
				dp[i][j][k] += (2*j+1) * dp[i-1][j][k-2*j]
			if k >= 2*j and j < n:
				dp[i][j][k] += (j+1) * (j+1) * dp[i-1][j+1][k-2*j]
			if k >= 2*j and j > 0:
				dp[i][j][k] += dp[i-1][j-1][k-2*j]
			dp[i][j][k] %= MOD

print(dp[n][0][K])

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

int main()
{
  string s;
  cin >> s;

  string::size_type a = 300000, z = 0;
  for (string::size_type i = 0; i < s.size(); i++) {
    switch (s.at(i)) {
    case 'A':
      if (a == 300000) a = i;
      break;
    case 'Z':
      z = i;
      break;
    }
  }
  cout << z - a + 1<< endl;
}


Measured memory_bytes: 640
INT_MAX = 999999999999999999999999

N,_=gets.chomp.split(' ').map{|n| n.to_i}
A=gets.chomp.split(' ').map{|n| n.to_i}
max = A[N-1]
maxdif = -1
maxcnt = 0
(N-1).downto(0){|i|
	# puts "Ai,max,maxdif,maxcnt"
	# puts A[i]
	# puts max
	# puts maxdif
	# puts maxcnt
	ai = A[i]
	dif = max - ai
	case maxdif <=> dif
	when -1
		maxdif = dif
		maxcnt = 1
	when 0
		maxcnt += 1
	end
	max < ai ? max = ai : 1
}
puts maxcnt



Measured memory_bytes: 11532
import java.util.Scanner;

public class Main {
	public static void main(String[] args) throws Exception {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		sc.close();

		for (int i = 0; i < 26; i++) {
			int a = n - 4 * i;
			if (a >= 0 && a % 7 == 0) {
				System.out.println("Yes");
				return;
			}
		}
		System.out.println("No");
	}
}


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

int main()
{
    ll N;
    cin >> N;
    vector<int> a(N);
    rep(i, N) cin >> a[i];
    vector<bool> ans(N);
    for (int i = N - 1; i >= 0; i--)
    {
        bool tmp = a[i] == 1;
        for (int j = i; j < N; j += i + 1)
        {
            tmp = tmp ^ ans[j];
        }
        ans[i] = tmp;
    }

    cout << accumulate(ans.begin(), ans.end(), 0) << endl;
    rep(i, N) if (ans[i]) cout << i + 1 << " ";
    cout << endl;

    return 0;
}


Measured memory_bytes: 1792
#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, t, a;
  cin >> n >> t >> a;
  int minn=10000000000;
  int h;
  int mn;
  for(int i=0; i<n; i++){
    cin >> h;
    if(minn >= abs(a*1000 - t*1000 + h * 6)){
      minn = abs(a*1000 - t*1000 + h * 6);
      mn = i + 1;
    }
  }
  
  cout << mn << endl;
}

Measured memory_bytes: 256
N,M =map(int,input().split())
a = [int(input()) for i in range(M)]
DP = [1]*N
mod = 10**9 + 7
for i in a:
    DP[i-1] = 0
if(N != 1):
    for i in range(N):
        if(DP[i] != 0):
            if(i<1):
                DP[i] = DP[i-1]%mod
            else:
                DP[i] = (DP[i-2] + DP[i-1])%mod
else:
    DP = [1]
print(DP[-1])

Measured memory_bytes: 50008
if __name__ == '__main__':
    n, m = list(map(int, input().split(' ')))
    ac_set = set([])
    num_list = []
    result_list = []
    counter = 0
    pena_dict = {}
    for i in range(m):
        num, result = input().split(' ')
        result_list.append(result)
        if result == 'AC':
            ac_set.add(num)
        elif (result == 'WA') and ((num in ac_set) is False):
            if (num in pena_dict) is False:
                pena_dict[num] = 1
            else:
                pena_dict[num] = pena_dict[num] + 1

    for i in ac_set:
        if i in pena_dict:
            counter = counter + pena_dict[i]

    print(len(ac_set), counter)

Measured memory_bytes: 20204
a = [int(i) for i in input().split()]
count = 0

def double_puls():
    a[0] += 1
    a[1] += 1
    

while True:
    a.sort()
    if a[0] == a[1] and a[1] == a[2]:
        break
    if a[2] >= a[1]+1:
        double_puls()
        count += 1
    elif a[1] == a[2]:
        a[0] += 2
        count += 1
    elif a[0] == a[1]:
        double_puls()
        count += 1

print(count)

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

using namespace std;

typedef long long ll;
typedef long double ld;
typedef vector<ll> vll;
typedef vector<vll> vvll;
typedef vector<vvll> vvvll;
typedef vector<ld> vld;
typedef vector<string> vstr;
typedef pair<ll, ll> pll;
typedef vector<pll> vpll;
typedef priority_queue<ll, vector<ll>, greater<ll>> spqll;  // 小さい順に取り出し
typedef priority_queue<ll, vector<ll>, less<ll>> bpqll;     // 大きい順に取り出し

#define REP(i, n) for (ll i = 0; i < (ll)(n); i++)
#define IREP(i, v) for (auto i = (v).begin(); i != (v).end(); ++i)
#define TS to_string
#define ALL(v) (v).begin(), (v).end()
#define endl "\n"

ll INF = 1e9;
ll MOD = 1000000007;
ll LINF = 1e18;
ld EPS = 1e-9;
ld PI = M_PI;
vll dx = {1, 0, -1, 0, 1, -1, -1, 1};
vll dy = {0, 1, 0, -1, 1, 1, -1, -1};
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;}     //最小公倍数

void yes(){ cout << "Yes" << endl;}
void no(){ cout << "No" << endl;}

//-----------------------------------------

//-----------------------------------------
int main()
{
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout << fixed << setprecision(10);

  ll q;
  cin >> q;
  set<ll> st;
  REP(i,q){
    ll com;
    cin >> com;
    if(com == 0){
      ll x; cin >> x;
      st.insert(x);
      cout << st.size() <<endl;
    }
    else{
      ll x; cin >> x;
      cout << (st.find(x) != st.end()) <<endl;
    }
  }
  return 0;
}




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

int main(){
    ll N;
    cin >> N;
    vector<ll> h(N);
    rep(i, 0, N) cin >> h[i];
    ll ans = h[0];
    rep(i, 1, N){
      if(h[i] > h[i-1]) ans += h[i] - h[i-1];
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 3620
#include <cstdio>
#include <iostream>
#include <cstdlib>
#include <algorithm>
#include <vector>
#include <cstring>
#include <queue>
#include <stack>
#include <functional>
#include <set>
#include <map>
#include <deque>
#include <cmath>
#define WMAX 10000
#define HMAX 10000
#define NMAX 100005
#define INF (ll)1e9

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

using namespace std;
template<typename A, size_t N, typename T>
void Fill(A (&array)[N], const T &val){
    std::fill( (T*)array, (T*)(array+N), val );
}

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

struct edge{
  ll to,cost;
};

ll A,B,C,N,W,H,ans,dp[HMAX][WMAX],h[NMAX];
string S;
static const ll dx[8] = {0,1,1,1,0,-1,-1,-1},
					dy[8] = {1,1,0,-1,-1,-1,0,1};

void solve(){
	ll ub = INF,lb = 0;
	while(ub - lb > 1){
		ll mid = (ub + lb)/2,sum = 0;
		for (ll i = 0; i < N; ++i)
		{
			if(h[i] > B*mid){
				sum += ceil(double(h[i] - B*mid)/(A-B));
			}
		}
		if(mid >= sum){
			// printf("%lld >= %lld\n",mid,sum);
			ub = mid;
		}else{
			// printf("%lld < %lld\n",mid,sum);
			lb = mid;
		}
	}
	ans = ub;
}

void debug(){

}

void answer(){
	cout << ans << "\n";
}

int main(){
	cin >> N >> A >> B;
	for (int i = 0; i < N; ++i)
	{
		cin >> h[i];
	}
	solve();
	#ifdef DEBUG
	debug();
	#endif
	answer();

	return 0;
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
int main(){
    string s,t,u;
    cin >> s;
    int n = s.size(),cnt=0;
    for(int i=0;i<n/2;i++) t += s[i];
    for(int i=n-1;n/2+n%2<=i;i--) u += s[i];
    for(int i=0;i<n/2;i++){
        if(t[i]!=u[i]) cnt++;
    }
    cout << cnt << endl;
}

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


using namespace std;

void get_elem(int A[], int n);
bool search(int A[], int n, int key);

#define MAX 10000
int main()
{
	int S[MAX];
	int n, m, sum = 0;
 	cin >> n;
 	get_elem(S, n);

	cin >> m;
	
	for (int i = 0; i < m; i++)
	{
		int key;
		cin >> key;
		if (search(S, n, key)) sum++;
	}
 	cout << sum << endl;
	return 0;
}


void get_elem(int A[], int n)
{
	for (int i = 0; i < n; i++)
	{
		cin >> A[i];
	}
}

bool search(int A[], int n, int key)
{
	int i = 0;
	A[n] = key;
	while (A[i] != key)
		i++;
	return i != n;
}


Measured memory_bytes: 3152
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.StringTokenizer;
import java.io.IOException;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.InputStream;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 */
public class Main {
	public static void main(String[] args) {
		InputStream inputStream = System.in;
		OutputStream outputStream = System.out;
		FastScanner in = new FastScanner(inputStream);
		PrintWriter out = new PrintWriter(outputStream);
		ProblemE solver = new ProblemE();
		solver.solve(1, in, out);
		out.close();
	}

	static class ProblemE {
		public void solve(int testNumber, FastScanner in, PrintWriter out) {
			int a = in.nextInt();
			int b = in.nextInt();
			int[][] d = new int[a + 1][b + 1];
			for (int x = 1; x <= a; x++) {
				for (int y = 1; y <= b; y++) {
					d[x][y] = in.nextInt();
				}
			}

			final int N = 101;
			int[][] f = new int[N][N];
			for (int i = 0; i < N; i++) {
				for (int j = 0; j < N; j++) {
					for (int x = 1; x <= a; x++) {
						for (int y = 1; y <= b; y++) {
							f[i][j] = Math.max(f[i][j], d[x][y] - i * x - j * y);
						}
					}
				}
			}

			for (int x = 1; x <= a; x++) {
				for (int y = 1; y <= b; y++) {
					int cur = Integer.MAX_VALUE;
					for (int i = 0; i < N; i++) {
						for (int j = 0; j < N; j++) {
							cur = Math.min(cur, i * x + j * y + f[i][j]);
						}
					}
					if (cur != d[x][y]) {
						out.println("Impossible");
						return;
					}
				}
			}

			out.println("Possible");
			int m = 2 * (N - 1) + N * N;
			out.println((2 * N) + " " + m);
			for (int i = 0; i + 1 < N; i++) {
				out.println((i + 1) + " " + (i + 2) + " X");
				out.println((N + i + 1) + " " + (N + i + 2) + " Y");
			}
			for (int i = 0; i < N; i++) {
				for (int j = 0; j < N; j++) {
					out.println((i + 1) + " " + (2 * N - j) + " " + f[i][j]);
				}
			}
			out.println(1 + " " + (2 * N));
		}

	}

	static class FastScanner {
		private BufferedReader in;
		private StringTokenizer st;

		public FastScanner(InputStream stream) {
			in = new BufferedReader(new InputStreamReader(stream));
		}

		public String next() {
			while (st == null || !st.hasMoreTokens()) {
				try {
					st = new StringTokenizer(in.readLine());
				} catch (IOException e) {
					throw new RuntimeException(e);
				}
			}
			return st.nextToken();
		}

		public int nextInt() {
			return Integer.parseInt(next());
		}

	}
}



Measured memory_bytes: 26660
#include<iostream>

using namespace std;

int main(){
	
	int i;

	int a,b,sum,figure;

	while(cin >> a >> b){
		sum = a + b;
		figure = 1;
		while(sum/10!=0){
			sum = sum/10;
			figure++;
		}
		cout << figure << "\n";
	}	
	return 0;
}

Measured memory_bytes: 1160
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <algorithm>
#include <array>
#include <vector>
#include <utility>
#include <bitset>
#include <queue>
#include <unordered_set>

using namespace std;

typedef long long ll;
constexpr ll MAX_N = 300;
constexpr ll INF = 1e18;
ll N;
ll D[MAX_N][MAX_N];
ll W[MAX_N][MAX_N];

int main(void) {
    cin.tie(0);
    ios::sync_with_stdio(false);
    cin >> N;
    for (ll i = 0; i < N; i++) {
        for (ll j = 0; j < N; j++) {
            cin >> D[i][j];
            W[i][j] = D[i][j];
        }
    }

    for (ll k = 0; k < N; k++) {
        for (ll i = 0; i < N; i++) {
            for (ll j = 0; j < N; j++) {
                W[i][j] = min(W[i][j], W[i][k] + W[k][j]);
            }
        }
    }

    for (ll i = 0; i < N; i++) {
        for (ll j = 0; j < N; j++) {
            if (D[i][j] != W[i][j]) {
                cout << -1 << endl;
                return 0;
            }
        }
    }

    ll ans = 0;

    for (ll i = 0; i < N; i++) {
        for (ll j = i + 1; j < N; j++) {
            bool need = true;
            for (ll k = 0; k < N; k++) {
                if (i == k || j == k) {
                    continue;
                }

                if (W[i][j] == W[i][k] + W[k][j]) {
                    need = false;
                    break;
                }
            }

            if (need) {
                ans += W[i][j];
            }
        }
    }

    cout << ans << endl;
}



Measured memory_bytes: 1792
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<iomanip>
#include<math.h>
#include<complex>
#include<queue>
#include<deque>
#include<stack>
#include<map>
#include<set>
#include<bitset>
using namespace std;
#define REP(i,m,n) for(int i=(int)m ; i < (int) n ; ++i )
#define rep(i,n) REP(i,0,n)
typedef long long ll;
typedef pair<int,int> pint;
typedef pair<ll,int> pli;
const int inf=1e9+7;
const ll longinf=1LL<<60 ;
const ll mod=1e9+7 ;
using namespace std;

vector<int> buf;
int ans=inf;
int d,g;
int p[100000],c[100000];
void dfs(int i, const int size, const int range_start, const int range_end)
{
  int score=0;
  int prob=0;
  
    if (i == size) {
        // ここで所望の作業を行う
      bool IsPerfect[buf.size()];
      rep(k,buf.size())IsPerfect[k]=false;
        for(int k = 0; k < buf.size(); ++k){
          if(buf[k]==1){
            IsPerfect[k]=true;
            score+=100*(k+1)*p[k]+c[k];
            prob+=p[k];
          }
        }
      rep(k,buf.size()){
       if(!IsPerfect[buf.size()-1-k]){
         int cnt=0;
        while(cnt<p[buf.size()-1-k] && score<g){
          cnt++;
          score+=100*(buf.size()-1-k+1);
          prob++;
        }
       }
      }
      if(score>=g)ans=min(ans,prob);
    }
    else{
        for(int j = range_start; j <= range_end; ++j){
            buf[i] = j;
            dfs(i + 1, size, range_start, range_end);
        }
    }
}

int main(void)
{
  cin >> d >> g;
  rep(i,d)cin >> p[i] >> c[i];
    int size = d;
    int range_start = 0;
    int range_end = 1;
    
    buf.resize(size);
    dfs(0, size, range_start, range_end);
  cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
#include "bits/stdc++.h"
using namespace std;
using ll = long long; using ull = unsigned long long;
#define int ll
using vb = vector<bool>; using vvb = vector<vb>;
using vi = vector<int>; using vvi = vector<vi>;
using vl = vector<ll>; using vvl = vector<vl>;
using pii = pair<int,int>; using pll = pair<ll,ll>;
#define FOR(i,a,b) for(ll i = (a); i < (ll)(b); ++i)
#define REP(i,n) FOR(i,0,n)
#define RFOR(i,a,b) for(ll i = (ll)(b)-1;i >= a;--i)
#define RREP(i,n) RFOR(i,0,n)
#define ALL(obj) (obj).begin(), (obj).end()
#define rALL(obj) (obj).rbegin(), (obj).rend()
#define eb(val) emplace_back(val)
const double PI = acos(-1);
const double EPS = 1e-10;
const ll MOD = 1e9+7;
void cioacc(){//accelerate cin/cout
  cin.tie(0);
  ios::sync_with_stdio(false);
}
signed main(){
  int n,m,l;
  cin >> n >> m >> l;
  vvi a(n,vi(m)),b(m,vi(l)),c(n,vi(l));
  REP(i,n)REP(j,m) cin >> a[i][j];
  REP(i,m)REP(j,l) cin >> b[i][j];
  REP(i,n)REP(j,l)REP(k,m) c[i][j] += a[i][k]*b[k][j];
  for(auto i:c){
    REP(j,i.size()-1) cout << i[j] << " ";
    cout << i.back() << endl;
  }
}


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

#define ll long long int
#define loop(i,s,e) for(ll i=s; i<e; i++)
#define endl '\n'
#define vll vector<ll>
#define pll pair<ll, ll>
#define ff first
#define ss second
#define bug(...)        __f (#__VA_ARGS__, __VA_ARGS__)
#define N 100001
#define pb push_back
#define INF LLONG_MAX
#define inf INT_MAX
#define minusinf INT_MIN
#define M (1000000000+7)

template <typename Arg1>
void __f (const char* name, Arg1&& arg1) { cout << name << " : " << arg1 << endl; }
template <typename Arg1, typename... Args>
void __f (const char* names, Arg1&& arg1, Args&&... args)
{
     const char* comma = strchr (names + 1, ',');
     cout.write (names, comma - names) << " : " << arg1 << " | "; __f (comma + 1, args...);
}

char arr[1001][1001];
ll n, m;

ll dp[1001][1001];

ll util(ll i, ll j){
	if(i>=n or j>=m or arr[i][j]=='#') return 0;

	if(dp[i][j]!=-1) return dp[i][j];

	if(i==n-1 and j==m-1) return 1;

	return dp[i][j] = ((util(i+1, j)%M) + (util(i, j+1)%M))%M ;
}

void alpha(){

	cin>>n>>m;

	memset(dp, -1, sizeof(dp));

	loop(i,0,n){
		loop(j,0,m){
			cin>>arr[i][j];
		}
	}

	cout<<util(0,0)%M<<endl;
	
	return;

}

int main(){

	ios_base:: sync_with_stdio(false);
    cin.tie(NULL); cout.tie(NULL);


    ll t=1;
	//cin>>t;

  	while(t--) alpha();

	return 0;

}

Measured memory_bytes: 9088
N = int(input())
A = list(map(int, input().split()))

ans = 1
border = pow(10, 18)
ng = 0
if 0 in A:
    print(0)
    ng = 1

for a in A:
    if ng == 1:
        break
        
    ans *= a
    if ans > border:
        print(-1)
        ng = 1
        break

if ng == 0:
    print(ans)

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



int main() {
  int n;
  cin >> n;
  vector<int> l(n);
  rep(i, n) cin >> l[i];
  int ans=0;
  for(int i=0; i<n; i++){
    for(int j=i+1; j<n; j++){
      if(l[i]==l[j]) continue;
      for(int k=j+1; k<n; k++){
        if(l[i]==l[k] || l[j]==l[k]) continue;
        int a = l[i], b = l[j], c = l[k];
        vector<int> vec(3);
        vec[0]=a; vec[1]=b; vec[2]=c;
        sort(vec.begin(), vec.end());
        if(vec[0]+vec[1] > vec[2]) ans++;
      }
    }
  }
        
  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 3628
#include <cstdio>
#include <iostream>
#include <algorithm>
#include <string>
#include <cstring>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <cmath>
#include <iomanip>
#include <cassert>
#include <bitset>
using namespace std;

typedef pair<int, int> P;
#define rep(i, n) for (int i=0; i<(n); i++)
#define all(c) (c).begin(), (c).end()
#define uniq(c) c.erase(unique(all(c)), (c).end())
#define index(xs, x) (int)(lower_bound(all(xs), x) - xs.begin())
#define _1 first
#define _2 second
#define pb push_back
//#define INF 1145141919
#define INF 500000
#define MOD 1000000007
#define MAX_N (1<<18)
int seg_m[2*MAX_N-1], seg_a[2*MAX_N-1];

void add(int a, int b, int x, int k=0, int l=0, int r=MAX_N) {
  if (r <= a || b <= l) return;
  if (a <= l && r <= b) {
    seg_a[k] += x;
    return;
  }
  add(a, b, x, k*2+1, l, (l+r)/2);
  add(a, b, x, k*2+2, (l+r)/2, r);
  seg_m[k] = min(
    seg_m[k*2+1] + seg_a[k*2+1],
    seg_m[k*2+2] + seg_a[k*2+2]
  );
}

int query(int a, int b, int k=0, int l=0, int r=MAX_N) {
  if (r <= a || b <= l) return 1145141919;
  if (a <= l && r <= b) return seg_m[k] + seg_a[k];
  return min(query(a, b, k*2+1, l, (l+r)/2),
             query(a, b, k*2+2, (l+r)/2, r)) + seg_a[k];
}
void chmin(int pos, int v) {
  int cur = query(pos, pos+1);
  if (v >= cur) return;
  add(pos, pos+1, v-cur);
}


int N, Q;
int B[200000];
vector<int> G[200000];

signed main() {
  ios::sync_with_stdio(false); cin.tie(0);
  cin >> N;
  rep(i, N) cin >> B[i];
  cin >> Q;
  rep(i, Q) {
    int l, r;
    cin >> l >> r;
    l--, r--;
    G[l].pb(r);
  }
  add(1, MAX_N, INF);
  rep(l, N) {
    for (int r : G[l]) chmin(r+1, query(0, r+2));
    if (B[l]) add(0, l+1, 1);
    else add(l+1, MAX_N, 1);
  }
  int m = query(0, N+1);
  cout << m << "\n";
  return 0;
}


Measured memory_bytes: 12672
import math
import itertools
import heapq
from sys import stdin, stdout, setrecursionlimit
from bisect import bisect, bisect_left, bisect_right
from collections import defaultdict, deque


# d = defaultdict(lambda: 0)
# setrecursionlimit(10**7)
# inf = float("inf")


##### stdin ####
def LM(t, r): return list(map(t, r))
def R(): return stdin.readline()
def RS(): return R().split()
def I(): return int(R())
def F(): return float(R())
def LI(): return LM(int,RS())
def LF(): return LM(float,RS())
def ONE_SL(): return list(input())
def ONE_IL(): return LM(int, ONE_SL())
def ALL_I(): return map(int, stdin)
def ALL_IL(): return LM(int,stdin)

##### tools #####
def ap(f): return f.append
def pll(li): print('\n'.join(LM(str,li)))
def pljoin(li, s): print(s.join(li))



##### main #####		
def main():
	s = ONE_IL()
	print(sum(s))

if __name__ == '__main__':
	main()

Measured memory_bytes: 3572
import java.util.Scanner;


public class Main {
    public static void main(String[] args) {
    	/*Scanner = テキスト入力を扱うためのクラス
		 *キーボードからの入力を受けつける場合は
		 *System.inを使って下記のように記述
		 */
		Scanner scan = new Scanner(System.in);

		//boolean型で2次元配列を作成
		boolean[][] cards = new boolean[4][13];

		//char型でmarkの配列を作成
		//※char型は''(シングルクォーテーション)で指定
		//表示用にのみ使う予定
		char[] mark = {'S','H','C','D'};

		//入力した枚数
		int n = scan.nextInt();

		for (int i=0; i < n; i++){
			/* scan.next().charAt(0)
			 * next()で文字を読み込み
			 * charAt(0)で0番目を取得
			 */
			char ch = scan.next().charAt(0);
			/* nextで指定することでD 8等のものが
			 * ↑の.nextにDが、↓の.nextに8を別々に入れられる
			 */
			int num = Integer.parseInt(scan.next());

			/* switch文の出番
			 * chがcaseと一緒ならcardsの[0](つまりS)にnum-1を行う
			 * これを各cardsのマークの種類分行う
			 */

			switch (ch){
			case 'S': cards[0][num-1] = true; break;
			case 'H': cards[1][num-1] = true; break;
			case 'C': cards[2][num-1] = true; break;
			case 'D': cards[3][num-1] = true; break;
			}
		}
		//Scannerを閉じることで黄色い注意マークが消える？
		scan.close();

		/*for文
		 * 二重for文でiでマーク数を、jで値を回して
		 * cardsの[0][0]から[12][12]まで調べて
		 * ないものを逆論理で見つけて表示している
		 */
		for (int i=0; i < 4; i++){
			for (int j =0; j < 13; j ++){
				if(!cards[i][j]){
					//※jに+1しているのは配列が0から始まるため
					//トランプに0はないのと全数値がずれてしまうため
					//markの[i]番目を指定するため、問題の指定通り
					//S,H,C,Dの順番で表示される
					System.out.println(mark[i] + " " + (j + 1));
				}
			}
		}
    }
}

Measured memory_bytes: 17196
import sys

read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

in_n = lambda: int(readline())
in_nn = lambda: map(int, readline().split())
in_s = lambda: readline().rstrip().decode('utf-8')
in_nl = lambda: list(map(int, readline().split()))
in_nl2 = lambda H: [in_nl() for _ in range(H)]
in_map = lambda: [s == ord('.') for s in readline() if s != ord('\n')]
in_map2 = lambda H: [in_map() for _ in range(H)]
in_all = lambda: map(int, read().split())


def main():
    N, X, T = in_nn()

    ans = -(-N // X) * T
    print(ans)


if __name__ == '__main__':
    main()


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

using namespace std;

int main(void)
{
	int n,m;
	int d,p;
	int sum;

	int i1,i2;

	while(1){
		cin >> n >> m;
		if(n+m==0) break;

		vector<pair<int, int> > michi;
		sum=0;

		for(i1=0;i1<n;i1++){
			cin >> d >> p;
			michi.push_back(make_pair(p,d));
			sum+=d*p;
		}

		sort(michi.begin(), michi.end());
		reverse(michi.begin(), michi.end());


		for(i1=0;i1<michi.size();i1++){
			for(i2=0;i2<michi[i1].second;i2++){
				if(m>0){
					sum-=michi[i1].first;
					m--;
				}
				
			}
			if(m<=0) break;
		}

		cout << sum << endl;



	}

	return 0;
}

Measured memory_bytes: 1324
#include<bits/stdc++.h>
#define watch(x) cout << (#x) << " is " << (x) << endl
typedef long long ll;
using namespace std;
int static fast = [](){
  ios::sync_with_stdio(false);
  cin.tie(0); cout.tie(0); return 0;
}();

int main() {
    string s;
    unordered_map<char, int> cnt;
    cin >> s;
    for(char c: s)
        cnt[c] += 1;
    if (cnt.size() == 2 && cnt.begin()->second == 2)
        cout << "Yes" << endl;
    else
        cout << "No" << endl;

    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main(){
    int w,h,n;
    cin>>h>>w;
    for(int i=0;i<h;i++){
        char s[101];
        cin>>s;
        n=0;
        for(int j=0;j<w;j++){
        if(j>0)cout<<" ";
        if(s[j]=='c'){
            n=1;
            cout<<"0";
        }else if(n>0){
            cout<<n;
            n++;
        }else{
            cout<<"-1";
        }

        }
        cout<<endl;
    }
    return 0;
}

Measured memory_bytes: 3092
# -*- coding: utf-8 -*-


def main():
    """Function."""
    n, t = map(int, input().split())

    min_val = 1001
    for _ in range(n):
        ci, ti = map(int, input().split())

        if ti <= t:
            if ci < min_val:
                min_val = ci
            else:
                pass
        else:
            pass

    if min_val == 1001:
        print("TLE")
    else:
        print(min_val)


if __name__ == "__main__":
    main()


Measured memory_bytes: 2940
import math
import copy
from operator import mul
from functools import reduce
from collections import defaultdict
from collections import Counter
from collections import deque
# 直積 A={a, b, c}, B={d, e}:のとき，A×B={(a,d),(a,e),(b,d),(b,e),(c,d),(c,e)}: product(A, B)
from itertools import product
# 階乗 P!: permutations(seq), 順列 {}_len(seq) P_n: permutations(seq, n)
from itertools import permutations
# 組み合わせ {}_len(seq) C_n: combinations(seq, n)
from itertools import combinations
# 一次元累積和
from itertools import accumulate
from bisect import bisect_left, bisect_right

# import numpy as np
# from scipy.special import perm
# from scipy.special import comb

def inside(y, x, H, W):
    return 0 <= y < H and 0 <= x < W

# 四方向: 右, 下, 左, 上
dy = [0, -1, 0, 1]
dx = [1, 0, -1, 0]
 
def i_inpl(): return int(input())
def l_inpl(): return list(map(int, input().split()))
INF = float("inf")

########

S = input()

c = Counter(S)

flag = True
for i in c.values():
    if i != 2:
        flag = False

if flag:
    print("Yes")
else:
    print("No")

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

int main() {
	ll n,no=1;
	cin>>n;
	ll arr[n];
	for(ll i=0;i<n;i++)
	{
		cin>>arr[i];
		if(arr[i]==no)
		{
			++no;
		}
	}
	ll ans=n-no+1;
	if(ans<n)
	cout<<ans;
	else
	cout<<"-1";
	return 0;
}

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

using namespace std;
 
#define rep(i,k,n) for(i=k;i<n;i++)
#define repr(i,k,n) for(i=k;i>=n;i--)
#define ll long long
#define pb(i) push_back(i)
 
int main(void)
{
	ios_base::sync_with_stdio(0);
	cin.tie(0);

	/*ll t;
	cin >> t;
	while(t--)
	{*/
		ll l;
		cin >> l;
		double vol;
		vol =(l/3.0)*(l/3.0)*(l/3.0);
		printf("%0.12lf",vol);
	//}

}

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

int main() {
    long long N;
    cin >> N;
    map <long long, long long> A;
    for (long long i=0; i<N; i++) {
        long long a;
        cin >> a;
        if (A.find(a)!=A.end()) {
            cout << "NO\n";
            return 0;
        }
        A[a]++;
    }
    cout << "YES\n";
}

Measured memory_bytes: 12800
#include<bits/stdc++.h>
using namespace std;
int a[1000000];
int main()
{
   int n;
   cin>>n;
   for (int i=1;i<=n;i++)
   {
       cin>>a[i];
       a[i]-=i;
   }
   sort(a+1,a+n+1);
   int b = a[(n+1)/2];
   long long ret=0;
   for (int i=1;i<=n;i++)
    ret+=abs(b-a[i]);
    cout<<ret<<endl;
}


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

int main() {
	int x;
	int n;
	int i;
	int p;
	int q;
	int a[110];
	int b[110];

	cin >> x >> n;
	if(n==0){
		cout << x << endl;
		return 0;
	}
	for(i=0;i<n+1;i++){
		a[i]=0;
		b[i]=0;
	}
	for(i=0;i<n;i++){
		cin >> p;
		if(p<x){
			b[x-p]=1;
		} else {
			a[p-x]=1;
		}
	}
	if(a[0]==0){
		cout << x << endl;
		return 0;
	}
	for(i=1;i<n+1;i++){
		if(b[i]==0){
			cout << x-i << endl;
			return 0;
		}
		if(a[i]==0){
			cout << x+i << endl;
			return 0;
		}
	}
	return 0;
}


Measured memory_bytes: 3592
#include <bits/stdc++.h>
#define ll long long
using namespace std;
int main(){
    int H,W;
    cin >> H >> W;
    int N;
    cin >> N;
    int a[N]; 
    for(int i=0;i<N;i++)cin >> a[i];

    int ans[H][W];
    int i=0,j=0,l=0;
    ans[0][0] = l+1;
    a[l]--;
    if(a[l]==0)l++;
    j++;

    for(int k=1;k<H*W;k++){
        if(i%2==0&&j==W-1){
            ans[i][j] = l+1;
            a[l]--;
            if(a[l]==0)l++;
            i++;
        }else if(i%2==1&&j==0){
            ans[i][j] = l+1;
            a[l]--;
            if(a[l]==0)l++;
            i++;
        }else if(i%2==0){
            ans[i][j] = l+1; 
            j++;
            a[l]--;
            if(a[l]==0)l++;
        }else{
            ans[i][j] = l+1;
            j--;
            a[l]--;
            if(a[l]==0)l++;
        }
    }
    for(int t=0;t<H;t++){
        for(int s=0;s<W;s++){
            cout << ans[t][s] << " ";
        }
        cout << endl;
    }
}

Measured memory_bytes: 384
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace AtCoder
{
  public class CodeABC141A
  {
    static void Main(string[] args)
    {
      var line = System.Console.ReadLine();
      var ret = string.Empty;
      switch(line)
      {
        case "Sunny":
          ret = "Cloudy";
          break;
        case "Cloudy":
          ret = "Rainy";
          break;
        case "Rainy":
          ret = "Sunny";
          break;
      }

      Console.WriteLine(ret);
    } 
  }
}


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

#define X real()
#define Y imag()

using D = double;
using P = complex<D>;

const D EPS = 1e-8;
const D PI = acos(-1);

D SQ(D x) {return x*x;}

int main() {
    cout << fixed << setprecision(20);
    int d, n, b;
    cin >> d >> n >> b;
    vector<D> p(n), h(n);
    rep(i, n) {
        cin >> p[i] >> h[i];
    }
    D ans = 1e9;
    rep(k, b+1) {
        D l = PI/4.0, r = PI/2.0; // r => OK, l => NG
        D L = (D)d/(k+1.0);

        auto check = [&](D m, int B) {
            D v = sqrt(L/(2*sin(m)*cos(m)));
            D vx = v*cos(m), vy = v*sin(m);
            int j = 0;
            rep(i, B+1) {
                auto getY = [&]() {
                    D x = p[j]-L*i;
                    return -(1.0/(2*SQ(vx)))*SQ(x)+(vy/vx)*(x);
                };
                while(j < n && p[j] < L*(i+1) + EPS) {
                    if(getY() < h[j] - EPS) return false;
                    j++;
                }
            }
            return true;
        };

        rep(_, 100) {
            D m = (l+r)/2.0;
            if(check(m, k)) r = m;
            else l = m; 
        }
        // printf("l:%.15lf\n", l);
        ans = min(ans, sqrt(L/(2*sin(l)*cos(l))));
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 3668
#include <iostream>
#include <algorithm>
#include <functional>
#include <vector>

using namespace std;

int n, m, st[401];
int use[401];
vector<int> data, tmp;
vector<vector<int> > res;

void init(){
  fill(st, st+401, false);
  data.clear();
  tmp.clear();
  res.clear();
}

void calc(int p, int len){
  if(p == n){
    res.push_back(tmp);
    return;
  }
  while(len > 0 && !st[len]) len--;
  if(len == 0) return;
  
  int val = len;
  for(int k=0;k<2;k++){
    bool f = true;
    for(int i=0;i<tmp.size();i++){
      if(--st[abs(tmp[i]-len)] < 0) f = false;
    }
    if(f){
      tmp.push_back(len);
      calc(p+1, val);
      tmp.pop_back();
    }
    for(int i=0;i<tmp.size();i++){
      st[abs(tmp[i]-len)]++;
    }
    len = data[0] - len;
  }
}

main(){
  while(cin >> n && n){
    m = n * (n - 1) / 2;
    init();
    for(int i=0;i<m;i++){
      int in;
      cin >> in;
      data.push_back(in);
      st[in]++;
    }
    if(m > 1){
      st[data[0]]--;
      tmp.push_back(0);
      tmp.push_back(data[0]);
      calc(2, data[0]);
      vector<vector<int > > ans;
      for(int i=0;i<res.size();i++){
        sort(res[i].begin(), res[i].end());
        vector<int> vec;
        for(int j=1;j<res[i].size();j++) vec.push_back(res[i][j] - res[i][j-1]);
        ans.push_back(vec);
        reverse(vec.begin(), vec.end());
        ans.push_back(vec);
      }
      sort(ans.begin(), ans.end());
      ans.erase(unique(ans.begin(), ans.end()), ans.end());
      for(int i=0;i<ans.size();i++){
        for(int j=0;j<ans[i].size();j++){
          if(j) cout << " ";
          cout << ans[i][j];
        }
        cout << endl;
      }
    }else{
      cout << data[0] << endl;
    }
    cout << "-----" << endl;
  }
}

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

//--------------------------------------------------------------------



void func() {
        int n, m;
        cin >> n >> m;
        int a[n], w[n], p;
        for(int i=0; i<n; i++){
                a[i] = 0;
                w[i] = 0;
        }
        string s;
        for(int i=0; i<m; i++){
                cin >> p >> s;
                if((s == "AC")&&(a[p-1] == 0)) a[p-1]++;
                if((s == "WA")&&(a[p-1] == 0)) w[p-1]++;
        }
        int AC=0, WA=0;
        for(int i=0; i<n; i++){
                AC += a[i] ;
                if (a[i]==1) WA += w[i];
        }
        cout << AC << " " << WA << endl;
}

int main(){
        func();
        return 0;
}

Measured memory_bytes: 1024
n=int(input())
a=[list(map(int,input().split()))for _ in range(n)]
b=[[j for j in i]for i in a]
c=[n*[1]for _ in range(n)]
for k in range(n):
  for i in range(n):
    for j in range(n):
      b[i][j]=min(b[i][j],b[i][k]+b[k][j])
      if a[i][j]==a[i][k]+a[k][j]:
        if i!=j and i!=k and j!=k:
          c[i][j]=0
if a!=b:exit(print(-1))
ans=0
for i in range(n):
  for j in range(i):
    if c[i][j]:ans+=a[i][j]
print(ans)

Measured memory_bytes: 46172
#include<bits/stdc++.h>
using namespace std;
#define ll long long
int main()
{
    string s;
    cin>>s;
    int sum=0;
    for(int i=0; i<s.size(); i++)
    {
        sum+=(s[i]-'0');
    }


    //cout<<sum<<endl;
    if(sum%9==0)
    {
        cout<<"Yes"<<endl;
    }
    else
        cout<<"No"<<endl;


}


Measured memory_bytes: 3680
#include "iostream"
#include <stdio.h>
#include <algorithm>
#include <stdlib.h>
#include <string>
#include <cctype>
#include <stack>
#include <vector>
#include <list>
#include <queue>
using namespace std;
using ll=long long;
#define mod  1000000007

int main(int argc, char const *argv[]) {
  ll x,n;
  std::cin >> x >> n;
  if(x-n>0) std::cout << x-n << '\n';
  else printf("0\n");
  return 0;
}


Measured memory_bytes: 256
import java.util.*;

public class Main{
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    int n = sc.nextInt();
    String s = sc.next();
    //nとstringを取得
    
    ArrayList<Integer> list = new ArrayList<>();
    int x = 0;
    //空のx,配列listを作成
    
    char[] chr;
    chr = s.toCharArray();
    //tocharArrayでstringをchar[n]の配列に
    
    for (int i=0; i<n; i++){
      if (chr[i]=='I'){
        x++;
        list.add(i, x);
      }else{
        x--;
        list.add(i, x);
      }//forでn回回す、Iだったらlist[i].add(x++)、Dだったらx--
    }
    Collections.sort(list);
    if(list.get(n-1)>0){
      System.out.println(list.get(n-1));
    }else{
      System.out.println(0);
    }
  }
}

//listをArrays.sort
//list[0]を表示

Measured memory_bytes: 21716
#include <iostream>
#include <stdio.h>
#include <math.h>
#include <string.h>
#include <time.h>
#include <stdlib.h>
#include <string>
#include <bitset>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <algorithm>
#include <sstream>
#include <stack>
#include <iomanip>
using namespace std;
#define pb push_back
#define mp make_pair
typedef pair<int,int> pii;
typedef long long ll;
typedef double ld;
typedef vector<int> vi;
#define fi first
#define se second
#define fe first
#define FO(x) {freopen(#x".in","r",stdin);freopen(#x".out","w",stdout);}
#define Edg int M=0,fst[SZ],vb[SZ],nxt[SZ];void ad_de(int a,int b){++M;nxt[M]=fst[a];fst[a]=M;vb[M]=b;}void adde(int a,int b){ad_de(a,b);ad_de(b,a);}
#define Edgc int M=0,fst[SZ],vb[SZ],nxt[SZ],vc[SZ];void ad_de(int a,int b,int c){++M;nxt[M]=fst[a];fst[a]=M;vb[M]=b;vc[M]=c;}void adde(int a,int b,int c){ad_de(a,b,c);ad_de(b,a,c);}
#define es(x,e) (int e=fst[x];e;e=nxt[e])
#define esb(x,e,b) (int e=fst[x],b=vb[e];e;e=nxt[e],b=vb[e])
#define VIZ {printf("digraph G{\n"); for(int i=1;i<=n;i++) for es(i,e) printf("%d->%d;\n",i,vb[e]); puts("}");}
#define VIZ2 {printf("graph G{\n"); for(int i=1;i<=n;i++) for es(i,e) if(vb[e]>=i)printf("%d--%d;\n",i,vb[e]); puts("}");}
#define SZ 666666
ll MOD=924844033;
ll w[2][666666];
ll qp(ll a,ll b)
{
    ll ans=1;
    while(b)
    {
        if(b&1) ans=ans*a%MOD;
        a=a*a%MOD; b>>=1;
    }
    return ans;
}
int K;
void fftinit(int n)
{
    for(K=1;K<n;K<<=1);
    w[0][0]=w[0][K]=1;
    ll g=qp(5,(MOD-1)/K);
    for(int i=1;i<K;i++) w[0][i]=w[0][i-1]*g%MOD;
    for(int i=0;i<=K;i++) w[1][i]=w[0][K-i];
}
void fft(int* x,int v)
{
    for(int i=0,j=0;i<K;i++)
    {
        if(i>j) swap(x[i],x[j]);
        for(int l=K>>1;(j^=l)<l;l>>=1);
    }
    for(int i=2;i<=K;i<<=1)
    {
        for(int j=0;j<K;j+=i)
        {
            for(int l=0;l<i>>1;l++)
            {
                ll t=(ll)x[j+l+(i>>1)]*w[v][K/i*l]%MOD;
                x[j+l+(i>>1)]=(x[j+l]-t+MOD)%MOD;
                x[j+l]=(x[j+l]+t)%MOD;
            }
        }
    }
    if(!v) return;
    ll rv=qp(K,MOD-2);
    for(int i=0;i<K;i++) x[i]=x[i]*rv%MOD;
}
int n,a[SZ],b[SZ],sz[SZ]; Edg
void dfs(int x,int f=0)
{
	sz[x]=1;
	for esb(x,e,b) if(b!=f)
		dfs(b,x),sz[x]+=sz[b];
}
int v[SZ],A[SZ],B[SZ];
ll fac[SZ],rfac[SZ];
int main()
{
	fac[0]=1;
	for(int i=1;i<SZ;++i) fac[i]=fac[i-1]*i%MOD;
	rfac[SZ-1]=qp(fac[SZ-1],MOD-2);
	for(int i=SZ-1;i>=1;--i)
		rfac[i-1]=rfac[i]*i%MOD;
	scanf("%d",&n);
	for(int i=1;i<n;++i)
	{
		scanf("%d%d",a+i,b+i);
		adde(a[i],b[i]);
	}
	dfs(1);
	for(int i=1;i<n;++i)
	{
		int s=min(sz[a[i]],sz[b[i]]);
		--v[s]; ++v[n]; --v[n-s];
	}
	for(int i=1;i<=n;++i)
		A[n-i]=v[i]*fac[i]%MOD;
	for(int i=0;i<=n;++i)
		B[i]=rfac[i];
	fftinit(n+n+2);
	fft(A,0); fft(B,0);
	for(int i=0;i<K;++i) A[i]=A[i]*(ll)B[i]%MOD;
	fft(A,1);
	for(int i=1;i<=n;++i)
	{
		ll ans=(A[n-i]+fac[n]*rfac[n-i])%MOD*rfac[i];
		ans=(ans%MOD+MOD)%MOD;
		printf("%d\n",int(ans));
	}
}

Measured memory_bytes: 53248
#include <bits/stdc++.h>
#define rep(i, n) for (ll i = 0; i < (n); ++i)
#define pb push_back
#define COUT(x) cout << (x) << endl
#define ENDL cout << endl
#define DF(x) x.erase(x.begin());  // 先頭文字削除
#define debug(x) cout << "[debug] " << #x << ": " << x << endl
using namespace std;
using ll = long long;
using P = pair<int, int>;
const int INF = 1000000000;

int main() {
    ll N;
    cin >> N;

    ll A[N];
    map<ll, ll> m;
    rep(i, N) {
        ll a;
        cin >> a;
        A[i] = a;
        m[a]++;
    }
    ll sum = 0;
    for (auto a : m) {
        sum += a.second * (a.second - 1) / 2;
    }

    map<ll, ll> t;
    ll ans[N];
    rep(i, N) {
        ll num = A[i];
        if (t[num] == 0) {
            // debug(i);
            // debug(sum);
            // debug(num);

            t[num] = sum - m[num] + 1;
            ans[i] = sum - m[num] + 1;
            // debug(t[num]);

        } else {
            ans[i] = t[num];
        }
    }
    rep(i, N) { COUT(ans[i]); }

    return 0;
}

Measured memory_bytes: 20480
#include <iostream>
#include <iomanip>
#include <sstream>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <cstring>
#include <climits>
#include <cfloat>
#include <string>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <bitset>
#include <algorithm>
#include <functional>
#include <utility>
#include <numeric>

using namespace std;

typedef unsigned int UI;
typedef long long LL;
typedef unsigned long long ULL;
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int,int> PII;
typedef istringstream ISS;
typedef ostringstream OSS;

#define REP( i, m, n ) for ( int i = (int)( m ); i < (int)( n ); ++i )
#define EACH( v, c ) for ( auto &v : c )

#define ITER( c ) __typeof( (c).begin() )
#define IREP( c, it ) for ( ITER(c) it = c.begin(); it != c.end(); ++it )
#define ALL( c ) (c).begin(), (c).end()

#define PB( n ) push_back( n )
#define MP( a, b ) make_pair( ( a ), ( b ) )
#define EXIST( c, e ) ( (c).find( e ) != (c).end() )

#define fst first
#define snd second

#define DUMP( x ) cerr << #x << " = " << ( x ) << endl
#define DEBUG( x ) cerr << __FILE__ << ":" << __LINE__ << ": " << #x << " = " << ( x ) << endl

int solve( const int N, VI costs, VI p )
{
	VI dp( N + 1, 0 );

	REP( i, 0, costs.size() )
	{
		REP( j, 0, N + 1 )
		{
			if ( 0 <= j - costs[i] )
			{
				dp[j] = max( dp[j], dp[ j - costs[i] ] + p[i] );
			}
		}
	}

	return *max_element( ALL( dp ) );
}

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

	int n, m;

	while ( cin >> n >> m )
	{
		VI c( n ), v( n ), d( n ), l( n );

		REP( i, 0, n )
		{
			string name;

			cin.ignore( 1 );
			getline( cin, name );

			cin >> c[i] >> v[i] >> d[i] >> l[i];
		}

		int res1 = solve( m, c, v );
		int res2 = solve( m, c, d );
		int res3 = solve( m, c, l );

		cout << max( res1, max( res2, res3 ) ) << endl;
	}

	return 0;
}

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

int n, m; 
vector< vector<int> > from;
vector< vector<int> > to;
vector<int> start, finish;
vector<int> d;

int dist(int u) {
	if (d[u] != -1) return d[u];

	int md = -1;
	for (int i = 0; i < from[u].size(); i++) {
		int v = from[u][i];
		md = max(md, dist(v)+1);
	}

	d[u] = md;
	return md;
}

int main(void) {
	cin >> n >> m;
	from = vector< vector<int> >(n, vector<int>());
	to = vector< vector<int> >(n, vector<int>());
	for (int i = 0; i < m; i++) {
		int u, v; cin >> u >> v;
		from[u-1].push_back(v-1);
		to[v-1].push_back(u-1);
	}
	
	for (int i = 0; i < n; i++) {
		if (from[i].size() == 0) finish.push_back(i);
		if (to[i].size() == 0) start.push_back(i);
	} 
	
	int md = -1;
	d = vector<int>(n, -1);
	for (int i = 0; i < finish.size(); i++) d[finish[i]] = 0;
	for (int i = 0; i < start.size(); i++) {
		int u = start[i];
		md = max(md, dist(u));
	}
	cout << md;
	
	return 0;
}


Measured memory_bytes: 16256
#include <iostream>

//include
//------------------------------------------
#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <stack>
#include <queue>
#include <bitset>
#include <tuple>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>
#include <climits>

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<long long> VL;
typedef vector<string> VS;
typedef pair<int, int> PII;
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 (auto 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 INFL = __LONG_LONG_MAX__ / 10;
const int INFI = __INT_MAX__ / 10;

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

uint64_t popcnt(uint64_t n)
{
    uint64_t c = 0;
    c = (n & 0x5555555555555555) + ((n >> 1) & 0x5555555555555555);
    c = (c & 0x3333333333333333) + ((c >> 2) & 0x3333333333333333);
    c = (c & 0x0f0f0f0f0f0f0f0f) + ((c >> 4) & 0x0f0f0f0f0f0f0f0f);
    c = (c & 0x00ff00ff00ff00ff) + ((c >> 8) & 0x00ff00ff00ff00ff);
    c = (c & 0x0000ffff0000ffff) + ((c >> 16) & 0x0000ffff0000ffff);
    c = (c & 0x00000000ffffffff) + ((c >> 32) & 0x00000000ffffffff);
    return (c);
}

int N;
const int LimitN = 2000;
const int LimL = 1000;

int L[LimitN];
set<int> L_set;

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

    cin >> N;

    int ans = 0;
    REP(i, N)
    {
        cin >> L[i];
    }

    FOR(i, 2, N)
    {
        FOR(j, 1, i)
        {
            FOR(k, 0, j)
            {
                if (L[i] < L[j] + L[k] && L[j] < L[k] + L[i] && L[k] < L[i] + L[j])
                    ans++;
            }
        }
    }

    cout << ans << endl;

    // cout << ans << endl;

    // cout
    // << ans << endl;
}

Measured memory_bytes: 888