akhauriyash/Code-Regression huggingface dataset:
#include<iostream>
#include<climits>
#include<cassert>
#include<algorithm>
#include<cassert>
#include<map>
#include<vector>
using namespace std;
#define REP(i,b,n) for(int i=b;i<n;i++)
#define rep(i,n)   REP(i,0,n)

#define left first
#define right second

typedef pair<int,int> pii;
const int N = 5012;

pair<int,int> st[2][N];//ããå ´æã«å·¦ç«¯ã¨å³ç«¯ã®ç¹ãä½åããããæ°ããã
vector<int> bp[N];
vector<pair<int,int> > ep[N];

/*
  åãã¤ã³ãã«ã¤ãã¦ãä¸è§å½¢ã®å·¦ç«¯ã¨å³ç«¯ããããã¹ã¨ãã®æ°ãè¦ãã¦ããã
  ãã¨ã¯å·¦ç«¯ããå¨é¨è¦ã¦ããã¨ãã®è¡ã®ãã¡ä½åãéãè¼ªã´ã ã«è¦ããã¦ãããããããã
 */
int solve(int n){
  rep(i,2)rep(j,n+1)st[i][j].left = 0,st[i][j].right = 0;
  int ret = 0;
  REP(i,1,n+1){
    rep(j,i+1){
      int l = 0,r = 0;
      if (j-1 >= 0)r = st[0][j-1].right;
      if (j != i)l = st[0][j].left;
      st[1][j].left  = l;
      st[1][j].right = r;
    }
    rep(j,bp[i].size()){
      st[1][bp[i][j]].left++;
      st[1][bp[i][j]].right++;
    }

    /*
    cout <<i <<" -th line" << endl;
    rep(j,i+1){
      cout << "(" <<st[i][j].left <<"," << st[i][j].right << ") ";
    }
    cout << endl;
    */

    int k = 0;
    rep(j,i+1){
      k += st[1][j].left;
      if (k)ret++;
      k -= st[1][j].right;
      assert(k >= 0);
    }
    rep(j,ep[i].size()){
      st[1][ep[i][j].left].left--;
      st[1][ep[i][j].right].right--;
    }
    rep(j,i+1){
      st[0][j] = st[1][j];
      st[1][j].left = 0;
      st[1][j].right = 0;
    }
  }
  return ret;
}

/**/
main(){
  int n,m;
  while(cin>>n>>m){
    rep(i,N){
      bp[i].clear();
      ep[i].clear();
    }
    rep(i,m){
      int a,b,x;
      cin>>a>>b>>x;
      //(Ai, Bi), (Ai + Xi, Bi), (Ai + Xi, Bi + Xi) 
      bp[a].push_back(b);
      ep[a+x].push_back(make_pair(b,b+x));
      //epR[a+x][b+x]++;
    }
    cout << solve(n) << endl;
  }
}

Measured memory_bytes: 10000
H,W = map(int, input().split())
A = []
B = []
for i in range(H):
  a = list(input())
  if a != ["."]*W:
    A.append(a)
for i in range(W):
  cnt = 0
  for j in range(len(A)):
    if A[j][i] != ".":
      cnt += 1
  if cnt == 0:
    B.insert(0,i)
for i in range(len(A)):
  for j in range(len(B)):
    del A[i][B[j]]
for i in range(len(A)):
  ans = "".join(A[i])
  print(ans)

Measured memory_bytes: 3188
#include <iostream>
#include <string>
#include <vector>
#include <queue>
#include <deque>
#include <stack>
#include <set>
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <cstring>
#include <cmath>
#include <cstdlib>
#include <algorithm>
#include <random>
#include <iomanip>
#include <functional>
#include <cassert>

using namespace std;

typedef long long ll;

const int L = 1e5 + 7;
int dp[1 << 10][L];

const int K = 9;

int main() {
  ios_base::sync_with_stdio(false); cin.tie(0);
#ifdef LOCAL
  freopen("input.txt", "r", stdin);
#endif
  int n;
  cin >> n;
  vector <int> v(n), w(n);
  for (int i = 0; i < n; ++i) cin >> v[i] >> w[i];
  vector <int> h(n);
  vector <int> par(n);
  function <void(int)> dfs = [&] (int u) {
    if (h[u] <= K) {
      if (u == 0) {
        dp[u][w[u]] = v[u];
      } else {
        for (int i = 0; i < L; ++i) {
          dp[u][i] = dp[par[u]][i];
          if (i >= w[u]) {
            dp[u][i] = max(dp[u][i], dp[par[u]][i - w[u]] + v[u]);
          }
        }
      }
      for (int i = 1; i < L; ++i) dp[u][i] = max(dp[u][i], dp[u][i - 1]);
    }

    if (2 * u + 1 < n) {
      h[2 * u + 1] = h[u] + 1;
      par[2 * u + 1] = u;
      dfs(2 * u + 1);
    }
    if (2 * u + 2 < n) {
      h[2 * u + 2] = h[u] + 1;
      par[2 * u + 2] = u;
      dfs(2 * u + 2);
    }
  };
  dfs(0);
  par[0] = -1;
  int q;
  cin >> q;
  for (int i = 0; i < q; ++i) {
    int u, l;
    cin >> u >> l;
    --u;
    if (h[u] <= K) {
      cout << dp[u][l] << '\n';
    } else {
      vector <int> who;
      while (h[u] > K) {
        who.push_back(u);
        u = par[u];
      }
      int ans = 0;
      function <void(int, int, int)> rec = [&] (int pos, int sw, int sv) {
        if (pos == (int)who.size()) {
          if (sw <= l) {
            ans = max(ans, dp[u][l - sw] + sv);
          }
        } else {
          rec(pos + 1, sw, sv);
          rec(pos + 1, sw + w[who[pos]], sv + v[who[pos]]);
        }
      };
      rec(0, 0, 0);
      cout << ans << '\n';
    }   
  }
}



Measured memory_bytes: 406996
h,w,a,b = map(int,input().split())
n = h+w
mod = 10**9+7
fun = [1]*(n+1)
for i in range(1,n+1):
    fun[i] = fun[i-1]*i%mod
rev = [1]*(n+1)
rev[n] = pow(fun[n],mod-2,mod)
for i in range(n-1,0,-1):
    rev[i] = rev[i+1]*(i+1)%mod
def nCr(n,r):
    if r > n:
        return 0
    return fun[n]*rev[r]%mod*rev[n-r]%mod
ans = 0
i = h-a
j = b+1
while i > 0 and j <= w:
  ans = (ans+nCr(i+j-2,i-1)*nCr(h+w-i-j,h-i)%mod)%mod
  i -= 1
  j += 1
print(ans)

Measured memory_bytes: 18804
#include <bits/stdc++.h>
using namespace std;
int main(void){
    
    long long int a, cnt = 0, money = 100;
    cin >> a ;

    while(1){
        money += money / 100;
        cnt++;
        if(money >= a){
            break;
        }
        
    }

    cout << cnt << endl;

    return 0; 
}


Measured memory_bytes: 3608
#include <iostream>
#include <vector>
#include <algorithm>
typedef long long ll;
#define rep(i, n) for(int i = 0; i < (n); ++i)
using namespace std;

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

  int n; cin >> n;
  vector<ll> a(n);
  rep(i, n) {
    int tmp; cin >> tmp;
    a[i] = tmp-(i+1);
  }
  sort(a.begin(), a.end());
  ll mid = a[n/2];

  ll ans = 0;
  rep(i, n) {
    ans += abs(a[i]-mid);
  }

  cout << ans << '\n';
  return 0;
}


Measured memory_bytes: 1792
#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++)
#define all(n) begin(n), end(n)
struct cww
{
    cww()
    {
        ios::sync_with_stdio(false);
        cin.tie(0);
    }
} star;
const long long INF = numeric_limits<long long>::max();
typedef long long ll;
typedef vector<int> vint;
typedef vector<char> vchar;
typedef vector<vector<int>> vvint;
typedef vector<ll> vll;
typedef vector<vector<ll>> vvll;
typedef unsigned long long ull;
template <class T>
bool chmax(T &a, const T &b)
{
    if (a < b)
    {
        a = b;
        return 1;
    }
    return 0;
}
template <class T>
bool chmin(T &a, const T &b)
{
    if (b < a)
    {
        a = b;
        return 1;
    }
    return 0;
}
template <typename T>
vector<T> make_v(size_t a) { return vector<T>(a); }

template <typename T, typename... Ts>
auto make_v(size_t a, Ts... ts)
{
    return vector<decltype(make_v<T>(ts...))>(a, make_v<T>(ts...));
}
template <typename T, typename V>
typename enable_if<is_class<T>::value == 0>::type
fill_v(T &t, const V &v) { t = v; }

template <typename T, typename V>
typename enable_if<is_class<T>::value != 0>::type
fill_v(T &t, const V &v)
{
    for (auto &e : t)
        fill_v(e, v);
}
struct UnionFind
{
    vector<int> data;

    UnionFind(int sz)
    {
        data.assign(sz, -1);
    }

    bool unite(int x, int y)
    {
        x = find(x), y = find(y);
        if (x == y)
            return (false);
        if (data[x] > data[y])
            swap(x, y);
        data[x] += data[y];
        data[y] = x;
        return (true);
    }

    int find(int k)
    {
        if (data[k] < 0)
            return (k);
        return (data[k] = find(data[k]));
    }

    int size(int k)
    {
        return (-data[find(k)]);
    }
    bool same(int x, int y)
    {
        return find(x) == find(y);
    }
};

int main()
{
    int N,M;
    cin>>N>>M;
    vint a(M),b(M);
    for (size_t i = 0; i < M; i++)
    {
        cin>>a[i]>>b[i];
        a[i]--;b[i]--;
    }
    int ans=0;
    for (size_t i = 0; i < M; i++)
    {
        UnionFind uf(N);
        for (size_t j = 0; j < M; j++)
        {
            if(i==j)continue;
            uf.unite(a[j],b[j]);
        }
        set<int> par;
        for (size_t i = 0; i < N; i++)
        {
            par.insert(uf.find(i));
        }
        if(par.size()>1)
        {
            ans++;
        }
    }
    cout<<ans;
    return 0;
}

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

count = 0
for i in range(A + 1):
    for j in range(B + 1):
        for k in range(C + 1):
            if (500 * i + 100 * j + 50 * k) == X:
                count += 1


print(count)

Measured memory_bytes: 39536
import java.util.*;
import java.io.*;

public class Main{

	public static void main(String[] args) throws IOException {
		
		int N = readInt(), A = readInt(), B = readInt();
		
		int mid = (A+B)/2, mid2 = mid+1;
		
		if(Math.abs(mid-A) <= Math.abs(mid2-B)) println("Borys");
		else println("Alice");
		exit();
	}

	static BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
	static StringTokenizer st;

	static String next() throws IOException {
		while (st == null || !st.hasMoreTokens())
			st = new StringTokenizer(br.readLine().trim());
		return st.nextToken();
	}

	static long readLong() throws IOException {
		return Long.parseLong(next());
	}

	static float readFloat() throws IOException {
		return Float.parseFloat(next());
	}

	static boolean readBoolean() throws IOException {
		return Boolean.parseBoolean(next());
	}

	static short readShort() throws IOException {
		return Short.parseShort(next());
	}

	static byte readByte() throws IOException {
		return Byte.parseByte(next());
	}

	static int readInt() throws IOException {
		return Integer.parseInt(next());
	}

	static double readDouble() throws IOException {
		return Double.parseDouble(next());
	}

	static char readCharacter() throws IOException {
		return next().charAt(0);
	}

	static String readLine() throws IOException {
		return br.readLine().trim();
	}

	static PrintWriter pr = new PrintWriter(new BufferedWriter(new OutputStreamWriter(System.out)));

	static void print(Object o) {
		pr.print(o);
	}

	static void println(Object o) {
		pr.println(o);
	}

	static void flush() {
		pr.flush();
	}

	static void exit() throws IOException {
		br.close();
		pr.close();
		System.exit(0);
	}
}


Measured memory_bytes: 23252
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <cmath>
#include <map>
#include <queue>
#include <iomanip>
#define MOD 1000000007
typedef long long ll;
using namespace std;

int main(){
  char c;
  cin>>c;
  if(c=='A') c='T';
  else if(c=='T') c='A';
  else if(c=='C') c='G';
  else c='C';
  cout<<c<<endl;

  return 0;
}


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

using namespace std;

int main(){
	int N, I, S, P;
	char com;
	map<int, int>::iterator it;
	
	while(cin >> N, N){
		map<int,int> data;
		data.insert( make_pair(0, -1) );
		data.insert( make_pair(1000000001, -2) );
		while(N--){
			cin >> com;
			switch( com ){
				case 'W':
					cin >> I >> S;
					for(it = data.begin(); it!=data.end();){
						if( it->second == -1 ){
							int b = it->first;
							it->second = I;
							it++;
							if( it->first - b > S ){
								data.insert( make_pair(b+S, -1) );
								break;
							}else if( it->first - b == S ){
								break;
							}else{
								S -= it->first - b;
							}
						}else it++;
					}
					break;
				case 'D':
					cin >> I;
					for(it = data.begin(); it!=data.end(); it++){
						if( it->second == I )
							it->second = -1;
					}
					break;
				case 'R':
					cin >> P;
					int ans = -1;
					for(it = data.begin(); it!=data.end(); it++){
						if( it->first <= P )
							ans = it->second;
					}
					cout << ans << endl;
					break;
			}
//			cout << "command comp" << endl;
		}
		cout << endl;
	}
	
	return 0;
}

Measured memory_bytes: 1408
#!usr/bin/env python3
from collections import defaultdict
from heapq import heappush, heappop
import sys
import math
import bisect
import random
def LI(): return list(map(int, sys.stdin.readline().split()))
def I(): return int(sys.stdin.readline())
def LS():return list(map(list, sys.stdin.readline().split()))
def S(): return list(sys.stdin.readline())[:-1]
def IR(n):
    l = [None for i in range(n)]
    for i in range(n):l[i] = I()
    return l
def LIR(n):
    l = [None for i in range(n)]
    for i in range(n):l[i] = LI()
    return l
def SR(n):
    l = [None for i in range(n)]
    for i in range(n):l[i] = S()
    return l
def LSR(n):
    l = [None for i in range(n)]
    for i in range(n):l[i] = SR()
    return l
mod = 1000000007

#A

#B

#C
"""
n,a = LI()
x = LI()
s = sum(x)
dp = [[[0 for i in range(s+1)] for j in range(n+1)] for k in range(n+1)]
for i in range(n+1):
    dp[i][0][0] = 1
for i in range(1,n+1):
    for j in range(1,n+1):
        for k in range(s+1):
            if k >= x[i-1]:
                dp[i][j][k] = dp[i-1][j][k]+dp[i-1][j-1][k-x[i-1]]
            else:
                dp[i][j][k] = dp[i-1][j][k]
ans = 0
for i in range(1,n+1):
    if a*i <= s:
        ans += dp[n][i][a*i]
print(ans)
"""

#D
def f(b,n):
    m = n
    res = 0
    while m > 0:
        res += m%b
        m //= b
    return res
n,s = IR(2)
if n == s:
    print(n+1)
    quit()
if n == 1:
    print(-1)
    quit()
k = int(n**0.5)
for b in range(2,k+1):
    if f(b,n) == s:
        print(b)
        quit()
for p in range(1,k+1)[::-1]:
    if (n-s)%p == 0:
        b = (n-s)//p+1
        if b != 0:
            if f(b,n) == s:
                print(b)
                quit()
print(-1)

#E

#F

#G

#H

#I

#J

#K

#L

#M

#N

#O

#P

#Q

#R

#S

#T


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

const int maxw = 1e5;
int n, W;
long long dp[maxw+2], dp1[maxw+2];

int main()
{
    int w, v;
    cin>>n>>W;
    for(int i=1; i<=n; i++)
    {
        cin>>w>>v;
        for(int j=0; j<=W; j++)
        {
            if(w>j)
            {
                dp[j]=dp1[j];
            }
            else
            {
                dp[j]=max(dp1[j],dp1[j-w]+v);
            }
        }
        memcpy(dp1, dp, sizeof dp);
    }
    cout<<dp[W];
    return 0;
}


Measured memory_bytes: 1792
#include<iostream>
#include<vector>
#include<set>
#include<algorithm>
#include<queue>
#include<functional>
#include<numeric>
#include<limits>
#include<boost/multi_array.hpp>
constexpr auto mod = 1000000007ull;

int main()
{
	std::ios::sync_with_stdio(false);
	long long N, A, B;
	std::cin >> N >> A >> B;
	if (A > B)
		std::swap(A, B);
	std::vector<unsigned long long> dp(N + 1);
	std::vector<long long> data = { -1000000000000000000 };
	int start = 0;
	int last = 0;
	dp[0] = 1;
	unsigned long long sum{};
	for (int i = 1;i <= N;++i)
	{
		long long d;
		std::cin >> d;
		data.emplace_back(d);
		if (i >= 2 && data[i] - data[i - 2] < A)
		{
			std::cout << 0 << std::endl;
			return 0;
		}
		for (int j = last;data[i] - data[j] >= B;++j)
		{
			++last;
			sum += dp[j];
			sum %= mod;
		}
		dp[i] += sum;
		dp[i] %= mod;
		if (data[i] - data[i - 1] < A)
		{
			dp[i - 1] = dp[i - 1];
			for (int j = start;j < i - 1 && j < last;++j)
			{
				sum += mod - dp[j];
				sum %= mod;
			}
			if (sum == 0)
			{
				last = i - 1;
			}
			start = i - 1;
		}
	}
	unsigned long long ret{};
	for (int i = start;i <= N;++i)
	{
		auto v = dp[i];
		ret += v;
		ret %= mod;
	}
	std::cout << ret << std::endl;
}

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

using namespace std;

double distance(const vector<int>& p1, const vector<int>& p2) {

	int p1_size = p1.size();
	double d = 0;

	if (p1_size != p2.size()) return 0.1; // 問題に影響しないように整数じゃない値を返す

	for (int i = 0; i < p1_size; ++i) {
		d += pow(abs(p1[i] - p2[i]), 2);
	}

	return sqrt(d);
}

int main(void) {

	int N, D, integer = 0;
	double d;

	cin >> N >> D;

	vector<vector<int>> X;

	for (int i = 0; i < N; ++i) {
		vector<int> point(D);
		for (int j = 0; j < D; ++j) {
			cin >> point[j];
		}
		X.push_back(point);
	}

	for (int i = 0; i < N - 1; ++i) {
		for (int j = i + 1; j < N; ++j) {
			d = distance(X[i], X[j]);

			if (ceil(d) == floor(d)) integer++;
		}
	}

	cout << integer << endl;

	return 0;
}

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

typedef long long ll;

ll n;
vector<pair<ll,int>> dvs;

int main(){

    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);

    cin>>n;
    for(ll i=2;i*i<=n;i++){
        if(n%i==0){
            dvs.push_back(make_pair(i,0));
            while(n%i==0){
                dvs.back().second++;
                n/=i;
            }
        }
    }
    if(n>1){
        dvs.push_back(make_pair(n,1));
    }
    int ans=0;
    for(pair<ll,int> &p:dvs){
        int i=1;
        for(;(1+i)*i/2<=p.second;i++);
        i--;
        ans+=i;
    }
    cout<<ans<<endl;

    return 0;
}

Measured memory_bytes: 3652
#include<map>
#include<set>
#include<stack>
#include<queue>
#include<cmath>
#include<cstring>
#include<climits>
#include<cstdio>
#include<iostream>
#include<algorithm>
using namespace std;
#define LL long long
//#define getchar() (p1 == p2 && (p2 = (p1 = buf) + fread(buf, 1, 1 << 21, stdin), p1 == p2) ? EOF : *p1++)
//char buf[(1 << 21) + 1], *p1 = buf, *p2 = buf;
inline int read() {
	bool f=0;int x=0;char c=getchar();
	while(c<'0'||'9'<c){if(c==EOF)exit(0);if(c=='-')f=1;c=getchar();}
	while('0'<=c&&c<='9') x=(x<<3)+(x<<1)+(c^48),c=getchar();
	return !f?x:-x;
}
#define MAXN 2000
#define INF 0x3f3f3f3f
#define Mod 924844033
bool cut[2*MAXN+5];
LL f[2*MAXN+5][2*MAXN+5][2],fac[MAXN+5];
int main(){
	fac[0]=1;
	for(int i=1;i<=MAXN;i++)
		fac[i]=fac[i-1]*i%Mod;
	int n=read(),k=read(),cnt=0;
	for(int i=1;i<=k;i++)
		for(int t=0;t<=1;t++)
			for(int j=i;j<=n;j+=k){
				++cnt;
				if(j==i)
					cut[cnt]=1;
			}
	f[1][0][0]=1;
	for(int i=2;i<=2*n;i++)
		for(int j=0;j<=n;j++){
			f[i][j][0]=(f[i-1][j][1]+f[i-1][j][0])%Mod;
			if((!cut[i])&&j)
				f[i][j][1]=f[i-1][j-1][0];
		}
	LL ans=0;
	for(int j=0;j<=n;j++)
		ans=(ans+(j&1?-1:1)*(f[2*n][j][0]+f[2*n][j][1])*fac[n-j]%Mod)%Mod;
	ans=(ans+Mod)%Mod;
	printf("%lld\n",ans);
	return 0;
}


Measured memory_bytes: 249472
#include<bits/stdc++.h>
using namespace std;
int main()
{
	int n;
	cin>>n;
	int a[n],b[n],c[n];
	int i=0;
	int k=n;
	while(k--)
	{
		//for(int i=0;i<n;i++)
		cin>>a[i]>>b[i]>>c[i];
		//cout<<a[i]<<" "<<b[i]<<" "<<c[i]<<"\n";
		i++;
	}
	int dp[n+1][4];
	
	dp[1][1]=a[0];
	dp[1][2]=b[0];
	dp[1][3]=c[0];
	for(int i=2;i<=n;i++)
	{
		dp[i][1]=a[i-1]+ std::max(dp[i-1][2],dp[i-1][3]);
		dp[i][2]=b[i-1]+ std::max(dp[i-1][1],dp[i-1][3]);
		dp[i][3]=c[i-1]+ std::max(dp[i-1][2],dp[i-1][1]);
	}
	cout<<std::max(dp[n][1],std::max(dp[n][2],dp[n][3]))<<"\n";
}

Measured memory_bytes: 2944
import sys
from collections import deque

def main():
    input = sys.stdin.readline
    S = deque([s for s in str(input().strip())])
    cnt = 0
    p = ''
    t = ''
    while len(S) > 0:
        t += S.popleft()
        if p != t:
            cnt += 1
            p = t
            t = ''

    return cnt

if __name__ == '__main__':
    print(main())


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

int main() {
  int a,b,c;
  cin >> a >> b >> c;
  if (a + b == c) {
    cout << "Yes" << endl;
  }
  else if (a + c == b) {
    cout << "Yes" << endl;
  }
  else if (b + c == a) {
    cout << "Yes" << endl;
  }
  else {
    cout << "No" << endl;
  }
}

Measured memory_bytes: 256
/* "It's okay if you hate me. I hate me too." */

#include <bits/stdc++.h>

using namespace std;

typedef long long LL;

const int maxN = (int)1E5+5;
const int MOD = (int)1E9+7;

int n;
int a[maxN];
int p[maxN];
int fact[maxN];
int l, r;

int powMOD(int x, int m) {
	int p = 1;
	while (m) {
		if (m&1) p = ((LL)p*x)%MOD;
		x = ((LL)x*x)%MOD;
		m >>= 1;
	}
	return p;
}

class CombN {
private:
	int N;
	int* res;
	int* temp;
public:
	CombN(int N) {
		this->N = N;
		this->res = new int[N+1];
		this->temp = new int[N+1];
		
		this->temp[N] = N;
		for (int i = N-1; i >= 1; --i) 
			this->temp[i] = ((LL)i*this->temp[i+1])%MOD;
		this->res[0] = 1;
		for (int i = 1; i <= N; ++i)
			this->res[i] = ((LL)powMOD(fact[i], MOD-2)*this->temp[N-i+1])%MOD;
	}

	int comb(int k) {
		if (k < 0 || k > N) return 0;
		return this->res[k];
	}

	~CombN() {
		delete[] this->res;
		delete[] this->temp;
	}
};

int main() {
	scanf("%d", &n);
	memset(p, 255, sizeof(p));
	for (int i = 1; i <= n+1; ++i) {
		scanf("%d", &a[i]);
		if (p[a[i]] == -1)
			p[a[i]] = i;
		else {
			l = p[a[i]];
			r = i;
		}
	}
	fact[0] = 1;
	for (int i = 1; i <= n+1; ++i)
		fact[i] = ((LL)fact[i-1]*i)%MOD;
	CombN Total(n+1);
	CombN Compl(n+1-r+l-1);
	for (int i = 1; i <= n+1; ++i) {
		printf("%d\n", (Total.comb(i)-Compl.comb(i-1)+MOD)%MOD);
	}
	return 0;
}


Measured memory_bytes: 3968
function main()
  
  (N, M) = map(x -> parse(Int, x), split(readline()))
  
  a = zeros(Int, 2N)
  for i in 1:M
    a[i] = parse(Int, readline()) + 1
  end
    
  ans = zeros(Int, 2N)
  num = 1
  
  for i in 1:N+1
    if i == 1
      ans[i] = 1
    elseif i == 2
      if a[num] == 2
        ans[i] = 0
        num += 1
      else
        ans[i] = 1
      end
    elseif a[num] == i
      num += 1
    else
      ans[i] = ans[i-1] + ans[i-2]
      ans[i] %= 1000000007
    end
  end
  
  println(ans[N+1])
  
end

main()

Measured memory_bytes: 144476
def retMin(a,b):
  if a >= b:
    return b
  else:
    return a  
 
n=int(input())
r=list(map(int,input().split()))
dpList = [99999999999] * (n)
 
dpList[0] = 0
dpList[1] = dpList[0]+(abs(r[1]-r[0]))
 
for i in range(2,n):
  dpList[i] = retMin(dpList[i-1]+(abs(r[i]-r[i-1])),dpList[i-2]+(abs(r[i]-r[i-2])))
  
print(dpList[n-1])

Measured memory_bytes: 52208
import java.util.*;
public class Main{
	public static void main(String[] args){
    	Scanner sc = new Scanner(System.in);
      	int[] a = new int[2];
      	a[0] = sc.nextInt();
      	a[1] = sc.nextInt();
      	int sum = 0;
      
      	Arrays.sort(a);
      	sum += a[1];
      	a[1]--;
      	Arrays.sort(a);
      	sum += a[1];
      	a[1]--;
      	System.out.println(sum);
    }
}

Measured memory_bytes: 35752
def main():
    N, A, B = list(map(int, input().split()))
    if (A ^ B) & 1:
        return min((A - 1) + 1 + (B - A - 1) // 2,
                   (N - B) + 1 + (N - (A + N - B + 1)) // 2)
    return (B - A) // 2

print(main())


Measured memory_bytes: 2940
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define rep(i,n)   FOR(i,0,n)
#define pb emplace_back
typedef long long ll;
typedef pair<int,int> pint;

int n;
int a[200001];
int main(){
    cin>>n;
    rep(i,n) cin>>a[i];
    int cur=0;
    rep(i,n)if(cur+1==a[i]) ++cur;
    if(cur==0) cout<<-1<<endl;
    else cout<<n-cur<<endl;
    return 0;
}

Measured memory_bytes: 1024
#include<bits/stdc++.h>
#include<iostream>
#include<cstdio>
#include<vector>
#include<string>
#include<algorithm>
#include<map>
using namespace std;
#define rep(i,x) for(ll i = 0; i < (ll)(x); i++)
#define pb push_back
#define eb emplace_back
#define debug(x) cerr << #x << ": " << (x) << "\n";
#define all(x) (x).begin(), (x).end()
typedef long long ll;
typedef long double ld;
typedef pair<int,int> P;
typedef pair<ll,ll> Pll;
typedef vector<ll> vl;
typedef vector<vector<ll>> vvl;
typedef vector<vector<vector<ll>>> vvvl;
const ll INF = numeric_limits<ll>::max()/4;
const ll MOD = 1e9+7;
const int n_max = 1e5+10;


ll n;
class neig {
    public:
    neig(){};
    template<class T>
    neig(T id){
        if(id == 0){pre = n-1; nex = 1;}
        else if(id == n-1){pre = n-2; nex = 0;}
        else{pre = id - 1; nex = id + 1;}
    }
    ll pre, nex;
};

ll ceil(ll a,ll b){
    return (a + b - 1) / b;
};

int main(){
    cin >> n;
    vector<ll> a(n);
    rep(i,n) cin >> a[i];
    priority_queue<Pll> pq;
    vector<ll> b(n);
    rep(i,n) {
        cin >> b[i];
        if(b[i] != a[i])pq.push({b[i], i});
    }
    bool ok = true;
    ll ans = 0;
    while(pq.size()){
        Pll temp = pq.top();pq.pop();
        neig tn = neig(temp.second);
        ll sum = b[tn.pre] + b[tn.nex];
        // debug(temp.first);debug(temp.second);
        // debug(sum);
        if(temp.first < sum){ok = false;break;}
        // if(temp.first == a[temp.second])continue;
        if(temp.first > max(a[temp.second], sum)){
            ll t = temp.first % sum;
            if(t < a[temp.second] ){
                if((b[temp.second] - a[temp.second]) % sum != 0){
                    ok = false;
                    break;
                }
            }
            ans += (b[temp.second] - max(t, a[temp.second])) / sum;
            b[temp.second] = max(t, a[temp.second]);
        }
        if(b[temp.second] != a[temp.second])pq.push({b[temp.second], temp.second});
    }

    cout << (ok ? ans : -1) << endl;
}

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

#define rep(i, n) for(int (i) = 0; (i) < (n); (i)++)
#define repn(i, n) for(int (i) = 1; (i) <= (n); (i)++)
#define repr(i, n) for(int (i) = (n-1); (i) >= 0; (i)--)
#define all(x) (x).begin(), (x).end()
#define lint long long
#define ulint unsigned long long
#define fi first
#define se second

typedef pair<lint, lint> P;
const lint MOD = 1e9+7;
const lint INF = MOD * MOD;
const int MAX = 100005;

int main(){
    int n, k; cin >> n >> k;
    lint a = 0;
    for(int b = k + 1; b <= n; b++){
        int p = n / b, q = n % b;
        if(q >= k && k != 0) a += (q - k + 1);
        if(q > k && k == 0) a += q;
        a += (b-k) * p;
    }
    cout << a << endl;
}


Measured memory_bytes: 764
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#include<cstdlib>
#include<cmath>

bool dfs(char board[8][8], bool v_used[], bool h_used[], bool dr_used[], bool dl_used[], int x, int y, int num) {
	if (num == 8) return true;
	for (int i = 0; i < 8; i++) {
		if (h_used[i]) continue;
		for (int j = 0; j < 8; j++) {
			if (board[i][j] != 'Q') {
				if (!v_used[j] && !h_used[i] && !dr_used[8 - j + i - 1] && !dl_used[i + j]) {
					v_used[j] = h_used[i] = dr_used[8 - j + i - 1] = dl_used[i + j] = true;
					board[i][j] = 'Q';
					bool ret = dfs(board, v_used, h_used, dr_used, dl_used, i, j, num + 1);
					if (ret) return true;
					v_used[j] = h_used[i] = dr_used[8 - j + i - 1] = dl_used[i + j] = false;
					board[i][j] = '.';
				}
			}
		}
	}
	return false;
}

int main() {
	int n;
	bool v_used[8], h_used[8], dr_used[16], dl_used[16];
	char board[8][8];

	// ?????????????????????
	for (int i = 0; i < 8; i++) {
		for (int j = 0; j < 8; j++) {
			board[i][j] = '.';
		}
		v_used[i] = h_used[i] = false;
	}

	for (int i = 0; i < 16; i++) {
		dr_used[i] = dl_used[i] = false;
	}

	std::cin >> n;

	for (int i = 0; i < n; i++) {
		int x, y;
		std::cin >> x >> y;
		board[x][y] = 'Q';

		v_used[y] = true;
		h_used[x] = true;
		dr_used[8 - y + x - 1] = true;
		dl_used[x + y] = true;
	}

	if (n == 8) {
		for (int k = 0; k < 8; k++) {
			for (int l = 0; l < 8; l++) {
				std::cout << board[k][l];
			}
			std::cout << std::endl;
		}
		return 0;
	}

	for (int i = 0; i < 8; i++) {
		if (h_used[i]) continue;
		for (int j = 0; j < 8; j++) {
			if (board[i][j] != 'Q') {
				if (!v_used[j] && !h_used[i] && !dr_used[8 - j + i - 1] && !dl_used[i + j]) {
					v_used[j] = h_used[i] = dr_used[8 - j + i - 1] = dl_used[i + j] = true;
					board[i][j] = 'Q';
					bool ret = dfs(board, v_used, h_used, dr_used, dl_used, i, j, n + 1);
					if (ret) {
						for (int k = 0; k < 8; k++) {
							for (int l = 0; l < 8; l++) {
								std::cout << board[k][l];
							}
							std::cout << std::endl;
						}
						return 0;
					}
					v_used[j] = h_used[i] = dr_used[8 - j + i - 1] = dl_used[i + j] = false;
					board[i][j] = '.';
				}
			}
		}
	}


}

Measured memory_bytes: 3116
#include <algorithm>
#include <cmath>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <vector>
#define repeat(i, n) for (int i = 0; (i) < (n); ++(i))
#define repeat_from(i, m, n) for (int i = (m); (i) < (n); ++(i))
using namespace std;
template <class T>
void setmax(T &a, T const &b) {
    if (a < b) a = b;
}

template <class T>
void setmin(T &a, T const &b) {
    if (a > b) a = b;
}

template <typename T, typename X>
auto vectors(T a, X x) { return vector<T>(x, a); }

template <typename T, typename X, typename Y, typename... Zs>
auto vectors(T a, X x, Y y, Zs... zs) {
    auto cont = vectors(a, y, zs...);
    return vector<decltype(cont)>(x, cont);
}

const int MAX_AI = 1000010;
#define PRINT(X) cout << #X << " : " << X << endl

// dpのはずなんだけど、計算量がO(HW)だと無理そう、、、
// あとで解く
// あとで遅延セグ木で解く

int main() {
    int H, W;
    cin >> H >> W;

    set<pair<int, int>> se;  // first := 今の地点 second := 開始地点
    multiset<int> dist;

    repeat(i, W) {
        se.emplace(i, i);
        dist.insert(0);
    }

    repeat(i, H) {
        int A, B;
        cin >> A >> B;
        --A;  // [A, B) 0-indexed
        auto itr = se.lower_bound(make_pair(A, -1));
        int max_r = -1;
        while (itr != se.end() && itr->first < B) {
            setmax(max_r, itr->second);
            dist.erase(dist.find(itr->first - itr->second));
            se.erase(itr++);
        }
        if (max_r != -1 && B < W) {
            se.emplace(B, max_r);
            dist.insert(B - max_r);
        }
        if (!dist.empty()) {
            cout << (*dist.begin()) + i + 1 << endl;
        } else {
            cout << -1 << endl;
        }
    }
    return 0;
}

Measured memory_bytes: 22224
//
// Created by nori on 19/09/11.
//

#include <bits/stdc++.h>

using namespace std;

int main() {
    int N, K, cnt=0;

    cin >> N >> K;
    vector<int> h(N);
    for (int i = 0; i < N; i++) {
        cin >> h.at(i);
        if(h.at(i) >= K){
            cnt++;
        }
    }
    cout << cnt << endl;
}

Measured memory_bytes: 640
#include<iostream>
#include<stdio.h>
#include<vector>
#include<algorithm>
#include<set>
#include<string>
#include<map>
#include<string.h>
#include<complex>
#include<math.h>
#include<queue>
#include<time.h>
using namespace std;
typedef long long int llint;
typedef pair<int, int> pint;
typedef vector<int> vint;
typedef vector<llint> vllint;
typedef vector<pair<int, int>> vpint;
typedef vector<pair<llint, llint>> vpllint;
#define rep(i,n) for(int i=0;i<n;i++)
#define drep(i,n) for(int i=n-1;0<=i;i--)
#define yes(ans) if(ans)cout<<"yes"<<endl;else cout<<"no"<<endl;
#define Yes(ans) if(ans)cout<<"Yes"<<endl;else cout<<"No"<<endl;
#define YES(ans) if(ans)cout<<"YES"<<endl;else cout<<"NO"<<endl;
#define POSSIBLE(ans) if(ans)cout<<"POSSIBLE"<<endl;else cout<<"IMPOSSIBLE"<<endl;

class UnionFind {
public:
	//親の番号を格納する。親だった場合は-(その集合のサイズ)
	vector<int> Parent;

	//作るときはParentの値を全て-1にする
	//こうすると全てバラバラになる
	UnionFind(int N) {
		Parent = vector<int>(N, -1);
	}

	//Aがどのグループに属しているか調べる
	int root(int A) {
		if (Parent[A] < 0) return A;
		return Parent[A] = root(Parent[A]);
	}

	//自分のいるグループの頂点数を調べる
	int size(int A) {
		return -Parent[root(A)];//親をとってきたい
	}

	//AとBをくっ付ける
	bool connect(int A, int B) {
		//AとBを直接つなぐのではなく、root(A)にroot(B)をくっつける
		A = root(A);
		B = root(B);
		if (A == B) {
			//すでにくっついてるからくっ付けない
			return false;
		}

		//大きい方(A)に小さいほう(B)をくっ付けたい
		//大小が逆だったらひっくり返しちゃう。
		if (size(A) < size(B)) swap(A, B);

		//Aのサイズを更新する
		Parent[A] += Parent[B];
		//Bの親をAに変更する
		Parent[B] = A;

		return true;
	}
};

//aとbの最大公約数を求めるよ
long long GCD(long long a, long long b) {
	if (b == 0) return a;
	else return GCD(b, a % b);
}

// 返り値: a と b の最大公約数
// ax + by = gcd(a, b) を満たす (x, y) が格納される
long long extGCD(long long a, long long b, long long& x, long long& y) {
	if (b == 0) {
		x = 1;
		y = 0;
		return a;
	}
	long long d = extGCD(b, a % b, y, x);
	y -= a / b * x;
	return d;
}

bool check(int a, int b) {
	return a > b;
}

int main() {
	int n, x;
	cin >> n >> x;
	vint l(n);
	rep(i, n) {
		cin >> l[i];
	}
	int now = 0;
	int ans = 1;
	rep(i, n) {
		now += l[i];
		if (now <= x)ans++;
		else {
			break;
		}
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 256
INF = 10 ** 15
MOD = 10 ** 9 + 7

def beruman(n,X,edges,start = 0,negative_loop = False):
    ans = False #startを含む負の閉路が存在するか
    dist = [INF] * n
    dist[start] = 0

    for i in range(X):
        update = False
        for a,b,c in edges:
            if dist[a] != INF and dist[b] > dist[a] + c:
                dist[b] = dist[a] + c
                update = True

        if not update:
            break
        if i == X - 1:
            ans = True
    
    if negative_loop:
        return dist,ans
    else:
        return dist

def dfs(G,can_reach,start):
    stack = [start]
    can_reach[start] = True
    while stack:
        v = stack.pop()
        for e in G[v]:
            if can_reach[e]:
                continue
            stack.append(e)
            can_reach[e] = True
    return can_reach

def main():
    N,M,P = map(int,input().split())
    edges = []
    G = [[] for _ in range(N)]
    G_inv = [[] for _ in range(N)]
    for _ in range(M):
        a,b,c = map(int,input().split())
        a -= 1
        b -= 1
        edges.append((a,b,P - c))
        G[a].append(b)
        G_inv[b].append(a)
    
    can_reach_from_start = [False] * N
    can_reach_from_goal = [False] * N
    dfs(G,can_reach_from_start,0)
    dfs(G_inv,can_reach_from_goal,N - 1)
    in_route = [False] * N
    X = 0
    for i in range(N):
        if can_reach_from_goal[i] and can_reach_from_start[i]:
            in_route[i] = True
            X += 1
        
    edge = []
    for a,b,c in edges:
        if in_route[a] and in_route[b]:
            edge.append((a,b,c))

    dist,flag = beruman(N,X,edge,0,True)
    if flag:
        print(-1)
    else:
        print(max(-dist[-1],0))
if __name__ == '__main__':
    main()


Measured memory_bytes: 50028
from __future__ import division, print_function

def main():
    n = int(input())
    dp = [0, 0, 0]
    for _ in range(n):
        curr_dp = [0, 0, 0]
        c = [int(_) for _ in input().split()]
        for i in range(3):
            for j in range(3):
                if i != j:
                    curr_dp[j] = max(curr_dp[j], dp[i] + c[j])

        dp = curr_dp

    print(max(dp[0], dp[1], dp[2]))


# PyPy 2 Fast IO Template. Made by Pajenegod & C1729
py2 = round(0.5)
if py2:
    from future_builtins import ascii, filter, hex, map, oct, zip
    range = xrange

import os, sys
from io import IOBase, BytesIO

BUFSIZE = 8192
class FastIO(BytesIO):
    newlines = 0

    def __init__(self, file):
        self._file = file
        self._fd = file.fileno()
        self.writable = "x" in file.mode or "w" in file.mode
        self.write = super(FastIO, self).write if self.writable else None

    def _fill(self):
        s = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
        self.seek((self.tell(), self.seek(0,2), super(FastIO, self).write(s))[0])
        return s

    def read(self):
        while self._fill(): pass
        return super(FastIO,self).read()

    def readline(self):
        while self.newlines == 0:
            s = self._fill(); self.newlines = s.count(b"\n") + (not s)
        self.newlines -= 1
        return super(FastIO, self).readline()

    def flush(self):
        if self.writable:
            os.write(self._fd, self.getvalue())
            self.truncate(0), self.seek(0)

class IOWrapper(IOBase):
    def __init__(self, file):
        self.buffer = FastIO(file)
        self.flush = self.buffer.flush
        self.writable = self.buffer.writable
        if py2:
            self.write = self.buffer.write
            self.read = self.buffer.read
            self.readline = self.buffer.readline
        else:
            self.write = lambda s:self.buffer.write(s.encode('ascii'))
            self.read = lambda:self.buffer.read().decode('ascii')
            self.readline = lambda:self.buffer.readline().decode('ascii')

sys.stdin, sys.stdout = IOWrapper(sys.stdin), IOWrapper(sys.stdout)
input = lambda: sys.stdin.readline().rstrip('\r\n')

# Importing Modules
import math
import collections

from collections import Counter
from math import fabs

if __name__ == "__main__":
    main()

Measured memory_bytes: 39916
#include <stdio.h>
#include <string>
#include <cstring>
#include <stdlib.h>
#include <math.h>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <list>
#include <iterator>
#include <assert.h>
#pragma warning(disable:4996) 
 
typedef long long ll;
#define MIN(a, b) ((a)>(b)? (b): (a))
#define MAX(a, b) ((a)<(b)? (b): (a))
#define LINF 9223300000000000000
#define INF 2140000000
const long long MOD = 1000000007;
//const long long MOD = 998244353;
using namespace std;

char str[30000];

int main(int argc, char* argv[])
{
    int n;
    scanf("%d", &n);
    scanf("%s", str);

    set<int> z1,z2,z3;
    int i;
    for(i=0; i<n; i++) {
        int tmp=str[i]-'0';
        {
            auto it=z2.begin();
            for(; it!=z2.end(); ++it) {
                z3.insert((*it)*10+tmp);
            }
        }
        {
            auto it=z1.begin();
            for(; it!=z1.end(); ++it) {
                z2.insert((*it)*10+tmp);
            }
        }
        z1.insert(tmp);
    }
    printf("%d\n", (int)z3.size());

    return 0;
}


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

int  main() {
  long int N, A, B;
  cin >> N >> A >> B;
  long int set = 0, mod = 0, count = 0;
  
  set  =  N / (A + B);
  count += set * A;
  
  mod = N % (A + B);
  
  if (mod < A) {
    count += mod;
  }
  if (mod >= A) {
    count += A;
  }
  cout << count << endl;
}



Measured memory_bytes: 256
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cctype>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#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 <string>
#include <time.h>
#include <tuple>
#include <utility>
#include <vector>
#define ll long long
#define itn int
#define endl '\n'
#define co(ans) cout<<ans<<endl
#define COYE cout<<"YES"<<endl
#define COYe cout<<"Yes"<<endl
#define COye cout<<"yes"<<endl
#define CONO cout<<"NO"<<endl
#define CONo cout<<"No"<<endl
#define COno cout<<"no"<<endl
#define FORE(i,a) for(auto &i:a)
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define FFOR(i,a,b) for(int i=(a);i<=(b);++i)
#define REP(i,n)  FOR(i,0,n)
#define RREP(i,n)  FFOR(i,1,n)
#define PB push_back
#define MP make_pair
#define ALL(V) (V).begin(),(V).end()
#define SORT(V) sort((V).begin(),(V).end())
#define REVERSE(V) reverse((V).begin(),(V).end())
#define EACH(V,i) for(typeof((V).begin()) i=(V).begin();i!=(V).end();++i)
#define equals(a,b) (fabs((a)-(b))<EPS)
#define INF ((1LL<<62)-(1LL<<31))
#define EPS 1e-10
#define PI 3.141592653589793238
#define MOD 1000000007
#define MAX 5100000
using namespace std;
using Edge=pair<int,int>;
using Graph=vector<vector<int>>;
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();}
template<class T>bool chmax(T &a,const T &b){if(a<b){a=b;return 1;}return 0;}
template<class T>bool chmin(T &a,const T &b){if(b<a){a=b;return 1;}return 0;}
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef long long LL;
const int dx[4]={0,1,0,-1},dy[4]={1,0,-1,0};
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
ll lcm(ll a,ll b){return a/gcd(a,b)*b;}

int main(){
  int N;
  cin>>N;
  ll S[N],ans=0LL;
  REP(i,N) cin>>S[i];
  RREP(i,N-1){
    ll cnt=0LL;
    int L=0,R=N-1;
    if((N-1)%i==0){
      while(L<R){
        cnt+=S[L]+S[R];
        chmax(ans,cnt);
        L+=i;
        R-=i;
      }
    }
    else{
      while(L+i<N-1){
        cnt+=S[L]+S[R];
        chmax(ans,cnt);
        L+=i;
        R-=i;
      }
    }
  }
  
  co(ans);
  return 0;
}

Measured memory_bytes: 1024
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
using ll = long long;
#define rep(i, n) for(ll i = 0; i < n; i++)
#define rep2(i, s, n) for(ll i = s; i < n; i++)
#define repr(i, n) for(ll i = n-1; i >= 0; i--)
using namespace std;

int main(){
  ll n;
  cin >> n;
  vector<ll> l(n);
  rep(i, n) cin >> l[i];
  sort(l.begin(), l.end());
  ll ans = 0;
  repr(i, n)repr(j, i){
    auto itr = lower_bound(l.begin(), l.end(), l[i] + l[j]);
    ll ng = distance(itr, l.end());
    ans += (n - 1 - i) - ng;
  }
  
  cout << ans << endl;
  
  return 0;
}

Measured memory_bytes: 3580
#include<bits/stdc++.h>
using namespace std;
const int n=1000;
const int mod= 1e9+7;
vector<vector<int>> dp(n,vector<int>(n));

int main()
{
	int n,m;
	cin>>n>>m;
	char c;
	dp[0][0]=1;
	for(int i=0;i<n;i++)
	{
		for(int j=0;j<m;j++)
		{
			cin>>c;
			if(c=='#')
				dp[i][j]=0;
			else
			{
				if(i==0 && j==0)
					continue;
				else if(i==0)
					dp[0][j]=dp[0][j-1]%mod;
				else if(j==0)
					dp[i][0]=dp[i-1][0]%mod;
				else
					dp[i][j]=(dp[i-1][j]+dp[i][j-1])%mod;
			}
		}
	}
	cout<<dp[n-1][m-1];

}

Measured memory_bytes: 4224
#include <iostream>

using namespace std;

int main()
{
  	string a, b;
  	cin >> a >> b;
  	int c = stoi(a + b);
  	bool x = false;
  	for(int i = 1; i < 320; i++){
      	if(i * i == c){
          	x = true;
          	break;
        }
    }
  	if(x){
		cout << "Yes";
    }else{
      	cout << "No";
    }
	return 0;
}


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

char str[10];

int main() {
	scanf("%s", str + 1);
	int ans = 0, fans = 0;
	for (int i = 1; i <= 3; ++i) {
		if (str[i] == 'R') ans++;
		else fans = max(fans, ans), ans = 0;
	}
	fans = max(fans, ans);
	printf("%d\n", fans);
	return 0;
}

Measured memory_bytes: 3824
import sys
def input(): return sys.stdin.readline().strip()
def mapint(): return map(int, input().split())
sys.setrecursionlimit(10**9)

S = input()
leng = len(S)-1
ans = 0
for i in range(1<<leng):
    lis = []
    start = 0
    for j in range(leng):
        if (i>>j)&1:
            lis.append(int(S[start:j+1]))
            start = j+1
    if start!=leng+1: lis.append(int(S[start:]))
    ans += sum(lis)
print(ans)

Measured memory_bytes: 69632
#include <iostream>
#include <vector>

using namespace std;

struct Card { char suit, value; };

void Output(vector<Card> A)
{
	for (int i = 0;i < A.size();i++)
	{
		if (i > 0)
			cout << " ";

		cout << A[i].suit << A[i].value;
	}

	cout << endl;
}

bool IsStable(vector<Card> C1, vector<Card> C2, int N)
{
	for (int i = 0;i < N;i++)
		if (C1[i].suit != C2[i].suit)
			return false;

	return true;
}

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

	vector<Card> C1(N);
	vector<Card> C2(N);

	for (int i = 0;i < N;i++)
		cin >> C1[i].suit >> C1[i].value;

	// ?????????
	for (int i = 0;i < N;i++)
		C2[i] = C1[i];

	// ??????????????????
	for (int i = 0;i < N;i++)
	{
		for (int j = N - 1;j > i;j--)
		{
			if (C1[j - 1].value > C1[j].value)
				swap(C1[j - 1], C1[j]);
		}
	}

	// ???????????????
	for (int i = 0;i < N;i++)
	{
		int minj = i;
		for (int j = i;j < N;j++)
		{
			if (C2[j].value < C2[minj].value)
				minj = j;
		}

		swap(C2[i], C2[minj]);
	}


	// ???????????????????????????(????????????)
	Output(C1);
	cout << "Stable" << endl;

	// ????????????????????????
	Output(C2);
	cout << ((IsStable(C1, C2, N)) ? "Stable" : "Not stable") << endl;

	return 0;
}

Measured memory_bytes: 3156
#include <bits/stdc++.h>
#define f first
#define s second
#define fore(i,a,b) for(int i = (a), ThxMK = (b); i < ThxMK; ++i)
#define pb push_back
#define all(s) begin(s), end(s)
#define lb(c, x) distance((c).begin(), lower_bound(all(c), (x)))
#define ub(c, x) distance((c).begin(), upper_bound(all(c), (x)))
#define _ ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define sz(s) int(s.size())
#define ENDL '\n'
#define vv(type, name, h, ...) vector<vector<type>> name(h, vector<type>(__VA_ARGS__))
#define vvv(type, name, h, w, ...) vector<vector<vector<type>>> name(h, vector<vector<type>>(w, vector<type>(__VA_ARGS__)))
using namespace std;
typedef long double ld;
typedef long long lli;
typedef pair<int,int> ii;
typedef vector<int> vi;
typedef vector<lli> vl;
typedef vector<vi> vvi;
typedef vector<vl> vvl;
typedef vector<ii> vii;

#define deb(x) cout << #x": " << (x) << endl;

const int N = 1e6+5;
const lli INF = 1e18;
const lli MOD = 1e9+7;
const ld EPS = 1e-4;



// ---- コーディングはここから！ ('-')7

int dp[N][4];
int n;
lli f(int u, int ma){
	if(u==n)return (ma==3);
	if(dp[u][ma]!=-1)return dp[u][ma];
	lli res = 8ll * f(u+1,ma) % MOD;
	res = (res + f(u+1,ma|1))%MOD;
	res = (res + f(u+1,ma|2))%MOD;
	dp[u][ma]=res;
	return dp[u][ma] = res;

}
void solve(){
	cin>>n;
	memset(dp, -1, sizeof dp);
	cout<<f(0,0)<<ENDL;
}
int main(){_
	//int t; cin>>t; while(t--)

	solve();
}


Measured memory_bytes: 66044
import scala.io.StdIn

object Main {
  def main(args: Array[String]){
    val input = StdIn.readLine().split(" ").map(_.toInt)
    val x = input(0)
    val y = input(1)
    println(s"${x * y} ${2 * x + 2 * y}")
  }
}

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

struct node{
    int key;
    node* parent;
    node* left;
    node* right;
};

node *nil, *root;

void insert(int key){

    node *y = nil;          // ノードyはzの親
    node *x = root;    // ノードxは木の根をさす
    node *z = (node *)malloc(sizeof(node));
    
    // 挿入ノードの初期値
    z->key = key;
    z->left = nil;
    z->right = nil;

    //　挿入先ノード探索
    while(x != nil){        // xがnilを指している(初期ノード)のとき終了
        y = x;              // zの親がxであるとする。
        
        if(z->key < x->key){// xのキーよりzのキーがxを小さければ左、そうでなければ右へ
            x = x->left;
        }else{
            x = x->right;
        }
    }

    z->parent = y;

    if(y == nil){ // treeが空の時
        root = z; 
    }else{
        if(z->key < y->key){
            y->left = z;
        }else{
            y->right = z;
        }
    }
}

void preorder(node *x){
    if(x == nil){
        return;
    }
    cout << " " << x->key;
    preorder(x->left);
    preorder(x->right);
}
void inorder(node *x){
    if(x == nil){
        return;
    }
    inorder(x->left);
    cout << " " << x->key;
    inorder(x->right);
}

int main(){
    int n; cin >> n;
    
    
    rep(i, n){
        string command; cin >> command;

        if(command == "insert"){
            int x; cin >> x;
            insert(x);
        }else if(command == "print"){
            inorder(root);
            cout << endl;
            preorder(root);
            cout << endl;
        }
    }

    return 0;
}


Measured memory_bytes: 26588
N = int(input())
A = [int(i) for i in input().split(' ')]
B = [int(i) for i in input().split(' ')]
totalB = sum(B)

for i in range(N):
    if i == 0:
        B[i] = B[i] - A[i]
        if B[i]<0:
            B[i] = 0
    else:
        A[i] = A[i] - B[i-1]
        B[i-1] = 0
        if A[i] < 0:
            B[i-1] = abs(A[i])
            A[i] = 0
            
        B[i] = B[i] - A[i]
        if B[i] < 0:
            B[i] = 0


B[N-1] = B[N-1] - A[N]
if B[N-1] < 0:
    B[N-1] = 0

print(totalB - sum(B))

Measured memory_bytes: 19648
using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Console = System.Console;

namespace Atcoder
{
    class Program
    {

        static void Main(string[] args)
        {
            var r = ReadIntArray();
            var N = r[0];
            var R = r[1];

            if (N < 10)
            {
                Console.WriteLine(R + (100 * (10 - N)));
            }
            else
            {
                Console.WriteLine(R);
            }
        }
        private static readonly Func<string> Read = () => Console.ReadLine();
        private static readonly Func<string[]> ReadStringArray = () => Console.ReadLine().Split();
        private static readonly Func<int> ReadInt = () => int.Parse(Console.ReadLine());
        private static readonly Func<long> ReadLong = () => long.Parse(Console.ReadLine());
        private static readonly Func<int[]> ReadIntArray = () => Console.ReadLine().Split().Select(int.Parse).ToArray();
        private static readonly Func<long[]> ReadLongArray = () => Console.ReadLine().Split().Select(long.Parse).ToArray();
        private static readonly Action<string> Cw = str => Console.WriteLine(str);
    }
}

Measured memory_bytes: 13396
import java.util.*;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		String S = sc.next();
		char[] s=S.toCharArray();
		int N = s.length;
		int count=0;
		
		for(int i=0;i<N;i+=2) {
			if(s[i]=='L') {
				count++;
			}
		}
		for(int i=1;i<N;i+=2) {
			if(s[i]=='R') {
				count++;
			}
		}
		
		if(count==0) {
			System.out.println("Yes");
		}
		else {
			System.out.println("No");
		}
		
		
	}
}


Measured memory_bytes: 22740