akhauriyash/Code-Regression huggingface dataset:
N,M=gets.chomp.split(" ").map(&:to_i)
A=[]
N.times do
    a=gets.chomp
    A.push(a)
end
B=[]
M.times do
    b=gets.chomp
    B.push(b)
end
(0..(N-M)).each do |x|
    (0..(N-M)).each do |y|
        judge=true
        (0..(M-1)).each do |m|
            a=A[m+x][y,M]
            b=B[m]
            if a!=b
                judge=false
                break
            end
        end
        if judge
            puts "Yes"
            exit
        end
    end
end
puts "No"


Measured memory_bytes: 14284
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define REP(i,a,b) for(int i=(a),_end_=(b);i<=_end_;i++)
#define DREP(i,a,b) for(int i=(a),_end_=(b);i>=_end_;i--)
#define EREP(i,u) for(int i=start[u];i;i=e[i].next)
#define fi first
#define se second
#define mkr(a,b) make_pair(a,b)
#define SZ(A) ((int)A.size())
template<class T>inline void chkmin(T &a,T b){ if(a>b)a=b;}
template<class T>inline void chkmax(T &a,T b){ if(a<b)a=b;}
inline void myassert(bool a,string s){ if(!a)cerr<<s<<endl,exit(0);}
inline int read()
{
	int s=0,f=1;char ch=getchar();
	while(!isdigit(ch) && ch!='-')ch=getchar();
	if(ch=='-')ch=getchar(),f=-1;
	while(isdigit(ch))s=s*10+ch-'0',ch=getchar();
	return ~f?s:-s;
}

const int maxp=5e5+20;

int n,D1,D2;

int num[920][920],tot;
vector<int>ed[maxp];
int vis[maxp];

inline void init()
{
	n=read();D1=read();D2=read();
	REP(i,0,2*n-1)REP(j,0,2*n-1)num[i][j]=++tot;
	
}

int ok[maxp],dis[maxp];

void dfs(int u)
{
	vis[u]=1;
	for(int v:ed[u])
	{
		if(vis[v])continue;
		dis[v]=dis[u]^1;
		dfs(v);
	}
}

	
inline void doing()
{
	REP(i,1,tot)ed[i].clear(),dis[i]=vis[i]=0,ok[i]=1;
	REP(dx,0,sqrt(D1))
	{
		int dy=sqrt(D1-dx*dx);
		if(dy*dy+dx*dx==D1)
		{
			REP(i,0,2*n-1)REP(j,0,2*n-1)
			{
				int now=num[i][j];
				if(i+dx<2*n && j+dy<2*n && num[i+dx][j+dy])ed[now].push_back(num[i+dx][j+dy]),ed[num[i+dx][j+dy]].push_back(now);
				if(i+dx<2*n && j-dy>=0 && num[i+dx][j-dy])ed[now].push_back(num[i+dx][j-dy]),ed[num[i+dx][j-dy]].push_back(now);
			}
		}
	}
	REP(i,1,tot)if(!vis[i])dfs(i);
	REP(i,1,tot)ok[i]&=!dis[i];

	REP(i,1,tot)ed[i].clear(),dis[i]=vis[i]=0;
	REP(dx,0,sqrt(D2))
	{
		int dy=sqrt(D2-dx*dx);
		if(dy*dy+dx*dx==D2)
		{
			REP(i,0,2*n-1)REP(j,0,2*n-1)
			{
				int now=num[i][j];
				if(i+dx<2*n && j+dy<2*n && num[i+dx][j+dy])ed[now].push_back(num[i+dx][j+dy]),ed[num[i+dx][j+dy]].push_back(now);
				if(i+dx<2*n && j-dy>=0 && num[i+dx][j-dy])ed[now].push_back(num[i+dx][j-dy]),ed[num[i+dx][j-dy]].push_back(now);
			}
		}
	}
	REP(i,1,tot)if(!vis[i])dfs(i);
	REP(i,1,tot)ok[i]&=!dis[i];
	int num=n*n;
	REP(i,1,tot)
	{
		if(ok[i] && num>0)
		{
			printf("%d %d\n",(i-1)/(2*n),(i-1)%(2*n));
			--num;
		}
	}
}

int main()
{
	init();
	doing();
	return 0;
}


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

#define pb push_back
#define S second
#define F first
#define sz size()
#define eps 0.000001
#define oo 2000000007
#define endl '\n'
#define bg begin()
#define nd end()
#define up upper_bound
#define lw lower_bound
#define debug(x) #x << " = " << x << "; "
typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<pii> vii;

const int MAX = 21;
int dp[MAX][(1<<MAX)];
bool mat[MAX][MAX];
int N, MOD = 1e9 + 7;

int f(int i, int mask){
	if(i == N) return 1;
	int &ans = dp[i][mask];
	if(ans != -1) return ans;
	ans = 0;
	for(int j = 0; j < N; j++){
		if(mat[i][j] && !(mask & (1<<j)))
			ans = (ans +  f(i + 1, mask | (1<<j))%MOD)%MOD;
	}
	return ans;
}

int main() {
	ios::sync_with_stdio(0);
	cin.tie(0);
	cin >> N;
	for(int i = 0; i < N; i++){
		for(int j = 0; j < N; j++){
			cin >> mat[i][j];
		}
	}
	memset(dp, -1, sizeof(dp));
	ll ans = f(0, 0);
	cout << ans << endl;
}

Measured memory_bytes: 172288
#include <bits/stdc++.h>
#define REP(i, n) for (int i = 0; i < n; i++)
#define REPR(i, n) for (int i = n; i >= 0; i--)
#define FOR(i, m, n) for (int i = m; i < n; i++)
#define ALL(v) v.begin(), v.end()
using namespace std;
typedef long long ll;
typedef long double ld;

template<class Abel> struct UnionFind {
  vector<int> par;
  vector<int> rank;
  vector<Abel> diff_weight;

  UnionFind(int n = 1, Abel SUM_UNITY = 0) {
    init(n, SUM_UNITY);
  }

  void init(int n = 1, Abel SUM_UNITY = 0) {
    par.resize(n); rank.resize(n); diff_weight.resize(n);
    for (int i = 0; i < n; ++i) par[i] = i, rank[i] = 0, diff_weight[i] = SUM_UNITY;
  }

  int root(int x) {
    if (par[x] == x) {
      return x;
    } else {
      int r = root(par[x]);
      diff_weight[x] += diff_weight[par[x]];
      return par[x] = r;
    }
  }

  Abel weight(int x) {
    root(x);
    return diff_weight[x];
  }

  bool issame(int x, int y) {
    return root(x) == root(y);
  }

  bool merge(int x, int y, Abel w) {
    w += weight(x); w -= weight(y);
    x = root(x); y = root(y);
    if (x == y) return false;
    if (rank[x] < rank[y]) swap(x, y), w = -w;
    if (rank[x] == rank[y]) ++rank[x];
    par[y] = x;
    diff_weight[y] = w;
    return true;
  }

  Abel diff(int x, int y) {
    return weight(y) - weight(x);
  }
};

int main()
{
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  int n,m;
  cin >> n >> m;
  UnionFind<int> tree(n);
  REP(i,m){
    int l,r,d;
    cin >> l >> r >> d;
    l--, r--;
    if(tree.issame(l,r)){
      int diff = tree.diff(l,r);
      if(diff!=d){
        cout << "No" << endl;
        return 0;
      }
    }else{
      tree.merge(l,r,d);
    }
  }
  cout << "Yes" << endl;
  return 0;
}


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

int main(){
	int n,r;
	int ans;
	cin>>n>>r;
	if(n>=10)ans=r;
	else{
		ans=r+100*(10-n);
	}
	cout<<ans<<endl;
	
	return 0;

}

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

using namespace std;

int main() {
    string eStr, oStr;
    cin >> oStr >> eStr;

    for (int i = 0; i < eStr.size(); ++i) {
        cout << oStr[i] << eStr[i];
    }
    if (oStr.size() != eStr.size()) {
        cout << oStr[oStr.size() - 1] << endl;
    } else {
        cout << endl;
    }
    return 0;
}


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

using namespace std;

const int mod = 1e9 + 7;
typedef long long int64;

int64 pow_mod(int64 x, int64 n, int64 mod)
{
  int64 ret = 1LL;
  while(n > 0) {
    if(n & 1) (ret *= x) %= mod;
    (x *= x) %= mod;
    n >>= 1;
  }
  return ret;
}

int main()
{
  string S;
  cin >> S;
  for(int i = 2; i < S.size(); i++) {
    set< int > kk = {S[i - 2], S[i - 1], S[i]};
    if(kk.size() <= 2) {
      cout << i - 1 << " " << i + 1 << endl;
      return (0);
    }
  }
  if(S.size() == 2 && S.front() == S.back()) {
    cout << 1 << " " << 2 << endl;
    return (0);
  }


  cout << -1 << " " << -1 << endl;

}

Measured memory_bytes: 512
#include <iostream>
#include <complex>
#include <cmath>
#include <vector>
#include <map>
using namespace std;

typedef complex<double> P;
const double PI = 3.14159265;
const double eps = 1e-7;

inline double dist(const P &p,const P &q) {
    double dx = (p-q).real(),dy = (p-q).imag();
    return sqrt(dx*dx+dy*dy);
}

double inner(const P &p,const P &q) {
    return (conj(p)*q).real();
}

double outer(const P &p,const P &q) {
    return (conj(p)*q).imag();
}

struct Line {
    P pos,dir;
    Line(const P &p,const P &q) : pos(p), dir(q) {;}
};

// rotate to right , radian
P rotate(const P &p,double degree) {
    return P(p.real()*cos(degree)+p.imag()*(-sin(degree)),
             p.real()*sin(degree)+p.imag()*cos(degree));
}

struct Circle {
    double r;
    P c;
    Circle(P c,double r) : c(c), r(r) {;}
};

// p in C?
inline bool inC(const Circle &c,const P &p) {
    return dist(c.c,p) < c.r + eps;
}

pair<P,P> findCenter(P &p1,P &p2) {
    P cp = p1+p2;
    cp /= 2;

//    cout<<"cp = "<<cp<<endl;
    P od = p2-cp;

//    cout<<"original od = "<<od<<endl;
    od = rotate(od,PI/2);
//    cout<<"rotated od = "<<od<<endl;

    double abod = abs(od),abcp = norm(cp-p1);
    double len = sqrt(1-abcp);

    // cout<<"abod = "<<abod<<" abcp = "<<abcp<<endl;
    // cout<<"len = "<<len<<endl;
    P rep1 = cp + (od/abod)*len;
    P rep2 = cp - (od/abod)*len;
    return make_pair(rep1,rep2);
}

int main() {
    int n;
    while(cin>>n, n) {
        vector<P> pv;
        double x,y;
        for(int i=0; i<n; ++i) {
            cin>>x>>y;
            pv.push_back(P(x,y));
        }

        int ans = 1;
        for(int i=0; i<n; ++i) {
            for(int j=i+1; j<n; ++j) {
                if(dist(pv[i],pv[j]) > 2.0) continue;
                pair<P,P> p = findCenter(pv[i],pv[j]);
                int t1 = 0,t2 = 0;
//                cout<<pv[i]<<" "<<pv[j]<<" "<<p.first<<" "<<p.second<<endl;
                Circle c1(p.first,1.0);
                Circle c2(p.second,1.0);
                for(int k=0; k<n; ++k) {
                    if(inC(c1,pv[k])) t1++;
                    if(inC(c2,pv[k])) t2++;
                }
                ans = max(ans, max(t1,t2));
            }
        }

        cout<<ans<<endl;
    }
}

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

const int M = 1e9 + 7;
int a[1001][1001];

int main() {

	int r,c;
	cin>>r>>c;

	char ch;
	for (int i = 0; i < r; ++i)
	{
		for(int j=0;j<c;j++) {

			cin>>ch;
			a[i][j]=ch;
		}
	}

	for (int i = 0; i < r; ++i)
	{
		for(int j=0;j<c;j++) {

			// cin>>a[i][j];

			if(a[i][j]!=a[0][0])
				a[i][j]=-1;
		}
	}

	for (int i = 0; i < r; ++i)
	{
		for(int j=0;j<c;j++) {

			// cin>>a[i][j];

			if(a[i][j]!=-1)
				a[i][j]=0;
		}
	}


	a[r-1][c-1] = 1;
	for(int i=r-2;i>=0;--i) {
		if(a[i][c-1]==-1)
			break;
		a[i][c-1]=1;
	}
	for(int i=c-2;i>=0;--i) {
		if(a[r-1][i]==-1)
			break;
		a[r-1][i]=1;
	}

	for(int row=r-2;row>=0;row--) {
		for(int col=c-2;col>=0;col--) {
			if(a[row][col]==-1)
				continue;
			if(a[row+1][col]!=-1)
				a[row][col] =  a[row+1][col];
			if(a[row][col+1]!=-1)
				a[row][col] = (a[row][col] + a[row][col+1])%M;
		}
	}



	cout<<a[0][0];

	return 0;
}

Measured memory_bytes: 7472
#include <iostream>  
#include <algorithm>
#define ll long long
using namespace std;  
int n,m;
ll ans;  
struct P  
{  
	int x,y;  
}pnt1[256],pnt2[256];  

int cmp1(P a,P b)  
{  
	return a.x<b.x;  
}  

int cmp2(P a,P b)  
{  
	return a.y<b.y;  
}  
int vis[256];  

void judge(int lx,int rx)  
{  
	int y[256],u=0,d=0;  
	for(int i=0;i<n;++i)  
		if(pnt2[i].x>=lx&&pnt2[i].x<=rx){  
			y[u++]=pnt2[i].y; 
			if(u-d==m){
				ans=min(ans,(ll)(y[u-1]-y[d])*(ll)(rx-lx));  
				++d;
			}
		}
}

int main()  
{
	scanf("%d%d",&n,&m);  
	for(int i=0;i<n;++i){  
		scanf("%d%d",&pnt1[i].x,&pnt1[i].y);  
		pnt2[i]=pnt1[i];  
	}  
	sort(pnt1,pnt1+n,cmp1);  
	sort(pnt2,pnt2+n,cmp2);  
	ans=(ll)(2147483600) * (ll)(2147483600);          
	for(int i=0;i<n;++i)  
		for(int j=i;j<n;++j)  
			judge(pnt1[i].x,pnt1[j].x);  
	printf("%lld\n",ans);  
	return 0;     
}   



Measured memory_bytes: 256
fun main(args: Array<String>) {
    val (a, b, c) = readLine()?.split(" ")?.map { it.toInt() } ?: return

    val list = mutableListOf(a, b ,c)

    var count = 0

    while (list[0] != list[1] || list[1] != list[2]) {
        val updatedPos = posExcludeMax(list)
        when (updatedPos.size) {
            0 -> {
                // ありえない
            }
            1 -> {
                list[updatedPos[0]] += 2
            }
            2 -> {
                list[updatedPos[0]]++
                list[updatedPos[1]]++
            }
        }
        count++
    }

    println(count)
}

private fun posExcludeMax(list: List<Int>): List<Int> {
    val max = list.max()
    val result = mutableListOf<Int>()
    for ((i, v) in list.withIndex()) {
        if (v != max) {
            result += i
        }
    }
    return result
}

Measured memory_bytes: 36136
#include <bits/stdc++.h>
#define FOR(i,a,b) for (int i = (a); i < (b); ++i)
#define rep(i,n) for (int i = (0); i < (n); ++i)
#define rng(x) (x).begin(),(x).end()
#define rrng(x) (x).rbegin(),(x).rend()
#define debug(x) cout << #x << " = " << (x) << endl;
#define fi first
#define se second
#define pb push_back
#define eb emplace_back
#define sz(x) (int)(x).size()
#define bn(x) ((1<<x)-1)
#define dup(x,y) (((x)+(y)-1)/(y))
#define uni(x) x.erase(unique(rng(x)),x.end())
#define SP << " " <<
using namespace std;
using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vll = vector<ll>;
using pii = pair<int, int>;
using tiii = tuple<int, int, int>;
const int mod = 1000000007;
const double EPS = 1e-9;
const int INF = 1<<30;
const ll INFLL = 1LL<<60;
//cout << fixed << setprecision(10);

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 main () {
  int a1, a2, a3;
  cin >> a1 >> a2 >> a3;
  cout << (a1+a2+a3>=22?"bust":"win") << endl;
  return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/trie_policy.hpp>

#define pb push_back
#define mp make_pair
#define taskname "A"

using namespace std;
using namespace __gnu_pbds;

typedef long long ll;
typedef long double ld;
typedef pair<ll,int> ii;
typedef tree <int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update> ordered_set;

const int maxn = 1e3 + 5;
const int maxm = 2e5 + 5;

vector<int> adj[maxn];
bitset<maxn> vis[maxn];
bitset<maxn> vis1;
int a[maxm],b[maxm];
bitset<maxm> res;
int n , m;

int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    if(fopen(taskname".INP","r")){
		freopen(taskname".INP", "r",stdin);
		freopen(taskname".OUT", "w",stdout);
    }
    cin >> n >> m;
    for(int i = 1 ; i <= m ; ++i){
        cin >> a[i] >> b[i];
        adj[a[i]].pb(i);
    }
    for(int i = 1 ; i <= n ; ++i){
        queue<int> q;
        q.push(i);vis[i][i] = 1;
        while(q.size()){
            auto u = q.front();q.pop();
            for(auto &c : adj[u]){
                if(vis[i][b[c]] == 0){
                    vis[i][b[c]] = 1;q.push(b[c]);
                }
            }
        }
    }
    for(int i = 1 ; i <= n ; ++i){
        vis1.reset();
        vis1[i] = 1;
        for(auto &c : adj[i]){
            if(vis1[b[c]]){
                res[c] = 1;
                continue;
            }
            queue<int> q;q.push(b[c]);vis1[b[c]] = 1;
            while(q.size()){
                auto u = q.front();q.pop();
                for(auto &c : adj[u]){
                    if(vis1[b[c]] == 0){
                        vis1[b[c]] = 1;q.push(b[c]);
                    }
                }
            }
        }
        reverse(adj[i].begin(),adj[i].end());
        vis1.reset();
        vis1[i] = 1;
        for(auto &c : adj[i]){
            if(vis1[b[c]]){
                res[c] = 1;
                continue;
            }
            queue<int> q;q.push(b[c]);vis1[b[c]] = 1;
            while(q.size()){
                auto u = q.front();q.pop();
                for(auto &c : adj[u]){
                    if(vis1[b[c]] == 0){
                        vis1[b[c]] = 1;q.push(b[c]);
                    }
                }
            }
        }
    }
    for(int i = 1 ; i <= m ; ++i){
//        cout << vis[b[i]][a[i]] << " " << res[i] << " ";
        if(vis[b[i]][a[i]] == res[i])cout << "same\n";
        else cout << "diff\n";
    }
}


Measured memory_bytes: 4480
{-# LANGUAGE ScopedTypeVariables #-}
{-# LANGUAGE BangPatterns #-}
{-# LANGUAGE TupleSections #-}
{-# LANGUAGE ExplicitForAll #-}
{-# LANGUAGE LambdaCase #-}
{-# LANGUAGE MultiWayIf #-}
{-# LANGUAGE Unsafe #-}
{-# LANGUAGE RecordWildCards #-}
{-# LANGUAGE FlexibleContexts #-}

import Data.Bits
import Data.List
import qualified Data.ByteString.Char8 as BS
import qualified Data.ByteString.Lazy.Char8 as BSL
import Data.IntMap.Strict (IntMap)
import qualified Data.IntMap.Strict as IMS
import Data.IntSet (IntSet)
import qualified Data.IntSet as IS
import qualified Data.Sequence as Seq
import Data.Sequence (Seq)
import qualified Data.Array.IArray as A
import qualified Data.Array.MArray.Safe as A
import qualified Data.Array.MArray as A
import Data.Array (Array)
import Data.Array.Unboxed (UArray)
import Data.Array.IArray (IArray)
import Data.Array.MArray.Safe (MArray)
import Data.Array.IO.Safe (IOArray, IOUArray)
import Data.Array.ST.Safe (STArray, STUArray, runSTArray, runSTUArray)
import qualified Data.Vector as V
import qualified Data.Vector.Unboxed as VU
import qualified Data.Vector.Unboxed.Mutable as VUM
import Control.Monad
import Control.Monad.ST
-- import Control.Monad.ST.Safe
import Control.Applicative
import Data.Maybe
import Data.Tuple
import Data.Ord
import Control.Monad.State.Strict
import Data.Int
import System.IO
import Data.Function
import Control.Monad.Primitive
import qualified Data.Vector.Primitive.Mutable as VPM
import qualified Data.Vector.Generic.Mutable as VGM
import Data.STRef
import Data.IORef

main :: IO ()
main = do
  n <- read <$> getLine
  as <- VU.unfoldrN n (BS.readInt . BS.dropWhile (==' ')) <$> BS.getLine
  bs <- VU.unfoldrN n (BS.readInt . BS.dropWhile (==' ')) <$> BS.getLine
  let diffs = sortOn Down $ VU.toList $ VU.zipWith (-) as bs
      (pos,neg) = span (>=0) diffs
      neglen = length neg
      negsum = sum neg
      poslen = foldr (\ !d cont !possum !k -> if possum + negsum >= 0 then
                                               Just k
                                             else
                                               cont (possum+d) (k+1))
                     (\ !possum !k -> if possum + negsum >= 0 then Just k
                                     else Nothing) pos 0 0
  print $ fromMaybe (-1) $ (neglen+) <$> poslen


Measured memory_bytes: 27004
#include <bits/stdc++.h>
#define all(x) begin(x), end(x)
#define dbg(x) cerr << #x << " = " << x << endl
#define _ << ' ' <<
using namespace std;
using ll = long long;
using vi = vector<int>;


int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    string s;
    cin >> s;
    ll sol = 0, b = 0;
    for (int i = 0; i < s.size(); ++i)
    {
        if (s[i] == 'W')
            sol += b;
        else
            b++;
    }
    cout << sol;
}


Measured memory_bytes: 720
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using vl = vector<ll>;
using vvl = vector<vl>;
using vi = vector<int>;
using vvi = vector<vi>;
#define ote(x) cout<<(x)<<endl
#define all(x) (x).begin(),(x).end()
#define rp(i,s,e) for(int i=(s);i<(e);++i)
#define rpz(i,e) rp(i,0,e)
#define irp(i,s,e) for(int i=(s);i>(e);--i)
#define irpz(i,s) irp(i,s,-1)


void v_print(vi &v){for(auto e:v){printf("%d,",e);}puts("");}//

int main(){
	string S; cin>>S;
	int N = S.size();
	vi R(N);
	vi L(N);

	int pre_ix;

	pre_ix = 0;
	rp(now_ix, 1, N){
		if(S[pre_ix] != S[now_ix]){
			if(S[pre_ix] == 'R'){
				int n = now_ix - pre_ix;
				int a = n/2;
				int b = n-a;
				R[now_ix-1] += b;
				R[now_ix] += a;
			}
			pre_ix = now_ix;
		}
	}

	reverse(all(S));

	pre_ix = 0;
	rp(now_ix, 1, N){
		if(S[pre_ix] != S[now_ix]){
			if(S[pre_ix] == 'L'){
				int n = now_ix - pre_ix;
				int a = n/2;
				int b = n-a;
				L[now_ix-1] += b;
				L[now_ix] += a;
			}
			pre_ix = now_ix;
		}
	}

	reverse(all(L));

	rpz(i, N) cout<<L[i]+R[i]<<(i+1<N?" ":"\n");
}


Measured memory_bytes: 1408
#include <iostream>
using namespace std;
int main(void){
    int N;
    cin>>N;
    int P[N];
    for(int i=0;i<N;i++){
        int d;
        cin>>d;
        P[i]=d;
    }
    int min=100;
    for(int i=0;i<N;i++){
        if(min>P[i]){
            min=P[i];
        }
    }
    for(int i=0;i<N;i++){
        for(int j=i+1;j<N;j++){
            if(P[i]==P[j]){
                P[j]=min;
            }
        }
    }
    int count=1;
    for(int i=0;i<N;i++){
        for(int j=0;j<N;j++){
            if(P[i]>P[j]){
                count++;
                break;
            }
        }
    }
    cout<<count<<endl;
    
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef pair<ll, ll> P;
typedef vector<int> VI;
typedef vector<VI> VVI;
const ll MOD = 1000000007;
const ll INF = 1000000000;
#define REP(i, n) for(int i = 0; i < n; i++)
#define ALL(v) v.begin(), v.end()

int main() {
	int n;
	cin >> n;
	string s;
	cin >> s;
	int ans = 1;
	REP(i, n - 1) {
		if (s[i] != s[i + 1])
			ans++;
	}
	cout << ans;
}

Measured memory_bytes: 512
#include <cstdio>
char s[5];int ans=-1,num;bool first=1;
int main(){
    scanf("%s",s);
    for(int i=0;s[i];i++){
        if(s[i]=='R'&&(s[i]==s[i-1]||first)) ++num,first=0;
        if(ans<num) ans=num;
    }
    printf("%d\n",ans);
    return 0;
}

Measured memory_bytes: 1732
# 

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

flag=0
for i in range(max(Y//10000, N) + 1):

    balance = Y - i*10000
    for j in range(max(balance//5000, N-i) +1):
        balance = Y - i*10000 - j*5000
        k = balance // 1000
        
#         print(i,j,k)
        if (k+j+i)==N:
            flag=1
            break
    if flag==1:
        break


if flag==1:
    print(i)
    print(j)
    print(k)    
else:
    print("-1 -1 -1")

Measured memory_bytes: 3064
DIV = 10**9+7

N = int(input())
a = []
for i in range(N):
  a.append(list(map(lambda x: int(x), input().split())))
  
#dp[i][b] = i番目でビット列bに到達するパターン数
dp = [[0]*(2**N) for i in range(N)]
#dp[0][:]の初期化
for k in range(N):
  if a[0][k]==1:
    dp[0][(1<<k)] = 1
    
for i in range(1, N):
  for b in range(2**N):
    if dp[i-1][b]==0:
      continue
    for k in range(N):
      if a[i][k]==1 and b&(1<<k)==0:
        target = (b|(1<<k))
        dp[i][target] += dp[i-1][b]
        if dp[i][target]>DIV:
          dp[i][target] %= DIV
          
s = 0
for i in range(2**N):
  s += dp[N-1][i]
  if s>DIV:
    s %= DIV
    
print(s)

Measured memory_bytes: 380168
#include<stdio.h>
int main(){
  int n,i,j,k,c=0,b[110]={};
  scanf("%d",&n);
  for(i=1;i<=n;i++){
    k=i;
    for(j=2;j<=k;j++){
      while(k%j==0){
	b[j]++;
	k/=j;
      }
    }
    //if(k>1)b[k]++;
  }
  //for(i=0;i<=10;i++)printf("%d %d\n",i,b[i]);
  for(i=2;i<=n;i++){
    if(b[i]<4)continue;
    for(j=i+1;j<=n;j++){
      if(b[j]<4)continue;
      for(k=2;k<=n;k++){
	if(i==k||j==k||b[k]<2)continue;
	c++;
      }
    }
  }
  for(i=2;i<=n;i++){
    if(b[i]<14)continue;
    for(j=2;j<=n;j++){
      if(i==j||b[j]<4)continue;
      c++;
    }
  }
  for(i=2;i<=n;i++){
    if(b[i]<24)continue;
    for(j=2;j<=n;j++){
      if(i==j||b[j]<2)continue;
      c++;
    }
  }
  for(i=2;i<=n;i++){
    if(b[i]<74)continue;
    c++;
  }
  printf("%d\n",c);
  return 0;
}
      


Measured memory_bytes: 128
import java.util.Scanner;

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

        // ??????????????????????????????.
        // ?????°????????????????¢??????????.
        // ?????????????´????????´???????.
        Scanner sc = new Scanner(System.in);
        int count = sc.nextInt();
        int array[] = new int[count];
        for (int i = 0; i < count; i ++) {
            array[i] = sc.nextInt();
        }


        // ????°???????????????????.
        // ?????§??????????????????.
        // ????¨???????????????????.
        long min = 1000001;
        for (int i = 0; i < count; i ++) {
            if (min > array[i]) { min = array[i]; }
        }
        long max = -1000001;
        for (int i = 0; i < count; i ++) {
            if (max < array[i]) { max = array[i]; }
        }
        long sum = 0;
        for (int i = 0; i < count; i ++) { sum += array[i]; }
        System.out.println(min + " " + max + " " + sum);
    }
}

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

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

    vector<int> p(n);
    rep(i, n)
    {
        cin >> p.at(i);
    }

    // p[0]からp[i]までの最小値の配列
    vector<int> m(n);
    //最小値を更新
    int tmp = p.at(0);

    rep(i, n)
    {
        if (i == 0)
        {
            m.at(i) = tmp;
        }
        else
        {
            //最小値の更新
            tmp = min(tmp, p.at(i));
            //最小値
            m.at(i) = tmp;
        }
    }

    int ans = 0;
    rep(i, n)
    {
        if (p.at(i) <= m.at(i))
        {
            ans += 1;
        }
    }

    cout << ans;
}


Measured memory_bytes: 1792
def main():
    import sys
    input = sys.stdin.readline
    N = int(input())
    A = [list(map(int,input().split())) for i in range(N)]
    
    import copy
    D = [[[0,1] for i in range(N)] for j in range(N)]
    for i in range(N):
        for j in range(N):
            D[i][j][0] = A[i][j]
    flag = 0
    
    for k in range(N):
        for i in range(N):
            for j in range(N):
                if k != i and k != j:
                    if D[i][j][0] > D[i][k][0] + D[k][j][0]:
                        flag = 1
                    elif D[i][j][0] == D[i][k][0] + D[k][j][0]:
                        D[i][j][1] += 1
    ans = 0
    for i in range(N):
        for j in range(i+1,N):
            if D[i][j][1] == 1:
                ans += D[i][j][0]
    if flag == 1:
        print(-1)
    else:
        print(ans)
    
main()

Measured memory_bytes: 51804
#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#pragma GCC optimize("unroll-loops")

#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

using namespace std;
using namespace __gnu_pbds;

#define ll long long int
#define pb push_back
#define mp make_pair
#define ld long double
#define sz(a) (ll)(a).size()

typedef tree<pair<ll,ll> ,null_type,less<pair<ll,ll> >,rb_tree_tag,tree_order_statistics_node_update> ordered_set;
//K-th smallest
//cout << k << "kth smallest: " << *A.find_by_order(k-1) << endl;
//NO OF ELEMENTS < X
//cout << "No of elements less than " << X << " are " << A.order_of_key(X) << endl;

ll n, k, mod = 1e9 + 7;

vector< vector<ll> > mul(vector< vector<ll> > a1, vector< vector<ll> > a2)
{
	vector< vector<ll> >a3(n);
	for(int i=0;i<n;i++)
	{
		a3[i] = vector<ll>(n);
		for(int j=0;j<n;j++)
		{
			a3[i][j] = 0;
			for(int k=0;k<n;k++)
			{
				a3[i][j] = (a3[i][j] + (a1[i][k] * a2[k][j]) % mod) % mod;
			}
		}
	}
	return a3;
}

vector< vector<ll> > getIdentity(ll len)
{
	vector< vector<ll> > temp(len);
	for(int i=0;i<len;i++)
	{
		temp[i] = vector<ll>(len);
		for(int j=0;j<len;j++)
		{
			temp[i][j] = (i == j);
		}
	}
	return temp;
}

vector< vector<ll> > power(vector< vector<ll> > a, ll b)
{
	vector< vector<ll> >ans = getIdentity(n);
	while(b)
	{
		if(b % 2 == 1)
			ans = mul(ans, a);
		a = mul(a, a);
		b >>= 1;
	}
	return ans;
}

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

 	cin >> n >> k;
 	vector< vector<ll> >a(n);
 	for(int i=0;i<n;i++)
 	{
 		a[i] = vector<ll>(n);
 		for(int j=0;j<n;j++)
 		{
 			cin >> a[i][j];
 		}
 	} 
 	a = power(a, k);	
 	ll res = 0;
 	for(int i=0;i<n;i++)
 	{
 		for(int j=0;j<n;j++)
 		{
 			res = (res + a[i][j]) % mod;
 		}
 	}
 	cout << res << endl;
    return 0;
}

Measured memory_bytes: 384
#include"bits/stdc++.h"
using namespace std;
typedef long long ll;
#define int ll
int dist[300][300];
int32_t main()
{
	#ifndef ONLINE_JUDGE
	freopen("in","r",stdin);
	freopen("out","w",stdout);
	#endif

	for(int i=0;i<300;i++)
		for(int j=0;j<300;j++)
			if(i!=j)dist[i][j]=1e18;

	int n,m,l;
	cin>>n>>m>>l;
	for(int i=0;i<m;i++)
	{
		int u,v,w;
		cin>>u>>v>>w;
		u--;v--;
		dist[u][v]=dist[v][u]=w;
	}
	for(int k=0;k<n;k++)
		for(int i=0;i<n;i++)
			for(int j=0;j<n;j++)
				dist[i][j]=min(dist[i][j],dist[i][k]+dist[k][j]);

	for(int i=0;i<n;i++)
		for(int j=0;j<n;j++)
		{
			if(dist[i][j]<=l)dist[i][j]=1;
			else dist[i][j]=1e18;
		}

	for(int k=0;k<n;k++)
		for(int i=0;i<n;i++)
			for(int j=0;j<n;j++)
				dist[i][j]=min(dist[i][j],dist[i][k]+dist[k][j]);

	int q;
	cin>>q;
	while(q--)
	{
		int s,t;
		cin>>s>>t;
		s--;t--;
		if(dist[s][t]>=1e18)puts("-1");
		else
		cout<<dist[s][t]-1<<"\n";
	}

	

}

Measured memory_bytes: 4352
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <math.h>
#include <vector>
#include <map>
#include <queue>
#include <utility>
#include <algorithm>
#include <string>
#include <set>
#include <random>
using namespace std;

int main() {
  int A, B, C;
  cin >> A >> B >> C;
  if (A > B) {
	  swap(A, B);
	}
  if (B > C) {
	  swap(B, C);
	}
  if (A > B) {
	  swap(A, B);
	}
  cout << A + B + 10 * C << endl;
  return 0;
}


Measured memory_bytes: 256
s = input()
ls = len(s)
zero_one = "01" * (ls//2) + "0" * (ls%2)
one_zero = "10" * (ls//2) + "1" * (ls%2)


a, b = 0, 0
for i in range(ls):
    if s[i] != zero_one[i]:
        a += 1
    if s[i] != one_zero[i]:
        b += 1

print(min(a,b))

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

struct Unionfind {
  // tree number
  vector<int> par;
  // tree rank
  vector<int> treerank;
  // constructor
  Unionfind(int n = 1) { stree(n + 1); }
  // make and initialization
  void stree(int n = 1) {
    par.assign(n, -1);
    treerank.assign(n, 0);
  }
  // search root
  int root(int x) {
    if(par[x] < 0) return x;
    return par[x] = root(par[x]);
  }
  // is same?
  bool issame(int x, int y) { return root(x) == root(y); }

  // add
  // already added, return 0
  bool uni(int x, int y) {
    x = root(x);
    y = root(y);
    if(x == y) return 0;
    if(treerank[x] > treerank[y]) swap(x, y);
    if(treerank[x] == treerank[y]) ++treerank[y];
    par[y] -= size(x);
    par[x] = y;
    return 1;
  }
  int size(int x) { return -par[root(x)]; }
};

long long n, m;
vector<vector<long long>> lang;
vector<bool> ch;
Unionfind uf;

bool solve();

int main() {
  cin >> n >> m;
  lang.resize(n);
  ch.assign(m, 0);
  uf = Unionfind(n + m);
  for(int i = 0; i < n; ++i) {
    int k;
    cin >> k;
    lang[i].resize(k);
    for(int j = 0; j < k; ++j) {
      cin >> lang[i][j];
      ch[--lang[i][j]] = 1;
      uf.uni(i, lang[i][j] + n);
    }
  }
  if(solve())
    cout << "YES" << endl;
  else
    cout << "NO" << endl;
  return 0;
}

bool solve() {
  long long ans = uf.size(0);
  for(int i = 0; i < m; ++i)
    if(!ch[i]) ++ans;
  return ans == n + m;
}

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

using namespace std;


void solve()
{
	int n; cin >> n;
	int val,count = 0;
	for(int i=1;i<=n;i++){
		cin >> val;
		if ( i % 2 == 1 && val % 2 == 1){
			count++;
		}
	}
	cout << count << '\n';
}

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

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

int main(){
  int n;
  cin >> n;
  vector<ll> h(n);
  rep(i,n) cin >> h[i];
  
  int pre = -999;
  
  rep(i,n){
    if(pre<h[i]){
      pre = h[i]-1;
    }else if(pre==h[i]){
      pre = h[i];
    }else{
      puts("No");
      return 0;
    }
  }
    puts("Yes");
}


Measured memory_bytes: 1024
import sys
readline = sys.stdin.readline

H, W = map(int, readline().split())
N = int(readline())
Arr = []
A = list(map(int, readline().split()))
for i in range(N):
    Arr.extend([i+1]*A[i])

G = [Arr[W*i:W*(i+1)] for i in range(H)]
for i in range(0, H, 2):
    G[i].reverse()
for g in G:
    print(' '.join(map(str, g)))

Measured memory_bytes: 39664
import bisect
import sys
input = sys.stdin.readline

N = int(input())
A = sorted(map(int, input().split()))
ans = 0
 
for i in range(0, N-2):
       for k in range(i+1, N-1):
            ans += bisect.bisect_left(A, A[i]+A[k])-k-1
print(ans)

Measured memory_bytes: 42844
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define REP(i, n) for(ll i=0; i<(ll)n; i++)
#define REPR(i, n) for(ll i=(ll)n-1; i>=0; i--)
#define FOR(i, m, n) for(ll i=(ll)m; i<(ll)n; i++)
#define FORR(i, m, n) for(ll i=(ll)m-1; i>=(ll)n; i--)
#define ALL(x) (x).begin(), (x).end()
#define ASC(v) sort(ALL(v));
#define DESC(v) sort(ALL(v), greater<int>());
#define UNIQ(a) sort(ALL(a));(a).resize(unique(ALL(a)) - a.begin());
#define PRINTD(x, d) cout << fixed << setprecision(d) << x << "\n";
#define DEBUG(x) cout<<#x<<": "<<x<<"\n"
const double PI = acos(-1);
ll lcm(ll a, ll b) { return a / __gcd(a, b) * b; }
bool isprime(int x){ int i; if(x<2)return 0; else if(x==2) return 1; if(x%2==0) return 0; for(i=3; i*i<=x; i+=2) if(x%i==0) return 0; return 1; }
int digsum(int n) { int r=0; while(n>0) { r+=n%10; n/=10; } return r; }
template<class T> bool chmax(T &a, const T &b) { if (a<b) { a = b; return 1; } return 0; }
template<class T> bool chmin(T &a, const T &b) { if (a>b) { a = b; return 1; } return 0; }
 
int main(){
    ll N, M, X, Y;
    cin >> N >> M >> X >> Y;
    vector<ll> x(N);
    REP(i, N) cin >> x[i];
    vector<ll> y(M);
    REP(i, M) cin >> y[i];

    bool can = true;
    DESC(x);
    ASC(y);
    FOR(Z, X+1, Y+1) {
        if (x[0] < Z && Z <= y[0]) can = false;
    }

    if (can) cout << "War\n";
    else cout << "No War\n";
}


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

using namespace std;

int main(){
    string s;
    cin>>s;
    if(s=="SUN"){
        cout<<7;
    }else if(s=="MON"){
        cout<<6;
    }else if(s=="TUE"){
        cout<<5;
    }else if(s=="WED"){
        cout<<4;
    }else if(s=="THU"){
        cout<<3;
    }else if(s=="FRI"){
        cout<<2;
    }else if(s=="SAT"){
        cout<<1;
    }

}



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

// #define multitest 1
// #define Debug 1
#ifdef Debug
#define db(...) ZZ(#__VA_ARGS__, __VA_ARGS__);
template <typename Arg1>
void ZZ(const char *name, Arg1 &&arg1)
{
	std::cerr << name << " = " << arg1 << endl;
}
template <typename Arg1, typename... Args>
void ZZ(const char *names, Arg1 &&arg1, Args &&... args)
{
	const char *comma = strchr(names + 1, ',');
	std::cerr.write(names, comma - names) << " = " << arg1;
	ZZ(comma, args...);
}
#else
#define db(...)
#endif

typedef long long ll;
typedef long double ld;
#define f first
#define s second
#define pb push_back
const long long mod = 1000000007;

void add_self(int &a, int b)
{
	a += b;
	if (a >= mod)
		a -= mod;
}

template <typename T>
T mul(T &a, int b)
{
	return (ll)a * b % mod;
}

struct Matrix
{
	int n;
	vector<vector<int>> t;
	Matrix(int n = 50)
	{
		this->n = n;
		t.resize(n, vector<int>(n));
		for (int i = 0; i < n; ++i)
			t[i][i] = 1;
	}
	Matrix operator*(const Matrix &b) const
	{
		Matrix c = Matrix(n);
		for (int i = 0; i < n; ++i)
			for (int j = 0; j < n; ++j)
			{
				c.t[i][j] = 0;
				for (int k = 0; k < n; ++k)
					add_self(c.t[i][j], mul(t[i][k], b.t[k][j]));
			}
		return c;
	}
};

Matrix power(Matrix &a, ll index)
{
	if (index == 0)
		return Matrix(a.n);
	Matrix temp = power(a, index / 2);
	temp = temp * temp;
	if (index & 1)
		temp = temp * a;
	return temp;
}

void solve()
{
	ll n, k;
	cin >> n >> k;
	vector<vector<int>> Can(n, vector<int>(n));
	for (int i = 0; i < n; ++i)
		for (int j = 0; j < n; ++j)
			cin >> Can[i][j];
	Matrix answer = Matrix(n);

	Matrix cani(n);
	cani.t = Can;
	answer = power(cani, k);
	int ans = 0;
	for (int i = 0; i < n; ++i)
		for (int j = 0; j < n; ++j)
		{
			db(i, j, answer.t[i][j]);
			add_self(ans, answer.t[i][j]);
		}
	cout << ans;
}

int main()
{
#ifndef Debug
	ios_base::sync_with_stdio(0);
	cin.tie(0);
#endif
	int t = 1;
#ifdef multitest
	cin >> t;
#endif
	while (t--)
		solve();
	return 0;
}

Measured memory_bytes: 384
import math

s = int(input())

rot = int(math.sqrt(s) // 1)
if s == rot**2:
    print("0 0 " + str(rot) + " 0 0 " + str(rot))
    exit()

rot += 1
ans = (rot**2) - s
print("0 0 " + str(rot) + " 1 " + str(ans) + " " + str(rot))


Measured memory_bytes: 3060
#include <iostream>
#include <string>

using namespace std;

int main(){
  int h, w;
  cin >> h >> w;

  string board[50];

  for(int i = 0; i < h; i++) cin >> board[i];

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

  for(int i = 0;i < h; i++){
    for(int j = 0; j < w; j++){
      if (board[i][j] == '#') continue;

      int num = 0;

      for(int d = 0; d < 8; d++){
	const int ni = i + dy[d];
	const int nj = j + dx[d];

	if(ni < 0 or h <= ni) continue;
	if(nj < 0 or w <= nj) continue;
	if(board[ni][nj] == '#') num++;
      }
      board[i][j] = char(num + '0');
    }
  }
  for(int i = 0; i < h; i++) cout << board[i] << endl;
  return 0;
}

/*
int main(){
  int h, w;
  cin >> h >> w;

  string board[50];

  int i, j;

  for(i=0; i<h; i++) cin >> board[i];
  
  //const int dx[8] = {-1, 0, 1, -1,    1, -1, 0, 1};
  //const int dy[8] = {-1, -1, -1, 0,   0,  1, 1, 1};
  const int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1};
  const int dy[8] = {0, 1, 0, -1, 1, 1, -1, -1};
  
  for(i = 0; i < h; i++){
    for(j = 0; j < w; j++){
      if(board[i][j] == '#') continue;

      int num = 0;
      for(int d = 0; d < 8; d++){
	const int ni = i + dy[d];
	const int nj = j + dx[d];

	if(ni < 0 or h <= ni) continue;
	if(nj < 0 or w <= nj) continue;
	if(board[ni][nj]=='#') num++;
      }

      board[i][j] = char(num + '0');
    }
  }

  for(i = 0; i < h; i++) cout << board[i] << endl;

  return 0;
}
*/



Measured memory_bytes: 256
while True:
    (m, f, r) = [int(i) for i in input().split()]
    if m == f == r == -1:
        break
    total = m + f
    if m == -1 or f == -1 or total < 30:
        print('F')
    elif total < 50 and r < 50:
        print('D')
    elif total < 65:
        print('C')
    elif total < 80:
        print('B')
    else:
        print('A')

Measured memory_bytes: 7716
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
typedef long long ll;
struct edge { ll s, t, x; };
typedef pair<ll, ll> P;
typedef pair<ll,P> event;
const ll MAX = 510000;
const ll MOD = 1000000007;

int main() {
  ll N,K;cin>>N>>K;
  vector<ll>A(N);
  vector<ll>B(N);
  rep(i,N){
    cin>>A[i];
  }
  rep(i,N){
    cin>>B[i];
  }
  sort(B.begin(),B.end());
  sort(A.begin(),A.end());
  reverse(B.begin(),B.end());
  ll mi=0ll;
  ll ma=100000000000000ll;
  while(ma-mi>0){
    ll mid=(ma+mi)/2ll;
    ll sum=0ll;
    rep(i,N){
      ll g=mid/B[i];
      if(A[i]>g){sum+=(A[i]-g);}
    }
    if(sum<=K){ma=mid;}
    else{mi=mid+1;}
  }
  cout<<ma<<endl;
}



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

using namespace std;

using ll = int64_t;
using Vi = vector<int>;
using Vl = vector<ll>;
using Pii = pair<int, int>;
using Pll = pair<ll, ll>;

constexpr int I_INF = 2147483647;
constexpr ll L_INF = 9223372036854775807LL;

//===

template <typename _Ty>
struct Edge
{
	int src, to;
	_Ty cost;

	constexpr Edge(int _to, _Ty _cost) noexcept : src(-1), to(_to), cost(_cost) {}
	constexpr Edge(int _src, int _to, _Ty _cost) noexcept : src(_src), to(_to), cost(_cost) {}
};

template <typename _Ty>
using WeightedGraph = std::vector<std::vector<Edge<_Ty>>>;

template <typename _Ty>
void bellman_ford(std::vector<_Ty>& dist, std::vector<bool>& closed, const WeightedGraph<_Ty>& g, int s)
{
	constexpr _Ty inf = std::numeric_limits<_Ty>::max();
	int n = static_cast<int>(g.size());
	dist.resize(n, inf);
	closed.resize(n, false);
	dist[s] = 0;
	for (int i = 0; i < n; ++i) {
		for (int j = 0; j < n; ++j) {
			for (const auto& edge : g[j]) {
				if (dist[j] != inf && dist[edge.to] > dist[j] + edge.cost) {
					dist[edge.to] = dist[j] + edge.cost;
					if (i == n - 1) {
						closed[edge.to] = true;
					}
				}
			}
		}
	}
}



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

	WeightedGraph<ll> g(N);

	for (int i = 0; i < M; ++i) {
		int a, b, c;
		cin >> a >> b >> c;
		--a; --b;
		g[a].emplace_back(b, -c);
	}

	Vl dist;
	vector<bool> closed;
	bellman_ford(dist, closed, g, 0);

	if (closed[N - 1]) {
		cout << "inf" << endl;
	}
	else {
		cout << -dist[N - 1] << endl;
	}

	return 0;
}

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

const int N = (int) 3e5 + 5;
const int INF = (int) 1e9 + 9;

int n;
char s[N];
int dp[N][2];

int main() {
	//freopen(".inp", "r", stdin); freopen(".out", "w", stdout);
	cin >> n;
	cin >> s + 1;
	for (int i = 1; i <= n; i++) {
		dp[i][0] = dp[i - 1][0];
		dp[i][1] = dp[i - 1][1];
		if (s[i] == 'W') dp[i][0]++;
		else dp[i][1]++;
	}
	int ans = INF;
	for (int i = 1; i <= n; i++) {
		ans = min(ans, dp[i - 1][0] + dp[n][1] - dp[i][1]);
	}
	cout << ans;
	return 0;
}

Measured memory_bytes: 2944
#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

bool is_grown(vector<int> &h){
    for(int i : h){
        if(i!=0) return false;
    }
    return true;
}

signed main(){
    int N; cin >> N;
    vector<int> h(N+1);
    collect(h, N);
    h[N] = 0;
    
    int cnt = 0;
    while(!is_grown(h)){
        rep(i,N){
            if(h[i]!=0){
                h[i]--;
                if(h[i+1]==0) cnt++;
            }
        }
    }
    
    cout << cnt << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<ll> vec;
typedef vector<vec> mat;
typedef pair<ll,ll> pll;
const ll mod=1e9+7;
//const ll mod=998244353;
const ll inf=1LL<<61;

int main() {
  ll n;
  cin >> n;
  vec v(n);
  for(ll i=0;i<n;i++) cin >> v[i];
  vector<map<ll,ll>> cnt(2);
  for(ll i=0;i<n;i++) {
    cnt[i%2][v[i]]++;
  }
  vec a(2);
  vec id(2);
  for(ll i=0;i<2;i++) {
    for(auto p:cnt[i]) {
      if(a[i]<p.second) {
        a[i]=p.second;
        id[i]=p.first;
      }
    }
  }
  if(id[0]==id[1]) {
    n-=a[0];
    a[0]=a[1]=0;
    for(ll i=0;i<2;i++) {
      for(auto p:cnt[i]) {
        if(p.first==id[i]) continue;
        a[i]=max(a[i],p.second);
      }
    }
    n-=max(a[0],a[1]);
  }
  else {
    n-=a[0]+a[1];
  }
  cout << n << endl;
}

Measured memory_bytes: 7296
// 失敗するからこそ そこから立ち向かって行く強さがあってそんな強さが本当の強さだと私は思うから
// ぜったいあきらめない
#include<bits/stdc++.h>
using namespace std;

#if defined(DAIJOBU)
#include "/home/ichigo/debug.hpp"
#define deb(x...) cerr << "[" << #x << "] = ["; _print(x)
#else
#define deb(x...)
#endif
#define FIO {ios::sync_with_stdio(0);cin.tie(nullptr);cout.tie(nullptr);}

int main(){
	FIO
	
	string s;cin >> s;
	stack<char> st;
	for(int i = 0; i < (int)s.size(); i++){
		if(st.empty())st.push(s[i]);
		else{
			if(s[i] == 'T' && st.top() == 'S')st.pop();
			else st.push(s[i]);
		}
	}
	cout << st.size();
	return 0;
}


Measured memory_bytes: 720
using System;
using System.Collections.Generic;
using System.Linq;

class Program
{
    static string InputPattern = "InputX";

    static List<string> GetInputList()
    {
        var WillReturn = new List<string>();

        if (InputPattern == "Input1") {
            WillReturn.Add("10 20");
            //10
        }
        else if (InputPattern == "Input2") {
            WillReturn.Add("10 -10");
            //1
        }
        else if (InputPattern == "Input3") {
            WillReturn.Add("-10 -20");
            //12
        }
        else {
            string wkStr;
            while ((wkStr = Console.ReadLine()) != null) WillReturn.Add(wkStr);
        }
        return WillReturn;
    }

    static void Main()
    {
        List<string> InputList = GetInputList();
        int[] wkArr = InputList[0].Split(' ').Select(A => int.Parse(A)).ToArray();

        int X = wkArr[0], Y = wkArr[1];
        Console.WriteLine(Solve(X, Y));
    }

    static int Solve(int pX, int pY)
    {
        if (pX == 0) {
            if (0 < pY) return pY;
            return -pY + 1;
        }
        if (pY == 0) {
            if (0 < pX) return 1 + pX;
            else return -pX;
        }

        int AbsDiff = Math.Abs(Math.Abs(pX) - Math.Abs(pY));

        if (0 < pX && 0 < pY) {
            //場合01
            if (pX < pY) return AbsDiff;
            //場合02
            else return 1 + AbsDiff + 1;
        }
        if (pX < 0 && pY < 0) {
            //場合03
            if (pX < pY) return AbsDiff;
            //場合04
            else return 1 + AbsDiff + 1;
        }
        if (0 < pX && pY < 0) {
            //場合05
            if (Math.Abs(pX) < Math.Abs(pY)) return AbsDiff + 1;
            //場合06
            else return 1 + AbsDiff;
        }
        if (pX < 0 && 0 < pY) {
            //場合07
            if (Math.Abs(pX) < Math.Abs(pY)) return 1 + AbsDiff;
            //場合08
            else return AbsDiff + 1;
        }
        return -1;
    }
}


Measured memory_bytes: 2776
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
ll n,ans,x;
int main(){
	cin >> n;
	for(ll i=1;i<n;){
		if(x==1)break;
		x=(n-i)/i;
		if(n/((n-i)/i)==n%((n-i)/i))ans+=(n-i)/i,i++;
		else if(x>1)i=max(i+1,n/(x-1));
	}
	cout << ans;
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
using namespace std;
typedef long long ll;

bool solve(string s) {
	int n = s.size();
	int h = 0;
	if (s[0] != 'm') return false;
	for (int i = 0; i < n-1; ++i) {
		if (s[i] == 'm') {
			if (s[i+1] == 'm') h++;
			else if (s[i+1] == 'w') h -= 10000;
		} else if (s[i] == 'e') {
			if (s[i+1] == 'm') h++;
			else if (s[i+1] == 'e') h -= 10000;
		} else {
			if (s[i+1] == 'm') h -= 10000;
			else h--;
		}
		if (h < 0) return false;
	}
	return h == 0;
}

int main() {
	string s; cin >> s;
	cout << (solve(s) ? "Cat" : "Rabbit") << endl;
}


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

int main() {
    int n;
    cin >> n;
    
    if (n == 1) 
        cout << "Hello World" <<endl;
    else if (n == 2) {
        int a, b;
        cin >> a >> b;
        cout << a + b << endl;
    }

    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define rep(i,n) for(int i=0;i<n;i++)
const ll MOD=1000000007;
const long double PI=3.14159265358979;
const ll MAX=0;

int main() {
  ll l,r,k,ans=0;
  cin>>l>>r>>k;
  for(int i=l;i<=r;i++){
    if(i%k==0){
      ans++;
    }
  }
  cout<<ans;
}



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

class MaxFlow {
public:
  struct edge { ll to, cap, rev; };

  const ll INF = 1LL << 60;
  ll N;
  vector< vector<edge> > E;
  vector<bool> used;

  MaxFlow(ll n): N(n), E(n), used(n) {};

  void add_directed_edge(ll from, ll to, ll cap) {
    E[from].push_back((edge) { to, cap, (ll) E[to].size() });
    E[to].push_back((edge) { from, 0, (ll) E[from].size() - 1 });
  }

  void add_undirected_edge(ll from, ll to, ll cap) {
    E[from].push_back((edge) { to, cap, (ll) E[to].size() });
    E[to].push_back((edge) { from, cap, (ll) E[from].size() - 1 });
  }

  ll dfs(ll v, ll t, ll f) {
    if(v == t) return f;
    used[v] = true;
    REP(i, 0, E[v].size()) {
      edge &e = E[v][i];
      if(!used[e.to] && e.cap > 0) {
        ll d = dfs(e.to, t, min(f, e.cap));
        if(d > 0) {
          e.cap -= d;
          E[e.to][e.rev].cap += d;
          return d;
        }
      }
    }
    return 0;
  }

  ll max_flow(ll s, ll t) {
    ll flow = 0;
    while(1) {
      REP(i, 0, N) used[i] = false;
      ll f = dfs(s, t, INF);
      if(f == 0 || f == INF) break;
      flow += f;
    }
    return flow;
  }
};

int main(void) {
  ll N;
  cin >> N;
  vector<ll> A(N), B(N);
  REP(i, 0, N) cin >> A[i] >> B[i], A[i]--;

  ll s = N + 31, t = N + 31 + 1;
  vector<ll> movie(N), date(31);
  REP(i, 0, N) movie[i] = i;
  REP(i, 0, 31) date[i] = N + i;

  MaxFlow mf(N * 2 + 31 + 2);
  REP(i, 0, N) {
    mf.add_directed_edge(s, movie[i], 1);
    REP(j, A[i], B[i]) mf.add_directed_edge(movie[i], date[j], 1);
  }
  REP(i, 0, 31) mf.add_directed_edge(date[i], t, 1);

  ll f = mf.max_flow(s, t);
  cout << f * 100 + (31 - f) * 50 << endl;
}


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

int main() {
  int N;

  cin >> N;

  int W[N];
  int sum1 = 0;

  for (int k = 1; k <= N; k++) {
    cin >> W[k];
    sum1 += W[k];
  }

  sum1 -= W[N];
  int sum2 = W[N];
  int ans = abs(sum1 - sum2);

  for (int k = (N-1); k > 1; k--) {
    sum1 -= W[k];
    sum2 += W[k];
    int diff = abs(sum1 - sum2);
    if (diff < ans) { ans = diff; }
  }

  cout << ans << endl;
}

Measured memory_bytes: 256
// Created by sz
#include <bits/stdc++.h>
using namespace std;
typedef long long  ll;

const int N = 1e5 + 5;

int main(){
#ifdef LOCAL
    freopen("./input.txt", "r", stdin);
#endif
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    
 
    string s;
    cin>>s;
    int cnt1 = 0, cnt0= 0;
    for(auto i:s){
        if(i == '0')cnt0++;
        if(i=='1')cnt1++;
    }
    cout<<2*min(cnt0,cnt1)<<endl;
    
    return 0;
}


Measured memory_bytes: 512