akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <algorithm>
using namespace std;
typedef long long int ll;
ll N;
ll a[100001];
ll d[100001];
ll sum;
ll k;
int main(){
  bool f=true;
  cin >> N;
  for(int i=0;i<N;i++){cin >> a[i];sum+=a[i];}
  ll t;
  t=(N*(N+1)/2);
  if(sum%t!=0){cout << "NO" << endl; return 0;}
  k=sum/t;
  for(int i=0;i<N;i++){
    d[i]=a[(i+1)%N]-a[i];
    d[i]-=k;
  }
  for(int i=0;i<N;i++){
    if(!(d[i]<=0 && abs(d[i])%N==0))f=false;
  }
  if(f==true)cout << "YES" << endl;
  else cout << "NO" << endl;
  return 0;
}


Measured memory_bytes: 1792
#include <iostream> // cin, cout, cerr
#include <algorithm> // minmax, sort, swap
#include <numeric> // iota
#include <cstdio> // printf, scanf
#include <string> // string, stoi, to_string
#include <vector> // vector
#include <queue> // queue, priority_queue
#include <deque> // deque
#include <map> // key-value pairs sorted by keys
#include <set> // set
#include <iomanip> // cout<<setprecision(n)
#include <functional> // function<void(int)>
#include <cmath>

#ifdef DEBUG
#include "debug.hpp"
#else
#define debug(...)
#endif

#define int long long // at least int64 > 9*10^18
#define ENDL '\n'
#define rep(i,n) for(int i = 0; i < (n); i++)
#define print(i) std::cout << (i) << '\n'
#define all(v) (v).begin(), (v).end()
/* libraries */

signed main() {
	int n;
	std::cin >> n;
	std::vector<int> a(n);
	rep(i,n) std::cin >> a[i];
	// dp[l][r]
	std::vector<std::vector<int> > dp(n+1,std::vector<int>(n+1));
	rep(i,n+1) dp[i][i]=0;
	for(int l=n-1;l>=0;l--) {
		for(int r=l+1;r<=n;r++) {
			bool first = (n-(r-l))%2==0;
			if(first) dp[l][r] = std::max(dp[l+1][r]+a[l], dp[l][r-1]+a[r-1]);
			else dp[l][r] = std::min(dp[l+1][r]-a[l], dp[l][r-1]-a[r-1]);
		}
	}
	print(dp[0][n]);
	return 0;
};


Measured memory_bytes: 70784
# from math import inf
inf = 10**50

N, M = map(int, input().split())
edges = []
for j in range(M):
    edges.append(list(map(int, input().split())))

d = [0] + ([-inf]*(N-1))
pred = [None] * N

for i in range(N-1):
    for j in range(M):
        u = edges[j][0]-1
        v = edges[j][1]-1
        w = edges[j][2]
        if (d[v] < d[u] + w) and (d[u] != -inf):
            d[v] = d[u] + w
            pred[v] = u

positive_loop = False
for i in range(N):
    for j in range(M):
        u = edges[j][0]-1
        v = edges[j][1]-1
        w = edges[j][2]
        if (d[u] + w > d[v]) and (d[u] != -inf):
            d[v] = d[u] + w
            if v == N-1:
                positive_loop = True
                break
    if positive_loop:
        break

if positive_loop:
    print("inf")
else:
    print(d[N-1])


Measured memory_bytes: 46424
#include <stdio.h>

int main(void){
	int n, m, l;
	int i, j, k;
	int mat1[10000] = { 0 };
	int mat2[10000] = { 0 };

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

	for (i = 0; i < n; i++)
	{
		for (j = 0; j < m; j++)
		{
			scanf("%d", &mat1[i * m + j]);
		}
	}
	for (i = 0; i < m; i++)
	{
		for (j = 0; j < l; j++)
		{
			scanf("%d", &mat2[i * l + j]);
		}
	}
	for (i = 0; i < n; i++)
	{
		for (j = 0; j < l; j++)
		{
			long c = 0;
			for (k = 0; k < m; k++)
			{
				c += mat1[i * m + k] * mat2[k * l + j];
			}
			printf("%ld", c);
			if (j < l - 1) putchar(' ');
		}
		putchar('\n');
	}

	return 0;
}


Measured memory_bytes: 2108
#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;
using ll = long long;
using u64 = uint_fast64_t;
using pii =  pair<int, int>;
using pll =  pair<long long, long long>;
#define rep(i, n) for(int i = 0; i < (n); ++i)
#define all(x) (x).begin(),(x).end()
constexpr char ln = '\n';
constexpr long long MOD = 1000000007;
//constexpr long long MOD = 998244353;
template<class T1, class T2> inline bool chmax(T1 &a, T2 b) { if (a < b) { a = b; return true;} return false; }
template<class T1, class T2> inline bool chmin(T1 &a, T2 b) { if (a > b) { a = b; return true;} return false; }
inline int popcount(int x) {return __builtin_popcount(x);}
inline int popcount(long long x) {return __builtin_popcountll(x);}
void print() { cout << "\n"; }
template<class T, class... Args>
void print(const T &x, const Args &... args) {
    cout << x << " ";
    print(args...);
}
///////////////////////////////////////////////////////////////////////////////////////////////////////////////

int main() {
    ios::sync_with_stdio(false); cin.tie(nullptr);
    int N; cin >> N;
    vector<int> A(N),B(N);
    rep(i,N) cin >> A[i];
    rep(i,N) cin >> B[i];

    vector<vector<int>> dp(1<<N, vector<int>(51,1e9));
    dp[0][0] = 0;
    rep(mask,1<<N) {
        int pos = popcount(mask);
        rep(d,51) {
            if (dp[mask][d]==1e9) continue;
            rep(i,N) {
                if (mask&(1<<i)) continue;
                int val = (abs(pos-i)&1) ? B[i] : A[i];
                if (d > val) continue;
                int cost = 0;
                rep(j,i) {
                    if (!(mask&(1<<j))) cost++;
                }
                chmin(dp[mask|(1<<i)][val],dp[mask][d]+cost);
            }
        }
    }

    int ans = 1e9;
    rep(i,51) chmin(ans,dp[(1<<N)-1][i]);

    cout << (ans==1e9 ? -1 : ans) << ln;
}


Measured memory_bytes: 66828
#include<iostream>
#include<iomanip>
#include<cmath>
#include<algorithm>
#include<string>
#include<cstring>
using namespace std;
int main(){
	string a;
	cin>>a;
	int ans=0;
	int len=a.length();
	for(int i=1;i<len;i++){
		if(a[i]!=a[i-1])ans++;
	}
	cout<<ans<<endl;

return 0;
}

Measured memory_bytes: 512
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.NoSuchElementException;

public class Main {
	public static void main(String[] args){
		FastScanner sc = new FastScanner();
		PrintWriter out = new PrintWriter(System.out);
		int N = sc.nextInt();
		int K = sc.nextInt();
		long[] map = new long[N];
		for(int i=0;i<N;i++){
			map[i] = sc.nextInt();
		}
		long dist=Long.MAX_VALUE;
		for(int i=0;i<=N-K;i++){
			long start = map[i];
			long end = map[i+K-1];
			if(start*end > 0){
				dist = Math.min(dist, Math.max(Math.abs(start), Math.abs(end)));
			}else{
				dist = Math.min(dist, Math.min(Math.abs(start), Math.abs(end))*2+Math.max(Math.abs(start), Math.abs(end)));
			}
		}
		out.println(dist);
		out.flush();
	}
}

class FastScanner {
    private final InputStream in = System.in;
    private final byte[] buffer = new byte[1024];
    private int ptr = 0;
    private int buflen = 0;
    private boolean hasNextByte() {
        if (ptr < buflen) {
            return true;
        }else{
            ptr = 0;
            try {
                buflen = in.read(buffer);
            } catch (IOException e) {
                e.printStackTrace();
            }
            if (buflen <= 0) {
                return false;
            }
        }
        return true;
    }
    private int readByte() { if (hasNextByte()) return buffer[ptr++]; else return -1;}
    private static boolean isPrintableChar(int c) { return 33 <= c && c <= 126;}
    public boolean hasNext() { while(hasNextByte() && !isPrintableChar(buffer[ptr])) ptr++; return hasNextByte();}
    public String next() {
        if (!hasNext()) throw new NoSuchElementException();
        StringBuilder sb = new StringBuilder();
        int b = readByte();
        while(isPrintableChar(b)) {
            sb.appendCodePoint(b);
            b = readByte();
        }
        return sb.toString();
    }
    public long nextLong() {
        if (!hasNext()) throw new NoSuchElementException();
        long n = 0;
        boolean minus = false;
        int b = readByte();
        if (b == '-') {
            minus = true;
            b = readByte();
        }
        if (b < '0' || '9' < b) {
            throw new NumberFormatException();
        }
        while(true){
            if ('0' <= b && b <= '9') {
                n *= 10;
                n += b - '0';
            }else if(b == -1 || !isPrintableChar(b)){
                return minus ? -n : n;
            }else{
                throw new NumberFormatException();
            }
            b = readByte();
        }
    }
    public int nextInt() {
        long nl = nextLong();
        if (nl < Integer.MIN_VALUE || nl > Integer.MAX_VALUE) throw new NumberFormatException();
        return (int) nl;
    }
    public double nextDouble() { return Double.parseDouble(next());}
}

Measured memory_bytes: 22356
N, X = map(int, input().split())
A = list(map(int, input().split()))
ans = 0
 
if A[0] > X:
    ans += A[0] - X
    A[0] = X
    
for i in range(N-1):
    if A[i] + A[i+1] > X:
        ans -= X - (A[i] + A[i + 1])
        A[i+1] += X - (A[i] + A[i+1])
 
print(ans)

Measured memory_bytes: 14540
#!/usr/bin/env python3
#C

import sys
import math
from bisect import bisect_right as br
from bisect import bisect_left as bl
sys.setrecursionlimit(2147483647)
from heapq import heappush, heappop,heappushpop
from collections import defaultdict
from itertools import accumulate
from collections import Counter
from collections import deque
from operator import itemgetter
from itertools import permutations
mod = 10**9 + 7
inf = float('inf')
def I(): return int(sys.stdin.readline())
def LI(): return list(map(int,sys.stdin.readline().split()))

n, c, k = LI()
t = [I() for _ in range(n)]
t.sort()
tmp = 0
cnt = 0
ans = 0
if c == 1:
    print(n)
    quit()
for i in range(n):
    if t[i] <= tmp:
        cnt += 1
        if cnt == c:
            cnt = 0
            ans += 1
            if i + 1 < n:
                tmp = t[i+1] + k
            else:
                ans += 1
                break
    else:
        tmp = t[i] + k
        cnt = 1
        ans += 1
print(ans)

Measured memory_bytes: 43612
import std.stdio;
import std.conv;
import std.string;
import std.typecons;
import std.algorithm;
import std.array;
import std.range;
import std.math;
import std.regex : regex;
import std.container;
import std.bigint;
import std.numeric;


void main()
{
  long n, m;
  readf("%s %s\n", &n, &m);
  long res;
  if (2 * n < m) {
    res = n;
    m -= 2 * n;
    res += m / 4;
  } else {
    res = m / 2;
  }
  res.writeln;
}


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

signed main(){
    int n;
    cin >> n;
    vector<int> a(n + 1), b(n);
    for(int i = 0; i < n + 1; i++) cin >> a[i];
    for(int i = 0; i < n; i++) cin >> b[i];
    int ans = 0;
    for(int i = 0; i < n; i++){
        int tmp =  min(a[i], b[i]);
        ans += tmp;
        a[i] -= tmp;
        b[i] -= tmp;
        tmp = min(a[i + 1], b[i]);
        ans += tmp;
        a[i + 1] -= tmp;
        b[i] -= tmp;
    }
    cout << ans << endl;
}

Measured memory_bytes: 1792
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class Main {
  public static void main(String[] args) throws IOException {
  	BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
    int k = Integer.parseInt(br.readLine());
    
    long sum = 0L;
    for (int i = 1; i <= k; i++)
      for (int j = 1; j <= k; j++) {
        int g = gcd(i, j);
        for (int s = 1; s <= k; s++)
          sum += gcd(g, s);
      }
    
    System.out.print(sum);
  }
  
  private static int gcd(int a, int b) {
  	while (b != 0) {
      int t = b;
      b = a % b;
      a = t;
    }
    
    return a;
  }
}


Measured memory_bytes: 32716
#include <iostream>
#include <vector>
#include <utility>
#include <algorithm>
#include <cmath>
using namespace std;

int main(){
  vector<pair<int,int>> V;
  for(int i = 1; i <= 150; ++i){
    for(int j = i+1; j <= 150; ++j){
      V.emplace_back(i*i+j*j,i);
    }
  }
  sort(V.begin(), V.end());
  int h, w;
  while(cin >> h >> w, h){
    pair<int,int> t(h*h+w*w,h);
    pair<int,int> p = *upper_bound(V.begin(), V.end(), t);
    int h_ = p.second, w_ = sqrt(p.first-h_*h_);
    cout << h_ << " " << w_ << endl;
  }
}



Measured memory_bytes: 3220
# 整数で受け取る

x, y = gets.chomp.split(' ').map(&:to_i)

# yが6の倍数である
# yの上限4x 下限2x
# 2x と 4xの間の全てのy偶数

if y <= 4*x && y >= 2*x && y%2==0
  puts "Yes"
else
  puts "No"
end

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

const int MAX_N = 1010;

int main(void) {
  int X;
  cin >> X;

  vector<int> v(MAX_N, 0);
  v[1] = 1;
  for (int i = 2; i < MAX_N; ++i) {
    int num = i;
    while (num * i < MAX_N) {
      num *= i;
      v[num] = 1;
    }
  }

  int ans = 1;
  for (int i = X; X > 0; --i) {
    if (v[i]) {
      ans = i;
      break;
    }
  }

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

Measured memory_bytes: 3584
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <queue>
#include <string>
#include <map>
#include <set>
#include <stack>
#include <tuple>
#include <deque>
#include <numeric>
#include <bitset>
#include <iomanip>
#include <cassert>
#include <chrono>
#include <random>
#include <limits>
#include <iterator>
#include <functional>
#include <sstream>
#include <complex>
using namespace std;

typedef long long ll;
typedef uint64_t ull;
typedef pair<int, int> P;
constexpr double EPS = 1e-9;
constexpr int INF = 1001001001;
constexpr int mod = 1000000007;
// constexpr int mod = 998244353;

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

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

    int x, y;
    cin >> x >> y;
    if((y - x * 2) % 2 != 0){
        cout << "No\n";
        return 0;
    }
    int b = (y - x * 2) / 2;
    if(b < 0){
        cout << "No\n";
        return 0;
    }
    // cerr << b << endl;
    if((y - b * 4) % 2 != 0){
        cout << "No\n";
        return 0;
    }
    int a = (y - b * 4) / 2;
    if(a < 0){
        cout << "No\n";
        return 0;
    }
    cout << "Yes\n";
}

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

public class Main {

  public static void main(String[] args) throws Exception {
    try (final var stdin = new InputStreamReader(System.in);
         final var br = new BufferedReader(stdin)) {
      br.readLine();
      final var a = Arrays.stream(br.readLine().split(" "))
        .mapToLong(Long::parseLong)
        .toArray();

      var modulo = (long)Math.pow(10, 9) + 7L;
      var modulo2 = calcModulo2((long)Math.pow(10, 9) + 5L);

      var sum = 0L;
      for (int i = 0; i < a.length; i++) {
        sum = (sum + a[i]) % modulo;
      }
      sum = (sum * sum) % modulo;

      for (int i = 0; i < a.length; i++) {
        sum = (sum - (a[i] * a[i]) % modulo) % modulo;
        while (sum < 0) {
          sum = (sum + modulo) % modulo;
        }
      }

      sum = (sum * (modulo2 % modulo)) % modulo;

      System.out.println(sum);
    }
  }

  private static long calcModulo2(long target) {
    var modulo = (long)Math.pow(10, 9) + 7L;

    var current = 1;
    var answer = 2L;
    while (current <= target / 2) {
      answer = (answer * answer) % modulo;
      current = current * 2;
    }

    if (current < target) {
      return answer * calcModulo2(target - current) % modulo;
    } else {
      return answer;
    }
  }
}

Measured memory_bytes: 62980
//#define _GLIBCXX_DEBUG
#include<bits/stdc++.h>
//#include<cstdio>//"scanf("%lf",&(double型変数));printf("%f",(double型変数));"
//#include<iomanip>//"cout<<fixed<<setprecision(n)<<sth<<endl;"
//#include<string>//"reverse(s's it,s's it)"
//#include<functional>//"greater<T>" "sort(a,a+n,greater<int>());""
//#include<cmath>//"abs" "sqrt"
//#include<numeric>//"accumulate(inputit,inputit,init,(optional) object)"
//#include<algorithm>//"lower_bound(it,it,v)" "next_permutation(a,a+n)"
//"reverse(v's it,v's it)"(v: vector)
//#include<cassert>//"assert(cond);": error if cond doesn't hold.
using namespace std;
#define pb push_back//also for STRING
#define fi first
#define sc second
#define mp make_pair
#define is insert//also use as v.is(v's it,w's it,w's it);
#define ps push//TMP//stack,(priority) queue,
#define fr front//TMP//queue//for priority, use top().
typedef long long ll;//not necessarily
typedef pair<int,int> pii;
//Add other types in the same way.
const ll M=1000000007;//can be changed
int mod(int a){	return (a+M)%M;	}//M can be a variable
void plmod(ll &a,ll b){	a=(a+b+M)%M;	return;	}
void mnmod(ll &a,ll b){	a=(a-b+M)%M;	return;	}
void mlmod(ll &a,ll b){	a=(a*b)%M;  	return;	}
//Caution! you may need sth larger than "+M"!
void chmax(int &a,int b){	a=max(a,b);	return;	}
void chmin(int &a,int b){	a=min(a,b);	return;	}
//These 2 could be better in long long

vector<ll> divisor(ll n){//O(n^(1/2))
	vector<ll> ret,spare;
	for(ll i=1;i*i<=n;++i){
		if(!(n%i)){
			ret.pb(i);
			if(i*i!=n) spare.pb(n/i);
		}
	}
	for(int i=spare.size()-1;i>=0;--i){
		ret.pb(spare[i]);
	}
	return ret;
}

ll f(ll b,ll n){
	if(n<b) return n;
	else return f(b,n/b)+(n%b);
}

int main(){
	ll n,s;
	cin>>n>>s;
	if(n==s){
		printf("%lld\n",n+1);
		return 0;
	}else if(n<s){
		printf("-1\n");
		return 0;
	}
	ll m=sqrt(n);
	for(ll b=2;b<=m;++b) if(f(b,n)==s){
		printf("%lld\n",b);
		return 0;
	}
	vector<ll> v=divisor(n-s);
	for(int i=0;i<v.size();++i){
		ll b=v[i]+1;
		if(b<=m) continue;
		if(f(b,n)==s){
			printf("%lld\n",b);
			return 0;
		}
	}
	printf("-1\n");
	return 0;
}

Measured memory_bytes: 384
from bisect import bisect_left, bisect_right

N = int(input())

S = list(input())

Q = int(input())

memo = {chr(ord('a') + i): [] for i in range(26)}

for key,val in enumerate(S):
    memo[val].append(key)

for q in range(Q):
    query = list(input().split())
    if query[0] == '1':
        i, x = int(query[1])-1, query[2]
        now = S[i]
        if now == x:
            continue
        memo[now].remove(i)
        next_i = bisect_left(memo[x], i)
        memo[x].insert(next_i, i)
        S[i] = x
    else:
        start, end = int(query[1])-1, int(query[2])-1
        tmp_cout = 0
        for alf_array in memo.values():
            if len(alf_array) == 0:
                continue
            ss = bisect_left(alf_array, start)
            gg = bisect_right(alf_array, end)
            if gg- ss > 0:
                tmp_cout += 1
        print(tmp_cout)


Measured memory_bytes: 134228
fun main(args: Array<String>) {
    val (N, M) = listOfInt()
    val PS = mutableListOf<Pair<Int, String>>()
    repeat(M) {
        val (p, s) = listOfString()
        PS.add(p.toInt() - 1 to s)
    }
    val AC = IntArray(N)
    val WA = IntArray(N)
    PS.forEach { ps ->
        val p = ps.first
        val s = ps.second
        if (AC[p] == 0) {
            if (s == "AC") AC[p] = 1
            else if (s == "WA") WA[p] += 1
        }
    }
    AC.forEachIndexed { index, ac -> if (ac == 0) WA[index] = 0 }
    println("${AC.sum()} ${WA.sum()}")
}
fun next() = readLine()!!
fun listOfString() = next().split(" ")
fun listOfInt(delta: Int = 0) = listOfString().map { Integer.parseInt(it) + delta }


Measured memory_bytes: 64884
#include <iostream>
#include <cstdlib>
#include <vector>
#include <algorithm>
#include <numeric>
using namespace std;
typedef long long unsigned int ll;
#define INF (1e9)

int main(){
    
    ll N;
    cin>>N;
    vector<ll> a(N);
    vector<ll> b(N);
    vector<ll> c(N);    
    for(ll i=0;i<N;i++){
        cin>>a[i]>>b[i]>>c[i];}
    
    vector<vector<ll>> dp(N,vector<ll>(3));
    
    dp[0][0]=a[0];
    dp[0][1]=b[0];
    dp[0][2]=c[0];
    
    for(ll i=1;i<N;i++){
        dp[i][0]=max(dp[i-1][1]+a[i],dp[i-1][2]+a[i]);
        dp[i][1]=max(dp[i-1][0]+b[i],dp[i-1][2]+b[i]);
        dp[i][2]=max(dp[i-1][0]+c[i],dp[i-1][1]+c[i]);
        //cout<<dp[i][0]<<","<<dp[i][1]<<","<<dp[i][2]<<","<<endl;
    }
    
    ll ans=*max_element(dp[N-1].begin(),dp[N-1].end());
        
    cout<<ans<<endl;
            
    return 0;}

Measured memory_bytes: 8064
function prime(max){
   var arr=[];
   for(var i=0;i<=max;i++)arr[i]=i;
   arr[0]=false;
   arr[1]=false;
   var sqrt=Math.floor(Math.sqrt(max));
   for(var i=2;i<=sqrt;i++){
      if(arr[i]==false)continue;
         for(var j=i+i;j<=max;j+=i){
            arr[j]=false;
         }
   }
   var result=[];
   for(var i=0;i<=max;i++){
      if(arr[i]!==false)result.push(arr[i]);
   }
   return result;
}
var p=prime(123456*2);

var input = require('fs').readFileSync('/dev/stdin', 'utf8');
var Arr=(input.trim()).split("\n").map(Number);
for(var I=0;I<Arr.length;I++){
   var v=Arr[I];
   if(v==0)break;
   var cnt=0;
   for(var i=0;i<p.length;i++){
      if(p[i]>v*2)break;
      if(p[i]>v)cnt++;
   }
   console.log(cnt);
}

Measured memory_bytes: 16780
#include <stdio.h>
 int main(void)
 {
     int H ,W;
     int i, j;
     while(1){
         scanf("%d %d" ,&H ,&W);
         if(H == 0 && W == 0) break;
         for ( i = 0; i < H; i++ ){
             for ( j = 0; j < W; j++ ){
                 if(j==0||j==W-1||i==0||i==H-1){
                     printf("#");
                     
                 }else{                    
                     printf("#");
                 }
             }
             printf("\n");
        }
         puts("");
        }
     return 0;
     }


Measured memory_bytes: 2052
#include <iostream>
#include <iomanip>
#include <string>
#include <vector>
#include <algorithm>
#include <numeric>
#include <utility>
#include <sys/time.h>
#include <cmath>
#include <tuple>
#include <queue>
#include <bitset>

using namespace std;

void solve(int N, vector<int> a) {
    vector<int> ret;
    bool is_even_m2 = true;
    bool exist_m1 = false;
    int head_m1;
    int tail_m2;
    for (int i = 0; i < N; i++) {
        if (a[i] == -1) {
            if (exist_m1 == false) {
                head_m1 = i;
            }
            exist_m1 = true;
        } else if (a[i] == -2) {
            is_even_m2 = !is_even_m2;
            tail_m2 = i;
        }
    }
    for (int i = 0; i < N; i++) {
        if (a[i] == 2) {
            ret.push_back(i);
        } else if(a[i] == -1) {
            if ((i == head_m1)&&(!is_even_m2)) {
                ret.push_back(i);
            }
        } else if(a[i] == -2) {
            if (is_even_m2 || exist_m1) {
                ret.push_back(i);
            } else {
                if (i != tail_m2) {
                    ret.push_back(i);
                }
            }
        }
    }

    std::cout << ret.size() << std::endl;
    for (int i = 0; i < ret.size(); i++) {
        std::cout << ret[i] + 1 << std::endl;
    }
}

int main() {
    int N;

    std::cin >> N;
    vector<int> a(N);
    for (int i = 0; i < N; i++) {
        std::cin >> a[i];
    }
    solve(N, a);

    return 0;
}



Measured memory_bytes: 3160
'use strict'

function main(input){
  const lines = input.split('\n');
  const ABCDEF = lines.shift().split(' ').map(x => parseInt(x));
  const A = ABCDEF[0];
  const B = ABCDEF[1];

  const C = ABCDEF[2];
  const D = ABCDEF[3];

  const E = ABCDEF[4];
  const F = ABCDEF[5];

  let water = [];
  let sugers = [];
  for(var i=0;i<=F;i++){
    for(var j=0;j<=F;j++){
      let c_water = 100*(A*i+B*j);
      if(c_water<=F){ water.push(c_water); }

      let suger = C*i + D*j;
      if(suger<=F){ sugers.push(suger); }
    }
  }


//--------------

  var waterTotal = []; // とりうる水の量
  var sugarTotal = []; // とりうる砂糖の量
  
  var sugarWater = []; // とりうる砂糖水の量
  var sugarWeight = []; // とりうる砂糖の量  // とりうる砂糖水と砂糖の量を列挙

  // とりうる水と砂糖の量を列挙
  for(var i = 0; i <= F; i++){
    for(var j = 0; j <= F; j++){
      var water2 = ((A * i) + (B * j)) * 100; // 水の量
      if(water2 <= F ) waterTotal.push(water2); 
  
      var sugar = (C * i + D * j); // 砂糖の量
      if(sugar <= F) sugarTotal.push(sugar);
    }
  }  
  
  // とりうる砂糖水と砂糖の量を列挙
  for(var i = 0; i <= F; i++){
    for(var j = 0; j <= F; j++){
      var sw = waterTotal[i] + sugarTotal[j]; // 砂糖水の量
      var meltSugar = 100 * sugarTotal[j] / waterTotal[i]; // 水に溶ける砂糖の量
      if( sw <= F && meltSugar <= E){
        sugarWater.push(sw); 
        sugarWeight.push(sugarTotal[j]);
      }
    }
  }  
  // 各砂糖水と砂糖の量から、濃度を求める
  var noudo = 0;
  var noudoIndex = 0;
  for(var i = 0; i < sugarWater.length; i++){
    var noudoTmp = (100 * sugarWeight[i]) / sugarWater[i]; // 砂糖水の濃度
    if(noudoTmp > noudo){
      noudo = noudoTmp;
      noudoIndex = i;
    }
  }
  
  console.log(sugarWater[noudoIndex] + ' ' + sugarWeight[noudoIndex]);

return;
//--------------

  let results = [];
  for(let i=0;i<water.length;i++){
    for(let j=0;j<sugers.length;j++){      let total = water[i] + sugers[j];
      let melt_suger = 100*sugers[j]/water[i];

      if( (total <= F) && (melt_suger <= E) ){
        results.push([water[i], sugers[j]]);
      }
    }
  }

  let tmp_density = 0.0;
  let result = [];
  for(var i=0;i<results.length;i++){
      let current_density = (100*results[i][1])/(results[i][0]+results[i][1]);
      if(current_density > tmp_density){ 
        tmp_density = current_density;
        result = results[i];
      }
  }

//console.log(result);
  console.log((result[0] + result[1])+' '+result[1]);
}
main( require('fs').readFileSync( '/dev/stdin', 'utf8') );


Measured memory_bytes: 20940
/*
██████╗  ███████╗  
██╔══██╗ ██╔════╝ 
██████╔╝ ███████╗ 
██╔══██╗ ╚════██║  
██║  ██║ ███████║      
╚═╝  ╚═╝ ╚══════╝                                                                                                             
*/

#include<bits/stdc++.h>
using namespace std;
 
#define ll long long int
#define rep(i,n) for(int i=0;i<n;i++)
#define rev(i,n) for(int i=n-1;i>=0;i--)
#define haha(j,a,n) for(int j=a;j<n;j++)
#define Max(x,y,z) max(x,max(y,z))
#define Min(x,y,z) min(x,min(y,z))
#define endl "\n"
#define bc(v) v.begin(),v.end()
#define vl vector<ll>
#define vi vector<int>
#define why 1000000007
#define NUM 100005
#define F first
#define S second
#define bhar(a) rep(i,a.size()) cin>>a[i];
#define show(a) rep(i,a.size()) cout<<a[i]<<" ";
#define sott(a) sort(bc(a))
#define mp(a,b) make_pair(a,b)
#define pb push_back
#define mapp map<ll,ll>
#define dkac cout<<fixed<<setprecision(15);
#define ios ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define yeah(n) while(n--)
ll gcd(int a, int b){if(b==0) return a; else return gcd(b,a%b);}
ll bitfun(ll x){
  return (x&(-x));
}
void solve(){
  ll n,m; cin>>n>>m;
  ll sm=0;
  rep(i,m){
    ll x; cin>>x;
    sm+=x;
  }
  cout<<max(n-sm,-1LL);
}
int main(){
    ios
    int t=1; 
    //cin>>t;
    yeah(t){
      solve();
    }
}

Measured memory_bytes: 3636
from collections import Counter

n = int(input())
a = list(map(int, input().split()))

mc = Counter(a).most_common()
ln = len(mc)

def detect():
    if ln == 1 and mc[0][0] == 0:
        return True
    elif ln == 2 and mc[1][0] == 0 and mc[1][1] == n // 3:
        return True
    elif ln == 3 and mc[0][0] ^ mc[1][0] ^ mc[2][0] == 0 and mc[0][1] == mc[1][1] == mc[2][1]:
        return True
    return False

print("Yes" if detect() else "No")


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

int main() {
  int n;
  ll x;
  cin >> n >> x;
  ll a[n];
  rep(i, n) cin >> a[i];
  
  // int sum[n-1];
  // rep(i, n-1) sum[i] = a[i] + a[i+1];
  ll b[n];
  rep(i, n) b[i] = a[i];
  
  ll res = 0;
  rep(i, n-1){
    if(b[i] + a[i+1] > x){
      ll dif = (b[i] + a[i+1] - x);
      if(dif > a[i+1]){
        b[i] -= (dif - a[i+1]);
        b[i+1] = 0;
      }else{
        b[i+1] -= dif;
      }
    }
  }

  rep(i, n){
    res += (a[i] - b[i]);
  }
  
  cout << res << endl;
  
  return 0;
}

Measured memory_bytes: 1792
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int a, b;
  cin >> a >> b;
  
  double a_min = ceil(a / 0.08);
  double a_max = ceil((a + 1) / 0.08) - 1;
  
  double b_min = ceil(b / 0.10);
  double b_max = ceil((b + 1) / 0.10) - 1;
  
  if(a_min > b_max || b_min > a_max){
    // どちらかの範囲の最小値がもう片方の最大値より大きい
    cout << -1 << endl;
    return 0;
  }
  
  cout << max(a_min, b_min) << endl;
  
  return 0;
  
}

Measured memory_bytes: 256
#include <iostream>
#include <cassert>
#include <cctype>
#include <cerrno>
#include <cfloat>
#include <ciso646>
#include <climits>
#include <clocale>
#include <cmath>
#include <csetjmp>
#include <csignal>
#include <cstdarg>
#include <cstddef>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <ccomplex>
#include <cfenv>
#include <cinttypes>
#include <cstdbool>
#include <cstdint>
#include <ctgmath>
#include <cwchar>
#include <cwctype>
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>
#include <array>
#include <atomic>
#include <chrono>
#include <condition_variable>
#include <forward_list>
#include <future>
#include <initializer_list>
#include <mutex>
#include <random>
#include <ratio>
#include <regex>
#include <system_error>
#include <thread>
#include <tuple>
#include <typeindex>
#include <type_traits>
#include <unordered_map>
#include <unordered_set>
using namespace std;
int main(void)
{
	int a, b, c;
	cin >> a >> b >> c;
	if (b - a + 2 <= c * 2)
	{
		for (int i = a; i <= b; i++)
		{
			cout << i << "\n";
		}
	}
	else {
		for (int i = a; i < a + c; i++)
		{
			cout << i << "\n";
		}
		for (int i = b-c+1; i <= b; i++)
		{
			cout << i << "\n";
		}
	}
}


Measured memory_bytes: 384
#include<iostream>
#include<algorithm>
#include<vector>
#include<queue>
#define lol(i,n) for(int i=0;i<n;i++)
#define mod 1000000007
typedef long long ll;

using namespace std;
#define N (1<<17)
class RSQ{
private:
    ll dat[2*N];
    ll dfs(int l,int r,int a,int b,int k){
	if(l<=a&&b<=r)return dat[k];
	if(b<=l||r<=a)return 0;
	ll vl=dfs(l,r,a,(a+b)/2,k*2+1);
	ll vr=dfs(l,r,(a+b)/2,b,k*2+2);
	return (vl+vr)%mod;
    }
public:
    void Init(){
	lol(i,2*N)dat[i]=0;
    }
    void Upd(int i,ll x){
	i+=N-1,dat[i]=x%mod;
	while(i>0){
	    i=(i-1)/2;
	    dat[i]=(dat[i*2+1]+dat[i*2+2])%mod;
	}
    }
    void Add(int i,ll x){
	Upd(i,(Sum(i,i)+x)%mod);
    }
    ll Sum(int l,int r){
	return dfs(l,r+1,0,N,0)%mod;
    }
};
ll n,m,x[N],y[N];
vector<pair<ll,ll> >v;
void Zaats(){
    vector<ll> w;
    lol(i,v.size())v[i].second*=-1;
    for(auto i:v)w.push_back(i.second);
    sort(w.begin(),w.end());
    lol(i,v.size()){
	v[i].second=lower_bound(w.begin(),w.end(),v[i].second)-w.begin();
	v[i].second++;
    }
}
int main(){
    cin>>n>>m;
    lol(i,n)cin>>x[i];
    lol(i,m)cin>>y[i];
    lol(i,n){
	if(x[i]<y[0]||x[i]>y[m-1])continue;
	auto it=lower_bound(y,y+m,x[i]);
	ll r=*it-x[i];
	it--;
	ll l=x[i]-*it;
	v.push_back(make_pair(l,-r));
    }
    sort(v.begin(),v.end());
    Zaats();
    RSQ seg;seg.Init();
    seg.Add(0,1);
    pair<ll,ll> bef=make_pair(-1,-1);
    lol(i,v.size()){
	if(v[i]==bef)continue;
	bef=v[i];
	ll t=v[i].second;
	seg.Add(t,seg.Sum(0,t-1));
    }
    cout<<seg.Sum(0,N-1)<<endl;
    return 0;
}


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

b = [] + a
ans = sum(a)
temp = [0 for _ in range(n)]
for i in range(1, n):
    r = a[n - i:] + a[:n - i]
    for j in range(n):
        temp[j] = min(b[j], r[j])
    ans = min(ans, sum(temp) + i * x)
    b = [] + temp

print(ans)

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

void connect(int x, vector<vector<int>> &road) {
  if (road.at(x).at(0) == -1)
    return;
  
  else {
    road.at(x).at(0) = -1;
    int y = road.at(x).size() - 1;
    
    for (int j = 0; j < y; j++) {
      connect(road.at(x).at(j + 1), road);
    }
  }
}

int main() {
  int n, m;
  cin >> n >> m;
  
  vector<vector<int>> road(n + 1, vector<int>(1, 1));
  
  for (int i = 0; i < m; i++) {
    int a, b;
    cin >> a >> b;
    
    road.at(a).push_back(b);
    road.at(b).push_back(a);
    
    road.at(a).at(0) = 0;
    road.at(b).at(0) = 0;
  }
  
  int count = 0;
  
  for (int i = 1; i < n + 1; i++) {
    if (road.at(i).at(0) == 0) {
      connect(i, road);
      count++;
    }
    else if (road.at(i).at(0) == 1)
      count++;
  }
  
  cout << count - 1 << endl;
}


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

int main(){
    string str;
    cin >> str;
    int n = str.size();
    int count=0,color=0,max=0;
    int children[n],c[n];
    int childs[n];
    int base;
    for(int i=0;i<n;i++) childs[i]=0;
    for(int i=0;i<n;i++){
        
        if(str[i]=='R') c[i] =0;
        else c[i] =1;

        if(c[i] == color){
            count+=1; 
        }else{
            if(color==0){
                int _c = count/2;
                int c_ = count/2;
                if(count%2==1)c_ += 1;
                childs[i-1]+=c_;
                childs[i]+=_c;
                base = i;
                color=1;
            }else{
                int _c = count/2;
                int c_ = count/2;
                if(count%2==1)c_ += 1;
                childs[base] += c_;
                childs[base-1] += _c;
                //base = i+1;
                color=0;
            }
            count = 1;
            //color = c[i];
        } 
    }
    int _c = count/2;
                int c_ = count/2;
                if(count%2==1)c_ += 1;
                childs[base] += c_;
                childs[base-1] += _c;


    for(int i=0;i<n;i++) cout << childs[i] << " ";

    cout << endl;
    return 0;

}

Measured memory_bytes: 1408
import sys
def input():
    return sys.stdin.readline()[:-1]
n=int(input())
uvw=[list(map(int,input().split())) for i in range(n-1)]
class WeightedUnionFind:
    def __init__(self, n):
        self.par = [i for i in range(n+1)]
        self.rank = [0] * (n+1)
        self.weight = [0] * (n+1)


    def find(self, x):
        if self.par[x] == x:
            return x
        else:
            y = self.find(self.par[x])
            self.weight[x] += self.weight[self.par[x]]
            self.par[x] = y
            return y

    def union(self, x, y, w):
        rx = self.find(x)
        ry = self.find(y)
        if self.rank[rx] < self.rank[ry]:
            self.par[rx] = ry
            self.weight[rx] = w - self.weight[x] + self.weight[y]
        else:
            self.par[ry] = rx
            self.weight[ry] = -w - self.weight[y] + self.weight[x]
            if self.rank[rx] == self.rank[ry]:
                self.rank[rx] += 1

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

    def diff(self, x, y):
        return self.weight[x] - self.weight[y]
uf=WeightedUnionFind(n)
for i in range(n-1):
    uf.union(uvw[i][0],uvw[i][1],uvw[i][2])

for i in range(n):
    if uf.diff(i+1,uf.find(i+1))%2==0:
        print(0)
    else:
        print(1)

Measured memory_bytes: 95196
import Data.Char

main = do
  ss <- getLine
  let x = func ss
  print (minimum x)

func :: String -> [Int]
func [a, b, c] = [abs (753 - ((digitToInt a * 100) + (digitToInt b * 10) + digitToInt c))]
func (a:b:c:xs) = abs (753 -  ((digitToInt a * 100) + (digitToInt b * 10) + digitToInt c)) : func (b:c:xs)


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

int A[200005];
map<ll, ll> M;

int main() {
    int n;
    ll k,diff,z;
    cin >> n >> k;
    for (int i=1;i<=n;i++) {
        cin >> A[i];
    }
    ll i=1,pos=1;
//    cout << "AAA " << i << " " << pos << endl;
    while(i<=k) {
        if (M.count(pos)>0) {
            diff=i-M[pos];
            z=(k-i)/diff;
            k-=z*diff;
//            k%=diff;
        }
        M[pos]=i;
        i++;
        pos=A[pos];
//        cout << "AAA " << i << " " << pos << endl;
    }
    cout << pos;
}


Measured memory_bytes: 14364
#include<stdio.h>
#include<string.h>
#include<time.h>
#include<math.h>
#include<stdlib.h>
#include<iostream>
#include<iomanip>
#include<utility>
#include<algorithm>
#include<stack>
#include<queue>
#include<map>
#include<set>
#define ll long long
#define fi first
#define sec second
#define mp make_pair
#define pb push_back
#define rep(a,b,c) for(int a=1;a<=b;a+=c)
#define repp(a,b,c,d) for(int a=b;a<=c;a+=d)

const double PI=acos(-1);
const double EPS=1e-12;
const ll MOD=1e9+7;
const ll INF=1<<30;


using namespace std;

int main(){
	int in,len;
	char c;
	string str;
	map<string,bool>m;
	cin>>in;
	bool fl=true;
	rep(i,in,1){
		cin>>str;
		if(i!=1&&str[0]!=c){
			fl=false;
			break;
		}
		if(m[str]){
			fl=false;
			break;
		}
		m[str]=true;
		len=str.length();
		c=str[len-1];
	}
	if(!fl)cout<<"No\n";
	else cout<<"Yes\n";
	return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;
import java.nio.*;

class Queue{
    private String name;
    private int time;

    public Queue(String name, int time){
        this.name = name;
        this.time = time;
    }

    public String getName(){
        return name;
    }

    public int getTime(){
        return time;
    }
}

class MyQueue{
    private Queue[] queue;
    private int head = 0;
    private int tail = 0;
    
    public MyQueue(int size){
        queue = new Queue[size + 1];
    }

    public boolean isEmpty(){
        return head == tail;
    }

    public boolean isFull(){
        return head == (tail + 1) % queue.length;
    }

    public void enqueue(String name, int time) throws Exception{
        if(isFull()){
            throw new Exception();
        }

        queue[tail] = new Queue(name, time);

        if(tail + 1 == queue.length){
            tail = 0;
        }else{
            tail++;
        }
    }

    public Queue dequeue() throws Exception{
        if(isEmpty()){
            throw new Exception();
        }
        Queue x = queue[head];
        if(head + 1 == queue.length){
            head = 0;
        }else{
            head++;
        }
        return x;
    }

    public int min(int a, int b){
        return a < b ? a : b;
    }
}

public class Main{
        public static void main(String[] args) throws Exception{
        Scanner sc = new Scanner(System.in);

        int n = sc.nextInt();
        int q = sc.nextInt();

        MyQueue queue = new MyQueue(n);

        String name;
        int time;
        for(int i = 0; i < n; i++){
            name = sc.next();
            time = sc.nextInt();
            queue.enqueue(name, time);
        }
        
        int sum = 0;
        while(!queue.isEmpty()){
            Queue q1 = queue.dequeue();
            if(q1.getTime() > q){
                sum += q;
                queue.enqueue(q1.getName(), q1.getTime() - q);
            }else{
                sum += q1.getTime();
                System.out.println(q1.getName() + " " + sum);
            }
        }
    }
}




Measured memory_bytes: 76076
#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0;i<n;i++)
#define rep2(i,a,n) for(int i=a;i<n;i++)
#define been(ix) (ix).begin(),(ix).end()
using namespace std;
typedef long long ll; 
typedef vector<int> vi;
typedef vector<long long> vl;
const ll INFL = 1e18;
const int INF = 1001001001; 
typedef pair<int,int> P;
#define foreach(ix,i) for(auto& (ix) : (i))
typedef long double ld;
const int mod =1000000007;
const double PI = acos(-1);
vector<P> edge[100005];
vl seen(100005,INFL);
int main(){
	int n;cin>>n;
    vl a(n);
    rep(i,n)cin>>a[i];
    multiset<ll> col;
    rep(i,n){
        a[i]*=-1;
        auto it =col.upper_bound(a[i]);
        if(it!=col.end())col.erase(it);
        col.insert(a[i]);
    }
    cout<<col.size()<<endl;
}

Measured memory_bytes: 11900
import sys
input = sys.stdin.buffer.readline
import heapq

def main():
	N = int(input())
	edge = [[] for _ in range(N)]
	for _ in range(N-1):
		a,b,d = map(int,input().split())
		edge[a-1].append((b-1,d))
		edge[b-1].append((a-1,d))
	
	Q,K = map(int,input().split())
	dist = [-1]*N
	dist[(K-1)] = 0
	q = [(0,K-1)]
	heapq.heapify(q)
	while q:
		_,now = heapq.heappop(q)
		for fol,d in edge[now]:
			if dist[fol] == -1:
				dist[fol] = dist[now]+d
				heapq.heappush(q,(dist[fol],fol))
	
	for _ in range(Q):
		a,b = map(int,input().split())
		print(dist[a-1]+dist[b-1])
	
if __name__ == "__main__":
	main()


Measured memory_bytes: 75952
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(n);++i)
#define rrep(i,n) for(int i=1;i<(n);++i)
#define all(a) (a).begin(),(a).end()
#define rall(a) (a).rbegin(),(a).rend()
#define maxs(a, b) a = max(a, b)
#define mins(a, b) a = min(a, b)
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
const ll linf = (1LL << 61);
const int inf = 1001001001;
const int mod = 1000000007;

int main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	string s;
	cin >> s;
	rep(bit, (1 << 3)) {
		int tmp = 0;
		rep(i, 4) {
			int t = s[i] - '0';
			if (i == 0) {
				tmp += t;
				continue;
			}
			if (bit & (1 << (i - 1))) tmp += t;
			else tmp -= t;
		}
		if (tmp == 7) {
			rep(i, 4) {
				if (i == 0) cout << s[i];
				else {
					if (bit & (1 << (i - 1))) cout << '+';
					else cout << '-';
					cout << s[i];
				}
			}
			cout << '=' << 7 << endl;
			return 0;
		}
	}
	return 0;
}

Measured memory_bytes: 256
#include<iostream>
using namespace std;
int K;
int main(){
  cin>>K;
  int a[32] = {1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51};
  cout<< a[K-1] << endl;
}

Measured memory_bytes: 256
#include<iostream>
#define l int64_t
#define c continue;
#define o(a) cout<<a<<" ";
#define r(i,x,y) for(l i=x;i<y;i++){
using namespace std;
int main(){l m=1e9+7,a=93,x,y,z,w,o,p,v[a],t[a][a][2],b;v[0]=1,v[1]=1;r(i,2,a)v[i]=v[i-1]+v[i-2];}r(i,2,a)r(j,1,i)b=v[i+1];if(j<2){t[i][0][0]=v[i],t[i][0][1]=b,t[i][j][0]=b,t[i][j][1]=2*b-v[i];c}t[i][j][0]=t[i-1][j-1][1],t[i][j][1]=t[i-1][j-1][1]+t[i-1][j-1][0];}}cin>>b;while(b--){cin>>x>>y;if(x>y)swap(x,y);if(y<2){o(1)o(1)c}r(i,0,a)if(v[i]>x||v[i+1]>y){z=i-1,o(z)break;}}if(z<2){o(x*y%m)c}w=0;r(j,0,z)o=t[z][j][0],p=t[z][j][1];if(o>x||p>y)c w+=(y-p)/o+1;if(x>=p)w+=(x-p)/o+1;}o(w%m)}}

Measured memory_bytes: 4468
#include<bits/stdc++.h>
using namespace std;
#define int long long 
#define ii pair <int, int>
#define app push_back
#define all(a) a.begin(), a.end()
#define bp __builtin_popcount
#define ll long long
#define mp make_pair
#define f first
#define s second
#define lb lower_bound
#define ub upper_bound
#define Time (double)clock()/CLOCKS_PER_SEC
const int N = 1e5 + 7;
vector <int> g[N];
bool used[N], col[N];
vector <int> comp;
void dfs(int u) {
    comp.app(u);
    used[u] = 1;
    for (int v : g[u]) {
        if (!used[v]) {
            col[v] = col[u] ^ 1;
            dfs(v);
        }   
    }   
}   
int cnt[3];
signed main() {
    #ifdef HOME
    freopen("input.txt", "r", stdin);
    #else
    ios_base::sync_with_stdio(0); cin.tie(0);
    #endif
    int n, m;
    cin >> n >> m;
    while (m--) {
        int u, v; cin >> u >> v;
        g[u].app(v); g[v].app(u);
    }   
    int t = 0;
    for (int i = 1; i <= n; ++i) {
        if (g[i].empty()) {
            ++t;
            continue;
        }   
        if (!used[i]) {
            comp.clear();
            dfs(i);
            bool b = 1;
            for (int u : comp) {
                for (int v : g[u]) {
                    b &= col[u] != col[v];
                }   
            }   
            ++cnt[b];
        }   
    }
    cout << (cnt[0] + cnt[1]) * (cnt[0] + cnt[1]) + cnt[1] * cnt[1] + t * n + (n - t) * t << '\n';
}

Measured memory_bytes: 12796
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define ll long long
#define P pair<int,int>
#define fi first
#define se second
#define rep(i,n) for(int i=0;i<n;i++)
#define INF 1000000000
#define MOD 1000000007
#define all(v) v.begin(),v.end()
#define pb push_back
int dx[]={0,1,0,-1},dy[]={1,0,-1,0};
int kaijo[200010];
struct edge{int to,cost;};
int gcd(int a,int b){
	if(b==0)return a;
	return gcd(b,a%b);
}
int lcm(int a,int b){
	return a/gcd(a,b)*b;
}
bool prime(int a){
	if(a==1)return false;
	for(int i=2;i*i<=a;i++){
		if(a%i==0)return false;
	}
	return true;
}
bool kosa(double ax,double ay,double bx,double by,double cx,double cy,double dx,double dy){//線分の交差判定
	double ta=(cx-dx)*(ay-cy)+(cy-dy)*(cx-ax);
	double tb=(cx-dx)*(by-cy)+(cy-dy)*(cx-bx);
	double tc=(ax-bx)*(cy-ay)+(ay-by)*(ax-cx);
	double td=(ax-bx)*(dy-ay)+(ay-by)*(ax-dx);
	return tc*td<0&&ta*tb<0;
}
void init_fact(int n){
	kaijo[0]=1;
	for(int i=1;i<=n;i++){
		kaijo[i]=kaijo[i-1]*i;
		kaijo[i]%=MOD;
	}
}
int modpow(int a,int b){
	if(b==0)return 1;
	if(b%2)return modpow(a,b-1)*a%MOD;
	int memo=modpow(a,b/2);
	return memo*memo%MOD;
}
int comb(int a,int b){
	if(b>a)return 0;
	if(a==b)return 1;
	return kaijo[a]*modpow(kaijo[a-b],MOD-2)%MOD*modpow(kaijo[b],MOD-2)%MOD;
}
int g(int x){
	x=modpow(x,MOD-2);
	return x;
}
int n,p[100010],b[100010],ans;
set<int>st;
signed main(){
	cin>>n;
	rep(i,n){
		cin>>p[i];
		b[p[i]]=i;
	}
	st.insert(b[n]);
	for(int i=n-1;i>=1;i--){
		auto itr1=st.lower_bound(b[i]);
		auto itr2=st.lower_bound(b[i]);
		int A=0,B=0,C=0,D=0,E=0;
		C=b[i];
		if(itr1!=st.end()){
			D=*itr1;
			itr1++;
			if(itr1!=st.end()){
				E=*itr1;
			}
			else{
				E=n;
			}
		}
		else{
			D=n;
			E=n;
		}
		if(itr2==st.begin()){
			B=-1;
			A=-1;
		}
		else{
			itr2--;
			B=*itr2;
			if(itr2==st.begin())A=-1;
			else{
				itr2--;
				A=*itr2;
			}
		}
		ans+=i*((B-A)*(D-C)+(C-B)*(E-D));
		st.insert(b[i]);
		
	}
	cout<<ans<<endl;
	return 0;
}


Measured memory_bytes: 6528
using System;

class Program
{
   static void Main(string[] args)
   {
      string input = Console.ReadLine();
      string str;
      string l = input.Substring(input.Length - 1);
      string f = input.Substring(0,1);

      Console.WriteLine(f + (input.Length - 2) + l);
      int i = 0;
   }
}


Measured memory_bytes: 11092
// D.

#include <iostream>
#include <sstream>
#include <vector>
#include <numeric>
#include <algorithm>

using namespace std;

vector< vector<int> > x, y;
vector<int> color;
vector<int> order;

void dfs(int a) {
	color[a] = 1;
	for (int b : x[a]) {
		if (color[b] != 2) {
			dfs(b);
		}
	}
	color[a] = 2;
	order.push_back(a);
}

int main(int argc, char *argv[]) {
	int n, m;
	cin >> n >> m;
	x.resize(n);
	y.resize(n);
	color.resize(n);
	for (int i = 0; i < n + m - 1; ++i) {
		int a, b;
		cin >> a >> b;
		x[a - 1].push_back(b - 1);
		y[b - 1].push_back(a - 1);
	}
	int r;
	for (r = 0; r < n; ++r) {
		if (y[r].empty()) {
			break;
		}
	}
	dfs(r);
	vector<int> w(n);
	for (int i = 0; i < n; ++i) {
		w[order[i]] = i;
	}
	for (int i = 0; i < n; ++i) {
		int p = r;
		for (int a : y[i]) {
			if (w[a] < w[p]) {
				p = a;
			}
		}
		cout << (i == r ? 0 : (p + 1)) << endl;
	}
	return 0;
}


Measured memory_bytes: 17788
#include <stdio.h>
#include <iostream>
#include <vector>
#include <algorithm>
#include <iterator>
#include <string>
#include <cmath>
#include <set>
#include <stack>
#include <queue>
#include <numeric>
#include <deque>
#include <cstring>
#include <iterator>
#include <map>
#include <cstdlib>
#include <unordered_map>
#include <unordered_set>
#include <iomanip>
#include <complex>
#include <bitset>
#include <chrono>
#include <random>
using namespace std;

#define pb push_back
#define fi first
#define se second
#define all(x) (x).begin(),(x).end()
#define eb emplace_back
#define el '\n'
typedef  long long  ll;
typedef pair<ll, ll> pll;
typedef pair<int, int> pii;
typedef vector<ll> vll;
typedef vector<int> vi;
typedef vector<pii> vpi;
typedef vector<pll> vpll;
typedef vector<vi> vvi;
typedef vector<vll> vvll;
typedef vector<bool> vb;


const int mod=1000000007;
//const int mod=998244353;

vvll dp;
vll v,vv;
int n;
ll recur(int i, int j){
    if(i<1||j>n||i>j){
        return 0;
    }
    if(dp[i][j]==1e18){
        if(i==j){
            return dp[i][i]=0;
        }
        if(j==i+1){
            return dp[i][j]=v[i]+v[j];
        }
        for(int p=i; p<j; p++){
            dp[i][j]=min(dp[i][j],recur(i,p)+recur(p+1,j)+vv[j]-vv[i-1]);
        }
        return dp[i][j];
    }
    return dp[i][j];
}



int main()
{   ios_base::sync_with_stdio(false);cin.tie(NULL);
    ll t,m,k,q,x,a,b,c,d,y,l,r;
    cin >> n;
    dp.resize(n+1,vll(n+1,1e18));
    v.resize(n+1);
    for(int i=1; i<=n; i++)
        cin >> v[i];
    vv=v;
    for(int i=1; i<=n; i++){
        vv[i]+=vv[i-1];
    }
    cout << recur(1,n) << el;
    
    return 0;
}


Measured memory_bytes: 1536