akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
using namespace std;
#pragma region atcoder
#include <atcoder/segtree>
using namespace atcoder;
//These are for segment tree
int op(int a, int b){return max(a, b);}
int e(){return 0;}
//bool f(int v){ return v < target;}

#pragma endregion
#pragma region macros
using ll = long long;
using vi = vector<int>;
using vs = vector<string>;
using vl = vector<ll>;
using vb = vector<bool>;
using vvi = vector<vector<int>>;
using vvl = vector<vector<ll>>;
#define rep(i, n) for(int i = 0; i < n; i++)
#define rrep(i, n) for(int i = n - 1; i >= 0; i--)
#define all(x) (x).begin(), (x).end()
#define sz(x) ((int)(x).size())
#pragma endregion
#pragma region debug for var, v, vv
#define debug(var)  do{std::cout << #var << " : ";view(var);}while(0)
template<typename T> void view(T e){std::cout << e << std::endl;}
template<typename T> void view(const std::vector<T>& v){for(const auto& e : v){ std::cout << e << " "; } std::cout << std::endl;}
template<typename T> void view(const std::vector<std::vector<T> >& vv){cout << endl;int cnt = 0;for(const auto& v : vv){cout << cnt << "th : "; view(v); cnt++;} cout << endl;}
#pragma endregion

const ll mod = 1000000007;
const int inf = 1001001001;
const ll INF = 1001001001001001001;
const int MAX = 2000005;

template<class T>bool chmax(T &a, const T b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T b) { if (b<a) { a=b; return 1; } return 0; }
ll modpow(ll a, ll p){ll ret = 1; while(p){if(p & 1){ret = ret * a % mod;} a = a * a % mod; p >>= 1;} return ret;}

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

/*-----------------------------------------------------------------------------------------------------*/
int main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	int n, k; cin >> n >> k;
	vi a(n);
	rep(i,n) cin >> a[i];
	segtree<int, op, e> dp(300002);
	rep(i,n){
		int len = dp.prod(max(0, a[i] - k), min(300002, a[i] + k + 1));
		dp.set(a[i], max(dp.get(a[i]), len + 1));
	}
	cout << dp.all_prod() << endl;
}

Measured memory_bytes: 9700
package main

import "fmt"

func main() {
	var N, R, G, B int
	fmt.Scan(&R, &G, &B, &N)
	ret := 0
	for r := 0; r <= N; r++ {
		for g := 0; g <= N; g++ {
			b := N - r*R - g*G
			if 0 <= b && b%B == 0 {
				ret++
			}
		}
	}
	fmt.Println(ret)
}


Measured memory_bytes: 512
#include<functional>
#include<algorithm>
#include<iostream>
#include<utility>
#include<string>
#include<vector>
#include<cmath>
#include<stack>
#include<queue>
#include<deque>
#include<map>
#define rep(i,n) for(int i=0;i<n;i++)
#define loop(i,x,n) for(int i=x;i<n;i++)
#define all(v) (v).begin(),(v).end()
#define pf push_front
#define pb push_back
#define int long long
using namespace std;
const int INF=1000000007;
int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};

int inf=pow(2,31)-1;
int size=1;
vector<int> tree;

void init(int n){
  while(size<n){
    size*=2;
  }
  tree.assign(size*2,inf);
}

void update(int m,int x){
  tree[m+=size]=x;
  while(m/=2){
    tree[m]=min(tree[m*2],tree[m*2+1]);
  }
}

int find(int l,int r){
  l+=size,r+=size;
  int al=inf,ar=inf;
  for(;l<r;l/=2,r/=2){
    if(l%2==1)al=min(tree[l++],al);
    if(r%2==1)ar=min(tree[--r],ar);
  }
  return min(al,ar);
}

signed main(){
  int n,q;
  cin>>n>>q;
  init(n);
  rep(i,q){
    int com,x,y;
    cin>>com>>x>>y;
    if(com){
      y+=1;
      cout<<find(x,y)<<endl;
    }else{
      update(x,y);
    }
  }
  return 0;
}

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

using namespace std;

int main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	int n, m;
	cin >> n >> m;
	int memo[100010] = {};
	for (int i = 0; i < n; i++) {
		int x;
		cin >> x;
		memo[x]++;
	}

	vector< vector<int> > a(m);
	for (int i = 1; i <= 100000; i++) {
		if (memo[i] == 0) continue;
		a[i % m].emplace_back(memo[i]);
	}
    
	vector<int> sum(m);
	for (int i = 0; i < m; i++) {
        sum[i] = accumulate(a[i].begin(), a[i].end(), 0);
	}

	int ans = sum[0] / 2;
	if (m % 2 == 1) {
		for (int i = 1; i <= m / 2; i++) {
			int tmp = 0;
			if (sum[i] < sum[m - i]) {
				swap(a[i], a[m - i]);
				swap(sum[i], sum[m - i]);
			}
			ans += sum[m - i];
			for (int j = 0; j < (int)a[i].size(); j++) {
				tmp += a[i][j] / 2;
				a[i][j] %= 2;
			}
			ans += min(tmp, (sum[i] - sum[m - i]) / 2);
		}
	} else {
		for (int i = 1; i < m / 2; i++) {
			int tmp = 0;
			if (sum[i] < sum[m - i]) {
				swap(a[i], a[m - i]);
				swap(sum[i], sum[m - i]);
			}
			ans += sum[m - i];
			for (int j = 0; j < (int)a[i].size(); j++) {
				tmp += a[i][j] / 2;
				a[i][j] %= 2;
			}
			ans += min(tmp, (sum[i] - sum[m - i]) / 2);
		}
		ans += sum[m / 2] / 2;
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 6528
#include<iostream>
#include<vector>
#include<algorithm>
using namespace std;
int main(){
	int k,t,sum=0;
	cin >> k >> t;
	vector<int>	cake(t);
	for(int i=0;i<t;i++)	cin >> cake[i];
	sort(cake.begin(),cake.end());
	for(int i=0;i<cake.size()-1;i++)	sum+=cake[i];
	if(sum>=cake[t-1])	cout << 0 << endl;
	else	cout << cake[t-1]-sum-1 << endl;
}

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

int main(void){
 	string s;
  	cin >> s;
  	if(s == "ABC") cout << "ARC";
	else cout << "ABC";
	return 0;
}


Measured memory_bytes: 3608
import java.util.*;
import static java.lang.System.*;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int d = sc.nextInt();
		double[][]  pos = new double[n][d];
		for (int i = 0; i < n; i++) {
			for(int j = 0; j < d; j++) {
				pos[i][j] = sc.nextDouble();
			}
		}
		//double[][] dist = new double[n][n];
		int cnt = 0;
		for(int i = 0; i < n - 1; i++) {
			for(int j = i + 1; j < n; j++) {
				double num = 0;
				for(int k = 0; k < d; k++) {
					num +=( pos[i][k] - pos[j][k]) * (pos[i][k] - pos[j][k]);
				}
				num = Math.sqrt(num);
				if( ((int)num - num) == 0)
					cnt++;
			}
		}
		out.println(cnt);
	}
}

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

#define EPS (1e-10)
#define rep(i, a, b) for (int i = a; i < (int)(b); ++i)
#define rrep(i, a, b) for (int i = b - 1; i >= (int)(a); --i)
#define all(a) a.begin(), a.end()

using namespace std;
using ll = long long;
using vi = vector<int>;
using vb = vector<bool>;
using vll = vector<ll>;
using vd = vector<double>;
using vvi = vector<vi>;
using vvb = vector<vb>;

constexpr int MOD = 1000000007;

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

    int n;
    cin >> n;

    rep(i, 1, 10) {
        rep(j, 1, 10) {
            if (i * j == n) {
                cout << "Yes" << endl;
                return 0;
            }
        }
    }

    cout << "No" << endl;
    return 0;
}

Measured memory_bytes: 256
#define _GLIBCXX_DEBUG

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

int calc(char ope, int a, int b){
    int result;
    switch (ope)
    {
        case '+':
            result = b + a;
            break;
        case '-':
            result = b - a;
            break;
        case '*':
            result = b * a;
            break;
    }
    return result;
}

int main(){
    string s;
    int re;
    vector<int> data;

    while(cin >> s){
        if (isdigit(s[0])){
            data.push_back(stoi(s));
        }else{
            int num1 = data.back();
            data.pop_back();
            int num2 = data.back();

            data.pop_back();
            data.push_back(calc(s[0], num1, num2));
        }
    }
    cout << data.at(0) << endl;
    return 0;
}


Measured memory_bytes: 3144
#include <iostream>
#include <vector>
#include <algorithm>
#include <ctime>
#include <cmath>
#include <string>
#include <stdlib.h>
#include <fstream>
#include <set>
#include <map>
#include <stack>
#include <deque>
#include <iterator>
#include <iomanip>
#include <queue>
using namespace std;


int main(){
    long long n, k, mx = 0;
    string s;
    cin >> n >> k >> s;
    for(int i = 0; i < n - 1; ++i){
        if(s[i] == s[i + 1]) mx++;
    }
    cout << min(mx + k * 2, n - 1);
}

Measured memory_bytes: 512
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int n;
  cin >> n;
  vector<int> a(n);
  
  for (int i = 0; i < n; i++) {
    cin >> a.at(i);
  }
  
  int count = 1, number = a.at(0);
  
  while (number != 2) {
    if (count != n) {
      count++;
      number = a.at(number - 1);
    }
    else {
      break;
    }
  }
  
  if (count != n) {
    cout << count << endl;
  }
  else {
    cout << -1 << endl;
  }
}

Measured memory_bytes: 3740
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for(int i = 0; i < (n); i++)
#define rep1(i, n) for(int i = 1; i <= (n); i++)
#define co(x) cout << (x) << "\n"
#define cosp(x) cout << (x) << " "
#define ce(x) cerr << (x) << "\n"
#define cesp(x) cerr << (x) << " "
#define pb push_back
#define mp make_pair
#define Would
#define you
#define please


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


	string S;
	cin >> S;

	int A = stoi(S.substr(0, 2));
	int B = stoi(S.substr(2, 2));

	bool YYMM = 1;
	bool MMYY = 1;

	if (A == 0 || A > 12) MMYY = 0;
	if (B == 0 || B > 12) YYMM = 0;

	if (YYMM && MMYY) co("AMBIGUOUS");
	else if (YYMM) co("YYMM");
	else if (MMYY) co("MMYY");
	else co("NA");

	Would you please return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define pll pair<long long,long long>
#define ii pair<int,int>
#define mod 1000000007
#define endl '\n'
#define IOS std::ios::sync_with_stdio(false); cin.tie(NULL);cout.tie(NULL);

ll power(ll a,ll b){
	ll ans=1;
	while(b>0){
		if(b%2!=0){
			ans=(ans*a)%mod;
		}
		a=((a%mod)*(a%mod))%mod;
		b>>=1;
	}
	return ans;
}

void sieve(int n){
	bool prime[n+1];
	memset(prime,true,sizeof(prime));
	for(int p=2;p*p<=n;p++){
		if(prime[p]){
			for(int i=p*p;i<=n;i+=p)
				prime[i]=false;
		}
	}
	for(int p=2;p<=n;p++){
		if(prime[p])
			cout<<p<<" ";
	}
}

int main() {
	IOS;
	int t=1;
	//cin>>t;
	while(t--){
		int d,t,s;
		cin>>d>>t>>s;
		if(s*t>=d){
			cout<<"Yes";
		}
		else
			cout<<"No";
	}
	return 0;
}

Measured memory_bytes: 3620
#include <bits/stdc++.h>
using namespace std;
const int MAX=109;
int arr[MAX];
int main ()
{
    int n;
    scanf("%d",&n);
    n*=2;
    for (int i=0;i<n;i++)
        scanf("%d",&arr[i]);
    sort(arr,arr+n);
    int ans=0;
    for (int i=0;i<n;i+=2){
        ans+=min(arr[i],arr[i+1]);
    }
    printf("%d\n",ans);
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#include<boost/variant.hpp>
using namespace std;
typedef long long ll;
typedef vector<boost::variant<bool, ll, int, string, double>> any;
template<typename T> inline void pr(const vector<T> &xs){
	for(int i=0; i<xs.size()-1; i++) cout << xs[i] << " ";
	cout << xs[xs.size()-1] << endl;
}
template<typename T> inline void debug(const vector<T> &xs){
#ifdef DEBUG
	pr(xs);
#endif
}

int main(){
	int N, K;
	cin >> N >> K;
	vector<pair<ll, int>> dt(N);
	for(int i=0; i<N; i++) cin >> dt[i].second >> dt[i].first;

	sort(dt.begin(), dt.end(), greater<>());

	ll sum = 0;
	ll kind = 0;
	vector<bool> used(N+1);
	vector<ll> removable;
	for(int i=0; i<K; i++){
		int t = dt[i].second;
		sum += dt[i].first;
		if(!used[t]){
			kind++;
			used[t] = true;
		} else {
			removable.push_back(dt[i].first);
		}
	}
	reverse(removable.begin(), removable.end());
	ll ans = sum + kind*kind;
	int k=0;
	for(int i=K; i<N; i++){
		if(k>=removable.size()) break;
		int t = dt[i].second;
		if(used[t]) continue;
		used[t] = true;
		sum += dt[i].first - removable[k];
		k++; kind++;
		ans = max(ans, sum+kind*kind);
	}

	cout << ans << endl;

	return 0;
}


Measured memory_bytes: 2432
import math

# S = list(input())
# n = int(input())
p, q, r = list(map(int, input().split()))
# a = list(map(int, input().split()))
# S = [list(map(int, input().split())) for i in range(n)]

s = p + q + r
print(s - max([p, q, r]))

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

using namespace std;

int main()
{
    int n, z, w;
    cin >> n >> z >> w;
    int array[n + 1];
    for(int i = 1;i <= n;i++)
        cin >> array[i];
    int ans = 0;
    ans = max(ans, abs(array[n] - w));
    if(n > 1)
        ans = max(ans, abs(array[n - 1] - array[n]));
    cout << ans;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
long long A[1000001],n,m,res=0;
int main()
{
cin>>n>>m;
for(int i=1;i<=m;i++)
{
cin>>A[i];
res+=A[i];
}
if(res<n)  cout<<(n-res);
if(res>n)  cout<<"-1";
if(res==n)  cout<<"0";
}

Measured memory_bytes: 3668
#include <bits/stdc++.h>
 
using namespace std;
 
#define rep(i, n) for(int i=0; i<(n); i++)
#define FOR(i, m, n) for(int i=(m);i<(n);i++)
#define sz(x) ((int)(x).size())
#define all(x) (x).begin(),(x).end()
#define SORT(x) sort((x).begin(),(x).end())
#define REVE(x) reverse((x).begin(),(x).end())
#define mp make_pair
#define pb push_back
 
typedef vector<int> VI;
typedef vector<string> VS;
typedef vector<char> VC;

typedef vector<vector<int> > VVI;
typedef pair<int, int> PII;
typedef long long LL;
typedef vector<bool> VB;
const int mod = 1000000007;
typedef vector<LL> VL;

 
int main() {
    string s;
    cin >> s;
    VL sum(s.length());
    int n = s.length();
    int p = 2019;
    
    vector<int> d(n+1);
    int ten = 1;
    for(int i = n-1; i>=0; --i) {
        int a = (s[i]-'0') * ten % p;
        d[i] = (d[i+1]+a) % p;
        ten *= 10; ten %= p; 
    }
    vector<int> cnt(p);
    LL ans = 0;
    for(int i = n;i >= 0 ; --i) {
        ans += cnt[d[i]];
        cnt[d[i]]++;
    }
    cout << ans << endl;


}

Measured memory_bytes: 6032
import java.util.Scanner;

/**
 * https://abc055.contest.atcoder.jp/tasks/arc069_b
 */
public class Main {

	public static void main(String[] args) {
		
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		char[] s = sc.next().toCharArray();
		sc.close();
		
		boolean[] ans = check(true, true, s);
		if(ans==null) ans = check(true, false, s);
		if(ans==null) ans = check(false, true, s);
		if(ans==null) ans = check(false, false, s);
		StringBuilder sb = new StringBuilder();
		if(ans!=null){
			for(boolean a:ans) sb.append( a ? 'S' : 'W');
		}else{
			sb.append("-1");
		}
		System.out.println(sb.toString());
	}
	
	static boolean[] check(boolean s1, boolean s2, char[] s){
		boolean[] ans = new boolean[s.length];
		ans[0] = s1; ans[1] = s2;
		for(int i=2; i<s.length; i++){
			if(s[i-1]=='o'){
				ans[i] = ans[i-1] ? ans[i-2] : !ans[i-2]; 
			}else{
				ans[i] = ans[i-1] ? !ans[i-2] : ans[i-2]; 
			}
		}	
		if(s[s.length-1] == 'o'){
			if((ans[s.length-1] && ans[s.length-2] != ans[0])||(!ans[s.length-1] && ans[s.length-2] == ans[0]))
				return null;
		}else{
			if((ans[s.length-1] && ans[s.length-2] == ans[0])||(!ans[s.length-1] && ans[s.length-2] != ans[0]))
				return null;
		}
		if(s[0] == 'o'){
			if((ans[0] && ans[s.length-1] != ans[1])||(!ans[0] && ans[s.length-1] == ans[1]))
				return null;
		}else{
			if((ans[0] && ans[s.length-1] == ans[1])||(!ans[0] && ans[s.length-1] != ans[1]))
				return null;
		}
		return ans;
		
	}

}

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

using namespace std;

typedef long long ll;



ifstream fin ("calafat.in");
ofstream fout ("calafat.out");

int n, r;

int main()
{
  cin >> n;
  cin >> r;
  if (n >= 10) {
    cout << r;
  }
  else
    cout << r + 100 * (10 - n);
  return 0;
}


Measured memory_bytes: 256
N, M = map(int, input().split())
mod = 10 ** 9 + 7
m = 0


def factorization(n):
    if n == 1:
        return []
    arr = []
    temp = n
    global m
    for i in range(2, int(-(-n**0.5//1))+1):
        if temp%i==0:
            cnt=0
            while temp%i==0:
                cnt+=1
                temp //= i
            arr.append((i, cnt))
            m = max(m, cnt)

    if temp!=1:
        arr.append((temp, 1))

    if arr==[]:
        arr.append((n, 1))

    return arr


fact = [1, 1]
factinv = [1, 1]
inv = [0, 1]


def cmb(n, r):
    if (r < 0) or (n < r):
        return 0
    r = min(r, n - r)
    return fact[n] * factinv[r] * factinv[n - r] % mod


for i in range(2, 2 * N + 2 * m + 10):
    fact.append((fact[-1] * i) % mod)
    inv.append((-inv[mod % i] * (mod // i)) % mod)
    factinv.append((factinv[-1] * inv[-1]) % mod)


A = factorization(M)
ans = 1

for (key, value) in A:
    ans *= cmb(value + N - 1, value)
    ans %= mod

print(ans)

Measured memory_bytes: 81072
#include <iostream>
#include <cmath>
#include <cstdio>
using namespace std;
#define PI 3.1415926535

const int N = 200005;
int q[N];

int main(){
    int n;
    cin >> n;
    for(int i = 0; i < n - 1; i ++){
        int t;
        cin >> t;
        q[t] += 1;
    }
    for(int i = 1; i <= n; i ++)
        cout << q[i] << endl;
    return 0;
}

Measured memory_bytes: 3972
#include <bits/stdc++.h>
#define all(vec) vec.begin(),vec.end()
using namespace std;
using ll=long long;
using P=pair<ll,ll>;
const ll INF=1LL<<30;
const ll LINF=1LL<<61;
const double eps=1e-9;
const ll MOD=1e9+7;
int main(){
    int n,a,b,c;cin>>n>>a>>b>>c;
    cout<<n-(a+b-c)<<endl;
}



Measured memory_bytes: 3092
// Created by sz
#include <bits/stdc++.h>
using namespace std;

const int N = 1e5 + 5;


int main(){
#ifdef LOCAL
    freopen("./input.txt", "r", stdin);
#endif
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    
    int n,k;
    cin>>n>>k;
    string s;
    cin>>s;
    
    vector<int> st(n), t(n);
    
    int num_of_gap = 0;
    
    int start = 0;
    for (int i = 0; i < n; i++){
        if(s[i] == '0'){
            if(start==0){
                start = 1;
                num_of_gap++;
                st[num_of_gap] = t[num_of_gap] = i;
            }
            else{
                t[num_of_gap] = i;
            }
        }else{
            start = 0;
        }
    }
    
    if(num_of_gap<=k){cout<<n<<endl;return 0;}
    
    
    int ans = 0;
    for (int i = 1; i+k -1<= num_of_gap; i++){
        int cur_ans =(i+k>num_of_gap?n: st[i+k]) - t[i-1] -1;
        if(i==1)cur_ans+=1;
        ans = max(ans, cur_ans);
    }
    cout<<ans<<endl;
    
    
    
    return 0;
}


Measured memory_bytes: 1232
//agrawal117
//chahatagrawal117
#include<bits/stdc++.h>
#define endl '\n'
#define mod 1000000007
typedef long long int ll;
using namespace std;
#define MAX 100005
int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    ll a,b, c;  cin>>a>>b>>c;
    swap(a,b);
    swap(a,c);
    cout<<a<<" "<<b<<" "<<c<<endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <vector>
#include <deque>
#include <queue>
#include <list>
#include <stack>
#include <string>
#include <tuple>
#include <functional>
#include <numeric>
#include <cmath>
#include <iomanip>
#include <map>
#include <random>
#include <cstdlib>
//#include "toollib.h"
//#include "puzzle.h"
#define INT_MAX 2147483647
#define Loop(i, n) for(int i = 0; i < (int)n; i++)
#pragma warning (disable:4018)
#pragma warning (disable:4244)
#pragma warning (disable:4996)

using namespace std;
typedef long long int lint;


//***** Main Program *****

vector<bool> dictionary((int)pow(4, 12), false);

int main() {
	int n;
	cin >> n;
	Loop(i, n) {
		char cquery[10], cword[15];
		scanf("%s %s", cquery, cword);
		lint j = 0, k = 1, key = 0;
		while (cword[j] != '\0') {
			if (cword[j] == 'A') key += 1 * k;
			else if (cword[j] == 'T') key += 2 * k;
			else if (cword[j] == 'G') key += 3 * k;
			else key += 4 * k;
			k *= 4;
			j++;
		}
		if (cquery[0] == 'i') {
			dictionary[key - 1] = true;
		}
		else {
			bool judge = dictionary[key - 1];
			if (judge) printf("yes\n");
			else printf("no\n");
		}
	}
	return 0;
}

Measured memory_bytes: 4772
#include<iostream>
#include<stdio.h>
using namespace std;
int main(){
	int a,b;
	char op;
	while(1){
	cin>>a>>op>>b;
	if(op=='+'){
		cout<<a+b<<endl;
	}
	else if(op=='-'){
		cout<<a-b<<endl;
	}
	else if(op=='*'){
		cout<<a*b<<endl;
	}
	else if(op=='/'){
		cout<<a/b<<endl;
	}
	else if(op=='?'){
		break;
	}

	}
	return 0;
}


Measured memory_bytes: 3104
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <set>
#include <queue>
#include <stack>
#include <tuple>
#include <cmath>
#include <iomanip>
#include <map>
#include <stdio.h>
#include <cstring> //memset(dp,0,sizeof(dp))
#include <functional>
#define ll long long
#define rep(i,n) for(int i=0;i<(n);i++)
#define rrep(i,n) for(int i=n-1;i>=0;i--)
#define fi first
#define se second
#define pb push_back
#define ALL(a) (a).begin(),(a).end()
using namespace std;
template<typename T1,typename T2> inline void chmin(T1 &a,T2 b){if(a>b) a=b;}
template<typename T1,typename T2> inline void chmax(T1 &a,T2 b){if(a<b) a=b;}
typedef pair<int,int> P;
typedef pair<ll,ll> Pll;
//小数点以下　cout << fixed << setprecision(10) << num << endl;
//桁数はlog10(mid)でやれ　log(mid)/log(10)はWA
//long*long<0で判定するな
//開区間と閉区間
//アルファベットが何番目かは x=s[i]-'a'
//bfsはmain()内で　rep(i,h)rep(j,w)rep(i,4)でバグ
//切り上げ：(a+(b-1))/b
//32bit以上は 1ull<<j
// map 初期値0 for(auto itr=mp.begin();itr!=mp.end();++itr) itr->fi itr->se で全探索
// for(auto u:mp) u.fi u.se も可能
//n個のgcd,lcmは一つずつみて更新していく
//大きな数を扱うときは素因数分解した形で持っておく
// (l/a[i]) = l*powmod(a[i],MOD-2)%MOD;
//auto itr=lower_bound(ALL(a),key) a[itr-a.begin()]

signed main(){
    int n,m; cin >> n >> m;
    priority_queue<ll> pq1;
    priority_queue<ll> pq2;
    priority_queue<ll> pq3;
    priority_queue<ll> pq4;
    priority_queue<ll> pq5;
    priority_queue<ll> pq6;
    priority_queue<ll> pq7;
    priority_queue<ll> pq8;
    rep(i,n){
        ll x,y,z; cin >> x >> y >> z;
        pq1.push(x+y+z); pq2.push(-x+y+z); pq3.push(x-y+z); pq4.push(x+y-z);
        pq5.push(-x-y-z); pq6.push(x-y-z); pq7.push(-x+y-z); pq8.push(-x-y+z);
    }
    vector<ll> ans(8,0);
    rep(i,m){
        ans[0]+=pq1.top(); pq1.pop();
        ans[1]+=pq2.top(); pq2.pop();
        ans[2]+=pq3.top(); pq3.pop();
        ans[3]+=pq4.top(); pq4.pop();
        ans[4]+=pq5.top(); pq5.pop();
        ans[5]+=pq6.top(); pq6.pop();
        ans[6]+=pq7.top(); pq7.pop();
        ans[7]+=pq8.top(); pq8.pop();
    }
    sort(ALL(ans));
    cout << ans[7] << endl;
}


Measured memory_bytes: 384
#include"bits/stdc++.h"
using namespace std;

#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define rep3(i,m,n) for(int (i)=m;(i)<=(n);(i)++)
#define rep3rev(i,m,n) for(int (i)=m;(i)>=(n);(i)--)
#define all(a) (a.begin()),(a.end())
#define rall(a) (a.rbegin()),(a.rend())
#define fi first
#define se second

typedef long long ll;
typedef vector<int> vi;
typedef vector<vector<int>> vvi;
typedef pair<int, int> pii;

void Main()
{
	int n, k;
	cin >> n >> k;
	cout << ((n-1)+(k-2))/(k-1) << endl;
	return;
}

int main()
{
	cin.tie(nullptr);
	ios_base::sync_with_stdio(false);
	cout << fixed << setprecision(15);
	Main();
	return 0;
}

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

vector<ll> ans;
vector<vector<int>> node;

void score(int now, int parent=-1) {
    if (parent != -1) {
        ans[now] += ans[parent];
    }
    rep(i, node[now].size()) {
        if (node[now][i] == parent) continue;
        score(node[now][i], now);
    }
}

void solve() {
    int n, q;
    cin >> n >> q;
    ans.resize(n);
    node.resize(n);

    rep(i, n-1) {
        int a, b;
        cin >> a >> b;
        a--; b--;
        node[a].push_back(b);
        node[b].push_back(a);
    }
    vector<int> p(q), x(q);
    rep(i, q) {
        cin >> p[i] >> x[i];
        p[i]--;
        ans[p[i]] += x[i];
    }

    score(0);
    rep(i, n) {
        if (i == 0) {
            cout << ans[i];
        } else {
            cout << " " << ans[i];
        }
    }
    cout << endl;
}

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


Measured memory_bytes: 25856
import sys
import numpy as np

read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

def main(XYP):
    X, Y, P = XYP[::3], XYP[1::3], XYP[2::3]
    N = len(X)
    dp_X = np.empty((1 << N, N), np.int64)  # 建設、人 -> Xコスト
    dp_X[0] = np.abs(X) * P
    for n in range(N):
        B = 1 << n
        dp_X[B:2 * B] = np.minimum(dp_X[:B], np.abs(X - X[n]) * P)

    dp_Y = np.empty((1 << N, N), np.int64)  # 建設、人 -> Xコスト
    dp_Y[0] = np.abs(Y) * P
    for n in range(N):
        B = 1 << n
        dp_Y[B:2 * B] = np.minimum(dp_Y[:B], np.abs(Y - Y[n]) * P)

    popcount = np.zeros(1 << N, np.int64)
    for n in range(N):
        popcount[1 << n:1 << n + 1] = popcount[:1 << n] + 1

    INF = 10**18
    ans = np.full(N + 1, INF, np.int64)
    for s in range(1 << N):
        size = popcount[s]
        t = s
        while True:
            u = s ^ t
            cost = (np.minimum(dp_X[t], dp_Y[u])).sum()
            ans[size] = min(ans[size], cost)
            if t == 0:
                break
            t = (t - 1) & s
    return ans

if sys.argv[-1] == 'ONLINE_JUDGE':
    import numba
    from numba.pycc import CC
    i8 = numba.int64
    cc = CC('my_module')

    def cc_export(f, signature):
        cc.export(f.__name__, signature)(f)
        return numba.njit(f)

    main = cc_export(main, (i8[:], ))
    cc.compile()

from my_module import main

N = int(readline())
XYP = np.array(read().split(), np.int64)

ans = main(XYP)
print('\n'.join(map(str, ans.tolist())))

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

int main() {
  int n;
  cin>>n;
  vector<int>a(n+1),b(n);
  for(int i=0;i<n+1;i++)cin>>a[i];
  for(int i=0;i<n;i++)cin>>b[i];
  long long kotae=0;
  for(int i=n;i>=1;--i){
    //cout<<b[i-1]<<" "<<a[i]<<" "<<a[i-1]<<endl;
    if(b[i-1]>=a[i]){
      b[i-1]-=a[i];
      kotae+=a[i];
      if(b[i-1]>=a[i-1]){
        kotae+=a[i-1];
        a[i-1]=0;
      }else{
        kotae+=b[i-1];
        a[i-1]-=b[i-1];
      }
    }else{
      kotae+=b[i-1];
    }
  }
  cout<<kotae<<endl;
  return 0;
}

Measured memory_bytes: 1024
#include <iostream>
#include <vector>
#include <algorithm>
 
#define rep(i, n) for(int i = 0; i < (n); ++i)
 
using namespace std;

const int inf = 1e7;

void to_coord(int x, int& p, int& q){
    int l = 0;
    int r = 500;
    while(r - l > 1){
        int m = (l + r) / 2;
        if(x <= 4 * m * m){
            r = m;
        }
        else{
            l = m;
        }
    }
    int a = 4 * r * r;
    int b = a - 2 * r + 1;
    int c = b - 2 * r + 1;
    int d = c - 2 * r + 1;
    if(x >= b){
        p = 500 - r;
        q = 500 - r + a - x;
    }
    else if(x >= c){
        p = 500 - r + b - x;
        q = 500 + r - 1;
    }
    else if(x >= d){
        p = 500 + r - 1;
        q = 500 - r + (x - d);
    }
    else{
        p = 500 + r - 1 - (d - x);
        q = 500 - r;
    }
}

int from_coord(int p, int q){
    int cp = p < 500 ? p - 500 : p - 499;
    int cq = q < 500 ? q - 500 : q - 499;
    int r = max(abs(cp), abs(cq));
    int a = 4 * r * r;
    int b = a - 2 * r + 1;
    int c = b - 2 * r + 1;
    int d = c - 2 * r + 1;
    int s = 500 - r;
    int t = 500 + r - 1;
    if(cp == -r){
        return a + s - q;
    }
    else if(cp == r){
        return d + q - s;
    }
    else if(cq == -r){
        return d + p - t;    
    }
    else{
        return b + s - p;
    }
}

bool prime[1000001];

void enum_prime(){
    fill_n(prime, 1000001, true);
    prime[0] = prime[1] = false;
    rep(i, 1000001){
        if(prime[i]){
            for(int j = 2 * i; j <= 1000000; j += i){
                prime[j] = false;
            }
        }
    }
}

int m, n;
bool z[1000][1000];
int dp[1000][1000];

int main(){
    enum_prime();

    while(1){
        cin >> m >> n;

        if(m == 0){
            break;
        }

        rep(i, 1000){
            fill_n(z[i], 1000, 0);
            fill_n(dp[i], 1000, -inf);
        }

        rep(i, m + 1){
            if(prime[i]){
                int p, q;
                to_coord(i, p, q);
                z[p][q] = true;
            }
        }

        int s, t;
        to_coord(n, s, t);
        dp[s][t] = z[s][t];
        for(int i = s + 1; i < 1000; ++i){
            rep(j, 1000){
                int a = j > 0 ? dp[i - 1][j - 1] : -inf;
                int c = j + 1 < 1000 ? dp[i - 1][j + 1] : -inf;
                dp[i][j] = max(dp[i - 1][j], max(a, c)) + z[i][j];
            }
        }

        int ans = *max_element(dp[999], dp[999] + 1000);
        cout << ans << ' ';

        int p = 0;
        rep(i, 1000){
            rep(j, 1000){
                if(dp[i][j] == ans && z[i][j]){
                    p = max(from_coord(i, j), p);
                }
            }
        }
        cout << p << endl;
    }
    return 0;
}

Measured memory_bytes: 8964
#include<bits/stdc++.h>
#define ll long long int
#define ld long double
#define pb push_back
using namespace std;

void solve()
{
    int x;
     cin >> x;
     if(x>=30)
        cout << "Yes" << endl;
     else
        cout << "No" << endl;
}

int main()
{
    int t=1;
    //cin >> t;
    while(t--)
    solve();

    return 0;
}



Measured memory_bytes: 3608
using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace aizu1
{
    public class Solution
    {
        public static void Main(string[] args)
        {
            string com;
            int[] A = new int[2000000];
            int H=0;
            StringBuilder builder=new StringBuilder();
            while ((com = Console.ReadLine())!="end")
            {
                var coms = com.Split(' ');
                switch (coms[0])
                {
                    case "insert": Insert(A, int.Parse(coms[1]),ref H);
                        break;
                    case "extract": Extract(A, ref H, builder);
                        break;
                    default: break;
                }
            }
            Console.Write(builder);
        }

        public static void Insert(int[] A, int num, ref int H)
        {
            A[H++]=num;
            HeapUp(A,H-1);
        }

        public static void Extract(int[] A, ref int H, StringBuilder builder)
        {
            if (H > 0)
            {
                builder.Append(A[0]).Append("\n");
                int tmp = A[0];
                A[0] = A[--H];
                A[H] = tmp;
                Maxify(A, 0, H);
            }
        }

        public static void Maxify(int[] A, int i, int H)
        {
            int largest;
            int tmp;
            int left = 2 * i + 1;
            int right = 2 * i + 2;
            if (left < H && A[left] > A[i]) largest = left;
            else largest = i;
            if (right < H && A[right] > A[largest]) largest = right;

            if (largest != i)
            {
                tmp = A[largest];
                A[largest] = A[i];
                A[i] = tmp;
                Maxify(A,largest,H);
            } 
        }
        public static void HeapUp(int[] A, int H)
        {
            int parent = (H-1) / 2;
            int tmp;
            while (parent >= 0)
            {
                if (A[H] > A[parent])
                {
                    tmp = A[H];
                    A[H] = A[parent];
                    A[parent] = tmp;
                    H = parent;
                    parent = (parent - 1) / 2;
                }
                else break;
            }
        }
    }
}

Measured memory_bytes: 38864
dic = {}
cou = 0
lop = int(input())
for i in range(lop):
    N = input()
    N = list(N)
    N.sort()
    N = "".join(N)
    if N in dic:
        dic[N] += 1
    else:
        dic[N] = 1
lis = list(dic.values())
print(sum(list(map(lambda x: int((x * (x - 1)) / 2), lis))))

Measured memory_bytes: 17920
#include <iostream>
#include <cstdio>
#include <algorithm>
using namespace std;
int main(){
    int N;
    cin>>N;
    int a[1000];
    for (int i=0; i<N; i++)cin>>a[i];
    
    sort(a, a+N, greater<int>());
    double ans=0;
    for (int i=0; i<N-1; i++) {
        if(i==0)ans=max(ans,(double)(a[2]+a[3])/(a[0]-a[1]));
        else if(i==1)ans=max(ans,(double)(a[2]+a[3])/(a[1]-a[2]));
        else ans=max(ans,(double)(a[0]+a[1])/(a[i]-a[i+1]));
    }
    printf("%0.5f\n",ans);
    return 0;
}

Measured memory_bytes: 3268
#include<bits/stdc++.h>
using namespace std;
#define pb push_back
#define mp make_pair
#define ll long long
#define forn(a,b,c) for(int a=b;a<=c;a++)
#define ford(a,b,c) for(int a=b;a>=c;a--)
#define f first
#define s second
typedef pair<int,int> pii;
const int N=1e5+5;
int n,mod,down[N],up[N];
vector<int>g[N],pref[N],suf[N];
int add(int x, int y){ x+=y;if(x>=mod) x-=mod;return x;}
int sub(int x, int y){ x-=y;if(x<0) x+=mod;return x;}
int mul(int x, int y){ x=(ll)x*y%mod;return x;}
void fix(int x){
    for(auto& y:g[x]){
        g[y].erase(find(g[y].begin(),g[y].end(),x));
        fix(y);
    }
}
void dfs(int x){
    down[x]=1;
    for(auto&y:g[x]){
        dfs(y);
        down[x]=mul(down[x],down[y]+1);
    }
    int sz=g[x].size();
    pref[x].resize(sz+1);
    suf[x].resize(sz+1);
    pref[x][0]=suf[x][sz]=1;
    forn(i,0,sz-1){
        pref[x][i+1]=mul(pref[x][i],1+down[g[x][i]]);
    }
    ford(i,sz-1,0){
        suf[x][i]=mul(suf[x][i+1],1+down[g[x][i]]);
    }
}
void dfs1(int x){
    for(int i=0;i<g[x].size();i++){
        int y=g[x][i];
        up[y]=mul(up[x],mul(pref[x][i],suf[x][i+1]));
        up[y]=add(up[y],1);
        dfs1(y);
    }
}
int main()
{
    scanf("%d%d",&n,&mod);
    forn(i,1,n-1){
        int u,v;
        scanf("%d%d",&u,&v);
        g[u].pb(v);
        g[v].pb(u);
    }
    fix(1);
    dfs(1);
    up[1]=1;
    dfs1(1);
    forn(i,1,n){
        printf("%d\n",mul(up[i],down[i]));
    }
    return 0;
}


Measured memory_bytes: 22784
#<B>
N = int(input())
A = list(map(int,input().split()))
B = list(map(int,input().split()))
C = list(map(int,input().split()))

ans = 0
for i in A:
    ans += B[i - 1]

for i in range(N - 1):
    if A[i + 1] == A [i] + 1:
        ans += C[A[i] - 1]

print(ans)
    
    

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

using namespace std;

int main()
{
  string s, t, u;
  int a, b;
  cin >> s >> t >> a >> b >> u;
  if (s == u)
  {
    a--;
  }
  else
  {
    b--;
  }
  cout << a << " " << b << endl;
  return 0;
}

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

using namespace std;
typedef long long LL;
const int MaxN = 1e5;




int a, b, k;
int main()
{
	cin >> a >> b >> k;
	if(b - a + 1 <= 2 * k)
	{
		for(int i = a;i <= b;i++)
		{
			cout << i << endl;
		}
	}
	else
	{
		for(int i = a;i < a + k;i++)
		{
			cout << i << endl;
		}
		for(int i = b - k + 1;i <= b ;i++)
		{
			cout << i << endl;
		}
	}
	return 0;
}

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

int main()
{
  string S;
  cin >> S;
  if (S.at(2) == S.at(3) && S.at(4) == S.at(5))
  {
    cout << "Yes" << endl;
  }
  else
  {
    cout << "No" << endl;
  }
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <queue>
#include <string>
#include <map>
#include <set>
#include <tuple>
#include <deque>
#include <numeric>
#include <bitset>
#include <iomanip>
#include <cassert>
#include <chrono>
#include <random>
#include <limits>
#include <iterator>
#include <functional>
#include <sstream>
using namespace std;

#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)

typedef long long ll;
typedef pair<int, int> P;
typedef pair<int, double> Pid;
typedef pair<double, int> Pdi;
const double PI = 3.1415926535897932;   // acos(-1)
const double EPS = 1e-15;
const int INF = 1001001001;
const int mod = 1e+9 + 7;

#define chadd(x, y) x = (x + y) % mod

int n, m;
vector<int> graph[100005];
vector<vector<ll>> dp;

ll memo_rec(int u, int parent = -1){
    ll res = 1;
    for(int i = 0; i < graph[u].size(); ++i){
        if(graph[u][i] != parent){
            dp[u][i] = memo_rec(graph[u][i], u);
            (res *= (dp[u][i] + 1)) %= m;
        }
    }
    return res;
}

void dfs(int u, ll add, int parent = -1){
    for(int i = 0; i < graph[u].size(); ++i){
        if(graph[u][i] == parent){
            dp[u][i] = add;
            break;
        }
    }

    int sz = graph[u].size();
    vector<ll> prefix(sz), suffix(sz);
    for(int i = 0; i < sz; ++i){
        suffix[i] = ((prefix[i] = (dp[u][i] + 1)) %= m);
    }
    for(int i = 1; i < sz; ++i){
        (prefix[i] *= prefix[i - 1]) %= m;
    }
    for(int i = sz - 2; i >= 0; --i){
        (suffix[i] *= suffix[i + 1]) %= m;
    }

    for(int i = 0; i < sz; ++i){
        if(graph[u][i] == parent) continue;

        ll add_c = 1;
        if(i != 0)  (add_c *= prefix[i - 1]) %= m;
        if(i != sz - 1) (add_c *= suffix[i + 1]) %= m;
        dfs(graph[u][i], add_c, u);
    }
}

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

    cin >> n >> m;
    for(int i = 0; i < n-1; ++i){
        int x, y;
        cin >> x >> y;
        --x, --y;
        graph[x].push_back(y);
        graph[y].push_back(x);
    }

    dp.resize(n);
    for(int v = 0; v < n; ++v){
        dp[v].assign(graph[v].size(), -1);
    }
    memo_rec(0);
    dfs(0, 0);

    for(int v = 0; v < n; ++v){
        ll ans = 1;
        for(ll add : dp[v]){
            (ans *= (add + 1)) %= m;
        }
        cout << ans << "\n";
    }
}

Measured memory_bytes: 22272
#include<iostream>
using namespace std;
int main(){
  int n;
  cin>>n;
  if(n>17)cout<<"Yes"<<endl;
  else{
    if(n%4==0||n%7==0)cout<<"Yes"<<endl;
    else if(n==11||n==15)cout<<"Yes"<<endl;
    else cout<<"No"<<endl;
  }
}

Measured memory_bytes: 256
import sys
import itertools
# import numpy as np
import time
import math
import heapq
from collections import defaultdict
sys.setrecursionlimit(10 ** 7)
 
INF = 10 ** 9 + 7
MOD = 10 ** 9 + 7
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

# map(int, input().split())

N, K = map(int, input().split())
A = list(map(int, input().split()))

S = []
T = []
for a in A:
    if a < 0:
        T.append(a)
    else:
        S.append(a)

ls = len(S)
lt = len(T)
ok = False

if ls > 0:
    if N == K:
        ok = lt % 2 == 0
    else:
        ok = True
else:
    ok = K % 2 == 0

ans = 1
if not ok:
    A = sorted(A, key=lambda x: abs(x))
    for a in A[:K]:
        ans *= a
        ans %= MOD
else:
    S = sorted(S)
    T = sorted(T, reverse=True)
    if K % 2 == 1: # if K is odd, the answer has at least one positive number.
        ans *= S.pop()
        ans %= MOD
    p = []
    # the num of negatives must be even, so positives must do the same
    # thus, we can pop 2 items at one time.
    while len(S) >= 2:
        x = S.pop()  
        y = S.pop()
        p.append(x * y)
    while len(T) >= 2:
        x = T.pop()  
        y = T.pop()
        p.append(x * y)
    p = sorted(p, reverse=True)
    for i in range(K // 2):
        ans *= p[i]
        ans %= MOD
print(ans % MOD)

Measured memory_bytes: 32348
#include<bits/stdc++.h>
using namespace std;
#define ll  long long
#define endl '\n'
#define FASTINOUT ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
const ll mod = 1000000007;
const double PI = 3.141592653589793238463;
const int N=1e7+9;
int main()
{
    FASTINOUT;
    int h,w,n;
    cin>>h>>w>>n;
    cout<<n/max(h,w)+(n%max(h,w)!=0)<<endl;
    return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<queue>
#include<map>
#include<math.h>
#include<iomanip>
#include<set>
#include<numeric>
#include<cstring>
#include<cstdio>
#include<functional>

#define REP(i, n) for(int i = 0;i < n;i++)
#define REPR(i, n) for(int i = n;i >= 0;i--)
#define FOR(i, m, n) for(int i = m;i < n;i++)
#define FORR(i, m, n) for(int i = m;i >= n;i--)
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
#define REVERSE(v,n) reverse(v,v+n);
#define VREVERSE(v) reverse(v.begin(), v.end());
#define ll long long
#define pb(a) push_back(a)
#define INF 999999999
#define m0(x) memset(x,0,sizeof(x))
#define fill(x,y) memset(x,y,sizeof(x))
#define int long long

using namespace std;


int dy[4] = { 0,0,1,-1 };
int dx[4] = { 1,-1,0,0 };
int dxx[8] = { 0,0,1,1,1,-1,-1,-1 };
int dyy[8] = { 1,-1,0,1,-1,0,1,-1 };


const int MOD = 1000000007;
const int MAX = 100010;

ll inv[MAX];

ll gcd(ll x, ll y) {
	ll m = max(x, y), n = min(x, y);
	if (m%n == 0)return n;
	else return gcd(m%n, n);
}
ll lcm(ll x, ll y) {
	return x / gcd(x, y)*y;
}

ll myPow(ll x, ll n, ll m) {
	if (n == 0)
		return 1;
	if (n % 2 == 0)
		return myPow(x * x % m, n / 2, m);
	else
		return x * myPow(x, n - 1, m) % m;
}

long long nCr(int n, int r) {
	if (r > n / 2) r = n - r; // because C(n, r) == C(n, n - r)
	long long ans = 1;
	int i;

	for (i = 1; i <= r; i++) {
		ans *= n - r + i;
		ans /= i;
	}

	return ans;
}

void makeInv() {
	inv[1] = 1;
	FOR(i, 2, MAX) {
		inv[i]= MOD - inv[MOD%i] * (MOD / i) % MOD;
	}
}

ll FactMod(int n, int m) {
	ll x = 1;
	FOR(i, 1, n + 1) {
		x *= i;
		x %= m;
	}
	return x;
}

int cum[MAX];
int Ex[MAX];
int A[MAX];
signed main() {
	int N; cin >> N;
	FOR(i,1, N+1) {
		cin >> A[i];
	}
	makeInv();
	cum[0] = 0;
	cum[1] = 1;
	ll fact = FactMod(N, MOD);
	FOR(i, 2, MAX) {
		cum[i] = (cum[i - 1] + inv[i]) % MOD;
	}
	ll ans = 0;
	FOR(i,1, N + 1) {
		Ex[i] = cum[i] - cum[0] + cum[N - i + 1] - cum[1];
		Ex[i] %= MOD;
	}
	
	FOR(i, 1, N + 1) {
		ans += Ex[i] * A[i];
		ans %= MOD;
	}
	ans *= fact;
	ans %= MOD;
	cout << ans << endl;
}




Measured memory_bytes: 3328
#include <stdio.h>

int main(){
    long a, v, b, w, t;

    scanf("%ld %ld %ld %ld %ld", &a, &v, &b, &w, &t);
    
    if (a < b) {
        long m1 = a + v * t;
        long m2 = b + w * t;
        if (m1 >= m2) {
            printf("YES");
        } else {
            printf("NO");
        }
    } else {
        long m1 = a - v * t;
        long m2 = b - w * t;
        if (m1 <= m2) {
            printf("YES");
        } else {
            printf("NO");
        }
    }
}


Measured memory_bytes: 2112
#!/usr/bin/env python3
import sys
input = sys.stdin.readline
from collections import Counter

n = int(input())
a = [int(item) for item in input().split()]
a.sort()

cnt = Counter(a)
if cnt[1] > 1:
    print(0)
    exit()
if cnt[1] == 1:
    print(1)
    exit()

MAX_SIZE = 10**6 + 10
is_divisible = [True] * MAX_SIZE 
ans = 0
for item in a:
    if is_divisible[item]:
        if cnt[item] == 1:
            ans += 1
        for i in range(MAX_SIZE):
            if i * item >= MAX_SIZE:
                break
            is_divisible[i * item] = False
    else:
        continue

print(ans)

Measured memory_bytes: 123312
#include <iostream>
#include <algorithm>
#include <iomanip>
#include <string>
#include <vector>
#include <math.h>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>
#define PI 3.14159265359
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> pai;
typedef pair<ll, ll> pal;
const int MOD = 1e9+7;
const ll LLINF = 1e18;


int main(){
	string s;
	cin >> s;
	cout << "2018" << s.substr(4, 6) << endl;
	return 0;
}



Measured memory_bytes: 3604
n = input()
str = input()
nums = str.split()
num_dict = {}
for num in nums:
    if num in num_dict:
        num_dict[num] += 1
    else:
        num_dict[num] = 1
result = 0
for k, v in num_dict.items():
    if int(k) > v:
        result += v
    elif int(k) < v:
        result += (v - int(k))

print(result)


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

vector<int> to[200005];
vector<int> ans;

void dfs(int v,int p=-1){
    for(int u:to[v]){
        if(u==p) continue;
        ans[u]+=ans[v];
        dfs(u,v);
    }
}

int main(){
    int n,q;
    cin>>n>>q;
    for(int i=0;i<n-1;i++){
        int a,b;
        cin>>a>>b;
        --a; --b;
        to[a].push_back(b);
        to[b].push_back(a);
    }
    ans.resize(n);
    for(int i=0;i<q;i++){
        int p,x;
        cin>>p>>x;
        --p;
        ans[p]+=x;
    }
    dfs(0);
    for(int i=0;i<n;i++){
        cout<<ans[i]<<' ';
    }
    cout<<endl;
    return 0;
}




Measured memory_bytes: 23424
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
const ll MOD = 1000000007;
const ld PI = acos(-1);  
const ld EPS = 0.0000000001;
#define REP(i, n) for(ll i=0; i<(ll)(n); i++)
#define REPD(i, n) for(ll i=n-1; 0<=i; i--)
#define FOR(i, a, b) for(ll i=a; i<(ll)(b); i++)
#define FORD(i, a, b) for(ll i=a; (ll)(b)<=i; i--)
#define ALL(x) x.begin(), x.end()
#define MAX(x) *max_element(ALL(x))
#define MIN(x) *min_element(ALL(x))


int main(){
    int h, w;   cin >> h >> w;
    vector<vector<int>> L(h, vector<int>(w, 0)), 
        R(h, vector<int>(w, 0)), D(h, vector<int>(w, 0)), U(h, vector<int>(w, 0)); 

    vector<vector<char>> g(h, vector<char>(w));
    REP(i, h)   REP(j, w)   cin >> g[i][j];

    REP(i, h){
        int tmp=0;
        REP(j, w){
            if(g[i][j]=='#') tmp=0;
            else tmp += 1;
            L[i][j]  = tmp;
        }
        tmp=0;
        REPD(j, w){
            if(g[i][j]=='#') tmp=0;
            else tmp += 1;
            R[i][j]  = tmp;
        }
    }
    REP(j, w){
        int tmp=0;
        REP(i, h){
            if(g[i][j]=='#') tmp=0;
            else tmp += 1;
            D[i][j] = tmp;
        }
        tmp=0;
        REPD(i, h){
            if(g[i][j]=='#') tmp=0;
            else tmp += 1;
            U[i][j] = tmp;
        }
    }
    int ans=0;
    REP(i, h)   REP(j,w) ans = max(ans, L[i][j]+U[i][j]+D[i][j]+R[i][j]-3);
    cout << ans << endl;
}

Measured memory_bytes: 67072
#include<cstdio>
#include<algorithm>
#include<functional>
using namespace std;
int main(void)
{
	int i,j,n,m,max,mx,s;
	int a[1001],b[1001],jun[1001];
	max=-1;
	scanf("%d %d",&n,&m);
	for(i=1;i<=n;i++){
		scanf("%d",&a[i]);
		jun[i]=0;
	}
	for(i=1;i<=m;i++){
		scanf("%d",&b[i]);
	}
	for(i=1;i<=m;i++){
		max=-1;
		for(j=1;j<=n;j++){
			if(b[i]>=a[j]){
				if(max<a[j]){
					max=a[j];
					jun[j]++;
					break;
				}
			}
		}
	}
	mx=-1;
	for(i=1;i<=n;i++){
		if(mx<jun[i]){
			mx=jun[i];
			s=i;
		}
	}
	printf("%d\n",s);
	return 0;
}
	

Measured memory_bytes: 1036
import math

n = int(input())
X = []
Y = []
for _ in range(n):
    x,y = map(int,input().split())
    X.append(x)
    Y.append(y)

ans = 0    
for i in range(n):
    for j in range(n):
        tmp = math.sqrt((X[i]-X[j])**2+(Y[i]-Y[j])**2)
        ans += tmp

print(ans/n)

Measured memory_bytes: 3064
N,A,B,C,D = map(int,input().split())
S = input()

goal = max(C,D)
if '##' in S[A-1:goal]:
  print("No")
  exit()

ok = True
# 追い越す必要がある
if D < C:
  # 間に3マスあきがない or B,Dの間に3マス空きがない
  if ('...' in S[B-1:D]) or ('...' in S[B-2:B+1]) or ('...' in S[D-2:D+1]):
    ok = True
  else:
    ok = False
# 必要がない場合は問題ない

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



Measured memory_bytes: 3572
#include<bits/stdc++.h>
#define mxn 1000010
#define LL long long
#define pb push_back
#define ppb pop_back
#define pf push_front
#define pii pair<int,int> 
#define mp make_pair
#define fr first
#define sc second
#define node(a,b,c) (node){a,b,c}
using namespace std;
const int inf=1e9,mod=1e9+7;
int n,m,sl,fh,res,ans,a[15][15];
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 main()
{
	n=rd();m=rd();int x;
	for(int i=1;i<=n;++i)
		for(int j=1;j<=m;++j)
			a[i][j]=rd();
	for(int i=1;i<=n;++i)
		for(int j=i+1;j<=n;++j)
		{
			for(int k=1;k<=m;++k) x=abs(a[i][k]-a[j][k]),res+=x*x;
			x=sqrt(res);if(x*x==res) ans++;res=0;
		}
	printf("%d\n",ans);
	return 0;
}

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

const int MAXN = 105;

char str[MAXN][MAXN];
int n, m;
int t[27];

int main()
{
	scanf("%d%d", &n, &m);
	for (int i = 1; i <= n; i++) {
		scanf("%s", str[i]+1);
		for (int j = 1; j <= m; j++) {
			t[str[i][j]-'a']++;
		}
	}
	int F = (n/2)*(m/2), T = (n%2==1)*(m/2)+(m%2==1)*(n/2), O = (n%2==1)*(m%2==1);
	// cerr << F << " " << T << " " << O << endl;
        for (int i = 0; i < 26; i++) 
		while (F && t[i] >= 4) t[i] -= 4, F--;
	for (int i = 0; i < 26; i++)
		while (T && t[i] >= 2) t[i] -= 2, T--;
	for (int i = 0; i < 26; i++)
		while (O && t[i] >= 1) t[i]--, O--;
	if (F == 0 && T == 0 && O == 0) puts("Yes");
	else puts("No");
	return 0;
}


Measured memory_bytes: 256
import java.util.Scanner;


public class Main {

	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);

		String wether [] = {"Sunny","Cloudy", "Rainy","Sunny"};
				
		String w = sc.next();
		
		int i=0;
		
		while(!(w.equals(wether[i]))){
			i++;
		}
		i++;
		
		System.out.println(wether[i]);

	}
}

Measured memory_bytes: 21204