akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <cmath>
#include <complex>
#include <string>
#include <sstream>
#include <limits>
#include <algorithm>
#include <functional>

#include <vector>

using namespace std;

template<typename value_type>
class fast_mod_combination
{
public:
	value_type mod_value;

	vector<value_type> mod_inv;
	vector<value_type> fact;
	vector<value_type> fact_inv;

public:
	fast_mod_combination(const value_type& limit, const value_type& m)
		: mod_value(m), mod_inv(), fact(), fact_inv()
	{
		mod_inv.assign(limit + 1, 0);
		fact.assign(limit + 1, 0);
		fact_inv.assign(limit + 1, 0);

		mod_inv[1] = 1;
		fact[0] = 1;
		fact[1] = 1;
		fact_inv[0] = 1;
		fact_inv[1] = 1;

		for (value_type i = 2; i <= limit; i++)
		{
			mod_inv[i] = mod_value - ((mod_value / i) * mod_inv[mod_value % i] % mod_value);
			fact[i] = (fact[i - 1] * i) % mod_value;
			fact_inv[i] = (fact_inv[i - 1] * mod_inv[i]) % mod_value;
		}
	}

public:
	value_type process(const value_type& n, const value_type& r)
	{
		if (n < 0 || r < 0) return 0;
		if (n < r) return 0;
		if (n == r) return 1;

		return (fact[n] * (fact_inv[r] * fact_inv[n - r] % mod_value)) % mod_value;
	}
};

//fast_mod_combination<long long> fmc(N, MOD);
//long long result = fmc.process(n, r);

const long long MOD = 1e9 + 7;

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

	int N, K;
	cin >> N >> K;

	fast_mod_combination<long long> fmc(N, MOD);

	long long result = 0;
	for (int i = 0; i <= min(K, N - 1); i++)
	{
		result = (result + (fmc.process(N, i) * fmc.process(N - 1, i)) % MOD) % MOD;
	}

	cout << result;

    return 0;
}

Measured memory_bytes: 4992
#include <bits/stdc++.h>
#include <algorithm>
#include <string>
using namespace std;
int main(){
	int H, W, K; 
	cin >> H >> W >> K; 
	long long int dp[110][10] = {}; 
	long long int P = 1e9 + 7; 
	int Fib[8] = {1, 1, 2, 3, 5, 8, 13, 21}; 
	if(W == 1){cout << 1 << endl; }
	else{
	dp[0][1] = 1; 
	for(int i = 1; i < 105; i++){
		dp[i][1] = ((dp[i-1][1] * Fib[W-1]) % P + (dp[i-1][2] * Fib[W-2]) % P) % P; 
		dp[i][W] = ((dp[i-1][W] * Fib[W-1]) % P + (dp[i-1][W-1] * Fib[W-2]) % P) % P; 
		for(int j = 2; j < W; j++){
			dp[i][j] = ((dp[i-1][j-1] * Fib[j-2] * Fib[W-j]) % P + (dp[i-1][j] * Fib[j-1] * Fib[W-j]) % P + (dp[i-1][j+1] * Fib[j-1] * Fib[W-j-1]) % P ) % P; 
	}
        }
	cout << dp[H][K] << endl; 
	}
}

Measured memory_bytes: 256
#include<algorithm>
#include<cstdio>
using namespace std;
int n,P,sl,fh,res,ans,pw1[3010],pw2[3010][3010],C[3010][3010],S[3010][3010];
int rd()
{
	sl=0;fh=1;
	char ch=getchar();
	while(ch<'0'||'9'<ch) {if(ch=='-') fh=-1; ch=getchar();}
	while('0'<=ch&&ch<='9') sl=sl*10+ch-'0',ch=getchar();
	return sl*fh;
}
int _pow(int k,int i)
{
	int t=1;
	for(;i;i>>=1,k=1ll*k*k%P)
		if(i&1)
			t=1ll*t*k%P;
	return t;
}
int main()
{
	n=rd();P=rd();pw1[0]=pw2[0][1]=1;
	for(int i=1;i<=n;++i) pw2[i][1]=2ll*pw2[i-1][1]%P,pw1[i]=2ll*pw1[i-1]%(P-1);
	for(int i=0;i<=n;++i) pw1[i]=_pow(2,pw1[i]);
	for(int i=0;i<=n;++i) pw2[i][0]=pw2[0][i]=C[i][0]=1;
	S[0][0]=1;
	for(int i=1;i<=n;++i)
	{
		for(int j=1;j<=i;++j)
		{
			C[i][j]=C[i-1][j]+C[i-1][j-1];
			if(C[i][j]>=P) C[i][j]-=P;
			S[i][j]=(S[i-1][j-1]+1ll*j*S[i-1][j])%P;
		}
		for(int j=2;j<=n-i;++j) pw2[i][j]=1ll*pw2[i][1]*pw2[i][j-1]%P;
	}
	for(int i=1;i<=n+1;++i) S[n+1][i]=(S[n][i-1]+1ll*i*S[n][i])%P;
	for(int x=1,i=0;i<=n;++i,x=-x)
	{
		res=0;
		for(int j=0;j<=i;++j) res=(res+1ll*S[i+1][j+1]*pw2[n-i][j])%P;
		ans=(ans+1ll*x*res*C[n][i]%P*pw1[n-i])%P;
	}
	if(ans<0) ans+=P;
	printf("%d\n",ans);
	return 0;
}

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

int main(){
  int N;
  cin >> N;
  vector<int> a(N),sum(N,0);
  set<int> s;
  for(int i=0;i<N;i++){
    cin >> a.at(i);
  }
  int n;
  int count=0;
  for(int i=N;i>0;i--){
    if(i*2<=N){
      n=i;
      break;
    }
    if(a.at(i-1)==1){
      s.insert(i);
      count++;
    }
  }
  for(int i=n;i>0;i--){
    for(int j=2;i*j<=N;j++){
      if(s.count(i*j)){
        sum.at(i-1)++;
      }
    }
    if(sum.at(i-1)%2!=a.at(i-1)){
      s.insert(i);
      count++;
    }
  }
  cout << count << endl;
  int c=0;
  for(auto x : s){
    cout << x;
    if(c==count-1){
      cout << endl;
    }else{
      cout << " ";
    }
    c++;
  }
  return 0;
}


Measured memory_bytes: 8448
import sys
from collections import defaultdict
from heapq import *

sys.setrecursionlimit(10 ** 6)
int1 = lambda x: int(x) - 1
p2D = lambda x: print(*x, sep="\n")
def MI(): return map(int, sys.stdin.readline().split())
def MI1(): return map(int1, sys.stdin.readline().split())
def LI(): return list(map(int, sys.stdin.readline().split()))
def LLI(rows_number): return [LI() for _ in range(rows_number)]

def main():
    to=defaultdict(list)
    n=int(input())
    for _ in range(n-1):
        a,b,c=MI()
        a,b=a-1,b-1
        to[a].append([b,c])
        to[b].append([a, c])
    q,k=MI()
    k-=1
    dist=[-1]*n
    hp=[]
    heappush(hp,[0,k])
    while hp:
        d,u=heappop(hp)
        if dist[u]!=-1:continue
        dist[u]=d
        for v,c in to[u]:
            if dist[v]!=-1:continue
            heappush(hp,[d+c,v])
    for _ in range(q):
        u,v=MI1()
        print(dist[u]+dist[v])

main()

Measured memory_bytes: 62340
module lib1

let allLines = seq{
    let mutable line = System.Console.ReadLine()
    while line <> null do
        yield line
        line <- System.Console.ReadLine()
}

let mutable line = System.Console.ReadLine()

let data = 
    allLines
    |> Seq.map (fun l ->
        int l
    )
    |>Seq.sort
    |>Seq.fold (fun s t ->
        match snd s with
        |Some b when b = t -> s
        |_ -> (fst s + 1, Some t)
    ) (0, None)
    |> fst

System.Console.WriteLine(data)


Measured memory_bytes: 14304
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using static System.Console;

namespace AtCoder
{
    class Program
    {
        static void Main()
        {
            var raw = ReadLine().Split().Select(int.Parse).ToArray();
            var A = raw[0];
            var B = raw[1];
            var K = raw[2];

            var c = 0;
            for (int i = Math.Max(A, B); i > 0; i--)
            {
                if (A % i == 0 && B % i == 0) c++;
                if (c == K)
                {
                    WriteLine(i);
                    break;
                }
            }
        }
    }
}


Measured memory_bytes: 13268
#include <iostream>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <algorithm>
#include <string>
#include <cmath>
#include <cstdio>
#include <iomanip>
#include <fstream>
#include <cassert>
#include <cstring>
#include <unordered_set>
#include <unordered_map>
#include <numeric>
#include <ctime>
#include <bitset>
#include <complex>

using namespace std;

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

	int n;
	cin >> n;
	map<string, int> kek;
	while (n--) {
		string s;
		cin >> s;
		kek[s]++;
	}
	vector<pair<int, string>> lol;
	for (auto t : kek) {
		lol.push_back({-t.second, t.first});
	}
	sort(lol.begin(), lol.end());
	for (auto t : lol) {
		if (t.first == lol.front().first) cout << t.second << '\n';
	}
}


Measured memory_bytes: 28400
#include<cstdio>
#define MAX 100

int main(int argc, char const *argv[])
{
    int N, K;
    int S[MAX], sum[MAX];
    int temp;
    while(1){
        bool flag = true;
        scanf("%d %d", &N, &K);
        if(N==0 && K==0) break;

        for(int i=0; i<K; i++){
            sum[i] = 0;
            scanf("%d", &S[i]);
        }

        for(int i=0; i<N; i++){
            for(int j=0; j<K; j++){
                scanf("%d", &temp);
                sum[j] += temp;
            }
        }

        for(int i=0; i<K; i++){
            if(S[i] < sum[i]) { flag = false; break;}
        }

        if(flag) printf("Yes\n");
        else printf("No\n");
    }

    return 0;
}



Measured memory_bytes: 2568
#include <bits/stdc++.h>
#define rep(i,n)    for(long long i = 0; i < (n) ; ++i)
#define orep(i,n)   for(long long i = 1; i <= (n); ++i)   // one rep
#define drep(i,n)   for(long long i = (n)-1; i >= 0; --i) // down rep
#define srep(i,s,t) for(long long i = (s); i < (t); ++i)  // set rep
#define rng(x)  (x).begin(),(x).end()

  // range
#define rrng(a) (a).rbegin(),(a).rend() // reverse range
#define isin(x,l,r) ((l) <= (x) && (x) < (r))
#define ru(x,y) (((x)+(y)-1)/(y)) // round up
#define fi first
#define se second
#define eb emplace_back
#define fcout cout << fixed << setprecision(15)


using namespace std;
using ll  = long long;
using P   = pair<int,int>;
using vi  = vector<int>;
using vvi = vector<vi>;
using vp  = vector<P>;
using vl  = vector<ll>;

template<typename T> void Yes(T flag) {
  cout << (flag ? "Yes" : "No") << endl;
}

template<typename T> void pv(vector<T> vec) {
  cout << "[";
  for(auto& v : vec) { cout << v << ","; }
  cout << "]" << endl;
}

template<>
void pv(vector<P> vec) {
  cout << "[";
  for(auto& v : vec) {
    cout << "<" << v.fi << ","<< v.se << ">" << ",";
  }
  cout << "]" << endl;
}

template<typename T> void pv2(vector<vector<T>> vec) {
  for(auto& v : vec) pv(v);
}

int main() {
  int n,k;
  cin >> n >> k;
  int ans=1;
  rep(i,n) {
    ans=min(ans*2,ans+k);
  }
  cout << ans <<endl;

  return 0;
}


Measured memory_bytes: 256
#include <map>
#include <set>
#include <list>
#include <cmath>
#include <deque>
#include <stack>
#include <queue>
#include <bitset>
#include <cstdio>
#include <string>
#include <vector>
#include <random>
#include <chrono>
#include <utility>
#include <numeric>
#include <cstdlib>
#include <cstring>
#include <climits>
#include <sstream>
#include <assert.h>
#include <iostream>
#include <iomanip>
#include <algorithm>
#include <unordered_map>
using namespace std;

void __print(int x) {cerr << x;}
void __print(long x) {cerr << x;}
void __print(float x) {cerr << x;}
void __print(double x) {cerr << x;}
void __print(unsigned x) {cerr << x;}
void __print(long long x) {cerr << x;}
void __print(long double x) {cerr << x;}
void __print(unsigned long x) {cerr << x;}
void __print(unsigned long long x) {cerr << x;}
void __print(char x) {cerr << '\'' << x << '\'';}
void __print(bool x) {cerr << (x ? "true" : "false");}
void __print(const char *x) {cerr << '\"' << x << '\"';}
void __print(const string &x) {cerr << '\"' << x << '\"';}

template<typename T, typename V> void __print(const pair<T, V> &x) {cerr << '{'; __print(x.first); cerr << ','; __print(x.second); cerr << '}';}
template<typename T>void __print(const T &x) {int f = 0; cerr << '{'; for (auto &i : x) cerr << (f++ ? "," : ""), __print(i); cerr << "}";} void _print() {cerr << "]\n";}
template <typename T, typename... V>void _print(T t, V... v) {__print(t); if (sizeof...(v)) cerr << ", "; _print(v...);}
#ifdef HOME
#warning CHECK int:ll::INT_MAX:LLONG_MAX
#define maxn 20
#define debug(x...) cerr << "[" << #x << "] = ["; _print(x)
#else
#define maxn 2000006
#define gcd __gcd
#define debug(x...)
#endif

#define ff first
#define endl '\n'
#define ss second
#define inf 0x3f3f3f3f
#define MOD 1000000007
#define PI 3.14159265358979323846264338327950L
#define f(i,x,n) for(int i=x;i<=n;i++)
#define fr(i,x,n) for(int i=x;i>=n;i--)
struct _ { ios_base::Init i; _() { ios_base::sync_with_stdio(false), cin.tie(NULL), cout.tie(NULL); } } _;

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


int main() {

	long long  a; cin>>a;
	cout<<a+a*a+a*a*a;

	return 0;
}

Measured memory_bytes: 3636
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<(n);++i);
 
int main() {
  int N; cin >> N;
  int c[10][10] = {};
  int ans = 0;
  for(int i = 1;i <= N; ++i){
    int a = i%10;
    int b = i;
    while(b>=10) b/=10;
    c[a][b]++;
  }
  
  for(int i = 0;i < 10; ++i){
    for(int j = 0;j < 10; ++j){
      ans += c[i][j]*c[j][i];
    }
  }
  
  cout << ans << endl;
}

Measured memory_bytes: 256
n = int(input())
d = [list(map(int, input().split())) for _ in range(n)]

streak = 0
ans = False

for a, b in d:
    if a == b:
        streak += 1
    else:
        streak = 0
    if streak >= 3: ans = True; break

print('Yes' if ans else 'No')


Measured memory_bytes: 9168
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(ll i=0;i<n;i++)
#define repl(i,l,r) for(ll i=(l);i<(r);i++)
#define per(i,n) for(ll i=n-1;i>=0;i--)
#define fi first
#define se second
#define all(x) (x).begin(),(x).end()
#define CST(x) cout<<fixed<<setpercision(x)
using ll=long long;
using vl=vector<ll>;
using vvl=vector<vector<ll>>;
using pl=pair<ll,ll>;
template<class T> inline bool chmin(T& a, T b){
    if(a>b){a = b;return true;}return false;}
template<class T> inline bool chmax(T& a, T b){
    if(a<b){a=b;return true;}return false;}
const ll MOD=1000000007;
const ll MOD9=998244353;
const int inf=1e9;
const ll INF=4e18;
const ll dy[4]={1,0,-1,0};
const ll dx[4]={0,-1,0,1};
int main(){
    ll a,b;cin>>a>>b;
    if(a<b)cout<<"a < b"<<endl;
    else if(a==b)cout<<"a == b"<<endl;
    else cout<<"a > b"<<endl;
    return 0;
}


Measured memory_bytes: 3108
a = int(input()) #500円
b = int(input()) #100円
c = int(input()) #50円
x = int(input())
 
count = 0
for i in range(a+1):
  for j in range(b+1):
    for k in range(c+1):
      if x == 500 * i + 100 * j + 50 * k:
        count += 1
print(count)     

Measured memory_bytes: 3060
#include <cstdio>
#include <algorithm>

using namespace std;

int main(){
    int n;
    scanf("%d", &n);
    int w[n];
    for(int i = 0; i < n; i++){
        scanf("%d", &w[i]);
    }

    int sum = 0;
    for(int i = 0; i < n; i++){
        sum += w[i];
    }

    int S1 = 0, S2;
    int ans = 100;
    for(int i = 0; i < n-1; i++){
        S1 += w[i];
        S2 = sum - S1;
        ans = min(ans, abs(S1 - S2));
    }

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

    return 0;
}

Measured memory_bytes: 128
N = int(input())
H = [int(x) for x in input().split()]

if N == 1:
  print(0)
else:
  ans = []
  c = 0
  for i in range(N - 1):
    if H[i] >= H[i + 1]:
      c += 1
      if i == N - 2:
        ans.append(c)
    elif H[i] < H[i + 1]:
      ans.append(c)
      c = 0
  print(max(ans))

Measured memory_bytes: 14252
#include<cstring>
#include<iostream>
#include<string>
#include<vector>
#include<fstream>
#include<cmath>
#include<algorithm>
#define ll long long
using namespace std;
int f[510][510];
int x[510],y[510];
int main()
{	
 	int n,m;
 	scanf("%d%d",&n,&m);
 	char c;
 	int z;
 	for(int i=1;i<=n;i++)
 	{
 		z=0;
 		for(int j=1;j<=m;j++)
 		{
 			cin>>c;
 			if(c=='#')f[i][j]=1;
 			else f[i][j]=0;
 			z+=f[i][j];
		 }
		 x[i]=z;
	 }
	 for(int i=1;i<=m;i++)
	 {
	 	z=0;
	 	for(int j=1;j<=n;j++)
	 	{
	 		z+=f[j][i]; 
		 }
		 y[i]=z;
	 }
	 for(int i=1;i<=n;i++)
	 {
	 	if(x[i]==0)continue;
	 	for(int j=1;j<=m;j++)
	 	{
	 		if(y[j]==0)continue;
	 		if(f[i][j]==1)cout<<"#";
	 		else cout<<".";
		 }
		 cout<<endl;
	 }
}

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

int cnt = 0;
void insertion(vector<int> &A, int n, int g) {
	for (int i = g; i < n; ++i) {
		int v = A.at(i);
		int j = i - g;
		while (j >= 0 && A.at(j) > v) {
			A.at(j + g) = A.at(j);
			j -= g;
			++cnt;
		}
		A.at(j + g) = v;
	}
}
void shell(vector<int> &A, int n) {
	int gn = 4;
	vector<int> G = {1};
	while (gn < n) {
		G.insert(G.begin(), gn);
		gn = 3 * gn + 1;
	}
	int m = G.size();
	for (int i = 0; i < m; ++i) {
		insertion(A, n, G.at(i));
	}

	cout << m << endl;
	for (int i = 0; i < m; ++i) {
		cout << G.at(i);
		if (i == m - 1) {
			cout << endl;
		} else {
			cout << " ";
		}
	}
}

int main() {
	int n;
	cin >> n;
	vector<int> A(n);
	for (int i = 0; i < n; ++i) {
		cin >> A.at(i);
	}
	shell(A, n);
	cout << cnt << endl;
	for (int i = 0; i < n; ++i) {
		cout << A.at(i) << endl;
	}
}


Measured memory_bytes: 6776
#include <cstdio>

using namespace std;

int main() {
  double w;
  while (scanf("%lf", &w) == 1) {
    if (w <= 48.0)
      puts("light fly");
    else if (w <= 51.0)
      puts("fly");
    else if (w <= 54.0)
      puts("bantam");
    else if (w <= 57.0)
      puts("feather");
    else if (w <= 60.0)
      puts("light");
    else if (w <= 64.0)
      puts("light welter");
    else if (w <= 69.0)
      puts("welter");
    else if (w <= 75.0)
      puts("light middle");
    else if (w <= 81.0)
      puts("middle");
    else if (w <= 91.0)
      puts("light heavy");
    else
      puts("heavy");
  }
  return 0;
}

Measured memory_bytes: 0
using System;
using System.IO;
using System.Collections;
using System.Collections.Generic;
using System.Linq;

class CompetitiveProgrammingProgram
{
    static long Gcd(long a, long b)
    {
        long[] v = new long[] { a, b };
        while (v[1] != 0) { v = new long[] { v[1], v[0] % v[1] }; }
        return v[0];
    }
    static long Lcm(long a, long b)
    {
        return a / Gcd(a, b) * b;
    }
    class Node<T>
    {
        private int m_height;
        private Node<T> m_parent;
        public T Item { get; private set; }
        public Node(T item)
        {
            m_height = 0;
            m_parent = this;
            Item = item;
        }
        public Node<T> Find()
        {
            if (m_parent == this) { return this; }

            Node<T> parent = m_parent.Find();
            m_parent = parent;
            return parent;
        }
        public static void Unite(Node<T> a, Node<T> b)
        {
            Node<T> p = a.Find();
            Node<T> q = b.Find();
            if (p.m_height < q.m_height)
            {
                p.m_parent = q;
                q.m_height = Math.Max(p.m_height + 1, q.m_height);
            }
            else
            {
                q.m_parent = p;
                p.m_height = Math.Max(q.m_height + 1, p.m_height);
            }
        }
    }
    static void Main(string[] args)
    {
        int K = int.Parse(Console.ReadLine());
        int a = 7;
        a %= K;
        int ans = 1;
        while (a != 0)
        {
            a = a * 10 + 7;
            a %= K;
            ans++;
            if (ans > 10*K)
            {
                ans = -1;
                break;
            }
        }
        Console.WriteLine(ans);
    }
}

Measured memory_bytes: 27436
from sys  import stdin,stdout

import bisect

import math

def st():
    return list(stdin.readline().strip())

def inp():
    return int(stdin.readline())

def li():
    return list(map(int,stdin.readline().split()))

def mp():
    return map(int,stdin.readline().split())

def pr(n):
    stdout.write(str(n)+"\n")

def soe(limit):
    l=[1]*(limit+1)
    prime=[]
    for i in range(2,limit+1):
        if l[i]:
            for j in range(i*i,limit+1,i):
                l[j]=0

    for i in range(2,limit+1):
        if l[i]:
            prime.append(i)
    return prime

def segsoe(low,high):
    limit=int(high**0.5)+1
    prime=soe(limit)
    n=high-low+1
    l=[0]*(n+1)
    for i in range(len(prime)):
        lowlimit=(low//prime[i])*prime[i]
        if lowlimit<low:
            lowlimit+=prime[i]
        if lowlimit==prime[i]:
            lowlimit+=prime[i]
        for j in range(lowlimit,high+1,prime[i]):
            l[j-low]=1
    for i in range(low,high+1):
        if not l[i-low]:
            if i!=1:
                print(i)
                
def gcd(a,b):
    while b:
        a=a%b
        b,a=a,b
    return a

def power(a,n):
    r=1
    while n:
        if n&1:
            r=(r*a)
        a*=a
        n=n>>1
    return r

def check(n,s):
    v=str(n)
    for i in v:
        if i in s:
            return False
    return True
    

    
def solve():
    n=inp()
    a=n*(n+1)//2
    pr(a)

        
        

for _ in range(1):
    solve()
    


Measured memory_bytes: 9180
#include <stdio.h>
#include <stdlib.h>
#define int long long
#define p (int)(1e9 + 7)

int MOD(int a){
	a %= p;
	return a >= 0 ? a : a + p;
}

int power(int a, int N){
	if(N == 0){
		return 1;
	}
	else if(N % 2 == 0){
		return power(MOD(a * a), N / 2);
	}
	else{
		return MOD(a * power(a, N - 1));
	}
}

int inverse(int a){
	return power(a, p - 2);
}

signed main(){
	int N, i, ans = 0;
	scanf("%lld", &N);
	int *A = (int *)malloc(sizeof(int) * N);
	for(i = 0; i < N; i++){
		scanf("%lld", &A[i]);
	}
	int *fact = (int *)malloc(sizeof(int) * (N + 1));
	int *inv = (int *)malloc(sizeof(int) * (N + 1));
	int *inv_sum = (int *)malloc(sizeof(int) * (N + 1));
	fact[0] = 1;
	inv_sum[0] = 0;
	for(i = 1; i <= N; i++){
		fact[i] = MOD(fact[i - 1] * i);
		inv[i] = inverse(i);
		inv_sum[i] = MOD(inv_sum[i - 1] + inv[i]);
	}
	for(i = 0; i < N; i++){
		ans = MOD(ans + (inv_sum[i + 1] + inv_sum[N - i] - 1) * A[i]);
	}
	printf("%lld\n", MOD(ans * fact[N]));
	return 0;
}

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

typedef long long ll;

// static const int MAX = 1e6;
// static const int NIL = -1;
// static const ll INF = 1<<21;
// static const ll MOD = 1e9 + 7;

// bool compPair(const pair<int, int>& arg1, const pair<int, int>& arg2) {
//     return arg1.first > arg2.first;
// }

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

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

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

    if(x==7||x==5||x==3) cout << "YES" << endl;
    else  cout << "NO" << endl;
    
    return 0;
}


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

int keta(int n) {
    int res;
    for(int i = 0; i < 100; i++) {
        n = n / 10;

        if(n == 0) {
            res = i + 1;
            break;
        }
    }
    return res;
}

ll risi(ll n) {
    ll y = n / 100;
    ll res;
    res = n + y;
    return res;
}
int main() {
    int n, k;
    cin >> n >> k;
    vector<int> p(n);
    rep(i, n) p[i] = 0;
    rep(i, k) {
        int d;
        cin >> d;

        rep(j, d) {
            int a;
            cin >> a;
            p[a - 1]++;
        }
    }
    int cnt = 0;
    rep(i, n) {
        if(p[i] == 0) cnt++;
    }
    cout << cnt << endl;
}


Measured memory_bytes: 3636
#include <iostream>
#include <cmath>
#include <vector>
#include <map>
#include <stack>
#include <queue>
#include <set>
#include <algorithm>
#include <iomanip>
#include <string.h>

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

typedef long long lint;

using namespace std;

int main(){
  double a,b,x,l;
  cin>>a>>b>>x;
  l=x/(a*a);
  //固定小数点
  cout<<fixed;
  //桁数固定
  cout<<setprecision(8);
  if(l>b/2)cout<<atan2(b-l,a/2.0)*180.0/3.14159265358979<<endl;
  else cout<<atan2(b,2.0*a*l/b)*180.0/3.14159265358979<<endl;
  return 0;
}


Measured memory_bytes: 384
#include<stdio.h>
int main(){
  int n,m,i,j,k,check=0;
  scanf("%d%d",&n,&m);
  int a[n+1];
  for(i=0;i<n;i++)
    a[i]=10;
  for(i=0;i<m;i++){
    scanf("%d%d",&j,&k);
    if(a[j-1]==10)
      a[j-1]=k;
    else if(a[j-1]!=k)
      check=-1;
  }
  if(check==-1)
    printf("-1\n");
  else if(n>1 && a[0]==0)
    printf("-1\n");
  else if(n==1 && a[0]%10==0)
    printf("0\n");
  else
    for(i=0;i<n;i++){
      if(a[0]==10)
        a[i]=1;
      else if(a[i]==10)
        a[i]=0;
      printf("%d",a[i]);
    }
  return 0;
}
    
    

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

int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
   
	int a,b,c;
	cin>>a>>b>>c;
	if(a+b+c>=22)
	cout<<"bust";
	else
	cout<<"win";   
}

Measured memory_bytes: 256
#define _CRT_SECURE_NO_WARNINGS
#include<stdio.h>
#include<vector>
#include<functional>
#include<algorithm>
#include<stdlib.h>
#include<string>
#include<string.h>
#define _USE_MATH_DEFINES
#include<math.h>
#include<deque>
#include<set>
#include<map>
#include<queue>
#include<list>
#include<iostream>
using namespace std;
typedef long long ll;
#define rep(i,a,b) for(auto i=a;i<b;i++)
#define all(_x) _x.begin(), _x.end()
#define r_sort(_x) sort(_x.begin(), _x.end(), std::greater<int>())
#define vec_cnt(_a, _n) (upper_bound(all(_a), _n) - lower_bound(all(_a), _n))
ll gcd(ll a, ll b) { return a % b == 0 ? b : gcd(b, a % b); }
ll lcm(ll a, ll b) { return (a / gcd(a, b)) * b; }
#define INF 1 << 30
const ll mod = 1000000007;
int main() {
	int n, v;
	list<int> a;
	deque<int> ans;
	scanf("%d", &n);
	rep(i, 0, n)scanf("%d", &v), a.push_back(v);
	while (a.size()) {
		int dn = -1;
		auto d = a.end();
		rep(i, 0, a.size()) {
			d--;
			if (*d == a.size() - i) {
				dn = a.size() - i;
				break;
			}
		}
		if (dn == -1) {
			puts("-1");
			return 0;
		}
		a.erase(d);
		ans.push_front(dn);
	}
	for (auto v : ans) {
		printf("%d\n", v);
	}
	return 0;
}


Measured memory_bytes: 256
package main

import (
	"bufio"
	"fmt"
	"os"
	"sort"
	"strconv"
)

func out(x ...interface{}) {
	fmt.Println(x...)
}

var sc = bufio.NewScanner(os.Stdin)

func getInt() int {
	sc.Scan()
	i, e := strconv.Atoi(sc.Text())
	if e != nil {
		panic(e)
	}
	return i
}

func getString() string {
	sc.Scan()
	return sc.Text()
}

// min, max, asub, absなど基本関数
func max(a, b int) int {
	if a > b {
		return a
	}
	return b
}

func min(a, b int) int {
	if a < b {
		return a
	}
	return b
}

func asub(a, b int) int {
	if a > b {
		return a - b
	}
	return b - a
}

func abs(a int) int {
	if a >= 0 {
		return a
	}
	return -a
}

func lowerBound(a []int, x int) int {
	idx := sort.Search(len(a), func(i int) bool {
		return a[i] >= x
	})
	return idx
}

func upperBound(a []int, x int) int {
	idx := sort.Search(len(a), func(i int) bool {
		return a[i] > x
	})
	return idx
}

const inf = 1001001001

func main() {
	sc.Split(bufio.ScanWords)
	N, K := getInt(), getInt()
	h := make([]int, N)
	for i := 0; i < N; i++ {
		h[i] = getInt()
	}
	sort.Ints(h)

	ret := inf

	// out(h)
	for i := 0; i <= N-K; i++ {
		ret = min(ret, h[i+K-1]-h[i])
		// out(i, i+K, h[i], h[i+K-1])
	}

	out(ret)

}


Measured memory_bytes: 3072
#include <bits/stdc++.h>
typedef long long ll;
#define pb push_back

using namespace std;
typedef pair<ll,ll> pll;

ll R,G,B,N;
int main()
{
        cin >> R >> G >> B >> N;
        ll ans = 0;
        for(ll i=0;i*R <= N;i++){
                for(ll j=0;j*G<=N;j++){
                        ll yo = i*R + j*G;
                        yo = N - yo;
                        if(yo%B ==0 && yo >= 0) ans++;
                }
        }
        cout << ans << endl;
        return 0;
}


Measured memory_bytes: 256
/* 
 * Author: aps
 * Time: 29-06-2019 17:35:53
**/
#include<bits/stdc++.h>

#define fi first
#define se second
#define pb push_back
#define all(x) x.begin(), x.end()

using namespace std;

typedef long long int ll;
typedef long double ld;
typedef pair<ll,ll> pll;
typedef vector<ll> vl;
typedef vector<int> vi;
typedef pair<int,int> pii;

const ll inf = 1e18;
const ll mod = 1e9+7;

inline ll add(ll x, ll y) { x += y; if (x >= mod) x -= mod; return x;}
inline ll sub(ll x, ll y) { x -= y; if (x < 0) x += mod; return x;}
inline ll mul(ll x, ll y) { return ((x % mod) * (y % mod)) % mod;}
inline ll power(ll a, ll b) {
    ll x = 1;
    while (b) {
        if (b & 1) x = mul(x, a);
        a = mul(a, a);
        b >>= 1;
    }
    return x;
}
inline ll inv(ll a) { return power(a, mod - 2);}

int main(){
    ios_base::sync_with_stdio(false); cin.tie(0);
    int n; cin >> n;
    vi a(n,0);
    for(int i=0;i<n;i++) cin >> a[i];
    int ans=0;
    for(int i=1;i<n-1;i++){
        int x=0;
        if(a[i] < a[i-1]) x++;
        if(a[i] < a[i+1]) x++;
        if(x == 1) ans++; 
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 256
using System;
using System.Collections.Generic;
using System.Linq;
using System.IO;
using System.Text;
//var input = Console.ReadLine().Split().Select(int.Parse).ToArray();
namespace AtCoderSolve
{
    class Solve
    {
        const int mod = 1000000007;
        static void Main(string[] args)
        {
            var sw = new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false };
            Console.SetOut(sw);

            var p = Console.ReadLine().Split();
            Console.WriteLine($"{p[0][0]}{p[1][0]}{p[2][0]}");

            Console.Out.Flush();
        }
    }
    


    public class Calculation
    {
        
    }

    public class Graph
    {

    }
}
    

Measured memory_bytes: 13140
#include<bits/stdc++.h>
#define range(i,a,b) for(int i = (a); i < (b); i++)
#define rep(i,b) for(int i = 0; i < (b); i++)
#define all(a) (a).begin(), (a).end()
#define show(x)  cerr << #x << " = " << (x) << endl;
using namespace std;

template <typename X, typename T>
auto vectors(X x, T a) {
	return vector<T>(x, a);
}

template <typename X, typename Y, typename Z, typename... Zs>
auto vectors(X x, Y y, Z z, Zs... zs) {
	auto cont = vectors(y, z, zs...);
	return vector<decltype(cont)>(x, cont);
}

template<typename T>
ostream& operator << (ostream& os, vector<T>& v){
	rep(i,v.size()){ os << v[i] << (i == v.size() - 1 ? "" : " "); } return os;
}
template<typename T>
istream& operator >> (istream& is, vector<T>& v){
	for(T& x: v){ is >> x; } return is;
}

int main(){
	int n;
	cin >> n;

	vector<int> a(n);
	cin >> a;

	map<int,int> odd, even;
	rep(i,n){
		if(i % 2){
			odd[a[i]]++;
		}else{
			even[a[i]]++;
		}
	}

	vector<pair<int, int>> x, y;
	for(auto i : odd) x.emplace_back(i.second, i.first);
	for(auto i : even) y.emplace_back(i.second, i.first);

	sort(all(x), greater<pair<int, int>>());
	sort(all(y), greater<pair<int, int>>());

	int cost = n;
	if(x.front().second != y.front().second){
		cost -= x.front().first + y.front().first;
	}else{
		int p = x.front().first + y[1].first;
		int q = x[1].first + y.front().first;
		cost -= max(p, q);
	}
	cout << cost << endl;
}


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

using namespace std;

int main() {
  int n, x, y;
  cin >> n >> x >> y;
  vector<int> ans(n, 0);
  for (int i = 1; i <= n; i++) {
    for (int j = i + 1; j <= n; j++) {
      int a, b, c, dist;
      a = j - i;
      b = abs(x - i) + 1 + abs(j - y);
      c = abs(y - i) + 1 + abs(j - x);
      dist = min({a, b, c});
      ans[dist]++;
    }
  }

  for (int i = 1; i < n; i++) {
    cout << ans[i] << endl;
  }

  return 0;
}

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

long gcd(long u, long v){
	long r;
	while (v != 0){
		r = u % v;
		u = v;
		v = r;
	}
	return u;
}

int main(){
	int n;
	long a, s;
	cin >> n;
	cin >> s;
	for (int i = 0; i < n-1; ++i){
		cin >> a;
		s = gcd(s, a);
	}
	cout << s;

	return 0;
}

Measured memory_bytes: 256
alphabet = 'abcdefghijklmnopqrstuvwxyz'
s = input()
K = int(input())
ans = ''
for i in range(len(s) - 1):
    s_i = alphabet.index(s[i])
    if s[i] == 'a':
        ans += 'a'
        continue
    if (26 - s_i <= K):
        K -= 26 - s_i
        ans += 'a'
    else:
        ans += s[i]
ans += alphabet[(K + alphabet.index(s[-1])) % 26]
print(ans)


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

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

using namespace std;

#define debug(x) cout<<(#x)<<"="<<(x)<<", ";
#define debug1(x) debug(x) cout<<'\n';
#define debug2(x1, x2) debug(x1) debug(x2) cout<<'\n';
#define debug3(x1, x2, x3) debug(x1) debug(x2) debug(x3) cout<<'\n';
#define debug4(x1, x2, x3, x4) debug(x1) debug(x2) debug(x3) debug(x4) cout<<'\n';
#define debug5(x1, x2, x3, x4, x5) debug(x1) debug(x2) debug(x3) debug(x4) debug(x5) cout<<'\n';

#define fcout cout<<fixed<<setprecision(15)
#define repp(i,j,k) for(int i=j; i<k; ++i)
#define rep(i,j) repp(i,0,j)
#define rrep(i,j,k) for(int i=j; i>=k; --i)
#define all(x) (x).begin(), (x).end()
#define sort(x) sort(x.begin(), x.end())
#define lb(x,val) lower_bound(x.begin(), x.end(), val)
#define ub(x,val) upper_bound(x.begin(), x.end(), val)
#define pb(x) emplace_back(x);

typedef long long int lli;
typedef pair<int,int> pii;
typedef pair<lli,lli> pll;
typedef vector<int> vi;
typedef vector<lli> vl;
typedef tuple<int, int, lli> tiil;

//const lli M=998244353ll;
const lli M=1000000007ll;
const double D=1.0;

int main(){
fast_io
string s; cin>>s;
s[3]='8';
cout<<s;
return 0;
}

Measured memory_bytes: 256
import Data.List
f ::[Int] -> Int
f [] = 0
f [_] = 0
f (x:xs) = if (x /= head(xs)) then (0 + (f xs)) else (1 + (f xs))
main = do 
 getLine
 u <- map read . words <$> getLine
 let u' = sort u
 if f u' == 0 then putStrLn "YES" else putStrLn "NO" 
 

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

int main()
{
	int n,counts=0;
	cin>>n;
	for (int i=1;i<=n;i++)
	{
		int x,y; 
		scanf ("%d%d",&x,&y);
		if (x==y) counts++;
		else counts=0;
		if (counts==3) break;
	}
	if (counts==3) cout<<"Yes"<<endl;
	else cout<<"No\n"<<endl;
	return 0;
}

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

#define fastio ios_base::sync_with_stdio(false);cin.tie(NULL);
#define ll long long

int main() {
    fastio;
    string a, b;
    cin >> a >> b;
    int aa = a.size(), bb = b.size(), f = 1;
    if (aa < bb) cout << "LESS";
    else if (aa > bb) cout << "GREATER";
    else {
        for (int i = 0; i < aa; ++i) {
            if (a[i] < b[i]) {
                f = 0;cout << "LESS";break;
            }
            else if (a[i] > b[i]) {
                f = 0;cout << "GREATER";break;
            }
        }
        if (f) cout << "EQUAL";
    }
    
    return 0;
}

Measured memory_bytes: 256
n,k = map(int,input().split())
r,s,p = map(int,input().split())
t = input()
li = [[""]*((n+k)//k) for i in range(k)]
for i in range(n):
    li[i%k][i//k] = t[i]
ans = 0
for i in li:
    P,R,S = 0,0,0
    hand_o = ""
    for j in i:
        if j == "r" and hand_o != "r":
            P += p
        elif j == "s" and hand_o != "s":
            R += r
        elif j == "p" and hand_o != "p":
            S += s
        else:
            hand_o = ""
            continue
        hand_o = j
    ans += (P+R+S)
print(ans)

Measured memory_bytes: 16608
# グラフわからんのでグラフアルゴリズム忘れた
# dfsでやる 限度2回c
# なんかしらんけどdfsが2TLEになるので諦めた それぞれの島について1とNがあれば良い

n, m = map(int, input().split())
graph = [[] for _ in range(n)]
for _ in range(m):
    a, b = map(int, input().split())
    graph[a - 1].append(b - 1)
    graph[b - 1].append(a - 1)

for g in graph[1 : n - 1]:
    c = 0
    for v in g:
        if c >= 2:
            break
        if v == 0 or v == n - 1:
            c += 1
    if c == 2:
        print("POSSIBLE")
        exit()
print("IMPOSSIBLE")


Measured memory_bytes: 82636
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define PI 3.14159265358979
#define EPS 1e-8
#define mod 1000000007
#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define endl "\n"
	 
const ll INF=(ll)2e18;
		
		
		
int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
				
	string s;
	cin>>s;
	vector<pair<ll,ll> > v;
	
	for(int i=0;i<s.length();i++)
	{
		int j=i;
		while(s[j]=='1')
		{
			j++;
		}
		if(j!=i)
		{
			v.pb({i,j-1});
			i=j-1;
		}
		
	}
	ll ans=s.length();
	ll n=s.length();
	for(ll i=0;i<v.size();i++)
	{
		ll ans1=max(n-1-v[i].se,v[i].fi);
		
		ans1=max(ans1,min(v[i].se,n-1-v[i].fi)+1);
		
		ans=min(ans,ans1);
	}
	cout<<ans;
}


Measured memory_bytes: 972
#pragma comment(linker, "/STACK:1024000000,1024000000")
//#include<bits/stdc++.h>
#include <algorithm>  
#include <iostream>  
#include <cstdlib>  
#include <cstring>  
#include <string>
#include <cstdio>  
#include <climits>
#include <cmath> 
#include <vector>
#include <set>
#include <queue>
#include <stack>
#include <map>
#include <sstream>
#define inf 0x3f3f3f3f
#define ll long long
#define fora(i,a,n) for(int i=a;i<=n;i++)
#define fors(i,n,a) for(int i=n;i>=a;i--)
#define sci(x) scanf("%d",&x)
#define scl(x) scanf("%lld",&x)
#define sci2(x,y) scanf("%d%d",&x,&y)
#define scl2(x,y) scanf("%lld%lld",&x,&y)
const int maxn = 100024;
const int mod = 1e9 + 7;
const double eps = 1e-8;
using namespace std;
typedef pair<int, int> pr;
int n, k;
int x[maxn];
int main() {
#ifdef local
	freopen("in.txt", "r", stdin);
	//freopen("out.txt","w",stdout);
#endif
	sci2(n, k);
	fora(i, 1, n ) {
		sci(x[i]);
	}
	int ans = mod;
	int sum,mmin;
	for (int i = k; i <= n; i++) {
		sum = x[i] - x[i - k + 1];
		if (0 >= x[i - k + 1] && 0 <= x[i]) {
			mmin = min(abs(0 - x[i - k + 1]), abs(x[i] - 0));
			mmin = mmin + sum;
		}
		else if (0 < x[i - k + 1]) {
			mmin = x[i];
		}
		else {
			mmin = -x[i - k + 1];
		}
		ans = min(ans, mmin);
	}
	printf("%d\n", ans);
	return 0;
}

Measured memory_bytes: 640
#include<cstdio>
#include<cstdlib>
#include<string>
#include<iostream>
using namespace std;
struct Node{
    int key;
    Node *parent,*left,*right;
};
Node *root,*NIL;
void insert(int k){
    Node *y=NIL;
    Node *x=root;
    Node *z;

    z=(Node *)malloc(sizeof(Node));
    z->key=k;
    z->left=NIL;
    z->right=NIL;

    while(x!=NIL){
        y=x;
        if(z->key<x->key) x=x->left;
        else x=x->right;
    }
    z->parent=y;
    if(y==NIL) root=z;
    else{
        if(z->key<y->key) y->left=z;
        else y->right=z;
    }
}
void find(int k){
    Node *x=root;
    Node *y=NIL;
    while(x!=NIL){
        y=x;
        if(x->key>k) x=x->left;
        else if(x->key<k) x=x->right;
        else{cout<<"yes"<<endl; return;}
    }
    cout<<"no"<<endl;
}
void inorder(Node *u){
    if(u==NIL) return;
    inorder(u->left);
    printf(" %d",u->key);
    inorder(u->right);
}
void preorder(Node *u){
    if(u==NIL) return;
    printf(" %d",u->key);
    preorder(u->left);
    preorder(u->right);
}
int main(){
    int n,x;
    string com;
    scanf("%d",&n);
    for(int i=0;i<n;i++){
        cin>>com;
        if(com=="insert"){
            scanf("%d",&x);
            insert(x);
        }
        else if(com=="print"){
            inorder(root);
            cout<<endl;
            preorder(root);
            cout<<endl;
        }
        else if(com=="find"){
            scanf("%d",&x);
            find(x);
        }
    }
    return 0;
}


Measured memory_bytes: 22048
#include <bits/stdc++.h>
using namespace std;
#define int long long
typedef pair<int,int> P;
int INF = 1e16+7;
int mod = 1e9+7;
int dx[4] = {1,-1, 0, 0};
int dy[4] = {0, 0, 1,-1};
signed main() {
    int N;
    cin >> N;
    vector<int>A(N);
    int now = 1000,sum = 0,mx = 0;
    for(int i = 0; i < N; i++) {
        cin >> A[i];
        if(i == 0) {
            sum = A[i];
        }
        else {
            if(A[i] <= A[i-1]) {
                if(mx != 0 && sum != 0) {
                    now = now+now/sum*(mx-sum);
                    mx = 0;
                }
                sum = A[i];
            }
            else {
                mx = A[i];
            }
        }
    }
    if(mx != 0 && sum != 0) {
        now = now+now/sum*(mx-sum);
        mx = 0;
    }
    cout << now << endl;
}


Measured memory_bytes: 3632
# -*- coding: utf-8 -*-
import numpy as np

def solve():
    N = int(input())
    A, B = np.vstack([np.array(list(map(int, input().split()))) for _ in range(N)]).T
    C = A+B
    C.sort()
    res = (C[-1::-2]).sum() - B.sum()
    return str(res)
if __name__ == '__main__':
    print(solve())

Measured memory_bytes: 48448
#include <bits/stdc++.h>
using namespace std;
int main()
{
  int n, m;
  cin>>n>>m;
  if(n>=m)
    cout<<0;
  else {
    int a[m];
    for(int i=0;i<m;i++)
      cin>>a[i];
    sort(a,a+m);
    int d[m-1];
    for(int i=0;i<m-1;i++)
      d[i] = a[i+1] - a[i];
    sort(d,d+m-1);
    int t=0;
    for(int i=0;i<m-n;i++)
      t+=d[i];
    cout<<t;
  }
  return 0;
}


Measured memory_bytes: 1024
#include <iostream>
using namespace std;
#define max 1000000
 
int main()
{
    int prime[max];
    
    fill(prime, prime + max, 1);
    prime[0] = 0;
    prime[1] = 0;
    for (int i = 2; i < max; i++) {
        if (prime[i]) {
            for (int j = 2*i; j < max; j += i) {
                prime[j] = 0;
            }
        }
    }
    
    for(int i = 1;i < max; i++){
	    prime[i] = prime[i] + prime[i-1];
    }
    
    int aaa;
    while (cin >> aaa) {
	cout << prime[aaa] << endl;
    }
    return 0;
}

Measured memory_bytes: 6980
from statistics import mean, median,variance,stdev
import numpy as np
import sys
import math
import fractions
import itertools
import copy
#以下てんぷら
def j(q):
    if q==1: print("YES")
    else:print("NO")
    exit(0)


def ct(x,y):
    if (x>y):print("GREATER")
    elif (x<y): print("LESS")
    else: print("EQUAL")

def ip():
    return int(input())
#n = ip()                                     #入力整数1つ
n,m,d= (int(i) for i in input().split())       #入力整数横2つ以上
b = [int(i) for i in input().split()]        #入力整数配列
#a = input()                                  #入力文字列
#a = input().split()                          #入力文字配列
#n = ip()                      #入力セット(整数改行あり)(1/2)
#a=[ip() for i in range(n)]    #入力セット(整数改行あり)(2/2)

#jの変数はしようできないので注意
#全足しにsum変数使用はsum関数使用できないので注意
#こっから本文
s = 0
for i in range(n):
    a = [int(i) for i in input().split()]
    c = 0
    for k in range(m):
        c+=(a[k]*b[k])
    if c+d>0:s+=1
print(s)



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

int main() {
    ll h, w;  // h行w列のマス目
    cin >> h >> w;

    vl y(h*w), x(h*w);  // うなぎのi番目の座標が(y[i], x[i])
    rep(i, h) {
        rep(j, w) {
            y[i*w + j] = i;
        }
    }

    rep(i, h*w) {
        ll m = i%(2*w);
        if(m < w) {
            x[i] = m;
        }
        else {
            x[i] = (2*w - 1) - m;
        }
    }   

    ll n;
    cin >> n;

    ll k = 0;
    vvl matrix(h, vl(w));
    rep(i, n) {
        ll a;
        cin >> a;
        exrep(j, k, k+a-1) {
            matrix[y[j]][x[j]] = i+1;
        }
        k += a;
    }

    rep(i, h) {
        rep(j, w) {
            cout << matrix[i][j] << " ";
        }
        cout << "\n";
    }

    re0;
}

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

#define ll long long
#define endl "\n"

int main ()
{

	ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    #define int ll
    //freopen("input.txt", "r", stdin); 
    //freopen("output.txt", "w", stdout);
    
    int n;
    cin >> n;

    int cont[10][10];
    memset(cont, 0, sizeof(cont));

    int ans = 0;
    for (int i=1; i<=n; i++){
        string now = to_string(i);
        int first = now[0] - '0';
        int second = i%10;
        cont[first][second]++;
    }

    for (int i=1; i<=9; i++){
        for (int j=1; j<=9; j++){
            ans += cont[i][j]*cont[j][i];
        }
    }

    cout << ans << endl;

    return 0;

}


Measured memory_bytes: 3764
#include <stdio.h>    
#include <string.h>    
#include <set>  
#include <map>  
#include <algorithm>  
#include <iostream>  
#include <vector>  
#include <string>  
#include <cmath>  
template <class T>
inline bool rd(T &ret) {
	char c; int sgn;
	if (c = getchar(), c == EOF) return 0;
	while (c != '-' && (c<'0' || c>'9')) c = getchar();
	sgn = (c == '-') ? -1 : 1;
	ret = (c == '-') ? 0 : (c - '0');
	while (c = getchar(), c >= '0'&&c <= '9') ret = ret * 10 + (c - '0');
	ret *= sgn;
	return 1;
}
template <class T>
inline void pt(T x) {
	if (x <0) {
		putchar('-');
		x = -x;
	}
	if (x>9) pt(x / 10);
	putchar(x % 10 + '0');
}
using namespace std;
const int N = 3000 + 105;

int n, m;
vector<string> myset[105];
set<string>ans;
map<string, int> mp;
string s;
bool vis[105];
void dfs(int x){
	vis[x] = 1;
	for (int i = 0; i < myset[x].size(); i++)
	{
		if (mp.count(myset[x][i]))
		{
			if (!vis[mp[myset[x][i]]])
			dfs(mp[myset[x][i]]);
		}
		else ans.insert(myset[x][i]);
	}
}
string str;
int main(){
	while (cin>>n, n){
		memset(vis, 0, sizeof vis);
		mp.clear();
		for (int j = 1; j <= n; j++){
			cin >> str; str[str.length() - 1] = ',';
			int pos = str.find(':');
			string temp = str.substr(0, pos);
			mp[temp] = j;
			while (1)
			{
				str = str.substr(pos + 1);
				pos = str.find(',');
				if (pos == -1)	break;
				temp = str.substr(0, pos);
				myset[j].push_back(temp);
			}
			sort(myset[j].begin(), myset[j].end());
			myset[j].erase(unique(myset[j].begin(), myset[j].end()), myset[j].end());
		}
		ans.clear();
		dfs(1);
		pt((int)ans.size()); puts("");
		for (int j = 1; j <= n; j++)myset[j].clear();
	}
	return 0;
}

Measured memory_bytes: 1344
#include <iostream>
#include <sstream>
using namespace std;
#include <bits/stdc++.h>
#include<utility>
#include <algorithm>
#include<iterator>
#define  go return 0
#define pb push_back
#define lp(j, n)  for(int j=0; j<(int)(n); ++j)
#define rep(i,n) for(int i=0;i<n;++i)
#define all(v)   ((v).begin()), ((v).end())
#define sz(v)    ( (int)((v).size()) )
#define F first
#define S second
typedef long long ll;
typedef double db;
typedef vector<int> vi;
typedef pair<int, int> pi;
typedef vector<pair<int,int> > vpii;
typedef map<int, int> mii;
const ll N=1e5+5;
ll arr[N],A[N]  ;
bool visited[N]={};
int main()
{

  vi v1(5);
  vi v2(5);
  int sum=0;
  rep(i,5)
  {
      cin>>v1[i];
      sum+=v1[i];
      v2[i]=10-v1[i]%10;
      if(v2[i]==10)
        v2[i]=0;
  }
  sort(all(v2));
  rep(i,4)
  {
      sum+=v2[i];
  }
  cout<<sum;
 go;
}


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

int main(){
  int a,b,k,nm=0;
  cin>>a>>b>>k;
  int i=min(a,b);
  while(k!=nm){
    if(a%i==0&&b%i==0){
      nm++;
    }
    i--;
  }
  cout<<i+1<<endl;
}
    
 


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

char mp[55][55];
int h, w;
int d[4] = {1, 0, -1, 0};
bool ans = 1;

void prians(bool answer) {
  if(answer)
    cout << "Yes" << endl;
  else
    cout << "No" << endl;
}

bool solve(int x, int y);

int main() {
  int i, j;
  cin >> h >> w;
  for(i = 0; i < h; ++i)
    for(j = 0; j < w; ++j) cin >> mp[i][j];
  for(i = 0; i < h; ++i)
    for(j = 0; j < w; ++j) {
      if(mp[i][j] == '#' && solve(i, j)) ans = 0;
      if(!ans) break;
    }

  prians(ans);
  return 0;
}

bool solve(int x, int y) {
  pair<int, int> now, nextn;
  bool rans = 1;
  stack<pair<int, int>> st;
  st.push(make_pair(x, y));
  while(!st.empty()) {
    now = st.top();
    st.pop();
    mp[now.first][now.second] = '.';
    for(int i = 0; i < 4; ++i) {
      nextn = now;
      nextn.first += d[i];
      nextn.second += d[1 ^ i];
      if(nextn.first >= 0 && nextn.first < h &&
         nextn.second >= 0 && nextn.second < w &&
         mp[nextn.first][nextn.second] == '#') {
        rans = 0;
        st.push(nextn);
      }
    }
  }
  return rans;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include<algorithm>
#include<string>
#include<stdio.h>
#include<map>
#include<math.h>
#include<queue>
using namespace std;
using ll = long long;
using ld = long double;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
const int MOD = 1000000007;
const int mod = 1000000007;
const int INF = 1000000000;
const long long LINF = 1e18;
const int MAX = 510000;
int main() {
	int a, b, cnt = 0;
	cin >> a >> b;
	for (int i = a; i <= b; i++) {
		if (i % 10 == i / 10000 && (i / 10) % 10 == (i / 1000)%10)cnt++;
	}
	cout << cnt << endl;
	return 0;

}

Measured memory_bytes: 3632
#include <iostream>
#include <stdio.h>
#include <algorithm>
#include <vector>
#include <utility>
#include <cstdio>
#include <cmath>
#include <string>
#include <string.h>
#include <stack>
#include <queue>
#include <map>
#include <stdlib.h>
#include <set>
typedef long long ll;
using namespace std;

int main() {
	ll n,sum=0,w2;
	cin>>n;
	string s,w1;
	s=to_string(n);
	for(int i=0;i<s.length();i++){
		w1=s.substr(i,1);
		w2=stoi(w1);
		sum+=w2;
	}
	if(n%sum==0){
		cout<<"Yes"<<endl;
	}else{
		cout<<"No"<<endl;
	}
	return 0;
}



Measured memory_bytes: 256
#include <cstdio>
#include <cstring>
#include <vector>
#include <tuple>

using namespace std;

int count[6];

int main() {
	for(int i=0; i<6; ++i) {
		int a;
		scanf("%d", &a);
		++count[a];
	}
	for(int a=0; a<6; ++a) {
		if(3<=count[a]) {
			printf("NO\n");
			return 0;
		}
	}
	printf("YES\n");
	return 0;
}


Measured memory_bytes: 128