akhauriyash/Code-Regression huggingface dataset:
#https://note.nkmk.me/python-union-find/

class UnionFind():
    def __init__(self, n):
        self.n = n
        self.parents = [-1] * n

    def find(self, x):
        if self.parents[x] < 0:
            return x
        else:
            self.parents[x] = self.find(self.parents[x])
            return self.parents[x]

    def union(self, x, y):
        x = self.find(x)
        y = self.find(y)

        if x == y:
            return

        if self.parents[x] > self.parents[y]:
            x, y = y, x

        self.parents[x] += self.parents[y]
        self.parents[y] = x

    def size(self, x):
        return -self.parents[self.find(x)]

    def same(self, x, y):
        return self.find(x) == self.find(y)

    def members(self, x):
        root = self.find(x)
        return [i for i in range(self.n) if self.find(i) == root]

    def roots(self):
        return [i for i, x in enumerate(self.parents) if x < 0]

    def group_count(self):
        return len(self.roots())

    def all_group_members(self):
        return {r: self.members(r) for r in self.roots()}

    def __str__(self):
        return '\n'.join('{}: {}'.format(r, self.members(r)) for r in self.roots())

n, m = map(int, input().split())

uf = UnionFind(n)

for _ in range(m):
    a, b = map(int, input().split())
    uf.union(a-1, b-1)

ans = 0

for i in range(n):
    ans = max(ans, uf.size(i))

print(ans)


Measured memory_bytes: 14636
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <map>
#include <cmath>
#include <queue>
#include <deque>
#include <set>
#include <iomanip>
#include <utility>
#define ll long long
#define ld long double
using namespace std;

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

int main() {
	ll A, B;
	cin >> A >> B;
	ll m=gcd(A, B);
	int ans=1;
	for(ll i=2; i*i<=m; ++i){
	    if(m%i==0){
	        ++ans;
	        while(m%i==0){
	            m /= i;
	        }
	    }
	}
	if(m>1) ++ans;
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 256
n, m, l = map(int, input().split())
A = [[int(n) for n in input().split()] for i in range(n)]
B = [[int(n) for n in input().split()] for i in range(m)]
C = [[0 for i in range(l)] for i in range(n)]
for i in range(n):
    for j in range(l):
        for k in range(m):
            C[i][j] += A[i][k] * B[k][j]
for i in range(n):
    for j in range(l):
        if j == l - 1:
            print(C[i][j])
        else:
            print(C[i][j], end = " ")

Measured memory_bytes: 9116
s = list(str(input()))
l = 0
n = len(s)-1
ans = 0
while l < n:
    if(s[l] == s[n]):
        l += 1
        n -= 1
    elif(s[l] == 'x'):
        l += 1
        ans += 1
    elif(s[n] == 'x'):
        n -= 1
        ans += 1
    elif(s[l] != 'x' and s[n] != 'x'):
        ans = -1
        break
print(ans)

Measured memory_bytes: 4084
#include <algorithm>
#include <iostream>
#include <vector>
#include <math.h>
#include <set>
#include <map>
#include <string>
#include <stack>
#include <queue>
#include <iomanip>
#include <numeric>
#include <tuple>
#include <bitset>
#include <complex>
#include <unistd.h>
#include <cassert>
#include <cctype>
#include <random>
#define _USE_MATH_DEFINES
#define _GLIBCXX_DEBUG
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> plglg;
typedef tuple<int, int, int> tiii;
typedef tuple<ll, ll, ll> tlglglg;
typedef complex<double> xy_t;
int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};
double pi = 3.141592653589793;
ll mod = 1000000007;
int intmax = 2147483647;
int intmin = -2147483648;
ll llmax = 9223372036854775807;
ll llmin = -9223372036854775807;
int iinf = intmax / 8;
ll inf = llmax / 8;
double eps = 1e-11;

bool bo[10][10];

int main() {
    while (1) {
        string s;
        cin >> s;
        if (s == "#") {
            break;
        }
        int a, b, c, d;
        cin >> a >> b >> c >> d;
        for (int i = 0; i < 10; i++) {
            fill(bo[i], bo[i] + 10, false);
        }
        int len = s.size();
        int row = 0;
        int col = 0;
        int brow = 0;
        int bcol = 0;
        for (int i = 0; i < len; i++) {
            if (s[i] == '/') {
                row++;
                bcol = col;
                col = 0;
            } else if (s[i] == 'b') {
                bo[row][col] = true;
                col++;
            } else {
                col += s[i] - '0';
            }
        }
        brow = row + 1;
        bo[a - 1][b - 1] = false;
        bo[c - 1][d - 1] = true;
        string ans = "";
        for (int i = 0; i < brow; i++) {
            char c = '0';
            for (int j = 0; j < bcol; j++) {
                if (bo[i][j]) {
                    if (c > '0') {
                        ans += c;
                    }
                    ans += 'b';
                    c = '0';
                } else {
                    c++;
                }
            }
            if (c > '0') {
                ans += c;
            }
            if (i != brow - 1) {
                ans += '/';
            }
        }
        cout << ans << endl;
    }
}



Measured memory_bytes: 3224
from itertools import accumulate, starmap
from operator import sub

n, k = map(int, input().split())
aaa = list(map(int, input().split()))
MOD = 10 ** 9 + 7
dp = [0] * (k + 1)
dp[0] = 1
for a in aaa:
    dp = list(accumulate(dp))
    dp[a + 1:] = starmap(sub, zip(dp[a + 1:], dp[:-a - 1]))
    dp = [x % MOD for x in dp]
print(dp[k])


Measured memory_bytes: 13360
import sys

def debug(x, table):
    for name, val in table.items():
        if x is val:
            print('DEBUG:{} -> {}'.format(name, val), file=sys.stderr)
            return None

def solve():
    N, K = map(int, input().split())
    ans = 1

    for i in range(N):
        if i == 0:
            ans *= K
        else:
            ans *= (K - 1)

    print(ans)


if __name__ == '__main__':
    solve()

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

int main(){
  int n;
  string s;
  cin >> n >>s;
  int l = s.length();
  for(int i=0;i<l;i++){
    s[i] += n;
    if(s[i] > 0x5a) s[i] -= 26;
  }
  cout << s << endl;
  return 0;
}

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

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

Measured memory_bytes: 256
"use strict";
function Main(input) {
    let cin = new Inputer(input);
    let N = cin.getInt();
    let A = new Array(N);
    let ans = 0;
	for (let n = 0; n < N; n++) {
		A[n] = cin.getInt();
		while (A[n] % 2 == 0) { A[n] /= 2, ans++; }
	}
    console.log(ans);
}
class Inputer{constructor(t){if(typeof t=='undefined')throw new Error('引数（stdin）を省略できません！');this.cnt=0;this.items=t.split(/\n|\s/)}getInt(){return this.items[this.cnt++]-0}getIntArray(t){if(typeof t=='undefined')throw new Error('引数（1以上）を省略できません！');if(t<1)throw new Error('引数は1以上であること！');let r=new Array(t);for(let e=0;e<t;e++)r[e]=this.getInt();return r}getStr(){return this.items[this.cnt++]}getStrArray(t){if(typeof t=='undefined')throw new Error('引数（1以上）を省略できません！');if(t<1)throw new Error('引数は1以上であること！');let r=new Array(t);for(let e=0;e<t;e++)r[e]=this.getStr();return r}}
if (typeof window == "undefined") Main(require("fs").readFileSync("/dev/stdin", "utf8"));

Measured memory_bytes: 7756
#define _CRT_SECURE_NO_WARNINGS
#include <iostream>
#include <algorithm>
#include <functional>
#include <string>
#include <vector>
#include <stdio.h>
using namespace std;

#define REP(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)
typedef long long ll;

vector<bool> eratosthenes(int n) {
	vector<bool> prime(n + 1);
	for (int i = 2; i <= n; i++) {
		prime[i] = true; // 初期化
	}
	prime[0] = prime[1] = false;
	for (int i = 2; i*i <= n;i++) {
		if (prime[i]) {
			for (int j = i * 2; j <= n; j += i) {
				prime[j] = false;
			}
		}
	}
	return prime;
}
int n, m,p[10], ans = 0,a[29], b[29];
const int nmax = 8;
bool graph[nmax][nmax];
/**
 * pos個は決定済み
 * mask 残に置く数の集合を表すビット配列
 */
void dfs(int pos, int mask) {
//	cout << "pos=" << pos << ",mask=" << mask << endl;
	if (pos == n) { // posが最後までいった
//		cout << p[0] << p[1] << p[2] << endl;
		return;
	}
	REP(i, n) {
		if (mask  & (1 << i)) { // 残の中にiが残っている場合
//			cout << "mask=" << mask << ",1<<" << i << "="  << (1 << i) << "=true" << endl;
			p[pos] = i; // 配列のPOS位置を0～nまでループ
			if (p[0] != 0)continue;
			if (pos > 0 && graph[p[pos - 1]][p[pos]] == false) {
				//				cout << "pos=" << pos << "," << p[0] << p[1] << p[2] << ",graph[" << p[pos - 1] << "][" << p[pos] << "]=false" << endl;
				continue;
			}
			dfs(pos + 1, (mask ^ (1 << i))); // 配列のPOS位置を進める,排他的論理和でフラグを下ろす
		}
		else {
//			cout << "mask=" << mask << ",1<<" << i << "=" << (1 << i) << "=false" << endl;
		}
	}
}
/*int main() {
	cin.tie(0);
	ios::sync_with_stdio(false);

	scanf("%d %d", &n ,&m);

	REP(i, m) {
		scanf("%d %d",&a[i], &b[i]);
		p[i] = i;
		graph[a[i] - 1][b[i] - 1] = graph[b[i] - 1][a[i] - 1] = true;
	}

	dfs(0, (1 << n) - 1);
	cout << ans << endl;
	return 0;
}*/
/**
 * v 現在の頂点
 */
int dfs(int v, int n, bool visited[]) {
	bool all_visited = true; // 全頂点を訪問済
	REP(i, n) {
		if(!visited[i])all_visited = false;
	}
	if (all_visited)return 1; //答を1増やす
	int ret = 0;
	REP(i, n) { //頂点i:頂点vに隣接、且つ、未訪問
		if (!graph[v][i])continue;
		if(visited[i])continue;

		visited[i] = true;
		ret += dfs(i, n, visited);
		visited[i] = false;
	}
	return ret;
}
int main() {
	scanf("%d %d", &n, &m);

	REP(i,m) {
		scanf("%d %d", &a[i], &b[i]);
		graph[a[i] - 1][b[i] - 1] = graph[b[i] - 1][a[i] - 1] = true;
	}
	
	bool visited[nmax];
	REP(i, n)visited[i] = false;
	
	visited[0] = true;
	cout << dfs(0, n, visited) << endl;
	return 0;

}


Measured memory_bytes: 256
import sys
sys.setrecursionlimit(1000000000)
import math
from math import gcd
def lcm(a, b): return a * b // gcd(a, b)
from itertools import count, permutations, chain
from functools import lru_cache
from collections import deque, defaultdict
from pprint import pprint
ii = lambda: int(input())
mis = lambda: map(int, input().split())
lmis = lambda: list(mis())
INF = float('inf')
N1097 = 10**9 + 7

def meg(f, ok, ng):
    while abs(ok-ng)>1:
        mid = (ok+ng)//2
        if f(mid):
            ok=mid
        else:
            ng=mid
    return ok

def get_inv(n, modp):
    return pow(n, modp-2, modp)

def factorials_list(n, modp):    # 10**6
    fs = [1]
    for i in range(1, n+1):
        fs.append(fs[-1] * i % modp)
    return fs

def invs_list(n, fs, modp):     # 10**6
    invs = [get_inv(fs[-1], modp)]
    for i in range(n, 1-1, -1):
        invs.append(invs[-1] * i % modp)
    invs.reverse()
    return invs

def comb(n, k, modp):
    num = 1
    for i in range(n, n-k, -1):
        num = num * i % modp
    den = 1
    for i in range(2, k+1):
        den = den * i % modp
    return num * get_inv(den, modp) % modp

def comb_from_list(n, k, modp, fs, invs):   
    return fs[n] * invs[n-k] * invs[k] % modp

#

class UnionFindEx:
    def __init__(self, size):
        #正なら根の番号、負ならグループサイズ
        self.roots = [-1] * size
    def getRootID(self, i):
        r = self.roots[i]
        if r < 0:   #負なら根
            return i
        else:
            r = self.getRootID(r)
            self.roots[i] = r
            return r
    def getGroupSize(self, i):
        return -self.roots[self.getRootID(i)]
    def connect(self, i, j):
        r1, r2 = self.getRootID(i), self.getRootID(j)
        if r1 == r2:
            return False
        if self.getGroupSize(r1) < self.getGroupSize(r2):
            r1, r2 = r2, r1
        self.roots[r1] += self.roots[r2]    #サイズ更新
        self.roots[r2] = r1
        return True

Yes = 'Yes'
No = 'No'


def main():
    print((1000-ii()%1000)%1000)

main()



Measured memory_bytes: 9976
n = int(input())
s = input()
ans = 0
for i in range(len(s) - 1):
    if s[i] + s[i + 1] == 'WR':
        ans += 1

r_num = s.count('R')
w_num = s.count('W')

change_num = 0
for i in range(r_num):
    if s[i] == 'W':
        change_num += 1

print(min(r_num, min(w_num, change_num)))


Measured memory_bytes: 9428
#include <algorithm>
#include <bitset>
#include <cmath>
#include <deque>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <tuple>
#include <vector>

using namespace std;
typedef long long ll;
#define rep(i, n) for (ll i = 0; i < (n); i++)
#define reps(i, f, n) for (ll i = (f); i < (n); i++)
#define repv(v) for (auto it = (v).begin(); it != (v).end(); it++)
ll const INF = 1LL << 60;
ll const MAX_N = 510000;
ll const MOD = 1000000007;

struct city {
    ll idx, p, y;

    bool operator<(const city& another) const { return y < another.y; }
};

int main() {
    ll N, M;
    cin >> N >> M;
    vector<city> cities(M);

    rep(i, M) {
        ll p, y;
        cin >> p >> y;

        city c = {i, p, y};
        cities[i] = c;
    }

    sort(cities.begin(), cities.end());

    vector<ll> cnt(N, 0);
    vector<string> ids(M);
    stringstream ss;

    repv(cities) {
        cnt[(*it).p - 1]++;
        ss << setw(6) << setfill('0') << (*it).p;
        ss << setw(6) << setfill('0') << cnt[(*it).p - 1];
        string str = ss.str();
        ids[(*it).idx] = str;
        // cout << (*it).idx << ": " << ss.str() << endl;
        ss.str("");
        ss.clear(stringstream::goodbit);

        //  ids[(*it).idx] =
        //     cout << (*it).idx << "," << (*it).p << "," << (*it).y << endl;
    }

    repv(ids) { cout << *it << endl; }

    return 0;
}


Measured memory_bytes: 9512
import sys
def input():
    return sys.stdin.readline()[:-1]
sys.setrecursionlimit(200000)
N=int(input())
S = [list(map(int, input().split()))+[i] for i in range(N-1)]
A=[None]*(N-1)
l=[[] for i in range(N+1)]
t=[0]*N
t[0]=1
for i in S:
    l[i[0]].append((i[1],i[2]))
    l[i[1]].append((i[0],i[2]))
def haba(o,c):
    p=1
    for i in l[o]:
        if t[i[0]-1]==0:
            if c==p:
                p+=1
            A[i[1]]=p
            t[i[0]-1]=1
            haba(i[0],p)
            p+=1
haba(1,0)
print(max(A))
print(*A,sep="\n")

Measured memory_bytes: 81368
import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,random,time,copy,functools
from collections import deque
 
sys.setrecursionlimit(10**7)
inf = 10**20
mod = 10**9 + 7
 
DR = [1, -1, 0, 0]
DC = [0, 0, 1, -1]
 
def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LI_(): return [int(x)-1 for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def I(): return int(sys.stdin.readline())
def F(): return float(sys.stdin.readline())
def S(): return input()
     
def main():
    N = I()
    G = []
    for _ in range(N):
        a = LI()
        G.append(a)
    dp = copy.deepcopy(G)
    for i in range(N):
        for j in range(N):
            for k in range(N):
                dp[i][j] = min(dp[i][j], dp[i][k] + dp[k][j])
 
    if dp != G:
        print(-1)
        return
 
    for k in range(N):
        for i in range(N):
            for j in range(N):
                if j == k:
                    continue
                if i == k:
                    continue
                if dp[i][k] == 0 or dp[i][j] == 0 or dp[j][k] == 0:
                    continue
                if dp[i][j] == dp[i][k] + dp[k][j]:
                    dp[i][j] = 0
                    dp[j][i] = 0
    cnt = 0
    for i in range(N):
        for j in range(N):
            cnt += dp[i][j]
    print(cnt // 2)
main()


Measured memory_bytes: 83160
N, K = list(map(int, input().split()))
S = input()

def komo(n):
  if n == "A":
    return "a"
  elif n == "B":
    return "b"
  else:
    return "c"
  
ans = S[:K-1] + komo(S[K-1]) + S[K:]

print(ans)


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

using namespace std;
typedef long long int ll;
typedef long double ld;
#define REP(i, n) for(ll i = 0LL; i < (ll)(n); i++)
#define REPR(i, n) for (ll i = (ll)(n) - 1; i >= 0; i--)
#define FOR(i, n, m) for(ll i = (ll)n; i < (ll)(m); i++)
#define ALL(x) (x).begin(),(x).end()
#define MOD 1000000007
#define INF (1LL << 62)

#define PI (acos(-1))
#define PRINT(x) cout << x << endl
 
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; }
ll countDigit(ll n) { return floor(log10(n) + 1); } 
typedef pair <ll,ll> P;
static const ll dy[4] = {0,1,0,-1}, dx[4] = {1,0,-1,0};

template <typename T> 
ostream& operator<<(ostream& os, const vector<T>& v) 
{ 
    for (int i = 0; i < (int)v.size(); ++i) os << v[i] << " ";  
    return os; 
}

template <typename T1, typename T2> 
ostream& operator<<(ostream& os, const map<T1, T2>& m) 
{ 
    for (auto p : m) os << "<" << p.first << ", " << p.second << "> "; 
    return os; 
}

int main()
{
    ll X, Y, Z;
    cin >> X >> Y >> Z;
    PRINT(Z << " " << X << " " << Y);
    return 0;
} 

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

using namespace std;

#define loop(i,a,b) for(int i=(a);i<int(b);i++)
#define rep(i,b) loop(i,0,b)
#define all(a) a.begin(), a.end()

int main(){
	int w,d;
	while(cin>>w>>d && w|d){
		map<int,pair<int,int>> a;
		rep(i,w){
			int x;cin>>x;
			a[x].first++;
		}
		rep(i,d){
			int x;cin>>x;
			a[x].second++;
		}
		int ans=0;
		for(auto &p:a)ans+=max(p.second.first, p.second.second) * p.first;
		cout<<ans<<endl;
	}
}

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

using namespace std;

long long n;
vector<long long> a;
long long dp[3002][3002];

long long go(long long i, long long j) {
  if(dp[i][j] != -1) return dp[i][j];

  if(i+j == n) {
    // base case
    return 0;
  }
  if((i+j) % 2 == 0) {
    // it's Taro's turn, he is trying to maximize
    long long take_left  = a[i] + go(i+1, j);
    long long take_right = a[n-j-1] + go(i, j+1);
    dp[i][j] = max(take_left, take_right);
    return dp[i][j];
  }
  else {
    // it's Jiro's turn, he is trying to minimize
    long long take_left  = -a[i] + go(i+1, j);
    long long take_right = -a[n-j-1] + go(i, j+1);
    dp[i][j] = min(take_left, take_right);
    return dp[i][j];
  }
}

int main() {
  // L: right now, just looking like a straightforward n^2
  // DP, where dp[i][j] is the state after taking i from
  // the left and j from the right
  // and you can tell whose turn it is by the parity
  // of i+j

  cin.tie(0);
  cin.sync_with_stdio(0);

  cin >> n;
  a.resize(n);
  for(long long i = 0; i<n; ++i) {
    cin >> a[i];
  }
  for(long long i = 0; i<=3000; ++i) {
    for(long long j = 0; j<=3000; ++j) {
      dp[i][j] = -1;
    }
  }

  cout << go(0, 0) << endl;
}


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

int main() {
  int n, a, b;
  cin >> n >> a >> b;
  if((b - a) % 2 == 0){
    cout << "Alice" << endl;
  }else{
    cout << "Borys" << endl;
  }
}


Measured memory_bytes: 256
import sys

read = sys.stdin.read
readline = sys.stdin.readline
readlines = sys.stdin.readlines
sys.setrecursionlimit(10 ** 9)
INF = 1 << 60
MOD = 1000000007


def main():
    S = readline().strip()

    if len(set(S)) == 3:
        print('Yes')
    else:
        print('No')

    return


if __name__ == '__main__':
    main()


Measured memory_bytes: 9016
#include<bits/stdc++.h>
using namespace std;
  
int main(void){
    int n;
    while(cin >> n,n){
        int k,s = 0,f = 0;
        for(int i = 0; i < n; i ++){
            cin >> k;
            if(k >= 1) s++;
            if(k > 1) f=1;
        }
        if(!f)cout << "NA" << endl;
        else cout << s+1 << endl;
    }
}


Measured memory_bytes: 3096
#include <bits/stdc++.h>
#define ll long long
double EPS = 1e-9;
constexpr ll MOD =  1e9+9;
using namespace std;

int main()
{
//    freopen("in.txt", "r", stdin);
//    freopen("out.txt", "w", stdout);
    ios::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    int n;
    cin >> n;
    pair<int, int> red[n];
    pair<int, int> blue[n];
    for(int i = 0;i < n;i++){
        cin >> red[i].first >> red[i].second;
    }
    for(int i = 0;i < n;i++){
        cin >> blue[i].first >> blue[i].second;
    }
    sort(red, red + n, [](const pair<int, int>& a, const pair<int, int>& b){
        return a.first > b.first;
    });
    sort(blue, blue + n, [](const pair<int, int>& a, const pair<int, int>& b){
        return a.first > b.first;
    });
    int res = 0;
    set<pair<int, int>> avail;
    int cur_j = 0;
    for(int i = 0;i < n;i++){
        while(cur_j < n && blue[cur_j].first > red[i].first){
            avail.insert({blue[cur_j].second, blue[cur_j].first});
            cur_j++;
        }
        auto it = avail.lower_bound({red[i].second, -1});
        if(it == avail.end())continue;
//        it--;
        res++;
        avail.erase(it);
    }
    cout << res;
    return 0;
}


Measured memory_bytes: 256
#include <algorithm>
#include <cctype>
#include <cstdio>
#include <iostream>
#include <locale>
#include <numeric>
#include <string>
#include <vector>

using namespace std;

int solve(int n) {
    int ans = 0;
    for (int sentou = 1; sentou < 1000; sentou++) {
        for (int kousuu = 2; kousuu < 1000; kousuu++) {
            if (kousuu * (2 * sentou + kousuu - 1) / 2 == n) {
                ans++;
                // cout << sentou << " " << kousuu << endl;
            }
        }
    }
    return ans;
}

int main(int argc, char const *argv[]) {
    cin.tie(0);

    int n;
    vector<int> ans;
    while (1) {
        cin >> n;
        if (n == 0) break;
        ans.push_back(solve(n));
    }
    for (int i = 0; i < ans.size(); i++) {
        cout << ans[i] << endl;
    }
}


Measured memory_bytes: 3092
#include "bits/stdc++.h"

// Begin {{{
using namespace std;

#ifndef DEBUG
#define dump(...)
#endif

template <class A, class B> inline bool chmax(A &a, const B &b) { return b > a && (a = b, true); }
template <class A, class B> inline bool chmin(A &a, const B &b) { return b < a && (a = b, true); }

template <class T>
inline vector<T> make_v(const T &initvalue, intmax_t sz) {
    return vector<T>(sz, initvalue);
}

template <class T, class... Args>
inline auto make_v(const T &initvalue, intmax_t sz, Args... args) {
    return vector<decltype(make_v<T>(initvalue, args...))>(sz, make_v<T>(initvalue, args...));
}

constexpr int INF = 0x3f3f3f3f;
constexpr int64_t LINF = 0x3f3f3f3f3f3f3f3fLL;
// }}} End

signed main() {
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);

    string X; cin >> X;

    stack<char> st;
    for (auto &x: X) {
        if (!st.empty() && st.top() == 'S' && x == 'T') {
            st.pop();
        } else {
            st.emplace(x);
        }
    }

    cout << st.size() << "\n";

    return 0;
}


Measured memory_bytes: 720
#include <bits/stdc++.h>
using namespace std;
#define rep(i,s,t) for(int i=s;i<t;i++)
#define pii pair<int,int>
typedef long long ll;
const ll mod=1e9+7;
#define MAXNUM 222222
ll fact[MAXNUM],ifact[MAXNUM];

ll qpow(ll a, ll b)
{
    ll res = 1;
    while (b)
    {
        if (b & 1)
            res = res * a % mod;
        a = a * a % mod, b >>= 1;
    }
    return res;
}
void sub(ll &a,ll b)
{
    a-=b;
    if(a<0)a+=mod;
}
ll getC(int a,int b)
{
    return fact[a]*ifact[b]%mod*ifact[a-b]%mod;
}
int main()
{
    int n,m,k;scanf("%d%d%d",&n,&m,&k);
    fact[0]=ifact[0]=1;
    rep(i,1,n*m+1)fact[i]=fact[i-1]*i%mod,ifact[i]=qpow(fact[i],mod-2);
    ll x=getC(n*m-2,k-2),res=0;
    rep(i,1,n+1)
        (res+=x*i%mod*m%mod*(m*(i-1)))%=mod,sub(res,x*i%mod*m%mod*(n*m-m*i)%mod);
    rep(i,1,m+1)
        (res+=x*i%mod*n%mod*(n*(i-1)))%=mod,sub(res,x*i%mod*n%mod*(n*m-n*i)%mod);
    printf("%lld\n",res);
}

Measured memory_bytes: 3328
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define In_The_Name_Of_Allah_The_Merciful ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
#define Alhamdulillah return 0;
#define all(v) v.begin(),v.end()
#define debug(n) cerr << "[" << #n << " = " << n << "]" << endl 

const int N = 1e5;
int dp[N];
vector <int> adj[N];
int n , m;

int calc (int u){

    int &ret = dp[u];
    if (~ret)
        return ret;

    ret = 1;
    for (int v : adj[u])
        ret = max (ret , calc(v) + 1);

    return ret;

} 

void Suhaib_Sawalha (){

    cin >> n >> m;
    for (int i = 0 , u , v; i < m ; ++i){
        cin >> u >> v;
        --u , --v;
        adj[u].push_back(v);
    }

    memset(dp,-1,sizeof dp);
    int ret = 0;
    calc(0);

    for (int i = 0 ; i < n ; ++i)
        ret = max (ret,calc(i)-1);
    cout << ret;

}

int main(){
                                In_The_Name_Of_Allah_The_Merciful   /* بسم الله الرحمن الرحيم  */
#ifndef ONLINE_JUDGE
    freopen("SuhaibSawalha1.txt","r",stdin);
#endif
//int _;for(cin>>_;_;--_,cout<<'\n')
        Suhaib_Sawalha();
                                         Alhamdulillah                    /* الحمد لله */
}

Measured memory_bytes: 11548
#include "bits/stdc++.h"
using namespace std;
#define FOR(i,j,k) for(int (i)=(j);(i)<(int)(k);++(i))
#define rep(i,j) FOR(i,0,j)
#define each(x,y) for(auto &(x):(y))
#define mp make_pair
#define mt make_tuple
#define all(x) (x).begin(),(x).end()
#define debug(x) cout<<#x<<": "<<(x)<<endl
#define smax(x,y) (x)=max((x),(y))
#define smin(x,y) (x)=min((x),(y))
#define MEM(x,y) memset((x),(y),sizeof (x))
#define sz(x) (int)(x).size()
#define pb push_back
typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<ll> vll;

const int DY[] = { -1,0,1,0 };
const int DX[] = { 0,1,0,-1 };

int vis[801][801];

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    int H, W, K;

    cin >> H >> W >> K;
    vector<string> A(H);
    int sy = -1, sx = -1;
    rep(y, H) {
        cin >> A[y];
        if (sy == -1)rep(x, W)if (A[y][x] == 'S') {
            sy = y; sx = x;
            break;
        }
    }

    queue<tuple<int, int, int> > q;
    q.push(mt(sy, sx, 0));
    vis[sy][sx] = 1;
    while (sz(q)) {
        int y, x, d;
        tie(y, x, d) = q.front();
        q.pop();

        if (d < K)rep(i, 4) {
            int ny = y + DY[i], nx = x + DX[i];
            if (ny >= 0 && nx >= 0 && ny < H&&nx < W && !vis[ny][nx] && A[ny][nx] != '#' && !vis[ny][nx]) {
                q.push(mt( ny,nx,d + 1 ));
                vis[ny][nx] = 1;
            }
        }
    }

    int ans = INT_MAX;
    rep(y, H)rep(x, W) {
        if (vis[y][x]) {
            smin(ans, y);
            smin(ans, x);
            smin(ans, H - 1 - y);
            smin(ans, W - 1 - x);
        }
    }
    ans = (ans + K - 1) / K + 1;
    cout << ans << endl;
}


Measured memory_bytes: 3456
#include<iostream>
#include<functional>
#include<iomanip>
#include<algorithm>
#include<vector>

using namespace std;
using ll = long long;

#define rep(i,n) for(int i = 0; i <(n); ++i)
#define ALL(n) (n).begin(),(n).end()
#define pb push_back
inline ll pow(ll x,ll n,ll m){ll r=1;while(n>0){if((n&1)==1)r=r*x%m;x=x*x%m;n>>=1;}return r%m;}

int d[100] = {};

int main(){
  int n,m;  cin >> n >> m;
  rep(i,n){
    int k; cin >> k;
    rep(j,k){
      int a; cin >> a;
      d[a]++;
    }
  }
  int ans = 0;
  rep(i,m+1){if(d[i] == n) ans++;}
  cout << ans << endl;
}

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

vector<vector<int>> f(string s)
{
  vector<vector<int>> ret(26, vector<int>(0));
  vector<char> m(26, 'X');
  
  int n = s.size();
  char p = 'a';
  rep(i, n)
  {
    int c = s[i] - 'a';
    if(m[c] == 'X')
    {
      m[c] = p;
      p++;
    }
    ret[m[c] - 'a'].emplace_back(i);
  }
  
  return ret;
  
}


int main()
{
  string s, t;
  cin >> t >> s;
  vector<vector<int>> a(26, vector<int>(0)), b(26, vector<int>(0));
  a = f(s);
  b = f(t);
  
  rep(i, 26)
  {
    if(a[i] != b[i])
    {
      cout << "No" << endl;
      return 0;
    }
    /*
    rep(j, a[i].size())
    {
      if(a[i][j] != b[i][j])
      {
        cout << "No" << endl;
        return 0;
      }
    }*/
  }
  
  cout << "Yes" << endl;
  
  return 0;
}

Measured memory_bytes: 3012
//#pragma GCC target("avx2")
#pragma GCC optimize("O3")
//#pragma GCC optimize("unroll-loops")

#include <bits/stdc++.h>

using namespace std;

#ifdef LOCAL
#include <prettyprint.hpp>
#define debug(...)  cerr << "[" << #__VA_ARGS__ << "]: ", d_err(__VA_ARGS__);
#else
#define debug(...) 83;
#endif

void d_err() {
    cerr << endl;
}

template <typename H, typename... T>
void d_err(H h, T... t) {
    cerr << h << " ";
    d_err(t...);
}

template <typename T>
void print(T x) {
    cout << x << "\n";
}

#define ALL(x) (x).begin(), (x).end()
#define FOR(i, m, n) for (int i = (m); i < (n); ++i)
#define REVFOR(i, m, n) for (int i = (n - 1); i >= (m); --i)
#define REP(i, n) FOR(i, 0, n)
#define REVREP(i, n) REVFOR(i, 0, n)
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define eb emplace_back
#define bcnt __builtin_popcountll

typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef pair<ll,ll> Pll;
typedef pair<int,int> Pin;

ll INF = 1e16;
int inf = 1e9;
ll MOD = 1e9+7;

int main(){
    cin.tie(0);
    ios_base::sync_with_stdio(false);
    cout << fixed << setprecision(20);
    
    string s;
    cin >> s;

    ll n = s.size();
    ll ans = n * (n - 1) / 2 + 1;

    vector<ll> cnt(26, 0);
    REP(i, s.size()) {
        cnt[s[i] - 'a']++;
    }

    for(auto &e: cnt) {
        ans -= e * (e - 1) / 2;
    }

    print(ans);
}


Measured memory_bytes: 3780
N = gets.to_i
A = []
sum = 0
line = gets.split(' ').map(&:to_i)

for num in 0..N-1 do
    n = line[num]
    A[n] ||= 0
    A[n] += 1
    sum += n
end

Q = gets.to_i
q_line = []

for num in 0..Q-1 do
    q_line = gets.chomp.split(' ').map(&:to_i)
    B = q_line[0]
    C = q_line[1]
    b = A[B].to_i
    A[B] = 0
    sum += b * (C - B) 
    A[C] ||= 0
    A[C] += b
    puts sum
end

Measured memory_bytes: 41932
n = int(input())
now = 1
num = 1
for i in range(1, n+1):
    now = int(i*(i+1)/2)
    if now >= n:
        num = i
        break
diff = now - n

for i in range(1,num+1):
    if i == diff:
        pass
    else:
        print(i)


Measured memory_bytes: 3316
#include <bits/stdc++.h>
using namespace std;
using ll = int64_t;
#define rep(i,n) for(int i = 0; i < ((int)(n)); i++)   // 0-indexed昇順

ll solve(ll A, ll B, ll N) {
    ll ma = 0;
    for (ll x = 0; x <= N; x++) {
        ll ans = (A * x) / B - A * (ll)(x/B);
        if (ma < ans) {
            ma = ans;
            if (ma > 99999) printf("%ld: %ld\n", x, ma);
        }
//        printf("%ld: %ld\n", x, A * x / B - A * (ll)(x / B));
    }
    return ma;
}

ll solve2(ll A, ll B, ll N) {
    ll x = min(N, B-1);
    return A * x / B - A * (ll)(x/B);
}

int main() {
    ll A, B, N; cin >> A >> B >> N;
//    cout << solve(A, B, N) << endl;
//    for (ll x = N - 100; x <= N; x++)

    cout << solve2(A, B, N) << endl;
}


Measured memory_bytes: 3560
#include <bits/stdc++.h>
#include <algorithm>
using namespace std;
int main(){
long long int H, W; 
cin >> H >> W; 
if(H % 3 == 0 || W % 3 == 0){
cout << 0 << endl; 
}
else{
long long int ans = min(H, W); 
for(long long int i = 1; i < H; i++){
long long int A = max({i * W, (W + 1)/2 * (H-i), W/2 * (H-i)}) 
  - min({i * W, (W + 1)/2 * (H-i), W/2 * (H-i)}); 
ans = min(ans, A); 
}
  for(long long int i = 1; i < W; i++){
long long int A = max({i * H, (H + 1)/2 * (W-i), H/2 * (W-i)}) 
  - min({i * H, (H + 1)/2 * (W-i), H/2 * (W-i)}); 
ans = min(ans, A); 
}
cout << ans << endl; 
}
}

Measured memory_bytes: 256
#include<stdio.h>
void bubbleSort(int A[],int N){
int flag=1;
int f,j,e;
int c=0;
while(flag){
flag=0;
for(j=N-1;j>0;j--){
if(A[j]<A[j-1]){
f=A[j];
A[j]=A[j-1];
A[j-1]=f;  
flag=1;
c++; 
        }
     }
   }
for(e=0;e<N;e++){
printf("%d",A[e]);
if(e==N-1){
printf("\n");
}else{
printf(" ");
}
}
printf("%d\n",c);
}

int main(){
int a,b[100],d;
scanf("%d",&a);
for(d=0;d<a;d++){
scanf("%d",&b[d]);
} 
bubbleSort(b,a);
}










Measured memory_bytes: 2000
#include <bits/stdc++.h>
#define rep(i, a) for(int i = 0; i < a; i++)
#define all(v) v.begin(), v.end()
#define dcout cout << fixed << setprecision(15)
#define arep(i, a) for(auto i : a)
#define F first
#define S second
#define VE vector<int>
#define pb(x) push_back(x)
#define MOD 1000000007
#define INF 10000000000
#define int long long
#define KETA(n) floor(log10(n) + 1)
using namespace std;
signed main() {
    int n, k;
    cin >> n >> k;
    double ans = 0;
    for(double i = 0; i < n; i++) {
        int me = i + 1;
        int j = me;
        int count = 0;
        while(1) {
            if(j >= k) break;
            j *= 2;
            count++;
        }
        ans += (1.0 / n) * pow(0.5, count);
    }
    dcout << ans << endl;
    return 0;
}

Measured memory_bytes: 512
#include<bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define rep2(i,a,b) for(int i=a;i<b;i++)
#define each(it,v) for(auto it : v)
#define mod 1000000007
#define all(v) (v).begin(),(v).end()
#define ll long long
#define vi vector<int>
#define vll vector<ll>
#define vpii vector<pair<int,int>>
#define vv vector<vector<int>>
using namespace std;

main()
{
    int n; cin>>n;
    bool f=true;

    vi v(n);
    each(&it,v)
    {
        cin>>it;
        if(it%2==0)
        {
            if(it%3!=0&&it%5!=0)f=false;
        }
    }

    if(f)cout<<"APPROVED"<<endl;
    else cout<<"DENIED"<<endl;
}

Measured memory_bytes: 256
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
int top,s[1000];
void push(int x){
    s[++top]=x;
}
int pop(){
    top--;
    return s[top+1];
}
int main(){
    int a,b;
    top=0;
    char t[100];
    while(scanf("%s",t)!=EOF){
        if(t[0]=='+'){
            b=pop();
            a=pop();
            push(a+b);
        }
        else if(t[0]=='-'){
            b=pop();
            a=pop();
            push(a-b);
        }else if(t[0]=='*'){
            b=pop();
            a=pop();
            push(a*b);
        }
        else{
            push(atoi(t));
        }
    }
    printf("%d\n",pop());
}


Measured memory_bytes: 2124
#include<stdio.h>

int main(){
	char S[7];
  	for(int i=0; i<6; i++){
		scanf("%c",&S[i]);
    }
	
  	if(S[2]==S[3] && S[4]==S[5]){
    	printf("Yes");
    }else{
    	printf("No");
    }
  	
	
	return 0;
}

Measured memory_bytes: 128
#include <stdio.h>

main(void){

int n;
int c = 0;
int max = 0;
int q=0;
int sum=0;
scanf("%d",&n);
int L[10];
while(c != n){

scanf("%d",&L[c]);
c++;

}

for(int s=0;s < n;s++){
	if(max<L[s]){
		max=L[s];
		q=s;
	}
}
for(int s=0;s < n;s++){
	if(s!=q){
		sum+=L[s];
	}
}

if(max<sum){
	printf("Yes");
}else{
	printf("No");
	}
}

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

int main() {
    int n, w, h;
    cin >> n >> w >> h;
    vector<int> yi(h + 1, 0), xi(w + 1, 0);
    for (int i = 0; i < n; i++) {
        int x, y, z;
        cin >> x >> y >> z;
        int lx = max(0, x - z);
        int rx = min(w, x + z);
        int ly = max(0, y - z);
        int ry = min(h, y + z);
        yi[ly]++;
        yi[ry]--;
        xi[lx]++;
        xi[rx]--;
    }
    int c = 0, f = 1;
    for (int i = 0; i < w; i++) {
        c += xi[i];
        if (c <= 0) f = 0;
    }
    c = 0;
    for (int i = 0; i < h; i++) {
        c += yi[i];
        if (c <= 0 && f == 0) {
            cout << "No" << endl;
            return 0;
        }
    }
    cout << "Yes" << endl;
    return 0;
}


Measured memory_bytes: 3636
#include <cstdio>
#include <string>
#include <algorithm>
#include <cstring>
#include <vector>
#include <queue>
#include <map>
#include <set>
#include <bitset>
#include <stack>
#include <cmath>
#include <time.h>
#include <unordered_set>
#include <unordered_map>
#define ll long long
#define LINF 0x3f3f3f3f3f3f3f3f
#define INF 0x3f3f3f3f
#define PI 3.14159265
#define RAND (rand()*rand())
#define MAX(x, y) ((x) > (y) ? (x):(y)) 
#define MIN(x, y) ((x) > (y) ? (y):(x))
#define ABS(x) ((x) > 0 ? (x) : -(x))
#define CEIL(x, y) (((x) + (y) - 1)/(y))
using namespace std;
const int MAXN = 1e5 + 5;
const ll MOD = 1e9 + 7;
const double eps = 1e-7;
int N, M, K, Q, T;

int main()
{
	int i, j, a, b;
	scanf("%d%d", &a, &b);
	if (a <= b) {
		printf("unsafe");
	}
	else printf("safe");
	return 0;
}

Measured memory_bytes: 1732
#include<bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(int)n;i++)
#define all(c) (c).begin(),(c).end()
#define pb push_back
#define dbg(...) do{cerr<<__LINE__<<": ";dbgprint(#__VA_ARGS__, __VA_ARGS__);}while(0);

using namespace std;

namespace std{template<class S,class T>struct hash<pair<S,T>>{size_t operator()(const pair<S,T>&p)const{return ((size_t)1e9+7)*hash<S>()(p.first)+hash<T>()(p.second);}};template<class T>struct hash<vector<T>>{size_t operator()(const vector<T> &v)const{size_t h=0;for(auto i : v)h=h*((size_t)1e9+7)+hash<T>()(i)+1;return h;}};}
template<class T>ostream& operator<<(ostream &os, const vector<T> &v){os<<"[ ";rep(i,v.size())os<<v[i]<<(i==v.size()-1?" ]":", ");return os;}template<class T>ostream& operator<<(ostream &os,const set<T> &v){os<<"{ "; for(const auto &i:v)os<<i<<", ";return os<<"}";}
template<class T,class U>ostream& operator<<(ostream &os,const map<T,U> &v){os<<"{";for(const auto &i:v)os<<" "<<i.first<<": "<<i.second<<",";return os<<"}";}template<class T,class U>ostream& operator<<(ostream &os,const pair<T,U> &p){return os<<"("<<p.first<<", "<<p.second<<")";}
void dbgprint(const string &fmt){cerr<<endl;}template<class H,class... T>void dbgprint(const string &fmt,const H &h,const T&... r){cerr<<fmt.substr(0,fmt.find(","))<<"= "<<h<<" ";dbgprint(fmt.substr(fmt.find(",")+1),r...);}
typedef long long ll;typedef vector<int> vi;typedef pair<int,int> pi;const int inf = (int)1e9;const double INF = 1e12, EPS = 1e-9;

int main(){
	cin.tie(0); cin.sync_with_stdio(0);
	
	int a, b; cin >> a >> b;
	if(a <= 5) cout << 0 << endl;
	else if(a < 13) cout << b / 2 << endl;
	else cout << b << endl;
	
	return 0;
}

Measured memory_bytes: 256
#include <iostream>

using namespace std;

int main()
{
    int n, x, t, min;

    cin >> n >> x >> t;
    if (n % x == 0)
    {
        min = (n / x) * t;

    }
    else
    {
        min = ((n / x) + 1) * t;
    }

    cout << min;

    return 0;
}

Measured memory_bytes: 3616
#include <cstdio>

int main(void) {
    int r, D, x_2000;
    std::scanf("%d", &r);
    std::scanf("%d", &D);
    std::scanf("%d", &x_2000);
    int x = x_2000;
    for (int i = 0; i < 10; i++) {
        x = r * x - D;
        printf("%d\n", x);
    }
    return 0;
}

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

#define REP(i,n) for(int i=0;i<n;i++)
#define REPR(i,n) for(int i=n;i>=0;i--)
#define FOR(i,m,n) for(int i=m;i<n;i++)
#define EPS (1e-7)

typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef pair<double,double> pdd;

int vx[]={0,1,0,-1};
int vy[]={1,0,-1,0};

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

const ll mod=1e9+7;
const int INF=INT_MAX/2;
const int MAX=1e9;

const int MAX_N=100001;

int main(){
	string s;
	cin>>s;
	int n=s.length();
	int k=n;
	for(int i=0;i<n-1;i++){
		if(s[i]!=s[i+1]){
			k=min(k,max(i+1,n-1-i));
		}
	}
	cout<<k<<endl;
	return 0;
}


Measured memory_bytes: 512
s = input()
res = [0] * (len(s)+1)

for i in range(len(s)):
  if s[i] == "<":
    res[i +1] = res[i] +1

for i in range(len(s)-1,-1,-1):
  if s[i] == ">":
    res[i] = max(res[i], res[i+1]+1)

print(sum(res))

Measured memory_bytes: 23336
N = int(input())
ans = 0
def dfs(s):
    if int(s) <= N and len(set(s)) >= 3:
        global ans
        ans += 1

    if len(s) == 9:
        return
    dfs(s + "7")
    dfs(s + "5")
    dfs(s + "3")

dfs("7")
dfs("5")
dfs("3")

print(ans)

Measured memory_bytes: 3060
import sys
import math
import itertools
import collections
from collections import deque
from collections import defaultdict

sys.setrecursionlimit(1000000)
MOD = 10 ** 9 + 7
MOD2 = 998244353
INF = float('inf')
input = lambda: sys.stdin.readline().strip()

NI = lambda: int(input())
NMI = lambda: map(int, input().split())
NLI = lambda: list(NMI())
SI = lambda: input()

def main():
    
    N, M = NMI()
    A = [NI() for _ in range(M)]
    
    broken = [1 for _ in range(N+1)]
    
    for a in A:
        broken[a] = 0
    
    dp = [0 for _ in range(N+1)]
    
    dp[0] = 1
    dp[1] = int(not(1 in A))
    
    for n in range(2,N+1):
        dp[n] = ((dp[n-1]*broken[n-1] + dp[n-2]*broken[n-2])*broken[n])%MOD
        
    print(dp[N])


if __name__ == '__main__':
    main()

Measured memory_bytes: 14640
#include<stdio.h>

#include<string.h>
void main()
{
	int a;
	char s[10];

	do{
		scanf("%d", &a);
	}while((a<2800)||(a>=5000));

	scanf("%s", s);

	if(a>=3200)
		printf("%s\n", s);
	else
		printf("red\n");
}


Measured memory_bytes: 128
K = int(input())

list = [1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51]

#list[K-1] = 1000

print(list[K-1])

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

int main()
{
    ll N,K,Q;
    cin >> N >> K >> Q;
    vector<ll> A(Q);
    map<ll,ll> mp;

    for(int i = 0; i < Q; i++)
    {
        cin >> A.at(i);
        mp[A.at(i)-1]++;
    }

    for(int i = 0; i < N; i++)
    {
        if((K + mp[i] - Q) > 0)
        {
            cout << "Yes";
        }
        else cout << "No";
        cout << endl;

    }
    return 0;
}

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

int main() {
    cin.tie(NULL);
    ios_base::sync_with_stdio(false);
    
    int n, m;
    cin>>n>>m;

    vector< pair<int, int> > v(m);

    int index = 0;
    int start = 1;
    int end = n;

    unordered_set<int> s;

    for(int i=1;i<=n/2;i++) {
        if( (end - start) != (n - end + start) &&
         s.find(end-start) == s.end() &&
          s.find(n-end+start) == s.end()) {
            s.insert(end-start);
            s.insert(n-end+start);
            v[index++] = {start++, end--};
            
        }else{
            end--;
        }

        if(index >= m) {
            break;
        }
    }

    for(int i=0;i<m;i++) {
        cout<<v[i].first<<" "<<v[i].second<<"\n";
    }
    
    return 0;
}

Measured memory_bytes: 11532
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define repi(i, a, b) for (int i = int(a); i < int(b); ++i)
typedef long long ll;
long long MOD = 1e9 + 7;
const long long INF = 1LL << 60;
using namespace std;

template <class T> inline bool chmin(T &a, T b) {
  if (a > b) {
    a = b;
    return true;
  }
  return false;
}

template <class T> inline bool chmax(T &a, T b) {
  if (a < b) {
    a = b;
    return true;
  }
  return false;
}

int main() {
  int n;
  cin >> n;
  string s;
  cin >> s;
  int ans = 0;
  rep(i, n - 2) {
    if (s[i] == 'A' && s[i + 1] == 'B' && s[i + 2] == 'C') {
      ans++;
    }
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 256
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.ArrayList;

public class Main {

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

		String str[] = br.readLine().split(" ");

		int x = Integer.parseInt(str[0]);
		int y = Integer.parseInt(str[1]);

		int ans = 0;

		if (x == 3) {
			ans += 100000;
		} else if (x == 2) {
			ans += 200000;
		} else if (x == 1) {
			ans += 300000;
		}
		if (y == 3) {
			ans += 100000;
		} else if (y == 2) {
			ans += 200000;
		} else if (y == 1) {
			ans += 300000;
			if (x == 1) {
				ans += 400000;
			}
		}
		System.out.println(ans);
	}
}

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

using namespace std;

typedef long long ll;

const ll MOD = 1e9 + 7;

ll get(ll x, ll y) {
  ll res = 1ll;
  while(y) {
    if(y & 1) {
      res = (res * x) % MOD; 
    }
    y >>= 1;
    x = (x * x) % MOD;
  }
  return res;
}

void solve() {
  int n, k; cin >> n >> k;
  vector <ll> cur(k + 1);
  for(int i = 1; i <= k; i++) {
    cur[i] = get((k / i), n);
  }
  for(int i = k; i >= 1; i--) {
    for(int j = i + i; j <= k; j += i) {
      cur[i] -= cur[j];
      cur[i] %= MOD;
      if(cur[i] < 0) cur[i] += MOD;
    }
  }
  ll ans = 0;
  for(ll i = 1; i <= k; i++) {
    //cout << cur[i] << '\n';
    ans = (ans + i * cur[i]) % MOD;
  }
  cout << ans << '\n';
}

int main() {
  int t; t = 1;
  for(int cs = 1; cs <= t; cs++) {
    solve();
  }
}


Measured memory_bytes: 4052
#include<stdio.h>
int main(void)
{
	int n,j,i[1000],p[1000],q[1000],r[1000],p2,q2,r2,c,flg,x[1000],cnt;
	while(1){
		cnt=0;
		flg=0;
		scanf("%d",&n);
		if(n==0)break;
		for(j=0;j<n;j++){
			scanf("%d %d %d %d",&i[j],&p[j],&q[j],&r[j]);
		}
		scanf("%d %d %d %d",&p2,&q2,&r2,&c);
		for(j=0;j<n;j++){
			if(p[j]<=p2&&q[j]<=q2&&r[j]<=r2&&p[j]*4+q[j]*9+r[j]*4<=c){
				x[cnt]=i[j];
				cnt++;
				flg=1;
			}
		}
		if(flg==1){
			for(j=0;j<cnt;j++){
				printf("%d\n",x[j]);
			}
		}
		else{
			printf("NA\n");
		}
	}
	return 0;
}

Measured memory_bytes: 1060
#include <iostream>
#include <iomanip>
#include <cmath>
#include <numeric>
using namespace std;

int main(){
	int n;
	while(cin >> n && n){
		int s[n];
		for(int &i:s) cin >> i;
		double sum = accumulate(s, s + n, 0.0), ave = sum / n;
		double ans = 0;
		for(int &i:s) ans += (i - ave) * (i - ave);
		cout << fixed << setprecision(10) << sqrt(ans / n) << endl;
	}
}

Measured memory_bytes: 3188
#include <bits/stdc++.h>
using namespace std;
#define INF 1e10

int main(void) {
  int N, M, R;
  cin >> N >> M >> R;
  vector<vector<long long>> graph(N, vector<long long>(N, INF));
  vector<int> root(R);
  for (int i = 0; i < R; i++) {
    int r;
    cin >> r;
    r--;
    root[i] = r;
  }
  sort(root.begin(), root.end());
  for (int i = 0; i < M; i++) {
    long long A, B, C;
    cin >> A >> B >> C;
    A--;
    B--;
    graph[A][B] = C;
    graph[B][A] = C;
  }

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

  long long ans = INF;
  do {
    long long tmp = 0;
    for (int i = 1; i < R; i++) {
      tmp += graph[root[i - 1]][root[i]];
    }
    ans = min(tmp, ans);
  } while (next_permutation(root.begin(), root.end()));

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

Measured memory_bytes: 512
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define LI list<int>
#define vct vector
#define D(a) (double)(a)
#define vi vct<int>
#define pii pair<int,int>
#define pll pair<ll,ll>
#define vvi vct<vi>
#define vll vct<ll>
#define vvll vct<vll>
#define vpii vct<pii>
#define vpll vct<pll>
#define vb vct<bool>
#define vs vector<string>
#define all(a) a.begin(),a.end()
#define allr(a) a.rbegin(),a.rend()
#define mp(a,b) make_pair(a,b)
#define pb push_back
#define ff first
#define ss second
#define bg begin()
#define UNIQUE(X) (X).erase(unique(all(X)),(X).end())
#define ft cout<<"for test"<<endl;
#define read(v,a,n) for(int i=a; i<n; i++)cin>>v[i];
#define print(v) for(auto it:v)cout<<it<<' ';cout<<endl;
#define PI 2*acos(0.0)
#define yes cout<<"YES"<<endl
#define no cout<<"NO"<<endl
#define FIO ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define t_c int test,cs=1;cin>>test;while(test--)
///................function.....................///
#define siz(s) (int)(s.size())
#define min3(a,b,c) min(a,min(b,c))
#define max3(a,b,c) max(a,max(b,c))
#define mod 1000000007
int main()
{
    FIO;
    ///freopen("in.txt","r",stdin);
    ///freopen("output.txt","w",stdout);
    int n,i,j;
    cin>>n;
    vpii v(n);
    bool ok=0;
    for(i=0; i<n; i++)
    {
        cin>>v[i].ff>>v[i].ss;
        if(i>=2)
        {
            if(v[i].ff==v[i].ss&&v[i-1].ff==v[i-1].ss&&v[i-2].ff==v[i-2].ss)
                ok=1;
        }
    }
    if(ok)
        cout<<"Yes"<<endl;
    else cout<<"No"<<endl;
    
}


Measured memory_bytes: 3648