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


struct givenMoney {
    double money;
    string unit;
};

int main() {
    int N; cin >> N;
    vector<givenMoney> otoshidama(N);
    for (int i = 0; i < N; i++) {
        double x; cin >> x;
        string u; cin >> u;
        otoshidama[i].money = x;
        otoshidama[i].unit = u;
    }

    double ans = 0.0;
    for (auto o : otoshidama) {
        if (o.unit == "JPY") {
            ans += o.money;
        } else {
            ans += o.money * 380000.0;
        }
    }

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

Measured memory_bytes: 256
#include <stdio.h>

int main(){
	int a, b;
	while( scanf("%d %d", &a, &b) != EOF )

	if( a > b ) {
		printf("a > b\n");
	} else if( a < b ) {
		printf("a < b\n");
	} else {
		printf("a == b\n", a, b);
	}

	return 0;
}

Measured memory_bytes: 580
#include <bits/stdc++.h>
using namespace std;
template<class T> struct rge { T b, e; };
template<class T> rge<T> range(T i, T j) { return rge<T>{i, j}; }
struct debug {
#ifdef LOCAL
	~debug(){cerr<<endl;}
	template<class T> debug& operator<<(T x){cerr<<boolalpha<<x; return *this;}
	template<class B, class C> debug& operator<<(pair<B, C> x){return *this<<"("<<x.first<<", "<<x.second<<")";}
	template<class T> debug& operator<<(rge<T> x){*this<<"[";for(auto it=x.b;it!=x.e;it++){*this<<", "+2*(it==x.b)<<*it;}return *this<<"]";}
	template<class T> debug& operator<<(vector<T> x){ return *this<<range(x.begin(),x.end());}
#else
	template<class T> debug& operator <<(const T&){return *this;}
#endif
};
#define nav(...) << "[ " << #__VA_ARGS__ ": " << (__VA_ARGS__) << " ] "
using ll = long long;


int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    
    int n;
    cin >> n;
    vector<int> h(n);
    for(int i = 0; i < n; i++) {
        cin >> h[i];
    }
    ll ans = 0;
    map<int, int> cnt;
    for(int i = 0; i < n; i++) {
        ans += cnt[h[i] - i];
        cnt[-h[i]-i]++;
    }
    
    cout << ans << endl;
}


Measured memory_bytes: 21104
#include <stdio.h>
#include <math.h>
#include <cmath>
#include <iostream>
#include <vector>
#include <algorithm>
#include <iterator>
#include <utility>
#include <map>
#include <unordered_map>
#include <string>

using namespace std;

#define REP(var, n)  for (decltype(n) var = 0; var < (n); var++)
#define RREP(var, n)  for (auto var = n - 1; var != static_cast<decltype(var)>(-1); var--)
#define FOR(var, a, b)  for (auto var = (a); var < (b); var++)
#define RFOR(var, a, b)  for (auto var = b - 1; var != a; var--)
#define all(c) begin(c),end(c)
#define vmax(c) *max_element(all(c))
#define vmin(c) *min_element(all(c))
 
template<typename T>
std::ostream &operator<<(std::ostream &out, const std::vector<T> &v) {
    if (!v.empty()) {
        out << '[';
        std::copy(v.begin(), v.end(), std::ostream_iterator<T>(out, ", "));
        out << "\b\b]";
    }
    return out;
}

template <typename T1, typename T2>
std::ostream &operator<<(std::ostream &out, const std::pair<T1, T2> &p) {
    out << "[" << p.first << ", " << p.second << "]";
    return out;
}

template<typename T1, typename T2>
std::ostream &operator<<(std::ostream &out, const std::map<T1, T2>& map)
{
    for (typename std::map<T1, T2>::const_iterator it = map.begin();
         it != map.end();
         ++it)
    {
        out << (*it);
    }
    return out;
}

typedef long long int ll;
typedef vector<int> vi;
typedef vector<ll> vll;

const long long INF = 0x3f3f3f3f3f3f3f3f;
const int MOD = (int)1e9 + 7;
const double EPS = 1e-9; 

// 2次元配列を作る
// vector<vi> my_vector(n, vi(m, 0));

// 多次元配列の dump
// for (auto v : my_vector) {
//     cout << v;
// }

// ll N;

auto solve() {
    int N;
    double total = 0;
    cin >> N;
    REP(i, N) {
        double v;
        string c;
        cin >> v >> c;
        // cout << v << " ,";
        // cout << c << endl;
        if (c == "JPY") {
            total = total + v;
        } else {
            total = total + v * 380000;
        }
    }
    return total;
}

int main(void){
    cin.tie(0);
    ios::sync_with_stdio(false);
    // solve();
    cout << solve();
}

Measured memory_bytes: 256
#include <cmath>
#include <cstdio>
double V[16],s,p;
int main(){
	int D,i,j,k,l;
	for(;scanf("%d",&D),D;){
		for(i=0;i<D+3;++i)scanf("%lf",V+i);
		for(i=0;i<D+3;++i){
			for(j=0;j<D+3;++j)if(j!=i){
				for(s=k=0;k<D+3;++k)if(k!=i&&k!=j){
					p=V[k];
					for(l=0;l<D+3;++l)if(l!=k&&l!=i&&l!=j)p=p*(j-l)/(k-l);
					s+=p;
				}
				if(fabs(s-V[j])>0.1)break;
			}
			if(j==D+3){
				printf("%d\n",i);
				break;
			}
		}
	}
}

Measured memory_bytes: 1072
N = int(input())
march = "MARCH"
count = [0 for i in range(5)]
for i in range(N):
    S = input()
    for j in range(5):
        if S[0] == "MARCH"[j]:
            count[j] += 1
def f(m):
    result = 0
    for i in range(5):
        result += count[i] ** m
    return result
print((f(1) ** 3 + 2 * f(3) - 3 * f(1) * f(2)) // 6)

Measured memory_bytes: 3064
#include<iostream>
#include<queue>
#include<vector>
#include<algorithm>
using namespace std;
int N,M;
vector<int>G[1<<17];
int S,T;
int d[1<<17][3];
main()
{
	cin>>N>>M;
	for(int i=0;i<M;i++)
	{
		int a,b;cin>>a>>b;a--,b--;
		G[a].push_back(b);
	}
	for(int i=0;i<N;i++)for(int j=0;j<3;j++)d[i][j]=2e9;
	cin>>S>>T;S--,T--;
	queue<pair<int,int> >P;
	P.push({S,0});
	d[S][0]=0;
	while(!P.empty())
	{
		int u=P.front().first;
		int c=P.front().second;
		P.pop();
		for(int v:G[u])
		{
			if(d[v][(c+1)%3]>d[u][c]+1)
			{
				d[v][(c+1)%3]=d[u][c]+1;
				P.push({v,(c+1)%3});
			}
		}
	}
	cout<<(d[T][0]%3==0?d[T][0]/3:-1)<<endl;
}


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

using namespace std;

typedef long long ll;

int main() {
  int n, m;
  int a1, a2;
  int s1[100], s2[100];
  int sum1, sum2;
  while(cin >> n >> m, n + m) {
    sum1 = sum2 = 0;
    a1 = a2 = 101;
    for (int i = 0; i < n; i++) {
      cin >> s1[i];
      sum1 += s1[i];
    }
    for (int i = 0; i < m; i++) {
      cin >> s2[i];
      sum2 += s2[i];
    }

    if((sum1 - sum2) % 2) {
      cout << -1 << endl;
      continue;
    }
    for (int i = 0; i < n; i++) {
      for (int j = 0; j < m; j++) {
        if((s1[i] - s2[j])*2 == sum1 - sum2 && s1[i]+s2[j] < a1+a2) {
          a1 = s1[i];
          a2 = s2[j];
        }
      }
    }
    if(a1 + a2 > 200) {
      cout << -1 << endl;
    }
    else {
      cout << a1 << ' ' << a2 << endl;
    }

  }
}

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

int main() {
  int n,m;
  cin >> n >> m;
  int a[n];
  int sum=0;
  int ca = 1;
  for (int i = 0; i < n; ++i) {
      cin >> a[i];
      sum += a[i];
  }
  sort(a, a+n, greater<>());
  double b = (double)sum  / (double)(4 * m );
  for (int i = 0; i < m; ++i) {
    
    if (a[i] < b) {
        ca = 0;
        break;
    }
  }
  if ( ca == 1) cout << "Yes" << endl;
  else cout << "No" << endl;
  
  return 0;

}

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

int main()
{
    ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);

    double  sum1=0,p,w;
    int n;
    cin>>n;
    for(int i=0;i<n;i++)
    {
        cin>>p;
        sum1=sum1+(1/p);
    }
    w=(1/sum1);
    cout<<w<<endl;
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main(){
    char s;
    cin>>s;
    if (s == 'A')
        cout << 'T'<<endl;
    else if (s == 'T')
        cout << 'A' << endl;
    else if (s == 'G')
        cout << 'C' << endl;
    else
        cout << 'G' <<endl;
}



Measured memory_bytes: 256
#include <bits/stdc++.h>
    using namespace std;
    
    typedef double dd;
    typedef long long ll;

    #define all(v) v.begin(),v.end()
    #define rall(v) v.rbegin(),v.rend()
    #define trav(i,a) for(auto i: a)
    #define ff first
    #define ss second
    #define eb emplace_back
    #define tc(t) ll t; cin>>t; while(t--)
    #define prec(n) fixed<<setprecission(n)
    #define mst(arr,value) memset(arr,value,sizeof(arr))
    #define sz(a) a.size()
    #define fio ios_base::sync_with_stdio(0);cin.tie(NULL);cout.tie(NULL);
    
    const long long inf = (long long)1e18;
    const long long M = (long long)1e9+7;
    
    #define fab(i,a,b) for(ll i=a; i<b; i++)
    #define fba(i,b,a) for(ll i=b; i>=a; i--)

    ll mpw(ll a, ll b, ll M = inf) {
        if(b == 0) return 1;
        if(b % 2 == 1) 
            return a * mpw((a * a) % M, b / 2, M) % M;
        return mpw((a * a) % M, b / 2, M);        
    } 

    string LCS(string s, ll n, string t, ll m) {
        vector<vector<int>> dp(n + 1, vector<int> (m + 1, 0));
        string lcs;
        fab(i, 1, n + 1) 
            fab(j, 1, m + 1) {
                if(s[i - 1] == t[j - 1]) 
                    dp[i][j] = dp[i - 1][j - 1] + 1;
                else dp[i][j] = max(dp[i - 1][j], dp[i][j - 1]);
            }
        int i = n, j = m;
        while(i > 0 and j > 0) {
            if(s[i - 1] == t[j - 1]) {
                lcs += s[i - 1];
                i--;
                j--;
            } else if(dp[i][j] == dp[i - 1][j]) i--;
            else j--;
        }
        return lcs;
        
    }

    int main() {
        fio

        string s, t;
        cin >> s >> t;
        string lcs = LCS(s, sz(s), t, sz(t));
        reverse(lcs.begin(), lcs.end());
        cout << lcs ;
        
        return 0;
    }

Measured memory_bytes: 38432
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, srt, end) for (long long i = (srt); i < (long long)(end); i++)
#define VL vector<ll>
#define VS vector<string>
#define VB vector<bool>
#define VP vector<pair<ll,ll>>
#define VVL vector<vector<ll>>
#define VVP vector<vector<pair<ll,ll>>>
#define PL pair<ll,ll>
#define ALL(v) (v).begin(), (v).end()
ll d1[4] = {1, -1, 0, 0};
ll d2[4] = {0, 0, 1, -1};

int main(){
    ll A, B, C, D, E, F;
    cin >> A >> B >> C >> D >> E >> F;
    set<ll> x, y;
    for(ll a = 0; a <= F; a += 100 * A){
        for(ll b = 0; b <= F - a; b += 100 * B){
            x.insert(a + b);
        } 
    }
    for(ll c = 0; c <= F; c += C){
        for(ll d = 0; d <= F - c; d += D){
            y.insert(c + d);
        } 
    }
    ll ansF = 100*A, ansS = 0;
    double node = 0;
    for(auto w : x){
        for(auto s : y){
            if(w + s <= F && s <= E * w / 100){
                if(node < 100 * (double) s / (double)(s + w)){
                    ansF = s + w;
                    ansS = s;
                    node = 100 * (double) s / (double)(s + w);
                }
            }
        }
    }
    cout << ansF << " " << ansS << endl;
    return 0;
}

Measured memory_bytes: 384
#include <bits/stdc++.h>
using namespace std;
struct fast_ios { fast_ios(){ cin.tie(0); ios::sync_with_stdio(false); cout << fixed << setprecision(20); }; } fast_ios_;
#define FOR(i, begin, end) for(int i=(begin);i<(end);i++)
#define REP(i, n) FOR(i,0,n)
#define IFOR(i, begin, end) for(int i=(end)-1;i>=(begin);i--)
#define IREP(i, n) IFOR(i,0,n)
#define Sort(v) sort(v.begin(), v.end())
#define Reverse(v) reverse(v.begin(), v.end())
#define all(v) v.begin(),v.end()
#define SZ(v) ((int)v.size())
#define Lower_bound(v, x) distance(v.begin(), lower_bound(v.begin(), v.end(), x))
#define Upper_bound(v, x) distance(v.begin(), upper_bound(v.begin(), v.end(), x))
#define Max(a, b) a = max(a, b)
#define Min(a, b) a = min(a, b)
#define bit(n) (1LL<<(n))
#define bit_exist(x, n) ((x >> n) & 1)
#define debug(x) cout << #x << "=" << x << endl;
#define vdebug(v) cout << #v << "=" << endl; REP(i_debug, v.size()){ cout << v[i_debug] << ","; } cout << endl;
#define mdebug(m) cout << #m << "=" << endl; REP(i_debug, m.size()){ REP(j_debug, m[i_debug].size()){ cout << m[i_debug][j_debug] << ","; } cout << endl;}
#define pb push_back
#define f first
#define s second
#define int long long
#define INF 1000000000000000000
template<typename T> istream &operator>>(istream &is, vector<T> &v){ for (auto &x : v) is >> x; return is; }
template<typename T> ostream &operator<<(ostream &os, vector<T> &v){ for(int i = 0; i < v.size(); i++) { cout << v[i]; if(i != v.size() - 1) cout << endl; }; return os; }
template<typename T> void Out(T x) { cout << x << endl; }
template<typename T1, typename T2> void Ans(bool f, T1 y, T2 n) { if(f) Out(y); else Out(n); }

using vec = vector<int>;
using mat = vector<vec>;
using Pii = pair<int, int>;
using PiP = pair<int, Pii>;
using PPi = pair<Pii, int>;
using bools = vector<bool>;
using pairs = vector<Pii>;

//int dx[4] = {1,0,-1,0};
//int dy[4] = {0,1,0,-1};
//char d[4] = {'D','R','U','L'};

const int mod = 1000000007;
//const int mod = 998244353;
#define Add(x, y) x = (x + (y)) % mod
#define Mult(x, y) x = (x * (y)) % mod



signed main(){

    int N; cin >> N;
    vec A(N); cin >> A;
    Sort(A);
    Reverse(A);

    int np = 0;
    REP(i, N) if(A[i] > 0) np++;

    pairs ans;
    int tmp;
    if(np == N){
        tmp = A[N - 1];
        FOR(i, 1, N - 1){
            ans.pb(Pii(tmp, A[i]));
            tmp -= A[i];
        }
        ans.pb(Pii(A[0], tmp));
        tmp = A[0] - tmp;
    }else if(np == 0){
        tmp = A[0];
        FOR(i, 1, N){
            ans.pb(Pii(tmp, A[i]));
            tmp -= A[i];
        }
    }else{
        tmp = A[N - 1];
        FOR(i, 1, N - 1) if(A[i] >= 0){
            ans.pb(Pii(tmp, A[i]));
            tmp -= A[i];
        }
        ans.pb(Pii(A[0], tmp));
        tmp = A[0] - tmp;
        FOR(i, 1, N - 1) if(A[i] < 0){
            ans.pb(Pii(tmp, A[i]));
            tmp -= A[i];
        }
    }

    Out(tmp);
    REP(i, N - 1){
        cout << ans[i].f << " " << ans[i].s << endl;
    }

    return 0;
}


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

bool check(int n, vector<int> H){
    bool HorL = true;
    rep(i, n){
        if(H[i] > H[n] ){
            HorL = false;
            break;
        }
    }
    return HorL;
}

int main(){
    int N, count;
    cin >> N;
    vector<int> H(N);
    rep(i, N){
        cin >> H[i];
    }

    rep(i, N){
        if(check(i, H) == true){
            count++;
        }
    }
    cout << count << endl;
}

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

using namespace std;

using int64 = long long;

const int mod = 1e9 + 7;

char G[100000000];

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


  int64 tail = 0, tailsum = 0, sum = 0;
  int64 fact, ret = 0;


  for(int i = 1; i < 10; i++) {
    G[i] = 1;
  }
  for(int i = 1; i < 100000000; i++) {
    if(i * 10 < 100000000) G[i * 10] = G[i] + 1;
    G[i] = max(G[i], G[i - 1]);
  }
  for(int i = 1; i < 10000000; i++) {
    while(sum + S > tailsum) tailsum += G[tail++];
    if(sum + S == tailsum) ++ret;
    sum += G[i];
  }
  fact = 10000000;
  for(int i = 8; i <= 100000002; i++) {
    if(S % i == 0) {
      int64 need = S / i;
      int64 sz = fact * 9 % mod;
      (sz += 1) %= mod;
      (sz += mod - need) %= mod;
      (ret += sz) %= mod;
    }
    (fact *= 10) %= mod;
  }

  for(int i = 8; i < S; i++) {
    int64 SS = (S - i - (i + 1));
    if(SS >= 0) {
      int64 YY = SS % i;
      int64 SYO = (SS - YY) / i;
      if(YY <= SYO) {
        ret += 1 + ((SYO - YY) / (i + 1));
        ret %= mod;
      }
    }
  }

  cout << ret << endl;
}

Measured memory_bytes: 98048
n, x, m = [int(_) for _ in input().split()]
d = {}
d_rev = {}
d[x] = 0
d_rev[0] = x
c = 0
while True:
    c += 1
    x = (x ** 2) % m
    if x in d:
        roop_idx = d[x]
        break
    else:
        d[x] = c
        d_rev[c] = x

ans = 0
if roop_idx >= n:
    for i in range(n):
        ans += d_rev[i]
    print(ans)
else:
    for i in range(roop_idx):
        ans += d_rev[i]
    roop_num = len(d) - roop_idx
    roop_sum = 0
    for i in range(roop_idx, len(d)):
        roop_sum += d_rev[i]
    ans += ((n-roop_idx)//roop_num) * roop_sum
    roop_last = (n-roop_idx)%roop_num
    for i in range(roop_last):
        ans += d_rev[roop_idx + i]
    print(ans)

Measured memory_bytes: 17992
n,k=map(int,input().split())
k -= (n-1)*(n-2)//2
if k > 0 :
    print(-1)
else:
    print(n-1 - k)
    for i in range(2,n+1):
        print(1,i)
    for i in range(2,n):
        for j in range(i+1,n+1):
            if k < 0:
                print(i,j)
                k += 1

Measured memory_bytes: 3608
#include<iostream>
using namespace std;
int main() {
	int x,y;
	for (;;) {
		cin >> x >> y;
		if (x < 1 && y < 1) {
			return 0;
		}
		if (x > y) {
			cout << y <<" "<< x << endl;
		}
		else if (x <= y) {
			cout << x <<" "<< y << endl;
		}
	}
}


Measured memory_bytes: 3020
//Robs Code

/***********HEADER***************/
#include <iostream>
#include <bitset>
#include <deque>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <string>
#include <algorithm>
#include <list>
#include <vector>
#include <unordered_set>
#include <unordered_map>
#include <stack>
#include <set>
#include <queue>
#include <map>
#include <iomanip>

/***********MACROS***************/
#define int long long int
#define all(x) x.begin(),x.end()
#define allr(x) x.rbegin(),x.rend()
#define endl "\n"
#define pb push_back
#define _1 first
#define _2 second
#define pii pair<int,int>

using namespace std;

const int N = 1e5 + 1;
int n,m,i,j,k,l,x,y,z,cnt[3],sum[3];

/***********MAIN**************/
signed main(){
	ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
	cin >> n;
	int pro = 1;
	vector<int> v(n);
	for(auto &x : v){
		cin >> x;
	}
	sort(all(v));
	for(int i = 0;i < n;i++){
		x = v[i];
		if((1e18/(long double)x) >= pro){
			pro *= x;
		}else{
			cout << "-1";
			return 0;
		}
	}
	cout << pro;
}
//.........

Measured memory_bytes: 3984
N,T = list(map(int,input().split()))
ct = []
for i in range(N):
    ct.append(list(map(int,input().split())))
kouho =[]
for i in range(N):
    if ct[i][1]<=T:
        kouho.append(ct[i][0])
if len(kouho)==0:
    print("TLE")
else:
    print(min(kouho))

Measured memory_bytes: 3060
n=int(input())+1
data=[0]*n*2
def update(i,x):
    i+=n
    data[i]=x
    i//=2
    while i:
        data[i]=data[i*2]|data[i*2+1]
        i//=2
def query(l,r):
    l+=n
    r+=n
    s=0
    while l<r:
        if l&1:
            s|=data[l]
            l+=1
        if r&1:
            r-=1
            s|=data[r]
        l//=2
        r//=2
    return sum(map(int,bin(s)[2:]))
s=input()
for i,c in enumerate(s,n):
    data[i]=1<<(ord(c)-97)
for i in range(n-1,0,-1):
    data[i]=data[2*i]|data[2*i+1]
for _ in range(int(input())):
    q,a,b=input().split()
    if q=="2":
        print(query(int(a)-1,int(b)))
    else:
        update(int(a)-1,1<<(ord(b)-97))

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

int main() {
  int n, m;
  vector<string> N, B;
  vector<int> M;

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

    for(int i = 0; i < n; i++) {
      string str;
      int money;
      cin >> str >> money;
      N.push_back(str);
      M.push_back(money);
    }

    for(int i = 0; i < m; i++) {
      string str;
      cin >> str;
      B.push_back(str);
    }

    int ans = 0;
    for(int i = 0; i < m; i++) {
      for(int j = 0; j < n; j++) {
        int chance = 1;
        for(int k = 0; k < 8; k++) {
          if(N[j][k] != '*') {
            if(N[j][k] != B[i][k]) {
              chance = 0;
              break;
            }
          }
        }
        if(chance == 1)
          ans += M[j];
      }
    }
    cout << ans << endl;
    M.clear();
    N.clear();
    B.clear();
  }
  return 0;
}


Measured memory_bytes: 3168
import java.util.Scanner;

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

    while (in.hasNext()) {
      int A = in.nextInt();
      int B = in.nextInt();
      int C = in.nextInt();

      if (A - B >= C) {
        System.out.println(0);
      } else {
        System.out.println(C - (A - B));
      }
    }
  }
}

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

using namespace std;
#define inf 1000000000
#define unvisited -1
#define visited 1
#define eps 1e-9
#define mp make_pair
#define pb push_back
#define pi acos(-1.0)
#define uint64 unsigned long long
typedef long long ll;
typedef vector<int> vi;
typedef pair<int,int> ii;
typedef vector<ii> vii;

const ll mod = 1e9 + 7;
const int maxn = 1e5 + 5;

ll fact[maxn];
ll inv[maxn];

ll modPow(ll a, ll b){
	if(b==0){return 1;}
	else{
		if(b%2==1){return a*modPow(a,b-1)%mod;}
		else{
			ll temp = modPow(a,b/2);
			return temp*temp%mod;
		}
	}
}

int main(){
	int n,i,j;
	scanf("%d",&n);
	int a[maxn];

	for(i=0;i<n;i++){
		scanf("%d",&a[i]);
	}
	fact[0] = 1;
	for(i=1;i<=n;i++){
		fact[i] = fact[i-1]*(ll)i;
		fact[i] %= mod;
	}
	//hitung inverse
	for(i=1;i<=n;i++){
		inv[i] = modPow(i,mod-2);
		// printf("nilai inv[%d]: %lld\n",i,inv[i]);
	}
	for(i=2;i<=n;i++){
		inv[i] += inv[i-1];
		inv[i] %= mod;
	}
	//hitung expected number masing"index
	ll ans = 0;
	for(i=0;i<n;i++){
		//hitung yang ke kiri
		// printf("i: %d\n",i);
		int jarakKeKiri = i + 1;
		int jarakKeKanan = n-i;
		ll expected = inv[jarakKeKiri] + inv[jarakKeKanan] - 1LL;
		if(expected < 0){expected += mod;}
		expected %= mod;
		// printf("inv[%d]: %lld inv[%d]: %lld expected: %lld\n",jarakKeKiri,inv[jarakKeKiri],jarakKeKanan,inv[jarakKeKanan], expected);
		expected *= fact[n];
		expected %= mod;
		ans += (expected*(ll)a[i]);
		// printf("ans awal jadi: %lld\n",ans);
		ans %= mod;
		// printf("ans jd: %lld\n",ans);
	}
	printf("%lld\n",ans);
	return 0;
};

Measured memory_bytes: 2176
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
#define mp make_pair
#define fst first
#define snd second
#define fr(i, a, b) for(int i=a; i<b; i++)
template<class T = int> using V = vector<T>;
template<class T = int> using VV = V< V<T> >;

int main() {
    cin.tie(nullptr); ios::sync_with_stdio(false);
    int x, y; cin >> x >> y;
    int ans = 0;
    int p[3] = {300000, 200000, 100000};
    if(x==1 && y == 1) {
        cout << 1000000 << endl;
        return 0;
    }
    if(x <=3) ans += p[x-1];
    if(y <=3) ans += p[y-1];
    cout << ans << endl;
}


Measured memory_bytes: 256
Data = list(map(int, input().split()))
N = Data[0]
M = Data[1]
del(Data)
Data = []
for i in range(M):
  Data.append(list(map(int, input().split())))
  Data[i].append(i)
Data.sort()
Cnt = 0
Num = 0
for i in range(M):
  if Num == Data[i][0]:
    Cnt += 1
  else:
    Cnt = 1
    Num = Data[i][0]
  Data[i].append(Cnt)
Data.sort(key=lambda x:x[2])

for i in range(M):
  print(str(Data[i][0]).zfill(6) + str(Data[i][3]).zfill(6))

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

int n, num, a[20005], ans[20005];
int main()
{
	int i;
//	freopen ("input.txt", "r", stdin);
	cin >> n;
	for (i = 1; i <= n; i++) {
		scanf ("%d", &a[i]);
	}
	for (i = 1; i <= n; i++) {
		printf("%d ", i * n);
	}
	num = n * n + a[1] * n;
	for (i = 1; i <= n; i++) {
		ans[a[i]] = num - a[i] * n;
		num++;
	}
	cout << endl;
    for (i = 1; i <= n; i++) {
		printf("%d ", ans[i]);
    }
    return 0;
}


Measured memory_bytes: 768
#include <bits/stdc++.h>
#define rep(i, a, n) for(int i = a; i < n; i++)
#define REP(i, n) rep(i, 0, n)
#define int long long
using namespace std;
typedef pair<int, int> P;
const int mod = 1000000007;
const int INF = 1e18;

signed main(){
	int n, k;
	cin >> n >> k;
	vector<int> a(n);
	rep(i, 0, n){
		cin >> a[i];
		a[i]++;
	}
	int sum = 0;
	rep(i, 0, k) sum += a[i];
	int ans = sum;
	rep(i, k, n){
		sum = sum - a[i - k] + a[i];
		ans = max(ans, sum);
	}
	printf("%.10f\n", (double)ans / 2.0);
}

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

int main(void){
    string S;
    long long int K;
    cin>>S>>K;
    int one_index=-1;

    for(int i=0;i<S.length();i++){
        if(S[i]=='1'){
            one_index++;
        }else{
            break;
        }
    }

   
    if(K<one_index+2){
        cout<<S[one_index]<<endl;
    }else if(one_index==-1){
            cout<<S[0]<<endl; 
    }else{
        cout<<S[one_index+1]<<endl;
    }
    



    return 0;
}

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

int n;
string s;

int main()
{
	cin>>n>>s;
	for(int i=0;i<s.length();i++)
	{
		char c=s[i]+n;
		if(c>'Z')
			c -= 26;
		cout<<c;
	}
	cout<<endl;
	
	return 0;
}

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

using namespace std;
#define int long long
#define rep(i,n) for(int i=0;i<n;++i)
#define rep1(i,n) for(int i=1;i<=n;++i)
#define ALL(x) x.begin(),x.end()
#define ll long long
typedef pair<int,int> P;
const int inf=1000000007;
const int MOD=1000000007;
signed main(){
  int k,a,b;cin>>k;
  cin>>a>>b;
  bool flag=false;
  for(int i=a;i<=b;++i){
    if(i%k==0)flag=true;
  }
	if(flag){
    cout<<"OK"<<endl;
  }
  else{
    cout<<"NG"<<endl;
  }
  return 0;
}


Measured memory_bytes: 3624
#include <algorithm>
#include <iostream>
#include <vector>
#include <math.h>
#include <set>
#include <map>
#include <string>
#include <stack>
#include <queue>
#include <iomanip>
#include <numeric>
#include <tuple>
#include <bitset>
#include <complex>
#include <unistd.h>
#include <cassert>
#include <cctype>
#define _USE_MATH_DEFINES
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> plglg;
typedef tuple<int, int, int> tiii;
typedef tuple<ll, ll, ll> tlglglg;
typedef complex<double> xy_t;
int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};
double pi = 3.141592653589793;
ll mod = 1000000007;
int intmax = 2147483647;
int intmin = -2147483648;
ll llmax = 9223372036854775807;
ll llmin = -9223372036854775807;
ll inf = llmax / 2;
double eps = 1e-11;

int main() {
    ll X, Y;
    cin >> X >> Y;
    if (X < Y) {
        swap(X, Y);
    }
    if (X - Y >= 2) {
        cout << "Alice" << endl;
    } else {
        cout << "Brown" << endl;
    }
}

Measured memory_bytes: 256
# Python3 (3.4.3)
import sys
input = sys.stdin.readline

# -------------------------------------------------------------
# function
# -------------------------------------------------------------
N = 100
primes = []
is_prime = [True]*N
for i in range(2,N):
    if is_prime[i]:
        primes.append(i)
        j = 2
        while i*j < N:
            is_prime[i*j] = False
            j += 1

def get(x):
    cnt = 0
    for e in E:
        if e >= x-1:
            cnt += 1
    return cnt

# -------------------------------------------------------------
# main
# -------------------------------------------------------------
N = int(input())

E = [0]*101
for i in range(2,N+1):
    for p in primes:
        while i%p==0:
            E[p] += 1
            i //= p

ans = 0

# e1^74
ans += get(75)

# e1^24, e2^2
ans += get(25) * (get(3)-1)

# e1^14, e2^4
ans += get(15) * (get(5)-1)

# e1^4, e2^4, e3^2
ans += get(5) * (get(5)-1) * (get(3)-2) // 2

print(ans)

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

using namespace std;
                                                                          	
#define forn(i, x, n) for (int i = int(x); i <= int(n); ++i)
#define for1(i, n, x) for (int i = int(n); i >= int(x); --i)
#define file ""     
#define F first                       
#define S second 
#define pb push_back   

typedef long long ll; 
typedef pair <ll, ll> PII;
typedef double ld;
                                                                                          
const int N = 2e6 + 1; 
const int INF = 1e9 + 9;
const int B = 1e9 + 7;

int n, a[N];

void no() {
	cout << "Impossible\n";
	exit(0);
}
   
int main () {
#ifdef machine42
	freopen (file"in", "r", stdin);
	freopen (file"out", "w", stdout);
#endif		
	ios_base :: sync_with_stdio (0);
	cin.tie(0);

	cin >> n;
	multiset <int> st;
	forn(i, 1, n) {
		cin >> a[i];
		st.insert(a[i]);
	}   
	int d = *--st.end();
	for1(i, d, (d + 1) / 2) {
	    int lim = (d % 2 == 0 && i == (d + 1) / 2) ? 1 : 2;
	    forn(it, 1, lim) {
			if (st.find(i) == st.end()) no();
			st.erase(st.find(i));
		}
	}
	if (st.size() && *st.begin() <= (d + 1) / 2) no();
	cout << "Possible\n";

	return 0;         	
}


Measured memory_bytes: 384
#pragma GCC optimize("Ofast")
#include <bits/stdc++.h> 
using namespace std;

typedef long long ll;

#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0) 
#define rep(pp,nn) for (int ii = pp; ii < nn; ++ii)
#define vi vector<int>
#define vll vector<ll>
#define vs vector<string>
#define endl "\n"

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

string int_to_string(int x) {
    stringstream ss;
	ss << x;
	string ni = ss.str();
	return ni;
}
int string_to_int(string x) {
	int n;
	stringstream s(x);
	s >> n;
	return n;
}

int64_t power_mod(ll a, ll b, ll mo) {
	ll ans = 1;
	while (b) {
		if(b & 1) {
			ans = (ans % mo * a % mo) % mo;
		}
		a = (a % mo * a % mo) % mo;
		b /= 2;
	}
	return ans;
}
int64_t POW(ll a, ll b) {
	ll ans = 1;
	while (b) {
		if(b & 1) {
			ans = ans * a;
		}
		a = a * a;
		b /= 2;
	}
	return ans;
}

vector<int64_t> INVERSE(int64_t nn, int64_t mo) {
	vector<int64_t> inv(nn + 1);
	vector<int64_t> mul(nn + 1);
	inv[0] = 1;
    inv[1] = 1;
	for (ll i = 2; i <= nn; ++i) {
		inv[i] = (mo - (mo / i) * inv[mo % i] % mo) % mo; 
	}
	mul[0] = 1;
	for (int i = 1; i <= nn; ++i) {
		mul[i] = (mul[i - 1] * inv[i]) % mo;
	}
	return mul;
}

template<typename T, typename V>
void __print(const pair<T, V> &x) {cerr << '{'; __print(x.first); cerr << ','; __print(x.second); cerr << '}';}
template<typename T>
void __print(const T &x) {int f = 0; cerr << '{'; for (auto &i: x) cerr << (f++ ? "," : ""), __print(i); cerr << "}";}
void _print() {cerr << "]\n";}
template <typename T, typename... V>
void _print(T t, V... v) {__print(t); if (sizeof...(v)) cerr << ", "; _print(v...);}

#ifndef ONLINE_JUDGE
#define debug(x...) cerr << "[" << #x << "] = ["; _print(x)
#else
#define debug(x...)
#endif

vector<int64_t> fact(2001);
vector<int64_t> inv(2001);
int mod = 1e9 + 7;

int64_t C(int64_t n, int64_t k) {
	if (k > n) {
		return 0;
	}
	return (fact[n] % mod * inv[k] % mod * inv[n - k] % mod) % mod;
}

int main() {
	IOS;
	int n, k;
	cin >> n >> k;
	int z = 2000;
	fact[0] = 1;
	for (int i = 1; i <= z; ++i) {
		fact[i] = (fact[i - 1] * i * 1LL) % mod;
	}
	inv = INVERSE(z, mod);
	int64_t R = n - k;
	int64_t B = k;
	for (int i = 1; i <= k; ++i) {
		 cout << (C(R + 1, i) % mod * C(B - 1, i - 1) % mod) % mod << endl;
	}
}















Measured memory_bytes: 3672
#include <bits/stdc++.h>
#define pb push_back
#define ll long long
#define f first
#define s second
using namespace std;

int main(){
    ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    string s; cin >> s;
    bool a = 1, b = 1, c = 1;
    if(s[0] != 'A')a = 0;
    int cnt = 0;
    for(int i = 2; i < s.length()-1; i++){
        if(s[i] == 'C')cnt++;
    }
    if(cnt == 1)b = 1;
    else b = 0;
    int lcnt = 0;
    for(int i = 0; i < s.length(); i++){
        if((int)s[i]-'a' < 26 && (int)s[i]-'a' >= 0)lcnt++;
    }
    //cout << lcnt << endl;
    if(s.length()-lcnt == 2)c = 1;
    else c = 0;
    if(a && b && c)cout << "AC" << endl;
    else cout << "WA" << endl;
    return 0;
}


Measured memory_bytes: 3648
/*
 * Author: .-O_O-.
 */
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include<bits/stdc++.h>
using namespace __gnu_pbds;
using namespace std;
#define ll long long
#define pb push_back
#define vi vector<int>
#define rep0(a,b) for(int a=0;a<b;a++)
#define rep1(a,b) for(int a=1;a<=b;a++)
#define repp(a,b,c) for(int a=b;a<c;a++)
#define in insert
#define len length()
#define si size()
#define lb lower_bound
#define ub upper_bound
#define beg begin()
#define en end()
#define f first
#define s second
#define pr(a) cout<<a
#define pr2(a,b) cout<<a<<" "<<b<<"\n"
#define nx cout<<"\n"
#define int long long
// void __print(int x) {cerr << x;}
void __print(long x) {cerr << x;}
void __print(long long x) {cerr << x;}
void __print(unsigned x) {cerr << x;}
void __print(unsigned long x) {cerr << x;}
void __print(unsigned long long x) {cerr << x;}
void __print(float x) {cerr << x;}
void __print(double x) {cerr << x;}
void __print(long double x) {cerr << x;}
void __print(char x) {cerr << '\'' << x << '\'';}
void __print(const char *x) {cerr << '\"' << x << '\"';}
void __print(const string &x) {cerr << '\"' << x << '\"';}
void __print(bool x) {cerr << (x ? "true" : "false");}
                                                     
template<typename T, typename V>
void __print(const pair<T, V> &x) {cerr << '{'; __print(x.first); cerr << ','; __print(x.second); cerr << '}';}
template<typename T>
void __print(const T &x) {int f = 0; cerr << '{'; for (auto &i: x) cerr << (f++ ? "," : ""), __print(i); cerr << "}";}
void _print() {cerr << "]"<<endl;}
template <typename T, typename... V>
void _print(T t, V... v) {__print(t); if (sizeof...(v)) cerr << ", "; _print(v...);}
#ifndef ONLINE_JUDGE
#define deb(x...) cerr << "[" << #x << "] = ["; _print(x)
#else
#define deb(x...)
#endif
const ll mod = 1000000007;
const ll N = 200005;
const ll mm = 1e+18;
long long power(long long x, long long y)
{
   long long res = 1;
   x = x % mod;
   while (y > 0)
   {
       if (y & 1)
            res = (res*x) %mod;
       y = y>>1;
       x = (x*x) %mod;
   }
   return res;
}
void solve()
{
    int n;
    cin>>n;
    map<int,int>mp;
    rep1(i,n){
        int x;
        cin>>x;
        mp[x]++;
    }
    map<int,int>mp1;
    int cu=0;
    int ne=n-1;
    rep1(i,n){
        mp1[abs(cu-ne)]++;
        cu++;
        ne--;
    }
    if(mp!=mp1){
        cout<<0;
        return;
    }
    cout<<power(2,n/2);
}
signed main()
{
    ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
    int t=1;
    //cin>>t;
    rep1(_i,t){
        //cout<<"Case #"<<_i<<": ";
        solve();
        //nx;
    }
    return 0;
}


Measured memory_bytes: 10704
s = list(input())
t = list(input())
max = 0
c = 0
for i in range(len(s) - len(t) + 1):
	for j in range(len(t)):
		if t[j] == (s[i:i+len(t)])[j]:
			c += 1
	if max < c:
		max = c
	c = 0
print(len(t) - max)

Measured memory_bytes: 9148
#include <bits/stdc++.h>
#define REP(i, a, n) for (long long i = (a); i < (long long)(n); ++i)
#define REPC(i, a, n) for (long long i = (a); i <= (long long)(n); ++i)
#define ALL(t) t.begin(), t.end()
#define RALL(t) t.rbegin(), t.rend()
#define MATINIT(type, row, col, init) \
  vector<vector<type>>(row, vector<type>(col, init));
#define Yes(cond) cout << (cond ? "Yes" : "No") << endl;
#define YES(cond) cout << (cond ? "YES" : "NO") << endl;
using namespace std;
using LL = long long;
using ULL = unsigned long long;
template <class T>
using VEC = std::vector<T>;
template <class T>
using MAT = std::vector<std::vector<T>>;
void DUMP() { cerr << endl; }
template <class Head, class... Tail>
void DUMP(Head &&head, Tail &&... tail) {
  cerr << head << ", ";
  DUMP(std::move(tail)...);
}
template <typename T>
ostream &operator<<(ostream &os, vector<T> &vec) {
  os << "{";
  for (auto v : vec) os << v << ",";
  os << "}";
  return os;
}
template <typename T>
ostream &operator<<(ostream &os, set<T> &s) {
  os << "{";
  for (auto p : s) os << p << ",";
  os << "}";
  return os;
}
template <typename T1, typename T2>
ostream &operator<<(ostream &os, map<T1, T2> &m) {
  os << "{";
  for (auto p : m) os << p << ",";
  os << "}";
  return os;
}
template <typename T1, typename T2>
ostream &operator<<(ostream &os, pair<T1, T2> p) {
  os << "[" << p.first << " " << p.second << "]";
  return os;
}

LL solve(LL N, LL K){
  if(N==K){
    return 0;
  }else if(N>K){
    return solve(N%K, K);
  }else{
    return min(K-N, N);
  }
}

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

  cout<<solve(N,K)<<endl;

  return 0;
}


Measured memory_bytes: 256
#include<stdio.h>
#include<stdlib.h>
#include<math.h>
#include<string.h>
#include<stdbool.h>
typedef long long ll;
typedef long double ld;
#define rep(i,l,r)for(ll i=(l);i<(r);i++)
#define repp(i,l,r,k)for(ll i=(l);i<(r);i+=(k))
#define INF (1LL<<60)
#define MOD1 1000000007
#define MAX_N (1 << 17)


void swap(ll *a, ll *b){ll c;c=*b;*b=*a;*a=c;}
ll max2(ll a,ll b){return a>=b?a:b;}
ll min2(ll a,ll b){return a>=b?b:a;}
ll minn(ll n, ll a[n]){ll b=INF;rep(i,0,n) b=min2(b,a[i]);return b;}
ll maxn(ll n, ll a[n]){ll b=-INF;rep(i,0,n) b=max2(b,a[i]);return b;}
ll ABS(ll a){return a>=0?a:(-a);}
ll POW(ll a, ll b){ll c=1;rep(i,0,b) c*=a;return c;}
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
ll lcm(ll a,ll b){return a/gcd(a,b)*b;}
int upll(const void*a, const void*b){return*(ll*)a<*(ll*)b?-1:*(ll*)a>*(ll*)b?1:0;}
int downll(const void*a, const void*b){return*(ll*)a<*(ll*)b?1:*(ll*)a>*(ll*)b?-1:0;}
void sortup(ll*a,int n){qsort(a,n,sizeof(ll),upll);}
void sortdown(ll*a,int n){qsort(a,n,sizeof(ll),downll);}

typedef struct{
    ll aa;
    ll bb;
}frequent;

int main(void){
    // char ;
    ll n,ans=0,c[9]={0};
    // rep(i,0,9) c[i]=0;
    scanf("%lld",&n);
    ll a[n];
    rep(i,0,n){
        scanf("%lld",&a[i]);
        c[ min2(a[i]/400,8) ]++;
    }
    rep(i,0,8){
        if(c[i]>0){
            ans++;
        }
    }
    // if(ans==8){
    //     printf("8 8\n");
    //     return 0;
    // }
    // if(ans==0){
    //     printf("1 %lld\n",min2(8,ans+c[8]));
    // }else{
        printf("%lld %lld\n",max2(1,ans),ans+c[8]);
    // }
    // if(c[8]==1){
    // }else{
        // printf("%lld %lld\n",ans,ans);
    // }
    // printf("\n");
    return 0;
}


Measured memory_bytes: 128
import java.util.*;

public class Main {
    public static void main(String[] args){

        Scanner scan = new Scanner( System.in );

        int x = Integer.parseInt( scan.next() );
        int n = Integer.parseInt( scan.next() );

        int[] p = new int[n];

        for(int i=0; i<n; i++){
            p[i] = Integer.parseInt( scan.next() );
        }

        Arrays.sort(p);

        Roop:
        for(int i=0; i<Integer.MAX_VALUE; i++){
            boolean flag = true;
            for(int j=0; j<n; j++){
                if(x-i == p[j]){
                    flag = false;
                    break;
                }
            }
            if(flag){
                System.out.println(x-i);
                break Roop;
            }
            for(int j=0; j<n; j++){
                if(x+i == p[j]){
                    continue Roop;
                }
            }
            System.out.println(x+i);
            break Roop;
        }
        

    }
}

Measured memory_bytes: 35688
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <iostream>
#include <string>
#include <vector>
#include <map>
#include <set>
#include <stack>
#include <list>
#include <queue>
#include <deque>
#include <algorithm>
#include <numeric>
#include <utility>
#include <complex>
#include <functional>
#include <climits>

using namespace std;
long DIV = 1000000007;
int main() {

    int n;
    long p = 1;
    char s[100001];
    cin >> n >> s;
    vector<int> a(30, 1);
    for(size_t i = 0; i < n; i++)
    {
        a[s[i]-'a'] += 1;
    }
    for(size_t i = 0; i < 30; i++)
    {
        if(a[i] != 1) {
            p *= a[i];
            p %= DIV;
        }
    }
    cout << p-1 << endl;
}


Measured memory_bytes: 384
#include<iostream>
#include<iomanip>
#include<cstdlib>
#include<math.h>
#include<algorithm>
#include<string>
#include<vector>
#include<list>
#include<queue>
#include<stack>
#include<set>
#include<map>
#define REP(i, N) for(ll i = 0; i < N; ++i)
#define ALL(a) (a).begin(),(a).end()
#define pb push_back
#define INF 1000000000
#define MOD 1000000007
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};
int qx[8] = {1, 1, 0, -1, -1, -1, 0, 1};
int qy[8] = {0, 1, 1, 1, 0, -1, -1, -1};

int main(void) {
	ll N;
	cin>>N;
	vector<ll> a(N);
	REP(i, N) cin>>a[i];
	ll ans = 0;
	ll bn = 0;
	ll det = 0;
	REP(i, N) {
		if(det == 0) {
			ll memo = i;
			++ans;
			for(ll j = i; j < N; ++j) {
				if(a[j] > a[i]) {
					det = 1;
					i = j;
					break;
				} else if(a[j] < a[i]) {
					det = -1;
					i = j;
					break;
				}
			}
			if(i == memo) break;
			bn = a[i];
		} else if(det == 1) {
			if(a[i] >= bn) {
				bn = a[i];
				continue;
			} else {
				det = 0;
				--i;
				continue;
			}
		} else if(det == -1) {
			if(a[i] <= bn) {
				bn = a[i];
				continue;
			} else {
				det = 0;
				--i;
				continue;
			}
		}
	}
	cout<<ans<<endl;
}


Measured memory_bytes: 1024
N, M = map(int, input().split())
data = [list(map(int, input().split())) for _ in range(M)]

answer = [N*(N-1)//2]
par = [-1] * (N+1)

def find(x):
    if par[x] < 0:
        return x
    else:
        return find(par[x])

def size(x):
    return -par[find(x)]

def unite(u, v):
    u = find(u)
    v = find(v)
    if u != v:
        if size(u) < size(v):
            u, v = v, u
        par[u] += par[v]
        par[v] = u


for d in data[::-1]:
    if find(d[0]) != find(d[1]):
        answer.append(answer[-1]-(size(d[0])*size(d[1])))
        unite(d[0], d[1])
    else:
        answer.append(answer[-1])

for i in answer[M-1::-1]:
    print(i)

Measured memory_bytes: 34180
#include <bits/stdc++.h>
#define ll double
using namespace std;

int main(){
   int n;
   cin>>n;
   int a[n],b[n],c[n];
   for(int i=0;i<n;i++){
    cin>>a[i]>>b[i]>>c[i];
   }
   int dp[n][3];
   dp[0][0]=a[0];dp[0][1]=b[0];dp[0][2]=c[0];
   for(int i=1;i<n;i++){
    dp[i][0]=max(dp[i-1][1]+a[i],dp[i-1][2]+a[i]);
    dp[i][1]=max(dp[i-1][0]+b[i],dp[i-1][2]+b[i]);
    dp[i][2]=max(dp[i-1][0]+c[i],dp[i-1][1]+c[i]);


   }
   cout<<max(dp[n-1][0],max(dp[n-1][1],dp[n-1][2]))<<endl;
}


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

int main(){
    //変数宣言
    string S,T,Si,Ti;
    int q,i,s1,t1;
    //入力
    cin >> S >> T >>q;
    int a[q],b[q],c[q],d[q];
    for (i=0;i<q;i++){
        cin >> a[i] >> b[i] >>c[i] >> d[i];
    }
    int m[S.size()],n[T.size()];
//各項までの和を出しておく
    m[0]=S[0]-'@';
    n[0]=T[0]-'@';
    for (i=1;i<S.size();i++){
        m[i]=S[i]-'@'+m[i-1];
    }
    for (i=1;i<T.size();i++){
        n[i]=T[i]-'@'+n[i-1];
    }
    //解決
    for (i=0;i<q;i++){
        s1 = m[b[i]-1]-m[a[i]-1]+(S[a[i]-1]-'@');
        t1 = n[d[i]-1]-n[c[i]-1]+(T[c[i]-1]-'@');
        if (s1%3==t1%3) cout << "YES"<<endl;
        else cout << "NO"<<endl;
    }
    return 0;
}

Measured memory_bytes: 3200
import sys
sys.setrecursionlimit(10**9)
INF=10**18
def input():
    return sys.stdin.readline().rstrip()

def main():
    def zalgo(S):
        A=[0]*len(S)
        A[0]=len(S)
        i,j=1,0
        while i<len(S):
            while i+j<len(S) and S[j]==S[i+j]:
                j+=1
            A[i]=j 
            if j==0:
                i+=1
                continue
            k=1
            while i+k<len(S) and k+A[k]<j:
                A[i+k]=A[k]
                k+=1
            i+=k
            j-=k
        return A
    N=int(input())
    S=input()
    ans=0
    for i in range(N-1):
        A=zalgo(S[i:])
        for j,x in enumerate(A):
            if x>j:
                ans=max(ans,j)
            else:
                ans=max(ans,x)
    print(ans)

if __name__ == '__main__':
    main()


Measured memory_bytes: 49244
#include <bits/stdc++.h>
 
using namespace std;
 
 
 
//c++ templte for help...........................................................
 
//#define deb(x) cout<<#x<<" "<<x<<endl;/* for debuging  printing variable with name*/
//#define debb(x,y) cout<<#x<<" "<<x<<" "<<#y<<" "<<y<<endl;										
//#define debbb(x,y,z) cout<<#x<<" "<<x<<" "<<#y<<" "<<y<<" "<<#z<<" "<<z<<endl;			
 
typedef long long ll;
	
 
//for loop
//#define fo(i,n) for(int i=0;i<(ll)n;i++)
//#define Fo(i,k,n) for(int i=k;i<n;i++)
 
 
//to print vector element 
//template<typename T>
//void printV(T vec){
	//fo(i,vec.size()) cout<<vec[i]<<" "<<flush;
	//cout<<endl;
	//}
	
 
//#define modulo 998244353
//const int INF=1e9+5;
 
 
 
 
//c++ template for help........................................................

int main() {
	//stringstream ss;
	//ss<<"akhil";
	//cout<<ss.str()<<endl;
	//cout<<setprecision(2);
	//ios::sync_with_stdio(0);
	//cin.tie(0);
	
	
	 // TESTCASE KO DEKH KA BHAUT SARA CONDITION GENERATE MAT KRO 
	 // PAPER PD CONFIRM HO JAO THORA JADA TIME HI KYU NA LGA
	 // greedy ma jadatr exceptional case check kr ke dekh lo
	 
	 // WHILE DOING THE QUESTION OF DYNAMIC PROGRAMMING GREEDY KA TRAH SOCHNA BAND KRO
	 // DP M DATA KA BHI USE KRNA PDTA HA BE BHULO MT 
	 // DP BHI WO LEETCODE WALE MATRIX KA QUESTION KI TARAH HA
	 // CONSTRAIN WILL BE THE DIMENSION OF DP
	 // DP MA STATE PTA KRO AUR PHIR FUNCTION GENERATE KRO
	 // OBJECT KO CHOOSE KIA YA NAE KIA AGAR KIA TO KYA HOGA AUR NAE KIA TO KYA HOGA
	 // KYA KYA CHEJ IMPORTANT HA WO STATE BN JYAGA AUR HUM LOG STATE KO CHANGE KR SKTA HA JYSA KNPSACK 2 WALE PROBLEM MA KIA THA
	 
	
	ll a,b,c,d;
	cin>>a>>b>>c>>d;
	
	while(a>0 and c>0){
		c=c-b;
		a=a-d;
	}
	
	if(c<=0) cout<<"Yes"<<endl;
	else cout<<"No"<<endl;
		
		
		
		
		
		
		
		
		
	 

	return 0;
}


Measured memory_bytes: 3636
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.ArrayList;


class Main {
	public static void main(String[] args) throws IOException {
		BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
		String s = new String(in.readLine());
		String[] ss = s.split(" ");
		int W = Integer.parseInt(ss[0]);
		int H = Integer.parseInt(ss[1]);
		int x = Integer.parseInt(ss[2]);
		int y = Integer.parseInt(ss[3]);
		int r = Integer.parseInt(ss[4]);
		
		if(x - r < 0 || y - r < 0){
			System.out.println("No");
		}
		else if(x + r > W || y + r > H){
			System.out.println("No");
		}
		else{
			System.out.println("Yes");
		}
		
	}

}

Measured memory_bytes: 17040
import java.util.Scanner;

class Main{
	public static void main(String[] args){
		Scanner scn = new Scanner(System.in);
		long n = Integer.parseInt(scn.next());
		long res = 1;
		for(long i=1;i<=n;i++){
			res = (res % 1000000007) * i;
		}
		System.out.println(res % 1000000007);
	}
}

Measured memory_bytes: 21716
/*
成績
2018/02/09
*/

#include<stdio.h>
int main(void){
  int m,f,r;/*中間試験、期末試験、再試験の点数*/
  int grade;
  while(1){
    scanf("%d %d %d",&m,&f,&r);
    if(m == -1 && f == -1 && r == -1)
      break;
    while(1){
      if(m ==-1 || f == -1){
	printf("F\n");
	break;
      }
      grade = m+f;
      if( grade >= 80){
	printf("A\n");
	break;
      }
      if( grade >= 65){
	printf("B\n");
	break;
      }
      if( grade >= 50 ||(grade >=30 && grade < 50 && r>=50)){
	printf("C\n");
	break;
      }
      if( grade >= 30){
	printf("D\n");
	break;
      }
      printf("F\n");
      break;
    }
  }
  return 0;
}


Measured memory_bytes: 2040
#pragma GCC optimize("Ofast")
#include<bits/stdc++.h>
using namespace std;
struct __INIT{__INIT(){cin.tie(0);ios::sync_with_stdio(false);cout<<fixed<<setprecision(15);}} __init;
#define max3(a,b,c) max(a,max(b,c))
#define min3(a,b,c) min(a,min(b,c))
constexpr int MOD=1000000007;
#define INF (1<<30)
#define LINF (lint)(1LL<<56)
#define endl "\n"
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define reprev(i,n) for(int (i)=(n-1);(i)>=0;(i)--)
#define Flag(x) (1<<(x))
#define Flagcount(x) __builtin_popcount(x)
#define pint pair<int,int>
#define pdouble pair<double,double>
#define plint pair<lint,lint>
#define fi first
#define se second
typedef long long lint;
int dx[8]={1,1,0,-1,-1,-1,0,1};
int dy[8]={0,1,1,1,0,-1,-1,-1};
const int MAX_N=2e5+5;

int main(void){
    double R;
    cin >> R;
    cout << R*2*M_PI << endl;
}

Measured memory_bytes: 3804
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        int w = scanner.nextInt();
        int n = scanner.nextInt();
        int kujis[] = new int[w];
        for (int i = 0; i < w; i++) {
            kujis[i] = i + 1;
        }
        for (int i = 0; i < n; i++) {
            String line = scanner.next();
            int a = Integer.valueOf(line.split(",")[0]) - 1;
            int b = Integer.valueOf(line.split(",")[1]) - 1;
            int tmp = kujis[a];
            kujis[a] = kujis[b];
            kujis[b] = tmp;
        }
        for (int i = 0; i < w; i++) {
            System.out.println(kujis[i]);
        }
        scanner.close();
    }
}



Measured memory_bytes: 26156