akhauriyash/Code-Regression huggingface dataset:
from itertools import*
from math import*
from collections import*
from heapq import*
from bisect import bisect_left,bisect_right
from copy import deepcopy
inf = float("inf")
mod = 10**9+7
from functools import reduce
import sys
sys.setrecursionlimit(10**7)

H,W = map(int,input().split())
grid = [list(input()) for _ in range(H)]
L=[[0]*W for _ in range(H)]
R=[[0]*W for _ in range(H)]
D=[[0]*W for _ in range(H)]
U=[[0]*W for _ in range(H)]
for h in range(H):
    for w in range(W):
        if grid[h][w] ==".":
            L[h][w] = L[h][w-1]+1
            U[h][w] = U[h-1][w]+1
        if grid[h][W-w-1]==".":
            R[h][-w-1]=R[h][-w]+1
        if grid[H-h-1][w] ==".":
            D[-h-1][w] = D[-h][w]+1
ans = 0
for i in range(H):
    for j in range(W):
        if grid[i][j] =="#":
            ans = max(ans,L[i][j]+R[i][j]+D[i][j]+U[i][j])
        else:
            ans = max(ans,L[i][j]+R[i][j]+D[i][j]+U[i][j]-3)
print(ans)

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

#define int long long

#define rep(i,n) for(int i=0;i<(n);i++)
#define pb push_back
#define all(v) (v).begin(),(v).end()
#define fi first
#define se second
typedef vector<int>vint;
typedef pair<int,int>pint;
typedef vector<pint>vpint;

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


map<string,int>cnt;

signed main(){
    int N,L;
    cin>>N>>L;

    rep(i,N){
        string S;cin>>S;
        cnt[S]++;
    }


    string ans;
    string med;

    while(cnt.size()){
        string s=cnt.begin()->fi;
        int c=cnt.begin()->se;
        cnt.erase(cnt.begin());
        string t=s;
        reverse(all(t));
        if(s>t){
            continue;
        }
        if(s==t&&c%2){
            c--;
            if(med=="")med=s;
            else chmin(med,s);
        }

        if(s<t)chmin(c,cnt[t]);
        else c/=2;
        rep(i,c)ans+=s;
    }


    string ansans=ans+med;
    reverse(all(ans));
    ansans+=ans;
    cout<<ansans<<endl;
    return 0;
}

Measured memory_bytes: 3296
def _f(px, py, qx, qy, rx, ry):
    return (qx - px) * (ry - py) - (qy - py) * (rx - px)

def intersect(px, py, qx, qy, rx, ry, sx, sy):
    f1 = _f(px, py, qx, qy, rx, ry)
    f2 = _f(px, py, qx, qy, sx, sy)
    f3 = _f(rx, ry, sx, sy, px, py)
    f4 = _f(rx, ry, sx, sy, qx, qy)
    
    return f1 * f2 < 0 and f3 * f4 < 0

def intersection(px, py, qx, qy, rx, ry, sx, sy):
    det = (px - qx) * (sy - ry) - (sx - rx) * (py - qy)
    t = ((sy - ry) * (sx - qx) + (rx - sx) * (sy - qy)) / det
    
    x = t * px + (1 - t) * qx
    y = t * py + (1 - t) * qy
    
    return (x, y)

def solve():
    from sys import stdin
    f_i = stdin
    
    while True:
        n = int(f_i.readline())
        if n == 0:
            break
        
        area = 1
        segments = set()
        
        for i in range(n):
            px, py, qx, qy = map(int, f_i.readline().split())
            points = set()
            cnt = 1
            
            for rx, ry, sx, sy in segments:
                if intersect(px, py, qx, qy, rx, ry, sx, sy):
                    ip = intersection(px, py, qx, qy, rx, ry, sx, sy)
                    if ip not in points:
                        cnt += 1
                        points.add(ip)
                        
            segments.add((px, py, qx, qy))
            
            area += cnt
        
        print(area)

solve()


Measured memory_bytes: 5644
package main

import "fmt"

func main() {
	var R, G, B, N, ans int
	fmt.Scan(&R, &G, &B, &N)
	for r := 0; r <= N; r++ {
		if r*R > N {
			break
		}
		for g := 0; g <= N; g++ {
			if r*R+g*G > N {
				break
			}
			if (N-r*R-g*G)%B == 0 {
				ans++
			}
		}
	}
	fmt.Printf("%v\n", ans)
}


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

struct UnionFind {
    vector<int> parent;
    
    UnionFind(int n) : parent(n, -1) { }
    void init(int n) { parent.assign(n, -1); }
    
    int root(int x) {
        if (parent[x] < 0) return x;
        else return parent[x] = root(parent[x]);
    }
    
    bool issame(int x, int y) {
        return root(x) == root(y);
    }
    
    bool merge(int x, int y) {
        x = root(x); y = root(y);
        if (x == y) return false;
        if (parent[x] > parent[y]) swap(x, y); // merge technique
        parent[x] += parent[y];
        parent[y] = x;
        return true;
    }
    
    int size(int x) {
        return -parent[root(x)];
    }
};
 
int main(){
    int N,M;
    cin >> N >> M;
    UnionFind U(N);
    vector<int> P(N);
    rep(i,N){
        cin >> P[i];
        P[i]--;
    }
    rep(i,M){
        int x,y;
        cin >> x >> y;
        x--,y--;
        U.merge(x,y);
    }

    int res = 0;
    rep(i,N){
        if(U.issame(i,P[i])) res++;
    }

    cout << res << endl;

    return 0;
}

Measured memory_bytes: 1024
//include
//------------------------------------------
#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <queue>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>

#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>

#include <stdexcept>

using namespace std;

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

//debug
#define dump(x)  cerr << #x << " = " << (x) << endl
#define debug(x) cerr << #x << " = " << (x) << " (l" << __line__ << ")" << " " << __file__ << endl

// type alias
using ll = long long;
using ull = unsigned long long;

template<class ll>
inline ll getCeilExponent(ll a)
{
	if (a <= 0)
	{
		throw invalid_argument("vaule equal to or less than 0 should not be valid");
	}

	ll index = 0;
	--a;
	for (; a != 0; a >>= 1)
	{
		++index;
	}
	return index;
}

template<class ll>
inline ll getFloorExponent(ll a)
{
	if (a <= 0)
	{
		throw invalid_argument("vaule equal to or less than 0 should not be valid");
	}

	ll index = 0;
	a >>= 1;
	for (; a != 0; a >>= 1)
	{
		++index;
	}
	return index;
}

// computational complexity: o(log(max(a, b))) 
template<class ll>
inline ll getGcd(ll a, ll b)
{
	if (b == 0)
	{
		return a;
	}
	return getGcd(b, a % b);
}

// computational complexity: o(log(max(a, b))) 
template<class ll>
inline pair<ll, ll> getBezoutsIdentitySolution(ll a, ll b)
{
	if (b == 0)
	{
		return { 1, 0 };
	}
	auto sol = getBezoutsIdentitySolution(b, a % b);
	return { sol.second, sol.first - (a / b) * sol.second };
}

template<class Integer>
inline Integer getPower(Integer base, unsigned exponential)
{
	Integer res = 1;
	while (exponential >= 1)
	{
		if (exponential & 1)
		{
			res *= base;
		}
		base = base * base;
		exponential >>= 1;
	}

	return res;
}

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

	ll N;
	cin >> N;

	vector<ll> Ss(N);
	for (ll i = 0; i < N; ++i)
	{
		cin >> Ss[i];
	}

	ll res = 0;
	for (ll C = 1; C + 1 < N; ++C)
	{
		ll resC = 0;
		for (ll k = 1; C * (k + 1) + 1 < N; ++k)
		{
			resC += Ss[N - 1 - C * k] + Ss[C * k];
			if ((N - 1) % C == 0 && (N - 1) / C <= k * 2 )
			{
				continue;
			}
			res = max(res, resC);
		}
	}

	cout << res << endl;


	return 0;
}


Measured memory_bytes: 1024
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <cmath>
#include <cstdlib>
#include <iomanip>
#include <cmath>
#include <climits>
using namespace std;

bool comp(pair<int, string> a, pair<int, string> b){
    if(a.first != b.first) return a.first > b.first;
    else return a.second < b.second;
}

int main(){
    int a,b;;
    char c;

    cin >> a >> c >> b;

    cout << (c == '+' ? a+b:a-b) << endl;

    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using ll  = long long;
#define int ll
#define rep(i,n) for(int i=0;i<n;i++)
#define loop(i,s,n) for(int i=s;i<n;i++)
#define erep(e,v) for(auto && e :v)
#define all(in) in.begin(), in.end()
#define MP make_pair
#define INF (sizeof(int) == 4 ? (int)1e9:(int)1e18)
#define EPS 0.0000000001
using namespace std;
template<class T, class S> void cmin(T &a, const S &b) { if (a > b)a = b; }
template<class T, class S> void cmax(T &a, const S &b) { if (a < b)a = b; }
template<typename Head, typename Value> auto vectors(const Head &head, const Value &v) { return vector<Value>(head, v); }
template<typename Head, typename... Tail> auto vectors(Head x, Tail... tail) { auto inner = vectors(tail...); return vector<decltype(inner)>(x, inner); }
template<class T> void join(T a){for(auto itr :a){if(itr != *a.begin())cout << " "; cout << itr;} }
using ld  = long double;
using pii = pair<int,int>;
using piii = pair<int,pii>;
int W,H;
int dx[]={0,0,1,-1}, dy[]={1,-1,0,0};
bool valid(int x,int y){return (0<=x&&x<W)&&(0<=y&&y<H);}
signed main(){
    int n; cin >> n;
    vector<int>v(n);
    for(auto & itr : v) cin >> itr;
    int ans = 0;
    rep(i,n-1)ans+=max(0LL,v[i]-v[i+1]);
    cout << ans + v.back() << endl;
}




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

using namespace std;
#ifdef _DEBUG
#define _GLIBCXX_DEBUG
#include "dump.hpp"
#else
#define dump(...)
#endif

//#define int long long
#define ll long long
#define ll1 1ll
#define ONE 1ll
#define DBG 1
#define rep(i, a, b) for (int i = (a); i < (b); i++)
#define rrep(i, a, b) for (int i = (b)-1; i >= (a); i--)
#define loop(n) rep(loop, (0), (n))
#define all(c) begin(c), end(c)
const int INF =
    sizeof(int) == sizeof(long long) ? 0x3f3f3f3f3f3f3f3fLL : 0x3f3f3f3f;
const int MOD = (int)(1e9) + 7;
const double PI = acos(-1);
const double EPS = 1e-9;
#define fi first
#define se second
#define pb push_back
#define eb emplace_back
using pii = pair<int, int>;
// template<class T> ostream &operator<<(ostream &os,T &t){dump(t);return os;}
template <typename T, typename S>
istream &operator>>(istream &is, pair<T, S> &p) {
  is >> p.first >> p.second;
  return is;
}
template <typename T, typename S>
ostream &operator<<(ostream &os, pair<T, S> &p) {
  os << p.first << " " << p.second;
  return os;
}

template <typename T> void printvv(const vector<vector<T>> &v) {
  cerr << endl;
  rep(i, 0, v.size()) rep(j, 0, v[i].size()) {
    if (typeid(v[i][j]).name() == typeid(INF).name() and v[i][j] == INF) {
      cerr << "INF";
    } else
      cerr << v[i][j];
    cerr << (j == v[i].size() - 1 ? '\n' : ' ');
  }
  cerr << endl;
}
/*
   typedef __int128_t Int;
   std::ostream &operator<<(std::ostream &dest, __int128_t value) {
   std::ostream::sentry s(dest);
   if (s) {
   __uint128_t tmp = value < 0 ? -value : value;
   char buffer[128];
   char *d = std::end(buffer);
   do {
   --d;
 *d = "0123456789"[tmp % 10];
 tmp /= 10;
 } while (tmp != 0);
 if (value < 0) {
 --d;
 *d = '-';
 }
 int len = std::end(buffer) - d;
 if (dest.rdbuf()->sputn(d, len) != len) {
 dest.setstate(std::ios_base::badbit);
 }
 }
 return dest;
 }

 __int128 parse(string &s) {
 __int128 ret = 0;
 for (int i = 0; i < s.length(); i++)
 if ('0' <= s[i] && s[i] <= '9')
 ret = 10 * ret + s[i] - '0';
 return ret;
 }
 */

#ifndef _DEBUG
#define printvv(...)
#endif
void YES(bool f) { cout << (f ? "YES" : "NO") << endl; }
void Yes(bool f) { cout << (f ? "Yes" : "No") << endl; }
template <class T> bool chmax(T &a, const T &b) {
  if (a < b) {
    a = b;
    return true;
  }
  return false;
}
template <class T> bool chmin(T &a, const T &b) {
  if (a > b) {
    a = b;
    return true;
  }
  return false;
}

signed main(signed argc, char *argv[]) {
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout << fixed << setprecision(12);

  int K;
  cin >> K;
  cout << K / 2 * (K / 2 + (K & 1)) << endl;

  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <set>
#include <queue>
#include <stack>
#include <tuple>
#include <cmath>
#include <iomanip>
#include <map>
#include <cstring> //memset(dp,0,sizeof(dp))
#include <functional>
#include <cctype>
#include <locale>
#define ll long long
#define rep(i,n) for(int i=0;i<(n);i++)
#define rrep(i,n) for(int i=n-1;i>=0;i--)
#define fi first
#define se second
#define pb push_back
#define ALL(a) (a).begin(),(a).end()
using namespace std;
template<typename T1,typename T2> inline void chmin(T1 &a,T2 b){if(a>b) a=b;}
template<typename T1,typename T2> inline void chmax(T1 &a,T2 b){if(a<b) a=b;}
typedef pair<int,int> P;
typedef pair<long long,long long> Pll;
#define fout(num) cout << fixed << setprecision(20) << (num) << endl
//s[i]=tolower(s[i]); islower(s[i]); cout << tolower(s[i])はバグ
//vector<vector<ll>> dp(n,vector<ll>(n))
const ll MOD = 1e9+7;
const int MAX = 1001001;
ll fac[MAX],finv[MAX],inv[MAX];
void COMinit(){
    fac[0]=fac[1]=1;
    finv[0]=finv[1]=1;
    inv[1]=1;
    for(int i=2;i<MAX;i++){
        fac[i]=fac[i-1]*i % MOD;
        inv[i]=MOD-inv[MOD%i]*(MOD/i) % MOD;
        finv[i]=finv[i-1]*inv[i] % MOD;
    }
}
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 N,K;
static const int MAX_V=100100;
vector<int> G[MAX_V];
vector<int> deg(MAX_V);

ll calc(int n,int r){
    if(r>n||r<0) return 0;
    return (fac[n]*finv[n-r])%MOD;
}

ll dfs(int x,int par=-1){
    ll c;
    if(par==-1){
        c=calc(K,deg[x]+1);
    }else{
        c=calc(K-2,deg[x]-1);
    }
    for(int v:G[x]){
        if(v==par) continue;
        c*=dfs(v,x);
        c%=MOD;
    }
    return c;
}

signed main(){
    ios::sync_with_stdio(false);
    std::cin.tie(nullptr);
    COMinit();
    cin >> N >> K;
    deg.resize(N);
    rep(i,N-1){
        int a,b; cin >> a >> b;
        a--; b--;
        G[a].pb(b); G[b].pb(a);
    }
    for(int i=0;i<N;i++) deg[i]=(int)G[i].size();
    cout << dfs(0) << endl;
}


Measured memory_bytes: 37160
#include <bits/stdc++.h>
using namespace std;
#define ll long long
const int N=2e5+10;
ll a[N];
int main()
{
	ll n,m,i,j,k,s,t,sum,l,r;
      scanf("%lld",&n);
	{
		sum=0;
		for(i=1;i<=n;i++)
		scanf("%lld",&a[i]),sum+=a[i];
		l=a[1];
		m=1E15;
		for(i=2;i<=n;i++)
		 {
		 	r=sum-l;
		 	ll rs=llabs(l-r);
		 	m=min(m,rs);
		 	l+=a[i];
		 }
		 printf("%lld\n",m);
	}
	return 0;
}

Measured memory_bytes: 1792
#include <algorithm>
#include <cmath>
#include <iostream>
#include <stack>

class steps
{
public:
    steps(const std::size_t l)
        :walk_limit_(l), walk_size_(), permutation_size_()
    {
        for(std::size_t i = 0; i < walk_limit_; ++i)
        {
            this->push(1);
        }
    };

    void step()
    {
        while(!this->done())
        {
            this->next();
        }
    }

    std::size_t permutation()const
    {
        return permutation_size_;
    }

private:
    void next()
    {
        if(this->formed())
        {
            ++permutation_size_;
            this->inc();
        }
        else if(this->overflow())
        {
            this->pop();
            this->inc();
        }
        else
        {
            this->push(1);
        }
    }

    void inc()
    {
        if(current_pattern_.empty()){return;}
        if(3 == this->top())
        {
            this->pop();
            if(current_pattern_.empty()){return;}
            this->inc();
        }
        else
        {
            ++this->top();
            ++walk_size_;
        }
    }
    
    void push(const std::size_t p)
    {
        walk_size_ += p;
        current_pattern_.push(p);
    }

    void pop()
    {
        walk_size_ -= current_pattern_.top();
        current_pattern_.pop();
    }

    std::size_t& top()
    {
        return current_pattern_.top();
    }

    bool formed()const
    {
        return walk_limit_ == walk_size_;
    }

    bool overflow()const
    {
        return walk_limit_ < walk_size_;
    }

    bool done()const
    {
        return current_pattern_.empty();
    }

    std::stack<std::size_t> current_pattern_;
    std::size_t walk_limit_;
    std::size_t walk_size_;
    std::size_t permutation_size_;
};

std::size_t permutation(const std::size_t limit)
{
    steps s(limit);
    s.step();
    return s.permutation();
}

std::size_t year(const std::size_t perm)
{
    return std::ceil(static_cast<double>(perm) / 10.0 / 365.0);
}

int main()
{
    for(std::size_t n; std::cin >> n, n != 0;)
    {
        std::cout << year(permutation(n)) << std::endl;
    }
}

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

#define rep(i, n) for (int i = 0; i < int(n); i++)
#define rrep(i, n) for (int i = int(n) - 1; i >= 0; i--)
#define reps(i, n) for (int i = 1; i <= int(n); i++)
#define rreps(i, n) for (int i = int(n); i >= 1; i--)
#define repi(i, a, b) for (int i = (a); i < int(b); i++)
#define all(a) (a).begin(), (a).end()
#define bit(b) (1ull << (b))
#define uniq(v) (v).erase(unique(all(v)), (v).end())

using namespace std;
using i32 = int;
using i64 = long long;
using f64 = double;
using vi32 = vector<i32>;
using vi64 = vector<i64>;
using vf64 = vector<f64>;
using vstr = vector<string>;

template<typename T, typename S> void amax(T &x, S y) { if (x < y) x = y; }
template<typename T, typename S> void amin(T &x, S y) { if (y < x) x = y; }

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout << fixed << setprecision(16);
  string s;
  cin >> s;
  int ans = 1e9;
  rep(i, 26) {
    char c = 'a' + i;
    int cnt = 0;
    string t = s;
    while (true) {
      bool b = true;
      rep(j, t.size()) if (t[j] != c) b = false;
      if (b) break;
      string temp = "";
      rep(j, t.size() - 1) {
        if (t[j] == c || t[j + 1] == c) temp += c;
        else temp += '?';
      }
      t = temp;
      cnt++;
    }
    amin(ans, cnt);
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 256
#include<stdio.h>
    
int S[1000000000],N;

int Search(int key){
int left=0;
int right=N;
int mid;
int s[10000000000];
while(left<right){
mid=(left+right)/2;
if(key==S[mid])
return 1;
if(key>S[mid])
left=mid+1;
else if(key<S[mid])
right=mid;
}
 
return 0;
 
}
 
int main(){
   
int i,k,q; 
int count = 0;
    
scanf("%d", &N);
for ( i = 0; i < N; i++ )
scanf("%d", &S[i]);

     
 scanf("%d", &q);
 for ( i = 0; i < q; i++ ){ 
scanf("%d", &k);
if(Search(k)==1)
count++;
}
    printf("%d\n",count);
    return 0;
}

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

using namespace std;

void devide(int &a, int &cnt) {
  if (a % 2 == 0) {
    a /= 2;
    ++cnt;
    devide(a, cnt);
  }
}

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

  int n;
  cin >> n;

  // vector<int> a(n);
  int cnt = 0;
  for (int i = 0; i < n; ++i) {
    int a;
    cin >> a;
    devide(a, cnt);
  }

  // bool ok = true;
  // while (ok) {
  //   ok = false;
  //   for (int i = 0; i < n; ++i) {
  //     if (a[i] % 2 == 0) {
  //       a[i] /= 2;
  //       ok = true;
  //       ++cnt;
  //       break;
  //     }
  //   }
  // }

  cout << cnt << '\n';

  return 0;
}


Measured memory_bytes: 3528
// Changing a Character
#include <iostream>
#include <vector>
#include <string>
#include <stack>
#include <queue>

using namespace std;
int main()
{
    int N,K;
    cin >> N >> K;
    string S;
    cin >> S;
    int d = 'a' - 'A';
    S[K-1] = S[K-1] + d;
    cout << S << endl;

    return 0;
}

Measured memory_bytes: 256
/************************************
/ AUTHOR : YATHARTH GOSWAMI         /  
/ ALIAS : hacker_yg                 /
/ INSTITUTE : IIT Kanpur            /
************************************/
//          TEMPLATE                //

#include <bits/stdc++.h>

#define ll long long
#define MOD 1000000007
#define pb push_back
#define mp make_pair
#define F first
#define S second
#define PI 3.14159265359

using namespace std;

/*ll powMod(ll a, ll y)
{
    ll ans = 1;
    
    while (y > 0) 
    { 
        if (y & 1) 
            ans = (ans*a) % MOD; 
  
        y = y>>1;
        a = (a*a) % MOD; 
    } 
    return ans;
}*/

/*ll modInv(ll a)
{
    return powMod(a, MOD-2);	
}*/

int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(0); cout.tie(0);
    int x;
    cin >> x;
    int prime[200005];
    prime[0] = 0;
    prime[1] = 0;
    for (int i = 2; i < 200005; i++) prime[i] = 1;
    for (int i = 2; i < 200005; i++) {
        int j = 2;
        while (i*j <= 200005) {
            prime[i*j] = 0;
            j++;
        }
    }
    while (prime[x] != 1) x++;
    cout << x << endl;
    return 0;
}




Measured memory_bytes: 1024
N, M = map(int, input().split())
S = list(map(int, input().split()))
T = list(map(int, input().split()))

MOD = 10**9+7

dp = [[0 for i in range(M+1)] for j in range(N+1)] # dp[i][j] : S[i]とT[j]が末尾に来る部分集合の数
dp_sum = [[0 for i in range(M+1)] for j in range(N+1)] # dp[i][j]の総和

# 一旦空集合＋空集合は考えない
ret = 0
for i, s in enumerate(S):
    for j, t in enumerate(T):
        if s == t:
            dp[i+1][j+1] = dp_sum[i][j] + 1 # S[i]とT[j]を使ってないものの総和にS[i]とT[j]だけの組み合わせを足す
        dp_sum[i+1][j+1] = (dp[i+1][j+1] + dp_sum[i][j+1] + dp_sum[i+1][j] - dp_sum[i][j]) % MOD
        
print(dp_sum[N][M]+1)#最後に空集合＋空集合を加える



Measured memory_bytes: 107996
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<vector>
using namespace std;
typedef long long ll;

int main(void)
{
	ll a,v, b,w, t;
	scanf("%lld%lld%lld%lld%lld",&a,&v,&b,&w,&t);
	
	if(a==b){ printf("YES\n"); return 0;}
	
	ll x = a-b;
	if(x<0) x=-x;
	
	if(v*t - w*t >= x) printf("YES");
	else printf("NO");
	return 0;
}

Measured memory_bytes: 1732
n = int(input())
li_p = list(map(int, input().split()))

answer = 0
mi = -1
for idx, p in enumerate(li_p):
    if idx == 0:
        mi = p
        answer += 1
    else:
        if p <= mi:
            answer += 1
        mi = min(mi, p)
print(answer)



Measured memory_bytes: 24744
import sys
input = sys.stdin.readline
N = int(input())
A = list(map(int,input().split()))

if A[0] != 0:
    if A[0] == 1 and N == 0:
        print(1)
    else:
        print(-1)
    exit()

B = [0]*(N+1)
B[0] = 1

for i in range(N):
    B[i+1] = 2*(B[i]-A[i])
    if max(B[i]-A[i],A[i+1]) > B[i+1]:
        print(-1)
        exit()

C = [0]*(N+2)
for i in range(N,-1,-1):
    C[i] = C[i+1] + A[i]
C = C[:-1]

D = [min(b,c) for b,c in zip(B,C)]
print(sum(D))

    




Measured memory_bytes: 708156
package main

import (
  "fmt"
)

func main() {
  var n int 
  fmt.Scan(&n)
  a := make([]int, n)
  b := make([]int, n)
  c := make([]int, n-1)
  for i := 0; i < n; i++ {fmt.Scan(&a[i]); a[i]--}
  for i := 0; i < n; i++ {fmt.Scan(&b[i])}
  for i := 0; i < n-1; i++ {fmt.Scan(&c[i])}
  prev := -100
  res := 0
  for _, x := range a {
    res += b[x]
    if prev == x - 1 {res += c[prev]}
    prev = x
  }
  fmt.Println(res)
}

Measured memory_bytes: 512
#include "bits/stdc++.h"
#include<unordered_map>
#include<unordered_set>
#pragma warning(disable:4996)
using namespace std;
using ld = long double;
template<class T>
using Table = vector<vector<T>>;
const ld eps = 1e-9;
//// < "D:\D_Download\Visual Studio 2015\Projects\programing_contest_c++\Debug\a.txt" > "D:\D_Download\Visual Studio 2015\Projects\programing_contest_c++\Debug\b.txt"

long long int gcd(long long int l, long long int r) {
	assert(l > 0 && r > 0);
	if (l > r)return gcd(r, l);
	else {
		const long long int num = r%l;
		if (num) {
			return gcd(l, num);
		}
		else {
			return l;
		}
	}
}
long long int lca(long long int l, long long int r) {
	return l / gcd(l, r)*r;
}

struct mobi {
	long long int a;
	long long int b;
	int lid;
	int rid;

};

long long int getans(const int id,const vector<mobi>&ms) {
	long long int lw=0, rw=0;
	if (ms[id].lid!=-1) {
		lw = getans(ms[id].lid, ms);
	}
	else {
		lw = 1;
	}
	if (ms[id].rid != -1) {
		rw = getans(ms[id].rid, ms);
	}
	else {
		rw = 1;
	}
	long long int al = lw*ms[id].a;
	long long int ar = rw*ms[id].b;
	long long int alca = lca(al, ar);
	return alca / al*lw + alca / ar*rw;
}

int main() {
	while (1) {
		int N; cin >> N;
		if (!N)break;
		vector<mobi>ms;
		vector<int>pas(N);
		for (int i = 0; i < N; ++i) {
			long long int a, b;int lid, rid; cin >> a >> b >> lid >> rid;
			lid--; rid--;
			if (lid != -1)pas[lid] = true;
			if (rid != -1)pas[rid] = true;
			const long long int agcd = gcd(a, b);
			a /= agcd; b /= agcd;
			ms.push_back(mobi{ a,b,lid,rid });
		}
		int nopa = find(pas.begin(), pas.end(), 0) - pas.begin();
		long long int ans = getans(nopa, ms);
		cout << ans << endl;
	}
	return 0;
}

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

using namespace std;


int main(void) {
	int N; cin >> N;
	string S;
	int  x[N] = { 0 }, y[N] = { 0 };
	int i, d[N] = { 0 };
	for (i = 0; i < N; i++) {
		cin >> S;
	}
	for (i = 0; i < N; i++) {
		if (S[i] == 'W') {
			x[i] += 1;
		}
		if (S[N - i - 1] == 'E')
			y[N - i - 1] += 1;
	}

	for (i = 0; i < N-1; i++) {
		x[i+1] += x[i];
		y[N - i - 2] += y[N - i - 1];
	}

	for (i = 0; i < N; i++) {
		d[N-i-1] = x[N-i-1] + y[N-i-1];
	}

	sort(d, d + N);

	cout << d[0]-1 << endl;

	return 0;
}

Measured memory_bytes: 4356
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define ll long long
int main(){
    int k;
    string s;
    cin >> k >> s;
    if(s.size() <= k){
        cout << s << endl;
    }
    else{
        rep(i,k){
            cout << s[i] ;
        }
        cout << "..." <<endl;
    }
    return 0;
    
    
}

Measured memory_bytes: 3632
def motomeruyuo():
    d = deque([(0, 1, [1])])
    num_list = [float('inf') for i in range(2001)]
    num_list[1] = 0
    
    while d:
        times, now, nums = d.popleft()

        for i in nums:
            tmp = i + now
            if tmp > 2000:
                continue
            if num_list[tmp] >= times:
                num_list[tmp] = times
                d.append((times + 1, tmp, nums + [tmp]))

        for i in nums:
            tmp = max(now - i, i - now)
            if tmp <= 0:
                continue
            if num_list[tmp] >= times:
                num_list[tmp] = times
                d.append((times + 1, tmp, nums + [tmp]))
        
    return num_list

from collections import deque

ans = []

num_list = motomeruyuo()
while True:
    a = int(input())
    if not a:
        break
    
    if a == 1:
        ans.append(num_list[a])
    else:
        ans.append(num_list[a] + 1)

[print(i) for i in ans]



Measured memory_bytes: 322680
#include <bits/stdc++.h>
#define REP(i, n) for(int64_t i = 0; i < n; i++)
#define REPR(i, n) for(int64_t i = n; i >= 0; i--)
#define FOR(i, m, n) for(int64_t i = m; i < n; i++)
#define ALL(v) v.begin(), v.end()
using namespace std;
typedef long long ll;
const ll LINF=1e18;
const int INF=1e9;
template<typename A, size_t N, typename T>
void Fill(A (&array)[N], const T &val){
    fill( (T*)array, (T*)(array+N), val );
}

int main(){
    int N;
    cin >> N;
    FOR(i, 1, 10)
        FOR(j, 1, 10)
            if(i*j==N){cout << "Yes" << endl;return 0;}
    cout << "No" << endl;
    return 0;
}

Measured memory_bytes: 256
#define _USE_MATH_DEFINES

#include <cstdio>
#include <cstdlib>
#include <iostream>
#include <cmath>
#include <cstring>
#include <algorithm>
#include <vector>
#include <queue>
#include <map>
#include <set>
#include <unordered_map> 
#include <unordered_set>
#include <functional>

using namespace std;

typedef pair<long long int, long long int> P;
typedef tuple<int, int, int> T;

long long int INF = 1e18;
long long int MOD = 1e9 + 7;

int A[16][16];

int main(){
	int N;
	cin >> N;
	for(int i = 0; i < N; i++){
		int num;
		cin >> num;
		for(int j = 0; j < num; j++){
			int x, y;
			cin >> x >> y;
			A[i][x - 1] = y * 2 - 1;
		}
	}
	long long int ans = 0;
	for(int i = 0; i < (1 << N); i++){
		bool flag = true;
		for(int j = 0; j < N; j++){
			for(int k = 0; k < N; k++){
				if(i & (1 << j)){
					if(A[j][k] == 1 && (i & (1 << k)) == 0){
						flag = false;
					}
					if(A[j][k] == -1 && (i & (1 << k))){
						flag = false;
					}
				}
			}
		}
		if(flag){
			long long int cnt = 0;
			for(int j = 0; j < N; j++){
				if(i & (1 << j)){
					cnt += 1;
				}
			}
			ans = max(ans, cnt);
		}
	}
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 256
xarr = [] 
yarr = []
while true
  x, y = gets.split.map(&:to_i)
  break if x.zero? && y.zero?
  xarr.push(x)
  yarr.push(y)
end

xarr.zip(yarr) do |x, y|
  if x < y
    puts x.to_s + " " + y.to_s
  else
    puts y.to_s + " " + x.to_s
  end
end



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

int main(int argc, char **argv)
{
    long long X;

    std::cin >> X;

    long long m = 100;
    long long n = 0;
    for(;;){
        if(m >= X){
            std::cout << n << std::endl;
            return 0;
        }
        m = (long long)(m * 1.01);
        n++;
    }

    
}


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

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

int main() {
	int n; ll d, a;
	cin >> n >> d >> a;
	vector<P>p(n);
	for (int i = 0; i < n; i++) {
		cin >> p[i].first >> p[i].second;
	}
	sort(p.begin(), p.end());
	d = d * 2;
	ll tot = 0;
	queue<pair<ll, ll>>q;
	ll ans = 0;
	for (int i = 0; i < n; i++) {
		ll x = p[i].first;
		ll h = p[i].second;
		while (q.size() && q.front().first < x) {
			tot -= q.front().second;
			q.pop();
		}
		h -= tot;
		if (h > 0) {
			ll num = (h + a - 1) / a;
			ans += num;
			ll damage = num * a;
			tot += damage;
			q.emplace(x + d, damage);
		}
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 3456
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef pair<int, int> ii;
typedef vector<ii> vii;
#define pb push_back
#define mp make_pair
#define ms memset
#define FOR(i, a, b) for(int i = a; i <= b; i++)
#define lower_bound lb
#define upper_bound ub

int main()
{
    int n; cin >> n;
    int m = 1999-n; m/= 200; m++;
    cout << m << '\n';
    return 0;
}

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

#define int long long
typedef vector<int>vint;
typedef pair<int,int>pint;
typedef vector<pint>vpint;
#define rep(i,n) for(int i=0;i<(n);i++)
#define reps(i,f,n) for(int i=(f);i<(n);i++)
#define all(v) (v).begin(),(v).end()
#define each(it,v) for(__typeof((v).begin()) it=(v).begin();it!=(v).end();it++)
#define pb push_back
#define fi first
#define se second
template<typename A,typename B>inline void chmin(A &a,B b){if(a>b)a=b;}
template<typename A,typename B>inline void chmax(A &a,B b){if(a<b)a=b;}

int N,M;
bool used[222222];
signed main(){
    cin>>N>>M;
    vint v(M);rep(i,M)cin>>v[i],v[i]--;
    reverse(all(v));rep(i,N)v.pb(i);
    rep(i,v.size()){
        if(used[v[i]])continue;
        used[v[i]]=true;
        printf("%lld\n",v[i]+1);
    }

    return 0;
}

Measured memory_bytes: 5820
import Control.Applicative
import Control.Monad
import Data.List
import qualified Data.IntSet as IS

main :: IO ()
main = do
  [n, k] <- f
  solve n <$> replicateM k (getLine >> f) >>= print
  where
    f = map read <$> words <$> getLine

solve :: Int -> [[Int]] -> Int
solve n = (n -) . IS.size . foldl' (foldl' (flip IS.insert)) IS.empty 


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

using namespace std;

const ll Mod = 1e9 + 7;

ll a[110];
ll Dp[110][100100];

int main()
{
    ll n,k; cin>>n>>k;

    for(ll i=1;i<=n;i++)    scanf("%I64d",a+i);

    Dp[0][0] = 1;

    for(ll K=1;K<=k;K++)    Dp[0][K] += Dp[0][K-1];

    for(ll i=1;i<=n;i++)
    {
        for(ll K=0;K<=k;K++)    Dp[i][K] = ( Dp[i-1][K] - ( K>a[i] ? Dp[i-1][K-a[i]-1] : 0 ) + 3*Mod )%Mod;
        for(ll K=1;K<=k;K++)    Dp[i][K] = (Dp[i][K] + Dp[i][K-1])%Mod;
    }

    ll Answer = ( Dp[n][k] - Dp[n][k-1] + Mod )%Mod;

    cout<<Answer;
}


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

// macro
#define rep(i,n) for(i=0;i<n;i++)
#define ll long long
#define all(v) v.begin(), v.end()

// code starts
#define N 10000
vector<int> par(N);
vector<int> ranks(N);

void init(int n)
{
  int i;
  rep(i,n)
  {
    par[i]=i;
    ranks[i]=0;
  }
}

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

void unite(int x,int y)
{
  x=find(x);
  y=find(y);
  if(x==y)return;
  if(ranks[x]<ranks[y])
  {
    par[x]=y;
  }
  else
  {
    if(ranks[x]==ranks[y])
    {
      ranks[x]++;
    }
    par[y]=x;
  }
}

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

int main()
{
  int n,q;cin>>n>>q;
  int i;
  init(n);
  rep(i,q)
  {
    int com;cin>>com;
    int x,y;cin>>x>>y;
    if(com==0)
    {
      unite(x,y);
    }
    if(com==1)
    {
      if(same(x,y))cout<<1<<endl;
      else cout<<0<<endl;
    }
  }
}



Measured memory_bytes: 3164
import java.util.Scanner;

public class Main {
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);

        int a = sc.nextInt();
        int b = sc.nextInt();

        if(a>b) {
            System.out.println("a > b");
        }else if(a<b) {
            System.out.println("a < b");
        }else{
            System.out.println("a == b");
        }
    }
}


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

int main (){
  int X;
  cin >> X;
  int ans = 0, hap = 0;
  hap += X / 500 * 1000;
  ans = X % 500;
  hap += ans / 5 * 5;
  cout << hap << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main()
{
    long long a,b,c,i,j;
    cin>>a>>b>>c>>i>>j;
     if(a==0)cout<<1<<endl;
     if(b==0)cout<<2<<endl;
     if(c==0)cout<<3<<endl;
     if(i==0)cout<<4<<endl;
     if(j==0)cout<<5<<endl;

}


Measured memory_bytes: 3632
#line 1 "/mnt/c/Users/leafc/dev/compro/lib/template.hpp"


#include <bits/stdc++.h>
#define REP(i, n) for (int i = 0; i < n; i++)
#define FOR(i, m, n) for (int i = m; i < n; i++)
#define ALL(v) (v).begin(), (v).end()
#define coutd(n) cout << fixed << setprecision(n)
#define ll long long int
#define vl vector<ll>
#define vi vector<int>
#define MM << " " <<

using namespace std;

template <class T> void say(bool val, T yes = "Yes", T no = "No") { cout << (val ? yes : no) << endl; }

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

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


#line 2 "tmp.cpp"

int f(int mid, int x, int n, vl &a) {
  return ((n + 1) / 2) >= mid && abs(x - a[max(0, n - mid)]) >= abs(x - a[max(n - 2 * mid + 1, 0)]);
}

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

  int n, q;
  cin >> n >> q;
  vl a(n);
  REP(i, n) { cin >> a[i]; }

  vl cum0(n + 1, 0), cum1(n + 1, 0), cuminv(n + 1, 0);
  REP(i, n) {
    if (i % 2 == 0) {
      cum0[i + 1] = cum0[i] + a[i];
      cum1[i + 1] = cum1[i];
    } else {
      cum0[i + 1] = cum0[i];
      cum1[i + 1] = cum1[i] + a[i];
    }
  }

  REP(i, n) { cuminv[i + 1] = cuminv[i] + a[n - i - 1]; }

  REP(i, q) {
    int x;
    cin >> x;
    int ok = 1, ng = n;
    while (abs(ok - ng) > 1) {
      int mid = (ok + ng) / 2;
      if (f(mid, x, n, a)) {
        ok = mid;
      } else {
        ng = mid;
      }
    }

    ll ans = cuminv[ok];
    if (2 * ok < n) {
      if ((n - 2 * ok) % 2 == 0) {
        ans += cum1[n - 2 * ok];
      } else {
        ans += cum0[n - 2 * ok];
      }
    }
    cout << ans << endl;
  }
  return 0;
}


Measured memory_bytes: 4992
#include<iomanip>
#include<limits>
#include<thread>
#include<utility>
#include<iostream>
#include<string>
#include<algorithm>
#include<set>
#include<map>
#include<vector>
#include<stack>
#include<queue>
#include<cmath>
#include<numeric>
#include<cassert>
#include<random>
#include<chrono>
#include<unordered_set>
#include<unordered_map>
#include<fstream>
#include<list>
#include<functional>
#include<bitset>
#include<complex>
#include<tuple>
using namespace std;
typedef unsigned long long int ull;
typedef long long int ll;
typedef pair<ll,ll> pll;
typedef long double D;
#define F first
#define S second
const ll E=1e18+7;
const ll MOD=1000000007;


int main(){
    ll n;
    while(cin>>n){
        if(n==0){break;}
    string s;
    cin>>s;
    vector<vector<bool>> dp(10,vector<bool>(1LL<<10,false));
    ll k=0;
    bool j=false;
    for(int i=0;i<s.size();i++){
        if(s[i]=='u'){k=0; continue;}
        if(i+1==s.size() || s[i+1]=='u'){continue;}
        k|=1LL<<(s[i]-'0');
        ll n=s[i+1]-'0';
        if(k>>n&1){j=true;}
        dp[n][k]=true;
    }
    for(ll i=0;i<(1LL<<10) && !j;i++){
        for(int t=0;t<10;t++){
            if(dp[t][i]==false){continue;}
            ll z=((1LL<<10)-1)^i;
            for(ll k=z;k>0;k=(k-1)&z){
                if((k>>t&1)==0){continue;}
                for(int h=0;h<10;h++){
                    if(dp[h][k]){
                        dp[h][i^k]=true;
                        if((i^k)>>h&1){j=true;}
                    }
                }
            }
            for(int h=0;h<10;h++){
                if(dp[h][0]){
                    dp[h][i]=true;
                    if(i>>h&1){j=true;}
                }
            }
        }
    }
    cout<<(j?"UNSAFE":"SAFE")<<endl;
    }
    
    
    return 0;
}



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

typedef long long ll;
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<long long> VL;
typedef vector<vector<long long>> VVL;
typedef pair<int,int> P;
typedef tuple<int,int,int> tpl;

#define ALL(a)  (a).begin(),(a).end()
#define SORT(c) sort((c).begin(),(c).end())
#define REVERSE(c) reverse((c).begin(),(c).end())
#define EXIST(m,v) (m).find((v)) != (m).end()
#define LB(a,x) lower_bound((a).begin(), (a).end(), x) - (a).begin()
#define UB(a,x) upper_bound((a).begin(), (a).end(), x) - (a).begin()

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)
#define RFOR(i,a,b) for(int i=(a)-1;i>=(b);--i)
#define RREP(i,n) RFOR(i,n,0)

#define en "\n"

constexpr double EPS = 1e-9;
constexpr double PI  = 3.1415926535897932;
constexpr int INF = 2147483647;
constexpr long long LINF = 1LL<<60;
constexpr long long MOD = 998244353;

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

void Main(){
    int N,K; cin >> N >> K;
    VI L(K), R(K); REP(i,K) cin >> L[i] >> R[i];
    ll dp[N+2]; REP(i,N+2) dp[i] = 0; dp[0] = 1;

    REP(i,N-1){
        (dp[i+1] += dp[i]) %= MOD;
        REP(j,K){
            int l = min(N+1, i+1 + L[j]);
            int r = min(N+1, i+1 + R[j]+1);
            (dp[l] += dp[i+1]) %= MOD;
            dp[r] -= dp[i+1];
            if(dp[r]<0) dp[r] += MOD;
        }
    }

    int ans = dp[N];
    cout << ans << en;
    return;
}

int main(void){
    cin.tie(0);cout.tie(0);ios_base::sync_with_stdio(0);cout<<fixed<<setprecision(15);
    int t=1; //cin>>t;
    REP(_,t) Main();
    return 0;
}

Measured memory_bytes: 5216
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <cstring>
#include <complex>
#include <stack>
#include <queue>
#include <unordered_map>
#include <map>
using namespace std;
 
int main() {
    double n, k;
    cin >> n >> k;

    double i;

    double ans = 0;
    
    if(n < k){
        for(i = 1; i <= n; i++){
            ans += (double)(1 / (double)pow(2, ceil(log2(k/i))));
        }
        printf("%.12lf\n", ans/n);
    }else{
        for(i = 1; i < k; i++){
            ans += (double)(1 / (double)(pow(2, ceil(log2(k/i)))));
        }
        ans += (n-k+1);
        printf("%.12lf\n", ans/n);
    }
}


Measured memory_bytes: 512
#include <iostream>
using namespace std;
#define ll long long
int g,p,a,b;
int main()
{	
	string s;
	cin >> s;
	
	for(int i=0; i<s.size(); i++)
	{
		if(s[i]=='g')
		{
			if(p<g)
			p++,a++;
			else
			g++;
		}
		else if(s[i]=='p')
		{
			if(p<g)
			p++;
			else
			g++,b++;
		}
	}
	cout << a-b;
}

Measured memory_bytes: 512
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <functional>
#include <bitset>
#include <cmath>
#include <stack>
#include <iomanip>
typedef long long ll;
using namespace std;

const int MOD = 1000000007;
ll GCD(ll a, ll b) { return b ? GCD(b, a%b) : a; }

int main()
{
    ll A,B,C,D;
    cin >> A >> B >> C >>D;
    ll gcd = GCD(C,D);
    ll l = C / gcd * D;
    ll underB;
    ll underAm1;
    underB = B - (B/C + B/D - B/l);
    underAm1 = A- 1 - ((A - 1)/C + (A -1)/D - (A -1)/l);
    cout << underB - underAm1 << endl;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define ll long long
#define ALL(v) (v).begin(),(v).end()
#define REP(i,p,n) for(int i=p;i<(int)(n);++i)
#define rep(i,n) REP(i,0,n)
#define dump(a) (cerr << #a << "=" << (a) << endl)
#define DUMP(list) cout << "{ "; for(auto nth : list){ cout << nth << " "; } cout << "}" << endl;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }

using namespace std;
typedef pair<ll, ll> pint;

const int MOD = 1000000007;
void yesno(bool b) {
    if (b) {
        cout << "Yes" << endl;
    }     else {
        cout << "No" << endl;
    }
}
int N, M;
vector<int> G[100005];
int ans[100005];


int main() {
    cin >> N >> M;
    rep(i, M) {
        int A, B;
        cin >> A >> B;
        A--; B--;
        G[A].push_back(B);
        G[B].push_back(A);
    }
    rep(i, N) {
        ans[i] = -2;
    }

    queue<pint> q;
    q.push(make_pair(0, 0));
    while(!q.empty()) {
        pint p = q.front();
        q.pop();
        if (ans[p.first] == -2) {
            ans[p.first] = p.second;
            rep(i, G[p.first].size()) {
                if (ans[G[p.first][i]] == -2) {
                    q.push(make_pair(G[p.first][i], p.first));
                }
            }
        }
    }
    cout << "Yes" << endl;
    rep(i, N-1) {
        cout << ans[i+1] + 1 << endl;
    }

}


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

#define rep(i,n) for(int i=0;i<(n);i++)

typedef long long ll;

#define REP(i,n) for(ll i=0;i<(ll)(n);i++)
#define REPD(i,n) for(ll i=n-1;i>=0;i--)
#define FOR(i,a,b) for(ll i=a;i<=(ll)(b);i++)
#define FORD(i,a,b) for(ll i=a;i>=(ll)(b);i--)
//定数
//#define INF 1000000000000 //10^12:極めて大きい値,∞
//略記
#define PB push_back //vectorヘの挿入
#define MP make_pair //pairのコンストラクタ
#define F first //pairの一つ目の要素
#define S second //pairの二つ目の要素

int ydir[]={ 1, 0, 0,-1};
int xdir[]={ 0, 1,-1, 0};

struct POS{
    int y;
    int x;
    POS(int y,int x): y(y), x(x) {}
};

int main(){
    int H,W;
    cin>>H>>W;
    vector<vector<int>> mazeo(H, vector<int>(W,0));
    vector<vector<int>> maze(H, vector<int>(W,0));
    rep(h,H){
        string s;
        cin>>s;
        rep(w,W){
            if(s[w]=='#')mazeo[h][w]=-1;
        }
    }
    int mk=0;
    rep(h,H){
        rep(w,W){
//            cout<<h<<" "<<w<<endl;
            maze=mazeo;
            queue<POS> q;
            if(maze[h][w]==-1) continue;
            maze[h][w]=1;
            q.emplace(h,w);
            while(!q.empty()>0){
                POS pos=q.front();
//                cout<<"out"<<pos.y<<" "<<pos.x<<endl;
                q.pop();
                int k=maze[pos.y][pos.x];
                mk=max(mk,k);
                k++;
                rep(i,4){
                    int y=pos.y+ydir[i];
                    int x=pos.x+xdir[i];
                    if(y<0 || y>=H || x<0 || x>=W) continue;
                    if(maze[y][x]!=0) continue;
                    maze[y][x]=k;
                    q.emplace(y,x);
//                    cout<<"in "<<y<<" "<<x<<endl;
                }
            }
        }

    }

    cout << mk-1 << endl;
    return 0;
}


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

#define rep(i,s,n) for(ll i = (s); i < (n); i++)
#define rep0(i,n) rep(i,0,n)
#define rep1(i,n) rep(i,1,n+1)
#define repR(i,s,n) for(ll i = (n-1); i >= (s); i--)
#define repR0(i,n) repR(i,0,n)
#define repR1(i,n) repR(i,1,n+1)

#define BR "\n"
#define SP " "
#define SHOW(x) for(int i = 0; i < x.size(); i++) { cout << x[i] << SP; } cout << BR;
#define SHOW2(x) for(int j = 0; j < x.size(); j++) { SHOW(x[j]); } cout << BR;
#define fcout cout << fixed << setprecision(18)

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

int a[100];
int cells[100][100]; // r * c

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

  vector<ll> A(N);
  rep0(i, N) cin >> A[i];

  vector<ll> S(N + 1, 0);
  rep1(i, N) {
    S[i] = S[i - 1] + A[i - 1];
  }
  ll SUM = S[N];

  ll ans = SUM;
  rep(i, 1, N) {
    ll temp = SUM - S[i] * 2;
    ans = min(ans, abs(temp));
  }

  cout << ans << BR;
  return 0;
}

Measured memory_bytes: 3328
#include<bits/stdc++.h>
using namespace std;
#define all(a)  (a).begin(),(a).end()
typedef long long ll;
const ll mod=1000000007;
#define repi(i,a,b) for(int i=int(a);i<int(b);++i)

int main() {
  string s,t;cin >>s>>t;
  int n =0;
  repi(i,0,3){
    string s1 = s.substr(i,1);
    string t1 = t.substr(i,1);
    if(s1==t1) ++n;
  }
  cout << n << endl;
  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <algorithm>
#include <cstdio>
#include <utility>
#include <string>
#include <cmath>
#include <cstdlib>
#include <cstring>
#include <deque>
#include <numeric>

using namespace std;

typedef uint64_t u64;
typedef int64_t s64;
typedef uint32_t u32;
typedef int32_t s32;
typedef vector<s32> vs32;
typedef vector<u32> vu32;
typedef vector<s64> vs64;
typedef vector<u64> vu64;

const double PI=3.14159265358979323846;

#define MAX(x, y) ((x) < (y) ? (y) : (x))
#define MIN(x, y) ((x) > (y) ? (y) : (x))

#define rep(i, N) for(int i = 0; i < N; ++i)

#define CEIL(x, y) (((x) + (y) - 1) / (y))
#define MOD 1000000007ULL

#define IN(l, r, x) ((l) <= (x) && (x) < (r))


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

    int x;
    rep (i, 5)
    {
        cin >> x;
        if (x == 0)
        {
            cout << i + 1 << "\n";
            return 0;
        }
    }

    return 0;
}



Measured memory_bytes: 3640
#include <iostream>

int main()
{
	int n;
	std::cin >> n;
	
	unsigned long long s = 0;
	for (int i = 1; i <= n; i++) {
		if (i % 3 != 0 && i % 5 != 0) {
			s += i;
		}
	}
	
	std::cout << s << std::endl;
	
	return 0;
}


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

using namespace std;
using ll = long long;
 
#define rep(i, n)      for (int i = 0; i < (n); i++)
#define repr(i, n)     for (int i = (n) - 1; i >= 0; i--)
#define repe(i, l, r)  for (int i = (l); i < (r); i++)
#define reper(i, l, r) for (int i = (r) - 1; i >= (l); i--)
#define repi(i, l, r)  for (int i = (l); i <= (r); i++)
#define repir(i, l, r) for (int i = (r); i >= (l); i--)
#define range(a) a.begin(), a.end()
void initio() { cin.tie(nullptr); ios::sync_with_stdio(false); cout << fixed << setprecision(15); }

constexpr int MOD = 1000000007;

class mint {
  int n;
public:
  mint(int n_ = 0) : n(n_) {}
  explicit operator int() { return n; }
  friend mint operator-(mint a) { return -a.n + MOD * (a.n != 0); }
  friend mint operator+(mint a, mint b) { int x = a.n + b.n; return x - (x >= MOD) * MOD; }
  friend mint operator-(mint a, mint b) { int x = a.n - b.n; return x + (x < 0) * MOD; }
  friend mint operator*(mint a, mint b) { return (long long)a.n * b.n % MOD; }
  friend mint &operator+=(mint &a, mint b) { return a = a + b; }
  friend mint &operator-=(mint &a, mint b) { return a = a - b; }
  friend mint &operator*=(mint &a, mint b) { return a = a * b; }
  friend bool operator==(mint a, mint b) { return a.n == b.n; }
  friend bool operator!=(mint a, mint b) { return a.n != b.n; }
  friend istream &operator>>(istream &i, mint &a) { return i >> a.n; }
  friend ostream &operator<<(ostream &o, mint a) { return o << a.n; }
};

int main() {
  int N; cin >> N;
  vector<int> A(N); rep(i, N) cin >> A[i];
  vector<int> now(3, 0);
  mint ans = 1;
  for (int x : A) {
    int k = count(range(now), x);
    ans *= k;
    int f = find(range(now), x) - now.begin();
    now[f]++;
  }
  cout << ans << endl;
}


Measured memory_bytes: 640