akhauriyash/Code-Regression huggingface dataset:
#include<iostream>
#include<sstream>
#include<fstream>
#include<string>
#include<vector>
#include<deque>
#include<queue>
#include<stack>
#include<set>
#include<map>
#include<algorithm>
#include<functional>
#include<utility>
#include<bitset>
#include<cmath>
#include<cstdlib>
#include<ctime>
#include<cstdio>

using namespace std;

#define REP(i,n) for(int i=0;i<int(n);i++)
#define foreach(c,itr) for(__typeof((c).begin()) itr=(c).begin();itr!=(c).end();itr++)
typedef long long ll;
typedef pair<int,int> P;

int a[100010];

int main(void){
	          int i;

	      	  cin.tie(0);  ios_base::sync_with_stdio(false);

	      	  int N;
	      	  cin >> N;
	      	  for(i=1;i<=N;i++){
	      		  int x;
	      		  cin >> x;
	      		  a[x]++;
	      		  a[x+3]--;
	      	  }

	      	  int mx=0;
	      	  for(i=1;i<=100001;i++){
	      		  a[i]+=a[i-1];
	      	  }

	      	  for(i=0;i<=100001;i++){
	      		  if(a[i]>mx){
	      			  mx=a[i];
	      		  }
	      	  }

	      	  cout << mx << endl;

	          return 0;
}


Measured memory_bytes: 640
N,K=map(int,input().split())

S=str(input())
q=S[K-1]
#print(q)

if q == "A":
    w="a"
elif q=="B":
    w="b"
else:
    w="c"
e=""
for i in range(N):
    if i != K-1:
        e=e+S[i]
    else:
        e=e+w
print(e)

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

int main(){
    int N;  cin >> N;
    vector<int> X(N);
    for(int i=0; i<N; i++){
        cin >> X[i];
    }

    int minCost = 1e9;
    for(int p=0; p<=100; p++){
        int cost = 0;
        for(int i=0; i<N; i++){
            cost += (X[i] - p)*(X[i] - p);
        }
        minCost = min(minCost, cost);
    }
    cout << minCost << endl;
}


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

void solve(void)
{
    int n;
    string s, t;
    cin >> n >> s >> t;
    int ans = 2 * n;
    rep(i, n)
    {
        int cta = 0;
        rep(j, n)
        {
            if (i + j >= n)
                continue;
            if (s[i + j] == t[j])
                cta++;
            else
                continue;
        }
        ans = min(ans, 2 * n - cta);
    }
    cout << ans << endl;
}
int main(void)
{
    solve();
}

Measured memory_bytes: 3532
import sys
input = sys.stdin.readline

n, m =  map(int, input().split()) # nは頂点の数、mは辺の数
pic = [[] for _ in range(n)] # 隣接リスト_初期化
#print(n,m)

for _ in range(m): # 隣接リスト_取り込み
    a, b = map(int, input().split())
    pic[a-1].append(b-1)
    pic[b-1].append(a-1)
#print(pic)

from collections import deque

def BFS(u): # 'u'を開始位置として各頂点までの距離を探索する関数
    queue = deque([u]) # dequeオブジェクトとして初期化、初期値は開始位置の'u'のみ
    dis = [None] * n # uからの距離を全ノード分初期化
    dis[u] = 0 # 自分'u'との距離は0
    ans = [-1] * n
    #print(ans)
    while queue:
        v = queue.popleft() # v:探索元のノード 
        for i in pic[v]: # pic[v]: 探索元のノードに隣接するノードのリスト
            if ans[i] == -1:
                ans[i] = v
            if dis[i] is None:
                dis[i] = dis[v] + 1
                queue.append(i)
    return ans

# 0からの各頂点の距離
#print(BFS(0))
dis = BFS(0)
print('Yes')
for j in dis[1:]:
    print(j+1)


Measured memory_bytes: 34776
using System;
using System.Linq;

namespace B.Digit_Sums
{
    class Program
    {
        static void Main(string[] args)
        {
            var S = Console.ReadLine().ToCharArray();

            Console.WriteLine(int.Parse(new string(S)) % S.Select(x => int.Parse(x.ToString())).Sum() == 0 ? "Yes" : "No");
        }
    }
}


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

using namespace std;
typedef long long LL;

#ifdef BTK
#define DEBUG if(1)
#else
#define CIN_ONLY if(1)
struct cww {cww() {CIN_ONLY{ios::sync_with_stdio(false); cin.tie(0);}}
}star;
#define DEBUG if(0)
#endif

#define ALL(v) (v).begin(),(v).end()
#define REC(ret, ...) std::function<ret (__VA_ARGS__)>
template <typename T>inline bool chmin(T &l, T r){bool a = l>r; if (a)l = r; return a;}
template <typename T>inline bool chmax(T &l, T r){bool a = l<r; if (a)l = r; return a;}
template <typename T>istream& operator>>(istream &is, vector<T> &v){for (auto &it : v)is >> it;return is;}

class range {private: struct I { int x; int operator*() { return x; }bool operator!=(I& lhs) { return x<lhs.x; }void operator++() { ++x; } }; I i, n;public:range(int n) :i({ 0 }), n({ n }) {}range(int i, int n) :i({ i }), n({ n }) {}I& begin() { return i; }I& end() { return n; }};

int main() {
	int N;
	cin >> N;
	vector<LL> L(N), R(N);
	for (int i : range(N)) {
		cin >> L[i] >> R[i];
		L[i] *= 2;
		R[i] *= -2;
	}
	sort(ALL(L));
	sort(ALL(R));
	reverse(ALL(L));
	reverse(ALL(R));

	LL ret = 0;
	LL ans = 0;
	for (int i : range(N)) {
		chmax(ret, ans + L[i]);
		chmax(ret, ans + R[i]);
		chmax(ret, ans + R[i] + L[i]);
		ans += L[i] + R[i];
	}
	cout << ret << endl;


	return 0;
}


Measured memory_bytes: 1792
#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#include<bits/stdc++.h>
#define ll long long
#define ull unsigned long long
#define pii pair<int,int>
#define pp pair<pair<ll, ll>,pair<ll, ll>>
#define pll pair<ll,ll>
#define pdd pair<double,double>
#define vii vector<int>
#define vll vector<ll>
#define mat vector<vector<ll>>
#define lb lower_bound
#define ub upper_bound
#define pb push_back
#define fi first
#define sc second
#define rep(i,n) for(ll i=0;i<n;i++)
#define rep2(i,a,b) for(ll i=a;i<b;i++)
#define repr(i,n) for(ll i=n-1;i>=0;i--)
#define all(x) x.begin(),x.end()
#define sz(x) (ll) (x).size()
#define pq priority_queue<ll>
#define pqg priority_queue<ll,vector<ll>,greater<ll>>
#define LB(v,x) (lower_bound(v.begin(),v.end(),x)-v.begin())
#define UB(v,x) (upper_bound(v.begin(),v.end(),x)-v.begin())
#define ERASE(v) sort(v.begin(),v.end());v.erase(unique(v.begin(),v.end()),v.end())
#define int ll
using namespace std;
const ll INF = (1 << 30 ) - 1;
const ll LLINF = (1LL << 60LL);
const ll MOD = 1000000007;
const ll mod = 998244353;
const ll MAX = 1100000;
const double pi = acos(-1);
const double eps = 1e-10;
ll dx[4] ={1,0,-1,0} , dy[4] ={0,1,0,-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; }

struct Timer{
    chrono::system_clock::time_point start, end;
    Timer(){ start = chrono::system_clock::now(); }
    ~Timer(){
        end = chrono::system_clock::now();
        auto msec = chrono::duration_cast<chrono::milliseconds>(end - start).count();
        cerr<<"time : "<<msec<<" ms"<<endl;
    }
};


signed main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(15);
    Timer TM;


    ll a,b;
    cin>>a>>b;
    ll now=0;
    rep(i,b){
        now+=(ll)pow(100,a);
        while(now%(ll)pow(100,a+1)==0){
            now+=(ll)pow(100,a);
        }
    }
    cout<<now<<endl;
    return 0;
}


Measured memory_bytes: 256
def postorder(preorder,inorder):
    if len(preorder) > 1:
        n = preorder[0]
        left_inorder = []
        right_inorder = []
        flag = False
        for i in range(len(inorder)):
            if flag == False:
                if n == inorder[i]:
                    flag = True
                else:
                    left_inorder.append(inorder[i])
            else:
                right_inorder.append(inorder[i])
        left_preorder = []
        right_preorder = []
        flag = False
        for i in range(1,len(preorder)):
            if flag == False:
                if len(left_preorder) == len(left_inorder):
                    flag = True
                else:
                    left_preorder.append(preorder[i])
            if flag == True:
                right_preorder.append(preorder[i])
        #print left_preorder,left_inorder
        #print right_preorder,right_inorder
        #print
        postorder(left_preorder,left_inorder)
        postorder(right_preorder,right_inorder)
    if len(preorder) > 0:
        print preorder[0],

n = int(raw_input())
preorder = map(int,raw_input().split(' '))
inorder = map(int,raw_input().split(' '))

postorder(preorder,inorder)

Measured memory_bytes: 6456
#include<bits/stdc++.h>
#define rep(i,n) for(int i=0;i<n;i++)
using namespace std;
int main(){
  int n;
  cin >> n;
  
  vector<int> a(n);
  rep(i,n) cin >> a[i];
  sort(a.rbegin(),a.rend());
  
  int alice = 0, bob = 0;
  rep(i,n){
    if(i%2 == 0) alice += a[i];
    else bob += a[i];
  }
  
  cout << alice - bob << endl;
  
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;


int main()
{
	string s,w[4]={"resare","esare","remaerd","maerd"},p[4]={"######","#####","#######","#####"};
	cin>>s;
	reverse(s.begin(),s.end());
	for(int i=0;i<4;i++)
	{
		for(int j=0;j<=s.length()-w[i].length();j++)
		{
			if(s.substr(j,w[i].length())==w[i])s.replace(j,w[i].length(),p[i]);
		}
	}
	bool flag=true;
	for(int i=0;i<s.length();i++)
	{
		if(s[i]!='#')flag=false;
	}
	if(flag)cout<<"YES"<<endl;
	else cout<<"NO"<<endl;
	return 0;
}

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

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

int main()
{
    int A, B;
    cin >> A >> B;
    rep(i, (100/0.08)+1)
    {
        int Xa = i * 0.08;
        if(Xa != A)
        {
            continue;
        }
        rep(j, (100/0.1)+1)
        {
            int Xb = j * 0.1;
            if(Xb != B)
            {
                continue;
            }
            else if(i == j)
            {
                cout << i << endl;
                return 0;
            }
        }
    }

    cout << -1 << endl;
}

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

const double PI = acos(-1);

int main(){
    double a,b,C;
    cin >> a >> b >> C;
    
    double S;
    double L;
    double c;
    double h;
    
    C = C * PI / 180;
    
    h = b * sin(C);
    
    S = a * h / 2;
    
    c = sqrt(a*a+b*b-2*a*b*cos(C));
    
    L = a + b + c;
    
    cout << fixed << setprecision(10) << S << endl;
    cout << fixed << setprecision(10) << L << endl;
    cout << fixed << setprecision(10) << h << endl;
}



Measured memory_bytes: 3540
package main

import (
	"bufio"
	"fmt"
	"io"
	"math"
	"os"
	"strconv"
	"strings"

)


func main() {
	solve(os.Stdin, os.Stdout)
}

type ReaderEx struct {
	baseScanner *bufio.Scanner
	words       []string
	nextWordIdx func() int
	initWordIdx func(int)
}

func NewScannerEx(stdin io.Reader) *ReaderEx {
	var this ReaderEx
	var idx int
	var wordsCnt int
	this.baseScanner = bufio.NewScanner(stdin)
	this.baseScanner.Buffer(make([]byte, 0), 1E+11)
	this.nextWordIdx = func() int {
		cur := idx
		idx = (idx + 1) % wordsCnt
		return cur
	}
	this.initWordIdx = func(wc int) {
		idx = 0
		wordsCnt = wc
	}
	return &this
}

func (me *ReaderEx) Scan(doSplit bool) (isScanned bool) {
	isScanned = me.baseScanner.Scan()
	if doSplit {
		me.words = strings.Fields(me.baseScanner.Text())
	} else {
		me.words = []string{me.baseScanner.Text()}
	}
	me.initWordIdx(len(me.words))
	return
}

func (me *ReaderEx) nextBytes() []byte {
	return []byte(me.words[me.nextWordIdx()])
}
func (me *ReaderEx) nextString() string {
	return me.words[me.nextWordIdx()]
}

type StringArray []string

func (me *ReaderEx) nextStringArray() StringArray {
	return me.words[me.nextWordIdx():]
}

func (me StringArray) toStrings() []string {
	return me
}

func (me StringArray) toInts() []int {
	strValues := me.toStrings()
	values := make([]int, len(strValues))
	for i, v := range strValues {
		n, err := strconv.Atoi(v)
		if err != nil {
			panic(err)
		}
		values[i] = n
	}
	return values
}
func (me *ReaderEx) nextInt() int {
	n, err := strconv.Atoi(me.words[me.nextWordIdx()])

	defer func() {
		if err != nil {
			panic(fmt.Sprintf("getInt(%d)", n))
		}
	}()
	return n
}

func pow(x, y, mod int) (ans int) {

	ans = 1
	for bit := 1 << uint(math.Floor(math.Log2(float64(y)))); ; bit >>= 1 {
		if y&bit != 0 {
			ans *= x
			if mod > 0 {
				ans %= mod
			}
		}
		if bit <= 1 {
			return
		}
		ans *= ans
		if mod > 0 {
			ans %= mod
		}
	}
}

type factType struct {
	prime int
	count int
}

func fact(n int) (facts []*factType) {

	for i := 2; i*i <= n; i++ {
		if n%i == 0 {
			fa := factType{prime: i}
			for n%fa.prime == 0 {
				n /= fa.prime
				fa.count++
			}
			facts = append(facts, &fa)
		}
	}
	if n > 1 {
		facts = append(facts, &factType{prime: n, count: 1})
	}
	return facts
}
func dec2bin(n int) (ret []bool) {
	for bit := 1 << uint(math.Floor(math.Log2(float64(n)))); ; bit >>= 1 {
		ret = append(ret, n&bit != 0)

		if bit <= 1 {
			return
		}
	}

}

func abs(v int) int {
	if v < 0 {
		v = -v
	}
	return v
}

func b2i(b bool) (i int) {
	if b {
		i = 1
	} else {
		i = 0
	}
	return
}

func solve(stdin io.Reader, stdout io.Writer) {

	r := NewScannerEx(stdin)
	r.Scan(true)
	//n := r.nextInt()
	r.Scan(true)
	d := r.nextStringArray().toInts()

	ans := 0
	for i := range d {
		for j := range d {
			if i < j {
				ans += d[i] * d[j]
			}
		}
	}
	fmt.Fprintln(stdout, ans)
}


Measured memory_bytes: 640
import java.io.*;
import java.math.*;
import java.util.*;
public class Main { //CASH MONEY --> Collections.sort()>>>>>Arrays.sort()
 
	public static void main(String[] args) { //Ball out dawg
		FastScanner I = new FastScanner(); //Input
		OutPut O = new OutPut(); //Output
		int[][] grid = new int[3][3];
		boolean good = false;
		for (int i = 0; i < 3; i++) {
			for (int j = 0; j < 3; j++) {
				grid[i][j] = I.nextInt();
			}
		}
		for (int a = 0; a <= 100; a++) {
			for (int b = 0; b <= 100; b++) {
				for (int c = 0; c <= 100; c++) {
					int check = 0; //how many columns are valid
					for (int col = 0; col < 3; col++) {
						if (grid[0][col]-a==grid[1][col]-b&&grid[0][col]-a==grid[2][col]-c) {
							check++;
						}
					}
					if (check==3) good=true;
				}
				if (good) break;
			}
			if (good) break;
		}
		O.pln(good?"Yes":"No");
	}
	public static int MEX(int N,int[] cnts) {
		for (int test = 0; test <=N; test++) if (cnts[test]==0) return test;
		return -1;
	}
	public static long ceil(long num, long den) {long ans = num/den; if (num%den!=0) 
	ans++; return ans;}
	public static long GCD(long a, long b) {
		if (a==0||b==0) return Math.max(a,b);
		return GCD(Math.min(a, b),Math.max(a, b)%Math.min(a, b));
	}
	public static long FastExp(long base, long exp, long mod) {
		long ans=1;
		while (exp>0) {
			if (exp%2==1) ans*=base;
			exp/=2;
			base*=base;
			base%=mod;
			ans%=mod;
		}
		return ans;
	}
	public static long ModInv(long num,long mod) {return FastExp(num,mod-2,mod);}
	static class FastScanner {
		BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
		StringTokenizer st=new StringTokenizer("");
		String next() {
			while (!st.hasMoreTokens())
				try {
					st=new StringTokenizer(br.readLine());
				} catch (IOException e) {
					e.printStackTrace();
				}
			return st.nextToken();
		}
		int nextInt() {return Integer.parseInt(next());}
		long nextLong() {return Long.parseLong(next());};
	}
	static class OutPut{
		PrintWriter w = new PrintWriter(System.out);
		void pln(int x) {w.println(x);w.flush();}
		void pln(long x) {w.println(x);w.flush();}
		void pln(String x) {w.println(x);w.flush();}
		void pln(char x) {w.println(x);w.flush();}
		void pln(StringBuilder x) {w.println(x);w.flush();}
		void p(int x) {w.print(x);w.flush();}
		void p(long x) {w.print(x);w.flush();}
		void p(String x) {w.print(x);w.flush();}
		void p(char x) {w.print(x);w.flush();}
		void p(StringBuilder x) {w.print(x);w.flush();}
	}
}


Measured memory_bytes: 26384
#include <bits/stdc++.h>
using namespace std;
int main(void){

    int n;
    cin >> n;
    
    map<string, int> datas;
    
    int max = 0;
    for(int i=0; i<n; i++) {
        string s;
        cin >> s;
        if(datas.find(s)!=datas.end()) {
            datas[s]++;
            if(datas[s]> max) max = datas[s];
        }
        else {
            datas[s] = 0;
        }
    }
    
    for(auto itr = datas.begin(); itr != datas.end(); itr++) {
        if(itr->second == max) {
            cout << itr->first << endl;
        }
    }
    
    return 0;    
}


Measured memory_bytes: 25216
import java.util.ArrayList;
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner in = new Scanner(System.in);
		String str = in.nextLine();
		int[] arr = new int[str.length()];
		int[] arr2 = new int[str.length()];
		int a=0,b=0;
		for(int i=0; i<str.length(); i++){
			arr[i] = str.charAt(i)-48;
			if(i%2==0){
				arr2[i]=1;
			}
		}
		for(int i=0; i<str.length(); i++){
			if(arr[i]==arr2[i]){
				a++;
			}
			else{
				b++;
			}
		}
		System.out.println(Math.min(a, b));
	}

}

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

ll gcd(ll a, ll b) { return b?gcd(b,a%b):a;}
ll lcm(ll a, ll b) { return a/gcd(a,b)*b;}


int main(){
  ll n;
  cin >> n;
  ll t = 1;
  ll order = 26;
  while(order < n){
    n -= order;
    order*=26;
    t++;
  }

  n--;

  string ans = "";
  order /= 26;
  while(t){
    // if(n<order/26){
    //   ans = ans + 'a';
    //   t--;
    //   continue;
    // }
    // int tmp = n/(order);
    // tmp = tmp*order;
    // tmp /= order/26;
    // cout << tmp << endl;
    // if(tmp==0){
    //   tmp = 26;
    // }
    // char c = 'a'+tmp-1;
    // ans = ans + c;
    // order *= 26;
    // t--;

    int tmp = n/(order);
    // cout << tmp;
    // cout << tmp << endl;
    char c = 'a'+tmp;
    // if(t==1){
    //   c -= 1;
    // }
    ans = ans + c;
    n -= tmp*order;
    order /= 26;
    t--;
  }

  cout << ans << endl;


  return 0;
} 



Measured memory_bytes: 3616
#include<stdio.h>
#include<stdlib.h>
#include<algorithm>
using namespace std;
int ox[100000];
int oy[100000];
int x[100000];
int y[100000];
int n;
long long calc(int a,int b){
	int md=0,i;
	long long ans=0;
	for(i=0;i<n;i++){
		int d=abs(ox[i]-a)+abs(oy[i]-b);
		md=max(md,d);
		ans+=(long long)d*2;
	}
	return ans-(long long)md;
}
int max(int a,int b){return a>b?a:b;}
int main(){
	int w,h,i,j;
	scanf("%d %d",&w,&h);
	scanf("%d",&n);
	for(i=0;i<n;i++){
		scanf("%d %d",&ox[i],&oy[i]);
		x[i]=ox[i];
		y[i]=oy[i];
	}
	sort(x,x+n);
	sort(y,y+n);
	long long ans=1000000000000000000LL;
	int ax[2];
	int ay[2];
	ax[0]=x[n/2];
	ay[0]=y[n/2];
	int nx,ny;
	if(n%2==0){
		ax[1]=x[n/2-1];
		ay[1]=y[n/2-1];
		for(i=1;i>=0;i--)for(j=1;j>=0;j--){
			if(ans>calc(ax[i],ay[j])){
				ans=calc(ax[i],ay[j]);
				nx=ax[i];
				ny=ay[j];
			}
		}
	}else{
		ans=calc(ax[0],ay[0]);
		nx=ax[0];
		ny=ay[0];
	}
	printf("%lld\n",ans);
	printf("%d %d\n",nx,ny);
	return 0;
}

Measured memory_bytes: 2604
#include <bits/stdc++.h>
#define rep(i, a, n) for(int i = a; i < n; i++)
#define REP(i, n) rep(i, 0, n)
#define repb(i, a, b) for(int i = a; i >= b; i--)
#define all(a) a.begin(), a.end()
#define int long long
#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)
using namespace std;
typedef pair<int, int> P;
const int mod = 1000000007;
const int INF = 1e12;

signed main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    int n;
    cin >> n;
    int a = sqrt(n);
    cout << a * a << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;const int N=1e3+7;
char s[N];int n,m,i,j,k,ans,res[10];
int go(int n){
	for(i=ans=0;i<n;i=j){
		for(j=i;s[i]==s[j]&&j<n;++j);
		ans+=(j-i)/2;
	}return ans;
}
int main(){
	for(scanf("%s%d",s,&m),n=strlen(s),i=0;i<n;++i)s[i+n]=s[i+2*n]=s[i+3*n]=s[i+4*n]=s[i+5*n]=s[i+6*n]=s[i];
	for(int i=1;i<8;++i)res[i]=go(i*n);
	if(m<=7)printf("%d\n",res[m]);
	else{
		if(m%2==0)printf("%lld\n",1LL*(res[6]-res[4])*(m-6)/2+res[6]);
		else printf("%lld\n",1LL*(res[5]-res[3])*(m-5)/2+res[5]);
	}
}

Measured memory_bytes: 256
#define _USE_MATH_DEFINES
#include <algorithm>
#include <cstdio>
#include <functional>
#include <iostream>
#include <cfloat>
#include <climits>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <time.h>
#include <vector>
#include <random>
#include <list>
#include <numeric>
using namespace std;
 
typedef long double ld;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> i_i;
typedef pair<ll, int> ll_i;
typedef pair<int, ll> i_ll;
typedef pair<double, int> d_i;
typedef pair<ll, ll> ll_ll;
typedef pair<double, double> d_d;
struct edge { int u, v; ll w; };
 
#define rep(i, N) for (int i = 0; i < (int)(N); i++)
#define pb push_back
 
int INF = INT_MAX / 10;
ll MOD = 1000000007;
ll _MOD = 1000000009;
double EPS = 1e-10;

int main() {
	string s; cin >> s;
	int cnt = 0;
	rep(i, 16) if (s[i] != "CODEFESTIVAL2016"[i]) cnt++;
	cout << cnt << endl;
}


Measured memory_bytes: 764
#include <iostream>
#include <vector>
#include <algorithm>
#include <numeric>

using namespace std;

int main() {
    vector<int> c(3);
    for (int i = 0; i < 3; ++i) cin >> c.at(i);
    cout << (count(c.begin(), c.end(), accumulate(c.begin(), c.end(), 0) / 2) && !(accumulate(c.begin(), c.end(), 0) % 2) ? "Yes" : "No") << endl;
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const ll mod = 1e9 + 7;
const ll inf = (1 << 30) - 1;
const ll infll = (1LL << 61) - 1;

int n;

int main()
{
    while (cin >> n)
    {
        if (n == 0) return 0;
        
        int ans = 0, l = 0, r = 0;
        bool now = true; // aim : false -> yuka, true -> dai
        string t;

        for (int i = 0; i < n; i++)
        {
            cin >> t;
            if (t == "lu")
                l = 1;
            else if (t == "ru")
                r = 1;
            else if (t == "ld")
                l = 0;
            else
                r = 0;

            if (now == true && r == 1 && l == 1)
            {
                ans++;
                now = false;
            }

            if (now == false && r == 0 && l == 0)
            {
                ans++;
                now = true;
            }
        }
        cout << ans << endl;
    }
}


Measured memory_bytes: 3156
import sys
import math
from collections import defaultdict

sys.setrecursionlimit(10**7)
def input():
    return sys.stdin.readline()[:-1]

mod = 10**9 + 7

def I(): return int(input())
def II(): return map(int, input().split())
def III(): return list(map(int, input().split()))
def Line(N,num):
    if N<=0:
        return [[] for _ in range(num)]
    elif num==1:
        return [I() for _ in range(N)]
    else:
        read_all = [tuple(II()) for _ in range(N)]
        return map(list, zip(*read_all))

#################

import cmath
pi = cmath.pi
exp = cmath.exp

def convolution(a,b):
    
    def fft(a,sz,inv=False):
        tmp = [0]*sz
        mask = sz-1
        p = 0
        i = sz>>1
        sign = 1 if inv else -1

        while i:
            if p&1:
                cur,nex = tmp,a
            else:
                cur,nex = a,tmp
            ei = exp(2j*pi*i*sign/sz)
            w = 1
            for j in range(0,sz,i):
                for k in range(i):
                    nex[j+k] = cur[((j<<1)&mask)+k] + w*cur[(((j<<1)+i)&mask)+k]
                w *= ei
            p += 1
            i >>= 1

        if p&1:
            a,tmp = tmp,a
        if inv:
            a = list(map(lambda x: x/sz, a))
        return a
    
    sz = 1<<(len(a)+len(b)-2).bit_length()
    a = a + [0]*(sz-len(a))
    b = b + [0]*(sz-len(b))

    fa = fft(a,sz)
    fb = fft(b,sz)
    fafb = [fai*fbi for fai,fbi in zip(fa,fb)]
    ab = fft(fafb,sz,inv=True)
    return [round(x.real) for x in ab[:len(a)+len(b)-1]]

N,M = II()
A = III()

h = [0]*(max(A))
for a in A:
    h[a-1] += 1

conv = [0,0] + convolution(h,h)

ans = 0
for k in range(2,2*max(A)+1)[::-1]:
    if conv[k]<M:
        ans += k*conv[k]
        M -= conv[k]
    else:
        ans += k*M
        break
        
print(ans)

Measured memory_bytes: 188208
#include <bits/stdc++.h>
#include <math.h>
#define _GLIBCXX_DEBUG
#define _LIBCPP_DEBUG 0

using namespace std;
#define ll long long
#define rep(i,n) for (int i = 0; i < n; i++)
#define MOD (1000000007)
#define vi vector<int>
#define vvi vector<vi>
#define pii pair<int, int>
#define pb push_back
#define mp make_pair
#define all(a) (a).begin(),(a).end()

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 gcd(int a, int b) {
    if (b == 0) return a;
    else return gcd(b, a % b);
}



const ll INF = 1LL << 60;
struct Edge{
  int to;
  int weight;
  Edge(int t, int w) : to(t), weight(w){}
};
using Graph = vector<vector<Edge>>;
using P = pair<ll, int>;

Graph G;
vector<ll> d; //distance;

// d[v] に頂点 s からの頂点 v の距離を入れる関数
void dijkstra(int s){
  fill(all(d), INF);
  d[s] = 0;

  priority_queue<P, vector<P>, greater<P>> pq;//距離が小さい順に取り出す
  pq.push(P(0,s)); // 頂点 s からスタート

  while (!pq.empty()) {
    P p = pq.top(); pq.pop();
    int v = p.second;
    //if(d[v] < p.first) continue;// 既に v に辿り着く短い経路有ならスルー

    for(auto e : G[v]){// v から行ける頂点 nv 達を走査
      int nv = e.to;
      ll w = e.weight;
      if(d[nv] > d[v] + w){
        d[nv] = d[v] + w;
        pq.push(P(d[nv], nv));
      }
    }
  }
}

int main(){
  int n,m; cin >> n >> m;
  G.resize(n);
  rep(i, m){
    int l,r,c; cin >> l >> r >> c;
    l--; r--;
    G[l].pb(Edge(r,c));
  }
  rep(i, n-1) G[i+1].pb(Edge(i,0));

  d.resize(n);
  dijkstra(0);

  std::cout << (d[n-1] != INF ? d[n-1] : -1) << '\n';
}


Measured memory_bytes: 7928
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#include<math.h>
#include<assert.h>
#define MIN(a,b) a<b?a:b
#define MAX(a,b) a>b?a:b
#define rep(i,a,b) for(i=a;i<b;i++)
#define rev(i,a,b) for(i=a;i>b;i--)
#define sf(a) scanf("%d",&(a))
#define pf(a) printf("%d",(a))
#define sfll(a) scanf("%lld",&(a))
#define pfll(a) printf("%lld",(a))
#define ssf(a) scanf("%s",(a))
#define spf(a) printf("%s",(a))
#define spc printf(" ");
#define nl printf("\n")
#define play int main()
#define out return
typedef int I;
typedef long long LL;
typedef char S;
typedef float F;
typedef double D;
int cmp(const void *a,const void *b)
{
    return (*(int*)a-*(int*)b);
}
play
{
    I a,b,mx=-1e5;
    sf(a),sf(b);
    mx=MAX((a+b),(a-b));
    mx=MAX(mx,(a*b));
    pf(mx);
    nl;
    out 0;
}


Measured memory_bytes: 128
#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
const int M=1e6+7;
int read(){
	int ans=0,f=1,c=getchar();
	while(c<'0'||c>'9'){if(c=='-') f=-1; c=getchar();}
	while(c>='0'&&c<='9'){ans=ans*10+(c-'0'); c=getchar();}
	return ans*f;
}
int n,k,vis[10],xs[M],xp;
void find(int x,int len){
	xs[++xp]=x;
	if(len==5) return ;
	for(int i=0;i<=9;i++)if(!vis[i]) find(x*10+i,len+1);
}
int main(){
	n=read(); k=read();
	for(int i=1;i<=k;i++) vis[read()]=1;
	for(int i=0;i<=9;i++)if(!vis[i]) find(i,1);
	sort(xs+1,xs+1+xp);
	printf("%d\n",*lower_bound(xs+1,xs+1+xp,n));
	return 0;
}

Measured memory_bytes: 512
// inputに入力データ全体が入る
function Main(input) {

  var inp = input.split(" ");
  var N = parseInt(inp[0]);
  var A = parseInt(inp[1]);
  var B = parseInt(inp[2]);

  var sum = 0;
  var ans = 0;
  var j = "0";
  var k = 0;
  var l = 0;
  var m = 0;
  var n = 0;
  for (var i = 1; i <= N; i++) {
    j = String(i);
    k = 0;
    l = 0;
    m = 0;
    n = 0;

    k = parseInt(j.substr(0, 1));

    if (i >= 10) {
      l = parseInt(j.substr(1, 1));
    }

    if (i >= 100) {
      m = parseInt(j.substr(2, 1));
    }

    if (i >= 1000) {
      n = parseInt(j.substr(3, 1));
    }
    
    sum = k + l + m + n;
    if (sum >= A && sum <= B) {
      ans += i;
    }
    

  }

  console.log('%d', ans);

}
//*この行以降は編集しないでください（標準入出力から一度に読み込み、Mainを呼び出します）
Main(require("fs").readFileSync("/dev/stdin", "utf8"));



Measured memory_bytes: 17060
#include<bits/stdc++.h>
using namespace std;
const int N=310;
char s[N]; int k,dp[N][N][N];
inline void cmax(int &x,int y){x=max(x,y);}
inline int dfs(int a,int b,int c){
	if(a==b)return 1; if(a>b)return 0;
	if(dp[a][b][c])return dp[a][b][c];
	if(s[a]==s[b])cmax(dp[a][b][c],dfs(a+1,b-1,c)+2);
	else if(c)cmax(dp[a][b][c],dfs(a+1,b-1,c-1)+2);
	cmax(dp[a][b][c],dfs(a+1,b,c));
	cmax(dp[a][b][c],dfs(a,b-1,c));
	return dp[a][b][c];
}
int main(){
	scanf("%s%d",s+1,&k); int len=strlen(s+1);
	for(int i=1; i<=len; ++i)dp[i][i][0]=1;
	int ans=0;
	for(int i=1; i<=len; ++i)
		for(int j=i; j<=len; ++j)
			cmax(ans,dfs(i,j,k));
	printf("%d",ans);
	return 0;
}

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

fn read<T: FromStr>() -> T {
    let stdin = stdin();
    let stdin = stdin.lock();
    let token: String = stdin
        //bytesのiterを生成
        .bytes()
        //それをas charでchar型に変換したiterを生成
        .map(|c| c.expect("failed to read char") as char)
        //c.is_whitespace()がfalseになるまで（つまり普通の文字が出るまで）iterを進めたiterを生成
        .skip_while(|c| c.is_whitespace())
        // !c.is_whitespace()がtrue, 即ち（普通の文字の間）iterを進め, 進んだところまでのiterを生成
        .take_while(|c| !c.is_whitespace())
        // それをcollect()してiterからStringを作る
        .collect();
    // parse()で任意の型に変換して返す。
    token.parse().ok().expect("failed to parse token")
}

fn read_one_line_to_vec() -> Vec<i32> {
    // 二桁以上の整数を入力に受け取れない・・・・。
    let stdin = stdin();
    let stdin = stdin.lock();
    let v: String = stdin
        .bytes()
        .map(|c| c.expect("failed to read char") as char)
        .skip_while(|c| c == &'\x0d' || c == &'\x0a')
        .take_while(|c| !(c == &'\x0d' || c == &'\x0a'))
        .collect();
    v.split_whitespace()
        .map(|c| { let string = c.to_string();
            string.parse::<i32>().unwrap()})
        .collect()
}

fn main() {
    // ALDS1_1_A_Insertion_Sort

    let length = read();
    let mut input_list: Vec<i32> = read_one_line_to_vec();
    print_vec(input_list.clone());

    for i in 1..length {
        let next_value: i32 = input_list[i];
        input_list.remove(i);
        for j in 0..i {
            if input_list[j] > next_value {
                input_list.insert(j, next_value);
                break;
            } else if j == i-1 {
                input_list.insert(j+1, next_value);
                break;
            }
        }
        print_vec(input_list.clone());
    }
}

fn print_vec(v: Vec<i32>) {
    let mut v_iter = v.iter();
    print!("{}", v_iter.next().as_ref().unwrap());
    for v in v_iter {
        print!(" {}", v)
    }
    println!();
}



Measured memory_bytes: 5048
#include<stdio.h>
 
int main(){
    int i,x,n;
    x=100000;
    scanf("%d",&n);
    
    for(i=0;i<n;i++){
    x*=1.05;
    if(x%1000!=0)x+=(1000-x%1000);
}
printf("%d\n",x);
return 0;
 
}

Measured memory_bytes: 592
#ifndef LOCAL
#pragma GCC optimize ("O3")
#endif

#include <bits/stdc++.h>

using namespace std;

#define sim template < class c
#define ris return * this
#define dor > debug & operator <<
#define eni(x) sim > typename \
enable_if<sizeof dud<c>(0) x 1, debug&>::type operator<<(c i) {
sim > struct rge { c b, e; };
sim > rge<c> range(c i, c j) { return {i, j}; }
sim > auto dud(c* x) -> decltype(cerr << *x, 0);
sim > char dud(...);
struct debug {
#ifdef LOCAL
~debug() { cerr << endl; }
eni(!=) cerr << boolalpha << i; ris; }
eni(==) ris << range(begin(i), end(i)); }
sim, class b dor(pair < b, c > d) {
  ris << "(" << d.first << ", " << d.second << ")";
}
sim dor(rge<c> d) {
  *this << "[";
  for (c it = d.b; it != d.e; ++it)
    *this << ", " + 2 * (it == d.b) << *it;
  ris << "]";
}
#else
sim dor(const c&) { ris; }
#endif
};
#define imie(x...) " [" #x ": " << (x) << "] "

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

constexpr int mod = 1000 * 1000 * 1000 + 7;
constexpr int odw2 = (mod + 1) / 2;

void OdejmijOd(int& a, int b) { a -= b; if (a < 0) a += mod; }
int Odejmij(int a, int b) { OdejmijOd(a, b); return a; }
void DodajDo(int& a, int b) { a += b; if (a >= mod) a -= mod; }
int Dodaj(int a, int b) { DodajDo(a, b); return a; }
int Mnoz(int a, int b) { return (ll) a * b % mod; }
void MnozDo(int& a, int b) { a = Mnoz(a, b); }
int Pot(int a, int b) { int res = 1; while (b) { if (b % 2 == 1) MnozDo(res, a); a = Mnoz(a, a); b /= 2; } return res; }
int Odw(int a) { return Pot(a, mod - 2); }
void PodzielDo(int& a, int b) { MnozDo(a, Odw(b)); }
int Podziel(int a, int b) { return Mnoz(a, Odw(b)); }
int Moduluj(ll x) { x %= mod; if (x < 0) x += mod; return x; }

template <typename T> T Maxi(T& a, T b) { return a = max(a, b); }
template <typename T> T Mini(T& a, T b) { return a = min(a, b); }

bool Trafiam(ll x, ll y, ll a, ll b, ll d) {
  a %= b;
  d %= b;
  d = __gcd(d, b);
  debug() << "Trafiam(" imie(x) imie(y) imie(a) imie(b) imie(d) ")";
  if (d == 0) {
    return x <= a and a <= y;
  }
  assert(0 <= x and x <= y and y < b);
  if (y - x + 1 >= d) return true;
  x %= d;
  y %= d;
  a %= d;
  debug() << "Trafiam(" imie(x) imie(y) imie(a) imie(b) imie(d) ")";
  if (x <= y and x <= a and a <= y) return true;
  if (x > y and (x <= a or a <= y)) return true;
  return false;
}

bool przyp() {
  ll a, b, c, d;
  cin >> a >> b >> c >> d;
  if (a < b) return false;
  if (d < b and Trafiam(0, b - d - 1, a, b, d)) return false;
  if (c + 1 < b and Trafiam(c + 1, b - 1, a, b, d)) return false;
  return true;
}

int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  int t;
  cin >> t;
  while (t--) {
    if (przyp()) cout << "Yes" << endl;
    else cout << "No" << endl;
  }
  return 0;
}


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

#define MAXN 100000

using namespace std;

int A[MAXN];

int func ( int N )
{
  int ans = 0;

  for ( int i = 0; i < N-1; ++i ) {
    if ( A[i] == i+1 ) {
      swap(A[i],A[i+1]);
      ++ans;
    }
  }

  if ( A[N-1] == N-1+1 ) {
    swap(A[N-1], A[N-2]);
    ++ans;
  }

  return ans;
}

int main()
{
  int N;

  cin >> N;

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

  cout << func(N) <<"\n";
}


Measured memory_bytes: 640
#include<iostream>
#include<iomanip>
#include<vector>
#include<map>
#include<set>
#include<stack>
#include<queue>
#include<string>
#include<utility>
#include<numeric>
#include<algorithm>
#include<cmath>
#include<climits>
using namespace std;

using ll = long long;

class Stream{
public:
    Stream(){

    }
    //配列以外の入力を受け取る
    void read(){

    }
    template<typename First, typename... Rest>
    void read(First& first, Rest&... rest){
        cin >> first;
        read(rest...);
    }
    //配列を区切って出力する
    template<typename T>
    void write_vec(vector<T>& v, char divider){
        for(size_t i = 0; i < v.size(); i++){
            cout << v[i] << divider;
        }
    }
};

int main(){
    Stream io;
    
    int X;
    io.read(X);
    if(X == 1){
        cout << 1;
        return 0;
    }
    int ans = 0;
    for(int i = 2; i * i <= X; i++){
        int b = i * i;
        while(b <= X) b *= i;
        ans = max(ans, b / i);
    }
    cout << ans;
    return 0;
}

Measured memory_bytes: 256
import sys
input=sys.stdin.readline
a, b, q = map(int, input().split())
s = []
t = []
x = []
for i in range(a):
    s.append(int(input()))
for i in range(b):
    t.append(int(input()))
for i in range(q):
    x.append(int(input()))
import bisect
def get(x):
    ls,rs,lt,rt=10**13,10**13,10**13,10**13
    s_ind = bisect.bisect_left(s,x)
    t_ind = bisect.bisect_left(t,x)
    if s_ind!=0:
        ls=abs(x - s[s_ind-1])
    if s_ind!=a:
        rs=abs(x - s[s_ind])
    if t_ind!=0:
        lt=abs(x - t[t_ind-1])
    if t_ind!=b:
        rt=abs(x - t[t_ind])
    return ls,rs,lt,rt

for que in x:
    ls,rs,lt,rt = get(que)

    rr = max(rs,rt)
    ll = max(ls,lt)
    lsrt = 2*ls+rt
    ltrs = 2*lt+rs
    rslt = 2*rs+lt
    rtls = 2*rt+ls
    ans = min([rr,ll,lsrt,ltrs,rslt,rtls])
    print(ans)

Measured memory_bytes: 82652
//
// Created by Myabu on 2020/01/26.
//

#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <map>
#include <utility>
#include <math.h>
#include <stack>
#include <queue>
#include <cstdio>
#include <numeric>
#include <iomanip>

using namespace std;


int main(void){
    int A,P;

    cin>>A>>P;

    int app = 0;

    app += P + 3*A;

    cout<<app/2<<endl;


    return 0;
}

Measured memory_bytes: 256
DIV = 100000
n, m = map(int, raw_input().split())
l = [0]*n
for i in range(n-1):
    k = input()
    l[i+1] = l[i] + k
ans = pos = 0
for _ in xrange(m):
    k = input()
    ans = (ans + abs(l[pos + k] - l[pos])) % DIV
    pos += k
print ans

Measured memory_bytes: 12652
#include<bits/stdc++.h>
using namespace std;
int a[10];
int main(){
	int n,m,x,y;scanf("%d%d",&n,&m);
	for(int i=1;i<=n;i++)a[i]=-1;
	for(int i=0;i<m;i++){
		scanf("%d%d",&x,&y);
		if(a[x]!=-1&&a[x]!=y)return puts("-1"),0;
		a[x]=y;
	}
	if(n==1)return putchar('0'+max(0,a[1])),0;
	if(a[1]==0)return puts("-1"),0;
	for(int i=1;i<=n;i++)putchar('0'+max(i==1?1:0,a[i]));
	return 0;
}

Measured memory_bytes: 256
/*input
3
10 40 70
20 50 80
30 60 90
*/

#include <functional>
#include <algorithm>
#include <iostream>
#include <string.h>
#include <utility> 
#include <iomanip>
#include <string>
#include <vector>
#include <math.h>
#include <map>
#include <set>

using namespace std;

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

const int SINF = 1000000009;
const ll INF =  1000000000000000018;

#define sp          cout << " "
#define nl          cout << "\n"
#define all(c)      (c).begin(),(c).end()
#define prec(n)     cout << fixed << setprecision(n)
#define PI          3.14159265358979323846264338327951
#define ifalse      ios_base::sync_with_stdio(false), cin.tie(NULL)

template <typename T, typename U>
ostream &operator<<(ostream &os, const pair<T, U> &p) {
  os << p.first << " " << p.second;
  return os;
}

template <typename T, typename U>
istream &operator>>(istream &is, pair<T, U> &p) {
  is >> p.first >> p.second;
  return is;
}

template <typename T>
ostream &operator<<(ostream &os, const vector<T> &v) {
  for(auto x: v) {
    os << x << " ";
  }
  return os;
}

template <typename T>
istream &operator>>(istream &is, vector<T> &v) {
  for (auto &x : v) is >> x;
  return is;
}

/******************************** START *********************************/
const int N = 100005;
vector < vector < int > > v;
int dp[N][4];

int func(int n, int prev)
{
  if(n == 0) {
    return 0;
  }
  if(dp[n][prev] > -1) {
    return dp[n][prev];
  }

  int res = 0;
  for(int i = 0; i < 3; i ++) {
    if(i == prev) continue;
    res = max(res, v[n - 1][i] + func(n - 1, i));
  }
  return dp[n][prev] = res;
}

int main()
{
  ifalse;
  int n;
  cin >> n;
  v.assign(n, vector < int >(3, 0));
  cin >> v;

  int dp[n][3] = {0};
  for(int i = 0; i < 3; i ++) {
    dp[0][i] = v[0][i];
  }  

  for(int i = 1; i < n; i ++) {
    for(int j = 0; j < 3; j ++) {
      for(int k = 0; k < 3; k ++) {
        if(j == k) continue;
        dp[i][j] = max(dp[i][j], v[i][j] + dp[i - 1][k]);
      }
    }
  }
  int res = 0;
  for(int i = 0; i < 3; i ++) {
    res = max(res, dp[n - 1][i]);
  }
  cout << res, nl;
  return 0;
}

Measured memory_bytes: 6912
#include <stdio.h>
#include <stdlib.h>
int asc(const void *a, const void *b){
    return *(char*)a-*(char*)b;
}
int main(void){
    char s[5];
    scanf("%s",s);
    qsort(s,4,sizeof(char),asc);
    if(s[0]==s[1] && s[2]==s[3] && s[0]!=s[2]) printf("Yes");
    else printf("No");
    return 0;
}

Measured memory_bytes: 128
#include<bits/stdc++.h>
using namespace std;
inline int read () {
	int num = 0;
	char c = ' ';
	bool flag = true;
	for (;c > '9' || c < '0';c = getchar())
		if (c == '-')
			flag = false;
	for (;c >= '0' && c <= '9';num = (num << 1) + (num << 3) + c - 48, c = getchar());
	return flag ? num : -num;
}
int main () {
	int t = read ();
	if (t == 1) {
		cout << "Hello World\n";
	}
	else cout << read () + read ();
	return 0;
}

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

template <class... Args>
string dbgFormat(const char* fmt, Args... args) {
  size_t len = snprintf(nullptr, 0, fmt, args...);
  char buf[len + 1];
  snprintf(buf, len + 1, fmt, args...);
  return string(buf);
}

template <class Head>
void dbgLog(Head&& head) {
  cerr << head << endl;
}

template <class Head, class... Tail>
void dbgLog(Head&& head, Tail&&... tail)
{
  cerr << head << " ";
  dbgLog(forward<Tail>(tail)...);
}

#if DEBUG
  #define DLOG(...)        dbgLog(__VA_ARGS__)
  #define DFMT(...)        cerr << dbgFormat(__VA_ARGS__) << endl
  #define DCALL(func, ...) func(__VA_ARGS__)
#else
  #define DLOG(...)
  #define DFMT(...)
  #define DCALL(func, ...)
#endif

// operator<< definitions for some classes

template <typename T1, typename T2>
ostream& operator<< (ostream& os, const pair<T1,T2>& p) {
  os << "(" << p.first << ", " << p.second << ")";
  return os;
}

template <typename T>
ostream& operator<< (ostream& os, const vector<T>& v) {
  os << '[';
  for (auto it = v.begin(); it != v.end(); it++) {
    if (it != v.begin()) os << ", ";
    os << *it;
  }
  os << ']';

  return os;
}

template <typename T, typename T2, typename T3>
ostream& operator<< (ostream& os, const priority_queue<T, T2, T3>& orig) {
  priority_queue<T, T2, T3> pq(orig);
  bool first = true;
  os << '[';
  while (!pq.empty()) {
    T x = pq.top(); pq.pop();
    if (!first) os << ", ";
    os << x;
    first = false;
  }
  return os << ']';
}


int main(int argc, char *argv[]) {
  // C-style stdio functions should not be used.
  ios_base::sync_with_stdio(false);
  cin.tie(nullptr);
  cout << setprecision(20);

  ll N;
  cin >> N;
  vector<ll> A(N), S(N+1);
  for (int i = 0; i < N; i++) {
    cin >> A.at(i);
  }
  for (int i = 0; i <= N; i++) {
    if (i == 0) S.at(i) = 0;
    else        S.at(i) = S.at(i-1) + A.at(i-1);
  }
  ll tot = S.at(N);
  int i = 0;
  for (i = 0; i < N && 2 * S.at(i) < tot; i++) {}
  if (2 * S.at(i) == tot) {
    cout << 0 << endl;
    return 0;
  }
  ll p1 = (tot - S.at(i-1)) - S.at(i-1);
  ll p2 = S.at(i) - (tot - S.at(i));
  ll p = min(p1, p2);
  DLOG(p1, p2, p);
  cout << p << endl;

  return 0;
}



Measured memory_bytes: 3456
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        boolean found = false;
        while(n>0) {
            int val = n%10;
            if(val == 7) {
                System.out.println("Yes");
                found = true;
                break;
            }
            n = n/10;
        }
        if(!found) {
            System.out.println("No");
        }
    }
}


Measured memory_bytes: 35884
import sys

sys.setrecursionlimit(10 ** 8)

input = sys.stdin.readline


def main():
    N = int(input())
    P = [int(input()) for _ in range(N)]

    dp = [0] * (N + 1)

    for p in P:
        dp[p] = dp[p - 1] + 1

    print(N - max(dp))


if __name__ == '__main__':
    main()


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

int main() {
  	int N,L;
  	cin >> N >> L;
  
  	string S;
  	vector<string> vec(N);
  
  	for(int i = 0; i < N; i++) {
    	cin >> vec.at(i);
    }
  
  	sort(vec.begin(),vec.end());
  	
 	for(int i = 0; i < N; i++) {
    	cout << vec.at(i);
    }
  
}

Measured memory_bytes: 256
void main()
{
    string t = rdStr;

    string s;
    foreach (x; t)
    {
        if (x == 'P' || x == 'D') s ~= x;
        else s ~= 'D';
    }

    s.writeln;
}

enum long mod = 10L^^9 + 7;
enum long inf = 1L << 60;
enum double eps = 1.0e-9;

T rdElem(T = long)()
if (!is(T == struct))
{
    return readln.chomp.to!T;
}

alias rdStr = rdElem!string;
alias rdDchar = rdElem!(dchar[]);

T rdElem(T)()
if (is(T == struct))
{
    T result;
    string[] input = rdRow!string;
    assert(T.tupleof.length == input.length);
    foreach (i, ref x; result.tupleof)
    {
        x = input[i].to!(typeof(x));
    }
    return result;
}

T[] rdRow(T = long)()
{
    return readln.split.to!(T[]);
}

T[] rdCol(T = long)(long col)
{
    return iota(col).map!(x => rdElem!T).array;
}

T[][] rdMat(T = long)(long col)
{
    return iota(col).map!(x => rdRow!T).array;
}

void rdVals(T...)(ref T data)
{
    string[] input = rdRow!string;
    assert(data.length == input.length);
    foreach (i, ref x; data)
    {
        x = input[i].to!(typeof(x));
    }
}

void wrMat(T = long)(T[][] mat)
{
    foreach (row; mat)
    {
        foreach (j, compo; row)
        {
            compo.write;
            if (j == row.length - 1) writeln;
            else " ".write;
        }
    }
}

import std.stdio;
import std.string;
import std.array;
import std.conv;
import std.algorithm;
import std.range;
import std.math;
import std.numeric;
import std.mathspecial;
import std.traits;
import std.container;
import std.functional;
import std.typecons;
import std.ascii;
import std.uni;
import core.bitop;

Measured memory_bytes: 3192
N, M = map(int, input().split())
ab = [list(map(int, input().split())) for _ in range(N)]
ab.sort(key=lambda x: x[0])
money = 0

for i in range(N):
    m = ab[i][1]
    if m <= M:
        money += ab[i][0] * ab[i][1]
        M -= m
    else:
        money += ab[i][0] * M
        break
print(money)

Measured memory_bytes: 29024
n,k = map(int,input().split())
h = list(map(int,input().split()))
dp = [0]
for i in range(n-1):
    cnt = float("inf")
    for j in range(k):
        if i-j < 0: continue
        cnt = min(dp[-1-j] + abs(h[i-j]-h[i+1]), cnt)
        #print("i =",i,"j =",j,"i-j =",i-j,"i+j =",i+j,"cnt =",cnt)
    dp.append(cnt)
print(dp[-1])

Measured memory_bytes: 85264
#include<iostream>
#include<vector>
#include<algorithm>
#include<string>
using namespace std;
int main(){
    int A,B;
    cin >> A >> B;
    if(A < 2*B){
        cout << 0 << endl;
    }
    else{
        cout << A-2*B << endl;
    }
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define pb push_back
#define COUT(x) cout << (x) << endl
#define ENDL cout << endl
#define DF(x) x.erase(x.begin());  // 先頭文字削除
#define debug(x) cout << "[debug] " << #x << ": " << x << endl
using namespace std;
using ll = long long;
using P = pair<int, int>;
const int INF = 1000000000;

int main() {
    int N;
    cin >> N;
    map<string, bool> m;
    int count = 0;
    rep(i, N) {
        string s;
        cin >> s;
        if (m[s]) {
            continue;
        } else {
            m[s] = true;
            count++;
        }
    }
    COUT(count);
    return 0;
}

Measured memory_bytes: 19184
#include <iostream>
#include <map>
#include <algorithm>
#include <string>
#include <vector> 
#include <numeric>
#include <cmath>
#include <queue>
#include <iomanip>
#include <functional>

#define CHMAX(a,b) a = std::max(a,b)
#define CHMIN(a,b) a = std::min(a,b)
#define MAXMIN(a,b,c) std::max(a,min(b,c))
#define CHABS(a) a = std::abs(a) 
#define COUT(a) std::cout << a << std::endl
#define CERR(a) std::cerr << a << std::endl
#define FOR(n) for(lli i = 0; i < n; i++)

using namespace std;
using lli = long long int;
using pll = pair<lli, lli>;
using tlll = tuple<lli, lli, lli>;
using vll = vector<lli>;

lli mod197 = 1000000007LL;
lli INF = 10000000000000;

// ax + by = gcd(a,b) 最大公約数
template< typename T >
T extgcd(T a, T b, T& x, T& y) {
	T d = a;
	if (b != 0) {
		d = extgcd(b, a % b, y, x);
		y -= (a / b) * x;
	}
	else {
		x = 1;
		y = 0;
	}
	return d;
}


int main(void) {

	string s;
	cin >> s;

	for (int i = 0; i < s.size(); i++) {
		if (i % 2 == 1 && s[i] == 'R') {
			COUT("No");
			return 0;
		}
		else if (i % 2 == 0 && s[i] == 'L') {
			COUT("No");
			return 0;
		}
	}

	COUT("Yes");

	return 0;
}


Measured memory_bytes: 256
#include<stdio.h>
int main(void)
{
	int n,c[10]={0},i,a,j;
	while(1){
		scanf("%d",&n);
		if(n==0){
		break;
		}
		for(i=1;i<=n;i++)
		{
			scanf("%d",&a);
			c[a]++;
		}
		for(i=0;i<10;i++)
		{
			if(c[i]>0){
			for(j=1;j<=c[i];j++){
			printf("*");
			}
		}
			else{
				printf("-");
			}
			printf("\n");
		}
		for(i=0;i<10;i++)
		{
			c[i]=0;
		}
	}
return 0;
}


Measured memory_bytes: 2044
import io.StdIn._

object Main extends App {
  val n   = readInt()
  val seq = readLine().split(" ").map(_.toInt).toSeq

  require(2 <= n && n <= 100)
  require(seq.forall(_ <= 100000))

  println(
    seq.zipWithIndex
      .foldLeft(Seq.empty[Int])((s, a) => seq.lift(a._2 - 1).map(b => s.appended(b.min(a._1))).getOrElse(Seq(a._1)))
      .sum + seq.last
  )
}


Measured memory_bytes: 58552