akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
/*#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>*/
 
#define pll              pair <long long,long long>
#define pb               push_back
#define ll               long long
#define ff               first
#define ss               second
#define D(x)             cerr<<#x " = "<<(x)<<endl
#define vll              vector <ll>
#define IOS              ios_base::sync_with_stdio(0); cin.tie(NULL);
#define endl             '\n'   
using namespace std;
int main()
{
    IOS
     // freopen("input.txt","r",stdin);
     // freopen("output.txt","w",stdout);
     // freopen("error.txt","w",stderr);
        ll n;
        cin>>n;
        ll ans=0;
        map<ll,ll>f;
        for(ll i=0;i<n;i++)
        {
            ll x;
            cin>>x;
            f[x]++;
            ans+=x;
        }
        ll q;
        cin>>q;
        for(ll i=0;i<q;i++)
        {
            ll b,c;
            cin>>b>>c;
            ans-=f[b]*(b-c);
            f[c]+=f[b];
            f[b]=0;
            cout<<ans<<endl;
        }
    return 0;
}

Measured memory_bytes: 9564
#include <cstdio>
#include <queue>
#include <vector>
#include <algorithm>
#include <cstring>
using namespace std;

#define INF (1<<28)
#define SOUR (L+L)
#define SINK (L+L+1)

bool flow[2005][2005];
bool DAG[1005][1005];
int L,v[2020];

class Node
{
public:
	vector<int> to;
};

void Connect(vector<Node>& node, int src, int dst)
{
	flow[dst][src]=1;
	node[src].to.push_back(dst);
	node[dst].to.push_back(src);
}

int dfs(int p, int T, int mf, vector<Node>& graph, vector<int>& level, vector<bool>& finished)
{
	if(p==T) return mf;
	if(finished[p]) return 0;
	
	finished[p]=true;
	
	for(int i=0; i<graph[p].to.size(); i++)
	{
		int next=graph[p].to[i], fw=(flow[p][next]?0:1);
		
		//if(p==SOUR) fw=1;
		if(level[p] >= level[next]) continue;
		if(fw <=0 ) continue;
	
		int f=dfs(next, T, min(mf, fw), graph, level, finished);
		if(f>0)
		{
			finished[p]=false;
			flow[p][next]=1;
			flow[next][p]=0;
			return f;
		}
	}
	
	return 0;
}

int dinic(int S, int T, vector<Node>& graph)
{
	bool end=false;
	int total=0;
	while(!end)
	{
		end=true;
		vector<int> level(graph.size(), -1);
		level[S]=0;
		
		queue<int> q;
		q.push(S);
		while(!q.empty())
		{
			int n=q.front(); q.pop();
			for(int i=0; i<graph[n].to.size(); i++)
			{
				int next=graph[n].to[i];
				if(level[next]!=-1) continue;
				if(flow[n][next]) continue;
				level[next]=level[n]+1;
				q.push(next);
			}
		}
		
		if(level[T]==-1) break;
		
		vector<bool> finished(graph.size());
		while(1)
		{
			int fw=dfs(S, T, INF, graph, level, finished);
			if(fw<=0) break;
			
			total+=fw;
			end=false;
		}
	}
	
	return total;
}

int main()
{
	int N,M;
	while(scanf("%d%d%d", &N,&M,&L), (N||M||L))
	{
		int d[105][105];
		for(int i=0; i<N; i++)
		for(int j=0; j<N; j++)
		{
				d[i][j]=INF;
				d[i][i]=d[j][j]=0;
		}

		for(int i=0; i<M; i++)
		{
			int u,v,c;
			scanf("%d%d%d", &u,&v,&c);
			d[u][v]=c;
			d[v][u]=c;
		}
		
		for(int k=0; k<N; k++)
		for(int i=0; i<N; i++)
		for(int j=0; j<N; j++)
		{
			d[i][j]=min(d[i][j], d[i][k]+d[k][j]);
		}
		

		int s[1005],t[1005];
		for(int i=0; i<L; i++)
		{
			scanf("%d%d", &s[i], &t[i]);
		}

		memset(flow, 0, sizeof(flow));
		memset(DAG, 0, sizeof(DAG));

		vector<Node> node(SINK+1);

		bool beg[1005]={0}, end[1005]={0};
		for(int i=0; i<L; i++)
		{
			Connect(node, SOUR, i);
			Connect(node, L+i, SINK);
			
			for(int j=0; j<L; j++)
			{
				if(i==j) continue;
				if(d[s[i]][s[j]] + t[i] <= t[j])
				{
					Connect(node, i, L+j);
				}
			}
		}
		
		printf("%d\n", L-dinic(SOUR,SINK,node));
	}
}

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

int main() {
	int K, X;
	cin >> K >> X;
	cout << X-K+1;
	for(int i=X-K+2; i<=X+K-1; ++i) cout << ' ' << i;
	cout << endl;
	return 0;
}


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

#define ll long long int
#define str string
#define ALL(a)  (a).begin(),(a).end()
#define P pair<ll,ll>

using Graph = vector<vector<int>>;

const int dy[] = { 0, 0, 1, -1 }, dx[] = { 1, -1, 0, 0 };
ll INFL = 1ll << 60, INF = 1 << 30, mod = 1e9 + 7, Min = INFL, Max = -1;
ll a, b, c, n, sum, A[500010], B[500000], rui[500000], dp[5000];
str S, T, U; bool check = true;	vector<ll> v;



int main() {
	//Code Line
	cin >> S;
	if (S == "AAA")cout << "No" << endl;
	else if (S == "BBB")cout << "No" << endl;
	else cout << "Yes" << endl;



	return 0;
}


Measured memory_bytes: 256
import numpy as np

A, B, H, M = map(int, input().split())

hangle = (H * 60 + M) / (12 * 60) * (2 * np.pi)
mangle = M / 60 * (2 * np.pi)

print(np.sqrt(A ** 2 + B ** 2 - 2 * A * B * np.cos(np.abs(hangle - mangle))))

Measured memory_bytes: 27196
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int a,b,c;
    cin>> a >> b >> c;
    if((a==b&&a!=c)||(a==c&&a!=b)||(b==c&&a!=c)){
        cout<<"Yes"<<endl;
    }
   else{
         cout<<"No"<<endl;
    }
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef unsigned long long int ull;
typedef long long int ll;
typedef pair<ll,ll> pll;
typedef long double D;
//typedef complex<D> P;
#define F first
#define S second
const ll MOD=1000000007;
//const ll MOD=998244353;

template<typename T,typename U>istream & operator >> (istream &i,pair<T,U> &A){i>>A.F>>A.S; return i;}
template<typename T>istream & operator >> (istream &i,vector<T> &A){for(auto &I:A){i>>I;} return i;}
template<typename T,typename U>ostream & operator << (ostream &o,const pair<T,U> &A){o<<A.F<<" "<<A.S; return o;}
template<typename T>ostream & operator << (ostream &o,const vector<T> &A){int i=A.size(); for(auto &I:A){o<<I<<(--i?" ":"");} return o;}



int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  ll H,W,h,w;
  cin>>H>>W>>h>>w;
  if(H%h==0 && W%w==0){cout<<"No"<<endl; return 0;}
  cout<<"Yes"<<endl;
  const ll uku=1e6;
  vector<vector<ll>> A(H,vector<ll>(W,uku));
  if(H%h!=0){
    for(int i=h-1;i<H;i+=h){
      for(auto &I:A[i]){I=-(h-1)*uku-1;}
    }
  }
  else{
    for(int j=w-1;j<W;j+=w){
      for(int i=0;i<H;i++){
        A[i][j]=-(w-1)*uku-1;
      }
    }
  }
  for(auto &I:A){cout<<I<<endl;}
  


  return 0;
}


Measured memory_bytes: 4352
#include <bits/stdc++.h>
using namespace std;
int main(){
  int64_t st,max,ct=0;
  cin>>st>>max;

  while(true){
    ct++;
    st*=2;
    if(st>max){
      break;
    }
  }

  cout<<ct<<endl;



  return 0;
}


Measured memory_bytes: 256
package main

// Solution for https://atcoder.jp/contests/abc068/tasks/abc068_a

import (
	"bufio"
	"fmt"
	"io"
	"os"
)

type contest struct {
	in  io.Reader
	out io.Writer
}

func (con *contest) Scan(a ...interface{}) (int, error) {
	return fmt.Fscan(con.in, a...)
}
func (con *contest) Scanln(a ...interface{}) (int, error) {
	return fmt.Fscanln(con.in, a...)
}
func (con *contest) Scanf(f string, a ...interface{}) (int, error) {
	return fmt.Fscanf(con.in, f, a...)
}
func (con *contest) Print(a ...interface{}) (int, error) {
	return fmt.Fprint(con.out, a...)
}
func (con *contest) Println(a ...interface{}) (int, error) {
	return fmt.Fprintln(con.out, a...)
}
func (con *contest) Printf(f string, a ...interface{}) (int, error) {
	return fmt.Fprintf(con.out, f, a...)
}
func main() {
	in := bufio.NewReader(os.Stdin)
	out := bufio.NewWriter(os.Stdout)
	defer out.Flush()
	con := &contest{in: in, out: out}
	con.main()
}

func (con *contest) main() error {
	var s string
	con.Scan(&s)
	con.Println("ABC" + s)
	return nil
}


Measured memory_bytes: 640
#include<iostream>
#include<iomanip>
#include<cctype>
#include<string>

using namespace std;

int main()
{
    int i,j,num;
    int counter[26];
    char ch;
    string s;
    for(i = 0;i < 26;i++){
        counter[i] = 0;
    }
    while(cin >> ch){
        if(ch >= 'a' && ch <= 'z' || ch >= 'A' && ch <= 'Z'){
            if(isupper(ch)) ch = tolower(ch);
            num = ch - 'a';
            counter[num]++;
        }
    }
    for(i = 0;i < 26;i++){
        cout << (char)(i+'a') << " : " << counter[i] << endl;
    }

    return 0;
}


Measured memory_bytes: 3092
import java.util.Scanner;
 
public class Main {
    public static void main(String[] args) {
        Scanner scan = new Scanner(System.in);
        String A = scan.next();
        int a = Integer.parseInt(A);
        String B = scan.next();
        int b = Integer.parseInt(B);
        String H = scan.next();
        int h = Integer.parseInt(H);
        String M = scan.next();
        int m = Integer.parseInt(M);

        double angle = Math.abs((30 * h + 0.5 * m) - 6 * m);
        double cos = Math.cos(Math.toRadians(angle));

        double ans;
        if (angle == 0) {
            ans = Math.abs(a - b);
        } else {
            ans = Math.sqrt((a * a) + (b * b) - (2 * a * b * cos));
        }

        System.out.println(ans);
    }
}

Measured memory_bytes: 35728
#include <bits/stdc++.h>
#include<stdio.h>
#include<string.h>
//char s[2000000];

using namespace std;

#define ll long long
#define pi pair<ll,ll>
 
vector<ll>v[200005];
ll arr[500005];
ll brr[500005];
//char str[2000000]; 
map<char,ll>mp;
//map<char,ll>cnt;
ll digits[13];
vector<string>names;
//vector<ll>cnt;
int main()
{
   ll i,j,k,l,p,q,r,s=1,t,n,money,x,y,solve;
   string str1,str2;
   cin>>n;
   cin>>str1>>str2;
   for(i=0;i<n;i++)
   {
      cout<<str1[i]<<str2[i];	
   }
  
   	
}

Measured memory_bytes: 6656
#include <algorithm>
#include <bitset>
#include <climits>
#include <cmath>
#include <cstdio>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <unordered_map>
#include <vector>

#define MOD 1000000007
#define MOD2 998244353
#define int long long
#define EPS 1e-9
//#define PI 3.14159265358979

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

using namespace std;

template < typename T >
ostream &operator<<(ostream &os, const vector< T > &A) {
	for (int i = 0; i < A.size(); i++)
		os << A[i] << " ";
	os << endl;
	return os;
}
template <>
ostream &operator<<(ostream &os, const vector< vector< int > > &A) {
	int N = A.size();
	int M;
	if (N > 0)
		M = A[0].size();
	for (int i = 0; i < N; i++) {
		for (int j = 0; j < M; j++)
			os << A[i][j] << " ";
		os << endl;
	}
	return os;
}

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

struct edge {
	int from, to, d, c;
	edge(int _from = 0, int _to = 0, int _d = 0, int _c = 0) {
		from = _from;
		to = _to;
		d = _d;
		c = _c;
	}
	bool operator<(const edge &rhs) const {
		return (d == rhs.d) ? (c < rhs.c) : (d < rhs.d);
	}
};
struct aabb {
	int x1, y1, x2, y2;
	aabb(int x1, int y1, int x2, int y2) : x1(x1), y1(y1), x2(x2), y2(y2) {}
};

typedef vector< edge > edges;
typedef vector< edges > graph;
struct flow {
	int to, cap, rev, cost;
	flow(int to = 0, int cap = 0, int rev = 0, int cost = 0) : to(to), cap(cap), rev(rev), cost(cost) {}
};
typedef vector< vector< flow > > flows;

const int di[4] = {0, -1, 0, 1};
const int dj[4] = {-1, 0, 1, 0};
const int ci[5] = {0, 0, -1, 0, 1};
const int cj[5] = {0, -1, 0, 1, 0};
const ll LINF = LLONG_MAX / 2;
const int INF = INT_MAX / 2;
const double PI = acos(-1);

int pow2(int n) { return 1LL << n; }
template < typename T, typename U >
bool chmin(T &x, const U &y) {
	if (x > y) {
		x = y;
		return true;
	}
	return false;
}
template < typename T, typename U >
bool chmax(T &x, const U &y) {
	if (x < y) {
		x = y;
		return true;
	}
	return false;
}

struct initializer {
	initializer() {
		cout << fixed << setprecision(20);
	}
};
initializer _____;

int N, M, K, T, Q, H, W;
signed main() {
	cin >> N;
	vector< int > A(N), B(N);
	rep(i, N) cin >> A[i];
	rep(i, N) cin >> B[i];
	vector< int > ans(51, 0);
	for (int k = 50; k >= 0; k--) {
		vector< vector< int > > G(51, vector< int >(51, LINF));
		rep(i, 51) G[i][i] = 0;
		for (int i = 1; i <= 50; i++)
			if (i <= k || ans[i] == 1) {
				for (int j = 1; j <= 50; j++)
					G[j][j % i] = 1;
			}
		rep(k, 51) rep(i, 51) rep(j, 51) chmin(G[i][j], G[i][k] + G[k][j]);
		bool f = false;
		rep(i, N) if (G[A[i]][B[i]] == LINF) f = true;
		if (f && k == 50) {
			cout << -1 << endl;
			return 0;
		}
		if (f)
			ans[k + 1] = 1;
	}
	int ans2 = 0;
	for (int i = 1; i <= 50; i++)
		if (ans[i])
			ans2 += (1LL << i);
	cout << ans2 << endl;
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define REP(i, N) for (int i = 0; i < (N); ++i)
#define ALL(x) (x).begin(), (x).end()
ll gcd(ll x, ll y) { return y ? gcd(y, x % y) : x; }
ll div_ceil(ll, ll);

int main() {
  string S;
  std::cin >> S;
  int N = S.size();
  std::vector<int> v(N), b(N), w(N);
  REP(i, N) {
    if (S.at(i) == '0') {
      v.at(i) = 0;
    } else {
      v.at(i) = 1;
    }
    if (i % 2 == 0) {
      b.at(i) = 0;
      w.at(i) = 1;
    } else {
      b.at(i) = 1;
      w.at(i) = 0;
    }
  }
  ll b_count = 0, w_count = 0;
  REP(i, N) {
    if (v.at(i) != b.at(i)) {
      b_count++;
    }
    if (v.at(i) != w.at(i)) {
      w_count++;
    }
  }
  std::cout << min(b_count, w_count) << '\n';
  // REP(i, N) { std::cout << b.at(i) << '\n'; }
  // REP(i, N) { std::cout << w.at(i) << '\n'; }
  // REP(i, N) { std::cout << v.at(i) << '\n'; }
  // std::cout << b_count << w_count << '\n';
}

ll div_ceil(ll a, ll b) {
  ll quotient = a / b;
  ll remainder = a % b;
  if (remainder == 0) {
    return quotient;
  } else {
    return quotient + 1;
  }
}


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

int main(){
  while(1){
    int E;
    cin >> E;
    if(E==0) break;
    int x=0,y=0,z=0;
    int m = 1000000;
    for(z=0;z*z*z<=E;z++){
      for(y=0;(z*z*z)+(y*y)<=E;y++){
	x=E-(z*z*z)-(y*y);
	if(x+y+z<m){
	  m=x+y+z;
	  //cout << x << y << z << endl;
	}
      }
    }
    cout << m << endl;	
  }
  
}

Measured memory_bytes: 1160
#include <iostream>
#include <algorithm>
#include <cmath>
#include <vector>
#include <string>
#include <queue>
#include <tuple>
#include <functional>
using namespace std;

int N, K, a[100009], minx = (1 << 30);

int main() {
	cin >> N >> K;
	for (int i = 0; i < N; i++) cin >> a[i];
	sort(a, a + N);
	for (int i = 0; i <= N - K; i++) minx = min(minx, a[i + K - 1] - a[i]);
	cout << minx << endl;
	return 0;
}

Measured memory_bytes: 640
#include <algorithm>
#include <iostream>
#include <map>
#include <numeric>
#include <set>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <vector>
#include <queue>
#define MOD (1000000007l)
#define rep(i, n) for(long i = 0; i < (n); i++)

using namespace std;

long N, M;
vector<pair<long, long>> ab;

long union_find_find(long node, vector<long> &vec) {
  if (vec[node] == 0) return node;
  long root = union_find_find(vec[node], vec);
  vec[node] = root;
  return root;
}

void union_find_union(long a, long b, vector<long> &vec) {
  long aroot = union_find_find(a, vec);
  long broot = union_find_find(b, vec);
  if (aroot == broot) return;
  vec[aroot] = broot;
}

bool foo(long m) {
  vector<long> vec(N+1, 0);
  rep (i, M) {
    if (i == m) continue;
    union_find_union(ab[i].first, ab[i].second, vec);
  }
  return union_find_find(ab[m].first, vec) != union_find_find(ab[m].second, vec);
}

void solve() {
  cin >> N >> M;
  rep (i, M) {
    long a, b;
    cin >> a >> b;
    ab.push_back(make_pair(a, b));
  }
  long ans = 0;
  rep (i, M) if (foo(i)) ans++;
  cout << ans << endl;
}

int main(void) {
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout.precision(12);
  solve();
  return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
#define REP(i, a, b) for(int i = (a); i < (b); ++i)
const ll mod = 1e9 + 7;

int main()
{
    ll N;
    cin >> N;
    ll res = 1;
    for(ll i = 1; i <= N; ++i) res *= i, res %= mod;
    cout << res << endl;
    return 0;
}

Measured memory_bytes: 256
/*
  AOJ 0584
  Title:
  @kankichi573
*/
#include <stdio.h>
#include <limits.h>

int result[3];
int least[4];

int pow_10(int n)
{
        if(n==0)
                return(1);
        else
                return(10*(pow_10(n-1)));
}

int log_10(int n) //ketasuu 
{
        if(n<10)
                return(1);
        else
                return(1+log_10(n/10));
}
int num_cat(int n1,int n2)
{
        return(n1*pow_10(log_10(n2))+n2);
}
update_cat(int n)
{
        //printf("u:%d\n",n);


        if(n < result[0])
        {
                result[2]=result[1];
                result[1]=result[0];
                result[0]=n;
        }
        else if(n < result[1])
        {
                result[2]=result[1];
                result[1]=n;
        }
        else if(n < result[2])
                result[2]=n;
}

update_least(int n)
{
        //printf("u:%d\n",n);

        if(n < least[0])
        {
                least[3]=least[2];
                least[2]=least[1];
                least[1]=least[0];
                least[0]=n;
        }
        else if(n < least[1])
        {
                least[3]=least[2];
                least[2]=least[1];
                least[1]=n;
        }
        else if(n < least[2])
        {
                least[3]=least[2];
                least[2]=n;
        }
        else if(n < least[3])
                least[3]=n;
}

init()
{
        result[0]=result[1]=result[2]=INT_MAX;
        least[0] =least[1] =least[2] =least[3] =INT_MAX;
}
main()
{
        int i,j,n,num;

        init();

        scanf("%d",&n);

        for(i=0;i<n;i++)
        {
                scanf("%d",&num);
                update_least(num);
        }
        for(i=0;i<4;i++)
                for(j=0;j<4;j++)
                {
                        if(i!=j)
                                update_cat(num_cat(least[i],least[j]));
                }

        //printf("%d\n",result[0]);
        //printf("%d\n",result[1]);
        printf("%d\n",result[2]);

        return(0);
}

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

typedef long long ll;
typedef pair<int, int> pi;

#define rep(i, n) for (int i = 0; i < n; i++)
#define rep_op(i, a, n) for (int i = a; i < n; i++)
#define rep_d(j, n) for (int j = n; j >= 0; j--)
#define rep_d_op(j, n, a) for (int j = n; j >= a; j--)

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;
}

const int MOD = 1000000007;

const vector<int> dx = {1, 0};
const vector<int> dy = {0, 1};
const ll INF = 1LL << 60;

// int max = *std::max_element(vec.begin(), vec.end());
// int sum = accumulate(list, list + size, 0);

int GCD(int a, int b) { return b ? GCD(b, a % b) : a; }

int main()
{
    ll n;
    cin >> n;
    ll ans = 0;
    for (int i = 1; i <= n; i++)
    {
        for (int j = 1; j <= n; j++)
        {
            for (int k = 1; k <= n; k++)
            {
                ans += GCD(i, GCD(j, k));
            }
        }
    }

    cout << ans << endl;
}


Measured memory_bytes: 3600
#include <bits/stdc++.h>
#include <iostream>
#include <math.h>    //pow(x,y)=x^y 99999とかの場合+1するif文
#include <algorithm> //sort(a.begin(), a.end());reverse(a.begin(), a.end());
#define rep(init, i, n) for (int i = init; i < (n); i++)
#define ll long long
#define rev(s) reverse(s.begin(), s.end())
#define sor(v) sort(v.begin(), v.end())
//コード自動整形 Shift + Option + F @vscode
using namespace std;

/////main/////
int main()
{
    ll N;
    cin >> N;

    vector<ll> A(N);
    vector<ll> summod(N-1);

    rep(0, i, N)
    {
        cin >> A.at(i);
    }

    ll output = 0;
    ll modbs = 1000000007;
    
    summod.at(N-2) = A.at(N-1);

    for(int i = N-3; i >= 0; --i){
        summod.at(i) = summod.at(i+1) + A.at(i+1);
        //cout<<"summod1.at("<<i<<")"<<summod.at(i)<<endl;//
        summod.at(i) %= modbs; 
    }
    //rep(0,i,N-1){//
        //cout<<"summod.at("<<i<<")"<<summod.at(i)<<endl;//
    //}//

    rep(0,i,N-1){
        output += A.at(i)*summod.at(i);
        //cout<<"output"<<output<<endl;//
        output %= modbs;
        //cout<<"outputmoded"<<output<<endl;//
    }

    cout<<output<<endl;

}
/////main/////

/////function/////

Measured memory_bytes: 6360
#include<bits/stdc++.h>
using namespace std;
int n;
int dp[100005];
int cost(int a[],int p)
{
    
    if(dp[p]!=-1)
    return dp[p];

    if(p>=n-1)
    return 0;

    if(p<n-2)
    return dp[p]=min(abs(a[p+1]-a[p])+cost(a,p+1) , (abs(a[p+2]-a[p])+cost(a,p+2) ));
    else
    return abs(a[p+1]-a[p]);
    /*if(p==n-3)
    return min(abs(a[p+2]-a[p]),abs(a[p+1]-a[p]));/*/
   
    
    
}

int main()
{
    cin>>n;
    int a[n];
    for(int i=0;i<n;++i)
    cin>>a[i];
    memset(dp,-1,sizeof(dp));
    cout<<cost(a,0)<<endl;
}

Measured memory_bytes: 4864
#include<bits/stdc++.h>
using namespace std;
#define ll long long
int main(){
	#ifndef ONLINE_JUDGE
	freopen("input.txt","r",stdin);
	freopen("output.txt","w",stdout);
	#endif
	int n;
	cin>>n;
	int a[100][2];
	for(int i=0;i<n;i++)
	{
		cin>>a[i][0]>>a[i][1];
	}
	for(int i=0;i<n-2;i++)
	{
		if(a[i][0]==a[i][1] && a[i+1][0]==a[i+1][1] && a[i+2][0]==a[i+2][1])
		{
			cout<<"Yes";
			return 0;
		}
	}
	cout<<"No";




	
}

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

vector<string> ans;
int K;

void dfs(string s, int depth) {
    if (depth == K) {
        ans.push_back(s);
        return;
    }
    vector<bool> use(26, false);
    for (char c : s) {
        use[c-'a'] = true;
    }
    int n = 0;
    while (n == 0 || use[n-1]) {
        string t = s;
        t += (char)('a' + n);
        dfs(t, depth+1);
        n++;
    }
    return;
}

int main() {
    cin >> K;
    dfs("", 0);
    sort(ans.begin(), ans.end());
    for (string s : ans) {
        cout << s << endl;
    }
    return 0;
}

Measured memory_bytes: 9588
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
sys.setrecursionlimit(10 ** 7)

a, b, c, d = map(int, readline().split())
for i in range(10000):
    c -= b
    if c <= 0:
        print('Yes')
        break
    a -= d
    if a <= 0:
        print('No')
        break


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

int m[3] = {0};

int is(double a){
	if(abs(a) < EPS)return 1;
	if(a < 0)return 0;
	if(a > 0)return 2;
}

double mysqrt(double x){
	double l = 0 , r = x;
	for(int i = 0 ; i < 256 ; i++){
		double m = (l+r) / 2.0;
		if(m * m < x) l = m;
		else r = m;
	}
	return l;
}

double solve(double a,double b,double c,double d){
	//cout << a << " " << b << " " << c << " " << d << endl;
	if(a < 0){ a *= -1; b *= -1; c *= -1; d *= -1;}
	if(abs(a) < EPS){
		if(c * c - 4 * b * d < -EPS)return 0.0;
		double one = ( -c + mysqrt(c*c-4*b*d)  )/(2*b);
		double two = ( -c - mysqrt(c*c-4*b*d)  )/(2*b);
		//cout << one << "<>" << two << endl;
		m[is(one)]++;
		m[is(two)]++;
		return 0.0;
	}
	
	double l = -1000.0 , r = 1000.0;
	for(int i=0;i<256;i++){
		double x = (l+r)/2.0;
		double res = a*x*x*x+b*x*x+c*x+d;
		if(res>0){
			r = x;
		}else{
			l = x;
		}
	}
	if(l >= 1000-EPS || l <= -1000+EPS)return 0.0;
	return l;
}
int main(){
	int N; cin >> N;
	while(N--){
		int a,b,c,d;
		cin >> a >> b >> c >> d;
		m[0] = m[1] = m[2] = 0;
		double n = solve(a,b,c,d);
			m[is(n)]++;
		//cout << n << endl;
		solve(0,a,a*n+b,n*(a*n+b)+c);	
		cout << m[2] << " " << m[0] << endl;
	}
}

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

int main() {
  bool cards[4][14];
  for (int i = 0; i < 4; i++) {
    for (int j = 1; j <= 13; j++) {
      cards[i][j] = false;
    }
  }
  /*
  ??\?????????????????????????????§?????????
  0: S
  1: H
  2: C
  3: D
  */

  int n, cardNum;
  char type;
  cin >> n;

  // ??????????????¶????????¨?????\???????????????
  for (int i = 0; i < n; i++) {
    char type;
    cin >> type >> cardNum;

    if (type == 'S') cards[0][cardNum] = true;
    if (type == 'H') cards[1][cardNum] = true;
    if (type == 'C') cards[2][cardNum] = true;
    if (type == 'D') cards[3][cardNum] = true;
  }

  // ????????????????????????
  for (int i = 0; i < 4; i++) {
    for (int j = 1; j <= 13; j++) {
      if (cards[i][j]) continue;
      if (i == 0) type = 'S';
      if (i == 1) type = 'H';
      if (i == 2) type = 'C';
      if (i == 3) type = 'D';
      cout << type << " " << j << endl;
    }
  }

  return 0;
}

Measured memory_bytes: 1160
#include <bits/stdc++.h>
using namespace std;
int main(){
    int a, b;
    cin >> a >> b;
    int cnt=0;
    for(int i=a; i<=b; i++){
        int d5 = i%10;
        int d4 = (i%100)/10;
        int d3 = (i%1000)/100;
        int d2 = (i%10000)/1000;
        int d1 = i/10000;
        if(d1==d5 && d2==d4) cnt++;
    }
    cout << cnt << endl;
    return 0;
}

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

namespace AtCoder
{
    public class Prog
    {
        public static void Main(string[] args)
        {
            var sw = new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false };
            Console.SetOut(sw);
            new Prog().Solve(new ConsoleInput(Console.In, ' '));
            Console.Out.Flush();
        }

        public void Solve(ConsoleInput cin)
        {
            var n = cin.ReadInt;
            var k = cin.ReadInt;
            var s = cin.ReadLine;

            var ans = string.Empty;

            for (int i = 0; i < s.Length; i++)
            {
                var c = s[i].ToString();
                if (i == k - 1)
                {
                    c = c.ToString().ToLower();
                }
                ans += c;
            }

            Console.WriteLine(ans);
        }
    }

    public class ConsoleInput
    {
        private readonly System.IO.TextReader _stream;
        private char _separator = ' ';
        private Queue<string> inputStream;
        public ConsoleInput(System.IO.TextReader stream, char separator = ' ')
        {
            this._separator = separator;
            this._stream = stream;
            inputStream = new Queue<string>();
        }
        public string Read
        {
            get
            {
                if (inputStream.Count != 0) return inputStream.Dequeue();
                string[] tmp = _stream.ReadLine().Split(_separator);
                for (int i = 0; i < tmp.Length; ++i)
                    inputStream.Enqueue(tmp[i]);
                return inputStream.Dequeue();
            }
        }
        public string ReadLine { get { return _stream.ReadLine(); } }
        public int ReadInt { get { return int.Parse(Read); } }
        public long ReadLong { get { return long.Parse(Read); } }
        public double ReadDouble { get { return double.Parse(Read); } }
        public string[] ReadStrArray(long N) { var ret = new string[N]; for (long i = 0; i < N; ++i) ret[i] = Read; return ret; }
        public int[] ReadIntArray(long N) { var ret = new int[N]; for (long i = 0; i < N; ++i) ret[i] = ReadInt; return ret; }
        public long[] ReadLongArray(long N) { var ret = new long[N]; for (long i = 0; i < N; ++i) ret[i] = ReadLong; return ret; }
        public void ReadIntArrays(long N, out int[] A, out int[] B) { A = new int[N]; B = new int[N]; for (long i = 0; i < N; ++i) { A[i] = ReadInt; B[i] = ReadInt; } }
    }
}


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

using namespace std;

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

#define ll long long

int main()
{
	vector<int> v;
	int q, a, b;

	cin >> q;

	rep (i, q) {
		cin >> a;
		if (a == 2) {
			v.pop_back();
			continue;
		}
		cin >> b;
		if (a == 0)
			v.push_back(b);
		else
			cout << v[b] << endl;
	}
}




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

int main() {
  int n,a,b,c;
  cin>>n;
  vector<int> timer(n);
  map<int, int> work{};
  for(int i=0;i<n;i++){
    cin>>a>>b;
    if(work[b] > 0){
      c=work[b];
      work.erase(b);
      work[b]=a+c;
      continue;
    }
    work[b]=a;
    timer[i]=b;
  }
  sort(timer.begin(),timer.end());
  int savetime=0;
  for(int i=0;i<n;i++){
    savetime += work[timer[i]];
    if(savetime>timer[i]){
      cout<<"No";
      exit(0);
    }
  }
  cout<<"Yes";
}

Measured memory_bytes: 10368
#include <bits/stdc++.h>
typedef long long ll;
const int INF = 1e9;
const ll LINF = 1e18;
const int MOD = 1e9 + 7;
using namespace std;

int main() {
  int n;
  string a, b, c;
  cin >> n >> a >> b >> c;
  vector<int> abc(26, 0);
  int ans = 0;
  for (int i = 0; i < n; i++) {
    abc[a[i] - 'a']++;
    abc[b[i] - 'a']++;
    abc[c[i] - 'a']++;
    ans += 3 - (*max_element(abc.begin(), abc.end()));
    for (int i = 0; i < 26; i++) {
      abc[i] = 0;
    }
  }
  cout << ans << endl;
}

Measured memory_bytes: 256
import qualified Data.Text as T
import qualified Data.Text.IO as T
import qualified Data.Text.Read as T
import Data.IntSet (IntSet)
import qualified Data.IntSet as IS

main :: IO ()
main = do
  let
    ds = 0 : concatMap (\d -> [-d, d]) [1..] :: [Int]
  [x, n] <- map unsafeTextToInt . T.words <$> T.getLine :: IO [Int]
  ps <- map unsafeTextToInt . T.words <$> T.getLine :: IO [Int]
  let
    ps' = IS.fromList ps :: IntSet
  print . head . filter (`IS.notMember` ps') . map (x +) $ ds

unsafeTextToInt :: T.Text -> Int
unsafeTextToInt s = case T.signed T.decimal s of
  Right (n, _) -> n
{-# INLINE unsafeTextToInt #-}


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

int main() {
  ll r, D, x;
  cin >> r >> D >> x;
  rep(i, 0, 10) {
    x = r * x - D;
    cout << x << "\n";
  }
  return 0;
}


Measured memory_bytes: 256
#include<stdio.h>
int W,H,x,y,r;
	
int isIn(int x,int y){
	if(x<=W&&y<=H&&0<=x&&0<=y)return 1;
	else return 0;
}

int main(){
	scanf("%d%d%d%d%d",&W,&H,&x,&y,&r);
	if(isIn(x+r,y)&&isIn(x-r,y)&&isIn(x,y+r)&&isIn(x,y-r))printf("Yes\n");
	else printf("No\n");
	return 0;
}	

Measured memory_bytes: 584
#include<bits/stdc++.h>
using namespace std;
int main(){
  string s;
  cin>>s;
  sort(s.begin(),s.end());
  string ans="yes";
  
  for(int i=0;i<s.size()-1;i++){
    if(s.at(i)==s.at(i+1)){
      ans="no";
      break;
    }
  }
  
  cout<<ans<<endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define db(x)	{ cerr << #x << " = " << x << endl; }

int32_t main(){
	int n; cin>>n;
	unordered_set<string> s;
	while(n--){
		string x; cin>>x;
		s.insert(x);
	}
	cout<<s.size();
return 0;
}
// g++ -std=c++17 -Wshadow -Wall -o "sol" "sol.cpp" -g -fsanitize=address -fsanitize=undefined -D_GLIBCXX_DEBUG

Measured memory_bytes: 17588
N,L = map(int,input().split())
deri = [L]
for num in range(1,N):
    num2 = L + num
    deri.append(num2)

deri.sort() #おいしさの小さい順に並び替え
if (0 in deri) == True:
    deri.remove(0) #remove Zero
elif sum(deri) < 0:
    del deri[-1]
else:
    del deri[0]

deru = sum(deri)
print(deru)

Measured memory_bytes: 3060
#include <algorithm>
#include <cassert>
#include <chrono>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <iostream>
#include <map>
#include <memory>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>


/*
unsigned seed1 = std::chrono::system_clock::now().time_since_epoch().count();
mt19937 g1.seed(seed1);
*/
using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> pii;
typedef pair<pii, pii> ppiipii;
typedef pair<int, ppiipii> pippiipii;
typedef pair<int, pii> pipii;
typedef pair<pii, int> ppiii;
typedef pair<int, ppiii> pippiii;
typedef pair<int, ll> pill;
typedef pair<int, double> pid;
// note to self, the below two triggers someone
typedef pair<ll, ll> pll;
typedef pair<ll, int> plli;

char buf[105];

int main() {
  int len;
  scanf("%d\n%s", &len, buf);
  int ret = 0;
  for(int pref = 1; pref < len; pref++) {
    set<char> a, b;
    for(int i = 0; i < len; i++) {
      if(i < pref) {
        a.insert(buf[i]);
      }
      else {
        b.insert(buf[i]);
      }
    }
    int curr = 0;
    for(char c: a) {
      if(b.count(c)) {
        curr++;
      }
    }
    ret = max(ret, curr);
  }
  printf("%d\n", ret);
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
#define DUMP(x) cout << #x << " = " << (x) << endl;
#define FOR(i, m, n) for (ll i = m; i < n; i++)
#define IFOR(i, m, n) for (ll i = n - 1; i >= m; i--)
#define REP(i, n) FOR(i, 0, n)
#define IREP(i, n) IFOR(i, 0, n)
#define FOREACH(x, a) for (auto&(x) : (a))
#define ALL(v) (v).begin(), (v).end()
#define SZ(x) ll(x.size())

int main() {
  ll s, t, d;
  cin >> d >> t >> s;
  cout << (s * t >= d ? "Yes" : "No") << endl;
}

Measured memory_bytes: 3632
#include <iostream>
#include <algorithm>
#include <vector>
#include <utility>
#include <map>
#define rep(i,n) for(int i=0;i<n;++i)
#define rep1(i,n) for(int i=1;i<=n;++i)
using namespace std;
int main()
{
  int n,m;cin >> n >> m;
  vector<int> x(n);
  rep(i,n) cin >> x[i];
  
  sort(x.begin(), x.end());
  map<int,int> mp1, mp2;
  rep(i,n) mp1[x[i] % m]++;
  rep(i,n-1) {
    if(x[i] == x[i+1]) {
      mp2[x[i] %m] += 2;
      i++;
    }
  }

  // rep(i,m) cout << i << ":" << mp1[i] << "\n";
  // rep(i,m) cout << i << ":" << mp2[i] << "\n";  
  
  if(m % 2 == 0) {
    int res = 0;
    res += mp1[0] / 2;
    res += mp1[m/2] / 2;
    rep1(i,m/2 - 1) {
      if(mp1[i] <= mp1[m - i]) {
	res += mp1[i];
	int tmp = min(mp2[m-i], mp1[m-i] - mp1[i]);
	res += tmp / 2;
      }
      else {
	res += mp1[m-i];
	int tmp = min(mp2[i], mp1[i] - mp1[m - i]);
	res += tmp / 2;
      }
    }
    cout << res << "\n";
  }
  else {
    int res = 0;
    res += mp1[0] / 2;
    rep1(i,m/2) {
      if(mp1[i] <= mp1[m - i]) {
	res += mp1[i];
	int tmp = min(mp2[m-i], mp1[m-i] - mp1[i]);
	res += tmp / 2;
      }
      else {
	res += mp1[m-i];
	int tmp = min(mp2[i], mp1[i] - mp1[m - i]);
	res += tmp / 2;
      }
    }
    cout << res << "\n";
  }
  
  return 0;
}


Measured memory_bytes: 7936
#include<bits/stdc++.h>
using namespace std;
#define MAX_N 100001
int prime[MAX_N];//i番目の素数
bool is_prime[MAX_N+1];

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

int main(){
  int m,a,b;
  sieve(100000);
  while(cin>>m>>a>>b,m){
    int ma=0;
    int x,y;
    for(int i=0;;i++){
      if(prime[i]*prime[i]>m)break;
      for(int j=i;;j++){
	if(prime[i]*prime[j]>m)break;
	if((double)prime[i]/prime[j]<(double)a/b)continue;
	if(prime[i]*prime[j]>ma){
	  ma=prime[i]*prime[j];
	  x=prime[i];
	  y=prime[j];
	}
      }
    }
    cout<<x<<" "<<y<<endl;
  }
  return 0;
}



Measured memory_bytes: 3216
#include <iostream>
#include <string>
#include <algorithm>
#include <cmath>
#include <map>
#include <vector>
#include <stack>
#include <queue>
#include <tuple>
#include <cassert>
#include <functional>
#include <set>
#include <deque>
using namespace std;
typedef long long ll;
int dx[4] = {0,0,1,-1};
int dy[4] = {1,-1,0,0};
const int INF = 1<<29;
#define LNF __LONG_LONG_MAX__;
const ll MOD = 1000000007;
const int MAX = 200000;

long long fac[MAX], finv[MAX], inv[MAX];

// テーブルを作る前処理
void COMinit() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (int i = 2; i < MAX; i++){
        fac[i] = fac[i - 1] * i % MOD;
        inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
        finv[i] = finv[i - 1] * inv[i] % MOD;
    }
}

// 二項係数計算
long long COM(int n, int k){
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}
// 法mでのaの逆元を計算
long long modinv(long long a, long long m) {
    long long b = m, u = 1, v = 0;
    while (b) {
        long long t = a / b;
        a -= t * b; swap(a, b);
        u -= t * v; swap(u, v);
    }
    u %= m;
    if (u < 0) u += m;
    return u;
}
// a^n mod を計算する
long long modpow(long long a, long long n, long long mod) {
    long long res = 1;
    while (n > 0) {
        if (n & 1) res = res * a % mod;
        a = a * a % mod;
        n >>= 1;
    }
    return res;
}
//最大公約数
int gcd(int x, int y) { return (x % y)? gcd(y, x % y): y; }
//最小公倍数
int lcm(int x, int y) { return x / gcd(x, y) * y; }
// nが大きく,kが10^7程度の時の二項係数
long long com[200005];
void combination(long long n,long long k){
    com[0] = 1;
    for(int i=1;i<=k;i++){
        com[i] = (com[i-1]*(n-i+1)%MOD)*modinv(i,MOD)%MOD;
    }
}

int main(){
    int L; cin >> L;
    long double e=1.0*L/3;
    long double out = e*e*e;
    printf("%.8Lf\n",out);
    
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <cmath>
#include <vector>
#include <list>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <string>
#include <cstring>
#include <utility>
#include <algorithm>
#include <functional>
#include <deque>
#include <cctype>
#include <ctime>
#include <cstdlib>
#include <iomanip>
using namespace std;

;;
;
long long dp[100];;
;;
;
long long L(int N){;;
    if(dp[N]!=0) {;return (dp[N]);;}
    else {;return (dp[N] = L(N-1)+L(N-2));    ;};
};;
;;

int main(){
  ;;
    dp[0] = 2;;
    dp[1] = 1;;
    int N;
    cin >> N;
    ;
    cout << (L(N)) << endl;;
    ;
    ;
}

Measured memory_bytes: 636
import sys
sys.setrecursionlimit(10**8)
stdin = sys.stdin


def ni(): return int(ns())


def na(): return list(map(int, stdin.readline().split()))


def naa(N): return [na() for _ in range(N)]


def ns(): return stdin.readline().rstrip()  # ignore trailing spaces


class SegmentTreeRMQ(object):  # 1-indexed [l,r)
    def __init__(self, size, value):
        self.len = 1 << size.bit_length()
        # print(self.len)
        self.array = [value] * (2 * self.len)

    def update(self, i, x):  # 0-indexed
        i += self.len
        while i > 0:
            self.array[i] = min(self.array[i], x)
            i >>= 1
        # print(self.array)

    def get(self, i):  # 0-indexed
        return self.array[i + self.len]

    def get_minimum(self, l, r):  # 0-indexed
        L = l+self.len
        R = r+self.len
        ANS = 1 << 30

        while L < R:
            if L & 1:
                ANS = min(ANS, self.array[L])
                L += 1

            if R & 1:
                R -= 1
                ANS = min(ANS, self.array[R])
            L >>= 1
            R >>= 1

        return ANS


N, K = na()
P = na()

if N == K or N == 2:
    print(1)
    exit()


min_tree = SegmentTreeRMQ(N, N)
max_tree = SegmentTreeRMQ(N, 1)

for i, p in enumerate(P):
    min_tree.update(i, p)
    max_tree.update(i, -p)

no_change = [0] * (N-K+1)

last = -1

for i in range(N):
    if i - last >= K:
        no_change[i-K+1] = 1
    if i == N-1:
        break
    if P[i] > P[i+1]:
        last = i

# print(no_change)


ans = 1
no_count = 0

for i in range(N-K):
    if P[i] > min_tree.get_minimum(i+1, i+K+1) or -P[i+K] > max_tree.get_minimum(i+1, i+K+1):
        ans += 1
        if no_change[i] == 1:
            no_count += 1
    if i == (N-K-1) and no_change[N-K] == 1:
        no_count += 1

print(ans - max(0, no_count-1))


Measured memory_bytes: 104924
#include <bits/stdc++.h>
using namespace std;
const int N = 2e5 + 7;
const int C = 26;

int n, q;
string s;
char c[N], t[N];

bool left(int p) {
    for (int i = 0; i < q; ++i) {
        if (c[i] != s[p]) continue;
        if (t[i] == 'L') --p;
        else ++p;
        if (p == -1) return 1;
        if (p == n) return 0;
    }   
    return 0;
}

bool right(int p) {
    for (int i = 0; i < q; ++i) {
        if (c[i] != s[p]) continue;
        if (t[i] == 'L') --p;
        else ++p;
        if (p == -1) return 0;
        if (p == n) return 1;
    }   
    return 0;
}

signed main() {
    #ifdef HOME
    freopen("input.txt", "r", stdin);
    #else
    ios_base::sync_with_stdio(0); cin.tie(0);
    #endif
    cin >> n >> q;
    cin >> s;
    for (int i = 0; i < q; ++i) cin >> c[i] >> t[i];
    
    int ans = n;

    int l = -1;
    int r = n;
    while (l < r - 1) {
        int m = (l + r) >> 1;
        if (left(m)) l = m;
        else r = m;
    }   
    ans -= l + 1;

    l = -1;
    r = n;
    while (l < r - 1) {
        int m = (l + r) >> 1;
        if (right(m)) r = m;
        else l = m;
    }
    ans -= n - r;

    cout << ans << '\n';
}   

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

using namespace std;

//#define double long double

typedef pair<int,int> ii;
typedef pair<int,long long> il;
typedef pair<long long,long long> ll;
typedef pair<ll,int> lli;
typedef pair<long long,int> li;
typedef pair<double,double> dd;
typedef pair<ii,int> iii;
typedef pair<double,int> di;
typedef pair<int,ii> iii2;
typedef pair<ii,ii> iiii;
long long mod = 1000000007LL;
long long large = 2000000000000000000LL;



int main(){

	vector<int> cnt(4,0);
	for(int i=0;i<3;i++){
		int x,y;
		cin>>x>>y;
		x--;y--;
		cnt[x]++;
		cnt[y]++;
	}
	bool can = true;
	for(int i=0;i<4;i++) if(cnt[i]>=3) can = false;

	if(can) cout<<"YES"<<endl;
	else cout<<"NO"<<endl;


	return 0;
}


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

#define ALL(v) (v).begin(), (v).end()
#define REP(i, p, n) for(int i = p; i < (int)(n); ++i)
#define rep(i, n) REP(i, 0, n)
#define dump(a) (cerr << #a << "=" << (a) << endl)
#define DUMP(list) cout << "{ "; for(auto nth : list) { cout << nth << " ";} cout << "}" << endl;

int H;
vector<vector<int>> field;

int erase(int cnt, int h, int st, int ed){
    int res = 0;
    if(cnt >= 3){
        for (int i = st; i <= ed; i++)
        {
            res += field[h][i];
            field[h][i] = 0;
        }
    }
    return res;
}

int chain(){
    int res = 0;
    int prev = 0, cnt = 0, st = 0;
    rep(h, H){
        rep(w, 5){
            if(w > 0 && prev == field[h][w] && field[h][w]){
                cnt++;
                if(w == 4){ res += erase(cnt, h, st, w); }
            }
            else{
                res += erase(cnt, h, st, w - 1);
                st = w;
                cnt = 1;
                prev = field[h][w];
            }
        }
    }
    return res;
}

void fall(){
    int cnt = 0;
    while (true)
    {
        for (int h = H - 1; h > 0; h--)
        {
            for (int w = 5 - 1; w >= 0; w--)
            {
                if(field[h][w] == 0 && field[h-1][w]){
                    swap(field[h][w], field[h-1][w]);
                    cnt++;
                }
            }
        }
        if(cnt == 0) break;
        cnt = 0;
    }
    return;
}

int main() {
    while (cin >> H && H)
    {
        field.assign(H, vector<int>(5, 0));
        rep(h, H){
            rep(w, 5){
                cin >> field[h][w];
            }
        }

        int score = 0, ans = 0;
        while (true)
        {
            score = chain();
            if(score == 0) break;
            ans += score;
            fall();
        }
        cout << ans << endl;
    }
    return 0;
}


Measured memory_bytes: 3160
#include <bits/stdc++.h>
 
using namespace std;
typedef unsigned long long ull;
typedef long long ll;
typedef long double ld;
typedef pair<ll, ll> pii;
 
#define REP(a,b,c) for(ll (a)=(b);(a)<(c);(a)++)
#define PER(a,b,c) for(ll (a)=(b);(a)>=(c);(a)--)
 
ll ii(){ ll x; cin >> x; return x; }
string is(){ string x; cin >> x; return x; }
void oi(ll x){ cout << x << " "; }
void od(ld x){ cout << fixed << setprecision(10) << x << " "; }
void os(string x){ cout << x; }
void oie(ll x){ cout << x << endl; }
void ode(ld x){ cout << fixed << setprecision(10) << x << endl; }
void ose(string x){ cout << x << endl; }
void oe(){ cout << endl; }

int main(){
    ll K=ii(), N=ii();
    vector<ll> A;
    REP(i,0,N) A.push_back(ii());
    ll all=0, maxd=0;
    REP(i,0,N){
        ll d=(i==N-1)?A[0]+K-A[i]:A[i+1]-A[i];
        all += d;
        maxd = max(d,maxd);
    }
    oie(all-maxd);

    return 0;
}


Measured memory_bytes: 2420
#include<iostream>
#include<cmath>
#define mod 1000000007
using namespace std;
long long int dp[101001][13];
int main()
{
	ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
	int n, d, nb=0;
	cin >> n >> d;
	int a[n][d];
	for(int i = 0; i  <n; i++)
	    for(int j = 0; j < d; j++)
	        cin >> a[i][j];
	for(int i = 0; i < n-1; i++)
	{
	    for(int j = i+1; j < n; j++)
	    {
	        long long int x=0;
	        for(int k = 0; k < d; k++)
	        {
	            x+=((a[i][k]-a[j][k])*(a[i][k]-a[j][k]));
	        }
	        //cout << x << '\n';
	        if((int)(sqrt((double)(x)))*(int)(sqrt((double)(x)))==x)
	            nb++;
	    }
	}
	cout << nb<< '\n';
}

Measured memory_bytes: 256
n, m = map(int, input().split(' '))

pena = [0 for i in range(n)]
acc = [0 for i in range(n)]

for i in range(m):
    pp, ss = input().split(' ')
    p = int(pp) - 1

    if acc[p] == 0:
        if ss == 'WA':
            pena[p] += 1
        else:
            acc[p] = 1

for i in range(n):
    pena[i] = pena[i] * acc[i]

print(sum(acc), sum(pena))

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

int main(void){
    int h, w;
    cin >> h >> w;
    char array[h+2][w+2] = {'.'};
    for(int i=1; i<=h; i++){
        for(int j=1; j<=w; j++){
            cin >> array[i][j];
        }
    }
    for(int i=1; i<=h; i++){
        for(int j=1; j<=w; j++){
            int cnt = 0;
            if(array[i][j] == '#'){
                cout << '#';
                continue;
            }
            for(int x=-1; x<=1; x++){
                for(int y=-1; y<=1; y++){
                    if(!(x == 0 && y == 0) && array[i+x][j+y] == '#'){
                        cnt++;
                    }
                }
            }
            cout << cnt;
        }
        cout << endl;
    }
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <bits/stdc++.h>
struct res {
    std::string name;
    int score;
    int index;
};
bool comp(res a, res b){
    if (a.name !=b.name){
        return a.name < b.name;
    }else{
        return a.score>b.score;
    }
}
int main() {
    int n;
    std::cin >> n ;
    std::vector<res> r;
    for(int i=0;i<n;i++){
        res re;
        std::cin>>re.name>>re.score;
        re.index=i+1;
        r.push_back(re);
    }
    std::sort(r.begin(),r.end(),comp);
    for(int i=0;i<n;i++){
        std::cout<<r[i].index<<'\n';
    }
    return 0;
}

Measured memory_bytes: 256
# 木グラフの直径
from heapq import heappop, heappush

INF = float("inf")

def dijkstra(n, G, s):
    dist = [INF] * n
    dist[s] = 0
    hq = [(0, s)]
    while hq:
        d, v = heappop(hq)
        if dist[v] < d:
            continue
        for child, child_d in G[v]:
            if dist[child] > dist[v] + child_d:
                arrow[child] = v + 1
                dist[child] = dist[v] + child_d
                heappush(hq, (dist[child], child))
    return dist

n, m = map(int, input().split())
edge = [list(map(int, input().split())) for _ in range(m)]

graph = [[] for _ in range(n)]
arrow = [0] * n

for a, b in edge:
    graph[a - 1].append((b - 1, 1))
    graph[b - 1].append((a - 1, 1))
    
dijkstra(n, graph, 0)

print("Yes")
for a in arrow[1:]:
  print(a)



Measured memory_bytes: 99408