akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
using namespace std;

int main(){
	int n,m,c;
	cin >> n >> m >> c;
	int b[m]  = {};
	for(int i = 0; i < m; i++){
		cin >> b[i];
	}
	int count= 0;
	int a;
	for(int i = 0; i < n; i++){
		int sum = c;
		for(int j = 0; j < m; j++){
			cin >> a;
			sum += a * b[j];
		}
		if(sum > 0)count++;
	}
	cout << count << endl;
	return 0;
}

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

int main() {
	int N, a[100000], count = 0;
	cin >> N;
	for (int i = 0; i < N; i++) {
		cin >> a[i];
	}
	for (int i = 0; i < N; i++) {
		if (a[a[i] - 1] - 1 == i) count++;
	}
	cout << count / 2 << endl;
}

Measured memory_bytes: 640
fn read<T: std::str::FromStr>(
    stdin_lock: &mut std::io::StdinLock,
    buf: &mut Vec<u8>,
    delimiter: u8,
) -> T {
    buf.clear();
    let l = std::io::BufRead::read_until(stdin_lock, delimiter, buf).unwrap();
    buf.truncate(l - 1); // remove delimiter
    let s = unsafe { std::str::from_utf8_unchecked(&buf) };
    s.parse().unwrap_or_else(|_| panic!("read"))
}

fn main() {
    let stdin = std::io::stdin();
    let mut stdin_lock = stdin.lock();
    let mut buf: Vec<u8> = Vec::new();
    let a: u8 = read(&mut stdin_lock, &mut buf, b' ');
    let b: u8 = read(&mut stdin_lock, &mut buf, b'\n');
    let ans = if a <= 8 && b <= 8 { "Yay!" } else { ":(" };
    println!("{}", ans);
}


Measured memory_bytes: 4352
def solve(N, As):
    increasing = None
    ans = 1
    for a1, a2 in zip(As, As[1:]):
        if increasing is None:
            if a1 < a2:
                increasing = True
            elif a1 > a2:
                increasing = False
        else:
            if a1 == a2 or (a1 < a2 and increasing) or (a1 > a2 and not increasing):
                pass
            else:
                ans += 1
                increasing = None
    return ans


if __name__ == "__main__":
    N = int(input())
    As = list(map(int, input().split(" ")))
    print(solve(N, As))


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

using namespace std;

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

int N;
vector<int> w;

int solve() {
    vector<vector<int>> dp(N+1, vector<int>(N+1, -N));
    for (int i = 0; i <= N; ++i) {
        dp[i][i] = 0;
        if (i < N) dp[i][i+1] = 0;
    }
    for (int bet = 2; bet <= N; ++bet) {
        for (int i = 0; i + bet <= N; ++i) {
            int j = i + bet;
 
            // 1. 全部取り除けるかもしれないとき
            if ( abs(w[i]- w[j-1]) <= 1){
                if ( dp[i+1][j-1] == j-i-2) chmax(dp[i][j],j-i);
            }
            
            // 2. otherwise
            for (int k = i+1; k <= j-1; ++k) {
                chmax(dp[i][j], dp[i][k] + dp[k][j]);
            }
            
        }
    }
    return dp[0][N];
}

int main() {
    while (cin >> N, N) {
        w.resize(N);
        for (int i = 0; i < N; ++i) cin >> w[i];
        cout << solve() << endl;
    }
}













Measured memory_bytes: 3268
#include<vector>
#include<iostream>
#include<stdio.h>
#include<stdlib.h>
#include <iostream>
#include <algorithm>
#include <map>
#include <cmath>
#define INF 100000000000000
using namespace std;
typedef long long llong;

//int isalpha(char ch): ch がアルファベットなら true を返す
//int isdigit(char ch): ch が数字なら true を返す
//int islower(char ch): ch が小文字なら true を返す
//int isupper(char ch): ch が大文字なら true を返す
//int tolower(char ch): ch の小文字を返す
//int toupper(char ch): ch の大文字を返す

//string型
//size()	文字数を返す
//Insert()	（指定した場所に）文字・文字列を挿入する
//erase()	（指定した場所の）文字・文字列を削除する
//clear()	すべての文字を削除する
//substr()	文字列の（指定した）部分文字列を返す
//replace()	（指定した）部分文字列を新しい文字列に置換する
//c_str()変換
//文字列の比較は、<=や==などを使え
//replace関数を使い、簡単に文字列を置換
//リバース関数：reverse(str.begin(), str.end());
//map<type, type> dict;で宣言
//グラフ理論用変数
//vector<vector<llong> > graph(N);

//ソート
//降順sort(v.begin(), v.end(), std::greater<Type>());

//大文字から小文字へんかん
//w[i] = w[i]-'A'+'a';

//vector
//assignメソッド　引数：サイズ、値
//与えられたサイズと値でvectorを初期化する

int main(){
    llong N;
    llong X;
    llong L;
    cin >> N;
    vector<pair<llong, llong> > Table(N);
    for(int i=0; i<Table.size(); i++){
        cin >> X >> L;
        Table[i].first  = X+L;
        Table[i].second = X-L;
    }
    sort(Table.begin(), Table.end());
    llong prev = Table[0].first;
    llong ans = 1;

    for(int i=1; i<Table.size(); i++){
        if(prev<=Table[i].second){
            ans++;
            prev = Table[i].first;
        }
    }
    cout << ans << endl;
    return 0;
}


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

int main(void) {
	long long int sum;
	int n;
	char s;
	short a[4000];
	long long int r = 0, g = 0, b = 0;
	cin >> n;
	for (int l = 0; l < n; l++) {
		cin >> s;
		if (s == 'R') {
			r++;
			a[l] = 2;
		}
		else if (s == 'B') {
			b++;
			a[l] = 3;
		}
		else if (s == 'G') {
			g++;
			a[l] = 5;
		}
	}
	sum = 0;
	for (int i = 0; i < n - 2; i++) {
		for (int j = 1;2 * j < n - i; j++) {
			if (a[i] * a[i + j] * a[i + (2 * j)] % 30 == 0)sum++;
		}
	}
	cout << (r * b * g) - sum << endl;
	return 0;

}

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

int main(int argc, char **argv){
	std::vector<int> v;
	int n = 0;

	std::cin >> n;
	v.resize(n);
	for(int i = 0; i < n; i++){
		std::cin >> v[i];
	}
	for(int i = n - 1; i >= 0; i--){
		std::cout << v[i];
		if(i > 0){
			std::cout << " ";
		}
	}
	std::cout << std::endl;
	return 0;
}

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

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

using vi = vector<int>;
using vvi = vector<vi>;
using vd = vector<double>;
using vvd = vector<vd>;

void phead(vd head) {
  int n = head.size();
  rep(k, n) {
    cout << head.at(k);
    if (k == n-1) {
      cout << endl;
    } else {
      cout << " ";
    }
  }
}

int main() {
  int n; cin >> n;
  int n_ = n+1;

  vd p(n_);
  rep(i, n_) {
    cin >> p.at(i);
  }
  
  vd head = vd(n_);
  head.at(0) = 1;
  for (int i = 0; i < n; i++) {
    for (int j = i; j >= 0; j--) {
      head.at(j+1) += head.at(j) * (1.0 - p.at(i));
      head.at(j) = head.at(j) * p.at(i);
      //phead(head);
    }
  }
  
  double result = 0.0;
  int m = n/2 + 1;
  for (int j = 0; j < m; j++) {
    result += head.at(j);
  }
  
  cout << setprecision(10) << result << endl;
}


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

public class Main {

	static Scanner sc = new Scanner(System.in);
	static int N, M;
	static int[] p = new int[15];
	static int[] move = new int[15];

	static int solve() {
		int[][] dp = new int[N + 1][3];
		for (int i = 0; i < N; ++i) {
			Arrays.fill(dp[i + 1], Integer.MAX_VALUE);
		}
		for (int i = 0; i < N; ++i) {
			for (int j = 0; j < 3; ++j) {
				dp[i + 1][p[i]] = Math.min(dp[i + 1][p[i]], dp[i][j] + move[i] * Math.abs(j - p[i]));
			}
			if (p[i] == 1) {
				dp[i + 1][0] = Math.min(dp[i + 1][0], dp[i][0] + move[i] * 4 + 1);
				dp[i + 1][0] = Math.min(dp[i + 1][0], dp[i][1] + move[i] * 3 + 1);
				dp[i + 1][0] = Math.min(dp[i + 1][0], dp[i][2] + move[i] * 2 + 1);
				dp[i + 1][2] = Math.min(dp[i + 1][2], dp[i][2] + move[i] * 4 + 1);
				dp[i + 1][2] = Math.min(dp[i + 1][2], dp[i][1] + move[i] * 3 + 1);
				dp[i + 1][2] = Math.min(dp[i + 1][2], dp[i][0] + move[i] * 2 + 1);
			} else {
				dp[i + 1][1] = Math.min(dp[i + 1][1], dp[i][p[i]] + move[i] * 3 + 1);
				dp[i + 1][1] = Math.min(dp[i + 1][1], dp[i][1] + move[i] * 2 + 1);
				dp[i + 1][1] = Math.min(dp[i + 1][1], dp[i][2 - p[i]] + move[i] * 1 + 1);
				dp[i + 1][2 - p[i]] = Math.min(dp[i + 1][2 - p[i]], dp[i][p[i]] + move[i] * 6 + 2);
				dp[i + 1][2 - p[i]] = Math.min(dp[i + 1][2 - p[i]], dp[i][1] + move[i] * 5 + 2);
				dp[i + 1][2 - p[i]] = Math.min(dp[i + 1][2 - p[i]], dp[i][2 - p[i]] + move[i] * 4 + 2);
			}
		}
		int m = Math.min(dp[N][0], dp[N][2]);
		return m <= M ? m : -1;
	}

	public static void main(String[] args) throws Exception {
		for (int i = 1; i < move.length; ++i) {
			move[i] = move[i - 1] * 3 + 1;
		}
		while (true) {
			N = sc.nextInt();
			if (N == 0) break;
			M = sc.nextInt();
			for (int i = 0; i < 3; ++i) {
				int c = sc.nextInt();
				for (int j = 0; j < c; ++j) {
					p[N - sc.nextInt()] = i;
				}
			}
			System.out.println(solve());
		}
	}
}

Measured memory_bytes: 12000
#include <bits/stdc++.h>
#define int long long
#define rep(i, n) REP(i, 0, n)
#define REP(i, l, r) for (long long i = l; i < r; i++)
using namespace std;
signed main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	int n, a[100000];
	cin >> n;
	rep(i, n) cin >> a[i];
	sort(a, a + n);
	int ans = 0;
	deque<int> que;
	rep(i, n) {
		if (i == 0 && a[i] >= 0 || a[i] < 0)
			ans -= a[i];
		else
			ans += a[i];
		que.push_back(a[i]);
	}
	if (a[n - 1] < 0) ans += a[n - 1] * 2;
	cout << ans << endl;
	rep(i, n - 1) {
		if (que.front() > 0) {
			int x = que.front();
			que.pop_front();
			int y = que.front();
			que.pop_front();
			cout << x << " " << y << endl;
			que.push_front(x - y);
		}
		else {
			if (que[que.size() - 2] <= 0) {
				int x = que.front(), y = que.back();
				que.pop_front();
				que.pop_back();
				cout << y << " " << x << endl;
				que.push_back(y - x);
			}
			else {
				int x = que.front(), y = que.back();
				que.pop_front();
				que.pop_back();
				cout << x << " " << y << endl;
				que.push_front(x - y);
			}
		}
	}
}

Measured memory_bytes: 3456
#include <iostream>
#include <algorithm>
#include <cmath>
#include <vector>
#include <string>
#include <map>
#include <cstdio>
#include <numeric>
#include <iomanip>

using namespace std;

using ll = long long;

ll N, M, X;
ll C[100];
ll A[100][100];

ll used[100];

const ll INF = 1e12;
ll ans = INF;

bool check()
{
    ll sum[100] = {0};
    for(int i = 0;i < N;i++)
    {
        if(used[i] == 1)
        {
            for(int j = 0;j < M;j++)
            {
                sum[j] += A[i][j];
            }
        }
    }
    for(int j = 0;j < M;j++)
    {
        if(sum[j] < X)
        {
            return false;
        }
    }
    return true;
}

void rec(int d)
{
    if(d > N)
    {
        if(check())
        {
            ll cost = 0;
            for(int i = 0;i < N;i++)
            {
                if(used[i] == 1)
                {
                    cost += C[i];
                }
            }
            ans = min(ans, cost);
        }
        return;
    }
    used[d] = 1;
    rec(d+1);
    used[d] = 0;
    rec(d+1);
}

int main()
{
    cin >> N >> M >> X;
    for(int i = 0;i < N;i++)
    {
        cin >> C[i];
        for(int j = 0;j < M;j++)
        {
            cin >> A[i][j];
        }
    }
    rec(0);
    if(ans == INF)
    {
        cout << -1 << endl;
    }
    else
    {
        cout << ans << endl;
    }
    return 0;
}

Measured memory_bytes: 3248
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int a = sc.nextInt();
		int b = sc.nextInt();
		for (int i = 0; i < String.valueOf(b).length(); i++) {
			a *= 10;
		}
		a += b;
		int c = (int)(Math.sqrt(a));
		System.out.println((c * c == a)? "Yes" : "No");
	}
}

Measured memory_bytes: 25044
n=gets.to_i
a=Array.new(n).map{Array.new}
(n-1).times do
  x,y=gets.split.map &:to_i
  a[x-1]<< y-1
  a[y-1]<< x-1
end
b=Array.new(n).map{Array.new(2)}
b[0][0]=0
r=[0]
rr=[]
c=1
while true do
  if r == []
    r = rr.dup
    break if r==[]
    rr = []
    c+=1
  else
    t = r.pop
    a[t].each do |e|
      if b[e][0]==nil
        b[e][0]=c
        rr << e
      end
    end
  end
end

b[n-1][1]=0
r=[n-1]
rr=[]
c=1
while true do
  if r == []
    r = rr.dup
    break if r==[]
    rr = []
    c+=1
  else
    t = r.pop
    a[t].each do |e|
      if b[e][1]==nil
        b[e][1]=c
        rr << e
      end
    end
  end
end
g=0
cc=0
b.each do |e|
  if e[0]<e[1]
    g+=1
  elsif e[0]==e[1]
    cc+=1
  end
end
g+=cc
if g > n-g
  puts :Fennec
elsif g < n-g
 puts :Snuke
else
  if b[0][1]%2==1
    puts :Snuke
  else
    puts :Fennec
  end
end

    



Measured memory_bytes: 23532
#include <algorithm>
#include <map>
#include <iostream>
#include <string>
#include <set>
#include <queue>
#include <cmath>
#include <iterator>
#include <array>
typedef long long int ll;
using namespace std;
#define maxN 200005
#define mod 1000000007

ll a, b, n;
void solve()
{
    cin >> a >> b >> n;
    ll temp = min(b - 1, n);
    cout << ll(a * temp / b);
}

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

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

using namespace std ;

#define rg register
#define dbg(v) cerr << #v << " " << v ;
typedef long long ll ;

int main() {
    int a, b ;
    cin >> a >> b ;
    int cnt = 0 ;
    while(a > 0){
        a -= b ;
        cnt++ ;
    }

    cout << cnt << "\n" ;
}

/*
 Empty set of troubles.
*/


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define REP(i, s, n) for (int i = s; i < n; ++i)
#define rep(i, n) REP(i, 0, n)
#define SORT(c) sort((c).begin(), (c).end())
#define SORT_INV(c) sort((c).begin(), (c).end(), greater<int>())
#define IINF INT_MAX
#define LLINF LLONG_MAX
#define DEBUG false
#define LL long long
#define STEP 0.0005
// sort(a.begin(), a.end(), std::greater<int>());

int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};
int main()
{
   int a,b,c;
   cin>>a>>b>>c;
   int ans=c;
   rep(i,a){
       int temp=0;
       cin>>temp;
       ans+=(b-1)/temp+1;
   }
   cout<<ans<<endl;
   return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <stdlib.h>
#include <cmath>
#include <string>
using namespace std;
int main(void){
	string S;
	cin >> S;
	int min = 100000;
	for(int cnt = 0; cnt < S.size() - 2; cnt++){
		int value = (S[cnt]-'0') * 100;
		value += (S[cnt+1] - '0') * 10;
		value += (S[cnt+2] - '0');
		if(abs(753 - value) < min){
			min = abs(753 - value);
		}
	}
	cout << min << endl;
	return 0;
}

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

#define MAX 14
#define M 1070707

char H[M][MAX];

int getch(char c){
  if (c == 'A') return 1;
  else if (c == 'C') return 2;
  else if (c == 'G') return 3;
  else if (c == 'T') return 4;
}

long long getkey(char word[]){
  long long sum=0,p=1;
  int i;

  for(i=0; i<strlen(word); i++){
    sum += p*(getch(word[i]));
    p *= 3;
  }
  return sum;
}

int h1(int key){
  return key % M;
}

int h2(int key){
  return 1 + key % (M-1);
}


int search(char word[]){
  long long i,key,h;

  key = getkey(word);

  for(i=0;;i++){
    h = (h1(key) + i*h2(key)) % M;
    if(strcmp(H[h],word) == 0) return 1;
    else if(strlen(H[h]) == 0) return 0;
  }
  return 0;
}

int insert(char word[]){
  long long i,key,h;

  key = getkey(word);

  for(i=0;;i++){
    h = (h1(key) + i*h2(key)) % M;
    if(strcmp(H[h],word) == 0) return 1;
    else if(strlen(H[h]) == 0){
      strcpy(H[h],word);
      return 0;
    }
  }
  return 0;
}

int main(){
  int i;
  int n,f;
  char jud[7],word[MAX];

  for(i=0; i<M; i++) H[i][0] = '\0';

  scanf("%d",&n);

  for(i=0; i<n; i++){
    scanf("%s %s",jud,word);
    if(strcmp(jud,"insert") == 0){
      insert(word);
    }
    else if(strcmp(jud,"find") == 0){
      f = search(word);
      if(f == 1) printf("yes\n");
      else if(f == 0) printf("no\n");
    }
  }

  return 0;
}


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

using namespace std;

#define all(c) (c).begin(), (c).end()
#define rall(c) (c).rbegin(), (c).rend()
#define loop(i,a,b) for(int i=(a); i<(int)(b); i++)
#define rep(i,b) loop(i,0,b)
#define pb push_back
#define mp make_pair



int main(){
    typedef unsigned long long ull;
    ull a,b;
    while(cin>>a>>b){
        cout << __gcd(a,b) << " ";
        cout << a*b/__gcd(a,b) << endl;
    }
}

Measured memory_bytes: 1152
#include <stdio.h>
#include <math.h>
#include <string.h>
#define pai 3.1415926535

	int main(void) {
		int N;
		scanf("%d", &N);
		if (N % 2 == 0) {
			printf("%d", N / 2 - 1);
		}
		else {
			printf("%d", N / 2);
		}




		return 0;
}


Measured memory_bytes: 128
import java.util.Scanner;

class Main{

    public static void main(String[] args){

	Scanner in = new Scanner(System.in);

	while(true){
	int n = in.nextInt();
	if(n == 0)break;       

	int[][] mat = new int[50][50]; 
	int[] ato = new int[50];
	int[] tap = new int[50];

	

	for(int i=0;i<50;i++){
	    ato[i]=0;
	    tap[i]=0;
	}


	for(int i=0;i<n;i++){
	    for(int j=0;j<n;j++){
		mat[i][j] = in.nextInt();
		ato[i] += mat[i][j];
		tap[j] += mat[i][j];
	    }
	}
	for(int i=0;i<n;i++)ato[n] += ato[i];



	for(int i=0;i<=n;i++){
	    for(int j=0;j<=n;j++){
		if(i<n && j<n){
		    System.out.printf("%5d",mat[i][j]);
		}
		else if(j == n){
		    System.out.printf("%5d",ato[i]);
		}
		else if(i == n){
		    System.out.printf("%5d",tap[j]);
		}

	    }
	    System.out.printf("\n");
	}
	

	}




    }



}

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

int main(){
	long long sum , E;
	int y, z;
	while (scanf("%lld", &E), E){
		sum = 1000000;
		for (z = 0; z*z*z <= E; z++)
			for (y = 0; y*y <= E; y++){
				long long x = E - z*z*z - y*y;
				if (x<0){ break; }
				else if (sum>(x + y + z))sum = x + y + z;
			}
		printf("%lld\n", sum);
	}

	return 0;
}

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

#define CPP_STR(x) CPP_STR_I(x)
#define CPP_CAT(x,y) CPP_CAT_I(x,y)
#define CPP_STR_I(args...) #args
#define CPP_CAT_I(x,y) x ## y

using i8  = int8_t;
using u8  = uint8_t;
using i16 = int16_t;
using u16 = uint16_t;
using i32 = int32_t;
using u32 = uint32_t;
using i64 = int64_t;
using u64 = uint64_t;

using f32 = float;
using f64 = double;

#define FOR(i, start, end) for(i64 i = (start), CPP_CAT(i,xxxx_end)=(end); i < CPP_CAT(i,xxxx_end); ++i)
#define REP(i, n) FOR(i, 0, n)
#define REPS(i, n) for(i64 i = 1; i <= n; ++i)
#define RREP(i, n) for(i64 i = n - 1; i >= 0 ; --i)
#define RREPS(i, n) for(i64 i = n; i >= 1; --i)

#define ALL(f,c,...) (([&](decltype((c)) cccc) { return (f)(std::begin(cccc), std::end(cccc), ## __VA_ARGS__); })(c))

#define UNIQUE(v) v.erase( unique(v.begin(), v.end()), v.end() );

#define pb push_back
#define mp make_pair
#define F first
#define S second

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

template<typename C>
i64 SIZE(const C& c) { return static_cast<i64>(c.size()); }

template<typename T, size_t N>
i64 SIZE(const T (&)[N]) { return static_cast<i64>(N); }


struct ProconInit {
    static constexpr int IOS_PREC = 15;
    static constexpr bool AUTOFLUSH = false;

    ProconInit() {
        cin.tie(nullptr);
        ios::sync_with_stdio(false);
        cout << fixed << setprecision(IOS_PREC);
        if(AUTOFLUSH)
            cout << unitbuf;
    }
} PROCON_INIT;

#define MAX_N 2500
i64 N, K;

void solve() {
  i64 cnt = 0;
  i64 rem;
  for (i64 i = 0; i <= N; i++) {
    for (i64 j = 0; j <= N; j++) {
      rem = K - i - j;
      if (0 <= rem && rem <= N) {
        cnt++;
      }
    }
  }
  cout << cnt << endl;
}

int main() {
  cin >> N >> K;

  solve();

  return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <stdio.h>
#include <vector>
#include <utility>
#include <string>
#include <algorithm>
#include <cmath>
#include <set>
 
typedef long long ll;

#define rep(i,n) for(ll i = 0; i < n; i++)
 
using namespace std;
 
const ll INF = ll(1e18)+1;
const double PI=3.14159265358979323846;

int main(){
  int n, A[21], q, m[201];
  cin >> n;
  rep(i,n) cin >> A[i];
  cin >> q;
  rep(i,q) cin >> m[i];

  bool ok[201]={};
  for(int bit=0; bit < (1<<n); bit++){
    int now=0;
    rep(i,n){
      if(bit & (1<<i)) now += A[i];
    }
    rep(i,q){
      if(m[i] == now) ok[i] = true;
    }
  }
  rep(i,q){
    if(ok[i]) cout << "yes" << endl;
    else cout << "no" << endl;
  }
}



Measured memory_bytes: 3096
#include <bits/stdc++.h>
using namespace std;
int dp[100000];
int main(){
	int n;
	cin>>n;
	int arr[n];
	for(int i = 0; i<n; i++){
	cin>>arr[i];
	dp[i] = INT_MAX;
}
	dp[0] = 0;
	for(int i = 0; i<n; i++){
		int next = i+1, nn = i+2;
		if(next<n)
		dp[next] = min(dp[next], dp[i] + abs(arr[next]-arr[i]));
		if(nn<n)
		dp[nn] = min(dp[nn], dp[i] + abs(arr[nn]-arr[i]));
	}
	cout<<dp[n-1];
	return 0;
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
#define int long long
#define db long double
#define x first
#define y second
#define mp make_pair
#define pb push_back
#define all(a) a.begin(), a.end()

using namespace std;

const int INF = 1e9 + 7;

main(){
#ifdef LOCAL
	freopen("B_input.txt", "r", stdin);
	//freopen("B_output.txt", "w", stdout);
#endif
	ios_base::sync_with_stdio(0);
	cin.tie(0);

	int n;
	cin >> n;

	vector <pair <int, int> > a(n);

	int maxL = 0, idL = -1, minL = -1;
	int minR = INF, idR = -1, maxR = -1;

	int res = 0;

	vector <pair <int, int> > lens;

	for (int i = 0; i < n; i++) {
		cin >> a[i].first >> a[i].second;
		if (a[i].first > maxL) {
			maxL = a[i].first;
			maxR = a[i].second;
			idL = i;
		}
		if (a[i].second < minR) {
			minR = a[i].second;
			minL = a[i].first;
			idR = i;
		}
		int len = a[i].second - a[i].first + 1;
		res = max(res, len);
		lens.push_back({len, i});
	}

	vector <pair <int, int> > b;

	for (int tt = 0; tt < n; tt++) {
		if (lens[tt].second != idL && lens[tt].second != idR) {
			res = max(res, max(minR - maxL + 1, 0LL) + lens[tt].first);
			b.push_back(a[tt]);
		}
	}

	a = b;

	sort(a.begin(), a.end(), [&](pair <int, int> x, pair <int, int> y) {
		if (x.second != y.second) {
			return x.second > y.second;
		}
		return x.first > y.first;
	});

	multiset <int> q;
	for (auto t : a) {
		q.insert(t.first);
	}

	/*for (auto t : a) {
		cout << t.first << " " << t.second << "\n";
	}*/

	int now = maxR;
	int dd = (q.size() ? *q.rbegin() : minL);

	res = max(res, min(now, maxR) - maxL + 1 + minR - max(minL, dd) + 1);	

	for (int i = 0; i < (int) a.size(); i++) {
		int now = a[i].second;
		q.erase(q.find(a[i].first));
		int dd = (q.size() ? *q.rbegin() : minL);
		//cout << maxL << " " << now << " " << minR << " " << dd << "\n";
		//cout << min(now, maxR) - maxL + 1 + minR - max(minL, dd) + 1 << "\n";
		res = max(res, min(now, maxR) - maxL + 1 + minR - max(minL, dd) + 1);	
	}

	cout << res << "\n";

}


Measured memory_bytes: 9584
#include <algorithm>
#include <assert.h>
#include <memory.h>
#include <stdio.h>

#define printArr(a, n) for(int i=0;i<(n);++i)printf(i==(n)-1?"%d\n":"%d ",(a)[i])

void insertionSort(int *A, const int N) {
    printArr(A, N);
    for(int i = 1; i < N; ++i) {
        int tmp = A[i];
        int j = i - 1;
        while(j >= 0 && A[j] > tmp) {
            A[j + 1] = A[j];
            j--;
        }
        A[j + 1] = tmp;
        printArr(A, N);
    }
}

int main() {
    int N;
    scanf("%d", &N);
    int A[N], B[N];
    for(int i = 0; i < N; ++i) {
        scanf("%d", A + i);
    }
    //memcpy(B, A, sizeof(A));

    // solve
    insertionSort(A, N);

    // definitely right sort
    //std::sort(B, B + N);
    // make sure
    //for(int i = 0; i < N; ++i) {
    //    assert(A[i] == B[i]);
    //}

    return 0;
}



Measured memory_bytes: 2620
#include <iostream>
#include <cstring>
#include <cmath>
#include <vector>
#include <algorithm>
#include <stdio.h>
#include <math.h>
#include <stdlib.h>
#include <set>
#include <map>
#include <iterator>
#include <stack>
#include <string.h>
#include <cstdlib>
#include <queue>
#include <list>
#include <string>
#include <functional>
#include <sstream>

using namespace std;

int n;
int k;
vector<int> c;
long long ans = 0;
vector<int> box;


int main()
{
    int n;
    long long x[100005];
    long long l[100005];
    vector<pair<long long,long long>> v;
    
    cin >> n;
    for (int i = 0;i < n;i++){
        cin >> x[i] >> l[i];
        v.push_back(make_pair(x[i]+l[i],x[i]));
    }
    
    sort(v.begin(),v.end());
    int ans = 1;
    long long nowb = v[0].first;
    
    for (int i = 1;i < n;i++){
        if (nowb <= 2*v[i].second - v[i].first){
            ans++;
            nowb = v[i].first;
        }
    }
    cout << ans << endl;
}


Measured memory_bytes: 6588
#include <bits/stdc++.h>
#include <algorithm>
#include <vector>
#define RANGE(i,n) for(ll i=0;i<n;i++)
typedef long long ll;

using namespace std;

signed main() {
    ll N, M;
    cin >> N >> M;
    ll A[N];
    ll B[N];
    RANGE(i,N) cin >> A[i] >> B[i];
    vector<ll> sorted_id(N);
    iota(sorted_id.begin(), sorted_id.end(),0);
    sort(sorted_id.begin(), sorted_id.end(), [&A](ll a_1, ll a_2){
        return A[a_1] < A[a_2];
    });

    ll money = 0;
    ll have = 0;
    for(ll id:sorted_id){
        if(have + B[id] < M){ // tarinai
            have += B[id];
            money += B[id] * A[id];
        }else {
            ll rest_drink = M - have;
            have += rest_drink;
            money += rest_drink * A[id];
            break;
        }
    }
    cout << money << endl;

}


Measured memory_bytes: 2560
import java.util.*;
public class Main {
	
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int A = sc.nextInt();
        int B = sc.nextInt();
        int C = sc.nextInt();
        System.out.println(A == B ? C : A == C ? B : A);
    }
}

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

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

  if (A >= K){
    cout << A - K << ' ' << B << endl;
  }
  else if (B >= K - A)
  {
    cout << 0 << ' ' << B - K + A << endl;
  }
  else
  {
    cout << 0 << ' ' << 0 << endl;
  }
  
  
  
}

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

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

using namespace std;
using ll = long long;

int gdb(int a, int b) {
  int r = a % b;
  while (r != 0) {
    a = b;
    b = r;
    r = a % b;
  }
  return b; 
}

int main(void) {
  int a, b, c;
  cin >> a >> b >> c;
  int s;
  if (a >= b) {
    s = gdb(a, b);
  } else {
    s = gdb(b, a);
  }
  if (a % s == b % s + c % s) {
    cout << "YES" << endl;
  } else {
    cout << "NO" << endl;
  }
  return 0;
}



Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <cmath>
#include <map>
#include <queue>
#include <iomanip>
#include <set>
#include <tuple>
#define mkp make_pair
#define mkt make_tuple
#define rep(i,n) for(int i = 0; i < (n); ++i)
using namespace std;
typedef long long ll;
const ll MOD=1e9+7;

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

  vector<ll> sum(N+1,0);
  vector<ll> masum(N+1,0);
  for(int i=0;i<N;i++){
    masum[i+1]=masum[i]+max(0ll,A[i]);
    sum[i+1]=sum[i]+A[i];
  }

  ll ans=0;
  for(int i=K;i<=N;i++){
    ans=max(ans,masum[N]-masum[i]+masum[i-K]+max(0ll,sum[i]-sum[i-K]));
  }
  cout<<ans<<endl;

  return 0;
}


Measured memory_bytes: 2560
/************************Code by Hardik Aggarwal!!!!***********************************/

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

#define IOS ios_base::sync_with_stdio(false);cin.tie(NULL); 

#define ff first
#define ss second
#define pb push_back
#define pf push_front
#define mp make_pair
#define pu push
#define pp pop_back
#define in insert
#define ld long double
#define endl '\n'
#define debug cout << "Hold right there sparky.....\n";
#define forn(low,high,i) for(i=low;i<high;i++)
#define forrev(high,low,i) for(i = high; i>= low;i--)
#define trace(x) cerr << #x << ": " << x << " " << endl;

typedef long long int ll;

typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<vi> vvi;
typedef vector<vl> vvl;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef vector<pii> vpii;
typedef vector<pll> vpll;
const ll mod =1e9+7;

bool comp(pll p1,pll p2)
{
    if(p1.ff==p2.ff)
        return p1.ss<p2.ss;

    return p1.ff<p2.ff;
}
ll n=12,m;
ll a[1010],val[1005];
ll dp[1005][10000];
bool vis[1005][10000];
ll f(ll idx, ll mask)
{
    if ( idx == m ) {
        if ( __builtin_popcount(mask)==n) 
        {   
            return 0;
        }
        return mod;
    }
   if(dp[idx][mask]!=-1)
        return dp[idx][mask];
    ll ans = min(f(idx + 1, mask), a[idx] + f(idx + 1, (mask | val[idx])));
    //trace(ans);
    dp[idx][mask]=ans;
    return ans;
}
int main()
{
    IOS
    
    cin>>n>>m;
    memset(val,0,sizeof(val));
    memset(a,0,sizeof(a));
    memset(dp,-1,sizeof(dp));

    bool visi[n+1];
    memset(visi,0,sizeof(visi));
    ll b[m+1];
    for(ll i=0;i<m;i++)
    {
        cin>>a[i]>>b[i];
        for(ll j=0;j<b[i];j++)
        {
            ll x;
            cin>>x;
            x--;
            val[i]|=(1ll<<x);
            visi[x]=1;
        }
        //cout<<bitset<64>(val[i])<<endl;
    }

    /*for(ll i=0;i<m;i++)
    {
        cout<<a[i]<<endl;
    }*/

    for(ll i=0;i<n;i++)
    {
        if(!visi[i])
        {
            cout<<-1<<endl;
            return 0;
        }
    }

    cout<<f(0,0);

    




    
    
}
    
 
    
    



Measured memory_bytes: 80512
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		try (Scanner scanner = new Scanner(System.in)) {
			long n = scanner.nextLong();
			long m = scanner.nextLong();

			if (n == 1 && m == 1) {
				System.out.println(1);
				return;
			}

			if (n == 1 || m == 1) {
				System.out.println(n * m - 2);
				return;
			}

			if (n == 2 || m == 2) {
				System.out.println(0);
				return;
			}

			System.out.println(n * m - (m * 2) - (n - 2) * 2);
		}
	}
}


Measured memory_bytes: 23632
// 153 A

#include <iostream>
#include <string>
#include <vector>
#include <numeric>

using namespace std;

int main(){
    long int h, n, tmp, sum;
    vector<int> v;
    cin >> h >> n;
    for(int i=0; i<n; i++){
        cin >> tmp;
        v.push_back(tmp);
    }
    sum = accumulate(v.begin(), v.end(), 0);
    if(h > sum) cout << "No" << endl;
    else cout << "Yes" << endl;
    return 0;
}


Measured memory_bytes: 892
#include<iostream>

using namespace std;

int main() {
	int N, M[100000], tmp;
	cin >> N;
	for (int i = 0; i < N; i++) {
		cin >> M[i];
	}
	if (M[0] >= 1)		M[0]--;


	tmp = M[0];

	for (int i = 1; i < N; i++) {
		if (M[i] < tmp) {
			cout << "No";
			return 0;
		}
		else if (M[i] == tmp) {
			tmp = M[i];
		}
		else {
			tmp = M[i] - 1;
		}

	}
	cout << "Yes";
	return 0;
}

Measured memory_bytes: 640
N=int(input())
s_list=[int(input()) for _ in range(N)]
# N = 10
# s_list = [17, 30, 1, 19, 20, 20, 23, 13, 35, 12]
s_list = sorted(s_list)
total = sum(s_list)
# print(total)
if (total %10 !=0):
    print(total)
else:
    for s in s_list:
        if ((total-s) %10 !=0):
            print(total-s)
            break
    else:
        print(0)


Measured memory_bytes: 2940
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#define ll long long
#define rep(i,l,r)for(ll i=(l);i<(r);i++)
#define repp(i,l,r,k)for(ll i=(l);i<(r);i+=(k))
#define INF ((1LL<<62)-(1LL<<31))
#define max(p,q)((p)>(q)?(p):(q))
#define min(p,q)((p)<(q)?(p):(q))
#define bit(n,m)(((n)>>(m))&1)
int upll(const void*a, const void*b){return*(ll*)a<*(ll*)b?-1:*(ll*)a>*(ll*)b?1:0;}
int downll(const void*a, const void*b){return*(ll*)a<*(ll*)b?1:*(ll*)a>*(ll*)b?-1:0;}
void sortup(ll*a,int n){qsort(a,n,sizeof(ll),upll);}
void sortdown(ll*a,int n){qsort(a,n,sizeof(ll),downll);}
ll pom(ll a,ll n,int m){ll x=1;for(a%=m;n;n/=2)n&1?x=x*a%m:0,a=a*a%m;return x;}
//#define MOD 998244353
#define MOD 1000000007
#define invp(a,p)pom(a,p-2,p)

ll a[100010];
int main(){
	int n;
	scanf("%d",&n);
	rep(i,0,n)scanf("%lld",a+i);
	sortup(a,n);
	printf("%d",a[n/2]-a[n/2-1]);
}

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

using namespace std;
using LL = long long;

int n, m;

int main() {
  cin >> n >> m;
  priority_queue<int> q;
  for (int i = 1; i <= n; ++i) {
    int x;
    cin >> x;
    q.push(x);
  }

  LL wyn = 0;
  for (int i = 1; i <= m; ++i) {
    int x = q.top();
    q.pop();
    x /= 2;
    q.push(x);
  }
  while (!q.empty()) {
    LL x = q.top();
    q.pop();
    wyn += x;
  }
  cout << wyn;
}


Measured memory_bytes: 892
#include <stdio.h>

int main(void) {
  char input[6];
  int n, m;
  fgets(input, 5, stdin);
  sscanf(input, "%d", &n);
  while(n > 1000)n = n-1000;
  m = 1000 - n;
  printf("%d", m);
  return 0;
}

Measured memory_bytes: 1760
MOD = 10**9+7

H, W = map(int, input().split())
dp = []
grid = []

for _ in range(H):
    dp.append([0] * W)
    grid.append(input())

dp[0][0] = 1

for r in range(H):
    for c in range(W):
        if grid[r][c] == "#" or (r == 0 and c == 0):
            continue

        up = dp[r-1][c] if r > 0 else 0
        left = dp[r][c-1] if c > 0 else 0

        dp[r][c] = (up + left) % MOD

print(dp[-1][-1])




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

using namespace std;

const int OO = 1e9;
const double EPS = 1e-9;

#define ndl cout << '\n'
#define sz(v) int(v.size())
#define pb push_back
#define mp make_pair
#define fs first
#define sc second
#define present(a, x) (a.find(x) != a.end())
#ifdef LOCAL
#define db(...) ({cout << "> Line " << __LINE__  \
		<< ": "; _db(#__VA_ARGS__, __VA_ARGS__);})
#define RNG() rng()
#else
#define db(...) true
#define RNG() true
#endif

template<class T>
void _db(const char *dbStr, T e) {
	cout << dbStr << " = " << e << endl;
}
template<class T, class... L>
void _db(const char *dbStr, T e, L... r) {
  while(*dbStr != ',') cout << *dbStr++;
  cout << " = " << e << ','; _db(dbStr + 1, r...);
}
template<class S, class T>
ostream& operator<<(ostream& o, const map<S, T>& v) {
	o << "["; int i = 0;
	for (const pair<S, T>& pr : v) o << (!i++ ? "" : ", ") << "{"
	<< pr.fs << " : " << pr.sc << "}"; return o << "]";
}
template<template <class, class...> class S, class T, class... L>
ostream& operator<<(ostream& o, const S<T, L...>& v) {
	o << "["; int i = 0;
	for (const auto& e : v) o << (!i++ ? "" : ", ") << e;
	return o << "]";
}
template<class S, class T>
ostream& operator<<(ostream& o, const pair<S, T>& pr) {
	return o << "(" << pr.fs << ", " << pr.sc << ")";
}
ostream& operator<<(ostream& o, const string& s) {
	for (const char& c : s) o << c;
	return o;
}

template<class T> using V = vector<T>;
template<class T> using VV = V<V<T>>;
template<class T> using VVV = VV<V<T>>;
using ll = long long;
using pii = pair<int, int>;
using vi = V<int>;
using vii = V<pii>;
using vvi = VV<int>;
using mii = map<int, int>;
using umii = unordered_map<int, int>;
using si = set<int>;
using usi = unordered_set<int>;


V<ll> divs;
map<ll, int> PFs;

void getPFs(ll x) {
	for (ll i = 2; i * i <= x; ++i)
		while (x % i == 0)
			PFs[i]++, x /= i;
	if (x > 1)
		PFs[x]++;
}


int main() {
	#ifdef LOCAL
	auto stTime = clock();
//	freopen("in.txt", "r", stdin);
	mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count());
	#endif
	ios::sync_with_stdio(false);
	cout.precision(10);
	cin.tie(0);

	ll N;

	cin >> N;

	if (N == 1)
		cout << "0\n";
	else {
		getPFs(N);
		int ans = 0;
		for (auto& pr : PFs) {
			int j = 1;
			int e = pr.sc;
			while (e >= j)
				++ans, e -= j, ++j;
		}
		cout << ans << '\n';
	}



	#ifdef LOCAL
	cout << "\n\n\nExecution time: " <<
		(clock() - stTime) * 1e3 / CLOCKS_PER_SEC << " ms" << endl;
	#endif
	return 0;
}


Measured memory_bytes: 3652
#include<bits/stdc++.h>
using namespace std;
#define ll long long int
#define pb push_back
#define pf push_front
#define mod 1000000007
#define endl '\n'
#define fast ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);


int main()
{
      string s1,s2;
      cin>>s1>>s2;
      map<string,ll>mp;
      ll a,b;
      cin>>a>>b;
      mp[s1]=a;
      mp[s2]=b;
      string s;
      cin>>s;
      mp[s]--;

      cout<<mp[s1]<<" "<<mp[s2]<<endl;
}


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

int main()
{
    int a, b, c;
    cin >> a >> b >> c;
    if (a + b == c || a + c == b || b + c == a)
        cout << "Yes" << endl;
    else
        cout << "No" << endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define pb push_back
#define ll long long
#define md 1000000007
#define ld long double
#define pi 3.14159265359
using namespace std;

long long mul(long long a, long long b){
    if(a == 0 || b == 0){
        return 0;
    }
    if(a == -1){
        return -1;
    }
    ll res = a*b;
    if(a > (ll)(1e18)/b){
        return -1;
    }
    if(a == res/b){
        return res;
    }
}

int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    long long n, i = 0, j= 0, k = 0, l = 0, m = 0, a = 0, b = 0, sum = 0, x = 0, y = 0, z = 0, c, p;
    cin >> n;
    a = (ll)1;
    for(i = 0; i < n; i++){
        cin >> x;
        a = mul(a,x);
        //cout << a << " ";
    }
    cout << a;

    return 0;
}


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

using namespace std;
typedef long long ll;

int main (){
    string s = "abcdefghijklmnopqrstuvwxyz";
    char c;
    cin >> c;
    int ans = 0;
    for(int i = 0; i < 26; i++){
        if(c == s[i]){
            ans = i;
        }
    }
    cout << s[ans+1] << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <map>
#include <set>
#include <vector>
#include <algorithm>
#include <iostream>
#include <bitset>
#include <cassert>
#include <queue>
#include <random>
#include <stack>
#include <iomanip>
#include <math.h>
using namespace std;
#define rep(i, n) for (ll i = 0; i < (ll)n; i++)
#define repf(i, a, b) for (ll i = (ll)a; i < (ll)b; i++)
#define repr(i, a, b) for (ll i = (ll)a; i > (ll)b; i--)
#define repv(x, arr) for (auto &x : arr)
#define all(v) (v).begin(), (v).end()
#define vec(name, num) vector<ll> name((num), 0);
#define mp(a, b) make_pair(a, b)
#define pb(x) push_back(x)
#define F first
#define S second
typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<ld, ld> pdd;
typedef vector<ll> vll;
typedef vector<vll> vvll;
typedef vector<int> vii;
typedef vector<vii> vvii;
const ll mod = 1e9 + 7;
const int infi = 2147483600;
const ll infl = 1e17;

struct COMB
{
    int L;
    vll kaijo, gyaku;
    void __init__(int sz)
    {
        L = sz;
        kaijo.resize(L + 1, 0);
        gyaku.resize(L + 1, 0);
        kaijo[0] = 1;
        repf(i, 1, L + 1)
            kaijo[i] = (kaijo[i - 1] * i) % mod;
        gyaku[L] = powmod(kaijo[L], mod - 2, mod);
        rep(i, L)
            gyaku[L - 1 - i] = gyaku[L - i] * (L - i) % mod;
    }
    ll powmod(ll x, ll y, ll mod)
    {
        if (y==0)
            return 1;
        map<ll, ll> Z;
        Z[0] = 1;
        Z[1] = x;
        ll nowy = 1;
        ll nowx = x;
        while (nowy * 2 <= y)
        {
            nowy *= 2;
            nowx = nowx * nowx % mod;
            Z[nowy] = nowx;
        }
        ll nowz = nowy / 2;
        while (nowy < y)
        {
            if (nowz + nowy <= y)
            {
                nowy += nowz;
                nowx = (nowx * Z[nowz]) % mod;
            }
            nowz /= 2;
        }
        return nowx;
    }

    ll calc_comb(int n, int k)
    {
        if (n > L)
            return -1;
        return (((kaijo[n] * gyaku[k]) % mod) * gyaku[n - k]) % mod;
    }
    ll calc_kaijo(int i)
    {
        return kaijo[i];
    }
    ll calc_gyaku(int i)
    {
        return gyaku[i];
    }
};

int main()
{
    int n;
    cin >> n;
    vll a(n);
    rep(i, n) cin >> a[i];

    COMB comb;
    comb.__init__(n);
    vll bunsu(n + 1, 0);
    repf(i,1,n+1){
        bunsu[i] = comb.powmod(i, mod - 2, mod);
    }
    vll s(n + 1, 0);
    rep(i,n){
        s[i+1]=(s[i]+bunsu[i+1])%mod;
    }
    ll ans = 0;
    rep(i,n){
        ll now = (mod + s[n - i] + s[i + 1] - s[1]) % mod;
        now = (now * comb.calc_kaijo(n)) % mod;
        now = (a[i] * now) % mod;
        ans = (ans + now) % mod;
    }
    cout << ans << endl;
}


Measured memory_bytes: 4224
#include <bits/stdc++.h>
using namespace std;
int main(void){
  int n,m,k,i,j,a,ans=0;
  cin >> n >> m;
  vector<int> l(m+3,0);
  for (i=0;i<n;i++){
    cin >> k;
    for (j=0;j<k;j++){
      cin >> a;
      l.at(a)++;
    }
  }
  for (i=1;i<=m;i++) if (l.at(i)==n) ans++;
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <math.h>
#include <algorithm>
#include <vector>
using std::cin;
using std::cout;
using std::endl;
using std::string;
using std::vector;
				
				
void del_island(int i,int j,vector<vector<int>> &v){	
	v[i][j] = 0;
	if(v[i-1][j] == 1){
		del_island(i-1,j,v);
	}
	
	if(v[i+1][j] == 1){
		del_island(i+1,j,v);
	}
	if(v[i][j-1] == 1){
		del_island(i,j-1,v);
	}
	
	if(v[i][j+1] == 1){
		del_island(i,j+1,v);
	}
	if(v[i-1][j-1] == 1){
		del_island(i-1,j-1,v);
	}
	
	if(v[i-1][j+1] == 1){
		del_island(i-1,j+1,v);
	}
	
	if(v[i+1][j-1] == 1){
		del_island(i+1,j-1,v);
	}
	
	if(v[i+1][j+1] == 1){
		del_island(i+1,j+1,v);
	}

}

void mapping(vector<vector<int>>v,int w,int h){
	for(int i = 1;i <= h ; i++){
		for(int j = 0; j <= w ;j++){
			cout << v[i][j];
		}
		cout <<endl;
	}
	cout << endl;
}
void mapping2(int i, int j){
	cout << "i = " << i << endl;
	cout << "j = " << j << endl;
}
int count_island(int w, int h,vector<vector<int>> v){
	int count = 0;
	for(int i = 1 ; i <= h ;i++){
		for(int j = 1 ;j <= w ;j++){
			//cout << v[i][j] ;
			if(v[i][j] == 1){
				count++;
				//cout << "hello" <<endl;
				del_island(i,j,v);
				//mapping2(i,j);
				
			}
		}
	}
	return count;
}
	
int main(){ 
	int w,h;
	vector<vector<int>> v(60,vector<int>(60,0));
	int count;

	while(1){
		cin >> w >> h;
		if(w == 0 && h == 0){
			break;
		}
		count = 0; 
		for(int i = 1; i <= 59 ; i++){
			for(int j = 1 ; j <= 59 ; j++){
				v[i][j] = 0;
			}
		}

		for(int i = 1;i <= h; i++){
			for(int j = 1; j <= w; j++){
				cin >> v[i][j];
			}
		}

		count = count_island(w,h,v);
		//mapping(v,50,50);


		cout << count << endl;
	}
}

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

void swap (int *x, int *y) {
  int temp;    // 値を一時保存する変数

  temp = *x;
  *x = *y;
  *y = temp;
}

/***
* pivotを決め、
* 全データをpivotを境目に振り分け、
* pivotの添え字を返す
***/
int partition (int array[], int left, int right) {
  int i, j, pivot;
  i = left;
  j = right + 1;
  pivot = left;   // 先頭要素をpivotとする

  do {
    do { i++; } while (array[i] < array[pivot]);
    do { j--; } while (array[pivot] < array[j]);
    // pivotより小さいものを左へ、大きいものを右へ
    if (i < j) { swap(&array[i], &array[j]); }
  } while (i < j);

  swap(&array[pivot], &array[j]);   //pivotを更新

  return j;
}

/* クイックソート */
void quick_sort (int array[], int left, int right) {
  int pivot;

  if (left < right) {
    pivot = partition(array, left, right);
    quick_sort(array, left, pivot-1);   // pivotを境に再帰的にクイックソート
    quick_sort(array, pivot+1, right);
  }
}





int main(void){
  int A,B;
  scanf("%d %d",&A,&B);
  printf("%d",A*B);
   return 0;
}


Measured memory_bytes: 1736
#define _GLIBCXX_DEBUG

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

// modint: mod 計算を int を扱うように扱える構造体
template<int MOD> struct Fp {
    long long val;
    constexpr Fp(long long v = 0) noexcept : val(v % MOD) {
        if (val < 0) v += MOD;
    }
    constexpr int getmod() { return MOD; }
    constexpr Fp operator - () const noexcept {
        return val ? MOD - val : 0;
    }
    constexpr Fp operator + (const Fp& r) const noexcept { return Fp(*this) += r; }
    constexpr Fp operator - (const Fp& r) const noexcept { return Fp(*this) -= r; }
    constexpr Fp operator * (const Fp& r) const noexcept { return Fp(*this) *= r; }
    constexpr Fp operator / (const Fp& r) const noexcept { return Fp(*this) /= r; }
    constexpr Fp& operator += (const Fp& r) noexcept {
        val += r.val;
        if (val >= MOD) val -= MOD;
        return *this;
    }
    constexpr Fp& operator -= (const Fp& r) noexcept {
        val -= r.val;
        if (val < 0) val += MOD;
        return *this;
    }
    constexpr Fp& operator *= (const Fp& r) noexcept {
        val = val * r.val % MOD;
        return *this;
    }
    constexpr Fp& operator /= (const Fp& r) noexcept {
        long long a = r.val, b = MOD, u = 1, v = 0;
        while (b) {
            long long t = a / b;
            a -= t * b; swap(a, b);
            u -= t * v; swap(u, v);
        }
        val = val * u % MOD;
        if (val < 0) val += MOD;
        return *this;
    }
    constexpr bool operator == (const Fp& r) const noexcept {
        return this->val == r.val;
    }
    constexpr bool operator != (const Fp& r) const noexcept {
        return this->val != r.val;
    }
    friend constexpr ostream& operator << (ostream &os, const Fp<MOD>& x) noexcept {
        return os << x.val;
    }
    friend constexpr istream& operator >> (istream &is, Fp<MOD>& x) noexcept {
        return is >> x.val;
    }
    friend constexpr Fp<MOD> modpow(const Fp<MOD> &a, long long n) noexcept {
        if (n == 0) return 1;
        auto t = modpow(a, n / 2);
        t = t * t;
        if (n & 1) t = t * a;
        return t;
    }
};


const int MOD = 1000000007;
using mint = Fp<MOD>;

long long N, K;

mint dp[110][111000];
mint sdp[111000];
long long num[111000];

mint solve() {
  //各レイヤーの個数
  int iter = 0;
  for(int i = 1; i <= N; ) {
    int j = N / i;
    if(j >= i) {
      // sqrt(N)以下
      num[iter++] = 1;
      ++i;
    } else {
      // sqrt(N)以上
      num[iter++] = N/j - i + 1;
      i = N/j + 1;
    }
  }
  
  memset(dp, 0, sizeof(dp));
  dp[0][0] = 1; //長さ0の場合は1で初期化する(*numされる対象となる)
  for(int k=0; k<K; ++k) {
    //現在のkの累積和を計算
    memset(sdp, 0, sizeof(sdp));
    for(int j=0; j<iter; ++j) sdp[j+1] = sdp[j] + dp[k][j];
    for(int j=0; j<iter; ++j) dp[k+1][j] = sdp[iter - j] * mint(num[j]);
  }
  
  mint res = 0;
  for(int j=0; j<iter; ++j) res += dp[K][j];
  return res;
}

int main() {
  cin >> N >> K;
  cout << solve() << endl;
}


Measured memory_bytes: 97024
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int N, A;
  cin >> N ;
  cin >> A ;

  if (N % 500 <= A){
  cout <<"Yes" << endl;
  }
  else if (N % 500 > A){
  cout <<"No" << endl;
  }
}


Measured memory_bytes: 256
#include<stdio.h>
#include <algorithm>
#include <cassert>
#include <cctype>
#include <climits>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <iostream>
#include <iterator>
#include <list>
#include <map>     
#include <numeric>
#include <utility>
#include <queue>
#include <set>
#include <sstream>
#include <iomanip>
#include <stack>
#include <string>
#include <limits>
#include <vector>
using namespace std;
#define ll long long
#define ld long double
#define rep(a,t) for(int a=0;a<t;++a) 
#define forever while(true)
#define Sort(a) sort(a.begin(),a.end())
#define Reverse(a) reverse(a.begin(),a.end())
#define pb push_back
#define print_double(val,a) cout << fixed << setprecision(a) << val << endl;
ll mod = 1e9 + 7;
int main()
{
	cin.tie(0);
	ios::sync_with_stdio(false);
	string s;
	int K;
	cin >> s >> K;
	if (s.length() == 1 && K == 1) { cout << s << endl; return 0; }
	vector<string>vec;
	for (int k = 1; k <= min(5,(int)s.length()); k++) {
		for (int i = 0; i < s.length()-k+1; i++) {
			string u = s.substr(i, k);
			bool flag = true;
			for (int k = 0; k < vec.size(); k++) {
				if (vec[k] == u) { flag = false; break; }
			}
			if (flag) { vec.push_back(u); }
		}
	}
	Sort(vec);
	cout << vec[K - 1] << endl;
	return 0;
}


Measured memory_bytes: 1152
import sys
sys.setrecursionlimit(10**9)
def input():
    return sys.stdin.readline().rstrip()

def main():
    S = input()
    N = len(S)
    ans = 0
    for i in range(N):
        if S[i] != S[N-i-1]:
            ans+=1
    print(ans//2)


if __name__ == '__main__':
    main()


Measured memory_bytes: 38256
use std::io::*;
use std::str::*;

fn read<T: FromStr>(s: &mut StdinLock) -> Option<T> {
    let s = s
        .by_ref()
        .bytes()
        .map(|c| c.unwrap() as char)
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect::<String>();
    s.parse::<T>().ok()
}

fn main() {
    let stdin = std::io::stdin();
    let n = read::<i32>(&mut stdin.lock()).unwrap();
    let d = read::<i32>(&mut stdin.lock()).unwrap();
    let mut ne = n / (d * 2 + 1);
    if n % (d * 2 + 1) != 0 {
        ne += 1
    };
    println!("{}", ne);
}


Measured memory_bytes: 4352