akhauriyash/Code-Regression huggingface dataset:
H, W = gets.chomp.split.map(&:to_i)
grid = Array.new
H.times do
  line = gets.chomp
  if line.include?('#')
    grid.push(line)
  end
end
row = Array.new
(W - 1).downto(0) do |i|
  if grid.all? { |l| l[i] == '.' }
    row.push(i)
  end
end
grid.each do |l|
  row.each do |r|
    l[r] = ''
  end
end
puts grid


Measured memory_bytes: 1788
#include <iostream>
#include <vector>
#include <string>
#include <map>
#include <set>
#include <queue>
#include <algorithm>

using namespace std;

#define lli long long int
#define REP(i,n) for(int i=0;i<n;i++)
#define DEBUG 0
#define LIM 1000000007
#define UP 1
#define DOWN 2

string operate(lli sx,lli sy,lli tx,lli ty,lli ope){
	string str="";

	if(ope == UP){
		while(sx < tx){
			str+="R";
			sx++;
		}
		while(sy<ty){
			str+="U";
			sy++;
		}
	}
	else{
		while(sx>tx){
			str+="L";
			sx--;
		}
		while(sy>ty){
			str+="D";
			sy--;
		}
	}
	return str;
}

int main(){
	lli sx,sy,tx,ty;
	cin>>sx>>sy>>tx>>ty;

	string ans="";
	ans+= operate(sx,sy,tx,ty,UP);
	ans+= operate(tx,ty,sx,sy,DOWN);
	ans+= "D"+operate(sx,sy-1,tx+1,ty,UP)+"L";
	ans+= "U"+operate(tx,ty+1,sx-1,sy,DOWN)+"R";

	cout<<ans<<endl;

	return 0;
}

Measured memory_bytes: 256
n=int(input())
a=list(map(int,input().split()))
import numpy as np
count=0
i=0
while i < n:
  while i<n-1:
    if a[i+1]==a[i]:
      i+=1
    else:
      break
  #print(i)
  if i<n-1 and a[i+1]>a[i]:
    while i<n-1 and a[i+1]>=a[i]:
      i+=1
  elif i<n-1 and a[i+1]<a[i]:
    while i<n-1 and a[i+1]<=a[i]:
      i+=1
  count+=1
  i+=1
  #print(i)

print(count)



Measured memory_bytes: 16448
# 回答を見て

x = -1
y = -1
S = list(input())

for i in range(len(S)-1):
    if S[i] == S[i+1]:
        x = i+1
        y = x+1
        break
    elif i+2<=len(S)-1:
        if S[i] == S[i+2]:
            x = i+1
            y = x+2
            break
        else:
            pass
    else:
        pass
print(x, y)

Measured memory_bytes: 3956
#include <iostream>
using namespace std;
int main(void){
    int a, b, k;
    cin >> a >> b >> k;
    if(b+1-a >= 2*k){
        for(int i = 0; i < k; i ++) cout << a+i << "\n";
        for(int i = k-1; i >= 0; i --) cout << b-i << "\n";
    }
    else{
        for(int i = a; i <= b; i ++) cout << i << "\n";
    }
}


Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<map>
using namespace std;
int main(){
    map<char,int> x;
    string s;
    cin>>s;
    for(auto i:s)
        ++x[i];
    bool check=true;
    for(auto i:x)
        if(i.second%2)
            check=false;
    cout<<(check ? "Yes":"No")<<endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
const int maxn = 2e5 + 10;
int n,k,a[maxn],d[maxn];
int main() {
	scanf("%d%d",&n,&k);
	for (int i = 1; i <= n; i++)
		scanf("%d",&a[i]);
	while (k--)	{
		bool f = true;
		for (int i = 1; i <= n; i++)
			if (a[i] != n) f = false;
		if (f) break;
		for (int i = 0; i <= n + 1; i++)
			d[i] = 0;
		for (int i = 1; i <= n; i++) {
			int l = max(i - a[i],1), r = min(i + a[i],n);
			d[l]++,d[r + 1]--;
		}
		for (int i = 1; i <= n; i++)
			d[i] += d[i - 1];
		for (int i = 1; i <= n; i++)
			a[i] = d[i];
	}
	for (int i = 1; i <= n; i++)
		printf("%d%s",a[i],i == n ? "\n" : " ");
	return 0;
}

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

int main() {
  	long long a,b,c,k,ans;
  
  	cin >> a >> b >> c >> k;
  	if (a>=k)
    {
      	ans=k;
    }
  	else if (b>=(k-a))
    {
      	ans = a;
    }
  	else
	{
      	ans=a-(k-a-b);
    }
  	cout << ans << endl;
}


Measured memory_bytes: 3668
#include<bits/stdc++.h>
using namespace std;
int fun(int n, int m){
	if(n == 0){
  		return (m)*(m-1)/2;
    }else if(m == 0){
    	return n*(n-1)/2;
    }else{
    	return n*(n-1)/2 + m*(m-1)/2;
    }
}
int main(){
	int n,m;
  cin>>n>>m;
  cout<<fun(n, m)<<endl;
  return 0;
}

Measured memory_bytes: 256
#include<cstdio>
typedef long long ll;
const int mod=998244353;
int w[1000050],cnt[1000050];
int main(){
	int n,m=0,i,j,x,sum,ans=0;
	scanf("%d",&n);
	for(i=0;i<n;++i){
		scanf("%d",&x);
		if(x>m)m=x;
		++cnt[x];
	}
	for(i=2,w[1]=1;i<=m;++i)w[i]=(ll)(mod-mod/i)*w[mod%i]%mod;
	for(i=1;i<=(m>>1);i++)
		for(j=(i<<1);j<=m;j+=i){w[j]-=w[i];if(w[j]<0)w[j]+=mod;}
	for(i=1;i<=m;i++){
		for(j=i,sum=0;j<=m;j+=i){
			ans=(ans+((ll)sum*j%mod*cnt[j]+((ll)cnt[j]*(cnt[j]-1)>>1ll)%mod*j%mod*j)%mod*w[i])%mod;
			sum=(sum+(ll)j*cnt[j])%mod;
		}
	}
	printf("%d\n",ans);
	return 0;
}


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

using namespace std;

typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<pii> vii;
typedef vector<vi> vvi;
typedef vector<pll> vll;
typedef vector<vl> vvl;

#define fori(i, n) for (int i = 0; i < n; i++)
#define ford(i, n) for (int i = n - 1; i >= 0; i--)
#define rep(i, a, b) for (int i = a; i <= b; i++)
#define repd(i, a, b) for (int i = a; i >= b; i--)
#define trav(x, a) for (auto &x : a)
#define all(x) (x).begin(), (x).end()
#define pb push_back
#define eb emplace_back
#define endl '\n'
#define sz(a) (int)(a).size()
#define fi first
#define se second

clock_t time_p = clock();
void time_taken()
{
    time_p = clock() - time_p;
    cerr << "Time Taken : " << (float)(time_p) / CLOCKS_PER_SEC << "\n";
}

const ll mod = 1e9 + 7;
const ll INF = 1e18;

const ld EPS = 1e-8;

#define TRACE
#ifdef TRACE
#define trace(...) { cerr<<"[ "; __trace__(#__VA_ARGS__, __VA_ARGS__);}
#undef endl
template <typename Arg1,typename Arg2>
ostream& operator << (ostream& out, const pair<Arg1,Arg2> &x) {
    return out<<"("<<x.first<<","<<x.second<<")";
}
 
template <typename Arg1>
ostream& operator << (ostream& out, const vector<Arg1> &a) {
    out<<"[";for(const auto &x:a)out<<x<<",";return out<<"]";
}
 
template <typename Arg1>
ostream& operator << (ostream& out, const set<Arg1> &a) {
    out<<"[";for(const auto &x:a)out<<x<<",";return out<<"]";
}
 
template <typename Arg1,typename Arg2>
ostream& operator << (ostream& out, const map<Arg1,Arg2> &a) {
    out<<"[";for(const auto &x:a)out<<x<<",";return out<<"]";
}
 
template <typename Arg1>
void __trace__(const string name, Arg1&& arg1){
    cerr << name << " : " << arg1 << " ] " << endl;
}
 
template <typename Arg1, typename... Args>
void __trace__(const string names, Arg1&& arg1, Args&&... args){
    const string name = names.substr(0,names.find(','));
    cerr<<name<<" : "<<arg1<<" | ";
    __trace__(names.substr(1+(int)name.size()), args...);
}
#else
    #define trace(args...)
#endif
 

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

    int n, k;
    cin >> n >> k;
    vi a(n);
    fori(i, n) cin >> a[i];
    ll lo = 1, hi = 1e9;
    ll ans = 1e9;
    while (lo <= hi)
    {
        ll mid = (lo + hi) / 2;
        ll req = 0;
        fori(i, n)
        {
            req += (a[i] + mid - 1) / mid - 1;
        }
        // trace(mid,req);
        if (req <= k)
        {
            ans = mid;
            hi = mid - 1;
        }
        else{
            lo = mid + 1;
        }
    }
    cout << ans << endl;

    time_taken();
    return 0;
}

Measured memory_bytes: 3968
#include<stdio.h>

int main(){
  //counter
  int i,j;

  //input
  int n;
  scanf("%2000000d",&n);
  
  int A[n];
  int k=0;  // TODO serching "k"
  for(i=0;i<n;i++){
    scanf("%10000d",&A[i]);
    if(A[i]>k){
      k = A[i];
  }
  }

  
  //Counting Sort

  int C[k+1];
  for(i=0;i<k+1;i++){
    C[i] = 0;
  }
  for(j=0;j<n;j++){
    C[A[j]]++;
  }
  for(i=1;i<k+1;i++){
    C[i] = C[i] + C[i-1];
  }
    int B[n];
    for(j=(n-1);j>=0;j--){
    B[C[A[j]]-1] = A[j];
    C[A[j]]--;
    }

  //output
  for(i=0;i<n-1;i++){
    printf("%d ",B[i]);
  }
  printf("%d\n",B[n-1]);
  


    return 0;
}



Measured memory_bytes: 17388
#include <bits/stdc++.h>
using namespace std;
 
using ll = long long int;
using ull = unsigned long long int;
using P = pair<ll, ll>;
using P3 = pair<ll, P>;
using PP = pair<P ,P>;
constexpr ll MOD = ll(1e9+7);
constexpr int IINF = INT_MAX;
constexpr ll LLINF = LLONG_MAX;
constexpr int MAX_N = int(1e6) + 5;
constexpr double EPS = 1e-8;
constexpr int di[] = {0, 1, 0, -1}, dj[] = {1, 0, -1, 0};
#define REP(i, n) for (int i = 0; i < n; i++)
#define REPR(i, n) for (int i = n; i >= 0; i--)
#define SORT(v) sort((v).begin(), (v).end())
#define SORTR(v) sort((v).rbegin(), (v).rend())
#define ALL(v) (v).begin(), (v).end()
 
int main(){
    ll n, ans;
    cin >> n;
    ans = n;
    for(ll i=1;i*i<=n;i++){
        if(n%i == 0){
            ans = min(ans, i+n/i-2);
        }
    }
    cout << ans << endl;
    return 0;
}

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

const int MAX = 510;
const int INF = 1e9;
const int MOD = 1e9 + 7;
 
int N, K, A[MAX];

bool func(int x){
    vector<int> a;
    rep(i, N) a.push_back(A[i] % x);

    sort(a.begin(), a.end());

    vector<int> sum1(N + 1, 0);
    rep(i, N) sum1[i + 1] = sum1[i] + a[i];

    vector<int> sum2(N + 1, 0);
    rep(i, N) sum2[i + 1] = sum2[i] + (a[i] - x);

    rep(i, N){
        int plus = sum1[i] - sum1[0];
        int minus = sum2[N] - sum2[i];

        if(minus + plus == 0 && plus <= K) return true;
    }

    return false;
}

int main(){
    cin >> N >> K;
    rep(i, N) cin >> A[i];

    int sum = accumulate(A, A+N, 0);

    int ans = 1;
    for(int i = 1; i * i <= sum; ++i){
        if(sum % i == 0){
            int x = i;
            if(func(x)) ans = max(ans, x);

            x = sum / i;
            if(func(x)) ans = max(ans, x);
        }
    }

    cout << ans << endl;
}

Measured memory_bytes: 256
#define P(s) {printf(s"\n");continue;}
main(m,f,r,s){for(;;){scanf("%d%d%d",&m,&f,&r);if((s=m+f)+r==-3)exit(0);if((m==-1)|(f==-1)|(s<30))P("F")if(s>=80)P("A")if(s>=65)P("B")if((s>=50)|(r>=50))P("C")P("D")}}

Measured memory_bytes: 584
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int a = sc.nextInt();
		int b = sc.nextInt();
		int c = sc.nextInt();
		int k = sc.nextInt();
		
		int ans = k <= a ? k : k <= a + b ? Math.min(k, a) : a - Math.min(k - a - b, c); 
		
		System.out.println(ans);
	}
}


Measured memory_bytes: 27020
#include<cstdio>
#include<ctime>

#define gec     getchar
#define FILE(F) freopen(F".in","r",stdin),freopen(F".out","w",stdout)
#define RunTime fprintf(stderr,"Running Time:%.5lfs\n",1.*clock()/1e6)

typedef long long ll;
typedef long double lb;
template<typename T>void umin(T &x,T y){if(x>y)x=y;}
template<typename T> T min(T x,T y){return x<y?x:y;}
template<typename T>void umax(T &x,T y){if(x<y)x=y;}
template<typename T> T max(T x,T y){return x>y?x:y;}
template<typename T>
inline void read(T &x)
{
	x=0;bool f=0; char c=gec();
	for(;c<'0'||c>'9';c=gec())f=(c=='-');
	for(;c>='0'&&c<='9';c=gec())x=x*10+c-'0';
	x=f?-x:x;
}

namespace DEBUG{
inline void fpr(char *c){fprintf(stderr,"%s\n",c);}
inline void fpr(int    x,char *c){fprintf(stderr,"[ %s ] : = %d   \n",c,x);}
inline void fpr(ll     x,char *c){fprintf(stderr,"[ %s ] : = %lld \n",c,x);}
inline void fpr(double x,char *c){fprintf(stderr,"[ %s ] : = %.5lf\n",c,x);}
inline void fpr(lb     x,char *c){fprintf(stderr,"[ %s ] : = %.5Lf\n",c,x);} 
}using namespace DEBUG;

const int MAXN(100010);
int n;
	
namespace Graph
{
	struct Node
	{
		int nd,nx;
	}bot[MAXN<<1];int tot,first[MAXN];
	void add(int a,int b)
	{bot[++tot]=(Node){b,first[a]};first[a]=tot;
	 bot[++tot]=(Node){a,first[b]};first[b]=tot;}
	int Siz[MAXN],st[MAXN],tp,pos,Dep[MAXN];
	void DFS(int x,int f)
	{
		st[++tp]=x; Siz[x]=1;
		if(x==n)pos=st[tp-((tp-2)/2)];
		for(int v=first[x],y;v;v=bot[v].nx)
		if((y=bot[v].nd)!=f)
			DFS(y,x),Siz[x]+=Siz[y];
		tp--;
	}
		
}using namespace Graph;

int main()
{
	read(n);
	for(int i=1,a,b;i<n;i++)
	{
		read(a);read(b);
		add(a,b);
	}
	DFS(1,0);
	printf((n-Siz[pos])>Siz[pos]?"Fennec\n":"Snuke\n");
	return 0;
}	

Measured memory_bytes: 7552
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define FOR(i,a,b) for(int i=(a); i<=(b); i++)
#define rep(i,n) for(int i = 0; i < (n); i++)
#define chmin(a,b) if((a)>(b)) (a)=(b);
#define chmax(a,b) if((a)<(b)) (a)=(b);
#define vi vector<int>
#define pii pair<int,int>
#define all(v) (v).begin(),(v).end()
#define allr(v) (v).rbegin(),(v).rend()
#define pb push_back
#define pf push_front
int gcd(int a,int b){/*a>=0,b>=0,￢(a=b=0)*/
  while(min(a,b)>0){if(a<b)swap(a,b);a%=b;}return max(a,b);
}
int dx[]={1,0,-1,0,1,-1,-1,1};
int dy[]={0,1,0,-1,1,1,-1,-1};
const int MOD = 1e9+7;
const int INF = 1e18+10;

/*----------------------------------------------*/


signed main(){
  rep(i,5){
    int a;
    cin>>a;
    if(a==0){
      cout<<i+1<<endl;
      return 0;
    }
  }

  return 0;
}


Measured memory_bytes: 3592
#include<bits/stdc++.h>
#define ci const int&
#define C(x,y) (1ll*fac[x]*invf[y]%mod*invf[x-(y)]%mod)
using namespace std;
const int mod=1e9+7;
struct edge{
	int t,nxt;
}e[210];
int n,m,k,fac[210],invf[210],u,v,dfn[55],low[55],cnt,be[55],tot,vis[55],q[55],sz,tn,en[110],in[55],ans=1,t;
vector<int>ps[110];
void add(ci x,ci y){
	e[++cnt].t=y,e[cnt].nxt=be[x],be[x]=cnt;
}
void dfs(ci x,ci f){
	dfn[x]=low[x]=++tot,q[++sz]=x;
	for(int i=be[x];i;i=e[i].nxt)if(!dfn[e[i].t]){
		dfs(e[i].t,x),low[x]=min(low[x],low[e[i].t]);
		if(low[e[i].t]>=dfn[x]){
			++tn,ps[tn].push_back(x);
			while(q[sz]!=e[i].t)ps[tn].push_back(q[sz--]);
			ps[tn].push_back(q[sz--]);
		}
	}else if(e[i].t!=f)low[x]=min(low[x],dfn[e[i].t]);
}
void dfs2(ci x,ci id){
	vis[x]=id;
	for(int i=be[x];i;i=e[i].nxt)if(in[e[i].t]==id){
		++en[id];
		if(vis[e[i].t]!=id)dfs2(e[i].t,id);
	}
}
int gcd(ci x,ci y){
	return y?gcd(y,x%y):x;
}
int POW(int x,int y){
	int ret=1;
	while(y)y&1?ret=1ll*ret*x%mod:0,x=1ll*x*x%mod,y>>=1;
	return ret;
}
int main(){
	scanf("%d%d%d",&n,&m,&k),fac[0]=1;
	for(int i=1;i<=m+k;++i)fac[i]=1ll*fac[i-1]*i%mod;
	invf[m+k]=POW(fac[m+k],mod-2);
	for(int i=m+k-1;i>=0;--i)invf[i]=1ll*invf[i+1]*(i+1)%mod;
	for(int i=1;i<=m;++i)scanf("%d%d",&u,&v),add(u,v),add(v,u);
	for(int i=1;i<=n;++i)if(!dfn[i])sz=0,dfs(i,0);
	for(int i=1;i<=tn;++i){
		for(int j=0;j<ps[i].size();++j)in[ps[i][j]]=i;
		dfs2(ps[i][0],i),en[i]>>=1;
		if(en[i]==1)ans=1ll*ans*k%mod;
		else if(en[i]==ps[i].size()){
			t=0;
			for(int j=0;j<ps[i].size();++j){
				t=(t+POW(k,gcd(j,ps[i].size())))%mod;
			}
			t=1ll*t*POW(ps[i].size(),mod-2)%mod;
			ans=1ll*ans*t%mod;
		}else ans=1ll*ans*C(en[i]+k-1,k-1)%mod;
	}
	printf("%d",ans);
	return 0;
}

Measured memory_bytes: 256
//Segment Tree
#include <iostream>
#include <vector>

using namespace std;

int INIT = 2147483647;

class SegmentTree {
    int size;
    vector<int> p;
public:
    SegmentTree(int n) {
        // 0-indexed
        size = 1;
        while(size<n) size *= 2;
        p = vector<int>(2*size-1, INIT);
    }

    void update(int i, int x) {
        int s = size+i-1;
        p[s] = x;
        while(s > 0) {
            s = (s - 1) / 2;
            p[s] = min(p[2*s+1], p[2*s+2]);
        }
    }

    int find(int s, int t) {
        return query(s, t, 0, 0, size);
    }

    int query(int s, int t, int k, int l, int r) {
        if(r<=s || t<=l) return INIT;
        if(s<=l && r<=t) return p[k];
        int lv = query(s, t, 2*k+1, l, (l+r)/2);
        int rv = query(s, t, 2*k+2, (l+r)/2, r);
        return min(lv, rv);
    }
};

int main() {
    int n, q, com, x, y;
    cin >> n >> q;
    SegmentTree S(n);

    for(int i = 0; i < q; i++) {
        cin >> com >> x >> y;
        if(com == 0) {
            S.update(x, y);
        }
        else if(com == 1) {
            cout << S.find(x, y+1) << endl;
        }
    }
}



Measured memory_bytes: 3912
#!/usr/bin/env python3
import collections

S = input()
c = collections.Counter(S)
ans = "No"

if (c["N"] > 0 and c["S"] > 0) or (c["N"] == 0 and c["S"] == 0):
    if (c["W"] > 0 and c["E"] > 0) or (c["W"] == 0 and c["E"] == 0):
        ans = "Yes"

print(ans)


Measured memory_bytes: 3316
#include<bits/stdc++.h>
using namespace std;
int main() {
	string s, t, u;
	int a, b;
	cin >> s >> t >> a >> b >> u;
	if(s == u) {
		cout << a-1 << " " << b << endl;
	}
	else cout << a << " " << b-1 << endl;
	return 0;
}


Measured memory_bytes: 256
N, A, B = map(int, input().split())
vs = list(map(int, input().split()))

vs.sort(reverse=True)
print(sum(vs[:A]) / A)

iVA = vs.index(vs[A - 1])
numVA = vs.count(vs[A - 1])

comb = [0] * (numVA + 1)
comb[0] = 1
for k in range(1, numVA + 1):
    comb[k] = comb[k - 1] * (numVA - k + 1) // k

if vs[0] != vs[A - 1]:
    print(comb[A - iVA])
else:
    ans = 0
    for k in range(A - iVA, min(B, numVA) + 1):
        ans += comb[k]
    print(ans)


Measured memory_bytes: 3064
ls = {"A":0, "B":1, "C":2}
cup = [1,0,0]
while 1:
    try:
        x, y = map(str, raw_input().split(","))
        tmp = cup[ls[x]]
        cup[ls[x]] = cup[ls[y]]
        cup[ls[y]] = tmp
    except:
        break
p = cup.index(1)
if p == 0:
    print "A"
else:
    print "B" if p == 1 else "C"

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

int main(){
  int N;
  cin >> N;
  vector<int> A(N);
  int all = 0;
  REP(i,N) {
    cin >> A[i];
    all ^= A[i];
  }
  REP(i,N) {
    cout << (all ^ A[i]) << " ";
  }
  cout << endl;

}


Measured memory_bytes: 4048
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i=0; i<(n); ++i)
#define REP(i, d, n) for(int i=(d); i<(n); ++i)
typedef long long ll;
const int mod = 1e9 + 7;

int main() {

    int dp[100001] = {};

    for(int i=1; i<=100000; i++){
        dp[i] = dp[i-1] + 1;
        for(int j=6; j<=i; j*=6){
            dp[i] = min(dp[i], dp[i-j]+1);
        }
        for(int k=9; k<=i; k*=9){
            dp[i] = min(dp[i], dp[i-k]+1);
        }
    }

    int n;
    cin >> n;

    cout << dp[n] << endl;

    return 0;
}

Measured memory_bytes: 640
/* package whatever; // don't place package name! */

import java.util.*;
import java.lang.*;
import java.io.*;

/* Name of the class has to be "Main" only if the class is public. */
public class Main
{
	public static void main (String[] args) throws java.lang.Exception
	{
		// your code goes here
		Scanner sc = new Scanner(System.in);
		
		int n = sc.nextInt();
		int k = sc.nextInt();
		int[] dp = new int[n];
		int[] arr = new int[n];
		
		for(int i = 0; i<n; i++){
			arr[i] = sc.nextInt();
		}
		
		dp[0] = 0;
		int j;
		for(int i = 1; i<n; i++){
			j = i;
			dp[i] = Integer.MAX_VALUE;
			while(j>0 && j>i-k){
				dp[i] = Math.min(Math.abs(arr[i]-arr[j-1]) + dp[j-1], dp[i]);
				j--;
			}
		}
		
		// System.out.println(Arrays.toString(dp));
		
		System.out.println(dp[n-1]);
	}
}

Measured memory_bytes: 49172
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
using ull = unsigned long long;
#define re(i,n) for(ll i=0;i<(n);++i)
#define itn int
#define ocut cout
#define ouct cout
#define outc cout

int main(){
    int h,w,n;
    cin >> h >> w >> n;
    if(w<h){
        w=h;
    }
    int a = n/w;
    if(n%w!=0){
        a++;
    }
    cout << a;
}


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

using namespace std;

int main() {
    int a, b, c;
    cin >> a >> b >> c;
    if (a == 7 && b == 5 && c == 5) {
        cout << "YES";
    }
    else if (a == 5 && b == 7 && c == 5) {
        cout << "YES";
    }
    else if (a == 5 && b == 5 && c == 7) {
        cout << "YES";
    }
    else {
        cout << "NO";
    }
}


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

#define ln                 '\n'
#define all(dat)           dat.begin(), dat.end()
#define loop(i, to)        for (int i = 0; i < to; ++i)
#define cont(i, to)        for (int i = 1; i <= to; ++i)
#define circ(i, fm, to)    for (int i = fm; i <= to; ++i)
#define foreach(i, dat)    for (__typeof(dat.begin()) i = dat.begin(); i != dat.end(); ++i)

typedef long long          num;

using namespace std;

const int nsz = 2e5;
const num inf = 0x3f3f3f3f3f3f3f3f;
int n, d, a[nsz + 5];
num w1[nsz + 5], w2[nsz + 5];
pair<int, int> dat[nsz + 5];
vector< pair<num, pair<int, int> > > e;

struct segment_tree {
	#define ls  (u << 1)
	#define rs  (u << 1 | 1)
	int fm[4 * nsz + 5];
	num mn[4 * nsz + 5];
	
	void inline up(int u) {
		mn[u] = min(mn[ls], mn[rs]);
		fm[u] = mn[ls] < mn[rs] ? fm[ls] : fm[rs];
	}
	
	void init(num a[], int u = 1, int l = 1, int r = n) {
		if (l == r) { mn[u] = a[l], fm[u] = l; return; }
		int md = (l + r) >> 1;
		init(a, ls, l, md);
		init(a, rs, md + 1, r);
		up(u);
	}
	
	void upd(int id, num w, int u = 1, int l = 1, int r = n) {
		if (l == r) { mn[u] = w; return; }
		int md = (l + r) >> 1;
		id <= md ? upd(id, w, ls, l, md) : upd(id, w, rs, md + 1, r);
		up(u);
	}
	
	pair<num, int> qry(int el, int er, int u = 1, int l = 1, int r = n) {
		if (l >= el && r <= er)  return {mn[u], fm[u]};
		int md = (l + r) >> 1;
		pair<num, int> res = {inf, 0};
		if (el <= md)  res = qry(el, er, ls, l, md);
		if (er > md) {
			pair<num, int> tmp = qry(el, er, rs, md + 1, r);
			if (res.first > tmp.first)  res = tmp;
		}
		return res;
	}
};
segment_tree tr1, tr2;

struct union_find {
	int sz, pr[nsz + 5];
	
	int inline operator [] (int id) { return qry(id); }
	
	void inline init(int sz = n) {
		this->sz = sz;
		cont (u, n)  pr[u] = u;
	}
	
	int qry(int u) {
		return pr[u] == u ? u : pr[u] = qry(pr[u]);
	}
	
	bool inline link(int u, int v) {
		int pu = qry(u), pv = qry(v);
		if (pu == pv)  return 0;
		pr[pv] = pu;
		return 1;
	}
};
union_find uf;

num inline w(int u, int v) {
	if (u < v)  swap(u, v);
	return w1[u] + w2[v];
}

num inline kruskal(vector< pair<num, pair<int, int> > > &e = ::e) {
	int cnt = 0;
	num res = 0;
	uf.init();
	sort(all(e));
	loop (i, e.size()) {
		int u = e[i].second.first, v = e[i].second.second;
		num w = e[i].first;
		if (uf.link(u, v)) {
			res += w;
			if (++cnt == n - 1)  break;
		}
	}
	return res;
}

int main() {
	scanf("%d%d", &n, &d);
	cont (i, n) {
		scanf("%d", &a[i]);
		dat[i] = make_pair(a[i], i);
		w1[i] = (num) a[i] + (num) d * i;
		w2[i] = (num) a[i] - (num) d * i;
	}
	sort(dat + 1, dat + n + 1);
	tr1.init(w1);
	tr2.init(w2);
	for (int i = n; i >= 1; --i) {
		int u = dat[i].second, v1 = u != 1 ? tr2.qry(1, u - 1).second : 0, v2 = u != n ? tr1.qry(u + 1, n).second : 0;
		if (v1)  e.push_back({w(u, v1), {u, v1}});
		if (v2)  e.push_back({w(u, v2), {u, v2}});
		tr1.upd(u, inf);
		tr2.upd(u, inf);
	}
	printf("%lld\n", kruskal());
}

Measured memory_bytes: 34796
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(n);++i)
#define ALL(A) A.begin(), A.end()

using namespace std;

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

void disp_stone(vector<vector<char> > s, int H, int W){
	cerr << endl;
	rep (i, H){
		rep (j, W){
			cerr << s[i][j];
		} // end rep
		cerr << endl;
	} // end rep
}

// 落ちきった状態を作り出す
vector<vector<char> > all_fall(vector<vector<char> > s, int H, int W){
	vector<vector<char> > t = s;
//	disp_stone(t, H, W);
	while(true){
		bool update = false;
		for (int i = 0; i < H-1; ++i){
			for (int j = 0; j < W; ++j){
				if (t[i][j] != '0' && t[i+1][j] == '0'){
					swap(t[i][j], t[i+1][j]);
					update |= true;
					break;
				} // end if
			} // end for
			if (update) break;
		} // end for
		if (!update) break;
	} // end while
//	disp_stone(t, H, W);
	
	return t;
}

// 消滅する状態を作り出す
int disappear(vector<vector<char> > &s, int H, int W, int K){
	int score = 0;
	for (int i = 0; i < H; ++i){
		int left = 0, right = 0;
		while(right < W){
			while (s[i][left] == s[i][right] && right < W){
				++right;
			} // end while
			if (right - 1 - left + 1 >= K){
				score += (right - 1 - left + 1)*(int)(s[i][left] - '0');
				for (int j = left; j < right; ++j){
					s[i][j] = '0';
				} // end for
			} // end if
			left = right;
		} // end while
	} // end for
	
	return score;
}

// 状態が変化しなくなるまでシミュレーション
int smulate(vector<vector<char> > s, int H, int W, int K){

	vector<vector<char> > t;
	int score = 0;
	for(int i = 0;; ++i){
		t = all_fall(s, H, W);
		if (t == s) break;
		score += (1<<i) * disappear(t, H, W, K);
		s = t;		
	} // end for
	
	return score;
}

int main()
{
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	int H, W, K; cin >> H >> W >> K;
	vector<vector<char> > stones(H, vector<char>(W, 0));
	rep (i, H){
		rep (j, W){
			cin >> stones[i][j];
		} // end rep
	} // end rep

	int res = 0;
	rep (i, H){
		rep (j, W){
			vector<vector<char> > s = stones;
			s[i][j] = '0';
			int curr = smulate(s, H, W, K);
			res = max(res, curr);
		} // end rep
	} // end rep

	cout << res << endl;

	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define F first
#define S second
#define R cin>>
#define Z class
#define ll long long
#define ln cout<<'\n'
#define in(a) insert(a)
#define pb(a) push_back(a)
#define pd(a) printf("%.10f\n",a)
#define mem(a) memset(a,0,sizeof(a))
#define all(c) (c).begin(),(c).end()
#define iter(c) __typeof((c).begin())
#define rrep(i,n) for(ll i=(ll)(n)-1;i>=0;i--)
#define REP(i,m,n) for(ll i=(ll)(m);i<(ll)(n);i++)
#define rep(i,n) REP(i,0,n)
#define tr(it,c) for(iter(c) it=(c).begin();it!=(c).end();it++)
template<Z A>void pr(A a){cout<<a;ln;}
template<Z A,Z B>void pr(A a,B b){cout<<a<<' ';pr(b);}
template<Z A,Z B,Z C>void pr(A a,B b,C c){cout<<a<<' ';pr(b,c);}
template<Z A,Z B,Z C,Z D>void pr(A a,B b,C c,D d){cout<<a<<' ';pr(b,c,d);}
template<Z A>void PR(A a,ll n){rep(i,n){if(i)cout<<' ';cout<<a[i];}ln;}
ll check(ll n,ll m,ll x,ll y){return x>=0&&x<n&&y>=0&&y<m;}
const ll MAX=1e9+7,MAXL=1LL<<61,dx[4]={-1,0,1,0},dy[4]={0,1,0,-1};
typedef pair<ll,ll> P;

void Main() {
  ll n,m;
  cin >> n >> m;
  if(n==m) pr("Yes");
  else pr("No");
}

int main(){ios::sync_with_stdio(0);cin.tie(0);Main();return 0;}


Measured memory_bytes: 256
import java.io.BufferedReader;
import java.io.InputStreamReader;

public class Main {

	public static void main(String[] args) throws Exception {
		BufferedReader bf = new BufferedReader(new InputStreamReader(System.in));

		// 一行目
		String s = bf.readLine().replace(" ", "");
		double tmp = Math.sqrt(Integer.parseInt(s));
		tmp -= (int)tmp;
		System.out.println((tmp > 0) ? "No" : "Yes");


	}
}


Measured memory_bytes: 22356
#include <bits/stdc++.h>
#define rep(i, n) for (ll i = 0; i < (n); ++i)
#define rep1(i, n) for (ll i = 1; i <= (n); ++i)
#define rrep(i, n) for (ll i = (n - 1); i >= 0; --i)
#define ALL(obj) (obj).begin(), (obj).end()
#define pb push_back
#define to_s to_string
#define len(v) (int)v.size()
#define UNIQUE(v) v.erase(unique(v.begin(), v.end()), v.end())
#define print(x) cout << (x) << '\n'
#define debug(x) cout << #x << ": " << (x) << '\n'
using namespace std;
using ll = long long;
typedef pair<ll, ll> P;
ll MOD = 1e9 + 7;
ll devc(ll x, ll y) { return 1 + (x - 1) / y; }

const int MAX = 510000;

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

int main()
{
    cin.tie(0);
    ios::sync_with_stdio(0);
    cout << fixed << setprecision(20);

    ll n, k;
    cin >> n >> k;

    COMinit();
    ll ans = 0;
    for (ll i = 0; i <= min(n - 1, k); ++i){
        ans += COM(n, i) * COM(n - 1, i) % MOD;
        ans %= MOD;
    }
    print(ans);

    return 0;
}

Measured memory_bytes: 12160
while True:
    n=int(input())
    if n==0:
        break
    ans=0
    for i in range (1,n+1):
        s=i
        for j in range(i+1,n+1):
            s+=j
            if s==n:
                ans+=1
                break
            elif s>n:
                break
    print(ans)


Measured memory_bytes: 5592
#include<iostream>
using namespace std;
int main(){
  int a,b;
  cin >> a >> b;
  int all[a] = {};
  int c;
  for(int i = 0;i < b;i++){
    cin >> c;
    int d[c];
    for(int j = 0;j < c;j++){
      cin >> d[j];
    }
    for(int j = 0;j < c;j++){
      all[d[j]-1] += 1;
    }
  }
  int end = 0;
  for(int i = 0;i < a;i++){
    if(all[i] == 0){
      end += 1;
    }
  }
  cout << end << endl;
}
    
  
  
    
    

Measured memory_bytes: 3592
L, R = map(int, input().split())
MOD = 2019

ans = float('inf')
for i in range(L, L + 2020):
    for j in range(L + 1, L + 2020):
        if (i >= j) or (j > R):
            continue
        ans = min(ans, (i * j) % MOD)

print(ans)

Measured memory_bytes: 41068
#include <bits/stdc++.h>
#define REP(i, n) for(int i = 0; i < n; ++i)
#define REPP(i, n) for(int i = 1; i <= n; ++i)
#define REPR(i, n) for(int i = n-1; i >= 0; --i)
#define FOR(i, m, n) for(int i = m; i < n; ++i)
#define ALL(v) v.begin(), v.end()
#define UNIQUE(v) v.erase(unique(v.begin(), v.end()), v.end());
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
const ll MOD = 1000000007;
const ll INF = 1000000000;

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    vector<pair<long double, long double>> v(4);
    v[0].second = 0.25;
    REP(i,4) {
        cin >> v[i].first;
        if(i>0) v[i].second = v[i-1].second * 2.0;
    }
    ll n; cin >> n;
    v[0].first *= 4.0; v[1].first *= 2.0; v[3].first /= 2.0;
    sort(ALL(v));
    ll ans = 0;
    if(n%2==0) ans = v[0].first * n;
    else {
        if(v[0].second==2.0) {
            if(n>1) ans =  v[0].first * (n-1) + v[1].first;
            else ans = v[1].first;
        }
        else ans = v[0].first * n;
    }
    cout << ans << endl;
    return 0;
}

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

using namespace std;

typedef long long LL;
typedef unsigned long long ULL;
typedef pair<int, int> PII;

const int N = 100010;
const double eps = 1e-6;

int n;
map<int, int> h;

int main()
{
    cin >> n;
    for(int i = 0; i < n; i++)
    {
        int x;
        cin >> x;
        h[x]++;
    }

    int w = 0;
    for(map<int, int>::iterator it = h.begin(); it != h.end(); it++)
        if(it->second > 1 && it->first > w)
            w = it->first;

    for(map<int, int>::iterator it = h.begin(); it != h.end(); it++)
        if(w == it->first)
            it->second -= 2;

    int t = 0;
    for(map<int, int>::iterator it = h.begin(); it != h.end(); it++)
        if(it->second > 1 && it->first > t)
            t = it->first;

    cout << 1LL * t * w << endl;
    return 0;
}


Measured memory_bytes: 4992
#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, w;
  long long int value[101];
  long long int cost[101];
  long long int dp[101][100001];
  cin >> n >> w;
  for (int idx(0); idx < n; ++idx) {
    cin >> cost[idx] >> value[idx];
  }
  for (int idx(0); idx <= w; ++idx) {
    dp[0][idx] = 0;
  }
  for (int idx(0); idx < n; ++idx) {
    for (int wdx(0); wdx <= w; ++wdx) {
      if (cost[idx] <= wdx ) {
        dp[idx+1][wdx] = max(dp[idx][wdx - cost[idx]] + value[idx], dp[idx][wdx]);
      } else {
        dp[idx+1][wdx] = dp[idx][wdx];
      }
    }
  }
  cout << dp[n][w] << endl;
  return 0;
}

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

string s ;
map<char , int > m ;
int main()
{

    cin >> s ;
    sort(s.begin() , s.end()) ;
    if (s[0] == s[1] && s[2] == s[3] && s[0] != s[2])
          cout <<"Yes";
    else
        cout <<"No";


    return 0;
}


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

using vi = vector<int>;
using vll = vector<long long>;

constexpr long long mod = 1000000007;

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

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

    long long n, k;
    cin >> n >> k;

    long long t = n % k;

    t = t > abs(k - t) ? abs(k - t) : t;

    cout << t << endl;
}

Measured memory_bytes: 256
/*
title:

url:
*/

#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <functional>
#include <queue>
#include <limits>
#include <string>
#include <utility>
#include <cstring>
#include <map>
#include <cmath>
#include <iterator>

using namespace std;

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

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

int main()
{
    int n;
    cin >> n;
    int c[n], s[n], f[n];
    rep(i, n - 1)
    {
        cin >> c[i] >> s[i] >> f[i];
    }

    int ans[n] = {};
    //ans[i]はi駅からN駅に行くとき到着する時間
    rep(i, n - 1)
    {
        int time = 0;
        for (int j = i; j < n - 1; j++)
        {
            if (!(time >= s[j] && (time % f[j]) == 0))
            {
                time += (f[j] - (time % f[j]));
                if (time < s[j])
                    time = s[j];
            }
            time += c[j];
        }
        ans[i] = time;
    }

    rep(i, n)
    {
        cout << ans[i] << endl;
    }
}

Measured memory_bytes: 256
import java.util.Scanner;

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

        long ans = scanner.nextLong();
        long K = scanner.nextLong();

        ans %= K;

        while (true) {
            long tmp = ans - K > 0 ? ans - K : K - ans;
            if (ans > tmp) {
                ans = tmp;
            } else {
                break;
            }
        }

        System.out.print(ans);

        scanner.close();
    }
}

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

int main() {
    //input
    vector<int> a(3);
    cin >> a.at(0);
    cin >> a.at(1);
    cin >> a.at(2);

    sort(a.begin(),a.end());
    cout << abs(a[1] - a[0]) + abs(a[2] - a[1]) ;

    return 0;
}


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

using namespace std;

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  string X;
  cin >> X;
  int res = X.size();
  int cnt = 0;
  for (int i = 0; i < X.size(); i++) {
    cnt += X[i] == 'S' ? 1 : 0;
    if (cnt > 0 && X[i] == 'T') {
      res -= 2;
      cnt--;
    }
  }
  cout << res << '\n';
  return 0;
}


Measured memory_bytes: 720
#include <iostream>
#include <algorithm>
#include <bitset>
#include <math.h>
#include <string>
#include <map>
#include <vector>
using namespace std;
using ll = long long;
using ull = unsigned long long;
#define rep(i, n) for (int i = 0; i < n; i++)
#define LargeNum 1000000007
typedef pair <double, double> P;

int main(){
    int A, B, C, D, t, a;
    bool flag;
    cin >> A >> B >> C >> D;
    while(true){
        C -= B;
        if(C<=0) {
            flag=true;
            break;
        }
        A -= D;
        if(A<=0){
            flag=false;
            break;
        }
    }
    if(flag) cout << "Yes" << endl;
    else cout << "No" << endl;
    return 0;
}


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

typedef long long lnt;

const int N = 2e5 + 1;

lnt exgcd (lnt a, lnt b, lnt & x, lnt & y) {
  if (b == 0) return x = 1, y = 0, a;
  lnt ret = exgcd(b, a % b, y, x); y -= a / b * x; return ret;
}

int main (void) {
  lnt n;
  scanf("%lld", &n);
  if (n == 1) {
    puts("1");
    return 0;
  }
  n <<= 1;
  lnt res = 1e18;
  for (lnt i = 2; i * i <= n; i ++) if (n % i == 0) {
    lnt a = i, b = n / i, x, y;
    if (__gcd(a, b) != 1) continue;
    exgcd(a, b, x, y);
    if (x < 0) {
      res = min(res, a * - x);
    } else {
      res = min(res, b * - y);
    }
  }
  printf("%lld\n", res);
}

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

// See debug.cc for usage etc
#define DEBUG 0

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

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

ll N;
constexpr ll maxN = 50;
vector<ll> x(maxN), y(maxN);
map<pair<ll, ll>, int> tmap;

int main() {
#if !DEBUG
  ios_base::sync_with_stdio(false);
#endif
  cout << setprecision(20);

  cin >> N;
  for (int i = 0; i < N; i++) {
    cin >> x.at(i);
    cin >> y.at(i);
  }
  for (int i = 0; i < N; i++) {
    for (int j = 0; j < i; j++) {
      ll dx = x.at(i) - x.at(j);
      ll dy = y.at(i) - y.at(j);
      if (dy < 0 || (dy == 0 && dx < 0)) {
	dx = -dx;
	dy = -dy;
      }
      DLOG("p = (%lld, %lld)", dx, dy);
      auto p = make_pair(dx, dy);
      tmap[p] += 1;
    }
  }
  int vmax = 0;
  for (auto it = tmap.begin(); it != tmap.end(); it++) {
    vmax = max(vmax, it->second);
  }
  cout << N - vmax << endl;

  return 0;
}



Measured memory_bytes: 384
import java.util.ArrayList;
import java.util.Collections;
import java.util.HashMap;
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {

		Scanner sc = new Scanner(System.in);

		final int n = sc.nextInt();

		final ArrayList<Integer> list = new ArrayList<Integer>();
		for (int i = 0; i < n; i++) {
			list.add(sc.nextInt());
		}

		Collections.sort(list);
		Collections.reverse(list);

		final int max = list.get(0);
		list.remove(0);

		int total = 0;
		for (int j = 0; j < list.size(); j++) {
			total = total + list.get(j);
		}

		java.lang.System.out.println(max < total ? "Yes" : "No");

	}

}


Measured memory_bytes: 21844
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <algorithm>
#include <queue>
using namespace std;
int n, m, vis[101][101], ans;
int dis[4][2] = {1, 0, -1, 0, 0, 1, 0, -1};
char ss[101][101], tmp;
struct xx
{
    int x, y;
}vv;
int check(int x, int y)
{
    if((x >= 0 && x < n) && (y >= 0 && y < m)) return 1;
    return 0;
}
queue <xx> qq;
void bfs()
{
//    ans = 0;
    while(!qq.empty())
    {
        vv = qq.front();
        int x1 = vv.x;
        int y1 = vv.y;
        qq.pop();
        for(int i = 0; i < 4; i++)
        {
            int x0 = x1 + dis[i][0];
            int y0 = y1 + dis[i][1];
            if(check(x0, y0) && ss[x0][y0] != '0' && ss[x0][y0] == tmp)
            {
                ss[x0][y0] = '0';
                vv.x = x0;
                vv.y = y0;
                qq.push(vv);
            }
        }
    }
}
int main()
{
    while(~scanf("%d %d", &n, &m))
    {
        if(!n && !m) break;
        ans = 0;
        for(int i = 0; i < n; i++)
            scanf("%s", ss[i]);
        for(int i = 0; i < n; i++)
        {
            for(int j = 0; j < m; j++)
            {
                if(ss[i][j] != '0')
                {
                    tmp = ss[i][j];
                    vv.x = i;
                    vv.y = j;
                    qq.push(vv);
                    ss[i][j] = '0';
                    bfs();
                    ans++;
                }
            }
        }
        printf("%d\n", ans);
    }
    return 0;
}

Measured memory_bytes: 1068
#include <bits/stdc++.h>
#define REP(i, n) for(int i = 0;i < n;i++)
#define REPR(i, n) for(int i = n;i >= 0;i--)
#define FOR(i, m, n) for(int i = m;i < n;i++)
#define FORR(i, m, n) for(int i = m;i >= n;i--)
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
#define llong long long
#define pb(a) push_back(a)
#define INF 999999999
using namespace std;
typedef pair<int, int> P;
typedef pair<llong, llong> LP;
typedef pair<int, P> PP;
typedef pair<llong, LP> LPP;

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

int main() {
string b;
cin>>b;
if(b[0]=='A') cout<<'T'<<endl;
if(b[0]=='T') cout<<'A'<<endl;
    if(b[0]=='C') cout<<'G'<<endl;
    if(b[0]=='G') cout<<'C'<<endl;
}


Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<cmath>
#include<string>
#include<cstring>
#include<algorithm>
#include<queue>
#include<map>
#include<set>
typedef long long ll;
const ll longinf=1LL<<60;
using namespace std;
ll a,b;

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



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

#define ll long long
#define vvi vector<vector<int>>
#define vec vector
#define pq priority_queue
#define all(v) (v).begin(), (v).end()
#define rep(i, n) for (int (i) = (0); (i) < (n); ++(i))
#define repp(i, m, n) for (int (i) = (m); (i) < (n); ++(i))
#define debug(x) cerr << #x << ": " << x << endl;
#define debug2(x, y) cerr<<"("<<#x<<", "<<#y<<") = "<<"("<<x<<", "<<y<<")"<<endl;
#define debug3(x, y, z) cerr<<"("<<#x<<", "<<#y<<", "<<#z<<") = "<<"("<<x<<", "<<y<<", "<<z<<")"<<endl;
#define debugB(x, y) cerr<<#x<<": "<<bitset<y>(x) << endl;
#define line() cerr << "---------------" << endl;

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

template<typename T>
void printA(vector<T> &printArray, char between = ' ') {
   int paSize = printArray.size();
   for (int i = 0; i < paSize; i++) { cerr << printArray[i] << between;}
   if (between != '\n') {cerr << endl;}
}

// ------------------------------------------------------------------------------------------

int main() {
   ll n, y;
   cin >> n >> y;
   
   rep (i, n+1) {
      rep (j, n+1) {
         ll k = n - (i+j);
         if (k < 0) continue;
         ll a = 10000*i + 5000*j + 1000*k;
         if (a == y) {
            printf("%d %d %d\n", i, j, k);
            return 0;
         }
      }
   }
   printf("%d %d %d\n", -1, -1, -1);

   return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
int main(){
int a,x[12],k,i;
while(scanf("%d",&a)!=EOF){
k=0;
if(a>=512){
x[k++]=512;
a-=512;
}
if(a>=256){
x[k++]=256;
a-=256;
}
if(a>=128){
x[k++]=128;
a-=128;
}
if(a>=64){
x[k++]=64;
a-=64;
}
if(a>=32){
x[k++]=32;
a-=32;
}
if(a>=16){
x[k++]=16;
a-=16;
}
if(a>=8){
x[k++]=8;
a-=8;
}
if(a>=4){
x[k++]=4;
a-=4;
}
if(a>=2){
x[k++]=2;
a-=2;
}
if(a>=1){
x[k++]=1;
a-=1;
}
if(a==0)
for(i=k-1;i>0;i--)
printf("%d ",x[i]);
printf("%d\n",x[0]);
}
return 0;
}

Measured memory_bytes: 0
# -*- coding: utf-8 -*-
"""
Created on Tue Mar 10 21:19:58 2020

@author: Kanaru Sato
"""
n = int(input())
s = input()

slime = [s[0]]

if n > 1:
    for i in range(1,n):
        if slime[-1] != s[i]:
            slime.append(s[i])

print(len(slime))

Measured memory_bytes: 3956
#include <bits/stdc++.h>
using namespace std;
int main(){
    int n;
    string s, t;
    cin >> n >> s >> t;
    int ans = s.size() + t.size();
    for(int i = 0; i < s.size(); i++){
        int tmp = 0;
        while(s.at(i + tmp) == t.at(tmp)){
            tmp++;
            if(i + tmp == s.size() || tmp == t.size())
                break;
        }
        ans = min(ans, (int)(s.size() + t.size() - tmp));
    }
    cout << ans;
}

Measured memory_bytes: 256
def f(n, k, p):
    p = [(i+1)/2 for i in p]
    sums = sum(p[:k])
    mx = sums
    for i in range(k, n):
        sums = sums - p[i - k] + p[i]
        # print(f"sums = {sums}")
        if sums > mx:
            mx = sums
    print(mx)

n, k = map(int, input().split())
p = list(map(int, input().split()))
f(n, k, p)


Measured memory_bytes: 25060
n,c,k = map(int,input().split())
t_input = [int(input()) for i in range(n)]

t_s = sorted(t_input)

ans = 1
c_limit = 1
t_limit = t_s[0]+k
for i in range(1,n):
    t = t_s[i]
    #乗客が前の客の時間制限より大きいか、すでにバスが定員以上なら
    if t>t_limit or c_limit>=c:
        ans+=1
        c_limit=1
        t_limit = t+k
    else:
        c_limit+=1
print(ans)

Measured memory_bytes: 8276
#include<cstdlib>
#include<cstdio>
#include<algorithm>
#define maxn 200005
using namespace std;
int a[maxn];
int n;
int main(){
    scanf("%d", &n);
    for (int i = 0; i < n; i++){
        scanf("%d", &a[i]);
    }
    for (int i = n - 1; i >=0 ; i -= 2){
        printf("%d ",a[i]);
    }
    for (int i = (n & 1) ? 1 : 0; i < n; i += 2){
        printf("%d ", a[i]);
    }
    return 0;
}

Measured memory_bytes: 2816
import java.util.HashSet;
import java.util.Scanner;
import java.util.Set;


public class Main {

	public static void main(String[] args) {
		// TODO ?????????????????????????????????????????????
		int n;
		Scanner sc=new Scanner(System.in);
		n=sc.nextInt();
		Set<String> dic=new HashSet<String>();
		for(int i=0;i<n;i++){
			String q=sc.next();
			String s=sc.next();
			if(q.equals("insert")){
				dic.add(s);
			}else{
				System.out.println((dic.contains(s)) ? ("yes") : ("no"));
			}
		}

	}

}

Measured memory_bytes: 268436
n = int(input())
v = list(map(int,input().split()))
c = list(map(int,input().split()))
ans = 0
diff = 0

for i in range(n):
    if v[i] - c[i] > 0:
#        diff = v[i] - c[i]
#        print(diff)
        ans += v[i] - c[i]

print(ans)


Measured memory_bytes: 2940
#import sys
#import numpy as np
import math
#from fractions import Fraction
import itertools
from collections import deque
from collections import Counter
#import heapq
#from fractions  import gcd
#input=sys.stdin.readline
#import bisect
s=input()
n=len(s)
ans=0
ans+=int(s)
if n==1:
  print(ans)
  exit()
for i in s:
    ans+=int(i)
l=[i for i in range(n-1)]
for i in range(1,n-1):
    c=itertools.combinations(l,i)
    for p in c:
        pulus=set(list(p))
        z=0
        for j in range(n):
            ans+=int(s[n-1-j])*10**z
            if j != n-1 and n-2-j not in pulus:
                z+=1
            else:
                z=0
print(ans)

Measured memory_bytes: 74300
// Math = ♥️

#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
using namespace std;

/*-------------------------------------------------------------------------------------------------------------------------*/
#define ll long long                  // Short form for long long
#define ld long double                // Short form for long double
typedef pair<ll, ll> ii;              // Pair of long long
typedef vector<ll> vi;                // Vector of long long
typedef vector<vi> vvi;               // Vector of vector of long long
typedef vector<ii> vii;               // Vector of pairs
typedef vector<vii> vvii;             // Vector of vector of pairs
#define pq priority_queue             // Max heap (To convert to min heap, use negative sign before every value)
#define ff first                      // For pairs
#define ss second                     // For pairs
#define pb push_back                  // Pushback to vector
#define mp make_pair                  // Makes pairs to be stored as pair
#define all(c) (c).begin(), (c).end() // Mainly used by me in sorting
// ordered_set adds two new functions to set - (set).find_by_order([kth element based on zero indexing]) and order_of_key()
// order_of_key returns number of elements less that parameter. If element exists, that order is its index
#define ordered_set tree<ll, null_type, less<ll>, rb_tree_tag, tree_order_statistics_node_update>
/*-------------------------------------------------------------------------------------------------------------------------*/

vi arr;
vii dp;
ll n;

ii solve(ll bit)
{
    if (dp[bit] == mp(-1ll, -1ll))
    {
        ii maxi = {bit, 0};
        if (arr[0] > arr[bit])
            swap(maxi.ff, maxi.ss);
        for (int i = n; i >= 0; i--)
        {
            ll check = (1 << i);
            if (bit & check)
            {
                auto c = solve(bit & (~(check)));
                if (c.ff != maxi.ff && c.ff != maxi.ss)
                {
                    if (arr[c.ff] > arr[maxi.ff])
                        maxi.ss = maxi.ff, maxi.ff = c.ff;
                    else if (arr[c.ff] > arr[maxi.ss])
                        maxi.ss = c.ff;
                }

                if (c.ss != maxi.ff && c.ss != maxi.ss)
                {
                    if (arr[c.ss] > arr[maxi.ff])
                        maxi.ss = maxi.ff, maxi.ff = c.ss;
                    else if (arr[c.ss] > arr[maxi.ss])
                        maxi.ss = c.ss;
                }
            }
        }
        dp[bit] = maxi;
    }
    return dp[bit];
}

int main(void)
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);

    cin >> n;

    ll N = (1 << n);
    arr.resize(N);

    for (int i = 0; i < N; i++)
        cin >> arr[i];

    dp.resize(N, {-1, -1});
    dp[0] = {0, 0};
    solve(N - 1);

    ll prev = 0;
    for (int i = 1; i < N; i++)
    {
        prev = max(prev, arr[dp[i].ff] + arr[dp[i].ss]);
        cout << prev << "\n";
    }
}


Measured memory_bytes: 9216