akhauriyash/Code-Regression huggingface dataset:
MOD = 998244353
def resolve():
    # 多項式 解
    N, S = map(int, input().split())
    A = list(map(int, input().split()))
    dp = [[0] * (S + 1) for _ in range(N + 1)]
    dp[0][0] = 1

    ans = 0
    for i in range(N):
        dp[i + 1][0] = dp[i][0] + 1
        for j in range(1, S + 1):
            if j - A[i] >= 0:
                dp[i + 1][j] += dp[i][j - A[i]]
            dp[i + 1][j] = (dp[i][j] + dp[i + 1][j]) % MOD
        ans = (ans + dp[i + 1][-1]) % MOD
        ans %= MOD
    print(ans)


if __name__ == "__main__":
    resolve()


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

#define mini -1

int main(){
	int n;
	cin >> n;
	int ar[n+1][3], dp[n+1][3];
	for(int i = 0 ; i < n ; i++)
		for(int j = 0 ; j < 3 ; j++)
			cin >> ar[i][j];

	for(int i = 0 ; i < n ; i++){
		for(int j = 0 ; j < 3 ; j++){
			if(!i) dp[i][j] = ar[i][j];
			else{
				dp[i][j] = mini;
				for(int k = 0 ; k < 3 ; k++){
					if(k == j) continue;
					dp[i][j] = max(dp[i][j], dp[i-1][k] + ar[i][j]);
				}
			}
		}
	}

	cout << max(dp[n-1][0], max(dp[n-1][1], dp[n-1][2])) << endl;
	return 0;
}

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

int main(){
    int year, month, day;
    bool flug[5] = {false};

    while(cin >> year >> month >> day){
        if(year<1868 || (year==1868 && month<9) || (year==1868 && month==9 && day<8)) {
            cout << "pre-meiji" << endl;
        }
        else if(year<1912 || (year==1912 && month<7) || (year==1912 && month==7 && day<=29)){
            cout << "meiji " << year-1867 << " " << month << " " << day << endl;
        }
        else if(year<1926 || (year==1926 && month<12) || (year==1926 && month==12 && day<=24)){
            cout << "taisho " << year-1911 << " " << month << " " << day << endl;
        }
        else if(year<1989 || (year==1989 && month==1 && day<=7)){
            cout << "showa " << year-1925 << " " << month << " " << day << endl;
        }
        else{
            cout << "heisei " << year-1988 << " " << month << " " << day << endl;
        }
    }
    return 0;
}

Measured memory_bytes: 0
import sys;input=lambda:sys.stdin.readline().rstrip();aint=lambda:int(input());ints=lambda:list(map(int,input().split()))
import math;floor,ceil=lambda x:int(math.floor(x)),lambda x:int(math.ceil(x))
from functools import reduce;gcd=lambda*x:reduce(math.gcd,x);lcm=lambda*x:reduce(lambda x,y:(x*y)//gcd(x,y),x,1)
from collections import deque
Yes=lambda b:print("Yes"if b else"No");YES=lambda b:print("YES"if b else"NO")
is_even=lambda x:True if x%2==0 else False

def is_palindrome(s):
  n=len(s);b=True
  for i in range(int(0.5*n)):
    if s[i]!=s[n-i-1]:b=False
  return b

def main():
  a,b,n=ints()
  flr=lambda a,b,x:floor(a*x/b)-a*floor(x/b)
  if n>=b:
    print(flr(a,b,b-1))
  else:
    print(flr(a,b,n))


if __name__ == '__main__':
    main()

Measured memory_bytes: 9576
#include <bits/stdc++.h> 
using namespace std;
const int maxn = 1e5 + 5;
int n;
int fa[maxn];
set<int> G[maxn], g[maxn];
queue<pair<int, int> > q;
int find(int x) {
	return x == fa[x] ? x : fa[x] = find(fa[x]);
}
pair<int, int> mp(int x, int y) {
	if(x > y) {
		swap(x, y);
	}
	return make_pair(x, y);
}
int main() {
	scanf("%d", &n);
	for(int i = 1; i <= n; ++i) {
		fa[i] = i;
	}
	for(int i = 1; i < n; ++i) {
		int u, v;
		scanf("%d%d", &u, &v);
		G[u].insert(v);
		G[v].insert(u);
	}
	for(int i = 1; i < n; ++i) {
		int u, v;
		scanf("%d%d", &u, &v);
		g[u].insert(v);
		g[v].insert(u);
		if(G[u].find(v) != G[u].end()) {
			q.push(mp(u, v));
		}
	}
	for(int i = 1, u, v; i < n; ++i) {
		do {
			if(q.empty()) {
				return puts("NO"), 0;
			}
			u = find(q.front().first);
			v = find(q.front().second);
			q.pop();
		} while(u == v);
		if(g[u].size() > g[v].size()) {
			swap(u, v);
		}
		g[u].erase(v);
		g[v].erase(u);
		G[u].erase(v);
		G[v].erase(u);
		fa[u] = v;
		set<int> :: iterator it;
		for(it = G[u].begin(); it != G[u].end(); ++it) {
			if(g[*it].find(v) != g[*it].end()) {
				q.push(mp(*it, v));
			}
		}
		for(it = g[u].begin(); it != g[u].end(); ++it) {
			if(G[*it].find(v) != G[*it].end()) {
				q.push(mp(*it, v));
			}
		}
		for(it = G[u].begin(); it != G[u].end(); ++it) {
			G[*it].erase(u);
			G[*it].insert(v);
			G[v].insert(*it);
		}
		for(it = g[u].begin(); it != g[u].end(); ++it) {
			g[*it].erase(u);
			g[*it].insert(v);
			g[v].insert(*it);
		}
	}
	return puts("YES"), 0;
}

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

int main(){
 	int H,W,N;
	cin >> H >> W >> N;
	vector<int> a(N);
	for (int i = 0; i < N; i++)
		cin >> a[i];
	int res[H][W];
	int col = 0;
	for (int i = 0; i < H; i++) {
		if ((i & 1) == 0)
			for (int j = 0; j < W; j++) {
				if (a[col] == 0)
					col++;
				res[i][j] = col+1;
				a[col]--;
			}
		else
			for (int j = W-1; j >=0; j--) {
				if (a[col] == 0)
					col++;
				res[i][j] = col+1;
				a[col]--;
			}		
	}
	for (int i = 0; i < H; i++) {
		for (int j = 0; j < W-1; j++) {
			cout << res[i][j] << " ";
		}
		cout << res[i][W-1] << endl;
	}
}



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

typedef long long ll;

const int MX = 1000010;

vector<int> pr;
int pchk[MX];

void sieve() {
    for(int i = 2; i < MX; i++) {
        if(!pchk[i]) {
            pr.push_back(i);
        }
        for(int j = 0; j < pr.size() && i * pr[j] < MX; j++) {
            pchk[ i * pr[j] ] = 1;
            if(i % pr[j] == 0) break;
        }
    }
}

ll N, P;

int main() {
    sieve();

    cin >> N >> P;

    if(N == 1) {
        printf("%lld", P);
        return 0;
    }

    ll ans = 1;
    for(int i = 0; i < pr.size() && pr[i] <= sqrt(P); i++) {
        int cnt = 0;
        while(P % pr[i] == 0) {
            P /= pr[i];
            cnt++;
        }
        for(int j = 0; j < cnt / N; j++) {
            ans *= pr[i];
        }
    }
    printf("%lld", ans);
}


Measured memory_bytes: 4732
k = int(input())
count = 0
before = 0
if k % 2 == 0 or k % 5 == 0:
    print(-1)
    exit()

ai = 0
i = 0
while True:
    ai = (ai*10+7) % k
    i += 1
    if ai == 0:
        print(i)
        break

Measured memory_bytes: 9112
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int N;
  cin>>N;
  long l=0,ll=0,lll=0;
  
  //初期値
  l=1;ll=2;
  
  for (int i=0;i<N-1;i++){
    lll=l;
    l=l+ll;
    ll=lll;
  }
  cout<<l<<endl;
  
}

Measured memory_bytes: 256
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
    ($($r:tt)*) => {
        let s = {
            use std::io::Read;
            let mut s = String::new();
            std::io::stdin().read_to_string(&mut s).unwrap();
            s
        };
        let mut iter = s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
}
macro_rules! input_inner {
    ($iter:expr) => {};
    ($iter:expr, ) => {};

    ($iter:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($iter, $t);
        input_inner!{$iter $($r)*}
    };
}
macro_rules! read_value {
    ($iter:expr, ( $($t:tt),* )) => {
        ( $(read_value!($iter, $t)),* )
    };

    ($iter:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($iter, $t)).collect::<Vec<_>>()
    };

    ($iter:expr, chars) => {
        read_value!($iter, String).chars().collect::<Vec<char>>()
    };

    ($iter:expr, usize1) => {
        read_value!($iter, usize) - 1
    };

    ($iter:expr, $t:ty) => {
        $iter.next().unwrap().parse::<$t>().expect("Parse error")
    };
}
fn main() {
    input!{
        n: usize,
        a: [i32; n],
    }
    println!("{}", {
        if a.iter().filter(|&&x| x % 2 == 0).all(|&x| x % 3 == 0 || x % 5 == 0) {
            "APPROVED"
        }
        else {
            "DENIED"
        }
    });
}


Measured memory_bytes: 4352
# ANSHUL GAUTAM
# IIIT-D

from math import *
from copy import *					# ll = deepcopy(l)
from heapq import *					# heappush(hp,x)
from string import *				# alpha = ascii_lowercase
from random import *				# l.sort(key=lambda l1:l1[0]-l1[1]) => ex: sort on the basis difference
from bisect import *				# bisect_left(arr,x,start,end)  => start and end parameters are temporary
from sys import stdin				# bisect_left return leftmost position where x should be inserted to keep sorted
from sys import maxsize				# minn = -maxsize
from operator import *				# d = sorted(d.items(), key=itemgetter(1))
from itertools import *				# pre = [0] + list(accumulate(l))
from collections import Counter		# d = dict(Counter(l))
from collections import defaultdict # d = defaultdict(list)

'''
24
'''

def isPrime(x):
	if(x == 1 or x == 4):
		return False
	elif(x in [2,3,5]):
		return True
	for i in range(2,int(sqrt(x))+1):
		if(x%i == 0):
			return False
	return True

def primeFactors(n):
	d = defaultdict(int)
	if(isPrime(n)):
		return {n:1}
	else:
		while(not n%2):
			n //= 2
			d[2] += 1
		for i in range(3,int(sqrt(n))+1,2):
			while(not n%i):
				n //= i
				d[i] += 1
		if(n > 2):
			d[n] += 1
	return dict(d)

def solve(l):
	ans = 0
	d = primeFactors(l)
	for i in d:
		l = d[i]
		ans += max(0,int((sqrt(1+8*l)-1)/2))
	return ans

N = int(stdin.readline())
ans = solve(N)
print(ans)



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

int main() {
    int N, M, sum = 0, count = 0;
    cin >> N >> M;
    vector<int> A(N);
    rep(i, N){
        cin >> A[i];
        sum += A[i];
    }
    
    rep(i, N){
        if(A[i] * 4 * M >= sum){
            count++;
        }
    }

    if(count < M){
        cout << "No" << endl;
    } else {
        cout << "Yes" << endl;
    }
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main(){

int a,b,c;
cin>>a;
if(a<1200)
{
    cout<<"ABC"<<endl;
}
else if(a<2800 && a>=1200)
{
    cout<<"ARC"<<endl;
}
else
    cout<<"AGC"<<endl;

    return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<cstdio>
#include<algorithm>
#include<cstdlib>
#include<cmath>
#include<vector>
#include<utility>
#include<queue>
#include<stack>
#include<set>
#include<map>
#include<unordered_set>
#include<unordered_map>
#include<bitset>
#include<iomanip>
#include<list>
#include<deque>
using namespace std;
//#define MODE 1
#ifdef MODE
#define DEB(X) cout<< #X <<": "<<X<<" ";
#define END cout<<endl;
#else
#define DEB(X) {}
#define END {}
#endif
typedef long long ll;
#define int ll
#define uset unordered_set
#define umap unordered_map
typedef std::pair<int,int> P;
struct edge{int to,cost;};
const int INF=100000000000000000;
const int INF2=9223372036854775807;
const int MOD=1000000007;
#define REP(i,n) for(int i=0;i<(int)(n);i++)
#define min(X,Y) (((int)(X)<(int)(Y))?(X):(Y))
#define max(X,Y) (((int)(X)>(int)(Y))?(X):(Y))
#define MAX(X,Y) (*max_element(X,Y))
#define MIN(X,Y) (*min_element(X,Y))
#define NP(X,Y) next_permutation(X,Y)
#define setp(X,Y) cout<<fixed<<setprecision(Y)<<X;
int ceil2(int a,int b){if(a%b==0){return a/b;}else{return a/b+1;}}
int pow2(int a,int b){int r=1;for(int i=1;i<=b;i++){r*=a;}return r;}
int Log2(int a){int t=0;while(1){if(a==0||a==1){break;}a/=2;t++;}return t;}

int N,S,T;
int A[100010],B[100010];
bool F[100010];
int d[100010];
int d2[100010];
vector<int> G[100010];


void dfs(int s,int dis){
	F[s]=true;
	d[s]=dis;
	REP(i,G[s].size()){
		int e=G[s][i];
		if(F[e]==false){
			dfs(e,dis+1);
		}
	}
}



signed main(){
	cin>>N>>T>>S;
	T--,S--;
	REP(i,N-1){
		cin>>A[i]>>B[i];
		A[i]--,B[i]--;
		G[A[i]].push_back(B[i]);
		G[B[i]].push_back(A[i]);
	}
	dfs(S,0);
	REP(i,N){
		d2[i]=d[i];
		F[i]=false;
		d[i]=0;
	}
	dfs(T,0);
	int M=0;
	REP(i,N){
		if(d2[i]>=d[i]&&d2[i]>M){
			M=d2[i];
		}
	}
	int ans=0;
	cout<<M-1<<endl;
	return 0;
}


Measured memory_bytes: 12928
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define repbtw(i, a, b) for (int i = a; i <= (int)(b); i++)
#define all(v) v.begin(), v.end()
#define pr(x) cout << x << endl


int main()
{
    string n;
    cin >> n;
    char l = n.at(n.size() - 1);
    if(l == '0' || l == '1' || l == '6' || l == '8') {
        pr("pon");
    }else if(l == '3') {
        pr("bon");
    }else {
        pr("hon");
    }

    return 0;
}



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

int main()
{
    deque<char> q;
    string s;
    cin >> s;
    for (int i = 0; i < s.size(); i++)
    {
        if (s[i] == '0' || s[i] == '1')
            q.push_back(s[i]);
        else if (!q.empty())
            q.pop_back();
    }
    for (int i = 0; i < q.size(); i++)
        cout << q[i];
    cout << endl;
}

Measured memory_bytes: 256
#pragma GCC optimize(2)
#include<bits/stdc++.h>
#define ll long long
#define maxn 1000005
#define inf 1e9
#define eps 1e-10
using namespace std;

inline int read()
{
	int x=0,w=1; char c=getchar();
	while(c<'0'||c>'9') {if(c=='-') w=-1; c=getchar();}
	while(c<='9'&&c>='0') {x=(x<<1)+(x<<3)+c-'0'; c=getchar();}
	return w==1?x:-x;
}

int n,k,a1[maxn],a2[maxn],t[maxn],b[10],ans[maxn];

inline void wk(int a,int x)
{
	b[1]=a1[a],b[2]=a2[a],b[3]=a1[x],b[4]=a2[x];
	sort(b+1,b+5); a1[a]=b[4],a2[a]=b[3];
}

int main()
{
	k=read(); n=(1<<k);
	for(int i=0;i<n;i++) t[i]=read(),a1[i]=t[i];
	for(int i=0;i<k;i++) for(int s=0;s<n;s++) if((s&(1<<i))!=0) wk(s,(s^(1<<i)));
	for(int s=1;s<n;s++) ans[s]=max(ans[s-1],a1[s]+a2[s]),printf("%d\n",ans[s]);
	return 0;
}

Measured memory_bytes: 16384
#include <bits/stdc++.h>
using namespace std;
//#include <boost/multiprecision/cpp_int.hpp>
//using multiInt = boost::multiprecision::cpp_int;

using ll = long long int;
using ld = long double;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
template <typename Q_temp>
using smaller_queue = priority_queue<Q_temp, vector<Q_temp>, greater<Q_temp>>;

const ll MOD = (ll)(1e9 + 7);
const int INF = (int)1e9;
const ll LINF = (ll)4e18;
const double PI = acos(-1.0);

#define REP(i, m, n) for (ll i = m; i < (ll)(n); ++i)
#define rep(i, n) REP(i, 0, n)
#define MP make_pair
#define MT make_tuple
#define YES(n) cout << ((n) ? "YES" : "NO") << endl
#define Yes(n) cout << ((n) ? "Yes" : "No") << endl
#define Possible(n) cout << ((n) ? "Possible" : "Impossible") << endl
#define all(v) v.begin(), v.end()
#define NP(v) next_permutation(all(v))
#define dbg(x) cerr << #x << ":" << x << endl;

vector<int> Dx = {0, 0, -1, 1, -1, 1, -1, 1, 0};
vector<int> Dy = {1, -1, 0, 0, -1, -1, 1, 1, 0};

int main()
{
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout << setprecision(20) << setiosflags(ios::fixed);
  int n;
  cin >> n;
  int t[210];
  ld v[210];
  rep(i, n) cin >> t[i + 1];
  rep(i, n) cin >> v[i + 1];
  t[0] = t[n + 1] = 0.0, v[0] = v[n + 1] = 0.0;
  ld sum = 0.0;
  ld graph[210][40100]; //i番目のグラフのf(0.5*j)

  int t_max = 0;
  rep(i, n) t_max += t[i + 1];

  int t_sum = 0;

  rep(i, n + 2)
  {
    for (int j = t_sum * 2; j <= (t_sum + t[i]) * 2; j++)
    {
      graph[i][j] = v[i];
    }

    for (int j = t_sum * 2 - 1; j >= 0; j--)
    {
      graph[i][j] = graph[i][j + 1] + 0.5;
    }

    for (int j = (t_sum + t[i]) * 2 + 1; j <= t_max * 2; j++)
    {
      graph[i][j] = graph[i][j - 1] + 0.5;
    }
    t_sum += t[i];
  }

  ld before = 0.0;
  ld ans = 0.0;
  for (int j = 0; j <= t_max * 2; ++j)
  {
    ld Min = INF;
    rep(i, n + 2) Min = min(Min, graph[i][j]);
    if (j != 0)
    {
      ans += (before + Min) * 0.5 / 2.0;
    }
    before = Min;
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 65024
#include <algorithm>
#include <cstdio>
#include <iostream>
#include <cfloat>
#include <climits>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <queue>
#include <sstream>
#include <stack>
#include <time.h>
#include <vector>
#include <complex>
#include <map>
#include <set>
#include <iomanip>
#include <math.h>
#include <stdlib.h>
using namespace std;
bool prime(int i){
  int num=0;
  for (int j=1;j<=i;j++)
    if (i % j == 0)
      num++;
  if (num==2) return true;
  return false;
}
int main(){
  int n;
  cin>>n;
  for (int i=2;i<=55555 && n > 0;i++){
   	if (prime(i) && i % 5 == 2){
   	  cout<<i<<" ";
   	  n--;
   }
  }
  return 0;
}

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

int ans,s,n;

void fanc(int sum,int i,int j){
	if (sum==s&&i==n) {
		ans++;
		return;
	}
	if (sum>s||i>n||j>9) {
		return;
	}
	fanc(sum+j,i+1,j+1);
	fanc(sum,i,j+1);
	
	return;
}


int main () {
	while(1){
		cin>>n>>s;
		if (n==0&&s==0) {
			break;
		}
		ans=0;
		fanc(0,0,0);
		cout << ans <<endl;
	}
}
			
			
			
			
			
			
			
			

Measured memory_bytes: 0
#include<iostream>
#include<vector>
#include<queue>
#include<utility>
using namespace std;

typedef pair<int, int> P;

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

int main() {
	int w, h;
	while (cin >> w >> h, w) {
		vector<vector<int>>ma(w, vector<int>(h));
		for (int i = 0; i < h;i++) {
			for (int j = 0; j < w;j++) {
				cin >> ma[j][i];
			}
		}
		int ans = 0;
		for (int i = 0; i < w;i++) {
			for (int j = 0; j < h;j++) {
				if (ma[i][j] == 1) {
					ans++;
					queue<P> q;
					q.push(P(i, j));
					ma[i][j] = 0;
					while (!q.empty()) {
						P p = q.front(); q.pop();
						for (int k = 0; k < 8; k++) {
							int nx = p.first + dx[k], ny = p.second + dy[k];
							if (nx < w && nx>=0 && ny < h && ny>=0 && ma[nx][ny]==1) {
								ma[nx][ny] = 0; q.push(P(nx, ny));
							}
						}
					}
				}
			}
		}
		cout << ans << endl;
	}
}

Measured memory_bytes: 3176
N,Y = map(int,input().split())
 
a = -1
b = -1
c = -1
for i in range(int(N+1)):
  for j in range(int(N+1-i)):
    k = int(N - i - j)
    total = int(10000*i + 5000*j + 1000*k)
    if (total == Y) and int(i + j + k) == N:
      a = i
      b = j
      c = k
      break
print("{} {} {}".format(a,b,c))

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

const int MOD = (int)1e9+7;

int main(){
	int N,M,Q;
	cin >> N >> M >> Q;
	vector<vector<int>> LR(N+1,vector<int>(N+1,0));
	for(int i=0;i<M;i++){
		int L,R;
		cin >> L >> R;
		LR.at(L).at(R)++;
	}
	vector<int> p(Q);
	vector<int> q(Q);
	for(int i=0;i<Q;i++)	cin >> p.at(i) >> q.at(i);

	vector<vector<int>> sum(N+1,vector<int>(N+1,0));
	for(int i=0;i<N+1;i++){
		for(int j=0;j<N+1;j++){
			sum.at(i).at(j)=LR.at(i).at(j);
			if(i-1>=0)	sum.at(i).at(j)+=sum.at(i-1).at(j);
			if(j-1>=0)	sum.at(i).at(j)+=sum.at(i).at(j-1);
			if(i-1>=0 && j-1>=0)	sum.at(i).at(j)-=sum.at(i-1).at(j-1);
		}
	}
	for(int i=0;i<Q;i++){
		int L=p.at(i);
		int R=q.at(i);
		cout << sum.at(R).at(R)-sum.at(R).at(L-1)-sum.at(L-1).at(R)+sum.at(L-1).at(L-1) << endl;
	}

	return 0;
}


Measured memory_bytes: 3712
N, M = list(map(int, input().split()))
As = set()
for i in range(0, M):
    As.add(int(input()))
C = 10 ** 9 + 7

dp = [0 for _ in range(N + 1)]
dp[0] = 1
dp[1] = 0 if 1 in As else 1

for i in range(2, N + 1):
    if i in As:
        dp[i] = 0
    else:
        dp[i] = (dp[i - 1] + dp[i - 2]) % C

print(dp[N])

Measured memory_bytes: 56536
#include <iostream>
#include <string>
#include <vector>
#include <map>
#include <algorithm>
#include <cmath>
#include <sstream>
#include <iomanip>
#include <set>
using namespace std;
typedef long long int ll;

#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define YES cout << "YES" << endl
#define Yes cout << "Yes" << endl
#define yes cout << "yes" << endl
#define NO cout << "NO" << endl
#define No cout << "No" << endl
#define no cout << "no" << endl

const int INF = 1001001001;
const int mod = 1000000007;
#define PI 3.14159265359;

void P(int x) {cout << x << endl;}
void P(long x) {cout << x << endl;}
void P(double x) {cout << x << endl;}
void P(ll x) {cout << x << endl;}
void P(string x) {cout << x << endl;}
void P(char 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;}

int main() {
  int n;
  cin >> n;
  int mi, ma;
  mi = INF;
  ma = 0;
  rep (i, n) {
    int tmp;
    cin >> tmp;
    ma = max(ma, tmp);
    mi = min(mi, tmp);
  }
  P(ma - mi);
  return 0;
}



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

const int N_MAX = 26;

int main(){
    int N;  string S;
    cin >> N >> S;
    int len = S.size();

    for(int i = 0; i < len; i++){
        S[i] += N;
        if(S[i] > 'Z')
            S[i] -= N_MAX;
    }  
    cout << S << endl;
}

Measured memory_bytes: 256
#ifdef LOCAL
#define _GLIBCXX_DEBUG
#endif
#include <bits/stdc++.h>
using namespace std;
#define pb push_back
#define mp make_pair
#define fst first
#define snd second
#define forn(i, n) for (int i = 0; i < (int)(n); ++i)
#define ford(i, n) for (int i = ((int)(n) - 1); i >= 0; --i)
typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vll;
typedef vector<char> vc;
typedef pair<int, int> pii;
typedef vector<pii> vii;
#define sz(c) (int)(c).size()
#define all(c) (c).begin(), (c).end()

const int mod = (int)1e9 + 7;
void add (int &a, int b)
{
    a += b;
    if (a >= mod)
        a -= mod;
}
void sub (int &a, int b)
{
    a -= b;
    if (a < 0)
        a += mod;
}
int mult (int a, int b)
{
    return (ll)a * b % mod;
}

void solve (int n)
{
    int m;
    cin >> m;
    vvi a(n, vi(m));
    forn (i, n) forn (j, m)
    {
        cin >> a[i][j];
        --a[i][j];
    }

    int ans = n;

    forn (it, m)
    {
        vi cnt(m);
        forn (i, n)
            cnt[a[i][0]]++;

        int ptr = max_element(all(cnt)) - cnt.begin();
        ans = min(ans, cnt[ptr]);

        forn (i, n)
            a[i].erase(find(all(a[i]), ptr));
    }

    cout << ans << endl;
}

int main()
{
#ifdef LOCAL
    freopen("input.txt", "rt", stdin);
    freopen("output.txt", "w", stdout);
#endif // ONLINE_JUDGE

    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);

    int n;
    while (cin >> n)
        solve(n);
}


Measured memory_bytes: 640
import collections
def main():
    N = int(input())
    A = list(map(int, input().split()))

    B = [a+i for i, a in enumerate(A)]
    C = [a-i for i, a in enumerate(A)]

    
    c = collections.Counter(C)

    ans = 0
    for b in B:
        ans += c.get(-b, 0)
    print(ans)


if __name__ == '__main__':
    main()

Measured memory_bytes: 134380
import java.io.*;
import java.math.*;
import java.security.*;
import java.text.*;
import java.util.*;
import java.util.concurrent.*;
import java.util.function.*;
import java.util.regex.*;
import java.util.stream.*;
import static java.util.stream.Collectors.joining;
import static java.util.stream.Collectors.toList;

public class Main
{
    public static void main(String[] args)
    {
        Scanner in = new Scanner(System.in);
        int n=in.nextInt();
        int[] dp=new int[2001];
        dp[0]=1;
        dp[3]=1;
        dp[4]=1;
        dp[5]=1;
        long MOD=1000000007;
        for(int i=6;i<=2000;i++)
        {
            long sum=0L;
            for(int j=i-3;j>=0;j--)
            {
                sum+=dp[j];
                sum%=MOD;
            }
            dp[i]=(int)sum;
        }
        System.out.println(dp[n]);
        
    }
}

Measured memory_bytes: 35760
#include <iostream>
#include <stdio.h>
#include <vector>
#include <algorithm>
#include <math.h>
#include <numeric>
#include <iomanip>
#include <map>
#include <queue>
#include <list>


#define REP(i, n ,N) for(ll i = (n); i < (N); i++)
//#define RREP(i, n ,N) for(ll i = (N-1); i >= (n); i--)
#define p(s) cout<<(s)<<endl
#define p2(a, b) cout<<(a)<<" "<<(b)<<endl
#define vint vector<int>
#define INF 1e9

using namespace std;
typedef long long  ll;

int main(){
    string s;
    cin >> s;
    if(s == "ABC"){
        p("ARC");
    } else {
        p("ABC");
    }

    return 0;
}


Measured memory_bytes: 3628
#include<bits/stdc++.h>
using namespace std;
const int maxn=1e5+7;
int num[maxn];
int main()
{
    string stra;
    string strb;
    cin>>stra>>strb;
    int len=stra.size();
    memset(num,-1,sizeof(num));
    for(int i=0;i<len;i++)
    {
        if(num[stra[i]]==-1)
        {
            num[stra[i]]=strb[i];
        }
        else
        {
            if(num[stra[i]]!=strb[i])
            {
                cout<<"No"<<endl;
                return 0;
            }
        }
    }
    memset(num,-1,sizeof(num));
    for(int i=0;i<len;i++)
    {
        if(num[strb[i]]==-1)
        {
            num[strb[i]]=stra[i];
        }
        else
        {
            if(num[strb[i]]!=stra[i])
            {
                cout<<"No"<<endl;
                return 0;
            }
        }
    }
    cout<<"Yes"<<endl;
    return 0;
}


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

using namespace std;
#define rep(i, n) for (ll i = 0; i < (n); ++i)
#define sz(x) ll(x.size())
typedef long long ll;
//typedef pair<int, int> P;
typedef pair<ll, ll> P;
//const double INF = 1e10;
const ll INF = 1001001001;
#define mins(x, y) x = min(x, y)
#define maxs(x, y) x = max(x, y)

typedef tuple<string, int, int> T;

int main() {

    int a, b;
    cin >> a >> b;

    if (a >= 13) {
        cout << b << endl;
        return 0;
    }
    if (a > 5) {
        cout << (b / 2) << endl;
        return 0;
    }

    cout << 0 << endl;

}



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

using ll = long long;
using pii = pair<int, int>;
template <class T>
using V = vector<T>;
template <class T>
using VV = V<V<T>>;

#define pb push_back
#define eb emplace_back
#define mp make_pair
#define fi first
#define se second
#define rep(i, n) rep2(i, 0, n)
#define rep2(i, m, n) for (int i = m; i < (n); i++)
#define per(i, b) per2(i, 0, b)
#define per2(i, a, b) for (int i = int(b) - 1; i >= int(a); i--)
#define ALL(c) (c).begin(), (c).end()
#define SZ(x) ((int)(x).size())

constexpr ll TEN(int n) { return (n == 0) ? 1 : 10 * TEN(n - 1); }

template <class T, class U>
void chmin(T& t, const U& u) {
    if (t > u) t = u;
}
template <class T, class U>
void chmax(T& t, const U& u) {
    if (t < u) t = u;
}

template <class T, class U>
ostream& operator<<(ostream& os, const pair<T, U>& p) {
    os << "(" << p.first << "," << p.second << ")";
    return os;
}

template <class T>
ostream& operator<<(ostream& os, const vector<T>& v) {
    os << "{";
    rep(i, v.size()) {
        if (i) os << ",";
        os << v[i];
    }
    os << "}";
    return os;
}

#ifdef LOCAL
void debug_out() { cerr << endl; }
template <typename Head, typename... Tail>
void debug_out(Head H, Tail... T) {
    cerr << " " << H;
    debug_out(T...);
}
#define debug(...) \
    cerr << __LINE__ << " [" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)
#define dump(x) cerr << __LINE__ << " " << #x << " = " << (x) << endl
#else
#define debug(...) (void(0))
#define dump(x) (void(0))
#endif

const int maxn = 100010;

V<int> g[maxn];
int sz[maxn], par[maxn];

void dfs(int v, int p) {
    sz[v] = 1;
    par[v] = p;
    for (int to : g[v]) {
        if (to != p) {
            dfs(to, v);
            sz[v] += sz[to];
        }
    }
}

int main() {
    int N;
    cin >> N;
    rep(i, N - 1) {
        int a, b;
        cin >> a >> b;
        --a, --b;
        g[a].pb(b);
        g[b].pb(a);
    }
    dfs(0, -1);
    V<int> vs;
    int v = N - 1;
    while (v != -1) {
        vs.pb(v);
        v = par[v];
    }
    reverse(ALL(vs));
    int len = vs.size();
    debug(vs);
    int b = sz[vs[(len + 1) / 2]], a = N - b;
    puts(a > b ? "Fennec" : "Snuke");

    return 0;
}

Measured memory_bytes: 13436
#include <iostream>
#include <queue>
using namespace std;
int W,H,sx,sy;
int A[21][21];
int inf = 1e9;

bool in(int x,int y){
    return 1<=x && x<=H && 1<=y && y<=W;
}

int dfs(int x,int y,int ti){
    if(ti==10) return inf;
    int res = inf;
    if(in(x+1,y) && A[x+1][y]!=1){
        for(int i=x+1;i<=H;i++){
            if(A[i][y]==1){
                A[i][y] = 0;
                res = min(res,dfs(i-1,y,ti+1)+1);
                A[i][y] = 1;
                break;
            }
            if(A[i][y]==3) return 1;
        }
    }
    if(in(x-1,y) && A[x-1][y]!=1){
        for(int i=x-1;i>=1;i--){
            if(A[i][y]==1){
                A[i][y] = 0;
                res = min(res,dfs(i+1,y,ti+1)+1);
                A[i][y] = 1;
                break;
            }
            if(A[i][y]==3) return 1;
        }
    }
    if(in(x,y+1) && A[x][y+1]!=1){
        for(int i=y+1;i<=W;i++){
            if(A[x][i]==1){
                A[x][i] = 0;
                res = min(res,dfs(x,i-1,ti+1)+1);
                A[x][i] = 1;
                break;
            }
            if(A[x][i]==3) return 1;
        }
    }
    if(in(x,y-1) && A[x][y-1]!=1){
        for(int i=y-1;i>=1;i--){
            if(A[x][i]==1){
                A[x][i] = 0;
                res = min(res,dfs(x,i+1,ti+1)+1);
                A[x][i] = 1;
                break;
            }
            if(A[x][i]==3) return 1;
        }
    }
    return res;
}

int main(){
    while(cin >> W >> H && W>0){
        for(int i=1;i<=H;i++){
            for(int j=1;j<=W;j++){
                cin >> A[i][j];
                if(A[i][j]==2){
                    sx = i; sy = j;
                }
            }
        }
        int ans = dfs(sx,sy,0);
        cout << (ans!=inf? ans:-1) << endl;
    }
}


Measured memory_bytes: 3012
#include <bits/stdc++.h>
#include <unordered_map>
#define mem(ara, a) memset(ara, a, sizeof(ara))
#define fo freopen("output.txt", "w", stdout)
#define fi freopen("bruh.txt", "r", stdin)
#define int long long
#define sp " "
#define pb push_back
#define ff first
#define sz(x) x.size();
#define len(x) x.length();
#define ss second
#define vi vector<int>
#define double long double
#define all(x) x.begin(), x.end()
#define allr(x) x.rbegin(), x.rend()
#define pii pair<int, int>


long long inf = 2e18;
long long minf = -inf;
int ans = 0;
using namespace std;

signed main() {
int cn=0;
string str;
cin >> str;
for (int i=0;i<str.length();i++){
if (str[i-1]==str[i] and str[i-2]==str[i-3]){
    cn+=5;
}
}
if (cn>=2){
    cout << "Yes" << endl;
}
else if (cn<2){
    cout << "No" << endl;
}
}


Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <fstream>
#include <sstream>
#include <vector>
#include <algorithm>
#include <math.h>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <stack>
#include <bitset>

#define _GLIBCXX_DEBUG
#define rep(i, n) for (int64_t i = 0; i < (int64_t)(n); i++)
using namespace std;
using vi = vector<int64_t>;
using vvi = vector<vi>;

int main(int argc, const char * argv[]) {
    // fasten cin
    cin.tie(0);
    ios::sync_with_stdio(false);
    // implement
    int64_t x,a,b;
    cin >> x >> a >> b;
    cout << (abs(x-a)<abs(x-b)?"A":"B") << endl;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define rrep(i,n) for (int i = (n)-1; i >= 0; i--)
#define rep2(i,s,n) for (int i = (s); i < (n); ++i)
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define pb push_back
#define eb emplace_back
#define vi vector<int>
#define vvi vector<vector<int>>
#define vl vector<ll>
#define vvl vector<vector<ll>>
#define vd vector<double>
#define vs vector<string>
#define vc vector<char>
#define vb vector<bool>
#define vp vector<P>
using namespace std;
using ll = long long;
using P = pair<int,int>;
using LP = pair<ll,ll>;
template<class S,class T> istream& operator>>(istream &is,pair<S,T> &p) { return is >> p.first >> p.second; }
template<class S,class T> ostream& operator<<(ostream &os,const pair<S,T> &p) { return os<<'{'<<p.first<<","<<p.second<<'}'; }
template<class T> istream& operator>>(istream &is,vector<T> &v) { for(T &t:v){is>>t;} return is; }
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; }
void Yes(bool b) { cout << (b ? "Yes" : "No") << endl; }
void YES(bool b) { cout << (b ? "YES" : "NO") << endl; }
template<class T> bool chmin(T& a,T b) {if(a > b){a = b; return true;} return false;}
template<class T> bool chmax(T& a,T b) {if(a < b){a = b; return true;} return false;}
const int inf = 1001001001;
const ll linf = 1001001001001001001;

int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr); cout.tie(nullptr);
    int h,w,k;
    cin >> h >> w >> k;
    vs c(h);
    cin >> c;
    int ans = 0;
    rep(row,1<<h) {
        rep(col,1<<w) {
            vs nc = c;
            rep(i,h) if(row>>i&1) {
                rep(j,w) nc[i][j] = '.';
            }
            rep(i,w) if(col>>i&1) {
                rep(j,h) nc[j][i] = '.';
            }
            int cnt = 0;
            rep(i,h) rep(j,w) if(nc[i][j] == '#') cnt++;
            if(cnt == k) ans++;
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 3656
#include<iostream>
#include<cstdio>
#include<string>
#include<algorithm>
#include<utility>
#include<numeric>
#include<vector>
#include<map>
#include<set>
#include<tuple>
#include<stack>
#include<queue>
#include<functional>
#include<iterator>
#include<cmath>

using namespace std;

typedef pair<int,int> P;

vector<int> es[50];	//es[from][to] 0origin

int used[50];
int low[50];

int ans=0;

void dfs(int n,int count,int parent){
	low[n] = count;

	int next;
	for(int i=0;i<es[n].size();i++){
		next = es[n][i];
		if(next == parent) continue;
		if(!used[next]){
			used[next] = 1;
			dfs(next,count+1,n);
			low[n] = min(low[n],low[next]);
		}
		else if(low[next] < low[n]) low[n] = low[next];
	}
	if(n != 0 && count == low[n]) ans++;
	
	return;
}

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

	int n,m;
	cin >> n >> m;

	int a,b;
	for(int i=0;i<m;i++){
		cin >> a >> b;
		a--;b--;
		es[a].push_back(b);
		es[b].push_back(a);
	}
	used[0] = 1;
	dfs(0,1,-1);

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

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
main()
{
    double a1,a2,b1,b2;
    double c,i;
    cin>>a1>>a2>>b1>>b2;
    scanf("%lf",&c);
    for(i=0; i<c; i++)
    {
        double e1,e2,c1,c2,f1,f2,d1,d2;
        cin>>d1>>d2;
        if(a1==b1)
        {
            e1=0;
        }
        else
        {
             e1=(b2-a2)/(b1-a1);
        }

        c1=(a2-(e1*a1));
        if(e1==0)
        {
            e2=0;
        }
        else
        {
            e2=(-1)/e1;
        }

        c2=(d2-(e2*d1));
        if(a1==0 && a2==0 && b1==0)
        {
            f1=0;
            f2=d2;
        }
        else if(a1==0&& b1==0 &&b2==0)
        {
            f1=0;
            f2=d2;
        }
        else if(e1==0)
        {
            f1=d1;
            f2=0;
        }
        else
        {
            f1=((c1-c2)/(e2-e1));
            f2=(((c1*e2)-c2*e1)/(e2-e1));

        }
        printf("%.10lf %.10lf\n",f1,f2);
    }
    return 0;
}



Measured memory_bytes: 3280
#include <iostream>
#include <math.h>
#include <string>
#include <algorithm>
using namespace std;

int main() {
  int n;
  cin >> n;
  
  int p[n];
  
  int ans=0;
  for(int i=0; i<n; i++){
    cin >> p[i];
  }
  
  for(int i=0; i<n-2; i++){
    if(p[i]<p[i+1]&&p[i+1]<p[i+2]){
      ans++;
    }
    if(p[i]>p[i+1]&&p[i+1]>p[i+2]){
      ans++;
    }
  }
  
  cout << ans;
}

Measured memory_bytes: 256
#from statistics import median
#import collections
#aa = collections.Counter(a) # list to list || .most_common(2)で最大の2個とりだせるお a[0][0]
from fractions import gcd
from itertools import combinations,permutations,accumulate # (string,3) 3回
#from collections import deque
from collections import deque,defaultdict,Counter
import decimal
import re
#import bisect
#
#    d = m - k[i] - k[j]
#    if kk[bisect.bisect_right(kk,d) - 1] == d:
#
#
#
# pythonで無理なときは、pypyでやると正解するかも！！
#
#

import sys
sys.setrecursionlimit(10000000)
mod = 10**9 + 7
#mod = 9982443453
def readInts():
  return list(map(int,input().split()))
def I():
  return int(input())
a,b = map(decimal.Decimal,input().split())
print(int(a*b))


Measured memory_bytes: 10496
#include <bits/stdc++.h>
 
using namespace std;
 
typedef long long ll;
typedef vector<ll> vll;
typedef vector<vll> vvll;
typedef pair<ll,ll> P;
typedef vector<P> vp;
typedef vector<string> vs;
typedef vector<bool> vb;

const ll mod=1e9+7;
const ll inf=1e16;

#define rep(i,m,n) for(ll i=m;i<n;i++)
#define repr(i,m,n) for(ll i=m-1;i>=n;i--)
#define fi first
#define se second
#define chmax(x,y) x=max(x,y)
#define chmin(x,y) x=min(x,y)
#define eb(x) emplace_back(x)
#define all(x) x.begin(),x.end()
#define allr(x) x.rbegin(),x.rend()
#define sum(x) accumulate(all(x),0)
#define gll greater<ll>()

void solve(){
  ll n;
  cin >> n;
  
  vll ans(n+1,0);
  
  ll m=sqrt(double(n))+2;
  
  rep(x,1,m){
   rep(y,1,m){ 
    rep(z,1,m){
     ll tot=x*x+y*y+z*z+x*y+y*z+z*x;
     if(tot<=n) ans[tot]++;
     else break; 
    }
   }
  }
  
  rep(i,1,n+1) cout << ans[i] << endl;
  
  

}

int main(){
   cin.tie(nullptr);
  ios::sync_with_stdio(false);
  solve();
}

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

namespace Atcoder
{
    class Program
    //    ABC127 D - Integer Cards
    {
        private static void Main(string[] args)
        {
            var nm = Console.ReadLine().Split(' ');
            var n = int.Parse(nm[0]);
            var m = int.Parse(nm[1]);

            var a = Console.ReadLine().Split(' ').Select(x => int.Parse(x)).ToArray();
            Bc[] bcs = new Bc[n+m];

            for (var i = 0; i < n; i++)
            {
                bcs[i].b = 1;
                bcs[i].c = a[i];
            }

            //Array.Sort(a);


            for (var i = n; i < n+m; i++)
            {
                var bc = Console.ReadLine().Split(' ').Select(x => int.Parse(x)).ToArray();
                bcs[i].b = bc[0];
                bcs[i].c = bc[1];
            }
            bcs = bcs.OrderByDescending(x => x.c).ToArray();

            long ans = 0;

            var idx = 0;
            var asum = 0;
            do
            {
                var bsum = 0;
                do
                {
                    asum++;
                    bsum++;
                    ans += bcs[idx].c;
                    if (asum == n)
                    {
                        break;
                    }
                } while (bsum < bcs[idx].b);

                idx++;
            } while (asum < n);
            Console.WriteLine(ans);
        }

        public struct Bc
        {
            public int b;
            public int c;

            public Bc(int b, int c)
            {
                this.b = b;
                this.c = c;
            }
        }

    }
}



Measured memory_bytes: 34080
#include <bits/stdc++.h>
using namespace std;
#define rep(i,N) for(int i = 0; i < (N); i++)
#define repo(i,N) for(int i = 1; i < (N); i++)
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define all(x) (x).begin(),(x).end()
//#define num 1000000007
#define pi acos(-1.0)
//intの最大値2147483647 ≒ 2×10^9
//long longの最大値9223372036854775807 ≒ 9×10^18
//#define int long long


int main() {
  int a;
  cin >> a;
  
  cout << 800*a-(a/15)*200 << endl;
  
}


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

int bfs(vector<vector<char>> &g, queue<vector<int>> &que, int H, int W){
    // cout << "bfs " << endl;
    int ans_rt = 0;
    while(!que.empty()){
        int h = que.front()[0];
        int w = que.front()[1];
        int count = que.front()[2];
        // cout << h << " " << w << " " << count << " " << endl;
        
        ans_rt = max(ans_rt, count);
        que.pop();

        if(h>0 && g[h-1][w]=='.'){
            que.push(vector<int>{h-1, w, count+1});
            g[h-1][w]='#';
        }
        if(h<H-1 && g[h+1][w]=='.'){
            que.push(vector<int>{h+1, w, count+1});
            g[h+1][w]='#';
        }
        if(w>0 && g[h][w-1]=='.'){
            que.push(vector<int>{h, w-1, count+1});
            g[h][w-1]='#';
        }
        if(w<W-1 && g[h][w+1]=='.'){
            que.push(vector<int>{h, w+1, count+1});
            g[h][w+1]='#';
        }

    }
    return ans_rt;
}


int main(){
    int H, W; cin >> H >> W;
    vector<vector<char>> g(H, vector<char>(W));
    rep(i, H){
        rep(j, W){
            cin >> g[i][j];
        }
    }


    // BFS
    // 各点ごとに、最大距離を求める。
    int ans = 0;
    rep(i, H){
        rep(j, W){
            if(g[i][j] != '#'){
                vector<vector<char>> tmp_g = g;
                tmp_g[i][j] = '#';

                queue<vector<int>> que;
                que.push(vector<int>{i, j, 0});

                int tmp = bfs(tmp_g, que, H, W);
                ans = max(ans, tmp);
            }
        }
    }

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 256
main(){
  long a[200009],b[200009],n,x,m,i,A=0,c=0;
  scanf("%ld%ld%ld",&n,&x,&m);
  i=x;
  while(n){if(a[i]>0)break;n--;a[i]=c++;b[i]=A;A+=i;i=i*i%m;}
  if(n){A+=(A-b[i])*(n/(c-a[i]));n%=c-a[i];}
  while(n--){A+=i;i=i*i%m;}
  printf("%ld",A);
}

Measured memory_bytes: 3236
def BF(edges,n,s):
    inf=float("inf")
    d=[inf for i in range(n+1)]
    d[s]=0
    flag=False
    for i in range(n+1):
      for v,u,cost in edges:
        if d[v]!=inf and d[u]>d[v]+cost:
          d[u]=d[v]+cost
    ans1=d[-1]
    for i in range(n+1):
      for v,u,cost in edges:
        if d[v]!=inf and d[u]>d[v]+cost:
          d[u]=d[v]+cost
    ans2=d[-1]
    if ans2<ans1:
      return -1
    else:
      return max(-ans1,0)

n,m,p=map(int,input().split())
g=[]
for _ in range(m):
  a,b,c=map(int,input().split())
  g.append([a,b,-(c-p)])
ans=BF(g,n,1)
print(ans)

Measured memory_bytes: 52696
#include<bits/stdc++.h>
using namespace std;
string S;int n;
int main(){
	cin>>n>>S;int maxn=0,t=0;
	for(int i=0;i<S.size();i++){
		if(S[i]=='I')t++;else t--;
		maxn=max(maxn,t);
	}
	cout<<maxn<<endl;
	return 0;
}

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

typedef long long ll;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(),(x).end()
#define m0(x) memset(x,0,sizeof(x))

int main(){
  int a[4];
  rep(i,4){
    char b;
    cin >> b;
    a[i] = int(b);
  }
  sort(a,a+4);
  if(a[0] == a[1] && a[2] == a[3] && a[1] != a[2]){
    cout << "Yes" <<endl;
  }else{
    cout << "No" <<endl;
  }
}

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

using namespace std;
typedef long long ll;
typedef vector<ll> vl;
typedef vector<string> vs;
typedef pair<ll, ll> pair_t;
using Graph = vector<vector<ll>>;

#define FOR(i, a, b) for (ll i = (a); i < (b); i++)
#define REP(i, n) FOR(i, 0, n)
/***** define constant start *******/
const ll MOD = 1000000007;
const double PI = 3.1415926535897932;
const ll INF = 1 << 29;
/****** define constant end ********/
/****** define variable start ******/
long double a, b, c;
/******* define variable end *******/
ll solve()
{
    cin >> a >> b >> c;
    if (a + 2 * sqrt(a * b) + b < c)
    {
        cout << "Yes" << endl;
    }
    else
    {
        cout << "No" << endl;
    }
    return 0;
}
int main()
{
    //clock_t start = clock();
    cout << std::fixed << std::setprecision(10);
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    ll end_solve = solve();
    /*
    clock_t end = clock();
    const double time = static_cast<double>(end - start) / CLOCKS_PER_SEC * 1000.0;
    printf("time %lf[ms]\n", time);
    */

    return (int)end_solve;
}


Measured memory_bytes: 256
#pragma GCC target("avx2")
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")
#include <iostream>
using namespace std;
using ll = long long;
constexpr ll MOD = 998244353;
ll a[3030], dp[3][3030][3030];

int main() {
	int n, s;
	scanf("%d %d", &n, &s);
	for (int i = 0; i < n; ++i) scanf("%d", &a[i]);

	dp[0][0][0] = 1;
	for (int i = 0; i < n; ++i) {
		for (int j = 0; j <= s; ++j) {
			(dp[0][i + 1][j] += dp[0][i][j]) %= MOD;
			(dp[1][i + 1][j] += dp[0][i][j] + dp[1][i][j]) %= MOD;
			(dp[2][i + 1][j] += dp[0][i][j] + dp[1][i][j] + dp[2][i][j]) %= MOD;
			if (j + a[i] <= s) {
				(dp[1][i + 1][j + a[i]] += dp[0][i][j] + dp[1][i][j]) %= MOD;
				(dp[2][i + 1][j + a[i]] += dp[0][i][j] + dp[1][i][j]) %= MOD;
			}
		}
	}
	printf("%d", dp[2][n][s]);
	return 0;
}


Measured memory_bytes: 215296
def main():
    koma_num, point_num = list(map(int, input().split()))
    data = list(map(int, input().split()))
    data.sort()
    data_list = [[ele, ele] for ele in data]
    ans = 0

    haba = 0
    while len(data_list) > koma_num:
        haba += 1
        for i in range(len(data_list) - 1)[::-1]:
            if data_list[i+1][0] - data_list[i][1] == haba:
                data_list[i][1] = data_list[i+1][1]
                data_list.pop(i+1)
                ans += haba
                # print(ans, data_list)
            if len(data_list) == koma_num:
                break
    print(ans)



if __name__ == '__main__':
    main()

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

int main(){
    double R;
    cin >> R;

    double ans = 2.0 * 3.141592 * R;
    cout << fixed << setprecision(10);
    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 3788
#include <limits.h>
#include <math.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

#include <algorithm>
#include <cassert>
#include <cfloat>
#include <complex>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <regex>
#include <set>
#include <stack>
#include <string>
#include <unordered_map>
#include <vector>

using namespace std;

#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)
#define rep(i, n) for (ll i = 0; i < (n); ++i)
#define repLRE(i, l, r) for (ll i = (l); i <= (r); ++i)
#define Sort(v) sort(v.begin(), v.end())
#define Reverse(v) reverse(v.begin(), v.end())
#define Lower_bound(v, x) \
  distance(v.begin(), lower_bound(v.begin(), v.end(), x))
#define Upper_bound(v, x) \
  distance(v.begin(), upper_bound(v.begin(), v.end(), x))

using ll = long long;
using ull = unsigned long long;
using P = pair<ll, ll>;
using T = tuple<ll, ll, ll>;
using vll = vector<ll>;
using vP = vector<P>;
using vT = vector<T>;
using vvll = vector<vector<ll>>;
using vvP = vector<vector<P>>;
using dqll = deque<ll>;

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

/* Macros reg. ends here */

const ll INF = 1LL << 50;

int main() {
  ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
  cout << fixed << setprecision(15);

  ll s, w;
  cin >> s >> w;
  string ans = "safe";
  if (w >= s) ans = "unsafe";

  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 3652
#include<iostream>
#include<vector>
#include<map>
#include<set>
#include<string>
#include<utility>
#include<algorithm>
#include<cstdio>
#include<iomanip>
#include<queue>
#include<stack>

#define ll int64_t
#define Rep(i, n) for (ll i = 0; i < n; i++)

using namespace std;

ll GCD (ll a, ll b) {
    if (a < b) {
        swap(a, b);
    }

    ll r = a % b;
    while (r != 0) {
        a = b;
        b = r;
        r = a % b;
    }

    return b;
}

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

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

    ll N, K;
    cin >> N >> K;
    vector<ll> A(N);
    Rep (i, N) {
        cin >> A.at(i);
    }

    ll g = A[0];
    Rep (i, N-1) {
        g = GCD (g, A[i+1]);
    }

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

    if (K % g == 0 && K <= A[N-1]) {
        cout << "POSSIBLE" << "\n";
    } else {
        cout << "IMPOSSIBLE" << "\n";
    }

    return 0;
}

Measured memory_bytes: 1024
#include<bits/stdc++.h>
using namespace std;
#define ll long long
int main() {
  ll N;
  cin >> N;
  string A,B,C;
  cin >> A >> B >> C;
  ll ans=0;
  for (ll i = 0; i < N; ++i) {
  	ll op;
    if (A[i]==B[i] && B[i]==C[i]) op = 0;
    else if (A[i]==B[i] && B[i]!=C[i]) op = 1;
    else if (A[i]!=B[i] && B[i]==C[i]) op = 1;
    else if (A[i]!=B[i] && A[i]==C[i]) op = 1;
    else op = 2;
    ans += op;
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define y1 __zzd001
using namespace std;
typedef long long LL;
LL read(){
    LL x=0;
    char ch=getchar();
    while (!isdigit(ch))
        ch=getchar();
    while (isdigit(ch))
        x=(x<<1)+(x<<3)+(ch^48),ch=getchar();
    return x;
}
const int N=100005;
int n,sg[N];
vector <int> e[N];
void solve(int x,int pre){
    sg[x]=0;
    for (auto y : e[x])
        if (y!=pre){
            solve(y,x);
            sg[x]^=sg[y]+1;
        }
}
int main(){
    n=read();
    for (int i=1;i<n;i++){
        int x=read(),y=read();
        e[x].push_back(y);
        e[y].push_back(x);
    }
    solve(1,0);
    puts(sg[1]?"Alice":"Bob");
    return 0;
}

Measured memory_bytes: 12288