akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int main() {
  ll n;
  cin >> n;
  vector<ll> a(n);
  for(int i=0;i<n;i++){
    cin >> a[i];
  }
  
  ll ans=0;
  for(int i=0;i<n;i++){
    if(a[i] == i+1){
      ans++;
      if(i<n-1 && a[i+1] != i+1){
        ll tmp=a[i+1];
        a[i+1] = a[i];
        a[i] = tmp;
      }else if(i>0 && a[i-1] != i){
        ll tmp = a[i-1];
        a[i-1] = a[i];
        a[i] = tmp;
      }
    }
  }
  
  /*
  for(int i=0;i<n;i++){
    cout << a[i] << endl;
  } 
  */
  
  cout << ans << endl;
  
  return(0);
}

Measured memory_bytes: 3988
x,y,z,k = map(int, input().split())
a = sorted(map(int, input().split()), reverse=True)
b = sorted(map(int, input().split()), reverse=True)
c = sorted(map(int, input().split()), reverse=True)

d = []
for i in range(x):
    for j in range(y):
        d.append(a[i]+b[j])

d = sorted(d, reverse=True)
d = d[0:min(k,len(d))]
w = len(d)

e = []
for i in range(min(k,z)):
    for j in range(min(k,w)):
        e.append(c[i]+d[j])

e = sorted(e, reverse=True)
for f in e[0:k]:
    print(f)


Measured memory_bytes: 140480
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
template <typename T> inline T sqr(T t) {return t*t;}
#define pb push_back
#define mp make_pair
#define endl "\n"

inline void files()
{
    ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
    //freopen("lca.in", "r", stdin);freopen("lca.out", "w", stdout);
    #ifdef _WIN32
        return;
    #endif // _WIN32
}

ll a, b, c, d, n;

int main()
{
    files();
    cin >> a >> b >> c >> d >> n;
    ll mnbottlelitr = min(a*4, min(b*2, min(c, a*2+b)));
    ll kol1=n/2,kol2=n%2;
    ll ans = min(n*mnbottlelitr, kol1*d+kol2*mnbottlelitr);
    cout << ans;
}


Measured memory_bytes: 256
#include <stdio.h>
int main()
{
    char N[4];
    scanf("%s", N);
    if (N[0] == '7' || N[1] == '7' || N[2] == '7')
    {
        printf("Yes\n");
    }
    else
    {
        printf("No\n");
    }
    return 0;
}

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

using namespace std;

bool prime[500005];
vector<int> pvec, vec;
int n, k;


int main(void)
{
	for(int i = 2; i < 800; i++){
		if(prime[i]) continue;
		for(int j = 2*i; j < 500005; j+=i) prime[j] = true;
	}
	for(int i = 2; i < 500005; i++) if(!prime[i]) pvec.push_back(i);
	
	while(1){
		cin >> n >> k;
		if(n == -1 && k == -1) break;
		
		int p = upper_bound(pvec.begin(), pvec.end(), n) - pvec.begin();
		vec.clear();
		for(int i = p; i < p+105; i++){
			for(int j = p; j < p+105; j++){
				if(i > j) continue;
				vec.push_back(pvec[i] + pvec[j]);
			}
		}
		sort(vec.begin(), vec.end());
		cout << vec[k-1] << endl;
	}
	return 0;
}


Measured memory_bytes: 3772
#include<bits/stdc++.h>
using namespace std;
int n,q,d[1<<18],a,b,c,e[1<<17];
void m(int l,int r,int k){if(r<=a||b<=l)return;if(a<=l&&r<=b)d[k]=q;else{m(l,(l+r)/2,k*2+1);m((l+r)/2,r,k*2+2);}}
int main(){
	cin>>a>>q;n=2;while(n<a)n*=2;a=2*n;while(a--)d[a]=114514;e[114514]=INT_MAX;
	while(q--){cin>>a;
		if(a){cin>>a;a+=n-1,b=d[a];while(a)a=(a-1)/2,b=min(b,d[a]);cout<<e[b]<<endl;}
		else{cin>>a>>b>>c;b++,e[q]=c;m(0,n,0);}
	}
	return 0;
}

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

int main() { 
  string s;
  cin >> s;
  bool ok = false;
  for (int i = 0; i < 3; i++) {
    if (s[i] == '7') ok = true;
  }
  cout << (ok ? "Yes" : "No") << endl;
  return 0;
} 

Measured memory_bytes: 3624
#include <iostream>

using namespace std;

int main(){
    string s;
    cin >> s;
    int count = 0;
    for(int i = 0;i < s.length();i++){
        if(s[s.length() - (i + 1)] != s[i]){
            count++;
        }
    }
    cout << count / 2 << endl;
}

Measured memory_bytes: 256
#if !defined(__clang__) && defined(__GNUC__)
#include <bits/stdc++.h>
#else
#include <cstdlib>
#include <climits>
#include <iostream>
#include <cstdint>
#include <vector>
#include <string>
#include <complex>
#include <bitset>
#include <queue>
#include <deque>
#include <stack>
#include <utility>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <regex>
#endif //  !defined(__clang__) && defined(__GNUG__)
#include <boost/lexical_cast.hpp>
#include <boost/algorithm/string.hpp>
#include <boost/multi_array.hpp>
#include <boost/optional.hpp>
#include <boost/math/common_factor_rt.hpp>

using namespace std;

int main()
{
    int64_t N, M;
    std::cin >> N >> M;

    struct Br {
        int64_t a;
        int64_t b;
    };

    std::vector<Br> br;
    for (decltype(M) i = 0; i < M; ++i) {
        int64_t a, b;
        std::cin >> a >> b;
        br.push_back({a, b});
    }

    std::sort(std::begin(br), std::end(br),
              [](const auto& l, const auto& r) {
                  return l.b == r.b ? l.a < l.a : l.b < r.b;
              });

    int64_t ans = 1;
    int64_t b = br[0].b;
    for (int64_t i = 1; i < M; ++i) {
        if (b <= br[i].a) {
            ans++;
            b = br[i].b;
        }
    }

    std::cout << ans << std::endl;

    return 0;
}


Measured memory_bytes: 3444
n = int(input())
a = list(map(int, input().split()))
 
ans = []
for i in range(n):
    c = 0
    while True:
        if a[i]%2 == 0:
            a[i] = a[i]/2
            c += 1
        else:
            ans.append(c)
            break
print(min(ans))

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

int main()
{
    int n;
    cin >> n;
    int a[2][n], dp[2][n];
    for(int i=0; i<2; i++){
        for(int j =0; j<n; j++){
            cin >> a[i][j];
            dp[i][j] = 0;
        }
    }
    dp[0][0] = a[0][0];
    for(int i= 0; i< 2; i++){
        for(int j=0; j<n; j++){
            //くばるDP
            if(j < n-1) 
                dp[i][j+1] = max(dp[i][j+1], dp[i][j] + a[i][j+1]);
            if(i < 1)
                dp[i+1][j] = max(dp[i+1][j], dp[i][j] + a[i+1][j]);
        }
    }
    cout << dp[1][n-1] <<endl;
    return 0;
}

Measured memory_bytes: 256
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<cassert>
#include<iostream>
#include<sstream>
#include<string>
#include<vector>
#include<queue>
#include<set>
#include<map>
#include<utility>
#include<numeric>
#include<algorithm>
#include<bitset>
#include<complex>

using namespace std;

typedef long long Int;
typedef vector<int> vint;
typedef pair<int,int> pint;
#define mp make_pair

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 &t, T f) { if (t > f) t = f; }
template<class T> void chmax(T &t, T f) { if (t < f) t = f; }
int in() { int x; scanf("%d", &x); return x; }

vector<pint> vpint;

int main() {
	int n,m;
	int i,j;
	while(n=in(),m=in()){
		vpint.clear();
		for(i=0;i<m;i++)vpint.push_back(pint(0,-i-1));
		for(i=0;i<n;i++){
			for(j=0;j<m;j++){
				if(in()==1)vpint[j].first++;
			}
		}
		stable_sort(vpint.begin(),vpint.end(),greater<pint>());
		for(i=0;i<m;i++)cout<<-vpint[i].second<<(i==m-1?'\n':' ');
	}
	return 0;
}

Measured memory_bytes: 0
#include<iostream>
#include<vector>
using namespace std;
const int N=1e2+5;
vector<int> lis,ans;
int main(){
    int n,i,j,k,l;
    cin>>n;
    for(i=1;i<=n;i++){
        cin>>j;
        lis.push_back(j);
    }
    for(j=n;j>=1;j--){
        for(i=lis.size()-1;i>=0;i--){
            if(lis[i]==i+1){
                lis.erase(lis.begin()+i);
                ans.push_back(i+1);
                break;
            }
        }
        if(lis.size()!=j-1){
            cout<<-1;
            return 0;
        }
    }
    for(i=ans.size()-1;i>=0;i--){
        cout<<ans[i]<<endl;
    }
}

Measured memory_bytes: 256
#include <stdio.h>
typedef struct node{
  int p,lc,rc,b;
  
} node;

node tree[100000];

int max(int a,int b){
  if(a>b)return a;
  else return b;
}

int getdepth(int x){
  if(tree[x].p==-1){
    return 0;
  } else{
    return getdepth(tree[x].p)+1;
  }
}

int getheight(int x){
  int ans=0,l=tree[x].lc,r=tree[x].rc;
  if(l!=-1)ans=max(ans,getheight(l)+1);
  if(r!=-1)ans=max(ans,getheight(r)+1);
  return ans;
}

int main(){

 
  int n,d,d2,k,l,id;
  int i,j;

  for(i=0;i<100000;i++){
    tree[i].p=-1;
    tree[i].lc=-1;
    tree[i].rc=-1;
    tree[i].b=-1;
  }
  scanf("%d",&n);
  for(i=0;i<n;i++){
    scanf("%d",&id);
    scanf("%d%d",&tree[id].lc,&tree[id].rc);
    tree[tree[id].lc].p=id;
    tree[tree[id].rc].p=id;
    tree[tree[id].lc].b=tree[id].rc;
    tree[tree[id].rc].b=tree[id].lc;
    

  }


  for(i=0;i<n;i++){
    printf("node %d: parent = %d, sibling = %d,",i,tree[i].p,tree[i].b);
    if(tree[i].lc==-1&&tree[i].rc==-1){
      printf(" degree = 0");
    } else if(tree[i].lc==-1||tree[i].rc==-1){
      printf(" degree = 1");
    } else{
      printf(" degree = 2");
    }
    printf(", depth = %d",getdepth(i));
    printf(", height = %d, ",getheight(i));
    if(tree[i].p==-1){
      printf("root");
    } else if(tree[i].lc==-1&&tree[i].rc==-1){
      printf("leaf");
    } else {
      printf("internal node");
    }
    printf("\n");
  }
  
  return 0;
}

Measured memory_bytes: 2164
#include <iostream>
#include <vector>
#include <string>
#include <bitset>
#include <cmath>
#include <iomanip>
#include <stack>
#include <queue>
using namespace std;

#define INF 1e18
#define int long long

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

    if(a <= 5) {
        cout << 0 << endl;
        return 0;
    } else if(a <= 12) {
        cout << b / 2 << endl;
        return 0;
    }

    cout << b << endl;
    return 0;
}


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

typedef pair<int,int> P;
typedef pair<int,P> PP;

int n,m,l;
vector<vector<PP> > edge;


int solve()
{
	
	//??????i??§?????????j????????????????????°
	vector<vector<long> > memo(n,vector<long>(l+1,1000000));
	
	for(int i=0;i<=l;i++) memo[0][i]=0;
	
	priority_queue<PP,vector<PP>,greater<PP> > q;
	
	//?????¨??°0,??????0,?????????l
	q.push(PP(0,P(0,l)));
	
	while(!q.empty()){
		PP tmp=q.top(); q.pop();
		
		int now_v=tmp.first;
		int now_e=tmp.second.first;
		int now_l=tmp.second.second;
								
		for(int i=0;i<edge[now_v].size();i++){
			int to=edge[now_v][i].first;
			int e_num=edge[now_v][i].second.second;
			int cost=edge[now_v][i].second.first;

			//???????????????
			if(now_l>=cost){
				if(memo[to][now_l-cost]>memo[now_v][now_l]){
					memo[to][now_l-cost]=memo[now_v][now_l];
					q.push(PP(to,P(now_e,now_l-cost)));
				}
			}
			
			//?????????????????????
			if(memo[to][now_l]>memo[now_v][now_l]+e_num){
				memo[to][now_l]=memo[now_v][now_l]+e_num;
				q.push(PP(to,P(now_e+e_num,now_l)));
			}			
		}
		
	}
	
	long ans=memo[n-1][0];
	for(int i=1;i<=l;i++) ans=min(ans,memo[n-1][i]);
	
	return ans;
	
}

int main()
{
	
	while(cin>>n>>m>>l,n){		
			
		edge.clear();
		edge.resize(n);
		
		for(int i=0;i<m;i++){
			int a,b,d,e;
			cin>>a>>b>>d>>e;
			a--; b--;
			
			edge[a].push_back(PP(b,P(d,e)));
			edge[b].push_back(PP(a,P(d,e)));
			
		}
		cout<<solve()<<endl;
		
	}
		
	

	return 0;
}

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

int main(){
  int n,k;
  cin>>n>>k;
  vector<int> l(n);
  for(int i=0; i<n; i++)cin>>l.at(i);

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

  int ans=0;
  for(int i=n-1; i>n-1-k; i--)ans+=l.at(i);
  cout<<ans<<endl;
}

Measured memory_bytes: 256
///supercalifragilisticexpialidocious.
#include <cstdio>
#include <cstring>
#include <cmath>
#include <cassert>
#include <cstdlib>
#include <cctype>
#include <ctime>
#include <iostream>
#include <iomanip>
#include <sstream>
#include <numeric>
#include <utility>
#include <string>
#include <algorithm>
#include <vector>
#include <map>
#include <queue>
#include <set>
#include <list>
#include <bitset>
#include <complex>
using namespace std;
#define f first
#define s second
#define endl '\n'
#define PB pop_back
#define pb push_back
#define mp make_pair
#define int long long
#define sz(s) (int)s.size()
#define seper(n) setprecision(n)
#define all(v) v.begin(),v.end()
#define mem(a,b) memset(a,b,sizeof a)
#define IOS ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0);
void debug_out() { cerr << endl; }
template <typename Head, typename... Tail>
void debug_out(Head H, Tail... T) { cerr << " " << H; debug_out(T...); }
#define debug(...) cerr << "{" << #__VA_ARGS__ << "}:", debug_out(__VA_ARGS__)
typedef long long ll;
typedef map<int , int> mii;
typedef pair<int , int> pii;
typedef map<string , int> msi;
const int MAXN = 1e2 + 10;
int n , l , r , a[MAXN] , d[MAXN];
string ans = "Impossible";
int32_t main()
{
	cin >> n , r = n - 1;
	for(int i = 0 ; i < n ; i ++)
		cin >> a[i] , d[a[i]] ++;
	while(!d[l])
		l ++;
	while(!d[r])
		r --;
	if((r + 1) / 2 == l)
	{
		ans = "Possible";
		for(int i = l ; i <= r ; i ++)
		{
			if(i == l)
			{
				if(d[i] != ((r % 2) + 1))
					{ans = "Impossible" ; break;}
			}
			else
			{
				if(d[i] <= 1)
					{ans = "Impossible" ; break;}
			}
		}
	}
	return cout << ans << endl , 0;
}


Measured memory_bytes: 256
//--------------------------------------------------template----------------------------------------//
//c
#include <stdio.h>
#include <time.h>
#include <math.h>
//c++
#include <cstdio>
#include <iostream>
#include <algorithm>
#include <functional>
#include <cstdlib>
#include <sstream>
#include <string>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <deque>
#include <vector>
#include <complex>
#include <cmath>
//c++11
#include <tuple>
#define all(c) ((c).begin(),(c).end())
#define rall(c) (c).rbegin(),(c).rend()
//#define sort(v,n) sort(v,v+n)
//#define vsort(v) sort(v.begin(),v.end())
//#define vvsort(v) sort(v.begin(),v.end(),greater<int>())
#define ll long long
#define pb(a) push_back(a)
#define fi first
#define se second
#define inf 999999999
using namespace std;
const ll MOD = 1e9 + 7;
const double PI = acos(-1.0);
//---------------------------------------------------------------------------------------------//
int a, b, c;
int main() {
	cin >> a >> b >> c;
	if (c >= a && c <= b) {
		cout << "Yes" << endl;
	}
	else {
		cout << "No" << endl;
	}
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <iostream>
using namespace std;
#define Get(x,y) scanf("%I64d%I64d",&x,&y);
#define get(x) scanf("%I64d",&x);
#define Gett(x,y) scanf("%d%d",&x,&y);
#define gett(x) scanf("%d",&x);																																														
#define f(i,a,b) for(int i=a;i<b;i++)
#define f_(i,a,b) for(int i=a;i>=b;i--)
#define print(v,r) f(i,0,r) cout<<v[i]<<" "; cout<<endl;
#define ll long long
#define pb push_back
#define maxm(a,b) a=max(a,b);
#define minm(a,b) a=min(a,b);
#define S second
#define F first
#define mp make_pair
const int N=3e5+20;
double m,n,s=3;
int main(){
	cout.precision(8);
	cin>>n;
	m=n/s;
	m=m*m*m;
	cout<<fixed<<m;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int MOD=1e9+7;
const int INF=1e9;

int main(){
    int n,k;
    string s;
    cin>>n>>k>>s;
    s[k-1]=s[k-1]+'a'-'A';
    cout<<s<<endl;
}


Measured memory_bytes: 256
from collections import deque

def bfs(y,x):
    f=[[float("inf")]*(w+1) for i in range(h+1)]
    f[y][x]=0
    que=deque([])
    que.append((y,x))
    dx=[1,0,-1,0]
    dy=[0,1,0,-1]
    while que:
        p=que.popleft()
        if p[0]==h and p[1]==w:
            break
        for i in range(4):
            nx=p[1]+dx[i]
            ny=p[0]+dy[i]
            if 0<=nx<w+1 and 0<=ny<h+1 and f[ny][nx]==float("inf") and maze[ny][nx]!="#":
                que.append((ny,nx))
                f[ny][nx]=f[p[0]][p[1]]+1
    return f[h][w]

h,w=map(int,input().split())
h-=1
w-=1
maze=[list(input()) for i in range(h+1)]
#print(maze)
cnt=0
for i in range(h+1):
    for j in range(w+1):
        if maze[i][j]==".":
            cnt+=1
route=bfs(0,0)
score=cnt-route-1
if 0<route<float("inf"):
    print(score)
else:
    print(-1)

Measured memory_bytes: 40944
#include<bits/stdc++.h>
using namespace std;
#define fi first
#define se second
#define rep(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define rrep(i,n) for(int i=1,i##_len=(n); i<=i##_len; ++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(obj) (obj).begin(), (obj).end()
#define maxs(x,y) (x=max((x),(y)))
#define mins(x,y) (x=min((x),(y)))
#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 pb push_back
#define sz(x) (int)(x).size()
#define uni(x) x.erase(unique(rng(x)),x.end())
#define show(x) cout<<#x<<" = "<<x<<endl;
#define PQ(T) priority_queue<T,v(T),greater<T>>
#define bn(x) ((1<<x)-1)
#define dup(x,y) (((x)+(y)-1)/(y))
#define newline puts("")
#define v(T) vector<T>
#define vv(T) vector<vector<T>>
using ll = long long;
using ull = unsigned long long;
using uint = unsigned int;
using P = pair<int,int>;
using vi = vector<int>;
using vvi = vector<vi>;
using vl = vector<ll>;
using vp = vector<P>;
template <class T> inline istream& operator>>(istream&i,v(T)&v)
{ rep(j,sz(v))i>>v[j];return i;}
template <class T> string join(const v(T)&v)
{ stringstream s;rep(i,sz(v))s<<' '<<v[i];return s.str().substr(1);}
template <class T> inline ostream& operator<<(ostream&o,const v(T)&v)
{ if(sz(v))o<<join(v); return o;}
template <class T1,class T2> inline istream& operator>>(istream&i ,pair<T1,T2>&v)
{ return i>>v.fi>>v.se;}
template <class T1,class T2> inline ostream& operator<<(ostream&o ,pair<T1,T2>&v)
{ return o<<v.fi<<","<<v.se;}
template <class T> inline ll suma(const v(T)& a) 
{ ll res(0); for(auto&& x:a) res += x; return res;}
const int INF = 1001001001;
const ll LINF = 1001002003004005006ll;
const double eps = 1e-10;
const int MX = 200005;
//----------------------------------------------------------------

#define fileio ifstream fio; if(argc>=2){fio.open(argv[1]); std::cin.rdbuf(fio.rdbuf());}
#define fastio ios_base::sync_with_stdio(false);
#define MOD 1000000007
//----------------------------------------------------------------

void Main(){
  int n,m;
  cin>>n>>m;
  set<int> f,s;
  rep(i,m){
    int a,b;
    cin>>a>>b;
    if(a==1){f.insert(b);}
    if(b==n){s.insert(a);}
  }
  vi res;
  set_intersection(rng(f),rng(s),inserter(res,res.end()));
  if(res.size()>0){
    cout<<"POSSIBLE"<<endl;
  }else{
    cout<<"IMPOSSIBLE"<<endl;
  }
} int main(int argc,char* argv[]){ 
    fastio; fileio; Main();}

Measured memory_bytes: 9600
# -*- coding: utf-8 -*-

N, D = list(map(int, input().split()))
cor = []
for i in range(N):
    cor.append(list(map(int, input().split())))

cnt = 0
for i in range(N-1):
    p1 = cor[i]
    for j in range(1, N-i):
        p2 = cor[i+j]
        tmp = 0
        for k in range(D):
            tmp += (p1[k] - p2[k]) ** 2
        if float.is_integer(tmp ** 0.5):
            cnt += 1

print(cnt)

Measured memory_bytes: 3064
import java.io.*;

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

		BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));

		String str = reader.readLine();
		int N = Integer.parseInt(str);

		int A[] = new int[N];

		for (int i = 0; i < N; i++) {
			A[i] = 0;
		}
		
		String a = reader.readLine();//行を読み込む
      	String[] data = a.split(" ");//スペース区切りで配列に格納
		for (int i = 0; i < N - 1; i++) {
			int count = Integer.parseInt(data[i]);//dataのi番目をintに変換
			A[count - 1]++;
		}

		for (int i = 0; i < N; i++) {
			System.out.println(A[i]);
        }
    }
}


Measured memory_bytes: 67728
#include<iostream>
#include<vector>
#include<map>
#include<unordered_map>
#define mod 1000000007
using namespace std;
#define LL long long int 
LL dfs(LL src,vector<LL> *adj,vector<bool> &vis)
{
    if(vis[src]==false)
    {
        vis[src]=true;
        LL count=1;
        for(auto it:adj[src])
        {
            if(vis[it]==false)
            {
                count+=dfs(it,adj,vis);
            }
        }
        return count;
    }
    return 0;
}
int main() 
{
    // freopen("input.txt","r",stdin);
    // freopen("output.txt","w",stdout);
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    LL N, M;
    cin >>  N  >> M;
    vector<LL> adj[N+1];
    for(LL i=0;i<M;i++)
    {
        LL x,y;
        cin >> x >> y;
        adj[x].push_back(y);
        adj[y].push_back(x);
    }
    LL ans=0;
    vector<bool> vis(N+1,false);
    for(LL i=1;i<=N;i++)
    {
        if(vis[i]==false)
        {
            LL count=dfs(i,adj,vis);
            ans=max(ans,count);
        }
    }
    cout<<ans;

}
 
 

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

#define rep(i,n) for(int i=0; i<(n); i++)
#define reps(i,x,n) for(int i=x; i<(n); i++)
#define rrep(i,n) for(int i=(n)-1; i>=0; i--)
#define all(X) (X).begin(),(X).end()
#define X first
#define Y second
#define pb push_back
#define eb emplace_back

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

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

template<class A, size_t N, class T> void Fill(A (&a)[N], const T &v){ fill( (T*)a, (T*)(a+N), v ); }

template<class T> ostream& operator<<(ostream &os, const vector<T> &t) {os<<"{"; rep(i,t.size()) {os<<t[i]<<",";} os<<"}"; return os;}
template<class T,size_t n> ostream& operator<<(ostream &os, const array<T,n> &t) {os<<"{"; rep(i,n) {os<<t[i]<<",";} os<<"}"; return os;}
template<class S, class T> ostream& operator<<(ostream &os, const pair<S,T> &t) { return os<<"("<<t.first<<","<<t.second<<")";}

const ll INF = 1e9+7;


vector<int> edge[200005];
int ans[200005];
pii sum[200005];
pii dfs(int n, int b, pii mx={}){
	for(auto t: edge[n]) if( t != b ){
		auto ret = dfs(t, n, max(mx, {n, mx.X}));
		if( mx.X < n ) ret = pii(ret.Y, 0);
		if( t < mx.X ) sum[n].X += ret.X + 1;
		if( t < mx.Y ) sum[n].Y += ret.Y + 1;
	}
	return sum[n];
}

void dfs2(int n, int b, pii mx={}, int s=0){
	ans[n] = s + sum[n].X;
	for(auto t: edge[n]) if( t != b ){
		int cost = s + sum[n].X + 1;
		if( t < mx.X ) cost -= (mx.X < n ? sum[t].Y : sum[t].X) + 1;
		dfs2(t, n, max(mx, {n, mx.X}), cost);
	}
}

int main(){
	ios_base::sync_with_stdio(false);
	int N;

	cin >> N;
	rep(i,N-1){
		int a, b;
		cin >> a >> b;
		a--; b--;
		edge[a].push_back(b);
		edge[b].push_back(a);
	}

	dfs(0, -1);
	dfs2(0, -1);

	//rep(i,N) cout << sum[i] << " "; cout << endl;

	rep(i,N-1) cout << ans[i+1] << " "; cout << endl;

	return 0;
}

Measured memory_bytes: 33664
#include <bits/stdc++.h>
using namespace std;
#define REP(i,n) for(int i=0;i<n;i++)
typedef priority_queue <int> pi;
typedef priority_queue <int, vector<int>, greater<int>> pg;
typedef unsigned long long int ulli;

int main() {
    ulli X, Y;
    cin >> X >> Y;
    if(X % Y == 0){
        cout << "-1" << endl;
    }else{
        int k = 0;
        ulli ans = 0;
        while(1){
            ++k;
            ans = X * k;
            if(ans % Y != 0) break;
        }
        cout << ans << endl;
    }
}

Measured memory_bytes: 256
s = input()

z_g = 0
z_k = 0
o_g = 0
o_k = 0

for i in range(len(s)):
    if i % 2 == 0:
        if s[i] == "0":
            z_g += 1
        else:
            o_g += 1
    else:
        if s[i] == "0":
            z_k += 1
        else:
            o_k += 1

if (z_g + o_k) > (z_k + o_g):
    print(z_k + o_g)
else:
    print(z_g + o_k)

Measured memory_bytes: 3188
#include <cmath>

#include <algorithm>
#include <iostream>
#include <string>
#include <vector>

using namespace std;

using ll = long long;
using ld = long double;
using vi = vector<int>;

int n;

vi a;

void input() {
  cin >> n;

  a.resize(n);
  for (auto&& i : a)
    cin >> i;
}

void solve() {
  sort(a.begin(), a.end());

  int ans = 0;

  for (auto&& i : a)
    ans += i;

  if (ans % 10 != 0) {
    cout << ans << '\n';

    return;
  }

  bool ok = false;

  for (int j = 0; j < n; ++j) {
    if ((ans - a[j]) % 10 != 0) {
      ans -= a[j];

      ok = true;

      break;
    }
  }

  if (!ok)
    ans = 0;

  cout << ans << '\n';
}

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

  cout.precision(16);
  cout << fixed;

  int _times = 1;

#ifdef _DEBUG
  freopen("input.txt", "r", stdin);
  //freopen("output.txt", "w", stdout);

  _times = 3;
#endif

  // cin >> _times;

  while (_times--) {
    input();
    solve();
  }
}


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

#define fi first
#define se second
#define pb push_back
#define all(x) begin(x), end(x)
#define sz(x) (int)(x).size()
#define FOR(i, a, b) for (int i = a; i <= (b); i++)
#define ROF(i, a, b) for (int i = a; i >= (b); i--)

using pii = pair<int, int>; using vpii = vector<pii>;
using vi = vector<int>; using vvi = vector<vi>;
using ll = long long;
using pll = pair<ll, ll>; using vpll = vector<pll>;
using vll = vector<ll>; using vvll = vector<vll>;

int main() {
    ll n, k; cin >> n >> k;
    vi a(n + 1);
    FOR(i, 1, n) cin >> a[i];
    vector <bool> vis(n + 1);
    vi og;
    int u = 1, sz = 0;
    while (!vis[a[u]]) {
        og.pb(u);
        vis[u] = 1, u = a[u];
    }
    og.pb(u);
    vector <int> p;
    int v = a[u];
    while (1) {
        if (v == u) break;
        p.pb(v);
        v = a[v];
    }
    p.pb(u);
    if (k < og.size())
        cout << og[k] << endl;
    else {
        k -= og.size() - p.size();
        cout << p[k % p.size()] << endl;
    }
}

Measured memory_bytes: 6216
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner scan = new Scanner(System.in);
        int n = scan.nextInt();
        int[] a = new int[n];
        int[] b = new int[n];
        int[] c = new int[n - 1];
        int ans = 0;
        for(int i = 0; i < n; i++) {
        	a[i] = scan.nextInt();
        }
        for(int i = 0; i < n; i++) {
        	b[i] = scan.nextInt();
        	ans += b[i];
        }
        for(int i = 0; i < n - 1; i++) {
        	c[i] = scan.nextInt();
        }

        int temp = a[0];
        for(int i = 1; i < n; i++) {
        	if(a[i] - 1 == temp) {
        		ans += c[temp - 1];
        	}
        	temp = a[i];
        }
        System.out.println(ans);
    }
}

Measured memory_bytes: 21844
#if 1
#include <iostream>
#include <fstream>
#include <string>
#include <vector>
#include <map>
#include <set>
#include <unordered_map>
#include <unordered_set>
#include <queue>
#include <stack>
#include <array>
#include <deque>
#include <algorithm>
#include <utility>
#include <cstdint>
#include <functional>
#include <iomanip>
#include <numeric>
#include <assert.h>

auto& in = std::cin;
auto& out = std::cout;

int32_t N,M;
int32_t set[100001];
std::vector<int32_t> graph[100001];
int main()
{
	using std::endl;
	in.sync_with_stdio(false);
	out.sync_with_stdio(false);

	in >> N>>M;
#if 0
	for (int32_t i = 0; i < M; ++i)
	{
		int a, b;
		in >> a >> b;
		--a; --b;
		set[a]++; set[b]--;
	}
	for (int32_t i = 1; i < N; ++i)
	{
		set[i] += set[i - 1];
	}
	if (std::all_of(set, set + N-1, [](int v) {return (v & 1) == 0; }))
	{
		std::cout << "YES\n";
	}
	else {
		std::cout << "NO\n";
	}
#endif

	int32_t remain = 0;
	for (int32_t i = 0; i < M; ++i)
	{
		int a, b;
		in >> a >> b;

		if (set[a] == 0) {
			if (set[b] == 0) {
				set[a] = b;
				set[b] = a;
				++remain;
			}
			else {
				int c = set[b];
				set[a] = c;
				set[c] = a;
				set[b] = 0;
			}
		}
		else {
			if (set[b] == 0) {
				int c = set[a];
				set[b] = c;
				set[c] = b;
				set[a] = 0;
			}
			else {
				if (set[a] == b || set[b] == a) {
					--remain;
					set[a] = set[b] = 0;
				}
				else if (set[a] == set[b]) {
					remain-=2;
					set[a] = set[b] = 0;
				}
				else {
					--remain;
					set[set[a]] = set[b];
					set[set[b]] = set[a];
					set[a] = set[b] = 0;
				}
			}
		}

	}

	std::cout << (remain == 0 ? "YES" : "NO") << std::endl;


	return 0;
}
#endif


Measured memory_bytes: 2944
#include <climits>
#include <cstring>
#include <cmath>
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <queue>
#include <map>
#include <set>
#include <functional>
#define fi first
#define se second
#define FO(x, n) for (int x = 0; x < n; ++x)
#define FOR(x, a, b) for (int x = a; x < b; ++x)
#define RFO(x, n) for (int x = n - 1; x >= 0; --x)
#define RFOR(x, a, b) for (int x = b - 1; x >= a; --x)
using namespace std;
typedef unsigned char byte;
typedef long long llong;
typedef unsigned long long ullong;
typedef pair<int, int> pii;
typedef pair<double, double> pdd;
typedef pair<string, string> pss;
typedef pair<llong, llong> pll;
inline bool feq(const double& a, const double& b) { return fabs(a - b) < 1e-10; }

int H, W;

int main()
{
    while (cin >> H >> W)
    {
        int res = INT_MAX;
        res = min(res, H);
        res = min(res, W);
        if (H % 3 == 0)
            res = 0;
        if (W % 3 == 0)
            res = 0;
        FO (i, 3)
        {
            int h1 = H / 3 + i;
            int h23 = H - h1;
            FO (j, 2)
            {
                int w1 = W / 2 + j;
                int w2 = W - w1;

                int area[3];
                area[0] = h1 * W;
                area[1] = w1 * h23;
                area[2] = w2 * h23;
                sort(area, area + 3);

                res = min(res, area[2] - area[0]);
            }
        }
        FO (i, 3)
        {
            int w1 = W / 3 + i;
            int w23 = W - w1;
            FO (j, 2)
            {
                int h1 = H / 2 + j;
                int h2 = H - h1;

                int area[3];
                area[0] = w1 * H;
                area[1] = w23 * h1;
                area[2] = w23 * h2;
                sort(area, area + 3);

                res = min(res, area[2] - area[0]);
            }
        }
        printf("%d\n", res);
    }
    return 0;
}

Measured memory_bytes: 256
#include <queue>
#include <iostream>
#include <cmath>
#include <cstdlib>
#include <algorithm>
#include <stack>
#include <string>
#include <vector>
#include <map>
#include <functional>
#include <set>

#define rep(i, n) for(int i = 0; i < (n); i++)
#define MAX(a, b) (((a) < (b)) ? (b) : (a))
#define MIN(a, b) (((a) < (b)) ? (a) : (b))

using namespace std;
typedef long long int ll;
typedef pair<ll, ll> pll;
typedef pair<int, int> pint;
const ll inf = (1LL << 60);
const ll mod = 1000000007;
ll max(ll a, ll b) {
	if (a < b)
		return b;
	else
		return a;

}
ll min(ll a, ll b) {
	if (a < b)
		return a;
	else
		return b;

}




int main() {
	ll N;

	cin >> N;
	vector<ll> a(N);
	ll ruiseki = 0;
	rep(i, N) {
		cin >> a[i];
		ruiseki = ruiseki ^ a[i];
	}
	
	ll sum = 0;
	bool flag = true;
	rep(i, N) {

		cerr << (ruiseki^a[i]);
		if (a[i] != (ruiseki ^ a[i])) {
			flag = false;
		}
	}
	
	if (flag == false) {
		cout << "No" << endl;
	}

	else {
		cout << "Yes" << endl;
	}
	return 0;
}

Measured memory_bytes: 1024
// AtCoder.cpp : このファイルには 'main' 関数が含まれています。プログラム実行の開始と終了がそこで行われます。
//

// AtCoder.cpp : このファイルには 'main' 関数が含まれています。プログラム実行の開始と終了がそこで行われます。
//


#define _USE_MATH_DEFINES
#include<math.h>

//#include<cmath>

#include<deque>
#include<queue>
#include<vector>
#include<algorithm>
#include<iostream>
#include<set>
#include<cmath>
#include<tuple>
#include<string>
#include<chrono>
#include<functional>
#include<iterator>
#include<random>
#include<unordered_set>
#include<array>
#include<map>
#include<iomanip>
#include<assert.h>
#include<bitset>
#include<stack>
#include<memory>



//#include "Ants.h"
using namespace std;
typedef long long ll;
#define rad_to_deg(rad) (((rad)/2/M_PI)*360)
#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))
#define rep(i,n) for(int i=0;i<n;i++)
#define show(s) cout<<s<<endl
#define chmin(x,y) x=min(x,y)
#define chmax(x,y) x=max(x,y)
#define LINF (1000000000000000000ll)
typedef pair < int, int> P;
ll gcd(ll a, ll b) {//最大公約数を求める///最大公倍数a*b/gcd(a,b)
	if (b == 0) return a;
	return gcd(b, a % b);
}
ll lcd(ll a, ll b) {//最小公倍数を求める　b=0のときaを返す
	if (b == 0) return a;
	return (a / gcd(a, b)) * b;
}
vector<int> divnum(ll num) {
	int dig;
	vector<int>p;
	while (num) {
		dig = num % 10;
		p.push_back(dig);
		num /= 10;
	}
	return p;
}
int digiter(ll num) {
	int dig;
	vector<int>p;
	while (num) {
		dig = num % 10;
		p.push_back(dig);
		num /= 10;
	}
	return p.size();
}
vector<int> convert(string s) {
	vector<int> d;
	ll n = s.size();
	rep(i, n) {
		d.push_back(s[i]-'0');
	}
	return d;
}
int H, W, K;
string S[100];
int  c[10][10000];
int main()
{
	cin >>H>>W>>K;
	rep(i, H) {
			cin >> S[i];
	
	}

	int ans = INF;
	rep(div, (1 << (H - 1))) {
		int g = 0; int num = 0;
		vector<int>id(H);
		rep(row, H) {
			id[row] = g;
			if ((div >> row) & 1) {
				g++;
			}

		}
		
		g++;
		rep(i, g) rep(j, W)c[i][j] = 0;
		rep(i, H)rep(j, W)c[id[i]][j] += (S[i][j] - '0');
		num = g - 1;vector<int>now(g);
		auto add = [&](int j) {
			rep(i, g) { now[i] += c[i][j]; if (now[i] > K)return false; }
			
			return true;
		};
		rep(j, W) {
			if (!add(j)) {
				num++;
				now = vector<int>(g);
				if (!add(j)) {
					num = INF;
					break;
				}
			}
		}
		
		//cout << num << endl;
		ans = min(ans, num);
	}
	cout << ans << endl;
}

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

int main() {
    int64_t H, W, K;
    cin >> H >> W >> K;
    vector<string> s(H);
    for (int64_t i = 0; i < H; i++) {
        cin >> s[i];
    }

    vector<vector<int64_t>> ans(H, vector<int64_t>(W, -1));
    int64_t index = 1;
    for (int64_t i = 0; i < H; i++) {
        int64_t num = 0;
        for (int64_t j = 0; j < W; j++) {
            if (s[i][j] == '#') {
                num++;
            }
        }

        if (num == 0) {
            continue;
        }

        for (int64_t j = 0; j < W; j++) {
            ans[i][j] = index;
            if (s[i][j] == '#') {
                if (--num > 0) {
                    index++;
                }
            }
        }
        index++;
    }

    for (int64_t i = 0; i < H; i++) {
        if (ans[i][0] == -1) {
            continue;
        }
        for (int64_t ii = i - 1; ii >= 0; ii--) {
            if (ans[ii][0] == -1) {
                ans[ii] = ans[i];
            } else {
                break;
            }
        }
        for (int64_t ii = i + 1; ii < H; ii++) {
            if (ans[ii][0] == -1) {
                ans[ii] = ans[i];
            } else {
                break;
            }
        }
    }

    for (int64_t i = 0; i < H; i++) {
        for (int64_t j = 0; j < W; j++) {
            cout << ans[i][j] << " \n"[j == W - 1];
            assert(1 <= ans[i][j] && ans[i][j] <= K);
        }
    }
}

Measured memory_bytes: 1664
#include <iostream>
#include <string>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <utility>
#include <stack>
#include <numeric>
#include <algorithm>
#include <tuple>
#include <stdio.h>
#include <bitset>
#include <limits.h>
#include <complex>
#include <deque>
#include <iomanip>
#include <list>
using namespace std;
#define pi pair<int32,int32>
#define pl pair<int64,int64>
#define chmax(a,b) (a<b ? a=b:0)
#define chmin(a,b) (a>b ? a=b:0)
#define en cout << endl //セミコロンつけろ
//#define MM 1000000000
//#define MOD MM+7
const int MM = 1e9;
const int MOD = MM+7;
const long double PI = acos(-1);
const long long INF = 1e15;
int dx[8] = {-1,0,1,0,-1,-1,1,1};
int dy[8] = {0,-1,0,1,-1,1,1,-1};
// 'A' = 65, 'Z' = 90, 'a' = 97, 'z' = 122
template<typename T>
T GCD(T u,T v){
    return v ? GCD(v,u%v) : u;
}
template<typename T>
T LCM(T x,T y){
    T gc = GCD(x,y);
    return x*y/gc;
}


int main(){
    int N; cin >> N;
    int ans = 0;
    for(int i = 1; i <= N; i++){
        if (i <= 9){
            ans++;
        } else if (100 <= i && i < 1000){
            ans++;
        } else if (10000 <= i && i < 100000){
            ans++;
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

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

	    int x=gi();
	    int a=gi();
	    int b=gi();


        //System.out.println(Math.min(Math.abs(x-a),Math.abs(x-b)));
        if (Math.abs(x-a)>Math.abs(x-b) ) {
        	System.out.print("B");
        }else {
            System.out.print("A");
        }


	}

	// 文字列として入力を取得
	public static String gs() {
		return scanner.next();
	}

	// intとして入力を取得
	public static int gi() {
		return Integer.parseInt(scanner.next());
	}

	// longとして入力を取得
	public static long gl() {
		return Long.parseLong(scanner.next());
	}
}

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

using namespace std;

int main(){
	int a, b;
	cin >> a >> b;
	
	if(a == 1){
		a = 14;
	}
	if(b == 1){
		b = 14;
	}
	
	if(a == b){
		cout << "Draw" << endl;
	}else if(a > b){
		cout << "Alice" << endl;
	}else{
		cout << "Bob" << endl;
	}
}

Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
using namespace std;
int a[10001];
int main(void) {
	int n;
	cin >> n;
	for (int i = 0; i < n; i++) {
		int key;
		cin >> key;
		a[key]++;
	}
	int adjust=0;
	for (int i = 0; i < 10001; i++) {
		while (a[i])
		{
			if (adjust) cout << " ";
			cout << i;
			a[i]--;
			adjust = 1;
		}
	}
	cout<<endl;
}


Measured memory_bytes: 3104
#include<iostream>
#include<vector>
#include<algorithm>
#include<cstdio>
#include<cstdlib>
#include<string>
#include<sstream>
#include<cmath>
#include<numeric>
#include<map>
#include<stack>
#include<queue>
#include<list>
#include<set>
#include<cstring>
using namespace std;
long long int mod = 1e9 + 7;

int main() {
  string s; cin >> s;
  int n = s.size();
  int ans = 0;
  for(int i=0; i<n; i++) {
    for(int j=i; j<n; j++){
      if(s[j] == 'A' || s[j] == 'C' || s[j] == 'G' || s[j] == 'T') {
        ans = max(ans, j-i+1);
      }else{
        break;
      }
    }
  }
  cout << ans << endl;

  return 0;
}



//EOF


Measured memory_bytes: 256
import java.io.*;
import java.util.*;

public class Main {
  private static void execute(ContestReader reader, PrintWriter out) {
    char c1 = reader.nextCharArray()[0];
    char c2 = reader.nextCharArray()[0];
    out.println(c1 == c2 ? "H" : "D");
  }
  
  public static void main(String[] args) {
    ContestReader reader = new ContestReader(System.in);
    PrintWriter out = new PrintWriter(System.out);
    execute(reader, out);
    out.flush();
  }
}

class ContestReader {
  private BufferedReader reader;
  private StringTokenizer tokenizer;
  
  ContestReader(InputStream in) {
    reader = new BufferedReader(new InputStreamReader(in));
  }
  
  public String next() {
    while (tokenizer == null || !tokenizer.hasMoreTokens()) {
      try {
        tokenizer = new java.util.StringTokenizer(reader.readLine());
      } catch (Exception e) {
        throw new RuntimeException(e);
      }
    }
    return tokenizer.nextToken();
  }
  
  public int nextInt() {
    return Integer.parseInt(next());
  }
  
  public long nextLong() {
    return Long.parseLong(next());
  }
  
  public double nextDouble() {
    return Double.parseDouble(next());
  }
  
  public String[] next(int n) {
    String[] array = new String[n];
    for (int i = 0; i < n; i++) {
      array[i] = next();
    }
    return array;
  }
  
  public int[] nextInt(int n) {
    int[] array = new int[n];
    for (int i = 0; i < n; i++) {
      array[i] = nextInt();
    }
    return array;
  }
  
  public long[] nextLong(int n) {
    long[] array = new long[n];
    for (int i = 0; i < n; i++) {
      array[i] = nextLong();
    }
    return array;
  }
  
  public double[] nextDouble(int n) {
    double[] array = new double[n];
    for (int i = 0; i < n; i++) {
      array[i] = nextDouble();
    }
    return array;
  }
  
  public char[] nextCharArray() {
    return next().toCharArray();
  }
  
  public int[][] nextInt(int n, int m) {
    int[][] matrix = new int[n][m];
    for (int i = 0; i < n; i++) {
      for (int j = 0; j < m; j++) {
        matrix[i][j] = nextInt();
      }
    }
    return matrix;
  }
  
  public long[][] nextLong(int n, int m) {
    long[][] matrix = new long[n][m];
    for (int i = 0; i < n; i++) {
      for (int j = 0; j < m; j++) {
        matrix[i][j] = nextLong();
      }
    }
    return matrix;
  }
  
  public double[][] nextDouble(int n, int m) {
    double[][] matrix = new double[n][m];
    for (int i = 0; i < n; i++) {
      for (int j = 0; j < m; j++) {
        matrix[i][j] = nextDouble();
      }
    }
    return matrix;
  }
  
  public char[][] nextCharArray(int n) {
    char[][] matrix = new char[n][];
    for (int i = 0; i < n; i++) {
      matrix[i] = next().toCharArray();
    }
    return matrix;
  }
}


Measured memory_bytes: 18772
#include <bits/stdc++.h>
#define rep(i,n)    for(long long i = 0; i < (n) ; ++i)
#define orep(i,n)   for(long long i = 1; i <= (n); ++i)   // one rep
#define drep(i,n)   for(long long i = (n)-1; i >= 0; --i) // down rep
#define srep(i,s,t) for(long long i = (s); i < (t); ++i)  // set rep
#define rng(x)  (x).begin(),(x).end()

  // range
#define rrng(a) (a).rbegin(),(a).rend() // reverse range
#define isin(x,l,r) ((l) <= (x) && (x) < (r))
#define ru(x,y) (((x)+(y)-1)/(y)) // round up
#define fi first
#define se second
#define eb emplace_back
#define fcout cout << fixed << setprecision(15)


using namespace std;
using ll  = long long;
using P   = pair<int,int>;
using vi  = vector<int>;
using vvi = vector<vi>;
using vp  = vector<P>;
using vl  = vector<ll>;

template<typename T> void Yes(T flag) {
  cout << (flag ? "Yes" : "No") << endl;
}

template<typename T> void pv(vector<T> vec) {
  cout << "[";
  for(auto& v : vec) { cout << v << ","; }
  cout << "]" << endl;
}

template<>
void pv(vector<P> vec) {
  cout << "[";
  for(auto& v : vec) {
    cout << "<" << v.fi << ","<< v.se << ">" << ",";
  }
  cout << "]" << endl;
}

template<typename T> void pv2(vector<vector<T>> vec) {
  for(auto& v : vec) pv(v);
}

int r,s,p;

int j(char a,char b) {
  if(a=='r' and b=='s') return r;
  if(a=='s' and b=='p') return s;
  if(a=='p' and b=='r') return p;
  return 0;
}

int sc(char a) {
  if(a=='r' ) return r;
  if(a=='s' ) return s;
  if(a=='p') return p;
  return 0;
}

char win_to(char a) {
  if(a=='r') return 'p';
  if(a=='s') return 'r';
  if(a=='p') return 's';
  return 'a';
}

string remain(char a) {
  if(a=='r') return "sp";
  if(a=='s') return "rp";
  if(a=='p') return "sr";
  return "aa";
}

bool f (string a,char b) {
  for(auto v : a) if(v==b)return true;
  return false;
}

int main() {
  int n,k;
  cin >> n >> k >> r >> s >> p;
  string t;
  cin >> t;
  ll ans=0;
  string h="rsp";

  rep(i,k) {
    string rem = h;
    rep(j,n/k + 1) {
      if(i+j*k >= n) continue;
      int now = i+j*k;
      char yh = t.at(now);
      if(f(rem,win_to(yh))) {
        ans+=sc(win_to(yh));
        rem=remain(win_to(yh));
      } else {
        if(now+k<n) {
          char yhs=t.at(now+k);
          rem=remain(yhs);
        }
      }
    }
  }


  cout << ans << endl;

  return 0;
}


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

//define ll long long;
//define ar array;

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

    long long x;
    cin >> x;
    cout << x + (x*x) + (x*x*x) << endl;

    return 0;
}



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

using namespace std;

int main()
{
    int a,b;
    cin >> a >> b;
    a--,b--;
    printf("100 100\n");
    for(int i=0;i<50;i++)
    {
        for(int j=0;j<100;j++)
        {
            if(i%2&&j%2&&a)
            {
                a--;
                printf(".");
            }
            else printf("#");
        }
        printf("\n");
    }
    for(int i=50;i<100;i++)
    {
        for(int j=0;j<100;j++)
        {
            if(i%2&&j%2&&b)
            {
                b--;
                printf("#");
            }
            else printf(".");
        }
        printf("\n");
    }
    return 0;
}


Measured memory_bytes: 256
#include <stdio.h>

void printHashLine(int n) {
    for (int j=0; j<n; ++j) {
        printf("#");
    }
    printf("\n");
}

void printDotLine(int n) {
    printf("#");
    for (int j=1; j<n-1; ++j) {
        printf(".");
    }
    printf("#\n");
}

int main() {
    int h, w;
    while (1) {
        scanf("%d %d", &h, &w);
        if (h == 0 && w == 0) { break; }

        printHashLine(w);
        for (int i=1; i<h-1; ++i) {
            printDotLine(w);
        }
        printHashLine(w);
        printf("\n");
    }
    return 0;
}



Measured memory_bytes: 2144
#pragma GCC target ("avx2")
#pragma GCC optimize "trapv"
#pragma GCC optimization ("O3")
#pragma GCC optimization ("unroll-loops")
#include <bits/stdc++.h>
#define input(a,n) for(ll i1=0;i1<n;i1++)cin>>a[i1]
#define ll long long
#define pi 2 * acos(0.0)
#define usll unordered_set<ll>
#define sll set<ll>
#define vll vector<ll>
#define mll map<ll,ll>
#define pll pair<ll,ll>
#define umll unordered_map<ll,ll>
#define S second
#define sz size()
#define all(v) v.begin(),v.end()
#define Y cout<< "YES"<< "\n"
#define N cout<< "NO"<< "\n"
#define F first
#define mp make_pair
#define pb push_back
#define pf push_front
#define ld long double
#define mod 1000000007
using namespace std;
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    string s;
    cin>>s;
    if(s=="SSS")
        cout<<0;
    else if(s=="RSS"||s=="SRS"||s=="SSR"||s=="RSR")
        cout<<1;
    else if(s=="RRS"||s=="SRR")
        cout<<2;
    else if(s=="RRR")
        cout<<3;
    return 0;
}


Measured memory_bytes: 3652
n = int(input())
H = list(map(int,input().split()))
ans = 0
while H.count(0) != len(H):
  l,r = -1,-1
  for i in range(len(H)):
    if l == -1 and H[i] != 0:
      l = i
      r = l
    elif H[i] != 0:
      r = i
    elif l != -1 and H[i] == 0:
      break
  selected = [ h - 1 for h in H[l:r+1]]
  H[l:r+1] = selected
  ans += 1
print(ans)

Measured memory_bytes: 3064
#include<stdio.h>

int main()
{
    int A,B;
    scanf("%d%d",&A,&B);
    if(2<=A && A<=13 && 2<=B && B<=13)
    {
        if(A>B) printf("Alice");
        else if (A==B) printf("Draw");
        else printf("Bob");
    }
    if(1==A && B>1) printf("Alice");
    if(1==B && A>1) printf("Bob");
    if(A==1 && B==1) printf("Draw");

return 0;
}

Measured memory_bytes: 1736
N, Y = map(int, input().split())

upper_10thousand = Y // 10000
for i in range(upper_10thousand, -1, -1):
    upper_5thousand = (Y - 10000 * i) // 5000
    for j in range(upper_5thousand, -1, -1):
        k = (Y - 10000 * i - 5000 * j) // 1000
        if N == (i + j + k):
            print(i, j, k)
            exit()

print(-1, -1, -1)


Measured memory_bytes: 3060
n,k=map(int,input().split())
l=[int(x) for x in input().split()]
d=[10**9]*n
d[-1]=0
for i in range(n-2,-1,-1):
	mn=10**9
	for j in range(i+1,min(i+1+k,n),1):
		mn=min(mn,abs(l[i]-l[j])+d[j])
	d[i]=mn
#print(d)
print(d[0])	

Measured memory_bytes: 52448