akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <algorithm>
#include <cstdio>
#include <vector>
#include <cmath>
#include <iomanip>
#include <bitset>
#include <string>
#include <stdlib.h>
using namespace std;
//cout <<  << endl;
typedef long long int ll;
typedef long double ld;

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

#define MAX_N 1000
#define MAX_M 100

const long long INF = 1LL << 60;

//境界値に注意！！！

// DP テーブル
ll dp[100010];

int main() {
    ll n;
    long double ans=0;
    cin >> n;
    for (ll i=0;i<n;++i){
        long double x;
        cin >> x;
        ans+=1/x;
    }
    cout << setprecision(20) << 1/ans << endl;
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>

using namespace std;
const int maxn = 300000;
int n;
char s[maxn+1];
int a,b,c,d;

bool jump(int x)
{
	return (s[x]=='.' and x!=a and x!=b);
}

bool check2conse(int x,int y)
{
	for (int i=x; i<y; i++)
	if (s[i]=='#' and s[i+1]=='#')
		return false;
	return true;
}

bool check3conse(int x,int y)
{
	for (int i=x; i+2<=y; i++)
	if (s[i]=='.' and s[i+1]=='.' and s[i+2]=='.')
		return true;
	return false;
}

int main()
{ 
	ios_base::sync_with_stdio(0);
	//freopen("input.txt","r",stdin);
	//freopen("output.txt","w",stdout);
	cin >> n >> a >> b >> c >> d;
	for (int i=1; i<=n; i++)
		cin >> s[i];
	
	// a c b d
	if (a<=c and c<=b and b<=d)
	{
		if (!check2conse(a,c) or !check2conse(b,d))
			cout << "No";
		else
			cout << "Yes";
	}
	else
	// a b c d
	if (a<=b and b<=c and c<=d)
	{
		if (check2conse(b,d) and check2conse(a,c))
			cout << "Yes";
		else
		if (!check2conse(b,d) or !check2conse(a,c))
			cout << "No";
	}
	// a b d c
	else
	{
		if (check2conse(a,c) and check2conse(b,d) and check3conse(b-1,d+1))
			cout << "Yes";
		else
			cout << "No";
	}
	return 0;
}


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

  int main()
  {
  long  int x;
    cin>>x;
    int a,b;
    for(a=-118;a<=119;a++)
      for( b=-118;b<=119;b++)
         if(pow(a,5)-pow(b,5)== x) 
         return cout<<a<<" "<<b,0;
   
    return 0;
  }


Measured memory_bytes: 4080
l = [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]
k = int(input())

print(l[k-1])

Measured memory_bytes: 3060
#include<iostream>
#include<string>
#include<vector>
#include<math.h>
#include<algorithm>
#include<cstdio>
#include<stdio.h>
#include<stack>
#include<sstream>
#include<iomanip>
#include<map>
#include<unordered_map>
#include<list>
#include<numeric>
typedef long long ll;

#define pi 3.14159265358979323846
#define VI vector<int>
#define VLL vector<long long>
#define MAX max_element
#define MIN min_element
#define all(v) v.begin(), v.end()
const ll MOD = 1e9 + 7;
using namespace std;
template<typename T>
T gcd(T a, T b) {
	return b ? gcd(b, a % b) : a;
}
template<typename T>
T lcm(T a, T b) {
	return a * b / gcd(a, b);
}

template<typename T>
T binarysearch(vector<T> A, T key) {
	ll left = 0;ll right = 4;ll mid;
	while (left < right) {
		mid = (left + right) / 2;
		if (key == A[mid]) return 1;
		if (key > A[mid]) left = mid + 1;
		else if (key < A[mid]) right = mid;
	}
	return 0;
}

template<typename T>
T finder(vector<T> vec, T number) {
	auto itr = find(vec.begin(), vec.end(), number);
	size_t index = distance(vec.begin(), itr);
	if (index != vec.size()) { // 発見できたとき
		return 1;
	}
	else { // 発見できなかったとき
		return 0;
	}
}
ll frac(ll n)//階乗
{
	if (n == 0) {
		return 1;
	}
	return (n * frac(n - 1)) % MOD;
}

template<typename T>
T keta(T a) {
	ll kazu = 1;
	while (1) {
		if (a / 10 != 0) { a /= 10;kazu++; }
		else break;
	}
	return kazu;
}//桁数


template<typename T>
T nCr(ll n, T r) {
	ll ans = 1;
	for (int i = n; i > n - r; --i) {
		ans = ans * i;
	}
	for (int i = 1; i < r + 1; ++i) {
		ans = ans / i;
	}
	return ans;
}
/*char r[4];
int yaju[4];
char op[3];
int sum = 0;
scanf("%s", r);
for (int i = 0;i < 4;i++) {
	yaju[i] = r[i] - '0';
}
*///map < string, ll> s;

/*i++ずつずらす
a[0] a[1] a[2]//a[1] a[2] a[3]
a[0] a[2] a[4]//a[1] a[3] a[5]
/*if (N % 2 != 0)a = N / 2;
else a = N / 2 - 1;
for (int i = 1;i <= a;i++) {
	for (int j = 0;j < N - (i * 2);j++) {
		if (S[j] != S[j + i] && S[j + i * 2] != S[j] && S[j + i] != S[j + i * 2]) sum--;
		if (sum == 0)break;
	}
}*/

//mapの使い方
/*map<int, int> mp;
for (int i = 0; i < N; i++)
	mp[a[i]]++;

int ans = 0;
for (auto p : mp) {
	int x = p.first;
	int n = p.second;
	if (n < x) ans += n;
	else ans += n - x;
}*/

int main() {
	ll N;cin >> N;
	vector<ll>A(N + 2), B(N);
	ll min = 5001, mins = 5001;
	ll max = -5001, maxs = -5001;
	ll sum = 0;
	A[0] = 0;A[N + 1] = 0;
	for (int i = 1;i <= N;i++) {
		cin >> A[i];
		sum += abs(A[i] - A[i - 1]);
	}
	sum += abs(A[N]);
	for (int i = 1;i <= N;i++) {
		cout << sum + abs(A[i + 1] - A[i - 1]) - abs(A[i] - A[i - 1]) - abs(A[i + 1] - A[i]) << endl;
	}
}

Measured memory_bytes: 2816
/**
 *      purpose : 
 *      author  : 𝒌𝒚𝒐𝒎𝒖𝒌𝒚𝒐𝒎𝒖𝒑𝒖𝒓𝒊𝒏
 *      created : 
**/

#include <iostream>
#include <deque>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
#include <algorithm>
#include <cmath>
#include <complex>
#include <numeric>
#include <bitset>
#include <cassert>
#include <cctype>
#include <functional>
#include <iomanip>
#include <random>
#include <utility>

using namespace std;

using int64 = long long;
#define debug(_) cerr << #_ << ": " << (_) << '\n'
template<typename T> inline void chmin(T &a, T b) { if (a > b) a = b; return; }
template<typename T> inline void chmax(T &a, T b) { if (a < b) a = b; return; }
template<typename T> ostream& operator<<(ostream& os, const vector<T>& vec) { os << '{'; for (size_t i = 0; i < vec.size(); ++i) { os << vec[i]; if (i != vec.size() - 1) os << ','; } os << '}'; return os; }
template<typename T, typename U> ostream& operator<<(ostream& os, const pair<T, U>& p) { return os << '{' << p.first << " " << p.second << '}'; }

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

  int n; cin >> n;
  if (n == 1 || n == 2) {
    cout << 0 << endl;
  } else {
    cout << (n - 1) / 2 << endl;
  }

  return 0;
}

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

#define FOR(i,a,b) for(i=(a);i<(b);++i) 
#define FORR(i,a,b) for(i=(a);i>(b);--i)
#define REP(i,n) for(i=0;i<(n);++i)
#define REPR(i,n) for(i=(n);i>0;--i)
#define PB push_back
#define ll long long
#define INT_MAX 2147483647
#define LL_MAX 9223372036854775807
#define sortR(a,b) sort(a, b, greater<int>())

using namespace std;

long long GCD(long long a, long long b) {
	if (a < b)
		swap(a, b);
	if (b == 0) return a;
	else return GCD(b, a % b);
}
bool sosuu_check(int num) {
	int i;
	for (i = 2; i <= sqrt(num); ++i) {
		if (num%i == 0)
			return false;
	}
	return (num < 2) ? false : true;
}

int main() {
	ll N, A, T,i,H,ans;
	double MIN=(double)111111111111111111,ondo;
	cin >> N >> T >> A;
	REP(i, N) {
		cin >> H;
		ondo = T - H * 0.006;
		if (MIN > abs(A-ondo)) {
			MIN = abs(A - ondo);
			ans = i;
		}
	}
	cout << ans+1 << endl;
}

Measured memory_bytes: 256
def bitadd(a,w,bit): #aにwを加える(1-origin)
 
    x = a
    while x <= (len(bit)-1):
        bit[x] += w
        x += x & (-1 * x)
 
def bitsum(x,bit): #ind 1～aまでの和を求める
   
    ret = 0
    while x:
        ret += bit[x]
        x -= x & (-1 * x)
    return ret


#区間更新BIT(BITを2つ用意し、BITの長さをN+2で初期化しておくべし)
def bitaddR(l,r,w,bit1,bit2): #半開区間[l,r)にwを加える

    bitadd(l,-1*w*l,bit1)
    bitadd(r,w*r,bit1)
    bitadd(l,w,bit2)
    bitadd(r,-1*w,bit2)

def bitsumR(r,bit1,bit2): #半開区間[1,r)の区間和

    return bitsum(r,bit1) + r * bitsum(r,bit2)


N,M = map(int,input().split())

BIT = [0] * (M+1)
dic = {}
for i in range(N):
    l,r = map(int,input().split())
    if r-l+1 not in dic:
        dic[r-l+1] = []
    dic[r-l+1].append([l,r])

ind = 0
ns = N
ans = []
for d in range(M):

    d += 1

    if d in dic:
        for L,R in dic[d]:

            bitadd(L , 1 ,BIT)
            bitadd(R+1 , -1 , BIT)
            ns -= 1

    nm = 0
    for i in range(d,M+1,d):
        
        nm += bitsum(i,BIT)
    ans.append(nm+ns)

print ("\n".join(map(str,ans)))


Measured memory_bytes: 116568
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll INF = 1000;

void solve(long long N, long long L){
    vector<pair<ll, ll>> score;
    for(ll i = 1; i <= N; ++i) score.emplace_back(abs(L + i - 1), L + i - 1);
    sort(score.begin(), score.end());
    ll total = 0;
    for(ll i = 0; i < N; ++i) total += score[i].second;
    cout << total - score[0].second << endl;
}

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


Measured memory_bytes: 256
#include <algorithm>
#include <cfloat>
#include <climits>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <functional>
#include <iostream>
#include <map>
#include <memory>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>

using namespace std;

typedef long long ll;

#define sz size()
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define all(c) (c).begin(), (c).end()
#define rep(i,a,b) for(long long i=(a);i<(b);++i)
#define per(i,a,b) for(long long i=b-1LL;i>=(a);--i)
#define clr(a, b) memset((a), (b) ,sizeof(a))
#define ctos(c) string(1,c)
#define print(x) cout<<#x<<" = "<<x<<endl;

#define MOD 1000000007

int main() {
  string s;
  cin>>s;
  ll n1 = (s[0]-'0')*10+(s[1]-'0');
  ll n2 = (s[2]-'0')*10+(s[3]-'0');
  if((n1>12||n1==0)&&(n2>12||n2==0)){
    cout << "NA" << endl;
  }
  else if((n1<=12&&n1>0)&&(n2<=12&&n2>0)){
    cout << "AMBIGUOUS" << endl;
  }
  else if((n1<=12&&n1>0)){
    cout << "MMYY" << endl;
  }
  else{
    cout << "YYMM" << endl;
  }
  return 0;
}

Measured memory_bytes: 256
import math
N,K=map(int,input().split())

sum=0
for i in range(K,N+2):
#  print(N*(N+1)//2-((N-i)*(N-i+1)//2),i*(i-1)//2)
  sum+=(N*(N+1)//2)-((N-i)*(N-i+1)//2)-(i*(i-1)//2)+1
  sum%=(10**9+7)
print(sum%(10**9+7))

Measured memory_bytes: 9176
c11, c12, c13 = map(int, input().split())
c21, c22, c23 = map(int, input().split())
c31, c32, c33 = map(int, input().split())

flag = True
if((c21 - c11) != (c22 - c12) or (c21 - c11) != (c23 - c13)):
    flag = False
if((c31 - c11) != (c32 - c12) or (c31 - c11) != (c33 - c13)):
    flag = False
if((c12 - c11) != (c22 - c21) or (c12 - c11) != (c32 - c31)):
    flag = False
if((c13 - c11) != (c23 - c21) or (c13 - c11) != (c33 - c31)):
    flag = False
if(flag):
    print('Yes')
else:
    print('No')

Measured memory_bytes: 3188
N = int(input())
H = list(map(int, input().split()))
if N == 1:
    print("Yes")
    exit()
for i in range(N-1):
    if H[i] < H[i + 1]:
        H[i + 1] -= 1
for i in range(N-1):
    ans = H[i + 1] - H[i]
    if ans < 0:
        print("No")
        exit()
print("Yes")


Measured memory_bytes: 14252
import java.util.*;

public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int r=sc.nextInt();
        int g=sc.nextInt();
        int b=sc.nextInt();
        int n=sc.nextInt();
        int ans=0;
        for(int i=0;i<n/r+1;i++){
            for(int j=0;j<(n-r*i)/g+1;j++){
                if((n-r*i-g*j)%b==0){
                    ans++;
                }
            }
        }
        System.out.println(ans);
    }
}

Measured memory_bytes: 21972
def gcd(a, b):
    while b: a, b = b, a % b
    return a
def isPrimeMR(n):
    d = n - 1
    d = d // (d & -d)
    L = [2, 7, 61] if n < 1<<32 else [2, 3, 5, 7, 11, 13, 17] if n < 1<<48 else [2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37]
    for a in L:
        t = d
        y = pow(a, t, n)
        if y == 1: continue
        while y != n - 1:
            y = y * y % n
            if y == 1 or t == n - 1: return 0
            t <<= 1
    return 1
def findFactorRho(n):
    m = 1 << n.bit_length() // 8
    for c in range(1, 99):
        f = lambda x: (x * x + c) % n
        y, r, q, g = 2, 1, 1, 1
        while g == 1:
            x = y
            for i in range(r):
                y = f(y)
            k = 0
            while k < r and g == 1:
                ys = y
                for i in range(min(m, r - k)):
                    y = f(y)
                    q = q * abs(x - y) % n
                g = gcd(q, n)
                k += m
            r <<= 1
        if g == n:
            g = 1
            while g == 1:
                ys = f(ys)
                g = gcd(abs(x - ys), n)
        if g < n:
            if isPrimeMR(g): return g
            elif isPrimeMR(n // g): return n // g
            return findFactorRho(g)
def primeFactor(n):
    i = 2
    ret = {}
    rhoFlg = 0
    while i * i <= n:
        k = 0
        while n % i == 0:
            n //= i
            k += 1
        if k: ret[i] = k
        i += i % 2 + (3 if i % 3 == 1 else 1)
        if i == 101 and n >= 2 ** 20:
            while n > 1:
                if isPrimeMR(n):
                    ret[n], n = 1, 1
                else:
                    rhoFlg = 1
                    j = findFactorRho(n)
                    k = 0
                    while n % j == 0:
                        n //= j
                        k += 1
                    ret[j] = k

    if n > 1: ret[n] = 1
    if rhoFlg: ret = {x: ret[x] for x in sorted(ret)}
    return ret

N = int(input())
A = list(map(int,input().split()))
g = 0
for a in A:
    g = gcd(g, a)
if g > 1:
    print("not coprime")
    exit()

X = set()
for a in A:
    for p in primeFactor(a):
        if p in X:
            print("setwise coprime")
            exit()
        X.add(p)

print("pairwise coprime")


Measured memory_bytes: 197232
#include<bits/stdc++.h>
using namespace std;
int dp[(1<<22)][22];
long long int countways(long long int mask,int done,int n,vector<int>v[])
    {if(mask==(1<<n)-1 && done==n){return 1;}
    if(dp[mask][done]>-1){return dp[mask][done];}
    long long int sumi=0;
    for(auto j:v[done])
        {if(!(mask&(1<<j))){sumi+=countways(mask|(1<<j),done+1,n,v); sumi%=1000000007;}
        }
    return dp[mask][done]=sumi;
    }
int main()
    {ios::sync_with_stdio(0);
    cin.tie(0);
    int n,dummy;
    cin>>n;
    vector<int> v[n];
    for(int i=0;i<n;i++)
        {for(int j=0;j<n;j++)
            {cin>>dummy;
            if(dummy==1){v[i].push_back(j);}
            }
        }
    for(int i=0;i<(1<<22);i++)
        {for(int j=0;j<22;j++){dp[i][j]=-1;}
        }
    cout<<countways(0,0,n,v);
    }


Measured memory_bytes: 360704
function main(input) {
  const S = input.split('');
  let ans = 0;
  
  S[0] === '+' ? ans++ : ans--;
  S[1] === '+' ? ans++ : ans--;
  S[2] === '+' ? ans++ : ans--;
  S[3] === '+' ? ans++ : ans--;
  
  console.log(ans);
}

main(require('fs').readFileSync('/dev/stdin', 'utf8'));

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

int main() {
	int a, b, c, d, e;
	cin >> a >> b >> c >> d >> e;
	vector<int> num{a, b, c, d, e};
	sort(num.begin(), num.end(),greater<int>());
	for (int i = 0; i < 5; i++) {
		if (i != 4)cout << num[i] << " ";
		else cout << num[i];
	}
	cout << endl;
	return 0;
}

Measured memory_bytes: 3064
#include <cstdio>
#include <limits>

using namespace std;

namespace {

static size_t Merge(size_t* A, size_t left, size_t mid, size_t right) {
  const size_t n1 = mid - left;
  const size_t n2 = right - mid;

  // When sorting large arrays, allocating L and R in heap for
  // each Merge call makes a bit the program slower.
  //
  // In the real application, we should use std::vectors instead of
  // fixed sized arrays, though.
  // vector<size_t> L(n1+1);
  // vector<size_t> R(n2+1);
  size_t L[n1 + 1];
  size_t R[n2 + 1];

  for (size_t i = 0; i < n1; ++i) {
    L[i] = A[left + i];
  }
  for (size_t i = 0; i < n2; ++i) {
    R[i] = A[mid + i];
  }

  static const size_t kInf = numeric_limits<size_t>::max();
  L[n1] = kInf;
  R[n2] = kInf;

  size_t i = 0;
  size_t j = 0;
  for (size_t k = left; k < right; ++k) {
    if (L[i] <= R[j]) {
      A[k] = L[i];
      i++;
    } else {
      A[k] = R[j];
      j++;
    }
  }
  return right - left;
}

static size_t MergeSortInternal(size_t* A, size_t left, size_t right) {
  if (left + 1 >= right) return 0;

  const size_t mid = (left + right) / 2;
  size_t ret = MergeSortInternal(A, left, mid);
  ret += MergeSortInternal(A, mid, right);
  return ret + Merge(A, left, mid, right);
}

static size_t MergeSort(size_t* A, size_t n) {
  return MergeSortInternal(A, 0, n);
}
} // namespace

int main() {
  size_t n;
  size_t S[500000];
  scanf("%lu", &n);
  for (size_t i = 0; i < n; ++i) {
    scanf("%lu", &S[i]);
  }

  const size_t swapped = MergeSort(S, n);
  for (size_t i = 0; i < n; ++i) {
    if (i > 0) printf(" ");
    printf("%lu", S[i]);
  }
  printf("\n");
  printf("%lu\n", swapped);

  return 0;
}

Measured memory_bytes: 8852
n = int(input())
s = [input() for _ in range(n)]
for i in range(n):
  s[i] = ''.join(sorted(s[i]))
t = {}
for i in range(n):
  if s[i] in t:
    t[s[i]] += 1
  else:
    t[s[i]] = 1
print(sum(t[k] * (t[k] -1) // 2 for k in t))

Measured memory_bytes: 19472
# -*- coding: utf-8 -*-
import sys
sys.setrecursionlimit(10**9)
INF=10**18
MOD=10**9+7
input=lambda: sys.stdin.readline().rstrip()
YesNo=lambda b: bool([print('Yes')] if b else print('No'))
YESNO=lambda b: bool([print('YES')] if b else print('NO'))
int1=lambda x:int(x)-1

def main():
    s=input()
    print(s[0]+str(len(s)-2)+s[-1])

if __name__ == '__main__':
    main()


Measured memory_bytes: 38256
sel=4
#ICC-D3-J
if sel==1: print('Judgement')

#ARC030-A
if sel==2:
    N=int(input())
    K=int(input())
    if 2*K-1<N:
        print('YES')
    else:
        print('NO')

#AGC004-A
if sel==3:
    A,B,C=map(int,input().split())
    ans=10**19
    whole=A*B*C
    for a in range(A//2,A//2+2):
        ans=min(ans,abs(whole-a*B*C*2))
    for b in range(B//2,B//2+2):
        ans=min(ans,abs(whole-A*b*C*2))
    for c in range(C//2,C//2+2):
        ans=min(ans,abs(whole-A*B*c*2))
    print(ans)

#AGC011-B
if sel==4:
    import bisect

    #O(N): 長さNの配列に対する累積和(+演算)
    def CS1D(lis): #listを渡す
        ret=[lis[0]]
        for i in range(1,len(lis)):
            ret.append(ret[i-1]+lis[i])
        return ret

    N=int(input())
    A=[int(i) for i in input().split()]
    A.sort()
    CS=CS1D(A)
    ans=0
    # print(A)
    # print(CS)
    # 各Aiに対して、x<=2*Aiを満たすAの最大の元Ajをとって,Ajについても同様にする。
    # こうして、変らなくなるか最後まで行ったら終わり。
    for i in range(N):
        # print('!',i)
        prev=-1
        size=CS[i]
        k=i
        while prev!=k:
            prev=k
            # print(size)
            k=bisect.bisect(A,2*size)-1 #ここまで食べれる
            # print(bisect.bisect(A,2*size))
            size=CS[k]
            if k==N-1:
                ans+=1
                break
    print(ans)


Measured memory_bytes: 14404
Scanf.scanf "%d %d" (fun n k ->
    let snuke = Array.make n false in
    for i = 1 to k do
        Scanf.scanf " %d" (fun d ->
            for j = 1 to d do
                Scanf.scanf " %d" (fun a -> snuke.(a - 1) <- true)
            done
        )
    done;
    Array.fold_left (fun acc v -> if v then acc else acc + 1) 0 snuke |> Printf.printf "%d\n"
)

Measured memory_bytes: 5768
n, k = gets.split.map(&:to_i)
p = gets.split.map(&:to_i)

mx = 0
s = 0
q = []
p.map! { |x| x + 1 }
p.each do |x|
  s += x
  q.push(x)
  if q.size > k
    s -= q.shift
  end
  if q.size == k
    mx = [mx, s].max
  end
end

puts mx / 2.0


Measured memory_bytes: 19772
m = 10**9+7
n = int(input())
inv = [0]*(n+3)
inv[1] = 1
for i in range(2,n+3):
  inv[i] = (m//i)*(m-inv[m%i])%m
# print(inv)

a = list(map(int,input().split()))
w = sum(a) - n*(n+1)//2

q = 0
t = -1
for i in range(n+1):
  if a[i] == w:
    q += t*i
    t = 1
q += 1

x = (n+1)%m
y = 1
for k in range(1,n+2):
  print((x-y)%m)
  x = x*(n+1-k)*inv[k+1]%m
  y = y*(n+2-q-k)*inv[k]%m
  

Measured memory_bytes: 17844
n = int(input())
a = list(map(int, input().split()))
q = int(input())
b = []
c = []
for _ in range(q):
    B, C = map(int, input().split())
    b.append(B)
    c.append(C)

imax = 10**5

d = [0]*imax
for i in range(n):
    d[a[i]-1] += 1

ans = sum(a)
for i in range(q):
    b_count = d[b[i]-1]
    d[c[i]-1] += b_count
    ans += (c[i]-b[i]) * b_count
    print(ans)
    d[b[i]-1] = 0

Measured memory_bytes: 22380
export class Main {
  static main(input: string): string {
    const tmp: string[] = input.split("\n");
    const [n]: number[] = tmp.shift().split(" ").map(int => parseInt(int));
    const [s]: string[] = tmp.shift().split(" ");
    const sList = s.split("").slice(0, n);
    let rCount = 0;
    let gCount = 0;
    let bCount = 0;
    for (let i = 0, leni = n; i < leni; i++) {
      switch (sList[i]) {
        case "R":
          rCount++;
          break;
        case "G":
          gCount++;
          break;
        default:
          bCount++;
      }
    }
    let allCount = rCount * gCount * bCount;
    let noCount = 0;
    for (let j = 1, lenj = n - 1; j < lenj; j++) {
      for (let d = 1, len = Math.min(j, n - (j + 1)); d <= len; d++) {
        let si = sList[j - d];
        let sj = sList[j];
        let sk = sList[j + d];
        if (si != sj && sj != sk && sk != si) {
          noCount++;
        }
      }
    }
    return `${allCount - noCount}`;
  }
}
console.log(Main.main(require("fs").readFileSync("/dev/stdin", "utf8")));


Measured memory_bytes: 32652
#include <bits/stdc++.h>
#define ll long long
#define DB(x) cerr << __LINE__ << ": " << #x << " = " << (x) << endl
using namespace std;
int n;
string s;

const int p = 97; 
const int m = 1e9 + 9;
vector<long long> p_pow(6000); 
vector<long long> h(6000, 0);
ll expo(ll number,ll power, ll mod){
	ll ans=1;
	number=number%mod;
	while(power){
		if(power&1){
			ans=(ans*number)%mod;
		}
		power=power>>1;
		number=(number*number)%mod;
	}
	return ans;
}

bool foo(int len) {
	unordered_map<int, int> ma;
	for(int i = len+1; i+len-1 <= n; ++i) {
		ll r1 = (h[i+len-1] - h[i-1] + m) % m;
		ll r3 = expo(p_pow[i-1], m-2, m);
		r1 = (r1*r3) % m; 
		++ma[r1];
	}
	for(int i = 1; i+len-1 <= n; ++i) {
		ll r1 = (h[i+len-1] - h[i-1] + m) % m;
		ll r3 = expo(p_pow[i-1], m-2, m);
		r1 = (r1*r3) % m;
		// DB(len);
		// DB(i);
		// DB(r1);
		if(ma[r1] > 0) return true;
		r1 = (h[i+2*len-1] - h[i+len-1] + m) % m;
		r3 = expo(p_pow[i+len-1], m-2, m);
		r1 = (r1*r3) % m;
		--ma[r1];
		// DB(r1);
	}
	return false;
	// for(int i = 1; i <= n; ++i) {
	// 	ll r1 = (h[i+len-1] - h[i-1] + m) % m;
	// 	ll r3 = expo(p_pow[i-1], m-2, m);
	// 	r1 = (r1*r3) % m; 
	// 	for(int  j = i+len; j+len-1 <= n; ++j) {
	// 		if(s[i-1] == s[j-1]) {
	// 			ll r2 = (h[j+len-1] - h[j-1] + m) % m;
	// 			ll r4 = expo(p_pow[j-1], m-2, m);
	// 			r2 = (r2*r4) % m; 
	// 			if(r1 == r2) return true;
	// 		}
	// 	}
	// }
	// return false;
}

int main() {
	ios_base::sync_with_stdio(false); 
    cin.tie(NULL); 
    cout.tie(NULL);
    
	cin >> n >> s;
	
    p_pow[0] = 1; 
    for (int i = 1; i < (int)p_pow.size(); i++) 
        p_pow[i] = (p_pow[i-1] * p) % m; 
    for (int i = 0; i < n; i++)
        h[i+1] = (h[i] + (s[i] - 'a' + 1) * p_pow[i]) % m; 

	int st = 0, en = n, ans = 0;
	while(st <= en) {
		int mid = (st+en)/2;
		if(foo(mid)) {
			ans = max(ans, mid);
			st = mid + 1;
		}
		else {
			en = mid - 1;
		}
	}
	cout << ans;
	return 0;
}


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

int int_len(int n) {
  int s=0;
  while(n!=0) s++, n/=10;
  return s;
}

int int_sum(int n) {
  int m=0,s=0,a=n;
  while(a!=0) s++, a/=10;
  for(int i=s-1;i>=0;i--) m+=n/((int)pow(10,i))-(n/((int)pow(10,i+1)))*10;
  return m;
}

int fac(int n){
  int m=1;
  while(n>=1) m*=n,n--;
  return m;
}

int vec_sum(vector<int> v){
  int n=0;
  for(int i=0;i<v.size();i++) n+=v[i];
  return n;
}
///////////////////////////
int main() {
  int n,count=1,ans=0;
  cin>>n;
  vector<int> v(n);
  rep(i,n) cin>>v[i];
  while(ans<=n){

    if(count==2){
      cout<<ans<<endl;
      return 0;
    }else{
      count=v[count-1];
    }
    ans++;
  }
  cout<<-1<<endl;
  
  
  
}
///////////////////////////



Measured memory_bytes: 640
#include <iostream>
#include <vector>
#include <algorithm>
#include <math.h>
#include <string>
#include <deque>
#include <tuple>
#include <map> 
#include <set>
#include <stack>
#include <functional>
#define ll long long
using namespace std;

int main() {

	char c;

	cin >> c;

	if (c >= 'a' && c <= 'z') {
		cout << 'a' << endl;
	}
	else {
		cout << 'A' << endl;
	}
}

Measured memory_bytes: 3604
#include <bits/stdc++.h>
using namespace std;
#pragma GCC optimize("O0")
typedef long long int ll;
typedef long double ld;
#define rep(i,n) for (ll i = 0; i < (n); ++i)
#define Rep(i,a,n) for (ll i = (a); i < (n); ++i)
const ll mod = 1e9+7;
const ll INF = 1e18;
#define All(a) (a).begin(),(a).end()
#define Pi acos(-1)
using Graph = vector<vector<ll>>;


// 素集合データ構造
struct UnionFind {
    //自身が親であれば、その集合に属する頂点数に-1を掛けたもの
    //そうでなければ親のid
    vector<int> r;
 
    UnionFind(int N) {
        r = vector<int>(N, -1);
    }

  // データxが属する木の根を得る 
    int root(int x) {
        if (r[x] < 0) return x;
        return r[x] = root(r[x]);
    }

  // 2つのデータx, yが属する木をマージする 
    bool unite(int x, int y) {
        x = root(x);
        y = root(y);
        if (x == y) return false;
        if (r[x] > r[y]) swap(x, y);
        r[x] += r[y];
        r[y] = x;
        return true;
    }

  // 2つのデータx, yが属する木が同じならtrueを返す
    bool same(int x, int y) {
      return root(x) == root(y);
    }

  // データxが含まれる木の大きさを返す
    ll size(int x) {
        return -r[root(x)];
    }
};

int main() {
  cin.tie(0);
  ios_base::sync_with_stdio(false);
  cout << setprecision(15) << fixed;
  chrono::system_clock::time_point start,end;
  start = chrono::system_clock::now();

  ll n, m;
  cin >> n >> m;
  vector<ll> a(n);
  rep(i,n) cin >> a[i];
  UnionFind UF(n);

  rep(i,m) {
    ll x, y;
    cin >> x >> y;
    UF.unite(x-1,y-1);
  }

  ll ans = 0;
  rep(i,n) {
    if (UF.same(a[i]-1, i)) ++ans;
  }
  cout << ans << '\n';

  end = chrono::system_clock::now();
  auto elapsed = chrono::duration_cast< chrono::milliseconds >(end - start).count();
  cerr << elapsed << "ms" << '\n';
}

Measured memory_bytes: 4584
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define REP(i,a,b) for (int i = a; i < (b); ++i)
#define all(x) (x).begin(),(x).end()
using namespace std;
const int INF = 1000000007;
typedef long long ll;
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; }
int main(){
  int n;
  cin>>n;
  cout<<n*n<<endl;
  return 0;
}

Measured memory_bytes: 256
#include <stdio.h>

int main() 
{
	int H;
	int A;
	int F;
	
	scanf("%d %d", &H, &A);
	
	F = H/A;
	
	H%A>0 ? printf("%d", F+1) : printf("%d", F);
	
	return 0;
}

Measured memory_bytes: 1712
import math

EPS = 1e-10

class Point():
    def __init__(self, x, y):
        self.x = x
        self.y = y

    def __add__(self, point):
        # + 演算子での挙動を指定
        return Point(self.x+point.x, self.y+point.y)

    def __sub__(self, point):
        # - 演算子での挙動を指定
        return Point(self.x-point.x, self.y-point.y)

    def __mul__(self, a):
        # * 演算子での挙動を指定
        return Point(a*self.x, a*self.y)

    def __truediv__(self, a):
        # / 演算子での挙動を指定
        return Point(self.x/a, self.y/a)

    def __abs__(self):
        # abs関数での挙動を指定
        return math.sqrt(self.norm())

    def norm(self):
        return self.x**2+self.y**2

    def __eq__(self, point):
        # == 演算子での挙動を指定
        return abs(self.x-point.x) < EPS and abs(self.y-point.y) <EPS

def dot(a, b):
    return a.x*b.x+a.y*b.y

def cross(a, b):
    return a.x*b.y - a.y*b.x

def isOrthogonal(a, b):
    return dot(a, b) == 0

def isParallel(a, b):
    return cross(a, b) == 0

if __name__ == '__main__':
    from sys import stdin
    input = stdin.readline

    q = int(input())

    for _ in range(q):
        x0, y0, x1, y1, x2, y2, x3, y3 = map(int, input().split())
        a = Point(x0, y0)-Point(x1, y1)
        b = Point(x2, y2)-Point(x3, y3)
        if isOrthogonal(a, b):
            print(1)
        elif isParallel(a, b):
            print(2)
        else:
            print(0)



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

int main() {
  int N; cin >> N;
  vector<ll> A(N); for (int i = 0; i < N; ++i) cin >> A[i];
  vector<ll> sum(N + 1, 0); for (int i = 0; i < N; ++i) sum[i + 1] = sum[i] + A[i];
  vector<ll> xsum(N + 1, 0); for (int i = 0; i < N; ++i) xsum[i + 1] = xsum[i] ^ A[i];
  ll ans = 0;
  deque<int> deq;
  auto f = [&](int l, int r) { return (xsum[r] ^ xsum[l - 1]) == sum[r] - sum[l - 1]; };
  for (int r = 1; r <= N; ++r) {
    deq.push_back(r);
    while (deq.size() > 1) {
      int l = deq.front();
      if (f(l, r)) break;
      deq.pop_front();
    }
    ans += deq.size();
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 5760
import sys

def get_read_func(fileobject):
    if fileobject == None :
        return raw_input
    else:
        return fileobject.readline

def dist(x1, y1, x2, y2):
    return abs(x1 - x2) + abs(y1 - y2)

def main():
    if len(sys.argv) > 1:
        f = open(sys.argv[1])
    else:
        f = None
    read_func = get_read_func(f);
    input_raw = read_func()
    top_str = input_raw.strip().split()
    [N, M] = [int(top_str[0]), int(top_str[1])]

    student_list = []
    checkpoint_list = []
    for i in range(N):
        input_raw = read_func().split()
        (a, b) = (int(input_raw[0]) , int(input_raw[1]))
        student_list.append((a,b))

    for i in range(M):
        input_raw = read_func().split()
        (c, d) = (int(input_raw[0]) , int(input_raw[1]))
        checkpoint_list .append((c, d))

    for i in range(N):
        min_checkpoint = 0
        min_dist = sys.maxint
        studentpoint = student_list[i]
        for j in range(M):
            checkpoint = checkpoint_list[j]
            d = dist(studentpoint[0], studentpoint[1], checkpoint[0], checkpoint[1])
            if d < min_dist:
                min_checkpoint = j
                min_dist = d
        print min_checkpoint + 1


if __name__ == '__main__':
    main()

Measured memory_bytes: 2696
import itertools

N,A,B,C = map(int,input().split())
L = [int(input()) for i in range(N)]
ans = 10**4
for v in itertools.product([0,1,2,3], repeat=N):
    if 1 not in v or 2 not in v or 3 not in v:
        continue
    a = 0
    b = 0
    c = 0
    m = -30
    for i in range(N):
        if v[i] == 1:
            a += L[i]
            m += 10
        if v[i] == 2:
            b += L[i]
            m += 10
        if v[i] == 3:
            c += L[i]
            m += 10
    m += abs(A-a) + abs(B-b) + abs(C-c)
    ans = min(ans,m)
print(ans)


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

typedef long long LL;
typedef unsigned long long ULL;

const int PI = 3.141592653589793238;
const LL inf64 = 1000000111111222222;
const int inf = 1000111222;
const int mod = 1000000007;
const int N = 200007;


int main() {
	
	ios_base :: sync_with_stdio(0);
	cin.tie(0); cout.tie(0);
	
	int n, k; cin >> n >> k;
	int ar[N];
	for (int i = 0; i < n; i++) {
		cin >> ar[i];
	}
	for (int i = k; i < n; i++) {
		if (ar[i - k] >= ar[i]) {
			cout << "No\n";
		}
		else {
			cout << "Yes\n";
		}
	}
	return 0;
}


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

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

    int num[26] = {0};
    for (int i = 0; i < s.size(); ++i) num[s[i] - 'a']++; 

    bool notFound = false;

    for (int i = 0; i < 26; ++i) {
        if (num[i] == 0) {
            printf("%c\n", (char)(i + 'a'));
            notFound = false;
            break;
        }
        else notFound = true;
    }

    if (notFound == true) cout << "None" << endl;


}

Measured memory_bytes: 512
#include<stdio.h>
int main () {
	int a , b;
	scanf("%d %d" , &a , &b);
	if (a < b) {
		printf("a < b\n");
	} else if(b < a) {
		printf("a > b\n");
	} else {
		printf("a == b\n");
	}
	return 0;
}

Measured memory_bytes: 580
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
using P = pair<ll,ll>;
const ll mod = 1e9+7;
#define ALL(x) (x).begin(),(x).end()
#define pow(x,y) modpow(x,y)
#define REP(i,n) for(ll (i)=0;(i)<(n);(i)++)
#define REPS(i,n) for(ll (i)=1;(i)<=(n);(i)++)
#define RREP(i,n) for(ll (i)=(n-1);(i)>=0;(i)--)
#define RREPS(i,n) for(ll (i)=(n);(i)>0;(i)--)
#define pb push_back
#define mp make_pair
#define F first
#define S second
#define UNIQUE(v) v.erase(unique(ALL(v)),v.end());

template<class T> inline void chmin(T& a, T b){
    if (a > b){
        a = b;
    }
}

template<class T> inline void chmax(T& a, T b){
    if (a < b){
        a = b;
    }
}

signed main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout<<fixed<<setprecision(10);
    string S;
    cin >> S;
    sort(ALL(S));
    if(S == "abc"){
        cout << "Yes" << "\n";
    }else{
        cout << "No" << "\n";
    }
}

Measured memory_bytes: 256
#include <stdio.h>
int main()
{
long long int n, a[200000], i, p = 0;
	scanf("%lld", &n);
	for (i = 0; i < n; i++)
	{
		scanf("%lld", &a[i]);
	}
	for (i = 1; i < n; i++)
	{
		if (a[i] < a[i - 1])
		{
			p += a[i - 1] - a[i];
			a[i] = a[i - 1];
		}
	}

	printf("%lld\n", p);
	return 0;
}

Measured memory_bytes: 3288
#include <iostream>
#include <stdio.h>
#include <stdlib.h>
#include <cmath>
#include <algorithm>
#include <vector>
using namespace std;

int main(){
    int n;
    cin>>n;
    string s[n];
    string x;
    int t[n];
    int ti=0;
    for(int i=0;i<n;i++){
        cin>>s[i]>>t[i];
    }
    cin>>x;
    int i=0;
    while(s[i]!=x){
        i+=1;
    }
    for(int j=i+1;j<n;j++){
        ti+=t[j];
    }
    cout<<ti;
}


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

int main(void)
{
    int d, v = 0;
    cin >> d;

    vector<int> c(26), last(26);
    int s[d][26];

    rep(i, 26)
    {
        cin >> c.at(i);
        last.at(i) = 0;
    }

    rep(i, d)
    {
        rep(j, 26)
        {
            cin >> s[i][j];
        }
    }

    rep(i, d)
    {
        int t;
        cin >> t;
        v += s[i][t - 1];
        last.at(t - 1) = i+1;
        rep(j, 26)
        {
            v -= c.at(j) * (i+1 - last.at(j));
        }
        cout << v << endl;
    }

    return 0;
}


Measured memory_bytes: 3636
#include <cstdio>
#include <iostream>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
using namespace std;

int main() {
	int A, B, C;
	int ans = 0;
	scanf("%d %d %d", &A, &B, &C);

	while (ans < C && B>=A) {
		B -= A;
		ans++;
	}

	printf("%d\n", ans);

	return 0;
}

Measured memory_bytes: 256
N=int(input())
A=[]
for i in range (N):
	A.append(list(map(int,input().split())))
C=sorted(A,key=lambda A: A[1])
tmp=0
count=0
for i in range (N):
  tmp+=C[i][0]
  if tmp<=C[i][1]:
    count+=1
  else:
    print("No")
    break
if count==N:
  print("Yes")

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

#define int long long
#define xxx int32_t
#define fuck_u return 0;
const int inf = 1e18L+5;

xxx main() {
	cin.tie(0);
    ios::sync_with_stdio(false);
    
    int n, w;
    //scanf("%lld %lld", &n, &w);
    cin>>n>>w;
	vector<int> weight(n), value(n);
    for(int i=0; i<n; ++i) {
		//scanf("%lld %lld", &weight[i], &value[i]);
		cin>>weight[i]>>value[i];
	}
	int sum_val = 0;
	for(int i: value) {
		sum_val += i;
	}
	vector<int> dp(sum_val+1, inf);
	//int dp[sum_val+1];
	//memset(dp, inf, sizeof(dp));
	dp[0] = 0;
	for(int i=0; i<n; ++i) {
		for(int j=sum_val-value[i]; j>=0; --j) {
			dp[value[i]+j] = min(dp[value[i]+j], dp[j]+weight[i]);
		}
	}
	int result = 0;
	for(int i=0; i<sum_val+1; ++i) {
		if(dp[i]<=w)
			result = i;
	}
    //printf("%lld\n", result);
    cout<<result<<"\n";
	fuck_u
}


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

int dp[30];

int main() {
  int N; cin >> N;
  vector<int> V(N), C(N);
  for (int i = 0; i < N; ++i) {
    cin >> V[i];
  }
  for (int i = 0; i < N; ++i) {
    cin >> C[i];
  }
  
  dp[0] = 0;
  
  for (int i = 0; i < N; ++i) {
    dp[i+1] = max(dp[i], dp[i] + (V[i] - C[i]));
  }
  
  cout << dp[N] << endl;
      
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define inf 1000000000000
int main()
{
    ll h,w,m;
    cin>>h>>w>>m;
    ll k=m;
    vector<ll>v1(h+1,0);
    vector<ll>v2(w+1,0);
    set<pair<int,int>>s;
    for(int i=0;i<k;i++)
    {
        ll x,y;
        cin>>x>>y;
        s.insert({x,y});
        v1[x]++;
        v2[y]++;
    }
    ll p=-inf;
    ll q=-inf;
    for(int i=1;i<=h;i++)
    {
        //cout<<v1[i]<<" ";
        if(v1[i]>p)
        {
            p=v1[i];
        }
    }
    vector<ll>v3;
    for(int i=1;i<=h;i++)
    {
        if(v1[i]==p)
        v3.push_back(i);
    }
    for(int i=1;i<=w;i++)
    {
        //cout<<v2[i]<<" ";
        if(v2[i]>q)
        {
            q=v2[i];
            //index2=i;
        }
    }
    vector<ll>v4;
    for(int i=1;i<=w;i++)
    {
        if(v2[i]==q)
        v4.push_back(i);
    }
    ll p1=v3.size();
    ll q1=v4.size();
    int f=0;
    for(int i=0;i<p1;i++)
    {
        for(int j=0;j<q1;j++)
        {
            //cout<<v3[i]<<" "<<v4[j]<<"\n";
            if(s.find({v3[i],v4[j]})==s.end())
            {
                cout<<p+q<<"\n";
                f=1;
                break;
            }
            
        }
        if(f)
        break;
    }
    if(f==0)
    cout<<p+q-1<<"\n";
    return 0;
}


Measured memory_bytes: 30296
/*
    Author: Nguyen Tan Bao
    Status:
    Idea:
*/
 
#include <bits/stdc++.h>
#define FI first
#define SE second
#define EPS 1e-9
#define ALL(a) a.begin(),a.end()
#define SZ(a) int((a).size())
#define MS(s, n) memset(s, n, sizeof(s))
#define FOR(i,a,b) for (int i = (a); i <= (b); i++)
#define FORE(i,a,b) for (int i = (a); i >= (b); i--)
#define FORALL(it, a) for (__typeof((a).begin()) it = (a).begin(); it != (a).end(); it++)
//__builtin_ffs(x) return 1 + index of least significant 1-bit of x
//__builtin_clz(x) return number of leading zeros of x
//__builtin_ctz(x) return number of trailing zeros of x
 
using namespace std;
using ll = long long;
using ld = double;
typedef pair<int, int> II;
typedef pair<II, int> III;
typedef complex<ld> cd;
typedef vector<cd> vcd;
 
const ll MODBASE = 1000000007LL;
const int MAXN = 3010;
const int MAXM = 1000;
const int MAXK = 16;
const int MAXQ = 200010;

int n, q, a[MAXN];
ll dp[MAXN][MAXN];

ll binPowMod(ll a, ll b, ll m) {
    a %= m;
    ll res = 1;
    while (b > 0) {
        if (b & 1LL) res = res * a % m;
        a = a * a % m;
        b >>= 1LL;
    }
    return res;
}

ll mul(ll a, ll b) {
    return a * b % MODBASE;
}

ll add(ll a, ll b) {
    return (a + b) % MODBASE;
}

ll sub(ll a, ll b) {
    return (a - b + MODBASE) % MODBASE;
}

int main() {
    ios::sync_with_stdio(0);
    cin.tie(nullptr);
    cin >> n >> q;
    FOR(i,1,n) cin >> a[i];
    FOR(i,1,n)
        FOR(j,1,n)
            if (a[i] > a[j]) dp[i][j] = 1;
    ll inv2 = binPowMod(2, MODBASE-2, MODBASE);
    FOR(i,1,q) {
        int l, r;
        cin >> l >> r;
        FOR(x,1,n) {
            if (x == l || x == r) continue;
            dp[l][x] = dp[r][x] = mul(inv2, add(dp[l][x], dp[r][x]));
            dp[x][l] = dp[x][r] = mul(inv2, add(dp[x][l], dp[x][r]));
        }
        dp[l][r] = dp[r][l] = mul(inv2, add(dp[l][r], dp[r][l]));
    }

    ll p = binPowMod(2, q, MODBASE), res = 0;
    FOR(i,1,n) {
        FOR(j,i+1,n) {
            dp[i][j] = mul(dp[i][j], p);
            res = add(res, dp[i][j]);
            // cout << dp[i][j] << ' ';
        }
        // cout << endl;
    }
    cout << res;
    return 0;
}


Measured memory_bytes: 70784
using System;
using System.Collections.Generic;
class Program
{
	static void Main(string[] args)
	{
		long N = long.Parse(Console.ReadLine());
		string[] str = Console.ReadLine().Split();
		double[]A = new double[N];
		double sum = 0;
		for(var i=0;i<N;i++){
			A[i] = double.Parse(str[i]);
			sum += A[i];
		}
		sum /= N;
		double min = 999999;
		for(var i=0;i<N;i++){
			min = Math.Min(Math.Abs(A[i]-sum),min);
		}
		long ans = -1;
		for(var i=0;i<N;i++){
			if(Math.Abs(A[i]-sum)==min){
				ans = i;
				break;
			}
		}
		Console.WriteLine(ans);
	}
}

Measured memory_bytes: 11348
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
ll GCD(ll x,ll y){
    if(y == 0) return x;
    else return GCD(y,x%y);
}
const int MOD = 1000000007;

//while(c){
//    total += c%10;
//    c/=10;
//}

int main() {
    int n; cin >> n;
    vector<int> vec;
    for(int i = 0;i < n;i++){
        int b; cin >> b;
        vec.push_back(b);
    }
    sort(vec.begin(),vec.end());
    vec.erase(unique(vec.begin(),vec.end()),vec.end());
    cout << vec.size();
}




Measured memory_bytes: 256
#pragma GCC optimize ("O3")
#include<map>
#include<iostream>
#include<deque>
#include<algorithm>
#include<string>
#include<cctype>
#include<iomanip>
#include<vector>
#include<queue>
#include<math.h>
#include<bitset>
#include<random>
using namespace std;
using ll = __int64_t;
using lll = __int128_t;
typedef pair<ll,ll> P;
#define REP(i,b,e) for(ll i=(ll)b;i<(ll)e;i++)
#define rep0(i,n) REP(i,0ll,n)
#define rep1(i,n) REP(i,1ll,n+1)
const ll longinf=1ll<<60;
const int inf=(1<<30)-1;
const ll mod=1e9+7;


int main(){
      ll n,k;
      cin>>n>>k;
      string s;
      cin>>s;
      ll ans=0;
      for(int j=0;j<n;j++){
            if(j==0&&s[j]=='L') continue;
            if(j==(n-1)&&s[j]=='R') continue;
            if(s[j]=='L'&&s[j-1]=='L') ans++;
            if(s[j]=='R'&&s[j+1]=='R') ans++;
      }
      cout<<min(ans+2*k,n-1)<<endl;

      return 0;
}


Measured memory_bytes: 512
#include<iostream>
using namespace std;
int main()
{
	int n,ans=0;
	cin>>n;
	int a[n+1],b[n+1];
	for(int i=1;i<=n;i++)cin>>a[i];
	for(int i=1;i<=n;i++)
	{
		cin>>b[i];
		if(a[i]>b[i])ans+=a[i]-b[i];
	}
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 256
def cross_product(ax, ay, bx, by)
  ax * by - ay * bx
end


while line = gets
  xa, ya, xb, yb, xc, yc, xd, yd = line.chomp.split(',').map(&:to_f)
  s1 = cross_product(xb - xa, yb - ya, xc - xa, yc - ya)
  s2 = cross_product(xc - xb, yc - yb, xd - xb, yd - yb)
  s3 = cross_product(xd - xc, yd - yc, xa - xc, ya - yc)
  s4 = cross_product(xa - xd, ya - yd, xb - xd, yb - yd)
  puts (s1 > 0 && s2 > 0 && s3 > 0 && s4 > 0 || s1 < 0 && s2 < 0 && s3 < 0 && s4 < 0) ? :YES : :NO
end

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

using namespace std;

#define pb push_back
#define ff first
#define ss second
#define sz(x) (int)x.size()
#define all(x) (x).begin(),(x).end()
#define F(i,x,n,y) for(i=x;i<n;i+=y)
#define fi(i,x,n) for(i=x;i<n;++i)
#define f(n) for(int i=0;i<n;++i)
#define fr(i,x,n) for(i=x;i>=n;--i)
#define endl '\n'

typedef long long ll;
typedef vector<int> vi;
typedef pair<int,int> ii;

int main(){
    ios::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    int i,n;
    cin>>n>>i;
    cout<<n-i+1<<endl;

    return 0;
}



Measured memory_bytes: 256
/**
 * code generated by JHelper
 * More info: https://github.com/AlexeyDmitriev/JHelper
 * @author
 */

#include <iostream>
#include <fstream>

#include <iostream>
#include <string>
#include <vector>
#include <math.h>
#include <map>
#include <set>
#include <algorithm>
#include <numeric>
#include <bitset>
using namespace std;
using ll = long long;
constexpr ll INF = 1010000000000000017LL;
#define rep(i, n) for(ll i = 0; i < (ll)(n); i++)
#define all(v) v.begin(), v.end()

class CPushpush {
public:
	void solve(std::istream& in, std::ostream& out) {
        ll n;
        in>>n;
        vector<ll> v(n);
        vector<ll> b;
        vector<ll> f;

        rep(i,n){
            ll tmp;
            in>>tmp;
            if(i%2==0) b.push_back(tmp);
            else f.push_back(tmp);
        }
        if(n%2==0) {
            reverse(all(f));

            rep(i, f.size()) {
                out << f.at(i) << ' ';
            }

            rep(i, b.size()) {
                out << b.at(i) << ' ';
            }
        } else {
            reverse(all(b));
            rep(i,b.size()) out<<b.at(i)<<' ';
            rep(i,f.size()) out<<f.at(i)<<' ';
        }



	}
};


int main() {
	CPushpush solver;
	std::istream& in(std::cin);
	std::ostream& out(std::cout);
	solver.solve(in, out);
	return 0;
}


Measured memory_bytes: 5860
# coding: utf-8
# Your code here!
#A,B= list(map(int,input().split()))	


words=[]
N=int(input())
ok=1
for i in range(N):
    s=input()
    if s in words:
        ok = 0
#        print("double",s)
        break
    
    if i != 0 and words[-1][-1] != s[0]:
        ok=0
#        print(words[-1][-1], s[0],i)
        break

    words.append(s)

if ok==0:
    print("No")
else:
    print("Yes")
    

Measured memory_bytes: 2940
n, a, b = [int(x) for x in input().split()]

if (a != b and n == 1) or a > b:
    print(0)
else:
    lowest_pos = a * (n - 1) + b
    highest_pos = a + b * (n - 1)
    print(highest_pos - lowest_pos + 1)


Measured memory_bytes: 2940
// luogu-judger-enable-o2
#include<bits/stdc++.h>
using namespace std;
int a,b,c;
int main(){
	cin>>a>>b>>c;
    for(int i=1;i<=b;i++){
    	if((i*a)%b==c){
    		cout<<"YES"<<endl;
    		return 0;
    	}
    }
    cout<<"NO"<<endl;
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <string.h>

using namespace std;
int dp[50][3001];

void solve()
{
	int N, M, S;
	while(cin >> N >> M >> S, N || M || S)
	{
		memset(dp, 0, sizeof(dp));
		dp[0][0] = 1;
		for (int i = 1; i <= M; ++i)
		{
			for (int j = N * N; j > 0; --j)
			{
				for (int k = S; k >= i; --k)
				{
					dp[j][k] = (dp[j][k] + dp[j-1][k-i]) % 100000;
				}
			}
		}
		cout << dp[N * N][S] << endl;
	}
}

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

Measured memory_bytes: 0
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef long double ld;
#define  fo(i,a,b) for(ll i=a;i<b;i++)
#define rfo(i,a,b) for(ll i=a;i>=b;i--)
#define fori(it, x) for (__typeof((x).begin()) it = (x).begin(); it != (x).end(); it++)

#define err() cout<<"----------"<<endl;
#define errA(A) for(auto i:A)   cout<<i<<" ";cout<<endl;
#define pb push_back
#define deb(x) cout<< #x << " = "<<x<<endl;
#define F first
#define S second
#define MP make_pair
#define all(x) (x).begin(), (x).end()
#define pi 3.141592653589
void solve()
{
    ll n;
    cin>>n;
    if(n%1000==0)
    {
        cout<<0<<endl;
    }
    else
    {
        cout<<(1000-n%1000)<<endl;
    }
}
int main()
{

    #ifndef ONLINE_JUDGE
        freopen("input.txt","r",stdin);
        freopen("output.txt","w",stdout);
    #endif
//  clock_t time_req;
//  time_req = clock();
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    ll t=1;
    //cin>>t;
    while(t--)
    {
        solve();
    }

// time_req = clock()-time_req;
//  cout<<"Time taken: "<<(float)time_req/CLOCKS_PER_SEC<<"s"<<endl;

    return 0;
}

Measured memory_bytes: 3652
#include<stdio.h>
int main()
{
	int x[6],i;
	for(i=1;i<=5;i++){
		scanf("%d",&x[i]);
	}
	for(i=1;i<=5;i++){
		if(x[i]==0){
			printf("%d\n",i);
		}
	}
	return 0;
}

Measured memory_bytes: 1640
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner scanner = new Scanner(System.in);
		String a = scanner.next();
		String b = scanner.next();
		String c = scanner.next();
		scanner.close();
		
		String ans = a.substring(0, 1) + b.substring(1, 2) + c.substring(2, 3);
		System.out.println(ans);

	}

}


Measured memory_bytes: 21844
from collections import deque

N, Q = map(int, input().split()) # Nは頂点の数、Qは操作の回数
graph = [[] for _ in range(N+1)]
for _ in range(N-1):
    a, b = map(int, input().split())
    graph[a].append(b)
    graph[b].append(a)

counts = [0] * (N+1)
for _ in range(Q):
    p, x  = map(int, input().split())
    counts[p] += x
visited = [-1] * (N+1)

q = deque()
q.append(1)
visited[1] = 1
while q:
    node = q.pop()

    next_nodes = graph[node]
    for next in next_nodes:
        if visited[next] != -1:
            continue
        q.append(next)
        visited[next] = 1
        counts[next] += counts[node]

print(*counts[1:])




Measured memory_bytes: 58280