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

using namespace std;

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

#define MOD 1000000007
#define REP(i, N) for (int i = 0; i < N; ++i)
#define REP1(i, N) for (int i = 1; i <= N; ++i)
#define RREP(i, N) for (int i = N - 1; i >= 0; --i)
#define ALL(a) a.begin(), a.end()

int main() {
  int X, Y, Z, K;
  cin >> X >> Y >> Z >> K;
  vector<ll> A(X), B(Y), C(Z);
  REP(i, X) cin >> A[i];
  REP(i, Y) cin >> B[i];
  REP(i, Z) cin >> C[i];
  vector<ll> AB;
  REP(i, X) REP(j, Y) AB.push_back(A[i] + B[j]);
  sort(ALL(AB));
  reverse(ALL(AB));
  AB.resize(min(X * Y, K));
  vector<ll> ABC;
  REP(i, AB.size()) REP(j, Z) ABC.push_back(AB[i] + C[j]);
  sort(ALL(ABC));
  reverse(ALL(ABC));
  ABC.resize(K);
  REP(i, ABC.size()) cout << ABC[i] << endl;
  return 0;
}

Measured memory_bytes: 43368
#include<iostream>
#include<cctype> // isdigit
#include<cassert> // assert
using namespace std;

struct Result{int value,pos;};

int calculate(string expression);
Result equation(string expression,int pos);
Result factor(string expression,int pos);
Result term(string expression,int pos);

int calculate(string expression)
{
  return equation(expression,0).value;
}

Result equation(string expression,int pos)
{
  Result r=factor(expression,pos);
  // Á¸Z
  while(expression[r.pos]=='+' || expression[r.pos]=='-'){
    Result _r=factor(expression,r.pos+1);
    if(expression[r.pos]=='+')r.value += _r.value;
    if(expression[r.pos]=='-')r.value -= _r.value;
    r.pos=_r.pos;
  }
  return r;
}
Result factor(string expression,int pos)
{
  Result r=term(expression,pos);
  // æZ
  while(expression[r.pos]=='*' || expression[r.pos]=='/'){
    Result _r=term(expression,r.pos+1);
    if(expression[r.pos]=='*')r.value *= _r.value;
    if(expression[r.pos]=='/')r.value /= _r.value;
    r.pos=_r.pos;
  }
  return r;
}
Result term(string expression,int pos)
{
  Result r;
  // l
  if(isdigit(expression[pos])){
    int value=0;
    while(isdigit(expression[pos]))value = value*10 + expression[pos++]-'0';
    r.value=value;
    r.pos=pos;
    return r;
  }
  // Ê
  if(expression[pos]=='('){
    r=equation(expression,pos+1);
    assert(expression[r.pos++]==')');
    return r;
  }
}

int main()
{
  int n;
  string s;
  cin>>n;
  while(n-->0){
    cin>>s;
    s=s.substr(0,s.size()-1);
    cout<<calculate(s)<<endl;
  }
}

Measured memory_bytes: 0
N = int(input())
S = input()

if N % 2 == 1:
  ans = "No"
else:
  zenhan = S[0:int(N/2)] 
  kouhan = S[int(N/2):N]
  if zenhan == kouhan:
    ans = "Yes"
  else:
    ans = "No"

print(ans)

Measured memory_bytes: 3060
#include <bits/stdc++.h>
#define rep(i, n) for(int (i)=0; (i)<(n); (i)++)

using namespace std;
typedef long long ll;

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 main()
{
  int A, B;
  cin >> A >> B;

  if(A>12)
    cout << B << endl;
  else if(A>5)
    cout << B/2 << endl;
  else
    cout << 0 << endl;


  return 0;
}


//cout << setprecision(13);
//next_permutation();
//__gcd();
//reverse();
//set ,tuple ,pair;
//bitset
//vector.find
//vector.count



Measured memory_bytes: 256
#if __has_include("D:/dhiraj/Programming/debug.h")
    #include "D:/dhiraj/Programming/debug.h"
#else
    #include <bits/stdc++.h>
    using namespace std;
    #define d(...) 11
    #define cerr if(0) cerr
#endif

// Macro --------------------------------------------------------------------

#define ll                  int64_t
#define FOR(i, a, b, s)     for(ll i = (a); ((s) > 0 ? i < (b) : i > (b)); i += (s))
#define FOR1(b)             FOR(i, 0, b, 1)
#define FOR2(i, b)          FOR(i, 0, b, 1)
#define FOR3(i, a, b)       FOR(i, a, b, (a) <= (b) ? 1 :-1)
#define FOR4(i, a, b, s)    FOR(i, a, b, s)
#define GET5(a, b, c, d, e, ...) e
#define FORC(...)           GET5(__VA_ARGS__, FOR4, FOR3, FOR2, FOR1)
#define loop(...)           FORC(__VA_ARGS__)(__VA_ARGS__)
#define all(x)              x.begin(),x.end()
#define rall(x)             x.rbegin(),x.rend()
#define endl                '\n'

// Template -----------------------------------------------------------------

// multiple input
template <typename... T> 
inline void inp(T&... args) {
    ((cin>>args), ...);
}
// scan vector
template <typename T> 
inline istream &operator >>(istream &in, vector<T> &a) {
    for(auto &x : a) in >> x;
    return in;
}
// scan pair
template <typename T, typename U> 
inline istream &operator >>(istream &in, pair<T, U> &a) {
    in >> a.first >> a.second; 
    return in;
}

// Solve --------------------------------------------------------------------

void solve(int &T)
{
    ll n;
    cin>>n;
    
    vector<ll> a(n);
    cin>>a;

    ll ans = 0;
    loop(i,n)
    {
        loop(j,i+1,n)
        {
            loop(k,j+1,n)
            {
                set<ll> s;
                s.insert(a[i]);
                s.insert(a[j]);
                s.insert(a[k]);

                ll kk = 0;
                vector<ll> x(3);
                for(ll X : s) x[kk++] = X;

                if(s.size() == 3) {
                    ans += (x[0] + x[1] > x[2]);
                }
            }
        }
    }
    cout << ans << endl;
}

// Main ---------------------------------------------------------------------

int main()
{
    #ifdef Dhiraj
        freopen("D:/dhiraj/Programming/i1.txt", "r", stdin);
        freopen("D:/dhiraj/Programming/o1.txt", "w", stdout);
        // freopen("D:/dhiraj/Programming/e1.txt", "w", stderr);
    #endif

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

    int t = 1;
    for(int i = 1; i <= t; i++) {
        cerr << "Case #" << i << "\n";
        solve(i);
    }
    return 0;
}

Measured memory_bytes: 3660
#include <bits/stdc++.h>
#include <math.h>
#include <ostream>
#include <stdio.h>
using namespace std;

int main(void) {
  int N;
  cin >> N;
  vector<string> items(N);
  for (int i = 0; i < N; i++) {
    cin >> items[i];
  }
  set<string> kinds(items.begin(), items.end());
  cout << kinds.size() << endl;
  return 0;
}


Measured memory_bytes: 25000
#include<algorithm>
#include<cstring>
#include<cctype>
#include<cstdio>
#define rep(i,x,y) for(int i=x; i<=y; ++i)

using namespace std;
const int N=2050,INF=1000000000;
typedef long long LL;
bool vis[N];
int n,h[N],cnt,q[10000000],from[N],s,t,head,tail;
LL ans,dis[N];
struct edge{int v,f,n; LL c;} e[N*20];

int getint()
{
	char ch;
	while(!isdigit(ch=getchar()));
	int x=ch-48;
	while(isdigit(ch=getchar())) x=x*10+ch-48;
	return x;
}

void addedge(int u,int v,int f,int c)
{
	e[cnt]=(edge){v,f,h[u],c},h[u]=cnt++;
	e[cnt]=(edge){u,0,h[v],-c},h[v]=cnt++;
}

bool spfa()
{
    rep(i,1,t) dis[i]=-1000000000000000ll,from[i]=-1;
   q[dis[s]=head=tail=0]=s,vis[s]=1;
    while(head<=tail)
    {
        int u=q[head++];
        for(int i=h[u],v; i!=-1; i=e[i].n)
            if(e[i].f>0 && dis[v=e[i].v]<dis[u]+e[i].c)
                if(dis[v]=dis[u]+e[i].c,from[v]=i,!vis[v])
                    vis[q[++tail]=v]=1;
        vis[u]=0;
    }
    return dis[t]!=-1000000000000000ll;
}

void mcf()
{
    int i=from[t],x=INF;
    while(i!=-1)
    {
        x=min(x,e[i].f);
        i=from[e[i^1].v];
    }
    i=from[t];
    ans+=x*dis[t];
    while(i!=-1)
    {
        e[i].f-=x,e[i^1].f+=x;
        i=from[e[i^1].v];
    }
}
 

int main()
{
	n=getint();
	memset(h,-1,sizeof(h));
	s=n*2+8+1,t=s+1;
	rep(i,1,n)
	{
		int x=getint(),y=getint(),c=getint();
		addedge(s,i,c,0);
		addedge(i,2*n+1,INF,x+y);
		addedge(i,2*n+2,INF,x-y);
		addedge(i,2*n+3,INF,-x+y);
		addedge(i,2*n+4,INF,-x-y);
	}
	
	rep(i,1,n)
	{
		int x=getint(),y=getint(),c=getint();
		addedge(i+n,t,c,0);
		addedge(2*n+5,i+n,INF,x+y);
		addedge(2*n+6,i+n,INF,x-y);
		addedge(2*n+7,i+n,INF,-x+y);
		addedge(2*n+8,i+n,INF,-x-y);
	}

	addedge(2*n+1,2*n+8,INF,0);
	addedge(2*n+2,2*n+7,INF,0);
	addedge(2*n+3,2*n+6,INF,0);
	addedge(2*n+4,2*n+5,INF,0);
	
	while(spfa())
		mcf();
	printf("%lld\n",ans);
	return 0;
}

Measured memory_bytes: 640
#include <iostream>
#include <ios> 
#include <vector>
#include <string>
#include <algorithm>
#include <functional>
#include <queue>
#include <set>
#include <cmath>
#include <map>
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define rep1(i,n) for(int i=1;i<=(int)(n);i++)

using namespace std;
typedef long long int lli;
const int MAX=2e5+2;

int main(){
	lli N;
	cin>>N;
	lli A[MAX];
	rep(i,N){
		cin>>A[i];
		A[i]-=i;
	}
	sort(A,A+N);
	lli b=A[(N-1)/2];
	lli ans=0;
	rep(i,N){
		ans+=abs(A[i]-b);
	}
	cout<<ans;
}

Measured memory_bytes: 1792
#include <bits/stdc++.h>
using namespace std;
#define  rep(i, n) for(int i = 0; i < n; i++) 
#define  all(x) (x).begin(),(x).end()     // 昇順ソート
#define  rall(v) (v).rbegin(), (v).rend() // 降順ソート
#define  INF 1LL << 60
typedef long long int LL;
typedef long long int ll;
#define pll pair<ll, ll>
#define F first
#define S second
const int MOD = 1000000007;
template<class T> bool chmax(T &a, const T &b) { if (a<b) { a=b; return true; } return false; }
template<class T> bool chmin(T &a, const T &b) { if (a>b) { a=b; return true; } return false; }
//sort(all(x))とするとソートできるよ
// 10^x は pow(10,(x)) 
// 任意のlogは　対数の底の変換を使う    log(N) / log(任意の底)

int main(){
    LL N,K,Q;cin >> N >> K >> Q;
    vector<LL> A(Q);
    rep(i,Q)cin >> A[i];
    vector<LL> score(N+1,K-Q);
    rep(i,Q)score[A[i]]++;
    rep(i,N+1){
        if(i == 0)continue;
        if(score[i] > 0)cout << "Yes" << endl;
        else cout << "No" << endl;
    }
}



Measured memory_bytes: 2176
#include<stdio.h>
int main(void){
    int a,b;
    scanf("%d %d",&a,&b);
    if(a==b){
        printf("%d\n",a+b);
    }else if(a>b){
        printf("%d\n",a+a-1);
    }else{
        printf("%d\n",b+b-1);
    }
    return 0;
}


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

int main() {
  int n;
  double m;
  cin>>n>>m;
  double vote=0;
  vector<int> item(n);
  for(int i=0;i<n; i++){
    cin>> item.at(i);
    vote+=item.at(i);
  }
  for(int i=0;i<n; i++){
    for(int j=0;j<i; j++){
      if(item.at(i)>item.at(j))swap(item.at(i),item.at(j));
  }
  }
  if (item.at(m-1)>=vote/(4.0*m) )cout<<"Yes"<<endl;
  else {cout<<"No"<<endl;}
 
}






Measured memory_bytes: 256
import Foundation

func solve(_ arr: [Int], _ m: Int) -> Int {
    var dp = [[Int]](repeating:[Int](repeating: 0, count: 3), count: arr.count) //stock, remainder, money
    dp[0] = [m/arr[0], m%arr[0], m]
    for i in stride(from: 1, to: arr.count, by: 1) {
        let ifBoughtStockPreviousDay = arr[i] * dp[i-1][0] + dp[i-1][1]
        let moneyTillPreviousDay = dp[i-1][2]
        if ifBoughtStockPreviousDay >= moneyTillPreviousDay {
            dp[i] = [dp[i-1][0], dp[i-1][1], arr[i] * dp[i-1][0] + dp[i-1][1]]
        } else {
            let m = dp[i-1][2]
            dp[i] = [m/arr[i], m%arr[i], m]
        }
    }
    return dp.last![2]
}


let n = Int(readLine()!)!
let arr = readLine()!.split(separator: " ").map { Int($0)! }

print(solve(arr, 1000))


Measured memory_bytes: 13664
#include <stdio.h>

int main(){
 
  char n[200001];
  scanf("%s",n);
  
  int i;
  long long sum = 0;
  for(i=0;n[i]!='\0';i++){
    sum+=n[i]-'0';
  }
  if(sum%9==0)
    printf("Yes\n");
  else
    printf("No\n");
  return 0;
}

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

int main() {
    int n, m;
    cin >> n >> m;
    vector<vector<int>> adj(n);
    for (int i = 0; i < m; i++) {
        int u, v;
        cin >> u >> v;
        u--; v--;
        adj[u].push_back(v);
        adj[v].push_back(u);
    }
    vector<int> comps, visited(n);
    int siz = 0;
    function<void(int)> dfs = [&](int u) {
        visited[u] = 1;
        siz++;
        for (int v : adj[u]) {
            if (!visited[v])
                dfs(v);
        }
    };
    for (int i = 0; i < n; i++) {
        if (!visited[i]) {
            siz = 0;
            dfs(i);
            comps.push_back(siz);
        }
    }
    int ans = 0;
    for (int x : comps)
        ans = max(ans, x);
    cout << ans << '\n';
}

Measured memory_bytes: 27408
# using dp with memoization, TLE
from sys import stdin
N, W = map(int, input().split())
m = stdin.read().splitlines()
s = [[int(i) for i in line.split()] for line in m]

dp = [0] * (W + 1)

for n in range(1, N + 1):
    w0, v0 = s[n - 1]
    for w in range(W, w0 - 1, -1):

        dp[w] = max(dp[w], dp[w - w0] + v0)

print(dp[W])


Measured memory_bytes: 41580
#include<bits/stdc++.h>
using namespace std;
#define     int                long long
#define     ll                 long long
#define     start              int t;cin>>t;while(t--)
#define     f(n)               for(ll i=0;i<n;i++)
#define     fk(i,k,n)          for(ll i=k;i<=n;i++)
#define     al(s)              s.begin(),s.end()
#define     mp                 make_pair
#define     isvowel(a)         (a=='a' or a=='e' or a=='o' or a=='i' or a=='u')
#define     pb                 push_back
#define     ln                 cout<<"\n"
#define     sum(v)             accumulate(v.begin(), v.end(), 0ll)
#define     db1(x)           cout<<(#x)<<" is "<<x<<endl
#define     db2(x,y)           cout<<(#x)<<" is "<<x<<endl<<(#y)<<" is "<<y<<endl
#define     MOD                1000000007
#define     mii                map<int,int>
#define     vi                 vector<int>
#define     vii                vector<pair<int, int> >

const int N=2e5+20;
void print(vector<int> v, int n){f(n){cout<<v[i]<<" ";}}

void run()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);cout.tie(0);
   /* #ifndef ONLINE_JUDGE 
    freopen("input.txt", "r", stdin);freopen("output.txt", "w", stdout);
    #endif  */  
}

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

 int x=ceil(a/(0.08));
 int y=ceil(b/(0.1));

 int z=(x*0.1);
 int z1=(y*0.08);
//db2(x,y);
 if(z==b)
    cout<<x;
else if(z1==a)
    cout<<y;
else
    cout<<-1;


}

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

using namespace std;
using ll=long long;

#define rep(i, a, n) for (int i = (a); i < (n); i++)

int main(){
  std::cin.tie(nullptr);                  // 標準入出力高速化
  std::ios_base::sync_with_stdio(false);  // SとS++の入出力出力を非同期
  ll n;
  cin>>n;
  ll ans[n];
  ans[0]=1;
  int b=1e9+7;
  rep(i,1,n){ans[i]=ans[i-1]*(i+1)%b;}
  cout<<ans[n-1]<<endl;
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define REP(i, n) for (int i = 0; i < (n); ++i)
#define SORT(v) sort((v).begin(), (v).end())
#define RSORT(v) sort((v).rbegin(), (v).rend())
const ll MOD = 1000000007;
const int nmax = 8;
bool graph[nmax][nmax];

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

ll lcm(ll a, ll b)
{
    ll g = gcd(a, b);
    return a / g * b;
}

ll mulMod(ll a, ll b)
{
    return (((a % MOD) * (b % MOD)) % MOD);
}
int dfs(int v, ll N, bool visited[nmax])
{
    bool all_visited = true;

    for (int i = 0; i < N; i++)
    {
        if (!visited[i])
        {
            all_visited = false;
        }
    }

    if (all_visited)
    {
        return 1;
    }
    int ret = 0;
    for (size_t i = 0; i < N; i++)
    {
        if (!graph[v][i])
        {
            continue;
        }
        if (visited[i])
        {
            continue;
        }

        visited[i] = true;
        ret += dfs(i, N, visited);
        visited[i] = false;
    }

    return ret;
}

void solve(long long N, long long A, std::vector<long long> x)
{
}
ll dp[51][51][3010];
int main()
{
    long long N;
    long long A;
    cin >> N >> A;
    std::vector<long long> x(N);
    for (int i = 0; i < N; i++)
    {
        cin >> x[i];
    }
    dp[0][0][0] = 1;
    for (int i = 0; i < N; i++)
    {
        for (int j = 0; j < N; j++)
        {
            for (int k = 0; k < 2500; k++)
            {
                if (dp[i][j][k])
                {
                    dp[i + 1][j][k] += dp[i][j][k];
                    dp[i + 1][j + 1][k + x[i]] += dp[i][j][k];
                }
            }
        }
    }
    ll ans = 0;
    for (int i = 1; i < N + 1; i++)
    {
        ans += dp[N][i][i * A];
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 58240
shops, need_drink = [int(x) for x in input().split()]

price_quantity = []
for count in range(shops):
    data = [int(x) for x in input().split(" ")]
    price_quantity.append(data)

#print(price_quantity)

price_quantity.sort(key=lambda x: x[0])
bought_drink = 0
counter2 = 0
total_cost = 0
# print(price_quantity)
while bought_drink < need_drink:
    if (price_quantity[counter2][1] + bought_drink) < need_drink:
        bought_drink += price_quantity[counter2][1]
        total_cost += price_quantity[counter2][0] * price_quantity[counter2][1]
    else:
        while price_quantity[counter2][1] != 0:
            price_quantity[counter2][1] -= 1
            bought_drink += 1
            total_cost += price_quantity[counter2][0]
            if bought_drink >= need_drink:
                break
    counter2 += 1

print(total_cost)


Measured memory_bytes: 22760
#include <bits/stdc++.h>
#define endl "\n"
using namespace std;
typedef long long int lli;
const lli N=16;
lli dp1[1<<N],dp2[1<<N];

int main()
{
    ios::sync_with_stdio(0);
    cin.tie(0); cout.tie(0);
    lli n;
    cin>>n;
    lli i,j,k,a[n][n];
    
    for(i=0;i<n;i++) for(j=0;j<n;j++) cin>>a[i][j];
    
    //O(2^n * n^2)
    //dp1[mask] => total score if on bit in mask are in one group  
    for(i=0;i<1<<n;i++)
    {
        for(j=0;j<n;j++)
        {
            if(i&(1<<j))
            {
                for(k=j+1;k<n;k++)
                {
                    if(i&(1<<k))
                    {
                        dp1[i]+=a[j][k];
                    }
                }
            }
        }
    }
    
    //O(3^n)
    //dp2[mask] => max possible score of mask
    for(i=0;i<1<<n;i++)
    {
        for(j=i;j;j=(j-1)&i)
        {
            dp2[i]=max(dp2[i], dp1[j]+dp2[i-j]);
        }
    }
    
    cout<<dp2[(1<<n)-1];
    return 0;
}

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

const int N = 305, inf = 0x3f3f3f3f;
typedef long long ll;
ll n, m, L, Q, dis[N][N], ans[N][N];

int main() {
    cin >> n >> m >> L;

    memset(dis, 0x3f, sizeof(dis));
    memset(ans, 0x3f, sizeof(ans));
    rep(i, 1, n) dis[i][i] = ans[i][i] = 0;
    rep(i, 1, m) {
        ll x, y, z; cin >> x >> y >> z;
        dis[x][y] = dis[y][x] = min(dis[x][y], z);
    }
    rep(k, 1, n)
        rep(i, 1, n)
            rep(j, 1, n)
                dis[i][j] = min(dis[i][j], dis[i][k] + dis[k][j]);
    rep(i, 1, n) rep(j, 1, n)
        if (dis[i][j] <= L && i != j) ans[i][j] = 1;
    rep(k, 1, n) rep(i, 1, n) rep(j, 1, n)
        ans[i][j] = min(ans[i][j], ans[i][k] + ans[k][j]);

    cin >> Q;
    while (Q--) {
        int x, y; cin >> x >> y;
        if (ans[x][y] >= inf) puts("-1");
        else printf("%lld\n", ans[x][y] - 1);
    }
    return 0;
}


Measured memory_bytes: 1920
n = int(input())
lst = []
lst.append(input())
c = 0

for i in range(n-1):
    word = input()
    
    if word in lst:
        c=1

    if lst[-1][-1] == word[0]:
        lst.append(word)
    else:
        c=1   
  
if c==1:
    print('No')
else:
    print('Yes')

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

#define rep(i, a, b) for(int i = (a); i < int(b); ++i)
#define rrep(i, a, b) for(int i = (a) - 1; i >= int(b); --i)
#define trav(it, v) for(typeof((v).begin()) it = (v).begin(); it != (v).end(); ++it)
#define all(v) (v).begin(), (v).end()
#define what_is(x) cerr << #x << " is " << x << endl;

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

char S[2000005];
int N, K;

void simulate(){
	int pos=0;
	int dir=1;
	while(pos < N && pos >= 0){
		S[pos]='B'-S[pos]+'A';
		if(S[pos] == 'B'){
			dir=-dir;
		}
		else{
		}
		pos += dir;
	}
}

int main(){
	scanf("%d%d", &N, &K);
	scanf("%s", S);
	int translations=0;
	int turns=0;
	while(translations < N){
		int t=1;
		if(S[translations] == 'A'+(translations%2))
			++t;
		if(turns+t > K){
			break;
		}
		turns += t;
		++translations;
	}
	if(translations > 0){
		rep(i,N,2*N){
			S[i] = 'B'-((i-N)%2);
		}
		rep(i,0,N-1){
			S[i] = S[i+translations];
			if(translations%2)
				S[i] = 'A'-S[i]+'B';
		}
		S[N-1]='A';
	}
	K -= turns;
	if(K > 10)
		K = 10+(K%2);
	while(K){
		simulate();
		--K;
	}
	S[N]=0;
	printf("%s\n", S);
	/*simulate();
	printf("%s\n", S);
	simulate();
	printf("%s\n", S);
	simulate();
	printf("%s\n", S);
	simulate();
	printf("%s\n", S);
	simulate();
	printf("%s\n", S);
	simulate();
	printf("%s\n", S);
	simulate();
	printf("%s\n", S);*/
}

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

using namespace std;

#define ll long long
const int mxN=1e5+5;

int main(){
//#ifndef ONLINE_JUGDE
//	freopen("input.txt", "r", stdin);
//	freopen("output.txt", "w", stdout);
//#endif

	ios::sync_with_stdio(0);
    cin.tie(0);
    
    string s;
    cin>>s;
    int ans=0;
    for(int i=0;i<(int)s.size();i++){
    	int a=(s[i]-'0');
    	ans+=a;
	}
	if(ans%9==0)
		cout<<"Yes";
	else
		cout<<"No";
    return 0;
}

Measured memory_bytes: 3752
function bomb(y,x,cnt,f){
   yx[y][x]=("   "+cnt).slice(-3);
   if(y==n-1 && x==n-1)return;
   else if(y==n-1 && f==-1)bomb(y,x+1,cnt+1,1);
   else if(y==n-1 && f==1)bomb(y-1,x+1,cnt+1,1);
   else if(x==n-1 && f==1)bomb(y+1,x,cnt+1,-1);
   else if(x==n-1 && f==-1)bomb(y+1,x-1,cnt+1,-1);
   else if(y==0 && f==1)bomb(y,x+1,cnt+1,-1);
   else if(y==0 && f==-1)bomb(y+1,x-1,cnt+1,-1);
   else if(x==0 && f==-1)bomb(y+1,x,cnt+1,1);
   else if(x==0 && f==1)bomb(y-1,x+1,cnt+1,1);
   else if(f==1)bomb(y-1,x+1,cnt+1,1);
   else if(f==-1)bomb(y+1,x-1,cnt+1,-1);
}
var input = require('fs').readFileSync('/dev/stdin', 'utf8');
var Arr=(input.trim()).split("\n");
var I=1;
while(true){
   var n=Arr.shift()-0;
   if(n==0)break;
   var yx=[];
   for(var i=0;i<n;i++){
      yx[i]=[];
      for(var j=0;j<n;j++){
         yx[i][j]=0;
      }
   }
   bomb(0,0,1,1);
   console.log("Case "+I+":");
   I++;
   console.log(yx.join("\n").replace(/\,/g,""));
}

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

using namespace std;
const int maxn=4e3+5;
string dp[maxn<<1];
char s[maxn<<1];
int a[maxn],b[maxn],n,A,B,t[maxn<<1],p,fi[maxn<<1];
int cnt,group[maxn<<1];
string ans;
int main(){
	scanf("%d",&n);
	scanf("%s",s+1);
	p=1;
	for (int i=1;i<=2*n;i++){
		if (s[i]=='a'){
			a[++A]=i;
			t[i]=A;
			cnt++;
		}else{
			b[++B]=i;
			t[i]=B;
			cnt--;
		}
		group[i]=p;
		if (cnt==0)
			fi[++p]=i+1;
	}
	fi[++p]=n*2+1;
	for (int i=2*n;i>=1;i--){
		int mi=min(a[t[i]],b[t[i]]);
		if (mi != i) continue;
		if (a[t[i]]>b[t[i]]){
			string S="";
			for (int j = i;group[j] == group[i];j++){
				if (b[t[j]] >= i){
					S+=s[j];
				}
			}
			S+=dp[fi[group[i]+1]];
			dp[i]=max(S,ans);
		}else{
			dp[i]=max("ab"+dp[b[t[i]]+1],ans);
		}
		ans=max(ans,dp[i]);
	}
	cout << ans << '\n';
	
	
}

Measured memory_bytes: 14720
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;

#define ll long long
#define db long double
#define ii pair<int,int>
#define vi vector<int>
#define fi first
#define se second
#define sz(a) (int)(a).size()
#define all(a) (a).begin(),(a).end()
#define pb push_back
#define mp make_pair
#define FN(i, n) for (int i = 0; i < (int)(n); ++i)
#define FEN(i,n) for (int i = 1;i <= (int)(n); ++i)
#define rep(i,a,b) for(int i=a;i<b;i++)
#define repv(i,a,b) for(int i=b-1;i>=a;i--)
#define SET(A, val) memset(A, val, sizeof(A))
typedef tree<int ,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update>ordered_set ;
// order_of_key (val): returns the no. of values less than val
// find_by_order (k): returns the kth largest element.(0-based)
#define TRACE
#ifdef TRACE
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>
void __f(const char* name, Arg1&& arg1){
  cerr << name << " : " << arg1 << std::endl;
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args){
  const char* comma = strchr(names + 1, ','); cerr.write(names, comma - names) << " : " << arg1<<" | ";__f(comma+1, args...);
}
#else
#define trace(...)
#endif
const int N=100005,mod=1e9+7;
int add(int x,int y)
{
  x+=y;
  if(x>=mod) x-=mod;
  if(x<0) x+=mod;
  return x;
}
int mult(int x,int y)
{
  ll tmp=(ll)x*y;
  if(tmp>=mod) tmp%=mod;
  return tmp;
}
int pow1(int x,int y)
{
  int ans=1;
  while(y)
    {
      if(y&1) ans=mult(ans,x);
      x=mult(x,x);
      y>>=1;
    }
  return ans;
}
int a[N],pw[N],fact[N],inv[N];
vi v[N];
int ncr(int n,int r)
{
  if(r<0 || n<r) return 0;
  return mult(fact[n],mult(inv[r],inv[n-r]));
}
int main()
{
  std::ios::sync_with_stdio(false);
  cin.tie(NULL) ; cout.tie(NULL) ;
  int n,ind;
  pw[0]=1;
  rep(i,1,N) pw[i]=mult(pw[i-1],2);
  fact[0]=inv[0]=1;
  rep(i,1,N) fact[i]=mult(fact[i-1],i);
  inv[N-1]=pow1(fact[N-1],mod-2);
  repv(i,1,N-1) inv[i]=mult(inv[i+1],i+1);
  cin>>n;
  rep(i,1,n+2)
    {
      cin>>a[i];
      v[a[i]].pb(i);
      if(sz(v[a[i]])==2) ind=a[i];
    }
  int pre=v[ind][0]-1,post=n+1-v[ind][1];
  rep(i,1,n+2)
    cout<<add(ncr(n+1,i),-ncr(pre+post,i-1))<<endl;
  return 0 ;
}


Measured memory_bytes: 8320
#include <algorithm>
#include <bitset>
#include <cassert>
#include <deque>
#include <fstream>
#include <iostream>
#include <map>
#include <math.h>
#include <memory>
#include <queue>
#include <sstream>
#include <stdio.h>
#include <string>
#include <vector>

#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define REP(i, n) FOR(i, 0, n)
#define POW(n) ((n) * (n))
#define ALL(a) (a).begin(), (a).end()
#define dump(v) (cerr << #v << ": " << v << endl)
#define cerr                                                                   \
  if (true)                                                                    \
  cerr

using namespace std;

typedef long long ll;
typedef unsigned long long ull;

typedef vector<int> vi;
typedef vector<double> vd;
typedef vector<string> vs;
typedef vector<unsigned long long> vull;

// ll n = to_T<ll>("114514")
template <class T> T to_T(const string &s) {
  istringstream is(s);
  T res;
  is >> res;
  return res;
}
template <class T> string to_s(const T &a) {
  ostringstream os;
  os << a;
  return os.str();
}

void solve(long long n, long long m) {
  n--;
  m--;
  cout << (n * m) << endl;
}

int main() {
  ios::sync_with_stdio(false);
  long long n;
  long long m;
  cin >> n;
  cin >> m;
  solve(n, m);
  return 0;
}


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

int aar[5010],bar[5010];
int main(){
	int A,B,nex,cnt,kai,res;
	cin>>A>>B;
	for(int i=0;i<A;i++){
		cin>>aar[i];
	}
	for(int i=0;i<B;i++){
		cin>>bar[i];
	}
	res=0;
	for(int i=0;i<B;i++){
		cnt=kai=0;
		for(int j=i;j<B;j++){
			nex=bar[j];
			while(aar[cnt]!=nex){
				cnt++;
				if(cnt>=A){
					goto hog;
				}
			}
			kai++;
			cnt++;
			if(cnt>=A) break;
		}
hog:
		res=max(res,kai);
	}
	cout<<res<<endl;
	return 0;
}

Measured memory_bytes: 1204
from collections import deque
from itertools import chain

INF = 10**18

H, W = map(int, input().split())
A = [input() for _ in range(H)]

q = deque([])
dist = [[INF for _ in range(W)]for _ in range(H)]
for y, A_line in enumerate(A):
    for x, a in enumerate(A_line):
        if a == "#":
            dist[y][x] = 0
            q.append((x, y))

while q:
    t_pos = tx, ty = q.popleft()
    dist_t = dist[ty][tx]

    for dx, dy in ((0, 1), (1, 0), (0, -1), (-1, 0)):
        pos = x, y = tx+dx, ty+dy
        if not (0 <= x < W and 0 <= y < H):
            continue
        elif A[y][x] == "#":
            continue
        elif dist[y][x] <= dist_t + 1:
            continue
        dist[y][x] = dist_t + 1
        q.append(pos)
# print(dist)

r = max(chain(*dist))
print(r)

Measured memory_bytes: 116988
#include <iostream>
#include <vector>
#include <algorithm>
#include <queue>
#include <set>
#include <string>
#include <cmath>
#include <map>
#include <iomanip>
#include <tuple>
#include <functional>
#include <bitset>
#define INF 1000000009
#define LINF 1000000000000000009
#define double long double
#define all(a) a.begin(),a.end()
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
typedef pair<ll, P> PP;
template<class T> bool chmax(T &a, const T&b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> bool chmin(T &a, const T&b) { if (a > b) { a = b; return 1; } return 0; }
ll gcd(ll n, ll m) { return (m ? gcd(m, n%m) : n); }
ll lcm(ll n, ll m) { return n / gcd(n, m)*m; }

int main(){
	int k;
	cin >> k;
	vector<vector<P>> graph(k, vector<P>());
	for (int i = 0; i < k; i++) {
		graph[i].push_back(P((i + 1) % k, 1));
		graph[i].push_back(P((10 * i) % k, 0));
	}
	vector<int> ans(k);
	for (int i = 0; i < k; i++) ans[i] = INF;
	ans[1] = 1;
	priority_queue<P, vector<P>, greater<P>> que;
	que.push(P(1, 1));
	while (!que.empty()) {
		P p = que.top(); que.pop();
		int v = p.second;
		if (ans[v] < p.first) continue;
		for (auto i : graph[v]) {
			if (ans[i.first] > ans[v] + i.second) {
				ans[i.first] = ans[v] + i.second;
				que.push(P(ans[i.first], i.first));
			}
		}
	}
	cout << ans[0] << endl;
}

Measured memory_bytes: 8824
#include<iostream>
#include<algorithm>

using namespace std;
 
string s[1000];
 
int main(){
    int n,l;
    cin >> n >> l;
    for(int i = 0; i < n; i++){
        cin >> s[i];
    }  
    sort(s, s + n);
    
    for(int i = 0; i < n; i++){
        cout << s[i];
    }
    cout << endl;
}

Measured memory_bytes: 256
#include<cstdio>
#include<cstdlib>
#include<iostream>
#include<algorithm>
#include<vector>
#include<stack>
#include<queue>
#include<string>
#include<cmath>
#include<cstdint>
//#include<>
using namespace std;

typedef int64_t i64;typedef int32_t i32;
typedef int16_t i16;typedef int8_t i8;
typedef uint64_t ui64;typedef uint32_t ui32;
typedef uint16_t ui16;typedef uint8_t ui8;

typedef i32 int__;
#define rep(i,j) for(int__ i=0;i<j;i++)
#define repeat(i,j,k) for(int__ i=(j);i<(k);i++)
#define repeat_eq(i,j,k) for(int__ i=(j);i<=(k);i++)
#define all(v) begin(v),end(v)

const i32 INF=1<<30;//=10E10

int main()
{
  while(true){
    i32 N;cin>>N;
    if(N==0)break;
    i32 ans=0;
    repeat(i,1,N){
      int sum=0;
      repeat(j,i,N){
	sum+=j;
	if(sum==N){
	  ans+=1;break;
	}
	if(sum>N)break;
      }
    }
    cout<<ans<<endl;
  }
  return 0;
}

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

using namespace std;

typedef long long ll;
const int maxn = (int) 1e6 + 1;

int n;
int a[maxn], b[maxn];
ll ans;
int main(){
    cin >> n;
    for(int i = 1; i <= n; i++){
        cin >> a[i];
        b[i] = a[i];
    }
    for(int i = 1; i <= n; i++){
        a[i] ^= a[i - 1];
        b[i] += b[i - 1];
    }
    for(int i = 1; i <= n; i++){
        int l = i, r = n;
        while(r - l > 1){
            int mid = (l + r) / 2;
            if((a[mid] ^ a[i - 1]) == b[mid] - b[i - 1]){
                l = mid;
            }
            else {
                r = mid;
            }
        }
        if((a[r] ^ a[i - 1]) == b[r] - b[i- 1]){
            ans += (r - i + 1);
        }
        else {
            ans += (l - i + 1);
        }
    }
    cout << ans;
}


Measured memory_bytes: 5120
S = input()
contain = ["A", "C", "G", "T"]
index = 0
size = 0
maxlen = 0
while index < len(S):
    if S[index] in contain:
        size += 1
    else:
        if size > maxlen:
            maxlen = size
        size = 0
    index += 1
if size > maxlen:
    maxlen = size
print(str(maxlen))

Measured memory_bytes: 3060
#include <stdio.h>
#include <string.h>
int main()
{
  int n;
  scanf("%d",&n);
  char s[n];
  scanf("%s",s);
  if(n%2!=0)
  printf("No");
  else
  {
    int i,flag=0;
    for(i=0;i<(n/2);i++)
    {
    if(s[i]!=s[i+(n/2)])
    {
      flag=1;
      break;
    }
    }
    if(flag==1)
    printf("No");
    else
    printf("Yes");
  }

  return 0;
}

Measured memory_bytes: 128
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <vector>
#include <functional>
#include <queue>
#include <string>
#include <cstring>
#include <numeric>
#include <cstdlib>
#include <cmath>
using namespace std;

typedef long long ll;

#define INF 10e10
#define rep(i,n) for(int i=0; i<n; i++)
#define rep_r(i,n,m) for(int i=m; i<n; i++)
#define MAX 100
#define MOD 1000000007
#define pb push_back

/* add vars here */

string s;

/* add your algorithm here */

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

  int ans = 0;

  int d = s[0] - '0' - 1;
  d += 9 * (n-1);
  ans = max(ans , d);

  d = 0;
  rep(i,n) d += s[i] - '0';
  ans = max(ans, d);

  cout << ans << endl;
}


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

int main(){
   string s,t;
   cin>>s>>t;
   int a =s.size();
   
   if(s==t.substr(0,a)){
       cout<<"Yes"<<endl;
   }
   else{
       cout<<"No"<<endl;
   }
}

Measured memory_bytes: 3644
#include<stdio.h>

int A[100][100];
int B[100];
int C[100];
int D[100];
int time,n;

void visit(int );
void dfs();

int main(){
  int i,j,k;
  int a,b;

  scanf("%d",&n);
  for(i=0;i<n;i++)
  {
    for(j=0;j<n;j++)
    {
      A[i][j] = 0;
    }
  }

  for(i=0;i<n;i++)
  {
    scanf("%d%d",&a,&b);
    for(j=0;j<b;j++)
    {
      scanf("%d",&k);
      A[a-1][k-1] = 1;
    }
  }

  dfs();
  return 0;
}

void visit(int u)
{
  int a;
  D[u] = 1;
  C[u] = ++time;
  for(a=0;a<n;a++)
  {
    if(!A[u][a])continue;
    if(!D[a])visit(a);
  }
  D[u] = 2;
  B[u] = ++time;
}

void dfs()
{
  int d;
  for(d=0;d<n;d++)
  {
    D[d] = 0;
  }
  time = 0;
  for(d=0;d<n;d++)
  {
    if(!D[d])visit(d);
  }
  for(d=0;d<n;d++)
  {
    printf("%d %d %d\n",d+1,C[d],B[d]);
  }
}


Measured memory_bytes: 2108
// Contest.cpp : アプリケーションのエントリ ポイントを定義します。
//

#include"iostream"
#include"string"
#include"vector"
#include"algorithm"

using namespace std;

int main()
{
	/*int n,k;
	cin >> n;
	vector<char>s(n);
	for (int j = 0; j < n; j++)  cin >> s[j];
	cin >> k;
	for (int i = 0; i < n; i++)
	{
		if (s[i] != s[k-1]) {
			s[i] = '*';
		}
	}

	for (int l = 0; l < n; l++)
	{
		cout << s[l] ;
	}*/
	
	string s,t;
	cin >>s>>t ;
	int sum = 0;
	for (int i = 0; i < 3; i++) {
		if (s[i] == t[i]) {

			sum++;
			
		}
	}
	cout << sum<<endl;
}






Measured memory_bytes: 256
/*https://atcoder.jp/contests/dp/tasks/dp_b*/
#include <bits/stdc++.h>
#include <sstream> 
#define FAST_IO ios_base::sync_with_stdio(false); cin.tie(NULL);cout.tie(NULL)
#define endl "\n"
#define pi 2*acos(0.0)
#define rep(i,a,b) for(ll i=a;i<b;++i)
#define repe(i,a,b) for(ll i=a;i<=b;++i)
#define CPrint(c)  for(auto i:(c)) { cout<<i<<" "; } nl 
#define eb   emplace_back
#define ef   emplace_front
#define pb   push_back
#define pf   push_front
#define popb pop_back
#define popf pop_front
#define mp   make_pair
#define sz(a) int((a).size())
#define tr(c,i) for(typeof((c).begin() i = (c).begin(); i != (c).end(); i++)
//Allows to traverse any type of macro
#define present(c,x) ((c).find(x) != (c).end())
#define cpresent(c,x) (find(all(c),x) != (c).end())
//debuggers
#define trace2(x,y) cout<<#x<<"="<<x<<" "<<#y<<"="<<y<<endl
#define trace3(x,y,z) cout<<#x<<"="<<x<<" "<<#y<<"="<<y<<" "<<#z<<"="<<z<<endl
#define trace4(w,x,y,z) cout<<#w<<"="<<w<<" "<<#x<<"="<<x<<" "<<#y<<"="<<y<<" "<<#z<<"="<<z<<endl
typedef long long ll;
using namespace std;
typedef vector<int> vi;
typedef vector< vi > vvi;
typedef pair<ll,ll> pll;
const int INF=1e9+5;
int main()
{
	FAST_IO;
ll n,k;
cin >>n >> k;
vector<ll>dp(n,INF);
dp[0] = 0;//base case
vector<ll>h(n);
rep(i,0,n)
{
	cin >> h[i];
}
/* i+1.. i+k abs(h[i]-h[j])
*/
for(int i= 0 ;i<n;i++)
{
	for(int j = i+1;j<=i+k && j<n;j++)
	{
		dp[j] = min(dp[j],dp[i]+abs(h[j]-h[i]));
	}
}
cout << dp[n-1] << endl;
}

Measured memory_bytes: 1792
package main

import (
	"bufio"
	"fmt"
	"math"
	"os"
	"strconv"
)

type Scanner struct {
	sc *bufio.Scanner
}

func NewScanner() *Scanner {
	sc := bufio.NewScanner(os.Stdin)
	sc.Split(bufio.ScanWords)
	sc.Buffer(make([]byte, 1024), int(1e+9))
	return &Scanner{sc}
}

func (s *Scanner) nextStr() string {
	s.sc.Scan()
	return s.sc.Text()
}

func (s *Scanner) nextInt() int {
	i, e := strconv.Atoi(s.nextStr())
	if e != nil {
		panic(e)
	}
	return i
}

func (s *Scanner) nextRuneSlice() []rune {
	return []rune(s.nextStr())
}

func (s *Scanner) nextIntSlice(n int) []int {
	res := make([]int, n)
	for i := 0; i < n; i++ {
		res[i] = s.nextInt()
	}
	return res
}

func main() {
	sc := NewScanner()
	N := sc.nextInt()
	var divisor int
	root := int(math.Floor(math.Sqrt(float64(N))))
	//fmt.Println(root)
	for i := 1; i <= root; i++ {
		if N%i == 0 {
			divisor = i
		}
	}
	quotient := N / divisor
	// fmt.Println(quotient, divisor)
	fmt.Println(quotient + divisor - 2)
}


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

#define REP(i, n) for(int64_t i = 0; i < n; i++)
#define REPR(i, n) for(int64_t i = n; i >= 0; i--)
#define FOR(i, m, n) for(int64_t i = m; i < n; i++)
#define FORR(i, m, n) for(int64_t i = m; i >= n; i--)
#define ALL(v) v.begin(), v.end()
typedef long long ll;
template<typename A, size_t N, typename T>
void Fill(A (&array)[N], const T &val){
    fill( (T*)array, (T*)(array+N), val );
}
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;}
const ll INF= 1ll << 60;
const ll MOD = 1000000007;
double EPS = 1e-10;
//----------------------------------------------------------

int N, K;

int main(){
    cin >> N >> K;
    int ans=0;
    FOR(i, 1, N+1){
        int h;
        cin >> h;
        if(h>=K)ans++;
    }

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

Measured memory_bytes: 256
#include<iostream>
using namespace std;
int main()
{
	int n,x=1,a=0;
	int i = 1;
	cin >> n;
	
	do{
		int x = i;
		if (x % 3 == 0){
			cout << " " << i;
			a = 1;
		}
		if (a==0){
			do{
				if (x % 10 == 3){
					cout << " " << i;
					break;
				}	
				x /= 10;
				
			} while (x);
		}
		else{
			a = 0;
		}
	} while (++i<=n);
	cout << endl;
	return 0;
}

Measured memory_bytes: 3052
#pragma GCC optimize("O3")
#include<bits/stdc++.h> 
using namespace std;
using ll=long long;
using P=pair<ll,ll>;
template<class T> using V=vector<T>; 
#define fi first
#define se second
#define all(v) (v).begin(),(v).end()
const ll inf=(1e18);
//const ll mod=998244353;
const ll mod=1000000007;
ll GCD(ll a,ll b) {return b ? GCD(b,a%b):a;}
ll LCM(ll c,ll d){return c/GCD(c,d)*d;}
struct __INIT{__INIT(){cin.tie(0);ios::sync_with_stdio(false);cout<<fixed<<setprecision(15);}} __init;
template<class T> bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T> bool chmin(T &a, const T &b) { if (a>b) { a=b; return 1; } return 0; }
int main(){
 ll a,b,c,k;
 cin>>a>>b>>c>>k;
 ll ans=0;
 if(a<=k){
   ans+=a;
   k-=a;
 }else{
   ans+=min(a,k);
   k=0;
 }
 if(b<=k){
   k-=b;
 }else{
   k=0;
 }
 if(c<=k){
    ans-=c;
   k=0;
 }else{
   ans-=min(c,k);
 }
 cout<<ans<<"\n";
}


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

#define ll long long
#define FOR(i,a,b) for (int i=(a);i<(b);++i)
#define REP(i,n) for(int i=0;i<(n);++i)
#define debug(x) cerr<<#x<<": "<<x<<'\n'

using namespace std;
typedef pair<int, int> P;
typedef pair<ll, ll> LP;
typedef pair<int, P> PP;
typedef pair<ll, LP> LPP;

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

template<class T=int>
T in(){T x;cin>>x;return (x);}
template<class T>
void print(T& x){cout<<x<<'\n';}

const int MOD =(int)1e9+7;
const int MAX =510000;

ll fac[MAX],finv[MAX],inv[MAX];
void COMint(){
    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 COM(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 gcd(ll a,ll b){
    if(b==0)return a;
    if(a>b){
        swap(a,b);
    }
    return gcd(a,b%a);
}
ll lcm(ll a,ll b){
    ll g;g=gcd(a,b);
    return a*b/g;
}
int main() {
    //COMint();
    int N=in();
    ll a;
    ll ans;ans=0;
    REP(i,N){
        cin>>a;
        REP(i,40){
            if(a%2==0){
                ans++;
                a/=2;
            }else{
                break;
            }
        }
    }
    print(ans);
}

Measured memory_bytes: 256
#include<bits/stdc++.h>	
#define int long long int
#define pb push_back
#define endl "\n"
#define F first
#define S second 
#define mod 1000000007     
using namespace std;

main()
{	
	ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
	string s;
	cin >> s;
	string f[2];
	int rox = 0;
	int q;
	cin >> q;     //front is 0
	for(int i = 0; i < q; i++){
		int x;
		cin >> x;
		if(x == 1){
			rox = 1 - rox;
			swap(f[0], f[1]);
		}
		else{
			int y;
			cin >> y;
			char c;
			cin >> c;
			if(y == 1){
				f[0] += c;
			}
			else f[1] += c; 
		}
	}
	if(rox == 0){
		reverse(f[0].begin(), f[0].end());
		cout << f[0] << s << f[1];
	}
	else{
		reverse(f[0].begin(), f[0].end());
		reverse(s.begin(), s.end());
		cout << f[0] << s << f[1];
	}
}

Measured memory_bytes: 1040
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
using namespace std;
int INF = 1000000007;
 
 
int main(){
  cin.tie(nullptr);
  ios::sync_with_stdio(false);
 
  int N;
  cin >> N;
  pair<double, double> P[N];
  for(int i=0;i<N;i++){
    cin >> P[i].first >> P[i].second;
  }
  double ans = 0;
  for(int i=0;i<N;i++){
    for(int j=i+1;j<N;j++){
      ans += sqrt((P[j].first - P[i].first)*(P[j].first - P[i].first) + (P[j].second - P[i].second)*(P[j].second - P[i].second));
    }
  }
  int kai = 1;
  for(int i=1;i<=N;i++){
    kai *= i;
  }
  ans *= 2;
  ans /= N;

  cout << fixed << setprecision(10);
  cout << ans << endl;
}

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

int main() {
  int k,x;
  cin >> k >> x;
  if(k*500>=x)cout<<"Yes"<<endl;
  else cout<<"No"<<endl;
}

Measured memory_bytes: 384
#include <iostream>
  #include <string>
  #include <vector>
  #include <algorithm>
  #include <utility>
  using namespace std;
  typedef long long ll;
  #define rep(i,n) for (int i=0;i < (int)(n);i++)
  
  
  int main(){
    int n,m,x,y;
    cin >> n >> m >> x >> y;
    int mx = -1,my = 1000;
    rep(i,n) {
      int tmp;
      cin >> tmp;
      mx = max(mx,tmp);
    }
    rep(i,m){
      int tmp;
      cin >> tmp;
      my = min(my,tmp);
    }
    for (x = x+1; x <= y; x++){
      if (mx < x && my >= x){
        cout << "No War" << endl;
        return 0;
      }
    }
    cout << "War" << endl;

    
    return 0;
  }


Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <cstdlib>
#include <cstring>
#include <map>
#include <set>
#include <cmath>
#define cl(A) memset(A, 0, sizeof(A))
using namespace std;

typedef long long LL;
const int MOD = 1e9 + 7;
const int MAXN = 1e5 + 10;

int pow_mod(LL a, int n) {
    LL ret = 1;
    while (n) {
        if (n & 1) {
            ret = (ret * a) % MOD;
        }
        a = a * a % MOD;
        n >>= 1;
    }
    return (int)ret;
}

int n, cnt[MAXN];

int main() {
    scanf("%d", &n);
    for (int i = 0; i < n; i++) {
        int t;
        scanf("%d", &t);
        if (t < MAXN) cnt[t]++;
    }
    if (n & 1) {
        if (cnt[0] != 1) {
            puts("0");
            return 0;
        }
        for (int i = 2; i < n; i += 2) {
            if (cnt[i] != 2) {
                puts("0");
                return 0;
            }
        }
        printf("%d\n", pow_mod(2, n / 2));
    }
    else {
        for (int i = 1; i < n; i += 2) {
            if (cnt[i] != 2) {
                puts("0");
                return 0;
            }
        }
        printf("%d\n", pow_mod(2, n / 2));
    }
    return 0;
}


Measured memory_bytes: 640
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

class Main
{

	public static void main(String[] args)throws IOException
	{
		BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
		String str=br.readLine();
		if(str.length()<4)
		{
			System.out.println("No");
		}
		else
		{
		if(str.substring(0,4).equals("YAKI"))
		{
			System.out.println("Yes");
		}
		else
		{
			System.out.println("No");
		}
		}
	}

}


Measured memory_bytes: 23124
while 1:
    n = input()
    if n == 0:
        break
    dic = {}
    for i in xrange(n):
        for d in map(int, raw_input().split())[1:]:
            dic.setdefault(d, []).append(i)
    E = [{i} for i in xrange(n)]
    for i in xrange(1, 31):
        if i not in dic:
            continue
        di = dic[i]
        su = set()
        for j in di:
            su |= E[j]
        for j in di:
            E[j] = su
        if len(su) == n:
            print i
            break
    else:
        print -1

Measured memory_bytes: 6508
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <cmath>
#include <queue>
#include <set>
#include <map>
#include <iomanip>
#include <fstream>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
const int mod = 1000000007;

int main() {
    ios::sync_with_stdio(false);
    int n, a;
    cin >> n;
    while (n--) {
        cin >> a;
        if (a % 2 == 0 && a % 3 != 0 && a % 5 != 0) {
            cout << "DENIED";
            return 0;
        }
    }
    cout << "APPROVED";
}


Measured memory_bytes: 3600
#pragma once
#include <stdio.h>
#include <sstream>
#include <string>
#include <string.h>
#include <vector>
#include <map>
#include <algorithm>
#include <iostream>
#include <utility>
#include <set>
#include <cctype>
#include <queue>
#include <stack>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <deque>
#include <limits>
#include <iomanip>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
#define bit(x,v) ((ll)x << v)

const ll INF = 1000000007;
const int MAX = 210000;
const int MOD = 1000000007;

long long fac[MAX], finv[MAX], inv[MAX];
void COMinit() {
	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 gcd(ll a, ll b) {
	if (b == 0) return a;
	return gcd(b, a % b);
}
int pr[100010];
void uini(int n) {
	for (size_t i = 0; i <= n; i++)
	{
		pr[i] = i;
	}
}

int parent(int x) {
	if (x == pr[x]) return x;
	return pr[x] = parent(pr[x]);
}

bool unit(int x, int y) {
	int px = parent(x);
	int py = parent(y);

	if (px == py) return false;
	if (px < py) {
		pr[py] = px;
	}
	else {
		pr[px] = py;
	}
	return true;
}

// res[i][c] := i 文字目以降で最初に文字 c が登場する index (存在しないときは n)
vector<vector<int> > calcNext(const string& S) {
	int n = (int)S.size();
	vector<vector<int> > res(n + 1, vector<int>(26, n));
	for (int i = n - 1; i >= 0; --i) {
		for (int j = 0; j < 26; ++j) res[i][j] = res[i + 1][j];
		res[i][S[i] - 'a'] = i;
	}
	return res;
}
// mod 1000000007 の世界で a += b する関数
void add(long long& a, long long b) {
	a += b;
	if (a >= MOD) a -= MOD;
}
ll slide(vector<ll>& v, ll a, ll b) {
	ll azv = abs(v[0] - a);
	ll bzv = abs(v[0] - b);
	ll aov = abs(v[1] - a);
	ll bov = abs(v[1] - b);
	v[0] = a;
	v[1] = b;
	return max((azv + bov), (bzv + aov));
}


void solv() {

	int n, c;
	cin >> n >> c;

	int ta[3][35];
	memset(ta, 0, sizeof(ta));
	int col[31][31];
	for (size_t i = 1; i <= c; i++)
	{
		for (size_t j = 1; j <= c; j++)
		{
			cin >> col[i][j];
		}
	}

	for (size_t i = 1; i <= n; i++)
	{
		for (size_t j = 1; j <= n; j++)
		{
			int p;
			cin >> p;
			ta[(i + j) % 3][p]++;
		}
	}

	int tp[3][35];
	memset(tp, 0, sizeof(tp));
	for (size_t i = 0; i < 3; i++)
	{
		for (size_t j = 1; j <= c; j++)
		{
			for (size_t k = 1; k <= c; k++)
			{
				tp[i][j] += ta[i][k] * col[k][j];
			}
		}
	}

	int res = INF;
	for (size_t i = 1; i <= c; i++)
	{
		for (size_t j = 1; j <= c; j++)
		{
			for (size_t k = 1; k <= c; k++)
			{
				if (i == j) continue;
				if (j == k) continue;
				if (i == k) continue;
				res = min(res, tp[0][i] + tp[1][j] + tp[2][k]);
			}

		}

	}
	cout << res << endl;
}
int main(){
	solv();

	return 0;
}


Measured memory_bytes: 256
#include <iostream>

using namespace std;

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

  for (int i = 1; i <= N; ++i) {
    int A;
    cin >> A;
  }

  int ans = 0;
  N -= 1;
  while (true) {
    N -= (K-1);
    ans++;
    if (N <= 0) break;
  }

  cout << ans << endl;
}


Measured memory_bytes: 256