akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#define int long long
using namespace std;
int n, c, x[123456], v[123456], a[123456], b[123456];
signed main() {
	cin >> n >> c; for (int i = 1; i <= n; i++)cin >> x[i] >> v[i];
	int sum = 0;
	for (int i = 1; i <= n; i++) {
		sum += v[i];
		a[i] = max(a[i - 1], sum - x[i]);
	}
	sum = 0;
	for (int i = n; i >= 1; i--) {
		sum += v[i];
		b[i] = max(b[i + 1], sum - 2*(c - x[i]));
	}
	int ans = 0;
	for (int i = 0; i <= n; i++)ans = max(ans, a[i] + b[i + 1]);
	sum = 0;
	for (int i = 1; i <= n; i++) {
		sum += v[i];
		a[i] = max(a[i - 1], sum - x[i] * 2);
	}
	sum = 0;
	for (int i = n; i >= 1; i--) {
		sum += v[i];
		b[i] = max(b[i + 1], sum - (c - x[i]));
	}
	for (int i = 0; i <= n; i++)ans = max(ans, a[i] + b[i + 1]);
	cout << ans << endl;
	cin >> n;
}

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

using namespace std;

#define endl '\n'

int main(){

  ios_base :: sync_with_stdio(false);
  cin.tie(NULL);
  
  int n;
  cin >> n;

  long long h[n+1];

  unordered_map <long long,long long> mp;

  for(int i=1;i<=n;i++){
    cin >> h[i];
    mp[i-h[i]]++;
  }

  long long ans = 0;

  for(int i=1;i<=n;i++){
    ans+=mp[h[i]+i]; 
  }

  cout << ans << endl;

  return 0;
}

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

int n;
ll X, D;
unordered_map<ll, vector<pair<ll,ll>>> mp;

int main() {
    ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
    cin>>n>>X>>D;
    if (D==0) {
        if (X!=0) cout<<n+1;
        else cout<<1;
        return 0;
    }

    for (int k=0; k<=n; ++k) {
        ll L=X*k+D*k*(k-1)/2;
        ll R=X*k+D*k*(2*n-k-1)/2;
        if (R<L) swap(L,R);
        ll du=L%abs(D);
        if (du<0) du+=abs(D);
        mp[du].emplace_back(L, R);
    }

    D=abs(D);
    ll ans=0;
    for (auto p: mp) {
        auto &v=p.second;
        vector<pair<ll,ll>> q;

        sort(v.begin(), v.end());
        for (auto &x: v) {
            ll tmp=(x.first-v[0].first)/D;
            q.emplace_back(tmp, tmp+(x.second-x.first)/D);
        }
        sort(q.begin(), q.end());

        ll last=LLONG_MIN;
        for (auto &x: q) {
            if (x.second<=last) continue;
            ans+=x.second-max(last, x.first);
            if (x.first>last) ++ans;
            last=max(last, x.second);
        }
    }
    cout<<ans;
    return 0;
}


Measured memory_bytes: 17864
#include <cstdlib>
#include <iostream>
#include <algorithm>
#include <vector>
#include <cmath>

using namespace std;

int a,b,n,res;
int INDEX[100001];

int find(int u)
{
    int tmp=u;
    while(INDEX[tmp]!=tmp)tmp=INDEX[tmp];
    INDEX[u] = tmp;
    return tmp;
}
void unite(int u,int v)
{
    int p = find(u);
    int q = find(v);
    if(p!=q)
    {
        INDEX[q] = p;
    }
}
struct city{
    int idx;
    int x;
    int y;
};
struct edge{
    int st;
    int ed;
    int cost;
};

int cmpx(const void * a,const void * b)
{
    return ((city*)a)->x-((city*)b)->x;
}

int cmpy(const void * a,const void * b)
{
    return ((city*)a)->y-((city*)b)->y;
}

int cmpc(const void * a,const void * b)
{
    return ((edge*)a)->cost - ((edge*)b)->cost;
}

city xcopy[100001];
edge Edge[200002];

city ycopy[100001];

void solve()
{
    int cityCnt = 0;
    for(int i = 0;i<n;i++)INDEX[i]=i;
    qsort(xcopy,n,sizeof(city),cmpx);
    qsort(ycopy,n,sizeof(city),cmpy);
    for(int i = 0;i<n-1;i++){
        Edge[i].st = xcopy[i].idx;
        Edge[i].ed = xcopy[i+1].idx;
        Edge[i].cost = abs(xcopy[i].x-xcopy[i+1].x); 
    }
    for(int i = 0;i<n-1;i++){
        Edge[i+n-1].st = ycopy[i].idx;
        Edge[i+n-1].ed = ycopy[i+1].idx;
        Edge[i+n-1].cost = abs(ycopy[i].y-ycopy[i+1].y);
    }
    qsort(Edge,2*(n-1),sizeof(edge),cmpc);
    //for(int i = 0;i<2*(n-1);i++)cout<<Edge[i].cost<<endl;
    for(int i = 0;i<2*(n-1);i++){
        a=Edge[i].st;b=Edge[i].ed;
        if(find(a)!=find(b)){
            unite(a,b);
            res += Edge[i].cost;
        }
    }
}

int main()
{
    cin>>n;
    for(int i = 0;i<n;i++){
        cin>>a>>b;
        xcopy[i].idx=i;
        ycopy[i].idx=i;
        xcopy[i].x=a;
        ycopy[i].x=a;
        xcopy[i].y=b;
        ycopy[i].y=b;
    }
    //for(int i = 0;i<n;i++)cout<<xcopy[i].idx<<" "<<xcopy[i].x<<" "<<xcopy[i].y<<endl;
    //for(int i = 0;i<n;i++)cout<<ycopy[i].idx<<" "<<ycopy[i].x<<" "<<ycopy[i].y<<endl;
    solve();
    cout<<res<<endl;
    return 0;
}


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

using namespace std;

typedef pair<int,int> P;
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vll;
// #define int long long
#define pb push_back
#define mp make_pair
#define eps 1e-9
#define INF 2000000000 //2e9
#define LLINF 2000000000000000000ll // 2e18 (llmax:9e18)
#define fi first
#define sec second
#define all(x) (x).begin(),(x).end()
#define sq(x) ((x)*(x))
#define dmp(x) cerr << #x << ": " << x << endl;

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

template<class T> using MaxHeap = priority_queue<T>;
template<class T> using MinHeap = priority_queue<T,vector<T>,greater<T>>;
template<class T> vector<T> vect(int len,T elem){ return vector<T>(len,elem); }

template<class T,class U>
ostream& operator << (ostream& os,const pair<T,U>& p){
  os << p.fi << ',' << p.sec; return os;
}
template<class T,class U>
istream& operator >> (istream& is,pair<T,U>& p){
  is >> p.fi >> p.sec; return is;
}
template<class T>
ostream& operator << (ostream &os,const vector<T> &vec){
  for(int i=0;i<vec.size();i++){
    os << vec[i];
    if(i+1<vec.size())os << ' ';
  }
  return os;
}
template<class T>
istream& operator >> (istream &is,vector<T>& vec){
  for(int i=0;i<vec.size();i++)is >> vec[i];
  return is;
}
void fastio(){
  cin.tie(0);
  ios::sync_with_stdio(0);
  cout<<fixed<<setprecision(20);
}
namespace Util{
  template<class T>
  vector<pair<T,int>> runLength(vector<T> v){
    vector<pair<T,int>> res;
    for(int i=0;i<v.size();i++){
      if(res.empty()||res.back().first!=v[i])res.push_back(make_pair(v[i],1));
      else res.back().second++;
    }
    return res;
  }
  template<class T>
  void compress(vector<T> &v){
    sort(v.begin(),v.end());
    v.erase(unique(v.begin(),v.end()),v.end());
  }
}

void solve(){
  ll n,k;
  cin >> n >> k;
  int cnt = 0;
  ll base = 1;
  while(base<=n){
    cnt++;
    base *= k;
  }
  cout << cnt << endl;
  return ;
}
 
signed main(){
  fastio();
  solve();
  // int t; cin >> t; while(t--)solve();
  return 0;
}


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

#define f first
#define s second
#define pb push_back
#define mp make_pair
#define all(x) x.begin(), x.end()

typedef long long ll;

using namespace std;

const int N = (int)3e5 + 123, mod = (int)1e9 + 7, inf = (int)1e9;
const ll INF = (ll)1e18;

void no(){
	cout << "No";
	exit(0);
}

int n, a[3];

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

	cin >> n;

	for(int i = 1; i <= n; ++i){
		int x, y = 0;
		cin >> x;
		while(x % 2 == 0)
			y++, x /= 2;
		a[min(y, 2)]++;
	}

	if(a[0] > a[2] + 1)
		no();
	if(a[0] == a[2] + 1 && a[1])
		no();
	cout << "Yes";

	return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<algorithm>
#include<cmath>
#include<map>
using namespace std;
#define INF 20000000000000000
using ll = long long;

ll coutdp[101][100001]={};

int main(){
    ll n,W;
    cin >> n >> W;
    vector<ll> weight(n),value(n);
    for(ll i=0;i<n;i++)    cin >> weight[i] >> value[i];
    for(ll i=0;i<n;i++){
        for(ll w=0;w<=W;w++){
            if(w>=weight[i]){
                coutdp[i+1][w] = max(coutdp[i][w],coutdp[i][w-weight[i]]+value[i]);
            }  
            else    coutdp[i+1][w] = coutdp[i][w];
        }
    }
   cout << coutdp[n][W] << endl;
    return 0;
}

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

using namespace std;
set<int> s1;
const int MAXN = 3e5+5;
int obs[MAXN];
int h[MAXN];
long long ans;
vector<char> res;
string s[MAXN];
map<long long,int> m1;
int main(){
    int n;
    int a,b,c;
    cin>>n>>a>>b>>c;
    for(int i=1;i<=n;i++){
        cin>>s[i];
    }
    for(int i=1;i<=n;i++){
        if(s[i]=="AB"){
            if(a==1 && b==1 && c==0){
                if(i<n && s[i+1]=="BC"){
                    a--;
                    b++;
                    res.push_back('B');
                }else{
                    a++;
                    b--;
                    
                    res.push_back('A');
                }
            }else if(min(a,b) == a){
                a++;
                b--;
                
                    res.push_back('A');
            }else if(min(a,b) == b){
                b++;
                a--;
                
                    res.push_back('B');
            }
        }else if(s[i] == "BC"){
            if(b==1 && c==1 && a==0){
                if(i<n && s[i+1]=="AB"){
                    c--;
                    b++;
                    
                    res.push_back('B');
                }else{
                    c++;
                    b--;
                    
                    res.push_back('C');
                }
            }else if(min(b,c) == b){
                b++;c--;
                
                    res.push_back('B');
            }else if(min(b,c) == c){
                c++;b--;
                
                    res.push_back('C');
            }
        }else{
            if(a==1 && c==1 && b==0){
                if(i<n && s[i+1]=="BC"){
                    c++;
                    a--;
                    
                    res.push_back('C');
                }else{
                    a++;
                    c--;
                    
                    res.push_back('A');
                }
            }else if(min(a,c) == a){
                a++;
                c--;
                
                    res.push_back('A');
            }else if(min(a,c) == c){
                c++;
                a--;
                
                    res.push_back('C');
            }
        }
        if(a<0||b<0||c<0){
            cout<<"No"<<endl;
            return 0;
        }
       
    }
    cout<<"Yes"<<endl;
    for(auto x:res){
        cout<<x<<endl;
    }
    
}

Measured memory_bytes: 13140
# include<bits/stdc++.h>
#define ll long long
using namespace std ;
int main( ){
	int tjk = 1 ;
	// cin >> tjk ;
	while( tjk -- ){
        ll a , b , c , d ;
        cin >> a >> b >> c >> d ;
        ll u = a * c , u1 = a * d , u2 = b * c , u3 = b * d ;
        cout << max( u , max( u1 , max( u2 , u3 ) ) ) ;
    }
}


Measured memory_bytes: 3616
#include <iostream>
#include <vector>
using namespace std;
int main(){
  int i,j;
  int h,w;
  cin >> h >> w;
  vector<vector<char>> v(h+2,vector<char>(w+2,'.'));
  for(i=1;i<=h;i++){
    for(j=1;j<=w;j++){
      cin >> v[i][j];
    }
  }
  for(i=1;i<=h;i++){
    for(j=1;j<=w;j++){
      if(v[i][j]=='#'){
        if(v[i][j+1]!='#'&&v[i][j-1]!='#'&&v[i+1][j]!='#'&&v[i-1][j]!='#'){
          cout << "No" << "\n";
          return 0;
        }
      }
    }
  }
  cout << "Yes" << "\n";
  return 0;
}

Measured memory_bytes: 3596
def gcd(a,b):
  while b!=0:
    a,b=b,a%b
  return a
n = int(input())
a = list(map(int, input().split()))
left, right = [0] * (n+1), [0] * (n+1)
for i in range(n):
    left[i+1] = gcd(left[i], a[i])
for i in reversed(range(n)):
    right[i] = gcd(right[i+1], a[i])
ans = 0
for i in range(n):
    l = left[i]
    r = right[i+1]
    ans = max(ans, gcd(l, r))
print(ans)

Measured memory_bytes: 14400
import java.io.*;
import java.util.ArrayList;
import java.util.List;
 
// main
 
public class Main {
  public static void main(String[] args) throws Exception {
    BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
    //String linebr.readLine()) != null;
 
  while (true) {
	
	   List<Integer> amanda;
	   amanda = getInt(br);
	   int num = amanda.get(0);
	   int kind = amanda.get(1);
	   if(num == 0 && kind == 0) {
		   break;
	   }
	   
	   List<Integer> goukei = getInt(br);
	   List<Integer> init = new ArrayList<Integer>();
	   for(int i=0; i<kind; i++) {
		   init.add(0);
	   }
	   
	   for(int i=0; i<num; i++) {
		   int r = 0;
		   for(int op : getInt(br)){
			 init.set(r,init.get(r) + op);  
			 r++;
		   }
		   
	   }
	   
	   String ans = "Yes";
	   for(int i=0; i<kind; i++) {		  
		   if(goukei.get(i) < init.get(i)) {
			   ans = "No";
		   }
	   }
	   System.out.println(ans);
  }
  }
  
  static List<Integer> getInt(BufferedReader bk) throws IOException {
	  String[] a = bk.readLine().split(" ");
	  List<Integer> k = new ArrayList<Integer>();
	  for(String string : a) {
		  int b = Integer.parseInt(string);
		  k.add(b);
	  }
	  return k;
  }
}



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


#define li          long long int
#define rep(i,to)   for(li i=0;i<((li)(to));i++)
#define repp(i,start,to)    for(li i=(li)(start);i<((li)(to));i++)
#define pb          push_back
#define sz(v)       ((li)(v).size())
#define bgn(v)      ((v).begin())
#define eend(v)     ((v).end())
#define allof(v)    (v).begin(), (v).end()
#define dodp(v,n)       memset(v,(li)n,sizeof(v))
#define bit(n)      (1ll<<(li)(n))
#define mp(a,b)     make_pair(a,b)
#define rin rep(i,n)
#define EPS 1e-12
#define ETOL 1e-8
#define MOD 1000000007
typedef pair<li, li> PI;

#define INF bit(60)

#define DBGP 1


#define idp if(DBGP)
#define F first
#define S second
#define p2(a,b)     idp cout<<a<<"\t"<<b<<endl
#define p3(a,b,c)       idp cout<<a<<"\t"<<b<<"\t"<<c<<endl
#define p4(a,b,c,d)     idp cout<<a<<"\t"<<b<<"\t"<<c<<"\t"<<d<<endl
#define p5(a,b,c,d,e)       idp cout<<a<<"\t"<<b<<"\t"<<c<<"\t"<<d<<"\t"<<e<<endl
#define p6(a,b,c,d,e,f)     idp cout<<a<<"\t"<<b<<"\t"<<c<<"\t"<<d<<"\t"<<e<<"\t"<<f<<endl
#define p7(a,b,c,d,e,f,g)       idp cout<<a<<"\t"<<b<<"\t"<<c<<"\t"<<d<<"\t"<<e<<"\t"<<f<<"\t"<<g<<endl
#define p8(a,b,c,d,e,f,g,h)     idp cout<<a<<"\t"<<b<<"\t"<<c<<"\t"<<d<<"\t"<<e<<"\t"<<f<<"\t"<<g<<"\t"<<h<<endl
#define p9(a,b,c,d,e,f,g,h,i)       idp cout<<a<<"\t"<<b<<"\t"<<c<<"\t"<<d<<"\t"<<e<<"\t"<<f<<"\t"<<g<<"\t"<<h<<"\t"<<i<<endl
#define p10(a,b,c,d,e,f,g,h,i,j)        idp cout<<a<<"\t"<<b<<"\t"<<c<<"\t"<<d<<"\t"<<e<<"\t"<<f<<"\t"<<g<<"\t"<<h<<"\t"<<i<<"\t"<<j<<endl
#define foreach(it,v)   for(__typeof((v).begin()) it=(v).begin(); it!=(v).end(); ++it)
#define p2p(x)      idp p2((x).F, (x).S)
#define dump(x,n)   idp{rep(i,n){cout<<x[i]<<" ";}puts("");}
#define dump2(x,n)  idp{rep(i,n){cout<<"["<<x[i].F<<" , "<<x[i].S<<"] ";}puts("");}
#define dumpi(x)    idp{foreach(it, x){cout<<(*it)<<" ";}puts("");}
#define dumpi2(x)   idp{foreach(it, x){cout<<"["<<(it)->F<<" , "<<(it)->S<<"] ";}puts("");}

#define read2d(a,w,h)   rep(i,h)rep(j,w)cin>>a[i][j]
#define dump2d(a,w,h)   rep(i,h){rep(j,w)cout<<a[i][j]<<" ";puts("");}

typedef pair<li, li> PI;

li n;
li cnt[10100];

int main() {
    cin >> n;
    repp(x, 1, 101) {
        repp(y, 1, 101) {
            repp(z, 1, 101) {
                li val = x * x + y * y + z * z + x * y + y * z + z * x;
                if (val > n) {
                    continue;
                }
                cnt[val]++;
            }
        }
    }
    rin{
        cout << cnt[i + 1] << endl;
    }



    return 0;
}

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

using namespace std;

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

const long long MOD = 1e9 + 7;
const int INF = 1e9;

int main() {
  int N;
  cin >> N;
  vector<int> a(N), b(N), c(N);
  for (int i = 0; i < N; ++i) cin >> a[i];
  for (int i = 0; i < N; ++i) cin >> b[i];
  for (int i = 0; i < N; ++i) cin >> c[i];
  sort(a.begin(), a.end());
  sort(b.begin(), b.end());
  sort(c.begin(), c.end());
  ll ans = 0;
  ll apos = 0, cpos = 0;
  for (int i = 0; i < N; ++i) {
    while (apos < N && a[apos] < b[i]) apos++;
    while (cpos < N && c[cpos] <= b[i]) cpos++;
    ans += apos * (N - cpos);
  }
  cout << ans << endl;
}

Measured memory_bytes: 1408
//#include <bits/stdc++.h>                          //include all library  
#include <cstdio>
#include <iostream>
#include <algorithm>
#include <cmath>
#include <string>
#include <map>
#include <sstream>
#include <vector>
#include <stack>
#include <queue>
//#include <priority_queue>
#include <string.h>
#include <functional> // greater<int> はfunctionalヘッダ
using namespace std;

#define REP(i, n) for(int i = 0;i < n;i++)          //REP(i, 10){...} //i=0～i=9までのループ
#define REPR(i, n) for(int i = n;i >= 0;i--)        //REPR(i, 10){...} //i=10～i=0までのループ
#define FOR(i, m, n) for(int i = m;i < n;i++)       //FOR(i, 3, 10){...} //i=3～i=9までのループ
#define FORR(i, m, n) for(int i = m;i >= n;i--)     //FORR(i, 10, 3){...} //i=10～i=3までのループ
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
#define llong long long
#define pb(a) push_back(a)
#define INF 999999999
#define PI 3.141592653589
#define npos -1

int main()
{
  int n,k;
  cin >> n >> k;
  int x,sum = 0;

  REP(i,n)
  {
  	cin >> x;
  	sum += min(x,abs(k-x));
  }
  cout << sum*2 << endl;
}



Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cstring>
#include<cmath>
using namespace std;
inline int read(){
	char ch=getchar();
	int o=0,f=1;
	while(ch<'0'||ch>'9'){
		if(ch=='-') f=-1;
		ch=getchar();
	}
	while(ch>='0'&&ch<='9'){
		o=(o<<3)+(o<<1)+(ch^48);
		ch=getchar();
	}
	return o*f;
}
int a[100],b[100],c[100],ans;
int main(){
	int n;cin>>n;
	for(register int i=1;i<=n;i++){
		cin>>a[i];
	}
	for(register int i=1;i<=n;i++){
		cin>>b[i];
	}
	for(register int i=1;i<=n-1;i++){
		cin>>c[i];
	}
	ans=b[a[1]];
	for(register int i=2;i<=n;i++){
		if(a[i]==a[i-1]+1) ans+=c[a[i]-1];
		ans+=b[a[i]];
	}
	cout<<ans<<endl;
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main 
{

	public static void main(String[] args) 
	{
		Scanner scan = new Scanner(System.in);
		
		int n = scan.nextInt();
		int[][] tile = new int[5][5];
		
		for(int i = 0; i < n; i++)
		{
			for(int y = 0; y < 5; y++)
			{
				for(int x = 0; x < 5; x++)
				{
					tile[x][y] = scan.nextInt();
				}
			}
			
			int ans = 0;
			
			for(int w = 5; w > 0; w--)
			{
				for(int h = 5; h > 0; h--)
				{
					if(w*h > ans)
					{
						for(int xp = 0; xp <= 5-w; xp++)
						{
							for(int yp = 0; yp <= 5-h; yp++)
							{
								boolean okay = true;
								for(int xpp = xp; xpp <= w+xp-1; xpp++)
								{
									for(int ypp = yp; ypp <= h+yp-1; ypp++)
									{
										if(tile[xpp][ypp] == 0)
										{
//											System.out.println("trying " + xp + ", " + yp + ", failed at " + xpp + "," + ypp);
											
											okay = false;
											break;
										}
									}
								}
								if(okay)
								{
									ans = w*h;
								}
							}
						}
					}
				}
			}
			
			System.out.println(ans);
			
			
		}
	}

}



Measured memory_bytes: 34572
// AOJ 1564: String Compression
// 2017.10.24 bal4u@uu

#include <stdio.h>

char s[102], *p;
int f['z'+1];

int main() 
{
	int i, j, w, ans;

	scanf("%s", s); 
	p = s; while (*p) f[*p++]++;
	w = p - s;
	
	p = s;
	do for (j = 0, i = '0'; i <= '9'; i++) if (f[i] > 0) j = 1, *p++ = i, f[i]--;
	while (j);
	do for (j = 0, i = 'a'; i <= 'z'; i++) if (f[i] > 0) j = 1, *p++ = i, f[i]--;
	while (j);

	ans = w;
	for (i = 0; i < w; i = j) {
		for (j = i+1; s[j] == s[j-1]+1; j++);
		if (j - i > 3) ans -= j - i - 3;
	}
	printf("%d\n", ans);
	return 0;
}

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

typedef long long ll;
typedef long double ld;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef pair<ld,ld> pdd;
typedef vector<ll> vll;
typedef vector<ld> vld;
typedef vector<pll> vpl;
typedef vector<vll> vvll;

#define ALL(a) a.begin(),a.end()
#define SZ(a) ((int)a.size())
#define FI first
#define SE second
#define REP(i,n) for(int i=0;i<((int)n);i++)
#define REP1(i,n) for(int i=1;i<((int)n);i++)
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define PB push_back
#define EB emplace_back
#define MP(a,b) make_pair(a,b)
#define SORT_UNIQUE(c) (sort(c.begin(),c.end()), c.resize(distance(c.begin(),unique(c.begin(),c.end()))))
#define GET_POS(c,x) (lower_bound(c.begin(),c.end(),x)-c.begin())
#define yes cout<<"Yes"<<endl
#define YES cout<<"YES"<<endl
#define no cout<<"No"<<endl
#define NO cout<<"NO"<<endl
#define Decimal fixed<<setprecision(20)
#define INF 1000000000
#define LLINF 1000000000000000000LL

const int inf = 1e9;
const ll linf = 1LL << 50;
const double eps = 1e-10;
const int MOD = 1e9 + 7;
const int dx[4] = {-1, 0, 1, 0};
const int dy[4] = {0, -1, 0, 1};

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

  ll n,k;
  cin>>n>>k;
  vll p(n);
  REP(i,n)cin>>p[i];

  vll remind(n+1);
  REP(i,n){
    remind[i+1]=remind[i];
    if(i==n-1)
      ;
    else if(p[i]<p[i+1])
      remind[i+1]++;
  }

  set<ll> s;
  ll ans=0;
  ll no_swap=0;
  REP(i,n){
    if(i<k)
      s.insert(p[i]);
    else{
      s.insert(p[i]);
      auto b=s.begin();
      auto e=s.rbegin();

      bool be_eq=false;
      if(*b==p[i-k] && *e==p[i])
        be_eq=true;

      s.erase(p[i-k]);
      if(remind[i]-remind[i-k+1]==k-1){
        no_swap++;
      }
      else{
        if(be_eq)
          ;
        else
          ans++;
      }
    }

    if(i==k-1){
      if(remind[i]-remind[i-k+1]==k-1){
        no_swap++;
      }
      else
        ans++;
    }
  }

  if(0<no_swap)
    ans++;
  cout<<ans<<endl;
}



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

using namespace std;

int a[100000], b[1000000];

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

    long long ans = 0;
    for (int i = n - 1; i >= 0; i--){
        if ((a[i] + ans) % b[i] != 0)
            ans += b[i] - (a[i] + ans) % b[i];
    }

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


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

using namespace std;

#ifdef DEBUG_MODE
	#define DBG(n) n;
#else
	#define DBG(n) ;
#endif
#define REP(i,n) for(ll (i) = (0);(i) < (n);++i)
#define rep(i,s,g) for(ll (i) = (s);(i) < (g);++i)
#define rrep(i,s,g) for(ll (i) = (s);i >= (g);--(i))
#define PB push_back
#define MP make_pair
#define FI first
#define SE second
#define SHOW1d(v,n) {for(int W = 0;W < (n);W++)cerr << v[W] << ' ';cerr << endl << endl;}
#define SHOW2d(v,i,j) {for(int aaa = 0;aaa < i;aaa++){for(int bbb = 0;bbb < j;bbb++)cerr << v[aaa][bbb] << ' ';cerr << endl;}cerr << endl;}
#define ALL(v) v.begin(),v.end()
#define Decimal fixed<<setprecision(20)
#define INF 1000000000
#define MOD 1000000007

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

int main(){
	int n;
	
	while(cin >> n,n){
		
		vector<int> imos(25*60*60);
		REP(i,n){
			int h,m,s,tmp;
			scanf("%d:%d:%d",&h,&m,&s);
			tmp = h*(3600) + m*60 + s;
			imos[tmp]++;
			scanf("%d:%d:%d",&h,&m,&s);
			tmp = h*(3600) + m*60 + s;
			imos[tmp]--;
		}
		
		REP(i,imos.size()-1){
			imos[i+1] += imos[i];
		}
		int ans = 0;
		REP(i,imos.size()){
			ans = max(ans,imos[i]);
		}
		
		cout << ans << endl;
	}
	
	return 0;
}


Measured memory_bytes: 3516
#include<iostream>
#include<algorithm>
#include<string>
#include<vector>
#include<cstdlib>
#include<queue>
#include<set>
#include<cstdio>
#include<map>

using namespace std;

#define ll long long
#define rep(i, n) for(int i = 0; i < n; i++)
#define P pair<int, int>

typedef vector<int> vec;
typedef vector<vec> mat;

const ll mod = 1000000007;

int main(){
    int n;
    cin >> n;
    ll a[n];
    rep(i, n) cin >> a[i];
    vector<P> cnt(60);
    rep(i, n){
        rep(j, 60){
            if ((a[i] >> j) & (ll)1) cnt[j].first++;
            else cnt[j].second++; 
        }
    }
    ll ans = 0;
    ll bit = 1;
    rep(i, 60){
        ll num;
        num = (ll)cnt[i].first * (ll)cnt[i].second;
        num %= mod;
        ans += num * bit;
        ans %= mod;
        bit *= 2;
        bit %= mod;
    }
    cout << ans << endl;
}

Measured memory_bytes: 5860
//
//  main.cpp
//  AGC_029_A
//
//  Created by Joe Mori on 2020/05/30.
//  Copyright © 2020 Joe Mori. All rights reserved.
//

#include <iostream>
#include<string>
int main() {
    long long int a,count=0,b=0;
    std::string str;
    std::cin>>str;
    a=str.length();
    int c=str.length();
    for(int i=0;i<c;i++){
        if(str[i]=='B'){
            b++;
        }else{
            count+=b;
        }
    }
    std::cout<<count<<std::endl;
    return 0;
}


Measured memory_bytes: 640
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <map>
#include <utility>

using namespace std;
using llong = long long;

vector<int> graph[50];
int ord[50],low[50];
bool visited[50];
vector<pair<int,int>> bridges;

int visited_time = 0;

int dfs(int v,int p){
  visited[v] = true;
  ord[v] = visited_time++;
  low[v] = ord[v];
  for(const auto &n:graph[v]){
    if(!visited[n]){
      dfs(n,v);
      low[v] = min(low[v],low[n]);
      if(ord[v]<low[n]){
        bridges.emplace_back(v,n);
      }
    }else if(n != p){
      low[v] = min(low[v],ord[n]);
    }
  }
}

int main(){
  int N,M;
  cin >> N >> M;
  for(int i=0;i<M;++i){
    int a,b;
    cin >> a >> b;
    graph[a-1].push_back(b-1);
    graph[b-1].push_back(a-1);
  }
  
  dfs(0,-1);
  cout << bridges.size() << endl;

  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h> //JuniorMonster a.k.a Sho10
#define ll long long
#pragma GCC optimize("O3")
#pragma GCC optimize("Ofast")
#define all(a) (a).begin(), (a).end()
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#define sz size
#define f first
#define s second
#define pb push_back
#define er erase
#define in insert
#define mp make_pair
#define pi pair
#define rc(s) return cout<<s,0
#define mod 1000000007
#define PI 3.14159265359
using namespace std;
ll n,v[100000],c[100000],s1,s2;
int32_t main(){
    cin>>n;
    for(ll i=0;i<n;i++)
        cin>>v[i];
    for(ll i=0;i<n;i++)
        cin>>c[i];
    for(ll i=0;i<n;i++)
    if(v[i]>c[i]){
        s1=s1+v[i];
        s2=s2+c[i];
    }
    cout<<abs(s1-s2);
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int n,cnt=0,ma,na=0;
    cin>>n;
    int w[n];
    for(int i=0;i<n;i++)
    {
        cin>>w[i];
        cnt+=w[i];
    }
    ma=cnt;
    for(int i=0;i<n;i++)
    {
        na+=w[i];
        ma=min(ma,abs(na-(cnt-na)));
    }
    cout<<ma<<endl;
    return 0;

}


Measured memory_bytes: 256
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace AtCorder
{
	public class Program
	{
		static void Main(string[] args)
		{
			A();
		}

		public static void A()
		{
			Scanner cin = new Scanner();
			int a = cin.NextInt();
			int b = cin.NextInt();

			if (a == b) {
				Console.WriteLine(a * 2);
			} else {
				int max = Math.Max(a, b);
				Console.WriteLine(max + max - 1);
			}
		}

		
	}

	public class Scanner
	{
		string[] s;
		int i;

		char[] cs = new char[] { ' ' };

		public Scanner()
		{
			s = new string[0];
			i = 0;
		}

		public string Next()
		{
			if (i < s.Length) return s[i++];
			string st = Console.ReadLine();
			while (st == "") st = Console.ReadLine();
			s = st.Split(cs, StringSplitOptions.RemoveEmptyEntries);
			if (s.Length == 0) return Next();
			i = 0;
			return s[i++];
		}

		public int NextInt()
		{
			return int.Parse(Next());
		}
		public int[] ArrayInt(int N, int add = 0)
		{
			int[] Array = new int[N];
			for (int i = 0; i < N; i++) {
				Array[i] = NextInt() + add;
			}
			return Array;
		}

		public long NextLong()
		{
			return long.Parse(Next());
		}

		public long[] ArrayLong(int N, long add = 0)
		{
			long[] Array = new long[N];
			for (int i = 0; i < N; i++) {
				Array[i] = NextLong() + add;
			}
			return Array;
		}

		public double NextDouble()
		{
			return double.Parse(Next());
		}


		public double[] ArrayDouble(int N, double add = 0)
		{
			double[] Array = new double[N];
			for (int i = 0; i < N; i++) {
				Array[i] = NextDouble() + add;
			}
			return Array;
		}
	}
}


Measured memory_bytes: 13140
#include <iostream>
#include <cstdio>
#include <string>
#include <cstring>
#include <deque>
#include <list>
#include <queue>
#include <stack>
#include <vector>
#include <utility>
#include <algorithm>
#include <map>
#include <set>
#include <complex>
#include <cmath>
#include <limits>
#include <climits>
#include <ctime>
#include <cassert>
#include <numeric>
#include <functional>
#include <bitset>

using namespace std;
using lint = long long int;
long long int INF = 1001001001001001LL;
int inf = 1000000007;
long long int MOD = 1000000007LL;
double PI = 3.1415926535897932;

template<typename T1,typename T2>inline void chmin(T1 &a,const T2 &b){if(a>b) a=b;}
template<typename T1,typename T2>inline void chmax(T1 &a,const T2 &b){if(a<b) a=b;}

#define ALL(a) a.begin(),a.end()
#define RALL(a) a.rbegin(),a.rend()

/* do your best */

int main() {
  
  int h, a; cin >> h >> a;
  int ans = 0;
  while(h > 0) {
    ans++;
    h -= a;
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 256
X, N = map(int, input().split())
P = list(map(int, input().split()))
Pli = set(sorted(P))
X1 = X
X2 = X
while True:
    if X1 not in Pli:
        print(X1)
        break
    elif X2 not in Pli:
        print(X2)
        break
    else:
        X1 -= 1
        X2 += 1


Measured memory_bytes: 9176
#include<bits/stdc++.h>
#define pb push_back
#define int long long
#define It set<node>::iterator
#define endl '\n'
#define fastio ios::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;

string s;
int ans;
int a[1000010];

inline void add(int p){
	++a[p];
	if(a[p]==10){
		a[p]=0;
		add(p-1);
	}
}

signed main(){
	cin>>s;
	for(int i=0;i<s.size();++i) a[i+1]=s[i]-'0';
	for(int i=s.size();i>=1;--i){
		int val1=a[i],val2=10-a[i];
		if(val1<val2){
			ans+=val1;
			continue;
		}
		if(val1==val2&&a[i-1]<5){
			ans+=val1;
			continue;
		}
		ans+=val2;
		add(i-1);
	}
	if(a[0]) ++ans;
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 9220
import sys
N,M,X = map(int,input().split())
ls = []
for i in range(N):
    ls1 = list(map(int,input().split()))
    ls.append(list(ls1))
    ls1.clear()

ans=[]
for i in range(2**N):
    bag = []
    skill = [0]*M
    flg = True
    mon = 0
    for j in range(N):
        if i >> j & 1:
            bag.append(ls[j][0])
            mon += ls[j][0]
            for k in range(M):
                skill[k] += ls[j][k+1]
    if min(skill) >= X:
        ans.append(mon)
if len(ans) == 0:
    print("-1")
else:
    print(min(ans))


Measured memory_bytes: 74372
n,k=map(int, input().split())
a=list(map(int, input().split()))

sf=[0]*n
sb=[0]*n

for i in range(n):
    for j in range(n):
        if i<j:
            if a[i]>a[j]:
                sf[i]+=1
        else:
            if a[i]>a[j]:
                sb[j]+=1
ans=0
for i in range(n):
    ans+=k*sf[i]+k*(k-1)*(sf[i]+sb[i])//2

print(round(ans%(10**9+7)))


Measured memory_bytes: 43388
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
using vi = vector<int>;
using vvi = vector<vector<int>>;
using vl = vector<ll>;
using vvl = vector<vector<ll>>;
#define all(x) x.begin(),x.end()
#define rep(i,j,n) for (long long i = j; i < (long long)(n); i++)
#define _GLIBCXX_DEBUG
#define MOD 1000000007
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
//name[i][j]-> vvl name(i,vl(j))
//map<int,int>mp
//�]���؂�グ�� =>  (a + b - 1) / b 

signed main(){
	int a,b,c,d; cin>>a>>b>>c>>d;
  cout<<min(a,b)+min(c,d);
	
	return 0;
}

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

typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef unsigned int ui32;
const long long INFLL = 1e18;

using namespace std;

const int MAXN = 18;

map<string, map<string, int> > d;

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    //freopen("input.txt", "r", stdin);
    //freopen("input.txt", "w", stdout);

    int n;
    cin >> n;

    string s;
    cin >> s;

    string t = s.substr(n);
    s = s.substr(0, n);

    for (int mask = 0; mask < (1 << n); mask++) {
        string a = "", b = "";
        for (int i = n - 1; i >= 0; i--) {
            if (mask & (1 << i)) {
                a += t[i];
            }
        }
        for (int i = 0; i < n; i++) {
            if (!(mask & (1 << i))) {
                b += t[i];
            }
        }
        ++d[b][a];
    }

    ll ans = 0;

    for (int mask = 0; mask < (1 << n); mask++) {
        string a = "", b = "";
        for (int i = n - 1; i >= 0; i--) {
            if (mask & (1 << i)) {
                a += s[i];
            }
        }
        for (int i = 0; i < n; i++) {
            if (!(mask & (1 << i))) {
                b += s[i];
            }
        }

        ans += d[a][b];
    }

    cout << ans << "\n";
    return 0;
}

Measured memory_bytes: 123904
#include <bits/stdc++.h>
using namespace std;
 
map<int64_t,int> prime;
 
void prime_list(int64_t n){
  for(int64_t i=2;i*i<=n;++i){
    while(n%i==0){
      ++prime[i];
      n=n/i;
    }
  }
  if(n!=1){
    ++prime[n];
  }
}
 
int main(){
  int N;
  cin>>N;
  for(int i=1;i<=N;++i){
    prime_list(i);
  }
 
  int a2=0,a4=0,a14=0,a24=0,a74=0;
  for(auto p:prime){
    if(p.second>=2) ++a2;
    if(p.second>=4) ++a4;
    if(p.second>=14) ++a14;
    if(p.second>=24) ++a24;
    if(p.second>=74) ++a74;
  }
 
  int ans=0;
  ans += a74;
  ans += a24*(a2-1);
  ans += a14*(a4-1);
  ans += ((a4*(a4-1))*(a2-2))/2;
  cout<<ans<<endl;
}

Measured memory_bytes: 256
N, A, B = map(int, input().split())
S = input()

passed = 1
passed_foreigners = 1
for c in S:
    if passed > A + B or c == 'c':
        print('No')
    elif c == 'a':
        print('Yes')
        passed += 1
    else:
        if passed_foreigners <= B:
            print('Yes')
            passed += 1
            passed_foreigners += 1
        else:
            print('No')


Measured memory_bytes: 4016
#include <functional>
#include <sstream>
#include <vector>
#include <algorithm>
#include <cstring>
#include <cstdlib>
#include <iostream>
#include <string>
#include <cassert>
#include <ctime>
#include <map>
#include <math.h>
#include <cstdio>
#include <set>
#include <deque>
#include <memory.h>
#include <queue>

#pragma comment(linker, "/STACK:64000000")
typedef long long ll;

using namespace std;

const int MAXN = 1 << 18;
const int MOD = 1; // 1000 * 1000 * 1000 + 7;
const int INF = 2e9;
const double PI = acos(-1.0);

int main() {
#ifdef _MSC_VER
	freopen("input.txt", "r", stdin);
#endif

	int n, k;
	while (cin >> n >> k) {
		vector<int> a(n);
		for (int i = 0; i < n; i++) cin >> a[i], a[i]--;

		int ans = 0;
		if (a[0] != 0) {
			a[0] = 0;
			ans++;
		}

		vector<int> d(n, -1);
		d[0] = 0;
		function<int(int)> f = [&](int v) {
			if (d[v] != -1) return d[v];
			return d[v] = f(a[v]) + 1;
		};
		for (int i = 0; i < n; i++) {
			f(i);
		}
		vector<pair<int, int> > p;
		for (int i = 0; i < n; i++) p.push_back(make_pair(-d[i], i));
		sort(p.begin(), p.end());

		vector<int> del(n, 0);
		vector<vector<int> > e(n);
		for (int i = 0; i < n; i++) e[a[i]].push_back(i);
		for (int i = 0; i < n; i++) {
			int v = p[i].second;
			if (del[v]) continue;
			if (-p[i].first <= k) continue;
			for (int j = 0; j < k - 1; j++) v = a[v];
			a[v] = 0;
			ans++;
			queue<int> q;
			q.push(v);
			while (!q.empty()) {
				int v = q.front();
				q.pop();
				if (del[v]) continue;
				del[v] = 1;
				for (int to : e[v]) q.push(to);
			}
		}
		cout << ans << endl;
	}

	return 0;
}

Measured memory_bytes: 10740
#include <bits/stdc++.h>
using namespace std;
int main()
{

    long long n;
    cin>>n;
    long long ans = n;
    for(long long i=0;i<=n;i++){
        long long x=0,num=i;
        while(num)x+=num%6,num/=6;
        num = n-i;
        while(num)x+=num%9,num/=9;
        ans=min(ans , x);
    }
    cout<<ans<<endl;

    return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<string>
#include<math.h>
using namespace std;
typedef pair<int, int> P;

int main() {
	int count[4];
	for (int i = 0; i < 4; i++) {
		count[i] = 0;
	}
	int a, b;
	for (int i = 0; i < 3; i++) {
		cin >> a >> b;
		count[a - 1]++;
		count[b - 1]++;
	}
	for (int i = 0; i < 4; i++) {
		if (count[i] == 0||count[i]==3) {
			cout << "NO" << endl;
			return 0;
		}
	}
	cout << "YES" << endl;
	return 0;
}

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

int N;

int main() {
  cin >> N;
  int A[N];
  for(int i=0;i<N;i++) A[i]=0;
  for(int i=0;i<N-1;i++){
    int temp;
    cin >> temp;
    A[temp-1]++;
  }
  for(int i=0;i<N;i++) cout << A[i] << endl;
}

Measured memory_bytes: 3976
#include<stdio.h>
int main(void)
{
  int a,x=0,i;
  for (i=0;i<5;i++)
    {
     scanf("%d",&a);
     if(a<=40)
       x=x+40;
     else
       x=x+a;
    }
  printf("%d\n",x/5);
  return 0;
}

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

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rept(i,k,n) for(int i = (k); i < (int)(n); i++)
#define all(v) v.begin(), v.end()
#define Sort(v) sort(v.begin(),v.end())
#define Reverse(v) reverse(v.begin(),v.end())
#define mod 1000000007
typedef long long ll;
typedef pair<int,int> Pii;
typedef pair<long long,long long> Pll;

template <typename T>
void vecprint(vector<T> &vec) {
    cout<<'[';
    for(T x:vec){
        cout<<x<<',';
    }
    cout<<']'<<endl;
    return;
}

ll powm(ll a,ll b){
    if(b==1) return a;
    if(b%2) return powm(a*a%mod,b/2)*a%mod;
    else return powm(a*a%mod,b/2)%mod;
}

int main() {
    ll n,k;
    cin>>n>>k;
    vector<ll> cnt(k+1,0);
    for(ll i=k;i>0;i--){
        ll tmp = powm(k/i,n);
        for(ll j=i*2;j<=k;j+=i){
            tmp=(tmp+mod-cnt[j])%mod;
        }
        cnt[i]=tmp;
    }
    ll ans=0;
    rept(i,1,k+1){
        ans+=cnt[i]*i;
        ans%=mod;
    }
    cout<<ans<<endl;
    return 0;
}


Measured memory_bytes: 4048
#include<iostream>

using namespace std;

int main() {
	int p, q, r;
	cin >> p >> q >> r;
	int sum = 0;
	if (p > q) {
		if (p > r) {
			sum = q + r;
		}
		else {
			sum = p + q;
		}
	}
	else {
		if (q > r) {
			sum = r + p;

		}
		else {
			sum = p + q;
		}
	}

	cout << sum << endl;

	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <vector>
#include <set>
#include <string>
#include <queue>
#include <algorithm>
#include <map>
#include <cmath>
#include <numeric>
#include <list>
#include <stack>
#include <cstdio>
#include <cstdlib>
#include <cstring>

#define rep(i, n) for (int i = 0; i < n; i++)
#define rep1(i, n) for (int i = 1; i <= n; i++)

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

const int INF = 1 << 30;
const long long INFL = 1LL << 62;
const int MOD = 1000000007;
const int MAX = 100000;
const int N = 100;

int main() {
	int n;cin>>n;
	int ans=0,a;
	rep(i,n){cin>>a;ans+=a-1;}
	cout<<ans<<endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <utility>
#include <map>
#include <vector>
#include <algorithm>
#include <queue>
#include <math.h>
#include <stack>
#include <set>
#include <deque>
#include <cmath>
#include <cassert>

using namespace std;
typedef long long ll;
ll mod = 1e9+7;
#define rep(i,n) for(int i = 0; i < (n); ++i)

vector<int> bfs(int n, int s, vector<vector<int>> &g) {
    vector<int> color(n, 0);
    vector<int> flg(n, false);
    queue<pair<int, int>> que;
    vector<int> ret;
    que.push(make_pair(s, 0));
    color[s] = 1;
    while(1) {
        if (que.empty()) break;
        pair<int, int> now = que.front();
        que.pop();
        if (flg[now.first]) continue;
        flg[now.first] = true;
        for (auto v: g[now.first]) {
            //cout << now.first << " " << v << endl;
            if (color[v] == 0) {
                color[v] = -color[now.first];
            }
            if (color[v] != -color[now.first]) {
                //cout << "test" << endl;
                ret.clear();
                return ret;
            }
            que.push(make_pair(v, now.second+1));
            ret.push_back(now.second+1);
        } 
    }
    return ret;
}

int main() {
    int n;
    cin >> n;
    vector<vector<int>> g(n);
    rep(i, n) rep(j, n) {
        char c;
        cin >> c;
        if (c == '1') {
            g[i].push_back(j);
        }
    }
    //cout << "test" << endl;
    ll ans = -1;
    rep(i, n) {
        //cout << i << endl;
        auto v = bfs(n, i, g);
        //for (auto vv: v) {
        //    cout << vv << endl;
        //}
        if (!v.empty()) {
            ans = max(ans, (ll)*max_element(v.begin(), v.end()));
        }
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 3792
#include <iostream>
#include <string>
#define ll long long int
using namespace std;

int main(){
    string St;
    ll a=0 , b= 0; 
    cin>>St;
    for (int i = 0; i < 3; i++)
    {
        if (St[i] == 'R')
            a++;
        if (St[i] == 'S')
            a = 0;
        if (b < a)
            b = a;
    }
    cout << b << endl;
}

Measured memory_bytes: 3616
#include<stdio.h>
main()
{
	int N, X, i;
	int a[100], sum,total;
	scanf("%d %d\n", &N, &X);
	sum = 0;
	total = 1;
	for (i = 0; i < N; i++) {
		scanf("%d", &a[i]);
		sum = sum + a[i];
		if (sum <= X) {
			total = total + 1;
		}
	}
	printf("%d", total);

	}

Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  	int num_city,num_road;
  	int city;
  	cin >> num_city >> num_road;
  	vector<int> data(num_city,0);
 	for(int i = 0;i<num_road;i++){
    	for(int j = 0;j<2;j++){
        	cin >> city;
          	data.at(city-1) ++;
        }
    }
  	for(int x : data){
    cout << x << endl;
    }
}


Measured memory_bytes: 256
parseInt(x::String) = parse(Int, x)
parseInt(x::SubString{String}) = parse(Int, x)
parseInt(x::Char) = parse(Int, x)
parseInt(x::Float64) = trunc(Int, x)
parseFloat(x::String) = parse(Float64, x)
parseFloat(x::Int) = trunc(Float64, x)
parseFloat(x::SubString{String}) = parse(Float64, x)
parseFloat(x::Char) = parse(Float64, x)
parseMap(x::Array{SubString{String},1}) = map(parseInt, x)

function main()
    x,a,b=parseMap(split(readline()))
    if b-a>x
        println("dangerous")
    elseif b-a>0
        println("safe")
    else
        println("delicious")
    end
end
main()

Measured memory_bytes: 109884
#include<bits/stdc++.h>
typedef long long ll;
typedef long double ld;
using namespace std;

using Pii = pair<int, int>;
using Pll = pair<ll, ll>;

#define REP(i, l, n) for(int i=(l), i##_len=(n); i<i##_len; ++i)
#define ALL(x) (x).begin(),(x).end()
#define pb push_back

ll gcd(ll a,ll b){return b ? gcd(b,a%b) : a;}
ll lcm(ll a,ll b){return a/gcd(a,b)*b;}

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

char alpha[26] = {'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z'};

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


int main(){
    int x, y; cin >> x >> y;
    REP(i, 0, 101){
        REP(l, 0, 101){
            int c = i * 2 + l * 4;
            if(c == y && x == (i+l)){
                cout << "Yes" << endl;
                return 0;
            }
        }
    }
    cout << "No" << endl;
}

Measured memory_bytes: 3652
#include<bits/stdc++.h>
#define ll long long int

using namespace std;

const ll mod=1000000007;
const ll inf=1e18;

int main(){

  ll k,x;
  cin >> k >> x;

  for(int i=x-k+1;i<x+k;i++){
    if(i>=-1000000 && i<=1000000)cout << i <<" ";
  }

}

Measured memory_bytes: 3596
#include<stdio.h>
#include<string.h>
#define max 10000
int main()
{char a[101],b[101],c[202]={0};
int t,i,m=0,n=0;
scanf("%d",&t);
scanf("%s %s",a,b);
for(i=0;i<t*2;i++)
	if(i%2)
	c[i]=b[m++];
	else
	c[i]=a[n++];
printf("%s",c);
}

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

int main() {
  int n, k;
  cin >> n >> k;
  vector<int> vec(n);
  for (int i = 0; i < n; i++) {
    cin >> vec.at(i);
  }
  int sum = 0;
  for (int i = 0; i < n; i++) {
    if (vec.at(i) <= k - vec.at(i)) {
      sum += (vec.at(i) * 2);
    }
    else {
      sum += ((k - vec.at(i)) * 2);
    }
  }
  cout << sum << endl;
}
      
    
    


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

using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef vector<int> vint;
typedef vector<double> vd;
typedef vector<ll> vll;
typedef vector<string> vstr;
typedef vector<vector<int>> vvint;
typedef vector<pair<int, int>> vpii;
typedef vector<pair<ll, ll>> vpll;
typedef priority_queue<int, vector<int>, greater<int>> spqint; //小さい順に取り出し
typedef priority_queue<ll, vector<ll>, greater<ll>> spqll;     //小さい順に取り出し
typedef priority_queue<int, vector<int>, less<int>> bpqint;    //大きい順に取り出し
typedef priority_queue<ll, vector<ll>, less<ll>> bpqll;        //大きい順に取り出し

#define REP(i, n) for (ll i = 0; i < (ll)(n); i++)
#define FOR(i, a, b) for (ll i = (ll)a; i < (ll)b; i++)
#define IREP(i, v) for (auto i = (v).begin(); i != (v).end(); i++)
#define FI first
#define SE second
#define MP make_pair
#define MT make_tuple
#define PB push_back
#define PF push_front
#define TS to_string
#define BS binary_search
#define LB lower_bound
#define UB upper_bound
#define NP next_permutation
#define ALL(v) (v).begin(), (v).end()
#define SZ(x) (ll) x.size()
#define SP(x) setprecision((ll)x)


int INF = 1e9;
int NIL = -1;
ll MOD = 1000000007;
ll LINF = 1e18;
double EPS = 1e-9;
double PI = M_PI;
int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1};
int dy[8] = {0, 1, 0, -1, 1, 1, -1, -1};
ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; } //最大公約数
ll lcm(ll a, ll b) { return a / gcd(a, b) * b; }     //最小公倍数

void yes(){ cout << "Yes" << endl;}
void no(){ cout << "No" << endl;}
//-----------------------------------------
vector<long long> factor_array(long long n){
    vector<long long> res ;
    for(long long i=1;i*i<=n;i++){
        if(n%i==0){
            res.push_back(i) ;
            if(i*i!=n){
                res.push_back(n/i) ;
            }
        }
    }
    sort(res.begin(),res.end()) ;
    return res ;
}
//-----------------------------------------
int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    std::chrono::system_clock::time_point start,end;
    start = std::chrono::system_clock::now();

    ll n;
    cin >> n;
    vll a(n);
    REP(i,n){
        cin >> a[i];
    }
    vll k = factor_array(a[0]);
    vll g = factor_array(a[1]);
    REP(i,SZ(g)){
        k.PB(g[i]);
    }

    sort(ALL(k));



    ll ans = -1;
    REP(i,SZ(k)){
        //cout << k[i] <<endl;
        ll tmp = 0;
        REP(j,n){
            if(a[j]%k[i]==0){
                tmp++;
            }
        }
        if(tmp>=n-1){
            ans = k[i];
        }
    }

    cout << ans <<endl;



    end = std::chrono::system_clock::now();
    auto elapsed = std::chrono::duration_cast< std::chrono::milliseconds >(end - start).count();
    //std::cout << elapsed <<"ms"<< std::endl;

    

    return 0;
}


Measured memory_bytes: 4012