akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <math.h>
#include <string>
#include <algorithm>
#include <set>
#include <queue>
#include <stack>
#include <utility>
#include <tuple>
using namespace std;

const double pi = acos(-1);

#define nyan cout<<"(=^•ω•^=)"<<endl;
#define int long long
#define rep(i,n) for(int i=0;i<n;i++)

int N,M,X,Y;
int x[200],y[200];

signed main(){
    cin>>N>>M>>X>>Y;
    int xx=X;
    int yy=Y;
    rep(i,N){
        cin>>x[i];
        xx=max(xx,x[i]);
    }
    rep(i,M){
        cin>>y[i];
        yy=min(yy,y[i]);
    }
    if(xx<=yy-1)cout<<"No War"<<endl;
    else cout<<"War"<<endl;
    return 0;
}


Measured memory_bytes: 256
n = int(input())

sp = []
for i in range(n):
    s, p = input().split()
    sp.append((s, int(p), i+1))

sp_sort = sorted(sp, key=lambda x: (x[0], -1 * x[1]))

for i in range(n):
    print(sp_sort[i][2])


Measured memory_bytes: 3060
import math as m
N=int(input())
for i in range(N):
    a,b,c=map(int,input().split())
    A = min(a,min(b,c))
    C = max(a,max(b,c))
    B = a+b+c-A-C
    r=m.sqrt(A**2+B**2)
    if C == r:
        print("YES")
    else:
        print("NO")


Measured memory_bytes: 5660
#include <iostream>
#include <numeric>
#include <cmath>
#include <limits>
#include <stdio.h>
#include <iomanip>
#include <string> // string, to_string, stoi
#include <vector> // vector
#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <utility> // pair, make_pair
#include <tuple> // tuple, make_tuple
#include <cstdint> // int64_t, int*_t
#include <cstdio> // printf
#include <map> // map
#include <queue> // queue, priority_queue
#include <set> // set
#include <stack> // stack
#include <deque> // deque
#include <unordered_map> // unordered_map
#include <unordered_set> // unordered_set
#include <bitset> // bitset
#include <cctype> // isupper, islower, isdigit, toupper, tolower
using namespace std;
using ll = long long;
#define rep(i, n) for (long long i = 0; i < (long long)(n); i++)
ll Max(ll(a), ll(b), ll(c)) {
	return max(max(a, b), c);
}
ll Min(ll(a), ll(b), ll(c)) {
	return min(min(a, b), c);
}





int main() {
	ll N;
	cin >> N;
	vector<ll> A(N);
	vector<ll> B(N);
	rep(i, N) {
		cin>>A.at(i);
		B.at(A.at(i) - 1)++;
	}
	ll ana =0 ;
	rep(i, N) {
		ana += (B.at(i) * (B.at(i) - 1)) / 2;
	}
	rep(i, N) {
		cout << ana - B.at(A.at(i) - 1) + 1 << endl;
	}
	
}


Measured memory_bytes: 5760
#include <iostream>
#include <set>
#include <algorithm>
using namespace std;

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    int n,command,x,l,r;
    set<int> mySet;
    set<int>::iterator begin;
    set<int>::iterator end;
    cin >> n;

    for(int i = 0;i < n;++i){
        cin >> command;
        if(command == 0){
            cin >> x;
            mySet.insert(x);
            cout << mySet.size() << endl;
        }else if(command == 1){
            cin >> x;
            bool find = mySet.find(x) != mySet.end() ? true : false;
            cout << find << endl;
        }
        else if(command == 2){
            cin >> x;
            mySet.erase(x);
        }
        else{
            cin >> l >> r;
            begin = mySet.lower_bound(l);
            end = mySet.upper_bound(r);

            for(;begin != end;++begin){
                cout << *begin << endl;
            }
        }
    }
}



Measured memory_bytes: 12508
#include<bits/stdc++.h>
#define M 205
using namespace std;

int main(){
  while(1){
    int m,nmin,nmax,g=-1,ans,p[M];
    cin>>m>>nmin>>nmax;
    if(!m&&!nmin&&!nmax)break;
    for(int i=1;i<=m;i++)cin>>p[i];
    for(int n=nmin;n<=nmax;n++){
      if(p[n]==p[n+1])continue;
      if(g<=p[n]-p[n+1]){
	g=p[n]-p[n+1];
	ans=n;
      }
    }
    cout<<ans<<endl;
  }
  return 0;
}

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

using namespace std;

using ll = long long;

int main() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    int a,b,c;
    cin >> a >> b >> c;
    cout << (a + b + c >= 22 ? "bust" : "win") << endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
typedef pair<int, P> P1;
typedef pair<P, P> P2;
#define pu push
#define pb push_back
#define mp make_pair
#define eps 1e-7
#define INF 10000000000000
#define fi first
#define sc second
#define rep(i, x) for (long long i = 0; i < x; i++)
#define repn(i, x) for (long long i = 1; i <= x; i++)
#define SORT(x) sort(x.begin(), x.end())
#define ERASE(x) x.erase(unique(x.begin(), x.end()), x.end())
#define POSL(x, v) (lower_bound(x.begin(), x.end(), v) - x.begin())
#define POSU(x, v) (upper_bound(x.begin(), x.end(), v) - x.begin())
vector<pair<string, P> > vec;
// vector<vector<int>> data(3, vector<int>(4));

void solve(long long N, std::vector<long long> A, std::vector<long long> B) {
    {
        bool flg = true;
        rep(i, N) {
            if (A[i] != B[i]) flg = false;
        }
        if (flg) {
            cout << "0" << endl;
            return;
        }
    }

    ll minb = INF;
    rep(i, N) {
        if (A[i] > B[i]) minb = min(minb, B[i]);
    }

    ll sum = 0;
    rep(i, N) sum += A[i];
    cout << sum - minb << endl;
}

int main() {
    long long N;
    scanf("%lld", &N);
    std::vector<long long> A(N);
    std::vector<long long> B(N);
    for (int i = 0; i < N; i++) {
        scanf("%lld", &A[i]);
        scanf("%lld", &B[i]);
    }
    solve(N, std::move(A), std::move(B));
    return 0;
}


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

int main() {
  int n;
  cin >> n;
  vector<pair<int, int>> op, cl;
  long long total = 0;
  for (int i = 0; i < n; i++) {
    string s;
    cin >> s;
    int res = 0, dep = 0;
    for (char c : s) {
      res += (c == '(' ? 1 : -1);
      dep = min(res, dep);
    }
    if (res > 0) op.push_back({dep, res});
    else cl.push_back({dep - res, -res});
    total += res;
  }
  if (total != 0) {
    cout << "No" << endl;
    return 0;
  }
  total = 0;
  sort(op.rbegin(), op.rend());
  for (auto p : op) {
    if (total + p.first < 0) {
      cout << "No" << endl;
      return 0;
    }
    total += p.second;
  }
  total = 0;
  sort(cl.rbegin(), cl.rend());
  for (auto p : cl) {
    if (total + p.first < 0) {
      cout << "No" << endl;
      return 0;
    }
    total += p.second;
  }
  cout << "Yes" << endl;
  return 0;
}

Measured memory_bytes: 11132
#include <bits/stdc++.h>
#include <math.h>
#define ALL(a)    a.begin(), a.end() 
#define rep(i, K, N)  for(long long int i = K; i < N; i++)
#define ll long long int
#define PP 1000000007
using namespace std;



int main(){
ll N;cin >> N;
bool C = 0;
  
rep(n, 1, 3501){

  rep(h, 1, 3501){
    
      if((4*h*n - N*n - N*h) == 0)continue;

      ll w = (N*n*h)/(4*h*n - N*n - N*h);

      if((N*n*h)%(4*h*n - N*n - N*h) == 0 && 0 <= w && w <= 3500){

        cout << h << " " << n << " " << w;C = 1;break;

      }

  }
  
if(C)break;
  
}
}

Measured memory_bytes: 3676
n, x, y = map(int, input().split())
dic={}
for i in range(1, n+1):
    for j in range(i+1,n+1):
        m = min(abs(y-j)+abs(x-i)+1,j-i)
        if m in dic.keys():
            dic[m] += 1
        else:
            dic[m] =1

for z in range(1,n):
    if z in dic.keys():
        print(dic[z])
    else:
        print(0)

Measured memory_bytes: 3572
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<ll, ll> l_l;
typedef pair<int , int> i_i;
typedef vector<ll> vel;
typedef vector<int> vei;
typedef vector<char> vec;
typedef vector<bool> veb;
typedef vector<string> ves;
typedef vector<vector<ll>> ve_vel;
typedef vector<vector<int>> ve_vei;
typedef vector<vector<char>> ve_vec;
typedef vector<vector<bool>> ve_veb;
typedef vector<vector<string>> ve_ves;
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define rep1(i,n) for(int i=1;i<(int)(n);i++)
#define rep2(i,n) for(int i=2;i<(int)(n);i++)
#define repk(i,k,n) for(int i=k;i<(int)(n);i++)
#define fs first
#define sc second
#define pub push_back
#define pob pop_back
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define maxel(a) *max_element(all(a))
#define minel(a) *min_element(all(a))
#define acc accumulate
#define EPS (1e-7)
//#define INF (1e9)
#define PI (acos(-1))
#define mod (1000000007)
typedef long long int64;
const int64 INF = 1LL << 58;
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 (a>b) { a=b; return 1; } return 0; }

#define MAX_N 60000
int prime[MAX_N]; //i番目の素数
bool is_prime[MAX_N+1]; //is_prime[i]==true->iはprime

//n以下の素数の数を返す
void sieve(int n) {
    int p = 0;
    rep(i,n+1) is_prime[i] = true;
    is_prime[0] = is_prime[1] = false;
    rep2(i,n+1) {
        if(is_prime[i]) {
            prime[p++] = i;
            for(int j = 2 * i; j<= n; j+= i) is_prime[j] = false;
        }
    }
    return ;
}


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

    int N; cin >> N;
    sieve(MAX_N);
    vei ans; int size;
    for(int i = 6; i <= 55555; i += 5) {
        if(is_prime[i]) { ans.pub(i); size++; }
        if(size == N) break;
    }
    rep(i,N) cout << ans[i] << endl;

}

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

#define _GLIBCXX_DEBUG
#define all(v) (v).begin(),(v).end()

using ll=long long;
using pii=pair<int, int>;
using vi=vector<int>;
using vii=vector<vector<int>>;

const ll LINF=1LL<<60;
const int INF=1<<29;
const ll MOD=1e9+7;

template<typename T> bool chmax(T &a,const T b){if(a < b){a=b; return true;} return false;}
template<typename T> bool chmin(T &a,const T b){if(a > b){a=b; return true;} return false;}

template <class T>
struct PrimeFact{
    vector<T> spf;
    PrimeFact(T N) {init(N);}
    void init(T N){
        spf.assign(N+1, 0);
        for(T i=0; i<=N; i++) spf[i]=i;
        for(T i=2; i*i<=N; i++){
            if(spf[i] == i){
                for(T j=i*i; j<=N; j+=i){
                    if(spf[j] == j){
                        spf[j]=i;
                    }
                }
            }
        }
    }
    map<T, T> get(T n){
        map<T, T> mp;
        while(n != 1){
            mp[spf[n]]++;
            n/=spf[n];
        }
        return mp;
    }
};


int main(){
    int N; cin >> N;
    vi A(N);
    for(auto &x : A) cin >> x;

    int G=A[0];
    for(int i=1; i<N; i++){
        G=__gcd(G, A[i]);
    }

    PrimeFact<int> p(1001001);
    vi cnt(1001001, 0);
    bool ok=true;
    for(int i=0; i<N; i++){
        while(A[i] != 1){
            int val=p.spf[A[i]];
            if(cnt[val]) ok=false;
            cnt[p.spf[A[i]]]++;
            while(p.spf[A[i]/val] == val){
                A[i]/=val;
            }
            A[i]/=val;
        }
    }
    if(ok){
        cout << "pairwise coprime" << endl;
        return 0;
    }

    
    if(G == 1) cout << "setwise coprime" << endl;
    else cout << "not coprime" << endl;
    return 0;
}

Measured memory_bytes: 15116
#include <iostream>
#include <algorithm>
#include <math.h>
#include <string>
using namespace std;
int main(){
  int A,B, C, D ,E ,F;
  string S,Sa,Sb,Sc;
  cin >> A >> B >> C;
  int ans;
if(A == B && B == C)ans = 1;
else if(A == B || B == C || A == C)ans = 2;
else ans = 3;
cout << ans << endl;
        return 0;
}

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

using namespace std;

typedef long long ll;

int special[210], prefix[210];

int factors(int a)
{
	int ans = 0;
	for(int i = 1; i <= a; i++)
	{
		if(a % i == 0)
			ans += 1;
	}
	return ans;
}

int main()
{
	int N;
	cin >> N;
	memset(special, 0, sizeof(special));
	for(int i = 1; i <= N; i += 2)
	{
		if(factors(i) == 8)
			special[i] = 1;
	}
	prefix[0] = 0;
	for(int i = 1; i <= N; i++)
	{
		prefix[i] = prefix[i - 1] + special[i];
	}
	cout << prefix[N] << endl;
	return 0;
}

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

MAX = 5 * 10 ** 5

fact = [1] * (MAX + 1)
for i in range(1, MAX + 1):
    fact[i] = (fact[i-1] * i) % mod

inv = [1] * (MAX + 1)
for i in range(2, MAX + 1):
    inv[i] = inv[mod % i] * (mod - mod // i) % mod

fact_inv = [1] * (MAX + 1)
for i in range(1, MAX + 1):
    fact_inv[i] = fact_inv[i-1] * inv[i] % mod


def comb(n, k):
    if n < k:
        return 0
    return fact[n] * fact_inv[n-k] * fact_inv[k] % mod


p1 = 1
p2 = 1

for i in range(m, m - n, -1):
    p2 *= i
    p2 %= mod

ans = 0
for i in range(n + 1):
    ans += (-1) ** (i % 2) * comb(n, i) * p1 * p2 ** 2
    ans %= mod

    p1 *= m - i
    p1 %= mod

    p2 *= inv[m - i]
    p2 %= mod

print(ans)


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

int main() {
    int x, y;
    cin >> x >> y;
    if (y % 2 == 1) {
        cout << "No" << endl;
        return 0;
    }
    if (x * 4 < y) {
        cout << "No" << endl;
        return 0;
    }
    if (x * 2 > y) {
        cout << "No" << endl;
        return 0;
    }
    cout << "Yes" << endl;
    
    return 0;
}

Measured memory_bytes: 3588
#include <stdio.h>
#include <math.h>
#define N 10000

int isPrime(int);

int main(){

  int i,j,n,x,key,count=0;
  int a[N];
  scanf("%d",&n);
  for(i=0;i<n;i++){
    scanf("%d",&a[i]);
  }
  
  for(i=0;i<n;i++){
    if(isPrime(a[i])){
     
      count++;
    }
  }
  
  
  printf("%d\n",count);
  
  return 0;
}
  
int isPrime(int x){

  int i;
  if(x<=1) return 0;

  for(i=2;i*i<=x;i++){
    if(x%i==0){
      return 0;
    }
  }

  return 1;
}

Measured memory_bytes: 2696
#include<bits/stdc++.h>
using namespace std;
int n,m,cnt,ans=0, k[20],x[20][20][2],s[11][11],sw[20] = {0};
bool judge(){
    for(int i = 1; i <= n; i++){
        if(sw[i]){
            for(int j = 1; j <= k[i]; j++){
                if(sw[x[i][j][0]] != x[i][j][1])
                return 0;
            }
        }
    }
    return 1;
}
 
int main(){
    cin >> n;
    for(int i = 1; i <= n; i++){
        cin >> k[i];
        for(int j = 1; j <= k[i]; j++){
            cin >> x[i][j][0] >> x[i][j][1];
        }
    }
    for(int i = 0; i < (1 << n+1); i+=2){
        for(int j = 1; j <= n; j++){
            if(i >> j & 1)
                sw[j] = 1; 
            else
                sw[j] = 0;
        }
        if(judge()){
            cnt = 0;
            for(int j = 1; j <= n; j++){
                if(sw[j])
                    cnt++;
            }
            ans = max(ans,cnt);
        }  
    } 
    cout << ans << endl;
}


Measured memory_bytes: 256
#!/usr/bin/env python3
import sys


def solve(S: str, T: str, A: int, B: int, U: str):
    print(str(A-1) + " " + str(B) if U == S else str(A) + " " + str(B-1))
    return


# Generated by 1.1.6 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    S = next(tokens)  # type: str
    T = next(tokens)  # type: str
    A = int(next(tokens))  # type: int
    B = int(next(tokens))  # type: int
    U = next(tokens)  # type: str
    solve(S, T, A, B, U)

if __name__ == '__main__':
    main()


Measured memory_bytes: 3064
#include <stdio.h>

    int main(void){
    char str[100];
    int i;
    int count=0;
    
    scanf("%s",str);
    
    for(i=0;str[i]!='\0';i++){
        count++;
    }
    for(i=count-1;i>=0;i--){
        printf("%c",str[i]);
    }
    printf("\n");

    return 0;
}




Measured memory_bytes: 2068
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int max_n=205;
string s,t;
int n;
int main(){
    cin>>n>>s>>t;
    string res="";
    for(int i=0;i<n;i++){
        res+=s[i];
        res+=t[i];
    }
    cout<<res<<endl;
}

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

#define pb(n) push_back(n)
#define fi first
#define se second
#define all(r) (r).begin(),(r).end()
#define gsort(st,en) sort((st),(en),greater<int>())
#define vmax(ary) *max_element(all(ary))
#define vmin(ary) *min_element(all(ary))
#define debug(x) cout<<#x<<": "<<x<<endl
#define fcout(n) cout<<fixed<<setprecision((n))
#define scout(n) cout<<setw(n)
#define vary(type,name,size,init) vector< type> name(size,init)

#define rep(i,n) for(int i = 0; i < (int)(n);++i)
#define REP(i,a,b) for(int i = (a);i < (int)(b);++i)
#define repi(it,array) for(auto it = array.begin(),end = array.end(); it != end;++it)
#define repa(n,array) for(auto &n :(array))

using ll = long long;
using vi = vector<int>;
using vl = vector<ll>;
using dict = map<string,int>;
using pii = pair<int,int> ;
using pll = pair<ll,ll> ;

const int mod = 1000000007;
constexpr int imax = ((1<<30)-1)*2+1 ;
constexpr int inf = 100000000;
constexpr double PI = acos(-1.0) ;
double eps = 1e-10 ;
const int dy[] = {-1,0,1,0};
const int dx[] = {0,-1,0,1};

inline bool value(int x,int y,int w,int h){
  return (x >= 0 && x < w && y >= 0 && y < h);
}

struct Edge{
  int to;
  long long cost;
};

struct NODE{
  int pos;
  long long cost;
};
bool operator < (const NODE &a,const NODE &b){
  return a.cost > b.cost;
}
vector<Edge> g[100000],rg[100000];

int N;
const ll INF = 1e15;
vector<ll> dijkstra(vector<Edge> g[100000], int s){
  priority_queue<NODE> Q;
  Q.push({s,0});
  vector<ll> res(N,INF);
  while(Q.size()){
    NODE q= Q.top();Q.pop();
    if(res[q.pos] == INF){
      res[q.pos] = q.cost;
    }
    else{
      continue;
    }
    for(auto n : g[q.pos]){
      Q.push({n.to,q.cost+n.cost});
    }
  }
  return res;
}

int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  int n,m,p,a,b,e;
  while(cin >> n >> m && n && m){
    N = n;
    rep(i,101){
      g[i].clear();
    }
    rep(i,m){
      cin >> p ;
      if(!p){
        cin >> a >> b;
        --a,--b;
        auto d = dijkstra(g,a);
        if(d[b] == INF){
          cout << -1 << endl;
        }
        else{
          cout << d[b]<<endl;
        }
      }
      else{
        cin >> a >> b >> e;
        --a,--b;
        g[a].push_back({b,e});
        g[b].push_back({a,e});
      }
    }
  }
  return 0;
}

Measured memory_bytes: 7928
def resolve():
    a, b, c, x, y = map(int, input().split())

    n_c = min(x, y)

    if (n_c * 2) * c < n_c * (a + b):
        if x - y >= 0:
            if a/2 < c:
                print(n_c * 2 * c + (x - y) * a)
            else:
                print(n_c * 2 * c + (x - y) * 2 * c)
        else:
            if b/2 < c:
                print(n_c * 2 * c + (y - x) * b)
            else:
                print(n_c * 2 * c + (y - x) * 2 * c)
    else:
        print(a * x + b * y)


if __name__ == "__main__":
    resolve()

Measured memory_bytes: 38384
#pragma GCC target("avx2")
#pragma GCC optimize("O3")
   
#include <x86intrin.h>
#include <bits/stdc++.h>   
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
 
using namespace __gnu_pbds;
using namespace std;

template<typename T> using ordered_set = tree <T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
     
#define F first
#define S second           
#define lb lower_bound               
#define ub upper_bound
#define pb push_back
#define pf push_front    
#define ppb pop_back
#define mp make_pair                                     
#define bpp __builtin_popcountll                                                                                        
#define sqr(x) ((x) * (x)) 
#define al 0x3F3F3F3F
#define sz(x) (int)x.size()
#define all(x) x.begin(), x.end()
#define in insert
#define ppf pop_front
#define endl '\n'
//#define int long long
 
typedef unsigned long long ull;
typedef long long ll;
typedef long double ld;
typedef pair <int, int> pii;
 
const int mod = (int)1e9 + 7;
const int N = (int)404;
const ll inf = (ll)1e18 + 1;

const double pi = acos (-1.0);
const double eps = 1e-7;                  
const int dx[] = {0, 0, 1, 0, -1};
const int dy[] = {0, 1, 0, -1, 0};

int n, a[N];
ll dp[N][N];
ll pref[N];

ll calc (int l = 1, int r = n) {
   if (l >= r) return 0;
   if (r - l == 1) return a[l] + a[r];
   ll &res = dp[l][r];
   if (res != -1) return res;
   res = inf;
   for (int mid = l; mid <= r; mid ++) res = min (res, calc (l, mid) + calc (mid + 1, r) + pref[r] - pref[l - 1]);  
   return res;
}

inline void boost () {                    
   ios_base :: sync_with_stdio (NULL);
   cin.tie (NULL), cout.tie (NULL);          
}                                                     

inline void Solve () {
   cin >> n;
   for (int i = 1; i <= n; i ++) cin >> a[i], pref[i] = pref[i - 1] + a[i];
   memset (dp, -1, sizeof dp);
   cout << calc ();
}

main () {                                       
// freopen (".in", "r", stdin);    
// freopen (".out", "w", stdout);              
   boost ();
   int tt = 1;
   //cin >> tt;   
   while (tt --) {
      Solve ();
   }                                               
   return 0;      
}
                          

Measured memory_bytes: 1664
import java.util.Scanner;
public class Main {
	public static void main(String[] args) {
		Scanner stdIn=new Scanner(System.in);
		int N=stdIn.nextInt();
		String S=stdIn.next();
		int K=stdIn.nextInt();
		int z=0;
		String a="";
		char s=S.charAt(K-1);
		while(z<N){
			if(S.charAt(z)!=s)
				a+="*";
			else
				a+=s;
			z++;
		}
		System.out.println(a);
	}
}

Measured memory_bytes: 21076
#include<iostream>
int main(){
  int M1,M2,D1,D2;
  std::cin >> M1 >> D1;
  std::cin >> M2 >> D2;
  if (D2 - D1 < 0){
    std::cout << 1;
    return 0;
  }else{
    std::cout << 0;
    return 0;
  }
}

Measured memory_bytes: 256
import java.util.Scanner;
public class Main{
    public static void main(String[] args){
	Scanner scan = new Scanner(System.in);
	String str = "";	
	while(true){
	    str = scan.next();
	    if(str.equals("#END")){
		return;
	    }else{
		System.out.println(rs(str));
	    }	    
	}
    }
    public static String rs(String str){
	char[] chr = str.toCharArray();
	int cl = chr.length;
	int[][] m = new int[cl][cl];
	String RS = "";
	char[] c_RS = new char[cl/2 + 1];
	int RSl = 0;
	for(int k = 0; k < cl; k++) m[k][0] = 0;
	for(int k = 0; k < cl; k++) m[0][k] = 0;
	
	int i = 1;
	int j = 1;
	for(int split = 1; split < cl; split++){
	    for(int k = 0; k < cl/2 + 1; k++) c_RS[k] = ' ';
	    i = 1;
	    while(i <= split){
		j = 1;
		while(j <= cl - split){
		    if(chr[i-1] == chr[j-1+split]) m[i][j] = m[i-1][j-1] + 1;
		    else m[i][j] = Math.max(m[i-1][j],m[i][j-1]);
		    j++;
		}
		i++;
	    }

	    i--;
	    j--;
	    RSl = m[i][j];
	    if(RSl > RS.length()){
		RS = "";
		while(i > 0 && j > 0){
		    if(m[i][j] == m[i-1][j])i--;
		    else if(m[i][j] == m[i][j-1])j--;
		    else{
			c_RS[m[i][j]] = chr[i-1];
			i--;
			j--;
		    }
		}
		for(int k = 1; k <= RSl; k++){
		  RS += c_RS[k];
		}
	    }
	}
	return RS;
    }
}

Measured memory_bytes: 61936
import java.io.*;
import java.math.BigInteger;
import java.util.*;
import java.util.Stack;

public class Main{
	public static class FastReader {
		BufferedReader br;
		StringTokenizer root;
		
 
		public FastReader() {
			br = new BufferedReader(new InputStreamReader(System.in));
		}
 
		String next() {
			while (root == null || !root.hasMoreTokens()) {
				try {
					root = new StringTokenizer(br.readLine());
				} catch (Exception r) {
					r.printStackTrace();
				}
			}
			return root.nextToken();
		}
 
		int nextInt() {
			return Integer.parseInt(next());
		}
 
		double nextDouble() {
			return Double.parseDouble(next());
		}
 
		long nextLong() {
			return Long.parseLong(next());
		}
 
		String nextLine() {
			String str = "";
			try {
				str = br.readLine();
			} catch (Exception r) {
				r.printStackTrace();
			}
			return str;
		}
	}
	
	public static PrintWriter out = new PrintWriter (new BufferedOutputStream(System.out));
	static int mod = (int) (1e9+7);
	static long cf = 998244353;
    static final int MAX = (int) 1e6;
    public static List<Pair>[] edges;
    public static int[][] parent;
    public static int col = 20;
    public static long[] Bit;
    public static long[] fac,inv;
    public  static int[] prime; 
    public static long[] dp;
	public static FastReader sc = new FastReader();
	public static void main(String[] args) {
	//	Scanner sc = new Scanner(System.in);
 
		int n = sc.nextInt(),m=sc.nextInt();
		boolean[] vis = new boolean[n+1];
		for(int i=0;i<m;i++){
		int idx = sc.nextInt();
		vis[idx]=true;
		}
		dp = new long[n+1];
		dp[0]=1;
		if(!vis[1])
		dp[1]=1;
		for(int i=2;i<=n;i++){
			if(vis[i])
			continue;
			dp[i]=(dp[i-1]+dp[i-2])%mod;
		}
		 out.print(dp[n]);
		out.close();
	}

	
	static class Pair{
		int x;
		int y;
		Pair(int x,int y){
			this.x = x;
			this.y = y;
		}
	}
	
}

Measured memory_bytes: 34112
def partition(A, p, r):
    x = A[r]
    i = p-1
    for j in range(p,r):
        if A[j] <= x:
            i = i+1
            A[i],A[j]=A[j],A[i]
    A[i+1],A[r]=A[r],A[i+1]
    return i+1

n=int(input())
Astr=input().split( )
A=[int(Astr[i]) for i in range(n)]

c=partition(A,0,n-1)

print(*A[0:c],end=" ")
print(f"[{A[c]}]",end=" ")
print(*A[c+1:n])



Measured memory_bytes: 16640
#include <bits/stdc++.h>
#define FOR(i,a,b) for(int i = (a); i < (b); ++i)
#define REP(i,n) FOR(i,0,n)
#define RREP(i,n) for(int i = (n) - 1; (i) >= 0; --i)
#define SZ(n) (int)(n).size()
#define ALL(n) (n).begin(), (n).end()
#define MOD LL(1e9 + 7)
#define INF 1000000
using namespace std;
using LL = long long;

int main() {
	int m, f, r;
	while (cin >> m >> f >> r) {
		if (m + f + r == -3) { break; }
		else if (m == -1 || f == -1) { cout << "F" << endl; }
		else if (m + f >= 80) { cout << "A" << endl; }
		else if (m + f >= 65) { cout << "B" << endl; }
		else if (m + f >= 50) { cout << "C" << endl; }
		else if (m + f >= 30) {
			if (r >= 50) { cout << "C" << endl; }
			else { cout << "D" << endl; }
		}
		else if (m + f < 30) { cout << "F" << endl; }
	}
	return 0;
}



Measured memory_bytes: 3076
c = [0] * 3
for i in range(3):
    c[i] = int(input())
x = int(input())
cnt = 0
for i in range(c[0] + 1):
    for j in range(c[1] + 1):
        req = x - (i * 500 + j * 100)
        if req >= 0 and req % 50 == 0 and req // 50 <= c[2]:
            cnt += 1
print(cnt)


Measured memory_bytes: 9120
A="".join(["11000000",
           "11"])

B="".join(["10000000",
           "10000000",
           "10000000",
           "1"])

C="".join(["1111"])

D="".join(["01000000",
           "11000000",
           "1"])

E="".join(["11000000",
           "011"])

F="".join(["10000000",
           "11000000",
           "01"])

G="".join(["01100000",
           "11"])

teto=[A,B,C,D,E,F,G]

while True:
    try:
        a="".join([raw_input() for i in xrange(8)])
        for i in range(len(teto)):
            if a.find(teto[i])>=0:
                print chr(i+ord("A"))
        raw_input()
    except:
        break
#temp

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

int main(){
	int D;
	cin>>D;
	if(D==25){
		cout<<"Christmas"<<endl;
	}else if(D==24){
		cout<<"Christmas Eve"<<endl;
	}else if(D==23){
		cout<<"Christmas Eve Eve"<<endl;
	}else if(D==22){
		cout<<"Christmas Eve Eve Eve"<<endl;
	}
	return 0;
}

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

#define rep(i,z) for(int i = 0; i<(int)(z); i++)
#define rep1(i,z) for(int i = 1; i<=(int)(z); i++)
 
using namespace std;

typedef long long ll;
const ll MOD=1e9+7;
using pear = pair<int,int>;




int main(){
   int  n; cin>>n;
   ll max = 0, ans = 0;
   rep(i ,n){
       ll a, b; cin>>a >>b;
       if(a > max){
           max = a;
           ans = a + b;
       }
   }
   cout<<ans<<endl;
}

Measured memory_bytes: 3604
//shan61916
#include <bits/stdc++.h>
  using namespace std;
typedef   long long ll;
typedef   unsigned long long ull ;
typedef   double dll ;

#define   mp make_pair
#define   pb push_back
#define   ff first 
#define   ss second
#define   IOS ios::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define   endl "\n" 
#define   pll pair<ll, ll>
#define   all(x) x.begin(), x.end()
#define   vll vector<ll> 

const ll inf = (ll)(1e17 + 17);
const ll mod = (ll)(1e9 + 7);


int main(){
 IOS
#ifdef SHAN
    freopen("input.txt" , "r" , stdin);  
#endif
  ll m1, d1, m2, d2; 
  cin >> m1 >> d1 >> m2 >> d2;
  if(d2 < d1) {
    cout << 1;
  } else cout << 0;
  return 0;
} //good night.

Measured memory_bytes: 256
import math
array=[2]
for i in range(3,100004,2):
    prime=True
    for n in range(len(array)):
        if array[n] > math.sqrt(i):
            break
        if i % array[n] == 0:
            prime = False
            break
    if prime:
        array.append(i)
l=int(input())
for m in range(len(array)):
    if l>array[m]:
        pass
    else:
        print(array[m])
        break

Measured memory_bytes: 3336
#include<bits/stdc++.h>
using namespace std;
#define ioS            ios::sync_with_stdio(false);cin.tie(0);
#define li             long int
#define ll             long li
#define ull            unsigned ll
#define pi             pair<int,int>
#define vi             vector<int>
#define vli            vector<li>
#define vll            vector<ll>
#define vvi            vector<vector<int>>
#define pb             push_back
#define mp             make_pair
#define forn(i,s,n)    for(auto i=s;i<n;++i)               
#define forr(i,s,n)    for(auto i=s;i>=n;--i) 
#define all(x)         (x).begin(),(x).end()
const ll mx = 1e9;
string alpha = "abcdefghijklmnopqrstuvwxyz";

void solve(int test)
{
    ll a,b,c,d;
    cin>>a>>b>>c>>d;
    ll ans = b*d;
    ans = max(ans,a*c);
    ans = max(ans,a*d);
    ans = max(ans,b*c);

    cout<<ans<<endl;
}   
int32_t main()
{
    ioS    
    int t;
    // cin>>t;
    // forn(i,1,t+1)
        solve(0);
    return 0;
}

Measured memory_bytes: 3628
#include "bits/stdc++.h"
#include "ext/pb_ds/assoc_container.hpp"
#include "ext/pb_ds/tree_policy.hpp"

using namespace std;
using namespace __gnu_pbds;


#define ll long long int
#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define all(a) a.begin(),a.end()

typedef tree <ll, null_type, less <ll>, rb_tree_tag, tree_order_statistics_node_update> ordered_set;
// order_of_key(val): returns the number of values less than val
// find_by_order(k): returns an iterator to the kth largest element (0-based)
ll freq[1000001];
int main(void)
{
	ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    ll n, i, j;
    cin>>n;
    ll ans = 0;
    ll a[n];
    for(i = 0; i < n; i++) {
    	ll temp;
    	cin>>a[i];
    	freq[a[i]]++;
    }
    for(i = 0; i < n; i++) {
    	freq[a[i]]--;
    	bool flag = true;
    	for(j = 1; j*j <= a[i]; j++) {
    		if(a[i] % j == 0) {
    			ll l = j;
    			ll r = a[i] / j;
    			if(freq[r]!= 0 || freq[l] != 0){
    				flag = false;
    				break;
    			}
    		}
    	}
    	if(flag) {
    		ans++;
    	}
    	freq[a[i]]++;
    }
    cout<<ans<<"\n";
}

Measured memory_bytes: 13012
package main

import (
	"fmt"
	"math"
)

func main() {
	var a, b, c, s, l, h float64
	fmt.Scan(&a, &b, &c)
	s = a * b * math.Sin(math.Pi*c/180) / 2
	l = a + b + math.Sqrt(math.Pow(a, 2)+math.Pow(b, 2)-2*a*b*math.Cos(math.Pi*c/180))
	h = s / a * 2
	fmt.Printf("%f\n", s)
	fmt.Printf("%f\n", l)
	fmt.Printf("%f\n", h)
}



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


int main() {
	int A;
	int B;
	int C;
	int i = 0;
	int ans = 0;

	scanf("%d %d", &A, &B);
	
	while (ans == 0 ) {
		C = A * i - (i - 1);
		if (C >= B) {
			ans = i;
			break;
		}
		i = i + 1;

	}

	printf("%d", ans);

	return 0;
}



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

int main(){
    
    double w,h,x,y;
    cin >> w >> h >> x >> y;

    cout << fixed <<setprecision(9) << w*h/2 << ' ';
    if(x==w/2 && y==h/2) cout << 1 << endl;
    else cout << 0 << endl;
}

Measured memory_bytes: 3748
//
// AtCoder ABC123-A - Five Antennas
//
#include <bits/stdc++.h>
using namespace std;


int main(){
    int k;
    int pos[5];

    cin >> pos[0];
    cin >> pos[1];
    cin >> pos[2];
    cin >> pos[3];
    cin >> pos[4];
    cin >> k;

    string ans = "Yay!";

    for(int i=0; i<4; i++) {
        for(int j=i+1; j<5; j++) {

            if(pos[j] - pos[i] > k) {
                ans = ":(";
                cout << ans << endl;
                return 0;
            }
        }
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<algorithm>

using namespace std;

const long long mod=1e9+7;

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

	vector<long long> oks(N+1, true);
	for(int i=0; i<M; ++i){
		int a;cin >> a;
		oks[a]=false;
	}

	vector<long long> dp(N+1);
	dp[0]=1;
	for(int now=0; now<N; ++now){
		for(int next=now+1; next<=min(N, now+2) ;++next){
			if(oks[next]){
				dp[next]+=dp[now];
				dp[next]%=mod;
			}
		}
	}
	cout << dp[N] << endl;
}

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

ll dp[3001][3001][5];
int a[3005][3005];

int main(){
    int r,c,k;
    cin >> r >> c >> k;
    
    for(int i = 0;i < k;i++){
        int x,y,v;
        cin >> x >> y >> v;
        a[x-1][y-1] = v;
    }
    
    for(int i = 0;i < r;i++){
        for(int j = 0;j < c;j++){
            for(int l = 0;l < 3;l++){
                dp[i+1][j+1][l+1] = max(dp[i+1][j+1][l+1],dp[i+1][j][l+1]);
                rep(z,4)dp[i+1][j+1][l+1] = max(dp[i+1][j+1][l+1],dp[i][j+1][z]+a[i][j]);
                dp[i+1][j+1][l+1] = max(dp[i+1][j+1][l+1],dp[i+1][j][l]+a[i][j]);
            }
        }
    }
    
    ll ans = 0;
    for(int i = 0;i <= c;i++){
        for(int j = 0;j <= 3;j++){
            ans = max(ans,dp[r][i][j]);
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 390172
import java.io.InputStream;
import java.io.PrintStream;
import java.util.HashSet;
import java.util.Scanner;
import java.util.Set;

public class Main {

  public static void main(String[] args) {
    resolve(System.in, System.out);
  }

  static void resolve(InputStream is, PrintStream pw) {
    Scanner sc = new Scanner(is);
    int x = Integer.parseInt(sc.next());
    int n = Integer.parseInt(sc.next());
    Set<Integer> forbidden = new HashSet<>();
    for (int i = 0; i < n; i++) {
      int p = Integer.parseInt(sc.next());
      forbidden.add(p);
    }
    int min = Integer.MAX_VALUE;
    int ans = -10;
    for (int i = -10; i <= 110; i++) {
      if (forbidden.contains(i)) {
        continue;
      }
      int abs = Math.abs(x - i);
      if (abs < min) {
        ans = i;
        min = abs;
      }
    }
    pw.println(ans);
  }
}


Measured memory_bytes: 35832
n,k=map(int,input().split())
a=[int(i) for i in input().split()]
k=min(k,41)

for j in range(k):
    b=[0 for i in range(n)]
    for i in range(n):
        l=max(0,i-a[i])
        r=min(n-1,i+a[i])
        b[l]+=1
        if r+1<n:
            b[r+1]-=1
    for i in range(1,n):
      b[i]+=b[i-1]
    a=b
print(" ".join(map(str,a)))

Measured memory_bytes: 171856
#[macro_use]
mod input {

use std;
use std::io;

const SPLIT_DELIMITER: char = ' ';

#[macro_export]
#[allow(unused_macros)]
macro_rules! input {
    ( $($x:expr ),*) => {
        {
            let temp_str = input_line_str();
            let mut split_result_iter = temp_str.split_whitespace();
                $(
                let buf_split_result = split_result_iter.next();
                let buf_split_result = buf_split_result.unwrap();
                    ($x) = buf_split_result.parse().unwrap();
                )*
        }
    };
}

#[allow(dead_code)]
pub fn input_line_str() -> String {
    let mut s = String::new();
    io::stdin().read_line(&mut s).unwrap();
    s.trim().to_string()
}

#[allow(dead_code)]
pub fn p<T>(t: T)
where
    T: std::fmt::Display,
{
    println!("{}", t);
}

#[allow(dead_code)]
pub fn input_vector2d<T>(line: usize) -> Vec<Vec<T>>
where
    T: std::str::FromStr,
{
    let mut v: Vec<Vec<T>> = Vec::new();

    for _ in 0..line {
        let vec_line = input_vector();
        v.push(vec_line);
    }
    v
}

#[allow(dead_code)]
pub fn input_vector<T>() -> Vec<T>
where
    T: std::str::FromStr,
{
    let mut v: Vec<T> = Vec::new();

    let s = input_line_str();
    let split_result = s.split(SPLIT_DELIMITER);
    for z in split_result {
        let buf = match z.parse() {
            Ok(r) => r,
            Err(_) => panic!("Parse Error"),
        };
        v.push(buf);
    }
    v
}

#[allow(dead_code)]
pub fn str2vec(s: &str) -> Vec<char> {
    let mut v: Vec<char> = Vec::new();
    for c in s.chars() {
        v.push(c);
    }
    v
}
}

#[allow(unused_imports)]
use input::*;

fn main() {
    let (m, d): (usize, usize);
    input!(m, d);

    let mut ans = 0;
    for i in 1..m + 1 {
        for j in 1..d + 1 {
            if j.to_string().len() < 2 {
                continue;
            }
            if j % 10 < 2 {
                continue;
            }
            if j / 10 < 2 {
                continue;
            }
            if i == (j % 10) * (j / 10) {
                ans += 1;
                //println!("{} {}",i,j);            
            }
        }
    }
    p(ans);
}


Measured memory_bytes: 4352
package main

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

func gcd(x, y int) {
	if x == 0 || y == 0 {
		fmt.Println(0)
	} else if x == 1 || y == 1 {
		fmt.Println(1)
	} else if x > y && x%y == 0 {
		fmt.Println(y)
	} else if y > x && y%x == 0 {
		fmt.Println(y)
	} else if x == y {
		fmt.Println(x)
	} else {
		gcd(y, x%y)
	}
}

func main() {
	sc := bufio.NewScanner(os.Stdin)
	sc.Split(bufio.ScanWords)

	sc.Scan()
	s := sc.Text()
	x, err := strconv.Atoi(s)
	if err != nil {
		panic(err)
	}

	sc.Scan()
	s = sc.Text()
	y, err := strconv.Atoi(s)
	if err != nil {
		panic(err)
	}

	gcd(x, y)
}



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

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

  replace(S.begin(), S.end(), ',', ' ');
  cout << S << endl;
  return 0;
}

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

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

signed main() {
  cin.tie(0);
  ios_base::sync_with_stdio(0);
  cout << fixed << setprecision(12);

  char c;
  cin >> c;

  if ( 'A' <= c && c <= 'Z' ) cout << 'A' << endl;
  else cout << 'a' <<endl;
  
  return 0;
}


Measured memory_bytes: 3636
#include <iostream>
using namespace std;
typedef long long  ll;

#define rep(i,s,n)for(ll i=s;i<n;i++)
#define repe(i,s,n)for(ll i=s;i<=n;i++)
void swap(char *s, char *t) {
	char x;
	x = *t;
	*t = *s;
	*s = x;
}

void strsort(char *s, bool asc) {
	char t;
	for (int i = 0; s[i] != '\0'; i++) {
		for (int j = i + 1; s[j] != '\0'; j++) {
			if (asc) {
				if (s[i] > s[j]) {
					swap(s[i], s[j]);
				}
			}
			else {
				if (s[i] < s[j]) {
					swap(s[i], s[j]);
				}
			}
		}
	}
}
int strcomp(const char *s, const char *t) {
	while (*s == *t) {
		if (!*s) {
			return 0;
		}
		s++;
		t++;
	}
	return *s - *t;
}

int main()
{
	char s[101], t[101]; cin >> s >> t;

	strsort(s, true);
	strsort(t, false);

	cout << (strcomp(s, t) < 0 ? "Yes" : "No") << endl;

	return 0;
}

Measured memory_bytes: 256
//g++ -std=c++14 test.cpp -o test.out
//問題URL
//https://atcoder.jp/contests/tenka1-2017/tasks/tenka1_2017_d

//ポイント：
//OR = なるべくビットが立っていたほうが嬉しいという意識
 
#include <string.h>
#include <stdlib.h>
#include <math.h>
#include <cassert>
#include <algorithm>
#include <functional>
#include <iostream>
#include <iomanip>
#include <vector>
#include <queue>
#include <stack>
#include <map> 
#include <unordered_map> 
#include <utility>
#include <limits.h>
#include <bitset>
#include <set>
using namespace std;
 
#define LL long long int
const LL INF = (1LL<<60);
const int INF_INT = 2147483647-1e6-1;
const LL mod = 1000000007ll;
const int mod_int = 1000000007;

LL N,K;
LL A[100000],B[100000];

LL ans = 0;

LL val_sum(LL bit){
    LL ret = 0;
    for(int i=0;i<N;i++){
        bool ok = true;
        for(int j=0;j<30;j++){
            if(!((bit>>j)&1LL) && ((A[i]>>j)&1LL)) ok = false;
        }
        ret += ok*B[i];
    }
    return ret;
}

void solve(){
    ans = val_sum(K);
    for(int d=0;d<30;d++){
        //Kのd桁目が1なら
        if((K>>d)&1LL){
            LL wise = K;
            wise &= ~(1<<d);//d桁目を0に変える
            wise |= ((1<<d) - 1);//d-1桁目より下を1に変える
            ans = max(ans,val_sum(wise));
        }
    }
}
 
int main(){
	cin >> N >> K;
    for(int i=0;i<N;i++) cin >> A[i] >> B[i];
 
    solve();

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

Measured memory_bytes: 4720
#include <sstream>
#include <string>
#include <vector>
#include <map>
#include <algorithm>
#include <iostream>
#include <utility>
#include <set>
#include <list>
#include <cctype>
#include <queue>
#include <stack>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <iomanip>
#include <iterator> 
#include <limits>

#define REP(i,n) for (int i=0;i<(n);i++)
#define FOR(i,a,b) for (int i=(a); i<(b); i++)
#define ALL(a) (a).begin(),(a).end()
#define RALL(A) (a).rbegin(),(a).rend()
#define PB push_back
#define MP make_pair

#define dump(x) cerr << #x << " = " << (x) << endl;

using namespace std;
const double PI = 3.14159265358979323846;
const double EPS = 1e-12;
const int INF = numeric_limits<int>::max() / 2;
const int NEG_INF = numeric_limits<int>::min() / 2;
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef long long LL;

int N;
const int MAX_N = 200000 + 100;
LL A[MAX_N];
LL B[MAX_N];

struct UnionFind {
    vector<int> par;
    int n, cnt;
    UnionFind(const int& x = 0) {init(x);}
    void init(const int& x) {par.assign(cnt=n=x, -1);}
    inline int find(const int& x) {return par[x] < 0 ? x : par[x] = find(par[x]);}
    inline bool same(const int& x, const int& y) { return find(x) == find(y); }
    inline bool unite(int x, int y) {
        if ((x = find(x)) == (y = find(y))) {
            return false;
        }
        --cnt;
        if (par[x] > par[y]) {
            swap(x, y);
        }
        par[x] += par[y];
        par[y] = x;
        return true;
    }
    inline int count() const {return cnt;}
    inline int count(int x) {return -par[find(x)];}
};

int main(int argc, char const* argv[])
{
    cin >> N;
    REP(i, N) {
        cin >> A[i+1];
        B[A[i+1]] = i + 1;
    }
    UnionFind l_uf(MAX_N);
    UnionFind r_uf(MAX_N);
    LL ans = 0;
    REP(i, N) {
        int n = N - i;
        int l = l_uf.count(n);
        int r = r_uf.count(n);
        ans += (LL)l * r * n;
        if (B[n] - 1 > 0) {
            l_uf.unite(n, A[B[n] - 1]);
        }
        if (B[n] + 1 <= N) {
            r_uf.unite(n, A[B[n] + 1]);
        }
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 4992
#include<bits/stdc++.h>
#define p5 100005
using namespace std;

int dp[p5][4],a[p5][4];
int n;

int solve(int day,int state)
{
    if(day==n) return a[day][state];
    if(dp[day][state]!=-1) return dp[day][state];
    int cost=a[day][state];
    if(state==1) cost+=max(solve(day+1,2),solve(day+1,3));
    else if(state==2) cost+=max(solve(day+1,1),solve(day+1,3));
    else if(state==3) cost+=max(solve(day+1,1),solve(day+1,2));
    else cost=max( solve(day+1,1), max(solve(day+1,2),solve(day+1,3)) );

    return dp[day][state]=cost;
}

int main()
{
    scanf("%d",&n);
    for(int i=1;i<=n;i++) scanf("%d %d %d",&a[i][1],&a[i][2],&a[i][3]);
    memset(dp,-1,sizeof(dp));
    printf("%d\n",solve(0,0));

    return 0;
}


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

class Main{
    public static void main(String[] args) throws Exception{
	int[] S;
	int[] T;
	int i=0;
	int j=0;
	int FOUND=0;

	BufferedReader br = new BufferedReader(new InputStreamReader(System.in));

	String str_n = br.readLine();
	String str_S = br.readLine();//data_and_key
	String str_q = br.readLine();
	String str_T = br.readLine();//key_stack

	int n = Integer.parseInt(str_n);
	int q = Integer.parseInt(str_q);
	S = new int[n+1];//S[n] = key
	T = new int[q];

	Scanner sc_S = new Scanner(str_S).useDelimiter("\\s* \\s*");
	Scanner sc_T = new Scanner(str_T).useDelimiter("\\s* \\s*");

	while(sc_S.hasNext()){
	    S[i] = sc_S.nextInt();
	    i++;
	}

	while(sc_T.hasNext()){
	    T[j] = sc_T.nextInt();
	    j++;
	}

	FOUND = linearSearch(n,S,q,T);

	System.out.println(FOUND);
	
	sc_S.close();
	sc_T.close();

    }

    private static int linearSearch(int n,int S[],int q,int T[]){
	int NOT_FOUND = 0;
	int FOUND_COUNT = 0;
	for(int j=0;j<T.length;j++){
	    int i=0;
	    int key = T[j];
	    S[n] = key;
	    while(S[i] != key) i++;
	    if(i==n) continue;
	    FOUND_COUNT++;
	}
	return FOUND_COUNT;
    }
}



Measured memory_bytes: 42016
#include <iostream>
#include <string>
using namespace std;
#define REP(i, n) for (int i = 0; i < (n); i++)

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

    while (1) {
        string str;
        cin >> str;
        if (str == "-") {
            break ;
        }

        int m;
        cin >> m;

        int h[m];
        REP(i, m) {
            cin >> h[i];
        }

        REP(i, m) {
            string tmp;
            tmp = str.substr(h[i], str.size()) + str.substr(0, h[i]);
            str = tmp;
        }
        cout << str << '\n';
    }
    return 0;
}


Measured memory_bytes: 3236
L, R = list(map(int, input().split()))

'''
d = R - L
if d >= 2019:
    ans = 0
else:
    l = L % 2019
    r = R % 2019
    
    if l + d >= 2019:
        ans = 0
    else:
        ans = l * (l+1)
        for i in range(l,l+d):
            for j in range(i+1,d):
                now = i * j % 2019
                ans = min(ans, now)
'''
d = R - L
if d >= 2019-1:
    ans = 0
else:
    I = L
    J = R
    ans = L * R % 2019
    for i in range(L,R):
        for j in range(i+1,R+1):
            now = i * j % 2019
            #ans = min(ans, now)
            if ans > now:
                ans = now
                I = i
                J = j
print(ans)


Measured memory_bytes: 3064
#include<bits/stdc++.h>
using namespace std;
char s[100+10],t[100+10];
deque<char> a;
bool same(deque<char> x,char y[])
{
	for(int i=0;i<strlen(y);i++)
	{
		if(x[i]!=y[i])	return 0;
	}
	return 1;
}
int main()
{
    cin>>s;
    cin>>t;
    int len=strlen(s);
    for(int i=0;i<strlen(s);i++)	a.push_back(s[i]);
    for(int i=1;i<=len;i++)
    {
        if(same(a,t))
        {
            cout<<"Yes";
            return 0;
        }
        a.push_front(a.back());
        a.pop_back();
    }
    cout<<"No";
    return 0;
}

Measured memory_bytes: 256
using System;
using System.Collections.Generic;

namespace AIsing20200711
{
    class Program
    {
        static void Main(string[] args)
        {
            int N = int.Parse(Console.ReadLine());
            string[] input = Console.ReadLine().Split(" ");
            int[] a = new int[N];
            for ( var i = 0; i< N; i++)
            {
                a[i] = int.Parse(input[i]);
            }

            int cnt = 0;


            for( var i = 0; i < N; i+=2)
            {
                if(a[i] % 2 != 0)
                {
                    cnt++;
                }
            }

            Console.WriteLine(cnt);
        }
    }
}


Measured memory_bytes: 27452
#include <iostream>

using namespace std;

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

    int numCoins, minValue;

  	cin >> numCoins >> minValue;

    string answer = minValue <= (numCoins * 500) ? "Yes" : "No";
    cout << answer;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(n);++i)
#define all(a) (a).begin(),(a).end()
#define dunk(a) cout << (a) << endl
using namespace std;
typedef long long ll;

int main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	int n;
	cin >> n;
	vector<ll> A(n);
	vector<ll> res2;
	vector<ll> res4;
	sort(all(A));
	int a = 0;
	rep(i, n) {
		cin >> A[i];
	}
	sort(all(A));
	rep(i, n) {
		if (i == 0) continue;
		if (A[i] == A[i - 1]) a++;
		else {
			a++;
			if (a >= 4) {
				res4.push_back(A[i - 1]);
			}
			if (a >= 2) {
				res2.push_back(A[i - 1]);
			}
			a = 0;
		}

		if (i == n - 1) {
			if (A[i] == A[i - 1]) {
				a++;
				if (a >= 4) {
					res4.push_back(A[i - 1]);
				}
				if (a >= 2) {
					res2.push_back(A[i - 1]);
				}
			}
		}
	}
	
	ll ans = 0;
	sort(all(res4),greater<ll>());
	if (res4.size() > 0) {
		ans = max(ans, res4[0] * res4[0]);
	}
	sort(all(res2),greater<ll>());
	if (res2.size() > 1) {
		ans = max(ans, res2[0] * res2[1]);
	}

	dunk(ans);
	
	return 0;
}


Measured memory_bytes: 1660