akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#define FOR(i,a,b) for (int i = (a); i < (b); ++i)
#define rep(i,n) for (int i = (0); i < (n); ++i)
#define rng(x) (x).begin(),(x).end()
#define rrng(x) (x).rbegin(),(x).rend()
#define show(x) cout << #x << " = " << (x) << endl;
#define show2(x,y) cout << #x << " = " << (x) << ", " << #y << " = " << (y) << endl;
#define show3(x,y,z) cout << #x << " = " << (x) << ", " << #y << " = " << (y) <<  ", " << #z << " = " << (z) << endl;
#define fi first
#define se second
#define pb push_back
#define eb emplace_back
#define sz(x) (int)(x).size()
#define bn(x) ((1<<x)-1)
#define dup(x,y) (((x)+(y)-1)/(y))
#define uni(x) x.erase(unique(rng(x)),x.end())
#define SP << " " <<
using namespace std;
using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vll = vector<ll>;
using pii = pair<int, int>;
using tiii = tuple<int, int, int>;
const int mod = 1000000007;
const double EPS = 1e-9;
const int INF = 1<<30;
const ll INFLL = 1LL<<60;
//cout << fixed << setprecision(10);

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

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

  ll ans;
  if (a%2 == b%2) ans = abs(b-a)/2;
  else ans = min(a-1,n-b) + 1 + (b-a-1)/2;

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

Measured memory_bytes: 256
program AAA
!
      implicit none
      character(len=1002) :: S
      integer :: N
      integer :: i
!
      read(*,*) S
      N = len_trim(S)
      if(S(N:N) == 's') then  
        S(N+1:N+2) = 'es'
      else
        S(N+1:N+1) = 's'
      end if
!
      write(*,*) S
!
      end program AAA

Measured memory_bytes: 2856
#pragma comment(linker, "/stack:247474112")
#pragma GCC optimize("Ofast")
#include"bits/stdc++.h"
using namespace std;
#define IOS ios::sync_with_stdio(0), cin.tie(0), cout.tie(0)
#define int long long
#define ends ' '
#define endl '\n'
#define pb emplace_back
#define x first
#define y second
#define pii pair<int, int>
#define sz(x) (int)(x).size()

map<string, int> mp;

int32_t main()
{
	IOS;

	int n;
  	cin >> n;
  	int ans = 0;
  
  	while(n--)
    {
  		string s;
      	cin >> s;
      	sort(s.begin(), s.end());
      	ans += mp[s];
      	mp[s]++;
    }
  	cout << ans;      
	return 0;
}

Measured memory_bytes: 11264
main=do
 n<-readLn
 csf<-map(map read.words).lines<$>getContents
 putStr$unlines$map show[solve 0$drop i csf|i<-[0..n-1]]
solve now[]=now
solve now([c,s,f]:csf)=solve(c+max s((now+f-1)`div`f*f))csf

Measured memory_bytes: 1532
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define X first
#define Y second
#define pb push_back
#define mp make_pair

const int maxn = 1e5 + 100 , maxc = 115, mod = 1e9 + 7, inf = 1e9+10;

ll n, a, b;
ll num (ll a)
{
	ll res = 0;
	while (a)
	{
		res += a % 10;
		a /= 10;
	}
	return res;
}

int32_t main()
{
	ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
	cin >> n ;
	cout << (n % num(n) ? "No" : "Yes") << endl;
	return 0;
}

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

using namespace std;

int main()
{
    int n ;
    cin>>n ;
    double t , a ;
    cin>>t>>a ;
    double MIN = 1e9 ;
    int idx ;
    for(int i = 0 ; i < n ; ++i)
    {
        double x ;
        cin>>x ;
        double temp = t- x * 0.006 ;
        if(temp > a)
            temp = temp - a ;
        else
            temp = a - temp ;
        if(temp < MIN)
            MIN = temp , idx = i+1 ;
    }
    return cout<<idx , 0 ;
}


Measured memory_bytes: 256
def warshall_floyd(d):
    for k in range(n):
        for i in range(n):
            for j in range(n):
                if d[i][j] > d[i][k] + d[k][j]: 
                    d[i][j] = d[i][k] + d[k][j]
    return d

n,w = map(int,input().split())
INF = 10**5
d = [[INF for i in range(n)] for i in range(n)]
e_list = []
for i in range(w):
    x,y,z = map(int,input().split())
    x -= 1
    y -= 1
    d[x][y] = z
    d[y][x] = z
    e_list.append([x,y,z])
for i in range(n):
    d[i][i] = 0

warshall_floyd(d)
ans = w
for x,y,z in e_list:
    ok = False
    for i in range(n):
        if d[i][x] + z == d[i][y]:
            ans -= 1
            break
print(ans)
    

Measured memory_bytes: 3436
#pragma comment(linker, "/stack:200000000")
#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#pragma GCC optimize("unroll-loops")
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define debug(x) cout << #x << " " << x << endl
#define fast ios_base::sync_with_stdio(false);
#define iscan1(x) scanf("%d",&x);
#define lscan1(x) scanf("%lld",&x);
#define iscan2(x,y) scanf("d",&x,&y);
#define lscan2(x,y) scanf("lld",&x,&y);
#define csprint(x) printf("Case %d: ",x);
#define iprint(x) printf("%d",x);
#define lprint(x) printf("%lld",x);
#define pnl printf("\n");
#define pg printf(" ");
ll ara[200005],dp[200005],lastpos[200005];
ll mod = 1000000007;
int main()
{
    memset(lastpos,-1,sizeof lastpos);
    int n;
    cin >> n;
    int idx = 1;
    for(int i=1;i<=n;i++)
    {
        ll a;
        cin >> a;
        if(a==ara[idx])continue;
        ara[++idx] = a;
    }
    for(int i=1;i<=idx;i++)
    {
        if(lastpos[ara[i]]!=-1)
        {
            dp[i] = (dp[i-1]%mod+dp[lastpos[ara[i]]]%mod+1)%mod;
            lastpos[ara[i]] = i;
        }
        else
        {
            lastpos[ara[i]] = i;
            dp[i] = dp[i-1];
        }
    }
    cout << (dp[idx]+1)%mod <<endl;
}


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

typedef long long ll;
#define REP(i,n) for(int i=0,_n=(int)(n);i<_n;++i)
#define ALL(v) (v).begin(),(v).end()
#define CLR(t,v) memset(t,(v),sizeof(t))
template<class T1,class T2>ostream& operator<<(ostream& os,const pair<T1,T2>&a){return os<<"("<<a.first<<","<<a.second<< ")";}
template<class T>void pv(T a,T b){for(T i=a;i!=b;++i)cout<<(*i)<<" ";cout<<endl;}
template<class T>void chmin(T&a,const T&b){if(a>b)a=b;}
template<class T>void chmax(T&a,const T&b){if(a<b)a=b;}


int nextInt() { int x; scanf("%d", &x); return x;}
ll nextLong() { ll x; scanf("%lld", &x); return x;}

ll gcd(ll a, ll b) {
  if (b == 0)
    return a;
  else
    return gcd(b, a%b);
}

int vis[999];
bool naive(ll A, ll B, ll C, ll D) {
  if (max({A,B,C,D}) > 30) return false;
  CLR(vis, 0);
  ll x = A;
  for (;;) {
    if (x < B) return false;
    if (vis[x]) return true;
    vis[x] = true;
    x -= B;
    if (x <= C) x += D;
  }
}

bool solve(ll A, ll B, ll C, ll D) {
  if (A < B) return false;
  if (D < B) return false;
  if (C+1 >= B) return true;
  // A >= B
  // D >= B
  // C+1 < B

  ll a = A % B;
  ll g = gcd(B, D);
  ll ma = B - g + a % g;
  return !(C < ma);
}

int main2() {
  int T = nextInt();
  for (;T--;) {
    ll a = nextLong();
    ll b = nextLong();
    ll c = nextLong();
    ll d = nextLong();
    bool res = solve(a, b, c, d);
    // if (max({a, b, c, d}) <= 30) {
    //   bool res2 = naive(a, b, c, d);
    //   if (res != res2) {
    //     cout << "WA: " << res << " vs " << res2 << "     " << a << " " << b << " " << c << " " << d << endl;      }
    // }
    cout << (res ? "Yes":"No") << endl;
  }
  return 0;
}

int main() {
  for (;!cin.eof();cin>>ws)
    main2();
  return 0;
}


Measured memory_bytes: 256
#include<cstdio>
#include<cstring>
#include<vector>
#include<queue>
#include<algorithm>
#include<cmath>
#include<climits>
#include<string>
#include<set>
#include<map>
#include<iostream>
using namespace std;
#define rep(i,n) for(int i=0;i<((int)(n));i++)
#define reg(i,a,b) for(int i=((int)(a));i<=((int)(b));i++)
#define irep(i,n) for(int i=((int)(n))-1;i>=0;i--)
#define ireg(i,a,b) for(int i=((int)(b));i>=((int)(a));i--)
typedef long long int lli;
typedef pair<int,int> mp;
#define fir first
#define sec second
#define IINF INT_MAX
#define LINF LLONG_MAX
#define eprintf(...) fprintf(stderr,__VA_ARGS__)
#define pque(type) priority_queue<type,vector<type>,greater<type> >
#define memst(a,b) memset(a,b,sizeof(a))
#define iter(v,ite) for(auto ite=(v).begin();ite!=(v).end();ite++)
#define mimunum(v,x) distance((v).begin(),lower_bound((v).begin(),(v).end(),x))

lli d[505][505];
int gone[505][505];

lli ds[2][100005];

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

typedef pair<lli,pair<int,int> > mmp;
int main(void){
	for(;;){
		memset(ds,-1,sizeof(ds));
		lli R;
		scanf("%lld",&R);
		if(R==0)break;
		rep(k,2){
			int h,w,sy,sx;
			scanf("%d%d%d%d",&w,&h,&sx,&sy); sy--; sx--;
			rep(y,h)rep(x,w){
				scanf("%lld",&d[y][x]);
			}
			memset(gone,0,sizeof(gone));
			lli nc=0;
			int s=0;
			int ms=0;
			priority_queue<mmp,vector<mmp>,greater<mmp> > que;
			que.push(mmp(d[sy][sx],mp(sy,sx)));
			que.push(mmp(LINF,mp(-1,-1)));
			gone[sy][sx]=1;
			while(!que.empty()){
				mmp pa = que.top();
				que.pop();
				//printf("%lld\n",pa.fir);
				if(pa.fir > nc){
					reg(t,ms,s){
						ds[k][t]=nc;
						//printf("%d %d : %lld\n",k,t,nc);
					}
					//printf("%d : %d->%d : %lld\n",k,ms,s,nc);
					nc = pa.fir;
					ms = s+1;
				}
				s += 1;
				int y = pa.sec.fir,x = pa.sec.sec;
				if(y<0)break;
				rep(t,4){
					int ty=y+dy[t],tx = x+dx[t];
					if(ty<0 || ty>=h || tx<0 || tx>=w || gone[ty][tx])continue;
					gone[ty][tx]=1;
					que.push(mmp(d[ty][tx],mp(ty,tx)));
				}
			}
		}
		
		lli ans = LINF;
		reg(i,0,R){
			lli a=ds[0][i],b=ds[1][R-i];
			//printf("%d : %d %d\n",i,a,b);
			if(a<0 || b<0)continue;
			ans=min(ans,a+b);
		}
		printf("%lld\n",ans);
	}
	return 0;
}


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

int main() {
	int x, a, b;
	int l = 0, r = 0;
	cin >> x >> a >> b;
	l = abs(x - a);
	r = abs(x - b);
	if (l <= r) cout << "A" << endl;
	else cout << "B" << endl;
	return 0;
}

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

using namespace std;
typedef unsigned long long ull;
typedef long long ll;
typedef pair<ll, ll> pii;

#define REP(a,b,c) for(ll (a)=(b);(a)<(c);(a)++)
#define PER(a,b,c) for(ll (a)=(b);(a)>=(c);(a)--)

int main(){
    ll H, A;
    cin >> H >> A;
    REP(i,1,INT_MAX){
        H-=A;
        if(H<=0){
            cout << i << endl;
            break;
        }
    }
    return 0;
}


Measured memory_bytes: 256
#include <stdio.h>

int main(void)
{
	char mass[9];
	int i;
	
	while (scanf("%s", mass) != EOF){
	
		if (mass[0] == mass[1] && mass[1] == mass[2] && mass[0] !=  's'){
			if (mass[1] == 'o'){
				printf("o\n");
			}
			else if (mass[1] == 'x'){
				printf("x\n");
			}
		}
		else if (mass[3] == mass[4] && mass[4] == mass[5] && mass[3] !=  's'){
			if (mass[4] == 'o'){
				printf("o\n");
			}
			else if (mass[4] == 'x'){
				printf("x\n");
			}
		}
		else if (mass[6] == mass[7] && mass[7] == mass[8] && mass[6] !=  's'){
			if (mass[7] == 'o'){
				printf("o\n");
			}
			else if (mass[7] == 'x'){
				printf("x\n");
			}
		}
		else if (mass[0] == mass[3] && mass[3] == mass[6] && mass[0] !=  's'){
			if (mass[3] == 'o'){
				printf("o\n");
			}
			else if (mass[3] == 'x'){
				printf("x\n");
			}
		}
		else if (mass[1] == mass[4] && mass[4] == mass[7] && mass[1] !=  's'){
			if (mass[4] == 'o'){
				printf("o\n");
			}
			else if (mass[4] == 'x'){
				printf("x\n");
			}
		}
		else if (mass[2] == mass[5] && mass[5] == mass[8] && mass[2] !=  's'){
			if (mass[5] == 'o'){
				printf("o\n");
			}
			else if (mass[5] == 'x'){
				printf("x\n");
			}
		}
		else if (mass[0] == mass[4] && mass[4] == mass[8] && mass[0] !=  's'){
			if (mass[4] == 'o'){
				printf("o\n");
			}
			else if (mass[4] == 'x'){
				printf("x\n");
			}
		}
		else if (mass[2] == mass[4] && mass[4] == mass[6] && mass[2] !=  's'){
			if (mass[4] == 'o'){
				printf("o\n");
			}
			else if (mass[4] == 'x'){
				printf("x\n");
			}
		}
		else {
			printf("d\n");
		}
	}
	return (0);
}

Measured memory_bytes: 524
#include <bits/stdc++.h>
#define rep(i,n) for (int i = (0); i < (n); ++i)
#define rrep(i,n) for(int i = 1; i <= (n); ++i)
#define drep(i,n) for(int i = (n)-1; i >= 0; --i)
#define srep(i,s,t) for (int i = s; i < t; ++i)
#define rng(x) (x).begin(),(x).end()
#define rrng(x) (x).rbegin(),(x).rend()
#define limit(x,l,r) max(l,min(x,r))
#define lims(x,l,r) (x = max(l,min(x,r)))
#define isin(x,l,r) ((l) <= (x) && (x) < (r))
#define show(x) cout << #x << " = " << (x) << endl
#define show2(x,y) cout << #x << " = " << (x) << ", " << #y << " = " << (y) << endl
#define show3(x,y,z) cout << #x << " = " << (x) << ", " << #y << " = " << (y) <<  ", " << #z << " = " << (z) << endl
#define showv(v) rep(i,v.size()) printf("%d%c", v[i], i==v.size()-1?'\n':' ')
#define showv2(v) rep(j,v.size()) showv(v[j])
#define showt(t,n) rep(i,n) printf("%d%c", t[i], i==n-1?'\n':' ')
#define showt2(t,r,c) rep(j,r) showt(t[j],c)
#define showvp(p) rep(i,p.size()) printf("%d %d\n", p[i].first, p[i].second);
#define printv(v) rep(i,v.size()) printf("%d\n", v[i])
#define printt(t,n) rep(i,n) printf("%d\n", t[i])
#define incl(v,x) find(rng(v),x)!=v.end()
#define incls(s,c) s.find(c)!=string::npos
#define fi first
#define se second
#define pb push_back
#define eb emplace_back
#define sz(x) (int)(x).size()
#define pcnt __builtin_popcountll
#define bit(n,k) ((n>>k)&1) // nのk bit目
#define bn(x) ((1<<x)-1)
#define dup(x,y) (((x)+(y)-1)/(y))
#define newline puts("")
#define uni(x) x.erase(unique(rng(x)),x.end())
#define SP << " " <<
#define v(T) vector<T>
#define vv(T) v(v(T))
using namespace std;
using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vl = vector<ll>;
using vs = vector<string>;
using P = pair<int, int>;
using T = tuple<int, int, int>;
using vp = vector<P>;
using vt = vector<T>;
const int mod = 1000000007;
const double EPS = 1e-9;
//const long double EPS = 1e-14;
const int INF = (1<<30)-1;
const ll LINF = (1LL<<62)-1;
#define dame { puts("No"); return 0;}
#define yn {puts("Yes");}else{puts("No");}
inline int in() { int x; scanf("%d",&x); return x;}
//template<class T = int> inline T in() { T x; cin >> x; return (x);}
template<typename T>inline ll suma(const v(T)& a) { ll res(0); for (auto&& x : a) res += x; return res;}
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
ll gcd(ll a, ll b) { return b ? gcd(b,a%b) : a;}
ll lcm(ll a, ll b) { return a/gcd(a,b)*b;}

ll dp[1005][20005];

int main () {
  ll h, n;
  cin >> h >> n;
  vl a(n), b(n);
  rep(i,n) cin >> a[i] >> b[i];

  ll amx = *max_element(rng(a));
  rep(i,1005)rep(j,20005) dp[i][j] = LINF;
  dp[0][0] = 0;
  rep(i,n)rep(j,h+amx) {
    if (j < a[i]) {
      dp[i+1][j] = dp[i][j];
    }
    else {
      dp[i+1][j] = min(dp[i][j], dp[i+1][j-a[i]]+b[i]);
    }
  }
  ll ans = LINF;
  srep(j,h,h+amx) chmin(ans, dp[n][j]);
  cout << ans << endl;
  return 0;
}

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

#define ll long long
#define INF 99999999
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(),(x).end()

int main()
{
    vector<int> a;
    int n;
    cin >> n;
    a.push_back(n/1000);
    n %= 1000;
    a.push_back(n/100);
    n %= 100;
    a.push_back(n/10);
    n %= 10;
    a.push_back(n);
    if(a[1] != a[2])
    {
        cout << "No" << endl;
        return 0;
    }
    size_t c = count(a.begin(),a.end(),a[1]);
    if(c < 3) cout << "No" << endl;
    else cout << "Yes" << endl;

    
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <iostream>
using namespace std;
#define ll long long
#define mod 1000000007
const int MAX=1e6+1;
ll fact[MAX];
ll infact[MAX];
ll power(ll i,ll m)
{
    if(m==0)
        return 1;
   	ll res=power(i,m/2)%mod;
    if(m%2)
        return (i%mod*res%mod*res%mod)%mod;
    else return (res%mod*res%mod)%mod;
}
int main()
{
    fact[0]=1;fact[1]=1;
    infact[1]=1;infact[0]=1;
	int x,y;
    cin>>x>>y;
    int sum=x+y;
    for(ll i=2;i<MAX;i++)
    {
        fact[i]=(fact[i-1]*i)%mod;
    }
    for(ll i=2;i<MAX;i++)
    {
        infact[i]=(infact[i-1]*power(i,mod-2))%mod;
    }
    ll ans=0;
    if(sum%3==0)
    {
        ll count=sum/3;
        for(int i=0;i<=count;i++)
        {
            ll one=i;
            ll two=count-i;
            ll s=one+two*2;
            if(s==x||s==y)
            {
                ans=(((fact[count]*infact[one])%mod)*infact[two])%mod;
                break;
            }
        }
    }
    cout<<ans%mod<<endl;
	return 0;
}

Measured memory_bytes: 16000
from collections import deque


def show_2d_array(array):
    [print(a) for a in array]


N, M = map(int, input().split())

cave = [[] for i in range(N)]
for i in range(M):
    a, b = map(int, input().split())
    cave[a-1].append(b-1)
    cave[b-1].append(a-1)


# show_2d_array(cave)


def bfs(tree, p):
    seen = [False] * len(tree)
    queue = deque((p,))
    depth = [0] * N
    depth[p] = 0
    current_depth = depth[p]
    while len(queue) > 0:
        # print(queue)
        q = queue.popleft()
        seen[q] = True
        # print(q)
        for v in tree[q]:
            if not seen[v]:
                depth[v] = depth[q] + 1
                queue.append(v)
                seen[v] = True


    return depth


depth = bfs(cave, 0)

# print("depth", depth)

sign = [0] * N
ans = "Yes"
for i in range(1, N):
    this_depth = depth[i]
    found = False
    for j in cave[i]:
        if depth[j] == this_depth - 1:
            sign[i] = j
            found = True
            break
    if not found:
        ans = "No"
        break

"""
for i in range(1, N):
    current = i
    found = False
    while not found:
        next = -1
        for j in cave[current]:
            if depth[j] == depth[current]-1:
                if sign[current] <= 0:
                    next = j
                    sign[current] = next
                    break
                else:
                    next = sign[current]
                    break
        if next < 0:
            ans = "No"
            break

        current = next
        if current == 0:
            found = True
"""

print(ans)
if ans == "Yes":
    [print(s+1) for s in sign[1:]]



Measured memory_bytes: 37076
#include<bits/stdc++.h>
using namespace std;
using ll=long long;
ll find(ll arr[], int n) 
{ 
    ll high = 0; 
    for (ll i = 0; i < n; i++) 
        high = max(high, arr[i]); 
    ll count[high + 1] = {0}; 
    for (ll i = 0; i < n; i++) 
        count[arr[i]]++; 

    ll counter = 0; 
    for (ll i = high; i >= 1; i--) 
    { 
       ll j = i; 
       counter = 0; 
        while (j <= high) 
        { 
           
            if(count[j] >=2) 
               return j; 
  
           else if (count[j] == 1)          
                counter++;          
            j += i; 
  
            if (counter == 2)          
                return i; 
        } 
    }
    return 1; 
} 
int main()
{
    ll n;
    cin>>n;
    ll arr[n];
    for(ll i=0;i<n;i++)
        cin>>arr[i];
    ll g=arr[0];
    for(ll i=1;i<n;i++)
        g=__gcd(g,arr[i]);
    if(find(arr,n)==1)
        cout<<"pairwise coprime";
    else if(g==1)
        cout<<"setwise coprime";
    else
        cout<<"not coprime";
    return 0;
}

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

#include <iostream>
//#include <algorithm>
// #include <iomanip>
#define ll long long
#define map unordered_map
#define set unordered_set
#define pll pair<ll, ll>
#define vll vector<ll>
#define mll map<ll, ll>

using namespace std;

const ll MOD = 1000000007LL;
const ll INF = (1LL << 60LL);

const int MAX = 2000010;

ll fac[MAX], finv[MAX], inv[MAX];
ll cache25[MAX];
ll cache26[MAX];

void init_ncr() {
  fac[0] = fac[1] = 1;
  finv[0] = finv[1] = 1;
  inv[1] = 1;
  for (int i = 2; i < MAX; i++) {
    fac[i] = fac[i - 1] * i % MOD;
    inv[i] = MOD - inv[MOD % i] * (MOD / i) % MOD;
    finv[i] = finv[i - 1] * inv[i] % MOD;
  }
}

ll ncr(int n, int k) {
  if (n < k) return 0;
  if (n < 0 || k < 0) return 0;
  return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}
ll npr(ll val1, ll val2) {
  ll c = ncr(val1, val2);
  return c * fac[val2] % MOD;
}

ll p25(ll n) { return cache25[n]; }

ll p26(ll n) { return cache26[n]; }

int main() {
  init_ncr();
  // std::cout << std::fixed << std::setprecision(10);
  ll N;
  scanf("%lld", &N);

  ll c = 1;
  for (ll i = 0; i < MAX; i++) {
    cache25[i] = c;
    c = (c * 25) % MOD;
  }
  c = 1;
  for (ll i = 0; i < MAX; i++) {
    cache26[i] = c;
    c = (c * 26) % MOD;
  }

  string str;
  cin >> str;

  ll len = str.length();

  ll ans = 0;

  ll total_len = len + N;

  // N回操作する
  // len:元の文字列の長さ
  // total = N + len

  for (ll i = 0; i <= N; i++) {
    // cout << "i:" << i << endl;
    ll rest = N - i;
    ll count = ncr(rest + len - 1, len - 1);

    // cout << "(count):" << count << endl;
    // cout << "rest:" << rest << endl;

    count = count * p25(rest);
    count %= MOD;
    count = count * p26(i);
    count %= MOD;

    // cout << "count:" << count << endl;

    ans += count;
    ans %= MOD;
  }
  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 83472
#include <bits/stdc++.h>
using namespace std;
using Graph = vector<vector<int> >;
#define rep(i, n)         for(int i = 0; i < (int)(n); i++)
#define brep(n)           for(int bit=0;bit<(1<<n);bit++)
#define erep(i,container) for (auto i : container)
#define irep(i, n)        for(int i = n-1; i >= (int)0; i--)
#define rrep(i,m,n) for(int i = m; i < (int)(n); i++)
#define reprep(i,j,h,w) rep(i,h)rep(j,w)
#define all(x) (x).begin(),(x).end()
#define aall(x,n) (x).begin(),(x).begin()+(n)
#define VEC(type,name,n) std::vector<type> name(n);rep(i,n)std::cin >> name[i];
#define pb push_back
#define pf push_front
#define lb lower_bound
#define ub upper_bound
#define fi first
#define se second
#define itn int
#define mp make_pair
#define sum accumulate
#define keta fixed<<setprecision
#define vvector(name,typ,m,n,a)vector<vector<typ> > name(m,vector<typ> (n,a))
#define vvvector(name,t,l,m,n,a) vector<vector<vector<t> > > name(l, vector<vector<t> >(m, vector<t>(n,a)));
#define vvvvector(name,t,k,l,m,n,a) vector<vector<vector<vector<t> > > > name(k,vector<vector<vector<t> > >(l, vector<vector<t> >(m, vector<t>(n,a)) ));
//ノート　isupperで大文字の判定　islowerで小文字の判定
typedef long long ll;
const int INF = 2000000000;
const ll INF64 = 1000000000000000ll;
const ll MOD = 1000000007LL;
int main(){
    int n,a,b;
    std::cin >> n>>a>>b;
    std::cout << min(a,b)<<" "<<max(0,n-(n-a)-(n-b)) << std::endl;
    
}

Measured memory_bytes: 256
#include<cstdio>
#include<vector>
#include<algorithm>
#include<functional>

using namespace std;

int main(){
	int n, t;
	scanf("%d%d", &n, &t);
	vector<int> a(n), b(n);
	int tmp = (int)1e9 + 1;
	for(int i = 0; i < n; i++){
		scanf("%d", &a[i]);
		tmp = min(tmp, a[i]);
		b[i] = a[i] - tmp;
	}
	sort(b.begin(), b.end(), greater<int>());
	int ans = 1;
	for(int i = 1; i < n && b[i] == b[i - 1]; i++){
		ans++;
	}
	printf("%d\n", ans);
	return 0;
}

Measured memory_bytes: 1024
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
#define INF 1000000000
#define MOD 1000000007
#define MAXN 1000010

ll n;
ll dp[2*MAXN];

int main(){
		//for(n=1; n<=1000000; n++){
		n=2;
		scanf("%lld", &n);
		ll sum = n-1;
		for(int i=2*n; i>=0; i--){
			if(i>=n){
				dp[i] = 1;
			}
			else if(i==n-1){
				dp[i] = n;
			}
			else{
				dp[i] = ((n-1)*(n-1)+ dp[i+1])%MOD;
				/*for(int j=2; (j<=n); j++){
					if(i+j+1>=n) dp[i] = (dp[i]+1)%MOD;
					else dp[i] = (dp[i] + dp[i+j+1])%MOD;	
				}*/
				dp[i] = (dp[i] + sum)%MOD;	
				sum = (sum - dp[n+i+1] + MOD)%MOD;
				sum = (sum + dp[i+2])%MOD;
			}
		}
		printf("%d\n", dp[0]);
	//}
	return 0;
}


Measured memory_bytes: 15872
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <queue>
#include <map>
#include <set>
using namespace std;
typedef long long LL;
const LL mod = 1e9+7;
const int SIZEN = 3000100;
LL fac[SIZEN];
LL inv[SIZEN];
int r1,c1,r2,c2;
LL qpow(LL x,LL len){
    LL ret = 1;
    for(;len;len>>=1){
        if(len & 1)ret = ret * x % mod;
        x = x * x % mod;
    }
    return ret;
}
LL C(int n,int m){
    if(n < m)return 0;
    return fac[n] * inv[m] % mod * inv[n-m] % mod;
}
LL f(int n,int m){
    LL ret = 0;
    for(int i = 0;i <= n;i++){
        ret = (ret + C(i+m+1,m))%mod;
    }
    return ret;
}
int main(){
    fac[0] = 1;
    for(int i = 1;i <= 2000010;i++)fac[i] = (fac[i-1] * i) %mod;
    inv[2000010] = qpow(fac[2000010],mod-2);
    for(int i = 2000010 - 1;i >= 0;i--)inv[i] = (inv[i+1] * (i+1)) % mod;
    // printf("inv[2] = %lld\n",inv[2]);
    scanf("%d%d%d%d",&r1,&c1,&r2,&c2);
    LL ans = (f(r2,c2) - f(r1-1,c2) - f(r2,c1-1) + f(r1-1,c1-1)) % mod;
    ans = (ans + mod) % mod;
    printf("%lld\n",ans);
    return 0;
}

Measured memory_bytes: 32980
#include<bits/stdc++.h>
#include<iostream>
#define rep(i,n) for(int i=0;i<n;++i)
#define rrep(i,n) for(int i=n-1;i>=0;--i)
#define yesno(flg) if(flg){cout<<"YES"<<endl;}else{cout<<"NO"<<endl;}
#define MAX_N 1002
#define i197 1000000007

using namespace std;
typedef long long ll;
typedef pair<ll,ll> P1;
typedef pair<int,int> Pi;
typedef pair<double,Pi> Pdi;
typedef pair<ll,int>Pli;
typedef pair<int,ll>Pil;
typedef pair<P1,ll> P2;
typedef pair<string,string> Ps;
const ll INF=1000000000000000001;
struct edge{int to,cost;};
int dy[]={0, 0, 1, -1};
int dx[]={1, -1, 0, 0};
struct Road{double cost;int a,b;};
struct pos{
	// 1 変数を入れる;
	int x,y;
};

int main(){

	string s;
	cin>>s;

	int a=0,t=0;
	rep(i,3){
		if(s[i]=='R')t++;
		else{
			a=max(a,t);
			t=0;
		}
	}
	cout<<max(a,t)<<endl;

	return 0;
}




Measured memory_bytes: 3624
#include <bits/stdc++.h>
#define err(args...) {}
#ifdef DEBUG
#include "_debug.cpp"
#endif
using namespace std;
using ll = long long;
using ld = long double;
template <typename T> using lim = numeric_limits<T>;
template <typename T> istream& operator>>(istream& is, vector<T>& a) { for(T& x : a) { is >> x; } return is; }
const int M = 1'000'000'007;
int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    int n, m;
    cin >> n >> m;
    vector<ll> x(n), y(m);
    cin >> x >> y;
    adjacent_difference(x.begin(), x.end(), x.begin());
    adjacent_difference(y.begin(), y.end(), y.begin());
    ll ysum = 0;
    for(int j = 1; j < m; j++) {
        ysum += y[j] * (m - j) % M * j % M;
        ysum %= M;
    }
    ll xsum = 0;
    for(int i = 1; i < n; i++) {
        xsum += x[i] * (n - i) % M * i % M;
        xsum %= M;
    }
    cout << xsum * ysum % M << endl;
    return 0;
}


Measured memory_bytes: 1792
#include <stdio.h>
#include <algorithm>
using namespace std;
typedef long long ll;
const ll INF = 1e18;
const int INF2 = 1e9;

int main() {
  int n, m;
  ll l;
  scanf("%d %d %lld", &n, &m, &l);

  ll dist[n][n];
  for (int i = 0; i < n; ++i) {
    for (int j = 0; j < n; ++j) {
      if (i == j) dist[i][j] = 0;
      else dist[i][j] = INF;
    }
  }

  for (int i = 0; i < m; ++i) {
    int a, b;
    ll c;
    scanf("%d %d %lld", &a, &b, &c);
    a--; b--;
    dist[a][b] = c;
    dist[b][a] = c;
  }

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

  int dist2[n][n];
  for (int i = 0; i < n; ++i)
    for (int j = 0; j < n; ++j) dist2[i][j] = INF2;

  for (int i = 0; i < n; ++i) {
    for (int j = 0; j < n; ++j) {
      if (dist[i][j] <= l) dist2[i][j] = 1;
    }
  }

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

  int q;
  scanf("%d", &q);
  int ans[q];
  for (int i = 0; i < q; ++i) {
    int s, t;
    scanf("%d %d", &s, &t);
    s--; t--;
    ans[i] = dist2[s][t] == INF2? -1: dist2[s][t] - 1;
  }
  for (int i = 0; i < q; ++i) {
    printf("%d\n", ans[i]);
  }
  return 0;
}


Measured memory_bytes: 1792
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
#define MOD 1000000007

vector<ll> fact;
void init_fact(int n){
    fact.resize(n+1);
	fact[0]=1;
	for (int i = 1; i < n+1; i++){
		fact[i]=fact[i-1]*i;
		fact[i]%=MOD;
	}
}
ll mod_pow(ll x, ll p){
	ll res=1;
	ll n=x;
	while(p>0){
		if(p&1==1)res=(res*n)%MOD;
		n=(n*n)%MOD;
		p=(p>>1);
	}
	return res;
}
ll modinv(ll a, int b){// a/b mod MOD
    ll res=1;
    int n=MOD-2;
    ll x=b;
    while(n>0){
        if(n&1==1){
            res*=x;
            res%=MOD;
        }
        x*=x;
        x%=MOD;
        n>>=1;
    }
    res*=a;
    res%=MOD;
    return res;
}

ll nCr(int n, int r){
	ll res=1;
	res*=fact[n];
	res*=mod_pow(fact[r],MOD-2);
	res%=MOD;
	res*=mod_pow(fact[n-r],MOD-2);
	res%=MOD;
	return res;
}

int main() {
    ll N,M;
    cin>>N>>M;
    init_fact(M);
    ll ans=0;
    for (int i = 0; i <= N; i++){
        ll tmp=modinv(fact[M],fact[M-N]);
        tmp=tmp*nCr(N,i)%MOD;
        tmp=tmp*modinv(fact[M-i],fact[M-N])%MOD;
        if(i%2==1)tmp*=-1;
        ans+=tmp;ans%=MOD;
    }
    ans+=MOD;ans%=MOD;
    cout<<ans<<endl;
}

Measured memory_bytes: 7124
use proconio::input;

fn main() {
    input! {
        k: usize,
        aa: [usize; k],
    }

    let mut min = 2;
    let mut max = 2;

    for &a in aa.iter().rev() {
        let new_min = (min + a - 1) / a * a;
        let new_max = max / a * a + a - 1;

        min = new_min;
        max = new_max;
    }

    if min > max {
        println!("-1");
        return;
    }

    println!("{} {}", min, max);
}


Measured memory_bytes: 3752
import sys
a,b=map(int,input().split())
b=b/1000
for i in range(a+1):
  for j in range(a-i+1):
    if 10*i+5*j+a-i-j==b:
      print(i,j,a-i-j)
      sys.exit()
print(-1,-1,-1)

Measured memory_bytes: 3060
import java.io.*;

class Main{
	public static void main(String args[]) throws IOException{
		BufferedReader buf = new BufferedReader(new InputStreamReader(System.in));
		int n = Integer.parseInt(buf.readLine());
		String[] str;
		int[] dice1 = new int[6];
		int[] dice2 = new int[6];
		int[][] dice = new int[n][6];
		String answer="";
		
		for(int i=0; i<n; i++){
			str = buf.readLine().split(" ");
			for(int j=0; j<6; j++){
				dice[i][j] = Integer.parseInt(str[j]);
			} 
		}
		for(int i=0; i<n; i++){
			for(int j=i+1; j<n; j++){
				for(int k=0; k<6; k++){
					dice1[k] = dice[i][k];
					dice2[k] = dice[j][k];
				}
				Saikoro sk = new Saikoro(dice1,dice2);
				if(sk.compare_saikoro()){
					answer = "No";
					break;
				}
				else
					answer = "Yes";
			}
			if(answer == "No")
				break;
		}
		System.out.println(answer);
	}
}
class Saikoro{
	int[] dice1 = new int[6];
	int[] dice2 = new int[6];
	StringBuilder sb1 = new StringBuilder();
	StringBuilder sb2 = new StringBuilder();
	String str1,str2;

	public Saikoro(int[] dice1, int[] dice2){
		for(int i=0; i<6; i++){
			this.dice1[i] = dice1[i];
			this.dice2[i] = dice2[i];

		}
		sb1.append(dice1[1]);
		sb1.append(dice1[2]);
		sb1.append(dice1[4]);
		sb1.append(dice1[3]);
		str1 = sb1.toString();
	}
	public boolean compare_saikoro(){
		if(dice2[0] == dice1[0] && dice2[5] == dice1[5]){
				sb2.append(dice2[1]);
				sb2.append(dice2[2]);
				sb2.append(dice2[4]);
				sb2.append(dice2[3]);
				str2 = sb2.toString();
				return (str1+str1).contains(str2);			
		}
		else if(dice2[1] == dice1[0] && dice2[4] == dice1[5]){
				sb2.append(dice2[0]);
				sb2.append(dice2[3]);
				sb2.append(dice2[5]);
				sb2.append(dice2[2]);
				str2 = sb2.toString();	
				return (str1+str1).contains(str2);	
		}
		else if(dice2[2] == dice1[0] && dice2[3] == dice1[5]){
				sb2.append(dice2[0]);
				sb2.append(dice2[1]);
				sb2.append(dice2[5]);
				sb2.append(dice2[4]);
				str2 = sb2.toString();
				return (str1+str1).contains(str2);			
		}
		else if(dice2[3] == dice1[0] && dice2[2] == dice1[5]){
				sb2.append(dice2[0]);
				sb2.append(dice2[4]);
				sb2.append(dice2[5]);
				sb2.append(dice2[1]);
				str2 = sb2.toString();
				return (str1+str1).contains(str2);			
		}
		else if(dice2[4] == dice1[0] && dice2[1] == dice1[5]){
				sb2.append(dice2[0]);
				sb2.append(dice2[2]);
				sb2.append(dice2[5]);
				sb2.append(dice2[3]);
				str2 = sb2.toString();
				return (str1+str1).contains(str2);			
		}
		else if(dice2[5] == dice1[0] && dice2[0] == dice1[5]){
				sb2.append(dice2[1]);
				sb2.append(dice2[3]);
				sb2.append(dice2[4]);
				sb2.append(dice2[2]);
				str2 = sb2.toString();
				return (str1+str1).contains(str2);			
		}else{
			return false;
		}
	}
}

Measured memory_bytes: 28872
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
# vim:fenc=utf-8 ff=unix


def solv(N, X, Y):
    ans = list(range(N, 0, -1))
    X = X - 1
    Y = Y - 1
    NN = N
    while X >= 0:
        # print('XY', X, Y)
        # 順方向
        x = X + 1
        y = Y
        while y < NN:
            # print('順  x+ y-', x, y)
            ans[x] += 1
            ans[y] -= 1
            x += 1
            y += 1
        # 逆方向
        y = Y-1
        x = X+2
        while x < y:
            # print('逆  x+ y-', x, y)
            ans[x] += 1
            ans[y] -= 1
            x += 1
            y -= 1
        X -= 1
        Y -= 1
        NN -= 1

    X = 1
    while X < Y:
        # print('XY', X, Y)
        # 順方向
        x = X + 1
        y = Y
        while y < NN:
            # print('順  x+ y-', x, y)
            ans[x] += 1
            ans[y] -= 1
            x += 1
            y += 1
        # 逆方向
        y = Y-1
        x = X+2
        while x < y:
            # print('逆  x+ y-', x, y)
            ans[x] += 1
            ans[y] -= 1
            x += 1
            y -= 1
        X += 1
        Y -= 1
        NN -= 1

    return ans


if __name__ == "__main__":

    N, X, Y = map(int, input().split())
    ans = solv(N, X, Y)

    print("\n".join(map(str, ans[1:])))


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

 using namespace std;

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

   vector<int> A(N + 1);
   vector<int> B(N + 1);
   vector<int> C(N);

   for (int i = 1; i <= N; i++) cin >> A.at(i);
   for (int i = 1; i <= N; i++) cin >> B.at(i);
   for (int i = 1; i < N; i++) cin >> C.at(i);

   int ans = 0;
   for (int i = 1; i < N; i++) {
     ans += B.at(A.at(i));
     if (A.at(i + 1) - A.at(i) == 1) ans += C.at(A.at(i));
   }
   ans += B.at(A.at(N));

   cout << ans << endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <queue>

using namespace std;
typedef long long ll;
typedef pair<int, int> P;

int main(){
  string s;
  cin >> s;
  int c[26];
  fill(c, c+26, 0);

  for(int i = 0; i < s.length(); i++){
    c[s[i]-'a'] = 1;
  }
  if (s.length() <= 25){
    for(int i = 0; i < 26; i++){
      if(c[i] == 0){
        char z = 'a'+i;
        cout << s << z << endl;
        return 0;
      }
    }
  }
  else{
    for(int i = 25; i >= 1; i--){
      if(s[i-1] > s[i]){
        c[s[i]-'a'] = 0;
      }
      else{
        c[s[i]-'a'] = 0;
        int z = s[i-1] - 'a';
        for(int j = z; j < 26; j++){
          if(c[j] == 0){
            for(int k = 0; k < i-1; k++){
              cout << s[k];
            }
            char p = 'a' + j;
            cout << p << endl;
            return 0;
          }
        }
      }
    }
    cout << -1 << endl;
  }

  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define L 1000000007
#define int long long
using namespace std;
int note[114514];
signed main(){
  int in;
  cin>>in;
  note[0]=1;
  for(int i=0;i<in+10;i++){
    if(i)note[i]=(note[i-1]*(i+1))%L;
  }
  cout<<note[in-1]<<endl;
}

Measured memory_bytes: 1024
import sys
input = sys.stdin.readline
from collections import deque

S = deque(list(input().rstrip()))
Q = int(input())
Query = []

flag = 0

for _ in range(Q):
    Query.append(input().rstrip().split())

for i in Query:
    if i[0] == "1":
        flag += 1
    elif i[1] == "1":
        if flag % 2 == 0:
            S.appendleft(i[2])
        else:
            S.append(i[2])
    else:
        if flag % 2 == 0:
            S.append(i[2])
        else:
            S.appendleft(i[2])
if flag % 2 == 0:
    print("".join(list(S)))
else:
    print("".join(list(S))[::-1])

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

int main(){
    int a, b;
    while( cin >> a >> b ){
        vector<int> count(100, 0);
        int cod;
        count[a-1]++;
        count[b-1]++;
        while( cin >> a >> b, a||b ){
            count[a-1]++;
            count[b-1]++;
        }
        cod = 0;
        for(int i = 0; i < 100; i++){
            if( count[i]%2 ) cod++;
        }
        if( cod*(cod-2) == 0 && count[0]%2 && count[1]%2 ) cout << "OK" << endl;
        else cout << "NG" << endl;
    }
    return 0;
}

Measured memory_bytes: 1188
#include<iostream>
#include<vector>
#include<algorithm>
#include<math.h>
#include<queue>
#define all(x) (x).begin(),(x).end()
typedef long long ll;

using namespace std;

int main(){
    int N, cnt4, cnt1;  cin >> N;
    vector<int> A(N);
    for(int i=0; i<N; i++)  cin >> A[i];
    cnt4 = 0;
    cnt1 = 0;
    for(int i=0; i<N; i++){
        if(A[i] % 4 == 0)   cnt4++;
        if(A[i] % 2 == 1)   cnt1++;
    }
    if(cnt4 >= N/2 || cnt1 <= cnt4){
        cout << "Yes";
    }else{
        cout << "No";
    }
    return 0;
}

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

using namespace std;
const int long long MOD=998244353;
long long n, s, a[3009], dp[3009][3009];

int main(){
  memset(dp, 0, sizeof(dp));
  cin >> n >> s;
  for(int i=0;i<n;i++)cin >> a[i];
  long long pow2=1;
  for(int i=0;i<n;i++){
    for(int j=1;j<=s;j++){
      if(i>0 && j-a[i]>0)dp[i][j] = (dp[i][j] + dp[i-1][j-a[i]])%MOD;
      if(i>0)dp[i][j] = (dp[i][j]+(dp[i-1][j]*2)%MOD)%MOD;
      if(j==a[i])dp[i][j] = (dp[i][j] + pow2)%MOD;
    }
    pow2 = (pow2*2)%MOD;
  }
  /*
  for(int i=0;i<n;i++){
    for(int j=1;j<=s;j++){
      cout << dp[i][j] << ' ';
    }
    cout << endl;
  }
  */
  cout << dp[n-1][s] << endl;
}


Measured memory_bytes: 74352
#include <bits/stdc++.h>
 
using namespace std;
 
#define SZ(x) ((int)(x).size())
using namespace std;
typedef pair<int,int> PII;
#define FF first
#define SS second
#define MP make_pair
#define PB push_back
#define REP(i,n) for (int i = 0; i < n; ++i)
#define FOR(i,a,b) for (int i = a; i <= b; ++i)
#define M 1000000007
#define MM 998244353
#define SZ(a) int((a).size())
#define all(v) (v).begin(), (v).end()
#define uni(v) sort(all(v)), (v).erase(unique(all(v)), (v).end())
#define mod 1000000007
//a and b are assumed to be taken modulo p
inline int add(int a, int b, int p = mod){ int c = a + b; if(c >= p) c -= p; return c; }
inline int sub(int a, int b, int p = mod){ int c = a - b; if(c < 0) c += p; return c; }
inline int mul(int a, int b, int p = mod){ return (a * 1ll * b) % p; }
 
using ll = long long;
using VI = vector<int>;
using PII = pair<int, int>;
using PLL = pair<ll, ll>;
using VLL = vector<ll>;
using ld = long double;
int gcd(int a, int b)
{
    if (b == 0)
        return a;
    return gcd(b, a % b);
      
}
const int MX = 2e5+10;
const int MX2 = 1e6+5;

ll INF= 4 * (ll)1e18;
int mx = 2 * (ll)1e9 + 10;

int cnt[MX];
bool cmp(string x,string y) {
    string XY = x.append(y);
    string YX = y.append(y);
    return XY.compare(YX) > 0 ? 0: 1;
    
}
vector<string> v;
int main(int argc, const char * argv[]) {

    ios_base::sync_with_stdio(false);
    cin.tie(0);cout.tie(0); // insert code here...
    int n,l;
    cin >> n >> l;
    REP(i,n) {
        string s;
        cin >> s;
        v.push_back(s);
    }
    sort(v.begin(),v.end());
    string res = "";
    for (int i = 0; i < n; ++i) {
        res += v[i];
    }
    cout << res << endl;
    return 0;
}


Measured memory_bytes: 256
//include
//------------------------------------------
#include <iostream>
#include <vector>
#include <list>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>
#include <limits>
using namespace std;

//repetition
//------------------------------------------
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define FORR(i,a,b) for(int i=(a);i>(b);i--)
#define REP(i,n)  FOR(i,0,n)

//conversion
//------------------------------------------
inline int toInt(string s) {int v; istringstream sin(s);sin>>v;return v;}
template<class T> inline string toString(T x) {ostringstream sout;sout<<x;return sout.str();}

//debug
//-------------------------------------------
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;
#define INF (1<<21)
#define NOT_VISITED 0
#define FOUND 1
#define VISITED 2

//typedef
//-------------------------------------------
typedef long long ll;
typedef pair<int, int> Pair;

int n;
vector<Pair> g[101];
int d[101];
int p[101];
int visited[101];

int dijkstra(int start) {
    d[start] = 0;
    p[start] = -1;

    while(1) {
        int mincost = INF;
        int u = -1;
        REP(i, n) {
           if (visited[i] != VISITED && d[i] < mincost) {
                mincost = d[i];
                u = i;
            }
        }
        if (u == -1) break;
        visited[u] = VISITED;

        REP(j, n) {
            REP(k, g[u].size()) {
                if (visited[j] != VISITED && g[u][k].first == j) {
                    if (d[u] + g[u][k].second < d[j]) {
                        d[j] = d[u] + g[u][k].second;
                        p[j] = u;
                        visited[j] = FOUND;
                    }
                }
            }
        }
    }
    return 1;
}

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

    REP(i, 101) {
        visited[i] = NOT_VISITED;
        d[i] = INF; 
        p[i] = -1;
    }

    cin >> n;
    REP(i, n) {
        int u, k;
        cin >> u >> k;
        REP(j, k) {
            int v, c;
            cin >> v >> c;
            Pair e(v, c);
            g[u].push_back(e);
        }
    }

    dijkstra(0);

    REP(i, n)  {
        cout << i << " " << d[i] << endl;
    }

    return 0;
}

Measured memory_bytes: 3180
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define ld long double
#define F first
#define S second
#define pb push_back
#define mp make_pair
#define mod 1000000007
#define vlli vector<ll>
#define vi vector<int>
#define vs vector<string>
#define vplli vector< pair< ll,ll> >
#define plli pair< ll,ll >
#define vps vector< pair< string, string> >
#define vpi vector< pair< int, int> >
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
#define fast ios::sync_with_stdio(false);cin.tie(0);cout.tie(0)
#define forn(i,a,n) for(ll i=a;i<n;i++)
#define forr(i,n,a) for(ll i=n-1;i>=a;i--)
#define scan(arr,a,n) for(ll i=(a);i<(n);i++)cin>>(arr)[i];
#define print(arr,a,n) for(ll i=(a);i<(n);i++)cout<<(arr)[i]<<" ";

const ll inf = 1e18;
const ll N = 1e5 + 2;

ll add(ll x, ll y) {ll res = x + y; return (res >= mod ? res - mod : res);}
ll mul(ll x, ll y) {ll res = x * y; return (res >= mod ? res % mod : res);}
ll sub(ll x, ll y) {ll res = x - y; return (res < 0 ? res + mod : res);}
ll power(ll x, ll y) {ll res = 1; x %= mod; while (y) {if (y & 1)res = mul(res, x); y >>= 1; x = mul(x, x);} return res;}
ll mod_inv(ll x) {return power(x, mod - 2);}


int main(){
	fast;
    #ifndef ONLINE_JUDGE
    freopen("input1.txt","r",stdin);
    freopen("output1.txt","w",stdout);
    #endif
	ll n, m;
	cin>>n>>m;
	vector< vlli > v(N);
	ll a, b;
	forn(i, 0, n){
		cin>>a>>b;
		v[a].pb(b);
	}
	priority_queue<ll> q;
	ll ans = 0;
	forn(i, 1, m+1){

		forn(j, 0, v[i].size()){
			q.push(v[i][j]);
		}
		if(q.empty()){
			continue;	
		}
		ans+=q.top();
		q.pop();		
	}
	cout<<ans<<endl;
}

Measured memory_bytes: 8728
import java.util.*;
import static java.lang.Math.*;
public class Main{
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int sum = 0;
        int w[] = new int[n];
        for(int i=0; i<n; i++){
          w[i] = sc.nextInt();
          sum += w[i];
        }
        int all = 0;
        int min = Integer.MAX_VALUE;
        for(int i=0; i<n; i++){
          all += w[i];
          min = min(min, abs(sum-all-all));
        }
        System.out.println(min);
    }
}


Measured memory_bytes: 23508
#include <bits/stdc++.h>
using namespace std;
typedef long long ll; 
#define arrlen(arr) (sizeof(arr)/sizeof(arr[0]))
#define Sort(arr) sort(arr, arr+arrlen(arr))
#define For(i,s,n) for(int i=s;i<n;i++)
#define Foreach(i,arr) For(i,0,arrlen(arr))
#define Arrin(arr) Foreach(i,arr){cin>>arr[i];}
#define Arrin2(arr1,arr2) Foreach(i,arr1){cin>>arr1[i]>>arr2[i];}
#define Arrin3(arr1,arr2,arr3) Foreach(i,arr1){cin>>arr1[i]>>arr2[i]>>arr3[i];}
	
int main(){
	int N,K;
	cin >> N >> K;
	string S;
	cin >> S;
	S[K-1]+='a'-'A';
	cout << S;
}

Measured memory_bytes: 256
#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;

struct Vertex
{
    vector<ll> node;
};
struct Edge
{
    ll from;
    ll to;
    ll cost;
};
Vertex V[3000];
Edge E[5005];
ll A[3000];
bool C[3000];
bool U[3000];

int main()
{
    ll N, M, P;
    cin >> N >> M >> P;
    REP(i, M)
    {
        ll a, b, c;
        cin >> a >> b >> c;
        E[i].from = --a;
        E[i].to = --b;
        E[i].cost = -(c - P);
        V[a].node.push_back(b);
    }
    memset(C, 0, sizeof(C));
    REP(i, N)
    {
        memset(U, 0, sizeof(U));
        queue<ll> q;
        q.push(i);
        U[i] = true;
        while (!q.empty())
        {
            ll t = q.front();
            q.pop();
            if (i == 0)
                C[t] = true;
            REP(i, V[t].node.size())
            {
                ll n = V[t].node[i];
                if (U[n])
                    continue;
                U[n] = true;
                q.push(n);
            }
        }
        C[i] = C[i] & U[N - 1];
    }

    REP(i, N)
    {
        A[i] = INF;
    }
    A[0] = 0;
    REP(v, N)
    {
        REP(j, M)
        {
            auto e = E[j];
            A[e.to] = std::min(A[e.to], A[e.from] + e.cost);
        }
    }

    bool loop = false;
    REP(i, M)
    {
        auto e = E[i];
        ll cost = A[e.from] + e.cost;
        if (cost < A[e.to] && C[e.to])
            loop = true;
    }

    if (loop)
        cout << -1 << endl;
    else
        cout << std::max(0LL, -A[N - 1]) << endl;
    return 0;
}

Measured memory_bytes: 512
#define _CRT_SECURE_NO_WARNINGS
#include<bits/stdc++.h>
using namespace std;
#define int long long
#ifndef FAST_IO
  #define IOS ios_base::sync_with_stdio(false),cin.tie(nullptr),cout.tie(nullptr);
#endif
#define ff first
#define ss second
#define endl "\n"
#define all(c) c.begin(),c.end()
template<typename T>void print(T t){for(auto &it:t)cout<<it<<" "; cout<<endl;}
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
const int MAXN=3e3+1;
void solve(){
   int n,ans,c1,c2,c3;
   ans=0,c1=0,c2=0,c3=0;
   cin>>n;
   for(int i=0;i<n;i++){
	  string s;
	  cin>>s;
	  for(int i=0;i<(int)s.size()-1;i++){
		  if(s[i]=='A' and s[i+1]=='B')ans++;
		  } 
	  if(s[0]=='B' and s[(int)s.size()-1]=='A')c1++;
	  if(s[0]=='B')c2++;
	  if(s[(int)s.size()-1]=='A')c3++;
	  }
	  ans+=min(c2,c3);
	  if(c2==c3 and c1==c3 and c1)ans--;
	  cout<<ans<<endl;
}
int32_t main(){
   IOS;
   solve();
   //debug();
  #ifdef LOCAL_DEFINE
   cerr<<"time elapsed "<<(double)clock()/CLOCKS_PER_SEC<<endl;
  #endif	
}

Measured memory_bytes: 384
import java.util.Scanner;

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

Scanner sc = new Scanner(System.in);
int limit = sc.nextInt();
int x;
for(int i = 1; i<= limit ; i++){
  x = i;
  if(x%3 ==0){
    System.out.print(" "+x);
    continue;
  }
  while(x>0){
if(x%10 ==3){
  System.out.print(" "+ i);
  break;
}
    x /=10;
  }

}//for
System.out.println("");
}//main


}//class



Measured memory_bytes: 28824