akhauriyash/Code-Regression huggingface dataset:
N=int(input())
H=list(map(int,input().split()))
f=0
if N==1:
  print("Yes")
else:
  for i in range(N-1,0,-1):
    if H[i-1]-H[i]>1:
      print("No")
      f=1
      break
    elif H[i-1]-H[i]==1:
      H[i-1]=H[i-1]-1
  if f!=1:
    print("Yes")

Measured memory_bytes: 14396
//#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
#define int long long
#define ll long long
using ull = unsigned long long;
using namespace std;
#define dump(x)                             \
    if (dbg) {                              \
        cerr << #x << " = " << (x) << endl; \
    }
#define overload4(_1, _2, _3, _4, name, ...) name
#define FOR1(n) for (ll i = 0; i < (n); ++i)
#define FOR2(i, n) for (ll i = 0; i < (n); ++i)
#define FOR3(i, a, b) for (ll i = (a); i < (b); ++i)
#define FOR4(i, a, b, c) for (ll i = (a); i < (b); i += (c))
#define FOR(...) overload4(__VA_ARGS__, FOR4, FOR3, FOR2, FOR1)(__VA_ARGS__)
#define FORR(i, a, b) for (int i = (a); i <= (b); ++i)
#define bit(n, k) (((n) >> (k)) & 1) /*nのk bit目*/
namespace mydef {
const int INF = 1ll << 60;
const int MOD = 1e9 + 7;
template <class T>
bool chmin(T& a, const T& b) {
    if (a > b) {
        a = b;
        return 1;
    } else
        return 0;
}
template <class T>
bool chmax(T& a, const T& b) {
    if (a < b) {
        a = b;
        return 1;
    } else
        return 0;
}
void Yes(bool flag = true) {
    if (flag)
        cout << "Yes" << endl;
    else
        cout << "No" << endl;
}
void No(bool flag = true) {
    Yes(!flag);
}
void YES(bool flag = true) {
    if (flag)
        cout << "YES" << endl;
    else
        cout << "NO" << endl;
}
void NO(bool flag = true) {
    YES(!flag);
}
template <typename A, size_t N, typename T>
void Fill(A (&array)[N], const T& val) {
    std::fill((T*)array, (T*)(array + N), val);
}
bool dbg = true;
}  // namespace mydef
using namespace mydef;
#define pb push_back
//#define mp make_pair
#define eb emplace_back
#define lb lower_bound
#define ub upper_bound
#define all(v) (v).begin(), (v).end()
#define SZ(x) ((int)(x).size())
#define vi vector<int>
#define vvi vector<vector<int>>
#define vp vector<pair<int, int>>
#define vvp vector<vector<pair<int, int>>>
#define pi pair<int, int>
//#define P pair<int, int>
//#define V vector<int>
//#define S set<int>
#define asn ans

int G[10][10];
int N, M;


void solve() {
    vi V(N);
    iota(all(V), 0);
    int ans = 0;
    do {
        if (V[0] != 0)
            break;
        int flag = 1;
        for (int i = 0; i < N - 1; i++) {
            if (!G[V[i]][V[i + 1]])
                flag = 0;
        }
        ans += flag;
    } while (next_permutation(all(V)));
    cout << ans << endl;
}

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

    cin >> N >> M;
    for (int i = 0; i < M; i++) {
        int a, b;
        cin >> a >> b;
        G[--a][--b]++;
        G[b][a]++;
    }

    solve();
    return 0;
}


Measured memory_bytes: 3624
#include <bits/stdc++.h>
using namespace std;
/*{{{*/  //template
#define rep(i,n) for(int i=0;i<n;i++)
constexpr int INF = numeric_limits<int>::max()/2;
constexpr long long LINF = numeric_limits<long long>::max()/3;
#define mp make_pair
#define pb push_back
#define eb emplace_back
#define fi first
#define se second
#define all(v) (v).begin(),(v).end()
#define sz(x) (int)(x).size()
#define debug(x) cerr<<#x<<":"<<x<<endl
#define debug2(x,y) cerr<<#x<<","<<#y":"<<x<<","<<y<<endl
//struct fin{ fin(){ cin.tie(0); ios::sync_with_stdio(false); } } fin_;
struct Double{ double d; explicit Double(double x) : d(x){} };
ostream& operator<<(ostream& os,const Double x){ os << fixed << setprecision(20) << x.d; return os; }
template<typename T> ostream& operator<<(ostream& os,const vector<T>& vec){ os << "["; for(const auto& v : vec){ os << v << ","; } os << "]"; return os; }
template<typename T,typename U> ostream& operator<<(ostream& os,const pair<T,U>& p){ os << "(" << p.first << ","<< p.second <<")"; return os; }
template<typename T> ostream& operator<<(ostream& os,const set<T>& st){ os<<"{"; for(T v:st) os<<v<<","; os <<"}"; return os; }
template<typename T,typename U> inline void chmax(T &x,U y){ if(y>x) x = y; }
template<typename T,typename U> inline void chmin(T &x,U y){ if(y<x) x = y; }
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> pii;
typedef vector<int> vi;
typedef vector<vi> vvi;
ll gcd(ll a,ll b){ if(b==0) return a; else return gcd(b,a%b); }
//constexpr double eps = 1e-14; 
constexpr double eps = 1e-10; 
constexpr ll mod = 1e9+7;
const int dx[]={1,0,-1,0} ,dy[] = {0,1,0,-1};
/*}}}*/

ll sx,sy,tx,ty;

int main(){
    cin >> sx >> sy >> tx >> ty;

    ll x = tx-sx;
    ll y = ty-sy;
    rep(i,x) cout << "R";
    rep(i,y) cout << "U";
    rep(i,x) cout << "L";
    rep(i,y) cout << "D";

    cout << "D";
    rep(i,x+1) cout << "R";
    rep(i,y+1) cout << "U";
    cout << "L";
    cout << "U";
    rep(i,x+1) cout << "L";
    rep(i,y+1) cout << "D";
    cout << "R";

    cout << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define endl '\n'
using namespace std;
typedef long long ll;
const int c=1e4;
const ll mod=1e9+7,M=998244353;
vector<ll>sold;
vector<ll>enem;
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    int n,k;
    cin>>n>>k;
    int s[n+5];
    for(int i=1;i<=n;i++){
        cin>>s[i];
    }
    ll dp[k+5]={0};
    for(int i=1;i<=k;i++){
            for(int j=1;j<=n;j++){
                    if(i-s[j]>=0&&!dp[i-s[j]]){
       dp[i]=1;


    }
            }
    }
   // cout<<dp[k];
   if(dp[k]==1){
    return cout<<"First",0;
   }
   cout<<"Second";
    return 0;
}


Measured memory_bytes: 1024
// Try Tenka1 Programmer Contest 2019
// author: Leonardone @ NEETSDKASU

fn main() {
	let mut stdin = String::new();
    std::io::Read::read_to_string(
    	&mut std::io::stdin(),
        &mut stdin).unwrap();
	let mut stdin = stdin.split_whitespace();
    let mut get = || stdin.next().unwrap();
    macro_rules! get {
    	($t:ty) => (get().parse::<$t>().unwrap());
        () => (get!(i64));
    }
    
    let n = get!(usize);
    let s = get().as_bytes();
    let mut sumw = vec![0; n+1];
    let mut sumb = vec![0; n+1];
    for i in 0..s.len() {
    	sumw[i+1] = sumw[i];
        sumb[i+1] = sumb[i];
    	if s[i] == b'.' {
        	sumw[i+1] += 1;
        } else {
        	sumb[i+1] += 1;
        }
    }
    let mut ans = n;
    for i in 0..n+1 {
    	let tmp = sumb[i]+sumw[n]-sumw[i];
        ans = std::cmp::min(ans, tmp);
    }
    println!("{}", ans);
}

Measured memory_bytes: 8444
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<vector>
#define pb push_back
#define rep(i,a,b) for(i=a;i<=b;i++)
using namespace std;
const int N=100010;
int a[N];
int n,K;
int ans;
int dep[N];
vector<int> vec[N];

void dfs(int x){
	int i,y;
	rep(i,0,(int)vec[x].size()-1){
		y=vec[x][i];
		dfs(y);
		if(dep[y]==K-1&&x!=1)	ans++;
		else dep[x]=max(dep[x],dep[y]+1);
	}
}

int main(){
//	freopen("a.in","r",stdin);
//	freopen("a.out","w",stdout);
	int i;
	scanf("%d%d",&n,&K);
	rep(i,1,n)	scanf("%d",&a[i]);
	if(a[1]!=1)	ans++;
	a[1]=1;
	rep(i,2,n)	vec[a[i]].pb(i);
	dfs(1);
	printf("%d",ans);
}

Measured memory_bytes: 14336
#include <iostream>
#include <vector>
#include<algorithm>
#include<string>
#include<stdio.h>
#include<map>
#include<math.h>
#include<queue>
using namespace std;
using ll = long long;
using ld = long double;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
const int MOD = 1000000007;
const int mod = 1000000007;
const int INF = 1000000001;
const long long LINF = 1e18;
const int MAX = 510000;

int main() {
	long long int q, h, s, k;
	long long int  n;
	cin >> q >>  h >> s >> k >> n;
	vector<pair<long long int,long double>> a(4);
	a.at(0) = make_pair(8*q, 0.25);
	a.at(1)= make_pair(4*h, 0.50);
	a.at(2)= make_pair(2*s, 1.00);
	a.at(3)= make_pair(1*k,2.00);
	sort(a.begin(), a.end());
	//long double cnt = 0;
	long long int ans = 0;
	long double cnt = 0;
	if (n % 2 == 0) {
		ans += (long long int)((a.at(0).first/(2/a.at(0).second)) * (long long int)(n *(1/a.at(0).second)));

	}
	
	else {
		ans += (long long int)((a.at(0).first/(2/a.at(0).second)) * (long long int)((n - 1)* (1 / a.at(0).second)));
		while (cnt < 1) {
			if (cnt + a.at(0).second <= 1) {
				ans += (long long int)(a.at(0).first / (2 / a.at(0).second));
				cnt += a.at(0).second;
			}
			else if (cnt + a.at(1).second <= 1) {
				ans += (long long int)(a.at(1).first / (2 / a.at(1).second));
				cnt += a.at(1).second;
			}
			else if (cnt + a.at(2).second <= 1) {
				ans += (long long int) (a.at(2).first / (2 / a.at(2).second));
				cnt += a.at(2).second;
			}
			else if (cnt + a.at(3).second <= 1) {
				ans += (long long int) (a.at(3).first / (2 / a.at(3).second));
				cnt += a.at(3).second;
			}
		//	cout << cnt << endl;
		}
	}
	//cout << (long int)(100000000 * (1 / 0.25)) << endl;
	cout <<(long long int) ans << endl;
		return 0;
	}


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

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

using namespace std;
template <class T>
using ordered_set = __gnu_pbds::tree<T, __gnu_pbds::null_type, less<T>, __gnu_pbds::rb_tree_tag, __gnu_pbds::tree_order_statistics_node_update>;
template <class T>
using ordered_multiset = __gnu_pbds::tree<T, __gnu_pbds::null_type, less_equal<T>, __gnu_pbds::rb_tree_tag, __gnu_pbds::tree_order_statistics_node_update>;

#define PI atan2(0, -1)
#define EPS 1e-9
#define INF 5e18
#define MOD 1000000007

#define mp make_pair
#define pb push_back
#define f first
#define s second
#define lb lower_bound
#define ub upper_bound

int main(){
    //freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout);
    ios_base::sync_with_stdio(0); cin.tie(0); cout << fixed << setprecision(10);
    int x; cin >> x;
    if(x < 600) x = 8;
    else if(x < 800) x = 7;
    else if(x < 1000) x = 6;
    else if(x < 1200) x = 5;
    else if(x < 1400) x = 4;
    else if(x < 1600) x = 3;
    else if(x < 1800) x = 2;
    else x = 1;
    cout << x << endl;
    return 0;
}

/******************************
Kateba ii dake no hanashi darou
Success is only a victory away
- No Game No Life Opening
******************************/

Measured memory_bytes: 3636
#include "bits/stdc++.h"
using namespace std;
#ifdef _DEBUG
#include "dump.hpp"
#else
#define dump(...)
#endif

//#define int long long
#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 all(c) begin(c),end(c)
const int INF = sizeof(int) == sizeof(long long) ? 0x3f3f3f3f3f3f3f3fLL : 0x3f3f3f3f;
const int MOD = (int)(1e9) + 7;
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 (b < a) { a = b; return true; } return false; }

struct HopcroftKarp {
	int n;
	vector<vector<int>> g;
	vector<int> match, dist;
	vector<bool> used, alive;
	HopcroftKarp(int n) : n(n), g(n), match(n), dist(n), used(n), alive(n, true) {}
	void addEdge(int u, int v) {
		g[u].emplace_back(v);
		g[v].emplace_back(u);
	}
	int maximumMatching() {
		int cnt = 0;
		fill(match.begin(), match.end(), -1);
		while (true) {
			buildAlternatingLevelGraph();
			fill(used.begin(), used.end(), false);
			int flow = 0;
			for (int u = 0; u < n; u++) {
				if (!alive[u])continue;
				if (match[u] == -1 && augment(u))
					flow++;
			}
			if (flow == 0)break;
			cnt += flow;
		}
		return cnt;
	}
	void buildAlternatingLevelGraph() {
		fill(dist.begin(), dist.end(), -1);
		queue<int> q;
		for (int u = 0; u < n; u++)
			if (match[u] == -1) {
				q.emplace(u);
				dist[u] = 0;
			}
		while (q.size()) {
			int u = q.front(); q.pop();
			for (int v : g[u]) {
				int w = match[v];
				if (w != -1 && dist[w] == -1) {
					dist[w] = dist[u] + 1;
					q.emplace(w);
				}
			}
		}
	};
	bool augment(int u) {
		used[u] = true;
		for (int v : g[u]) {
			if (!alive[v])continue;
			int w = match[v];
			if (w == -1 || (!used[w] && dist[w] == dist[u] + 1 && augment(w))) {
				match[u] = v;
				match[v] = u;
				used[v] = true;
				return true;
			}
		}
		return false;
	}
};


struct LexicographicallyBipartiteMatching :HopcroftKarp {
	LexicographicallyBipartiteMatching(int n) :HopcroftKarp(n) {}
	int maximumMatching() {
		for (int v = 0; v < n; v++)
			sort(g[v].begin(), g[v].end());
		int cnt = HopcroftKarp::maximumMatching();
		for (int v = 0; v < n; v++) {
			if (!alive[v] || match[v] == -1)continue;
			match[match[v]] = -1;
			match[v] = -1;
			fill(used.begin(), used.end(), false);
			augment(v);
			alive[match[v]] = 0;
			alive[v] = 0;
		}
		return cnt;
	}
	bool augment(int u) {
		used[u] = true;
		for (int v : g[u]) {
			if (!alive[v])continue;
			int w = match[v];
			if (w == -1 || (!used[w] && augment(w))) {
				match[u] = v;
				match[v] = u;
				return true;
			}
		}
		return false;
	}
};

signed main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	int N; cin >> N; N--;
	vector<vector<int>> b(N, vector<int>(N));
	rep(v, 0, N) rep(u, 0, N) { cin >> b[v][u]; }

	LexicographicallyBipartiteMatching lbm(N + N);
	rep(v, 0, N)rep(u, 0, N) {
		if (b[v][u])
			lbm.addEdge(u, N + v);
	}
	int res = lbm.maximumMatching();
	dump(res);
	if (res == N) {
		cout << "yes" << endl;
		rep(v, 0, N) {
			cout << lbm.match[v] - N + 1 << endl;
		}
	}
	else {
		cout << "no" << endl;
	}
	return 0;
}

Measured memory_bytes: 4128
#include<bits/stdc++.h>
using namespace std;
#define ll long long int
int mod=998244353;
#define mp make_pair
#define pb push_back
int main(){ 
	long long int t,n,m,b,c=0,d;
	cin>>n;
	int a[n];
	int mp[n+1]={0};
	for(int i=0;i<n-1;i++){
		cin>>a[i];
		mp[a[i]]++;
		}
		for(int i=1;i<=n;i++){
			cout<<mp[i]<<" ";	
			}
    return 0;
}


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

using namespace std;
#define _overload3(_1,_2,_3,name,...) name
#define _rep(i,n) repi(i,0,n)
#define repi(i,a,b) for(int i=int(a);i<int(b);++i)
#define rep(...) _overload3(__VA_ARGS__,repi,_rep,)(__VA_ARGS__)

typedef long long ll;
typedef pair<ll, ll> P;
const ll INF = 1LL<<60;

ll gcd(ll a, ll b) {
  if(b == 0) return a;
  return gcd(b, a % b);
}

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

ll modpow(ll a, ll n, ll mod) {
  ll res = 1;
  while (n > 0) {
    if (n & 1) res = res * a % mod;
    a = a * a % mod;
    n >>= 1;
  }
  return res;
}

struct LazySegmentTree {
private:
    int n;
    vector<ll> node, lazy;

public:
    LazySegmentTree(vector<ll> v) {
        int sz = (int)v.size();
        n = 1; while(n < sz) n *= 2;
        node.resize(2*n-1);
        lazy.resize(2*n-1, 0);

        for(int i=0; i<sz; i++) node[i+n-1] = v[i];
        for(int i=n-2; i>=0; i--) node[i] = node[i*2+1] + node[i*2+2];
    };

  void eval(int k, int l, int r) {

  // 遅延配列が空でない場合、自ノード及び子ノードへの
  // 値の伝播が起こる
    if(lazy[k] != 0) {
      node[k] += lazy[k];

      // 最下段かどうかのチェックをしよう
      // 子ノードは親ノードの 1/2 の範囲であるため、
      // 伝播させるときは半分にする
      if(r - l > 1) {
          lazy[2*k+1] += lazy[k] / 2;
          lazy[2*k+2] += lazy[k] / 2;
      }

      // 伝播が終わったので、自ノードの遅延配列を空にする
      lazy[k] = 0;
  }
  };

    void add(int a, int b, ll x, int k=0, int l=0, int r=-1) {
      if(r < 0) r = n;

      // k 番目のノードに対して遅延評価を行う
      eval(k, l, r);

      // 範囲外なら何もしない
      if(b <= l || r <= a) return;
      
      // 完全に被覆しているならば、遅延配列に値を入れた後に評価
      if(a <= l && r <= b) {
          lazy[k] += (r - l) * x;
          eval(k, l, r);
      }

      // そうでないならば、子ノードの値を再帰的に計算して、
      // 計算済みの値をもらってくる
      else {
          add(a, b, x, 2*k+1, l, (l+r)/2);
          add(a, b, x, 2*k+2, (l+r)/2, r);
          node[k] = node[2*k+1] + node[2*k+2];
      }
  };

  ll getsum(int a, int b, int k=0, int l=0, int r=-1) {
    if(r < 0) r = n;
    if(b <= l || r <= a) return 0;

    // 関数が呼び出されたら評価！
    eval(k, l, r);
    if(a <= l && r <= b) return node[k];
    ll vl = getsum(a, b, 2*k+1, l, (l+r)/2);
    ll vr = getsum(a, b, 2*k+2, (l+r)/2, r);
    return vl + vr;
}

};




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

  int N;
  cin >> N;
  ll D, A;
  cin >> D >> A;

  vector<pair<ll, ll>> XH(N);
  vector<ll> X(N);
  vector<ll> H(N);

  ll t_x, t_h;
  rep(i, N){
    cin >> t_x >> t_h;
    XH[i] = make_pair(t_x, t_h);
  }

  sort(XH.begin(), XH.end());

  rep(i, N){
    X[i] = XH[i].first;
    H[i] = XH[i].second;
  }

  LazySegmentTree seg(H);

  ll ans = 0;

  for(int i = 0; i < N; i++){

    if(seg.getsum(i, i+1) > 0){

      ll num = seg.getsum(i, i+1);

      ll cnt = (num + A - 1) / A;

      auto ind = lower_bound(X.begin()+i, X.end(), X[i]+2*D+1) - X.begin();

      seg.add(i, ind, (-A) * cnt);

      ans += cnt;
    }

  }

  cout << ans << endl;




  return 0;
}


Measured memory_bytes: 16256
#include <iostream>
#include <vector>
using namespace std;
class BPopularVote {
public:
	void solve(std::istream& in, std::ostream& out) {
	    int N = 0;
	    int M = 0;
	    in >> N >> M;

	    vector<int> a(N, 0);
	    int input = 0;
	    int total = 0;
	    for (int i = 0; i < N; ++i) {
	        in >> input;
	        total += input;
	        a[i] = input;
	    }

	    int count = 0;
	    for (int value: a) {
	        if (value >= (total * 0.25 / M)) {
	            ++count;
	        }
	    }

	    if (count >= M) {
	        out << "Yes" << endl;
	    } else {
	        out << "No" << endl;
	    }
	}
};


int main() {
	BPopularVote solver;
	std::istream& in(std::cin);
	std::ostream& out(std::cout);
	solver.solve(in, out);
	return 0;
}


Measured memory_bytes: 256
#include<cstdio>
const int maxn=1010;
int n;
int t,a;
int h[maxn];
int ans;
int ab(register int x) {
	return x>0?x:-x;
}
int main() {
	scanf("%d",&n);
	scanf("%d%d",&t,&a);
	for(register int i=1;i<=n;++i)scanf("%d",&h[i]);
	ans=1;
	for(register int i=2;i<=n;++i)if(ab(1000*(t-a)-6*h[i])<ab(1000*(t-a)-6*h[ans])) ans=i;
	printf("%d\n",ans);
	return 0;
}

Measured memory_bytes: 128
#include<stdio.h>
int main(void)
{
	int C,n,d,r,c,flg[500][500],cnt,i,j,acnt,flg1;
	char p[1000][1001];
	scanf("%d %d",&C,&n);
	for(i=0;i<n;i++){
		scanf("%s",p[i]);
	}
	flg1=0;
	cnt=0;
	acnt=0;
	for(i=0;i<n/2;i++){
		for(j=0;j<n/2;j++){
			flg[i][j]=0;
			if(p[i][j]!=p[i][n-j-1]){
				flg[i][j]=1;
				cnt++;
			}
			if(flg[i][j]==0&&p[i][j]!=p[n-i-1][j]){
				flg[i][j]=1;
				cnt++;
			}
			if(flg[i][j]==0&&p[i][j]!=p[n-i-1][n-j-1]){
				flg[i][j]=1;
				cnt++;
			}
		}
	}
	if(cnt==0){
		acnt++;
	}
	for(i=2;i<=C;i++){
		scanf("%d",&d);
		for(j=0;j<d;j++){
			scanf("%d %d",&r,&c);
			r=r-1;
			c=c-1;
			if(p[r][c]=='0'){
				p[r][c]='1';
			}
			else{
				p[r][c]='0';
			}
			if(r>=n/2){
				r=n-r-1;
			}
			if(c>=n/2){
				c=n-c-1;
			}
			flg1=0;
			if(p[r][c]!=p[r][n-c-1]){
				flg1=1;
			}
			if(p[r][c]!=p[n-r-1][c]){
				flg1=1;
			}
			if(p[r][c]!=p[n-r-1][n-c-1]){
			    flg1=1;
			}
			if(flg1==0&&flg[r][c]==1){
				cnt=cnt-1;
				flg[r][c]=0;
			}
			if(flg1==1&&flg[r][c]==0){
				cnt++;
				flg[r][c]=1;
			}
		}	
		if(cnt<1){
			acnt++;
		}
	}
	printf("%d\n",acnt);
	return 0;
}


Measured memory_bytes: 3748
import heapq as hq
n,m,s = list(map(int,input().split()))
G = [[] for _ in range(n)]

for i in range(m):
  u,v,A,B = list(map(int,input().split()))
  u -= 1
  v -= 1
  hq.heappush(G[u], (B,A,v))
  hq.heappush(G[v], (B,A,u))
  #G[u].append((B,A,v))
  #G[v].append((B,A,u))

c = [0]*n
d = [0]*n
for i in range(n):
  C,D = list(map(int,input().split()))
  c[i] = C
  d[i] = D

inf = 1<<61
M = 50*51
if s > M:s = M-1
dp = [[inf] * M for _ in range(n)] 
cur = 0
dp[cur][s] = 0
que = [(0,s,0)]
while que:
  cd,cs,cur = hq.heappop(que)
  C = c[cur];D = d[cur]
  if dp[cur][cs] < cd:continue
  if cs+C < M and cd+D < dp[cur][cs+C]:
    dp[cur][cs+C] = cd+D
    hq.heappush(que, (cd+D, cs+C, cur))
  for g in G[cur]:
    B = g[0];A = g[1];to = g[2]
    if cs >= A and B+cd < dp[to][cs-A]:
      dp[to][cs-A] = B+cd
      hq.heappush(que, (B+cd, cs-A, to))

for i in range(1,n):
  print(min(dp[i]))


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

typedef long long int ll;
typedef unsigned long long int ull;
#define rep(i,n) for(ll i=0;i<(n);i++)

using namespace std;


const double pi=acos(-1);

struct Point{
    ll x,y;
    bool operator< (const Point t) const{
        return atan2(x,y)<atan2(t.x,t.y);
    }
};

Point subV(Point& a, Point& b){
    return {a.x - b.x, a.y - b.y};
}

int main(){
    ll n;
    cin >> n;
    vector<Point> p(n);
    rep(i, n) cin >> p[i].x >> p[i].y;

    if(n == 2){
        cout << 0.5 << endl << 0.5 << endl;
        return 0;
    }

    rep(i, n){
        vector<Point> q;
        rep(j, n){
            if(i == j)  continue;
            q.push_back(subV(p[j], p[i]));
        }
        sort(q.begin(), q.end());
        
        double x = 0;
        rep(j, n-2){
            double a = atan2(q[j+1].x, q[j+1].y);
            double b = atan2(q[j].x, q[j].y);
            if(M_PI <= a-b) x = a-b-M_PI;
        }
        double c = atan2(q[0].x, q[0].y);
        double d = atan2(q[n-2].x, q[n-2].y);
        if(M_PI <= c-d+2*M_PI) x = c-d+M_PI;
    
        cout << fixed << setprecision(15) << x/(2*M_PI) << endl;
    }


    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <cmath>
#include <vector>
#include <list>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <string>
#include <cstring>
#include <utility>
#include <algorithm>
#include <functional>
#include <deque>
#include <cctype>
#include <ctime>
#include <cstdlib>
#include <iomanip>
using namespace std;

;;

int main(){
  ;;
    int n, i;
    cin >> n >> i;
    ;
    cout << (n-i+1) << endl;;
}

Measured memory_bytes: 256
import java.util.*;
import java.lang.*;
import java.io.*;

/* Name of the class has to be "Main" only if the class is public. */
public class Main
{
	public static void main (String[] args) throws java.lang.Exception
	{
	 Scanner sc=new Scanner(System.in);
	 int N=sc.nextInt();
	 int [][] mat=new int[N][3];
	 for(int i=0;i<N;i++)
	 {
	     for(int j=0;j<3;j++)
	     {
	         mat[i][j]=sc.nextInt();
	         // System.out.print(mat[i][j]+" ");
	     }
	    // System.out.println();
	 }
	 int [][] dp=new int[N][3];
	 dp[0][0]=mat[0][0];
	 dp[0][1]=mat[0][1];
	 dp[0][2]=mat[0][2];
	 
	 for(int i=1;i<N;i++)
	 {
	     for(int j=0;j<3;j++)
	     {
	         if(j==0)
	         {
	             dp[i][j]=mat[i][j]+Math.max(dp[i-1][j+1],dp[i-1][j+2]);
	         }
	         if(j==1)
	         {
	             dp[i][j]=mat[i][j]+Math.max(dp[i-1][j-1],dp[i-1][j+1]);
	         }
	         if(j==2)
	         {
	             dp[i][j]=mat[i][j]+Math.max(dp[i-1][j-2],dp[i-1][j-1]);
	         }
	     }
	 }
	 int max=0;
	 for(int j=0;j<3;j++)
	 {
	     if(dp[N-1][j]>max)
	     {  max=dp[N-1][j];}
	 }
	
	 System.out.println(max);
	}
}


Measured memory_bytes: 53708
#include<bits/stdc++.h>
using namespace std;
string s,p;
int main(){
    int t,i,j,n,m,l=0,r;
    cin>>n>>s>>p;
    for(i=0,j=0;i<n || j<n;){
        if(l==0){
            cout<<s[i];
            i++;
        }
        else{
            cout<<p[j];
            j++;
        }
        l=(l+1)%2;
    }
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
  long N;cin>>N;
  string out="";
  if(N==0){cout<<0;return 0;}
  while(N!=0){
    out+=to_string(abs(N%2));
    N=(N-abs(N%2))/2;N*=-1;
  }
  int L=out.length();
  for(int i=0;i<L;i++)cout<<out[L-1-i];
}

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

const ll MOD = 1e9 + 7;
template<ll MOD> struct ModInt {
    ll value;
    ModInt() : value(0) {}
    ModInt(const ll& v) : value(v % MOD) {
        if ( value < 0 ) value += MOD;
    }
    ModInt<MOD>& operator=(const ModInt& o) {
        value = o.value;
        return *this;
    }
    inline bool operator==(const ModInt& o) {
        return value == o.value;
    }
    inline bool operator!=(const ModInt& o) {
        return value != o.value;
    }
    ModInt<MOD>& operator+=(const ModInt& o) {
        value += o.value;
        if ( value >= MOD ) value -= MOD;
        return *this;
    }
    ModInt<MOD>& operator-=(const ModInt& o) {
        value += MOD - o.value;
        if (value >= MOD ) value -= MOD;
        return *this;
    }
    ModInt<MOD>& operator*=(const ModInt& o) {
        value *= o.value;
        value %= MOD;
        return *this;
    }
    ModInt<MOD>& operator/=(const ModInt& o) {
        value *= inverse(o.value);
        value %= MOD;
        return *this;
    }
    ModInt<MOD> operator-() {
        return ModInt<MOD>(-value);
    }
    ModInt<MOD> operator+(const ModInt& o) {
        ModInt<MOD> r(*this);
        r += o;
        return r;
    }
    ModInt<MOD> operator-(const ModInt& o) {
        ModInt<MOD> r(*this);
        r -= o;
        return r;
    }
    ModInt<MOD> operator*(const ModInt& o) {
        ModInt<MOD> r(*this);
        r *= o;
        return r;
    }
    ModInt<MOD> operator/(const ModInt& o) {
        ModInt<MOD> r(*this);
        r /= o;
        return r;
    }
    ModInt<MOD> pow(ll n) {
        ModInt<MOD> t(*this), r = 1;
        while ( n > 0 ) {
            if ( n & 1 ) r *= t;
            t *= t;
            n >>= 1;
        }
        return r;
    }
private:
    ll inverse(ll a) {
        ModInt<MOD> t(a);
        return t.pow(MOD - 2).value;
    }
};

using Int = ModInt<MOD>;

ll solve() {
    ll N;
    string S;
    cin >> N >> S;
    vector<Int> dp(N+1), dpt(N+1);
    dp[0] = Int(1);
    for ( int i = 0; i < N; i++ ) {
        swap(dp, dpt);
        dp.assign(N+1, 0);
        dp[0] += dpt[0];
        dp[1] += dpt[0] * 2;
        for ( int j = 1; j <= i; j++ ) {
            dp[j-1] += dpt[j];
            dp[j+1] += dpt[j] * 2;
        }
    }
    Int ans = dp[S.size()];
    ans /= Int(2).pow(S.size());
    return ans.value;
}

int main() {
    auto ans = solve();
    cout << ans << "\n";
    return 0;
}

Measured memory_bytes: 384
L, R = map(int, input().split())
MOD = 10**9 + 7

*BL, = map(int, bin(L)[2:])
*BR, = map(int, bin(R)[2:])

a = len(BL)
b = len(BR)
BL = [0]*(len(BR) - len(BL)) + BL

BL.reverse()
BR.reverse()

memo = [[[-1]*2 for i in range(2)] for j in range(70)]
def dfs(i, p, q):
    if memo[i][p][q] != -1:
        return memo[i][p][q]
    if i == -1:
        memo[i][p][q] = 1
        return 1
    r = 0
    if p == q == 0:
        if BL[i] == 1 and BR[i] == 0:
            memo[i][0][0] = 0
            return 0
        if BL[i] == 1 or BR[i] == 0:
            r = dfs(i-1, 0, 0)
        else:
            r = (dfs(i-1, 0, 1) + dfs(i-1, 1, 0) + dfs(i-1, 0, 0)) % MOD
    elif p == 0:
        if BL[i] == 1:
            r = dfs(i-1, 0, 1)
        else:
            r = (2*dfs(i-1, 0, 1) + dfs(i-1, 1, 1)) % MOD
    elif q == 0:
        if BR[i] == 0:
            r = dfs(i-1, 1, 0)
        else:
            r = (2*dfs(i-1, 1, 0) + dfs(i-1, 1, 1)) % MOD
    else:
        r = 3 * dfs(i-1, 1, 1)
    memo[i][p][q] = r
    return r
ans = 0
for l in range(a-1, b):
    ans += dfs(l-1, +(not a-1 == l), +(not b-1 == l))
print(ans % MOD)

Measured memory_bytes: 3192
#include <bits/stdc++.h>
#define sz(x) int(x.size())
using namespace std;
typedef long long ll;
int main() {
	string s,ans="Yes";
	cin >>s;
	for(ll i=0;i<sz(s);i++){
		if((i+1)%2==1){
			if(s.at(i)=='L'){
				ans="No";
				break;
			}
		}
		else{ 
			if(s.at(i)=='R'){
				ans="No";
				break;
			}
		}
	}
	cout << ans << endl;
}


Measured memory_bytes: 256
#include<iostream>
#include<math.h>
#include<stdio.h>
#include<algorithm>
#include<queue>
#include<map>
#include<stack>
#include<set>
#include<vector>
#include<string.h>
using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef double db;
typedef pair <int, int> pii;
typedef pair <ll, ll> pll;
typedef pair <ll, int> pli;
typedef pair <db, db> pdd;

const int maxn = 100005;
const int Mod=1000000007;
const int INF = 0x3f3f3f3f;
const ll LL_INF = 0x3f3f3f3f3f3f3f3f;
const db PI = acos(-1);
const db ERR = 1e-10;
map<pair<int,int> ,int> mm;
#define Se second
#define Fi first
int n,m;
int  l,r,d;
int book[maxn];
int num[maxn];
int flag;
vector<int> v[maxn];
void dfs(int x)
{
    if(flag==1)
        return ;
    for(int i=0;i<v[x].size();i++)
    {
        int pos=v[x][i];
         if(book[pos]==0)
         {
             book[pos]=1;
             num[pos]=num[x]+mm[pair<int,int>(x,pos)];
             dfs(pos);
         }
         else
         {
             if(num[pos]!=num[x]+mm[pair<int,int>(x,pos)])
             {
                 flag=1;
                 return ;
             }
         }
    }
    return ;
}
int main()
{
    cin>>n>>m;
    flag=0;
    while(m--)
    {
        cin>>l>>r>>d;
        v[l].push_back(r);
        v[r].push_back(l);
        mm[pair<int,int>(l,r)]=d;
        mm[pair<int,int>(r,l)]=-d;
    }
    for(int i=1;i<=n;i++)
    {
        if(flag==1)
            break;
        if(book[i]==0)
        {
            book[i]=1;
            num[i]=0;
            dfs(i);
        }
    }
    if(flag==1)
    {
        cout<<"No"<<endl;
    }
    else
    {
        cout<<"Yes"<<endl;
    }
    return 0;
}


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

int main() {
    long long A,B,C,K;
    cin >> A >> B >> C >> K;
    long long ans = 0;
    if(K >= A){
        ans = A;
        K = K - A;
    }else{
        ans = K;
        cout << ans << endl;
        return 0;
    }
    if(K == 0){
        cout << ans << endl;
        return 0;
    }
    if(K >= B){
        K -= B;
    }else{
        cout << ans << endl;
        return 0;
    }
    if(K == 0){
        cout << ans << endl;
        return 0;
    }
    if(K >= C){
        ans -= C;
        K -= C;
    }else{
        ans -= K;
        cout << ans << endl;
        return 0;
    }
	cout << ans << endl;
    return 0;
}

Measured memory_bytes: 3592
using System;

class Sample
{
    static void Main(string[] args)
    {
        string[] s = Console.ReadLine().Split();
        int a = int.Parse(s[0]), b = int.Parse(s[1]);
        
        if (a > b)
        Console.WriteLine("a > b");
        
        else if (a < b)
        Console.WriteLine("a < b");
        
        else
        Console.WriteLine("a == b");
        
    }
}


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

# define rep(i, n) for(int(i)=0;(i)<(n);(i)++)
# define reps(i, n) for(int(i)=1;(i)<=(n);(i)++)
# define rrep(i, n) for(int i=((int)(n)); i>0; --i)
# define rreps(i, n) for(int i=((int)(n)); i>=0; --i)
# define ALL(v) v.begin(), v.end()
template<class T>inline bool chmax(T &a, const T &b) { if (a<b) { a=b; return true; } return false; }
template<class T>inline bool chmin(T &a, const T &b) { if (b<a) { a=b; return true; } return false; }
template<typename T> void dump(T e){std::cout << e << std::endl;}
template<typename T> void dump(const std::vector<T>& v){for(const auto& e : v){ std::cout << e << " "; } std::cout << std::endl;}
template<typename T> void dump(const std::vector<std::vector<T> >& vv){ for(const auto& v : vv){ dump(v); } }
typedef long long ll;


int main() {
  int n; cin >> n;
  vector <int> a(3*n);
  rep(i, 3*n) cin >> a[i];
  sort(a.begin(), a.end(), greater<int>());
  ll ret = 0;
  for (int i=1; i<2*n; i+=2) {
    ret +=a[i];
  }
  dump(ret);

}


Measured memory_bytes: 1408
#include <bits/stdc++.h>
#include <type_traits>
using namespace std;
#define FOR(i, a, b) for (int i = int(a); i < int(b); i++)
#define REP(i, b) FOR(i, 0, b)
#define MP make_pair
#define PB push_back
#define EB emplace_back
#define ALL(x) x.begin(), x.end()
using pi = pair<int, int>;
using vi = vector<int>;
using ld = long double;

int main() {
    int n, m;
    cin >> n >> m;
    vector<int> a(n), b(n);
    vector<int> c(m), d(m);
    REP(i, n) {
        cin >> a[i] >> b[i];
    }
    REP(i, m) {
        cin >> c[i] >> d[i];
    }

    REP(i, n) {
        int min = 4e8 + 1;
        int ans = 0;
        REP(j, m) {
            int dis = abs(a[i] - c[j]) + abs(b[i] - d[j]);
            if (dis < min) {
                min = dis;
                ans = j + 1;
            }
        }
        cout << ans << endl;
    }
}

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

/*
#include <boost/functional/hash.hpp>
#include <boost/multiprecision/cpp_int.hpp>
typedef boost::multiprecision::cpp_int mlint;
*/

#define debug 0
#define fcout(d) cout << fixed << setprecision(d)
#define urep(i,s,t) for(int i = (int)(s); i <= (int)(t); ++i)
#define drep(i,s,t) for(int i = (int)(s); i >= (int)(t); --i)
#define rep(i,n) urep(i,0,(n) - 1)
#define rep1(i,n) urep(i,1,(n))
#define rrep(i,n) drep(i,(n) - 1,0)
#define all(v) begin(v),end(v)
#define rall(v) rbegin(v),rend(v)
#define vct vector
#define prique priority_queue
#define l_bnd lower_bound
#define u_bnd upper_bound
#define rsz resize
#define era erase
#define emp emplace
#define emf emplace_front
#define emb emplace_back
#define pof pop_front
#define pob pop_back
#define mkp make_pair
#define mkt make_tuple
#define fir first
#define sec second
#define odd(x) ((x) & 1)
#define even(x) (~(x) & 1)

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef double db;
typedef vct<vct<ll>> mat;
typedef pair<int,int> pii;
typedef tuple<int,int,int> tiii;
typedef map<int,int> mpii;
typedef unordered_map<int,int> umpii;

const int dir[8][2] = { {1,0},{0,1},{-1,0},{0,-1},{1,1},{-1,1},{-1,-1},{1,-1} };
const ll inf32 = (1 << 30) - 1;
const ll inf64 = (1LL << 62) - 1;
const ll mod = 1e9 + 7;
const db eps = 1e-9;

template <class T, class U> T qceil(T x, U y) { return x > 0 ? (x - 1) / y + 1 : x / y; }
template <class T, class U> bool parity(T x, U y) { return odd(x) ^ even(y); }
template <class T, class U> bool chmax(T &m, U x) { if(m < x) { m = x; return 1; } return 0; }
template <class T, class U> bool chmin(T &m, U x) { if(m > x) { m = x; return 1; } return 0; }
template <class T> bool cmprs(T &v) {
    T tmp = v;
    sort(all(tmp));
    tmp.erase(unique(all(tmp)),end(tmp));
    for(auto it = begin(v); it != end(v); ++it) *it = l_bnd(all(tmp),*it) - begin(tmp) + 1;
    return v.size() > tmp.size();
}

template <class T> void esc(T ret) {
    cout << ret << endl;
    exit(0);
}

int n,m;

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

    cin>>n>>m;
    ll ret = 1;
    for(int i = 1; i * i <= m; i++){
        if(m%i) continue;
        int d=m/i;
        if(d>=n) chmax(ret,i);
        if(i>=n) chmax(ret,d);
    }
    esc(ret);
}


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

using namespace std;

int main () {
	int n, m, x;
	cin >> n >> m >> x;
	int e, less = 0, more = 0;
	for (int i = 0; i < m; i++) {
		cin >> e;
		if (e < x)
			less++;
		else if (e > x)
			more++;
	}
	cout << min(less, more);
	return 0;
}

Measured memory_bytes: 256
#define _USE_MATH_DEFINES

#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <cmath>
#include <algorithm>
#include <vector>
#include <queue>
#include <map>

using namespace std;

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

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

#define MAX_V 200000

struct edge{
	int to;
	long long int cost;
	edge(int to_, int cost_){
		to = to_;
		cost = cost_;
	}
};

vector<edge> G[MAX_V];
long long int d[MAX_V];

// 計算コストはO(ElogV)

void shortest_path(int s, int V){ // Vは頂点数
	
	priority_queue<P, vector<P>, greater<P> > que;
	
	for(int i = 0; i < V; i++){
		d[i] = INF;
	}
	d[s] = 0;
	
	que.push(P(0, s));
	
	while(!que.empty()){
		
		P p = que.top();
		que.pop();
		
		int v = p.second;
		
		if(d[v] < p.first){
			continue;
		}
		
		for(int i = 0; i < G[v].size(); i++){
			edge e = G[v][i];
			if(d[e.to] > e.cost + d[v]){
				d[e.to] = d[v] + e.cost;
				que.push(P(d[e.to], e.to));
			}
		} // 頂点への最小コストを更新
	}
}

int main(){
	
	int N, M, s, t;
	cin >> N >> M >> s >> t;
	
	for(int i = 0; i < M; i++){
		long long int a, b, c, d2;
		cin >> a >> b >> c >> d2;
		G[a].push_back(edge(b, d2));
		G[a].push_back(edge(c, d2));
		G[b].push_back(edge(a, d2));
		G[b].push_back(edge(c, d2));
		G[c].push_back(edge(a, d2));
		G[c].push_back(edge(b, d2));
	}
	
	shortest_path(s, N + 1);
	cout << d[t] << endl;
	
	return 0;
}



Measured memory_bytes: 26120
#pragma GCC target("avx")
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
vector<ll> parent;
vector<ll> depth;
vector<vector<ll>> graph;
ll n;
using P = pair<ll,ll>;
void bfs(){
    queue<P> que;
    for(ll i = 0; i < n; i++){
        depth[i] = 1145141919810;
    }
    depth[0] = 0;
    que.push(P(0,depth[0]));
    while(que.size()){
        P p = que.front();
        que.pop();
        for(ll i = 0; i < graph[p.first].size(); i++){
            if(p.second + 1 < depth[graph[p.first][i]]){
                
                parent[graph[p.first][i]] = p.first + 1;
                depth[graph[p.first][i]] = p.second + 1;
                que.push(P(graph[p.first][i],depth[graph[p.first][i]]));
            }
        }
    }
    return ;
}
int main()
{
    ios::sync_with_stdio(false);
    std::cin.tie(nullptr);
    ll m;
    cin >> n >> m;
    graph.resize(n);
    parent.resize(n,0);
    depth.resize(n);
    for(ll i = 0; i < m; i++){
        ll a,b;
        cin >> a >> b;
        a--;
        b--;
        graph[a].emplace_back(b);
        graph[b].emplace_back(a);
    }
    bfs();
    cout << "Yes" << endl;
    for(ll i = 1; i < n; i++)
        cout << parent[i] << endl;
}

Measured memory_bytes: 14484
#include <sstream>
#include <vector>
#include <algorithm>
#include <cstring>
#include <cstdlib>
#include <iostream>
#include <string>
#include <cassert>
#include <ctime>
#include <map>
#include <math.h>
#include <cstdio>
#include <set>
#include <deque>
#include <memory.h>
#include <queue>

#pragma comment(linker, "/STACK:64000000")
typedef long long ll;

using namespace std;

const int MAXN = 1 << 18;
const int MOD = 1; // 1000 * 1000 * 1000 + 7;
const int INF = 2e9;
const double PI = acos(-1.0);

int main() {
#ifdef _MSC_VER
	freopen("input.txt", "r", stdin);
#endif

	string s;
	while (cin >> s) {
		int n = s.length();
		char c[] = { 'N', 'S', 'W', 'E' };
		vector<char> was(4);
		for (int i = 0; i < n; i++) {
			char cc = s[i];
			for (int j = 0; j < 4; j++) if (c[j] == cc) was[j] = 1;
		}
		bool res = ((was[0] == was[1]) && (was[2] == was[3]));
		cout << (res ? "Yes" : "No") << endl;
	}

	return 0;
}

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

int main(){
   int n,k;
   cin >> n >> k;
   vector<int> P(n),C(n);
   rep(i,n) cin >> P[i];
   rep(i,n) cin >> C[i];
   rep(i,n) P[i]--;
   ll ans = -1e18;
   rep(si,n){
      int x = si;
      vector<int> s;
      ll tot=0;
      while(1){
         x=P[x];
         s.push_back(C[x]);
         tot += C[x]; 
         if(x==si) break;
      }
      int l = s.size();
      ll t = 0;
      rep(i,l){
         t += s[i];
         if (i+1 > k) break;
         ll now = t;
         if (tot > 0){
            ll e = (k-(i+1))/l;
            now += e*tot;
         }
         ans = max(ans,now);
      }
   }
   cout << ans << endl;
   return 0;  
}

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

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

  int A = 0;
  for (int i = 0; i < str.size(); i++) {
    if (str.at(i) == '+') {
      A++;
    }
  }
  
  int B = 0;
  for (int j = 0; j < str.size(); j++) {
    if (str.at(j) == '-') {
      B++;
    }
  }
  
  cout << A - B << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, n) for(int i = 0; i < (int)n; i++)
#define rfor(i, a, b) for(int i = a; i < (int)b; i++)
#define all(ary) (ary).begin(), (ary).end()
#define debug(x) cerr << #x << ": " << x << '\n'
const long long INF = 1LL << 60;
const int MOD = 1000000007; // 1e9 + 7
using namespace std;
using vec = vector<int>;
using ll = long long;
template <class T = int> T in(){ T x; cin >> x; return (x);}
template <class T> inline bool chmin(T &a, T b) { if ( a > b ) { a = b; return 1; } return 0; }
template <class T> inline bool chmax(T &a, T b) { if ( a < b ) { a = b; return 1; } return 0; }
const int dy[4] = {-1, 0, 0, 1};
const int dx[4] = {0, -1, 1, 0};

int N, F[101][11], P[101][11];
int res = -1000000000;
int sum;
int c;

int main(int argc, char *argv[]){
    cin >> N;
    rep(i, N) rep(j, 10) cin >> F[i][j];
    rep(i, N) rep(j, 11) cin >> P[i][j];
    rfor(i, 1, 1 << 10){
        sum = 0;
        rep(j, N){
            c = 0;
            rep(k, 10)
                if(i & (1 << k)) if(F[j][k]) c++;
            sum += P[j][c];
        }
        res = max(res, sum);
    }
    cout << res << endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define forn(i, n) for (ll i = 0; i < (n); i++)
#define fori(i, b, e) for (ll i = (b); i < (e); i++)
#define forr(i, b, e) for (ll i = (b); i >= (e); i--)
#define allele(v) v.begin(), v.end()
#define fi first
#define se second

int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    int n, m;
    cin >> n >> m;
    vector<vector<int>> b(m);
    vector<int> c(m);
    int sz;
    forn(i, m)
    {
        cin >> sz;
        b[i].resize(sz);
        forn(j, sz) cin >> b[i][j];
    }
    forn(i, m) cin >> c[i];

    int ans = 0;
    forn(mask, 1 << n)
    {
        bool flag = true;
        forn(i, m)
        {
            int cnt = 0;
            forn(j, b[i].size()) if ((mask >> (b[i][j] - 1)) & 1) cnt ^= 1;
            if (cnt != c[i])
            {
                flag = false;
                break;
            }
        }
        if (flag)
            ans++;
    }
    cout << ans;
    return 0;
}

Measured memory_bytes: 256
A,B,C,D = map(int,input().split())

#N = int(input())

#list(map(int,input().split()))

cnt = B-A+1

import fractions
E = C*D // fractions.gcd(C, D)


A_C = A//C
A_dC = A%C

B_C = B//C
#B_dC = B%C

A_D = A//D
A_dD = A%D

B_D = B//D
#B_dD = B%D

A_E = A//E
A_dE = A%E

B_E = B//E
#B_dE = B%E

C_cnt = B_C - A_C
if A_dC == 0:
    C_cnt += 1
D_cnt = B_D - A_D
if A_dD == 0:
    D_cnt += 1
E_cnt = B_E - A_E
if A_dE == 0:
    E_cnt += 1  

ans = cnt - C_cnt - D_cnt + E_cnt
print(int(ans))


Measured memory_bytes: 63980
N, M, K = map(int, input().split())
A = list(map(int, input().split()))
B = list(map(int, input().split()))

lia = [0]
lib = [0]
j = M
ans = 0

for i in range(N):
    lia.append(lia[i]+A[i])
for i in range(M):
    lib.append(lib[i]+B[i])

for i in range(N+1):
    if lia[i] > K:
        break

    while lib[j] > K-lia[i]:
        j -= 1
    ans = max(ans, i+j)

print(ans)

Measured memory_bytes: 47552
#include <iostream>
#include <vector>
#include <iomanip>
#include <string>
#include <sstream>
#include <algorithm>
#include <map>
#include <bits/stdc++.h>

using namespace std;
#define REP(i,n) FOR(i,0,n)
#define FOR(i,a,b) for(long long i=(a),i##Len_=(b);i<i##Len_;i++)
typedef long long ll;
static const ll MOD = 1000000007;
static const ll INF = 1000000000000000000LL;

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

    int res = 1;
    int be,af;
    REP(i,N)
    {
        be = res;
        af = res * 2;
        if(af-be < K)
        {
            res *= 2;
        }
        else
        {
            res += K;
        }
    }

    cout << res << endl;



    return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
int main(void){
char s[100];
  int count;
  scanf("%s",&s);
  for(count=0;s[count]!='\0';count++){
  if(s[count]=='A'&&s[count+1]=='C'){printf("Yes"); return 0;}
  }
  printf("No");
return 0;
}

Measured memory_bytes: 128
package main

import (
	"fmt"
)

const mod = int64(1e9 + 7)
const max = int64(5e5 + 5)
func mul(a , b int64) int64 {
	return (mod+(a*b)%mod)%mod
}

func sum(a , b int64) int64 {
	return (mod+(a+b)%mod)%mod
}

func power(a, b int64) int64 {

	x := int64(1)

	for b>0{
		if b%2 == 1{
			x = mul(x, a)
		}
		a = mul(a, a)
		b = b/2
	}
	return x
}

var fact [max]int64

func factorial()  {
	fact[0] = 1
	for i := int64(1);i<max;i++{
		fact[i] = mul(i, fact[i-1])
	}
}

func permutation(n,p int64) int64  {
	return mul(fact[n], power(fact[n-p], mod-2))
}

func combination(n, p int64) int64  {
	return mul(permutation(n,p), power(fact[p], mod-2))
}

func main() {

	factorial()

	var n,m int64
	fmt.Scan(&n, &m)
	ans := permutation(m, n)
	cur := int64(0)
	for i := int64(0);i<=n;i++{
		cur = sum(cur, mul(power(int64(-1),i),mul(combination(n, i), permutation(m-i, n-i))))
	}
	ans = mul(ans, cur)
	fmt.Printf("%v", ans)
}




Measured memory_bytes: 5768
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
template<typename T> bool chmin(T& a,const T& b) {
    if(a > b) {
        a = b;
      return true;
    }
  return false;
}

int main () {
    int n;
    cin >> n;
    vector<int> h(n);
    rep(i, n) {
        cin >> h[i];
    }

    vector<int> dp(n);
    for (int i = 0; i < n; i++) {
        dp[i] = 1e9;
    }
    dp[0] = 0;


    for (int i = 1; i < n; i++) {
        chmin(dp[i], dp[i-1] + abs(h[i] - h[i-1]));
        if (i > 1) {
            chmin(dp[i], dp[i-2] + abs(h[i] - h[i-2]));
        }
    }

    cout << dp[n-1] << endl;
}

Measured memory_bytes: 3972
MAX = 10**9 + 7
MAXAi = 1<<20

def solve2():
    N = int(raw_input())
    arr = [int(_) for _ in raw_input().split()]
    xor_acu = [0] * (N + 1)
    for i in range(1, N + 1):
        xor_acu[i] = xor_acu[i - 1] ^ arr[i - 1]
    dp = [[not j for i in range(MAXAi)] for j in range(2)]
    cnt = [0 for i in range (MAXAi)]
    cnt_zero = 0
    for i in range(1, N + 1):
        if xor_acu[i] == 0:
            cnt_zero += 1
        dp[0][xor_acu[i]] += dp[1][xor_acu[i]] * (cnt_zero - cnt[xor_acu[i]])
        dp[0][xor_acu[i]] %= MAX
        dp[1][xor_acu[i]] += dp[0][xor_acu[i]]
        dp[1][xor_acu[i]] %= MAX
        cnt[xor_acu[i]] = cnt_zero
    if xor_acu[N] != 0:
        ret = dp[0][xor_acu[N]]
    else:
        ret = pow(2, cnt_zero - 1, MAX)
        for j in range(1, MAXAi):
            ret += dp[1][j]
            ret %= MAX
    print str(ret)

if __name__ == '__main__':
    solve2()


Measured memory_bytes: 101936
n = int(input())
a = list(map(int, input().split()))
q = int(input())
bc = [list(map(int, input().split())) for _ in range(q)]
s = 0
for g in range(len(a)):
    s += a[g]
e = [0] * 100001
for i in a:
    e[i] += 1
for j in range(q):
    s += (bc[j][1] - bc[j][0]) * e[bc[j][0]]
    e[bc[j][1]] += e[bc[j][0]]
    e[bc[j][0]] = 0
    print(s)

Measured memory_bytes: 32344
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ALDS_1_3_A
{
    class Program
    {
        static void Main(string[] args)
        {
            string inputline = Console.ReadLine();
            string[] element = inputline.Split(' ');
            int tryparse_output = 0;

            var stack = new Stack<string>();

            foreach(string ele in element)
            {
                if (int.TryParse(ele, out tryparse_output) == true)
                {
                    /* 数値に変換成功 */
                    int push_num = int.Parse(ele);
                    stack.Push(ele);
                }
                else
                {
                    int right = int.Parse(stack.Pop());
                    int left = int.Parse(stack.Pop());
                    int result;

                    /* 数値に変換失敗 */
                    switch (ele)
                    {
                        case "+":
                            result = left + right;
                            stack.Push(result.ToString());
                            break;
                        case "-":
                            result = left - right;
                            stack.Push(result.ToString());
                            break;
                        case "*":
                            result = left * right;
                            stack.Push(result.ToString());
                            break;
                        default:
                            Console.WriteLine("invalid operator.");
                            break;
                    }    
                }
            }
            int outputResult = int.Parse(stack.Pop());
            Console.WriteLine(outputResult);
        }
    }
}



Measured memory_bytes: 16400