akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
#define inf INT_MAX
#define mod 1000000007
#define int long long

int visit(vector<vector<int>> &a, vector<int> &dp, int src, vector<int> &vis) {
	vis[src] = 1;
	if (dp[src] != -1)return dp[src];
	int t = 0;
	for (auto x : a[src]) {
		t = max(t, visit(a, dp, x, vis));
	}
	dp[src] = 1 + t;
	return dp[src];
}

void solve() {
	int n;
	cin >> n;
	int m;
	cin >> m;
	vector<vector<int>> a(n + 1);
	int i;
	for (i = 0; i < m; i++) {
		int u, v;
		cin >> u >> v;
		a[u].push_back(v);
	}
	vector<int> dp(n + 1);
	fill(dp.begin(), dp.end(), -1);
	vector<int> vis(n + 1);
	fill(vis.begin(), vis.end(), 0);
	for (i = 1; i <= n; i++) {
		if (vis[i] == 0) {
			visit(a, dp, i, vis);
		}
	}

	int t = INT_MIN;
	for (i = 1; i <= n; i++) {
		t = max(t, dp[i]);
	}

	cout << t - 1 << endl;
	return;
}

int32_t main() {
	std::ios::sync_with_stdio(false);
	cout.tie(0);
	cin.tie(0);
	solve();
	return 0;
}


Measured memory_bytes: 13728
import java.io.*;
 
public class Main {
    public static void main(String[] args)throws IOException {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        int n = Integer.parseInt(br.readLine());
        String str2[] = br.readLine().split(" ");
        long sum = 0;
        int tmp = 0;
        int max = -1000000;
        int min = 1000000;
         
        for(int i=0; i<n;i++) {
            tmp = Integer.parseInt(str2[i]);
            if(tmp>max) max = tmp;
            if(tmp<min) min = tmp;
            sum += tmp;
        }
        System.out.println(min + " " + max + " " + sum);
    }
}

Measured memory_bytes: 28456
#include<bits/stdc++.h>
using namespace std;
const int INF=0x3f3f3f3f; 
typedef long long ll;


 
int main(){
	int a,b,c,k;
    cin>>a>>b>>c>>k;
	int ans=0;
	ans+=min(a,k);
	k-=ans;
	int y=min(k,b);
	k-=y;
	y=min(k,c);
	ans-=y;
	cout<<ans;
    return 0;
}
 

Measured memory_bytes: 3644
#include <bits/stdc++.h>
using namespace std;
# define ll long long int
#define M 998244353 
#define ff1 first
#define ss second
#define pb push_back  
#define INF 1000000000000
                                        // nestedcode

                                        
ll binpow(ll x, ll y){
	ll ans = 1;
	while(y){
		if(y&1)	ans = (ans*x)%M;
		x = (x*x)%M;
		y>>=1;
	}
	return ans;
}


int main(){
	ios_base::sync_with_stdio(false);
    cin.tie(NULL); cout.tie(NULL);
    string s;
    ll l,r,fl = 0;
   	cin>>s;
   	ll n = s.length();
   	l = 0;
   	r = n-1;
   	while(l<r){
   		if(s[l] != s[r]){
   			fl = 1;
   			break;
		   }
		   l++;r--;
	   }
	   l = 0;
   	r = (n-1)/2 - 1;
   	while(l<r){
   		if(s[l] != s[r]){
   			fl = 1;
   			break;
		   }
		   l++;r--;
	   }
	   l = (n+1)/2;
   	r = n-1;
   	while(l<r){
   		if(s[l] != s[r]){
   			fl = 1;
   			break;
		   }
		   l++;r--;
	   }
	   
	   if(fl)	cout<<"No";
	   else	cout<<"Yes";
}



Measured memory_bytes: 256
import fractions

A, B, C, D = map(int, input().split())

def lcm(x, y):
    return((x * y) // fractions.gcd(x, y))

n = B - A + 1
cn = B // C - (A - 1) // C
dn = B // D - (A - 1) // D
cdn = B // lcm(C, D) - (A - 1) // lcm(C, D)

ans = n - (cn + dn - cdn)
print(ans)

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

// #define int long long
#define rep(i, n) for (long long i = (long long)(0); i < (long long)(n); ++i)
#define reps(i, n) for (long long i = (long long)(1); i <= (long long)(n); ++i)
#define rrep(i, n) for (long long i = ((long long)(n)-1); i >= 0; i--)
#define rreps(i, n) for (long long i = ((long long)(n)); i > 0; i--)
#define irep(i, m, n) for (long long i = (long long)(m); i < (long long)(n); ++i)
#define ireps(i, m, n) for (long long i = (long long)(m); i <= (long long)(n); ++i)
#define SORT(v, n) sort(v, v + n);
#define REVERSE(v, n) reverse(v, v+n);
#define vsort(v) sort(v.begin(), v.end());
#define all(v) v.begin(), v.end()
#define mp(n, m) make_pair(n, m);
#define cout(d) cout<<d<<endl;
#define coutd(d) cout<<std::setprecision(10)<<d<<endl;
#define cinline(n) getline(cin,n);
#define replace_all(s, b, a) replace(s.begin(),s.end(), b, a);
#define PI (acos(-1))
#define FILL(v, n, x) fill(v, v + n, x);
#define sz(x) long long(x.size())

using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vll = vector<ll>;
using vvll = vector<vll>;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
using vs = vector<string>;
using vpll = vector<pair<ll, ll>>;
using vtp = vector<tuple<ll,ll,ll>>;
using vb = vector<bool>;

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

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



signed main()
{
  cin.tie( 0 ); ios::sync_with_stdio( false );
  ll n,m; cin>>n>>m;
  
  vpll ba(m);
  rep(i,m){
    ll a,b; cin>>a>>b;
    ba[i]={b,a};
  }
  vsort(ba);
  
  ll ans=1;
  ll l=ba[0].first;
  rep(i,m){
    ll a=ba[i].second, b=ba[i].first;
    if(l<=a){
      ans++;
      l=b;
    }
  }
  cout<<ans<<endl;
}

Measured memory_bytes: 1792
#include<iostream>
#include<string>
#include<algorithm>
#include<math.h>
using namespace std;

int main()
{
    int N;
	int x[8], y[8];
	cin >> N;
	for(int i=0; i<N; i++)
		cin >> x[i] >> y[i];

	double dxy[8][8];
	for(int i=0; i<N; i++){
		for(int j=0; j<N; j++)
			dxy[i][j] = sqrt( ((x[i]-x[j])*(x[i]-x[j])) + ((y[i]-y[j])*(y[i]-y[j])) );
	}

	int perm[8];
	for(int i=0; i<N; i++){
            perm[i] = i;
	}
	double sum = 0;
	do{
        for(int i=0; i<N-1; i++){
           sum += dxy[perm[i]][perm[i+1]];
		  // cout << perm[i];
        }
		//cout << perm[N-1] << endl;
		//cout << "sum = " << sum << endl;
    }while(next_permutation(perm,perm+N));

	int factN = 1;
	for(int i=0; i<N; i++){
            factN *= (i+1);
	}
	sum /= factN;
	printf("%.10f\n", sum);
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, a, n) for(int i = a; i < n; i++)
#define repb(i, a, b) for(int i = a; i >= b; i--)
#define all(a) a.begin(), a.end()
#define o(a) cout << a << endl
#define int long long
#define first first
#define second se
using namespace std;
typedef pair<int, int> P;
typedef vector<int> vi;

signed main(){
    string s;
    cin >> s;
    int now = 0, sc = 0;
    rep(i, 0, s.size()){
        if(s[i] == 'g'){
            if(now > 0){
                now--;
                sc++;
            }else{
                now++;
            }
        }else{
            if(now > 0){
                now--;
            }else{
                now++;
                sc--;
            }
        }
    }
    o(sc);
}

Measured memory_bytes: 512
#include <bits/stdc++.h>
#define ll long long int
#define pb push_back
#define mp make_pair
#define mod 1000000007
#define pi 3.141592653589793
using namespace std;


bool prime[100000];
vector<ll> primes;
void sieve() {
    fill(prime, prime + 100000, 1);
    prime[0] = prime[1] = 0;

    for (int i = 2; i < 100000; i++) {
        if (prime[i]) {
            primes.pb(i);
            for (int j = i * 2; j < 100000; j += i) {
                prime[j] = 0;
            }
        }
    }
}



int main() {
    cout << setprecision(10);
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);

    string s;
    cin >> s;
    int n = s.size();
    int ans = 0;
    char tar = '1';
    map<char, char> d;
    d['0'] = '1';
    d['1'] = '0';

    for (char c : s) {
        if (c != tar) {
            ans++;
        }
        tar = d[tar];
    }

    int ans1 = 0;
    tar = '0';
    for (char c : s) {
        if (c != tar) {
            ans1++;
        }
        tar = d[tar];
    }

    cout << min(ans, ans1);


}






Measured memory_bytes: 512
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> pll;
typedef vector<ll> vll;
typedef vector<vector<ll>> vvll;
typedef vector<pll> vpll;

#define INX(x) (cin >> x)
#define OUTX(x) (cout << x << endl)

#define ADD emplace_back
#define MP make_pair
#define VVEC(type) vector<vector<type>>

int main()
{
    ll H, W, M;
    cin >> H >> W >> M;

    vpll bomb;
    vll rcount(H+1, 0);
    vll ccount(W+1, 0);
    for (ll i = 0; i < M; i++)
    {
        ll tmp1, tmp2;
        cin >> tmp1 >> tmp2;
        rcount[tmp1]++;
        ccount[tmp2]++;
        bomb.ADD(MP(tmp1,tmp2));
    }
    
    ll rmax = 0;
    vll rmaxindex;
     for (ll i = 1; i <= H; i++)
    {
        if(rmax < rcount[i])
        {
            rmax = rcount[i];
            rmaxindex.resize(0);
            rmaxindex.ADD(i);
        }
        else if(rmax == rcount[i])
        {
            rmaxindex.ADD(i);
        }
    }

    ll cmax = 0;
    vll cmaxindex;
     for (ll i = 1; i <= W; i++)
    {
        if(cmax < ccount[i])
        {
            cmax = ccount[i];
            cmaxindex.resize(0);
            cmaxindex.ADD(i);
        }
        else if(cmax == ccount[i])
        {
            cmaxindex.ADD(i);
        }
    }

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

    ll result = rmax + cmax;
    bool isFound = false;
    for(auto x : rmaxindex)
    {
        for(auto y : cmaxindex)
        {
            if(binary_search(bomb.begin(), bomb.end(), MP(x, y)))
            {
                continue;
            }
            else
            {
                isFound = true;
                break;
            }
        }

        if(isFound)
        {
            break;
        }
    }
    cout << (isFound ? result : result - 1) << endl;


    return 0;
}


Measured memory_bytes: 21424
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (int)(n); i++)
#define REP(i,n) for (int i = 1; i < (int)(n); i++)
#define all(x) x.begin(),x.end()
#define rall(x) x.rbegin(),x.rend()
#define debug(var) do{cout << #var << " : "; view(var);}while(0)
template<class T> bool chmin(T &a, T b) {if(a>b) {a=b;return 1;}return 0;}
template<class T> bool chmax(T &a, T b) {if(a<b) {a=b;return 1;}return 0;}
using namespace std;
template<class T> void view(T e) {cout << e << endl;}
template<class T> void view(const vector<T> &v) {for(const auto &e : v){cout << e << " ";} cout << endl;}
template<class T> void view(const vector<vector<T>> &vv) {for(const auto &v : vv){view(v);}}
using vint = vector<int>;
using vvint = vector<vector<int>>;
using ll = long long;
using vll = vector<ll>;
using vvll = vector<vector<ll>>;
using P = pair<int,int>;
const int inf = 1e9;
const ll inf_l = 1e18;
const int MAX = 1e5;

int main() {
    string s; cin >> s;
    rep(i,s.size()) {
        if (s[i] == 'K' && s[i-1] != 'A') s.insert(s.begin()+i,'A');
    }
    rep(i,s.size()) {
        if (s[i] == 'B' && s[i-1] != 'A') s.insert(s.begin()+i,'A');
    }
    rep(i,s.size()) {
        if (s[i] == 'R' && s[i-1] != 'A') s.insert(s.begin()+i,'A');
    }
    if (s.back() != 'A') s.push_back('A');
    if (s == "AKIHABARA") cout << "YES" << endl;
    else cout << "NO" << endl;
}

Measured memory_bytes: 3620
#include <bits/stdc++.h>
#define inf (int)(1e9)
using namespace std;

int n;
string s;
vector<int> dp;
map<int, int> mp;

int solve();

int main() {
  cin >> s;
  n = s.size();
  cout << solve() << endl;
  return 0;
}

int solve() {
  int sum = 0;
  dp.assign(n + 1, inf);
  dp[0] = 0;
  mp[0] = 0;
  for (int i = 0; i < n; ++i) {
    sum ^= 1 << (s[i] - 'a');
    for (int j = 0; j < 26; ++j) {
      int bit = sum ^ (1 << j);
      if (mp.find(bit) != mp.end()) dp[i + 1] = min(dp[i + 1], mp[bit] + 1);
    }
    if (mp.find(sum) != mp.end()) dp[i + 1] = min(dp[i + 1], mp[sum] + 1);
    if (mp.find(sum) == mp.end()) mp[sum] = dp[i + 1];
    if (mp[sum] > dp[i + 1]) mp[sum] = dp[i + 1];
  }
  return dp[n];
}

Measured memory_bytes: 13584
#include <bits/stdc++.h>
 
# define C continue;
# define R return
 
# define D double
# define I insert
# define ll long long
# define ld long double
 
# define ull unsigned long long
# define ui unsigned int
 
# define pb push_back
# define pf push_front
 
# define vi vector < int >
# define vc vector < char >
# define vs vector < string >
# define vb vector < bool >
# define vd vector < D >
# define vll vector < ll >
# define vull vector < ull >
# define vld vector < ld >
# define PQ priority_queue
 
# define vvi vector < vector < int > >
# define vvb vector < vector < bool > >
# define vvc vector < vector < char > >
# define vvll vector < vector < ll > >
# define vvd vector < vector < D > >
# define vvld vector < vector < ld > >
 
# define all(v) (v).begin() , (v).end()
# define allrev(v) (v).rbegin() , (v).rend()
# define allcomp(v) v.begin() , v.end() , comp
# define allrevcomp(v) v.rbegin() , v.rend() , comp
 
# define pii pair < int , int >
# define pll pair < ll , ll >
# define pld pair < ld , ld >
# define pDD pair < D , D >
# define pipii pair<int, pii >
# define pcpii pair<char,pii>
 
# define vpld vector < pld >
# define vpii vector < pii >
# define vpll vector < pll >
# define vpDD vector < pDD >
 
# define vvpii vector < vector < pii > >
# define vpipii vector< pipii >
 
# define F first
# define S second
# define mp make_pair
 
# define unm unordered_map
# define unmii unm< int , int >
# define unmll unm< ll , ll >
# define unms unm<string,int>
# define unmci unm<char,int>
 
# define sortvia sort(a.begin(),a.end());
# define sortvib sort(b.begin(),b.end());
# define revsorta sort(a.begin(), a.end(), greater <int>());
# define revsortb sort(b.begin(), b.end(), greater <>());
# define loop(q,n) for(int i=q;i<=n;i++)
# define loopj(r,n) for(int j=r;j<n;j++)
# define loopm(s,m) for(int k=s;k<m;k++)
# define test int t;cin >> t;while(t--)
# define nextline "\n"
# define tab "\t"
# define space " "
//YES
//NO
//cout
//true
//false
//yes
//no
 
const ll mod9=1e9+7;
const ll maxsize=2e9+1;
const ll mod =998244353;
const ll mod2=1073741824;
const ll INF=1e8;
 
using namespace std;

int modfn(int p){
	if(p<0)return (-1*p);
	else return p;
}

int main()
{
ios::sync_with_stdio(0);
cin.tie(0);
	int n;
	cin>>n;
	vi h(n+1);
	vi a(n+1);
	loop(1,n)cin>>h[i];
	// loop(1,n)cout<<h[i]<<space;
	a[n]=0;
	a[n-1]=modfn(h[n]-h[n-1]);
	// cout<<a[n]<<space<<a[n-1];
	// cout<<nextline;
	int term1,term2;
	for(int i=n-2;i>=1;i--){
		term1=modfn(h[i]-h[i+1])+a[i+1];
		term2=modfn(h[i]-h[i+2])+a[i+2];
		// cout<<i<<space<<term1<<space<<term2<<nextline;
		a[i]=min(term1,term2);
	}
	cout<<a[1];
}









Measured memory_bytes: 1024
// AOJ Volume 0 Problem 0066

#include <stdio.h>
#include <stdlib.h>


int main(void)
{
    char in_str[81];
	int field[9];
	int i, j;
	int check;
	
	while (scanf("%s", in_str) != EOF){
		
		for (i = 0; i < 9; i++){
			if (in_str[i] == 'o'){
				field[i] = 1;
			}
			else if (in_str[i] == 'x'){
				field[i] = -1;
			}
			else {
				field[i] = 0;
			}
		}
		
		for (i = 0; i < 3; i++){
			check = 0;
			for (j = 0; j < 3; j++){
				check += field[i * 3 + j];
			}
			if (abs(check) == 3){
				goto end;
			}
			check = 0;
			for (j = 0; j < 3; j++){
				check += field[i + j * 3];
			}
			if (abs(check) == 3){
				goto end;
			}
		}
		
		check = field[0] + field[4] + field[8];
		if (abs(check) == 3){
			goto end;
		}
		
		check = field[2] + field[4] + field[6];

end:
		if (check == 3){
			printf("o\n");
		}
		else if (check == -3){
			printf("x\n");
		}
		else {
			printf("d\n");
		}
	}

	return (0);
}

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

signed main(){
    int a,b,c;cin>>a>>b>>c;
    if(a+b+c<22)cout<<"win"<<endl;
    else cout<<"bust"<<endl;
}


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

using namespace std;

#define REP(i,n)   for(int i=0; i<(int)(n); i++)
#define FOR(i,b,e) for(int i=(b); i<=(int)(e); i++)
#define DUMP(a, n) REP(i, n) printf("%d%c", a[i], i + 1 == n ? '\n' : ' ')

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

//------------------------------------------------------------------------------
const int UF_SIZE = 400000;

int par[UF_SIZE];
int rnk[UF_SIZE];

void union_find_init(int n) {
  REP(i, n) {
    par[i] = i;
    rnk[i] = 0;
  }
}

int find(int x) {
  if (par[x] == x) {
    return x;
  } else {
    return par[x] = find(par[x]);
  }
}

void unite(int x, int y) {
  x = find(x);
  y = find(y);
  if (x == y) return;

  if (rnk[x] < rnk[y]) {
    par[x] = y;
  } else {
    par[y] = x;
    if (rnk[x] == rnk[y]) rnk[x]++;
  }
}

bool same(int x, int y) {
  return find(x) == find(y);
}

//------------------------------------------------------------------------------
const int N_MAX = 100000;
const int M_MAX = 200000;
const int C_MAX = 1000000;
const int V_MAX = N_MAX + M_MAX * 2;
const int INF = 1e9;

struct edge { int p, q, c; };

int N, M;
edge es[M_MAX];

int VC;
map<ll, int> mp;

int V;
vector<int> G[V_MAX];
int d[V_MAX];

int idx(int v, int c) {
  ll vc = (ll) v * C_MAX + c;
  if (mp.count(vc) == 0) mp[vc] = VC++;
  return mp[vc];
}

void add_edge(int from, int to) {
  G[from].push_back(to);
  G[to].push_back(from);
}

void dijkstra(int s) {
  priority_queue<P, vector<P>, greater<P> > que;
  fill(d, d + V, INF);
  d[s] = 0;
  que.push(P(0, s));

  while (!que.empty()) {
    P p = que.top(); que.pop();
    int v = p.second;
    if (d[v] < p.first) continue;
    REP(i, G[v].size()) {
      int u = G[v][i];
      int cost = u >= N ? 1 : 0;
      if (d[u] > d[v] + cost) {
        d[u] = d[v] + cost;
        que.push(P(d[u], u));
      }
    }
  }
}

void solve() {
  union_find_init(M * 2);
  REP(i, M) {
    int p = es[i].p;
    int q = es[i].q;
    int c = es[i].c;
    unite(idx(p, c), idx(q, c));
  }
  REP(i, M) {
    int p = es[i].p;
    int q = es[i].q;
    int c = es[i].c;
    int ei = find(idx(p, c));
    add_edge(p, N + ei);
    add_edge(q, N + ei);
  }

  V = N + M * 2;
  // REP(v, V) {
  //   REP(i, G[v].size()) {
  //     printf("v: %d, u: %d\n", v, G[v][i]);
  //   }
  // }

  dijkstra(0);

  // DUMP(d, V);

  int ans = d[N - 1];
  printf("%d\n", ans == INF ? -1 : ans);
}

void input() {
  scanf("%d%d", &N, &M);
  REP(i, M) {
    int p, q, c;
    scanf("%d%d%d", &p, &q, &c);
    es[i] = { p - 1, q - 1, c - 1};
  }
}

int main() {
  input();
  solve();
  return 0;
}




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

namespace ABC057A
{
    class Program
    {
        static void Main(string[] args)
        {
            int a, b, c;

            var word = Console.ReadLine().Split(' ');

            a = int.Parse(word[0]);
            b = int.Parse(word[1]);

            c = a + b;

            if (c < 24)
                Console.WriteLine(c);
            else
                Console.WriteLine(c - 24);

            Console.ReadKey();
        }
    }
}


Measured memory_bytes: 11220
#include <iostream>
#include <string>
#include <vector>
#include <typeinfo>

using namespace std;

auto max_int = [](int x, int y){return(x>y?x:y);};

string k_substr(int k, int offset, int n, string t){
    string str = "";
    for (int i=offset;i < n;i+=k) {
        str += t[i];
    }
    return(str);
}

typedef struct jnkn {
    int score[3] = {0};
} jnkn;

int dp_solve(string str, int m[3][3]) {
    jnkn j_current, j_previous;
    for (auto it = str.begin();it != str.end();it++) {
        int j;
        char &c = *it;
        // if (c=='r') {
        //     cout << "c is r" << endl;
        // } else {
        //     cout << "c is not r" << endl;
        // }
        if (c=='r') {
            j = 0;
        } else if(c=='s') {
            j = 1;
        } else if(c=='p') {
            j = 2;
        } else {
            abort();
        }
        // switch (c) {
        //     case 'r':
        //         j=0;
        //     case 's':
        //         j=1;
        //     case 'p':
        //         j=2;
        //     default:
        //         cerr << "warnings:" << c << endl;
        //         abort();
        // }
        j_current.score[0] = max_int(j_previous.score[1] + m[0][j],
                                     j_previous.score[2] + m[0][j]);
        j_current.score[1] = max_int(j_previous.score[0] + m[1][j],
                                     j_previous.score[2] + m[1][j]);
        j_current.score[2] = max_int(j_previous.score[0] + m[2][j],
                                     j_previous.score[1] + m[2][j]);
        j_previous.score[0] = j_current.score[0];
        j_previous.score[1] = j_current.score[1];
        j_previous.score[2] = j_current.score[2];
    }
    return(max_int(max_int(j_current.score[0], j_current.score[1]), j_current.score[2]));
}

int main(){
    int n, k, r, s, p;
    int a[3][100001] = {0};
    int m[3][3] = {0};
    string t;
    cin >> n >> k;
    cin >> r >> s >> p;
    cin >> t;
    m[0][1] = r;
    m[1][2] = s;
    m[2][0] = p;
    int tot = 0;
    for (int offset=0;offset<k;offset++) {
        string str = k_substr(k, offset, n, t);
        tot += dp_solve(str, m);
    }
    cout << tot << endl;
    return(0);
}


// rspss
// pspsr
// pspsp
// pprps
// prpss
// prpsr


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

int main(){
  string S;
  int ccnt=0;
  bool b = 1;
  cin >> S;
  if(S.at(0)!='A'){
    b = 0;
  }
  for(int i=1;i<S.size();++i){
    if(isupper(S.at(i))){
      if(i==1||i==S.size()-1||S.at(i)!='C'){
        b = 0;
      }
      ++ccnt;
    }
  }
  if(ccnt!=1){
    b = 0;
  }
  if(b){
    cout << "AC" << endl;
  }else{
    cout << "WA" << endl;
  }
}


Measured memory_bytes: 256
#include<iostream>

using namespace std;

bool func(int a,int b)
{
	if(abs(a-b)==1)return true;
	return false;
}

int main()
{
	int N;
	int *a;
	int loop = 0;
	int ans = 0;
	int *cnt;

	cin >> N;
	a = new int[N];

	for(int i=0;i<N;i++)
	{
		cin >> a[i];
		loop = max(loop,a[i]);
	}

	cnt = new int[loop+1];

	for(int i=0;i<loop+1;i++)
	{
		cnt[i] = 0;
	}

	for(int i=0;i<N;i++)
	{
		cnt[a[i]]++;
		cnt[a[i]-1]++;
		cnt[a[i]+1]++;
	}

	for(int i=0;i<loop+1;i++)
	{
		ans = max(ans,cnt[i]);
	}

	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 1024
#include<iostream>
#include<cstdio>
#include<algorithm>
using namespace std;
int main(){
	while(1){
        int n;
        cin >> n;
        if(n == 0) break;
        int cnt = 0;
        while(1){
            if(n == 1) break;
            if(n % 2 == 0){
                n /= 2;
                cnt++;
            }
            else{
                n = n * 3 + 1;
                cnt++;
            }
        }
        cout << cnt << endl;
	}
	return 0;
}

Measured memory_bytes: 1160
#include <iostream>
#include <iomanip>
#include <vector>
#include <algorithm>
#include <numeric>
#include <functional>
#include <cmath>
#include <string>
#include <map>
#include <queue>
#include <stack>

using namespace std;
int main(int argc, const char * argv[]) {
    
    string w;
    cin >> w;

    map<char, int> m;
    for(int i=0; i<w.size(); i++){
        m[w[i]]++;
    }

    for(map<char, int>::iterator it = m.begin(), itEnd=m.end(); it!=itEnd; it++){
        if ( (*it).second %2 ) {
            cout << "No" << endl;
            return 0;
        }
    }

    cout << "Yes" << endl;


    return 0;
}

Measured memory_bytes: 256
#include<iostream>
using namespace std;
int main() {
	int a, b, c, d, e, k;
	cin >> a >> b >> c >> d >> e >> k;
	if (e - a > k) {
		cout << ":(" << endl;
	}
	else if (e-a <= k){
		cout << "Yay!" << endl;
	}
	return 0;
}


Measured memory_bytes: 256
#include "bits/stdc++.h"
#define hhh cerr<<"hhh"<<endl
#define see(x) cerr<<(#x)<<'='<<(x)<<endl
using namespace std;
typedef long long ll;
typedef pair<int,int> pr;
inline int read() {int x=0,f=1;char c=getchar();while(c!='-'&&(c<'0'||c>'9'))c=getchar();if(c=='-')f=-1,c=getchar();while(c>='0'&&c<='9')x=x*10+c-'0',c=getchar();return f*x;}

const int maxn = 3e5+7;
const int inf = 0x3f3f3f3f;
const int mod = 1e9+7;

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

int main() {
    int k=read(); ll s=0;
    for(int i=1; i<=k; ++i) {
        for(int j=1; j<=k; ++j) {
            for(int t=1; t<=k; ++t) {
                s+=gcd(gcd(i,j),t);
            }
        }
    }
    cout<<s<<endl;
}

Measured memory_bytes: 3624
#include <stdio.h>
#include <stdlib.h>

int main(){
  int *a,i,j,n,key;

  scanf("%d",&n);
  a =  malloc( n*sizeof(int));

  for(i=0;i<n;i++) scanf("%d",&a[i]);

  for(i=0;i<n;i++){
    printf("%d",a[i]);
    if(i!=n-1) putchar(' ');
  }

  putchar('\n');


  for(j=1;j<n;j++){
    key=a[j];
    i=j-1;

    while( i>=0 && a[i] >key){
      a[i+1]=a[i];
      i-=1;
    }

    a[i+1]=key;

    for(i=0;i<n;i++){
      printf("%d",a[i]);
      if(i!=n-1) putchar(' ');
    }

    putchar('\n');
  }

  return 0;
}
    



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

ll dp[101010];

int main() {
    int n, k;
    cin >> n >> k;
    vector<ll> h(n);
    rep(i, n) cin >> h[i];

    fill(dp, dp+n+1, 1e10);

    dp[0] = 0;
    for (int i=0; i<n; ++i) {
        for (int j=1; j<=k; ++j) {
            if (i+j<n) dp[i+j] = min(dp[i+j], dp[i] + abs(h[i] - h[i+j]));
        }
    }

    cout << dp[n-1] << endl;
}


Measured memory_bytes: 1792
#include<stdio.h>
#include<string.h>

#define LEN 100005

typedef struct pp{
  char name[100];
  int t;
}P;

void initialize(void);
int isEmpty(void);
int isFull(void);
void enqueue(P);
P dequeue(void);

P Q[LEN+1];
int head, tail, n;

void initialize(){
  head = 0;
  tail = 0;
}
int isEmpty(){
  if(head == tail)
    return 1;
  else return 0;
}

int isFull(){
  if(head == (tail + 1) % LEN)
    return 1;
  else return 0;
}

void enqueue(P x){
  if(isFull()==1){
     fprintf(stderr,"Over\n");
  }
  Q[tail]=x;
  if((tail+1)==LEN){
    tail=0;
  }
  else tail++;
}

P dequeue(){
  P x;
  if(isEmpty()==1){
    fprintf(stderr,"Under\n");
  }
  x = Q[head];
  if((head+1)== LEN){
    head=0;
  }
  else head++;
  return x;
}


int main(){
  int elaps = 0,c=0;
  int i, q;
  P u;
  scanf("%d %d", &n, &q);
  head = n;
  tail = n+1;
  for ( i = 1; i <= n; i++){
    scanf("%s", Q[i].name);
    scanf("%d", &Q[i].t);
  }
  initialize();
  for(i=1;i<=n;i++){
    enqueue(Q[i]);
  }
  while(c!=n){
    u=Q[head];
    u.t=Q[head].t-q;
    if(u.t<=0){
      elaps+=u.t+q;
      dequeue();
      printf("%s %d\n",u.name,elaps);
      c++;
    }
    else{
      elaps+=q;
      dequeue();
      enqueue(u);
    }
  }
  
  
  return 0;
}



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


    int N=0;
    int W=0;
    int max=0;
    int a=0;
    int w[1000]={0};
    int v[1000]={0};
    int dp[10000][1000]={0};
    

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

    for(int i=0;i<N;i++){
        cin>>v[i]>>w[i];
    }
    a=w[0];
    for(int i=0;i<N;i++){
        if(a>w[i]){
            a=w[i];
        }
    }
    for(int i=a;i<W+1;i++){
        for(int j=0;j<N;j++){
            
            if(i>=w[j]&&dp[i][j]==0){
                for(int B=i;B<W+1;B++){
                    dp[B][j]=v[j];
                }
            }
            if(i-w[j]>0&&j>0){
                dp[i][j]+=dp[i-w[j]][j-1];
            }
            if(dp[i][j]<dp[i][j-1]&&j>0){
                dp[i][j]=dp[i][j-1];
            }
       
       
        }
    
    }
    if(dp[W][N-1]<dp[W][N-2]){
        dp[W][N-1]=dp[W][N-2];
    }

    cout<<dp[W][N-1]<<endl;
   
    return 0;

}

Measured memory_bytes: 42116
// in the name of Allah ;
#include<bits/stdc++.h>
using namespace std ;
const int maxn = 1e5 + 10 ;
int arr[maxn] , n , x ;
int t[4] ;
void input() 
{	
	cin >> n ;
	for ( int i= 0 ; i < n ; i++ ) 
		cin >> x , arr[i] = x % 4 , t[x%4]++;
}
int main () 
{
	input() ;	
	if ( t[2] && (n+1-t[2])/2 <= t[0] ) 
		cout << "Yes" << endl;	
	else if ( t[2] == 0 && n/2 <= t[0] ) 
		cout << "Yes" << endl;
	else
		cout << "No" << endl;	
	
}

Measured memory_bytes: 640
#include <iostream>

//include
//------------------------------------------
#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <stack>
#include <queue>
#include <bitset>
#include <tuple>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>
#include <climits>

using namespace std;

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

//math
//-------------------------------------------
template <class T>
inline T sqr(T x) { return x * x; }

//typedef
//------------------------------------------
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<long long> VL;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef long long LL;

//container util
//------------------------------------------
#define ALL(a) (a).begin(), (a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define MP make_pair
#define SZ(a) int((a).size())
#define EACH(i, c) for (auto i = (c).begin(); i != (c).end(); ++i)
#define EXIST(s, e) ((s).find(e) != (s).end())
#define SORT(c) sort((c).begin(), (c).end())

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

//constant
//--------------------------------------------
const double EPS = 1e-10;
const double PI = acos(-1.0);
const long long INFL = __LONG_LONG_MAX__ / 10;
const int INFI = __INT_MAX__ / 10;

//clear memory
#define CLR(a) memset((a), 0, sizeof(a))

//debug
// #define dump(x) cerr << #x << " = " << (x) << endl;
// #define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" \
//                       << " " << __FILE__ << endl;

enum Behav
{
    SEA,
    Mt,
    HOME
};

int N;
VI A, B, C;

int main()
{
    cin >> N;
    REP(i, N)
    {
        int a, b, c;
        cin >> a >> b >> c;
        A.push_back(a);
        B.push_back(b);
        C.push_back(c);
    }

    VL max_seas(N, -1);
    VL max_mts(N, -1);
    VL max_homes(N, -1);

    max_seas[0] = A[0];
    max_mts[0] = B[0];
    max_homes[0] = C[0];

    FOR(day, 1, N)
    {
        max_seas[day] = max(
            {max_mts[day - 1] + A[day],
             max_homes[day - 1] + A[day]});
        max_mts[day] = max(
            {max_seas[day - 1] + B[day],
             max_homes[day - 1] + B[day]});
        max_homes[day] = max(
            {max_mts[day - 1] + C[day],
             max_seas[day - 1] + C[day]});
    }
    LL ans = max({
        max_seas[N - 1],
        max_mts[N - 1],
        max_homes[N - 1],
    });
    cout << ans << endl;
}

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

#define all(v) (v).begin(), (v).end()
#define sortv(v) sort(all(v))
#define uniqv(v) (v).erase(unique(all(v)), (v).end())
#define pb push_back
#define FI first
#define SE second
#define lb lower_bound
#define ub upper_bound
#define mp make_pair
#define test 1
#define TEST if(test)

using namespace std;

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

const int MOD = 1000000007; // 998244353
const int INF = 2e9;
const ll INFLL = 1e18;
const int MAX_N = 1;

ll N;

int main(){
	cin>>N;
	cout<<N*(N-1)/2;
	return 0;
}


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


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

const int oo = 1e9 + 7;
const int mod = 1e9 + 7;

int main (){
    ll n, m, ans;
    cin >> n >> m;
    if (m < 2*n){
        ans = m/2;
    }
    else {
        ans = n;
        m -= 2*n;
        ans+=m/4;
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define rep(i,a,n) for(i=a;i<=n;i++)
#define ll long long
int main(){
  ll i,j;
  ll N,K;
  ll countMod[200001];
  ll sum = 0;
  ll sumTmp;
  
  
  cin >> N >> K ;
  rep(i,0,K-1){
   countMod[i] = 0;
  }
  
  rep(i,1,N){
    if(2*i%K == 0){
      countMod[i%K] += 1;
      //cout << i << endl;
    }
  }
  rep(i,0,K-1){
    sumTmp = sum;
    sum += pow(countMod[i],3);
    
    if(sum != sumTmp){
      //cout << i << endl;
      //cout << sum << endl;
      //cout << "*" << endl;
    }
    
  }
  //cout << countMod[199606] << endl;
  //cout << pow(countMod[199607],3) << endl;
  //cout << countMod[199608] << endl;
  
  cout << sum << endl;
  
}

Measured memory_bytes: 1792
#include <iostream>

using namespace std;

int main()
{
    int m , i ;
    string T , S ;
    m = 0 ;
    cin >> S >> T ;
    for(i=0; i <= 2 ; i++)
    {
        if(S[i] == T[i])
        {
            m = m + 1 ;
        }
    }


    cout << m << endl;
    return 0;
}


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

#define ll long long

inline ll read() {
    ll x = 0, f = 1; char ch = getchar();
    for(; ch < '0' || ch>'9'; ch = getchar())
        if(ch == '-') f = -f;
    for(; ch >= '0' && ch <= '9'; ch = getchar())
        x = x * 10 + ch - '0';
    return x * f;
}

inline void chkmin( int &a, int b ) { if(a > b) a = b; }

inline void chkmax( int &a, int b ) { if(a < b) a = b; }

#define _ read()

#define ln endl

const int N = 1e5 + 5;
int n, siz[N], tmp, ans[N];
vector<int> vv[N], id[N];

inline void dfs( int u, int fa, int pre )
{
	int cnt = 0;
	for( int i = 0; i < vv[u].size(); i++ ) 
	{
		int v = vv[u][i];
		if(v == fa) 
			continue;
		++cnt;
		if(cnt == pre)
			++cnt;
		ans[id[u][i]] = cnt;
		dfs(v, u, cnt);
	}
}

int main()
{
	n = _;
	for( int i = 1, u, v; i < n; i++ ) 
		u = _, v = _, 
		vv[u].push_back(v),
		vv[v].push_back(u),
		id[u].push_back(i),
		id[v].push_back(i),
		tmp = max(tmp, (int)max(vv[u].size(), vv[v].size()));
	cout << tmp << ln;
	dfs(1, 0, 0);
	for( int i = 1; i < n; i++ ) 
		cout << ans[i] << ln;
}

Measured memory_bytes: 12032
/**
 * The man who codes no bugs
 * McCheng is the man studying Maths in CUHK with IQ200
 * @author McCheng
 */

#include <bits/stdc++.h>
using namespace std;

class AAirConditioner {
public:
    static constexpr int kStressCount = 0;
    static void generateTest(ostream& test) {}
	void solve(istream& cin, ostream& cout) {
int n;
cin>>n;
if (n>=30){
    cout << "Yes";
} else cout << "No";
	}
};

signed main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    istream &in(cin);
    ostream &out(cout);
    out << fixed;
    out.precision(20);
    AAirConditioner solver;
    solver.solve(in, out);
}


Measured memory_bytes: 3632
input()
S = list(map(int,input().split()))
i = 0
ans = 0
while True:
    if i >= len(S):
        #print('終わり！')
        break
    for j in range(i+1,len(S)+1):
        #print(S[i:j])
        a = max(S[i:j])
        if j >= len(S):
            #print(1,S[i:j],i,j,ans)
            ans += max(S[i:j])
            i += j
            break
        elif a <= S[j]:
            #print(2,i,j,ans)
            continue
        else:
            #print(3,S[i:j],i,j,ans)
            ans += max(S[i:j])
            ans -= S[j]
            i = j
            break
print(ans)

Measured memory_bytes: 3064
using System;
using System.Linq;

class C
{
	static void Main()
	{
		var n = int.Parse(Console.ReadLine());
		var ps = new int[n].Select(_ => int.Parse(Console.ReadLine()))
			.Select(a => new int[a].Select(i => Console.ReadLine().Split().Select(int.Parse).ToArray()).ToArray())
			.ToArray();

		var m = new int[n, n];
		for (int i = 0; i < n; i++)
			foreach (var xy in ps[i])
				m[i, xy[0] - 1] = xy[1] == 0 ? -1 : 1;

		var p2 = new int[n + 1];
		p2[0] = 1;
		for (int i = 1; i <= n; i++) p2[i] = 2 * p2[i - 1];

		var M = 0;
		for (int x = 0; x < p2[n]; x++)
		{
			var ok = true;
			var c = 0;
			for (int i = 0; i < n; i++)
			{
				if ((x & p2[i]) == 0) continue;
				c++;
				for (int j = 0; j < n; j++)
				{
					if (m[i, j] == 1 && (x & p2[j]) == 0) { ok = false; break; }
					if (m[i, j] == -1 && (x & p2[j]) > 0) { ok = false; break; }
				}
				if (!ok) break;
			}
			if (ok) M = Math.Max(M, c);
		}
		Console.WriteLine(M);
	}
}


Measured memory_bytes: 13524
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }


int N, M, Q, L[200009], R[200009], X[509][509], C[509][509];

int main() {
	cin >> N >> M >> Q;
	for (int i = 1; i <= M; i++) {
		cin >> L[i] >> R[i]; X[L[i]][R[i]]++;
	}
	for (int i = 1; i <= N; i++) {
		for (int j = 1; j <= N; j++) C[i][j] = C[i][j - 1] + X[i][j];
	}
	for (int i = 1; i <= Q; i++) {
		int p, q; cin >> p >> q;
		int sum = 0;
		for (int j = p; j <= q; j++) sum += C[j][q];
		cout << sum << endl;
	}
	return 0;
}


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

#define pb push_back
#define f1 first
#define s2 second

#define fastio ios :: sync_with_stdio(); cin.tie(0); cout.tie(0);
#define debug(x...) cerr << "[" << #x << "]: " << x << "\n";

typedef long long ll;
typedef pair<int, int> ii;
typedef pair<ll, ll> pl;

int const N = 2e5 + 7;

int ar[N];
int dp[N];

int main()
{
	fastio;

	for (int i = 1; i < N; ++i)
		dp[i] = INT_MAX;

	int n, k;
	cin >> n >> k;

	for (int i = 1; i <= n; ++i)
		cin >> ar[i];

	dp[1] = 0;
	for (int i = 2; i <= n; ++i)
	{
		for (int j = max(1, i-k); j <= i-1; ++j)
			dp[i] = min(dp[i], dp[j] + abs(ar[i] - ar[j]));
	}
	cout << dp[n] << '\n';

	return 0;
}


Measured memory_bytes: 4800
/**
 *    author: gxfireball       
**/
#include <bits/stdc++.h>
#define ll long long
#define endl '\n'
#define fastio ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL); 
using namespace std;

void solve(){
   string str1,str2;
   cin>>str1>>str2;
   ll cnt=0;
   for(int i=0; i<str1.size(); ++i){
       if(str1[i] != str2[i]) cnt++;
   }
   cout<<cnt;

}

int main(){
    fastio;
    #ifndef ONLINE_JUDGE
        freopen("input.txt", "r", stdin);
        freopen("output.txt", "w", stdout);
    #endif
    int t;
    t = 1;
    //cin>>t;
    while(t--){
    	solve();
    }
    return 0;
}



Measured memory_bytes: 3800
#include <vector>
#include <cstdint>

using namespace std;

using lint=int64_t;
using uint=uint32_t;
using ulint=uint64_t;

template<class T>
using vector2d=vector<vector<T>>;

template<class T>
struct CumulativeSum2D{
  vector2d<T> cum;

  CumulativeSum2D(const vector2d<T>& data):cum(data.size(), vector<T>(data[0].size(),0)){
    cum[0][0]=data[0][0];
    for(int r=1;r<data.size();r++){
      cum[r][0]=cum[r-1][0]+data[r][0];
    }
    for(int c = 1; c < data[0].size(); ++c){
      cum[0][c]=cum[0][c-1]+data[0][c];
    }
    for(int r = 1; r < data.size(); ++r){
      for(int c = 1; c < data[0].size(); ++c){
        cum[r][c]=cum[r-1][c]+cum[r][c-1]-cum[r-1][c-1]+data[r][c];
      }
    }
  }


  /// \return 2頂点が(sr,sc)と(gr,gc)であるような矩形内の和(2頂点を含む)
  T Query(int sr, int sc, int gr, int gc){
    T result=cum[gr][gc];
    if(sr-1>=0){
      result-=cum[sr-1][gc];
    }
    if(sc-1>=0){
      result-=cum[gr][sc-1];
    }
    if(sr-1>=0&&sc-1>=0){
      result+=cum[sr-1][sc-1];
    }
    return result;
  }
};

//verify

#include <iostream>

template<class T>
bool UpdateMax(T &a, const T &b){
  if(a<b){
    a=b;
    return true;
  }else{
    return false;
  }
}

template<class T>
bool UpdateMin(T &a, const T &b){
  if(a>b){
    a=b;
    return true;
  }else{
    return false;
  }
}

int main(){
  int n;
  cin>>n;
  vector2d<lint> a(n, vector<lint>(n, 0));
  for(int i = 0; i < n; ++i){
    for(int j = 0; j < n; ++j){
      cin>>a[i][j];
    }
  }

  CumulativeSum2D<lint> cum(a);
  lint result=INT64_MIN/2;

  for(int sr = 0; sr < n; ++sr){
    for(int sc = 0; sc < n; ++sc){
      for(int gr = sr; gr < n; ++gr){
        for(int gc = sc; gc < n; ++gc){
          UpdateMax(result,cum.Query(sr,sc,gr,gc));
        }
      }
    }
  }

  cout<<result<<endl;

}


Measured memory_bytes: 3268
import java.util.Scanner;
class Main{
  public static void main(String[] args){
    Scanner scanner = new Scanner(System.in);
    int n = scanner.nextInt();
    int five_hundreds = n / 500;
    n -= five_hundreds * 500;
    System.out.println(five_hundreds * 1000 + n/5 * 5);
  }
}

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

int main() {
	int n;
	cin >> n;
	int ans = 0;
	rep(i, n) {
		int a;
		cin >> a;
		while(a%2==0){
			a /= 2;
			ans++;
		}
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 256
H, W = map(int, input().split())

maze = [list(input()) for _ in range(H)]

siro_yoko = []
#w_yoko = [False] * W
for i in range(H):
    w_yoko = [False] * W
    for j in range(W):
        #w_yoko = [False] * W
        if maze[i][j] == '.':
            w_yoko[j] = True
    if all(w_yoko):
        siro_yoko.append(i)
    

siro_tate = []
for j in range(W):
    h_tate = [False] * H
    for i in range(H):
        if maze[i][j] == '.':
            h_tate[i] = True
    if all(h_tate):
        siro_tate.append(j)

for i in range(H):
    yoko = ""
    for j in range(W):
        if not i in siro_yoko and  j not in siro_tate:
            yoko += maze[i][j]
    if yoko:
        print(yoko)
    else:
        print('', end='')

Measured memory_bytes: 3188
#include<algorithm>
#include<cstdio>
#include<set>
#include<queue>
#include<utility>
using namespace std;
typedef pair<int, int> P;

const int N_MAX = 1e5;
int n;
P p[N_MAX];
priority_queue<P> q, r;
set<P> s;
int loc[N_MAX];

int main() {
    scanf("%d", &n);
    for (int i = 0; i < n; i++) scanf("%d", &p[i].second);
    for (int i = 0; i < n; i++) scanf("%d", &p[i].first);
    sort(p, p + n);
    for (int i = 0; i < n; i++) {
        int j = lower_bound(p, p + n, p[i].second, [](const P &p1, const int &i1)->bool {
            return p1.first < i1;
        }) - p;
        q.emplace(j, i);
        r.emplace(i, j);
        loc[i] = j;
    }

    int cnt = n - 2;
    while (!q.empty()) {
        P p1 = q.top(); q.pop();
        if (loc[p1.second] != p1.first) continue;
        while (!r.empty() && r.top().first >= p1.first) {
            s.emplace(r.top().second, r.top().first);
            r.pop();
        }
        
        if (p1.first <= p1.second) continue;
        set<P>::iterator it = s.upper_bound(P(p1.second, -1));
        if (it == s.begin()) {
            if (s.empty() || it->first >= p1.first) {
                printf("No\n");
                return 0;
            }
        }
        else it = prev(it);
        q.emplace(it->first, p1.second);
        r.emplace(p1.second, it->first);
        loc[p1.second] = it->first;
        s.erase(it);
        if (cnt-- == 0) {
            printf("No\n");
            return 0;
        }
    }
    printf("Yes\n");
    return 0;
}



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

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define reps(i, n, m) for (int i = (int)(n); i <= (int)(m); i++)
#define all(obj) (obj).begin(), (obj).end()
#define rall(obj) (obj).rbegin(), (obj).rend()
#define collect(arr, size) rep(i,size) cin >> arr[i];
#define int long long

signed main(){
    int N, T;
    cin >> N >> T;
    
    int cost = INT_MAX;
    rep(i,N){
        int c,t;
        cin >> c >> t;
        if(t <= T) cost = min(cost, c);
    }
    
    if(cost == INT_MAX){
        cout << "TLE" << endl;
    }else{
        cout << cost << endl;
    }
}

Measured memory_bytes: 256
#include <stdio.h>

int main(){
    int A, B,N,m;
    int sum = 0;

    scanf("%d", &N);
    scanf("%d", &A);
    scanf("%d", &B);

    for (m = 1; m <= N; m++){
        int q_5,q_4,q_3,q_2,q_1,q_sum;
        q_5 = m / 10000;
        q_4 = (m - (q_5 * 10000))/ 1000;
        q_3 = (m - (q_5 * 10000) - (q_4 * 1000))/100;
        q_2 = (m - (q_5 * 10000)- (q_4 * 1000) - (q_3 * 100))/10;
        q_1 = m - (q_5 * 10000) - (q_4 * 1000) - (q_3 * 100) - (q_2 * 10);
        q_sum = q_5 + q_4 + q_3 + q_2 + q_1;
        if((A <= q_sum)&&(q_sum <= B)){
            sum =   sum + m;
        }
    }
    printf("%d", sum);
    return 0;
}

Measured memory_bytes: 128
#include <iostream>
#include <cmath>
#include <bits/stdc++.h>
#define FOR(i, a, b) for (int i = 0; i < (a); i < (b); ++i)
#define REP(i, n) for (int i = 0; i < (n); ++i)
using ll = long long;
using namespace std;

int main(void)
{
  ll N, K;
  cin >> N >> K;
  ll array[100001] = {};
  REP(i, N)
  {
    ll a, b;
    cin >> a >> b;
    array[a] += b;
  }
  REP(i, 100001)
  {
    K -= array[i];
    if (K <= 0)
    {
      cout << i << endl;
      return 0;
    }
  }
}


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

using namespace std;

map <int64_t, int64_t> arr;

int64_t res(int64_t n){
    int64_t num;
    if(n == 1) return 1;
    else{
        if(arr[n] != 0) return arr[n];
        else{
            num = 1 + 2*res(n/2);
            arr[n] = num;
        }
    }
    return num;
}

int main(){
    int64_t H;
    cin >> H;
    cout << res(H) << endl;
    return 0;
}

Measured memory_bytes: 256
import java.util.*;

public class Main {
    static int n;
    static int[] A = new int [50];

    static boolean solve(int i, int m) {
        // mになる組み合わせが見つかった
        if (m == 0) return true;
        // 与えられた数列の長さnを越えてしまった
        if (i >= n) return false;

        // 次の整数へ進める。i番目の整数を選んだ場合と選ばなかった場合
        boolean res = solve(i + 1, m) || solve(i + 1, m - A[i]);
        return res;
    }
    public static void main(String[] args) throws Exception {
        int q, m;

        Scanner sc = new Scanner(System.in);
        // 数列の長さ
        n = Integer.parseInt(sc.next());
        // 数列
        for (int i = 0; i < n; i++) {
            A[i] = Integer.parseInt(sc.next());
        }
        // mの数
        q = Integer.parseInt(sc.next());
        // q回検証する
        for (int i = 0; i < q; i++) {
            m = Integer.parseInt(sc.next());
            if (solve(0, m)) System.out.println("yes");
            else System.out.println("no");
        }
    }
}



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

int main() {
	int n;
	cin>>n;
	vector<int> a(n);
	for(int i=0;i<n;i++){
		cin>>a[i];
	}
	int b=a[0],s=a[0];
	for(int i=1;i<n;i++){
		b=max(b,a[i]);
		s=min(s,a[i]);
	}
	cout<<b-s<<endl;
}


Measured memory_bytes: 256
#include <cstdio>
#include <cstring>
#include <string>
#include <cmath>
#include <algorithm>
#include <vector>
#include <queue>
#include <set>
#include <map>
using namespace std;
using ll = long long;
using ii = pair<int, int>;
using vi = vector<int>;

#define errp(...) fprintf(stderr, __VA_ARGS__)

int main () { 
	char S[150];
	int N,x=0,y=0;

	scanf("%d %s",&N,S);
	for(int i=0;i<=N-1;i++) {
		if(S[i]=='I')
			x++;
		else
			x--;

		if(y<x)
			y=x;
	}
	printf("%d",y);
}

Measured memory_bytes: 128
from sys import stdin
#from collections import deque
#from math import sqrt, floor, ceil, log, log2, log10, pi, gcd, sin, cos, asin
def ii(): return int(stdin.readline())
def fi(): return float(stdin.readline())
def mi(): return map(int, stdin.readline().split())
def fmi(): return map(float, stdin.readline().split())
def li(): return list(mi())
def lsi():
    x=list(stdin.readline())
    x.pop()
    return x
def si(): return stdin.readline()
############# CODE STARTS HERE #############
n=ii()
s=[0]*n
a=li()
s[n-2]=abs(a[n-2]-a[n-1])
for i in range(n-3, -1, -1):
    s[i]=min(abs(a[i]-a[i+1])+s[i+1], abs(a[i]-a[i+2])+s[i+2])
print(s[0])

Measured memory_bytes: 14780
import bisect

n = int(input())

l = sorted(list(map(int, input().split())))
ans = 0

for i in range(n):
  for j in range(i+1, n):
    k = bisect.bisect_left(l, l[i]+l[j])
    #if k > j:
    ans += k - j - 1

print(ans)


Measured memory_bytes: 42972