akhauriyash/Code-Regression huggingface dataset:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Prob0001
{
    class Program
    {
        const char splitBy = ' ';

        static void Main(string[] args)
        {
            string line;
            List<int> mountains = new List<int>();
            while (!string.IsNullOrEmpty(line = System.Console.ReadLine()))
                mountains.Add(Convert.ToInt32(line));

            var res = mountains.OrderByDescending(x => x).ToList();
            for (int i = 0; i < 3; i++)
                Console.WriteLine(res[i]);
        }


    }
}

Measured memory_bytes: 6388
import sys
def MI(): return map(int,sys.stdin.readline().rstrip().split())


N,K = MI()
K += 1
k = K.bit_length()

AB = []

for _ in range(N):
    a,b = MI()
    if a >= K:
        continue
    else:
        AB.append(([(a >> i) & 1 for i in range(k-1,-1,-1)],b))

N = len(AB)
K_bit = [(K >> i) & 1 for i in range(k-1,-1,-1)]

ANS = [0]*k  # 

for i in range(N):
    a,b = AB[i]
    for j in range(k):
        if K_bit[j] == 1:
            if a[j] == 0:
                ANS[j] += b
        else:
            if a[j] == 1:
                break

print(max(ANS))


Measured memory_bytes: 119320
#include<iostream>
#include<vector>
#include<algorithm>
#include<cstring>
#include<cstdio>
#include<cmath>
#include<cstdlib>
#include<ctime>
#include<queue>
#include<set>
#include<map>
#include<stack>
#include<bitset>
using namespace std;
typedef long long LL;
LL gi() {
	LL w=0;bool q=1;char c=getchar();
	while ((c<'0'||c>'9') && c!='-') c=getchar();
	if (c=='-') q=0,c=getchar();
	while (c>='0'&&c <= '9') w=w*10+c-'0',c=getchar();
	return q? w:-w;
}
LL fib[100];
vector<pair<LL,LL>>v[100];
#define x first
#define y second
int main()
{
	int ans,i,Q=gi();LL x,y;
	
	fib[0]=fib[1]=1;
	for (i=2;(fib[i]=fib[i-1]+fib[i-2])<=1e18;i++);

	v[1].push_back(make_pair(1,2));
	v[1].push_back(make_pair(1,3));

	for (i=1;i<=90;i++)
		for (auto t:v[i-1])
			for (x=t.y,y=t.x+t.y;y<=fib[i+2]+fib[i-1];y+=t.y)
				v[i].push_back(make_pair(x,y));

	const int mod=1e9+7;
	
	while (Q--) {
		x=gi(),y=gi();
		if (x>y) swap(x,y);
		if (x==1) printf("1 %d\n",y%mod);
		else if (y==2) puts("1 4");
		else {
			for (i=0;fib[i]<=x&&fib[i+1]<=y;i++);i--;
			printf("%d ",i);
			ans=0;
			for (auto t:v[i-1]) {
				if (t.y<=x)
					ans=(ans+(y-t.x)/t.y)%mod;
				if (t.y<=y)
					ans=(ans+(x-t.x)/t.y)%mod;
			}
			printf("%d\n",ans);
		}
	}
	
	return 0;
}


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

int top, S[1000];
void push(int);
int pop();

int main(){
  int x, y;
  char s[100];

  top = 0;

  while(scanf("%s", s) != EOF){
    if(s[0] ==  '+'){
      x = pop();
      y = pop();
      push(x + y);
    }else if(s[0] == '-'){
      y = pop();
      x = pop();
      push(x - y);
    }else if(s[0] == '*'){
      x = pop();
      y = pop();
      push(x * y);
    }else{
      push(atoi(s));
    }
  }
  printf("%d\n", pop());
  
  return 0;
}

void push(int x){
  top++;
  S[top] = x;
}

int pop()
{
  return S[top--];
}

Measured memory_bytes: 548
import java.util.Scanner;

//Card Game
public class Main {

	int[] g, j;
	boolean[] u;
	int res;

	void dfs(int k, int pa, int pb) {
		int p, q;
		if (k == 9) {
			if (pb < pa) {
				res++;
			}
			return;
		}
		for (int i = 0; i < 9; i++) {
			if (!u[i]) {
				u[i] = true;
				if (j[k] < g[i]) {
					p = g[i] + j[k];
				} else {
					p = 0;
				}
				if (j[k] < g[i]) {
					q = 0;
				} else {
					q = g[i] + j[k];
				}
				dfs(k + 1, pa + p, pb + q);
				u[i] = false;
			}
		}
	}

	void run() {
		Scanner sc = new Scanner(System.in);
		int T = sc.nextInt();
		while (T-- != 0) {
			g = new int[9];
			j = new int[9];
			u = new boolean[9];
			for (int i = 0; i < 9; i++)
				g[i] = sc.nextInt();
			for (int i = 0; i < 9; i++)
				j[i] = sc.nextInt();
			res = 0;
			dfs(0, 0, 0);
			double x = res * 1.0 / 362880;
			System.out.printf("%.5f %.5f\n", x, 1 - x);
		}
	}

	public static void main(String[] args) {
		new Main().run();
	}
}

Measured memory_bytes: 20884
package main

import (
	"bufio"
	"fmt"
	"math"
	"os"
	"sort"
	"strconv"
	"strings"
)

var sc = bufio.NewReaderSize(os.Stdin, 1024*1024*1)

func main() {
	list := getStdinIntArr()
	p := getStdinIntArr()
	X := list[0]
	N := list[1]

	sort.Ints(p)

	find := false
	index := 0
	for idx, val := range p {
		if val == X {
			find = true
			index = idx
			break
		}
	}
	if !find {
		fmt.Printf("%d\n", X)
		return
	}

	prev := 0
	left := -math.MaxInt16
	right := math.MaxInt16

	prev = p[index]
	find = false
	for i := index - 1; i >= 0; i-- {
		if prev-1 != p[i] {
			left = prev - 1
			find = true
			break
		}
		prev = p[i]
	}
	if !find {
		left = p[0] - 1
	}

	prev = p[index]
	find = false
	for i := index + 1; i < N; i++ {
		if prev+1 != p[i] {
			right = prev + 1
			find = true
			break
		}
		prev = p[i]
	}
	if !find {
		right = p[N-1] + 1
	}

	leftAbs := X - left
	rightAbs := right - X
	if leftAbs < 0 {
		leftAbs = -leftAbs
	}
	if rightAbs < 0 {
		rightAbs = -rightAbs
	}

	if leftAbs == rightAbs {
		fmt.Printf("%d\n", left)
	} else if leftAbs < rightAbs {
		fmt.Printf("%d\n", left)
	} else {
		fmt.Printf("%d\n", right)
	}
}

func getStdin() string {
	return readLine()
}
func getStdinInt() int {
	str := getStdin()
	rtn, _ := strconv.Atoi(str)
	return rtn
}
func getStdinInt64() int64 {
	str := getStdin()
	rtn, _ := strconv.ParseInt(str, 10, 64)
	return rtn
}
func getStdinIntArr() []int {
	str := getStdin()
	list := strings.Split(str, " ")
	rtn := make([]int, len(list))
	for idx, val := range list {
		rtn[idx], _ = strconv.Atoi(val)
	}
	return rtn
}

func getStdinArr() []string {
	str := getStdin()
	list := strings.Split(str, " ")
	return list
}

func getStdinIntArr64() []int64 {
	str := getStdin()
	list := strings.Split(str, " ")
	rtn := make([]int64, len(list))
	for idx, val := range list {
		rtn[idx], _ = strconv.ParseInt(val, 10, 64)
	}
	return rtn
}

func readLine() string {
	buf := make([]byte, 0, 0)
	for {
		l, p, e := sc.ReadLine()
		if e != nil {
			panic(e)
		}
		buf = append(buf, l...)
		if !p {
			break
		}
	}
	return string(buf)
}


Measured memory_bytes: 1788
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i = 0; i < (int)(n); i++)
#define repr(i,n) for(int i = (int)(n); i >= 0; i--)
#define all(v) v.begin(),v.end()
typedef long long ll;

int main(){
    double N,M;
    cin >> N >> M;
    vector<double> vec(N);
    rep(i,N){
        cin >> vec[i];
    }
    sort(all(vec));
    double sum = 0;
    rep(i,N){
        sum += vec[i];
    }
    if (vec[N - M] >= sum /(4 * M)) cout << "Yes" << endl;
    else cout << "No" << endl;
}



Measured memory_bytes: 256
import java.util.Scanner

object Main {
  def main(args: Array[String]): Unit = {
    val sc: Scanner = new Scanner(System.in)
    val s: String = sc.nextLine()
    val t: String = sc.nextLine()

    if (s.sorted < t.sorted.reverse) println("Yes")
    else println("No")
  }
}


Measured memory_bytes: 25552
#include <iostream>
#include <algorithm>
#include <vector>
#include <set>
#include <queue>
#include <map>
#include <string.h>
#include <math.h>
#include <stdio.h>
#include <deque>
//#include "D:\C++\test_lib_projects\testlib.h"
using namespace std;
#define ll long long
#define pii pair<int,int>

bool debug=true;
/*
   Write In New Computer
    By XiaoGeNintendo
	     gwq2017
	Type:
*/

/*
void fo(int id){
	freopen((toString(id)+".txt").c_str(),"w",stdout);
}
*/
map<int,int> mp;
int main(int argc,char* argv[]){
	int n;
	cin>>n;
	for(int i=0;i<n;i++){
		int x;
		cin>>x;
		mp[x]++;
	}
	
	int ans=0;
	
	for(map<int,int>::iterator it=mp.begin();it!=mp.end();it++){
		int ans1=it->first,ans2=it->second;
		if(ans2>ans1){
			ans+=ans2-ans1;
		}
		if(ans2<ans1){
			ans+=ans2;
		}
	}
	
	cout<<ans;
	return 0;
}


Measured memory_bytes: 4736
#include "bits/stdc++.h"
using namespace std;
using     ll=long long;
using    vll=vector<   ll>;
using   vvll=vector<  vll>;
using  vvvll=vector< vvll>;
using vvvvll=vector<vvvll>;
constexpr ll INF = 1LL << 60;
struct Fast{ Fast(){ cin.tie(0); ios::sync_with_stdio(false); cout<<fixed<<setprecision(numeric_limits<double>::max_digits10); } } fast;
#define REPS(i, S, E) for (ll i = (S); i <= (E); i++)
#define REP(i, N) REPS(i, 0, (N)-1)
#define DEPS(i, S, E) for (ll i = (E); i >= (S); i--)
#define DEP(i, N) DEPS(i, 0, (N)-1)
#define rep(i, S, E)  for (ll i = (S); i <= (E); i++)
#define dep(i, E, S)  for (ll i = (E); i >= (S); i--)
#define each(e, v) for (auto&& e : v)
#define ALL(v) (v).begin(), (v).end()
#define RALL(v) (v).rbegin(), (v).rend()
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; }
template<class T> inline T MaxE(vector<T>&v,ll S,ll E){ T m=v[S]; rep(i,S,E)chmax(m,v[i]); return m; }
template<class T> inline T MinE(vector<T>&v,ll S,ll E){ T m=v[S]; rep(i,S,E)chmin(m,v[i]); return m; }
template<class T> inline T MaxE(vector<T> &v) { return MaxE(v,0,(ll)v.size()-1); }
template<class T> inline T MinE(vector<T> &v) { return MinE(v,0,(ll)v.size()-1); }
template<class T> inline T Sum(vector<T> &v,ll S,ll E){ T s=T(); rep(i,S,E)s+=v[i]; return s; }
template<class T> inline T Sum(vector<T> &v) { return Sum(v,0,v.size()-1); }
template<class T> inline ll sz(T &v){ return (ll)v.size(); }
inline ll CEIL(ll a,ll b){ return (a<0) ? -(-a/b) : (a+b-1)/b; }
inline ll FLOOR(ll a,ll b){ return -CEIL(-a,b); }

#if 1
#include <atcoder/all>
#endif
using namespace atcoder;


void solve()
{
	ll n,d;  cin >> n >> d;
	vector<pair<ll,ll>> xy(n);
	rep(i,0,n-1){ ll x; ll y; cin>>x>>y; xy[i]={x,y}; }

	two_sat ts(n);

	rep(i,0,n-1){
		rep(j,i+1,n-1){
			ll xi,yi;  tie(xi,yi) = xy[i];
			ll xj,yj;  tie(xj,yj) = xy[j];

			if (abs(xi-xj)<d){
				ts.add_clause(i,false,j,false);
			}
			if (abs(yi-yj)<d){
				ts.add_clause(i,true,j,true);
			}
			if (abs(yi-xj)<d){
				ts.add_clause(i,true,j,false);
			}
			if (abs(xi-yj)<d){
				ts.add_clause(i,false,j,true);
			}
		}
	}
	if (!ts.satisfiable()){
		cout << "No" << '\n';return;
	}
	cout << "Yes" << '\n';
	auto ans=ts.answer();
	rep(i,0,n-1){
		ll xi,yi;  tie(xi,yi) = xy[i];
		if (ans[i]){
			cout << xi << '\n';
		}
		else{
			cout << yi << '\n';
		}
	}
}


int main(){
#if 1
	solve();
#else
	ll t;  cin >> t;
	rep(i, 0, t-1){
		solve();
	}
#endif
	return 0;
}


Measured memory_bytes: 3732
#include<bits/stdc++.h>
#define lli long long int
#define ulli unsigned long long int
#pragma GCC target ("sse4.2")
using namespace std;
#define fast ios_base::sync_with_stdio(0);cin.tie(NULL);cout.tie(NULL)
#define time cout<<"\nTime Elapsed: " << 1.0*clock() / CLOCKS_PER_SEC << " sec\n";
lli maxSubArraySum(lli a[], lli size)
{
    lli max_so_far = INT_MIN, max_ending_here = 0;

    for (lli i = 0; i < size; i++)
    {
        max_ending_here = max_ending_here + a[i];
        if (max_so_far < max_ending_here)
            max_so_far = max_ending_here;

        if (max_ending_here < 0)
            max_ending_here = 0;
    }
    return max_so_far;
}
int main()
{


    fast;
    lli n;
    cin>>n;
    lli a[n][2];
    double x=0,y=0;
    for(lli i=0;i<n;i++)
    {
        cin>>a[i][0]>>a[i][1];
        x+=a[i][0],y+=a[i][1];
    }
    double X=x/n,Y=y/n;
    //cout<<X<<" "<<Y<<"\n";
    double m=0.999;
    double p=0.01;
    lli f;
    double dist=0;
    for(lli i=1;i<=8000000;i++)
    {
        f=0;
        dist=((X-a[0][0])*(X-a[0][0])+(Y-a[0][1])*(Y-a[0][1]));
        for(lli j=1;j<n;j++)
        {
            if(((X-a[j][0])*(X-a[j][0])+(Y-a[j][1])*(Y-a[j][1]))>dist)
            {
                dist=((X-a[j][0])*(X-a[j][0])+(Y-a[j][1])*(Y-a[j][1]));
                f=j;
            }
        }
        X+=(a[f][0]-X)*p;
        Y+=(a[f][1]-Y)*p;
        p*=m;
    }

    cout<<fixed<<setprecision(9)<<sqrt((X-a[f][0])*(X-a[f][0])+(Y-a[f][1])*(Y-a[f][1]));


    return 0;

}


Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<algorithm>
using namespace std;

typedef long long LL;

const int N=100005;

int n;
LL a[N];

int main()
{
	scanf("%d",&n);
	for (int i=1;i<=n;i++) scanf("%lld",&a[i]);
	LL l=2,r=2;
	for (int i=n;i>=1;i--)
	{
		LL p=((l-1)/a[i]+1)*a[i],q=r/a[i]*a[i];
		if (p<l||p>r) {puts("-1");return 0;}
		l=p;r=q+a[i]-1;
	}
	printf("%lld %lld",l,r);
	return 0;
}

Measured memory_bytes: 1024
#include<iostream>
#include<algorithm>
using namespace std ;
int main()
{
	int a,b,c;
	cin >> a >> b >> c ;
	int t;
	if(b>a) {t=b;b=a;a=t;}
	if(c>a) {t=c;c=a;a=t;}
	int s=a*10+b+c;
	cout << s ;
	return 0;
}

Measured memory_bytes: 888
# coding: utf-8
# Your code here!
# s=input()
#https://atcoder.jp/contests/abc158/tasks/abc158_e p=2019 copype
P=2019

# N,P=map(int,input().split());
S,a,i,j,c=input(),0,0,1,[1]+[0]*P
if 10%P:
	for v in S[::-1]:i,j=(i+int(v)*j)%P,j*10%P;a+=c[i];c[i]+=1
else:
	for v in S:
		i+=1
		if int(v)%P<1:a+=i
print(a)

#honto???

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

typedef long long ll;
const int N = 1e5 + 100, MOD = 1000 * 1000 * 1000 + 7;

int sum(int a, int b) {
	a += b;
	if(a >= MOD)
		a -= MOD;
	return a;
}

int n, m, a, dp[N];
bool mark[N];

int main() {
	ios::sync_with_stdio(false), cin.tie(0);
	cin >> n >> m;
	while(m--) {
		cin >> a;
		mark[a] = true;
	}
	dp[0] = 1;
	dp[1] = (mark[1]? 0: dp[0]);
	for (int i = 2; i <= n; i++) {
		if(mark[i - 1] == false)
			dp[i] = dp[i - 1];
		if(mark[i - 2] == false)
			dp[i] = sum(dp[i], dp[i - 2]);
	}
	cout << dp[n];
	return 0;
}

Measured memory_bytes: 768
#include<iostream>
#include<cmath>
#include<algorithm>
#include<iomanip>
#include<string>
#include<vector>
#include<cstdio>
#include<cstring>
#include<map>
#include<set>
#include<fstream>
#include<sstream>
#include<queue>
#include<iterator>
#include<stack>
using namespace std;
long long gcd(long long a,long long b){
	return b==0?a:gcd(b,a%b);
}
int main(){
	int n;
	long long ans;
	cin>>n;
	cin>>ans;
	for(int i=1;i<n;i++){
		long long x;
		cin>>x;
		x/=gcd(ans,x);
		ans*=x;
	}
	cout<<ans<<endl;




  return 0;
}


Measured memory_bytes: 256
#include<stdio.h>
#define N 100
#define M 1000
int main(void){
  int i,n,j,jj,flag;
  char x[N][M],y[N][M];
  int xdigi,ydigi,ldigi;
  char sum[M];

  scanf("%d",&n);
  for(i=0;i<n;i++)
    scanf("%s%s",x[i],y[i]);

  for(i=0;i<n;i++){
    for(j=0;;j++)
      if(x[i][j]==0){
        xdigi=j;
        break;
      }
    for(j=0;;j++)
      if(y[i][j]==0){
        ydigi=j;
        break;
      }

    if(xdigi>=ydigi)
      ldigi=xdigi;
    else
      ldigi=ydigi;

    if(ldigi>80){
      printf("overflow\n");
    }else{

      for(j=0;j<ldigi+2;j++)
        sum[j]=0;

      for(j=xdigi-1,jj=0;j>=0;j--,jj++)
        sum[jj]+=x[i][j]-'0';
      for(j=ydigi-1,jj=0;j>=0;j--,jj++)
        sum[jj]+=y[i][j]-'0';

      for(j=0;j<ldigi;j++)
        if(sum[j]>9){
          if(j==ldigi-1)
            ldigi++;
          sum[j]-=10;
          sum[j+1]++;
        }

      if(ldigi>80){
        printf("overflow\n");
      }else{
        for(j=ldigi-1;j>=0;j--){
          printf("%c",sum[j]+'0');
        }
        printf("\n");
      }
    }
  }
  return 0;
}

Measured memory_bytes: 0
#include <iostream>

using namespace std;

int Days(string day){
    string d[7] = {"SUN", "MON", "TUE", "WED", "THU", "FRI", "SAT"};
    int counter = 0;
    int size = *(&d + 1) - d;
        bool flag = false;
        for (int i = 0;i < size; i++) {
            if (day == d[i]) {
                flag = true;
            }
            if (flag)
                counter++;
        }
        return counter;
}
int main()
{
    string n;
    cin>>n;
    cout<<Days(n)<<endl;
    return 0;
}


Measured memory_bytes: 256
import Control.Applicative( (<$>))
import Data.List( sort, group, transpose)
import Control.Monad( replicateM)

main = do   
    n_ <- readLn::IO Int
    ss_ <- replicateM n_ getLine
    let
	smallLetters = ['a'..'z']

	processedSS = (smallLetters++) <$> ss_

	letterDistribution = countLetter <$> processedSS

	countLetter s = count' <$> (group . sort $ s)
	  where
	    count' = (subtract 1) . length

	result = minimum <$> transpose letterDistribution

	lender _ [] = []
	lender c (n:ns) = (replicate n c)++(lender (succ c) ns)

    putStr $ lender 'a' result

Measured memory_bytes: 1148
#include <stdio.h>

int main() {
  int mahojin[15][15];
  int px, py;
  int n;
  int i, j;
  while(scanf("%d", &n) != EOF) {
    for(i = 0; i < 15; i++)
      for(j = 0; j < 15; j++)
	mahojin[i][j] = 0;

    px = py = n/2;
    py += 1;
    mahojin[py][px] = 1;
    px += 1;
    py += 1;
    if(px >= n) px = 0;
    if(py >= n) py = 0;
    for(i = 2; i <= n*n; i++) {
      if(mahojin[py][px] == 0) {
	mahojin[py][px] = i;
	px += 1;
	py += 1;
	if(px >= n) px = 0;
	if(py >= n) py = 0;
      } else {
	px += -1;
	py += 1;
	if(px < 0) px = n-1;
	if(py >= n) py = 0;
	i--;
      }
    }

    for(i = 0; i < n; i++) {
      for(j = 0; j < n; j++) {
	printf("%4d", mahojin[i][j]);
      }
      printf("\n");
    }
  }
  return 0;
}

Measured memory_bytes: 0
#include <stdio.h>
#include <string.h>
int main(void)
{
    int i, a = 0;
    char test[4];
    scanf("%s", test);
    for (i = 0; i < 4; i++)
    {
    	if( test[i] == 'o')
    	a += 1;
    }
    if (a == 3)
    printf("1000\n");
    else if (a == 2)
    printf("900\n");
    else if (a == 1)
    printf("800\n");
    else 
    printf("700\n");
}

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

#define fi first
#define se second
#define repl(i,a,b) for(int i=(int)(a);i<(int)(b);i++)
#define repr(i,a,b) for(int i=(int)(a-1);i>=b;i--)
#define rep(i,n) repl(i,0,n)
#define each(itr,v) for(auto itr:v)
#define pb(s) push_back(s)
#define all(x) (x).begin(),(x).end()
#define dbg(x) cout << #x" = " << x << endl
#define maxch(x,y) x=max(x,y)
#define minch(x,y) x=min(x,y)
#define uni(x) x.erase(unique(all(x)),x.end())
#define exist(x,y) (find(all(x),y)!=x.end())
#define bcnt(x) bitset<32>(x).count()

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> P;

#define INF INT_MAX/3

int main(){
    cin.sync_with_stdio(false);
    int n;
    cin >> n;
    vector<int> v(n);
    rep(i, n) cin >> v[i];
    sort(all(v));
    uni(v);
    cout << v.size() << endl;
    return 0;
}

Measured memory_bytes: 256
use proconio::input;
use proconio::marker::Chars;
fn main() {
    input!{
        a:usize, b:usize
    };
    let mi = a.min(b);
    let mx = a.max(b);
    if (mx+mi)%2==0 {println!("{}", (mx+mi)/2);} 
    else {println!("IMPOSSIBLE");}
}

Measured memory_bytes: 2108
s = gets.chomp.split("")
t = gets.chomp.split("")
n = s.size
m = t.size
ans = 114514
(n-m+1).times do |i|
    c = 0
    m.times do |j|
        c += 1 if s[i+j] != t[j]
    end
    ans = ans > c ? c : ans
end
puts ans

Measured memory_bytes: 14308
# -*- coding: utf-8 -*-
from collections import Counter
import math
N = int(input())

Ps = list(map(int, input().split()))

V = [[]]
k = 0
tmp = 0

for i,p in enumerate(Ps):
    if i+1 == p:
        #print(tmp, i, p, V)
        if tmp == i:
            V[k].append(p)
            tmp = i+1
        else:
            V.append([])
            k += 1
            V[k].append(p)
            tmp = i+1
ans = 0
for v in V:
    ans += math.ceil(len(v)/2)

print(ans)


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

using namespace std;

int main(){
  int n;
  string s;
  cin >> n >> s;
  int cnt = 0;
  for(int i = 0; i < n-2; i++) {
    if(s.substr(i, 3) == "ABC") cnt++;
  }
  cout << cnt << endl;
  return 0;
}


Measured memory_bytes: 3608
#include <bits/stdc++.h>
#define rep(i,a,b) for(int i = a; i < b; ++i)
#define all(c) c.begin(), c.end()
#define gmax(x,y) x=max(x,y)
#define gmin(x,y) x=min(x,y)
#define gadd(x,y) x=add(x,y)
#define gmul(x,y) x=mul(x,y)
using namespace std;

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

int main(){
	cin.tie(0);
	cout.tie(0);
	ios_base::sync_with_stdio(0);
	string s;
	cin >> s;
	if(s == "ABC")cout << "ARC\n";
	else cout << "ABC\n";
}


Measured memory_bytes: 3620
#include<bits/stdc++.h> 
using namespace std;
using ll=long long;
const ll mod=1e+9;
typedef pair<int,int> P;
#define fi first
#define se second
int main(){
ios::sync_with_stdio(false);
cin.tie(0);
ll n,m;
cin>>n>>m;
ll p=2*m+1;
ll ans=n/p,check=n%p;
if(check!=0)ans++;
cout<<ans<<endl;
}


Measured memory_bytes: 256
#include<bits/stdc++.h> //Ithea Myse Valgulious
namespace chtholly{
typedef long long ll;
#define re0 register int
#define rec register char
#define rel register ll
#define gc getchar
#define pc putchar
#define p32 pc(' ')
#define pl puts("")
/*By Citrus*/
inline int read(){
  int x=0,f=1;char c=gc();
  for (;!isdigit(c);c=gc()) f^=c=='-';
  for (;isdigit(c);c=gc()) x=(x<<3)+(x<<1)+(c^'0');
  return f?x:-x;
  }
template <typename mitsuha>
inline bool read(mitsuha &x){
  x=0;int f=1;char c=gc();
  for (;!isdigit(c)&&~c;c=gc()) f^=c=='-';
  if (!~c) return 0;
  for (;isdigit(c);c=gc()) x=(x<<3)+(x<<1)+(c^'0');
  return x=f?x:-x,1;
  }
template <typename mitsuha>
inline int write(mitsuha x){
  if (!x) return 0&pc(48);
  if (x<0) x=-x,pc('-');
  int bit[20],i,p=0;
  for (;x;x/=10) bit[++p]=x%10;
  for (i=p;i;--i) pc(bit[i]+48);
  return 0;
  }
inline char fuhao(){
  char c=gc();
  for (;isspace(c);c=gc());
  return c;
  }
}using namespace chtholly;
using namespace std;

int main(){
int r=read();
puts(r<1200?"ABC":r<2800?"ARC":"AGC");
}

Measured memory_bytes: 256
N=input()
S=input()
N=int(N)
ans=0
ind=[]
tmp={"R":0,"G":0,"B":0}
for i in S:
    tmp[i]+=1
    ind.append(tmp.copy())
#print(ind)
for i in range(0,N-2):
    for j in range(i+1,N-1):
        if S[i]==S[j]:
            continue
        for k in tmp.keys():
            if k!=S[i] and k!=S[j]:
                col=k
                break
        #print(i,j,col)
        if 2*j-i <N and S[j+j-i]==col:
            ans-=1
        ans+=(ind[-1][col]-ind[j][col])
print(ans)


Measured memory_bytes: 70388
#include <bits/stdc++.h>
#define rep(i, s, n) for (int i = (s); i < (int)(n); i++)
#define all(x) (x).begin(),(x).end()
#define debug(x) cout<<#x<<": "<<x<<endl
using namespace std;
using ll = long long;
const ll MOD = 1e9+7;
const ll LINF = LLONG_MAX;
const int INF = INT_MAX;
const double PI=acos(-1);
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; }

ll n, k;

vector<ll> next_calc(vector<ll> a){
      vector<ll> now(n,0);
      rep(i,0,n){
            now[max(i-a[i],0LL)]++;
            if(i+a[i]+1<=n-1){
                  now[i+a[i]+1]--;
            }
      }
      /* rep(i,0,n){
            cout<<now[i]<<endl;
      }*/
      rep(i,1,n){
            now[i]=now[i-1]+now[i];
      }
      return now;
}

int main(){
      cin>>n>>k;
      vector<ll> a(n,0);
      rep(i,0,n){
            cin>>a[i];
      }
      rep(i,0,k){
            vector<ll> now = next_calc(a);
            bool ok=true;
            rep(i,0,n){
                  if(now[i]!=n) ok=false;
                  a[i]=now[i];
            }
            if(ok) break;
      }

      rep(i,0,n){
            if(i!=n-1) cout<<a[i]<<" ";
            else cout<<a[i]<<endl;
      }
}

Measured memory_bytes: 8012
#include<iostream>
using namespace std;
int main()
{
	int a,b,count;
	for(;cin>>a>>b;)
	{
		a=a+b;
		count=0;
		do
		{
			a=a/10;
			count++;
		}while(a>0);
		cout<<count<<endl;
	}
	return 0;
}

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

using namespace std;

using ll = long long;
using P = pair<int, int>;

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n;
    cin >> n;
    vector<P> v;
    for (int i = 1; i <= n; i++) {
        int a;
        cin >> a;
        v.emplace_back(a, i);
    }
    sort(v.begin(), v.end());

    for (int i = 0; i < n; i++) {
        cout << v[i].second << " \n"[i + 1 == n];
    }
    return 0;
}

Measured memory_bytes: 1780
import sys
a, b, m = [int(i) for i in sys.stdin.readline().split()]
a_ls = [int(i) for i in sys.stdin.readline().split()]
b_ls = [int(i) for i in sys.stdin.readline().split()]
best = min(a_ls) + min(b_ls)
for i in range(m):
    x, y, c = [int(i) for i in sys.stdin.readline().split()]
    x -= 1
    y -= 1
    best = min(best, a_ls[x] + b_ls[y] - c)
print(best)

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

int main(){
  int a;
  cin >> a;
  if(a==1){
    cout << "Yes" << endl;
    return 0;
  }
  int b,prev;
  bool minus=false;
  for(int i=0; i<a; i++){
    cin >> b;
    if(i==0){
      prev = b;
      continue;
    }
    if(b-prev<-1){
      cout << "No" << endl;
      return 0;
    }else if(b-prev==-1){
      if(minus){
        cout << "No" << endl;
        return 0;
      }else{
        minus = true;
      }
    }else if(b-prev==0){
    }else{
      minus = false;
    }
    prev = b;
  }
  cout << "Yes" << endl;
  return 0;
}

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

int main(void)
{
	int A, B, C;
	cin >> A >> B >> C;

	if (A == B && B == C)
		cout << "Yes" << endl;
	else
		cout << "No" << endl;

	return 0;
}


Measured memory_bytes: 384
#code
N,M,X=map(int,input().split())
book=[]
for i in range(N):
    temp=list(map(int,input().split()))
    book.append(temp)
ans=10**9    
for i in range(2**N):
    temp=bin(i)[2:]
    temp='0'*(N-len(temp))+temp
    cost=0
    ls=[0 for j in range(M)]
    for j in range(N):
        if(temp[j]=='1'):
            cost+=book[j][0]
            for k in range(1,M+1):
                ls[k-1]+=book[j][k]
    flag=True
    for j in range(M):
        if(ls[j]<X):
            flag=False
    if(flag):ans=min(ans,cost)
if(ans==10**9):print(-1)
else:print(ans)    

Measured memory_bytes: 68880
#include <iostream>
#include <string>
#include <vector>
using namespace std;
using P = pair<int, int>;

int main()
{
    string S;
    cin >> S;
    int N = S.size();
    vector<P> binding;
    for (int i = 0; i <= N - 2; ++i)
    {
        if (S[i] == 'R' && S[i + 1] == 'L')
        {
            binding.push_back(P(i, i + 1));
            ++i;
        }
    }
    int len = binding.size();
    vector<int> res(N, 0);
    for (int i = 0; i <= len - 2; ++i)
    {
        ++res[binding[i].first], ++res[binding[i].second];
        for (int j = binding[i].second + 1; j < binding[i + 1].first; ++j)
        {
            if (S[j] == 'L')
            {
                int d = j - binding[i].first;
                if (d % 2 == 0)
                {
                    ++res[binding[i].first];
                }
                else
                {
                    ++res[binding[i].second];
                }
            }
            else
            {
                int d = binding[i + 1].second - j;
                if (d % 2 == 0)
                {
                    ++res[binding[i + 1].second];
                }
                else
                {
                    ++res[binding[i + 1].first];
                }
            }
        }
    }
    // Left
    if (binding[0].first != 0)
    {
        for (int i = 0; i < binding[0].first; ++i)
        {
            int d = binding[0].second - i;
            if (d % 2 == 0)
            {
                ++res[binding[0].second];
            }
            else
            {
                ++res[binding[0].first];
            }
            
        }
    }

    // Right
    if (binding[len - 1].second != N - 1)
    {
        ++res[binding[len - 1].first];
        ++res[binding[len - 1].second];
        for (int i = binding[len - 1].second + 1; i <= N - 1; ++i)
        {
            int d = i - binding[len - 1].first;
            if (d % 2 == 0)
            {
                ++res[binding[len - 1].first];
            }
            else
            {
                ++res[binding[len - 1].second];
            }
        }
    }
    else
    {
        ++res[binding[len - 1].first];
        ++res[binding[len - 1].second];
    }
    
    for (int i = 0; i < N; ++i)
    {
        cout << res[i];
        if (i != N - 1) cout << " ";
        else cout << "\n";
    }
    return 0;
}


Measured memory_bytes: 1528
#include <bits/stdc++.h>
#define pb push_back
#define rep(i,n) for(int i=0;i<(n);i++)
#define reps(i,n,s) for(int i=(s);i<(n);i++)
#define rrep(i,n) for(int i=(n-1);i>=0;i--)
#define rreps(i,n,s) for(int i=s;i>=n;i--)
#define MOD 1000000007
using ll = long long;
using namespace std;
template<class T> bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T> bool chmin(T &a, const T &b) { if (a>b) { a=b; return 1; } return 0; }

int main(){
cin.tie(0);
ios::sync_with_stdio(false);
int a, b, c, x;
cin >> a >> b >> c >> x;
int ans=0;
rep(i,a+1){
    rep(j,b+1){
        rep(k,c+1){
        if(500*i+100*j+50*k==x){
            ans++;
        }
    }
}
}
cout << ans << endl;

//system("pause");
return 0;
}

Measured memory_bytes: 256
// This amazing code is by Eric Sunli Chen.
#include <algorithm>
#include <bitset>
#include <cmath>
#include <cstring>
#include <cstdio>
#include <cstdlib>
#include <ctime>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <string>
#include <utility>
#include <vector>
using namespace std;
template<typename T> void get_int(T &x)
{
	char t=getchar();
	bool neg=false;
	x=0;
	for(; (t>'9'||t<'0')&&t!='-'; t=getchar());
	if(t=='-')neg=true,t=getchar();
	for(; t<='9'&&t>='0'; t=getchar())x=x*10+t-'0';
	if(neg)x=-x;
}
template<typename T> void print_int(T x)
{
	if(x<0)putchar('-'),x=-x;
	short a[20]= {},sz=0;
	while(x>0)a[sz++]=x%10,x/=10;
	if(sz==0)putchar('0');
	for(int i=sz-1; i>=0; i--)putchar('0'+a[i]);
}
#define ff first
#define ss second
#define pb push_back
#define mp make_pair
#define get1(a) get_int(a)
#define get2(a,b) get1(a),get1(b)
#define get3(a,b,c) get1(a),get2(b,c)
#define printendl(a) print_int(a),puts("")
typedef long long LL;
typedef unsigned long long uLL;
typedef pair<int,int> pii;
const int inf=0x3f3f3f3f;
const LL Linf=1ll<<61;
const double pi=acos(-1.0);

int n,k,a[100111];
LL pre[100111],suf[100111],ans;
int main()
{
	get2(n,k);
	for(int i=1;i<=n;i++)get1(a[i]);
	
	for(int i=1;i<=n;i++)pre[i]=pre[i-1]+max(0,a[i]);
	for(int i=n;i>=1;i--)suf[i]=suf[i+1]+max(0,a[i]);
	LL cur=0;
	for(int i=1;i<=k;i++)cur+=a[i];
	for(int i=1;i<=n-k+1;i++)
	{
		ans=max(ans,max(0ll,cur)+pre[i-1]+suf[i+k]);
		cur+=a[i+k]-a[i];
	}
	printendl(ans);
	return 0;
}

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

using namespace std;
#define int long long
#define rep(i,n) for(int i=0;i<n;++i)
#define rep1(i,n) for(int i=1;i<=n;++i)
#define ALL(x) x.begin(),x.end()
using P=pair<int,int>;
using lint=long long;
using ll=long long;
const lint inf=1e18+7;
const int MOD=1000000007;
signed main(){
  int n,k;cin>>n>>k;
  vector<int> a(n);
  rep(i,n)cin>>a[i];
  sort(a.begin(),a.end());
  int hu=0;
  bool zero=false;
  rep(i,n){
    if(a[i]==0)zero=true;
  }
  rep(i,n){
    if(a[i]<0)++hu;
    else break;
  }
  int num=0;
  int cur=n-k;
  int res=1;
  while(num<=hu){
    if(cur+1>=n)break;
    if(a[num]*a[num+1]<a[cur]*a[cur+1]){
      break;
    }
    num+=2;
    cur+=2;
  }
  rep(i,num){
    res*=a[i];res%=MOD;
  }
  for(int i=cur;i<n;++i){
    res*=a[i];res%=MOD;
  }
  if(a[n-1]<0&&k%2==1){
    if(zero)res=MOD-1;
    else{
      res=1;
      rep1(i,k){
        res*=-a[n-i];res%=MOD;
      }
      res=MOD-res;
    }
  }
  res+=MOD;
  res%=MOD;
  cout<<res<<"\n";
  return 0;
}


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

typedef long long int ll;
#define INF 1999999999
#define MODA 1000000007

int main()
{
    // freopen("input.txt", "r", stdin);
    // freopen("output.txt", "w", stdout);
    ios::sync_with_stdio(false);
    cin.tie(0);
    string a, b, c;
    cin >> a >> b >> c;
    int len1 = a.length();
    int len2 = b.length();
    if(a[len1-1] == b[0] && b[len2-1] == c[0])
        cout << "YES" << endl;
    else
        cout << "NO" << endl;


    return 0;
}


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

int main(){
  
  cout << fixed;
  cout << setprecision(10);
  
  long double a, b;
  long double x, y;
  cin >> a >> b >> x;
  y = a * a * b;
  
  long double xx, yy;
  xx = x / a;
  yy = y / a;
  
  long double h, w, theta;
  h = b - x / (a * a);
  
  if (h > b / 2.0) {
    w = xx / b * 2.0;
    //cout << "w = " << w << endl;
    //cout << "h = " << b << endl;
    //cout << "h / w = " << b / w << endl;
    theta = atan2(w , b);
    cout << (M_PI / 2.0 - theta) / M_PI * 180.0;
    return 0;
  } else {
    w = a;
    theta = atan2(2.0 * h, w);
    cout << theta / M_PI * 180.0;
    return 0;
  }
  
  return 0;
}


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

struct node{
  struct node *right;
  struct node *left;
  struct node *parent;
  int key;
};
typedef struct node * Node;
#define NIL NULL

Node root;

Node treeMinimum(Node x){

  while(x->left!=NIL){
    x=x->left;
  }

  return x;

}

Node treeSearch(Node u, int k){

  if(u==NIL || k==u->key) return u;
  if(k<u->key) return treeSearch(u->left,k);
    else return treeSearch(u->right,k);
}

Node treeSuccessor(Node x){

  if (x->right!=NIL) return treeMinimum(x->right);
    
  /*y=x->parent;

  while(y!=NIL && x==y->right){
    x=y;
    y=y->parent;
  }
  return y;
  */
}

void treeDelete(Node z){
  Node y; // node to be deleted
  Node x; // child of y



}

void insert(int k){
  Node y = NIL;
  Node x = root;
  Node z;

  z = malloc(sizeof(struct node));
  z->key = k;
  z->left = NIL;
  z->right = NIL;

  while(x!=NIL){
    y=x;
    if(z->key<x->key) x=x->left;
    else x=x->right;
    z->parent=y;
  }

    if(y==NIL) root=z;
    else if (z->key<y->key)
		 y->left=z;
    else y->right=z;

}

void inorder(Node u){

  if(u!=NIL) {

    inorder(u->left);
    printf(" %d",u->key);
    inorder(u->right);

  }

}
void preorder(Node u){

  if(u!=NIL){

  printf(" %d",u->key);
 preorder(u->left);
 preorder(u->right);

  }

}


int main(){
  int n, i, x;
  char com[20];
  scanf("%d", &n);

  for ( i = 0; i < n; i++ ){
    scanf("%s", com);
    if ( com[0] == 'f' ){
      scanf("%d", &x);
      Node t = treeSearch(root, x);
      if ( t != NIL ) printf("yes\n");
      else printf("no\n");
    } else if ( com[0] == 'i' ){
      scanf("%d", &x);
      insert(x);
    } else if ( com[0] == 'p' ){
      inorder(root);
      printf("\n");
      preorder(root);
      printf("\n");
    } else if ( com[0] == 'd' ){
      scanf("%d", &x);
      treeDelete(treeSearch(root, x));
    }
  }

  return 0;
}

Measured memory_bytes: 24040
//
// Created by yamunaku on 2019/10/06.
//

#include <bits/stdc++.h>

using namespace std;

#define rep(i, n) for(int i = 0; i < (n); i++)
#define repl(i, l, r) for(int i = (l); i < (r); i++)
#define per(i, n) for(int i = ((n)-1); i >= 0; i--)
#define perl(i, l, r) for(int i = ((r)-1); i >= (l); i--)
#define all(x) (x).begin(),(x).end()
#define MOD9 998244353
#define MOD1 1000000007
#define IINF 1000000000
#define LINF 1000000000000000000
#define SP <<" "<<
#define CYES cout<<"Yes"<<endl
#define CNO cout<<"No"<<endl
#define CFS cin.tie(0);ios::sync_with_stdio(false)
#define CST(x) cout<<fixed<<setprecision(x)

typedef long long ll;
typedef long double ld;
typedef vector<int> vi;
typedef vector<vector<int>> mti;
typedef vector<ll> vl;
typedef vector<vector<ll>> mtl;

mti e,ne;
vi vis,c;

void dfs(int x, int &t){
    vis[x]=true;
    for(auto nx:e[x]){
        if(vis[nx]==false){
            dfs(nx, t);
        }
    }
    c[t++]=x;
}

int dfs2(int x, vi &v){
    vis[x]=true;
    v.push_back(x);
    for(auto nx:ne[x]){
        if(vis[nx]==false){
            dfs2(nx, v);
        }
    }
}

int main(){
    int n,m;
    cin >> n >> m;
    e=mti(n);
    ne=mti(n);
    vis=vi(n,false);
    c=vi(n);
    int u,v;
    rep(i,m){
        cin >> u >> v;
        u--,v--;
        e[u].push_back(v);
        ne[v].push_back(u);
    }
    int t=0;
    rep(i,n){
        if(!vis[i]){
            dfs(i, t);
        }
    }
    vis=vi(n,false);
    mti st;
    per(i,n){
        if(!vis[c[i]]){
            st.push_back(vi());
            dfs2(c[i], st[st.size()-1]);
        }
    }
    mti ans(n);
    rep(i,st.size()){
        rep(j,st[i].size()){
            rep(k,st[i].size()){
                ans[st[i][j]].push_back(st[i][k]);
            }
        }
    }
    rep(i,n){
        sort(all(ans[i]));
        cout << ans[i][0]+1;
        repl(j,1,ans[i].size()){
            cout << " " << ans[i][j]+1;
        }
        cout << endl;
    }
    return 0;
}



Measured memory_bytes: 4748
#include <iostream>
#include <string>
#include <vector>
#include <list>
#include <map>
#include <queue>
#include <stack>
#include <algorithm>
#include <fstream>
#include <sstream>
#include <iomanip>

using namespace std;

long long MOD = 1000000007;

int main(){
    string X;
    cin >> X;
    int N=X.size();
    int cntS=0;
    for(int i=0; i<(int) X.size(); i++){
        if(X[i]=='S'){
            cntS++;
        }else if(cntS>0 && X[i]=='T'){
            cntS--;
            N-=2;
        }
    }
    cout << N << endl;
}

Measured memory_bytes: 640
#include <iostream>
#include <vector>
#include <climits>
#include <cstdlib>
#define rep(v,n) for(int v=0;v<n;v++)
using namespace std;
int main()
{
    int N, K;
    cin >> N >> K;
    vector<int> xs(N);
    rep(i, N) cin >> xs[i];
    int time = INT_MAX;
    rep(i, N) {
        int j = i + K - 1;
        if (!(j<N)) continue;
        if (xs[i] < 0 && xs[j] > 0) {
            time = min(time, -2*xs[i]+xs[j]);
            time = min(time, -xs[i]+2*xs[j]);
        } else {
            time = min(time, max(abs(xs[i]), abs(xs[j])));
        }
    }
    cout << time << endl;
    return 0;
}


Measured memory_bytes: 640
#include<bits/stdc++.h>
#define P pair<int,int>
#define fr first
#define se second
using namespace std;
typedef long long ll;
const int maxx=1e5+10;
const ll mod=1e9+7;
int main(){
    int n; cin>>n;
    while(n){
        if(n%10==7) return 0*puts("Yes");
        n/=10;
    }
    puts("No");
}


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

int main(){
    int n; cin >> n;
    int64_t ans = 0, prev = 0;
    for (auto i = 0; i < n; i++) {
        int64_t a, tmp = 0; cin >> a;
        if(a < prev) tmp = prev - a;
        prev = a + tmp;
        ans += tmp;
    }

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

Measured memory_bytes: 3592
#include <iostream>
using namespace std;
int main(void){
    // Your code here!
    string a,b;
    int c,k=0;
    cin>>a>>b;
    c=a.size();
    for(int z=0;z<=c;z++){
        if(a[z]!=b[z]){
            k++;
        }
    }
    cout<<k<<endl;
}


Measured memory_bytes: 3824
#define _CRT_SECURE_NO_WARNINGS
#define MOD 1000000007 
#define INF 100000000
//#define MOD 3025908521 
#include <iostream>
#include <vector>
#include <list>
#include <set>
#include <bitset>
#include <map>
#include <stack>
#include <queue>
#include <deque>
#include <string>
#include <functional>
#include <algorithm>
#include <iterator>
#include <cstdio>
#include <utility>
#include <unordered_map>
#include <cmath>
#include <chrono>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;

typedef pair<ll, ll> P;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<vector<int>> vvi;
typedef vector<vector<ll>> vvl;
struct edge { ll to, cost; };
#define FOR(i,a,b) for(ll i=(a);i<(b);++i)
#define RFOR(i,a,b) for(ll i=(a);i>(b);i--)
#define REP(i,n) FOR(i,0,n)
#define RREP(i,n) RFOR(i,n,-1)
#define ALL(obj) (obj).begin(), (obj).end()

inline ll madd(ll a, ll b) {
	a %= MOD;b %= MOD;
	return (a + b) % MOD;
}
inline ll msub(ll a, ll b) {
	a %= MOD;b %= MOD;
	a += MOD;
	return (a - b) % MOD;
}
inline ll mmul(ll a, ll b) {
	a %= MOD;b %= MOD;
	return (a*b) % MOD;
}
inline ll mpow(ll a, ll r) {
	long long res = 1;
	while (r > 0) {
		if (r & 1) res = res * a % MOD;
		a = a * a % MOD;
		r >>= 1;
	}
	return res;
}
inline ll minv(ll a) {
	a %= MOD;
	ll b = MOD, u = 0, v = 1;
	while (a) {
		ll t = b / a;
		b -= t * a; swap(a, b);
		u -= t * v; swap(u, v);
	}
	if (u < 0) u += MOD;
	return u;
}
inline ll mdiv(ll a, ll b) {
	a %= MOD;
	a *= minv(b);
	return a%MOD;
}
//ll fact[]
//inline ll combi(int a, int b) {
//	return mmul(fact[a], mmul(fact_inv[b], fact_inv[a - b]));
//}

struct UnionFind {
	vector<int> data;
	UnionFind(int size) : data(size, -1) { }
	bool unite(int x, int y) {
		x = root(x); y = root(y);
		if (x != y) {
			if (data[y] < data[x]) swap(x, y);
			data[x] += data[y]; data[y] = x;
		}
		return x != y;
	}
	bool same(int x, int y) {
		return root(x) == root(y);
	}
	int root(int x) {
		return data[x] < 0 ? x : data[x] = root(data[x]);
	}
	int size(int x) {
		return -data[root(x)];
	}
};

int main() {
	int n, j;
	cin >> n;
	vi ind(n+1);
	ind[0] = -1;
	REP(i, n) {
		cin >> j;
		ind[j] = i;
	}
	set<int> s;
	s.insert(-1);
	s.insert(n);
	s.insert(ind[n]);
	ll res = 0;
	RFOR(i, n-1, 0) {
		auto next=s.lower_bound(ind[i]);
		auto before = next; before--;
		if (before != s.begin()) {
			auto bb = before;bb--;
			res += i*(*next - ind[i])*(*before - *bb);
		}
		auto en = s.end();en--;
		if (next != en){
			auto nn = next;nn++;
			res += i*(ind[i] - *before)*(*nn - *next);
		}
		s.insert(ind[i]);
	}
	cout << res;
	return 0;
}


Measured memory_bytes: 5376
#include <stdio.h>
int main(void)
{
  int N;
  int X[N];
  int i;
  int P;
  int total=0;
  int total1=0;

  int T=0;
  scanf("%d\n",&N);
  for(i=0;i<N;i++)
  {
    scanf("%d ",&X[i]);
  }
  for(i=0;i<N;i++)
    T = T+X[i];
  P=T/N;
  for(i=0;i<N;i++)
  {
    total =total + (X[i]-P) * (X[i]-P);
    total1 =total1 + (X[i]-P-1) * (X[i]-P-1);
  }
  if(total>total1)  printf("%d\n",total1);
  else printf("%d\n",total);
  return 0;
}


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


int main() {
  int a, b;
  cin >> a >> b;
  int c = a + b;
  if (c % 2 == 0) {
    int k = c / 2;
    cout << k << endl;
  } else {
    cout << "IMPOSSIBLE" << endl;
  }
}

Measured memory_bytes: 256
#include <string>
#include <stdio.h>
#include <algorithm>
#include <iostream>
#include <vector>
#include <cmath>
#include <map>
#define rep(i,n) for(int i = 0; i < (n); i++)
using namespace std;
typedef pair<int, int> P;

P f(int x){
    int a = x % 10;
    int b = 0;
    while(x){
        b = x;
        x /= 10;
    }
    return P(a, b);
}

int main()
{
    int n;
    cin >> n;
    map<P, int> freq;
    for(int i = 1; i <= n; i++){
        P p = f(i);
        freq[p]++;
    }
    long long ans = 0;
    for(int i = 1; i <= n; i++){
        P p = f(i);
        P q(p.second, p.first);
        ans += freq[q];
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
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 = read::<usize>();
    let k = read::<usize>();
    let s = read::<String>().chars().collect::<Vec<char>>();
    let mut ans = 0;
    let mut prev = s[0];
    let mut cnt = 0;
    let mut used = false;
    for i in 1..n {
        if prev == s[i] {
            ans += 1;
            continue;
        }
        if used {
            ans += 1;
            used = false;
            prev = s[i];
            continue;
        }
        if cnt < k {
            cnt += 1;
            ans += 1;
            used = true;
            prev = s[i];
            continue;
        }
        prev = s[i];
    }
    println!("{}", ans);
}


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

main(){
	int N;
	int i=0;
	char S[10000];
	scanf("%d",&N);
	scanf("%s",&S);
	
	
	while(S[i]!='\0'){
		if(S[i]+N>90){
			S[i] = 64 + (S[i]+N-90);
		}
		else{
			S[i] = S[i]+N;
		}
		i++;
	}
	puts(S);
}

Measured memory_bytes: 128
import java.util.*;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		
		int a,b,c;
		
		a = sc.nextInt();
		b = sc.nextInt();
		c = a*b;
		
		if(c%2 == 0) {
			System.out.println("Even");
		}
		else {
			System.out.println("Odd");
		}
	}
}

Measured memory_bytes: 23252
#include <stdio.h>

int main(void)
{
    int n, k;
    char s[51];
    scanf("%d%d%s", &n, &k, s);

    switch (s[k - 1])
    {
    case 'A':
        s[k - 1] = 'a';
        break;
    case 'B':
        s[k - 1] = 'b';
        break;
    case 'C':
        s[k - 1] = 'c';
        break;
    }

    printf("%s\n", s);
    return 0;
}

Measured memory_bytes: 128
#include<iostream>
using namespace std;
#define ll long long

int N;
ll X;
ll a[50],p[50];

ll fact(int n,ll x){
  if(n==0) return 1;
  if(x==1) return 0;
  if(x<=1+a[n-1]) return fact(n-1,x-1);
  if(x==2+a[n-1]) return p[n-1]+1;
  if(x<=2*a[n-1]+2) return p[n-1]+1+fact(n-1,x-a[n-1]-2);
  if(x==2*a[n-1]+3) return p[n-1]*2+1;
}
int main(){
  cin>>N>>X;
  a[0]=p[0]=1;
  for(int i=1;i<N;i++){
    a[i]=2*a[i-1]+3;
    p[i]=2*p[i-1]+1;
  }
  cout<<fact(N,X)<<endl;
  return 0;
}

Measured memory_bytes: 256
//
//
#include <cstdio>
#include <cmath>
using namespace std;
long long t;
int min(int a,long long b){
	if(a>b)	return b;
	return a;
}
int main(){
	long long a,b,minn=0x6f6f6f6f6f6f6f;
	scanf("%d %d",&a,&b);
	if(a>=b){
		printf("0");
		return 0;
	}
	for(int i=a;i<=b;i++){
		for(int j=i+1;j<=b;j++){
			if(i%2019==0||j%2019==0){
				printf("0");
				return 0;
			}
			minn=min(minn,(i%2019)*(j%2019)%2019);
		}
	}
	printf("%d",minn);
	return 0;
}

Measured memory_bytes: 128