akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
struct Edge {
    int to;     // 辺の行き先
    int weight; // 辺の重み
    Edge(int t, int w) : to(t), weight(w) { }
};
using Graph = vector<vector<int> >;
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define reprep(i,j,h,w) rep(i,h)rep(j,w)
#define rrep(i,m, n) for(int i = m; i < (int)(n); i++)
#define all(x) (x).begin(),(x).end()
#define aall(x,n) (x).begin(),(x).begin()+(n)
#define VEC(type,name,n) std::vector<type> name(n);rep(i,n)std::cin >> name[i];
#define pb push_back
#define pf push_front
#define lb lower_bound
#define ub upper_bound
#define fi first
#define se second
#define mk make_pair
#define sum accumulate
#define keta fixed<<setprecision
#define vvector(name,typ,m,n,a)vector<vector<typ> > name(m,vector<typ> (n,a))
#define vvvector(name,t,l,m,n,a) vector<vector<vector<t> > > name(l, vector<vector<t> >(m, vector<int>(n,a)));
typedef long long ll;
const int INF = 2000000000;
const long INF64 = 1000000000000000ll;
const ll MOD = 1000000007LL;
typedef unsigned int uint;
int main(){
    string s,t;
    std::cin >> s>>t;
    std::vector<std::vector<int>> p(26);
    rep(i,s.size()){
        p[s[i]-'a'].pb(i+1);
    }
    if(p[t[0]-'a'].size()==0){
        std::cout << -1 << std::endl;
        exit(0);}
    ll cou=0ll;
    ll moji=0ll;
    moji=*(lb(all(p[t[0]-'a']),moji));
    
    rep(i,t.size()-1){
    //    std::cout << moji << std::endl;
        if(p[t[i+1]-'a'].size()==0){
        std::cout << -1 << std::endl;
        exit(0);}
        if(ub(all(p[t[i+1]-'a']),moji)!=p[t[i+1]-'a'].end()){
            moji=*(ub(all(p[t[i+1]-'a']),moji));
        }
        else{
            
            moji=*(ub(all(p[t[i+1]-'a']),0ll));
            cou++;   
            //std::cout << moji << std::endl;
        }
        //std::cout << moji << std::endl;
    }
    
   // std::cout << moji << std::endl;
    //std::cout << cou << std::endl;
    std::cout << cou*s.size()+moji << std::endl;
    
}

Measured memory_bytes: 1216
#include <iostream>
#include <iomanip>
#include <random>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
#include <cmath>
#include <numeric>
#include <cstdlib>
#include <cstring>
#include <deque>
#include <sstream>
#include <bitset>
#include <cassert>
#include <fstream>
#include <queue>

#define len(X) ((int)(X).size())

#ifdef __LOCAL
	#define DBG(X) cout << #X << "=" << (X) << '\n';
#else
	#define DBG(X)
#endif

using std::cin;
using std::cout;
using std::vector;
using std::string;
using std::pair;
using std::swap;
using std::sort;
using std::lower_bound;
using std::unique;
using std::abs;

using int64 = long long int;
using pii   = pair<int, int>;
using pii64 = pair<int64, int64>;

const int NIL = -1;
const int INF = (int)2e9;
const int64 INF64 = (int64)2e18;

void init_IO() {
	std::ios_base::sync_with_stdio(false);
	cin.tie(nullptr);
	cout.tie(nullptr);
}

template<typename T>
std::ostream& operator<<(std::ostream& os, const vector<T>& vec) {
	os << '[';
	int fst = 1;

	for(auto& elem: vec) {
		if(fst == 0) {
			os << ' ';
		}

		os << elem;
		fst = 0;
	}

	os << ']';
	return os;
}

const int MAX_N = (int)1e5 + 777;
int p[MAX_N], n, m, ncc, used[MAX_N];
vector<int> g[MAX_N], cc[MAX_N];

void dfs(int i) {
	used[i] = 1;

	cc[ncc].push_back(i);
	cc[ncc].push_back(p[i]);

	for(auto& j: g[i]) {
		if(!used[j]) {
			dfs(j);
		}
	}
}

void solve() {
	cin >> n >> m;

	for(int i = 0; i < n; ++i) {
		cin >> p[i];
		--p[i];
	}

	for(int i = 0; i < m; ++i) {
		int v, u;
		cin >> v >> u;
		--v, --u;

		g[v].push_back(u);
		g[u].push_back(v);
	}

	for(int i = 0; i < n; ++i) {
		if(!used[i]) {
			dfs(i);
			++ncc;
		}
	}

	int answ = 0;

	for(int c = 0; c < ncc; ++c) {
		sort(cc[c].begin(), cc[c].end());

		for(int i = 0; i < len(cc[c]);) {
			int j = i;

			while(j + 1 < len(cc[c]) && cc[c][j + 1] == cc[c][i]) {
				++j;
			}

			answ += j - i;
			i = j + 1;
		}
	}

	cout << answ << '\n';
}

int main() {
	init_IO();
	solve();

	return 0;
}


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

using namespace std;

int main(void){
    int n;
    string s;

    cin >> n;
    cin >> s;

    int s_i = 0;
    int ans = 0;
    int find_p;
    while((find_p = s.find("ABC", s_i)) != string::npos){
        s_i = find_p + strlen("ABC");
        ans++;
    }

    cout << ans << endl;

    return 0;
}

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

int main()
{
    ios_base::sync_with_stdio(0);

    string less = "LESS";
    string greater = "GREATER";
    string equal = "EQUAL";

    string a, b; cin >> a >> b;

    if(a == b)
    {
        cout << equal << endl;
        return 0;
    }

    if(a.size() < b.size())
    {
        cout << less << endl;
        return 0;
    }

    if(a.size() > b.size())
    {
        cout << greater << endl;
        return 0;
    }

    int n = a.size();

    for(int i = 0; i < n; i++)
    if(a[i] < b[i])
    {
        cout << less << endl;
        break;
    }
    else
    if(a[i] > b[i])
    {
        cout << greater << endl;
        break;
    }

    return 0;
}

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

int main(){
    long long h;
    cin >> h;
    long long sum = 0;
    long long d = 0;
    while(1){
        h /= 2;
        d++;
        if(h == 0) break;
    }
	//cout << d << endl;
    for(int i = 2;i <= d;i++){
        sum += pow(2,i-1);
        //cout << sum << endl;
    }
    long long ans = sum + 1;
    cout << ans << endl;
}

Measured memory_bytes: 256
#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; }

const long long INF = 1e18;

long long n, W;
vector<long long> w(110, 0);
vector<long long> v(110, 0);
long long dp[110][100100];

int main() {
    cin >> n >> W;
    for(int i = 0; i < n; ++i) {
        cin >> w.at(i) >> v.at(i);
    }

    long long maxV = n*1000;
    for(int i = 0; i <= n; ++i) {
        for(int j = 0; j <= maxV; ++j) {
            dp[i][j] = INF;
        }
    }
    dp[0][0] = 0;

    for(int i = 0; i < n; ++i) {
        for(int j = 0; j <= maxV; ++j) {
            if(j+v.at(i) <= maxV) chmin(dp[i+1][j+v.at(i)], dp[i][j]+w.at(i));
            chmin(dp[i+1][j], dp[i][j]);
        }
    }

    int ans = 0;
    for(int i = 0; i <= maxV; ++i) {
        if(W >= dp[n][i]) ans = i;
    }
    cout << ans << endl;
}

Measured memory_bytes: 80128
// #define _GLIBCXX_DEBUG
#include <bits/stdc++.h>

#define FOR(i, a, b) for (int i = (a); i < int(b); ++i)
#define RFOR(i, a, b) for (int i = (b)-1; i >= int(a); --i)
#define REP(i, n) FOR(i, 0, n)
#define REP1(i, n) FOR(i, 1, int(n) + 1)
#define RREP(i, n) RFOR(i, 0, n)
#define RREP1(i, n) RFOR(i, 1, int(n) + 1)
#define ALL(c) begin(c), end(c)

int _ = (
#ifndef LOCAL
    std::cin.tie(nullptr), std::ios::sync_with_stdio(false),
#endif
    std::cout.precision(10), std::cout.setf(std::ios::fixed));

using ll = long long;
using ull = unsigned long long;
using ld = long double;
template <typename T> using vec = std::vector<T>;
using namespace std;

int main() {
  string S;
  cin >> S;

  const bool has_n = S.find('N') != string::npos;
  const bool has_s = S.find('S') != string::npos;
  const bool has_e = S.find('E') != string::npos;
  const bool has_w = S.find('W') != string::npos;

  if (has_n != has_s) {
    cout << "No" << endl;
    return 0;
  }
  if (has_e != has_w) {
    cout << "No" << endl;
    return 0;
  }
  cout << "Yes" << endl;
  return 0;
}


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

int main() {
  int N, M, C;
  cin >> N >> M >> C;
  vector<int> B(M);
  int cnt = 0;
  for (int i = 0; i < M; i++) cin >> B[i];
  for (int i = 0; i < N; i++) {
    int productAB = 0;
    for (int j = 0; j < M; j++) {
      int A;
      cin >> A;
      productAB += A * B[j];
    }
    if (productAB + C > 0) cnt++;
  }
  cout << cnt << endl;

  return 0;
}


Measured memory_bytes: 256
n,a,b = list(map(int,input().split()))
def comb(n,k,p):
  """power_funcを用いて(nCk) mod p を求める"""
  from math import factorial
  if n<0 or k<0 or n<k: return 0
  if n==0 or k==0: return 1
  a = 1
  b = 1
  c = 1
  for i in range(1,n+1):
    a = (a*i)%p
  for i in range(1,k+1):
    b = (b*i)%p
  for i in range(1,n-k+1):
    c = (c*i)%p
  return (a*power_func(b,p-2,p)*power_func(c,p-2,p))%p
def power_func(a,b,p):
  """a^b mod p を求める"""
  if b==0: return 1
  if b%2==0:
    d=power_func(a,b//2,p)
    return d*d %p
  if b%2==1:
    return (a*power_func(a,b-1,p ))%p
def power_func(a,b,p):
  """a^b mod p を求める"""
  if b==0: return 1
  if b%2==0:
    d=power_func(a,b//2,p)
    return d*d %p
  if b%2==1:
    return (a*power_func(a,b-1,p ))%p
mod = 10**9 + 7
ans = (power_func(2,n,mod)-1)%mod
ac = 1
for i in range(1,a+1):
    ac = (ac*(n-i+1)*power_func(i,mod-2,mod))%mod
ans = (ans-ac)%mod
bc = ac
for i in range(a+1,b+1):
    bc = (bc*(n-i+1)*power_func(i,mod-2,mod))%mod
ans = (ans-bc)%mod
print(ans)

Measured memory_bytes: 61788
n = int(input())
first = 0
second = 0
a = []

for i in range(n):	
	a.append(int(input()))
	if first < a[i]:
		first = a[i]
	elif second < a[i]:
		second = a[i]


for i in a:
	print(second) if i == first else print(first) 

Measured memory_bytes: 89792
import sys

sys.setrecursionlimit(200000)


def input():
    return sys.stdin.readline()[:-1]


def ii(t: type = int):
    return t(input())


def il(t: type = int):
    return list(map(t, input().split()))


def imi(N: int, t: type = int):
    return [ii(t) for _ in range(N)]


def iml(N: int, t: type = int):
    return [il(t) for _ in range(N)]


def solve():
    K, A, B = il()
    ka = K - (A - 1)
    ans = (ka // 2 - 1) * (B - A) + B
    if ka % 2 == 1:
        ans += 1
    return max(K + 1, ans)


if __name__ == "__main__":
    print(solve())


Measured memory_bytes: 3064
<?php
list($a, $b) = explode(" ", trim(fgets(STDIN)));

$da = floor(($a - 1) / 33) + 1;
$ma = ($a - 1) % 33;

$db = floor(($b - 1) / 33) + 1;
$md = ($b - 1) % 33;

$h = ($da + $db) * 3;
$w = 100;

$b = [];

for ($i = 1; $i <= $da; $i++) {
    $b[3 * $i - 2] = array_fill(0, 100, '#');
    $b[3 * $i - 1] = array_fill(0, 100, '#');
    $b[3 * $i - 0] = array_fill(0, 100, '#');

    if ($i != $da) {
        for ($j = 1; $j <= 33; $j++) {
            $b[3 * $i - 1][3 * $j - 1] = '.';
        }
    } else {
        for ($j = 1; $j <= $ma; $j++) {
            $b[3 * $i - 1][3 * $j - 1] = '.';
        }
    }
}

for ($i = 1; $i <= $db; $i++) {
    $b[3 * $da + 3 * $i - 2] = array_fill(0, 100, '.');
    $b[3 * $da + 3 * $i - 1] = array_fill(0, 100, '.');
    $b[3 * $da + 3 * $i - 0] = array_fill(0, 100, '.');

    if ($i != $db) {
        for ($j = 1; $j <= 33; $j++) {
            $b[3 * $da + 3 * $i - 1][3 * $j - 1] = '#';
        }
    } else {
        for ($j = 1; $j <= $md; $j++) {
            $b[3 * $da + 3 * $i - 1][3 * $j - 1] = '#';
        }
    }
}

echo $h . " " . $w . "\n";
foreach ($b as $v) {
    echo(implode($v) . "\n");

}

Measured memory_bytes: 4856
//Changed by LIRUNJING
#include<bits/stdc++.h>
using namespace std;
int how(int a)
{
    int cnt=0;
    for(int i=1;i<=a;i++)
    {
        if(a%i==0) cnt++;
    }
    if(cnt==8) return 1;
    else return 0;
}
int main()
{
    int n,x=0;
    cin>>n;
    for(int i=1;i<=n;i++)
    {
        if(how(i)==1 && i%2!=0) x++;
     } 
     cout<<x;
     return 0;
 } 
//time: 773us


Measured memory_bytes: 256
import Control.Applicative

main = do
    ss <- words <$>getLine
    let h:w:_ = [read x| x<- ss] ::[Int]
    if h==0 then return ()
    else do
      let o = concat[ [if even (x+y) then '#' else '.'|x <- [0..w-1] ] ++"\n"| y<- [0..h-1]]
      putStrLn $ o
      main

Measured memory_bytes: 3948
x = int(input())
a = []
dif = x // 100
spl = x % 100
cnt = 0
#print(dif, spl)

while spl > 0:
    if spl >= 5:
        spl -= 5
    elif spl == 4:
        spl -= 4
    elif spl == 3:
        spl -= 3
    elif spl == 2:
        spl -= 2
    elif spl == 1:
        spl -= 1
    cnt += 1

#print(cnt)

if dif >= cnt:
    print(1)
else:
    print(0)






Measured memory_bytes: 38384
#include <bits/stdc++.h>
using namespace std;
int main(){
  cout << fixed << setprecision(10);
  while (1){
    int n, w;
    cin >> n >> w;
    if (n == 0 && w == 0){
      break;
    }
    vector<int> v(n);
    for (int i = 0; i < n; i++){
      cin >> v[i];
    }
    int b = *max_element(v.begin(), v.end()) / w + 1;
    vector<int> cnt(b, 0);
    for (int i = 0; i < n; i++){
      cnt[v[i] / w]++;
    }
    int mx = *max_element(cnt.begin(), cnt.end());
    double ans = 0;
    for (int i = 0; i < b; i++){
      ans += (double) (b - 1 - i) / (b - 1) * cnt[i] / mx;
    }
    ans += 0.01;
    cout << ans << endl;
  }
}


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

int main(){
    int a,b,c,d;
    int n;
    cin >> n;
    d = n % 10;
    n /= 10;
    c = n % 10;
    n /= 10;
    b = n % 10;
    n /= 10;
    a = n % 10;
    if(a+b+c+d==7){
        cout << a << '+' << b << '+' << c << '+' << d << '=' << 7 << endl;
    }
    else if(a+b+c-d==7){
        cout << a << '+' << b << '+' << c << '-' << d << '=' << 7 << endl;
    }
    else if(a+b-c+d==7){
        cout << a << '+' << b << '-' << c << '+' << d << '=' << 7 << endl;
    }
    else if(a+b-c-d==7){
        cout << a << '+' << b << '-' << c << '-' << d << '=' << 7 << endl;
    }
    else if(a-b-c-d==7){
        cout << a << '-' << b << '-' << c << '-' << d << '=' << 7 << endl;
    }
    else if(a-b-c+d==7){
        cout << a << '-' << b << '-' << c << '+' << d << '=' << 7 << endl;
    }
    else if(a-b+c+d==7){
        cout << a << '-' << b << '+' << c << '+' << d << '=' << 7 << endl;
    }
    else if(a-b+c-d==7){
        cout << a << '-' << b << '+' << c << '-' << d << '=' << 7 << endl;
    }
    return 0;
}

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

using namespace std;

typedef pair<int, int> P_ii;
typedef pair<string, int> P_si;
typedef long long int ll;

const int MOD = 1000000007;

int main() {
    int N, M;
    cin >> N >> M;
    vector<vector<int> > Glaph(N+10);
    for (int j = 0; j < M; ++j) {
        int a, b;
        cin >> a >> b;
        Glaph[a].push_back(b);
        Glaph[b].push_back(a);
    }
    for (int i = 0; i < (int)Glaph[1].size(); ++i) {
        int from = Glaph[1][i];
        for (int j = 0; j < (int)Glaph[from].size(); ++j) {
            int to = Glaph[from][j];
            if (to == N) {
                printf("%s\n", "POSSIBLE");
                return 0;
            }
        }
    }
    printf("%s\n", "IMPOSSIBLE");
    return 0;
}



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

#define int long long int
#define rep(a,b,c) for(int a=b;a<c;a++)
#define repm(a,b,c) for(int a=(b-1);a>=c;a--)
#define pb push_back
#define str string
#define sf(a) scanfs("%d",&a)
#define pb push_back
#define mp make_pair
#define Fi first
#define Se second
#define ALL(v) (v).begin(), (v).end()

using namespace std;

const int INF = 1e18 + 9;
const int Mod = 1e9 + 7;
inline int replac(str s){double ans=0;rep(i,0,s.length()){ans+=(s[i]-'0')*pow(10,s.length()-i-1);}return (int)ans;}
inline string numstr(int m){str s="";while(m>0){char c;int a=m/10;if(a>0)a=m%(a*10);else a=m;c=(char)('0'+a);s+=c;m/=10;}str st="";for(int i=s.size()-1;i>=0;i--){st+=s[i];}return st;}
typedef vector<int> vi;
typedef pair<int,int> pii;
typedef vector<pii> vii;

signed main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n,m,a[100005];
    cin >> n >> m;
    rep(i,0,n){
        cin >> a[i];
    }
    rep(j,1,m+1){
    rep(i,0,n-1){
        int k=(a[i]%j);
        if(k>(a[i+1]%j))swap(a[i],a[i+1]);
    }
    }
    rep(i,0,n){
        cout << a[i] << endl;
    }
    return 0;
}

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

int main(void){
  int t,n,s,f,total;

  for(;;){
    total = 0;

    cin >> t;
    if( t == 0 ) break;

    cin >> n;
    for( int i = 0 ; i < n ; i++ ){
      cin >> s >> f;
      total += f - s;
    }

    if( total >= t ) cout << "OK" << endl;
    else cout << t - total << endl;
  }

  return 0;
}

Measured memory_bytes: 1160
#include <stdio.h>
#include <iostream>
#include <algorithm>
#include <sstream>
#include <complex>
#include <vector>
#include <list>
#include <queue>
#include <deque>
#include <stack>
#include <set>
#include <map>
#include <cstdio>
#include <string>
#include <cstdlib>
#include <cstring>
#include <bits/stdc++.h>
 
using namespace std;
typedef long long ll;
typedef string str;
typedef std::pair<ll,ll> pl;
typedef std::map<string, ll> msl;
typedef std::map<ll, ll> mll;
typedef std::vector<ll> vl;
const long double EPS = 1e-9;
 
#define rep(i, n) for(ll (i) = 0; (i) < (n) ; (i)++ )
#define For(i, a, b) for(ll (i) = (a); (i) < (b) ; (i)++ )
#define all(a) (a).begin(), (a).end()
#define rall(a) (a).rbegin(), (a).rend()
#define tol(c) char((c)+0x20)
#define tou(c) char((c)-0x20)
#define pb push_back
#define mp make_pair
#define pr(a) cout << (a)
#define prl(a) cout << (a) << endl
#define prl2(a,b) cout << (a) << " " << (b) << endl
#define prs(a) cout << (a) << " "
#define yn(condition) if ((condition)) prl("Yes"); else prl("No");
#define YN(condition) if ((condition)) prl("YES"); else prl("NO");
#define rpr(i,n,ans) rep((i),(n)) prs((ans[(i)]))
#define cpr(i,n,ans) rep((i),(n)) prl((ans[(i)]))
#define in1(a) cin >> (a)
#define in2(a,b) cin >> (a) >> (b)
#define in3(a,b,c) cin >> (a) >> (b) >> (c)
#define in4(a,b,c,d) cin >> (a) >> (b) >> (c) >> (d)
#define rin1(i,n,a) rep((i),(n)) cin >> (a[(i)])
#define rin2(i,n,a,b) rep((i),(n)) cin >> (a[(i)]) >> (b[(i)])
#define rin3(i,n,a,b,c) rep((i),(n)) cin >> (a[(i)]) >> (b[(i)]) >> (c[(i)])
#define e1 first
#define e2 second
#define ctol(c) ll((c)) - ll('0')
#define ltos(n) to_string((n))
#define items(kv, v) for(auto &(kv): (v))
#define ndig(N, n) ctol(ll(ltos((N))[ll(ltos((N)).length()) - (n)]))
#define beto(a,b,c) (a) < (b) && (b) < (c)
#define betc(a,b,c) (a) <= (b) && (b) <= (c)
#define rsort(a,n) sort(a,a+n,greater<>())
 
const ll mod = 1e9 + 7;
const ll INF = mod * mod;
const ll MAX_N = 100;
 
int main(void){
    ll n,k,x,y;
    str s,t,u;

    in4(n,k,x,y);
    ll ans = 0;

    rep(i, min(k,n)) ans += x;
    rep(i, n-k) ans += y;
    prl(ans);

    return 0;
}

Measured memory_bytes: 256
#include <cstdio>
#include <cstring>
#include <algorithm>
#define fo(i,a,b) for(int i=a;i<=b;i++)
#define fd(i,a,b) for(int i=a;i>=b;i--)
using namespace std;

typedef long long ll;
typedef double db;
int read() {
	char ch;
	for(ch=getchar();ch<'0'||ch>'9';ch=getchar());
	int x=ch-'0';
	for(ch=getchar();ch>='0'&&ch<='9';ch=getchar()) x=x*10+ch-'0';
	return x;
}

const int N=3*1e5+5;
const ll inf=1e16;

int n,m,x,y,a[N],stack[N],top;
ll f[N],g[N],h[N],ans[N],t[N],c[N],tmp[N],sum[N];

db P(int y,int x) {
	return (t[y]+(ll)y*(y-1)/2+sum[y]-t[x]-(ll)x*(x-1)/2-sum[x])*1.0/(y-x);
}

void Dp() {
	fo(i,1,n) sum[i]=sum[i-1]+a[i];stack[top=1]=0;
	fo(i,1,n) {
		while (top>1&&P(stack[top],stack[top-1])<=i) top--;
		int now=stack[top];
		t[i]=max(t[i-1],t[now]+(ll)(i-now)*(i-now+1)/2+sum[now]-sum[i]);
		while (top>1&&P(stack[top],stack[top-1])<P(i,stack[top])) top--;
		stack[++top]=i;
	}
}

void solve(int l,int r) {
	if (l==r) {
		h[l]=max(h[l],g[r+1]+f[l-1]+1-a[l]);
		return;
	}
	int mid=l+r>>1;
	stack[top=1]=l-1;
	fo(i,l,mid-1) {
		while (top>1&&P(stack[top],stack[top-1])<P(i,stack[top])) top--;
		stack[++top]=i;
	}
	fo(i,mid,r) {
		while (top>1&&P(stack[top],stack[top-1])<=i) top--;
		int now=stack[top];
		tmp[i]=t[now]+(ll)(i-now)*(i-now+1)/2+sum[now]-sum[i]+g[i+1];
	}
	fd(i,r-1,mid) tmp[i]=max(tmp[i],tmp[i+1]);
	fo(i,mid,r) h[i]=max(h[i],tmp[i]);
	solve(l,mid);solve(mid+1,r);
}
int main() {
	n=read();
	fo(i,1,n) a[i]=read();
	Dp();fo(i,1,n) f[i]=t[i];
	fo(i,1,n/2) swap(a[i],a[n-i+1]);
	Dp();fo(i,1,n) g[i]=t[n-i+1];
	fo(i,1,n) ans[i]=-inf;

	fo(i,1,n/2) swap(a[i],a[n-i+1]);
	fo(i,1,n) t[i]=f[i];
	fo(i,1,n) sum[i]=sum[i-1]+a[i];
	fo(i,1,n) h[i]=-inf;
	solve(1,n);
	fo(i,1,n) ans[i]=max(ans[i],h[i]);

	fo(i,1,n) swap(f[i],g[i]);
	fo(i,1,n/2) {
		swap(a[i],a[n-i+1]);
		swap(f[i],f[n-i+1]);
		swap(g[i],g[n-i+1]);
	}
	fo(i,1,n) t[i]=f[i];
	fo(i,1,n) sum[i]=sum[i-1]+a[i];
	fo(i,1,n) h[i]=-inf;
	solve(1,n);
	fo(i,1,n) ans[i]=max(ans[i],h[n-i+1]);

	fo(i,1,n/2) {
		swap(f[i],f[n-i+1]);
		swap(g[i],g[n-i+1]);
		swap(a[i],a[n-i+1]);
	}
	fo(i,1,n) swap(f[i],g[i]);

	for(m=read();m;m--) x=read(),y=read(),printf("%lld\n",max(f[x-1]+g[x+1],ans[x]+a[x]-y));
	return 0;
}

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

h,w=map(int,input().split())
s=[input() for _ in range(h)]
flag = [[0]*w for _ in range(h)]

def dfs(th,tw):
    global flag,h,w,s
    flag[th][tw] = True
    tblack = 0
    twhite = 0
    if s[th][tw] == "#":
        tblack += 1
    else:
        twhite += 1 
    for x,y in ([0,1],[0,-1],[1,0],[-1,0]):
        nth = th + x
        ntw = tw + y
        if nth >= 0 and nth < h and ntw >= 0 and ntw < w:
            if not flag[nth][ntw] and s[th][tw] != s[nth][ntw]:
                ttb,ttw = dfs(nth,ntw)
                tblack += ttb
                twhite += ttw
    return [tblack,twhite]
                
def main():
    global flag,h,w,s
    res = 0
    for i in range(h):
        for j in range(w):
            if not flag[i][j]:
                black,white = dfs(i,j)
                res += black * white 

    return res
print(main())

Measured memory_bytes: 227828
#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define srep(i,s,t) for (int i = s; i < t; ++i)
#define drep(i,n) for(int i = (n)-1; i >= 0; --i)
using namespace std;
typedef long long int ll;
typedef pair<int,int> P;
#define yn {puts("Yes");}else{puts("No");}
#define MAX_N 200005

int main() {
    int n, k;
    cin >> n >> k;
    int a[n+1];
    srep(i,1,n+1)cin >> a[i];
    int ans = 0;
    if(a[1] != 1){
        ans++; a[1] = 1;
    }

    int c[n + 1] = {};
    srep(i,1,n+1)c[a[i]]++;
    int f[n + 1] = {};
    queue<int> que;
    srep(i,2,n+1){
        if(c[i] == 0){
            f[i] = 1;
            que.push(i);
        }
    }

    while(que.size() > 0){
        int x = que.front(); que.pop();
        if(a[x] == 1)continue;
        if(f[x] == k){
            ans++;
            c[a[x]]--;
            if(c[a[x]] == 0){
                f[a[x]] = max(1, f[a[x]]);
                que.push(a[x]);
            }
            a[x] = 1;
        }else{
            f[a[x]] = max(f[a[x]], f[x]+1);
            c[a[x]]--;
            if(c[a[x]] == 0){
                f[a[x]] = max(1, f[a[x]]);
                que.push(a[x]);
            }
        }
    }

    cout << ans << endl;
    return 0;
}
 
 


Measured memory_bytes: 1792
#include <iostream>
#include <fstream> 
#include <iomanip>
#include <cstdio> 
#include <vector>
#include <string>
#include <bitset>
#include <algorithm>
#include <unordered_map>
#include <unordered_set>
#include <cmath>
#include <deque>
#include <set>
#include <map>
#include <queue>
using namespace std;
#define pb push_back
#define mp make_pair
#define forn(i, n) for (int i = 0; i < (int)(n); ++i)
typedef long long LL;
const LL INF = (1LL << 60) - 1;
const LL MOD = 1e9 + 7;
const LL N = 200005;
int dx[] = { -1, 0, 1, 0 };
int dy[] = { 0, 1, 0, -1 };

int main() {
    //freopen("input.txt", "r", stdin);
    //freopen("output.txt", "w", stdout);
    ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0), cout.precision(20), cout.setf(ios::fixed);
    int n;
    cin >> n;
    LL ans = 0;
    for (int i = 1; i < n; i++) {
        ans = ans + (n - 1) / i;
    }
    cout << ans << endl;
}

Measured memory_bytes: 3596
#include <cstdio>
#include <algorithm>
using namespace std;

int n;
long long a[100001], pf[100001];

int main(){
	scanf("%d", &n);
	for(int i=1; i<=n; i++)
		scanf("%lld", &a[i]);
		sort(a+1, a+1+n);
	for(int i=1; i<=n; i++)
		pf[i]=pf[i-1]+a[i];
	int ans=1;
	for(int i=n; i>=2; i--){
		if(a[i] <= pf[i-1]*2)
			ans++;
		else break;
	}
	printf("%d", ans);
	return 0;
}


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

int main() {
    int N, x[102], M, a, i, l;

    cin >> N;
    for(i = 1; i <= N; i++) {
        cin >> x[i];
    }
    cin >> M;
    for(l = 0; l < M; l++) {
        cin >> i;
        if(i == N) {
            if(x[i] < 2019) {
                x[i]++;
            }
        } else {
            if (x[i]+1 < x[i+1]) {
                x[i]++;
            }
        }
    }
    for(i = 1; i <= N; i++) {
        cout << x[i] << endl;
    }
    return 0;
}




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

#define pb push_back
#define mp make_pair
typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef complex<double> point;
#define xx real()
#define yy imag()

#define REP(i, a, b) for(int i = (a); i < (int)(b); i++)
#define REPN(i, a, b) for(int i = (a); i <= (int)(b); i++)
#define FA(it, x) for(__typeof((x).begin()) it = (x).begin(); it != (x).end(); it++)
#define SZ(x) (int)(x).size()
#define BE(x) (x).begin(), (x).end()
#define SORT(x) sort(BE(x))
#define _1 first
#define _2 second

#define x1 gray_cat_x1
#define y1 gray_cat_y1

template<class T> T gcd(T a, T b) { return b ? gcd(b, a % b) : a; }

mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

#define file "I1"

const double EPS = 1e-9;
const double PI = acos(-1.);
const int INF = 1e9;
const ll MOD = 1e9 + 7;

const int MAXN = 2e2 + 5;

char g[MAXN][MAXN];

void solve(){
	int n = 100;
	int a, b;
	scanf("%d%d", &a, &b);
	REP(i, 0, n / 2) {
		REP(j, 0, n) {
			g[i][j] = '.';
		}
	}
	REP(i, n / 2, n) {
		REP(j, 0, n) {
			g[i][j] = '#';
		}
	}
	int i0 = 0, j0 = 0;
	REP(k, 1, b) {
		g[i0][j0] = '#';
		j0 += 2;
		if (j0 >= n) {
			i0 += 2;
			j0 = 0;
		}
	}
	i0 = n / 2 + 1, j0 = 0;
	REP(k, 1, a) {
		g[i0][j0] = '.';
		j0 += 2;
		if (j0 >= n) {
			i0 += 2;
			j0 = 0;
		}
	}
	printf("%d %d\n", n, n);
	REP(i, 0, n) {
		printf("%s\n", g[i]);
	}
}   

int main(){

    //freopen(file".in", "r", stdin); freopen(file".out", "w", stdout);
    int t = 1;
    //cin >> t;
    while(t--){
        solve();    
    }
}


Measured memory_bytes: 256
import sys
N,A,B,C,D = map(int, input().split())
S = input()
for i in range(N-1):
  if S[i] == S[i+1] == '#':
    if A < i+1 < C or B < i+1 < D:
      print("No")
      sys.exit()
if C>D:
  for i in range(N-2):
    if S[i] == S[i+1] == S[i+2] == '.':
      if B <= i+2 <= D:
        break
    if i == N-3:
      print("No")
      sys.exit()
print("Yes")

Measured memory_bytes: 3572
#include <cstdio>
#include <cstdlib>
#include <iostream>
#include <fstream>
#include <sstream>
#include <set>
#include <map>
#include <vector>
#include <list>
#include <algorithm>
#include <cstring>
#include <cmath>
#include <string>
#include <queue>
#include <bitset>     //UWAGA - w czasie kompilacji musi byc znany rozmiar wektora - nie mozna go zmienic
#include <cassert>
#include <iomanip>        //do setprecision
#include <ctime>
#include <complex>
using namespace std;

#define FOR(i,b,e) for(int i=(b);i<(e);++i)
#define FORQ(i,b,e) for(int i=(b);i<=(e);++i)
#define FORD(i,b,e) for(int i=(b)-1;i>=(e);--i)
#define REP(x, n) for(int x = 0; x < (n); ++x)

#define ST first
#define ND second
#define PB push_back
#define MP make_pair
#define LL long long
#define ULL unsigned LL
#define LD long double

const double pi = 3.141592653589793238462643383279502884197169399375105820974944592307816406286208998628034825342;
const int mod=1000000007;

int main(){
	int n,a[200200]={},ans[200200]={},answ=0;
	cin>>n;
	FOR(i,0,n){
		cin>>a[i];
		ans[a[i]]=ans[a[i]-1]+1;
		answ=max(answ,ans[a[i]]);
	}
	cout<<n-answ<<endl;
    return 0;
}


Measured memory_bytes: 1792
//Never stop trying
#pragma GCC target ("avx2")
#pragma GCC optimization ("O3")
#pragma GCC optimization ("unroll-loops")
#include <bits/stdc++.h>
using namespace std;
#define boost ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0)

typedef string str;
typedef long long ll;
typedef double db;
typedef long double ld;
typedef pair<int, int> pi;
#define fi first
#define se second
typedef vector<int> vi;
typedef vector<pi> vpi;
typedef vector<str> vs;
typedef vector<ld> vd;
#define pb push_back
#define sz(x) (int)x.size()
#define all(x) begin(x), end(x)
#define rall(x) rbegin(x), rend(x)
#define endl "\n"

#define FOR(i,a,b) for (int i = (a); i < (b); ++i)
#define F0R(i,a) FOR(i,0,a)
#define ROF(i,a,b) for (int i = (b)-1; i >= (a); --i)
#define R0F(i,a) ROF(i,0,a)

const int MOD = 1e9 + 7; //998244353
const ll INF = 1e18;
const int MX = 2e5 + 10;
const int nx[4] = {0, 0, 1, -1}, ny[4] = {1, -1, 0, 0}; //right left down up

template<class T> using V = vector<T>;
template<class T> bool ckmin(T& a, const T& b) { return a > b ? a = b, 1 : 0; }
template<class T> bool ckmax(T& a, const T& b) { return a < b ? a = b, 1 : 0; }

ll cdiv(ll a, ll b) { return a / b + ((a ^ b) > 0 && a % b); } // divide a by b rounded up
constexpr int log2(int x) { return 31 - __builtin_clz(x); } // floor(log2(x))

#define dbg(x) cerr << " - " << #x << " : " << x << endl;
#define dbgs(x,y) cerr << " - " << #x << " : " << x << " / " << #y << " : " << y << endl;
#define dbgv(v) cerr << " - " << #v << " : " << endl << "[ "; for(auto it : v) cerr << it << ' '; cerr << ']' << endl;

void IO() {
#ifndef ONLINE_JUDGE
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#endif
}


int main() {
	boost; IO();

	int N; cin>>N;
	vi a(N),b(N); 
	FOR(i,0,N) cin>>a[i];

	multiset <int> s;
	FOR(i,0,N) cin>>b[i],s.insert(b[i]);

	vi res(N,-1);
	FOR(i,0,N){
		int x=a[i];
		auto it=s.begin();
		if(*it!=x) res[i]=(*it);
		else{
			it=s.upper_bound(x);
			if(it!=s.end()) res[i]=(*it);
		}
		if(it!=s.end()) s.erase(it);
	}


	if(!s.empty()){

		//of only one integer is remaining 
		bool y=true,p=-1;
		for(auto x: s){
			if(p!=-1 && x!=p) y=false;
			p=x;
		}
		//assert(y);


		vi v;
		int x=(*s.begin());
		FOR(i,0,N) if(res[i]!=-1 && res[i]!=x && a[i]!=x){
			v.pb(res[i]),res[i]=x;
			s.erase(s.begin());
			if(s.empty()) break;
		}
		if(!s.empty()){
			cout << "No" << endl;
				return 0;
		}

		FOR(i,0,N) if(res[i]==-1){
			if(v.empty()){
				cout << "No" << endl;
				return 0;
			}
			if( a[i]!=v.back() ) { res[i]=v.back(); v.pop_back(); }
		}	
		if(!v.empty()){cout << "No" << endl; return 0;}
	}

	cout << "Yes" << endl;
	FOR(i,0,N) cout << res[i] << ' '; cout << endl;
	

	




	return 0;
}

/* Careful!!!
	.Array bounds
	.Infinite loops
	.Uninitialized variables / empty containers
	.Order of input

   Some insights:
	.Binary search
	.Graph representation
	.Write brute force code
	.Change your approach
*/


Measured memory_bytes: 15028
#include <iostream>
#include <fstream>
#include <cstdio>
#include <cmath>
#include <vector>
#include <string>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <deque>
#include <bitset>
#include <algorithm>
#include <complex>
#include <array>
#include <functional>
using namespace std;

#define REP(i,n) for(int i=0; i<n; ++i)
#define FOR(i,a,b) for(int i=a; i<=b; ++i)
#define FORR(i,a,b) for (int i=a; i>=b; --i)
#define ALL(c) (c).begin(), (c).end()

typedef long long ll;
typedef vector<int> VI;
typedef vector<ll> VL;
typedef vector<double> VD;
typedef vector<VI> VVI;
typedef vector<VL> VVL;
typedef vector<VD> VVD;
typedef pair<int,int> P;
typedef pair<ll,ll> PL;

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

int in() { int x; scanf("%d", &x); return x; }
ll lin() { ll x; scanf("%lld", &x); return x; }

int main(void){
    int x;
    cin >> x;
    cout << 1 - x << endl;

    return 0;
}


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

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

    int ans = 0;
    for(int i = 0; i < n; i++){
        long a; cin >> a;
        do {
            if((a & 1) != 1){
                ans++;
                a >>= 1;
            } else {
                break;
            }
        } while(a > 1);
    }
    cout << ans << endl;

}

Measured memory_bytes: 384
#include <iostream>
#include <stack>      //std::stack
#include <string>
#include <stdlib.h>
using namespace std;
std::stack<int> myStack;

int calc_pop(void)
{
	int data = myStack.top();
	myStack.pop();
	return data;
}
 
int main(void)
{
    string container;
    int count = 0;			// mojisuu
 
    while(cin >> container)
    {
        count++;
    	if(count > 2)
        {
    		int data01, data02;
            if(container == "+")             //addition
            {
                data01 = calc_pop();
                data02 = calc_pop();
                myStack.push(data01+data02);
            }
            else if(container == "-")         //subtraction
            {
                data01 = calc_pop();
                data02 = calc_pop();
                myStack.push(data02-data01);
            }
            else if(container == "*")       //multiplication
            {
                data01 = calc_pop();
                data02 = calc_pop();
                myStack.push(data01*data02);
            }
            else
            {
                myStack.push(atoi(container.c_str()));
            }
        }
    	else
        {
            myStack.push(atoi(container.c_str()));
    	}
    }
    
    //result
    if(count > 2)     //2 <= count
    {
        cout << myStack.top() << endl;      //Calculation result
    }
    else
    {
        cout <<"Can not calculate!" << endl;    //not enough
    }
    return 0;
}

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

using namespace std;

int main(){
  string s;
  cin >> s;
  int a,b,c;
  a = 0; b = 0; c = 0;
  for(int i=0;i<sizeof(s);i++){
    if(s[i] == 'a') a++;
    if(s[i] == 'b') b++;
    if(s[i] == 'c') c++;
  }
  if(a==1 && b==1 && c==1) cout << "Yes" << endl;
  else cout << "No" << endl;

  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <algorithm>
#include <set>
#include <map>
#include <vector>
#include <queue>
#include <stack>
#include <math.h>
#include<bitset>
#include<stdio.h>
#include<iomanip>
using namespace std;
#define rep(i,n) for(int i=0;i<(int)(n);i++)
const int INF = 100000000;

bool isOK(int a[],int index,int key){
    if(a[index] >= key){
        return true;
    }else{
        return false;
    }
}

int binary_search(int a[],int n,int key){
    int left = -1;
    int right = n;

    while(right-left>1){
        int mid = left + (right - left)/2;
        if(isOK(a,mid,key)){
            right = mid;
        }else{
            left = mid;
        }
    }
    return right;
}

int factrial(int n){
    if(n==0){
        return 1;
    }else{
        return n*factrial(n-1);
    }
}

int main(void){
    int r,d,x;
    cin >> r >> d >>x;
    vector<int> buf(10);
    buf[0] = r*x - d;
    for(int i=1;i<10;++i){
        buf[i] = r*buf[i-1] -d;
    }
    rep(i,10){
        cout << buf[i] << endl;
    }
    return 0;
}



Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <algorithm>

using namespace std;

int main(){
    string s = "";
    long long n; cin >> n;
    if(n == 0){
        cout << 0 << endl;
        return 0;
    }
    while(n != 0) {
        int rest = n%(-2);
        if(rest == -1)
            rest = 1;
        s += to_string(rest);
        n = (n - rest)/(-2);
    }
    reverse(s.begin(), s.end());
    cout << s << endl;
}


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

int main()
{
	int X,t;
	cin >> X >> t;
	cout << max(0,X-t) << endl;
	return 0;
}

Measured memory_bytes: 256
h, n = gets.chomp.split.map(&:to_i)
dp = [0xffffffff] * (20001)
dp[0] = 0

n.times do
  a, b = gets.chomp.split.map(&:to_i)
  h.times do |i|
    x, y = a + i, b + dp[i]
    dp[x] = y if y < dp[x]
  end
end

puts dp.drop(h).min


Measured memory_bytes: 3964
#include<iostream>
using namespace std;
int main(){
	int a, b,c,count;
	count = 0;
	cin >> a >> b >> c;
	for (int x = a; x <= b; x++){
		if (c%x == 0){
			count++;
		}
	}
			cout << count << endl;
		return 0;
}

Measured memory_bytes: 3108
#include <string>
#include <vector>
#include <sstream>
#include <iostream>
#include <algorithm>
#include <map>
#include <list>
#include <set>
#include <numeric>
#include <queue>
#include <stack>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <cstring>
#include <climits>
#include <cfloat>
#include <ctime>
#include <complex>
#include <cassert>
#include <iomanip>
using namespace std;
typedef long long LL;
typedef pair<int,int> P;

int A,B;
vector<int> pop[1001];
int as[5000];
int bs[5000];
int main() {
	cin >> A >> B;
	for(int i=0;i<A;i++){
		cin >> as[i];
	}
	for(int i=0;i<B;i++){
		cin >> bs[i];
	}
	int ret=0;
	for(int i=0;i<B;i++){
		int k=0;
		int j=i;
		for(;j<B&&k<A;j++){
			bool ok=false;
			for(;k<A;k++){
				if(as[k]==bs[j]){
					ok=true;
					k++;
					break;
				}
			}
			if(!ok){
				break;
			}
		}
		ret=max(ret,j-i);
	}
	cout << ret << endl;
	return 0;
}

Measured memory_bytes: 1220
#include <iostream>
#include <algorithm>
#include <map>
using namespace std;

int main()
{
    int n;
    cin >> n;
    int a[200002];
    map<int, int> mp;
    for(int i = 0; i < n; i++){
        cin >> a[i];
        mp[a[i]]++;
    }
    sort(a, a + n);
    int p[31];
    p[0] = 1;
    int ans = 0;
    for(int i = 1; i < 31; i++) p[i] = p[i - 1] * 2;
    for(int i = n - 1; i >= 0; i--){
        if(mp[a[i]]){
            mp[a[i]]--;
            int b = *upper_bound(p, p + 31, a[i]);
            if(mp[b - a[i]]){
                mp[b - a[i]]--;
                ans++;
            }
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 19712
#include <bits/stdc++.h>
#define FOR(i, a, b) for(int i = a; i < b; i++)
#define REP(i, n) FOR(i, 0, n)
#define INF 999999999
typedef long long ll;
using namespace std;
int main() {
    string s, t;
    cin >> s >> t;
    sort(s.begin(), s.end());
    sort(t.begin(), t.end(), greater<char>());
    if(s < t) {
        cout << "Yes" << endl;
    }else {
        cout << "No" << endl;
    }
}

Measured memory_bytes: 256
a, b = map(int, input().split())

def gcd(a, b):
    if a == 0:
        return b
    if b == 0:
        return a
    if a > b:
        return gcd(a%b, b)
    else:
        return gcd(b%a, a)

print(int(a * b / gcd(a, b)))

Measured memory_bytes: 38256
#include <stdio.h>
#include <string.h>
#include <ctype.h>

int main() {
	char card[205] = { 0 };
	char copy_card[205] = { 0 };
	int m;
	int h;
	int i, j;
	int length;

	while (1) {
		for (j = 0; j < sizeof(card); j++) { //cardを初期化
			card[j] = '\0';
		}
		scanf("%s", card);
		
		if (strcmp(card, "-") == 0) {
			break;
		}

		for (length = 0; card[length] != '\0' ; length++);

		scanf("%d", &m);

		for (i = 0; i < m ;i++) {
			scanf("%d", &h);

			for (j = 0; j < sizeof(copy_card); j++) { //copy_cardを初期化
				copy_card[j] = '\0';
			}
			memcpy(copy_card, card, h);

			for (j = h; j < length + 1;j++) {
				card[j - h] = card[j];
			}
			for (j = 0; j < h; j++) {
				card[length - j] = '\0';
			}
			strcat(card, copy_card);
		}

		printf("%s\n" ,card);

	}

	return 0;
}


Measured memory_bytes: 2104
from collections import deque

def bfs(x, graph, people):
    if people[x] is not None:
        return
    unvisited = deque([x])
    people[x] = 0
    while unvisited:
        now = unvisited.popleft()
        for next, d in graph[now]:
            if people[next] is None:
                people[next] =  people[now] + d
                unvisited.append(next)

def main():
    N, M = list(map(int, input().split()))

    graph = [ [] for n in range(N+1)]
    people = [None] * (N+1)

    for n in range(M):
        L, R, D = list(map(int, input().split()))
        graph[L].append((R, D))
        graph[R].append((L, -D))
    for i in range(1, N+1):
        bfs(i, graph, people)

    for i in range(1, N+1):
        for j, d in graph[i]:
            if people[j] - people[i] != d:
                print("No")
                exit()
    else:
        print("Yes")


if __name__ == "__main__":
    main()


Measured memory_bytes: 69652
$H, $W = gets.split.map(&:to_i)
$ss = []
$H.times do |i|
    $ss[i] = gets.chomp.split('')
end

def mines(h, w)
    sum = 0
    (h-1..h+1).each do |hi|
        next if hi < 0 || hi > $H - 1
        (w-1..w+1).each do |wi|
            next if wi < 0 || wi > $W - 1
            sum += 1 if $ss[hi][wi] == '#'
        end
    end
    return sum
end

$H.times do |h|
    $W.times do |w|
        print $ss[h][w] == '#' ? '#' : mines(h, w)
    end
    print "\n"
end

Measured memory_bytes: 2172
#include<stdio.h>

int main(){
  int i,pCount=0;
  char s[100001];

  scanf("%s",s);
  for(i=1;s[i]!='\0';++i){
    if(s[i]=='p') ++pCount;
  }
  i=i/2;
  printf("%d\n",i-pCount);

  return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <string>
#include <queue>
#include <vector>
#include <set>
#include <map>
#include <bitset>
#include <cmath>
using namespace std;
typedef long int li;
typedef long long int lli;
const int INF = 0xfffffff;

int main() {
	int a, b, c;
	cin >> a >> b >> c;
	int x = a * 10 + b + c, y = a + b * 10 + c, z = a + b + c * 10;
	cout << max(x, max(y, z)) << endl;
}

Measured memory_bytes: 256
#pragma target("avx")
#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef long double ld;
typedef pair<ll, ll> P;
typedef vector<ll> V;
typedef unordered_map<ll, ll> U_MAP;
typedef priority_queue<ll> pq;
typedef priority_queue<ll, vector<ll>, greater<ll>> rpq;
constexpr ll INF = 1e9, MOD = 1e9 + 7, ohara = 1e6 + 10;
constexpr ll LINF = 1e18;

#define rep(i, n) for (ll(i) = 0; (i) < (int)(n); (i)++)
#define rrep(i, a, b) for (ll i = (a); i < (b); i++)
#define rrrep(i, a, b) for (ll i = (a); i >= (b); i--)
#define all(v) (v).begin(), (v).end()
#define Size(n) (n).size()
#define Cout(x) cout << (x) << endl
#define doublecout(a) cout << fixed << setprecision(15) << a << endl;
#define fi first
#define se second
#define m_p make_pair
#define p_b push_back
string to_string(string s) { return '"' + s + '"'; }
string to_string(const char* s) { return to_string((string)s); }
string to_string(bool b) { return (b ? "true" : "false"); }
template <typename A, typename B>
string to_string(pair<A, B> p) {
  return "(" + to_string(p.first) + ", " + to_string(p.second) + ")";
}
template <typename A>
string to_string(A v) {
  bool first = true;
  string res = "{";
  for (const auto& x : v) {
    if (!first) {
      res += ", ";
    }
    first = false;
    res += to_string(x);
  }
  res += "}";
  return res;
}
void debug_out() { cerr << endl; }
template <typename Head, typename... Tail>
void debug_out(Head H, Tail... T) {
  cerr << " " << to_string(H);
  debug_out(T...);
}
#define debug(...) cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)

//------ Believe yourself as a genius!!!!!! ------

int dy[] = {1, 0, -1, 0};
int dx[] = {0, 1, 0, -1};
// int dy[]={-1,0,1,-1,1,-1,0,1};int dx[]={-1,-1,-1,0,0,1,1,1};
string alph("abcdefghijklmnopqrstuvwxyz"), s;
ll n, cnt, ans, a, b, c, d, tmp, m, h, w, x, y, sum, k, q;

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

  cin >> x;
  if (x >= 30)
    Cout("Yes");
  else
    Cout("No");
  return 0;
}

Measured memory_bytes: 3652
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<ctime>
#include<iostream>
#include<algorithm>
#include<vector>
#include<string>
#include<map>
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
const int MAXN = 2e5 + 5;

struct Hash
{
	ll mod, base;
	vector<ll> pwb,val;
	
	Hash(ll base = 0): mod(1e9), base(base) {}
	inline void set_base(ll base_){ mod=1e9; base=base_;}
	
	void set_hash(const string &s)
	{
		val.resize(s.size()); pwb.resize(s.size());
		pwb[0] = 1;
		for(int i=1; i<(int)val.size(); ++i)
			val[i] = (val[i-1] * base + s[i]) %mod,
			pwb[i] = pwb[i-1] * base %mod;
	}
	
	inline ll get_seg(int l,int r){ return (val[r] - val[l-1] * pwb[r-l+1] %mod + mod) %mod;}
	
	inline bool eq(int l1,int r1,int l2,int r2){ return get_seg(l1,r1) == get_seg(l2,r2);}
	inline bool eq(const pii &p,const pii &q){ return get_seg(p.first,p.second) == get_seg(q.first,q.second);}
};

struct Double_Hash
{
	Hash h1,h2;
	Double_Hash(ll base1=0, ll base2=0): h1(base1), h2(base2) {}
	inline void set_base(ll base1,ll base2){ h1.set_base(base1); h2.set_base(base2);}
	
	void set_hash(const string &s){ h1.set_hash(s); h2.set_hash(s);}
	
	inline pii get_seg(int l,int r){ return make_pair(h1.get_seg(l,r), h2.get_seg(l,r));}
	
	inline bool eq(int l1,int r1,int l2,int r2){ return h1.eq(l1,r1,l2,r2) && h2.eq(l1,r1,l2,r2);}
	inline bool eq(const pii &p,const pii &q){ return h1.eq(p,q) && h2.eq(p,q);}
};

string s[MAXN];
Double_Hash h[MAXN];

map<pii, vector<char> > t;

int cnt1[30];

int main(void)
{
	srand(time(0));
	
	int n;
	scanf("%d",&n);
	for(int i=1; i<=n; ++i)
	{
		cin>>s[i];
		s[i] = '\0' + s[i];
	}
	
	ll base1 = rand() + 1919810;
	ll base2 = rand() + 114514;
	
	for(int i=1; i<=n; ++i)
	{
		if((int)s[i].size()-1 == 1)
		{
			++cnt1[s[i][1] - 'a'];
			continue;
		}
		
		h[i].set_base(base1, base2);
		h[i].set_hash(s[i]);
		
		t[ h[i].get_seg(2, (int)s[i].size()-1) ].push_back(s[i][1]);
	}
	
	int ans = 0;
	for(int k=1; k<=n; ++k) if((int)s[k].size()-1 > 1)
	{
		string &s = ::s[k];
		
		static int cnt[30];
		memset(cnt,0,sizeof(cnt));
		for(int i=1; i<(int)s.size(); ++i) ++cnt[s[i]-'a'];
		
		for(int i=0; i<26; ++i)
			if(cnt[i] && cnt1[i]) ++ans;
		
		for(int i=(int)s.size()-1; i>2; --i)
		{
			--cnt[s[i]-'a'];
			vector<char> &res = t[ h[k].get_seg(i, (int)s.size()-1) ];
			
			for(int j=0; j<(int)res.size(); ++j)
				if(cnt[res[j] - 'a']) ++ans;
		}
	}
	printf("%d",ans);
	return 0;
}

Measured memory_bytes: 145196
#include<bits/stdc++.h>
#include<iostream>
using namespace std;
int main()
{
int n;
cin>>n;
vector<int> v;
for(int i=0;i<n;i++)
{   int x;
    cin>>x;
    v.push_back(x);

}
vector<int> dp(n,0);
for(int i=n-2;i>=0;i--)
{   int op2=INT_MAX;
    int op1=dp[i+1]+abs(v[i]-v[i+1]);
    if(i+2<n)
    {

        op2=dp[i+2]+abs(v[i]-v[i+2]);
    }
        dp[i]=min(op1,op2);

}
cout<<dp[0];
    return 0;
}


Measured memory_bytes: 3924
// Aizu Vol-1 0185: Goldbach's Conjecture II
// 2017.8.3

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

char *gets(char *);

#define MAX  1000000
#define SQRT 1000     // sqrt(MAX)

char prime[MAX + 5];
char buf[100];

void putInt(int n)
{
	char s[22], *p;

	p = s + 20, *p = 0;
	while (n) *--p = (n % 10) + '0', n /= 10;
	puts(p);
}

int main()
{
	int i, n, cnt;
	char *p1, *p2, *pmax;

	memset(prime, 1, MAX), prime[1] = 0;
	pmax = prime + MAX;
	for (p1 = prime + 3, i = 3; i <= SQRT; p1 += 2, i += 2) {
		if (*p1) {
			for (p2 = p1 + i; p2 <= pmax; p2 += i) *p2 = 0;
		}
	}

	while (1) {
		gets(buf);
		if (!(n = atoi(buf))) break;
		i = n >> 1;
		p1 = p2 = prime + i;
		if (!(i & 1)) i--, p1--, p2++;
		for (cnt = 0; i > 0; i -= 2, p1 -= 2, p2 += 2) {
			if (*p1 && *p2) cnt++;
		}
		putInt(cnt);
	}
	return 0;
}

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

int a[200000];

int main (void) {
  int n;
  cin >> n;
  for (int i = 0; i < n; i++) {
    cin >> a[i];
  }
  int ans = 0;
  for (int i = 0; i < n - 1; i++) {
    if (a[i] == i + 1) {
      swap(a[i], a[i + 1]);
      ans++;
    }
  }
  if (a[n - 1] == n) {
    ans++;
  }
  cout << ans << endl;
  return 0;
}


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

int main() {
    int n;
    cin >> n;
    vector<string> w(n);
    for(int i=0;i<n;i++){
        cin >> w.at(i);
    }
    bool shi=1;
    string s,t;
    for(int i=0;i<n-1;i++){
        s=w.at(i);
        t=w.at(i+1);
        if(s.at(s.size()-1)!=t.at(0)){
            shi=0;
        }
    }
    sort(w.begin(),w.end());
    for(int i=0;i<n-1;i++){
        if(w.at(i)==w.at(i+1)){
            shi=0;
        }
    }
    if(shi){
        cout << "Yes";
    }
    else{
        cout << "No";
    }
}

Measured memory_bytes: 256
#!/usr/bin/env python3
# DSL_5_A: The Maximum Number of Customers


def run():
    n, t = [int(i) for i in input().split()]
    sch = [0] * (t+1)

    for _ in range(n):
        enter, leave = [int(i) for i in input().split()]
        sch[enter] += 1
        sch[leave] -= 1

    c = 0
    maxc = 0
    for i in sch:
        c += i
        if c >= maxc:
            maxc = c

    print(maxc)


if __name__ == '__main__':
    run()



Measured memory_bytes: 6244
#!/usr/bin/env python3
import itertools

N, K = list(map(int, input().split()))
s_list = []

for _ in range(K):
    _ = input()
    a_list = list(map(int, input().split()))
    s_list.append(a_list)

s_list = set(itertools.chain.from_iterable(s_list))
ans = N - len(s_list)

print(ans)


Measured memory_bytes: 9088