akhauriyash/Code-Regression huggingface dataset:
#include<iostream>
#include<algorithm>
#include<climits>
#include<cmath>
#include<cstdio>
#include<cstdlib>
#include<ctime>
#include<string>
#include<cstring>
#include<vector>
#include<stack>
#include<queue>
#include<set>
#include<bitset>

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> i_i;

#define PI 3.141592653589793238462643383279
#define mod 1000000007LL
#define rep(i, n) for(i = 0;i < n;++i)
#define rep1(i, n) for(i = 1;i < n;++i)
#define per(i, n) for(i = n - 1;i > -1;--i)
#define int(x) int x; scanf("%d",&x)
#define int2(x, y) int x, y; scanf("%d%d",&x, &y)
#define int3(x, y, z) int x, y, z; scanf("%d%d%d",&x, &y, &z)
#define int4(v, x, y, z) int v, x, y, z; scanf("%d%d%d%d", &v, &x, &y, &z)
#define int5(v, w, x, y, z) int v, w, x, y, z; scanf("%d%d%d%d%d", &v, &w, &x, &y, &z)
#define ll2(x, y) ll x, y; cin >> x >> y;
#define scn(n, a) rep(i, n)cin >> a[i]
#define sc2n(n, a, b) rep(i, n)cin >> a[i] >> b[i]
#define pri(x) cout << (x) << "\n"
#define pri2(x, y) cout << (x) << " " << (y) << "\n"
#define pri3(x, y, z) cout << (x) << " " << (y) << " " << (z) << "\n"
#define pb push_back
#define mp make_pair
#define all(a) (a).begin(),(a).end()
#define endl "\n"
#define kabe puts("---------------------------")
#define kara puts("")
#define debug(x) cout << " --- " << (x) << "\n"
#define debug2(x, y) cout << " --- " << (x) << " " << (y) << "\n"
#define debug3(x, y, z) cout << " --- " << (x) << " " << (y) << " " << (z) << "\n"
#define X first
#define Y second
#define eps 0.0001
#define prid(x) printf("%.15lf\n", x)


signed main(void){
  int i, j;
  for(int testcase = 0;testcase >= 0;testcase++){
    int(n);
    for(;n--;){
      int4(x, y, b, p);
      int res = x * b + y * p;
      res = min(res, (x * max(b, 5) + y * max(p, 2)) / 5 * 4);
      pri(res);
    }


/*/

//*/ break;
  }
  return 0;
}

Measured memory_bytes: 3136
#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define mod 1000000007LL
#define all(x) x.begin() , x.end()

void solve()
{
	ll a, b, c; cin >> a >> b >> c;
	ll k; cin >> k;
	while (b <= a)
	{
		k--; b *= 2;
	}
	while (c <= b)
	{
		k--; c *= 2;
	}
	if (k >= 0) cout << "Yes";
	else cout << "No";
}
int32_t main() {
	ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
	ll t = 1; //cin >> t;
	while (t--)
		solve();
	return 0;
}

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

using namespace std;

#define INF 1000000007
#define LINF (1LL << 60)
#define PI 3.14159265358979

typedef long long i64;
typedef pair<i64,i64> P;

inline i64 mod(i64 a, i64 m) { return (a % m + m) % m; }

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



int n;
string s[101010];
void solve(){
	cin >> n;
	for(int i = 0; i < n; i++){
		cin >> s[i];
	}
	
	int ans = 0, a = 0, b = 0;
	int c = 0;
	for(int i = 0; i < n; i++){
		for(int j = 0; j < s[i].size(); j++){
			if(s[i][j] == 'A' && s[i][j+1] == 'B') ans++;
		}
		bool bb = 0,aa = 0;
		if(s[i][0] == 'B') b++, bb = 1;
		if(*(s[i].end()-1) == 'A') a++, aa = 1;
		if(bb && aa) c++;
	}
	
	if(max(a,b) == c) ans += max(c-1,0);
	else ans += min(a,b);
	cout << ans << endl;
}

int main(){
	std::cin.tie(0);
	std::ios::sync_with_stdio(false);
	int t = 1;
	//cin >> t;
	while(t--){
		solve();
	}
	
	return 0;
}


Measured memory_bytes: 1536
A = int(input())
B = int(input())
C = int(input())
X = int(input())
cnt = 0
for i in range(min(A,X//500)+1):
    for j in range(min(B,X//100)+1):
        y = X-500*i-100*j
        if y<0:break
        if y//50<=C:
            cnt += 1
print(cnt)

Measured memory_bytes: 3064
#include <iostream>
#include <cstring>
#include <cstdlib>
#include <set>
#include <vector>
#include <map>
#include <cstdio>
#include <utility>
#include <algorithm>
#include <cmath>
#include <queue>
#include <stack>
#include <cassert>
#include <climits>
using namespace std;
typedef long long ll;
#define DEBUG
#ifdef DEBUG
	#define debug printf
#else
	#define debug(...)
#endif
const int maxn = 1e5 + 5;
vector<ll> G[maxn];
ll indegree[maxn],ans[maxn];
ll n,m;
int main(int argc, char const *argv[])
{
	cin>>n>>m;
	for(int i = 0;i < n - 1 + m; ++i)
	{
		int x,y;
		scanf("%lld%lld",&x,&y);
		G[x].push_back(y);
		indegree[y]++;
	}
	queue<ll> q;
	for(int i = 1;i <= n; ++i)
	{
		if(indegree[i] == 0)
		{
			q.push(i);
		}
	}
	while(!q.empty())
	{
		ll now = q.front();
		q.pop();
		for(ll i : G[now])
		{
			indegree[i]--;
			if(indegree[i] == 0)
			{
				ans[i] = now;
				q.push(i);
			}
		}
	}
	for(int i = 1;i <= n; ++i)
	{
		printf("%d\n",ans[i]);
	}
	return 0;
}

Measured memory_bytes: 7808
S = input()

if S == 'SUN':
    print(7)
elif S == 'MON':
    print(6)
elif S == 'TUE':
    print(5)
elif S == 'WED':
    print(4)
elif S == 'THU':
    print(3)
elif S == 'FRI':
    print(2)
else:
    print(1) 

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

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

#define FOR(i, n, m) for (ll(i) = (m); (i) < (n); ++(i))
#define REP(i, n) FOR(i, n, 0)
#define OF64 std::setprecision(10)

const ll MOD = 1000000007;
const ll INF = (ll)1e15;

int L[55];

int main()
{
    int N, K;
    cin >> N >> K;
    REP(i, N)
    {
        cin >> L[i];
    }
    sort(L, L + N, [](int a, int b) { return a > b; });
    int S = 0;
    REP(i, K)
    {
        S += L[i];
    }
    cout << S << endl;
    return 0;
}

Measured memory_bytes: 256
n=int(input()) #　a1
f = [list(map(int, input().split())) for i in range(n)]
p=[list(map(int, input().split())) for i in range(n)]

numf=[]
ansp=0
ans=-float('inf')

for i in range(1,2**10):
  l=str(bin(i)).lstrip("0b")
  ll=list(l.zfill(10))
  ilist=[int(xl) for xl in ll]
  j=0
  ansp=0
  for jlist in f:
    suml=[ilist[k]*jlist[k] for k in range(10)]
    c=sum(suml)
    ansp+=p[j][c]
    j+=1

  ans=max(ans,ansp)

print(ans)

Measured memory_bytes: 3064
#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<cmath>
#include<queue>
#include<vector>
#include<stack>
#include<map>
#include<deque>
#include<set>
#define inf 1e9
#define eps 1e-6
#define N 200010
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
inline ll read()
{
	char ch=getchar();
	ll s=0,w=1;
	while(ch<'0'||ch>'9'){if(ch=='-')w=-1;ch=getchar();}
	while(ch>='0'&&ch<='9'){s=s*10+ch-'0';ch=getchar();}
	return s*w;
}
ll n,m;
ll q[N],val[N],ans[N];
ll Stack[N],top;
inline void Solve(ll now,ll v,ll V)
{
	if(!v)return ;
	if(now==1){ans[v]+=V;return ;}
	ll l=1,r=now-1,pos=1;
	while(l<=r)
	{
		ll mid=(l+r)>>1;
		if(q[mid]<=v)pos=mid,l=mid+1;
		else r=mid-1;
	}
//	cout<<"???:"<<now<<" "<<v<<" "<<V<<" "<<pos<<endl;
	val[pos]+=(v/q[pos])*V;Solve(pos,v%q[pos],V);
}
int main()
{
	//freopen(".in","r",stdin);
	//freopen(".out","w",stdout);
	n=read(),m=read();
	for(register ll i=1;i<=m;i++)q[i]=read();q[0]=n;
	for(register ll i=0;i<=m;i++)
	{
		while(top&&Stack[top]>=q[i])top--;
		Stack[++top]=q[i];
	}
	m=top;
	for(register ll i=1;i<=m;i++)q[i]=Stack[i];
	val[m]=1;
	for(register ll i=m-1;i>=1;i--)
	{
		val[i]+=val[i+1]*(q[i+1]/q[i]);
		Solve(i,q[i+1]%q[i],val[i+1]);
	}
//	for(register int i=1;i<=m;i++)cout<<val[i]<<" ";
//	cout<<endl;
	ans[q[1]]+=val[1];
//	for(register int i=1;i<=q[1];i++)cout<<ans[i]<<" ";cout<<endl;
	for(register ll i=q[1];i>=1;i--)ans[i]+=ans[i+1];
	for(register ll i=1;i<=q[1];i++)printf("%lld\n",ans[i]);
	for(register ll i=q[1]+1;i<=n;i++)printf("0\n");
	return 0;
}


Measured memory_bytes: 6892
#include<stdio.h>
#define M 2000000000
#define INF (1 << 21)

void maxHeapify(int);
void insert(int);
void increase(int, int);
int extract(void);

int A[M], H;
int left(i)
{
  return 2 * i;
}
int right(i)
{
  return 2 * i + 1;
}
void maxHeapify(int i)
{
  int l, r, largest;
  int tmp;
  l = left(i);
  r = right(i);
  if(l <= H && A[l] > A[i])
    {
      largest = l;
    }
  else
    {
      largest = i;
    }
  if(r <= H && A[r] > A[largest])
    {
      largest = r;
    }
  if(largest != i)
    {
      tmp = A[i];
      A[i] = A[largest];
      A[largest] = tmp;
      maxHeapify(largest);
    }
}

void insert(int n)
{
  H++;
  A[H] = -INF;
  increase(H, n);
}

void increase(int i, int n)
{
  int a;
  if(n < A[i])
    {
      return;
    }
  A[i] = n;
  while(i > 1 && A[i/2] < A[i])
    {
      a = A[i/2];
      A[i/2] = A[i];
      A[i] = a;
      i = i / 2;
    }
}

int extract()
{
  int m;
  if(H < 1)
    {
      return -INF;
    }
  m = A[1];
  A[1] = A[H];
  H--;
  maxHeapify(1);
  return m;
}

int main()
{
  int n;
  A[H] = -INF;
  char ch[10];
  while(1)
    {
      scanf("%s", ch);
      if(ch[0] == 'e' && ch[1] == 'n')
	{
	  break;
	}
      if(ch[0] == 'i')
	{
	  scanf("%d", &n);
	  insert(n);
	}
      else
	{
	  printf("%d\n", extract());
	}
    }
  return 0;
}



Measured memory_bytes: 5632
#include <iostream>
#include <string>
#include <algorithm>

#define INF 1000000007

using namespace std;

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

    long long l=-1, r=-1, w=0;
    for (long long i=0; i<n; i++){
        if (s[i]=='#' && l==-1){
            l = i;
        }
        if (s[i]=='.' && l!=-1){
            r = i;
            w++;
        }
    }
    if (r==-1){
        cout << 0 << endl;
    }
    else{
        long long ans = w, b_i=0;

        for (int i=l; i<=r; i++){
            if (s[i]=='#') b_i++;
            if (ans > b_i + (w-i+l-1+b_i)){
                ans = b_i + (w-i+l-1+b_i);
            }
        }
        cout << ans << endl;
    }

    return 0;
}


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

using namespace std;
using ll = long long;

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(nullptr);
  int n, m;
  cin >> n >> m;
  vector<int> vals(n, -1);
  int free = 0;
  vector<vector<int>> g(n);
  for(int i = 0; i < m; ++i) {
    int x, y, z;
    cin >> x >> y >> z;
    g[x - 1].push_back(y - 1);
    g[y - 1].push_back(x - 1);
  }
  vector<int> done(n, 0);
  function<void(int)> dfs = [&](int x) {
    done[x] = 1;
    for(int y: g[x]) if(!done[y]) {
      dfs(y);
    }
  };
  for(int i = 0; i < n; ++i) {
    if(!done[i]) {
      free++;
      dfs(i);
    }
  }
  cout << free << '\n';
  return 0;
}


Measured memory_bytes: 11264
using System;

class IfSample
{
    static void Main()
    {
        // 整数を入力してもらう
        int x,y,n,a;
       
        a = int.Parse(Console.ReadLine());
        x =a * 800;
        y = a/ 15 * 200;
            n = x - y;
        Console.WriteLine("{0}", n);
        

        
        }
    }

Measured memory_bytes: 13268
#include <iostream>

using namespace std;

int main(){
    int hi, hy, ki, ky, a, b, c, d;

    cin >> hi >> hy;
    cin >> ki >> ky;
    cin >> a >> b >> c >> d;

    double hia = (hi / 10);
    int hia2 = hia;

    double hyb = (hy / 20);
    int hyb2 = hyb;

    int ht = (hi * a) + (hy * b) + (hia2 * c) + (hyb2 * d);

    double kia = (ki / 10);
    int kia2 = kia;

    double kyb = (ky / 20);
    int kyb2 = kyb;

    int kt = (ki * a) + (ky * b) + (kia2 * c) + (kyb2 * d);

    if(ht > kt){
        cout << "hiroshi" << endl;
    }
    if(kt > ht){
        cout << "kenjiro" << endl;
    }
    if(ht == kt){
        cout << "even" << endl;
    }
}

/*
5 1
3 1
1 2 5 5
hiroshi

5 1
4 2
1 2 5 5
kenjiro

0 20
10 0
1 1 10 0
even
*/



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

typedef long long ll;

int main () {
	ll a, b, c, d;
	cin >> a >> b >> c >> d;
	ll max = a*c;
	if (a*d > max)
		max = a*d;
	if (b*c > max)
		max = b*c;
	if (b*d > max)
		max = b*d;
	cout << max << endl;
	return 0;
}

Measured memory_bytes: 3620
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N = 2e5 + 10;

int n;
int a[N];

int main() {
#ifdef ACM_LOCAL
    freopen("input.in", "r", stdin);
    freopen("output.out", "w", stdout);
#endif
    scanf("%d", &n);
    for (int i = 1; i <= n; i++) scanf("%d", &a[i]);
    int cnt = 0;
    for (int i = 1; i <= n; i++)
        for (int j = i + 1; j <= n; j++)
            if (a[i] != a[j])
                for (int k = j + 1; k <= n; k++)
                    if (a[i] != a[k] && a[k] != a[j])
                        if (a[i] + a[j] > a[k] && a[k] + a[j] > a[i] && a[k] + a[i] > a[j]) cnt++;
    printf("%d\n", cnt);

    return 0;
}

Measured memory_bytes: 3844
N, K = map(int, input().split())
A = list(map(int, input().split()))
F = list(map(int, input().split()))

A.sort()
F.sort(reverse=True)

hi = 10**18
lo = -1

while hi - lo > 1:
    mid = (hi + lo) // 2
    tr = 0
    for i in range(N):
        if A[i] * F[i] > mid:
            tr += A[i] - mid // F[i]
    if tr > K:
        lo = mid
    else:
        hi = mid

print(hi)

Measured memory_bytes: 122828
#include <bits/stdc++.h>
#define ll long long
#define pb push_back
#define ep emplace_back
#define st first
#define sc second

using namespace std;

const ll mod = 998244353;
const int e = 1e6 + 69;
const int base = 311;

// dung igt thay cho gt luc tinh giai thua
// 3
// cach tao hoan vi tu n so : n*(n+1)/2;

ll a[e];

int main()
{
    int n;
    cin >> n;
    for(int i=1; i<=n; i++)
    {
        cin >> a[i];
    }
    ll minn = 1e18;
    for(ll x=-100; x<=100; x++)
    {
        ll ans = 0;
        for(int j=1; j<=n; j++)
        {
            ans += (a[j] - x) * (a[j] - x);
        }
        minn = min(ans, minn);
    }
    cout << minn;
}


Measured memory_bytes: 256
/* ****mittal21**** */
#include<bits/stdc++.h>
#define ll          long long int 
#define ld          long double
#define pb          push_back
#define endl        '\n'
#define pii         pair<long long int,long long int>
#define vi          vector<ll>
#define all(a)      (a).begin(),(a).end()
#define F           first
#define S           second
#define sz(x)       (ll )x.size()
#define hell        1000000007
#define jell        998244353
#define rep(i,a,b)    for(ll int i=a;i<b;i++)
#define repr(i,a,b)   for(ll int i=a;i>=b;i--)
#define lbnd    lower_bound
#define ubnd        upper_bound
#define mp          make_pair
#define DEC(N)  cout << std::fixed; cout << setprecision(N);
using namespace std;
#define N  100005
void solve()
{
   ll k;
   cin>>k;
   for(int i=0;i<3*k;i++)
   {
       if(i%3==0)
        cout<<"A";
       else if(i%3==1)
        cout<<"C";
      else
        cout<<"L";
   }
   return;
}
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    ll testcase=1;
    //cin>>testcase;
    while(testcase--)
    {
        solve();
    }
    return 0;
}

Measured memory_bytes: 3520
#include <bits/stdc++.h>
using namespace std;
void trace(int A[],int N) {
    int i;
    for(i = 0;i < N;i++){
        if(i > 0)printf(" ");
        printf("%d",A[i]);
    }
    printf("\n");
}
void insertionSort(int A[],int N) {
    int i,v,j;
    for( i = 1;i < N;i++){
        v = A[i];
        j = i - 1;
        while(j >= 0 && A[j] > v){
            A[j + 1] = A[j];
            j--;
        }
        A[j + 1] = v;
        trace(A,N);
    }
}
int main(){
    int N;
    cin >> N;
    int A[100];
    for(int i = 0;i < N;i++)cin >> A[i];
    trace(A,N);
    insertionSort(A,N);
    
    }


Measured memory_bytes: 3160
N, M = map(int, input().split())

ans = 1
for i in range(1, int(M**0.5)+1):
    if M % i != 0:
        continue

    j = M // i
    if i * N <= M:
        ans = max(ans, i)
    if j * N <= M:
        ans = max(ans, j)

print(ans)


Measured memory_bytes: 3060
#include <bits/stdc++.h>
using ll = long long;
using ld = long double;
#define vi vector<ll>
#define vvi vector<vector<ll>>
#define vd vector<ld>
#define vvd vector<vector<ld>>
#define ALL(a) begin(a), end(a)
#define RALL(a) rbegin(a), rend(a)
#define SORT(a) stable_sort(ALL(a))
#define RSORT(a) stable_sort(RALL(a))
#define REV(a) reverse(ALL(a))
#define UNIQUE(a) a.erase(unique(ALL(a)), end(a))
#define lambda(i) [](auto& i)
#define compare(i, j) [](auto& i, auto& j)
#define min_of(a) *min_element(ALL(a))
#define max_of(a) *max_element(ALL(a))
#define sum(a) accumulate(ALL(a), 0)
#define pb push_back
#define mp make_pair
#define SZ(a) ll((a).size())
#define REP(i, n) for (decltype(+n) i = 0; i < (n); i++)
#define RREP(i, n) for (auto i = n - 1; i != static_cast<decltype(i)>(-1); i--)
#define FOR(i, a, b) for (auto i = (a); i < (b); i++)
#define RFOR(i, a, b) for (auto i = b - 1; i != a; i--)
#define EACH(i, a) for (auto&& i: (a))
using namespace std;

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

struct UnionFind {
  vector<ll> data;
  UnionFind(ll size) : data(size, -1) { }
  bool unionSet(ll x, ll y) {
    x = root(x); y = root(y);
    if (x != y) {
      if (data[y] < data[x]) swap(x, y);
      data[x] += data[y]; data[y] = x;
    }
    return x != y;
  }
  bool findSet(ll x, ll y) {
    return root(x) == root(y);
  }
  ll root(ll x) {
    return data[x] < 0 ? x : data[x] = root(data[x]);
  }
  ll size(ll x) {
    return -data[root(x)];
  }
};

vi cum(vi V) {
  vi U(SZ(V));
  partial_sum(ALL(V), begin(U));
  return U;
}

void solve() {
  ll n;
  ll ans = 0;

  cin >> n;
  auto uf = UnionFind(n);
  vector<pair<ll, ll>> v(n), xi(n), yi(n);
  vector<tuple<ll, ll, ll>> e;
  REP(i, n) {
    ll x, y;
    cin >> x >> y;
    v[i] = mp(x, y);
    xi[i] = mp(x, i);
    yi[i] = mp(y, i);
  }
  SORT(xi);
  SORT(yi);
  REP(i, n - 1) {
    e.pb(make_tuple(xi[i + 1].first - xi[i].first, xi[i + 1].second, xi[i].second));
    e.pb(make_tuple(yi[i + 1].first - yi[i].first, yi[i + 1].second, yi[i].second));
  }
  SORT(e);
  EACH(i, e) {
    if (uf.findSet(get<1>(i), get<2>(i))) continue;
    ans += get<0>(i);
    uf.unionSet(get<1>(i), get<2>(i));
  }

  cout << ans << endl;
}

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout << fixed << setprecision(15);
  solve();
}


Measured memory_bytes: 16736
#include <algorithm>
#include <iostream>
#include <iomanip>
#include <cstring>
#include <string>
#include <vector>
#include <queue>
#include <cmath>
#include <stack>
#include <set>
#include <map>
typedef long long ll;
using namespace std;

vector<int> G[201];
int col[201];
const int INF = 1 << 25;

//vをcで濡れるか
bool dfs(int v, int c){
  //cout << v << c << endl;
  col[v] = c;
  for(int i = 0; i < (int)G[v].size(); i++){
    if(col[G[v][i]] == c) return false;
    if(col[G[v][i]] == 0 && !dfs(G[v][i], -c)) return false;
  }
  return true;
}

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

  char s[N][N];
  for(int i = 0; i < N; i++){
    for(int j = 0; j < N; j++){
      cin >> s[i][j];
      if(s[i][j] == '1'){
        G[i].push_back(j);
      }
    }
  }

  /*for(int i = 0; i < N; i++){
    for(int j = 0; j < G[i].size(); j++){
      cout << G[i][j] << " ";
    }
    cout << endl;
  }*/

  //2部グラフ判定
  fill(col, col + N, 0);
  bool isBGraph = dfs(0, 1);

  int ans = 0;
  if(isBGraph){
    int d[N][N];
    for(int i = 0; i < N; i++){
      for(int j = 0; j < N; j++){
        if(i == j) d[i][j] = 0;
        else{
          if(s[i][j] == '1') d[i][j] = 1;
          else d[i][j] = INF;
        }
      }
    }

    for(int k = 0; k < N; k++){
      for(int i = 0; i < N; i++){
        for(int j = 0; j < N; j++) d[i][j] = min(d[i][j], d[i][k] + d[k][j]);
      }
    }

    for(int i = 0; i < N; i++){
      for(int j = 0; j < N; j++){
        //cout << d[i][j] << " ";

        if(d[i][j] != INF){
          ans = max(ans, d[i][j] + 1);
        }
      }
      //cout << endl;
    }
  }
  else {
    ans = -1;
  }

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


Measured memory_bytes: 512
#include <cstdio>
#include <cstdlib>
#include <iostream>
#include <fstream>
#include <sstream>
#include <set>
#include <map>
#include <vector>
#include <list>
#include <algorithm>
#include <cstring>
#include <cmath>
#include <string>
#include <stack>
#include <queue>
#include <bitset>     //UWAGA - w czasie kompilacji musi byc znany rozmiar wektora - nie mozna go zmienic
#include <cassert>
#include <iomanip>        //do setprecision
#include <ctime>
#include <complex>
using namespace std;

#define FOR(i,b,e) for(int i=(b);i<(e);++i)
#define FORQ(i,b,e) for(int i=(b);i<=(e);++i)
#define FORD(i,b,e) for(int i=(b)-1;i>=(e);--i)
#define REP(x, n) for(int x = 0; x < (n); ++x)

#define ST first
#define ND second
#define PB push_back
#define PF push_front
#define MP make_pair
#define LL long long
#define ULL unsigned LL
#define LD long double
#define pii pair<int,int>
#define pll pair<LL,LL>
#define vi vector<int>
#define vl vector<LL>
#define vii vector<vi>
#define vll vector<vl>

const double pi = 3.14159265358979323846264;
const int mod=1000000007;

int main(){
	LL x,y,a,b,c;
    cin>>x>>y>>a>>b>>c;
    vi aa(a);
    vi bb(b);
    vi cc(c);
    FOR(i,0,a){
        cin>>aa[i];
    }
    FOR(i,0,b){
        cin>>bb[i];
    }
    FOR(i,0,c){
        cin>>cc[i];
    }
    sort(aa.begin(),aa.end());
    sort(bb.begin(),bb.end());
    sort(cc.begin(),cc.end());
    priority_queue<LL> pq;
    FOR(i,0,x){
        pq.push(aa[a-1-i]);
    }
    FOR(i,0,y){
        pq.push(bb[b-1-i]);
    }
    FOR(i,0,c){
        pq.push(cc[i]);
    }
    LL ans=0;
    FOR(i,0,x+y){
        LL t=pq.top();
        pq.pop();
        ans+=t;
    }
    cout<<ans<<endl;



}


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

int main(){
  int n;
  cin >> n;
  vector<int> x(n);
  rep(i,n) cin >> x[i];
  
  int ans = 1001000010;
  for(int p = 1; p <= 100; ++p){
  	int ans2 = 0;
  	rep(i,n){
  		ans2 += (x[i] - p)*(x[i] - p);
  	}
  	ans = min(ans, ans2);
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 256
//in the name of god
#include <bits/stdc++.h>
using namespace std;
#define MAX_N (int)1e5+20
#define INF 1e9+20
#define pb push_back
#define F first
#define S second
typedef long long LL;
typedef pair<int,int> pii;
const int delta=(int)1e9+7;
int n,m,s,ans; double x;
int main(){
	ios_base::sync_with_stdio(false); cin.tie(0);
	cin>>n>>m; s=100*n+1800*m; s*=(1<<m); cout<<s;
	return cout<<endl,0;
}

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

bool judge(vector<int>& v)
{	
	int d = v[1] - v[0];
	for(int i = 1; i < v.size() - 1; ++i){
		if(v[i + 1] - v[i] != d){
			
			return false;
		}
	}
	return true;
} 

int main()
{
	int n;
	while(cin >> n, n){
		vector<int> v(n + 1);
		for(int i = 0; i < n + 1; ++i){
			cin >> v[i];
		}
		
		for(int i = 0; i < n + 1; ++i){
			vector<int> w;
			w.reserve(n);
			for(int j = 0; j < n + 1; ++j){
				if(j == i)continue;
				w.push_back(v[j]);
			}
			if(judge(w)){
				cout << v[i] << endl;
				break;
			}
		}
	}
}

Measured memory_bytes: 1200
#include <bits/stdc++.h>
using namespace std;
#define TRACE(x) x
#define WATCH(x) TRACE( cout << #x" = " << x << endl)
#define PRINT(x) TRACE(printf(x))
#define WATCHR(a, b) TRACE( for(auto c = a; c != b;) cout << *(c++) << " "; cout << endl)
#define WATCHC(V) TRACE({cout << #V" = "; WATCHR(V.begin(), V.end()); } )
#define rep(i, a, b) for(int i = a; i < (b); ++i)
#define trav(a, x) for(auto& a : x)
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define sz(x) (int)(x).size()
#define mp make_pair
#define st first
#define nd second

using ll = long long;
using pii = pair<int, int>;
using vi = vector<int>;
using ld = long double;
using pll = pair<ll, ll>;
using vll = vector<ll>;
using pll = pair<ll, ll>;

void buff() { ios::sync_with_stdio( false ); cin.tie( nullptr ); }

constexpr ll MOD = 1e9 + 7;

inline ll pow_mod( ll a, ll b, ll mod = MOD) {
    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;
}
// End of template code!
int main() 
{
    buff();
    long long n, k;
    cin >> n >> k;
    vector<ll> go(n);
    for(auto& x : go) {
        cin >> x;
        --x;
    }
    
    if(go[0] == 0) {
        cout << 1ll << '\n';
        return 0;
    }
    ++k;

    vector<ll> visto(n, -1);
    vector<ll> ord;
    
    long long cur = 0ll;
    long long tempo = 0ll;
    while(visto[cur] == -1) {
        ord.push_back(cur);
        visto[cur] = tempo++;
        cur = go[cur];
    }
    // cur vai ser o primeiro cara do ciclo
    long long inicio_ciclo = visto[cur];
    
    vector<ll> pref, cyc;
    for(int i = 0; i < inicio_ciclo; ++i) pref.push_back(ord[i] + 1);
    for(int i = inicio_ciclo; i < sz(ord); ++i) cyc.push_back(ord[i] + 1);
    
    if(k <= sz(pref)) {
        cout << pref[k - 1] << '\n';
    }
    else {
        k -= sz(pref);
        k %= sz(cyc);
        k = (k - 1ll + sz(cyc)) % sz(cyc); 
        cout << cyc[k] << '\n';
    }
    return 0;
}



Measured memory_bytes: 10968
//MADE BY Y_is_sunshine;
//#include <bits/stdc++.h>
//#include <memory.h>
#include <algorithm>
#include <iostream>
#include <cstdlib>
#include <cstring>
#include <sstream>
#include <cstdio>
#include <vector>
#include <string>
#include <cmath>
#include <queue>
#include <stack>
#include <map>
#include <set>

#define INF 0x3f3f3f3f
#define MAXN 100005

typedef long long ll;

const ll mod = 1e9 + 7;
const double PI = acos(-1);

using namespace std;

int N, M, K;

int main(void)
{
#ifdef Sunshine
	freopen("data.txt", "r", stdin);
#endif

	ios_base::sync_with_stdio(false);
	cin.tie(NULL);

	ll a, b, c;
	cin >> a >> b >> c;
	
	if(c >= a){
		c -= a;
		a = 0;
		b -= c;
		cout << a << ' ' << max(0ll, b);
	}
	else{
		cout << a - c << ' ' << b;
	}





	return 0;
}



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

int main()
{
    int n, a, b, c;

    while( cin >> n )
    {
        if( n == 0 )
            break;

        int r1 = 0, r2 = 0;
        for( int i = 0; i < n; i++ )
        {
            cin >> a >> b >> c;
            if( b + c > r2 )
            {
                r1 = a;
                r2 = b + c;
            }
        }
        cout << r1 << " " << r2 << endl;
    }
    return 0;
}


Measured memory_bytes: 3104
#include<bits/stdc++.h>
using namespace std;
int main(){
  int N;
  cin>>N;
  vector<int> A(N);
  for(int i=1;i<N;i++){
    int a;
    cin>>a;
    A[a-1]++;
  }
  for(int &i:A)
    cout<<i<<endl;
}

Measured memory_bytes: 3996
#include <iostream>
#include <iomanip>
#include <utility>
#include <cmath>
#include <random>
#include <vector>
#include <map>
#include <set>
#include <deque>
#include <queue>
#include <stack>
#include <string>
#include <algorithm>
using namespace std;

#define rep(i,n) for(int i = 0; i<n; ++i)
#define REP(i,n) for(int i = 1; i<=n; ++i)
#define all(x) begin(x),end(x)
#define show(obj) {for(auto x:obj)cout<<x<<' ';cout<<endl;}
#define line "----------"
typedef long long ll;
typedef pair<int,int> P;
const int inf = 1001001000;
const ll INF = 1LL<<60;
const ll MOD = 1e9 + 7;

int main(){
	int N; cin >> N;
	vector<ll> A(N);
	rep(i,N)cin>>A[i];
	vector<int> act(N, 0);
	//1->buy 2->sell
	act[0] = 1;
	int lt_act = 0;
	for(int i = 1; i < N; ++i){
		if(A[i] < A[i-1]){
			act[i-1] = 2;
			act[i] = 1;
			lt_act = i;
		}
	}
	// cout <<lt_act << endl;
	if(A[lt_act] < A[N-1]){
		act[N-1] = 2;
	}else{
		act[lt_act] = 0;
	}
	// show(act);
	ll money = 1000;
	ll kabu = 0;
	rep(i,N){
		if(act[i] == 1){
			kabu += money/A[i];
			money %= A[i];
		}else if(act[i] == 2){
			money += kabu*A[i];
			kabu = 0;
		}
		// printf("[money:kabu] -> [%lld, %lld]\n", money, kabu);
	}
	cout << money << endl;
	return 0;
}

Measured memory_bytes: 3628
Prefix = 'YAKI'

def main(argv)
  s = gets.chomp

  if s.size < Prefix.size then
    puts 'No'
    return
  end

  flag = true
  Prefix.size.times do |i|
    flag = false if s[i] != Prefix[i]
  end
  puts (flag ? 'Yes': 'No')
end

if self.to_s == 'main' then
  main(ARGV)
end

Measured memory_bytes: 1788
#include<bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < n; ++i)
#define rep2(i,s,n) for (int i = s; i < n; ++i)
#define all(a) a.begin(),a.end()
using namespace std;
using ll = long long;
using P = pair<int,int>;

int main() {
    int n;
    cin >> n;
    vector<int> a(n);
    rep(i,n) cin >> a[i];
    sort(all(a),greater<int>());
    int ali = 0,bob = 0;
    int now = 0;
    rep(i,n) {
        if(now == 0) {
            ali += a[i];
        } else {
            bob += a[i];
        }
        now = 1-now;
    }
    cout << ali-bob << endl;
}

Measured memory_bytes: 256
#include<iostream>
#include<string>

using namespace std;

int main(){
 string s;
  cin >> s;
  
  bool res=false;
  for(int i=0;i<s.length()-1;i++){
   if(s[i]!='C') continue;
    for(int j=i+1;j<s.length();j++){
     if(s[j]=='F'){
       res=true;
       break;
     }
    }
  }

  if(res) cout << "Yes" << endl;
  else cout << "No" << endl;
}

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

int main(){
	int n;
	while(scanf("%d",&n), n != -1){
		if(n == 0){
			printf("0\n");
			continue;
		}
		stack<int> st = stack<int>();
		while(n != 0){
			int r = n % 4;
			n /= 4;
			st.push(r);
		}
		while(!st.empty()){
			printf("%d",st.top());
			st.pop();
		}
		printf("\n");
	}
	return 0;
}



Measured memory_bytes: 2624
let content = '';
process.stdin.resume();
process.stdin.setEncoding('utf8');
process.stdin.on('data', buf => {
  content += buf;
});

process.stdin.on('end', () => {
  const chars = content
    .trim()
    .split('')
    .map(s => s.toLowerCase())
    .filter(isLowerCase)

  const count = chars.reduce((prev, cur) => {
    return Object.assign({}, prev, {
      [cur]: prev[cur] === undefined ? 1 : prev[cur] + 1
    });
  }, {});
  
  for (let i = 97; i <= 122; i++) {
    const char = String.fromCharCode(i);
    console.log(`${char} : ${count[char] || 0}`);
  }
});

const isLowerCase = charCode => charCode >= 'a' && charCode <= 'z';


Measured memory_bytes: 17556
#チェスボードの描画

while True:

    H, W = map(int, input().split())
    if H == 0 and W == 0:
        break
    for i in range(H):
        for k in range(W):
            if (i+k) % 2 == 0:
                print('#', end='')
            else:
                print('.', end='')
        print('')
    print('')


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

int main() {
  string S; cin >>S;
  int MojiNagasa=S.size();
  bool flag=true;
  if (S[0]!='A') flag=false;
  int count=0;
  rep(i,1,MojiNagasa) {
    if (isupper(S[i])) {
      if (i==1 || i==MojiNagasa-1 || S[i]!='C') flag=false;
      count++;
    }
  }
  if (count!=1) flag=false;
  cout <<(flag ? "AC":"WA") <<endl;
}


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

#define rep(n) for(int i=0;i<n;i++)
#define repp(j, n) for(int j=0;j<n;j++)
#define reppp(i, m, n) for(int i=m;i<n;i++)
#define all(c) c.begin(), c.end()
#define rall(c) c.rbegin(), c.rend()

using namespace std;

typedef long long ll;
typedef pair<ll, ll> Pll;
typedef pair<int, int> Pii;
struct edge{int from, to; ll cost;};

char ans[100][50];
int w, b, ww, bb;

int main(){
    std::ios::sync_with_stdio(0); cin.tie(0);
    cin >> w >> b;

    ww = 1;
    bb = 1;

    rep(50){
        if(i % 2 == 0 || i >= 40){
            repp(j, 50) ans[i][j] = '#';
        }else{
            repp(j, 50){
                if((j % 2) != 0 && ww < w){
                    ans[i][j] = '.';
                    ww++;
                }
                else ans[i][j] = '#';
            }
        }
    }
    rep(50){
        if(i % 2 == 0 || i >= 40){
            repp(j, 50) ans[i+50][j] = '.';
        }else{
            repp(j, 50){
                if((j % 2) != 0 && bb < b){
                    ans[i+50][j] = '#';
                    bb++;
                }
                else ans[i+50][j] = '.';
            }
        }
    }
    cout << 100 << " " << 50 << endl;
    rep(100){
        repp(j, 50) cout << ans[i][j];
        cout << endl;
    }
}


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

int main() {
  long long  A , B , K  ; 
  cin >> A >> B >> K ;



  if( A >= K){
    cout << A-K << " " << B << endl ; 
  }
  else if( K >= A && K-A <= B ){
    cout << 0 << " " << B - (K - A) << endl ;
  }
  else {
    cout << 0 << " " << 0 << endl ;
  }

  
  

  
}

Measured memory_bytes: 3600
import sys
import numpy as np
import numba
from numba import njit, b1, i4, i8, f8

read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

@njit((i8, i8[:, :]), cache=True)
def scc(N, G):
    ind = np.searchsorted(G[:, 0], np.arange(N + 2))
    preorder = np.empty(N, np.int64)
    n = 0
    st = np.empty(N, np.int64)
    p = 0
    nxt = np.full(N + 1, -1, np.int64)

    for root in range(N):
        if nxt[root] != -1:
            continue
        st[p], p = root, p + 1
        while p:
            v = st[p - 1]
            if nxt[v] == -1:
                nxt[v] = ind[v]
            if nxt[v] == ind[v + 1]:
                preorder[n], n = v, n + 1
                p -= 1
                continue
            w = G[nxt[v], 1]
            nxt[v] += 1
            if nxt[w] != -1:
                continue
            st[p], p = w, p + 1
    Grev = G[:, :2][:, ::-1].copy()
    Grev = Grev[np.argsort(Grev[:, 0])]
    ind = np.searchsorted(Grev[:, 0], np.arange(N + 2))
    comp = np.zeros(N, np.int64)
    n_comp = 0
    for root in preorder[::-1]:
        if comp[root]:
            continue
        n_comp += 1
        comp[root] = n_comp
        st[p], p = root, p + 1
        while p:
            v, p = st[p - 1], p - 1
            for i in range(ind[v], ind[v + 1]):
                w = Grev[i, 1]
                if comp[w]:
                    continue
                comp[w] = n_comp
                st[p], p = w, p + 1
    return n_comp, comp

def main(N, G):
    n_comp, comp = scc(N, G)
    ans = np.empty((N, 2), np.int64)
    ans[:, 0] = np.arange(N)
    ans[:, 1] = comp
    ans = ans[np.argsort(ans[:, 1])]
    idx = np.searchsorted(ans[:, 1], np.arange(n_comp + 2))
    print(n_comp)
    for c in range(1, n_comp + 1):
        V = ans[idx[c]:idx[c + 1], 0]
        print(len(V), ' '.join(map(str, V)))

N, M = map(int, readline().split())
AB = np.array(read().split(), np.int64).reshape(-1, 2)

AB = AB[np.argsort(AB[:, 0])]

main(N, AB)

Measured memory_bytes: 170200
N = int(input())
A = []
while N>0:
    if N==1:
        A.append(1)
        break
    if N==2:
        A.append(2)
        break
    high = N
    low = 0
    while True:
        mid = (high+low)//2
        if N<=((mid-1)*mid)//2:
            high = mid
        elif N>(mid*(mid+1))//2:
            low = mid
        else:
            break
    A.append(mid)
    N -= mid
for i in range(len(A)):
    print(A[i])
    

Measured memory_bytes: 3444
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for (int i = 0;i < (n);i++)
using ll = long long;
const ll MOD=1000000007;
const double pi=acos(-1);





int main() 
{
  ll N; cin>>N;
  vector<ll> A(N);
  vector<ll> B(N);
  rep(i,N)
  {
    cin>>A.at(i)>>B.at(i);
  }
  reverse(A.begin(),A.end());
  reverse(B.begin(),B.end());
  
  ll ans=0;
  rep(i,N)
  {
    ll amari=(A.at(i)+ans)%B.at(i);
    if(amari!=0) {ans+=B.at(i)-amari;}
  }
  cout<<ans<<endl;
  return 0;
}


Measured memory_bytes: 1792
N, M = gets.split.map(&:to_i)

as = Hash.new(0)
N.times do |i|
  gets.split.map(&:to_i)[1..-1].each do |a|
    as[a.to_s] += 1
  end
end

ans = 0
as.each do |k ,v|
  ans += 1 if v == N
end
puts ans


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

static const int MOD = 1000000007;
using ll = long long;
using u32 = unsigned;
using namespace std;

template<class T>
constexpr T INF = ::numeric_limits<T>::max() / 32 * 15 + 208;

int main() {
    int n;
    cin >> n;
    if(n == 1){
        cout << "Hello World\n";
        return 0;
    }else {
        int a, b;
        cin >> a >> b;
        cout << a+b << "\n";
    }
    return 0;
}


Measured memory_bytes: 764
import java.util.Scanner;

/**
 * TITLE : Comparing Strings
 * URL : https://atcoder.jp/contests/abc152/tasks/abc152_b
 */
public class Main {

    public static void main(String args[]) {
        Scanner sc = new Scanner(System.in);
        int a = sc.nextInt();
        int b = sc.nextInt();
        int answer;

        if (a < b) {
            answer = a;
            for (int i = 1; i < b; i++) {
                answer = answer * 10 + a;
            }
        } else {
            answer = b;
            for (int i = 1; i < a; i++) {
                answer = answer * 10 + b;
            }
        }

        System.out.println(answer);
        sc.close();
    }
}

Measured memory_bytes: 21332
#include <iostream>
#include <vector>
#include <algorithm>

using namespace std;

int main(void){
  int N,tmp,lenA,lenB;
  vector<int> A;
  bool ans=true;

  cin >> N;
  for(int i=0;i<N;i++){
    cin >> tmp;
    A.push_back(tmp);
  }

  lenA = A.size();

  sort(A.begin(), A.end());
  A.erase(unique(A.begin(), A.end()), A.end());
  lenB = A.size();

  if(lenA != lenB){
    ans = false;
  }

  // for(int i=0;i<N-1;i++){
  //   for(int j=i+1;j<N;j++){
  //     if(A[i]==A[j]){
  //       ans = false;
  //       i=N;
  //       break;
  //     }
  //   }
  // }

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

  return 0;
}


Measured memory_bytes: 1400
#include<bits/stdc++.h>
//#pragma GCC optimize("trapv")
#define I inline void 

using namespace std ; 
using ll = long long ; 
using ld = long double ; 
	
const int N = 2e5 + 7 , mod = 1e9 + 7 ; 

// How interesting!
	
int n , m; 

ll a[N] ; 
	
int main(){	
	ios_base::sync_with_stdio(0) ; 
	cin.tie(0) ; 
	//freopen("in.in" , "r" ,stdin) ; 
	cin >> n ; 
	ll sum = 0 ; 
	for(int i =0 ;i < n;i++){
		cin >>a[i] ; 
		sum+=a[i] ;
	}
	ll suml = 0 ; 
	ll ans = 1e18 ; 
	for(int i = 0 ;i < n;i++){
		suml+=a[i] ; 
		sum-=a[i] ; 
		ans = min(ans , abs(suml - sum) ) ; 
	}
	cout<< ans ; 
	return 0 ; 
	
}

Measured memory_bytes: 5176
#include <bits/stdc++.h>
using namespace std;
int main () {
  long N;
  cin >> N;
  if(N % 2 == 1){
    cout << 0 << endl;
    return 0;
  }
  N /= 2;
  long count = 0,a = 1000000000000000000, ans = 0;
  a = 5;
  for(int i = 0; i < 26; i++){
    ans += N / a;
    a *= 5;
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 256
import sys
sys.setrecursionlimit(500000)
MOD = 10**9+7

def input():
    return sys.stdin.readline()[:-1]

def mi():
    return map(int, input().split())

def ii():
    return int(input())

def i2(n):
    tmp = [list(mi()) for i in range(n)]
    return [list(i) for i in zip(*tmp)]


def main():
    N = ii()
    a = list(mi())
    cnt = 0
    for i in range(N):
        if i%2 == 0 and a[i]%2 == 1:
            cnt += 1
    print(cnt)

if __name__ == '__main__':
    main()


Measured memory_bytes: 61728
#include<bits/stdc++.h>
#include<iostream>
#include<cstdio>
#include<vector>
#include<string>
#include<algorithm>
#include<map>
using namespace std;
#define rep(i,x) for(int i = 0; i < x; i++)
#define pb push_back
#define mp make_pair
typedef long long ll;
typedef long double ld;
typedef pair<int,int> P;
typedef pair<ll,ll> Pll;
typedef vector<int> vi;
typedef vector<vector<int>> vvi;
typedef vector<vector<vector<int>>> vvvi;
const ll N = 1e9+7;
const int n_max = 1e5+10;
int main(){
    string s; cin >> s;
    int len = s.size();
    vector<int> a(len,0);
    int rt = 1,lt = 0,chg = 0,sum = 1;
    rep(i,len-1){
        if(s[i] == 'R' && s[i+1] == 'R'){
            rt++;
            sum++;
        }
        else if(s[i] == 'R' && s[i+1] == 'L'){
            lt++;
            sum++;
            chg = i;
        }
        else if(s[i] == 'L' && s[i+1] == 'L'){
            lt++;
            sum++;
        }
        else if(s[i] == 'L' && s[i+1] == 'R'){
            // cout << rt  << ' ' << lt  << ' ' << sum << endl;
            if(!(sum%2)){
                a[chg] = sum/2;
                a[chg+1] = sum/2;
            }
            else if(lt > rt){
                int temp = lt-rt;
                if((rt + temp)%2){
                    a[chg] = sum/2;
                    a[chg+1] = sum/2+1;
                }
                else{
                    a[chg] = sum/2+1;
                    a[chg+1] = sum/2;
                }
            }
            else if(lt < rt){
                int temp = rt-lt;
                if((lt + temp)%2 == 0){
                    a[chg] = sum/2;
                    a[chg+1] = sum/2+1;
                }
                else{
                    a[chg] = sum/2+1;
                    a[chg+1] = sum/2;
                }
            }
            rt = 1;lt = 0;sum = 1;
        }

        if(i == len-2){
            // cout << rt  << ' ' << lt  << ' ' << sum << endl;
            if(!(sum%2)){
                a[chg] = sum/2;
                a[chg+1] = sum/2;
            }
            else if(lt > rt){
                int temp = lt-rt;
                if((rt + temp)%2){
                    a[chg] = sum/2;
                    a[chg+1] = sum/2+1;
                }
                else{
                    a[chg] = sum/2+1;
                    a[chg+1] = sum/2;
                }
            }
            else if(lt < rt){
                int temp = rt-lt;
                if((lt + temp)%2 == 0){
                    a[chg] = sum/2;
                    a[chg+1] = sum/2+1;
                }
                else{
                    a[chg] = sum/2+1;
                    a[chg+1] = sum/2;
                }
            }
        }
    }
    rep(i,len){
        cout << a[i] << " ";
    }
    cout << endl;
    return 0;

}

Measured memory_bytes: 1024
n,x = map(int, input().split())
x_list = list(map(int, input().split()))

#最大公約数
def gcd(a,b):
    while b!=0:
        a,b = b,a%b
    return a

res = 0
for i in x_list:
    res = gcd(res, abs(x-i))

print(res)

Measured memory_bytes: 14224
import java.util.Scanner;

public class Main {
	public static void main(String args[]){
		Scanner scanner = new Scanner(System.in);
		
		
		int n = scanner.nextInt();
		long arr[] = new long[n];
		long a = scanner.nextLong();
		long count = 0;
		for(int i = 0 ;i<n ; i++){
			arr[i] = scanner.nextLong();
		}
		if(arr[0] > a){
			count += arr[0]-a;
			arr[0] = a;
		}
		for(int i = 1 ; i<n ; i++){
			if( arr[i]+arr[i-1] > a){
				count += arr[i-1] + arr[i] - a;
				arr[i] = a-arr[i-1];
			}
		}

		System.out.println(count);
	}
}

Measured memory_bytes: 60032
#include <bits/stdc++.h>
#define rep(i,n) for (int i=0; i<(n); i++)
#define repi(i,a,b) for (int i=a;i<(b);i++)
#define SIZE_OF_ARRAY(array) (sizeof(array)/sizeof(array[0]))
using namespace std;
typedef long long ll;
  
  int main(void){
    cin.tie(0); //cin高速化
    ios::sync_with_stdio(false); //cin高速化
	int n;
    cin >> n;
    cout << n/3 << endl;
    return 0;
  } 

Measured memory_bytes: 256
#include<cstdio>
#include<cstring>
#include<algorithm>
#define rep(i,l,r) for (int i=(l); i<=(r); i++)
#define For(i,x) for (int i=h[x],k; i; i=nxt[i])
typedef long long ll;
using namespace std;

const int N=5010;
int n,cnt,u,v,ans,a[N],g[N],sz[N],h[N],to[N<<1],nxt[N<<1];
ll sm[N],f[N][N];
void add(int u,int v){ to[++cnt]=v; nxt[cnt]=h[u]; h[u]=cnt; }

void dfs(int x,int fa){
	sm[x]=a[x];
	For(i,x) if ((k=to[i])!=fa) dfs(k,x),sm[x]+=sm[k];
	if (a[x]>0){
		g[x]=0;
		For(i,x) if ((k=to[i])!=fa){
			int s=g[k];
			rep(j,0,n) if (f[k][j]<0){ s=min(s,j+1); break; }
			g[x]+=s;
		}
	}
	f[x][0]=a[x]; sz[x]=1;
	For(i,x) if ((k=to[i])!=fa){
		for (int j=sz[x]+sz[k]; ~j; j--){
			f[x][j]+=sm[k];
			if (j-g[k]-1>=0) f[x][j]=min(f[x][j],f[x][j-g[k]-1]);
			rep(s,max(0,j-sz[x]),min(j,sz[k])){
				if (s) f[x][j]=min(f[x][j],f[x][j-s]+f[k][s]);
				if (s<j && f[k][s]<0) f[x][j]=min(f[x][j],f[x][j-s-1]);
			}
		}
		sz[x]+=sz[k];
	}
}

int main(){
	scanf("%d",&n);
	rep(i,1,n) scanf("%d",&a[i]);
	rep(i,2,n) scanf("%d%d",&u,&v),add(u,v),add(v,u);
	memset(g,42,sizeof(g)); memset(f,42,sizeof(f));
	dfs(1,1); ans=g[1];
	rep(i,0,n) if (f[1][i]<0){ ans=min(ans,i); break; }
	printf("%d\n",ans);
	return 0;
}

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

int H, W;
const int r = 1001, mod = 1e9 + 7;
char grid[r][r];
int dp[r][r];

bool valid(int i, int j) {
    return (i > -1 && i < H && j > -1 && j < W && grid[i][j] != '#');
}

long long dfs(int i, int j) {
    if (!valid(i, j))
        return 0;
    if (i == H - 1 && j == W - 1)
        return 1;
    if (dp[i][j] != -1)
        return dp[i][j];
    long long cnt = 0;
    cnt += dfs(i + 1, j);
    cnt += dfs(i, j + 1);
    if (cnt >= mod)
        cnt -= mod;
    return dp[i][j] = cnt;
}

int main() {
    memset(dp, -1, sizeof dp);
    cin >> H >> W;
    for (int i = 0; i < H; i++)
        for (int j = 0; j < W; j++)
            cin >> grid[i][j];
    cout << dfs(0, 0) << '\n';
    return 0;
}


Measured memory_bytes: 5248
N = int(input())
ac = 0
wa = 0
tle = 0
re = 0
for i in range(N):
  S = input()
  if S == 'AC':
    ac += 1
  elif S == 'WA':
    wa += 1
  elif S == 'TLE':
    tle += 1
  elif S == 'RE':
    re += 1
  else:
    break

print('AC x',ac)
print('WA x',wa)
print('TLE x',tle)
print('RE x',re)

Measured memory_bytes: 9200
#include <iostream>
#include <vector>
#include <string>
#include <numeric>
#include <tuple>
#include <algorithm>
#include <array>
using namespace std;
using ll = long long;
#define rep(i,n) for(decltype(n) i=0; i<n; ++i)
#define revrep(i,n) for(decltype(n) i=n-1; n>=0; --i)
inline constexpr ll Inf = (1ULL << 62) -1;

template <class T>
void updatemax(T& a, T b) { if (b > a) a = b; }

int main() {
    ll ans=0, N;
    cin >> N;
    vector<ll> a(N);
    rep(i,N) cin >> a[i];

    ll prev = a[0];
    for (int i=1; i<N; ++i) {
        if (prev > a[i]) {
            ans += prev-a[i];
        } else {
            prev = a[i];
        }
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 4400
#include<bits/stdc++.h>
#define ll long long
#define int long long
#define M 1000000007
#define sz(c) c.size()
#define fr first
#define sc second
#define pb push_back
#define sz(c) c.size()
#define ppb  pop_back
#define mp make_pair
#define all(a)      (a).begin(),(a).end()
#define rep(i,a,n)   for( int i=a ; i<n ; i++)
#define what_is(x)  cout << #x << " is " << x << endl;
#define U 1000000007
#define N 100005
using namespace std;
signed main()
{
  ios_base::sync_with_stdio(false);
  int a,b;
  cin>>a>>b;
  b=b*2;
  cout<<max((int)0,a-b);



}

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <string>
#include <cmath>
#include <cctype>
#include <cstdlib>
#include <stack>
#include <queue>
#include <vector>
#include <algorithm>
#include <list>
#include <map>
#include <set>
using namespace std;

int main() {
	string u, t,s;
	cin >> u >> t;
	s = u;
	int n = u.size(), m = t.size();
	int k=0;
	bool g = 0;
	for (int i = n-m; i >=0;i--) {
		bool f = 1;
		for (int j = 0; j < m; j++) {
			if (u[i + j] != t[j] && u[i+j]!='?') f = 0;
		}
		if (f) {
			k = i;
			g = 1;
			break;
		}
	}
	if (g) {
		for (int i = 0; i < n; i++) {
			if (i >= k && i <= k + m - 1) s[i] = t[i - k];
			else if (u[i] == '?') s[i] = 'a';
		}
		cout << s << endl;
	}
	else cout << "UNRESTORABLE" << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main(){
  int N, M;
  cin >> N >> M;
  vector<vector<int>> E(N);
  for (int i = 0; i < M; i++){
    int A, B;
    cin >> A >> B;
    A--;
    B--;
    E[A].push_back(B);
    E[B].push_back(A);
  }
  int ans = 0;
  vector<bool> used(N, false);
  for (int i = 0; i < N; i++){
    if (!used[i]){
      used[i] = true;
      int cnt = 1;
      queue<int> Q;
      Q.push(i);
      while (!Q.empty()){
        int v = Q.front();
        Q.pop();
        for (int w : E[v]){
          if (!used[w]){
            used[w] = true;
            cnt++;
            Q.push(w);
          }
        }
      }
      ans = max(ans, cnt);
    }
  }
  cout << ans << endl;
}

Measured memory_bytes: 14864