akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#define r(i,n) for(int i=0;i<n;i++)
#define int long long
using namespace std;
typedef pair<int,int>P;
typedef pair<int,P>P2;
#define fi first
#define se second
int dx[]={0,1,0,-1};
int dy[]={-1,0,1,0};
 
string s;

int A[200009],B[200009];

bool rp[200009],o_rp[200009];
bool ban[200009],used[200009];
int col[200009],c;
int x,y,n,m;
vector<int>v[200009];
 
void H_E(){
	cout<<"Yes"<<endl;
	exit(0);
}
 
void dfs(int x){
	used[x]=1;
	col[x]=c;
	r(i,v[x].size()){
		if(!used[v[x][i]]&&!ban[v[x][i]]){
			if(s[v[x][i]]==s[x]){
				dfs(v[x][i]);
			}
		}
	}
}
 
void dfs2(int x,int pre){
	if(used[x])H_E();
	used[x]=1;
	r(i,v[x].size()){
		int nex=v[x][i];
		if(nex!=x&&nex!=pre){
			if(!ban[nex]){
				dfs2(nex,x);
			}
		}
	}
}
 
set<P>st;
 
signed main(){
	cin>>n>>m;
	cin>>s;
	r(i,m){
		cin>>x>>y;
		x--;y--;
		if(st.count(P(x,y)))continue;
		st.insert(P(x,y));
		st.insert(P(y,x));
		v[x].push_back(y);
		v[y].push_back(x);
		if(x==y)rp[x]=1;
	}
	r(i,n)if(rp[i]){
		r(j,v[i].size()){
			if(s[i]!=s[v[i][j]])o_rp[v[i][j]]=1;
		}
	}
	r(i,n){
		r(j,v[i].size()){
			if(rp[i]&&rp[v[i][j]]){
				if(s[i]!=s[v[i][j]])H_E();
			}
			if(o_rp[i]&&o_rp[v[i][j]]){
				if(s[i]==s[v[i][j]])H_E();
			}
		}
	}

	queue<int>q;
 
	r(i,n){
		int sum=0;
		r(j,v[i].size()){
			if(s[v[i][j]]=='A')sum|=(1<<0),A[i]++;
			else sum|=(1<<1),B[i]++;
		}
		if(sum!=3) ban[i]=1,q.push(i);
	}

	while(!q.empty()){
		int x=q.front();q.pop();
		int C= (s[x]=='A');
		r(i,v[x].size()){
			int nex=v[x][i];
			if(ban[nex])continue;
			if(C)A[nex]--;
			else B[nex]--;
			if(!A[nex]||!B[nex]){
				ban[nex]=1;
				q.push(nex);
			}
		}
	}

	/*
	r(i,n)if(!used[i]&&!ban[i]){
		dfs(i);
		c++;
	}*/
	r(i,n)if(!ban[i]){
		dfs2(i,-1);
		break;
	}
	cout<<"No"<<endl;
}

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

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

typedef long long ll;
const ll MOD = 1e9 + 7;

int main() {
  int N, u, v;
  std::cin >> N >> u >> v;
  --u;
  --v;

  std::vector<std::vector<int>> from(N);
  rep(i, N - 1) {
    int A, B;
    std::cin >> A >> B;
    --A;
    --B;
    from[A].push_back(B);
    from[B].push_back(A);
  }

  std::vector<int> du(N, -1), dv(N, -1);
  du[u] = 0;
  dv[v] = 0;

  std::queue<int> q;
  q.push(u);
  while(! q.empty()) {
    int x = q.front(); q.pop();
    for(int y : from[x]) {
      if(du[y] >= 0) {
        continue;
      }
      du[y] = du[x] + 1;
      q.push(y);
    }
  }
  q.push(v);
  while(! q.empty()) {
    int x = q.front(); q.pop();
    for(int y : from[x]) {
      if(dv[y] >= 0) {
        continue;
      }
      dv[y] = dv[x] + 1;
      q.push(y);
    }
  }

  int ans = 0;
  for(int p = 0; p < N; ++p) {
    if(du[p] >= dv[p]) {
      continue;
    }

    ans = std::max(ans, dv[p] - 1);
  }

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


Measured memory_bytes: 6656
#include<stdio.h>

int main(void){
	int r,c,i,j,sum1,sum2,SUM;
	sum1=0;
	sum2=0;
	SUM=0;
	scanf("%d %d",&r,&c);
	int A[100][100]={};
	for(i=0;i<r;i++){
		for(j=0;j<c;j++){
			scanf("%d",&A[i][j]);
		}
	}
	for(i=0;i<r;i++){
		for(j=0;j<c;j++){
			printf("%d ",A[i][j]);
			sum1+=A[i][j];
		}
		printf("%d\n",sum1);
		SUM+=sum1;
		sum1=0;
	}
	for(i=0;i<c;i++){
		for(j=0;j<r;j++){
			sum2+=A[j][i];
		}
		printf("%d ",sum2);
		sum2=0;
	}
	printf("%d\n",SUM);
	return 0;
}

Measured memory_bytes: 648
#pragma GCC optimize("O2")

#include <bits/stdc++.h>
#ifdef DEBUG
    #include "debug.hpp"
#endif

using namespace std;

#define all(c) (c).begin(), (c).end()
#define traverse(c, it) for(auto it = (c).begin(); it != (c).end(); it++)
#define rep(i, N) for(int i = 0; i < (N); i++)
#define rep1(i, N) for(int i = 1; i <= (N); i++)
#define rep2(i, s, e) for(int i = (s); i <= (e); i++)
#define rep3(i, s, e, d) for(int i = (s); (d) >= 0 ? i <= (e) : i >= (e); i += (d))
#define pb push_back


#ifdef DEBUG
    #define debug(x...) {dbg::depth++; string dbg_vals = dbg::to_string(x); dbg::depth--; dbg::fprint(__func__, __LINE__, #x, dbg_vals);}
    #define light_debug(x) {dbg::light = 1; dbg::dout << __func__ << ":" << __LINE__ << "  " << #x << " = " << x << endl; dbg::light = 0;}
#else
    #define debug(x...)
    #define light_debug(x) 
#endif


using ll = long long;
using pii = pair<int, int>;
using vi = vector<int>;


signed main(){

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

    #ifdef DEBUG
        freopen("debug", "w", stderr);
    #endif
    
    int N, C = 0;
    ll D;
    cin >> N >> D;
    D *= D;

    rep(i, N){
        ll X, Y;
        cin >> X >> Y;
        C += X * X + Y * Y <= D;
    }

    cout << C << '\n';

    #ifdef DEBUG
        dbg::dout << "\nExecution time: " << clock() << "ms\n";
    #endif

    return 0;
}


Measured memory_bytes: 3652
/**
 * CatChecker - Accepted
 */

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.HashSet;
import java.util.Set;

import static java.lang.Integer.parseInt;

public class Main {

	static Set<String> cat = new HashSet<>();
	static Set<String> rabbit = new HashSet<>();

	public static void main(String[] args) throws IOException {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		String line;
		String[] words;

		cat.add("");
		cat.add("mew");

		while ((line = br.readLine()) != null && !line.isEmpty()) {
			System.out.println(isCat(line) ? "Cat" : "Rabbit");
		}
	}

	static boolean isCat(String S) {

		if (cat.contains(S)) return true;
		if (rabbit.contains(S)) return false;

		if (S.charAt(0) == 'm'
				&& S.charAt(S.length() - 1) == 'w'
				&& S.indexOf('e') > 0) {
			boolean ret = false;
			for (int i = 1; i < S.length() - 1; i++) {
				if (S.charAt(i) == 'e') {
					ret = isCat(S.substring(1, i)) & isCat(S.substring(i + 1, S.length() - 1));
					if (ret) {
						cat.add(S);
						break;
					} else {
						rabbit.add(S);
					}
				}
			}
			return ret;
		}

		return false;
	}
}

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

using namespace std;
using ll = long long int;
using lc = complex<double>;

int main(void) {
    constexpr ll MOD = 1e9 + 7;
    constexpr double PI = acos(-1);
    cout << fixed << setprecision(32);
    cin.tie(0); ios::sync_with_stdio(false);

    auto powm = [&](ll a, ll b) {
        ll r = 1;
        while(b) {
            if(b&1) (r *= a) %= MOD;
            (a *= a) %= MOD;
            b >>= 1;
        }
        return r;
    };

    constexpr ll MAX = 2e6;
    vector<ll> fact, ifact;
    fact.assign(MAX+1, 1);
    for(ll i=1; i<=MAX; i++)
        (fact[i] = i * fact[i-1]) %= MOD;

    ifact.assign(MAX+1, 1);
    {
        ll a = fact[MAX], b = MOD-2;
        while(b) {
            if(b&1) (ifact[MAX] *= a) %= MOD;
            (a *= a) %= MOD;
            b >>= 1;
        }
    }
    for(ll i=MAX-1; i>=0; i--)
        (ifact[i] = ifact[i+1] * (i+1)) %= MOD;

    auto comb = [&](ll a, ll b) {
        if(a < b) return 0ll;
        return ((fact[a] * ifact[b]) % MOD * ifact[a-b]) % MOD;
    };

    ll k;
    string s;
    cin >> k >> s;
    ll n = s.size();

    ll res = 0;
    for(ll i=n; i<=n+k; i++) {
        // i C n
        ll t = comb(i-1, n-1);
        (t *= powm(25, i-n)) %= MOD;
        (t *= powm(26, n+k-i)) %= MOD;
        (res += t) %= MOD;
    }
    cout << res << endl;
}


Measured memory_bytes: 35460
n, m = map(int, input().split())
an = [input() for _ in range(n)]
bm = [input() for _ in range(m)]

for i in range(n-m+1) :
    for j in range(n-m+1) :
      match = True
      for k in range(m) :
        for l in range(m) :
          if an[i+k][j+l] != bm[k][l] :
            match = False
            break
          else :
            continue
      if match :
        print("Yes")
        exit()
                    
print("No")

Measured memory_bytes: 9024
package main

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

func proc(r io.Reader, w io.Writer) {
	var n, d int
	fmt.Fscanf(r, "%d", &n)
	p := make([]int, n)
	for i := 0; i < n; i++ {
		fmt.Fscanf(r, "%d", &d)
		p[i] = d
	}
	cnt := 0
	for i := 0; i < n; i++ {
		if p[i] != i+1 {
			cnt++
		}
	}

	if cnt <= 2 {
		fmt.Fprintf(w, "YES")
	} else {
		fmt.Fprintf(w, "NO")
	}
}

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


Measured memory_bytes: 512
#include<iostream>
#include<sstream>
#include<algorithm>
#include<climits>
#include<cmath>
#include<cstdio>
#include<cstdlib>
#include<ctime>
#include<cfloat>
#include<functional>
#include<map>
#include<string>
#include<cstring>
#include<vector>
#include<queue>
#include<stack>
#include<deque>
#include<set>
#include<bitset>
#include<list>
#include<numeric>
#include<complex>

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> i_i;
typedef pair<long long, int> ll_i;
typedef pair<double, int> d_i;
typedef pair<long long, long long> ll_ll;
typedef pair<double, double> d_d;

#define PI 3.141592653589793238462643383279
#define mod 1000000007LL
#define rep(i, n) for(i = 0;i < n;++i)
#define rep1(i, n) for(i = 1;i < n;++i)
#define rep2d(i, j, n) for(i = 0;i < n;++i)for(j = i + 1;j < n;++j)
#define per(i, n) for(i = n - 1;i > -1;--i)
#define int(x) int x; scanf("%d",&x)
#define int2(x, y) int x, y; scanf("%d%d",&x, &y)
#define int3(x, y, z) int x, y, z; scanf("%d%d%d",&x, &y, &z)
#define sc(x) cin >> x
#define sc2(x, y) cin >> x >> y
#define sc3(x, y, z) cin >> x >> y >> z
#define scn(n, a) rep(i, n)cin >> a[i]
#define sc2n(n, a, b) rep(i, n)cin >> a[i] >> b[i]
#define pri(x) cout << x << "\n"
#define pri2(x, y) cout << x << " " << y << "\n"
#define pri3(x, y, z) cout << x << " " << y << " " << z << "\n"
#define pb push_back
#define mp make_pair
#define all(a) (a).begin(),(a).end()
#define kabe puts("---------------------------")
#define kara puts("")
#define debug(x) cout << " --- " << x << "\n"
#define debug2(x, y) cout << " --- " << x << " " << y << "\n"
#define debug3(x, y, z) cout << " --- " << x << " " << y << " " << z << "\n"
#define debugn(i, n, a) rep(i, n)cout << " --- " << a[i] << "\n";
#define debugin(i, n, a) rep(i, n)printf(" --- %10d\n", a[i])
#define debugi2n(i, n, a, b) rep(i, n)printf(" --- %10d %10d\n", a[i], b[i])
#define debugiin(i, n, a) rep(i, n)printf(" --- %10d %10d\n", a[i].first, a[i].second)
#define X first
#define Y second
#define eps 0.0001
#define prid(x) printf("%.15lf\n", x)


signed main(void){
  int i, j;
  for(int testcase = 0;;testcase++){
    int(n);
    double r[n], o[n];
    scn(n, r);

    o[0] = r[0];
    rep1(i, n){
      o[i] = r[i];
      rep(j, i)o[i] = max(o[i], o[j] + 2.0 * sqrt(r[i] * r[j]));
    }

    double res = 0;
    rep(i, n)res = max(res, o[i] + r[i]);
    prid(res);

/*/

//*/ break;
  }
  return 0;
}

Measured memory_bytes: 1280
#include<iostream>
#include<string>
#include<ctype.h>

int main() {

	int N = 0;
	int K = 0;
	std::string S;

	std::cin >> N;
	std::cin >> K;
	std::cin >> S;

	S[K - 1] = tolower(S[K - 1]);

	std::cout << S << std::endl;

}

Measured memory_bytes: 256
//Optimize
#pragma GCC optimize("Ofast")

//Head File
#include<bits/stdc++.h>
using namespace std;

#define il inline

//Variable
#define ll long long
#define ull unsigned long long
#define db double
#define lb long double
#define ui unsigned int

//Debug
#define B cerr<<"Break Point"<<endl;
#define P(x) cerr<<#x<<' '<<"="<<' '<<(x)<<endl;
#define p(x) cerr<<#x<<' '<<"="<<' '<<(x)<<' ';
#define ml(x) cerr<<"Size of array is "<<x*4/1024/1024<<" MB"<<endl;

//Vector
#define vc vector
#define puf push_front
#define pof pop_front
#define pub push_back
#define pob pop_back
#define vbe(x) x.begin(),x.end()

//Memset
#define ms(x) memset(x,0,sizeof(x))
#define MS(x) memset(x,0x3f3f3f3f,sizeof(x))

//Pair
#define fi first
#define se second

//File

#define fin(x) freopen(x,"r",stdin)
#define fou(x) freopen(x,"w",stdout)
void fio()
{
    #ifndef ONLINE_JUDGE
    freopen("sample.in","r",stdin);
    freopen("sample.out","w",stdout);
    #endif
}
void pti()
{
    double timeuse = clock()*1000.0/CLOCKS_PER_SEC;
    cerr<<"Timeuse "<<timeuse<<"ms"<<endl;
}
void end()
{
    pti();
    exit(0);
}

//Inf
#define INF 0x3f3f3f3f
#define LINF ((long long)(0x3f3f3f3f3f3f3f3f))

//IO
#define pc(s) putchar(s)
#define say(s) cout<<s<<endl
namespace io
{
    const int SIZ=55;int que[SIZ],op,qr;char ch;
    template<class I>
    il void gi(I &w)
    {
        ch=getchar(),op=1,w=0;
	while(!isdigit(ch)){if(ch=='-') op=-1;ch=getchar();}
        while(isdigit(ch)){w=w*10+ch-'0';ch=getchar();}w*=op;
    }
    template<typename T,typename... Args>
    il void gi(T& t,Args&... args){gi(t);gi(args...);}
    template<class I>
    il void print(I w)
    {
        qr=0;if(!w) putchar('0');if(w<0) putchar('-'),w=-w;
	while(w) que[++qr]=w%10+'0',w/=10;
        while(qr) putchar(que[qr--]);
    }
}
using io::gi;
using io::print;

const int N=105;
const int M=100;

int n;
int a[N];

int calc(int v)
{
    int res=0;
    for(int i=1;i<=n;++i) res+=(v-a[i])*(v-a[i]);
    return res;
}
int main()
{
    gi(n);
    int ans=INF;
    for(int i=1;i<=n;++i) gi(a[i]);
    for(int i=1;i<=M;++i) ans=min(ans,calc(i));
    print(ans);
    end();
}


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

using namespace std;

int i, j, k, p, q, r, n, m, a, b, c, cost[101], t, dc[101][101], dt[101][101];

int dic(const int d[101][101]) {
  cost[p] = 0;
  int min, f[101] = {};
  for(i = 0; i < m; i++) {
    f[p] = 1;
    for(j = 0; j <= m; j++) {
      if(f[j]) continue;
      if(cost[j] > cost[p] + d[p][j]) cost[j]  = cost[p] + d[p][j];
    }
    min = 200000000;
    for(j = 0; j <= m; j++ ) {
      if(f[j]) continue;
      if(min > cost[j]) min = cost[p = j];
    }
  }
  return cost[q];
}


int main() {
  while(cin >> n >> m, n != 0 || m != 0) {
    for(i = 0; i <= 100; i++)
      for(j = 0; j <= 100; j++) {
	dc[i][j] = 100000000;
	dt[i][j] = 100000000;
      }
  

  
    while(n--) {
      cin >> a >> b >> c >> t;
      dc[a][b] = dc[b][a] = c;
      dt[a][b] = dt[b][a] = t;
    }
  
    cin >> k;
    
    while(k--) {
      cin >> p >> q >> r;
      for(i = 0; i <= 100; i++) cost[i] = 100000000;
      if(r) cout << dic(dt) << endl;
      else cout << dic(dc) << endl;
    }
  
  }
  return 0;
}

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

int main(){
    int n;
    string s,t;
    string ans;

    cin >>n;
    cin >>s >>t;
    for(int i=0;i<n;i++){
        ans = ans + s[i];
        ans = ans + t[i];
    }
    cout << ans <<endl; 

    return 0;
}

Measured memory_bytes: 256
import 'dart:io';

int solve(int n){
	int ans = 0;
	for(int i = 5; i<=n; i*=5){
		ans += n~/(2 * i);
	}
	return ans;
}

void main(){
	int n = int.parse(stdin.readLineSync());
	if(n % 2 == 1){
		print(0);
		return;
	}
	else{
		print(solve(n));
	}

}

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

int main() {
    int n, a, b;
    cin >> n >> a >> b;
    int x = 0, y = 0, z = 0;
    rep(i,n) {
        int p;
        cin >> p;
        if (p <= a) x++;
        if (a+1 <= p && p <= b) y++;
        if (b+1 <= p) z++;
    }
    cout << min({x, y, z}) << endl;
}

Measured memory_bytes: 256
#include<stdio.h>
#include<stdlib.h>
#define df 0
#define MAX 100010
#define MOD 1000000007
int que[3*MAX];
int head=0,tail=0;

void enq(int a){
  que[tail++]=a;
}
int deq(){
  return que[head++];
}

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

  int  *a[MAX+1];
  int deg[MAX+1]={},i;
  int *search;
  search=(int*)malloc(sizeof(int)*(n+1));


  for(i=0;i<=n;i++){
    a[i]=NULL;
    search[i]=0;
  }

  for(i=0;i<n-1;i++){
    int u,v;
    scanf("%d%d",&u,&v);
    a[u]=(int *)realloc(a[u],sizeof(int)*++deg[u]);
    a[v]=(int *)realloc(a[v],sizeof(int)*++deg[v]);
    a[u][deg[u]-1]=v;
    a[v][deg[v]-1]=u;
  }
  if(df){
    for(i=1;i<=n;i++){
      int j;
      printf("N(%d):[",i);
      for(j=0;j<deg[i];j++){
	printf(" %d",a[i][j]);
      }
      printf(" ]\n");
    }
  }

  

  

  long int count=k;
  int s=k-1;
  search[1]=1;
  if(df)printf("search:1-> %d",k);
  for(i=0;i<deg[1];i++){
    if(df)printf(" *%d",s);
    enq(a[1][i]);
    count=count*s%MOD;
    s--;
  }
  if(df)printf("\n");
  while(tail-head){
    int v=deq();
    if(df)printf("search:%d->",v);
    search[v]=1;
    int s=k-2;
    for(i=0;i<deg[v];i++){
      if(search[a[v][i]])continue;
      if(df)printf(" *%d",s);
      count=count*s%MOD;
      enq(a[v][i]);
      s--;
    }
    if(df)printf("\n");
  }

  printf("%ld",count);
  return 0;
}


/// confirm df==0 ///


Measured memory_bytes: 5632
#include<bits/stdc++.h>
using namespace std;
int main(){
  int h,w;cin>>h>>w;
  string a[h];
  for(int i=0;i<h;i++)cin>>a[i];
  for(int i=0;i<1<<h+w-2;i++){
    bool used[h][w];
    for(int j=0;j<h;j++)for(int k=0;k<w;k++)used[j][k]=false;
    int now=i;
    int c=0;
    int x=0,y=0;
    used[0][0]=true;
    for(int j=0;j<h+w-2;j++){
      if(now%2==0)x++;
      else y++;
      if(x>=w||y>=h){
        c=1;
        break;
      }
      now/=2;
      used[y][x]=true;
    }
    int d=0;
    if(c==0){
      for(int j=0;j<h;j++){
        for(int k=0;k<w;k++){
          if((a[j][k]=='#'&&used[j][k]==false)||(a[j][k]=='.'&&used[j][k]==true)){
            d=1;
            break;
          }
        }
        if(d==1)break;
      }
      if(d==0){
        cout<<"Possible"<<endl;
        return 0;
      }
    }
  }
  cout<<"Impossible"<<endl;
}


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

int main()
{
    char s[4];
    cin >> s;

    int ans = 0, pos = 0;
    for (int i = 0; i < (1 << 3); i++)
    {
        pos = i;
        ans = s[0] - '0';
        for (int j = 0; j < 3; j++)
        {
            if (i >> j & 1)
            {
                ans += s[j + 1] - '0';
            }
            else
            {
                ans -= s[j + 1] - '0';
            }
        }
        if (ans == 7)
        {
            break;
        }
    }

    cout << s[0] << flush;
    for (int i = 0; i < 3; i++)
    {
        if (pos >> i & 1)
        {
            cout << "+" << s[i + 1] << flush;
        }
        else
        {
            cout << "-" << s[i + 1] << flush;
        }
    }
            cout << "=7" << endl;

    return 0;
}

Measured memory_bytes: 256
var input = require('fs').readFileSync('/dev/stdin', 'utf8');
var Arr=(input.trim()).split("\n").map(Number);
Arr.forEach(function(v){
var str="";
var k="light fly,fly,bantam,feather,light,light welter,welter,light middle,middle,light heavy,heavy".split(",");
if(v<=48)str=k[0];
if(v>48)str=k[1];
if(v>51)str=k[2];
if(v>54)str=k[3];
if(v>57)str=k[4];
if(v>60)str=k[5];
if(v>64)str=k[6];
if(v>69)str=k[7];
if(v>75)str=k[8];
if(v>81)str=k[9];
if(v>91)str=k[10];
console.log(str);
});

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

int main(){
    int n, a, max = 0, tmp = 0;
    vector<int> h;

    cin >> n;

    for(int i = 0; i < n; i++){
        cin >> a;
        h.push_back(a);
    }

    for(int i = 1; i < n; i++){
        if(h[i-1] >= h[i]){
            tmp++;
        }
        else{
            if(tmp > max) max = tmp;
            tmp = 0;
        }
    }
    
    if(tmp > max) max = tmp;

    cout << max << endl;
    
    return 0;
}


Measured memory_bytes: 892
# -*- coding: utf-8 -*-

N = int(input())
X = list(map(int, input().split()))

ans = 10 ** 9
for i in range(min(X), max(X) + 1):
    tmp = 0
    for x in X:
        tmp += (x - i) ** 2
    ans = min(ans, tmp)

print(ans)


Measured memory_bytes: 2940
# cook your dish here
def dijkstra_back(s,t,n,w,cost):
    #sからtへの最短経路の経路復元
    prev = [s] * n #最短経路の直前の頂点
    d = [float("inf")] * n
    used = [False] * n
    d[s] = 0
    
    while True:
        v = -1
        for i in range(n):
            if (not used[i]) and (v == -1):
               v = i
            elif (not used[i]) and d[i] < d[v]:
                v = i
        if v == -1:
               break
        used[v] = True
        
        for i in range(n):
            if d[i] > d[v] + cost[v][i]: 
                d[i] = d[v] + cost[v][i]
                prev[i] = v
        
    path = [t]
    while prev[t] != s:
        path.append(prev[t])
        prev[t] = prev[prev[t]]
    path.append(s)
    path = path[::-1]
    return path

################################
n,w = map(int,input().split()) #n:頂点数　w:辺の数

cost = [[float("inf") for i in range(n)] for i in range(n)] 
#cost[u][v] : 辺uvのコスト(存在しないときはinf この場合は10**10)
for i in range(w):
    x,y,z = map(int,input().split())
    cost[x-1][y-1] = z
    cost[y-1][x-1] = z

check = [[0 for i in range(n)] for j in range(n)]

for i in range(n):
    for j in range(i+1,n):
        tmp = dijkstra_back(i,j,n,w,cost)
        #print(tmp)
        for k in range(len(tmp)-1):
            #print(tmp[k],tmp[k+1])
            check[min(tmp[k],tmp[k+1])][max(tmp[k],tmp[k+1])] = 1

#print(check)

#exit()

print(w - sum(map(sum, check)))

#print(dijkstra_back(0,1,n,w,cost))

Measured memory_bytes: 48220
<?php
fscanf(STDIN, "%d", $n);
fscanf(STDIN, "%s", $s);
$x = $y = 0;
for ($i = $n - 1; $i >= 0; $i--) {
	if ($s[$i] == '(') {
		if ($x <= 0) {
			$y++;
		} else {
			$x--;
		}
	} else {
		$x++;
	}
}
echo str_repeat('(', $x), $s, str_repeat(')', $y);

Measured memory_bytes: 4728
package main

import (
	"fmt"
)

func main() {

	var str string

	var q int

	fmt.Scan(&str)

	fmt.Scan(&q)

	for i := 0; i < q; i++ {

		var a, d string
		var b, c int

		fmt.Scan(&a)

		if a == "print" {
			fmt.Scan(&b, &c)

			fmt.Println(str[b : c+1])

		} else if a == "reverse" {
			fmt.Scan(&b, &c)

			var e []byte

			for i := 0; i < b; i++ {
				e = append(e, str[i])
			}

			for i := c; i >= b; i-- {
				e = append(e, str[i])
			}

			for i := c + 1; i < len(str); i++ {
				e = append(e, str[i])
			}

			str = string(e)

		} else {
			fmt.Scan(&b, &c, &d)

			var e []byte

			for i := 0; i < b; i++ {
				e = append(e, str[i])
			}

			for i := 0; i < len(d); i++ {
				e = append(e, d[i])
			}

			for i := c + 1; i < len(str); i++ {
				e = append(e, str[i])
			}

			str = string(e)
		}

	}

}



Measured memory_bytes: 1484
#include<cstdio>
#include<algorithm>
#include<iostream>
#include<queue>
#include<vector>
#include<cstring>
#include<map>
#include<set>
#include<cstdlib>
#include<bitset>
#define mall (nxd*)mallxc(sizexf(nxd))
using namespace std;
typedef long long ll;
int main(void)
{
	ll x;
	cin>>x;
	if(x==1) cout<<"0";
	else cout<<"1";
}

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

int main() {
  string T, P;
  cin >> T >> P;

  int t = T.size();
  int p = P.size();
  for ( int i = 0; i <= t-p; i++ ) {
    if ( P == T.substr(i, p) ) cout << i << endl;
  }
  
  return 0;
}



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

int main(void){
  int n, m, x;
  int a[100];

  cin >> n >> m >> x;
  for(int i = 0; i < m; i ++) cin >> a[i];

  int sum_left = 0, sum_right = 0;
  int count = 0;

  for(int i = 1; i < x; i ++){
    if(i == a[count]){
      sum_left += 1;
      count ++;
    }
  }
  for(int i = x; i < n; i ++)
    if(i == a[count]){
      sum_right += 1;
      count ++;
    }
  
  cout << min({sum_left, sum_right}) << endl;

  return 0;
}

Measured memory_bytes: 256
#include<stdio.h>

#define MAX 500000
#define INFTY 1000000000

int L[MAX/2+2], R[MAX/2+2];
int sum;

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

  scanf("%d",&n);
  sum = 0;
  for(i = 0 ; i < n ; i++) {
    scanf("%d",&A[i]);
    if(A[i] >= INFTY) {
      return 1;
    }
  }
  mergeSort(A,n,0,n);

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

void merge(int A[], int n, int left, int mid, int right) {
  int i,j,k;
  int n1 = mid - left;
  int n2 = right - mid;

  for(i = 0 ; i < n1 ; i++) {
    L[i] = A[left + i];
  }
  for(i = 0 ; i < n2 ; i++) {
    R[i] = A[mid + i];
  }
  L[n1] = R[n2] = INFTY;
  i = j = 0;
  for(k = left ; k < right ; k++) {
    sum++;
    if(L[i] <= R[j]) {
      A[k] = L[i];
      i = i + 1;
    }
    else {
      A[k] = R[j];
      j = j + 1;
    }
  }
}

void mergeSort(int A[], int n, int left, int right) {
  int mid;

  if(left + 1 < right) {
    mid = (left + right) / 2;
    mergeSort(A,n,left,mid);
    mergeSort(A,n,mid,right);
    merge(A,n,left,mid,right);
  }
}



Measured memory_bytes: 5612
#include <bits/stdc++.h>
using namespace std;
int main() 
{
	ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    // int T;
    // cin>>T;
    // for(int t=0;t<T;t++)
    // {

    
    
    
    // }
    int n,a;
    cin>>n>>a;
    int p=n%500;
    if(p<= a)
    {
    	cout<<"Yes\n";
    }
    else
    	cout<<"No\n";
	return 0;
}


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

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

#define fi first
#define se second
#define repl(i,a,b) for(ll i=(ll)(a);i<(ll)(b);i++)
#define rep(i,n) repl(i,0,n)
#define each(itr,v) for(auto itr:v)
#define pb push_back
#define all(x) (x).begin(),(x).end()
#define dbg(x) cout<<#x"="<<x<<endl
#define mmax(x,y) (x>y?x:y)
#define mmin(x,y) (x<y?x:y)
#define maxch(x,y) x=mmax(x,y)
#define minch(x,y) x=mmin(x,y)
#define uni(x) x.erase(unique(all(x)),x.end())
#define exist(x,y) (find(all(x),y)!=x.end())
#define bcnt __builtin_popcount

#define INF INT_MAX/3

string s;

int main(){
	cin.sync_with_stdio(false);
  cin>>s;
  rep(i,s.size()){
    if(s[i]=='9'){
      cout<<"Yes"<<endl;
      return 0;
    }
  }
  cout<<"No"<<endl;
	return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <cmath>
#include <queue>
#include <set>
#include <map>
#include <iomanip>
#include <fstream>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
const int mod = 1000000007;

int main() {
    ios::sync_with_stdio(false);
    int n, m, a;
    cin >> n >> m;
    while (m--) cin >> a, n -= a;
    if (n < 0) cout << -1;
    else cout << n;
}


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

int Getint(){
	char c = getchar();
	bool flag = false;
	int ans = 0;
	while(c != '-' && (c < '0' || c > '9'))c = getchar();
	if(c == '-')flag = true,c = getchar();
	while(c >= '0' && c <= '9')ans = ans*10 + c-'0',c = getchar();
	return (flag == true) ? -ans : ans;
}

const int maxn = 8 + 2;

int N;
char ch[maxn][maxn];
bool vis_r[maxn*2],vis_c[maxn*2],vis_left[maxn*2],vis_right[maxn*2];

void init(){
	memset(ch,'.',sizeof(ch));
	N = Getint();
	for(int i = 1;i <= N; i++){
		int r,c;
		r = Getint();
		c = Getint();
		ch[r][c] = 'Q';
		int left = r - c + 7;
		int right = r + c;
		vis_c[c] = true;
		vis_r[r] = true;
		vis_left[left] = true;
		vis_right[right] = true;
	}
}

void print(){
	for(int i = 0;i <= 7; i++){
		for(int j = 0;j <= 7; j++){
			printf("%c",ch[i][j]);
		}
		printf("\n");
	}
}

void dfs(int r){
	if(r > 7){
		print();
		exit(0);
	}
	if(vis_r[r] == true){
		dfs(r+1);
		return;
	}
	for(int c = 0;c <= 7; c++){
		int left = r - c + 7;
		int right = r + c;
		if(!vis_c[c] && !vis_left[left] && !vis_right[right]){
			vis_c[c] = true;vis_left[left] = true;vis_right[right] = true;
			ch[r][c] = 'Q';
			dfs(r+1);
			vis_c[c] = false;vis_left[left] = false;vis_right[right] = false;
			ch[r][c] = '.';
		}
	}
}

int main(){
	init();
	dfs(0);
	return 0;
}

Measured memory_bytes: 3076
#include <iostream>
#include <algorithm>
#include <vector>
#include <cmath>
#include <queue>
#include <cstring>
 
using namespace std;
 
#define rep(i, n) for (long long i = 0; i < (n); ++i)
#define repA(i, a, n) for (ll i = a; i <= (n); ++i)
#define repD(i, a, n) for (ll i = a; i >= (n); --i)
#define trav(a, x) for (auto &a : x)
#define all(x) x.begin(), x.endd()
#define sz(x) (ll)(x).size()
#define fill(a) memset(a, 0, sizeof(a))
#define fst first
#define snd second
#define ll long long
#define mp make_pair
#define pb push_back
#define clr(a)	memset(a,0x00,sizeof(a))
typedef long double ld;
 
typedef pair<int, int> pii;
typedef vector<ll> vi;
#define mod 1e9+7
#define MOD 1e9+7
 
bool compare(const pair<long long, long long>&i, const pair<long long, long long>&j)
{
    return i.second < j.second;
}

int calc(int * longest, int i, vector<int> adj[]){
    if(longest[i] >= 0) return longest[i];
    if(adj[i].size() > 0){
        int maxv = -1;
        for(int j : adj[i]){
            maxv = max( calc(longest, j, adj) + 1, maxv );
        }
        longest[i] = maxv;
        
    } else {
        longest[i] = 0;
    }
    return longest[i];
} 

void solve()
{   
    int n,m;
    cin >> n >> m;
    vector<int> adj[n];
    for(int i =0;i<m;++i){
        int x,y;
        cin >> x >> y;
        adj[x-1].push_back(y-1);
    }
    int longest[n];
    memset(longest, -1, sizeof(longest));
    int maxv = -1;
    for(int i = 0;i < n; ++i){
        if(longest[i] == -1){
            longest[i] = calc(longest, i, adj);
        }   
        maxv = max(maxv, longest[i]);
    }   
    cout << maxv;

}
 
 
int main()
{
    cin.sync_with_stdio(0); cin.tie(0);
	cin.exceptions(cin.failbit);
    // long long t;
    // cin >> t;
    // while(t--)
    solve();
}
 
 
// g++ pro.cpp
// ./a.out

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

int d;
int c[26];
int s[365][26];

map<int,int> exist[26];
int sum[26];

int sigma(int x) { return (x+1)*x/2; }

void make_sum(int i) {
    sum[i]=0;
    int last = -1;
    for (auto x:exist[i]) {
        sum[i] += sigma(x.first-last-1);
        last = x.first;
    }
    sum[i] += sigma(d-1-last);
    /*cout << "i=" << (i+1) << ":";
      for (auto x:exist[i]) cout << x << ",";
      cout <<sum[i]<< endl;*/
}


void sol_init(int order[]) {
    rep(i,26) exist[i].clear();
    rep(j,d)  exist[order[j]][j]=1;
    rep(i,26) make_sum(i);
}

int sol_val(int order[]) {
    int ans = 0;
    rep(j,d)  ans += s[j][order[j]];
    rep(i,26) ans -= c[i]*sum[i];
    return ans;
}

int diff(int order[], int j, int x) {
    int i = order[j];
    int ans = - s[j][i] + s[j][x];

    int tmp = sum[i];
    exist[i].erase(j);
    make_sum(i);
    ans -= c[i]*(sum[i]-tmp);
    sum[i]=tmp;
    exist[i][j] = 1;

    tmp = sum[x];
    exist[x][j] = 1;
    make_sum(x);
    ans -= c[x]*(sum[x]-tmp);
    sum[x]=tmp;
    exist[x].erase(j);

    return ans;
}

int diff_1opt(int order[], int j) {
    int max = 0;
    int max_i = order[j];
    rep(i,26) {
        if (i == order[j]) continue;
        int ans = s[j][i];
        int tmp = sum[i];
        exist[i][j] = 1;
        make_sum(i);
        ans -= c[i]*(sum[i]-tmp);
        sum[i]=tmp;
        exist[i].erase(j);

        if (max < ans) {
            max = ans;
            max_i = i;
        }
    }
    return max_i;
}

int main() {
    clock_t start = clock();
    cin >> d;
    rep(i,26) cin >> c[i];
    rep(j,d) {
        rep(i,26) cin >> s[j][i];
    }

    int order[d];
    rep(j,d) {
        int max=s[j][0], max_i = 0;
        rep(i,26) {
            if (max < s[j][i]) {
                max = s[j][i];
                max_i = i;
            }
        }
        order[j] = max_i;
        //cout << (max_i+1) << endl;
    }
    sol_init(order);
    //cout << sol_val(order) << endl;

    //int best_val = sol_val(order);
    //int best_order[d]; memcpy(best_order, order, sizeof(int)*d);
    int j=0, last_j = 0;
    while (j<d) {
        clock_t now = clock();
        if ((now - start)/CLOCKS_PER_SEC > 1.9) break;
        int opt = diff_1opt(order, (last_j+j)%d);
        int dif = diff(order, (last_j+j)%d, opt);
        if (dif > 0) {
            order[(last_j+j)%d]=opt;
            sol_init(order);
            //cout << last_j+j << "->" << opt+1 << "=" << sol_val(order) << endl;
            last_j = (last_j+j)%d;
            j=0;
        }
        j++;
    }
    for (auto x:order) cout << (x+1) << endl;
    //cout << sol_val(order) << endl;
}


Measured memory_bytes: 3700
#include <iostream>
#define int long long
#define MOD 1000000007
//#define _DEBUG
using namespace std;
int N, M;
int mod_times(int a, int b){
    return ((a%MOD)*(b%MOD))%MOD;
}
int pow(int n, int p){
    //cout << n << "," << p << endl;
    if(p==1){
        return n;
    }else if(p%2 == 0){
        int n2 = pow(n, p/2);
        return mod_times(n2, n2);
    }else{
        return mod_times(pow(n, p-1), n);
    }
}
signed main(){
    while(cin >> N >> M){
        cout << pow(N, M) << endl;
    }
}


Measured memory_bytes: 3120
#include <iostream>
#include <vector>
#include <set>

using namespace std;

int main(){
    int n, m;
    cin >> n >> m;
    vector<int> H(n), A(m), B(m);
    set<int> NG;
    for(int i = 0; i < n; i++) cin >> H[i];
    for(int i = 0; i < m; i++){
        cin >> A[i] >> B[i];
        if(H[A[i]-1] == H[B[i]-1]){
            NG.insert(A[i]-1);
            NG.insert(B[i]-1);
        }
        else if(H[A[i]-1] < H[B[i]-1]){
            NG.insert(A[i]-1);
        }
        else{
            NG.insert(B[i]-1);
        }
    }
    cout << n - NG.size();
    return 0;
}


Measured memory_bytes: 7096
#include<bits/stdc++.h>
#define ll          long long
#define pb          push_back
#define eb 			emplace_back
#define mp 			make_pair
#define pii         pair<ll,ll>
#define vi          vector<ll>
#define vii         vector<pii>
#define mi          map<ll,ll>
#define mii         map<pii,ll>
#define all(a)      (a).begin(),(a).end()
#define fi          first
#define si          second
#define sz(x)       (ll)x.size()
#define endl        '\n'
#define checkbit(n, b) ((n >> b) & 1)
#define mod        1000000007
#define puts(n)		cout<<n;
#define rep(i,a,b)  for(ll i=a;i<b;i++)
#define setbits(x) __builtin_popcount(x)
#define mset(m,v) memset(m,v,sizeof(m))
using namespace std;
 
int main(){
ll a,x;
cin>>a;
ll  v[a][3];
rep(i,0,a){
	cin>>v[i][0]>>v[i][1]>>v[i][2];
	if(v[0][0]>= v[0][1] && v[0][0]>=v[0][2])
	x=0;
	else if(v[0][1]>= v[0][0] && v[0][1]>=v[0][2])
	x=1;
	else if(v[0][2]>= v[0][1] && v[0][2]>=v[0][0])
	x=2;
}
ll dp[a][3];
ll ans=0;
mset(dp,0);
ans=dp[0][x]=max(v[0][0],max(v[0][1],v[0][2]));
//dp[0]=max(v[0][0],max(v[0][1],v[0][2]));
dp[0][0]=v[0][0];
dp[0][1]=v[0][1];
dp[0][2]=v[0][2];
rep(i,1,a){
	rep(k,0,3){
		rep(o,0,3){
			if(k!=o){
				dp[i][o]=max(dp[i-1][k]+v[i][o],dp[i][o]);
				ans=dp[i][k];}
		}}	//cout<<ans<<" ";
		
	}cout<<max(dp[a-1][0],max(dp[a-1][1],dp[a-1][2]));

return 0;
	
}

Measured memory_bytes: 4992
#include<iostream>
#include<algorithm>
#include<vector>
#include<map>
using namespace std;
using ll = long long;

int main(){
        string s,t;
        int c1[26]={},c2[26]={};
        cin >> s >> t;
        for(int i=0;i<s.size();i++){
                c1[s[i]-'a']++;
                c2[t[i]-'a']++;
        }
        sort(c1,c1+26);
        sort(c2,c2+26);
        for(int j=0;j<26;j++){
                if(c1[j]!=c2[j]){
                        cout << "No";
                        return 0;
                }
        }
        cout << "Yes";
       return 0;
}

Measured memory_bytes: 776
#include<bits/stdc++.h>
using namespace std;
int a[4];
int main(){
	ios::sync_with_stdio(0);
	//freopen("p.in","r",stdin);
//	freopen("p.out","w",stdout);
	int a2,b;
	cin>>a2>>b;
	a[1]=a2+b;
	a[2]=a2*b;
	a[3]=a2-b;
	sort(a+1,a+4);
	cout<<a[3];
	return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<cmath>
using std::cin;
using std::cout;
using std::endl;
using std::string;

int Dice(int n[6],int a,int b){
  int east;
  int west;
  int sou;
  int nor;
  int g;
  g = 1;
  int t = 0;
  sou = 2;
  east = 3;
  west = 4;
  nor = 5;
  string str;
  if (a == sou){
    str = 'N';
  }else if(a == east){
    str = 'W';
  }else if(a == west){
    str = 'E';
  }else if(a == nor){
    str = 'S';
  }else if(a == 6){
    str = "NN";
  }else{
    str = 'Y';
  }

  for(int i = 0;i < str.length(); i++){
    if(str[i] == 'E'){
      east = g;
      g = west;
      west = 7-east;
    }else if(str[i] == 'W'){
      west = g;
      g = east;
      east = 7-west;
    }else if(str[i] == 'N'){
      nor = g;
      g = sou;
      sou = 7-nor;
    }else if(str[i] == 'S'){
      sou = g;
      g = nor;
      nor = 7-sou;
    }else{
    }
  }
  for(int i = 0; i < 4;i++){
    if(b == sou){
      break;
    }
    int temp = nor;
    nor = east;
    east = sou;
    sou = west;
    west = temp;
  }
  return n[east-1];
}

int main(void){
  int k[6];
  for(int i = 0;i < 6;i++){
    cin >> k[i];
  }
  int q;
  cin >> q;
  int a,b;
  for(int i = 1; i <= q;i++){
    cin >> a >> b;
    for(int j = 0;j < 6;j++){
      if(a == k[j]){
        a = j+1;
      }
      if(b == k[j]){
        b = j+1;
      }
    }
    cout << Dice(k,a,b) <<  endl;
  }
}
      

Measured memory_bytes: 3220
import sys
from collections import deque

def solve():
    input = sys.stdin.readline
    N, u, v = map(int, input().split())
    edge = [[] for _ in range(N)]
    for _ in range(N-1):
        a, b = map(int, input().split())
        edge[a-1].append(b-1)
        edge[b-1].append(a-1)
    par = [int(i) for i in range(N)]
    son = [[] for _ in range(N)]
    q = deque()
    for s in edge[v-1]:
        q.append((s, v-1))
        son[v-1].append(s)
    while q:
        now, pre = q.popleft()
        par[now] = pre
        for s in edge[now]:
            if s != pre:
                son[now].append(s)
                q.append((s, now))

    distAT = 0
    Tnow = u-1
    while Tnow != v-1:
        distAT += 1
        Tnow = par[Tnow]
    
    ans = (distAT - 1) // 2
    turn = u - 1
    for _ in range(ans): turn = par[turn]
    dist = [-1] * N
    q.append((turn, 0))
    maxback = 0
    while q:
        now, d = q.popleft()
        maxback = max(maxback, d)
        for s in son[now]: q.append((s, d+1))

    if distAT % 2 == 0:
        ans += maxback + 1
    else: ans += maxback
    print(ans)

    return 0

if __name__ == "__main__":
    solve()

Measured memory_bytes: 36748
#include <bits/stdc++.h>
using namespace std;
int main() {
  int N, A, b, t;
  cin >> N;
  t = 100;
  for (int i = 0; i < N; i++) {
    b = 0;
    cin >> A;
    while (true) {
      if (A % 2 == 1) {
        if (t > b) {
          t = b;
        }
        break;
      }
      else {
        b++;
        A /= 2;
      }
    }
  }
  cout << t << endl;
}


Measured memory_bytes: 256
w=input()
a=[(i+1)*(j=="0") for i,j in enumerate(w)]
b=[(i+1)*(j=="1") for i,j in enumerate(w)]
l=len(w)
ma=a[0];mb=b[0]
for t in range(1,l+1):
	ma=max(ma,a[t-1])
	mb=max(mb,b[t-1])
	m=min(ma,mb)
	if l-m<t:
		print(t-1)
		exit()
print(l)

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

//10 4
//40 10 20 70 80 10 20 70 80 60
//0  1  2  3  4  5  6  7  8  9
// dp[0]=0;
// dp[1]=30;
// dp[2]=min(dp[1]+10,|dp[0]+20|)=20;
// dp[3]=min(dp[2]+50,dp[1]+60,|dp[0]+30|)=30;
// dp[4]=min(dp[3]+10,dp[2]+60,dp[1]+70,|dp[0]+40|)=40;
// dp[5]=min(dp[4]+70,dp[3]+60,dp[2]+10,|dp[1]+0|)=30;
// dp[6]=min(dp[5]+10,dp[4]+60,dp[3]+50,|dp[2]+0|)=20;
// dp[7]=min(dp[6]+50,dp[5]+60,dp[4]+10,|dp[3]+0|)=30;
// dp[8]=min(dp[7]+10,dp[6]+60,dp[5]+70,|dp[4]+0|)=40;
// dp[9]=min(dp[8]+20,|dp[7]+10|,dp[6]+40,dp[5]+50)=40;
int dp[100050]={0};
#define rep(i,a,b) for(int i=a;i<b;i++)
int main(){
    int n,k;cin>>n>>k;int a[n];rep(i,0,n)cin>>a[i];
    dp[1]=abs(a[1]-a[0]);
    rep(i,2,k+1){//2
        int minimum=INT_MAX;
        rep(j,0,i){//0    
            minimum=min(minimum,dp[i-j-1]+abs(a[i]-a[i-j-1]));//40
        }
        dp[i]=minimum;
    }
    rep(i,k+1,n){//5rep(i,0,k+1)cout<<dp[i]<<" ";
        int minimum=INT_MAX;
        rep(j,0,k){//0
            minimum=min(minimum,dp[i-j-1]+abs(a[i]-a[i-j-1]));
        }
        dp[i]=minimum;
    }
    cout<<dp[n-1]<<"\n";


    return 0;
}

Measured memory_bytes: 1024
#include<bits/stdc++.h>
using namespace std;
#define inf 1000000000
#define INF 1000000000000000
#define ll long long
#define ull unsigned long long
#define M (int)(1e9+7)
#define P pair<int,int>
#define PLL pair<ll,ll>
#define FOR(i,m,n) for(int i=(int)m;i<(int)n;i++)
#define RFOR(i,m,n) for(int i=(int)m;i>=(int)n;i--)
#define rep(i,n) FOR(i,0,n)
#define rrep(i,n) RFOR(i,n,0)
#define all(a) a.begin(),a.end()
#define IN(a,n) rep(i,n){ cin>>a[i]; }
const int vx[4] = {0,1,0,-1};
const int vy[4] = {1,0,-1,0};
#define PI 3.14159265
#define F first
#define S second
#define PB push_back
#define EB emplace_back
void init(){
  cin.tie(0);
  ios::sync_with_stdio(false);
}


int h,w,n;
int sr,sc;
string s,t;
int sx1,sx2,sy1,sy2;

int main(){
  cin>>h>>w>>n;
  cin>>sr>>sc;
  sx1=sc;sx2=sc;
  sy1=sr;sy2=sr;

  cin>>s>>t;

  rep(i,n){
    if(s[i]=='R')
      sx1++;
    if(s[i]=='L')
      sx2--;
    if(s[i]=='D')
      sy1++;
    if(s[i]=='U')
      sy2--;

    if(sx2<1||sx1>w||sy2<1||sy1>h){
      cout<<"NO"<<endl;
      return 0;
    }

    if(t[i]=='R')
      sx2=min(sx2+1,w-1);
    if(t[i]=='L')
      sx1=max(sx1-1,1);
    if(t[i]=='D')
      sy2=min(sy2+1,h-1);
    if(t[i]=='U')
      sy1=max(sy1-1,1);
  }

  cout<<"YES"<<endl;
}


Measured memory_bytes: 776
#include <iostream>
#include <algorithm>
#include <string>

using namespace std;

int h, w, dy[] = {0, 1}, dx[] = {1, 0};
char data[70][70];
string dp[70][70];

main(){
  while(cin >> w >> h && (h|w)){
    for(int i=0;i<h;i++){
      for(int j=0;j<w;j++){
        cin >> data[i][j];
        dp[i][j] = "";
        if('1' <= data[i][j] && data[i][j] <= '9') dp[i][j] += data[i][j];
      }
    }
    for(int i=0;i<h;i++){
      for(int j=0;j<w;j++){
        for(int k=0;k<2;k++){
          int ny = i + dy[k];
          int nx = j + dx[k];
          if(ny<0 || ny>=h) continue;
          if(nx<0 || nx>=w) continue;
          if('0' <= data[ny][nx] && data[ny][nx] <= '9'){
            if(dp[i][j] != "" || data[ny][nx] != '0'){
              string tmp = dp[i][j];
              tmp += data[ny][nx];
              if(dp[ny][nx].size() < tmp.size()) dp[ny][nx] = tmp;
              else if(dp[ny][nx].size() == tmp.size()) dp[ny][nx] = max(dp[ny][nx], tmp);
            }
          }
        }
      }
    }
    string ans = "";
    for(int i=0;i<h;i++){
      for(int j=0;j<w;j++){
        if(ans.size() < dp[i][j].size()) ans = dp[i][j];
        else if(ans.size() == dp[i][j].size()) ans = max(ans, dp[i][j]);
      }
    }
    cout << ans << endl;
  }
}

Measured memory_bytes: 1052
fun main() = abc166b()

@OptIn(ExperimentalStdlibApi::class)
fun abc166b() {
    val (n, k) = readLine()!!.split(' ').map { it.toInt() }
    val aList = (1..k).map {
        readLine()!!.toInt()
        readLine()!!.split(' ').map { it.toInt() }
    }.flatten().toSet()

    val answer = (1..n).count { it !in aList }

    println(answer)
}


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

ll n, a, b;

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

  if (a == 0)
  {
    cout << 0 << endl;
  }
  else
  {
    ll sum = a + b;
    if (a >= n)
    {
      cout << n << endl;
    }

    if (a <= n && n<= sum)
    {
      cout << a << endl;
    }

    if (sum < n)
    {
      ll first = n / sum * a;
      ll second = n % sum;
      if (second <= a)
      {
        cout << first  + second << endl;
      }
      else {
        cout << first + a << endl;
      }
    }
  }
}


Measured memory_bytes: 256
#include <stdio.h>

int main(void)
{
	int i,j,k;
	int n,x;
	int count;

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

		if(n == 0 && x ==0){
			break;
		}
		count = 0;

		for(i = 1;i <= n; i++){
			for(j = i+1; j <= n; j++){	
				for(k = j+1; k <= n; k++){

					if(i + j + k == x){
						count++;
					}
				}
			}
		}
		printf("%d\n",count);
	}

	return 0;	
}

Measured memory_bytes: 600
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <cmath>
#include <set>
#include <map>
#include <queue>
#include<limits.h>
#define rep(i, n) for(int i = 0; i < n; i++)
#define REP(i, m, n) for(int i = m; i < n; i++)
#define ALL(v) v.begin(),v.end()
#define RALL(v) v.rbegin(),v.rend()
#define check(v) rep(i,v.size()) cout << v[i] << " ";\
cout << endl
#define INF 1e8
typedef long long ll;
using namespace std;
//オーバーフローに気をつけろよおおおおおお
//確認忘れるなよおおおおおお

int main() {
    ll h, w; cin >> h >> w;
    ll ans = 1e12;
    for(ll i = 1; i < w; i++){
        ll p1 = i*h;
        ll p2 = 1e12;
        if(i!=w-1) p2 = (w-i)/2*h;
        ll p3 = w*h - p1 - p2;
        ll p4 = (w-i)*(h/2);
        ll p5 = w*h - p1 - p4;
        ans = min(ans,abs(max(p1,max(p2,p3))-min(p1,min(p2,p3))));
        ans = min(ans,abs(max(p1,max(p4,p5))-min(p1,min(p4,p5))));
    }
    for(ll i = 1; i < h; i++){
        ll p1 = i*w;
        ll p2 = 1e12;
        if(i!=h-1) p2 = (h-i)/2*w;
        ll p3 = w*h - p1 - p2;
        ll p4 = (h-i)*(w/2);
        ll p5 = w*h - p1 - p4;
        ans = min(ans,abs(max(p1,max(p2,p3))-min(p1,min(p2,p3))));
        ans = min(ans,abs(max(p1,max(p4,p5))-min(p1,min(p4,p5))));
    }
    cout << ans << endl;
    return 0;
}

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

int main() {
  int N, sum, t;
  cin >> N;
  t = N;
  
  for(; N>0; N/=10) {    
    if(N<10)
      sum += N;
    else
      sum += N % 10;
  }
  
  if(t % sum == 0)
    cout << "Yes" << endl;
  else
    cout << "No" << endl;
}

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

using namespace std;

int main(){
	int n;
	while( scanf(" %d", &n) != EOF ){
		int count=0;
		for(int a=0; a<10; ++a){
			for(int b=0; b<10; ++b){
				for(int c=0; c<10; ++c){
					for(int d=0; d<10; ++d){
						if(a+b+c+d == n) ++count;
					}
				}
			}
		}
	
		printf("%d\n", count);
	}

	return 0;
}

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

using namespace std;

#define YES cout << "YES" << endl;
#define NO  cout << "NO"  << endl;
#define Yes cout << "Yes" << endl;
#define No  cout << "No"  << endl;
 
#define INF INT_MAX
#define MOD 1000000007
#define PI  acos(-1)

using ll  = long long;
using ull = unsigned long long;
using Pii = pair<int, int>;
using Pll = pair<ll, ll>;

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

int main(int argc, char *argv[])
{
    cin.tie(0);
    ios::sync_with_stdio(false);

    int A, B;
    cin >> A >> B;

    cout << (A-B) + 1 << endl;

    return 0;
}

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

int main() {
  long N;
  cin >> N;
  
  long S = 1;
  long A;
  for(int i=0;i<N;i++){
    cin >> A;
    if (A == 0 || S == 0){
      S = 0;
    } else if (A != 0 && A <= (1000000000000000000 / S) && S != -1){
      S *= A;
    } else {
      S = -1;
    }
  }
  
  
  cout << S << endl;
}


Measured memory_bytes: 3636
#include<bits/stdc++.h>
using namespace std;
int main()
{
	int n;
	cin>>n;
	int sum = 0;
	for(int i=1;i<=9;i++)
	{
		for(int j=1;j<=9;j++)
		{
			int mid1=0;
			int mid2=0;
			for(int k=1;k<=n;k++)
			{
				int h=k,t=k%10;
				while(h>=10)
				{
					h/=10;
				}
				if (h == i && t == j)
					mid1++;
				if (h == j && t == i)
					mid2++;
			}
			sum += mid1 * mid2;
		}
	}
	cout<<sum<<endl;
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define i64 long long int
#define pii pair<int,int>
#define mp make_pair
int n;
i64 res;
map<pii,int> s;
int mul(int x,int y){
	return (int)((i64)x*y%998244353);
}
int chk(vector<pii> c){
	int f=0,cnt=0;
	for(auto X : c){
		if(!s.count(X))cnt++;else
		f^=s[X];
	}
	if(cnt==0)return f==0?1:-1;
	if(cnt==1){
		for(auto X : c)
			if(!s.count(X)){
				s[X] = f;
				return 0;
			}
	}
	return 0;
}
int calc(){
	int m;
	scanf("%d%d",&n,&m);
	i64 res = (i64)(n - 1) + (i64)(n-1) * (n-2) / 2 + m;
	while(m --){
		int x,y,z;
		scanf("%d%d%d",&x,&y,&z);
		s[mp(x,y)] = z;
	}
	for(int i=1; i+2 <= n; i++){
		vector<pii> v;
		v.push_back(mp(i,i+2));
		v.push_back(mp(i+1,i+1));
		v.push_back(mp(i+2,i));
		int w = chk(v);
		if(w == 1)res --;else
		if(w == -1)return 0;
	}
	for(int i=1; i+1<=n; i++){
		vector<pii> v;
		v.push_back(mp(i,i));
		v.push_back(mp(i,i+1));
		v.push_back(mp(i+1,i));
		v.push_back(mp(i+1,i+1));
		int w = chk(v);
		if(w == 1)res --;else
		if(w == -1)return 0;
	}
	for(auto X : s){
		pii coord = X.first;
		if(coord.second - coord.first <= 2)continue;
		vector<pii> v;
		v.push_back(coord);
		swap(coord.first, coord.second);
		v.push_back(coord);
		int w = chk(v);
		if(w == 1)res --;else
		if(w == -1)return 0;
	}
	res = (i64)n * n - res;
	int A = 1, B = 2;
	while(1){
		if(res%2)A = mul(A, B);
		if(res/=2)B = mul(B, B);else
			break;
	}
	return A;
}
int main(){
	printf("%d\n",calc());
	return 0;
}


Measured memory_bytes: 4992