akhauriyash/Code-Regression huggingface dataset:
#include<iostream>
#include<iomanip>
#include<string>
#include<vector>
#include<stack>
#include<queue>
#include<deque>
#include<set>
#include<map>
#include<utility>
#include<tuple>
#include<algorithm>
#include<cmath>
using namespace std;

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

const ll INF=1LL<<60;

template<class T> inline bool chmin(T& a, 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<ll> dp(n,INF);
  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;
  return 0;
}

Measured memory_bytes: 1408
#include <bits/stdc++.h>
 
using namespace std;
typedef long long LL;
typedef pair<int,int> pii;
 
#define pb push_back 
#define eb emplace_back
#define mp make_pair
#define fi first
#define se second 
#define debug(x)  do{cerr<<#x<<": "<<x<<"\n";}while(0)
#define debugv(x) do{cerr<<#x<<": ";for(auto&e: (x))cerr<<e<<" ";cerr<<"\n";}while(0)
#define fori(i, n) for (int i = 0; i < (int)(n); ++i)
#define forn(i, n) for (int i = 1; i <= (int)(n); ++i)
#define ford(i, n) for (int i = (int)(n); i >= 0; --i)
#define fore(i, a, b) for (int i = (int)(a); i <= (int)(b); ++i)
template<typename T> bool mmax(T &m, const T q) { if (m < q) {m = q; return true;} else return false; }
template<typename T> bool mmin(T &m, const T q) { if (m > q) {m = q; return true;} else return false; }
#define RETURN(x) do{cout << x << '\n'; return 0;}while(0)
#define FIRSTWIN do{cout << "Monocarp\n"; return 0;}while(0)
#define SECONDWIN do{cout << "Bicarp\n"; return 0;}while(0)
 
const int MAXN = 1e5+5;
const int MOD = 1e9+7;
const int INF = 1e9+1;

pair<LL,int> val[MAXN*4];
int trace[MAXN];

int N,M;
char S[MAXN];

void build(int node, int left, int right) {
    if (left == right) {
        if(left == N) val[node] = {0, left};
        else val[node] = {1e9,left};
        return;
    }

    int m = (left + right) / 2;
    build(node*2, left, m);
    build(node*2+1, m+1, right);

    val[node] = min(val[node*2], val[node*2+1]);
}

void update(int node, int left, int right, int i, int newval) {
    if(left == right) {
        assert(left == i);
        val[node].fi = newval;
        return;
    }

    int m = (left + right) / 2;
    if(i <= m) update(node*2, left, m, i, newval);
    else update(node*2+1, m+1, right, i, newval);

    val[node] = min(val[node*2],val[node*2+1]);
}

pair<LL,int> query(int node, int left, int right, int l, int r) {
    if (r < l) return {1e9, 1e9};
    if (r < left || right < l) return {1e9,1e9};

    if (l <= left && right <= r) return val[node];

    int m = (left + right) / 2;
    return min(query(node*2, left, m, l, min(m,r)), 
               query(node*2+1, m+1, right, max(m+1,l), r));
}


int main() {
#ifdef OJ
    freopen("input.txt", "rt", stdin);
    //freopen("output.txt", "wt", stdout);
#endif
    ios::sync_with_stdio(false);
    cin.tie(0);

    cin >> N >> M;
    cin >> S;

    build(1,0,N);
    for(int i = N-1; i >= 0; i--) {
        if(S[i] == '1') continue;
        auto p = query(1,0,N,i+1,min(N,i+M));
        if(p.fi == 1e9) RETURN(-1);
        update(1,0,N,i,p.fi+1);
        trace[i] = p.se;
    }

    int i = 0;
    while(i < N) {
        int j = trace[i];
        cout << j - i << ' ';
        i = j;
    }
    cout << endl;

    return 0;
}



Measured memory_bytes: 6656
import sys,queue,math,copy,itertools,bisect,collections,heapq

def main():
    sys.setrecursionlimit(10**7)
    INF = 10**18
    MOD = 10**9 + 7
    LI = lambda : [int(x) for x in sys.stdin.readline().split()]
    NI = lambda : int(sys.stdin.readline())

    D,G = LI()
    pc = [LI() for _ in range(D)]

    ans = INF
    for p in itertools.permutations(range(D)):
        g = G
        cnt = 0
        for i in p:
            if g < pc[i][0] * (i+1) * 100:
                cnt += math.ceil(g/((i+1)*100))
                break
            else:
                cnt += pc[i][0]
                g -= pc[i][0] * (i+1) * 100 + pc[i][1]
            if g <= 0: break
        ans = min(ans,cnt)

    print(ans)


if __name__ == '__main__':
    main()

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

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

long long lcm(long long m, long long n) {
  if (m==0 || n==0) return 0;
  else return m/gcd(m,n)*n;
}

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int n;
  cin >> n;
  long long clock1, clock2;
  cin >> clock1;
  for (int i = 0; i < n-1; i++) {
    cin >> clock2;
    clock1 = lcm(clock1, clock2);
  }
  cout << clock1 << '\n';
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <limits.h>
#include <algorithm>
#include <string>
#include <math.h>
#include <limits.h>
#include <queue>
#include <map>
#include <set>
#include <iomanip>
#include <bitset>
#include <cassert>
#include <random>
#include <functional>
#include <stack>
#include <iomanip>
#include <cassert>
using namespace std;
long long MOD = 1e9 + 7;

//重み付きグラフ
//距離の部分をテンプレートに
template<class T>
class wGraph {
public:
	int N;
	vector<vector<pair<int, T>>>* E;
	wGraph(int n, T i) {
		N = n;
		E = new vector<vector<pair<int, T>>>;
		E->resize(N);
		INF = i;
	}
	wGraph() {
	}
	void constructor(int n, T i) {
		N = n;
		E = new vector<vector<pair<int, T>>>;
		E->resize(N);
		INF = i;
	}
	~wGraph() {
		delete E;
	}
	void addEdge(int a, int b, T c) {
		E->at(a).push_back(pair<int, T>(b, c));
	}
	T INF;
};

//ワーシャルフロイド、全点対最短路
//グラフと結果保存用
//到達不可能はg.INF
//O(|V|^3)
template<class T>
void warshallFloyd(wGraph<T>& g, vector<vector<T>>& array) {
	array.resize(g.N);
	for (auto itr = array.begin(); itr != array.end(); itr++) {
		(*itr).resize(g.N);
		fill((*itr).begin(), (*itr).end(), g.INF);
	}
	for (int n = 0; n < g.N; n++)array[n][n] = 0;
	for (int n = 0; n < g.N; n++) {
		for (auto itr = g.E->at(n).begin(); itr != g.E->at(n).end(); itr++) {
			array[n][(*itr).first] = min(array[n][(*itr).first], (*itr).second);
		}
	}
	for (int k = 0; k < g.N; k++) {
		for (int i = 0; i < g.N; i++) {
			for (int j = 0; j < g.N; j++) {
				if (array[i][k] != g.INF && array[k][j] != g.INF) {
					array[i][j] = min(array[i][j], array[i][k] + array[k][j]);
				}
			}
		}
	}
	return;
}

long long N, M, L;

int main() {
	cin >> N >> M >> L;
	wGraph<long long> G0(N,INT_MAX);
	for (int m = 0; m < M; m++) {
		int a, b, c;
		cin >> a >> b >> c;
		G0.addEdge(--a, --b, c);
		G0.addEdge(b, a, c);
	}
	vector<vector<long long>> belans;
	warshallFloyd(G0, belans);
	wGraph<long long> G(N, INT_MAX);
	for (int s = 0; s < N; s++) {
		for (int t = 0; t < N; t++) {
			if (s == t)continue;
			if (belans[s][t] <= L)G.addEdge(s, t, 1);
		}
	}
	vector<vector<long long>> ans;
	warshallFloyd(G, ans);
	int Q;
	cin >> Q;
	for (int q = 0; q < Q; q++) {
		int s, t;
		cin >> s >> t;
		if (ans[--s][--t] == INT_MAX)cout << -1 << endl;
		else cout << ans[s][t]-1 << endl;
	}
	return 0;
}


Measured memory_bytes: 6656
#include <bits/stdc++.h>
using namespace std;
typedef long long LL;
typedef unsigned long long ULL;
#define rep(i,j,k) for(int i=j;i<k;i++)
#define BIG_NUM 2000000000
#define MOD 1000000007
#define EPS 0.000000001
const int  COMMAX = 510000;

long long fac[COMMAX], finv[COMMAX], inv[COMMAX];

// テーブルを作る前処理
void COMinit() {
  fac[0] = fac[1] = 1;
  finv[0] = finv[1] = 1;
  inv[1] = 1;
  for (int i = 2; i < COMMAX; 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;
  }
}

// 二項係数計算
long long 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;
}

struct UnionFind {
  vector<int> par; // par[i]:iの親の番号　(例) par[3] = 2 : 3の親が2
  vector<int> rank;
  int num;
  UnionFind(int N) : par(N) , rank(N) { //最初は全てが根であるとして初期化
    num = N;
    for(int i = 0; i < N; i++){
      par[i] = i;
      rank[i] = 0;
    }
  }

  int root(int x) { // データxが属する木の根を再帰で得る：root(x) = {xの木の根}
    if (par[x] == x) return x;
    return par[x] = root(par[x]);
  }

  void unite(int x, int y) { // xとyの木を併合
    int rx = root(x); //xの根をrx
    int ry = root(y); //yの根をry
    if (rx == ry) return; //xとyの根が同じ(=同じ木にある)時はそのまま
    if(rank[rx] < rank[ry]){
      par[rx] = ry;  
    }else{
      par[ry] = rx;
      if(rank[rx] == rank[ry])rank[rx]++;
    }
    num--;
  }

  bool same(int x, int y) { // 2つのデータx, yが属する木が同じならtrueを返す
    return root(x) == root(y);
  }
};

const int MS = 2;
const long long mod[] = {999999937LL, 1000000007LL}, base = 9973;
struct rolling_hash {
    int n;
    vector<long long> hs[MS], pw[MS];
    rolling_hash(){}
    rolling_hash(const string &s) {
        n = s.size();
        for (int i = 0; i < MS; i++) {
            hs[i].assign(n+1,0);
            pw[i].assign(n+1,0);
            hs[i][0] = 0;
            pw[i][0] = 1;
            for (int j = 0; j < n; j++) {
                pw[i][j+1] = pw[i][j]*base%mod[i];
                hs[i][j+1] = (hs[i][j]*base+s[j])%mod[i];
            }
        }
    }

    long long hash(int l, int r, int i) { return ((hs[i][r]-hs[i][l]*pw[i][r-l])%mod[i]+mod[i])%mod[i]; }

    bool match(int l1, int r1, int l2, int r2) {
        bool ret = 1;
        for (int i = 0; i < MS; i++) ret &= hash(l1,r1,i)==hash(l2,r2,i);
        return ret;
    }

    bool match(int l, int r, long long h[]) {
        bool ret = 1;
        for (int i = 0; i < MS; i++) ret &= hash(l,r,i)==h[i];
        return ret;
    }
};
int bhako[100100];
int main(){
  int n;
  cin >> n;
  rep(i,0,n-1)cin >> bhako[i];
  int res = bhako[0];
  rep(i,0,n){
    res += min(bhako[i],bhako[i+1]);
  }
  res += bhako[n-2];
  cout << res << endl;
  return 0;
}


Measured memory_bytes: 256
#include <stdio.h>
char s[110];
int main(){
	int n,max=0,sum=0;
	scanf("%d", &n);
	scanf("%s", s);
	for(int i=0;i<n;i++){
		if(s[i]=='I')
			sum+=1;
		if(s[i]=='D')
			sum-=1;
		if(sum>max)
			max=sum;
	}
	printf("%d", max);
	return 0;
}

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

using namespace std;

typedef unsigned long long ull;
typedef long long ll;

int main(){
	int n;
	cin >> n;
	int a[n];
	for(int i=0; i<n; i++) cin >> a[i];

	int cnt=0, ans=0;
	for(int i=0; i<n; i++){
		if(a[i]==i+1) cnt++;
		else{
			ans+=(cnt+1)/2;
			cnt=0;
		}
	}
	ans+=(cnt+1)/2;
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
using PP = pair<long, long>;
const int INF = 1e9;
template <class T> T Next() { T buf; cin >> buf; return buf; }

int n;
int a[100000];
int d[100001];
int main() {
  cin >> n;
  for (int i = 0; i < n; ++i) cin >> a[i];
  fill(d, d + n + 1, -INF);
  
  int mx = 0;
  for (int i = 0; i < n; ++i) {
    auto lit = upper_bound(d, d + n + 1, a[i], greater<int>());
    *lit = a[i];
    mx = max<int>(mx, lit - d + 1);
  }
  cout << mx << endl;
}

Measured memory_bytes: 1024
fun main(args: Array<String>) {
  val n = readLine()!!.toInt()
  val aList = readLine()!!.split(" ").map { it.toInt() }.toMutableList()
  val bList = readLine()!!.split(" ").map { it.toInt() }

  var cnt = 0L

  for (i in 0 until n) {
    val b = bList[i]
    val left = Math.min(b, aList[i])
    val right = Math.min(b - left, aList[i + 1])
    aList[i] -= left
    aList[i + 1] -= right
    cnt += (left + right)
  }

  println(cnt)
}



Measured memory_bytes: 84456
import collections

#  copyright by: Weizheng Wang
def sme():
    for cur, M in enumerate(element):
        while que and M <= que[-1][1]:  # 如果插入的元素小于队列最后一个元素，则弹出当前队列元素，保证队列第一个元素是最小值
            que.pop()
        que.append((cur, M))  # 队列压入数组元素的序号和内容(0,1)

        res.append(que[0][1])  # 队列压入数组元素内容[1]

        if que and que[0][0] == cur - L + 1:  # 如果队列队首元素和当前元素的距离等于L时，则弹出队首元素 队首压入新元素就变成旧元素
            que.popleft()


N, L = map(int, input().split())  # N数组元素个数 L数组长度
element = list(map(int, input().split()))  # element数组
que = collections.deque()  # 双向队列
res = []  # 结果数组
sme()
print(*res[L - 1:])  # 输出结果


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

int main(){
    long long a,b,c,d;
    cin >> a >> b >> c >> d;
    long long max;
    long long ac = a*c;
    long long ad = a*d;
    long long bc = b*c;
    long long bd = b*d;
    max = ac;
    if(ad>max)max=ad;
    if(bc>max)max=bc;
    if(bd>max)max=bd;
    cout << max << endl;
    return 0;
}

Measured memory_bytes: 3568
#include <iostream>
#include <algorithm>
#include <stdio.h>
#include <string.h>
#include <string>
#include <math.h>
#include <cmath>
#include <cstring>
#include <sstream>
#include <stdlib.h>
#include <iomanip>
#include <vector>

using namespace std;

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

	int co = 0;
	for (int i = 1; i < n + 1; i++)
	{
		for (int j = 1; j < n + 1; j++)
		{
			if (i % 2 == 0 && j % 2 != 0)
			{
				co++;
			}
		}
	}
	cout << co << endl;
}





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

using namespace std;

using ll = long long;

int main () {
    ll N;
    cin >> N;
    vector<ll> A(N);
    for (ll i = 0; i < N; i++) {
        cin >> A[i];
    }
    ll ans = 0;
    ll c = A[0];
    for (ll i = 1; i < N; i++) {
        if (c <= A[i]) {
            c = A[i];
            continue;
        }
        ans += c - A[i];
    }
    cout << ans << endl;
}

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

#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define PN printf("\n")
#define MODV 1000000007

typedef long long ll;
typedef double dbl;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef pair<int, int> pi;
template<class T>void addmod(T &a, ll b){a=(a+b)%MODV;}
template<class T>void mulmod(T &a, ll b){a=(a*b)%MODV;}
template<class T>bool domin(T &a, const T &b){return a>b?a=b,1:0;}
template<class T>bool domax(T &a, const T &b){return a<b?a=b,1:0;}
int gi(){int a;scanf("%d",&a);return a;}
ll gll(){ll a;scanf("%lld",&a);return a;}
dbl gdbl(){dbl a;scanf("%lf",&a);return a;}
long double gldbl(){long double a;scanf("%Lf",&a);return a;}

class graphwal
{
  public:
    int n;
    //0 1->bidirectional, 2->reverse edges
    typedef vector<pair<int,ll>> vpi;
    vector<vpi> ed;
    vll val;
    vi edgecnt;
    graphwal(int n):n(n),ed(n),val(n,-1),edgecnt(n,0){}
    void reset(int n){
    ed.clear();
    this->n=n;
    ed.resize(n);
  }
    void add(int a, int b, ll w){
      ed[a].pb(mp(b,w));
      edgecnt[b]++;
    }
    void load(int m){ for(int i=0;i<m;i++){int a=gi()-1,b=gi()-1;ll w=gll();add(a,b,w);}}
    void doit() {
      queue<int> indexes;
      for(int i=0;i<n;i++)
      if(edgecnt[i]==0){
        indexes.push(i);
        val[i]=0;
      }
      while(!indexes.empty()){
        int ix=indexes.front();
        indexes.pop();

        for(auto i:ed[ix]){
          int rval=val[ix]+i.se;
          int nix=i.fi;
          if(val[nix]==-1)val[nix]=rval;
          else if(val[nix]!=rval){
            cout<<"No"<<endl;
            return;
          }
          edgecnt[nix]--;
          if(edgecnt[nix]==0)indexes.push(nix);
        }
      }
      for(int i=0;i<n;i++)
      if(val[i]==-1){
        cout<<"No"<<endl;
        return;
      }
      cout<<"Yes"<<endl;
    }
};

int main() {
  int n=gi(), m=gi();
  graphwal g(n);
  for(int i=0;i<m;i++){
    int l=gi()-1, r=gi()-1, d=gi();
    g.add(l,r,d);
  }
  g.doit();

  return 0;
}

Measured memory_bytes: 8832
N, M = map(int, input().split())
KA = [tuple(map(int, input().split())) for _ in range(N)]

mask = int("1" * M, 2)
flag = mask

for k, *al in KA:
	tf = 0
	for a in al:
		tf |= 1 << (M - a)
	#print(format(~tf & mask, "b").zfill(M))
	flag &= tf
	#print(format(flag, "b").zfill(M))
print(bin(flag).count("1"))


Measured memory_bytes: 3064
from collections import defaultdict
import io

nim, mike = map(int, input().split())
kite = list(map(int, input().split()))
for i in range(nim):
    kite[i] -= mike
qwe = defaultdict(int)
qwe[0] = 1
for o in kite:
    for j, c in list(qwe.items()):
        qwe[j + o] += c
print(qwe[0]-1)

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

typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef long long LL;
typedef pair<LL, LL> PLL;

#define ALL(a)  (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define EB emplace_back
#define MP make_pair
#define SZ(a) int((a).size())
#define SORT(c) sort((c).begin(),(c).end())

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)

#define FF first
#define SS second
template<class S, class T>
istream& operator>>(istream& is, pair<S,T>& p){
  return is >> p.FF >> p.SS;
}

const double EPS = 1e-10;
const double PI  = acos(-1.0);
const LL MOD = 1e9+7;

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

  int H, W; cin >> H >> W;
  REP(y,H) REP(x,W){
	string s;
	cin >> s;
	if(s == "snuke"){
	  cout << (char)('A'+x) << y+1 << endl;
	  return 0;
	}
  }

  return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<cstring>
#include<algorithm>
#include<vector>
#include<iomanip>
#include<math.h>
#include<complex>
#include<queue>
#include<deque>
#include<stack>
#include<map>
#include<set>
#include<bitset>
#include<functional>
#include<assert.h>
#include<numeric>
using namespace std;
#define REP(i,m,n) for(int i=(int)(m) ; i < (int) (n) ; ++i )
#define rep(i,n) REP(i,0,n)
using ll = long long;
const int inf=1e9+7;
const ll longinf=1LL<<60 ;
const ll mod=1e9+7 ;
#define PI 3.141592653589793

int main(){
  int N, K;
  cin >> N >> K;
  ll a[N];
  rep(i, N){
    cin >> a[i];
  }
  ll ans = 0;
  rep(i, min(K+1,N+1)){
    rep(j, min(K+1-i,N+1-i)){
      ll tmp = 0;
      vector<ll> eque;
      rep(l, i) {eque.push_back(a[l]); tmp+=a[l];}
      for(int l=N-1; l>N-1-j; l--) {eque.push_back(a[l]); tmp+=a[l];}
      sort(eque.begin(), eque.end());
      rep(l, min(K-j-i, i+j)){ if(eque[l] < 0) tmp-=eque[l];}
      ans = max(tmp, ans);
    }
  }
  cout << ans << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <algorithm>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#define REP(i, n) for(int i = 0;i < n;i++)
#define REPR(i, n) for(int i = n;i >= 0;i--)
#define FOR(i, m, n) for(int i = m;i < n;i++)
#define FORR(i, m, n) for(int i = m;i >= n;i--)
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
#define llong long long
#define pb(a) push_back(a)
#define INF 999999999
using namespace std;
typedef pair<int, int> P;
typedef pair<llong, llong> LP;
typedef pair<int, P> PP;
typedef pair<llong, LP> LPP;

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

int main(){
	while(1){
		llong n, m;
		scanf("%lld%lld", &n, &m);
		if(n==0) return 0;

		vector<llong> v(n);
		REP(i, n){
			scanf("%lld", &v[i]);
		}
		v.push_back(0);
		n++;

		vector<llong> a;
		REP(i, n){
			REP(j, n){
				a.push_back(v[i]+v[j]);
			}
		}
		VSORT(a);

		llong ans=0;
		REP(i, n){
			REP(j, n){
				llong tmp=v[i]+v[j];
				llong k=upper_bound(a.begin(), a.end(), m-tmp)-a.begin();
				if(k==a.size()) continue;
				k--;

				if(k>=0) ans=max(ans, tmp+a[k]);
			}
		}

		printf("%lld\n", ans);
	}
}

Measured memory_bytes: 17432
#include <bits/stdc++.h>
using namespace std;
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
#define ll long long 
#define REP(i, a, b) for (ll i = a; i < b; i++)
#define REPI(i, a, b) for (ll i = b - 1; i >= a; i--)
#define i_os ios::sync_with_stdio(0);  cin.tie(0);  cout.tie(0);
#define INF (ll)1e18 + 100
#define endl "\n"
#define p0(a) cout << a << " "
#define p1(a) cout << a << endl
#define p2(a, b) cout << a << " " << b << endl
#define p3(a, b, c) cout << a << " " << b << " " << c << endl
#define p4(a, b, c, d) cout << a << " " << b << " " << c << " " << d << endl
/*SOME BITMASK KNOWLEDGE
1)x & (x - 1):sets the last one bit of x to zero
power of two exactly when x & (x − 1) = 0.
2)x & -x:sets all the one bits to zero, except last one bit
3)x | (x - 1):inverts all the bits after the last one bit*/
#define o_set tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update>
#define o_setll tree<ll, null_type, less<ll>, rb_tree_tag, tree_order_statistics_node_update>
typedef tree<pair<ll, ll>,null_type,less<pair<ll, ll>>,rb_tree_tag,tree_order_statistics_node_update> indexed_set;
typedef tree<ll,null_type,less<ll>,rb_tree_tag,tree_order_statistics_node_update> indexed_set1;
//1. order_of_key(k) : number of elements strictly lesser than k
//2. find_by_order(k) : k-th element in the set
 
int main() 
{
	ll n;
	cin>>n;
	ll arr1[n],arr2[n];
	REP(i,0,n){
		cin>>arr1[i]>>arr2[i];
	}
	sort(arr1,arr1+n);
	sort(arr2,arr2+n);
	if(n % 2){
		cout<<arr2[n/2] - arr1[n/2] + 1<<endl;
	}
	else {
		cout<<(arr2[n/2] + arr2[n/2-1]) - (arr1[n/2] + arr1[n/2-1]) + 1<<endl;	
	}
	return 0;
}

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

int main(void) {

    int w, h, n;
    cin >> w >> h >> n;

    vector<int> x(n);
    vector<int> y(n);
    vector<int> a(n);
    for(int i=0; i<n; i++) cin >> x[i] >> y[i] >> a[i];

    int x1 = 0;
    int x2 = w;
    int y1 = 0;
    int y2 = h;
    for(int i=0; i<n; i++){

        if( a[i] == 1 ) x1 = max(x[i], x1);
        else if( a[i] == 2 ) x2 = min(x[i], x2);
        else if( a[i] == 3 ) y1 = max(y[i], y1);
        else if( a[i] == 4 ) y2 = min(y[i], y2);

    }
    int ans = max(0, (x2 - x1)) * max(0, (y2 - y1));
    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#define _USE_MATH_DEFINES
#include<math.h>
#include<string>
#include<vector>
#include<stack>
#include<queue>
#include<list>
#include<map>
#include<unordered_map>
#include<set>
#include <algorithm>
#include <utility>

using std::cin;
using std::cout;
using std::endl;
using std::string;
using std::set;
using std::vector;
using std::pair;
using std::make_pair;
using std::priority_queue;

typedef unsigned long long ull;
typedef long long ll;

#define Prime1 1000000007
#define Prime2 9999973

#define INF 0x7fffffffffffffff

ull i, j, k, l, m, n;
ull H, W, Q;
ull a, b, c, x, y;
ull K, L, N, M;
string str;

int main()
{
	string s;
	cin >> s;
	if (s[0] == s[1] || s[1] == s[2] || s[2] == s[3])
	{
		cout << "Bad";
	}
	else
	{
		cout << "Good";
	}
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < n; i++)
#define print(x) cout << x << endl;
using namespace std;
typedef long long ll;
 
int main() {
    int D;
    ll G;
    vector<ll> p, c;

    cin >> D >> G;
    p.resize(D);
    c.resize(D);
    rep(i, D) cin >> p[i] >> c[i];

    ll res = 1<<29;
    for (int bit = 0; bit < (1 << D); bit++) {
        ll sum = 0;
        ll num = 0;
        for (int i = 0; i < D; i++) {
            if (bit & (1 << i)) {
                sum += c[i] + p[i] * 100 * (i + 1);
                num += p[i];
            }
        }
        if (sum >= G) {
            res = min(res, num);
        }
        else {
            for (int i = D-1; i >= 0; i--) {
                if (bit & (1 << i)) continue;
                for (int j = 0; j < p[i]; j++) {
                    if (sum >= G) break;
                    sum += 100 * (i + 1);
                    ++num;
                }
            }
            res = min(res, num);
        }
    }

    cout << res << endl;
    return 0;
}

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

using namespace std;

typedef long long int ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;

#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define rep2(i,n) for(int i=1;i<=(int)(n);i++)
#define rep3(i,n) for(int i=0;i<=(int)(n);i++)
#define REP(i,m,n) for(int i=m;i<(int)(n);i++)
#define repll(i,n) for(ll i=0;i<(ll)(n);i++)
#define repll2(i,n) for(ll i=1;i<=(ll)(n);i++)
#define REPLL(i,m,n) for(ll i=m;i<(ll)(n);i++)
#define INF (int)1e9  //
#define LINF (ll)4e18  //
#define MOD (int)(1e9)+7
#define MP make_pair
#define YES(n) cout << ((n) ? "YES" : "NO"  ) << endl
#define Yes(n) cout << ((n) ? "Yes" : "No"  ) << endl
#define PI 3.1415926535898

//------------------------------------------------------

int main() {
    int n;
    cin >> n;
    ll a[n], b[n], c[n];
    rep(i, n) cin >> a[i];
    rep(i, n) cin >> b[i];
    rep(i, n) cin >> c[i];

    sort(a, a + n);
    sort(c, c + n);

    ll sum = 0;

    rep(i, n) {
        auto it_a = lower_bound(a, a + n, b[i]);
        ll cnt_a = distance(a, it_a);
        auto it_c = upper_bound(c, c + n, b[i]);
        ll cnt_c = distance(it_c, c + n);

        sum += cnt_a * cnt_c;
    }

    cout << sum << endl;

    return 0;
}



Measured memory_bytes: 2688
n = int(input())
arr = [int(x) for x in input().split()]
arr.insert(0,0)
prefix = [0 for x in range(n+1)]
for i in range(1,n+1):
    prefix[i] = prefix[i-1]+arr[i];

ans = 0
mod = int(1e9+7)
for i in range(1,n):
    ans += arr[i]*(prefix[n]-prefix[i])
print(ans%mod)

Measured memory_bytes: 31484
import sys
import os
import math

ii = lambda: int(sys.stdin.buffer.readline().rstrip())
il = lambda: list(map(int, sys.stdin.buffer.readline().split()))
fl = lambda: list(map(float, sys.stdin.buffer.readline().split()))
iln = lambda n: [int(sys.stdin.buffer.readline().rstrip()) for _ in range(n)]

iss = lambda: sys.stdin.buffer.readline().decode().rstrip()
sl = lambda: list(map(str, sys.stdin.buffer.readline().decode().split()))
isn = lambda n: [sys.stdin.buffer.readline().decode().rstrip() for _ in range(n)]

MOD = 10 ** 9 + 7


def main():
    if os.getenv("LOCAL"):
        sys.stdin = open("input.txt", "r")

    S = iss()
    N = len(S)
    print(min(abs(753 - int(S[n:n + 3])) for n in range(N - 2)))


if __name__ == '__main__':
    main()


Measured memory_bytes: 3064
#include<iostream>
using namespace std;
int n,a[200005];
int main(){
    cin >> n;
    for(int i = 1; i <= n; ++i) {
        cin >> a[i];
    }
    for (int i = n; i >= 1; i -= 2) {
        cout << a[i] << " ";
    }
    for (int i = (n & 1) + 1; i <= n; i += 2) {
        cout << a[i] << " ";
    }
    cout << endl;
    return 0;
}

Measured memory_bytes: 2944
#include <bits/stdc++.h>
using namespace std;
#ifdef _DEBUG
#define dlog(str) cout << "====" << str << endl;
#else
#define dlog(str)
#endif
#define INF 999999999
#define MOD 1000000007
#define REP(i, n) for(int i = 0, i##_l = (n); i < i##_l; i++)
#define FOR(i, s, e) for(int i = s, i##_l = (e); i < i##_l; i++)
#define LLI long long int
#define _min(a, b) ((a < b) ? a : b)
#define _max(a, b) ((a < b) ? b : a)
#define chmax(a, b) a = _max(a, b)
#define chmin(a, b) a = _min(a, b)
#define bit(a, shift) ((a>>shift)&1))
#define pm(a) ((a) ? 1 : -1)
#define SORT(v) sort(v.begin(), v.end())
#define RSORT(v) sort((v).rbegin(), (v).rend())
// int 2.14E±9    lli 9.2E±18    double 1.7E±380

int main() {
    cout << fixed << setprecision(10);
    int a, b;
    cin >> a >> b;
    int cnt = 1;
    int sum = 0;
    while(true) {
        if(b <= cnt)
            break;

        cnt += a-1;
        sum++;
    }
    cout << sum;
    return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
int top,S[1000];
void push(int x){
  S[++top]=x;
}
int pop(){
  top--;
  return S[top+1];
}
int main(){
  int a,b;
  top=0;
  char s[100];
  while( scanf("%s", s) != EOF ){
    if ( s[0] == '+' ){
      a=pop();
      b=pop();
      push(a+b);
    } else if ( s[0] == '-' ){
      a=pop();
      b=pop();
      push(b-a);
    } else if ( s[0] == '*' ){
      a=pop();
      b=pop();
      push(a*b);
    } else {
      push(atoi(s));
    }
  }
  printf("%d\n",pop());
  return 0;
}

Measured memory_bytes: 548
#include<iostream>
#include<random>
using namespace std;
int D;
int c[26],s[365][26];
int t[365],now;
int anst[365],ans;
void calc()
{
	int lst[26];
	for(int i=0;i<26;i++)lst[i]=-1;
	now=0;
	for(int i=0;i<D;i++)
	{
		now+=s[i][t[i]];
		lst[t[i]]=i;
		for(int j=0;j<26;j++)now-=c[j]*(i-lst[j]);
	}
}
int change(int d,int q)
{
	int ret=0;
	ret-=s[d][t[d]];
	ret+=s[d][q];
	{
		int r=d+1;
		while(r<D&&t[r]!=t[d])r++;
		int l=d-1;
		while(l>=0&&t[l]!=t[d])l--;
		ret-=c[t[d]]*(r-d)*(d-l);
	}
	{
		int r=d+1;
		while(r<D&&t[r]!=q)r++;
		int l=d-1;
		while(l>=0&&t[l]!=q)l--;
		ret+=c[q]*(r-d)*(d-l);
	}
	return ret;
}
main()
{
	cin>>D;
	for(int i=0;i<26;i++)cin>>c[i];
	for(int i=0;i<D;i++)for(int j=0;j<26;j++)cin>>s[i][j];
	mt19937 rng(114514);
	for(int i=0;i<D;i++)
	{
		anst[i]=t[i]=rng()%26;
	}
	calc();
	ans=now;
	for(int tm=0;tm<2700;tm++)
	{
		int d=rng()%D,q=rng()%26;
		now+=change(d,q);
		t[d]=q;
		for(int k=0;k<2700;k++)
		{
			int d1=rng()%(D-1)+1,d2=rng()%d1;
			int pt1=t[d1],pt2=t[d2];
			int diff=0;
			diff+=change(d1,pt2);
			t[d1]=pt2;
			diff+=change(d2,pt1);
			t[d2]=pt1;
			if(diff>=0)
			{
				now+=diff;
			}
			else
			{
				t[d1]=pt1;
				t[d2]=pt2;
			}
		}
		if(ans<=now)
		{
			ans=now;
			for(int i=0;i<D;i++)anst[i]=t[i];
		}
		else
		{
			now=ans;
			for(int i=0;i<D;i++)t[i]=anst[i];
		}
	}
	for(int i=0;i<D;i++)cout<<anst[i]+1<<endl;
	cerr<<ans<<endl;
}

Measured memory_bytes: 3668
#include <algorithm>
#include <iostream>
#include <vector>
using namespace std;
using ll = long long;

int main() {
    string s; cin >> s;
    int n = s.length();

    vector<ll> dp(n + 1, 0);
    ll tmp = 0, acc = 0;
    for (int i = 0; i < n; i++) {
        acc += (dp[i + 1] += acc + (tmp = tmp * 10 + (s[i] - '0') * (1 << i)));
    }
    cout << dp[n] << endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i,n) for(long long i=0; i<(n); i++)
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }


int main(){
    ll n; cin>>n;
    vector<ll> a(n);
    rep(i,n) cin>>a[i];
    vector<vector<ll>> tree(n);
    rep(i,n-1){
        ll u,v; cin>>u>>v;
        u--; v--;
        tree[u].push_back(v);
        tree[v].push_back(u);
    }
    vector<ll> res(n, -1);
    vector<ll> lis(n+1, 1e10);
    lis[0]=0;
    // lis[i][j]: 根から i までの最短経路のうち、長さが j であるものの最後の値
    stack<ll> tr;
    stack<pair<ll,ll>> ch; // {インデックス, 元の値}
    tr.push(0);
    while(!tr.empty()){
        ll x=tr.top();
        if(res[x]==-1){
            auto itr = lower_bound(lis.begin(), lis.end(), a[x]);
            ll ind = itr - lis.begin();
            ch.push({ind, lis[ind]});
            lis[ind]=a[x];
            itr = lower_bound(lis.begin(), lis.end(), 1e10);
            res[x]=itr-lis.begin();
        }
        ll cnt=0;
        for(ll y : tree[x]){
            if(res[y]!=-1) continue;
            cnt++;
            tr.push(y);
        }
        if(cnt==0){
            tr.pop();
            pair<ll,ll> p =ch.top();
            lis[p.first] = p.second;
            ch.pop();
        }
    }
    rep(i,n){
        cout<<res[i]-1<<endl;
    }
    return 0;
}

Measured memory_bytes: 24960
// abc146_d
#include <bits/stdc++.h>
#ifdef LOCAL
#include "../cxx-prettyprint/prettyprint.hpp"
#endif
using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> P;

#define REP(i, n) for (int (i) = 0 ; (i) < (int)(n) ; ++(i))
#define REPN(i, m, n) for (int (i) = m ; (i) < (int)(n) ; ++(i))
#define REP_REV(i, n) for (int (i) = (int)(n) - 1 ; (i) >= 0 ; --(i))
#define REPN_REV(i, m, n) for (int (i) = (int)(n) - 1 ; (i) >= m ; --(i))
#define ALL(x) x.begin(), x.end()

#define INF ((1 << 29)-1)
#define MOD (1000000007)

#define print2D(h, w, arr) REP(i, h) { REP(j, w) cout << arr[i][j] << " "; cout << endl; }
#define print_line(vec, n) {for(int i=0;i<(n-1);i++) cout << (vec)[i] << " "; cout << (vec)[(n)-1] << endl;}
template<class T> void print(const T& x){cout << x << endl;}
template<class T, class... A> void print(const T& first, const A&... rest) { cout << first << " "; print(rest...); }
struct PreMain {PreMain(){cin.tie(0);ios::sync_with_stdio(false);cout<<fixed<<setprecision(20);}} premain;

struct Graph {

    int n;

    vector<vector<P>> edges;
    vector<int> cnt;
    int color_num;
    vector<int> edge_color;

    Graph(int n) : n(n), edges(n), cnt(n), edge_color(n-1) {}

    void add_edge(int i, int u, int v) {
        edges[u].emplace_back(v, i);
        edges[v].emplace_back(u, i);
        cnt[u]++;
        cnt[v]++;
    }

    void dfs(int u, int p, int c){

        int k = 1;
        for (auto e: edges[u]){
            int idx = e.second;
            int v = e.first;

            if (v == p) continue;

            if (k == c) k++;
            edge_color[idx] = k;
//            print(p, u, v, idx, k);
            dfs(v, u, k);
            k++;
        }
    }


    void calc(){

        int idx = max_element(ALL(cnt)) - cnt.begin();
        color_num = cnt[idx];

        dfs(idx, -1, -1);

        print(color_num);
        for (auto c: edge_color){
            print(c);
        }
    }

};

int main() {
#ifdef LOCAL
    ifstream in("../arg.txt"); cin.rdbuf(in.rdbuf());
#endif

    int N;
    cin >> N;

    Graph g(N);
    REP(i, N-1){
        int a, b;
        cin >> a >> b; a--; b--;
        g.add_edge(i, a, b);
    }

    g.calc();




    return 0;
}


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

map<string,int> dis;
int n;
string a[11],b[11];
string g,d;

string trans(string x,int id){
  string res = "";
  for(int i=0;i<x.size();i++){
    if(i+a[id].size()<=x.size() && x.substr(i,a[id].size()) == a[id]){
      res += b[id];
      i += a[id].size();
      i--;
    }else res += x[i];
  }
  return res;
}

int main(){
  while(cin >> n,n){
    for(int i=0;i<n;i++)cin >> a[i] >> b[i];
    cin >> g >> d;
    dis.clear();
    dis[g] = 0;
    queue<string> q; q.push(g);

    while(q.size()){
      string tmp = q.front(); q.pop();
      if(tmp == d)break;
      if(tmp.size()>10)continue;
      for(int i=0;i<n;i++){
	string trs = trans(tmp,i);
	if(dis.find(trs)==dis.end()){
	  dis[trs] = dis[tmp] + 1;
	  q.push(trs);
	}
      }
    }

    if(dis.find(d)!=dis.end())cout << dis[d] << endl;
    else cout << -1 << endl;
  }
}

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

using namespace std;

constexpr int Nmax = 10000;

int S[Nmax];

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

    int same = 0;

    int n;
    cin >> n;
    for (int i = 0; i < n; i++) {
        cin >> S[i];
    }
    int q;
    cin >> q;
    for (int i = 0; i < q; i++) {
        int value;
        cin >> value;
        for (int j = 0; j < n; j++) {
            if (S[j] == value) {
                same++;
                break;
            }
        }
    }
    cout << same << endl;

    return 0;
}

Measured memory_bytes: 3112
#include <bits/stdc++.h>
#define fo(i,a,b) for(i=a;i<=b;i++)
#define fd(i,a,b) for(i=a;i>=b;i--)
#define max(a,b) (a>b?a:b)
#define min(a,b) (a<b?a:b)
using namespace std;
typedef long long ll;
inline int read(){
	int n=0,f=1;char c;
	for(c=getchar();c!='-'&&(c<'0'||c>'9');c=getchar());
	if (c=='-') f=-1,c=getchar();
	for(;c>='0'&&c<='9';c=getchar()) n=(n<<3)+(n<<1)+(c&15);
	return n*f;
}
const int N=2e5+5;
int H,W,n,i,j,x,y,ans,now;
vector<int>g[N];
map<int,int>p[N];
int main(){
	H=read(),W=read(),n=read();
	fo(i,1,n){
		x=read(),y=read();
		g[y].push_back(x);
		p[y][x]=1;
	}
	ans=H,now=1;
	fo(i,1,W) {
		sort(g[i].begin(),g[i].end());
		int cnt=g[i].size();
		for(j=0;j<cnt&&g[i][j]<=now;j++);
		if (j!=cnt) ans=min(ans,g[i][j]-1);
	 	if (i==W) break;
	 	for(now++;p[i+1][now];now++);
	 	if (now>=H) break;
	}printf("%d\n",ans);
}

Measured memory_bytes: 34944
N = $stdin.gets.to_i
$es = {}
(N-1).times {
  a,b,c = $stdin.gets.split.map(&:to_i)
  $es[a] ||= {}; $es[b] ||= {}
  $es[a][b] = c; $es[b][a] = c
}

#p $es

Q,K = $stdin.gets.split.map(&:to_i)
visited = (0..N).map{ nil }
visited[K] = 0
next_nodes = [K]
while next_nodes.size > 0
  #p next_nodes
  next_nodes = next_nodes.map{ |i| 
    ns = $es[i].keys.reject{ |j| visited[j] }
    ns.each{ |j| visited[j] = $es[i][j] + visited[i] }
    ns
  }.flatten
end

#p visited

Q.times {
  x,y = $stdin.gets.split.map(&:to_i)  
  puts visited[x] + visited[y]
}


Measured memory_bytes: 52888
#include<bits/stdc++.h>
#define ll long long
#define speed_up    ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define rep(i,a,b) for(ll i=a;i<b;i++)
#define pb push_back
#define MAX 1000000007
using namespace std;
int main()
{
    speed_up
    ll n;cin>>n;
    ll a[n],b[n];
    for(ll i=0;i<n;i++) cin>>a[i];
     for(ll i=0;i<n;i++) cin>>b[i];
     ll sum=0;
     for(ll i=0;i<n;i++)
     {
     	if(a[i]>b[i]) sum+=a[i]-b[i];
	 }
	 cout<<sum;
     
	
	
	
	
	
	
 return 0;
}

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

int main() {
  int A, B, K;
  cin >> A >> B >> K;

  vector<int> v;
  for (int i = A; i <= A + K - 1 && i <= B; i++) v.push_back(i);
  for (int i = B; B - K + 1 <= i && A <= i; i--) v.push_back(i);
  sort(v.begin(), v.end());
  v.erase(unique(v.begin(), v.end()), v.end());
  for (int i : v) cout << i << endl;
}


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

using namespace std;
using namespace __gnu_cxx;

#define REP(i,n) for( (i)=0 ; (i)<(n) ; (i)++ )
#define rep(i,x,n) for( (i)=(x) ; (i)<(n) ; (i)++ )
#define REV(i,n) for( (i)=(n) ; (i)>=0 ; (i)-- )
#define FORIT(it,x) for( (it)=(x).begin() ; (it)!=(x).end() ; (it)++ )
#define foreach(it,c) for(__typeof((c).begin()) it=(c).begin();it!=(c).end();++it)
#define rforeach(it,c) for(__typeof((c).rbegin()) it=(c).rbegin();it!=(c).rend();++it)
#define foreach2d(i, j, v) foreach(i,v) foreach(j,*i)
#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(),(x).rend()
#define SZ(x) ((int)(x).size())
#define MMS(x,n) memset(x,n,sizeof(x))
#define mms(x,n,s) memset(x,n,sizeof(x)*s)
#define pb push_back
#define mp make_pair
#define NX next_permutation
#define UN(x) sort(all(x)),x.erase(unique(all(x)),x.end())
#define CV(x,n) count(all(x),(n))
#define FIND(x,n) find(all(x),(n))-(x).begin()
#define ACC(x) accumulate(all(x),0)
#define PPC(x) __builtin_popcountll(x)
#define LZ(x) __builtin_clz(x)
#define TZ(x) __builtin_ctz(x)
#define mxe(x) *max_element(all(x))
#define mne(x) *min_element(all(x))
#define low(x,i) lower_bound(all(x),i)
#define upp(x,i) upper_bound(all(x),i)
#define NXPOW2(x) (1ll << ((int)log2(x)+1))
#define PR(x) cout << #x << " = " << (x) << endl ;

typedef unsigned long long ull;
typedef long long ll;
typedef vector<int> vi;
typedef vector<vector<int> > vvi;
typedef pair<int, int> pii;

const int OO = (int) 2e9;
const double eps = 1e-9;

const int N = 200005;

int n, m;
char s[N];
vi adj[N];
int c[N][2];
queue<int> Q;
bool vis[N];

int main() {
	std::ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
#ifndef ONLINE_JUDGE
//	freopen("in.txt", "rt", stdin);
//	freopen("out.txt", "wt", stdout);
#endif
	cin >> n >> m >> s;
	for (int i = 0; i < m; i++) {
		int u, v;
		cin >> u >> v;
		u--, v--;
		adj[u].pb(v);
		adj[v].pb(u);
		c[u][s[v] - 'A']++;
		c[v][s[u] - 'A']++;
	}
	for (int i = 0; i < n; i++) {
		if (!c[i][0] || !c[i][1]) {
			Q.push(i);
			vis[i] = 1;
		}
	}
	while (!Q.empty()) {
		int cur = Q.front();
		Q.pop();
		for (int to : adj[cur]) {
			if (vis[to])
				continue;
			c[to][s[cur] - 'A']--;
			if (!c[to][0] || !c[to][1]) {
				Q.push(to);
				vis[to] = 1;
			}
		}
	}
	for (int i = 0; i < n; i++) {
		if (!vis[i]) {
			puts("Yes");
			return 0;
		}
	}
	puts("No");
	return 0;
}


Measured memory_bytes: 12800
X, N = input().split()
datalist = input().split()

Z = int(X)
flag = 0
count = 0

while flag != 2:

    flag = 0

    for num in datalist:
#        print('now is for Loop num = {}'.format(num))
        if int(num) == Z:
#            print('num equal Z. num = Z = {}'.format(Z))
            flag = 1
            break
#        print('here is under if . here is in for loop. break ln = 11')
#    print('here is out of for loop. ln = 12. Lets Check Flag statement')

    if flag == 0:
#        print('This is result!!')
        print(Z)
        flag = 2
#    print('flag = {}'.format(flag))

#    print('before count = {} '.format(count))

    count = abs(count) + 1
    if (count % 2) == 1:
       Z += count * (-1)
    else:
       Z += count 
    
#    print('Now End is While Loop.')
#    print('===')
#    print('Z={}'.format(Z))
#    print('after count={}'.format(count))
#    print('===')

Measured memory_bytes: 9192
#include <iostream>
#include <string>
#include <algorithm>
#include <cmath>
#include <vector>
#include <ctype.h>
#include <stdlib.h>
#include <map>
using namespace std;

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

	if (S == "ABC") {
		cout << "ARC" << endl;
	}
	else {
		cout << "ABC" << endl;
	}
}




Measured memory_bytes: 3592
import java.util.*;
import java.math.*;
public class Main{

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int P = sc.nextInt();
		for(int KK = 0; KK < P; KK++) {
			int n = sc.nextInt();
			int x = sc.nextInt();
			int y = sc.nextInt();
			Node start = new Node(sc.nextInt(),sc.nextInt());
			Node[] staff = new Node[n+1];
			for(int i = 0; i < n; i++) {
				staff[i] = new Node(sc.nextInt(),sc.nextInt());
			}
			for(int i = 0; i < n; i++) {
				int len = l(start,staff[i]);
				if(len > 10 * 10) continue;
				start.to.add(i);
			}
			for(int i = 0; i < n; i++) {
				for(int j = i + 1; j < n; j++) {
					int len = l(staff[i],staff[j]);
					if(len > 50 * 50) continue;
					staff[i].to.add(j);
					staff[j].to.add(i);
				}
			}
			int count = 0;
			int say   = 0;
			ArrayDeque<Data> queue = new ArrayDeque<Data>();
			for(int i = 0; i < start.to.size(); i++) {
				queue.add(new Data(start.to.get(i),0));
			}
			while(!queue.isEmpty() && count < 1500) {
				Data tmp = queue.pollFirst();
				Node check = staff[tmp.now];
				//????????????       //????????????
				if(check.time > tmp.time) continue;
				say = Math.max(tmp.time + x,say);
				count++;
				ArrayList<Integer> to = check.to;
				for(int i = 0; i < to.size(); i++) {
					queue.add(new Data(to.get(i),tmp.time + x));
				}
				//????????????
				check.time = tmp.time + x + y + 1;
			}
			if(count == 1500) System.out.println("You're always welcome!");
			else {
				System.out.println(say);
			}
		}
	}
	static class Data {
		int now;
		int time;
		Data(int now, int time) {
			this.now = now;
			this.time = time;
		}
	}
	static int l(Node a, Node b) {
		int k = (a.x - b.x) * (a.x - b.x) + (a.y - b.y) * (a.y - b.y);
		return k;
	}
	static class Node {
		int x;
		int y;
		int time;
		Node(int a, int b) {
			x = a;
			y = b;
		}
		ArrayList<Integer> to = new ArrayList<Integer>();
	}
}

Measured memory_bytes: 129904
#include<stdio.h>
#include<string.h>

static  int N = 1000;

int max(int, int);
int lcs(char *, char *);

int main(){
  char s1[1500], s2[1500];
  int n, i;
  scanf("%d", &n);
  for(i = 0; i < n; i++){
    scanf("%s %s", s1, s2);
    printf("%d\n", lcs(s1, s2));
  }

 return 0;
}

int max(int x, int y){

  if(x > y){
    return x;
  }else{
    return y;
  }
}

int lcs(char *x, char *y){

  int c[N+1][N+1];
  int m = strlen(x);
  int n = strlen(y);
  int maxl = 0, i, j;

  for(i = 0; i <= m; i++) c[i][0] = 0;
  for(j = 1; j <= n; j++) c[0][j] = 0;

  for(i = 1; i <= m; i++){
    for(j = 1; j <= n; j++){
      if(x[i-1] == y[j-1]){
	       c[i][j] = c[i-1][j-1]+1;
      }else{
	       c[i][j] = max(c[i-1][j], c[i][j-1]);
      }
      maxl = max(maxl,c[i][j]);
    }
  }
  return maxl;
}



Measured memory_bytes: 5648
#pragma GCC optimize ("O3")
#include <bits/stdc++.h>

using namespace std;
typedef long long int ll;
typedef long double lld;

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

	int n, k; cin >> n >> k;

	vector<int> a(n, 0);
	for(int i = 0; i < n; i++) cin >> a[i];

	vector<int> dp(k + 1, 0);
	
	dp[0] = 0;
	for(int i = 1; i <= k; i++) {
		dp[i] = 0;
		for(int j = 0; j < n; j++) {
			if(i - a[j] >= 0 && dp[i - a[j]] == 0) { dp[i] = 1; break;}
		}
	}
	if(dp[k]) cout << "First\n"; else cout << "Second\n";
}

Measured memory_bytes: 640
#include <bits/stdc++.h>
#include <math.h>
#include <cmath>

using namespace std;
using ll =long long;
using vi = vector<int>; 
using vvi = vector<vi>; 
using vl = vector<ll>; 
using vvl = vector<vl>; 
using vs = vector<string>;
using vvs = vector<vs>; 
using vc = vector<char>;
using vvc = vector<vc>; 
using vb = vector<bool>;
using vvb = vector<vb>; 

#define rep(i,n) ;for( int i =0; i < n ; i ++)
#define all(a) a.begin(),a.end()
#define pb(a) push_back(a)
#define pd(a) printf("%.10f\n",a)
#define mem(a) memset(a,0,sizeof(a))
#define f(i,a,b) for(int i=a;i<b;i++)
#define pri(a)  printf("%.14lf\n",a);
#define MOD 1000000007
bool is_int_lround(double x){
  return std::lround(x)==x;
}
ll keta(ll x){
  int n=0;
  while(x>0){
    x /=10 ;
    n ++;
  }
  return n;
}

ll conbi(int n,int m){
  
  cin>>n>>m;
  vector<ll> a(100);
  a[0] =1;
  for(int i=0;i<14;i++){
    a[i+1]=a[i]*(i+1);
  }
  return a[n] /(a[m] *a[n-m]);
}

int main(){
  int n;cin>>n;
  vvi x(n);
  vvi y(n);
  rep(i,n){
    int a;cin>>a;
    rep(j,a){
      int X,Y;
      cin>>X>>Y;
      X--;
      x[i].push_back(X);
      y[i].push_back(Y);
    }
  }
  int ans=0;
  for (int tmp = 0; tmp < (1 << n); tmp++) {
    bitset<15> s(tmp);
    bool ok=true;
    rep(i,n){
      
      rep(j,x[i].size()){
        if(s.test(i)){
          if(s.test(x[i][j])!=y[i][j]){
            ok=false;
          }
        }
      }
      
    }
    if(ok){
      int kari =s.count();
      ans =max(ans,kari);
    }
  }
  cout<<ans<<endl;
  
}


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

int res[10][1000];

int main() {
	vector<int> v;
	for(int i = 0; i < 10; i++) {
		v.push_back(i);
	}

	sort(v.begin(), v.end());
	int mx = 0;
	do {
		int tmp = 0;
		for(int j = 0; j < 10; j++) {
			tmp += v[j] * (1+j);
			res[j][tmp]++;
		}
	} while(next_permutation(v.begin(), v.end()));

	int fact = 1;
	for(int i = 0; i < 10; i++) {
		for(int j = 0; j < 1000; j++) {
			res[9-i][j] /= fact;
		}
		fact *= (i+1);
	}

	int n, s;
	while(cin >> n >> s) {
		if(n ==0 || n > 10 || s >= 1000)
			cout << 0 << endl;
		else
			cout << res[n-1][s] << endl;
	}
}

Measured memory_bytes: 1256
//
//  main.cpp
//  ITP1_9-C
//
//  Created by Saicj on 2015/08/04.
//  Copyright (c) 2015??´ saicj. All rights reserved.
//

#include <iostream>
using namespace std;

int main() {

    int count;
    
    int resultA = 0;
    int resultB = 0;
    
    cin >> count;
    
    for (int i = 0; i < count; i++ ) {
        
        string a;
        string b;
        
        cin >> a >> b;
        
        if (a > b) {
            
            resultA += 3;
            
        }else if (a < b){
            
            resultB += 3;
            
        }else if (a == b){
            
            resultA++;
            resultB++;
        }
            
    }
    
    cout << resultA << " " << resultB << endl;
    
    return 0;
}

Measured memory_bytes: 1212
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,k,n) for(int i = (int)(k); i < (int)(n); i++)
#define REP(i,n) FOR(i,0,n)
#define ALL(a) a.begin(), a.end()
#define MS(m,v) memset(m,v,sizeof(m))
typedef long long ll;
typedef long double ld;
typedef vector<int> vi;
typedef vector<string> vs;
typedef pair<int, int> pii;
const int MOD = 1000000007;
const int INF = MOD + 1;
const ld EPS = 1e-12;
template<class T> T &chmin(T &a, const T &b) { return a = min(a, b); }
template<class T> T &chmax(T &a, const T &b) { return a = max(a, b); }

/*--------------------template--------------------*/

int main()
{
	cin.sync_with_stdio(false); cout << fixed << setprecision(10);
	int a, b, c;
	string s, t;
	cin >> s;
	int ans = 0;
	t = "CODEFESTIVAL2016";
	REP(i, s.size())
	{
		if (s[i] != t[i]) ans++;
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 764