akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#define INF 1e9
#define all(v) v.begin(), v.end()
#define rep(i, n) for(int i = 0; i < n; i++)
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define max(v) *max_element(v.begin(), v.end())
#define min(v) *min_element(v.begin(), v.end())
using namespace std;
 
int main(void){
    cin.tie(0);
    ios::sync_with_stdio(false);

    int n, x;
    cin>>n;
    //vector<int> l;
    list<int> l;
    
    for(int i = 0; i < n; i++){
        string com;
        cin>>com;
        if(com == "insert"){
            cin>>x;
//            cout<<"insert "<<x<<endl;
            l.push_front(x);
/*
            if(l.size() != 0){
                l.insert(l.begin(), x);
            }
            else{
                l.pb(x);
            }
*/
        }
        else if(com == "delete"){
            cin>>x;
//            cout<<"delete "<<x<<endl;
            for (list<int>::iterator it = l.begin(); it != l.end(); it++){
				if (*it == x) {
					l.erase(it); break;
				}
            }
        }
        else if(com == "deleteFirst"){
//            l.erase(l.begin());
//            cout<<"deleteFirst"<<endl;
            l.pop_front();
        }
        else if(com == "deleteLast"){
//            cout<<"deleteLast"<<endl;
            l.pop_back();
        }
/*
        rep(k, l.size()){
            if(l.size()-1 == k){
                cout<<l[k]<<endl;            
            }
            else{
                cout<<l[k]<<" ";
            }
        }
*/
    }
    list<int>::iterator it=l.begin();
    for(int i = 0; it != l.end(); it++,i++){
        if(i){
            cout<<" ";
        }
        cout<<(*it);
    }
    cout<<endl;
    return 0;
}



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

int n,m,c,s,g;
int p[30], q[30][60], r[30][60];

int d_dist[30][110][110];
int d_final[110][110];

const int inf = 1e9;

inline int getcost(int dist, int *q, int *p){
    if(dist == inf) return inf;
    int res = 0;
    rep(i,1000000){
        if(dist <= q[i+1]){
            res += (dist-q[i]) * p[i];
            break;
        } else {
            res += (q[i+1]-q[i]) * p[i];
        }
    }
    return res;
}

signed main(){
    ios::sync_with_stdio(0);
    cin.tie(0);
    /*
      ????´?????????¢??§???????????¨???WF 1
      ??????????????¨???????????¨????????? 2
      ??????????????§WF 3
     */
    while(cin >> n >> m >> c >> s >> g && n){
        --s, --g;
        rep(ic,c)rep(i,n)rep(j,n) d_dist[ic][i][j] = inf;
        rep(i,n)rep(j,n) d_final[i][j] = inf;
        rep(i,c)rep(j,n) d_dist[i][j][j] = 0;
        rep(i,n) d_final[i][i] = 0;

        rep(i,m){
            int x,y,d,c;
            cin >> x >> y >> d >> c;
            --x, --y, --c;
            d_dist[c][x][y] = min(d_dist[c][x][y], d);
            d_dist[c][y][x] = min(d_dist[c][y][x], d);
        }

        rep(i,c) cin >> p[i];
        rep(i,c){
            q[i][0] = 0;
            rep(j,p[i]-1) cin >> q[i][j+1];
            q[i][p[i]] = inf*2;
            rep(j,p[i]) cin >> r[i][j];
        }

        rep(ic,c) rep(k,n)rep(i,n)rep(j,n) {
            d_dist[ic][i][j] = min(d_dist[ic][i][j], d_dist[ic][i][k] + d_dist[ic][k][j]);
        }

        rep(ic,c)rep(i,n)rep(j,n){
            d_final[i][j] = min(d_final[i][j], getcost(d_dist[ic][i][j], q[ic], r[ic]));
        }

        rep(k,n)rep(i,n)rep(j,n){
            d_final[i][j] = min(d_final[i][j], d_final[i][k] + d_final[k][j]);
        }
        int ans = d_final[s][g];
        cout << (ans == inf ? -1 : ans) << '\n';
    }
}

Measured memory_bytes: 4120
using System;

class Program {
    static void Main(string[] args) {
        int n = Cin.Ni();

        for (int i = n; i > 0; i--) {
            int sqrt = (int)Math.Sqrt(i);
            if (sqrt * sqrt == i) {
                Console.WriteLine(i);
                return;
            }
        }


    }
}


public class Cin {
    private static string[] s = new string[0];
    private static int i = 0;

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

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

    public static int Ni() {
        return int.Parse(Next());
    }

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

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

}


Measured memory_bytes: 13140
using System;
using static System.Console;
using System.Collections.Generic;
using System.Linq;

namespace Atcoder
{
    class Program
    {
        static void Main(string[] args)
        {
            var a = int.Parse(ReadLine());
            if (a / 10 == 9 || a % 10 == 9) WriteLine("Yes");
            else WriteLine("No");
        }
    }
}



Measured memory_bytes: 11092
#define dbg(...) fprintf(stderr,__VA_ARGS__)
#define dpr(x) cerr<<#x<<": "<<x<<endl;
#define dprc(c) do{cerr<<#c<<":";for(auto&_i:(c)){cerr<<" "<<_i;}cerr<<endl;}while(0)
#include <bits/stdc++.h>
using namespace std;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<vi> vvi;
int INF = 1e9+7;
#define all(c) (c).begin(), (c).end()
#define tr(i,c) for(auto i=(c).begin();i!=(c).end();i++)
#define rtr(i,c) for(auto i=(c).rbegin();i!=(c).rend();i++)
#define rep(i,b) for(auto i=0;i<(b);i++)
#define pb push_back
#define sz(c) int((c).size())

int main(int argc, char **argv)
{
  int n, q;
  map<string, int> m;
  queue<string> waiting;
  cin >> n >> q;
  for (int i = 0; i < n; i++) {
    string name;
    int time;
    cin >> name >> time;
    m[name] = time;
    waiting.push(name);
  }

  int elapsed = 0;
  while (sz(waiting) > 0) {
    string s = waiting.front(); waiting.pop();
    m[s] -= q;
    if (m[s] > 0) {
      elapsed = elapsed + q;
      waiting.push(s);
    } else {
      elapsed = elapsed + q + m[s];
      cout << s << " " << elapsed << endl;
    }
  }
  return 0;
}

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

using namespace std;
typedef long long ll;
int main() {
  ll N, K;
  cin >> N >> K;
  map<ll, ll> m;
  for (int i = 0; i < N; ++i) {
    ll a, b;
    cin >> a >> b;
    m[a] += b;
  }

  ll sum = 0LL;
  for (auto const& e: m) {
    sum += e.second;
    if (sum >= K) {
      cout << e.first << endl;
      return 0;
    }
  }
  return 0;
}



Measured memory_bytes: 4224
#include <bits/stdc++.h>
using namespace std;
 
//long long
using ll = long long;
 
// pair<int, int>
using PII = pair<int, int>;
 
//最大値、mod
const int MOD = 1000000007;
const int INF = 1000000000;
const long long LINF = 1e18;
const int MAX = 510000;
 
//出力系
#define print(x) cout << x << endl
#define prints(x) cout << fixed << setprecision(10) << x << endl
#define printc(x) cout << setw(2) << setfill('0') << x << endl;
#define yes cout << "Yes" << endl
#define YES cout << "YES" << endl
#define no cout << "No" << endl
#define NO cout << "NO" << endl
 
// begin() end()
#define all(x) (x).begin(),(x).end()
 
//for
#define REP(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)
 
//最大公約数 
unsigned gcd(unsigned a, unsigned b) {
  if(a < b) return gcd(b, a);
  unsigned r;
  while ((r=a%b)) {
    a = b;
    b = r;
  }
  return b;
}
 
// 最小公倍数
unsigned lcm(unsigned a, unsigned b){
    return a / gcd(a, b) * b; 
}
 
// a = max(a, b), a = min(a, b)
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; }
 
// 階乗(MODをとる)
ll pow_mod(ll num, ll pow, ll mod) {
    ll prod = 1;
    num %= mod;
    while (pow > 0) {
        if (pow & 1) prod = prod * num % mod;
        num = num * num % mod;
        pow >>= 1;
    }
    return prod;
}
 
 
 
// 二項係数(MODとる、1 ≦ k ≦ n ≦ 10^7 程度)
// COMinit()
// COM(x, y)
// とコンビで使う
 
// テーブルを作る前処理
long long fac[MAX], finv[MAX], inv[MAX];
void COMinit() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (int i = 2; i < MAX; i++){
        fac[i] = fac[i - 1] * i % MOD;
        inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
        finv[i] = finv[i - 1] * inv[i] % MOD;
    }
}
 
// 二項係数計算
long long COM(int n, int k){
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}

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






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

  ll ans = 0;
  if(b == 0){
    cout << a * a << endl;
    return 0;
  }
  for (ll i = 1; i <= a; i++) {
      ans += max((ll)0, i - b)*(a / i) + max((ll)0, a % i - b + 1);
  }
  print(ans);
  return 0;
}


Measured memory_bytes: 256
n = int(input())

pedras = list(map(int,input().split()))

dp = [0] * n

dp[0] = 0
dp[1] = abs(pedras[0] - pedras[1])


for i in range(2,n):
    custo1 = dp[i-1] + abs(pedras[i-1] - pedras[i])
    custo2 = dp[i-2] + abs(pedras[i-2] - pedras[i])
    dp[i] = min(custo1,custo2)

print(dp[n-1])


Measured memory_bytes: 20444
#include<iostream>
#include<stack>
#include<vector>
#include<utility>
using namespace std;

int main(){
    char c;
    stack<int> bs_pos;
    vector<pair<int, int> > puddle; //???????????¢???
    int pos = 0;
    int total_area = 0;
    while (cin >> c) {
        pos++;
        if (c == '\\') {
            bs_pos.push(pos);
            continue;
        }
        if (c == '_' || bs_pos.empty()) continue;
        int left_pos = bs_pos.top();
        int area = pos - left_pos;
        total_area += area;
        bs_pos.pop();
        while (!puddle.empty() && left_pos < puddle.back().first) {
            area += puddle.back().second;
            puddle.pop_back();
        }
        puddle.push_back(make_pair(left_pos, area));
    }
    cout << total_area << endl;
    cout << puddle.size();
    for (int i = 0; i < puddle.size(); i++) {
        cout << " " << puddle[i].second;
    }
    cout << endl;
}

Measured memory_bytes: 3196
/* ex5_3
   seira3 */

#include<stdio.h>

int arrayIn(int obj,int size, int arr[]){ //objがarr内にあるかどうかを判別する関数,あれば1なければ0を返す
    int count = 0;
    for(int i = 0; i < size; i++){
        if(arr[i]==obj){
            count++;
            break;
        }
    }
    return count;
}

int main(void){
    int row, line, count, countRow, countLine; //変数宣言
    char square[100][100]; //元の迷路の配列を宣言
    int whiteRow[100], whiteLine[100]; //行,列全て'.'の番号を記憶する配列
    scanf("%d %d",&row,&line); //rowとlineに入力
    count = 0; //初期化
    countRow = 0; //初期化
    countLine = 0; //初期化
    for(int i = 0; i < row; i++){ //squareに入力
        for(int j = 0; j < line; j++){
            scanf(" %c",&square[i][j]);
        }
    }
    for(int i = 0; i < row; i++){ //全て-1に初期化(0で初期化すると0番目が全て'.'なときに区別がつかなくなる)
        whiteRow[i] = -1;
    }
    for(int i = 0; i < line; i++){ //全て-1に初期化(0で初期化すると0番目が全て'.'なときに区別がつかなくなる)
        whiteLine[i] = -1;
    }
    for(int i = 0; i < row; i++){ //何行目に全て'.'なのかを探してwhiteRowに格納する
        count = 0;
        for(int j = 0; j < line; j++){
            if (square[i][j] == '.'){
                count++;
            }
        }
        if(count == line){
            whiteRow[countRow] = i;
            countRow++;
        }
    }
    for(int i = 0; i < line; i++){ //何列目に全て'.'なのかを探してwhiteLineに格納する
        count = 0;
        for(int j = 0; j < row; j++){
            if (square[j][i] == '.'){
                count++;
            }
        }
        if(count == row){
            whiteLine[countLine] = i;
            countLine++;
        }
    }
    for(int i = 0; i < row; i++){ //答えを出力する
        for(int j = 0; j < line; j++){
            if(arrayIn(i,row,whiteRow) == 0 && arrayIn(j,line,whiteLine) == 0){ //もし全て'.'の行,列に属していなかったら
                printf("%c",square[i][j]);
            }
        }
        if(arrayIn(i,row,whiteRow) == 0){ //行が全て'.'でなければ改行
            printf("\n");
        }
    }
    return 0;
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using db = double;
#define fi first
#define se second
#define pb push_back
#define all(v) (v).begin(),(v).end()
#define siz(v) (ll)(v).size()
#define rep(i,n) for(ll i=0;i<(ll)(n);i++)
#define repn(i,n) for(ll i=0;i<=(ll)(n);i++)
typedef pair<int,int> P;
typedef pair<ll,ll> PL;
const ll mod = 1000000007;
const ll INF = 1000000099;
//cin.tie(0);
//ios::sync_with_stdio(false);

ll dp[101][301][101]={};

signed main(){
  ll n,we;cin>>n>>we;
  vector<ll> w(n),v(n);//相対値
  cin>>w[0]>>v[0];
  for(int i=1;i < n;i++)
  {
    cin>>w[i]>>v[i];
    w[i]-=w[0];
  }

  rep(j,301)dp[0][j][1]=v[0];

  for(int i=1;i < n;i++)
  {
    for(int j=0;j < 1+n*3;j++)
    {
      for(int k=0;k < n+1;k++)
      {

        if(k>0 && j>=w[i]) dp[i][j][k]=max(dp[i-1][j][k],dp[i-1][j-w[i]][k-1]+v[i]);
        else dp[i][j][k]=dp[i-1][j][k];

        //if(i==3)cout<<j<<":"<<k<<":"<<dp[i][j][k]<<endl;
        
      }
    }
  }
  ll ans=0;
  for(int k=1;k < n+1;k++)
  {
    if(we-k*w[0]>=0){
      if(we-k*w[0]>3*k)ans=max(ans,dp[n-1][3*k][k]);
      else ans=max(ans,dp[n-1][we-k*w[0]][k]);
    }
  }

  cout<<ans<<endl;
}

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

using namespace std;

using ll=long long;
const int INF = 1e9+5;

void max_self(ll &a, ll b){
    a=max(a,b);
}

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

    int n,w;
    cin>>n>>w;
    vector<ll>dp(w+1);
    // for(int i=0; i<n; i++)cin>>n;
    for(int i=0; i<n; i++){
        int wei, val;
        cin>>wei>>val;
        for(int curr=w; curr-wei>=0; curr--){
            max_self(dp[curr],dp[curr-wei]+(ll)val);
        }
    }
    cout<<dp[w]<<endl;

    return 0;
}

Measured memory_bytes: 3908
#include<iostream>
#include<string>
#include<algorithm>	
#include<cmath>
#include <vector>
using namespace std;
int test[51][51], W[51], B[51], R[51];
int main() {
	long long n, a, sum = 0, ans = 10000000; char w; cin >> n >> a;
	for (int h = 0; h < n; h++) {
		for (int i = 0; i < a; i++) {
			cin >> w; test[h][i] = w;
			if (test[h][i] != 'W')W[h]++;
			if (test[h][i] != 'B')B[h]++;
			if (test[h][i] != 'R')R[h]++;
		}
	}
	for (int h = 1; h < n - 1; h++) {
		for (int i = h; i < n - 1; i++) {
			for (int j = 0; j < h; j++) {
				sum += W[j];
			}
			for (int j = h; j <= i; j++) {
				sum += B[j];
			}
			for (int j = i + 1; j < n; j++) {
				sum += R[j];
			}
			ans = min(ans, sum);
			sum = 0;
		}
	}
	cout << ans << endl;
	cin >> n;
}


Measured memory_bytes: 3104
#include <bits/stdc++.h>
using namespace std;
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; }
using ll = long long;
using P = pair<int, int>;
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; }

int k;
string s;

int main() {
    cin >> k >> s;
    int slen = s.length();
    if(slen <= k) {
        cout << s << endl;
    }else {
        string ans = s.substr(0, k);
        cout << ans << "..." << endl;
    }
}

Measured memory_bytes: 3644
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<string>
#include<algorithm>
using namespace std;
const int MaxN = 1e5;

char s[15];

int main()
{
	int n;
	char lj;
	long long ans,m,a,r,c,h;
	while(~scanf("%d",&n))
	{
		m = 0;a = 0;r = 0;c = 0;h = 0;
		for(int i = 1;i <= n;i++)
		{
			scanf("%c",&lj);
			scanf("%s",s);
			if(s[0]=='M') m++;
			else if(s[0]=='A') a++;
			else if(s[0]=='R') r++;
			else if(s[0]=='C') c++;
			else if(s[0]=='H') h++;
		}
		ans = m*a*r+m*a*c+m*a*h+m*r*c+m*r*h+m*c*h+a*c*h+a*r*c+a*r*h+r*c*h;
		printf("%lld\n",ans);
	}
	return 0;
}

Measured memory_bytes: 128
#include<iostream>
#include<cstdio>
#include<cstring>
#include <cstdlib>  
#include <math.h>
#include <cmath>
#include<cctype>
#include<string>
#include<set>
#include<iomanip>
#include <map>
#include<algorithm>
#include <functional>
#include<vector>
#include<climits>
#include<stack>
#include<queue>
#include<bitset>
#include <deque>
#include <climits>
#include <typeinfo>
#include <utility> 
using namespace std;
using ll = long long;
template<typename T>using min_priority_queue = priority_queue<T, vector<T>, greater<T>>;
const ll inf = 1145141919810364364LL;
#define all(x) (x).begin(),(x).end()
#define puts(x) cout << x << endl
#define rep(i,m,n) for(ll i = m;i < n;++i)
#define pb push_back
#define fore(i,a) for(auto &i:a)
#define rrep(i,m,n) for(ll i = m;i >= n;--i)

ll N;
vector<ll>sum;
vector<ll>bunpu;
int check(ll K,ll cnt){
	ll S;
	if(cnt < bunpu.back()){
		ll idx = lower_bound(all(bunpu), cnt) - bunpu.begin();
		S = cnt * (N - idx + 1LL) + sum[idx];
	}
	else S = N;
	return S >= cnt * K;
}

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

	cin >> N;
	sum.resize(N+2);
	bunpu.resize(N+1);
	for (int i = 0; i < N; i++) {
		int A;
		cin >> A;
		bunpu[A]++;
	}
	sort(all(bunpu));
	for (int i = 0; i <= N; i++)sum[i + 1] = bunpu[i] + sum[i];

	for (int K = 1; K <= N; K++) {
		int ok = 0, ng = N+1;
		while (ng - ok > 1) {
			int mid = (ng + ok) / 2;
			if (check(K,mid))ok = mid;
			else ng = mid;
		}
		puts(ok);
	}



	return 0;
}

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

using namespace std;

void debug_out() { cerr << endl; }
template <typename Head, typename... Tail>
void debug_out(Head H, Tail... T) {
  cerr << " " << to_string(H);
  debug_out(T...);
}
#ifdef LOCAL
#define debug(...) cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)
#else
#define debug(...) 42
#endif

#define rep(i,n) for(int i=0; i<(int)(n); i++)
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; }

using ll = long long;
using P = pair<ll, ll>;

//constexpr ll mod = 998244353;
constexpr ll mod = 1e9+7;
const double PI = acos(-1.0);
mt19937_64 engine(chrono::steady_clock::now().time_since_epoch().count());

signed main() {
  ios_base::sync_with_stdio(false);
  cin.tie(nullptr);

  ll n, k; cin >> n >> k;
  vector<ll> a(n), f(n);
  rep(i, n) cin >> a[i];
  rep(i, n) cin >> f[i];
  
  sort(f.rbegin(), f.rend());
  sort(a.begin(), a.end());

  ll ng = -1;
  ll ok = 1e12;

  while(ng + 1 < ok) {
    ll med = (ok+ng)/2;
    debug(med);
    ll now = k;

    rep(i, n) {
      if (a[i]*f[i] > med) {
        ll b = med/f[i];
        now -= (a[i]-b);
      }
    }
    if (now < 0) {
      ng = med;
    } else {
      ok = med;
    }
  }
  cout << ok << endl;
}

Measured memory_bytes: 3456
N,M=map(int,input().split())
#SC=[s,c for input().split() in range(M)]
SC=[list(input().split()) for i in range(M)]
'''
SC=[]
for i in range(M):
  SC.append((input().split()))
'''
def check(x):
  x=str(x)
  if len(x)!=N:
    return False
  for s,c in SC:
    if x[int(s)-1]!=c:
      return False
  return True
for i in range(1000):
  if check(i):
    print(i)
    exit()
print(-1)

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

using namespace std;

#define all(v)				((v).begin()), ((v).end())
#define allr(v)				((v).rbegin()), ((v).rend())
#define sz(v)				((int)((v).size()))
#define rep(i, v)		for(int i=0;i<sz(v);++i)
#define lp(i, n)		for(int i=0;i<(int)(n);++i)
#define lpi(i, j, n)	for(int i=(j);i<(int)(n);++i)
#define lpd(i, j, n)	for(int i=(j);i>=(int)(n);--i)
#define ll long long
#define pb					push_back
#define fIO ios_base::sync_with_stdio(0);cin.tie(0);

const ll inf = 1e8;
const double pi = 3.1415926535897;


const double EPS = (1e-7);
int dcmp(double x, double y) {	return fabs(x-y) <= EPS ? 0 : x < y ? -1 : 1;	}


typedef vector<int>                vi;
typedef vector<pair<int,int>>      vii;
typedef vector<ll>                 vll;
typedef vector<double>             vd;
typedef vector< vi >               vvi;
typedef vector< vd >               vvd;
typedef vector<string>             vs;

/**
    * PLEASEEE READDD PROBLEEEM CARFULLY ****
    * Always check for OVERFLOW ll vs int
    * Always check for array bounds
    * Check for function return
    * READ OUTPUT SECTION AGAIN!!!
**/


const int N = 1e5 + 5;

vi adj[N];
int dp[N];
int n, m;

int sol(int idx) {
    int & ret = dp[idx];

    if(ret != -1) return ret;

    ret = 0;

    for(auto ch : adj[idx]) {
        ret = max(ret, sol(ch) + 1);
    }

    return ret;
}

int main(){
    fIO

    cin >> n >> m;

    memset(dp, -1, sizeof(dp));

    int x, y;
    for(int i = 0; i < m; i++) {
        cin >> x >> y;

        x--; y--;

        adj[x].pb(y);
    }

    int maxi = 0;
    for(int i = 0; i < n; i++) {
        maxi = max(maxi, sol(i));
    }

    cout << maxi;


}









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

class Main {

    public static void main(String[] args) {
        MyScanner sc = new MyScanner();
        
        String a = sc.next();
        String b = sc.next();

        int cnt=0;

        for(int i=0; i<3; i++){
            if(a.charAt(i)==b.charAt(i)){
                cnt++;
            }
        }

        System.out.println(cnt);

    }

    static class MyScanner {
        BufferedReader reader = new BufferedReader(new InputStreamReader(System.in), 1 << 15);
        StringTokenizer tokenizer;
    
        String next() {
            try {
                while (tokenizer == null || !tokenizer.hasMoreTokens()) {
                    tokenizer = new StringTokenizer(reader.readLine());
                }
            } catch (IOException ignored) {
            }
            return tokenizer.nextToken();
        }
    
        int nextInt() {
            return Integer.parseInt(next());
        }
    
        long nextLong() {
            return Long.parseLong(next());
        }
    }
}

Measured memory_bytes: 21204
#include<bits/stdc++.h>
using namespace std;
///Welcome to Nasif's Code
#define bug printf("bug\n");
#define bug2(var) cout<<#var<<" "<<var<<endl;
#define co(q) cout<<q<<endl;
#define all(q) (q).begin(),(q).end()
typedef long long int ll;
typedef unsigned long long int ull;
const int MOD = (int)1e9+7;
const int MAX = 1e6;
#define pi acos(-1)
#define inf 1000000000000000LL
#define FastRead    ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
int main()
{
    FastRead
    //freopen("output.txt", "w", stdout);
    int a,b,c;
    cin>>a>>b>>c;
    if(a==b)
        cout<<c<<endl;
    else if(a==c)
        cout<<b<<endl;
    else if(b==c)
    cout<<a<<endl;

    return 0;
}


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

int main()
{
        int h, w;

        while(scanf("%d %d\n", &h, &w)){

                if( h==0 && w==0 )break;

                for(int i=0; i<h; i++){
                        if(i==0 || i==h-1){
                                for(int j=0; j<w; j++){
                                        cout << "#";
                                }
                        }else{
                                for(int j=0; j<w; j++){
                                        if(j==0 || j== w-1)  cout << "#";
                                        else cout << ".";
                                }
                        }
                        cout << endl;
                }
                cout << endl;
        }
        return 0;
}

Measured memory_bytes: 1204
#pragma region
#include <algorithm>
#include <cstring>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <stack>
#include <string>
#include <vector>
typedef long long ll;
#define rep(i, a, n) for (long long i = a; i <= n; ++i)
#define per(i, a, n) for (long long i = n; i >= a; --i)
#define IO ios::sync_with_stdio(false), cin.tie(0), cout.tie(0)
using namespace std;
/*
 *                                                     __----~~~~~~~~~~~------___
 *                                    .  .   ~~//====......          __--~ ~~
 *                    -.            \_|//     |||\\  ~~~~~~::::... /~
 *                 ___-==_       _-~o~  \/    |||  \\            _/~~-
 *         __---~~~.==~||\=_    -_--~/_-~|-   |\\   \\        _/~
 *     _-~~     .=~    |  \\-_    '-~7  /-   /  ||    \      /
 *   .~       .~       |   \\ -_    /  /-   /   ||      \   /
 *  /  ____  /         |     \\ ~-_/  /|- _/   .||       \ /
 *  |~~    ~~|--~~~~--_ \     ~==-/   | \~--===~~        .\
 *           '         ~-|      /|    |-~\~~       __--~~
 *                       |-~~-_/ |    |   ~\_   _-~            /\
 *                            /  \     \__   \/~                \__
 *                        _--~ _/ | .-~~____--~-/                  ~~==.
 *                       ((->/~   '.|||' -_|    ~~-/ ,              . _||
 *                                  -_     ~\      ~~---l__i__i__i--~~_/
 *                                  _-~-__   ~)  \--______________--~~
 *                                //.-~~~-~_--~- |-------~~~~~~~~
 *                                       //.-~~~--\
 *                       ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
 */
#pragma endregion
const int maxn = 105;
const ll mod = 1e9 + 7;
ll a[maxn], b[int(1e5 + 5)], n, k;
ll dp[int(1e5 + 5)];
int main() {
    IO;
    cin >> n >> k;
    rep(i, 1, n) cin >> a[i];
    dp[0] = 1;
    rep(i, 1, n) {
        memset(b, 0, sizeof(b));
        per(j, 0, k) {
            int l = j + 1, r = min(k, j + a[i]);
            if (l <= r) {
                (b[l] += dp[j]) %= mod;
                (b[r + 1] += mod - dp[j]) %= mod;
            }
        }
        ll now = 0;
        rep(i, 0, k) {
            (now += b[i]) %= mod;
            (dp[i] += now) %= mod;
        }
    }
    cout << dp[k] << endl;
}

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

using namespace std;

class Solution {
public:
	void solve() {
		int n, m;
		cin >> n >> m;
		vector<int> a(n, 0);
		for (int i = 0; i < n; i++) cin >> a[i];
		int s = accumulate(a.begin(), a.end(), 0);
		int t = (s + (4 * m - 1)) / (4 * m);
		for (int i = 0; i < n; i++) {
			if (a[i] >= t) m--;
		}
		if (m <= 0)
			cout << "Yes\n";
		else
			cout << "No\n";
		return;
	};
};

int main() {
	ios_base::sync_with_stdio(false);
	cin.tie(nullptr);
	Solution solution;
	solution.solve();
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define int long long
#undef int
#define mk make_pair
#define pb push_back
typedef pair<int, int> pii;
const int mod = 1000000007;
const int INF = 1000000009;

int N, K, a[2020], b[2020];
vector<int> G[5020];

signed main()
{
    cin >> N >> K;
    for(int i = 0; i < N - 1; i++){
        cin >> a[i] >> b[i];
        a[i]--;
        b[i]--;
        G[a[i]].pb(b[i]);
        G[b[i]].pb(a[i]);
    }
    int ans = 0;
    if(K % 2){
        for(int i = 0; i < N - 1; i++){
            int res = 0;
            queue<pii > que;
            que.push(mk(a[i], 0));
            que.push(mk(b[i], 0));
            bool used[2020] = {false};
            used[a[i]] = true;
            used[b[i]] = true;
            while(que.size()){
                int cur = que.front().first;
                int dis = que.front().second;
                que.pop();
                res++;
                if(dis >= K / 2)continue;
                for(int j = 0; j < (int)G[cur].size(); j++){
                    int to = G[cur][j];
                    if(!used[to]){
                        used[to] = true;
                        que.push(mk(to, dis + 1));
                    }
                }
            }
            ans = max(ans, res);
        }
    }
    else{
        for(int i = 0; i < N; i++){
            int res = 0;
            queue<pii > que;
            que.push(mk(i, 0));
            bool used[2020] = {false};
            used[i] = true;
            while(que.size()){
                int cur = que.front().first;
                int dis = que.front().second;
                que.pop();
                res++;
                if(dis >= K / 2)continue;
                for(int j = 0; j < (int)G[cur].size(); j++){
                    int to = G[cur][j];
                    if(!used[to]){
                        used[to] = true;
                        que.push(mk(to, dis + 1));
                    }
                }
            }
            ans = max(ans, res);
        }
    }
    cout << N - ans << endl;

    return 0;
}

/*



*/


Measured memory_bytes: 512
use num::Integer;
use proconio::input;

fn main() {
    input!(n: u64);

    let m = 2 * n;

    let ans = divisors(m)
        .iter()
        .filter_map(|&a| {
            let a = a as i64;
            let b = m as i64 / a;

            let mut ext = a.extended_gcd(&b);
            if ext.gcd != 1 {
                return None;
            }
            if ext.x >= 0 {
                let dec = ext.x / b + 1;
                ext.x -= dec * b;
                ext.y += dec * a;
            }
            Some(-ext.x * a)
        })
        .min()
        .unwrap();

    println!("{}", ans);
}

fn divisors(n: u64) -> Vec<u64> {
    let mut ret = Vec::new();
    for x in 1.. {
        if x * x > n {
            break;
        }
        if n % x == 0 {
            ret.push(x);
            if x * x < n {
                ret.push(n / x)
            }
        }
    }
    ret
}


Measured memory_bytes: 2272
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<int,int>;
using node = pair<string,ll>;
const ll inf = numeric_limits<ll>::max()/3;
const ll mod = 1e9+7;

int main(void) {
  map<ll,int> rest;
  vector< ll > a;
  int n;
  cin >> n;
  for(int i = 0;i < n;++i) {
    ll tmp;
    cin >> tmp;
    a.push_back(tmp);
    rest[tmp]++;
  }
  sort(a.begin(),a.end(),greater<ll>());
  int res = 0;
  for(int i = 0;i < n;++i) {
    if(rest[a[i]] == 0)
      continue;

    --rest[a[i]];
    bool found = false;
    for(int j = 32;j > 0;--j){
      ll target = 1LL << j;
      target -= a[i];
      if(rest.find(target) != rest.end()
         && rest[target] > 0) {
        found = true;
        rest[target]--;
        ++res;
        break;
      }
    }
    if(!found) {
      ++rest[a[i]];
    }
  }
  cout << res << endl;
}


Measured memory_bytes: 14320
#include <stdio.h>

int main(void) {
	int n, m;
	int a[100][100] = { 0 };
	int b[100] = { 0 };
	int c[100] = { 0 };
	int i, j;

	scanf("%d %d", &n, &m);

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

	for (i = 0; i < n; i++) {
		for (j = 0; j < m; j++) {
			c[i] += b[j] * a[i][j];
		}
	}

	for (i = 0; i < n; i++) {
		printf("%d\n", c[i]);
	}

	return 0;
}


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

#define ll long long
#define int long long
#define ff first
#define ss second
#define pb push_back
#define mp make_pair
#define pii pair<int, int>
#define vi vector<int>
#define pqb priority_queue<int>
#define pqs priority_queue<int, vi, greater<int>>
#define setbits(x) __builtin_popcountll(x)
#define zrobits(x) __builtin_ctzll(x)
#define mod 1000000007
#define inf (int)(1e18)
#define ps(x, y) fixed << setprecision(y) << x
#define w(x)  \
    int x;    \
    cin >> x; \
    while (x--)
#define rep(i, begin, end) for (__typeof(end) i = (begin) - ((begin) > (end)); i != (end) - ((begin) > (end)); i += 1 - 2 * ((begin) > (end)))
#define all(p) p.begin(), p.end()
#define ub(a, b) upper_bound(all(a), b)
#define lb(a, b) lower_bound(all(a), b)
#define PI 3.14159265
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

void run()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
}
const int N = (int)(3e5);
vi parent(N, -1);
vi siz(N, 0);
int find_set(int v)
{
    if (v == parent[v])
        return v;
    return parent[v] = find_set(parent[v]);
}
void make_set(int v)
{
    parent[v] = v;
    siz[v] = 1;
}

void union_sets(int a, int b)
{
    a = find_set(a);
    b = find_set(b);
    if (a != b)
    {
        if (siz[a] < siz[b])
            swap(a, b);
        parent[b] = a;
        siz[a] += siz[b];
    }
}
void solution()
{
    int n, m;
    cin >> n >> m;
    for (int i = 1; i <= n; i++)
    {
        make_set(i);
    }
    int ans = 1;
    for (int i = 0; i < m; i++)
    {
        int u, v;
        cin >> u >> v;
        union_sets(u, v);
        ans = max({ans, siz[find_set(u)], siz[find_set(v)]});
    }
    cout << ans << endl;
    return;
}
int32_t main()
{
    run();
    solution();
    return 0;
}

Measured memory_bytes: 7872
// abc129_b
#include <bits/stdc++.h>
#ifdef LOCAL
#include "../cxx-prettyprint/prettyprint.hpp"
#endif
using namespace std;

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

#define REP(i, n) for (int (i) = 0 ; (i) < (int)(n) ; ++(i))
#define REPN(i, m, n) for (int (i) = m ; (i) < (int)(n) ; ++(i))
#define REP_REV(i, n) for (int (i) = (int)(n) - 1 ; (i) >= 0 ; --(i))
#define REPN_REV(i, m, n) for (int (i) = (int)(n) - 1 ; (i) >= m ; --(i))
#define ALL(x) x.begin(), x.end()

#define INF ((1 << 29)-1)
#define MOD (1000000007)

#define print2D(h, w, arr) REP(i, h) { REP(j, w) cout << arr[i][j] << " "; cout << endl; }
template<class T> void print(const T& x){cout << x << endl;}
template<class T, class... A> void print(const T& first, const A&... rest) { cout << first << " "; print(rest...); }
struct PreMain {PreMain(){cin.tie(0);ios::sync_with_stdio(false);cout<<fixed<<setprecision(20);}} premain;

int main() {
#ifdef LOCAL
    ifstream in("../arg.txt");
    cin.rdbuf(in.rdbuf());
#endif

    int N;
    cin >> N;

    vector<int> W(N);
    REP(i, N) cin >> W[i];

    int ans = INF;
    REP(i, N) {

        int S1=0;
        REP(j, i) S1 += W[j];

        int S2=0;
        REPN(j, i, N) S2 += W[j];

        ans = min(ans, abs(S1-S2));
    }

    print(ans);




    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <algorithm>
#include <functional>
#include <vector>
#include <stack>
#include <queue>
#include <deque>
#include <set>
#include <map>
#include <cstdio>
#include <cmath>
#include <tuple>
#include <iomanip>
#include <numeric>
#include <unordered_map>
#include <sstream>   
#include<limits.h>
#include<float.h>
#include<list>
#include <array>
#include <complex>
#include<stdio.h>
#include<string.h>

using namespace std;
#define int  long long
 
#define I32_MAX 2147483647
#define I64_MAX 9223372036854775807LL
#define I64_MAX2 1223372036854775807LL
#define INF I64_MAX2
#define MOD 1000000007
#define MEM_SIZE 10000
#define DEBUG_OUT true
#define ALL(x) (x).begin(),(x).end()
// int DP[MEM_SIZE][MEM_SIZE] = {0};
// int GMEM[MEM_SIZE][MEM_SIZE] = {0};
template<typename T> void DEBUG(T e){if(DEBUG_OUT == false)return;std::cout << e << std::endl;}
template<typename T> void DEBUG(const std::vector<T>& v){if(DEBUG_OUT == false)return;for(const auto& e : v){ std::cout << e << " "; } std::cout << std::endl;}
template<typename T> void DEBUG(const std::vector<std::vector<T> >& vv){if(DEBUG_OUT == false)return;for(const auto& v : vv){ DEBUG(v); } }
template<class T,class X> void DEBUG(X d, T e){if(DEBUG_OUT == false)return;std::cout <<d<<" ";DEBUG(e);};
template <class T> void corner(bool flg, T hoge) {if (flg) {cout << hoge << endl; exit(0);}}
template< typename T1, typename T2 > inline bool chmax(T1 &a, T2 b) { return a < b && (a = b, true); }
template< typename T1, typename T2 > inline bool chmin(T1 &a, T2 b) { return a > b && (a = b, true); }
template< typename T > using matrix = vector< vector< T > >;

//FUNCTION  


void solve(void)
{
  int X,Y,A,B,C;
  cin>>X>>Y>>A>>B>>C;
  vector<int>VA(A),VB(B),VC(C);

  priority_queue<int> PC;
  priority_queue<int, vector<int>, greater<int> > PA,PB;
  for (int i = 0; i < A; i++)
  {
    int X;
    cin>>X;
    PA.push(X);
  }
  for (int i = 0; i < B; i++)
  {
    int X;
    cin>>X;
    PB.push(X);
  }
  for (int i = 0; i < C; i++)
  {
    int X;
    cin>>X;
    PC.push(X);
  }
  while(PB.size() != Y)
  {
    PB.pop();
  }
  while(PA.size() != X)
  {
    PA.pop();
  }
  priority_queue<int> PQ;
  while(!PB.empty())
  {
    PQ.push(PB.top());PB.pop();
  }
    while(!PA.empty())
  {
    PQ.push(PA.top());PA.pop();
  }
      while(!PC.empty())
  {
    PQ.push(PC.top());PC.pop();
  }
  int ANS = 0;
  for (int i = 0; i < X+Y; i++)
  {
    ANS += PQ.top();
    PQ.pop();
  }
  
  cout<<ANS<<endl;
  return;
}

int32_t main(int32_t argc, const char *argv[])
{
  std::ios::sync_with_stdio(false);
  std::cin.tie(0);

  std::cout << std::fixed;
  std::cout << std::setprecision(9);
  solve();

  return 0;
}


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

//typedef
//------------------------------------------
typedef long long LL;
typedef vector<LL> VL;
typedef vector<VL> VVL;
typedef vector<string> VS;
typedef pair<LL, LL> PLL;

//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(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort((c).begin(),(c).end())

//constant
//--------------------------------------------
const double EPS = 1e-10;
const double PI  = acos(-1.0);
const int MOD = 1000000007;

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

//main code

int main(int argc, char const* argv[])
{
    int n;
    cin >> n;
    VL a(n*3);
    for (int i = 0; i < n*3; i++) {
        cin >> a[i];
    }
    SORT(a);
    LL ans = 0;
    for (int i = 0; i < n; i++) {
        ans += a[3*n-2*(i+1)];
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 2560
#include <bits/stdc++.h>
using namespace std;
int main(){
	int n;int l;
	cin>>n>>l;
	vector<int> fla;
	for(int i=0;i<n;i++){
		int t;
		cin>>t;
		fla.push_back(l+i+1-1);
	}
	int tsum=0;
	tsum = accumulate(fla.begin(),fla.end(),tsum);
	int opt =0x3f3f3f3f;
	int optind=-1;
	int optsum =0;
	for(int i=0;i<n;i++){
		int cursum=0;
		for(int j=0;j<n;j++){
			if(j==i)continue;
			cursum+=fla[j];
		}
		int dif = abs(cursum-tsum);
		if(dif<opt){
			opt = dif;
			optsum = cursum;
		}
	}
	cout<<optsum<<endl;
	return 0;
}

Measured memory_bytes: 256
import sys
input = sys.stdin.readline

a, b = input().split()
if 'H' in a:
    if 'H' in b:
        ans = 'H'
    else:
        ans = 'D'
else:
    if 'H' in b:
        ans = 'D'
    else:
        ans = 'H'
print(ans)

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

int main() {
  int A, B, C;
  cin >> A >> B >> C;

  string ans = "No";

  if ( (A == B && A != C)
    || (B == C && B != A)
    || (C == A && C != B) )
  {
    ans = "Yes";
  }

  cout << ans << endl;
}


Measured memory_bytes: 256
// clang-format off
#include <bits/stdc++.h>

#define mp make_pair
#define fst first
#define snd second
#define forn(i,n) for (int i = 0; i < int(n); i++)
#define forn1(i,n) for (int i = 1; i <= int(n); i++)
#define popcnt __builtin_popcount
#define ffs __builtin_ffs
#define ctz __builtin_ctz
#define clz __builtin_clz
#define all(a) (a).begin(), (a).end()
 
using namespace std;

using uint = unsigned int;
using ll = long long;
using ull = unsigned long long;
using pii = pair<int,int>;
using pli = pair<ll,int>;
using pil = pair<int,ll>;
using pll = pair<ll,ll>;
template <typename T> using vec = vector<T>;
using vi = vec<int>;
using vl = vec<ll>;
template <typename T> using que = queue<T>;
template <typename T> using deq = deque<T>;

template <typename T> T id(T b) {return b;};
template <typename T> void chmax(T &x, T y) {if (x < y) x = y;}
template <typename T> void chmin(T &x, T y) {if (x > y) x = y;}
template <typename S, typename K> bool contains(S &s, K k) { return s.find(k) != s.end(); }
void fastio() { ios_base::sync_with_stdio(false); cin.tie(nullptr); }
constexpr ll TEN(int n) { if (n == 0) return 1LL; else return 10LL*TEN(n-1); }
// clang-format on

int main() {
    fastio();

    char x, y;
    cin >> x >> y;
    if (x > y) {
        cout << ">\n";
    } else if (x < y) {
        cout << "<\n";
    } else {
        cout << "=\n";
    }

    return 0;
}

Measured memory_bytes: 256
package main

import ("fmt"
     "strconv"  )
func main(){
  dt:=map[string][]string{
  }
var n int
  fmt.Scan(&n)
  c:=0
  
  s :=[]string{}
  for i:=1;i<=n;i++{
    a:=strconv.Itoa(i)
    s=append(s,a)
    t:=string(a[0])
    b:=string(a[len(a)-1])
    k:=fmt.Sprintf("%v-%v",t,b)
    _,ok := dt[k]
    if ok {
      dt[k]=append(dt[k],a)
    } else {
      dt[k]=[]string{
        a,
      }
  }
  }
  for _,a :=range s {
    t:=string(a[0])
    b:=string(a[len(a)-1])
    if t !="0" && b !="0"{
    k:=fmt.Sprintf("%v-%v",b,t)
    c=c+len(dt[k])
    }
      }
 
fmt.Println(c)

}

Measured memory_bytes: 20224
#include<iostream>
#include<vector>
#include<algorithm>
#include<map>
#include<queue>
#include<cmath>
#include<stack>

typedef long long ll;

using namespace std;
int main(){
    int N, M;
    cin >> N >> M;
    string S;
    cin >> S;
    int now=N;
    stack<int> ans;

    while(true){
        int next = now-M;
        if(next < 0){
            ans.push(now-0);
            break;
        }
        while(next < now && S[next] == '1'){
            next++;
        }
        if(next == now){
            cout << "-1" << endl;
            return 0;
        }
        ans.push(now-next);
        now = next;
        if(now == 0){
            break;
        }
    }
    while(!ans.empty()){
        cout << ans.top() << " ";
        ans.pop();
    }
    cout << endl;
    return 0;
}


Measured memory_bytes: 868
#include <iostream>
#include <vector>
#include <utility>
#include <algorithm>
#include <cmath>
#include <queue>
#include <string>
#include <set>
#include <map>
#include <cassert>
#include <fstream>

using namespace std;

int main() {
    
    
    string s;
    cin >> s;
    
    int ret1 = 0;
    int ret2 = 0;
    for (int i = 0; i < s.size(); ++i)
    {
        if (i % 2)
        {
            if (s[i] != '1')
            {
                ret1++;
            }
        }
        else
        {
            if (s[i] != '0')
            {
                ret1++;
            }
        }
    }
    
    for (int i = 0; i < s.size(); ++i)
    {
        if (i % 2)
        {
            if (s[i] != '0')
            {
                ret2++;
            }
        }
        else
        {
            if (s[i] != '1')
            {
                ret2++;
            }
        }
    }
    
    int ret = min(ret1, ret2);
    
    cout << ret << endl;
    
    return 0;
}

Measured memory_bytes: 512
import sys
sys.setrecursionlimit(10**7)

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

michi = [[] for i in range(N)]
for i in range(M):
  tempa, tempb = map(int,input().split())
  michi[tempa-1].append(tempb-1)
  michi[tempb-1].append(tempa-1)
#print(michi)
  
colors = [0 for i in range(N)]

def dfs(v,color):
  colors[v] = color
  for to in michi[v]:
    if colors[to] == color:
      return False
    if colors[to] == 0 and not dfs(to,-color):
      return False
  return True

if dfs(0,1):
  a = colors.count(1)
  b = colors.count(-1)
  #print(colors)
  print(a*b-M)
else:
  print(N*(N-1)//2 - M)

Measured memory_bytes: 31288
#include <stdio.h>
#include <malloc.h>
#include <assert.h>
#include <ctype.h>
#include <memory.h>

// just implement simple stack
typedef struct StkDat {
    int key;
    struct StkDat *next;
} StkDat;
typedef struct Stack {
    size_t len;
    StkDat *top;
} Stack;
#define stk_init(s) ((s) ? ((s)->len = 0, (s)->top = NULL) : 0)
int stk_pop(Stack *stk_hdr) {
    assert(stk_hdr->len != 0);
    stk_hdr->len--;
    int key = stk_hdr->top->key;
    StkDat *old_head = stk_hdr->top;
    stk_hdr->top = stk_hdr->top->next;
    free(old_head);
    return key;
}
void stk_push(Stack *stk_hdr, const int key) {
    StkDat *new_dat = (StkDat *)malloc(sizeof(StkDat));
    new_dat->key = key;
    new_dat->next = stk_hdr->top;
    stk_hdr->top = new_dat;
    stk_hdr->len++;
}
// <- stack

// just implement simple lexing
#define TOKEN_INT   1
#define TOKEN_OP    2
#define TOKEN_OTHER 3
#define TOKEN_LAST  4

typedef struct Token {
    int kind;
    const char *start;
    const char *end;
    union {
        int val;
        const char *name;
    };
} Token;

Token token;
const char *stream;

void next_token() {
    token.start = stream;
    if(isdigit(*stream)) {
        int val = 0;
        while(isdigit(*stream)) {
            val *= 10;
            val += *stream++ - '0';
        }
        token.kind = TOKEN_INT;
        token.val = val;
    } else {
        token.kind = TOKEN_OTHER;
        switch(*stream) {
        case '+':
        case '-':
        case '*':
            token.kind = TOKEN_OP;
            token.name = stream;
            break;
        case '\0':
            token.kind = TOKEN_LAST;
            break;
        }
        stream++;
    }
    token.end = stream;
}
// <- lexing

// solve
void lexing(const char *source) {
    stream = source;
    next_token();
    Stack stk;
    stk_init(&stk);
    // first char should be number
    stk_push(&stk, token.val);
    // while char is not '\0'
    while(token.kind != TOKEN_LAST) {
        next_token();
        // if number    push stack
        // if operator  calc then push stack
        if(token.kind == TOKEN_INT) stk_push(&stk, token.val);
        else if(token.kind == TOKEN_OP) {
            int y = stk_pop(&stk);
            int x = stk_pop(&stk); 
            switch(*token.name) {
            case '+':
                stk_push(&stk, x + y);
                break;
            case '-':
                stk_push(&stk, x - y);
                break;
            case '*':
                stk_push(&stk, x * y);
                break;
            default:
                break;
            }
        }
    }
    printf("%d\n", stk_pop(&stk));
}

int main() {
    char chr[512];
    scanf("%[^\n]", chr);
    lexing(chr);
    return 0;
}



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

using namespace std;

const int N = 2e5+5;

const int mod = 998244353;

int n;
int m;
int k;

long long inv[N];
long long fac[N];
long long finv[N];

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

long long nCr(long long n , long long r){
    if(n < r)
        return 0;
    if(n < 0 || r < 0)
        return 0;
    return fac[n] * (finv[r] * finv[n - r] % mod) %mod;
}

int fastP(int b, int e){
    if(!e)
        return 1;
    if(e & 1)
        return b * 1ll * fastP(b * 1ll * b % mod, e >> 1) % mod;
    return fastP(b * 1ll * b % mod, e >> 1) % mod;
}

void mul(long long & a , long long b){
    a *= b;
    a %= mod;
}

int main(){
    scanf("%d%d%d" , &n , &m , &k);
    cominit();
    long long ways = 0;
    for(int i = 0; i <= k; i++){
        long long sofar = 1;
        mul(sofar , m);
        mul(sofar , fastP(m - 1 , n - 1 - i));
        mul(sofar , nCr(n - 1 , i));
        ways += sofar;
        ways %= mod;
    }
    printf("%lld\n" , ways);
}


Measured memory_bytes: 8508