akhauriyash/Code-Regression huggingface dataset:
# F - Tree and Constraints

# Read input

n = int(input())
adj = {a: [] for a in range(1, n + 1)}
for i in range(n - 1):
    a, b = map(int, input().split())
    adj[a].append((b, i))
    adj[b].append((a, i))
m = int(input())
ranges = [tuple(map(int, input().split())) for i in range(m)]

# Subroutines

def findpath(u, v, parent=None):
    """uからvへの経路 (辺の集合)"""
    if u == v:
        return set()
    for x, i in adj[u]:
        if x == parent:
            continue
        p = findpath(x, v, u)
        if p is not None:
            p.add(i)  # id of edge
            return p
    return None

def powerset(seq, bag):
    """[(seqの部分集合s, bag[e] for e in s の和集合)]"""
    if len(seq) <= 1:
        yield ((seq[0],), bag[seq[0]])
        yield ((), set())
    else:
        for s, b in powerset(seq[1:], bag):
            yield ((seq[0],) + s, b | bag[seq[0]])
            yield (s, b)

# Find paths

paths = [findpath(u, v) for u, v in ranges]

# いずれかの区間をすべて白にする塗り方の個数
white = 0
for s, b in powerset(list(range(m)), paths):
    l = len(s)
    if l <= 0:
        continue
    # b中の辺をすべて白にする塗り方の個数
    w = 2 ** (n - 1 - len(b))
    # 包除原理
    sign = -1 if l % 2 == 0 else 1    
    white += sign * w

# どの区間も黒を含む塗り方の個数
coloring = 2 ** (n - 1) - white
print(coloring)


Measured memory_bytes: 48092
#include <iostream>
#include <algorithm>
#include <queue>
#include <vector>
using namespace std;
typedef long long ll;
typedef struct pair<int,int> P;
typedef struct pair<int,P> P2;

int n;

int dp[31][1000001]={};
int d[31][1000001]={};

const ll INF=100000000001;
int main() {
	char chr[4];
	cin>>chr;
	int a=chr[0]-48;
	int b=chr[1]-48;
	int c=chr[2]-48;
	int d=chr[3]-48;

	if(a+b+c+d==7){
		cout<<a<<"+"<<b<<"+"<<c<<"+"<<d<<"=7"<<endl;
	}else if(a+b+c-d==7){
		cout<<a<<"+"<<b<<"+"<<c<<"-"<<d<<"=7"<<endl;
	}else if(a+b-c+d==7){
		cout<<a<<"+"<<b<<"-"<<c<<"+"<<d<<"=7"<<endl;
	}else if(a+b-c-d==7){
		cout<<a<<"+"<<b<<"-"<<c<<"-"<<d<<"=7"<<endl;
	}else if(a-b+c+d==7){
		cout<<a<<"-"<<b<<"+"<<c<<"+"<<d<<"=7"<<endl;
	}else if(a-b+c-d==7){
		cout<<a<<"-"<<b<<"+"<<c<<"-"<<d<<"=7"<<endl;
	}else if(a-b-c+d==7){
		cout<<a<<"-"<<b<<"-"<<c<<"+"<<d<<"=7"<<endl;
	}else if(a-b-c-d==7){
		cout<<a<<"-"<<b<<"-"<<c<<"-"<<d<<"=7"<<endl;
	}
	return 0;
}


Measured memory_bytes: 256
import sys
stdin = sys.stdin

sys.setrecursionlimit(10 ** 7)

def li(): return map(int, stdin.readline().split())
def li_(): return map(lambda x: int(x) - 1, stdin.readline().split())
def lf(): return map(float, stdin.readline().split())
def ls(): return stdin.readline().split()
def ns(): return stdin.readline().rstrip()
def lc(): return list(ns())
def ni(): return int(stdin.readline())
def nf(): return float(stdin.readline())

s = lc()
n = len(s)

tol = [0]*n
tor = [0]*n
ans = [0]*n

# Rにいる子のLまでの距離
dist = 0
for i in range(n-1, -1, -1):
    if s[i] == "L":
        dist = 0
    else:
        dist += 1
        tol[i] = dist

# Lにいる子のRまでの距離
dist = 0
for i in range(n):
    if s[i] == "R":
        dist = 0
    else:
        dist += 1
        tor[i] = dist

# それぞれの最終的な位置
for j, tolj in enumerate(tol):
    if tolj == 0:
        continue
    elif tolj % 2:
        ans[j + tolj - 1] += 1
    else:
        ans[j + tolj] += 1

for j, torj in enumerate(tor):
    if torj == 0:
        continue
    elif torj % 2:
        ans[j - torj + 1] += 1
    else:
        ans[j -torj] += 1

print(*ans)




Measured memory_bytes: 11812
#include <iostream>
#include <math.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <queue>
#include <stack>
#include <vector>
#include <algorithm>
#include <map>
#include <unordered_map>
#include <set>
#include <deque>
#include <utility>

long long GCD(long long x, long long y){
  long long max = std::max(x, y);
  long long min = std::min(x, y);
  if (min==0){
    return x;
  } else {
    return GCD(min, max%min);
  }
}

int main() {
  int N;
  scanf("%d", &N);
  std::vector<long long > A(N), B(N);
  std::map<std::pair<long long, long long >, std::pair<int, int> > mp;
  int zero=0;
  for (int i=0; i<N; i++){
    scanf("%lld", &A[i]);
    scanf("%lld", &B[i]);
    if (A[i]==0 && B[i]==0){
      zero++;
    } else {
      long long gcd = GCD(abs(A[i]), abs(B[i]));
      if (A[i]<0) {
	A[i] *= -1;
	B[i] *= -1;
      }
      //printf("gcd=%lld\n", gcd);
      if (B[i]==0){
	mp[std::make_pair(1, 0)].second++;
      } else if (A[i]==0){
	mp[std::make_pair(1, 0)].first++;
      } else if (B[i]<0){
	mp[std::make_pair(-B[i]/gcd, A[i]/gcd)].second++;
      } else {
	mp[std::make_pair(A[i]/gcd, B[i]/gcd)].first++;
      }
    }
  }
  long long ans = 1;
  std::vector<long long > power2(N+4);
  power2[0]=1;
  long long mod = 1e9+7;
  for (int i=1; i<N+4; i++){
    power2[i]=power2[i-1]*2;
    power2[i]%=mod;
  }
  
  for (auto &entry: mp){
    int num1= entry.second.first;
    int num2= entry.second.second;
    //printf("x=%lld, y=%lld, num1=%lld, num2=%lld\n", x,y,num1,num2);
    //printf("num1=%lld, num2=%lld\n", num1,num2);
    ans *= power2[num1]+power2[num2]-1;
    if (ans>=mod)ans %= mod;
    else if (ans<0)ans+=mod;
  }
  ans+=zero;
  ans--;
  if (ans>=mod)ans %= mod;
  else if (ans<0)ans += mod;
  std::cout << ans << std::endl;
  return 0;
}

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

#define fi first
#define se second
#define vi vector<int>
#define vpi vector<pair<int,int>>
#define vll vector<ll>
#define vpll vector<pair<ll,ll>>
#define endl '\n'

#define si(v) int(v.size())
#define all(v) v.begin(), v.end()
#define rep(i, n) for (ll i = 0; i < (n); ++i)
#define rep2(i, n, m) for (ll i = n; i <= (m); ++i)
#define rep3(i, n, m) for (ll i = n; i >= (m); --i)

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

using ll = long long;
using ld = long double;
using namespace std;

constexpr ll MOD = 1000000007;

signed main()
{
  cout << fixed << setprecision(20);
  ios::sync_with_stdio(false);
  cin.tie(0);
  
  int n; cin >> n;
  vll a(n);
  rep(i, n) cin >> a[i];

  int ans = 0;
  for (int i = 0; i < n; ++i) {
    for (int j = i+1; j < n; ++j) {
      for (int k = j+1; k < n; ++k) {
        if (a[i] == a[j] || a[j] == a[k] || a[i] == a[k]) continue;

        if (a[i] + a[j] > a[k] && a[j] + a[k] > a[i] && a[k] + a[i] > a[j]) ++ans;
      }
    }
  }

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

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

using namespace std;

int main(){
    long long N;
    cin >> N;
    long long arr[N];
    for(long long i = 0; i < N; i++){
        cin >> arr[i];
    }
    long long mn = arr[0];
    long long ans = 1;
    for(long long i = 1; i < N; i++){
        if(arr[i] < mn){
            mn = arr[i];
            ans++;
        }
    }
    cout << ans << endl;
    return 0;
}

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

int main()
{
	int n,k;
	cin>>n>>k;
	int i = 1;
	int kk = k;
	while(true)
	{
		if(n<kk)
			break;
		i++;
		kk *= k;
	}
	cout<<i<<endl;
	return 0;
}



Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int a[101101];
int main()
{	
	int check,n;
	cin>>n;
	for(int i=1; i<=n; i++)
	{
		cin>>a[i];
	}
	sort(a+1,a+1+n);
	for(int i=1; i<=n; i++)
	{
		if(a[i]==a[i-1])check++;
	}
	if(check%2==1) check++;
	cout<<n-check<<endl;
	return 0;

}

Measured memory_bytes: 640
def get_i() #空白区切の入力を数値(整数)の配列で返す
  return gets.chomp.split(" ").map(&:to_i)
end
def get_f() #空白区切の入力を数値(実数)の配列で返す
  return gets.chomp.split(" ").map(&:to_f)
end
def get() #空白区切の入力を文字列の配列で返す
  return gets.chomp.split(" ")
end
def get_nsp() #入力されたものを一文字ずつに区切った文字列の配列で返す
  return gets.chomp.split("")
end
def yn_judge(bool,y="Yes",n="No") #boolに真偽を投げることで、trueならy、falseならnの値を出力する
  return bool ? y : n 
end
def array(size1,init=nil,size2=1) #size2に二次元配列時の最初の要素数、size1に次の配列の大きさ、initに初期値を投げることでその配列を返す
  if size2==1
    return Array.new(size1){init}
  else
    return Array.new(size2){Array.new(size1){init}}
  end
end

def max(a,b)
    return a>b ? a : b
end
N=gets.to_i
A,B=get_i
topping=array(N)
col=gets.to_i
N.times do|i|
    topping[i]=gets.to_i
end
topping.sort!{|x,y| x<=>y}
dp=array((N+1)*1000+1,0)

dp[A]=col
N.times do|i|
    ((N+1)*1000).downto(A+B) do|j|
        dp[j]=max(dp[j],dp[j-B]+topping[i])
    end
end
ans=0
1.upto((N+1)*1000) do|i|
  ans=dp[i]/i if ans<dp[i]/i
end
puts ans


Measured memory_bytes: 7676
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <string>
#include <cstring>
#include <deque>
#include <list>
#include <queue>
#include <stack>
#include <vector>
#include <utility>
#include <algorithm>
#include <map>
#include <set>
#include <complex>
#include <cmath>
#include <limits>
#include <climits>
#include <ctime>
#include <cassert>
using namespace std;

#define rep(i,a,n) for(int (i)=(a); (i)<(n); (i)++)
#define repq(i,a,n) for(int (i)=(a); (i)<=(n); (i)++)
#define repr(i,a,n) for(int (i)=(a); (i)>=(n); (i)--)
#define all(v) begin(v), end(v)
#define pb(a) push_back(a)
#define fr first
#define sc second
#define INF 2000000000
#define int long long int

#define X real()
#define Y imag()
#define EPS (1e-10)
#define EQ(a,b) (abs((a) - (b)) < EPS)
#define EQV(a,b) ( EQ((a).X, (b).X) && EQ((a).Y, (b).Y) )
#define LE(n, m) ((n) < (m) + EPS)
#define LEQ(n, m) ((n) <= (m) + EPS)
#define GE(n, m) ((n) + EPS > (m))
#define GEQ(n, m) ((n) + EPS >= (m))

typedef vector<int> VI;
typedef vector<VI> MAT;
typedef pair<int, int> pii;
typedef long long ll;

typedef complex<double> P;
typedef pair<P, P> L;
typedef pair<P, double> C;

int dy[]={0, 0, 1, -1};
int dx[]={1, -1, 0, 0};
int const MOD = 1000000007;

namespace std {
    bool operator<(const P& a, const P& b) {
        return a.X != b.X ? a.X < b.X : a.Y < b.Y;
    }
}

int calc(int a, int b, int c) {
    return 3600*a + 60*b + c;
}

signed main() {
    int n;
    while(cin >> n, n) {
        int rec[100010] = {};
        rep(i,0,n) {
            int a, b, c, d, e, f;
            scanf(" %lld:%lld:%lld", &a, &b, &c);
            scanf(" %lld:%lld:%lld", &d, &e, &f);
            int s = calc(a, b, c), t = calc(d, e, f);
            rec[s]++; rec[t]--;
        }
        rep(i,1,100000) {
            rec[i] += rec[i-1];
        }
        cout << *max_element(rec, rec+100000) << endl;
    }
    return 0;
}

Measured memory_bytes: 3820
#include <bits/stdc++.h>
#define ull uint64_t
#define ll long long int
#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define mx5 100005
#define mx6 1000005
#define mod 1000000007
#define nfs ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
using namespace std;

ll out[3001][3001] = {}, total = 0;
    
int main() {
    nfs
    int i, j, d, n, a[3001];
    
    cin >> n;
    

    for (i = 0; i < n; i++) {
        cin >> a[i];
        total += a[i];
        out[i][i] = (n&1) ? a[i] : 0; 
    }
    for (d = 1; d < n; d++) {
        bool fturn = (n-d)&1;
        for (i = 0, j = i + d; i < n-d; i++, j++) {
            if (fturn)
                out[i][j] = max(a[i] + out[i+1][j], a[j] + out[i][j-1]);
            else
                out[i][j] = min(out[i+1][j], out[i][j-1]);
        }
    }
    cout << 2*out[0][n-1] - total;
}

Measured memory_bytes: 49808
import  itertools
d,g=map(int,input().split())
p=[]
c=[]
for i in range(d):
    x,y=map(int,input().split())
    p.append(x)
    c.append(y)
ans=float('inf')
def judge(tmp):
    ss=g
    count=0
    for i in range(d):
        if tmp[i]==1:
            ss-=((i+1)*p[i]*100+c[i])
            count+=p[i]
    if ss<=0:
        return count
    else:
        for i in range(d-1,-1,-1):
            if tmp[i]==0:
                if ss%((i+1)*100)==0:
                    fgh=ss//((i+1)*100)
                else:
                    fgh=1+ss//((i+1)*100)
                if fgh>=p[i]:
                    count+=float('inf')
                else:
                    count+=fgh
                ss -= fgh * ((i + 1) * 100)
            if ss<=0:
                return count
        return count+float('inf')
nums=[0,1]
for sd in itertools.product(nums,repeat=d):
    pat=list(sd)
    sdf=judge(pat)
    ans=min(ans,sdf)
print(ans)

Measured memory_bytes: 3064
# B
# 2020/03/02 12:44-
n = int(input())
def SumDegit(n):
    ans = 0
    while n > 0:
        ans += n%10
        n = n//10
    return ans

if n%SumDegit(n) == 0:
    print('Yes')
else:
    print('No')

Measured memory_bytes: 2940
#include <iostream>

using namespace std;

int gcd(int a, int b)
{
	while(a != 0)
	{
		if (a < b)
			swap(a, b);

		a = a % b;
	}
	return b;
}

int main()
{
	int N;
	cin >> N;
	int A[100000];
	for (int i = 0; i < N; i++)
		cin >> A[i];
	int ans = gcd(A[0], A[1]);

	for (int i = 2; i < N; i++)
		ans = gcd(ans, A[i]);
	
	cout << ans;
	
	return 0;
}

Measured memory_bytes: 640
#include <bits/stdc++.h>
#define rep(i,n)for(long long i=0;i<(long long)(n);++i)
#define all(a) a.begin(), a.end()
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll, ll> P;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
 
const ll MOD=1e9+7;
const ll INF=1e18;
const int MAX=510000;
const double pi=acos(-1);
int dx[8] = {1,0,-1,0,1,1,-1,-1};
int dy[8] = {0,1,0,-1,-1,1,1,-1};
// int d[13]={0,31,28,31,30,31,30,31,31,30,31,30,31};



int main(){
  string s;
  cin >> s;
  int n=s.size();
  int cnt1=0,cnt2=0;
  rep(i,n){
    if(i%2==0 && s[i]=='0'){
      cnt1++;
    }
    else if(i%2==1 && s[i]=='1'){
      cnt1++;
    }
  }
  rep(i,n){
    if(i%2==0 && s[i]=='1'){
      cnt2++;
    }
    else if(i%2==1 && s[i]=='0'){
      cnt2++;
    }
  }
  cout << min(cnt1,cnt2) << endl;
}

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

int main(){
    ll H;
    cin >> H;
    ll ans = 0;
    ll cnt = 1;
    while(H>0){
        H >>= 1;
        ans += cnt;
        cnt <<= 1;
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
#include<iterator>
#include<algorithm>
#include<vector>
#include<map>
#include<iostream>
auto main ( ) -> int
{
    using namespace std ;
    vector < int > ns ;
    copy ( istream_iterator < int > { cin } , istream_iterator < int > { } , back_inserter ( ns ) ) ;
    map < int , int > table ;
    for ( auto n : ns )
    {
        auto table_find = table.find ( n ) ;
        if ( table_find != table.end ( ) )
	{
            ++ table_find->second ;
	}
	else
	{
            table [ n ] = 1 ;
	}
    }
    vector < pair < int , int > > sorted_table ;
    for ( auto p : table )
    {
        sorted_table.emplace_back ( p.second , p.first ) ;
    }
    sort ( sorted_table.rbegin ( ) , sorted_table.rend ( ) , [ ] ( pair < int , int > p1 , pair < int , int > p2 ) { return make_pair ( p1.first , p2.second ) < make_pair ( p2.first , p1.second ) ; } ) ;
    sorted_table.erase ( remove_if ( sorted_table.begin ( ) , sorted_table.end ( ) , [ sorted_table ] ( pair < int , int > p ) { return p.first < sorted_table [ 0 ].first ; } ) , sorted_table.end ( ) ) ;
    for ( auto p : sorted_table )
    {
        cout << p.second << endl ; 
    }
}

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

int main()
{
    int N;
    cin>>N;
    string a;
    cin>>a;

    vector<int> x(N-1);
    for (int i=0; i<N-1; i++)
        x[i] = abs(a[i]-a[i+1]);
    N--;

    int a1 = 0;
    for (int i=0; i<N; i++)
    {
        int c = int(((N-1)|i)==N-1);
        a1 += c*(x[i]%2);
    }
    a1 %= 2;
    if (a1==1)
    {
        cout<<a1<<endl;
        return 0;
    }
    for (int i=0; i<N; i++)
        if (x[i]==1)
        {
            cout<<0<<endl;
            return 0;
        }
    int a2 = 0;
    for (int i=0; i<N; i++)
    {
        int c = int(((N-1)|i)==N-1);
        a2 += c*(x[i]/2);
    }
    cout<<a2%2*2<<endl;
}


Measured memory_bytes: 5236
s = input()
n = int(s)
l = len(s)

if l==1:
    print(n)
elif l==2:
    print(9)
elif l==3:
    print(n-90)
elif l==4:
    print(909)
elif l==5:
    print(n-9090)
else:
    print(90909)

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

// header area

int main(){
    int A, B; cin >> A >> B;

    if(A<10 && B<10) cout << A*B << endl;
    else cout << -1 << endl;

    return 0;
}

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

using namespace std;

main(){
    string s1, s2;

    cin >> s1 >> s2;
    if(s1[0]==s2[2] and s1[1]==s2[1] and s1[2]==s2[0]) cout << "YES" << endl;
    else cout << "NO" << endl;
}

Measured memory_bytes: 256
import java.util.*;

public class Main {
	public static void main (String[] args) {
		Scanner sc = new Scanner(System.in);
		int l = sc.nextInt();
		int n = sc.nextInt();
		StringBuilder sb = new StringBuilder();
		sb.append(n).append("\n");
		for (int i = 0; i < n; i++) {
		    int x = sc.nextInt();
		    int w = sc.nextInt();
		    sb.append(-x).append(" ").append(w).append("\n");
		}
		System.out.print(sb);
	}
}



Measured memory_bytes: 26248
#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;

#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define fbo find_by_order
#define ook order_of_key

typedef long long ll;
typedef pair<ll,ll> ii;
typedef vector<int> vi;
typedef long double ld;
typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> pbds;

int main(){
    ios_base::sync_with_stdio(0); cin.tie(0);
    char a,b;
    cin>>a>>b;
    if(a=='H'){
        cout<<b<<endl;
    }
    else{
        if(b=='D')
            cout<<'H'<<endl;
        else
            cout<<'D'<<endl;
    }
    return 0;
}


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

int main() {
  vector<int> n(3);
  for(int i=0; i<3 ; i++){
    cin >> n[i];
  }
  
  int f=0;
  int s=0;
  
  for(int x : n){
    if(x==5) f++;
    else if(x==7) s++;
  }
  
  if(f==2 && s==1) cout << "YES" << endl;
  else cout << "NO" << endl;
}


Measured memory_bytes: 256
use std::vec::Vec;

fn read<T: std::str::FromStr>() -> T {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).ok();
    s.trim().parse().ok().unwrap()
}

fn read_vec<T: std::str::FromStr>() -> Vec<T> {
    read::<String>().split_whitespace().map(|e| e.parse().ok().unwrap()).collect()
}

fn read_touple<T: std::str::FromStr + Copy>() -> (T, T) {
  let v: Vec<T> = read_vec();
  assert_eq!(v.len(), 2);
  (v[0], v[1])
}

fn main() {
    let a: Vec<usize> = read_vec();

    if a[1] + a[2] + a[0] >= 22 {
      println!("bust");
    } else {
      println!("win");
    }
}


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

#ifdef DEBUG
#include "../.inc/debug.hpp"
#else
#define debug(...) 42
#define rdfile(...) 42
#endif

int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    // rdfile("_input.txt");

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

    vector<int> b(n, 0);
    for (int i=n; i>=1; --i) {
        if (n < i*2) {
            b[i-1] = a[i-1];
            continue;
        }
        int sum = 0;
        for (int j=i*2; j<=n; j+=i) {
            sum += b[j-1];
            sum %= 2;
        }
        if (sum == a[i-1]) {
            b[i-1] = 0;
        } else {
            b[i-1] = 1;
        }
    }

    vector<int> ans;
    for (int i=0; i<n; ++i) {
        if (b[i] > 0) {
            ans.push_back(i+1);
        }
    }
    
    int m = ans.size();
    cout << m << endl;
    for (int i=0; i<m; ++i) {
        cout << ans[i] << endl;
    }

    return 0;
}

Measured memory_bytes: 3192
n = int(input())
import numpy as np
li = np.array([ int(it) for it in input().split()])
cs = np.cumsum(li)
import collections
cd = collections.Counter(cs)
sm = 0
for k,v in cd.items():
  p = v - 1 + (1 if k==0 else 0)
  sm += (p*(p+1))//2
print (sm)
  

Measured memory_bytes: 39396
//============================================================================
// Name        : abc141_d.cpp D - Powerful Discount Tickets
// Author      :
// Version     :
// Copyright   : Your copyright notice
// Description : https://atcoder.jp/contests/abc141/tasks/abc141_d
//============================================================================

#pragma GCC optimize ("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")

#include <bits/stdc++.h>
using namespace std;

// 数値の読み取り, 低速な cin の使用を回避する
inline int read() {
	int f = 1, x = 0; // 負数フラグ、絶対値
	char ch = getchar();
	while (ch < '0' || ch > '9') { // 数値以外を飛ばす
		if (ch == '-') { // ただし '-' のとき負数フラグを立てる
			f = -1;
		}
		ch = getchar();
	}
	while (ch >= '0' && ch <= '9') { // 数値の読み取り
		x = x * 10 + (ch - '0');
		ch = getchar();
	}
	return x * f;
}

// 数値の書き出し, 低速な cout の使用を回避する
template<typename T>inline void write(T n) {
	int i = 0;
	char b[30];
	if (!n) {
		putchar('0');
	} else {
		if (n < 0) { // 負数のとき負号出力
			putchar('-');
			n *= -1;
		}
		i = 0;
		while (n) { // 下の桁から順番に文字にして b に格納
			b[i++] = '0' + (n % 10);
			n /= 10;
		}
		while (i--) { // 上の桁から順番に出力
			putchar(b[i]);
		}
	}
	putchar('\n');
}

int N, M;
int main() {
	N = read(); // 品物数
	M = read(); // 割引券枚数

	// 品物値段 A_1(=A[0]) ~ A_N(=A[N-1]) の読み取り
	priority_queue<long long> A;
	for (int i = 0; i < N; ++i) {
		A.push(read());
	}
	// 割引適用 M 枚
	long long max;
	for (int j = 0; j < M; ++j) {
		max = A.top();
		A.pop();
		A.push(max >> 1);
	}
	long long sum = 0;
	for (int i = 0; i < N; ++i) {
		sum += A.top();
		A.pop();
	}
	write(sum);
	return 0;
}


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

using namespace std;

int main() {
    int A, cnt = 0;
    for (int i = 0; i < 3; ++i) {
        cin >> A;
        cnt += A;
    }

    if (cnt >= 22) {
        cout << "bust" << endl;
        return 0;
    } else {
        cout << "win" << endl;
        return 0;
    }
}

Measured memory_bytes: 3604
/*
 * ID: 3000
 * Problem: mean of two angles
 */

#include <stdio.h>

int main(void)
{
    int a, b;
    scanf("%d", &a);
    scanf("%d", &b);

    if (a > b) {
        int t = a;
        a = b;
        b = t;
    }

    int d = b - a;
    double t;
    if (d < 180) 
        t = d / 2.0 + a;
    else
        t = (360 - d) / 2.0 + b;
    if (t > 360.0)
        t -= 360.0;

    printf("%f\n", t);

    return 0;
}



Measured memory_bytes: 2108
#!/usr/bin/env python3
import sys
import math

def solve(a: int, b: int, x: int):
    if x<= b*a**2/2:
        print(math.degrees(math.atan((a*b**2)/(2*x))))
    else:
        print(math.degrees(math.atan(2*b/a-(2*x)/a**3)))
    return


def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    a = int(next(tokens))  # type: int
    b = int(next(tokens))  # type: int
    x = int(next(tokens))  # type: int
    solve(a, b, x)

if __name__ == '__main__':
    main()


Measured memory_bytes: 3064
#include<stdio.h>
#include<iostream>
#include<vector>
#include<math.h>
#include<queue>
#include<map>
#include<algorithm>
#include<string.h>
#include<functional>
#include<limits.h>
#include<stdlib.h>
#include<cmath>
#include<cstring>
#include<set>
#include<climits>
#include<deque>
#include <iomanip>
#include<utility>
using namespace std;

#define intmax INT_MAX
#define lmax LONG_MAX
#define uintmax UINT_MAX
#define ulmax ULONG_MAX
#define llmax LLONG_MAX
#define ll long long
#define rep(i,a,N) for((i)=(a);(i)<(N);(i)++)
#define rrp(i,N,a) for((i)=(N)-1;(i)>=(a);(i)--)
#define llfor ll i,j
#define sc(a) cin>>a
#define pr(a) cout<<a<<endl
#define pY puts("YES")
#define pN puts("NO")
#define py puts("Yes")
#define pn puts("No")
#define pnn printf("\n")
#define all(a) a.begin(),a.end()
#define push(a,b) (a).push_back(b)
#define llvec vector<vector<ll>>
#define charvec vector<vector<char>>
#define size(a,b) (a,vector<ll>(b))
#define llpvec vector<pair<ll,ll>>
#define S 21 
llfor;ll mod=1000000007;
/*pi*/double pi=acos(-1);
/*繰り上げ除算*/ll cei(ll x,ll y){ll ans=x/y;if(x%y!=0)ans++;return ans;}
/*最大公約数*/ll gcd(ll x,ll y){return y?gcd(y,x%y):x;}
/*最小公倍数*/ll lcm(ll x,ll y){return x/gcd(x,y)*y;}
/*n乗*/ll llpow(ll x,ll n){ll ans=1;rep(i,0,n){ans*=x;ans%=mod;}return ans;}
/*階乗*/ll fact(ll x){ll ans=1;rep(i,0,x)ans*=(x-i);return ans;}
/*nCr*/ll ncr(ll n,ll r){return fact(n)*fact(n-r)/fact(r);}
/*nPr*/ll npr(ll n,ll r){return fact(n)/fact(n-r);}
/*primejudge*/bool prime(ll a){if(a<=1)return false;for(i=2;i*i<=a;i++){if(a%i==0)return false;}return true;}
/*Fibonacci数列*/ll fib(ll x){ll fibo[x+10];fibo[0]=1;fibo[1]=1;fibo[2]=1;rep(i,3,x+1)fibo[i]=fibo[i-1]+fibo[i-2];return fibo[x];}
/*桁数*/ll dig(ll n){ll d=1,tmp=n;while(tmp/10>0){tmp/=10;d++;}return d;}
/*行列のコピー*/void matcpy(ll a[S][S],ll b[S][S]){ll t=i;rep(i,0,S)rep(j,0,S)b[i][j]=a[i][j];/*(aをbに)*/i=t;}
/*行列のリセット*/void matrst(ll a[S][S]){ll t=i;rep(i,0,S)rep(j,0,S)a[i][j]=0;i=t;}
/*行列の2乗*/void matpow(ll a[S][S]){ll ans[S][S];matrst(ans);ll t=i,k;rep(i,0,S)rep(j,0,S)rep(k,0,S)ans[i][j]+=a[i][k]*a[k][j];matcpy(ans,a);i=t;}
/*行列の乗算*/void matmul(ll a[S][S],ll b[S][S], ll as[S][S]){ll t=i,k;matrst(as);rep(i,0,S)rep(j,0,S)rep(k,0,S)as[i][j]+=a[i][k]*b[k][j];i=t;}
//ll ans=0;
////////////////////////////////////////////////////////////
int main(){
 ll n;
 cin>>n;
 ll a,cnt=0;
 rep(i,0,n){
  cin>>a;
  if(a%2)cnt++;
 }
 if(cnt%2)pN;
 else pY;
return 0;}




Measured memory_bytes: 3596
###template###
import sys
def input(): return sys.stdin.readline().rstrip()
from collections import defaultdict, Counter
from itertools import product, groupby, count, permutations, combinations
from math import pi, sqrt, ceil, floor
from collections import deque
from bisect import bisect, bisect_left, bisect_right
from string import ascii_lowercase
import heapq
INF = float("inf")
sys.setrecursionlimit(10**7)
# 4近傍（右, 下, 左, 上）
dy = [0, -1, 0, 1]
dx = [1, 0, -1, 0]
def inside(y: int, x: int, H: int, W: int) -> bool: return 0 <= y < H and 0 <= x < W
def mi(): return map(int, input().split())
def ii(): return int(input())
###template###

n = ii()
Ps = list(mi())

ans = 0
for i in range(1, n-1): #1~n-2について確認
  if sorted([Ps[i-1],Ps[i],Ps[i+1]])[1] == Ps[i]:
    ans += 1

print(ans)



Measured memory_bytes: 38640
#include <bits/stdc++.h>
#define int long long
#define bp __builtin_popcountll
#define pb push_back
#define in(s) freopen(s, "r", stdin);
#define out(s) freopen(s, "w", stdout);
#define inout(s, end1, end2) freopen((string(s) + "." + end1).c_str(), "r", stdin),\
		freopen((string(s) + "." + end2).c_str(), "w", stdout);
#define fi first
#define se second
#define bw(i, r, l) for (int i = r - 1; i >= l; i--)
#define fw(i, l, r) for (int i = l; i < r; i++)
#define fa(i, x) for (auto i: x)
using namespace std;
const int mod = 1e9 + 7, inf = 1061109567;
const long long infll = 4557430888798830399;
const int MAX = 4e18 + 5, MAX2 = 1e18;
int mul(int a, int b) {
	if (a == 0 || b == 0) return 0;
	if (a > MAX / b) return MAX;
	return a * b;
}
signed main() {
	#ifdef BLU
	in("blu.inp");
	#endif
	ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
	int n, ans = 1;
	cin >> n;
	fw (i, 0, n) {
		int x;
		cin >> x;
		ans = mul(ans, x);
	}
	if (ans > MAX2) cout << "-1";
	else cout << ans;
	return 0;
}

Measured memory_bytes: 3692
/********************/
/* K B G D E L T A */
/*     DA-IICT      */
/********************/
 
#include<bits/stdc++.h>
using namespace std;
using   ll=long long;
using   ld=long double;
#define fast           ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define endl           "\n"
#define F(i,n)         for(ll i=0;i<n;i++)
#define rep(i,a,b)     for(ll i=a;i<b;i++)
#define repp(i,a,b)    for(ll i=a;i>=b;i--)
#define pb             push_back
#define mp             make_pair
#define vll            vector<ll>
#define f              first
#define s              second
#define pll            pair<ll,ll>
#define ALL(v)         v.begin(),v.end()
#define ALLR(v)        v.rbegin(),v.rend()
#define pii            3.14159265358979323
#define mod            1000000007
 
void solve()
{
    ll n;

    cin>>n;

    cout<<(n*(n-1))/2;
}
 
signed main(){
 
    fast;
 
    ll t=1;
 
    //cin>>t;
 
    while(t--)
    {
        solve();
    }
 
    return 0;
}


Measured memory_bytes: 256
#include<stdio.h>
#define N 101

int main(){
  int n,u,k,v,i,j,l[N][N];
  scanf("%d",&n);
  
for(i=1 ; i<=n ; i++){
  for(j=1 ; j<=n ; j++){
     l[i][j] = 0;
  }
 }

  for(i=1 ; i<=n ; i++){
    scanf("%d%d",&k,&u);
    for(j=1 ; j<=u ; j++){
      scanf("%d",&v);
      l[k][v] = 1;
    }
  }

  for(i=1 ; i<=n ; i++){
    for(j=1 ; j<=n ; j++){
      printf("%d",l[i][j]);
      if(j != n) printf(" ");
      }
    printf("\n");
    }
  return 0;
}



Measured memory_bytes: 2052
import java.util.*;

public class Main {
	
	/*
	 * default function
	 * */	
	int ni() {
		return cin.nextInt();
	}
	
	long nl() {
		return cin.nextLong();
	}
	
	String line() {
		return cin.nextLine();
	}
	
	void println(String str) {	
		System.out.println(str);
	}
	
	void print(String str) {
		System.out.print(str);
	}
	
	/*
	 * default variable
	 */
	
	static final int MOD = 1000000007;
	
	Scanner cin = new Scanner(System.in);	
	String  output;
	
	public static void main(String[] args) {			
		new Main().run();						
	}
	
	/* default above */		
	public void run() {
			
		input();
		/* 
		 * start
		 */	
		
		solve();
		
		/*
		 * finish
		 */
		
		
		println(output);
			
	}
	/* 
	 * define variable
	 */
	
	long X, Y;
	
	void input() {
		
		X = nl();
		Y = nl();
	}
	
	void solve() {
		
		if (Math.abs(X-Y) <= 1) {
			output = "Brown";
		} else {
			output = "Alice";
		}
	}
	
}


Measured memory_bytes: 23636
import sys

s = input()
if len(s) == 1:
    print(0)
    sys.exit(0)

sb = s[:len(s)//2]
if len(s) % 2 == 1:
    sa = s[len(s)//2+1:]
else:
    sa = s[len(s)//2:]
sa = sa[::-1]

cnt = 0
for i,b in enumerate(sb):
    if b != sa[i]:
        cnt += 1
print(cnt)


Measured memory_bytes: 3060
s = {}
m = 0
for _ in range(int(input())):
  t = input()
  if t in s:
    s[t] += 1
  else:
    s[t] = 1
  m = max(m, s[t])
ans = []
for el in s:
  if s[el] == m:
    ans.append(el)
ans.sort()
for a in ans:
  print(a)


Measured memory_bytes: 92324
#include <cstdio>
#include <vector>
#include <algorithm>
#include <queue>
#include <set>
#include <cstdlib>
using namespace std;

char c[32][32];
char order[10];


struct state{
	int x;
	int y;
	char top;
	char south;
	char west;
	int time;
	int pass;
	
	state(int x, int y, char top, char south, char west, int time, int pass)
		: x(x), y(y), top(top), south(south), west(west), time(time), pass(pass)
	{ }

	bool operator< (const state &s) const{
		if(x != s.x) return x < s.x;
		if(y != s.y) return y < s.y;
		if(top != s.top) return top < s.top;
		if(south != s.south) return south < s.south;
		return pass < s.pass;
	}
};


void travel(state &next, queue<state> &q, set<state> &visit){
	char tile = c[next.y][next.x];

	if( tile != 'k' ){
		if( tile == 'w' ){
			if( visit.find(next) == visit.end() ){
				q.push(next);
				visit.insert(next);
			}
		}
		else{
			if( tile == order[next.pass + 1] && tile == next.top ){
				++next.pass;
				if( visit.find(next) == visit.end() ){
					q.push(next);
					visit.insert(next);
				}
			}
		}
	}
}


char opposite(char clr){
	switch(clr){
		case 'r': return 'c';
		case 'c': return 'r';
		case 'g': return 'm';
		case 'm': return 'g';
		case 'b': return 'y';
		case 'y': return 'b';
	}
	return '_';
}


int main(){
	int w, d;
	
	while( scanf("%d%d", &w, &d), w != 0 ){
		fill(*c, *c + sizeof c, 'k');

		for(int i = 1; i <= d; ++i){
			scanf(" %s", c[i] + 1);
			c[i][w + 1] = 'k';
		}

		scanf(" %s", order + 1);

		char *first = find(*c, *c + sizeof c, '#');
		*first = 'w';
		int pos = first - *c;
		
		queue<state> q;
		q.push( state(pos % 32, pos / 32, 'r', 'm', 'y', 0, 0) );

		set<state> visit;
		visit.insert(q.front());

		bool reachable = false;
		while( !q.empty() ){
			state s = q.front();
			q.pop();

			if(s.pass == 6){
				printf("%d\n", s.time);
				reachable = true;
				break;
			}

			if( c[s.y - 1][s.x] != 'k' ){
				state next(s.x, s.y - 1, s.south, opposite(s.top), s.west, s.time + 1, s.pass);
				travel(next, q, visit);
			}
			if( c[s.y + 1][s.x] != 'k' ){
				state next(s.x, s.y + 1, opposite(s.south), s.top, s.west, s.time + 1, s.pass);
				travel(next, q, visit);
			}
			if( c[s.y][s.x - 1] != 'k' ){
				state next(s.x - 1, s.y, opposite(s.west), s.south, s.top, s.time + 1, s.pass);
				travel(next, q, visit);
			}
			if( c[s.y][s.x + 1] != 'k' ){
				state next(s.x + 1, s.y, s.west, s.south, opposite(s.top), s.time + 1, s.pass);
				travel(next, q, visit);
			}
		}
		
		if( !reachable ){
			puts("unreachable");
		}
	}
}

Measured memory_bytes: 5100
#include <iostream>
#include <cstdio>

using namespace std;
int num[4];
int symbol[4];


int main(){
    int t,sum = 0;
    scanf("%d",&t);
    for(int i=3; i>=0; i--){
        num[i] = t%10;
        sum+=num[i];
        t/=10;
    }
    if(sum==7){
        printf("%d+%d+%d+%d=7\n",num[0],num[1],num[2],num[3]);
        return 0;
    }
    for(int i=1; i<4; i++){
        if(sum-2*num[i]==7){
            symbol[i] = 1;
            printf("%d",num[0]);
            for(int j=1;j<4;j++){
                if(symbol[j]){
                    printf("-");
                }
                else{
                    printf("+");
                }
                printf("%d",num[j]);
            }
            printf("=7\n");
            return 0;
        }
    }
    for(int i=1; i<4; i++){
        for(int j=i+1; j<4;j++){
            if(sum-2*num[i]-2*num[j]==7){
                symbol[i] = 1;
                symbol[j] = 1;
                printf("%d",num[0]);
                for(int k=1; k<4; k++){
                    if(symbol[k]){
                        printf("-");
                    }
                    else{
                        printf("+");
                    }
                    printf("%d",num[k]);
                }
                printf("=7\n");
                return 0;
            }
        }
    }
    return 0;
}


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

# 絶対値の和
plus_sum = 0
# 負の数の個数
minus_num = 0
# 絶対値が最も小さい数
min_abs = 10**10

for a in A:
    plus_sum += abs(a)
    if a < 0:
        minus_num += 1
    if abs(a) < abs(min_abs):
        min_abs = a

# 0が入っていたら全部正にできる
if 0 in A:
    print(plus_sum)

else:
    # 0が含まれない場合、負の個数の偶奇で場合分け
    # 偶数個なら全部正にできる
    if minus_num % 2 == 0:
        print(plus_sum)

    # min_absだけマイナス、他はプラス
    elif minus_num % 2 == 1:
        ans = plus_sum - 2 * abs(min_abs)
        print(ans)


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

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(), (x).end()

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

    // start
    int x, y;
    cin >> x >> y;
    if (x % y == 0)
        cout << -1 << endl;
    else
        cout << x << endl;
    // end

    return 0;
}


Measured memory_bytes: 256
#include <sstream>
#include <string>
#include <vector>
#include <map>
#include <algorithm>
#include <iostream>
#include <utility>
#include <set>
#include <cctype>
#include <queue>
#include <stack>
#include <cstdio>
#include <cstdlib>
#include <cmath>
using namespace std;
int w, n, a[32], b[32], ans[32];
int main(void) {
    cin >> w;
    cin >> n;
    for (int i = 0; i < n; i++) {
        scanf("%d,%d", a+i, b+i);
    }
    for (int i = 1; i <= w; i++) {
        int now = i;
        for (int j = 0; j < n; j++) {
            if (now == a[j]) now = b[j];
            else if (now == b[j]) now = a[j];
        }
        ans[now] = i;
    }
    for (int i = 1; i <= w; i++) {
        cout << ans[i] << endl;
    }
    return 0;
}

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

int main(){
	int N, K, x, i, ans = 0;
	scanf("%d%d", &N, &K);
	for(i = 0; i < N; i++){
		scanf("%d", &x);
		ans += 2 * min(x, K - x);
	}
	printf("%d\n", ans);
	return 0;
}

Measured memory_bytes: 256
#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define all(x) x.begin(),x.end()
const long double PI = acos(-1.0L);
const long long MOD = 1000000007LL;
// const long long MOD = 998244353LL;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<long long, long long> pll;
template<class T> inline bool chmax(T &a, T b) { if (a < b) { a = b; return true;} return false; }
template<class T> inline bool chmin(T &a, T b) { if (a > b) { a = b; return true;} return false; }
///////////////////////////////////////////////////////////////////////////////////////////////////

int main() {
    ios::sync_with_stdio(false); cin.tie(nullptr);
    ll N,A,B; cin >> N >> A >> B;
    ll m = A*(N-1LL)+B;
    ll M = A+B*(N-1LL);

    cout << max(0LL,M-m+1LL) << endl;
}

Measured memory_bytes: 256
# -*- coding: utf-8 -*-
# モジュールのインポート
import itertools

# 標準入力の取得
X = int(input())


def get_value(A: int, B: int) -> int:
    """関数

    Arguments:
        A {int} -- 整数
        B {int} -- 整数

    Returns:
        int -- 整数
    """
    return A**5 - B**5


def main() -> None:
    """Entry point
    """
    # 求解処理
    """
    "X = A^5 - B^5"について増加スピードが最も遅い"A - B = 1"の場合について考える。
    このとき、数列"a_n = n^5 - (n-1)^5"はn=-119, 120のときにXの最大値10^9を超えるため、
    -118 <= A <= 119の場合についてのみ考える。
    この不等式とA - B = 1より、-119 <= B <= 118であるため、これらの範囲内のA, Bについて全探索を行う。
    """
    A_min, A_max = -118, 119
    B_min, B_max = -119, 118
    result = ""
    for A, B in itertools.product(range(A_min, A_max+1), range(B_min, B_max+1)):
        value = get_value(A, B)
        if value == X:
            result = f"{A} {B}"
            break

    # 結果出力
    print(result)


if __name__ == "__main__":
    main()


Measured memory_bytes: 9216
#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 a, b, c;
  cin >> a >> b >> c;

  int res = min({a + b, a + c, b + c});

  cout << res << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> pp;
typedef pair<ll,ll> pll;
void read(int& x){ scanf("%d",&x); }
void read(ll& x){ scanf("%lld",&x); }
void read(pp& x){ scanf("%d%d",&x.first, &x.second); }
void read(pll& x){ scanf("%lld%lld",&x.first, &x.second); }
template<typename T,typename... Args>
void read(T& a,Args&... b){ read(a); read(b...); }
#define all(x) (x).begin(),(x).end()
#define pb push_back
#define eb emplace_back
#define x first
#define y second
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define rrep(i,n) for(int i = 1; i <= (n); ++i)
#define sz(x) (int)(x).size()

int n;
const ll mod = int(1e9) + 7;

ll dp[4010][4010];

pp d[200010];

ll fact[8010];
ll frev[8010];

ll ppow(ll b, ll e){
	ll ret = 1;
	while(e){
		if(e&1) (ret*=b)%=mod;
		(b*=b)%=mod; e>>=1;
	}
	return ret;
}

int main()
{
	read(n);
	rrep(i, n) read(d[i]), ++dp[2000-d[i].x][2000-d[i].y];
	rep(i, 4001) rep(j, 4001){
		if(i) (dp[i][j] += dp[i-1][j]) %= mod;
		if(j) (dp[i][j] += dp[i][j-1]) %= mod;
	}
	fact[0]=1;
	rrep(i, 8000) fact[i]=fact[i-1]*i%mod;
	frev[8000]=ppow(fact[8000], mod-2);
	for(int i=7999; 0<=i; --i) frev[i]=frev[i+1]*(i+1)%mod;
	ll ans = 0;
	rrep(i, n){
		int x, y; tie(x, y) = d[i];
		(ans += dp[x+2000][y+2000]) %= mod;
	}
	rrep(i, n){
		int x, y; tie(x, y) = d[i];
		(ans += mod - fact[x+y<<1]*frev[x<<1]%mod*frev[y<<1]%mod) %= mod;
	}
	(ans *= (mod+1)/2) %= mod;
	printf("%lld\n", ans);
	return 0;
}


Measured memory_bytes: 127232
from fractions import gcd
def lcm(x, y):
    return (x * y) // gcd(x, y)
MOD = 10 ** 9 + 7  
n = int(input())
A = list(map(int, input().split()))

l = 1
for i in A:
  l = lcm(l, i)
  
ans = 0
for a in A:
  ans += l // a

print(ans % MOD)


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

int main()
{
    int H, W, N;
    cin >> H >> W >> N;
    vector<int> A(N);
    for (auto &a : A) cin >> a;

    vector<vector<int>> ans(H, vector<int>(W));
    int now = 0;
    for (int c = 1; c <= N; c++)
    {
        for (int goal = now + A[c - 1]; now < goal; now++)
        {
            ans[now / W][now % W] = c;
        }
    }
    for (int i = 0; i < H; i += 2)
    {
        reverse(ans[i].begin(), ans[i].end());
    }
    for (auto vec : ans)
    {
        for (auto val : vec) cout << val << " ";
        cout << endl;
    }
    return 0;
}

Measured memory_bytes: 384
/* ex3_2
   tamayama */

#include<stdio.h>

int main(void){
    int N;
  int Pencil;
    scanf("%d",&N);
  Pencil = N;
    if((Pencil-2)%10 == 0 || (Pencil-4)%10 == 0 || (Pencil-5)%10 == 0 || (Pencil-7)%10 == 0 || (Pencil-9)%10 == 0){
        printf("hon");
    }else if(Pencil%10 == 0 || (Pencil-1)%10 == 0 || (Pencil-6)%10 == 0 || (Pencil-8)%10 == 0){
        printf("pon");
    }else{
        printf("bon");
    }
    return 0;
}


Measured memory_bytes: 1728
#include <fstream>
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <queue>
#include <set>
#include <cmath>
#include <climits>
#include <map>
#include <unordered_map>
#include <set>
#include <unordered_set>
#include <numeric>
#include <sstream>

#define rep(i,n) for (int i = 0; i < (n); ++i)
#define sz(x) int(x.size())

using namespace std;
typedef long long ll;

int main() {
#ifdef RUN_LOCAL
  ifstream in("../input.txt");
  cin.rdbuf(in.rdbuf());
#endif

  cin.tie(0);
  ios::sync_with_stdio(false);

  int n_room, n_aisle;
  cin >> n_room >> n_aisle;
  vector<vector<int>> graph(n_room, vector<int>());

  for (int i = 0; i < n_aisle; ++i) {
    int a, b;
    cin >> a >> b;
    --a, --b;
    graph[a].push_back(b);
    graph[b].push_back(a);
  }

  vector<int> trg(n_room, -1);
  queue<int> que;

  trg[0] = 0;
  que.push(0);

  while (!que.empty()) {
    int v = que.front();
    que.pop();
    for (int nv : graph[v]) {
      if (trg[nv] != -1) continue;
      trg[nv] = v;
      que.push(nv);
    }
  }

  cout << "Yes" << endl;
  for (int i = 1; i < n_room; ++i) {
    cout << trg[i] + 1 << endl; // 0-index to 1-index
  }


  return 0;
}


Measured memory_bytes: 9640
#include <bits/stdc++.h>
#define rep(i,x,n) for(int i = x; i < (int)(n); i++)
#define rep_ll(i,x,n) for(ll i = x; i < (ll)(n); i++)
using namespace std;
typedef long long ll;
typedef unsigned long long u_ll;
typedef pair<int, int> pair_;
const long double PI = (acos(-1));
const int INF = 1001001001;
const int dx[] = {-1, 0, 1, 0}; const int dy[] = {0, -1, 0, 1};
ll mod = 1000000007;
int main(){
    int n;
    cin >> n;
    //vector<int> h(n);
    //rep(i, 0, n) cin >> h[i];
    if(n>=30) cout << "Yes";
    else cout << "No";


    return 0;
}

Measured memory_bytes: 3632
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef double lf;
typedef pair<int,int> ii;
typedef pair<ii,int> iii;
#define REP(i,n) for(int i=0;i<n;i++)
#define REP1(i,n) for(int i=1;i<=n;i++)
#define RST(i,n) memset(i,n,sizeof i)
#define SZ(a) (int)a.size()
#define ALL(a) a.begin(),a.end()
#define X first
#define Y second
#define eb emplace_back
#ifdef cold66
#define debug(...) do{\
    fprintf(stderr,"LINE %d: (%s) = ",__LINE__,#__VA_ARGS__);\
    _do(__VA_ARGS__);\
}while(0)
template<typename T>void _do(T &&_x){cerr<<_x<<endl;}
template<typename T,typename ...S> void _do(T &&_x,S &&..._t){cerr<<_x<<", ";_do(_t...);}
template<typename _a,typename _b> ostream& operator << (ostream &_s,const pair<_a,_b> &_p){return _s<<"("<<_p.X<<","<<_p.Y<<")";}
template<typename It> ostream& _OUTC(ostream &_s,It _ita,It _itb)
{
    _s<<"{";
    for(It _it=_ita;_it!=_itb;_it++)
    {
        _s<<(_it==_ita?"":",")<<*_it;
    }
    _s<<"}";
    return _s;
}
template<typename _a> ostream &operator << (ostream &_s,vector<_a> &_c){return _OUTC(_s,ALL(_c));}
template<typename _a> ostream &operator << (ostream &_s,set<_a> &_c){return _OUTC(_s,ALL(_c));}
template<typename _a,typename _b> ostream &operator << (ostream &_s,map<_a,_b> &_c){return _OUTC(_s,ALL(_c));}
template<typename _t> void pary(_t _a,_t _b){_OUTC(cerr,_a,_b);cerr<<endl;}
#define IOS()
#else
#define debug(...)
#define pary(...)
#define endl '\n'
#define IOS() ios_base::sync_with_stdio(0);cin.tie(0);
#endif // cold66
//}
template<class T> inline bool chkmax(T &a, const T &b) { return b > a ? a = b, true : false; }
template<class T> inline bool chkmin(T &a, const T &b) { return b < a ? a = b, true : false; }

const ll MAXn=2e5+5,MAXlg=__lg(MAXn)+2;
const ll MOD=1000000007;
const ll INF=0x3f3f3f3f;


int a[MAXn],b[MAXn];
int main(){
    IOS();
    int n;
    cin >> n;
    for (int i=0;i<n;++i) {
        cin >> a[i];
    }
    for (int i=0;i<n;++i) {
        cin >> b[i];
    }

    reverse(b,b+n);
    int l = -1, r = -1;
    int C = -1;
    for (int i=0;i<n;++i) {
        if (a[i] != b[i]) continue;
        if (l == -1) l = r = i, C = a[i];
        else r = i;
    }
    int idx = l;
    for (int i=0;i<n;++i) {
        if (idx == -1) break;
        if (i >= l && i <= r) continue;
        if (idx > r) continue;
        if (a[i] != C && b[i] != C) {
            swap(b[idx],b[i]);
            idx++;
        }
    }
    if (idx == -1 || idx > r) {
        cout << "Yes" << endl;
        for (int i=0;i<n;++i) {
            cout << b[i] << " \n"[i==n-1];
        }
    }
    else cout << "No" << endl;
}


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

int main()
{
    int tmp;
    int fivecount = 0, sevencount = 0;
    for (int i = 0; i < 3; i++)
    {
        std::cin >> tmp;
        if (tmp == 7) { sevencount++; }
        else if (tmp == 5)
        {
            fivecount++;
        }
    }

    if (fivecount == 2 && sevencount == 1) { std::cout << "YES" << std::endl; }
    else
    {
        std::cout << "NO" << std::endl;
    }
    return 0;
}

Measured memory_bytes: 256
import java.util.*;

public class Main {

    public static void main(String[] args) {
        // write your code here
        Scanner sc = new Scanner(System.in);

        long h = sc.nextLong();
        long x = 1;

        while (h != 1) {
            h /= 2;
            x *= 2;
            x++;
        }

        System.out.println(x);
    }
}

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

int main()
{
    int A,B,C,D;
    int ans;
    cin >>A>>B>>C>>D;
    if(B<C){
        ans=0;
    }
    else if(D<A){
        ans=0;
    }
    else if(A<=C){
        if(D<=B){
            ans=D-C;
        }
        else{
            ans=B-C;
        }
    }
    else {
        if(D<=A){
            ans=0;
        }
        else if(D<=B){
            ans=D-A;
        }
        else{
            ans=B-A;
        }
    }
    cout << ans <<"\n";
    return 0;
}

Measured memory_bytes: 256