akhauriyash/Code-Regression huggingface dataset:
// atcoder/abc159/F/main.cpp
// author: @___Johniel
// github: https://github.com/johniel/

#include <bits/stdc++.h>

#define each(i, c) for (auto& i : c)
#define unless(cond) if (!(cond))

using namespace std;

template<typename P, typename Q> ostream& operator << (ostream& os, pair<P, Q> p) { os << "(" << p.first << "," << p.second << ")"; return os; }
template<typename P, typename Q> istream& operator >> (istream& is, pair<P, Q>& p) { is >> p.first >> p.second; return is; }
template<typename T> ostream& operator << (ostream& os, vector<T> v) { os << "("; for (auto& i: v) os << i << ","; os << ")"; return os; }
template<typename T> istream& operator >> (istream& is, vector<T>& v) { for (auto& i: v) is >> i; return is; }
template<typename T> ostream& operator << (ostream& os, set<T> s) { os << "#{"; for (auto& i: s) os << i << ","; os << "}"; return os; }
template<typename K, typename V> ostream& operator << (ostream& os, map<K, V> m) { os << "{"; for (auto& i: m) os << i << ","; os << "}"; return os; }

template<typename T> inline T setmax(T& a, T b) { return a = std::max(a, b); }
template<typename T> inline T setmin(T& a, T b) { return a = std::min(a, b); }

using lli = long long int;
using ull = unsigned long long;
using point = complex<double>;
using str = string;
template<typename T> using vec = vector<T>;

constexpr array<int, 8> di({0, 1, -1, 0, 1, -1, 1, -1});
constexpr array<int, 8> dj({1, 0, 0, -1, 1, -1, -1, 1});
constexpr lli mod = 998244353;

int main(int argc, char *argv[])
{
  std::ios_base::sync_with_stdio(0);
  std::cin.tie(0);
  std::cout.setf(std::ios_base::fixed);
  std::cout.precision(15);

  int n, s;
  while (cin >> n >> s) {
    vec<lli> a(n);
    cin >> a;

    const int N = 3000 + 5;
    static lli dp[N][N][3];
    fill(&dp[0][0][0], &dp[N - 1][N - 1][3 - 1] + 1, 0);
    dp[0][0][0] = 1;

    for (int i = 0; i < a.size(); ++i) {
      for (int j = 0; j < N; ++j) {
        if (j + a[i] <= s) {
          (dp[i + 1][j + a[i]][1] += dp[i][j][0]) %= mod;
          (dp[i + 1][j + a[i]][1] += dp[i][j][1]) %= mod;
          (dp[i + 1][j + a[i]][2] += dp[i][j][0]) %= mod;
          (dp[i + 1][j + a[i]][2] += dp[i][j][1]) %= mod;
        }
        (dp[i + 1][j][0] += dp[i][j][0]) %= mod;
        (dp[i + 1][j][1] += dp[i][j][0]) %= mod;
        (dp[i + 1][j][1] += dp[i][j][1]) %= mod;
        (dp[i + 1][j][2] += dp[i][j][0]) %= mod;
        (dp[i + 1][j][2] += dp[i][j][1]) %= mod;
        (dp[i + 1][j][2] += dp[i][j][2]) %= mod;
      }
    }

    cout << dp[a.size()][s][2] << endl;
  }

  return 0;
}


Measured memory_bytes: 211968
def main():
    n = int(input())
    s = input()
    ans = ""
    for i in range(len(s)):
        suuji = ord(s[i])
        tsugi = suuji + n
        if tsugi > 65+25:
            tsugi -= 26
        ans += chr(tsugi)
    print(ans)


    
    
if __name__ == "__main__":
    main()


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

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

using namespace std;

typedef long long ll;

#define REP(i, n) for (int i = 0; i < int(n); i++)
#define REPD(i, n) for (int i = n - 1; i >= 0; i--)
#define FOR(i, a, b) for (int i = a; i < int(b); i++)
#define FORD(i, a, b) for (int i = b - 1; i >= int(a); i--)
#define WRAP(y, x, h, w) (0 <= y && y < h && 0 <= x && x < w)

#define ALL(x) (x).begin(), (x).end()

int gcd(int a, int b)
{
    return b ? gcd(b, a % b) : a;
}
int dx[4] ={ 1, 0, -1, 0 };
int dy[4] ={ 0, 1, 0, -1 };

int main()
{
    ll a;
    double b;
    cin>>a>>b;
    b+=0.0001;
    ll c=(ll)(b*100);
    cout<<a*c/100<<endl;
    
}

Measured memory_bytes: 3704
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <queue>

using namespace std;

vector< vector< int > > grid_bfs(vector< string > &s, char start, const string &wall = "#") {
    const int vx[] = {0, 1, 0, -1}, vy[] = {1, 0, -1, 0};
    vector< vector< int > > min_cost(s.size(), vector< int >(s[0].size(), -1));
    queue< pair< int, int > > que;
    for(int i = 0; i < s.size(); i++) {
        for(int j = 0; j < s[i].size(); j++) {
        if(s[i][j] == start) {
            que.emplace(i, j);
            min_cost[i][j] = 0;
        }
        }
    }
    while(!que.empty()) {
        auto p = que.front();
        que.pop();
        for(int i = 0; i < 4; i++) {
        int ny = p.first + vy[i], nx = p.second + vx[i];
        if(nx < 0 || ny < 0 || nx >= s[0].size() || ny >= s.size()) continue;
        if(min_cost[ny][nx] != -1) continue;
        if(wall.find(s[ny][nx]) != string::npos) continue;
        min_cost[ny][nx] = min_cost[p.first][p.second] + 1;
        que.emplace(ny, nx);
        }
    }
    return min_cost;
}

int main(void) {
    int H, W;
    cin >> H >> W;
    vector<string> grid(H);
    for(int i=0; i<H; i++) {
        cin >> grid[i];
    }

    int ans = 0;
    for(int i=0; i<H; i++) {
        for(int j=0; j<W; j++) {
            if(grid[i][j] == '.') {
                grid[i][j] ='s';
                auto tmp = grid_bfs(grid, 's');
                for(int k=0; k<H; k++) {
                    ans = max(ans, *max_element(tmp[k].begin(), tmp[k].end()));
                }
                grid[i][j] = '.';
            }
        }
    }

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


Measured memory_bytes: 256
// Frog 2 https://atcoder.jp/contests/dp/tasks/dp_b
#include <bits/stdc++.h>
using namespace std;

const int INF = 1e9 + 5;

int n, k;
vector<int> h;
vector<int> memo;
vector<bool> computed;

// rec(x) is best score to get to position x
int rec(int pos) {
	if(pos == 0) {
		return 0;
	}
	if(computed[pos]) {
		return memo[pos];
	}
	int best = INF;
	for(int jump = 1; jump <= k && pos - jump >= 0; ++jump) {
		best = min(best, rec(pos - jump) + abs(h[pos] - h[pos-jump]));
	}
	computed[pos] = true;
	return memo[pos] = best;
}

int solve1() {
	return rec(n-1);
}

int solve2() { // pull dp
	vector<int> dp(n);
	for(int i = 1; i < n; i++) {
		dp[i] = INF; // and now compute dp[i]
		for(int jump = 1; jump <= k && i - jump >= 0; ++jump) {
			dp[i] = min(dp[i], dp[i-jump] + abs(h[i]-h[i-jump]));
		}
	}
	return dp[n-1];
}

void min_self(int& a, int b) {
	a = min(a, b);
}

int solve3() { // push dp
	vector<int> dp(n, INF);
	dp[0] = 0;
	for(int i = 0; i <= n - 2; ++i) {
		for(int jump = 1; jump <= k && i + jump < n; ++jump) {
			min_self(dp[i+jump], dp[i] + abs(h[i]-h[i+jump]));
		}
	}
	return dp[n-1];
}

const int B = 16 * 1024; // greater than 10,000
struct Tree {
	vector<int> a;
	vector<multiset<int>> values_in_leaves;
	void init() {
		a.resize(2*B, INF);
		values_in_leaves.resize(B);
		for(int i = 0; i < B; ++i) {
			values_in_leaves[i].insert(INF);
		}
	}
	int query_min(int L, int R) {
		if(L > R) {
			return INF;
		}
		L += B;
		R += B;
		int x = min(a[L], a[R]);
		while(L + 1 < R) {
			min_self(x, a[L+1]);
			min_self(x, a[R-1]);
			L /= 2;
			R /= 2;
		}
		return x;
	}
	void insert(int i, int value) {
		values_in_leaves[i].insert(value);
		a[i+B] = *values_in_leaves[i].begin();
		for(int j = (i + B) / 2; j >= 1; j /= 2) {
			a[j] = min(a[2*j], a[2*j+1]);
		}
	}
	void erase(int i, int value) {
		values_in_leaves[i].erase(values_in_leaves[i].find(value));
		a[i+B] = *values_in_leaves[i].begin();
		for(int j = (i + B) / 2; j >= 1; j /= 2) {
			a[j] = min(a[2*j], a[2*j+1]);
		}
	}
};
Tree sum, diff;

void insert(int i, const vector<int>& dp) {
	sum.insert(i, dp[i] + h[i]);
	diff.insert(i, dp[i] - h[i]);
}
void erase(int i, const vector<int>& dp) {
	sum.erase(i, dp[i] + h[i]);
	diff.erase(i, dp[i] - h[i]);
}

int solve4() { // pull dp with segment trees
	vector<int> dp(n);
	
	// O(N * log(H))
	for(int i = 1; i < n; ++i) {
		insert(i-1, dp);
		erase(i-k-1, dp);
		// [i-k, i-1]
		dp[i] = INF;
		
		min_self(dp[i], diff.query_min(0, h[i]-1) + h[i]);
		min_self(dp[i], sum.query_min(h[i]+1, 10 * 1000) - h[i]);
	}
	return dp[n-1];
}

int main() {
	sum.init();
	diff.init();
	cin >> n >> k;
	h.resize(n);
	memo.resize(n, 0);
	computed.resize(n, false);
	for(int& x : h) {
		cin >> x;
	}
	cout << solve3();
}


Measured memory_bytes: 4736
#include <algorithm>
#include <bitset>
#include <cctype>
#include <cmath>
#include <cstdlib>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <set>
#include <string>
#include <utility>
#include <vector>
#define REP(i, n) for(int i = 0; i < (n); ++i)
typedef long long ll;
const ll MOD = 1000000007;
using namespace std;

int main(){
    int n, minD = 10000; cin >> n;
    string s; cin >> s;
    vector<int> d(n+1); //i文字目(s[i-1])までの(の数 - )の数
    d[0] = 0;
    REP(i, n){
        d[i+1] = d[i] + (s[i]=='(' ? 1 : -1);
        minD = min(d[i+1], minD);
    }
    REP(i, -minD) cout << "(";
    cout << s;
    REP(i, (minD>=1 ? d[n] : d[n]-minD)) cout << ")";
    cout << "\n";
    return 0;
}

Measured memory_bytes: 256
var GET=(function(){function f(s){return new g(s);}function g(s){this._s=s.trim().split("\n");this._y=0;}g.prototype.a=function(f){var s=this._s, y=this._y, r;if(typeof s[y]==="string")s[y]=s[y].split(" ").reverse();r=s[y].pop();if(!s[y].length)this._y++;return f?r:+r;};g.prototype.l=function(f){var s=this._s[this._y++].split(" ");return f?s:s.map(a=>+a);};g.prototype.m=function(n,f){var r=this._s.slice(this._y,this._y+=n).map(a=>a.split(" "));return f?r:r.map(a=>a.map(a=>+a));};g.prototype.r=function(n,f){var r=this._s.slice(this._y,this._y+=n);return f?r:r.map(a=>+a);};return f;})();
var o=GET(require("fs").readFileSync("/dev/stdin","utf8"));
function xArray(v){var a=arguments,l=a.length,r="Array(a["+--l+"]).fill(0).map(x=>{return "+v+";})";while(--l)r="Array(a["+l+"]).fill(0).map(x=>"+r+")";return eval(r);}
var n,x=[];

console.log(main());
function main(){
  n = o.a();
  for(var i = 0; i < n; i++){
    var a = o.a(), b = o.a();
    if(a === 0 && b === 0)continue;
    x.push([a,b,f(a,b)]);
  }
  n = x.length;
  x.sort((a,b)=>a[2]-b[2]);
  x = x.concat(x);
  var ans = 0;
  var tx = 0, ty = 0, k = 0;
  for(var i = 0; i < n; i++){
    while(k < i+n){
      var ux = tx+x[k][0];
      var uy = ty+x[k][1];
      if(tx*tx+ty*ty >= ux*ux+uy*uy)break;
      tx = ux, ty = uy;
      k++;
    }
    var u = tx*tx+ty*ty;
    if(ans < u)ans = u;
    tx -= x[i][0], ty -= x[i][1];
  }
  return Math.sqrt(ans);
}

function f(a,b){
  if(a === 0){
    return b > 0 ? 90 : 270;
  }
  if(b === 0){
    return a > 0 ? 0 : 180;
  }
  var r = Math.atan(b/a)/Math.PI*180;
  if(a < 0)r += 180;
  if(r < 0)r += 360;
  return Math.round(r*1e7)/1e7;
}

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

struct data {
  long long x, y;
};
long long k, x, y;
bool minusx = 0, minusy = 0, swapped = 0;
vector<data> ans;

void solve();

int main() {
  cin >> k >> x >> y;
  solve();
  if(ans.size() == 0)
    cout << -1 << endl;
  else {
    cout << ans.size() << endl;
    x = y = 0;
    for(int i = 0; i < ans.size(); ++i) {
      x += ans[i].x - 2 * ans[i].x * minusx;
      y += ans[i].y - 2 * ans[i].y * minusy;
      if(!swapped)
        cout << x << " " << y << endl;
      else
        cout << y << " " << x << endl;
    }
  }
  return 0;
}

void solve() {
  if(x < 0) {
    x *= -1;
    minusx = 1;
  }
  if(y < 0) {
    y *= -1;
    minusy = 1;
  }
  if(x < y) {
    swap(x, y);
    swap(minusx, minusy);
    swapped = 1;
  }
  if(x + y == k) {
    ans.push_back({x, y});
    return;
  }
  long long n, a;
  a = (k - (x + y) % k) % k;
  if(a % 2) {
    if(k % 2)
      a += k;
    else
      return;
  }
  n = (x + y + a) / k;
  a /= 2;
  if(n == 1) {
    if((x + y) % 2 == 0) {
      long long i = (x + y) / 2;
      ans.push_back({i, -(k - i)});
      ans.push_back({x - i, y + (k - i)});
      return;
    }
    ans.push_back({-k, 0});
    x += k;
  }
  ans.push_back({k - a, -a});
  y += a;
  x -= k - a;
  while(x || y) {
    long long nowx = min(k, x);
    ans.push_back({nowx, k - nowx});
    x -= nowx;
    y -= k - nowx;
  }
}

Measured memory_bytes: 5484
#!/usr/bin/env python3
import sys


def solve(N: int, K: int):
    ans = 1
    for _ in range(N):
        ans = min(ans * 2, ans + K)
    print(ans)


def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    K = int(next(tokens))  # type: int
    solve(N, K)


if __name__ == '__main__':
    main()


Measured memory_bytes: 3060
#include <bits/stdc++.h>
using namespace std ;
#define INF (1<<29)
int N ,M , R ;
int d [201][201];
int r [9];
int A ,B , C ;
int res ;
bool used [9];

void dfs ( int c , int las , int dist )
{
    if ( c == R +1)
    {
        if ( res > dist ) res = dist ;
        return ;
    }
    for ( int i =1; i <= R ; i ++) if (! used [ i ])
        {
            used [ i ]= true ;
            if ( las == -1) dfs ( c +1 ,i ,0);
            else dfs ( c +1 ,i , dist + d [ r [ las ]][ r [ i ]]);
            used [ i ]= false ;
        }
}
int main ()
{
    scanf ("%d %d %d" ,&N ,& M ,& R );
    for ( int i =1; i <= N ; i ++) for ( int j =1; j <= N ; j ++) if ( i != j ) d [ i ][ j ]= INF ;
    for ( int i =1; i <= R ; i ++) scanf ( " %d " ,& r [ i ]);
    for ( int i =1; i <= M ; i ++)
    {
        scanf ( " %d %d %d" ,&A ,& B ,& C );
        if ( d [ A ][ B ] > C ) d [ A ][ B ]= d [ B ][ A ]= C ;
    }
    for ( int k =1; k <= N ; k ++)
        for ( int i =1; i <= N ; i ++)
            for ( int j =1; j <= N ; j ++)
                if ( d [ i ][ j ] > d [ i ][ k ]+ d [ k ][ j ])
                    d[ i ][ j ]= d [ i ][ k ]+ d [ k ][ j ];
    res = INF ;
    dfs (1 , -1 ,0);
    printf ("%d\n" , res );
}


Measured memory_bytes: 384
#include <bits/stdc++.h>
#include <stdlib.h>
using namespace std;
typedef long long ll;
typedef vector<ll> vec;
typedef vector<vec> mat;
const ll mod=1000000007;
const ll INF=1e15;
#define REP(i,a,b) for(ll i=a;i<b;i++)
#define rep(i,n) REP(i,0,n)
#define ALL(a)  (a).begin(),(a).end()
#define U_ERASE(V) V.erase(unique(ALL(V)), V.end())
#define pb push_back
#define mp make_pair
#define MODP(A,B) A=(A+B)%mod
typedef pair<ll,ll> P;
typedef pair<double,double> Pd;
vec dx={1,0,-1,0};
vec dy={0,1,0,-1};

ll ans[2001];


int main(){
    ll N,X,Y; cin>>N>>X>>Y;
    X--; Y--;
    
    
    rep(i,N-1) REP(j,i,N){
        if(i<X){
            if(j<=(X+Y+1)/2) ans[j-i]++;
            else if(j<=Y) ans[Y-j+X+1-i]++;
            else ans[j-Y+X+1-i]++;
        }

        else if(i<=Y){
            ll D=i-X+1;
            ll DD=abs(j-Y);
            ll K=min(DD+D,j-i);
            ans[K]++;
        }

        else ans[j-i]++;
    }
    REP(i,1,N) cout<<ans[i]<<endl;

}

Measured memory_bytes: 256
#include <algorithm>
#include <climits>
#include <cmath>
#include <iostream>
#include <numeric>
#include <unordered_map>
#include <vector>

const int mod = 1e9 + 7;

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

    std::vector<long long> a(n);
    for (int i = 0; i < n; i++) {
        std::cin >> a[i];
    }

    std::vector<long long> b(n);
    for (int i = 0; i < n; i++) {
        std::cin >> b[i];
    }

    long long s = 0, t = 0;

    for (int i = 0; i < n; i++) {
        if (a[i] > b[i]) {
            s += a[i] - b[i];
        } else {
            t += (b[i] - a[i]) / 2;
        }
    }

    std::cout << (s <= t ? "Yes" : "No") << std::endl;
}


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

int root(vector<int> &parent, int idx) { 
  if (parent[idx] < 0)
    return idx;
  return parent[idx] = root(parent, parent[idx]);
}

long long N, M;
int main() { 
  cin >> N >> M;
  vector<int> parent(N, -1);
  for (int i = 0; i < M; ++i) {
    int A, B;
    cin >> A >> B;
    int root_a = root(parent, --A);
    int root_b = root(parent, --B);
    if (root_a != root_b) {
      parent[root_a] += parent[root_b];
      parent[root_b] = root_a;
    }
  }
  int result = 0;
  for (int i = 0; i < N; ++i) {
    result = max(result, -parent[i]);
  }
  cout << result << endl;
}


Measured memory_bytes: 4056
#include <iostream>
#include <sstream>
#include <algorithm>
#include <string>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <stack>
#include <memory>
#include <complex>
#include <numeric>
#include <cstdio>
#include <iomanip>

#define REP(i,m,n) for(int i=int(m);i<int(n);i++)
#define RREP(i,m,n) for(int i=int(n)-1;i>=int(m);--i)
#define EACH(i,c) for (auto &(i): c)
#define all(c) begin(c),end(c)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort(begin(c),end(c))
#define pb emplace_back
#define MP make_pair
#define SZ(a) int((a).size())

#ifdef LOCAL
#define DEBUG(s) cout << (s) << endl
#define dump(x)  cerr << #x << " = " << (x) << endl
#define BR cout << endl;
#else
#define DEBUG(s) do{}while(0)
#define dump(x) do{}while(0)
#define BR 
#endif
using namespace std;

using UI = unsigned int;
using UL = unsigned long;
using LL = long long int;
using ULL = unsigned long long;
using VI = vector<int>;
using VVI = vector<VI>;
using VLL = vector<LL>;
using VS = vector<string>;
using PII = pair<int,int>;
using VP = vector<PII>;

//struct edge {int from, to, cost;};

constexpr double EPS = 1e-10;
//constexpr double PI  = acos(-1.0);
//constexpr int INF = INT_MAX;
constexpr int MOD = 1'000'000'007;
//inline void modAdd(LL &l, LL &r) {l = (l + r) % MOD;}

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

void solve() {
    int t,x;
    cin >> t >> x;
    cout << 1.0 * t / x << endl;

}

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

Measured memory_bytes: 764
#include<bits/stdc++.h>
#define god dimasi5eks
#pragma GCC optimize("O3")
#define fi first
#define se second
#define pb push_back
#define pf push_front
#define mod 1000000007
#define dancila 3.14159265359
#define eps 1e-9

// #define fisier 1

using namespace std;

typedef long long ll;

int n, v[200002];
deque<pair<int, int> >d;
bool chk(int mx)
{
    d.clear();
    for(int i = 1; i <= n; ++i)
    {
        if(v[i] > v[i-1])
            d.pb({v[i] - v[i-1], 1});
        else
        {
            int sum = v[i-1];
            while(sum >= v[i])
            {
                pair<int, int> x = d.back();
                if(sum - x.fi >= v[i])
                {
                    sum -= x.fi;
                    d.pop_back();
                }
                else
                {
                    int dif = sum - v[i];
                    x.fi -= dif;
                    d.pop_back();
                    if(x.fi)
                        d.pb(x);
                    sum = v[i];
                    break;
                }
            }
            while(!d.empty())
            {
                pair<int, int> x = d.back();
                if(x.se == mx)
                {
                    sum -= x.fi;
                    d.pop_back();
                }
                else
                {
                    --x.fi;
                    d.pop_back();
                    if(x.fi)
                        d.pb(x);
                    d.pb({1, x.se + 1});
                    if(v[i] - sum)
                        d.pb({v[i] - sum, 1});
                    break;
                }
            }
            if(d.empty())
                return 0;
        }
    }
    return 1;
}
int main()
{

   // ifstream cin("a.in");
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);

    cin >> n;
    for(int i = 1; i <= n; ++i)
        cin >> v[i];
    int st = 1;
    int dr = n;
    int ans = n;
    while(st <= dr)
    {
        int mid = (st + dr) / 2;
        if(chk(mid))
            ans = mid, dr = mid - 1;
        else
            st = mid + 1;
    }
    cout << ans;
    return 0;
}


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

typedef long long ll;
typedef unsigned long long ull;

int main() {
  ll a, b;
  cin >> a >> b;
  if (a <= 5) {
    cout << 0 << endl;
  } else if (a >= 13) {
    cout << b << endl;
  } else {
    cout << b/2 << endl;
  }
  return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>

using namespace std;

typedef long long ll;

vector<ll> pra, dol;
ll l, Size;

ll n, q;
const ll INF = 1000000000;

void Stworz(vector<ll>& T)
{
    int p = 1;
    while (p < n)
        p *= 2;
    l = p;
    Size = 2 * p - 1;
    for (int i = 0; i <= Size; ++i)
        T.push_back(0);
}

void Zmien(vector<ll>& T, ll a, ll b, ll x)
{
    a += l;
    b += l;
    T[a] += x;
    if (a != b)
        T[b] += x;
    while (a / 2 != b / 2)
    {
        if (a % 2 == 0)
            T[a + 1] += x;
        if (b % 2 == 1)
            T[b - 1] += x;
        a /= 2;
        b /= 2;
    }
}

ll Pyt(vector<ll>& T, ll a)
{
    a += l;
    ll wyn = 0;
    while (a != 0)
    {
        wyn += T[a];
        a /= 2;
    }
    return wyn;
}

int main()
{
    ios_base::sync_with_stdio(0);
    cin >> n >> q;
    ll odp = (n - 2) * (n - 2);
    Stworz(pra);
    Stworz(dol);
    for (int i = 0; i < n; ++i)
    {
        Zmien(pra, i, i, n - 1);
        Zmien(dol, i, i, n - 1);
    }
    ll minPio = INF, minPoz = INF;
    for (int i = 0; i < q; ++i)
    {
        ll oper, x;
        cin >> oper >> x;
        --x;
        if (oper == 1)
        {
            ll nast = Pyt(dol, x);
            odp -= nast - 1;
            if (x < minPio)
            {
                Zmien(pra, 0, nast, -(Pyt(pra, 0) - x));
                minPio = x;
            }
        }
        else
        {
            ll nast = Pyt(pra, x);
            odp -= nast - 1;
            if (x < minPoz)
            {
                Zmien(dol, 0, nast, -(Pyt(dol, 0) - x));
                minPoz = x;
            }
        }
    }
    cout << odp;
    return 0;
}


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

#define MAX_N (100100)
#define MAX_M (200100)

using namespace std;

typedef long long Int;
typedef pair<Int, int> Stat;

const Int INF = 1001001001001001001ll;

int N, M;
Int C;

int head[MAX_N], to[2 * MAX_M], nxt[2 * MAX_M], cost[2 * MAX_M];
Int dist[MAX_N];

void addEdge(int id, int a, int b, int c)
{
    nxt[id] = head[a];
    to[id] = b;
    cost[id] = c;
    head[a] = id;
}

int main()
{
    scanf("%d %d %lld", &N, &M, &C);
    
    memset(head, -1, sizeof(head));
    
    Int sum = 0;
    for (int i = 0; i < M; i++){
        int A, B, D;
        scanf("%d %d %d", &A, &B, &D);
        addEdge(i * 2    , A, B, D);
        addEdge(i * 2 + 1, B, A, D);
        
        sum += D;
    }
    
    fill(dist + 1, dist + N + 1, INF);
    
    priority_queue<Stat, vector<Stat>, greater<Stat> > pq;
    
    for (pq.push(Stat(0, 1)); pq.size();){
        Stat tmp = pq.top(); pq.pop();
        
        Int d = tmp.first;
        int v = tmp.second;
        
        if (dist[v] != INF) continue;
        dist[v] = d;
        for (int e = head[v]; e != -1; e = nxt[e]){
            pq.push(Stat(d + cost[e], to[e]));
        }
    }
    
    pair<Int, int> distPair[MAX_N];
    for (int i = 1; i <= N; i++){
        distPair[i - 1] = make_pair(dist[i], i);
    }
    
    sort(distPair, distPair + N);
    
    Int ans = sum;
    set<int> s;
    for (int i = 0; i < N;){
        int j;
        for (j = i; j < N && distPair[i].first == distPair[j].first; j++){
            s.insert(distPair[j].second);
            int v = distPair[j].second;
            for (int e = head[v]; e != -1; e = nxt[e]){
                if (s.find(to[e]) != s.end()){
                    sum -= cost[e];
                }
            }
        }
        ans = min(ans, sum + distPair[i].first * C);
        i = j;
    }
    
    printf("%lld\n", ans);
    
    return (0);
}

Measured memory_bytes: 17228
#define taskname ""

#include <iostream>
#include <algorithm>
#include <bits/stdc++.h>

using namespace std;
#define long long long

const int N = 1e5 + 10;
const int MOD = 1e9 + 7;

int n, d, dp[N][110][2];
char s[N];

int solve(int index, int remainder, int smaller)
{
    if (index == n) return remainder == 0;
    if (dp[index][remainder][smaller] != -1) return dp[index][remainder][smaller];

    int limit = 9;
    if (smaller) limit = s[index] - '0';

    int res = 0;
    for (int i = 0; i <= limit; ++i) {
        int new_type = (i < limit ? 0 : smaller);
        res = (res + solve(index + 1, (remainder + i) % d, new_type)) % MOD;
    }

    dp[index][remainder][smaller] = res;
    return res;
}

int main()
{
//    freopen(taskname".INP", "r", stdin);
//    freopen(taskname".OUT", "w", stdout);
    cin.tie(nullptr); ios_base::sync_with_stdio(false);

    memset(dp, -1, sizeof(dp));
    cin >> s >> d;
    n = strlen(s);

    cout << (solve(0, 0, 1) - 1 + MOD) % MOD;

    return 0;
}


Measured memory_bytes: 87040
#include <stdio.h>

int main(void){
    // Your code here!
    long long N;
    long long A,B;
    int ans=0;
    
    scanf("%lld",&N);
    
    for(long long i = 1; i*i <= N; i++){
        if(N % i == 0){
            B = i;
        }
    }
    
    A = N / B;
    if(A < B){
        long long tmp = A;
        A = B;
        B = tmp;
    }
    
    while(A > 0){
        ans++;
        A /= 10;
    }
    
    printf("%d\n",ans);
}


Measured memory_bytes: 128
#include <iostream>
#include <algorithm>
#include <vector>
#include <queue>
#include <map>
#include <cmath>
#include <iomanip>
using namespace std;
#define REP(i,n) for (int i=0;i<(n);++i)
#define rep(i,a,b) for(int i=a;i<(b);++i)
template<class T> inline bool chmin(T &a, T b){ if(a > b) { a = b; return true;} return false;}
template<class T> inline bool chmax(T &a, T b){ if(a < b) { a = b; return true;} return false;}
using ll = long long;
constexpr long long INF = 1LL << 62;
constexpr int MOD = 1e9 + 7;
constexpr double EPS = 1e-10;

int m[202020];

void pf(ll x) {
    for(ll i=1; i*i <= x; ++i) {
        if(x%i==0) {
            ++m[i];
            if(i!= x/i) ++m[x/i];
        }
    }
}

int main() {
    cin.tie(0); ios_base::sync_with_stdio(false);
    ll N; cin >> N;
    vector<ll> a(N+1);
    for(int i=1; i <= N; ++i) cin >> a[i];

    vector<ll> ans;
    for(int i = N; i >= 1; --i) {
        if(m[i]%2 != a[i]) {
            ans.push_back(i);
            pf(i);
        }
    }

    int M = (int)ans.size();
    cout << M << '\n';
    REP(i,M) cout << ans[i] << (i==M-1 ? '\n' : ' ');
    return 0;
}

Measured memory_bytes: 4340
#include <bits/stdc++.h>
using namespace std;
#define REP(i,a) for(int i = 0; i < (a); i++)
typedef long long ll;
typedef pair<int, int> P;
const int INF = 1e9;
const int MOD = 1e9 + 7;

int main(){
	int n;
	cin >> n;
	int d[n];
	REP(i,n) cin >> d[i];
	sort(d, d + n);
	cout << d[n / 2] - d[n / 2 - 1] << endl;
}

Measured memory_bytes: 640
# -*- coding: utf-8 -*-
import itertools
import numpy as np

h, w, k = map(int, input().split()) 

c = []
for i in range(h):
    c.append(list(input()))

c_rep = c.copy()
for i in range(h):
    for j in range(w):
        if c[i][j] == ".":
            c_rep[i][j] = 0
        else:
            c_rep[i][j] = 1
c = np.array(c_rep)

hp = [""] * (h+1)
for i in range(1,h+1):
    hp[i] = list(itertools.combinations(range(h), i))

hp_lis = [[]]
for i in range(len(hp)):
    if i == "":
        hp_lis.append([])
    else:
        for j in range(len(hp[i])):
            hp_lis.append(list(hp[i][j]))

wp = [""] * (w+1)
for i in range(1,w+1):
    wp[i] = list(itertools.combinations(range(w), i))

wp_lis = [[]]
for i in range(len(wp)):
    if i == "":
        wp_lis.append([])
    else:
        for j in range(len(wp[i])):
            wp_lis.append(list(wp[i][j]))

count = 0
for i in range(len(hp_lis)):
    for j in range(len(wp_lis)):
        #print(i,j)
        temp = np.delete(c, obj=hp_lis[i], axis=0)
        temp = np.delete(temp, obj=wp_lis[j], axis=1)
        #print("temp", temp)
        if np.sum(temp) == k:
            count += 1

print(count)

Measured memory_bytes: 27356
#include <iostream>
#include <algorithm>
#include <string.h>
#include <string>

using namespace std;
int main()
{
	int n, p[20], ans = 0;
	cin >> n;
	for (int i = 0; i < n; i++) {
		cin >> p[i];
	}
	for (int i = 0; i < n - 2; i++) {
		if (p[i + 1] < p[i] && p[i + 1] > p[i + 2]) {
			ans++;
		}
		if (p[i + 1] > p[i] && p[i + 1] < p[i + 2]) {
			ans++;
		}
	}
	cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
from itertools import product
S = input()
len_s = len(S)
patterns = product([0,1], repeat=len(S) - 1)

ans = 0

for pattern in patterns:
  tmp_st = ''
  tmp_arr = []
  for i in range(len_s):
    tmp_st += S[i]
    if i <= len_s-2 and pattern[i]:
      ans += int(tmp_st)
      tmp_st = ''
  ans += int(tmp_st)

print(ans)



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

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

#define vt          vector
#define sz(x)       (int)(x).size()
#define all(x)      (x).begin(), (x).end()
#define rall(x)     (x).rbegin(), (x).rend()
#define fi          first
#define se          second

const int mod = 1e9 + 7, maxn = 5e5 + 1;

ll iv(ll a, ll b = mod) {
    return a > 1 ? b - iv(b % a, a) * b / a : 1;
}

ll f[maxn];

signed main() {
    ios::sync_with_stdio(0), cin.tie(0);

    f[0] = 1;
    for (int i = 1; i < maxn; i++) f[i] = f[i - 1] * i % mod;

    auto P = [&](int n, int r) {
        return f[n] * iv(f[n - r]) % mod;
    };

    auto C = [&](int n, int r) {
        return P(n, r) * iv(f[r]) % mod;
    };

    int n, m;
    cin >> n >> m;

    ll ans = 0;
    for (int i = 0; i <= n; i++) {
        ll add = C(n, i) * P(m, i) % mod *
            P(m - i, n - i) % mod * P(m - i, n - i) % mod;
        ans += (i & 1 ? -1 : 1) * add;
    }

    cout << (ans % mod + mod) % mod;
}


Measured memory_bytes: 7468
#include <unistd.h>
#include <stdio.h>
#include <algorithm>

typedef long long ll;

int mat[3000][3000];

ll dp[3000][3000][4];
ll dpl[3000];

char buf[1048576];
int lim = 0;
int cur = 0;

void refill()
{
    lim = read(STDIN_FILENO, buf, sizeof buf);
    cur = 0;
}

int rd()
{
    while (true) {
        if (cur == lim) {
            refill();
            if (lim == 0) return -1;
        } else {
            if (buf[cur] >= '0' && buf[cur] <= '9') break;
            cur++;
        }
    }
    int acc = buf[cur++] - '0';
    while (true) {
        if (cur == lim) {
            refill();
            if (lim == 0) return acc;
        } else {
            if (buf[cur] < '0' || buf[cur] > '9') return acc;
            acc = acc * 10 + buf[cur++] - '0';
        }
    }
}

int main(int argc, char **argv)
{
    int rr = rd();
    int cc = rd();
    int k  = rd();

    for (int i = 1; i <= k; i++) {
        int r = rd();
        int c = rd();
        int v = rd();
        mat[r - 1][c - 1] = v;
    }
    dp[0][0][1] = mat[0][0];
    for (int y = 0; y < rr; y++) {
        for (int x = 0; x < cc; x++) {
            for (int c = 0; c < 4; c++) {
                int v = mat[y][x];
                ll q;
                if (c == 0 || v == 0) {
                    q = (x == 0) ? dpl[x] : std::max(dpl[x], dp[y][x - 1][c]);
                } else {
                    q = (x == 0) ? dpl[x] + v : std::max(dpl[x] + v, std::max(dp[y][x - 1][c], dp[y][x - 1][c - 1] + v));
                }
                dp[y][x][c] = q;
            }
        }
        for (int x = 0; x < cc; x++) {
            dpl[x] = std::max(std::max(dp[y][x][0], dp[y][x][1]), std::max(dp[y][x][2], dp[y][x][3]));
        }
    }
    printf("%lld\n", dpl[cc - 1]);
    return 0;
}


Measured memory_bytes: 320352
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef double db;
typedef pair<int,int> P;
#define pb push_back
#define ft first
#define sd second
#define mp make_pair
#define fr(i,n) for(int i=0;i<(n);i++)
#define Fr(i,n) for(int i=0;i++<(n);)
#define ifr(i,n) for(int i=(n)-1;i>=0;i--)
#define iFr(i,n) for(int i=(n);i>0;i--)

int main(){
    ll r,g,b,n,cnt=0;
    cin>>r>>g>>b>>n;
    fr(i,n/r+1){
        fr(j,(n-i*r)/g+1){
            if((n-r*i-g*j)%b==0) cnt++;
        }
    }
    cout<<cnt<<endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ll  long long
#define endl '\n'
#define FASTINOUT ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
int main()
{
    FASTINOUT;
    int x;
    cin>>x;
    if (x>=400&&x<=599)
        cout<<8<<endl;
    else if (x>=600&&x<=799)
        cout<<7<<endl;
    else if (x>=800&&x<=999)
        cout<<6<<endl;
    else if (x>=1000&&x<=1199)
        cout<<5<<endl;
    else if (x>=1200&&x<=1399)
        cout<<4<<endl;
    else if (x>=1400&&x<=1599)
        cout<<3<<endl;
    else if (x>=1600&&x<=1799)
        cout<<2<<endl;
    else if (x>=1800&&x<=1999)
        cout<<1<<endl;
    return 0;
}


Measured memory_bytes: 3608
#include <bits/stdc++.h>
using namespace std;
void debug_out() { cerr << endl; }
template<class T> ostream& prnt(ostream& out, T v) { out << v.size() << '\n'; for(auto e : v) out << e << ' '; return out;}
template<class T> ostream& operator<<(ostream& out, vector <T> v) { return prnt(out, v); }
template<class T> ostream& operator<<(ostream& out, set <T> v) { return prnt(out, v); }
template<class T1, class T2> ostream& operator<<(ostream& out, map <T1, T2> v) { return prnt(out, v); }
template<class T1, class T2> ostream& operator<<(ostream& out, pair<T1, T2> p) { return out << '(' << p.st << ' ' << p.nd << ')'; }
template <typename Head, typename... Tail> void debug_out(Head H, Tail... T) { cerr << " " << H; debug_out(T...);}
#define dbg(...) cerr << #__VA_ARGS__ << " ->", debug_out(__VA_ARGS__)
#define dbg_v(x, n) do{cerr<<#x"[]: ";for(int _=0;_<n;++_)cerr<<x[_]<<" ";cerr<<'\n';}while(0)
#define dbg_ok cerr<<"OK!\n"
#define ll long long
#define ld long double
#define ull unsigned long long
#define pii pair<int,int>
#define MOD 1000000007
#define zeros(x) x&(x-1)^x
#define fi first
#define se second
#define Nmax 500005
#define B 73
const long double PI = acos(-1);

int n;
string s1,s2;
map<pair<ull,ull>, ll> M[20];

void read(){
	cin >> n;
    cin >> s1;
    s2 = s1.substr(n, n);
    s1 = s1.substr(0, n);
    reverse(s2.begin(),s2.end());
}

void add(string &s){
	int mx = 1 << n;
	int cnt;
	ull h1 = 0, h2 = 0;
	for (int i=0;i<mx;i++){
		cnt = 0;
		h1 = h2 = 0;
		for (int k=0;k<n;k++){
			if (i & 1<<k) 
				h1 = h1 * B + (s[k] - 'a' + 1), 
				cnt++;
			else 
				h2 = h2 * B + (s[k] - 'a' + 1);
		}
		M[cnt][{h1,h2}]++;
	}
}

ll ans = 0;
void solve(string &s){
	int mx = 1 << n;
	int cnt;
	ull h1 = 0, h2 = 0;
	for (int i = 0; i < mx; i++){
		h1 = h2 = 0;
		cnt = 0;
		for (int k = 0; k < n; k++){
			if (i & 1 << k) 
				h1 = h1 * B + (s[k] - 'a' + 1), 
				cnt++;
			else 
				h2 = h2 * B + (s[k] - 'a' + 1);
		}
		ans += M[cnt][{h1, h2}];
	}
}

int main(){
    ios::sync_with_stdio(false);

    read();
    add(s1);
    solve(s2);

    cout << ans << '\n';

    return 0;
}

Measured memory_bytes: 33024
import java.util.*;

class Main{
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int[] food = new int[n];
        int[] com = new int[n-1];
        int sum = 0;
        for(int i = 0;i < n;i++){
            food[i] = sc.nextInt()-1;
        }
        for(int i = 0;i < n;i++){
            sum += sc.nextInt();
        }
        for(int i = 0;i < n-1;i++){
            com[i] = sc.nextInt();
        }

        for(int i = 1;i < n;i++){
            if(food[i-1] == food[i]-1)
            sum += com[food[i-1]];
        }
        System.out.println(sum);
    }
}

Measured memory_bytes: 21844
#define _USE_MATH_DEFINES

#include <iostream>
#include<stdio.h>
#include <vector>
#include <math.h>
#include <cmath>

using namespace std;

bool CanMakeNum(vector<int> &vNum, int index, int checkNum)
{
	if (checkNum == 0)
	{
		return true;
	}
	else if (checkNum < 0)
	{
		return false;
	}
	if (index >= vNum.size())
	{
		return false;
	}
	bool result = CanMakeNum(vNum, index + 1, checkNum - vNum[index]) || CanMakeNum(vNum, index + 1, checkNum);
	return result;
}

struct POINT
{
	double x;
	double y;
};

double rad = M_PI * 60.0 / 180.0;

void koch(int depth, POINT start, POINT end)
{
	if (depth == 0)
	{
		return;
	}

	//3分割
	POINT s;
	s.x = (start.x * 2.0 + end.x) / 3.0;
	s.y = (start.y * 2.0 + end.y) / 3.0;

	POINT t;
	t.x = (end.x * 2.0 + start.x) / 3.0;
	t.y = (end.y * 2.0 + start.y) / 3.0;

	POINT u;
	u.x = (t.x - s.x) * cosf(rad) - (t.y - s.y) * sinf(rad) + s.x;
	u.y = (t.x - s.x) * sinf(rad) + (t.y - s.y) * cosf(rad) + s.y;

	--depth;

	if (depth != 0)
	{
		koch(depth, start, s);
	}
	printf("%.8f %.8f\n", s.x, s.y);
	if (depth != 0)
	{
		koch(depth, s, u);
	}
	printf("%.8f %.8f\n", u.x, u.y);
	if (depth != 0)
	{
		koch(depth, u, t);
	}
	printf("%.8f %.8f\n", t.x, t.y);
	if (depth != 0)
	{
		koch(depth, t, end);
	}
}


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

	POINT start{ 0, 0 };
	POINT end{ 100, 0 };

	printf("%.8f %.8f\n", start.x, start.y);
	koch(n, start, end);
	printf("%.8f %.8f\n", end.x, end.y);
	return 0;
}












Measured memory_bytes: 3280
#include<iostream>
#include<string>
#include<queue>
using namespace std;

int main(){
  int n, q, t;
  string name;
  queue<pair<string, int> > Q; //????????????????????\???

  cin >> n >> q;
  for(int i = 0; i < n; i++){
    cin >> name >> t;
    Q.push(make_pair(name, t));
  }

  pair<string, int> u;
  int elaps = 0, a;

  //????????\??¬????????§???
  for (; !Q.empty();){
    u = Q.front(); Q.pop();
    a = min(u.second, q); //a???????????????????????????????????§????????????q???
    u.second -= a;
    elaps += a; //?????????????????????
    if ( u.second > 0 ){
      Q.push(u); //??????????????????????????´???????????\??????????°??????????
    }
    else{
      cout << u.first << " " << elaps << endl;
    }
  }

  return 0;

}

Measured memory_bytes: 6380
fun main(args: Array<String>) {
    Program().solve()
}

class Program {
    fun solve() {
        val sc = MyScanner()
        val n = sc.nextInt()
        val a = sc.longList()

        var left = 0
        var tmp = 0L
        var ans = 0L
        for (right in 0 until n) {
            if ((tmp and a[right]) > 0) {
                while ((tmp and a[right]) > 0) {
                    ans += right - left
                    tmp -= a[left++]
                }
            }
            tmp += a[right]
        }

        ans += (n - left + 1).toLong() * (n - left) / 2
        println(ans)
    }
}


class MyScanner() {
    private var index = 0
    private var line = listOf<String>()

    fun next(): String {
        while (line.size <= index) {
            line = readLine()!!.split(' ')
            index = 0
        }
        return line[index++]
    }

    fun nextInt() = next().toInt()
    fun nextLong() = next().toLong()
    fun nextDouble() = next().toDouble()
    fun nextCharArray() = next().toCharArray()
    fun nextChar() = next()[0]

    fun strList(): List<String> {
        index = line.size
        return readLine()!!.split(' ')
    }

    fun intList() = strList().map { it.toInt() }
    fun longList() = strList().map { it.toLong() }
    fun doubleList() = strList().map { it.toDouble() }
}

Measured memory_bytes: 84404
#include <cstdio>
#include <iostream>

using namespace std;

int main() {

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

	int A[n];
	for (int i = 0; i < n; ++i) {
		scanf("%d", &A[i]);
	}

	int V[n];
	V[0] = A[0];
	int length = 1;
	for (int i = 1; i < n; ++i) {
		if (A[i] > V[length - 1]) {
			V[length++] = A[i];
		} else {
			int left = 0;
			int right = length;
			while (left < right) {
				int mid = (left + right) / 2;
				if (V[mid] >= A[i]) {
					right = mid;
				} else {
					left = mid + 1;
				}
			}
			V[right] = A[i];
		}
	}
	cout << length << endl;

	return 0;
}

Measured memory_bytes: 3980
#include <bits/stdc++.h>
#include <iostream>
//#include <algorithm>
// #include <iomanip>
#define ll long long

using namespace std;

vector<int> z_algorithm(const string &s) {
  vector<int> prefix(s.size());
  for (int i = 1, j = 0; i < s.size(); i++) {
    if (i + prefix[i - j] < j + prefix[j]) {
      prefix[i] = prefix[i - j];
    } else {
      int k = max(0, j + prefix[j] - i);
      while (i + k < s.size() && s[k] == s[i + k]) ++k;
      prefix[i] = k;
      j = i;
    }
  }
  prefix[0] = (int)s.size();
  return prefix;
}

int main() {
  int n;
  scanf("%d", &n);

  string s;
  cin >> s;

  int a = 0;
  for (int i = 0; i < s.size(); i++) {
    auto z = z_algorithm(s.substr(i));

    for (int j = 0; j < z.size(); j++) {
      // cout << j << "," << z[j] << endl;
      int m = min(j, z[j]);

      a = max(a, m);
    }
    // cout << "===============" << endl;
  }
  cout << a << endl;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int vis[100007];
vector<int>v[100007];
vector<int>vt;
int deg[100007];
void dfs(int a,int pp,int st,int nev){
    for(auto&x:v[a]){
        if(!vis[x]&&x!=pp&&x!=nev){
            vis[x]=1;
            dfs(x,a,st,nev);
        }
    }
}
int main(){
    int n,m;
    scanf("%d%d",&n,&m);
    int a=0,b=0;
    for(int i=1;i<=m;i++){
        scanf("%d%d",&a,&b);
        v[a].push_back(b);
        v[b].push_back(a);
        deg[a]++;
        deg[b]++;
    }
    int flag=0;
    for(int i=1;i<=n;i++){
        if(deg[i]%2==1){
            printf("No");
            return 0;
        }
        if(deg[i]>=6)
            flag=1;
        if(deg[i]>=4)
            vt.push_back(i);
    }
    if(m>=n+3)
        flag=1;
    if(flag){
        printf("Yes");
        return 0;
    }
    else{
        if(vt.size()==2){
            dfs(vt[0],-1,vt[0],vt[1]);
            if(vis[vt[0]]){//有环
                printf("Yes");
                return 0;
            }
        }
    }
    printf("No");
    return 0;
}


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

int main() {
    ll a,b,c;
    cin >> a >> b >> c;
    ll d = max(max(a,b),c);
    ll e = min(min(a,b),c);
    if (d == 7 && e == 5 && a + b + c == 17) {
        cout << "YES" << endl;
    }
    else {
        cout << "NO" << endl;
    }

}



Measured memory_bytes: 3568
#include<cstdio>
#include<cstdlib>
#include<algorithm>
#include<iostream>
#include<queue>
#include<vector>
#include <bitset>
#include <cmath>
#include <limits>
#include <iostream>
#include<set>
#include<tuple>
using namespace std;
#define INF 11000000000
#define MAX 210000
#define MOD 1000000007
typedef long long ll;
typedef pair<int,int> P;
typedef pair<pair<int,int>,int> p;
typedef pair< pair<int,int>, int> p; 
#define bit(n,k) ((n>>k)&1) /*nのk bit目*/
#define rad_to_deg(rad) (((rad)/2/M_PI)*360)

//http://kmjp.hatenablog.jp/entry/2019/05/26/0900

ll fac[MAX],finv[MAX],inv[MAX];
//http://drken1215.hatenablog.com/entry/2018/06/08/210000
//テーブルを作る前処理　O(n)
//pが素数でなくてはならない
void COMinit(){
    fac[0]=fac[1]=1;
    finv[0]=finv[1]=1;
    inv[1]=1;
    for(int i=2;i<MAX;i++){
        fac[i]=fac[i-1]*i%MOD;
        inv[i]=MOD-inv[MOD%i]*(MOD/i)%MOD;
        finv[i]=finv[i-1]*inv[i]%MOD;
    }
}
//二項係数計算
ll COM(int n,int k){
    if(n<k) return 0;
    if(n<0 || k<0) return 0;
    return fac[n]*(finv[k]*finv[n-k]%MOD)%MOD;
}


int main(){
    COMinit();
    int N,M,K;
    cin>>N>>M>>K;
    ll ans=0;
    for(int i=0;i<N;i++){
        ll d=1LL*i*(i+1)/2%MOD;
        d=d*M%MOD*M%MOD;
        ans+=d;
    }
    for(int i=0;i<M;i++){
        ll d=1LL*i*(i+1)/2%MOD;
        d=d*N%MOD*N%MOD;
        ans+=d;
    }
    
    cout<<ans%MOD*COM(N*M-2,K-2)%MOD<<endl;
}



Measured memory_bytes: 5120
n, q = map(int, input().split())
s = input()
t = []
c = 0
for i in range(n - 1):
    if i != 0:
        if s[i - 1] == "A" and s[i] == "C":
            c += 1
    t.append(c)
if s[n - 2] == "A" and s[n - 1] == "C":
    t.append(c + 1)
else:
    t.append(c)
for i in range(q):
    l, r = map(int, input().split())
    print(t[r - 1] - t[l - 1])

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

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll, ll> P;
typedef complex<double> Point;

#define PI acos(-1.0)
#define EPS 1e-10
const ll INF = 1e16;
const ll MOD = 1e9 + 7;

#define FOR(i,a,b) for(ll i=(a);i<(b);i++)
#define rep(i,N) for(ll i=0;i<(N);i++)
#define ALL(s) (s).begin(),(s).end()
#define EQ(a,b) (abs((a)-(b))<EPS)
#define EQV(a,b) ( EQ((a).real(), (b).real()) && EQ((a).imag(), (b).imag()) )
#define fi first
#define se second
#define N_SIZE (1LL << 20)
#define NIL -1

ll mod_add(ll a, ll b) { return (a + b) % MOD; }
ll mod_sub(ll a, ll b) { return (a - b + MOD) % MOD; }
ll mod_mul(ll a, ll b) { return a*b % MOD; }

ll n,m,c;

int main(){
    cin >> n >> m >> c;
    vector<ll> b(m);
    rep(i,m)cin >> b[i];
    ll ans = 0;
    rep(i,n){
        ll sum = c;
        rep(j,m){
            ll a;
            cin >> a;
            sum += a * b[j];
        }
        if(sum > 0)ans++;
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define SORT(a) sort(a.begin(), a.end())
#define RSORT(a) sort(a.rbegin(), a.rend())
#define REP(i, n) for (long long i = 0; i < n; i++)
#define RREP(i, n) for (long long i = n - 1, 0 <= i; i--)
#define FOR(i, start, end) for (long long i = start; i < end; i++)
#define RFOR(i, start, end) for (long long i = start - 1; 0 <= i; i--)
#define ALL(a) a.begin(), a.end()
#define MOD(a) a %= 1'000'000'007
using ll = long long;
using namespace std;
const int INF32       = 1'050'000'000;
const long long INF64 = 4'000'000'000'000'000'000;
const int MOD7        = 1'000'000'007;
const int MOD9        = 1'000'000'009;
template <class T> inline bool chmin(T &a, T b) {
    if (a > b) {
        a = b;
        return true;
    }
    return false;
}
template <class T> inline bool chmax(T &a, T b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}
void print() { std::cout << '\n'; }
template <class H, class... T> void print(H &&head, T &&... args) {
    std::cout << head;
    sizeof...(args) == 0 ? std::cout << "" : std::cout << ' ';
    print(std::forward<T>(args)...);
}
template <class T> void print(std::vector<T> &v) {
    for (int i = 0; i < v.size(); i++) {
        std::cout << v[i];
        i == v.size() - 1 ? std::cout << '\n' : std::cout << ' ';
    }
}
template <class T> void print(std::vector<std::vector<T>> &v) {
    for (int i = 0; i < v.size(); i++) {
        for (int j = 0; j < v[i].size(); j++) {
            std::cout << v[i][j];
            j == v[i].size() - 1 ? std::cout << '\n' : std::cout << ' ';
        }
    }
}
template <class T> T up(T a, T div) { return (a + div - 1) / div; }
int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);

    ll S;
    cin >> S;

    vector<ll> ans(6);
    ans[0] = 0;
    ans[1] = 0;
    ans[2] = (ll)1E9;
    ans[3] = 1;
    ans[5] = up(S, ans[2]);
    ans[4] = ans[5] * ans[2] - S;

    print(ans);

    return 0;
}

Measured memory_bytes: 256
#include <iostream>
int main(){
 int a;
 int b;
 std::cin >> a >> b;
 if( a > b ){
  std::cout << "a > b";
 }else if( a==b ){
  std::cout << "a == b";
 }else{
  std::cout << "a < b";
 }
 std::cout << std::endl;
}

Measured memory_bytes: 3032