akhauriyash/Code-Regression huggingface dataset:
mod = 998244353

N,K = map(int,input().split())
O = []
for i in range(K):
    O.append(tuple(map(int,input().split())))

A = [0] * (N+1)
A[0] = 1
B = [0] * (N+1)
aaa = 0
for i in range(N):
    for L,R in O:
        if i + L < N:
            B[i + L] += A[i]
            if i + R < N:
                B[i + R + 1] -= A[i]
    aaa += B[i + 1]
    A[i+1] = aaa % mod

print(A[N-1])

Measured memory_bytes: 71256
#![allow(dead_code)]
#![allow(unused_imports)]
#![allow(unused_variables)]

use proconio::{fastout, input};
use std::cmp::{max, min};

const INF: i32 = 1001001001;
const LNF: i64 = 1001001001001001001;
const MOD: i32 = 1000000007;

fn is_prime(x: usize) -> bool {
  if x == 1 {
    return false;
  }
  let mut i = 2;
  while i * i <= x {
    if x % i == 0 {
      return false;
    }
    i += 1;
  }
  true
}

#[fastout]
fn main() {
  input! {
    q: usize,
    lines: [(usize, usize); q],
  }
  let mut st = SegmentTree::new(100001, |a, b| a + b, 0);
  for i in (1..=100000).step_by(2) {
    if is_prime(i) && is_prime((i + 1) / 2) {
      st.update(i, st.query(i, i + 1) + 1);
    }
  }
  for (l, r) in lines {
    println!("{}", st.query(l, r + 1));
  }
}

struct SegmentTree<T> {
  v: Vec<T>,
  f: fn(T, T) -> T,
  e: T,
  n: usize,
}

impl<T: Copy> SegmentTree<T> {
  fn new(size: usize, f: fn(T, T) -> T, e: T) -> Self {
    let mut n = 1;
    while n < size {
      n <<= 1;
    }
    let v: Vec<T> = vec![e; n * 2];
    SegmentTree { v, f, e, n }
  }
  fn set(&mut self, k: usize, x: T) {
    self.v[k + self.n] = x;
  }
  fn build(&mut self) {
    for i in (1..self.n).rev() {
      self.v[i] = (self.f)(self.v[i * 2 + 0], self.v[i * 2 + 1]);
    }
  }
  fn update(&mut self, mut k: usize, x: T) {
    self.v[k + self.n] = x;
    k += self.n;
    while (k >> 1) > 0 {
      k >>= 1;
      self.v[k] = (self.f)(self.v[k * 2 + 0], self.v[k * 2 + 1]);
    }
  }
  fn query(&self, mut a: usize, mut b: usize) -> T {
    let mut l = self.e;
    let mut r = self.e;
    a += self.n;
    b += self.n;
    while a < b {
      if a & 1 == 1 {
        l = (self.f)(l, self.v[a]);
        a += 1;
      }
      if b & 1 == 1 {
        b -= 1;
        r = (self.f)(self.v[b], r);
      }
      a >>= 1;
      b >>= 1;
    }
    (self.f)(l, r)
  }
  fn reset(&mut self, k: usize) {
    self.update(k, self.e);
  }
}


Measured memory_bytes: 5524
using System;
namespace ConsoleApplication1{
    class Program{
        static void Main(string[] args){
            int w=int.Parse(Console.ReadLine());
		    int n=int.Parse(Console.ReadLine());
		    int[] wArr=new int[w];
		    for(int i=0;i<w;i++){
			    wArr[i]=i+1;
		    }
		    for(int i=0;i<n;i++){
			    String[] ab=Console.ReadLine().Split(',');
			    int a=int.Parse(ab[0])-1;
			    int b=int.Parse(ab[1])-1;
			    int box=wArr[a];
			    wArr[a]=wArr[b];
			    wArr[b]=box;
		    }
		    for(int i=0;i<w;i++){
                Console.WriteLine(wArr[i]);
		    }
        }
    }
}

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

int main() {
    int n;
    cin >> n;
    vector<int> a(n);  
    for(int i = 0; i < n; i++) cin >> a[i];

    int ans=0;
    for(int i = 0; i < n; i++) {
        if(i%2==0 && a[i]%2==1) ans++;
    }

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

Measured memory_bytes: 3588
import java.util.Scanner;
public class Main {

	public static void main(String[] args) {
		// TODO Auto-generated method stub
		Scanner sc = new Scanner(System.in);
		
		int n = sc.nextInt();
		String s = sc.next();
		int sum = 1;
		char c = s.charAt(0);
		
		for (int i = 0; i < n; i++) {
			if(s.charAt(i) != c) {
				sum++;
				c = s.charAt(i);				
			}
		}
			
	
	
		System.out.println(sum);

	}
}


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

void fnInput(vector<int> &a_rviTarget, vector<int> &a_rviSearch)
{
  int iTargetCnt;
  cin >> iTargetCnt;

  a_rviTarget.resize(iTargetCnt);
  for (int i = 0; i < iTargetCnt; i++)
    cin >> a_rviTarget[i];

  int iSearchCnt;
  cin >> iSearchCnt;

  a_rviSearch.resize(iSearchCnt);
  for (int i = 0; i < iSearchCnt; i++)
    cin >> a_rviSearch[i];
}

void fnBinarySearch(const vector<int> &a_cnrviTarget, const vector<int> &a_cnrviSearch, int &a_riFound)
{
  for (int i = 0; i < a_cnrviSearch.size(); i++)
  {
    int iLow  = 0;
    int iHigh = a_cnrviTarget.size();
    while (iLow != iHigh)
    {
      int iMid = (iLow + iHigh) / 2;
      if (a_cnrviSearch[i] == a_cnrviTarget[iMid])
      {
        a_riFound++;
        break;
      }
      else if (a_cnrviSearch[i] < a_cnrviTarget[iMid])
        iHigh = iMid;
      else
        iLow  = iMid + 1;
    }
  }
}

void fnResultOut(int a_iFound)
{
  cout << a_iFound << endl;
}

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

  vector<int> viTarget, viSearch;
  int iFound = 0;

  fnInput(viTarget, viSearch);
  fnBinarySearch(viTarget, viSearch, iFound);
  fnResultOut(iFound);

  return 0;
}

Measured memory_bytes: 1588
#line 1 "main.cpp"

/**
 * @title Template
 */

#include <iostream>
#include <algorithm>
#include <utility>
#include <numeric>
#include <vector>
#include <array>
#include <iomanip>

template <class T, class U>
inline bool chmin(T &lhs, const U &rhs) {
  if (lhs > rhs) { lhs = rhs; return true; }
  return false;
}

template <class T, class U>
inline bool chmax(T &lhs, const U &rhs) {
  if (lhs < rhs) { lhs = rhs; return true; }
  return false;
}

struct range {
  using itr = int64_t;
  struct iterator {
    itr i;
    constexpr iterator(itr i_) noexcept : i(i_) { }
    constexpr void operator ++ () noexcept { ++i; }
    constexpr itr operator * () const noexcept { return i; }
    constexpr bool operator != (iterator x) const noexcept { return i != x.i; }
  };
  const iterator l, r;
  constexpr range(itr l_, itr r_) noexcept : l(l_), r(std::max(l_, r_)) { }
  constexpr iterator begin() const noexcept { return l; }
  constexpr iterator end() const noexcept { return r; }
};

struct revrange {
  using itr = int64_t;
  struct iterator {
    itr i;
    constexpr iterator(itr i_) noexcept : i(i_) { }
    constexpr void operator ++ () noexcept { --i; }
    constexpr itr operator * () const noexcept { return i; }
    constexpr bool operator != (iterator x) const noexcept { return i != x.i; }
  };
  const iterator l, r;
  constexpr revrange(itr l_, itr r_) noexcept : l(l_ - 1), r(std::max(l_, r_) - 1) { }
  constexpr iterator begin() const noexcept { return r; }
  constexpr iterator end() const noexcept { return l; }
};

using i32 = int32_t;
using i64 = int64_t;
using u32 = uint32_t;
using u64 = uint64_t;

constexpr i32 inf32 = (i32(1) << 30) - 1;
constexpr i64 inf64 = (i64(1) << 62) - 1;

std::vector<i32> operator * (const std::vector<i32> &v1, const std::vector<i32> &v2) {
  size_t N = v1.size();
  std::vector<i32> res(N);
  for (auto i: range(0, N)) {
    res[i] = v2[v1[i]];
  }
  return res;
}
 
std::vector<i32> power(std::vector<i32> vec, u64 exp) {
  size_t N = vec.size();
  std::vector<i32> res(N);
  std::iota(res.begin(), res.end(), 0);
  while (exp > 0) {
    if (exp & 1) res = res * vec;
    vec = vec * vec;
    exp >>= 1;
  }
  return res;
}

int main() {  
  size_t N;
  std::cin >> N;
  std::vector<i64> X(N);
  for (auto &x: X) {
    std::cin >> x;
  }
  std::vector<i64> Y(N - 1);
  for (auto i: range(0, N - 1)) {
    Y[i] = X[i + 1] - X[i];
  }
  std::vector<i32> idx(N - 1);
  std::iota(idx.begin(), idx.end(), 0);
  size_t M;
  std::cin >> M;
  u64 K;
  std::cin >> K;
  while (M--) {
    i32 i;
    std::cin >> i;
    i -= 2;
    std::swap(idx[i], idx[i + 1]);
  }
  idx = power(idx, K);
  std::vector<i64> ans(N);
  ans.front() = X.front();
  for (auto i: range(0, N - 1)) {
    ans[i + 1] = ans[i] + Y[idx[i]];
  }
  for (auto x: ans) {
    std::cout << x << ".0\n";
  }
  return 0;
}


Measured memory_bytes: 6420
#include <iostream>
#include <algorithm>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
#include <queue>

// output
#define SPBR(w, n) std::cout<<(w + 1 == n ? '\n' : ' ');
#define YES cout << "YES" << endl;
#define Yes cout << "Yes" << endl;
#define NO cout << "NO" << endl;
#define No cout << "No" << endl;
// utility
#define ALL(i) (i).begin(), (i).end()
#define FOR(i, a, n) for(int i=(a);i<(n);++i)
#define RFOR(i, a, n) for(int i=(n)-1;i>=(a);--i)
#define REP(i, n) for(int i=0;i<int(n);++i)
#define RREP(i, n) for(int i=int(n)-1;i>=0;--i)
#define IN(a, x, b) (a<=x && x<b)
#define OUT(a, x, b) (x<a || b<=x)
template<class T> inline T chmax(T & a, const T b) { return a = (a < b) ? b : a; }
template<class T> inline T chmin(T& a, const T b) { return a = (a > b) ? b : a; }

// type/const
#define int ll
using ll = long long;
using ull = unsigned long long;
using ld = long double;
constexpr int MOD = 1000000007;

using namespace std;


signed main() {
  int a;
  string s;
  cin >> a >> s;
  
  if(a >= 3200) cout << s << endl;
  else cout << "red" << endl;

  return 0;
}

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

public class Main {
	static int n;

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

		String str[] = br.readLine().split(" ");
		n = Integer.parseInt(str[0]);
		int m = Integer.parseInt(str[1]);

		if (n > m) {
			for (int i = 0; i < n; i++)
				System.out.print(m);
		} else {
			for (int i = 0; i < m; i++)
				System.out.print(n);
		}
		System.out.println();
	}
}

Measured memory_bytes: 20308
#include <iostream>

using namespace std;

int main() {
    long long N, K, min;
    cin >> N >> K;

    if (N <= K) {
        min = N < K - N ? N : K - N;
    } else {
        long long s = N % K;
        min = s < K - s ? s : K - s;
    }

    cout << min << endl;
    
    return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
int main(void){
   int i,N,cnt=0;
   
   scanf("%d",&N);
   
   for(i=0;i<=N/4;i++){
       if( ((N-4*i)%7) ==0)
       cnt++;
   }
      if(cnt>0)
      printf("Yes");
      else
      printf("No");
      
       return(0);
   }


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

#define INF (INT64_MAX/2)
#define MAX 100000

int N, M;
typedef pair<int, int> P;
P ap[MAX];


int main() {
	cin >> N >> M;
	for( int i = 0; i < N; i++ ) {
		int A, B;
		cin >> A >> B;
		P p( A, B );
		ap[i] = p;
	}

	sort( ap, ap + N );
	long long ans = 0;
	int m = 0;
	for( int i = 0; i < N; i++ ) {
		if( m + ap[i].second < M ) {
			m += ap[i].second;
			ans += (long long)ap[i].first * ap[i].second;
		}
		else {
			for( int j = 0; j < ap[i].second; j++ ) {
				ans += ap[i].first;
				m++;
				if( m >= M ) {
					break;
				}
			}
			break;
		}
	}

	cout << ans << endl;

	return 0;
}


Measured memory_bytes: 1024
// ALDS1_3_D Areas on the cross-section diagram

#include <iostream>
#include <stack>
#include <list>
#include <string>

struct puddle{
	int area;
	int begin;
};

int main(int argc, char *argv[]){
	std::stack<int> down;	// Position of down slope
	std::list<puddle> p;	// Data of puddle (area and begin position)
	char shape;	// '\' or '/' or '_'
	int position = 0;
	int total_area = 0;

	while(std::cin >> shape){
		puddle new_p;
		new_p.area = 0;
		if(shape == '\\'){
			down.push(position);
		}
		else if((shape == '/') && !down.empty()){
			int new_begin = down.top();
			new_p.area = position - new_begin;
			total_area += new_p.area;
			new_p.begin = new_begin;
			while((p.back()).begin > new_begin){
				new_p.area = new_p.area + (p.back()).area;
				p.pop_back();	// Delete top data
			}
			p.push_back(new_p);	// Add new puddle
			down.pop();	// Delete top data
		}
		position++;
	}

	std::cout << total_area << std::endl;
	std::cout << p.size();
	for(auto itr=p.begin() ; itr!=p.end() ; itr++){
		std::cout << " " << itr->area;
	}
	std::cout << std::endl;

	return 0;
}



Measured memory_bytes: 3240
/**
 *    author:  otera    
**/
#include<iostream>
#include<string>
#include<cstdio>
#include<cstring>
#include<vector>
#include<cmath>
#include<algorithm>
#include<functional>
#include<iomanip>
#include<queue>
#include<deque>
#include<ciso646>
#include<random>
#include<map>
#include<set>
#include<complex>
#include<bitset>
#include<stack>
#include<unordered_map>
#include<utility>
#include<cassert>
using namespace std;

//#define int long long
typedef long long ll;
typedef unsigned long long ul;
typedef unsigned int ui;
typedef long double ld;
const int inf=1e9+7;
const ll INF=1LL<<60 ;
const ll mod=1e9+7 ;
#define rep(i,n) for(int i=0;i<n;i++)
#define per(i,n) for(int i=n-1;i>=0;i--)
#define Rep(i,sta,n) for(int i=sta;i<n;i++)
#define rep1(i,n) for(int i=1;i<=n;i++)
#define per1(i,n) for(int i=n;i>=1;i--)
#define Rep1(i,sta,n) for(int i=sta;i<=n;i++)
typedef complex<ld> Point;
const ld eps = 1e-8;
const ld pi = acos(-1.0);
typedef pair<int, int> P;
typedef pair<ld, ld> LDP;
typedef pair<ll, ll> LP;
#define fr first
#define sc second
#define all(c) c.begin(),c.end()
#define pb push_back
#define debug(x)  cerr << #x << " = " << (x) << endl;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

void solve() {
	int n; cin >> n;
    int sum = 0, ma = 0;
    rep(i, n) {
        int p; cin >> p;
        sum += p;
        chmax(ma, p);
    }
    cout << sum - ma + ma / 2 << endl;
}

signed main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	//cout << fixed << setprecision(10);
	//int t; cin >> t; rep(i, t)solve();
	solve();
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
using namespace std;
int main()
{
    int N;
    int ANS = 0;
    cin >> N;
    int D[N];
    for (int i = 0; i < N; i++)
        cin >> D[i];
    for (int a = 0; a < N - 1; a++)
        for (int b = a + 1; b < N; b++)
            ANS += D[a] * D[b];
    cout << ANS << "\n";
}

Measured memory_bytes: 256
import java.io.BufferedInputStream;
import java.io.BufferedOutputStream;
import java.io.PrintWriter;
import java.util.Scanner;

public class Main {

    public static void main(String[] args) throws Exception {
        try (BufferedInputStream in = new BufferedInputStream(System.in);
             PrintWriter out = new PrintWriter(new BufferedOutputStream(System.out))) {

            Scanner sc = new Scanner(in);

            // 12:44-

            int n = sc.nextInt();
            int last = sc.nextInt() - 1;
            for (int i = 1; i < n; i++) {
                int cur = sc.nextInt();
                if (cur < last) {
                    out.println("No");
                    return;
                }
                if (cur > last) cur--;
                last = cur;
            }

            out.println("Yes");
        }
    }

}


Measured memory_bytes: 47836
#include <iostream>
#include <vector>
#include <list>
#include <set>
#include <queue>
#include <map>
#include <algorithm>
#include <functional>
#include <string>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
using namespace std;

#define REP(i,p,n) for(int i=p;i<n;++i)
#define rep(i,n) REP(i,0,n)

using ll = long long int;
using pll = pair<ll, ll>;

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

    const int n = s.size();

    int a = 0;
    int b = 0;

    rep(i, n)
    {
        if ((i % 2 == 0))
        {
            if (s[i] == '0') { ++a; }
            if (s[i] == '1') { ++b; }
        }
        else
        {
            if (s[i] == '1') { ++a; }
            if (s[i] == '0') { ++b; }
        }
    }

    cout << std::min<int>(a, b) << endl;

    return 0;
}


Measured memory_bytes: 512
#include <iostream>
#include <cmath>

using namespace std;

int main() {
    long long int S;
    cin >> S;

    long long int X, Y;
    X = (long long int)sqrt(S);
    Y = X;
    
    if(X*Y==S) {
        cout << 0 << " " << 0 << " " << X << " " << 0 << " " << 0 << " " << Y << endl;
        return 0;
    } else {
        X++;
        Y++;
    }
    
    bool flag=true;
    int cnt=0;
    long long int x, y;
    while(flag) {
        long long int tmp=X*Y-S;
        for(long long int i=1; i<=sqrt(tmp); i++) {
            if(tmp%i==0) {
                if(tmp/i<Y && i<X) {
                    x = i;
                    y = tmp/i;
                    flag=false;
                    break;
                }
            }
        }

        if(flag) {
            if(cnt%2) {
                X++;
            } else {
                Y++;
            }
            
            cnt++;
        }
    }
    
    cout << 0 << " " << 0 << " " << X << " " << y << " " << x << " " << Y << endl;

    return 0;
    
}

Measured memory_bytes: 888
N = int(input())
S = input()
stack = []
for i in S:
    if len(stack) == 0:
        stack.append(i)
    else:
        prev = stack.pop()
        if prev == "(" and i == ")":
            continue
        else:
            stack.append(prev)
            stack.append(i)
ans = S
for i in stack:
    if i == ")":
        ans = "(" + ans
    else:
        ans = ans + ")"
print(ans)


Measured memory_bytes: 3060
#include <cstdlib>
#include <iostream>
#include <vector>
using namespace std;

#define REP(i, n) for (int i = 0; i < (n); ++i)
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)

int main(void) {
    int n, d;

    cin.tie(0);
    ios::sync_with_stdio(false);
    cin >> n >> d;
    vector<vector<int>> x(n, vector<int>(d));
    REP(i, n) {
        REP(j, d) {
            cin >> x[i][j];
        }
    }
    int dist, ans = 0;
    bool flg;
    REP(i, n) {
        FOR(j, i + 1, n) {
            dist = 0;
            
            REP(k, d) {
                dist += abs(x[i][k] - x[j][k]) * abs(x[i][k] - x[j][k]);
            }

            flg = false;
            REP (k, dist + 1) {
                if (k * k == dist) {
                    flg = true;
                }
            }
            if (flg) {
                ans++;
            }
        }
    }

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

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

int main(){
  long long int n,d;
  cin >> n >> d;
  
  long long int count = 0;
  
  for(int i = 0;i < n;i ++){
    long long int a,b;
    cin >> a >> b;
    if(sqrt(a * a + b * b) <= d)count ++;
  }
  
  cout << count << endl;
}

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

using namespace std;

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

  int n;
  cin >> n;
  int a = 1;
  while (true) {
    a *= 2;
    if (a > n) {
      a /= 2;
      break;
    }
  }

  cout << a << endl;

  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <algorithm>
#include <complex>
#include <utility>
#include <vector>
#include <string>
#include <stack>
#include <queue>
#include <tuple>
#include <cmath>
#include <bitset>
#include <cctype>
#include <set>
#include <map>
#include <unordered_map>
#include <numeric>
#include <functional>
#define _overload3(_1,_2,_3,name,...) name
#define _rep(i,n) repi(i,0,n)
#define repi(i,a,b) for(ll i=ll(a);i<ll(b);++i)
#define rep(...) _overload3(__VA_ARGS__,repi,_rep,)(__VA_ARGS__)
#define all(x) (x).begin(),(x).end()
#define PRINT(V) cout << V << "\n"
#define SORT(V) sort((V).begin(),(V).end())
#define RSORT(V) sort((V).rbegin(), (V).rend())
using namespace std;
using ll = long long;
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
inline void Yes(bool condition){ if(condition) PRINT("Yes"); else PRINT("No"); }
template<class itr> void cins(itr first,itr last){
    for (auto i = first;i != last;i++){
        cin >> (*i);
    }
}
template<class itr> void array_output(itr start,itr goal){
    string ans = "",k = " ";
    for (auto i = start;i != goal;i++) ans += to_string(*i)+k;
    if (!ans.empty()) ans.pop_back();
    PRINT(ans);
}
ll gcd(ll a, ll b) {
    return a ? gcd(b%a,a) : b;
}
const ll INF = 1e15;
const ll MOD = 1000000007;
const ll MOD2 = 998244353;
typedef pair<ll,ll> P;
typedef pair<double,double> point;
const ll MAX = 200005;
constexpr ll nx[8] = {1,0,-1,0,1,-1,1,-1};
constexpr ll ny[8] = {0,1,0,-1,1,1,-1,-1};
int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll n,m;
    cin >> n >> m;
    vector<vector<ll>> g(n);
    ll a,b;
    rep(i,m){
        cin >> a >> b;
        a--;
        b--;
        g[a].push_back(b);
    }
    vector<vector<ll>> ans;
    rep(i,n){
        queue<ll> q;
        vector<ll> par(n,-1);
        par[i] = -2;
        q.push(i);
        ll goal = -1;
        while(!q.empty() && goal == -1){
            ll v = q.front();
            q.pop();
            for (ll u:g[v]){
                if (u == i){
                    goal = v;
                    break;
                }
                else if (par[u] != -1){
                    continue;
                }
                else{
                    par[u] = v;
                    q.push(u);
                }
            }
        }
        if (goal == -1) continue;
        vector<ll> s;
        while(goal != -2){
            s.push_back(goal);
            goal = par[goal];
        }
        ans.push_back(s);
    }
    if (ans.size() == 0) PRINT(-1);
    else{
        ll ind = -1,siz = INF;
        rep(i,ans.size()){
            if (chmin(siz,(ll)ans[i].size())){
                ind = i;
            }
        }
        PRINT(ans[ind].size());
        for (ll v:ans[ind]) PRINT(v+1);
    }
}


Measured memory_bytes: 11016
#include <bits/stdc++.h>
using namespace std;
#define pp pair<int,int>
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define rep2(i,m,n) for(int (i)=(m);(i)<(n);(i)++)
#define ll long long
#define ld long double
#define all(a) (a).begin(),(a).end()
#define mk make_pair
ll mod=998244353;
int inf=1000001000;
ll INF=1e18+5;
ll MOD=1000000007;
int main(){
  ll n;
  cin>>n;
  if(n==1){
    cout<<0<<endl;
    return 0;
  }
  int m=ceil(sqrt(n))+1;
  vector<int> index(m);
  rep2(i,2,m){
    while(n%i==0){
      n/=i;
      index[i]++;
    }
  }
 int ans=0;
 rep(i,m){
   rep(j,45){
     if(j*(j+1)/2<=index[i]&&index[i]<(j+1)*(j+2)/2){
       ans+=j;
       break;
     }
   }
 }
  if(n>1) ans++;
  cout<<max(1,ans)<<endl;
return 0;
}

Measured memory_bytes: 7196
#include <cstdio>
#include <cstring>
#include <cmath>
#include <utility>
#include <iostream>
#include <functional>
#include <bitset>
#include <algorithm>
#include <vector>
#include <forward_list>
#include <set>
#include <map>
#include <queue>
#include <deque>
#include <stack>
#include <numeric>
#define ll long long int
#define pb push_back
#define rep(i,n) for(int i=0;i<(n);i++)
using namespace std;
int mx4[] = {0,1,0,-1};
int my4[] = {1,0,-1,0};
int INF = 2e6;
ll MOD = 1e9 + 7;
 
int main(){
    int n; cin >> n;
    vector<ll> a(n);
    rep(i,n) cin >> a[i];

    vector<ll> r(n),l(n);
    l[0] = a[0];
    r[n-1] = a[n-1];
    for(int i = 1;i < n;i++){
        l[i] = __gcd(a[i],l[i-1]);
    }
    for(int i = n-2;i >= 0;i--){
        r[i] = __gcd(a[i],r[i+1]);
    }
//rep(i,n)cout << r[i] <<" ";
    ll ans = 1;
    rep(i,n){
        if(i == 0) {
          ans = max(ans,r[1]);
          continue;
        }
        if(i == n-1) {
          ans = max(ans,l[n-2]);
          continue;
        }
        ll g = __gcd(l[i-1],r[i+1]);
        ans = max(ans,g);
    }
    cout << ans << endl;
}

Measured memory_bytes: 2560
#include<iostream>
#include<string>
#include<string.h>
#include<algorithm>
#include<stdio.h>
#include<cmath>
#include<vector>
#include<utility>
#include<stack>
#include<queue>
#include<list>
#include<bitset>
 
#define FOR(i, a, b) for(int i=(a);i<=(b);i++)
#define RFOR(i, a, b) for(int i=(a);i>=(b);i--)
#define MOD 1000000007
#define INF 1000000000
 
using namespace std;
 
int main(void) {
	int n, k;
	int sum = 1;
 
	cin >> n >> k;
 
	FOR(i, 1, n) {
		if (sum + k > sum * 2) {
			sum *= 2;
			
		}
		else {
			sum += k;
		}
	}
	cout << sum << endl;
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int A, B, C;
  cin >> A >> B >> C;
  if (A == B && A != C) {
      cout << "Yes" << endl;
  } else if (A == C && A != B) {
      cout << "Yes" << endl;
  } else if (B == C && A != B) {
      cout << "Yes" << endl;
  } else {
      cout << "No" << endl;
  }
}

Measured memory_bytes: 256
#include <stdio.h>
#define max 101
typedef struct{
  int num;
  int degree;
  int Adj[max];
} node;
int main()
{
  int n, A[max+1][max+1], i, j;
  node node[max];
  
  for(i = 0 ; i < max ; i++){
    for(j = 0 ; j < max ; j++) A[i][j] = 0; }

  scanf("%d",&n);

  for(i = 0 ; i < n ; i++){
    scanf("%d%d",&node[i].num,&node[i].degree);
    for(j = 0 ; j < node[i].degree ; j++){
      scanf("%d",&node[i].Adj[j]);
      A[node[i].num][node[i].Adj[j]] = 1; }
  }

  for(i = 1 ; i <= n ; i++){
    for(j = 1 ; j <= n-1 ; j++) printf("%d ",A[i][j]);
    printf("%d\n",A[i][n]); }

  return 0;
}



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

int main() {
    ll a, v, b, w, t; cin >> a >> v >> b >> w >> t;
    if(a == b){
        cout << "YES" << endl;
        return 0;
    } else if(v <= w){
        cout << "NO" << endl;
        return 0;
    }

    ll kyori = abs(a-b);
    ll tizimu = v-w;
    tizimu *= t;
    if(kyori > tizimu){
        cout << "NO" << endl;
    } else {
        cout << "YES" << endl;
    }

    return 0;
}

Measured memory_bytes: 3628
#include <iostream>
#include <cstdio>
#include <string>
#include <algorithm>
#include <utility>
#include <cmath>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <numeric>
#include <functional>
using namespace std;
typedef long long ll;
typedef vector<ll> vl;
typedef vector<vector<ll>> vvl;
typedef pair<ll, ll> P;
#define rep(i, n) for(ll i = 0; i < n; i++)
#define exrep(i, a, b) for(ll i = a; i <= b; i++)
#define out(x) cout << x << endl
#define exout(x) printf("%.10f\n", x)
#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define pb push_back
#define re0 return 0
const ll mod = 1000000007;
const ll INF = 1e16;
const ll MAX_N = 100010;
 
int main() {
    ll n, z, w;
    cin >> n >> z >> w;

    vl a(n);
    rep(i, n) {
        cin >> a[i];
    }

    if(n == 1) {
        out(abs(a[0] - w));
    }
    else {
        out(max(abs(a[n-1] - w), abs(a[n-2] - a[n-1])));
    }
    
    re0;
}

Measured memory_bytes: 384
#include <stdio.h>
#define M 121

long long p[M], t, tt;

int main()
{		
	int x, i, j;
	
	scanf("%d", &x);
	for(t = 0, i = 0; t < M; t++, i++){
		tt = t * t;
		p[i] = tt * tt * t;
	}
	for(i = 1; p[i] - p[i - 1] <= x; i++){
		for(j = i - 1; ; j--){
			if(j >= 0) t = p[i] - p[j];
			else t = p[i] + p[-j];
			if(t > x) break;
			if(t == x){
				printf("%d %d\n", i, j);
				return 0;
			}
		}
	}
			
	return 0;
}

Measured memory_bytes: 1736
#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <stack>
#include <queue>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>

using namespace std;

typedef long long ll;
typedef unsigned long long ull;

static const double EPS = 1e-8;
static const double PI = 4.0 * atan(1.0);
static const double PI2 = 8.0 * atan(1.0);

#define REP(i,n)	for(int i=0;i<(int)n;++i)
#define ALL(c)		(c).begin(),(c).end()
#define CLEAR(v)	memset(v,0,sizeof(v))
#define MP(a,b)		make_pair((a),(b))
#define ABS(a)		((a)>0?(a):-(a))
#define FOR(i,s,n)	for(int i=s;i<(int)n;++i)

int main(int argc, char **argv) {
	string S;
	cin >> S;
	cout << S.substr(0, 4) << " " << S.substr(4) << endl;
	return 0;
}


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

using namespace std;

bool odd_digits(int n) {
	int res = 0;
	while(n > 0) {
		res++;
		n /= 10;
	}
	return (res&1);
}

int main() {
	ios_base::sync_with_stdio(0);
	cin.tie(NULL);

	int n;
	cin >> n;

	int ans = 0;

	for(int i = 1; i <= n; i++) {
		ans += odd_digits(i);
	}

	cout << ans;

	return 0;
}

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

#define int             long long
#define INF             1e18
#define setbits(x)      __builtin_popcountll(x)
#define zerobits(x)      __builtin_ctzll(x)

const int MOD = 1e9 + 7;





int32_t main()
{
	ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);

	int n;
	cin >> n;
	int num = ceil((float)n / 1000);
	cout << num * 1000 - n;


	return 0;
}


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

#define int long long
#define ld long double

#define rep(i,a,b) for(int i=a;i<b;i++)
#define repb(i,a,b) for(int i=a;i>b;i--)

#define pb push_back
#define mp make_pair
#define all(A) A.begin(),A.end()
#define allr(A) A.rbegin(),A.rend()
#define precise(i) fixed << setprecision(i)
#define fi first
#define se second

#define err() cout<<"\n==================================\n";
#define errA(A) for(auto i:A) cout<<i<<" "; cout<<"\n";
#define err1(a) cout<<#a<<" "<<a<<"\n";
#define err2(a,b) cout<<#a<<" "<<a<<" "<<#b<<" "<<b<<"\n";
#define err3(a,b,c) cout<<#a<<" "<<a<<" "<<#b<<" "<<b<<" "<<#c<<" "<<c<<"\n";
#define err4(a,b,c,d) cout<<#a<<" "<<a<<" "<<#b<<" "<<b<<" "<<#c<<" "<<c<<" "<<#d<<" "<<d<<"\n";

const int logN = 20;
const int M = 1000000007;
const int INF = 1e12;
#define PI 3.14159265;
const int N = 200005;

#define Pii pair<int,int>
#define Vi vector<int>
#define Vpii vector<Pii>

void solve()
{
       int n,x,t;
       cin>>n>>x>>t;
       if(n%x)
       {
              cout<<((n/x)*(t)+t);
       }
       else
       {
              cout<<((n/x)*(t));
       }
}

int32_t main()
{
    ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
    int t=1;
//    cin>>t;
    while(t--)
    {
           solve();
    }
    return 0;
}

Measured memory_bytes: 3644
#include<bits/stdc++.h>
#define range(i,a,b) for(int i = (a); i < (b); i++)
#define rep(i,b) range(i,0,b)
#define vi vector<int>
#define pb(a) push_back(a)
#define all(a) (a).begin(), (a).end()
#define debug(x) cout << "<debug " << x << endl;
#define inf 5000
using namespace std;

int main(){
    string word;
    int page;
    map<string,vector<int> > info;

    while(cin >> word >> page){
        info[word].pb(page);
    }
    map<string, vector<int> >::iterator it;
    for(it = info.begin(); it != info.end(); it++){
        vector<int> &pageList = it->second;
        cout << it->first << endl;
        sort(all(pageList));
        for(int i = 0; i < pageList.size(); i++){
            if(i) cout << ' ';
            cout << pageList[i];
        }
        cout << endl;
    }
}

Measured memory_bytes: 1244
#include <stdio.h>
#include <string.h>
int main (){
	char hari[100];
	scanf ("%s",hari);
	if (strcmp(hari,"SUN")==0){
		printf ("7\n");
	}
	if (strcmp(hari,"MON")==0){
		printf ("6\n");
	}
	if (strcmp(hari,"TUE")==0){
		printf ("5\n");
	}
	if (strcmp(hari,"WED")==0){
		printf ("4\n");
	}
	if (strcmp(hari,"THU")==0){
		printf ("3\n");
	}
	if (strcmp(hari,"FRI")==0){
		printf ("2\n");
	}
	if (strcmp(hari,"SAT")==0){
		printf ("1\n");
	}
	
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  for(int i=0;i<(n);++i)
#define FORq(i, m, n) for(int i = (m);i <= (n);++i)
#define SCD(n) scanf("%d",&n)
#define SCD2(m,n) scanf("%d%d",&m,&n)
#define SCD3(m,n,k) scanf("%d%d%d",&m,&n,&k)
#define PB push_back
#define MP make_pair
#define ARSCD(A,N) REP(i,N){SCD(A[i]);}
#define ARSCD1(A,N) FORq(i,1,N){SCD(A[i]);}
#define PRINTD(n) printf("%d\n",n)
#define PRINTLLD(n) printf("%lld\n",n)
#define DEBUG printf("%s\n","debug")
#define fst first
#define snd second
#define IN(x,S) (S.count(x) != 0)
using namespace std;
typedef pair<int,int> PII;
typedef vector<int> VI;
typedef long long ll;
//////////////////////////////////////////////////////
int main(){
	int N;SCD(N);
	getchar();
	
	string S;
	set<char> T;
	getline(cin,S);
	
	REP(i,N){
		int s = S[i];
		T.insert(s);
	}
	
	int ans = 0;
	
	REP(c,N){
		set<char> Aset;
		set<char> Bset;
		
		REP(j,c){
			Aset.insert(S[j]);
		}
		
		REP(k,N-c){
			Bset.insert(S[k+c]);
		}
		
		int nans = Aset.size() + Bset.size() - T.size();
		ans = max(ans,nans);
	}
	
	PRINTD(ans);
	
	return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <algorithm>
#include <map>
#include <string>
#include <vector>
#include <cmath>
#include <random>
#include <climits>
#include <set>
#include <deque>
#include <queue>
#include <bitset>
#include <stack>
#include <regex>

#define mod 1000000007
#define INF2 9999999999
#define INF (1<<30)
#define rep(i,n) for(int (i)=0; (i)<(n); (i)++)
#define P pair<int, int>

using namespace std;
using ll = int64_t;

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

void solve(){
    int a, b;
    cin >> a >> b;
    int remain = b-a;
    int tower = 0;
    rep(i, remain){
        tower += i;
    }
    cout << tower - a << endl;
}

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


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


int main() {
	
	int n;
	cin >> n;
	vector<int> h(n);
	
	for(auto &i : h) cin >> i;
	vector<int> t(n);
	for(int i=n-2; i>=0; i--){
		if(h.at(i)>=h.at(i+1)) t.at(i)=t.at(i+1)+1;
	}
	sort(t.rbegin(), t.rend());
	cout << t.at(0) << endl;
	
	return 0;
}

Measured memory_bytes: 1024
#input
N = int(input())

B = [[] for _ in range(N)]
for i in range(N):
    A = int(input())
    for _ in range(A):
        x, y  = map(int, input().split())
        B[i].append([x-1, y])
    
#output
answer = 0
for i in range(1, 2**N):
    Flag = True
    for j in range(N):
        if (i >>j) & 1 == 0:
            continue
        for x, y in B[j]:
            if (i >> x) & 1 != y:
                Flag = False
                break
        if not Flag:
            break
    if Flag:
        answer = max(answer, bin(i)[2:].count("1"))

print(answer)

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

    using namespace std;
    typedef long long ll;
    typedef unsigned long long ull;
    # define M_PI  3.14159265358979323846


    const int M=1e9+7;
    long long mod(long long x){
        return ((x%M + M)%M);
    }
    long long add(long long a, long long b){
        return mod(mod(a)+mod(b));
    }
    long long mul(long long a, long long b){
        return mod(mod(a)*mod(b));
    }
    long long minu(long long a, long long b){
        return mod(mod(a)-mod(b));
    }
    ll modPow(ll a, ll b){
        if(b==0)
            return 1LL;
        if(b==1)
            return a%M;
        ll res=1;
        while(b){
            if(b%2==1)
                res=mul(res,a);
            a=mul(a,a);
            b=b/2;
        }
        return res;
    }
ll dp[2002];

ll gen(ll x)
{
    if(x==0)
        return 1LL;
    if(x==2 ||x==1)
        return 0LL;
    if(x>=3 and x<=5)
        return 1LL;
    if(dp[x]!=-1)
        return dp[x];
    else{
        ll res=0;
        for(int i=3;i<=x;i++)
        {
            if(x-i>=0)
            res=add(res,gen(x-i));
        }
        return dp[x]=res;
    }
}
int main()
{
    int n;
    cin>>n;
    memset(dp,-1,sizeof(dp));
    dp[0]=1;
    cout<<gen(n);

}


Measured memory_bytes: 3644
// https://atcoder.jp/contests/abc139/submissions/7298310

#include <iostream>
#include <vector>
#pragma GCC optimize("Ofast")
#pragma GCC target("avx")

using namespace std;
#define rep(i,n) for(int i=0;i<int(n);++i)

int main(void){
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    int n;
    cin >> n;
    int a[1010][1010] = {};
    int head[1010] = {};
    rep(i,n){
        rep(j,n-1){
            int x;
            cin >> x;
            x--;
            a[i][j] = x;
        }
    }
    int turn = 0;
    vector<int> used(n, -1);
    while(true){
        bool ng = true;
        int empty_cnt = 0;
        rep(i,n){
            if (head[i] == n-1) {
                empty_cnt++;
                continue;
            }
            int j = a[i][head[i]];
            if (used[i] == turn || used[j] == turn) continue;
            if (a[j][head[j]] == i) {
                head[i]++;
                head[j]++;
                used[i] = used[j] = turn;
                ng = false;
            }
        }
        if (empty_cnt == n) break;
        if (ng) {
            cout << -1 << endl;
            return 0;
        }
        turn++;
    }
    cout << turn << endl;

    return 0;
}


Measured memory_bytes: 4224
/**********************************************************************************************
******************************AUTHOR:**********************************************************
****************************ASHISH RANJAN******************************************************
***********************************************************************************************/
#include<iostream>
#include<algorithm>
#include<cmath>
#include<chrono>
#include<vector>
#include<string>
#include<cstring>
#include<iomanip>
using namespace std;
using namespace std::chrono;
/*
auto start = high_resolution_clock::now();
auto stop = high_resolution_clock::now();
  auto duration = duration_cast<microseconds>(stop - start); 
  
    cout << "Time taken by function: "
         << duration.count() << " microseconds" << endl;
*/
#define fast() ios_base::sync_with_stdio(false);cin.tie(NULL)
#define ll long long
#define mod 1000000007
#define fr(i,n) for(int i=0;i<(int)n;i++)
#define frs(i,a,b) for(int i = a;i<b;i++)
#define meme(a,b,c) memset(a,b,sizeof(c)); //works only for 0 and -1
int main(){
  fast();
  ll n;
  cin>>n;
  ll arr[n];
  fr(i,n)cin>>arr[i];
  ll sum = 0;
  frs(i,1,n){
  if(arr[i]<arr[i-1]){sum+= (arr[i-1]-arr[i]);arr[i] = arr[i-1];}
  }
  cout<<sum;
 return 0;
  
}




Measured memory_bytes: 5112
#pragma GCC optimize("O3")
#include <bits/stdc++.h>
#define ll long long
#define rep(i,n) for(ll i=0;i<(n);i++)
#define pll pair<ll,ll>
#define pq priority_queue
#define pb push_back
#define eb emplace_back
#define fi first
#define se second
#define ios ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0);
#define lb(c,x) distance(c.begin(),lower_bound(all(c),x))
#define ub(c,x) distance(c.begin(),upper_bound(all(c),x))

using namespace std;

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

const ll INF=1e9+7;


int main(){
    ll n;
    cin >> n;
    cout << (n-2)*180 << endl;
}


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

int main(){
    int n;  cin >> n;
    vector<ll>a(n);
    rep(i, n)   cin >> a[i];
    ll s = 0;
    rep(i, n)   s ^= a[i];
    rep(i, n){
        ll ans = s^a[i];
        cout << ans << endl;
    }
}


Measured memory_bytes: 4844
N, M = gets.split.map(&:to_i)
data = Hash.new(0)
N.times do
  d = gets.split.map(&:to_i)
  k = d[0]
  k.times do |i|
    data[d[i + 1]] += 1
  end
end

count = 0
M.times do |i|
  if data[i+1] == N
    count += 1
  end
end

puts count

Measured memory_bytes: 1788
N, A = map(int, input().split())
X = list(map(int, input().split()))
for i in range(N):
  X[i] -= A
D = {0: 1}
for i in X:
  S = [[j, D[j]] for j in D]
  for j in S:
    if j[0] + i in D:
      D[j[0]+i] += j[1]
    else:
      D[j[0]+i] = j[1]
print(D[0]-1)

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

check = {}
ans = 0

for i in range(N):
    x = i - A[i]
    y = A[i] + i
    ans += check.get(x, 0)
    check.setdefault(y, 0)
    check[y] += 1

print(ans)


Measured memory_bytes: 40308
#include <bits/stdc++.h>
#define REP(i, n) for (int i = 0; i < n; i++) //for文マクロ
using namespace std;

typedef unsigned long long ull;
typedef long long ll;
typedef pair<ull, ull> P; //ペア　タイプでふ
constexpr ll bigNum = 1000000007;

int main(void)
{
    std::cin.tie(0);
    std::ios_base::sync_with_stdio(false);
    //ここから本体
    int n, d;
    cin >> n >> d;
    vector<vector<int>> vec(n, vector<int>(d));
    for (int i = 0; i < n; i++)
    {
        for (int j = 0; j < d; j++)
        {
            cin >> vec[i][j];
        }
    }
    int count = 0;
    double num = 0;
    for (int i = 0; i < n - 1; i++)
    {
        for (int j = i + 1; j < n; j++)
        {
            for (int k = 0; k < d; k++)
            {
                num += (fabs(vec[i][k] - vec[j][k]) * fabs(vec[i][k] - vec[j][k]));
            }
            num = sqrt(num);
            if (num == (int)num)
            {
                count++;
            }
            num = 0;
        }
    }
    cout << count;
}

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

int main() {
  
  int64_t A, B, K; cin >> A >> B >> K;
  
  if (K <= A) {
    cout << A - K << " " << B << endl;
  }
  else {
    cout << 0 << " " << max(0L, A + B - K) << endl;
  }
  
}

Measured memory_bytes: 256
from collections import deque

class Process:
        def __init__(self, id, time):
                self.id = id
                self.time = time

list = input().split()
n = int(list[0])
q = int(list[1])

queue = deque([]) 

for i in range(n):
        temp = input().split()
        queue.append(Process(temp[0], int(temp[1])))

totalTime = 0
while len(queue) != 0:
        if queue[0].time > q:
                queue[0].time -= q
                queue.append(queue.popleft())
                totalTime += q
        else:
                totalTime += queue[0].time
                print(queue[0].id, totalTime)
                queue.popleft()


Measured memory_bytes: 17732
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define MN 5005
#define Mod 1000000007
int read(){
	int a=0;char c=getchar();
	while(c>'9'||c<'0')c=getchar();
	while('0'<=c&&c<='9'){
		a=a*10+c-48;
		c=getchar();
	}
	return a;
}
vector<int>edge[MN];
int n,g[MN],fa[MN];
int siz[MN],f[MN][MN],tmp[MN];
void dfs(int x){
	siz[x]=f[x][1]=1;
	for(int i=0;i<edge[x].size();++i){
		int v=edge[x][i];
		if(fa[x]==v)continue;
		fa[v]=x;
		dfs(v);
		for(int i=0;i<=siz[x]+siz[v];++i)tmp[i]=0;
		for(int i=0;i<=siz[x];++i)
			for(int j=0;j<=siz[v];++j)
				tmp[i+j]=(tmp[i+j]+f[x][i]*f[v][j])%Mod;
		siz[x]+=siz[v];
		for(int i=0;i<=siz[x];++i)f[x][i]=tmp[i];
	}
	for(int i=2;i<=siz[x];i+=2)
		f[x][0]=(f[x][0]-f[x][i]*g[i]%Mod+Mod)%Mod;
}
signed main(){
	n=read();
	for(int i=1;i<n;++i){
		int x=read(),y=read();
		edge[x].push_back(y);
		edge[y].push_back(x);
	}
	g[0]=1;
	for(int i=2;i<=n;i+=2)g[i]=g[i-2]*(i-1)%Mod;
	dfs(1);
	printf("%lld\n",Mod-f[1][0]);
	return 0;
}


Measured memory_bytes: 92768
n,x,mod=map(int,input().split())
#32 回やればコーナーは回避できる
now=x
xs=0
for i in range(min(n,32)):
    if now%mod==0:print(xs);exit()
    else:
        xs+=now
        now=now*now%mod
        
if x%mod:
    from collections import defaultdict
    d=defaultdict(int)
    su=defaultdict(int)
    s=0
    for i in range(1,n+1):
        if  d[x]:cnt=i;pre=d[x];break
        d[x]=i
        s+=x
        su[i]=s
        x=x**2%mod
    else:print(s);exit()
    length=cnt-pre
    roop=(n-pre)//length
    amari=(n-pre)%length
    once=s-su[pre]+x

    print(su[pre]+roop*once+su[pre+amari]-su[pre-1]-x)


else:print(0)


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

#define REP(i, n) for(int (i)=0;(i)<(n);++(i))
#define MOD 1000000007

using namespace std;

typedef long long ll;

int main()
{
    ll K, N;
    cin >> K >> N;
    ll A[N];
    REP(i, N) cin >> A[i];

    ll diffMax = 0;
    REP(i, N - 1) diffMax = max(diffMax, A[i + 1] - A[i]);
    diffMax = max(diffMax, A[0] + K - A[N -1]);
    ll ans = K - diffMax;

    cout << ans << endl;
}


Measured memory_bytes: 1792
#include <bits/stdc++.h>
#define LOCAL
using namespace std;
template <typename A, typename B>
ostream& operator <<(ostream& out, const pair<A, B>& a) {
out << "(" << a.first << "," << a.second << ")";
return out;
}
template <typename T, size_t N>
ostream& operator <<(ostream& out, const array<T, N>& a) {
out << "["; bool first = true;
for (auto& v : a) { out << (first ? "" : ", "); out << v; first = 0;} out << "]";
return out;
}
template <typename T>
ostream& operator <<(ostream& out, const vector<T>& a) {
out << "["; bool first = true;
for (auto& v : a) { out << (first ? "" : ", "); out << v; first = 0;} out << "]";
return out;
}
template <typename T, class Cmp>
ostream& operator <<(ostream& out, const set<T, Cmp>& a) {
out << "{"; bool first = true;
for (auto& v : a) { out << (first ? "" : ", "); out << v; first = 0;} out << "}";
return out;
}
template <typename U, typename T, class Cmp>
ostream& operator <<(ostream& out, const map<U, T, Cmp>& a) {
out << "{"; bool first = true;
for (auto& p : a) { out << (first ? "" : ", "); out << p.first << ":" << p.second; first = 0;} out << "}";
return out;
}
#ifdef LOCAL
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
#else
#define trace(...) 42
#endif
template <typename Arg1>
void __f(const char* name, Arg1&& arg1){
cerr << name << ": " << arg1 << endl;
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args){
const char* comma = strchr(names + 1, ',');
cerr.write(names, comma - names) << ": " << arg1 << " |";
__f(comma + 1, args...);
}
#define rep(i,n) for(int i=0; i<(n); i++)
using ll = long long;
#define int long long
using P = pair<int,int>;
signed main(){
    string s;cin >> s;
    int k;cin >> k;
    int n = s.size();
    int i;
    for(i =0; i< n && s[i] == '1';i++);
    if(k <= i)cout << 1 << endl;
    else{
        cout << s[i] << endl;
    }
    return 0;
}

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

int main() {
  int N, L;
  cin >> N >> L;
  vector<string> dic(N);
  for (int i = 0; i < N; i++) cin >> dic.at(i);
  sort(dic.begin(), dic.end());
  string S = "";
  for (int i = 0; i < N; i++) S += dic.at(i);
  cout << S << endl;
  return 0;
}


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

int main() {
	long long a, b, c, x, y; cin >> a >> b >> c >> x >> y;
	c *= 2;
	long long ans = 1e10;
	for (long long i = 0; i <= max(x, y); i++) {
		ans = min(ans, c * i + max(0LL, x - i) * a + max(0LL, y - i) * b);
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 256
/* Author: Dhruv Rastogi */
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define int long long
#define all(sdk) sdk.begin(),sdk.end()
#define mll map<int, int>
#define pb push_back
#define rep(i,a,b) for(int i=a;i<b;++i)
#define repd(i,a,b) for(int i=a;i>=b;--i)
#define mp make_pair
#define hell 1000000007
#define endl '\n'
#define vvll vector<vector<int> >
#define vll vector<int>
#define mint map<int,int> 
#define sz(x) (int)x.size()
#define sll set<int>
#define pll pair<int,int>
#define F first
#define S second
const long double PI = acos(-1.0);

void solve(){  
	map<int,int> m;
	rep(i,0,2){
		int x;
		cin>>x;
		m[x]=1;
	} 
	rep(i,1,4){
		if(!m[i]){
			cout<<i<<endl;
			return;
		}
	}
}

signed main(){
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    int t=1;
    // cin>>t;
    while(t--){
        solve();
    }
    return 0;
}

Measured memory_bytes: 256
#include <set>
#include <map>
#include <deque>
#include <queue>
#include <stack>
#include <cmath>
#include <ctime>
#include <bitset>
#include <cstdio>
#include <string>
#include <vector>
#include <cstdlib>
#include <cstring>
#include <cassert>
#include <iostream>
#include <algorithm>
#include <unordered_map>
#define mem(a,b) memset(a,b,sizeof (a))
#define endl '\n'
#define pb push_back
typedef long long ll;
const int maxn=200010;
const int inf=1e9;
const ll mod=998244353;
const double pi=acos(-1.0);
using namespace std;
int main()
{
    std::ios::sync_with_stdio(false);
    int n,p;
    string s;
    cin>>n>>p>>s;
    ll ans=0,x=1,a[11100],b=0;
    if (p==2||p==5)
    {
        for (int i=0;i<n;i++)
            if ((s[i]-'0')%p==0)
                ans+=i+1;
    }
    else
    {
        a[0]=1;
        for (int i=n-1;i>=0;i--)
        {
            b+=(s[i]-'0')*x;
            b%=p;
            ans+=a[b]++;
            x=x*10%p;
        }
    }
    cout<<ans<<endl;
    return 0;
}


Measured memory_bytes: 832
import java.util.Scanner;
public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int D = sc.nextInt();
		int N = sc.nextInt();
		int n = N/100;
		N += n;

		System.out.println((int)Math.pow(100, D)*N);

	}

}


Measured memory_bytes: 23892