akhauriyash/Code-Regression huggingface dataset:
//#include <bits/stdc++.h>
#include <iostream>
#include <iomanip>
#include <algorithm>
#include <cmath>
#include <queue>
#include <list>
#include <limits>
#include <string>
#include <vector>
using namespace std;

typedef long long ll;
const int MOD = 1000000007;

    class Pairs{
        public : ll a;
        ll b;
        void setpairs(ll _a, ll _b){
            a = _a;
            b = _b;
        }
    };

    bool cmp(const Pairs &A, const Pairs &B){
        return (A.a < B.a);
    }


int main(){  
    int W,H;
    cin >> H >> W;
    char map[50][50];
    int dx[4] = {1,0,-1,0},dy[4] = {0,1,0,-1};
    for(int i=0;i<H;i++){
        for(int j=0;j<W;j++){
            cin >> map[i][j];
        }
    }
    for(int i=0;i<H;i++){
        for(int j=0;j<W;j++){
            if(map[i][j] == '#'){
                for(int k=0;k<4;k++){
                    if(i+dx[k] < 0 || j+dy[k] < 0 || i+dx[k] > W-1 || j+dy[k] > H-1) continue;
                    if(map[i+dx[k]][j+dy[k]] == '#') break;
                    if(k == 3){
                        cout << "No";
                        return 0;
                    }
                }
            }
        }
    }
    cout << "Yes";
}


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

typedef pair<int, int> p;
int N;
vector<p> X;
vector<int> B;

int main () {
  cin >> N;
  X.resize(N);
  B.resize(N);
  rep(i,N) {
    cin >> X[i].first;
    X[i].second = i;
  }

  sort(all(X));

  rep(i,N) {
    auto m = X[N/2 - (i >= N/2)];
    B[X[i].second] = m.first;
  }

  rep(i,N) {
    cout << B[i] << endl;
  }

  return 0;
}


Measured memory_bytes: 4480
/**
*
* Author: MARS
* Lang: GNU C++14
*
**/

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

#define F first
#define S second
#define ii pair<int,int>

typedef long double ldbl;
typedef long long ll;
typedef double dbl;

const ldbl pi = acos(-1);
const ll inf = 1LL<<30;
const dbl eps = 1e-9;
const ll mod = 1e9+7;

/** /////////// ** Code ** /////////// **/

const int N=0;

int main(){
    ll x,k,d;
    scanf("%lld%lld%lld",&x,&k,&d);

    ll m=abs(x)/d;
    ll y=min(m, k);

    if(x < 0) x+=y*d;
    else x-=y*d;

    k-=y;
    if(k&1) {
        if(x > 0) x-=d;
        else x+=d;
    }

    printf("%lld",abs(x));
}


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

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

#define p_ary(ary,a,b,i) do { cout << "["; for (int (i) = (a);(i) < (b);++(i)) cout << ary[(i)] << ((b)-1 == (i) ? "" : ", "); cout << "]\n"; } while(0)
#define p_map(map,it) do {cout << "{";for (auto (it) = map.begin();;++(it)) {if ((it) == map.end()) {cout << "}\n";break;}else cout << "" << (it)->first << "=>" << (it)->second << ", ";}}while(0)

int main() {
    int h,w;
    cin >> h >> w;
    string c[300];
    for (int i = 0;i < h;++i) cin >> c[i];
    vector<vector<int>> sums(2*h+1,vector<int>(h+1,0)),dp(h+1,vector<int>(h+1,1<<28));
    int ans = 0;
    for (int i = 0;i < w-1;++i) {
        for (int j = 0;j < 2*h;++j) for (int k = 0;k < h+1;++k) sums[j][k] = 0;
        for (int j = 0;j < h+1;++j) for (int k = 0;k < h+1;++k) dp[j][k] = (1<<28);
        for (int j = -h+1;j < h;++j) {
            for (int k = 0;k < h;++k) {
                if (k-j < 0) continue;
                if (k-j >= h) continue;
                if (c[h-1-k][i] == c[h-1-k+j][i+1]) sums[j+h][k+1] = 1;
            }
            for (int k = 0;k < h;++k) sums[j+h][k+1] += sums[j+h][k];
        }
        dp[0][0] = 0;
        for (int j = 0;j < h+1;++j) for (int k = 0;k < h+1;++k) if (j || k) {
            if (j) dp[j][k] = dp[j-1][k]+sums[j-1-k+h][h]-sums[j-1-k+h][j-1];
            if (k) dp[j][k] = min(dp[j][k],dp[j][k-1]+sums[j-k+1+h][h]-sums[j-k+1+h][j]);
        }
        ans += dp[h][h];
    }
    cout << ans << endl;
    return 0;
}

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

int main()
{
    int a[10];
    for(int i=0;i<10;i++)
        cin >> a[i];
    sort(a,a+10,greater<int>());
    for(int i=0;i<3;i++)
        cout << a[i] << endl;
    return 0;
}



Measured memory_bytes: 3092
#include <iostream>

using namespace std;

int main(int argc, char **argv) {
	int n, m;
	string  s, t;
	cin >> n >> m >> s >> t;
	int g;
	int n2 = max(n, m), m2 = min(n, m);
	while (1) {
		int r = n2 % m2;
		if (r == 0) {
			g = m2;
			break;
		} else {
			n2 = m2;
			m2 = r;
		}
	}
	for (int i = 0; i < g; i++) {
		if (s[i * n / g] != t[i * m / g]) {
			cout << -1 << endl;
			return 0;
		}
	}
	cout << 1ll * n * m / g << endl;
	return 0;
}



Measured memory_bytes: 512
n = int(input())
ans = 0
a =[0 for i in range(n)]
b = [0 for i in range(n)]
c = [0 for i in range(n)]
for i in range(n):
    s = input()
    q = len(s)
    for j in range(q):
        if j == 0 and s[j] == 'B':
            b[i] = 1
        elif j == q-1 and s[j] == 'A':
            a[i] = 1
        if j > 0:
            if s[j] == 'B' and s[j-1] == 'A':
                ans += 1
    if b[i] == 1 and a[i] == 1:
        c[i] = 1
        a[i] = 0
        b[i] = 0



A = sum(a)
B = sum(b)
C = sum(c)
if C >= 1:
    ans += C-1
    if A >= 1 and B >= 1:
        ans += 2 + min(A-1,B-1)
    elif A == 0 and B == 0:
        pass
    else:
        ans += 1
else:
    ans += min(A,B)

print(ans)

Measured memory_bytes: 53208
import sys
sys.setrecursionlimit(10 ** 5 + 10)
def input(): return sys.stdin.readline().strip()

def resolve():
    
    n=int(input())
    V=0
    E=0
    for i in range(1,n+1):
        V+=i*(n+1-i)

    for i in range(n-1):
        a,b=map(int,input().split())
        if a>b:
            a,b=b,a
        E+=a*(n-b+1)
    
    ans=V-E
    print(ans)
    
    
resolve()

Measured memory_bytes: 73912
def check(N, c):
    RinRight = c.count('R')
    WinLeft = 0
    r = RinRight
    for i in range(N):
        if c[i] == 'R':
            RinRight -= 1
        else: # c[i] == 'W'
            WinLeft +=1
        r = min(r, max(RinRight,WinLeft))

    return r


N = int(input())
c= input()
print(check(N,c))

Measured memory_bytes: 9360
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <deque>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <cstring>
#include <iomanip>
#include <utility>
 
#define rep(i,n) for(int i=0;i<(n);i++)
#define reps(i,n) for(int i=1;i<=(n);i++)
#define lol long long
#define mp make_pair
#define fi first
#define se second
#define pu push_back
#define SYOU(x) setprecision(x+1)
#define abs(x,y) (max(x,y)-min(x,y))
#define SUM(n) ((n)+1)*(n)/2
const int INF = 0x3f3f3f3f;
const long long LINF = 0x3f3f3f3f3f3f3f3fLL;
const int MOD = (1e9)+7;
#define all(v) v.begin(),v.end()
using namespace std;
using pii = pair<int,int>;
typedef vector<int> vit;

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

  int n;
  cin >> n;
  int x[n + 5], copy[n + 5];
  rep(i,n){
    cin >> x[i];
    copy[i] = x[i];
  }
  sort(copy, copy + n);
  rep(i,n){
    if(x[i] <= copy[n/2 - 1]){
      cout << copy[n/2] << '\n';
    } else {
      cout << copy[n/2 - 1] << '\n';
    }
  }
  return 0;
}


Measured memory_bytes: 3712
ans [a,b] i =
  let f = filter(\ [s,f] -> (a <= s && s <  b) ||
                            (a <  f && f <= b) ||
                            (s <= a && b <= f) ) i
  in
    if f == []
    then 0
    else 1

main = do
  ab <- getLine
  _  <- getLine
  c  <- getContents
  let [a,b] = map read $ words ab :: [Int]
      i     = map (map read) $ map words $ lines c :: [[Int]]
      o     = ans [a,b] i
  print o
  

Measured memory_bytes: 4108
def make(a, b)
  (["A"]*a+["B"]*b).permutation.map{|s| s.join}.uniq!
end
def make2(a, b)
  if a == 5
    make(a-1, b).map{|s| s + "A"}
  else
    make(a, b-1).map{|s| s + "B"}
  end
end
a, b = gets.split.map(&:to_i)
if a <= 4 && b <= 4
  arr = make(a, b)
elsif (a == 5 || b == 5) && a + b < 10
  arr = make2(a, b)
else
  x = make2(5, 4)
  y = make2(4, 5)
  if a == 5 && b == 5
    arr = (x.map{|s| s + "B"} + y.map{|s| s + "A"}).sort
  elsif a == 6
    arr = x.map{|s| s + "A"}
  else
    arr = y.map{|s| s + "B"}
  end
end
arr.each{|res| puts res}

Measured memory_bytes: 24596
#include <bits/stdc++.h>
 
using namespace std;
 
#define BOOST        std::ios::sync_with_stdio(false);  cin.tie(NULL); cout.tie(NULL);
#define sp           <<" "<<
#define ll           long long
#define ld           long double
#define AZI(i,x)     for(auto i=x.begin();i!=x.end();i++)
#define AZ(x)        x.begin(),x.end()
#define P(x,y)       pair < x,y >
#define V(x)         vector < x >
#define fi           first
#define se           second
#define pb           push_back
#define mp           make_pair
#define PI           3.14159265358979323846264338327950288419716939937510
 
const ll mod=1e9+7,N=1e5+5;

ll n,W;
ll w[105],v[105];
ll dp[100005]; // dp[i] -> max value for weight i 
int main() 
{ 
    BOOST

    cin >> n >> W;

    memset(dp,0,sizeof(dp));   

    for(int i = 0; i < n; i++)
        cin >> w[i] >> v[i];

    for(int i = 0; i < n; i++)    
        for(int j = W; j >= w[i]; j--)
            dp[j] = max(dp[j], v[i] + dp[j - w[i]]);

    cout << dp[W] << "\n";

    return 0; 
} 

Measured memory_bytes: 1024
#include<cstdio>
typedef long long LL;

int main(){
	LL n,a,b,max,min;
	scanf("%lld%lld%lld",&n,&a,&b);
	//对于不符和要求的情况
	if(a>b){
		printf("0");
	}
	else if(n==1){
		if(a==b) printf("1");
		else if(a<b) printf("0");
	}
	//正常情况
	else{
		max = (n-1)*b+a;
		min = (n-1)*a+b;
		printf("%lld",max-min+1);
	}
	return 0;	
}

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

#define ASC(vec) vec.begin(), vec.end()    // 昇順ソート 例：sort(ASC(vec));
#define DESC(vec) vec.rbegin(), vec.rend() // 降順ソート 例:sort(DESC(vec));
#define rep(i, n) for (int i = 0; i < (n); i++)
#define Rep(i, n) for (int i = 1; i < n; i++)
#define REP(i, vec) for (auto i = vec.begin(); i != vec.end(); ++i)

const int       mod = 1000000007;
const int       inf = (1 << 21);
const long long INF = 1LL << 60;

using ii = pair<int, int>;
using ll = long long;
using vi = vector<int>;
using vd = vector<double>;
using vb = vector<bool>;
using vl = vector<ll>;
using vs = vector<string>;
using vvi = vector<vector<int>>;
using vvl = vector<vector<ll>>;
using vvb = vector<vector<bool>>;
using vii = vector<pair<int, int>>;
using vll = vector<pair<ll, ll>>;

template<class T>
inline bool chmin(T& a, T b) {
    if (a > b) {
        a = b;
        return true;
    }
    return false;
}
template<class T>
inline bool chmax(T& a, T b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}
template<class T>
inline T GCD(T a, T b) {
    return b ? GCD(b, a % b) : a;
}
template<class T>
inline T LCM(T a, T b) {
    return (a + (b - 1)) / b;
}

int round_int(int a, int b) {
    return (a + (b - 1)) / b;
}

constexpr array<int, 9> dx = { 0, 1, 0, -1, -1, 1, 1, -1, 0 };
constexpr array<int, 9> dy = { 1, 0, -1, 0, 1, 1, -1, -1, 0 };

// ──────────────────────────────────────────────────────────────────

int main() {
    int n;
    ll k;
    cin >> n >> k;

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

    ll res = 0;
    for (int d = 60; d >= -1; --d) {
        if (d != -1 && !(k & (1LL << d))) continue;

        ll tmp = 0;
        for (int e = 60; e >= 0; --e) {
            ll mask = 1LL << e;
            int num = 0;
            rep(i, n) if (a[i] & mask) ++num;

            if (e > d) {
                if (k & mask) tmp += mask * (n - num);
                else tmp += mask * num;
            }
            else if (e == d) {
                tmp += mask * num;
            }
            else {
                tmp += mask * max(num, n - num);
            }
        }
        res = max(res, tmp);
    }
    cout << res << endl;
}

Measured memory_bytes: 1024
#include <iostream>
#include <cstdio>
#include <fstream>
#include <algorithm>
#include <iterator>
#include <math.h>
#include <cmath>
#include <stdlib.h>
#include <vector>
#include <queue>
#include <stack>
#include <set>
#include <regex>
#include <stdexcept>
#include <unordered_set>
#include <string>
#include <map>
#include <iomanip>
#include <sstream>
#include <cassert>
#include <time.h>
#include <numeric>
#include <complex>

using namespace std;
using ull = unsigned long long;
using ll = long long;
using ld = long double;
using D = double;
using ii = pair<int, int>;
using vi = vector<int>;
using vii = vector<ii>;

#define pb push_back
#define mp make_pair
#define all(x) x.begin(),x.end()
#define rall(x) x.rbegin(), x.rend()
#define fill(x, y) memset(x, y, sizeof(x))
#define makeunique(x) sort(all(x)), (x).resize(unique(all(x)) - (x).begin())
#define rep(i, x)  for(int i = 0; i < (x); i++)
#define rrep(i, x) for(int i = (x - 1); i >= 0; i--)
#define y1 y1_1234413
#define j1 j1_235
#define y0 y0_235
#define j0 j0_256
#define fi first
#define se second
#define itn int
#define re return
#define prev PREV
#define next NEXT

#define sz(x) ((int)x.size())

const int inf = 2e9;
const ld st = 0.000001;
const ld pi = acos((ld)-1);
const int maxn = 2*1000005;

#define FILENAME ""
const int MX = 100 * 1000 + 7;

ll dp[MX];

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    for (int i = 1; i < MX; i++) {
        dp[i] = inf;
    }
    int n, w;
    cin >> n >> w;
    for (int i = 0; i < n; i++) {
        int a, b;
        cin >> a >> b;
        for (int j = MX - 1; j >= b; j--) {
            dp[j] = min(dp[j], dp[j - b] + a);
        }
    }
    int ans = 0; 
    for (int i = 0; i < MX; i++) {
        if (dp[i] <= w) {
            ans = max(ans, i);
        }
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 1024
#include<bits/stdc++.h>
using namespace std;
int main()
{
	int n;
	cin>>n;
	int c0=0,c1=0,c2=0,c3=0;
	string s;
	for(int i=0;i<n;i++)
	{
		
		cin>>s;
		if(s=="AC")
		{
			c0++;	
		}
		else if(s=="WA")
		{
			c1++;
		}
		else if ( s== "TLE")
		{
			c2++;
		}
		else
		{
			c3++;
		}
	}
	cout<<"AC"<<" "<<"x"<<" "<<c0<<endl;
	cout<<"WA"<<" "<<"x"<<" "<<c1<<endl;
	cout<<"TLE"<<" "<<"x"<<" "<<c2<<endl;
	cout<<"RE"<<" "<<"x"<<" "<<c3<<endl;

}

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

int main(){
  int N, T, A;
  cin >> N >> T >> A;
  double ans = 1000;
  int H;
  vector<double> temp(N);
  for(int i=0; i<N; i++){
    cin >> H;
    temp.at(i) = abs(A - T + H*0.006);
    ans= min(ans, temp.at(i));
  }
  
  int num;
  for(int i=0; i<N; i++){
    if(ans==temp.at(i)){
      num=i+1;
      break;
    }
  }
  cout << num << endl;
}

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

int main() {
  int a,b,d,r;
  double f;
  cout << fixed << setprecision(10);
    cin >> a >> b;
    d=a/b;
    r=a%b;
    f=(double)a/b;
        
        cout << d << " " << r << " " << f << endl;
}



Measured memory_bytes: 3272
// #pragma GCC target("avx2")
// #pragma GCC optimize("O3")
// #pragma GCC optimize("unroll-loops")
// #pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")

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

//for loop関係
#define rep(i,a,n) for(int i=(a);i<(n);++i)
#define repe(i,a,n) for(int i=(a);i<=(n);++i)
#define rrep(i,n,a) for(int i=(n);n>(a);--i)
#define rrepe(i,n,a) for(int i=(n);n>=(a);--i)

//略記
#define PB push_back
#define MP make_pair
#define F first
#define S second
#define all(v) v.begin(),v.end()
#define ENDL << "\n"

using ll = long long;
using P = pair<int,int>;
using itn = int;

//定数
const int INF = 1<<30;
const ll MOD = 1000000007;
const long double PI =(acos(-1));

//Degree <-> Radian
double toRad(double d){ double rad; rad=d*PI/180; return rad; }
double toDegree(double rad){ double d; d=rad*180/PI; return d; }
//The least common multiple : lcm
ll lcm(int a,int b){ return a*b/__gcd(a,b); }
//素数判定
bool isPrime(int n){
    int i; 
    if(n<2) return 0;
    else if(n==2) return 1;
    if(n%2==0) return 0;
    for(i=3;i*i<=n;i+=2) if(n%i==0) return 0;
    return 1;
}


int main(){
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    ll n,m;
    cin >> n >> m;
    ll sum=0;
    rep(i,0,m){
        int a=0;
        cin >> a;
        sum+=a;
    }
    if(n<sum){
        cout << -1 ENDL;
    }else cout << (n-sum) ENDL;
    
    return 0;
}

Measured memory_bytes: 3656
#include<iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<map>
#include<math.h>
#include<queue>
#include<deque>
#include<stack>
#include<cstdio>
#include<utility>
#include<set>
#include<list>
#include<cmath>
#include<stdio.h>
#include<string.h>
#include<iomanip>
#include<cstdio>
#include<cstdlib>
#include<cstring>
using namespace std;
#define FOR(i, a, b) for (ll i = (a); i <= (b); i++)
#define REP(i, n) FOR(i, 0, n - 1)
#define NREP(i, n) FOR(i, 1, n)
using ll = long long;
using pii = pair<int, int>;
using piii = pair<pii, pii>;
const ll dx[4] = { -1, 0, 0, 1 };
const ll dy[4] = { 0, -1, 1, 0 };
const ll INF = 1e9 + 7;
const ll inf = 1LL << 50;
int gcd(int x, int y) {
	if (x < y)swap(x, y);
	if (y == 0)return x;
	return gcd(y, x%y);
}
void mul(ll a, ll b) {
	a = a * b % INF;
}
struct Accelerate_Cin {
	Accelerate_Cin() {
		cin.tie(0);
		ios::sync_with_stdio(0);
		cout << fixed << setprecision(20);
	};
};
///////////////////////////////////////

//あらかじめソートすることでc1>=c2>=,,,,>=cNとしてよい
//それらの辺とその端点からなるTの部分グラフをUとするUは森になるのでk+1個以上の頂点を持つ
//したがってk本の辺に書き込まれる整数のうち最小のものはck+1以下になる。
//この考察により各辺に書き込まれる整数をx1,,,xN-1するとxi<=ci+1となることがわかる
//したがってスコアは常にc2+,,,cN以下
//またスコアはc2+,,,,+cNとなるように構成できる
//Tの辺を選んで両端にc1,c2をそれぞれ書き込む
//k=2,,,,N-1に対して次の操作を繰り返す
//e1,,ekとその端点からなるTの部分グラフが連結になるようにTの辺ekを選ぶことができる

int N;
vector<vector<int>>V;
vector<int>c;
int ans[10010];
bool visited[10010];
int cnt = 1;
int main() {
	cin >> N;
	V.resize(N);
	int sum = 0;
	REP(i, N - 1) {
		int a, b; cin >> a >> b;
		a--, b--;
		V[a].push_back(b);
		V[b].push_back(a);
	}
	c.resize(N);
	REP(i, N) {
		cin >> c[i];
		sum += c[i];
		visited[i] = false;
	}
	sort(c.begin(), c.end(),greater<int>());
	sum -= c[0];
	cout << sum << endl;
	queue<int>que;
	que.push(0);
	ans[0] = c[0];
	visited[0] = true;
	while (!que.empty()) {
		int x = que.front();
		que.pop();
		for (int a : V[x]) {
			if (visited[a])continue;
			que.push(a);
			ans[a] = c[cnt];
			cnt++;
			visited[a] = true;
		}
	}
	REP(i, N)cout << ans[i] << " ";
	return 0;
}


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


int main(){
    set<long long> s;

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

    bool flag = true;
    for(int i=0; i<N; ++i){
        if( s.count(A[i]) > 0 ){
            flag = false;
            break;
        }

        s.insert(A[i]);
    }

    if(flag){
        cout << "YES" << endl;
    }else{
        cout << "NO" << endl;
    }

}


Measured memory_bytes: 14352
import sys
from collections import deque

readline = sys.stdin.readline
readall = sys.stdin.read
ns = lambda: readline().rstrip()
ni = lambda: int(readline().rstrip())
nm = lambda: map(int, readline().split())
nl = lambda: list(map(int, readline().split()))


def solve():
    h, w, k = nm()
    sy, sx, gy, gx = nm()
    d = [(0, 1), (1, 0), (-1, 0), (0, -1)]
    sx -= 1; sy -= 1
    gx -= 1; gy -= 1
    C = [ns() for _ in range(h)]
    G = [[10**7]*w for _ in range(h)]
    G[sy][sx] = 0
    q = deque([(sy, sx)])
    while q:
        y, x = q.popleft()
        for i in range(4):
            dy, dx = d[i]
            ny, nx = y, x
            for _ in range(k):
                ny += dy; nx += dx
                if ny < 0 or h <= ny or nx < 0 or w <= nx:
                    break
                if C[ny][nx] == '@' or G[ny][nx] <= G[y][x]:
                    break
                if G[ny][nx] > G[y][x] + 1:
                    G[ny][nx] = G[y][x] + 1
                    q.append((ny, nx))
    ans = G[gy][gx]
    print(ans if ans < 10**7 else -1)
    return

solve()


Measured memory_bytes: 38280
#include<iostream>
using namespace std;
int main()
{
    int n;
    cin>>n;
    int a,b,c,d;
    a=n/1000;
    b=n/100%10;
    c=n/10%10;
    d=n%10;
    if (a==b && b==c)  cout<<"Yes"<<endl;
    else
    {
        if (b==c && c==d)  cout<<"Yes"<<endl;
         else  cout<<"No"<<endl;
    }
    system("pause");
    return 0;
}

Measured memory_bytes: 504
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#include<math.h>
#include<algorithm>
#include<queue>
#include<set>
#include<map>
#include<iostream>
using namespace std;
#define re register
#define ll long long
inline int gi(){
	int f=1,sum=0;char ch=getchar();
	while(ch>'9' || ch<'0'){if(ch=='-')f=-1;ch=getchar();}
	while(ch>='0' && ch<='9'){sum=(sum<<3)+(sum<<1)+ch-'0';ch=getchar();}
	return f*sum;
}
int main(){
	int h=gi(),a=gi();
	printf("%d\n",h/a+(h%a?1:0));
	return 0;
}


Measured memory_bytes: 256
import java.util.Scanner;
 
public class Main {
	public static void main(String[] args) {
		Scanner scanner = new Scanner(System.in);
		char[] array = scanner.next().toCharArray();
 
		int a = Character.getNumericValue(array[0]);
		int b = Character.getNumericValue(array[1]);
		int c = Character.getNumericValue(array[2]);
		int d = Character.getNumericValue(array[3]);
 
		String op1 = "+";
		String op2 = "+";
		String op3 = "+";
 
		int ans = a;
 
		for (int i = 0; i < 2; i++) {
			for (int j = 0; j < 2; j++) {
				for (int k = 0; k < 2; k++) {
					ans = a;
					if (i == 0) {
						ans += b;
					} else {
						ans -= b;
					}
					if (j == 0) {
						ans += c;
					} else {
						ans -= c;
					}
					if (k == 0) {
						ans += d;
					} else {
						ans -= d;
					}
					if(ans == 7){
						if(i == 1){
							op1 = "-";
						}
						if(j == 1){
							op2 = "-";
						}
						if(k == 1){
							op3 = "-";
						}
						System.out.println(a + op1 + b + op2 + c + op3 + d + "=7");
						return;
					}
				}
			}
		}
	}
}

Measured memory_bytes: 21716
#include <bits/stdc++.h>
//登録しよう！→ https://www.youtube.com/channel/UCRXsI3FL_kvaVL9zoolBfbQ
using namespace std;
using ll = long long;
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}//a,bの最大公約数(gcd)を求める
ll lcm(ll a,ll b){return abs(a*b)/gcd(a,b);}//a,bの最小公倍数(lcm)を求める
vector<ll> enum_div(ll n){vector<ll> ret;for(int i=1 ; i*i<=n ; i++){if(n%i == 0){ret.push_back(i);if(i!=1 && i*i!=n)ret.push_back(n/i);}}ret.push_back(n);return ret;}
//↑nの約数を求める
vector<bool> IsPrime; void sieve(size_t max){if(max+1 > IsPrime.size())IsPrime.resize(max+1,true);IsPrime[0] = false;IsPrime[1] = false;for(size_t i=2; i*i<=max; ++i)if(IsPrime[i])for(size_t j=2; i*j<=max; ++j)IsPrime[i*j] = false;}
//↑エラトステネスの篩で素数を求める
#define roundup(divisor,dividend) (divisor + (dividend - 1)) / dividend //切り上げ割り算
#define all(x) (x).begin(),(x).end() //xの初めから終わりまでのポインタ
#define size_t ll //size_tは自動でllに変換される
#define pb(x) push_back(x)
#define gre greater //sortを降順にする
#define pri_queue priority_queue //優先度付きキュー
#define syo(x) fixed << setprecision(x) //iostreamで小数をx桁表示
const long long MOD = 2;

void solve(long long N, std::vector<long long> A){
  int ans = 0;
  bool end = false;
  while(1){
    for (int l = 0; l < N; l++) {
      if(A[l]%2 == 1)end = true;
      A[l] /= 2;
    }
    if(end)break;
    ans++;
  }
  cout << ans << endl;
}

// Generated by 1.1.6 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
int main(){
    long long N;
    scanf("%lld",&N);
    std::vector<long long> A(N);
    for(int i = 0 ; i < N ; i++){
        scanf("%lld",&A[i]);
    }
    solve(N, std::move(A));
}


Measured memory_bytes: 256
N = int(input())
h = [int(i) for i in input().split()]
dp = [0]*N
dp[0],dp[1] = 0,abs(h[1]-h[0])
for i in range(2,N):
    dp[i] = min(dp[i-2] + abs(h[i]-h[i-2]), dp[i-1] + abs(h[i]-h[i-1]))

print(dp[N-1])


Measured memory_bytes: 13708
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll,ll> PP;
#define MOD 1000000007
//#define MOD 998244353
#define INF 1145141919810893364
//#define INF 810114514
#define PI 3.141592653589
#define setdouble setprecision
#define REP(i,n) for(ll i=0;i<(n);++i)
#define OREP(i,n) for(ll i=1;i<=(n);++i)
#define RREP(i,n) for(ll i=(n)-1;i>=0;--i)
#define GOODBYE do { cout << "0" << endl; return 0; } while (false)
#define MM <<" "<<
#define Endl endl
#define debug false
#define debug2 false


int main(void){
    ll N,a,b;
    vector<pair<ll,ll>> UV;
    cin >> N;
    REP(i,N-1){
        cin >> a >> b;
        UV.push_back({a,b});
    }
    
    ll Ans = N*(N+1)*(N+2)/6;
    REP(i,N-1){
        if(UV[i].first>UV[i].second)swap(UV[i].first,UV[i].second);
        Ans -= UV[i].first*(N+1-UV[i].second);
    }
    
    cout << Ans << endl;
    
    return 0;
}



Measured memory_bytes: 7448
import java.util.*;

public class Main{
    public static void main(String[] args){
        Scanner scan=new Scanner(System.in);
        int n,minN,q=0;
        String tmpstr="";
        n=scan.nextInt();
        String[] sortN=new String[n];
        String[] sort0=new String[n];
        String[] sort1=new String[n];
        int[] stablechecker=new int[n];
        int checker=1;
        
        for(int i=0; i<n; i++){
            sort0[i]=sort1[i]=sortN[i]=scan.next();
        }
        
        for(int i=0; i<n; i++)
            for(int j=i+1; j<n; j++)
                if(sortN[i].charAt(1)==sortN[j].charAt(1)){
                    stablechecker[i]=stablechecker[j]=checker;
                    checker++;
                }
                        
        //System.out.println(Arrays.toString(sort0)+Arrays.toString(sort1));
        for(int i=0; i<n-1; i++){
            for(int j=0; j<n-1; j++){
                if(sort0[j].charAt(1)-'0'>sort0[j+1].charAt(1)-'0'){
                    tmpstr=sort0[j];
                    sort0[j]=sort0[j+1];
                    sort0[j+1]=tmpstr;
                }
            }
        }
        for(int i=0; i<n; i++){
            System.out.print(sort0[i]);
            if(i!=n-1)
                System.out.print(" ");
            else
                System.out.println();
        }
        System.out.println("Stable");
    	
        for(int i=0; i<n; i++){
            minN=i;
            for(int j=i+1; j<n; j++){
                if(sort1[minN].charAt(1)-'0'>sort1[j].charAt(1)-'0'){
                    minN=j;
                }
            }
            if(minN!=i){
                tmpstr=sort1[minN];
                sort1[minN]=sort1[i];
                sort1[i]=tmpstr;
            }
        }
        for(int i=0; i<n; i++){
            System.out.print(sort1[i]);
            if(i!=n-1)
                System.out.print(" ");
            else
                System.out.println();
        }
        if(Arrays.toString(sort0).equals(Arrays.toString(sort1)))
            System.out.println("Stable");
        else
            System.out.println("Not stable");
        
        //System.out.println(Arrays.toString(sort0)+Arrays.toString(sort1));
    }
}


Measured memory_bytes: 26284
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define Int int32_t
#define all(c) c.begin(), c.end()
#define FAST ios_base::sync_with_stdio(false) , cin.tie(NULL);
#define pii pair<int,int>
#define pb push_back
#define F first
#define S second
#define endl "\n"
#define bitcnt(n) __builtin_popcountll(n)
#define setpre(n) cout << fixed << setprecision(n)
#define tr(c) for(const auto& x : c )cout << x << " "; cout << "\n";
#define ol(c, s, e) for(int pos=s; pos<e; pos++)cout << c[pos] << " ";cout <<"\n";
#define PI acos(-1LL)

const int M = 1000000007;
const int N = 2e5 + 5;
const long long INF = 1e9 + 12;

vector<vector<int>> v;
int n, weight;
int dp[105][N];

//fun returns the minimum weight of items with total value exactly i;
int fun(int i, int val){
    if(val == 0 )
        return 0;
    if(val < 0 || i <= 0)
        return INF;
    if(dp[i][val]!=-1)
        return dp[i][val];
    return dp[i][val] = min(fun(i-1,val), fun(i-1, val-v[i][1])+v[i][0]);
}
void solve() {
    cin >> n >> weight;
    v.resize(n+1, vector<int>(2));
    memset(dp, 0, sizeof dp);
    int sum = 0;

    for(int i=1; i<=n; i++) {
        cin >> v[i][0] >> v[i][1];
        sum+=v[i][1];
    }
    for(int i=1; i<=sum; i++){
        dp[0][i] = INF;
    }
    for(int i=1; i<=n; i++){
        for(int j=0; j<=sum; j++){
            dp[i][j] = dp[i-1][j];
            if(j - v[i][1] >=0){
                dp[i][j] = min(dp[i-1][j-v[i][1]] + v[i][0] , dp[i][j]);
            }
        }
    }
    int ans = 0;
    for(int i=1; i<=sum; i++){
        int minWt = dp[n][i];
        if(minWt <= weight)
            ans = i;
    }
    cout << ans << endl;
}

signed main(){
    FAST
    int tc = 1;
//    TODO: check for tc
//    cin >> tc;
    for (int t = 1; t <= tc; t++) {
        solve();
    }
}


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

typedef long long ll;

const int N = 100100;
const ll INF = (ll)1e18;

ll a[N];

int main(void) {
	int n, k;
	scanf("%d%d", &n, &k);
	for (int i = 0; i < n; ++i) {
		scanf("%lld", &a[i]);
	}
	ll ans = INF;
	for (int i = 0; i + k - 1 < n; ++i) {
		ll cur = a[i + k - 1] - a[i];
		if (a[i + k - 1] <= 0) {
			cur += llabs(a[i + k - 1]);
		} else if (a[i] >= 0) {
			cur += llabs(a[i]);
		} else {
			cur += std::min(llabs(a[i + k - 1]), llabs(a[i]));
		}
		ans = std::min(ans, cur);
	}
	printf("%lld\n", ans);
	return 0;
}

Measured memory_bytes: 1024
import sys,heapq
from collections import deque,defaultdict
printn = lambda x: sys.stdout.write(x)
inn = lambda : int(input())
inl   = lambda: list(map(int, input().split()))
inm   = lambda:      map(int, input().split())
DBG = True # and False
def ddprint(x):
  if DBG:
    print(x)

n = inn()
edges = []
dst = [ [] for i in range(n) ]
for i in range(n-1):
    a,b = inm()
    a -= 1
    b -= 1
    dst[a].append(b)
    dst[b].append(a)
    edges.append((a,b))
c = inl()

c.sort(reverse=True)
labs = [-1] * n
q = []
for i in range(n):
    if len(dst[i]) == 1:
        q.append(i)

while(len(q)>1):
    i = q.pop()
    labs[i] = c.pop()
    d = dst[i][0]
    dst[d].remove(i)
    if len(dst[d]) == 1:
        q.append(d)

i = q.pop()
labs[i] = c.pop()

m = 0
for z in edges:
    m += min(labs[z[0]], labs[z[1]])
print(m)
for i in range(n):
    printn(str(labs[i]) + ' ')
print("")


Measured memory_bytes: 7000
#include <stdio.h>
#define rep(i, n) for (int i = 0; i < (int) (n); i++)
typedef long long ll;

int main(){
	int bingo[9];
	int g[] = {0,0,0,0,0,0,0,0,0};
	rep(i, 9){
      scanf("%d", &bingo[i]);
    }
	int n = scanf("%d", &n);
	int call[10];
	for (int i = 0; i < 10; i++){
		scanf("%d", &call[i]);
		rep(j, 9){
			if (call[i] == bingo[j]){
				g[j] = 1;
				if (((g[0] == 1) && (g[3] == 1) && (g[6] == 1)) || ((g[1] == 1) && (g[4] == 1) && (g[7] == 1)) || ((g[2] == 1) && (g[5] == 1) && (g[8] == 1)) || ((g[0] == 1) && (g[1] == 1) && (g[2] == 1)) || ((g[3] == 1) && (g[4] == 1) && (g[5] == 1)) || ((g[6] == 1) && (g[7] == 1) && (g[8] == 1)) || ((g[0] == 1) && (g[4] == 1) && (g[8] == 1)) || ((g[2] == 1) && (g[4] == 1) && (g[6] == 1))){
					printf("Yes");
					return 0;
				}
			}
		}
	}
	printf("No");
	return 0;
}



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

int main(){

    int x;
    cin >> x;

    if (x >= 400 && x< 600){
        cout << 8 << endl;
    }else if (x >= 600 && x <800){
        cout << 7 << endl;
    }else if ( x >= 800 && x<1000){
        cout << 6 << endl;
    }else if (x >= 1000 && x <1200){
        cout << 5 << endl;
    }else if (x >= 1200 && x<1400){
        cout << 4 << endl;
    }else if (x >=1400 && x <1600){
        cout <<3<<endl;
    }else if (x>=1600 && x<1800){
        cout <<2<<endl;
    }else if (x>=1800){
        cout <<1<<endl;
    }
}


Measured memory_bytes: 3608
#include<bits/stdc++.h> 
using namespace std;
using ll=long long;
typedef pair<int,int> P;
#define fi first
#define se second
#define all(v) (v).begin(),v.end()
const ll inf=(1e18);
const ll mod=1000000007;
const ll mod2=998244353;
ll gcd(ll a,ll b) {return b ? gcd(b,a%b):a;}
ll lcm(ll c,ll d){return c/gcd(c,d)*d;}
vector<vector<int>> graph;
//ios_base::sync_with_stdio(false);
//cin.tie(NULL);
ll dp[100010][2];
bool flag[100010];
void dfs(int i){
	flag[i]=true;
	dp[i][0]=1;
	dp[i][1]=1;
	for(int j:graph[i]){
        if(flag[j])continue;
		dfs(j);
		(dp[i][0]*=(dp[j][0]+dp[j][1])%mod)%=mod;
		(dp[i][1]*=dp[j][0])%=mod;
	}
}
int main(){
ios_base::sync_with_stdio(false);
cin.tie(NULL);
int n;cin>>n;
graph.resize(n);
for(int i=0;i<n-1;i++){
    int a,b;cin>>a>>b;
    a--;b--;
    graph[a].push_back(b);
    graph[b].push_back(a);
}
dfs(0);
cout<<(dp[0][0]+dp[0][1])%mod<<endl;
}


Measured memory_bytes: 11520
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <bitset>
#include <map>
#include <tuple>
#include <unordered_map>
#include <list>
#include <numeric>
#include <utility>
#include <iterator>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cstring>
#include <climits>
#include <ctime>
#include <cassert>

#define INF 1000000000
#define LINF 9000000000000000000
#define mod 1000000007

#define rep(i,n) for(int i=0;i<int(n);i++)
#define rrep(i,n) for(int i=n-1;i>=0;i--)
#define REP(i,a,b) for(int i=(a);i<int(b);i++)
#define all(x) (x).begin(),x.end()
#define pb push_back
#define mp make_pair

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef vector<long long>vll;
typedef pair<int,int> pi;
int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};
int ddx[8]={-1,-1,0,1,1,1,0,-1};
int ddy[8]={0,1,1,1,0,-1,-1,-1};
bool debug=false;

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

int main(){
  vector<ll> ans(3);
  int k;
  
  cin >> ans[0] >> ans[1] >> ans[2];
  cin >> k;
  sort(all(ans));

  cout << ans[0] + ans[1] + ans[2] * pow(2, k) << endl;
  
  return 0;
}


Measured memory_bytes: 256
a,b,c=gets.split(' ').map(&:to_i)
array=[0]
count=3
if array.include?(a)
	count-=1
end
array.push(a)
if array.include?(b)
	count-=1
end
array.push(b)
if array.include?(c) 
	count-=1
end
p count

Measured memory_bytes: 1788
#include<cstdio>
#include <iostream>
#include<algorithm>
#include<string>
#include<queue>
#include<vector>
#include<functional>
#include<cmath>
#include<map>
#include<stack>
#include<set>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
const ll MOD = 1000000007;

int main() {

	ll h, w;
	cin >> h >> w;

	ll s = h * w;
	ll ans = 10000000000;
	if (h % 3 == 0 || w % 3 == 0) 
		ans = 0;
	else {
		ll mi = min(h, w);
		ll ma = max(h, w);

		for (ll i = 1; i < ma; i++) {
			ll sa = i * mi;
			ll sb = (ma - i) * (mi / 2);
			ll sc = s - sa - sb;
			ll diff = max(abs(sa - sc), max(abs(sa - sb), abs(sb - sc)));
			ans = min(diff, ans);
		}
		for (ll i = 1; i < mi; i++) {
			ll sa = i * ma;
			ll sb = (mi - i) * (ma / 2);
			ll sc = s - sa - sb;
			ll diff = max(abs(sa - sc), max(abs(sa - sb), abs(sb - sc)));
			ans = min(diff, ans);
		}
		ans = min(ans, mi);
	}
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 256
var output;
var input = require("fs").readFileSync("/dev/stdin", "utf8").trim().split("\n");
var obj = {
  "list" : input,
  "index" : 0,
  "max" : input.length,
  "next" : function(){
    if(!this.hasNext()){throw "NoSuchElementException:次に要素は無いよ";}
    var returnObj = this.list[this.index];
    this.index++;
    return returnObj;
  },
  "hasNext" : function(){return (this.index < this.max);}
}
Main();
function next(){return obj.next();}
function hasNext(){return obj.hasNext();}
function myout(t){console.log(t);}//standard output
function myerr(t){console.error(t);}//standard error
//[no]要素の扱い。数値型
//不明値、異常時:引数そのまま返す
//1:数値へ変換 2:半角SPで分割 4:半角SPで分割し、数値配列へ
//6:1文字に分割 7:1文字に分割し、数値配列へ
//8:半角SPで結合 9:改行で結合 0:文字なしで結合
function myconv(i,no){try{switch(no){case 1:return parseInt(i);case 2:return i.split(" ");case 4:return i.split(" ").map((a)=>Number(a));case 6:return i.split("");case 7:return i.split("").map((a)=>Number(a));case 8:return i.join(" ");case 9:return i.join("\n");case 0:return i.join("");default:return i;}}catch(e){return i;}}
function Main() {
  var one = myconv(next(),4);
  var N = one[0];
  var K = one[1];
  var list = new Array(N);
  var cost = myconv(next(),4);
  list[0] = 0;
  for(var i = 0; i < N; i++){
       for(var j = 1; j <= K; j++){
         if(i + j >= N){break;}
         if(list[i + j] == null){
            list[i + j] = list[i] + Math.abs(cost[i] - cost[i + j]);
         }else{
            list[i + j] = Math.min(list[i] + Math.abs(cost[i] - cost[i + j]), list[i + j]);
         }
       }
    
  }
  myout(list[N - 1]);
}

Measured memory_bytes: 28732
#include <iostream>
using namespace std;
 
int main() {
	int n;
	cin >> n;
	int h = 0;
	int num = 0;
	for (int i = 0; i < n; ++i) {
		int h_i;
		cin >> h_i;
		if (h_i >= h) {
			h = h_i;
			++num;
		}
	}
	cout << num << endl;
	return 0;
}

Measured memory_bytes: 256
import Data.List
main :: IO ()
main = do
    [_,k] <- fmap (map read . words) getLine 
    h0:hs <- fmap (map read . words) getLine
    let c_end = snd $ head $ foldl' step s0 hs 
        step l h = (h, c) : l
            where c = minimum 
                        $ map (\(hi,ci) -> ci + abs (hi - h))
                        $ take k l
        s0 = [(h0, 0)]
    print (c_end :: Int)
    



Measured memory_bytes: 109948
import java.util.Arrays;
import java.util.HashMap;
import java.util.Map;
import java.util.Scanner;

public class Main {
	static int cnt = 0;
	public static void main(String[] args) throws Exception {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		Map<Integer, Integer> map = new HashMap<>();
		for (int i = 0; i < n; i++) {
			int a = sc.nextInt();
			putCntMap(map, a);
		}
		sc.close();

		Integer[] k = map.keySet().toArray(new Integer[0]);
		if (k.length > 3) {
			System.out.println("No");
		} else if (k.length == 3) {
			Arrays.parallelSort(k);
			if (k[0] == 0) {
				System.out.println("No");
			} else {
				int v0 = map.get(k[0]);
				int v1 = map.get(k[1]);
				int v2 = map.get(k[2]);
				if (v0 == v1 && v1 == v2) {
					if ((k[0] ^ k[1]) == k[2] && (k[0] ^ k[2]) == k[1] && (k[2] ^ k[1]) == k[0]) {
						System.out.println("Yes");
					} else {
						System.out.println("No");
					}
				} else {
					System.out.println("No");
				}
			}
		} else if (k.length == 2) {
			Arrays.parallelSort(k);
			if (k[0] == 0) {
				int v0 = map.get(k[0]);
				int v1 = map.get(k[1]);
				if (v0 * 2 == v1) {
					System.out.println("Yes");
				} else {
					System.out.println("No");
				}
			} else {
				System.out.println("No");
			}
		} else if (k.length == 1) {
			if (k[0] == 0) {
				System.out.println("Yes");
			} else {
				System.out.println("No");
			}
		}
	}

	static void putCntMap(Map<Integer, Integer> map, Integer key) {
		if (map.containsKey(key)) {
			map.put(key, map.get(key) + 1);
		} else {
			map.put(key, 1);
		}
	}
}


Measured memory_bytes: 60184
#include <iostream>
#include <vector>
#include <chrono>
#include <random>
#include <algorithm>
#include <cassert>

std::mt19937 rng((int) std::chrono::steady_clock::now().time_since_epoch().count());

const int MOD = 1e9 + 7;
const int ms = 200200;

long long fexp(long long x, long long e = MOD - 2) {
	long long ans = 1;
	for(; e > 0; e /= 2) {
		if(e & 1) ans = ans * x % MOD;
		x = x * x % MOD;
	}
	return ans;
}

long long fat[ms], ifat[ms];

long long comb(int n, int a) {
	return a < 0 || a > n ? 0LL : fat[n] * ifat[a] % MOD * ifat[n - a] % MOD;
}

int main() {
	std::ios_base::sync_with_stdio(false); std::cin.tie(NULL);
	fat[0] = ifat[0] = 1;
	for(int i = 1; i < ms; i++) {
		fat[i] = (long long) fat[i-1] * i % MOD;
		ifat[i] = fexp(fat[i]);
	}
	long long good = 1, bad = 0;
	int w, b;
	std::cin >> b >> w;
	for(int i = 0; i < b + w; i++) {
		if(i < b) {
			//good = fexp(2, i);
		}
		if(i == w) {
			bad = 1;
		}
		//std::cout << "for " << i << " got (" << good << ", " << bad << "), " << fexp(2) << ", " << fexp(fexp(2), i + 1) << "\n";
		std::cout << (good + bad) * fexp(fexp(2), i + 1) % MOD << '\n';
		{
			long long trans = (good - 1 + comb(i, b) + MOD) % MOD;
			//std::cout << trans << '\n';
			//std::cout << "(" << 1 << " + " << good << " + " << trans << " - " << comb(i+1, b) << ")\n";
			good = (1 + good + trans - comb(i + 1, b) + MOD) % MOD;
		}
		{
			long long trans = (bad - comb(i, w) + MOD) % MOD;
			bad = (bad + trans + MOD + comb(i+1, w)) % MOD;
		}
	}
}

Measured memory_bytes: 5376
#include <iostream>
#include <bits/stdc++.h>
#define lli  long long int
using namespace std;
#define S second
#define F first
#define pb push_back
#define M1 1000000007
#define M2 998244353
#define plli pair<lli,lli>
#define setit set<lli>::iterator seti
#define mapit map<lli,lli> ::iterator mapi
#define MP make_pair
#define MT make_tuple
#define PI 3.14159265358979323846
// map      iterator->first  iterator.first
// map      auto pl:mp       pl.S && pl.F
// map      mp[key]=value
// set      *s.begin()
// vector   v[j]=value
// pair     p.first p.second
// vector of pairs v[j].first v[j].second
// tuple    get<index>(tuple_name)
// vector of tuples get<index>(v[j])  sort(v.begin(),v.end())
//priority queue .top() .pop() .push()
// __gcd(x,y)
#define mini(x,y) (y + ((x - y) & ((x - y) >>(sizeof(int) * CHAR_BIT - 1))))
#define maxi(x,y) (x - ((x - y) & ((x - y) >> (sizeof(int) * CHAR_BIT - 1))))
#define fr(j,a,b) for(j=a;j<b;j++)

int power(int x, unsigned int y, int p)
{   int res = 1;
    x = x % p;
    if (x == 0) return 0;
    while (y > 0)
    {   if (y & 1)
            res = (res * x) % p;
        y = y >> 1;
        x = (x * x) % p;
    }
    return res;
}

int main()
{
#ifndef ONLINE_JUDGE
    // for getting input from input.txt
    freopen("input.txt", "r", stdin);
    // for writing output to output.txt
    freopen("output.txt", "w", stdout);
#endif
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    int t, i, j, n, x;
    cin >> t;
    if (t % 1000 == 0) {
        cout << "0";
    }
    else {
        cout << (((t + 1000) / 1000) * 1000) - t;
    }
}


Measured memory_bytes: 3620
N, C = map(int, input().split())
x = []
v = []
for i in range(N):
    a, b = map(int, input().split())
    x.append(a)
    v.append(b)

R = [v[0] - x[0]] + [0] * (N - 1)
L = [0] * (N - 1) + [v[-1] - (C - x[-1])]
for i in range(1, N):
    R[i] = R[i - 1] + v[i] - (x[i] - x[i - 1])
    L[-1-i] = L[-i] + v[-1-i] - (x[-i] - x[-1-i])

Rmax = [R[0]] + [0] * (N - 1)
Lmax = [0] * (N - 1) + [L[-1]]
for i in range(1, N):
    Rmax[i] = max(Rmax[i-1], R[i])
    Lmax[-1-i] = max(Lmax[-i], L[-1-i])

R2L = Rmax[-1]
L2R = Lmax[0]
for i in range(N-1):
    R2L = max(R2L, R[i] - x[i] + Lmax[i+1])
    L2R = max(L2R, L[-1-i] - (C - x[-1-i]) + Rmax[-1-i-1])

print(max(0, R2L, L2R))

Measured memory_bytes: 22256
#include <bits/stdc++.h>
#include <algorithm>
#include <string>

using namespace std;
#define rep(i,n) for(int i=0;i<n;i++)
int main(){
	int N;cin>>N;
	int K;cin>>K;
  	string S;cin>>S;
	char target;target=S[K-1];
  
  	S[K-1]=target+32;
  
  	
	cout<<S<<endl;
  
}


Measured memory_bytes: 256
import sys

input = sys.stdin.readline
mod = 1000000007
n, m = map(int, input().split())
dp = [0] * (n + 1)
dp[0] = 1
ng = set()
for _ in range(m):
    a = int(input())
    ng.add(a)

for i in range(n):
    next1 = i + 1
    if next1 not in ng:
        dp[next1] += dp[i]
        dp[next1] %= mod
    next2 = i + 2
    if next2 not in ng and next2 <= n:
        dp[next2] += dp[i]
        dp[next2] %= mod
print(dp[-1])

Measured memory_bytes: 18064
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <cstdio>
#include <cstring>
#include <cmath>
using namespace std;
using ll = long long;

int main() {
    string s;
    cin >> s;
    int n = s.size();

    int b = n % 2 == 0;
    for (int i = 0; i < n; i += 2) {
        if (s[i] != 'h') b = 0;
        if (s[i + 1] != 'i') b = 0;
    }

    cout << (b ? "Yes" : "No") << endl;

    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <stack>

//求解图的联通分量

using namespace std;

static const int MAX = 100000;
static const int NIL = -1;

int n;
vector<int> G[MAX];
int color[MAX];

void dfs(int r, int c) {
    stack<int> S;
    S.push(r);

    color[r] = c;

    while (!S.empty()) {
        int u = S.top();
        S.pop();
        for (int i = 0; i < G[u].size(); i++) {
            int v = G[u][i];
            if (color[v] == NIL) {
                color[v] = c;
                S.push(v);
            }
        }
    }
}

void assignColor() {
    int id = 1;
    for (int i = 0; i < n; i++)
        color[i] = NIL;

    for (int u = 0; u < n; u++) {
        if (color[u] == NIL)
            dfs(u, id++);
    }
}

int main() {
    int s, t, m, q;

    cin >> n >> m;
    for (int i = 0; i < m; i++) {
        cin >> s >> t;
        G[s].push_back(t);
        G[t].push_back(s);
    }

    assignColor();
    cin >> q;

    for (int i = 0; i < q; i++) {
        cin >> s >> t;
        if (color[s] == color[t])
            cout << "yes" << endl;
        else
            cout << "no" << endl;
    }

    return 0;
}


Measured memory_bytes: 8996
/**
 * code generated by JHelper
 * More info: https://github.com/AlexeyDmitriev/JHelper
 * @author Kein Yukiyoshi
 */

#include "bits/stdc++.h"
#define int long long
#define rep(i, n)           for (int i = 0; i < (int)(n); i++)
#define REP(i, a, b)        for (int i = (int)(a); i < (int)(b); i++)
#define FOR(i, a)           for (auto &i : a)
#define ALL(obj)            begin(obj), end(obj)
#define MAX(x)              *max_element(ALL(x))
#define MIN(x)              *min_element(ALL(x))
#define SUM(x)              accumulate(ALL(x), 0LL)
#define LOWER_BOUND(A, key) distance(A.begin(), lower_bound(ALL(A), key))
#define UPPER_BOUND(A, key) distance(A.begin(), upper_bound(ALL(A), key))

using namespace std;
const int MOD    = (int)(1e9 + 7);
const int INF    = (int)(1e13 + 7);
const double EPS = 1e-14;
const double PI  = acos(-1);

int CEIL(int a, int b) { return (a >= 0 ? (a + (b - 1)) / b : (a - (b - 1)) / b); } //ceil() for int
int mod(int a, int b) { return a >= 0 ? a % b : a - (b * CEIL(a, b)); }             //always return positive num
int bpm(int a, int b) {                                                             //return x^y in order(log(y))
  int res = 1;
  for (a %= MOD; b; a = a * a % MOD, b >>= 1)
    if (b & 1) res = res * a % MOD;
  return res;
}

class BMixJuice {
public:
  static void solve(istream &cin, ostream &cout) {
    int N, K;
    cin >> N >> K;
    vector<int> p(N);
    rep(i, N) cin >> p[i];
    sort(ALL(p));
    int ans = 0;
    rep(i, K) ans += p[i];
    cout << ans << endl;
  }
};


signed main() {
  cin.tie(0);
  cout.tie(0);
  ios_base::sync_with_stdio(false);
  cout<<fixed<<setprecision(15);
  BMixJuice solver;
  std::istream& in(std::cin);
  std::ostream& out(std::cout);
  solver.solve(in, out);
  return 0;
}


Measured memory_bytes: 3640