akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <vector>
#include <stack>
#include <queue>
#include <deque>
#include <algorithm>
#include <numeric>
#include <functional>
#include <map>
#include <set>
#define Rep(i, n) for(int i=0;i<n;++i)
#define rep(i, n) for(int i=1;i<=n;++i)
#define ll long long
#define INF 100000000
#define mod 1000000007
#define PI 3.14159265359
#define All(a) (a).begin(), (a).end()

using namespace std;
using P = pair<ll int, ll int>;
 
int dx[4] = {0, 1, 0, -1};
int dy[4] = {1, 0, -1, 0};

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

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

int N;
int a[110000];

int main () {
  cin >> N;
  Rep(i, N) cin >> a[i];

  multiset<int> st;
  st.insert(a[0]);

  for(int i=1;i<N;++i) {
    auto itr = st.lower_bound(a[i]);

    if (itr == st.begin()) {
      st.insert(a[i]);
    } else {
      itr--;
      st.erase(itr);
      st.insert(a[i]);
    }
  }

  cout << st.size() << "\n";
}

Measured memory_bytes: 5376
import string, sys

alpha = 'abcdefghijklmnopqrstuvwxyza'
tbl = string.maketrans(alpha[:-1], alpha[1:])

for s in sys.stdin:
	while not('the' in s or 'that' in s or 'this' in s):
		s = s.translate(tbl)
	print s[:-1]

Measured memory_bytes: 4372
#include<iostream>
#include <string>
#include <vector>
#include <stdio.h>

int main(void)
{
    int N;
    std::cin >> N;
    std::vector<int> vec(N);
    int tmp;
    int i = 0, j = 0;
    std::string answer;
    while (std::cin >> tmp)
    {
        vec[i] = tmp;
        if (i == N - 1)
        {
            break;
        }
        i++;
    }
    for (j = 0; j < N; j++)
    {
        if (vec[j] % 2 == 0)
        {
            if (vec[j] % 3 != 0 && vec[j] % 5 != 0)
            {
            answer = "DENIED";
            break;
            }
        }
    }

    if (answer != "DENIED")
    {
        answer = "APPROVED";
    }
    std::cout << answer;
    return 0;
}

Measured memory_bytes: 256
<?php
$D = (int)trim(fgets(STDIN));
//$S = trim(fgets(STDIN));
//list($N,$M,$K) = array_map('intval',explode(" ",trim(fgets(STDIN))));
$c = array_map('intval',explode(" ",trim(fgets(STDIN))));
for($i=0;$i<$D;$i++) {
  $s[]=array_map('intval',explode(" ",trim(fgets(STDIN))));
}
for($i=0;$i<$D;$i++) {
  $t[]=(int)trim(fgets(STDIN));
  printf("%d\n",compute_score($t));
}


function compute_score($out) {
  global $D,$s,$c;
  $last = array_fill(0,26,0);
  $outcnt = count($out);

  for($d=0;$d<$outcnt;$d++) {
    $last[$out[$d]-1]=$d+1;
    for($i=0;$i<26;$i++) {
      $score -= ($d + 1 - $last[$i]) * $c[$i];
    }
    $score += $s[$d][$out[$d]-1];
  }
  return $score;
}


Measured memory_bytes: 16668
fun main(args: Array<String>) {
    val (n, m) = readLine()!!.split(' ').map { it.toLong() }
    var ans = 0L
    var i = 1L
    while (i * i <= m) {
        if (m % i == 0L) {
            for (d in arrayOf(i, m / i)) {
                if (m >= n * d) {
                    ans = Math.max(ans, d)
                }
            }
        }
        i++
    }
    println(ans)
}


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

using namespace std;
using ll = long long;

int main() {
    int N = 0;
    cin >> N;
    string temp[N];
    map<string, int> voting_paper;
    int ans = 0;

    for(int i = 0; i < N; i++) {
        cin >> temp[i];
        if(voting_paper.count(temp[i])) {
            voting_paper.at(temp[i])++;
            continue;
        }
        voting_paper[temp[i]] = 1;
    }

    for(int i = 0; i < N; i++) {
        ans = max(ans,voting_paper[temp[i]]);
    }
    queue<string> que;
    for(int i = 0; i < N; i++) {
        if(ans == voting_paper[temp[i]]) {
            que.push(temp[i]);
            voting_paper.erase(temp[i]);
        }
    }
    vector<string> list(que.size());
    for(int i = 0; i < list.size(); i++) {
        list.at(i) = que.front();
        que.pop();
    }
    sort(list.begin(),list.end());
    for(int i = 0; i < list.size(); i++) {
        cout << list.at(i) << endl;
    }



    return 0;
}

Measured memory_bytes: 25488
n=int(input())
s=input()
ch=['S','W']


for c1 in range(2):
    for c0 in range(2):
        if (ch[c1]=='S' and s[1]=='o') or (ch[c1]=='W' and s[1]=='x'):
            ans=ch[c0]+ch[c1]+ch[c0]
        else:
            ans=ch[c0]+ch[c1]+ch[(c0+1)%2]
        
        i=2

        while i<n-1:
            if (ans[-1]=='S' and s[i]=='o') or (ans[-1]=='W' and s[i]=='x'):
                ans+=ans[-2]
            else:
                ans+='W' if ans[-2]=='S' else 'S'
            i+=1
        
        for i in range(n):
            bc=ans[(i-1+n)%n]
            ac=ans[(i+1)%n]

            if (ans[i]=='S' and s[i]=='o') or (ans[i]=='W' and s[i]=='x'):
                if bc!=ac:
                    break
            else:
                if bc==ac:
                    break
        else:
            print(ans)
            exit(0)

print(-1)

Measured memory_bytes: 213984
N, Q = map(int, input().split())
S = '0' + input()
acm_cntAC = [0 for _ in range(N+1)]
for i in range(1, N+1):
    if S[i-1:i+1] == 'AC':
        acm_cntAC[i] = acm_cntAC[i-1] + 1
    else:
        acm_cntAC[i] = acm_cntAC[i - 1]

for _ in range(Q):
    l, r = map(int, input().split())
    if S[l-1:l+1] == 'AC':
        print(acm_cntAC[r] - acm_cntAC[l - 1] - 1)
    else:
        print(acm_cntAC[r] - acm_cntAC[l-1])


Measured memory_bytes: 6304
#include<iostream>
#include<string>
#include<cstdio>
#include<algorithm>
#include<cstdlib>
#include<cmath>
#include<vector>
#include<utility>
#include<queue>
#include<stack>
#include<set>
#include<map>
#include<unordered_set>
#include<unordered_map>
#include<bitset>
using namespace std;
#define INF 1000000007
#define LINF 100000000000000007
#define MOD 1000000007
#define int long long
#define rep(i,n) for(int i=0;i<n;i++)
#define repb(i, n) for (int i = n - 1; i >= 0; i--)
#define MODE 1
#ifdef MODE
#define DEB(X) cout<< #X <<": "<<X<<" ";
#define ARDEB(i,X) cout<< #X <<"["<<i<<"]: "<<X[i]<<" ";
#define END cout<<endl;
#else
#define DEB(X) {}
#define ARDEB(i,X) {}
#define END {}
#endif
//typedef long long int ll;
typedef pair<int,int> P;
struct edge{int to,cost;};

int ans=1;
int n,m;
int a[111111];
int cntcol[3];
signed main(){
	
	cin>>n;

	rep(i,n)cin>>a[i];
	if(a[0]!=0)ans=0;
	rep(i,n){
		if(i==0){
			ans*=3;
			cntcol[0]++;
		}
		else{
			int cnt=0;
			rep(j,3){
				if(cntcol[j]==a[i])cnt++;
			}
			rep(j,3){
				if(cntcol[j]==a[i]){
					cntcol[j]++;
					break;
				}
			}
			ans*=cnt;
			ans%=MOD;
		}
	}
	cout<<ans<<endl;
}


Measured memory_bytes: 1024
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cstring>
#include <string>
#include <cmath>
#define N 100010
#define M 55
#define ls i << 1
#define rs i << 1 | 1
#define inf 1000000001
#define inc(i) (++ (i))
#define dec(i) (-- (i))
#define mid ((l + r) >> 1)
#define int long long
#define XRZ 1000000007
#define debug() puts("XRZ TXDY");
#define n_ ((n >> 1) + 1)
#define mem(i, x) memset(i, x, sizeof(i));
#define Next(i, u) for(register int i = head[u]; i ; i = e[i].nxt)
// #define file(x) freopen(#x".in", "r", stdin), freopen(#x".out", "w", stdout);
#define Rep(i, a, b) for(register int i = (a) , i##Limit = (b) ; i <= i##Limit ; inc(i))
#define Dep(i, a, b) for(register int i = (a) , i##Limit = (b) ; i >= i##Limit ; dec(i))
// const int dx[10] = {1, -1, 0, 0};
// const int dy[10] = {0, 0, 1, -1};
using namespace std;
inline int read() {
    register int x = 0, f = 1; register char c = getchar();
    while(c < '0' || c > '9') {if(c == '-') f = -1; c = getchar();}
    while(c >= '0' && c <= '9') x = x * 10 + c - 48, c = getchar();
    return x * f;
}
int n, x;
signed main() {
    n = read();
    Rep(i, 1, n) {
      x = read();
      if(x % 2 == 0) {
        if(x % 3 != 0 && x % 5 != 0) {puts("DENIED"); return 0;}
      }
    } puts("APPROVED");
    return 0;int zmy666 = 232313092, zzz = 389898087, xjj = 83989342;
}


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

const ll mod = 1e9 + 7;
const ll nmax = 4e5 + 5;
ll facts[nmax];

void calc_fact() {
  facts[0] = 1;
  for (ll i = 1; i < nmax; i++) {
    facts[i] = facts[i - 1] * i % mod;
  }
}

ll powmod(ll a, ll b) {
  ll ans = 1;
  while (b) {
    if (b % 2) {
      ans *= a;
      ans %= mod;
    }
    a *= a;
    a %= mod;
    b /= 2;
  }
  return ans;
}

ll comb(ll a, ll b) {
  return facts[a] * powmod(facts[b], mod - 2) % mod
                  * powmod(facts[a - b], mod - 2) % mod;
}

int main() {
  ll n, k;
  cin >> n >> k;

  calc_fact();

  ll ans = 0;
  if (n - 1 <= k) {
    ans = comb(2 * n - 1, n);
  } else {
    for (ll i = 0; i <= k; i++) {
      ans += (comb(n, i) * comb(n - 1, i)) % mod;
      ans %= mod;
    }
  }
  cout << ans << endl;
}

Measured memory_bytes: 3328
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> lpair;
const ll MOD = 1e9 + 7;
const ll INF = 1e18;
#define rep(i,m,n) for(ll i = (m); i < (n); i++)
#define rrep(i,m,n) for(ll i = (m); i >= (n); i--)
#define print(x) cout << (x) << endl;
#define print2(x,y) cout << (x) << " " << (y) << endl;
#define printa(x,n) for(ll i = 0; i < n; i++){ cout << (x[i]) << " ";} cout<<endl;
int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll a[5];
    rep(i,0,5) cin >> a[i];
    ll ans = 0;
    rep(i,0,5){
        ans += 10 * ((a[i] + 9) / 10);
    }
    ll amari = 10;
    rep(i,0,5){
        if(a[i] % 10 == 0) continue;
        amari = min(amari, a[i]%10);
    }
    ans += amari - 10;
    print(ans);


    
}

Measured memory_bytes: 256
A = int(input())
B = int(input())
C = int(input())
X = int(input())

cnt = 0

for i in range(A+1):
    for j in range(B+1):
        for l in range(C+1):
            if (X == ( (500 * i) + (100 * j) + (50 * l) )):
                cnt += 1

print (cnt)


Measured memory_bytes: 3060
#include <cstdio>
#include <cmath>
#include <iostream>
#include <set>
#include <algorithm>
#include <vector>
#include <map>
#include <cassert>
#include <string>
#include <cstring>
#include <queue>

using namespace std;

#define rep(i,a,b) for(int i = a; i < b; i++)
#define S(x) scanf("%d",&x)
#define S2(x,y) scanf("%d%d",&x,&y)
#define P(x) printf("%d\n",x)
#define all(v) v.begin(),v.end()
#define FF first
#define SS second
#define pb push_back
#define mp make_pair

typedef long long int LL;
typedef pair<int, int > pii;
typedef vector<int > vi;

set<int> s;

int main() {
  int n;
  S(n);
  while(n--) {
    int x;
    S(x);
    if(s.find(x) == s.end()) {
      s.insert(x);
    } else {
      s.erase(x);
    }
  }
  P((int)s.size());
  return 0;
}

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

int main(){
int H,W;
  cin>>H>>W;
  char a[100][100], b[102][102];
  
  for(int i=0; i<H; i++){
    for(int j=0; j<W; j++){
    cin>>a[i][j]; }}
 
  for(int i=0; i<H+2; i++){
   for(int j=0; j<W+2; j++){
    b[i][j]='#'; }}
  
  for(int i=0; i<H; i++){
   for(int j=0; j<W; j++){
    b[i+1][j+1]=a[i][j]; }}
  
  for(int i=0; i<H+2; i++){
   for(int j=0; j<W+2; j++){
     cout<<b[i][j];
   }
    cout<<endl;
  }
  
}


Measured memory_bytes: 256
n=int(input())
x=[]
u=[]
for i in range(n):
  a,b=input().split()
  x.append(float(a))
  u.append(b)

ans=0
for i in range(n):
  if u[i]=="JPY":
    ans+=x[i]
  else:
    ans+=x[i]*380000.0
print(ans)

Measured memory_bytes: 3064
#include<stdio.h>
#include<string.h>
char a[4001],b[4001];
int dp[4001][4001]={0};
int main(){
	int i,j,n,x,y;
	while(scanf("%s %s",a,b)!=EOF){
		n=0;
		memset(dp,0,sizeof(dp));
		x=strlen(a);
		y=strlen(b);
		for(i=1;i<=x;i++){
			for(j=1;j<=y;j++){
				if(a[i-1]==b[j-1])dp[i][j]=dp[i-1][j-1]+1;
				else dp[i][j]=0;
				if(n<dp[i][j])n=dp[i][j];
			}
		}
		printf("%d\n",n);
	}
	return 0;
}


Measured memory_bytes: 64312
#include <bits/stdc++.h>
#define MOD 1000000007LL
using namespace std;
typedef long long ll;
typedef pair<int,int> P;

int n,k;
int a[200005];
int sum[200005];

int main(void){
	scanf("%d%d",&n,&k);
	for(int i=0;i<n;i++){
		scanf("%lld",&a[i]);
	}
	for(int i=0;i<k;i++){
		memset(sum,0,sizeof(sum));
		bool flag=true;
		for(int j=0;j<n;j++){
			if(a[j]!=n){
				flag=false;
			}
		}
		if(flag)break;
		for(int j=0;j<n;j++){
			sum[max(0,j-a[j])]++;
			sum[min(n,j+a[j]+1)]--;
		}
		for(int j=0;j<n;j++){
			sum[j+1]+=sum[j];
			a[j]=sum[j];
		}
	}
	for(int i=0;i<n;i++){
		printf("%d%c",a[i],i+1==n?'\n':' ');
	}
	return 0;
}


Measured memory_bytes: 5384
#include<iostream>
#include<algorithm>
#include<vector>
#include<numeric>
#include<string>
#include<cmath>
#include<set>
#include<queue>
#include<deque>
#include<bitset>
#include<iomanip>
#include<cctype>
#include<map>

#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define rep2(i,a,b) for (int (i)=a;(i)<(b);(i)++)
#define all(x) (x).begin(),(x).end()

using namespace std;
const int inf = 1001001000;
const long long int Inf = 1001001001001001000;

void print(vector<vector<int>> a){
	for (int i = 0; i < a.size(); i++)
	{
		for (int j=0;j<a[i].size();j++){
			cout << a[i][j] << " ";
		}
		cout << endl;
	}
}

void print(vector<vector<long long int>> a){
	for (int i=0;i<a.size();i++){
		for (int j=0;j<a[i].size();j++){
			cout << a[i][j] << " ";
		}
		cout << endl;
	}
}

void print(vector<int> a){
    int n = a.size();
    for (int j=0;j<n;j++) {
        if (j != n-1) cout << a[j] << " ";
        else cout << a[j] << endl;
    }
}

void print(set<int> a){
	for (auto x:a)
		cout << x << " ";
	cout << endl;
}



int main()
{
	int n, q;
	cin >> n >> q;
	vector<vector<int>> a(n);
	rep(_,q){
		int c;
		cin >> c;
		if(c == 0){
			int t, x;
			cin >> t >> x;
			a[t].push_back(x);
		} else if (c == 2){
			int t;
			cin >> t;
			if (a[t].size())
				a[t].pop_back();
		} else {
			int t;
			cin >> t;
			if (a[t].size())
				cout << a[t].back() << endl;
		}
	}

	return 0;
}


Measured memory_bytes: 3728
#include<stdio.h>
#define N 10001
#define M 100

int main()
{
  int i, j, n;
  int a[N];
  int sa[M][M];
  int temp;

  while(1)
    {
      
      scanf("%d",&n);

      if(n==0)
	return 0;
      else
	{
	  /*printf("n = %d\n",n);*/
	  
	  for(i=0;i<n;i++)
	    {
	      scanf("%d",&a[i]);
	      /*printf("%d = %d\n",i,a[i]);*/
	    }
	  
	  temp = 0;
	  
	  for(i=0;i<n;i++)
	    {
	      for(j=i+1;j<n;j++)
		{
		  sa[i][j] = a[i] - a[j];
		  if(sa[i][j]<0)
		    {
		      sa[i][j] = (-1)*sa[i][j];
		    }
		  if(j==1 || temp>sa[i][j])
		    {
		      temp = sa[i][j];
		    }
		}
	    }
	  printf("%d\n",temp);
	}
    }
  return 0;
}

Measured memory_bytes: 612
#pragma GCC optimize("Ofast", "unroll-loops")

#include <bits/stdc++.h>

using namespace std;

#define ll long long
#define ld long double

signed main() {
	int a, b; cin >> a >> b;
	if (a < b)
		for (int i = 0; i < b; ++i)
			cout << a;
	else
		for (int i = 0; i < a; ++i)
			cout << b;
	cout << endl;
	return 0;
}

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

#define int long long
#define pb push_back
#define vi vector<int>
#define pi pair<int,int>
#define vii vector<pi>
#define ps(x,y) fixed<<setprecision(y)<<x
#define w(t) int t;cin>>t;while(t--)solve()
#define debug(...) fprintf(stderr, __VA_ARGS__), fflush(stderr)
#define f(n) for (int i=0;i<n;++i)
#define init(arr,m,n,value) std::fill(*arr,*arr+m*n,value)
#define low(s) transform(s.begin(),s.end(),s.begin(),::tolower)
#define up(s) transform(s.begin(),s.end(),s.begin(),::toupper)
//debug("Total Time: %.3f\n", (double)(clock() - z) / CLOCKS_PER_SEC);

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

int binpow(int a, int b) {
    int res = 1;
    while (b > 0) {
        if (b & 1)res = res * a;
        a = a * a;
        b >>= 1;
    }
    return res;
}

void solve(){
	
}

int32_t main(){
	ios::sync_with_stdio(0);
	cin.tie(0);
	//clock_t z = clock();
	int a,b,c,d;
	cin>>a>>b>>c>>d;
	cout<<max({b*d,a*c,a*d,b*c});


}


Measured memory_bytes: 3616
#include <bits/stdc++.h>
using namespace std;
 
int main() {
	// your code goes here
	long long int  n;
	cin>>n;
	long long int  sum = 0;
	for(long long int i=0;i<=n;i++)
	{
		if(i%3==0) 
		continue;
		else if(i%5==0)
		continue;
		else
		sum = sum + i;
	}
	cout<<sum;
	
	return 0;
}

Measured memory_bytes: 3676
#include<stdio.h>

int main()
{
  int n,a,b,ap,bp;
  while(1)
  {
    scanf("%d",&n); if(!n)break;
    ap = bp = 0;
    while(n--)
    {
      scanf("%d%d",&a,&b);

      if(a > b) ap += a+b;
      if(a < b) bp += a+b;
      if(a == b)
      {
        ap += a;
        bp += b;
      }
    }
    printf("%d %d\n",ap,bp);
  }
  return 0;
}

Measured memory_bytes: 0
extern crate core;

use std::io::{self, Read};
use std::collections::HashMap;

fn main() {
    let mut input = String::new();
    io::stdin().read_to_string(&mut input).unwrap();
    let output = run(input);
    println!("{}", output);
}

fn f(vec: &mut Vec<(&i32, &i32)>, k: i32, count: i32) -> i32 {
    if vec.len() as i32 <= k {
        count
    } else {
        let (_, x) = vec.pop().unwrap();
        f(vec, k, count + x)
    }
}

fn run(input: String) -> String {
    let list: Vec<i32> = input
        .split("\n")
        .nth(1)
        .unwrap()
        .split_whitespace()
        .map(|x| x.parse::<i32>().unwrap())
        .collect();

    let k = input
        .split("\n")
        .nth(0)
        .unwrap()
        .split_whitespace()
        .nth(1)
        .unwrap()
        .parse::<i32>()
        .unwrap();

    let mut map: HashMap<i32, i32> = HashMap::new();
    for x in list {
        let insert = match map.get(&x) {
            Option::Some(y) => y + 1,
            Option::None => 1,
        };
        map.insert(x, insert);
    }

    let mut vec: Vec<(&i32, &i32)> = map.iter().collect();
    vec.sort_by(|&(_, a), &(_, b)| b.cmp(&a));

    f(&mut vec, k, 0).to_string()
}

Measured memory_bytes: 15024
// #pragma comment(linker, "/stack:200000000")
// #pragma GCC optimize("Ofast,no-stack-protector")
// #pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,avx2,tune=native")
// #pragma GCC optimize("unroll-loops")

#include <bits/stdc++.h>

#ifdef PERVEEVM_LOCAL
    #define debug(x) std::cerr << (#x) << ":\t" << (x) << std::endl
#else
    #define debug(x) 238;
#endif

#define fastIO std::ios_base::sync_with_stdio(false); std::cin.tie(0); std::cout.tie(0)
#define NAME "File"

using ll = long long;
using ld = long double;

#ifdef PERVEEVM_LOCAL
    std::mt19937 rnd(238);
#else
    std::mt19937 rnd(std::chrono::high_resolution_clock::now().time_since_epoch().count());
#endif

const double PI = atan2(0.0, -1.0);
const int INF = 0x3f3f3f3f;
const ll LINF = (ll)2e18;
const int N = 100100;

ll dp[N];
int h[N];

void run() {
    int n, k;
    scanf("%d%d", &n, &k);

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

    dp[0] = 0;
    for (int i = 1; i < n; ++i) {
        dp[i] = LINF;

        for (int j = i - 1; j >= std::max(0, i - k); --j) {
            dp[i] = std::min(dp[i], dp[j] + abs(h[i] - h[j]));
        }
    }

    printf("%lld\n", dp[n - 1]);
}

int main(void) {
    // freopen(NAME".in", "r", stdin);
    // freopen(NAME".out", "w", stdout);

    auto start = std::chrono::high_resolution_clock::now();
    run();
    auto end = std::chrono::high_resolution_clock::now();

    #ifdef PERVEEVM_LOCAL
        std::cerr << "Execution time: "
                  << std::chrono::duration_cast<std::chrono::milliseconds>(end - start).count()
                  << " ms" << std::endl;
    #endif

    return 0;
}


Measured memory_bytes: 1536
#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pii = pair<int, int>; 
using pll = pair<long long, long long>;
constexpr char ln =  '\n';
constexpr long long MOD = 1000000007LL;
constexpr long long INF = 1001001001LL;
constexpr long long LINF = 1001001001001001001;
#define all(x) (x).begin(),(x).end()
#define rep(i,n) for(int i=0;i<(n);i++)
#define rept(i, j, n) for(int i=(j); i<(n); i++)
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }


int main(){
    int n; cin >> n;
    vector<ll> A(n); rep(i, n) cin >> A[i];
    
    bool fg = true;
    if(A[0] != 0)fg = false;
    int bef = A[0]; ll sum = 0;
    rept(i, 1, n){
      if(A[i] > bef + 1){fg = false; break;}
      if(A[i] < bef + 1){
        sum += A[i-1];
      }
      bef = A[i];
    }
    sum += A[n-1];
    if(fg) cout << sum << ln;
    else cout << -1 << ln;
}


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

int main() {
    int64_t q, h, s, d, n;
    cin >> q >> h >> s >> d >> n;
    int64_t cost[3] = {4*q, 2*h, s};
    int64_t ans;
    sort(cost, cost+3);
    int64_t mincost = cost[0];
    if (n == 1) {
        ans = mincost;
    }
    else if (n % 2 == 1) {
        if (d < 2*mincost) {
            ans = n/2*d + mincost;
        }
        else {
            ans = n * mincost;
        }
    }
    else {
        ans = min(n * mincost, n/2*d);
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#define pb push_back
#define mp make_pair
#define all(a)      (a).begin(),(a).end()
#define debug_array(a,n) for (ll bccc=(0); bccc<(n); bccc++) cout<<a[bccc]<<" "<<"\n"
#define debug_vector(a) for(ll bccc=(0); bccc<(a.size());bccc++) cout<<a[bccc]<<" "<<"\n"
#define F           first
#define S           second
#define debug_set(s) for(auto p:s) cout<<p<<" "
#define debug_map(m) for(auto p:m) cout<<p.F<<" "<<p.S<<"\n"
#define trace(x) cerr<<#x<<": "<<x<<" "<<endl;
typedef long long ll;
using namespace __gnu_pbds;
typedef tree<pair<ll,ll>,null_type,less<pair<ll,ll> >,rb_tree_tag,tree_order_statistics_node_update> ordered_multiset;

/* ll t = 0;
ordered_multiset me;
...
me.insert({x, t++});
me.erase(me.lower_bound({x, 0}));
cout << me.order_of_key({x, 0}) << "\n";

///////////   t is insertion time
*/
//#pragma GCC optimize("Ofast")  // works very well
#define ordered_set tree<ll, null_type,less<ll>, rb_tree_tag,tree_order_statistics_node_update>
mt19937 rng(chrono::high_resolution_clock::now().time_since_epoch().count());
typedef long double lld;
lld pi=3.14159265358;
ll powr(ll a,ll b)
{
    ll c=1;
    ll kjk;
    for(kjk=0;kjk<b;kjk++)
        c*=a;
    return c;
}
ll hell=1000000007;
//ll hell=998244353   ;
ll power(ll x, ll y, ll p)
{
    ll res = 1;
    x = x % p;
    while (y > 0)
    {
        if (y & 1)
            res = (res*x) % p;
        y = y>>1;
        x = (x*x) % p;
    }
    return res;
}
//freopen("input.txt", "r", stdin);
//freopen("output.txt", "w", stdout);
// to generate random number , use rng() ... eg cout<<rng();
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    string s,t;
    cin>>s>>t;
    ll n,i;
    n=s.size();
    ll ans=0;
    for(i=0;i<n;i++)
    {
        if(s[i]!=t[i])
            ans++;
    }
    cout<<ans;

    return 0;
}


Measured memory_bytes: 3788
N, A, B, C = [int(i) for i in input().split()]
# Nが与えられた竹, A, B, Cが作り出したい竹
L = [int(input()) for i in range(N)]


def dfs(idx, a, b, c):

    if idx == N:
        if a == 0 or b == 0 or c == 0:
            return 1e9  # 10の9乗

        return abs(A - a) + abs(B - b) + abs(C - c)

    x = dfs(idx + 1, a, b, c)
    y = dfs(idx + 1, a + L[idx], b, c) + 10*(a != 0)
    z = dfs(idx + 1, a, b + L[idx], c) + 10*(b != 0)
    w = dfs(idx + 1, a, b, c + L[idx]) + 10*(c != 0)
    return min(x, y, z, w)


ans = dfs(0, 0, 0, 0)
print(ans)


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

using namespace std;

long long MOD=1'000'000'007;

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

    dp[0] = 1;
    for(int i=0; i<N; ++i){
        if(i+1<N+1 && a[i+1]){
            dp[i+1]+=dp[i];
            dp[i+1]%=MOD;
        }
        if(i+2<N+1 && a[i+2]){
            dp[i+2]+=dp[i];
            dp[i+2]%=MOD;
        }
    }

    cout<<dp[N]<<endl;

    return 0;
}


Measured memory_bytes: 1024
import sys
sys.setrecursionlimit(2147483647)
INF=float("inf")
MOD=10**9+7
# input=sys.stdin.readline
def resolve():
    s=input()
    n=len(s)
    ans=0
    from itertools import product
    for A in product(range(2),repeat=n-1):
        k=s[0]
        for i in range(n-1):
            k+='+' if A[i] else ''
            k+=s[i+1]
        ans+=eval(k)
    print(ans)
resolve()

Measured memory_bytes: 39408
#include<map>
#include<set>
#include<bitset>
#include<cstdio>
#include<iostream>
#include<algorithm>
#include<vector>
#include<queue>
#include<string>
#include<stack>
#define REP(i,x,y) for(ll i=x;i<=y;i++)
#define SIZE(a) ll(a.size())
#define vll vector<ll> 
#define BIT(n) (ll(1)<<n)
#define UNIQUE(v) v.erase(unique(v.begin(),v.end()),v.end()) 
#define UNIQUE_ARRAY(a,n) n = unique(a + 1, a + x + 1) - a - 1
#define SORT(a,n) sort(a+1,a+n+1)
#define SORT_O(a,n,order) sort(a+1,a+n+1,order)
#define PER(i,y,x) for(ll i=y;i>=x;i--)
typedef long long ll;
using namespace std;
/*
struct point
{
long long dist; long long name;
bool operator<(const point& rhs) const {
return dist > rhs.dist;
}
};
*/

ll const MAX = 3005;
ll a[MAX];
vll G[MAX];
bool order(ll x, ll y) {
	return a[x] < a[y];
}
ll p[MAX];
ll b[MAX] = {};

int main() {
	ll n;
	cin >> n;
	REP(i, 1, n) {
		cin >> a[i];
	}
	REP(i, 1, n - 1) {
		ll x, y;
		cin >> x >> y;
		G[x].push_back(y);
		G[y].push_back(x);
	}
	REP(i, 1, n) {
		p[i] = i;
	}
	sort(p + 1, p + n + 1, order);
	ll cnt = 0;
	REP(i, 1, n) {
		ll cur = p[i];
		REP(j, 0, SIZE(G[cur])-1) {
			ll next = G[cur][j];
			if (b[next] == -1 && a[cur] != a[next]) {
				b[cur] = 1;
				cnt++;
				break;
			}
		}
		if (b[cur] == 0) {
			b[cur] = -1;
		}
	}
	REP(i, 1, n) {
		if (b[i] == 1) {
			cout << i;
			if (cnt > 1) cout << " ";
			cnt--;
		}
	}
	cout << endl;
}


Measured memory_bytes: 512
#include <bits/stdc++.h>
#define FOR(i, m, n) for(int i = m;i < n;i++)
#define FORR(i, m, n) for(int i = m;i >= n;i--)
#define SORT(v, n) sort(v, v+n);
#define SORTR(v,n) sort(v, v+n, greater<int>());
#define SORTPairSecond(v, n) sort(v, v+n, pairCompareSecond);
#define int long long    // %d=>%lld, 1<<n  => 1LL<<n
#define pb push_back

using namespace std;
typedef long long ll;

typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<int, pii> piii;
typedef pair<ll, pll> plll;
bool pairCompareSecond(const pii& firstEl, const pii& secondEl) {
    return firstEl.second > secondEl.second;
}

const ll MOD = 1000000007;
const int INF = 1000000007;
// const int INF = 0x3f3f3f3f;
const ll LLINF = 0x3f3f3f3f3f3f3f3f;
// const ll LLINF = 1LL << 50;
const double PI = acos(-1);
const double EPS = 0.000000001;
string s;
signed main(){
    cin >> s;

    string out = (s[0] == s[2])?"Yes":"No";
    cout<< out << endl;
    return 0;
}

Measured memory_bytes: 256
while True:
    S=[str(x) for x in input()]
    if S==["-"]:
        break
    else:
        l=len(S)
        m=int(input())
        for i in range(m):
            h=input()
            S=S[int(h):int(l+1)]+S[0:int(h)]
        print("".join(S))

Measured memory_bytes: 7668
#include<bits/stdc++.h>
using namespace std;
const long long maxn=3e5+5;
const long long inf=(1LL<<62);
long long a[maxn],maxv[maxn],minv[maxn];
priority_queue<long long> q;
long long ans=-inf;
int main(){
	ios::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	//freopen(".in","r",stdin);
	//freopen(".out","w",stdout);
	long long n;
	cin>>n;
	for(long long i=1;i<=3*n;i++)
		cin>>a[i];
	long long sum=0;
	for(long long i=1;i<=2*n;i++)
	{
		q.push(-a[i]);
		sum+=a[i];
		if(i>n)
			sum+=q.top(),q.pop();
		maxv[i]=sum;
	}
	while(!q.empty())
		q.pop();
	sum=0;
	for(long long i=3*n;i>=n+1;i--)
	{
		q.push(a[i]);
		sum+=a[i];
		if(i<=2*n)
			sum-=q.top(),q.pop();
		minv[i]=sum;
	}
	for(long long i=n;i<=2*n;i++)
		ans=max(ans,maxv[i]-minv[i+1]);
	cout<<ans<<endl;
	return 0;
}




Measured memory_bytes: 7412
n,p = map(int,input().split())
a = list(map(int,input().split()))

# dp[i][p]:i番目まで見たとき、余りがpとなる選び方
dp = [[0 for _ in range(2)] for _ in range(n+1)]
dp[0][0] = 1
for i in range(n):
  if a[i]%2 == 0:
    dp[i+1][0] = dp[i][0]*2
    dp[i+1][1] = dp[i][1]*2
  else:
    dp[i+1][0] = dp[i][0]+dp[i][1]
    dp[i+1][1] = dp[i][0]+dp[i][1]
print(dp[n][p])
#print(dp)

Measured memory_bytes: 38384
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp> 
using namespace __gnu_pbds;
using namespace std;

typedef long long int lli;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<lli> vli;
typedef vector<pii> vii;
typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> OrderedSet;

const int MOD	= 1e9 + 7;
const double PI = acos(-1.0);

#define fastio			ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
#define sz(a) int((a).size())
#define pb push_back
#define mp make_pair
#define mt make_tuple
#define eb emplace_back
#define all(c) (c).begin(),(c).end()
#define tr(c,i) for(auto &i : c)
#define present(c,x) ((c).find(x) != (c).end())
#define cpresent(c,x) (find(all(c),x) != (c).end())
#define rep(i, n)    for(int i = 0; i < (n); ++i)
#define repA(i, a, n)  for(int i = a; i <= (n); ++i)
#define repD(i, a, n)  for(int i = a; i >= (n); --i)
#define fill(a)  memset(a, 0, sizeof (a))
#define error(x) cerr << #x << " = " << (x) << endl
#define errorp(p) cerr << #p << " = " << (p.first) << ", " << (p.second) << endl

template<typename T> T gcd(T a, T b){return(b?__gcd(a,b):a);}
template <typename T> T lcm(T a, T b){return (a*b)/gcd(a,b); }
int mul(int a, int b, int c){lli res=(lli)a*b;return (int)(res>=c?res%c:res);}
template<typename T>T power(T e, T n, T m){T x=1,p=e;while(n){if(n&1)x=mul(x,p,m);p=mul(p,p,m);n>>=1;}return x;}
int mod_neg(int a, int b, int c){int res;if(abs(a-b)<c)res=a-b;else res=(a-b)%c;return(res<0?res+c:res);}
template<typename T>T extended_euclid(T a, T b, T &x, T &y){T xx=0,yy=1;y=0;x=1;while(b){T q=a/b,t=b;b=a%b;a=t;\
t=xx;xx=x-q*xx;x=t;t=yy;yy=y-q*yy;y=t;}return a;}
template<typename T>T mod_inverse(T a, T n){T x,y,z=0;T d=extended_euclid(a,n,x,y);return(d>1?-1:mod_neg(x,z,n));}
template <class T>  inline void smax(T &x,T y){ x = max((x), (y));}
template <class T>  inline void smin(T &x,T y){ x = min((x), (y));}


int main(){
    #ifdef DEBUG
		freopen("test", "r", stdin);
	#endif
    fastio;
    
    lli N, K;
    cin >> N >> K;
    vi arr(N);
    rep(i, N){
        cin >> arr[i];
        arr[i]--;
    }

    vi dp(N, 0); // step -> country;
    vi visited(N, -1); // country -> step;
    visited[0] = 0;
    dp[0] = 0;
    int curr = 0;
    int step = 0;
    int cycle, start_cycle;
    while(true){
        step++;
        curr = arr[curr];
        if(visited[curr] != -1){
            start_cycle = visited[curr];
            cycle = step - visited[curr];
            break;
        }
        visited[curr] = step;
        dp[step] = curr;
    }

    if(K <= start_cycle){
        cout << dp[K] + 1 << endl;
    }else{
        K -= start_cycle;
        K %= cycle;
        cout << dp[start_cycle + K] + 1 << endl;
    }

    return 0;
}


Measured memory_bytes: 5576
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int main()
{
	int n, m;
	cin>>n>>m;
	vector<int> a(n);
	priority_queue<int> pq;
	for(int i = 0; i < n; i++)
	{
		cin>>a[i];
		pq.push(a[i]);
	}
	for(int i = 0; i < m; i++)
	{
		int t = pq.top();
		pq.pop();
		pq.push(t/2);
	}
	ll sum =0;
	while(n--)
	{
		sum+=pq.top();
		pq.pop();
	}
	cout<<sum<<endl;
}

Measured memory_bytes: 1276
import java.util.Scanner;

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

    while (in.hasNext()) {
      int A = in.nextInt();
      int B = in.nextInt();
      int ans = Math.max(0, A - 2 * B);
      
      System.out.println(ans);
    }
  }
}

Measured memory_bytes: 21844
extern crate proconio;
use proconio::{fastout, marker::Chars};
use std::cmp::Ordering;

#[fastout]
fn main() {
    proconio::input! {
        n: usize,
        mut a: u32,
        mut b: u32,
        mut c: u32,
        s: [Chars; n],
    }

    let mut vars = [a, b, c];

    let id = |x| match x {
        'A' => 0,
        'B' => 1,
        'C' => 2,
        _ => unreachable!(),
    };

    let mut ans = Vec::new();
    for j in 0..n {
        let q = &s[j];
        let i = q.iter().copied().map(id).collect::<Vec<_>>();
        let d = match vars[i[0]].cmp(&vars[i[1]]) {
            Ordering::Less => true,
            Ordering::Equal => {
                if vars[i[0]] == 0 {
                    println!("No");
                    return;
                }
                (j + 1 != n) && (s[j + 1].iter().find(|&&x| x == q[0]).is_some())
            }
            Ordering::Greater => false,
        };
        if d {
            vars[i[0]] += 1;
            vars[i[1]] -= 1;
            ans.push(q[0]);
        } else {
            vars[i[0]] -= 1;
            vars[i[1]] += 1;
            ans.push(q[1]);
        }
    }
    println!("Yes");
    for ans in ans {
        println!("{}", ans);
    }
}


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

const double pi  = 2 * acos(0.0);
const double eps = 1e-8;

#define REP(i,a,b) for(int i=(a); i<(b);++i)
#define rep(i,n) REP(i,0,n)
#define INF (1<<29)
#define INFLL (1L<<29)

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;

typedef int Cost;
struct Edge {
  int src, dst; Cost cost;
  Edge(int s, int d, Cost c) : src(s), dst(d), cost(c) {}
};
typedef vector<Edge>  Edges;
typedef vector<Edges> Graph;
typedef vector<Cost>  Array;
typedef vector<Array> Matrix;

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

int main(void) {
  ios_base::sync_with_stdio(false); cin.tie(0);
  int N, x;
  cin >> N >> x;
  vector<int> a(N);
  rep(i, N) cin >> a[i];

  long long cnt = 0;
  REP(i, 1, N) {
    if (a[i] == 0) continue;
    if (a[i] + a[i-1] <= x) continue;
    int over = a[i] + a[i-1] - x;
    cnt += over;
    if (a[i] >= over) {
      a[i] -= over;
    } else {
      a[i-1] -= (over - a[i]);
      a[i] = 0;
    }
  }
  cout << cnt << endl;
  return 0;
}


Measured memory_bytes: 640
N, = list(map(int, input().split()))
abc = []
for i in range(N):
  abc.append(list(map(int, input().split())))
dp = [[0]*3 for i in range(N)]
dp[0] = abc[0]
for i in range(1,N):
  for j in range(3):
    dp[i][j] = max([dp[i-1][k] for k in set([0,1,2])-set([j])])+abc[i][j]
print(max(dp[-1]))

Measured memory_bytes: 47280
package main

import (
	"bufio"
	"flag"
	"fmt"
	"io/ioutil"
	"log"
	"os"
	"strconv"
	"strings"
)

func (p *problem) solve() {

	// 100回割り切れる
	// 0回, 100番目
	// 1回, 100番目
	// 2回, 100番目

	in := p.NextInts()
	D, N := in[0], in[1]

	switch {
	case D == 0 && N == 100:
		p.Printf("101")
		return
	case D == 1 && N == 100:
		p.Printf("10100")
		return
	case D == 2 && N == 100:
		p.Printf("1010000")
		return
	}

	p.Printf("%v", N)
	if D == 0 {
		return
	}
	for i := 0; i < D; i++ {
		p.Printf("00")
	}
}

var (
	debug  bool
	output string
)

func main() {
	flag.BoolVar(&debug, "debug", false, "Print debug logs")
	flag.BoolVar(&debug, "d", false, "Print debug logs")
	flag.StringVar(&output, "output", "stdout", "Specify output target (Default: stdout)")
	flag.StringVar(&output, "o", "stdout", "Specify output target (Default: stdout)")
	flag.Parse()

	if debug {
		out := os.Stdout
		if output != "stdout" {
			logfile, err := os.OpenFile(output, os.O_CREATE|os.O_WRONLY, 0666)
			if err != nil {
				panic(err)
			}
			defer logfile.Close()
			out = logfile
		}
		log.SetOutput(out)
	} else {
		log.SetOutput(ioutil.Discard)
	}

	p := problem{
		in:  bufio.NewReader(os.Stdin),
		out: bufio.NewWriter(os.Stdout),
	}
	p.solve()

	if err := p.out.Flush(); err != nil {
		panic(err)
	}
}

type problem struct {
	in  *bufio.Reader
	out *bufio.Writer
}

func (p *problem) PrintInt(d int) {
	p.Printf("%d\n", d)
}

func (p *problem) Printf(format string, a ...interface{}) {
	if _, err := fmt.Fprintf(p.out, format, a...); err != nil {
		panic(err)
	}
}

func (p *problem) Printfln(format string, a ...interface{}) {
	if _, err := fmt.Fprintf(p.out, fmt.Sprintf("%v\n", format), a...); err != nil {
		panic(err)
	}
}

func (p *problem) NextInt() int {
	return stoi(p.Next())
}

func (p *problem) NextInts() []int {
	line := p.NextSSLine()
	ds := make([]int, len(line))
	for i, s := range line {
		ds[i] = stoi(s)
	}
	return ds
}

func (p *problem) NextSSLine() []string {
	return strings.Split(p.Next(), " ")
}

// Next reads line and return string.
func (p *problem) Next() string {
	var b []byte
	for {
		l, pre, err := p.in.ReadLine()
		if err != nil {
			panic(err)
		}
		b = append(b, l...)
		if !pre {
			break
		}
	}
	return string(b)
}

func stoi(s string) int {
	i, err := strconv.Atoi(s)
	if err != nil {
		fmt.Println(i)
		fmt.Println(err)
	}
	return i
}


Measured memory_bytes: 640
use std::io::*;
use std::str::FromStr;

#[allow(dead_code)]
fn read<T: FromStr>() -> T {
    let stdin = stdin();
    let stdin = stdin.lock();
    let token: String = stdin
        .bytes()
        .map(|c| c.expect("failed to read char") as char)
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect();
    token.parse().ok().expect("failed to parse token")
}

fn main() {
    let n: i32 = read();
    let a: i32 = read();
    println!("{}", n * n - a);
}


Measured memory_bytes: 4352
N, Y = map(int, input().split())

for i in range(Y // 10000 + 1):
    for j in range((Y - i*10000) // 5000 + 1):
        remain_money = (Y - i*10000 - j*5000)
        k = remain_money // 1000
        if remain_money % 1000 == 0 and i+j+k == N:
            print(i, j, k)
            exit()
        else:
            pass
                
print(-1, -1, -1)


Measured memory_bytes: 3060
#include <stdio.h>

int main(void){
	int i, start, end, divisor;
	int num = 0;
	
	scanf("%d %d %d", &start, &end, &divisor);
	
	for(i = start; i <= end; i++){
		if(divisor % i == 0){
			num++;
		}
	}
	
	printf("%d\n", num);
	
	return 0;
}

Measured memory_bytes: 596
#include <stdio.h>

int main(void){
	int a,b;
	char op;
	while(1){
		scanf("%d %c %d",&a,&op,&b);
		if(op=='?')break;
		if(op=='+'){
			printf("%d\n",a+b);
		}
		else if(op=='-'){
			printf("%d\n",a-b);
		}
		else if(op=='*'){
			printf("%d\n",a*b);
		}
		else if(op=='/'){
			printf("%d\n",a/b);
		}
	}
	return 0;
}

Measured memory_bytes: 600
s=raw_input()
result=len(s)
for i in range(0, 26):
	cur_result=0
	ch=chr(ord("a")+i)
	s+=ch
	cur=-1
	while True:
		next=s.find(ch, cur+1)
		if next==-1:
			break
		cur_result=max(cur_result, next-cur-1)
		cur=next
	s=s[:-1]
	result=min(result, cur_result)
print result

Measured memory_bytes: 2568
fun main(args: Array<String>) {
    val (n, a, b, c, d) = readLine()!!.split(' ').map(String::toInt)
    val s = readLine()!!.take(Math.max(c, d))
    var ans = s.drop(a - 1).split('.').all { it.length <= 1 }
    if (c > d) {
        val po = s.take(d).drop(b - 1).split('#').any { it.length >= 3 }
        ans = ans && (po || (s[b - 2] == '.' && s[b] == '.') || (s[d - 2] == '.') && s[d] == '.')
    }

    if (ans)
        println("Yes")
    else
        println("No")
}


Measured memory_bytes: 50228
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<(n);i++)
#define all(x) (x).begin(),(x).end()
#define ll long long
int main(){
  int N;
  cin>>N;
  vector<ll> A(N);
  rep(i,N) cin>>A[i];
  sort(all(A));
  ll ans=1,c=0,x=1;
  rep(i,N){
    if(x&&A[N-1-i]==A[N-2-i]){
      ans*=A[N-1-i];
      c++;
      x=0;
    }else x=1;
    if(c==2) break;
  }
  cout<<(c==2?ans:0)<<endl;
}

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

int main() {
  int N, M;
  cin >> N >> M;
  
  // 都市ごとの道路本数を格納する配列
  vector<int> douro_count(N);
  
  // 標準入力から読み込んで、各都市の道路数をカウント
  for (int i = 0; i < M; i++) {
    int toshi1, toshi2;
    cin >> toshi1 >> toshi2;
    // 道路数の加算
    douro_count.at(toshi1 -1) += 1; // 添字が1ずれている
    douro_count.at(toshi2 -1) += 1;
  }
  // 結果を出力
  for (int i = 0; i < N; i++) {
    cout << douro_count.at(i) << endl;
  }
return 0;
}

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

using namespace std;
typedef long long ll;
#define rep(i, n) for (ll i = 0; i < (ll)(n); ++i)
#define erep(i, n) for (ll i = 0; i <= (ll)(n); ++i)
#define FOR(i,a,b) for (ll i = (a); i < (ll)(b); ++i)
#define EFOR(i,a,b) for (ll i = (a); i <= (ll)(b); ++i)
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } }


int dp[100010];

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

    dp[0] = 0;
    EFOR(i, 1, 100000) {
        dp[i] = INT_MAX;
        int power = 1;
        while(power <= i) {
            dp[i] = min(dp[i], dp[i-power]+1);
            power *= 6;
        }
        power = 1;
        while(power <= i) {
            dp[i] = min(dp[i], dp[i-power]+1);
            power *= 9;
        }
    }

    cout << dp[n] << endl;

    return 0;
}


Measured memory_bytes: 640
import java.util.*;

class Main {
  public static void main (String[] args) {
    Scanner scanner = new Scanner(System.in);
    String  out = "";
    while (scanner.hasNext()) {
      int n = scanner.nextInt();
      if (n == 0) {
        break;
      }
      List<Integer> m = new ArrayList<Integer>();
      for (int ii = 0; ii < n; ii++) {
        m.add(scanner.nextInt());
      }
      Collections.sort(m);
      double t = 0;
      for (int ii = 0; ii < m.size() - 1; ii++) {
        t += m.get(ii) * (n - (ii + 1));
      }
      out += String.format("%.0f", t) + "\n";
    }
    System.out.print(out);
  }
}

Measured memory_bytes: 53600
#include "bits/stdc++.h"
#define esc(ret) cout << ret << endl,quick_exit(0)
#define fcout(d) cout << fixed << setprecision(d)
#define repU(i,s,t) for(int i = (int)(s); i <= (int)(t); ++i)
#define repD(i,t,s) for(int i = (int)(t); i >= (int)(s); --i)
#define rep(i,n) repU(i,0,n - 1)
#define rep1(i,n) repU(i,1,n)
#define all(v) begin(v),end(v)
#define vct vector
#define prique priority_queue
#define l_bnd lower_bound
#define u_bnd upper_bound
#define puf push_front
#define pub push_back
#define pof pop_front
#define pob pop_back
#define mkp make_pair
#define mkt make_tuple
#define fir first
#define sec second
#define qceil(n,d) ((n) > 0 ? ((n) - 1) / (d) + 1 : (n) / (d))
#define parity(a,b) (a & 1 == b & 1)

using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef double db;
typedef pair<int,int> pii;

const pii dir[] = { {1,0},{0,1},{-1,0},{0,-1},{1,1},{-1,1},{-1,-1},{1,-1} };
const int inf32 = (1 << 30) - 1;
const ll inf64 = (1LL << 62) - 1;
const int mod = 1e9 + 7;

template<class Abel> struct WeightedUF {
	vector<int> par;
	vector<int> size;
	vector<Abel> diff_weight;

	WeightedUF(int n) {
		init(n);
	}

	void init(int n) {
		par.resize(n);
		size.assign(n,1);
		diff_weight.resize(n);
		for (int i = 0; i < n; ++i) par[i] = i; 
	}

	int find(int x) {
		if (par[x] == x) {
			return x;
		} else { 
			int r = find(par[x]);
			diff_weight[x] += diff_weight[par[x]];
			return par[x] = r;
		}
	}
	
	int scale(int x) {
		return size[find(x)];
	}

	Abel weight(int x) {
		find(x);
		return diff_weight[x];
	} 

	Abel diff(int x, int y) {
		return weight(y) - weight(x);
	} 

	bool is_same(int x, int y) {
		return find(x) == find(y);
	}

	bool unite(int x, int y, Abel w = 0) {
		w += weight(x);
		w -= weight(y);
		x = find(x);
		y = find(y);
		if (x == y) return 0;
		if (size[x] < size[y]) {
			swap(x,y);
			w = -w;
		}
		size[x] += size[y];
		par[y] = x;
		diff_weight[y] = w;
		return 1;
	}
};
 
int N,M;

int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	
	cin >> N >> M;
	ll s[100010];
	s[0] = 0;
	rep(i,N){
		int a; cin >> a;
		s[i + 1] = (s[i] + a) % M;
	}
	sort(s,s + N + 1);
	ll l = s[0],cnt = 0;
	ll ans = 0;
	rep1(i,N){
		if(s[i] == l) cnt++;
		else{
			ans += cnt * (cnt + 1) / 2;
			cnt = 0;
		}
		l = s[i];
	}
	cout << ans + cnt * (cnt + 1) / 2 << endl;
}



Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
typedef long long LL;
LL n,k;
const LL mof=1e9+7;
LL p=mof;
const LL maxn=200007;
inline LL pow_mod(LL a,LL k,LL mo)
{
    LL ans=1;
    while(k)
    {
        if(k%2) ans=ans*a%mo;
        a=a*a%mo;
        k>>=1;
    }
    return ans%mo;
}
LL jc[maxn+7];
inline LL inv(LL x)
{
    return pow_mod(x,mof-2,mof);
}
LL Inv[maxn+7];
LL C(LL N,LL k)
{
    if(k>N||k<0)return 0;
    if(k==0||k==N)return 1;
    LL ans=1;
    ans=ans*jc[N]*Inv[k]%mof*Inv[N-k]%mof;
    return ans;
}
void init()
{
    jc[1]=jc[0]=1;
    for(LL i=2; i<=maxn; ++i) jc[i]=jc[i-1]*i%mof;
    for(int i=0; i<=maxn; ++i) Inv[i]=inv(jc[i]);
}
const long long MOD = 1000000007;

void solve(long long H, long long W, long long A, long long B){
    LL ans = 0;
    LL h = H-A;
    for(LL w=B+1;w<=W;++w)
    {
        ans += C(h+w-2,h-1) * C(H-h+W-w-1,H-h-1);
        ans %= mof;
    }
    cout<<ans<<endl;
}

int main(){
    init();
    long long H;
    scanf("%lld",&H);
    long long W;
    scanf("%lld",&W);
    long long A;
    scanf("%lld",&A);
    long long B;
    scanf("%lld",&B);
    solve(H, W, A, B);
    return 0;
}


Measured memory_bytes: 3328
<?php

while (($line = trim(fgets(STDIN))) !== '') {
    if ($line === '0') {
        break;
    }

    sscanf($line, '%d', $n);
    $line = trim(fgets(STDIN));
    $arr = explode(' ', $line);
    $cnt = count($arr);
    $sum = array_sum($arr);
    $m = $sum / $cnt;

    $a2 = 0;
    foreach ($arr as $s) {
        $a2 += pow($s - $m, 2);
    }

    $a = sqrt($a2 / $cnt);
    printf("%f\n", $a);
}

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

using namespace std;

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

  int N,M; cin>>N>>M;

  vector<int> parent(N);
  iota(parent.begin(), parent.end(), 0);
  auto root = [f=[&](auto g, int n) {
    if (parent[n] == n)
      return n;
    return parent[n] = g(g, parent[n]);
  }] (int n) {
    return f(f, n);
  };

  for (int i = 0; i < M; i++) {
    int x,y,z;cin>>x>>y>>z;
    x--;y--;
    auto rl = root(x);
    auto rr = root(y);
    if (rl != rr) {
      parent[rl] = rr;
    }
  }

  std::set<int> graphs;
  for (int i = 0; i < N; i++) {
    graphs.insert(root(i));
  }
  cout << graphs.size() << endl;

  return 0;
}


Measured memory_bytes: 5376