akhauriyash/Code-Regression huggingface dataset:
def solve(s, k):
    n = len(s)
    s = list(s)
    if len(set(s)) == 1:
        return n*k//2
    a = 0
    for i in range(n):
        if s[0] == s[i]:
            a += 1
        else:
            break
    b = 0
    for i in range(n):
        if s[-1] == s[-1-i]:
            b += 1
        else:
            break
    c = 0
    for i in range(a, n-b-1):
        if s[i] == s[i+1]:
            c += 1
            s[i+1] = "."
    res = a//2 + b//2 + c*k
    if s[0] == s[-1]:
        res += ((a+b)//2) * (k-1)
    else:
        res += (a//2 + b//2) * (k-1)
    return res

s = input()
k = int(input())
print(solve(s, k))

Measured memory_bytes: 3064
import java.util.Scanner;

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

		String S = sc.nextLine();
		String T = sc.nextLine();
		String[] Ss = S.split("");
		String[] Ts = T.split("");

		int count = 0;
		for(int i = 0; i < Ss.length; i++) {
			if(!Ss[i].equals(Ts[i])) {
				count++;
			}
		}

		System.out.println(count);
	}


}


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

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

    int res = 0;

    if(a < b){
        res += b;
        b--;
    }else{
        res += a;
        a--;
    }

    if(a < b){
        res += b;
    }else{
        res += a;
    }

    cout << res << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
using namespace std;
int main(){
    string s;
    cin >> s;
    int len = s.size();
    int ans1 = 0;
    for(int i = 0; i < len; i++)
    {
        if (i%2==0) {
            if (s[i] != '0') {
                ans1++;
            }
        }
        else
        {
            if (s[i] != '1') {
                ans1++;
            }
        }
    }
    int ans2 = 0;
    for(int i = 0; i < len; i++)
    {
        if (i%2==0) {
            if (s[i] != '1') {
                ans2++;
            }
        }
        else
        {
            if (s[i] != '0') {
                ans2++;
            }
        }
    }
    cout << min(ans1,ans2) << endl;
}

Measured memory_bytes: 512
/*
 *    author:  Gary Shih
 *    created: 2020-05-03 22:12:38
 */
#pragma GCC optimize("O3")
#include <bits/stdc++.h>

using namespace std;

int main() {
  ios::sync_with_stdio(0), cin.tie(0), cout.setf(ios::fixed), cout.precision(9);
  int n, k;
  cin >> n >> k;
  vector<int> h(n);
  for (int i = 0; i < n; ++i) cin >> h[i];
  vector<int> dp(n, INT_MAX);
  dp[0] = 0;
  for (int i = 0; i < n; ++i)
    for (int j = 1; j <= k; ++j) {
      if (i + j >= n) break;
      dp[i + j] = min(dp[i + j], dp[i] + abs(h[i] - h[i + j]));
    }
  cout << dp.back() << '\n';
}


Measured memory_bytes: 1024
N, M = map(int, input().split())
cake = [list(map(int, input().split())) for i in range(N)]
def func(p):
    x, y, z = p
    ans = 0
    for j ,k in enumerate(p) :
        if i >> j & 1:
            ans += k
        else:
            ans -= k
    return ans
ans = []
for i in range(8):
    x = 0
    y = 0
    z = 0
    d = sorted(cake, key = func, reverse = True)
    for l in range(M):
        x += d[l][0]
        y += d[l][1]
        z += d[l][2]
    ans.append(abs(x)+abs(y)+abs(z))
print(max(ans))
        
            

Measured memory_bytes: 3316
#include <iostream>
#include <string>
#include <vector>
#include <set>
#include <algorithm>
#include <cctype>
#include <cmath>
#include <queue>
#include <map>
#include <numeric>
#include <unordered_map>
#include <iomanip>
#include <functional>
#include <bitset>
#include <complex>
#include <stack>



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

template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }

typedef long long ll;

using namespace std;


int main()
{
  ios::sync_with_stdio(false);
  cin.tie(0);
  string s;
  vector<int>ss(4);
  cin>>s;
  rep(i,4)ss[i]=s[i]-'0';
  rep(i,8)
  {
    bitset<3> ti=i;
    int tres=ss[0];
    rep(j,3)
    {
      if(ti[j])
      {
        tres+=ss[j+1];
      }
      else
      {
        tres-=ss[j+1];
      }
    }
    if(tres==7)
    {
      cout<<s[0];
      rep(j,3)
      {
        if(ti[j])cout<<"+";
        else cout<<"-";
        cout<<s[j+1];
      }
      cout<<"=7";
      return 0;
    }
  }

  return 0;

}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define FOR(i, a, b) for(int i=(a); i<(b); i++)
#define REP(i, n) FOR(i, 0, n)
#define all(x) (x).begin(), (x).end()
#define bit(x) (1L << (x))
using ll = long long;
using namespace std;

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

  cout << a - b + 1 << endl;

  return 0;
}


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

int main() {
  int n,k;
  cin>>n>>k;
  int ans=k;
  if(n==1) {cout<<ans; return 0;}
  for(int i=1;i<n;i++) ans*=k-1;
  cout<<ans<<endl;
}

Measured memory_bytes: 256
from math import factorial

def fac(n, mod):
    res = 1
    for i in range(1, n + 1):
        res = res * i % mod
    return res


n, m = map(int, input().split())
mod = 10 ** 9 + 7
if abs(n - m) > 1:
    print(0)
else:
    if n == m:
        res = fac(n, mod) * fac(m, mod) * 2 % mod
    else:
        res = fac(n, mod) * fac(m, mod) % mod
    print(res)

Measured memory_bytes: 3064
x=int(input())
if 400<=x<=599:print(8)
elif 600<=x<=799:print(7)
elif 800<=x<=999:print(6)
elif 1000<=x<=1199:print(5)
elif 1200<=x<=1399:print(4)
elif 1400<=x<=1599:print(3)
elif 1600<=x<=1799:print(2)
elif 1800<=x<=1999:print(1)


Measured memory_bytes: 9180
s = input()
ans = 0
#print(ans)
for i in range(2**(len(s)-1)):
  formula = ""
  for j in range(len(s)):
    formula += s[j]
   # print("i=",i,"j=",j,"formula=",formula)
    if (i>>j & 1):
      formula += "+"
  #print(formula)
  ans += eval(formula)
print(ans)

Measured memory_bytes: 3060
#include<iostream>
#include<cmath>
#include<algorithm>
#include<vector>
#include<functional>
#include<string>
#include<iomanip>
#include<map>
#include<utility>
#include<string>
#include<unordered_map>
#include<queue>

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

using namespace std;

typedef long long ll;
typedef pair<int, int> P;
int gcd(int a, int b){return b ? gcd(b, a%b) : a;}
int lcm(int a, int b){return a*b / gcd(a, b);}


int main(){
    int n;
    cin >> n;
    int cnt4 = 0, cnt2 = 0;
    for(int i = 0; i < n; i++){
        int a;
        cin >> a;
        if(a%4 == 0) cnt4++;
        else if(a%2 == 0) cnt2++;
        else continue;
    }

    string ans;
    //cout << cnt2 << " " << cnt4 << endl;
    if(cnt2 == n || n/2 == cnt4 || (n-(cnt4*2+1) < cnt2)) ans = "Yes";
    else ans = "No";

    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 3632
#include<bits/stdc++.h>
using namespace std;
int a,b;
int main()
{
    cin>>a>>b;
    if(a>0) cout<<"Positive"<<endl;
    else if(a==0 || (a<0 && b>0)) cout<<"Zero"<<endl;
    else if((abs(b)-abs(a))%2!=0) cout<<"Positive"<<endl;
    else cout<<"Negative"<<endl;
    return 0;
}

Measured memory_bytes: 256
import heapq
def dijkstra(V, edges, s):
    inf=float('inf')

    dist=[inf]*V
    dist[s]=0
    
    que=[[0,s]]
    heapq.heapify(que) #最小値を管理 [dist[i],i]となる要素

    while  que:
        p=heapq.heappop(que) #距離が最小のものを取り出す
        dis=p[0]
        v=p[1]
        if dist[v] <dis:
            continue
        for edge in edges[v]:
            to_v=edge[0]
            cost=edge[1]
        
            if dist[to_v] > dist[v] + cost:
                dist[to_v]=dist[v]+cost
                heapq.heappush(que,[dist[to_v], to_v])
    
    return dist

def main():
    import sys
    input=sys.stdin.readline
    n=int(input())
    edges=[[] for _ in range(n)]
    for i in range(n-1):
        a,b,c=map(int,input().split())
        a-=1
        b-=1
        edges[a].append([b,c])
        edges[b].append([a,c])
    q,k=map(int,input().split())
    k-=1
   
    dist=dijkstra(n,edges,k)
    for i in range(q):
        x,y=map(int,input().split())
        x-=1
        y-=1
        print(dist[x]+dist[y])
if __name__=='__main__':
    main()

Measured memory_bytes: 55112
#include<cstdio>
#include<cmath>
#include<cstring>
#include<algorithm>
using namespace std;
struct node
{
	int x,y,r;
	double operator - (node b){return max(sqrt(1ll*(x-b.x)*(x-b.x)+1ll*(y-b.y)*(y-b.y))-r-b.r,0.0);}
}a[1005];
double c[1005][1005],d[1005];
bool vis[1005];
int main()
{
	int x,y,k,n;
	scanf("%d%d%d%d",&a[0].x,&a[0].y,&x,&y);
	scanf("%d",&n);
	a[n+1].x=x,a[n+1].y=y;
	for(int i=1;i<=n;i++)
		scanf("%d%d%d",&a[i].x,&a[i].y,&a[i].r);
	n++;
	for(int i=1;i<=n;i++)
		for(int j=i-1;j>=0;j--)
			c[i][j]=c[j][i]=a[i]-a[j];
	memset(d,0x7f,sizeof d);
	d[0]=0;
	for(int i=0;i<n;i++)
	{
		k=n+1;
		for(int j=0;j<=n;j++)
			if(!vis[j]&&d[j]<d[k]) k=j;
		vis[k]=1;
		if(k==n) break;
		for(int j=0;j<=n;j++)
			if(!vis[j]) d[j]=min(d[j],d[k]+c[k][j]);
	}
	printf("%.10lf",d[n]);
}

Measured memory_bytes: 8064
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<climits>
#include<iostream>
#include<algorithm>
#include<stack>
#include<queue>
#include<vector>
#include<list>
#include<map>
#include<set>
typedef long long ll;
typedef unsigned long long ull;
using namespace std;
#define pb push_back
int dy[]={0, 0, 1, -1, 0};
int dx[]={1, -1, 0, 0, 0};
 
#define FOR(i,a,b) for (int i=(a);i<(b);i++)
#define RFOR(i,a,b) for (int i=(b)-1;i>=(a);i--)
#define REP(i,n) for (int i=0;i<(n);i++)
#define RREP(i,n) for (int i=(n)-1;i>=0;i--)
int t[17][17];
int n;
int memo[1 << 17][17];

int dp(int s,int now){
    if(memo[s][now] >= 0)
        return memo[s][now];

    if(s == (1 << (n + 1)) - 1)
        return memo[s][now] = 0;

    int mini = 1000000000;

    for(int i = 1;i <= n;i++){
        if(!((s >> i) & 1)){
            int k = 1,mini2 = t[i][0];
            for(int j = 1;j <= n;j++){
                k <<= 1;
                if((s & k) && mini2 > t[i][j])
                    mini2 = t[i][j];
            }
            mini = min(mini,dp(s | (1 << i),i) + mini2);
        }
    }
    return memo[s][now] = mini;
}

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

        if(n == 0)
            break;

        memset(memo,-1,sizeof(memo));

        for(int i = 1;i <= n;i++)
            for(int j = 0;j <= n;j++)
                scanf("%d",&t[i][j]);
        printf("%d\n",dp(1,0));
    }
    return 0;
}

Measured memory_bytes: 11872
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>

using namespace std;

using lint = long long;
using ldouble = long double;

bool solve() {
    int H, W;
    cin >> H >> W;
    if (H == 0) return false;

    vector<vector<int>> pond(H, vector<int>(W));
    for (auto& v : pond) {
        for (auto& e : v) cin >> e;
    }

    auto cap = [&](int lx, int ly, int rx, int ry) {
        int H = 10;
        for (int x = lx; x <= rx; ++x) {
            H = min({H, pond[x][ly], pond[x][ry]});
        }
        for (int y = ly; y <= ry; ++y) {
            H = min({H, pond[lx][y], pond[rx][y]});
        }

        int sum = 0;
        for (int x = lx + 1; x <= rx - 1; ++x) {
            for (int y = ly + 1; y <= ry - 1; ++y) {
                if (pond[x][y] >= H) return 0;
                sum += H - pond[x][y];
            }
        }
        return sum;
    };

    int ans = 0;
    for (int lx = 0; lx < H; ++lx) {
        for (int ly = 0; ly < W; ++ly) {
            for (int rx = lx + 2; rx < H; ++rx) {
                for (int ry = ly + 2; ry < W; ++ry) {
                    ans = max(ans, cap(lx, ly, rx, ry));
                }
            }
        }
    }

    cout << ans << endl;
    return true;
}

int main() {
    while (solve()) {}
    return 0;
}



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

int main(void){
    
   int A,B,K;
   cin >> K >> A >> B;
   
   for(int i=A;i<=B;i++){
       if(i % K == 0){
           cout << "OK" <<endl;
           break;
       }
       if(i == B) cout << "NG" <<endl;
   }
}

Measured memory_bytes: 3632
#include <cstdio>

const int N = 100000 + 10;

char s[N];

int main() {
  scanf(" %s", s);
  int ans = 0;
  for (char *i = s; *i;) {
    char *j = i;
    while (*j == *i) ++j;
    i = j;
    ++ans;
  }
  printf("%d\n", ans - 1);
  return 0;
}


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

#define _overload3(_1,_2,_3,name,...) name
#define _rep(i,n) repi(i,0,n)
#define repi(i,a,b) for(int i=int(a);i<int(b);++i)
#define rep(...) _overload3(__VA_ARGS__,repi,_rep,)(__VA_ARGS__)

using namespace std;
using ll = long long;
//using P = pair<int,int>;
constexpr int INF = 1001001001;
constexpr int MAX = 100005;

template<class T> bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T> bool chmin(T &a, const T &b) { if (a>b) { a=b; return 1; } return 0; }

const int mod = 1000000007;
struct mint {
    ll x;
    mint(ll x=0):x((x%mod+mod)%mod){}
    mint operator-() const { return mint(-x);}
    mint& operator+=(const mint a) {
        if ((x += a.x) >= mod) x -= mod;
        return *this;
    }
    mint& operator-=(const mint a) {
        if ((x += mod-a.x) >= mod) x -= mod;
        return *this;
    }
    mint& operator*=(const mint a) { (x *= a.x) %= mod; return *this;}
    mint operator+(const mint a) const { return mint(*this) += a;}
    mint operator-(const mint a) const { return mint(*this) -= a;}
    mint operator*(const mint a) const { return mint(*this) *= a;}
    mint pow(ll t) const {
        if (!t) return 1;
        mint a = pow(t>>1);
        a *= a;
        if (t&1) a *= *this;
        return a;
    }
    mint inv() const { return pow(mod-2);}
    mint& operator/=(const mint a) { return *this *= a.inv();}
    mint operator/(const mint a) const { return mint(*this) /= a;}
};
istream& operator>>(istream& is, mint& a) { return is >> a.x;}
ostream& operator<<(ostream& os, const mint& a) { return os << a.x;}

ll f[MAX];
void init() {
    f[0] = 1;
    for (int i = 1; i < MAX; i++)
        f[i] = (f[i - 1] * i) % mod;
}
ll inv(ll x) {
    ll res = 1;
    ll k = mod - 2;
    ll y = x;
    while (k) {
        if (k & 1) res = (res * y) % mod;
        y = (y * y) % mod;
        k /= 2;
    }
    return res;
}
ll P(int n, int k) {
    if (n < 0 || n-k < 0)
        return 0;
    ll a = f[n];
    ll b = f[n-k];
    return a * inv(b) % mod;
}

int main() {
    init();
    int n, k;
    cin >> n >> k;
    vector<int> e[MAX];
    rep (i, n-1) {
        int a, b;
        cin >> a >> b;
        a--; b--;
        e[a].push_back(b);
        e[b].push_back(a);
    }
    
    mint ans = P(k, e[0].size()+1);
    vector<bool> done(n, false);
    queue<int> q;
    for (int v : e[0]) q.push(v);
    done[0] = true;
    while (!q.empty()) {
        int v = q.front();
        q.pop();
        ans *= P(k-2, e[v].size()-1);
        done[v] = true;
        for (int u : e[v]) if(!done[u]) q.push(u);
    }
    cout << ans << endl;
    
    return 0;
}


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

int  main()
{
	long n; cin >> n;
	vector <long> a(n);
	long mx = 0;
	rep(i, n)
	{
		cin >> a[i];
		mx = max(a[i], mx);
	}
	vector <long> b(mx + 1, 0);
	rep (i, n)
	{
		for (int j = a[i]; j <= mx; j += a[i])
		{
			b[j]++;
		}
	}
	long ans = 0;
	rep(i, n)
	{
		if (b[a[i]] <= 1)
			ans++;
	}
	cout << ans << endl;
	return (0);
}

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

int main(){
  int n;
  int cnt=0;
  cin >> n;
  for(int i=1; i<=n; i++){
    int t=i;
    for(int j=1; j<=5; j++){
      if (t==0) break;
      
      if (t/10==0 && j%2==1)
      {
        cnt++;
        break;
      }
      t /= 10;
    }
  }
  cout << cnt << endl;
  return 0;
}


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

int main() {
    string s;
    cin >> s;

    vector <pair <char, int>> ci;
    rep (i, s.size()) {
        if ((i == 0) || (i != 0 && s[i] != s[i - 1])) ci.emplace_back(s[i], 1);
        else ci.back().second ++;
    }

    int ans = 0;
    rep (i, (int)ci.size() - 2) {
        if (ci[i].first == 'J' && ci[i + 1].first == 'O' && ci[i + 2].first == 'I') {
            if (ci[i].second >= ci[i + 1].second && ci[i + 1].second <= ci[i + 2].second) {
                ans = max(ans, min({ci[i].second, ci[i + 1].second, ci[i + 2].second}));
            }
        }
    }
    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 12648
n, m, k = gets.split(' ').map(&:to_i)
flg = false
0.upto(n) do |nn|
  0.upto(m) do |mm|
    if nn * (m - mm) + (n - nn) * mm == k
	    puts 'Yes' 
     	flg = true
      break
    end
  end
  break if flg
end
puts 'No' unless flg

Measured memory_bytes: 1788
# coding: utf-8
import sys

sr = lambda: sys.stdin.readline().rstrip()
ir = lambda: int(sr())
lr = lambda: list(map(int, sr().split()))

# 上半分と下半分に分けて、１マスずつ塗っていく
A, B = lr()
X = [['#'] * 100 for _ in range(50)] + [['.'] * 100 for _ in range(50)]
A -= 1; B -= 1
h = 0; w = 0
while A:
    X[h][w] = '.'
    w += 2
    A -= 1
    if w >= 100:
        h += 2
        w = 0

h = 51; w = 0
while B:
    X[h][w] = '#'
    w += 2
    B -= 1
    if w >= 100:
        h += 2
        w = 0

X = [''.join(y) for y in X]
print(100, 100)
print('\n'.join(X))


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

using namespace std;


using Graph = vector<vector<int>>;

int N, M;
Graph G;

vector<bool> visit;

int depth = 0;
int ans = 0;


void dfs(int from, int to) {
    visit[to] = true;
    depth++;
    if (depth == N) ans++;
    //cout << "depth" << depth << endl;
    for (auto next : G[to]) {
        if (visit[next]) continue;
        if (next == from) continue;
        dfs(to, next);
    }
    visit[to] = false;
    depth--;
}


void solve() {
    cin >> N >> M;
    G.resize(N);
    for (int i = 0; i < M; i++) {
        int a, b; cin >> a >> b;
        a--; b--;
        G[a].push_back(b);
        G[b].push_back(a);
    }

    visit.resize(N);

    dfs(-1, 0);

    cout << ans << endl;
}


int main() {
    solve();
    return 0;
}

Measured memory_bytes: 256
//CatsandDogs.java
import java.util.Scanner;
class Main
{
	public static void main(String args[])
	{
		Scanner sc=new Scanner(System.in);
		int a=sc.nextInt();
        int b=sc.nextInt();
        int x=sc.nextInt();

        if(a>x||a+b<x){
            System.out.println("NO");
        }
        else{
            if(x-a<=b){
                System.out.println("YES");
            }
            else{
                System.out.println("NO");
            }
        }
        sc.close();
    }
}	

Measured memory_bytes: 21844
import Control.Monad

main = do
    n <- readLn
    xs <- replicateM n getLine
    if foldl (&&) True $ map ((>0) . foldl1 (\a b -> if (a-10) < 0 then 0 else max (a-10) b) . map read) [xs, reverse xs]
        then putStrLn "yes"
        else putStrLn "no"



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

using ll = long long;
const int MAX = 2e5;

// 最長増加部分列
int LIS(const vector<ll> &x) {
  vector<ll> y; // y[i]:長さi+1の増加部分列の最後の要素の最小値
  y.emplace_back(x[0]);
  for (int i = 1; i < x.size(); i++) {
    if (y.back() < x[i]) y.emplace_back(x[i]);
    else *lower_bound(y.begin(), y.end(), x[i]) = x[i];
  }
  return y.size();
}

// 隣接リストを用いた深さ優先探索（再帰ver.） O(|V|+|E|)
vector<int> color(MAX, 0);
vector<ll> ans(MAX, 0);
vector<ll> a(MAX);

void dfs(const vector<vector<int>> &G, int u, vector<ll> &y) {
  color[u] = 1; // GRAY
  ll keep1 = 0, keep2 = 0, keep3 = 0;
  if (y.size() == 0) y.emplace_back(a.at(u));
  else {
    if (y.back() < a.at(u)) {
      y.emplace_back(a.at(u));
      keep1 = 1;
    }
    else {
      keep1 = 2;
      keep2 = lower_bound(y.begin(), y.end(), a.at(u)) - y.begin();
      keep3 = *lower_bound(y.begin(), y.end(), a.at(u));
      *lower_bound(y.begin(), y.end(), a.at(u)) = a.at(u);
    }
  }
  ans.at(u) = y.size();
  
  for (int i = 0; i < G[u].size(); i++) {
    if (color[G[u][i]] == 0) dfs(G, G[u][i], y);
  }
  color[u] = 2; // BLACK
  if (keep1 == 1) y.pop_back();
  else if (keep1 == 2) {
    y.at(keep2) = keep3;
  }
  return;
}

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  
  // 無向(有向)グラフの隣接リスト
  int n; // n:頂点数
  cin >> n;
  
  a.resize(n);
  for (int i = 0; i < n; i++) cin >> a.at(i);
  
  vector<vector<int>> G(n); // G:頂点数nのグラフの隣接リスト
  
  for (int i = 0; i < n - 1; i++) {
    int u, v;
    cin >> u >> v;
    u--;
    v--;
    G[u].emplace_back(v);
    G[v].emplace_back(u); // 有向グラフではコメントアウト
  }
  
  vector<ll> y;
  dfs(G, 0, y);
  
  for (int i = 0; i < n; i++) cout << ans.at(i) << '\n';
}

Measured memory_bytes: 32388
import numpy as np

# x: T-x * 0.006
# 平均気温がA度に最も近い点を選ぶ
n = int(input())
t, a = map(int, input().split())
h = np.array(list(map(int, input().split())))
h2 = abs((t-h*0.006) - a)
res = np.where(h2==min(h2))[0][0] + 1

print(res)

Measured memory_bytes: 21368
import java.util.Arrays;
import java.util.Scanner;
public class Main {

	public static void main(String[] args) {

		Scanner sc = new Scanner(System.in);
		int[] a = new int[3];
		for(int i = 0; i<3; i++) {
			a[i] = sc.nextInt();
		}
		Arrays.sort(a);

		System.out.println(a[0] + " " + a[1] + " " + a[2]);


    }

}


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

#define inRange(x,a,b) (a <= x && x < b)
int di[8] = {0,0,1,-1,1,1,-1,-1};
int dj[8] = {1,-1,0,0,1,-1,1,-1};

int main(){
    int w, h;
    while(cin >> w >> h, w+h){
        char mat[h][w];
        for(int i = 0; i < h*w; i++)    cin >> mat[i/w][i%w];
        int ans = 0;
        for(int i = 0; i < h; i++){
            for(int j = 0; j < w; j++){
                if(mat[i][j] == '0')    continue;
                ans++;
                mat[i][j] = '0';
                queue<pair<int,int>> q;
                q.push({i,j});
                while(!q.empty()){
                    auto p = q.front(); q.pop();
                    int x = p.first, y = p.second;
                    for(int k = 0; k < 8; k++){
                        int nx = x+di[k], ny = y+dj[k];
                        if(inRange(nx,0,h)&&inRange(ny,0,w)&&mat[nx][ny]=='1'){
                            mat[nx][ny] = '0';
                            q.push({nx,ny});
                        }
                    }
                }
            }
        }
        cout << ans << endl;
    }
    return 0;
}


Measured memory_bytes: 3016
n,m = map(int, input().split())
ans = 0

md = m - 2*n
nd = n - m//2
## s型が無くなるまでsccを作った場合
if md >= 0:
    m = md
    ans = n + m//4
## c型が無くなるまでsccを作った場合
elif nd >= 0:
    ans = m//2

print(ans)


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

int main(){
    
    double x1,y1,x2,y2;
    double d1,d2,d;
    scanf("%lf%lf%lf%lf",&x1,&y1,&x2,&y2);
    
    d1=fabs(x1-x2);
    d2=fabs(y1-y2);
    
    d=sqrt(d1*d1+d2*d2);
    printf("%.8lf\n",d);
    return 0;
}



Measured memory_bytes: 2148
n = int(input())
hs = list(map(int, input().split()))

for i in range(n - 1):
    if hs[i] < hs[i + 1]:
        hs[i + 1] -= 1
    elif hs[i] == hs[i + 1]:
        continue
    else:
        print('No')
        break
else:
    print('Yes')


Measured memory_bytes: 63856
#include <bits/stdc++.h>
#include <vector>
#include <algorithm>
#include <deque>
#include <numeric>
#include <utility>
#define sign(a) ((a>0)-(a<0))
#define LL long long
#define INF (LL)(1LL<<60)

using namespace std;

void solve(long long N, long long K, std::vector<long long> x, std::vector<long long> y, std::vector<std::string> c) {
    vector<vector<LL>> tw(2 * K + 1, vector<LL>(2 * K + 1, 0)), tb(2 * K + 1, vector<LL>(2 * K + 1, 0));
    // initialize
    for (LL i = 0; i < N; i++) {
        if (c[i] == "W")
            tw[y[i] % (2 * K) + 1][x[i] % (2 * K) + 1]++;
        else
            tb[y[i] % (2 * K) + 1][x[i] % (2 * K) + 1]++;
    }
    // accumulate
    for (LL i = 0; i <= 2 * K; i++)
        for (LL j = 1; j <= 2 * K; j++) {
            tb[i][j] = tb[i][j] + tb[i][j - 1];
            tw[i][j] = tw[i][j] + tw[i][j - 1];
        }
    for (LL i = 1; i <= 2 * K; i++)
        for (LL j = 0; j <= 2 * K; j++) {
            tb[i][j] = tb[i][j] + tb[i - 1][j];
            tw[i][j] = tw[i][j] + tw[i - 1][j];
        }

    auto get_sum = [K](vector<vector<LL>> &tab, LL x1, LL y1, LL x2, LL y2){
        //if(x1>x2 || y1>y2)return 0LL;
        x1=max(x1, 1LL), y1=max(y1, 1LL);
        x2=min(x2, 2*K+1), y2=min(y2, 2*K+1);
        return tab[y2-1][x2-1]-tab[y2-1][x1-1]-tab[y1-1][x2-1]+tab[y1-1][x1-1];
    };
    LL ans=0;
    for(LL x1=1; x1<=K; x1++){
        for(LL y1=1; y1<=K; y1++){
            LL p1=0, p2=0;
            for(LL dx=0; dx<=2; dx++){
                for(LL dy=0; dy<=2; dy++){
                    if(((dx+dy)%2)==0){
                        p1 += get_sum(tb, x1+K*(dx-1), y1+K*(dy-1), x1+K*dx, y1+K*dy);
                        p2 += get_sum(tw, x1+K*(dx-1), y1+K*(dy-1), x1+K*dx, y1+K*dy);
                    }else{
                        p1 += get_sum(tw, x1+K*(dx-1), y1+K*(dy-1), x1+K*dx, y1+K*dy);
                        p2 += get_sum(tb, x1+K*(dx-1), y1+K*(dy-1), x1+K*dx, y1+K*dy);
                    }
                }
            }
            ans = max(ans, p1);
            ans = max(ans, p2);
        }
    }
    cout << ans << endl;
}

int main(){
    long long N;
    scanf("%lld",&N);
    long long K;
    scanf("%lld",&K);
    std::vector<long long> x(N);
    std::vector<long long> y(N);
    std::vector<std::string> c(N);
    for(int i = 0 ; i < N ; i++){
        scanf("%lld",&x[i]);
        scanf("%lld",&y[i]);
        std::cin >> c[i];
    }
    solve(N, K, std::move(x), std::move(y), std::move(c));
    return 0;
}


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

#define INF INT_MAX
#define UINF UINT_MAX
#define MOD 1000000007
#define REP(i,n) for(int i=0;i<n;i++)
#define all(x) (x).begin(),(x).end()

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

using namespace std;

int n;
vector<pair<double,double>> xy;

int main() {
    cin >> n;

    vector<int> index(n);

    REP(i,n){
        double x,y;
        cin >> x >> y;
        xy.push_back(make_pair(x,y));
        index[i] = i;
    }

    double ans = 0;
    double nn = 0;
    do{
        double sum = 0.0;
        // REP(i,n)cout << index[i] << " ";
        // cout << endl;
        for(int i = 0;i < index.size()-1;i++){
            sum += sqrt(pow(xy[index[i]].first - xy[index[i+1]].first,2) + pow(xy[index[i]].second - xy[index[i+1]].second,2));
        }
        nn = nn + 1.0;
        ans += sum;
    }while (next_permutation(index.begin(), index.end()));

    cout << fixed;
    cout << setprecision(8) << ans/nn << endl;

    return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<cstring>
#include <fstream>
#include<string>
#include<sstream>
#include<algorithm>
#include<bitset>
#include<vector>
#include<deque>
#include<queue>
#include<list>
#include<map>
#include<set>
#include<stack>
#include<cmath>
#include<iomanip>
#include <functional>
#include <math.h>
#include <assert.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
const long long int MOD = 1000000007;
const int INF = 1000000007;
const double EPS = 1e-10;
const double PI = 3.14159265359;
const int N = 100005;
//cout << fixed << std::setprecision(9)
//--------------------------

ll n, a;
ll cnt[4];
double dp[330][330][330];

int main()
{
	cin >> n;
	for (int i = 0; i < n; i++) {
		cin >> a;
		cnt[a]++;
	}
	for (int i = 0; i <= n; i++) {
		for (int j = 0; j <= n; j++) {
			for (int k = 0; k <= n; k++) {
				int nonzero = i + j + k;
				if (nonzero == 0) {
					dp[i][j][k] = 0;
					continue;
				}
				dp[i][j][k] = (double)n / nonzero;
				if (i - 1 >= 0) dp[i][j][k] += dp[i - 1][j + 1][k] * i / nonzero;
				if (j - 1 >= 0) dp[i][j][k] += dp[i][j - 1][k + 1] * j / nonzero;
				if (k - 1 >= 0) dp[i][j][k] += dp[i][j][k - 1] * k / nonzero;
			}
		}
	}
	printf("%.10lf\n", dp[cnt[3]][cnt[2]][cnt[1]]);
	return 0;
}

Measured memory_bytes: 258176
#include <iostream>
#include <iomanip>
#include <fstream>
#include <vector>
#include <algorithm>
#include <math.h>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <stack>
#include <bitset>

#define _GLIBCXX_DEBUG
#define rep(i, n) for (int64_t i = 0; i < (int64_t)(n); i++)
using namespace std;
using vi = vector<int64_t>;
using vvi = vector<vi>;

int main(int argc, const char * argv[]) {
    // fasten cin
    cin.tie(0);
    ios::sync_with_stdio(false);
    // implement
    int64_t a, b;
    cin >> a >> b;
    if(b%a == 0){
        cout << a + b << endl;
    }else{
        cout << b - a << endl;
    }
    
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define mk make_pair
#define fs first
#define sc second
using namespace std;
typedef long long ll;
typedef long double ld;

int main(){
  string s;
  while(cin>>s){
    bool l=0;
    for(int i=0; i+1<s.size(); ++i){
      if(s[i]=='A'&&s[i+1]=='C')
        l=1;
    }
    if(l)
      cout<<"Yes"<<endl;
    else{
      cout<<"No"<<endl;
    }
  }
  return 0;
}



Measured memory_bytes: 256
import std.stdio, std.algorithm, std.conv, std.array, std.string, std.math, std.typecons, std.numeric;

void main()
{
    auto abx = readln.split.to!(int[]);
    auto c = abx[2] - abx[0];
    writeln(c >= 0 && c <= abx[1] ? "YES" : "NO");   
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define ll long long
ll h[100009];
ll dp[100009];
int main() {
    int n;
    cin>>n;
    for(int i=1;i<=n;i++)cin>>h[i];
    dp[1]=0;dp[2]=abs(h[2]-h[1]);
    for(int i=3;i<=n;i++){
        dp[i]=min(dp[i-1]+abs(h[i]-h[i-1]),dp[i-2]+abs(h[i]-h[i-2]));
    }
    cout<<dp[n]<<endl;
    return 0;
}


Measured memory_bytes: 1792
#include<bits/stdc++.h>
#define rep(i,a,b) for(int i=int(a);i<int(b);++i)
using namespace std;
typedef long long ll;
int INF = (1LL << 30) - 1;
int MOD = 1e9+7;
main(){
    int N;
    cin >> N;
    vector<ll> A(N),B(N);
    rep(i,0,N)cin >> A[i] >> B[i];
    ll cnt = 0;
    for(int i = N-1;i >= 0;i--){
        if((A[i] + cnt) % (B[i])){
            cnt += B[i] - (A[i] + cnt) % B[i];
        }
    }
    cout << cnt << endl;
}

Measured memory_bytes: 1920
n, m=map(int, raw_input().split())
A=[]
b=[]

for i in range(n):
  A+=[map(int, raw_input().split())]
for j in range(m):
  b+=[input()]

for i in range(n):
  c=0
  for j in range(m):
    c+=A[i][j]*b[j]
  print c

Measured memory_bytes: 6544
#include <bits/stdc++.h>
#define REP(i, n) for (int i = 0; i < n; i++)
#define FOR(i, m, n) for (int i = m; i < n; i++)
#define ll long long int
const int INF = 2147483647;

using namespace std;

int main()
{
  int a, b;
  cin >> a >> b;
  int ans = 0;
  while (ans * a - ans + 1 < b)
    ans++;
  cout << ans << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i = 0; i < n; i++)
#define rep2(i, x, n) for(int i = x; i <= n; i++)
#define rep3(i, x, n) for(int i = x; i >= n; i--)
#define elif else if
#define sp setprecision
#define pb(x) push_back(x)
typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<ld, ld> pdd;
const ll MOD = 1e9+7;
const ll MOD2 = 998244353;
const int inf = INT_MAX;
const ll INF = LLONG_MAX;
const string alpha = "abcdefghijklmnopqrstuvwxyz";

struct unionfind_tree{
    int par[500000], rank[500000], num[500000];
    //要素数n(0〜n-1)の初期化されたUnion-Find木を構築
    unionfind_tree(int N){
        rep(i, N){par[i] = i, rank[i] = 0, num[i] = 1;}
    }
    //ノードxの根を取得
    int find(int x){
        if(par[x] == x) return x;
        else return find(par[x]);
    }
    //xとyの属する集合を併合
    void unite(int x, int y){
        x = find(x), y = find(y);
        if(x == y) return;
        elif(rank[x] < rank[y]){par[x] = y, num[y] += num[x];}
        else{
            par[y] = x, num[x] += num[y];
            if(rank[x] == rank[y]) rank[x]++;
        }
    }
    //xの属する集合の要素数を取得
    int size(int x){
        return num[find(x)];
    }
    //xとyが同じ集合に属するか判定
    bool same(int x, int y){
        return find(x) == find(y);
    }
};

int main(){
    int N, K, L;
    cin >> N >> K >> L;
    tuple<int, int, int> t[N];
    unionfind_tree uft1(N), uft2(N);
    rep(i, K){
        int u, v;
        cin >> u >> v;
        u--, v--;
        uft1.unite(u, v);
    }
    rep(i, L){
        int u, v;
        cin >> u >> v;
        u--, v--;
        uft2.unite(u, v);
    }
    rep(i, N){
        t[i] = make_tuple(uft1.find(i), uft2.find(i), i);
    }
    sort(t, t+N);
    int ans[N];
    int i = 0;
    while(i < N){
        int j = 0;
        while(i+j < N && get<0>(t[i]) == get<0>(t[i+j]) && get<1>(t[i]) == get<1>(t[i+j])){
            j++;
        }
        rep2(k, i, i+j-1){
            ans[get<2>(t[k])] = j;
        }
        i += j;
    }
    rep(i, N) cout << ans[i] << endl;
}

Measured memory_bytes: 13568
import java.math.BigInteger;
import java.util.*;

public class Main {

	/**
	 * @param args
	 */
	static Scanner sc = new Scanner(System.in);
	
	public static void main(String[] args) {
		int n = Integer.parseInt(sc.next());
		while(n-- > 0) {
			String a1, a2;
			if(sc.hasNext()) {
				a1 = sc.next();
			} else {
				break;
			}
			if(sc.hasNext()) {
				a2 = sc.next();
			} else {
				break;
			}
			BigInteger b1 = new BigInteger(a1), b2 = new BigInteger(a2);
			BigInteger sum = b1.add(b2);
			if(sum.toString().length() > 80) {
				System.out.println("overflow");
			} else {
				System.out.println(sum);
			}
		}
	}
}

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

typedef long long ll;
typedef pair<ll, ll> ii;

#define Canuc80k cin.tie(0); cout.tie(0);
#define FOR(i,a,b) for (ll i=a;i<=b;i++)
#define FORD(i,a,b) for (ll i=a;i>=b;i--)
#define I_AM ios_base::sync_with_stdio(0);
#define FORS(i,a,b,c) for (ll i=a;i<=b;i+=c)
#define FORSD(i,a,b,c) for (ll i=a;i>=b;i-=c)

const ll N = 5e3 + 1;
const ll M = 1e9 + 7;

ll n, m, sum = 0;
ll v[N], w[N], f[101][10001];

ll cal(ll pos, ll val) {
    if (pos == n + 1) {
        if (val == 0) return 0;
        return INT_MAX;
    }
    if (f[pos][val] != -1) return f[pos][val];

    ll temp = cal(pos + 1, val);
    if (val >= v[pos]) temp = min(temp, cal(pos + 1, val - v[pos]) + w[pos]);
    
    // cout << pos << " " << val << " " << temp << " " << endl;

    f[pos][val] = temp;
    return temp;
}

int main() {
    I_AM Canuc80k

    cin >> n >> m;
    FOR (i, 1, n) { 
        cin >> v[i] >> w[i];
        sum += v[i];
    }

    memset(f, -1 ,sizeof(f));

    ll res = 0;
    FORD (i, sum, 1) {
        ll temp = cal(1, i);
        // cout << i << " " << temp << endl;
        if (temp <= m) {
            res = i;
            break;
        }
    }
    cout << res << endl;
}


Measured memory_bytes: 11124
#include <bits/stdc++.h>
#include <chrono>
#include <random>
#include <sstream>
#include <string>
#define ll long long int
#define ull unsigned long long int
#define pb push_back
#define mp make_pair
#define mod 1000000007
#define rep(i,n) for(ll i=0;i<n;i++)
#define loop(i,a,b) for(ll i=a;i<=b;i++)
#define vi vector <int>
#define vs vector <string>
#define vc vector <char>
#define vl vector <ll>
#define all(c) (c).begin(),(c).end()
#define max3(a,b,c) max(max(a,b),c)
#define min3(a,b,c) min(min(a,b),c)
using namespace std;
ll power(ll a,ll b) {ll res=1;a%=mod; assert(b>=0); for(;b;b>>=1){if(b&1)res=res*a%mod;a=a*a%mod;}return res;}
ll modInverse(ll a){return power(a,mod-2);}
const int N=100001;
bool vis[N];
vector <int> adj[N];
ll gcd(ll a, ll b) { if (a == 0) return b; return gcd(b % a, a); } 
ll lcm(ll a, ll b){return a*b/gcd(a, b);}
// ll binaryNum[8];
// void decToBinary(ll n) 
// { 
//     // binaryNum[8];
//     rep(i,8){
//         binaryNum[i]=0;
//     }
//     int i = 0; 
//     while (n > 0) { 
//         binaryNum[i] = n % 2; 
//         n = n / 2; 
//         i++; 
//     } 
// } 
vl cnt;
vi prnt;
void dfs(ll u, ll parent){
    // vis[u]=true;
    ll a=0;
    if(adj[u].size()==1){
        // cout<<u<<' ';
        cnt[u]=1;
    }
    // cout<<u<<' ';
    for(int v:adj[u]){
        if(v!=parent){
            a++;
            prnt[v]=u;
            dfs(v, u);
            // cnt[u]+=cnt[v];
        }
    }
    if(u!=1){
        cnt[parent]+=cnt[u];
    }

}

void solve(){
    string s;
    cin>>s;
    ll n = s.length();
    ll sum=0;
    rep(i,n){
        sum += s[i]-'0';
    }
    if(sum%9==0)
        cout<<"Yes";
    else
        cout<<"No";
    



}


int main()
{
    // cout<<1<<endl;
    #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(NULL);
    int T=1;
    // cin>>T;
    int t=0;
    while(t++<T)
    {
        // cout<<"Case #"<<t<<":"<<' ';
        solve();
        //cout<<'\n';
    }
    cerr << "Time : " << 1000 * ((double)clock()) / (double)CLOCKS_PER_SEC << "ms\n";
}

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

using namespace std;

string s;
int n;
int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    
    cin >> n >> s;
    int cnt = 0;
    for(int i = 0; i <= n - 3;i ++){
        if(s.substr(i, 3) == "ABC"){
            cnt++;
        }
    }
    cout << cnt << '\n';
    return 0;
}

Measured memory_bytes: 256
<?php
$k = trim(fgets(STDIN));

$arr = explode(',', '1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51');
echo $arr[$k - 1];
?>


Measured memory_bytes: 4856
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <stack>
#include <queue>
#include <cmath>
#include <tuple>
#include <cstdio>
#include <bitset>
#include <sstream>
#include <iterator>
#include <numeric>
#include <map>
#include <cstring>
#include <set>
#include <functional>
#include <iomanip>

using namespace std;

//#define DEBUG_ //!!提出時にコメントアウト!!
#ifdef DEBUG_
	#define dump(x)  cerr << #x << " = " << (x) << endl;
#else
	#define dump(x)  ;
#endif

#define equals(a,b) (fabs((a)-(b)) < EPS)
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)
#define SZ(x) ((int)(x).size())
#define pb push_back
#define eb emplace_back

//#define int long long

typedef long long LL;
typedef vector<int> VI;
typedef vector<LL> VL;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef pair<LL, LL> PLL;

template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }

template <typename T>
std::string printVector(const std::vector<T> &data)
{
    std::stringstream ss;
    std::ostream_iterator<T> out_it(ss, ", ");
    ss << "[";
    std::copy(data.begin(), data.end() - 1, out_it);
    ss << data.back() << "]";
    return ss.str();
}

template <typename T>
void print_array(const T &ary, int size){
    REP(i,size){
        cout << ary[i] << " ";
    }
    cout << endl;
}

const int MOD = 1e9+7;
const LL LINF = 1001002003004005006ll;
const int INF = 1001001001;
const double EPS = (1e-10);

signed main(int argc, char const *argv[])
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout << setprecision(12);

    int N; cin >> N;
    map<int,int> mp;
    REP(i,N){
        int a; cin >> a;
        mp[a]++;
    }
    VI H;
    for(auto p : mp){
        H.eb(p.second);
    }
    int len = SZ(H);
    sort(H.begin(),H.end());
    VL aH(len+1);
    REP(i,len){
        aH[i+1] = aH[i] + H[i];
    }
    //for(auto i : aH){
    //    cout << i << " ";
    //}
    //cout << endl;

    FOR(i,1,N+1){
        LL ok = 0;
        LL ng = 1e6;
        while(abs(ok-ng) > 1){
            LL mid = (ok+ng) / 2;
            dump(mid)
            LL sum = 0;
            auto it = lower_bound(H.begin(),H.end(),mid);
            sum += mid * (H.end() - it);
            int index = it - H.begin();
            dump(sum)
            sum += aH[index];

            dump(sum)
            if(sum >= i*mid){
                ok = mid;
            }else{
                ng = mid;
            }
        }
        cout << ok << endl;
    }

}


Measured memory_bytes: 17904
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <stack>
#include <queue>
#include <set>
#include <cmath>
#include <map>
#include <fstream>
#include <iterator>
using namespace std;

// Debug Vector
template <typename T>
std::ostream &operator<<(std::ostream &out, const std::vector<T> &v)
{
    if (!v.empty())
    {
        out << '[';
        std::copy(v.begin(), v.end(), std::ostream_iterator<T>(out, ", "));
        out << "\b\b]";
    }
    return out;
}

template <typename T1, typename T2>
std::ostream &operator<<(std::ostream &out, const std::pair<T1, T2> &p)
{
    out << "[" << p.first << ", " << p.second << "]";
    return out;
}

typedef long long ll;

int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n;
    cin >> n;
    vector<int> l(n);

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

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

    int sum = 0;
    for (int i = 0; i < n - 1; i++)
    {
        sum += l[i];
    }

    if (sum > l[n - 1])
    {
        cout << "Yes" << endl;
    }
    else
    {
        cout << "No" << 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;

int main() {
    int A,B; cin >> A >> B;
    bool can = false;
    if(A%3 == 0)can = true;
    else if(B%3 == 0)can = true;
    else if((A+B)%3 == 0)can = true;
    else cout << "Impossible" << endl;
    if(can) cout << "Possible" << endl;
    return 0;
}

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

using namespace std;

int limit = 50;

int n, m;

vector<int> a(limit,0), b(limit,0);

vector<vector<bool>> G(50,vector<bool> (50,false));
vector<bool> visit(50,false);

//dfsで訪問検査
//無向グラフ隣接行列
//bool G[limit][limit];
//2次元のbool行列を作り、a,bが繋がっている場合
//G[a][b] = true,G[b][a] = true;
void dfs(int v){
  visit[v] = true;
  for(int v2; v2 < n; v2++){
    if(G[v][v2] == false) continue;
    if(visit[v2]) continue;
    dfs(v2);
  }
}

int main(void){
  cin >> n >> m;
  
  //グラフ生成
  for(int i = 0; i < m; i++){
    cin >> a[i] >> b[i];
    a[i]--,b[i]--;
    G[a[i]][b[i]] = G[b[i]][a[i]] = true; 
  }
  
  int  ans = 0;
  for(int i = 0; i < m; i++){
    //隣接を一つ外す;
    G[a[i]][b[i]] = G[b[i]][a[i]] = false;
    
    //visitを初期化
    for(int j = 0; j < n; j++) visit[j] = false;
    
    dfs(0);
    
    bool bridge = false;
    for(int j = 0; j < n; j++) if(visit[j] == false) bridge = true;
    if(bridge) ans++;
    
    //隣接をもとに戻す
    G[a[i]][b[i]] = G[b[i]][a[i]] = true;
  
  }
  cout << ans;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define REP(i, n) for(int i=0, i##_len=(n); i<i##_len; ++i)
typedef long long ll;
#define pb push_back
#define fi first
#define se second
#define ALL(x) (x).begin(),(x).end()
#define RALL(x) (x).rbegin(),(x).rend()
template <class T, class U> ostream &operator<<(ostream &os, const pair<T, U> &p){os<<"("<<p.first<<","<< p.second<<")";return os;}
template <class T> ostream &operator<<(ostream &os, const vector<T> &v){os<<"{";REP(i,(int)v.size()){if(i)os<<",";os<<v[i];}os<<"}";return os;}
template <typename T, size_t S> void printArray(const T (&array)[S]){for(auto val : array)std::cout << val << ", ";std::cout << "\n";}
void Yes() {cout << "Yes" << endl;}
void No() {cout << "No" << endl;}
void YES() {cout << "YES" << endl;}
void NO() {cout << "NO" << endl;}
const double PI=acos(-1);
const ll MOD = 1000000007;
using Graph = vector<vector<int>>;
//const int dx[4] = {1, 0, -1, 0};
//const int dy[4] = {0, 1, 0, -1};
//const int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1};
//const int dy[8] = {0, 1, 0, -1, 1, 1, -1, -1};

void solve(){
    ll x;
    cin >> x;
    if(1 <= x && x <= 6) cout << 1 << endl;
    else if(7 <= x && x <= 11) cout << 2 << endl;
    else{
        ll num11 = x/11;
        ll resid11 = x%11;
        if(1 <= resid11 && resid11 <= 6) cout << 2*num11 + 1 << endl;
        else if(7 <= resid11 && resid11 <= 10) cout << 2*num11 + 2 << endl;
        else cout << 2*num11 << endl;
    }
}

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

Measured memory_bytes: 256
from statistics import mean, median,variance,stdev
import numpy as np
import sys
import math
import fractions
import itertools
import copy
from operator import itemgetter
#以下てんぷら
def j(q):
    if q==1: print("Yes")
    else:print("No")
    exit(0)


def ct(x,y):
    if (x>y):print("+")
    elif (x<y): print("-")
    else: print("?")

def ip():
    return int(input())
#n = ip()                                     #入力整数1つ
x,y,z= (int(i) for i in input().split())       #入力整数横2つ以上
#a = [int(i) for i in input().split()]        #入力整数配列
#a = input()                                  #入力文字列
#a = input().split()                          #入力文字配列
#n = ip()                      #入力セット(整数改行あり)(1/2)
#a=[input() for i in range(x)]    #入力セット(整数改行あり)(2/2)

#jの変数はしようできないので注意
#全足しにsum変数使用はsum関数使用できないので注意
#こっから本文
low = (x//z)*z
if low < x: low+=z
high = (y//z)*z
print((high - low)//z+1)

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

using namespace std;
using ll = long long;

#define rep(i, a) for (int (i) = 0; (i) < (int) (a); (i)++)
#define reps(i, a, b) for (int (i) = (int) (a); (i) < (int) (b); (i)++)
#define rrep(i, a) for (int (i) = (int) a-1; (i) >= 0; (i)--)
#define rreps(i, a, b) for (int (i) = (int) (a)-1; (i) >= (int) (b); (i)--)
#define MP(a, b) make_pair((a), (b))
#define PB(a) push_back((a))
#define all(v) (v).begin(), (v).end()
#define PRINT(f) if((f)){cout << (TRUE__) << endl;}else{cout << FALSE__ << endl;}
#define TRUE__ "Yes"
#define FALSE__ "No"
#define PERM(v) next_permutation(all(v))
#define UNIQUE(v) sort(all(v));(v).erase(unique(all(v)), v.end())
#define CIN(type, x) type x;cin >> x

#ifdef LOCAL
	#define lcout(a) cout << a;
	#define lcoutln(a) cout << a << endl;
	#define lcerr(a) cerr << a;
	#define lcerrln(a) cerr << a << endl;
#else
	#define lcout(a) 
	#define lcoutln(a) 
	#define lcerr(a) 
	#define lcerrln(a) 
#endif

int main()
{
	CIN(string, s);
	cout << s[0] << s.length()-2 << s[s.length()-1] << endl;
}


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

#define li long long int
#define rep(i, to) for (li i = 0; i < ((li)(to)); i++)
#define repp(i, start, to) for (li i = (li)(start); i < ((li)(to)); i++)

int main(void)
{
	string a, b;
	cin >> a >> b;
	if (a == "H") {
		cout << (b == "H" ? "H" : "D") << endl;
	} else {
		cout << (b == "H" ? "D" : "H") << endl;
	}

	return 0;
}

Measured memory_bytes: 3624
import java.util.Scanner;

public class Main {
    Scanner sc = new Scanner(System.in);

    public static void main(String[] arg){
        Main m = new Main();
        m.run();
    }

    void run(){
        String s = sc.next();
        int q = sc.nextInt();

        int direction = 1;

        StringBuilder sbf = new StringBuilder();
        StringBuilder sbb = new StringBuilder();

        for(int i = 0; i< q; i ++){
            int t = sc.nextInt();

            if(t == 1){
                direction = 3 - direction;
            }else{
                int f = sc.nextInt();
                String c = sc.next();

                if(direction != f ){
                    sbf.append(c);
                }else{
                    sbb.append(c);
                }
            }
        }

        sbb.reverse().append(s).append(sbf.toString());

        if(direction == 2){
            sbb.reverse();
        }

        System.out.println(sbb.toString());
    }
}


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

using namespace std;

int main() {

    cin.tie(0);
    ios::sync_with_stdio(false);

    int f[4] = {0};

    for(int i = 0; i < 6; i++) {
        int a;
        cin >> a;
        f[a - 1]++;
    }

    int ans = 1;
    for(int i = 0; i < 4; i++) {
        if(f[i] > 2) {
            ans = 0;
            break;
        }
    }

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

    return 0;

}

Measured memory_bytes: 256