akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <string>

using namespace std;

int main() {
	string s;
	cin >> s;
	int n = s.length();
	
	for (int i = 0; i < n; i++) {
		if (s[i] != s[n - 1 - i]) {
			cout << "No\n";
			return 0;
		}
	}
	
	for (int i = 0; i < (n - 1) / 2; i++) {
		if (s[i] != s[(n - 1) / 2 - 1 - i]) {
			cout << "No\n";
			return 0;
		}
	}
	
	for (int i = (n + 3) / 2 - 1; i < n; i++) {
		if (s[i] != s[n - 1 - i]) {
			cout << "No\n";
			return 0;
		}
	}
	
	cout << "Yes\n";
	return 0;
}

Measured memory_bytes: 256
n = int(input())
A = list(map(int,input().split()))


for i in range(n):
    if A[i]==0:
        print(0)
        exit()


ans = 1
for i in range(n):
    ans *= A[i]
    if ans > 1e18:
        print(-1)
        exit()

print(ans)

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

void input() {
    cin >> S;
}
string solve() {
    int i1 = atoi(S.substr(0,2).c_str());
    int i2 = atoi(S.substr(2,2).c_str());
    if(0 < i1 && i1 < 13) {
        if(0 < i2 && i2 < 13) {
            return "AMBIGUOUS";
        }
        else {
            return "MMYY";
        }
    }
    if(0 < i2 && i2 < 13) {
        return "YYMM";
    }
    return "NA";
}
int main() {
    input();
    cout << solve() << endl;
}

Measured memory_bytes: 256
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cctype>
#include <chrono>
#define _USE_MATH_DEFINES
#include <cmath>
#include <cstring>
#include <ctime>
#include <deque>
#include <functional>
#include <iostream>
#include <iomanip>
#include <iterator>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <tuple>
#include <utility>
#include <vector>
using namespace std;

#define FOR(i,m,n) for(int i=(m);i<(n);++i)
#define REP(i,n) FOR(i,0,n)
#define ALL(v) (v).begin(),(v).end()

const int INF = 0x3f3f3f3f;
const long long LINF = 0x3f3f3f3f3f3f3f3fLL;
const double EPS = 1e-8;
const int MOD = 1000000007; // 998244353;
const int dy[] = {1, 0, -1, 0}, dx[] = {0, -1, 0, 1};

struct IOSetup {
  IOSetup() {
    cin.tie(nullptr);
    ios_base::sync_with_stdio(false);
    cout << fixed << setprecision(20);
    cerr << fixed << setprecision(10);
  }
} iosetup;
/*-------------------------------------------------*/
int main() {
  const int N = 50;
  vector<long long> a(N);
  REP(i, N) a[i] = N - i - 1;
  long long k; cin >> k;
  long long matomete = k / N;
  REP(i, N) a[i] += matomete;
  k -= matomete * N;
  for (int i = N - 1; i >= 0; --i) {
    if (k > 0) {
      --k;
      a[i] += N;
      REP(j, i) --a[j];
      FOR(j, i + 1, N) --a[j];
    }
  }
  cout << N << '\n';
  REP(i, N) cout << a[i] << (i + 1 == N ? '\n' : ' ');
  return 0;
}


Measured memory_bytes: 384
N, K = [int(x) for x in input().split()] 
h = [int(x) for x in input().split()]

def chmin(a, b):
    return a if a <= b else b

dp = [float('inf')] * N
dp[0] = 0
for i in range(N):
    for j in range(1, K+1):
        if i + j >= len(dp):
            break
        else:
            dp[i+j] = chmin(dp[i+j], dp[i] + abs(h[i] - h[i+j]))
        
print(dp[-1])

Measured memory_bytes: 55264
#include <iostream>
#include <iomanip>
typedef long long ll;
using namespace std;
const ll INF = 1e18;
const ll MOD = 1e9 + 7;
#define repi(i, n, init) for (ll i = init; i < (n); i++)

int main()
{
    int a, b;
    cin >> a >> b;
    if (a <= 5)
    {
        cout << 0 << endl;
    }
    else if (a <= 12)
    {
        cout << b / 2 << endl;
    }
    else
    {
        cout << b << endl;
    }
    return 0;
}

Measured memory_bytes: 256
// F - Strivore
#include <bits/stdc++.h>
using namespace std;
using ll = long long;

#define MOD 1000000007
#define MAX 2000001// [n+1] 1_origin
ll fac[MAX]; // 階乗 n!
ll inv[MAX]; // 逆元 1/n
ll finv[MAX]; // 逆元の階乗 (n^-1)! = (1/n)!

// n 個の配列に、mod p で前処理する
void init(int n, int p){
	fac[0] = fac[1] = 1;
	finv[0] = finv[1] = 1;
	inv[1] = 1;
	for(int i=2; i<=n; ++i){
		fac[i] = fac[i-1] * i % p;
		inv[i] = p - inv[p%i] * (p/i) % p;
		finv[i] = finv[i-1] * inv[i] % p;
	}
}

// nCr(mod m)
ll nCr(int n, int r, int m){
	if(n<r || n<0 || r<0) return 0;
	return fac[n] * (finv[n-r] * finv[r] % m) % m;
}

// a^n mod m
ll modpow(ll a, ll n, ll m) {
	ll x = 1;
	while(n > 0){
		if(n & 1) x = x * a % m;
		a = a * a % m;
		n >>= 1;
	}
	return x;
}

int main(){
	int K; string S; cin>>K>>S;
	init(K + S.size(), MOD);
	ll ans = 0;
	for(int i=0; i<=K; ++i){
		ll a = modpow(25, i, MOD) * modpow(26, K-i, MOD) % MOD;
		a *= nCr(i+S.size()-1, S.size()-1, MOD);
		ans += a % MOD;
		ans %= MOD;
	}
	cout<< ans <<endl;
}


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

int main()
{
  int A,B;
  cin >> A >> B;
  if((A+B)%2==0)
  {
    cout << (A+B)/2 << endl;
  }
  else
  {
    cout << "IMPOSSIBLE" << endl;
  }
}

Measured memory_bytes: 256
from itertools import accumulate
import bisect
n, m, k = map(int, input().split())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
i = 0
j = 0
total = 0

ac = list(accumulate(a))
bc = list(accumulate(b))

ans = 0
for i in range(bisect.bisect(ac, k)):
    bi = bisect.bisect(bc, k - ac[i])
    ans = max(ans, i+1+bi)
for i in range(bisect.bisect(bc, k)):
    bi = bisect.bisect(ac, k - bc[i])
    ans = max(ans, i+1+bi)
ans = max(ans, bisect.bisect(ac, k))
ans = max(ans, bisect.bisect(bc, k))
print(ans)

Measured memory_bytes: 48796
/*
    Problem 67
    https://atcoder.jp/contests/abc065/tasks/arc076_b
*/
#include <bits/stdc++.h>
using namespace std;
/* typedef */
typedef long long ll;
typedef pair<int, int> pii;
/* class */
class DisjontSet {
    public:
    vector<int> d;
    DisjontSet (int size) : d(size, -1) {}
    int find(int x) {
        if (d[x] < 0) return x;
        return d[x] = find(d[x]);
    }
    bool unite(int x, int y) {
        x = find(x), y = find(y);
        if (x == y) return false;
        if (d[x] > d[y]) swap(x, y);
        d[x] += d[y];
        d[y] = x;
        return true;
    }
};
class Edge {
    public:
    int from, to, cost;
    Edge (int from, int to, int cost) :
    from(from), to(to), cost(cost) {}
    bool operator < (const Edge &e) const {
        return cost < e.cost;
    }
};
class Point {
    public:
    int x, y, ind;
    Point (int x, int y, int ind) : x(x), y(y), ind(ind) {}
    bool operator < (const Point &p) const {
        return x < p.x;
    }
};
/* constant */
const int INF = 1 << 30;
const int NIL = -1;
const int MAX = 10000;
const int mod = 1000000007;
const double pi = 3.141592653589;
/* global variables */
/* function */
/* main */
int main(){
    int N, x, y;
    cin >> N;
    vector<Point> p1, p2;
    for (int i = 0; i < N; i++) {
        scanf("%d %d", &x, &y);
        p1.push_back(Point(x, y, i));
        p2.push_back(Point(y, x, i));
    }
    sort(p1.begin(), p1.end());
    sort(p2.begin(), p2.end());

    vector<Edge> edges;
    for (int i = 0; i < N - 1; i++) {
        int diff1 = abs(p1[i].x - p1[i + 1].x);
        int diff2 = abs(p2[i].x - p2[i + 1].x);
        edges.push_back(Edge(p1[i].ind, p1[i + 1].ind, diff1));
        edges.push_back(Edge(p2[i].ind, p2[i + 1].ind, diff2));
    }

    sort(edges.begin(), edges.end());
    DisjontSet dset = DisjontSet(N + 1);
    int totalCost = 0;
    for (Edge e : edges) {
        if (dset.unite(e.from, e.to)) totalCost += e.cost;
    }
    cout << totalCost << '\n';
}

Measured memory_bytes: 7212
#include <algorithm>
#include <bitset>
#include <climits>
#include <cmath>
#include <cstdio>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <vector>
using namespace std;
using ll = long long;
typedef pair<ll, ll> pll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<vector<ll>> vvl;
#define REP(var, a, b) for (int var = (a); var < (b); var++)
#define rep(var, n) for (int var = 0; var < (n); ++var)
#define ALL(c) (c).begin(), (c).end()
#define rALL(c) (c).rbegin(), (c).rend()
ll MOD = 1000000007;
const ll INF = 1LL << 60;

struct mint {
  ll x;
  mint(ll x = 0) : x(x % MOD) {}
  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 {
    mint res(*this);
    return res += a;
  }
  mint operator-(const mint a) const {
    mint res(*this);
    return res -= a;
  }
  mint operator*(const mint a) const {
    mint res(*this);
    return res *= a;
  }
  mint pow(ll t) const {
    if (!t) return 1;
    mint a = pow(t >> 1);
    a *= a;
    if (t & 1) a *= *this;
    return a;
  }

  // for prime MOD
  mint inv() const { return pow(MOD - 2); }
  mint& operator/=(const mint a) { return (*this) *= a.inv(); }
  mint operator/(const mint a) const {
    mint res(*this);
    return res /= a;
  }
};

int main() {
  //
  ll n;
  cin >> n;
  vl a(n);
  rep(i, n) cin >> a[i];
  vvl s(61, vl(n, 0));
  mint ans(0);
  rep(k, 61) {
    rep(i, n) {
      if ((a[i] >> k) & 1) {
        s[k][i] = 1;
      }
      if (i > 0) {
        s[k][i] += s[k][i - 1];
      }
    }
    // cerr << k << ":" << s[k][n - 1] << endl;
    rep(i, n - 1) {
      ll cnt = s[k][n - 1] - s[k][i];
      mint tmp(1LL << k);
      if ((a[i] >> k) & 1) {
        // zero
        tmp *= (n - 1 - i - cnt);
      } else {
        tmp *= cnt;
      }
      // cout << k << "," << a[i] << "," << tmp << endl;
      ans += tmp;
    }
  }
  cout << ans.x << endl;
  return 0;
}


Measured memory_bytes: 147968
#include<iostream>
#include<stdio.h>

int N, A, B;

int main(){
    int a, b, c, d, e;
    int sum;
    scanf("%d %d %d", &N, &A, &B);

    sum = 0;
    for(int n = 1; n <= N; n++){
        a = n/10000%10;
        b = n/1000%10;
        c = n/100%10;
        d = n/10%10;
        e = n%10;

        if(a+b+c+d+e >= A && a+b+c+d+e <= B) sum += n;
    }
    std::cout << sum;

    return 0;
}

Measured memory_bytes: 256
def editorial():
    h, w, k = map(int, input().split())
    mat = []
    for r in range(h):
        mat.append(list(input()))
    
    ans = 0
    for rowmask in range(0, 1<<h):
        for colmask in range(0, 1<<w):
            count = 0
            for r in range(h):
                for c in range(w):
                    if (rowmask>>r)&1 == 0 and (colmask>>c)&1 == 0 and mat[r][c] == '#': count += 1
            if count == k: ans += 1
    print(ans)

editorial()


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

int main()
{
	string s, t;
	cin >> s >> t;
	s += s;
	bool ans = false;
	for(auto i = 0; i < (int)t.size(); ++i){
		if(t == s.substr(i, t.size())){
			ans = true;
			break;
		}
	}
	cout << (ans ? "Yes" : "No") << endl;
	return 0;
}

Measured memory_bytes: 256
package main

import (
	"fmt"
)

func main() {
	var t string
	fmt.Scan(&t)
	
	ans := ""
	for i := 0; i < len(t); i++ {
		if t[i] == '?' {
			ans += "D"
		} else {
			ans += string(t[i])
		}
	}
	fmt.Println(ans)
}

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

long long modinv(long long a, long long m) {
    long long b = m, u = 1, v = 0;
    while (b) {
        long long t = a / b;
        a -= t * b; swap(a, b);
        u -= t * v; swap(u, v);
    }
    u %= m; 
    if (u < 0) u += m;
    return u;
}

long long modpow(long long a, long long n, long long mod) {
    long long res = 1;
    while (n > 0) {
        if (n & 1) res = res * a % mod;
        a = a * a % mod;
        n >>= 1;
    }
    return res;
}
 
int main() {
  long long n,a,b;
  cin >> n >> a >> b;
  long long ans;
  ans = modpow(2,n,1000000007);
  ans--;
  long long aa=1;
  long long bb=1;
  for(int i = 0;i < a;i++){
    aa *= (n-i);
    aa %= 1000000007;
    aa *= modinv(i+1,1000000007);
      aa %= 1000000007;
  }
   for(int i = 0;i < b;i++){
    bb *= (n-i);
    bb %= 1000000007;
    bb *= modinv(i+1,1000000007);
      bb %= 1000000007;
  }
  ans -= aa+bb;
  ans += 3000000021;
  ans %= 1000000007;
  cout << ans << endl;}

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

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

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

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

    cout << vec[N-1] - vec[0]<< endl;
}

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

int main() {
  int k,n; cin >> k >> n;
  
  vector<int> houses(n);
  for(int i = 0; i < n; i++) {
    cin >> houses.at(i);
  }
  
  int longest = 0;
  for(int i = 1; i <= n; i++) {
   int distance;
   if(i == n) {
     distance = k - houses.at(i-1) + houses.at(0);
   } else {
     distance = houses.at(i) - houses.at(i-1);
   }
    if(longest < distance) {
      longest = distance;
    }
  }
 
  cout << k - longest << endl;
  
  return 0; 
}

Measured memory_bytes: 4056
import java.util.Scanner;

public class Main {

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

        String a = scan.next();
        String b = scan.next();
        String c = scan.next();


        if (a.charAt(a.length() - 1) == b.charAt(0) &&
            b.charAt(b.length() - 1) == c.charAt(0)) {
                System.out.println("YES");
        } else {
            System.out.println("NO");
        }
    }
}

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

int main() {
	int n,W;cin>>n>>W;
	int v[100],w[100];
	for(int i=0;i<n;i++)cin>>v[i]>>w[i];
	int dp[W+1]={};
	for(int i=0;i<n;i++)
	{
		for(int j=w[i];j<=W;j++)
		{
			dp[j]=max(dp[j],dp[j-w[i]]+v[i]);
		}
	}
	cout<<dp[W]<<endl;
	return 0;
}

Measured memory_bytes: 3084
//#include <bits/stdc++.h>
#include<cstdio>
#include<iostream>
#define ll long long
#define pi pair<int, int>
#define pb push_back
#define mod 1000000007
using namespace std;

ll ans;

ll fun(string &s, ll pos){
    if(pos >= s.length()){
        return -1;
    }
    if(pos == s.length() - 1){
        ans += 1;
        if(s[pos] == '<'){
            return 0;
        }
        else{
            return 1;
        }
    }
    if(s[pos] == '>'){
        ll cur = fun(s, pos + 1) + 1;
        ans += cur;
        return cur;
    }
    ll i = pos;
    while(i < s.length() && s[i] == '<'){
        ans += i - pos;
        i++;
    }
    if(i != s.length()){
        ll cur = fun(s, i);
        ans += max(0ll, i - pos - cur);
    }
    else{
        ans += i - pos;
    }
    // cout<<pos<<" "<<ans<<endl;
    return 0;
}

int main() {
    // ios::sync_with_stdio(false);
    // cin.tie(0);
    string s;
    cin>>s;
    fun(s, 0);
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 24324
#include <iostream>
#include <string>
#include <algorithm>
#include <cmath>


using namespace std;


int main() {
	int N,K;
	cin>>N>>K;

	int ans=K;
	for(int i=2;i<=N;++i){
		ans*=(K-1);
	}

	cout<<ans;
	return 0;
}


Measured memory_bytes: 256
using System;

namespace ALDS1_1_A
{
	class Program
	{
		static void Main(string[] args)
		{
			int n = int.Parse(Console.ReadLine());

			int[] a = new int[n];
			string[] vs = Console.ReadLine().Split(' ');

			for(int i = 0; i < n; i++) {
				a[i] = int.Parse(vs[i]);
			}

			for(int i = 1; i < n; i++) {
				Output(a, n);

				int v = a[i];
				int j = i - 1;
				while(j >= 0 && a[j] > v) {
					a[j + 1] = a[j];
					j--;
				}
				a[j + 1] = v;
			}

			Output(a, n);
		}

		static void Output(int[] vs, int n)
		{
			string text = string.Empty;

			for(int i = 0; i < n; i++) {
				text += i == 0 ? $"{vs[i]}" : $" {vs[i]}";
			}

			Console.WriteLine(text);
		}
	}
}



Measured memory_bytes: 19996
import itertools
N, M = [int(n) for n in input().split()]
path = [[False for i in range(N)]for j in range(N)]


for i in range(M):
    a, b = [int(n)-1 for n in input().split()]
    path[a][b] = True
    path[b][a] = True


res = 0
for way in itertools.permutations(range(1,N), N-1):
    exist = True
    if path[0][way[0]] == False:
        exist = False
    for n in range(N-2):
        if path[way[n]][way[n+1]] == False:
            exist = False
    if exist == True:
        res += 1

print(res)


Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
int main()
{
 	int n,a,b;
 	cin>>n;
 	if(n==1) cout<<"Hello World";
 	if(n==2) 
 	{	
 		cin>>a>>b;
 		cout<<a+b;
    }
	 
	return 0;
}



Measured memory_bytes: 256
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.Scanner;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 *
 * @author Akash
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        Scanner in = new Scanner(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        BStringPalindrome solver = new BStringPalindrome();
        solver.solve(1, in, out);
        out.close();
    }

    static class BStringPalindrome {
        public void solve(int testNumber, Scanner in, PrintWriter out) {
            String s = in.nextLine();
            int n = s.length();
            boolean result = isPalindrome(s) && isPalindrome(s.substring(0, (n - 1) / 2)) && isPalindrome(s.substring((n + 2) / 2));
            out.println(result ? "Yes" : "No");
        }

        boolean isPalindrome(String s) {
            StringBuilder a = new StringBuilder(s);
            a = a.reverse();
            return a.toString().compareTo(s) == 0;
        }

    }
}



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

int main(void)
{
    int i,n;
        double x,mean,poi[1010]={0};
    
    while(scanf("%d",&n)==1 && n!=0){
        x=0;
        for(i=0;i<n;i++){
            scanf("%lf",&poi[i]);
            x+=poi[i];
        }
        mean=x/n;
        x=0;
        
        for(i=0;i<n;i++){
            x+=pow(poi[i]-mean,2);
        }
        
        mean=sqrt(x/n);
        printf("%f\n",mean);
    }
    return 0;
}


Measured memory_bytes: 2132
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define llu unsigned long long
#define ld double
#define llu unsigned long long
#define rep(i,x,y)  for(ll i=x;i<y;++i)
#define For(i,x,y)  for(ll i=x;i<=y;++i)
#define FOr(i,x,y)  for(ll i=x;i>=y;--i)
#define pi acos(-1)
#define mk make_pair<ll,ll>
#define pa pair<ll,ll>
#define lf else if
#define max(x,y)    ((x)<(y)?(y):(x))
#define min(x,y)    ((x)<(y)?(x):(y))
#define sqr(x)      ((x)*(x))
#define abs(x)      ((x)>0?(x):-(x))
#define Mul(x,y)    ((x)=1LL*(x)*(y)%mod)
#define Add(x,y)    ((x)=((x)+(y))%mod)
#define Max(x,y)    ((x)=((x)<(y)?(y):(x)))
#define Min(x,y)    ((x)=((x)>(y)?(y):(x)))
#define E(x)        return writeln(x),0
#define p(x)        printf("~%lld~\n",(long long)x)
#define pp(x,y)     printf("~~%lld %lld~~\n",(long long)x,(long long)y)
#define ppp(x,y,z)  printf("~~~%lld %lld %lld~~~\n",(long long)x,(long long)y,(long long)z)
#define pppp(a,b,c,d)	printf("~~~%lld %lld %lld %lld\n",(long long)a,(long long)b,(long long)c,(long long)d)
#define f_in(x)     freopen(x".in","r",stdin)
#define f_out(x)    freopen(x".out","w",stdout)
#define open(x)     f_in(x),f_out(x)
#define GuYue		puts("\nGuYueNa________________________________________________________________________________")
typedef complex<double> E;
namespace SHENZHEBEI{
#ifdef LOCAL
    struct _{_(){freopen("cf.in","r",stdin);}}_;
#endif
#define NEG 1
#if NEG
    inline ll read(){    ll x=0,fa=1; char ch=getchar();   for (;!isdigit(ch);ch=getchar()) if (ch=='-') fa=-1;  for (;isdigit(ch);ch=getchar())  x=x*10-48+ch;   return x*fa; }
    inline void write(ll x){    if (x<0) putchar('-'),x=-x;  if (x>=10)   write(x/10);    putchar(x%10+'0');  }
#else
    inline ll read(){    ll x=0; char ch=getchar();   for (;!isdigit(ch);ch=getchar());    for (;isdigit(ch);ch=getchar())  x=x*10-48+ch;   return x;   }
    inline void write(ll x){    if (x>=10)   write(x/10);    putchar(x%10+'0');  }
#endif
	void writeln(ll x){write(x);puts("");}
	void Print(long long *a,int s,int t){For(i,s,t)printf("%lld ",a[i]);}
	void Print(int *a,int s,int t){For(i,s,t)printf("%d ",a[i]);}
	void Print(char *a,int s,int t){For(i,s,t)putchar(a[i]);}
}using namespace SHENZHEBEI;
ll n,x,y,sum,ans,frog;
const ll N=200010;
int main(){
	n=read(),sum=1e16,frog=0;
	For(i,1,n){
		ll x=read(),y=read();
		if (x^y)frog=1;
		if (x>y)Min(sum,y);
		ans+=x;
	}writeln(!frog?0:(ans-sum));
}

Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<cstdio>
#include<cmath>
#include<math.h>
#include<string>
#include<string.h>
#include<stack>
#include<queue>
#include<vector>
#include<utility>
#include<set>
#include<map>
#include<stdlib.h>
#include<iomanip>

using namespace std;

#define ll long long
#define ld long double
#define EPS 0.0000000001
#define INF 1e9
#define MOD 1000000007
#define rep(i,n) for(i=0;i<n;i++)
#define loop(i,a,n) for(i=a;i<n;i++)
#define all(in) in.begin(),in.end()
#define shosu(x) fixed<<setprecision(x)

typedef vector<int> vi;
typedef pair<int,int> pii;

int main(void) {
  int i,j;
  int n;
  string s;
  cin>>s;
  s[3]='8';
  cout<<s<<endl;
}


Measured memory_bytes: 256
import sys
import socket

if socket.gethostname() in ['N551J', 'F551C']:
    sys.stdin = open('a1.in')


def read_int_list():
    return list(map(int, input().split()))


def read_int():
    return int(input())


def read_str_list():
    return input().split()


def read_str():
    return input()


def solve():
    n, x = read_int_list()
    a = read_int_list()
    a.sort()
    if sum(a) == x:
        return n
    res = 0
    for i in range(n):
        if sum(a[:i]) <= x:
            res = i
    return res


def main():
    res = solve()
    print(res)


if __name__ == '__main__':
    main()


Measured memory_bytes: 3700
#include <functional>
#include <algorithm>
#include <iostream>
#include <numeric>
#include <iomanip>
#include <utility>
#include <cstdlib>
#include <sstream>
#include <bitset>
#include <vector>
#include <cstdio>
#include <ctime>
#include <queue>
#include <deque>
#include <cmath>
#include <stack>
#include <list>
#include <map>
#include <set>

using namespace std;

typedef vector<int> vi;
typedef pair<int,int> pii;
typedef long long ll;

#define dump(x)  cerr << #x << " = " << (x) << endl
#define rep(i,n) for(int i=0;i<(n);i++)
#define all(a)  (a).begin(),(a).end()
#define pb push_back
#define sz size()

const double EPS = 1e-10;
const int INF = 100000000;


char add(char ch,int x){
    x=x%26;
    ch+=x;
    if(ch<'A'){
        ch+=26;
    }
    else if(ch>'Z'){
        ch-=26;
    }
    
    return ch;
}

string doPlusMinas(string s){
    string ret="";
    int now=0;
    rep(i,s.sz){
        if(s[i]=='[' || s[i]==']'){
            ret+=s[i];
        }
        else if(s[i]=='+')now++;
        else if(s[i]=='-')now--;
        else if(s[i]>='A' && s[i]<='Z'){
            ret+=add(s[i],now);
            now=0;
        }
        else if(s[i]=='?'){
            ret+='A';
            now=0;
        }
    }
    return ret;
}

string rev(string s){

    string ret="";
    
    rep(i,s.sz){
        int spoint=-1;
        int count=0;
        
        if(s[i]=='['){
            int sum=1;
            spoint=i;
            count++;

            while(sum){
                i++;
                count++;
                if(s[i]=='[')sum++;
                if(s[i]==']')sum--;
            }
            ret+=rev(s.substr(spoint+1,count-2));
        }
        else{
            ret+=s[i];
        }
    }
    reverse(all(ret));
    return ret;
}



int main(){
    string s;
    while(cin>>s){
        if(s==".")break;
        s=doPlusMinas(s);
        
        string ans="";
        
        rep(i,s.sz){
            int start,count=0;

            if(s[i]=='['){
                start=i;
                int sum=0;
                do{
                    if(s[i]=='[')sum++;
                    if(s[i]==']')sum--;
                    i++;
                    count++;
                }while(sum);
                i--;
                ans+=rev(s.substr(start+1,count-2));
            }
            else{
                ans+=s[i];
            }
        }
        cout<<ans<<endl;
    }
    
    return 0;
}

Measured memory_bytes: 1200
#include<stdio.h>

int main(void){
    
    int x;
    int i=1;
    
    
    while(1){
        scanf("%d",&x);
        if(x == 0){
            break;
        }
        printf("Case %d: %d\n",i,x);
        i++;
    }
    
    return 0;
}


Measured memory_bytes: 2036
#include<bits/stdc++.h>
using namespace std;
#define all(x) (x).begin(),(x).end()
const long long mod = 1e9+7;
//////////////////////////////////

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

  long long ans = 0;
  for(int i=1; i<n; i++) {
    if (a[i] < a[i-1]) {
      ans += a[i-1] - a[i];
      a[i] = a[i-1];
    }
  }
  cout << ans << endl;

  return 0;
}

// EOF

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

using namespace std;
typedef long long ll;

const int N = 3010;
const ll INF = 0x3f3f3f3f3f3f3f3f;

int R, C, k;
int x, y, v;
ll val[N][N], dp[N][N][4];

int main() { 
	scanf("%d%d%d", &R, &C, &k);
	for(int i = 1;i <= k; ++i) {
		scanf("%d%d%d", &x, &y, &v);
		val[x][y] = v;
	}
	dp[1][1][0] = 0; dp[1][1][1] = val[1][1];
	for(int i = 1;i <= R; ++i) {
		for(int j = 1;j <= C; ++j) {
			if(i > 1) {
				for(int k = 0;k < 4; ++k)
					dp[i][j][0] = max(dp[i][j][0], dp[i - 1][j][k]),
					dp[i][j][1] = max(dp[i][j][1], dp[i - 1][j][k] + val[i][j]);
			}
			if(j > 1) {
				dp[i][j][0] = max(dp[i][j][0], dp[i][j - 1][0]);
				for(int k = 1;k <= 3; ++k)
					dp[i][j][k] = max(dp[i][j][k], dp[i][j - 1][k - 1] + val[i][j]),
					dp[i][j][k] = max(dp[i][j][k], dp[i][j - 1][k]);
			}
		}
	}
	ll ans = max(max(dp[R][C][0], dp[R][C][1]), max(dp[R][C][2], dp[R][C][3]));
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 356048
#include <bits/stdc++.h>
#define ll long long
#define rep(X,N) for(ll X = 0; X < (N); X++)
#define PI (acos(-1.0))
#define pback push_back
#define mpair make_pair
#define divceil(A, B) ((A + (B - 1)) / B)
#define MODN 1000000007
#define ALL(V) (V).begin(),(V).end()
#define CERR if(false) cerr

using namespace std;

int main(){

    int n,k;
    cin >> n >> k;
    vector<int> v;

    rep(i,n){
        int tmp;
        cin >> tmp;
        v.pback(tmp);
    }

    vector<int> left;
    vector<int> right;
    vector<int> leftminus;
    vector<int> rightminus;


    left.pback(0);
    right.pback(0);

    for(int i = 0; i < n; i++){
        if(v[i] >= 0){
            left.pback(left[i] + v[i]);
            leftminus.pback(0);
        }else{
            left.pback(left[i] + v[i]);
            leftminus.pback(v[i]);
        }
        cerr << left[i + 1] << " ";
    }
    cerr << endl;

    for(int i = 0; i < n; i++){
        if(v[n - 1 - i] >= 0){
            right.pback(right[i] + v[n - 1 - i]);
            rightminus.pback(0);
        }else{
            right.pback(right[i] + v[n - 1 - i]);
            rightminus.pback(v[n - 1 - i]);
        }
        cerr << right[i + 1] << " ";
    }
    cerr << endl;

    int ans = 0;

    for(int l = 0; l <= n; l++){
        for(int r = 0; r <= n; r++){
            if(l + r > n || l + r > k) continue;

            int sum = left[l] + right[r];
            
            
            vector<int> tmpminus;

            for(int i = 0; i < l; i++){
                if(v[i] < 0) tmpminus.pback(v[i]);
            }

            for(int i = 0; i < r; i++){
                if(v[n - 1 - i] < 0) tmpminus.pback(v[n - 1 - i]);
            }

            sort(ALL(tmpminus));

            int rest = k - l - r;

            rep(i, rest){
                if(tmpminus.size() == i) break;
                sum = sum - tmpminus[i];
            }

            if(ans < sum){
                cerr << l << " " << r << endl;
                ans = sum;
            }
        }
    }


    cout << ans << endl;



}


Measured memory_bytes: 256
#include <iostream>

int main(){
   std::string s[3];
   for(int i=0; i<3; ++i)
      std::cin >> s[i];

   for(int i=0; i<3; ++i){
      char initial = 'A';
      for(int j=0; j<s[i][0]-'a'; ++j) initial++;
      std::cout << initial;
   }
   std::cout << std::endl;

   return 0;
}


Measured memory_bytes: 256
#include <iostream>

using namespace std;
int main(int argc, char *argv[]) {
	string s;
	cin >> s;
	for (int i = 0; i < s.size() - 1; i++) {
		if (s[i] == s[i + 1]) {
			cout << "Bad" << endl;
			return 0;
		}
	}
	cout << "Good" << endl;
}

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

int main() {
	int n;
	cin >> n;
	int temp = n;
	int fx = 0;
	while (temp) {
		fx += temp % 10;
		temp /= 10;
	}
	if (n % fx == 0) {
		cout << "Yes";
	} else {
		cout << "No";
	}
	return 0;
}

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

using ll = long long;
using Vi = vector<int>;
using Vl = vector<ll>;
using Pii = pair<int, int>;
using Pll = pair<ll, ll>;

constexpr int I_INF = numeric_limits<int>::max();
constexpr ll L_INF = numeric_limits<ll>::max();

//%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

int main() {
#ifdef FASTIO
    cin.tie(0), cout.tie(0);
    ios::sync_with_stdio(false);
#endif
#ifdef FILEINPUT
    ifstream ifs("./in_out/input.txt");
    cin.rdbuf(ifs.rdbuf());
#endif
#ifdef FILEOUTPUT
    ofstream ofs("./in_out/output.txt");
    cout.rdbuf(ofs.rdbuf());
#endif

    ll K, A, B;
    cin >> K >> A >> B;

    bool ok = false;
    for (ll x = A; x <= B; x++) {
        if (x % K == 0) {
            ok = true;
        }
    }

    cout << (ok ? "OK\n" : "NG\n");

    cout << flush;
    return 0;
}

Measured memory_bytes: 3648
#include "bits/stdc++.h"
using namespace std;
#define ll long long int
#define rep(i,n) for( int i = 0; i < n; i++ )
#define rrep(i,n) for( int i = n; i >= 0; i-- )
#define REP(i,s,t) for( int i = s; i <= t; i++ )
#define RREP(i,s,t) for( int i = s; i >= t; i-- )
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define INF 2000000000
#define mod 1000000007
#define INF2 1000000000000000000

int D[31][31];
int c[510][510];
int cnt[31][3];
int main(void)
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    int N, C; cin >> N >> C;
    
    rep(i, C) {
        rep(j, C) {
            cin >> D[i][j];
        }
    }
    rep(i, N) {
        rep(j, N) {
            cin >> c[i][j];
            c[i][j]--;
            cnt[c[i][j]][(i + j) % 3]++;
        }
    }
    int ans = INF;
    rep(s, C) {
        rep(t, C) {
            rep(r, C) {
                if (s == t || t == r || r == s) continue;
                int tmp = 0;
                rep(i, C) {
                    
                    tmp += D[i][s] * cnt[i][0];
                    tmp += D[i][t] * cnt[i][1];
                    tmp += D[i][r] * cnt[i][2];
                }
                //cout << s << " " << t << " " << r << "->" << tmp << endl;
                ans = min(ans, tmp);
            }
        }
    }
    cout << ans << endl;


    return 0;
}


Measured memory_bytes: 1280
#include <bits/stdc++.h>
#define MAX (ll)(3e5 + 7)
#define INF (ll)(1e5 + 7)
#define MOD (ll)(1e9 + 7)
#define PI (double)(3.14159265)
#define IO ios_base :: sync_with_stdio (false);
#define LOG 20

using namespace std;
using ll = long long;

int main () {
	string st;
	cin >> st;
	int n = st.size ();
	int n2 = n / 2;
	for (int i = 0; i < n / 2; i++) {
		if (st[i] != st[n - i - 1] || st[i] != st[n2 - i - 1]) {
			cout << "No\n";
			return 0;
		}
	}
	cout << "Yes\n";
}



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

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

	int n = strlen(s);
	
	if (n <= 1) {
		cout << 0;
		return 0;
	}

	int preNum;
	preNum = s[0] - '0';

	int change = 0;
	for (int i = 1; i < n;i++) {
		int n = s[i] - '0';
		if (n == preNum) {
			change++;
			preNum = n == 0 ? 1 : 0;
		}
		else {
			preNum = n;
		}
	}

	cout << change;
	return 0;
}

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

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

long long MOD = 1000000000 + 7;

int main(){
  cout << setprecision(10);
  vector<vector<char>> ans(100, vector<char>(100,'.'));

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

  for(int i= 0; i < 50; i++ ){
    for(int j = 0; j < 100; j++){
      ans[i][j] = '#';
    }
  }

  int num = 1;
  for(int j = 0; j < 100; j+= 2){
    for(int i = 0; i < 49; i+= 2){
      if(num < A){
        ans[i][j] = '.';
        num++;
      }
      if(num == A){
        break;
      }
    }
  }

  num = 1;
  for(int j = 0; j < 100; j+= 2){
    for(int i = 51; i < 100; i+= 2){
      if(num < B){
        ans[i][j] = '#';
        num++;
      }
      if(num == B){
        break;
      }
    }
  }

  cout << 100 << " " << 100 << endl;
  for(int i = 0; i < 100; i++){
    for(int j = 0; j < 100; j++){
      cout << ans[i][j];
    }
    cout << endl;
  }
}


Measured memory_bytes: 256
#pragma GCC optimize ("Ofast")
#pragma GCC target ("avx,avx2")
//#pragma GCC optimize ("trapv")

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

#define fastio ios_base::sync_with_stdio(0); cin.tie(0); cin.exceptions(cin.failbit);
//#define rep(i, begin, end) for (__typeof(end) i = (begin) - ((begin) > (end)); i != (end) - ((begin) > (end)); i += 1 - 2 * ((begin) > (end)))
#define rep(i, a, b) for(lli i = a; i < (b); ++i)
#define trav(a, x) for(auto& a : x)
#define ff first
#define ss second
#define mp make_pair
#define pb push_back
#define all(x) (x).begin(), (x).end()
#define sz(x) lli((x).size())
#define what_is(x) cerr << #x << " is " << x << endl;
#define wis cout<<endl<<"I already speak english, bitch"<<endl<<endl;

typedef long long int lli;
typedef vector<lli> vi;
typedef pair<lli,lli> ii;
typedef vector<ii> vii;
typedef pair<ii,lli> iii;
typedef long double C;

#define trace(args...) { string  _s =#args; replace(_s.begin(), _s.end(), ',',' '); stringstream _ss(_s); istream_iterator<string> _it(_ss); err(_it, args);}
void err(istream_iterator<string> it){}
template<typename T, typename... Args>
void err(istream_iterator<string> it, T a, Args... args){
    cout <<  *it  << " : " << a << endl;
    err(++it, args...);
}


int main(){
	int a,b,c; cin>>a>>b>>c;
	int A,B,C;
	A=b,B=a,C=c;
	swap(A,C);
	cout<<A<<" "<<B<<" "<<C<<endl;


	return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<cstring>
using namespace std;
char a[101],b[101];
int blen;
int main()
{
    cin>>a>>b;
    blen=strlen(b);
    for(int i=0;i<blen;i++)cout<<a[i]<<b[i]; 
    if(strlen(a)>strlen(b)) cout<<a[blen]<<endl; 
    return 0;
}

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

// マクロ //
#define rep(i,N) for(int i = 0; i < N; i++)
#define all(x) x.begin(), x.end()
#define sort(x) sort(all(x))
#define uniq(x) x.erase(unique(all(x)), x.end())
#define vsum(x) accumulate(all(x), 0)
#define cou(x) cout << x << endl
#define y() cout << "Yes" << endl
#define n() cout << "No" << endl
#define Y() cout << "YES" << endl
#define N() cout << "NO" << endl
#define x2(x) (x) * (x)

// 型エイリアス //
using lint = long long;
using pii = pair<int, int>;
using vi = vector<int>;
using vli = vector<lint>;
using vc = vector<char>;
using vs = vector<string>;
using vb = vector<bool>;
using vvi = vector<vi>;
using vvb = vector<vb>;
using vvc = vector<vc>;
using vpii = vector<pii>;
using msi = map<string, int>;

// 関数 //
template<class T> lint gcd(T a, T b) {
    int t;
    while (b != 0) {
        t = a % b;
        a = b;
        b = t;
    }
    return a;
}

template<class T> lint lcm(T a, T b) {
    return a * b / gcd(a, b);
}

double distance(pii a, pii b) {
    double dist;
    dist = sqrt(x2(a.first - b.first) + x2(a.second - b.second));
    return dist;
}

lint perm(int a) {
    lint perm = 1;
    for (int i = a; i >= 1; i--) {
        perm *= i;
    }
    return perm;
}

lint combination(int n, int m) {
    long double c = 1;
    for (int i = n, k = 1; i > m; i--, k++) {
        c *= i;
        c /= k;
    }
    return (lint)c;
}

template<class T, class Q> inline bool chmin(T& a, Q b) {
    if (a > b) {
        a = b;
        return true;
    }
    return false;
}

template<class T, class Q> inline bool chmax(T& a, Q b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}

// 定数 //
#define pi acos(-1)
#define mod 1000000007
#define MOD 998244353
#define inf ((1LL << 62) - 1 + (1LL << 62))

// キーワード //
#define elif else if

// End of Template //



int main() {

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

    int A, B, C;
    cin >> A >> B >> C;
    cou(max(C - (A - B), 0));



}


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

long long N,arr[200010];

int main(){
	cin>>N;
	long long increase=0,total=1;
	cin>>arr[0];
	for(int i=1; i<N; i++){
		cin>>arr[i];
		if(increase==1){
			if(arr[i]<arr[i-1]){
				total++;
				increase=0;
			}
		}else if(increase==2){
			if(arr[i]>arr[i-1]){
				total++;
				increase=0;
			}
		}else if(increase==0){
			if(arr[i]<arr[i-1]){
				increase=2;
			}else if(arr[i]>arr[i-1]){
				increase=1;
			}
		}
	}
	cout<<total<<'\n';
}

Measured memory_bytes: 4356
#include<bits/stdc++.h>
#define ll long long int
using namespace std;
bool ispal(string a)
{
    long long int n=a.length();
    if(n==1)
        return true;
    else{
    int i=0,j;
    j=n-1;
    while(1)
    {
        if(a[i]!=a[j])
        {
            cout<<i<<" "<<j;
           return false;
        }
        i++,j--;
        if(i==j)
         {
        //     cout<<i<<" ";
             break;
        }
    }
    return true;
}}

int main(){
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
 ll n;
 cin>>n;
 ll a[n];
 for(int i=0;i<n;i++)
 {
     cin>>a[i];
 }
ll ans=0;
 for(int i=0;i<n-1;i++)
 {
     if(a[i+1]<a[i])
     {
         ans+= (a[i]-a[i+1]);
         a[i+1]=a[i];
     }
 }
 cout<<ans;
 }

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

#define rep(i, n) for(int (i) = 0; (i) < (n); (i)++)
#define repp(i, n, m) for(int (i) = (n); (i) < (m); (i)++)
#define repn(i, n) for(int (i) = 1; (i) <= (n); (i)++)
#define repr(i, n) for(int (i) = (n-1); (i) >= 0; (i)--)
#define all(x) (x).begin(), (x).end()
#define lint long long
#define ulint unsigned long long
#define ldou long double
#define fi first
#define se second
#define setpre(x) std::cout << fixed << setprecision(x)
#define ii(x) int x; cin >> (x)
#define ii2(x, y) int x, y; cin >> (x) >> (y)
#define ii3(x, y, z) int x, y, z; cin >> (x) >> (y) >> (z)
#define out(x) cout << (x) << endl
#define outs(x) cout << (x) << " "
#define yn(x) cout << ((x)?("Yes"):("No")) << endl
#define YN(x) cout << ((x)?("YES"):("NO")) << endl
#define bit_c(x) __builtin_popcountll(x)

inline void logger(){ std::cout << " [LOGGER] " << endl; }
template<typename A, typename... B>
void logger(const A& a, const B&... b){
    cout << a << " , "; logger(b...);
}

typedef pair<lint, lint> P;
const lint MOD = 1000000007;
const lint MOD9 = 998244353;
const lint INF = MOD * MOD;
const int MAX = 200005;

/* ...o(^-^)o... */


template<class T>
class abstract_segtree{
    public:
    int n; vector<T> data;
    T id;
    function<T(T,T)> op;
    function<T(T,T)> upd;
    abstract_segtree(size_t _n, T _id, function<T(T,T)> _op, function<T(T,T)> _upd)
    : id(_id), op(_op), upd(_upd){
        n = 1;
        while(n < _n) n *= 2;
        data = vector<T>(2*n-1, id);
    }
    T _query(int a, int b, int k, int l, int r){
        if(r <= a || b <= l) return id;
        if(a <= l && r <= b) return data[k];
        else{
            T ll = _query(a, b, k*2+1, l, (l+r)/2);
            T rr = _query(a, b, k*2+2, (l+r)/2, r);
            return op(ll, rr);
        }
    }
    T query(int a, int b){
        return _query(a, b, 0, 0, n);
    }
    void update(int i, T x){
        i += n-1;
        data[i] = upd(data[i], x);
        while(i > 0){
            i = (i-1)/2;
            data[i] = op(data[i*2+1], data[i*2+2]);
        }
    }
    T operator[](int i){
        return data[i+n-1];
    }
};


int main(){
    int n, q; cin >> n >> q;
    abstract_segtree<lint> st(n, 0,
        [](lint l, lint r){ return l+r; },
        [](lint d, lint x){ return x+d; });
    rep(i, q){
        lint c, x, y; cin>>c>>x>>y;
        if(c==0) st.update(x-1, y);
        else out(st.query(x-1, y));
    }
}



Measured memory_bytes: 4932
#include <bits/stdc++.h>
using namespace std;
#define pp pair<int,int>
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define ll long long
#define ld long double
#define all(a) (a).begin(),(a).end()
#define mk make_pair
ll MOD=1000000007;
ll mod=998244353;
int inf=1000001000;
ll INF=1e18+5;

int main() {
    int n;
    cin >> n;
    vector<vector<int>> e(n+1,vector<int>(0));
    int u,v;
    cin >> u >> v;
    rep(i,n-1){
        int f,g;
        cin >> f >> g;
        e[f].push_back(g);
        e[g].push_back(f);
    }
    queue<pp> q;
    q.push(mk(v,0));
    vector<int> r(n+1,-1);
    r[v]=0;
    while(!q.empty()){
        int f=q.front().first,g=q.front().second;
        q.pop();
        rep(i,e[f].size()){
            int h=e[f][i];
            if (r[h]==-1){
                r[h]=g+1;
                q.push(mk(h,g+1));
            }
        }
    }
    vector<int> o(n+1,0);
    int ans=0;
    q.push(mk(u,0));
    o[u]=1;
    while(!q.empty()){
        int f=q.front().first,g=q.front().second;
        q.pop();
        ans=max(ans,r[f]);
        rep(i,e[f].size()){
            int h=e[f][i];
            if (o[h]==0 && g+1<=r[h]){
                o[h]=1;
                q.push(mk(h,g+1));
            }
        }
    }
    cout << ans-1 << endl;
}


Measured memory_bytes: 6784
#include <iostream>
#include <vector>
#include <cmath>
#include <algorithm>
#include <string>

#define ll long long
using namespace std;
int main()
{
	int n;
	cin >> n;
	vector<ll> a(n);
	for (int i = 0; i < n; i++) {
		cin >> a[i];
	}

	vector<ll>::iterator min_it;
	int minIndex;
	ll min;
	while (a.size() > 1) {
		min_it = min_element(a.begin(), a.end());
		minIndex = distance(a.begin(), min_it);
		min = a[minIndex];
		for (int i = 0; i < a.size(); i++) {
			if (i != minIndex) {
				a[i] = a[i] % min;
			}
		}
		for (int i = 0; i < a.size(); i++) {
			if (a[i] == 0) {
				a.erase(a.begin() + i);
				i--;
			}
		}
	}
	cout << a[0];
	return 0;
}

Measured memory_bytes: 1152
#include <bits/stdc++.h>
using namespace std;
 
int main(){
  int A,B,C;
  cin >> A >> B >> C;
  for(int i=0;i<100000000;i++){
    if(A%2==1 || B%2==1 || C%2==1){cout << i << endl; return 0;}
    int a=A/2; int b=B/2; int c=C/2;
    A=b+c; B=c+a; C=a+b;
  }
  cout << -1 << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <algorithm>
#include <utility>
#include <iomanip>
#include <functional>
#include <queue>
#include <stack>
#include <map>
#include <vector>
#include <cmath>
#include <cctype>
#include <cstdio>
#define ll long long
#define INF 1e+9
#define MOD 1000000007
using namespace std;


int main(){
    int N;
    cin >> N;
    
    int stt=1;
    for(int i=0; i<N; i++){
        stt*=4;
    }
    
    int A,B,C;
    cin >> A >> B >> C;
    
    int l[N];
    for(int i=0; i<N; i++){
        cin >> l[i];
    }
    
    
    int ans=INF;
    
    for(int i=0; i<stt; i++){
        int b[4]={};
        int tmp=0;
        
        int s=i;
        for(int k=0; k<N; k++){
            if(s%4!=0 && b[s%4]!=0){
                tmp+=10;
            }
            b[s%4]+=l[k];

            s/=4;
        }
        
        if(b[1]==0 || b[2]==0 || b[3]==0){
            continue;
        }else{
            tmp += abs(A-b[1]) + abs(B-b[2]) + abs(C-b[3]);
            ans = min(ans,tmp);
        }
    }
    
    cout<<ans<<endl;
        
    return 0;
}


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

int main(void){
  string N;
  cin>>N;
  if(N[0]==N[1]){
    if(N[1]==N[2])cout<<"Yes";
    else cout<<"No";
  }
  else{
    if(N[1]==N[2]){
      cout<<(N[2]==N[3]?"Yes":"No");
    }
    else cout<<"No";
  }


  return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<algorithm>
#include<queue>
#include<cmath>
#include<iomanip>
#include<map>
#include<cstring>

using namespace std;

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define vi vector<int>
#define vivi vector<vi>
const int INF = int(1e9);
typedef long long int ll;
/* -- template -- */

int main(){
    int N, M; cin >> N >> M;
    pair<int, int> a[M];
    rep(i, M){
        cin >> a[i].first >> a[i].second;
    }
    sort(a, a + M);
    int nowB;
    nowB = a[0].second;
    int ans = 0;
    for(int i = 1;i < M;++i){
        if(nowB <= a[i].first){
            ++ans;
            nowB = a[i].second;
        }else{
            if(nowB > a[i].second)nowB = a[i].second;
        }
    }
    cout << ans + 1 << endl;
}


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

int main(){
	string s,k={};
  	cin >> s;
  	for (int i=0;i<s.size();i++){
    	if(s[i]=='0') k=k+'0';
      	if(s[i]=='1') k=k+'1';
      	if(s[i]=='B' && k.size()>=1 ) k.pop_back();
    }
  	cout << k << endl;

}

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

# i番目までからｊ枚選んで合計がｋ
dp = [[[0 for _ in range(50*N + 1)] for _ in range(N+1)] for _ in range(N+1)]
# 何も選ばず平均が０
dp[0][0][0] = 1

#全てのカードについてみる
#i-1番までからj-1枚選んで、j番目にiを選択したときの合計がA*jになるかどうか
for i in range(N+1):
    #i-1番目までからj-1枚選んであるので、最大でi-1枚選んである
    for j in range(i+1):
        # ｋは合計値
        for k in range(50*j + 1):
            # i番目を選んで合計がｋになるには、i番目の値がｋより小さくなければならない
            if i >= 1 and k < X[i-1]:
                # i番目がｋより大きいから、i-1番目までで合計がｋになる組の個数と同じ
                dp[i][j][k] = dp[i-1][j][k]
            # 
            elif i >= 1 and j >= 1 and k >= X[i-1]:
                #i番目を選んで合計がｋになるとき、ｋがi番目より大きい＆i-1からj-1枚選んだ時に合計がｋ－X[i-1]と、i-1番目まででできるやつ
                dp[i][j][k] = dp[i-1][j][k] + dp[i-1][j-1][k - X[i-1]]

ans = 0
for i in range(1, N+1):
    #N枚からi枚選んで合計がi*A
    ans += dp[N][i][i*A]

print(ans)

Measured memory_bytes: 65504