akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
#define fi first
#define se second
#define pb push_back
#define SZ(x) ((int)x.size())
#define L(i,u) for (register int i=head[u]; i; i=nxt[i])
#define rep(i,a,b) for (register int i=(a); i<=(b); i++)
#define per(i,a,b) for (register int i=(a); i>=(b); i--)
using namespace std;
typedef long long ll;
typedef unsigned int ui;
typedef pair<int,int> Pii;
typedef vector<int> Vi;
inline void read(int &x) {
	x=0; char c=getchar(); int f=1;
	while (!isdigit(c)) {if (c=='-') f=-1; c=getchar();}
	while (isdigit(c)) {x=x*10+c-'0'; c=getchar();} x*=f;
}
inline ui R() {
	static ui seed=416;
	return seed^=seed>>5,seed^=seed<<17,seed^=seed>>13;
}
const int N = 903;
int n,m;char s[N][N];ll res;
void rotate(){
	static char t[N][N];
	rep(i,1,n)rep(j,1,n)t[n-j+1][i]=s[i][j];
	memcpy(s,t,sizeof(t));
}
int cnt[N][N],val[N][N];
void solve(){
//	memset(cnt,0,sizeof(cnt));
//	memset(val,0,sizeof(val));
	per(i,n,0)per(j,n,0){
		cnt[i][j]=cnt[i+1][j+1]+(s[i][j]=='#');
	}
	rep(i,1,n)per(j,n,0)val[i][j]=(val[i-1][j+1])+(s[i][j]=='#');
	for(int x=2;x<=2*n;x+=2){
		int mid=x>>1;
		rep(i,1,n-mid)rep(j,1,n-mid)if(s[i][j]=='#'&&s[i+mid][j+mid]=='#'){
			int a=i-mid,b=j+mid;if(a<0)b-=a,a-=a;res+=cnt[a][b]-cnt[i][j+x];
		//	if(i==1&&j==2)printf("QAQ");
			a=i+mid,b=j-mid;if(b<0)a-=b,b-=b;res+=cnt[a][b]-cnt[i+x+1][j+1];
		}
		rep(i,mid+1,n)rep(j,1,n-mid)if(s[i][j]=='#'&&s[i-mid][j+mid]=='#'){
			int a=i+mid-1,b=j+mid+1;if(a>n)b=a+b-n,a=n;
			res+=val[a][b]-val[i][j+x];
		}
	}
}
int main() {
	read(n);read(m);rep(i,1,n)scanf("%s",s[i]+1);//WA!!
	n=m=max(n,m);
	solve();
	rotate();solve();
	rotate();solve();
	rotate();solve();
	cout<<res/3;return 0;
}


Measured memory_bytes: 6528
#include "bits/stdc++.h"
#define in std::cin
#define out std::cout
#define rep(i,N) for(LL i=0;i<N;++i)
typedef long long int LL;

std::vector<LL>divisor(LL num)
{
	std::vector<LL>res;
	for (LL i = 1; i * i <= num; ++i)
	{
		if (num % i == 0)
		{
			res.push_back(i);
			if ((num / i) != i) res.push_back(num / i);
		}
	}
	return res;
}

int main()
{
	LL N, K;
	in >> N >> K;
	std::vector<LL>A(N);
	rep(i, N) in >> A[i];

	LL sum = 0;
	rep(i, N) sum += A[i];
	auto divs = divisor(sum);
	std::sort(divs.rbegin(), divs.rend());

	for (LL d : divs)
	{
		std::vector<std::pair<LL, LL>>delta;
		rep(i, N) delta.push_back(std::make_pair(A[i] % d, d - (A[i] % d)));
		std::sort(delta.begin(), delta.end());

		std::vector<LL>imos1(N + 1), imos2(N + 1);
		rep(i, N)
		{
			imos1[i + 1] = imos1[i] + delta[i].first;
			imos2[i + 1] = imos2[i] + delta[i].second;
		}
		for (LL i = 0; i <= N; ++i)
		{
			if (imos1[i] == imos2[N] - imos2[i] && imos1[i] <= K)
			{
				out << d << std::endl;
				return 0;
			}
		}
	}
}


Measured memory_bytes: 256
import java.util.*;

public class Main {
	
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt(), k = sc.nextInt();
		sc.close();
		long ans = (long)Math.pow((long)(n / k), (long)3);
		if(k % 2 == 0) {
			ans += (long)Math.pow((long)((n + (k / 2)) / k), (long)3);
		}
		System.out.println(ans);
	}

}


Measured memory_bytes: 22740
#include<iostream>
#include<stack>
#include<string>
#include<sstream>
#include<cstdlib>

using namespace std;

int main(void)
{
	string str;
	while(getline(cin,str)){
		stack<double> stk;
		double ans=0;
		stringstream strs(str);
		string tmp;
		while(strs>>tmp){
			if(tmp=="+"||tmp=="-"||tmp=="*"||tmp=="/"){
				double n1,n2;
				n1=stk.top(); stk.pop();
				n2=stk.top(); stk.pop();
				if(tmp=="+") stk.push(n2+n1);
				else if(tmp=="-") stk.push(n2-n1);
				else if(tmp=="*") stk.push(n2*n1);
				else if(tmp=="/") stk.push(n2/n1);
			}
			else stk.push(atof(tmp.c_str()));
		}
		printf("%.6lf\n",stk.top());
	}
	return 0;
}

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

int main() 
{
        char a;

        cin >> a;
        if (a == 'a' || a == 'i' || a == 'u' || a == 'e' || a == 'o')
                cout << "vowel" << endl;
        else
                cout << "consonant" << endl;
}


Measured memory_bytes: 256
import java.util.*;
import java.io.*;
public class Main{
    public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		PrintWriter ou = new PrintWriter(System.out);
		int[] a = new int[3];
		for(int i = 0 ; i < 3 ; i++) a[i] = Integer.parseInt(sc.next());
		if(a[0] > a[1]){
			int e = a[0];
			a[0] = a[1];
			a[1] = e;
		}
		if(a[0] <= a[2] && a[2] <= a[1]) ou.print("Yes\n");
		else ou.print("No\n");
		ou.flush();
    }
}

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

long long row[300003],col[300003],mp[300003];

vector<long long>adj[300003];

int main()
{

        long long n,m,a,b,c,d,e,f,g,h,p,q,r,fr,sc,tr,sz,tz=0,i,j,k,mx=LLONG_MIN,mn=LLONG_MAX;
        long long x=0,y=0,cnt=0,res=0,ttl=0,ans,sum=0; long long flg=0,flag=1,na=0,as=1;
        vector<long long>u,v,w; vector< pair<long long,long long> >vct; vector<string>vst;
        set<long long>st,nt,tt; string str,ttr,ntr;

        ans=mx;

        scanf("%lld %lld %lld",&n,&m,&p);

        for(i=1;i<=p;i++)
        {
            scanf("%lld %lld",&a,&b); adj[a].push_back(b);
            row[a]++; col[b]++;

            st.insert(b); tt.insert(a);
        }

        set<long long>:: iterator it;  tz=st.size();


        for(it=st.begin();it!=st.end();it++)
        {
            b=*it;
            vct.push_back(make_pair(col[b],b));
        }

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

        for(j=tz-1;j>=0;j--)
        {
            a=vct[j].first;  b=vct[j].second; if(a>mx)mx=a;

            if(j!=tz-1)
            {
                if(a<q)break;
            }

            mp[b]=7; cnt++;

            q=a;
        }


        for(it=tt.begin();it!=tt.end();it++)
        {

               a=*it;

               b=row[a]; ttl=0; x=1;
               sz=adj[a].size();

               for(j=0;j<sz;j++)
               {
                  c=adj[a][j]; if(mp[c]==7){ flg=0; ttl++;  }
               }

               if(cnt>ttl)x=0;

               fr=b+mx-x;

               if(fr>ans)ans=fr;



        }



        printf("%lld\n",ans);







    return 0;
}





Measured memory_bytes: 60848
#include<cstdio>
#include<algorithm>
using namespace std;
const int N=1e5+4;
int n,a[N],ans;
int main() {
	scanf("%d",&n);
	for (register int i=1;i<=n;++i)
		scanf("%d",&a[i]);
	int l=1,r=1;
	while (l<=n) {
		while (a[r+1]<=a[r]&&r+1<=n) ++r;
		ans=max(ans,r-l+1);
		l=r+1,++r;
	}
	printf("%d\n",ans-1);
	return 0;
}

Measured memory_bytes: 512
from collections import deque

N = int(input())
b_li = list(map(int, input().split()))
a_li = deque()
while len(b_li) > 0:
    found = False
    for i in range(len(b_li) - 1, -1, -1):
        if b_li[i] == i + 1:
            found = True
            a_li.appendleft(b_li[i])
            del b_li[i]
            break

    if not found:
        print(-1)
        exit()

for a in a_li:
    print(a)


Measured memory_bytes: 66436
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define rep(i,n) for(int i=0;i<n;i++)
#define REP(i,x,n) for(int i=x;i<n;i++)
#define mod 1000000007 //10^9+7
#define INF 1000000000000 //10^12
#define F first
#define S second
#define P pair<int,int>
#define all(vec) vec.begin(),vec.end()
//library begin
int gcd(int a,int b){
    if(a%b==0)return b;
    return gcd(b,a%b);
}
int lcm(int a,int b){
    return a*b/gcd(a,b);
}
int log(int a){
    int b=a;
    int cnt=0;
    while(b%2==0){
        b/=2;
        cnt++;
    }
    return cnt;
}
int mypow(int a,int b){
    if(b==0)return 1;
    if(b==1)return a;
    int t=mypow(a,b/2);
    if(b%2==0)return t*t;
    return t*t*a;
}
//library end
int n,k,s;
signed main(){
    cin>>n>>k>>s;
    if(s==1000000000){
        rep(i,k)cout<<s<<" ";
        rep(i,n-k)cout<<1<<" ";
    }
    else{
        rep(i,k)cout<<s<<" ";
        rep(i,n-k)cout<<s+1<<" ";
    }
    cout<<endl;
    return 0;
}


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

int main() {
    int n;
    cin>>n;
    vector<ll> l;
    l.push_back(2);
    l.push_back(1);
    for (int i=2; i<=n; i++) {
        l.push_back(l[i-1]+l[i-2]);
    }
    cout<<l[n]<<endl;
}


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

using namespace std;
using ll = long long;

int main()
{
  int H, W; cin >> H >> W;
  for (int i = 0; i < H; ++i) {
    for (int j = 0; j < W; ++j) {
      string s; cin >> s;
      if (s == "snuke") {
        cout << char(j+'A') << i+1 << endl;
      }
    }
  }
}

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

int main(){
	int N;cin>>N;
    int *a = new int [N+1];
    int *b = new int [N+1];
    for(int i=1;i<=N;i++){
    	cin>>a[i];
    	b[a[i]]=i;
	}
    for(int i=1;i<N;i++)
    cout<<b[i]<<" ";
    cout<<b[N]<<endl;
	return 0;
}

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

int main() {
    int n,m; cin >> n;
    map<string, int> mp;
    rep(i,n){
        string s;
        cin >> s;
        mp[s]++;
    }
    cin >> m;
    rep(i,m){
        string s;
        cin >> s;
        mp[s]--;
    }
    int maxv = -999999;
    for(auto & p: mp){
        int s = p.second;
        maxv = max(maxv,s);
    }
    if(maxv > 0) cout << maxv;
    else cout << 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <numeric>
#include <utility>
#include <tuple>

#define REP(i, a, b) for (int i = int(a); i < int(b); i++)
using namespace std;
using ll = long long int;
using P = pair<int, int>;

// clang-format off
#ifdef _DEBUG_
#define dump(...) do{ cerr << __LINE__ << ":\t" << #__VA_ARGS__ << " = "; PPPPP(__VA_ARGS__); cerr << endl; } while(false)
template<typename T> void PPPPP(T t) { cerr << t; }
template<typename T, typename... S> void PPPPP(T t, S... s) { cerr << t << ", "; PPPPP(s...); }
#else
#define dump(...) do{ } while(false)
#endif
template<typename T> vector<T> make_v(size_t a, T b) { return vector<T>(a, b); }
template<typename... Ts> auto make_v(size_t a, Ts... ts) { return vector<decltype(make_v(ts...))>(a, make_v(ts...)); }
template<typename T> bool chmin(T &a, T b) { if (a > b) {a = b; return true; } return false; }
template<typename T> bool chmax(T &a, T b) { if (a < b) {a = b; return true; } return false; }
template<typename T> void print(T a) { cout << a << endl; }
template<typename T, typename... Ts> void print(T a, Ts... ts) { cout << a << ' '; print(ts...); }
template<typename T> istream &operator,(istream &in, T &t) { return in >> t; }
// clang-format on

#include <set>

int main() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    set<int> s;
    REP(i, 1, 4) {
        s.insert(i);
    }
    REP(i, 0, 2) {
        int a;
        cin, a;
        s.erase(a);
    }
    cout << *s.begin() << endl;
    return 0;
}


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

int main() {
  long n;
  cin>>n;
  vector<long> rui(15);
  long sum=0;
  int mozi=0;
  rep(i,15){
  	if(i==0){
    	rui.at(0)=1;
    }else{
    	rui.at(i)=rui.at(i-1)*26;
    }
  }
  for(int i=0;i<15;i++){
  	sum+=rui.at(i);
    if(n<sum){
    	mozi=i;
      sum-=rui.at(i);
      break;
    }
  }
  n-=sum;
  string ans="";
  rep(i,mozi){
  	ans.push_back(n%26+'a');
    n/=26;
  }
  reverse(ans.begin(),ans.end());
  cout<<ans<<endl;
}

Measured memory_bytes: 3620
k = int(input())

if k % 2 == 0:
    print('-1')
    exit()

mod = [pow(10, i, k) for i in range(0, 1000000)]

num = 0
for i in range(0, 1000000):
    num += mod[i]
    if 7 * num % k == 0:
        print(i + 1)
        exit()

print('-1')

Measured memory_bytes: 139736
N = int(input())
list_s = []
for i in range(N):
  list_s.append(input())
M = int(input())
list_t = []
for k in range(M):
  list_t.append(input())
list_s_new = list(set(list_s))
cnt_list = []
for l in list_s_new:
  cntplus = list_s.count(l)
  cntminus = list_t.count(l)
  cnt_list.append(cntplus-cntminus)
if max(cnt_list) > 0:
  print(max(cnt_list))
else:
  print(0)

Measured memory_bytes: 3064
program three_variables_game
  implicit none
  integer :: n, r(4) = 0, x(100001) = 0, i, j, p(2) = 0
  character(1) :: c(4) = (/ "A", "B", "X", "C" /)
  character(2) :: s
  read(*,*) n, r(1), r(2), r(4)
  if (sum(r) == 0) then
    write(*,'(a)') "No"
    stop
  end if
  do i = 1, n
    read(*,*) s
    x(i) = hash(s)
  end do
  if (sum(r) == 1) then
    j = maxloc(r,1)
    call simulate(.false.)
    r = 0
    r(j) = 1
    call simulate(.true.)
    stop
  end if
  call get_index(x(1),p)
  if (r(p(1)) == 0 .and. r(p(2)) == 0) then
    write(*,'(a)') "No"
    stop
  else
    write(*,'(a)') "Yes"
  end if
  do i = 1, n
    call get_index(x(i),p)
    j = 1
    if (sum(r) == 2 .and. r(p(1))*r(p(2)) == 1 .and. &
    & i < n .and. x(i) /= x(i+1) .and. p(2) == and(x(i),x(i+1))) then
      j = 2
    else if (r(p(1)) > r(p(2))) then
      j = 2
    end if
    r(p(j)) = r(p(j))+1
    r(p(3-j)) = r(p(3-j))-1
    write(*,'(a)') c(p(j))
  end do
contains
  integer function hash(s)
    character(2), intent(in) :: s
    select case (s)
      case ("AB")
        hash = 3
      case ("AC")
        hash = 5
      case ("BC")
        hash = 6
    end select
  end
  subroutine get_index(x,p)
    integer, intent(in) :: x
    integer, intent(out) :: p(2)
    integer :: i, k
    i = 0
    do k = 0, 2
      if (.not.btest(x,k)) cycle
      i = i+1
      p(i) = lshift(1,k)
    end do
  end
  subroutine simulate(out)
    logical, intent(in) :: out
    if (out) write(*,'(a)') "Yes"
    do i = 1, n
      call get_index(x(i),p)
      if (r(p(1)) /= 0) then
        r(p(1)) = r(p(1))-1
        r(p(2)) = r(p(2))+1
        if (out) write(*,'(a)') c(p(2))
      else if (r(p(2)) /= 0) then
        r(p(1)) = r(p(1))+1
        r(p(2)) = r(p(2))-1
        if (out) write(*,'(a)') c(p(1))
      else
        write(*,'(a)') "No"
        stop
      end if
    end do
  end
end program three_variables_game

Measured memory_bytes: 3320
#include <iostream>
#include <vector>
#include <set>
#include <algorithm>
#include <math.h>
#include <string.h>
#include <map>
#include <numeric>
using namespace std;

const int MOD = 1000000007;
typedef long long ll;

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

  int N;
  long long ans;
  cin>>N;
  vector<int> A(N);
  for(int i=0;i<N;i++){
    cin>>A[i];
  }
  sort(A.begin(),A.end());
  if(N%2==0){
    ans=accumulate(A.begin()+N/2,A.end(),0ll)-accumulate(A.begin(),A.begin()+N/2,0ll);
    ans*=2;
    ans-=A[N/2];
    ans+=A[N/2-1];
  }else{
    long long ans1,ans2;
    ans1=accumulate(A.begin()+(N-1)/2+1,A.end(),0ll)-accumulate(A.begin(),A.begin()+(N-1)/2+1,0ll);
    ans1*=2;
    ans1+=A[(N-1)/2];
    ans1+=A[(N-1)/2-1];
    ans2=accumulate(A.begin()+(N-1)/2,A.end(),0ll)-accumulate(A.begin(),A.begin()+(N-1)/2,0ll);
    ans2*=2;
    ans2-=A[(N-1)/2];
    ans2-=A[(N-1)/2+1];
    ans=max(ans1,ans2);
  }
  cout<<ans<<endl;
}

Measured memory_bytes: 640
#include <iostream>
#include <string>
#include <iomanip>
#include <algorithm>
#include <cassert>
#include <numeric>
#include <queue>
#include <set>
#include <vector>
#include <cmath>
#include <bitset>
#include <functional>
#include <limits>
#include <map>
using namespace std;

typedef long long ll;
#define rep2(i, n) for(ll i = 2; i <=(ll)(n); i++)
#define rep1(i, n) for(ll i = 1; i <=(ll)(n); i++)
#define rep0(i, n) for(ll i = 0; i <=(ll)(n); i++)

ll pow(ll a, ll n) { //compute a^n with o(logn)
    ll res = 1;
    while (n > 0) {
        if (n & 1) res = res * a;
        a = a * a;
        n >>= 1;
    }
    return res;
}

ll pow(ll a, ll n, ll mod) { //compute a^n (mod mod) with o(logn)
    ll res = 1;
    while (n > 0) {
        if (n & 1) res = res * a % mod;
        a = a * a % mod;
        n >>= 1;
    }
    return res;
}

const int MAX = 199;
const int MOD = 1000000007;
ll 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;
    }
}

// 二項係数計算
ll 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;
}

//順列計算
ll PER(int n, int k){
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[n - k] % MOD) % MOD;
}

int main(){
    ll n;
    cin >> n;
    ll mod = 1e9 + 7;
    ll mod8 = 1; // 8^n % mod;
    ll mod10 = 1; // 10^n % mod;
    ll mod9 = 1; // 9^n % mod;
    ll ans;
    rep1(i, n){
        mod8 *= 8;
        mod8 %= mod;
        mod10 *= 10;
        mod10 %= mod;
        mod9 *= 9;
        mod9 %= mod;
    }
    ans = (mod8 + mod10) % mod -2*mod9;
    ans = (ans + 2*mod) % mod;
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 3196
#include <stdio.h>
int main(void){
  int n;
  int tmp;

  scanf("%d\n",&n);
  int num[n];

  for(int i = 0; i < n; i++){
    scanf("%d\n",&num[i]);
  }
  for(int i = (n-1); i >= 0; i--){
    if(i != 0){
      printf("%d ",num[i]);
    }else{
      printf("%d",num[i]);
    }
  }
    printf("\n");
    return 0;
}


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

int main() {

  int n;
  int N;
  cin >> n;
  N = n % 10;
  if(N == 2 || N == 4 ||N == 5 || N == 7 ||N == 9 ){
    cout << "hon" << endl;
  }else if(N == 0 || N == 1 ||N == 6 || N == 8 ){
    cout << "pon" << endl;
  }else{
    cout << "bon" << endl;
  }
  
}


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

using namespace std;

int main(){
    long long int n,a[100000],lm = -1,sum = 0;
    cin >> n;
    for(int i=0;i<n;i++){
        cin >> a[i];
        if(a[i]<0)sum-=a[i];
        else sum += a[i];
    }
    sort(a,a+n);
    for(int i=0;i<n-1;i++){
        if(a[i]*a[i+1]<=0){
            lm = i;
            break;
        }
    }
    if(n == 2){
        cout << a[1]-a[0] << endl;
        cout << a[1] <<" "<< a[0] << endl;
    }
    else if(lm == -1){
        if(a[0] == a[n-1]){
            if(a[0] < 0)cout << sum + a[0] * 2 << endl;
            else cout << sum - a[0] * 2 << endl;
        } 
        else{
            if(a[0] > 0)cout << sum -a[0] * 2 << endl;
            else cout << a[n-1] * 2 + sum << endl;
        }
        if(a[0]>0){
            for(int i=1;i<n-1;i++){
                cout << a[0] << " " << a[i] << endl;
                a[0] -= a[i];
            }
            cout << a[n-1] << " " << a[0] << endl;
        }
        else{
            for(int i=n-2;i>0;i--){
                cout << a[n-1] << " " << a[i] << endl;
                a[n-1] -= a[i];
            }
            cout << a[n-1] << " " << a[0] << endl;
        }
    }
    else{
        cout << sum << endl;
        for(int i=n-2;i>lm;i--){
            cout << a[0] << " " << a[i] << endl;
            a[0] -= a[i];
        }
        for(int i=1;i<=lm;i++){
            cout << a[n-1] << " " << a[i] << endl;
            a[n-1] -= a[i];
        }
        cout << a[n-1] << " " << a[0] << endl;
    }
}

Measured memory_bytes: 2688
n, k = list(map(int,input().split()))
h = list(map(int,input().split()))

inf = n * (10**4)
c = [inf] * n

c[0] = 0
c[1] = abs(h[1]-h[0]) + c[0]

for i in range(2,n):
    for j in range(1, k + 1):
        if i - j < 0:
            continue
        if c[i] < c[i-j]:
            continue
        c[i] = min(c[i], abs(h[i] - h[i-j]) + c[i-j])

print(c[n-1])


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

//typedef
//------------------------------------------
typedef long long LL;
typedef vector<LL> VL;
typedef vector<VL> VVL;
typedef vector<string> VS;
typedef pair<LL, LL> PLL;

//container util
//------------------------------------------
#define ALL(a)  (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define MP make_pair
#define SZ(a) int((a).size())
#define EACH(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort((c).begin(),(c).end())

//constant
//--------------------------------------------
const double EPS = 1e-10;
const double PI  = acos(-1.0);
const int MOD = 1000000007;

//debug
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;

//main code

int main(int argc, char const* argv[])
{
    int n;
    cin >> n;
    LL count_odd = 0;
    for (int i = 0; i < n; i++) {
        int a;
        cin >> a;
        if (a % 2 == 1) {
            count_odd++;
        }
    }
    if (count_odd % 2 == 1) {
        cout << "NO" << endl;
    }
    else {
        cout << "YES" << endl;
    }
    return 0;
}


Measured memory_bytes: 256
def main():
    from collections import deque
    import sys;input=sys.stdin.readline

    h,w=map(int,input().split())
    grid=[["#"]*(w+2)]+[list("#"+input()+"#")for x in range(h)]+[["#"]*(w+2)]

    stack=deque()
    for y in range(1,h+1):
        for x in range(1,w+1):
            if grid[y][x]=="#":
                grid[y][x]=0
                stack.append((y,x))

    for i in range(h*w):
        tmp=deque()
        while stack:
            my,mx=stack.pop()
            for y,x in ([0,1],[1,0],[-1,0],[0,-1]):
                if grid[my+y][mx+x]==".":
                    grid[my+y][mx+x]=i+1
                    tmp.append([my+y,mx+x])
        stack=tmp
        if not tmp:
            print(i)
            break
if __name__ == '__main__':
    main()

Measured memory_bytes: 163976
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<cmath>
#include<math.h>
#include<limits>
#include<list>
#include <stdio.h>
using namespace std;
using ll = long long;
#define rep(i,n) for(int i = 0;i < (n); ++i)
#pragma GCC optimize("Ofast")



int main() {
	int n;
	cin >> n;
	vector<int>a(n);
	rep(i, n)cin >> a[i];
	sort(a.begin(), a.end());
	reverse(a.begin(), a.end());
	int alice = 0;
	int bob = 0;
	for (int i = 0; i < n; i += 2) {
		alice += a[i];
	}
	for (int i = 1; i < n; i += 2) {
		bob += a[i];
	}
	cout << alice - bob << endl;
	return 0;
}


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

long modpow(long a, long n, long mod){
	if (n == 0) {
		return 1;
	}
	long answer;
	if (n%2 == 0) {
		answer = modpow(a, n/2, mod);
		answer *= answer;
	} else {
		answer = modpow(a, n-1, mod);
		answer *= a;
	}
	answer %= mod;
	return answer;
}

int main(void) {

  long n,k;
  scanf("%ld %ld", &n, &k);
  long mod = pow(10,9)+7;
  if (k > n) {
    k = n;
  }
  long combination_list0[k+1],combination_list1[k+1];
  combination_list0[0] = 1;
  combination_list1[0] = 1;
  long tmp;
  for (long i = 1; i <= k; i++) {
    tmp = modpow(i,mod-2,mod);
    combination_list0[i] = combination_list0[i-1];
    combination_list0[i] *= n+1-i;
    combination_list0[i] %= mod;
    combination_list0[i] *= tmp;
    combination_list0[i] %= mod;
    combination_list1[i] = combination_list1[i-1];
    combination_list1[i] *= n-i;
    combination_list1[i] %= mod;
    combination_list1[i] *= tmp;
    combination_list1[i] %= mod;
  }
  long sum = 1;
  long count;
  for (long i = 1; i <= k; i++) {
    count = combination_list0[i]*combination_list1[i];
    count %= mod;
    sum += count;
    sum %= mod;
  }
  printf("%ld\n", sum);

  return 0;
}

Measured memory_bytes: 3328
#include<stdio.h>
#include<algorithm>
#include<map>
#include<string.h>
using namespace std;
char in[20];
map<int,int> dpL[8][3][71];
map<int,int> dpR[8][3][71];
long long ret=0;
long long lt[71];
long long rt[71];
int main(){
	scanf("%s",in);
	int n=strlen(in);
	int L=n/2;
	int R=n-L;
	dpL[0][0][0][1]=dpR[0][0][0][1]=1;
	for(int i=0;i<L;i++){
		for(int j=0;j<3;j++){
			for(int l=0;l<10;l++){
				int tj=j;
				if(j==0&&l<in[i]-'0')tj=1;
				else if(j==0&&l>in[i]-'0')tj=2;
				for(int k=0;k<=(10*i);k++){
					for(map<int,int>::iterator it=dpL[i][j][k].begin();it!=dpL[i][j][k].end();it++){
			//			printf("%d %d %d %d: %d %d\n",i,j,k,l,(*it).first,(*it).second);
						if(!dpL[i+1][tj][k+l].count((*it).first*(l+1)))dpL[i+1][tj][k+l][(*it).first*(l+1)]=(*it).second;
						else dpL[i+1][tj][k+l][(*it).first*(l+1)]+=(*it).second;
					}
				}
			}
		}
	}
	for(int i=0;i<R;i++){
		for(int j=0;j<3;j++){
			for(int l=0;l<10;l++){
				int tj=j;
				if(j==0&&l<in[i+L]-'0')tj=1;
				else if(j==0&&l>in[i+L]-'0')tj=2;
				for(int k=0;k<=(10*i);k++){
					for(map<int,int>::iterator it=dpR[i][j][k].begin();it!=dpR[i][j][k].end();it++){
						if(!dpR[i+1][tj][k+l].count((*it).first*(l+1)))dpR[i+1][tj][k+l][(*it).first*(l+1)]=(*it).second;
						else dpR[i+1][tj][k+l][(*it).first*(l+1)]+=(*it).second;
					}
				}
			}
		}
	}
	int S=0;
	long long T=1;
	
	for(int i=0;i<n;i++){
		S+=in[i]-'0';
		T*=in[i]-'0'+1;
	}
	for(int i=0;i<71;i++)for(int j=0;j<3;j++){
		for(map<int,int>::iterator it=dpL[L][j][i].begin();it!=dpL[L][j][i].end();it++)lt[i]+=(*it).second;
		for(map<int,int>::iterator it=dpR[R][j][i].begin();it!=dpR[R][j][i].end();it++)rt[i]+=(*it).second;
		
	}
	for(int i=0;i<71;i++)for(int j=0;j<71;j++){
		if(i+j<S){
			ret+=lt[i]*rt[j];
		//	printf("%d %d\n",lt[i],rt[j]);
		}else if(i+j==S){
			for(int k=0;k<3;k++)for(int l=0;l<3;l++){
				for(map<int,int>::iterator it1=dpL[L][k][i].begin();it1!=dpL[L][k][i].end();it1++)
				for(map<int,int>::iterator it2=dpR[R][l][j].begin();it2!=dpR[R][l][j].end();it2++){
					//printf("%d %d: %d %d %d %d\n",k,l,(*it1).first,(*it1).second,(*it2).first,(*it2).second);
					if((long long)(*it1).first*(*it2).first<T)ret+=(long long)(*it1).second*(*it2).second;
					if((long long)(*it1).first*(*it2).first==T){
						if(k==1||(k==0&&l==1))ret+=(long long)(*it1).second*(*it2).second;
					}
				}
			}
		}
	}
	printf("%lld\n",ret);
}

Measured memory_bytes: 3584
#include<iostream>
#include<queue>
#include<string>
#include<cmath>
#include<cstdio>
#include<cctype>
#include<cstring>
#include<iomanip>
#include<cstdlib>
#include<ctime>
#include<set>
#include<map>
#include<utility>
#include<vector>
#include<stack>
#include<sstream>
#include<algorithm>
using namespace std;
/****************************/
#define ll long long
#define vi vector<int>
#define vvi vector<vi>
#define pii pair<int,int>
#define vpii vector<pair<int,int> >
#define qi queue<int>
#define mii map<int,int>
#define msi map<string,int>
#define vs vector<string>
#define vc vector<char>
/****************************/
#define rep(i,n) for(ll i=0;i<(n);i++)
#define rep2(i,n) for(ll i=(n)-1;i>=0;i--)
#define rep3(i,a,n) for(ll i=(a);i<(n);i++)
#define rep4(i,a,n) for(ll i=(a)-1;i>=n;i--)
#define mp make_pair
#define pb push_back
#define st first
#define nd second
#define pi 3.1415926535897932384626433832795
#define zero(n) memset(n,0,sizeof(n));
#define SZ(n) n.size()
#define sn st.nd 
int dx[4]={1,-1,0,0};
int dy[4]={0,0,1,-1};
/****************************/
int main()
{
	int n,m,a;
	cin>>n>>m>>a;
	int ans=0;
	rep3(i,n,m+1)
	{
		if(i%a==0) ans++;
	}
	cout<<ans;
	return 0;
}

Measured memory_bytes: 3616
#include "bits/stdc++.h"

using namespace std;
using ll = long long;
const double pi = acos(-1);
#define FOR(i,a,b) for (ll i=(a),__last_##i=(b);i<__last_##i;i++)
#define RFOR(i,a,b) for (ll i=(b)-1,__last_##i=(a);i>=__last_##i;i--)
#define REP(i,n) FOR(i,0,n)
#define RREP(i,n) RFOR(i,0,n)
#define __GET_MACRO3(_1, _2, _3, NAME, ...) NAME
#define rep(...) __GET_MACRO3(__VA_ARGS__, FOR, REP)(__VA_ARGS__)
#define rrep(...) __GET_MACRO3(__VA_ARGS__, RFOR, RREP)(__VA_ARGS__)
template<typename T> ostream& operator<<(ostream& os, const vector<T>& v) {
	REP(i, v.size()) { if (i)os << " "; os << v[i]; }return os;
}
template<typename T> ostream& operator<<(ostream& os, const vector<vector<T>>& v) {
	REP(i, v.size()) { if (i)os << endl; os << v[i]; }return os;
}

const ll INF = LLONG_MAX;
ll MOD = 1000000007;
ll _MOD = 1000000009;
double EPS = 1e-10;

#define int long long

inline void my_io() {

	std::ios::sync_with_stdio(false);

	std::cin.tie(0);

	cout << fixed << setprecision(16);

	//cout << setprecision(10) << scientific << ans << endl;
}

signed main() {
	ll n, k, h;

	cin >> n >> k;

	ll ans = 0;

	REP(i, n) {
		cin >> h;

		if (h >= k) {
			ans++;
		}
	}

	cout << ans << endl;
}

Measured memory_bytes: 256
#include "bits/stdc++.h"
using namespace std;
using ll = long long;
using ld = long double;
using vi = vector<int>;
using vvi = vector<vector<int>>;
using vl = vector<ll>;
using vll = vector<vector<ll>>;
using pii = pair<int,int>;
#define FOR(i,a,b) for(ll i = (a); i < (b); i++)
#define REP(i,n) FOR(i,0,n)
#define ALL(obj) (obj).begin(), (obj).end()
#define pb push_back
const double PI = acos(-1);
const double EPS = 1e-10;
const ll MOD = 1000000007;
void cioacc(){//accelerate cin/cout
  cin.tie(0);
  ios::sync_with_stdio(false);
}
int main(){
  cioacc();
  ll n;
  cin >> n;
  unordered_multiset<ll> gr;
  ll ans = 0;
  vl v(n);
  REP(i,n) cin >> v[i];
  sort(ALL(v));
  REP(i,n){
    ll tmp = v[v.size()-i-1];
    ll t = 1<<30;
    bool flag = false;
    REP(j,30){
      auto itr = gr.find(abs(tmp-t));
      if(itr!=gr.end()){
        flag = true;
        gr.erase(itr);
        ++ans;
        break;
      }
      t >>= 1;
    }
    if(!flag){
      gr.insert(tmp);
    }
  }
  cout << ans << endl;
}


Measured memory_bytes: 10056
#pragma GCC optimize("Ofast")
#include<bits/stdc++.h>
using namespace std;
using ll=long long;
using ld=long double;
const ll LL_MAX=LLONG_MAX;

struct In{
    template<typename T>
    operator T(){
        T x;
        cin >> x;
        return x;
    }
};
In in;

template <typename T,typename U>
void forin(T* x,U n){
    for (U i=0;i<n;i++) cin >> x[i];
}

template <typename T>
int div1(T x) {
    return x%1000000007;
}

template <typename T>
void out(T x){
    cout << x << endl;
}

template <typename T>
T gcd(T x,T y){
    if (y == 0) return x;
    return gcd(y,x%y);
}

template <typename T>
T lcm(T x,T y){
    return x*y/gcd(x,y);
}

int main(){
    int n=in,m=in,sum=0,a;
    for (int i=0;i<m;i++){
        a=in;
        sum+=a;
    }
    if (sum>n) out(-1);
    else out(n-sum);
}

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

int main(){

	int a[3] = {};

	cin >> a[0] >> a[1] >> a[2];

	int add = 0;

	for(int i = 0;i < 3;i++){
		switch(a[i]){
		   case 5:
		   case 7:
		      add += a[i];
		      break;
		   default:
			   add  = 0;
			   break;
		}
	}

	if(add == 17){
		cout << "YES" << endl;
	}else {
		cout << "NO" << endl;
	}


	return 0;




}


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

long long i,o,t,j,l,s,z;

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

    cin>>i>>o>>t>>j>>l>>s>>z;
    long long ans=0;
    ans=2*(int)(i/2)+o+2*(int)(j/2)+2*(int)(l/2);
    if(i-1>=0 && j-1>=0 && l-1>=0)ans=max(ans,2*(int)((i-1)/2)+o+2*(int)((j-1)/2)+2*(int)((l-1)/2)+3);
    cout<< ans;

    return 0;
}


Measured memory_bytes: 384
from collections import deque
n,c,k=map(int,input().split())
t=deque(sorted([int(input()) for i in range(n)]))
b=[]
b.append(t.popleft())
ans=0
while t:
    if len(b)==c or t[0]>b[0]+k:
        ans+=1
        b=[]
    b.append(t.popleft())
if len(b)>0:
    ans+=1
print(ans)

Measured memory_bytes: 8632
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {

		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int[] h = new int[n];
		for (int i = 0; i < n; i++) {
			h[i] = sc.nextInt();
		}

		int max = 0;
		int cnt = 0;
		for (int i = 0; i < n - 1; i++) {
			if (h[i] >= h[i + 1]) {
				cnt++;
			} else {
				cnt = 0;
			}
			if (max < cnt) {
				max = cnt;
			}
		}
		System.out.println(max);
	}
}


Measured memory_bytes: 49920
#include<iostream>
#include<algorithm>
using namespace std;
int main()
{
  int N,A,B;
  cin>>N>>A>>B;
  int i;
  i=N*A;
  int d[3]={i,B};
  sort(d,d+2);
  cout<<d[0]<<endl;
  return 0;
}

  


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

#define rep(i, n) for (int i = 0; i < (n); i++)
using namespace std;
typedef long long ll;
const int INF = 1e9;

struct UnionFind {
  // 子は親のID,親は-サイズ
  vector<int> d;
  UnionFind(int n) : d(n, -1) {}
  int root(int x) {
    if (d[x] < 0) return x;
    return d[x] = root(d[x]);
  }
  bool unite(int x, int y) {
    x = root(x);
    y = root(y);
    if (x == y) return false;
    if (d[x] > d[y]) swap(x, y);
    d[x] += d[y];
    d[y] = x;
    return true;
  }
  bool same(int x, int y) { return root(x) == root(y); }
  int size(int x) { return -d[root(x)]; }
};

int main() {
  ll n, m;
  cin >> n >> m;
  vector<ll> a(m), b(m), ans;
  rep(i, m) cin >> a[i] >> b[i], a[i]--, b[i]--;

  ans.push_back(n * (n - 1) / 2);

  UnionFind uf(n);
  for (int i = m - 1; i > 0; --i) {
    if (uf.same(a[i], b[i]))
      ans.push_back(ans.back());
    else
      ans.push_back(ans.back() - (ll)uf.size(a[i]) * (ll)uf.size(b[i]));
    uf.unite(a[i], b[i]);
  }
  reverse(ans.begin(), ans.end());

  rep(i, m) cout << ans[i] << endl;
  return 0;
}


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

void fnInput(vector<int>& rvnCard)
{
  int nCardSiz;
  cin >> nCardSiz;

  for (int i = 0; i < nCardSiz; i++)
    cin >> rvnCard[i];

  sort(begin(rvnCard), end(rvnCard), greater<int>() );
}

int fnGameExec(const vector<int>& cnrvnCard)
{
  int nAlicePnt = 0, nBobPnt = 0;

  for (int i = 0; i < cnrvnCard.size(); i++)
  {
    if (i % 2 == 0)
      nAlicePnt += cnrvnCard[i];
    else
      nBobPnt  += cnrvnCard[i];
  }

  return (nAlicePnt - nBobPnt);
}

int main()
{
  vector<int> vnCard(100);
  fnInput(vnCard);
  cout << fnGameExec(vnCard) << endl;

  return 0;
}


Measured memory_bytes: 256
//  Created by conan1024hao in 2019.
//  Copyright © 2019 conan1024hao. All rights reserved.
//  専用ライブラリです、自由にコピーして構いません。
//  感谢看我的代码！Wechat:conan1024hao Twitter/QQ:810396815
#pragma GCC optimize ("O3")
#include <iostream>
#include <iomanip>
#include <istream>
#include <ostream>
#include <sstream>
#include <iterator>
#include <vector>
#include <algorithm>
#include <queue>
#include <deque>
#include <list>
#include <stack>
#include <map>
#include <unordered_map>
#include <set>
#include <utility>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <string>
#include <ctime>
#include <cctype>
#include <cstdlib>
#define IINF 10e8
#define INF 10e16
#define MOD 1000000007
#define mod 1000000007
#define rep(i, a, n) for (ll i = a; i < (ll)(n); i++)
#define Endl endl
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define eb emplace_back
#define mmax(x,y)(x>y?x:y)
#define mmin(x,y)(x<y?x:y)
#define chmax(x,y) x=mmax(x,y)
#define chmin(x,y) x=mmin(x,y)
#define all(x) (x).begin(),(x).end()
#define siz(x) (ll)(x).size()
#define PI acos(-1.0)
using namespace std;
//using Int=int_fast64_t;
typedef long long int ll;
typedef long long int LL;
typedef pair<ll,ll>Pll;
typedef pair<int,int>Pin;
long long GCD(long long a, long long b) { return b ? GCD(b, a%b) : a; }
long long LCM(long long a, long long b)  {return a/GCD(a,b)*b;}
int dx[8]={-1,0,1,0,1,1,-1,-1};
int dy[8]={0,-1,0,1,1,-1,1,-1};
char dir[4]={'u','l','d','r'};
ll cmp1(pair<ll,string>a,pair<ll,string> b){
        if(a.fi!=b.fi)
        return a.fi<b.fi;
        else
        return a.se<b.se;
}

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

//---------------------------------------------------------------------------
int main(){//問題をちゃんと見ろ!!!!!!!!!!!!!!!!!      llか??????????统一类型        memset()!!!!!!!!!!!!       ペナを減らせ!!!!!!!!!!!!!
    cin.tie(0);
    ios::sync_with_stdio(false);
    //-------------------------------
    ll h,n;cin>>h>>n;
    vector<ll>a(n);
    for(ll i=0;i<n;i++)cin>>a[i];
    ll sum=0;
    for(ll i=0;i<n;i++)sum+=a[i];
    if(sum>=h)cout<<"Yes"<<endl;
    else cout<<"No"<<endl;
    //-------------------------------
    return 0;
}
//---------------------------------------------------------------------------









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

using namespace std;

template <typename A, typename B>
string to_string(pair<A, B> p);

template <typename A, typename B, typename C>
string to_string(tuple<A, B, C> p);

template <typename A, typename B, typename C, typename D>
string to_string(tuple<A, B, C, D> p);

string to_string(const string& s) {
  return '"' + s + '"';
}

string to_string(const char* s) {
  return to_string((string) s);
}

string to_string(bool b) {
  return (b ? "true" : "false");
}

string to_string(vector<bool> v) {
  bool first = true;
  string res = "{";
  for (int i = 0; i < static_cast<int>(v.size()); i++) {
    if (!first) {
      res += ", ";
    }
    first = false;
    res += to_string(v[i]);
  }
  res += "}";
  return res;
}

template <size_t N>
string to_string(bitset<N> v) {
  string res = "";
  for (size_t i = 0; i < N; i++) {
    res += static_cast<char>('0' + v[i]);
  }
  return res;
}

template <typename A>
string to_string(A v) {
  bool first = true;
  string res = "{";
  for (const auto &x : v) {
    if (!first) {
      res += ", ";
    }
    first = false;
    res += to_string(x);
  }
  res += "}";
  return res;
}

template <typename A, typename B>
string to_string(pair<A, B> p) {
  return "(" + to_string(p.first) + ", " + to_string(p.second) + ")";
}

template <typename A, typename B, typename C>
string to_string(tuple<A, B, C> p) {
  return "(" + to_string(get<0>(p)) + ", " + to_string(get<1>(p)) + ", " + to_string(get<2>(p)) + ")";
}

template <typename A, typename B, typename C, typename D>
string to_string(tuple<A, B, C, D> p) {
  return "(" + to_string(get<0>(p)) + ", " + to_string(get<1>(p)) + ", " + to_string(get<2>(p)) + ", " + to_string(get<3>(p)) + ")";
}

void debug_out() { cerr << endl; }

template <typename Head, typename... Tail>
void debug_out(Head H, Tail... T) {
  cerr << " " << to_string(H);
  debug_out(T...);
}

#ifdef LOCAL
#define debug(...) cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)
#else
#define debug(...) 42
#endif

int main() {
  ios:: sync_with_stdio(false);
  cin.tie();
  int n;
  cin >> n;
  int k;
  cin >> k;
  vector<int> cnt(10, 0);
  while (k--) {
    int x;
    cin >> x;
    cnt[x] = 1;
  }
  for (int i = n; i <= 99999; i++) {
    bool f = true;
    int x = i;
    while (x) {
      if (cnt[x % 10] == 1) {
        f = false;
        break;
      }
      x /= 10;
    }
    if (f) {
      cout << i;
      return 0;
    }
  }
  return 0;
}




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

int main()
{
	int N, C, K;
	cin >> N >> C >> K;
	vector<int> T(N);
	for (int i = 0; i < N; i++) {
		cin >> T[i];
	}
	sort(T.begin(), T.end());
	int res = 1, t = T[0], cnt = 1;
	for (int i = 1; i < N; i++) {
		if (T[i] > t + K || cnt >= C) {
			res++;
			t = T[i];
			cnt = 1;
		}
		else {
			cnt++;
		}
	}
	cout << res << endl;
	return 0;
}


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

int main(){
  int n;
  cin>>n;
  ll a[n][n];
  rep(i,0,n){
    rep(j,0,n){
      cin>>a[i][j];
    }
  }
  ll b[n][n];
  rep(i,0,n){
    rep(j,0,n){
      b[i][j]=a[i][j];
    }
  }
  rep(k,0,n){
    rep(i,0,n){
      rep(j,0,n){
        b[i][j]=min(b[i][j],b[i][k]+b[k][j]);
      }
    }
  }
  bool p=true;
  rep(i,0,n){
    rep(j,0,n){
      if(a[i][j]!=b[i][j]) p=false;
    }
  }
  if(!p) cout<<-1<<endl;
  else{
    ll ans=0;
    rep(i,0,n){
      rep(j,i+1,n){
        bool q=true;
        rep(k,0,n){
          if(k==i || k==j) continue;
          if(b[i][k]+b[k][j]==b[i][j]) q=false;
        }
        if(q) ans+=b[i][j];
      }
    }
    cout<<ans<<endl;
  }
}

Measured memory_bytes: 5036
#include<iostream>
#include<vector>
#include<map>
#include<string>
#include<cstring>
#include<bitset>
#include<stack>
#include<queue>
#include<cmath>
#include<algorithm>
#include<cstdio>
#include<numeric>
#include<set>
#include<math.h>
#include<queue>
using namespace std;

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

#define rep(i,x) for(int i=0;i<x;i++)
#define re(i,x,y) for(int i=x;i<y;i++)

long long INF = 1e9;
const long long mod = 2019;
#define ll long long


int main() {
	cin.tie(0); ios::sync_with_stdio(false);
	int n, r = 0;
	bool c[10];
	memset(c, false, sizeof(c));
	cin >> n;
	for (int i = 0; i < n; i++) {
		int a; cin >> a;
		if (a < 3200) {
			c[a / 400] = true;
		}
		else {
			r++;
		}
	}
	int cnt = 0;
	for (int i = 0; i <= 7; i++) {
		if (c[i])cnt++;
	}
	cout << (cnt == 0 ? 1 : cnt) << ' ' << cnt + r << endl;
	return 0;
}

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

int main()
{
  string buf;
  getline( cin, buf );

  for( int i = 0; i < buf.size(); i++ ) {
    char ch = buf[ i ];
    if( ch >= 97 and ch <= 122  ) {
      ch = ch - 32;
    }
    else if( ch >= 65 and ch <= 90 ) {
      ch = ch + 32;
    }
    cout << ch;
  }
  cout << endl;
  return 0;
}

Measured memory_bytes: 3168
#include <iostream>

using namespace std;
const long long mod=1000*1000*1000+7;
int n,m;
long long ans;
long long fact(int x)
{
    long long ret=1;
    for(long long i=1;i<=x;i++)
        ret=(1LL*ret*i)%mod;
    return ret;
}
int main()
{
    cin>>n>>m;
    if(n==m) ans=(2*(1LL*fact(n)*fact(m))%mod)%mod;
    if(n==m-1||m==n-1) ans=(1LL*fact(n)*fact(m))%mod;
    cout<<ans;
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
#define ll long long
#define fw(p) for(int w=0;w<(p);w++)
#define fx(p) for(int x=0;x<(p);x++)
#define fy(p) for(int y=0;y<(p);y++)
#define fz(p) for(int z=0;z<(p);z++)
#define fyg(p,g) for(int y=(g);y<(p);y++)
#define fzg(p,g) for(int z=(g);z<(p);z++)
#define ce(d) cout<<d<<endl;
#define ces(d) cout<<" "<<endl;

int main() {
   
int N;
cin >>N;
int sum=0;

fyg(N+1,1){
	int ans=0;
if(y%2==0){continue;}
	fzg(y+1,1){
		if(y%z==0){
			ans++;
		}
	}
	if(ans==8){
		sum++;
	}
}
ce(sum);
}


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

using namespace std;

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

int main() {
    cin.tie(0); ios::sync_with_stdio(false);
    // cout << setprecision(8) << setiosflags(ios::fixed);

    int N;
    cin >> N;

    int sum = 0, a = 0, b = 0, c = 0;
    for (int i = 0; i < N; ++i) {
        string s;
        cin >> s;
        if (s.front() == 'B' && s.back() == 'A') ++c;
        else if (s.front() == 'B') ++a;
        else if (s.back() == 'A') ++b;

        for (size_t j = 0; j + 1 < s.size(); ++j) {
            if (s[j] == 'A' && s[j + 1] == 'B') ++sum;
        }
    }
    // cout << sum << " " << a << " " << b << " " << c << endl;

    if (0 < c) {
        sum += c - 1;
        if (0 < b) {
            --b;
            ++sum;
        }
        if (0 < a) {
            --a;
            ++sum;
        }
    }
    sum += min(a, b);

    cout << sum << endl;


    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main(){
  int n;
  cin >> n;
  vector<int> v(n * 2);
  for(int i = 0; i < n * 2; i++){
    cin >> v[i];
  }
  sort(v.begin(), v.end());
  int ans = 0;
  for(int i = 0; i < n; i++){
    ans += v[i * 2];
  }
  cout << ans << endl;
  return 0;
}

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

using namespace std;

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

  int N;
  cin >> N;
  string S;
  cin >> S;

  int result = 0;
  for (int i = 1; i < N; ++i) {
    int matched = 0;
    for (int j = 0; j < N - i; ++j) {
      if (S[j] == S[j + i]) {
        ++matched;
        result = max(result, matched);
        if (matched == i) {
          break;
        }
      } else {
        matched = 0;
      }
    }
  }

  cout << result << endl;
}

Measured memory_bytes: 256
#include <iostream>
using namespace std;
int main(void){
    // Your code here!
    int N;
    cin >> N;
    int color[100] = {0};
    int count=1;
    int sum=0;
    for(int i=0;i<N;i++){
        cin >> color[i];
    }
    for(int i=0;i<N;i++){
        for(;;i++){
            if(color[i]==color[i+1]){
                count++;
            }else{
                sum += count/2;
                count = 1;
                break;
            }
        }
    }
    cout << sum << endl;
}


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

using namespace std;

using ll = long long;
#define FOR(i, a, b) for(int i=(a);i<(b);++i)
#define FORE(i, a, b) for(int i=(a);i<=(b);++i)
#define rep(i, n) for(int i=0;i<(n);++i)
#define repe(i, n) for(int i=0;i<=(n);++i)
#define ALL(v) (v).begin(),(v).end()
#define SP cout<<fixed<<setprecision(10)
typedef pair<int, int> P;
const int INF = (int) 1e9;
const int MOD = (int) 1e9 + 7;

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

int main(void) {
	cin.tie(0);
	ios::sync_with_stdio(false);
	
	int n;
	cin >> n;
	string a, b, c;
	cin >> a >> b >> c;
	
	int sum = 0;
	rep(i, n) {
		if (a[i] == b[i] and b[i] == c[i]) continue;
		if (a[i] == b[i] or b[i] == c[i] or c[i] == a[i]) {
			sum++;
			continue;
		}
		sum += 2;
	}
	
	cout << sum << endl;
	
	return 0;
}

Measured memory_bytes: 256
# -*- coding: utf-8 -*-
"""
B - ROT N
https://atcoder.jp/contests/abc146/tasks/abc146_b

"""
import sys


from string import ascii_uppercase

def solve(N, S):
    t = ascii_uppercase[N:] + ascii_uppercase[:N]
    return S.translate(str.maketrans(ascii_uppercase, t))


def main(args):
    N = int(input())
    S = input()
    ans = solve(N, S)
    print(ans)


if __name__ == '__main__':
    main(sys.argv[1:])


Measured memory_bytes: 3768
import java.util.*;

import static java.util.Arrays.*;
import static java.util.Collections.*;
import static java.lang.Math.*;

public class Main {
    int INF = 1 << 28;
    E[] G;
    
    void run() {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt(), m = sc.nextInt();
        E[] G = new E[(int)n];
        for (int i = 0; i < n; i++) G[i] = new E();
        for (;;) {
            long s = sc.nextInt(), t = sc.nextInt(), e = sc.nextInt();
            if ((s|t|e) == 0) break;
            s--; t--;
            G[(int)s].add(new P((int)t, e));
        }
        
        int l = sc.nextInt();
        long[] b = new long[m];
        for (int i = 0; i < l; i++) {
            for (int j = 0; j < m; j++) b[j] = sc.nextInt();
            for (int k = 0; k < n; k++) {
                int sum = 0;
                for (P p : G[k]) sum += b[p.t] * p.c;
                System.out.print(sum + (k == n - 1 ? "\n" : " "));
            }
        }
    }
    
    class E extends ArrayList<P>{}
    
    class P {
        int t;
        long c;
        P(int t, long c) {
            this.t = t;
            this.c = c;
        }
    }
    
    void debug(Object...os) {
        System.out.println(deepToString(os));
    }
    
    public static void main(String[] args) {
        new Main().run();
    }
}

Measured memory_bytes: 296340
#include <cstdio>
#include <iostream>
using namespace std;
const int NN = 2e5 + 5;
struct E {
	int v, nxt;
	E(int _v=0, int _nxt=0) : v(_v), nxt(_nxt) {}
};
struct Graph {
	int head[NN], totE;
	E edge[NN*2];
	void AddEdge(int u, int v) {
		edge[++totE] = E(v, head[u]);
		head[u] = totE;
	}
} a, b;
int N, X, Y, da[NN], db[NN], fab[NN];
bool save[NN];
void Dfs1(int u, int fr) {
	fab[u] = fr;
	db[u] = db[fr] + 1;
	for (int p = b.head[u]; p; p = b.edge[p].nxt) {
		int v = b.edge[p].v; //注意两棵树别用串了 
		if (v != fr)
			Dfs1(v, u);
	}
}
bool inf, edgetag[NN];
void Dfs2(int u, int fr, int is) {
	da[u] = da[fr] + 1;
	if (da[u] >= db[u]) is = 0;
	else if (is) {
		save[u] = 1;
	}
	if (fr != 0) {
		int x = u, y = fr;
		if (db[x] < db[y]) swap(x, y);
		if (fab[x] == fab[y] || fab[x] == y || fab[fab[x]] == y) ;
		else if (save[u] || save[fr]) {
			inf = 1;
			edgetag[u] = 1;
		}
	}
	for (int p = a.head[u]; p; p = a.edge[p].nxt) {
		int v = a.edge[p].v;
		if (v != fr) {
			Dfs2(v, u, is);
			if (edgetag[v] && (save[u] || save[v]))
				inf = 1;
		}
	}
}
int main() {
	scanf("%d%d%d", &N, &X, &Y);
	for (int i = 1; i < N; ++i) {
		int u, v;
		scanf("%d%d", &u, &v);
		a.AddEdge(u, v);
		a.AddEdge(v, u);
	}
	for (int i = 1; i < N; ++i) {
		int u, v;
		scanf("%d%d", &u, &v);
		b.AddEdge(u, v);
		b.AddEdge(v, u);
	}
	Dfs1(Y, 0);
	Dfs2(X, 0, 1);
	if (inf) printf("-1\n");
	else {
		int ans = 0;
		for (int i = 1; i <= N; ++i)
			if (save[i]) {
				ans = max(ans, db[i]-1);
			}
		ans *= 2;
		printf("%d\n", ans);
	}
	return 0;
}

Measured memory_bytes: 23896