akhauriyash/Code-Regression huggingface dataset:
N = int(input())
list_S = []
num = len(str(N))
count = N
for i in range(1, num + 1):
    q = count // (10 ** (num - i))
    list_S.append(q)
    count = count % (10 ** (num - i))
if N % sum(list_S) == 0:
    print("Yes")
else:
    print("No")


Measured memory_bytes: 2940
n,a,b = map(int,input().split())
pas,foreignpass = 0,0
s = input()
for i in range (n):
  if pas == a+b:
    print("No")
  elif s[i] == "c":
    print("No")
    continue
  elif s[i] == "a":
    pas += 1
    print("Yes")
  elif s[i] == "b" and foreignpass < b:
    pas += 1
    print("Yes")
    foreignpass += 1
  else:
    print("No")
    continue

Measured memory_bytes: 9088
while True:
    n = int(input())
    if n == 0:
        break
    d = {}
    for _ in range(n):
        a, b = input().split()
        d[a] = b
    m = int(input())
    ans = ""
    for _ in range(m):
        a = input().strip()
        ans += d[a] if a in d else a
    print(ans)

Measured memory_bytes: 7808
#include <stdio.h>

struct Node {
	int p, l, r;
};
struct Node T[10000];

void preParse(int u) {
	if (u == -1) {
		return;
	}
	printf(" %d", u);
	preParse(T[u].l);
	preParse(T[u].r);
}

void inParse(int u) {
	if (u == -1) {
		return;
	}
	inParse(T[u].l);
	printf(" %d", u);
	inParse(T[u].r);
}

void postParse(int u) {
	if (u == -1) {
		return;
	}
	postParse(T[u].l);
	postParse(T[u].r);
	printf(" %d", u);
}

int main(void)
{
	int i, num, root, a, b, c;

	scanf("%d", &num);
	for (i = 0; i < num; i++) {
		T[i].p = -1;
	}

	for (i = 0; i < num; i++) {
		scanf("%d %d %d", &a, &b, &c);
		T[a].l = b;
		T[a].r = c;
		if (b != -1) {
			T[b].p = a;
		}
		if (c != -1) {
			T[c].p = a;
		}
	}

	for (i = 0; i < num; i++) {
		if (T[i].p == -1) {
			root = i;
		}
	}

	printf("Preorder\n");
	preParse(root);
	putchar('\n');
	printf("Inorder\n");
	inParse(root);
	putchar('\n');
	printf("Postorder\n");
	postParse(root);
	putchar('\n');
	
	return 0;
}


Measured memory_bytes: 2120
#include <iostream>
#include <sstream>
#include <stack>
#include <iomanip>
#include <string>
#include <cstring>
#include <algorithm>
#include <functional>
#include <cstdlib>
#include <map>
#include <set>
#include <vector>
#include <utility>
#include <queue>
#include <cmath>

#define BEGIN(x) x.begin()
#define END(x) x.end()
#define ALL(x) BEGIN(x), END(x)
#define PAIR make_pair
#define VEC(type) vector<type >

#define FOR(i, A, B) for(auto i = (A);i != (B); i++)
#define FORD(i, A, B) for(auto i = (A);i != (B); i--)

#define READRANGE(begin, end) FOR(it, begin, end) cin >> *it
#define READVEC(V) READRANGE(BEGIN(V), END(V))

using namespace std;

typedef long long lint;
typedef pair<int, int> Pii;
typedef pair<int, lint> Pil;
typedef pair<lint, lint> Pll;
typedef pair<lint, int> Pli;

// ---- BEGIN LIBRARY CODE ----
// ---- END LIBRARY CODE ----
void io_init()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
};

int main(int argc, char **argv)
{
    io_init();

    // Actual program code starts here.
    lint A, B, N;
    cin >> A >> B >> N;
    lint r = min(N, B - 1);
    cout << (A * r / B) << endl;
    return 0;
};


Measured memory_bytes: 3656
#define _USE_MATH_DEFINES
#include <bits/stdc++.h>
#define USE_LLONG_AS_INT
#ifdef USE_LLONG_AS_INT
#define int long long
#define inf (1ll<<60)
#else
#define inf (1<<30)
#endif
#define rep(i,n) for(int i=0;i<(n);i++)
#define Rep(i,a,b) for(int i=(a);i<(b);i++)
#define REP(i,a,b) for(int i=(a);i<=(b);i++)
#define rev(i,n) for(int i=(n)-1;i>=0;i--)
#define vi vector<int>
#define vvi vector<vi>
#define pb push_back
#define eb emplace_back
#define pi pair<int,int>
#define vp vector<pair<int,int>>
#define mp make_pair
#define all(v) (v).begin(),(v).end()
#define fi first
#define se second
#define MEMSET(a) memset(a,0,sizeof(a))
#define Yes(f) cout<<(f?"Yes":"No")<<endl
#define yes(f) cout<<(f?"yes":"no")<<endl
#define YES(f) cout<<(f?"YES":"NO")<<endl
#define SORT(v) sort(all(v))
#define RSORT(v) sort(all(v), greater<int>())

using namespace std;

const int mod=1e9+7;
const string sp=" ";

void run();

void init() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout<<fixed<<setprecision(12);
}

signed main(){
    init();
    run();
    return 0;
}

int modpow(int x,int n = mod-2) {
    int result = 1;
    while (n > 0) {
        if ((n & 1) == 1) {
            result = (result * x) % mod;
        }
        x = (x * x) % mod;
        n >>= 1;
    }
 
    return result;
}

int f(int n,int r){
    int a=1;
    rep(i,r)a=a*(n-i)%mod;
    int b=1;
    rep(i,r)b=b*(i+1)%mod;
    b=modpow(b);
    return a*b%mod;
}

void run(){
    int n,a,b;
    cin>>n>>a>>b;
    int ans=modpow(2,n)-1-f(n,a);
    if(ans<0)ans+=mod;
    ans-=f(n,b);
    if(ans<0)ans+=mod;
    cout<<ans<<endl;
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int a[] = new int[3];
		a[0] = sc.nextInt();
		a[1] = sc.nextInt();
		a[2] = sc.nextInt();
		int K = sc.nextInt();
		sc.close();
		long sum = 0;
		if (K >= a[0]) {
			sum += a[0];
			K -= a[0];
		} else {
			sum += K;
			K = 0;
		}
		if (K >= a[1]) {
			K -= a[1];
		} else {
			K = 0;
		}
		if (K >= a[2]) {
			sum -= a[2];
			K -= a[2];
		} else {
			sum -= K;
			K = 0;
		}
		System.out.println(sum);
	}
}


Measured memory_bytes: 35796
#include <bits/stdc++.h>
#define REP(i,s,e) for(int i=(s); i<(e);i++)
#define rep(i,n) REP(i,0,n)
#define rep1(i,n) REP(i,1,n)
#define repe(i,n) for(auto &&i:n)
#define all(v) (v).begin(),(v).end()
#define decimal fixed<<setprecision(20)
#define fastcin() cin.tie(0);ios::sync_with_stdio(false)
using namespace std;
using LL = long long;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
const int INF = 1e9;
const LL LLINF = 1e16;

struct UnionFind{
    vector<int> data;

    UnionFind(int sz){
        data.assign(sz, -1);
    }

    bool unite(int x, int y){
        x = find(x), y = find(y);
        if(x == y) return(false);
        if(data[x] > data[y]) swap(x, y);
        data[x] += data[y];
        data[y] = x;
        return(true);
    }

    int find(int k){
        if(data[k] < 0) return(k);
        return(data[k] = find(data[k]));
    }

    int size(int k){
        return(-data[find(k)]);
    }
};

int main(){
    int n;
    cin >> n;
    vector<int> px(n), py(n);
    rep(i, n) cin >> px[i] >> py[i];
    UnionFind UF(n);
    map<int, int> mx, my;
    rep(i, n){
        if(mx.count(px[i])) UF.unite(i, mx[px[i]]);
        mx[px[i]] = i;
        if(my.count(py[i])) UF.unite(i, my[py[i]]);
        my[py[i]] = i;
    }

    vector<set<int>> sx(n), sy(n);
    rep(i, n){
        sx[UF.find(i)].insert(px[i]);
        sy[UF.find(i)].insert(py[i]);
    }
    LL ans = 0;
    rep(i, n){
        // cout << sx[i].size() << " " << sy[i].size() << endl;
        ans += 1LL*sx[i].size()*sy[i].size();
    }
    cout << ans - n << endl;


}

Measured memory_bytes: 20224
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <string>
#include <cstdio>
using namespace std;

#define int long long
#define INF 1e18

signed main() {
    int n; cin >> n;
    for(int i = n; i > 0; i--) {
        double root = sqrt(i);
        if(root - (int)root == 0) {
            cout << i << endl;
            return 0;
        }
    }
}


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

int main() {
	int n,sum=0;
	cin >> n;
	int d[n];
	int a[101]={0};
	
	for (int i=0;i<n;i++){
			cin >> d[i];
			a[d[i]]=1;
	}	
	for(int i=0;i<101;i++){
			sum=sum+a[i];
	}
	cout << sum << endl;
	return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;
import java.io.PrintWriter;

class Main {
    enum NodeType {
        Root, InternalNode, Leaf
    };

    class Node {
        int parent = -1;
        int depth = 0;
        NodeType type = NodeType.Root;
        int[] children;

        Node(int[] children) {
            this.children = children;
        }

        String strType() {
            String result = "root";
            switch(type) {
                case Leaf:
                    result = "leaf";
                    break;
                case InternalNode:
                    result = "internal node";
                    break;
            }
            return result;
        }
    }

    Node[] setNodes(int[][] nodes) {
        int n = nodes.length;
        Node[] result = new Node[n];
        int i;
        for (i = 0; i < n; i ++) {
            result[i] = new Node(nodes[i]);
        }

        int[] children;
        for (i = 0; i < n; i ++) {
            children = result[i].children;
            for (int c: children) {
                result[c].parent = i;
            }
        }

        int parent = 0;
        for (i = 0; i < n; i ++) {
            if (result[i].parent == -1) {
                parent = i;
            } else {
                if (result[i].children.length == 0) {
                    result[i].type = NodeType.Leaf;
                } else {
                    result[i].type = NodeType.InternalNode;
                }
            }
        }

        setDepth(result, parent, 0);
        return result;
    }

    void setDepth(Node[] nodes, int index, int depth) {
        Node node = nodes[index];
        node.depth = depth;
        for (int c: node.children) {
            setDepth(nodes, c, depth + 1);
        }
        return;
    }

    void printNodes(Node[] nodes, PrintWriter out) {
        for (int i = 0; i < nodes.length; i ++) {
            out.print("node " + i + ": ");
            out.print("parent = " + nodes[i].parent + ", ");
            out.print("depth = " + nodes[i].depth + ", ");
            out.print(nodes[i].strType() + ", ");
            out.print("[");
            for (int j = 0; j < nodes[i].children.length; j ++) {
                out.print(nodes[i].children[j]);
                if (j < nodes[i].children.length - 1) out.print(", ");
            }
            out.println("]");
        }

    }

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

        int n = Integer.parseInt(sc.next());
        int k = 0;
        int[][] nodes = new int[n][];
        int id;
        for (int i = 0; i < n; i ++) {
            id = Integer.parseInt(sc.next()); // node id
            k = Integer.parseInt(sc.next()); // k
            int[] children = new int[k];
            for (int j = 0; j < k; j ++) {
                children[j] = Integer.parseInt(sc.next());
            }
            nodes[id] = children;
        }

        Main m = new Main();
        Node[] result = m.setNodes(nodes);
        m.printNodes(result, out);
        out.flush();
    }
}



Measured memory_bytes: 85068
#include <bits/stdc++.h>
#define FOR(i,k,n) for(int i=(k);i<int(n);++i)
#define REP(i,n) FOR(i,0,n)
#define ALL(x) begin(x),end(x)

using ll=long long;
constexpr ll mod = 1000000007;

// cond: a>b
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
ll lcm(ll a,ll b){return a/gcd(a,b)*b;}

using namespace std;
struct Data {
  ll num;
  ll sum;
  Data() : num(1), sum(0) {;}
  Data(int64_t n, int64_t s) : num(n), sum(s) {;}
};
ll inv(ll a,ll p){
  return ( a == 1 ? 1 : (1 - p*inv(p%a,a)) / a + p );
}

inline Data Merge(Data left, Data right) {
  ll l = lcm(left.num, right.num);
  ll g = gcd(left.num, right.num);
  ll llinv = (right.num / g) % mod;
  ll lrinv = (left.num / g) % mod;
  ll s = left.sum * llinv + right.sum * lrinv;
  return Data(l, s % mod);
}

struct SegmentTree {
  int n; vector<Data> data;
  SegmentTree(int N) : n(1 << N), data(n * 2) {}
  void update (int pos, Data value) {
    data[pos] = value;
    while (pos < 2*n-1) {
      int l = pos, r = pos^1;
      if (l > r) swap(l, r);
      pos = pos / 2 + n;
      data[pos] = Merge(data[l], data[r]);
    }
  }
  Data sub(int fr, int to, int node, int la, int ra) {
    if (ra<=fr || to<=la) return Data();
    if (fr<=la && ra<=to) return data[node];
    Data vl = sub(fr, to, (node-n)*2+0, la, (la+ra)/2);
    Data vr = sub(fr, to, (node-n)*2+1, (la+ra)/2, ra);
    return Merge(vl, vr);
  }
  Data query(int fr, int to) { return sub(fr, to, 2*n-2, 0, n); }
};

int main() {
  int64_t n,q;
  cin>>n>>q;
  vector<int64_t> p(n);
  REP(i,n) {
    cin>>p[i];
  }
  vector<int64_t> c(n, 43);
  vector<int64_t> sum(n, 0);
  vector<int64_t> x(n, 0);
  iota(ALL(x), 1);
  REP(i,42) {
    vector<int64_t> y = x;
    REP(j,n) y[j] = p[x[j]-1];
    swap(x, y);
    REP(j,n) if (c[j] > 41) sum[j] += x[j];
    REP(j,n) if (x[j] == j+1) c[j] = min(c[j], (int64_t)i+1);
  }
  SegmentTree st(17);
  REP(i,n) st.update(i, Data(c[i], sum[i] % mod));
  REP(i,q) {
    int64_t l,r;
    cin>>l>>r;
    --l; --r;
    auto res = st.query(l, r+1);
    cout << res.sum << endl;
  }
  return 0;
}

Measured memory_bytes: 10900
#include <iostream>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

using namespace std;

int abs(int n) {
	if (n > 0) { return n; }
	return -n;
}

int main() {
	bool flag[101][101];
	for (int i = 0; i < 101; i++) {
		for (int k = 0; k < 101; k++) {
			flag[i][k] = true;
		}
	}

	int N = 0; cin >> N;

	int *x = new int[N];
	int *y = new int[N];
	int *h = new int[N];

	int max = -1; int maxX = 0, maxY = 0;

	for (int i = 0; i < N; i++) {
		cin >> x[i] >> y[i] >> h[i];
		if (h[i] >= max) {
			maxX = x[i], maxY = y[i]; max = h[i];
		}
	}

	for (int i = 0; i <= 100; i++) {
		int H = max + i;

		for (int k = -i; k <= i; k++) {
			int X = maxX + k; if (X < 0 || X>100) { continue; }
			int Y1 = maxY + i - abs(k); int Y2 = maxY - i + abs(k);

			int n = 0;
			for (n = 0; n < N; n++) {
				if (Y1 > 100) { break; }
				if (h[n] == 0) {
					continue;
				}
				if (abs(X - x[n]) + abs(Y1 - y[n]) + h[n] != H) {
					break;
				}
			}
			if (n == N) {
				cout << X << " " << Y1 << " " << H;
				delete[] x; delete[] y; delete[] h; return 0;
			}

			for (n = 0; n < N; n++) {
				if (Y2 < 0) { break; }
				if (h[n] == 0) {
					continue;
				}
				if (abs(X - x[n]) + abs(Y2 - y[n]) + h[n] != H) {
					break;
				}
			}
			if (n == N) {
				cout << X << " " << Y2 << " " << H;
				delete[] x; delete[] y; delete[] h; return 0;
			}
		}
	}

	delete[] x; delete[] y; delete[] h;
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <cstring>
#include <string>
#include <cmath>
using namespace std;
int a[105];

int main(){
    int n;
    scanf("%d", &n);
    memset(a, 0, sizeof(a));
    for (int i = 0; i<n; i++) {
        scanf("%d", &a[i]);
    }
    int ans = 0x3f3f3f3f, temp = 0;
    for (int i = -100; i<=100; i++) {
        temp = 0;
        for (int j = 0; j<n; j++) {
            temp += (a[j]-i)*(a[j]-i);
        }
        ans = min(ans, temp);
    }
    printf("%d\n", ans);
}

Measured memory_bytes: 256
#ifdef DBG1
  #define LOCAL
#endif

#ifdef LOCAL
  #define _GLIBCXX_DEBUG
#endif

#include <iostream>
#include <cstdio>
#include <cstring>
#include <cassert>
#include <cstring>
#include <string>
#include <vector>
#include <algorithm>
#include <map>
#include <set>

#ifdef DBG1
    #define dbg(...) fprintf(stderr, __VA_ARGS__)
#else
    #define dbg(...)
#endif

using namespace std;

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

bool solve() {
  int n;
  int W, H;
  if (scanf("%d%d%d", &H, &W, &n) != 3) { return false; }

  vector<int> minY(H + 1, W);
  minY[H] = 0;
  for (int i = 0; i < n; ++i) {
    int x, y;
    scanf("%d%d", &x, &y);
    --x, --y;
    minY[x] = min(minY[x], y);
  }

  int res = 0;
  int x = 0, maxY = 0;
  while (1) {
    if (minY[x + 1] <= maxY) {
      break;
    }
    x++;
    res += 1;
    maxY = min(maxY + 1, minY[x] - 1);
  }
  printf("%d\n", res + 1);


  return true;
}

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

Measured memory_bytes: 1024
s = input()
ans = 10 ** 9
for alpha in range(97,123):
    a = chr(alpha)
    cnt = 0
    ret = 0
    for i in range(len(s)):
        if s[i] == a:
            ret = max(ret,cnt)
            cnt = 0
        else:
            cnt += 1
    ret = max(ret,cnt)
    ans = min(ans,ret)
print(ans)


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

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

    int n = s.length();
    int count = 0;
    for(int i = 0; i < n / 2; i++) {
        if(s[i] != s[n-1-i]) count++;
    }

    cout << count << endl;
}

Measured memory_bytes: 3532
/*
Problem:AcCoder ARC-086 C
Algorithm:
Status:
*/

#include <iostream>
#include <cstdio>
#include <cmath>
#include <algorithm>
#include <string>
#include <vector>
#include <map>
#include <queue>
#include <deque>
#include <set>
#include <sstream>
#include <utility>
#include <list>
#include <ctime>
#include <memory.h>
#include <stack>
#include <stdio.h>
#include <string.h>

using namespace std;

const int INF=1e9+7;

int main()
{
	map<int,int> mp;
	vector<int> cnt;
	int n,k,kind=0;
	cin>>n>>k;
	for(int i=0;i<n;i++){
		int a;
		cin>>a;
		if(mp.count(a)==0){
			//cout<<"++"<<endl;
			kind++;
		}
		mp[a]++;
	}
	if(kind-k<0){
		cout<<"0"<<endl;
		return 0;
	}
	
	for(map<int,int>::iterator it=mp.begin();it!=mp.end();it++){
		cnt.push_back(it->second);
		//cout<<it->second<<" ";
	}
	//cout<<endl;
	sort(cnt.begin(),cnt.end());
	
	/*
	int ans=0,i=cnt.size()-1,changed=0;
	while(kind-changed>k){
		if(kind-changed-cnt[i]>=k){
			cout<<ans+1<<endl;
			return 0;
		}
		changed++;
		i--;
		ans+=cnt[i];
	}*/
	int ss=0;
    for(int i=k;i<kind;i++){
    	ss+=cnt[i-k];
    }
    
	cout<<ss<<endl;
	return 0;
	
	return 0;
}


Measured memory_bytes: 10748
MAX_N = 50
MAX_DAY = 30

def solve(n, f):
    dp = [[set() for j in range(n)] for i in range(MAX_DAY + 1)]
    for i in range(n):
        dp[0][i].add(i)

    for d in range(1, MAX_DAY + 1):

        # for line in dp[:5]:
        #     print(line)

        for i in range(n):
            dp[d][i] |= dp[d - 1][i]
            for j in range(n):
                if f[d][i] and f[d][j]:
                    dp[d][i] |= dp[d - 1][j]

            if len(dp[d][i]) == n:
                return d

    return -1

######################################

while True:
    n = int(input())
    if n == 0:
        exit()

    f = [[False] * n for i in range(MAX_DAY + 1)]
    for i in range(n):
        _, *li = map(int, input().split())
        for x in li:
            f[x][i] = True

    # for line in f:
    #     print(line)

    print(solve(n, f))

Measured memory_bytes: 13912
#l=int(input())
n,k=map(int,input().split())
#pl=list(map(int,input().split()))
#l=[list(map(int,input().split())) for i in range(n)]

mod=10**9+7
total=0

for m in range(k,n+2):
    add=m*(n-m+1)+1
    total=(total+add)%mod
print(total)





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

using namespace std;

typedef long long ll;

int main()
{
    ll N, M;
    cin >> N >> M;
    ll left = 1;
    ll right = M + 1;
    ll _left = N - (M - 1);
    ll _right = N;
    while (1)
    {
        if (M % 2 == 1)
        {
            if (right - left == -1)
            {
                break;
            }
        }
        else
        {
            if (right - left == 0)
            {
                break;
            }
        }
        cout << left << " " << right << endl;
        left++;
        right--;
    }
    while (1)
    {
        if (M % 2 == 0)
        {
            if (_right - _left == -1)
            {
                break;
            }
        }
        else
        {
            if (_right - _left == 0)
            {
                break;
            }
        }
        cout << _left << " " << _right << endl;
        _left++;
        _right--;
    }
}

Measured memory_bytes: 3640
#define _USE_MATH_DEFINES
#include<iostream>
#include<string>
#include<queue>
#include<cmath>
#include<map>
#include<set>
#include<list>
#include<iomanip>
#include<vector>
#include<random>
#include<functional>
#include<algorithm>
#include<stack>
#include<cstdio>
#include<cstring>
#include<bitset>
#include<unordered_map>
#include<climits>
#include<fstream>
#include<time.h>
#include<cassert>

using namespace std;
#define ll long long
#define ld long double
#define int long long
#define all(a) (a).begin(),(a).end()
#define EPS (1e-13)
#define fs first
#define sc second
#define xx first
#define yy second.first
#define zz second.second
#define H pair<int, int>
#define P pair<int, pair<int, int>>
#define Q(i,j,k) mkp(i,mkp(j,k))
#define rep(i,n) for(int (i) = 0 ; (i) < (n) ; (i)++)
#define mkp make_pair
#define pb push_back
#define lb lower_bound
#define ub upper_bound
#define crdcomp(b) sort(all((b)));(b).erase(unique(all((b))),(b).end())
#define ssp(i,n) (i==n-1?"\n":" ")
const int mod = 1e9 + 7;
const int Mod = 998244353;
const ll Inf = 3 * 1e18;
const int inf = 15 * 1e8;
ll read() {
	ll u, k = scanf("%lld", &u);
	return u;
}
ll gcd(ll i, ll j) {
	if (i > j) swap(i, j);
	if (i == 0) return j;
	return gcd(j % i, i);
}
ll mod_pow(ll x, ll n, ll p) {
	ll res = 1;
	while (n > 0) {
		if (n & 1) res = res * x % p;
		x = x * x % p;
		n >>= 1;
	}
	return res;
}
ll bcount(ll x) {
	int sum = 0;
	for (int i = 0; i < 20; i++)
		if ((1ll << i) & x) sum++;
	return sum;
}
const int fn_ = 2000000;
ll fact_[fn_], comp_[fn_];
ll comb(ll x, ll y, ll Mod = mod) {
	if (!fact_[0]) {
		fact_[0] = 1; comp_[0] = 1;
		for (int i = 1; i < fn_; i++) {
			fact_[i] = fact_[i - 1] * i % Mod;
			comp_[i] = mod_pow(fact_[i], Mod - 2, Mod);
		}
	}
	if (x < y) return 0;
	return fact_[x] * comp_[x - y] % Mod * comp_[y] % Mod;
}
//------------------------]---------------------------
signed main() {
	int n;
	vector<int>a(200000);
	cin >> n;
	int ans = 0;
	for (int i = 0; i < n; i++) {
		cin >> a[i];
		if (i > 0 && a[i] > a[i - 1]) {
			ans++;
		}
	}
	cout << ans << endl;
}


Measured memory_bytes: 4256
#!usr/bin/env python3
from collections import defaultdict
from heapq import heappush, heappop
import sys
import math
import bisect
import random
def LI(): return list(map(int, sys.stdin.readline().split()))
def I(): return int(sys.stdin.readline())
def LS():return list(map(list, sys.stdin.readline().split()))
def S(): return list(sys.stdin.readline())[:-1]
def IR(n):
    l = [None for i in range(n)]
    for i in range(n):l[i] = I()
    return l
def LIR(n):
    l = [None for i in range(n)]
    for i in range(n):l[i] = LI()
    return l
def SR(n):
    l = [None for i in range(n)]
    for i in range(n):l[i] = S()
    return l
def LSR(n):
    l = [None for i in range(n)]
    for i in range(n):l[i] = SR()
    return l
mod = 1000000007

#A

#B

#C
x = I()
a = 0
i = 1
while a < x:
    a += i
    i += 1
print(i-1)
#D

#E

#F

#G

#H

#I

#J

#K

#L

#M

#N

#O

#P

#Q

#R

#S

#T


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

using namespace std;
typedef long long ll;
const int INF = 1e9;
const int MOD = 1e9 + 7;
const ll LINF = 1e18;

int main() {

    int d, g; cin >> d >> g;
    vector<int> p(d);
    vector<int> c(d);
    for (int i = 0; i < d; ++i) {
        cin >> p[i] >> c[i];
    }

    int ans = INF;

    for (int bit = 0; bit < (1 << d); ++bit) {
        int sum = 0;
        int cnt = 0;
        for (int i = 0; i < d; ++i) {
            if (bit & (1 << i)) {
                sum += 100 * (i + 1) * p[i] + c[i];
                cnt += p[i];
            }
        }

        if (sum >= g) {
            ans = min(ans, cnt);
        } else {
            for (int i = d - 1; i >= 0; --i) {
                if (!(bit & (1 << i))) {
                    bool brk = false;
                    for (int j = 1; j < p[i]; ++j) {
                        sum += 100 * (i + 1);
                        cnt++;
                        if (sum >= g) {
                            brk = true;
                            break;
                        }
                    }
                    if (brk) break;
                }
            }

            if (sum >= g) {
                ans = min(ans, cnt);
            }
        }
    }

    cout << ans << endl;
}

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

int main(){
  int i,n;
  cin >> n;
  long long a[n+1],sum=0;
  for(i=1;i<=n;i++){
    cin >> a[i];
    a[i]-=i;
  }
  sort(a+1,a+n+1);
  long long ans=0; 
  for(i=1;i<=n;i++){
    ans+=abs(a[i]-a[n/2+1]);
  }
  cout << ans << endl;
  return 0;
}
  
  


Measured memory_bytes: 1792
from collections import deque
k = int(input())

d = deque(map(str, range(1, 10)))

counter = 1
while True:
    v = d.popleft()
    if (counter == k):
        print(v)
        break

    counter += 1

    first = v[-1]
    if first == "9":
        d.append(v + "8")
        d.append(v + "9") 
    elif first == "0":
        d.append(v + "0")
        d.append(v + "1") 
    else:
        for i in [-1, 0, 1]:
            d.append(v + str(int(first) + i))

        

Measured memory_bytes: 17012
#coding=UTF-8

N=int(input())

mozir=input()
hyo=mozir.split(' ')
A=[int(mono) for mono in hyo]

ans=0
kireiA=sorted(A,reverse=True)
mae=0
tmphen=0
for bo in kireiA:
    if mae==bo:
        if tmphen == 0:
            tmphen=mae
            mae=0 # do not use again
            continue
        else:
            ans=tmphen*mae
            break

    mae=bo

print(ans)


Measured memory_bytes: 16344
#include <algorithm>
#include<iostream>
#include<vector>
#include<map>
#include<string>

#include<stdlib.h>
#include<string.h>
#include<math.h>
#include<limits.h>

using namespace std;

int num2(long n){
  int cnt=0;
  while(n % 2 == 0){
	cnt ++;
	n = n/2;
  }
  return cnt;
}

int main(){
  long n,ii;
  vector<long> a;
  long cnt = 0;
  cin >> n;
  a.resize(n);
  for(ii=0;ii<n;ii++){
	cin >> a[ii];
  }

  for(ii=0;ii<n;ii++){
	cnt += num2(a[ii]);
  }

  cout << cnt << endl;
  return 0;
}


Measured memory_bytes: 384
#include<iostream>
using namespace std;
int main(){
  	char c;
  	cin >> c;
  	if(c=='a' || c=='e' || c=='i' || c=='o' || c=='u'){
    	cout << "vowel\n";
    }
  	else{
      	cout << "consonant\n";
    }
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
using namespace std;
int main(){
	int W,H,x,y,r;
	cin>>W>>H>>x>>y>>r;
	
	W=W-r;
	H=H-r;
	if(x>=r && x<=W){
		if(y>=r && y<=H){
			cout<<"Yes"<<endl;
			
		}else{cout<<"No"<<endl;}
	}else{cout<<"No"<<endl;}
	
	
	
	
	
}


Measured memory_bytes: 3112
#include <iostream>
#include <bits/stdc++.h>
using namespace std;
typedef  long long int ll;
typedef long double db;
#define pb push_back
#define mp make_pair
#define ub(v,val) upper_bound(v.begin(),v.end(),val)
#define np(str) next_permutation(str.begin(),str.end())
#define lb(v,val) lower_bound(v.begin(),v.end(),val)
#define sortv(vec) sort(vec.begin(),vec.end())
#define rev(p) reverse(p.begin(),p.end());
#define v vector
#define PI 3.1415926535
#define len length()
#define repc(i,s,e) for(ll i=s;i<e;i++)
#define fi first
#define se second
#define mset(a,val) memset(a,val,sizeof(a));
#define mt make_tuple
#define repr(i,n) for(ll i=n-1;i>=0;i--)
#define rep(i,n) for( ll i=0;i<n;i++)
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
const ll M = 1e9 + 7;
ll INF = 1e18;

ll n, m;
v<v<char>>s;
v<v<ll>> used;
ll cnt = 0;
void dfs(ll i, ll j) {
	used[i][j] = cnt;
	v<pair<ll, ll>> move = {{1, 0}, {0, 1}, { -1, 0}, {0, -1}};
	for (auto mv : move) {
		ll x = i + mv.fi;
		ll y = j + mv.se;
		if (x >= 0 && x < n && y >= 0 && y < m) {
			if (s[x][y] == '.' && used[x][y] == 0) {
				dfs(x, y);
			}
		}
	}
}
v<v<ll>> adj;
v<bool> vis;
int main() {
	// your code goes here
	IOS;

#ifndef ONLINE_JUDGE
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#endif
	ll i, j, t, k, x, y, z,  N;
	cin >> n >> m;
	ll x1, x2, y1, y2;
	cin >> x1 >> y1;
	cin >> x2 >> y2;
	s.resize(n, v<char>(m));
	used.assign(n, v<ll>(m, 0));
	rep(i, n) {
		rep(j, m) {
			cin >> s[i][j];
		}
	}
	rep(i, n) {
		rep(j, m) {
			if (used[i][j] == 0 && s[i][j] == '.') {
				cnt++;
				dfs(i, j);
			}
		}
	}
	adj.resize(cnt);
	vis.assign(cnt, false);
	map<pair<ll, ll>, ll> edge;
	rep(i, n) {
		rep(j, m) {
			if (s[i][j] == '.') {
				for (x = i - 2; x <= i + 2; x++) {
					for (y = j - 2; y <= j + 2; y++) {
						if (x >= 0 && x < n && y >= 0 && y < m) {
							if (s[x][y] == '.') {
								if (edge[ {min(used[x][y], used[i][j]), max(used[x][y], used[i][j])}] == 0 && used[x][y] != used[i][j]) {
									edge[ {min(used[x][y], used[i][j]), max(used[x][y], used[i][j])}] = 1;
									adj[used[x][y] - 1].pb(used[i][j] - 1);
									adj[used[i][j] - 1].pb(used[x][y] - 1);
								}
							}
						}
					}
				}
			}
		}
	}
	ll s = used[x1 - 1][y1 - 1] - 1;
	queue<ll> q;
	v<ll> d(cnt, INF);
	d[s] = 0;
	q.push(s);
	vis[s] = true;
	while (!q.empty()) {
		ll v = q.front();
		q.pop();
		for (ll u : adj[v]) {
			if (!vis[u]) {
				vis[u] = true;
				q.push(u);
				d[u] = d[v] + 1;
			}
		}
	}
	y = used[x2 - 1][y2 - 1] - 1;
	if (d[y] == INF)
		cout << -1;
	else
		cout << d[y];



	return 0;
}

Measured memory_bytes: 43164
#include <iostream>
#include <array>
#include <vector>
#include <iomanip>
#include <string>
#include <cmath>
#include <algorithm>
#include <queue>
#include <map>
#include <set>
using namespace std;

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

const LL  INF=1<<31;
const LL MOD=1000000007;



int main(){
     int m,n;
     cin>>n>>m;
     string a[55];
     string b[55];
     for(int i=0;i<n;++i)cin>>a[i];
     for(int i=0;i<m;++i)cin>>b[i];

     bool han=false;
     
     for(int i=0;i<n-m+1;++i){
          for(int j=0;j<n-m+1;++j){
               bool han2=true;
               for(int k=0;k<m;++k){
                    for(int l=0;l<m;++l){
                         if(b[k][l]!=a[i+k][j+l]){
                              han2=false;
                         }
                    }

               }
               if(han2){
               han=true;
               }
          }
     }
     if(han)cout<<"Yes"<<endl;
     else cout<<"No"<<endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <numeric>
#include <vector>
#include <string>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <stack>
#include <iomanip>
#include <functional>
#include <bitset>
#include <limits>
#include <cstdio>
#include <cmath>
#include <cassert>
#include <random>

#ifdef DEBUG
#include "library/Utility/debug.cpp"
#else
#define debug(...)
#endif

#define rep(i,n) for(int i=0;i<(n);++i)
#define EL '\n'
#define print(i) std::cout << (i) << '\n'
#define all(v) (v).begin(), (v).end()
using lnt = long long;
struct FIO{FIO(){std::cin.tie(0);std::cout.tie(0);std::ios_base::sync_with_stdio(0);std::cout<<std::fixed<<std::setprecision(15);}}fIO;
/*-*/

int main() {
	int d;
	std::cin >> d;
	int N=26;
	std::vector<lnt> c(N);
	std::vector<std::vector<lnt> > v(d,std::vector<lnt>(N));
	rep(i,N) std::cin >> c[i];
	rep(i,d) {
		rep(j,N) {
			std::cin >> v[i][j];
		}
	}
	lnt sum=0;
	std::vector<int> last(N,-1);
	rep(i,d) {
		int t;
		std::cin >> t;
		t--;
		sum+=v[i][t];
		last[t]=i;
		rep(j,N) sum-=(i-last[j])*c[j];
		print(sum);
	}
}


Measured memory_bytes: 3752
#include <cstdio>
#include <iostream>
#include <sstream>
#include <iomanip>
#include <algorithm>
#include <cmath>
#include <string>
#include <vector>
#include <list>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <bitset>
#include <numeric>
#include <climits>
#include <cfloat>
using namespace std;

map<string, bitset<256> > variable;

bitset<256> setValue(const string& s)
{
    if(variable.find(s) != variable.end())
        return variable[s];

    istringstream iss(s);
    int a;
    iss >> a;
    bitset<256> bs;
    bs[a] = true;
    return bs;
}

bool solve()
{
    int m;
    cin >> m;
    for(int i=0; i<m; ++i){
        string s;
        int lb, ub;
        cin >> s >> lb >> ub;

        bitset<256> bs;
        for(int i=lb; i<=ub; ++i)
            bs[i] = true;
        variable[s] = bs;
    }

    int n;
    cin >> n;
    stack<bitset<256> > stk;
    for(int i=0; i<n; ++i){
        string s;
        cin >> s;
        if(isalnum(s[0])){
            stk.push(setValue(s));
        }else{
            bitset<256> b = stk.top();
            stk.pop();
            bitset<256> a = stk.top();
            stk.pop();

            bitset<256> c;
            if(s[0] == '+'){
                for(int i=0; i<256; ++i){
                    for(int j=0; j<256; ++j){
                        if(a[i] && b[j])
                            c[(i+j)%256] = true;
                    }
                }
            }else if(s[0] == '-'){
                for(int i=0; i<256; ++i){
                    for(int j=0; j<256; ++j){
                        if(a[i] && b[j])
                            c[(i-j+256)%256] = true;
                    }
                }
            }else if(s[0] == '*'){
                for(int i=0; i<256; ++i){
                    for(int j=0; j<256; ++j){
                        if(a[i] && b[j])
                            c[(i*j)%256] = true;
                    }
                }
            }else{
                if(b[0])
                    return false;
                for(int i=0; i<256; ++i){
                    for(int j=0; j<256; ++j){
                        if(a[i] && b[j])
                            c[(i/j)%256] = true;
                    }
                }
            }
            stk.push(c);
        }
    }

    return true;
}

int main()
{
    if(solve())
        cout << "correct" << endl;
    else
        cout << "error" << endl;

    return 0;
}

Measured memory_bytes: 1236
#include <iostream>
using namespace std;
int main()
{
char b;
cin>>b;
if(b=='A')
{
cout<<"T"<<endl;
}
if(b=='T')
{
cout<<"A"<<endl;
}
if(b=='C')
{
cout<<"G"<<endl;
}
if(b=='G')
{
cout<<"C"<<endl;
}
return 0;
}

Measured memory_bytes: 256
#include <algorithm>
#include <iostream>
#include <cstdio>
#include <map>
#include <numeric>
#include <cmath>
#include <set>
#include <sstream>
#include <string>
#include <vector>
#include <queue>
#include <stack>
#include <complex>
#include <string.h>
#include <unordered_set>
#include <unordered_map>
#include <bitset>
#include <iomanip>
#include <sys/time.h>
#include <tuple>
#include <random>
using namespace std;

#define endl '\n'
#define ALL(v) (v).begin(), (v).end()
#define RALL(v) (v).rbegin(), (v).rend()
#define UNIQ(v) (v).erase(unique((v).begin(), (v).end()), (v).end())

typedef long long ll;
typedef long double ld;
typedef pair<int, int> P;
typedef complex<double> comp;
typedef vector< vector<ld> > matrix;
struct pairhash {
public:
    template<typename T, typename U>
    size_t operator()(const pair<T, U> &x) const {
	size_t seed = hash<T>()(x.first);
	return hash<U>()(x.second) + 0x9e3779b9 + (seed<<6) + (seed>>2);
    }
};
const int inf = 1e9 + 9;
const ll mod = 1e9 + 7;
const double eps = 1e-8;
const double pi = acos(-1);

int n;
ll k;
int a[55][55];
typedef vector<ll> vec;
typedef vector<vec> mat;

mat mult(mat &A, mat &B) {
    mat C(A.size(), vec(B[0].size()));
    for (int i = 0; i < A.size(); i++) {
        for (int k = 0; k < B.size(); k++) {
            for (int j = 0; j < B[0].size(); j++) {
                C[i][j] = (C[i][j] + A[i][k]*B[k][j] + mod) % mod;
            }
        }
    }
    return C;
}

mat pow(mat A, ll n) {
    mat B(A.size(), vec(A.size()));
    for (int i = 0; i < A.size(); i++)
        B[i][i] = 1;
    while (n > 0) {
        if (n & 1) B = mult(B, A);
        A = mult(A, A);
        n >>= 1;
    }
    return B;
}

ll solve() {
    mat A(n, vec(n));
    for (int i = 0; i < n; i++) {
        for (int j = 0; j < n; j++) A[i][j] = a[i][j];
    }
    mat B = pow(A, k);
    ll res = 0;
    for (int i = 0; i < n; i++) {
        for (int j = 0; j < n; j++) {
            res += B[i][j];
            res %= mod;
        }
    }
    return res;
}

void input() {
    cin >> n >> k;
    for (int i = 0; i < n; i++)
        for (int j = 0; j < n; j++)
            cin >> a[i][j];
}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout << fixed << setprecision(15);

    input();
    cout << solve() << endl;
}


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

template<typename T1, typename T2> void cmax(T1 &a, T2 b) { if (a < b) a = b; }
template<typename T1, typename T2> void cmin(T1 &a, T2 b) { if (a > b) a = b; }

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

  string S;
  cin >> S;
  int ans = 0, cnt = 0;
  for (int i = 0; i < 3; i++) {
    if (S.at(i) == 'R') cnt++;
    else cnt = 0;
    cmax(ans, cnt);
  }
  cout << ans << "\n";
}

Measured memory_bytes: 3632
import sys

stdin = sys.stdin

ni = lambda: int(ns())
na = lambda: list(map(int, stdin.readline().split()))
ns = lambda: stdin.readline().rstrip()  # ignore trailing spaces

mod = 1000000007

n, k = na()
a = na()
a.sort()

def enumfif(n, mod):
    f = [0] * (n+1)
    invf = [0] * (n+1)
    f[0] = 1
    for i in range(1, n+1):
        f[i] = f[i-1] * i % mod

    a = f[n]
    b = mod
    p, q = 1, 0
    while b > 0:
        c = a//b
        d = a; a = b; b = d % b
        d = p; p = q; q = d-c*q
    invf[n] = p + mod if p < 0 else p
    for i in range(n-1,-1,-1):
        invf[i] = invf[i+1] * (i+1) % mod
    return f, invf

def C(n, r, mod, fif):
    if n < 0 or r < 0 or r > n:
        return 0
    return fif[0][n] * fif[1][r] * fif[1][n-r] % mod

fif = enumfif(100005, mod)
ans = 0
for i in range(n):
    ans += C(i, k-1, mod, fif) * a[i]
    ans -= C(i, k-1, mod, fif) * a[-i-1]

ans %= mod
if ans < 0:
    ans += mod
print(ans)


Measured memory_bytes: 59376
#include <iostream>
#include <vector>
#include <algorithm>
#include <set>

using namespace std;


int main() {
	char s;
	multiset<char> k;
	set<char> k2;
	for (int i = 0; i < 4; i++) {
		cin >> s;
		k2.insert(s);
		k.insert(s);
	}
	//cout << k2.size() << ' ' << k.count(s) << ' ' << s;
	if (k2.size() == 2 & k.count(s) == 2)
		cout << "Yes";
	else
		cout << "No";
}

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

ll N;
ll a[3];

ll dfs( ll num ) {
  if (num > N) return 0;
  ll v = num;
  vector<bool> f(10,false);
  REP(i, 10) {
    f[ v%10 ] = true;
    v /= 10;
  }
  ll ret = 0;
  if ( f[3] && f[5] && f[7] ) ret = 1;
  REP(j,3)
    ret += dfs( num *10 + a[j] );
  return ret;
}


int main() {
  cin >> N;
  a[0] = 3;
  a[1] = 5;
  a[2] = 7;
  cout << dfs(0) << endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <bits/stdc++.h>
#include <vector>
#include <iterator>
#include <string>
#define pan(i,n) for(int i=0;i<n;i++)
#define ll long long int
#define vi vector<int>
#define pb push_back
using namespace std;
 

int main(){
    string s;
    cin>>s;
    int n=s.size(),a=0,b=0;
    pan(i,n){
        if(i%2!=0){
            // cout<<s[i]<<"--";
            if(s[i]=='L' || s[i]=='U' || s[i]=='D'){
                // cout<<a<<"--";
                a++;
            }
        }
        else{
            if(s[i]=='R' || s[i]=='U' || s[i]=='D') b++;
        }
    }
    // cout<<a<<b;
    if(a+b==n){
        cout<<"Yes";
    }
    else cout<<"No";
}

Measured memory_bytes: 384
#include <vector>
#include <iostream>
#include <algorithm>
#include <string>

using namespace std;
#define pb push_back
#define mp make_pair
#define all(x) (x).begin(),(x).end()
#define rep(i,n) for(int i=0;i<(n);i++)
constexpr int MOD = 1000000007;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
constexpr int dx[] = {1, 0, -1, 0, 1, 1, -1, -1};
constexpr int dy[] = {0, -1, 0, 1, 1, -1, -1, 1};

template <typename T> ostream &operator<<(ostream &os, const vector<T> &vec){os << "["; for (const auto &v : vec) {os << v << ","; } os << "]"; return os; }


void solve() {
    int N, A, B;
    cin >> N >> A >> B;
    if (A < B) {
        if ((B - A) % 2 == 0) {
            cout << "Alice" << endl;
        } else {
            cout << "Borys" << endl;
        }
    } else {
        if ((B - A) % 2 == 0) {
            cout << "Borys" << endl;
        } else {
            cout << "Alice" << endl;
        }
    }
}

int main() {
    std::cin.tie(0);
    std::ios::sync_with_stdio(false);
    cout.setf(ios::fixed);
    cout.precision(16);
    solve();
    return 0;
}


Measured memory_bytes: 256
#include<stdio.h>
#include<stdlib.h>
#include<iostream>
#include<string>
#include<algorithm>
#include<vector> 
#include<limits>
#include<numeric>
#include<type_traits>
#include<math.h>
#include<fstream>
using namespace std;
typedef long long ll;

#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define repi(i,a,b) for(int i = (int)(a); i < (int)(b); i++)
#define out(str) cout << str << endl
#define ALL(a) (a).begin(),(a).end()
#define INF (1<<29)

template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }

int A,B,C,X,Y;

int main(){
    cin>>A>>B>>C>>X>>Y;
    out(min(X,Y)*min(A+B,C*2)+(X-min(X,Y))*min(A,C*2)+(Y-min(X,Y))*min(B,C*2));
    
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define ll long long
#define ull unsigned ll
#define uint unsigned
#define db long double
#define pii pair<int,int>
#define pll pair<ll,ll>
#define IT iterator
#define PB push_back
#define MK make_pair
#define LB lower_bound
#define UB upper_bound
#define fi first
#define se second
#define For(i,j,k) for (int i=(int)(j);i<=(int)(k);i++)
#define Rep(i,j,k) for (int i=(int)(j);i>=(int)(k);i--)
#define UPD(x,y) (((x)+=(y))>=mo?x-=mo:233)
#define CLR(a,v) memset(a,v,sizeof(a));
#define CPY(a,b) memcpy(a,b,sizeof(a));
using namespace std;
const int N=3005;
const int mo=1000000007;
int n,Q,a[N],f[N][N],ans;
int main(){
	scanf("%d%d",&n,&Q);
	For(i,1,n) scanf("%d",&a[i]);
	For(i,1,n) For(j,1,n) f[i][j]=(a[i]>a[j]);
	For(i,1,Q){
		int x,y;
		scanf("%d%d",&x,&y);
		For(p,1,n) if (p!=x&&p!=y){
			f[x][p]=f[y][p]=1ll*(f[x][p]+f[y][p])*(mo+1)/2%mo;
			f[p][x]=f[p][y]=1ll*(f[p][x]+f[p][y])*(mo+1)/2%mo;
		}
		f[x][y]=f[y][x]=1ll*(f[x][y]+f[y][x])*(mo+1)/2%mo;
	}
	For(i,1,n) For(j,i+1,n)
		ans=(ans+f[i][j])%mo;
	For(i,1,Q) ans=1ll*ans*2%mo;
	printf("%d\n",ans);
} 

Measured memory_bytes: 35456
#include<bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); ++i)
int main() {
  int n, m, c, ans = 0;
  cin >> n >> m >> c;
  int b[m], a, sum = 0;
  rep(i,m)
    cin >> b[i];
  rep(i,n)
  {
    sum = 0;
    rep(j,m)
    {
      cin >> a;
      sum += b[j] * a;
    }
    sum += c;
    if (sum > 0) {
      ans++;
    }
  }
  cout << ans;
}


Measured memory_bytes: 256
N=int(input())
D=[list(map(int,input().split())) for _ in range(N)]

ans=False
for i in range(N-2):
    if D[i][0]==D[i][1] and D[i+1][0]==D[i+1][1] and D[i+2][0]==D[i+2][1]:
        ans=True

print('Yes' if ans else 'No')

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

#define all(x) (x).begin(),(x).end()
#define rep(i,l,r) for(int i=(int)(l);i<(int)(r);i++)

typedef long long ll;
const ll MOD = 1e9 + 7;
const ll inf = 1LL<<60;
const double eps = 1e-9;



int main()
{
    int N, K, R, S, P;
    ll ans = 0;
    string T;
    cin >> N >> K >> R >> S >> P;
    cin >> T;

    char M[1000000];
    int tmp_R=K, tmp_S=K, tmp_P=K;

    for (int i = 0; i < N; i++) {
        char tmp;
        if (i - K < 0) {
            tmp = 'x';
        } else {
            tmp = M[i-K];
        }
        if (T[i] == 'r' && (tmp != 'p')) {
            ans += P;
            M[i] = 'p';
        }
        if (T[i] == 's' && (tmp != 'r')) {
            ans += R;
            M[i] = 'r';
        }
        if (T[i] == 'p' && (tmp != 's')) {
            ans += S;
            M[i] = 's';
        }
    }
    cout << ans << endl;
    return 0;
}



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

using namespace std;
#define inf 1000000000
#define unvisited -1
#define visited 1
#define eps 1e-9
#define mp make_pair
#define pb push_back
#define pi acos(-1.0)
#define uint64 unsigned long long
#define FastSlowInput ios_base::sync_with_stdio(false); cin.tie(NULL);
typedef long long ll;
typedef vector<int> vi;
typedef pair<int,int> ii;
typedef vector<ii> vii;

const int maxn = 100010;
int dp[maxn][101][2];

const int mod = 1e9 + 7;

void add(int &a, int b){
	a += b;
	if(a < 0){a += mod;}
	if(a >= mod){
		a -= mod;
	}
}

int main(){
	string s;
	int i,d,j,k;
	cin>>s>>d;
	int n = s.length();
	dp[0][0][0] = 1;
	for(i=0;i<n;i++) {
		for(j=0;j<d;j++){
			for(k=0;k<2;k++){
				int batas;
				if(k == 0){
					batas = s[i] - '0';
				}else{
					batas = 9;
				}
				// printf("k: %d batas: %d\n",k,batas);
				for(int l=0;l<=batas;l++){
					if(l < batas){
						add(dp[i+1][(j + l) % d][1], dp[i][j][k]);
						// printf("dp[%d][%d][%d] jd: %d\n",i+1,(j+l)%d, 1, dp[i+1][(j+l)%d][1]);
					}
					else{
						add(dp[i+1][(j + l) % d][k], dp[i][j][k]);
						// printf("dp[%d][%d][%d] jd: %d\n",i+1,(j+l)%d, k, dp[i+1][(j+l)%d][k]);
					}
					
				}
			}
		}
	}
	int ans = 0;
	add(ans, dp[n][0][0]);
	add(ans, dp[n][0][1]);
	add(ans, -1);
	printf("%d\n",ans);
	return 0;
};

Measured memory_bytes: 8448
#include <cstdio>
#include <cmath>
#include <cstring>
#include <iostream>
#include <iomanip>
#include <sstream>
#include <map>
#include <set>
#include <array>
#include <queue>
#include <string>
#include <vector>
#include <numeric>
#include <algorithm>
#include <functional>
#define MOD 1000000007
#define INF 11234567890
#define in std::cin
#define out std::cout
#define rep(i,N) for(LL i=0;i<N;++i)
typedef long long int LL;
typedef std::pair<int, int> P;

LL N;
std::vector<LL>tmp;
LL ans;

std::vector<LL>divisor(LL num)
{
	std::vector<LL>res;
	for (LL i = 1; i*i <= num; ++i)
	{
		if (num % i == 0)
		{
			res.push_back(i);
			if ((num / i) != i)
			{
				res.push_back(num / i);
			}
		}
	}
	return res;
}

int main()
{
	in >> N;

	tmp = divisor(N);
	std::sort(tmp.begin(), tmp.end());
	if (tmp.size() % 2 == 1)
	{
		auto num = tmp[tmp.size() / 2];
		while (num > 0)
		{
			num /= 10;
			++ans;
		}
	}
	else
	{
		auto num1 = tmp[tmp.size() / 2 - 1], num2 = tmp[tmp.size() / 2];
		auto num = std::max(num1, num2);
		while (num > 0)
		{
			num /= 10;
			++ans;
		}
	}
	out << ans << std::endl;
	return 0;
}

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

class adj_list {
	vector<vector<int>> m_vt;

public:
	explicit adj_list( int s ): m_vt( s+1 ) {}

	void add_edge( int a, int b ) {
		m_vt[a].push_back( b );
		m_vt[b].push_back( a );
	}

	int find_path() const {
		vector<bool> vf( m_vt.size()+1 );
		vf[1] = true;
		return dfs( 1, 1, vf );
	}

	int dfs( int nd, int nv, vector<bool>& vf ) const {
		if( nv == m_vt.size()-1 ) {
			return 1;
		}

		int result = 0;
		auto& ed = m_vt[nd];

		for( int i = 0; i < ed.size(); ++i ) {
			if( !vf[ed[i]] ) {
				vf[ed[i]] = true;
				result += dfs( ed[i], nv+1, vf );
				vf[ed[i]] = false;
			}
		}

		return result;
	}
};

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

	int N, M;
	cin >> N >> M;

	adj_list al( N );
	for( int i = 0; i < M; ++i ) {
		int a, b;
		cin >> a >> b;

		al.add_edge( a, b );
	}

	cout << al.find_path() << endl;
}


Measured memory_bytes: 256
n = int(input())
s = list(input())
left = [0] * n
right = [0] * n
for i in range(n):
    if s[i] == 'W':
        if i == 0:
            left[0] = 1
        else:
            left[i] = left[i-1] + 1
    elif i != 0:
        left[i] = left[i-1]
for i in range(n-1, -1, -1):
    if s[i] == 'E':
        if i == n - 1:
            right[n-1] = 1
        else:
            right[i] = right[i+1] + 1
    elif i != n - 1:
        right[i] = right[i+1]
ans = right[1]
for i in range(1, n-1):
    ans = min(ans, left[i-1] + right[i+1])
ans = min(ans, left[n-2])
print(ans)

Measured memory_bytes: 20044