akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <vector>
#include <algorithm>

using namespace std;

int N, P[10], Q[10];

vector<int> A, B,V;

int main(void) {

	cin >> N;

	for (int i = 1; i <= N; i++) { cin >> P[i]; A.push_back(P[i]); }
	for (int i = 1; i <= N; i++) { cin >> Q[i]; B.push_back(Q[i]); }

	for (int i = 1; i <= N; i++) { V.push_back(i); }

	int cnt = 0;

	int a, b;
	do {
		cnt++;
		if (V == A) { a = cnt; }
		if (V == B) { b = cnt; }
	//	for (auto y : V) { cout << " " << y; }cout << endl;
	} while (next_permutation(V.begin(), V.end()));


	cout << abs(a - b) << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define ll long long 
#define ld long double
#define pb push_back
#define vl vector
#define ff first
#define ss second
using namespace std;
int main()
{
    ld a,b,x,y,area;
    cin>>a>>b>>x>>y;
    area=(a*b)/2;
    ll flag=0;
    if(a/2==x && b/2==y) flag=1;
    cout<<fixed<<setprecision(8)<<area<<" ";
    if(flag==1) cout<<1;
    else cout<<0;
}

Measured memory_bytes: 3760
package main

import "fmt"

func main() {
	// Code for B - Comparison
	var A, B float64
	fmt.Scanf("%f\n%f", &A, &B)

	if A > B {
		fmt.Println("GREATER")
	} else if A == B {
		fmt.Println("EQUAL")
	} else {
		fmt.Println("LESS")
	}
}


Measured memory_bytes: 1832
#include<cstdio>
int n,m,l,k;void solve(int p,int d){if(p==m){printf("%d\n",p);return;}printf("%d ",p);if(p==9)solve(5,0);else if(!p||d)solve(p+1,1);else solve(p-1,0);}main(){scanf("%d",&l);while(l--){scanf("%d%d",&n,&m);if(n==9||(n<6&&n>m))k=0;else k=1;solve(n,k);}}

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

#define ll long long
#define inf 1e9+1

struct item{
    int wt;
    int val;
};

int knapsack(const vector<item> &arr,int n,int W) {
    int maxVal = n*1000;
    int dp[n+1][maxVal+1];

    for(int val=0; val <= maxVal ; val++) {
        dp[1][val] = inf;
    }

    dp[1][0] = 0;
    dp[1][arr[1].val] = arr[1].wt;

    for(int i=2;i<=n;i++) {
        for(int v=0; v <=maxVal ; v++ ) {
            dp[i][v] = dp[i-1][v];
            if(arr[i].val > v)
                continue;
            dp[i][v] =min(dp[i][v], arr[i].wt + dp[i-1][v-arr[i].val]);
        }
    }

    int ans = 0;

    for(int x=0;x<=maxVal;x++) {
        if(dp[n][x] <= W) {
            ans = x;
        }
    }

    return ans;
}

int main() {
    int n,W;
    cin >> n >> W;
    vector<item> v(n+1);

    for(int i=1;i<=n;i++) {
        cin >> v[i].wt >> v[i].val; 
    }

    cout << knapsack(v,n,W);

    return 0;
}


Measured memory_bytes: 39296
#include <cmath>
#include <cstdio>
#include <vector>
#include <iostream>
#include <algorithm>
#include <iomanip>
#include <unordered_map>
#include <unordered_set>
#include <map>
#include <set>
#include <vector>
#include <iostream>
#include <vector>
#include <numeric>

#define rep(i, n) for(int i = 0; i < (n); ++i)
typedef long long ll;
typedef long double ld;

using namespace std;



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

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

    sort(A.begin(), A.end());

    ll ans = 0;
    ll hoge = A[0];
    
    for (int i = 1; i < N; ++i) {
        if (A[i] > 2 * hoge) {
            ans = i;
        }
        hoge += A[i];
    }
    cout << N - ans;
}

Measured memory_bytes: 1024
length = int(input())
num_li = list(map(int, input().split()))
count = 0
loop = True
while True:
    for i in range(length):
        if num_li[i]%2 == 1:
            loop = False
            break
        else:
            num_li[i] /= 2
    if loop == False:
        break
    else:
        count += 1
print(count)

Measured memory_bytes: 3060
#include<bits/stdc++.h>
using namespace std;
#define N 100005
#define pii pair<int,int>
#define mp make_pair
#define F first
#define S second
#define pb push_back
#define LL long long

int n,m;
int a[N];
pii p[N];
vector<int> al;
LL sum;

int main()
{
	
	cin>>n>>m;
	for(int i=0;i<n;i++)
		cin>>a[i];
	for(int i=0;i<m;i++)
		cin>>p[i].S>>p[i].F;
	sort(p,p+m);
	reverse(p,p+m);
	
	for(int i=0;i<m;i++)
	{
		if(al.size()>n) break;
		for(int j=0;j<p[i].S;j++)
			al.pb(p[i].F);
	}
	for(int i=0;i<n;i++)
		al.pb(a[i]);
	sort(al.begin(),al.end());
	reverse(al.begin(),al.end());
	for(int i=0;i<n;i++)
		sum+=al[i];
	cout<<sum<<'\n';
	
	return 0;
}

Measured memory_bytes: 3572
#include <iostream>
#include <string>
#include <algorithm>
#include <functional>
#include <vector>
#include <stack>
#include <queue>
#include <deque>
#include <set>
#include <map>
#include <cstdio>
#include <cmath>
#include <tuple>
#include <iomanip>
#include <numeric>
#include <unordered_map>
#include <sstream>   
#include<limits.h>
#include<float.h>
#include<list>
#include <array>
#include <complex>
#include<stdio.h>
#include<string.h>

using namespace std;
#define int  long long
 
#define I32_MAX 2147483647
#define I64_MAX 9223372036854775807LL
#define I64_MAX2 1223372036854775807LL
#define INF I64_MAX2
#define MOD 1000000007
#define MEM_SIZE 10000
#define DEBUG_OUT true
#define ALL(x) (x).begin(),(x).end()
// int DP[MEM_SIZE][MEM_SIZE] = {0};
// int GMEM[MEM_SIZE][MEM_SIZE] = {0};
template<typename T> void DEBUG(T e){if(DEBUG_OUT == false)return;std::cout << e << std::endl;}
template<typename T> void DEBUG(const std::vector<T>& v){if(DEBUG_OUT == false)return;for(const auto& e : v){ std::cout << e << " "; } std::cout << std::endl;}
template<typename T> void DEBUG(const std::vector<std::vector<T> >& vv){if(DEBUG_OUT == false)return;for(const auto& v : vv){ DEBUG(v); } }
template<class T,class X> void DEBUG(X d, T e){if(DEBUG_OUT == false)return;std::cout <<d<<" ";DEBUG(e);};
template <class T> void corner(bool flg, T hoge) {if (flg) {cout << hoge << endl; exit(0);}}
template< typename T1, typename T2 > inline bool chmax(T1 &a, T2 b) { return a < b && (a = b, true); }
template< typename T1, typename T2 > inline bool chmin(T1 &a, T2 b) { return a > b && (a = b, true); }

  // vector<vector<vector<int> > > DP =  vector<vector<vector<int> > >(100001,vector<vector<int> >(2,vector<int>(2,0)));
void solve(void)
{
  string str;
  cin>>str;
  int K ;
  cin>>K;
  vector<vector<vector<int> > > DP (101,vector<vector<int> >(2,vector<int>(K+2,0)));
  vector<int> v(str.size());

  for (int i = 0; i < str.size(); i++)
  {
    v[i] = str[i] - '0';
  }
  DP[0][0][0] = 1;
  for (int i = 0; i < v.size(); i++)
  {
    for (int j = 0; j < 2; j++)
    {
      for (int k = 0; k <= K; k++)
      {
        for (int p = 0; p <= (j?9:v[i]); p++)
        {
          if(p == 0)
          DP[i+1][j||(p<v[i])][k] += DP[i][j][k];
          else
          DP[i+1][j||(p<v[i])][k+1] += DP[i][j][k];
        }
        
      }
      
    }
    
  }
  
  cout<<DP[v.size()][0][K]+DP[v.size()][1][K]<<endl;
  // for (int i = 0; i <= v.size(); i++)
  // {
  //   DEBUG("DP num",i);
  //   DEBUG(DP[i]);
  // }
  
  return;
}

int32_t main(int32_t argc, const char *argv[])
{
  std::ios::sync_with_stdio(false);
  std::cin.tie(0);

  std::cout << std::fixed;
  std::cout << std::setprecision(9);
  solve();

  return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<cstring>
#include<map>
#include<algorithm>
#define lk (k<<1)
#define rk (k<<1|1)
using namespace std;
typedef long long ll;
const int inf=0x3f3f3f3f;
const int N=1e5+10;
int main()
{
    int n;
    cin>>n;
    if(n>=30) cout<<"Yes"<<endl;
    else cout<<"No"<<endl;
    return 0;
}

Measured memory_bytes: 3640
// ABC159 C

#include <iostream>

using namespace std;

int main(){
    double a, b;
    cin >> a >> b;
    for(int i=1; i<1010; i++){
        if(a*100/8 <= i && i < (a+1)*100/8 && b*10 <= i && i < (b+1)*10){
            cout << i << endl;
            return 0;
        }
    }
    cout << "-1" << endl;
    return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
int sum[200005];
int main()
{
	int n=0,i,j,k,s,t;
	sum[0]=0;
	for(i=1;sum[i-1]<=1e9;i++)
	sum[++n]=sum[i-1]+i;
	int x;
	while(~scanf("%d",&x))
	 {
	 	int l=1,r=n,mid;
	 	while(l<r)
	 	{
	 		mid=(l+r)/2;
	 		if(sum[mid]>=x) r=mid;
			else l=mid+1;
		}
		printf("%d\n",l);
	 }
	 return 0;
}

Measured memory_bytes: 384
#include<iostream>
using namespace std;
int ax[10005];
int ay[10005];
int main(){
	//???????????????????????°??????(1,1)
	int w,h,n; //w,h?????????????????????????????????
	int i=0;
	int x=1;
	int y=1;
	int a,b,c; //?§?????????¢???x,y?????????????§???????
	int an=0; //???????¨?
	
	cin>>w>>h>>n;
	for(i=0;i<n;i++){
		cin>>ax[i]>>ay[i];
	}
	x=ax[0];
	y=ay[0];
	for(i=1;i<n;i++){
		a=ax[i]-x;
		b=ay[i]-y;
		if(a*b>0){
			if(a<0){
				a=-a;
				b=-b;
			}
			if(a<b){
				c=a;
				b-=a;
				a=0;
			}else{
				c=b;
				a-=b;
				b=0;
			}
			an+=a+b+c;
			
		}else{
			if(a<0){
				a=-a;
			}
			if(b<0){
				b=-b;
			}
			an+=a+b;
		}
		x=ax[i];
		y=ay[i];
	}
	cout<<an<<endl;
}

Measured memory_bytes: 3068
N, M = map(int, input().split())

A_list = list(map(int, input().split()))

All_dict = {}

for Ai in A_list:
    if Ai not in All_dict.keys():
        All_dict[Ai] = 0
    All_dict[Ai] += 1
    
for _ in range(M):
    Bi, Ci = map(int, input().split())
    if Ci not in All_dict.keys():
        All_dict[Ci] = 0
    All_dict[Ci] += Bi
counter = 0
res = 0
all_card_val = list(All_dict.keys())
all_card_val.sort(reverse=True)
for card_val in all_card_val:
    possesion = All_dict[card_val]
    if counter + possesion <= N:
       res += card_val * possesion
       counter += possesion
    else:
        res += card_val * (N - counter)
        break

print (res)

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

int main() {
	long long int n,m,a,s=0;
	cin>>n>>m;
	while(m--){
	    cin>>a;
	    s+=a;
	}
	if(s<n)
	cout<<"No";
	else
	cout<<"Yes";
	return 0;
}

Measured memory_bytes: 256
#include <algorithm>  //min, max, sort, unique, fill
#include <iostream>
#include <numeric>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <utility>  //pair, swap,
#include <vector>
using namespace std;
using ll = long long;
#define FOR(i, a, b) for (ll i = (a); i <= (b); i++)
#define REP(i, n) for (ll i = 0; i < (n); i++)

int main() {
  int a;
  cin >> a;
  cout << (a == 7 || a == 5 || a == 3 ? "YES" : "NO") << endl;
  return 0;
}


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

const int MOD = 1e9 + 7;
int n, m, s, t;
std::vector<std::vector<std::pair<int, int>>> g;
std::vector<long long> dist;
std::vector<long long> a, b, c, dp1, dp2;

void solve(){
	std::priority_queue<std::pair<long long, int>, std::vector<std::pair<long long, int>>, std::greater<std::pair<long long, int>>> qu;
	dist[s] = 0; qu.push({0, s});
	
	while(!qu.empty()){
		auto p = qu.top(); qu.pop();
		
		for(auto e : g[p.second]){
			if(p.first + e.second >= dist[e.first]) continue;
			dist[e.first] = p.first + e.second;
			qu.push({dist[e.first], e.first});
		}
	}
	
	std::vector<std::pair<long long, int>> vec; dp1[s] = 1; dp2[t] = 1;
	for(int i = 0; i < n; i++) vec.push_back({dist[i], i});
	sort(begin(vec), end(vec));
	
	for(int i = 0; i < n; i++){
		for(auto e : g[vec[i].second]){
			if(vec[i].first + e.second == dist[e.first]){
				(dp1[e.first] += dp1[vec[i].second]) %= MOD;
			}
		}
	}
	
	for(int i = n - 1; i >= 0; i--){
		for(auto e : g[vec[i].second]){
			if(dist[e.first] + e.second == vec[i].first){
				(dp2[e.first] += dp2[vec[i].second]) %= MOD;
			}
		}
	}
}

int main(){
	std::cin >> n >> m >> s >> t; g.resize(n); s--; t--;
	a.resize(m); b.resize(m); c.resize(m);
	for(int i = 0; i < m; i++){
		std::cin >> a[i] >> b[i] >> c[i]; a[i]--; b[i]--;
		
		g[a[i]].push_back({b[i], c[i]});
		g[b[i]].push_back({a[i], c[i]});
	}
	
	dist.resize(n, 1e18); dp1.resize(n, 0); dp2.resize(n, 0); solve();
	
	long long ans = dp1[t] * dp1[t] % MOD;
	for(int i = 0; i < n; i++){
		if(dist[i] * 2 != dist[t]) continue;
		ans = (ans - dp1[i] * dp1[i] % MOD * dp2[i] % MOD * dp2[i] % MOD + MOD) % MOD;
	}
	
	for(int i = 0; i < m; i++){
		if(dist[a[i]] + c[i] == dist[b[i]] and dist[a[i]] * 2 < dist[t] and dist[t] < dist[b[i]] * 2){
			ans = (ans - dp1[a[i]] * dp1[a[i]] % MOD * dp2[b[i]] % MOD * dp2[b[i]] % MOD + MOD) % MOD;
		}else if(dist[b[i]] + c[i] == dist[a[i]] and dist[b[i]] * 2 < dist[t] and dist[t] < dist[a[i]] * 2){
			ans = (ans - dp1[b[i]] * dp1[b[i]] % MOD * dp2[a[i]] % MOD * dp2[a[i]] % MOD + MOD) % MOD;
		}
	}
	
	std::cout << ans << std::endl;
	return 0;
}


Measured memory_bytes: 20080
#include <cstdio>
#include <algorithm>
#include <vector>
#include <map>

using namespace std;

using i64=long long;

template <typename T>
struct BinaryIndexedTree {
    size_t n;
    vector<T> tree;
    BinaryIndexedTree(size_t n, T e=0): n(n) {
        tree = vector<T>(n+1, e);
    }
    void add(size_t i, T w) {
        // v[i] += w;
        // i in [1, n]
        for (size_t j=i; j<=n; j+=j&-j)
            tree[j] += w;
    }
    T sum(T m) {
        // returns sum of v[i] for i in [1, m]
        T sum_=0;
        for (size_t i=m; i>0; i-=i&-i)
            sum_ += tree[i];

        return sum_;
    }
};

int main() {
    size_t n;
    scanf("%zu", &n);

    vector<int> a(n);
    for (size_t i=0; i<n; ++i)
        scanf("%d", &a[i]);

    map<int, size_t> m;
    for (size_t i=0; i<n; ++i)
        m[a[i]] = i;

    vector<int> b(n);
    int rank_=1;
    for (pair<const int, size_t> p: m)
        b[p.second] = rank_++;

    BinaryIndexedTree<i64> tree(n+1);
    i64 res=0;
    for (size_t i=0; i<n; ++i) {
        res += i-tree.sum(b[i]);
        tree.add(b[i], 1);
    }

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

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

template <typename T>
void chmax(T &a, T b) {
  a = max(a, b);
}
template <typename T>
void chmin(T &a, T b) {
  a = min(a, b);
}

int dx[] = {0, 0, 1, -1};
int dy[] = {1, -1, 0, 0};
const int INF = 1LL << 29;

int dist[25][25];
char board[25][25];
int main() {
  int H, W;
  cin >> H >> W;
  for (int i = 0; i < H; i++) {
    for (int j = 0; j < W; j++) {
      cin >> board[i][j];
    }
  }

  int ans = 0;
  for (int sx = 0; sx < H; sx++) {
    for (int sy = 0; sy < W; sy++) {
      if (board[sx][sy] == '#') continue;
      fill(dist[0], dist[H + 1], INF);
      dist[sx][sy] = 0;
      queue<pair<int, int> > que;
      que.emplace(sx, sy);

      while (que.size()) {
        int x, y;
        tie(x, y) = que.front();
        que.pop();
        for (int k = 0; k < 4; k++) {
          int nx = x + dx[k];
          int ny = y + dy[k];
          if (nx < 0 or nx >= H or ny < 0 or ny >= W) continue;
          if (board[nx][ny] == '#') continue;
          if (dist[nx][ny] > dist[x][y] + 1) {
            dist[nx][ny] = dist[x][y] + 1;
            que.emplace(nx, ny);
          }
        }
      }

      int max_dist = 0;
      for (int i = 0; i < H; i++) {
        for (int j = 0; j < W; j++) {
          if (board[i][j] == '#') continue;
          max_dist = max(max_dist, dist[i][j]);
        }
      }
      chmax(ans, max_dist);
    }
  }
  cout << ans << endl;
  return 0;
}


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

using namespace std;
using uint = unsigned int;
using ll = long long;
using ull = unsigned long long;
using pii = pair<int,int>;
using pll = pair<long, long>;
template <class T> using V = vector<T>;
template <class T> using VV = V<V<T>>;
#define rep(i, n) for(ll i = 0; i<n; i++)
#define rep_s(i, start, n) for(ll i= start;  i<n; i++)
#define rep_down(i, n) for(ll i = n-1; i>=0; i--)
#define rep_down_s(i, n, start) for(ll i = n-1; i>=start; i--)
#define ALL(a) (a).begin(), (a).end()
#define ALL_str(a) (a).cbegin(), (a).cend()
#define print(ans) cout << ans << endl;
#define MOD 1000000007
string alphabet_upper = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
string alphabet_lower  = "abcdefghijklmnopqrstuvwxyz";
string numbers = "0123456789";

/*
for (iterator = hash.begin(); iterator != hash.end(); iterator++)
{
// ここで、要素毎の操作を行います。
std::pair<std::string, CMyClass> element = *iterator;

}
*/
/*
using edge = struct {int to; ll cost;};
vector<edge> tree[limit];
ll depth[limit];

void dfs(int v, int p, ll d){
  depth[v] = d;
  //cout <<"v: " << v << endl;
  for (auto &e: tree[v]){
    //cout << "e.to: " << e.to << endl;
    if (e.to == p) continue;
    dfs(e.to, v, d+e.cost);
  }
}
*/
int keta_sum(int num){
  int dig, sum = 0;
  while(num){
    dig = num % 10;
    sum = sum + dig;
    num = num / 10;
  }
  return sum;
}

ll keta_num(ll num){
  ll total = 0;
  while(num){
    num /= 10;
    total++;
  }
}


ll binary_search(ll left_key, ll border, ll low, ll high) {
     // 配列 a の左端と右端
    ll mid = (low+high)/2;
    while (high > low+1) {
       mid = (low+high)/2;
        if (left_key*mid>border) high = mid;
        else if (left_key*mid<border) low = mid;
        else {
          mid =mid-1;
          break;
        }
    }
    return mid;
}

bool IsPrime(ll a){
  ll b = sqrt(a);
  b++;
  while(b-->=2){
    if (a%b==0) return false;
  }
  return true;
}

ll gcd(ll a, ll b){
  ll tmp;
  if(a<b){
    tmp = a;
    a = b;
    b = tmp;
  }

  ll r = a % b;
  while(r!=0){
    a = b;
    b = r;
    r = a % b;
  }
  return b;
}

ll fibonacchi(ll num){
  ll f0 = 0, f1 = 1, f2;
  ll count = 0;
  while(count<num){
    f2 = f0+f1;
    f0 = f1;
    f1 = f2;
    count++;
  }
  return f2;
}

struct UnionFind {
    vector<int> par; // par[i]:iの親の番号　(例) par[3] = 2 : 3の親が2

    UnionFind(int N) : par(N) { //最初は全てが根であるとして初期化
        for(int i = 0; i < N; i++) par[i] = i;
    }

    int root(int x) { // データxが属する木の根を再帰で得る：root(x) = {xの木の根}
        if (par[x] == x) return x;
        return par[x] = root(par[x]);
    }

    void unite(int x, int y) { // xとyの木を併合
        int rx = root(x); //xの根をrx
        int ry = root(y); //yの根をry
        if (rx == ry) return; //xとyの根が同じ(=同じ木にある)時はそのまま
        par[rx] = ry; //xとyの根が同じでない(=同じ木にない)時：xの根rxをyの根ryにつける
    }

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

int main(void){
  string S, T;
  cin >> S;
  ll count_a = 0;
  rep(i, S.length()) if (S[i]=='A') count_a++;
  if (count_a ==0 || count_a == 3) cout <<"No" << endl;
  else cout <<"Yes" << endl;
  return 0;
}


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

int main() {
	int r,c,n;cin>>r>>c>>n;
	vector<int> x1(n),y1(n),x2(n),y2(n);
	vector<int> l(n,0);
//	vector<vector<int>> v(r+2,vector<int>(c+2,0));
	for(int i=0;i<n;i++){
		int flag,f1,f2,fx,fy;
		cin>>x1[i]>>y1[i]>>x2[i]>>y2[i];
		f1=f2=fx=fy=flag=0;
		if((x1[i]==r)+(x1[i]==0))fx=1;
		if((y1[i]==c)+(y1[i]==0))fy=1;
		if(fx+fy)f1=1;
		fx=fy=0;
		if((x2[i]==r)+(x2[i]==0))fx=1;
		if((y2[i]==c)+(y2[i]==0))fy=1;
		if(fx+fy)f2=1;
		if(f1*f2)flag=1;
		l[i]=flag;
	}
	vector<int> d1(n),d2(n);
	for(int i=0;i<n;i++){
		if(l[i]){
			if(x1[i]==0){
				d1[i]=r+c+r+c-y1[i];
			}else if(x1[i]==r){
				d1[i]=r+y1[i];
			}else{
				if(y1[i]==0){
					d1[i]=x1[i];
				}else{
					d1[i]=r+c+r-x1[i];
				}
			}
			if(d1[i]==2*r+2*c)d1[i]=0;
			if(x2[i]==0){
				d2[i]=r+c+r+c-y2[i];
			}else if(x2[i]==r){
				d2[i]=r+y2[i];
			}else{
				if(y2[i]==0){
					d2[i]=x2[i];
				}else{
					d2[i]=r+c+r-x2[i];
				}
			}
			if(d2[i]==2*r+2*c)d2[i]=0;
		}
	}
	vector<pair<int,int>> pv;
	for(int i=0;i<n;i++){
		if(l[i]){
			pair<int,int> p;
			p.first=d1[i];
			p.second=i;
			pv.push_back(p);
			p.first=d2[i];
			pv.push_back(p);
		}
	}
	sort(pv.begin(),pv.end());
	vector<int> a;
	while(pv.size()){
		int temp=pv.back().second;
		pv.erase(pv.end()-1);
		if(a.size()){
			if(a.back()==temp){
				a.erase(a.end()-1);
			}else{
				a.push_back(temp);
			}
		}else{
		a.push_back(temp);
		}
	}


//	for(int i=0;i<n;i++){
//		if(l[i]){
//			long long temp1,temp2;
//			temp1=d1[i];
//			temp2=d2[i];
//			if(temp1>temp2){
//				temp1=d2[i];
//				temp2=d1[i];
//			}
//			s[temp1]++;
//			s[temp2+1]--;
////			cout<<temp1<<' '<<temp2<<endl;
//		}
//	}
//	for(long long i=1;i<2*r+2*c;i++){
//		s[i]+=s[i-1];
////		cout<<s[i];
//	}
//	int flag=1;
//	for(int i=0;i<n;i++){
//		if(l[i]){
//			if(s[d1[i]]!=s[d2[i]]){
//				flag=0;
//			}
//		}
//	}



//	for(int i=0;i<n;i++){
//		if(l[i]){
//			long long tx1,tx2,ty1,ty2;
//			tx1=x1[i];
//			tx2=x2[i];
//			ty1=y1[i];
//			ty2=y2[i];
//			if((x1[i]-x2[i])*(y1[i]-y2[i])>1){
//				tx1=x2[i];
//				tx2=x1[i];
//			}
//			if(y1[i]>y2[i]){
//				long long temp;
//				temp=ty1;
//				ty1=ty2;
//				ty2=temp;
//				temp=tx1;
//				tx1=tx2;
//				tx2=temp;
//			}
////			v[tx1][ty1]++;
////			v[tx1][ty2+1]--;
////			v[tx2+1][ty1]--;
////			v[tx2+1][ty2+1]++;
//			v[tx1][ty1]++;
//			v[tx1][ty2]--;
//			v[tx2][ty1]--;
//			v[tx2][ty2]++;
//		}
//	}
//	for(int i=0;i<=r+1;i++){
//		for(int j=1;j<=c+1;j++){
//			v[i][j]+=v[i][j-1];
//		}
//	}
//	for(int i=1;i<=r+1;i++){
//		for(int j=0;j<=c+1;j++){
//			v[i][j]+=v[i-1][j];
//		}
//	}
//	int flag=1;
//	for(int i=0;i<n;i++){
//		if(l[i]){
//			if(v[x1[i]][y1[i]]!=v[x2[i]][y2[i]]){
//				flag=0;
//			}
//		}
//	}

	if(a.size()==0){
		cout<<"YES"<<endl;
	}else{
		cout<<"NO"<<endl;
	}



	return 0;
}

Measured memory_bytes: 5488
import java.util.Scanner;
public class Main{
  public static void main(String[]args){
    Scanner sc = new Scanner(System.in);
    int n = sc.nextInt();
    double m = 0;

    if(1<=n && n<=100){
      if(n%2==0){
        m = (double)(n/2)/n;
        System.out.println(m);
      }
      if(n%2==1){
        m = (double)((n+1)/2)/n;
        System.out.println(m);
      }
    }
  }
}


Measured memory_bytes: 23252
#include <iostream>
#include <stdio.h>
#include <vector>
#include <cmath>
#include <algorithm>
#include <string>
#include <queue>
#include <stack>
#include <functional>
#include <list>
#include <utility>
#include <map>

using namespace std;

typedef long long ll;
typedef long double ld;
typedef pair<int,int> Pii;
typedef pair<ll, ll> Pll;
typedef pair<int, Pii > P1;

#define rep(i,n) for(int i=0;i<n;i++)
#define rrep(i,x) for(int i=x-1;i>=0;i--)
#define sor(v) sort(v.begin(),v.end())
#define rev(s) reverse(s.begin(),s.end())
#define lb(vec,a) lower_bound(vec.begin(),vec.end(),a)
#define ub(vec,a) upper_bound(vec.begin(),vec.end(),a)
#define mp1(a,b,c) P1(a,P(b,c))
#define get_arsize(a) (sizeof(a)/sizeof(a[0]))

const ll mod = 1000000007;
const double eps = 1e-10;
const int MAX = 2000000000;
// 解説読んだ
// 753からなる数を生成し、そこから753数に当てはまるものを選ぶ
long int N;
int dfs(string s) {
  // Nを超えたらおしまい
  if (stol(s) > N) return 0;
  // 753数判定し、判定クリアなら1、判定Noの場合は、0
  int ret = 0;
  if (s.find('3') != std::string::npos && s.find('5') != std::string::npos && s.find('7') != std::string::npos) ret = 1;

  // 再帰でその文字列に3,5,7を足したものの753数の数
  ret += dfs(s + "3");
  ret += dfs(s + "5");
  ret += dfs(s + "7");
  return ret;
}

int main() {
	cin >> N;
	cout << dfs("0") << endl;
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define endl "\n"
#define what_is(x) cerr << #x <<" is " << x << endl;
typedef long long ll;
const int MOD = 998244353;
const double PI = 3.141592653589793;
const ll INF =  1e18 + 7;
const int nax = 200005;


double power(double a, ll b) {
	double ans = 1;
	while (b) {
		if (b & 1) {
			ans = (ans * a);
		}
		a = (a * a);
		b = b >> 1;
	}
	return ans;
}


int main() {
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	int tc = 1;
	// cin >> tc;
	while (tc--) {
		string s;
		cin >> s;
		if(s=="ABC")
			cout<<"ARC";
		else cout<<"ABC";
	}
	return 0;
}




















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

long long int n,k,i,j,a,b,c,dp[100010][3],ans;
string s;

signed main()
{
    ios_base::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
	
	cin>>n>>k>>a>>b>>c>>s;
	dp[0][1]=0;dp[0][2]=0;dp[0][3]=0;
	for (i=1;i<n+1;i++) for (j=1;j<4;j++)
	{
		dp[i][j]=0;
		if (j==1 && s[i-1]=='s') dp[i][j]=a;
		if (j==2 && s[i-1]=='p') dp[i][j]=b;
		if (j==3 && s[i-1]=='r') dp[i][j]=c;
		if (i>k) dp[i][j]=dp[i][j]+max(dp[i-k][j%3+1],dp[i-k][(j+1)%3+1]);
	}
	ans=0;
	for (i=0;i<min(n,k);i++) ans=ans+max(dp[n-i][1],max(dp[n-i][2],dp[n-i][3]));
	cout<<ans;
}

Measured memory_bytes: 6072
#include<bits/stdc++.h>
using namespace std;
#define fs first
#define sc second
#define pb push_back
#define mp make_pair
#define eb emplace_back
#define ALL(A) A.begin(),A.end()
#define RALL(A) A.rbegin(),A.rend()
typedef long long ll;
typedef pair<ll,ll> P;
const ll mod=1000000007;
const ll LINF=1LL<<60;
const int INF=1<<30;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
vector<ll> a(200000);
vector<ll> b(200000);
int n;
ll search(){
	ll ans = 0;
	for(int i = 0; i < n; i++) {
		ll key = i + a[i];
		auto low =  lower_bound(ALL(b),key);
		auto up = upper_bound(ALL(b),key);
		ans += (up - low);
	}
	return ans;
}
int main(){
	cin>>n;
	for(int i = 0; i < n; i++) {
		cin>>a[i];
		b[i] = i - a[i];
	}
	sort(ALL(b));
	cout << search() << endl;
	return 0;
}

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

const int MAX = 20;

int main(){
    string s;
    cin >> s;
    for(int i = 0; i < 3; i++){
        if(s[i] == s[i+1]){
            cout << "Bad" << endl;
            return 0;
        }
    }
    cout << "Good" << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define MAX 101
int m[MAX][MAX],d[MAX],f[MAX],tt,n,book[MAX];

void dfs_vis(int s)
{
	book[s]=0;
	d[s]=++tt;
	for(int i=1;i<=n;i++)
	{
		if(!m[s][i]) continue;
		if(book[i]) dfs_vis(i);
	}
	f[s]=++tt;
}

void dfs()
{
	for(int i=1;i<=n;i++) book[i]=1;
	for(int i=1;i<=n;i++) if(book[i]) dfs_vis(i);
	for(int i=1;i<=n;i++) cout<<i<<" "<<d[i]<<" "<<f[i]<<endl;
}
int main()
{
	int u,k,t;
	scanf("%d",&n);
	for(int i=0;i<n;i++)
	{
		cin>>u>>k;
		for(int j=0;j<k;j++)
		{
			cin>>t;
			m[u][t]=1;
		}
	}	
	dfs();
	return 0;
}


Measured memory_bytes: 3236
#include<iostream>}

#include<cstdio>

using namespace std;

int main()
{
	int a; int b; int c; int d;int x;

	d = 0;
	cin >> a >> b >> c;
	for (x = a; x <= b; x++)
		if (c%x == 0){
			d++;
		}
	cout << d << endl;


	return 0;
}

Measured memory_bytes: 1164
import java.io.*;
import java.util.*;

public class Main {
    
    public static void main(String[] args) throws IOException {
        int N = in.nextInt();         // number of items
        int W = in.nextInt();         // capacity
        int[] weight = new int[N];    // weights
        int[] value = new int[N];     // values
        
        for(int i = 0; i < N; i++){
            weight[i] = in.nextInt();
            value[i] = in.nextInt();
        }

        long[][] dp = new long[N + 1][W + 1];
        
        // without repetition - each item can be taken only once
        for(int n = 1; n <= N; n++){
            for(int w = 1; w <= W; w++){
                if(weight[n - 1] <= w){
                    // pick the best option among choosing the current item and skipping it
                    dp[n][w] = Math.max(dp[n - 1][w - weight[n - 1]] + value[n - 1], dp[n - 1][w]);
                }
                else{
                    // fill with how much we can get without this item and with capacity of w
                    dp[n][w] = dp[n - 1][w];
                }
            }
        }

        println(dp[N][W]);
        in.close();
        out.close();
    }

    static int MIN = Integer.MIN_VALUE;
    static int MAX = Integer.MAX_VALUE;
    static Reader in = new Reader();
    static PrintWriter out = new PrintWriter(System.out);
    static void read(int arr[], int N) throws IOException{ for(int i = 0; i < N; i++){ arr[i] = in.nextInt(); } }
    static void read(long arr[], int N) throws IOException{ for(int i = 0; i < N; i++){ arr[i] = in.nextLong(); } }
    static void read(String arr[], int N) throws IOException{ for(int i = 0; i < N; i++){ arr[i] = in.next(); } }
    static void print(Object O){ out.print(O); }
    static void println(Object O){ out.println(O); }
    static void print(int arr[]){ for(int i = 0; i < arr.length; i++){ print(arr[i]+" "); } println(""); }
    static void print(int arr[][]){ for(int i = 0; i < arr.length; i++){ print(arr[i]); } }
    static void debug(Object O){ System.out.println(O); }
}

class Reader {
    BufferedReader reader;
    StringTokenizer tokenizer;

    Reader() {
        reader = new BufferedReader(new InputStreamReader(System.in));
        tokenizer = new StringTokenizer("");
    }

    String next() throws IOException {
        while (!tokenizer.hasMoreTokens() ) { 
            tokenizer = new StringTokenizer(reader.readLine()); 
        }
        return tokenizer.nextToken();
    }

    int nextInt() throws IOException { 
        return Integer.parseInt(next()); 
    }
    
    double nextDouble() throws IOException { 
        return Double.parseDouble(next());
    }
    
    long nextLong() throws IOException { 
        return Long.parseLong(next()); 
    }
    
    String nextLine() throws IOException { 
        return reader.readLine(); 
    }
    
    void close() throws IOException { 
        reader.close(); 
    }
}


Measured memory_bytes: 128980
import std.algorithm, std.array, std.container, std.range, std.bitmanip;
import std.numeric, std.math, std.bigint, std.random, core.bitop;
import std.string, std.conv, std.stdio, std.typecons;

void main()
{
  auto n = readln.chomp.to!int;
  auto ai = readln.split.map!(to!long);
  writeln(ai.reduce!(min), " ", ai.reduce!(max), " ", ai.sum);
}

Measured memory_bytes: 2800
#include <bits/stdc++.h>
#define _GLIBCXX_DEBUG
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()

using namespace std;
using ll = long long;
using vpii = vector<pair<int, int>>;
using vpll = vector<pair<ll, ll>>;
// ceil() 切り上げ, floor() 切り捨て
// next_permutation(all(x))

int		main(void)
{
	int N;
	cin >> N;
	vector<int> A1(N);
	vector<int> A2(N);
	for (int i = 0; i < N; i++)
		cin >> A1[i];
	for (int i = 0; i < N; i++)
		cin >> A2[i];
	int ans = 0;
	for (int i = 0; i < N; i++)
	{
		int sum = 0, j = 0;
		while (j <= i)
			sum += A1[j++];
		int k = i;
		while (k < N)
			sum += A2[k++];
		ans = max(ans, sum);
	}
	cout << ans << endl;
}



Measured memory_bytes: 256
var n,h,left:int64;
begin
  readln(n);
  left:=0;
  while n>0 do begin
    read(h);
    if left < h then
      left:=h-1
    else if left = h then
    else begin
      writeln('No');
      exit;
    end;
    dec(n);
  end;
  writeln('Yes');
end.

Measured memory_bytes: 128
package main

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

var sc, wr = bufio.NewScanner(os.Stdin), bufio.NewWriter(os.Stdout)

func scanString() string { sc.Scan(); return sc.Text() }
func scanInt() int { a,_ := strconv.Atoi(scanString()); return a }
func scanInt64() int64 { a,_ := strconv.ParseInt(scanString(),10,64); return a }
func scanFloat64() float64 { a,_ := strconv.ParseFloat(scanString(),64); return a }

func scanInts(n int) []int {
	res := make([]int, n); for i := 0; i < n; i++ { res[i] = scanInt() }; return res
}

func abs(a int) int { if a<0 { return -a }; return a }
func min(a,b int) int { if a<b { return a }; return b }
func max(a,b int) int { if a>b { return a }; return b }

//•*¨*•.¸¸♪Main•*¨*•.¸¸♪(　-ω-)ノ　(　・ω・)

func main() {
	defer wr.Flush()
	sc.Split(bufio.ScanWords)
	sc.Buffer(make([]byte, 10000), 1001001)

	a := scanInt()
	b := scanInt()
	c := scanInt()
	x := scanInt()
	y := scanInt()

	ma := max(x,y)
	ans := 0
	for i := 0; i < ma; i++ {
		co := 0
		if x != 0 {
			co += a
			x--
		}
		if y != 0 {
			co += b
			y--
		}

		if co < 2*c {
			ans += co
		} else {
			ans += 2*c
		}
	}

	fmt.Fprintln(wr, ans)
}


Measured memory_bytes: 640
#include<bits/stdc++.h>
 
using namespace std;
 
typedef long long ll;
 
int main() {
#ifndef ONLINE_JUDGE
    //freopen("input.txt", "r", stdin);
    //freopen("output.txt", "w", stdout);
#endif
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    int n, l;
    cin >> n >> l;
    vector <string> s(n);
    for(int i = 0; i < n; i++){
        cin >> s[i];
    }
    sort(s.begin(), s.end());
    string ans = "";
    for(int i = 0; i < n; i++){
        ans += s[i];
    }
    cout << ans << "\n";
    return 0;
}

Measured memory_bytes: 3664
#include "bits/stdc++.h"
#define rep(i,n) for(int i = 0; i < (n); ++i)
using namespace std;
typedef long long int ll;
typedef pair<int, int> P;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

ll gcd(ll a, ll b) {
    if (b == 0) return a;
    return gcd(b, a % b);
}

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int a, b, c;
    cin >> a >> b >> c;
    int g = gcd(a, b);
    if(c%g == 0) cout << "YES" << endl;
    else cout << "NO" << endl;
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
 
struct UnionFind {
    vector<int> r;
 
    UnionFind(int N) {
        r = vector<int>(N, -1);
    }
 
    int root(int x) {
        if (r[x] < 0) return x;
        return r[x] = root(r[x]);
    }
 
    bool unite(int x, int y) {
        x = root(x);
        y = root(y);
        if (x == y) return false;
        if (r[x] > r[y]) swap(x, y);
        r[x] += r[y];
        r[y] = x;
        return true;
    }
 
    int size(int x) {
        return -r[root(x)];
    }
};
 
 
int main() {
    int N, M;
    cin >> N >> M;
 
    UnionFind UF(N);
    for (int i = 0; i < M; i++)
    {
        int A, B;
        cin >> A >> B;
        A -= 1; B -= 1;
        UF.unite(A, B);
    }
 
    int ans = 0;
    for (int i = 0; i < N; i++)
    {
        ans = max(ans, UF.size(i));
    }
 
    cout << ans << endl;
}


Measured memory_bytes: 4048
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define repit(it, li) for(auto it=li.begin(); it!=li.end(); it++)
using namespace std;
using ll = long long;
using P = pair<int,int>;

int main(){
   int d, t, s;
   cin>>d>>t>>s;

   bool ok= d<=(ll)t*s;

   if(ok) cout<<"Yes"<<endl;
   else cout<<"No"<<endl;
   return 0;
}


Measured memory_bytes: 3632
// https://atcoder.jp/contests/abc160/tasks/abc160_c

#include "algorithm"
#include "bitset"
#include "cmath"
#include "functional"
#include "iomanip"
#include "iostream"
#include "map"
#include "numeric"
#include "queue"
#include "set"
#include "string"
#include "vector"
#define rep(i, to) for (ll i = 0; i < (to); ++i)
#define rep1(i, to) for (ll i = 1; i <= (to); ++i)
#define repf(i, from, to) for (ll i = from; i < (to); ++i)
#define repr(i, from) for (ll i = from - 1; i >= 0; --i)
#define all(vec) vec.begin(), vec.end()
#define unless(cond) if (!(cond))
#define fi first
#define se second
using namespace std;
typedef long long ll;
typedef long double ld;
template <typename T>
using V = vector<T>;
using VL = V<ll>;
using VVL = V<VL>;
template <typename T, typename U>
using P = pair<T, U>;
using PL = P<ll, ll>;
using VPL = V<PL>;
template <typename T>
inline bool chmax(T& a, T b);
template <typename T>
inline bool chmin(T& a, T b);
void print_ints(vector<ll> v);
template <typename T>
void drop(T a);

const ll INF = 1e18;

void solve() {
  ll K, N;
  cin >> K >> N;

  VL as(N);
  rep(i, N) cin >> as[i];

  ll max_ds = -1;

  rep(i, N) {
    ll next = i == N - 1 ? as[0] + K : as[i + 1];
    chmax(max_ds, next - as[i]);
  }

  cout << K - max_ds << endl;
}

struct exit_exception : public std::exception {
  const char* what() const throw() { return "Exited"; }
};

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

  try {
    solve();
  } catch (exit_exception& e) {
  }

  return 0;
}
#endif

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

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

void print_ints(vector<ll> v) {
  rep(i, v.size()) {
    if (i > 0) {
      cout << " ";
    }

    cout << v[i];
  }

  cout << endl;
}

template <typename T>
void drop(T res) {
  cout << res << endl;
  throw exit_exception();
}


Measured memory_bytes: 1792
#include <algorithm>
#include <iostream>
#include <cstdlib>
#include <cstring>
#include <cstdio>
#include <string>
#include <vector>
#include <queue>
#include <cmath>
#include <ctime>
#include <map>
#include <set>
#define MEM(x,y) memset ( x , y , sizeof ( x ) )
#define rep(i,a,b) for (int i = (a) ; i <= (b) ; ++ i)
#define per(i,a,b) for (int i = (a) ; i >= (b) ; -- i)
#define pii pair < int , int >
#define one first
#define two second
#define rint read<int>
#define int long long
#define pb push_back
#define db double
#define ull unsigned long long
#define lowbit(x) ( x & ( - x ) )

using std::queue ;
using std::set ;
using std::pair ;
using std::max ;
using std::min ;
using std::priority_queue ;
using std::vector ;
using std::swap ;
using std::sort ;
using std::unique ;
using std::greater ;

template < class T >
    inline T read () {
        T x = 0 , f = 1 ; char ch = getchar () ;
        while ( ch < '0' || ch > '9' ) {
            if ( ch == '-' ) f = - 1 ;
            ch = getchar () ;
        }
       while ( ch >= '0' && ch <= '9' ) {
            x = ( x << 3 ) + ( x << 1 ) + ( ch - 48 ) ;
            ch = getchar () ;
       }
       return f * x ;
    }

int n , d ;
int x , y ;

signed main (int argc , char * argv[]) {
    n = rint () ;
    for (int i = 1 ; i * i <= n ; ++ i) if ( n % i == 0 ) d = i ;
    x = d ; y = n / d ;
    printf ("%lld\n" , x - 1 + y - 1 ) ;
    return 0 ;
}

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

#define file(s) freopen(s".in", "r", stdin), freopen(s".out", "w", stdout)
#define go(x, i) for(register int i = head[x]; i; i = nxt[i])
#define For(i, a, b) for(register int i = (a), i##_end_ = (b); i <= i##_end_; ++ i)
#define DFor(i, a, b) for(register int i = (a), i##_end_ = (b); i >= i##_end_; -- i)
#define debug(x) cout << #x << " = " << x << endl
#define mem(a, b) memset(a, b, sizeof(a))
#define cpy(a, b) memcpy(a, b, sizeof(a))
#define min(a, b) (a < b ? a : b)
#define max(a, b) (b < a ? a : b)
#define inf (0x3f3f3f3f)
#define INF (1e18)
#define pb push_back
#define mp make_pair
#define x first
#define y second
#define read() Read<int>()

typedef unsigned long long ull;
typedef unsigned int uint;
typedef long long ll;
typedef std::pair<ll, int> PLI;
typedef std::pair<int, int> PII;
typedef double db;

namespace IO {
#define getc() ((S_ == T_) && (T_ = (S_ = Ch_) + fread(Ch_, 1, Buffsize, stdin), S_ == T_) ? 0 : *S_ ++)
	const uint Buffsize = 1 << 15, Output = 1 << 23;
	static char Ch_[Buffsize], *S_ = Ch_, *T_ = Ch_;
	static char Out[Output], *nowps = Out;
	inline void flush(){fwrite(Out, 1, nowps - Out, stdout); nowps = Out;}
	template<typename T >inline T Read() {
		T _ = 0; static char __; T ___ = 1;
		for(__ = getc(); !isdigit(__); __=getc()) if(__ == '-') ___ = -1;
		for(; isdigit(__); __ = getc()) _ = (_ << 3) + (_ << 1) + (__ ^ 48);
		return _ *= ___;
	}
	template<typename T>inline void write(T _, char __ = '\n') {
		if(!_) *nowps ++ = '0';
		if(_ < 0) *nowps ++ = '-', _ = -_;
		static uint sta[111], tp;
		for(tp = 0; _; _ /= 10) sta[++ tp] = _ % 10;
		for(; tp; *nowps ++ = sta[tp --] ^ 48); 
		(*nowps ++) = __;
	}
	template<class T>inline bool chkmax(T &_, T __) {return _ < __ ? _ = __, 1 : 0;}
	template<class T>inline bool chkmin(T &_, T __) {return _ > __ ? _ = __, 1 : 0;}
}

using namespace std;
using namespace IO;

const int N = 1e5 + 10;
const int Mod = 1e9 + 7;
int n, ans;
int a[N], Sum[N];
int Pow(int x,int k) {
	int res = 1;
	while(k) {
		if(k & 1) res = 1ll * res * x % Mod;
		x = 1ll * x * x % Mod;
		k >>= 1;
	}
	return res;
}
int main() {
	//file("B");
	n = read();int tot = 1;
	For(i, 1, n) a[i] = read();
	For(i, 1, n) {
		Sum[i] = (Sum[i - 1] + Pow(i, Mod - 2)) % Mod;
		tot = 1ll * tot * i % Mod;
	}
	For(i, 1, n) {
		int p = (Sum[i] + Sum[n - i + 1] - 1) % Mod;
		ans = (ans + 1ll * p * a[i] % Mod) % Mod;
	}
	printf("%lld\n",1ll * ans * tot % Mod);
	return flush(), 0;
}


Measured memory_bytes: 1024
S = str(input())

s0 = int(S[:2])
s1 = int(S[2:])

if s0 <= 12 and s0 >= 1 and s1 <= 12 and s1 >= 1:
    print('AMBIGUOUS')
elif s0 <= 12 and s0 >= 1:
    print('MMYY')
elif s1 <= 12 and s1 >= 1:
    print('YYMM')
else:
    print('NA')

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

#define ll long long
#define endl "\n"
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);

const int MAX = 1e5 + 1;
ll a[MAX];

int main()
{
	IOS
	int t = 1;
	//cin >> t;
	while(t--)
	{
		int x;
		cin >> x;
		if(x >= 30) cout << "Yes\n";
		else cout << "No\n";
	}
	return 0;
}


Measured memory_bytes: 3648
#include <bits/stdc++.h>
#define maxn 800
#define maxm 1009
using namespace std;
int b[maxn][maxn],a[maxn][maxn];
int  guass(int n)
{
	int i,j,p,row=0,col=0;
	for(;row<n&&col<n;row++,col++)
	{
		for(i=row,p=row;i<n;i++)
			if(a[i][col])
			{p=i;break;}
		if(p!=row)
			for(j=col;j<=n;j++)
				swap(a[p][j],a[row][j]);
		if(!a[row][col]) 
		{
			row--;
			continue;
		}
		for(i=row+1;i<n;i++)
			if(a[i][col])
			for(j=col+1;j<=n;j++)
				a[i][j]^=a[row][j];
	}
	for(i=row;i<n;i++)
		if(a[i][n]) return 0;
	return 1;
}
int main()
{
	int n,m,d;
	while(scanf("%d%d%d",&m,&n,&d)!=EOF&&n+m+d)
	{
		for(int i=0;i<n;i++)
		{
			for(int j=0;j<m;j++)
				scanf("%d",&b[i][j]);
		}
		memset(a,0,sizeof(a));
		for(int i=0;i<n;i++)
		{
			for(int j=0;j<m;j++)
			{
				a[i*m+j][n*m]=b[i][j];
				a[i*m+j][i*m+j]=1;
				for(int x=0;x<n;x++)
				{
					for(int y=0;y<m;y++)
					{
						if(abs(x-i)+abs(y-j)==d)
							a[i*m+j][x*m+y]=1;
					}
				}
			}
		}
		if(guass(n*m))
			puts("1");
		else
			puts("0");
	}
	return 0;
}

Measured memory_bytes: 5268
#include <algorithm>
#include <iomanip>
#include <iostream>
#include <queue>
#include <set>
#include <string>
#include <vector>
#define SORT(a) sort(a.begin(), a.end())
#define RSORT(a) sort(a.rbegin(), a.rend())
#define REP(i, n) for (int i = 0; i < n; i++)
#define RREP(i, n) for (int i = n; 0 <= i; i--)
#define FOR(i, start, end) for (int i = start; i < end; i++)
#define FORSTEP(i, start, end, step) for (int i = start; i < end; i += step)
#define RFOR(i, start, end) for (int i = start; end <= i; i--)
#define ALL(a) a.begin(), a.end()
#define MOD(a) a %= 1000000007
typedef long long ll;
const int INF32 = 2147483647;
const ll INF64  = 9223372036854775807;
using namespace std;

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

    char a;
    cin >> a;
    char ans;
    if (a == 'A')
        ans = 'T';
    if (a == 'T')
        ans = 'A';
    if (a == 'C')
        ans = 'G';
    if (a == 'G')
        ans = 'C';
    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 256
n = int(input())
arr = list(map(int, input().split()))
arr.sort()
for i in range(n - 1):
    arr[i + 1] = (arr[i] + arr[i +1])/2
if arr[-1] == int(arr[-1]):
    print(int(arr[-1]))
else:
    print(arr[-1])


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

int main(int argc, char const *argv[])
{
	int n,p;
	int s;
	int i1;

	while(1){
		cin>>n>>p;
		if (n+p==0) break;

		vector<int> v(n);
		i1=0;
		s=p;

		while(1){
			if (s>0){
				v[i1]++;
				s--;	
			}
			else {
				s=v[i1];
				v[i1]=0;
			}

			if (v[i1] == p) break;

			i1++;
			if(i1==n) i1=0;
		}

		cout<<i1<<endl;

	}
	return 0;
}

Measured memory_bytes: 1196
import kotlin.math.pow
import kotlin.math.sqrt

//

fun main() {
    abc174b()
}

fun abc174b() {
    val (n, d) = readLine()!!.split(" ").map { it.toInt() }
    var count = 0
    repeat(n) {
        val (x, y) = readLine()!!.split(" ").map { it.toLong() }
        if (sqrt(x.toDouble().pow(2.0) + y.toDouble().pow(2.0)) <= d) {
            count++
        }
    }
    println(count)
}


Measured memory_bytes: 60128
//A
#include <iostream>
#include <string>
#include <algorithm>

using namespace std;
int N, K;
string S;

int main()
{
  cin >> N >> K;
  cin >> S;
  S.at(K - 1) = tolower(S.at(K - 1));
  cout << S << endl;
  return 0;
}


Measured memory_bytes: 256
#include <algorithm>
#include <bitset>
#include <cctype>
#include <climits>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>

using namespace std;

#define FOR(i, first, last) for (int i = (first); i < (last); ++i)
#define REP(i, n) FOR(i, 0, n)
#define CLR(a) memset((a), 0, sizeof(a))
#define DUMP(x) std::cerr << #x << " = " << (x) << std::endl;

inline int to_int(string s) {
  int v;
  istringstream sin(s);
  sin >> v;
  return v;
}
template <class T> inline string to_string(T x) {
  ostringstream sout;
  sout << x;
  return sout.str();
}

typedef unsigned long long ull;
typedef unsigned long ul;

template<class Iterator>
bool is_ith_same(Iterator first, Iterator last, size_t index) {
  const char c = first->at(index);
  for(auto it=first; it!=last; ++it) {
    if(it->at(index) != c) return false;
  }
  return true;
}

int main() {
  int n;
  cin >> n;
  vector<string> v(n);

  REP(i, n) cin >> v[i];

  for (auto &s : v)
    sort(s.begin(), s.end());

  string common = *v.begin();

  for(const auto& s:v) {
    string tmp;
    set_intersection(common.begin(), common.end(),
                     s.begin(), s.end(),
                     back_inserter(tmp));
    common = tmp;
  }
  sort(common.begin(), common.end());
  cout<<common<<endl;

  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <queue>
#include <cstring>
#include <cstdio>
#include <cmath>
#include <set>
#include <map>
#include <bitset>

using namespace std;

int main() {
	int n,answer;
	answer=0;
	cin>>n;
	vector<int> v(n);
	for(int i=0; i<n; i++) cin>>v.at(i);
	vector<int> c(n);
	for(int i=0; i<n; i++) cin>>c.at(i);
	
	for(int i=0; i<n; i++){
		if(v.at(i)>c.at(i)) answer+=(v.at(i)-c.at(i));
	}
	cout<<answer<<endl;
}



Measured memory_bytes: 256
#!/usr/bin/env python
# coding: utf-8

# In[22]:


N = int(input())
P = list(map(int, input().split()))


# In[23]:


ans = 0
tmp = P[0]
for i in range(N):
    if P[i] <= tmp:
        ans += 1
        tmp = P[i]
print(ans)


# In[ ]:






Measured memory_bytes: 24744
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

#include <iostream>
#include <string>
#include <vector>
#include <map>
#include <unordered_map>
#include <queue>
#include <algorithm>

#include <bits/stdc++.h>
#include <cmath>
#include <limits>

using namespace std;

int A, B, C, D, E, F;

int dp[3000+2] = {0}; // 0 未, 1不可, 2可能

int possibleWater(int water){
	int ret = 1;
	if(dp[water] != 0){
		return dp[water];
	}
	for(int i=0; (100 * A * i) <= F; i++){
		for(int j=0; (100 * B * j) <= F; j++){
			int tmp = (100 * A * i) + (100 * B * j) ;
			if(tmp <= F)
				dp[tmp] = 2;
			if(water == tmp){
				ret = 2;
				break;
			}
		}
		if(ret == 2){
			break;
		}
	}
	if(water <= F){
		dp[water] = ret;
	}
	return ret;
}

int main(int argc, char* argv[]){
	cin.tie(0);
	ios::sync_with_stdio(false);

	cin >> A >> B >> C >> D >> E >> F;
	
	// 水 100A g : x回 
	// 水 100B g : y回 
	// さとう C g : u 回
	// さとう D g : v 回
	int water, water1;
	int sugar, sugar1;
	water1 = 100 * A , sugar1 = 0;
	for(water = 100; water <= F; water += 100){
		if(possibleWater(water) != 2) continue;
		int water2 = 100 * A, sugar2 = 0;
		int k = water / 100;
		int u, v;
		for(v = 0; (D * v) <= F - water; v++){
			for(u = 0; (C * u) <= F - water - (D * v); u++){
				sugar = (C * u) + (D * v);
				if( sugar > (E * k) ) continue;
				if((water + sugar) > F) continue;
				if( (sugar + C) <= E * k && (sugar + C + water) <=F){
					u = u + 1;
					sugar = sugar + C;
				}
				if(sugar * (100 + E) > E * (sugar + water)) continue;
				if(sugar2 * (water + sugar) <= sugar * (water2 + sugar2)){
					sugar2 = sugar;
					water2 = water;
				}
			}
		}
		if(sugar1 * (water2 + sugar2) <= sugar2 * (water1 + sugar1)){
			water1 = water2;
			sugar1 = sugar2;
		}
	}
	printf("%d %d\n", water1+sugar1, sugar1);
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
const int inf = 1e9 + 7;
typedef long long ll;
using pii = pair<int, int>;
#define rep(i, n) for (int i = 0; i < n; ++i)
#define rrep(i, st, n) for (int i = st; i < n; ++i)
#define chmax(a, b) a = max(a, b)
#define chmin(a, b) a = min(a, b)
int dx[] = {0, 0, -1, 1};
int dy[] = {1, -1, 0, 0};
int main() {
    int n, m; cin >> n >> m;
    int table[100002] = {0};
    rep(i, m) {
        int l, r; cin >> l >> r;
        table[l]++;
        table[r + 1]--;
    }
    rrep(i, 1, 100002) table[i] += table[i - 1];
    int c = 0;
    rep(i, 100002) if (table[i] == m) c++;
    cout << c << endl;
}



Measured memory_bytes: 640