akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
#define rep(i, n) for(int i = 0; i < (n); ++i)
using namespace std;
using ll = long long;

int main(void){
    int n;
    cin >> n;
    string c;
    cin >> c;
    int cnt = 0, l = 0, r = n - 1;
    while(1){
        while(l < n && c[l] != 'W') ++l;
        while(r >= 0 && c[r] != 'R') --r;
        if(l < r){
            ++cnt;
            swap(c[l], c[r]);
        } 
        else break;
    }
    cout << cnt << endl;
    return 0;
}

Measured memory_bytes: 3732
#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <queue>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <complex>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>
#include <fstream>
#include <stdio.h>

using namespace std;

//conversion
//------------------------------------------
inline int toInt(string s) {int v; istringstream sin(s);sin>>v;return v;}
template<class T> inline string toString(T x) {ostringstream sout;sout<<x;return sout.str();}

//typedef
//------------------------------------------
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<double> VEC;
typedef vector<VEC> MAT;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef pair<int, PII> TIII;
typedef long long LL;
typedef vector<LL> VLL;
typedef vector<VLL> VVLL;
//container util

//------------------------------------------
#define ALL(a)  (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define MP make_pair
#define SZ(a) int((a).size())
#define EACH(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort((c).begin(),(c).end())
#define MT(a,b,c) MP(a, MP(b, c))
#define T1 first
#define T2 second.first
#define T3 second.second

//repetition
//------------------------------------------
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)
#define EPS 1.0e-9

int know[100][100];

int main(){
	int n;
	while(cin>>n, n){
		memset(know, 0, sizeof(know));
		REP(i,n){
			int m;
			cin>>m;
			REP(j,m){
				int k;
				cin >>k;
				know[i][k-1]=1;
			}
		}
		int K;
		cin >> K;
		VI more(K);
		int idx = -1;
		int cnt = 0;
		REP(i,K){
			cin>>more[i];
			more[i]--;
		}
		REP(i,n){
			int stmp = 0;
			REP(j,K)stmp+=know[i][more[j]];
			if(stmp == K){
				idx = i+1;
				cnt++;
			}
		}
		if(cnt == 1)cout << idx << endl;
		else cout << -1 << endl;
	}
	return 0;
}

Measured memory_bytes: 1244
using System;
using System.Linq;
using System.Collections.Generic;

class Program
{
    static void Main(string[] args)
    {
        var inputs = Console.ReadLine().Split(' ');
        var A = int.Parse(inputs[0]);
        var B = int.Parse(inputs[1]);
        var ans = (A - 1) * (B - 1);
        Console.WriteLine(ans);
    }
}



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

int main(){
    int n,m,i,sum=0,summ=0,a;
    cin>>n>>m;
    for(i=1;i<=n;i++){
	    cin>>a;
	    summ+=a;
	    if(summ<=m) sum++;
	    else break;
    }
    cout<<sum+1;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define FAST_IO ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
typedef long long ll;
#define endl '\n'

void solve() {
    string s, t;
    cin >> s >> t;

    for (char ch = 'a'; ch <= 'z'; ++ch) {
        if (s + ch == t) {
            cout << "Yes" << endl;
            return;
        }
    }
    cout << "No" << endl;
}

int main() {
    FAST_IO;

    int t;
    // cin >> t;
    t = 1;

    while (t--) {
        solve();
    }
    
    return 0;
}

Measured memory_bytes: 3616
#include <stdio.h>
#define MAX 500000
#define INFTY 1000000000
void margesort(int*, int , int);
void marge(int*, int, int, int);
int count = 0;

int main(){
int i, n;
int mer[MAX];

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

/*for(i=0; i<n-1; i++){
 printf("%d ", mer[i]);
}*/
margesort(mer ,0 , n);

for(i=0; i<n-1; i++){
 printf("%d ", mer[i]);
}
printf("%d\n", mer[n-1]);
printf("%d\n", count);

  return 0;
}

void margesort(int *A, int left, int right){
  int mid;
//  printf("left = %d\n", left);
//  printf("right = %d\n", right);
  if(left+1<right){
    mid = (left+right)/2;
  //  printf("%d\n", mid);
    margesort(A, left, mid);
    margesort(A, mid, right);
    marge(A, left, mid, right);
  }
}

void marge(int *A, int left, int mid, int right){
int i, j, k, n1, n2;
int L[MAX], R[MAX];
 n1 = mid-left;
 n2 = right-mid;


for(i = 0; i<n1; i++){
  L[i] = A[left+i];
}
for(j = 0; j<n2; j++){
  R[j] = A[mid+j];
}

L[n1] = INFTY;
R[n2] = INFTY;

i = 0;
j = 0;

for(k= left; k<right;k++){
  count++;
  if(L[i]<=R[j]){
    A[k]=L[i];
    i++;
  }
  else {
    A[k] = R[j];
    j++;
  }
}
}

Measured memory_bytes: 5484
import java.util.*;
public class Main{
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    String s = sc.next();
    int count = 0;
    int max = 0;
    for(int i = 0; i < s.length(); i++){
      char n = s.charAt(i);
      switch(n){
        case 'A':
        case 'G':
        case 'T':
        case 'C':
          count++;
          break;
        default:
          count = 0;
      }
      max = Math.max(max, count);
    }
    System.out.println(max);
  }
}

Measured memory_bytes: 23252
bingo = []
3.times { bingo += gets.split.map(&:to_i) }
n = gets.to_i
nums = []
n.times { nums << gets.to_i }
called = []
nums.each do |num|
  bingo.each_with_index do |b, i|
    if num == b
      called << i
    end
  end
end

if called.include?(0) && called.include?(1) && called.include?(2)
  puts "Yes"
elsif called.include?(3) && called.include?(4) && called.include?(5)
  puts "Yes"
elsif called.include?(6) && called.include?(7) && called.include?(8)
  puts "Yes"
elsif called.include?(3) && called.include?(0) && called.include?(6)
  puts "Yes"
elsif called.include?(7) && called.include?(4) && called.include?(1)
  puts "Yes"
elsif called.include?(2) && called.include?(8) && called.include?(5)
  puts "Yes"
elsif called.include?(0) && called.include?(4) && called.include?(8)
  puts "Yes"
elsif called.include?(6) && called.include?(4) && called.include?(2)
  puts "Yes"
else
  puts "No"
end


Measured memory_bytes: 1788
#include<algorithm>//sort,二分探索,など
#include<bitset>//固定長bit集合
#include<cmath>//pow,logなど
#include<complex>//複素数
#include<deque>//両端アクセスのキュー
#include<functional>//sortのgreater
#include<iomanip>//setprecision(浮動小数点の出力の誤差)
#include<iostream>//入出力
#include<iterator>//集合演算(積集合,和集合,差集合など)
#include<map>//map(辞書)
#include<numeric>//iota(整数列の生成),gcdとlcm(c++17)
#include<queue>//キュー
#include<set>//集合
#include<stack>//スタック
#include<string>//文字列
#include<unordered_map>//イテレータあるけど順序保持しないmap
#include<unordered_set>//イテレータあるけど順序保持しないset
#include<utility>//pair
#include<vector>//可変長配列

// vectorの重複削除
// std::sort(test.begin(), test.end());
// test.erase(std::unique(test.begin(), test.end()), test.end());

using namespace std;
using ll = long long;
using P = pair<int, int>; // vector<P> ba(n); みたいな感じですぐ使える ba[i] = P(a, b); make_pairをしなくてもいい
// typedef vector<int> v;
template <class T>ostream &operator<<(ostream &o,const vector<T>&v){o<<"{";for(int i=0;i<(int)v.size();i++)o<<(i>0?", ":"")<<v[i];o<<"}";return o;}
#define debug(v) {cerr<<"\033[1;36m[debug]\033[m "<<#v<<" : "<<v<<endl;}
#define rep(i, c) for(int i = 0; i < int(c); i++)
#define ALL(x) (x).begin(), (x).end() //sort(ALL(obj))みたいな
#define SIZE(x) ((ll)(x).size()) //sizeをsize_tからllに直しておく
#define MAX(x) *max_element(ALL(x)) //最大値
#define pb push_back //
// const int MOD = 1000000007;


int main() {
  ll x;
  cin >> x;
  for (int i=-118; i<=119; i++) {
    for (int j=-119; j<=118; j++){
      if (x == pow(i,5) - pow(j,5)) {
        cout << i << " " << j << endl;
        return 0;
      }
    }
  }
}


Measured memory_bytes: 3548
import java.util.Scanner;

public class Main {
	public static void main(String[] args){
		//????????£?????????????????????
		Scanner sc = new Scanner(System.in);
		String str ="";
		//??°?????????
		while(true){
			//???????????????????????????
			str = sc.next(); 
			//"-"????????????????????????
			if(str.equals("-")){
				break;
			}
			//??°????????????
			int num = sc.nextInt();
			
			//??????????????°???????????£?????????
			for(int i = 0;i< num;i++){
				int h = sc.nextInt();
				//
				str = str.substring(h)+str.substring(0,h);
			}
			//??¨???
			System.out.println(str);
		}
	}
}

Measured memory_bytes: 26224
#define _USE_MATH_DEFINES

#include <bits/stdc++.h>

#define sz(x) (int)((x).size())
#define endl '\n'
#define x first
#define y second
#define int long long
#define all(a) (a).begin(), (a).end()
#define ar vector
#define vse(a) a.begin(), a.end()

#ifdef LOCAL
	#define dbg(x) cout << #x << " = " << x << endl;
#else 
	#define dbg(x)
#endif 

using namespace std;

void solve(); signed main() {
#ifdef LOCAL
    freopen("file1.txt", "r", stdin);                                       
    freopen("file2.txt", "w", stderr);
#endif
    srand(time(0));
    ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    cout.setf(ios::fixed); cout.precision(15);
    solve();  	
}

const int MAXN = 2e5 + 10;                                      
 
void solve() {                                
	int n, k;
	cin >> n >> k;
	string s;
	cin >> s;
	
	s[k - 1] -= ('A' - 'a');

	cout << s << endl;
}	 	



Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <iomanip>
#include <vector>
#include <queue>
#include <set>
#include <map>

using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
int N;
int K[200000];
ll L[200000], R[200000];

void solve(){
    cin >> N;
    ll ans = 0;
    vector<P> vl, vr;
    for(int i = 0; i < N; i++) {
        cin >> K[i] >> L[i] >> R[i];
        ans += min(L[i], R[i]);
        K[i]--;
        ll m = min(L[i], R[i]);
        L[i] -= m;
        R[i] -= m;
        if(L[i] > 0){
            vl.push_back(P(K[i], L[i]));
        }
        if(R[i] > 0){
            int rem = N-K[i]-2;
            vr.push_back(P(rem, R[i]));
        }
    }
    sort(vl.begin(), vl.end());
    sort(vr.begin(), vr.end());
    priority_queue<ll, vector<ll>, greater<ll>> que;
    for(P p : vl){
        ll cur = p.second;
        int idx = p.first;
        // idx is 0-indexed
        if(que.size() <= idx){
            que.push(cur);
        }else{
            ll top = que.top();
            if(top < cur){
                que.pop();
                que.push(cur);
            }
        }
    }
    while(!que.empty()){
        ll top = que.top();
        ans += top;
        que.pop();
    }
    for(P p : vr){
        ll cur = p.second;
        int idx = p.first;
        if(idx == -1) continue;
        // idx is 0-indexed
        if(que.size() <= idx){
            que.push(cur);
        }else{
            ll top = que.top();
            if(top < cur){
                que.pop();
                que.push(cur);
            }
        }
    }
    while(!que.empty()){
        ll top = que.top();
        ans += top;
        que.pop();
    }
    cout << ans << endl;
}

int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout << setprecision(10) << fixed;
    int t; cin >> t;
    for(int i = 0; i < t; i++){
        solve();
    }
}

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

int main()
{
    long X, A, B;
    cin >> X >> A >> B;
    if (B <= A) cout << "delicious" << endl;
    else if (B - A <= X) cout << "safe" << endl;
    else cout << "dangerous" << endl;

    return 0;
}


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

int main() {
    int n, res = 0;
    cin >> n;
    for(int i = 0; i < n; ++i) {
        int x; cin >> x;
        res += __builtin_ctz(x);
    }
    printf("%d\n", res);
}

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

#define MAXTEXT 1002
#define MAXWORD 32

int main(){
	int i,j,length,space=0,next=0;
	unsigned int count,max,pos,longest,lnpos; 
	char *text,buf[MAXTEXT+1];
	char **tok;
	char str[]=" ";

	fgets(buf,sizeof(buf),stdin);
	if(buf[strlen(buf)]=='\n') length=strlen(buf)-1;
	else length=strlen(buf);

	text=(char*)malloc(sizeof(char)*(length+1));
	for(i=0;i<=length;i++){
		text[i]=buf[i];
		if(buf[i]==' ') space++;
		if(buf[i]=='\n') break;
	}
	text[i]='\0';
	tok=(char**)malloc(sizeof(char*)*(space+1));
	for(i=0;i<space+1;i++){
		tok[i]=(char*)malloc(sizeof(char)*(MAXWORD+1));
	}
	for(i=0;i<space+1;i++){
		if(next>length) break;
		for(j=0;j<MAXWORD+1;j++){
			if(j+next>length) break;
			if(text[j+next]==' ' || text[j+next]=='\0'){
				tok[i][j]='\0';
				next=next+j+1;
				break;
			}else{
				tok[i][j]=text[j+next];
			}
		}
	}

	max=longest=0;
	for(i=0;i<space+1;i++){
		count=0;
		if(longest<strlen(tok[i])){
			longest=strlen(tok[i]);
			lnpos=i;
		}
		for(j=0;j<space+1;j++){
			if(strcmp(tok[i],tok[j])==0){
				count++;
			}
		}
		if(max<count){
			max=count;
			pos=i;
		}
	}
	printf("%s %s\n",tok[pos],tok[lnpos]);
	text=NULL;
	free(text);
	return 0;
}

Measured memory_bytes: 564
#pragma GCC optimize("Ofast")
#define _USE_MATH_DEFINES
#include "bits/stdc++.h"

using namespace std;

using u8 = uint8_t;
using u16 = uint16_t;
using u32 = uint32_t;
using u64 = uint64_t;
using i8 = int8_t;
using i16 = int16_t;
using i32 = int32_t;
using i64 = int64_t;

constexpr char newl = '\n';
constexpr double eps = 1e-10;

#define FOR(i,a,b) for (int i = (a); i < (b); i++)
#define F0R(i,b) FOR(i,0,b)
#define RFO(i,a,b) for (int i = ((b)-1); i >=(a); i--)
#define RF0(i,b) RFO(i,0,b)
#define fi first
#define se second
#define debug(x) cout << #x << ": " << x << '\n';
#define rng(a) a.begin(),a.end()
#define rrng(a) a.rbegin(),a.rend()

template<typename T1, typename T2> inline void chmin(T1& a, T2 b) { if (a > b) a = b; }
template<typename T1, typename T2> inline void chmax(T1& a, T2 b) { if (a < b) a = b; }
template<class T> void Print(vector<T> v) {
  F0R(i, v.size()) {
    cout << v[i] << ' ';
  }
  cout << newl;
}

#if 1


// INSERT ABOVE HERE
signed main() {
  cin.tie(0);
  ios_base::sync_with_stdio(false);

  int N;
  cin >> N;
  vector<int> as(N), cs(N - 1);
  F0R(i, N) cin >> as[i];
  int result = 0;
  F0R(i, N) {
    int b; cin >> b;
    result += b;
  }
  F0R(i, N - 1) {
    cin >> cs[i];
  }
  int prev = -2;
  F0R(i, N) {
    if (as[i] - 1 == prev + 1) {
      result += cs[prev];
    }
    prev = as[i] - 1;
  }
  cout << result;
}
#endif


Measured memory_bytes: 256
N, M = list(map(int, input().split(" ")))

MOD = 10**9+7

dp = [0 for _ in range(10**5+2)]
dp[0] = 1
for i in range(max(N, M)+1):
    dp[i+1] = dp[i]*(i+1)%MOD


if abs(N-M) >= 2:
    print(0)
elif abs(N-M) == 1:
    print((dp[N]*dp[M])%MOD)
else:
    print((2*dp[N]*dp[M])%MOD)

Measured memory_bytes: 7064
import java.util.Scanner;

public class Main{
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		int a = sc.nextInt();
		int b = sc.nextInt();
		int c = sc.nextInt();
		int y = 0;
		for(; a <= b; a++){
			if(c % a == 0)y++;
		}
		System.out.println(y);
	}
	}

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

const int INF=1001001001;

int main(){
  int h,n;
  cin >> h >> n;
  vector<int> dp(h+1,INF);
  dp[0]=0;
  for(int i=0;i<n;++i){
    int a,b;
    cin >> a >> b;
    for(int j=0;j<h;++j){
      int nj=min(j+a,h);
      dp[nj]=min(dp[nj],dp[j]+b);
    }
  }
  cout << dp[h] << endl;
  return 0;
}


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

using namespace std;
using ll = long long;

int main(){
	// freopen("test.in", "r", stdin);
	int n;
	cin >> n;
	vector<ll> a(n), pref(n + 1);
	for(int i = 0; i < n; ++ i) cin >> a[i];
	pref[1] = a[0];
	for(int i = 2; i <= n; ++ i) pref[i] = pref[i - 1] + a[i - 1];
	int p1 = 1, p3 = 3;
	ll ans = 1e18;
	for(int p2 = 2; p2 <= n - 1; ++ p2){
		while(pref[p2] - pref[p1] > pref[p1]) p1++;
		while(pref[n] - pref[p3] > pref[p3] - pref[p2]) p3++;
		// cout << p1 << " " << p2 << " " << p3 << '\n';
		ll max_sub = max({pref[p1], pref[p2] - pref[p1], pref[p3] - pref[p2], pref[n] - pref[p3]});
		ll min_sub = min({pref[p1], pref[p2] - pref[p1], pref[p3] - pref[p2], pref[n] - pref[p3]});
		ans = min(ans, max_sub - min_sub);
		
		p1 --;
		max_sub = max({pref[p1], pref[p2] - pref[p1], pref[p3] - pref[p2], pref[n] - pref[p3]});
		min_sub = min({pref[p1], pref[p2] - pref[p1], pref[p3] - pref[p2], pref[n] - pref[p3]});
		ans = min(ans, max_sub - min_sub);
		
		p1 ++;
		p3 --;
		max_sub = max({pref[p1], pref[p2] - pref[p1], pref[p3] - pref[p2], pref[n] - pref[p3]});
		min_sub = min({pref[p1], pref[p2] - pref[p1], pref[p3] - pref[p2], pref[n] - pref[p3]});
		ans = min(ans, max_sub - min_sub);
		
		p1 --;
		max_sub = max({pref[p1], pref[p2] - pref[p1], pref[p3] - pref[p2], pref[n] - pref[p3]});
		min_sub = min({pref[p1], pref[p2] - pref[p1], pref[p3] - pref[p2], pref[n] - pref[p3]});
		ans = min(ans, max_sub - min_sub);
		
	}
	/*
	ll ans_brute = 1e18; 
	for(int p1 = 1; p1 <= n; ++ p1){
		for(int p2 = p1 + 1; p2 <= n; ++ p2){
			for(int p3 = p2 + 1; p3 <= n; ++ p3){
				ll max_sub = max({pref[p1], pref[p2] - pref[p1], pref[p3] - pref[p2], pref[n] - pref[p3]});
				ll min_sub = min({pref[p1], pref[p2] - pref[p1], pref[p3] - pref[p2], pref[n] - pref[p3]});
				ans_brute = min(ans_brute, max_sub - min_sub);
				// cout << ans_brute << " " << p1 << " " << p2 << " " << p3 << '\n';
			}
		}
	}		
	cout << ans_brute << " " << ans << '\n';
	*/
	cout << ans << '\n';
}
		
		
		


Measured memory_bytes: 3328
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<bits/stdc++.h>
#include<cmath>
#include<bitset>
#define ll long long
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define FFOR(i,a,b) for(int i=(a);i<=(b);++i)
#define REP(i,n)  FOR(i,0,n)
#define RREP(i,n)  FFOR(i,0,n)
#define SORT(V) sort((V).begin(),(V).end())
#define INF ((1LL<<62)-(1LL<<31))
#define MOD 1000000007
using namespace std;

int main(){
  int N,cnt=0;
  cin>>N;
  
  vector<int> P;
  vector<int> Q;
  REP(i,N){
    int a;
    cin>>a;
    P.push_back(a);
    Q.push_back(a);
  }
  
  SORT(P);
  REP(i,N){
    if(P.at(i)==Q.at(i)) cnt++;
  }
  
  if(cnt==N-2 || cnt==N) cout<<"YES"<<endl;
  else cout<<"NO"<<endl;
}


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

template <class T>
class perm {
    vector<T> facts, ifacts;
public:
    perm(int n): facts(n+1), ifacts(n+1) {
        facts[0] = 1;
        rep1(i,n) facts[i] = facts[i-1] * i;
        ifacts[n] = facts[n];
        ifacts[n].inv();
        for (int i=n; i> 0; --i)
            ifacts[i-1] = ifacts[i] * i;
    }
    T const& f(int n) const {
        return facts[n];
    }
    T c(int n, int k) const {
        return facts[n] * ifacts[k] * ifacts[n-k];
    }
    T p(int n, int k) const {
        return facts[n] * ifacts[n-k];
    }
};

template <ll Mod>
class modint {
    public:
    ll n=0;
    modint(){}
    modint(ll n):n(n){ clamp(); }
    modint& operator = (modint const& a) = default;
    modint& operator = (int a) { n = a; clamp(); return *this; }
    modint operator - () { modint t = *this; t.n = -t.n; t.clamp(); return t; }
    modint& operator *= (modint const& a) { n *= a.n; clamp(); return *this; }
    modint& operator *= (ll const& a) { n *= a; clamp(); return *this; }
    modint& operator += (modint const& a) { n += a.n; if (n >= Mod) n -= Mod; return *this; }
    modint& operator %= (modint const& a) { n %= a.n; clamp(); return *this; }
    friend modint operator * (modint a, modint b) { modint t(a); t.n *= b.n; t.clamp(); return t; }
    friend modint operator + (modint a, modint b) { modint t(a); t.n += b.n; t.clamp(); return t; }
    friend modint operator - (modint a, modint b) { modint t(a); t.n -= b.n; t.clamp(); return t; }
    friend ostream& operator << (ostream& os, modint const& a) { os << a.n; return os; }
    friend bool operator == (modint const& a, int b) { return a.n == b; }
    void clamp() { n %= Mod; if (n < 0) n += Mod; }
    modint& inv() { return pow(Mod-2); }
    ll get() { return n; }
    modint& pow(ll p) {
        ll a=1, e=n;
        while (p > 0) {
            if (p&1) { a *= e; a %= Mod; }
            e *= e; e %= Mod; p >>= 1;
        }
        n = a; clamp();
        return *this;
    }
};
const ll Mod = 998244353;
using mint = modint<Mod>;

int main() {
    ll n, m, k;
    cin >> n >> m >> k;
    mint ans;
    if (n == 1) {
        ans = m;
    } else {
        perm<mint> pm(n-1);
        mint u(m-1);
        ans += u.pow(n-1-k) * pm.c((n-1),k);
        revrep(i,k) {
            u *= m-1;
            ans += u * pm.c((n-1),i);
        }
        ans *= m;
    }
    cout << ans << endl;
}


Measured memory_bytes: 6292
#include <bits/stdc++.h>
using namespace std;
int main() {
  int64_t n, ct=0;
  cin >> n;
  if(n%2==1){
    cout << 0;
    return 0;
  }
  n/=2;
  while(n>=1){
    ct+=n/5;
    n/=5;
  }
  cout << ct;
  return 0;
}

Measured memory_bytes: 3588
import Data.List
import Data.Set


main = do
    n <- getLine
    s <- getLine
    putStrLn $ show $ ans s

ans s = foldl1 max counts
    where
        counts = [overlapCount ls rs | (ls, rs) <- zip (inits s) (tails s)]
        overlapCount xs ys = size $ intersection (Data.Set.fromList xs) (Data.Set.fromList ys)


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

#define rep(i, a, b) for (auto i = (a); i < (b); ++i)
#define per(i, a, b) for (auto i = (b) - 1; i >= (a); --i)

using ll = int64_t;

template<class T> bool ckmin(T& a, const T& b) { return a > b ? a = b, 1 : 0; }
template<class T> bool ckmax(T& a, const T& b) { return a < b ? a = b, 1 : 0; }

constexpr ll inf = 2e18;
constexpr ll V = 1 << 17;

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

	int n, w; cin >> n >> w;
	ll v[n], c[n], dp[V];
	rep(i, 0, n) cin >> c[i] >> v[i];
	dp[0] = 0; rep(x, 1, V) dp[x] = inf;
	rep(i, 0, n) per(x, v[i], V) ckmin(dp[x], dp[x - v[i]] + c[i]);
	per(x, 0, V) if (dp[x] <= w) return cout << x, 0;
}

Measured memory_bytes: 1280
cnt = 0
n = int(raw_input())
A = [int(raw_input()) for _ in range(n)]
G = [1] if n < 5 else [1, 4]
while G[-1]*3+1 <= n/3: G.append(G[-1]*3+1)
G.append(n/10*9)
G.reverse()

def insersionSort(g):
	global cnt
	for i in range(g, n):
		v = A[i]
		j = i - g
		while j >= 0 and A[j] > v:
			A[j+g] = A[j]
			j = j - g
			cnt += 1
		A[j+g] = v

def shellSort():
	for g in G:
		insersionSort(g)

shellSort()
print len(G)
print " ".join(map(str, G))
print cnt
print "\n".join(map(str, A))

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

//#define int long long
#define all(v) (v).begin(), (v).end()
#define rall(v) (v).rbegin(), (v).rend()
#define rep(i,n) for(int i=0;i<n;++i)
#define rep1(i,n) for(int i=1;i<n;++i)
#define exrep(i, a, b) for(ll i = a; i < b; i++)
#define out(x) cout << x << endl
#define EPS (1e-7)
#define gearup ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
typedef long double ld;
typedef long long int ll;
typedef unsigned long long int ull;
typedef vector<int> vi;
typedef vector<char> vc;
typedef vector<bool> vb;
typedef vector<double> vd;
typedef vector<string> vs;
typedef vector<pair<int,int> > vpii;
typedef vector<vector<int> > vvi;
typedef vector<vector<char> > vvc;
typedef vector<vector<bool> > vvb;
typedef vector<vector<double> > vvd;
typedef vector<vector<string> > vvs;
typedef vector<ll> vl;
typedef vector<vector<ll> > vvl;
typedef vector<vector<vector<ll> > > vvvl;
ll MOD = 1000000007;
const long long L_INF = 1LL << 60;
const int INF = 2147483647; // 2^31-1
const double PI = acos(-1);
//cout<<fixed<<setprecision(10);

template<class T> inline bool chmin(T& a, T b) {if (a > b) {a = b;return true;}return false;}
template<class T> inline bool chmax(T& a, T b) {if (a < b) {a = b;return true;}return false;}
template<class T> void debug(T v){rep(i,v.size()) cout<<v[i]<<" ";cout<<endl;}
const ll dx[8] = {1, 1, 0, -1, -1, -1, 0, 1};
const ll dy[8] = {0, 1, 1, 1, 0, -1, -1, -1};

signed main()
{   
    gearup;
    ll n,d; cin >> n >> d;
    vvl x(n,vl(d));
    ll res = 0;
    rep(i,n)rep(j,d)cin>>x[i][j];
    for(int i=0;i<n;i++){
        for(int j=i+1;j<n;j++){
            ll sum = 0;
            rep(k,d){
                sum += (x[i][k] - x[j][k])*(x[i][k] - x[j][k]);
            }
            ll sum1 = sqrt(sum);
            if(sum == (sum1*sum1))res++;
        }
    }
    out(res);
}


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

int main(){
  int n, k;
  vector<int> x;
  int x_;
  cin>>n>>k;
  for (int i=0;i<n;i++){
    cin>>x_;
    x.push_back(x_);
  }

  int sum = 0;
  for (int i=0;i<n;i++){
    sum += min(abs(x[i]-0)*2, abs(x[i]-k)*2);
  }

  cout<<sum<<endl;

  return 0;
}


Measured memory_bytes: 256
program main
 implicit none
 
 integer*8 i
 real*8 N,K,P
 
 read(*,*) N,K
 P = 0.0D0
 do i=1,int(N)
  if(i >= K) then
   P = P + 1
  else
   P = P + 2 ** (-real(ceiling(log(K/real(i))/log(2.0D0))))
  end if
 end do
 write(*,*) P/N
end program main

Measured memory_bytes: 256
using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Numerics;

namespace AtCoder
{
    class Program
    {
        static void Main(string[] args)
        {
            var R = int.Parse(Console.ReadLine());

            if (R < 1200) Console.WriteLine("ABC");
            else if (R < 2800) Console.WriteLine("ARC");
            else Console.WriteLine("AGC");
        }
    }
}


Measured memory_bytes: 13140
# from math import factorial,sqrt,ceil,gcd
# from itertools import permutations as permus
# from collections import deque,Counter
# import re
# from functools import lru_cache # 簡単メモ化 @lru_cache(maxsize=1000)
# from decimal import Decimal, getcontext
# # getcontext().prec = 1000
# # eps = Decimal(10) ** (-100)

import numpy as np
# import networkx as nx
# from scipy.sparse.csgraph import shortest_path, dijkstra, floyd_warshall, bellman_ford, johnson
# from scipy.sparse import csr_matrix
# from scipy.special import comb

# slist = "abcdefghijklmnopqrstuvwxyz"
N,M = map(int,input().split())
times = N
AB = []
for _ in range(times):
    AB.append(list(map(int,input().split()))) # 行列の場合
times = M
CD = []
for _ in range(times):
    CD.append(list(map(int,input().split()))) # 行列の場合

AB = np.array(AB)
CD = np.array(CD)
for ab in AB:
    arr = np.sum(abs(ab-CD),axis=1)
    # print(arr)
    print(np.argmin(arr)+1)
# print(*ans)   # unpackして出力。間にスペースが入る
# for row in board:
#     print(*row,sep="")    #unpackして間にスペース入れずに出力する
# print("{:.10f}".format(ans))
# print("{:0=10d}".format(ans))


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

static const int Maxn = 100005;

int n, id[Maxn];
int par[Maxn], sz[Maxn];
long long a[Maxn];
map<long long, int> mp;

int main() {
  scanf("%d", &n);
  for (int i = 1; i <= n; ++i) {
    scanf("%lld", a + i);
    id[i] = i, sz[i] = 1;
    mp[a[i]] = i;
  }
  sort(id + 1, id + n + 1, [&](const int &x, const int &y)->bool {
    return a[x] > a[y];
  });
  for (int i = 1; i < n; ++i) {
    int now = id[i];
    par[now] = mp[a[now] - n + 2 * sz[now]];
    if (!par[now]) return puts("-1") & 0;
    sz[par[now]] += sz[now];
  }
  long long sum = 0;
  for (int i = 1; i < n; ++i) sum += sz[id[i]];
  if (sum != a[id[n]]) return puts("-1") & 0;
  for (int i = 1; i < n; ++i)
    printf("%d %d\n", id[i], par[id[i]]);
  return 0;
}

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

public class Main {
	public static final int MOD = 1000000007;
	
    public static void main(String[] args) {
        Scanner sc = new Scanner(in);

        int n = sc.nextInt();
		int m = sc.nextInt();
		
		boolean[] wet = new boolean[n+1];
		Arrays.fill(wet, false);
		for(int i=0; i<m; i++) wet[sc.nextInt()] = true;

		int[] dp = new int[n+3];
		Arrays.fill(dp, 0);
		
		dp[0] = 1;
		for(int i=0; i<=n; i++) {
			if(wet[i]) continue;

			dp[i+1] += dp[i];
			dp[i+1] %= MOD;
			dp[i+2] += dp[i];
			dp[i+2] %= MOD;
		}
		
        out.println(dp[n]);
    }
}


Measured memory_bytes: 49036
import java.util.Scanner;
class Main{
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        int A = sc.nextInt();
        int B = sc.nextInt();

        if ((A == 1 && B == 2)||(A == 2 && B == 1)) {
            System.out.println(3);
        } else if ((A == 1 && B == 3)||(A == 3 && B == 1)) {
            System.out.println(2);
        } else {
            System.out.println(1);
        }
    }
}

Measured memory_bytes: 22100
#include<iostream>
#include<vector>
#include<string>

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

int main(){
	int N;
	std::cin >> N;
	std::vector<ll> A(N);
	rep(i, N) std::cin >> A[i];

	ll tmp = A[0];
	ll res = 0;
	for(int i=1; i<N; i++){
		if(A[i] < tmp){
			res += (tmp - A[i]);
		}else{
			tmp = A[i];
		}
	}
	std::cout << res << std::endl;
	return 0;
}

Measured memory_bytes: 4832
/* 
	Author: ankrypt
*/
#include <bits/stdc++.h>

using namespace std;

long long dp[90];
long long finalAns;
int N;

long long dpOperation(int N)
{
	if(N == 0)
	{
		return 2;
	}
	if(N == 1)
	{
		return 1;
	}
	if(dp[N] != -1)
	{
		return dp[N];
	}
	long long ans = dpOperation(N - 1) + dpOperation(N - 2);
	return dp[N] = ans;
}
int main()
{
	memset(dp, -1, sizeof(dp));
	scanf("%d", &N);
	finalAns = dpOperation(N);
	printf("%lld\n", finalAns);
	
	return 0;
}
/*
	Powered by Buggy Plugin
*/


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

class Program
{
    void Calc()
    {
        var sc = new Scanner();
        int a = sc.NextInt();
        int b = sc.NextInt();
        int c = sc.NextInt();

        if (a < b )
        {
            if (b < c)
            {
                Console.WriteLine("Yes");
            }
            else
            {
                Console.WriteLine("No");
            }
        }
        else
        {
            Console.WriteLine("No");
        }

       
    }

    static void Main()
    {
        new Program().Calc();
    }

    class Scanner
    {
        string[] s = new string[0];
        int i = 0;
        char[] cs = new char[] { ' ' };

        public string Next()
        {
            if (i < s.Length) return s[i++];
            s = Console.ReadLine().Split(cs, StringSplitOptions.RemoveEmptyEntries);
            i = 0;
            return s[i++];
        }
        public int NextInt() { return int.Parse(Next()); }
        public long NextLong() { return long.Parse(Next()); }
        public double NextDouble() { return double.Parse(Next()); }
    }
}

Measured memory_bytes: 5300
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#define ll long long
#define iii tuple<int, int, int>
#define ii pair<int, int>
#define fi first
#define se second

using namespace std;
using namespace __gnu_pbds;

template <typename T>
using ordered_set =
    tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;

void solve() {
    int n, M = 1e9 + 7;
    cin >> n;

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

    for (auto& i : a)
        for (auto& j : i) cin >> j;

    vector<int> dp(1 << n), p2(n + 1);
    for (int i = 0; i <= n; ++i) p2[i] = 1 << i;
    dp[0] = 1;

    queue<int> q;
    q.push(0);
    auto cnt = [](int x) {
        int res = 0;
        while (x) {
            res += x & 1;
            x >>= 1;
        }
        return res;
    };

    while (!q.empty()) {
        int msk = q.front(), i = cnt(msk);
        q.pop();

        if (i == n) break;
        if (!dp[msk]) continue;

        for (int j = 0; j < n; ++j) {
            if (a[i][j] && !(msk & p2[j])) {
                q.push(msk | p2[j]);
                dp[msk | p2[j]] = (dp[msk | p2[j]] + dp[msk]) % M;
            }
        }
        dp[msk] = 0;
    }
    cout << dp[p2[n] - 1] << '\n';
}

int main() {
    ios::sync_with_stdio(false), cin.tie(nullptr), cout.tie(nullptr);
    // freopen("in", "r", stdin);

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

    return 0;
}

Measured memory_bytes: 25108
#include <bits/stdc++.h>
template<class T> inline bool chmin(T&a, T b){if(a > b){a = b; return true;}else{return false;}}
template<class T> inline bool chmax(T&a, T b){if(a < b){a = b; return true;}else{return false;}}
#define ll long long
#define double long double
#define rep(i,n) for(int i=0;i<(n);i++)
#define REP(i,n) for(int i=1;i<=(n);i++)
#define mod (ll)(1e9+7)
#define inf (ll)(3e18+7)
#define pi (double) acos(-1.0)
#define P pair<int,int>
#define PiP pair<int,pair<int,int>>
#define all(x) x.begin(),x.end()
#define rall(x) x.rbegin(),x.rend()
using namespace std;

int main() {
    int n, sum = 0;
    cin >> n;
    vector<int> a(n);
    rep(i, n){
        cin >> a[i];
        sum ^= a[i];
    }
    rep(i, n){
        sum ^= a[i];
        cout << sum << " ";
        sum ^= a[i];
    }
    cout << endl;
}

Measured memory_bytes: 4048
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <climits>
#include <cfloat>
#include <map>
#include <utility>
#include <ctime>
#include <set>
#include <iostream>
#include <memory>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <sstream>
#include <complex>
#include <stack>
#include <queue>
#include <cstring>
#include <numeric>
#include <cassert>
using namespace std;
static const double EPS = 1e-10;
typedef long long ll;
#define rep(i,n) for(int i=0;i<n;i++)
#define rev(i,n) for(int i=n-1;i>=0;i--)
#define all(a) a.begin(),a.end()
#define mp(a,b) make_pair(a,b)
#define pb(a) push_back(a)
#define SS stringstream
#define DBG1(a) rep(_X,sz(a)){printf("%d ",a[_X]);}puts("");
#define DBG2(a) rep(_X,sz(a)){rep(_Y,sz(a[_X]))printf("%d ",a[_X][_Y]);puts("");}
#define bitcount(b) __builtin_popcount(b)
#define EACH(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)

#define delete(a,n) a.erase(remove(all(a),n),a.end())
template<typename T, typename S> vector<T>& operator<<(vector<T>& a, S b) { a.push_back(b); return a; }
template<typename T> void operator>>(vector<T>& a, int b) {while(b--)if(!a.empty())a.pop_back();}
bool isprime(int n){ if(n<2)return false;  for(int i=2;i*i<=n;i++)if(n%i==0)return false;  return true;} 
ll b_pow(ll x,ll n){return n ? b_pow(x*x,n/2)*(n%2?x:1) : 1ll;}
string itos(int n){stringstream ss;ss << n;return ss.str();}


int main(){
	ios_base::sync_with_stdio(false);
	int n;
	while(cin >> n){
		n--;
		printf("3C%02d\n",n%39+1);
	}
}

Measured memory_bytes: 0
#include <bits/stdc++.h>
#define dibs reserve
#define OVER9000 1234567890
#define ALL_THE(CAKE,LIE) for(auto LIE =CAKE.begin(); LIE != CAKE.end(); LIE++)
#define tisic 47
#define soclose 1e-8
#define chocolate win
// so much chocolate
#define patkan 9
#define ff first
#define ss second
#define abs(x) ((x < 0)?-(x):x)
#define uint unsigned int
#define dbl long double
#define pi 3.14159265358979323846
using namespace std;
// mylittledoge

typedef long long cat;

#ifdef DONLINE_JUDGE
	// palindromic tree is better than splay tree!
	#define lld I64d
#endif

void DFS(int R, vector< vector<int> > &G, vector<int> &S, vector<int> &par) {
	S[R] =1;
	ALL_THE(G[R],it) if(S[*it] == 0) {
		DFS(*it,G,S,par);
		par[*it] =R;
		S[R] +=S[*it];
	}
}

cat pw(cat a, cat e, cat mod) {
	if(e <= 0) return 1;
	cat x =pw(a,e/2,mod);
	x =(x*x)%mod;
	if(e%2) x =(x*a)%mod;
	return x;
}

int main() {
	cin.sync_with_stdio(0);
	cin.tie(0);
	cout << fixed << setprecision(10);
	int N;
	cin >> N;
	vector< vector<int> > G(N);
	for(int i =0; i < N-1; i++) {
		int x,y;
		cin >> x >> y;
		G[--x].push_back(--y);
		G[y].push_back(x);
	}

	vector<int> S(N,0), par(N,0);
	DFS(0,G,S,par);
	int c =0;
	for(int i =0; i < N; i++) {
		bool isc =(S[i] >= N-S[i]);
		ALL_THE(G[i],it) if(*it != par[i] && S[*it] > N-S[*it]) isc =false;
		if(isc) c =i;
	}
	for(int i =0; i < N; i++) S[i] =0;
	par[c] =c;
	DFS(c,G,S,par);
	vector<int> A;
	ALL_THE(G[c],it) A.push_back(S[*it]);
	A.push_back(1);
	int M =A.size();

	cat mod =1000000007;
	vector<cat> fac(10000,1), inv(10000,1);
	for(int i =1; i < 10000; i++) fac[i] =(i*fac[i-1])%mod;
	for(int i =1; i < 10000; i++) inv[i] =pw(fac[i],mod-2,mod);
	vector< vector<cat> > cnt(M+1,vector<cat>(N+1,0));
	cnt[0][0] =1;
	for(int i =0; i < M; i++) for(int k =0; k <= A[i]; k++) {
		cat C =(fac[A[i]]*inv[k])%mod*inv[A[i]-k]%mod;
		C =C*fac[A[i]]%mod*inv[A[i]-k]%mod;
		for(int j =0; j <= N-k; j++)
			cnt[i+1][j+k] =(cnt[i+1][j+k]+cnt[i][j]*C)%mod;
	}
	
	cat ans =0;
	for(int i =N; i >= 0; i--) {
		if((N-i)%2) ans =(ans-fac[i]*cnt[M][N-i])%mod;
		else ans =(ans+fac[i]*cnt[M][N-i])%mod;
	}
	for(int i =N-1; i >= 0; i--) {
		if((N-1-i)%2) ans =(ans-fac[i]*cnt[M-1][N-1-i])%mod;
		else ans =(ans+fac[i]*cnt[M-1][N-1-i])%mod;
	}
	ans %=mod;
	if(ans < 0) ans +=mod;
	cout << ans << "\n";
	return 0;
}



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

int main(){
	ios::sync_with_stdio(false),cin.tie(0);
	string s;
	cin>>s;
	if(s=="hi"s||s=="hihi"s||s=="hihihi"s||s=="hihihihi"s||s=="hihihihihi"s){
		cout<<"Yes\n"s;
		return 0;
	}else{
		cout<<"No\n"s;
		return 0;
	}
}

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

int main() {
  int n, T;
  cin >> n >> T;
  vector<int> t(n);
  rep(i, n) cin >> t[i];

  ll ans = T;
  rep(i, n-1) {
    if (t[i] + T > t[i+1]) ans += t[i+1] - t[i];
    else ans += T;
  }
  cout << ans << endl;
}


Measured memory_bytes: 1024
#include<bits/stdc++.h>
#define rep(i, n) for (ll i = 0; i < (ll)(n); ++i)
#define repk(i,k,n) for (ll i = k; i < (ll)(n); ++i)
#define INF 5000000000
#define MOD 1000000007
typedef long long  ll;

using namespace std;


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

	ll N, M, X;
	cin >> N >> M >> X;
	
	vector<ll> C(N);
	vector<vector<ll>> A(N, vector<ll>(M));
	rep(i, N) {
		cin >> C[i];
		rep(j, M) {
			cin >> A[i][j];
		}
	}
	
	ll ans = INF;
	vector<ll> skill(M);
	ll minsk = INF;
	ll money = 0;
	for (ll bit = 0; bit <= (1 << N); bit++) {
		minsk = INF;
		money = 0;
		skill.assign(M, 0);
		for (ll i = 0; i < N; ++i) { 
			if (bit & (1 << i)) { // bitのi番目にフラグが立っているか
				rep(j, M) {
					skill[j] += A[i][j];
				}
				money += C[i];
			}
		}
		rep(j, M) {
			minsk = min(minsk, skill[j]);
		}
		if (minsk >= X) {
			ans = min(ans, money);
		}
	}

	if (ans == INF) ans = -1;
	cout << ans << endl;
	
	return 0;
}

Measured memory_bytes: 3664
#include <algorithm>
#include <cstdint>
#include <iostream>
#include <vector>

using namespace std;

struct Node
{
    int left;
    int right;

    Node(int left, int right) : left(left), right(right) {}
    Node() : Node(-1, -1) {}

    static Node Merge(const Node &a, const Node &b)
    {
        int left = (a.left != -1 && b.left != -1 ? min(a.left, b.left) : max(a.left, b.left));
        int right = max(a.right, b.right);

        return Node(left, right);
    }
};

class SegTree
{
public:
    SegTree(int size) : tree_(4 * size + 4), size_(size) {}

    void Add(int pos) { Update(0, 0, size_ - 1, pos); }

    int GetLeft(int pos) const { return Get(0, 0, size_ - 1, 0, pos - 1).right; }
    int GetRight(int pos) const { return Get(0, 0, size_ - 1, pos + 1, size_ - 1).left; }

private:
    void Update(int node, int left, int right, int pos);
    Node Get(int node, int left, int right, int x, int y) const;

    int LeftSon(int node) const { return 2 * node + 1; }
    int RightSon(int node) const { return 2 * node + 2; }

    vector<Node> tree_;
    int size_;
};


void SegTree::Update(int node, int left, int right, int pos)
{
    if (left == right) {
        tree_[node].left = tree_[node].right = pos;
        return;
    }

    int mid = left + (right - left) / 2;
    if (pos <= mid) {
        Update(LeftSon(node), left, mid, pos);
    } else {
        Update(RightSon(node), mid + 1, right, pos);
    }
    tree_[node] = Node::Merge(tree_[LeftSon(node)], tree_[RightSon(node)]);
}

Node SegTree::Get(int node, int left, int right, int x, int y) const
{
    if (x > y) {
        return Node();
    }
    if (x <= left && right <= y) {
        return tree_[node];
    }

    Node res;
    int mid = left + (right - left) / 2;

    if (x <= mid) {
        res = Node::Merge(res, Get(LeftSon(node), left, mid, x, y));
    }
    if (mid < y) {
        res = Node::Merge(res, Get(RightSon(node), mid + 1, right, x, y));
    }
    return res;
}

int64_t CountPairs(const SegTree &tree, int pos)
{
    int left = tree.GetLeft(pos);
    int right = tree.GetRight(pos);

    int far_left = tree.GetLeft(left);
    int far_right = tree.GetRight(right);

    int64_t pairs = 0;
    if (far_left != -1) {
        pairs += 1LL * (right - pos) * (left - far_left);
    }
    if (far_right != -1) {
        pairs += 1LL * (pos - left) * (far_right - right);
    }
    return pairs;
}

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

    vector<pair<int, int>> vec(n);
    for (int i = 0; i < n; i += 1) {
        cin >> vec[i].first;
        vec[i].second = i + 1;
    }
    sort(vec.begin(), vec.end(), greater<pair<int, int>>());

    SegTree tree(n + 2);
    tree.Add(0);
    tree.Add(n + 1);

    int64_t sum = 0;
    for (const auto &p : vec) {
        auto pairs = CountPairs(tree, p.second);
        sum += pairs * p.first;
        tree.Add(p.second);
    }

    cout << sum << "\n";
    return 0;
}


Measured memory_bytes: 4096
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <cmath>
#include <iomanip>
#include <map>
#include <unordered_map>
#include <cstring>

using namespace std;
using ll = long long;
using pint = pair<int, int>;

ll INF = 1LL << 60;

int dr[4] = { 1, 1, -1, -1 };
int dc[4] = { 1, -1, -1, 1 };

bool dfs(vector<string>& board, int r, int c) {
	for (int dir = 0; dir < 4; dir++) {
		int nr = r;
		int nc = c;
		while (true) {
			nr += dr[dir];
			nc += dc[dir];
			if (nr < 0 || nr >= 8 || nc < 0 || nc >= 8) break;
			if (board[nr][nc] == 'Q') return false;
		}
	}
	return true;
}

int main() {
	int k;
	cin >> k;
	vector<string> board(8, "........");
	vector<int> r(k), c(k);
	for (int i = 0; i < k; i++) cin >> r[i] >> c[i];
	vector<int> order(8);
	for (int i = 0; i < 8; i++) order[i] = i;

	do {
		for (int i = 0; i < 8; i++) {
			for (int j = 0; j < 8; j++) board[i][j] = '.';
		}

		bool ok = true;
		for (int i = 0; i < 8; i++) board[i][order[i]] = 'Q';
		for (int i = 0; i < k; i++) {
			if (board[r[i]][c[i]] != 'Q') ok = false;
		}
		if (!ok) continue;

		for (int a = 0; a < 8; a++) {
			ok = dfs(board, a, order[a]);
			if (!ok) break;
		}

		if (ok) break;

	} while (next_permutation(order.begin(), order.end()));

	for (int i = 0; i < 8; i++) {
		for (int j = 0; j < 8; j++) cout << board[i][j];
		cout << endl;
	}

	return 0;
}


Measured memory_bytes: 3220
#include <stdio.h>
#include <math.h>

int main(void)
{
	double S[1000];

	double a, m, t;
	int i, n;

	while (1)
	{
		scanf("%d", &n);
		if (n == 0) break;

		t = 0;
		for (i = 0; i < n; i++)
		{
			scanf("%lf", &S[i]);
			t += S[i];
		}
		m = t / n;

		a = 0;		
		for (i = 0; i < n; i++) a += (S[i] - m) * (S[i] - m);
		a = sqrt(a / n);

		printf("%.5lf\n", a);

	}

	return 0;
}

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

int main() {
    int d, s, i;
    while (cin >> d) {
        s = 0;
        for (i = 1; i < 600/d; i++) {
            s += d * (d * i) * (d * i);
        }
    cout << s << endl; 
    }
    return 0;
}


Measured memory_bytes: 3124
#include<bits/stdc++.h>
#define rep(i, n) for(i = 0; i < (n); ++i)
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
#define MOD 1000000007
 
int main(){
  ll N, i, M;
  double tot = 0;
  vector<ll> A(100);
  string ans = "Yes";
  cin >> N >> M;
  rep(i, N){
    cin >> A[i];
    tot += A[i];
  }
  sort(A.begin(), A.end()); reverse(A.begin(), A.end());
  if(A[M - 1] < tot*1/4/M){
    ans = "No";
  }
 
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 256
#include <algorithm>
#include <cassert>
#include <climits>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <list>
#include <map>
#include <memory>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>
//#include <regex>

/* g++ -g -std=c++0x */
/* g++ -g -std=c++11 */

using namespace std;

// freopen("input.txt", "rt", stdin);
// freopen("output.txt", "wt", stdout);

#define ALL(c)          (c).begin(), (c).end()
#define ALLR(c)         (c).rbegin(), (c).rend()
#define FOR(i,a,b)      for (int i=(a); i < (b); ++i)
#define FORR(i,a,b)     for (int i=(a); i > (b); --i)
#define FOR_ALL(i,c)    for (__typeof((c).begin()) i=(c).begin();   \
                             i != (c).end(); ++i)
#define FOR_ALLR(i,c)   for (__typeof((c).rbegin()) i=(c).rbegin(); \
                             i != (c).rend(); ++i)
#define SZ(array)       (sizeof(array)/sizeof(array[0]))
#define lc(x)           (x<<1)     /* 2*x */
#define rc(x)           (x<<1 | 1) /* 2*x+1 */
#define lowbit(x)       (x & (-x)) /* 0b10100 -> 0b100 */

typedef long long       LL;
typedef map<int,int>    MII;
typedef pair<int,int>   PII;
typedef set<int>        SI;
typedef vector<bool>    VB;
typedef vector<double>  VD;
typedef vector<int>     VI;
typedef vector<string>  VS;

/* check if a key is in container C */
template <class C>
inline bool in_(const typename C::key_type& k, const C& A)
{ return A.find(k) != A.end(); }
inline bool in_(const string& s, const string& S)
{ return S.find(s) != string::npos; }

/*
 * Basically, we want to count how many sub-sequence of 'ABC' can be
 * generated.
 */

const int mod = 1e9+7;
const int maxn = 1e5+5;
int power[maxn], dp[maxn][3];
string s;

int mul(const LL a, const LL b)
{ return (a*b % mod + mod ) % mod; }
int mul(const LL a, const LL b, const LL c)
{ return mul(a, mul(b,c)); }
int mul(const LL a, const LL b, const LL c, const LL d)
{ return mul(a, mul(b,c,d)); }

int dfs(const int i, const int j)
{
    if (i < 1 && j > 0)
        return 0;
    if (i == 0)
        return s[i] == 'A' | s[i] == '?';
    int& ans = dp[i][j];
    if (-1 == ans) {
        ans = 0;
        typedef vector<char> VC;
        VC A = (s[i] == '?') ? VC({ 'A','B','C' }) : VC({ s[i] });
        FOR_ALL(a,A) {
            ans += dfs(i-1,j); 
            ans %= mod;
            if (*a - 'A' == j) {
                if (j > 0) 
                    ans += dfs(i-1,j-1);
                else
                    ans += power[i-1];
            }
            ans %= mod;
        }
    }
    return ans;
}

int main()
{
/* #ifndef ONLINE_JUDGE */
/*     freopen("foo", "rt", stdin); */
/* #endif */
    ios::sync_with_stdio(false);
    while (cin >> s) {
        memset(dp,-1,sizeof(dp));
        const int n = s.size();
        power[0] = s[0] == '?' ? 3 : 1;
        FOR(i,1,n)
            power[i] = 1LL * power[i-1] * (s[i] == '?' ? 3 : 1) % mod;
        const int ans = dfs(n-1,2);
        cout << ans << endl;
    }
    return 0;
}


Measured memory_bytes: 14416