akhauriyash/Code-Regression huggingface dataset:
import sys

sys.setrecursionlimit(10 ** 6)
INF = float("inf")
MOD = 10 ** 9 + 7


def input():
    return sys.stdin.readline().strip()


def main():
    S = input()

    if S[:4] == "YAKI":
        print("Yes")
    else:
        print("No")


if __name__ == "__main__":
    main()


Measured memory_bytes: 2940
use std::io::Read;

fn main() {
    let mut buf = String::new();
    std::io::stdin().read_to_string(&mut buf).unwrap();

    let answer = solve(&buf);

    println!("{}", answer);
}

fn solve(input: &str) -> String {
    let mut iterator = input.split_whitespace();

    let n: usize = iterator.next().unwrap().parse().unwrap();
    let m: usize = iterator.next().unwrap().parse().unwrap();
    let d: usize = iterator.next().unwrap().parse().unwrap();

    if d == 0 {
        let ans = (m - 1) as f64 / n as f64;
        format!("{}", ans)
    } else {
        let ans = (2 * (n - d) * (m - 1)) as f64 / (n * n) as f64;
        format!("{}", ans)
    }
}


Measured memory_bytes: 2100
#include <bits/stdc++.h> 
 
using namespace std;
 
template<class T> inline string toString(T x) {ostringstream sout;sout<<x;return sout.str();}
 
 
//typedef
//------------------------------------------
typedef pair<int, int> PII;
typedef long long LL;
typedef pair<long, long> PLL;
 
//container util
//------------------------------------------
#define PB emplace_back
#define MP make_pair 
#define SZ(a) int((a).size())
//repetition
//------------------------------------------
#define FOR(i,a,b) for(LL i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)
#define SORT(c) sort((c).begin(),(c).end())
#define ALL(a)  (a).begin(),(a).end()
//constant
//--------------------------------------------
//clear memory
#define CLR(a) memset((a), 0 ,sizeof(a))
 
const double EPS=1e-10;

int main(){
    int T,X;
    cin>>T>>X;
    cout<<setprecision(10)<<(double)T/X<<endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const ll mod=1e9+7;

int main(){
    int A, B;
    cin >> A >> B;
    int tap=1, cnt=0;
    while(tap<B){
        tap--;
        tap+=A;
        cnt++;
    }
    cout << cnt;
}

Measured memory_bytes: 256
#include<stdio.h>
using namespace std;

void outPut(int H[3][10]) {
	for (int k = 0; k < 3; k++)
	{
		for (int h = 0; h < 10; h++)
		{
			printf(" %d", H[k][h]);
		}
		printf("\n");
	}

}

int main() {
	int H1[3][10] = { 0 }, H2[3][10] = { 0 }, H3[3][10] = { 0 }, H4[3][10] = { 0 };
	int n, b, f, r, v;
	scanf("%d", &n);
	for (int i = 0; i < n; i++)
	{
		scanf("%d %d %d %d", &b, &f, &r, &v);
		switch (b)
		{
		case 1:
			H1[f - 1][r - 1] += v;
			break;
		case 2:
			H2[f - 1][r - 1] += v;
			break;
		case 3:
			H3[f - 1][r - 1] += v;
			break;
		case 4:
			H4[f - 1][r - 1] += v;
			break;
		}
	}
		outPut(H1);
		printf("####################\n");
		outPut(H2);
		printf("####################\n");
		outPut(H3);
		printf("####################\n");
		outPut(H4);

	
}


Measured memory_bytes: 2756
bld=Array.new(4){Array.new(3){Array.new(10,0)}}

n=gets.to_i
for i in 1..n do
   mp=Array.new()
   mp=gets.split(' ').map(&:to_i)
   bld[mp[0]-1][mp[1]-1][mp[2]-1]+=mp[3]
end

bld.each_with_index{|b,i|
    b.each{|f|
      f.each{|r|
        printf(" %d",r)
      }
      printf("\n")
    }
    if(i<3) then
    printf("####################\n")
    end
}

Measured memory_bytes: 8764
#include <iostream>
#include <string>
#include <algorithm>
#include <cmath>
#include <vector>
#include <numeric>
#include <set>
#include <cstdlib>
#include <queue>

using namespace std;

typedef long long llint;
typedef long double ld;
#define inf 1e18
#define mod 1000000007
priority_queue<llint,vector<llint>,greater<llint>> que;
//priority_queue<llint> q;
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

int x,t;
void solve(){
  cin >> x >> t;
  if(x-t<0)cout << 0;
  else cout << x-t;
  cout << endl;
}

int main(int argc, char *argv[]) {
  solve();
  return 0;
}


Measured memory_bytes: 256
s = input()
t = input()

slen = len(s)
tlen = len(t)

s = " " + s
t = " " + t

dp = [ [0]*(tlen+1) for _ in range(slen+1) ]

for i in range(1,slen+1):
    for j in range(1,tlen+1):
        if s[i]==t[j]:
            dp[i][j] = dp[i-1][j-1] + 1
        else:
            dp[i][j] = max(dp[i-1][j],dp[i][j-1])

anslen = dp[slen][tlen]
i = slen
j = tlen
ans = []

while anslen>0:
    if s[i]==t[j]:
        ans.append(s[i])
        i -= 1
        j -= 1
        anslen -= 1
    else:
        if dp[i][j]==dp[i-1][j]:
            i -= 1
        else:
            j -= 1

ans = "".join(ans)
print(ans[::-1])

Measured memory_bytes: 112348
n = int(input())
a = list(map(int,input().split()))
y = sum(a) - a[0]
x = a[0]
ans = abs(x-y)
for i in range(1,n-1):
    x += a[i]
    y -= a[i]
    ans = min(ans,abs(x-y))
print(ans)

Measured memory_bytes: 30728
N,K = map(int,input().split())
A = [0]+list(map(int,input().split()))
visit = [-1]*(N+1)
point = 1
notloop_cnt = 0
while(visit[point]==-1):
    visit[point] = 1
    point = A[point]
    notloop_cnt += 1
s_point = point
loop_cnt = 0
visit = [-1]*(N+1)
while(visit[point]==-1):
    visit[point] = 1
    point = A[point]
    loop_cnt += 1
    
visit = [-1]*(N+1)
if(K<=notloop_cnt):
    point,cnt = 1,0
    while(cnt != K):
        point = A[point]
        cnt += 1
    print(point)
else:
    K = (K-notloop_cnt)%loop_cnt
    point = s_point
    cnt = 0
    while(cnt != K):
        point = A[point]
        cnt += 1
    print(point)

Measured memory_bytes: 32384
import sys
sys.setrecursionlimit(10**6)


def main(input, print):
    n = int(input())
    ans = ''
    n -= 1
    ans += chr(ord('a')+n % 26)
    now = n // 26
    while now > 0:
        now -= 1
        ans = chr(ord('a')+now % 26) + ans
        now = now//26
    print(ans)


if __name__ == '__main__':
    main(sys.stdin.readline, print)


Measured memory_bytes: 61856
#pragma GCC optimize("Ofast")
#include "bits/stdc++.h"
using namespace std;
using ll = long long;
using ull = unsigned long long;
#define PI 3.141592
#define MOD7 1000000007
#define LL_INF 9000000000000000000
#define LL_MINF -9000000000000000000
#define INT_INF 2000000000
#define INT_MINF -2000000000
#define all(a) (a).begin(), (a).end()
#define fi first
#define se second
const int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1};
const int dy[8] = {0, 1, 0, -1, 1, 1, -1, -1};


int main(){
    ull N;
    cin >> N;
    cout << (1 + N - 1) * (N - 1) / 2 << endl;
}

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

using namespace std;

#define int long long
#define FR first
#define SC second
#define all(v) (v).begin(), (v).end()
#define rall(v) (v).rbegin(), (v).rend()
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define reps(i, f, n) for(int i = (int)(f); i < (int)(n); i++)
#define each(a, b) for(auto& a : b)

typedef pair<int, string> P;

struct Chara
{
  string name;  
  int x;
  Chara(){}
  Chara(string name, int x):name(name), x(x){}
  bool operator < (const Chara& c) const {
    return x != c.x ? x > c.x : name < c.name;
  }
};

const int inf = 1LL << 55;
const int mod = 1e9 + 7;

int N, M, K, L;
set<string> favname;
vector<Chara> dic, fav, unf;

bool check(int k)
{
  if(unf.size() < K-k+1) return true;
  int l = 0;
  for(int i = 0; i < k; i++) {
    l += max(0LL, unf[K-k].x - fav[i].x + (fav[i].name > unf[K-k].name));
  }
  return l <= L;
}

signed main()
{
  cin.tie(0);
  ios_base::sync_with_stdio(0);
  cout << fixed << setprecision(12);

  while(cin >> N >> M >> K >> L, N) {
    dic.clear();
    for(int i = 0; i < N; i++) {
      string name; int x;          
      cin >> name >> x;
      dic.push_back(Chara(name, x));
    }
    favname.clear();
    for(int i = 0; i < M; i++) {
      string name; cin >> name;
      favname.insert(name);
    }
    fav.clear();
    unf.clear();
    for(auto a : dic) {
      if(favname.find(a.name) != favname.end()) fav.push_back(a);
      else unf.push_back(a);
    }
    sort(all(fav));
    sort(all(unf));
    int lb = 0, ub = min(M, K) + 1;
    while(lb + 1 < ub) {
      int mb = (lb + ub) / 2;
      if(check(mb)) lb = mb;
      else ub = mb;
    }
    cout << lb << endl;
  }
  
  return 0;
}

Measured memory_bytes: 26200
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  string str;
  cin >> str;
 
  if (str == "a" || str == "i" || str == "u" || str == "e" || str == "o"  ) {
    cout << "vowel"  << endl;
  }
  else{
    cout << "consonant" <<endl;
  }
}

Measured memory_bytes: 256
#include<iostream>
using namespace std;
int main()
{
  long N;
  cin >> N;
  long s=N*(N+1)/2;
  long qt=(N-N%3)/3;
  long qf=(N-N%5)/5;
  long qtf=(N-N%15)/15;
  long sumt, sumf,sumtf;
  sumt = 3*qt*(qt+1)/2;
  sumf = 5*qf*(qf+1)/2;
  sumtf = 15*qtf*(qtf+1)/2;
  cout << (s+sumtf-sumt-sumf) << endl;
  return 0;
}

Measured memory_bytes: 3636
import java.util.Arrays;
import java.util.Scanner;

public class Main {

	public static int calc(char[] arr, int x) {
		boolean[] mae=new boolean[26];
		boolean[] ato=new boolean[26];
		Arrays.fill(mae, false);
		Arrays.fill(ato, false);
		for(int i=0; i<arr.length; i++) {
			if (i<x) {
				mae[arr[i]-'a']=true;
			} else {
				ato[arr[i]-'a']=true;
			}
		}
		int count=0;
		for(int i=0; i<mae.length; i++) {
			if (mae[i]&&ato[i])
				count++;
		}
		return count;
	}
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		sc.nextLine();
		char[] arr = sc.nextLine().toCharArray();
		sc.close();

		int max=0;
		for(int i=1; i<arr.length-1; i++) {
			int tmp = calc(arr, i);
			if (tmp>max)
				max=tmp;
		}
		System.out.println(max);
	}
}


Measured memory_bytes: 21972
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <functional>
using namespace std;

int main() {
    int N, M;
    cin >> N >> M;
    int L, R;
    int l = 0;
    int r = N;
    for (int i = 0; i < M; ++i) {
        cin >> L >> R;
        l = max(l, L);
        r = min(r, R);
    }
    if (l > r) {
        printf("0\n");
    } else {
        printf("%d\n", r-l+1);
    }
    return 0;
}

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

#define IOS  ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define endl "\n"
#define int  long long

#define x first
#define y second

using pii = pair<int, int>;
using ld  = long double;

const int mxn = 1e5 + 5;
const int mod = 1e9 + 7;

int v[mxn], w[mxn];
int dp[105][mxn];

int32_t main()
{
    IOS
    int n, W;
    cin >> n >> W;
    for(int i = 0; i < n; i++)
        cin >> w[i] >> v[i];
    dp[0][0] = 0;
    dp[0][w[0]] = v[0];
    for(int i = 1; i < n; i++)
    {
        for(int j = 1; j <= W; j++)
        {
            dp[i][j] = dp[i - 1][j];
            if(j - w[i] >= 0) dp[i][j] = max(dp[i][j], v[i] + dp[i - 1][j - w[i]]);
        }
    }
    int ans = 0;
    for(int i = 0; i <= W; i++) ans = max(ans, dp[n - 1][i]);
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 80912
#include <iostream>
#include <iomanip>
#include <algorithm>
using namespace std;
#include <cstdio>
#include <tuple>
#include <string>
#include <vector> 
#include <set>
#include <string.h>
#include <map>
#include <cmath>
#include <deque>
using ll = long long;
using Graph = vector<vector<int>>;
#include <queue>
#include <stack>


#include <math.h>  /* M_PI */

int main(){

    double r;
    cin >> r;


    printf("%.15f\n", 2* r * M_PI);
}

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

int main() {
  int a, b, c;
  cin >> a >> b >> c;

  int ans=3;

  if(a==b){
    ans--;
  }
  if(b==c){
    ans--;
  }
  if(c==a){
    ans--;
  }

  if(ans==0){
    cout << 1 << endl;
  }
  else{
    cout << ans << endl;
}

return 0;  
}

Measured memory_bytes: 256
import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,copy,functools
import time,random

sys.setrecursionlimit(10**7)
inf = 10**20
eps = 1.0 / 10**10
mod = 10**9+7
mod2 = 998244353
dd = [(-1,0),(0,1),(1,0),(0,-1)]
ddn = [(-1,0),(-1,1),(0,1),(1,1),(1,0),(1,-1),(0,-1),(-1,-1)]

def LI(): return list(map(int, sys.stdin.readline().split()))
def LLI(): return [list(map(int, l.split())) for l in sys.stdin.readlines()]
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 pf(s): return print(s, flush=True)
def pe(s): return print(str(s), file=sys.stderr)
def JA(a, sep): return sep.join(map(str, a))
def JAA(a, s, t): return s.join(t.join(map(str, b)) for b in a)


def main():
    s = S()
    a = [int(c) for c in s]

    dp = [0, 1]
    for c in a:
        np = [dp[0] + c, dp[0] + c + 1]
        if np[0] > dp[1] + (10 - c):
            np[0] = dp[1] + (10 - c)
        if np[1] > dp[1] + (9 - c):
            np[1] = dp[1] + (9 - c)
        dp = np

    return dp[0]

print(main())





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

int main()
{
	long long n;
	cin >> n;
	int sq = sqrt(n);
	
	for (int i = sq; i >= 1; i--)
	{
		if (n%i==0)
		{
			cout << (i-1)+((n/i)-1) << "\n";
			return 0;
		}
	}
 } 

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
typedef vector<int> vec1;
typedef vector<string> vec2;
typedef vector<double> vec3;

int main() {

  int k;
  cin >> k;
  int a, b;
  cin >> a >> b;
  for(int i = 1; i < 10e6; i++) {
    int n = k * i;
    if(n >= a && n <= b) {
      cout << "OK" << endl;
      return 0;
    } else if(n > b) {
      cout << "NG" << endl;
      return 0;
    }
  }
}

Measured memory_bytes: 3636
using System;

class AOJ {
    static void Main(string[] args)
    {
        string[] s;

        while ((s = Console.ReadLine().Split(' ')) != null) {

        int H = int.Parse(s[0]);
        int W = int.Parse(s[1]);

        if (H == 0 && W == 0) break;

        string side = "";
        string mid = "";

        for (int i = 0; i < W; i++) {

            side += "#";

            if (i == 0 || i == W-1)
                mid += "#";

            else
                mid += ".";
        }

        for (int i = 0; i < H; i++) {

            if (i == 0 || i == H-1)
                Console.WriteLine(side);

            else
                Console.WriteLine(mid);
        }
        Console.WriteLine();
        }
    }
}

Measured memory_bytes: 8800
S = input()
T = input()
Slist = list(S)
Tlist = list(T)
Ulist = []
ans = len(T)
count = 0

for i in range(len(S)-len(T)+1):
    Ulist = Slist[i:len(T)+i:] 
    for j in range(len(T)):
        if(Tlist[j] == Ulist[j]):
            count += 1
    ans = min(ans,len(T)-count)
    count = 0

print(ans)

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

typedef long long int ll;

const ll mod = 1e9+7;

using namespace std;

int main(void){

    int n, m;

    cin >> n >> m;

    vector<int> a(n+1, true);

    for(int i = 0;i < m;i++){
        int x;
        cin >> x;
        a[x] = false;
    }

    vector<ll> dp(n+2);
    dp[n] = 1;
    dp[n-1] = 1;
    for(int i = n-1;i >= 0;i--){
        if(a[i]){
            dp[i] = dp[i+1] + dp[i+2];
            dp[i] %= mod;
        }else{
            dp[i] = 0;
        }
    }

    cout << dp[0] << endl;

    return 0;
}


Measured memory_bytes: 1408
using System;
using System.Linq;
using System.Collections.Generic;
using System.IO;
 
namespace ABC
{
  public class Program
  {
    public static void Main(string[] args)
    {
      Console.SetOut(new StreamWriter(Console.OpenStandardOutput()){AutoFlush = false});
      var nk = Console.ReadLine().Split().Select(int.Parse).ToArray();
      int n = nk[0];
      int k = nk[1];
      long ans = 0;
      ans = (long)Math.Pow(k-1, n-1) * k;
      Console.WriteLine(ans);
      Console.Out.Flush();
    }
  }
}


Measured memory_bytes: 2904
#include<iostream>
#include<cstdio>
#include<cstring>
#include<string>
#include<vector>
#include<cmath>
#include<algorithm>
#include<map>
#include<queue>
#include<deque>
#include<iomanip>
#include<tuple>
using namespace std;
typedef long long int LL;
typedef pair<int,int> P;
typedef pair<LL,int> LP;
const int INF=1<<30;
const LL MAX=1e9+7;

void array_show(int *array,int array_n,char middle=' '){
	for(int i=0;i<array_n;i++)printf("%d%c",array[i],(i!=array_n-1?middle:'\n'));
}
void array_show(LL *array,int array_n,char middle=' '){
	for(int i=0;i<array_n;i++)printf("%lld%c",array[i],(i!=array_n-1?middle:'\n'));
}
void array_show(vector<int> &vec_s,int vec_n=-1,char middle=' '){
	if(vec_n==-1)vec_n=vec_s.size();
	for(int i=0;i<vec_n;i++)printf("%d%c",vec_s[i],(i!=vec_n-1?middle:'\n'));
}
void array_show(vector<LL> &vec_s,int vec_n=-1,char middle=' '){
	if(vec_n==-1)vec_n=vec_s.size();
	for(int i=0;i<vec_n;i++)printf("%lld%c",vec_s[i],(i!=vec_n-1?middle:'\n'));
}

int main(){
	LL n,m;
	LL i,j,k;
	int a,b,c;
	bool flag=false;
	cin>>n;
	for(i=1;i<=9;i++){
		for(j=1;j<=9;j++){
			if(n==i*j)flag=true;
		}
	}
	if(flag)cout<<"Yes"<<endl;
	else cout<<"No"<<endl;
}

Measured memory_bytes: 256
#include <cstdio>

int N, M;
int edge[110][110];
int vis[1100];
int last[110];
int L[110];
int vv[110];
int G[110][110];
int Eu[1100];
int Ev[1100];

int H[100100];
int H2[100100];
int Hn=0;
void addHeap(int nd, int x)
{
	Hn ++;
	H[Hn] = x;
	H2[Hn] = nd;
	int i=Hn, j;
	while(i>1){
		j = i/2;
		if(H[j] > x){
			H[i] = H[j];
			H2[i] = H2[j];
			i = j;
		}
		else
			break;
	}
	H[i] = x;
	H2[i] = nd;
}

void delHeap(int &nd, int &x)
{
	int r = H[1];
	int rnd = H2[1];
	int tmp = H[Hn];
	int t2 = H2[Hn];
	Hn --;
	int i = 1, j;
	while(2*i<=Hn){
		j = 2*i;
		if(j+1<=Hn && H[j+1]<H[j])
			j ++;
		if(H[j] < tmp){
			H[i] = H[j];
			H2[i] = H2[j];
			i = j;
		}
		else
			break;
	}
	H[i] = tmp;
	H2[i] = t2;
	x = r;
	nd = rnd;
}

void calc(int s, int t)
{
	int i;
	Hn = 0;
	addHeap(s, 0);
	last[s] = -1;
	for(i=0; i<N; i++){
		vv[i] = 0;
		L[i] = 2000000;
	}
	while(Hn > 0){
		int nd, x;
		delHeap(nd, x);
		vv[nd] = 1;
		if(nd == t)
			break;
		int nd2, x2;
		for(i=0; i<N; i++){
			if(vv[i]==0 && edge[nd][i] > 0){
				nd2 = i;
				x2 = x + edge[nd][i];
				if(x2 < L[nd2]){
					L[nd2] = x2;
					addHeap(nd2, x2);
					last[nd2] = nd;
				}
			}
		}
	}
	int path[1100];
	int pL = 0;
	int v = t;
	while(v != s){
		int u = last[v];
		G[u][v] = G[v][u] = 1;
		v = u;
	}
}

void solve()
{
	int i, j;
	for(i=0; i<N; i++){
		for(j=i+1; j<N; j++){
			calc(i, j);
		}
	}
	int res = 0;
	for(i=0; i<M; i++){
		if(G[Eu[i]][Ev[i]] == 0)
			res ++;
	}
	printf("%d\n", res);
}

int main()
{
	//freopen("in.txt", "r", stdin);
	scanf("%d%d", &N, &M);
	int i;
	for(i=0; i<M; i++){
		int u, v, c;
		scanf("%d%d%d", &u, &v, &c);
		u --;
		v --;
		Eu[i] = u;
		Ev[i] = v;
		edge[u][v] = edge[v][u] = c;
	}
	solve();
	return 0;
}

Measured memory_bytes: 256
nl = lambda: list(map(int, input().split()))
sl = lambda: input().split()
n = lambda: int(input())
s = lambda: input()

N = n()
A = nl()

A = sorted(A, reverse=True)
alice = 0
bob = 0
for i in range(N):
    if i % 2 == 0:
        alice += A[i]
    else:
        bob += A[i]

print(alice - bob)


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

long long INF=1e18;

int main()
{
    long long n,m,l;
    cin>>n>>m>>l;
    long long mat[n+1][n+1],mat1[n+1][m+1];
    memset(mat,0,sizeof(mat));
    memset(mat1,0,sizeof(mat1));
    for(int i=0; i<m; i++)
    {
        long long a,b,c;
        cin>>a>>b>>c;
        mat[a][b]=c;
        mat[b][a]=c;
    }
    for(int i=1; i<=n; i++)
        for(int j=1; j<=n; j++)
            if(mat[i][j]==0) mat[i][j]=INF;
    for(int k=1; k<=n; k++)
        for(int i=1; i<=n; i++)
            for(int j=1; j<=n; j++)
                mat[i][j]=min(mat[i][j],mat[i][k]+mat[k][j]);
    for(int i=1; i<=n; i++)
        for(int j=1; j<=n; j++)
            if(mat[i][j]<=l) mat1[i][j]=1;
            else mat1[i][j]=INF;
  for(int i=1; i<=n; i++)
        for(int j=1; j<=n; j++)
            if(mat1[i][j]==0) mat1[i][j]=INF;
    for(int k=1; k<=n; k++)
        for(int i=1; i<=n; i++)
            for(int j=1; j<=n; j++)
                mat1[i][j]=min(mat1[i][j],mat1[i][k]+mat1[k][j]);
    long long q;
    cin>>q;
    while(q--)
    {
        long long a,b;
        cin>>a>>b;
        if(mat1[a][b]>=INF) cout<<-1<<endl;
        else cout<<mat1[a][b]-1<<endl;
    }
    return 0;
}


Measured memory_bytes: 106624
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <ctime>
#include <cctype>

#include <algorithm>
#include <random>
#include <bitset>
#include <queue>
#include <functional>
#include <set>
#include <map>
#include <vector>
#include <chrono>
#include <iostream>
#include <limits>
#include <numeric>

#define LOG(FMT...) fprintf(stderr, FMT)

using namespace std;

typedef long long ll;
typedef unsigned long long ull;

// mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

template <class T>
istream& operator>>(istream& is, vector<T>& v) {
  for (T& x : v)
    is >> x;
  return is;
}

template <class T>
ostream& operator<<(ostream& os, const vector<T>& v) {
  if (!v.empty()) {
    os << v.front();
    for (int i = 1; i < v.size(); ++i)
      os << ' ' << v[i];
  }
  return os;
}

int main() {
#ifdef LBT
  freopen("test.in", "r", stdin);
  int nol_cl = clock();
#endif
  ios::sync_with_stdio(false);
  cin.tie(nullptr);

  int N;
  cin >> N;
  vector<int> A(N);
  cin >> A;
  ll sum = accumulate(A.begin(), A.end(), 0LL), pre = 0;
  ll ans = numeric_limits<ll>::max();
  for (int i = 0; i < N - 1; ++i) {
    pre += A[i];
    ans = min(ans, abs(sum - pre * 2));
  }
  cout << ans;

#ifdef LBT
  LOG("Time: %dms\n", int ((clock()
          -nol_cl) / (double)CLOCKS_PER_SEC * 1000));
#endif
  return 0;
}


Measured memory_bytes: 1024
#include <stdio.h>
int main(){
	char a[100];
	int n;
	scanf("%s",&a);
	for (int i = 0; i < 4; ++i)
	{
		if(a[i]=='+'){
			n=n+1;
		}else if (a[i]=='-')
		{
			n=n-1;
		}
	}
	printf("%d\n",n);
}

Measured memory_bytes: 128
import sys

sys.setrecursionlimit(10 ** 8)

input = sys.stdin.readline


def main():
    N = int(input())

    for h in range(1, 3501):
        for n in range(1, 3501):
            if 4 * n * h - N * n - N * h == 0:
                continue
            q, r = divmod(N * n * h, 4 * n * h - N * n - N * h)
            if r == 0 and q > 0:
                print(h, n, q)
                return


if __name__ == '__main__':
    main()


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

#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))
#define deg_to_rad(deg) (((deg) / 360) * 2 * M_PI)
#define rad_to_deg(rad) (((rad) / 2 / M_PI) * 360)

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep1(i, n) for (int i = 1; i < (int)(n); i++)

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

typedef long long ll;


void solve(long long S, long long W){
    if(W>=S){
        cout << "unsafe"<<endl;
    }
    else{
        cout << "safe"<<endl;
    }
}

int main(){
    long long S;
    scanf("%lld",&S);
    long long W;
    scanf("%lld",&W);
    solve(S, W);
    return 0;
}


Measured memory_bytes: 3688
#include <stdio.h>

#include <algorithm>
#include <bitset>
#include <cassert>
#include <cmath>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <string>
#include <vector>

// Acknowledgement: Special thanks to kyomukyomupurin, who developed this
// template.
template <class T, class U>
std::ostream& operator<<(std::ostream& os, const std::pair<T, U>& p) {
  return os << '(' << p.first << ", " << p.second << ')';
}

template <class T>
std::ostream& operator<<(std::ostream& os, const std::vector<T>& vec) {
  int n = 0;
  for (auto e : vec) os << (n++ ? ", " : "{") << e;
  return os << (n ? "}" : "{}");
}

template <class T>
std::ostream& operator<<(std::ostream& os, const std::set<T>& st) {
  int n = 0;
  for (auto e : st) os << (n++ ? ", " : "{") << e;
  return os << (n ? "}" : "{}");
}

template <class T, class U>
std::ostream& operator<<(std::ostream& os, const std::map<T, U>& mp) {
  int n = 0;
  for (auto e : mp) os << (n++ ? ", " : "{") << e;
  return os << (n ? "}" : "{}");
}

template <class T>
std::istream& operator>>(std::istream& is, std::vector<T>& vec) {
  for (T& e : vec) is >> e;
  return is;
}

#ifdef LOCAL
#define debug(...) \
  std::cerr << "[" << #__VA_ARGS__ << "]: ", debug_out(__VA_ARGS__)
#else
#define debug(...)
#endif

void debug_out() { std::cerr << '\n'; }

template <class Head, class... Tail>
void debug_out(Head&& head, Tail&&... tail) {
  std::cerr << head;
  if (sizeof...(Tail) != 0) std::cerr << ", ";
  debug_out(std::forward<Tail>(tail)...);
}
using namespace std;
using int64 = long long;

int main() {
  int N;
  cin >> N;
  vector<pair<string, int>> vp;
  vp.push_back(make_pair("0", 0));
  int cnt = 1;
  while (cnt != N) {
    vector<pair<string, int>> vp_new;
    for (auto p : vp) {
      for (int i = 0; i < p.second + 2; i++) {
        vp_new.push_back(make_pair(p.first + to_string(i), max(i, p.second)));
      }
    }
    vp = vp_new;
    cnt++;
  }
  debug(vp);
  for (auto p : vp) {
    for (auto c : p.first) {
      int idx = c - '0';
      printf("%c", 'a' + idx);
    }
    cout << endl;
  }
  return 0;
}

Measured memory_bytes: 13172
#include <iostream>
#include <map>
#include <set>
#include <algorithm>
#include <vector>
#include <sstream>
#include <string>
#include <functional>
#include <queue>
#include <deque>
#include <stack>
#include <limits>
#include <unordered_map>
#include <unordered_set>
#include <math.h>
#include <fstream>
#include <iterator>
#include <random>
#include <chrono>


#define forr(i,start,count) for (int i = (start); i < (start)+(count); ++i)
#define set_map_includes(set, elt) (set.find((elt)) != set.end())
#define readint(i) int i; cin >> i
#define readll(i) ll i; cin >> i
#define readdouble(i) double i; cin >> i
#define readstring(s) string s; cin >> s

typedef long long ll;

using namespace std;

int main()   {
    cout.precision(17);
    ll modd = 1000 * 1000 * 1000 + 7;
    mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
    uniform_int_distribution<int> rand_gen(0, modd);   // rand_gen(rng) gets the rand no
    ll infinit = 10000000000000000;

//    readint(test_cases);
    int test_cases = 1;
    forr(t, 1, test_cases) {
        readint(h1); readint(m1); readint(h2); readint(m2); readint(k);
        int wake_up = h1*60+m1;
        int go_to_sleep = h2*60+m2;
        int time_awake = go_to_sleep - wake_up;

        cout << (time_awake-k) << endl;
    }
    return 0;
}


Measured memory_bytes: 3624
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
using namespace std;

// https://beta.atcoder.jp/contests/abc113/tasks/abc113_c

struct city {
	int input_order;
	int P;
	int Y;
	string id_first;
	string id_second;
};

bool compare_P(const city& x, const city& y);
bool compare_Y(const city& x, const city& y);
bool compare_input_order(const city& x, const city& y);

string to_string_6(int number);

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

	vector<city> cities;
	for (int i = 0; i < M; ++i) {
		city instance;
		instance.input_order = i;
		cin >> instance.P >> instance.Y;
		cities.push_back(instance);
	}

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

	vector<city>::iterator it_begin, it_end;
	it_begin = cities.begin();
	it_end = cities.begin();
	do {
		++it_end;

		if ((it_end == cities.end()) || (it_begin->P != it_end->P)) {
			sort(it_begin, it_end, compare_Y);

			vector<city>::iterator it;
			for (it = it_begin; it != it_end; ++it) {
				it->id_first = to_string_6(it->P);
				it->id_second = to_string_6(distance(it_begin, it) + 1);
			}

			it_begin = it_end;
		}
	} while (it_end != cities.end());
		
	sort(cities.begin(), cities.end(), compare_input_order);

	for (int i = 0; i < cities.size(); ++i)
		cout << cities[i].id_first << cities[i].id_second << endl;

	return 0;
}


bool compare_P(const city& x, const city& y)
{
	return x.P < y.P;
}

bool compare_Y(const city& x, const city& y)
{
	return x.Y < y.Y;
}

bool compare_input_order(const city& x, const city& y)
{
	return x.input_order < y.input_order;
}

string to_string_6(int number) {
	string ret;
	int tmp = number, cnt = 0;

	if (number == 0)
		return "00000000";

	while (tmp > 0) {
		tmp = tmp / 10;
		++cnt;
	}

	ret = string(6 - cnt, '0');
	ret.append(to_string(number));

	return ret;
}

Measured memory_bytes: 14828
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef vector<ll> vl;
typedef vector<vector<ll>> vvl;
typedef vector<pair<ll,ll>> vp;
#define rep(i,n) for(ll i = 0; i < ll(n); i++)
#define reep(i,n) for(ll i = n; i >-1; i--)
#define deb(variable) cout<<#variable<<"="<<variable<<endl
#define MMOD(i) ((i%MOD)+MOD)%MOD;
#define vec(i,j) vector<vector<ll>>(i,vector<ll>(j,0))
const ll INF=99999999999999999;
const ll MOD=128;
const ll MAX_N=500010;
ll a,b,c,d,e,x,y,z,k,m,n,l,q,ans=0;
vl v1,v2,v(200100,0),kaijo,gysku;
vector<pair<pair<string,ll>,ll>> p;
string s;
ll solve(void){
    return ((a*3)+b)/2;
 
}
int main(){
    cin>>n;
    rep(i,n){
        cin>>s>>a;
        p.push_back(make_pair(make_pair(s,-a),i+1));
    }
 
    sort(p.begin(),p.end());
    rep(i,n){
        cout<<p[i].second<<endl;
    }
 
}

Measured memory_bytes: 1792
#include <bits/stdc++.h>
#define rep(i, a, n) for(int i = a; i < n; i++)
#define repb(i, a, b) for(int i = a; i >= b; i--)
#define all(a) a.begin(), a.end()
#define o(a) cout << a << endl
#define int long long
using namespace std;
typedef pair<int, int> P;

struct BIT{
    int n;
    vector<int>dat;
    BIT(){}
    BIT(int _n){
        n = _n;
        dat.resize(n + 1);
    }
    void add(int k,int x){
        for(k++; k <= n; k += k & -k) dat[k] += x;
    }
    int sum(int k){
        int ret=0;
        for(k++; k; k -= k & -k) ret += dat[k];
        return ret;
    }
};

int n, m;
vector<int> ls[100010];

signed main(){
    cin >> n >> m;
    rep(i, 0, n){
        int l, r;
        cin >> l >> r;
        r++;
        ls[r - l]. push_back(l);
    }
    BIT bit(m + 10);
    int now = n;
    rep(i, 1, m + 1){
        rep(j, 0, ls[i].size()){
            int r = ls[i][j] + i;
            bit.add(ls[i][j], 1);
            bit.add(r, -1);
        }
        now -= ls[i].size();
        int ans = now;
        for(int j = i; j <= m; j += i) ans += bit.sum(j);
        cout << ans << endl;
    }

}

Measured memory_bytes: 8320
#include<iostream>
using namespace std;
int main(){
  string S;
  cin>>S;
  int C_count=0;
  for(int i=0;i<S.length();i++){
    if(i==0&&S[i]!='A'){
      cout<<"WA"<<endl;
      return 0;
    }
    if(2<=i&&i<S.length()-1&&S[i]=='C'){
      C_count++;
      if(C_count>1){
        cout<<"WA"<<endl;
        return 0;
      }
    }
    if(S[i]!='A'&&S[i]!='C'){
      if('A'<=S[i]&&S[i]<='Z'){
        cout<<"WA"<<endl;
        return 0;
      }
    }
  }
  if(C_count==0){
    cout<<"WA"<<endl;
  }else{
    cout<<"AC"<<endl;
  }
  return 0;
}


Measured memory_bytes: 256
N = int(input())
P = list(map(int,input().split()))
P_sort = sorted(P)
counter = 0
for p,p_sort in zip(P,P_sort):
    if p != p_sort:
        counter += 1
if counter == 2 or counter == 0:
    print('YES')
else:
    print('NO')

Measured memory_bytes: 9120
N=int(input())
a=[0]*N
b=[0]*N
c=[0]*N
hpa=[0]*N
hpb=[0]*N
hpc=[0]*N
hp=[0]*N

for i in range(N):
    a[i],b[i],c[i]=map(int,input().split())

hpa[0]=a[0]
hpb[0]=b[0]
hpc[0]=c[0]
hp[0]=max(hpa[0],hpb[0],hpc[0])

for i in range(N-1):
    hpa[i+1]=max(hpb[i]+a[i+1],hpc[i]+a[i+1])
    hpb[i+1]=max(hpa[i]+b[i+1],hpc[i]+b[i+1])
    hpc[i+1]=max(hpa[i]+c[i+1],hpb[i]+c[i+1])
    hp[i+1]=max(hpa[i+1],hpb[i+1],hpc[i+1])

print(hp[-1])

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

int main(){
  int a,b,c,d;
  cin>>a>>b>>c>>d;
  while(a>0 && c>0){
      c-=b;
      if(c<=0){
          cout<<"Yes";return 0;}
      a-=d;
      if(a<=0){
          cout<<"No";return 0;}
  }
  return 0;
}

Measured memory_bytes: 3620
#include<iostream>
using namespace std;
int main()
{
  bool ok=true;
    char a[6];
    for(int i=0;i<6;i++)
    cin>>a[i];
    for(int i=0;i<6;i++){
        if(a[i]!=a[5-i])
            ok=false;
    }
    if(ok)
        printf("YES");
    else
        printf("NO");
    
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int N, A;
  cin >> N;
  cin >> A;
  int numof500 = N / 500;
  int a = N - numof500 * 500;
  if(a > A){
  	cout << "No" << endl;
  }else{
  	cout << "Yes" << endl;
  }
}

Measured memory_bytes: 256
n = gets.to_i
h = gets.chomp.split
n.times do |i|
    h[i] = h[i].to_i
end

counts = []
i = 0
while i < n
    now_height = h[i]
    j = i + 1
    count = 0
    while j < n
        if now_height >= h[j]
            count += 1
            now_height = h[j]
            i += 1
            j += 1
        else
            break
        end
    end
    counts << count
    i += 1
end

puts counts.max

Measured memory_bytes: 9100
//
//  0558.cpp
//  
//
//  Created by Yoshida Satoshi on 2017/11/16.
//
//

#include <iostream>
#include <queue>
#include <utility>
#include <algorithm>
#include <stdlib.h>

#define MAX 1000
#define INF 100000000
#define FOR(index,max) for(int index=0;index<max;index++)

using namespace std;

typedef pair<int, int> P;

int ctoi(char c){
    switch(c){
        case '0': return 0;
        case '1': return 1;
        case '2': return 2;
        case '3': return 3;
        case '4': return 4;
        case '5': return 5;
        case '6': return 6;
        case '7': return 7;
        case '8': return 8;
        case '9': return 9;
        default : return -1;
    }
}

int main(){
    int dx[4]={1,-1,0,0};
    int dy[4]={0,0,1,-1};
    
    int nx,ny;
    
    queue<P> que;
    int H,W,N;
    int state[MAX][MAX];//0:????????°or????????? -1:????????¶???
    int d[MAX][MAX];
    int ans=0;
    int sx[10];
    int sy[10];
    P p;
    char in;
    cin>>H>>W>>N;
    FOR(i,H){
        FOR(j,W){
            cin>>in;
            if(in=='S'){
                sx[0]=i;
                sy[0]=j;
                state[i][j]=0;
            }
            else if(in=='X') state[i][j]=-1;
            else if(in=='.') state[i][j]=0;
            else{
                state[i][j]=0;
                sx[ctoi(in)]=i;
                sy[ctoi(in)]=j;
                
            }
        }
    }
    
    FOR(k,N){
        FOR(i,H){
            FOR(j,W){
                d[i][j]=INF;
            }
        }
        que.push(P(sx[k],sy[k]));
        d[sx[k]][sy[k]]=0;
        while(que.size()){
            p=que.front();
            que.pop();
            
            if(p==P(sx[k+1],sy[k+1]))   break;
            
            FOR(l,4){
                nx=p.first+dx[l];
                ny=p.second+dy[l];
                
                if(!(nx<0||ny<0||nx>H-1||ny>W-1||state[nx][ny]==-1||d[nx][ny]!=INF)){
                    que.push(P(nx,ny));
                    d[nx][ny]=d[p.first][p.second]+1;
                }
            }
        }
        
        ans += d[sx[k+1]][sy[k+1]];
        queue<P> empty;
        swap(empty,que);
    }
    
    cout<<ans<<endl;
    
    return 0;
}

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

int main() {
  int ans;
  vector<int> num(3);
  cin >>num.at(0) >>num.at(1) >>num.at(2);
  sort(num.begin(), num.end());
  
  ans = num.at(0) + num.at(1) + num.at(2) * 10;
  cout <<ans <<endl;
  
  return 0;
}


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

using namespace std;
using ll = long long;

int main() {
    int N;
    cin >> N;
    vector<ll> A(N), B(N);
    vector<pair<ll, int>> S(N);
    for(int i = 0; i < N; i++) {
        cin >> A[i] >> B[i];
        S[i].first = A[i] + B[i];
        S[i].second = i;
    }

    sort(S.begin(), S.end(), greater<pair<ll, int>>());

    bool takahashi = true;
    ll res = 0;
    for(auto s: S) {
        if(takahashi) {
            res += A[s.second];
        } else {
            res -= B[s.second];
        }
        takahashi = !takahashi;
    }
    cout << res << endl;
}

Measured memory_bytes: 6388
module vector_int32_mod
    use,intrinsic :: iso_fortran_env
    type vector
        integer(int64),allocatable:: array(:)
        integer(int64):: l
    contains
        procedure :: push_back => vector_regist
    end type

    interface vector
        module procedure vector_init
    end interface
    private
    public:: vector
contains
    function vector_init() result(vec)
        type(vector):: vec
        allocate(vec%array(1))
        vec%l = 0
    end function

    subroutine vector_regist(vec, v)
        class(vector):: vec
        integer(int64):: v

        if (vec%l+1 > size(vec%array)) call add_(vec)
        vec%l=vec%l+1
        vec%array(vec%l) = v
    end subroutine


    subroutine add_(vec)
        type(vector):: vec
        integer(int64),allocatable:: tmp(:)
        integer(int64):: l

        l = size(vec%array)
        allocate(tmp(l))
        tmp(:) = vec%array(:)
        deallocate(vec%array)
        allocate(vec%array(l*2))
        vec%array(1:l) = tmp(:)
        deallocate(tmp)
    end subroutine
end module

program main
    use,intrinsic :: iso_fortran_env
    use vector_int32_mod
    implicit none
    integer(int64):: n,q,k,i
    integer(int64), allocatable:: a(:), b(:), c(:), x(:), y(:)
    integer(int64), allocatable:: k_dist(:)
    type(vector), allocatable:: to(:), d(:)
    
    read*, n
    allocate(a(n-1), b(n-1), c(n-1))
    allocate(to(n), d(n))
    allocate(k_dist(0:n))

    do i=1,n
        to(i) = vector()
        d(i) = vector()
    end do
    
    do i=1,n-1
        read*, a(i), b(i), c(i)
        call to(a(i))%push_back(b(i))
        call to(b(i))%push_back(a(i))
        call d(a(i))%push_back(c(i))
        call d(b(i))%push_back(c(i))
    end do

    read*, q,k
    allocate(x(q), y(q))
    k_dist(0)=0_8
    call dfs(k,0_8,0_8)

    do i=1,q
        read*, x(i), y(i)
    end do

    do i=1,q
        print'(i0)', k_dist(x(i)) + k_dist(y(i))
    end do
contains
    recursive subroutine dfs(self, from, distance)
        integer(int64):: self, from, distance
        integer(int64):: i, next, next_d

        k_dist(self) = k_dist(from)+distance

        do i=1,to(self)%l
            next = to(self)%array(i)
            next_d = d(self)%array(i)
            if (next == from) cycle
            call dfs(next, self,next_d)
        end do
    end subroutine
end program main

Measured memory_bytes: 35700
N = int(input())
W = input()
S = set([W])
e = W[-1]
for _ in range(N-1):
    W = input()
    if W[0] == e and not W in S:
        e = W[-1]
        S.add(W)
    else:
        print("No")
        break
else:
    print("Yes")


Measured memory_bytes: 3060
# ABC061c
from collections import deque
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10**6)

n, k = map(int, input().split())
nums = [list(map(int, input().split())) for _ in range(n)]
nums.sort()
i = 0
for a, b in nums:
    i += b
    if i >= k:
        print(a)
        exit(0)


Measured memory_bytes: 57864
#define _USE_MATH_DEFINES
#include <iostream>
#include <algorithm>
#include <queue>
#include <stack>
#include <deque>
#include <climits>
#include <string>
#include <vector>
#include <set>
#include <map>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
//#include <tuple>

#define break break
#define continue continue
#define INF INT_MAX>>1 
#define SIZE 100010
#define MOD 1000000007
#define rep(i, n) for(int i=0; i<(int)(n); i++)
#define rep2(i, from, to) for(int i=(from); i<(int)(to); i++)
#define ALL(obj) (obj).begin(), (obj).end()
#define LLPair pair<ll, ll>
#define vint vector<int>
#define vll vector<ll>
typedef long long ll;

using namespace std;


ll gcd(ll a, ll b){ return a % b == 0 ? b : gcd(b, a%b); }
ll lcm(ll a, ll b){ return a * b/ gcd(a, b); }
ll extgcd(ll a, ll b, ll& x, ll& y){
	ll d = a;
	if(b != 0){
		d = extgcd(b, a%b, y, x);
		y -= (a/b) * x;
	} else{
		x = 1; y = 0;
	}
	return d;
}

int main(void){
	int a, b; cin >> a >> b;
	cout << lcm(a, b);
	return 0;
}

Measured memory_bytes: 256
n1 = int(input())
A = list(map(int, input().split()))
n2 = int(input())
q = list(map(int, input().split()))

B = []
C = []
n = n1
ans = list("no" for i in range(n2))

for i in range(2 ** n):
    C0 = []
    B = list(map(int, format(i, "b").zfill(n)))[::-1]
    C0 = [ x*y for x, y in zip(A, B)]
    C.append(sum(C0))

for j, r in enumerate(q):    
    if  r in C:
        ans[j] = "yes"

print(*ans, sep="\n")

Measured memory_bytes: 44924
N = int(input())
d_list = list(map(int,input().split()))

dist = [0] * 10**5
max_d = 0
for d in d_list:
    dist[d] += 1
    max_d = max(max_d, d)

MOD = 998244353
if d_list[0] != 0:
    print(0)
    exit()
elif dist[0]>1:
    print(0)
    exit()

ans = 1
for i in range(max_d):
    if dist[i] == 0 or dist[i+1] ==0:
        print(0)
        exit()
    ans *= (dist[i]**dist[i+1])
    ans %= MOD

print(ans)

Measured memory_bytes: 53428
#include <cstdio>
#include <iostream>
#include <algorithm>
#include <cstring>
#include <bitset>
#include <queue>
using namespace std;
const int Q=2000;
bitset<Q> apr[Q][Q],link[Q],ret,all,si[Q];
int las[Q],e[Q<<1],nn[Q<<1],inc;
void ins(int x,int y)
{
	e[++inc]=y;
	nn[inc]=las[x];
	las[x]=inc;
}
struct dt{
	int x,y;
	void R()
	{scanf("%d%d",&x,&y);--x,--y;link[x][y]=link[y][x]=1;}
};
queue<dt> q;
int fa[Q];
int sec;
void dfs(int x,int last,int rig)
{
	if(last==rig)sec=x;
	for(int t=las[x];t;t=nn[t]){
		int y=e[t];
		if(y==last)continue;
		apr[rig][y]=apr[rig][x],apr[rig][y][y]=1;
		dfs(y,x,rig);
	}
	if(x==rig)return;
	if(last==fa[x])apr[rig][x]|=si[x];
	else apr[rig][x]|=(all^si[last]);
	if(sec==fa[rig])apr[rig][x]|=si[rig];
	else apr[rig][x]|=(all^si[sec]);
}
void ddfs(int x,int last)
{
	fa[x]=last;
	si[x][x]=1;
	for(int t=las[x];t;t=nn[t]){
		int y=e[t];
		if(y==last)continue;
		ddfs(y,x);
		si[x]|=si[y];
	}
}
int main()
{
	int n,m;
	scanf("%d%d",&n,&m);
	for(int i=0;i<n;i++)
		all[i]=1,link[i][i]=1;
	for(int i=1,x,y;i<n;i++){
		scanf("%d%d",&x,&y);
		--x,--y;
		ins(x,y),ins(y,x);
		
	}
	ddfs(0,-1);
	for(int i=0;i<n;i++){
		apr[i][i][i]=1;
		dfs(i,-1,i);
	}
	for(int i=1;i<=m;i++){
		dt now;
		now.R();
		q.push(now);
	}
	while(q.size()){
		dt now=q.front();
		q.pop();
		int x=now.x,y=now.y;
		if(x>y)swap(x,y);
		ret=apr[x][y]&(link[x]^link[y]);
		for(int p=ret._Find_first();p!=Q;p=ret._Find_next(p)){
			if(link[x][p])q.push((dt){p,y}),link[p][y]=link[y][p]=1,++m;
			else q.push((dt){p,x}),link[p][x]=link[x][p]=1,++m;
		}
	}
	printf("%d",m);
	return 0;
} 

Measured memory_bytes: 1018292
//  Created by conan1024hao in 2019.
//  Copyright © 2019 conan1024hao. All rights reserved.
//  専用ライブラリです、自由にコピーして構いません。
//  感谢看我的代码！Wechat:conan1024hao QQ:810396815
#pragma GCC optimize ("O3")
#include <iostream>
#include <iomanip>
#include <istream>
#include <ostream>
#include <sstream>
#include <iterator>
#include <vector>
#include <algorithm>
#include <queue>
#include <deque>
#include <list>
#include <stack>
#include <map>
#include <set>
#include <utility>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <string>
#include <ctime>
#include <cctype>
#include <cstdlib>
#define INF 10e16
#define MOD 1000000007
#define  mod 998244353
#define rep(i, a, n) for (ll i = a; i < (ll)(n); i++)
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define eb emplace_back
#define mmax(x,y)(x>y?x:y)
#define mmin(x,y)(x<y?x:y)
#define chmax(x,y) x=mmax(x,y)
#define chmin(x,y) x=mmin(x,y)
#define all(x) (x).begin(),(x).end()
#define siz(x) (ll)(x).size()
#define PI acos(-1.0)
using namespace std;
//using Int=int_fast64_t;
typedef long long int ll;
typedef pair<ll,ll>Pll;
typedef pair<int,int>Pin;
long long GCD(long long a, long long b) { return b ? GCD(b, a%b) : a; }
long long LCM(long long a, long long b)  {return a/GCD(a,b)*b;}
int dx[8]={-1,0,1,0};
int dy[8]={0,-1,0,1};
char dir[4]={'u','l','d','r'};
ll cmp1(pair<ll,string>a,pair<ll,string> b){
        if(a.fi!=b.fi)
        return a.fi<b.fi;
        else
        return a.se<b.se;
}
//--------------------------------------------------------------------------

//---------------------------------------------------------------------------
int main(){//問題をちゃんと見ろ!!!!!!!!!!!!!!!!!      llか??????????        memset()!!!!!!!!!!!!       ペナを減らせ!!!!!!!!!!!!!
    cin.tie(0);
    ios::sync_with_stdio(false);
    //-------------------------------
    string s;cin>>s;
    cout<<2018;
    for(int i=4;i<s.length();i++)
        cout<<s[i];
    
    //-------------------------------
    return 0;
}
//---------------------------------------------------------------------------






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

int main(void){
int n,a[105];
scanf("%d",&n);
for(int count=0;count<n;count++){
  scanf("%d",&a[count]);
}

for(int count=0;count<n;count++){
  if(a[count]%2==0){
    if(a[count]%3!=0&&a[count]%5!=0){printf("DENIED");return 0;}
  }
}
printf("APPROVED");
}



Measured memory_bytes: 128
#include <iostream>
#include <stdio.h>
using namespace std;
int main(){
    int fst = 0;
    int snd = 0;
    int thd = 0;
    int tmp=0;
    std::cin >> fst;
    for(int i=0;i<9;i++) {
        tmp = 0;
        std::cin >> tmp;
        if(fst < tmp) {
            thd = snd;
            snd = fst;
            fst = tmp;
        }else if(tmp > snd){
            thd = snd;
            snd = tmp;
        }else if(tmp > thd){
            thd = tmp;
        }else{}
    }
    printf("%d\n%d\n%d\n",fst,snd,thd);
}

Measured memory_bytes: 1144
#include <iostream>
#include <vector>
#include <map>
#include <algorithm>
#include <string>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
using namespace std;

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

    if (input[0] == 'R') {
        if (input[1] == 'R') {
            if (input[2] == 'R') {
                // RRR
                cout << "3";
            }
            else {
                // RRS
                cout << "2";
            }
        }
        else {
            // RSR or RSS
            cout << "1";
        }

    } else if (input[1] == 'R') {
        if (input[2] == 'R') {
            // SRR
            cout << "2";
        } else {
            // SRS
            cout << "1";
        }
    }
    else if (input[2] == 'R') {
            // SSR
            cout << "1";
        }
        else {
            // SSS
            cout << "0";
        }
}


Measured memory_bytes: 3132
#include "bits/stdc++.h"
#define rep(i,n) for(int i=0;i<n;i++)
#define ALL(v) (v).begin(),(v).end()
typedef long long LL;
const int INF = 1 << 25;
const LL MOD = 1000000007LL;
using namespace std;
int main() {
	string S;
	cin >> S;
	for (int i = 0; i + 1 < S.size(); i++) {
		if (S.substr(i, 2) == "AC") {
			cout << "Yes" << endl;
			return 0;
		}
	}
	cout << "No" << endl;
}

Measured memory_bytes: 764
n = int(input())
a = list(map(int, input().split()))

a.sort()

ans = (0,0)
import bisect
i = n-2
j = bisect.bisect_left(a, a[n-1]//2)
if j < n-1: i = j
if j > 0:
    if (a[n-1] - 2*a[j-1]) < (2*a[j] - a[n-1]): i = j-1

print('{} {}'.format(a[n-1], a[i]))

Measured memory_bytes: 62704
N=int(input())
arr=[[-1 for j in range(2)] for i in range(N)]
for i in range(N):
	arr[i][0],arr[i][1]=map(int,input().split())
cnt=0
for i in range(N-2):
	if arr[i][0]==arr[i][1] and arr[i+1][0]==arr[i+1][1] and arr[i+2][0]==arr[i+2][1]:
		cnt+=1
if cnt>0:
	print("Yes")
else:
	print("No")

Measured memory_bytes: 62640
#include <bits/stdc++.h>
using namespace std;
#define INF 1000000005
typedef long long ll;
typedef pair <ll, ll> P;

int main() {
	ll h,w,cx,cy,dx,dy;
	cin >> h >> w >> cx >> cy >> dx >> dy;
	cx--;
	cy--;
	dx--;
	dy--;
	string s[h];
	for(ll i = 0; i < h; i++) cin >> s[i];
	deque <P> que;

	que.push_back(P(cx, cy));
	bool visited[h][w];
	ll d[h][w];
	for(ll i = 0; i < h; i++) {
		fill(visited[i], visited[i] + w, false);
		fill(d[i], d[i] + w, INF);
	}
	d[cx][cy] = 0;
	visited[cx][cy] = true;

	while(!que.empty()) {
		P p = que.front();
		ll X = p.first, Y = p.second;
		if(X == dx && Y == dy) {
			cout << d[X][Y] << endl;
			return 0;
		}
		visited[X][Y] = true;
		que.pop_front();
		for(ll i = -2; i < 3; i++)
			for(ll j = -2; j < 3; j++) {
				ll x = X + i, y = Y + j;
				if(x < h && x >= 0 && y < w && y >= 0 && s[x][y] == '.') {
					if(visited[x][y]) continue;
					if(abs(i) + abs(j) < 2) {
						que.push_front(P(x, y));
						d[x][y] = d[X][Y];
						visited[i][j] = true;
					} else {
						if(d[X][Y] + 1 < d[x][y]) {
							d[x][y] = d[X][Y] + 1;
							que.push_back(P(x, y));
						}
					}
				}
			}
	}

	cout << -1 << endl;
	return 0;
}

Measured memory_bytes: 14404